@voidhash/mimic 0.0.1-alpha.7 → 0.0.1-alpha.9
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 +43 -15
- 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-CasheIbX.d.mts +1175 -0
- package/dist/Primitive-CasheIbX.d.mts.map +1 -0
- package/dist/Primitive-Cyvy7zvF.d.cts +1175 -0
- package/dist/Primitive-Cyvy7zvF.d.cts.map +1 -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 +226 -765
- package/dist/index.d.cts +5 -1152
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -1152
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +71 -569
- package/dist/index.mjs.map +1 -1
- 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 +17 -5
- package/src/primitives/Array.ts +25 -14
- package/src/primitives/Boolean.ts +29 -17
- package/src/primitives/Either.ts +30 -17
- package/src/primitives/Lazy.ts +16 -2
- package/src/primitives/Literal.ts +29 -18
- package/src/primitives/Number.ts +35 -24
- package/src/primitives/String.ts +36 -23
- package/src/primitives/Struct.ts +74 -26
- package/src/primitives/Tree.ts +30 -14
- package/src/primitives/TreeNode.ts +6 -0
- package/src/primitives/Union.ts +21 -21
- package/src/primitives/shared.ts +35 -34
- package/tests/primitives/Array.test.ts +108 -0
- package/tests/primitives/Struct.test.ts +2 -2
- package/tests/primitives/Tree.test.ts +128 -0
- package/tsdown.config.ts +1 -1
- /package/dist/{chunk-C6wwvPpM.mjs → chunk-CLMFDpHK.mjs} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,118 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
1
|
+
const require_Document = require('./Document-ChuFrTk1.cjs');
|
|
2
|
+
const require_Presence = require('./Presence-gWrmGBeu.cjs');
|
|
41
3
|
let effect = require("effect");
|
|
42
|
-
let effect_Schema = require("effect/Schema");
|
|
43
|
-
effect_Schema = __toESM(effect_Schema);
|
|
44
|
-
|
|
45
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
46
|
-
function _typeof(o) {
|
|
47
|
-
"@babel/helpers - typeof";
|
|
48
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
49
|
-
return typeof o$1;
|
|
50
|
-
} : function(o$1) {
|
|
51
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
52
|
-
}, _typeof(o);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
57
|
-
function toPrimitive(t, r) {
|
|
58
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
59
|
-
var e = t[Symbol.toPrimitive];
|
|
60
|
-
if (void 0 !== e) {
|
|
61
|
-
var i = e.call(t, r || "default");
|
|
62
|
-
if ("object" != _typeof(i)) return i;
|
|
63
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
64
|
-
}
|
|
65
|
-
return ("string" === r ? String : Number)(t);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
70
|
-
function toPropertyKey(t) {
|
|
71
|
-
var i = toPrimitive(t, "string");
|
|
72
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
77
|
-
function _defineProperty(e, r, t) {
|
|
78
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
79
|
-
value: t,
|
|
80
|
-
enumerable: !0,
|
|
81
|
-
configurable: !0,
|
|
82
|
-
writable: !0
|
|
83
|
-
}) : e[r] = t, e;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
88
|
-
function ownKeys(e, r) {
|
|
89
|
-
var t = Object.keys(e);
|
|
90
|
-
if (Object.getOwnPropertySymbols) {
|
|
91
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
92
|
-
r && (o = o.filter(function(r$1) {
|
|
93
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
94
|
-
})), t.push.apply(t, o);
|
|
95
|
-
}
|
|
96
|
-
return t;
|
|
97
|
-
}
|
|
98
|
-
function _objectSpread2(e) {
|
|
99
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
100
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
101
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
102
|
-
_defineProperty(e, r$1, t[r$1]);
|
|
103
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
104
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return e;
|
|
108
|
-
}
|
|
109
4
|
|
|
110
|
-
//#endregion
|
|
111
5
|
//#region src/primitives/shared.ts
|
|
112
6
|
var ValidationError = class extends Error {
|
|
113
7
|
constructor(message) {
|
|
114
8
|
super(message);
|
|
115
|
-
_defineProperty(this, "_tag", "ValidationError");
|
|
9
|
+
require_Document._defineProperty(this, "_tag", "ValidationError");
|
|
116
10
|
this.name = "ValidationError";
|
|
117
11
|
}
|
|
118
12
|
};
|
|
@@ -147,7 +41,7 @@ function applyDefaults(primitive, value) {
|
|
|
147
41
|
if (primitive._tag === "StructPrimitive") {
|
|
148
42
|
var _structPrimitive$_int;
|
|
149
43
|
const structPrimitive = primitive;
|
|
150
|
-
const result = _objectSpread2(_objectSpread2({}, (_structPrimitive$_int = structPrimitive._internal.getInitialState()) !== null && _structPrimitive$_int !== void 0 ? _structPrimitive$_int : {}), value);
|
|
44
|
+
const result = require_Presence._objectSpread2(require_Presence._objectSpread2({}, (_structPrimitive$_int = structPrimitive._internal.getInitialState()) !== null && _structPrimitive$_int !== void 0 ? _structPrimitive$_int : {}), value);
|
|
151
45
|
for (const key in structPrimitive.fields) {
|
|
152
46
|
const fieldPrimitive = structPrimitive.fields[key];
|
|
153
47
|
if (result[key] === void 0) {
|
|
@@ -162,7 +56,7 @@ function applyDefaults(primitive, value) {
|
|
|
162
56
|
|
|
163
57
|
//#endregion
|
|
164
58
|
//#region src/OperationDefinition.ts
|
|
165
|
-
const make
|
|
59
|
+
const make = (options) => {
|
|
166
60
|
return {
|
|
167
61
|
kind: options.kind,
|
|
168
62
|
payload: options.payload,
|
|
@@ -171,198 +65,25 @@ const make$5 = (options) => {
|
|
|
171
65
|
};
|
|
172
66
|
};
|
|
173
67
|
|
|
174
|
-
//#endregion
|
|
175
|
-
//#region src/OperationPath.ts
|
|
176
|
-
var OperationPath_exports = /* @__PURE__ */ __export({
|
|
177
|
-
decode: () => decode$2,
|
|
178
|
-
encode: () => encode$2,
|
|
179
|
-
fromTokens: () => fromTokens,
|
|
180
|
-
getRelativePath: () => getRelativePath,
|
|
181
|
-
isPrefix: () => isPrefix,
|
|
182
|
-
make: () => make$4,
|
|
183
|
-
pathsEqual: () => pathsEqual,
|
|
184
|
-
pathsOverlap: () => pathsOverlap
|
|
185
|
-
});
|
|
186
|
-
const parseStringPath = (stringPath) => {
|
|
187
|
-
return stringPath.split("/");
|
|
188
|
-
};
|
|
189
|
-
const makeStringPathFromTokens = (tokens) => {
|
|
190
|
-
return tokens.join("/");
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* Creates a new operation path.
|
|
194
|
-
* @param stringPath - The string path to create the path from.
|
|
195
|
-
* @returns The new operation path.
|
|
196
|
-
*/
|
|
197
|
-
function make$4(stringPath) {
|
|
198
|
-
const tokensInternal = stringPath ? parseStringPath(stringPath) : [];
|
|
199
|
-
/**
|
|
200
|
-
* Returns the tokens of the path.
|
|
201
|
-
* @returns The tokens of the path.
|
|
202
|
-
*/
|
|
203
|
-
const toTokens = () => {
|
|
204
|
-
return tokensInternal;
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Concatenates two paths.
|
|
208
|
-
* @param other - The other path to concatenate.
|
|
209
|
-
* @returns The new path.
|
|
210
|
-
*/
|
|
211
|
-
const concat = (other) => {
|
|
212
|
-
return make$4(makeStringPathFromTokens(toTokens().concat(other.toTokens())));
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Appends a token to the path.
|
|
216
|
-
* @param token - The token to append.
|
|
217
|
-
* @returns The new path.
|
|
218
|
-
*/
|
|
219
|
-
const append = (token) => {
|
|
220
|
-
return make$4(makeStringPathFromTokens(toTokens().concat([token])));
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* Removes the last token from the path.
|
|
224
|
-
* @returns The new path.
|
|
225
|
-
*/
|
|
226
|
-
const pop = () => {
|
|
227
|
-
return make$4(makeStringPathFromTokens(toTokens().slice(0, -1)));
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Removes the first token from the path.
|
|
231
|
-
* @returns The new path.
|
|
232
|
-
*/
|
|
233
|
-
const shift = () => {
|
|
234
|
-
return make$4(makeStringPathFromTokens(toTokens().slice(1)));
|
|
235
|
-
};
|
|
236
|
-
return {
|
|
237
|
-
_tag: "OperationPath",
|
|
238
|
-
toTokens,
|
|
239
|
-
concat,
|
|
240
|
-
append,
|
|
241
|
-
pop,
|
|
242
|
-
shift
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Creates a new operation path from tokens.
|
|
247
|
-
* @param tokens - The tokens to create the path from.
|
|
248
|
-
* @returns The new operation path.
|
|
249
|
-
*/
|
|
250
|
-
function fromTokens(tokens) {
|
|
251
|
-
return make$4(makeStringPathFromTokens(tokens));
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Checks if two operation paths overlap (one is prefix of the other or equal).
|
|
255
|
-
*/
|
|
256
|
-
const pathsOverlap = (pathA, pathB) => {
|
|
257
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
258
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
259
|
-
const minLength = Math.min(tokensA.length, tokensB.length);
|
|
260
|
-
for (let i = 0; i < minLength; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
261
|
-
return true;
|
|
262
|
-
};
|
|
263
|
-
/**
|
|
264
|
-
* Checks if pathA is a prefix of pathB (pathA is ancestor of pathB).
|
|
265
|
-
*/
|
|
266
|
-
const isPrefix = (pathA, pathB) => {
|
|
267
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
268
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
269
|
-
if (tokensA.length > tokensB.length) return false;
|
|
270
|
-
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
271
|
-
return true;
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* Checks if two paths are exactly equal.
|
|
275
|
-
*/
|
|
276
|
-
const pathsEqual = (pathA, pathB) => {
|
|
277
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
278
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
279
|
-
if (tokensA.length !== tokensB.length) return false;
|
|
280
|
-
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
281
|
-
return true;
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* Gets the relative path of pathB with respect to pathA.
|
|
285
|
-
* Assumes pathA is a prefix of pathB.
|
|
286
|
-
*/
|
|
287
|
-
const getRelativePath = (basePath, fullPath) => {
|
|
288
|
-
const baseTokens = basePath.toTokens().filter((t) => t !== "");
|
|
289
|
-
return fullPath.toTokens().filter((t) => t !== "").slice(baseTokens.length);
|
|
290
|
-
};
|
|
291
|
-
/**
|
|
292
|
-
* Encodes an OperationPath to a string for network transport.
|
|
293
|
-
* @param path - The operation path to encode.
|
|
294
|
-
* @returns The encoded string representation.
|
|
295
|
-
*/
|
|
296
|
-
const encode$2 = (path) => {
|
|
297
|
-
return makeStringPathFromTokens(path.toTokens());
|
|
298
|
-
};
|
|
299
|
-
/**
|
|
300
|
-
* Decodes an encoded string back to an OperationPath.
|
|
301
|
-
* @param encoded - The encoded string representation.
|
|
302
|
-
* @returns The decoded OperationPath.
|
|
303
|
-
*/
|
|
304
|
-
const decode$2 = (encoded) => {
|
|
305
|
-
return make$4(encoded);
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
//#endregion
|
|
309
|
-
//#region src/Operation.ts
|
|
310
|
-
var Operation_exports = /* @__PURE__ */ __export({
|
|
311
|
-
decode: () => decode$1,
|
|
312
|
-
encode: () => encode$1,
|
|
313
|
-
fromDefinition: () => fromDefinition
|
|
314
|
-
});
|
|
315
|
-
const fromDefinition = (operationPath, definition, payload) => {
|
|
316
|
-
return {
|
|
317
|
-
kind: definition.kind,
|
|
318
|
-
path: operationPath,
|
|
319
|
-
payload
|
|
320
|
-
};
|
|
321
|
-
};
|
|
322
|
-
/**
|
|
323
|
-
* Encodes an Operation to a JSON-serializable format for network transport.
|
|
324
|
-
* @param operation - The operation to encode.
|
|
325
|
-
* @returns The encoded representation.
|
|
326
|
-
*/
|
|
327
|
-
const encode$1 = (operation) => {
|
|
328
|
-
return {
|
|
329
|
-
kind: operation.kind,
|
|
330
|
-
path: encode$2(operation.path),
|
|
331
|
-
payload: operation.payload
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
/**
|
|
335
|
-
* Decodes an encoded operation back to an Operation.
|
|
336
|
-
* Note: This returns a partial operation without the definition methods.
|
|
337
|
-
* The caller must have the operation definitions to fully reconstruct if needed.
|
|
338
|
-
* @param encoded - The encoded representation.
|
|
339
|
-
* @returns The decoded Operation (without definition-specific methods).
|
|
340
|
-
*/
|
|
341
|
-
const decode$1 = (encoded) => {
|
|
342
|
-
return {
|
|
343
|
-
kind: encoded.kind,
|
|
344
|
-
path: decode$2(encoded.path),
|
|
345
|
-
payload: encoded.payload
|
|
346
|
-
};
|
|
347
|
-
};
|
|
348
|
-
|
|
349
68
|
//#endregion
|
|
350
69
|
//#region src/primitives/String.ts
|
|
351
70
|
var StringPrimitive = class StringPrimitive {
|
|
352
71
|
constructor(schema) {
|
|
353
|
-
_defineProperty(this, "_tag", "StringPrimitive");
|
|
354
|
-
_defineProperty(this, "_State", void 0);
|
|
355
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
356
|
-
_defineProperty(this, "
|
|
357
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
358
|
-
_defineProperty(this, "
|
|
359
|
-
_defineProperty(this, "
|
|
72
|
+
require_Document._defineProperty(this, "_tag", "StringPrimitive");
|
|
73
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
74
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
75
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
76
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
77
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
78
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
79
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
80
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
360
81
|
kind: "string.set",
|
|
361
82
|
payload: effect.Schema.String,
|
|
362
83
|
target: effect.Schema.String,
|
|
363
84
|
apply: (payload) => payload
|
|
364
85
|
}) });
|
|
365
|
-
_defineProperty(this, "_internal", {
|
|
86
|
+
require_Document._defineProperty(this, "_internal", {
|
|
366
87
|
createProxy: (env, operationPath) => {
|
|
367
88
|
const defaultValue = this._schema.defaultValue;
|
|
368
89
|
return {
|
|
@@ -371,7 +92,10 @@ var StringPrimitive = class StringPrimitive {
|
|
|
371
92
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
372
93
|
},
|
|
373
94
|
set: (value) => {
|
|
374
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
95
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
96
|
+
},
|
|
97
|
+
update: (value) => {
|
|
98
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
375
99
|
},
|
|
376
100
|
toSnapshot: () => {
|
|
377
101
|
const state = env.getState(operationPath);
|
|
@@ -390,7 +114,7 @@ var StringPrimitive = class StringPrimitive {
|
|
|
390
114
|
return this._schema.defaultValue;
|
|
391
115
|
},
|
|
392
116
|
transformOperation: (clientOp, serverOp) => {
|
|
393
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
117
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
394
118
|
type: "transformed",
|
|
395
119
|
operation: clientOp
|
|
396
120
|
};
|
|
@@ -404,15 +128,15 @@ var StringPrimitive = class StringPrimitive {
|
|
|
404
128
|
}
|
|
405
129
|
/** Mark this string as required */
|
|
406
130
|
required() {
|
|
407
|
-
return new StringPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
131
|
+
return new StringPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
408
132
|
}
|
|
409
133
|
/** Set a default value for this string */
|
|
410
134
|
default(defaultValue) {
|
|
411
|
-
return new StringPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
135
|
+
return new StringPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
412
136
|
}
|
|
413
137
|
/** Add a custom validation rule */
|
|
414
138
|
refine(fn, message) {
|
|
415
|
-
return new StringPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
139
|
+
return new StringPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
416
140
|
validate: fn,
|
|
417
141
|
message
|
|
418
142
|
}] }));
|
|
@@ -451,7 +175,7 @@ var StringPrimitive = class StringPrimitive {
|
|
|
451
175
|
}
|
|
452
176
|
};
|
|
453
177
|
/** Creates a new StringPrimitive */
|
|
454
|
-
const String
|
|
178
|
+
const String = () => new StringPrimitive({
|
|
455
179
|
required: false,
|
|
456
180
|
defaultValue: void 0,
|
|
457
181
|
validators: []
|
|
@@ -461,19 +185,21 @@ const String$1 = () => new StringPrimitive({
|
|
|
461
185
|
//#region src/primitives/Struct.ts
|
|
462
186
|
var StructPrimitive = class StructPrimitive {
|
|
463
187
|
constructor(schema) {
|
|
464
|
-
_defineProperty(this, "_tag", "StructPrimitive");
|
|
465
|
-
_defineProperty(this, "_State", void 0);
|
|
466
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
467
|
-
_defineProperty(this, "
|
|
468
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
469
|
-
_defineProperty(this, "
|
|
470
|
-
_defineProperty(this, "
|
|
188
|
+
require_Document._defineProperty(this, "_tag", "StructPrimitive");
|
|
189
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
190
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
191
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
192
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
193
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
194
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
195
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
196
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
471
197
|
kind: "struct.set",
|
|
472
198
|
payload: effect.Schema.Unknown,
|
|
473
199
|
target: effect.Schema.Unknown,
|
|
474
200
|
apply: (payload) => payload
|
|
475
201
|
}) });
|
|
476
|
-
_defineProperty(this, "_internal", {
|
|
202
|
+
require_Document._defineProperty(this, "_internal", {
|
|
477
203
|
createProxy: (env, operationPath) => {
|
|
478
204
|
const fields = this._schema.fields;
|
|
479
205
|
const defaultValue = this._schema.defaultValue;
|
|
@@ -498,7 +224,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
498
224
|
},
|
|
499
225
|
set: (value) => {
|
|
500
226
|
const merged = applyDefaults(this, value);
|
|
501
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, merged));
|
|
227
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, merged));
|
|
502
228
|
},
|
|
503
229
|
update: (value) => {
|
|
504
230
|
for (const key in value) if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
@@ -549,11 +275,11 @@ var StructPrimitive = class StructPrimitive {
|
|
|
549
275
|
if (!(fieldName in this._schema.fields)) throw new ValidationError(`Unknown field: ${globalThis.String(fieldName)}`);
|
|
550
276
|
const fieldPrimitive = this._schema.fields[fieldName];
|
|
551
277
|
const remainingPath = path.shift();
|
|
552
|
-
const fieldOperation = _objectSpread2(_objectSpread2({}, operation), {}, { path: remainingPath });
|
|
278
|
+
const fieldOperation = require_Presence._objectSpread2(require_Presence._objectSpread2({}, operation), {}, { path: remainingPath });
|
|
553
279
|
const currentState = state !== null && state !== void 0 ? state : {};
|
|
554
280
|
const currentFieldState = currentState[fieldName];
|
|
555
281
|
const newFieldState = fieldPrimitive._internal.applyOperation(currentFieldState, fieldOperation);
|
|
556
|
-
newState = _objectSpread2(_objectSpread2({}, currentState), {}, { [fieldName]: newFieldState });
|
|
282
|
+
newState = require_Presence._objectSpread2(require_Presence._objectSpread2({}, currentState), {}, { [fieldName]: newFieldState });
|
|
557
283
|
}
|
|
558
284
|
runValidators(newState, this._schema.validators);
|
|
559
285
|
return newState;
|
|
@@ -575,7 +301,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
575
301
|
transformOperation: (clientOp, serverOp) => {
|
|
576
302
|
const clientPath = clientOp.path;
|
|
577
303
|
const serverPath = serverOp.path;
|
|
578
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
304
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
579
305
|
type: "transformed",
|
|
580
306
|
operation: clientOp
|
|
581
307
|
};
|
|
@@ -604,12 +330,12 @@ var StructPrimitive = class StructPrimitive {
|
|
|
604
330
|
type: "transformed",
|
|
605
331
|
operation: clientOp
|
|
606
332
|
};
|
|
607
|
-
const clientOpForField = _objectSpread2(_objectSpread2({}, clientOp), {}, { path: clientOp.path.shift() });
|
|
608
|
-
const serverOpForField = _objectSpread2(_objectSpread2({}, serverOp), {}, { path: serverOp.path.shift() });
|
|
333
|
+
const clientOpForField = require_Presence._objectSpread2(require_Presence._objectSpread2({}, clientOp), {}, { path: clientOp.path.shift() });
|
|
334
|
+
const serverOpForField = require_Presence._objectSpread2(require_Presence._objectSpread2({}, serverOp), {}, { path: serverOp.path.shift() });
|
|
609
335
|
const result = fieldPrimitive._internal.transformOperation(clientOpForField, serverOpForField);
|
|
610
336
|
if (result.type === "transformed") return {
|
|
611
337
|
type: "transformed",
|
|
612
|
-
operation: _objectSpread2(_objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
338
|
+
operation: require_Presence._objectSpread2(require_Presence._objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
613
339
|
};
|
|
614
340
|
return result;
|
|
615
341
|
}
|
|
@@ -623,12 +349,12 @@ var StructPrimitive = class StructPrimitive {
|
|
|
623
349
|
}
|
|
624
350
|
/** Mark this struct as required */
|
|
625
351
|
required() {
|
|
626
|
-
return new StructPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
352
|
+
return new StructPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
627
353
|
}
|
|
628
354
|
/** Set a default value for this struct */
|
|
629
355
|
default(defaultValue) {
|
|
630
356
|
const merged = applyDefaults(this, defaultValue);
|
|
631
|
-
return new StructPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue: merged }));
|
|
357
|
+
return new StructPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue: merged }));
|
|
632
358
|
}
|
|
633
359
|
/** Get the fields schema */
|
|
634
360
|
get fields() {
|
|
@@ -636,7 +362,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
636
362
|
}
|
|
637
363
|
/** Add a custom validation rule (useful for cross-field validation) */
|
|
638
364
|
refine(fn, message) {
|
|
639
|
-
return new StructPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
365
|
+
return new StructPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
640
366
|
validate: fn,
|
|
641
367
|
message
|
|
642
368
|
}] }));
|
|
@@ -654,19 +380,21 @@ const Struct = (fields) => new StructPrimitive({
|
|
|
654
380
|
//#region src/primitives/Boolean.ts
|
|
655
381
|
var BooleanPrimitive = class BooleanPrimitive {
|
|
656
382
|
constructor(schema) {
|
|
657
|
-
_defineProperty(this, "_tag", "BooleanPrimitive");
|
|
658
|
-
_defineProperty(this, "_State", void 0);
|
|
659
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
660
|
-
_defineProperty(this, "
|
|
661
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
662
|
-
_defineProperty(this, "
|
|
663
|
-
_defineProperty(this, "
|
|
383
|
+
require_Document._defineProperty(this, "_tag", "BooleanPrimitive");
|
|
384
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
385
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
386
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
387
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
388
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
389
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
390
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
391
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
664
392
|
kind: "boolean.set",
|
|
665
393
|
payload: effect.Schema.Boolean,
|
|
666
394
|
target: effect.Schema.Boolean,
|
|
667
395
|
apply: (payload) => payload
|
|
668
396
|
}) });
|
|
669
|
-
_defineProperty(this, "_internal", {
|
|
397
|
+
require_Document._defineProperty(this, "_internal", {
|
|
670
398
|
createProxy: (env, operationPath) => {
|
|
671
399
|
const defaultValue = this._schema.defaultValue;
|
|
672
400
|
return {
|
|
@@ -675,7 +403,10 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
675
403
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
676
404
|
},
|
|
677
405
|
set: (value) => {
|
|
678
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
406
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
407
|
+
},
|
|
408
|
+
update: (value) => {
|
|
409
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
679
410
|
},
|
|
680
411
|
toSnapshot: () => {
|
|
681
412
|
const state = env.getState(operationPath);
|
|
@@ -694,7 +425,7 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
694
425
|
return this._schema.defaultValue;
|
|
695
426
|
},
|
|
696
427
|
transformOperation: (clientOp, serverOp) => {
|
|
697
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
428
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
698
429
|
type: "transformed",
|
|
699
430
|
operation: clientOp
|
|
700
431
|
};
|
|
@@ -708,15 +439,15 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
708
439
|
}
|
|
709
440
|
/** Mark this boolean as required */
|
|
710
441
|
required() {
|
|
711
|
-
return new BooleanPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
442
|
+
return new BooleanPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
712
443
|
}
|
|
713
444
|
/** Set a default value for this boolean */
|
|
714
445
|
default(defaultValue) {
|
|
715
|
-
return new BooleanPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
446
|
+
return new BooleanPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
716
447
|
}
|
|
717
448
|
/** Add a custom validation rule */
|
|
718
449
|
refine(fn, message) {
|
|
719
|
-
return new BooleanPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
450
|
+
return new BooleanPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
720
451
|
validate: fn,
|
|
721
452
|
message
|
|
722
453
|
}] }));
|
|
@@ -733,19 +464,21 @@ const Boolean = () => new BooleanPrimitive({
|
|
|
733
464
|
//#region src/primitives/Number.ts
|
|
734
465
|
var NumberPrimitive = class NumberPrimitive {
|
|
735
466
|
constructor(schema) {
|
|
736
|
-
_defineProperty(this, "_tag", "NumberPrimitive");
|
|
737
|
-
_defineProperty(this, "_State", void 0);
|
|
738
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
739
|
-
_defineProperty(this, "
|
|
740
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
741
|
-
_defineProperty(this, "
|
|
742
|
-
_defineProperty(this, "
|
|
467
|
+
require_Document._defineProperty(this, "_tag", "NumberPrimitive");
|
|
468
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
469
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
470
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
471
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
472
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
473
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
474
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
475
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
743
476
|
kind: "number.set",
|
|
744
477
|
payload: effect.Schema.Number,
|
|
745
478
|
target: effect.Schema.Number,
|
|
746
479
|
apply: (payload) => payload
|
|
747
480
|
}) });
|
|
748
|
-
_defineProperty(this, "_internal", {
|
|
481
|
+
require_Document._defineProperty(this, "_internal", {
|
|
749
482
|
createProxy: (env, operationPath) => {
|
|
750
483
|
const defaultValue = this._schema.defaultValue;
|
|
751
484
|
return {
|
|
@@ -754,7 +487,10 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
754
487
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
755
488
|
},
|
|
756
489
|
set: (value) => {
|
|
757
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
490
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
491
|
+
},
|
|
492
|
+
update: (value) => {
|
|
493
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
758
494
|
},
|
|
759
495
|
toSnapshot: () => {
|
|
760
496
|
const state = env.getState(operationPath);
|
|
@@ -773,7 +509,7 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
773
509
|
return this._schema.defaultValue;
|
|
774
510
|
},
|
|
775
511
|
transformOperation: (clientOp, serverOp) => {
|
|
776
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
512
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
777
513
|
type: "transformed",
|
|
778
514
|
operation: clientOp
|
|
779
515
|
};
|
|
@@ -787,15 +523,15 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
787
523
|
}
|
|
788
524
|
/** Mark this number as required */
|
|
789
525
|
required() {
|
|
790
|
-
return new NumberPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
526
|
+
return new NumberPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
791
527
|
}
|
|
792
528
|
/** Set a default value for this number */
|
|
793
529
|
default(defaultValue) {
|
|
794
|
-
return new NumberPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
530
|
+
return new NumberPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
795
531
|
}
|
|
796
532
|
/** Add a custom validation rule */
|
|
797
533
|
refine(fn, message) {
|
|
798
|
-
return new NumberPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
534
|
+
return new NumberPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
799
535
|
validate: fn,
|
|
800
536
|
message
|
|
801
537
|
}] }));
|
|
@@ -822,7 +558,7 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
822
558
|
}
|
|
823
559
|
};
|
|
824
560
|
/** Creates a new NumberPrimitive */
|
|
825
|
-
const Number
|
|
561
|
+
const Number = () => new NumberPrimitive({
|
|
826
562
|
required: false,
|
|
827
563
|
defaultValue: void 0,
|
|
828
564
|
validators: []
|
|
@@ -832,19 +568,21 @@ const Number$1 = () => new NumberPrimitive({
|
|
|
832
568
|
//#region src/primitives/Literal.ts
|
|
833
569
|
var LiteralPrimitive = class LiteralPrimitive {
|
|
834
570
|
constructor(schema) {
|
|
835
|
-
_defineProperty(this, "_tag", "LiteralPrimitive");
|
|
836
|
-
_defineProperty(this, "_State", void 0);
|
|
837
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
838
|
-
_defineProperty(this, "
|
|
839
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
840
|
-
_defineProperty(this, "
|
|
841
|
-
_defineProperty(this, "
|
|
571
|
+
require_Document._defineProperty(this, "_tag", "LiteralPrimitive");
|
|
572
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
573
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
574
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
575
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
576
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
577
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
578
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
579
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
842
580
|
kind: "literal.set",
|
|
843
581
|
payload: effect.Schema.Unknown,
|
|
844
582
|
target: effect.Schema.Unknown,
|
|
845
583
|
apply: (payload) => payload
|
|
846
584
|
}) });
|
|
847
|
-
_defineProperty(this, "_internal", {
|
|
585
|
+
require_Document._defineProperty(this, "_internal", {
|
|
848
586
|
createProxy: (env, operationPath) => {
|
|
849
587
|
const defaultValue = this._schema.defaultValue;
|
|
850
588
|
return {
|
|
@@ -853,7 +591,10 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
853
591
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
854
592
|
},
|
|
855
593
|
set: (value) => {
|
|
856
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
594
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
595
|
+
},
|
|
596
|
+
update: (value) => {
|
|
597
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
857
598
|
},
|
|
858
599
|
toSnapshot: () => {
|
|
859
600
|
const state = env.getState(operationPath);
|
|
@@ -871,7 +612,7 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
871
612
|
return this._schema.defaultValue;
|
|
872
613
|
},
|
|
873
614
|
transformOperation: (clientOp, serverOp) => {
|
|
874
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
615
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
875
616
|
type: "transformed",
|
|
876
617
|
operation: clientOp
|
|
877
618
|
};
|
|
@@ -885,11 +626,11 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
885
626
|
}
|
|
886
627
|
/** Mark this literal as required */
|
|
887
628
|
required() {
|
|
888
|
-
return new LiteralPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
629
|
+
return new LiteralPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
889
630
|
}
|
|
890
631
|
/** Set a default value for this literal */
|
|
891
632
|
default(defaultValue) {
|
|
892
|
-
return new LiteralPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
633
|
+
return new LiteralPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
893
634
|
}
|
|
894
635
|
/** Get the literal value this primitive represents */
|
|
895
636
|
get literal() {
|
|
@@ -1278,39 +1019,41 @@ const generatePosBetween = (left, right) => {
|
|
|
1278
1019
|
};
|
|
1279
1020
|
var ArrayPrimitive = class ArrayPrimitive {
|
|
1280
1021
|
constructor(schema) {
|
|
1281
|
-
_defineProperty(this, "_tag", "ArrayPrimitive");
|
|
1282
|
-
_defineProperty(this, "_State", void 0);
|
|
1283
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1284
|
-
_defineProperty(this, "
|
|
1285
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
1286
|
-
_defineProperty(this, "
|
|
1287
|
-
_defineProperty(this, "
|
|
1288
|
-
|
|
1022
|
+
require_Document._defineProperty(this, "_tag", "ArrayPrimitive");
|
|
1023
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
1024
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
1025
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
1026
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
1027
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1028
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1029
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
1030
|
+
require_Document._defineProperty(this, "_opDefinitions", {
|
|
1031
|
+
set: make({
|
|
1289
1032
|
kind: "array.set",
|
|
1290
1033
|
payload: effect.Schema.Unknown,
|
|
1291
1034
|
target: effect.Schema.Unknown,
|
|
1292
1035
|
apply: (payload) => payload
|
|
1293
1036
|
}),
|
|
1294
|
-
insert: make
|
|
1037
|
+
insert: make({
|
|
1295
1038
|
kind: "array.insert",
|
|
1296
1039
|
payload: effect.Schema.Unknown,
|
|
1297
1040
|
target: effect.Schema.Unknown,
|
|
1298
1041
|
apply: (payload) => payload
|
|
1299
1042
|
}),
|
|
1300
|
-
remove: make
|
|
1043
|
+
remove: make({
|
|
1301
1044
|
kind: "array.remove",
|
|
1302
1045
|
payload: effect.Schema.Unknown,
|
|
1303
1046
|
target: effect.Schema.Unknown,
|
|
1304
1047
|
apply: (payload) => payload
|
|
1305
1048
|
}),
|
|
1306
|
-
move: make
|
|
1049
|
+
move: make({
|
|
1307
1050
|
kind: "array.move",
|
|
1308
1051
|
payload: effect.Schema.Unknown,
|
|
1309
1052
|
target: effect.Schema.Unknown,
|
|
1310
1053
|
apply: (payload) => payload
|
|
1311
1054
|
})
|
|
1312
1055
|
});
|
|
1313
|
-
_defineProperty(this, "_internal", {
|
|
1056
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1314
1057
|
createProxy: (env, operationPath) => {
|
|
1315
1058
|
const elementPrimitive = this._schema.element;
|
|
1316
1059
|
const getCurrentState = () => {
|
|
@@ -1339,7 +1082,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1339
1082
|
});
|
|
1340
1083
|
prevPos = pos;
|
|
1341
1084
|
}
|
|
1342
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, entries));
|
|
1085
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, entries));
|
|
1343
1086
|
},
|
|
1344
1087
|
push: (value) => {
|
|
1345
1088
|
const sorted = getCurrentState();
|
|
@@ -1347,7 +1090,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1347
1090
|
const id = env.generateId();
|
|
1348
1091
|
const pos = generatePosBetween(lastPos, null);
|
|
1349
1092
|
const mergedValue = applyElementDefaults(value);
|
|
1350
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1093
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1351
1094
|
id,
|
|
1352
1095
|
pos,
|
|
1353
1096
|
value: mergedValue
|
|
@@ -1360,20 +1103,20 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1360
1103
|
const id = env.generateId();
|
|
1361
1104
|
const pos = generatePosBetween(leftPos, rightPos);
|
|
1362
1105
|
const mergedValue = applyElementDefaults(value);
|
|
1363
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1106
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1364
1107
|
id,
|
|
1365
1108
|
pos,
|
|
1366
1109
|
value: mergedValue
|
|
1367
1110
|
}));
|
|
1368
1111
|
},
|
|
1369
1112
|
remove: (id) => {
|
|
1370
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
1113
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
1371
1114
|
},
|
|
1372
1115
|
move: (id, toIndex) => {
|
|
1373
1116
|
const without = getCurrentState().filter((e) => e.id !== id);
|
|
1374
1117
|
const clampedIndex = Math.max(0, Math.min(toIndex, without.length));
|
|
1375
1118
|
const pos = generatePosBetween(clampedIndex > 0 && without[clampedIndex - 1] ? without[clampedIndex - 1].pos : null, clampedIndex < without.length && without[clampedIndex] ? without[clampedIndex].pos : null);
|
|
1376
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
1119
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
1377
1120
|
id,
|
|
1378
1121
|
pos
|
|
1379
1122
|
}));
|
|
@@ -1428,7 +1171,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1428
1171
|
}
|
|
1429
1172
|
case "array.move": {
|
|
1430
1173
|
const { id, pos } = operation.payload;
|
|
1431
|
-
newState = currentState.map((entry) => entry.id === id ? _objectSpread2(_objectSpread2({}, entry), {}, { pos }) : entry);
|
|
1174
|
+
newState = currentState.map((entry) => entry.id === id ? require_Presence._objectSpread2(require_Presence._objectSpread2({}, entry), {}, { pos }) : entry);
|
|
1432
1175
|
break;
|
|
1433
1176
|
}
|
|
1434
1177
|
default: throw new ValidationError(`ArrayPrimitive cannot apply operation of kind: ${operation.kind}`);
|
|
@@ -1439,11 +1182,11 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1439
1182
|
if (entryIndex === -1) throw new ValidationError(`Array element not found with ID: ${elementId}`);
|
|
1440
1183
|
const elementPrimitive = this._schema.element;
|
|
1441
1184
|
const remainingPath = path.shift();
|
|
1442
|
-
const elementOperation = _objectSpread2(_objectSpread2({}, operation), {}, { path: remainingPath });
|
|
1185
|
+
const elementOperation = require_Presence._objectSpread2(require_Presence._objectSpread2({}, operation), {}, { path: remainingPath });
|
|
1443
1186
|
const currentEntry = currentState[entryIndex];
|
|
1444
1187
|
const newValue = elementPrimitive._internal.applyOperation(currentEntry.value, elementOperation);
|
|
1445
1188
|
const mutableState = [...currentState];
|
|
1446
|
-
mutableState[entryIndex] = _objectSpread2(_objectSpread2({}, currentEntry), {}, { value: newValue });
|
|
1189
|
+
mutableState[entryIndex] = require_Presence._objectSpread2(require_Presence._objectSpread2({}, currentEntry), {}, { value: newValue });
|
|
1447
1190
|
newState = mutableState;
|
|
1448
1191
|
}
|
|
1449
1192
|
runValidators(newState, this._schema.validators);
|
|
@@ -1455,7 +1198,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1455
1198
|
transformOperation: (clientOp, serverOp) => {
|
|
1456
1199
|
const clientPath = clientOp.path;
|
|
1457
1200
|
const serverPath = serverOp.path;
|
|
1458
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
1201
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
1459
1202
|
type: "transformed",
|
|
1460
1203
|
operation: clientOp
|
|
1461
1204
|
};
|
|
@@ -1481,11 +1224,11 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1481
1224
|
operation: clientOp
|
|
1482
1225
|
};
|
|
1483
1226
|
}
|
|
1484
|
-
if (pathsEqual(clientPath, serverPath)) return {
|
|
1227
|
+
if (require_Document.pathsEqual(clientPath, serverPath)) return {
|
|
1485
1228
|
type: "transformed",
|
|
1486
1229
|
operation: clientOp
|
|
1487
1230
|
};
|
|
1488
|
-
if (serverOp.kind === "array.set" && isPrefix(serverPath, clientPath)) return {
|
|
1231
|
+
if (serverOp.kind === "array.set" && require_Document.isPrefix(serverPath, clientPath)) return {
|
|
1489
1232
|
type: "transformed",
|
|
1490
1233
|
operation: clientOp
|
|
1491
1234
|
};
|
|
@@ -1497,12 +1240,12 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1497
1240
|
operation: clientOp
|
|
1498
1241
|
};
|
|
1499
1242
|
const elementPrimitive = this._schema.element;
|
|
1500
|
-
const clientOpForElement = _objectSpread2(_objectSpread2({}, clientOp), {}, { path: clientOp.path.shift() });
|
|
1501
|
-
const serverOpForElement = _objectSpread2(_objectSpread2({}, serverOp), {}, { path: serverOp.path.shift() });
|
|
1243
|
+
const clientOpForElement = require_Presence._objectSpread2(require_Presence._objectSpread2({}, clientOp), {}, { path: clientOp.path.shift() });
|
|
1244
|
+
const serverOpForElement = require_Presence._objectSpread2(require_Presence._objectSpread2({}, serverOp), {}, { path: serverOp.path.shift() });
|
|
1502
1245
|
const result = elementPrimitive._internal.transformOperation(clientOpForElement, serverOpForElement);
|
|
1503
1246
|
if (result.type === "transformed") return {
|
|
1504
1247
|
type: "transformed",
|
|
1505
|
-
operation: _objectSpread2(_objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
1248
|
+
operation: require_Presence._objectSpread2(require_Presence._objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
1506
1249
|
};
|
|
1507
1250
|
return result;
|
|
1508
1251
|
}
|
|
@@ -1516,11 +1259,11 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1516
1259
|
}
|
|
1517
1260
|
/** Mark this array as required */
|
|
1518
1261
|
required() {
|
|
1519
|
-
return new ArrayPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
1262
|
+
return new ArrayPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
1520
1263
|
}
|
|
1521
1264
|
/** Set a default value for this array */
|
|
1522
1265
|
default(defaultValue) {
|
|
1523
|
-
return new ArrayPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1266
|
+
return new ArrayPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1524
1267
|
}
|
|
1525
1268
|
/** Get the element primitive */
|
|
1526
1269
|
get element() {
|
|
@@ -1528,7 +1271,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1528
1271
|
}
|
|
1529
1272
|
/** Add a custom validation rule */
|
|
1530
1273
|
refine(fn, message) {
|
|
1531
|
-
return new ArrayPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
1274
|
+
return new ArrayPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
1532
1275
|
validate: fn,
|
|
1533
1276
|
message
|
|
1534
1277
|
}] }));
|
|
@@ -1554,12 +1297,16 @@ const Array$1 = (element) => new ArrayPrimitive({
|
|
|
1554
1297
|
//#region src/primitives/Lazy.ts
|
|
1555
1298
|
var LazyPrimitive = class {
|
|
1556
1299
|
constructor(thunk) {
|
|
1557
|
-
_defineProperty(this, "_tag", "LazyPrimitive");
|
|
1558
|
-
_defineProperty(this, "_State", void 0);
|
|
1559
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1560
|
-
_defineProperty(this, "
|
|
1561
|
-
_defineProperty(this, "
|
|
1562
|
-
_defineProperty(this, "
|
|
1300
|
+
require_Document._defineProperty(this, "_tag", "LazyPrimitive");
|
|
1301
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
1302
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
1303
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
1304
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
1305
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1306
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1307
|
+
require_Document._defineProperty(this, "_thunk", void 0);
|
|
1308
|
+
require_Document._defineProperty(this, "_resolved", void 0);
|
|
1309
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1563
1310
|
createProxy: (env, operationPath) => {
|
|
1564
1311
|
return this._resolve()._internal.createProxy(env, operationPath);
|
|
1565
1312
|
},
|
|
@@ -1592,19 +1339,21 @@ const Lazy = (thunk) => new LazyPrimitive(thunk);
|
|
|
1592
1339
|
//#region src/primitives/Union.ts
|
|
1593
1340
|
var UnionPrimitive = class UnionPrimitive {
|
|
1594
1341
|
constructor(schema) {
|
|
1595
|
-
_defineProperty(this, "_tag", "UnionPrimitive");
|
|
1596
|
-
_defineProperty(this, "_State", void 0);
|
|
1597
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1598
|
-
_defineProperty(this, "
|
|
1599
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
1600
|
-
_defineProperty(this, "
|
|
1601
|
-
_defineProperty(this, "
|
|
1342
|
+
require_Document._defineProperty(this, "_tag", "UnionPrimitive");
|
|
1343
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
1344
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
1345
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
1346
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
1347
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1348
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1349
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
1350
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
1602
1351
|
kind: "union.set",
|
|
1603
1352
|
payload: effect.Schema.Unknown,
|
|
1604
1353
|
target: effect.Schema.Unknown,
|
|
1605
1354
|
apply: (payload) => payload
|
|
1606
1355
|
}) });
|
|
1607
|
-
_defineProperty(this, "_internal", {
|
|
1356
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1608
1357
|
createProxy: (env, operationPath) => {
|
|
1609
1358
|
const variants = this._schema.variants;
|
|
1610
1359
|
const defaultValue = this._schema.defaultValue;
|
|
@@ -1615,7 +1364,7 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1615
1364
|
},
|
|
1616
1365
|
set: (value) => {
|
|
1617
1366
|
const merged = this._applyVariantDefaults(value);
|
|
1618
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, merged));
|
|
1367
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, merged));
|
|
1619
1368
|
},
|
|
1620
1369
|
as: (variant) => {
|
|
1621
1370
|
const variantPrimitive = variants[variant];
|
|
@@ -1660,7 +1409,7 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1660
1409
|
transformOperation: (clientOp, serverOp) => {
|
|
1661
1410
|
const clientPath = clientOp.path;
|
|
1662
1411
|
const serverPath = serverOp.path;
|
|
1663
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
1412
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
1664
1413
|
type: "transformed",
|
|
1665
1414
|
operation: clientOp
|
|
1666
1415
|
};
|
|
@@ -1700,12 +1449,12 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1700
1449
|
}
|
|
1701
1450
|
/** Mark this union as required */
|
|
1702
1451
|
required() {
|
|
1703
|
-
return new UnionPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
1452
|
+
return new UnionPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
1704
1453
|
}
|
|
1705
1454
|
/** Set a default value for this union */
|
|
1706
1455
|
default(defaultValue) {
|
|
1707
1456
|
const merged = this._applyVariantDefaults(defaultValue);
|
|
1708
|
-
return new UnionPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue: merged }));
|
|
1457
|
+
return new UnionPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue: merged }));
|
|
1709
1458
|
}
|
|
1710
1459
|
/** Get the discriminator field name */
|
|
1711
1460
|
get discriminator() {
|
|
@@ -1748,19 +1497,21 @@ function Union(options) {
|
|
|
1748
1497
|
//#region src/primitives/Either.ts
|
|
1749
1498
|
var EitherPrimitive = class EitherPrimitive {
|
|
1750
1499
|
constructor(schema) {
|
|
1751
|
-
_defineProperty(this, "_tag", "EitherPrimitive");
|
|
1752
|
-
_defineProperty(this, "_State", void 0);
|
|
1753
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1754
|
-
_defineProperty(this, "
|
|
1755
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
1756
|
-
_defineProperty(this, "
|
|
1757
|
-
_defineProperty(this, "
|
|
1500
|
+
require_Document._defineProperty(this, "_tag", "EitherPrimitive");
|
|
1501
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
1502
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
1503
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
1504
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
1505
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1506
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1507
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
1508
|
+
require_Document._defineProperty(this, "_opDefinitions", { set: make({
|
|
1758
1509
|
kind: "either.set",
|
|
1759
1510
|
payload: effect.Schema.Unknown,
|
|
1760
1511
|
target: effect.Schema.Unknown,
|
|
1761
1512
|
apply: (payload) => payload
|
|
1762
1513
|
}) });
|
|
1763
|
-
_defineProperty(this, "_internal", {
|
|
1514
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1764
1515
|
createProxy: (env, operationPath) => {
|
|
1765
1516
|
const defaultValue = this._schema.defaultValue;
|
|
1766
1517
|
return {
|
|
@@ -1769,7 +1520,10 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1769
1520
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
1770
1521
|
},
|
|
1771
1522
|
set: (value) => {
|
|
1772
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
1523
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
1524
|
+
},
|
|
1525
|
+
update: (value) => {
|
|
1526
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
1773
1527
|
},
|
|
1774
1528
|
match: (handlers) => {
|
|
1775
1529
|
const currentState = env.getState(operationPath);
|
|
@@ -1809,7 +1563,7 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1809
1563
|
return this._schema.defaultValue;
|
|
1810
1564
|
},
|
|
1811
1565
|
transformOperation: (clientOp, serverOp) => {
|
|
1812
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
1566
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
1813
1567
|
type: "transformed",
|
|
1814
1568
|
operation: clientOp
|
|
1815
1569
|
};
|
|
@@ -1823,11 +1577,11 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1823
1577
|
}
|
|
1824
1578
|
/** Mark this either as required */
|
|
1825
1579
|
required() {
|
|
1826
|
-
return new EitherPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
1580
|
+
return new EitherPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
1827
1581
|
}
|
|
1828
1582
|
/** Set a default value for this either */
|
|
1829
1583
|
default(defaultValue) {
|
|
1830
|
-
return new EitherPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1584
|
+
return new EitherPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1831
1585
|
}
|
|
1832
1586
|
/** Get the variants */
|
|
1833
1587
|
get variants() {
|
|
@@ -1961,14 +1715,16 @@ const isSelf = (value) => {
|
|
|
1961
1715
|
*/
|
|
1962
1716
|
var TreeNodePrimitive = class {
|
|
1963
1717
|
constructor(type, config) {
|
|
1964
|
-
_defineProperty(this, "_tag", "TreeNodePrimitive");
|
|
1965
|
-
_defineProperty(this, "_Type", void 0);
|
|
1966
|
-
_defineProperty(this, "_Data", void 0);
|
|
1967
|
-
_defineProperty(this, "_Children", void 0);
|
|
1968
|
-
_defineProperty(this, "
|
|
1969
|
-
_defineProperty(this, "
|
|
1970
|
-
_defineProperty(this, "
|
|
1971
|
-
_defineProperty(this, "
|
|
1718
|
+
require_Document._defineProperty(this, "_tag", "TreeNodePrimitive");
|
|
1719
|
+
require_Document._defineProperty(this, "_Type", void 0);
|
|
1720
|
+
require_Document._defineProperty(this, "_Data", void 0);
|
|
1721
|
+
require_Document._defineProperty(this, "_Children", void 0);
|
|
1722
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1723
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1724
|
+
require_Document._defineProperty(this, "_type", void 0);
|
|
1725
|
+
require_Document._defineProperty(this, "_data", void 0);
|
|
1726
|
+
require_Document._defineProperty(this, "_children", void 0);
|
|
1727
|
+
require_Document._defineProperty(this, "_resolvedChildren", void 0);
|
|
1972
1728
|
this._type = type;
|
|
1973
1729
|
this._data = config.data;
|
|
1974
1730
|
this._children = config.children;
|
|
@@ -2031,40 +1787,42 @@ const generateTreePosBetween = (left, right) => {
|
|
|
2031
1787
|
};
|
|
2032
1788
|
var TreePrimitive = class TreePrimitive {
|
|
2033
1789
|
constructor(schema) {
|
|
2034
|
-
_defineProperty(this, "_tag", "TreePrimitive");
|
|
2035
|
-
_defineProperty(this, "_State", void 0);
|
|
2036
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
2037
|
-
_defineProperty(this, "
|
|
2038
|
-
_defineProperty(this, "_THasDefault", void 0);
|
|
2039
|
-
_defineProperty(this, "
|
|
2040
|
-
_defineProperty(this, "
|
|
2041
|
-
_defineProperty(this, "
|
|
2042
|
-
|
|
1790
|
+
require_Document._defineProperty(this, "_tag", "TreePrimitive");
|
|
1791
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
1792
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
1793
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
1794
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
1795
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1796
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1797
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
1798
|
+
require_Document._defineProperty(this, "_nodeTypeRegistry", void 0);
|
|
1799
|
+
require_Document._defineProperty(this, "_opDefinitions", {
|
|
1800
|
+
set: make({
|
|
2043
1801
|
kind: "tree.set",
|
|
2044
1802
|
payload: effect.Schema.Unknown,
|
|
2045
1803
|
target: effect.Schema.Unknown,
|
|
2046
1804
|
apply: (payload) => payload
|
|
2047
1805
|
}),
|
|
2048
|
-
insert: make
|
|
1806
|
+
insert: make({
|
|
2049
1807
|
kind: "tree.insert",
|
|
2050
1808
|
payload: effect.Schema.Unknown,
|
|
2051
1809
|
target: effect.Schema.Unknown,
|
|
2052
1810
|
apply: (payload) => payload
|
|
2053
1811
|
}),
|
|
2054
|
-
remove: make
|
|
1812
|
+
remove: make({
|
|
2055
1813
|
kind: "tree.remove",
|
|
2056
1814
|
payload: effect.Schema.Unknown,
|
|
2057
1815
|
target: effect.Schema.Unknown,
|
|
2058
1816
|
apply: (payload) => payload
|
|
2059
1817
|
}),
|
|
2060
|
-
move: make
|
|
1818
|
+
move: make({
|
|
2061
1819
|
kind: "tree.move",
|
|
2062
1820
|
payload: effect.Schema.Unknown,
|
|
2063
1821
|
target: effect.Schema.Unknown,
|
|
2064
1822
|
apply: (payload) => payload
|
|
2065
1823
|
})
|
|
2066
1824
|
});
|
|
2067
|
-
_defineProperty(this, "_internal", {
|
|
1825
|
+
require_Document._defineProperty(this, "_internal", {
|
|
2068
1826
|
createProxy: (env, operationPath) => {
|
|
2069
1827
|
const getCurrentState = () => {
|
|
2070
1828
|
const state = env.getState(operationPath);
|
|
@@ -2109,7 +1867,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2109
1867
|
const childSnapshot = buildSnapshot(child.id, nodes);
|
|
2110
1868
|
if (childSnapshot) children.push(childSnapshot);
|
|
2111
1869
|
}
|
|
2112
|
-
return _objectSpread2(_objectSpread2({
|
|
1870
|
+
return require_Presence._objectSpread2(require_Presence._objectSpread2({
|
|
2113
1871
|
id: node.id,
|
|
2114
1872
|
type: node.type
|
|
2115
1873
|
}, node.data), {}, { children });
|
|
@@ -2119,7 +1877,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2119
1877
|
return getCurrentState();
|
|
2120
1878
|
},
|
|
2121
1879
|
set: (nodes) => {
|
|
2122
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, nodes));
|
|
1880
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, nodes));
|
|
2123
1881
|
},
|
|
2124
1882
|
root: () => {
|
|
2125
1883
|
return getCurrentState().find((n) => n.parentId === null);
|
|
@@ -2142,7 +1900,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2142
1900
|
this._validateChildType(parentType, nodeType.type);
|
|
2143
1901
|
if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
|
|
2144
1902
|
const mergedData = applyDefaults(nodeType.data, data);
|
|
2145
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1903
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2146
1904
|
id,
|
|
2147
1905
|
type: nodeType.type,
|
|
2148
1906
|
parentId,
|
|
@@ -2161,7 +1919,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2161
1919
|
this._validateChildType(parentType, nodeType.type);
|
|
2162
1920
|
if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
|
|
2163
1921
|
const mergedData = applyDefaults(nodeType.data, data);
|
|
2164
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1922
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2165
1923
|
id,
|
|
2166
1924
|
type: nodeType.type,
|
|
2167
1925
|
parentId,
|
|
@@ -2181,7 +1939,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2181
1939
|
this._validateChildType(parentType, nodeType.type);
|
|
2182
1940
|
if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
|
|
2183
1941
|
const mergedData = applyDefaults(nodeType.data, data);
|
|
2184
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1942
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2185
1943
|
id,
|
|
2186
1944
|
type: nodeType.type,
|
|
2187
1945
|
parentId,
|
|
@@ -2203,7 +1961,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2203
1961
|
const parentType = getParentType(parentId);
|
|
2204
1962
|
this._validateChildType(parentType, nodeType.type);
|
|
2205
1963
|
const mergedData = applyDefaults(nodeType.data, data);
|
|
2206
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1964
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2207
1965
|
id,
|
|
2208
1966
|
type: nodeType.type,
|
|
2209
1967
|
parentId,
|
|
@@ -2225,7 +1983,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2225
1983
|
const parentType = getParentType(parentId);
|
|
2226
1984
|
this._validateChildType(parentType, nodeType.type);
|
|
2227
1985
|
const mergedData = applyDefaults(nodeType.data, data);
|
|
2228
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1986
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2229
1987
|
id,
|
|
2230
1988
|
type: nodeType.type,
|
|
2231
1989
|
parentId,
|
|
@@ -2235,7 +1993,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2235
1993
|
return id;
|
|
2236
1994
|
},
|
|
2237
1995
|
remove: (id) => {
|
|
2238
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
1996
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
2239
1997
|
},
|
|
2240
1998
|
move: (nodeId, newParentId, toIndex) => {
|
|
2241
1999
|
var _state$find$type, _state$find;
|
|
@@ -2250,7 +2008,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2250
2008
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2251
2009
|
const clampedIndex = Math.max(0, Math.min(toIndex, siblings.length));
|
|
2252
2010
|
const pos = generateTreePosBetween(clampedIndex > 0 && siblings[clampedIndex - 1] ? siblings[clampedIndex - 1].pos : null, clampedIndex < siblings.length && siblings[clampedIndex] ? siblings[clampedIndex].pos : null);
|
|
2253
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2011
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2254
2012
|
id: nodeId,
|
|
2255
2013
|
parentId: newParentId,
|
|
2256
2014
|
pos
|
|
@@ -2271,7 +2029,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2271
2029
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2272
2030
|
const nextSibling = siblings[siblings.findIndex((n) => n.id === siblingId) + 1];
|
|
2273
2031
|
const pos = generateTreePosBetween(sibling.pos, (_nextSibling$pos2 = nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.pos) !== null && _nextSibling$pos2 !== void 0 ? _nextSibling$pos2 : null);
|
|
2274
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2032
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2275
2033
|
id: nodeId,
|
|
2276
2034
|
parentId: newParentId,
|
|
2277
2035
|
pos
|
|
@@ -2292,7 +2050,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2292
2050
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2293
2051
|
const prevSibling = siblings[siblings.findIndex((n) => n.id === siblingId) - 1];
|
|
2294
2052
|
const pos = generateTreePosBetween((_prevSibling$pos2 = prevSibling === null || prevSibling === void 0 ? void 0 : prevSibling.pos) !== null && _prevSibling$pos2 !== void 0 ? _prevSibling$pos2 : null, sibling.pos);
|
|
2295
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2053
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2296
2054
|
id: nodeId,
|
|
2297
2055
|
parentId: newParentId,
|
|
2298
2056
|
pos
|
|
@@ -2310,7 +2068,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2310
2068
|
if (node.parentId === null && newParentId !== null) throw new ValidationError("Cannot move root node to have a parent");
|
|
2311
2069
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2312
2070
|
const pos = generateTreePosBetween(null, siblings.length > 0 ? siblings[0].pos : null);
|
|
2313
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2071
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2314
2072
|
id: nodeId,
|
|
2315
2073
|
parentId: newParentId,
|
|
2316
2074
|
pos
|
|
@@ -2328,7 +2086,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2328
2086
|
if (node.parentId === null && newParentId !== null) throw new ValidationError("Cannot move root node to have a parent");
|
|
2329
2087
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2330
2088
|
const pos = generateTreePosBetween(siblings.length > 0 ? siblings[siblings.length - 1].pos : null, null);
|
|
2331
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2089
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2332
2090
|
id: nodeId,
|
|
2333
2091
|
parentId: newParentId,
|
|
2334
2092
|
pos
|
|
@@ -2388,7 +2146,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2388
2146
|
}
|
|
2389
2147
|
case "tree.move": {
|
|
2390
2148
|
const { id, parentId, pos } = operation.payload;
|
|
2391
|
-
newState = currentState.map((node) => node.id === id ? _objectSpread2(_objectSpread2({}, node), {}, {
|
|
2149
|
+
newState = currentState.map((node) => node.id === id ? require_Presence._objectSpread2(require_Presence._objectSpread2({}, node), {}, {
|
|
2392
2150
|
parentId,
|
|
2393
2151
|
pos
|
|
2394
2152
|
}) : node);
|
|
@@ -2403,10 +2161,10 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2403
2161
|
const node = currentState[nodeIndex];
|
|
2404
2162
|
const nodeTypePrimitive = this._getNodeTypePrimitive(node.type);
|
|
2405
2163
|
const remainingPath = path.shift();
|
|
2406
|
-
const nodeOperation = _objectSpread2(_objectSpread2({}, operation), {}, { path: remainingPath });
|
|
2164
|
+
const nodeOperation = require_Presence._objectSpread2(require_Presence._objectSpread2({}, operation), {}, { path: remainingPath });
|
|
2407
2165
|
const newData = nodeTypePrimitive.data._internal.applyOperation(node.data, nodeOperation);
|
|
2408
2166
|
const mutableState = [...currentState];
|
|
2409
|
-
mutableState[nodeIndex] = _objectSpread2(_objectSpread2({}, node), {}, { data: newData });
|
|
2167
|
+
mutableState[nodeIndex] = require_Presence._objectSpread2(require_Presence._objectSpread2({}, node), {}, { data: newData });
|
|
2410
2168
|
newState = mutableState;
|
|
2411
2169
|
}
|
|
2412
2170
|
runValidators(newState, this._schema.validators);
|
|
@@ -2430,7 +2188,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2430
2188
|
transformOperation: (clientOp, serverOp) => {
|
|
2431
2189
|
const clientPath = clientOp.path;
|
|
2432
2190
|
const serverPath = serverOp.path;
|
|
2433
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
2191
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
2434
2192
|
type: "transformed",
|
|
2435
2193
|
operation: clientOp
|
|
2436
2194
|
};
|
|
@@ -2463,11 +2221,11 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2463
2221
|
operation: clientOp
|
|
2464
2222
|
};
|
|
2465
2223
|
}
|
|
2466
|
-
if (pathsEqual(clientPath, serverPath)) return {
|
|
2224
|
+
if (require_Document.pathsEqual(clientPath, serverPath)) return {
|
|
2467
2225
|
type: "transformed",
|
|
2468
2226
|
operation: clientOp
|
|
2469
2227
|
};
|
|
2470
|
-
if (serverOp.kind === "tree.set" && isPrefix(serverPath, clientPath)) return {
|
|
2228
|
+
if (serverOp.kind === "tree.set" && require_Document.isPrefix(serverPath, clientPath)) return {
|
|
2471
2229
|
type: "transformed",
|
|
2472
2230
|
operation: clientOp
|
|
2473
2231
|
};
|
|
@@ -2493,11 +2251,11 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2493
2251
|
}
|
|
2494
2252
|
/** Mark this tree as required */
|
|
2495
2253
|
required() {
|
|
2496
|
-
return new TreePrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
2254
|
+
return new TreePrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
2497
2255
|
}
|
|
2498
2256
|
/** Set a default value for this tree */
|
|
2499
2257
|
default(defaultValue) {
|
|
2500
|
-
return new TreePrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
2258
|
+
return new TreePrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
2501
2259
|
}
|
|
2502
2260
|
/** Get the root node type */
|
|
2503
2261
|
get root() {
|
|
@@ -2505,7 +2263,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2505
2263
|
}
|
|
2506
2264
|
/** Add a custom validation rule */
|
|
2507
2265
|
refine(fn, message) {
|
|
2508
|
-
return new TreePrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
2266
|
+
return new TreePrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
2509
2267
|
validate: fn,
|
|
2510
2268
|
message
|
|
2511
2269
|
}] }));
|
|
@@ -2557,7 +2315,7 @@ const Tree = (options) => new TreePrimitive({
|
|
|
2557
2315
|
|
|
2558
2316
|
//#endregion
|
|
2559
2317
|
//#region src/Primitive.ts
|
|
2560
|
-
var Primitive_exports = /* @__PURE__ */ __export({
|
|
2318
|
+
var Primitive_exports = /* @__PURE__ */ require_Document.__export({
|
|
2561
2319
|
Array: () => Array$1,
|
|
2562
2320
|
ArrayPrimitive: () => ArrayPrimitive,
|
|
2563
2321
|
Boolean: () => Boolean,
|
|
@@ -2568,9 +2326,9 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2568
2326
|
LazyPrimitive: () => LazyPrimitive,
|
|
2569
2327
|
Literal: () => Literal,
|
|
2570
2328
|
LiteralPrimitive: () => LiteralPrimitive,
|
|
2571
|
-
Number: () => Number
|
|
2329
|
+
Number: () => Number,
|
|
2572
2330
|
NumberPrimitive: () => NumberPrimitive,
|
|
2573
|
-
String: () => String
|
|
2331
|
+
String: () => String,
|
|
2574
2332
|
StringPrimitive: () => StringPrimitive,
|
|
2575
2333
|
Struct: () => Struct,
|
|
2576
2334
|
StructPrimitive: () => StructPrimitive,
|
|
@@ -2587,330 +2345,33 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2587
2345
|
runValidators: () => runValidators
|
|
2588
2346
|
});
|
|
2589
2347
|
|
|
2590
|
-
//#endregion
|
|
2591
|
-
//#region src/ProxyEnvironment.ts
|
|
2592
|
-
var ProxyEnvironment_exports = /* @__PURE__ */ __export({ make: () => make$3 });
|
|
2593
|
-
/** Default UUID generator using crypto.randomUUID */
|
|
2594
|
-
const defaultGenerateId = () => {
|
|
2595
|
-
return crypto.randomUUID();
|
|
2596
|
-
};
|
|
2597
|
-
/** Default state getter that always returns undefined */
|
|
2598
|
-
const defaultGetState = (_path) => {};
|
|
2599
|
-
/**
|
|
2600
|
-
* Creates a ProxyEnvironment.
|
|
2601
|
-
* @param optionsOrCallback - Either an options object or a simple callback for operations
|
|
2602
|
-
*/
|
|
2603
|
-
const make$3 = (optionsOrCallback) => {
|
|
2604
|
-
var _options$getState, _options$generateId;
|
|
2605
|
-
const options = typeof optionsOrCallback === "function" ? { onOperation: optionsOrCallback } : optionsOrCallback;
|
|
2606
|
-
return {
|
|
2607
|
-
addOperation: (operation) => {
|
|
2608
|
-
options.onOperation(operation);
|
|
2609
|
-
},
|
|
2610
|
-
getState: (_options$getState = options.getState) !== null && _options$getState !== void 0 ? _options$getState : defaultGetState,
|
|
2611
|
-
generateId: (_options$generateId = options.generateId) !== null && _options$generateId !== void 0 ? _options$generateId : defaultGenerateId
|
|
2612
|
-
};
|
|
2613
|
-
};
|
|
2614
|
-
|
|
2615
|
-
//#endregion
|
|
2616
|
-
//#region src/Transaction.ts
|
|
2617
|
-
var Transaction_exports = /* @__PURE__ */ __export({
|
|
2618
|
-
decode: () => decode,
|
|
2619
|
-
empty: () => empty,
|
|
2620
|
-
encode: () => encode,
|
|
2621
|
-
isEmpty: () => isEmpty,
|
|
2622
|
-
make: () => make$2,
|
|
2623
|
-
merge: () => merge
|
|
2624
|
-
});
|
|
2625
|
-
/**
|
|
2626
|
-
* Creates a new Transaction with the given operations.
|
|
2627
|
-
*/
|
|
2628
|
-
const make$2 = (ops) => ({
|
|
2629
|
-
id: crypto.randomUUID(),
|
|
2630
|
-
ops,
|
|
2631
|
-
timestamp: Date.now()
|
|
2632
|
-
});
|
|
2633
|
-
/**
|
|
2634
|
-
* Creates an empty Transaction.
|
|
2635
|
-
*/
|
|
2636
|
-
const empty = () => make$2([]);
|
|
2637
|
-
/**
|
|
2638
|
-
* Checks if a transaction is empty (has no operations).
|
|
2639
|
-
*/
|
|
2640
|
-
const isEmpty = (tx) => tx.ops.length === 0;
|
|
2641
|
-
/**
|
|
2642
|
-
* Merges multiple transactions into one.
|
|
2643
|
-
*/
|
|
2644
|
-
const merge = (txs) => {
|
|
2645
|
-
return make$2(txs.flatMap((tx) => tx.ops));
|
|
2646
|
-
};
|
|
2647
|
-
/**
|
|
2648
|
-
* Encodes a Transaction to a JSON-serializable format for network transport.
|
|
2649
|
-
* @param transaction - The transaction to encode.
|
|
2650
|
-
* @returns The encoded representation.
|
|
2651
|
-
*/
|
|
2652
|
-
const encode = (transaction) => ({
|
|
2653
|
-
id: transaction.id,
|
|
2654
|
-
ops: transaction.ops.map(encode$1),
|
|
2655
|
-
timestamp: transaction.timestamp
|
|
2656
|
-
});
|
|
2657
|
-
/**
|
|
2658
|
-
* Decodes an encoded transaction back to a Transaction.
|
|
2659
|
-
* @param encoded - The encoded representation.
|
|
2660
|
-
* @returns The decoded Transaction.
|
|
2661
|
-
*/
|
|
2662
|
-
const decode = (encoded) => ({
|
|
2663
|
-
id: encoded.id,
|
|
2664
|
-
ops: encoded.ops.map(decode$1),
|
|
2665
|
-
timestamp: encoded.timestamp
|
|
2666
|
-
});
|
|
2667
|
-
|
|
2668
|
-
//#endregion
|
|
2669
|
-
//#region src/Document.ts
|
|
2670
|
-
var Document_exports = /* @__PURE__ */ __export({
|
|
2671
|
-
NestedTransactionError: () => NestedTransactionError,
|
|
2672
|
-
OperationError: () => OperationError,
|
|
2673
|
-
make: () => make$1
|
|
2674
|
-
});
|
|
2675
|
-
/**
|
|
2676
|
-
* Error thrown when attempting to start a nested transaction.
|
|
2677
|
-
*/
|
|
2678
|
-
var NestedTransactionError = class extends Error {
|
|
2679
|
-
constructor() {
|
|
2680
|
-
super("Nested transactions are not supported");
|
|
2681
|
-
_defineProperty(this, "_tag", "NestedTransactionError");
|
|
2682
|
-
this.name = "NestedTransactionError";
|
|
2683
|
-
}
|
|
2684
|
-
};
|
|
2685
|
-
/**
|
|
2686
|
-
* Error thrown when an operation fails to apply.
|
|
2687
|
-
*/
|
|
2688
|
-
var OperationError = class extends Error {
|
|
2689
|
-
constructor(message) {
|
|
2690
|
-
super(message);
|
|
2691
|
-
_defineProperty(this, "_tag", "OperationError");
|
|
2692
|
-
this.name = "OperationError";
|
|
2693
|
-
}
|
|
2694
|
-
};
|
|
2695
|
-
/**
|
|
2696
|
-
* Creates a new Document for the given schema.
|
|
2697
|
-
*/
|
|
2698
|
-
const make$1 = (schema, options) => {
|
|
2699
|
-
var _options$initial;
|
|
2700
|
-
let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
|
|
2701
|
-
let _pending = [];
|
|
2702
|
-
let _inTransaction = false;
|
|
2703
|
-
let _txOps = [];
|
|
2704
|
-
let _txBaseState = void 0;
|
|
2705
|
-
/**
|
|
2706
|
-
* Gets state at the given path.
|
|
2707
|
-
*/
|
|
2708
|
-
const getStateAtPath = (path) => {
|
|
2709
|
-
const tokens = path.toTokens().filter((t) => t !== "");
|
|
2710
|
-
if (tokens.length === 0) return _state;
|
|
2711
|
-
let current = _state;
|
|
2712
|
-
for (const token of tokens) {
|
|
2713
|
-
if (current === null || current === void 0) return;
|
|
2714
|
-
if (typeof current === "object") {
|
|
2715
|
-
if (Array.isArray(current)) {
|
|
2716
|
-
const entry = current.find((e) => e.id === token);
|
|
2717
|
-
if (entry) {
|
|
2718
|
-
current = entry.value;
|
|
2719
|
-
continue;
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
current = current[token];
|
|
2723
|
-
} else return;
|
|
2724
|
-
}
|
|
2725
|
-
return current;
|
|
2726
|
-
};
|
|
2727
|
-
/**
|
|
2728
|
-
* Applies a single operation to the current state.
|
|
2729
|
-
*/
|
|
2730
|
-
const applyOperation = (op) => {
|
|
2731
|
-
try {
|
|
2732
|
-
_state = schema._internal.applyOperation(_state, op);
|
|
2733
|
-
} catch (error) {
|
|
2734
|
-
if (error instanceof Error) throw new OperationError(error.message);
|
|
2735
|
-
throw new OperationError(String(error));
|
|
2736
|
-
}
|
|
2737
|
-
};
|
|
2738
|
-
/**
|
|
2739
|
-
* Handles an operation from a proxy.
|
|
2740
|
-
* In transaction mode: collects operations, applies to state immediately for subsequent reads.
|
|
2741
|
-
* Outside transaction mode: auto-wraps in a single-operation transaction.
|
|
2742
|
-
*/
|
|
2743
|
-
const handleOperation = (op) => {
|
|
2744
|
-
if (_inTransaction) {
|
|
2745
|
-
_txOps.push(op);
|
|
2746
|
-
applyOperation(op);
|
|
2747
|
-
} else {
|
|
2748
|
-
const baseState = _state;
|
|
2749
|
-
try {
|
|
2750
|
-
applyOperation(op);
|
|
2751
|
-
_pending.push(op);
|
|
2752
|
-
} catch (error) {
|
|
2753
|
-
_state = baseState;
|
|
2754
|
-
throw error;
|
|
2755
|
-
}
|
|
2756
|
-
}
|
|
2757
|
-
};
|
|
2758
|
-
/**
|
|
2759
|
-
* Creates a ProxyEnvironment for the document.
|
|
2760
|
-
*/
|
|
2761
|
-
const createEnv = () => {
|
|
2762
|
-
return make$3({
|
|
2763
|
-
onOperation: handleOperation,
|
|
2764
|
-
getState: getStateAtPath
|
|
2765
|
-
});
|
|
2766
|
-
};
|
|
2767
|
-
const env = createEnv();
|
|
2768
|
-
const rootProxy = schema._internal.createProxy(env, make$4(""));
|
|
2769
|
-
return {
|
|
2770
|
-
schema,
|
|
2771
|
-
root: rootProxy,
|
|
2772
|
-
get: () => {
|
|
2773
|
-
return _state;
|
|
2774
|
-
},
|
|
2775
|
-
toSnapshot: () => {
|
|
2776
|
-
return rootProxy.toSnapshot();
|
|
2777
|
-
},
|
|
2778
|
-
transaction: (fn) => {
|
|
2779
|
-
if (_inTransaction) throw new NestedTransactionError();
|
|
2780
|
-
_inTransaction = true;
|
|
2781
|
-
_txOps = [];
|
|
2782
|
-
_txBaseState = _state;
|
|
2783
|
-
try {
|
|
2784
|
-
const result = fn(rootProxy);
|
|
2785
|
-
_pending.push(..._txOps);
|
|
2786
|
-
return result;
|
|
2787
|
-
} catch (error) {
|
|
2788
|
-
_state = _txBaseState;
|
|
2789
|
-
throw error;
|
|
2790
|
-
} finally {
|
|
2791
|
-
_inTransaction = false;
|
|
2792
|
-
_txOps = [];
|
|
2793
|
-
_txBaseState = void 0;
|
|
2794
|
-
}
|
|
2795
|
-
},
|
|
2796
|
-
apply: (ops) => {
|
|
2797
|
-
for (const op of ops) applyOperation(op);
|
|
2798
|
-
},
|
|
2799
|
-
flush: () => {
|
|
2800
|
-
const tx = make$2(_pending);
|
|
2801
|
-
_pending = [];
|
|
2802
|
-
return tx;
|
|
2803
|
-
}
|
|
2804
|
-
};
|
|
2805
|
-
};
|
|
2806
|
-
|
|
2807
2348
|
//#endregion
|
|
2808
2349
|
//#region src/Transform.ts
|
|
2809
2350
|
var Transform_exports = {};
|
|
2810
2351
|
|
|
2811
|
-
//#endregion
|
|
2812
|
-
//#region src/Presence.ts
|
|
2813
|
-
/**
|
|
2814
|
-
* @since 0.0.1
|
|
2815
|
-
* Presence module for ephemeral per-connection state.
|
|
2816
|
-
* Used by both client and server for schema validation.
|
|
2817
|
-
*/
|
|
2818
|
-
var Presence_exports = /* @__PURE__ */ __export({
|
|
2819
|
-
isValid: () => isValid,
|
|
2820
|
-
make: () => make,
|
|
2821
|
-
validate: () => validate,
|
|
2822
|
-
validateSafe: () => validateSafe
|
|
2823
|
-
});
|
|
2824
|
-
/**
|
|
2825
|
-
* Creates a new Presence schema wrapper.
|
|
2826
|
-
*
|
|
2827
|
-
* @example
|
|
2828
|
-
* ```typescript
|
|
2829
|
-
* import { Presence } from "@voidhash/mimic";
|
|
2830
|
-
* import { Schema } from "effect";
|
|
2831
|
-
*
|
|
2832
|
-
* const CursorPresence = Presence.make({
|
|
2833
|
-
* schema: Schema.Struct({
|
|
2834
|
-
* name: Schema.String,
|
|
2835
|
-
* cursor: Schema.Struct({
|
|
2836
|
-
* x: Schema.Number,
|
|
2837
|
-
* y: Schema.Number,
|
|
2838
|
-
* }),
|
|
2839
|
-
* }),
|
|
2840
|
-
* });
|
|
2841
|
-
* ```
|
|
2842
|
-
*/
|
|
2843
|
-
const make = (options) => ({
|
|
2844
|
-
_tag: "Presence",
|
|
2845
|
-
schema: options.schema,
|
|
2846
|
-
_Data: void 0
|
|
2847
|
-
});
|
|
2848
|
-
/**
|
|
2849
|
-
* Validates unknown data against a Presence schema.
|
|
2850
|
-
* Throws a ParseError if validation fails.
|
|
2851
|
-
*
|
|
2852
|
-
* @param presence - The Presence instance with the schema
|
|
2853
|
-
* @param data - Unknown data to validate
|
|
2854
|
-
* @returns The validated and typed data
|
|
2855
|
-
* @throws ParseError if validation fails
|
|
2856
|
-
*/
|
|
2857
|
-
const validate = (presence, data) => {
|
|
2858
|
-
return effect_Schema.decodeUnknownSync(presence.schema)(data);
|
|
2859
|
-
};
|
|
2860
|
-
/**
|
|
2861
|
-
* Safely validates unknown data against a Presence schema.
|
|
2862
|
-
* Returns undefined if validation fails instead of throwing.
|
|
2863
|
-
*
|
|
2864
|
-
* @param presence - The Presence instance with the schema
|
|
2865
|
-
* @param data - Unknown data to validate
|
|
2866
|
-
* @returns The validated data or undefined if invalid
|
|
2867
|
-
*/
|
|
2868
|
-
const validateSafe = (presence, data) => {
|
|
2869
|
-
try {
|
|
2870
|
-
return effect_Schema.decodeUnknownSync(presence.schema)(data);
|
|
2871
|
-
} catch (_unused) {
|
|
2872
|
-
return;
|
|
2873
|
-
}
|
|
2874
|
-
};
|
|
2875
|
-
/**
|
|
2876
|
-
* Checks if unknown data is valid according to a Presence schema.
|
|
2877
|
-
*
|
|
2878
|
-
* @param presence - The Presence instance with the schema
|
|
2879
|
-
* @param data - Unknown data to check
|
|
2880
|
-
* @returns true if valid, false otherwise
|
|
2881
|
-
*/
|
|
2882
|
-
const isValid = (presence, data) => {
|
|
2883
|
-
try {
|
|
2884
|
-
effect_Schema.decodeUnknownSync(presence.schema)(data);
|
|
2885
|
-
return true;
|
|
2886
|
-
} catch (_unused2) {
|
|
2887
|
-
return false;
|
|
2888
|
-
}
|
|
2889
|
-
};
|
|
2890
|
-
|
|
2891
2352
|
//#endregion
|
|
2892
2353
|
Object.defineProperty(exports, 'Document', {
|
|
2893
2354
|
enumerable: true,
|
|
2894
2355
|
get: function () {
|
|
2895
|
-
return Document_exports;
|
|
2356
|
+
return require_Document.Document_exports;
|
|
2896
2357
|
}
|
|
2897
2358
|
});
|
|
2898
2359
|
Object.defineProperty(exports, 'Operation', {
|
|
2899
2360
|
enumerable: true,
|
|
2900
2361
|
get: function () {
|
|
2901
|
-
return Operation_exports;
|
|
2362
|
+
return require_Document.Operation_exports;
|
|
2902
2363
|
}
|
|
2903
2364
|
});
|
|
2904
2365
|
Object.defineProperty(exports, 'OperationPath', {
|
|
2905
2366
|
enumerable: true,
|
|
2906
2367
|
get: function () {
|
|
2907
|
-
return OperationPath_exports;
|
|
2368
|
+
return require_Document.OperationPath_exports;
|
|
2908
2369
|
}
|
|
2909
2370
|
});
|
|
2910
2371
|
Object.defineProperty(exports, 'Presence', {
|
|
2911
2372
|
enumerable: true,
|
|
2912
2373
|
get: function () {
|
|
2913
|
-
return Presence_exports;
|
|
2374
|
+
return require_Presence.Presence_exports;
|
|
2914
2375
|
}
|
|
2915
2376
|
});
|
|
2916
2377
|
Object.defineProperty(exports, 'Primitive', {
|
|
@@ -2922,13 +2383,13 @@ Object.defineProperty(exports, 'Primitive', {
|
|
|
2922
2383
|
Object.defineProperty(exports, 'ProxyEnvironment', {
|
|
2923
2384
|
enumerable: true,
|
|
2924
2385
|
get: function () {
|
|
2925
|
-
return ProxyEnvironment_exports;
|
|
2386
|
+
return require_Document.ProxyEnvironment_exports;
|
|
2926
2387
|
}
|
|
2927
2388
|
});
|
|
2928
2389
|
Object.defineProperty(exports, 'Transaction', {
|
|
2929
2390
|
enumerable: true,
|
|
2930
2391
|
get: function () {
|
|
2931
|
-
return Transaction_exports;
|
|
2392
|
+
return require_Document.Transaction_exports;
|
|
2932
2393
|
}
|
|
2933
2394
|
});
|
|
2934
2395
|
Object.defineProperty(exports, 'Transform', {
|