jazz-tools 0.15.15 → 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 -50
- package/CHANGELOG.md +35 -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-4CFNXQE7.js → chunk-MLCNE3TL.js} +791 -698
- package/dist/chunk-MLCNE3TL.js.map +1 -0
- package/dist/index.js +363 -11
- 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 +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/testing.js +3 -1
- package/dist/react/testing.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/group.d.ts +1 -0
- package/dist/tools/coValues/group.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 +58 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts +82 -0
- package/dist/tools/coValues/request.d.ts.map +1 -0
- 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 +4 -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/id.d.ts +2 -0
- package/dist/tools/lib/id.d.ts.map +1 -0
- package/dist/tools/lib/utilityTypes.d.ts +10 -0
- package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
- package/dist/tools/subscribe/SubscriptionScope.d.ts +3 -2
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- 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/tools/tests/exportImport.test.d.ts +2 -0
- package/dist/tools/tests/exportImport.test.d.ts.map +1 -0
- package/dist/tools/tests/request.test.d.ts +2 -0
- package/dist/tools/tests/request.test.d.ts.map +1 -0
- 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 +7 -6
- 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/group.ts +1 -0
- package/src/tools/coValues/inbox.ts +8 -7
- package/src/tools/coValues/interfaces.ts +177 -69
- package/src/tools/coValues/request.ts +633 -0
- package/src/tools/coValues/schemaUnion.ts +8 -4
- package/src/tools/exports.ts +11 -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/id.ts +3 -0
- package/src/tools/lib/utilityTypes.ts +7 -0
- package/src/tools/subscribe/SubscriptionScope.ts +10 -1
- 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 +526 -0
- 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/request.test.ts +951 -0
- 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/tsup.config.ts +0 -2
- package/dist/chunk-4CFNXQE7.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,22 +84,45 @@ 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
|
|
121
|
+
// src/tools/coValues/interfaces.ts
|
122
|
+
import {
|
123
|
+
emptyKnownState
|
124
|
+
} from "cojson";
|
125
|
+
|
91
126
|
// src/tools/coValues/CoValueBase.ts
|
92
127
|
import { ControlledAccount, RawAccount } from "cojson";
|
93
128
|
var CoValueBase = class {
|
@@ -104,9 +139,9 @@ var CoValueBase = class {
|
|
104
139
|
if (agent instanceof ControlledAccount) {
|
105
140
|
return coValuesCache.get(
|
106
141
|
agent.account,
|
107
|
-
() =>
|
108
|
-
|
109
|
-
)
|
142
|
+
() => coValueClassFromCoValueClassOrSchema(
|
143
|
+
RegisteredSchemas["Account"]
|
144
|
+
).fromRaw(agent.account)
|
110
145
|
);
|
111
146
|
}
|
112
147
|
return new AnonymousJazzAgent(this._raw.core.node);
|
@@ -718,9 +753,9 @@ var _CoList = class _CoList extends Array {
|
|
718
753
|
}
|
719
754
|
/** @category Collaboration */
|
720
755
|
get _owner() {
|
721
|
-
return this._raw.group instanceof RawAccount2 ?
|
722
|
-
|
723
|
-
) : 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);
|
724
759
|
}
|
725
760
|
/**
|
726
761
|
* If a `CoList`'s items are a `coField.ref(...)`, you can use `coList._refs[i]` to access
|
@@ -756,9 +791,9 @@ var _CoList = class _CoList extends Array {
|
|
756
791
|
if (agent instanceof ControlledAccount2) {
|
757
792
|
return coValuesCache.get(
|
758
793
|
agent.account,
|
759
|
-
() =>
|
760
|
-
|
761
|
-
)
|
794
|
+
() => coValueClassFromCoValueClassOrSchema(
|
795
|
+
RegisteredSchemas["Account"]
|
796
|
+
).fromRaw(agent.account)
|
762
797
|
);
|
763
798
|
}
|
764
799
|
return new AnonymousJazzAgent(this._raw.core.node);
|
@@ -1771,9 +1806,13 @@ var _Account = class _Account extends CoValueBase {
|
|
1771
1806
|
valueID,
|
1772
1807
|
inviteSecret
|
1773
1808
|
);
|
1774
|
-
return loadCoValue(
|
1775
|
-
|
1776
|
-
|
1809
|
+
return loadCoValue(
|
1810
|
+
coValueClassFromCoValueClassOrSchema(coValueClass),
|
1811
|
+
valueID,
|
1812
|
+
{
|
1813
|
+
loadAs: this
|
1814
|
+
}
|
1815
|
+
);
|
1777
1816
|
}
|
1778
1817
|
/** @private */
|
1779
1818
|
static async create(options) {
|
@@ -1921,7 +1960,11 @@ var AccountAndGroupProxyHandler = {
|
|
1921
1960
|
return true;
|
1922
1961
|
} else if (key === "root") {
|
1923
1962
|
if (value) {
|
1924
|
-
target._raw.set(
|
1963
|
+
target._raw.set(
|
1964
|
+
"root",
|
1965
|
+
value.id,
|
1966
|
+
"trusting"
|
1967
|
+
);
|
1925
1968
|
}
|
1926
1969
|
return true;
|
1927
1970
|
} else {
|
@@ -2179,6 +2222,13 @@ var Profile = class extends CoMap {
|
|
2179
2222
|
|
2180
2223
|
// src/tools/coValues/inbox.ts
|
2181
2224
|
import { RawAccount as RawAccount4 } from "cojson";
|
2225
|
+
|
2226
|
+
// src/tools/lib/id.ts
|
2227
|
+
function isCoValueId(id) {
|
2228
|
+
return typeof id === "string" && id.startsWith("co_z");
|
2229
|
+
}
|
2230
|
+
|
2231
|
+
// src/tools/coValues/inbox.ts
|
2182
2232
|
function createInboxRoot(account) {
|
2183
2233
|
if (!account.isLocalNodeOwner) {
|
2184
2234
|
throw new Error("Account is not controlled");
|
@@ -2261,7 +2311,7 @@ var Inbox = class _Inbox {
|
|
2261
2311
|
);
|
2262
2312
|
}
|
2263
2313
|
return loadCoValue(
|
2264
|
-
|
2314
|
+
coValueClassFromCoValueClassOrSchema(Schema),
|
2265
2315
|
message.get("payload"),
|
2266
2316
|
{
|
2267
2317
|
loadAs: account
|
@@ -2403,7 +2453,7 @@ async function acceptInvite(invite, account) {
|
|
2403
2453
|
account ||= activeAccountContext.get();
|
2404
2454
|
const id = invite.slice(0, invite.indexOf("/"));
|
2405
2455
|
const inviteSecret = invite.slice(invite.indexOf("/") + 1);
|
2406
|
-
if (!id
|
2456
|
+
if (!isCoValueId(id) || !inviteSecret.startsWith("inviteSecret_")) {
|
2407
2457
|
throw new Error("Invalid inbox ticket");
|
2408
2458
|
}
|
2409
2459
|
if (!account.isLocalNodeOwner) {
|
@@ -2415,7 +2465,7 @@ async function acceptInvite(invite, account) {
|
|
2415
2465
|
function getAccountIDfromSessionID(sessionID) {
|
2416
2466
|
const until = sessionID.indexOf("_session");
|
2417
2467
|
const accountID = sessionID.slice(0, until);
|
2418
|
-
if (accountID
|
2468
|
+
if (isCoValueId(accountID)) {
|
2419
2469
|
return accountID;
|
2420
2470
|
}
|
2421
2471
|
return;
|
@@ -2453,9 +2503,9 @@ var CoPlainText = class extends String {
|
|
2453
2503
|
if (agent instanceof ControlledAccount4) {
|
2454
2504
|
return coValuesCache.get(
|
2455
2505
|
agent.account,
|
2456
|
-
() =>
|
2457
|
-
|
2458
|
-
)
|
2506
|
+
() => coValueClassFromCoValueClassOrSchema(
|
2507
|
+
RegisteredSchemas["Account"]
|
2508
|
+
).fromRaw(agent.account)
|
2459
2509
|
);
|
2460
2510
|
}
|
2461
2511
|
return new AnonymousJazzAgent(this._raw.core.node);
|
@@ -3007,7 +3057,9 @@ function getOwnerFromRawValue(raw) {
|
|
3007
3057
|
const owner = raw.group;
|
3008
3058
|
return coValuesCache.get(
|
3009
3059
|
owner,
|
3010
|
-
() => owner instanceof RawAccount6 ?
|
3060
|
+
() => owner instanceof RawAccount6 ? coValueClassFromCoValueClassOrSchema(
|
3061
|
+
RegisteredSchemas["Account"]
|
3062
|
+
).fromRaw(owner) : RegisteredSchemas["Group"].fromRaw(owner)
|
3011
3063
|
);
|
3012
3064
|
}
|
3013
3065
|
function createCoValue(ref2, raw, subscriptionScope) {
|
@@ -3027,11 +3079,12 @@ function createCoValue(ref2, raw, subscriptionScope) {
|
|
3027
3079
|
|
3028
3080
|
// src/tools/subscribe/SubscriptionScope.ts
|
3029
3081
|
var SubscriptionScope = class _SubscriptionScope {
|
3030
|
-
constructor(node, resolve, id, schema, skipRetry) {
|
3082
|
+
constructor(node, resolve, id, schema, skipRetry = false, bestEffortResolution = false) {
|
3031
3083
|
this.node = node;
|
3032
3084
|
this.id = id;
|
3033
3085
|
this.schema = schema;
|
3034
3086
|
this.skipRetry = skipRetry;
|
3087
|
+
this.bestEffortResolution = bestEffortResolution;
|
3035
3088
|
this.childNodes = /* @__PURE__ */ new Map();
|
3036
3089
|
this.childValues = /* @__PURE__ */ new Map();
|
3037
3090
|
this.childErrors = /* @__PURE__ */ new Map();
|
@@ -3162,6 +3215,9 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3162
3215
|
if (this.childErrors.size === 0 && this.validationErrors.size === 0) {
|
3163
3216
|
return void 0;
|
3164
3217
|
}
|
3218
|
+
if (this.bestEffortResolution) {
|
3219
|
+
return void 0;
|
3220
|
+
}
|
3165
3221
|
for (const [key, value] of this.childErrors.entries()) {
|
3166
3222
|
if (this.autoloaded.has(key)) {
|
3167
3223
|
continue;
|
@@ -3289,7 +3345,9 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3289
3345
|
this.node,
|
3290
3346
|
true,
|
3291
3347
|
id,
|
3292
|
-
descriptor
|
3348
|
+
descriptor,
|
3349
|
+
this.skipRetry,
|
3350
|
+
this.bestEffortResolution
|
3293
3351
|
);
|
3294
3352
|
this.childNodes.set(id, child);
|
3295
3353
|
child.setListener((value) => this.handleChildUpdate(id, value));
|
@@ -3468,7 +3526,9 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3468
3526
|
this.node,
|
3469
3527
|
resolve,
|
3470
3528
|
id,
|
3471
|
-
descriptor
|
3529
|
+
descriptor,
|
3530
|
+
this.skipRetry,
|
3531
|
+
this.bestEffortResolution
|
3472
3532
|
);
|
3473
3533
|
this.childNodes.set(id, child);
|
3474
3534
|
child.setListener((value) => this.handleChildUpdate(id, value, key));
|
@@ -3549,7 +3609,7 @@ async function createJazzContextFromExistingCredentials({
|
|
3549
3609
|
crypto
|
3550
3610
|
);
|
3551
3611
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3552
|
-
const AccountClass =
|
3612
|
+
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
3553
3613
|
const node = await LocalNode2.withLoadedAccount({
|
3554
3614
|
accountID: credentials.accountID,
|
3555
3615
|
accountSecret: credentials.secret,
|
@@ -3589,7 +3649,7 @@ async function createJazzContextForNewAccount({
|
|
3589
3649
|
storage
|
3590
3650
|
}) {
|
3591
3651
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3592
|
-
const AccountClass =
|
3652
|
+
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
3593
3653
|
const { node } = await LocalNode2.withNewlyCreatedAccount({
|
3594
3654
|
creationProps,
|
3595
3655
|
peersToLoadFrom,
|
@@ -3695,23 +3755,220 @@ function createAnonymousJazzContext({
|
|
3695
3755
|
};
|
3696
3756
|
}
|
3697
3757
|
|
3698
|
-
// src/tools/implementation/zodSchema/
|
3699
|
-
|
3700
|
-
|
3701
|
-
|
3702
|
-
|
3703
|
-
|
3704
|
-
|
3705
|
-
|
3706
|
-
|
3707
|
-
|
3708
|
-
|
3709
|
-
|
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
|
+
};
|
3710
3807
|
}
|
3711
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
|
+
|
3712
3824
|
// src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts
|
3713
|
-
function
|
3714
|
-
return
|
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, {
|
3715
3972
|
create: (...args) => {
|
3716
3973
|
return coValueClass.create(...args);
|
3717
3974
|
},
|
@@ -3721,591 +3978,176 @@ function enrichRichTextSchema(schema, coValueClass) {
|
|
3721
3978
|
subscribe: (...args) => {
|
3722
3979
|
return coValueClass.subscribe(...args);
|
3723
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
|
+
},
|
3724
4001
|
getCoValueClass: () => {
|
3725
4002
|
return coValueClass;
|
4003
|
+
},
|
4004
|
+
optional: () => {
|
4005
|
+
return coOptionalDefiner(coValueSchema);
|
3726
4006
|
}
|
3727
4007
|
});
|
4008
|
+
return coValueSchema;
|
3728
4009
|
}
|
3729
4010
|
|
3730
|
-
// src/tools/implementation/zodSchema/
|
3731
|
-
|
3732
|
-
|
3733
|
-
|
3734
|
-
|
3735
|
-
|
3736
|
-
|
3737
|
-
);
|
3738
|
-
}
|
3739
|
-
const discriminator = schema._zod.def.discriminator;
|
3740
|
-
const field = schema._zod.disc.get(discriminator);
|
3741
|
-
if (!field) {
|
3742
|
-
throw new Error(
|
3743
|
-
"co.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
|
3744
|
-
);
|
3745
|
-
}
|
3746
|
-
for (const value of field.values) {
|
3747
|
-
if (typeof value !== "string" && typeof value !== "number") {
|
3748
|
-
throw new Error(
|
3749
|
-
"co.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported"
|
3750
|
-
);
|
3751
|
-
}
|
3752
|
-
}
|
3753
|
-
const availableOptions = [];
|
3754
|
-
for (const option of schema._zod.def.options) {
|
3755
|
-
if (option._zod.def.type === "object") {
|
3756
|
-
availableOptions.push(option);
|
3757
|
-
} else if (option._zod.def.type === "union") {
|
3758
|
-
for (const subOption of option._zod.def.options) {
|
3759
|
-
if (subOption._zod.def.type === "object") {
|
3760
|
-
availableOptions.push(subOption);
|
3761
|
-
}
|
3762
|
-
}
|
3763
|
-
} else {
|
3764
|
-
throw new Error(
|
3765
|
-
"Unsupported zod type in co.discriminatedUnion() of collaborative types"
|
3766
|
-
);
|
3767
|
-
}
|
3768
|
-
}
|
3769
|
-
const determineSchema = (_raw) => {
|
3770
|
-
if (_raw instanceof RawCoList) {
|
3771
|
-
throw new Error(
|
3772
|
-
"co.discriminatedUnion() of collaborative types is not supported for CoLists"
|
3773
|
-
);
|
3774
|
-
}
|
3775
|
-
for (const option of availableOptions) {
|
3776
|
-
let match = true;
|
3777
|
-
for (const key of schema._zod.disc.keys()) {
|
3778
|
-
const discriminatorDef = option._zod.def.shape[key];
|
3779
|
-
const discriminatorValue = _raw.get(key);
|
3780
|
-
if (discriminatorValue && typeof discriminatorValue === "object") {
|
3781
|
-
throw new Error("Discriminator must be a primitive value");
|
3782
|
-
}
|
3783
|
-
if (!discriminatorDef) {
|
3784
|
-
if (key === discriminator) {
|
3785
|
-
match = false;
|
3786
|
-
break;
|
3787
|
-
} else {
|
3788
|
-
continue;
|
3789
|
-
}
|
3790
|
-
}
|
3791
|
-
if (discriminatorDef._zod.def.type !== "literal") {
|
3792
|
-
break;
|
3793
|
-
}
|
3794
|
-
const literalDef = discriminatorDef._zod.def;
|
3795
|
-
if (!Array.from(literalDef.values).includes(discriminatorValue)) {
|
3796
|
-
match = false;
|
3797
|
-
break;
|
3798
|
-
}
|
3799
|
-
}
|
3800
|
-
if (match) {
|
3801
|
-
const coValueSchema = zodSchemaToCoSchema(option);
|
3802
|
-
return coValueSchema.getCoValueClass();
|
3803
|
-
}
|
3804
|
-
}
|
3805
|
-
throw new Error(
|
3806
|
-
"co.discriminatedUnion() of collaborative types with no matching discriminator value found"
|
3807
|
-
);
|
3808
|
-
};
|
3809
|
-
return determineSchema;
|
3810
|
-
} else {
|
3811
|
-
throw new Error(
|
3812
|
-
"z.discriminatedUnion() of non-collaborative types is not supported"
|
3813
|
-
);
|
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";
|
3814
4018
|
}
|
3815
|
-
|
3816
|
-
|
3817
|
-
if (schema instanceof z.core.$ZodUnion) {
|
3818
|
-
return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3819
|
-
} else {
|
3820
|
-
return false;
|
4019
|
+
create(items, options) {
|
4020
|
+
return this.coValueClass.create(items, options);
|
3821
4021
|
}
|
3822
|
-
|
3823
|
-
|
3824
|
-
if (schema instanceof z.core.$ZodObject && isAnyCoValueSchema(schema)) {
|
3825
|
-
return true;
|
3826
|
-
} else if (schema instanceof z.core.$ZodUnion) {
|
3827
|
-
return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3828
|
-
} else {
|
3829
|
-
return false;
|
4022
|
+
load(id, options) {
|
4023
|
+
return this.coValueClass.load(id, options);
|
3830
4024
|
}
|
3831
|
-
|
3832
|
-
|
3833
|
-
|
3834
|
-
|
3835
|
-
|
3836
|
-
|
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);
|
3837
4033
|
}
|
4034
|
+
};
|
4035
|
+
function createCoreCoListSchema(element) {
|
4036
|
+
return {
|
4037
|
+
collaborative: true,
|
4038
|
+
builtin: "CoList",
|
4039
|
+
element
|
4040
|
+
};
|
3838
4041
|
}
|
3839
4042
|
|
3840
|
-
// src/tools/implementation/zodSchema/
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3844
|
-
|
3845
|
-
|
3846
|
-
|
3847
|
-
}
|
3848
|
-
} else if (isCoValueSchema(schema)) {
|
3849
|
-
if (isAnyCoOptionalSchema(schema)) {
|
3850
|
-
return coField.ref(schema.getCoValueClass(), {
|
3851
|
-
optional: true
|
3852
|
-
});
|
3853
|
-
}
|
3854
|
-
if (isOptional) {
|
3855
|
-
return coField.ref(schema.getCoValueClass(), { optional: true });
|
3856
|
-
} else {
|
3857
|
-
return coField.ref(schema.getCoValueClass());
|
3858
|
-
}
|
3859
|
-
} else {
|
3860
|
-
if ("_zod" in schema) {
|
3861
|
-
if (schema._zod.def.type === "optional") {
|
3862
|
-
const inner = zodSchemaToCoSchemaOrKeepPrimitive(
|
3863
|
-
schema._zod.def.innerType
|
3864
|
-
);
|
3865
|
-
return schemaFieldToCoFieldDef(inner, true);
|
3866
|
-
} else if (schema._zod.def.type === "string") {
|
3867
|
-
return coField.string;
|
3868
|
-
} else if (schema._zod.def.type === "number") {
|
3869
|
-
return coField.number;
|
3870
|
-
} else if (schema._zod.def.type === "boolean") {
|
3871
|
-
return coField.boolean;
|
3872
|
-
} else if (schema._zod.def.type === "null") {
|
3873
|
-
return coField.null;
|
3874
|
-
} else if (schema._zod.def.type === "enum") {
|
3875
|
-
return coField.string;
|
3876
|
-
} else if (schema._zod.def.type === "readonly") {
|
3877
|
-
return schemaFieldToCoFieldDef(
|
3878
|
-
schema.def.innerType,
|
3879
|
-
isOptional
|
3880
|
-
);
|
3881
|
-
} else if (schema._zod.def.type === "date") {
|
3882
|
-
return coField.optional.Date;
|
3883
|
-
} else if (schema._zod.def.type === "template_literal") {
|
3884
|
-
return coField.string;
|
3885
|
-
} else if (schema._zod.def.type === "lazy") {
|
3886
|
-
return schemaFieldToCoFieldDef(
|
3887
|
-
schema.unwrap(),
|
3888
|
-
isOptional
|
3889
|
-
);
|
3890
|
-
} else if (schema._zod.def.type === "default" || schema._zod.def.type === "catch") {
|
3891
|
-
console.warn(
|
3892
|
-
"z.default()/z.catch() are not supported in collaborative schemas. They will be ignored."
|
3893
|
-
);
|
3894
|
-
return schemaFieldToCoFieldDef(
|
3895
|
-
schema.def.innerType,
|
3896
|
-
isOptional
|
3897
|
-
);
|
3898
|
-
} else if (schema._zod.def.type === "literal") {
|
3899
|
-
if (schema._zod.def.values.some(
|
3900
|
-
(literal2) => typeof literal2 === "undefined"
|
3901
|
-
)) {
|
3902
|
-
throw new Error("z.literal() with undefined is not supported");
|
3903
|
-
}
|
3904
|
-
if (schema._zod.def.values.some((literal2) => literal2 === null)) {
|
3905
|
-
throw new Error("z.literal() with null is not supported");
|
3906
|
-
}
|
3907
|
-
if (schema._zod.def.values.some((literal2) => typeof literal2 === "bigint")) {
|
3908
|
-
throw new Error("z.literal() with bigint is not supported");
|
3909
|
-
}
|
3910
|
-
return coField.literal(
|
3911
|
-
...schema._zod.def.values
|
3912
|
-
);
|
3913
|
-
} else if (schema._zod.def.type === "object" || schema._zod.def.type === "array" || schema._zod.def.type === "tuple") {
|
3914
|
-
return coField.json();
|
3915
|
-
} else if (schema._zod.def.type === "custom") {
|
3916
|
-
if ("builtin" in schema) {
|
3917
|
-
return schemaFieldToCoFieldDef(schema.builtin, isOptional);
|
3918
|
-
} else {
|
3919
|
-
throw new Error(`Unsupported custom zod type`);
|
3920
|
-
}
|
3921
|
-
} else if (schema._zod.def.type === "union") {
|
3922
|
-
if (isUnionOfPrimitivesDeeply(schema)) {
|
3923
|
-
return coField.json();
|
3924
|
-
} else if (isUnionOfCoMapsDeeply(schema)) {
|
3925
|
-
const result = schemaUnionDiscriminatorFor(schema);
|
3926
|
-
if (isOptional) {
|
3927
|
-
return coField.ref(result, { optional: true });
|
3928
|
-
} else {
|
3929
|
-
return coField.ref(result);
|
3930
|
-
}
|
3931
|
-
} else {
|
3932
|
-
throw new Error(
|
3933
|
-
"z.union()/z.discriminatedUnion() of mixed collaborative and non-collaborative types is not supported"
|
3934
|
-
);
|
3935
|
-
}
|
3936
|
-
} else {
|
3937
|
-
throw new Error(
|
3938
|
-
`Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`
|
3939
|
-
);
|
3940
|
-
}
|
3941
|
-
} else {
|
3942
|
-
throw new Error(`Unsupported zod type: ${schema}`);
|
3943
|
-
}
|
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";
|
3944
4050
|
}
|
3945
|
-
|
3946
|
-
|
3947
|
-
// src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts
|
3948
|
-
var coSchemasForZodSchemas = /* @__PURE__ */ new Map();
|
3949
|
-
function isAnyCoValueSchema(schema) {
|
3950
|
-
return "collaborative" in schema && schema.collaborative === true;
|
3951
|
-
}
|
3952
|
-
function isCoValueSchema(schema) {
|
3953
|
-
return isAnyCoValueSchema(schema) && "getCoValueClass" in schema;
|
3954
|
-
}
|
3955
|
-
function tryZodSchemaToCoSchema(schema) {
|
3956
|
-
if (isAnyCoValueSchema(schema)) {
|
3957
|
-
if (coSchemasForZodSchemas.has(schema)) {
|
3958
|
-
return coSchemasForZodSchemas.get(
|
3959
|
-
schema
|
3960
|
-
);
|
3961
|
-
}
|
3962
|
-
if (isAnyCoOptionalSchema(schema)) {
|
3963
|
-
return null;
|
3964
|
-
} else if (isZodObject(schema)) {
|
3965
|
-
const def = getDef(schema);
|
3966
|
-
const ClassToExtend = "builtin" in schema && schema.builtin === "Account" ? Account : CoMap;
|
3967
|
-
const coValueClass = class ZCoMap extends ClassToExtend {
|
3968
|
-
constructor(options) {
|
3969
|
-
super(options);
|
3970
|
-
for (const [field, fieldType] of Object.entries(
|
3971
|
-
def.shape
|
3972
|
-
)) {
|
3973
|
-
this[field] = schemaFieldToCoFieldDef(
|
3974
|
-
zodSchemaToCoSchemaOrKeepPrimitive(fieldType)
|
3975
|
-
);
|
3976
|
-
}
|
3977
|
-
if (def.catchall) {
|
3978
|
-
this[coField.items] = schemaFieldToCoFieldDef(
|
3979
|
-
zodSchemaToCoSchemaOrKeepPrimitive(def.catchall)
|
3980
|
-
);
|
3981
|
-
}
|
3982
|
-
}
|
3983
|
-
};
|
3984
|
-
const coValueSchema = ClassToExtend === Account ? enrichAccountSchema(schema, coValueClass) : enrichCoMapSchema(schema, coValueClass);
|
3985
|
-
coSchemasForZodSchemas.set(schema, coValueSchema);
|
3986
|
-
return coValueSchema;
|
3987
|
-
} else if (isZodArray(schema)) {
|
3988
|
-
const def = getDef(schema);
|
3989
|
-
const coValueClass = class ZCoList extends CoList {
|
3990
|
-
constructor(options) {
|
3991
|
-
super(options);
|
3992
|
-
this[coField.items] = schemaFieldToCoFieldDef(
|
3993
|
-
zodSchemaToCoSchemaOrKeepPrimitive(def.element)
|
3994
|
-
);
|
3995
|
-
}
|
3996
|
-
};
|
3997
|
-
const coValueSchema = enrichCoListSchema(schema, coValueClass);
|
3998
|
-
coSchemasForZodSchemas.set(schema, coValueSchema);
|
3999
|
-
return coValueSchema;
|
4000
|
-
} else if (isZodCustom(schema)) {
|
4001
|
-
if ("builtin" in schema) {
|
4002
|
-
if (schema.builtin === "CoFeed" && "element" in schema) {
|
4003
|
-
const coValueClass = CoFeed.Of(
|
4004
|
-
schemaFieldToCoFieldDef(
|
4005
|
-
zodSchemaToCoSchemaOrKeepPrimitive(
|
4006
|
-
schema.element
|
4007
|
-
)
|
4008
|
-
)
|
4009
|
-
);
|
4010
|
-
const coValueSchema = enrichCoFeedSchema(schema, coValueClass);
|
4011
|
-
return coValueSchema;
|
4012
|
-
} else if (schema.builtin === "FileStream") {
|
4013
|
-
const coValueClass = FileStream;
|
4014
|
-
const coValueSchema = enrichFileStreamSchema(schema, coValueClass);
|
4015
|
-
return coValueSchema;
|
4016
|
-
} else if (schema.builtin === "CoPlainText") {
|
4017
|
-
const coValueClass = CoPlainText;
|
4018
|
-
const coValueSchema = enrichPlainTextSchema(schema, coValueClass);
|
4019
|
-
return coValueSchema;
|
4020
|
-
} else if (schema.builtin === "CoRichText") {
|
4021
|
-
const coValueClass = CoRichText;
|
4022
|
-
const coValueSchema = enrichRichTextSchema(schema, coValueClass);
|
4023
|
-
return coValueSchema;
|
4024
|
-
} else {
|
4025
|
-
throw new Error(`Unsupported builtin type: ${schema.builtin}`);
|
4026
|
-
}
|
4027
|
-
} else {
|
4028
|
-
throw new Error(`Unsupported custom zod type`);
|
4029
|
-
}
|
4030
|
-
} else {
|
4031
|
-
throw new Error(
|
4032
|
-
`Unsupported zod CoValue type for top-level schema: ${schema._zod?.def?.type || JSON.stringify(schema, void 0, 2)}`
|
4033
|
-
);
|
4034
|
-
}
|
4035
|
-
} else if (schema instanceof z.core.$ZodDiscriminatedUnion) {
|
4036
|
-
if (isUnionOfCoMapsDeeply(schema)) {
|
4037
|
-
const coValueClass = SchemaUnion.Of(schemaUnionDiscriminatorFor(schema));
|
4038
|
-
const coValueSchema = enrichCoDiscriminatedUnionSchema(
|
4039
|
-
schema,
|
4040
|
-
coValueClass
|
4041
|
-
);
|
4042
|
-
return coValueSchema;
|
4043
|
-
} else {
|
4044
|
-
throw new Error(
|
4045
|
-
"z.discriminatedUnion() of non-collaborative types is not supported as a top-level schema"
|
4046
|
-
);
|
4047
|
-
}
|
4048
|
-
} else {
|
4049
|
-
return null;
|
4051
|
+
create(init, options) {
|
4052
|
+
return this.coValueClass.create(init, options);
|
4050
4053
|
}
|
4051
|
-
|
4052
|
-
|
4053
|
-
const coSchema = tryZodSchemaToCoSchema(schema);
|
4054
|
-
if (!coSchema) {
|
4055
|
-
throw new Error(
|
4056
|
-
`Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`
|
4057
|
-
);
|
4054
|
+
load(id, options) {
|
4055
|
+
return this.coValueClass.load(id, options);
|
4058
4056
|
}
|
4059
|
-
|
4060
|
-
|
4061
|
-
function anySchemaToCoSchema(schema) {
|
4062
|
-
if (isCoValueClass(schema)) {
|
4063
|
-
return schema;
|
4064
|
-
} else if (isCoValueSchema(schema)) {
|
4065
|
-
return schema.getCoValueClass();
|
4066
|
-
} else if ("def" in schema) {
|
4067
|
-
const coSchema = tryZodSchemaToCoSchema(
|
4068
|
-
schema
|
4069
|
-
);
|
4070
|
-
if (!coSchema) {
|
4071
|
-
throw new Error(
|
4072
|
-
`Unsupported zod type: ${schema.def?.type || JSON.stringify(schema)}`
|
4073
|
-
);
|
4074
|
-
}
|
4075
|
-
return coSchema.getCoValueClass();
|
4057
|
+
subscribe(...args) {
|
4058
|
+
return this.coValueClass.subscribe(...args);
|
4076
4059
|
}
|
4077
|
-
|
4078
|
-
|
4079
|
-
|
4080
|
-
|
4081
|
-
|
4082
|
-
return schema;
|
4060
|
+
getCoValueClass() {
|
4061
|
+
return this.coValueClass;
|
4062
|
+
}
|
4063
|
+
optional() {
|
4064
|
+
return coOptionalDefiner(this);
|
4083
4065
|
}
|
4084
|
-
return coSchema;
|
4085
|
-
}
|
4086
|
-
|
4087
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts
|
4088
|
-
function createCoOptionalSchema(schema) {
|
4089
|
-
return Object.assign(z.optional(schema), {
|
4090
|
-
collaborative: true,
|
4091
|
-
getCoValueClass: () => {
|
4092
|
-
return schema.getCoValueClass();
|
4093
|
-
}
|
4094
|
-
});
|
4095
|
-
}
|
4096
|
-
function isAnyCoOptionalSchema(schema) {
|
4097
|
-
return isAnyCoValueSchema(schema) && schema._zod.def.type === "optional";
|
4098
|
-
}
|
4099
|
-
|
4100
|
-
// src/tools/implementation/zodSchema/zodCo.ts
|
4101
|
-
var coMapDefiner = (shape) => {
|
4102
|
-
const objectSchema = z.object(shape).meta({
|
4103
|
-
collaborative: true
|
4104
|
-
});
|
4105
|
-
const enrichedSchema = Object.assign(objectSchema, {
|
4106
|
-
collaborative: true
|
4107
|
-
});
|
4108
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4109
|
-
};
|
4110
|
-
var coAccountDefiner = (shape = {
|
4111
|
-
profile: coMapDefiner({
|
4112
|
-
name: z.string(),
|
4113
|
-
inbox: z.optional(z.string()),
|
4114
|
-
inboxInvite: z.optional(z.string())
|
4115
|
-
}),
|
4116
|
-
root: coMapDefiner({})
|
4117
|
-
}) => {
|
4118
|
-
const schema = z.object(shape).meta({
|
4119
|
-
collaborative: true
|
4120
|
-
});
|
4121
|
-
const enrichedSchema = Object.assign(schema, {
|
4122
|
-
collaborative: true,
|
4123
|
-
builtin: "Account"
|
4124
|
-
});
|
4125
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4126
|
-
};
|
4127
|
-
var coRecordDefiner = (_keyType, valueType) => {
|
4128
|
-
return coMapDefiner({}).catchall(valueType);
|
4129
|
-
};
|
4130
|
-
var coListDefiner = (element) => {
|
4131
|
-
const schema = z.array(element).meta({
|
4132
|
-
collaborative: true
|
4133
|
-
});
|
4134
|
-
const enrichedSchema = Object.assign(schema, {
|
4135
|
-
collaborative: true
|
4136
|
-
});
|
4137
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4138
|
-
};
|
4139
|
-
var coProfileDefiner = (shape = {}) => {
|
4140
|
-
const ehnancedShape = Object.assign(shape, {
|
4141
|
-
name: z.string(),
|
4142
|
-
inbox: z.optional(z.string()),
|
4143
|
-
inboxInvite: z.optional(z.string())
|
4144
|
-
});
|
4145
|
-
return coMapDefiner(ehnancedShape);
|
4146
4066
|
};
|
4147
|
-
|
4148
|
-
|
4149
|
-
const enrichedSchema = Object.assign(schema, {
|
4067
|
+
function createCoreCoFeedSchema(element) {
|
4068
|
+
return {
|
4150
4069
|
collaborative: true,
|
4151
4070
|
builtin: "CoFeed",
|
4152
4071
|
element
|
4153
|
-
}
|
4154
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4155
|
-
};
|
4156
|
-
var coFileStreamDefiner = () => {
|
4157
|
-
const schema = z.instanceof(FileStream);
|
4158
|
-
const enrichedSchema = Object.assign(schema, {
|
4159
|
-
collaborative: true,
|
4160
|
-
builtin: "FileStream"
|
4161
|
-
});
|
4162
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4163
|
-
};
|
4164
|
-
var coPlainTextDefiner = () => {
|
4165
|
-
const schema = z.instanceof(CoPlainText);
|
4166
|
-
const enrichedSchema = Object.assign(schema, {
|
4167
|
-
collaborative: true,
|
4168
|
-
builtin: "CoPlainText"
|
4169
|
-
});
|
4170
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4171
|
-
};
|
4172
|
-
var coRichTextDefiner = () => {
|
4173
|
-
const schema = z.instanceof(CoRichText);
|
4174
|
-
const enrichedSchema = Object.assign(schema, {
|
4175
|
-
collaborative: true,
|
4176
|
-
builtin: "CoRichText"
|
4177
|
-
});
|
4178
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4179
|
-
};
|
4180
|
-
var coImageDefiner = () => {
|
4181
|
-
return ImageDefinition;
|
4182
|
-
};
|
4183
|
-
var coOptionalDefiner = (schema) => {
|
4184
|
-
return createCoOptionalSchema(schema);
|
4185
|
-
};
|
4186
|
-
var coDiscriminatedUnionDefiner = (discriminator, schemas) => {
|
4187
|
-
const schema = z.discriminatedUnion(discriminator, schemas);
|
4188
|
-
return zodSchemaToCoSchema(schema);
|
4189
|
-
};
|
4190
|
-
|
4191
|
-
// src/tools/implementation/zodSchema/coExport.ts
|
4192
|
-
var coExport_exports = {};
|
4193
|
-
__export(coExport_exports, {
|
4194
|
-
account: () => coAccountDefiner,
|
4195
|
-
discriminatedUnion: () => coDiscriminatedUnionDefiner,
|
4196
|
-
feed: () => coFeedDefiner,
|
4197
|
-
fileStream: () => coFileStreamDefiner,
|
4198
|
-
image: () => coImageDefiner,
|
4199
|
-
list: () => coListDefiner,
|
4200
|
-
map: () => coMapDefiner,
|
4201
|
-
optional: () => coOptionalDefiner,
|
4202
|
-
plainText: () => coPlainTextDefiner,
|
4203
|
-
profile: () => coProfileDefiner,
|
4204
|
-
record: () => coRecordDefiner,
|
4205
|
-
richText: () => coRichTextDefiner
|
4206
|
-
});
|
4207
|
-
|
4208
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
|
4209
|
-
function enrichCoMapSchema(schema, coValueClass) {
|
4210
|
-
const baseCatchall = schema.catchall;
|
4211
|
-
const coValueSchema = Object.assign(schema, {
|
4212
|
-
create: (...args) => {
|
4213
|
-
return coValueClass.create(...args);
|
4214
|
-
},
|
4215
|
-
load: (...args) => {
|
4216
|
-
return coValueClass.load(...args);
|
4217
|
-
},
|
4218
|
-
subscribe: (...args) => {
|
4219
|
-
return coValueClass.subscribe(...args);
|
4220
|
-
},
|
4221
|
-
findUnique: (...args) => {
|
4222
|
-
return coValueClass.findUnique(...args);
|
4223
|
-
},
|
4224
|
-
upsertUnique: (...args) => {
|
4225
|
-
return coValueClass.upsertUnique(...args);
|
4226
|
-
},
|
4227
|
-
loadUnique: (...args) => {
|
4228
|
-
return coValueClass.loadUnique(...args);
|
4229
|
-
},
|
4230
|
-
catchall: (index) => {
|
4231
|
-
const newSchema = baseCatchall(index);
|
4232
|
-
const enrichedSchema = Object.assign(newSchema, {
|
4233
|
-
collaborative: true
|
4234
|
-
});
|
4235
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
4236
|
-
},
|
4237
|
-
withHelpers: (helpers) => {
|
4238
|
-
return Object.assign(schema, helpers(schema));
|
4239
|
-
},
|
4240
|
-
withMigration: (migration) => {
|
4241
|
-
coValueClass.prototype.migrate = migration;
|
4242
|
-
return coValueSchema;
|
4243
|
-
},
|
4244
|
-
getCoValueClass: () => {
|
4245
|
-
return coValueClass;
|
4246
|
-
}
|
4247
|
-
});
|
4248
|
-
return coValueSchema;
|
4249
|
-
}
|
4250
|
-
|
4251
|
-
// src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts
|
4252
|
-
function enrichCoDiscriminatedUnionSchema(schema, coValueClass) {
|
4253
|
-
return Object.assign(schema, {
|
4254
|
-
load: (...args) => {
|
4255
|
-
return coValueClass.load(...args);
|
4256
|
-
},
|
4257
|
-
subscribe: (...args) => {
|
4258
|
-
return coValueClass.subscribe(...args);
|
4259
|
-
},
|
4260
|
-
getCoValueClass: () => {
|
4261
|
-
return coValueClass;
|
4262
|
-
}
|
4263
|
-
});
|
4072
|
+
};
|
4264
4073
|
}
|
4265
4074
|
|
4266
|
-
// src/tools/implementation/zodSchema/schemaTypes/
|
4267
|
-
function
|
4268
|
-
return
|
4269
|
-
|
4270
|
-
|
4271
|
-
|
4272
|
-
load: (...args) => {
|
4273
|
-
return coValueClass.load(...args);
|
4274
|
-
},
|
4275
|
-
subscribe: (...args) => {
|
4276
|
-
return coValueClass.subscribe(...args);
|
4277
|
-
},
|
4278
|
-
withHelpers: (helpers) => {
|
4279
|
-
return Object.assign(schema, helpers(schema));
|
4280
|
-
},
|
4281
|
-
getCoValueClass: () => {
|
4282
|
-
return coValueClass;
|
4283
|
-
}
|
4284
|
-
});
|
4075
|
+
// src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts
|
4076
|
+
function createCoreCoPlainTextSchema() {
|
4077
|
+
return {
|
4078
|
+
collaborative: true,
|
4079
|
+
builtin: "CoPlainText"
|
4080
|
+
};
|
4285
4081
|
}
|
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
|
+
};
|
4286
4107
|
|
4287
|
-
// src/tools/implementation/zodSchema/schemaTypes/
|
4288
|
-
function
|
4289
|
-
return
|
4290
|
-
|
4291
|
-
|
4292
|
-
|
4293
|
-
load: (...args) => {
|
4294
|
-
return coValueClass.load(...args);
|
4295
|
-
},
|
4296
|
-
subscribe: (...args) => {
|
4297
|
-
return coValueClass.subscribe(...args);
|
4298
|
-
},
|
4299
|
-
withHelpers: (helpers) => {
|
4300
|
-
return Object.assign(schema, helpers(schema));
|
4301
|
-
},
|
4302
|
-
getCoValueClass: () => {
|
4303
|
-
return coValueClass;
|
4304
|
-
}
|
4305
|
-
});
|
4108
|
+
// src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts
|
4109
|
+
function createCoreFileStreamSchema() {
|
4110
|
+
return {
|
4111
|
+
collaborative: true,
|
4112
|
+
builtin: "FileStream"
|
4113
|
+
};
|
4306
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
|
+
};
|
4307
4143
|
|
4308
4144
|
// src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
|
4145
|
+
function createCoreAccountSchema(shape) {
|
4146
|
+
return {
|
4147
|
+
...createCoreCoMapSchema(shape),
|
4148
|
+
builtin: "Account"
|
4149
|
+
};
|
4150
|
+
}
|
4309
4151
|
function enrichAccountSchema(schema, coValueClass) {
|
4310
4152
|
const enrichedSchema = Object.assign(schema, {
|
4311
4153
|
create: (...args) => {
|
@@ -4323,9 +4165,6 @@ function enrichAccountSchema(schema, coValueClass) {
|
|
4323
4165
|
subscribe: (...args) => {
|
4324
4166
|
return coValueClass.subscribe(...args);
|
4325
4167
|
},
|
4326
|
-
withHelpers: (helpers) => {
|
4327
|
-
return Object.assign(schema, helpers(schema));
|
4328
|
-
},
|
4329
4168
|
fromRaw: (...args) => {
|
4330
4169
|
return coValueClass.fromRaw(...args);
|
4331
4170
|
},
|
@@ -4342,49 +4181,268 @@ function enrichAccountSchema(schema, coValueClass) {
|
|
4342
4181
|
return enrichedSchema;
|
4343
4182
|
}
|
4344
4183
|
|
4345
|
-
// src/tools/implementation/zodSchema/
|
4346
|
-
|
4347
|
-
|
4348
|
-
|
4349
|
-
|
4350
|
-
}
|
4351
|
-
|
4352
|
-
|
4353
|
-
|
4354
|
-
|
4355
|
-
|
4356
|
-
},
|
4357
|
-
loadAsBlob: (...args) => {
|
4358
|
-
return coValueClass.loadAsBlob(...args);
|
4359
|
-
},
|
4360
|
-
subscribe: (...args) => {
|
4361
|
-
return coValueClass.subscribe(...args);
|
4362
|
-
},
|
4363
|
-
getCoValueClass: () => {
|
4364
|
-
return coValueClass;
|
4184
|
+
// src/tools/implementation/zodSchema/unionUtils.ts
|
4185
|
+
import { RawCoList } from "cojson";
|
4186
|
+
function schemaUnionDiscriminatorFor(schema) {
|
4187
|
+
if (isUnionOfCoMapsDeeply(schema)) {
|
4188
|
+
const definition = schema.getDefinition();
|
4189
|
+
const { discriminatorMap, discriminator, options } = definition;
|
4190
|
+
const field = discriminatorMap[discriminator];
|
4191
|
+
if (!field) {
|
4192
|
+
throw new Error(
|
4193
|
+
"co.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
|
4194
|
+
);
|
4365
4195
|
}
|
4366
|
-
|
4196
|
+
for (const value of field) {
|
4197
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
4198
|
+
throw new Error(
|
4199
|
+
"co.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported"
|
4200
|
+
);
|
4201
|
+
}
|
4202
|
+
}
|
4203
|
+
const availableOptions = [];
|
4204
|
+
for (const option of options) {
|
4205
|
+
if (option.builtin === "CoMap") {
|
4206
|
+
availableOptions.push(option);
|
4207
|
+
} else if (option.builtin === "CoDiscriminatedUnion") {
|
4208
|
+
for (const subOption of option.getDefinition().options) {
|
4209
|
+
if (!options.includes(subOption)) {
|
4210
|
+
options.push(subOption);
|
4211
|
+
}
|
4212
|
+
}
|
4213
|
+
} else {
|
4214
|
+
throw new Error(
|
4215
|
+
"Unsupported zod type in co.discriminatedUnion() of collaborative types"
|
4216
|
+
);
|
4217
|
+
}
|
4218
|
+
}
|
4219
|
+
const determineSchema = (_raw) => {
|
4220
|
+
if (_raw instanceof RawCoList) {
|
4221
|
+
throw new Error(
|
4222
|
+
"co.discriminatedUnion() of collaborative types is not supported for CoLists"
|
4223
|
+
);
|
4224
|
+
}
|
4225
|
+
for (const option of availableOptions) {
|
4226
|
+
let match = true;
|
4227
|
+
for (const key of Object.keys(discriminatorMap)) {
|
4228
|
+
const discriminatorDef = option.getDefinition().shape[key];
|
4229
|
+
const discriminatorValue = _raw.get(key);
|
4230
|
+
if (discriminatorValue && typeof discriminatorValue === "object") {
|
4231
|
+
throw new Error("Discriminator must be a primitive value");
|
4232
|
+
}
|
4233
|
+
if (!discriminatorDef) {
|
4234
|
+
if (key === discriminator) {
|
4235
|
+
match = false;
|
4236
|
+
break;
|
4237
|
+
} else {
|
4238
|
+
continue;
|
4239
|
+
}
|
4240
|
+
}
|
4241
|
+
if (discriminatorDef._zod.def.type !== "literal") {
|
4242
|
+
break;
|
4243
|
+
}
|
4244
|
+
const literalDef = discriminatorDef._zod.def;
|
4245
|
+
if (!Array.from(literalDef.values).includes(discriminatorValue)) {
|
4246
|
+
match = false;
|
4247
|
+
break;
|
4248
|
+
}
|
4249
|
+
}
|
4250
|
+
if (match) {
|
4251
|
+
const coValueSchema = hydrateCoreCoValueSchema(option);
|
4252
|
+
return coValueSchema.getCoValueClass();
|
4253
|
+
}
|
4254
|
+
}
|
4255
|
+
throw new Error(
|
4256
|
+
"co.discriminatedUnion() of collaborative types with no matching discriminator value found"
|
4257
|
+
);
|
4258
|
+
};
|
4259
|
+
return determineSchema;
|
4260
|
+
} else {
|
4261
|
+
throw new Error(
|
4262
|
+
"co.discriminatedUnion() of non-collaborative types is not supported"
|
4263
|
+
);
|
4264
|
+
}
|
4265
|
+
}
|
4266
|
+
function isUnionOfCoMapsDeeply(schema) {
|
4267
|
+
return schema.getDefinition().options.every(isCoMapOrUnionOfCoMapsDeeply);
|
4268
|
+
}
|
4269
|
+
function isCoMapOrUnionOfCoMapsDeeply(schema) {
|
4270
|
+
if (schema.builtin === "CoMap") {
|
4271
|
+
return true;
|
4272
|
+
} else if (schema.builtin === "CoDiscriminatedUnion") {
|
4273
|
+
return schema.getDefinition().options.every(isCoMapOrUnionOfCoMapsDeeply);
|
4274
|
+
} else {
|
4275
|
+
return false;
|
4276
|
+
}
|
4277
|
+
}
|
4278
|
+
function isUnionOfPrimitivesDeeply(schema) {
|
4279
|
+
if (schema instanceof z.core.$ZodUnion) {
|
4280
|
+
return schema._zod.def.options.every(isUnionOfPrimitivesDeeply);
|
4281
|
+
} else {
|
4282
|
+
return !isAnyCoValueSchema2(schema);
|
4283
|
+
}
|
4367
4284
|
}
|
4368
4285
|
|
4369
|
-
// src/tools/implementation/zodSchema/
|
4370
|
-
function
|
4371
|
-
|
4372
|
-
|
4373
|
-
|
4374
|
-
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4378
|
-
subscribe: (...args) => {
|
4379
|
-
return coValueClass.subscribe(...args);
|
4380
|
-
},
|
4381
|
-
fromRaw: (...args) => {
|
4382
|
-
return coValueClass.fromRaw(...args);
|
4383
|
-
},
|
4384
|
-
getCoValueClass: () => {
|
4385
|
-
return coValueClass;
|
4286
|
+
// src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts
|
4287
|
+
function schemaFieldToCoFieldDef(schema) {
|
4288
|
+
if (isCoValueClass(schema)) {
|
4289
|
+
return coField.ref(schema);
|
4290
|
+
} else if (isCoValueSchema(schema)) {
|
4291
|
+
if (schema.builtin === "CoOptional") {
|
4292
|
+
return coField.ref(schema.getCoValueClass(), {
|
4293
|
+
optional: true
|
4294
|
+
});
|
4386
4295
|
}
|
4387
|
-
|
4296
|
+
return coField.ref(schema.getCoValueClass());
|
4297
|
+
} else {
|
4298
|
+
if ("_zod" in schema) {
|
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") {
|
4304
|
+
return coField.string;
|
4305
|
+
} else if (zodSchemaDef.type === "number") {
|
4306
|
+
return coField.number;
|
4307
|
+
} else if (zodSchemaDef.type === "boolean") {
|
4308
|
+
return coField.boolean;
|
4309
|
+
} else if (zodSchemaDef.type === "null") {
|
4310
|
+
return coField.null;
|
4311
|
+
} else if (zodSchemaDef.type === "enum") {
|
4312
|
+
return coField.string;
|
4313
|
+
} else if (zodSchemaDef.type === "readonly") {
|
4314
|
+
return schemaFieldToCoFieldDef(
|
4315
|
+
schema.def.innerType
|
4316
|
+
);
|
4317
|
+
} else if (zodSchemaDef.type === "date") {
|
4318
|
+
return coField.optional.Date;
|
4319
|
+
} else if (zodSchemaDef.type === "template_literal") {
|
4320
|
+
return coField.string;
|
4321
|
+
} else if (zodSchemaDef.type === "lazy") {
|
4322
|
+
return schemaFieldToCoFieldDef(
|
4323
|
+
schema.unwrap()
|
4324
|
+
);
|
4325
|
+
} else if (zodSchemaDef.type === "default" || zodSchemaDef.type === "catch") {
|
4326
|
+
console.warn(
|
4327
|
+
"z.default()/z.catch() are not supported in collaborative schemas. They will be ignored."
|
4328
|
+
);
|
4329
|
+
return schemaFieldToCoFieldDef(
|
4330
|
+
schema.def.innerType
|
4331
|
+
);
|
4332
|
+
} else if (zodSchemaDef.type === "literal") {
|
4333
|
+
if (zodSchemaDef.values.some((literal2) => typeof literal2 === "undefined")) {
|
4334
|
+
throw new Error("z.literal() with undefined is not supported");
|
4335
|
+
}
|
4336
|
+
if (zodSchemaDef.values.some((literal2) => literal2 === null)) {
|
4337
|
+
throw new Error("z.literal() with null is not supported");
|
4338
|
+
}
|
4339
|
+
if (zodSchemaDef.values.some((literal2) => typeof literal2 === "bigint")) {
|
4340
|
+
throw new Error("z.literal() with bigint is not supported");
|
4341
|
+
}
|
4342
|
+
return coField.literal(
|
4343
|
+
...zodSchemaDef.values
|
4344
|
+
);
|
4345
|
+
} else if (zodSchemaDef.type === "object" || zodSchemaDef.type === "array" || zodSchemaDef.type === "tuple") {
|
4346
|
+
return coField.json();
|
4347
|
+
} else if (zodSchemaDef.type === "union") {
|
4348
|
+
if (isUnionOfPrimitivesDeeply(schema)) {
|
4349
|
+
return coField.json();
|
4350
|
+
} else {
|
4351
|
+
throw new Error(
|
4352
|
+
"z.union()/z.discriminatedUnion() of collaborative types is not supported. Use co.discriminatedUnion() instead."
|
4353
|
+
);
|
4354
|
+
}
|
4355
|
+
} else {
|
4356
|
+
throw new Error(
|
4357
|
+
`Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`
|
4358
|
+
);
|
4359
|
+
}
|
4360
|
+
} else {
|
4361
|
+
throw new Error(`Unsupported zod type: ${schema}`);
|
4362
|
+
}
|
4363
|
+
}
|
4364
|
+
}
|
4365
|
+
|
4366
|
+
// src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts
|
4367
|
+
function isAnyCoValueSchema2(schema) {
|
4368
|
+
return "collaborative" in schema && schema.collaborative === true;
|
4369
|
+
}
|
4370
|
+
function isCoValueSchema(schema) {
|
4371
|
+
return isAnyCoValueSchema2(schema) && "getCoValueClass" in schema;
|
4372
|
+
}
|
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
|
4390
|
+
);
|
4391
|
+
}
|
4392
|
+
if (def.catchall) {
|
4393
|
+
this[coField.items] = schemaFieldToCoFieldDef(
|
4394
|
+
def.catchall
|
4395
|
+
);
|
4396
|
+
}
|
4397
|
+
}
|
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;
|
4432
|
+
} else {
|
4433
|
+
const notReachable = schema;
|
4434
|
+
throw new Error(
|
4435
|
+
`Unsupported zod CoValue type for top-level schema: ${JSON.stringify(notReachable, void 0, 2)}`
|
4436
|
+
);
|
4437
|
+
}
|
4438
|
+
}
|
4439
|
+
function coValueClassFromCoValueClassOrSchema(schema) {
|
4440
|
+
if (isCoValueClass(schema)) {
|
4441
|
+
return schema;
|
4442
|
+
} else if (isCoValueSchema(schema)) {
|
4443
|
+
return schema.getCoValueClass();
|
4444
|
+
}
|
4445
|
+
throw new Error(`Unsupported schema: ${JSON.stringify(schema)}`);
|
4388
4446
|
}
|
4389
4447
|
|
4390
4448
|
// src/tools/coValues/extensions/imageDef.ts
|
@@ -4392,7 +4450,7 @@ var ImageDefinitionBase = coMapDefiner({
|
|
4392
4450
|
originalSize: z.tuple([z.number(), z.number()]),
|
4393
4451
|
placeholderDataURL: z.string().optional()
|
4394
4452
|
}).catchall(coFileStreamDefiner());
|
4395
|
-
var ImageDefinition =
|
4453
|
+
var ImageDefinition = Object.assign({}, ImageDefinitionBase, {
|
4396
4454
|
highestResAvailable(imageDef, options) {
|
4397
4455
|
const resolutions = Object.keys(imageDef).filter(
|
4398
4456
|
(key) => key.match(/^\d+x\d+$/)
|
@@ -4422,7 +4480,7 @@ var ImageDefinition = ImageDefinitionBase.withHelpers((Self) => ({
|
|
4422
4480
|
stream: imageDef[highestAvailableResolution]
|
4423
4481
|
};
|
4424
4482
|
}
|
4425
|
-
})
|
4483
|
+
});
|
4426
4484
|
|
4427
4485
|
// src/tools/implementation/ContextManager.ts
|
4428
4486
|
import { cojsonInternals as cojsonInternals4 } from "cojson";
|
@@ -4993,46 +5051,6 @@ function subscribeToCoValue(cls, id, options, listener) {
|
|
4993
5051
|
}
|
4994
5052
|
return unsubscribe;
|
4995
5053
|
}
|
4996
|
-
function createCoValueObservable(initialValue = void 0) {
|
4997
|
-
let currentValue = initialValue;
|
4998
|
-
let subscriberCount = 0;
|
4999
|
-
function subscribe(cls, id, options, listener) {
|
5000
|
-
subscriberCount++;
|
5001
|
-
const unsubscribe = subscribeToCoValue(
|
5002
|
-
anySchemaToCoSchema(cls),
|
5003
|
-
id,
|
5004
|
-
{
|
5005
|
-
loadAs: options.loadAs,
|
5006
|
-
resolve: options.resolve,
|
5007
|
-
onUnavailable: () => {
|
5008
|
-
currentValue = null;
|
5009
|
-
options.onUnavailable?.();
|
5010
|
-
},
|
5011
|
-
onUnauthorized: () => {
|
5012
|
-
currentValue = null;
|
5013
|
-
options.onUnauthorized?.();
|
5014
|
-
},
|
5015
|
-
syncResolution: options.syncResolution
|
5016
|
-
},
|
5017
|
-
(value) => {
|
5018
|
-
currentValue = value;
|
5019
|
-
listener();
|
5020
|
-
}
|
5021
|
-
);
|
5022
|
-
return () => {
|
5023
|
-
unsubscribe();
|
5024
|
-
subscriberCount--;
|
5025
|
-
if (subscriberCount === 0) {
|
5026
|
-
currentValue = void 0;
|
5027
|
-
}
|
5028
|
-
};
|
5029
|
-
}
|
5030
|
-
const observable = {
|
5031
|
-
getCurrentValue: () => currentValue,
|
5032
|
-
subscribe
|
5033
|
-
};
|
5034
|
-
return observable;
|
5035
|
-
}
|
5036
5054
|
function subscribeToExistingCoValue(existing, options, listener) {
|
5037
5055
|
return subscribeToCoValue(
|
5038
5056
|
existing.constructor,
|
@@ -5053,9 +5071,9 @@ function isAccountInstance(instance) {
|
|
5053
5071
|
return "_type" in instance && instance._type === "Account";
|
5054
5072
|
}
|
5055
5073
|
function parseCoValueCreateOptions(options) {
|
5056
|
-
const
|
5074
|
+
const Group9 = RegisteredSchemas["Group"];
|
5057
5075
|
if (!options) {
|
5058
|
-
return { owner:
|
5076
|
+
return { owner: Group9.create(), uniqueness: void 0 };
|
5059
5077
|
}
|
5060
5078
|
if ("_type" in options) {
|
5061
5079
|
if (options._type === "Account" || options._type === "Group") {
|
@@ -5064,7 +5082,7 @@ function parseCoValueCreateOptions(options) {
|
|
5064
5082
|
}
|
5065
5083
|
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
5066
5084
|
return {
|
5067
|
-
owner: options.owner ??
|
5085
|
+
owner: options.owner ?? Group9.create(),
|
5068
5086
|
uniqueness
|
5069
5087
|
};
|
5070
5088
|
}
|
@@ -5074,12 +5092,86 @@ function parseGroupCreateOptions(options) {
|
|
5074
5092
|
}
|
5075
5093
|
return "_type" in options && isAccountInstance(options) ? { owner: options } : { owner: options.owner ?? activeAccountContext.get() };
|
5076
5094
|
}
|
5095
|
+
async function exportCoValue(cls, id, options) {
|
5096
|
+
const loadAs = options.loadAs ?? activeAccountContext.get();
|
5097
|
+
const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
|
5098
|
+
const resolve = options.resolve ?? true;
|
5099
|
+
const rootNode = new SubscriptionScope(
|
5100
|
+
node,
|
5101
|
+
resolve,
|
5102
|
+
id,
|
5103
|
+
{
|
5104
|
+
ref: coValueClassFromCoValueClassOrSchema(cls),
|
5105
|
+
optional: false
|
5106
|
+
},
|
5107
|
+
options.skipRetry,
|
5108
|
+
options.bestEffortResolution
|
5109
|
+
);
|
5110
|
+
const value = await new Promise((resolve2) => {
|
5111
|
+
rootNode.setListener((value2) => {
|
5112
|
+
if (value2.type === "unavailable") {
|
5113
|
+
resolve2(null);
|
5114
|
+
console.error(value2.toString());
|
5115
|
+
} else if (value2.type === "unauthorized") {
|
5116
|
+
resolve2(null);
|
5117
|
+
console.error(value2.toString());
|
5118
|
+
} else if (value2.type === "loaded") {
|
5119
|
+
resolve2(value2.value);
|
5120
|
+
}
|
5121
|
+
rootNode.destroy();
|
5122
|
+
});
|
5123
|
+
});
|
5124
|
+
if (!value) {
|
5125
|
+
return null;
|
5126
|
+
}
|
5127
|
+
const valuesExported = /* @__PURE__ */ new Set();
|
5128
|
+
const contentPieces = [];
|
5129
|
+
loadContentPiecesFromSubscription(rootNode, valuesExported, contentPieces);
|
5130
|
+
return contentPieces;
|
5131
|
+
}
|
5132
|
+
function loadContentPiecesFromSubscription(subscription, valuesExported, contentPieces) {
|
5133
|
+
if (valuesExported.has(subscription.id)) {
|
5134
|
+
return;
|
5135
|
+
}
|
5136
|
+
valuesExported.add(subscription.id);
|
5137
|
+
const core2 = subscription.getCurrentValue()?._raw.core;
|
5138
|
+
if (core2) {
|
5139
|
+
loadContentPiecesFromCoValue(core2, valuesExported, contentPieces);
|
5140
|
+
}
|
5141
|
+
for (const child of subscription.childNodes.values()) {
|
5142
|
+
loadContentPiecesFromSubscription(child, valuesExported, contentPieces);
|
5143
|
+
}
|
5144
|
+
}
|
5145
|
+
function loadContentPiecesFromCoValue(core2, valuesExported, contentPieces) {
|
5146
|
+
for (const dependency of core2.getDependedOnCoValues()) {
|
5147
|
+
if (valuesExported.has(dependency)) {
|
5148
|
+
continue;
|
5149
|
+
}
|
5150
|
+
const depCoValue = core2.node.getCoValue(dependency);
|
5151
|
+
if (depCoValue.isAvailable()) {
|
5152
|
+
valuesExported.add(dependency);
|
5153
|
+
loadContentPiecesFromCoValue(depCoValue, valuesExported, contentPieces);
|
5154
|
+
}
|
5155
|
+
}
|
5156
|
+
const pieces = core2.verified.newContentSince(emptyKnownState(core2.id));
|
5157
|
+
for (const piece of pieces ?? []) {
|
5158
|
+
contentPieces.push(piece);
|
5159
|
+
}
|
5160
|
+
}
|
5161
|
+
function importContentPieces(contentPieces, loadAs) {
|
5162
|
+
const account = loadAs ?? Account.getMe();
|
5163
|
+
const node = "node" in account ? account.node : account._raw.core.node;
|
5164
|
+
for (const piece of contentPieces) {
|
5165
|
+
node.syncManager.handleNewContent(piece, "import");
|
5166
|
+
}
|
5167
|
+
}
|
5077
5168
|
|
5078
5169
|
export {
|
5079
5170
|
zodReExport_exports,
|
5080
5171
|
loadCoValue,
|
5081
5172
|
subscribeToCoValue,
|
5082
|
-
|
5173
|
+
exportCoValue,
|
5174
|
+
importContentPieces,
|
5083
5175
|
CoValueBase,
|
5084
5176
|
CoMap,
|
5085
5177
|
CoList,
|
@@ -5089,6 +5181,7 @@ export {
|
|
5089
5181
|
isControlledAccount,
|
5090
5182
|
Group,
|
5091
5183
|
Profile,
|
5184
|
+
isCoValueId,
|
5092
5185
|
Inbox,
|
5093
5186
|
InboxSender,
|
5094
5187
|
CoPlainText,
|
@@ -5104,9 +5197,9 @@ export {
|
|
5104
5197
|
createJazzContextForNewAccount,
|
5105
5198
|
createJazzContext,
|
5106
5199
|
createAnonymousJazzContext,
|
5107
|
-
|
5108
|
-
anySchemaToCoSchema,
|
5200
|
+
coMapDefiner,
|
5109
5201
|
coExport_exports,
|
5202
|
+
coValueClassFromCoValueClassOrSchema,
|
5110
5203
|
ImageDefinition,
|
5111
5204
|
KvStoreContext,
|
5112
5205
|
AuthSecretStorage,
|
@@ -5114,4 +5207,4 @@ export {
|
|
5114
5207
|
JazzContextManager
|
5115
5208
|
};
|
5116
5209
|
/* istanbul ignore file -- @preserve */
|
5117
|
-
//# sourceMappingURL=chunk-
|
5210
|
+
//# sourceMappingURL=chunk-MLCNE3TL.js.map
|