jazz-tools 0.15.10 → 0.15.12
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 +37 -37
- package/CHANGELOG.md +20 -0
- package/dist/{chunk-V54IPL5M.js → chunk-DZFT4EZM.js} +426 -303
- package/dist/chunk-DZFT4EZM.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/react/index.js +1 -3
- package/dist/react/testing.js +1 -3
- package/dist/react/testing.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +27 -1
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/coExport.d.ts +1 -1
- package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +6 -3
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +6 -25
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +30 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +3 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +3 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +11 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +2 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +5 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +5 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +5 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +7 -12
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- 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/zodCo.d.ts +6 -6
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts +8 -1
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +18 -13
- 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/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/tests/coDiscriminatedUnion.test-d.d.ts +2 -0
- package/dist/tools/tests/coDiscriminatedUnion.test-d.d.ts.map +1 -0
- package/dist/tools/tests/coDiscriminatedUnion.test.d.ts +2 -0
- package/dist/tools/tests/coDiscriminatedUnion.test.d.ts.map +1 -0
- package/dist/tools/tests/coOptional.test.d.ts +2 -0
- package/dist/tools/tests/coOptional.test.d.ts.map +1 -0
- package/dist/tools/tests/testStorage.d.ts +5 -0
- package/dist/tools/tests/testStorage.d.ts.map +1 -0
- package/dist/tools/tests/zod.test-d.d.ts +2 -0
- package/dist/tools/tests/zod.test-d.d.ts.map +1 -0
- package/package.json +5 -4
- package/src/react-core/tests/useAccount.test.ts +1 -11
- package/src/react-core/tests/useCoState.test.ts +20 -0
- package/src/tools/coValues/CoValueBase.ts +2 -2
- package/src/tools/coValues/inbox.ts +0 -2
- package/src/tools/coValues/schemaUnion.ts +62 -0
- package/src/tools/implementation/ContextManager.ts +5 -1
- package/src/tools/implementation/zodSchema/coExport.ts +2 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +29 -12
- package/src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +93 -63
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +62 -3
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +90 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +27 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +27 -5
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +60 -5
- package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +33 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +3 -5
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +32 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +30 -2
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +26 -2
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +10 -13
- package/src/tools/implementation/zodSchema/unionUtils.ts +22 -14
- package/src/tools/implementation/zodSchema/zodCo.ts +68 -256
- package/src/tools/implementation/zodSchema/zodReExport.ts +34 -5
- package/src/tools/implementation/zodSchema/zodSchema.ts +78 -19
- package/src/tools/internal.ts +1 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +4 -0
- package/src/tools/tests/ContextManager.test.ts +84 -10
- package/src/tools/tests/coDiscriminatedUnion.test-d.ts +57 -0
- package/src/tools/tests/coDiscriminatedUnion.test.ts +93 -0
- package/src/tools/tests/coList.test.ts +4 -12
- package/src/tools/tests/coMap.record.test.ts +4 -4
- package/src/tools/tests/coMap.test-d.ts +3 -3
- package/src/tools/tests/coMap.test.ts +10 -10
- package/src/tools/tests/coOptional.test.ts +39 -0
- package/src/tools/tests/createContext.test.ts +5 -4
- package/src/tools/tests/deepLoading.test.ts +3 -3
- package/src/tools/tests/inbox.test.ts +3 -11
- package/src/tools/tests/load.test.ts +9 -0
- package/src/tools/tests/patterns/requestToJoin.test.ts +1 -1
- package/src/tools/tests/schemaUnion.test.ts +11 -22
- package/src/tools/tests/subscribe.test.ts +25 -39
- package/src/tools/tests/testStorage.ts +70 -0
- package/src/tools/tests/zod.test-d.ts +70 -0
- package/src/tools/tests/zod.test.ts +64 -5
- package/dist/chunk-V54IPL5M.js.map +0 -1
@@ -41,16 +41,18 @@ __export(zodReExport_exports, {
|
|
41
41
|
uuid: () => uuid,
|
42
42
|
z: () => z
|
43
43
|
});
|
44
|
+
import {
|
45
|
+
array as zodArray,
|
46
|
+
tuple as zodTuple,
|
47
|
+
union as zodUnion
|
48
|
+
} from "zod/v4";
|
44
49
|
import {
|
45
50
|
string,
|
46
51
|
number,
|
47
52
|
boolean,
|
48
|
-
union,
|
49
53
|
object,
|
50
|
-
array,
|
51
54
|
templateLiteral,
|
52
55
|
json,
|
53
|
-
tuple,
|
54
56
|
date,
|
55
57
|
emoji,
|
56
58
|
base64,
|
@@ -76,6 +78,15 @@ import {
|
|
76
78
|
optional,
|
77
79
|
z
|
78
80
|
} from "zod/v4";
|
81
|
+
function union(options, params) {
|
82
|
+
return zodUnion(options, params);
|
83
|
+
}
|
84
|
+
function array(element, params) {
|
85
|
+
return zodArray(element, params);
|
86
|
+
}
|
87
|
+
function tuple(options, params) {
|
88
|
+
return zodTuple(options, params);
|
89
|
+
}
|
79
90
|
|
80
91
|
// src/tools/coValues/CoValueBase.ts
|
81
92
|
import { ControlledAccount, RawAccount } from "cojson";
|
@@ -124,7 +135,7 @@ var CoValueBase = class {
|
|
124
135
|
}
|
125
136
|
/** @category Type Helpers */
|
126
137
|
castAs(schema) {
|
127
|
-
const cl =
|
138
|
+
const cl = isCoValueSchema(schema) ? schema.getCoValueClass() : schema;
|
128
139
|
if (this.constructor === cl) {
|
129
140
|
return this;
|
130
141
|
}
|
@@ -2653,6 +2664,20 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
|
|
2653
2664
|
static fromRaw(raw) {
|
2654
2665
|
throw new Error("Not implemented");
|
2655
2666
|
}
|
2667
|
+
/**
|
2668
|
+
* Load a `SchemaUnion` with a given ID, as a given account.
|
2669
|
+
*
|
2670
|
+
* Note: The `resolve` option is not supported for `SchemaUnion`s due to https://github.com/garden-co/jazz/issues/2639
|
2671
|
+
*
|
2672
|
+
* @category Subscription & Loading
|
2673
|
+
*/
|
2674
|
+
static load(id, options) {
|
2675
|
+
return loadCoValueWithoutMe(this, id, options);
|
2676
|
+
}
|
2677
|
+
static subscribe(id, ...args) {
|
2678
|
+
const { options, listener } = parseSubscribeRestArgs(args);
|
2679
|
+
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
2680
|
+
}
|
2656
2681
|
};
|
2657
2682
|
|
2658
2683
|
// src/tools/implementation/anonymousJazzAgent.ts
|
@@ -2906,18 +2931,21 @@ var CoValueCoreSubscription = class {
|
|
2906
2931
|
this.subscribeToState();
|
2907
2932
|
this.listener("unavailable");
|
2908
2933
|
}
|
2934
|
+
}).catch((error) => {
|
2935
|
+
console.error("Unexpected error loading CoValue: ", error);
|
2936
|
+
this.listener("unavailable");
|
2909
2937
|
});
|
2910
2938
|
}
|
2911
2939
|
}
|
2912
2940
|
subscribeToState() {
|
2913
2941
|
const entry = this.node.getCoValue(this.id);
|
2914
|
-
const handleStateChange = (
|
2942
|
+
const handleStateChange = (core2, unsubFromStateChange2) => {
|
2915
2943
|
if (this.unsubscribed) {
|
2916
2944
|
unsubFromStateChange2();
|
2917
2945
|
return;
|
2918
2946
|
}
|
2919
|
-
if (
|
2920
|
-
this.subscribe(
|
2947
|
+
if (core2.isAvailable()) {
|
2948
|
+
this.subscribe(core2.getCurrentContent());
|
2921
2949
|
unsubFromStateChange2();
|
2922
2950
|
}
|
2923
2951
|
};
|
@@ -3682,265 +3710,23 @@ function getDef(schema) {
|
|
3682
3710
|
return schema.def;
|
3683
3711
|
}
|
3684
3712
|
|
3685
|
-
// src/tools/implementation/zodSchema/
|
3686
|
-
function
|
3687
|
-
|
3688
|
-
const enrichedSchema = Object.assign(schema, {
|
3689
|
-
collaborative: true,
|
3713
|
+
// src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts
|
3714
|
+
function enrichRichTextSchema(schema, coValueClass) {
|
3715
|
+
return Object.assign(schema, {
|
3690
3716
|
create: (...args) => {
|
3691
|
-
return
|
3717
|
+
return coValueClass.create(...args);
|
3692
3718
|
},
|
3693
3719
|
load: (...args) => {
|
3694
|
-
return
|
3720
|
+
return coValueClass.load(...args);
|
3695
3721
|
},
|
3696
3722
|
subscribe: (...args) => {
|
3697
|
-
return
|
3698
|
-
},
|
3699
|
-
findUnique: (...args) => {
|
3700
|
-
return coSchema.findUnique(...args);
|
3723
|
+
return coValueClass.subscribe(...args);
|
3701
3724
|
},
|
3702
|
-
|
3703
|
-
return
|
3704
|
-
},
|
3705
|
-
loadUnique: (...args) => {
|
3706
|
-
return coSchema.loadUnique(...args);
|
3707
|
-
},
|
3708
|
-
catchall: (index) => {
|
3709
|
-
return enrichCoMapSchema(baseCatchall(index));
|
3710
|
-
},
|
3711
|
-
withHelpers: (helpers) => {
|
3712
|
-
return Object.assign(schema, helpers(schema));
|
3713
|
-
},
|
3714
|
-
withMigration: (migration) => {
|
3715
|
-
coSchema.prototype.migrate = migration;
|
3716
|
-
return enrichedSchema;
|
3717
|
-
},
|
3718
|
-
getCoSchema: () => {
|
3719
|
-
return coSchema;
|
3725
|
+
getCoValueClass: () => {
|
3726
|
+
return coValueClass;
|
3720
3727
|
}
|
3721
3728
|
});
|
3722
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3723
|
-
return enrichedSchema;
|
3724
3729
|
}
|
3725
|
-
var coMapDefiner = (shape) => {
|
3726
|
-
const objectSchema = z.object(shape).meta({
|
3727
|
-
collaborative: true
|
3728
|
-
});
|
3729
|
-
return enrichCoMapSchema(objectSchema);
|
3730
|
-
};
|
3731
|
-
function enrichAccountSchema(schema) {
|
3732
|
-
const enrichedSchema = Object.assign(schema, {
|
3733
|
-
collaborative: true,
|
3734
|
-
builtin: "Account",
|
3735
|
-
create: (...args) => {
|
3736
|
-
return coSchema.create(...args);
|
3737
|
-
},
|
3738
|
-
createAs: (...args) => {
|
3739
|
-
return coSchema.createAs(...args);
|
3740
|
-
},
|
3741
|
-
getMe: (...args) => {
|
3742
|
-
return coSchema.getMe(...args);
|
3743
|
-
},
|
3744
|
-
load: (...args) => {
|
3745
|
-
return coSchema.load(...args);
|
3746
|
-
},
|
3747
|
-
subscribe: (...args) => {
|
3748
|
-
return coSchema.subscribe(...args);
|
3749
|
-
},
|
3750
|
-
withHelpers: (helpers) => {
|
3751
|
-
return Object.assign(schema, helpers(schema));
|
3752
|
-
},
|
3753
|
-
fromRaw: (...args) => {
|
3754
|
-
return coSchema.fromRaw(...args);
|
3755
|
-
},
|
3756
|
-
withMigration: (migration) => {
|
3757
|
-
coSchema.prototype.migrate = async function(creationProps) {
|
3758
|
-
await migration(this, creationProps);
|
3759
|
-
};
|
3760
|
-
return enrichedSchema;
|
3761
|
-
},
|
3762
|
-
getCoSchema: () => {
|
3763
|
-
return coSchema;
|
3764
|
-
}
|
3765
|
-
});
|
3766
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3767
|
-
return enrichedSchema;
|
3768
|
-
}
|
3769
|
-
var coAccountDefiner = (shape = {
|
3770
|
-
profile: coMapDefiner({
|
3771
|
-
name: z.string(),
|
3772
|
-
inbox: z.optional(z.string()),
|
3773
|
-
inboxInvite: z.optional(z.string())
|
3774
|
-
}),
|
3775
|
-
root: coMapDefiner({})
|
3776
|
-
}) => {
|
3777
|
-
const objectSchema = z.object(shape).meta({
|
3778
|
-
collaborative: true
|
3779
|
-
});
|
3780
|
-
return enrichAccountSchema(objectSchema);
|
3781
|
-
};
|
3782
|
-
var coRecordDefiner = (_keyType, valueType) => {
|
3783
|
-
return coMapDefiner({}).catchall(valueType);
|
3784
|
-
};
|
3785
|
-
function enrichCoListSchema(schema) {
|
3786
|
-
const enrichedSchema = Object.assign(schema, {
|
3787
|
-
collaborative: true,
|
3788
|
-
create: (...args) => {
|
3789
|
-
return coSchema.create(...args);
|
3790
|
-
},
|
3791
|
-
load: (...args) => {
|
3792
|
-
return coSchema.load(...args);
|
3793
|
-
},
|
3794
|
-
subscribe: (...args) => {
|
3795
|
-
return coSchema.subscribe(...args);
|
3796
|
-
},
|
3797
|
-
withHelpers: (helpers) => {
|
3798
|
-
return Object.assign(schema, helpers(schema));
|
3799
|
-
},
|
3800
|
-
getCoSchema: () => {
|
3801
|
-
return coSchema;
|
3802
|
-
}
|
3803
|
-
});
|
3804
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3805
|
-
return enrichedSchema;
|
3806
|
-
}
|
3807
|
-
var coListDefiner = (element) => {
|
3808
|
-
const arraySchema = z.array(element).meta({
|
3809
|
-
collaborative: true
|
3810
|
-
});
|
3811
|
-
return enrichCoListSchema(arraySchema);
|
3812
|
-
};
|
3813
|
-
var coProfileDefiner = (shape = {}) => {
|
3814
|
-
const ehnancedShape = Object.assign(shape ?? {}, {
|
3815
|
-
name: z.string(),
|
3816
|
-
inbox: z.optional(z.string()),
|
3817
|
-
inboxInvite: z.optional(z.string())
|
3818
|
-
});
|
3819
|
-
return coMapDefiner(ehnancedShape);
|
3820
|
-
};
|
3821
|
-
function enrichCoFeedSchema(schema, element) {
|
3822
|
-
const enrichedSchema = Object.assign(schema, {
|
3823
|
-
collaborative: true,
|
3824
|
-
builtin: "CoFeed",
|
3825
|
-
element,
|
3826
|
-
create: (...args) => {
|
3827
|
-
return coSchema.create(...args);
|
3828
|
-
},
|
3829
|
-
load: (...args) => {
|
3830
|
-
return coSchema.load(...args);
|
3831
|
-
},
|
3832
|
-
subscribe: (...args) => {
|
3833
|
-
return coSchema.subscribe(...args);
|
3834
|
-
},
|
3835
|
-
withHelpers: (helpers) => {
|
3836
|
-
return Object.assign(schema, helpers(schema));
|
3837
|
-
},
|
3838
|
-
getCoSchema: () => {
|
3839
|
-
return coSchema;
|
3840
|
-
}
|
3841
|
-
});
|
3842
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3843
|
-
return enrichedSchema;
|
3844
|
-
}
|
3845
|
-
var coFeedDefiner = (element) => {
|
3846
|
-
return enrichCoFeedSchema(z.instanceof(CoFeed), element);
|
3847
|
-
};
|
3848
|
-
function enrichFileStreamSchema(schema) {
|
3849
|
-
const enrichedSchema = Object.assign(schema, {
|
3850
|
-
collaborative: true,
|
3851
|
-
builtin: "FileStream",
|
3852
|
-
create: (...args) => {
|
3853
|
-
return coSchema.create(...args);
|
3854
|
-
},
|
3855
|
-
createFromBlob: (...args) => {
|
3856
|
-
return coSchema.createFromBlob(...args);
|
3857
|
-
},
|
3858
|
-
load: (...args) => {
|
3859
|
-
return coSchema.load(...args);
|
3860
|
-
},
|
3861
|
-
loadAsBlob: (...args) => {
|
3862
|
-
return coSchema.loadAsBlob(...args);
|
3863
|
-
},
|
3864
|
-
subscribe: (...args) => {
|
3865
|
-
return coSchema.subscribe(...args);
|
3866
|
-
},
|
3867
|
-
getCoSchema: () => {
|
3868
|
-
return coSchema;
|
3869
|
-
}
|
3870
|
-
});
|
3871
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3872
|
-
return enrichedSchema;
|
3873
|
-
}
|
3874
|
-
var coFileStreamDefiner = () => {
|
3875
|
-
return enrichFileStreamSchema(z.instanceof(FileStream));
|
3876
|
-
};
|
3877
|
-
function enrichPlainTextSchema(schema) {
|
3878
|
-
const enrichedSchema = Object.assign(schema, {
|
3879
|
-
collaborative: true,
|
3880
|
-
builtin: "CoPlainText",
|
3881
|
-
create: (...args) => {
|
3882
|
-
return coSchema.create(...args);
|
3883
|
-
},
|
3884
|
-
load: (...args) => {
|
3885
|
-
return coSchema.load(...args);
|
3886
|
-
},
|
3887
|
-
subscribe: (...args) => {
|
3888
|
-
return coSchema.subscribe(...args);
|
3889
|
-
},
|
3890
|
-
fromRaw: (...args) => {
|
3891
|
-
return coSchema.fromRaw(...args);
|
3892
|
-
},
|
3893
|
-
getCoSchema: () => {
|
3894
|
-
return coSchema;
|
3895
|
-
}
|
3896
|
-
});
|
3897
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3898
|
-
return enrichedSchema;
|
3899
|
-
}
|
3900
|
-
var coPlainTextDefiner = () => {
|
3901
|
-
return enrichPlainTextSchema(z.instanceof(CoPlainText));
|
3902
|
-
};
|
3903
|
-
function enrichRichTextSchema(schema) {
|
3904
|
-
const enrichedSchema = Object.assign(schema, {
|
3905
|
-
collaborative: true,
|
3906
|
-
builtin: "CoRichText",
|
3907
|
-
create: (...args) => {
|
3908
|
-
return coSchema.create(...args);
|
3909
|
-
},
|
3910
|
-
load: (...args) => {
|
3911
|
-
return coSchema.load(...args);
|
3912
|
-
},
|
3913
|
-
subscribe: (...args) => {
|
3914
|
-
return coSchema.subscribe(...args);
|
3915
|
-
},
|
3916
|
-
getCoSchema: () => {
|
3917
|
-
return coSchema;
|
3918
|
-
}
|
3919
|
-
});
|
3920
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3921
|
-
return enrichedSchema;
|
3922
|
-
}
|
3923
|
-
var coRichTextDefiner = () => {
|
3924
|
-
return enrichRichTextSchema(z.instanceof(CoRichText));
|
3925
|
-
};
|
3926
|
-
var coImageDefiner = () => {
|
3927
|
-
return ImageDefinition;
|
3928
|
-
};
|
3929
|
-
|
3930
|
-
// src/tools/implementation/zodSchema/coExport.ts
|
3931
|
-
var coExport_exports = {};
|
3932
|
-
__export(coExport_exports, {
|
3933
|
-
account: () => coAccountDefiner,
|
3934
|
-
feed: () => coFeedDefiner,
|
3935
|
-
fileStream: () => coFileStreamDefiner,
|
3936
|
-
image: () => coImageDefiner,
|
3937
|
-
list: () => coListDefiner,
|
3938
|
-
map: () => coMapDefiner,
|
3939
|
-
plainText: () => coPlainTextDefiner,
|
3940
|
-
profile: () => coProfileDefiner,
|
3941
|
-
record: () => coRecordDefiner,
|
3942
|
-
richText: () => coRichTextDefiner
|
3943
|
-
});
|
3944
3730
|
|
3945
3731
|
// src/tools/implementation/zodSchema/unionUtils.ts
|
3946
3732
|
import { RawCoList } from "cojson";
|
@@ -3948,20 +3734,20 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
3948
3734
|
if (isUnionOfCoMapsDeeply(schema)) {
|
3949
3735
|
if (!schema._zod.disc || schema._zod.disc.size == 0) {
|
3950
3736
|
throw new Error(
|
3951
|
-
"z.union() of collaborative types is not supported, use
|
3737
|
+
"z.union() of collaborative types is not supported, use co.discriminatedUnion() instead"
|
3952
3738
|
);
|
3953
3739
|
}
|
3954
3740
|
const discriminator = schema._zod.def.discriminator;
|
3955
3741
|
const field = schema._zod.disc.get(discriminator);
|
3956
3742
|
if (!field) {
|
3957
3743
|
throw new Error(
|
3958
|
-
"
|
3744
|
+
"co.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
|
3959
3745
|
);
|
3960
3746
|
}
|
3961
3747
|
for (const value of field.values) {
|
3962
3748
|
if (typeof value !== "string" && typeof value !== "number") {
|
3963
3749
|
throw new Error(
|
3964
|
-
"
|
3750
|
+
"co.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported"
|
3965
3751
|
);
|
3966
3752
|
}
|
3967
3753
|
}
|
@@ -3977,14 +3763,14 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
3977
3763
|
}
|
3978
3764
|
} else {
|
3979
3765
|
throw new Error(
|
3980
|
-
"Unsupported zod type in
|
3766
|
+
"Unsupported zod type in co.discriminatedUnion() of collaborative types"
|
3981
3767
|
);
|
3982
3768
|
}
|
3983
3769
|
}
|
3984
3770
|
const determineSchema = (_raw) => {
|
3985
3771
|
if (_raw instanceof RawCoList) {
|
3986
3772
|
throw new Error(
|
3987
|
-
"
|
3773
|
+
"co.discriminatedUnion() of collaborative types is not supported for CoLists"
|
3988
3774
|
);
|
3989
3775
|
}
|
3990
3776
|
for (const option of availableOptions) {
|
@@ -4013,11 +3799,12 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
4013
3799
|
}
|
4014
3800
|
}
|
4015
3801
|
if (match) {
|
4016
|
-
|
3802
|
+
const coValueSchema = zodSchemaToCoSchema(option);
|
3803
|
+
return coValueSchema.getCoValueClass();
|
4017
3804
|
}
|
4018
3805
|
}
|
4019
3806
|
throw new Error(
|
4020
|
-
"
|
3807
|
+
"co.discriminatedUnion() of collaborative types with no matching discriminator value found"
|
4021
3808
|
);
|
4022
3809
|
};
|
4023
3810
|
return determineSchema;
|
@@ -4035,7 +3822,7 @@ function isUnionOfCoMapsDeeply(schema) {
|
|
4035
3822
|
}
|
4036
3823
|
}
|
4037
3824
|
function isCoMapOrUnionOfCoMapsDeeply(schema) {
|
4038
|
-
if (schema instanceof z.core.$ZodObject &&
|
3825
|
+
if (schema instanceof z.core.$ZodObject && isAnyCoValueSchema(schema)) {
|
4039
3826
|
return true;
|
4040
3827
|
} else if (schema instanceof z.core.$ZodUnion) {
|
4041
3828
|
return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
|
@@ -4047,14 +3834,21 @@ function isUnionOfPrimitivesDeeply(schema) {
|
|
4047
3834
|
if (schema instanceof z.core.$ZodUnion) {
|
4048
3835
|
return schema._zod.def.options.every(isUnionOfPrimitivesDeeply);
|
4049
3836
|
} else {
|
4050
|
-
return !(
|
3837
|
+
return !isAnyCoValueSchema(schema);
|
4051
3838
|
}
|
4052
3839
|
}
|
4053
3840
|
|
4054
3841
|
// src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts
|
4055
|
-
function
|
3842
|
+
function schemaFieldToCoFieldDef(schema) {
|
4056
3843
|
if (isCoValueClass(schema)) {
|
4057
3844
|
return coField.ref(schema);
|
3845
|
+
} else if (isCoValueSchema(schema)) {
|
3846
|
+
if (isAnyCoOptionalSchema(schema)) {
|
3847
|
+
return coField.ref(schema.getCoValueClass(), {
|
3848
|
+
optional: true
|
3849
|
+
});
|
3850
|
+
}
|
3851
|
+
return coField.ref(schema.getCoValueClass());
|
4058
3852
|
} else {
|
4059
3853
|
if ("_zod" in schema) {
|
4060
3854
|
if (schema._zod.def.type === "optional") {
|
@@ -4064,7 +3858,7 @@ function zodFieldToCoFieldDef(schema) {
|
|
4064
3858
|
if (isCoValueClass(inner)) {
|
4065
3859
|
return coField.ref(inner, { optional: true });
|
4066
3860
|
} else {
|
4067
|
-
return
|
3861
|
+
return schemaFieldToCoFieldDef(inner);
|
4068
3862
|
}
|
4069
3863
|
} else if (schema._zod.def.type === "string") {
|
4070
3864
|
return coField.string;
|
@@ -4077,7 +3871,7 @@ function zodFieldToCoFieldDef(schema) {
|
|
4077
3871
|
} else if (schema._zod.def.type === "enum") {
|
4078
3872
|
return coField.string;
|
4079
3873
|
} else if (schema._zod.def.type === "readonly") {
|
4080
|
-
return
|
3874
|
+
return schemaFieldToCoFieldDef(
|
4081
3875
|
schema.def.innerType
|
4082
3876
|
);
|
4083
3877
|
} else if (schema._zod.def.type === "date") {
|
@@ -4085,14 +3879,14 @@ function zodFieldToCoFieldDef(schema) {
|
|
4085
3879
|
} else if (schema._zod.def.type === "template_literal") {
|
4086
3880
|
return coField.string;
|
4087
3881
|
} else if (schema._zod.def.type === "lazy") {
|
4088
|
-
return
|
3882
|
+
return schemaFieldToCoFieldDef(
|
4089
3883
|
schema.unwrap()
|
4090
3884
|
);
|
4091
3885
|
} else if (schema._zod.def.type === "default" || schema._zod.def.type === "catch") {
|
4092
3886
|
console.warn(
|
4093
3887
|
"z.default()/z.catch() are not supported in collaborative schemas. They will be ignored."
|
4094
3888
|
);
|
4095
|
-
return
|
3889
|
+
return schemaFieldToCoFieldDef(
|
4096
3890
|
schema.def.innerType
|
4097
3891
|
);
|
4098
3892
|
} else if (schema._zod.def.type === "literal") {
|
@@ -4114,7 +3908,7 @@ function zodFieldToCoFieldDef(schema) {
|
|
4114
3908
|
return coField.json();
|
4115
3909
|
} else if (schema._zod.def.type === "custom") {
|
4116
3910
|
if ("builtin" in schema) {
|
4117
|
-
return
|
3911
|
+
return schemaFieldToCoFieldDef(schema.builtin);
|
4118
3912
|
} else {
|
4119
3913
|
throw new Error(`Unsupported custom zod type`);
|
4120
3914
|
}
|
@@ -4143,61 +3937,81 @@ function zodFieldToCoFieldDef(schema) {
|
|
4143
3937
|
|
4144
3938
|
// src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts
|
4145
3939
|
var coSchemasForZodSchemas = /* @__PURE__ */ new Map();
|
3940
|
+
function isAnyCoValueSchema(schema) {
|
3941
|
+
return "collaborative" in schema && schema.collaborative === true;
|
3942
|
+
}
|
3943
|
+
function isCoValueSchema(schema) {
|
3944
|
+
return isAnyCoValueSchema(schema) && "getCoValueClass" in schema;
|
3945
|
+
}
|
4146
3946
|
function tryZodSchemaToCoSchema(schema) {
|
4147
|
-
if (
|
3947
|
+
if (isAnyCoValueSchema(schema)) {
|
4148
3948
|
if (coSchemasForZodSchemas.has(schema)) {
|
4149
|
-
return coSchemasForZodSchemas.get(
|
3949
|
+
return coSchemasForZodSchemas.get(
|
3950
|
+
schema
|
3951
|
+
);
|
4150
3952
|
}
|
4151
|
-
if (
|
3953
|
+
if (isAnyCoOptionalSchema(schema)) {
|
3954
|
+
return null;
|
3955
|
+
} else if (isZodObject(schema)) {
|
4152
3956
|
const def = getDef(schema);
|
4153
3957
|
const ClassToExtend = "builtin" in schema && schema.builtin === "Account" ? Account : CoMap;
|
4154
|
-
const
|
3958
|
+
const coValueClass = class ZCoMap extends ClassToExtend {
|
4155
3959
|
constructor(options) {
|
4156
3960
|
super(options);
|
4157
3961
|
for (const [field, fieldType] of Object.entries(
|
4158
3962
|
def.shape
|
4159
3963
|
)) {
|
4160
|
-
this[field] =
|
3964
|
+
this[field] = schemaFieldToCoFieldDef(
|
4161
3965
|
zodSchemaToCoSchemaOrKeepPrimitive(fieldType)
|
4162
3966
|
);
|
4163
3967
|
}
|
4164
3968
|
if (def.catchall) {
|
4165
|
-
this[coField.items] =
|
3969
|
+
this[coField.items] = schemaFieldToCoFieldDef(
|
4166
3970
|
zodSchemaToCoSchemaOrKeepPrimitive(def.catchall)
|
4167
3971
|
);
|
4168
3972
|
}
|
4169
3973
|
}
|
4170
3974
|
};
|
4171
|
-
|
4172
|
-
|
3975
|
+
const coValueSchema = ClassToExtend === Account ? enrichAccountSchema(schema, coValueClass) : enrichCoMapSchema(schema, coValueClass);
|
3976
|
+
coSchemasForZodSchemas.set(schema, coValueSchema);
|
3977
|
+
return coValueSchema;
|
4173
3978
|
} else if (isZodArray(schema)) {
|
4174
3979
|
const def = getDef(schema);
|
4175
|
-
const
|
3980
|
+
const coValueClass = class ZCoList extends CoList {
|
4176
3981
|
constructor(options) {
|
4177
3982
|
super(options);
|
4178
|
-
this[coField.items] =
|
3983
|
+
this[coField.items] = schemaFieldToCoFieldDef(
|
4179
3984
|
zodSchemaToCoSchemaOrKeepPrimitive(def.element)
|
4180
3985
|
);
|
4181
3986
|
}
|
4182
3987
|
};
|
4183
|
-
|
4184
|
-
|
3988
|
+
const coValueSchema = enrichCoListSchema(schema, coValueClass);
|
3989
|
+
coSchemasForZodSchemas.set(schema, coValueSchema);
|
3990
|
+
return coValueSchema;
|
4185
3991
|
} else if (isZodCustom(schema)) {
|
4186
3992
|
if ("builtin" in schema) {
|
4187
3993
|
if (schema.builtin === "CoFeed" && "element" in schema) {
|
4188
|
-
|
4189
|
-
|
3994
|
+
const coValueClass = CoFeed.Of(
|
3995
|
+
schemaFieldToCoFieldDef(
|
4190
3996
|
zodSchemaToCoSchemaOrKeepPrimitive(
|
4191
3997
|
schema.element
|
4192
3998
|
)
|
4193
3999
|
)
|
4194
4000
|
);
|
4001
|
+
const coValueSchema = enrichCoFeedSchema(schema, coValueClass);
|
4002
|
+
return coValueSchema;
|
4195
4003
|
} else if (schema.builtin === "FileStream") {
|
4196
|
-
|
4004
|
+
const coValueClass = FileStream;
|
4005
|
+
const coValueSchema = enrichFileStreamSchema(schema, coValueClass);
|
4006
|
+
return coValueSchema;
|
4197
4007
|
} else if (schema.builtin === "CoPlainText") {
|
4198
|
-
|
4008
|
+
const coValueClass = CoPlainText;
|
4009
|
+
const coValueSchema = enrichPlainTextSchema(schema, coValueClass);
|
4010
|
+
return coValueSchema;
|
4199
4011
|
} else if (schema.builtin === "CoRichText") {
|
4200
|
-
|
4012
|
+
const coValueClass = CoRichText;
|
4013
|
+
const coValueSchema = enrichRichTextSchema(schema, coValueClass);
|
4014
|
+
return coValueSchema;
|
4201
4015
|
} else {
|
4202
4016
|
throw new Error(`Unsupported builtin type: ${schema.builtin}`);
|
4203
4017
|
}
|
@@ -4211,9 +4025,12 @@ function tryZodSchemaToCoSchema(schema) {
|
|
4211
4025
|
}
|
4212
4026
|
} else if (schema instanceof z.core.$ZodDiscriminatedUnion) {
|
4213
4027
|
if (isUnionOfCoMapsDeeply(schema)) {
|
4214
|
-
|
4215
|
-
|
4028
|
+
const coValueClass = SchemaUnion.Of(schemaUnionDiscriminatorFor(schema));
|
4029
|
+
const coValueSchema = enrichCoDiscriminatedUnionSchema(
|
4030
|
+
schema,
|
4031
|
+
coValueClass
|
4216
4032
|
);
|
4033
|
+
return coValueSchema;
|
4217
4034
|
} else {
|
4218
4035
|
throw new Error(
|
4219
4036
|
"z.discriminatedUnion() of non-collaborative types is not supported as a top-level schema"
|
@@ -4223,7 +4040,7 @@ function tryZodSchemaToCoSchema(schema) {
|
|
4223
4040
|
return null;
|
4224
4041
|
}
|
4225
4042
|
}
|
4226
|
-
function
|
4043
|
+
function zodSchemaToCoSchema(schema) {
|
4227
4044
|
const coSchema = tryZodSchemaToCoSchema(schema);
|
4228
4045
|
if (!coSchema) {
|
4229
4046
|
throw new Error(
|
@@ -4235,16 +4052,18 @@ function zodSchemaToCoSchema2(schema) {
|
|
4235
4052
|
function anySchemaToCoSchema(schema) {
|
4236
4053
|
if (isCoValueClass(schema)) {
|
4237
4054
|
return schema;
|
4238
|
-
} else if (
|
4239
|
-
return schema.
|
4055
|
+
} else if (isCoValueSchema(schema)) {
|
4056
|
+
return schema.getCoValueClass();
|
4240
4057
|
} else if ("def" in schema) {
|
4241
|
-
const coSchema = tryZodSchemaToCoSchema(
|
4058
|
+
const coSchema = tryZodSchemaToCoSchema(
|
4059
|
+
schema
|
4060
|
+
);
|
4242
4061
|
if (!coSchema) {
|
4243
4062
|
throw new Error(
|
4244
4063
|
`Unsupported zod type: ${schema.def?.type || JSON.stringify(schema)}`
|
4245
4064
|
);
|
4246
4065
|
}
|
4247
|
-
return coSchema;
|
4066
|
+
return coSchema.getCoValueClass();
|
4248
4067
|
}
|
4249
4068
|
throw new Error(`Unsupported schema: ${JSON.stringify(schema)}`);
|
4250
4069
|
}
|
@@ -4256,6 +4075,309 @@ function zodSchemaToCoSchemaOrKeepPrimitive(schema) {
|
|
4256
4075
|
return coSchema;
|
4257
4076
|
}
|
4258
4077
|
|
4078
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts
|
4079
|
+
function createCoOptionalSchema(schema) {
|
4080
|
+
return Object.assign(z.optional(schema), {
|
4081
|
+
collaborative: true,
|
4082
|
+
getCoValueClass: () => {
|
4083
|
+
return schema.getCoValueClass();
|
4084
|
+
}
|
4085
|
+
});
|
4086
|
+
}
|
4087
|
+
function isAnyCoOptionalSchema(schema) {
|
4088
|
+
return isAnyCoValueSchema(schema) && schema._zod.def.type === "optional";
|
4089
|
+
}
|
4090
|
+
|
4091
|
+
// src/tools/implementation/zodSchema/zodCo.ts
|
4092
|
+
var coMapDefiner = (shape) => {
|
4093
|
+
const objectSchema = z.object(shape).meta({
|
4094
|
+
collaborative: true
|
4095
|
+
});
|
4096
|
+
const enrichedSchema = Object.assign(objectSchema, {
|
4097
|
+
collaborative: true
|
4098
|
+
});
|
4099
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4100
|
+
};
|
4101
|
+
var coAccountDefiner = (shape = {
|
4102
|
+
profile: coMapDefiner({
|
4103
|
+
name: z.string(),
|
4104
|
+
inbox: z.optional(z.string()),
|
4105
|
+
inboxInvite: z.optional(z.string())
|
4106
|
+
}),
|
4107
|
+
root: coMapDefiner({})
|
4108
|
+
}) => {
|
4109
|
+
const schema = z.object(shape).meta({
|
4110
|
+
collaborative: true
|
4111
|
+
});
|
4112
|
+
const enrichedSchema = Object.assign(schema, {
|
4113
|
+
collaborative: true,
|
4114
|
+
builtin: "Account"
|
4115
|
+
});
|
4116
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4117
|
+
};
|
4118
|
+
var coRecordDefiner = (_keyType, valueType) => {
|
4119
|
+
return coMapDefiner({}).catchall(valueType);
|
4120
|
+
};
|
4121
|
+
var coListDefiner = (element) => {
|
4122
|
+
const schema = z.array(element).meta({
|
4123
|
+
collaborative: true
|
4124
|
+
});
|
4125
|
+
const enrichedSchema = Object.assign(schema, {
|
4126
|
+
collaborative: true
|
4127
|
+
});
|
4128
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4129
|
+
};
|
4130
|
+
var coProfileDefiner = (shape = {}) => {
|
4131
|
+
const ehnancedShape = Object.assign(shape, {
|
4132
|
+
name: z.string(),
|
4133
|
+
inbox: z.optional(z.string()),
|
4134
|
+
inboxInvite: z.optional(z.string())
|
4135
|
+
});
|
4136
|
+
return coMapDefiner(ehnancedShape);
|
4137
|
+
};
|
4138
|
+
var coFeedDefiner = (element) => {
|
4139
|
+
const schema = z.instanceof(CoFeed);
|
4140
|
+
const enrichedSchema = Object.assign(schema, {
|
4141
|
+
collaborative: true,
|
4142
|
+
builtin: "CoFeed",
|
4143
|
+
element
|
4144
|
+
});
|
4145
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4146
|
+
};
|
4147
|
+
var coFileStreamDefiner = () => {
|
4148
|
+
const schema = z.instanceof(FileStream);
|
4149
|
+
const enrichedSchema = Object.assign(schema, {
|
4150
|
+
collaborative: true,
|
4151
|
+
builtin: "FileStream"
|
4152
|
+
});
|
4153
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4154
|
+
};
|
4155
|
+
var coPlainTextDefiner = () => {
|
4156
|
+
const schema = z.instanceof(CoPlainText);
|
4157
|
+
const enrichedSchema = Object.assign(schema, {
|
4158
|
+
collaborative: true,
|
4159
|
+
builtin: "CoPlainText"
|
4160
|
+
});
|
4161
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4162
|
+
};
|
4163
|
+
var coRichTextDefiner = () => {
|
4164
|
+
const schema = z.instanceof(CoRichText);
|
4165
|
+
const enrichedSchema = Object.assign(schema, {
|
4166
|
+
collaborative: true,
|
4167
|
+
builtin: "CoRichText"
|
4168
|
+
});
|
4169
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4170
|
+
};
|
4171
|
+
var coImageDefiner = () => {
|
4172
|
+
return ImageDefinition;
|
4173
|
+
};
|
4174
|
+
var coOptionalDefiner = (schema) => {
|
4175
|
+
return createCoOptionalSchema(schema);
|
4176
|
+
};
|
4177
|
+
var coDiscriminatedUnionDefiner = (discriminator, schemas) => {
|
4178
|
+
const schema = z.discriminatedUnion(discriminator, schemas);
|
4179
|
+
return zodSchemaToCoSchema(schema);
|
4180
|
+
};
|
4181
|
+
|
4182
|
+
// src/tools/implementation/zodSchema/coExport.ts
|
4183
|
+
var coExport_exports = {};
|
4184
|
+
__export(coExport_exports, {
|
4185
|
+
account: () => coAccountDefiner,
|
4186
|
+
discriminatedUnion: () => coDiscriminatedUnionDefiner,
|
4187
|
+
feed: () => coFeedDefiner,
|
4188
|
+
fileStream: () => coFileStreamDefiner,
|
4189
|
+
image: () => coImageDefiner,
|
4190
|
+
list: () => coListDefiner,
|
4191
|
+
map: () => coMapDefiner,
|
4192
|
+
optional: () => coOptionalDefiner,
|
4193
|
+
plainText: () => coPlainTextDefiner,
|
4194
|
+
profile: () => coProfileDefiner,
|
4195
|
+
record: () => coRecordDefiner,
|
4196
|
+
richText: () => coRichTextDefiner
|
4197
|
+
});
|
4198
|
+
|
4199
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
|
4200
|
+
function enrichCoMapSchema(schema, coValueClass) {
|
4201
|
+
const baseCatchall = schema.catchall;
|
4202
|
+
const coValueSchema = Object.assign(schema, {
|
4203
|
+
create: (...args) => {
|
4204
|
+
return coValueClass.create(...args);
|
4205
|
+
},
|
4206
|
+
load: (...args) => {
|
4207
|
+
return coValueClass.load(...args);
|
4208
|
+
},
|
4209
|
+
subscribe: (...args) => {
|
4210
|
+
return coValueClass.subscribe(...args);
|
4211
|
+
},
|
4212
|
+
findUnique: (...args) => {
|
4213
|
+
return coValueClass.findUnique(...args);
|
4214
|
+
},
|
4215
|
+
upsertUnique: (...args) => {
|
4216
|
+
return coValueClass.upsertUnique(...args);
|
4217
|
+
},
|
4218
|
+
loadUnique: (...args) => {
|
4219
|
+
return coValueClass.loadUnique(...args);
|
4220
|
+
},
|
4221
|
+
catchall: (index) => {
|
4222
|
+
const newSchema = baseCatchall(index);
|
4223
|
+
const enrichedSchema = Object.assign(newSchema, {
|
4224
|
+
collaborative: true
|
4225
|
+
});
|
4226
|
+
return zodSchemaToCoSchema(enrichedSchema);
|
4227
|
+
},
|
4228
|
+
withHelpers: (helpers) => {
|
4229
|
+
return Object.assign(schema, helpers(schema));
|
4230
|
+
},
|
4231
|
+
withMigration: (migration) => {
|
4232
|
+
coValueClass.prototype.migrate = migration;
|
4233
|
+
return coValueSchema;
|
4234
|
+
},
|
4235
|
+
getCoValueClass: () => {
|
4236
|
+
return coValueClass;
|
4237
|
+
}
|
4238
|
+
});
|
4239
|
+
return coValueSchema;
|
4240
|
+
}
|
4241
|
+
|
4242
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts
|
4243
|
+
function enrichCoDiscriminatedUnionSchema(schema, coValueClass) {
|
4244
|
+
return Object.assign(schema, {
|
4245
|
+
load: (...args) => {
|
4246
|
+
return coValueClass.load(...args);
|
4247
|
+
},
|
4248
|
+
subscribe: (...args) => {
|
4249
|
+
return coValueClass.subscribe(...args);
|
4250
|
+
},
|
4251
|
+
getCoValueClass: () => {
|
4252
|
+
return coValueClass;
|
4253
|
+
}
|
4254
|
+
});
|
4255
|
+
}
|
4256
|
+
|
4257
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts
|
4258
|
+
function enrichCoListSchema(schema, coValueClass) {
|
4259
|
+
return Object.assign(schema, {
|
4260
|
+
create: (...args) => {
|
4261
|
+
return coValueClass.create(...args);
|
4262
|
+
},
|
4263
|
+
load: (...args) => {
|
4264
|
+
return coValueClass.load(...args);
|
4265
|
+
},
|
4266
|
+
subscribe: (...args) => {
|
4267
|
+
return coValueClass.subscribe(...args);
|
4268
|
+
},
|
4269
|
+
withHelpers: (helpers) => {
|
4270
|
+
return Object.assign(schema, helpers(schema));
|
4271
|
+
},
|
4272
|
+
getCoValueClass: () => {
|
4273
|
+
return coValueClass;
|
4274
|
+
}
|
4275
|
+
});
|
4276
|
+
}
|
4277
|
+
|
4278
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts
|
4279
|
+
function enrichCoFeedSchema(schema, coValueClass) {
|
4280
|
+
return Object.assign(schema, {
|
4281
|
+
create: (...args) => {
|
4282
|
+
return coValueClass.create(...args);
|
4283
|
+
},
|
4284
|
+
load: (...args) => {
|
4285
|
+
return coValueClass.load(...args);
|
4286
|
+
},
|
4287
|
+
subscribe: (...args) => {
|
4288
|
+
return coValueClass.subscribe(...args);
|
4289
|
+
},
|
4290
|
+
withHelpers: (helpers) => {
|
4291
|
+
return Object.assign(schema, helpers(schema));
|
4292
|
+
},
|
4293
|
+
getCoValueClass: () => {
|
4294
|
+
return coValueClass;
|
4295
|
+
}
|
4296
|
+
});
|
4297
|
+
}
|
4298
|
+
|
4299
|
+
// src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
|
4300
|
+
function enrichAccountSchema(schema, coValueClass) {
|
4301
|
+
const enrichedSchema = Object.assign(schema, {
|
4302
|
+
create: (...args) => {
|
4303
|
+
return coValueClass.create(...args);
|
4304
|
+
},
|
4305
|
+
createAs: (...args) => {
|
4306
|
+
return coValueClass.createAs(...args);
|
4307
|
+
},
|
4308
|
+
getMe: (...args) => {
|
4309
|
+
return coValueClass.getMe(...args);
|
4310
|
+
},
|
4311
|
+
load: (...args) => {
|
4312
|
+
return coValueClass.load(...args);
|
4313
|
+
},
|
4314
|
+
subscribe: (...args) => {
|
4315
|
+
return coValueClass.subscribe(...args);
|
4316
|
+
},
|
4317
|
+
withHelpers: (helpers) => {
|
4318
|
+
return Object.assign(schema, helpers(schema));
|
4319
|
+
},
|
4320
|
+
fromRaw: (...args) => {
|
4321
|
+
return coValueClass.fromRaw(...args);
|
4322
|
+
},
|
4323
|
+
withMigration: (migration) => {
|
4324
|
+
coValueClass.prototype.migrate = async function(creationProps) {
|
4325
|
+
await migration(this, creationProps);
|
4326
|
+
};
|
4327
|
+
return enrichedSchema;
|
4328
|
+
},
|
4329
|
+
getCoValueClass: () => {
|
4330
|
+
return coValueClass;
|
4331
|
+
}
|
4332
|
+
});
|
4333
|
+
return enrichedSchema;
|
4334
|
+
}
|
4335
|
+
|
4336
|
+
// src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts
|
4337
|
+
function enrichFileStreamSchema(schema, coValueClass) {
|
4338
|
+
return Object.assign(schema, {
|
4339
|
+
create: (...args) => {
|
4340
|
+
return coValueClass.create(...args);
|
4341
|
+
},
|
4342
|
+
createFromBlob: (...args) => {
|
4343
|
+
return coValueClass.createFromBlob(...args);
|
4344
|
+
},
|
4345
|
+
load: (...args) => {
|
4346
|
+
return coValueClass.load(...args);
|
4347
|
+
},
|
4348
|
+
loadAsBlob: (...args) => {
|
4349
|
+
return coValueClass.loadAsBlob(...args);
|
4350
|
+
},
|
4351
|
+
subscribe: (...args) => {
|
4352
|
+
return coValueClass.subscribe(...args);
|
4353
|
+
},
|
4354
|
+
getCoValueClass: () => {
|
4355
|
+
return coValueClass;
|
4356
|
+
}
|
4357
|
+
});
|
4358
|
+
}
|
4359
|
+
|
4360
|
+
// src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts
|
4361
|
+
function enrichPlainTextSchema(schema, coValueClass) {
|
4362
|
+
return Object.assign(schema, {
|
4363
|
+
create: (...args) => {
|
4364
|
+
return coValueClass.create(...args);
|
4365
|
+
},
|
4366
|
+
load: (...args) => {
|
4367
|
+
return coValueClass.load(...args);
|
4368
|
+
},
|
4369
|
+
subscribe: (...args) => {
|
4370
|
+
return coValueClass.subscribe(...args);
|
4371
|
+
},
|
4372
|
+
fromRaw: (...args) => {
|
4373
|
+
return coValueClass.fromRaw(...args);
|
4374
|
+
},
|
4375
|
+
getCoValueClass: () => {
|
4376
|
+
return coValueClass;
|
4377
|
+
}
|
4378
|
+
});
|
4379
|
+
}
|
4380
|
+
|
4259
4381
|
// src/tools/coValues/extensions/imageDef.ts
|
4260
4382
|
var ImageDefinitionBase = coMapDefiner({
|
4261
4383
|
originalSize: z.tuple([z.number(), z.number()]),
|
@@ -4631,8 +4753,9 @@ var JazzContextManager = class {
|
|
4631
4753
|
peer2role: "server"
|
4632
4754
|
}
|
4633
4755
|
);
|
4634
|
-
prevContext.node.
|
4756
|
+
prevContext.node.removeStorage();
|
4635
4757
|
currentContext.node.syncManager.addPeer(prevAccountAsPeer);
|
4758
|
+
prevContext.node.syncManager.addPeer(currentAccountAsPeer);
|
4636
4759
|
try {
|
4637
4760
|
await this.props.onAnonymousAccountDiscarded?.(prevContext.me);
|
4638
4761
|
await prevContext.me.waitForAllCoValuesSync();
|
@@ -4921,9 +5044,9 @@ function isAccountInstance(instance) {
|
|
4921
5044
|
return "_type" in instance && instance._type === "Account";
|
4922
5045
|
}
|
4923
5046
|
function parseCoValueCreateOptions(options) {
|
4924
|
-
const
|
5047
|
+
const Group4 = RegisteredSchemas["Group"];
|
4925
5048
|
if (!options) {
|
4926
|
-
return { owner:
|
5049
|
+
return { owner: Group4.create(), uniqueness: void 0 };
|
4927
5050
|
}
|
4928
5051
|
if ("_type" in options) {
|
4929
5052
|
if (options._type === "Account" || options._type === "Group") {
|
@@ -4932,7 +5055,7 @@ function parseCoValueCreateOptions(options) {
|
|
4932
5055
|
}
|
4933
5056
|
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
4934
5057
|
return {
|
4935
|
-
owner: options.owner ??
|
5058
|
+
owner: options.owner ?? Group4.create(),
|
4936
5059
|
uniqueness
|
4937
5060
|
};
|
4938
5061
|
}
|
@@ -4972,9 +5095,9 @@ export {
|
|
4972
5095
|
createJazzContextForNewAccount,
|
4973
5096
|
createJazzContext,
|
4974
5097
|
createAnonymousJazzContext,
|
4975
|
-
|
4976
|
-
zodSchemaToCoSchema2 as zodSchemaToCoSchema,
|
5098
|
+
zodSchemaToCoSchema,
|
4977
5099
|
anySchemaToCoSchema,
|
5100
|
+
coExport_exports,
|
4978
5101
|
ImageDefinition,
|
4979
5102
|
KvStoreContext,
|
4980
5103
|
AuthSecretStorage,
|
@@ -4982,4 +5105,4 @@ export {
|
|
4982
5105
|
JazzContextManager
|
4983
5106
|
};
|
4984
5107
|
/* istanbul ignore file -- @preserve */
|
4985
|
-
//# sourceMappingURL=chunk-
|
5108
|
+
//# sourceMappingURL=chunk-DZFT4EZM.js.map
|