jazz-tools 0.16.1 → 0.16.3
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 +33 -33
- package/CHANGELOG.md +19 -0
- package/dist/{chunk-CL3ROOZM.js → chunk-RAMDW4VL.js} +83 -29
- package/dist/chunk-RAMDW4VL.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/react-core/hooks.d.ts +150 -2
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +7 -2
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +12 -2
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +2 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +3 -6
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts +20 -6
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +3 -3
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +3 -25
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +3 -25
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts +24 -0
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts +2 -3
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +3 -4
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +1 -0
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/react-core/hooks.ts +143 -0
- package/src/tools/coValues/coFeed.ts +12 -4
- package/src/tools/coValues/coList.ts +41 -19
- package/src/tools/coValues/coMap.ts +12 -2
- package/src/tools/coValues/inbox.ts +1 -1
- package/src/tools/coValues/schemaUnion.ts +28 -3
- package/src/tools/exports.ts +0 -1
- package/src/tools/implementation/schema.ts +28 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +2 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +2 -10
- package/src/tools/implementation/zodSchema/typeConverters/CoFieldInit.ts +74 -9
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +9 -4
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +3 -3
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +3 -114
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +5 -129
- package/src/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.ts +79 -0
- package/src/tools/implementation/zodSchema/unionUtils.ts +6 -9
- package/src/tools/implementation/zodSchema/zodSchema.ts +3 -13
- package/src/tools/internal.ts +1 -0
- package/src/tools/subscribe/SubscriptionScope.ts +4 -2
- package/src/tools/subscribe/utils.ts +2 -2
- package/src/tools/tests/coFeed.test.ts +40 -0
- package/src/tools/tests/coList.test.ts +42 -0
- package/src/tools/tests/coMap.test-d.ts +41 -1
- package/src/tools/tests/coMap.test.ts +82 -5
- package/src/tools/tests/groupsAndAccounts.test.ts +54 -0
- package/src/tools/tests/zod.test.ts +16 -0
- package/dist/chunk-CL3ROOZM.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.16.
|
2
|
+
> jazz-tools@0.16.3 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup && pnpm types && pnpm build:svelte
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -107,81 +107,81 @@
|
|
107
107
|
[34mESM[39m Build start
|
108
108
|
[34mCLI[39m Cleaning output folder
|
109
109
|
[34mESM[39m Build start
|
110
|
-
[32mESM[39m [1mdist/react/ssr.js [22m[32m688.00 B[39m
|
111
|
-
[32mESM[39m [1mdist/react/ssr.js.map [22m[32m1.12 KB[39m
|
112
|
-
[32mESM[39m ⚡️ Build success in 15ms
|
113
|
-
[32mESM[39m [1mdist/browser-media-images/index.js [22m[32m2.55 KB[39m
|
114
|
-
[32mESM[39m [1mdist/browser-media-images/index.js.map [22m[32m5.46 KB[39m
|
115
|
-
[32mESM[39m ⚡️ Build success in 20ms
|
116
110
|
[32mESM[39m [1mdist/worker/index.js [22m[32m2.31 KB[39m
|
117
111
|
[32mESM[39m [1mdist/worker/index.js.map [22m[32m4.77 KB[39m
|
118
112
|
[32mESM[39m ⚡️ Build success in 16ms
|
119
113
|
[32mESM[39m [1mdist/tiptap/index.js [22m[32m564.00 B[39m
|
120
114
|
[32mESM[39m [1mdist/tiptap/index.js.map [22m[32m1.21 KB[39m
|
121
|
-
[32mESM[39m ⚡️ Build success in
|
115
|
+
[32mESM[39m ⚡️ Build success in 17ms
|
116
|
+
[32mESM[39m [1mdist/react/ssr.js [22m[32m688.00 B[39m
|
117
|
+
[32mESM[39m [1mdist/react/ssr.js.map [22m[32m1.12 KB[39m
|
118
|
+
[32mESM[39m ⚡️ Build success in 19ms
|
119
|
+
[32mESM[39m [1mdist/browser-media-images/index.js [22m[32m2.55 KB[39m
|
120
|
+
[32mESM[39m [1mdist/browser-media-images/index.js.map [22m[32m5.46 KB[39m
|
121
|
+
[32mESM[39m ⚡️ Build success in 21ms
|
122
122
|
[32mESM[39m [1mdist/react-native-media-images/index.js [22m[32m6.19 KB[39m
|
123
123
|
[32mESM[39m [1mdist/react-native-media-images/index.js.map [22m[32m10.96 KB[39m
|
124
|
-
[32mESM[39m ⚡️ Build success in
|
124
|
+
[32mESM[39m ⚡️ Build success in 18ms
|
125
125
|
[32mESM[39m [1mdist/react-core/index.js [22m[32m8.42 KB[39m
|
126
|
-
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js [22m[32m279.00 B[39m
|
127
126
|
[32mESM[39m [1mdist/react-core/testing.js [22m[32m1.17 KB[39m
|
128
|
-
[32mESM[39m [1mdist/react-core/
|
129
|
-
[32mESM[39m [1mdist/react-core/
|
127
|
+
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js [22m[32m279.00 B[39m
|
128
|
+
[32mESM[39m [1mdist/react-core/index.js.map [22m[32m20.69 KB[39m
|
130
129
|
[32mESM[39m [1mdist/react-core/testing.js.map [22m[32m1.82 KB[39m
|
131
|
-
[32mESM[39m
|
130
|
+
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js.map [22m[32m533.00 B[39m
|
131
|
+
[32mESM[39m ⚡️ Build success in 25ms
|
132
132
|
[32mESM[39m [1mdist/browser/index.js [22m[32m13.43 KB[39m
|
133
133
|
[32mESM[39m [1mdist/browser/index.js.map [22m[32m28.65 KB[39m
|
134
|
-
[32mESM[39m ⚡️ Build success in
|
134
|
+
[32mESM[39m ⚡️ Build success in 38ms
|
135
135
|
[32mESM[39m [1mdist/react-native/index.js [22m[32m2.53 KB[39m
|
136
136
|
[32mESM[39m [1mdist/react-native/testing.js [22m[32m120.00 B[39m
|
137
137
|
[32mESM[39m [1mdist/react-native/crypto.js [22m[32m117.00 B[39m
|
138
138
|
[32mESM[39m [1mdist/react-native/index.js.map [22m[32m5.68 KB[39m
|
139
139
|
[32mESM[39m [1mdist/react-native/testing.js.map [22m[32m176.00 B[39m
|
140
140
|
[32mESM[39m [1mdist/react-native/crypto.js.map [22m[32m174.00 B[39m
|
141
|
-
[32mESM[39m ⚡️ Build success in
|
141
|
+
[32mESM[39m ⚡️ Build success in 35ms
|
142
|
+
[32mESM[39m [1mdist/react/testing.js [22m[32m122.00 B[39m
|
143
|
+
[32mESM[39m [1mdist/react/index.js [22m[32m20.70 KB[39m
|
144
|
+
[32mESM[39m [1mdist/react/testing.js.map [22m[32m165.00 B[39m
|
145
|
+
[32mESM[39m [1mdist/react/index.js.map [22m[32m34.14 KB[39m
|
146
|
+
[32mESM[39m ⚡️ Build success in 36ms
|
142
147
|
[32mESM[39m [1mdist/expo/index.js [22m[32m4.65 KB[39m
|
143
148
|
[32mESM[39m [1mdist/expo/testing.js [22m[32m112.00 B[39m
|
144
149
|
[32mESM[39m [1mdist/expo/crypto.js [22m[32m109.00 B[39m
|
145
150
|
[32mESM[39m [1mdist/expo/index.js.map [22m[32m10.17 KB[39m
|
146
|
-
[32mESM[39m [1mdist/expo/testing.js.map [22m[32m168.00 B[39m
|
147
151
|
[32mESM[39m [1mdist/expo/crypto.js.map [22m[32m166.00 B[39m
|
148
|
-
[32mESM[39m
|
149
|
-
[32mESM[39m
|
152
|
+
[32mESM[39m [1mdist/expo/testing.js.map [22m[32m168.00 B[39m
|
153
|
+
[32mESM[39m ⚡️ Build success in 39ms
|
150
154
|
[32mESM[39m [1mdist/react-native-core/index.js [22m[32m16.95 KB[39m
|
151
155
|
[32mESM[39m [1mdist/react-native-core/testing.js [22m[32m119.00 B[39m
|
152
|
-
[32mESM[39m [1mdist/react-native-core/crypto.js
|
156
|
+
[32mESM[39m [1mdist/react-native-core/crypto.js [22m[32m2.10 KB[39m
|
153
157
|
[32mESM[39m [1mdist/react-native-core/index.js.map [22m[32m33.57 KB[39m
|
154
158
|
[32mESM[39m [1mdist/react-native-core/testing.js.map [22m[32m175.00 B[39m
|
155
|
-
[32mESM[39m
|
156
|
-
[32mESM[39m
|
157
|
-
[32mESM[39m [1mdist/react/index.js [22m[32m20.70 KB[39m
|
158
|
-
[32mESM[39m [1mdist/react/testing.js.map [22m[32m165.00 B[39m
|
159
|
-
[32mESM[39m [1mdist/react/index.js.map [22m[32m34.14 KB[39m
|
160
|
-
[32mESM[39m ⚡️ Build success in 41ms
|
159
|
+
[32mESM[39m [1mdist/react-native-core/crypto.js.map [22m[32m4.25 KB[39m
|
160
|
+
[32mESM[39m ⚡️ Build success in 37ms
|
161
161
|
[32mESM[39m [1mdist/prosemirror/index.js [22m[32m76.90 KB[39m
|
162
162
|
[32mESM[39m [1mdist/prosemirror/index.js.map [22m[32m305.53 KB[39m
|
163
|
-
[32mESM[39m ⚡️ Build success in
|
163
|
+
[32mESM[39m ⚡️ Build success in 51ms
|
164
164
|
[32mESM[39m [1mdist/inspector/index.js [22m[32m60.37 KB[39m
|
165
165
|
[32mESM[39m [1mdist/inspector/index.js.map [22m[32m107.85 KB[39m
|
166
|
-
[32mESM[39m ⚡️ Build success in
|
166
|
+
[32mESM[39m ⚡️ Build success in 57ms
|
167
167
|
[32mESM[39m [1mdist/testing.js [22m[32m6.76 KB[39m
|
168
168
|
[32mESM[39m [1mdist/index.js [22m[32m26.00 KB[39m
|
169
|
-
[32mESM[39m [1mdist/chunk-
|
169
|
+
[32mESM[39m [1mdist/chunk-RAMDW4VL.js [22m[32m150.32 KB[39m
|
170
170
|
[32mESM[39m [1mdist/testing.js.map [22m[32m13.06 KB[39m
|
171
171
|
[32mESM[39m [1mdist/index.js.map [22m[32m52.65 KB[39m
|
172
|
-
[32mESM[39m [1mdist/chunk-
|
173
|
-
[32mESM[39m ⚡️ Build success in
|
172
|
+
[32mESM[39m [1mdist/chunk-RAMDW4VL.js.map [22m[32m359.88 KB[39m
|
173
|
+
[32mESM[39m ⚡️ Build success in 76ms
|
174
174
|
[32mESM[39m [1mdist/inspector/register-custom-element.js [22m[32m218.00 B[39m
|
175
175
|
[32mESM[39m [1mdist/inspector/register-custom-element.js.map [22m[32m314.00 B[39m
|
176
176
|
[32mESM[39m [1mdist/inspector/custom-element-TUXKXSZU.js [22m[32m1.53 MB[39m
|
177
177
|
[32mESM[39m [1mdist/inspector/custom-element-TUXKXSZU.js.map [22m[32m2.35 MB[39m
|
178
|
-
[32mESM[39m ⚡️ Build success in
|
178
|
+
[32mESM[39m ⚡️ Build success in 116ms
|
179
179
|
|
180
|
-
> jazz-tools@0.16.
|
180
|
+
> jazz-tools@0.16.3 types /home/runner/_work/jazz/jazz/packages/jazz-tools
|
181
181
|
> tsc --outDir dist
|
182
182
|
|
183
183
|
|
184
|
-
> jazz-tools@0.16.
|
184
|
+
> jazz-tools@0.16.3 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
|
185
185
|
> rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
|
186
186
|
|
187
187
|
src/svelte -> dist/svelte
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.16.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 43d3511: Streamlined CoValue creation:
|
8
|
+
- CoValues can be created with plain JSON objects. Nested CoValues will be automatically created when necessary.
|
9
|
+
- Optional fields can be ommited (i.e. it's no longer necessary to provide an explicit `undefined` value).
|
10
|
+
- cojson@0.16.3
|
11
|
+
- cojson-storage-indexeddb@0.16.3
|
12
|
+
- cojson-transport-ws@0.16.3
|
13
|
+
|
14
|
+
## 0.16.2
|
15
|
+
|
16
|
+
### Patch Changes
|
17
|
+
|
18
|
+
- cojson@0.16.2
|
19
|
+
- cojson-storage-indexeddb@0.16.2
|
20
|
+
- cojson-transport-ws@0.16.2
|
21
|
+
|
3
22
|
## 0.16.1
|
4
23
|
|
5
24
|
### Patch Changes
|
@@ -406,8 +406,17 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
406
406
|
if (descriptor === "json") {
|
407
407
|
rawInit[key] = initValue;
|
408
408
|
} else if (isRefEncoded(descriptor)) {
|
409
|
-
if (initValue) {
|
410
|
-
|
409
|
+
if (initValue != null) {
|
410
|
+
let refId = initValue.id;
|
411
|
+
if (!refId) {
|
412
|
+
const coValue = instantiateRefEncodedWithInit(
|
413
|
+
descriptor,
|
414
|
+
initValue,
|
415
|
+
owner
|
416
|
+
);
|
417
|
+
refId = coValue.id;
|
418
|
+
}
|
419
|
+
rawInit[key] = refId;
|
411
420
|
}
|
412
421
|
} else if ("encoded" in descriptor) {
|
413
422
|
rawInit[key] = descriptor.encoded.encode(
|
@@ -846,7 +855,7 @@ var _CoList = class _CoList extends Array {
|
|
846
855
|
const { owner } = parseCoValueCreateOptions(options);
|
847
856
|
const instance = new this({ init: items, owner });
|
848
857
|
const raw = owner._raw.createList(
|
849
|
-
toRawItems(items, instance._schema[ItemsSym])
|
858
|
+
toRawItems(items, instance._schema[ItemsSym], owner)
|
850
859
|
);
|
851
860
|
Object.defineProperties(instance, {
|
852
861
|
id: {
|
@@ -859,14 +868,18 @@ var _CoList = class _CoList extends Array {
|
|
859
868
|
}
|
860
869
|
push(...items) {
|
861
870
|
this._raw.appendItems(
|
862
|
-
toRawItems(items, this._schema[ItemsSym]),
|
871
|
+
toRawItems(items, this._schema[ItemsSym], this._owner),
|
863
872
|
void 0,
|
864
873
|
"private"
|
865
874
|
);
|
866
875
|
return this._raw.entries().length;
|
867
876
|
}
|
868
877
|
unshift(...items) {
|
869
|
-
for (const item of toRawItems(
|
878
|
+
for (const item of toRawItems(
|
879
|
+
items,
|
880
|
+
this._schema[ItemsSym],
|
881
|
+
this._owner
|
882
|
+
)) {
|
870
883
|
this._raw.prepend(item);
|
871
884
|
}
|
872
885
|
return this._raw.entries().length;
|
@@ -893,7 +906,11 @@ var _CoList = class _CoList extends Array {
|
|
893
906
|
for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
|
894
907
|
this._raw.delete(idxToDelete);
|
895
908
|
}
|
896
|
-
const rawItems = toRawItems(
|
909
|
+
const rawItems = toRawItems(
|
910
|
+
items,
|
911
|
+
this._schema[ItemsSym],
|
912
|
+
this._owner
|
913
|
+
);
|
897
914
|
if (rawItems.length === 0) {
|
898
915
|
return deleted;
|
899
916
|
}
|
@@ -1026,13 +1043,29 @@ var _CoList = class _CoList extends Array {
|
|
1026
1043
|
};
|
1027
1044
|
_CoList.prototype._type = "CoList";
|
1028
1045
|
var CoList = _CoList;
|
1029
|
-
function toRawItems(items, itemDescriptor) {
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
}
|
1046
|
+
function toRawItems(items, itemDescriptor, owner) {
|
1047
|
+
let rawItems = [];
|
1048
|
+
if (itemDescriptor === "json") {
|
1049
|
+
rawItems = items;
|
1050
|
+
} else if ("encoded" in itemDescriptor) {
|
1051
|
+
rawItems = items?.map((e) => itemDescriptor.encoded.encode(e));
|
1052
|
+
} else if (isRefEncoded(itemDescriptor)) {
|
1053
|
+
rawItems = items?.map((value) => {
|
1054
|
+
if (value == null) return null;
|
1055
|
+
let refId = value.id;
|
1056
|
+
if (!refId) {
|
1057
|
+
const coValue = instantiateRefEncodedWithInit(
|
1058
|
+
itemDescriptor,
|
1059
|
+
value,
|
1060
|
+
owner
|
1061
|
+
);
|
1062
|
+
refId = coValue.id;
|
1063
|
+
}
|
1064
|
+
return refId;
|
1065
|
+
});
|
1066
|
+
} else {
|
1034
1067
|
throw new Error("Invalid element descriptor");
|
1035
|
-
}
|
1068
|
+
}
|
1036
1069
|
return rawItems;
|
1037
1070
|
}
|
1038
1071
|
var CoListProxyHandler = {
|
@@ -1265,7 +1298,16 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1265
1298
|
} else if ("encoded" in itemDescriptor) {
|
1266
1299
|
this._raw.push(itemDescriptor.encoded.encode(item));
|
1267
1300
|
} else if (isRefEncoded(itemDescriptor)) {
|
1268
|
-
|
1301
|
+
let refId = item.id;
|
1302
|
+
if (!refId) {
|
1303
|
+
const coValue = instantiateRefEncodedWithInit(
|
1304
|
+
itemDescriptor,
|
1305
|
+
item,
|
1306
|
+
this._owner
|
1307
|
+
);
|
1308
|
+
refId = coValue.id;
|
1309
|
+
}
|
1310
|
+
this._raw.push(refId);
|
1269
1311
|
}
|
1270
1312
|
}
|
1271
1313
|
/**
|
@@ -2696,6 +2738,10 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
|
|
2696
2738
|
**/
|
2697
2739
|
static Of(discriminator) {
|
2698
2740
|
return class SchemaUnionClass extends _SchemaUnion {
|
2741
|
+
static create(init, owner) {
|
2742
|
+
const ResolvedClass = discriminator(new Map(Object.entries(init)));
|
2743
|
+
return ResolvedClass.create(init, owner);
|
2744
|
+
}
|
2699
2745
|
static fromRaw(raw) {
|
2700
2746
|
const ResolvedClass = discriminator(
|
2701
2747
|
raw
|
@@ -2704,13 +2750,15 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
|
|
2704
2750
|
}
|
2705
2751
|
};
|
2706
2752
|
}
|
2753
|
+
static create(init, owner) {
|
2754
|
+
throw new Error("Not implemented");
|
2755
|
+
}
|
2707
2756
|
/**
|
2708
2757
|
* Create an instance from raw data. This is called internally and should not be used directly.
|
2709
2758
|
* Use {@link SchemaUnion.Of} to create a union type instead.
|
2710
2759
|
*
|
2711
2760
|
* @internal
|
2712
2761
|
*/
|
2713
|
-
// @ts-ignore
|
2714
2762
|
static fromRaw(raw) {
|
2715
2763
|
throw new Error("Not implemented");
|
2716
2764
|
}
|
@@ -2940,11 +2988,21 @@ function ref(arg, options) {
|
|
2940
2988
|
function isRefEncoded(schema) {
|
2941
2989
|
return typeof schema === "object" && "ref" in schema && "optional" in schema && typeof schema.ref === "function";
|
2942
2990
|
}
|
2943
|
-
function
|
2991
|
+
function instantiateRefEncodedFromRaw(schema, raw) {
|
2944
2992
|
return isCoValueClass(schema.ref) ? schema.ref.fromRaw(raw) : schema.ref(
|
2945
2993
|
raw
|
2946
2994
|
).fromRaw(raw);
|
2947
2995
|
}
|
2996
|
+
function instantiateRefEncodedWithInit(schema, init, parentOwner) {
|
2997
|
+
if (!isCoValueClass(schema.ref)) {
|
2998
|
+
throw Error(
|
2999
|
+
`Cannot automatically create CoValue from value: ${JSON.stringify(init)}. Use the CoValue schema's create() method instead.`
|
3000
|
+
);
|
3001
|
+
}
|
3002
|
+
const owner = Group.create();
|
3003
|
+
owner.addMember(parentOwner.castAs(Group));
|
3004
|
+
return schema.ref.create(init, owner);
|
3005
|
+
}
|
2948
3006
|
|
2949
3007
|
// src/tools/lib/migration.ts
|
2950
3008
|
function applyCoValueMigrations(instance) {
|
@@ -3063,7 +3121,7 @@ function getOwnerFromRawValue(raw) {
|
|
3063
3121
|
);
|
3064
3122
|
}
|
3065
3123
|
function createCoValue(ref2, raw, subscriptionScope) {
|
3066
|
-
const freshValueInstance =
|
3124
|
+
const freshValueInstance = instantiateRefEncodedFromRaw(ref2, raw);
|
3067
3125
|
Object.defineProperty(freshValueInstance, "_subscriptionScope", {
|
3068
3126
|
value: subscriptionScope,
|
3069
3127
|
writable: false,
|
@@ -3138,7 +3196,9 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3138
3196
|
return;
|
3139
3197
|
}
|
3140
3198
|
this.migrating = true;
|
3141
|
-
applyCoValueMigrations(
|
3199
|
+
applyCoValueMigrations(
|
3200
|
+
instantiateRefEncodedFromRaw(this.schema, value)
|
3201
|
+
);
|
3142
3202
|
this.migrated = true;
|
3143
3203
|
this.handleUpdate(lastUpdate);
|
3144
3204
|
return;
|
@@ -4182,7 +4242,6 @@ function enrichAccountSchema(schema, coValueClass) {
|
|
4182
4242
|
}
|
4183
4243
|
|
4184
4244
|
// src/tools/implementation/zodSchema/unionUtils.ts
|
4185
|
-
import { RawCoList } from "cojson";
|
4186
4245
|
function schemaUnionDiscriminatorFor(schema) {
|
4187
4246
|
if (isUnionOfCoMapsDeeply(schema)) {
|
4188
4247
|
const definition = schema.getDefinition();
|
@@ -4216,17 +4275,12 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
4216
4275
|
);
|
4217
4276
|
}
|
4218
4277
|
}
|
4219
|
-
const determineSchema = (
|
4220
|
-
if (_raw instanceof RawCoList) {
|
4221
|
-
throw new Error(
|
4222
|
-
"co.discriminatedUnion() of collaborative types is not supported for CoLists"
|
4223
|
-
);
|
4224
|
-
}
|
4278
|
+
const determineSchema = (discriminable) => {
|
4225
4279
|
for (const option of availableOptions) {
|
4226
4280
|
let match = true;
|
4227
4281
|
for (const key of Object.keys(discriminatorMap)) {
|
4228
4282
|
const discriminatorDef = option.getDefinition().shape[key];
|
4229
|
-
const discriminatorValue =
|
4283
|
+
const discriminatorValue = discriminable.get(key);
|
4230
4284
|
if (discriminatorValue && typeof discriminatorValue === "object") {
|
4231
4285
|
throw new Error("Discriminator must be a primitive value");
|
4232
4286
|
}
|
@@ -5075,9 +5129,9 @@ function isAccountInstance(instance) {
|
|
5075
5129
|
return "_type" in instance && instance._type === "Account";
|
5076
5130
|
}
|
5077
5131
|
function parseCoValueCreateOptions(options) {
|
5078
|
-
const
|
5132
|
+
const Group10 = RegisteredSchemas["Group"];
|
5079
5133
|
if (!options) {
|
5080
|
-
return { owner:
|
5134
|
+
return { owner: Group10.create(), uniqueness: void 0 };
|
5081
5135
|
}
|
5082
5136
|
if ("_type" in options) {
|
5083
5137
|
if (options._type === "Account" || options._type === "Group") {
|
@@ -5086,7 +5140,7 @@ function parseCoValueCreateOptions(options) {
|
|
5086
5140
|
}
|
5087
5141
|
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
5088
5142
|
return {
|
5089
|
-
owner: options.owner ??
|
5143
|
+
owner: options.owner ?? Group10.create(),
|
5090
5144
|
uniqueness
|
5091
5145
|
};
|
5092
5146
|
}
|
@@ -5211,4 +5265,4 @@ export {
|
|
5211
5265
|
JazzContextManager
|
5212
5266
|
};
|
5213
5267
|
/* istanbul ignore file -- @preserve */
|
5214
|
-
//# sourceMappingURL=chunk-
|
5268
|
+
//# sourceMappingURL=chunk-RAMDW4VL.js.map
|