Skip to content

Commit

Permalink
refactor(io): add crdt-library-type (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
leedavidcs authored Sep 25, 2024
1 parent 86778bf commit 7246a9e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changeset/fast-monkeys-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pluv/crdt-loro": patch
"@pluv/crdt-yjs": patch
"@pluv/io": patch
---

Added `CrdtLibraryType` so that `@pluv/crdt-yjs` and `@pluv/crdt-loro` export a new property `kind` containing an identifier for the crdt.
1 change: 1 addition & 0 deletions packages/crdt-loro/src/loro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { map } from "./map";
export { object } from "./object";
export { text } from "./text";
export type { LoroType } from "./types";
export const kind = "loro" as const;
1 change: 1 addition & 0 deletions packages/crdt-yjs/src/yjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export type { YjsType } from "./types";
export { xmlElement } from "./xmlElement";
export { xmlFragment } from "./xmlFragment";
export { xmlText } from "./xmlText";
export const kind = "yjs" as const;
6 changes: 3 additions & 3 deletions packages/io/src/PluvIO.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
import { noop } from "@pluv/crdt";
import type { BaseIOAuthorize, IOAuthorize, InferIOAuthorizeUser, JsonObject } from "@pluv/types";
import type { AbstractPlatform, InferPlatformContextType, WebSocketRegistrationMode } from "./AbstractPlatform";
import type { AbstractPlatform, InferPlatformContextType } from "./AbstractPlatform";
import { PluvProcedure } from "./PluvProcedure";
import type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
import { PluvRouter } from "./PluvRouter";
import { PluvServer } from "./PluvServer";
import type { JWTEncodeParams } from "./authorize";
import { authorize } from "./authorize";
import type { GetInitialStorageFn, PluvIOListeners } from "./types";
import type { CrdtLibraryType, GetInitialStorageFn, PluvIOListeners } from "./types";
import { __PLUV_VERSION } from "./version";

export type PluvIOConfig<
Expand All @@ -18,7 +18,7 @@ export type PluvIOConfig<
> = {
authorize?: TAuthorize;
context?: TContext;
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
crdt?: CrdtLibraryType;
debug?: boolean;
platform: TPlatform;
};
Expand Down
7 changes: 1 addition & 6 deletions packages/io/src/PluvServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import type {
Maybe,
} from "@pluv/types";
import colors from "kleur";
import type {
AbstractPlatform,
InferPlatformContextType,
InferRoomContextType,
WebSocketRegistrationMode,
} from "./AbstractPlatform";
import type { AbstractPlatform, InferPlatformContextType, InferRoomContextType } from "./AbstractPlatform";
import type { IORoomListeners } from "./IORoom";
import { IORoom } from "./IORoom";
import { PluvProcedure } from "./PluvProcedure";
Expand Down
5 changes: 2 additions & 3 deletions packages/io/src/createIO.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
import type { BaseUser, IOAuthorize, JsonObject } from "@pluv/types";
import type { AbstractPlatform, InferPlatformContextType } from "./AbstractPlatform";
import { PluvIO } from "./PluvIO";
import type { GetInitialStorageFn } from "./types";
import { CrdtLibraryType } from "./types";

export type CreateIOParams<
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
Expand All @@ -12,7 +11,7 @@ export type CreateIOParams<
> = {
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
context?: TContext;
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
crdt?: CrdtLibraryType;
debug?: boolean;
platform: TPlatform;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/io/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
export { PluvServer } from "./PluvServer";
export type { CreateRoomOptions, InferIORoom, PluvServerConfig } from "./PluvServer";
export type {
CrdtLibraryType,
GetInitialStorageFn,
IORoomListenerEvent,
IORoomMessageEvent,
PluvIOListeners,
Expand Down
7 changes: 6 additions & 1 deletion packages/io/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AbstractCrdtDoc } from "@pluv/crdt";
import type { AbstractCrdtDoc, AbstractCrdtDocFactory } from "@pluv/crdt";
import type {
BaseIOAuthorize,
EventRecord,
Expand Down Expand Up @@ -26,6 +26,11 @@ declare global {
};
}

export interface CrdtLibraryType {
doc: (value: any) => AbstractCrdtDocFactory<any>;
kind: "loro" | "yjs";
}

export type EventResolver<
TPlatform extends AbstractPlatform = AbstractPlatform,
TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize,
Expand Down

0 comments on commit 7246a9e

Please sign in to comment.