jazz-tools 0.19.2 → 0.19.4
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/.svelte-kit/__package__/jazz.class.svelte.d.ts +2 -2
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/jazz.class.svelte.js +15 -17
- package/.turbo/turbo-build.log +54 -54
- package/CHANGELOG.md +24 -0
- package/dist/{chunk-NCNM6UDZ.js → chunk-PT7FCV26.js} +148 -78
- package/dist/chunk-PT7FCV26.js.map +1 -0
- package/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/dist/inspector/{custom-element-ABVPHX53.js → custom-element-P76EIWEV.js} +322 -146
- package/dist/inspector/custom-element-P76EIWEV.js.map +1 -0
- package/dist/inspector/index.js +302 -126
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/inspector/tests/viewer/co-plain-text-view.test.d.ts +2 -0
- package/dist/inspector/tests/viewer/co-plain-text-view.test.d.ts.map +1 -0
- package/dist/inspector/utils/history.d.ts +5 -1
- package/dist/inspector/utils/history.d.ts.map +1 -1
- package/dist/inspector/utils/permissions.d.ts +3 -0
- package/dist/inspector/utils/permissions.d.ts.map +1 -0
- package/dist/inspector/viewer/co-map-view.d.ts.map +1 -1
- package/dist/inspector/viewer/co-plain-text-view.d.ts +4 -2
- package/dist/inspector/viewer/co-plain-text-view.d.ts.map +1 -1
- package/dist/inspector/viewer/grid-view.d.ts.map +1 -1
- package/dist/inspector/viewer/page.d.ts.map +1 -1
- package/dist/inspector/viewer/use-resolve-covalue.d.ts +0 -1
- package/dist/inspector/viewer/use-resolve-covalue.d.ts.map +1 -1
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +4 -17
- package/dist/react-core/index.js.map +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts +2 -2
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +15 -17
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +7 -6
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/promise.d.ts +9 -0
- package/dist/tools/coValues/promise.d.ts.map +1 -0
- package/dist/tools/coValues/request.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/refs.d.ts +1 -1
- package/dist/tools/implementation/refs.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts +5 -2
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts +1 -1
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +2 -1
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/tests/SubscriptionScope.test.d.ts +2 -0
- package/dist/tools/tests/SubscriptionScope.test.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/inspector/tests/utils/history.test.ts +233 -2
- package/src/inspector/tests/viewer/co-plain-text-view.test.tsx +125 -0
- package/src/inspector/tests/viewer/comap-view.test.tsx +309 -1
- package/src/inspector/tests/viewer/history-view.test.tsx +134 -2
- package/src/inspector/utils/history.ts +168 -1
- package/src/inspector/utils/permissions.ts +10 -0
- package/src/inspector/viewer/co-map-view.tsx +27 -15
- package/src/inspector/viewer/co-plain-text-view.tsx +102 -3
- package/src/inspector/viewer/grid-view.tsx +2 -1
- package/src/inspector/viewer/history-view.tsx +5 -23
- package/src/inspector/viewer/page.tsx +8 -1
- package/src/inspector/viewer/use-resolve-covalue.ts +2 -6
- package/src/react-core/hooks.ts +5 -29
- package/src/svelte/jazz.class.svelte.ts +16 -34
- package/src/tools/coValues/coFeed.ts +10 -7
- package/src/tools/coValues/coMap.ts +10 -7
- package/src/tools/coValues/group.ts +6 -2
- package/src/tools/coValues/interfaces.ts +48 -28
- package/src/tools/coValues/promise.ts +34 -0
- package/src/tools/coValues/request.ts +12 -8
- package/src/tools/exports.ts +1 -0
- package/src/tools/implementation/refs.ts +9 -17
- package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +62 -30
- package/src/tools/implementation/zodSchema/unionUtils.ts +3 -4
- package/src/tools/subscribe/SubscriptionScope.ts +45 -2
- package/src/tools/subscribe/index.ts +28 -13
- package/src/tools/subscribe/types.ts +5 -2
- package/src/tools/tests/SubscriptionScope.test.ts +397 -0
- package/src/tools/tests/deepLoading.test.ts +22 -0
- package/src/tools/tests/subscribe.test.ts +69 -0
- package/dist/chunk-NCNM6UDZ.js.map +0 -1
- package/dist/inspector/custom-element-ABVPHX53.js.map +0 -1
|
@@ -847,10 +847,13 @@ function getEditFromRaw(target, rawEdit, descriptor, key) {
|
|
|
847
847
|
target
|
|
848
848
|
) : void 0,
|
|
849
849
|
get by() {
|
|
850
|
-
|
|
850
|
+
if (!rawEdit.by) return null;
|
|
851
|
+
const account = accessChildById(target, rawEdit.by, {
|
|
851
852
|
ref: Account,
|
|
852
853
|
optional: false
|
|
853
854
|
});
|
|
855
|
+
if (!account.$isLoaded) return null;
|
|
856
|
+
return account;
|
|
854
857
|
},
|
|
855
858
|
madeAt: rawEdit.at,
|
|
856
859
|
key
|
|
@@ -1792,10 +1795,13 @@ function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField)
|
|
|
1792
1795
|
}
|
|
1793
1796
|
},
|
|
1794
1797
|
get by() {
|
|
1795
|
-
|
|
1798
|
+
if (!accountID) return null;
|
|
1799
|
+
const account = accessChildById(accessFrom, accountID, {
|
|
1796
1800
|
ref: Account,
|
|
1797
1801
|
optional: false
|
|
1798
1802
|
});
|
|
1803
|
+
if (!account.$isLoaded) return null;
|
|
1804
|
+
return account;
|
|
1799
1805
|
},
|
|
1800
1806
|
madeAt: rawEntry.at,
|
|
1801
1807
|
tx: rawEntry.tx
|
|
@@ -2602,7 +2608,11 @@ var _Group = class _Group extends CoValueBase {
|
|
|
2602
2608
|
role,
|
|
2603
2609
|
ref: ref2,
|
|
2604
2610
|
get account() {
|
|
2605
|
-
return accessChildById(
|
|
2611
|
+
return accessChildById(
|
|
2612
|
+
group,
|
|
2613
|
+
accountID,
|
|
2614
|
+
refEncodedAccountSchema
|
|
2615
|
+
);
|
|
2606
2616
|
}
|
|
2607
2617
|
});
|
|
2608
2618
|
}
|
|
@@ -2758,7 +2768,7 @@ function getCoValueOwner(coValue) {
|
|
|
2758
2768
|
ref: RegisteredSchemas["Group"],
|
|
2759
2769
|
optional: false
|
|
2760
2770
|
});
|
|
2761
|
-
if (!group) {
|
|
2771
|
+
if (!group.$isLoaded) {
|
|
2762
2772
|
throw new Error("CoValue has no owner");
|
|
2763
2773
|
}
|
|
2764
2774
|
return group;
|
|
@@ -3695,27 +3705,18 @@ var Ref = class {
|
|
|
3695
3705
|
node = subscriptionScope.childNodes.get(this.id);
|
|
3696
3706
|
}
|
|
3697
3707
|
if (!node) {
|
|
3698
|
-
return createUnloadedCoValue(this.id, CoValueLoadingState.
|
|
3708
|
+
return createUnloadedCoValue(this.id, CoValueLoadingState.UNAVAILABLE);
|
|
3699
3709
|
}
|
|
3700
|
-
const value = node.
|
|
3701
|
-
if (value
|
|
3702
|
-
return value
|
|
3710
|
+
const value = node.getCurrentValue();
|
|
3711
|
+
if (value.$isLoaded) {
|
|
3712
|
+
return value;
|
|
3703
3713
|
} else {
|
|
3704
3714
|
return new Promise((resolve) => {
|
|
3705
3715
|
const unsubscribe = node.subscribe((value2) => {
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
resolve(value2.value);
|
|
3709
|
-
} else if (value2?.type === CoValueLoadingState.UNAVAILABLE) {
|
|
3710
|
-
unsubscribe();
|
|
3711
|
-
resolve(
|
|
3712
|
-
createUnloadedCoValue(this.id, CoValueLoadingState.UNAVAILABLE)
|
|
3713
|
-
);
|
|
3714
|
-
} else if (value2?.type === CoValueLoadingState.UNAUTHORIZED) {
|
|
3716
|
+
const currentValue = node.getCurrentValue();
|
|
3717
|
+
if (currentValue.$jazz.loadingState !== CoValueLoadingState.LOADING) {
|
|
3715
3718
|
unsubscribe();
|
|
3716
|
-
resolve(
|
|
3717
|
-
createUnloadedCoValue(this.id, CoValueLoadingState.UNAUTHORIZED)
|
|
3718
|
-
);
|
|
3719
|
+
resolve(currentValue);
|
|
3719
3720
|
}
|
|
3720
3721
|
if (subscriptionScope.closed) {
|
|
3721
3722
|
node.destroy();
|
|
@@ -4334,7 +4335,30 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
|
4334
4335
|
if (this.value.type !== CoValueLoadingState.LOADED) return true;
|
|
4335
4336
|
return this.pendingLoadedChildren.size === 0;
|
|
4336
4337
|
}
|
|
4338
|
+
getUnloadedValue(reason) {
|
|
4339
|
+
if (this.unloadedValue?.$jazz.loadingState === reason) {
|
|
4340
|
+
return this.unloadedValue;
|
|
4341
|
+
}
|
|
4342
|
+
const unloadedValue = {
|
|
4343
|
+
$jazz: {
|
|
4344
|
+
id: this.id,
|
|
4345
|
+
loadingState: reason,
|
|
4346
|
+
// @ts-expect-error - This is a private property
|
|
4347
|
+
_subscriptionScope: this
|
|
4348
|
+
},
|
|
4349
|
+
$isLoaded: false
|
|
4350
|
+
};
|
|
4351
|
+
this.unloadedValue = unloadedValue;
|
|
4352
|
+
return unloadedValue;
|
|
4353
|
+
}
|
|
4337
4354
|
getCurrentValue() {
|
|
4355
|
+
const rawValue = this.getCurrentRawValue();
|
|
4356
|
+
if (rawValue === CoValueLoadingState.UNAUTHORIZED || rawValue === CoValueLoadingState.UNAVAILABLE || rawValue === CoValueLoadingState.LOADING) {
|
|
4357
|
+
return this.getUnloadedValue(rawValue);
|
|
4358
|
+
}
|
|
4359
|
+
return rawValue;
|
|
4360
|
+
}
|
|
4361
|
+
getCurrentRawValue() {
|
|
4338
4362
|
if (this.value.type === CoValueLoadingState.UNAUTHORIZED || this.value.type === CoValueLoadingState.UNAVAILABLE) {
|
|
4339
4363
|
console.error(this.value.toString());
|
|
4340
4364
|
return this.value.type;
|
|
@@ -4414,7 +4438,7 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
|
4414
4438
|
return;
|
|
4415
4439
|
}
|
|
4416
4440
|
this.subscription.pullValue();
|
|
4417
|
-
const value = this.
|
|
4441
|
+
const value = this.getCurrentRawValue();
|
|
4418
4442
|
if (typeof value !== "string") {
|
|
4419
4443
|
listener({
|
|
4420
4444
|
type: CoValueLoadingState.LOADED,
|
|
@@ -4542,6 +4566,10 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
|
4542
4566
|
if (key === "$onError") {
|
|
4543
4567
|
return void 0;
|
|
4544
4568
|
}
|
|
4569
|
+
const skipInvalid = typeof depth === "object" && depth.$onError === "catch";
|
|
4570
|
+
if (skipInvalid) {
|
|
4571
|
+
this.skipInvalidKeys.add(key);
|
|
4572
|
+
}
|
|
4545
4573
|
const id = map.$jazz.raw.get(key);
|
|
4546
4574
|
const descriptor = map.$jazz.getDescriptor(key);
|
|
4547
4575
|
if (!descriptor) {
|
|
@@ -4677,12 +4705,12 @@ function accessChildByKey(parent, childId, key) {
|
|
|
4677
4705
|
const value = subscriptionScope.childValues.get(childId);
|
|
4678
4706
|
if (value?.type === CoValueLoadingState.LOADED) {
|
|
4679
4707
|
return value.value;
|
|
4680
|
-
} else {
|
|
4681
|
-
return createUnloadedCoValue(
|
|
4682
|
-
childId,
|
|
4683
|
-
value?.type ?? CoValueLoadingState.LOADING
|
|
4684
|
-
);
|
|
4685
4708
|
}
|
|
4709
|
+
const childNode = subscriptionScope.childNodes.get(childId);
|
|
4710
|
+
if (!childNode) {
|
|
4711
|
+
return createUnloadedCoValue(childId, CoValueLoadingState.UNAVAILABLE);
|
|
4712
|
+
}
|
|
4713
|
+
return childNode.getCurrentValue();
|
|
4686
4714
|
}
|
|
4687
4715
|
function accessChildById(parent, childId, schema) {
|
|
4688
4716
|
const subscriptionScope = getSubscriptionScope(parent);
|
|
@@ -4690,12 +4718,12 @@ function accessChildById(parent, childId, schema) {
|
|
|
4690
4718
|
const value = subscriptionScope.childValues.get(childId);
|
|
4691
4719
|
if (value?.type === CoValueLoadingState.LOADED) {
|
|
4692
4720
|
return value.value;
|
|
4693
|
-
} else {
|
|
4694
|
-
return createUnloadedCoValue(
|
|
4695
|
-
childId,
|
|
4696
|
-
value?.type ?? CoValueLoadingState.LOADING
|
|
4697
|
-
);
|
|
4698
4721
|
}
|
|
4722
|
+
const childNode = subscriptionScope.childNodes.get(childId);
|
|
4723
|
+
if (!childNode) {
|
|
4724
|
+
return createUnloadedCoValue(childId, CoValueLoadingState.UNAVAILABLE);
|
|
4725
|
+
}
|
|
4726
|
+
return childNode.getCurrentValue();
|
|
4699
4727
|
}
|
|
4700
4728
|
|
|
4701
4729
|
// src/tools/implementation/createContext.ts
|
|
@@ -5783,7 +5811,9 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
|
5783
5811
|
if (match) {
|
|
5784
5812
|
const coValueSchema = hydrateCoreCoValueSchema(option);
|
|
5785
5813
|
const coValueClass = coValueSchema.getCoValueClass();
|
|
5786
|
-
const dummyFieldNames =
|
|
5814
|
+
const dummyFieldNames = Array.from(allNestedRefKeys).filter(
|
|
5815
|
+
(key) => !optionDef.shape[key]
|
|
5816
|
+
);
|
|
5787
5817
|
if (dummyFieldNames.length === 0) {
|
|
5788
5818
|
return coValueClass;
|
|
5789
5819
|
}
|
|
@@ -5846,16 +5876,28 @@ function makeCodecCoField(codec2) {
|
|
|
5846
5876
|
}
|
|
5847
5877
|
});
|
|
5848
5878
|
}
|
|
5879
|
+
var schemaFieldCache = /* @__PURE__ */ new WeakMap();
|
|
5880
|
+
function cacheSchemaField(schema, value) {
|
|
5881
|
+
schemaFieldCache.set(schema, value);
|
|
5882
|
+
return value;
|
|
5883
|
+
}
|
|
5849
5884
|
function schemaFieldToCoFieldDef(schema) {
|
|
5885
|
+
const cachedCoFieldDef = schemaFieldCache.get(schema);
|
|
5886
|
+
if (cachedCoFieldDef !== void 0) {
|
|
5887
|
+
return cachedCoFieldDef;
|
|
5888
|
+
}
|
|
5850
5889
|
if (isCoValueClass(schema)) {
|
|
5851
|
-
return coField.ref(schema);
|
|
5890
|
+
return cacheSchemaField(schema, coField.ref(schema));
|
|
5852
5891
|
} else if (isCoValueSchema(schema)) {
|
|
5853
5892
|
if (schema.builtin === "CoOptional") {
|
|
5854
|
-
return
|
|
5855
|
-
|
|
5856
|
-
|
|
5893
|
+
return cacheSchemaField(
|
|
5894
|
+
schema,
|
|
5895
|
+
coField.ref(schema.getCoValueClass(), {
|
|
5896
|
+
optional: true
|
|
5897
|
+
})
|
|
5898
|
+
);
|
|
5857
5899
|
}
|
|
5858
|
-
return coField.ref(schema.getCoValueClass());
|
|
5900
|
+
return cacheSchemaField(schema, coField.ref(schema.getCoValueClass()));
|
|
5859
5901
|
} else {
|
|
5860
5902
|
if ("_zod" in schema) {
|
|
5861
5903
|
const zodSchemaDef = schema._zod.def;
|
|
@@ -5865,35 +5907,44 @@ function schemaFieldToCoFieldDef(schema) {
|
|
|
5865
5907
|
if (zodSchemaDef.type === "nullable" && coFieldDef === coField.optional.Date) {
|
|
5866
5908
|
throw new Error("Nullable z.date() is not supported");
|
|
5867
5909
|
}
|
|
5868
|
-
return coFieldDef;
|
|
5910
|
+
return cacheSchemaField(schema, coFieldDef);
|
|
5869
5911
|
} else if (zodSchemaDef.type === "string") {
|
|
5870
|
-
return coField.string;
|
|
5912
|
+
return cacheSchemaField(schema, coField.string);
|
|
5871
5913
|
} else if (zodSchemaDef.type === "number") {
|
|
5872
|
-
return coField.number;
|
|
5914
|
+
return cacheSchemaField(schema, coField.number);
|
|
5873
5915
|
} else if (zodSchemaDef.type === "boolean") {
|
|
5874
|
-
return coField.boolean;
|
|
5916
|
+
return cacheSchemaField(schema, coField.boolean);
|
|
5875
5917
|
} else if (zodSchemaDef.type === "null") {
|
|
5876
|
-
return coField.null;
|
|
5918
|
+
return cacheSchemaField(schema, coField.null);
|
|
5877
5919
|
} else if (zodSchemaDef.type === "enum") {
|
|
5878
|
-
return coField.string;
|
|
5920
|
+
return cacheSchemaField(schema, coField.string);
|
|
5879
5921
|
} else if (zodSchemaDef.type === "readonly") {
|
|
5880
|
-
return
|
|
5881
|
-
schema
|
|
5922
|
+
return cacheSchemaField(
|
|
5923
|
+
schema,
|
|
5924
|
+
schemaFieldToCoFieldDef(
|
|
5925
|
+
schema.def.innerType
|
|
5926
|
+
)
|
|
5882
5927
|
);
|
|
5883
5928
|
} else if (zodSchemaDef.type === "date") {
|
|
5884
|
-
return coField.optional.Date;
|
|
5929
|
+
return cacheSchemaField(schema, coField.optional.Date);
|
|
5885
5930
|
} else if (zodSchemaDef.type === "template_literal") {
|
|
5886
|
-
return coField.string;
|
|
5931
|
+
return cacheSchemaField(schema, coField.string);
|
|
5887
5932
|
} else if (zodSchemaDef.type === "lazy") {
|
|
5888
|
-
return
|
|
5889
|
-
schema
|
|
5933
|
+
return cacheSchemaField(
|
|
5934
|
+
schema,
|
|
5935
|
+
schemaFieldToCoFieldDef(
|
|
5936
|
+
schema.unwrap()
|
|
5937
|
+
)
|
|
5890
5938
|
);
|
|
5891
5939
|
} else if (zodSchemaDef.type === "default" || zodSchemaDef.type === "catch") {
|
|
5892
5940
|
console.warn(
|
|
5893
5941
|
"z.default()/z.catch() are not supported in collaborative schemas. They will be ignored."
|
|
5894
5942
|
);
|
|
5895
|
-
return
|
|
5896
|
-
schema
|
|
5943
|
+
return cacheSchemaField(
|
|
5944
|
+
schema,
|
|
5945
|
+
schemaFieldToCoFieldDef(
|
|
5946
|
+
schema.def.innerType
|
|
5947
|
+
)
|
|
5897
5948
|
);
|
|
5898
5949
|
} else if (zodSchemaDef.type === "literal") {
|
|
5899
5950
|
if (zodSchemaDef.values.some((literal2) => typeof literal2 === "undefined")) {
|
|
@@ -5905,14 +5956,17 @@ function schemaFieldToCoFieldDef(schema) {
|
|
|
5905
5956
|
if (zodSchemaDef.values.some((literal2) => typeof literal2 === "bigint")) {
|
|
5906
5957
|
throw new Error("z.literal() with bigint is not supported");
|
|
5907
5958
|
}
|
|
5908
|
-
return
|
|
5909
|
-
|
|
5959
|
+
return cacheSchemaField(
|
|
5960
|
+
schema,
|
|
5961
|
+
coField.literal(
|
|
5962
|
+
...zodSchemaDef.values
|
|
5963
|
+
)
|
|
5910
5964
|
);
|
|
5911
5965
|
} else if (zodSchemaDef.type === "object" || zodSchemaDef.type === "record" || zodSchemaDef.type === "array" || zodSchemaDef.type === "tuple" || zodSchemaDef.type === "intersection") {
|
|
5912
|
-
return coField.json();
|
|
5966
|
+
return cacheSchemaField(schema, coField.json());
|
|
5913
5967
|
} else if (zodSchemaDef.type === "union") {
|
|
5914
5968
|
if (isUnionOfPrimitivesDeeply(schema)) {
|
|
5915
|
-
return coField.json();
|
|
5969
|
+
return cacheSchemaField(schema, coField.json());
|
|
5916
5970
|
} else {
|
|
5917
5971
|
throw new Error(
|
|
5918
5972
|
"z.union()/z.discriminatedUnion() of collaborative types is not supported. Use co.discriminatedUnion() instead."
|
|
@@ -5933,8 +5987,11 @@ function schemaFieldToCoFieldDef(schema) {
|
|
|
5933
5987
|
}
|
|
5934
5988
|
throw error;
|
|
5935
5989
|
}
|
|
5936
|
-
return
|
|
5937
|
-
schema
|
|
5990
|
+
return cacheSchemaField(
|
|
5991
|
+
schema,
|
|
5992
|
+
makeCodecCoField(
|
|
5993
|
+
schema
|
|
5994
|
+
)
|
|
5938
5995
|
);
|
|
5939
5996
|
} else {
|
|
5940
5997
|
throw new Error(
|
|
@@ -6538,6 +6595,16 @@ globalThis.devtoolsFormatters = [
|
|
|
6538
6595
|
function isCoValueClass(value) {
|
|
6539
6596
|
return typeof value === "function" && value.fromRaw !== void 0;
|
|
6540
6597
|
}
|
|
6598
|
+
var unloadedCoValueStates = /* @__PURE__ */ new Map();
|
|
6599
|
+
function getUnloadedCoValueWithoutId(loadingState) {
|
|
6600
|
+
const value = unloadedCoValueStates.get(loadingState);
|
|
6601
|
+
if (value) {
|
|
6602
|
+
return value;
|
|
6603
|
+
}
|
|
6604
|
+
const newValue = createUnloadedCoValue("", loadingState);
|
|
6605
|
+
unloadedCoValueStates.set(loadingState, newValue);
|
|
6606
|
+
return newValue;
|
|
6607
|
+
}
|
|
6541
6608
|
function createUnloadedCoValue(id, loadingState) {
|
|
6542
6609
|
return {
|
|
6543
6610
|
$jazz: { id, loadingState },
|
|
@@ -6561,12 +6628,8 @@ function loadCoValue(cls, id, options) {
|
|
|
6561
6628
|
loadAs: options.loadAs,
|
|
6562
6629
|
syncResolution: true,
|
|
6563
6630
|
skipRetry: options.skipRetry,
|
|
6564
|
-
onUnavailable:
|
|
6565
|
-
|
|
6566
|
-
},
|
|
6567
|
-
onUnauthorized: () => {
|
|
6568
|
-
resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAUTHORIZED));
|
|
6569
|
-
},
|
|
6631
|
+
onUnavailable: resolve,
|
|
6632
|
+
onUnauthorized: resolve,
|
|
6570
6633
|
unstable_branch: options.unstable_branch
|
|
6571
6634
|
},
|
|
6572
6635
|
(value, unsubscribe) => {
|
|
@@ -6643,29 +6706,35 @@ function subscribeToCoValue(cls, id, options, listener) {
|
|
|
6643
6706
|
false,
|
|
6644
6707
|
options.unstable_branch
|
|
6645
6708
|
);
|
|
6646
|
-
const handleUpdate = (
|
|
6709
|
+
const handleUpdate = () => {
|
|
6647
6710
|
if (unsubscribed) return;
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6711
|
+
const value = rootNode.getCurrentValue();
|
|
6712
|
+
if (value.$isLoaded) {
|
|
6713
|
+
listener(value, unsubscribe);
|
|
6714
|
+
return;
|
|
6715
|
+
}
|
|
6716
|
+
switch (value.$jazz.loadingState) {
|
|
6717
|
+
case CoValueLoadingState.UNAVAILABLE:
|
|
6718
|
+
options.onUnavailable?.(value);
|
|
6719
|
+
if (!options.skipRetry) {
|
|
6720
|
+
console.error(value.toString());
|
|
6721
|
+
}
|
|
6722
|
+
break;
|
|
6723
|
+
case CoValueLoadingState.UNAUTHORIZED:
|
|
6724
|
+
options.onUnauthorized?.(value);
|
|
6651
6725
|
console.error(value.toString());
|
|
6652
|
-
|
|
6653
|
-
} else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
|
|
6654
|
-
options.onUnauthorized?.();
|
|
6655
|
-
console.error(value.toString());
|
|
6656
|
-
} else if (value.type === CoValueLoadingState.LOADED) {
|
|
6657
|
-
listener(value.value, unsubscribe);
|
|
6726
|
+
break;
|
|
6658
6727
|
}
|
|
6659
6728
|
};
|
|
6660
6729
|
let shouldDefer = !options.syncResolution;
|
|
6661
|
-
rootNode.setListener((
|
|
6730
|
+
rootNode.setListener(() => {
|
|
6662
6731
|
if (shouldDefer) {
|
|
6663
6732
|
shouldDefer = false;
|
|
6664
6733
|
Promise.resolve().then(() => {
|
|
6665
|
-
handleUpdate(
|
|
6734
|
+
handleUpdate();
|
|
6666
6735
|
});
|
|
6667
6736
|
} else {
|
|
6668
|
-
handleUpdate(
|
|
6737
|
+
handleUpdate();
|
|
6669
6738
|
}
|
|
6670
6739
|
});
|
|
6671
6740
|
function unsubscribe() {
|
|
@@ -6823,7 +6892,7 @@ function loadContentPiecesFromSubscription(subscription, valuesExported, content
|
|
|
6823
6892
|
}
|
|
6824
6893
|
valuesExported.add(subscription.id);
|
|
6825
6894
|
const currentValue = subscription.getCurrentValue();
|
|
6826
|
-
if (
|
|
6895
|
+
if (currentValue.$isLoaded) {
|
|
6827
6896
|
const core2 = currentValue.$jazz.raw.core;
|
|
6828
6897
|
loadContentPiecesFromCoValue(core2, valuesExported, contentPieces);
|
|
6829
6898
|
}
|
|
@@ -6901,6 +6970,7 @@ async function unstable_mergeBranchWithResolve(cls, id, options) {
|
|
|
6901
6970
|
|
|
6902
6971
|
export {
|
|
6903
6972
|
zodReExport_exports,
|
|
6973
|
+
getUnloadedCoValueWithoutId,
|
|
6904
6974
|
createUnloadedCoValue,
|
|
6905
6975
|
loadCoValue,
|
|
6906
6976
|
subscribeToCoValue,
|
|
@@ -6946,4 +7016,4 @@ export {
|
|
|
6946
7016
|
JazzContextManager
|
|
6947
7017
|
};
|
|
6948
7018
|
/* istanbul ignore file -- @preserve */
|
|
6949
|
-
//# sourceMappingURL=chunk-
|
|
7019
|
+
//# sourceMappingURL=chunk-PT7FCV26.js.map
|