@voidhash/mimic 1.0.0-beta.15 → 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 (112) hide show
  1. package/dist/Document.cjs +0 -3
  2. package/dist/Document.d.mts.map +1 -1
  3. package/dist/Document.mjs +0 -3
  4. package/dist/Document.mjs.map +1 -1
  5. package/dist/EffectSchema.cjs +3 -3
  6. package/dist/EffectSchema.d.cts +5 -5
  7. package/dist/EffectSchema.d.cts.map +1 -1
  8. package/dist/EffectSchema.d.mts +5 -5
  9. package/dist/EffectSchema.d.mts.map +1 -1
  10. package/dist/EffectSchema.mjs +3 -3
  11. package/dist/EffectSchema.mjs.map +1 -1
  12. package/dist/FractionalIndex.mjs.map +1 -1
  13. package/dist/Operation.d.cts +4 -4
  14. package/dist/Operation.d.cts.map +1 -1
  15. package/dist/Operation.d.mts +4 -4
  16. package/dist/Operation.d.mts.map +1 -1
  17. package/dist/Operation.mjs.map +1 -1
  18. package/dist/OperationDefinition.d.cts +2 -2
  19. package/dist/OperationDefinition.d.cts.map +1 -1
  20. package/dist/OperationDefinition.d.mts +2 -2
  21. package/dist/OperationDefinition.d.mts.map +1 -1
  22. package/dist/OperationDefinition.mjs.map +1 -1
  23. package/dist/Presence.mjs.map +1 -1
  24. package/dist/Primitive.d.cts +2 -2
  25. package/dist/Primitive.d.mts +2 -2
  26. package/dist/SchemaJSON.cjs +305 -0
  27. package/dist/SchemaJSON.d.cts +11 -0
  28. package/dist/SchemaJSON.d.cts.map +1 -0
  29. package/dist/SchemaJSON.d.mts +11 -0
  30. package/dist/SchemaJSON.d.mts.map +1 -0
  31. package/dist/SchemaJSON.mjs +301 -0
  32. package/dist/SchemaJSON.mjs.map +1 -0
  33. package/dist/index.cjs +7 -0
  34. package/dist/index.d.cts +2 -1
  35. package/dist/index.d.mts +2 -1
  36. package/dist/index.mjs +2 -1
  37. package/dist/primitives/Array.cjs +12 -2
  38. package/dist/primitives/Array.d.cts.map +1 -1
  39. package/dist/primitives/Array.d.mts.map +1 -1
  40. package/dist/primitives/Array.mjs +12 -2
  41. package/dist/primitives/Array.mjs.map +1 -1
  42. package/dist/primitives/Boolean.mjs.map +1 -1
  43. package/dist/primitives/Either.mjs.map +1 -1
  44. package/dist/primitives/Literal.mjs.map +1 -1
  45. package/dist/primitives/Number.cjs +27 -5
  46. package/dist/primitives/Number.d.cts.map +1 -1
  47. package/dist/primitives/Number.d.mts.map +1 -1
  48. package/dist/primitives/Number.mjs +27 -5
  49. package/dist/primitives/Number.mjs.map +1 -1
  50. package/dist/primitives/String.cjs +44 -13
  51. package/dist/primitives/String.d.cts.map +1 -1
  52. package/dist/primitives/String.d.mts.map +1 -1
  53. package/dist/primitives/String.mjs +44 -13
  54. package/dist/primitives/String.mjs.map +1 -1
  55. package/dist/primitives/Struct.cjs +48 -9
  56. package/dist/primitives/Struct.d.cts +22 -3
  57. package/dist/primitives/Struct.d.cts.map +1 -1
  58. package/dist/primitives/Struct.d.mts +22 -3
  59. package/dist/primitives/Struct.d.mts.map +1 -1
  60. package/dist/primitives/Struct.mjs +48 -9
  61. package/dist/primitives/Struct.mjs.map +1 -1
  62. package/dist/primitives/Union.mjs.map +1 -1
  63. package/dist/primitives/shared.cjs +2 -5
  64. package/dist/primitives/shared.d.cts +2 -4
  65. package/dist/primitives/shared.d.cts.map +1 -1
  66. package/dist/primitives/shared.d.mts +2 -4
  67. package/dist/primitives/shared.d.mts.map +1 -1
  68. package/dist/primitives/shared.mjs +2 -5
  69. package/dist/primitives/shared.mjs.map +1 -1
  70. package/package.json +15 -8
  71. package/src/Document.ts +13 -4
  72. package/src/EffectSchema.ts +3 -3
  73. package/src/FractionalIndex.ts +18 -18
  74. package/src/Operation.ts +5 -5
  75. package/src/OperationDefinition.ts +2 -2
  76. package/src/Presence.ts +3 -3
  77. package/src/SchemaJSON.ts +396 -0
  78. package/src/index.ts +1 -0
  79. package/src/primitives/Array.ts +18 -8
  80. package/src/primitives/Boolean.ts +2 -2
  81. package/src/primitives/Either.ts +2 -2
  82. package/src/primitives/Literal.ts +2 -2
  83. package/src/primitives/Number.ts +44 -22
  84. package/src/primitives/String.ts +61 -34
  85. package/src/primitives/Struct.ts +100 -12
  86. package/src/primitives/Union.ts +1 -1
  87. package/src/primitives/shared.ts +12 -2
  88. package/.turbo/turbo-build.log +0 -270
  89. package/tests/Document.test.ts +0 -557
  90. package/tests/EffectSchema.test.ts +0 -546
  91. package/tests/FractionalIndex.test.ts +0 -377
  92. package/tests/OperationPath.test.ts +0 -151
  93. package/tests/Presence.test.ts +0 -321
  94. package/tests/Primitive.test.ts +0 -381
  95. package/tests/client/ClientDocument.test.ts +0 -1981
  96. package/tests/client/WebSocketTransport.test.ts +0 -1217
  97. package/tests/primitives/Array.test.ts +0 -526
  98. package/tests/primitives/Boolean.test.ts +0 -126
  99. package/tests/primitives/Either.test.ts +0 -707
  100. package/tests/primitives/Lazy.test.ts +0 -143
  101. package/tests/primitives/Literal.test.ts +0 -122
  102. package/tests/primitives/Number.test.ts +0 -133
  103. package/tests/primitives/String.test.ts +0 -128
  104. package/tests/primitives/Struct.test.ts +0 -1044
  105. package/tests/primitives/Tree.test.ts +0 -1139
  106. package/tests/primitives/TreeNode.test.ts +0 -50
  107. package/tests/primitives/Union.test.ts +0 -554
  108. package/tests/server/ServerDocument.test.ts +0 -903
  109. package/tsconfig.build.json +0 -24
  110. package/tsconfig.json +0 -8
  111. package/tsdown.config.ts +0 -18
  112. package/vitest.mts +0 -11
@@ -1,143 +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("LazyPrimitive", () => {
8
- describe("proxy", () => {
9
- it("delegates proxy creation to resolved primitive", () => {
10
- const operations: Operation.Operation<any, any, any>[] = [];
11
- const env = ProxyEnvironment.make((op) => operations.push(op));
12
-
13
- const lazyPrimitive = Primitive.Lazy(() => Primitive.String());
14
- const proxy = lazyPrimitive._internal.createProxy(env, OperationPath.make(""));
15
-
16
- proxy.set("lazy value");
17
-
18
- expect(operations).toHaveLength(1);
19
- expect(operations[0]!.kind).toBe("string.set");
20
- expect(operations[0]!.payload).toBe("lazy value");
21
- });
22
-
23
- it("works with lazy struct", () => {
24
- const operations: Operation.Operation<any, any, any>[] = [];
25
- const env = ProxyEnvironment.make((op) => operations.push(op));
26
-
27
- const lazyPrimitive = Primitive.Lazy(() =>
28
- Primitive.Struct({
29
- name: Primitive.String(),
30
- })
31
- );
32
- const proxy = lazyPrimitive._internal.createProxy(env, OperationPath.make(""));
33
-
34
- proxy.name.set("lazy struct field");
35
-
36
- expect(operations).toHaveLength(1);
37
- expect(operations[0]!.kind).toBe("string.set");
38
- expect(operations[0]!.path.toTokens()).toEqual(["name"]);
39
- });
40
- });
41
-
42
- describe("applyOperation", () => {
43
- it("delegates operation application to resolved primitive", () => {
44
- const lazyPrimitive = Primitive.Lazy(() => Primitive.String());
45
- const operation: Operation.Operation<any, any, any> = {
46
- kind: "string.set",
47
- path: OperationPath.make(""),
48
- payload: "lazy applied",
49
- };
50
-
51
- const result = lazyPrimitive._internal.applyOperation(undefined, operation);
52
- expect(result).toBe("lazy applied");
53
- });
54
-
55
- it("works with lazy struct operations", () => {
56
- const lazyPrimitive = Primitive.Lazy(() =>
57
- Primitive.Struct({
58
- name: Primitive.String(),
59
- })
60
- );
61
- const operation: Operation.Operation<any, any, any> = {
62
- kind: "string.set",
63
- path: OperationPath.make("name"),
64
- payload: "Updated",
65
- };
66
-
67
- const result = lazyPrimitive._internal.applyOperation({ name: "Original" }, operation);
68
- expect(result).toEqual({ name: "Updated" });
69
- });
70
- });
71
-
72
- describe("getInitialState", () => {
73
- it("delegates to resolved primitive", () => {
74
- const lazyPrimitive = Primitive.Lazy(() => Primitive.String().default("lazy default"));
75
- expect(lazyPrimitive._internal.getInitialState()).toBe("lazy default");
76
- });
77
-
78
- it("returns undefined when resolved primitive has no default", () => {
79
- const lazyPrimitive = Primitive.Lazy(() => Primitive.String());
80
- expect(lazyPrimitive._internal.getInitialState()).toBeUndefined();
81
- });
82
- });
83
-
84
- describe("recursive structures", () => {
85
- it("supports self-referential structures", () => {
86
- const operations: Operation.Operation<any, any, any>[] = [];
87
- const env = ProxyEnvironment.make((op) => operations.push(op));
88
-
89
- // Define a recursive node structure
90
- const Node: Primitive.LazyPrimitive<any> = Primitive.Lazy(() =>
91
- Primitive.Struct({
92
- name: Primitive.String(),
93
- children: Primitive.Array(Node),
94
- })
95
- );
96
-
97
- const proxy = Node._internal.createProxy(env, OperationPath.make("")) as any;
98
-
99
- // Access nested child
100
- proxy.children.at(0).name.set("Child Name");
101
-
102
- expect(operations).toHaveLength(1);
103
- expect(operations[0]!.kind).toBe("string.set");
104
- expect(operations[0]!.path.toTokens()).toEqual(["children", "0", "name"]);
105
- });
106
-
107
- it("applies operations to recursive structures", () => {
108
- const Node: Primitive.LazyPrimitive<any> = Primitive.Lazy(() =>
109
- Primitive.Struct({
110
- name: Primitive.String(),
111
- children: Primitive.Array(Node),
112
- })
113
- );
114
-
115
- // Use entry ID in path (arrays now use ID-based addressing)
116
- const operation: Operation.Operation<any, any, any> = {
117
- kind: "string.set",
118
- path: OperationPath.make("children/child-entry-1/name"),
119
- payload: "Updated Child",
120
- };
121
-
122
- // State with array entries format { id, pos, value }
123
- const state = {
124
- name: "Root",
125
- children: [
126
- { id: "child-entry-1", pos: "a0", value: { name: "Child", children: [] } }
127
- ],
128
- };
129
-
130
- const result = Node._internal.applyOperation(state, operation);
131
- expect(result).toEqual({
132
- name: "Root",
133
- children: [
134
- { id: "child-entry-1", pos: "a0", value: { name: "Updated Child", children: [] } }
135
- ],
136
- });
137
- });
138
- });
139
- });
140
-
141
- // =============================================================================
142
- // Union Primitive Tests
143
- // =============================================================================
@@ -1,122 +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("LiteralPrimitive", () => {
8
- describe("proxy", () => {
9
- it("set() generates correct operation with string literal", () => {
10
- const operations: Operation.Operation<any, any, any>[] = [];
11
- const env = ProxyEnvironment.make((op) => operations.push(op));
12
-
13
- const literalPrimitive = Primitive.Literal("active" as const);
14
- const proxy = literalPrimitive._internal.createProxy(env, OperationPath.make(""));
15
-
16
- proxy.set("active");
17
-
18
- expect(operations).toHaveLength(1);
19
- expect(operations[0]!.kind).toBe("literal.set");
20
- expect(operations[0]!.payload).toBe("active");
21
- });
22
-
23
- it("set() generates correct operation with number literal", () => {
24
- const operations: Operation.Operation<any, any, any>[] = [];
25
- const env = ProxyEnvironment.make((op) => operations.push(op));
26
-
27
- const literalPrimitive = Primitive.Literal(42 as const);
28
- const proxy = literalPrimitive._internal.createProxy(env, OperationPath.make(""));
29
-
30
- proxy.set(42);
31
-
32
- expect(operations[0]!.payload).toBe(42);
33
- });
34
-
35
- it("set() generates correct operation with boolean literal", () => {
36
- const operations: Operation.Operation<any, any, any>[] = [];
37
- const env = ProxyEnvironment.make((op) => operations.push(op));
38
-
39
- const literalPrimitive = Primitive.Literal(true as const);
40
- const proxy = literalPrimitive._internal.createProxy(env, OperationPath.make(""));
41
-
42
- proxy.set(true);
43
-
44
- expect(operations[0]!.payload).toBe(true);
45
- });
46
-
47
- it("set() generates correct operation with null literal", () => {
48
- const operations: Operation.Operation<any, any, any>[] = [];
49
- const env = ProxyEnvironment.make((op) => operations.push(op));
50
-
51
- const literalPrimitive = Primitive.Literal(null);
52
- const proxy = literalPrimitive._internal.createProxy(env, OperationPath.make(""));
53
-
54
- proxy.set(null);
55
-
56
- expect(operations[0]!.payload).toBe(null);
57
- });
58
- });
59
-
60
- describe("applyOperation", () => {
61
- it("returns the literal value from literal.set operation", () => {
62
- const literalPrimitive = Primitive.Literal("foo" as const);
63
- const operation: Operation.Operation<any, any, any> = {
64
- kind: "literal.set",
65
- path: OperationPath.make(""),
66
- payload: "foo",
67
- };
68
-
69
- const result = literalPrimitive._internal.applyOperation(undefined, operation);
70
- expect(result).toBe("foo");
71
- });
72
-
73
- it("throws ValidationError for wrong literal value", () => {
74
- const literalPrimitive = Primitive.Literal("foo" as const);
75
- const operation: Operation.Operation<any, any, any> = {
76
- kind: "literal.set",
77
- path: OperationPath.make(""),
78
- payload: "bar",
79
- };
80
-
81
- expect(() => literalPrimitive._internal.applyOperation(undefined, operation)).toThrow(
82
- Primitive.ValidationError
83
- );
84
- });
85
-
86
- it("throws ValidationError for wrong operation kind", () => {
87
- const literalPrimitive = Primitive.Literal("foo" as const);
88
- const operation: Operation.Operation<any, any, any> = {
89
- kind: "string.set",
90
- path: OperationPath.make(""),
91
- payload: "foo",
92
- };
93
-
94
- expect(() => literalPrimitive._internal.applyOperation(undefined, operation)).toThrow(
95
- Primitive.ValidationError
96
- );
97
- });
98
- });
99
-
100
- describe("getInitialState", () => {
101
- it("returns undefined when no default is set", () => {
102
- const literalPrimitive = Primitive.Literal("test" as const);
103
- expect(literalPrimitive._internal.getInitialState()).toBeUndefined();
104
- });
105
-
106
- it("returns the default value when set", () => {
107
- const literalPrimitive = Primitive.Literal("active" as const).default("active");
108
- expect(literalPrimitive._internal.getInitialState()).toBe("active");
109
- });
110
- });
111
-
112
- describe("literal accessor", () => {
113
- it("returns the literal value", () => {
114
- const literalPrimitive = Primitive.Literal("myLiteral" as const);
115
- expect(literalPrimitive.literal).toBe("myLiteral");
116
- });
117
- });
118
- });
119
-
120
- // =============================================================================
121
- // Struct Primitive Tests
122
- // =============================================================================
@@ -1,133 +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("NumberPrimitive", () => {
8
- describe("proxy", () => {
9
- it("set() generates correct operation with path and payload", () => {
10
- const operations: Operation.Operation<any, any, any>[] = [];
11
- const env = ProxyEnvironment.make((op) => operations.push(op));
12
-
13
- const numberPrimitive = Primitive.Number().required();
14
- const proxy = numberPrimitive._internal.createProxy(env, OperationPath.make(""));
15
-
16
- proxy.set(42);
17
-
18
- expect(operations).toHaveLength(1);
19
- expect(operations[0]!.kind).toBe("number.set");
20
- expect(operations[0]!.payload).toBe(42);
21
- });
22
-
23
- it("set() works with decimal numbers", () => {
24
- const operations: Operation.Operation<any, any, any>[] = [];
25
- const env = ProxyEnvironment.make((op) => operations.push(op));
26
-
27
- const numberPrimitive = Primitive.Number();
28
- const proxy = numberPrimitive._internal.createProxy(env, OperationPath.make(""));
29
-
30
- proxy.set(3.14159);
31
-
32
- expect(operations[0]!.payload).toBe(3.14159);
33
- });
34
-
35
- it("set() works with negative numbers", () => {
36
- const operations: Operation.Operation<any, any, any>[] = [];
37
- const env = ProxyEnvironment.make((op) => operations.push(op));
38
-
39
- const numberPrimitive = Primitive.Number();
40
- const proxy = numberPrimitive._internal.createProxy(env, OperationPath.make(""));
41
-
42
- proxy.set(-100);
43
-
44
- expect(operations[0]!.payload).toBe(-100);
45
- });
46
- });
47
-
48
- describe("applyOperation", () => {
49
- it("returns the new number value from number.set operation", () => {
50
- const numberPrimitive = Primitive.Number();
51
- const operation: Operation.Operation<any, any, any> = {
52
- kind: "number.set",
53
- path: OperationPath.make(""),
54
- payload: 123,
55
- };
56
-
57
- const result = numberPrimitive._internal.applyOperation(undefined, operation);
58
- expect(result).toBe(123);
59
- });
60
-
61
- it("replaces existing state with new value", () => {
62
- const numberPrimitive = Primitive.Number();
63
- const operation: Operation.Operation<any, any, any> = {
64
- kind: "number.set",
65
- path: OperationPath.make(""),
66
- payload: 999,
67
- };
68
-
69
- const result = numberPrimitive._internal.applyOperation(100, operation);
70
- expect(result).toBe(999);
71
- });
72
-
73
- it("throws ValidationError for non-number payload", () => {
74
- const numberPrimitive = Primitive.Number();
75
- const operation: Operation.Operation<any, any, any> = {
76
- kind: "number.set",
77
- path: OperationPath.make(""),
78
- payload: "42",
79
- };
80
-
81
- expect(() => numberPrimitive._internal.applyOperation(undefined, operation)).toThrow(
82
- Primitive.ValidationError
83
- );
84
- });
85
-
86
- it("throws ValidationError for wrong operation kind", () => {
87
- const numberPrimitive = Primitive.Number();
88
- const operation: Operation.Operation<any, any, any> = {
89
- kind: "string.set",
90
- path: OperationPath.make(""),
91
- payload: 42,
92
- };
93
-
94
- expect(() => numberPrimitive._internal.applyOperation(undefined, operation)).toThrow(
95
- Primitive.ValidationError
96
- );
97
- });
98
- });
99
-
100
- describe("getInitialState", () => {
101
- it("returns undefined when no default is set", () => {
102
- const numberPrimitive = Primitive.Number();
103
- expect(numberPrimitive._internal.getInitialState()).toBeUndefined();
104
- });
105
-
106
- it("returns the default value when set", () => {
107
- const numberPrimitive = Primitive.Number().default(0);
108
- expect(numberPrimitive._internal.getInitialState()).toBe(0);
109
- });
110
- });
111
-
112
- describe("schema modifiers", () => {
113
- it("required() returns a new NumberPrimitive", () => {
114
- const original = Primitive.Number();
115
- const required = original.required();
116
-
117
- expect(required).toBeInstanceOf(Primitive.NumberPrimitive);
118
- expect(required).not.toBe(original);
119
- });
120
-
121
- it("default() returns a new NumberPrimitive with default value", () => {
122
- const original = Primitive.Number();
123
- const withDefault = original.default(100);
124
-
125
- expect(withDefault).toBeInstanceOf(Primitive.NumberPrimitive);
126
- expect(withDefault._internal.getInitialState()).toBe(100);
127
- });
128
- });
129
- });
130
-
131
- // =============================================================================
132
- // Literal Primitive Tests
133
- // =============================================================================
@@ -1,128 +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("StringPrimitive", () => {
8
- describe("proxy", () => {
9
- it("set() generates correct operation with path and payload", () => {
10
- const operations: Operation.Operation<any, any, any>[] = [];
11
- const env = ProxyEnvironment.make((op) => {
12
- operations.push(op);
13
- });
14
-
15
- const stringPrimitive = Primitive.String().required();
16
- const proxy = stringPrimitive._internal.createProxy(env, OperationPath.make(""));
17
-
18
- proxy.set("Hello World");
19
-
20
- expect(operations).toHaveLength(1);
21
- expect(operations[0]!.kind).toBe("string.set");
22
- expect(operations[0]!.payload).toBe("Hello World");
23
- });
24
-
25
- it("set() includes the correct path in operation", () => {
26
- const operations: Operation.Operation<any, any, any>[] = [];
27
- const env = ProxyEnvironment.make((op) => {
28
- operations.push(op);
29
- });
30
-
31
- const stringPrimitive = Primitive.String();
32
- const proxy = stringPrimitive._internal.createProxy(env, OperationPath.make("users/0/name"));
33
-
34
- proxy.set("John");
35
-
36
- expect(operations).toHaveLength(1);
37
- expect(operations[0]!.path.toTokens()).toEqual(["users", "0", "name"]);
38
- });
39
- });
40
-
41
- describe("applyOperation", () => {
42
- it("returns the new string value from string.set operation", () => {
43
- const stringPrimitive = Primitive.String();
44
- const operation: Operation.Operation<any, any, any> = {
45
- kind: "string.set",
46
- path: OperationPath.make(""),
47
- payload: "New Value",
48
- };
49
-
50
- const result = stringPrimitive._internal.applyOperation(undefined, operation);
51
-
52
- expect(result).toBe("New Value");
53
- });
54
-
55
- it("replaces existing state with new value", () => {
56
- const stringPrimitive = Primitive.String();
57
- const operation: Operation.Operation<any, any, any> = {
58
- kind: "string.set",
59
- path: OperationPath.make(""),
60
- payload: "Updated",
61
- };
62
-
63
- const result = stringPrimitive._internal.applyOperation("Original", operation);
64
-
65
- expect(result).toBe("Updated");
66
- });
67
-
68
- it("throws ValidationError for non-string payload", () => {
69
- const stringPrimitive = Primitive.String();
70
- const operation: Operation.Operation<any, any, any> = {
71
- kind: "string.set",
72
- path: OperationPath.make(""),
73
- payload: 123,
74
- };
75
-
76
- expect(() => stringPrimitive._internal.applyOperation(undefined, operation)).toThrow(
77
- Primitive.ValidationError
78
- );
79
- });
80
-
81
- it("throws ValidationError for wrong operation kind", () => {
82
- const stringPrimitive = Primitive.String();
83
- const operation: Operation.Operation<any, any, any> = {
84
- kind: "wrong.kind",
85
- path: OperationPath.make(""),
86
- payload: "value",
87
- };
88
-
89
- expect(() => stringPrimitive._internal.applyOperation(undefined, operation)).toThrow(
90
- Primitive.ValidationError
91
- );
92
- });
93
- });
94
-
95
- describe("getInitialState", () => {
96
- it("returns undefined when no default is set", () => {
97
- const stringPrimitive = Primitive.String();
98
- expect(stringPrimitive._internal.getInitialState()).toBeUndefined();
99
- });
100
-
101
- it("returns the default value when set", () => {
102
- const stringPrimitive = Primitive.String().default("Default Text");
103
- expect(stringPrimitive._internal.getInitialState()).toBe("Default Text");
104
- });
105
- });
106
-
107
- describe("schema modifiers", () => {
108
- it("required() returns a new StringPrimitive", () => {
109
- const original = Primitive.String();
110
- const required = original.required();
111
-
112
- expect(required).toBeInstanceOf(Primitive.StringPrimitive);
113
- expect(required).not.toBe(original);
114
- });
115
-
116
- it("default() returns a new StringPrimitive with default value", () => {
117
- const original = Primitive.String();
118
- const withDefault = original.default("test");
119
-
120
- expect(withDefault).toBeInstanceOf(Primitive.StringPrimitive);
121
- expect(withDefault._internal.getInitialState()).toBe("test");
122
- });
123
- });
124
- });
125
-
126
- // =============================================================================
127
- // Boolean Primitive Tests
128
- // =============================================================================