diff --git a/.changeset/fast-monkeys-admire.md b/.changeset/fast-monkeys-admire.md new file mode 100644 index 00000000..2e4fcef3 --- /dev/null +++ b/.changeset/fast-monkeys-admire.md @@ -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. diff --git a/packages/crdt-loro/src/loro.ts b/packages/crdt-loro/src/loro.ts index bce7063a..a9e534cd 100644 --- a/packages/crdt-loro/src/loro.ts +++ b/packages/crdt-loro/src/loro.ts @@ -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; diff --git a/packages/crdt-yjs/src/yjs.ts b/packages/crdt-yjs/src/yjs.ts index 7cfd5c36..889d5826 100644 --- a/packages/crdt-yjs/src/yjs.ts +++ b/packages/crdt-yjs/src/yjs.ts @@ -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; diff --git a/packages/io/src/PluvIO.ts b/packages/io/src/PluvIO.ts index 00c4931c..df62cf2c 100644 --- a/packages/io/src/PluvIO.ts +++ b/packages/io/src/PluvIO.ts @@ -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< @@ -18,7 +18,7 @@ export type PluvIOConfig< > = { authorize?: TAuthorize; context?: TContext; - crdt?: { doc: (value: any) => AbstractCrdtDocFactory }; + crdt?: CrdtLibraryType; debug?: boolean; platform: TPlatform; }; diff --git a/packages/io/src/PluvServer.ts b/packages/io/src/PluvServer.ts index 0a1d1453..ec8e5cf9 100644 --- a/packages/io/src/PluvServer.ts +++ b/packages/io/src/PluvServer.ts @@ -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"; diff --git a/packages/io/src/createIO.ts b/packages/io/src/createIO.ts index ed7b69f0..abbc588f 100644 --- a/packages/io/src/createIO.ts +++ b/packages/io/src/createIO.ts @@ -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 = AbstractPlatform, @@ -12,7 +11,7 @@ export type CreateIOParams< > = { authorize?: IOAuthorize>; context?: TContext; - crdt?: { doc: (value: any) => AbstractCrdtDocFactory }; + crdt?: CrdtLibraryType; debug?: boolean; platform: TPlatform; }; diff --git a/packages/io/src/index.ts b/packages/io/src/index.ts index c22a5a5a..3d50faa6 100644 --- a/packages/io/src/index.ts +++ b/packages/io/src/index.ts @@ -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, diff --git a/packages/io/src/types.ts b/packages/io/src/types.ts index a1389196..e36af860 100644 --- a/packages/io/src/types.ts +++ b/packages/io/src/types.ts @@ -1,4 +1,4 @@ -import type { AbstractCrdtDoc } from "@pluv/crdt"; +import type { AbstractCrdtDoc, AbstractCrdtDocFactory } from "@pluv/crdt"; import type { BaseIOAuthorize, EventRecord, @@ -26,6 +26,11 @@ declare global { }; } +export interface CrdtLibraryType { + doc: (value: any) => AbstractCrdtDocFactory; + kind: "loro" | "yjs"; +} + export type EventResolver< TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize> = BaseIOAuthorize,