@voidhash/mimic 1.0.0-beta.16 → 1.0.0-beta.17

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 (95) hide show
  1. package/dist/EffectSchema.cjs +3 -3
  2. package/dist/EffectSchema.d.cts +5 -5
  3. package/dist/EffectSchema.d.cts.map +1 -1
  4. package/dist/EffectSchema.d.mts +5 -5
  5. package/dist/EffectSchema.d.mts.map +1 -1
  6. package/dist/EffectSchema.mjs +3 -3
  7. package/dist/EffectSchema.mjs.map +1 -1
  8. package/dist/FractionalIndex.mjs.map +1 -1
  9. package/dist/Operation.d.cts +4 -4
  10. package/dist/Operation.d.cts.map +1 -1
  11. package/dist/Operation.d.mts +4 -4
  12. package/dist/Operation.d.mts.map +1 -1
  13. package/dist/Operation.mjs.map +1 -1
  14. package/dist/OperationDefinition.d.cts +2 -2
  15. package/dist/OperationDefinition.d.cts.map +1 -1
  16. package/dist/OperationDefinition.d.mts +2 -2
  17. package/dist/OperationDefinition.d.mts.map +1 -1
  18. package/dist/OperationDefinition.mjs.map +1 -1
  19. package/dist/Presence.mjs.map +1 -1
  20. package/dist/SchemaJSON.cjs +305 -0
  21. package/dist/SchemaJSON.d.cts +11 -0
  22. package/dist/SchemaJSON.d.cts.map +1 -0
  23. package/dist/SchemaJSON.d.mts +11 -0
  24. package/dist/SchemaJSON.d.mts.map +1 -0
  25. package/dist/SchemaJSON.mjs +301 -0
  26. package/dist/SchemaJSON.mjs.map +1 -0
  27. package/dist/index.cjs +7 -0
  28. package/dist/index.d.cts +2 -1
  29. package/dist/index.d.mts +2 -1
  30. package/dist/index.mjs +2 -1
  31. package/dist/primitives/Array.cjs +12 -2
  32. package/dist/primitives/Array.d.cts.map +1 -1
  33. package/dist/primitives/Array.d.mts.map +1 -1
  34. package/dist/primitives/Array.mjs +12 -2
  35. package/dist/primitives/Array.mjs.map +1 -1
  36. package/dist/primitives/Boolean.mjs.map +1 -1
  37. package/dist/primitives/Either.mjs.map +1 -1
  38. package/dist/primitives/Literal.mjs.map +1 -1
  39. package/dist/primitives/Number.cjs +27 -5
  40. package/dist/primitives/Number.d.cts.map +1 -1
  41. package/dist/primitives/Number.d.mts.map +1 -1
  42. package/dist/primitives/Number.mjs +27 -5
  43. package/dist/primitives/Number.mjs.map +1 -1
  44. package/dist/primitives/String.cjs +44 -13
  45. package/dist/primitives/String.d.cts.map +1 -1
  46. package/dist/primitives/String.d.mts.map +1 -1
  47. package/dist/primitives/String.mjs +44 -13
  48. package/dist/primitives/String.mjs.map +1 -1
  49. package/dist/primitives/Union.mjs.map +1 -1
  50. package/dist/primitives/shared.d.cts +2 -0
  51. package/dist/primitives/shared.d.cts.map +1 -1
  52. package/dist/primitives/shared.d.mts +2 -0
  53. package/dist/primitives/shared.d.mts.map +1 -1
  54. package/dist/primitives/shared.mjs.map +1 -1
  55. package/package.json +15 -8
  56. package/src/EffectSchema.ts +3 -3
  57. package/src/FractionalIndex.ts +18 -18
  58. package/src/Operation.ts +5 -5
  59. package/src/OperationDefinition.ts +2 -2
  60. package/src/Presence.ts +3 -3
  61. package/src/SchemaJSON.ts +396 -0
  62. package/src/index.ts +1 -0
  63. package/src/primitives/Array.ts +18 -8
  64. package/src/primitives/Boolean.ts +2 -2
  65. package/src/primitives/Either.ts +2 -2
  66. package/src/primitives/Literal.ts +2 -2
  67. package/src/primitives/Number.ts +44 -22
  68. package/src/primitives/String.ts +61 -34
  69. package/src/primitives/Union.ts +1 -1
  70. package/src/primitives/shared.ts +2 -0
  71. package/.turbo/turbo-build.log +0 -270
  72. package/tests/Document.test.ts +0 -557
  73. package/tests/EffectSchema.test.ts +0 -546
  74. package/tests/FractionalIndex.test.ts +0 -377
  75. package/tests/OperationPath.test.ts +0 -151
  76. package/tests/Presence.test.ts +0 -321
  77. package/tests/Primitive.test.ts +0 -381
  78. package/tests/client/ClientDocument.test.ts +0 -1981
  79. package/tests/client/WebSocketTransport.test.ts +0 -1217
  80. package/tests/primitives/Array.test.ts +0 -526
  81. package/tests/primitives/Boolean.test.ts +0 -126
  82. package/tests/primitives/Either.test.ts +0 -707
  83. package/tests/primitives/Lazy.test.ts +0 -143
  84. package/tests/primitives/Literal.test.ts +0 -122
  85. package/tests/primitives/Number.test.ts +0 -133
  86. package/tests/primitives/String.test.ts +0 -128
  87. package/tests/primitives/Struct.test.ts +0 -1154
  88. package/tests/primitives/Tree.test.ts +0 -1139
  89. package/tests/primitives/TreeNode.test.ts +0 -50
  90. package/tests/primitives/Union.test.ts +0 -554
  91. package/tests/server/ServerDocument.test.ts +0 -903
  92. package/tsconfig.build.json +0 -24
  93. package/tsconfig.json +0 -8
  94. package/tsdown.config.ts +0 -18
  95. package/vitest.mts +0 -11
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest";
2
- import * as Primitive from "../../src/Primitive";
3
- import * as ProxyEnvironment from "../../src/ProxyEnvironment";
4
- import * as OperationPath from "../../src/OperationPath";
5
- import * as Operation from "../../src/Operation";
6
-
7
- describe("TreeNodePrimitive", () => {
8
- it("creates a TreeNode with type, data, and empty children", () => {
9
- const FileNode = Primitive.TreeNode("file", {
10
- data: Primitive.Struct({ name: Primitive.String(), size: Primitive.Number() }),
11
- children: [],
12
- });
13
-
14
- expect(FileNode.type).toBe("file");
15
- expect(FileNode.data).toBeInstanceOf(Primitive.StructPrimitive);
16
- expect(FileNode.children).toEqual([]);
17
- });
18
-
19
- it("creates a TreeNode with lazy children for self-reference", () => {
20
- const FolderNode: Primitive.AnyTreeNodePrimitive = Primitive.TreeNode("folder", {
21
- data: Primitive.Struct({ name: Primitive.String() }),
22
- children: (): readonly Primitive.AnyTreeNodePrimitive[] => [FolderNode],
23
- });
24
-
25
- expect(FolderNode.type).toBe("folder");
26
- expect(FolderNode.children).toHaveLength(1);
27
- expect(FolderNode.children[0]).toBe(FolderNode);
28
- });
29
-
30
- it("isChildAllowed returns true for allowed child types", () => {
31
- const FileNode = Primitive.TreeNode("file", {
32
- data: Primitive.Struct({ name: Primitive.String() }),
33
- children: [],
34
- });
35
-
36
- const FolderNode: Primitive.AnyTreeNodePrimitive = Primitive.TreeNode("folder", {
37
- data: Primitive.Struct({ name: Primitive.String() }),
38
- children: (): readonly Primitive.AnyTreeNodePrimitive[] => [FolderNode, FileNode],
39
- });
40
-
41
- expect(FolderNode.isChildAllowed("folder")).toBe(true);
42
- expect(FolderNode.isChildAllowed("file")).toBe(true);
43
- expect(FolderNode.isChildAllowed("unknown")).toBe(false);
44
- expect(FileNode.isChildAllowed("file")).toBe(false);
45
- });
46
- });
47
-
48
- // =============================================================================
49
- // Tree Primitive Tests
50
- // =============================================================================
@@ -1,554 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest";
2
- import * as Primitive from "../../src/Primitive";
3
- import * as ProxyEnvironment from "../../src/ProxyEnvironment";
4
- import * as OperationPath from "../../src/OperationPath";
5
- import * as Operation from "../../src/Operation";
6
-
7
- describe("UnionPrimitive", () => {
8
- const TextVariant = Primitive.Struct({
9
- type: Primitive.Literal("text" as const),
10
- content: Primitive.String(),
11
- });
12
-
13
- const NumberVariant = Primitive.Struct({
14
- type: Primitive.Literal("number" as const),
15
- value: Primitive.Number(),
16
- });
17
-
18
- const unionPrimitive = Primitive.Union({
19
- variants: {
20
- text: TextVariant,
21
- number: NumberVariant,
22
- },
23
- });
24
-
25
- describe("proxy", () => {
26
- it("set() generates correct operation", () => {
27
- const operations: Operation.Operation<any, any, any>[] = [];
28
- const env = ProxyEnvironment.make((op) => operations.push(op));
29
-
30
- const proxy = unionPrimitive._internal.createProxy(env, OperationPath.make(""));
31
-
32
- proxy.set({ type: "text", content: "Hello" });
33
-
34
- expect(operations).toHaveLength(1);
35
- expect(operations[0]!.kind).toBe("union.set");
36
- expect(operations[0]!.payload).toEqual({ type: "text", content: "Hello" });
37
- });
38
-
39
- it("as() returns variant proxy", () => {
40
- const operations: Operation.Operation<any, any, any>[] = [];
41
- const env = ProxyEnvironment.make((op) => operations.push(op));
42
-
43
- const proxy = unionPrimitive._internal.createProxy(env, OperationPath.make(""));
44
-
45
- proxy.as("text").content.set("Updated content");
46
-
47
- expect(operations).toHaveLength(1);
48
- expect(operations[0]!.kind).toBe("string.set");
49
- expect(operations[0]!.path.toTokens()).toEqual(["content"]);
50
- });
51
-
52
- it("as() with different variant", () => {
53
- const operations: Operation.Operation<any, any, any>[] = [];
54
- const env = ProxyEnvironment.make((op) => operations.push(op));
55
-
56
- const proxy = unionPrimitive._internal.createProxy(env, OperationPath.make(""));
57
-
58
- proxy.as("number").value.set(42);
59
-
60
- expect(operations).toHaveLength(1);
61
- expect(operations[0]!.kind).toBe("number.set");
62
- expect(operations[0]!.payload).toBe(42);
63
- });
64
-
65
- it("as() throws for unknown variant", () => {
66
- const env = ProxyEnvironment.make(() => {});
67
- const proxy = unionPrimitive._internal.createProxy(env, OperationPath.make(""));
68
-
69
- expect(() => proxy.as("unknown" as any)).toThrow(Primitive.ValidationError);
70
- });
71
- });
72
-
73
- describe("applyOperation", () => {
74
- it("union.set replaces entire value", () => {
75
- const operation: Operation.Operation<any, any, any> = {
76
- kind: "union.set",
77
- path: OperationPath.make(""),
78
- payload: { type: "text", content: "New text" },
79
- };
80
-
81
- const result = unionPrimitive._internal.applyOperation(undefined, operation);
82
- expect(result).toEqual({ type: "text", content: "New text" });
83
- });
84
-
85
- it("union.set can change variant type", () => {
86
- const operation: Operation.Operation<any, any, any> = {
87
- kind: "union.set",
88
- path: OperationPath.make(""),
89
- payload: { type: "number", value: 100 },
90
- };
91
-
92
- const currentState = { type: "text" as const, content: "old" };
93
- const result = unionPrimitive._internal.applyOperation(currentState, operation);
94
- expect(result).toEqual({ type: "number", value: 100 });
95
- });
96
-
97
- it("delegates field operations to active variant", () => {
98
- const operation: Operation.Operation<any, any, any> = {
99
- kind: "string.set",
100
- path: OperationPath.make("content"),
101
- payload: "Updated",
102
- };
103
-
104
- const currentState = { type: "text" as const, content: "Original" };
105
- const result = unionPrimitive._internal.applyOperation(currentState, operation);
106
- expect(result).toEqual({ type: "text", content: "Updated" });
107
- });
108
-
109
- it("throws ValidationError for non-object payload on set", () => {
110
- const operation: Operation.Operation<any, any, any> = {
111
- kind: "union.set",
112
- path: OperationPath.make(""),
113
- payload: "not an object",
114
- };
115
-
116
- expect(() => unionPrimitive._internal.applyOperation(undefined, operation)).toThrow(
117
- Primitive.ValidationError
118
- );
119
- });
120
-
121
- it("throws ValidationError for missing discriminator", () => {
122
- const operation: Operation.Operation<any, any, any> = {
123
- kind: "union.set",
124
- path: OperationPath.make(""),
125
- payload: { content: "no type field" },
126
- };
127
-
128
- expect(() => unionPrimitive._internal.applyOperation(undefined, operation)).toThrow(
129
- Primitive.ValidationError
130
- );
131
- });
132
-
133
- it("throws ValidationError for nested operation on undefined state", () => {
134
- const operation: Operation.Operation<any, any, any> = {
135
- kind: "string.set",
136
- path: OperationPath.make("content"),
137
- payload: "value",
138
- };
139
-
140
- expect(() => unionPrimitive._internal.applyOperation(undefined, operation)).toThrow(
141
- Primitive.ValidationError
142
- );
143
- });
144
- });
145
-
146
- describe("getInitialState", () => {
147
- it("returns undefined when no default is set", () => {
148
- expect(unionPrimitive._internal.getInitialState()).toBeUndefined();
149
- });
150
-
151
- it("returns the default value when set", () => {
152
- const withDefault = unionPrimitive.default({ type: "text", content: "default" });
153
- expect(withDefault._internal.getInitialState()).toEqual({
154
- type: "text",
155
- content: "default",
156
- });
157
- });
158
-
159
- it("return correct defaults for nested structs when global default is set", () => {
160
- const stringVariableTypeSchema = Primitive.Struct({
161
- key: Primitive.Literal("string"),
162
- value: Primitive.String(),
163
- });
164
-
165
- const numberVariableTypeSchema = Primitive.Struct({
166
- key: Primitive.Literal("number"),
167
- value: Primitive.Number(),
168
- });
169
-
170
-
171
- const variableTypeSchema = Primitive.Union({
172
- discriminator: "key",
173
- variants: {
174
- string: stringVariableTypeSchema,
175
- number: numberVariableTypeSchema,
176
- },
177
- }).default({
178
- key: "string",
179
- value: "",
180
- });
181
-
182
- expect(variableTypeSchema._internal.getInitialState()).toEqual({
183
- key: "string",
184
- value: "",
185
- });
186
- });
187
-
188
- it("return correct defaults for nested structs when variant default is set", () => {
189
- const stringVariableTypeSchema = Primitive.Struct({
190
- key: Primitive.Literal("string"),
191
- value: Primitive.String().default(""),
192
- });
193
-
194
- const numberVariableTypeSchema = Primitive.Struct({
195
- key: Primitive.Literal("number"),
196
- value: Primitive.Number().default(10),
197
- });
198
-
199
-
200
- const variableTypeSchema = Primitive.Union({
201
- discriminator: "key",
202
- variants: {
203
- string: stringVariableTypeSchema,
204
- number: numberVariableTypeSchema,
205
- },
206
- }).default({
207
- key: "number",
208
- });
209
-
210
- expect(variableTypeSchema._internal.getInitialState()).toEqual({
211
- key: "number",
212
- value: 10,
213
- });
214
- });
215
-
216
- it("set() applies defaults to generated operation payload", () => {
217
- const stringVariableTypeSchema = Primitive.Struct({
218
- key: Primitive.Literal("string"),
219
- value: Primitive.String().default(""),
220
- });
221
-
222
- const numberVariableTypeSchema = Primitive.Struct({
223
- key: Primitive.Literal("number"),
224
- value: Primitive.Number().default(10),
225
- });
226
-
227
-
228
- const variableTypeSchema = Primitive.Union({
229
- discriminator: "key",
230
- variants: {
231
- string: stringVariableTypeSchema,
232
- number: numberVariableTypeSchema,
233
- },
234
- });
235
-
236
- const operations: Operation.Operation<any, any, any>[] = [];
237
- const proxy = variableTypeSchema._internal.createProxy(ProxyEnvironment.make((op) => operations.push(op)), OperationPath.make(""));
238
- proxy.set({ key: "number" });
239
-
240
- expect(operations).toHaveLength(1);
241
- expect(operations[0]!.kind).toBe("union.set");
242
- expect(operations[0]!.payload).toEqual({
243
- key: "number",
244
- value: 10,
245
- });
246
- });
247
- });
248
-
249
- describe("custom discriminator", () => {
250
- it("supports custom discriminator field", () => {
251
- const KindVariantA = Primitive.Struct({
252
- kind: Primitive.Literal("a" as const),
253
- data: Primitive.String(),
254
- });
255
-
256
- const KindVariantB = Primitive.Struct({
257
- kind: Primitive.Literal("b" as const),
258
- count: Primitive.Number(),
259
- });
260
-
261
- const customUnion = Primitive.Union({
262
- discriminator: "kind",
263
- variants: {
264
- a: KindVariantA,
265
- b: KindVariantB,
266
- },
267
- });
268
-
269
- expect(customUnion.discriminator).toBe("kind");
270
-
271
- const operation: Operation.Operation<any, any, any> = {
272
- kind: "string.set",
273
- path: OperationPath.make("data"),
274
- payload: "Updated data",
275
- };
276
-
277
- const currentState = { kind: "a" as const, data: "original" };
278
- const result = customUnion._internal.applyOperation(currentState, operation);
279
- expect(result).toEqual({ kind: "a", data: "Updated data" });
280
- });
281
- });
282
-
283
- describe("type inference", () => {
284
- it("infers correct state type from union definition", () => {
285
- type ExpectedState = Primitive.InferState<typeof unionPrimitive>;
286
-
287
- // This is a compile-time check
288
- const textState: ExpectedState = { type: "text", content: "hello" };
289
- const numberState: ExpectedState = { type: "number", value: 42 };
290
-
291
- expect(textState.type).toBe("text");
292
- expect(numberState.type).toBe("number");
293
- });
294
- });
295
- });
296
-
297
- // =============================================================================
298
- // Integration Tests - Complex Nested Structures
299
- // =============================================================================
300
-
301
- describe("Union defaults in nested structures", () => {
302
- // Schema matching the production use case
303
- const stringVariableTypeSchema = Primitive.Struct({
304
- key: Primitive.Literal("string"),
305
- value: Primitive.String().default(""),
306
- });
307
-
308
- const numberVariableTypeSchema = Primitive.Struct({
309
- key: Primitive.Literal("number"),
310
- value: Primitive.Number().default(0),
311
- });
312
-
313
- const booleanVariableTypeSchema = Primitive.Struct({
314
- key: Primitive.Literal("boolean"),
315
- value: Primitive.Boolean().default(false),
316
- });
317
-
318
- const productVariableTypeSchema = Primitive.Struct({
319
- key: Primitive.Literal("product"),
320
- value: Primitive.Struct({
321
- productId: Primitive.Either(
322
- Primitive.String(),
323
- Primitive.Literal(null),
324
- ),
325
- }).default({
326
- productId: null,
327
- }),
328
- });
329
-
330
- const variableTypeSchema = Primitive.Union({
331
- discriminator: "key",
332
- variants: {
333
- string: stringVariableTypeSchema,
334
- number: numberVariableTypeSchema,
335
- boolean: booleanVariableTypeSchema,
336
- product: productVariableTypeSchema,
337
- },
338
- });
339
-
340
- const variableSchema = Primitive.Struct({
341
- id: Primitive.String(),
342
- name: Primitive.String(),
343
- value: variableTypeSchema,
344
- });
345
-
346
- describe("Struct.set() with nested Union", () => {
347
- it("applies Union variant defaults when setting partial Union value", () => {
348
- const operations: Operation.Operation<any, any, any>[] = [];
349
- const env = ProxyEnvironment.make((op) => operations.push(op));
350
- const proxy = variableSchema._internal.createProxy(env, OperationPath.make(""));
351
-
352
- proxy.set({
353
- id: "var-1",
354
- name: "test",
355
- value: { key: "number" },
356
- });
357
-
358
- expect(operations).toHaveLength(1);
359
- expect(operations[0]!.kind).toBe("struct.set");
360
- expect(operations[0]!.payload).toEqual({
361
- id: "var-1",
362
- name: "test",
363
- value: {
364
- key: "number",
365
- value: 0,
366
- },
367
- });
368
- });
369
-
370
- it("applies Union variant defaults for string type", () => {
371
- const operations: Operation.Operation<any, any, any>[] = [];
372
- const env = ProxyEnvironment.make((op) => operations.push(op));
373
- const proxy = variableSchema._internal.createProxy(env, OperationPath.make(""));
374
-
375
- proxy.set({
376
- id: "var-1",
377
- name: "test",
378
- value: { key: "string" },
379
- });
380
-
381
- expect(operations[0]!.payload).toEqual({
382
- id: "var-1",
383
- name: "test",
384
- value: {
385
- key: "string",
386
- value: "",
387
- },
388
- });
389
- });
390
-
391
- it("applies Union variant defaults for boolean type", () => {
392
- const operations: Operation.Operation<any, any, any>[] = [];
393
- const env = ProxyEnvironment.make((op) => operations.push(op));
394
- const proxy = variableSchema._internal.createProxy(env, OperationPath.make(""));
395
-
396
- proxy.set({
397
- id: "var-1",
398
- name: "test",
399
- value: { key: "boolean" },
400
- });
401
-
402
- expect(operations[0]!.payload).toEqual({
403
- id: "var-1",
404
- name: "test",
405
- value: {
406
- key: "boolean",
407
- value: false,
408
- },
409
- });
410
- });
411
-
412
- it("applies Union variant defaults for nested struct (product type)", () => {
413
- const operations: Operation.Operation<any, any, any>[] = [];
414
- const env = ProxyEnvironment.make((op) => operations.push(op));
415
- const proxy = variableSchema._internal.createProxy(env, OperationPath.make(""));
416
-
417
- proxy.set({
418
- id: "var-1",
419
- name: "test",
420
- value: { key: "product" },
421
- });
422
-
423
- expect(operations[0]!.payload).toEqual({
424
- id: "var-1",
425
- name: "test",
426
- value: {
427
- key: "product",
428
- value: {
429
- productId: null,
430
- },
431
- },
432
- });
433
- });
434
-
435
- it("preserves explicitly provided Union values", () => {
436
- const operations: Operation.Operation<any, any, any>[] = [];
437
- const env = ProxyEnvironment.make((op) => operations.push(op));
438
- const proxy = variableSchema._internal.createProxy(env, OperationPath.make(""));
439
-
440
- proxy.set({
441
- id: "var-1",
442
- name: "test",
443
- value: { key: "number", value: 42 },
444
- });
445
-
446
- expect(operations[0]!.payload).toEqual({
447
- id: "var-1",
448
- name: "test",
449
- value: {
450
- key: "number",
451
- value: 42,
452
- },
453
- });
454
- });
455
- });
456
-
457
- describe("Array.push() with Struct containing Union", () => {
458
- const variablesArraySchema = Primitive.Array(variableSchema);
459
-
460
- it("applies Union variant defaults when pushing with partial Union value", () => {
461
- const operations: Operation.Operation<any, any, any>[] = [];
462
- const env = ProxyEnvironment.make((op) => operations.push(op));
463
- const proxy = variablesArraySchema._internal.createProxy(env, OperationPath.make(""));
464
-
465
- proxy.push({
466
- id: "var-1",
467
- name: "test",
468
- value: { key: "number" },
469
- });
470
-
471
- expect(operations).toHaveLength(1);
472
- expect(operations[0]!.kind).toBe("array.insert");
473
- expect(operations[0]!.payload.value).toEqual({
474
- id: "var-1",
475
- name: "test",
476
- value: {
477
- key: "number",
478
- value: 0,
479
- },
480
- });
481
- });
482
-
483
- it("applies Union variant defaults for all variant types", () => {
484
- const operations: Operation.Operation<any, any, any>[] = [];
485
- const env = ProxyEnvironment.make((op) => operations.push(op));
486
- const proxy = variablesArraySchema._internal.createProxy(env, OperationPath.make(""));
487
-
488
- proxy.push({ id: "var-1", name: "str", value: { key: "string" } });
489
- proxy.push({ id: "var-2", name: "num", value: { key: "number" } });
490
- proxy.push({ id: "var-3", name: "bool", value: { key: "boolean" } });
491
- proxy.push({ id: "var-4", name: "prod", value: { key: "product" } });
492
-
493
- expect(operations[0]!.payload.value.value).toEqual({ key: "string", value: "" });
494
- expect(operations[1]!.payload.value.value).toEqual({ key: "number", value: 0 });
495
- expect(operations[2]!.payload.value.value).toEqual({ key: "boolean", value: false });
496
- expect(operations[3]!.payload.value.value).toEqual({ key: "product", value: { productId: null } });
497
- });
498
- });
499
-
500
- describe("Array.set() with Struct containing Union", () => {
501
- const variablesArraySchema = Primitive.Array(variableSchema);
502
-
503
- it("applies Union variant defaults when setting array with partial Union values", () => {
504
- const operations: Operation.Operation<any, any, any>[] = [];
505
- const env = ProxyEnvironment.make((op) => operations.push(op));
506
- const proxy = variablesArraySchema._internal.createProxy(env, OperationPath.make(""));
507
-
508
- proxy.set([
509
- { id: "var-1", name: "str", value: { key: "string" } },
510
- { id: "var-2", name: "num", value: { key: "number" } },
511
- ]);
512
-
513
- expect(operations).toHaveLength(1);
514
- expect(operations[0]!.kind).toBe("array.set");
515
- expect(operations[0]!.payload[0].value).toEqual({
516
- id: "var-1",
517
- name: "str",
518
- value: { key: "string", value: "" },
519
- });
520
- expect(operations[0]!.payload[1].value).toEqual({
521
- id: "var-2",
522
- name: "num",
523
- value: { key: "number", value: 0 },
524
- });
525
- });
526
- });
527
-
528
- describe("Array.insertAt() with Struct containing Union", () => {
529
- const variablesArraySchema = Primitive.Array(variableSchema);
530
-
531
- it("applies Union variant defaults when inserting with partial Union value", () => {
532
- const operations: Operation.Operation<any, any, any>[] = [];
533
- const env = ProxyEnvironment.make((op) => operations.push(op));
534
- const proxy = variablesArraySchema._internal.createProxy(env, OperationPath.make(""));
535
-
536
- proxy.insertAt(0, {
537
- id: "var-1",
538
- name: "test",
539
- value: { key: "boolean" },
540
- });
541
-
542
- expect(operations).toHaveLength(1);
543
- expect(operations[0]!.kind).toBe("array.insert");
544
- expect(operations[0]!.payload.value).toEqual({
545
- id: "var-1",
546
- name: "test",
547
- value: {
548
- key: "boolean",
549
- value: false,
550
- },
551
- });
552
- });
553
- });
554
- });