@voidhash/mimic 0.0.1-alpha.6 → 0.0.1-alpha.8
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-BK7kfHJZ.d.cts +1165 -0
- package/dist/Primitive-BK7kfHJZ.d.cts.map +1 -0
- package/dist/Primitive-D1kdB6za.d.mts +1165 -0
- package/dist/Primitive-D1kdB6za.d.mts.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 +309 -757
- package/dist/index.d.cts +5 -1054
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -1054
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +168 -575
- 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 +57 -22
- package/src/primitives/Boolean.ts +32 -18
- package/src/primitives/Either.ts +39 -24
- package/src/primitives/Lazy.ts +16 -2
- package/src/primitives/Literal.ts +32 -19
- package/src/primitives/Number.ts +38 -25
- package/src/primitives/String.ts +39 -24
- package/src/primitives/Struct.ts +124 -27
- package/src/primitives/Tree.ts +117 -30
- package/src/primitives/Union.ts +56 -29
- package/src/primitives/shared.ts +103 -9
- package/tests/primitives/Array.test.ts +108 -0
- package/tests/primitives/Struct.test.ts +250 -0
- package/tests/primitives/Tree.test.ts +250 -0
- package/tsdown.config.ts +1 -1
- /package/dist/{chunk-C6wwvPpM.mjs → chunk-CLMFDpHK.mjs} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,94 +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
4
|
|
|
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
5
|
//#region src/primitives/shared.ts
|
|
88
6
|
var ValidationError = class extends Error {
|
|
89
7
|
constructor(message) {
|
|
90
8
|
super(message);
|
|
91
|
-
_defineProperty(this, "_tag", "ValidationError");
|
|
9
|
+
require_Document._defineProperty(this, "_tag", "ValidationError");
|
|
92
10
|
this.name = "ValidationError";
|
|
93
11
|
}
|
|
94
12
|
};
|
|
@@ -107,10 +25,38 @@ function runValidators(value, validators) {
|
|
|
107
25
|
function isCompatibleOperation(operation, operationDefinitions) {
|
|
108
26
|
return Object.values(operationDefinitions).some((value) => value.kind === operation.kind);
|
|
109
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Applies default values to a partial input, recursively handling nested structs.
|
|
30
|
+
*
|
|
31
|
+
* Uses a two-layer approach:
|
|
32
|
+
* 1. First, get the struct's initial state (which includes struct-level defaults)
|
|
33
|
+
* 2. Then, layer the provided values on top
|
|
34
|
+
* 3. Finally, ensure nested structs are recursively processed
|
|
35
|
+
*
|
|
36
|
+
* @param primitive - The primitive definition containing field information
|
|
37
|
+
* @param value - The partial value provided by the user
|
|
38
|
+
* @returns The value with defaults applied for missing fields
|
|
39
|
+
*/
|
|
40
|
+
function applyDefaults(primitive, value) {
|
|
41
|
+
if (primitive._tag === "StructPrimitive") {
|
|
42
|
+
var _structPrimitive$_int;
|
|
43
|
+
const structPrimitive = primitive;
|
|
44
|
+
const result = require_Presence._objectSpread2(require_Presence._objectSpread2({}, (_structPrimitive$_int = structPrimitive._internal.getInitialState()) !== null && _structPrimitive$_int !== void 0 ? _structPrimitive$_int : {}), value);
|
|
45
|
+
for (const key in structPrimitive.fields) {
|
|
46
|
+
const fieldPrimitive = structPrimitive.fields[key];
|
|
47
|
+
if (result[key] === void 0) {
|
|
48
|
+
const fieldDefault = fieldPrimitive._internal.getInitialState();
|
|
49
|
+
if (fieldDefault !== void 0) result[key] = fieldDefault;
|
|
50
|
+
} else if (fieldPrimitive._tag === "StructPrimitive" && typeof result[key] === "object" && result[key] !== null) result[key] = applyDefaults(fieldPrimitive, result[key]);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
110
56
|
|
|
111
57
|
//#endregion
|
|
112
58
|
//#region src/OperationDefinition.ts
|
|
113
|
-
const make
|
|
59
|
+
const make = (options) => {
|
|
114
60
|
return {
|
|
115
61
|
kind: options.kind,
|
|
116
62
|
payload: options.payload,
|
|
@@ -119,220 +65,25 @@ const make$5 = (options) => {
|
|
|
119
65
|
};
|
|
120
66
|
};
|
|
121
67
|
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/OperationPath.ts
|
|
124
|
-
var OperationPath_exports = /* @__PURE__ */ __export({
|
|
125
|
-
decode: () => decode$2,
|
|
126
|
-
encode: () => encode$2,
|
|
127
|
-
fromTokens: () => fromTokens,
|
|
128
|
-
getRelativePath: () => getRelativePath,
|
|
129
|
-
isPrefix: () => isPrefix,
|
|
130
|
-
make: () => make$4,
|
|
131
|
-
pathsEqual: () => pathsEqual,
|
|
132
|
-
pathsOverlap: () => pathsOverlap
|
|
133
|
-
});
|
|
134
|
-
const parseStringPath = (stringPath) => {
|
|
135
|
-
return stringPath.split("/");
|
|
136
|
-
};
|
|
137
|
-
const makeStringPathFromTokens = (tokens) => {
|
|
138
|
-
return tokens.join("/");
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Creates a new operation path.
|
|
142
|
-
* @param stringPath - The string path to create the path from.
|
|
143
|
-
* @returns The new operation path.
|
|
144
|
-
*/
|
|
145
|
-
function make$4(stringPath) {
|
|
146
|
-
const tokensInternal = stringPath ? parseStringPath(stringPath) : [];
|
|
147
|
-
/**
|
|
148
|
-
* Returns the tokens of the path.
|
|
149
|
-
* @returns The tokens of the path.
|
|
150
|
-
*/
|
|
151
|
-
const toTokens = () => {
|
|
152
|
-
return tokensInternal;
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Concatenates two paths.
|
|
156
|
-
* @param other - The other path to concatenate.
|
|
157
|
-
* @returns The new path.
|
|
158
|
-
*/
|
|
159
|
-
const concat = (other) => {
|
|
160
|
-
return make$4(makeStringPathFromTokens(toTokens().concat(other.toTokens())));
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Appends a token to the path.
|
|
164
|
-
* @param token - The token to append.
|
|
165
|
-
* @returns The new path.
|
|
166
|
-
*/
|
|
167
|
-
const append = (token) => {
|
|
168
|
-
return make$4(makeStringPathFromTokens(toTokens().concat([token])));
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Removes the last token from the path.
|
|
172
|
-
* @returns The new path.
|
|
173
|
-
*/
|
|
174
|
-
const pop = () => {
|
|
175
|
-
return make$4(makeStringPathFromTokens(toTokens().slice(0, -1)));
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Removes the first token from the path.
|
|
179
|
-
* @returns The new path.
|
|
180
|
-
*/
|
|
181
|
-
const shift = () => {
|
|
182
|
-
return make$4(makeStringPathFromTokens(toTokens().slice(1)));
|
|
183
|
-
};
|
|
184
|
-
return {
|
|
185
|
-
_tag: "OperationPath",
|
|
186
|
-
toTokens,
|
|
187
|
-
concat,
|
|
188
|
-
append,
|
|
189
|
-
pop,
|
|
190
|
-
shift
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Creates a new operation path from tokens.
|
|
195
|
-
* @param tokens - The tokens to create the path from.
|
|
196
|
-
* @returns The new operation path.
|
|
197
|
-
*/
|
|
198
|
-
function fromTokens(tokens) {
|
|
199
|
-
return make$4(makeStringPathFromTokens(tokens));
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Checks if two operation paths overlap (one is prefix of the other or equal).
|
|
203
|
-
*/
|
|
204
|
-
const pathsOverlap = (pathA, pathB) => {
|
|
205
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
206
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
207
|
-
const minLength = Math.min(tokensA.length, tokensB.length);
|
|
208
|
-
for (let i = 0; i < minLength; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
209
|
-
return true;
|
|
210
|
-
};
|
|
211
|
-
/**
|
|
212
|
-
* Checks if pathA is a prefix of pathB (pathA is ancestor of pathB).
|
|
213
|
-
*/
|
|
214
|
-
const isPrefix = (pathA, pathB) => {
|
|
215
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
216
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
217
|
-
if (tokensA.length > tokensB.length) return false;
|
|
218
|
-
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
219
|
-
return true;
|
|
220
|
-
};
|
|
221
|
-
/**
|
|
222
|
-
* Checks if two paths are exactly equal.
|
|
223
|
-
*/
|
|
224
|
-
const pathsEqual = (pathA, pathB) => {
|
|
225
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
226
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
227
|
-
if (tokensA.length !== tokensB.length) return false;
|
|
228
|
-
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
229
|
-
return true;
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Gets the relative path of pathB with respect to pathA.
|
|
233
|
-
* Assumes pathA is a prefix of pathB.
|
|
234
|
-
*/
|
|
235
|
-
const getRelativePath = (basePath, fullPath) => {
|
|
236
|
-
const baseTokens = basePath.toTokens().filter((t) => t !== "");
|
|
237
|
-
return fullPath.toTokens().filter((t) => t !== "").slice(baseTokens.length);
|
|
238
|
-
};
|
|
239
|
-
/**
|
|
240
|
-
* Encodes an OperationPath to a string for network transport.
|
|
241
|
-
* @param path - The operation path to encode.
|
|
242
|
-
* @returns The encoded string representation.
|
|
243
|
-
*/
|
|
244
|
-
const encode$2 = (path) => {
|
|
245
|
-
return makeStringPathFromTokens(path.toTokens());
|
|
246
|
-
};
|
|
247
|
-
/**
|
|
248
|
-
* Decodes an encoded string back to an OperationPath.
|
|
249
|
-
* @param encoded - The encoded string representation.
|
|
250
|
-
* @returns The decoded OperationPath.
|
|
251
|
-
*/
|
|
252
|
-
const decode$2 = (encoded) => {
|
|
253
|
-
return make$4(encoded);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
//#endregion
|
|
257
|
-
//#region src/Operation.ts
|
|
258
|
-
var Operation_exports = /* @__PURE__ */ __export({
|
|
259
|
-
decode: () => decode$1,
|
|
260
|
-
encode: () => encode$1,
|
|
261
|
-
fromDefinition: () => fromDefinition
|
|
262
|
-
});
|
|
263
|
-
const fromDefinition = (operationPath, definition, payload) => {
|
|
264
|
-
return {
|
|
265
|
-
kind: definition.kind,
|
|
266
|
-
path: operationPath,
|
|
267
|
-
payload
|
|
268
|
-
};
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* Encodes an Operation to a JSON-serializable format for network transport.
|
|
272
|
-
* @param operation - The operation to encode.
|
|
273
|
-
* @returns The encoded representation.
|
|
274
|
-
*/
|
|
275
|
-
const encode$1 = (operation) => {
|
|
276
|
-
return {
|
|
277
|
-
kind: operation.kind,
|
|
278
|
-
path: encode$2(operation.path),
|
|
279
|
-
payload: operation.payload
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* Decodes an encoded operation back to an Operation.
|
|
284
|
-
* Note: This returns a partial operation without the definition methods.
|
|
285
|
-
* The caller must have the operation definitions to fully reconstruct if needed.
|
|
286
|
-
* @param encoded - The encoded representation.
|
|
287
|
-
* @returns The decoded Operation (without definition-specific methods).
|
|
288
|
-
*/
|
|
289
|
-
const decode$1 = (encoded) => {
|
|
290
|
-
return {
|
|
291
|
-
kind: encoded.kind,
|
|
292
|
-
path: decode$2(encoded.path),
|
|
293
|
-
payload: encoded.payload
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
//#endregion
|
|
298
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
299
|
-
function ownKeys(e, r) {
|
|
300
|
-
var t = Object.keys(e);
|
|
301
|
-
if (Object.getOwnPropertySymbols) {
|
|
302
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
303
|
-
r && (o = o.filter(function(r$1) {
|
|
304
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
305
|
-
})), t.push.apply(t, o);
|
|
306
|
-
}
|
|
307
|
-
return t;
|
|
308
|
-
}
|
|
309
|
-
function _objectSpread2(e) {
|
|
310
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
311
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
312
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
313
|
-
_defineProperty(e, r$1, t[r$1]);
|
|
314
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
315
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
return e;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
68
|
//#endregion
|
|
322
69
|
//#region src/primitives/String.ts
|
|
323
70
|
var StringPrimitive = class StringPrimitive {
|
|
324
71
|
constructor(schema) {
|
|
325
|
-
_defineProperty(this, "_tag", "StringPrimitive");
|
|
326
|
-
_defineProperty(this, "_State", void 0);
|
|
327
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
328
|
-
_defineProperty(this, "
|
|
329
|
-
_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({
|
|
330
81
|
kind: "string.set",
|
|
331
82
|
payload: effect.Schema.String,
|
|
332
83
|
target: effect.Schema.String,
|
|
333
84
|
apply: (payload) => payload
|
|
334
85
|
}) });
|
|
335
|
-
_defineProperty(this, "_internal", {
|
|
86
|
+
require_Document._defineProperty(this, "_internal", {
|
|
336
87
|
createProxy: (env, operationPath) => {
|
|
337
88
|
const defaultValue = this._schema.defaultValue;
|
|
338
89
|
return {
|
|
@@ -341,7 +92,10 @@ var StringPrimitive = class StringPrimitive {
|
|
|
341
92
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
342
93
|
},
|
|
343
94
|
set: (value) => {
|
|
344
|
-
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));
|
|
345
99
|
},
|
|
346
100
|
toSnapshot: () => {
|
|
347
101
|
const state = env.getState(operationPath);
|
|
@@ -360,7 +114,7 @@ var StringPrimitive = class StringPrimitive {
|
|
|
360
114
|
return this._schema.defaultValue;
|
|
361
115
|
},
|
|
362
116
|
transformOperation: (clientOp, serverOp) => {
|
|
363
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
117
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
364
118
|
type: "transformed",
|
|
365
119
|
operation: clientOp
|
|
366
120
|
};
|
|
@@ -374,15 +128,15 @@ var StringPrimitive = class StringPrimitive {
|
|
|
374
128
|
}
|
|
375
129
|
/** Mark this string as required */
|
|
376
130
|
required() {
|
|
377
|
-
return new StringPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
131
|
+
return new StringPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
378
132
|
}
|
|
379
133
|
/** Set a default value for this string */
|
|
380
134
|
default(defaultValue) {
|
|
381
|
-
return new StringPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
135
|
+
return new StringPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
382
136
|
}
|
|
383
137
|
/** Add a custom validation rule */
|
|
384
138
|
refine(fn, message) {
|
|
385
|
-
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, {
|
|
386
140
|
validate: fn,
|
|
387
141
|
message
|
|
388
142
|
}] }));
|
|
@@ -421,7 +175,7 @@ var StringPrimitive = class StringPrimitive {
|
|
|
421
175
|
}
|
|
422
176
|
};
|
|
423
177
|
/** Creates a new StringPrimitive */
|
|
424
|
-
const String
|
|
178
|
+
const String = () => new StringPrimitive({
|
|
425
179
|
required: false,
|
|
426
180
|
defaultValue: void 0,
|
|
427
181
|
validators: []
|
|
@@ -431,17 +185,21 @@ const String$1 = () => new StringPrimitive({
|
|
|
431
185
|
//#region src/primitives/Struct.ts
|
|
432
186
|
var StructPrimitive = class StructPrimitive {
|
|
433
187
|
constructor(schema) {
|
|
434
|
-
_defineProperty(this, "_tag", "StructPrimitive");
|
|
435
|
-
_defineProperty(this, "_State", void 0);
|
|
436
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
437
|
-
_defineProperty(this, "
|
|
438
|
-
_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({
|
|
439
197
|
kind: "struct.set",
|
|
440
198
|
payload: effect.Schema.Unknown,
|
|
441
199
|
target: effect.Schema.Unknown,
|
|
442
200
|
apply: (payload) => payload
|
|
443
201
|
}) });
|
|
444
|
-
_defineProperty(this, "_internal", {
|
|
202
|
+
require_Document._defineProperty(this, "_internal", {
|
|
445
203
|
createProxy: (env, operationPath) => {
|
|
446
204
|
const fields = this._schema.fields;
|
|
447
205
|
const defaultValue = this._schema.defaultValue;
|
|
@@ -465,7 +223,20 @@ var StructPrimitive = class StructPrimitive {
|
|
|
465
223
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
466
224
|
},
|
|
467
225
|
set: (value) => {
|
|
468
|
-
|
|
226
|
+
const merged = applyDefaults(this, value);
|
|
227
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, merged));
|
|
228
|
+
},
|
|
229
|
+
update: (value) => {
|
|
230
|
+
for (const key in value) if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
231
|
+
const fieldValue = value[key];
|
|
232
|
+
if (fieldValue === void 0) continue;
|
|
233
|
+
const fieldPrimitive = fields[key];
|
|
234
|
+
if (!fieldPrimitive) continue;
|
|
235
|
+
const fieldPath = operationPath.append(key);
|
|
236
|
+
const fieldProxy = fieldPrimitive._internal.createProxy(env, fieldPath);
|
|
237
|
+
if (fieldPrimitive._tag === "StructPrimitive" && typeof fieldValue === "object" && fieldValue !== null && !Array.isArray(fieldValue)) fieldProxy.update(fieldValue);
|
|
238
|
+
else fieldProxy.set(fieldValue);
|
|
239
|
+
}
|
|
469
240
|
},
|
|
470
241
|
toSnapshot: () => {
|
|
471
242
|
return buildSnapshot();
|
|
@@ -474,6 +245,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
474
245
|
get: (target, prop, _receiver) => {
|
|
475
246
|
if (prop === "get") return target.get;
|
|
476
247
|
if (prop === "set") return target.set;
|
|
248
|
+
if (prop === "update") return target.update;
|
|
477
249
|
if (prop === "toSnapshot") return target.toSnapshot;
|
|
478
250
|
if (typeof prop === "symbol") return;
|
|
479
251
|
if (prop in fields) {
|
|
@@ -483,7 +255,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
483
255
|
}
|
|
484
256
|
},
|
|
485
257
|
has: (_target, prop) => {
|
|
486
|
-
if (prop === "get" || prop === "set" || prop === "toSnapshot") return true;
|
|
258
|
+
if (prop === "get" || prop === "set" || prop === "update" || prop === "toSnapshot") return true;
|
|
487
259
|
if (typeof prop === "string" && prop in fields) return true;
|
|
488
260
|
return false;
|
|
489
261
|
}
|
|
@@ -503,11 +275,11 @@ var StructPrimitive = class StructPrimitive {
|
|
|
503
275
|
if (!(fieldName in this._schema.fields)) throw new ValidationError(`Unknown field: ${globalThis.String(fieldName)}`);
|
|
504
276
|
const fieldPrimitive = this._schema.fields[fieldName];
|
|
505
277
|
const remainingPath = path.shift();
|
|
506
|
-
const fieldOperation = _objectSpread2(_objectSpread2({}, operation), {}, { path: remainingPath });
|
|
278
|
+
const fieldOperation = require_Presence._objectSpread2(require_Presence._objectSpread2({}, operation), {}, { path: remainingPath });
|
|
507
279
|
const currentState = state !== null && state !== void 0 ? state : {};
|
|
508
280
|
const currentFieldState = currentState[fieldName];
|
|
509
281
|
const newFieldState = fieldPrimitive._internal.applyOperation(currentFieldState, fieldOperation);
|
|
510
|
-
newState = _objectSpread2(_objectSpread2({}, currentState), {}, { [fieldName]: newFieldState });
|
|
282
|
+
newState = require_Presence._objectSpread2(require_Presence._objectSpread2({}, currentState), {}, { [fieldName]: newFieldState });
|
|
511
283
|
}
|
|
512
284
|
runValidators(newState, this._schema.validators);
|
|
513
285
|
return newState;
|
|
@@ -529,7 +301,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
529
301
|
transformOperation: (clientOp, serverOp) => {
|
|
530
302
|
const clientPath = clientOp.path;
|
|
531
303
|
const serverPath = serverOp.path;
|
|
532
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
304
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
533
305
|
type: "transformed",
|
|
534
306
|
operation: clientOp
|
|
535
307
|
};
|
|
@@ -558,12 +330,12 @@ var StructPrimitive = class StructPrimitive {
|
|
|
558
330
|
type: "transformed",
|
|
559
331
|
operation: clientOp
|
|
560
332
|
};
|
|
561
|
-
const clientOpForField = _objectSpread2(_objectSpread2({}, clientOp), {}, { path: clientOp.path.shift() });
|
|
562
|
-
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() });
|
|
563
335
|
const result = fieldPrimitive._internal.transformOperation(clientOpForField, serverOpForField);
|
|
564
336
|
if (result.type === "transformed") return {
|
|
565
337
|
type: "transformed",
|
|
566
|
-
operation: _objectSpread2(_objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
338
|
+
operation: require_Presence._objectSpread2(require_Presence._objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
567
339
|
};
|
|
568
340
|
return result;
|
|
569
341
|
}
|
|
@@ -577,11 +349,12 @@ var StructPrimitive = class StructPrimitive {
|
|
|
577
349
|
}
|
|
578
350
|
/** Mark this struct as required */
|
|
579
351
|
required() {
|
|
580
|
-
return new StructPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
352
|
+
return new StructPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
581
353
|
}
|
|
582
354
|
/** Set a default value for this struct */
|
|
583
355
|
default(defaultValue) {
|
|
584
|
-
|
|
356
|
+
const merged = applyDefaults(this, defaultValue);
|
|
357
|
+
return new StructPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue: merged }));
|
|
585
358
|
}
|
|
586
359
|
/** Get the fields schema */
|
|
587
360
|
get fields() {
|
|
@@ -589,7 +362,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
589
362
|
}
|
|
590
363
|
/** Add a custom validation rule (useful for cross-field validation) */
|
|
591
364
|
refine(fn, message) {
|
|
592
|
-
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, {
|
|
593
366
|
validate: fn,
|
|
594
367
|
message
|
|
595
368
|
}] }));
|
|
@@ -607,17 +380,21 @@ const Struct = (fields) => new StructPrimitive({
|
|
|
607
380
|
//#region src/primitives/Boolean.ts
|
|
608
381
|
var BooleanPrimitive = class BooleanPrimitive {
|
|
609
382
|
constructor(schema) {
|
|
610
|
-
_defineProperty(this, "_tag", "BooleanPrimitive");
|
|
611
|
-
_defineProperty(this, "_State", void 0);
|
|
612
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
613
|
-
_defineProperty(this, "
|
|
614
|
-
_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({
|
|
615
392
|
kind: "boolean.set",
|
|
616
393
|
payload: effect.Schema.Boolean,
|
|
617
394
|
target: effect.Schema.Boolean,
|
|
618
395
|
apply: (payload) => payload
|
|
619
396
|
}) });
|
|
620
|
-
_defineProperty(this, "_internal", {
|
|
397
|
+
require_Document._defineProperty(this, "_internal", {
|
|
621
398
|
createProxy: (env, operationPath) => {
|
|
622
399
|
const defaultValue = this._schema.defaultValue;
|
|
623
400
|
return {
|
|
@@ -626,7 +403,10 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
626
403
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
627
404
|
},
|
|
628
405
|
set: (value) => {
|
|
629
|
-
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));
|
|
630
410
|
},
|
|
631
411
|
toSnapshot: () => {
|
|
632
412
|
const state = env.getState(operationPath);
|
|
@@ -645,7 +425,7 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
645
425
|
return this._schema.defaultValue;
|
|
646
426
|
},
|
|
647
427
|
transformOperation: (clientOp, serverOp) => {
|
|
648
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
428
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
649
429
|
type: "transformed",
|
|
650
430
|
operation: clientOp
|
|
651
431
|
};
|
|
@@ -659,15 +439,15 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
659
439
|
}
|
|
660
440
|
/** Mark this boolean as required */
|
|
661
441
|
required() {
|
|
662
|
-
return new BooleanPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
442
|
+
return new BooleanPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
663
443
|
}
|
|
664
444
|
/** Set a default value for this boolean */
|
|
665
445
|
default(defaultValue) {
|
|
666
|
-
return new BooleanPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
446
|
+
return new BooleanPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
667
447
|
}
|
|
668
448
|
/** Add a custom validation rule */
|
|
669
449
|
refine(fn, message) {
|
|
670
|
-
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, {
|
|
671
451
|
validate: fn,
|
|
672
452
|
message
|
|
673
453
|
}] }));
|
|
@@ -684,17 +464,21 @@ const Boolean = () => new BooleanPrimitive({
|
|
|
684
464
|
//#region src/primitives/Number.ts
|
|
685
465
|
var NumberPrimitive = class NumberPrimitive {
|
|
686
466
|
constructor(schema) {
|
|
687
|
-
_defineProperty(this, "_tag", "NumberPrimitive");
|
|
688
|
-
_defineProperty(this, "_State", void 0);
|
|
689
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
690
|
-
_defineProperty(this, "
|
|
691
|
-
_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({
|
|
692
476
|
kind: "number.set",
|
|
693
477
|
payload: effect.Schema.Number,
|
|
694
478
|
target: effect.Schema.Number,
|
|
695
479
|
apply: (payload) => payload
|
|
696
480
|
}) });
|
|
697
|
-
_defineProperty(this, "_internal", {
|
|
481
|
+
require_Document._defineProperty(this, "_internal", {
|
|
698
482
|
createProxy: (env, operationPath) => {
|
|
699
483
|
const defaultValue = this._schema.defaultValue;
|
|
700
484
|
return {
|
|
@@ -703,7 +487,10 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
703
487
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
704
488
|
},
|
|
705
489
|
set: (value) => {
|
|
706
|
-
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));
|
|
707
494
|
},
|
|
708
495
|
toSnapshot: () => {
|
|
709
496
|
const state = env.getState(operationPath);
|
|
@@ -722,7 +509,7 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
722
509
|
return this._schema.defaultValue;
|
|
723
510
|
},
|
|
724
511
|
transformOperation: (clientOp, serverOp) => {
|
|
725
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
512
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
726
513
|
type: "transformed",
|
|
727
514
|
operation: clientOp
|
|
728
515
|
};
|
|
@@ -736,15 +523,15 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
736
523
|
}
|
|
737
524
|
/** Mark this number as required */
|
|
738
525
|
required() {
|
|
739
|
-
return new NumberPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
526
|
+
return new NumberPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
740
527
|
}
|
|
741
528
|
/** Set a default value for this number */
|
|
742
529
|
default(defaultValue) {
|
|
743
|
-
return new NumberPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
530
|
+
return new NumberPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
744
531
|
}
|
|
745
532
|
/** Add a custom validation rule */
|
|
746
533
|
refine(fn, message) {
|
|
747
|
-
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, {
|
|
748
535
|
validate: fn,
|
|
749
536
|
message
|
|
750
537
|
}] }));
|
|
@@ -771,7 +558,7 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
771
558
|
}
|
|
772
559
|
};
|
|
773
560
|
/** Creates a new NumberPrimitive */
|
|
774
|
-
const Number
|
|
561
|
+
const Number = () => new NumberPrimitive({
|
|
775
562
|
required: false,
|
|
776
563
|
defaultValue: void 0,
|
|
777
564
|
validators: []
|
|
@@ -781,17 +568,21 @@ const Number$1 = () => new NumberPrimitive({
|
|
|
781
568
|
//#region src/primitives/Literal.ts
|
|
782
569
|
var LiteralPrimitive = class LiteralPrimitive {
|
|
783
570
|
constructor(schema) {
|
|
784
|
-
_defineProperty(this, "_tag", "LiteralPrimitive");
|
|
785
|
-
_defineProperty(this, "_State", void 0);
|
|
786
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
787
|
-
_defineProperty(this, "
|
|
788
|
-
_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({
|
|
789
580
|
kind: "literal.set",
|
|
790
581
|
payload: effect.Schema.Unknown,
|
|
791
582
|
target: effect.Schema.Unknown,
|
|
792
583
|
apply: (payload) => payload
|
|
793
584
|
}) });
|
|
794
|
-
_defineProperty(this, "_internal", {
|
|
585
|
+
require_Document._defineProperty(this, "_internal", {
|
|
795
586
|
createProxy: (env, operationPath) => {
|
|
796
587
|
const defaultValue = this._schema.defaultValue;
|
|
797
588
|
return {
|
|
@@ -800,7 +591,10 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
800
591
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
801
592
|
},
|
|
802
593
|
set: (value) => {
|
|
803
|
-
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));
|
|
804
598
|
},
|
|
805
599
|
toSnapshot: () => {
|
|
806
600
|
const state = env.getState(operationPath);
|
|
@@ -818,7 +612,7 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
818
612
|
return this._schema.defaultValue;
|
|
819
613
|
},
|
|
820
614
|
transformOperation: (clientOp, serverOp) => {
|
|
821
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
615
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
822
616
|
type: "transformed",
|
|
823
617
|
operation: clientOp
|
|
824
618
|
};
|
|
@@ -832,11 +626,11 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
832
626
|
}
|
|
833
627
|
/** Mark this literal as required */
|
|
834
628
|
required() {
|
|
835
|
-
return new LiteralPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
629
|
+
return new LiteralPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
836
630
|
}
|
|
837
631
|
/** Set a default value for this literal */
|
|
838
632
|
default(defaultValue) {
|
|
839
|
-
return new LiteralPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
633
|
+
return new LiteralPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
840
634
|
}
|
|
841
635
|
/** Get the literal value this primitive represents */
|
|
842
636
|
get literal() {
|
|
@@ -1225,37 +1019,41 @@ const generatePosBetween = (left, right) => {
|
|
|
1225
1019
|
};
|
|
1226
1020
|
var ArrayPrimitive = class ArrayPrimitive {
|
|
1227
1021
|
constructor(schema) {
|
|
1228
|
-
_defineProperty(this, "_tag", "ArrayPrimitive");
|
|
1229
|
-
_defineProperty(this, "_State", void 0);
|
|
1230
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1231
|
-
_defineProperty(this, "
|
|
1232
|
-
_defineProperty(this, "
|
|
1233
|
-
|
|
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({
|
|
1234
1032
|
kind: "array.set",
|
|
1235
1033
|
payload: effect.Schema.Unknown,
|
|
1236
1034
|
target: effect.Schema.Unknown,
|
|
1237
1035
|
apply: (payload) => payload
|
|
1238
1036
|
}),
|
|
1239
|
-
insert: make
|
|
1037
|
+
insert: make({
|
|
1240
1038
|
kind: "array.insert",
|
|
1241
1039
|
payload: effect.Schema.Unknown,
|
|
1242
1040
|
target: effect.Schema.Unknown,
|
|
1243
1041
|
apply: (payload) => payload
|
|
1244
1042
|
}),
|
|
1245
|
-
remove: make
|
|
1043
|
+
remove: make({
|
|
1246
1044
|
kind: "array.remove",
|
|
1247
1045
|
payload: effect.Schema.Unknown,
|
|
1248
1046
|
target: effect.Schema.Unknown,
|
|
1249
1047
|
apply: (payload) => payload
|
|
1250
1048
|
}),
|
|
1251
|
-
move: make
|
|
1049
|
+
move: make({
|
|
1252
1050
|
kind: "array.move",
|
|
1253
1051
|
payload: effect.Schema.Unknown,
|
|
1254
1052
|
target: effect.Schema.Unknown,
|
|
1255
1053
|
apply: (payload) => payload
|
|
1256
1054
|
})
|
|
1257
1055
|
});
|
|
1258
|
-
_defineProperty(this, "_internal", {
|
|
1056
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1259
1057
|
createProxy: (env, operationPath) => {
|
|
1260
1058
|
const elementPrimitive = this._schema.element;
|
|
1261
1059
|
const getCurrentState = () => {
|
|
@@ -1263,6 +1061,9 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1263
1061
|
if (!state || !globalThis.Array.isArray(state)) return [];
|
|
1264
1062
|
return sortByPos(state);
|
|
1265
1063
|
};
|
|
1064
|
+
const applyElementDefaults = (value) => {
|
|
1065
|
+
return applyDefaults(elementPrimitive, value);
|
|
1066
|
+
};
|
|
1266
1067
|
return {
|
|
1267
1068
|
get: () => {
|
|
1268
1069
|
return getCurrentState();
|
|
@@ -1273,24 +1074,26 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1273
1074
|
for (const value of values) {
|
|
1274
1075
|
const id = env.generateId();
|
|
1275
1076
|
const pos = generatePosBetween(prevPos, null);
|
|
1077
|
+
const mergedValue = applyElementDefaults(value);
|
|
1276
1078
|
entries.push({
|
|
1277
1079
|
id,
|
|
1278
1080
|
pos,
|
|
1279
|
-
value
|
|
1081
|
+
value: mergedValue
|
|
1280
1082
|
});
|
|
1281
1083
|
prevPos = pos;
|
|
1282
1084
|
}
|
|
1283
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, entries));
|
|
1085
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, entries));
|
|
1284
1086
|
},
|
|
1285
1087
|
push: (value) => {
|
|
1286
1088
|
const sorted = getCurrentState();
|
|
1287
1089
|
const lastPos = sorted.length > 0 ? sorted[sorted.length - 1].pos : null;
|
|
1288
1090
|
const id = env.generateId();
|
|
1289
1091
|
const pos = generatePosBetween(lastPos, null);
|
|
1290
|
-
|
|
1092
|
+
const mergedValue = applyElementDefaults(value);
|
|
1093
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1291
1094
|
id,
|
|
1292
1095
|
pos,
|
|
1293
|
-
value
|
|
1096
|
+
value: mergedValue
|
|
1294
1097
|
}));
|
|
1295
1098
|
},
|
|
1296
1099
|
insertAt: (index, value) => {
|
|
@@ -1299,20 +1102,21 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1299
1102
|
const rightPos = index < sorted.length && sorted[index] ? sorted[index].pos : null;
|
|
1300
1103
|
const id = env.generateId();
|
|
1301
1104
|
const pos = generatePosBetween(leftPos, rightPos);
|
|
1302
|
-
|
|
1105
|
+
const mergedValue = applyElementDefaults(value);
|
|
1106
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
1303
1107
|
id,
|
|
1304
1108
|
pos,
|
|
1305
|
-
value
|
|
1109
|
+
value: mergedValue
|
|
1306
1110
|
}));
|
|
1307
1111
|
},
|
|
1308
1112
|
remove: (id) => {
|
|
1309
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
1113
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
1310
1114
|
},
|
|
1311
1115
|
move: (id, toIndex) => {
|
|
1312
1116
|
const without = getCurrentState().filter((e) => e.id !== id);
|
|
1313
1117
|
const clampedIndex = Math.max(0, Math.min(toIndex, without.length));
|
|
1314
1118
|
const pos = generatePosBetween(clampedIndex > 0 && without[clampedIndex - 1] ? without[clampedIndex - 1].pos : null, clampedIndex < without.length && without[clampedIndex] ? without[clampedIndex].pos : null);
|
|
1315
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
1119
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
1316
1120
|
id,
|
|
1317
1121
|
pos
|
|
1318
1122
|
}));
|
|
@@ -1367,7 +1171,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1367
1171
|
}
|
|
1368
1172
|
case "array.move": {
|
|
1369
1173
|
const { id, pos } = operation.payload;
|
|
1370
|
-
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);
|
|
1371
1175
|
break;
|
|
1372
1176
|
}
|
|
1373
1177
|
default: throw new ValidationError(`ArrayPrimitive cannot apply operation of kind: ${operation.kind}`);
|
|
@@ -1378,11 +1182,11 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1378
1182
|
if (entryIndex === -1) throw new ValidationError(`Array element not found with ID: ${elementId}`);
|
|
1379
1183
|
const elementPrimitive = this._schema.element;
|
|
1380
1184
|
const remainingPath = path.shift();
|
|
1381
|
-
const elementOperation = _objectSpread2(_objectSpread2({}, operation), {}, { path: remainingPath });
|
|
1185
|
+
const elementOperation = require_Presence._objectSpread2(require_Presence._objectSpread2({}, operation), {}, { path: remainingPath });
|
|
1382
1186
|
const currentEntry = currentState[entryIndex];
|
|
1383
1187
|
const newValue = elementPrimitive._internal.applyOperation(currentEntry.value, elementOperation);
|
|
1384
1188
|
const mutableState = [...currentState];
|
|
1385
|
-
mutableState[entryIndex] = _objectSpread2(_objectSpread2({}, currentEntry), {}, { value: newValue });
|
|
1189
|
+
mutableState[entryIndex] = require_Presence._objectSpread2(require_Presence._objectSpread2({}, currentEntry), {}, { value: newValue });
|
|
1386
1190
|
newState = mutableState;
|
|
1387
1191
|
}
|
|
1388
1192
|
runValidators(newState, this._schema.validators);
|
|
@@ -1394,7 +1198,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1394
1198
|
transformOperation: (clientOp, serverOp) => {
|
|
1395
1199
|
const clientPath = clientOp.path;
|
|
1396
1200
|
const serverPath = serverOp.path;
|
|
1397
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
1201
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
1398
1202
|
type: "transformed",
|
|
1399
1203
|
operation: clientOp
|
|
1400
1204
|
};
|
|
@@ -1420,11 +1224,11 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1420
1224
|
operation: clientOp
|
|
1421
1225
|
};
|
|
1422
1226
|
}
|
|
1423
|
-
if (pathsEqual(clientPath, serverPath)) return {
|
|
1227
|
+
if (require_Document.pathsEqual(clientPath, serverPath)) return {
|
|
1424
1228
|
type: "transformed",
|
|
1425
1229
|
operation: clientOp
|
|
1426
1230
|
};
|
|
1427
|
-
if (serverOp.kind === "array.set" && isPrefix(serverPath, clientPath)) return {
|
|
1231
|
+
if (serverOp.kind === "array.set" && require_Document.isPrefix(serverPath, clientPath)) return {
|
|
1428
1232
|
type: "transformed",
|
|
1429
1233
|
operation: clientOp
|
|
1430
1234
|
};
|
|
@@ -1436,12 +1240,12 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1436
1240
|
operation: clientOp
|
|
1437
1241
|
};
|
|
1438
1242
|
const elementPrimitive = this._schema.element;
|
|
1439
|
-
const clientOpForElement = _objectSpread2(_objectSpread2({}, clientOp), {}, { path: clientOp.path.shift() });
|
|
1440
|
-
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() });
|
|
1441
1245
|
const result = elementPrimitive._internal.transformOperation(clientOpForElement, serverOpForElement);
|
|
1442
1246
|
if (result.type === "transformed") return {
|
|
1443
1247
|
type: "transformed",
|
|
1444
|
-
operation: _objectSpread2(_objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
1248
|
+
operation: require_Presence._objectSpread2(require_Presence._objectSpread2({}, result.operation), {}, { path: clientOp.path })
|
|
1445
1249
|
};
|
|
1446
1250
|
return result;
|
|
1447
1251
|
}
|
|
@@ -1455,11 +1259,11 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1455
1259
|
}
|
|
1456
1260
|
/** Mark this array as required */
|
|
1457
1261
|
required() {
|
|
1458
|
-
return new ArrayPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
1262
|
+
return new ArrayPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
1459
1263
|
}
|
|
1460
1264
|
/** Set a default value for this array */
|
|
1461
1265
|
default(defaultValue) {
|
|
1462
|
-
return new ArrayPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1266
|
+
return new ArrayPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1463
1267
|
}
|
|
1464
1268
|
/** Get the element primitive */
|
|
1465
1269
|
get element() {
|
|
@@ -1467,7 +1271,7 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1467
1271
|
}
|
|
1468
1272
|
/** Add a custom validation rule */
|
|
1469
1273
|
refine(fn, message) {
|
|
1470
|
-
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, {
|
|
1471
1275
|
validate: fn,
|
|
1472
1276
|
message
|
|
1473
1277
|
}] }));
|
|
@@ -1493,12 +1297,16 @@ const Array$1 = (element) => new ArrayPrimitive({
|
|
|
1493
1297
|
//#region src/primitives/Lazy.ts
|
|
1494
1298
|
var LazyPrimitive = class {
|
|
1495
1299
|
constructor(thunk) {
|
|
1496
|
-
_defineProperty(this, "_tag", "LazyPrimitive");
|
|
1497
|
-
_defineProperty(this, "_State", void 0);
|
|
1498
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1499
|
-
_defineProperty(this, "
|
|
1500
|
-
_defineProperty(this, "
|
|
1501
|
-
_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", {
|
|
1502
1310
|
createProxy: (env, operationPath) => {
|
|
1503
1311
|
return this._resolve()._internal.createProxy(env, operationPath);
|
|
1504
1312
|
},
|
|
@@ -1531,17 +1339,21 @@ const Lazy = (thunk) => new LazyPrimitive(thunk);
|
|
|
1531
1339
|
//#region src/primitives/Union.ts
|
|
1532
1340
|
var UnionPrimitive = class UnionPrimitive {
|
|
1533
1341
|
constructor(schema) {
|
|
1534
|
-
_defineProperty(this, "_tag", "UnionPrimitive");
|
|
1535
|
-
_defineProperty(this, "_State", void 0);
|
|
1536
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1537
|
-
_defineProperty(this, "
|
|
1538
|
-
_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({
|
|
1539
1351
|
kind: "union.set",
|
|
1540
1352
|
payload: effect.Schema.Unknown,
|
|
1541
1353
|
target: effect.Schema.Unknown,
|
|
1542
1354
|
apply: (payload) => payload
|
|
1543
1355
|
}) });
|
|
1544
|
-
_defineProperty(this, "_internal", {
|
|
1356
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1545
1357
|
createProxy: (env, operationPath) => {
|
|
1546
1358
|
const variants = this._schema.variants;
|
|
1547
1359
|
const defaultValue = this._schema.defaultValue;
|
|
@@ -1551,7 +1363,8 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1551
1363
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
1552
1364
|
},
|
|
1553
1365
|
set: (value) => {
|
|
1554
|
-
|
|
1366
|
+
const merged = this._applyVariantDefaults(value);
|
|
1367
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, merged));
|
|
1555
1368
|
},
|
|
1556
1369
|
as: (variant) => {
|
|
1557
1370
|
const variantPrimitive = variants[variant];
|
|
@@ -1596,7 +1409,7 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1596
1409
|
transformOperation: (clientOp, serverOp) => {
|
|
1597
1410
|
const clientPath = clientOp.path;
|
|
1598
1411
|
const serverPath = serverOp.path;
|
|
1599
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
1412
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
1600
1413
|
type: "transformed",
|
|
1601
1414
|
operation: clientOp
|
|
1602
1415
|
};
|
|
@@ -1636,11 +1449,12 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1636
1449
|
}
|
|
1637
1450
|
/** Mark this union as required */
|
|
1638
1451
|
required() {
|
|
1639
|
-
return new UnionPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
1452
|
+
return new UnionPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
1640
1453
|
}
|
|
1641
1454
|
/** Set a default value for this union */
|
|
1642
1455
|
default(defaultValue) {
|
|
1643
|
-
|
|
1456
|
+
const merged = this._applyVariantDefaults(defaultValue);
|
|
1457
|
+
return new UnionPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue: merged }));
|
|
1644
1458
|
}
|
|
1645
1459
|
/** Get the discriminator field name */
|
|
1646
1460
|
get discriminator() {
|
|
@@ -1661,6 +1475,13 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1661
1475
|
}
|
|
1662
1476
|
}
|
|
1663
1477
|
}
|
|
1478
|
+
/** Apply defaults to a variant value based on the discriminator */
|
|
1479
|
+
_applyVariantDefaults(value) {
|
|
1480
|
+
const variantKey = this._findVariantKey(value);
|
|
1481
|
+
if (!variantKey) return value;
|
|
1482
|
+
const variantPrimitive = this._schema.variants[variantKey];
|
|
1483
|
+
return applyDefaults(variantPrimitive, value);
|
|
1484
|
+
}
|
|
1664
1485
|
};
|
|
1665
1486
|
function Union(options) {
|
|
1666
1487
|
var _options$discriminato;
|
|
@@ -1676,17 +1497,21 @@ function Union(options) {
|
|
|
1676
1497
|
//#region src/primitives/Either.ts
|
|
1677
1498
|
var EitherPrimitive = class EitherPrimitive {
|
|
1678
1499
|
constructor(schema) {
|
|
1679
|
-
_defineProperty(this, "_tag", "EitherPrimitive");
|
|
1680
|
-
_defineProperty(this, "_State", void 0);
|
|
1681
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1682
|
-
_defineProperty(this, "
|
|
1683
|
-
_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({
|
|
1684
1509
|
kind: "either.set",
|
|
1685
1510
|
payload: effect.Schema.Unknown,
|
|
1686
1511
|
target: effect.Schema.Unknown,
|
|
1687
1512
|
apply: (payload) => payload
|
|
1688
1513
|
}) });
|
|
1689
|
-
_defineProperty(this, "_internal", {
|
|
1514
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1690
1515
|
createProxy: (env, operationPath) => {
|
|
1691
1516
|
const defaultValue = this._schema.defaultValue;
|
|
1692
1517
|
return {
|
|
@@ -1695,7 +1520,10 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1695
1520
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
1696
1521
|
},
|
|
1697
1522
|
set: (value) => {
|
|
1698
|
-
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));
|
|
1699
1527
|
},
|
|
1700
1528
|
match: (handlers) => {
|
|
1701
1529
|
const currentState = env.getState(operationPath);
|
|
@@ -1735,7 +1563,7 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1735
1563
|
return this._schema.defaultValue;
|
|
1736
1564
|
},
|
|
1737
1565
|
transformOperation: (clientOp, serverOp) => {
|
|
1738
|
-
if (!pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
1566
|
+
if (!require_Document.pathsOverlap(clientOp.path, serverOp.path)) return {
|
|
1739
1567
|
type: "transformed",
|
|
1740
1568
|
operation: clientOp
|
|
1741
1569
|
};
|
|
@@ -1749,11 +1577,11 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1749
1577
|
}
|
|
1750
1578
|
/** Mark this either as required */
|
|
1751
1579
|
required() {
|
|
1752
|
-
return new EitherPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
1580
|
+
return new EitherPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
1753
1581
|
}
|
|
1754
1582
|
/** Set a default value for this either */
|
|
1755
1583
|
default(defaultValue) {
|
|
1756
|
-
return new EitherPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1584
|
+
return new EitherPrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
1757
1585
|
}
|
|
1758
1586
|
/** Get the variants */
|
|
1759
1587
|
get variants() {
|
|
@@ -1887,14 +1715,14 @@ const isSelf = (value) => {
|
|
|
1887
1715
|
*/
|
|
1888
1716
|
var TreeNodePrimitive = class {
|
|
1889
1717
|
constructor(type, config) {
|
|
1890
|
-
_defineProperty(this, "_tag", "TreeNodePrimitive");
|
|
1891
|
-
_defineProperty(this, "_Type", void 0);
|
|
1892
|
-
_defineProperty(this, "_Data", void 0);
|
|
1893
|
-
_defineProperty(this, "_Children", void 0);
|
|
1894
|
-
_defineProperty(this, "_type", void 0);
|
|
1895
|
-
_defineProperty(this, "_data", void 0);
|
|
1896
|
-
_defineProperty(this, "_children", void 0);
|
|
1897
|
-
_defineProperty(this, "_resolvedChildren", void 0);
|
|
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, "_type", void 0);
|
|
1723
|
+
require_Document._defineProperty(this, "_data", void 0);
|
|
1724
|
+
require_Document._defineProperty(this, "_children", void 0);
|
|
1725
|
+
require_Document._defineProperty(this, "_resolvedChildren", void 0);
|
|
1898
1726
|
this._type = type;
|
|
1899
1727
|
this._data = config.data;
|
|
1900
1728
|
this._children = config.children;
|
|
@@ -1957,38 +1785,42 @@ const generateTreePosBetween = (left, right) => {
|
|
|
1957
1785
|
};
|
|
1958
1786
|
var TreePrimitive = class TreePrimitive {
|
|
1959
1787
|
constructor(schema) {
|
|
1960
|
-
_defineProperty(this, "_tag", "TreePrimitive");
|
|
1961
|
-
_defineProperty(this, "_State", void 0);
|
|
1962
|
-
_defineProperty(this, "_Proxy", void 0);
|
|
1963
|
-
_defineProperty(this, "
|
|
1964
|
-
_defineProperty(this, "
|
|
1965
|
-
_defineProperty(this, "
|
|
1966
|
-
|
|
1788
|
+
require_Document._defineProperty(this, "_tag", "TreePrimitive");
|
|
1789
|
+
require_Document._defineProperty(this, "_State", void 0);
|
|
1790
|
+
require_Document._defineProperty(this, "_Proxy", void 0);
|
|
1791
|
+
require_Document._defineProperty(this, "_TRequired", void 0);
|
|
1792
|
+
require_Document._defineProperty(this, "_THasDefault", void 0);
|
|
1793
|
+
require_Document._defineProperty(this, "TSetInput", void 0);
|
|
1794
|
+
require_Document._defineProperty(this, "TUpdateInput", void 0);
|
|
1795
|
+
require_Document._defineProperty(this, "_schema", void 0);
|
|
1796
|
+
require_Document._defineProperty(this, "_nodeTypeRegistry", void 0);
|
|
1797
|
+
require_Document._defineProperty(this, "_opDefinitions", {
|
|
1798
|
+
set: make({
|
|
1967
1799
|
kind: "tree.set",
|
|
1968
1800
|
payload: effect.Schema.Unknown,
|
|
1969
1801
|
target: effect.Schema.Unknown,
|
|
1970
1802
|
apply: (payload) => payload
|
|
1971
1803
|
}),
|
|
1972
|
-
insert: make
|
|
1804
|
+
insert: make({
|
|
1973
1805
|
kind: "tree.insert",
|
|
1974
1806
|
payload: effect.Schema.Unknown,
|
|
1975
1807
|
target: effect.Schema.Unknown,
|
|
1976
1808
|
apply: (payload) => payload
|
|
1977
1809
|
}),
|
|
1978
|
-
remove: make
|
|
1810
|
+
remove: make({
|
|
1979
1811
|
kind: "tree.remove",
|
|
1980
1812
|
payload: effect.Schema.Unknown,
|
|
1981
1813
|
target: effect.Schema.Unknown,
|
|
1982
1814
|
apply: (payload) => payload
|
|
1983
1815
|
}),
|
|
1984
|
-
move: make
|
|
1816
|
+
move: make({
|
|
1985
1817
|
kind: "tree.move",
|
|
1986
1818
|
payload: effect.Schema.Unknown,
|
|
1987
1819
|
target: effect.Schema.Unknown,
|
|
1988
1820
|
apply: (payload) => payload
|
|
1989
1821
|
})
|
|
1990
1822
|
});
|
|
1991
|
-
_defineProperty(this, "_internal", {
|
|
1823
|
+
require_Document._defineProperty(this, "_internal", {
|
|
1992
1824
|
createProxy: (env, operationPath) => {
|
|
1993
1825
|
const getCurrentState = () => {
|
|
1994
1826
|
const state = env.getState(operationPath);
|
|
@@ -2010,11 +1842,15 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2010
1842
|
as: (nodeType) => {
|
|
2011
1843
|
if (nodeState.type !== nodeType.type) throw new ValidationError(`Node is of type "${nodeState.type}", not "${nodeType.type}"`);
|
|
2012
1844
|
const nodePath = operationPath.append(nodeState.id);
|
|
1845
|
+
const dataProxy = nodeType.data._internal.createProxy(env, nodePath);
|
|
2013
1846
|
return {
|
|
2014
1847
|
id: nodeState.id,
|
|
2015
1848
|
type: nodeType.type,
|
|
2016
|
-
data:
|
|
2017
|
-
get: () => nodeState
|
|
1849
|
+
data: dataProxy,
|
|
1850
|
+
get: () => nodeState,
|
|
1851
|
+
update: (value) => {
|
|
1852
|
+
dataProxy.update(value);
|
|
1853
|
+
}
|
|
2018
1854
|
};
|
|
2019
1855
|
},
|
|
2020
1856
|
get: () => nodeState
|
|
@@ -2029,7 +1865,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2029
1865
|
const childSnapshot = buildSnapshot(child.id, nodes);
|
|
2030
1866
|
if (childSnapshot) children.push(childSnapshot);
|
|
2031
1867
|
}
|
|
2032
|
-
return _objectSpread2(_objectSpread2({
|
|
1868
|
+
return require_Presence._objectSpread2(require_Presence._objectSpread2({
|
|
2033
1869
|
id: node.id,
|
|
2034
1870
|
type: node.type
|
|
2035
1871
|
}, node.data), {}, { children });
|
|
@@ -2039,7 +1875,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2039
1875
|
return getCurrentState();
|
|
2040
1876
|
},
|
|
2041
1877
|
set: (nodes) => {
|
|
2042
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, nodes));
|
|
1878
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.set, nodes));
|
|
2043
1879
|
},
|
|
2044
1880
|
root: () => {
|
|
2045
1881
|
return getCurrentState().find((n) => n.parentId === null);
|
|
@@ -2061,12 +1897,13 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2061
1897
|
const parentType = getParentType(parentId);
|
|
2062
1898
|
this._validateChildType(parentType, nodeType.type);
|
|
2063
1899
|
if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
|
|
2064
|
-
|
|
1900
|
+
const mergedData = applyDefaults(nodeType.data, data);
|
|
1901
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2065
1902
|
id,
|
|
2066
1903
|
type: nodeType.type,
|
|
2067
1904
|
parentId,
|
|
2068
1905
|
pos,
|
|
2069
|
-
data
|
|
1906
|
+
data: mergedData
|
|
2070
1907
|
}));
|
|
2071
1908
|
return id;
|
|
2072
1909
|
},
|
|
@@ -2079,12 +1916,13 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2079
1916
|
const parentType = getParentType(parentId);
|
|
2080
1917
|
this._validateChildType(parentType, nodeType.type);
|
|
2081
1918
|
if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
|
|
2082
|
-
|
|
1919
|
+
const mergedData = applyDefaults(nodeType.data, data);
|
|
1920
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2083
1921
|
id,
|
|
2084
1922
|
type: nodeType.type,
|
|
2085
1923
|
parentId,
|
|
2086
1924
|
pos,
|
|
2087
|
-
data
|
|
1925
|
+
data: mergedData
|
|
2088
1926
|
}));
|
|
2089
1927
|
return id;
|
|
2090
1928
|
},
|
|
@@ -2098,12 +1936,13 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2098
1936
|
const parentType = getParentType(parentId);
|
|
2099
1937
|
this._validateChildType(parentType, nodeType.type);
|
|
2100
1938
|
if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
|
|
2101
|
-
|
|
1939
|
+
const mergedData = applyDefaults(nodeType.data, data);
|
|
1940
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2102
1941
|
id,
|
|
2103
1942
|
type: nodeType.type,
|
|
2104
1943
|
parentId,
|
|
2105
1944
|
pos,
|
|
2106
|
-
data
|
|
1945
|
+
data: mergedData
|
|
2107
1946
|
}));
|
|
2108
1947
|
return id;
|
|
2109
1948
|
},
|
|
@@ -2119,12 +1958,13 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2119
1958
|
const id = env.generateId();
|
|
2120
1959
|
const parentType = getParentType(parentId);
|
|
2121
1960
|
this._validateChildType(parentType, nodeType.type);
|
|
2122
|
-
|
|
1961
|
+
const mergedData = applyDefaults(nodeType.data, data);
|
|
1962
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2123
1963
|
id,
|
|
2124
1964
|
type: nodeType.type,
|
|
2125
1965
|
parentId,
|
|
2126
1966
|
pos,
|
|
2127
|
-
data
|
|
1967
|
+
data: mergedData
|
|
2128
1968
|
}));
|
|
2129
1969
|
return id;
|
|
2130
1970
|
},
|
|
@@ -2140,17 +1980,18 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2140
1980
|
const id = env.generateId();
|
|
2141
1981
|
const parentType = getParentType(parentId);
|
|
2142
1982
|
this._validateChildType(parentType, nodeType.type);
|
|
2143
|
-
|
|
1983
|
+
const mergedData = applyDefaults(nodeType.data, data);
|
|
1984
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.insert, {
|
|
2144
1985
|
id,
|
|
2145
1986
|
type: nodeType.type,
|
|
2146
1987
|
parentId,
|
|
2147
1988
|
pos,
|
|
2148
|
-
data
|
|
1989
|
+
data: mergedData
|
|
2149
1990
|
}));
|
|
2150
1991
|
return id;
|
|
2151
1992
|
},
|
|
2152
1993
|
remove: (id) => {
|
|
2153
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
1994
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.remove, { id }));
|
|
2154
1995
|
},
|
|
2155
1996
|
move: (nodeId, newParentId, toIndex) => {
|
|
2156
1997
|
var _state$find$type, _state$find;
|
|
@@ -2165,7 +2006,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2165
2006
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2166
2007
|
const clampedIndex = Math.max(0, Math.min(toIndex, siblings.length));
|
|
2167
2008
|
const pos = generateTreePosBetween(clampedIndex > 0 && siblings[clampedIndex - 1] ? siblings[clampedIndex - 1].pos : null, clampedIndex < siblings.length && siblings[clampedIndex] ? siblings[clampedIndex].pos : null);
|
|
2168
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2009
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2169
2010
|
id: nodeId,
|
|
2170
2011
|
parentId: newParentId,
|
|
2171
2012
|
pos
|
|
@@ -2186,7 +2027,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2186
2027
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2187
2028
|
const nextSibling = siblings[siblings.findIndex((n) => n.id === siblingId) + 1];
|
|
2188
2029
|
const pos = generateTreePosBetween(sibling.pos, (_nextSibling$pos2 = nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.pos) !== null && _nextSibling$pos2 !== void 0 ? _nextSibling$pos2 : null);
|
|
2189
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2030
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2190
2031
|
id: nodeId,
|
|
2191
2032
|
parentId: newParentId,
|
|
2192
2033
|
pos
|
|
@@ -2207,7 +2048,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2207
2048
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2208
2049
|
const prevSibling = siblings[siblings.findIndex((n) => n.id === siblingId) - 1];
|
|
2209
2050
|
const pos = generateTreePosBetween((_prevSibling$pos2 = prevSibling === null || prevSibling === void 0 ? void 0 : prevSibling.pos) !== null && _prevSibling$pos2 !== void 0 ? _prevSibling$pos2 : null, sibling.pos);
|
|
2210
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2051
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2211
2052
|
id: nodeId,
|
|
2212
2053
|
parentId: newParentId,
|
|
2213
2054
|
pos
|
|
@@ -2225,7 +2066,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2225
2066
|
if (node.parentId === null && newParentId !== null) throw new ValidationError("Cannot move root node to have a parent");
|
|
2226
2067
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2227
2068
|
const pos = generateTreePosBetween(null, siblings.length > 0 ? siblings[0].pos : null);
|
|
2228
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2069
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2229
2070
|
id: nodeId,
|
|
2230
2071
|
parentId: newParentId,
|
|
2231
2072
|
pos
|
|
@@ -2243,7 +2084,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2243
2084
|
if (node.parentId === null && newParentId !== null) throw new ValidationError("Cannot move root node to have a parent");
|
|
2244
2085
|
const siblings = getOrderedChildren(state, newParentId).filter((n) => n.id !== nodeId);
|
|
2245
2086
|
const pos = generateTreePosBetween(siblings.length > 0 ? siblings[siblings.length - 1].pos : null, null);
|
|
2246
|
-
env.addOperation(fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2087
|
+
env.addOperation(require_Document.fromDefinition(operationPath, this._opDefinitions.move, {
|
|
2247
2088
|
id: nodeId,
|
|
2248
2089
|
parentId: newParentId,
|
|
2249
2090
|
pos
|
|
@@ -2256,6 +2097,13 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2256
2097
|
const nodePath = operationPath.append(id);
|
|
2257
2098
|
return nodeType.data._internal.createProxy(env, nodePath);
|
|
2258
2099
|
},
|
|
2100
|
+
updateAt: (id, nodeType, value) => {
|
|
2101
|
+
const node = getCurrentState().find((n) => n.id === id);
|
|
2102
|
+
if (!node) throw new ValidationError(`Node not found: ${id}`);
|
|
2103
|
+
if (node.type !== nodeType.type) throw new ValidationError(`Node is of type "${node.type}", not "${nodeType.type}"`);
|
|
2104
|
+
const nodePath = operationPath.append(id);
|
|
2105
|
+
nodeType.data._internal.createProxy(env, nodePath).update(value);
|
|
2106
|
+
},
|
|
2259
2107
|
toSnapshot: () => {
|
|
2260
2108
|
const state = getCurrentState();
|
|
2261
2109
|
const rootNode = state.find((n) => n.parentId === null);
|
|
@@ -2296,7 +2144,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2296
2144
|
}
|
|
2297
2145
|
case "tree.move": {
|
|
2298
2146
|
const { id, parentId, pos } = operation.payload;
|
|
2299
|
-
newState = currentState.map((node) => node.id === id ? _objectSpread2(_objectSpread2({}, node), {}, {
|
|
2147
|
+
newState = currentState.map((node) => node.id === id ? require_Presence._objectSpread2(require_Presence._objectSpread2({}, node), {}, {
|
|
2300
2148
|
parentId,
|
|
2301
2149
|
pos
|
|
2302
2150
|
}) : node);
|
|
@@ -2311,10 +2159,10 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2311
2159
|
const node = currentState[nodeIndex];
|
|
2312
2160
|
const nodeTypePrimitive = this._getNodeTypePrimitive(node.type);
|
|
2313
2161
|
const remainingPath = path.shift();
|
|
2314
|
-
const nodeOperation = _objectSpread2(_objectSpread2({}, operation), {}, { path: remainingPath });
|
|
2162
|
+
const nodeOperation = require_Presence._objectSpread2(require_Presence._objectSpread2({}, operation), {}, { path: remainingPath });
|
|
2315
2163
|
const newData = nodeTypePrimitive.data._internal.applyOperation(node.data, nodeOperation);
|
|
2316
2164
|
const mutableState = [...currentState];
|
|
2317
|
-
mutableState[nodeIndex] = _objectSpread2(_objectSpread2({}, node), {}, { data: newData });
|
|
2165
|
+
mutableState[nodeIndex] = require_Presence._objectSpread2(require_Presence._objectSpread2({}, node), {}, { data: newData });
|
|
2318
2166
|
newState = mutableState;
|
|
2319
2167
|
}
|
|
2320
2168
|
runValidators(newState, this._schema.validators);
|
|
@@ -2338,7 +2186,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2338
2186
|
transformOperation: (clientOp, serverOp) => {
|
|
2339
2187
|
const clientPath = clientOp.path;
|
|
2340
2188
|
const serverPath = serverOp.path;
|
|
2341
|
-
if (!pathsOverlap(clientPath, serverPath)) return {
|
|
2189
|
+
if (!require_Document.pathsOverlap(clientPath, serverPath)) return {
|
|
2342
2190
|
type: "transformed",
|
|
2343
2191
|
operation: clientOp
|
|
2344
2192
|
};
|
|
@@ -2371,11 +2219,11 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2371
2219
|
operation: clientOp
|
|
2372
2220
|
};
|
|
2373
2221
|
}
|
|
2374
|
-
if (pathsEqual(clientPath, serverPath)) return {
|
|
2222
|
+
if (require_Document.pathsEqual(clientPath, serverPath)) return {
|
|
2375
2223
|
type: "transformed",
|
|
2376
2224
|
operation: clientOp
|
|
2377
2225
|
};
|
|
2378
|
-
if (serverOp.kind === "tree.set" && isPrefix(serverPath, clientPath)) return {
|
|
2226
|
+
if (serverOp.kind === "tree.set" && require_Document.isPrefix(serverPath, clientPath)) return {
|
|
2379
2227
|
type: "transformed",
|
|
2380
2228
|
operation: clientOp
|
|
2381
2229
|
};
|
|
@@ -2401,11 +2249,11 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2401
2249
|
}
|
|
2402
2250
|
/** Mark this tree as required */
|
|
2403
2251
|
required() {
|
|
2404
|
-
return new TreePrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { required: true }));
|
|
2252
|
+
return new TreePrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { required: true }));
|
|
2405
2253
|
}
|
|
2406
2254
|
/** Set a default value for this tree */
|
|
2407
2255
|
default(defaultValue) {
|
|
2408
|
-
return new TreePrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
2256
|
+
return new TreePrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { defaultValue }));
|
|
2409
2257
|
}
|
|
2410
2258
|
/** Get the root node type */
|
|
2411
2259
|
get root() {
|
|
@@ -2413,7 +2261,7 @@ var TreePrimitive = class TreePrimitive {
|
|
|
2413
2261
|
}
|
|
2414
2262
|
/** Add a custom validation rule */
|
|
2415
2263
|
refine(fn, message) {
|
|
2416
|
-
return new TreePrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
2264
|
+
return new TreePrimitive(require_Presence._objectSpread2(require_Presence._objectSpread2({}, this._schema), {}, { validators: [...this._schema.validators, {
|
|
2417
2265
|
validate: fn,
|
|
2418
2266
|
message
|
|
2419
2267
|
}] }));
|
|
@@ -2465,7 +2313,7 @@ const Tree = (options) => new TreePrimitive({
|
|
|
2465
2313
|
|
|
2466
2314
|
//#endregion
|
|
2467
2315
|
//#region src/Primitive.ts
|
|
2468
|
-
var Primitive_exports = /* @__PURE__ */ __export({
|
|
2316
|
+
var Primitive_exports = /* @__PURE__ */ require_Document.__export({
|
|
2469
2317
|
Array: () => Array$1,
|
|
2470
2318
|
ArrayPrimitive: () => ArrayPrimitive,
|
|
2471
2319
|
Boolean: () => Boolean,
|
|
@@ -2476,9 +2324,9 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2476
2324
|
LazyPrimitive: () => LazyPrimitive,
|
|
2477
2325
|
Literal: () => Literal,
|
|
2478
2326
|
LiteralPrimitive: () => LiteralPrimitive,
|
|
2479
|
-
Number: () => Number
|
|
2327
|
+
Number: () => Number,
|
|
2480
2328
|
NumberPrimitive: () => NumberPrimitive,
|
|
2481
|
-
String: () => String
|
|
2329
|
+
String: () => String,
|
|
2482
2330
|
StringPrimitive: () => StringPrimitive,
|
|
2483
2331
|
Struct: () => Struct,
|
|
2484
2332
|
StructPrimitive: () => StructPrimitive,
|
|
@@ -2490,334 +2338,38 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2490
2338
|
Union: () => Union,
|
|
2491
2339
|
UnionPrimitive: () => UnionPrimitive,
|
|
2492
2340
|
ValidationError: () => ValidationError,
|
|
2341
|
+
applyDefaults: () => applyDefaults,
|
|
2493
2342
|
isCompatibleOperation: () => isCompatibleOperation,
|
|
2494
2343
|
runValidators: () => runValidators
|
|
2495
2344
|
});
|
|
2496
2345
|
|
|
2497
|
-
//#endregion
|
|
2498
|
-
//#region src/ProxyEnvironment.ts
|
|
2499
|
-
var ProxyEnvironment_exports = /* @__PURE__ */ __export({ make: () => make$3 });
|
|
2500
|
-
/** Default UUID generator using crypto.randomUUID */
|
|
2501
|
-
const defaultGenerateId = () => {
|
|
2502
|
-
return crypto.randomUUID();
|
|
2503
|
-
};
|
|
2504
|
-
/** Default state getter that always returns undefined */
|
|
2505
|
-
const defaultGetState = (_path) => {};
|
|
2506
|
-
/**
|
|
2507
|
-
* Creates a ProxyEnvironment.
|
|
2508
|
-
* @param optionsOrCallback - Either an options object or a simple callback for operations
|
|
2509
|
-
*/
|
|
2510
|
-
const make$3 = (optionsOrCallback) => {
|
|
2511
|
-
var _options$getState, _options$generateId;
|
|
2512
|
-
const options = typeof optionsOrCallback === "function" ? { onOperation: optionsOrCallback } : optionsOrCallback;
|
|
2513
|
-
return {
|
|
2514
|
-
addOperation: (operation) => {
|
|
2515
|
-
options.onOperation(operation);
|
|
2516
|
-
},
|
|
2517
|
-
getState: (_options$getState = options.getState) !== null && _options$getState !== void 0 ? _options$getState : defaultGetState,
|
|
2518
|
-
generateId: (_options$generateId = options.generateId) !== null && _options$generateId !== void 0 ? _options$generateId : defaultGenerateId
|
|
2519
|
-
};
|
|
2520
|
-
};
|
|
2521
|
-
|
|
2522
|
-
//#endregion
|
|
2523
|
-
//#region src/Transaction.ts
|
|
2524
|
-
var Transaction_exports = /* @__PURE__ */ __export({
|
|
2525
|
-
decode: () => decode,
|
|
2526
|
-
empty: () => empty,
|
|
2527
|
-
encode: () => encode,
|
|
2528
|
-
isEmpty: () => isEmpty,
|
|
2529
|
-
make: () => make$2,
|
|
2530
|
-
merge: () => merge
|
|
2531
|
-
});
|
|
2532
|
-
/**
|
|
2533
|
-
* Creates a new Transaction with the given operations.
|
|
2534
|
-
*/
|
|
2535
|
-
const make$2 = (ops) => ({
|
|
2536
|
-
id: crypto.randomUUID(),
|
|
2537
|
-
ops,
|
|
2538
|
-
timestamp: Date.now()
|
|
2539
|
-
});
|
|
2540
|
-
/**
|
|
2541
|
-
* Creates an empty Transaction.
|
|
2542
|
-
*/
|
|
2543
|
-
const empty = () => make$2([]);
|
|
2544
|
-
/**
|
|
2545
|
-
* Checks if a transaction is empty (has no operations).
|
|
2546
|
-
*/
|
|
2547
|
-
const isEmpty = (tx) => tx.ops.length === 0;
|
|
2548
|
-
/**
|
|
2549
|
-
* Merges multiple transactions into one.
|
|
2550
|
-
*/
|
|
2551
|
-
const merge = (txs) => {
|
|
2552
|
-
return make$2(txs.flatMap((tx) => tx.ops));
|
|
2553
|
-
};
|
|
2554
|
-
/**
|
|
2555
|
-
* Encodes a Transaction to a JSON-serializable format for network transport.
|
|
2556
|
-
* @param transaction - The transaction to encode.
|
|
2557
|
-
* @returns The encoded representation.
|
|
2558
|
-
*/
|
|
2559
|
-
const encode = (transaction) => ({
|
|
2560
|
-
id: transaction.id,
|
|
2561
|
-
ops: transaction.ops.map(encode$1),
|
|
2562
|
-
timestamp: transaction.timestamp
|
|
2563
|
-
});
|
|
2564
|
-
/**
|
|
2565
|
-
* Decodes an encoded transaction back to a Transaction.
|
|
2566
|
-
* @param encoded - The encoded representation.
|
|
2567
|
-
* @returns The decoded Transaction.
|
|
2568
|
-
*/
|
|
2569
|
-
const decode = (encoded) => ({
|
|
2570
|
-
id: encoded.id,
|
|
2571
|
-
ops: encoded.ops.map(decode$1),
|
|
2572
|
-
timestamp: encoded.timestamp
|
|
2573
|
-
});
|
|
2574
|
-
|
|
2575
|
-
//#endregion
|
|
2576
|
-
//#region src/Document.ts
|
|
2577
|
-
var Document_exports = /* @__PURE__ */ __export({
|
|
2578
|
-
NestedTransactionError: () => NestedTransactionError,
|
|
2579
|
-
OperationError: () => OperationError,
|
|
2580
|
-
make: () => make$1
|
|
2581
|
-
});
|
|
2582
|
-
/**
|
|
2583
|
-
* Error thrown when attempting to start a nested transaction.
|
|
2584
|
-
*/
|
|
2585
|
-
var NestedTransactionError = class extends Error {
|
|
2586
|
-
constructor() {
|
|
2587
|
-
super("Nested transactions are not supported");
|
|
2588
|
-
_defineProperty(this, "_tag", "NestedTransactionError");
|
|
2589
|
-
this.name = "NestedTransactionError";
|
|
2590
|
-
}
|
|
2591
|
-
};
|
|
2592
|
-
/**
|
|
2593
|
-
* Error thrown when an operation fails to apply.
|
|
2594
|
-
*/
|
|
2595
|
-
var OperationError = class extends Error {
|
|
2596
|
-
constructor(message) {
|
|
2597
|
-
super(message);
|
|
2598
|
-
_defineProperty(this, "_tag", "OperationError");
|
|
2599
|
-
this.name = "OperationError";
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
/**
|
|
2603
|
-
* Creates a new Document for the given schema.
|
|
2604
|
-
*/
|
|
2605
|
-
const make$1 = (schema, options) => {
|
|
2606
|
-
var _options$initial;
|
|
2607
|
-
let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
|
|
2608
|
-
let _pending = [];
|
|
2609
|
-
let _inTransaction = false;
|
|
2610
|
-
let _txOps = [];
|
|
2611
|
-
let _txBaseState = void 0;
|
|
2612
|
-
/**
|
|
2613
|
-
* Gets state at the given path.
|
|
2614
|
-
*/
|
|
2615
|
-
const getStateAtPath = (path) => {
|
|
2616
|
-
const tokens = path.toTokens().filter((t) => t !== "");
|
|
2617
|
-
if (tokens.length === 0) return _state;
|
|
2618
|
-
let current = _state;
|
|
2619
|
-
for (const token of tokens) {
|
|
2620
|
-
if (current === null || current === void 0) return;
|
|
2621
|
-
if (typeof current === "object") {
|
|
2622
|
-
if (Array.isArray(current)) {
|
|
2623
|
-
const entry = current.find((e) => e.id === token);
|
|
2624
|
-
if (entry) {
|
|
2625
|
-
current = entry.value;
|
|
2626
|
-
continue;
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
current = current[token];
|
|
2630
|
-
} else return;
|
|
2631
|
-
}
|
|
2632
|
-
return current;
|
|
2633
|
-
};
|
|
2634
|
-
/**
|
|
2635
|
-
* Applies a single operation to the current state.
|
|
2636
|
-
*/
|
|
2637
|
-
const applyOperation = (op) => {
|
|
2638
|
-
try {
|
|
2639
|
-
_state = schema._internal.applyOperation(_state, op);
|
|
2640
|
-
} catch (error) {
|
|
2641
|
-
if (error instanceof Error) throw new OperationError(error.message);
|
|
2642
|
-
throw new OperationError(String(error));
|
|
2643
|
-
}
|
|
2644
|
-
};
|
|
2645
|
-
/**
|
|
2646
|
-
* Handles an operation from a proxy.
|
|
2647
|
-
* In transaction mode: collects operations, applies to state immediately for subsequent reads.
|
|
2648
|
-
* Outside transaction mode: auto-wraps in a single-operation transaction.
|
|
2649
|
-
*/
|
|
2650
|
-
const handleOperation = (op) => {
|
|
2651
|
-
if (_inTransaction) {
|
|
2652
|
-
_txOps.push(op);
|
|
2653
|
-
applyOperation(op);
|
|
2654
|
-
} else {
|
|
2655
|
-
const baseState = _state;
|
|
2656
|
-
try {
|
|
2657
|
-
applyOperation(op);
|
|
2658
|
-
_pending.push(op);
|
|
2659
|
-
} catch (error) {
|
|
2660
|
-
_state = baseState;
|
|
2661
|
-
throw error;
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
|
-
};
|
|
2665
|
-
/**
|
|
2666
|
-
* Creates a ProxyEnvironment for the document.
|
|
2667
|
-
*/
|
|
2668
|
-
const createEnv = () => {
|
|
2669
|
-
return make$3({
|
|
2670
|
-
onOperation: handleOperation,
|
|
2671
|
-
getState: getStateAtPath
|
|
2672
|
-
});
|
|
2673
|
-
};
|
|
2674
|
-
const env = createEnv();
|
|
2675
|
-
const rootProxy = schema._internal.createProxy(env, make$4(""));
|
|
2676
|
-
return {
|
|
2677
|
-
schema,
|
|
2678
|
-
root: rootProxy,
|
|
2679
|
-
get: () => {
|
|
2680
|
-
return _state;
|
|
2681
|
-
},
|
|
2682
|
-
toSnapshot: () => {
|
|
2683
|
-
return rootProxy.toSnapshot();
|
|
2684
|
-
},
|
|
2685
|
-
transaction: (fn) => {
|
|
2686
|
-
if (_inTransaction) throw new NestedTransactionError();
|
|
2687
|
-
_inTransaction = true;
|
|
2688
|
-
_txOps = [];
|
|
2689
|
-
_txBaseState = _state;
|
|
2690
|
-
try {
|
|
2691
|
-
const result = fn(rootProxy);
|
|
2692
|
-
_pending.push(..._txOps);
|
|
2693
|
-
return result;
|
|
2694
|
-
} catch (error) {
|
|
2695
|
-
_state = _txBaseState;
|
|
2696
|
-
throw error;
|
|
2697
|
-
} finally {
|
|
2698
|
-
_inTransaction = false;
|
|
2699
|
-
_txOps = [];
|
|
2700
|
-
_txBaseState = void 0;
|
|
2701
|
-
}
|
|
2702
|
-
},
|
|
2703
|
-
apply: (ops) => {
|
|
2704
|
-
for (const op of ops) applyOperation(op);
|
|
2705
|
-
},
|
|
2706
|
-
flush: () => {
|
|
2707
|
-
const tx = make$2(_pending);
|
|
2708
|
-
_pending = [];
|
|
2709
|
-
return tx;
|
|
2710
|
-
}
|
|
2711
|
-
};
|
|
2712
|
-
};
|
|
2713
|
-
|
|
2714
2346
|
//#endregion
|
|
2715
2347
|
//#region src/Transform.ts
|
|
2716
2348
|
var Transform_exports = {};
|
|
2717
2349
|
|
|
2718
|
-
//#endregion
|
|
2719
|
-
//#region src/Presence.ts
|
|
2720
|
-
/**
|
|
2721
|
-
* @since 0.0.1
|
|
2722
|
-
* Presence module for ephemeral per-connection state.
|
|
2723
|
-
* Used by both client and server for schema validation.
|
|
2724
|
-
*/
|
|
2725
|
-
var Presence_exports = /* @__PURE__ */ __export({
|
|
2726
|
-
isValid: () => isValid,
|
|
2727
|
-
make: () => make,
|
|
2728
|
-
validate: () => validate,
|
|
2729
|
-
validateSafe: () => validateSafe
|
|
2730
|
-
});
|
|
2731
|
-
/**
|
|
2732
|
-
* Creates a new Presence schema wrapper.
|
|
2733
|
-
*
|
|
2734
|
-
* @example
|
|
2735
|
-
* ```typescript
|
|
2736
|
-
* import { Presence } from "@voidhash/mimic";
|
|
2737
|
-
* import { Schema } from "effect";
|
|
2738
|
-
*
|
|
2739
|
-
* const CursorPresence = Presence.make({
|
|
2740
|
-
* schema: Schema.Struct({
|
|
2741
|
-
* name: Schema.String,
|
|
2742
|
-
* cursor: Schema.Struct({
|
|
2743
|
-
* x: Schema.Number,
|
|
2744
|
-
* y: Schema.Number,
|
|
2745
|
-
* }),
|
|
2746
|
-
* }),
|
|
2747
|
-
* });
|
|
2748
|
-
* ```
|
|
2749
|
-
*/
|
|
2750
|
-
const make = (options) => ({
|
|
2751
|
-
_tag: "Presence",
|
|
2752
|
-
schema: options.schema,
|
|
2753
|
-
_Data: void 0
|
|
2754
|
-
});
|
|
2755
|
-
/**
|
|
2756
|
-
* Validates unknown data against a Presence schema.
|
|
2757
|
-
* Throws a ParseError if validation fails.
|
|
2758
|
-
*
|
|
2759
|
-
* @param presence - The Presence instance with the schema
|
|
2760
|
-
* @param data - Unknown data to validate
|
|
2761
|
-
* @returns The validated and typed data
|
|
2762
|
-
* @throws ParseError if validation fails
|
|
2763
|
-
*/
|
|
2764
|
-
const validate = (presence, data) => {
|
|
2765
|
-
return effect_Schema.decodeUnknownSync(presence.schema)(data);
|
|
2766
|
-
};
|
|
2767
|
-
/**
|
|
2768
|
-
* Safely validates unknown data against a Presence schema.
|
|
2769
|
-
* Returns undefined if validation fails instead of throwing.
|
|
2770
|
-
*
|
|
2771
|
-
* @param presence - The Presence instance with the schema
|
|
2772
|
-
* @param data - Unknown data to validate
|
|
2773
|
-
* @returns The validated data or undefined if invalid
|
|
2774
|
-
*/
|
|
2775
|
-
const validateSafe = (presence, data) => {
|
|
2776
|
-
try {
|
|
2777
|
-
return effect_Schema.decodeUnknownSync(presence.schema)(data);
|
|
2778
|
-
} catch (_unused) {
|
|
2779
|
-
return;
|
|
2780
|
-
}
|
|
2781
|
-
};
|
|
2782
|
-
/**
|
|
2783
|
-
* Checks if unknown data is valid according to a Presence schema.
|
|
2784
|
-
*
|
|
2785
|
-
* @param presence - The Presence instance with the schema
|
|
2786
|
-
* @param data - Unknown data to check
|
|
2787
|
-
* @returns true if valid, false otherwise
|
|
2788
|
-
*/
|
|
2789
|
-
const isValid = (presence, data) => {
|
|
2790
|
-
try {
|
|
2791
|
-
effect_Schema.decodeUnknownSync(presence.schema)(data);
|
|
2792
|
-
return true;
|
|
2793
|
-
} catch (_unused2) {
|
|
2794
|
-
return false;
|
|
2795
|
-
}
|
|
2796
|
-
};
|
|
2797
|
-
|
|
2798
2350
|
//#endregion
|
|
2799
2351
|
Object.defineProperty(exports, 'Document', {
|
|
2800
2352
|
enumerable: true,
|
|
2801
2353
|
get: function () {
|
|
2802
|
-
return Document_exports;
|
|
2354
|
+
return require_Document.Document_exports;
|
|
2803
2355
|
}
|
|
2804
2356
|
});
|
|
2805
2357
|
Object.defineProperty(exports, 'Operation', {
|
|
2806
2358
|
enumerable: true,
|
|
2807
2359
|
get: function () {
|
|
2808
|
-
return Operation_exports;
|
|
2360
|
+
return require_Document.Operation_exports;
|
|
2809
2361
|
}
|
|
2810
2362
|
});
|
|
2811
2363
|
Object.defineProperty(exports, 'OperationPath', {
|
|
2812
2364
|
enumerable: true,
|
|
2813
2365
|
get: function () {
|
|
2814
|
-
return OperationPath_exports;
|
|
2366
|
+
return require_Document.OperationPath_exports;
|
|
2815
2367
|
}
|
|
2816
2368
|
});
|
|
2817
2369
|
Object.defineProperty(exports, 'Presence', {
|
|
2818
2370
|
enumerable: true,
|
|
2819
2371
|
get: function () {
|
|
2820
|
-
return Presence_exports;
|
|
2372
|
+
return require_Presence.Presence_exports;
|
|
2821
2373
|
}
|
|
2822
2374
|
});
|
|
2823
2375
|
Object.defineProperty(exports, 'Primitive', {
|
|
@@ -2829,13 +2381,13 @@ Object.defineProperty(exports, 'Primitive', {
|
|
|
2829
2381
|
Object.defineProperty(exports, 'ProxyEnvironment', {
|
|
2830
2382
|
enumerable: true,
|
|
2831
2383
|
get: function () {
|
|
2832
|
-
return ProxyEnvironment_exports;
|
|
2384
|
+
return require_Document.ProxyEnvironment_exports;
|
|
2833
2385
|
}
|
|
2834
2386
|
});
|
|
2835
2387
|
Object.defineProperty(exports, 'Transaction', {
|
|
2836
2388
|
enumerable: true,
|
|
2837
2389
|
get: function () {
|
|
2838
|
-
return Transaction_exports;
|
|
2390
|
+
return require_Document.Transaction_exports;
|
|
2839
2391
|
}
|
|
2840
2392
|
});
|
|
2841
2393
|
Object.defineProperty(exports, 'Transform', {
|