@voidhash/mimic 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +202 -198
- package/dist/Document.cjs +1 -2
- package/dist/Document.d.cts +9 -3
- package/dist/Document.d.cts.map +1 -1
- package/dist/Document.d.mts +9 -3
- package/dist/Document.d.mts.map +1 -1
- package/dist/Document.mjs +1 -2
- package/dist/Document.mjs.map +1 -1
- package/dist/Presence.d.mts.map +1 -1
- package/dist/Primitive.d.cts +2 -2
- package/dist/Primitive.d.mts +2 -2
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutProperties.cjs +15 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutProperties.mjs +15 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutPropertiesLoose.cjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutPropertiesLoose.mjs +13 -0
- package/dist/client/ClientDocument.cjs +17 -12
- package/dist/client/ClientDocument.d.mts.map +1 -1
- package/dist/client/ClientDocument.mjs +17 -12
- package/dist/client/ClientDocument.mjs.map +1 -1
- package/dist/client/WebSocketTransport.cjs +6 -6
- package/dist/client/WebSocketTransport.mjs +6 -6
- package/dist/client/WebSocketTransport.mjs.map +1 -1
- package/dist/primitives/Tree.cjs +58 -8
- package/dist/primitives/Tree.d.cts +99 -10
- package/dist/primitives/Tree.d.cts.map +1 -1
- package/dist/primitives/Tree.d.mts +99 -10
- package/dist/primitives/Tree.d.mts.map +1 -1
- package/dist/primitives/Tree.mjs +58 -8
- package/dist/primitives/Tree.mjs.map +1 -1
- package/dist/primitives/shared.d.cts +9 -0
- package/dist/primitives/shared.d.cts.map +1 -1
- package/dist/primitives/shared.d.mts +9 -0
- package/dist/primitives/shared.d.mts.map +1 -1
- package/dist/primitives/shared.mjs.map +1 -1
- package/dist/server/ServerDocument.cjs +1 -1
- package/dist/server/ServerDocument.d.cts +3 -3
- package/dist/server/ServerDocument.d.cts.map +1 -1
- package/dist/server/ServerDocument.d.mts +3 -3
- package/dist/server/ServerDocument.d.mts.map +1 -1
- package/dist/server/ServerDocument.mjs +1 -1
- package/dist/server/ServerDocument.mjs.map +1 -1
- package/package.json +2 -2
- package/src/Document.ts +18 -5
- package/src/client/ClientDocument.ts +20 -21
- package/src/client/WebSocketTransport.ts +9 -9
- package/src/primitives/Tree.ts +213 -19
- package/src/primitives/shared.ts +10 -1
- package/src/server/ServerDocument.ts +4 -3
- package/tests/client/ClientDocument.test.ts +309 -2
- package/tests/client/WebSocketTransport.test.ts +228 -3
- package/tests/primitives/Tree.test.ts +296 -17
- package/tests/server/ServerDocument.test.ts +1 -1
- package/tsconfig.json +1 -1
package/dist/Document.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.cts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;AAA/B,cAWA,cAAA,SAAuB,KAAA,CAXa;EAWpC,SAAA,IAAA,GAAA,gBAAuB;EAenB,WAAQ,CAAA,OAAA,EAAA,MAAA;;;;;AAQK,UARb,QAQa,CAAA,gBARY,YAQZ,CAAA,CAAA;EAArB;EAQ+B,SAAA,MAAA,EAdrB,OAcqB;EAAxB;EAQiC,SAAA,IAAA,EAnBhC,UAmBgC,CAnBX,OAmBW,CAAA;EAArB;EAAkC,GAAA,EAAA,EAhBrD,UAgBqD,CAhBhC,OAgBgC,CAAA,GAAA,SAAA;EAAI;;;;;AAkBlE;EAAiD,UAAA,EAAA,EA1BjC,aA0BiC,CA1BT,OA0BS,CAAA;
|
|
1
|
+
{"version":3,"file":"Document.d.cts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;AAA/B,cAWA,cAAA,SAAuB,KAAA,CAXa;EAWpC,SAAA,IAAA,GAAA,gBAAuB;EAenB,WAAQ,CAAA,OAAA,EAAA,MAAA;;;;;AAQK,UARb,QAQa,CAAA,gBARY,YAQZ,CAAA,CAAA;EAArB;EAQ+B,SAAA,MAAA,EAdrB,OAcqB;EAAxB;EAQiC,SAAA,IAAA,EAnBhC,UAmBgC,CAnBX,OAmBW,CAAA;EAArB;EAAkC,GAAA,EAAA,EAhBrD,UAgBqD,CAhBhC,OAgBgC,CAAA,GAAA,SAAA;EAAI;;;;;AAkBlE;EAAiD,UAAA,EAAA,EA1BjC,aA0BiC,CA1BT,OA0BS,CAAA;EAEJ;;;;;AAgB7C;EAAqC,WAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EApCT,UAoCS,CApCY,OAoCZ,CAAA,EAAA,GApCyB,CAoCzB,CAAA,EApC6B,CAoC7B;EAC3B;;;;EAEP,KAAA,CAAA,GAAA,EAjCU,aAiCV,CAjCwB,SAiCxB,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAAA,EAAA,IAAA;EAAQ;;;WA5BA;;UAOM,gCAAgC;;qBAE5B,cAAwB;;;;;;0BAMnB,WAAqB;;;;;cAUlC,uBAAwB,sBAC3B,mBACE,gBAAgB,aACzB,SAAS"}
|
package/dist/Document.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Operation } from "./Operation.mjs";
|
|
2
2
|
import { Transaction } from "./Transaction.mjs";
|
|
3
|
-
import { AnyPrimitive, InferProxy, InferSnapshot, InferState } from "./primitives/shared.mjs";
|
|
3
|
+
import { AnyPrimitive, InferProxy, InferSetInput, InferSnapshot, InferState } from "./primitives/shared.mjs";
|
|
4
4
|
import "./Primitive.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/Document.d.ts
|
|
@@ -56,8 +56,14 @@ interface Document<TSchema extends AnyPrimitive> {
|
|
|
56
56
|
flush(): Transaction;
|
|
57
57
|
}
|
|
58
58
|
interface DocumentOptions<TSchema extends AnyPrimitive> {
|
|
59
|
-
/** Initial
|
|
60
|
-
readonly initial?:
|
|
59
|
+
/** Initial value for the document (using set input format) */
|
|
60
|
+
readonly initial?: InferSetInput<TSchema>;
|
|
61
|
+
/**
|
|
62
|
+
* Raw initial state for the document (already in internal state format).
|
|
63
|
+
* Use this when loading state from the server or storage.
|
|
64
|
+
* Takes precedence over `initial` if both are provided.
|
|
65
|
+
*/
|
|
66
|
+
readonly initialState?: InferState<TSchema>;
|
|
61
67
|
}
|
|
62
68
|
/**
|
|
63
69
|
* Creates a new Document for the given schema.
|
package/dist/Document.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.mts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;cAW/B,cAAA,SAAuB,KAAA;EAXvB,SAAA,IAAA,GAAA,gBAAuB;EAWvB,WAAA,CAAA,OAAe,EAAA,MAAA;AAe5B;;;;AAKiB,UALA,QAKA,CAAA,gBALyB,YAKzB,CAAA,CAAA;EAGa;EAArB,SAAA,MAAA,EANU,OAMV;EAQ+B;EAAxB,SAAA,IAAA,EAXC,UAWD,CAXsB,OAWtB,CAAA;EAQiC;EAArB,GAAA,EAAA,EAhBnB,UAgBmB,CAhBE,OAgBF,CAAA,GAAA,SAAA;EAAkC;;;;;;EAkB7C,UAAA,EAAA,EA1BD,aA0BgB,CA1BQ,OA0BR,CAAA;EAAiB
|
|
1
|
+
{"version":3,"file":"Document.d.mts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;cAW/B,cAAA,SAAuB,KAAA;EAXvB,SAAA,IAAA,GAAA,gBAAuB;EAWvB,WAAA,CAAA,OAAe,EAAA,MAAA;AAe5B;;;;AAKiB,UALA,QAKA,CAAA,gBALyB,YAKzB,CAAA,CAAA;EAGa;EAArB,SAAA,MAAA,EANU,OAMV;EAQ+B;EAAxB,SAAA,IAAA,EAXC,UAWD,CAXsB,OAWtB,CAAA;EAQiC;EAArB,GAAA,EAAA,EAhBnB,UAgBmB,CAhBE,OAgBF,CAAA,GAAA,SAAA;EAAkC;;;;;;EAkB7C,UAAA,EAAA,EA1BD,aA0BgB,CA1BQ,OA0BR,CAAA;EAAiB;;;;;;EAkBpC,WAyKZ,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EA7M2B,UA6M3B,CA7MgD,OA6MhD,CAAA,EAAA,GA7M6D,CA6M7D,CAAA,EA7MiE,CA6MjE;EAzKoC;;;;EAGzB,KAAA,CAAA,GAAA,EAjCC,aAiCD,CAjCe,SAiCf,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAAA,EAAA,IAAA;EAAT;;;WA5BQ;;UAOM,gCAAgC;;qBAE5B,cAAwB;;;;;;0BAMnB,WAAqB;;;;;cAUlC,uBAAwB,sBAC3B,mBACE,gBAAgB,aACzB,SAAS"}
|
package/dist/Document.mjs
CHANGED
|
@@ -34,8 +34,7 @@ var OperationError = class extends Error {
|
|
|
34
34
|
* Creates a new Document for the given schema.
|
|
35
35
|
*/
|
|
36
36
|
const make = (schema, options) => {
|
|
37
|
-
|
|
38
|
-
let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
|
|
37
|
+
let _state = (options === null || options === void 0 ? void 0 : options.initialState) !== void 0 ? options.initialState : (options === null || options === void 0 ? void 0 : options.initial) !== void 0 ? schema._internal.convertSetInputToState ? schema._internal.convertSetInputToState(options.initial) : options.initial : schema._internal.getInitialState();
|
|
39
38
|
let _pending = [];
|
|
40
39
|
let _inTransaction = false;
|
|
41
40
|
let _txOps = [];
|
package/dist/Document.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.mjs","names":["_state: Primitive.InferState<TSchema> | undefined","_pending: Operation.Operation<any, any, any>[]","_txOps: Operation.Operation<any, any, any>[]","_txBaseState: Primitive.InferState<TSchema> | undefined","current: unknown","ProxyEnvironment.make","OperationPath.make","Transaction.make"],"sources":["../src/Document.ts"],"sourcesContent":["import * as Operation from \"./Operation\";\nimport * as OperationPath from \"./OperationPath\";\nimport * as ProxyEnvironment from \"./ProxyEnvironment\";\nimport * as Transaction from \"./Transaction\";\nimport type * as Primitive from \"./Primitive\";\n\n// =============================================================================\n// Document Errors\n// =============================================================================\n\n/**\n * Error thrown when attempting to start a nested transaction.\n */\nexport class NestedTransactionError extends Error {\n readonly _tag = \"NestedTransactionError\";\n constructor() {\n super(\"Nested transactions are not supported\");\n this.name = \"NestedTransactionError\";\n }\n}\n\n/**\n * Error thrown when an operation fails to apply.\n */\nexport class OperationError extends Error {\n readonly _tag = \"OperationError\";\n constructor(message: string) {\n super(message);\n this.name = \"OperationError\";\n }\n}\n\n// =============================================================================\n// Document Interface\n// =============================================================================\n\n/**\n * A Document manages state for a primitive-based schema with transaction support.\n */\nexport interface Document<TSchema extends Primitive.AnyPrimitive> {\n /** The schema defining this document's structure */\n readonly schema: TSchema;\n \n /** Root proxy for accessing and modifying document data */\n readonly root: Primitive.InferProxy<TSchema>;\n \n /** Returns the current document state */\n get(): Primitive.InferState<TSchema> | undefined;\n \n /**\n * Returns a readonly snapshot of the entire document state for rendering.\n * The snapshot is a type-safe, readonly structure where:\n * - Required fields and fields with defaults are guaranteed to be defined\n * - Optional fields may be undefined\n */\n toSnapshot(): Primitive.InferSnapshot<TSchema>;\n \n /**\n * Runs a function within a transaction.\n * All operations are collected and applied atomically.\n * If the function throws, all changes are rolled back.\n * @returns The return value of the function\n */\n transaction<R>(fn: (root: Primitive.InferProxy<TSchema>) => R): R;\n \n /**\n * Applies external operations (e.g., from server/peers) to the document.\n * These operations are NOT added to pending operations.\n */\n apply(ops: ReadonlyArray<Operation.Operation<any, any, any>>): void;\n \n /**\n * Returns pending local operations as a Transaction and clears the buffer.\n */\n flush(): Transaction.Transaction;\n}\n\n// =============================================================================\n// Document Options\n// =============================================================================\n\nexport interface DocumentOptions<TSchema extends Primitive.AnyPrimitive> {\n /** Initial state for the document */\n readonly initial?: Primitive.InferState<TSchema>;\n}\n\n// =============================================================================\n// Document Implementation\n// =============================================================================\n\n/**\n * Creates a new Document for the given schema.\n */\nexport const make = <TSchema extends Primitive.AnyPrimitive>(\n schema: TSchema,\n options?: DocumentOptions<TSchema>\n): Document<TSchema> => {\n // Internal state\n let _state: Primitive.InferState<TSchema> | undefined = \n options?.initial ?? schema._internal.getInitialState();\n \n // Pending operations buffer (local changes not yet flushed)\n let _pending: Operation.Operation<any, any, any>[] = [];\n \n // Transaction state\n let _inTransaction = false;\n let _txOps: Operation.Operation<any, any, any>[] = [];\n let _txBaseState: Primitive.InferState<TSchema> | undefined = undefined;\n\n /**\n * Gets state at the given path.\n */\n const getStateAtPath = (path: OperationPath.OperationPath): unknown => {\n const tokens = path.toTokens().filter(t => t !== \"\");\n \n if (tokens.length === 0) {\n return _state;\n }\n \n let current: unknown = _state;\n for (const token of tokens) {\n if (current === null || current === undefined) {\n return undefined;\n }\n \n if (typeof current === \"object\") {\n // Handle array entries (which have { id, pos, value } structure)\n if (Array.isArray(current)) {\n // Try to find by ID in array entries\n const entry = current.find((e: any) => e.id === token);\n if (entry) {\n current = entry.value;\n continue;\n }\n }\n \n // Handle regular object property access\n current = (current as Record<string, unknown>)[token];\n } else {\n return undefined;\n }\n }\n \n return current;\n };\n\n /**\n * Applies a single operation to the current state.\n */\n const applyOperation = (op: Operation.Operation<any, any, any>): void => {\n try {\n _state = schema._internal.applyOperation(_state, op);\n } catch (error) {\n if (error instanceof Error) {\n throw new OperationError(error.message);\n }\n throw new OperationError(String(error));\n }\n };\n\n /**\n * Handles an operation from a proxy.\n * In transaction mode: collects operations, applies to state immediately for subsequent reads.\n * Outside transaction mode: auto-wraps in a single-operation transaction.\n */\n const handleOperation = (op: Operation.Operation<any, any, any>): void => {\n if (_inTransaction) {\n // In transaction: collect op and apply immediately for subsequent reads\n _txOps.push(op);\n applyOperation(op);\n } else {\n // Not in transaction: auto-wrap in single-operation transaction\n const baseState = _state;\n try {\n applyOperation(op);\n _pending.push(op);\n } catch (error) {\n // Rollback on error\n _state = baseState;\n throw error;\n }\n }\n };\n\n /**\n * Creates a ProxyEnvironment for the document.\n */\n const createEnv = (): ProxyEnvironment.ProxyEnvironment => {\n return ProxyEnvironment.make({\n onOperation: handleOperation,\n getState: getStateAtPath,\n });\n };\n\n // Create the root proxy\n const env = createEnv();\n const rootProxy = schema._internal.createProxy(env, OperationPath.make(\"\")) as Primitive.InferProxy<TSchema>;\n\n // Document implementation\n const document: Document<TSchema> = {\n schema,\n root: rootProxy,\n \n get: (): Primitive.InferState<TSchema> | undefined => {\n return _state;\n },\n \n toSnapshot: (): Primitive.InferSnapshot<TSchema> => {\n return (rootProxy as { toSnapshot(): Primitive.InferSnapshot<TSchema> }).toSnapshot();\n },\n \n transaction: <R,>(fn: (root: Primitive.InferProxy<TSchema>) => R): R => {\n if (_inTransaction) {\n throw new NestedTransactionError();\n }\n \n // Start transaction\n _inTransaction = true;\n _txOps = [];\n _txBaseState = _state;\n \n try {\n // Execute the transaction function\n const result = fn(rootProxy);\n \n // Commit: add transaction ops to pending\n _pending.push(..._txOps);\n \n return result;\n } catch (error) {\n // Rollback: restore base state\n _state = _txBaseState;\n throw error;\n } finally {\n // Clean up transaction state\n _inTransaction = false;\n _txOps = [];\n _txBaseState = undefined;\n }\n },\n \n apply: (ops: ReadonlyArray<Operation.Operation<any, any, any>>): void => {\n for (const op of ops) {\n applyOperation(op);\n }\n },\n \n flush: (): Transaction.Transaction => {\n const tx = Transaction.make(_pending);\n _pending = [];\n return tx;\n },\n };\n\n return document;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,yBAAb,cAA4C,MAAM;CAEhD,cAAc;AACZ,QAAM,wCAAwC;wBAFvC,QAAO;AA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GACX,CAAC;;CAIJ,MAAM,MAAM,WAAW;CACvB,MAAM,YAAY,OAAO,UAAU,YAAY,KAAKC,OAAmB,GAAG,CAAC;AA0D3E,QAvDoC;EAClC;EACA,MAAM;EAEN,WAAsD;AACpD,UAAO;;EAGT,kBAAoD;AAClD,UAAQ,UAAiE,YAAY;;EAGvF,cAAkB,OAAsD;AACtE,OAAI,eACF,OAAM,IAAI,wBAAwB;AAIpC,oBAAiB;AACjB,YAAS,EAAE;AACX,kBAAe;AAEf,OAAI;IAEF,MAAM,SAAS,GAAG,UAAU;AAG5B,aAAS,KAAK,GAAG,OAAO;AAExB,WAAO;YACA,OAAO;AAEd,aAAS;AACT,UAAM;aACE;AAER,qBAAiB;AACjB,aAAS,EAAE;AACX,mBAAe;;;EAInB,QAAQ,QAAiE;AACvE,QAAK,MAAM,MAAM,IACf,gBAAe,GAAG;;EAItB,aAAsC;GACpC,MAAM,KAAKC,OAAiB,SAAS;AACrC,cAAW,EAAE;AACb,UAAO;;EAEV"}
|
|
1
|
+
{"version":3,"file":"Document.mjs","names":["_state: Primitive.InferState<TSchema> | undefined","_pending: Operation.Operation<any, any, any>[]","_txOps: Operation.Operation<any, any, any>[]","_txBaseState: Primitive.InferState<TSchema> | undefined","current: unknown","ProxyEnvironment.make","OperationPath.make","Transaction.make"],"sources":["../src/Document.ts"],"sourcesContent":["import * as Operation from \"./Operation\";\nimport * as OperationPath from \"./OperationPath\";\nimport * as ProxyEnvironment from \"./ProxyEnvironment\";\nimport * as Transaction from \"./Transaction\";\nimport type * as Primitive from \"./Primitive\";\n\n// =============================================================================\n// Document Errors\n// =============================================================================\n\n/**\n * Error thrown when attempting to start a nested transaction.\n */\nexport class NestedTransactionError extends Error {\n readonly _tag = \"NestedTransactionError\";\n constructor() {\n super(\"Nested transactions are not supported\");\n this.name = \"NestedTransactionError\";\n }\n}\n\n/**\n * Error thrown when an operation fails to apply.\n */\nexport class OperationError extends Error {\n readonly _tag = \"OperationError\";\n constructor(message: string) {\n super(message);\n this.name = \"OperationError\";\n }\n}\n\n// =============================================================================\n// Document Interface\n// =============================================================================\n\n/**\n * A Document manages state for a primitive-based schema with transaction support.\n */\nexport interface Document<TSchema extends Primitive.AnyPrimitive> {\n /** The schema defining this document's structure */\n readonly schema: TSchema;\n \n /** Root proxy for accessing and modifying document data */\n readonly root: Primitive.InferProxy<TSchema>;\n \n /** Returns the current document state */\n get(): Primitive.InferState<TSchema> | undefined;\n \n /**\n * Returns a readonly snapshot of the entire document state for rendering.\n * The snapshot is a type-safe, readonly structure where:\n * - Required fields and fields with defaults are guaranteed to be defined\n * - Optional fields may be undefined\n */\n toSnapshot(): Primitive.InferSnapshot<TSchema>;\n \n /**\n * Runs a function within a transaction.\n * All operations are collected and applied atomically.\n * If the function throws, all changes are rolled back.\n * @returns The return value of the function\n */\n transaction<R>(fn: (root: Primitive.InferProxy<TSchema>) => R): R;\n \n /**\n * Applies external operations (e.g., from server/peers) to the document.\n * These operations are NOT added to pending operations.\n */\n apply(ops: ReadonlyArray<Operation.Operation<any, any, any>>): void;\n \n /**\n * Returns pending local operations as a Transaction and clears the buffer.\n */\n flush(): Transaction.Transaction;\n}\n\n// =============================================================================\n// Document Options\n// =============================================================================\n\nexport interface DocumentOptions<TSchema extends Primitive.AnyPrimitive> {\n /** Initial value for the document (using set input format) */\n readonly initial?: Primitive.InferSetInput<TSchema>;\n /**\n * Raw initial state for the document (already in internal state format).\n * Use this when loading state from the server or storage.\n * Takes precedence over `initial` if both are provided.\n */\n readonly initialState?: Primitive.InferState<TSchema>;\n}\n\n// =============================================================================\n// Document Implementation\n// =============================================================================\n\n/**\n * Creates a new Document for the given schema.\n */\nexport const make = <TSchema extends Primitive.AnyPrimitive>(\n schema: TSchema,\n options?: DocumentOptions<TSchema>\n): Document<TSchema> => {\n // Internal state - determine initial state based on options\n // Priority: initialState (raw) > initial (needs conversion) > schema defaults\n let _state: Primitive.InferState<TSchema> | undefined =\n options?.initialState !== undefined\n ? options.initialState\n : options?.initial !== undefined\n ? (schema._internal.convertSetInputToState\n ? schema._internal.convertSetInputToState(options.initial)\n : options.initial as Primitive.InferState<TSchema>)\n : schema._internal.getInitialState();\n \n // Pending operations buffer (local changes not yet flushed)\n let _pending: Operation.Operation<any, any, any>[] = [];\n \n // Transaction state\n let _inTransaction = false;\n let _txOps: Operation.Operation<any, any, any>[] = [];\n let _txBaseState: Primitive.InferState<TSchema> | undefined = undefined;\n\n /**\n * Gets state at the given path.\n */\n const getStateAtPath = (path: OperationPath.OperationPath): unknown => {\n const tokens = path.toTokens().filter(t => t !== \"\");\n \n if (tokens.length === 0) {\n return _state;\n }\n \n let current: unknown = _state;\n for (const token of tokens) {\n if (current === null || current === undefined) {\n return undefined;\n }\n \n if (typeof current === \"object\") {\n // Handle array entries (which have { id, pos, value } structure)\n if (Array.isArray(current)) {\n // Try to find by ID in array entries\n const entry = current.find((e: any) => e.id === token);\n if (entry) {\n current = entry.value;\n continue;\n }\n }\n \n // Handle regular object property access\n current = (current as Record<string, unknown>)[token];\n } else {\n return undefined;\n }\n }\n \n return current;\n };\n\n /**\n * Applies a single operation to the current state.\n */\n const applyOperation = (op: Operation.Operation<any, any, any>): void => {\n try {\n _state = schema._internal.applyOperation(_state, op);\n } catch (error) {\n if (error instanceof Error) {\n throw new OperationError(error.message);\n }\n throw new OperationError(String(error));\n }\n };\n\n /**\n * Handles an operation from a proxy.\n * In transaction mode: collects operations, applies to state immediately for subsequent reads.\n * Outside transaction mode: auto-wraps in a single-operation transaction.\n */\n const handleOperation = (op: Operation.Operation<any, any, any>): void => {\n if (_inTransaction) {\n // In transaction: collect op and apply immediately for subsequent reads\n _txOps.push(op);\n applyOperation(op);\n } else {\n // Not in transaction: auto-wrap in single-operation transaction\n const baseState = _state;\n try {\n applyOperation(op);\n _pending.push(op);\n } catch (error) {\n // Rollback on error\n _state = baseState;\n throw error;\n }\n }\n };\n\n /**\n * Creates a ProxyEnvironment for the document.\n */\n const createEnv = (): ProxyEnvironment.ProxyEnvironment => {\n return ProxyEnvironment.make({\n onOperation: handleOperation,\n getState: getStateAtPath,\n });\n };\n\n // Create the root proxy\n const env = createEnv();\n const rootProxy = schema._internal.createProxy(env, OperationPath.make(\"\")) as Primitive.InferProxy<TSchema>;\n\n // Document implementation\n const document: Document<TSchema> = {\n schema,\n root: rootProxy,\n \n get: (): Primitive.InferState<TSchema> | undefined => {\n return _state;\n },\n \n toSnapshot: (): Primitive.InferSnapshot<TSchema> => {\n return (rootProxy as { toSnapshot(): Primitive.InferSnapshot<TSchema> }).toSnapshot();\n },\n \n transaction: <R,>(fn: (root: Primitive.InferProxy<TSchema>) => R): R => {\n if (_inTransaction) {\n throw new NestedTransactionError();\n }\n \n // Start transaction\n _inTransaction = true;\n _txOps = [];\n _txBaseState = _state;\n \n try {\n // Execute the transaction function\n const result = fn(rootProxy);\n \n // Commit: add transaction ops to pending\n _pending.push(..._txOps);\n \n return result;\n } catch (error) {\n // Rollback: restore base state\n _state = _txBaseState;\n throw error;\n } finally {\n // Clean up transaction state\n _inTransaction = false;\n _txOps = [];\n _txBaseState = undefined;\n }\n },\n \n apply: (ops: ReadonlyArray<Operation.Operation<any, any, any>>): void => {\n for (const op of ops) {\n applyOperation(op);\n }\n },\n \n flush: (): Transaction.Transaction => {\n const tx = Transaction.make(_pending);\n _pending = [];\n return tx;\n },\n };\n\n return document;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,yBAAb,cAA4C,MAAM;CAEhD,cAAc;AACZ,QAAM,wCAAwC;wBAFvC,QAAO;AAGd,OAAK,OAAO;;;;;;AAOhB,IAAa,iBAAb,cAAoC,MAAM;CAExC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;wBAFP,QAAO;AAGd,OAAK,OAAO;;;;;;AAuEhB,MAAa,QACX,QACA,YACsB;CAGtB,IAAIA,4DACF,QAAS,kBAAiB,SACtB,QAAQ,kEACR,QAAS,aAAY,SAClB,OAAO,UAAU,yBACd,OAAO,UAAU,uBAAuB,QAAQ,QAAQ,GACxD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AQ,UAAiE,YAAY;;EAGvF,cAAkB,OAAsD;AACtE,OAAI,eACF,OAAM,IAAI,wBAAwB;AAIpC,oBAAiB;AACjB,YAAS,EAAE;AACX,kBAAe;AAEf,OAAI;IAEF,MAAM,SAAS,GAAG,UAAU;AAG5B,aAAS,KAAK,GAAG,OAAO;AAExB,WAAO;YACA,OAAO;AAEd,aAAS;AACT,UAAM;aACE;AAER,qBAAiB;AACjB,aAAS,EAAE;AACX,mBAAe;;;EAInB,QAAQ,QAAiE;AACvE,QAAK,MAAM,MAAM,IACf,gBAAe,GAAG;;EAItB,aAAsC;GACpC,MAAM,KAAKC,OAAiB,SAAS;AACrC,cAAW,EAAE;AACb,UAAO;;EAEV"}
|
package/dist/Presence.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Presence.d.mts","names":[],"sources":["../src/Presence.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAeiB;;;mBAGE,MAAA,CAAO,OAAO;;EAHhB,SAAA,KAAQ,EAKP,KALO;;;;;AAWR,UAAA,eAAe,CAAA,
|
|
1
|
+
{"version":3,"file":"Presence.d.mts","names":[],"sources":["../src/Presence.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAeiB;;;mBAGE,MAAA,CAAO,OAAO;;EAHhB,SAAA,KAAQ,EAKP,KALO;;;;;AAWR,UAAA,eAAe,CAAA,KAEC,CAAA,CAAA;EAMrB;EAKA,SAAA,MAAW,EAXJ,MAAA,CAAO,MAWA,CAXO,KAWC,CAAA;AASlC;AA8BA;;;AAAwE,KA5C5D,KA4C4D,CAAA,UA5C5C,QA4C4C,CAAA,GAAA,CAAA,CAAA,GA5C3B,CA4C2B,CAAA,OAAA,CAAA;;;AAmBxE;AACqB,KA3DT,WAAA,GAAc,QA2DL,CAAA,GAAA,CAAA;;;;AAcR,UAhEI,aAyEhB,CAAA,QAAA,OAAA,CAAA,CAAA;EARoB;EAAT,SAAA,IAAA,EA/DK,KA+DL;EAET;EAAK,SAAA,MAAA,CAAA,EAAA,MAAA;AAeR;;;;;;;;;;;;;;;;;;;;cApDa,uBAAyB,gBAAgB,WAAS,SAAS;;;;;;;;;;cAmB3D,4BACD,SAAS,0BAElB;;;;;;;;;cAYU,gCACD,SAAS,0BAElB;;;;;;;;cAeU,2BACD,SAAS,kCAEV"}
|
package/dist/Primitive.d.cts
CHANGED
|
@@ -9,11 +9,11 @@ import { InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, I
|
|
|
9
9
|
import { InferUnionSnapshot, InferUnionState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants } from "./primitives/Union.cjs";
|
|
10
10
|
import { Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, InferEitherSnapshot, InferEitherState, ScalarPrimitive } from "./primitives/Either.cjs";
|
|
11
11
|
import { AnyTreeNodePrimitive, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodePrimitive, TreeNodeSelf, TreeNodeSelfType } from "./primitives/TreeNode.cjs";
|
|
12
|
-
import { InferTreeSnapshot, Tree, TreeNodeDataSetInput, TreeNodeProxyBase, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState } from "./primitives/Tree.cjs";
|
|
12
|
+
import { InferTreeSetInput, InferTreeSnapshot, Tree, TreeNodeDataSetInput, TreeNodeProxyBase, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState } from "./primitives/Tree.cjs";
|
|
13
13
|
|
|
14
14
|
//#region src/Primitive.d.ts
|
|
15
15
|
declare namespace Primitive_d_exports {
|
|
16
|
-
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators };
|
|
16
|
+
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSetInput, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators };
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
export { Primitive_d_exports };
|
package/dist/Primitive.d.mts
CHANGED
|
@@ -9,11 +9,11 @@ import { InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, I
|
|
|
9
9
|
import { InferUnionSnapshot, InferUnionState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants } from "./primitives/Union.mjs";
|
|
10
10
|
import { Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, InferEitherSnapshot, InferEitherState, ScalarPrimitive } from "./primitives/Either.mjs";
|
|
11
11
|
import { AnyTreeNodePrimitive, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodePrimitive, TreeNodeSelf, TreeNodeSelfType } from "./primitives/TreeNode.mjs";
|
|
12
|
-
import { InferTreeSnapshot, Tree, TreeNodeDataSetInput, TreeNodeProxyBase, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState } from "./primitives/Tree.mjs";
|
|
12
|
+
import { InferTreeSetInput, InferTreeSnapshot, Tree, TreeNodeDataSetInput, TreeNodeProxyBase, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState } from "./primitives/Tree.mjs";
|
|
13
13
|
|
|
14
14
|
//#region src/Primitive.d.ts
|
|
15
15
|
declare namespace Primitive_d_exports {
|
|
16
|
-
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators };
|
|
16
|
+
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSetInput, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators };
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
export { Primitive_d_exports };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const require_objectWithoutPropertiesLoose = require('./objectWithoutPropertiesLoose.cjs');
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutProperties.js
|
|
4
|
+
function _objectWithoutProperties(e, t) {
|
|
5
|
+
if (null == e) return {};
|
|
6
|
+
var o, r, i = require_objectWithoutPropertiesLoose._objectWithoutPropertiesLoose(e, t);
|
|
7
|
+
if (Object.getOwnPropertySymbols) {
|
|
8
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
9
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
10
|
+
}
|
|
11
|
+
return i;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports._objectWithoutProperties = _objectWithoutProperties;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { _objectWithoutPropertiesLoose } from "./objectWithoutPropertiesLoose.mjs";
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutProperties.js
|
|
4
|
+
function _objectWithoutProperties(e, t) {
|
|
5
|
+
if (null == e) return {};
|
|
6
|
+
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
7
|
+
if (Object.getOwnPropertySymbols) {
|
|
8
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
9
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
10
|
+
}
|
|
11
|
+
return i;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { _objectWithoutProperties };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutPropertiesLoose.js
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
4
|
+
if (null == r) return {};
|
|
5
|
+
var t = {};
|
|
6
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
7
|
+
if (e.includes(n)) continue;
|
|
8
|
+
t[n] = r[n];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports._objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutPropertiesLoose.js
|
|
2
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
3
|
+
if (null == r) return {};
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
6
|
+
if (e.includes(n)) continue;
|
|
7
|
+
t[n] = r[n];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { _objectWithoutPropertiesLoose };
|
|
@@ -18,7 +18,7 @@ const make = (options) => {
|
|
|
18
18
|
let _pending = [];
|
|
19
19
|
let _serverTransactionHistory = [];
|
|
20
20
|
const MAX_HISTORY_SIZE = 100;
|
|
21
|
-
let _optimisticDoc = require_Document.make(schema, {
|
|
21
|
+
let _optimisticDoc = require_Document.make(schema, { initialState: _serverState });
|
|
22
22
|
let _unsubscribe = null;
|
|
23
23
|
const _timeoutHandles = /* @__PURE__ */ new Map();
|
|
24
24
|
let _initState = initialState !== void 0 ? { type: "ready" } : { type: "uninitialized" };
|
|
@@ -146,7 +146,7 @@ const make = (options) => {
|
|
|
146
146
|
pendingCount: _pending.length,
|
|
147
147
|
serverState: _serverState
|
|
148
148
|
});
|
|
149
|
-
_optimisticDoc = require_Document.make(schema, {
|
|
149
|
+
_optimisticDoc = require_Document.make(schema, { initialState: _serverState });
|
|
150
150
|
for (const pending of _pending) _optimisticDoc.apply(pending.transaction.ops);
|
|
151
151
|
const newState = _optimisticDoc.get();
|
|
152
152
|
debugLog("recomputeOptimisticState: new optimistic state", newState);
|
|
@@ -154,13 +154,14 @@ const make = (options) => {
|
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Adds a transaction to pending queue and sends to server.
|
|
157
|
+
* If disconnected, the transport will queue it for later submission.
|
|
157
158
|
*/
|
|
158
159
|
const submitTransaction = (tx) => {
|
|
159
|
-
if (!transport.isConnected()) throw new require_errors.NotConnectedError();
|
|
160
160
|
debugLog("submitTransaction", {
|
|
161
161
|
txId: tx.id,
|
|
162
162
|
ops: tx.ops,
|
|
163
|
-
pendingCount: _pending.length + 1
|
|
163
|
+
pendingCount: _pending.length + 1,
|
|
164
|
+
isConnected: transport.isConnected()
|
|
164
165
|
});
|
|
165
166
|
const pending = {
|
|
166
167
|
transaction: tx,
|
|
@@ -168,12 +169,17 @@ const make = (options) => {
|
|
|
168
169
|
sentAt: Date.now()
|
|
169
170
|
};
|
|
170
171
|
_pending.push(pending);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
if (transport.isConnected()) {
|
|
173
|
+
const timeoutHandle = setTimeout(() => {
|
|
174
|
+
handleTransactionTimeout(tx.id);
|
|
175
|
+
}, transactionTimeout);
|
|
176
|
+
_timeoutHandles.set(tx.id, timeoutHandle);
|
|
177
|
+
}
|
|
175
178
|
transport.send(tx);
|
|
176
|
-
debugLog("submitTransaction: sent to
|
|
179
|
+
debugLog("submitTransaction: sent to transport", {
|
|
180
|
+
txId: tx.id,
|
|
181
|
+
queued: !transport.isConnected()
|
|
182
|
+
});
|
|
177
183
|
};
|
|
178
184
|
/**
|
|
179
185
|
* Handles a transaction timeout.
|
|
@@ -219,7 +225,7 @@ const make = (options) => {
|
|
|
219
225
|
_timeoutHandles.delete(serverTx.id);
|
|
220
226
|
}
|
|
221
227
|
_pending.splice(pendingIndex, 1);
|
|
222
|
-
const tempDoc = require_Document.make(schema, {
|
|
228
|
+
const tempDoc = require_Document.make(schema, { initialState: _serverState });
|
|
223
229
|
tempDoc.apply(serverTx.ops);
|
|
224
230
|
_serverState = tempDoc.get();
|
|
225
231
|
debugLog("handleServerTransaction: updated server state", {
|
|
@@ -233,7 +239,7 @@ const make = (options) => {
|
|
|
233
239
|
txId: serverTx.id,
|
|
234
240
|
pendingCount: _pending.length
|
|
235
241
|
});
|
|
236
|
-
const tempDoc = require_Document.make(schema, {
|
|
242
|
+
const tempDoc = require_Document.make(schema, { initialState: _serverState });
|
|
237
243
|
tempDoc.apply(serverTx.ops);
|
|
238
244
|
_serverState = tempDoc.get();
|
|
239
245
|
_serverTransactionHistory.push(serverTx);
|
|
@@ -457,7 +463,6 @@ const make = (options) => {
|
|
|
457
463
|
isReady: _initState.type === "ready",
|
|
458
464
|
pendingCount: _pending.length
|
|
459
465
|
});
|
|
460
|
-
if (!transport.isConnected()) throw new require_errors.NotConnectedError();
|
|
461
466
|
if (_initState.type !== "ready") throw new require_errors.InvalidStateError("Client is not ready. Wait for initialization to complete.");
|
|
462
467
|
const result = _optimisticDoc.transaction(fn);
|
|
463
468
|
const tx = _optimisticDoc.flush();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientDocument.d.mts","names":[],"sources":["../../src/client/ClientDocument.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;UA6CiB;;;;;;;UAQA;;AARjB;AAQA;;EAiBoE,SAAA,MAAA,EAAA,GAAA,GAAA,MAAA,GAAA,SAAA;EAAvB;;;;EAKvB,SAAA,IAAA,EAAA,GAAA,GAXC,KAWD,GAAA,SAAA;EAOC;;;;EAiBN,SAAA,MAAA,EAAA,GAAA,GA7BQ,WA6Ba,CAAA,MAAA,EA7BO,aA6BP,CA7B8B,KA6B9B,CAAA,CAAA;EACpB;;;EAMI,SAAA,GAAA,EAAA,GAAA,GA/BA,WA+BA,CAAA,MAAA,EA/BoB,aA+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Am6BZ,WAAA,CAAA,EAAA,MAAA;EAl6BiB;EACE,SAAA,KAAA,CAAA,EAAA,OAAA;EAEa;;;;EACN,SAAA,QAAA,CAAA,EAvGL,SAuGK;EAAxB;EAAc,SAAA,eAAA,CAAA,EArGY,SAqGZ,SArG8B,WAqG9B,GArGqD,KAqGrD,CArGoE,SAqGpE,CAAA,GAAA,SAAA;;;;;UA/FA,uCAAuC;;mCAErB,WAAqB;;;;;;;;;UAUvC,+BACC,gCACE;;mBAGD;;iBAGF,WAAqB;;SAG7B,WAAqB;;oBAGV,WAAqB;;;;;;;;;;;4BAeb,WAAqB,aAAa,IAAI;;;;aAKrD;;;;;;;;;;;;;;;;;;;;;sBA0BS,uBAAuB;;;;;qBAMxB,kBAAkB,cACjC,eAAe,MAAe;;;;;cAWvB,uBACK,gCACE,8CAET,sBAAsB,SAAS,eACvC,eAAe,SAAS"}
|
|
@@ -18,7 +18,7 @@ const make = (options) => {
|
|
|
18
18
|
let _pending = [];
|
|
19
19
|
let _serverTransactionHistory = [];
|
|
20
20
|
const MAX_HISTORY_SIZE = 100;
|
|
21
|
-
let _optimisticDoc = make$1(schema, {
|
|
21
|
+
let _optimisticDoc = make$1(schema, { initialState: _serverState });
|
|
22
22
|
let _unsubscribe = null;
|
|
23
23
|
const _timeoutHandles = /* @__PURE__ */ new Map();
|
|
24
24
|
let _initState = initialState !== void 0 ? { type: "ready" } : { type: "uninitialized" };
|
|
@@ -146,7 +146,7 @@ const make = (options) => {
|
|
|
146
146
|
pendingCount: _pending.length,
|
|
147
147
|
serverState: _serverState
|
|
148
148
|
});
|
|
149
|
-
_optimisticDoc = make$1(schema, {
|
|
149
|
+
_optimisticDoc = make$1(schema, { initialState: _serverState });
|
|
150
150
|
for (const pending of _pending) _optimisticDoc.apply(pending.transaction.ops);
|
|
151
151
|
const newState = _optimisticDoc.get();
|
|
152
152
|
debugLog("recomputeOptimisticState: new optimistic state", newState);
|
|
@@ -154,13 +154,14 @@ const make = (options) => {
|
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Adds a transaction to pending queue and sends to server.
|
|
157
|
+
* If disconnected, the transport will queue it for later submission.
|
|
157
158
|
*/
|
|
158
159
|
const submitTransaction = (tx) => {
|
|
159
|
-
if (!transport.isConnected()) throw new NotConnectedError();
|
|
160
160
|
debugLog("submitTransaction", {
|
|
161
161
|
txId: tx.id,
|
|
162
162
|
ops: tx.ops,
|
|
163
|
-
pendingCount: _pending.length + 1
|
|
163
|
+
pendingCount: _pending.length + 1,
|
|
164
|
+
isConnected: transport.isConnected()
|
|
164
165
|
});
|
|
165
166
|
const pending = {
|
|
166
167
|
transaction: tx,
|
|
@@ -168,12 +169,17 @@ const make = (options) => {
|
|
|
168
169
|
sentAt: Date.now()
|
|
169
170
|
};
|
|
170
171
|
_pending.push(pending);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
if (transport.isConnected()) {
|
|
173
|
+
const timeoutHandle = setTimeout(() => {
|
|
174
|
+
handleTransactionTimeout(tx.id);
|
|
175
|
+
}, transactionTimeout);
|
|
176
|
+
_timeoutHandles.set(tx.id, timeoutHandle);
|
|
177
|
+
}
|
|
175
178
|
transport.send(tx);
|
|
176
|
-
debugLog("submitTransaction: sent to
|
|
179
|
+
debugLog("submitTransaction: sent to transport", {
|
|
180
|
+
txId: tx.id,
|
|
181
|
+
queued: !transport.isConnected()
|
|
182
|
+
});
|
|
177
183
|
};
|
|
178
184
|
/**
|
|
179
185
|
* Handles a transaction timeout.
|
|
@@ -219,7 +225,7 @@ const make = (options) => {
|
|
|
219
225
|
_timeoutHandles.delete(serverTx.id);
|
|
220
226
|
}
|
|
221
227
|
_pending.splice(pendingIndex, 1);
|
|
222
|
-
const tempDoc = make$1(schema, {
|
|
228
|
+
const tempDoc = make$1(schema, { initialState: _serverState });
|
|
223
229
|
tempDoc.apply(serverTx.ops);
|
|
224
230
|
_serverState = tempDoc.get();
|
|
225
231
|
debugLog("handleServerTransaction: updated server state", {
|
|
@@ -233,7 +239,7 @@ const make = (options) => {
|
|
|
233
239
|
txId: serverTx.id,
|
|
234
240
|
pendingCount: _pending.length
|
|
235
241
|
});
|
|
236
|
-
const tempDoc = make$1(schema, {
|
|
242
|
+
const tempDoc = make$1(schema, { initialState: _serverState });
|
|
237
243
|
tempDoc.apply(serverTx.ops);
|
|
238
244
|
_serverState = tempDoc.get();
|
|
239
245
|
_serverTransactionHistory.push(serverTx);
|
|
@@ -457,7 +463,6 @@ const make = (options) => {
|
|
|
457
463
|
isReady: _initState.type === "ready",
|
|
458
464
|
pendingCount: _pending.length
|
|
459
465
|
});
|
|
460
|
-
if (!transport.isConnected()) throw new NotConnectedError();
|
|
461
466
|
if (_initState.type !== "ready") throw new InvalidStateError("Client is not ready. Wait for initialization to complete.");
|
|
462
467
|
const result = _optimisticDoc.transaction(fn);
|
|
463
468
|
const tx = _optimisticDoc.flush();
|