jazz-tools 0.15.16 → 0.16.0
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 +5 -5
- package/.svelte-kit/__package__/jazz.svelte.d.ts +2 -2
- package/.svelte-kit/__package__/jazz.svelte.d.ts.map +1 -1
- package/.turbo/turbo-build.log +46 -46
- package/CHANGELOG.md +25 -0
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser-media-images/index.d.ts +3 -1
- package/dist/browser-media-images/index.d.ts.map +1 -1
- package/dist/browser-media-images/index.js.map +1 -1
- package/dist/{chunk-OSVAAVWQ.js → chunk-MLCNE3TL.js} +594 -598
- package/dist/chunk-MLCNE3TL.js.map +1 -0
- package/dist/index.js +8 -10
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts +2 -2
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +2 -2
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +3 -3
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-native-core/hooks.d.ts +2 -2
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-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 +5 -5
- package/dist/svelte/jazz.svelte.d.ts +2 -2
- package/dist/svelte/jazz.svelte.d.ts.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts +3 -13
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +2 -2
- package/dist/tools/coValues/account.d.ts.map +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 +5 -18
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +4 -1
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +4 -7
- package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts +2 -2
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +2 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts +2 -2
- package/dist/tools/coValues/request.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +5 -1
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +3 -3
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts +4 -4
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/implementation/invites.d.ts +2 -2
- package/dist/tools/implementation/invites.d.ts.map +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts +8 -0
- package/dist/tools/implementation/schemaUtils.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/coExport.d.ts +11 -1
- package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts +22 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +11 -11
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +34 -24
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +16 -14
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +23 -17
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +24 -16
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +20 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +18 -12
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +18 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +14 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +14 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +14 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +15 -13
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +12 -15
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +17 -20
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +17 -20
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts +3 -5
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts +10 -8
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts +4 -8
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +21 -30
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +3 -2
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/utilityTypes.d.ts +10 -0
- package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +2 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +2 -2
- package/dist/worker/index.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/index.ts +2 -4
- package/src/browser-media-images/index.ts +1 -1
- package/src/react/hooks.tsx +2 -2
- package/src/react-core/hooks.ts +6 -6
- package/src/react-core/tests/useAccount.test.ts +2 -2
- package/src/react-core/tests/useCoState.test.ts +3 -2
- package/src/react-native-core/hooks.tsx +2 -2
- package/src/svelte/jazz.class.svelte.ts +10 -7
- package/src/svelte/jazz.svelte.ts +2 -2
- package/src/tools/coValues/CoValueBase.ts +8 -20
- package/src/tools/coValues/account.ts +18 -14
- package/src/tools/coValues/coFeed.ts +0 -4
- package/src/tools/coValues/coList.ts +7 -9
- package/src/tools/coValues/coMap.ts +1 -6
- package/src/tools/coValues/coPlainText.ts +4 -4
- package/src/tools/coValues/deepLoading.ts +4 -1
- package/src/tools/coValues/extensions/imageDef.ts +3 -3
- package/src/tools/coValues/inbox.ts +4 -4
- package/src/tools/coValues/interfaces.ts +4 -71
- package/src/tools/coValues/request.ts +15 -13
- package/src/tools/coValues/schemaUnion.ts +8 -4
- package/src/tools/exports.ts +3 -14
- package/src/tools/implementation/createContext.ts +9 -9
- package/src/tools/implementation/invites.ts +2 -2
- package/src/tools/implementation/schemaUtils.ts +18 -0
- package/src/tools/implementation/zodSchema/coExport.ts +14 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +156 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +133 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +36 -17
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +101 -52
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +54 -50
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +54 -46
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +187 -137
- package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +29 -27
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +28 -18
- package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +18 -0
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +45 -36
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +47 -35
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +43 -30
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +28 -23
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +28 -25
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +86 -78
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +91 -82
- package/src/tools/implementation/zodSchema/unionUtils.ts +47 -51
- package/src/tools/implementation/zodSchema/zodCo.ts +42 -75
- package/src/tools/implementation/zodSchema/zodReExport.ts +44 -24
- package/src/tools/implementation/zodSchema/zodSchema.ts +64 -102
- package/src/tools/internal.ts +3 -2
- package/src/tools/lib/utilityTypes.ts +7 -0
- package/src/tools/subscribe/utils.ts +4 -2
- package/src/tools/testing.ts +4 -4
- package/src/tools/tests/ContextManager.test.ts +8 -9
- package/src/tools/tests/account.test.ts +65 -3
- package/src/tools/tests/coDiscriminatedUnion.test-d.ts +38 -0
- package/src/tools/tests/coDiscriminatedUnion.test.ts +219 -1
- package/src/tools/tests/coFeed.test-d.ts +4 -3
- package/src/tools/tests/coList.test-d.ts +32 -3
- package/src/tools/tests/coList.test.ts +20 -2
- package/src/tools/tests/coMap.record.test-d.ts +31 -3
- package/src/tools/tests/coMap.record.test.ts +9 -9
- package/src/tools/tests/coMap.test-d.ts +8 -8
- package/src/tools/tests/coMap.test.ts +19 -5
- package/src/tools/tests/coOptional.test.ts +63 -1
- package/src/tools/tests/createContext.test.ts +7 -9
- package/src/tools/tests/deepLoading.test.ts +4 -10
- package/src/tools/tests/exportImport.test.ts +2 -2
- package/src/tools/tests/groupsAndAccounts.test.ts +5 -4
- package/src/tools/tests/inbox.test.ts +3 -2
- package/src/tools/tests/load.test.ts +3 -29
- package/src/tools/tests/schemaUnion.test.ts +2 -2
- package/src/tools/tests/subscribe.test.ts +22 -114
- package/src/tools/tests/testing.test.ts +6 -6
- package/src/tools/tests/zod.test-d.ts +27 -0
- package/src/tools/tests/zod.test.ts +50 -45
- package/src/worker/index.ts +0 -1
- package/dist/chunk-OSVAAVWQ.js.map +0 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +0 -12
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +0 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +0 -9
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +0 -1
- package/src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +0 -172
- package/src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +0 -218
@@ -42,15 +42,27 @@ __export(zodReExport_exports, {
|
|
42
42
|
z: () => z
|
43
43
|
});
|
44
44
|
import {
|
45
|
-
|
46
|
-
|
47
|
-
union as zodUnion
|
45
|
+
object as zodObject,
|
46
|
+
strictObject as zodStrictObject
|
48
47
|
} from "zod/v4";
|
48
|
+
|
49
|
+
// src/tools/implementation/schemaUtils.ts
|
50
|
+
function removeGetters(obj) {
|
51
|
+
const result = {};
|
52
|
+
for (const key of Object.keys(obj)) {
|
53
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
54
|
+
if (!descriptor?.get) {
|
55
|
+
result[key] = obj[key];
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return result;
|
59
|
+
}
|
60
|
+
|
61
|
+
// src/tools/implementation/zodSchema/zodReExport.ts
|
49
62
|
import {
|
50
63
|
string,
|
51
64
|
number,
|
52
65
|
boolean,
|
53
|
-
object,
|
54
66
|
templateLiteral,
|
55
67
|
json,
|
56
68
|
date,
|
@@ -72,20 +84,38 @@ import {
|
|
72
84
|
cidrv6,
|
73
85
|
iso,
|
74
86
|
int32,
|
75
|
-
|
87
|
+
union,
|
76
88
|
discriminatedUnion,
|
77
89
|
int,
|
78
90
|
optional,
|
91
|
+
array,
|
92
|
+
tuple,
|
79
93
|
z
|
80
94
|
} from "zod/v4";
|
81
|
-
function
|
82
|
-
|
95
|
+
function object(shape, params) {
|
96
|
+
rejectCoValueSchemas(
|
97
|
+
shape,
|
98
|
+
"z.object() does not support collaborative types as values. Use co.map() instead"
|
99
|
+
);
|
100
|
+
return zodObject(shape, params);
|
101
|
+
}
|
102
|
+
function strictObject(shape, params) {
|
103
|
+
rejectCoValueSchemas(
|
104
|
+
shape,
|
105
|
+
"z.strictObject() does not support collaborative types as values. Use co.map() instead"
|
106
|
+
);
|
107
|
+
return zodStrictObject(shape, params);
|
108
|
+
}
|
109
|
+
function rejectCoValueSchemas(shape, errorMessage) {
|
110
|
+
if (containsCoValueSchema(shape)) {
|
111
|
+
throw Error(errorMessage);
|
112
|
+
}
|
83
113
|
}
|
84
|
-
function
|
85
|
-
return
|
114
|
+
function containsCoValueSchema(shape) {
|
115
|
+
return Object.values(removeGetters(shape ?? {})).some(isAnyCoValueSchema);
|
86
116
|
}
|
87
|
-
function
|
88
|
-
return
|
117
|
+
function isAnyCoValueSchema(schema) {
|
118
|
+
return "collaborative" in schema && schema.collaborative === true;
|
89
119
|
}
|
90
120
|
|
91
121
|
// src/tools/coValues/interfaces.ts
|
@@ -109,9 +139,9 @@ var CoValueBase = class {
|
|
109
139
|
if (agent instanceof ControlledAccount) {
|
110
140
|
return coValuesCache.get(
|
111
141
|
agent.account,
|
112
|
-
() =>
|
113
|
-
|
114
|
-
)
|
142
|
+
() => coValueClassFromCoValueClassOrSchema(
|
143
|
+
RegisteredSchemas["Account"]
|
144
|
+
).fromRaw(agent.account)
|
115
145
|
);
|
116
146
|
}
|
117
147
|
return new AnonymousJazzAgent(this._raw.core.node);
|
@@ -723,9 +753,9 @@ var _CoList = class _CoList extends Array {
|
|
723
753
|
}
|
724
754
|
/** @category Collaboration */
|
725
755
|
get _owner() {
|
726
|
-
return this._raw.group instanceof RawAccount2 ?
|
727
|
-
|
728
|
-
) : RegisteredSchemas["Group"].fromRaw(this._raw.group);
|
756
|
+
return this._raw.group instanceof RawAccount2 ? coValueClassFromCoValueClassOrSchema(
|
757
|
+
RegisteredSchemas["Account"]
|
758
|
+
).fromRaw(this._raw.group) : RegisteredSchemas["Group"].fromRaw(this._raw.group);
|
729
759
|
}
|
730
760
|
/**
|
731
761
|
* If a `CoList`'s items are a `coField.ref(...)`, you can use `coList._refs[i]` to access
|
@@ -761,9 +791,9 @@ var _CoList = class _CoList extends Array {
|
|
761
791
|
if (agent instanceof ControlledAccount2) {
|
762
792
|
return coValuesCache.get(
|
763
793
|
agent.account,
|
764
|
-
() =>
|
765
|
-
|
766
|
-
)
|
794
|
+
() => coValueClassFromCoValueClassOrSchema(
|
795
|
+
RegisteredSchemas["Account"]
|
796
|
+
).fromRaw(agent.account)
|
767
797
|
);
|
768
798
|
}
|
769
799
|
return new AnonymousJazzAgent(this._raw.core.node);
|
@@ -1776,9 +1806,13 @@ var _Account = class _Account extends CoValueBase {
|
|
1776
1806
|
valueID,
|
1777
1807
|
inviteSecret
|
1778
1808
|
);
|
1779
|
-
return loadCoValue(
|
1780
|
-
|
1781
|
-
|
1809
|
+
return loadCoValue(
|
1810
|
+
coValueClassFromCoValueClassOrSchema(coValueClass),
|
1811
|
+
valueID,
|
1812
|
+
{
|
1813
|
+
loadAs: this
|
1814
|
+
}
|
1815
|
+
);
|
1782
1816
|
}
|
1783
1817
|
/** @private */
|
1784
1818
|
static async create(options) {
|
@@ -1926,7 +1960,11 @@ var AccountAndGroupProxyHandler = {
|
|
1926
1960
|
return true;
|
1927
1961
|
} else if (key === "root") {
|
1928
1962
|
if (value) {
|
1929
|
-
target._raw.set(
|
1963
|
+
target._raw.set(
|
1964
|
+
"root",
|
1965
|
+
value.id,
|
1966
|
+
"trusting"
|
1967
|
+
);
|
1930
1968
|
}
|
1931
1969
|
return true;
|
1932
1970
|
} else {
|
@@ -2273,7 +2311,7 @@ var Inbox = class _Inbox {
|
|
2273
2311
|
);
|
2274
2312
|
}
|
2275
2313
|
return loadCoValue(
|
2276
|
-
|
2314
|
+
coValueClassFromCoValueClassOrSchema(Schema),
|
2277
2315
|
message.get("payload"),
|
2278
2316
|
{
|
2279
2317
|
loadAs: account
|
@@ -2465,9 +2503,9 @@ var CoPlainText = class extends String {
|
|
2465
2503
|
if (agent instanceof ControlledAccount4) {
|
2466
2504
|
return coValuesCache.get(
|
2467
2505
|
agent.account,
|
2468
|
-
() =>
|
2469
|
-
|
2470
|
-
)
|
2506
|
+
() => coValueClassFromCoValueClassOrSchema(
|
2507
|
+
RegisteredSchemas["Account"]
|
2508
|
+
).fromRaw(agent.account)
|
2471
2509
|
);
|
2472
2510
|
}
|
2473
2511
|
return new AnonymousJazzAgent(this._raw.core.node);
|
@@ -3019,7 +3057,9 @@ function getOwnerFromRawValue(raw) {
|
|
3019
3057
|
const owner = raw.group;
|
3020
3058
|
return coValuesCache.get(
|
3021
3059
|
owner,
|
3022
|
-
() => owner instanceof RawAccount6 ?
|
3060
|
+
() => owner instanceof RawAccount6 ? coValueClassFromCoValueClassOrSchema(
|
3061
|
+
RegisteredSchemas["Account"]
|
3062
|
+
).fromRaw(owner) : RegisteredSchemas["Group"].fromRaw(owner)
|
3023
3063
|
);
|
3024
3064
|
}
|
3025
3065
|
function createCoValue(ref2, raw, subscriptionScope) {
|
@@ -3569,7 +3609,7 @@ async function createJazzContextFromExistingCredentials({
|
|
3569
3609
|
crypto
|
3570
3610
|
);
|
3571
3611
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3572
|
-
const AccountClass =
|
3612
|
+
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
3573
3613
|
const node = await LocalNode2.withLoadedAccount({
|
3574
3614
|
accountID: credentials.accountID,
|
3575
3615
|
accountSecret: credentials.secret,
|
@@ -3609,7 +3649,7 @@ async function createJazzContextForNewAccount({
|
|
3609
3649
|
storage
|
3610
3650
|
}) {
|
3611
3651
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3612
|
-
const AccountClass =
|
3652
|
+
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
3613
3653
|
const { node } = await LocalNode2.withNewlyCreatedAccount({
|
3614
3654
|
creationProps,
|
3615
3655
|
peersToLoadFrom,
|
@@ -3715,55 +3755,445 @@ function createAnonymousJazzContext({
|
|
3715
3755
|
};
|
3716
3756
|
}
|
3717
3757
|
|
3718
|
-
// src/tools/implementation/zodSchema/
|
3719
|
-
|
3720
|
-
|
3758
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts
|
3759
|
+
var CoDiscriminatedUnionSchema = class {
|
3760
|
+
constructor(coreSchema, coValueClass) {
|
3761
|
+
this.coValueClass = coValueClass;
|
3762
|
+
this.collaborative = true;
|
3763
|
+
this.builtin = "CoDiscriminatedUnion";
|
3764
|
+
this.getDefinition = coreSchema.getDefinition;
|
3765
|
+
}
|
3766
|
+
load(id, options) {
|
3767
|
+
return this.coValueClass.load(id, options);
|
3768
|
+
}
|
3769
|
+
subscribe(id, options, listener) {
|
3770
|
+
return this.coValueClass.subscribe(id, options, listener);
|
3771
|
+
}
|
3772
|
+
getCoValueClass() {
|
3773
|
+
return this.coValueClass;
|
3774
|
+
}
|
3775
|
+
optional() {
|
3776
|
+
return coOptionalDefiner(this);
|
3777
|
+
}
|
3778
|
+
};
|
3779
|
+
function createCoreCoDiscriminatedUnionSchema(discriminator, schemas) {
|
3780
|
+
return {
|
3781
|
+
collaborative: true,
|
3782
|
+
builtin: "CoDiscriminatedUnion",
|
3783
|
+
getDefinition: () => ({
|
3784
|
+
discriminator,
|
3785
|
+
get discriminatorMap() {
|
3786
|
+
const propValues = {};
|
3787
|
+
for (const option of schemas) {
|
3788
|
+
const dm = option.getDefinition().discriminatorMap;
|
3789
|
+
if (!dm || Object.keys(dm).length === 0)
|
3790
|
+
throw new Error(
|
3791
|
+
`Invalid discriminated union option at index "${schemas.indexOf(option)}"`
|
3792
|
+
);
|
3793
|
+
for (const [k, v] of Object.entries(dm)) {
|
3794
|
+
propValues[k] ??= /* @__PURE__ */ new Set();
|
3795
|
+
for (const val of v) {
|
3796
|
+
propValues[k].add(val);
|
3797
|
+
}
|
3798
|
+
}
|
3799
|
+
}
|
3800
|
+
return propValues;
|
3801
|
+
},
|
3802
|
+
get options() {
|
3803
|
+
return schemas;
|
3804
|
+
}
|
3805
|
+
})
|
3806
|
+
};
|
3807
|
+
}
|
3808
|
+
|
3809
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts
|
3810
|
+
var CoOptionalSchema = class {
|
3811
|
+
constructor(innerType) {
|
3812
|
+
this.innerType = innerType;
|
3813
|
+
this.collaborative = true;
|
3814
|
+
this.builtin = "CoOptional";
|
3815
|
+
this.getDefinition = () => ({
|
3816
|
+
innerType: this.innerType
|
3817
|
+
});
|
3818
|
+
}
|
3819
|
+
getCoValueClass() {
|
3820
|
+
return this.innerType.getCoValueClass();
|
3821
|
+
}
|
3822
|
+
};
|
3823
|
+
|
3824
|
+
// src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts
|
3825
|
+
function createCoreCoRichTextSchema() {
|
3826
|
+
return {
|
3827
|
+
collaborative: true,
|
3828
|
+
builtin: "CoRichText"
|
3829
|
+
};
|
3830
|
+
}
|
3831
|
+
var RichTextSchema = class {
|
3832
|
+
constructor(coValueClass) {
|
3833
|
+
this.coValueClass = coValueClass;
|
3834
|
+
this.collaborative = true;
|
3835
|
+
this.builtin = "CoRichText";
|
3836
|
+
}
|
3837
|
+
create(text, options) {
|
3838
|
+
return this.coValueClass.create(text, options);
|
3839
|
+
}
|
3840
|
+
load(id, options) {
|
3841
|
+
return this.coValueClass.load(id, options);
|
3842
|
+
}
|
3843
|
+
subscribe(...args) {
|
3844
|
+
return this.coValueClass.subscribe(...args);
|
3845
|
+
}
|
3846
|
+
getCoValueClass() {
|
3847
|
+
return this.coValueClass;
|
3848
|
+
}
|
3849
|
+
optional() {
|
3850
|
+
return coOptionalDefiner(this);
|
3851
|
+
}
|
3852
|
+
};
|
3853
|
+
|
3854
|
+
// src/tools/implementation/zodSchema/zodCo.ts
|
3855
|
+
var coMapDefiner = (shape) => {
|
3856
|
+
const coreSchema = createCoreCoMapSchema(shape);
|
3857
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3858
|
+
};
|
3859
|
+
var coAccountDefiner = (shape = {
|
3860
|
+
profile: coMapDefiner({
|
3861
|
+
name: z.string(),
|
3862
|
+
inbox: z.optional(z.string()),
|
3863
|
+
inboxInvite: z.optional(z.string())
|
3864
|
+
}),
|
3865
|
+
root: coMapDefiner({})
|
3866
|
+
}) => {
|
3867
|
+
const coreSchema = createCoreAccountSchema(shape);
|
3868
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3869
|
+
};
|
3870
|
+
var coRecordDefiner = (_keyType, valueType) => {
|
3871
|
+
return coMapDefiner({}).catchall(valueType);
|
3872
|
+
};
|
3873
|
+
var coListDefiner = (element) => {
|
3874
|
+
const coreSchema = createCoreCoListSchema(element);
|
3875
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3876
|
+
};
|
3877
|
+
var coProfileDefiner = (shape = {}) => {
|
3878
|
+
const ehnancedShape = Object.assign(shape, {
|
3879
|
+
name: z.string(),
|
3880
|
+
inbox: z.optional(z.string()),
|
3881
|
+
inboxInvite: z.optional(z.string())
|
3882
|
+
});
|
3883
|
+
return coMapDefiner(ehnancedShape);
|
3884
|
+
};
|
3885
|
+
var coFeedDefiner = (element) => {
|
3886
|
+
const coreSchema = createCoreCoFeedSchema(element);
|
3887
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3888
|
+
};
|
3889
|
+
var coFileStreamDefiner = () => {
|
3890
|
+
const coreSchema = createCoreFileStreamSchema();
|
3891
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3892
|
+
};
|
3893
|
+
var coPlainTextDefiner = () => {
|
3894
|
+
const coreSchema = createCoreCoPlainTextSchema();
|
3895
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3896
|
+
};
|
3897
|
+
var coRichTextDefiner = () => {
|
3898
|
+
const coreSchema = createCoreCoRichTextSchema();
|
3899
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3900
|
+
};
|
3901
|
+
var coImageDefiner = () => {
|
3902
|
+
return ImageDefinition;
|
3903
|
+
};
|
3904
|
+
var coOptionalDefiner = (schema) => {
|
3905
|
+
return new CoOptionalSchema(schema);
|
3906
|
+
};
|
3907
|
+
var coDiscriminatedUnionDefiner = (discriminator, schemas) => {
|
3908
|
+
const coreSchema = createCoreCoDiscriminatedUnionSchema(
|
3909
|
+
discriminator,
|
3910
|
+
schemas
|
3911
|
+
);
|
3912
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
3913
|
+
};
|
3914
|
+
|
3915
|
+
// src/tools/implementation/zodSchema/coExport.ts
|
3916
|
+
var coExport_exports = {};
|
3917
|
+
__export(coExport_exports, {
|
3918
|
+
DiscriminatedUnion: () => CoDiscriminatedUnionSchema,
|
3919
|
+
Feed: () => CoFeedSchema,
|
3920
|
+
FileStream: () => FileStreamSchema,
|
3921
|
+
List: () => CoListSchema,
|
3922
|
+
Optional: () => CoOptionalSchema,
|
3923
|
+
PlainText: () => PlainTextSchema,
|
3924
|
+
RichText: () => RichTextSchema,
|
3925
|
+
account: () => coAccountDefiner,
|
3926
|
+
discriminatedUnion: () => coDiscriminatedUnionDefiner,
|
3927
|
+
feed: () => coFeedDefiner,
|
3928
|
+
fileStream: () => coFileStreamDefiner,
|
3929
|
+
image: () => coImageDefiner,
|
3930
|
+
list: () => coListDefiner,
|
3931
|
+
map: () => coMapDefiner,
|
3932
|
+
optional: () => coOptionalDefiner,
|
3933
|
+
plainText: () => coPlainTextDefiner,
|
3934
|
+
profile: () => coProfileDefiner,
|
3935
|
+
record: () => coRecordDefiner,
|
3936
|
+
richText: () => coRichTextDefiner
|
3937
|
+
});
|
3938
|
+
|
3939
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
|
3940
|
+
function createCoreCoMapSchema(shape, catchAll) {
|
3941
|
+
return {
|
3942
|
+
collaborative: true,
|
3943
|
+
builtin: "CoMap",
|
3944
|
+
shape,
|
3945
|
+
catchAll,
|
3946
|
+
getDefinition: () => ({
|
3947
|
+
get shape() {
|
3948
|
+
return shape;
|
3949
|
+
},
|
3950
|
+
get catchall() {
|
3951
|
+
return catchAll;
|
3952
|
+
},
|
3953
|
+
get discriminatorMap() {
|
3954
|
+
const propValues = {};
|
3955
|
+
for (const key in removeGetters(shape)) {
|
3956
|
+
if (isAnyCoValueSchema2(shape[key])) {
|
3957
|
+
continue;
|
3958
|
+
}
|
3959
|
+
const field = shape[key]._zod;
|
3960
|
+
if (field.values) {
|
3961
|
+
propValues[key] ??= /* @__PURE__ */ new Set();
|
3962
|
+
for (const v of field.values) propValues[key].add(v);
|
3963
|
+
}
|
3964
|
+
}
|
3965
|
+
return propValues;
|
3966
|
+
}
|
3967
|
+
})
|
3968
|
+
};
|
3969
|
+
}
|
3970
|
+
function enrichCoMapSchema(schema, coValueClass) {
|
3971
|
+
const coValueSchema = Object.assign(schema, {
|
3972
|
+
create: (...args) => {
|
3973
|
+
return coValueClass.create(...args);
|
3974
|
+
},
|
3975
|
+
load: (...args) => {
|
3976
|
+
return coValueClass.load(...args);
|
3977
|
+
},
|
3978
|
+
subscribe: (...args) => {
|
3979
|
+
return coValueClass.subscribe(...args);
|
3980
|
+
},
|
3981
|
+
findUnique: (...args) => {
|
3982
|
+
return coValueClass.findUnique(...args);
|
3983
|
+
},
|
3984
|
+
upsertUnique: (...args) => {
|
3985
|
+
return coValueClass.upsertUnique(...args);
|
3986
|
+
},
|
3987
|
+
loadUnique: (...args) => {
|
3988
|
+
return coValueClass.loadUnique(...args);
|
3989
|
+
},
|
3990
|
+
catchall: (catchAll) => {
|
3991
|
+
const schemaWithCatchAll = createCoreCoMapSchema(
|
3992
|
+
coValueSchema.getDefinition().shape,
|
3993
|
+
catchAll
|
3994
|
+
);
|
3995
|
+
return hydrateCoreCoValueSchema(schemaWithCatchAll);
|
3996
|
+
},
|
3997
|
+
withMigration: (migration) => {
|
3998
|
+
coValueClass.prototype.migrate = migration;
|
3999
|
+
return coValueSchema;
|
4000
|
+
},
|
4001
|
+
getCoValueClass: () => {
|
4002
|
+
return coValueClass;
|
4003
|
+
},
|
4004
|
+
optional: () => {
|
4005
|
+
return coOptionalDefiner(coValueSchema);
|
4006
|
+
}
|
4007
|
+
});
|
4008
|
+
return coValueSchema;
|
4009
|
+
}
|
4010
|
+
|
4011
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts
|
4012
|
+
var CoListSchema = class {
|
4013
|
+
constructor(element, coValueClass) {
|
4014
|
+
this.element = element;
|
4015
|
+
this.coValueClass = coValueClass;
|
4016
|
+
this.collaborative = true;
|
4017
|
+
this.builtin = "CoList";
|
4018
|
+
}
|
4019
|
+
create(items, options) {
|
4020
|
+
return this.coValueClass.create(items, options);
|
4021
|
+
}
|
4022
|
+
load(id, options) {
|
4023
|
+
return this.coValueClass.load(id, options);
|
4024
|
+
}
|
4025
|
+
subscribe(id, options, listener) {
|
4026
|
+
return this.coValueClass.subscribe(id, options, listener);
|
4027
|
+
}
|
4028
|
+
getCoValueClass() {
|
4029
|
+
return this.coValueClass;
|
4030
|
+
}
|
4031
|
+
optional() {
|
4032
|
+
return coOptionalDefiner(this);
|
4033
|
+
}
|
4034
|
+
};
|
4035
|
+
function createCoreCoListSchema(element) {
|
4036
|
+
return {
|
4037
|
+
collaborative: true,
|
4038
|
+
builtin: "CoList",
|
4039
|
+
element
|
4040
|
+
};
|
3721
4041
|
}
|
3722
|
-
|
3723
|
-
|
4042
|
+
|
4043
|
+
// src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts
|
4044
|
+
var CoFeedSchema = class {
|
4045
|
+
constructor(element, coValueClass) {
|
4046
|
+
this.element = element;
|
4047
|
+
this.coValueClass = coValueClass;
|
4048
|
+
this.collaborative = true;
|
4049
|
+
this.builtin = "CoFeed";
|
4050
|
+
}
|
4051
|
+
create(init, options) {
|
4052
|
+
return this.coValueClass.create(init, options);
|
4053
|
+
}
|
4054
|
+
load(id, options) {
|
4055
|
+
return this.coValueClass.load(id, options);
|
4056
|
+
}
|
4057
|
+
subscribe(...args) {
|
4058
|
+
return this.coValueClass.subscribe(...args);
|
4059
|
+
}
|
4060
|
+
getCoValueClass() {
|
4061
|
+
return this.coValueClass;
|
4062
|
+
}
|
4063
|
+
optional() {
|
4064
|
+
return coOptionalDefiner(this);
|
4065
|
+
}
|
4066
|
+
};
|
4067
|
+
function createCoreCoFeedSchema(element) {
|
4068
|
+
return {
|
4069
|
+
collaborative: true,
|
4070
|
+
builtin: "CoFeed",
|
4071
|
+
element
|
4072
|
+
};
|
3724
4073
|
}
|
3725
|
-
|
3726
|
-
|
4074
|
+
|
4075
|
+
// src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts
|
4076
|
+
function createCoreCoPlainTextSchema() {
|
4077
|
+
return {
|
4078
|
+
collaborative: true,
|
4079
|
+
builtin: "CoPlainText"
|
4080
|
+
};
|
3727
4081
|
}
|
3728
|
-
|
3729
|
-
|
4082
|
+
var PlainTextSchema = class {
|
4083
|
+
constructor(coValueClass) {
|
4084
|
+
this.coValueClass = coValueClass;
|
4085
|
+
this.collaborative = true;
|
4086
|
+
this.builtin = "CoPlainText";
|
4087
|
+
}
|
4088
|
+
create(text, options) {
|
4089
|
+
return this.coValueClass.create(text, options);
|
4090
|
+
}
|
4091
|
+
load(id, options) {
|
4092
|
+
return this.coValueClass.load(id, options);
|
4093
|
+
}
|
4094
|
+
subscribe(...args) {
|
4095
|
+
return this.coValueClass.subscribe(...args);
|
4096
|
+
}
|
4097
|
+
fromRaw(raw) {
|
4098
|
+
return this.coValueClass.fromRaw(raw);
|
4099
|
+
}
|
4100
|
+
getCoValueClass() {
|
4101
|
+
return this.coValueClass;
|
4102
|
+
}
|
4103
|
+
optional() {
|
4104
|
+
return coOptionalDefiner(this);
|
4105
|
+
}
|
4106
|
+
};
|
4107
|
+
|
4108
|
+
// src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts
|
4109
|
+
function createCoreFileStreamSchema() {
|
4110
|
+
return {
|
4111
|
+
collaborative: true,
|
4112
|
+
builtin: "FileStream"
|
4113
|
+
};
|
3730
4114
|
}
|
4115
|
+
var FileStreamSchema = class {
|
4116
|
+
constructor(coValueClass) {
|
4117
|
+
this.coValueClass = coValueClass;
|
4118
|
+
this.collaborative = true;
|
4119
|
+
this.builtin = "FileStream";
|
4120
|
+
}
|
4121
|
+
create(options) {
|
4122
|
+
return this.coValueClass.create(options);
|
4123
|
+
}
|
4124
|
+
createFromBlob(blob, options) {
|
4125
|
+
return this.coValueClass.createFromBlob(blob, options);
|
4126
|
+
}
|
4127
|
+
loadAsBlob(id, options) {
|
4128
|
+
return this.coValueClass.loadAsBlob(id, options);
|
4129
|
+
}
|
4130
|
+
load(id, options) {
|
4131
|
+
return this.coValueClass.load(id, options);
|
4132
|
+
}
|
4133
|
+
subscribe(...args) {
|
4134
|
+
return this.coValueClass.subscribe(...args);
|
4135
|
+
}
|
4136
|
+
getCoValueClass() {
|
4137
|
+
return this.coValueClass;
|
4138
|
+
}
|
4139
|
+
optional() {
|
4140
|
+
return coOptionalDefiner(this);
|
4141
|
+
}
|
4142
|
+
};
|
3731
4143
|
|
3732
|
-
// src/tools/implementation/zodSchema/schemaTypes/
|
3733
|
-
function
|
3734
|
-
return
|
4144
|
+
// src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
|
4145
|
+
function createCoreAccountSchema(shape) {
|
4146
|
+
return {
|
4147
|
+
...createCoreCoMapSchema(shape),
|
4148
|
+
builtin: "Account"
|
4149
|
+
};
|
4150
|
+
}
|
4151
|
+
function enrichAccountSchema(schema, coValueClass) {
|
4152
|
+
const enrichedSchema = Object.assign(schema, {
|
3735
4153
|
create: (...args) => {
|
3736
4154
|
return coValueClass.create(...args);
|
3737
4155
|
},
|
4156
|
+
createAs: (...args) => {
|
4157
|
+
return coValueClass.createAs(...args);
|
4158
|
+
},
|
4159
|
+
getMe: (...args) => {
|
4160
|
+
return coValueClass.getMe(...args);
|
4161
|
+
},
|
3738
4162
|
load: (...args) => {
|
3739
4163
|
return coValueClass.load(...args);
|
3740
4164
|
},
|
3741
4165
|
subscribe: (...args) => {
|
3742
4166
|
return coValueClass.subscribe(...args);
|
3743
4167
|
},
|
4168
|
+
fromRaw: (...args) => {
|
4169
|
+
return coValueClass.fromRaw(...args);
|
4170
|
+
},
|
4171
|
+
withMigration: (migration) => {
|
4172
|
+
coValueClass.prototype.migrate = async function(creationProps) {
|
4173
|
+
await migration(this, creationProps);
|
4174
|
+
};
|
4175
|
+
return enrichedSchema;
|
4176
|
+
},
|
3744
4177
|
getCoValueClass: () => {
|
3745
4178
|
return coValueClass;
|
3746
4179
|
}
|
3747
4180
|
});
|
4181
|
+
return enrichedSchema;
|
3748
4182
|
}
|
3749
4183
|
|
3750
4184
|
// src/tools/implementation/zodSchema/unionUtils.ts
|
3751
4185
|
import { RawCoList } from "cojson";
|
3752
4186
|
function schemaUnionDiscriminatorFor(schema) {
|
3753
4187
|
if (isUnionOfCoMapsDeeply(schema)) {
|
3754
|
-
|
3755
|
-
|
3756
|
-
|
3757
|
-
);
|
3758
|
-
}
|
3759
|
-
const discriminator = schema._zod.def.discriminator;
|
3760
|
-
const field = schema._zod.disc.get(discriminator);
|
4188
|
+
const definition = schema.getDefinition();
|
4189
|
+
const { discriminatorMap, discriminator, options } = definition;
|
4190
|
+
const field = discriminatorMap[discriminator];
|
3761
4191
|
if (!field) {
|
3762
4192
|
throw new Error(
|
3763
4193
|
"co.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
|
3764
4194
|
);
|
3765
4195
|
}
|
3766
|
-
for (const value of field
|
4196
|
+
for (const value of field) {
|
3767
4197
|
if (typeof value !== "string" && typeof value !== "number") {
|
3768
4198
|
throw new Error(
|
3769
4199
|
"co.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported"
|
@@ -3771,13 +4201,13 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
3771
4201
|
}
|
3772
4202
|
}
|
3773
4203
|
const availableOptions = [];
|
3774
|
-
for (const option of
|
3775
|
-
if (option.
|
4204
|
+
for (const option of options) {
|
4205
|
+
if (option.builtin === "CoMap") {
|
3776
4206
|
availableOptions.push(option);
|
3777
|
-
} else if (option.
|
3778
|
-
for (const subOption of option.
|
3779
|
-
if (subOption
|
3780
|
-
|
4207
|
+
} else if (option.builtin === "CoDiscriminatedUnion") {
|
4208
|
+
for (const subOption of option.getDefinition().options) {
|
4209
|
+
if (!options.includes(subOption)) {
|
4210
|
+
options.push(subOption);
|
3781
4211
|
}
|
3782
4212
|
}
|
3783
4213
|
} else {
|
@@ -3794,8 +4224,8 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
3794
4224
|
}
|
3795
4225
|
for (const option of availableOptions) {
|
3796
4226
|
let match = true;
|
3797
|
-
for (const key of
|
3798
|
-
const discriminatorDef = option.
|
4227
|
+
for (const key of Object.keys(discriminatorMap)) {
|
4228
|
+
const discriminatorDef = option.getDefinition().shape[key];
|
3799
4229
|
const discriminatorValue = _raw.get(key);
|
3800
4230
|
if (discriminatorValue && typeof discriminatorValue === "object") {
|
3801
4231
|
throw new Error("Discriminator must be a primitive value");
|
@@ -3818,7 +4248,7 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
3818
4248
|
}
|
3819
4249
|
}
|
3820
4250
|
if (match) {
|
3821
|
-
const coValueSchema =
|
4251
|
+
const coValueSchema = hydrateCoreCoValueSchema(option);
|
3822
4252
|
return coValueSchema.getCoValueClass();
|
3823
4253
|
}
|
3824
4254
|
}
|
@@ -3829,22 +4259,18 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
3829
4259
|
return determineSchema;
|
3830
4260
|
} else {
|
3831
4261
|
throw new Error(
|
3832
|
-
"
|
4262
|
+
"co.discriminatedUnion() of non-collaborative types is not supported"
|
3833
4263
|
);
|
3834
4264
|
}
|
3835
4265
|
}
|
3836
4266
|
function isUnionOfCoMapsDeeply(schema) {
|
3837
|
-
|
3838
|
-
return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3839
|
-
} else {
|
3840
|
-
return false;
|
3841
|
-
}
|
4267
|
+
return schema.getDefinition().options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3842
4268
|
}
|
3843
4269
|
function isCoMapOrUnionOfCoMapsDeeply(schema) {
|
3844
|
-
if (schema
|
4270
|
+
if (schema.builtin === "CoMap") {
|
3845
4271
|
return true;
|
3846
|
-
} else if (schema
|
3847
|
-
return schema.
|
4272
|
+
} else if (schema.builtin === "CoDiscriminatedUnion") {
|
4273
|
+
return schema.getDefinition().options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3848
4274
|
} else {
|
3849
4275
|
return false;
|
3850
4276
|
}
|
@@ -3853,104 +4279,77 @@ function isUnionOfPrimitivesDeeply(schema) {
|
|
3853
4279
|
if (schema instanceof z.core.$ZodUnion) {
|
3854
4280
|
return schema._zod.def.options.every(isUnionOfPrimitivesDeeply);
|
3855
4281
|
} else {
|
3856
|
-
return !
|
4282
|
+
return !isAnyCoValueSchema2(schema);
|
3857
4283
|
}
|
3858
4284
|
}
|
3859
4285
|
|
3860
|
-
// src/tools/implementation/zodSchema/runtimeConverters/
|
3861
|
-
function schemaFieldToCoFieldDef(schema
|
4286
|
+
// src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts
|
4287
|
+
function schemaFieldToCoFieldDef(schema) {
|
3862
4288
|
if (isCoValueClass(schema)) {
|
3863
|
-
|
3864
|
-
return coField.ref(schema, { optional: true });
|
3865
|
-
} else {
|
3866
|
-
return coField.ref(schema);
|
3867
|
-
}
|
4289
|
+
return coField.ref(schema);
|
3868
4290
|
} else if (isCoValueSchema(schema)) {
|
3869
|
-
if (
|
4291
|
+
if (schema.builtin === "CoOptional") {
|
3870
4292
|
return coField.ref(schema.getCoValueClass(), {
|
3871
4293
|
optional: true
|
3872
4294
|
});
|
3873
4295
|
}
|
3874
|
-
|
3875
|
-
return coField.ref(schema.getCoValueClass(), { optional: true });
|
3876
|
-
} else {
|
3877
|
-
return coField.ref(schema.getCoValueClass());
|
3878
|
-
}
|
4296
|
+
return coField.ref(schema.getCoValueClass());
|
3879
4297
|
} else {
|
3880
4298
|
if ("_zod" in schema) {
|
3881
|
-
|
3882
|
-
|
3883
|
-
|
3884
|
-
);
|
3885
|
-
|
3886
|
-
} else if (schema._zod.def.type === "string") {
|
4299
|
+
const zodSchemaDef = schema._zod.def;
|
4300
|
+
if (zodSchemaDef.type === "optional") {
|
4301
|
+
const inner = zodSchemaDef.innerType;
|
4302
|
+
return schemaFieldToCoFieldDef(inner);
|
4303
|
+
} else if (zodSchemaDef.type === "string") {
|
3887
4304
|
return coField.string;
|
3888
|
-
} else if (
|
4305
|
+
} else if (zodSchemaDef.type === "number") {
|
3889
4306
|
return coField.number;
|
3890
|
-
} else if (
|
4307
|
+
} else if (zodSchemaDef.type === "boolean") {
|
3891
4308
|
return coField.boolean;
|
3892
|
-
} else if (
|
4309
|
+
} else if (zodSchemaDef.type === "null") {
|
3893
4310
|
return coField.null;
|
3894
|
-
} else if (
|
4311
|
+
} else if (zodSchemaDef.type === "enum") {
|
3895
4312
|
return coField.string;
|
3896
|
-
} else if (
|
4313
|
+
} else if (zodSchemaDef.type === "readonly") {
|
3897
4314
|
return schemaFieldToCoFieldDef(
|
3898
|
-
schema.def.innerType
|
3899
|
-
isOptional
|
4315
|
+
schema.def.innerType
|
3900
4316
|
);
|
3901
|
-
} else if (
|
4317
|
+
} else if (zodSchemaDef.type === "date") {
|
3902
4318
|
return coField.optional.Date;
|
3903
|
-
} else if (
|
4319
|
+
} else if (zodSchemaDef.type === "template_literal") {
|
3904
4320
|
return coField.string;
|
3905
|
-
} else if (
|
4321
|
+
} else if (zodSchemaDef.type === "lazy") {
|
3906
4322
|
return schemaFieldToCoFieldDef(
|
3907
|
-
schema.unwrap()
|
3908
|
-
isOptional
|
4323
|
+
schema.unwrap()
|
3909
4324
|
);
|
3910
|
-
} else if (
|
4325
|
+
} else if (zodSchemaDef.type === "default" || zodSchemaDef.type === "catch") {
|
3911
4326
|
console.warn(
|
3912
4327
|
"z.default()/z.catch() are not supported in collaborative schemas. They will be ignored."
|
3913
4328
|
);
|
3914
4329
|
return schemaFieldToCoFieldDef(
|
3915
|
-
schema.def.innerType
|
3916
|
-
isOptional
|
4330
|
+
schema.def.innerType
|
3917
4331
|
);
|
3918
|
-
} else if (
|
3919
|
-
if (
|
3920
|
-
(literal2) => typeof literal2 === "undefined"
|
3921
|
-
)) {
|
4332
|
+
} else if (zodSchemaDef.type === "literal") {
|
4333
|
+
if (zodSchemaDef.values.some((literal2) => typeof literal2 === "undefined")) {
|
3922
4334
|
throw new Error("z.literal() with undefined is not supported");
|
3923
4335
|
}
|
3924
|
-
if (
|
4336
|
+
if (zodSchemaDef.values.some((literal2) => literal2 === null)) {
|
3925
4337
|
throw new Error("z.literal() with null is not supported");
|
3926
4338
|
}
|
3927
|
-
if (
|
4339
|
+
if (zodSchemaDef.values.some((literal2) => typeof literal2 === "bigint")) {
|
3928
4340
|
throw new Error("z.literal() with bigint is not supported");
|
3929
4341
|
}
|
3930
4342
|
return coField.literal(
|
3931
|
-
...
|
4343
|
+
...zodSchemaDef.values
|
3932
4344
|
);
|
3933
|
-
} else if (
|
4345
|
+
} else if (zodSchemaDef.type === "object" || zodSchemaDef.type === "array" || zodSchemaDef.type === "tuple") {
|
3934
4346
|
return coField.json();
|
3935
|
-
} else if (
|
3936
|
-
if ("builtin" in schema) {
|
3937
|
-
return schemaFieldToCoFieldDef(schema.builtin, isOptional);
|
3938
|
-
} else {
|
3939
|
-
throw new Error(`Unsupported custom zod type`);
|
3940
|
-
}
|
3941
|
-
} else if (schema._zod.def.type === "union") {
|
4347
|
+
} else if (zodSchemaDef.type === "union") {
|
3942
4348
|
if (isUnionOfPrimitivesDeeply(schema)) {
|
3943
4349
|
return coField.json();
|
3944
|
-
} else if (isUnionOfCoMapsDeeply(schema)) {
|
3945
|
-
const result = schemaUnionDiscriminatorFor(schema);
|
3946
|
-
if (isOptional) {
|
3947
|
-
return coField.ref(result, { optional: true });
|
3948
|
-
} else {
|
3949
|
-
return coField.ref(result);
|
3950
|
-
}
|
3951
4350
|
} else {
|
3952
4351
|
throw new Error(
|
3953
|
-
"z.union()/z.discriminatedUnion() of
|
4352
|
+
"z.union()/z.discriminatedUnion() of collaborative types is not supported. Use co.discriminatedUnion() instead."
|
3954
4353
|
);
|
3955
4354
|
}
|
3956
4355
|
} else {
|
@@ -3964,455 +4363,94 @@ function schemaFieldToCoFieldDef(schema, isOptional = false) {
|
|
3964
4363
|
}
|
3965
4364
|
}
|
3966
4365
|
|
3967
|
-
// src/tools/implementation/zodSchema/runtimeConverters/
|
3968
|
-
|
3969
|
-
function isAnyCoValueSchema(schema) {
|
4366
|
+
// src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts
|
4367
|
+
function isAnyCoValueSchema2(schema) {
|
3970
4368
|
return "collaborative" in schema && schema.collaborative === true;
|
3971
4369
|
}
|
3972
4370
|
function isCoValueSchema(schema) {
|
3973
|
-
return
|
4371
|
+
return isAnyCoValueSchema2(schema) && "getCoValueClass" in schema;
|
3974
4372
|
}
|
3975
|
-
function
|
3976
|
-
if (
|
3977
|
-
|
3978
|
-
|
3979
|
-
|
3980
|
-
|
3981
|
-
|
3982
|
-
|
3983
|
-
|
3984
|
-
|
3985
|
-
|
3986
|
-
|
3987
|
-
|
3988
|
-
|
3989
|
-
|
3990
|
-
|
3991
|
-
|
3992
|
-
)) {
|
3993
|
-
this[field] = schemaFieldToCoFieldDef(
|
3994
|
-
zodSchemaToCoSchemaOrKeepPrimitive(fieldType)
|
3995
|
-
);
|
3996
|
-
}
|
3997
|
-
if (def.catchall) {
|
3998
|
-
this[coField.items] = schemaFieldToCoFieldDef(
|
3999
|
-
zodSchemaToCoSchemaOrKeepPrimitive(def.catchall)
|
4000
|
-
);
|
4001
|
-
}
|
4002
|
-
}
|
4003
|
-
};
|
4004
|
-
const coValueSchema = ClassToExtend === Account ? enrichAccountSchema(schema, coValueClass) : enrichCoMapSchema(schema, coValueClass);
|
4005
|
-
coSchemasForZodSchemas.set(schema, coValueSchema);
|
4006
|
-
return coValueSchema;
|
4007
|
-
} else if (isZodArray(schema)) {
|
4008
|
-
const def = getDef(schema);
|
4009
|
-
const coValueClass = class ZCoList extends CoList {
|
4010
|
-
constructor(options) {
|
4011
|
-
super(options);
|
4012
|
-
this[coField.items] = schemaFieldToCoFieldDef(
|
4013
|
-
zodSchemaToCoSchemaOrKeepPrimitive(def.element)
|
4373
|
+
function hydrateCoreCoValueSchema(schema) {
|
4374
|
+
if (isCoValueSchema(schema)) {
|
4375
|
+
return schema;
|
4376
|
+
}
|
4377
|
+
if (schema.builtin === "CoOptional") {
|
4378
|
+
throw new Error(
|
4379
|
+
`co.optional() of collaborative types is not supported as top-level schema: ${JSON.stringify(schema)}`
|
4380
|
+
);
|
4381
|
+
} else if (schema.builtin === "CoMap" || schema.builtin === "Account") {
|
4382
|
+
const def = schema.getDefinition();
|
4383
|
+
const ClassToExtend = schema.builtin === "Account" ? Account : CoMap;
|
4384
|
+
const coValueClass = class ZCoMap extends ClassToExtend {
|
4385
|
+
constructor(options) {
|
4386
|
+
super(options);
|
4387
|
+
for (const [fieldName, fieldType] of Object.entries(def.shape)) {
|
4388
|
+
this[fieldName] = schemaFieldToCoFieldDef(
|
4389
|
+
fieldType
|
4014
4390
|
);
|
4015
4391
|
}
|
4016
|
-
|
4017
|
-
|
4018
|
-
|
4019
|
-
return coValueSchema;
|
4020
|
-
} else if (isZodCustom(schema)) {
|
4021
|
-
if ("builtin" in schema) {
|
4022
|
-
if (schema.builtin === "CoFeed" && "element" in schema) {
|
4023
|
-
const coValueClass = CoFeed.Of(
|
4024
|
-
schemaFieldToCoFieldDef(
|
4025
|
-
zodSchemaToCoSchemaOrKeepPrimitive(
|
4026
|
-
schema.element
|
4027
|
-
)
|
4028
|
-
)
|
4392
|
+
if (def.catchall) {
|
4393
|
+
this[coField.items] = schemaFieldToCoFieldDef(
|
4394
|
+
def.catchall
|
4029
4395
|
);
|
4030
|
-
const coValueSchema = enrichCoFeedSchema(schema, coValueClass);
|
4031
|
-
return coValueSchema;
|
4032
|
-
} else if (schema.builtin === "FileStream") {
|
4033
|
-
const coValueClass = FileStream;
|
4034
|
-
const coValueSchema = enrichFileStreamSchema(schema, coValueClass);
|
4035
|
-
return coValueSchema;
|
4036
|
-
} else if (schema.builtin === "CoPlainText") {
|
4037
|
-
const coValueClass = CoPlainText;
|
4038
|
-
const coValueSchema = enrichPlainTextSchema(schema, coValueClass);
|
4039
|
-
return coValueSchema;
|
4040
|
-
} else if (schema.builtin === "CoRichText") {
|
4041
|
-
const coValueClass = CoRichText;
|
4042
|
-
const coValueSchema = enrichRichTextSchema(schema, coValueClass);
|
4043
|
-
return coValueSchema;
|
4044
|
-
} else {
|
4045
|
-
throw new Error(`Unsupported builtin type: ${schema.builtin}`);
|
4046
4396
|
}
|
4047
|
-
} else {
|
4048
|
-
throw new Error(`Unsupported custom zod type`);
|
4049
4397
|
}
|
4050
|
-
}
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4054
|
-
|
4055
|
-
|
4056
|
-
|
4057
|
-
|
4058
|
-
|
4059
|
-
|
4060
|
-
|
4061
|
-
|
4062
|
-
|
4063
|
-
|
4064
|
-
|
4065
|
-
|
4066
|
-
|
4067
|
-
|
4398
|
+
};
|
4399
|
+
const coValueSchema = ClassToExtend === Account ? enrichAccountSchema(schema, coValueClass) : enrichCoMapSchema(schema, coValueClass);
|
4400
|
+
return coValueSchema;
|
4401
|
+
} else if (schema.builtin === "CoList") {
|
4402
|
+
const element = schema.element;
|
4403
|
+
const coValueClass = class ZCoList extends CoList {
|
4404
|
+
constructor(options) {
|
4405
|
+
super(options);
|
4406
|
+
this[coField.items] = schemaFieldToCoFieldDef(
|
4407
|
+
element
|
4408
|
+
);
|
4409
|
+
}
|
4410
|
+
};
|
4411
|
+
const coValueSchema = new CoListSchema(element, coValueClass);
|
4412
|
+
return coValueSchema;
|
4413
|
+
} else if (schema.builtin === "CoFeed") {
|
4414
|
+
const coValueClass = CoFeed.Of(
|
4415
|
+
schemaFieldToCoFieldDef(schema.element)
|
4416
|
+
);
|
4417
|
+
const coValueSchema = new CoFeedSchema(schema.element, coValueClass);
|
4418
|
+
return coValueSchema;
|
4419
|
+
} else if (schema.builtin === "FileStream") {
|
4420
|
+
const coValueClass = FileStream;
|
4421
|
+
return new FileStreamSchema(coValueClass);
|
4422
|
+
} else if (schema.builtin === "CoPlainText") {
|
4423
|
+
const coValueClass = CoPlainText;
|
4424
|
+
return new PlainTextSchema(coValueClass);
|
4425
|
+
} else if (schema.builtin === "CoRichText") {
|
4426
|
+
const coValueClass = CoRichText;
|
4427
|
+
return new RichTextSchema(coValueClass);
|
4428
|
+
} else if (schema.builtin === "CoDiscriminatedUnion") {
|
4429
|
+
const coValueClass = SchemaUnion.Of(schemaUnionDiscriminatorFor(schema));
|
4430
|
+
const coValueSchema = new CoDiscriminatedUnionSchema(schema, coValueClass);
|
4431
|
+
return coValueSchema;
|
4068
4432
|
} else {
|
4069
|
-
|
4070
|
-
}
|
4071
|
-
}
|
4072
|
-
function zodSchemaToCoSchema(schema) {
|
4073
|
-
const coSchema = tryZodSchemaToCoSchema(schema);
|
4074
|
-
if (!coSchema) {
|
4433
|
+
const notReachable = schema;
|
4075
4434
|
throw new Error(
|
4076
|
-
`Unsupported zod type: ${
|
4435
|
+
`Unsupported zod CoValue type for top-level schema: ${JSON.stringify(notReachable, void 0, 2)}`
|
4077
4436
|
);
|
4078
4437
|
}
|
4079
|
-
return coSchema;
|
4080
4438
|
}
|
4081
|
-
function
|
4439
|
+
function coValueClassFromCoValueClassOrSchema(schema) {
|
4082
4440
|
if (isCoValueClass(schema)) {
|
4083
4441
|
return schema;
|
4084
4442
|
} else if (isCoValueSchema(schema)) {
|
4085
4443
|
return schema.getCoValueClass();
|
4086
|
-
} else if ("def" in schema) {
|
4087
|
-
const coSchema = tryZodSchemaToCoSchema(
|
4088
|
-
schema
|
4089
|
-
);
|
4090
|
-
if (!coSchema) {
|
4091
|
-
throw new Error(
|
4092
|
-
`Unsupported zod type: ${schema.def?.type || JSON.stringify(schema)}`
|
4093
|
-
);
|
4094
|
-
}
|
4095
|
-
return coSchema.getCoValueClass();
|
4096
4444
|
}
|
4097
4445
|
throw new Error(`Unsupported schema: ${JSON.stringify(schema)}`);
|
4098
4446
|
}
|
4099
|
-
function zodSchemaToCoSchemaOrKeepPrimitive(schema) {
|
4100
|
-
const coSchema = tryZodSchemaToCoSchema(schema);
|
4101
|
-
if (!coSchema) {
|
4102
|
-
return schema;
|
4103
|
-
}
|
4104
|
-
return coSchema;
|
4105
|
-
}
|
4106
|
-
|
4107
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts
|
4108
|
-
function createCoOptionalSchema(schema) {
|
4109
|
-
return Object.assign(z.optional(schema), {
|
4110
|
-
collaborative: true,
|
4111
|
-
getCoValueClass: () => {
|
4112
|
-
return schema.getCoValueClass();
|
4113
|
-
}
|
4114
|
-
});
|
4115
|
-
}
|
4116
|
-
function isAnyCoOptionalSchema(schema) {
|
4117
|
-
return isAnyCoValueSchema(schema) && schema._zod.def.type === "optional";
|
4118
|
-
}
|
4119
|
-
|
4120
|
-
// src/tools/implementation/zodSchema/zodCo.ts
|
4121
|
-
var coMapDefiner = (shape) => {
|
4122
|
-
const objectSchema = z.object(shape).meta({
|
4123
|
-
collaborative: true
|
4124
|
-
});
|
4125
|
-
const enrichedSchema = Object.assign(objectSchema, {
|
4126
|
-
collaborative: true
|
4127
|
-
});
|
4128
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4129
|
-
};
|
4130
|
-
var coAccountDefiner = (shape = {
|
4131
|
-
profile: coMapDefiner({
|
4132
|
-
name: z.string(),
|
4133
|
-
inbox: z.optional(z.string()),
|
4134
|
-
inboxInvite: z.optional(z.string())
|
4135
|
-
}),
|
4136
|
-
root: coMapDefiner({})
|
4137
|
-
}) => {
|
4138
|
-
const schema = z.object(shape).meta({
|
4139
|
-
collaborative: true
|
4140
|
-
});
|
4141
|
-
const enrichedSchema = Object.assign(schema, {
|
4142
|
-
collaborative: true,
|
4143
|
-
builtin: "Account"
|
4144
|
-
});
|
4145
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4146
|
-
};
|
4147
|
-
var coRecordDefiner = (_keyType, valueType) => {
|
4148
|
-
return coMapDefiner({}).catchall(valueType);
|
4149
|
-
};
|
4150
|
-
var coListDefiner = (element) => {
|
4151
|
-
const schema = z.array(element).meta({
|
4152
|
-
collaborative: true
|
4153
|
-
});
|
4154
|
-
const enrichedSchema = Object.assign(schema, {
|
4155
|
-
collaborative: true
|
4156
|
-
});
|
4157
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4158
|
-
};
|
4159
|
-
var coProfileDefiner = (shape = {}) => {
|
4160
|
-
const ehnancedShape = Object.assign(shape, {
|
4161
|
-
name: z.string(),
|
4162
|
-
inbox: z.optional(z.string()),
|
4163
|
-
inboxInvite: z.optional(z.string())
|
4164
|
-
});
|
4165
|
-
return coMapDefiner(ehnancedShape);
|
4166
|
-
};
|
4167
|
-
var coFeedDefiner = (element) => {
|
4168
|
-
const schema = z.instanceof(CoFeed);
|
4169
|
-
const enrichedSchema = Object.assign(schema, {
|
4170
|
-
collaborative: true,
|
4171
|
-
builtin: "CoFeed",
|
4172
|
-
element
|
4173
|
-
});
|
4174
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4175
|
-
};
|
4176
|
-
var coFileStreamDefiner = () => {
|
4177
|
-
const schema = z.instanceof(FileStream);
|
4178
|
-
const enrichedSchema = Object.assign(schema, {
|
4179
|
-
collaborative: true,
|
4180
|
-
builtin: "FileStream"
|
4181
|
-
});
|
4182
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4183
|
-
};
|
4184
|
-
var coPlainTextDefiner = () => {
|
4185
|
-
const schema = z.instanceof(CoPlainText);
|
4186
|
-
const enrichedSchema = Object.assign(schema, {
|
4187
|
-
collaborative: true,
|
4188
|
-
builtin: "CoPlainText"
|
4189
|
-
});
|
4190
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4191
|
-
};
|
4192
|
-
var coRichTextDefiner = () => {
|
4193
|
-
const schema = z.instanceof(CoRichText);
|
4194
|
-
const enrichedSchema = Object.assign(schema, {
|
4195
|
-
collaborative: true,
|
4196
|
-
builtin: "CoRichText"
|
4197
|
-
});
|
4198
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4199
|
-
};
|
4200
|
-
var coImageDefiner = () => {
|
4201
|
-
return ImageDefinition;
|
4202
|
-
};
|
4203
|
-
var coOptionalDefiner = (schema) => {
|
4204
|
-
return createCoOptionalSchema(schema);
|
4205
|
-
};
|
4206
|
-
var coDiscriminatedUnionDefiner = (discriminator, schemas) => {
|
4207
|
-
const schema = z.discriminatedUnion(discriminator, schemas);
|
4208
|
-
return zodSchemaToCoSchema(schema);
|
4209
|
-
};
|
4210
|
-
|
4211
|
-
// src/tools/implementation/zodSchema/coExport.ts
|
4212
|
-
var coExport_exports = {};
|
4213
|
-
__export(coExport_exports, {
|
4214
|
-
account: () => coAccountDefiner,
|
4215
|
-
discriminatedUnion: () => coDiscriminatedUnionDefiner,
|
4216
|
-
feed: () => coFeedDefiner,
|
4217
|
-
fileStream: () => coFileStreamDefiner,
|
4218
|
-
image: () => coImageDefiner,
|
4219
|
-
list: () => coListDefiner,
|
4220
|
-
map: () => coMapDefiner,
|
4221
|
-
optional: () => coOptionalDefiner,
|
4222
|
-
plainText: () => coPlainTextDefiner,
|
4223
|
-
profile: () => coProfileDefiner,
|
4224
|
-
record: () => coRecordDefiner,
|
4225
|
-
richText: () => coRichTextDefiner
|
4226
|
-
});
|
4227
|
-
|
4228
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
|
4229
|
-
function enrichCoMapSchema(schema, coValueClass) {
|
4230
|
-
const baseCatchall = schema.catchall;
|
4231
|
-
const coValueSchema = Object.assign(schema, {
|
4232
|
-
create: (...args) => {
|
4233
|
-
return coValueClass.create(...args);
|
4234
|
-
},
|
4235
|
-
load: (...args) => {
|
4236
|
-
return coValueClass.load(...args);
|
4237
|
-
},
|
4238
|
-
subscribe: (...args) => {
|
4239
|
-
return coValueClass.subscribe(...args);
|
4240
|
-
},
|
4241
|
-
findUnique: (...args) => {
|
4242
|
-
return coValueClass.findUnique(...args);
|
4243
|
-
},
|
4244
|
-
upsertUnique: (...args) => {
|
4245
|
-
return coValueClass.upsertUnique(...args);
|
4246
|
-
},
|
4247
|
-
loadUnique: (...args) => {
|
4248
|
-
return coValueClass.loadUnique(...args);
|
4249
|
-
},
|
4250
|
-
catchall: (index) => {
|
4251
|
-
const newSchema = baseCatchall(index);
|
4252
|
-
const enrichedSchema = Object.assign(newSchema, {
|
4253
|
-
collaborative: true
|
4254
|
-
});
|
4255
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4256
|
-
},
|
4257
|
-
withHelpers: (helpers) => {
|
4258
|
-
return Object.assign(schema, helpers(schema));
|
4259
|
-
},
|
4260
|
-
withMigration: (migration) => {
|
4261
|
-
coValueClass.prototype.migrate = migration;
|
4262
|
-
return coValueSchema;
|
4263
|
-
},
|
4264
|
-
getCoValueClass: () => {
|
4265
|
-
return coValueClass;
|
4266
|
-
}
|
4267
|
-
});
|
4268
|
-
return coValueSchema;
|
4269
|
-
}
|
4270
|
-
|
4271
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts
|
4272
|
-
function enrichCoDiscriminatedUnionSchema(schema, coValueClass) {
|
4273
|
-
return Object.assign(schema, {
|
4274
|
-
load: (...args) => {
|
4275
|
-
return coValueClass.load(...args);
|
4276
|
-
},
|
4277
|
-
subscribe: (...args) => {
|
4278
|
-
return coValueClass.subscribe(...args);
|
4279
|
-
},
|
4280
|
-
getCoValueClass: () => {
|
4281
|
-
return coValueClass;
|
4282
|
-
}
|
4283
|
-
});
|
4284
|
-
}
|
4285
|
-
|
4286
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts
|
4287
|
-
function enrichCoListSchema(schema, coValueClass) {
|
4288
|
-
return Object.assign(schema, {
|
4289
|
-
create: (...args) => {
|
4290
|
-
return coValueClass.create(...args);
|
4291
|
-
},
|
4292
|
-
load: (...args) => {
|
4293
|
-
return coValueClass.load(...args);
|
4294
|
-
},
|
4295
|
-
subscribe: (...args) => {
|
4296
|
-
return coValueClass.subscribe(...args);
|
4297
|
-
},
|
4298
|
-
withHelpers: (helpers) => {
|
4299
|
-
return Object.assign(schema, helpers(schema));
|
4300
|
-
},
|
4301
|
-
getCoValueClass: () => {
|
4302
|
-
return coValueClass;
|
4303
|
-
}
|
4304
|
-
});
|
4305
|
-
}
|
4306
|
-
|
4307
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts
|
4308
|
-
function enrichCoFeedSchema(schema, coValueClass) {
|
4309
|
-
return Object.assign(schema, {
|
4310
|
-
create: (...args) => {
|
4311
|
-
return coValueClass.create(...args);
|
4312
|
-
},
|
4313
|
-
load: (...args) => {
|
4314
|
-
return coValueClass.load(...args);
|
4315
|
-
},
|
4316
|
-
subscribe: (...args) => {
|
4317
|
-
return coValueClass.subscribe(...args);
|
4318
|
-
},
|
4319
|
-
withHelpers: (helpers) => {
|
4320
|
-
return Object.assign(schema, helpers(schema));
|
4321
|
-
},
|
4322
|
-
getCoValueClass: () => {
|
4323
|
-
return coValueClass;
|
4324
|
-
}
|
4325
|
-
});
|
4326
|
-
}
|
4327
|
-
|
4328
|
-
// src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
|
4329
|
-
function enrichAccountSchema(schema, coValueClass) {
|
4330
|
-
const enrichedSchema = Object.assign(schema, {
|
4331
|
-
create: (...args) => {
|
4332
|
-
return coValueClass.create(...args);
|
4333
|
-
},
|
4334
|
-
createAs: (...args) => {
|
4335
|
-
return coValueClass.createAs(...args);
|
4336
|
-
},
|
4337
|
-
getMe: (...args) => {
|
4338
|
-
return coValueClass.getMe(...args);
|
4339
|
-
},
|
4340
|
-
load: (...args) => {
|
4341
|
-
return coValueClass.load(...args);
|
4342
|
-
},
|
4343
|
-
subscribe: (...args) => {
|
4344
|
-
return coValueClass.subscribe(...args);
|
4345
|
-
},
|
4346
|
-
withHelpers: (helpers) => {
|
4347
|
-
return Object.assign(schema, helpers(schema));
|
4348
|
-
},
|
4349
|
-
fromRaw: (...args) => {
|
4350
|
-
return coValueClass.fromRaw(...args);
|
4351
|
-
},
|
4352
|
-
withMigration: (migration) => {
|
4353
|
-
coValueClass.prototype.migrate = async function(creationProps) {
|
4354
|
-
await migration(this, creationProps);
|
4355
|
-
};
|
4356
|
-
return enrichedSchema;
|
4357
|
-
},
|
4358
|
-
getCoValueClass: () => {
|
4359
|
-
return coValueClass;
|
4360
|
-
}
|
4361
|
-
});
|
4362
|
-
return enrichedSchema;
|
4363
|
-
}
|
4364
|
-
|
4365
|
-
// src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts
|
4366
|
-
function enrichFileStreamSchema(schema, coValueClass) {
|
4367
|
-
return Object.assign(schema, {
|
4368
|
-
create: (...args) => {
|
4369
|
-
return coValueClass.create(...args);
|
4370
|
-
},
|
4371
|
-
createFromBlob: (...args) => {
|
4372
|
-
return coValueClass.createFromBlob(...args);
|
4373
|
-
},
|
4374
|
-
load: (...args) => {
|
4375
|
-
return coValueClass.load(...args);
|
4376
|
-
},
|
4377
|
-
loadAsBlob: (...args) => {
|
4378
|
-
return coValueClass.loadAsBlob(...args);
|
4379
|
-
},
|
4380
|
-
subscribe: (...args) => {
|
4381
|
-
return coValueClass.subscribe(...args);
|
4382
|
-
},
|
4383
|
-
getCoValueClass: () => {
|
4384
|
-
return coValueClass;
|
4385
|
-
}
|
4386
|
-
});
|
4387
|
-
}
|
4388
|
-
|
4389
|
-
// src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts
|
4390
|
-
function enrichPlainTextSchema(schema, coValueClass) {
|
4391
|
-
return Object.assign(schema, {
|
4392
|
-
create: (...args) => {
|
4393
|
-
return coValueClass.create(...args);
|
4394
|
-
},
|
4395
|
-
load: (...args) => {
|
4396
|
-
return coValueClass.load(...args);
|
4397
|
-
},
|
4398
|
-
subscribe: (...args) => {
|
4399
|
-
return coValueClass.subscribe(...args);
|
4400
|
-
},
|
4401
|
-
fromRaw: (...args) => {
|
4402
|
-
return coValueClass.fromRaw(...args);
|
4403
|
-
},
|
4404
|
-
getCoValueClass: () => {
|
4405
|
-
return coValueClass;
|
4406
|
-
}
|
4407
|
-
});
|
4408
|
-
}
|
4409
4447
|
|
4410
4448
|
// src/tools/coValues/extensions/imageDef.ts
|
4411
4449
|
var ImageDefinitionBase = coMapDefiner({
|
4412
4450
|
originalSize: z.tuple([z.number(), z.number()]),
|
4413
4451
|
placeholderDataURL: z.string().optional()
|
4414
4452
|
}).catchall(coFileStreamDefiner());
|
4415
|
-
var ImageDefinition =
|
4453
|
+
var ImageDefinition = Object.assign({}, ImageDefinitionBase, {
|
4416
4454
|
highestResAvailable(imageDef, options) {
|
4417
4455
|
const resolutions = Object.keys(imageDef).filter(
|
4418
4456
|
(key) => key.match(/^\d+x\d+$/)
|
@@ -4442,7 +4480,7 @@ var ImageDefinition = ImageDefinitionBase.withHelpers((Self) => ({
|
|
4442
4480
|
stream: imageDef[highestAvailableResolution]
|
4443
4481
|
};
|
4444
4482
|
}
|
4445
|
-
})
|
4483
|
+
});
|
4446
4484
|
|
4447
4485
|
// src/tools/implementation/ContextManager.ts
|
4448
4486
|
import { cojsonInternals as cojsonInternals4 } from "cojson";
|
@@ -5013,46 +5051,6 @@ function subscribeToCoValue(cls, id, options, listener) {
|
|
5013
5051
|
}
|
5014
5052
|
return unsubscribe;
|
5015
5053
|
}
|
5016
|
-
function createCoValueObservable(initialValue = void 0) {
|
5017
|
-
let currentValue = initialValue;
|
5018
|
-
let subscriberCount = 0;
|
5019
|
-
function subscribe(cls, id, options, listener) {
|
5020
|
-
subscriberCount++;
|
5021
|
-
const unsubscribe = subscribeToCoValue(
|
5022
|
-
anySchemaToCoSchema(cls),
|
5023
|
-
id,
|
5024
|
-
{
|
5025
|
-
loadAs: options.loadAs,
|
5026
|
-
resolve: options.resolve,
|
5027
|
-
onUnavailable: () => {
|
5028
|
-
currentValue = null;
|
5029
|
-
options.onUnavailable?.();
|
5030
|
-
},
|
5031
|
-
onUnauthorized: () => {
|
5032
|
-
currentValue = null;
|
5033
|
-
options.onUnauthorized?.();
|
5034
|
-
},
|
5035
|
-
syncResolution: options.syncResolution
|
5036
|
-
},
|
5037
|
-
(value) => {
|
5038
|
-
currentValue = value;
|
5039
|
-
listener();
|
5040
|
-
}
|
5041
|
-
);
|
5042
|
-
return () => {
|
5043
|
-
unsubscribe();
|
5044
|
-
subscriberCount--;
|
5045
|
-
if (subscriberCount === 0) {
|
5046
|
-
currentValue = void 0;
|
5047
|
-
}
|
5048
|
-
};
|
5049
|
-
}
|
5050
|
-
const observable = {
|
5051
|
-
getCurrentValue: () => currentValue,
|
5052
|
-
subscribe
|
5053
|
-
};
|
5054
|
-
return observable;
|
5055
|
-
}
|
5056
5054
|
function subscribeToExistingCoValue(existing, options, listener) {
|
5057
5055
|
return subscribeToCoValue(
|
5058
5056
|
existing.constructor,
|
@@ -5073,9 +5071,9 @@ function isAccountInstance(instance) {
|
|
5073
5071
|
return "_type" in instance && instance._type === "Account";
|
5074
5072
|
}
|
5075
5073
|
function parseCoValueCreateOptions(options) {
|
5076
|
-
const
|
5074
|
+
const Group9 = RegisteredSchemas["Group"];
|
5077
5075
|
if (!options) {
|
5078
|
-
return { owner:
|
5076
|
+
return { owner: Group9.create(), uniqueness: void 0 };
|
5079
5077
|
}
|
5080
5078
|
if ("_type" in options) {
|
5081
5079
|
if (options._type === "Account" || options._type === "Group") {
|
@@ -5084,7 +5082,7 @@ function parseCoValueCreateOptions(options) {
|
|
5084
5082
|
}
|
5085
5083
|
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
5086
5084
|
return {
|
5087
|
-
owner: options.owner ??
|
5085
|
+
owner: options.owner ?? Group9.create(),
|
5088
5086
|
uniqueness
|
5089
5087
|
};
|
5090
5088
|
}
|
@@ -5103,7 +5101,7 @@ async function exportCoValue(cls, id, options) {
|
|
5103
5101
|
resolve,
|
5104
5102
|
id,
|
5105
5103
|
{
|
5106
|
-
ref:
|
5104
|
+
ref: coValueClassFromCoValueClassOrSchema(cls),
|
5107
5105
|
optional: false
|
5108
5106
|
},
|
5109
5107
|
options.skipRetry,
|
@@ -5172,7 +5170,6 @@ export {
|
|
5172
5170
|
zodReExport_exports,
|
5173
5171
|
loadCoValue,
|
5174
5172
|
subscribeToCoValue,
|
5175
|
-
createCoValueObservable,
|
5176
5173
|
exportCoValue,
|
5177
5174
|
importContentPieces,
|
5178
5175
|
CoValueBase,
|
@@ -5200,10 +5197,9 @@ export {
|
|
5200
5197
|
createJazzContextForNewAccount,
|
5201
5198
|
createJazzContext,
|
5202
5199
|
createAnonymousJazzContext,
|
5203
|
-
zodSchemaToCoSchema,
|
5204
|
-
anySchemaToCoSchema,
|
5205
5200
|
coMapDefiner,
|
5206
5201
|
coExport_exports,
|
5202
|
+
coValueClassFromCoValueClassOrSchema,
|
5207
5203
|
ImageDefinition,
|
5208
5204
|
KvStoreContext,
|
5209
5205
|
AuthSecretStorage,
|
@@ -5211,4 +5207,4 @@ export {
|
|
5211
5207
|
JazzContextManager
|
5212
5208
|
};
|
5213
5209
|
/* istanbul ignore file -- @preserve */
|
5214
|
-
//# sourceMappingURL=chunk-
|
5210
|
+
//# sourceMappingURL=chunk-MLCNE3TL.js.map
|