@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.
Files changed (53) hide show
  1. package/.turbo/turbo-build.log +43 -15
  2. package/dist/Document-ChuFrTk1.cjs +571 -0
  3. package/dist/Document-CwiAFTIq.mjs +438 -0
  4. package/dist/Document-CwiAFTIq.mjs.map +1 -0
  5. package/dist/Presence-DKKP4v5X.d.cts +91 -0
  6. package/dist/Presence-DKKP4v5X.d.cts.map +1 -0
  7. package/dist/Presence-DdMVKcOv.mjs +110 -0
  8. package/dist/Presence-DdMVKcOv.mjs.map +1 -0
  9. package/dist/Presence-N8u7Eppr.d.mts +91 -0
  10. package/dist/Presence-N8u7Eppr.d.mts.map +1 -0
  11. package/dist/Presence-gWrmGBeu.cjs +126 -0
  12. package/dist/Primitive-BK7kfHJZ.d.cts +1165 -0
  13. package/dist/Primitive-BK7kfHJZ.d.cts.map +1 -0
  14. package/dist/Primitive-D1kdB6za.d.mts +1165 -0
  15. package/dist/Primitive-D1kdB6za.d.mts.map +1 -0
  16. package/dist/client/index.cjs +1456 -0
  17. package/dist/client/index.d.cts +692 -0
  18. package/dist/client/index.d.cts.map +1 -0
  19. package/dist/client/index.d.mts +692 -0
  20. package/dist/client/index.d.mts.map +1 -0
  21. package/dist/client/index.mjs +1413 -0
  22. package/dist/client/index.mjs.map +1 -0
  23. package/dist/index.cjs +309 -757
  24. package/dist/index.d.cts +5 -1054
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts +5 -1054
  27. package/dist/index.d.mts.map +1 -1
  28. package/dist/index.mjs +168 -575
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/server/index.cjs +191 -0
  31. package/dist/server/index.d.cts +148 -0
  32. package/dist/server/index.d.cts.map +1 -0
  33. package/dist/server/index.d.mts +148 -0
  34. package/dist/server/index.d.mts.map +1 -0
  35. package/dist/server/index.mjs +182 -0
  36. package/dist/server/index.mjs.map +1 -0
  37. package/package.json +17 -5
  38. package/src/primitives/Array.ts +57 -22
  39. package/src/primitives/Boolean.ts +32 -18
  40. package/src/primitives/Either.ts +39 -24
  41. package/src/primitives/Lazy.ts +16 -2
  42. package/src/primitives/Literal.ts +32 -19
  43. package/src/primitives/Number.ts +38 -25
  44. package/src/primitives/String.ts +39 -24
  45. package/src/primitives/Struct.ts +124 -27
  46. package/src/primitives/Tree.ts +117 -30
  47. package/src/primitives/Union.ts +56 -29
  48. package/src/primitives/shared.ts +103 -9
  49. package/tests/primitives/Array.test.ts +108 -0
  50. package/tests/primitives/Struct.test.ts +250 -0
  51. package/tests/primitives/Tree.test.ts +250 -0
  52. package/tsdown.config.ts +1 -1
  53. /package/dist/{chunk-C6wwvPpM.mjs → chunk-CLMFDpHK.mjs} +0 -0
package/dist/index.mjs CHANGED
@@ -1,49 +1,8 @@
1
- import { t as __export } from "./chunk-C6wwvPpM.mjs";
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
6
  //#region src/primitives/shared.ts
48
7
  var ValidationError = class extends Error {
49
8
  constructor(message) {
@@ -67,10 +26,38 @@ function runValidators(value, validators) {
67
26
  function isCompatibleOperation(operation, operationDefinitions) {
68
27
  return Object.values(operationDefinitions).some((value) => value.kind === operation.kind);
69
28
  }
29
+ /**
30
+ * Applies default values to a partial input, recursively handling nested structs.
31
+ *
32
+ * Uses a two-layer approach:
33
+ * 1. First, get the struct's initial state (which includes struct-level defaults)
34
+ * 2. Then, layer the provided values on top
35
+ * 3. Finally, ensure nested structs are recursively processed
36
+ *
37
+ * @param primitive - The primitive definition containing field information
38
+ * @param value - The partial value provided by the user
39
+ * @returns The value with defaults applied for missing fields
40
+ */
41
+ function applyDefaults(primitive, value) {
42
+ if (primitive._tag === "StructPrimitive") {
43
+ var _structPrimitive$_int;
44
+ const structPrimitive = primitive;
45
+ const result = _objectSpread2(_objectSpread2({}, (_structPrimitive$_int = structPrimitive._internal.getInitialState()) !== null && _structPrimitive$_int !== void 0 ? _structPrimitive$_int : {}), value);
46
+ for (const key in structPrimitive.fields) {
47
+ const fieldPrimitive = structPrimitive.fields[key];
48
+ if (result[key] === void 0) {
49
+ const fieldDefault = fieldPrimitive._internal.getInitialState();
50
+ if (fieldDefault !== void 0) result[key] = fieldDefault;
51
+ } else if (fieldPrimitive._tag === "StructPrimitive" && typeof result[key] === "object" && result[key] !== null) result[key] = applyDefaults(fieldPrimitive, result[key]);
52
+ }
53
+ return result;
54
+ }
55
+ return value;
56
+ }
70
57
 
71
58
  //#endregion
72
59
  //#region src/OperationDefinition.ts
73
- const make$5 = (options) => {
60
+ const make = (options) => {
74
61
  return {
75
62
  kind: options.kind,
76
63
  payload: options.payload,
@@ -79,205 +66,6 @@ const make$5 = (options) => {
79
66
  };
80
67
  };
81
68
 
82
- //#endregion
83
- //#region src/OperationPath.ts
84
- var OperationPath_exports = /* @__PURE__ */ __export({
85
- decode: () => decode$2,
86
- encode: () => encode$2,
87
- fromTokens: () => fromTokens,
88
- getRelativePath: () => getRelativePath,
89
- isPrefix: () => isPrefix,
90
- make: () => make$4,
91
- pathsEqual: () => pathsEqual,
92
- pathsOverlap: () => pathsOverlap
93
- });
94
- const parseStringPath = (stringPath) => {
95
- return stringPath.split("/");
96
- };
97
- const makeStringPathFromTokens = (tokens) => {
98
- return tokens.join("/");
99
- };
100
- /**
101
- * Creates a new operation path.
102
- * @param stringPath - The string path to create the path from.
103
- * @returns The new operation path.
104
- */
105
- function make$4(stringPath) {
106
- const tokensInternal = stringPath ? parseStringPath(stringPath) : [];
107
- /**
108
- * Returns the tokens of the path.
109
- * @returns The tokens of the path.
110
- */
111
- const toTokens = () => {
112
- return tokensInternal;
113
- };
114
- /**
115
- * Concatenates two paths.
116
- * @param other - The other path to concatenate.
117
- * @returns The new path.
118
- */
119
- const concat = (other) => {
120
- return make$4(makeStringPathFromTokens(toTokens().concat(other.toTokens())));
121
- };
122
- /**
123
- * Appends a token to the path.
124
- * @param token - The token to append.
125
- * @returns The new path.
126
- */
127
- const append = (token) => {
128
- return make$4(makeStringPathFromTokens(toTokens().concat([token])));
129
- };
130
- /**
131
- * Removes the last token from the path.
132
- * @returns The new path.
133
- */
134
- const pop = () => {
135
- return make$4(makeStringPathFromTokens(toTokens().slice(0, -1)));
136
- };
137
- /**
138
- * Removes the first token from the path.
139
- * @returns The new path.
140
- */
141
- const shift = () => {
142
- return make$4(makeStringPathFromTokens(toTokens().slice(1)));
143
- };
144
- return {
145
- _tag: "OperationPath",
146
- toTokens,
147
- concat,
148
- append,
149
- pop,
150
- shift
151
- };
152
- }
153
- /**
154
- * Creates a new operation path from tokens.
155
- * @param tokens - The tokens to create the path from.
156
- * @returns The new operation path.
157
- */
158
- function fromTokens(tokens) {
159
- return make$4(makeStringPathFromTokens(tokens));
160
- }
161
- /**
162
- * Checks if two operation paths overlap (one is prefix of the other or equal).
163
- */
164
- const pathsOverlap = (pathA, pathB) => {
165
- const tokensA = pathA.toTokens().filter((t) => t !== "");
166
- const tokensB = pathB.toTokens().filter((t) => t !== "");
167
- const minLength = Math.min(tokensA.length, tokensB.length);
168
- for (let i = 0; i < minLength; i++) if (tokensA[i] !== tokensB[i]) return false;
169
- return true;
170
- };
171
- /**
172
- * Checks if pathA is a prefix of pathB (pathA is ancestor of pathB).
173
- */
174
- const isPrefix = (pathA, pathB) => {
175
- const tokensA = pathA.toTokens().filter((t) => t !== "");
176
- const tokensB = pathB.toTokens().filter((t) => t !== "");
177
- if (tokensA.length > tokensB.length) return false;
178
- for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
179
- return true;
180
- };
181
- /**
182
- * Checks if two paths are exactly equal.
183
- */
184
- const pathsEqual = (pathA, pathB) => {
185
- const tokensA = pathA.toTokens().filter((t) => t !== "");
186
- const tokensB = pathB.toTokens().filter((t) => t !== "");
187
- if (tokensA.length !== tokensB.length) return false;
188
- for (let i = 0; i < tokensA.length; i++) if (tokensA[i] !== tokensB[i]) return false;
189
- return true;
190
- };
191
- /**
192
- * Gets the relative path of pathB with respect to pathA.
193
- * Assumes pathA is a prefix of pathB.
194
- */
195
- const getRelativePath = (basePath, fullPath) => {
196
- const baseTokens = basePath.toTokens().filter((t) => t !== "");
197
- return fullPath.toTokens().filter((t) => t !== "").slice(baseTokens.length);
198
- };
199
- /**
200
- * Encodes an OperationPath to a string for network transport.
201
- * @param path - The operation path to encode.
202
- * @returns The encoded string representation.
203
- */
204
- const encode$2 = (path) => {
205
- return makeStringPathFromTokens(path.toTokens());
206
- };
207
- /**
208
- * Decodes an encoded string back to an OperationPath.
209
- * @param encoded - The encoded string representation.
210
- * @returns The decoded OperationPath.
211
- */
212
- const decode$2 = (encoded) => {
213
- return make$4(encoded);
214
- };
215
-
216
- //#endregion
217
- //#region src/Operation.ts
218
- var Operation_exports = /* @__PURE__ */ __export({
219
- decode: () => decode$1,
220
- encode: () => encode$1,
221
- fromDefinition: () => fromDefinition
222
- });
223
- const fromDefinition = (operationPath, definition, payload) => {
224
- return {
225
- kind: definition.kind,
226
- path: operationPath,
227
- payload
228
- };
229
- };
230
- /**
231
- * Encodes an Operation to a JSON-serializable format for network transport.
232
- * @param operation - The operation to encode.
233
- * @returns The encoded representation.
234
- */
235
- const encode$1 = (operation) => {
236
- return {
237
- kind: operation.kind,
238
- path: encode$2(operation.path),
239
- payload: operation.payload
240
- };
241
- };
242
- /**
243
- * Decodes an encoded operation back to an Operation.
244
- * Note: This returns a partial operation without the definition methods.
245
- * The caller must have the operation definitions to fully reconstruct if needed.
246
- * @param encoded - The encoded representation.
247
- * @returns The decoded Operation (without definition-specific methods).
248
- */
249
- const decode$1 = (encoded) => {
250
- return {
251
- kind: encoded.kind,
252
- path: decode$2(encoded.path),
253
- payload: encoded.payload
254
- };
255
- };
256
-
257
- //#endregion
258
- //#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
259
- function ownKeys(e, r) {
260
- var t = Object.keys(e);
261
- if (Object.getOwnPropertySymbols) {
262
- var o = Object.getOwnPropertySymbols(e);
263
- r && (o = o.filter(function(r$1) {
264
- return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
265
- })), t.push.apply(t, o);
266
- }
267
- return t;
268
- }
269
- function _objectSpread2(e) {
270
- for (var r = 1; r < arguments.length; r++) {
271
- var t = null != arguments[r] ? arguments[r] : {};
272
- r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
273
- _defineProperty(e, r$1, t[r$1]);
274
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
275
- Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
276
- });
277
- }
278
- return e;
279
- }
280
-
281
69
  //#endregion
282
70
  //#region src/primitives/String.ts
283
71
  var StringPrimitive = class StringPrimitive {
@@ -285,8 +73,12 @@ var StringPrimitive = class StringPrimitive {
285
73
  _defineProperty(this, "_tag", "StringPrimitive");
286
74
  _defineProperty(this, "_State", void 0);
287
75
  _defineProperty(this, "_Proxy", void 0);
76
+ _defineProperty(this, "_TRequired", void 0);
77
+ _defineProperty(this, "_THasDefault", void 0);
78
+ _defineProperty(this, "TUpdateInput", void 0);
79
+ _defineProperty(this, "TSetInput", void 0);
288
80
  _defineProperty(this, "_schema", void 0);
289
- _defineProperty(this, "_opDefinitions", { set: make$5({
81
+ _defineProperty(this, "_opDefinitions", { set: make({
290
82
  kind: "string.set",
291
83
  payload: Schema.String,
292
84
  target: Schema.String,
@@ -303,6 +95,9 @@ var StringPrimitive = class StringPrimitive {
303
95
  set: (value) => {
304
96
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
305
97
  },
98
+ update: (value) => {
99
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
100
+ },
306
101
  toSnapshot: () => {
307
102
  const state = env.getState(operationPath);
308
103
  return state !== null && state !== void 0 ? state : defaultValue;
@@ -381,7 +176,7 @@ var StringPrimitive = class StringPrimitive {
381
176
  }
382
177
  };
383
178
  /** Creates a new StringPrimitive */
384
- const String$1 = () => new StringPrimitive({
179
+ const String = () => new StringPrimitive({
385
180
  required: false,
386
181
  defaultValue: void 0,
387
182
  validators: []
@@ -394,8 +189,12 @@ var StructPrimitive = class StructPrimitive {
394
189
  _defineProperty(this, "_tag", "StructPrimitive");
395
190
  _defineProperty(this, "_State", void 0);
396
191
  _defineProperty(this, "_Proxy", void 0);
192
+ _defineProperty(this, "_TRequired", void 0);
193
+ _defineProperty(this, "_THasDefault", void 0);
194
+ _defineProperty(this, "TSetInput", void 0);
195
+ _defineProperty(this, "TUpdateInput", void 0);
397
196
  _defineProperty(this, "_schema", void 0);
398
- _defineProperty(this, "_opDefinitions", { set: make$5({
197
+ _defineProperty(this, "_opDefinitions", { set: make({
399
198
  kind: "struct.set",
400
199
  payload: Schema.Unknown,
401
200
  target: Schema.Unknown,
@@ -425,7 +224,20 @@ var StructPrimitive = class StructPrimitive {
425
224
  return state !== null && state !== void 0 ? state : defaultValue;
426
225
  },
427
226
  set: (value) => {
428
- env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
227
+ const merged = applyDefaults(this, value);
228
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, merged));
229
+ },
230
+ update: (value) => {
231
+ for (const key in value) if (Object.prototype.hasOwnProperty.call(value, key)) {
232
+ const fieldValue = value[key];
233
+ if (fieldValue === void 0) continue;
234
+ const fieldPrimitive = fields[key];
235
+ if (!fieldPrimitive) continue;
236
+ const fieldPath = operationPath.append(key);
237
+ const fieldProxy = fieldPrimitive._internal.createProxy(env, fieldPath);
238
+ if (fieldPrimitive._tag === "StructPrimitive" && typeof fieldValue === "object" && fieldValue !== null && !Array.isArray(fieldValue)) fieldProxy.update(fieldValue);
239
+ else fieldProxy.set(fieldValue);
240
+ }
429
241
  },
430
242
  toSnapshot: () => {
431
243
  return buildSnapshot();
@@ -434,6 +246,7 @@ var StructPrimitive = class StructPrimitive {
434
246
  get: (target, prop, _receiver) => {
435
247
  if (prop === "get") return target.get;
436
248
  if (prop === "set") return target.set;
249
+ if (prop === "update") return target.update;
437
250
  if (prop === "toSnapshot") return target.toSnapshot;
438
251
  if (typeof prop === "symbol") return;
439
252
  if (prop in fields) {
@@ -443,7 +256,7 @@ var StructPrimitive = class StructPrimitive {
443
256
  }
444
257
  },
445
258
  has: (_target, prop) => {
446
- if (prop === "get" || prop === "set" || prop === "toSnapshot") return true;
259
+ if (prop === "get" || prop === "set" || prop === "update" || prop === "toSnapshot") return true;
447
260
  if (typeof prop === "string" && prop in fields) return true;
448
261
  return false;
449
262
  }
@@ -541,7 +354,8 @@ var StructPrimitive = class StructPrimitive {
541
354
  }
542
355
  /** Set a default value for this struct */
543
356
  default(defaultValue) {
544
- return new StructPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
357
+ const merged = applyDefaults(this, defaultValue);
358
+ return new StructPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue: merged }));
545
359
  }
546
360
  /** Get the fields schema */
547
361
  get fields() {
@@ -570,8 +384,12 @@ var BooleanPrimitive = class BooleanPrimitive {
570
384
  _defineProperty(this, "_tag", "BooleanPrimitive");
571
385
  _defineProperty(this, "_State", void 0);
572
386
  _defineProperty(this, "_Proxy", void 0);
387
+ _defineProperty(this, "_TRequired", void 0);
388
+ _defineProperty(this, "_THasDefault", void 0);
389
+ _defineProperty(this, "TUpdateInput", void 0);
390
+ _defineProperty(this, "TSetInput", void 0);
573
391
  _defineProperty(this, "_schema", void 0);
574
- _defineProperty(this, "_opDefinitions", { set: make$5({
392
+ _defineProperty(this, "_opDefinitions", { set: make({
575
393
  kind: "boolean.set",
576
394
  payload: Schema.Boolean,
577
395
  target: Schema.Boolean,
@@ -588,6 +406,9 @@ var BooleanPrimitive = class BooleanPrimitive {
588
406
  set: (value) => {
589
407
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
590
408
  },
409
+ update: (value) => {
410
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
411
+ },
591
412
  toSnapshot: () => {
592
413
  const state = env.getState(operationPath);
593
414
  return state !== null && state !== void 0 ? state : defaultValue;
@@ -647,8 +468,12 @@ var NumberPrimitive = class NumberPrimitive {
647
468
  _defineProperty(this, "_tag", "NumberPrimitive");
648
469
  _defineProperty(this, "_State", void 0);
649
470
  _defineProperty(this, "_Proxy", void 0);
471
+ _defineProperty(this, "_TRequired", void 0);
472
+ _defineProperty(this, "_THasDefault", void 0);
473
+ _defineProperty(this, "TUpdateInput", void 0);
474
+ _defineProperty(this, "TSetInput", void 0);
650
475
  _defineProperty(this, "_schema", void 0);
651
- _defineProperty(this, "_opDefinitions", { set: make$5({
476
+ _defineProperty(this, "_opDefinitions", { set: make({
652
477
  kind: "number.set",
653
478
  payload: Schema.Number,
654
479
  target: Schema.Number,
@@ -665,6 +490,9 @@ var NumberPrimitive = class NumberPrimitive {
665
490
  set: (value) => {
666
491
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
667
492
  },
493
+ update: (value) => {
494
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
495
+ },
668
496
  toSnapshot: () => {
669
497
  const state = env.getState(operationPath);
670
498
  return state !== null && state !== void 0 ? state : defaultValue;
@@ -731,7 +559,7 @@ var NumberPrimitive = class NumberPrimitive {
731
559
  }
732
560
  };
733
561
  /** Creates a new NumberPrimitive */
734
- const Number$1 = () => new NumberPrimitive({
562
+ const Number = () => new NumberPrimitive({
735
563
  required: false,
736
564
  defaultValue: void 0,
737
565
  validators: []
@@ -744,8 +572,12 @@ var LiteralPrimitive = class LiteralPrimitive {
744
572
  _defineProperty(this, "_tag", "LiteralPrimitive");
745
573
  _defineProperty(this, "_State", void 0);
746
574
  _defineProperty(this, "_Proxy", void 0);
575
+ _defineProperty(this, "_TRequired", void 0);
576
+ _defineProperty(this, "_THasDefault", void 0);
577
+ _defineProperty(this, "TUpdateInput", void 0);
578
+ _defineProperty(this, "TSetInput", void 0);
747
579
  _defineProperty(this, "_schema", void 0);
748
- _defineProperty(this, "_opDefinitions", { set: make$5({
580
+ _defineProperty(this, "_opDefinitions", { set: make({
749
581
  kind: "literal.set",
750
582
  payload: Schema.Unknown,
751
583
  target: Schema.Unknown,
@@ -762,6 +594,9 @@ var LiteralPrimitive = class LiteralPrimitive {
762
594
  set: (value) => {
763
595
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
764
596
  },
597
+ update: (value) => {
598
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
599
+ },
765
600
  toSnapshot: () => {
766
601
  const state = env.getState(operationPath);
767
602
  return state !== null && state !== void 0 ? state : defaultValue;
@@ -1188,27 +1023,31 @@ var ArrayPrimitive = class ArrayPrimitive {
1188
1023
  _defineProperty(this, "_tag", "ArrayPrimitive");
1189
1024
  _defineProperty(this, "_State", void 0);
1190
1025
  _defineProperty(this, "_Proxy", void 0);
1026
+ _defineProperty(this, "_TRequired", void 0);
1027
+ _defineProperty(this, "_THasDefault", void 0);
1028
+ _defineProperty(this, "TSetInput", void 0);
1029
+ _defineProperty(this, "TUpdateInput", void 0);
1191
1030
  _defineProperty(this, "_schema", void 0);
1192
1031
  _defineProperty(this, "_opDefinitions", {
1193
- set: make$5({
1032
+ set: make({
1194
1033
  kind: "array.set",
1195
1034
  payload: Schema.Unknown,
1196
1035
  target: Schema.Unknown,
1197
1036
  apply: (payload) => payload
1198
1037
  }),
1199
- insert: make$5({
1038
+ insert: make({
1200
1039
  kind: "array.insert",
1201
1040
  payload: Schema.Unknown,
1202
1041
  target: Schema.Unknown,
1203
1042
  apply: (payload) => payload
1204
1043
  }),
1205
- remove: make$5({
1044
+ remove: make({
1206
1045
  kind: "array.remove",
1207
1046
  payload: Schema.Unknown,
1208
1047
  target: Schema.Unknown,
1209
1048
  apply: (payload) => payload
1210
1049
  }),
1211
- move: make$5({
1050
+ move: make({
1212
1051
  kind: "array.move",
1213
1052
  payload: Schema.Unknown,
1214
1053
  target: Schema.Unknown,
@@ -1223,6 +1062,9 @@ var ArrayPrimitive = class ArrayPrimitive {
1223
1062
  if (!state || !globalThis.Array.isArray(state)) return [];
1224
1063
  return sortByPos(state);
1225
1064
  };
1065
+ const applyElementDefaults = (value) => {
1066
+ return applyDefaults(elementPrimitive, value);
1067
+ };
1226
1068
  return {
1227
1069
  get: () => {
1228
1070
  return getCurrentState();
@@ -1233,10 +1075,11 @@ var ArrayPrimitive = class ArrayPrimitive {
1233
1075
  for (const value of values) {
1234
1076
  const id = env.generateId();
1235
1077
  const pos = generatePosBetween(prevPos, null);
1078
+ const mergedValue = applyElementDefaults(value);
1236
1079
  entries.push({
1237
1080
  id,
1238
1081
  pos,
1239
- value
1082
+ value: mergedValue
1240
1083
  });
1241
1084
  prevPos = pos;
1242
1085
  }
@@ -1247,10 +1090,11 @@ var ArrayPrimitive = class ArrayPrimitive {
1247
1090
  const lastPos = sorted.length > 0 ? sorted[sorted.length - 1].pos : null;
1248
1091
  const id = env.generateId();
1249
1092
  const pos = generatePosBetween(lastPos, null);
1093
+ const mergedValue = applyElementDefaults(value);
1250
1094
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
1251
1095
  id,
1252
1096
  pos,
1253
- value
1097
+ value: mergedValue
1254
1098
  }));
1255
1099
  },
1256
1100
  insertAt: (index, value) => {
@@ -1259,10 +1103,11 @@ var ArrayPrimitive = class ArrayPrimitive {
1259
1103
  const rightPos = index < sorted.length && sorted[index] ? sorted[index].pos : null;
1260
1104
  const id = env.generateId();
1261
1105
  const pos = generatePosBetween(leftPos, rightPos);
1106
+ const mergedValue = applyElementDefaults(value);
1262
1107
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
1263
1108
  id,
1264
1109
  pos,
1265
- value
1110
+ value: mergedValue
1266
1111
  }));
1267
1112
  },
1268
1113
  remove: (id) => {
@@ -1456,6 +1301,10 @@ var LazyPrimitive = class {
1456
1301
  _defineProperty(this, "_tag", "LazyPrimitive");
1457
1302
  _defineProperty(this, "_State", void 0);
1458
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);
1459
1308
  _defineProperty(this, "_thunk", void 0);
1460
1309
  _defineProperty(this, "_resolved", void 0);
1461
1310
  _defineProperty(this, "_internal", {
@@ -1494,8 +1343,12 @@ var UnionPrimitive = class UnionPrimitive {
1494
1343
  _defineProperty(this, "_tag", "UnionPrimitive");
1495
1344
  _defineProperty(this, "_State", void 0);
1496
1345
  _defineProperty(this, "_Proxy", void 0);
1346
+ _defineProperty(this, "_TRequired", void 0);
1347
+ _defineProperty(this, "_THasDefault", void 0);
1348
+ _defineProperty(this, "TSetInput", void 0);
1349
+ _defineProperty(this, "TUpdateInput", void 0);
1497
1350
  _defineProperty(this, "_schema", void 0);
1498
- _defineProperty(this, "_opDefinitions", { set: make$5({
1351
+ _defineProperty(this, "_opDefinitions", { set: make({
1499
1352
  kind: "union.set",
1500
1353
  payload: Schema.Unknown,
1501
1354
  target: Schema.Unknown,
@@ -1511,7 +1364,8 @@ var UnionPrimitive = class UnionPrimitive {
1511
1364
  return state !== null && state !== void 0 ? state : defaultValue;
1512
1365
  },
1513
1366
  set: (value) => {
1514
- env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
1367
+ const merged = this._applyVariantDefaults(value);
1368
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, merged));
1515
1369
  },
1516
1370
  as: (variant) => {
1517
1371
  const variantPrimitive = variants[variant];
@@ -1600,7 +1454,8 @@ var UnionPrimitive = class UnionPrimitive {
1600
1454
  }
1601
1455
  /** Set a default value for this union */
1602
1456
  default(defaultValue) {
1603
- return new UnionPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue }));
1457
+ const merged = this._applyVariantDefaults(defaultValue);
1458
+ return new UnionPrimitive(_objectSpread2(_objectSpread2({}, this._schema), {}, { defaultValue: merged }));
1604
1459
  }
1605
1460
  /** Get the discriminator field name */
1606
1461
  get discriminator() {
@@ -1621,6 +1476,13 @@ var UnionPrimitive = class UnionPrimitive {
1621
1476
  }
1622
1477
  }
1623
1478
  }
1479
+ /** Apply defaults to a variant value based on the discriminator */
1480
+ _applyVariantDefaults(value) {
1481
+ const variantKey = this._findVariantKey(value);
1482
+ if (!variantKey) return value;
1483
+ const variantPrimitive = this._schema.variants[variantKey];
1484
+ return applyDefaults(variantPrimitive, value);
1485
+ }
1624
1486
  };
1625
1487
  function Union(options) {
1626
1488
  var _options$discriminato;
@@ -1639,8 +1501,12 @@ var EitherPrimitive = class EitherPrimitive {
1639
1501
  _defineProperty(this, "_tag", "EitherPrimitive");
1640
1502
  _defineProperty(this, "_State", void 0);
1641
1503
  _defineProperty(this, "_Proxy", void 0);
1504
+ _defineProperty(this, "_TRequired", void 0);
1505
+ _defineProperty(this, "_THasDefault", void 0);
1506
+ _defineProperty(this, "TUpdateInput", void 0);
1507
+ _defineProperty(this, "TSetInput", void 0);
1642
1508
  _defineProperty(this, "_schema", void 0);
1643
- _defineProperty(this, "_opDefinitions", { set: make$5({
1509
+ _defineProperty(this, "_opDefinitions", { set: make({
1644
1510
  kind: "either.set",
1645
1511
  payload: Schema.Unknown,
1646
1512
  target: Schema.Unknown,
@@ -1657,6 +1523,9 @@ var EitherPrimitive = class EitherPrimitive {
1657
1523
  set: (value) => {
1658
1524
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
1659
1525
  },
1526
+ update: (value) => {
1527
+ env.addOperation(fromDefinition(operationPath, this._opDefinitions.set, value));
1528
+ },
1660
1529
  match: (handlers) => {
1661
1530
  const currentState = env.getState(operationPath);
1662
1531
  const effectiveState = currentState !== null && currentState !== void 0 ? currentState : defaultValue;
@@ -1920,28 +1789,32 @@ var TreePrimitive = class TreePrimitive {
1920
1789
  _defineProperty(this, "_tag", "TreePrimitive");
1921
1790
  _defineProperty(this, "_State", void 0);
1922
1791
  _defineProperty(this, "_Proxy", void 0);
1792
+ _defineProperty(this, "_TRequired", void 0);
1793
+ _defineProperty(this, "_THasDefault", void 0);
1794
+ _defineProperty(this, "TSetInput", void 0);
1795
+ _defineProperty(this, "TUpdateInput", void 0);
1923
1796
  _defineProperty(this, "_schema", void 0);
1924
1797
  _defineProperty(this, "_nodeTypeRegistry", void 0);
1925
1798
  _defineProperty(this, "_opDefinitions", {
1926
- set: make$5({
1799
+ set: make({
1927
1800
  kind: "tree.set",
1928
1801
  payload: Schema.Unknown,
1929
1802
  target: Schema.Unknown,
1930
1803
  apply: (payload) => payload
1931
1804
  }),
1932
- insert: make$5({
1805
+ insert: make({
1933
1806
  kind: "tree.insert",
1934
1807
  payload: Schema.Unknown,
1935
1808
  target: Schema.Unknown,
1936
1809
  apply: (payload) => payload
1937
1810
  }),
1938
- remove: make$5({
1811
+ remove: make({
1939
1812
  kind: "tree.remove",
1940
1813
  payload: Schema.Unknown,
1941
1814
  target: Schema.Unknown,
1942
1815
  apply: (payload) => payload
1943
1816
  }),
1944
- move: make$5({
1817
+ move: make({
1945
1818
  kind: "tree.move",
1946
1819
  payload: Schema.Unknown,
1947
1820
  target: Schema.Unknown,
@@ -1970,11 +1843,15 @@ var TreePrimitive = class TreePrimitive {
1970
1843
  as: (nodeType) => {
1971
1844
  if (nodeState.type !== nodeType.type) throw new ValidationError(`Node is of type "${nodeState.type}", not "${nodeType.type}"`);
1972
1845
  const nodePath = operationPath.append(nodeState.id);
1846
+ const dataProxy = nodeType.data._internal.createProxy(env, nodePath);
1973
1847
  return {
1974
1848
  id: nodeState.id,
1975
1849
  type: nodeType.type,
1976
- data: nodeType.data._internal.createProxy(env, nodePath),
1977
- get: () => nodeState
1850
+ data: dataProxy,
1851
+ get: () => nodeState,
1852
+ update: (value) => {
1853
+ dataProxy.update(value);
1854
+ }
1978
1855
  };
1979
1856
  },
1980
1857
  get: () => nodeState
@@ -2021,12 +1898,13 @@ var TreePrimitive = class TreePrimitive {
2021
1898
  const parentType = getParentType(parentId);
2022
1899
  this._validateChildType(parentType, nodeType.type);
2023
1900
  if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
1901
+ const mergedData = applyDefaults(nodeType.data, data);
2024
1902
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
2025
1903
  id,
2026
1904
  type: nodeType.type,
2027
1905
  parentId,
2028
1906
  pos,
2029
- data
1907
+ data: mergedData
2030
1908
  }));
2031
1909
  return id;
2032
1910
  },
@@ -2039,12 +1917,13 @@ var TreePrimitive = class TreePrimitive {
2039
1917
  const parentType = getParentType(parentId);
2040
1918
  this._validateChildType(parentType, nodeType.type);
2041
1919
  if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
1920
+ const mergedData = applyDefaults(nodeType.data, data);
2042
1921
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
2043
1922
  id,
2044
1923
  type: nodeType.type,
2045
1924
  parentId,
2046
1925
  pos,
2047
- data
1926
+ data: mergedData
2048
1927
  }));
2049
1928
  return id;
2050
1929
  },
@@ -2058,12 +1937,13 @@ var TreePrimitive = class TreePrimitive {
2058
1937
  const parentType = getParentType(parentId);
2059
1938
  this._validateChildType(parentType, nodeType.type);
2060
1939
  if (parentId === null && state.some((n) => n.parentId === null)) throw new ValidationError("Tree already has a root node");
1940
+ const mergedData = applyDefaults(nodeType.data, data);
2061
1941
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
2062
1942
  id,
2063
1943
  type: nodeType.type,
2064
1944
  parentId,
2065
1945
  pos,
2066
- data
1946
+ data: mergedData
2067
1947
  }));
2068
1948
  return id;
2069
1949
  },
@@ -2079,12 +1959,13 @@ var TreePrimitive = class TreePrimitive {
2079
1959
  const id = env.generateId();
2080
1960
  const parentType = getParentType(parentId);
2081
1961
  this._validateChildType(parentType, nodeType.type);
1962
+ const mergedData = applyDefaults(nodeType.data, data);
2082
1963
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
2083
1964
  id,
2084
1965
  type: nodeType.type,
2085
1966
  parentId,
2086
1967
  pos,
2087
- data
1968
+ data: mergedData
2088
1969
  }));
2089
1970
  return id;
2090
1971
  },
@@ -2100,12 +1981,13 @@ var TreePrimitive = class TreePrimitive {
2100
1981
  const id = env.generateId();
2101
1982
  const parentType = getParentType(parentId);
2102
1983
  this._validateChildType(parentType, nodeType.type);
1984
+ const mergedData = applyDefaults(nodeType.data, data);
2103
1985
  env.addOperation(fromDefinition(operationPath, this._opDefinitions.insert, {
2104
1986
  id,
2105
1987
  type: nodeType.type,
2106
1988
  parentId,
2107
1989
  pos,
2108
- data
1990
+ data: mergedData
2109
1991
  }));
2110
1992
  return id;
2111
1993
  },
@@ -2216,6 +2098,13 @@ var TreePrimitive = class TreePrimitive {
2216
2098
  const nodePath = operationPath.append(id);
2217
2099
  return nodeType.data._internal.createProxy(env, nodePath);
2218
2100
  },
2101
+ updateAt: (id, nodeType, value) => {
2102
+ const node = getCurrentState().find((n) => n.id === id);
2103
+ if (!node) throw new ValidationError(`Node not found: ${id}`);
2104
+ if (node.type !== nodeType.type) throw new ValidationError(`Node is of type "${node.type}", not "${nodeType.type}"`);
2105
+ const nodePath = operationPath.append(id);
2106
+ nodeType.data._internal.createProxy(env, nodePath).update(value);
2107
+ },
2219
2108
  toSnapshot: () => {
2220
2109
  const state = getCurrentState();
2221
2110
  const rootNode = state.find((n) => n.parentId === null);
@@ -2436,9 +2325,9 @@ var Primitive_exports = /* @__PURE__ */ __export({
2436
2325
  LazyPrimitive: () => LazyPrimitive,
2437
2326
  Literal: () => Literal,
2438
2327
  LiteralPrimitive: () => LiteralPrimitive,
2439
- Number: () => Number$1,
2328
+ Number: () => Number,
2440
2329
  NumberPrimitive: () => NumberPrimitive,
2441
- String: () => String$1,
2330
+ String: () => String,
2442
2331
  StringPrimitive: () => StringPrimitive,
2443
2332
  Struct: () => Struct,
2444
2333
  StructPrimitive: () => StructPrimitive,
@@ -2450,311 +2339,15 @@ var Primitive_exports = /* @__PURE__ */ __export({
2450
2339
  Union: () => Union,
2451
2340
  UnionPrimitive: () => UnionPrimitive,
2452
2341
  ValidationError: () => ValidationError,
2342
+ applyDefaults: () => applyDefaults,
2453
2343
  isCompatibleOperation: () => isCompatibleOperation,
2454
2344
  runValidators: () => runValidators
2455
2345
  });
2456
2346
 
2457
- //#endregion
2458
- //#region src/ProxyEnvironment.ts
2459
- var ProxyEnvironment_exports = /* @__PURE__ */ __export({ make: () => make$3 });
2460
- /** Default UUID generator using crypto.randomUUID */
2461
- const defaultGenerateId = () => {
2462
- return crypto.randomUUID();
2463
- };
2464
- /** Default state getter that always returns undefined */
2465
- const defaultGetState = (_path) => {};
2466
- /**
2467
- * Creates a ProxyEnvironment.
2468
- * @param optionsOrCallback - Either an options object or a simple callback for operations
2469
- */
2470
- const make$3 = (optionsOrCallback) => {
2471
- var _options$getState, _options$generateId;
2472
- const options = typeof optionsOrCallback === "function" ? { onOperation: optionsOrCallback } : optionsOrCallback;
2473
- return {
2474
- addOperation: (operation) => {
2475
- options.onOperation(operation);
2476
- },
2477
- getState: (_options$getState = options.getState) !== null && _options$getState !== void 0 ? _options$getState : defaultGetState,
2478
- generateId: (_options$generateId = options.generateId) !== null && _options$generateId !== void 0 ? _options$generateId : defaultGenerateId
2479
- };
2480
- };
2481
-
2482
- //#endregion
2483
- //#region src/Transaction.ts
2484
- var Transaction_exports = /* @__PURE__ */ __export({
2485
- decode: () => decode,
2486
- empty: () => empty,
2487
- encode: () => encode,
2488
- isEmpty: () => isEmpty,
2489
- make: () => make$2,
2490
- merge: () => merge
2491
- });
2492
- /**
2493
- * Creates a new Transaction with the given operations.
2494
- */
2495
- const make$2 = (ops) => ({
2496
- id: crypto.randomUUID(),
2497
- ops,
2498
- timestamp: Date.now()
2499
- });
2500
- /**
2501
- * Creates an empty Transaction.
2502
- */
2503
- const empty = () => make$2([]);
2504
- /**
2505
- * Checks if a transaction is empty (has no operations).
2506
- */
2507
- const isEmpty = (tx) => tx.ops.length === 0;
2508
- /**
2509
- * Merges multiple transactions into one.
2510
- */
2511
- const merge = (txs) => {
2512
- return make$2(txs.flatMap((tx) => tx.ops));
2513
- };
2514
- /**
2515
- * Encodes a Transaction to a JSON-serializable format for network transport.
2516
- * @param transaction - The transaction to encode.
2517
- * @returns The encoded representation.
2518
- */
2519
- const encode = (transaction) => ({
2520
- id: transaction.id,
2521
- ops: transaction.ops.map(encode$1),
2522
- timestamp: transaction.timestamp
2523
- });
2524
- /**
2525
- * Decodes an encoded transaction back to a Transaction.
2526
- * @param encoded - The encoded representation.
2527
- * @returns The decoded Transaction.
2528
- */
2529
- const decode = (encoded) => ({
2530
- id: encoded.id,
2531
- ops: encoded.ops.map(decode$1),
2532
- timestamp: encoded.timestamp
2533
- });
2534
-
2535
- //#endregion
2536
- //#region src/Document.ts
2537
- var Document_exports = /* @__PURE__ */ __export({
2538
- NestedTransactionError: () => NestedTransactionError,
2539
- OperationError: () => OperationError,
2540
- make: () => make$1
2541
- });
2542
- /**
2543
- * Error thrown when attempting to start a nested transaction.
2544
- */
2545
- var NestedTransactionError = class extends Error {
2546
- constructor() {
2547
- super("Nested transactions are not supported");
2548
- _defineProperty(this, "_tag", "NestedTransactionError");
2549
- this.name = "NestedTransactionError";
2550
- }
2551
- };
2552
- /**
2553
- * Error thrown when an operation fails to apply.
2554
- */
2555
- var OperationError = class extends Error {
2556
- constructor(message) {
2557
- super(message);
2558
- _defineProperty(this, "_tag", "OperationError");
2559
- this.name = "OperationError";
2560
- }
2561
- };
2562
- /**
2563
- * Creates a new Document for the given schema.
2564
- */
2565
- const make$1 = (schema, options) => {
2566
- var _options$initial;
2567
- let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
2568
- let _pending = [];
2569
- let _inTransaction = false;
2570
- let _txOps = [];
2571
- let _txBaseState = void 0;
2572
- /**
2573
- * Gets state at the given path.
2574
- */
2575
- const getStateAtPath = (path) => {
2576
- const tokens = path.toTokens().filter((t) => t !== "");
2577
- if (tokens.length === 0) return _state;
2578
- let current = _state;
2579
- for (const token of tokens) {
2580
- if (current === null || current === void 0) return;
2581
- if (typeof current === "object") {
2582
- if (Array.isArray(current)) {
2583
- const entry = current.find((e) => e.id === token);
2584
- if (entry) {
2585
- current = entry.value;
2586
- continue;
2587
- }
2588
- }
2589
- current = current[token];
2590
- } else return;
2591
- }
2592
- return current;
2593
- };
2594
- /**
2595
- * Applies a single operation to the current state.
2596
- */
2597
- const applyOperation = (op) => {
2598
- try {
2599
- _state = schema._internal.applyOperation(_state, op);
2600
- } catch (error) {
2601
- if (error instanceof Error) throw new OperationError(error.message);
2602
- throw new OperationError(String(error));
2603
- }
2604
- };
2605
- /**
2606
- * Handles an operation from a proxy.
2607
- * In transaction mode: collects operations, applies to state immediately for subsequent reads.
2608
- * Outside transaction mode: auto-wraps in a single-operation transaction.
2609
- */
2610
- const handleOperation = (op) => {
2611
- if (_inTransaction) {
2612
- _txOps.push(op);
2613
- applyOperation(op);
2614
- } else {
2615
- const baseState = _state;
2616
- try {
2617
- applyOperation(op);
2618
- _pending.push(op);
2619
- } catch (error) {
2620
- _state = baseState;
2621
- throw error;
2622
- }
2623
- }
2624
- };
2625
- /**
2626
- * Creates a ProxyEnvironment for the document.
2627
- */
2628
- const createEnv = () => {
2629
- return make$3({
2630
- onOperation: handleOperation,
2631
- getState: getStateAtPath
2632
- });
2633
- };
2634
- const env = createEnv();
2635
- const rootProxy = schema._internal.createProxy(env, make$4(""));
2636
- return {
2637
- schema,
2638
- root: rootProxy,
2639
- get: () => {
2640
- return _state;
2641
- },
2642
- toSnapshot: () => {
2643
- return rootProxy.toSnapshot();
2644
- },
2645
- transaction: (fn) => {
2646
- if (_inTransaction) throw new NestedTransactionError();
2647
- _inTransaction = true;
2648
- _txOps = [];
2649
- _txBaseState = _state;
2650
- try {
2651
- const result = fn(rootProxy);
2652
- _pending.push(..._txOps);
2653
- return result;
2654
- } catch (error) {
2655
- _state = _txBaseState;
2656
- throw error;
2657
- } finally {
2658
- _inTransaction = false;
2659
- _txOps = [];
2660
- _txBaseState = void 0;
2661
- }
2662
- },
2663
- apply: (ops) => {
2664
- for (const op of ops) applyOperation(op);
2665
- },
2666
- flush: () => {
2667
- const tx = make$2(_pending);
2668
- _pending = [];
2669
- return tx;
2670
- }
2671
- };
2672
- };
2673
-
2674
2347
  //#endregion
2675
2348
  //#region src/Transform.ts
2676
2349
  var Transform_exports = {};
2677
2350
 
2678
- //#endregion
2679
- //#region src/Presence.ts
2680
- /**
2681
- * @since 0.0.1
2682
- * Presence module for ephemeral per-connection state.
2683
- * Used by both client and server for schema validation.
2684
- */
2685
- var Presence_exports = /* @__PURE__ */ __export({
2686
- isValid: () => isValid,
2687
- make: () => make,
2688
- validate: () => validate,
2689
- validateSafe: () => validateSafe
2690
- });
2691
- /**
2692
- * Creates a new Presence schema wrapper.
2693
- *
2694
- * @example
2695
- * ```typescript
2696
- * import { Presence } from "@voidhash/mimic";
2697
- * import { Schema } from "effect";
2698
- *
2699
- * const CursorPresence = Presence.make({
2700
- * schema: Schema.Struct({
2701
- * name: Schema.String,
2702
- * cursor: Schema.Struct({
2703
- * x: Schema.Number,
2704
- * y: Schema.Number,
2705
- * }),
2706
- * }),
2707
- * });
2708
- * ```
2709
- */
2710
- const make = (options) => ({
2711
- _tag: "Presence",
2712
- schema: options.schema,
2713
- _Data: void 0
2714
- });
2715
- /**
2716
- * Validates unknown data against a Presence schema.
2717
- * Throws a ParseError if validation fails.
2718
- *
2719
- * @param presence - The Presence instance with the schema
2720
- * @param data - Unknown data to validate
2721
- * @returns The validated and typed data
2722
- * @throws ParseError if validation fails
2723
- */
2724
- const validate = (presence, data) => {
2725
- return Schema$1.decodeUnknownSync(presence.schema)(data);
2726
- };
2727
- /**
2728
- * Safely validates unknown data against a Presence schema.
2729
- * Returns undefined if validation fails instead of throwing.
2730
- *
2731
- * @param presence - The Presence instance with the schema
2732
- * @param data - Unknown data to validate
2733
- * @returns The validated data or undefined if invalid
2734
- */
2735
- const validateSafe = (presence, data) => {
2736
- try {
2737
- return Schema$1.decodeUnknownSync(presence.schema)(data);
2738
- } catch (_unused) {
2739
- return;
2740
- }
2741
- };
2742
- /**
2743
- * Checks if unknown data is valid according to a Presence schema.
2744
- *
2745
- * @param presence - The Presence instance with the schema
2746
- * @param data - Unknown data to check
2747
- * @returns true if valid, false otherwise
2748
- */
2749
- const isValid = (presence, data) => {
2750
- try {
2751
- Schema$1.decodeUnknownSync(presence.schema)(data);
2752
- return true;
2753
- } catch (_unused2) {
2754
- return false;
2755
- }
2756
- };
2757
-
2758
2351
  //#endregion
2759
2352
  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 };
2760
2353
  //# sourceMappingURL=index.mjs.map