jazz-tools 0.19.12 → 0.19.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +50 -50
- package/CHANGELOG.md +10 -0
- package/dist/browser/createBrowserContext.d.ts +1 -5
- package/dist/browser/createBrowserContext.d.ts.map +1 -1
- package/dist/browser/index.js +124 -47
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.d.ts +12 -0
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.d.ts.map +1 -0
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.test.d.ts +2 -0
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.test.d.ts.map +1 -0
- package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts +6 -0
- package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts.map +1 -0
- package/dist/browser/provideBrowserLockSession/index.d.ts +4 -0
- package/dist/browser/provideBrowserLockSession/index.d.ts.map +1 -0
- package/dist/{chunk-AGF4HEDH.js → chunk-GAPMDNJY.js} +437 -82
- package/dist/chunk-GAPMDNJY.js.map +1 -0
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/react-native/index.js +41 -12
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native-core/ReactNativeSessionProvider.d.ts +11 -0
- package/dist/react-native-core/ReactNativeSessionProvider.d.ts.map +1 -0
- package/dist/react-native-core/index.js +41 -12
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +2 -8
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/react-native-core/tests/ReactNativeSessionProvider.test.d.ts +2 -0
- package/dist/react-native-core/tests/ReactNativeSessionProvider.test.d.ts.map +1 -0
- package/dist/testing.js +4 -3
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +2 -2
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +1 -2
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coVector.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts +5 -1
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +2 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +2 -2
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts +21 -11
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +14 -6
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts +99 -0
- package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +11 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +11 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +15 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +9 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +13 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts +12 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +1 -0
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/schema.withPermissions.test.d.ts +2 -0
- package/dist/tools/tests/schema.withPermissions.test.d.ts.map +1 -0
- package/dist/worker/index.js +2 -2
- package/dist/worker/index.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/createBrowserContext.ts +3 -62
- package/src/browser/provideBrowserLockSession/BrowserSessionProvider.test.ts +406 -0
- package/src/browser/provideBrowserLockSession/BrowserSessionProvider.ts +132 -0
- package/src/browser/provideBrowserLockSession/SessionIDStorage.ts +33 -0
- package/src/browser/provideBrowserLockSession/index.ts +11 -0
- package/src/react-native-core/ReactNativeSessionProvider.ts +52 -0
- package/src/react-native-core/platform.ts +5 -30
- package/src/react-native-core/tests/ReactNativeSessionProvider.test.ts +124 -0
- package/src/tools/coValues/account.ts +4 -0
- package/src/tools/coValues/coFeed.ts +8 -3
- package/src/tools/coValues/coList.ts +6 -3
- package/src/tools/coValues/coMap.ts +10 -0
- package/src/tools/coValues/coVector.ts +2 -1
- package/src/tools/coValues/group.ts +6 -4
- package/src/tools/coValues/interfaces.ts +19 -7
- package/src/tools/exports.ts +3 -1
- package/src/tools/implementation/createContext.ts +43 -15
- package/src/tools/implementation/schema.ts +23 -13
- package/src/tools/implementation/schemaUtils.ts +1 -1
- package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +105 -4
- package/src/tools/implementation/zodSchema/schemaPermissions.ts +188 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +46 -3
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +46 -3
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +50 -13
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +14 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +24 -1
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +51 -4
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +25 -1
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +21 -1
- package/src/tools/implementation/zodSchema/unionUtils.ts +72 -20
- package/src/tools/internal.ts +1 -0
- package/src/tools/testing.ts +3 -1
- package/src/tools/tests/ContextManager.test.ts +2 -1
- package/src/tools/tests/coPlainText.test.ts +2 -2
- package/src/tools/tests/createContext.test.ts +79 -1
- package/src/tools/tests/deepLoading.test.ts +25 -2
- package/src/tools/tests/schema.resolved.test.ts +10 -0
- package/src/tools/tests/schema.withPermissions.test.ts +859 -0
- package/src/tools/tests/utils.ts +2 -2
- package/src/worker/index.ts +2 -2
- package/dist/chunk-AGF4HEDH.js.map +0 -1
|
@@ -377,10 +377,14 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
|
377
377
|
if (initValue != null) {
|
|
378
378
|
let refId = initValue.$jazz?.id;
|
|
379
379
|
if (!refId) {
|
|
380
|
+
const newOwnerStrategy = descriptor.permissions?.newInlineOwnerStrategy;
|
|
381
|
+
const onCreate = descriptor.permissions?.onCreate;
|
|
380
382
|
const coValue = instantiateRefEncodedWithInit(
|
|
381
383
|
descriptor,
|
|
382
384
|
initValue,
|
|
383
|
-
owner
|
|
385
|
+
owner,
|
|
386
|
+
newOwnerStrategy,
|
|
387
|
+
onCreate
|
|
384
388
|
);
|
|
385
389
|
refId = coValue.$jazz.id;
|
|
386
390
|
}
|
|
@@ -586,10 +590,14 @@ var CoMapJazzApi = class extends CoValueJazzApi {
|
|
|
586
590
|
this.raw.set(key, null);
|
|
587
591
|
} else {
|
|
588
592
|
if (!refId) {
|
|
593
|
+
const newOwnerStrategy = descriptor.permissions?.newInlineOwnerStrategy;
|
|
594
|
+
const onCreate = descriptor.permissions?.onCreate;
|
|
589
595
|
const coValue = instantiateRefEncodedWithInit(
|
|
590
596
|
descriptor,
|
|
591
597
|
value,
|
|
592
|
-
this.owner
|
|
598
|
+
this.owner,
|
|
599
|
+
newOwnerStrategy,
|
|
600
|
+
onCreate
|
|
593
601
|
);
|
|
594
602
|
refId = coValue.$jazz.id;
|
|
595
603
|
}
|
|
@@ -939,8 +947,8 @@ var _CoList = class _CoList extends Array {
|
|
|
939
947
|
* @deprecated Use `co.list(...).create` instead.
|
|
940
948
|
**/
|
|
941
949
|
static create(items, options) {
|
|
942
|
-
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
|
943
950
|
const instance = new this();
|
|
951
|
+
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
|
944
952
|
Object.defineProperties(instance, {
|
|
945
953
|
$jazz: {
|
|
946
954
|
value: new CoListJazzApi(instance, () => raw),
|
|
@@ -1431,10 +1439,14 @@ function toRawItems(items, itemDescriptor, owner) {
|
|
|
1431
1439
|
}
|
|
1432
1440
|
let refId = value.$jazz?.id;
|
|
1433
1441
|
if (!refId) {
|
|
1442
|
+
const newOwnerStrategy = itemDescriptor.permissions?.newInlineOwnerStrategy;
|
|
1443
|
+
const onCreate = itemDescriptor.permissions?.onCreate;
|
|
1434
1444
|
const coValue = instantiateRefEncodedWithInit(
|
|
1435
1445
|
itemDescriptor,
|
|
1436
1446
|
value,
|
|
1437
|
-
owner
|
|
1447
|
+
owner,
|
|
1448
|
+
newOwnerStrategy,
|
|
1449
|
+
onCreate
|
|
1438
1450
|
);
|
|
1439
1451
|
refId = coValue.$jazz.id;
|
|
1440
1452
|
}
|
|
@@ -1727,10 +1739,14 @@ var CoFeedJazzApi = class extends CoValueJazzApi {
|
|
|
1727
1739
|
} else if (isRefEncoded(itemDescriptor)) {
|
|
1728
1740
|
let refId = item.$jazz?.id;
|
|
1729
1741
|
if (!refId) {
|
|
1742
|
+
const newOwnerStrategy = itemDescriptor.permissions?.newInlineOwnerStrategy;
|
|
1743
|
+
const onCreate = itemDescriptor.permissions?.onCreate;
|
|
1730
1744
|
const coValue = instantiateRefEncodedWithInit(
|
|
1731
1745
|
itemDescriptor,
|
|
1732
1746
|
item,
|
|
1733
|
-
this.owner
|
|
1747
|
+
this.owner,
|
|
1748
|
+
newOwnerStrategy,
|
|
1749
|
+
onCreate
|
|
1734
1750
|
);
|
|
1735
1751
|
refId = coValue.$jazz.id;
|
|
1736
1752
|
}
|
|
@@ -1940,6 +1956,7 @@ var FileStream = class extends CoValueBase {
|
|
|
1940
1956
|
*
|
|
1941
1957
|
* @param options - Configuration options for the new FileStream
|
|
1942
1958
|
* @param options.owner - The Account or Group that will own this FileStream and control access rights
|
|
1959
|
+
* @param schemaConfiguration - Internal schema configuration
|
|
1943
1960
|
*
|
|
1944
1961
|
* @example
|
|
1945
1962
|
* ```typescript
|
|
@@ -1960,7 +1977,8 @@ var FileStream = class extends CoValueBase {
|
|
|
1960
1977
|
* @deprecated Use `co.fileStream(...).create` instead.
|
|
1961
1978
|
*/
|
|
1962
1979
|
static create(options) {
|
|
1963
|
-
|
|
1980
|
+
const { owner } = parseCoValueCreateOptions(options);
|
|
1981
|
+
return new this({ owner });
|
|
1964
1982
|
}
|
|
1965
1983
|
getMetadata() {
|
|
1966
1984
|
return this.$jazz.raw.getBinaryStreamInfo();
|
|
@@ -2416,10 +2434,14 @@ var AccountJazzApi = class extends CoValueJazzApi {
|
|
|
2416
2434
|
let refId = value.$jazz?.id;
|
|
2417
2435
|
if (!refId) {
|
|
2418
2436
|
const descriptor = this.schema[key];
|
|
2437
|
+
const newOwnerStrategy = descriptor.permissions?.newInlineOwnerStrategy;
|
|
2438
|
+
const onCreate = descriptor.permissions?.onCreate;
|
|
2419
2439
|
const coValue = instantiateRefEncodedWithInit(
|
|
2420
2440
|
descriptor,
|
|
2421
2441
|
value,
|
|
2422
|
-
accountOrGroupToGroup(this.account)
|
|
2442
|
+
accountOrGroupToGroup(this.account),
|
|
2443
|
+
newOwnerStrategy,
|
|
2444
|
+
onCreate
|
|
2423
2445
|
);
|
|
2424
2446
|
refId = coValue.$jazz.id;
|
|
2425
2447
|
}
|
|
@@ -3438,7 +3460,8 @@ var _CoVector = class _CoVector extends Float32Array {
|
|
|
3438
3460
|
`Vector dimension mismatch! Expected ${this.requiredDimensionsCount} dimensions, got ${givenVectorDimensions}`
|
|
3439
3461
|
);
|
|
3440
3462
|
}
|
|
3441
|
-
const
|
|
3463
|
+
const { owner } = parseCoValueCreateOptions(options);
|
|
3464
|
+
const coVector = new this({ owner });
|
|
3442
3465
|
coVector.setVectorData(vectorAsFloat32Array);
|
|
3443
3466
|
const byteArray = _CoVector.toByteArray(vectorAsFloat32Array);
|
|
3444
3467
|
coVector.$jazz.raw.startBinaryStream({
|
|
@@ -3886,14 +3909,15 @@ var coField = {
|
|
|
3886
3909
|
items: ItemsSym,
|
|
3887
3910
|
optional: optional2
|
|
3888
3911
|
};
|
|
3889
|
-
function optionalRef(arg) {
|
|
3890
|
-
return ref(arg, { optional: true });
|
|
3912
|
+
function optionalRef(arg, options) {
|
|
3913
|
+
return ref(arg, { optional: true, permissions: options.permissions });
|
|
3891
3914
|
}
|
|
3892
3915
|
function ref(arg, options) {
|
|
3893
3916
|
return {
|
|
3894
3917
|
[SchemaInit]: {
|
|
3895
3918
|
ref: arg,
|
|
3896
|
-
optional: options
|
|
3919
|
+
optional: options.optional || false,
|
|
3920
|
+
permissions: options.permissions
|
|
3897
3921
|
}
|
|
3898
3922
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3899
3923
|
};
|
|
@@ -3906,16 +3930,14 @@ function instantiateRefEncodedFromRaw(schema, raw) {
|
|
|
3906
3930
|
raw
|
|
3907
3931
|
).fromRaw(raw);
|
|
3908
3932
|
}
|
|
3909
|
-
function instantiateRefEncodedWithInit(schema, init,
|
|
3933
|
+
function instantiateRefEncodedWithInit(schema, init, containerOwner, newOwnerStrategy = extendContainerOwner, onCreate) {
|
|
3910
3934
|
if (!isCoValueClass(schema.ref)) {
|
|
3911
3935
|
throw Error(
|
|
3912
3936
|
`Cannot automatically create CoValue from value: ${JSON.stringify(init)}. Use the CoValue schema's create() method instead.`
|
|
3913
3937
|
);
|
|
3914
3938
|
}
|
|
3915
|
-
const
|
|
3916
|
-
|
|
3917
|
-
const owner = new Group2({ fromRaw: rawGroup });
|
|
3918
|
-
owner.addMember(parentOwner);
|
|
3939
|
+
const owner = newOwnerStrategy(() => Group2.create(), containerOwner, init);
|
|
3940
|
+
onCreate?.(owner, init);
|
|
3919
3941
|
return schema.ref.create(init, owner);
|
|
3920
3942
|
}
|
|
3921
3943
|
|
|
@@ -4949,13 +4971,23 @@ function accessChildById(parent, childId, schema) {
|
|
|
4949
4971
|
import {
|
|
4950
4972
|
LocalNode as LocalNode5
|
|
4951
4973
|
} from "cojson";
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4974
|
+
var MockSessionProvider = class {
|
|
4975
|
+
async acquireSession(accountID, crypto) {
|
|
4976
|
+
return {
|
|
4977
|
+
sessionID: crypto.newRandomSessionID(
|
|
4978
|
+
accountID
|
|
4979
|
+
),
|
|
4980
|
+
sessionDone: () => {
|
|
4981
|
+
}
|
|
4982
|
+
};
|
|
4983
|
+
}
|
|
4984
|
+
async persistSession(_accountID, _sessionID) {
|
|
4985
|
+
return {
|
|
4986
|
+
sessionDone: () => {
|
|
4987
|
+
}
|
|
4988
|
+
};
|
|
4989
|
+
}
|
|
4990
|
+
};
|
|
4959
4991
|
async function createJazzContextFromExistingCredentials({
|
|
4960
4992
|
credentials,
|
|
4961
4993
|
peers,
|
|
@@ -4966,7 +4998,7 @@ async function createJazzContextFromExistingCredentials({
|
|
|
4966
4998
|
onLogOut,
|
|
4967
4999
|
asActiveAccount
|
|
4968
5000
|
}) {
|
|
4969
|
-
const { sessionID, sessionDone } = await sessionProvider(
|
|
5001
|
+
const { sessionID, sessionDone } = await sessionProvider.acquireSession(
|
|
4970
5002
|
credentials.accountID,
|
|
4971
5003
|
crypto
|
|
4972
5004
|
);
|
|
@@ -5012,7 +5044,8 @@ async function createJazzContextForNewAccount({
|
|
|
5012
5044
|
crypto,
|
|
5013
5045
|
AccountSchema: PropsAccountSchema,
|
|
5014
5046
|
onLogOut,
|
|
5015
|
-
storage
|
|
5047
|
+
storage,
|
|
5048
|
+
sessionProvider
|
|
5016
5049
|
}) {
|
|
5017
5050
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
|
5018
5051
|
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
|
@@ -5030,11 +5063,16 @@ async function createJazzContextForNewAccount({
|
|
|
5030
5063
|
});
|
|
5031
5064
|
const account = AccountClass.fromNode(node);
|
|
5032
5065
|
activeAccountContext3.set(account);
|
|
5066
|
+
const { sessionDone } = await sessionProvider.persistSession(
|
|
5067
|
+
account.$jazz.id,
|
|
5068
|
+
node.currentSessionID
|
|
5069
|
+
);
|
|
5033
5070
|
return {
|
|
5034
5071
|
node,
|
|
5035
5072
|
account,
|
|
5036
5073
|
done: () => {
|
|
5037
5074
|
node.gracefulShutdown();
|
|
5075
|
+
sessionDone();
|
|
5038
5076
|
},
|
|
5039
5077
|
logOut: async () => {
|
|
5040
5078
|
node.gracefulShutdown();
|
|
@@ -5076,6 +5114,7 @@ async function createJazzContext(options) {
|
|
|
5076
5114
|
peers: options.peers,
|
|
5077
5115
|
crypto,
|
|
5078
5116
|
AccountSchema: options.AccountSchema,
|
|
5117
|
+
sessionProvider: options.sessionProvider,
|
|
5079
5118
|
onLogOut: async () => {
|
|
5080
5119
|
await authSecretStorage.clearWithoutNotify();
|
|
5081
5120
|
},
|
|
@@ -5221,6 +5260,74 @@ var CoOptionalSchema = class {
|
|
|
5221
5260
|
}
|
|
5222
5261
|
};
|
|
5223
5262
|
|
|
5263
|
+
// src/tools/implementation/zodSchema/schemaPermissions.ts
|
|
5264
|
+
var DEFAULT_SCHEMA_PERMISSIONS = {
|
|
5265
|
+
default: () => Group2.create(),
|
|
5266
|
+
onInlineCreate: "extendsContainer"
|
|
5267
|
+
};
|
|
5268
|
+
function setDefaultSchemaPermissions(permissions) {
|
|
5269
|
+
DEFAULT_SCHEMA_PERMISSIONS = {
|
|
5270
|
+
...DEFAULT_SCHEMA_PERMISSIONS,
|
|
5271
|
+
...permissions
|
|
5272
|
+
};
|
|
5273
|
+
}
|
|
5274
|
+
var extendContainerOwnerFactory = (roleOverride) => (createNewGroup, containerOwner) => {
|
|
5275
|
+
const node = containerOwner.$jazz.localNode;
|
|
5276
|
+
const rawGroup = node.createGroup();
|
|
5277
|
+
const owner = new Group2({ fromRaw: rawGroup });
|
|
5278
|
+
owner.addMember(containerOwner, roleOverride);
|
|
5279
|
+
return owner;
|
|
5280
|
+
};
|
|
5281
|
+
var extendContainerOwner = extendContainerOwnerFactory();
|
|
5282
|
+
function schemaToRefPermissions(permissions) {
|
|
5283
|
+
const newInlineOwnerStrategy = parseOnInlineCreate(
|
|
5284
|
+
permissions.onInlineCreate
|
|
5285
|
+
);
|
|
5286
|
+
const onCreate = permissions.onCreate ? (newGroup, _init) => permissions.onCreate?.(newGroup) : void 0;
|
|
5287
|
+
return {
|
|
5288
|
+
newInlineOwnerStrategy,
|
|
5289
|
+
onCreate
|
|
5290
|
+
};
|
|
5291
|
+
}
|
|
5292
|
+
function parseOnInlineCreate(onInlineCreate) {
|
|
5293
|
+
if (!onInlineCreate || onInlineCreate === "extendsContainer") {
|
|
5294
|
+
return extendContainerOwner;
|
|
5295
|
+
}
|
|
5296
|
+
if (typeof onInlineCreate === "object" && "extendsContainer" in onInlineCreate) {
|
|
5297
|
+
return extendContainerOwnerFactory(onInlineCreate.extendsContainer);
|
|
5298
|
+
}
|
|
5299
|
+
if (onInlineCreate === "newGroup") {
|
|
5300
|
+
return (createNewGroup) => createNewGroup();
|
|
5301
|
+
}
|
|
5302
|
+
if (onInlineCreate === "sameAsContainer") {
|
|
5303
|
+
return (_createNewGroup, containerOwner) => containerOwner;
|
|
5304
|
+
}
|
|
5305
|
+
return (createNewGroup, containerOwner) => {
|
|
5306
|
+
const newGroup = createNewGroup();
|
|
5307
|
+
onInlineCreate(newGroup, { containerOwner });
|
|
5308
|
+
return newGroup;
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5311
|
+
function getDefaultRefPermissions() {
|
|
5312
|
+
return schemaToRefPermissions(DEFAULT_SCHEMA_PERMISSIONS);
|
|
5313
|
+
}
|
|
5314
|
+
function withSchemaPermissions(options, schemaPermissions) {
|
|
5315
|
+
const onCreate = schemaPermissions?.onCreate;
|
|
5316
|
+
if (!options) {
|
|
5317
|
+
const owner2 = schemaPermissions?.default?.() ?? Group2.create();
|
|
5318
|
+
return { owner: owner2, onCreate };
|
|
5319
|
+
}
|
|
5320
|
+
if (TypeSym in options) {
|
|
5321
|
+
return { owner: options, onCreate };
|
|
5322
|
+
}
|
|
5323
|
+
const owner = options.owner ?? schemaPermissions?.default?.() ?? Group2.create();
|
|
5324
|
+
return {
|
|
5325
|
+
...options,
|
|
5326
|
+
owner,
|
|
5327
|
+
onCreate
|
|
5328
|
+
};
|
|
5329
|
+
}
|
|
5330
|
+
|
|
5224
5331
|
// src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts
|
|
5225
5332
|
function createCoreCoRichTextSchema() {
|
|
5226
5333
|
return {
|
|
@@ -5229,15 +5336,20 @@ function createCoreCoRichTextSchema() {
|
|
|
5229
5336
|
resolveQuery: true
|
|
5230
5337
|
};
|
|
5231
5338
|
}
|
|
5232
|
-
var RichTextSchema = class {
|
|
5339
|
+
var RichTextSchema = class _RichTextSchema {
|
|
5233
5340
|
constructor(coValueClass) {
|
|
5234
5341
|
this.coValueClass = coValueClass;
|
|
5235
5342
|
this.collaborative = true;
|
|
5236
5343
|
this.builtin = "CoRichText";
|
|
5237
5344
|
this.resolveQuery = true;
|
|
5345
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5238
5346
|
}
|
|
5239
5347
|
create(text, options) {
|
|
5240
|
-
|
|
5348
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
5349
|
+
options,
|
|
5350
|
+
this.permissions
|
|
5351
|
+
);
|
|
5352
|
+
return this.coValueClass.create(text, optionsWithPermissions);
|
|
5241
5353
|
}
|
|
5242
5354
|
load(id, options) {
|
|
5243
5355
|
return this.coValueClass.load(id, options);
|
|
@@ -5254,6 +5366,14 @@ var RichTextSchema = class {
|
|
|
5254
5366
|
optional() {
|
|
5255
5367
|
return coOptionalDefiner(this);
|
|
5256
5368
|
}
|
|
5369
|
+
/**
|
|
5370
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
5371
|
+
*/
|
|
5372
|
+
withPermissions(permissions) {
|
|
5373
|
+
const copy = new _RichTextSchema(this.coValueClass);
|
|
5374
|
+
copy.permissions = permissions;
|
|
5375
|
+
return copy;
|
|
5376
|
+
}
|
|
5257
5377
|
};
|
|
5258
5378
|
|
|
5259
5379
|
// src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts
|
|
@@ -5428,7 +5548,7 @@ __export(coExport_exports, {
|
|
|
5428
5548
|
});
|
|
5429
5549
|
|
|
5430
5550
|
// src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
|
|
5431
|
-
var CoMapSchema = class
|
|
5551
|
+
var CoMapSchema = class {
|
|
5432
5552
|
constructor(coreSchema, coValueClass) {
|
|
5433
5553
|
this.coValueClass = coValueClass;
|
|
5434
5554
|
this.collaborative = true;
|
|
@@ -5439,12 +5559,21 @@ var CoMapSchema = class _CoMapSchema {
|
|
|
5439
5559
|
* @default true
|
|
5440
5560
|
*/
|
|
5441
5561
|
this.resolveQuery = true;
|
|
5562
|
+
/**
|
|
5563
|
+
* Permissions to be used when creating or composing CoValues
|
|
5564
|
+
* @internal
|
|
5565
|
+
*/
|
|
5566
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5442
5567
|
this.shape = coreSchema.shape;
|
|
5443
5568
|
this.catchAll = coreSchema.catchAll;
|
|
5444
5569
|
this.getDefinition = coreSchema.getDefinition;
|
|
5445
5570
|
}
|
|
5446
|
-
create(
|
|
5447
|
-
|
|
5571
|
+
create(init, options) {
|
|
5572
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
5573
|
+
options,
|
|
5574
|
+
this.permissions
|
|
5575
|
+
);
|
|
5576
|
+
return this.coValueClass.create(init, optionsWithPermissions);
|
|
5448
5577
|
}
|
|
5449
5578
|
load(id, options) {
|
|
5450
5579
|
return this.coValueClass.load(
|
|
@@ -5566,15 +5695,26 @@ var CoMapSchema = class _CoMapSchema {
|
|
|
5566
5695
|
* This resolve query will be used when no resolve query is provided to the load method.
|
|
5567
5696
|
*/
|
|
5568
5697
|
resolved(resolveQuery) {
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5698
|
+
return this.copy({ resolveQuery });
|
|
5699
|
+
}
|
|
5700
|
+
/**
|
|
5701
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
5702
|
+
*/
|
|
5703
|
+
withPermissions(permissions) {
|
|
5704
|
+
return this.copy({ permissions });
|
|
5705
|
+
}
|
|
5706
|
+
/**
|
|
5707
|
+
* Creates a copy of this schema, preserving all previous configuration
|
|
5708
|
+
*/
|
|
5709
|
+
copy({
|
|
5710
|
+
permissions,
|
|
5711
|
+
resolveQuery
|
|
5712
|
+
}) {
|
|
5713
|
+
const coreSchema = createCoreCoMapSchema(this.shape, this.catchAll);
|
|
5714
|
+
const copy = hydrateCoreCoValueSchema(coreSchema);
|
|
5715
|
+
copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
|
|
5716
|
+
copy.resolveQuery = resolveQuery ?? this.resolveQuery;
|
|
5717
|
+
copy.permissions = permissions ?? this.permissions;
|
|
5578
5718
|
return copy;
|
|
5579
5719
|
}
|
|
5580
5720
|
};
|
|
@@ -5611,7 +5751,7 @@ function createCoreCoMapSchema(shape, catchAll) {
|
|
|
5611
5751
|
}
|
|
5612
5752
|
|
|
5613
5753
|
// src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts
|
|
5614
|
-
var CoListSchema = class
|
|
5754
|
+
var CoListSchema = class {
|
|
5615
5755
|
constructor(element, coValueClass) {
|
|
5616
5756
|
this.element = element;
|
|
5617
5757
|
this.coValueClass = coValueClass;
|
|
@@ -5623,9 +5763,21 @@ var CoListSchema = class _CoListSchema {
|
|
|
5623
5763
|
* @default true
|
|
5624
5764
|
*/
|
|
5625
5765
|
this.resolveQuery = true;
|
|
5766
|
+
/**
|
|
5767
|
+
* Permissions to be used when creating or composing CoValues
|
|
5768
|
+
* @internal
|
|
5769
|
+
*/
|
|
5770
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5626
5771
|
}
|
|
5627
5772
|
create(items, options) {
|
|
5628
|
-
|
|
5773
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
5774
|
+
options,
|
|
5775
|
+
this.permissions
|
|
5776
|
+
);
|
|
5777
|
+
return this.coValueClass.create(
|
|
5778
|
+
items,
|
|
5779
|
+
optionsWithPermissions
|
|
5780
|
+
);
|
|
5629
5781
|
}
|
|
5630
5782
|
load(id, options) {
|
|
5631
5783
|
return this.coValueClass.load(
|
|
@@ -5678,8 +5830,22 @@ var CoListSchema = class _CoListSchema {
|
|
|
5678
5830
|
* This resolve query will be used when no resolve query is provided to the load method.
|
|
5679
5831
|
*/
|
|
5680
5832
|
resolved(resolveQuery) {
|
|
5681
|
-
|
|
5682
|
-
|
|
5833
|
+
return this.copy({ resolveQuery });
|
|
5834
|
+
}
|
|
5835
|
+
/**
|
|
5836
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
5837
|
+
*/
|
|
5838
|
+
withPermissions(permissions) {
|
|
5839
|
+
return this.copy({ permissions });
|
|
5840
|
+
}
|
|
5841
|
+
copy({
|
|
5842
|
+
permissions,
|
|
5843
|
+
resolveQuery
|
|
5844
|
+
}) {
|
|
5845
|
+
const coreSchema = createCoreCoListSchema(this.element);
|
|
5846
|
+
const copy = hydrateCoreCoValueSchema(coreSchema);
|
|
5847
|
+
copy.resolveQuery = resolveQuery ?? this.resolveQuery;
|
|
5848
|
+
copy.permissions = permissions ?? this.permissions;
|
|
5683
5849
|
return copy;
|
|
5684
5850
|
}
|
|
5685
5851
|
};
|
|
@@ -5693,7 +5859,7 @@ function createCoreCoListSchema(element) {
|
|
|
5693
5859
|
}
|
|
5694
5860
|
|
|
5695
5861
|
// src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts
|
|
5696
|
-
var CoFeedSchema = class
|
|
5862
|
+
var CoFeedSchema = class {
|
|
5697
5863
|
constructor(element, coValueClass) {
|
|
5698
5864
|
this.element = element;
|
|
5699
5865
|
this.coValueClass = coValueClass;
|
|
@@ -5705,9 +5871,21 @@ var CoFeedSchema = class _CoFeedSchema {
|
|
|
5705
5871
|
* @default true
|
|
5706
5872
|
*/
|
|
5707
5873
|
this.resolveQuery = true;
|
|
5874
|
+
/**
|
|
5875
|
+
* Permissions to be used when creating or composing CoValues
|
|
5876
|
+
* @internal
|
|
5877
|
+
*/
|
|
5878
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5708
5879
|
}
|
|
5709
5880
|
create(init, options) {
|
|
5710
|
-
|
|
5881
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
5882
|
+
options,
|
|
5883
|
+
this.permissions
|
|
5884
|
+
);
|
|
5885
|
+
return this.coValueClass.create(
|
|
5886
|
+
init,
|
|
5887
|
+
optionsWithPermissions
|
|
5888
|
+
);
|
|
5711
5889
|
}
|
|
5712
5890
|
load(id, options) {
|
|
5713
5891
|
return this.coValueClass.load(
|
|
@@ -5744,8 +5922,22 @@ var CoFeedSchema = class _CoFeedSchema {
|
|
|
5744
5922
|
* This resolve query will be used when no resolve query is provided to the load method.
|
|
5745
5923
|
*/
|
|
5746
5924
|
resolved(resolveQuery) {
|
|
5747
|
-
|
|
5748
|
-
|
|
5925
|
+
return this.copy({ resolveQuery });
|
|
5926
|
+
}
|
|
5927
|
+
/**
|
|
5928
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
5929
|
+
*/
|
|
5930
|
+
withPermissions(permissions) {
|
|
5931
|
+
return this.copy({ permissions });
|
|
5932
|
+
}
|
|
5933
|
+
copy({
|
|
5934
|
+
permissions,
|
|
5935
|
+
resolveQuery
|
|
5936
|
+
}) {
|
|
5937
|
+
const coreSchema = createCoreCoFeedSchema(this.element);
|
|
5938
|
+
const copy = hydrateCoreCoValueSchema(coreSchema);
|
|
5939
|
+
copy.resolveQuery = resolveQuery ?? this.resolveQuery;
|
|
5940
|
+
copy.permissions = permissions ?? this.permissions;
|
|
5749
5941
|
return copy;
|
|
5750
5942
|
}
|
|
5751
5943
|
};
|
|
@@ -5766,15 +5958,24 @@ function createCoreCoPlainTextSchema() {
|
|
|
5766
5958
|
resolveQuery: true
|
|
5767
5959
|
};
|
|
5768
5960
|
}
|
|
5769
|
-
var PlainTextSchema = class {
|
|
5961
|
+
var PlainTextSchema = class _PlainTextSchema {
|
|
5770
5962
|
constructor(coValueClass) {
|
|
5771
5963
|
this.coValueClass = coValueClass;
|
|
5772
5964
|
this.collaborative = true;
|
|
5773
5965
|
this.builtin = "CoPlainText";
|
|
5774
5966
|
this.resolveQuery = true;
|
|
5967
|
+
/**
|
|
5968
|
+
* Permissions to be used when creating or composing CoValues
|
|
5969
|
+
* @internal
|
|
5970
|
+
*/
|
|
5971
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5775
5972
|
}
|
|
5776
5973
|
create(text, options) {
|
|
5777
|
-
|
|
5974
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
5975
|
+
options,
|
|
5976
|
+
this.permissions
|
|
5977
|
+
);
|
|
5978
|
+
return this.coValueClass.create(text, optionsWithPermissions);
|
|
5778
5979
|
}
|
|
5779
5980
|
load(id, options) {
|
|
5780
5981
|
return this.coValueClass.load(id, options);
|
|
@@ -5794,6 +5995,14 @@ var PlainTextSchema = class {
|
|
|
5794
5995
|
optional() {
|
|
5795
5996
|
return coOptionalDefiner(this);
|
|
5796
5997
|
}
|
|
5998
|
+
/**
|
|
5999
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
6000
|
+
*/
|
|
6001
|
+
withPermissions(permissions) {
|
|
6002
|
+
const copy = new _PlainTextSchema(this.coValueClass);
|
|
6003
|
+
copy.permissions = permissions;
|
|
6004
|
+
return copy;
|
|
6005
|
+
}
|
|
5797
6006
|
};
|
|
5798
6007
|
|
|
5799
6008
|
// src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts
|
|
@@ -5804,21 +6013,42 @@ function createCoreFileStreamSchema() {
|
|
|
5804
6013
|
resolveQuery: true
|
|
5805
6014
|
};
|
|
5806
6015
|
}
|
|
5807
|
-
var FileStreamSchema = class {
|
|
6016
|
+
var FileStreamSchema = class _FileStreamSchema {
|
|
5808
6017
|
constructor(coValueClass) {
|
|
5809
6018
|
this.coValueClass = coValueClass;
|
|
5810
6019
|
this.collaborative = true;
|
|
5811
6020
|
this.builtin = "FileStream";
|
|
5812
6021
|
this.resolveQuery = true;
|
|
6022
|
+
/**
|
|
6023
|
+
* Permissions to be used when creating or composing CoValues
|
|
6024
|
+
*/
|
|
6025
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5813
6026
|
}
|
|
5814
6027
|
create(options) {
|
|
5815
|
-
|
|
6028
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
6029
|
+
options,
|
|
6030
|
+
this.permissions
|
|
6031
|
+
);
|
|
6032
|
+
return this.coValueClass.create(optionsWithPermissions);
|
|
5816
6033
|
}
|
|
5817
6034
|
createFromBlob(blob, options) {
|
|
5818
|
-
|
|
6035
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
6036
|
+
options,
|
|
6037
|
+
this.permissions
|
|
6038
|
+
);
|
|
6039
|
+
return this.coValueClass.createFromBlob(blob, optionsWithPermissions);
|
|
5819
6040
|
}
|
|
5820
|
-
createFromArrayBuffer(
|
|
5821
|
-
|
|
6041
|
+
createFromArrayBuffer(arrayBuffer, mimeType, fileName, options) {
|
|
6042
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
6043
|
+
options,
|
|
6044
|
+
this.permissions
|
|
6045
|
+
);
|
|
6046
|
+
return this.coValueClass.createFromArrayBuffer(
|
|
6047
|
+
arrayBuffer,
|
|
6048
|
+
mimeType,
|
|
6049
|
+
fileName,
|
|
6050
|
+
optionsWithPermissions
|
|
6051
|
+
);
|
|
5822
6052
|
}
|
|
5823
6053
|
loadAsBlob(id, options) {
|
|
5824
6054
|
return this.coValueClass.loadAsBlob(id, options);
|
|
@@ -5838,6 +6068,14 @@ var FileStreamSchema = class {
|
|
|
5838
6068
|
optional() {
|
|
5839
6069
|
return coOptionalDefiner(this);
|
|
5840
6070
|
}
|
|
6071
|
+
/**
|
|
6072
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
6073
|
+
*/
|
|
6074
|
+
withPermissions(permissions) {
|
|
6075
|
+
const copy = new _FileStreamSchema(this.coValueClass);
|
|
6076
|
+
copy.permissions = permissions;
|
|
6077
|
+
return copy;
|
|
6078
|
+
}
|
|
5841
6079
|
};
|
|
5842
6080
|
|
|
5843
6081
|
// src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts
|
|
@@ -5849,16 +6087,24 @@ function createCoreCoVectorSchema(dimensions) {
|
|
|
5849
6087
|
resolveQuery: true
|
|
5850
6088
|
};
|
|
5851
6089
|
}
|
|
5852
|
-
var CoVectorSchema = class {
|
|
6090
|
+
var CoVectorSchema = class _CoVectorSchema {
|
|
5853
6091
|
constructor(dimensions, coValueClass) {
|
|
5854
6092
|
this.dimensions = dimensions;
|
|
5855
6093
|
this.coValueClass = coValueClass;
|
|
5856
6094
|
this.collaborative = true;
|
|
5857
6095
|
this.builtin = "CoVector";
|
|
5858
6096
|
this.resolveQuery = true;
|
|
6097
|
+
/**
|
|
6098
|
+
* Permissions to be used when creating or composing CoValues
|
|
6099
|
+
*/
|
|
6100
|
+
this.permissions = DEFAULT_SCHEMA_PERMISSIONS;
|
|
5859
6101
|
}
|
|
5860
6102
|
create(vector, options) {
|
|
5861
|
-
|
|
6103
|
+
const optionsWithPermissions = withSchemaPermissions(
|
|
6104
|
+
options,
|
|
6105
|
+
this.permissions
|
|
6106
|
+
);
|
|
6107
|
+
return this.coValueClass.create(vector, optionsWithPermissions);
|
|
5862
6108
|
}
|
|
5863
6109
|
/**
|
|
5864
6110
|
* Load a `CoVector` with a given ID.
|
|
@@ -5875,6 +6121,14 @@ var CoVectorSchema = class {
|
|
|
5875
6121
|
optional() {
|
|
5876
6122
|
return coOptionalDefiner(this);
|
|
5877
6123
|
}
|
|
6124
|
+
/**
|
|
6125
|
+
* Configure permissions to be used when creating or composing CoValues
|
|
6126
|
+
*/
|
|
6127
|
+
withPermissions(permissions) {
|
|
6128
|
+
const copy = new _CoVectorSchema(this.dimensions, this.coValueClass);
|
|
6129
|
+
copy.permissions = permissions;
|
|
6130
|
+
return copy;
|
|
6131
|
+
}
|
|
5878
6132
|
};
|
|
5879
6133
|
|
|
5880
6134
|
// src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
|
|
@@ -5958,6 +6212,7 @@ function createCoreAccountSchema(shape) {
|
|
|
5958
6212
|
}
|
|
5959
6213
|
|
|
5960
6214
|
// src/tools/implementation/zodSchema/unionUtils.ts
|
|
6215
|
+
import { RawCoMap as RawCoMap3 } from "cojson";
|
|
5961
6216
|
function schemaUnionDiscriminatorFor(schema) {
|
|
5962
6217
|
if (isUnionOfCoMapsDeeply(schema)) {
|
|
5963
6218
|
const definition = schema.getDefinition();
|
|
@@ -5975,22 +6230,7 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
|
5975
6230
|
);
|
|
5976
6231
|
}
|
|
5977
6232
|
}
|
|
5978
|
-
const availableOptions =
|
|
5979
|
-
for (const option of options) {
|
|
5980
|
-
if (option.builtin === "CoMap") {
|
|
5981
|
-
availableOptions.push(option);
|
|
5982
|
-
} else if (option.builtin === "CoDiscriminatedUnion") {
|
|
5983
|
-
for (const subOption of option.getDefinition().options) {
|
|
5984
|
-
if (!options.includes(subOption)) {
|
|
5985
|
-
options.push(subOption);
|
|
5986
|
-
}
|
|
5987
|
-
}
|
|
5988
|
-
} else {
|
|
5989
|
-
throw new Error(
|
|
5990
|
-
"Unsupported zod type in co.discriminatedUnion() of collaborative types"
|
|
5991
|
-
);
|
|
5992
|
-
}
|
|
5993
|
-
}
|
|
6233
|
+
const availableOptions = getFlattenedUnionOptions(schema);
|
|
5994
6234
|
const determineSchema = (discriminable) => {
|
|
5995
6235
|
const allNestedRefKeys = /* @__PURE__ */ new Set();
|
|
5996
6236
|
for (const option of availableOptions) {
|
|
@@ -6006,7 +6246,10 @@ function schemaUnionDiscriminatorFor(schema) {
|
|
|
6006
6246
|
const optionDef = option.getDefinition();
|
|
6007
6247
|
for (const key of Object.keys(discriminatorMap)) {
|
|
6008
6248
|
const discriminatorDef = optionDef.shape[key];
|
|
6009
|
-
const discriminatorValue =
|
|
6249
|
+
const discriminatorValue = resolveDiscriminantValue(
|
|
6250
|
+
discriminable,
|
|
6251
|
+
key
|
|
6252
|
+
);
|
|
6010
6253
|
if (discriminatorValue && typeof discriminatorValue === "object") {
|
|
6011
6254
|
throw new Error("Discriminator must be a primitive value");
|
|
6012
6255
|
}
|
|
@@ -6076,6 +6319,49 @@ function isUnionOfPrimitivesDeeply(schema) {
|
|
|
6076
6319
|
return !isAnyCoValueSchema2(schema);
|
|
6077
6320
|
}
|
|
6078
6321
|
}
|
|
6322
|
+
function getFlattenedUnionOptions(schema) {
|
|
6323
|
+
const definition = schema.getDefinition();
|
|
6324
|
+
const options = definition.options;
|
|
6325
|
+
const availableOptions = [];
|
|
6326
|
+
for (const option of options) {
|
|
6327
|
+
if (option.builtin === "CoMap") {
|
|
6328
|
+
availableOptions.push(option);
|
|
6329
|
+
} else if (option.builtin === "CoDiscriminatedUnion") {
|
|
6330
|
+
const nestedOptions = getFlattenedUnionOptions(
|
|
6331
|
+
option
|
|
6332
|
+
);
|
|
6333
|
+
for (const subOption of nestedOptions) {
|
|
6334
|
+
if (!availableOptions.includes(subOption)) {
|
|
6335
|
+
availableOptions.push(subOption);
|
|
6336
|
+
}
|
|
6337
|
+
}
|
|
6338
|
+
} else {
|
|
6339
|
+
throw new Error(
|
|
6340
|
+
"Unsupported zod type in co.discriminatedUnion() of collaborative types"
|
|
6341
|
+
);
|
|
6342
|
+
}
|
|
6343
|
+
}
|
|
6344
|
+
return availableOptions;
|
|
6345
|
+
}
|
|
6346
|
+
function getDiscriminatorValuesForOption(option, discriminatorKey) {
|
|
6347
|
+
const optionDefinition = option.getDefinition();
|
|
6348
|
+
return optionDefinition.discriminatorMap?.[discriminatorKey];
|
|
6349
|
+
}
|
|
6350
|
+
function resolveDiscriminantValue(init, discriminatorKey) {
|
|
6351
|
+
if (init == null) {
|
|
6352
|
+
return void 0;
|
|
6353
|
+
}
|
|
6354
|
+
if (init instanceof Map || init instanceof RawCoMap3) {
|
|
6355
|
+
return init.get(discriminatorKey);
|
|
6356
|
+
}
|
|
6357
|
+
if (typeof init === "object") {
|
|
6358
|
+
const record2 = init;
|
|
6359
|
+
if (discriminatorKey in record2) {
|
|
6360
|
+
return record2[discriminatorKey];
|
|
6361
|
+
}
|
|
6362
|
+
}
|
|
6363
|
+
return void 0;
|
|
6364
|
+
}
|
|
6079
6365
|
|
|
6080
6366
|
// src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts
|
|
6081
6367
|
function makeCodecCoField(codec2) {
|
|
@@ -6106,17 +6392,28 @@ function schemaFieldToCoFieldDef(schema) {
|
|
|
6106
6392
|
return cachedCoFieldDef;
|
|
6107
6393
|
}
|
|
6108
6394
|
if (isCoValueClass(schema)) {
|
|
6109
|
-
return cacheSchemaField(
|
|
6395
|
+
return cacheSchemaField(
|
|
6396
|
+
schema,
|
|
6397
|
+
coField.ref(schema, {
|
|
6398
|
+
permissions: getDefaultRefPermissions()
|
|
6399
|
+
})
|
|
6400
|
+
);
|
|
6110
6401
|
} else if (isCoValueSchema(schema)) {
|
|
6111
6402
|
if (schema.builtin === "CoOptional") {
|
|
6112
6403
|
return cacheSchemaField(
|
|
6113
6404
|
schema,
|
|
6114
6405
|
coField.ref(schema.getCoValueClass(), {
|
|
6115
|
-
optional: true
|
|
6406
|
+
optional: true,
|
|
6407
|
+
permissions: schemaFieldPermissions(schema)
|
|
6116
6408
|
})
|
|
6117
6409
|
);
|
|
6118
6410
|
}
|
|
6119
|
-
return cacheSchemaField(
|
|
6411
|
+
return cacheSchemaField(
|
|
6412
|
+
schema,
|
|
6413
|
+
coField.ref(schema.getCoValueClass(), {
|
|
6414
|
+
permissions: schemaFieldPermissions(schema)
|
|
6415
|
+
})
|
|
6416
|
+
);
|
|
6120
6417
|
} else {
|
|
6121
6418
|
if ("_zod" in schema) {
|
|
6122
6419
|
const zodSchemaDef = schema._zod.def;
|
|
@@ -6222,6 +6519,55 @@ function schemaFieldToCoFieldDef(schema) {
|
|
|
6222
6519
|
}
|
|
6223
6520
|
}
|
|
6224
6521
|
}
|
|
6522
|
+
function schemaFieldPermissions(schema) {
|
|
6523
|
+
if (schema.builtin === "CoOptional") {
|
|
6524
|
+
return schemaFieldPermissions(schema.innerType);
|
|
6525
|
+
}
|
|
6526
|
+
if (schema.builtin === "CoDiscriminatedUnion") {
|
|
6527
|
+
return discriminatedUnionFieldPermissions(
|
|
6528
|
+
schema
|
|
6529
|
+
);
|
|
6530
|
+
}
|
|
6531
|
+
return "permissions" in schema ? schemaToRefPermissions(schema.permissions) : getDefaultRefPermissions();
|
|
6532
|
+
}
|
|
6533
|
+
function discriminatedUnionFieldPermissions(schema) {
|
|
6534
|
+
const discriminatorKey = schema.getDefinition().discriminator;
|
|
6535
|
+
const allOptions = getFlattenedUnionOptions(schema);
|
|
6536
|
+
const valueToStrategy = /* @__PURE__ */ new Map();
|
|
6537
|
+
for (const option of allOptions) {
|
|
6538
|
+
const optionPermissions = schemaFieldPermissions(option);
|
|
6539
|
+
const discriminatorValues = getDiscriminatorValuesForOption(
|
|
6540
|
+
option,
|
|
6541
|
+
discriminatorKey
|
|
6542
|
+
);
|
|
6543
|
+
if (!discriminatorValues) {
|
|
6544
|
+
continue;
|
|
6545
|
+
}
|
|
6546
|
+
for (const value of discriminatorValues) {
|
|
6547
|
+
if (!valueToStrategy.has(value)) {
|
|
6548
|
+
valueToStrategy.set(value, optionPermissions);
|
|
6549
|
+
}
|
|
6550
|
+
}
|
|
6551
|
+
}
|
|
6552
|
+
const fallbackStrategy = getDefaultRefPermissions();
|
|
6553
|
+
const newInlineOwnerStrategy = (createNewGroup, containerOwner, init) => {
|
|
6554
|
+
const discriminantValue = resolveDiscriminantValue(init, discriminatorKey);
|
|
6555
|
+
const strategy = discriminantValue !== void 0 ? valueToStrategy.get(discriminantValue) : void 0;
|
|
6556
|
+
const effectiveStrategy = strategy ?? fallbackStrategy;
|
|
6557
|
+
return effectiveStrategy.newInlineOwnerStrategy(
|
|
6558
|
+
createNewGroup,
|
|
6559
|
+
containerOwner,
|
|
6560
|
+
init
|
|
6561
|
+
);
|
|
6562
|
+
};
|
|
6563
|
+
const onCreate = (newGroup, init) => {
|
|
6564
|
+
const discriminantValue = resolveDiscriminantValue(init, discriminatorKey);
|
|
6565
|
+
const strategy = discriminantValue !== void 0 ? valueToStrategy.get(discriminantValue) : void 0;
|
|
6566
|
+
const effectiveStrategy = strategy ?? fallbackStrategy;
|
|
6567
|
+
effectiveStrategy.onCreate?.(newGroup, init);
|
|
6568
|
+
};
|
|
6569
|
+
return { newInlineOwnerStrategy, onCreate };
|
|
6570
|
+
}
|
|
6225
6571
|
|
|
6226
6572
|
// src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts
|
|
6227
6573
|
function isAnyCoValueSchema2(schema) {
|
|
@@ -7162,20 +7508,28 @@ function isAccountInstance(instance) {
|
|
|
7162
7508
|
return TypeSym in instance && instance[TypeSym] === "Account";
|
|
7163
7509
|
}
|
|
7164
7510
|
function parseCoValueCreateOptions(options) {
|
|
7165
|
-
const
|
|
7511
|
+
const onCreate = options && "onCreate" in options ? options.onCreate : void 0;
|
|
7512
|
+
const Group18 = RegisteredSchemas["Group"];
|
|
7166
7513
|
if (!options) {
|
|
7167
|
-
|
|
7514
|
+
const owner2 = Group18.create();
|
|
7515
|
+
onCreate?.(owner2);
|
|
7516
|
+
return { owner: owner2, uniqueness: void 0 };
|
|
7168
7517
|
}
|
|
7169
7518
|
if (TypeSym in options) {
|
|
7170
7519
|
if (options[TypeSym] === "Account") {
|
|
7171
|
-
|
|
7520
|
+
const owner2 = accountOrGroupToGroup(options);
|
|
7521
|
+
onCreate?.(owner2);
|
|
7522
|
+
return { owner: owner2, uniqueness: void 0 };
|
|
7172
7523
|
} else if (options[TypeSym] === "Group") {
|
|
7524
|
+
onCreate?.(options);
|
|
7173
7525
|
return { owner: options, uniqueness: void 0 };
|
|
7174
7526
|
}
|
|
7175
7527
|
}
|
|
7176
7528
|
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
|
7529
|
+
const owner = options.owner ? accountOrGroupToGroup(options.owner) : Group18.create();
|
|
7530
|
+
onCreate?.(owner);
|
|
7177
7531
|
const opts = {
|
|
7178
|
-
owner
|
|
7532
|
+
owner,
|
|
7179
7533
|
uniqueness
|
|
7180
7534
|
};
|
|
7181
7535
|
return opts;
|
|
@@ -7412,11 +7766,12 @@ export {
|
|
|
7412
7766
|
setCustomErrorReporter,
|
|
7413
7767
|
captureStack,
|
|
7414
7768
|
SubscriptionScope,
|
|
7415
|
-
|
|
7769
|
+
MockSessionProvider,
|
|
7416
7770
|
createJazzContextFromExistingCredentials,
|
|
7417
7771
|
createJazzContextForNewAccount,
|
|
7418
7772
|
createJazzContext,
|
|
7419
7773
|
createAnonymousJazzContext,
|
|
7774
|
+
setDefaultSchemaPermissions,
|
|
7420
7775
|
coMapDefiner,
|
|
7421
7776
|
coExport_exports,
|
|
7422
7777
|
coValueClassFromCoValueClassOrSchema,
|
|
@@ -7427,4 +7782,4 @@ export {
|
|
|
7427
7782
|
JazzContextManager
|
|
7428
7783
|
};
|
|
7429
7784
|
/* istanbul ignore file -- @preserve */
|
|
7430
|
-
//# sourceMappingURL=chunk-
|
|
7785
|
+
//# sourceMappingURL=chunk-GAPMDNJY.js.map
|