@voidhash/mimic 1.0.0-beta.15 → 1.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +23 -23
- package/dist/Document.cjs +0 -3
- package/dist/Document.d.mts.map +1 -1
- package/dist/Document.mjs +0 -3
- package/dist/Document.mjs.map +1 -1
- package/dist/Primitive.d.cts +2 -2
- package/dist/Primitive.d.mts +2 -2
- package/dist/primitives/Struct.cjs +48 -9
- package/dist/primitives/Struct.d.cts +22 -3
- package/dist/primitives/Struct.d.cts.map +1 -1
- package/dist/primitives/Struct.d.mts +22 -3
- package/dist/primitives/Struct.d.mts.map +1 -1
- package/dist/primitives/Struct.mjs +48 -9
- package/dist/primitives/Struct.mjs.map +1 -1
- package/dist/primitives/shared.cjs +2 -5
- package/dist/primitives/shared.d.cts +0 -4
- package/dist/primitives/shared.d.cts.map +1 -1
- package/dist/primitives/shared.d.mts +0 -4
- package/dist/primitives/shared.d.mts.map +1 -1
- package/dist/primitives/shared.mjs +2 -5
- package/dist/primitives/shared.mjs.map +1 -1
- package/package.json +2 -2
- package/src/Document.ts +13 -4
- package/src/primitives/Struct.ts +100 -12
- package/src/primitives/shared.ts +10 -2
- package/tests/primitives/Struct.test.ts +110 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @voidhash/mimic@1.0.0-beta.
|
|
2
|
+
> @voidhash/mimic@1.0.0-beta.16 build /home/runner/work/mimic/mimic/packages/mimic
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.18.2[22m powered by rolldown [2mv1.0.0-beta.55[22m
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Tree.cjs [2m30.01 kB[22m [2m│ gzip: 4.99 kB[22m
|
|
15
15
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/ClientDocument.cjs [2m24.61 kB[22m [2m│ gzip: 5.36 kB[22m
|
|
16
16
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mFractionalIndex.cjs [2m16.98 kB[22m [2m│ gzip: 3.39 kB[22m
|
|
17
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Struct.cjs [2m13.67 kB[22m [2m│ gzip: 2.98 kB[22m
|
|
17
18
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mutils/tree-helpers.cjs [2m13.42 kB[22m [2m│ gzip: 3.18 kB[22m
|
|
18
19
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Array.cjs [2m12.23 kB[22m [2m│ gzip: 2.67 kB[22m
|
|
19
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Struct.cjs [2m11.53 kB[22m [2m│ gzip: 2.58 kB[22m
|
|
20
20
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/WebSocketTransport.cjs [2m10.98 kB[22m [2m│ gzip: 2.71 kB[22m
|
|
21
21
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Either.cjs [2m 8.08 kB[22m [2m│ gzip: 2.06 kB[22m
|
|
22
22
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/Rebase.cjs [2m 7.85 kB[22m [2m│ gzip: 1.76 kB[22m
|
|
23
23
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Union.cjs [2m 7.49 kB[22m [2m│ gzip: 1.78 kB[22m
|
|
24
24
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mEffectSchema.cjs [2m 6.75 kB[22m [2m│ gzip: 1.63 kB[22m
|
|
25
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mDocument.cjs [2m 5.
|
|
26
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/shared.cjs [2m 5.12 kB[22m [2m│ gzip: 1.66 kB[22m
|
|
25
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mDocument.cjs [2m 5.22 kB[22m [2m│ gzip: 1.73 kB[22m
|
|
27
26
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/String.cjs [2m 5.05 kB[22m [2m│ gzip: 1.37 kB[22m
|
|
27
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/shared.cjs [2m 5.05 kB[22m [2m│ gzip: 1.62 kB[22m
|
|
28
28
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/errors.cjs [2m 4.80 kB[22m [2m│ gzip: 0.97 kB[22m
|
|
29
29
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Number.cjs [2m 4.63 kB[22m [2m│ gzip: 1.23 kB[22m
|
|
30
30
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mOperationPath.cjs [2m 4.24 kB[22m [2m│ gzip: 1.19 kB[22m
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutPropertiesLoose.cjs [2m 0.37 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
53
53
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/Transport.cjs [2m 0.21 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
54
54
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mTransform.cjs [2m 0.20 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
55
|
-
[34mℹ[39m [33m[CJS][39m 44 files, total:
|
|
55
|
+
[34mℹ[39m [33m[CJS][39m 44 files, total: 225.56 kB
|
|
56
56
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Tree.d.cts.map [2m 6.90 kB[22m [2m│ gzip: 2.60 kB[22m
|
|
57
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Struct.d.cts.map [2m
|
|
57
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Struct.d.cts.map [2m 5.26 kB[22m [2m│ gzip: 2.17 kB[22m
|
|
58
58
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mutils/tree-helpers.d.cts.map [2m 3.61 kB[22m [2m│ gzip: 1.31 kB[22m
|
|
59
59
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Array.d.cts.map [2m 3.27 kB[22m [2m│ gzip: 1.36 kB[22m
|
|
60
60
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Union.d.cts.map [2m 3.16 kB[22m [2m│ gzip: 1.38 kB[22m
|
|
@@ -90,17 +90,17 @@
|
|
|
90
90
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mserver/index.d.cts[22m[39m [2m 0.68 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
91
91
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Tree.d.cts[39m [2m13.50 kB[22m [2m│ gzip: 3.50 kB[22m
|
|
92
92
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mutils/tree-helpers.d.cts[39m [2m12.18 kB[22m [2m│ gzip: 2.52 kB[22m
|
|
93
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Struct.d.cts[39m [2m 8.04 kB[22m [2m│ gzip: 2.06 kB[22m
|
|
93
94
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mclient/Transport.d.cts[39m [2m 7.30 kB[22m [2m│ gzip: 1.84 kB[22m
|
|
94
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/shared.d.cts[39m [2m
|
|
95
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/shared.d.cts[39m [2m 6.99 kB[22m [2m│ gzip: 2.12 kB[22m
|
|
95
96
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mclient/ClientDocument.d.cts[39m [2m 6.99 kB[22m [2m│ gzip: 2.01 kB[22m
|
|
96
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Struct.d.cts[39m [2m 6.96 kB[22m [2m│ gzip: 1.86 kB[22m
|
|
97
97
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mserver/ServerDocument.d.cts[39m [2m 5.48 kB[22m [2m│ gzip: 1.76 kB[22m
|
|
98
98
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Either.d.cts[39m [2m 5.44 kB[22m [2m│ gzip: 1.54 kB[22m
|
|
99
99
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Array.d.cts[39m [2m 5.01 kB[22m [2m│ gzip: 1.44 kB[22m
|
|
100
100
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mclient/Rebase.d.cts[39m [2m 4.88 kB[22m [2m│ gzip: 1.14 kB[22m
|
|
101
101
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Union.d.cts[39m [2m 4.58 kB[22m [2m│ gzip: 1.26 kB[22m
|
|
102
102
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/TreeNode.d.cts[39m [2m 4.28 kB[22m [2m│ gzip: 1.29 kB[22m
|
|
103
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mPrimitive.d.cts[39m [2m 3.
|
|
103
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mPrimitive.d.cts[39m [2m 3.94 kB[22m [2m│ gzip: 0.84 kB[22m
|
|
104
104
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mclient/StateMonitor.d.cts[39m [2m 3.33 kB[22m [2m│ gzip: 1.07 kB[22m
|
|
105
105
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mEffectSchema.d.cts[39m [2m 3.20 kB[22m [2m│ gzip: 0.92 kB[22m
|
|
106
106
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/String.d.cts[39m [2m 3.08 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
@@ -120,16 +120,16 @@
|
|
|
120
120
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mclient/WebSocketTransport.d.cts[39m [2m 1.22 kB[22m [2m│ gzip: 0.55 kB[22m
|
|
121
121
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mOperationDefinition.d.cts[39m [2m 1.21 kB[22m [2m│ gzip: 0.40 kB[22m
|
|
122
122
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mTransform.d.cts[39m [2m 0.48 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
123
|
-
[34mℹ[39m [33m[CJS][39m 67 files, total:
|
|
124
|
-
[32m✔[39m Build complete in [
|
|
123
|
+
[34mℹ[39m [33m[CJS][39m 67 files, total: 187.98 kB
|
|
124
|
+
[32m✔[39m Build complete in [32m6056ms[39m
|
|
125
125
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 1.13 kB[22m [2m│ gzip: 0.29 kB[22m
|
|
126
126
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mclient/index.mjs[22m [2m 0.99 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
127
127
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mserver/index.mjs[22m [2m 0.41 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
128
128
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Tree.mjs.map [2m68.20 kB[22m [2m│ gzip: 12.85 kB[22m
|
|
129
129
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/ClientDocument.mjs.map [2m56.58 kB[22m [2m│ gzip: 12.99 kB[22m
|
|
130
130
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mFractionalIndex.mjs.map [2m52.10 kB[22m [2m│ gzip: 10.05 kB[22m
|
|
131
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.mjs.map [2m32.95 kB[22m [2m│ gzip: 7.96 kB[22m
|
|
131
132
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Tree.mjs [2m28.14 kB[22m [2m│ gzip: 4.95 kB[22m
|
|
132
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.mjs.map [2m27.59 kB[22m [2m│ gzip: 6.97 kB[22m
|
|
133
133
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Array.mjs.map [2m26.06 kB[22m [2m│ gzip: 6.49 kB[22m
|
|
134
134
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils/tree-helpers.mjs.map [2m24.70 kB[22m [2m│ gzip: 5.20 kB[22m
|
|
135
135
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/ClientDocument.mjs [2m24.17 kB[22m [2m│ gzip: 5.32 kB[22m
|
|
@@ -138,14 +138,14 @@
|
|
|
138
138
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Either.mjs.map [2m16.82 kB[22m [2m│ gzip: 4.14 kB[22m
|
|
139
139
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mEffectSchema.mjs.map [2m16.73 kB[22m [2m│ gzip: 3.54 kB[22m
|
|
140
140
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mFractionalIndex.mjs [2m16.49 kB[22m [2m│ gzip: 3.36 kB[22m
|
|
141
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.mjs.map [2m15.
|
|
141
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.mjs.map [2m15.92 kB[22m [2m│ gzip: 4.54 kB[22m
|
|
142
142
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/Rebase.mjs.map [2m14.15 kB[22m [2m│ gzip: 3.21 kB[22m
|
|
143
143
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mserver/ServerDocument.mjs.map [2m14.09 kB[22m [2m│ gzip: 3.86 kB[22m
|
|
144
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mDocument.mjs.map [2m13.50 kB[22m [2m│ gzip: 4.16 kB[22m
|
|
144
145
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils/tree-helpers.mjs [2m13.31 kB[22m [2m│ gzip: 3.15 kB[22m
|
|
145
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[
|
|
146
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.mjs [2m12.60 kB[22m [2m│ gzip: 2.95 kB[22m
|
|
146
147
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Array.mjs [2m11.09 kB[22m [2m│ gzip: 2.65 kB[22m
|
|
147
148
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/WebSocketTransport.mjs [2m10.81 kB[22m [2m│ gzip: 2.68 kB[22m
|
|
148
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.mjs [2m10.49 kB[22m [2m│ gzip: 2.56 kB[22m
|
|
149
149
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/StateMonitor.mjs.map [2m10.39 kB[22m [2m│ gzip: 3.04 kB[22m
|
|
150
150
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/String.mjs.map [2m 9.73 kB[22m [2m│ gzip: 2.71 kB[22m
|
|
151
151
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/Transport.mjs.map [2m 9.09 kB[22m [2m│ gzip: 1.86 kB[22m
|
|
@@ -160,9 +160,9 @@
|
|
|
160
160
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mEffectSchema.mjs [2m 6.47 kB[22m [2m│ gzip: 1.59 kB[22m
|
|
161
161
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/TreeNode.mjs.map [2m 6.47 kB[22m [2m│ gzip: 2.05 kB[22m
|
|
162
162
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/errors.mjs.map [2m 5.68 kB[22m [2m│ gzip: 1.37 kB[22m
|
|
163
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[
|
|
164
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[
|
|
165
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/
|
|
163
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.d.mts.map [2m 5.30 kB[22m [2m│ gzip: 2.21 kB[22m
|
|
164
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mDocument.mjs [2m 4.94 kB[22m [2m│ gzip: 1.69 kB[22m
|
|
165
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.mjs [2m 4.88 kB[22m [2m│ gzip: 1.62 kB[22m
|
|
166
166
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Lazy.mjs.map [2m 4.59 kB[22m [2m│ gzip: 1.40 kB[22m
|
|
167
167
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mPresence.mjs.map [2m 4.56 kB[22m [2m│ gzip: 1.30 kB[22m
|
|
168
168
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/String.mjs [2m 4.44 kB[22m [2m│ gzip: 1.35 kB[22m
|
|
@@ -236,17 +236,17 @@
|
|
|
236
236
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mserver/index.d.mts[22m[39m [2m 0.68 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
237
237
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/Tree.d.mts[39m [2m13.50 kB[22m [2m│ gzip: 3.50 kB[22m
|
|
238
238
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mutils/tree-helpers.d.mts[39m [2m12.18 kB[22m [2m│ gzip: 2.52 kB[22m
|
|
239
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/Struct.d.mts[39m [2m 8.07 kB[22m [2m│ gzip: 2.07 kB[22m
|
|
239
240
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/Transport.d.mts[39m [2m 7.30 kB[22m [2m│ gzip: 1.84 kB[22m
|
|
240
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/shared.d.mts[39m [2m 7.16 kB[22m [2m│ gzip: 2.19 kB[22m
|
|
241
241
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/ClientDocument.d.mts[39m [2m 7.02 kB[22m [2m│ gzip: 2.02 kB[22m
|
|
242
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/
|
|
242
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/shared.d.mts[39m [2m 6.99 kB[22m [2m│ gzip: 2.12 kB[22m
|
|
243
243
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mserver/ServerDocument.d.mts[39m [2m 5.50 kB[22m [2m│ gzip: 1.76 kB[22m
|
|
244
244
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/Either.d.mts[39m [2m 5.44 kB[22m [2m│ gzip: 1.54 kB[22m
|
|
245
245
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/Array.d.mts[39m [2m 5.04 kB[22m [2m│ gzip: 1.45 kB[22m
|
|
246
246
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/Rebase.d.mts[39m [2m 4.91 kB[22m [2m│ gzip: 1.15 kB[22m
|
|
247
247
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/Union.d.mts[39m [2m 4.61 kB[22m [2m│ gzip: 1.27 kB[22m
|
|
248
248
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/TreeNode.d.mts[39m [2m 4.31 kB[22m [2m│ gzip: 1.29 kB[22m
|
|
249
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mPrimitive.d.mts[39m [2m 3.
|
|
249
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mPrimitive.d.mts[39m [2m 3.94 kB[22m [2m│ gzip: 0.84 kB[22m
|
|
250
250
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/StateMonitor.d.mts[39m [2m 3.33 kB[22m [2m│ gzip: 1.07 kB[22m
|
|
251
251
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mEffectSchema.d.mts[39m [2m 3.20 kB[22m [2m│ gzip: 0.92 kB[22m
|
|
252
252
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/String.d.mts[39m [2m 3.08 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
@@ -266,5 +266,5 @@
|
|
|
266
266
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/WebSocketTransport.d.mts[39m [2m 1.22 kB[22m [2m│ gzip: 0.55 kB[22m
|
|
267
267
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mOperationDefinition.d.mts[39m [2m 1.21 kB[22m [2m│ gzip: 0.40 kB[22m
|
|
268
268
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mTransform.d.mts[39m [2m 0.48 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
269
|
-
[34mℹ[39m [34m[ESM][39m 144 files, total:
|
|
270
|
-
[32m✔[39m Build complete in [
|
|
269
|
+
[34mℹ[39m [34m[ESM][39m 144 files, total: 890.45 kB
|
|
270
|
+
[32m✔[39m Build complete in [32m6139ms[39m
|
package/dist/Document.cjs
CHANGED
|
@@ -35,9 +35,6 @@ var OperationError = class extends Error {
|
|
|
35
35
|
*/
|
|
36
36
|
const make = (schema, options) => {
|
|
37
37
|
let _state = (options === null || options === void 0 ? void 0 : options.initialState) !== void 0 ? options.initialState : (options === null || options === void 0 ? void 0 : options.initial) !== void 0 ? schema._internal.convertSetInputToState ? schema._internal.convertSetInputToState(options.initial) : options.initial : schema._internal.getInitialState();
|
|
38
|
-
/**
|
|
39
|
-
* An ops buffer that maintains a dedup index for O(1) lookups by path:kind.
|
|
40
|
-
*/
|
|
41
38
|
const makeOpsBuffer = () => {
|
|
42
39
|
let ops = [];
|
|
43
40
|
let index = /* @__PURE__ */ new Map();
|
package/dist/Document.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.mts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;cAW/B,cAAA,SAAuB,KAAA;EAXvB,SAAA,IAAA,GAAA,gBAAuB;EAWvB,WAAA,CAAA,OAAe,EAAA,MAAA;AAe5B;;;;AAKiB,UALA,QAKA,CAAA,gBALyB,YAKzB,CAAA,CAAA;EAGa;EAArB,SAAA,MAAA,EANU,OAMV;EAQ+B;EAAxB,SAAA,IAAA,EAXC,UAWD,CAXsB,OAWtB,CAAA;EAQiC;EAArB,GAAA,EAAA,EAhBnB,UAgBmB,CAhBE,OAgBF,CAAA,GAAA,SAAA;EAAkC;;;;;;EAkB7C,UAAA,EAAA,EA1BD,aA0BgB,CA1BQ,OA0BR,CAAA;EAAiB;;;;;;EAkBpC,
|
|
1
|
+
{"version":3,"file":"Document.d.mts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;cAW/B,cAAA,SAAuB,KAAA;EAXvB,SAAA,IAAA,GAAA,gBAAuB;EAWvB,WAAA,CAAA,OAAe,EAAA,MAAA;AAe5B;;;;AAKiB,UALA,QAKA,CAAA,gBALyB,YAKzB,CAAA,CAAA;EAGa;EAArB,SAAA,MAAA,EANU,OAMV;EAQ+B;EAAxB,SAAA,IAAA,EAXC,UAWD,CAXsB,OAWtB,CAAA;EAQiC;EAArB,GAAA,EAAA,EAhBnB,UAgBmB,CAhBE,OAgBF,CAAA,GAAA,SAAA;EAAkC;;;;;;EAkB7C,UAAA,EAAA,EA1BD,aA0BgB,CA1BQ,OA0BR,CAAA;EAAiB;;;;;;EAkBpC,WAuOZ,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EA3Q2B,UA2Q3B,CA3QgD,OA2QhD,CAAA,EAAA,GA3Q6D,CA2Q7D,CAAA,EA3QiE,CA2QjE;EAvOoC;;;;EAGzB,KAAA,CAAA,GAAA,EAjCC,aAiCD,CAjCe,SAiCf,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAAA,EAAA,IAAA;EAAT;;;WA5BQ;;UAOM,gCAAgC;;qBAE5B,cAAwB;;;;;;0BAMnB,WAAqB;;;;;cAUlC,uBAAwB,sBAC3B,mBACE,gBAAgB,aACzB,SAAS"}
|
package/dist/Document.mjs
CHANGED
|
@@ -35,9 +35,6 @@ var OperationError = class extends Error {
|
|
|
35
35
|
*/
|
|
36
36
|
const make = (schema, options) => {
|
|
37
37
|
let _state = (options === null || options === void 0 ? void 0 : options.initialState) !== void 0 ? options.initialState : (options === null || options === void 0 ? void 0 : options.initial) !== void 0 ? schema._internal.convertSetInputToState ? schema._internal.convertSetInputToState(options.initial) : options.initial : schema._internal.getInitialState();
|
|
38
|
-
/**
|
|
39
|
-
* An ops buffer that maintains a dedup index for O(1) lookups by path:kind.
|
|
40
|
-
*/
|
|
41
38
|
const makeOpsBuffer = () => {
|
|
42
39
|
let ops = [];
|
|
43
40
|
let index = /* @__PURE__ */ new Map();
|
package/dist/Document.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.mjs","names":["_state: Primitive.InferState<TSchema> | undefined","ops: Operation.Operation<any, any, any>[]","OperationPath.encode","_txBaseState: Primitive.InferState<TSchema> | undefined","current: unknown","ProxyEnvironment.make","OperationPath.make","Transaction.make"],"sources":["../src/Document.ts"],"sourcesContent":["import * as Operation from \"./Operation\";\nimport * as OperationPath from \"./OperationPath\";\nimport * as ProxyEnvironment from \"./ProxyEnvironment\";\nimport * as Transaction from \"./Transaction\";\nimport type * as Primitive from \"./Primitive\";\n\n// =============================================================================\n// Document Errors\n// =============================================================================\n\n/**\n * Error thrown when attempting to start a nested transaction.\n */\nexport class NestedTransactionError extends Error {\n readonly _tag = \"NestedTransactionError\";\n constructor() {\n super(\"Nested transactions are not supported\");\n this.name = \"NestedTransactionError\";\n }\n}\n\n/**\n * Error thrown when an operation fails to apply.\n */\nexport class OperationError extends Error {\n readonly _tag = \"OperationError\";\n constructor(message: string) {\n super(message);\n this.name = \"OperationError\";\n }\n}\n\n// =============================================================================\n// Document Interface\n// =============================================================================\n\n/**\n * A Document manages state for a primitive-based schema with transaction support.\n */\nexport interface Document<TSchema extends Primitive.AnyPrimitive> {\n /** The schema defining this document's structure */\n readonly schema: TSchema;\n \n /** Root proxy for accessing and modifying document data */\n readonly root: Primitive.InferProxy<TSchema>;\n \n /** Returns the current document state */\n get(): Primitive.InferState<TSchema> | undefined;\n \n /**\n * Returns a readonly snapshot of the entire document state for rendering.\n * The snapshot is a type-safe, readonly structure where:\n * - Required fields and fields with defaults are guaranteed to be defined\n * - Optional fields may be undefined\n */\n toSnapshot(): Primitive.InferSnapshot<TSchema>;\n \n /**\n * Runs a function within a transaction.\n * All operations are collected and applied atomically.\n * If the function throws, all changes are rolled back.\n * @returns The return value of the function\n */\n transaction<R>(fn: (root: Primitive.InferProxy<TSchema>) => R): R;\n \n /**\n * Applies external operations (e.g., from server/peers) to the document.\n * These operations are NOT added to pending operations.\n */\n apply(ops: ReadonlyArray<Operation.Operation<any, any, any>>): void;\n \n /**\n * Returns pending local operations as a Transaction and clears the buffer.\n */\n flush(): Transaction.Transaction;\n}\n\n// =============================================================================\n// Document Options\n// =============================================================================\n\nexport interface DocumentOptions<TSchema extends Primitive.AnyPrimitive> {\n /** Initial value for the document (using set input format) */\n readonly initial?: Primitive.InferSetInput<TSchema>;\n /**\n * Raw initial state for the document (already in internal state format).\n * Use this when loading state from the server or storage.\n * Takes precedence over `initial` if both are provided.\n */\n readonly initialState?: Primitive.InferState<TSchema>;\n}\n\n// =============================================================================\n// Document Implementation\n// =============================================================================\n\n/**\n * Creates a new Document for the given schema.\n */\nexport const make = <TSchema extends Primitive.AnyPrimitive>(\n schema: TSchema,\n options?: DocumentOptions<TSchema>\n): Document<TSchema> => {\n // Internal state - determine initial state based on options\n // Priority: initialState (raw) > initial (needs conversion) > schema defaults\n let _state: Primitive.InferState<TSchema> | undefined =\n options?.initialState !== undefined\n ? options.initialState\n : options?.initial !== undefined\n ? (schema._internal.convertSetInputToState\n ? schema._internal.convertSetInputToState(options.initial)\n : options.initial as Primitive.InferState<TSchema>)\n : schema._internal.getInitialState();\n \n /**\n * An ops buffer that maintains a dedup index for O(1) lookups by path:kind.\n */\n const makeOpsBuffer = () => {\n let ops: Operation.Operation<any, any, any>[] = [];\n // Maps \"encodedPath:kind\" → array index for deduplicable ops\n let index = new Map<string, number>();\n\n const dedupKey = (op: Operation.Operation<any, any, any>): string =>\n `${OperationPath.encode(op.path)}:${String(op.kind)}`;\n\n return {\n push(op: Operation.Operation<any, any, any>): void {\n if (op.deduplicable) {\n const key = dedupKey(op);\n const existing = index.get(key);\n if (existing !== undefined) {\n // Remove old entry; shift indices above it down by 1\n ops.splice(existing, 1);\n // Rebuild affected index entries\n const newIndex = new Map<string, number>();\n for (const [k, v] of index) {\n if (k === key) continue;\n newIndex.set(k, v > existing ? v - 1 : v);\n }\n index = newIndex;\n }\n index.set(key, ops.length);\n }\n ops.push(op);\n },\n /** Drains all ops and resets the buffer. */\n drain(): Operation.Operation<any, any, any>[] {\n const result = ops;\n ops = [];\n index = new Map();\n return result;\n },\n /** Appends all ops from another buffer (used on tx commit). */\n mergeFrom(other: ReturnType<typeof makeOpsBuffer>): void {\n for (const op of other.toArray()) {\n this.push(op);\n }\n },\n toArray(): readonly Operation.Operation<any, any, any>[] {\n return ops;\n },\n reset(): void {\n ops = [];\n index = new Map();\n },\n };\n };\n\n // Pending operations buffer (local changes not yet flushed)\n const _pending = makeOpsBuffer();\n\n // Transaction state\n let _inTransaction = false;\n let _txOps = makeOpsBuffer();\n let _txBaseState: Primitive.InferState<TSchema> | undefined = undefined;\n\n /**\n * Gets state at the given path.\n */\n const getStateAtPath = (path: OperationPath.OperationPath): unknown => {\n const tokens = path.toTokens().filter(t => t !== \"\");\n \n if (tokens.length === 0) {\n return _state;\n }\n \n let current: unknown = _state;\n for (const token of tokens) {\n if (current === null || current === undefined) {\n return undefined;\n }\n \n if (typeof current === \"object\") {\n // Handle array entries (which have { id, pos, value } structure)\n if (Array.isArray(current)) {\n // Try to find by ID in array entries\n const entry = current.find((e: any) => e.id === token);\n if (entry) {\n current = entry.value;\n continue;\n }\n }\n \n // Handle regular object property access\n current = (current as Record<string, unknown>)[token];\n } else {\n return undefined;\n }\n }\n \n return current;\n };\n\n /**\n * Applies a single operation to the current state.\n */\n const applyOperation = (op: Operation.Operation<any, any, any>): void => {\n try {\n _state = schema._internal.applyOperation(_state, op);\n } catch (error) {\n if (error instanceof Error) {\n throw new OperationError(error.message);\n }\n throw new OperationError(String(error));\n }\n };\n\n /**\n * Handles an operation from a proxy.\n * In transaction mode: collects operations, applies to state immediately for subsequent reads.\n * Outside transaction mode: auto-wraps in a single-operation transaction.\n */\n const handleOperation = (op: Operation.Operation<any, any, any>): void => {\n if (_inTransaction) {\n // In transaction: collect op and apply immediately for subsequent reads\n _txOps.push(op);\n applyOperation(op);\n } else {\n // Not in transaction: auto-wrap in single-operation transaction\n const baseState = _state;\n try {\n applyOperation(op);\n _pending.push(op);\n } catch (error) {\n // Rollback on error\n _state = baseState;\n throw error;\n }\n }\n };\n\n /**\n * Creates a ProxyEnvironment for the document.\n */\n const createEnv = (): ProxyEnvironment.ProxyEnvironment => {\n return ProxyEnvironment.make({\n onOperation: handleOperation,\n getState: getStateAtPath,\n });\n };\n\n // Create the root proxy\n const env = createEnv();\n const rootProxy = schema._internal.createProxy(env, OperationPath.make(\"\")) as Primitive.InferProxy<TSchema>;\n\n // Document implementation\n const document: Document<TSchema> = {\n schema,\n root: rootProxy,\n \n get: (): Primitive.InferState<TSchema> | undefined => {\n return _state;\n },\n \n toSnapshot: (): Primitive.InferSnapshot<TSchema> => {\n return (rootProxy as { toSnapshot(): Primitive.InferSnapshot<TSchema> }).toSnapshot();\n },\n \n transaction: <R,>(fn: (root: Primitive.InferProxy<TSchema>) => R): R => {\n if (_inTransaction) {\n throw new NestedTransactionError();\n }\n \n // Start transaction\n _inTransaction = true;\n _txOps.reset();\n _txBaseState = _state;\n \n try {\n // Execute the transaction function\n const result = fn(rootProxy);\n \n // Commit: add transaction ops to pending\n _pending.mergeFrom(_txOps);\n \n return result;\n } catch (error) {\n // Rollback: restore base state\n _state = _txBaseState;\n throw error;\n } finally {\n // Clean up transaction state\n _inTransaction = false;\n _txOps.reset();\n _txBaseState = undefined;\n }\n },\n \n apply: (ops: ReadonlyArray<Operation.Operation<any, any, any>>): void => {\n for (const op of ops) {\n applyOperation(op);\n }\n },\n \n flush: (): Transaction.Transaction => {\n const tx = Transaction.make(_pending.drain());\n return tx;\n },\n };\n\n return document;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,yBAAb,cAA4C,MAAM;CAEhD,cAAc;AACZ,QAAM,wCAAwC;wBAFvC,QAAO;AAGd,OAAK,OAAO;;;;;;AAOhB,IAAa,iBAAb,cAAoC,MAAM;CAExC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;wBAFP,QAAO;AAGd,OAAK,OAAO;;;;;;AAuEhB,MAAa,QACX,QACA,YACsB;CAGtB,IAAIA,4DACF,QAAS,kBAAiB,SACtB,QAAQ,kEACR,QAAS,aAAY,SAClB,OAAO,UAAU,yBACd,OAAO,UAAU,uBAAuB,QAAQ,QAAQ,GACxD,QAAQ,UACZ,OAAO,UAAU,iBAAiB;;;;CAK1C,MAAM,sBAAsB;EAC1B,IAAIC,MAA4C,EAAE;EAElD,IAAI,wBAAQ,IAAI,KAAqB;EAErC,MAAM,YAAY,OAChB,GAAGC,OAAqB,GAAG,KAAK,CAAC,GAAG,OAAO,GAAG,KAAK;AAErD,SAAO;G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AACF,YAAS,OAAO,UAAU,eAAe,QAAQ,GAAG;WAC7C,OAAO;AACd,OAAI,iBAAiB,MACnB,OAAM,IAAI,eAAe,MAAM,QAAQ;AAEzC,SAAM,IAAI,eAAe,OAAO,MAAM,CAAC;;;;;;;;CAS3C,MAAM,mBAAmB,OAAiD;AACxE,MAAI,gBAAgB;AAElB,UAAO,KAAK,GAAG;AACf,kBAAe,GAAG;SACb;GAEL,MAAM,YAAY;AAClB,OAAI;AACF,mBAAe,GAAG;AAClB,aAAS,KAAK,GAAG;YACV,OAAO;AAEd,aAAS;AACT,UAAM;;;;;;;CAQZ,MAAM,kBAAqD;AACzD,SAAOC,OAAsB;GAC3B,aAAa;GACb,UAAU;GACX,CAAC;;CAIJ,MAAM,MAAM,WAAW;CACvB,MAAM,YAAY,OAAO,UAAU,YAAY,KAAKC,OAAmB,GAAG,CAAC;AAyD3E,QAtDoC;EAClC;EACA,MAAM;EAEN,WAAsD;AACpD,UAAO;;EAGT,kBAAoD;AAClD,UAAQ,UAAiE,YAAY;;EAGvF,cAAkB,OAAsD;AACtE,OAAI,eACF,OAAM,IAAI,wBAAwB;AAIpC,oBAAiB;AACjB,UAAO,OAAO;AACd,kBAAe;AAEf,OAAI;IAEF,MAAM,SAAS,GAAG,UAAU;AAG5B,aAAS,UAAU,OAAO;AAE1B,WAAO;YACA,OAAO;AAEd,aAAS;AACT,UAAM;aACE;AAER,qBAAiB;AACjB,WAAO,OAAO;AACd,mBAAe;;;EAInB,QAAQ,QAAiE;AACvE,QAAK,MAAM,MAAM,IACf,gBAAe,GAAG;;EAItB,aAAsC;AAEpC,UADWC,OAAiB,SAAS,OAAO,CAAC;;EAGhD"}
|
|
1
|
+
{"version":3,"file":"Document.mjs","names":["_state: Primitive.InferState<TSchema> | undefined","ops: BufferedOperation[]","OperationPath.encode","_txBaseState: Primitive.InferState<TSchema> | undefined","current: unknown","ProxyEnvironment.make","OperationPath.make","Transaction.make"],"sources":["../src/Document.ts"],"sourcesContent":["import * as Operation from \"./Operation\";\nimport * as OperationPath from \"./OperationPath\";\nimport * as ProxyEnvironment from \"./ProxyEnvironment\";\nimport * as Transaction from \"./Transaction\";\nimport type * as Primitive from \"./Primitive\";\n\n// =============================================================================\n// Document Errors\n// =============================================================================\n\n/**\n * Error thrown when attempting to start a nested transaction.\n */\nexport class NestedTransactionError extends Error {\n readonly _tag = \"NestedTransactionError\";\n constructor() {\n super(\"Nested transactions are not supported\");\n this.name = \"NestedTransactionError\";\n }\n}\n\n/**\n * Error thrown when an operation fails to apply.\n */\nexport class OperationError extends Error {\n readonly _tag = \"OperationError\";\n constructor(message: string) {\n super(message);\n this.name = \"OperationError\";\n }\n}\n\n// =============================================================================\n// Document Interface\n// =============================================================================\n\n/**\n * A Document manages state for a primitive-based schema with transaction support.\n */\nexport interface Document<TSchema extends Primitive.AnyPrimitive> {\n /** The schema defining this document's structure */\n readonly schema: TSchema;\n \n /** Root proxy for accessing and modifying document data */\n readonly root: Primitive.InferProxy<TSchema>;\n \n /** Returns the current document state */\n get(): Primitive.InferState<TSchema> | undefined;\n \n /**\n * Returns a readonly snapshot of the entire document state for rendering.\n * The snapshot is a type-safe, readonly structure where:\n * - Required fields and fields with defaults are guaranteed to be defined\n * - Optional fields may be undefined\n */\n toSnapshot(): Primitive.InferSnapshot<TSchema>;\n \n /**\n * Runs a function within a transaction.\n * All operations are collected and applied atomically.\n * If the function throws, all changes are rolled back.\n * @returns The return value of the function\n */\n transaction<R>(fn: (root: Primitive.InferProxy<TSchema>) => R): R;\n \n /**\n * Applies external operations (e.g., from server/peers) to the document.\n * These operations are NOT added to pending operations.\n */\n apply(ops: ReadonlyArray<Operation.Operation<any, any, any>>): void;\n \n /**\n * Returns pending local operations as a Transaction and clears the buffer.\n */\n flush(): Transaction.Transaction;\n}\n\n// =============================================================================\n// Document Options\n// =============================================================================\n\nexport interface DocumentOptions<TSchema extends Primitive.AnyPrimitive> {\n /** Initial value for the document (using set input format) */\n readonly initial?: Primitive.InferSetInput<TSchema>;\n /**\n * Raw initial state for the document (already in internal state format).\n * Use this when loading state from the server or storage.\n * Takes precedence over `initial` if both are provided.\n */\n readonly initialState?: Primitive.InferState<TSchema>;\n}\n\n// =============================================================================\n// Document Implementation\n// =============================================================================\n\n/**\n * Creates a new Document for the given schema.\n */\nexport const make = <TSchema extends Primitive.AnyPrimitive>(\n schema: TSchema,\n options?: DocumentOptions<TSchema>\n): Document<TSchema> => {\n // Internal state - determine initial state based on options\n // Priority: initialState (raw) > initial (needs conversion) > schema defaults\n let _state: Primitive.InferState<TSchema> | undefined =\n options?.initialState !== undefined\n ? options.initialState\n : options?.initial !== undefined\n ? (schema._internal.convertSetInputToState\n ? schema._internal.convertSetInputToState(options.initial)\n : options.initial as Primitive.InferState<TSchema>)\n : schema._internal.getInitialState();\n \n /**\n * An ops buffer that maintains a dedup index for O(1) lookups by path:kind.\n */\n type BufferedOperation = Operation.Operation<any, any, any>;\n interface OpsBuffer {\n push(op: BufferedOperation): void;\n drain(): BufferedOperation[];\n mergeFrom(other: OpsBuffer): void;\n toArray(): readonly BufferedOperation[];\n reset(): void;\n }\n\n const makeOpsBuffer = (): OpsBuffer => {\n let ops: BufferedOperation[] = [];\n // Maps \"encodedPath:kind\" → array index for deduplicable ops\n let index = new Map<string, number>();\n\n const dedupKey = (op: BufferedOperation): string =>\n `${OperationPath.encode(op.path)}:${String(op.kind)}`;\n\n return {\n push(op: Operation.Operation<any, any, any>): void {\n if (op.deduplicable) {\n const key = dedupKey(op);\n const existing = index.get(key);\n if (existing !== undefined) {\n // Remove old entry; shift indices above it down by 1\n ops.splice(existing, 1);\n // Rebuild affected index entries\n const newIndex = new Map<string, number>();\n for (const [k, v] of index) {\n if (k === key) continue;\n newIndex.set(k, v > existing ? v - 1 : v);\n }\n index = newIndex;\n }\n index.set(key, ops.length);\n }\n ops.push(op);\n },\n /** Drains all ops and resets the buffer. */\n drain(): Operation.Operation<any, any, any>[] {\n const result = ops;\n ops = [];\n index = new Map();\n return result;\n },\n /** Appends all ops from another buffer (used on tx commit). */\n mergeFrom(other: OpsBuffer): void {\n for (const op of other.toArray()) {\n this.push(op);\n }\n },\n toArray(): readonly Operation.Operation<any, any, any>[] {\n return ops;\n },\n reset(): void {\n ops = [];\n index = new Map();\n },\n };\n };\n\n // Pending operations buffer (local changes not yet flushed)\n const _pending = makeOpsBuffer();\n\n // Transaction state\n let _inTransaction = false;\n let _txOps = makeOpsBuffer();\n let _txBaseState: Primitive.InferState<TSchema> | undefined = undefined;\n\n /**\n * Gets state at the given path.\n */\n const getStateAtPath = (path: OperationPath.OperationPath): unknown => {\n const tokens = path.toTokens().filter(t => t !== \"\");\n \n if (tokens.length === 0) {\n return _state;\n }\n \n let current: unknown = _state;\n for (const token of tokens) {\n if (current === null || current === undefined) {\n return undefined;\n }\n \n if (typeof current === \"object\") {\n // Handle array entries (which have { id, pos, value } structure)\n if (Array.isArray(current)) {\n // Try to find by ID in array entries\n const entry = current.find((e: any) => e.id === token);\n if (entry) {\n current = entry.value;\n continue;\n }\n }\n \n // Handle regular object property access\n current = (current as Record<string, unknown>)[token];\n } else {\n return undefined;\n }\n }\n \n return current;\n };\n\n /**\n * Applies a single operation to the current state.\n */\n const applyOperation = (op: Operation.Operation<any, any, any>): void => {\n try {\n _state = schema._internal.applyOperation(_state, op);\n } catch (error) {\n if (error instanceof Error) {\n throw new OperationError(error.message);\n }\n throw new OperationError(String(error));\n }\n };\n\n /**\n * Handles an operation from a proxy.\n * In transaction mode: collects operations, applies to state immediately for subsequent reads.\n * Outside transaction mode: auto-wraps in a single-operation transaction.\n */\n const handleOperation = (op: Operation.Operation<any, any, any>): void => {\n if (_inTransaction) {\n // In transaction: collect op and apply immediately for subsequent reads\n _txOps.push(op);\n applyOperation(op);\n } else {\n // Not in transaction: auto-wrap in single-operation transaction\n const baseState = _state;\n try {\n applyOperation(op);\n _pending.push(op);\n } catch (error) {\n // Rollback on error\n _state = baseState;\n throw error;\n }\n }\n };\n\n /**\n * Creates a ProxyEnvironment for the document.\n */\n const createEnv = (): ProxyEnvironment.ProxyEnvironment => {\n return ProxyEnvironment.make({\n onOperation: handleOperation,\n getState: getStateAtPath,\n });\n };\n\n // Create the root proxy\n const env = createEnv();\n const rootProxy = schema._internal.createProxy(env, OperationPath.make(\"\")) as Primitive.InferProxy<TSchema>;\n\n // Document implementation\n const document: Document<TSchema> = {\n schema,\n root: rootProxy,\n \n get: (): Primitive.InferState<TSchema> | undefined => {\n return _state;\n },\n \n toSnapshot: (): Primitive.InferSnapshot<TSchema> => {\n return (rootProxy as { toSnapshot(): Primitive.InferSnapshot<TSchema> }).toSnapshot();\n },\n \n transaction: <R,>(fn: (root: Primitive.InferProxy<TSchema>) => R): R => {\n if (_inTransaction) {\n throw new NestedTransactionError();\n }\n \n // Start transaction\n _inTransaction = true;\n _txOps.reset();\n _txBaseState = _state;\n \n try {\n // Execute the transaction function\n const result = fn(rootProxy);\n \n // Commit: add transaction ops to pending\n _pending.mergeFrom(_txOps);\n \n return result;\n } catch (error) {\n // Rollback: restore base state\n _state = _txBaseState;\n throw error;\n } finally {\n // Clean up transaction state\n _inTransaction = false;\n _txOps.reset();\n _txBaseState = undefined;\n }\n },\n \n apply: (ops: ReadonlyArray<Operation.Operation<any, any, any>>): void => {\n for (const op of ops) {\n applyOperation(op);\n }\n },\n \n flush: (): Transaction.Transaction => {\n const tx = Transaction.make(_pending.drain());\n return tx;\n },\n };\n\n return document;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,yBAAb,cAA4C,MAAM;CAEhD,cAAc;AACZ,QAAM,wCAAwC;wBAFvC,QAAO;AAGd,OAAK,OAAO;;;;;;AAOhB,IAAa,iBAAb,cAAoC,MAAM;CAExC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;wBAFP,QAAO;AAGd,OAAK,OAAO;;;;;;AAuEhB,MAAa,QACX,QACA,YACsB;CAGtB,IAAIA,4DACF,QAAS,kBAAiB,SACtB,QAAQ,kEACR,QAAS,aAAY,SAClB,OAAO,UAAU,yB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ItB,aAAsC;AAEpC,UADWC,OAAiB,SAAS,OAAO,CAAC;;EAGhD"}
|
package/dist/Primitive.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyPrimitive, HasDefault, InferProxy, InferSetInput, InferSnapshot, InferState, InferUpdateInput, IsDefined, IsRequired, MaybeUndefined, NeedsValue, Optional, Primitive, PrimitiveInternal, ValidationError, Validator, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators } from "./primitives/shared.cjs";
|
|
2
2
|
import { String, StringPrimitive, StringProxy } from "./primitives/String.cjs";
|
|
3
|
-
import { InferStructSnapshot, InferStructState, MakeOptional, PartialFields, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue } from "./primitives/Struct.cjs";
|
|
3
|
+
import { InferStructSnapshot, InferStructState, MakeOptional, MakeOptionalNoDefault, PartialFields, PartialFieldsNoDefault, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue } from "./primitives/Struct.cjs";
|
|
4
4
|
import { Boolean, BooleanPrimitive, BooleanProxy } from "./primitives/Boolean.cjs";
|
|
5
5
|
import { Number, NumberPrimitive, NumberProxy } from "./primitives/Number.cjs";
|
|
6
6
|
import { Literal, LiteralPrimitive, LiteralProxy, LiteralValue } from "./primitives/Literal.cjs";
|
|
@@ -13,7 +13,7 @@ import { InferTreeSetInput, InferTreeSnapshot, Tree, TreeNodeDataSetInput, TreeN
|
|
|
13
13
|
|
|
14
14
|
//#region src/Primitive.d.ts
|
|
15
15
|
declare namespace Primitive_d_exports {
|
|
16
|
-
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSetInput, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MakeOptional, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, PartialFields, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators };
|
|
16
|
+
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSetInput, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MakeOptional, MakeOptionalNoDefault, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, PartialFields, PartialFieldsNoDefault, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators };
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
export { Primitive_d_exports };
|
package/dist/Primitive.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyPrimitive, HasDefault, InferProxy, InferSetInput, InferSnapshot, InferState, InferUpdateInput, IsDefined, IsRequired, MaybeUndefined, NeedsValue, Optional, Primitive, PrimitiveInternal, ValidationError, Validator, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators } from "./primitives/shared.mjs";
|
|
2
2
|
import { String, StringPrimitive, StringProxy } from "./primitives/String.mjs";
|
|
3
|
-
import { InferStructSnapshot, InferStructState, MakeOptional, PartialFields, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue } from "./primitives/Struct.mjs";
|
|
3
|
+
import { InferStructSnapshot, InferStructState, MakeOptional, MakeOptionalNoDefault, PartialFields, PartialFieldsNoDefault, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue } from "./primitives/Struct.mjs";
|
|
4
4
|
import { Boolean, BooleanPrimitive, BooleanProxy } from "./primitives/Boolean.mjs";
|
|
5
5
|
import { Number, NumberPrimitive, NumberProxy } from "./primitives/Number.mjs";
|
|
6
6
|
import { Literal, LiteralPrimitive, LiteralProxy, LiteralValue } from "./primitives/Literal.mjs";
|
|
@@ -13,7 +13,7 @@ import { InferTreeSetInput, InferTreeSnapshot, Tree, TreeNodeDataSetInput, TreeN
|
|
|
13
13
|
|
|
14
14
|
//#region src/Primitive.d.ts
|
|
15
15
|
declare namespace Primitive_d_exports {
|
|
16
|
-
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSetInput, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MakeOptional, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, PartialFields, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators };
|
|
16
|
+
export { AnyPrimitive, AnyTreeNodePrimitive, Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySetInput, ArraySnapshot, ArrayState, ArrayUpdateInput, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySetInput, InferLazySnapshot, InferLazyState, InferLazyUpdateInput, InferProxy, InferSetInput, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSetInput, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, InferUpdateInput, IsDefined, IsRequired, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MakeOptional, MakeOptionalNoDefault, MaybeUndefined, NeedsValue, Number, NumberPrimitive, NumberProxy, Optional, PartialFields, PartialFieldsNoDefault, Primitive, PrimitiveInternal, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSetInput, TreeNodeSetInputUnion, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeSetInput, TreeState, TreeUpdateInput, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators };
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
export { Primitive_d_exports };
|
|
@@ -223,13 +223,19 @@ var StructPrimitive = class StructPrimitive {
|
|
|
223
223
|
validators: []
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
partial(options) {
|
|
227
|
+
const stripDefaults = options === null || options === void 0 ? void 0 : options.stripDefaults;
|
|
228
228
|
const partialFields = {};
|
|
229
229
|
for (const key in this._schema.fields) {
|
|
230
230
|
const field = this._schema.fields[key];
|
|
231
|
-
partialFields[key] = this._makeFieldOptional(field);
|
|
231
|
+
partialFields[key] = this._makeFieldOptional(field, stripDefaults);
|
|
232
232
|
}
|
|
233
|
+
if (stripDefaults) return new StructPrimitive({
|
|
234
|
+
required: this._schema.required,
|
|
235
|
+
defaultValue: void 0,
|
|
236
|
+
fields: partialFields,
|
|
237
|
+
validators: []
|
|
238
|
+
});
|
|
233
239
|
return new StructPrimitive({
|
|
234
240
|
required: this._schema.required,
|
|
235
241
|
defaultValue: void 0,
|
|
@@ -237,13 +243,46 @@ var StructPrimitive = class StructPrimitive {
|
|
|
237
243
|
validators: []
|
|
238
244
|
});
|
|
239
245
|
}
|
|
240
|
-
_makeFieldOptional(field) {
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
_makeFieldOptional(field, stripDefaults) {
|
|
247
|
+
const maybeStripped = stripDefaults ? this._stripDefaultsRecursively(field) : field;
|
|
248
|
+
const fieldWithSchema = maybeStripped;
|
|
249
|
+
if (fieldWithSchema._schema && typeof fieldWithSchema._schema === "object") {
|
|
250
|
+
const Constructor = maybeStripped.constructor;
|
|
251
|
+
return new Constructor(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, fieldWithSchema._schema), {}, { required: false }));
|
|
252
|
+
}
|
|
253
|
+
return maybeStripped;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Recursively strips defaults from a primitive and nested child primitives.
|
|
257
|
+
* This is used by partial({ stripDefaults: true }) so omitted fields resolve to undefined.
|
|
258
|
+
*/
|
|
259
|
+
_stripDefaultsRecursively(field) {
|
|
260
|
+
const fieldWithSchema = field;
|
|
261
|
+
if (!fieldWithSchema._schema || typeof fieldWithSchema._schema !== "object") return field;
|
|
262
|
+
const nextSchema = require_objectSpread2._objectSpread2({}, fieldWithSchema._schema);
|
|
263
|
+
if (nextSchema["fields"] && typeof nextSchema["fields"] === "object" && !Array.isArray(nextSchema["fields"])) {
|
|
264
|
+
const nextFields = {};
|
|
265
|
+
for (const key in nextSchema["fields"]) {
|
|
266
|
+
const nestedField = nextSchema["fields"][key];
|
|
267
|
+
nextFields[key] = this._stripDefaultsRecursively(nestedField);
|
|
268
|
+
}
|
|
269
|
+
nextSchema["fields"] = nextFields;
|
|
270
|
+
}
|
|
271
|
+
if (nextSchema["element"] && typeof nextSchema["element"] === "object") nextSchema["element"] = this._stripDefaultsRecursively(nextSchema["element"]);
|
|
272
|
+
if (Array.isArray(nextSchema["variants"])) nextSchema["variants"] = nextSchema["variants"].map((variant) => this._stripDefaultsRecursively(variant));
|
|
273
|
+
else if (nextSchema["variants"] && typeof nextSchema["variants"] === "object") {
|
|
274
|
+
const nextVariants = {};
|
|
275
|
+
for (const key in nextSchema["variants"]) {
|
|
276
|
+
const nestedVariant = nextSchema["variants"][key];
|
|
277
|
+
nextVariants[key] = this._stripDefaultsRecursively(nestedVariant);
|
|
278
|
+
}
|
|
279
|
+
nextSchema["variants"] = nextVariants;
|
|
245
280
|
}
|
|
246
|
-
|
|
281
|
+
if (nextSchema["root"] && typeof nextSchema["root"] === "object") nextSchema["root"] = this._stripDefaultsRecursively(nextSchema["root"]);
|
|
282
|
+
if ("defaultValue" in nextSchema) nextSchema["defaultValue"] = void 0;
|
|
283
|
+
if ("defaultInput" in nextSchema) nextSchema["defaultInput"] = void 0;
|
|
284
|
+
const Constructor = field.constructor;
|
|
285
|
+
return new Constructor(nextSchema);
|
|
247
286
|
}
|
|
248
287
|
_isRequiredWithoutDefault(field) {
|
|
249
288
|
var _schema;
|
|
@@ -53,11 +53,20 @@ type StructUpdateValue<TFields extends Record<string, AnyPrimitive>> = { readonl
|
|
|
53
53
|
* Preserves the primitive structure while changing the required flag.
|
|
54
54
|
*/
|
|
55
55
|
type MakeOptional<T extends AnyPrimitive> = T extends Primitive<infer S, infer P, any, infer H, infer SI, infer UI> ? Primitive<S, P, false, H, SI, UI> : T;
|
|
56
|
+
/**
|
|
57
|
+
* Transforms a primitive type to make it optional and strip its default (TRequired = false, THasDefault = false).
|
|
58
|
+
*/
|
|
59
|
+
type MakeOptionalNoDefault<T extends AnyPrimitive> = T extends Primitive<infer S, infer P, any, any, infer SI, infer UI> ? Primitive<S, P, false, false, SI, UI> : T;
|
|
56
60
|
/**
|
|
57
61
|
* Maps each field in a struct to its optional version.
|
|
58
62
|
* All fields become optional (TRequired = false).
|
|
59
63
|
*/
|
|
60
64
|
type PartialFields<TFields extends Record<string, AnyPrimitive>> = { [K in keyof TFields]: MakeOptional<TFields[K]> };
|
|
65
|
+
/**
|
|
66
|
+
* Maps each field in a struct to its optional version with defaults stripped.
|
|
67
|
+
* All fields become optional (TRequired = false) and lose their defaults (THasDefault = false).
|
|
68
|
+
*/
|
|
69
|
+
type PartialFieldsNoDefault<TFields extends Record<string, AnyPrimitive>> = { [K in keyof TFields]: MakeOptionalNoDefault<TFields[K]> };
|
|
61
70
|
/**
|
|
62
71
|
* Maps a schema definition to its proxy type.
|
|
63
72
|
* Provides nested field access + get()/set()/toSnapshot() methods for the whole struct.
|
|
@@ -99,14 +108,24 @@ declare class StructPrimitive<TFields extends Record<string, AnyPrimitive>, TReq
|
|
|
99
108
|
refine(fn: (value: InferStructState<TFields>) => boolean, message: string): StructPrimitive<TFields, TRequired, THasDefault>;
|
|
100
109
|
/** Extend this struct with additional fields */
|
|
101
110
|
extend<TNewFields extends Record<string, AnyPrimitive>>(newFields: TNewFields): StructPrimitive<TFields & TNewFields, TRequired, THasDefault>;
|
|
102
|
-
/** Make all properties of this struct optional (TRequired = false for all fields) */
|
|
103
|
-
partial(
|
|
111
|
+
/** Make all properties of this struct optional (TRequired = false for all fields), optionally stripping defaults */
|
|
112
|
+
partial(options: {
|
|
113
|
+
stripDefaults: true;
|
|
114
|
+
}): StructPrimitive<PartialFieldsNoDefault<TFields>, TRequired, THasDefault>;
|
|
115
|
+
partial(options?: {
|
|
116
|
+
stripDefaults?: boolean;
|
|
117
|
+
}): StructPrimitive<PartialFields<TFields>, TRequired, THasDefault>;
|
|
104
118
|
private _makeFieldOptional;
|
|
119
|
+
/**
|
|
120
|
+
* Recursively strips defaults from a primitive and nested child primitives.
|
|
121
|
+
* This is used by partial({ stripDefaults: true }) so omitted fields resolve to undefined.
|
|
122
|
+
*/
|
|
123
|
+
private _stripDefaultsRecursively;
|
|
105
124
|
private _isRequiredWithoutDefault;
|
|
106
125
|
readonly _internal: PrimitiveInternal<InferStructState<TFields>, StructProxy<TFields, TRequired, THasDefault>>;
|
|
107
126
|
}
|
|
108
127
|
/** Creates a new StructPrimitive with the given fields */
|
|
109
128
|
declare const Struct: <TFields extends Record<string, AnyPrimitive>>(fields: TFields) => StructPrimitive<TFields, false, false>;
|
|
110
129
|
//#endregion
|
|
111
|
-
export { InferStructSnapshot, InferStructState, MakeOptional, PartialFields, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue };
|
|
130
|
+
export { InferStructSnapshot, InferStructState, MakeOptional, MakeOptionalNoDefault, PartialFields, PartialFieldsNoDefault, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue };
|
|
112
131
|
//# sourceMappingURL=Struct.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Struct.d.cts","names":[],"sources":["../../src/primitives/Struct.ts"],"sourcesContent":[],"mappings":";;;;;;AAM8L;AAYhJ;KAAzC,gBAK+C,CAAA,CAAA,CAAA,GALzB,CAKyB,SALf,SAKe,CAAA,GAAA,EAAA,GAAA,EAAA,IAAA,EAAA,KAAA,CAAA,GAAA,IAAA,GAAA,KAAA;;;;KAA/C,eAC4C,CAAA,gB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4FyC,SA5FzC,EA4FoD,WA5FpD,CAAA;EAAxC,OAAA,CAAA,OAEG,CAFH,EAAA;IAE0B,aAAA,CAAA,EAAA,OAAA;EAAvB,CAAA,CAAA,EA2FkC,eA3FlC,CA2FkD,aA3FlD,CA2FgE,OA3FhE,CAAA,EA2F0E,SA3F1E,EA2FqF,WA3FrF,CAAA;EAEmC,QAAA,kBAAA;EAApB;;;;EAAD,QAAA,yBAAA;EAGpB,QAAA,yBAAqB;EAAgC,SAAA,SAAA,EAmMzC,iBAnMyC,CAmMvB,gBAnMuB,CAmMN,OAnMM,CAAA,EAmMI,WAnMJ,CAmMgB,OAnMhB,EAmMyB,SAnMzB,EAmMoC,WAnMpC,CAAA,CAAA;;;AAEtC,cAyeZ,MAzeY,EAAA,CAAA,gBAyec,MAzed,CAAA,MAAA,EAye6B,YAze7B,CAAA,CAAA,CAAA,MAAA,EA0ef,OA1ee,EAAA,GA2etB,eA3esB,CA2eN,OA3eM,EAAA,KAAA,EAAA,KAAA,CAAA"}
|
|
@@ -54,11 +54,20 @@ type StructUpdateValue<TFields extends Record<string, AnyPrimitive>> = { readonl
|
|
|
54
54
|
* Preserves the primitive structure while changing the required flag.
|
|
55
55
|
*/
|
|
56
56
|
type MakeOptional<T extends AnyPrimitive> = T extends Primitive<infer S, infer P, any, infer H, infer SI, infer UI> ? Primitive<S, P, false, H, SI, UI> : T;
|
|
57
|
+
/**
|
|
58
|
+
* Transforms a primitive type to make it optional and strip its default (TRequired = false, THasDefault = false).
|
|
59
|
+
*/
|
|
60
|
+
type MakeOptionalNoDefault<T extends AnyPrimitive> = T extends Primitive<infer S, infer P, any, any, infer SI, infer UI> ? Primitive<S, P, false, false, SI, UI> : T;
|
|
57
61
|
/**
|
|
58
62
|
* Maps each field in a struct to its optional version.
|
|
59
63
|
* All fields become optional (TRequired = false).
|
|
60
64
|
*/
|
|
61
65
|
type PartialFields<TFields extends Record<string, AnyPrimitive>> = { [K in keyof TFields]: MakeOptional<TFields[K]> };
|
|
66
|
+
/**
|
|
67
|
+
* Maps each field in a struct to its optional version with defaults stripped.
|
|
68
|
+
* All fields become optional (TRequired = false) and lose their defaults (THasDefault = false).
|
|
69
|
+
*/
|
|
70
|
+
type PartialFieldsNoDefault<TFields extends Record<string, AnyPrimitive>> = { [K in keyof TFields]: MakeOptionalNoDefault<TFields[K]> };
|
|
62
71
|
/**
|
|
63
72
|
* Maps a schema definition to its proxy type.
|
|
64
73
|
* Provides nested field access + get()/set()/toSnapshot() methods for the whole struct.
|
|
@@ -100,14 +109,24 @@ declare class StructPrimitive<TFields extends Record<string, AnyPrimitive>, TReq
|
|
|
100
109
|
refine(fn: (value: InferStructState<TFields>) => boolean, message: string): StructPrimitive<TFields, TRequired, THasDefault>;
|
|
101
110
|
/** Extend this struct with additional fields */
|
|
102
111
|
extend<TNewFields extends Record<string, AnyPrimitive>>(newFields: TNewFields): StructPrimitive<TFields & TNewFields, TRequired, THasDefault>;
|
|
103
|
-
/** Make all properties of this struct optional (TRequired = false for all fields) */
|
|
104
|
-
partial(
|
|
112
|
+
/** Make all properties of this struct optional (TRequired = false for all fields), optionally stripping defaults */
|
|
113
|
+
partial(options: {
|
|
114
|
+
stripDefaults: true;
|
|
115
|
+
}): StructPrimitive<PartialFieldsNoDefault<TFields>, TRequired, THasDefault>;
|
|
116
|
+
partial(options?: {
|
|
117
|
+
stripDefaults?: boolean;
|
|
118
|
+
}): StructPrimitive<PartialFields<TFields>, TRequired, THasDefault>;
|
|
105
119
|
private _makeFieldOptional;
|
|
120
|
+
/**
|
|
121
|
+
* Recursively strips defaults from a primitive and nested child primitives.
|
|
122
|
+
* This is used by partial({ stripDefaults: true }) so omitted fields resolve to undefined.
|
|
123
|
+
*/
|
|
124
|
+
private _stripDefaultsRecursively;
|
|
106
125
|
private _isRequiredWithoutDefault;
|
|
107
126
|
readonly _internal: PrimitiveInternal<InferStructState<TFields>, StructProxy<TFields, TRequired, THasDefault>>;
|
|
108
127
|
}
|
|
109
128
|
/** Creates a new StructPrimitive with the given fields */
|
|
110
129
|
declare const Struct: <TFields extends Record<string, AnyPrimitive>>(fields: TFields) => StructPrimitive<TFields, false, false>;
|
|
111
130
|
//#endregion
|
|
112
|
-
export { InferStructSnapshot, InferStructState, MakeOptional, PartialFields, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue };
|
|
131
|
+
export { InferStructSnapshot, InferStructState, MakeOptional, MakeOptionalNoDefault, PartialFields, PartialFieldsNoDefault, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue };
|
|
113
132
|
//# sourceMappingURL=Struct.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Struct.d.mts","names":[],"sources":["../../src/primitives/Struct.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAM8L;AAYhJ,KAAzC,gBAKA,CAAe,CAAA,CAAA,GALO,CAKP,SALiB,SAKjB,CAAA,GAAA,EAAA,GAAA,EAAA,IAAA,EAAA,KAAA,CAAA,GAAA,IAAA,GAAA,KAAA;;;;KAAf,eACoC,CAAA,gBADJ,MACI,CAAA,MAAA,EADW,YACX,CAAA,CAAA,GAAA,QAAQ,MAAnC,OAAmC,GAAzB,gBAAyB,CAAR,OAAQ,CAAA,CAAA,CAAA,CAAA,SAAA,IAAA,GAAmB,CAAnB,GAAA,KAAA,EAAzB,CAAA,MAChB,OADgB,CAAA;;;;AACT,KAKV,eAAA,CAAA,gBAAgC,MAAjB,CAAA,MAAA,EAAgC,YAAhC,CAAA,CAAA,GAAA,QAAgC,MACtC,OADsC,GAC5B,gBAD4B,CACX,OADW,CACH,CADG,CAAA,CAAA,SAAA,IAAA,GAAA,KAAA,GACwB,CADxB,EAAf,CAAA,MAE7B,OAF6B,CAAA;;;;;;;AAEtB,KAQH,cARG,CAAA,gBAQ4B,MAR5B,CAAA,MAAA,EAQ2C,YAR3C,CAAA,CAAA,GAAA,iBASI,eADO,CACS,OADT,CAAA,GACoB,aADpB,CACkC,OADlC,CAC0C,CAD1C,CAAA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