@voidhash/mimic 0.0.1-alpha.1 → 0.0.1-alpha.111
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 +51 -0
- package/LICENSE.md +663 -0
- package/dist/Document-ChuFrTk1.cjs +571 -0
- package/dist/Document-CwiAFTIq.mjs +438 -0
- package/dist/Document-CwiAFTIq.mjs.map +1 -0
- package/dist/Presence-DKKP4v5X.d.cts +91 -0
- package/dist/Presence-DKKP4v5X.d.cts.map +1 -0
- package/dist/Presence-DdMVKcOv.mjs +110 -0
- package/dist/Presence-DdMVKcOv.mjs.map +1 -0
- package/dist/Presence-N8u7Eppr.d.mts +91 -0
- package/dist/Presence-N8u7Eppr.d.mts.map +1 -0
- package/dist/Presence-gWrmGBeu.cjs +126 -0
- package/dist/Primitive-CvFVxR8_.d.cts +1175 -0
- package/dist/Primitive-CvFVxR8_.d.cts.map +1 -0
- package/dist/Primitive-lEhQyGVL.d.mts +1175 -0
- package/dist/Primitive-lEhQyGVL.d.mts.map +1 -0
- package/dist/chunk-CLMFDpHK.mjs +18 -0
- package/dist/client/index.cjs +1456 -0
- package/dist/client/index.d.cts +692 -0
- package/dist/client/index.d.cts.map +1 -0
- package/dist/client/index.d.mts +692 -0
- package/dist/client/index.d.mts.map +1 -0
- package/dist/client/index.mjs +1413 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.cjs +2577 -0
- package/dist/index.d.cts +143 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +143 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2526 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server/index.cjs +191 -0
- package/dist/server/index.d.cts +148 -0
- package/dist/server/index.d.cts.map +1 -0
- package/dist/server/index.d.mts +148 -0
- package/dist/server/index.d.mts.map +1 -0
- package/dist/server/index.mjs +182 -0
- package/dist/server/index.mjs.map +1 -0
- package/package.json +25 -13
- package/src/EffectSchema.ts +374 -0
- package/src/Primitive.ts +3 -0
- package/src/client/ClientDocument.ts +1 -1
- package/src/client/errors.ts +10 -10
- package/src/index.ts +1 -0
- package/src/primitives/Array.ts +57 -22
- package/src/primitives/Boolean.ts +33 -19
- package/src/primitives/Either.ts +379 -0
- package/src/primitives/Lazy.ts +16 -2
- package/src/primitives/Literal.ts +33 -20
- package/src/primitives/Number.ts +39 -26
- package/src/primitives/String.ts +40 -25
- package/src/primitives/Struct.ts +126 -29
- package/src/primitives/Tree.ts +119 -32
- package/src/primitives/TreeNode.ts +77 -30
- package/src/primitives/Union.ts +56 -29
- package/src/primitives/shared.ts +111 -9
- package/src/server/errors.ts +6 -6
- package/tests/EffectSchema.test.ts +546 -0
- package/tests/primitives/Array.test.ts +108 -0
- package/tests/primitives/Either.test.ts +707 -0
- package/tests/primitives/Struct.test.ts +250 -0
- package/tests/primitives/Tree.test.ts +250 -0
- package/tsdown.config.ts +1 -1
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (all, symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) {
|
|
11
|
+
__defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (symbols) {
|
|
17
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
36
|
+
value: mod,
|
|
37
|
+
enumerable: true
|
|
38
|
+
}) : target, mod));
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
|
|
42
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
43
|
+
function _typeof(o) {
|
|
44
|
+
"@babel/helpers - typeof";
|
|
45
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
46
|
+
return typeof o$1;
|
|
47
|
+
} : function(o$1) {
|
|
48
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
49
|
+
}, _typeof(o);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
54
|
+
function toPrimitive(t, r) {
|
|
55
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
56
|
+
var e = t[Symbol.toPrimitive];
|
|
57
|
+
if (void 0 !== e) {
|
|
58
|
+
var i = e.call(t, r || "default");
|
|
59
|
+
if ("object" != _typeof(i)) return i;
|
|
60
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
61
|
+
}
|
|
62
|
+
return ("string" === r ? String : Number)(t);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
67
|
+
function toPropertyKey(t) {
|
|
68
|
+
var i = toPrimitive(t, "string");
|
|
69
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
74
|
+
function _defineProperty(e, r, t) {
|
|
75
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
76
|
+
value: t,
|
|
77
|
+
enumerable: !0,
|
|
78
|
+
configurable: !0,
|
|
79
|
+
writable: !0
|
|
80
|
+
}) : e[r] = t, e;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/OperationPath.ts
|
|
85
|
+
var OperationPath_exports = /* @__PURE__ */ __export({
|
|
86
|
+
decode: () => decode$2,
|
|
87
|
+
encode: () => encode$2,
|
|
88
|
+
fromTokens: () => fromTokens,
|
|
89
|
+
getRelativePath: () => getRelativePath,
|
|
90
|
+
isPrefix: () => isPrefix,
|
|
91
|
+
make: () => make$3,
|
|
92
|
+
pathsEqual: () => pathsEqual,
|
|
93
|
+
pathsOverlap: () => pathsOverlap
|
|
94
|
+
});
|
|
95
|
+
const parseStringPath = (stringPath) => {
|
|
96
|
+
return stringPath.split("/");
|
|
97
|
+
};
|
|
98
|
+
const makeStringPathFromTokens = (tokens) => {
|
|
99
|
+
return tokens.join("/");
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new operation path.
|
|
103
|
+
* @param stringPath - The string path to create the path from.
|
|
104
|
+
* @returns The new operation path.
|
|
105
|
+
*/
|
|
106
|
+
function make$3(stringPath) {
|
|
107
|
+
const tokensInternal = stringPath ? parseStringPath(stringPath) : [];
|
|
108
|
+
/**
|
|
109
|
+
* Returns the tokens of the path.
|
|
110
|
+
* @returns The tokens of the path.
|
|
111
|
+
*/
|
|
112
|
+
const toTokens = () => {
|
|
113
|
+
return tokensInternal;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Concatenates two paths.
|
|
117
|
+
* @param other - The other path to concatenate.
|
|
118
|
+
* @returns The new path.
|
|
119
|
+
*/
|
|
120
|
+
const concat = (other) => {
|
|
121
|
+
return make$3(makeStringPathFromTokens(toTokens().concat(other.toTokens())));
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Appends a token to the path.
|
|
125
|
+
* @param token - The token to append.
|
|
126
|
+
* @returns The new path.
|
|
127
|
+
*/
|
|
128
|
+
const append = (token) => {
|
|
129
|
+
return make$3(makeStringPathFromTokens(toTokens().concat([token])));
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Removes the last token from the path.
|
|
133
|
+
* @returns The new path.
|
|
134
|
+
*/
|
|
135
|
+
const pop = () => {
|
|
136
|
+
return make$3(makeStringPathFromTokens(toTokens().slice(0, -1)));
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Removes the first token from the path.
|
|
140
|
+
* @returns The new path.
|
|
141
|
+
*/
|
|
142
|
+
const shift = () => {
|
|
143
|
+
return make$3(makeStringPathFromTokens(toTokens().slice(1)));
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
_tag: "OperationPath",
|
|
147
|
+
toTokens,
|
|
148
|
+
concat,
|
|
149
|
+
append,
|
|
150
|
+
pop,
|
|
151
|
+
shift
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new operation path from tokens.
|
|
156
|
+
* @param tokens - The tokens to create the path from.
|
|
157
|
+
* @returns The new operation path.
|
|
158
|
+
*/
|
|
159
|
+
function fromTokens(tokens) {
|
|
160
|
+
return make$3(makeStringPathFromTokens(tokens));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if two operation paths overlap (one is prefix of the other or equal).
|
|
164
|
+
*/
|
|
165
|
+
const pathsOverlap = (pathA, pathB) => {
|
|
166
|
+
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
167
|
+
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
168
|
+
const minLength = Math.min(tokensA.length, tokensB.length);
|
|
169
|
+
for (let i = 0; i < minLength; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
170
|
+
return true;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Checks if pathA is a prefix of pathB (pathA is ancestor of pathB).
|
|
174
|
+
*/
|
|
175
|
+
const isPrefix = (pathA, pathB) => {
|
|
176
|
+
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
177
|
+
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
178
|
+
if (tokensA.length > tokensB.length) return false;
|
|
179
|
+
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
180
|
+
return true;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Checks if two paths are exactly equal.
|
|
184
|
+
*/
|
|
185
|
+
const pathsEqual = (pathA, pathB) => {
|
|
186
|
+
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
187
|
+
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
188
|
+
if (tokensA.length !== tokensB.length) return false;
|
|
189
|
+
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
190
|
+
return true;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Gets the relative path of pathB with respect to pathA.
|
|
194
|
+
* Assumes pathA is a prefix of pathB.
|
|
195
|
+
*/
|
|
196
|
+
const getRelativePath = (basePath, fullPath) => {
|
|
197
|
+
const baseTokens = basePath.toTokens().filter((t) => t !== "");
|
|
198
|
+
return fullPath.toTokens().filter((t) => t !== "").slice(baseTokens.length);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Encodes an OperationPath to a string for network transport.
|
|
202
|
+
* @param path - The operation path to encode.
|
|
203
|
+
* @returns The encoded string representation.
|
|
204
|
+
*/
|
|
205
|
+
const encode$2 = (path) => {
|
|
206
|
+
return makeStringPathFromTokens(path.toTokens());
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Decodes an encoded string back to an OperationPath.
|
|
210
|
+
* @param encoded - The encoded string representation.
|
|
211
|
+
* @returns The decoded OperationPath.
|
|
212
|
+
*/
|
|
213
|
+
const decode$2 = (encoded) => {
|
|
214
|
+
return make$3(encoded);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/Operation.ts
|
|
219
|
+
var Operation_exports = /* @__PURE__ */ __export({
|
|
220
|
+
decode: () => decode$1,
|
|
221
|
+
encode: () => encode$1,
|
|
222
|
+
fromDefinition: () => fromDefinition
|
|
223
|
+
});
|
|
224
|
+
const fromDefinition = (operationPath, definition, payload) => {
|
|
225
|
+
return {
|
|
226
|
+
kind: definition.kind,
|
|
227
|
+
path: operationPath,
|
|
228
|
+
payload
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Encodes an Operation to a JSON-serializable format for network transport.
|
|
233
|
+
* @param operation - The operation to encode.
|
|
234
|
+
* @returns The encoded representation.
|
|
235
|
+
*/
|
|
236
|
+
const encode$1 = (operation) => {
|
|
237
|
+
return {
|
|
238
|
+
kind: operation.kind,
|
|
239
|
+
path: encode$2(operation.path),
|
|
240
|
+
payload: operation.payload
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Decodes an encoded operation back to an Operation.
|
|
245
|
+
* Note: This returns a partial operation without the definition methods.
|
|
246
|
+
* The caller must have the operation definitions to fully reconstruct if needed.
|
|
247
|
+
* @param encoded - The encoded representation.
|
|
248
|
+
* @returns The decoded Operation (without definition-specific methods).
|
|
249
|
+
*/
|
|
250
|
+
const decode$1 = (encoded) => {
|
|
251
|
+
return {
|
|
252
|
+
kind: encoded.kind,
|
|
253
|
+
path: decode$2(encoded.path),
|
|
254
|
+
payload: encoded.payload
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/ProxyEnvironment.ts
|
|
260
|
+
var ProxyEnvironment_exports = /* @__PURE__ */ __export({ make: () => make$2 });
|
|
261
|
+
/** Default UUID generator using crypto.randomUUID */
|
|
262
|
+
const defaultGenerateId = () => {
|
|
263
|
+
return crypto.randomUUID();
|
|
264
|
+
};
|
|
265
|
+
/** Default state getter that always returns undefined */
|
|
266
|
+
const defaultGetState = (_path) => {};
|
|
267
|
+
/**
|
|
268
|
+
* Creates a ProxyEnvironment.
|
|
269
|
+
* @param optionsOrCallback - Either an options object or a simple callback for operations
|
|
270
|
+
*/
|
|
271
|
+
const make$2 = (optionsOrCallback) => {
|
|
272
|
+
var _options$getState, _options$generateId;
|
|
273
|
+
const options = typeof optionsOrCallback === "function" ? { onOperation: optionsOrCallback } : optionsOrCallback;
|
|
274
|
+
return {
|
|
275
|
+
addOperation: (operation) => {
|
|
276
|
+
options.onOperation(operation);
|
|
277
|
+
},
|
|
278
|
+
getState: (_options$getState = options.getState) !== null && _options$getState !== void 0 ? _options$getState : defaultGetState,
|
|
279
|
+
generateId: (_options$generateId = options.generateId) !== null && _options$generateId !== void 0 ? _options$generateId : defaultGenerateId
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/Transaction.ts
|
|
285
|
+
var Transaction_exports = /* @__PURE__ */ __export({
|
|
286
|
+
decode: () => decode,
|
|
287
|
+
empty: () => empty,
|
|
288
|
+
encode: () => encode,
|
|
289
|
+
isEmpty: () => isEmpty,
|
|
290
|
+
make: () => make$1,
|
|
291
|
+
merge: () => merge
|
|
292
|
+
});
|
|
293
|
+
/**
|
|
294
|
+
* Creates a new Transaction with the given operations.
|
|
295
|
+
*/
|
|
296
|
+
const make$1 = (ops) => ({
|
|
297
|
+
id: crypto.randomUUID(),
|
|
298
|
+
ops,
|
|
299
|
+
timestamp: Date.now()
|
|
300
|
+
});
|
|
301
|
+
/**
|
|
302
|
+
* Creates an empty Transaction.
|
|
303
|
+
*/
|
|
304
|
+
const empty = () => make$1([]);
|
|
305
|
+
/**
|
|
306
|
+
* Checks if a transaction is empty (has no operations).
|
|
307
|
+
*/
|
|
308
|
+
const isEmpty = (tx) => tx.ops.length === 0;
|
|
309
|
+
/**
|
|
310
|
+
* Merges multiple transactions into one.
|
|
311
|
+
*/
|
|
312
|
+
const merge = (txs) => {
|
|
313
|
+
return make$1(txs.flatMap((tx) => tx.ops));
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Encodes a Transaction to a JSON-serializable format for network transport.
|
|
317
|
+
* @param transaction - The transaction to encode.
|
|
318
|
+
* @returns The encoded representation.
|
|
319
|
+
*/
|
|
320
|
+
const encode = (transaction) => ({
|
|
321
|
+
id: transaction.id,
|
|
322
|
+
ops: transaction.ops.map(encode$1),
|
|
323
|
+
timestamp: transaction.timestamp
|
|
324
|
+
});
|
|
325
|
+
/**
|
|
326
|
+
* Decodes an encoded transaction back to a Transaction.
|
|
327
|
+
* @param encoded - The encoded representation.
|
|
328
|
+
* @returns The decoded Transaction.
|
|
329
|
+
*/
|
|
330
|
+
const decode = (encoded) => ({
|
|
331
|
+
id: encoded.id,
|
|
332
|
+
ops: encoded.ops.map(decode$1),
|
|
333
|
+
timestamp: encoded.timestamp
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/Document.ts
|
|
338
|
+
var Document_exports = /* @__PURE__ */ __export({
|
|
339
|
+
NestedTransactionError: () => NestedTransactionError,
|
|
340
|
+
OperationError: () => OperationError,
|
|
341
|
+
make: () => make
|
|
342
|
+
});
|
|
343
|
+
/**
|
|
344
|
+
* Error thrown when attempting to start a nested transaction.
|
|
345
|
+
*/
|
|
346
|
+
var NestedTransactionError = class extends Error {
|
|
347
|
+
constructor() {
|
|
348
|
+
super("Nested transactions are not supported");
|
|
349
|
+
_defineProperty(this, "_tag", "NestedTransactionError");
|
|
350
|
+
this.name = "NestedTransactionError";
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* Error thrown when an operation fails to apply.
|
|
355
|
+
*/
|
|
356
|
+
var OperationError = class extends Error {
|
|
357
|
+
constructor(message) {
|
|
358
|
+
super(message);
|
|
359
|
+
_defineProperty(this, "_tag", "OperationError");
|
|
360
|
+
this.name = "OperationError";
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Creates a new Document for the given schema.
|
|
365
|
+
*/
|
|
366
|
+
const make = (schema, options) => {
|
|
367
|
+
var _options$initial;
|
|
368
|
+
let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
|
|
369
|
+
let _pending = [];
|
|
370
|
+
let _inTransaction = false;
|
|
371
|
+
let _txOps = [];
|
|
372
|
+
let _txBaseState = void 0;
|
|
373
|
+
/**
|
|
374
|
+
* Gets state at the given path.
|
|
375
|
+
*/
|
|
376
|
+
const getStateAtPath = (path) => {
|
|
377
|
+
const tokens = path.toTokens().filter((t) => t !== "");
|
|
378
|
+
if (tokens.length === 0) return _state;
|
|
379
|
+
let current = _state;
|
|
380
|
+
for (const token of tokens) {
|
|
381
|
+
if (current === null || current === void 0) return;
|
|
382
|
+
if (typeof current === "object") {
|
|
383
|
+
if (Array.isArray(current)) {
|
|
384
|
+
const entry = current.find((e) => e.id === token);
|
|
385
|
+
if (entry) {
|
|
386
|
+
current = entry.value;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
current = current[token];
|
|
391
|
+
} else return;
|
|
392
|
+
}
|
|
393
|
+
return current;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Applies a single operation to the current state.
|
|
397
|
+
*/
|
|
398
|
+
const applyOperation = (op) => {
|
|
399
|
+
try {
|
|
400
|
+
_state = schema._internal.applyOperation(_state, op);
|
|
401
|
+
} catch (error) {
|
|
402
|
+
if (error instanceof Error) throw new OperationError(error.message);
|
|
403
|
+
throw new OperationError(String(error));
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Handles an operation from a proxy.
|
|
408
|
+
* In transaction mode: collects operations, applies to state immediately for subsequent reads.
|
|
409
|
+
* Outside transaction mode: auto-wraps in a single-operation transaction.
|
|
410
|
+
*/
|
|
411
|
+
const handleOperation = (op) => {
|
|
412
|
+
if (_inTransaction) {
|
|
413
|
+
_txOps.push(op);
|
|
414
|
+
applyOperation(op);
|
|
415
|
+
} else {
|
|
416
|
+
const baseState = _state;
|
|
417
|
+
try {
|
|
418
|
+
applyOperation(op);
|
|
419
|
+
_pending.push(op);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
_state = baseState;
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Creates a ProxyEnvironment for the document.
|
|
428
|
+
*/
|
|
429
|
+
const createEnv = () => {
|
|
430
|
+
return make$2({
|
|
431
|
+
onOperation: handleOperation,
|
|
432
|
+
getState: getStateAtPath
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
const env = createEnv();
|
|
436
|
+
const rootProxy = schema._internal.createProxy(env, make$3(""));
|
|
437
|
+
return {
|
|
438
|
+
schema,
|
|
439
|
+
root: rootProxy,
|
|
440
|
+
get: () => {
|
|
441
|
+
return _state;
|
|
442
|
+
},
|
|
443
|
+
toSnapshot: () => {
|
|
444
|
+
return rootProxy.toSnapshot();
|
|
445
|
+
},
|
|
446
|
+
transaction: (fn) => {
|
|
447
|
+
if (_inTransaction) throw new NestedTransactionError();
|
|
448
|
+
_inTransaction = true;
|
|
449
|
+
_txOps = [];
|
|
450
|
+
_txBaseState = _state;
|
|
451
|
+
try {
|
|
452
|
+
const result = fn(rootProxy);
|
|
453
|
+
_pending.push(..._txOps);
|
|
454
|
+
return result;
|
|
455
|
+
} catch (error) {
|
|
456
|
+
_state = _txBaseState;
|
|
457
|
+
throw error;
|
|
458
|
+
} finally {
|
|
459
|
+
_inTransaction = false;
|
|
460
|
+
_txOps = [];
|
|
461
|
+
_txBaseState = void 0;
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
apply: (ops) => {
|
|
465
|
+
for (const op of ops) applyOperation(op);
|
|
466
|
+
},
|
|
467
|
+
flush: () => {
|
|
468
|
+
const tx = make$1(_pending);
|
|
469
|
+
_pending = [];
|
|
470
|
+
return tx;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
//#endregion
|
|
476
|
+
Object.defineProperty(exports, 'Document_exports', {
|
|
477
|
+
enumerable: true,
|
|
478
|
+
get: function () {
|
|
479
|
+
return Document_exports;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
Object.defineProperty(exports, 'OperationPath_exports', {
|
|
483
|
+
enumerable: true,
|
|
484
|
+
get: function () {
|
|
485
|
+
return OperationPath_exports;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
Object.defineProperty(exports, 'Operation_exports', {
|
|
489
|
+
enumerable: true,
|
|
490
|
+
get: function () {
|
|
491
|
+
return Operation_exports;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
Object.defineProperty(exports, 'ProxyEnvironment_exports', {
|
|
495
|
+
enumerable: true,
|
|
496
|
+
get: function () {
|
|
497
|
+
return ProxyEnvironment_exports;
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
Object.defineProperty(exports, 'Transaction_exports', {
|
|
501
|
+
enumerable: true,
|
|
502
|
+
get: function () {
|
|
503
|
+
return Transaction_exports;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
Object.defineProperty(exports, '__export', {
|
|
507
|
+
enumerable: true,
|
|
508
|
+
get: function () {
|
|
509
|
+
return __export;
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
Object.defineProperty(exports, '__toESM', {
|
|
513
|
+
enumerable: true,
|
|
514
|
+
get: function () {
|
|
515
|
+
return __toESM;
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
Object.defineProperty(exports, '_defineProperty', {
|
|
519
|
+
enumerable: true,
|
|
520
|
+
get: function () {
|
|
521
|
+
return _defineProperty;
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
Object.defineProperty(exports, 'decode', {
|
|
525
|
+
enumerable: true,
|
|
526
|
+
get: function () {
|
|
527
|
+
return decode;
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
Object.defineProperty(exports, 'encode', {
|
|
531
|
+
enumerable: true,
|
|
532
|
+
get: function () {
|
|
533
|
+
return encode;
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
Object.defineProperty(exports, 'fromDefinition', {
|
|
537
|
+
enumerable: true,
|
|
538
|
+
get: function () {
|
|
539
|
+
return fromDefinition;
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
Object.defineProperty(exports, 'isEmpty', {
|
|
543
|
+
enumerable: true,
|
|
544
|
+
get: function () {
|
|
545
|
+
return isEmpty;
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
Object.defineProperty(exports, 'isPrefix', {
|
|
549
|
+
enumerable: true,
|
|
550
|
+
get: function () {
|
|
551
|
+
return isPrefix;
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
Object.defineProperty(exports, 'make', {
|
|
555
|
+
enumerable: true,
|
|
556
|
+
get: function () {
|
|
557
|
+
return make;
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
Object.defineProperty(exports, 'pathsEqual', {
|
|
561
|
+
enumerable: true,
|
|
562
|
+
get: function () {
|
|
563
|
+
return pathsEqual;
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
Object.defineProperty(exports, 'pathsOverlap', {
|
|
567
|
+
enumerable: true,
|
|
568
|
+
get: function () {
|
|
569
|
+
return pathsOverlap;
|
|
570
|
+
}
|
|
571
|
+
});
|