@voidhash/mimic 1.0.0-beta.14 → 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 +30 -30
- 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.cjs +1 -0
- package/dist/Primitive.d.cts +3 -3
- package/dist/Primitive.d.mts +3 -3
- package/dist/Primitive.mjs +2 -1
- package/dist/client/ClientDocument.cjs +36 -7
- package/dist/client/ClientDocument.d.mts.map +1 -1
- package/dist/client/ClientDocument.mjs +36 -7
- package/dist/client/ClientDocument.mjs.map +1 -1
- package/dist/primitives/Struct.cjs +86 -22
- package/dist/primitives/Struct.d.cts +23 -3
- package/dist/primitives/Struct.d.cts.map +1 -1
- package/dist/primitives/Struct.d.mts +23 -3
- package/dist/primitives/Struct.d.mts.map +1 -1
- package/dist/primitives/Struct.mjs +87 -23
- package/dist/primitives/Struct.mjs.map +1 -1
- package/dist/primitives/shared.cjs +25 -4
- package/dist/primitives/shared.d.cts +2 -1
- package/dist/primitives/shared.d.cts.map +1 -1
- package/dist/primitives/shared.d.mts +2 -1
- package/dist/primitives/shared.d.mts.map +1 -1
- package/dist/primitives/shared.mjs +25 -5
- package/dist/primitives/shared.mjs.map +1 -1
- package/package.json +2 -2
- package/src/Document.ts +13 -4
- package/src/client/ClientDocument.ts +40 -3
- package/src/primitives/Struct.ts +152 -30
- package/src/primitives/shared.ts +59 -5
- package/tests/client/ClientDocument.test.ts +99 -0
- package/tests/primitives/Struct.test.ts +251 -4
- package/tests/primitives/Tree.test.ts +143 -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
|
|
@@ -12,18 +12,19 @@
|
|
|
12
12
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mclient/index.cjs[22m [2m 1.92 kB[22m [2m│ gzip: 0.42 kB[22m
|
|
13
13
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mserver/index.cjs[22m [2m 0.67 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
14
14
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Tree.cjs [2m30.01 kB[22m [2m│ gzip: 4.99 kB[22m
|
|
15
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/ClientDocument.cjs [
|
|
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
20
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/WebSocketTransport.cjs [2m10.98 kB[22m [2m│ gzip: 2.71 kB[22m
|
|
20
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Struct.cjs [2m10.26 kB[22m [2m│ gzip: 2.34 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.
|
|
25
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mDocument.cjs [2m 5.22 kB[22m [2m│ gzip: 1.73 kB[22m
|
|
26
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
|
|
27
28
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/errors.cjs [2m 4.80 kB[22m [2m│ gzip: 0.97 kB[22m
|
|
28
29
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Number.cjs [2m 4.63 kB[22m [2m│ gzip: 1.23 kB[22m
|
|
29
30
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mOperationPath.cjs [2m 4.24 kB[22m [2m│ gzip: 1.19 kB[22m
|
|
@@ -31,11 +32,10 @@
|
|
|
31
32
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Literal.cjs [2m 3.91 kB[22m [2m│ gzip: 1.07 kB[22m
|
|
32
33
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mserver/ServerDocument.cjs [2m 3.74 kB[22m [2m│ gzip: 1.16 kB[22m
|
|
33
34
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mclient/StateMonitor.cjs [2m 3.71 kB[22m [2m│ gzip: 1.27 kB[22m
|
|
34
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/shared.cjs [2m 3.69 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
35
35
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mserver/errors.cjs [2m 3.29 kB[22m [2m│ gzip: 0.70 kB[22m
|
|
36
36
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/TreeNode.cjs [2m 2.67 kB[22m [2m│ gzip: 0.92 kB[22m
|
|
37
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mPrimitive.cjs [2m 2.41 kB[22m [2m│ gzip: 0.61 kB[22m
|
|
37
38
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mPresence.cjs [2m 2.36 kB[22m [2m│ gzip: 0.87 kB[22m
|
|
38
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mPrimitive.cjs [2m 2.34 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
39
39
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Lazy.cjs [2m 1.81 kB[22m [2m│ gzip: 0.57 kB[22m
|
|
40
40
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mOperation.cjs [2m 1.75 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
41
41
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mTransaction.cjs [2m 1.66 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
@@ -52,14 +52,14 @@
|
|
|
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
|
|
61
61
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Either.d.cts.map [2m 3.12 kB[22m [2m│ gzip: 1.26 kB[22m
|
|
62
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/shared.d.cts.map [2m 2.
|
|
62
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/shared.d.cts.map [2m 2.31 kB[22m [2m│ gzip: 0.92 kB[22m
|
|
63
63
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/TreeNode.d.cts.map [2m 2.27 kB[22m [2m│ gzip: 1.01 kB[22m
|
|
64
64
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/String.d.cts.map [2m 2.26 kB[22m [2m│ gzip: 1.00 kB[22m
|
|
65
65
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mprimitives/Literal.d.cts.map [2m 2.16 kB[22m [2m│ gzip: 0.99 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
|
|
95
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/shared.d.cts[39m [2m 6.99 kB[22m [2m│ gzip: 2.12 kB[22m
|
|
94
96
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mclient/ClientDocument.d.cts[39m [2m 6.99 kB[22m [2m│ gzip: 2.01 kB[22m
|
|
95
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/Struct.d.cts[39m [2m 6.93 kB[22m [2m│ gzip: 1.84 kB[22m
|
|
96
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mprimitives/shared.d.cts[39m [2m 6.89 kB[22m [2m│ gzip: 2.09 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,34 +120,34 @@
|
|
|
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
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/ClientDocument.mjs.map [
|
|
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
133
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Array.mjs.map [2m26.06 kB[22m [2m│ gzip: 6.49 kB[22m
|
|
133
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.mjs.map [2m25.49 kB[22m [2m│ gzip: 6.51 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
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/ClientDocument.mjs [2m24.17 kB[22m [2m│ gzip: 5.32 kB[22m
|
|
135
136
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/WebSocketTransport.mjs.map [2m23.44 kB[22m [2m│ gzip: 5.75 kB[22m
|
|
136
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/ClientDocument.mjs [2m22.98 kB[22m [2m│ gzip: 5.08 kB[22m
|
|
137
137
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Union.mjs.map [2m18.59 kB[22m [2m│ gzip: 4.65 kB[22m
|
|
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.92 kB[22m [2m│ gzip: 4.54 kB[22m
|
|
141
142
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/Rebase.mjs.map [2m14.15 kB[22m [2m│ gzip: 3.21 kB[22m
|
|
142
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
|
|
143
145
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils/tree-helpers.mjs [2m13.31 kB[22m [2m│ gzip: 3.15 kB[22m
|
|
144
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[
|
|
145
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.mjs.map [2m13.14 kB[22m [2m│ gzip: 3.69 kB[22m
|
|
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
149
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/StateMonitor.mjs.map [2m10.39 kB[22m [2m│ gzip: 3.04 kB[22m
|
|
149
150
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/String.mjs.map [2m 9.73 kB[22m [2m│ gzip: 2.71 kB[22m
|
|
150
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Struct.mjs [2m 9.32 kB[22m [2m│ gzip: 2.32 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
|
|
152
152
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Number.mjs.map [2m 8.75 kB[22m [2m│ gzip: 2.43 kB[22m
|
|
153
153
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/Rebase.mjs [2m 7.61 kB[22m [2m│ gzip: 1.73 kB[22m
|
|
@@ -160,8 +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/[
|
|
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
|
|
165
166
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Lazy.mjs.map [2m 4.59 kB[22m [2m│ gzip: 1.40 kB[22m
|
|
166
167
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mPresence.mjs.map [2m 4.56 kB[22m [2m│ gzip: 1.30 kB[22m
|
|
167
168
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/String.mjs [2m 4.44 kB[22m [2m│ gzip: 1.35 kB[22m
|
|
@@ -173,7 +174,6 @@
|
|
|
173
174
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils/tree-helpers.d.mts.map [2m 3.61 kB[22m [2m│ gzip: 1.31 kB[22m
|
|
174
175
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/StateMonitor.mjs [2m 3.60 kB[22m [2m│ gzip: 1.23 kB[22m
|
|
175
176
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mserver/ServerDocument.mjs [2m 3.56 kB[22m [2m│ gzip: 1.13 kB[22m
|
|
176
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.mjs [2m 3.55 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
177
177
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Boolean.mjs [2m 3.43 kB[22m [2m│ gzip: 1.05 kB[22m
|
|
178
178
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Literal.mjs [2m 3.33 kB[22m [2m│ gzip: 1.05 kB[22m
|
|
179
179
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Array.d.mts.map [2m 3.26 kB[22m [2m│ gzip: 1.35 kB[22m
|
|
@@ -185,12 +185,12 @@
|
|
|
185
185
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/TreeNode.d.mts.map [2m 2.45 kB[22m [2m│ gzip: 1.07 kB[22m
|
|
186
186
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mProxyEnvironment.mjs.map [2m 2.42 kB[22m [2m│ gzip: 0.93 kB[22m
|
|
187
187
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/TreeNode.mjs [2m 2.42 kB[22m [2m│ gzip: 0.93 kB[22m
|
|
188
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.d.mts.map [2m 2.
|
|
188
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.d.mts.map [2m 2.31 kB[22m [2m│ gzip: 0.92 kB[22m
|
|
189
189
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/String.d.mts.map [2m 2.26 kB[22m [2m│ gzip: 1.00 kB[22m
|
|
190
190
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Literal.d.mts.map [2m 2.16 kB[22m [2m│ gzip: 0.99 kB[22m
|
|
191
191
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mPresence.mjs [2m 2.15 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
192
192
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Number.d.mts.map [2m 2.13 kB[22m [2m│ gzip: 0.95 kB[22m
|
|
193
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mPrimitive.mjs [2m
|
|
193
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mPrimitive.mjs [2m 2.06 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
194
194
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/ClientDocument.d.mts.map [2m 1.85 kB[22m [2m│ gzip: 0.79 kB[22m
|
|
195
195
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Boolean.d.mts.map [2m 1.76 kB[22m [2m│ gzip: 0.81 kB[22m
|
|
196
196
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Lazy.mjs [2m 1.57 kB[22m [2m│ gzip: 0.58 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
241
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/ClientDocument.d.mts[39m [2m 7.02 kB[22m [2m│ gzip: 2.02 kB[22m
|
|
241
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/
|
|
242
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mprimitives/shared.d.mts[39m [2m 6.89 kB[22m [2m│ gzip: 2.09 kB[22m
|
|
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;GACL,KAAK,IAA8C;AACjD,QAAI,GAAG,cAAc;KAC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AC7C,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,yBACd,OAAO,UAAU,uBAAuB,QAAQ,QAAQ,GACxD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CAAC;;EAGhD"}
|
package/dist/Primitive.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var Primitive_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
|
40
40
|
ValidationError: () => require_shared.ValidationError,
|
|
41
41
|
applyDefaults: () => require_shared.applyDefaults,
|
|
42
42
|
isCompatibleOperation: () => require_shared.isCompatibleOperation,
|
|
43
|
+
primitiveAllowsNullValue: () => require_shared.primitiveAllowsNullValue,
|
|
43
44
|
runValidators: () => require_shared.runValidators
|
|
44
45
|
});
|
|
45
46
|
|
package/dist/Primitive.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnyPrimitive, HasDefault, InferProxy, InferSetInput, InferSnapshot, InferState, InferUpdateInput, IsDefined, IsRequired, MaybeUndefined, NeedsValue, Optional, Primitive, PrimitiveInternal, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators } from "./primitives/shared.cjs";
|
|
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, 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
|
-
import { AnyPrimitive, HasDefault, InferProxy, InferSetInput, InferSnapshot, InferState, InferUpdateInput, IsDefined, IsRequired, MaybeUndefined, NeedsValue, Optional, Primitive, PrimitiveInternal, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators } from "./primitives/shared.mjs";
|
|
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, 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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __export } from "./_virtual/rolldown_runtime.mjs";
|
|
2
|
-
import { ValidationError, applyDefaults, isCompatibleOperation, runValidators } from "./primitives/shared.mjs";
|
|
2
|
+
import { ValidationError, applyDefaults, isCompatibleOperation, primitiveAllowsNullValue, runValidators } from "./primitives/shared.mjs";
|
|
3
3
|
import { String, StringPrimitive } from "./primitives/String.mjs";
|
|
4
4
|
import { Struct, StructPrimitive } from "./primitives/Struct.mjs";
|
|
5
5
|
import { Boolean, BooleanPrimitive } from "./primitives/Boolean.mjs";
|
|
@@ -40,6 +40,7 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
40
40
|
ValidationError: () => ValidationError,
|
|
41
41
|
applyDefaults: () => applyDefaults,
|
|
42
42
|
isCompatibleOperation: () => isCompatibleOperation,
|
|
43
|
+
primitiveAllowsNullValue: () => primitiveAllowsNullValue,
|
|
43
44
|
runValidators: () => runValidators
|
|
44
45
|
});
|
|
45
46
|
|
|
@@ -174,11 +174,15 @@ const make = (options) => {
|
|
|
174
174
|
* If disconnected, the transport will queue it for later submission.
|
|
175
175
|
*/
|
|
176
176
|
const submitTransaction = (tx) => {
|
|
177
|
+
var _Error$stack;
|
|
177
178
|
debugLog("submitTransaction", {
|
|
178
179
|
txId: tx.id,
|
|
179
180
|
ops: tx.ops,
|
|
180
181
|
pendingCount: _pending.length + 1,
|
|
181
|
-
isConnected: transport.isConnected()
|
|
182
|
+
isConnected: transport.isConnected(),
|
|
183
|
+
activeDraftCount: _drafts.size,
|
|
184
|
+
activeDraftIds: Array.from(_drafts.keys()),
|
|
185
|
+
callStack: (_Error$stack = (/* @__PURE__ */ new Error()).stack) === null || _Error$stack === void 0 ? void 0 : _Error$stack.split("\n").slice(1, 6).join("\n")
|
|
182
186
|
});
|
|
183
187
|
const pending = {
|
|
184
188
|
transaction: tx,
|
|
@@ -475,10 +479,14 @@ const make = (options) => {
|
|
|
475
479
|
getPendingCount: () => _pending.length,
|
|
476
480
|
hasPendingChanges: () => _pending.length > 0,
|
|
477
481
|
transaction: (fn) => {
|
|
482
|
+
var _Error$stack2;
|
|
478
483
|
debugLog("transaction: starting", {
|
|
479
484
|
isConnected: transport.isConnected(),
|
|
480
485
|
isReady: _initState.type === "ready",
|
|
481
|
-
pendingCount: _pending.length
|
|
486
|
+
pendingCount: _pending.length,
|
|
487
|
+
activeDraftCount: _drafts.size,
|
|
488
|
+
activeDraftIds: Array.from(_drafts.keys()),
|
|
489
|
+
callStack: (_Error$stack2 = (/* @__PURE__ */ new Error()).stack) === null || _Error$stack2 === void 0 ? void 0 : _Error$stack2.split("\n").slice(1, 6).join("\n")
|
|
482
490
|
});
|
|
483
491
|
if (_initState.type !== "ready") throw new require_errors.InvalidStateError("Client is not ready. Wait for initialization to complete.");
|
|
484
492
|
const result = _optimisticDoc.transaction(fn);
|
|
@@ -579,6 +587,12 @@ const make = (options) => {
|
|
|
579
587
|
return {
|
|
580
588
|
id: draftId,
|
|
581
589
|
update: (fn) => {
|
|
590
|
+
debugLog("draft.update: starting", {
|
|
591
|
+
draftId,
|
|
592
|
+
consumed,
|
|
593
|
+
currentOpsCount: draftState.ops.size,
|
|
594
|
+
pendingCount: _pending.length
|
|
595
|
+
});
|
|
582
596
|
if (consumed) throw new require_errors.InvalidStateError("Draft has already been committed or discarded.");
|
|
583
597
|
const baseDoc = require_Document.make(schema, { initialState: _serverState });
|
|
584
598
|
for (const pending of _pending) baseDoc.apply(pending.transaction.ops);
|
|
@@ -598,32 +612,47 @@ const make = (options) => {
|
|
|
598
612
|
draftState.ops.set(uniqueKey, op);
|
|
599
613
|
}
|
|
600
614
|
}
|
|
601
|
-
debugLog("draft.update", {
|
|
615
|
+
debugLog("draft.update: complete", {
|
|
602
616
|
draftId,
|
|
603
617
|
newOpsCount: tx.ops.length,
|
|
604
|
-
totalOps: draftState.ops.size
|
|
618
|
+
totalOps: draftState.ops.size,
|
|
619
|
+
note: "Ops stored in draft - NOT sent to server"
|
|
605
620
|
});
|
|
606
621
|
recomputeOptimisticState();
|
|
607
622
|
notifyDraftChange();
|
|
608
623
|
},
|
|
609
624
|
commit: () => {
|
|
625
|
+
debugLog("draft.commit: starting", {
|
|
626
|
+
draftId,
|
|
627
|
+
consumed,
|
|
628
|
+
opsCount: draftState.ops.size
|
|
629
|
+
});
|
|
610
630
|
if (consumed) throw new require_errors.InvalidStateError("Draft has already been committed or discarded.");
|
|
611
631
|
consumed = true;
|
|
612
632
|
const ops = Array.from(draftState.ops.values());
|
|
613
633
|
_drafts.delete(draftId);
|
|
614
|
-
debugLog("draft.commit", {
|
|
634
|
+
debugLog("draft.commit: submitting", {
|
|
615
635
|
draftId,
|
|
616
|
-
opsCount: ops.length
|
|
636
|
+
opsCount: ops.length,
|
|
637
|
+
note: ops.length > 0 ? "Will call submitTransaction" : "Empty draft - no transaction"
|
|
617
638
|
});
|
|
618
639
|
if (ops.length > 0) submitTransaction(require_Transaction.make(ops));
|
|
619
640
|
recomputeOptimisticState();
|
|
620
641
|
notifyDraftChange();
|
|
621
642
|
},
|
|
622
643
|
discard: () => {
|
|
644
|
+
debugLog("draft.discard: starting", {
|
|
645
|
+
draftId,
|
|
646
|
+
consumed,
|
|
647
|
+
opsCount: draftState.ops.size
|
|
648
|
+
});
|
|
623
649
|
if (consumed) throw new require_errors.InvalidStateError("Draft has already been committed or discarded.");
|
|
624
650
|
consumed = true;
|
|
625
651
|
_drafts.delete(draftId);
|
|
626
|
-
debugLog("draft.discard", {
|
|
652
|
+
debugLog("draft.discard: complete", {
|
|
653
|
+
draftId,
|
|
654
|
+
note: "Draft discarded - no transaction sent to server"
|
|
655
|
+
});
|
|
627
656
|
recomputeOptimisticState();
|
|
628
657
|
notifyDraftChange();
|
|
629
658
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientDocument.d.mts","names":[],"sources":["../../src/client/ClientDocument.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;UA6BiB,4BAA4B;;;;oBAIzB,WAAqB;;;;;;AAJzC;;;AAIoB,UAwCH,gBAxCG,CAAA,MAAA,CAAA,CAAA;EAAoB;EAwCvB,SAAA,gBAAgB,CAAA,EAAA,GAAA,GAAA,IAAA;AAQjC;;;;AAiByB,UAjBR,cAiBQ,CAAA,KAAA,CAAA,CAAA;EAKwC;;;;EAkBf,SAAA,MAAA,EAAA,GAAA,GAAA,MAAA,GAAA,SAAA;EAAjB;;AAMjC;;EAEoB,SAAA,IAAA,EAAA,GAAA,GArCG,KAqCH,GAAA,SAAA;EAGD;;;;EASF,SAAA,MAAA,EAAA,GAAA,GA3CQ,WA2CR,CAAA,MAAA,EA3C4B,aA2C5B,CA3CmD,KA2CnD,CAAA,CAAA;EAIuC;;;EAiB3B,SAAA,GAAA,EAAA,GAAA,GA3DP,WA2DO,CAAA,MAAA,EA3Da,aA2Db,CA3DoC,KA2DpC,CAAA,CAAA;EAAkB;;;;AAM/C;EAAwD,SAAA,GAAA,EAAA,CAAA,IAA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CAAA,EAAA,MAAA;EAEa;EAAS,SAAA,WAAA,CAAA,EAAA,MAAA;EAA/B;EACO,SAAA,KAAA,CAAA,EAAA,OAAA;EAAS;;;;sBApHL;;6BAEO,kBAAkB,cAAuB,MAAe;;;;;UAMpE,uCAAuC;;mCAErB,WAAqB;;;;;;;;;;;UAYvC,+BACC,gCACE;;mBAGD;;iBAGF,WAAqB;;SAG7B,WAAqB;;oBAGV,WAAqB;;;;;;;;;;;4BAeb,WAAqB,aAAa,IAAI;;;;aAKrD;;;;;;;;;;;;;;;;;;;;;sBA0BS,uBAAuB;;;;;iBAM5B,YAAY;;;;uBAKN;;;;;qBAMF,kBAAkB,cACjC,eAAe,MAAe;;;;;cAWvB,uBACK,gCACE,8CAET,sBAAsB,SAAS,eACvC,eAAe,SAAS"}
|
|
@@ -174,11 +174,15 @@ const make = (options) => {
|
|
|
174
174
|
* If disconnected, the transport will queue it for later submission.
|
|
175
175
|
*/
|
|
176
176
|
const submitTransaction = (tx) => {
|
|
177
|
+
var _Error$stack;
|
|
177
178
|
debugLog("submitTransaction", {
|
|
178
179
|
txId: tx.id,
|
|
179
180
|
ops: tx.ops,
|
|
180
181
|
pendingCount: _pending.length + 1,
|
|
181
|
-
isConnected: transport.isConnected()
|
|
182
|
+
isConnected: transport.isConnected(),
|
|
183
|
+
activeDraftCount: _drafts.size,
|
|
184
|
+
activeDraftIds: Array.from(_drafts.keys()),
|
|
185
|
+
callStack: (_Error$stack = (/* @__PURE__ */ new Error()).stack) === null || _Error$stack === void 0 ? void 0 : _Error$stack.split("\n").slice(1, 6).join("\n")
|
|
182
186
|
});
|
|
183
187
|
const pending = {
|
|
184
188
|
transaction: tx,
|
|
@@ -475,10 +479,14 @@ const make = (options) => {
|
|
|
475
479
|
getPendingCount: () => _pending.length,
|
|
476
480
|
hasPendingChanges: () => _pending.length > 0,
|
|
477
481
|
transaction: (fn) => {
|
|
482
|
+
var _Error$stack2;
|
|
478
483
|
debugLog("transaction: starting", {
|
|
479
484
|
isConnected: transport.isConnected(),
|
|
480
485
|
isReady: _initState.type === "ready",
|
|
481
|
-
pendingCount: _pending.length
|
|
486
|
+
pendingCount: _pending.length,
|
|
487
|
+
activeDraftCount: _drafts.size,
|
|
488
|
+
activeDraftIds: Array.from(_drafts.keys()),
|
|
489
|
+
callStack: (_Error$stack2 = (/* @__PURE__ */ new Error()).stack) === null || _Error$stack2 === void 0 ? void 0 : _Error$stack2.split("\n").slice(1, 6).join("\n")
|
|
482
490
|
});
|
|
483
491
|
if (_initState.type !== "ready") throw new InvalidStateError("Client is not ready. Wait for initialization to complete.");
|
|
484
492
|
const result = _optimisticDoc.transaction(fn);
|
|
@@ -579,6 +587,12 @@ const make = (options) => {
|
|
|
579
587
|
return {
|
|
580
588
|
id: draftId,
|
|
581
589
|
update: (fn) => {
|
|
590
|
+
debugLog("draft.update: starting", {
|
|
591
|
+
draftId,
|
|
592
|
+
consumed,
|
|
593
|
+
currentOpsCount: draftState.ops.size,
|
|
594
|
+
pendingCount: _pending.length
|
|
595
|
+
});
|
|
582
596
|
if (consumed) throw new InvalidStateError("Draft has already been committed or discarded.");
|
|
583
597
|
const baseDoc = make$2(schema, { initialState: _serverState });
|
|
584
598
|
for (const pending of _pending) baseDoc.apply(pending.transaction.ops);
|
|
@@ -598,32 +612,47 @@ const make = (options) => {
|
|
|
598
612
|
draftState.ops.set(uniqueKey, op);
|
|
599
613
|
}
|
|
600
614
|
}
|
|
601
|
-
debugLog("draft.update", {
|
|
615
|
+
debugLog("draft.update: complete", {
|
|
602
616
|
draftId,
|
|
603
617
|
newOpsCount: tx.ops.length,
|
|
604
|
-
totalOps: draftState.ops.size
|
|
618
|
+
totalOps: draftState.ops.size,
|
|
619
|
+
note: "Ops stored in draft - NOT sent to server"
|
|
605
620
|
});
|
|
606
621
|
recomputeOptimisticState();
|
|
607
622
|
notifyDraftChange();
|
|
608
623
|
},
|
|
609
624
|
commit: () => {
|
|
625
|
+
debugLog("draft.commit: starting", {
|
|
626
|
+
draftId,
|
|
627
|
+
consumed,
|
|
628
|
+
opsCount: draftState.ops.size
|
|
629
|
+
});
|
|
610
630
|
if (consumed) throw new InvalidStateError("Draft has already been committed or discarded.");
|
|
611
631
|
consumed = true;
|
|
612
632
|
const ops = Array.from(draftState.ops.values());
|
|
613
633
|
_drafts.delete(draftId);
|
|
614
|
-
debugLog("draft.commit", {
|
|
634
|
+
debugLog("draft.commit: submitting", {
|
|
615
635
|
draftId,
|
|
616
|
-
opsCount: ops.length
|
|
636
|
+
opsCount: ops.length,
|
|
637
|
+
note: ops.length > 0 ? "Will call submitTransaction" : "Empty draft - no transaction"
|
|
617
638
|
});
|
|
618
639
|
if (ops.length > 0) submitTransaction(make$1(ops));
|
|
619
640
|
recomputeOptimisticState();
|
|
620
641
|
notifyDraftChange();
|
|
621
642
|
},
|
|
622
643
|
discard: () => {
|
|
644
|
+
debugLog("draft.discard: starting", {
|
|
645
|
+
draftId,
|
|
646
|
+
consumed,
|
|
647
|
+
opsCount: draftState.ops.size
|
|
648
|
+
});
|
|
623
649
|
if (consumed) throw new InvalidStateError("Draft has already been committed or discarded.");
|
|
624
650
|
consumed = true;
|
|
625
651
|
_drafts.delete(draftId);
|
|
626
|
-
debugLog("draft.discard", {
|
|
652
|
+
debugLog("draft.discard: complete", {
|
|
653
|
+
draftId,
|
|
654
|
+
note: "Draft discarded - no transaction sent to server"
|
|
655
|
+
});
|
|
627
656
|
recomputeOptimisticState();
|
|
628
657
|
notifyDraftChange();
|
|
629
658
|
}
|