Skip to content

Commit

Permalink
fix builds
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Sep 29, 2024
1 parent 538ca2c commit 638cba0
Show file tree
Hide file tree
Showing 33 changed files with 1,531 additions and 1,223 deletions.
26 changes: 26 additions & 0 deletions apps/humding/verdant/src/client/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,36 @@ export class Client<Presence = any, Profile = any> {
import: BaseClient<Presence, Profile>["import"];
subscribe: BaseClient<Presence, Profile>["subscribe"];
stats: BaseClient<Presence, Profile>["stats"];

/**
* Deletes all local data. If the client is connected to sync,
* this will cause the client to re-sync all data from the server.
* Use this very carefully, and only as a last resort.
*/
__dangerous__resetLocal: BaseClient<
Presence,
Profile
>["__dangerous__resetLocal"];

/**
* Export all data, then re-import it. This might resolve
* some issues with the local database, but it should
* only be done as a second-to-last resort. The last resort
* would be __dangerous__resetLocal on ClientDescriptor, which
* clears all local data.
*
* Unlike __dangerous__resetLocal, this method allows local-only
* clients to recover data, whereas __dangerous__resetLocal only
* lets networked clients recover from the server.
*/
__dangerous__hardReset: () => Promise<void>;

/**
* Manually triggers storage rebasing. Follows normal
* rebasing rules. Rebases already happen automatically
* during normal operation, so you probably don't need this.
*/
__manualRebase: () => Promise<void>;
}

export interface ClientDescriptorOptions<Presence = any, Profile = any>
Expand Down
3 changes: 3 additions & 0 deletions apps/humding/verdant/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ClientDescriptorOptions } from "./client.js";
export * from "./client.js";
import schema from "./schema.js";
import oldSchemas from "./schemaVersions/index.js";
import { ClientDescriptor as StorageDescriptor } from "./client.js";
import migrations from "../migrations/index.js";
export * from "@verdant-web/store";
Expand All @@ -12,10 +13,12 @@ export class ClientDescriptor<
constructor(init: ClientDescriptorOptions<Presence, Profile>) {
const defaultedSchema = init.schema || schema;
const defaultedMigrations = init.migrations || migrations;
const defaultedOldSchemas = init.oldSchemas || oldSchemas;
super({
...init,
schema: defaultedSchema,
migrations: defaultedMigrations,
oldSchemas: defaultedOldSchemas,
});
}
}
62 changes: 59 additions & 3 deletions apps/humding/verdant/src/client/react.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Context, ComponentType, ReactNode } from "react";
import {
Context,
ComponentType,
ReactNode,
ChangeEvent,
FocusEvent,
} from "react";
import type {
Client,
ClientDescriptor,
Expand All @@ -12,6 +18,7 @@ import type {
EntityShape,
AnyEntity,
EntityDestructured,
EntityInit,
EntityFile,
Song,
SongFilter,
Expand All @@ -23,20 +30,29 @@ type HookConfig<F> = {
key?: string;
};

type FieldInputProps<Shape> = {
value: Shape extends boolean ? undefined : Shape;
checked?: boolean;
onChange: (event: ChangeEvent) => void;
onFocus: (event: FocusEvent) => void;
onBlur: (event: FocusEvent) => void;
type?: string;
};

export interface GeneratedHooks<Presence, Profile> {
/**
* Render this context Provider at the top level of your
* React tree to provide a Client to all hooks.
*/
Provider: ComponentType<{
value: ClientDescriptor<Schema>;
value: ClientDescriptor<any, any>;
children: ReactNode;
sync?: boolean;
}>;
/**
* Direct access to the React Context, if needed.
*/
Context: Context<ClientDescriptor<Schema>>;
Context: Context<ClientDescriptor<any, any>>;
/** @deprecated use useClient instead */
useStorage: () => Client<Presence, Profile>;
useClient: () => Client<Presence, Profile>;
Expand All @@ -52,6 +68,46 @@ export interface GeneratedHooks<Presence, Profile> {
query: (peer: UserInfo<Profile, Presence>) => boolean,
options?: { includeSelf: boolean },
) => UserInfo<Profile, Presence>[];
useViewPeers: () => UserInfo<Profile, Presence>[];
useViewId: (viewId: string | undefined) => void;
useField<
T extends AnyEntity<any, any, any>,
K extends keyof EntityDestructured<T>,
>(
entity: T,
fieldName: K,
options?: {
/** after this timeout, the field will be considered abandoned by a peer. defaults to 1m */
timeout: number;
},
): {
/* The live value of the field */
value: EntityDestructured<T>[K];
/* Sets the value of the field */
setValue: (value: Exclude<EntityInit<T>[K], undefined>) => void;
/* Pass these props to any <input> or <textarea> element to auto-wire it */
inputProps: FieldInputProps<EntityDestructured<T>[K]>;
presence: {
/**
* Whether the current replica is editing the field
*/
self: boolean;
/**
* A list of peers editing this field
*/
peers: UserInfo<Profile, Presence>[];
/**
* Whether the field is currently being edited by someone else.
* Will return false if the current replica is already editing it.
*/
occupied: boolean;
/**
* Mark the field as being edited by the current replica, similar to
* what inputProps do on 'focus' events.
*/
touch: () => void;
};
};
useSyncStatus: () => boolean;
useWatch<T extends AnyEntity<any, any, any> | null>(
entity: T,
Expand Down
2 changes: 1 addition & 1 deletion apps/humding/verdant/src/client/schema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import schema from './schemaVersions/v1.js';
const finalSchema = { wip: true, ...schema };
const finalSchema = { wip: false, ...schema };
export default finalSchema;
5 changes: 5 additions & 0 deletions apps/humding/verdant/src/client/schemaVersions/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

import { StorageSchema } from '@verdant-web/common';
declare const versions: StorageSchema[];
export default versions;

8 changes: 8 additions & 0 deletions apps/humding/verdant/src/client/schemaVersions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/**
* @generated - do not modify this file.
*/
import v1 from './v1.js';

export default [v1]

26 changes: 26 additions & 0 deletions apps/palette/verdant/src/client/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,36 @@ export class Client<Presence = any, Profile = any> {
import: BaseClient<Presence, Profile>["import"];
subscribe: BaseClient<Presence, Profile>["subscribe"];
stats: BaseClient<Presence, Profile>["stats"];

/**
* Deletes all local data. If the client is connected to sync,
* this will cause the client to re-sync all data from the server.
* Use this very carefully, and only as a last resort.
*/
__dangerous__resetLocal: BaseClient<
Presence,
Profile
>["__dangerous__resetLocal"];

/**
* Export all data, then re-import it. This might resolve
* some issues with the local database, but it should
* only be done as a second-to-last resort. The last resort
* would be __dangerous__resetLocal on ClientDescriptor, which
* clears all local data.
*
* Unlike __dangerous__resetLocal, this method allows local-only
* clients to recover data, whereas __dangerous__resetLocal only
* lets networked clients recover from the server.
*/
__dangerous__hardReset: () => Promise<void>;

/**
* Manually triggers storage rebasing. Follows normal
* rebasing rules. Rebases already happen automatically
* during normal operation, so you probably don't need this.
*/
__manualRebase: () => Promise<void>;
}

export interface ClientDescriptorOptions<Presence = any, Profile = any>
Expand Down
3 changes: 3 additions & 0 deletions apps/palette/verdant/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ClientDescriptorOptions } from "./client.js";
export * from "./client.js";
import schema from "./schema.js";
import oldSchemas from "./schemaVersions/index.js";
import { ClientDescriptor as StorageDescriptor } from "./client.js";
import migrations from "../migrations/index.js";
export * from "@verdant-web/store";
Expand All @@ -12,10 +13,12 @@ export class ClientDescriptor<
constructor(init: ClientDescriptorOptions<Presence, Profile>) {
const defaultedSchema = init.schema || schema;
const defaultedMigrations = init.migrations || migrations;
const defaultedOldSchemas = init.oldSchemas || oldSchemas;
super({
...init,
schema: defaultedSchema,
migrations: defaultedMigrations,
oldSchemas: defaultedOldSchemas,
});
}
}
62 changes: 59 additions & 3 deletions apps/palette/verdant/src/client/react.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Context, ComponentType, ReactNode } from "react";
import {
Context,
ComponentType,
ReactNode,
ChangeEvent,
FocusEvent,
} from "react";
import type {
Client,
ClientDescriptor,
Expand All @@ -12,6 +18,7 @@ import type {
EntityShape,
AnyEntity,
EntityDestructured,
EntityInit,
EntityFile,
Project,
ProjectFilter,
Expand All @@ -23,20 +30,29 @@ type HookConfig<F> = {
key?: string;
};

type FieldInputProps<Shape> = {
value: Shape extends boolean ? undefined : Shape;
checked?: boolean;
onChange: (event: ChangeEvent) => void;
onFocus: (event: FocusEvent) => void;
onBlur: (event: FocusEvent) => void;
type?: string;
};

export interface GeneratedHooks<Presence, Profile> {
/**
* Render this context Provider at the top level of your
* React tree to provide a Client to all hooks.
*/
Provider: ComponentType<{
value: ClientDescriptor<Schema>;
value: ClientDescriptor<any, any>;
children: ReactNode;
sync?: boolean;
}>;
/**
* Direct access to the React Context, if needed.
*/
Context: Context<ClientDescriptor<Schema>>;
Context: Context<ClientDescriptor<any, any>>;
/** @deprecated use useClient instead */
useStorage: () => Client<Presence, Profile>;
useClient: () => Client<Presence, Profile>;
Expand All @@ -52,6 +68,46 @@ export interface GeneratedHooks<Presence, Profile> {
query: (peer: UserInfo<Profile, Presence>) => boolean,
options?: { includeSelf: boolean },
) => UserInfo<Profile, Presence>[];
useViewPeers: () => UserInfo<Profile, Presence>[];
useViewId: (viewId: string | undefined) => void;
useField<
T extends AnyEntity<any, any, any>,
K extends keyof EntityDestructured<T>,
>(
entity: T,
fieldName: K,
options?: {
/** after this timeout, the field will be considered abandoned by a peer. defaults to 1m */
timeout: number;
},
): {
/* The live value of the field */
value: EntityDestructured<T>[K];
/* Sets the value of the field */
setValue: (value: Exclude<EntityInit<T>[K], undefined>) => void;
/* Pass these props to any <input> or <textarea> element to auto-wire it */
inputProps: FieldInputProps<EntityDestructured<T>[K]>;
presence: {
/**
* Whether the current replica is editing the field
*/
self: boolean;
/**
* A list of peers editing this field
*/
peers: UserInfo<Profile, Presence>[];
/**
* Whether the field is currently being edited by someone else.
* Will return false if the current replica is already editing it.
*/
occupied: boolean;
/**
* Mark the field as being edited by the current replica, similar to
* what inputProps do on 'focus' events.
*/
touch: () => void;
};
};
useSyncStatus: () => boolean;
useWatch<T extends AnyEntity<any, any, any> | null>(
entity: T,
Expand Down
4 changes: 2 additions & 2 deletions apps/palette/verdant/src/client/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./schemaVersions/v1.js";
export { default } from "./schemaVersions/v1.js";
export * from "./schemaVersions/v2.js";
export { default } from "./schemaVersions/v2.js";
2 changes: 1 addition & 1 deletion apps/palette/verdant/src/client/schema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import schema from './schemaVersions/v1.js';
import schema from './schemaVersions/v2.js';
const finalSchema = { wip: false, ...schema };
export default finalSchema;
5 changes: 5 additions & 0 deletions apps/palette/verdant/src/client/schemaVersions/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

import { StorageSchema } from '@verdant-web/common';
declare const versions: StorageSchema[];
export default versions;

8 changes: 8 additions & 0 deletions apps/palette/verdant/src/client/schemaVersions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/**
* @generated - do not modify this file.
*/
import v2 from './v2.js';

export default [v2]

Loading

0 comments on commit 638cba0

Please sign in to comment.