@voidhash/mimic 0.0.1-alpha.7 → 0.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +43 -15
- package/dist/Document-ChuFrTk1.cjs +571 -0
- package/dist/Document-CwiAFTIq.mjs +438 -0
- package/dist/Document-CwiAFTIq.mjs.map +1 -0
- package/dist/Presence-DKKP4v5X.d.cts +91 -0
- package/dist/Presence-DKKP4v5X.d.cts.map +1 -0
- package/dist/Presence-DdMVKcOv.mjs +110 -0
- package/dist/Presence-DdMVKcOv.mjs.map +1 -0
- package/dist/Presence-N8u7Eppr.d.mts +91 -0
- package/dist/Presence-N8u7Eppr.d.mts.map +1 -0
- package/dist/Presence-gWrmGBeu.cjs +126 -0
- package/dist/Primitive-CasheIbX.d.mts +1175 -0
- package/dist/Primitive-CasheIbX.d.mts.map +1 -0
- package/dist/Primitive-Cyvy7zvF.d.cts +1175 -0
- package/dist/Primitive-Cyvy7zvF.d.cts.map +1 -0
- package/dist/client/index.cjs +1456 -0
- package/dist/client/index.d.cts +692 -0
- package/dist/client/index.d.cts.map +1 -0
- package/dist/client/index.d.mts +692 -0
- package/dist/client/index.d.mts.map +1 -0
- package/dist/client/index.mjs +1413 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.cjs +226 -765
- package/dist/index.d.cts +5 -1152
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -1152
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +71 -569
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.cjs +191 -0
- package/dist/server/index.d.cts +148 -0
- package/dist/server/index.d.cts.map +1 -0
- package/dist/server/index.d.mts +148 -0
- package/dist/server/index.d.mts.map +1 -0
- package/dist/server/index.mjs +182 -0
- package/dist/server/index.mjs.map +1 -0
- package/package.json +17 -5
- package/src/primitives/Array.ts +25 -14
- package/src/primitives/Boolean.ts +29 -17
- package/src/primitives/Either.ts +30 -17
- package/src/primitives/Lazy.ts +16 -2
- package/src/primitives/Literal.ts +29 -18
- package/src/primitives/Number.ts +35 -24
- package/src/primitives/String.ts +36 -23
- package/src/primitives/Struct.ts +74 -26
- package/src/primitives/Tree.ts +30 -14
- package/src/primitives/TreeNode.ts +6 -0
- package/src/primitives/Union.ts +21 -21
- package/src/primitives/shared.ts +35 -34
- package/tests/primitives/Array.test.ts +108 -0
- package/tests/primitives/Struct.test.ts +2 -2
- package/tests/primitives/Tree.test.ts +128 -0
- package/tsdown.config.ts +1 -1
- /package/dist/{chunk-C6wwvPpM.mjs → chunk-CLMFDpHK.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,73 +1,8 @@
|
|
|
1
|
-
import { t as __export } from "./chunk-
|
|
1
|
+
import { t as __export } from "./chunk-CLMFDpHK.mjs";
|
|
2
|
+
import { c as Operation_exports, d as isPrefix, f as pathsEqual, l as fromDefinition, m as _defineProperty, p as pathsOverlap, r as Transaction_exports, s as ProxyEnvironment_exports, t as Document_exports, u as OperationPath_exports } from "./Document-CwiAFTIq.mjs";
|
|
3
|
+
import { r as _objectSpread2, t as Presence_exports } from "./Presence-DdMVKcOv.mjs";
|
|
2
4
|
import { Effect, Schema } from "effect";
|
|
3
|
-
import * as Schema$1 from "effect/Schema";
|
|
4
5
|
|
|
5
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
6
|
-
function _typeof(o) {
|
|
7
|
-
"@babel/helpers - typeof";
|
|
8
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
9
|
-
return typeof o$1;
|
|
10
|
-
} : function(o$1) {
|
|
11
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
12
|
-
}, _typeof(o);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
17
|
-
function toPrimitive(t, r) {
|
|
18
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
-
var e = t[Symbol.toPrimitive];
|
|
20
|
-
if (void 0 !== e) {
|
|
21
|
-
var i = e.call(t, r || "default");
|
|
22
|
-
if ("object" != _typeof(i)) return i;
|
|
23
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
|
-
}
|
|
25
|
-
return ("string" === r ? String : Number)(t);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
30
|
-
function toPropertyKey(t) {
|
|
31
|
-
var i = toPrimitive(t, "string");
|
|
32
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
37
|
-
function _defineProperty(e, r, t) {
|
|
38
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
39
|
-
value: t,
|
|
40
|
-
enumerable: !0,
|
|
41
|
-
configurable: !0,
|
|
42
|
-
writable: !0
|
|
43
|
-
}) : e[r] = t, e;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
48
|
-
function ownKeys(e, r) {
|
|
49
|
-
var t = Object.keys(e);
|
|
50
|
-
if (Object.getOwnPropertySymbols) {
|
|
51
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
52
|
-
r && (o = o.filter(function(r$1) {
|
|
53
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
54
|
-
})), t.push.apply(t, o);
|
|
55
|
-
}
|
|
56
|
-
return t;
|
|
57
|
-
}
|
|
58
|
-
function _objectSpread2(e) {
|
|
59
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
60
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
61
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
62
|
-
_defineProperty(e, r$1, t[r$1]);
|
|
63
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
64
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return e;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
6
|
//#region src/primitives/shared.ts
|
|
72
7
|
var ValidationError = class extends Error {
|
|
73
8
|
constructor(message) {
|
|
@@ -122,7 +57,7 @@ function applyDefaults(primitive, value) {
|
|
|
122
57
|
|
|
123
58
|
//#endregion
|
|
124
59
|
//#region src/OperationDefinition.ts
|
|
125
|
-
const make
|
|
60
|
+
const make = (options) => {
|
|
126
61
|
return {
|
|
127
62
|
kind: options.kind,
|
|
128
63
|
payload: options.payload,
|
|
@@ -131,181 +66,6 @@ const make$5 = (options) => {
|
|
|
131
66
|
};
|
|
132
67
|
};
|
|
133
68
|
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/OperationPath.ts
|
|
136
|
-
var OperationPath_exports = /* @__PURE__ */ __export({
|
|
137
|
-
decode: () => decode$2,
|
|
138
|
-
encode: () => encode$2,
|
|
139
|
-
fromTokens: () => fromTokens,
|
|
140
|
-
getRelativePath: () => getRelativePath,
|
|
141
|
-
isPrefix: () => isPrefix,
|
|
142
|
-
make: () => make$4,
|
|
143
|
-
pathsEqual: () => pathsEqual,
|
|
144
|
-
pathsOverlap: () => pathsOverlap
|
|
145
|
-
});
|
|
146
|
-
const parseStringPath = (stringPath) => {
|
|
147
|
-
return stringPath.split("/");
|
|
148
|
-
};
|
|
149
|
-
const makeStringPathFromTokens = (tokens) => {
|
|
150
|
-
return tokens.join("/");
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Creates a new operation path.
|
|
154
|
-
* @param stringPath - The string path to create the path from.
|
|
155
|
-
* @returns The new operation path.
|
|
156
|
-
*/
|
|
157
|
-
function make$4(stringPath) {
|
|
158
|
-
const tokensInternal = stringPath ? parseStringPath(stringPath) : [];
|
|
159
|
-
/**
|
|
160
|
-
* Returns the tokens of the path.
|
|
161
|
-
* @returns The tokens of the path.
|
|
162
|
-
*/
|
|
163
|
-
const toTokens = () => {
|
|
164
|
-
return tokensInternal;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Concatenates two paths.
|
|
168
|
-
* @param other - The other path to concatenate.
|
|
169
|
-
* @returns The new path.
|
|
170
|
-
*/
|
|
171
|
-
const concat = (other) => {
|
|
172
|
-
return make$4(makeStringPathFromTokens(toTokens().concat(other.toTokens())));
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Appends a token to the path.
|
|
176
|
-
* @param token - The token to append.
|
|
177
|
-
* @returns The new path.
|
|
178
|
-
*/
|
|
179
|
-
const append = (token) => {
|
|
180
|
-
return make$4(makeStringPathFromTokens(toTokens().concat([token])));
|
|
181
|
-
};
|
|
182
|
-
/**
|
|
183
|
-
* Removes the last token from the path.
|
|
184
|
-
* @returns The new path.
|
|
185
|
-
*/
|
|
186
|
-
const pop = () => {
|
|
187
|
-
return make$4(makeStringPathFromTokens(toTokens().slice(0, -1)));
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* Removes the first token from the path.
|
|
191
|
-
* @returns The new path.
|
|
192
|
-
*/
|
|
193
|
-
const shift = () => {
|
|
194
|
-
return make$4(makeStringPathFromTokens(toTokens().slice(1)));
|
|
195
|
-
};
|
|
196
|
-
return {
|
|
197
|
-
_tag: "OperationPath",
|
|
198
|
-
toTokens,
|
|
199
|
-
concat,
|
|
200
|
-
append,
|
|
201
|
-
pop,
|
|
202
|
-
shift
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Creates a new operation path from tokens.
|
|
207
|
-
* @param tokens - The tokens to create the path from.
|
|
208
|
-
* @returns The new operation path.
|
|
209
|
-
*/
|
|
210
|
-
function fromTokens(tokens) {
|
|
211
|
-
return make$4(makeStringPathFromTokens(tokens));
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Checks if two operation paths overlap (one is prefix of the other or equal).
|
|
215
|
-
*/
|
|
216
|
-
const pathsOverlap = (pathA, pathB) => {
|
|
217
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
218
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
219
|
-
const minLength = Math.min(tokensA.length, tokensB.length);
|
|
220
|
-
for (let i = 0; i < minLength; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
221
|
-
return true;
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
224
|
-
* Checks if pathA is a prefix of pathB (pathA is ancestor of pathB).
|
|
225
|
-
*/
|
|
226
|
-
const isPrefix = (pathA, pathB) => {
|
|
227
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
228
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
229
|
-
if (tokensA.length > tokensB.length) return false;
|
|
230
|
-
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
231
|
-
return true;
|
|
232
|
-
};
|
|
233
|
-
/**
|
|
234
|
-
* Checks if two paths are exactly equal.
|
|
235
|
-
*/
|
|
236
|
-
const pathsEqual = (pathA, pathB) => {
|
|
237
|
-
const tokensA = pathA.toTokens().filter((t) => t !== "");
|
|
238
|
-
const tokensB = pathB.toTokens().filter((t) => t !== "");
|
|
239
|
-
if (tokensA.length !== tokensB.length) return false;
|
|
240
|
-
for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
|
|
241
|
-
return true;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Gets the relative path of pathB with respect to pathA.
|
|
245
|
-
* Assumes pathA is a prefix of pathB.
|
|
246
|
-
*/
|
|
247
|
-
const getRelativePath = (basePath, fullPath) => {
|
|
248
|
-
const baseTokens = basePath.toTokens().filter((t) => t !== "");
|
|
249
|
-
return fullPath.toTokens().filter((t) => t !== "").slice(baseTokens.length);
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Encodes an OperationPath to a string for network transport.
|
|
253
|
-
* @param path - The operation path to encode.
|
|
254
|
-
* @returns The encoded string representation.
|
|
255
|
-
*/
|
|
256
|
-
const encode$2 = (path) => {
|
|
257
|
-
return makeStringPathFromTokens(path.toTokens());
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Decodes an encoded string back to an OperationPath.
|
|
261
|
-
* @param encoded - The encoded string representation.
|
|
262
|
-
* @returns The decoded OperationPath.
|
|
263
|
-
*/
|
|
264
|
-
const decode$2 = (encoded) => {
|
|
265
|
-
return make$4(encoded);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
//#endregion
|
|
269
|
-
//#region src/Operation.ts
|
|
270
|
-
var Operation_exports = /* @__PURE__ */ __export({
|
|
271
|
-
decode: () => decode$1,
|
|
272
|
-
encode: () => encode$1,
|
|
273
|
-
fromDefinition: () => fromDefinition
|
|
274
|
-
});
|
|
275
|
-
const fromDefinition = (operationPath, definition, payload) => {
|
|
276
|
-
return {
|
|
277
|
-
kind: definition.kind,
|
|
278
|
-
path: operationPath,
|
|
279
|
-
payload
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* Encodes an Operation to a JSON-serializable format for network transport.
|
|
284
|
-
* @param operation - The operation to encode.
|
|
285
|
-
* @returns The encoded representation.
|
|
286
|
-
*/
|
|
287
|
-
const encode$1 = (operation) => {
|
|
288
|
-
return {
|
|
289
|
-
kind: operation.kind,
|
|
290
|
-
path: encode$2(operation.path),
|
|
291
|
-
payload: operation.payload
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
/**
|
|
295
|
-
* Decodes an encoded operation back to an Operation.
|
|
296
|
-
* Note: This returns a partial operation without the definition methods.
|
|
297
|
-
* The caller must have the operation definitions to fully reconstruct if needed.
|
|
298
|
-
* @param encoded - The encoded representation.
|
|
299
|
-
* @returns The decoded Operation (without definition-specific methods).
|
|
300
|
-
*/
|
|
301
|
-
const decode$1 = (encoded) => {
|
|
302
|
-
return {
|
|
303
|
-
kind: encoded.kind,
|
|
304
|
-
path: decode$2(encoded.path),
|
|
305
|
-
payload: encoded.payload
|
|
306
|
-
};
|
|
307
|
-
};
|
|
308
|
-
|
|
309
69
|
//#endregion
|
|
310
70
|
//#region src/primitives/String.ts
|
|
311
71
|
var StringPrimitive = class StringPrimitive {
|
|
@@ -313,10 +73,12 @@ var StringPrimitive = class StringPrimitive {
|
|
|
313
73
|
_defineProperty(this, "_tag", "StringPrimitive");
|
|
314
74
|
_defineProperty(this, "_State", void 0);
|
|
315
75
|
_defineProperty(this, "_Proxy", void 0);
|
|
316
|
-
_defineProperty(this, "
|
|
76
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
317
77
|
_defineProperty(this, "_THasDefault", void 0);
|
|
78
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
79
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
318
80
|
_defineProperty(this, "_schema", void 0);
|
|
319
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
81
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
320
82
|
kind: "string.set",
|
|
321
83
|
payload: Schema.String,
|
|
322
84
|
target: Schema.String,
|
|
@@ -333,6 +95,9 @@ var StringPrimitive = class StringPrimitive {
|
|
|
333
95
|
set: (value) => {
|
|
334
96
|
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
335
97
|
},
|
|
98
|
+
update: (value) => {
|
|
99
|
+
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
100
|
+
},
|
|
336
101
|
toSnapshot: () => {
|
|
337
102
|
const state = env.getState(operationPath);
|
|
338
103
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
@@ -411,7 +176,7 @@ var StringPrimitive = class StringPrimitive {
|
|
|
411
176
|
}
|
|
412
177
|
};
|
|
413
178
|
/** Creates a new StringPrimitive */
|
|
414
|
-
const String
|
|
179
|
+
const String = () => new StringPrimitive({
|
|
415
180
|
required: false,
|
|
416
181
|
defaultValue: void 0,
|
|
417
182
|
validators: []
|
|
@@ -424,10 +189,12 @@ var StructPrimitive = class StructPrimitive {
|
|
|
424
189
|
_defineProperty(this, "_tag", "StructPrimitive");
|
|
425
190
|
_defineProperty(this, "_State", void 0);
|
|
426
191
|
_defineProperty(this, "_Proxy", void 0);
|
|
427
|
-
_defineProperty(this, "
|
|
192
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
428
193
|
_defineProperty(this, "_THasDefault", void 0);
|
|
194
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
195
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
429
196
|
_defineProperty(this, "_schema", void 0);
|
|
430
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
197
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
431
198
|
kind: "struct.set",
|
|
432
199
|
payload: Schema.Unknown,
|
|
433
200
|
target: Schema.Unknown,
|
|
@@ -617,10 +384,12 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
617
384
|
_defineProperty(this, "_tag", "BooleanPrimitive");
|
|
618
385
|
_defineProperty(this, "_State", void 0);
|
|
619
386
|
_defineProperty(this, "_Proxy", void 0);
|
|
620
|
-
_defineProperty(this, "
|
|
387
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
621
388
|
_defineProperty(this, "_THasDefault", void 0);
|
|
389
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
390
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
622
391
|
_defineProperty(this, "_schema", void 0);
|
|
623
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
392
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
624
393
|
kind: "boolean.set",
|
|
625
394
|
payload: Schema.Boolean,
|
|
626
395
|
target: Schema.Boolean,
|
|
@@ -637,6 +406,9 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
637
406
|
set: (value) => {
|
|
638
407
|
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
639
408
|
},
|
|
409
|
+
update: (value) => {
|
|
410
|
+
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
411
|
+
},
|
|
640
412
|
toSnapshot: () => {
|
|
641
413
|
const state = env.getState(operationPath);
|
|
642
414
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
@@ -696,10 +468,12 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
696
468
|
_defineProperty(this, "_tag", "NumberPrimitive");
|
|
697
469
|
_defineProperty(this, "_State", void 0);
|
|
698
470
|
_defineProperty(this, "_Proxy", void 0);
|
|
699
|
-
_defineProperty(this, "
|
|
471
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
700
472
|
_defineProperty(this, "_THasDefault", void 0);
|
|
473
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
474
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
701
475
|
_defineProperty(this, "_schema", void 0);
|
|
702
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
476
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
703
477
|
kind: "number.set",
|
|
704
478
|
payload: Schema.Number,
|
|
705
479
|
target: Schema.Number,
|
|
@@ -716,6 +490,9 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
716
490
|
set: (value) => {
|
|
717
491
|
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
718
492
|
},
|
|
493
|
+
update: (value) => {
|
|
494
|
+
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
495
|
+
},
|
|
719
496
|
toSnapshot: () => {
|
|
720
497
|
const state = env.getState(operationPath);
|
|
721
498
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
@@ -782,7 +559,7 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
782
559
|
}
|
|
783
560
|
};
|
|
784
561
|
/** Creates a new NumberPrimitive */
|
|
785
|
-
const Number
|
|
562
|
+
const Number = () => new NumberPrimitive({
|
|
786
563
|
required: false,
|
|
787
564
|
defaultValue: void 0,
|
|
788
565
|
validators: []
|
|
@@ -795,10 +572,12 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
795
572
|
_defineProperty(this, "_tag", "LiteralPrimitive");
|
|
796
573
|
_defineProperty(this, "_State", void 0);
|
|
797
574
|
_defineProperty(this, "_Proxy", void 0);
|
|
798
|
-
_defineProperty(this, "
|
|
575
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
799
576
|
_defineProperty(this, "_THasDefault", void 0);
|
|
577
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
578
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
800
579
|
_defineProperty(this, "_schema", void 0);
|
|
801
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
580
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
802
581
|
kind: "literal.set",
|
|
803
582
|
payload: Schema.Unknown,
|
|
804
583
|
target: Schema.Unknown,
|
|
@@ -815,6 +594,9 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
815
594
|
set: (value) => {
|
|
816
595
|
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
817
596
|
},
|
|
597
|
+
update: (value) => {
|
|
598
|
+
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
599
|
+
},
|
|
818
600
|
toSnapshot: () => {
|
|
819
601
|
const state = env.getState(operationPath);
|
|
820
602
|
return state !== null && state !== void 0 ? state : defaultValue;
|
|
@@ -1241,29 +1023,31 @@ var ArrayPrimitive = class ArrayPrimitive {
|
|
|
1241
1023
|
_defineProperty(this, "_tag", "ArrayPrimitive");
|
|
1242
1024
|
_defineProperty(this, "_State", void 0);
|
|
1243
1025
|
_defineProperty(this, "_Proxy", void 0);
|
|
1244
|
-
_defineProperty(this, "
|
|
1026
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
1245
1027
|
_defineProperty(this, "_THasDefault", void 0);
|
|
1028
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
1029
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
1246
1030
|
_defineProperty(this, "_schema", void 0);
|
|
1247
1031
|
_defineProperty(this, "_opDefinitions", {
|
|
1248
|
-
set: make
|
|
1032
|
+
set: make({
|
|
1249
1033
|
kind: "array.set",
|
|
1250
1034
|
payload: Schema.Unknown,
|
|
1251
1035
|
target: Schema.Unknown,
|
|
1252
1036
|
apply: (payload) => payload
|
|
1253
1037
|
}),
|
|
1254
|
-
insert: make
|
|
1038
|
+
insert: make({
|
|
1255
1039
|
kind: "array.insert",
|
|
1256
1040
|
payload: Schema.Unknown,
|
|
1257
1041
|
target: Schema.Unknown,
|
|
1258
1042
|
apply: (payload) => payload
|
|
1259
1043
|
}),
|
|
1260
|
-
remove: make
|
|
1044
|
+
remove: make({
|
|
1261
1045
|
kind: "array.remove",
|
|
1262
1046
|
payload: Schema.Unknown,
|
|
1263
1047
|
target: Schema.Unknown,
|
|
1264
1048
|
apply: (payload) => payload
|
|
1265
1049
|
}),
|
|
1266
|
-
move: make
|
|
1050
|
+
move: make({
|
|
1267
1051
|
kind: "array.move",
|
|
1268
1052
|
payload: Schema.Unknown,
|
|
1269
1053
|
target: Schema.Unknown,
|
|
@@ -1517,6 +1301,10 @@ var LazyPrimitive = class {
|
|
|
1517
1301
|
_defineProperty(this, "_tag", "LazyPrimitive");
|
|
1518
1302
|
_defineProperty(this, "_State", void 0);
|
|
1519
1303
|
_defineProperty(this, "_Proxy", void 0);
|
|
1304
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
1305
|
+
_defineProperty(this, "_THasDefault", void 0);
|
|
1306
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
1307
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
1520
1308
|
_defineProperty(this, "_thunk", void 0);
|
|
1521
1309
|
_defineProperty(this, "_resolved", void 0);
|
|
1522
1310
|
_defineProperty(this, "_internal", {
|
|
@@ -1555,10 +1343,12 @@ var UnionPrimitive = class UnionPrimitive {
|
|
|
1555
1343
|
_defineProperty(this, "_tag", "UnionPrimitive");
|
|
1556
1344
|
_defineProperty(this, "_State", void 0);
|
|
1557
1345
|
_defineProperty(this, "_Proxy", void 0);
|
|
1558
|
-
_defineProperty(this, "
|
|
1346
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
1559
1347
|
_defineProperty(this, "_THasDefault", void 0);
|
|
1348
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
1349
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
1560
1350
|
_defineProperty(this, "_schema", void 0);
|
|
1561
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
1351
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
1562
1352
|
kind: "union.set",
|
|
1563
1353
|
payload: Schema.Unknown,
|
|
1564
1354
|
target: Schema.Unknown,
|
|
@@ -1711,10 +1501,12 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1711
1501
|
_defineProperty(this, "_tag", "EitherPrimitive");
|
|
1712
1502
|
_defineProperty(this, "_State", void 0);
|
|
1713
1503
|
_defineProperty(this, "_Proxy", void 0);
|
|
1714
|
-
_defineProperty(this, "
|
|
1504
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
1715
1505
|
_defineProperty(this, "_THasDefault", void 0);
|
|
1506
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
1507
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
1716
1508
|
_defineProperty(this, "_schema", void 0);
|
|
1717
|
-
_defineProperty(this, "_opDefinitions", { set: make
|
|
1509
|
+
_defineProperty(this, "_opDefinitions", { set: make({
|
|
1718
1510
|
kind: "either.set",
|
|
1719
1511
|
payload: Schema.Unknown,
|
|
1720
1512
|
target: Schema.Unknown,
|
|
@@ -1731,6 +1523,9 @@ var EitherPrimitive = class EitherPrimitive {
|
|
|
1731
1523
|
set: (value) => {
|
|
1732
1524
|
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
1733
1525
|
},
|
|
1526
|
+
update: (value) => {
|
|
1527
|
+
env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
|
|
1528
|
+
},
|
|
1734
1529
|
match: (handlers) => {
|
|
1735
1530
|
const currentState = env.getState(operationPath);
|
|
1736
1531
|
const effectiveState = currentState !== null && currentState !== void 0 ? currentState : defaultValue;
|
|
@@ -1925,6 +1720,8 @@ var TreeNodePrimitive = class {
|
|
|
1925
1720
|
_defineProperty(this, "_Type", void 0);
|
|
1926
1721
|
_defineProperty(this, "_Data", void 0);
|
|
1927
1722
|
_defineProperty(this, "_Children", void 0);
|
|
1723
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
1724
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
1928
1725
|
_defineProperty(this, "_type", void 0);
|
|
1929
1726
|
_defineProperty(this, "_data", void 0);
|
|
1930
1727
|
_defineProperty(this, "_children", void 0);
|
|
@@ -1994,30 +1791,32 @@ var TreePrimitive = class TreePrimitive {
|
|
|
1994
1791
|
_defineProperty(this, "_tag", "TreePrimitive");
|
|
1995
1792
|
_defineProperty(this, "_State", void 0);
|
|
1996
1793
|
_defineProperty(this, "_Proxy", void 0);
|
|
1997
|
-
_defineProperty(this, "
|
|
1794
|
+
_defineProperty(this, "_TRequired", void 0);
|
|
1998
1795
|
_defineProperty(this, "_THasDefault", void 0);
|
|
1796
|
+
_defineProperty(this, "TSetInput", void 0);
|
|
1797
|
+
_defineProperty(this, "TUpdateInput", void 0);
|
|
1999
1798
|
_defineProperty(this, "_schema", void 0);
|
|
2000
1799
|
_defineProperty(this, "_nodeTypeRegistry", void 0);
|
|
2001
1800
|
_defineProperty(this, "_opDefinitions", {
|
|
2002
|
-
set: make
|
|
1801
|
+
set: make({
|
|
2003
1802
|
kind: "tree.set",
|
|
2004
1803
|
payload: Schema.Unknown,
|
|
2005
1804
|
target: Schema.Unknown,
|
|
2006
1805
|
apply: (payload) => payload
|
|
2007
1806
|
}),
|
|
2008
|
-
insert: make
|
|
1807
|
+
insert: make({
|
|
2009
1808
|
kind: "tree.insert",
|
|
2010
1809
|
payload: Schema.Unknown,
|
|
2011
1810
|
target: Schema.Unknown,
|
|
2012
1811
|
apply: (payload) => payload
|
|
2013
1812
|
}),
|
|
2014
|
-
remove: make
|
|
1813
|
+
remove: make({
|
|
2015
1814
|
kind: "tree.remove",
|
|
2016
1815
|
payload: Schema.Unknown,
|
|
2017
1816
|
target: Schema.Unknown,
|
|
2018
1817
|
apply: (payload) => payload
|
|
2019
1818
|
}),
|
|
2020
|
-
move: make
|
|
1819
|
+
move: make({
|
|
2021
1820
|
kind: "tree.move",
|
|
2022
1821
|
payload: Schema.Unknown,
|
|
2023
1822
|
target: Schema.Unknown,
|
|
@@ -2528,9 +2327,9 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2528
2327
|
LazyPrimitive: () => LazyPrimitive,
|
|
2529
2328
|
Literal: () => Literal,
|
|
2530
2329
|
LiteralPrimitive: () => LiteralPrimitive,
|
|
2531
|
-
Number: () => Number
|
|
2330
|
+
Number: () => Number,
|
|
2532
2331
|
NumberPrimitive: () => NumberPrimitive,
|
|
2533
|
-
String: () => String
|
|
2332
|
+
String: () => String,
|
|
2534
2333
|
StringPrimitive: () => StringPrimitive,
|
|
2535
2334
|
Struct: () => Struct,
|
|
2536
2335
|
StructPrimitive: () => StructPrimitive,
|
|
@@ -2547,307 +2346,10 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2547
2346
|
runValidators: () => runValidators
|
|
2548
2347
|
});
|
|
2549
2348
|
|
|
2550
|
-
//#endregion
|
|
2551
|
-
//#region src/ProxyEnvironment.ts
|
|
2552
|
-
var ProxyEnvironment_exports = /* @__PURE__ */ __export({ make: () => make$3 });
|
|
2553
|
-
/** Default UUID generator using crypto.randomUUID */
|
|
2554
|
-
const defaultGenerateId = () => {
|
|
2555
|
-
return crypto.randomUUID();
|
|
2556
|
-
};
|
|
2557
|
-
/** Default state getter that always returns undefined */
|
|
2558
|
-
const defaultGetState = (_path) => {};
|
|
2559
|
-
/**
|
|
2560
|
-
* Creates a ProxyEnvironment.
|
|
2561
|
-
* @param optionsOrCallback - Either an options object or a simple callback for operations
|
|
2562
|
-
*/
|
|
2563
|
-
const make$3 = (optionsOrCallback) => {
|
|
2564
|
-
var _options$getState, _options$generateId;
|
|
2565
|
-
const options = typeof optionsOrCallback === "function" ? { onOperation: optionsOrCallback } : optionsOrCallback;
|
|
2566
|
-
return {
|
|
2567
|
-
addOperation: (operation) => {
|
|
2568
|
-
options.onOperation(operation);
|
|
2569
|
-
},
|
|
2570
|
-
getState: (_options$getState = options.getState) !== null && _options$getState !== void 0 ? _options$getState : defaultGetState,
|
|
2571
|
-
generateId: (_options$generateId = options.generateId) !== null && _options$generateId !== void 0 ? _options$generateId : defaultGenerateId
|
|
2572
|
-
};
|
|
2573
|
-
};
|
|
2574
|
-
|
|
2575
|
-
//#endregion
|
|
2576
|
-
//#region src/Transaction.ts
|
|
2577
|
-
var Transaction_exports = /* @__PURE__ */ __export({
|
|
2578
|
-
decode: () => decode,
|
|
2579
|
-
empty: () => empty,
|
|
2580
|
-
encode: () => encode,
|
|
2581
|
-
isEmpty: () => isEmpty,
|
|
2582
|
-
make: () => make$2,
|
|
2583
|
-
merge: () => merge
|
|
2584
|
-
});
|
|
2585
|
-
/**
|
|
2586
|
-
* Creates a new Transaction with the given operations.
|
|
2587
|
-
*/
|
|
2588
|
-
const make$2 = (ops) => ({
|
|
2589
|
-
id: crypto.randomUUID(),
|
|
2590
|
-
ops,
|
|
2591
|
-
timestamp: Date.now()
|
|
2592
|
-
});
|
|
2593
|
-
/**
|
|
2594
|
-
* Creates an empty Transaction.
|
|
2595
|
-
*/
|
|
2596
|
-
const empty = () => make$2([]);
|
|
2597
|
-
/**
|
|
2598
|
-
* Checks if a transaction is empty (has no operations).
|
|
2599
|
-
*/
|
|
2600
|
-
const isEmpty = (tx) => tx.ops.length === 0;
|
|
2601
|
-
/**
|
|
2602
|
-
* Merges multiple transactions into one.
|
|
2603
|
-
*/
|
|
2604
|
-
const merge = (txs) => {
|
|
2605
|
-
return make$2(txs.flatMap((tx) => tx.ops));
|
|
2606
|
-
};
|
|
2607
|
-
/**
|
|
2608
|
-
* Encodes a Transaction to a JSON-serializable format for network transport.
|
|
2609
|
-
* @param transaction - The transaction to encode.
|
|
2610
|
-
* @returns The encoded representation.
|
|
2611
|
-
*/
|
|
2612
|
-
const encode = (transaction) => ({
|
|
2613
|
-
id: transaction.id,
|
|
2614
|
-
ops: transaction.ops.map(encode$1),
|
|
2615
|
-
timestamp: transaction.timestamp
|
|
2616
|
-
});
|
|
2617
|
-
/**
|
|
2618
|
-
* Decodes an encoded transaction back to a Transaction.
|
|
2619
|
-
* @param encoded - The encoded representation.
|
|
2620
|
-
* @returns The decoded Transaction.
|
|
2621
|
-
*/
|
|
2622
|
-
const decode = (encoded) => ({
|
|
2623
|
-
id: encoded.id,
|
|
2624
|
-
ops: encoded.ops.map(decode$1),
|
|
2625
|
-
timestamp: encoded.timestamp
|
|
2626
|
-
});
|
|
2627
|
-
|
|
2628
|
-
//#endregion
|
|
2629
|
-
//#region src/Document.ts
|
|
2630
|
-
var Document_exports = /* @__PURE__ */ __export({
|
|
2631
|
-
NestedTransactionError: () => NestedTransactionError,
|
|
2632
|
-
OperationError: () => OperationError,
|
|
2633
|
-
make: () => make$1
|
|
2634
|
-
});
|
|
2635
|
-
/**
|
|
2636
|
-
* Error thrown when attempting to start a nested transaction.
|
|
2637
|
-
*/
|
|
2638
|
-
var NestedTransactionError = class extends Error {
|
|
2639
|
-
constructor() {
|
|
2640
|
-
super("Nested transactions are not supported");
|
|
2641
|
-
_defineProperty(this, "_tag", "NestedTransactionError");
|
|
2642
|
-
this.name = "NestedTransactionError";
|
|
2643
|
-
}
|
|
2644
|
-
};
|
|
2645
|
-
/**
|
|
2646
|
-
* Error thrown when an operation fails to apply.
|
|
2647
|
-
*/
|
|
2648
|
-
var OperationError = class extends Error {
|
|
2649
|
-
constructor(message) {
|
|
2650
|
-
super(message);
|
|
2651
|
-
_defineProperty(this, "_tag", "OperationError");
|
|
2652
|
-
this.name = "OperationError";
|
|
2653
|
-
}
|
|
2654
|
-
};
|
|
2655
|
-
/**
|
|
2656
|
-
* Creates a new Document for the given schema.
|
|
2657
|
-
*/
|
|
2658
|
-
const make$1 = (schema, options) => {
|
|
2659
|
-
var _options$initial;
|
|
2660
|
-
let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
|
|
2661
|
-
let _pending = [];
|
|
2662
|
-
let _inTransaction = false;
|
|
2663
|
-
let _txOps = [];
|
|
2664
|
-
let _txBaseState = void 0;
|
|
2665
|
-
/**
|
|
2666
|
-
* Gets state at the given path.
|
|
2667
|
-
*/
|
|
2668
|
-
const getStateAtPath = (path) => {
|
|
2669
|
-
const tokens = path.toTokens().filter((t) => t !== "");
|
|
2670
|
-
if (tokens.length === 0) return _state;
|
|
2671
|
-
let current = _state;
|
|
2672
|
-
for (const token of tokens) {
|
|
2673
|
-
if (current === null || current === void 0) return;
|
|
2674
|
-
if (typeof current === "object") {
|
|
2675
|
-
if (Array.isArray(current)) {
|
|
2676
|
-
const entry = current.find((e) => e.id === token);
|
|
2677
|
-
if (entry) {
|
|
2678
|
-
current = entry.value;
|
|
2679
|
-
continue;
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
current = current[token];
|
|
2683
|
-
} else return;
|
|
2684
|
-
}
|
|
2685
|
-
return current;
|
|
2686
|
-
};
|
|
2687
|
-
/**
|
|
2688
|
-
* Applies a single operation to the current state.
|
|
2689
|
-
*/
|
|
2690
|
-
const applyOperation = (op) => {
|
|
2691
|
-
try {
|
|
2692
|
-
_state = schema._internal.applyOperation(_state, op);
|
|
2693
|
-
} catch (error) {
|
|
2694
|
-
if (error instanceof Error) throw new OperationError(error.message);
|
|
2695
|
-
throw new OperationError(String(error));
|
|
2696
|
-
}
|
|
2697
|
-
};
|
|
2698
|
-
/**
|
|
2699
|
-
* Handles an operation from a proxy.
|
|
2700
|
-
* In transaction mode: collects operations, applies to state immediately for subsequent reads.
|
|
2701
|
-
* Outside transaction mode: auto-wraps in a single-operation transaction.
|
|
2702
|
-
*/
|
|
2703
|
-
const handleOperation = (op) => {
|
|
2704
|
-
if (_inTransaction) {
|
|
2705
|
-
_txOps.push(op);
|
|
2706
|
-
applyOperation(op);
|
|
2707
|
-
} else {
|
|
2708
|
-
const baseState = _state;
|
|
2709
|
-
try {
|
|
2710
|
-
applyOperation(op);
|
|
2711
|
-
_pending.push(op);
|
|
2712
|
-
} catch (error) {
|
|
2713
|
-
_state = baseState;
|
|
2714
|
-
throw error;
|
|
2715
|
-
}
|
|
2716
|
-
}
|
|
2717
|
-
};
|
|
2718
|
-
/**
|
|
2719
|
-
* Creates a ProxyEnvironment for the document.
|
|
2720
|
-
*/
|
|
2721
|
-
const createEnv = () => {
|
|
2722
|
-
return make$3({
|
|
2723
|
-
onOperation: handleOperation,
|
|
2724
|
-
getState: getStateAtPath
|
|
2725
|
-
});
|
|
2726
|
-
};
|
|
2727
|
-
const env = createEnv();
|
|
2728
|
-
const rootProxy = schema._internal.createProxy(env, make$4(""));
|
|
2729
|
-
return {
|
|
2730
|
-
schema,
|
|
2731
|
-
root: rootProxy,
|
|
2732
|
-
get: () => {
|
|
2733
|
-
return _state;
|
|
2734
|
-
},
|
|
2735
|
-
toSnapshot: () => {
|
|
2736
|
-
return rootProxy.toSnapshot();
|
|
2737
|
-
},
|
|
2738
|
-
transaction: (fn) => {
|
|
2739
|
-
if (_inTransaction) throw new NestedTransactionError();
|
|
2740
|
-
_inTransaction = true;
|
|
2741
|
-
_txOps = [];
|
|
2742
|
-
_txBaseState = _state;
|
|
2743
|
-
try {
|
|
2744
|
-
const result = fn(rootProxy);
|
|
2745
|
-
_pending.push(..._txOps);
|
|
2746
|
-
return result;
|
|
2747
|
-
} catch (error) {
|
|
2748
|
-
_state = _txBaseState;
|
|
2749
|
-
throw error;
|
|
2750
|
-
} finally {
|
|
2751
|
-
_inTransaction = false;
|
|
2752
|
-
_txOps = [];
|
|
2753
|
-
_txBaseState = void 0;
|
|
2754
|
-
}
|
|
2755
|
-
},
|
|
2756
|
-
apply: (ops) => {
|
|
2757
|
-
for (const op of ops) applyOperation(op);
|
|
2758
|
-
},
|
|
2759
|
-
flush: () => {
|
|
2760
|
-
const tx = make$2(_pending);
|
|
2761
|
-
_pending = [];
|
|
2762
|
-
return tx;
|
|
2763
|
-
}
|
|
2764
|
-
};
|
|
2765
|
-
};
|
|
2766
|
-
|
|
2767
2349
|
//#endregion
|
|
2768
2350
|
//#region src/Transform.ts
|
|
2769
2351
|
var Transform_exports = {};
|
|
2770
2352
|
|
|
2771
|
-
//#endregion
|
|
2772
|
-
//#region src/Presence.ts
|
|
2773
|
-
/**
|
|
2774
|
-
* @since 0.0.1
|
|
2775
|
-
* Presence module for ephemeral per-connection state.
|
|
2776
|
-
* Used by both client and server for schema validation.
|
|
2777
|
-
*/
|
|
2778
|
-
var Presence_exports = /* @__PURE__ */ __export({
|
|
2779
|
-
isValid: () => isValid,
|
|
2780
|
-
make: () => make,
|
|
2781
|
-
validate: () => validate,
|
|
2782
|
-
validateSafe: () => validateSafe
|
|
2783
|
-
});
|
|
2784
|
-
/**
|
|
2785
|
-
* Creates a new Presence schema wrapper.
|
|
2786
|
-
*
|
|
2787
|
-
* @example
|
|
2788
|
-
* ```typescript
|
|
2789
|
-
* import { Presence } from "@voidhash/mimic";
|
|
2790
|
-
* import { Schema } from "effect";
|
|
2791
|
-
*
|
|
2792
|
-
* const CursorPresence = Presence.make({
|
|
2793
|
-
* schema: Schema.Struct({
|
|
2794
|
-
* name: Schema.String,
|
|
2795
|
-
* cursor: Schema.Struct({
|
|
2796
|
-
* x: Schema.Number,
|
|
2797
|
-
* y: Schema.Number,
|
|
2798
|
-
* }),
|
|
2799
|
-
* }),
|
|
2800
|
-
* });
|
|
2801
|
-
* ```
|
|
2802
|
-
*/
|
|
2803
|
-
const make = (options) => ({
|
|
2804
|
-
_tag: "Presence",
|
|
2805
|
-
schema: options.schema,
|
|
2806
|
-
_Data: void 0
|
|
2807
|
-
});
|
|
2808
|
-
/**
|
|
2809
|
-
* Validates unknown data against a Presence schema.
|
|
2810
|
-
* Throws a ParseError if validation fails.
|
|
2811
|
-
*
|
|
2812
|
-
* @param presence - The Presence instance with the schema
|
|
2813
|
-
* @param data - Unknown data to validate
|
|
2814
|
-
* @returns The validated and typed data
|
|
2815
|
-
* @throws ParseError if validation fails
|
|
2816
|
-
*/
|
|
2817
|
-
const validate = (presence, data) => {
|
|
2818
|
-
return Schema$1.decodeUnknownSync(presence.schema)(data);
|
|
2819
|
-
};
|
|
2820
|
-
/**
|
|
2821
|
-
* Safely validates unknown data against a Presence schema.
|
|
2822
|
-
* Returns undefined if validation fails instead of throwing.
|
|
2823
|
-
*
|
|
2824
|
-
* @param presence - The Presence instance with the schema
|
|
2825
|
-
* @param data - Unknown data to validate
|
|
2826
|
-
* @returns The validated data or undefined if invalid
|
|
2827
|
-
*/
|
|
2828
|
-
const validateSafe = (presence, data) => {
|
|
2829
|
-
try {
|
|
2830
|
-
return Schema$1.decodeUnknownSync(presence.schema)(data);
|
|
2831
|
-
} catch (_unused) {
|
|
2832
|
-
return;
|
|
2833
|
-
}
|
|
2834
|
-
};
|
|
2835
|
-
/**
|
|
2836
|
-
* Checks if unknown data is valid according to a Presence schema.
|
|
2837
|
-
*
|
|
2838
|
-
* @param presence - The Presence instance with the schema
|
|
2839
|
-
* @param data - Unknown data to check
|
|
2840
|
-
* @returns true if valid, false otherwise
|
|
2841
|
-
*/
|
|
2842
|
-
const isValid = (presence, data) => {
|
|
2843
|
-
try {
|
|
2844
|
-
Schema$1.decodeUnknownSync(presence.schema)(data);
|
|
2845
|
-
return true;
|
|
2846
|
-
} catch (_unused2) {
|
|
2847
|
-
return false;
|
|
2848
|
-
}
|
|
2849
|
-
};
|
|
2850
|
-
|
|
2851
2353
|
//#endregion
|
|
2852
2354
|
export { Document_exports as Document, Operation_exports as Operation, OperationPath_exports as OperationPath, Presence_exports as Presence, Primitive_exports as Primitive, ProxyEnvironment_exports as ProxyEnvironment, Transaction_exports as Transaction, Transform_exports as Transform };
|
|
2853
2355
|
//# sourceMappingURL=index.mjs.map
|