jazz-tools 0.17.14 → 0.18.1
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.js +1 -1
- package/.svelte-kit/__package__/media/image.svelte +3 -9
- package/.svelte-kit/__package__/media/image.svelte.d.ts +1 -6
- package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/media/image.types.d.ts +7 -0
- package/.svelte-kit/__package__/media/image.types.d.ts.map +1 -0
- package/.svelte-kit/__package__/media/image.types.js +1 -0
- package/.svelte-kit/__package__/tests/media/image.svelte.test.js +31 -31
- package/.turbo/turbo-build.log +60 -46
- package/CHANGELOG.md +41 -0
- package/dist/better-auth/auth/client.d.ts +29 -0
- package/dist/better-auth/auth/client.d.ts.map +1 -0
- package/dist/better-auth/auth/client.js +127 -0
- package/dist/better-auth/auth/client.js.map +1 -0
- package/dist/better-auth/auth/react.d.ts +2170 -0
- package/dist/better-auth/auth/react.d.ts.map +1 -0
- package/dist/better-auth/auth/react.js +40 -0
- package/dist/better-auth/auth/react.js.map +1 -0
- package/dist/better-auth/auth/server.d.ts +14 -0
- package/dist/better-auth/auth/server.d.ts.map +1 -0
- package/dist/better-auth/auth/server.js +198 -0
- package/dist/better-auth/auth/server.js.map +1 -0
- package/dist/better-auth/auth/tests/client.test.d.ts +2 -0
- package/dist/better-auth/auth/tests/client.test.d.ts.map +1 -0
- package/dist/better-auth/auth/tests/server.test.d.ts +2 -0
- package/dist/better-auth/auth/tests/server.test.d.ts.map +1 -0
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/{chunk-LZOF6WP5.js → chunk-IERUTUXB.js} +1336 -1017
- package/dist/chunk-IERUTUXB.js.map +1 -0
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
- package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
- package/dist/inspector/index.js +1 -1
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
- package/dist/media/chunk-KR2V6X2N.js.map +1 -0
- package/dist/media/create-image.d.ts +6 -6
- package/dist/media/index.browser.d.ts +6 -6
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.d.ts +6 -6
- package/dist/media/index.native.js +1 -1
- package/dist/media/utils.d.ts.map +1 -1
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/index.js.map +1 -1
- package/dist/react/index.js +7 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +4675 -23
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-native-core/index.js +1 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +1 -1
- package/dist/svelte/media/image.svelte +3 -9
- package/dist/svelte/media/image.svelte.d.ts +1 -6
- package/dist/svelte/media/image.svelte.d.ts.map +1 -1
- package/dist/svelte/media/image.types.d.ts +7 -0
- package/dist/svelte/media/image.types.d.ts.map +1 -0
- package/dist/svelte/media/image.types.js +1 -0
- package/dist/svelte/tests/media/image.svelte.test.js +31 -31
- package/dist/testing.js +18 -14
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
- package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
- package/dist/tools/coValues/CoValueBase.d.ts +18 -15
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +101 -46
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +78 -62
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +212 -99
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +210 -192
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coPlainText.d.ts +30 -22
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +13 -13
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
- package/dist/tools/coValues/group.d.ts +32 -32
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +18 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/profile.d.ts +6 -5
- package/dist/tools/coValues/profile.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +3 -3
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +5 -5
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/symbols.d.ts +2 -0
- package/dist/tools/implementation/symbols.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts +3 -3
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +2 -1
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/migration.d.ts +1 -1
- package/dist/tools/lib/migration.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts +1 -1
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +2 -2
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/utils.d.ts +2 -6
- package/dist/tools/tests/utils.d.ts.map +1 -1
- package/dist/worker/index.js +3 -3
- package/dist/worker/index.js.map +1 -1
- package/package.json +23 -4
- package/src/better-auth/auth/client.ts +169 -0
- package/src/better-auth/auth/react.tsx +105 -0
- package/src/better-auth/auth/server.ts +250 -0
- package/src/better-auth/auth/tests/client.test.ts +249 -0
- package/src/better-auth/auth/tests/server.test.ts +226 -0
- package/src/browser/auth/PasskeyAuth.ts +2 -2
- package/src/browser/createBrowserContext.ts +2 -2
- package/src/browser/tests/PasskeyAuth.test.ts +2 -2
- package/src/inspector/custom-element.tsx +2 -2
- package/src/inspector/viewer/new-app.tsx +1 -1
- package/src/media/create-image.test.ts +7 -7
- package/src/media/create-image.ts +5 -3
- package/src/media/index.ts +1 -1
- package/src/media/utils.test.ts +72 -66
- package/src/media/utils.ts +9 -6
- package/src/prosemirror/lib/plugin.ts +1 -1
- package/src/prosemirror/lib/sync.ts +1 -1
- package/src/prosemirror/tests/plugin.test.ts +4 -4
- package/src/react/media/image.tsx +2 -2
- package/src/react/tests/media/image.test.tsx +52 -32
- package/src/react-core/hooks.ts +11 -5
- package/src/react-core/tests/useAccount.test.ts +16 -22
- package/src/react-core/tests/useCoState.test.ts +19 -19
- package/src/react-core/tests/useInboxSender.test.ts +5 -2
- package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
- package/src/react-native-core/media/image.tsx +1 -1
- package/src/svelte/jazz.class.svelte.ts +1 -1
- package/src/svelte/media/image.svelte +3 -9
- package/src/svelte/media/image.types.ts +7 -0
- package/src/svelte/tests/media/image.svelte.test.ts +34 -32
- package/src/tools/auth/DemoAuth.ts +2 -2
- package/src/tools/auth/PassphraseAuth.ts +2 -2
- package/src/tools/auth/clerk/index.ts +2 -2
- package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
- package/src/tools/coValues/CoFieldInit.ts +20 -0
- package/src/tools/coValues/CoValueBase.ts +40 -60
- package/src/tools/coValues/account.ts +311 -232
- package/src/tools/coValues/coFeed.ts +185 -153
- package/src/tools/coValues/coList.ts +507 -334
- package/src/tools/coValues/coMap.ts +434 -286
- package/src/tools/coValues/coPlainText.ts +94 -110
- package/src/tools/coValues/deepLoading.ts +13 -13
- package/src/tools/coValues/group.ts +100 -114
- package/src/tools/coValues/inbox.ts +16 -14
- package/src/tools/coValues/interfaces.ts +49 -31
- package/src/tools/coValues/profile.ts +8 -6
- package/src/tools/coValues/request.ts +9 -9
- package/src/tools/coValues/schemaUnion.ts +11 -5
- package/src/tools/exports.ts +1 -1
- package/src/tools/implementation/ContextManager.ts +4 -4
- package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
- package/src/tools/implementation/createContext.ts +1 -1
- package/src/tools/implementation/devtoolsFormatters.ts +9 -9
- package/src/tools/implementation/invites.ts +2 -2
- package/src/tools/implementation/schema.ts +7 -7
- package/src/tools/implementation/symbols.ts +3 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
- package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
- package/src/tools/implementation/zodSchema/zodCo.ts +3 -3
- package/src/tools/internal.ts +2 -1
- package/src/tools/lib/migration.ts +5 -5
- package/src/tools/subscribe/SubscriptionScope.ts +32 -24
- package/src/tools/subscribe/index.ts +4 -4
- package/src/tools/subscribe/utils.ts +11 -11
- package/src/tools/testing.ts +17 -13
- package/src/tools/tests/ContextManager.test.ts +70 -59
- package/src/tools/tests/PassphraseAuth.test.ts +2 -2
- package/src/tools/tests/account.test.ts +188 -67
- package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
- package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
- package/src/tools/tests/coFeed.test-d.ts +18 -17
- package/src/tools/tests/coFeed.test.ts +108 -97
- package/src/tools/tests/coList.test-d.ts +18 -23
- package/src/tools/tests/coList.test.ts +350 -165
- package/src/tools/tests/coMap.record.test-d.ts +9 -13
- package/src/tools/tests/coMap.record.test.ts +37 -23
- package/src/tools/tests/coMap.test-d.ts +43 -21
- package/src/tools/tests/coMap.test.ts +459 -182
- package/src/tools/tests/coOptional.test.ts +28 -13
- package/src/tools/tests/coPlainText.test.ts +15 -15
- package/src/tools/tests/createContext.test.ts +14 -14
- package/src/tools/tests/deepLoading.test.ts +95 -94
- package/src/tools/tests/exportImport.test.ts +61 -41
- package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
- package/src/tools/tests/inbox.test.ts +22 -17
- package/src/tools/tests/interfaces.test.ts +12 -11
- package/src/tools/tests/invites.test.ts +6 -4
- package/src/tools/tests/load.test.ts +20 -18
- package/src/tools/tests/patterns/notifications.test.ts +7 -7
- package/src/tools/tests/patterns/quest.test.ts +3 -3
- package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
- package/src/tools/tests/request.test.ts +38 -39
- package/src/tools/tests/schemaUnion.test.ts +64 -10
- package/src/tools/tests/subscribe.test.ts +64 -64
- package/src/tools/tests/testing.test.ts +7 -11
- package/src/tools/tests/utils.ts +3 -3
- package/src/tools/tests/zod.test.ts +3 -3
- package/src/worker/index.ts +3 -3
- package/tsup.config.ts +9 -0
- package/dist/chunk-LZOF6WP5.js.map +0 -1
- package/dist/media/chunk-E5J3WLQW.js.map +0 -1
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +0 -1
@@ -119,35 +119,8 @@ function isAnyCoValueSchema(schema) {
|
|
119
119
|
}
|
120
120
|
|
121
121
|
// src/tools/coValues/CoValueBase.ts
|
122
|
-
import { ControlledAccount
|
122
|
+
import { ControlledAccount } from "cojson";
|
123
123
|
var CoValueBase = class {
|
124
|
-
get _owner() {
|
125
|
-
const schema = this._raw.group instanceof RawAccount ? RegisteredSchemas["Account"] : RegisteredSchemas["Group"];
|
126
|
-
return accessChildById(this, this._raw.group.id, {
|
127
|
-
ref: schema,
|
128
|
-
optional: false
|
129
|
-
});
|
130
|
-
}
|
131
|
-
/** @private */
|
132
|
-
get _loadedAs() {
|
133
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
134
|
-
if (agent instanceof ControlledAccount) {
|
135
|
-
return coValuesCache.get(
|
136
|
-
agent.account,
|
137
|
-
() => coValueClassFromCoValueClassOrSchema(
|
138
|
-
RegisteredSchemas["Account"]
|
139
|
-
).fromRaw(agent.account)
|
140
|
-
);
|
141
|
-
}
|
142
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
143
|
-
}
|
144
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
145
|
-
constructor(..._args) {
|
146
|
-
Object.defineProperty(this, "_instanceID", {
|
147
|
-
value: `instance-${Math.random().toString(36).slice(2)}`,
|
148
|
-
enumerable: false
|
149
|
-
});
|
150
|
-
}
|
151
124
|
/** @category Internals */
|
152
125
|
static fromRaw(raw) {
|
153
126
|
return new this({ fromRaw: raw });
|
@@ -155,21 +128,39 @@ var CoValueBase = class {
|
|
155
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
156
129
|
toJSON() {
|
157
130
|
return {
|
158
|
-
id: this.id,
|
159
|
-
type: this
|
131
|
+
id: this.$jazz.id,
|
132
|
+
type: this[TypeSym],
|
160
133
|
error: "unknown CoValue class"
|
161
134
|
};
|
162
135
|
}
|
163
136
|
[inspect]() {
|
164
137
|
return this.toJSON();
|
165
138
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
139
|
+
};
|
140
|
+
var CoValueJazzApi = class {
|
141
|
+
constructor(coValue) {
|
142
|
+
this.coValue = coValue;
|
143
|
+
Object.defineProperty(this, "_instanceID", {
|
144
|
+
value: `instance-${Math.random().toString(36).slice(2)}`,
|
145
|
+
enumerable: false
|
146
|
+
});
|
147
|
+
}
|
148
|
+
/** @internal */
|
149
|
+
get localNode() {
|
150
|
+
return this.raw.core.node;
|
151
|
+
}
|
152
|
+
/** @private */
|
153
|
+
get loadedAs() {
|
154
|
+
const agent = this.localNode.getCurrentAgent();
|
155
|
+
if (agent instanceof ControlledAccount) {
|
156
|
+
return coValuesCache.get(
|
157
|
+
agent.account,
|
158
|
+
() => coValueClassFromCoValueClassOrSchema(
|
159
|
+
RegisteredSchemas["Account"]
|
160
|
+
).fromRaw(agent.account)
|
161
|
+
);
|
171
162
|
}
|
172
|
-
return
|
163
|
+
return new AnonymousJazzAgent(this.localNode);
|
173
164
|
}
|
174
165
|
};
|
175
166
|
|
@@ -179,6 +170,7 @@ var inspect = Symbol.for("nodejs.util.inspect.custom");
|
|
179
170
|
// src/tools/implementation/symbols.ts
|
180
171
|
var SchemaInit = "$SchemaInit$";
|
181
172
|
var ItemsSym = "$items$";
|
173
|
+
var TypeSym = "$type$";
|
182
174
|
|
183
175
|
// src/tools/coValues/registeredSchemas.ts
|
184
176
|
var RegisteredSchemas = {};
|
@@ -188,125 +180,23 @@ import {
|
|
188
180
|
cojsonInternals
|
189
181
|
} from "cojson";
|
190
182
|
var _CoMap = class _CoMap extends CoValueBase {
|
191
|
-
/** @internal */
|
192
|
-
get _schema() {
|
193
|
-
return this.constructor._schema;
|
194
|
-
}
|
195
|
-
/**
|
196
|
-
* The timestamp of the creation time of the CoMap
|
197
|
-
*/
|
198
|
-
get _createdAt() {
|
199
|
-
return this._raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
|
200
|
-
}
|
201
|
-
/**
|
202
|
-
* The timestamp of the last updated time of the CoMap
|
203
|
-
*/
|
204
|
-
get _lastUpdatedAt() {
|
205
|
-
return this._raw.latestTxMadeAt;
|
206
|
-
}
|
207
|
-
/**
|
208
|
-
* If property `prop` is a `coField.ref(...)`, you can use `coMaps._refs.prop` to access
|
209
|
-
* the `Ref` instead of the potentially loaded/null value.
|
210
|
-
*
|
211
|
-
* This allows you to always get the ID or load the value manually.
|
212
|
-
*
|
213
|
-
* @example
|
214
|
-
* ```ts
|
215
|
-
* person._refs.pet.id; // => ID<Animal>
|
216
|
-
* person._refs.pet.value;
|
217
|
-
* // => Animal | null
|
218
|
-
* const pet = await person._refs.pet.load();
|
219
|
-
* ```
|
220
|
-
*
|
221
|
-
* @category Content
|
222
|
-
**/
|
223
|
-
get _refs() {
|
224
|
-
return makeRefs(
|
225
|
-
this,
|
226
|
-
(key) => this._raw.get(key),
|
227
|
-
() => {
|
228
|
-
const keys = this._raw.keys().filter((key) => {
|
229
|
-
const descriptor = this.getDescriptor(key);
|
230
|
-
return descriptor && descriptor !== "json" && isRefEncoded(descriptor);
|
231
|
-
});
|
232
|
-
return keys;
|
233
|
-
},
|
234
|
-
this._loadedAs,
|
235
|
-
(key) => this.getDescriptor(key)
|
236
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
237
|
-
);
|
238
|
-
}
|
239
|
-
/** @internal */
|
240
|
-
getEditFromRaw(target, rawEdit, descriptor, key) {
|
241
|
-
return {
|
242
|
-
value: descriptor === "json" ? rawEdit.value : "encoded" in descriptor ? rawEdit.value === null || rawEdit.value === void 0 ? rawEdit.value : descriptor.encoded.decode(rawEdit.value) : accessChildById(target, rawEdit.value, descriptor),
|
243
|
-
ref: descriptor !== "json" && isRefEncoded(descriptor) ? new Ref(
|
244
|
-
rawEdit.value,
|
245
|
-
target._loadedAs,
|
246
|
-
descriptor,
|
247
|
-
target
|
248
|
-
) : void 0,
|
249
|
-
get by() {
|
250
|
-
return rawEdit.by && accessChildById(target, rawEdit.by, {
|
251
|
-
ref: Account,
|
252
|
-
optional: false
|
253
|
-
});
|
254
|
-
},
|
255
|
-
madeAt: rawEdit.at,
|
256
|
-
key
|
257
|
-
};
|
258
|
-
}
|
259
|
-
/** @category Collaboration */
|
260
|
-
get _edits() {
|
261
|
-
const map = this;
|
262
|
-
return new Proxy(
|
263
|
-
{},
|
264
|
-
{
|
265
|
-
get(_target, key) {
|
266
|
-
const rawEdit = map._raw.lastEditAt(key);
|
267
|
-
if (!rawEdit) return void 0;
|
268
|
-
const descriptor = map.getDescriptor(key);
|
269
|
-
if (!descriptor) return void 0;
|
270
|
-
return {
|
271
|
-
...map.getEditFromRaw(map, rawEdit, descriptor, key),
|
272
|
-
get all() {
|
273
|
-
return [...map._raw.editsAt(key)].map(
|
274
|
-
(rawEdit2) => map.getEditFromRaw(map, rawEdit2, descriptor, key)
|
275
|
-
);
|
276
|
-
}
|
277
|
-
};
|
278
|
-
},
|
279
|
-
ownKeys(_target) {
|
280
|
-
return map._raw.keys();
|
281
|
-
},
|
282
|
-
getOwnPropertyDescriptor(target, key) {
|
283
|
-
return {
|
284
|
-
value: Reflect.get(target, key),
|
285
|
-
writable: false,
|
286
|
-
enumerable: true,
|
287
|
-
configurable: true
|
288
|
-
};
|
289
|
-
}
|
290
|
-
}
|
291
|
-
);
|
292
|
-
}
|
293
183
|
/** @internal */
|
294
184
|
constructor(options) {
|
295
185
|
super();
|
186
|
+
const proxy = new Proxy(this, CoMapProxyHandler);
|
296
187
|
if (options) {
|
297
188
|
if ("fromRaw" in options) {
|
298
189
|
Object.defineProperties(this, {
|
299
|
-
|
300
|
-
value: options.fromRaw
|
190
|
+
$jazz: {
|
191
|
+
value: new CoMapJazzApi(proxy, () => options.fromRaw),
|
301
192
|
enumerable: false
|
302
|
-
}
|
303
|
-
_raw: { value: options.fromRaw, enumerable: false }
|
193
|
+
}
|
304
194
|
});
|
305
195
|
} else {
|
306
196
|
throw new Error("Invalid CoMap constructor arguments");
|
307
197
|
}
|
308
198
|
}
|
309
|
-
return
|
199
|
+
return proxy;
|
310
200
|
}
|
311
201
|
/**
|
312
202
|
* Create a new CoMap with the given initial values and owner.
|
@@ -325,10 +215,12 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
325
215
|
* ```
|
326
216
|
*
|
327
217
|
* @category Creation
|
218
|
+
*
|
219
|
+
* @deprecated Use `co.map(...).create`.
|
328
220
|
**/
|
329
221
|
static create(init, options) {
|
330
222
|
const instance = new this();
|
331
|
-
return
|
223
|
+
return _CoMap._createCoMap(instance, init, options);
|
332
224
|
}
|
333
225
|
/**
|
334
226
|
* Return a JSON representation of the `CoMap`
|
@@ -336,21 +228,18 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
336
228
|
*/
|
337
229
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
338
230
|
toJSON(_key, processedValues) {
|
339
|
-
const result = {
|
340
|
-
|
341
|
-
_type: this._type
|
342
|
-
};
|
343
|
-
for (const key of this._raw.keys()) {
|
231
|
+
const result = {};
|
232
|
+
for (const key of this.$jazz.raw.keys()) {
|
344
233
|
const tKey = key;
|
345
|
-
const descriptor = this.getDescriptor(tKey);
|
234
|
+
const descriptor = this.$jazz.getDescriptor(tKey);
|
346
235
|
if (!descriptor) {
|
347
236
|
continue;
|
348
237
|
}
|
349
238
|
if (descriptor == "json" || "encoded" in descriptor) {
|
350
|
-
result[key] = this.
|
239
|
+
result[key] = this.$jazz.raw.get(key);
|
351
240
|
} else if (isRefEncoded(descriptor)) {
|
352
|
-
const id = this.
|
353
|
-
if (processedValues?.includes(id) || id === this.id) {
|
241
|
+
const id = this.$jazz.raw.get(key);
|
242
|
+
if (processedValues?.includes(id) || id === this.$jazz.id) {
|
354
243
|
result[key] = { _circular: id };
|
355
244
|
continue;
|
356
245
|
}
|
@@ -358,7 +247,7 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
358
247
|
if (ref2 && typeof ref2 === "object" && "toJSON" in ref2 && typeof ref2.toJSON === "function") {
|
359
248
|
const jsonedRef = ref2.toJSON(tKey, [
|
360
249
|
...processedValues || [],
|
361
|
-
this.id
|
250
|
+
this.$jazz.id
|
362
251
|
]);
|
363
252
|
result[key] = jsonedRef;
|
364
253
|
}
|
@@ -371,30 +260,31 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
371
260
|
[inspect]() {
|
372
261
|
return this.toJSON();
|
373
262
|
}
|
374
|
-
|
263
|
+
/**
|
264
|
+
* @internal
|
265
|
+
*/
|
266
|
+
static _createCoMap(instance, init, options) {
|
375
267
|
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
value: raw.id,
|
268
|
+
Object.defineProperties(instance, {
|
269
|
+
$jazz: {
|
270
|
+
value: new CoMapJazzApi(instance, () => raw),
|
380
271
|
enumerable: false
|
381
|
-
}
|
382
|
-
_raw: { value: raw, enumerable: false }
|
272
|
+
}
|
383
273
|
});
|
384
|
-
|
274
|
+
const raw = _CoMap.rawFromInit(instance, init, owner, uniqueness);
|
275
|
+
return instance;
|
385
276
|
}
|
386
277
|
/**
|
387
278
|
* Create a new `RawCoMap` from an initialization object
|
388
279
|
* @internal
|
389
280
|
*/
|
390
|
-
|
391
|
-
|
392
|
-
const rawOwner = owner._raw;
|
281
|
+
static rawFromInit(instance, init, owner, uniqueness) {
|
282
|
+
const rawOwner = owner.$jazz.raw;
|
393
283
|
const rawInit = {};
|
394
284
|
if (init)
|
395
285
|
for (const key of Object.keys(init)) {
|
396
286
|
const initValue = init[key];
|
397
|
-
const descriptor =
|
287
|
+
const descriptor = instance.$jazz.getDescriptor(key);
|
398
288
|
if (!descriptor) {
|
399
289
|
continue;
|
400
290
|
}
|
@@ -402,14 +292,14 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
402
292
|
rawInit[key] = initValue;
|
403
293
|
} else if (isRefEncoded(descriptor)) {
|
404
294
|
if (initValue != null) {
|
405
|
-
let refId = initValue
|
295
|
+
let refId = initValue.$jazz?.id;
|
406
296
|
if (!refId) {
|
407
297
|
const coValue = instantiateRefEncodedWithInit(
|
408
298
|
descriptor,
|
409
299
|
initValue,
|
410
300
|
owner
|
411
301
|
);
|
412
|
-
refId = coValue.id;
|
302
|
+
refId = coValue.$jazz.id;
|
413
303
|
}
|
414
304
|
rawInit[key] = refId;
|
415
305
|
}
|
@@ -422,9 +312,6 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
422
312
|
}
|
423
313
|
return rawOwner.createMap(rawInit, null, "private", uniqueness);
|
424
314
|
}
|
425
|
-
getDescriptor(key) {
|
426
|
-
return this._schema?.[key] || this._schema?.[ItemsSym];
|
427
|
-
}
|
428
315
|
/**
|
429
316
|
* Declare a Record-like CoMap schema, by extending `CoMap.Record(...)` and passing the value schema using `co`. Keys are always `string`.
|
430
317
|
*
|
@@ -444,11 +331,11 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
444
331
|
* @category Declaration
|
445
332
|
*/
|
446
333
|
static Record(value) {
|
447
|
-
var
|
448
|
-
class RecordLikeCoMap extends (_b = _CoMap,
|
334
|
+
var _a2, _b;
|
335
|
+
class RecordLikeCoMap extends (_b = _CoMap, _a2 = ItemsSym, _b) {
|
449
336
|
constructor() {
|
450
337
|
super(...arguments);
|
451
|
-
this[
|
338
|
+
this[_a2] = value;
|
452
339
|
}
|
453
340
|
}
|
454
341
|
return RecordLikeCoMap;
|
@@ -472,6 +359,8 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
472
359
|
* ```
|
473
360
|
*
|
474
361
|
* @category Subscription & Loading
|
362
|
+
*
|
363
|
+
* @deprecated Use `co.map(...).load` instead.
|
475
364
|
*/
|
476
365
|
static load(id, options) {
|
477
366
|
return loadCoValueWithoutMe(this, id, options);
|
@@ -496,7 +385,7 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
496
385
|
meta: null,
|
497
386
|
uniqueness: unique
|
498
387
|
};
|
499
|
-
const crypto = as
|
388
|
+
const crypto = as[TypeSym] === "Anonymous" ? as.node.crypto : as.$jazz.localNode.crypto;
|
500
389
|
return cojsonInternals.idforHeader(header, crypto);
|
501
390
|
}
|
502
391
|
/**
|
@@ -521,30 +410,34 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
521
410
|
* @param options The options for creating or loading the CoMap. This includes the intended state of the CoMap, its unique identifier, its owner, and the references to resolve.
|
522
411
|
* @returns Either an existing & modified CoMap, or a new initialised CoMap if none exists.
|
523
412
|
* @category Subscription & Loading
|
413
|
+
*
|
414
|
+
* @deprecated Use `co.map(...).upsertUnique` instead.
|
524
415
|
*/
|
525
416
|
static async upsertUnique(options) {
|
526
417
|
const mapId = _CoMap._findUnique(
|
527
418
|
options.unique,
|
528
|
-
options.owner.id,
|
529
|
-
options.owner.
|
419
|
+
options.owner.$jazz.id,
|
420
|
+
options.owner.$jazz.loadedAs
|
530
421
|
);
|
531
422
|
let map = await loadCoValueWithoutMe(this, mapId, {
|
532
423
|
...options,
|
533
|
-
loadAs: options.owner.
|
424
|
+
loadAs: options.owner.$jazz.loadedAs,
|
534
425
|
skipRetry: true
|
535
426
|
});
|
536
427
|
if (!map) {
|
537
428
|
const instance = new this();
|
538
|
-
map =
|
429
|
+
map = _CoMap._createCoMap(instance, options.value, {
|
539
430
|
owner: options.owner,
|
540
431
|
unique: options.unique
|
541
432
|
});
|
542
433
|
} else {
|
543
|
-
map.applyDiff(
|
434
|
+
map.$jazz.applyDiff(
|
435
|
+
options.value
|
436
|
+
);
|
544
437
|
}
|
545
438
|
return await loadCoValueWithoutMe(this, mapId, {
|
546
439
|
...options,
|
547
|
-
loadAs: options.owner.
|
440
|
+
loadAs: options.owner.$jazz.loadedAs,
|
548
441
|
skipRetry: true
|
549
442
|
});
|
550
443
|
}
|
@@ -554,6 +447,8 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
554
447
|
* @param ownerID The ID of the owner of the CoMap.
|
555
448
|
* @param options Additional options for loading the CoMap.
|
556
449
|
* @returns The loaded CoMap, or null if unavailable.
|
450
|
+
*
|
451
|
+
* @deprecated Use `co.map(...).loadUnique` instead.
|
557
452
|
*/
|
558
453
|
static loadUnique(unique, ownerID, options) {
|
559
454
|
return loadCoValueWithoutMe(
|
@@ -562,20 +457,100 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
562
457
|
{ ...options, skipRetry: true }
|
563
458
|
);
|
564
459
|
}
|
460
|
+
};
|
461
|
+
_CoMap.prototype[TypeSym] = "CoMap";
|
462
|
+
var CoMap = _CoMap;
|
463
|
+
var CoMapJazzApi = class extends CoValueJazzApi {
|
464
|
+
constructor(coMap, getRaw) {
|
465
|
+
super(coMap);
|
466
|
+
this.coMap = coMap;
|
467
|
+
this.getRaw = getRaw;
|
468
|
+
}
|
565
469
|
/**
|
566
|
-
*
|
470
|
+
* The ID of this `CoMap`
|
471
|
+
* @category Content
|
472
|
+
*/
|
473
|
+
get id() {
|
474
|
+
return this.raw.id;
|
475
|
+
}
|
476
|
+
get owner() {
|
477
|
+
return getCoValueOwner(this.coMap);
|
478
|
+
}
|
479
|
+
/**
|
480
|
+
* Check if a key is defined in the CoMap.
|
567
481
|
*
|
568
|
-
*
|
482
|
+
* This check does not load the referenced value or validate permissions.
|
569
483
|
*
|
570
|
-
* @
|
484
|
+
* @param key The key to check
|
485
|
+
* @returns True if the key is defined, false otherwise
|
486
|
+
* @category Content
|
571
487
|
*/
|
572
|
-
|
573
|
-
|
488
|
+
has(key) {
|
489
|
+
const entry = this.raw.getRaw(key);
|
490
|
+
return entry?.change !== void 0 && entry.change.op !== "del";
|
574
491
|
}
|
575
|
-
|
576
|
-
|
577
|
-
|
492
|
+
/**
|
493
|
+
* Set a value on the CoMap
|
494
|
+
*
|
495
|
+
* @param key The key to set
|
496
|
+
* @param value The value to set
|
497
|
+
*
|
498
|
+
* @category Content
|
499
|
+
*/
|
500
|
+
set(key, value) {
|
501
|
+
const descriptor = this.getDescriptor(key);
|
502
|
+
if (!descriptor) {
|
503
|
+
throw Error(`Cannot set unknown key ${key}`);
|
504
|
+
}
|
505
|
+
let refId = value?.$jazz?.id;
|
506
|
+
if (descriptor === "json") {
|
507
|
+
this.raw.set(key, value);
|
508
|
+
} else if ("encoded" in descriptor) {
|
509
|
+
this.raw.set(key, descriptor.encoded.encode(value));
|
510
|
+
} else if (isRefEncoded(descriptor)) {
|
511
|
+
if (value === void 0) {
|
512
|
+
if (!descriptor.optional) {
|
513
|
+
throw Error(`Cannot set required reference ${key} to undefined`);
|
514
|
+
}
|
515
|
+
this.raw.set(key, null);
|
516
|
+
} else {
|
517
|
+
if (!refId) {
|
518
|
+
const coValue = instantiateRefEncodedWithInit(
|
519
|
+
descriptor,
|
520
|
+
value,
|
521
|
+
this.owner
|
522
|
+
);
|
523
|
+
refId = coValue.$jazz.id;
|
524
|
+
}
|
525
|
+
this.raw.set(key, refId);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
}
|
529
|
+
/**
|
530
|
+
* Delete a value from a CoMap.
|
531
|
+
*
|
532
|
+
* For record-like CoMaps (created with `co.record`), any string key can be deleted.
|
533
|
+
* For struct-like CoMaps (created with `co.map`), only optional properties can be deleted.
|
534
|
+
*
|
535
|
+
* @param key The key to delete
|
536
|
+
*
|
537
|
+
* @category Content
|
538
|
+
*/
|
539
|
+
delete(key) {
|
540
|
+
this.raw.delete(key);
|
578
541
|
}
|
542
|
+
/**
|
543
|
+
* Modify the `CoMap` to match another map.
|
544
|
+
*
|
545
|
+
* The new values are assigned to the CoMap, overwriting existing values
|
546
|
+
* when the property already exists.
|
547
|
+
*
|
548
|
+
* @param newValues - The new values to apply to the CoMap. For collaborative values,
|
549
|
+
* both CoValues and JSON values are supported.
|
550
|
+
* @returns The modified CoMap.
|
551
|
+
*
|
552
|
+
* @category Content
|
553
|
+
*/
|
579
554
|
applyDiff(newValues) {
|
580
555
|
for (const key in newValues) {
|
581
556
|
if (Object.prototype.hasOwnProperty.call(newValues, key)) {
|
@@ -583,33 +558,146 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
583
558
|
const descriptor = this.getDescriptor(key);
|
584
559
|
if (!descriptor) continue;
|
585
560
|
const newValue = newValues[tKey];
|
586
|
-
const currentValue = this[tKey];
|
561
|
+
const currentValue = this.coMap[tKey];
|
587
562
|
if (descriptor === "json" || "encoded" in descriptor) {
|
588
563
|
if (currentValue !== newValue) {
|
589
|
-
this
|
564
|
+
this.set(tKey, newValue);
|
590
565
|
}
|
591
566
|
} else if (isRefEncoded(descriptor)) {
|
592
|
-
const currentId = currentValue
|
593
|
-
|
567
|
+
const currentId = currentValue?.$jazz.id;
|
568
|
+
let newId = newValue?.$jazz?.id;
|
594
569
|
if (currentId !== newId) {
|
595
|
-
this
|
570
|
+
this.set(tKey, newValue);
|
596
571
|
}
|
597
572
|
}
|
598
573
|
}
|
599
574
|
}
|
600
|
-
return this;
|
575
|
+
return this.coMap;
|
576
|
+
}
|
577
|
+
/**
|
578
|
+
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
579
|
+
*
|
580
|
+
* Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.
|
581
|
+
*
|
582
|
+
* @category Subscription & Loading
|
583
|
+
*/
|
584
|
+
ensureLoaded(options) {
|
585
|
+
return ensureCoValueLoaded(this.coMap, options);
|
586
|
+
}
|
587
|
+
subscribe(...args) {
|
588
|
+
const { options, listener } = parseSubscribeRestArgs(args);
|
589
|
+
return subscribeToExistingCoValue(this.coMap, options, listener);
|
601
590
|
}
|
602
591
|
/**
|
603
592
|
* Wait for the `CoMap` to be uploaded to the other peers.
|
604
593
|
*
|
605
594
|
* @category Subscription & Loading
|
606
595
|
*/
|
607
|
-
waitForSync(options) {
|
608
|
-
|
596
|
+
async waitForSync(options) {
|
597
|
+
await this.raw.core.waitForSync(options);
|
598
|
+
}
|
599
|
+
/**
|
600
|
+
* Get the descriptor for a given key
|
601
|
+
* @internal
|
602
|
+
*/
|
603
|
+
getDescriptor(key) {
|
604
|
+
return this.schema?.[key] || this.schema?.[ItemsSym];
|
605
|
+
}
|
606
|
+
/**
|
607
|
+
* If property `prop` is a `coField.ref(...)`, you can use `coMap.$jazz.refs.prop` to access
|
608
|
+
* the `Ref` instead of the potentially loaded/null value.
|
609
|
+
*
|
610
|
+
* This allows you to always get the ID or load the value manually.
|
611
|
+
*
|
612
|
+
* @example
|
613
|
+
* ```ts
|
614
|
+
* person.$jazz.refs.pet.id; // => ID<Animal>
|
615
|
+
* person.$jazz.refs.pet.value;
|
616
|
+
* // => Animal | null
|
617
|
+
* const pet = await person.$jazz.refs.pet.load();
|
618
|
+
* ```
|
619
|
+
*
|
620
|
+
* @category Content
|
621
|
+
**/
|
622
|
+
get refs() {
|
623
|
+
return makeRefs(
|
624
|
+
this.coMap,
|
625
|
+
(key) => this.raw.get(key),
|
626
|
+
() => {
|
627
|
+
const keys = this.raw.keys().filter((key) => {
|
628
|
+
const descriptor = this.getDescriptor(key);
|
629
|
+
return descriptor && descriptor !== "json" && isRefEncoded(descriptor);
|
630
|
+
});
|
631
|
+
return keys;
|
632
|
+
},
|
633
|
+
this.loadedAs,
|
634
|
+
(key) => this.getDescriptor(key)
|
635
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
636
|
+
);
|
637
|
+
}
|
638
|
+
/**
|
639
|
+
* Get the edits made to the CoMap.
|
640
|
+
*
|
641
|
+
* @category Collaboration
|
642
|
+
*/
|
643
|
+
getEdits() {
|
644
|
+
const map = this.coMap;
|
645
|
+
return new Proxy(
|
646
|
+
{},
|
647
|
+
{
|
648
|
+
get(_target, key) {
|
649
|
+
const rawEdit = map.$jazz.raw.lastEditAt(key);
|
650
|
+
if (!rawEdit) return void 0;
|
651
|
+
const descriptor = map.$jazz.getDescriptor(key);
|
652
|
+
if (!descriptor) return void 0;
|
653
|
+
return {
|
654
|
+
...getEditFromRaw(map, rawEdit, descriptor, key),
|
655
|
+
get all() {
|
656
|
+
return [...map.$jazz.raw.editsAt(key)].map(
|
657
|
+
(rawEdit2) => getEditFromRaw(map, rawEdit2, descriptor, key)
|
658
|
+
);
|
659
|
+
}
|
660
|
+
};
|
661
|
+
},
|
662
|
+
ownKeys(_target) {
|
663
|
+
return map.$jazz.raw.keys();
|
664
|
+
},
|
665
|
+
getOwnPropertyDescriptor(target, key) {
|
666
|
+
return {
|
667
|
+
value: Reflect.get(target, key),
|
668
|
+
writable: false,
|
669
|
+
enumerable: true,
|
670
|
+
configurable: true
|
671
|
+
};
|
672
|
+
}
|
673
|
+
}
|
674
|
+
);
|
675
|
+
}
|
676
|
+
/** @internal */
|
677
|
+
get raw() {
|
678
|
+
return this.getRaw();
|
679
|
+
}
|
680
|
+
/**
|
681
|
+
* The timestamp of the creation time of the CoMap
|
682
|
+
*
|
683
|
+
* @category Content
|
684
|
+
*/
|
685
|
+
get createdAt() {
|
686
|
+
return this.raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
|
687
|
+
}
|
688
|
+
/**
|
689
|
+
* The timestamp of the last updated time of the CoMap
|
690
|
+
*
|
691
|
+
* @category Content
|
692
|
+
*/
|
693
|
+
get lastUpdatedAt() {
|
694
|
+
return this.raw.latestTxMadeAt;
|
695
|
+
}
|
696
|
+
/** @internal */
|
697
|
+
get schema() {
|
698
|
+
return this.coMap.constructor._schema;
|
609
699
|
}
|
610
700
|
};
|
611
|
-
_CoMap.prototype._type = "CoMap";
|
612
|
-
var CoMap = _CoMap;
|
613
701
|
var CoMapProxyHandler = {
|
614
702
|
get(target, key, receiver) {
|
615
703
|
if (key === "_schema") {
|
@@ -620,11 +708,11 @@ var CoMapProxyHandler = {
|
|
620
708
|
if (typeof key !== "string") {
|
621
709
|
return void 0;
|
622
710
|
}
|
623
|
-
const descriptor = target.getDescriptor(key);
|
711
|
+
const descriptor = target.$jazz.getDescriptor(key);
|
624
712
|
if (!descriptor) {
|
625
713
|
return void 0;
|
626
714
|
}
|
627
|
-
const raw = target.
|
715
|
+
const raw = target.$jazz.raw.get(key);
|
628
716
|
if (descriptor === "json") {
|
629
717
|
return raw;
|
630
718
|
} else if ("encoded" in descriptor) {
|
@@ -635,36 +723,15 @@ var CoMapProxyHandler = {
|
|
635
723
|
}
|
636
724
|
},
|
637
725
|
set(target, key, value, receiver) {
|
638
|
-
if (
|
726
|
+
if (typeof key === "string" && typeof value === "object" && value !== null && SchemaInit in value) {
|
639
727
|
target.constructor._schema ||= {};
|
640
728
|
target.constructor._schema[key] = value[SchemaInit];
|
641
729
|
return true;
|
642
730
|
}
|
643
|
-
const descriptor = target.getDescriptor(key);
|
731
|
+
const descriptor = target.$jazz.getDescriptor(key);
|
644
732
|
if (!descriptor) return false;
|
645
733
|
if (typeof key === "string") {
|
646
|
-
|
647
|
-
target._raw.set(key, value);
|
648
|
-
} else if ("encoded" in descriptor) {
|
649
|
-
target._raw.set(key, descriptor.encoded.encode(value));
|
650
|
-
} else if (isRefEncoded(descriptor)) {
|
651
|
-
if (value === void 0) {
|
652
|
-
if (descriptor.optional) {
|
653
|
-
target._raw.set(key, null);
|
654
|
-
} else {
|
655
|
-
throw new Error(
|
656
|
-
`Cannot set required reference ${key} to undefined`
|
657
|
-
);
|
658
|
-
}
|
659
|
-
} else if (value?.id) {
|
660
|
-
target._raw.set(key, value.id);
|
661
|
-
} else {
|
662
|
-
throw new Error(
|
663
|
-
`Cannot set reference ${key} to a non-CoValue. Got ${value}`
|
664
|
-
);
|
665
|
-
}
|
666
|
-
}
|
667
|
-
return true;
|
734
|
+
throw Error("Cannot update a CoMap directly. Use `$jazz.set` instead.");
|
668
735
|
} else {
|
669
736
|
return Reflect.set(target, key, value, receiver);
|
670
737
|
}
|
@@ -680,7 +747,7 @@ var CoMapProxyHandler = {
|
|
680
747
|
},
|
681
748
|
ownKeys(target) {
|
682
749
|
const keys = Reflect.ownKeys(target).filter((k) => k !== ItemsSym);
|
683
|
-
for (const key of target.
|
750
|
+
for (const key of target.$jazz.raw.keys()) {
|
684
751
|
if (!keys.includes(key)) {
|
685
752
|
keys.push(key);
|
686
753
|
}
|
@@ -691,8 +758,8 @@ var CoMapProxyHandler = {
|
|
691
758
|
if (key in target) {
|
692
759
|
return Reflect.getOwnPropertyDescriptor(target, key);
|
693
760
|
} else {
|
694
|
-
const descriptor = target.getDescriptor(key);
|
695
|
-
if (descriptor || key in target.
|
761
|
+
const descriptor = target.$jazz.getDescriptor(key);
|
762
|
+
if (descriptor || key in target.$jazz.raw.latest) {
|
696
763
|
return {
|
697
764
|
enumerable: true,
|
698
765
|
configurable: true,
|
@@ -702,27 +769,47 @@ var CoMapProxyHandler = {
|
|
702
769
|
}
|
703
770
|
},
|
704
771
|
has(target, key) {
|
705
|
-
const descriptor = target
|
706
|
-
if (target
|
707
|
-
return target.
|
772
|
+
const descriptor = target.$jazz?.getDescriptor(key);
|
773
|
+
if (target.$jazz?.raw && typeof key === "string" && descriptor) {
|
774
|
+
return target.$jazz.raw.get(key) !== void 0;
|
708
775
|
} else {
|
709
776
|
return Reflect.has(target, key);
|
710
777
|
}
|
711
778
|
},
|
712
779
|
deleteProperty(target, key) {
|
713
|
-
const descriptor = target.getDescriptor(key);
|
780
|
+
const descriptor = target.$jazz.getDescriptor(key);
|
714
781
|
if (typeof key === "string" && descriptor) {
|
715
|
-
|
716
|
-
|
782
|
+
throw Error(
|
783
|
+
"Cannot delete a CoMap property directly. Use `$jazz.delete` instead."
|
784
|
+
);
|
717
785
|
} else {
|
718
786
|
return Reflect.deleteProperty(target, key);
|
719
787
|
}
|
720
788
|
}
|
721
789
|
};
|
722
790
|
RegisteredSchemas["CoMap"] = CoMap;
|
791
|
+
function getEditFromRaw(target, rawEdit, descriptor, key) {
|
792
|
+
return {
|
793
|
+
value: descriptor === "json" ? rawEdit.value : "encoded" in descriptor ? rawEdit.value === null || rawEdit.value === void 0 ? rawEdit.value : descriptor.encoded.decode(rawEdit.value) : accessChildById(target, rawEdit.value, descriptor),
|
794
|
+
ref: descriptor !== "json" && isRefEncoded(descriptor) ? new Ref(
|
795
|
+
rawEdit.value,
|
796
|
+
target.$jazz.loadedAs,
|
797
|
+
descriptor,
|
798
|
+
target
|
799
|
+
) : void 0,
|
800
|
+
get by() {
|
801
|
+
return rawEdit.by && accessChildById(target, rawEdit.by, {
|
802
|
+
ref: Account,
|
803
|
+
optional: false
|
804
|
+
});
|
805
|
+
},
|
806
|
+
madeAt: rawEdit.at,
|
807
|
+
key
|
808
|
+
};
|
809
|
+
}
|
723
810
|
|
724
811
|
// src/tools/coValues/coList.ts
|
725
|
-
import {
|
812
|
+
import { cojsonInternals as cojsonInternals2 } from "cojson";
|
726
813
|
import { calcPatch } from "fast-myers-diff";
|
727
814
|
var _CoList = class _CoList extends Array {
|
728
815
|
/**
|
@@ -741,11 +828,11 @@ var _CoList = class _CoList extends Array {
|
|
741
828
|
* @category Declaration
|
742
829
|
*/
|
743
830
|
static Of(item) {
|
744
|
-
var
|
745
|
-
return class CoListOf extends (_b = _CoList,
|
831
|
+
var _a2, _b;
|
832
|
+
return class CoListOf extends (_b = _CoList, _a2 = coField.items, _b) {
|
746
833
|
constructor() {
|
747
834
|
super(...arguments);
|
748
|
-
this[
|
835
|
+
this[_a2] = item;
|
749
836
|
}
|
750
837
|
};
|
751
838
|
}
|
@@ -755,79 +842,21 @@ var _CoList = class _CoList extends Array {
|
|
755
842
|
static of(..._args) {
|
756
843
|
throw new Error("Can't use Array.of with CoLists");
|
757
844
|
}
|
758
|
-
/** @internal */
|
759
|
-
get _schema() {
|
760
|
-
return this.constructor._schema;
|
761
|
-
}
|
762
|
-
/** @category Collaboration */
|
763
|
-
get _owner() {
|
764
|
-
return this._raw.group instanceof RawAccount2 ? coValueClassFromCoValueClassOrSchema(
|
765
|
-
RegisteredSchemas["Account"]
|
766
|
-
).fromRaw(this._raw.group) : RegisteredSchemas["Group"].fromRaw(this._raw.group);
|
767
|
-
}
|
768
|
-
/**
|
769
|
-
* If a `CoList`'s items are a `coField.ref(...)`, you can use `coList._refs[i]` to access
|
770
|
-
* the `Ref` instead of the potentially loaded/null value.
|
771
|
-
*
|
772
|
-
* This allows you to always get the ID or load the value manually.
|
773
|
-
*
|
774
|
-
* @example
|
775
|
-
* ```ts
|
776
|
-
* animals._refs[0].id; // => ID<Animal>
|
777
|
-
* animals._refs[0].value;
|
778
|
-
* // => Animal | null
|
779
|
-
* const animal = await animals._refs[0].load();
|
780
|
-
* ```
|
781
|
-
*
|
782
|
-
* @category Content
|
783
|
-
**/
|
784
|
-
get _refs() {
|
785
|
-
return makeRefs(
|
786
|
-
this,
|
787
|
-
(idx) => this._raw.get(idx),
|
788
|
-
() => Array.from({ length: this._raw.entries().length }, (_, idx) => idx),
|
789
|
-
this._loadedAs,
|
790
|
-
(_idx) => this._schema[ItemsSym]
|
791
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
792
|
-
);
|
793
|
-
}
|
794
|
-
get _edits() {
|
795
|
-
throw new Error("Not implemented");
|
796
|
-
}
|
797
|
-
get _loadedAs() {
|
798
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
799
|
-
if (agent instanceof ControlledAccount2) {
|
800
|
-
return coValuesCache.get(
|
801
|
-
agent.account,
|
802
|
-
() => coValueClassFromCoValueClassOrSchema(
|
803
|
-
RegisteredSchemas["Account"]
|
804
|
-
).fromRaw(agent.account)
|
805
|
-
);
|
806
|
-
}
|
807
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
808
|
-
}
|
809
845
|
static get [(ItemsSym, Symbol.species)]() {
|
810
846
|
return Array;
|
811
847
|
}
|
812
|
-
getItemsDescriptor() {
|
813
|
-
return this._schema?.[ItemsSym];
|
814
|
-
}
|
815
848
|
constructor(options) {
|
816
849
|
super();
|
817
|
-
|
818
|
-
value: `instance-${Math.random().toString(36).slice(2)}`,
|
819
|
-
enumerable: false
|
820
|
-
});
|
850
|
+
const proxy = new Proxy(this, CoListProxyHandler);
|
821
851
|
if (options && "fromRaw" in options) {
|
822
852
|
Object.defineProperties(this, {
|
823
|
-
|
824
|
-
value: options.fromRaw
|
853
|
+
$jazz: {
|
854
|
+
value: new CoListJazzApi(proxy, () => options.fromRaw),
|
825
855
|
enumerable: false
|
826
|
-
}
|
827
|
-
_raw: { value: options.fromRaw, enumerable: false }
|
856
|
+
}
|
828
857
|
});
|
829
858
|
}
|
830
|
-
return
|
859
|
+
return proxy;
|
831
860
|
}
|
832
861
|
/**
|
833
862
|
* Create a new CoList with the given initial values and owner.
|
@@ -849,126 +878,37 @@ var _CoList = class _CoList extends Array {
|
|
849
878
|
* ```
|
850
879
|
*
|
851
880
|
* @category Creation
|
881
|
+
* @deprecated Use `co.list(...).create` instead.
|
852
882
|
**/
|
853
883
|
static create(items, options) {
|
854
884
|
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
855
|
-
const instance = new this(
|
856
|
-
|
857
|
-
|
885
|
+
const instance = new this();
|
886
|
+
Object.defineProperties(instance, {
|
887
|
+
$jazz: {
|
888
|
+
value: new CoListJazzApi(instance, () => raw),
|
889
|
+
enumerable: false
|
890
|
+
}
|
891
|
+
});
|
892
|
+
const raw = owner.$jazz.raw.createList(
|
893
|
+
toRawItems(items, instance.$jazz.schema[ItemsSym], owner),
|
858
894
|
null,
|
859
895
|
"private",
|
860
896
|
uniqueness
|
861
897
|
);
|
862
|
-
Object.defineProperties(instance, {
|
863
|
-
id: {
|
864
|
-
value: raw.id,
|
865
|
-
enumerable: false
|
866
|
-
},
|
867
|
-
_raw: { value: raw, enumerable: false }
|
868
|
-
});
|
869
898
|
return instance;
|
870
899
|
}
|
871
|
-
push(...items) {
|
872
|
-
this._raw.appendItems(
|
873
|
-
toRawItems(items, this._schema[ItemsSym], this._owner),
|
874
|
-
void 0,
|
875
|
-
"private"
|
876
|
-
);
|
877
|
-
return this._raw.entries().length;
|
878
|
-
}
|
879
|
-
unshift(...items) {
|
880
|
-
for (const item of toRawItems(
|
881
|
-
items,
|
882
|
-
this._schema[ItemsSym],
|
883
|
-
this._owner
|
884
|
-
)) {
|
885
|
-
this._raw.prepend(item);
|
886
|
-
}
|
887
|
-
return this._raw.entries().length;
|
888
|
-
}
|
889
|
-
pop() {
|
890
|
-
const last = this[this.length - 1];
|
891
|
-
this._raw.delete(this.length - 1);
|
892
|
-
return last;
|
893
|
-
}
|
894
|
-
shift() {
|
895
|
-
const first = this[0];
|
896
|
-
this._raw.delete(0);
|
897
|
-
return first;
|
898
|
-
}
|
899
|
-
/**
|
900
|
-
* Splice the `CoList` at a given index.
|
901
|
-
*
|
902
|
-
* @param start - The index to start the splice.
|
903
|
-
* @param deleteCount - The number of items to delete.
|
904
|
-
* @param items - The items to insert.
|
905
|
-
*/
|
906
|
-
splice(start, deleteCount, ...items) {
|
907
|
-
const deleted = this.slice(start, start + deleteCount);
|
908
|
-
for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
|
909
|
-
this._raw.delete(idxToDelete);
|
910
|
-
}
|
911
|
-
const rawItems = toRawItems(
|
912
|
-
items,
|
913
|
-
this._schema[ItemsSym],
|
914
|
-
this._owner
|
915
|
-
);
|
916
|
-
if (rawItems.length === 0) {
|
917
|
-
return deleted;
|
918
|
-
}
|
919
|
-
if (rawItems.length === 1) {
|
920
|
-
const item = rawItems[0];
|
921
|
-
if (item === void 0) return deleted;
|
922
|
-
if (start === 0) {
|
923
|
-
this._raw.prepend(item);
|
924
|
-
} else {
|
925
|
-
this._raw.append(item, Math.max(start - 1, 0));
|
926
|
-
}
|
927
|
-
return deleted;
|
928
|
-
}
|
929
|
-
if (start === 0) {
|
930
|
-
for (let i = rawItems.length - 1; i >= 0; i--) {
|
931
|
-
const item = rawItems[i];
|
932
|
-
if (item === void 0) continue;
|
933
|
-
this._raw.prepend(item);
|
934
|
-
}
|
935
|
-
} else {
|
936
|
-
let appendAfter = Math.max(start - 1, 0);
|
937
|
-
for (const item of rawItems) {
|
938
|
-
if (item === void 0) continue;
|
939
|
-
this._raw.append(item, appendAfter);
|
940
|
-
appendAfter++;
|
941
|
-
}
|
942
|
-
}
|
943
|
-
return deleted;
|
944
|
-
}
|
945
|
-
/**
|
946
|
-
* Modify the `CoList` to match another list, where the changes are managed internally.
|
947
|
-
*
|
948
|
-
* @param result - The resolved list of items.
|
949
|
-
*/
|
950
|
-
applyDiff(result) {
|
951
|
-
const current = this._raw.asArray();
|
952
|
-
const comparator = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => {
|
953
|
-
return current[aIdx]?.id === result[bIdx]?.id;
|
954
|
-
} : void 0;
|
955
|
-
const patches = [...calcPatch(current, result, comparator)];
|
956
|
-
for (const [from, to, insert] of patches.reverse()) {
|
957
|
-
this.splice(from, to - from, ...insert);
|
958
|
-
}
|
959
|
-
}
|
960
900
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
961
901
|
toJSON(_key, seenAbove) {
|
962
|
-
const itemDescriptor = this.
|
902
|
+
const itemDescriptor = this.$jazz.schema[ItemsSym];
|
963
903
|
if (itemDescriptor === "json") {
|
964
|
-
return this.
|
904
|
+
return this.$jazz.raw.asArray();
|
965
905
|
} else if ("encoded" in itemDescriptor) {
|
966
|
-
return this.
|
906
|
+
return this.$jazz.raw.asArray().map((e) => itemDescriptor.encoded.encode(e));
|
967
907
|
} else if (isRefEncoded(itemDescriptor)) {
|
968
908
|
return this.map(
|
969
|
-
(item, idx) => seenAbove?.includes(item
|
909
|
+
(item, idx) => seenAbove?.includes(item?.$jazz.id) ? { _circular: item.$jazz.id } : item?.toJSON(idx + "", [
|
970
910
|
...seenAbove || [],
|
971
|
-
this.id
|
911
|
+
this.$jazz.id
|
972
912
|
])
|
973
913
|
);
|
974
914
|
} else {
|
@@ -1008,6 +948,7 @@ var _CoList = class _CoList extends Array {
|
|
1008
948
|
* ```
|
1009
949
|
*
|
1010
950
|
* @category Subscription & Loading
|
951
|
+
* @deprecated Use `co.list(...).load` instead.
|
1011
952
|
*/
|
1012
953
|
static load(id, options) {
|
1013
954
|
return loadCoValueWithoutMe(this, id, options);
|
@@ -1016,24 +957,6 @@ var _CoList = class _CoList extends Array {
|
|
1016
957
|
const { options, listener } = parseSubscribeRestArgs(args);
|
1017
958
|
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
1018
959
|
}
|
1019
|
-
/**
|
1020
|
-
* Given an already loaded `CoList`, ensure that items are loaded to the specified depth.
|
1021
|
-
*
|
1022
|
-
* Works like `CoList.load()`, but you don't need to pass the ID or the account to load as again.
|
1023
|
-
*
|
1024
|
-
* @category Subscription & Loading
|
1025
|
-
*/
|
1026
|
-
ensureLoaded(options) {
|
1027
|
-
return ensureCoValueLoaded(this, options);
|
1028
|
-
}
|
1029
|
-
subscribe(...args) {
|
1030
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
1031
|
-
return subscribeToExistingCoValue(this, options, listener);
|
1032
|
-
}
|
1033
|
-
/** @category Type Helpers */
|
1034
|
-
castAs(cl) {
|
1035
|
-
return cl.fromRaw(this._raw);
|
1036
|
-
}
|
1037
960
|
/** @deprecated Use `CoList.upsertUnique` and `CoList.loadUnique` instead. */
|
1038
961
|
static findUnique(unique, ownerID, as) {
|
1039
962
|
return _CoList._findUnique(unique, ownerID, as);
|
@@ -1050,7 +973,7 @@ var _CoList = class _CoList extends Array {
|
|
1050
973
|
meta: null,
|
1051
974
|
uniqueness: unique
|
1052
975
|
};
|
1053
|
-
const crypto = as
|
976
|
+
const crypto = as[TypeSym] === "Anonymous" ? as.node.crypto : as.$jazz.localNode.crypto;
|
1054
977
|
return cojsonInternals2.idforHeader(header, crypto);
|
1055
978
|
}
|
1056
979
|
/**
|
@@ -1069,60 +992,377 @@ var _CoList = class _CoList extends Array {
|
|
1069
992
|
* );
|
1070
993
|
* ```
|
1071
994
|
*
|
1072
|
-
* @param options The options for creating or loading the CoList. This includes the intended state of the CoList, its unique identifier, its owner, and the references to resolve.
|
1073
|
-
* @returns Either an existing & modified CoList, or a new initialised CoList if none exists.
|
995
|
+
* @param options The options for creating or loading the CoList. This includes the intended state of the CoList, its unique identifier, its owner, and the references to resolve.
|
996
|
+
* @returns Either an existing & modified CoList, or a new initialised CoList if none exists.
|
997
|
+
* @category Subscription & Loading
|
998
|
+
*/
|
999
|
+
static async upsertUnique(options) {
|
1000
|
+
const listId = _CoList._findUnique(
|
1001
|
+
options.unique,
|
1002
|
+
options.owner.$jazz.id,
|
1003
|
+
options.owner.$jazz.loadedAs
|
1004
|
+
);
|
1005
|
+
let list = await loadCoValueWithoutMe(this, listId, {
|
1006
|
+
...options,
|
1007
|
+
loadAs: options.owner.$jazz.loadedAs,
|
1008
|
+
skipRetry: true
|
1009
|
+
});
|
1010
|
+
if (!list) {
|
1011
|
+
list = this.create(options.value, {
|
1012
|
+
owner: options.owner,
|
1013
|
+
unique: options.unique
|
1014
|
+
});
|
1015
|
+
} else {
|
1016
|
+
list.$jazz.applyDiff(options.value);
|
1017
|
+
}
|
1018
|
+
return await loadCoValueWithoutMe(this, listId, {
|
1019
|
+
...options,
|
1020
|
+
loadAs: options.owner.$jazz.loadedAs,
|
1021
|
+
skipRetry: true
|
1022
|
+
});
|
1023
|
+
}
|
1024
|
+
/**
|
1025
|
+
* Loads a CoList by its unique identifier and owner's ID.
|
1026
|
+
* @param unique The unique identifier of the CoList to load.
|
1027
|
+
* @param ownerID The ID of the owner of the CoList.
|
1028
|
+
* @param options Additional options for loading the CoList.
|
1029
|
+
* @returns The loaded CoList, or null if unavailable.
|
1030
|
+
*/
|
1031
|
+
static loadUnique(unique, ownerID, options) {
|
1032
|
+
return loadCoValueWithoutMe(
|
1033
|
+
this,
|
1034
|
+
_CoList._findUnique(unique, ownerID, options?.loadAs),
|
1035
|
+
{ ...options, skipRetry: true }
|
1036
|
+
);
|
1037
|
+
}
|
1038
|
+
// Override mutation methods defined on Array, as CoLists aren't meant to be mutated directly
|
1039
|
+
/**
|
1040
|
+
* @deprecated Use `.$jazz.push` instead.
|
1041
|
+
*/
|
1042
|
+
push(...items) {
|
1043
|
+
throw new Error(
|
1044
|
+
"Cannot mutate a CoList directly. Use `.$jazz.push` instead."
|
1045
|
+
);
|
1046
|
+
}
|
1047
|
+
/**
|
1048
|
+
* @deprecated Use `.$jazz.unshift` instead.
|
1049
|
+
*/
|
1050
|
+
unshift(...items) {
|
1051
|
+
throw new Error(
|
1052
|
+
"Cannot mutate a CoList directly. Use `.$jazz.unshift` instead."
|
1053
|
+
);
|
1054
|
+
}
|
1055
|
+
/**
|
1056
|
+
* @deprecated Use `.$jazz.pop` instead.
|
1057
|
+
*/
|
1058
|
+
// @ts-expect-error
|
1059
|
+
pop(value) {
|
1060
|
+
throw new Error(
|
1061
|
+
"Cannot mutate a CoList directly. Use `.$jazz.pop` instead."
|
1062
|
+
);
|
1063
|
+
}
|
1064
|
+
/**
|
1065
|
+
* @deprecated Use `.$jazz.shift` instead.
|
1066
|
+
*/
|
1067
|
+
// @ts-expect-error
|
1068
|
+
shift(value) {
|
1069
|
+
throw new Error(
|
1070
|
+
"Cannot mutate a CoList directly. Use `.$jazz.shift` instead."
|
1071
|
+
);
|
1072
|
+
}
|
1073
|
+
/**
|
1074
|
+
* @deprecated Use `.$jazz.splice` instead.
|
1075
|
+
*/
|
1076
|
+
splice(start, deleteCount, ...items) {
|
1077
|
+
throw new Error(
|
1078
|
+
"Cannot mutate a CoList directly. Use `.$jazz.splice` instead."
|
1079
|
+
);
|
1080
|
+
}
|
1081
|
+
/**
|
1082
|
+
* @deprecated Use `.$jazz.set` instead.
|
1083
|
+
*/
|
1084
|
+
copyWithin(target, start, end) {
|
1085
|
+
throw new Error(
|
1086
|
+
"Cannot mutate a CoList directly. Use `.$jazz.set` instead."
|
1087
|
+
);
|
1088
|
+
}
|
1089
|
+
/**
|
1090
|
+
* @deprecated Use `.$jazz.set` instead.
|
1091
|
+
*/
|
1092
|
+
fill(value, start, end) {
|
1093
|
+
throw new Error(
|
1094
|
+
"Cannot mutate a CoList directly. Use `.$jazz.set` instead."
|
1095
|
+
);
|
1096
|
+
}
|
1097
|
+
/**
|
1098
|
+
* @deprecated Use `.toReversed` if you want a reversed copy, or `.$jazz.set` to mutate the CoList.
|
1099
|
+
*/
|
1100
|
+
// @ts-expect-error
|
1101
|
+
reverse(value) {
|
1102
|
+
throw new Error(
|
1103
|
+
"Cannot mutate a CoList directly. Use `.toReversed` if you want a reversed copy, or `.$jazz.set` to mutate the CoList."
|
1104
|
+
);
|
1105
|
+
}
|
1106
|
+
/**
|
1107
|
+
* @deprecated Use `.toSorted()` if you want a sorted copy, or `.$jazz.set` to mutate the CoList.
|
1108
|
+
*/
|
1109
|
+
sort(compareFn) {
|
1110
|
+
throw new Error(
|
1111
|
+
"Cannot mutate a CoList directly. Use `.toSorted` if you want a sorted copy, or `.$jazz.set` to mutate the CoList."
|
1112
|
+
);
|
1113
|
+
}
|
1114
|
+
};
|
1115
|
+
_CoList.prototype[TypeSym] = "CoList";
|
1116
|
+
var CoList = _CoList;
|
1117
|
+
var CoListJazzApi = class extends CoValueJazzApi {
|
1118
|
+
constructor(coList, getRaw) {
|
1119
|
+
super(coList);
|
1120
|
+
this.coList = coList;
|
1121
|
+
this.getRaw = getRaw;
|
1122
|
+
}
|
1123
|
+
/**
|
1124
|
+
* The ID of this `CoList`
|
1125
|
+
* @category Content
|
1126
|
+
*/
|
1127
|
+
get id() {
|
1128
|
+
return this.raw.id;
|
1129
|
+
}
|
1130
|
+
/** @category Collaboration */
|
1131
|
+
get owner() {
|
1132
|
+
return getCoValueOwner(this.coList);
|
1133
|
+
}
|
1134
|
+
set(index, value) {
|
1135
|
+
const itemDescriptor = this.schema[ItemsSym];
|
1136
|
+
const rawValue = toRawItems([value], itemDescriptor, this.owner)[0];
|
1137
|
+
if (rawValue === null && !itemDescriptor.optional) {
|
1138
|
+
throw new Error(`Cannot set required reference ${index} to undefined`);
|
1139
|
+
}
|
1140
|
+
this.raw.replace(index, rawValue);
|
1141
|
+
}
|
1142
|
+
/**
|
1143
|
+
* Appends new elements to the end of an array, and returns the new length of the array.
|
1144
|
+
* @param items New elements to add to the array.
|
1145
|
+
*
|
1146
|
+
* @category Content
|
1147
|
+
*/
|
1148
|
+
push(...items) {
|
1149
|
+
this.raw.appendItems(
|
1150
|
+
toRawItems(items, this.schema[ItemsSym], this.owner),
|
1151
|
+
void 0,
|
1152
|
+
"private"
|
1153
|
+
);
|
1154
|
+
return this.raw.entries().length;
|
1155
|
+
}
|
1156
|
+
/**
|
1157
|
+
* Inserts new elements at the start of an array, and returns the new length of the array.
|
1158
|
+
* @param items Elements to insert at the start of the array.
|
1159
|
+
*
|
1160
|
+
* @category Content
|
1161
|
+
*/
|
1162
|
+
unshift(...items) {
|
1163
|
+
for (const item of toRawItems(
|
1164
|
+
items,
|
1165
|
+
this.schema[ItemsSym],
|
1166
|
+
this.owner
|
1167
|
+
)) {
|
1168
|
+
this.raw.prepend(item);
|
1169
|
+
}
|
1170
|
+
return this.raw.entries().length;
|
1171
|
+
}
|
1172
|
+
/**
|
1173
|
+
* Removes the last element from an array and returns it.
|
1174
|
+
* If the array is empty, undefined is returned and the array is not modified.
|
1175
|
+
*
|
1176
|
+
* @category Content
|
1177
|
+
*/
|
1178
|
+
pop() {
|
1179
|
+
const last = this.coList[this.coList.length - 1];
|
1180
|
+
this.raw.delete(this.coList.length - 1);
|
1181
|
+
return last;
|
1182
|
+
}
|
1183
|
+
/**
|
1184
|
+
* Removes the first element from an array and returns it.
|
1185
|
+
* If the array is empty, undefined is returned and the array is not modified.
|
1186
|
+
*
|
1187
|
+
* @category Content
|
1188
|
+
*/
|
1189
|
+
shift() {
|
1190
|
+
const first = this.coList[0];
|
1191
|
+
this.raw.delete(0);
|
1192
|
+
return first;
|
1193
|
+
}
|
1194
|
+
/**
|
1195
|
+
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
|
1196
|
+
* @param start The zero-based location in the array from which to start removing elements.
|
1197
|
+
* @param deleteCount The number of elements to remove.
|
1198
|
+
* @param items Elements to insert into the array in place of the deleted elements.
|
1199
|
+
* @returns An array containing the elements that were deleted.
|
1200
|
+
*
|
1201
|
+
* @category Content
|
1202
|
+
*/
|
1203
|
+
splice(start, deleteCount, ...items) {
|
1204
|
+
const deleted = this.coList.slice(start, start + deleteCount);
|
1205
|
+
for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
|
1206
|
+
this.raw.delete(idxToDelete);
|
1207
|
+
}
|
1208
|
+
const rawItems = toRawItems(
|
1209
|
+
items,
|
1210
|
+
this.schema[ItemsSym],
|
1211
|
+
this.owner
|
1212
|
+
);
|
1213
|
+
if (rawItems.length === 0) {
|
1214
|
+
return deleted;
|
1215
|
+
}
|
1216
|
+
if (rawItems.length === 1) {
|
1217
|
+
const item = rawItems[0];
|
1218
|
+
if (item === void 0) return deleted;
|
1219
|
+
if (start === 0) {
|
1220
|
+
this.raw.prepend(item);
|
1221
|
+
} else {
|
1222
|
+
this.raw.append(item, Math.max(start - 1, 0));
|
1223
|
+
}
|
1224
|
+
return deleted;
|
1225
|
+
}
|
1226
|
+
if (start === 0) {
|
1227
|
+
for (let i = rawItems.length - 1; i >= 0; i--) {
|
1228
|
+
const item = rawItems[i];
|
1229
|
+
if (item === void 0) continue;
|
1230
|
+
this.raw.prepend(item);
|
1231
|
+
}
|
1232
|
+
} else {
|
1233
|
+
let appendAfter = Math.max(start - 1, 0);
|
1234
|
+
for (const item of rawItems) {
|
1235
|
+
if (item === void 0) continue;
|
1236
|
+
this.raw.append(item, appendAfter);
|
1237
|
+
appendAfter++;
|
1238
|
+
}
|
1239
|
+
}
|
1240
|
+
return deleted;
|
1241
|
+
}
|
1242
|
+
remove(...args) {
|
1243
|
+
const predicate = args[0] instanceof Function ? args[0] : void 0;
|
1244
|
+
let indices = [];
|
1245
|
+
if (predicate) {
|
1246
|
+
for (let i = 0; i < this.coList.length; i++) {
|
1247
|
+
if (predicate(this.coList[i], i, this.coList)) {
|
1248
|
+
indices.push(i);
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
} else {
|
1252
|
+
indices = args.filter((index) => index >= 0 && index < this.coList.length).sort((a, b) => a - b);
|
1253
|
+
}
|
1254
|
+
const deletedItems = indices.map((index) => this.coList[index]);
|
1255
|
+
for (const index of indices.reverse()) {
|
1256
|
+
this.raw.delete(index);
|
1257
|
+
}
|
1258
|
+
return deletedItems;
|
1259
|
+
}
|
1260
|
+
/**
|
1261
|
+
* Retains only the elements matching the predicate from the array.
|
1262
|
+
* @param predicate The predicate to match the elements to retain.
|
1263
|
+
* @returns The removed elements.
|
1264
|
+
*
|
1265
|
+
* @category Content
|
1266
|
+
*/
|
1267
|
+
retain(predicate) {
|
1268
|
+
return this.remove((...args) => !predicate(...args));
|
1269
|
+
}
|
1270
|
+
/**
|
1271
|
+
* Modify the `CoList` to match another list, where the changes are managed internally.
|
1272
|
+
*
|
1273
|
+
* Changes are detected using `Object.is` for non-collaborative values and `$jazz.id` for collaborative values.
|
1274
|
+
*
|
1275
|
+
* @param result - The resolved list of items. For collaborative values, both CoValues and JSON values are supported.
|
1276
|
+
* @returns The modified CoList.
|
1277
|
+
*
|
1278
|
+
* @category Content
|
1279
|
+
*/
|
1280
|
+
applyDiff(result) {
|
1281
|
+
const current = this.raw.asArray();
|
1282
|
+
const comparator = isRefEncoded(this.schema[ItemsSym]) ? (aIdx, bIdx) => {
|
1283
|
+
const oldCoValueId = current[aIdx]?.$jazz?.id;
|
1284
|
+
const newCoValueId = result[bIdx]?.$jazz?.id;
|
1285
|
+
const isSame = !!oldCoValueId && !!newCoValueId && oldCoValueId === newCoValueId;
|
1286
|
+
return isSame;
|
1287
|
+
} : void 0;
|
1288
|
+
const patches = [...calcPatch(current, result, comparator)];
|
1289
|
+
for (const [from, to, insert] of patches.reverse()) {
|
1290
|
+
this.splice(from, to - from, ...insert);
|
1291
|
+
}
|
1292
|
+
return this.coList;
|
1293
|
+
}
|
1294
|
+
/**
|
1295
|
+
* Given an already loaded `CoList`, ensure that items are loaded to the specified depth.
|
1296
|
+
*
|
1297
|
+
* Works like `CoList.load()`, but you don't need to pass the ID or the account to load as again.
|
1298
|
+
*
|
1299
|
+
* @category Subscription & Loading
|
1300
|
+
*/
|
1301
|
+
ensureLoaded(options) {
|
1302
|
+
return ensureCoValueLoaded(this.coList, options);
|
1303
|
+
}
|
1304
|
+
subscribe(...args) {
|
1305
|
+
const { options, listener } = parseSubscribeRestArgs(args);
|
1306
|
+
return subscribeToExistingCoValue(this.coList, options, listener);
|
1307
|
+
}
|
1308
|
+
/**
|
1309
|
+
* Wait for the `CoList` to be uploaded to the other peers.
|
1310
|
+
*
|
1074
1311
|
* @category Subscription & Loading
|
1075
1312
|
*/
|
1076
|
-
|
1077
|
-
|
1078
|
-
options.unique,
|
1079
|
-
options.owner.id,
|
1080
|
-
options.owner._loadedAs
|
1081
|
-
);
|
1082
|
-
let list = await loadCoValueWithoutMe(this, listId, {
|
1083
|
-
...options,
|
1084
|
-
loadAs: options.owner._loadedAs,
|
1085
|
-
skipRetry: true
|
1086
|
-
});
|
1087
|
-
if (!list) {
|
1088
|
-
list = this.create(options.value, {
|
1089
|
-
owner: options.owner,
|
1090
|
-
unique: options.unique
|
1091
|
-
});
|
1092
|
-
} else {
|
1093
|
-
list.applyDiff(options.value);
|
1094
|
-
}
|
1095
|
-
return await loadCoValueWithoutMe(this, listId, {
|
1096
|
-
...options,
|
1097
|
-
loadAs: options.owner._loadedAs,
|
1098
|
-
skipRetry: true
|
1099
|
-
});
|
1313
|
+
async waitForSync(options) {
|
1314
|
+
await this.raw.core.waitForSync(options);
|
1100
1315
|
}
|
1101
1316
|
/**
|
1102
|
-
*
|
1103
|
-
* @
|
1104
|
-
* @param ownerID The ID of the owner of the CoList.
|
1105
|
-
* @param options Additional options for loading the CoList.
|
1106
|
-
* @returns The loaded CoList, or null if unavailable.
|
1317
|
+
* Get the descriptor for the items in the `CoList`
|
1318
|
+
* @internal
|
1107
1319
|
*/
|
1108
|
-
|
1109
|
-
return
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1320
|
+
getItemsDescriptor() {
|
1321
|
+
return this.schema[ItemsSym];
|
1322
|
+
}
|
1323
|
+
/**
|
1324
|
+
* If a `CoList`'s items are a `coField.ref(...)`, you can use `coList.$jazz.refs[i]` to access
|
1325
|
+
* the `Ref` instead of the potentially loaded/null value.
|
1326
|
+
*
|
1327
|
+
* This allows you to always get the ID or load the value manually.
|
1328
|
+
*
|
1329
|
+
* @example
|
1330
|
+
* ```ts
|
1331
|
+
* animals.$jazz.refs[0].id; // => ID<Animal>
|
1332
|
+
* animals.$jazz.refs[0].value;
|
1333
|
+
* // => Animal | null
|
1334
|
+
* const animal = await animals.$jazz.refs[0].load();
|
1335
|
+
* ```
|
1336
|
+
*
|
1337
|
+
* @category Content
|
1338
|
+
**/
|
1339
|
+
get refs() {
|
1340
|
+
return makeRefs(
|
1341
|
+
this.coList,
|
1342
|
+
(idx) => this.raw.get(idx),
|
1343
|
+
() => Array.from({ length: this.raw.entries().length }, (_, idx) => idx),
|
1344
|
+
this.loadedAs,
|
1345
|
+
(_idx) => this.schema[ItemsSym]
|
1346
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1113
1347
|
);
|
1114
1348
|
}
|
1115
1349
|
/**
|
1116
|
-
*
|
1350
|
+
* Get the edits made to the CoList.
|
1117
1351
|
*
|
1118
|
-
* @category
|
1352
|
+
* @category Collaboration
|
1119
1353
|
*/
|
1120
|
-
|
1121
|
-
|
1354
|
+
getEdits() {
|
1355
|
+
throw new Error("Not implemented");
|
1356
|
+
}
|
1357
|
+
/** @internal */
|
1358
|
+
get raw() {
|
1359
|
+
return this.getRaw();
|
1360
|
+
}
|
1361
|
+
/** @internal */
|
1362
|
+
get schema() {
|
1363
|
+
return this.coList.constructor._schema;
|
1122
1364
|
}
|
1123
1365
|
};
|
1124
|
-
_CoList.prototype._type = "CoList";
|
1125
|
-
var CoList = _CoList;
|
1126
1366
|
function toRawItems(items, itemDescriptor, owner) {
|
1127
1367
|
let rawItems = [];
|
1128
1368
|
if (itemDescriptor === "json") {
|
@@ -1131,15 +1371,17 @@ function toRawItems(items, itemDescriptor, owner) {
|
|
1131
1371
|
rawItems = items?.map((e) => itemDescriptor.encoded.encode(e));
|
1132
1372
|
} else if (isRefEncoded(itemDescriptor)) {
|
1133
1373
|
rawItems = items?.map((value) => {
|
1134
|
-
if (value == null)
|
1135
|
-
|
1374
|
+
if (value == null) {
|
1375
|
+
return null;
|
1376
|
+
}
|
1377
|
+
let refId = value.$jazz?.id;
|
1136
1378
|
if (!refId) {
|
1137
1379
|
const coValue = instantiateRefEncodedWithInit(
|
1138
1380
|
itemDescriptor,
|
1139
1381
|
value,
|
1140
1382
|
owner
|
1141
1383
|
);
|
1142
|
-
refId = coValue.id;
|
1384
|
+
refId = coValue.$jazz.id;
|
1143
1385
|
}
|
1144
1386
|
return refId;
|
1145
1387
|
});
|
@@ -1151,8 +1393,8 @@ function toRawItems(items, itemDescriptor, owner) {
|
|
1151
1393
|
var CoListProxyHandler = {
|
1152
1394
|
get(target, key, receiver) {
|
1153
1395
|
if (typeof key === "string" && !isNaN(+key)) {
|
1154
|
-
const itemDescriptor = target.
|
1155
|
-
const rawValue = target.
|
1396
|
+
const itemDescriptor = target.$jazz.schema[ItemsSym];
|
1397
|
+
const rawValue = target.$jazz.raw.get(Number(key));
|
1156
1398
|
if (itemDescriptor === "json") {
|
1157
1399
|
return rawValue;
|
1158
1400
|
} else if ("encoded" in itemDescriptor) {
|
@@ -1161,7 +1403,7 @@ var CoListProxyHandler = {
|
|
1161
1403
|
return rawValue === void 0 || rawValue === null ? void 0 : accessChildByKey(target, rawValue, key);
|
1162
1404
|
}
|
1163
1405
|
} else if (key === "length") {
|
1164
|
-
return target.
|
1406
|
+
return target.$jazz.raw.entries().length;
|
1165
1407
|
} else {
|
1166
1408
|
return Reflect.get(target, key, receiver);
|
1167
1409
|
}
|
@@ -1173,31 +1415,7 @@ var CoListProxyHandler = {
|
|
1173
1415
|
return true;
|
1174
1416
|
}
|
1175
1417
|
if (typeof key === "string" && !isNaN(+key)) {
|
1176
|
-
|
1177
|
-
let rawValue;
|
1178
|
-
if (itemDescriptor === "json") {
|
1179
|
-
rawValue = value;
|
1180
|
-
} else if ("encoded" in itemDescriptor) {
|
1181
|
-
rawValue = itemDescriptor.encoded.encode(value);
|
1182
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
1183
|
-
if (value === void 0) {
|
1184
|
-
if (itemDescriptor.optional) {
|
1185
|
-
rawValue = null;
|
1186
|
-
} else {
|
1187
|
-
throw new Error(
|
1188
|
-
`Cannot set required reference ${key} to undefined`
|
1189
|
-
);
|
1190
|
-
}
|
1191
|
-
} else if (value?.id) {
|
1192
|
-
rawValue = value.id;
|
1193
|
-
} else {
|
1194
|
-
throw new Error(
|
1195
|
-
`Cannot set reference ${key} to a non-CoValue. Got ${value}`
|
1196
|
-
);
|
1197
|
-
}
|
1198
|
-
}
|
1199
|
-
target._raw.replace(Number(key), rawValue);
|
1200
|
-
return true;
|
1418
|
+
throw Error("Cannot update a CoList directly. Use `$jazz.set` instead.");
|
1201
1419
|
} else {
|
1202
1420
|
return Reflect.set(target, key, value, receiver);
|
1203
1421
|
}
|
@@ -1213,7 +1431,7 @@ var CoListProxyHandler = {
|
|
1213
1431
|
},
|
1214
1432
|
has(target, key) {
|
1215
1433
|
if (typeof key === "string" && !isNaN(+key)) {
|
1216
|
-
return Number(key) < target.
|
1434
|
+
return Number(key) < target.$jazz.raw.entries().length;
|
1217
1435
|
} else {
|
1218
1436
|
return Reflect.has(target, key);
|
1219
1437
|
}
|
@@ -1235,28 +1453,24 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1235
1453
|
* @category Declaration
|
1236
1454
|
*/
|
1237
1455
|
static Of(item) {
|
1238
|
-
var
|
1239
|
-
const cls = class CoFeedOf extends (_b = _CoFeed,
|
1456
|
+
var _a2, _b;
|
1457
|
+
const cls = class CoFeedOf extends (_b = _CoFeed, _a2 = coField.items, _b) {
|
1240
1458
|
constructor() {
|
1241
1459
|
super(...arguments);
|
1242
|
-
this[
|
1460
|
+
this[_a2] = item;
|
1243
1461
|
}
|
1244
1462
|
};
|
1245
1463
|
cls._schema ||= {};
|
1246
1464
|
cls._schema[ItemsSym] = item[SchemaInit];
|
1247
1465
|
return cls;
|
1248
1466
|
}
|
1249
|
-
/** @internal */
|
1250
|
-
get _schema() {
|
1251
|
-
return this.constructor._schema;
|
1252
|
-
}
|
1253
1467
|
/**
|
1254
1468
|
* The current account's view of this `CoFeed`
|
1255
1469
|
* @category Content
|
1256
1470
|
*/
|
1257
1471
|
get byMe() {
|
1258
|
-
if (this.
|
1259
|
-
return this.perAccount[this.
|
1472
|
+
if (this.$jazz.loadedAs[TypeSym] === "Account") {
|
1473
|
+
return this.perAccount[this.$jazz.loadedAs.$jazz.id];
|
1260
1474
|
} else {
|
1261
1475
|
return void 0;
|
1262
1476
|
}
|
@@ -1304,102 +1518,45 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1304
1518
|
* @category Content
|
1305
1519
|
*/
|
1306
1520
|
get inCurrentSession() {
|
1307
|
-
if (this.
|
1308
|
-
return this.perSession[this.
|
1521
|
+
if (this.$jazz.loadedAs[TypeSym] === "Account") {
|
1522
|
+
return this.perSession[this.$jazz.loadedAs.$jazz.sessionID];
|
1309
1523
|
} else {
|
1310
1524
|
return void 0;
|
1311
1525
|
}
|
1312
1526
|
}
|
1527
|
+
/** @internal */
|
1313
1528
|
constructor(options) {
|
1314
1529
|
super();
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
_raw: { value: options.fromRaw, enumerable: false }
|
1322
|
-
});
|
1323
|
-
}
|
1530
|
+
Object.defineProperties(this, {
|
1531
|
+
$jazz: {
|
1532
|
+
value: new CoFeedJazzApi(this, options.fromRaw),
|
1533
|
+
enumerable: false
|
1534
|
+
}
|
1535
|
+
});
|
1324
1536
|
return this;
|
1325
1537
|
}
|
1326
1538
|
/**
|
1327
1539
|
* Create a new `CoFeed`
|
1328
1540
|
* @category Creation
|
1541
|
+
* @deprecated Use `co.feed(...).create` instead.
|
1329
1542
|
*/
|
1330
1543
|
static create(init, options) {
|
1331
1544
|
const { owner } = parseCoValueCreateOptions(options);
|
1332
|
-
const
|
1333
|
-
const
|
1334
|
-
Object.defineProperties(instance, {
|
1335
|
-
id: {
|
1336
|
-
value: raw.id,
|
1337
|
-
enumerable: false
|
1338
|
-
},
|
1339
|
-
_raw: { value: raw, enumerable: false }
|
1340
|
-
});
|
1545
|
+
const raw = owner.$jazz.raw.createStream();
|
1546
|
+
const instance = new this({ fromRaw: raw });
|
1341
1547
|
if (init) {
|
1342
|
-
instance.push(...init);
|
1548
|
+
instance.$jazz.push(...init);
|
1343
1549
|
}
|
1344
1550
|
return instance;
|
1345
1551
|
}
|
1346
|
-
getItemsDescriptor() {
|
1347
|
-
return this._schema?.[ItemsSym];
|
1348
|
-
}
|
1349
|
-
/**
|
1350
|
-
* Push items to this `CoFeed`
|
1351
|
-
*
|
1352
|
-
* Items are appended to the current session's log. Each session (tab, device, app instance)
|
1353
|
-
* maintains its own append-only log, which is then aggregated into the per-account view.
|
1354
|
-
*
|
1355
|
-
* @example
|
1356
|
-
* ```ts
|
1357
|
-
* // Adds items to current session's log
|
1358
|
-
* feed.push("item1", "item2");
|
1359
|
-
*
|
1360
|
-
* // View items from current session
|
1361
|
-
* console.log(feed.inCurrentSession);
|
1362
|
-
*
|
1363
|
-
* // View aggregated items from all sessions for current account
|
1364
|
-
* console.log(feed.byMe);
|
1365
|
-
* ```
|
1366
|
-
*
|
1367
|
-
* @category Content
|
1368
|
-
*/
|
1369
|
-
push(...items) {
|
1370
|
-
for (const item of items) {
|
1371
|
-
this.pushItem(item);
|
1372
|
-
}
|
1373
|
-
}
|
1374
|
-
pushItem(item) {
|
1375
|
-
const itemDescriptor = this._schema[ItemsSym];
|
1376
|
-
if (itemDescriptor === "json") {
|
1377
|
-
this._raw.push(item);
|
1378
|
-
} else if ("encoded" in itemDescriptor) {
|
1379
|
-
this._raw.push(itemDescriptor.encoded.encode(item));
|
1380
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
1381
|
-
let refId = item.id;
|
1382
|
-
if (!refId) {
|
1383
|
-
const coValue = instantiateRefEncodedWithInit(
|
1384
|
-
itemDescriptor,
|
1385
|
-
item,
|
1386
|
-
this._owner
|
1387
|
-
);
|
1388
|
-
refId = coValue.id;
|
1389
|
-
}
|
1390
|
-
this._raw.push(refId);
|
1391
|
-
}
|
1392
|
-
}
|
1393
1552
|
/**
|
1394
1553
|
* Get a JSON representation of the `CoFeed`
|
1395
1554
|
* @category
|
1396
1555
|
*/
|
1397
1556
|
toJSON() {
|
1398
|
-
const itemDescriptor = this.
|
1399
|
-
const mapper = itemDescriptor === "json" ? (v) => v : "encoded" in itemDescriptor ? itemDescriptor.encoded.encode : (v) => v && v.id;
|
1557
|
+
const itemDescriptor = this.$jazz.schema[ItemsSym];
|
1558
|
+
const mapper = itemDescriptor === "json" ? (v) => v : "encoded" in itemDescriptor ? itemDescriptor.encoded.encode : (v) => v && v.$jazz.id;
|
1400
1559
|
return {
|
1401
|
-
id: this.id,
|
1402
|
-
_type: this._type,
|
1403
1560
|
...Object.fromEntries(
|
1404
1561
|
Object.entries(this).map(([account, entry]) => [
|
1405
1562
|
account,
|
@@ -1426,6 +1583,7 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1426
1583
|
/**
|
1427
1584
|
* Load a `CoFeed`
|
1428
1585
|
* @category Subscription & Loading
|
1586
|
+
* @deprecated Use `co.feed(...).load` instead.
|
1429
1587
|
*/
|
1430
1588
|
static load(id, options) {
|
1431
1589
|
return loadCoValueWithoutMe(this, id, options);
|
@@ -1434,6 +1592,69 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1434
1592
|
const { options, listener } = parseSubscribeRestArgs(args);
|
1435
1593
|
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
1436
1594
|
}
|
1595
|
+
};
|
1596
|
+
_CoFeed.prototype[TypeSym] = "CoStream";
|
1597
|
+
var CoFeed = _CoFeed;
|
1598
|
+
var CoFeedJazzApi = class extends CoValueJazzApi {
|
1599
|
+
constructor(coFeed, raw) {
|
1600
|
+
super(coFeed);
|
1601
|
+
this.coFeed = coFeed;
|
1602
|
+
this.raw = raw;
|
1603
|
+
}
|
1604
|
+
/**
|
1605
|
+
* The ID of this `CoFeed`
|
1606
|
+
* @category Content
|
1607
|
+
*/
|
1608
|
+
get id() {
|
1609
|
+
return this.raw.id;
|
1610
|
+
}
|
1611
|
+
get owner() {
|
1612
|
+
return getCoValueOwner(this.coFeed);
|
1613
|
+
}
|
1614
|
+
/**
|
1615
|
+
* Push items to this `CoFeed`
|
1616
|
+
*
|
1617
|
+
* Items are appended to the current session's log. Each session (tab, device, app instance)
|
1618
|
+
* maintains its own append-only log, which is then aggregated into the per-account view.
|
1619
|
+
*
|
1620
|
+
* @example
|
1621
|
+
* ```ts
|
1622
|
+
* // Adds items to current session's log
|
1623
|
+
* feed.$jazz.push("item1", "item2");
|
1624
|
+
*
|
1625
|
+
* // View items from current session
|
1626
|
+
* console.log(feed.inCurrentSession);
|
1627
|
+
*
|
1628
|
+
* // View aggregated items from all sessions for current account
|
1629
|
+
* console.log(feed.byMe);
|
1630
|
+
* ```
|
1631
|
+
*
|
1632
|
+
* @category Content
|
1633
|
+
*/
|
1634
|
+
push(...items) {
|
1635
|
+
for (const item of items) {
|
1636
|
+
this.pushItem(item);
|
1637
|
+
}
|
1638
|
+
}
|
1639
|
+
pushItem(item) {
|
1640
|
+
const itemDescriptor = this.schema[ItemsSym];
|
1641
|
+
if (itemDescriptor === "json") {
|
1642
|
+
this.raw.push(item);
|
1643
|
+
} else if ("encoded" in itemDescriptor) {
|
1644
|
+
this.raw.push(itemDescriptor.encoded.encode(item));
|
1645
|
+
} else if (isRefEncoded(itemDescriptor)) {
|
1646
|
+
let refId = item.$jazz?.id;
|
1647
|
+
if (!refId) {
|
1648
|
+
const coValue = instantiateRefEncodedWithInit(
|
1649
|
+
itemDescriptor,
|
1650
|
+
item,
|
1651
|
+
this.owner
|
1652
|
+
);
|
1653
|
+
refId = coValue.$jazz.id;
|
1654
|
+
}
|
1655
|
+
this.raw.push(refId);
|
1656
|
+
}
|
1657
|
+
}
|
1437
1658
|
/**
|
1438
1659
|
* Ensure a `CoFeed` is loaded to the specified depth
|
1439
1660
|
*
|
@@ -1441,11 +1662,11 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1441
1662
|
* @category Subscription & Loading
|
1442
1663
|
*/
|
1443
1664
|
ensureLoaded(options) {
|
1444
|
-
return ensureCoValueLoaded(this, options);
|
1665
|
+
return ensureCoValueLoaded(this.coFeed, options);
|
1445
1666
|
}
|
1446
1667
|
subscribe(...args) {
|
1447
1668
|
const { options, listener } = parseSubscribeRestArgs(args);
|
1448
|
-
return subscribeToExistingCoValue(this, options, listener);
|
1669
|
+
return subscribeToExistingCoValue(this.coFeed, options, listener);
|
1449
1670
|
}
|
1450
1671
|
/**
|
1451
1672
|
* Wait for the `CoFeed` to be uploaded to the other peers.
|
@@ -1453,11 +1674,20 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1453
1674
|
* @category Subscription & Loading
|
1454
1675
|
*/
|
1455
1676
|
waitForSync(options) {
|
1456
|
-
return this.
|
1677
|
+
return this.raw.core.waitForSync(options);
|
1678
|
+
}
|
1679
|
+
/**
|
1680
|
+
* Get the descriptor for the items in the `CoFeed`
|
1681
|
+
* @internal
|
1682
|
+
*/
|
1683
|
+
getItemsDescriptor() {
|
1684
|
+
return this.schema[ItemsSym];
|
1685
|
+
}
|
1686
|
+
/** @internal */
|
1687
|
+
get schema() {
|
1688
|
+
return this.coFeed.constructor._schema;
|
1457
1689
|
}
|
1458
1690
|
};
|
1459
|
-
_CoFeed.prototype._type = "CoStream";
|
1460
|
-
var CoFeed = _CoFeed;
|
1461
1691
|
function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField) {
|
1462
1692
|
return {
|
1463
1693
|
get value() {
|
@@ -1501,18 +1731,20 @@ function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField)
|
|
1501
1731
|
var CoStreamPerAccountProxyHandler = (innerTarget) => ({
|
1502
1732
|
get(_target, key, receiver) {
|
1503
1733
|
if (typeof key === "string" && key.startsWith("co_")) {
|
1504
|
-
const rawEntry = innerTarget.
|
1734
|
+
const rawEntry = innerTarget.$jazz.raw.lastItemBy(key);
|
1505
1735
|
if (!rawEntry) return;
|
1506
1736
|
const entry = entryFromRawEntry(
|
1507
1737
|
receiver,
|
1508
1738
|
rawEntry,
|
1509
|
-
innerTarget.
|
1739
|
+
innerTarget.$jazz.loadedAs,
|
1510
1740
|
key,
|
1511
|
-
innerTarget.
|
1741
|
+
innerTarget.$jazz.schema[ItemsSym]
|
1512
1742
|
);
|
1513
1743
|
Object.defineProperty(entry, "all", {
|
1514
1744
|
get: () => {
|
1515
|
-
const allRawEntries = innerTarget.
|
1745
|
+
const allRawEntries = innerTarget.$jazz.raw.itemsBy(
|
1746
|
+
key
|
1747
|
+
);
|
1516
1748
|
return function* () {
|
1517
1749
|
while (true) {
|
1518
1750
|
const rawEntry2 = allRawEntries.next();
|
@@ -1520,9 +1752,9 @@ var CoStreamPerAccountProxyHandler = (innerTarget) => ({
|
|
1520
1752
|
yield entryFromRawEntry(
|
1521
1753
|
receiver,
|
1522
1754
|
rawEntry2.value,
|
1523
|
-
innerTarget.
|
1755
|
+
innerTarget.$jazz.loadedAs,
|
1524
1756
|
key,
|
1525
|
-
innerTarget.
|
1757
|
+
innerTarget.$jazz.schema[ItemsSym]
|
1526
1758
|
);
|
1527
1759
|
}
|
1528
1760
|
}();
|
@@ -1534,7 +1766,7 @@ var CoStreamPerAccountProxyHandler = (innerTarget) => ({
|
|
1534
1766
|
}
|
1535
1767
|
},
|
1536
1768
|
ownKeys(_target) {
|
1537
|
-
return Array.from(innerTarget.
|
1769
|
+
return Array.from(innerTarget.$jazz.raw.accounts());
|
1538
1770
|
},
|
1539
1771
|
getOwnPropertyDescriptor(_target, key) {
|
1540
1772
|
if (typeof key === "string" && key.startsWith("co_")) {
|
@@ -1552,19 +1784,19 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
|
|
1552
1784
|
get(_target, key, receiver) {
|
1553
1785
|
if (typeof key === "string" && key.includes("session")) {
|
1554
1786
|
const sessionID = key;
|
1555
|
-
const rawEntry = innerTarget.
|
1787
|
+
const rawEntry = innerTarget.$jazz.raw.lastItemIn(sessionID);
|
1556
1788
|
if (!rawEntry) return;
|
1557
1789
|
const by = cojsonInternals3.accountOrAgentIDfromSessionID(sessionID);
|
1558
1790
|
const entry = entryFromRawEntry(
|
1559
1791
|
accessFrom,
|
1560
1792
|
rawEntry,
|
1561
|
-
innerTarget.
|
1793
|
+
innerTarget.$jazz.loadedAs,
|
1562
1794
|
cojsonInternals3.isAccountID(by) ? by : void 0,
|
1563
|
-
innerTarget.
|
1795
|
+
innerTarget.$jazz.schema[ItemsSym]
|
1564
1796
|
);
|
1565
1797
|
Object.defineProperty(entry, "all", {
|
1566
1798
|
get: () => {
|
1567
|
-
const allRawEntries = innerTarget.
|
1799
|
+
const allRawEntries = innerTarget.$jazz.raw.itemsIn(sessionID);
|
1568
1800
|
return function* () {
|
1569
1801
|
while (true) {
|
1570
1802
|
const rawEntry2 = allRawEntries.next();
|
@@ -1572,9 +1804,9 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
|
|
1572
1804
|
yield entryFromRawEntry(
|
1573
1805
|
accessFrom,
|
1574
1806
|
rawEntry2.value,
|
1575
|
-
innerTarget.
|
1807
|
+
innerTarget.$jazz.loadedAs,
|
1576
1808
|
cojsonInternals3.isAccountID(by) ? by : void 0,
|
1577
|
-
innerTarget.
|
1809
|
+
innerTarget.$jazz.schema[ItemsSym]
|
1578
1810
|
);
|
1579
1811
|
}
|
1580
1812
|
}();
|
@@ -1586,7 +1818,7 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
|
|
1586
1818
|
}
|
1587
1819
|
},
|
1588
1820
|
ownKeys() {
|
1589
|
-
return innerTarget.
|
1821
|
+
return innerTarget.$jazz.raw.sessions();
|
1590
1822
|
},
|
1591
1823
|
getOwnPropertyDescriptor(target, key) {
|
1592
1824
|
if (typeof key === "string" && key.startsWith("co_")) {
|
@@ -1607,16 +1839,15 @@ var FileStream = class extends CoValueBase {
|
|
1607
1839
|
if ("fromRaw" in options) {
|
1608
1840
|
raw = options.fromRaw;
|
1609
1841
|
} else {
|
1610
|
-
const rawOwner = options.owner.
|
1842
|
+
const rawOwner = options.owner.$jazz.raw;
|
1611
1843
|
raw = rawOwner.createBinaryStream();
|
1612
1844
|
}
|
1613
1845
|
Object.defineProperties(this, {
|
1614
|
-
|
1615
|
-
|
1846
|
+
[TypeSym]: { value: "BinaryCoStream", enumerable: false },
|
1847
|
+
$jazz: {
|
1848
|
+
value: new FileStreamJazzApi(this, raw),
|
1616
1849
|
enumerable: false
|
1617
|
-
}
|
1618
|
-
_type: { value: "BinaryCoStream", enumerable: false },
|
1619
|
-
_raw: { value: raw, enumerable: false }
|
1850
|
+
}
|
1620
1851
|
});
|
1621
1852
|
}
|
1622
1853
|
/**
|
@@ -1641,27 +1872,28 @@ var FileStream = class extends CoValueBase {
|
|
1641
1872
|
* For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead.
|
1642
1873
|
*
|
1643
1874
|
* @category Creation
|
1875
|
+
* @deprecated Use `co.fileStream(...).create` instead.
|
1644
1876
|
*/
|
1645
1877
|
static create(options) {
|
1646
1878
|
return new this(parseCoValueCreateOptions(options));
|
1647
1879
|
}
|
1648
1880
|
getMetadata() {
|
1649
|
-
return this.
|
1881
|
+
return this.$jazz.raw.getBinaryStreamInfo();
|
1650
1882
|
}
|
1651
1883
|
getChunks(options) {
|
1652
|
-
return this.
|
1884
|
+
return this.$jazz.raw.getBinaryChunks(options?.allowUnfinished);
|
1653
1885
|
}
|
1654
1886
|
isBinaryStreamEnded() {
|
1655
|
-
return this.
|
1887
|
+
return this.$jazz.raw.isBinaryStreamEnded();
|
1656
1888
|
}
|
1657
1889
|
start(options) {
|
1658
|
-
this.
|
1890
|
+
this.$jazz.raw.startBinaryStream(options);
|
1659
1891
|
}
|
1660
1892
|
push(data) {
|
1661
|
-
this.
|
1893
|
+
this.$jazz.raw.pushBinaryStreamChunk(data);
|
1662
1894
|
}
|
1663
1895
|
end() {
|
1664
|
-
this.
|
1896
|
+
this.$jazz.raw.endBinaryStream();
|
1665
1897
|
}
|
1666
1898
|
toBlob(options) {
|
1667
1899
|
const chunks = this.getChunks({
|
@@ -1676,6 +1908,7 @@ var FileStream = class extends CoValueBase {
|
|
1676
1908
|
* Load a `FileStream` as a `Blob`
|
1677
1909
|
*
|
1678
1910
|
* @category Content
|
1911
|
+
* @deprecated Use `co.fileStream(...).loadAsBlob` instead.
|
1679
1912
|
*/
|
1680
1913
|
static async loadAsBlob(id, options) {
|
1681
1914
|
let stream = await this.load(id, options);
|
@@ -1712,6 +1945,7 @@ var FileStream = class extends CoValueBase {
|
|
1712
1945
|
* const fileStream = await FileStream.createFromBlob(file, {owner: group})
|
1713
1946
|
* ```
|
1714
1947
|
* @category Content
|
1948
|
+
* @deprecated Use `co.fileStream(...).createFromBlob` instead.
|
1715
1949
|
*/
|
1716
1950
|
static async createFromBlob(blob, options) {
|
1717
1951
|
const arrayBuffer = await blob.arrayBuffer();
|
@@ -1732,6 +1966,7 @@ var FileStream = class extends CoValueBase {
|
|
1732
1966
|
* const fileStream = await FileStream.createFromBlob(file, {owner: group})
|
1733
1967
|
* ```
|
1734
1968
|
* @category Content
|
1969
|
+
* @deprecated Use `co.fileStream(...).createFromArrayBuffer` instead.
|
1735
1970
|
*/
|
1736
1971
|
static async createFromArrayBuffer(arrayBuffer, mimeType, fileName, options) {
|
1737
1972
|
const stream = this.create(options);
|
@@ -1770,8 +2005,6 @@ var FileStream = class extends CoValueBase {
|
|
1770
2005
|
*/
|
1771
2006
|
toJSON() {
|
1772
2007
|
return {
|
1773
|
-
id: this.id,
|
1774
|
-
_type: this._type,
|
1775
2008
|
...this.getChunks()
|
1776
2009
|
};
|
1777
2010
|
}
|
@@ -1782,6 +2015,7 @@ var FileStream = class extends CoValueBase {
|
|
1782
2015
|
/**
|
1783
2016
|
* Load a `FileStream`
|
1784
2017
|
* @category Subscription & Loading
|
2018
|
+
* @deprecated Use `co.fileStream(...).load` instead.
|
1785
2019
|
*/
|
1786
2020
|
static async load(id, options) {
|
1787
2021
|
const stream = await loadCoValueWithoutMe(this, id, options);
|
@@ -1806,12 +2040,29 @@ var FileStream = class extends CoValueBase {
|
|
1806
2040
|
const { options, listener } = parseSubscribeRestArgs(args);
|
1807
2041
|
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
1808
2042
|
}
|
2043
|
+
};
|
2044
|
+
var FileStreamJazzApi = class extends CoValueJazzApi {
|
2045
|
+
constructor(fileStream, raw) {
|
2046
|
+
super(fileStream);
|
2047
|
+
this.fileStream = fileStream;
|
2048
|
+
this.raw = raw;
|
2049
|
+
}
|
2050
|
+
/**
|
2051
|
+
* The ID of this `FileStream`
|
2052
|
+
* @category Content
|
2053
|
+
*/
|
2054
|
+
get id() {
|
2055
|
+
return this.raw.id;
|
2056
|
+
}
|
2057
|
+
get owner() {
|
2058
|
+
return getCoValueOwner(this.fileStream);
|
2059
|
+
}
|
1809
2060
|
/**
|
1810
2061
|
* An instance method to subscribe to an existing `FileStream`
|
1811
2062
|
* @category Subscription & Loading
|
1812
2063
|
*/
|
1813
2064
|
subscribe(listener) {
|
1814
|
-
return subscribeToExistingCoValue(this, {}, listener);
|
2065
|
+
return subscribeToExistingCoValue(this.fileStream, {}, listener);
|
1815
2066
|
}
|
1816
2067
|
/**
|
1817
2068
|
* Wait for the `FileStream` to be uploaded to the other peers.
|
@@ -1819,146 +2070,114 @@ var FileStream = class extends CoValueBase {
|
|
1819
2070
|
* @category Subscription & Loading
|
1820
2071
|
*/
|
1821
2072
|
waitForSync(options) {
|
1822
|
-
return this.
|
2073
|
+
return this.raw.core.waitForSync(options);
|
1823
2074
|
}
|
1824
2075
|
};
|
1825
2076
|
|
1826
2077
|
// src/tools/coValues/account.ts
|
1827
2078
|
import {
|
1828
|
-
ControlledAccount as
|
1829
|
-
LocalNode,
|
2079
|
+
ControlledAccount as RawControlledAccount,
|
2080
|
+
LocalNode as LocalNode2,
|
1830
2081
|
cojsonInternals as cojsonInternals4
|
1831
2082
|
} from "cojson";
|
1832
|
-
var
|
1833
|
-
get _schema() {
|
1834
|
-
return this.constructor._schema;
|
1835
|
-
}
|
1836
|
-
get _owner() {
|
1837
|
-
return this;
|
1838
|
-
}
|
1839
|
-
get _loadedAs() {
|
1840
|
-
if (this.isLocalNodeOwner) return this;
|
1841
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
1842
|
-
if (agent instanceof ControlledAccount3) {
|
1843
|
-
return coValuesCache.get(
|
1844
|
-
agent.account,
|
1845
|
-
() => _Account.fromRaw(agent.account)
|
1846
|
-
);
|
1847
|
-
}
|
1848
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
1849
|
-
}
|
1850
|
-
getDescriptor(key) {
|
1851
|
-
if (key === "profile") {
|
1852
|
-
return this._schema.profile;
|
1853
|
-
} else if (key === "root") {
|
1854
|
-
return this._schema.root;
|
1855
|
-
}
|
1856
|
-
return void 0;
|
1857
|
-
}
|
1858
|
-
get _refs() {
|
1859
|
-
const profileID = this._raw.get("profile");
|
1860
|
-
const rootID = this._raw.get("root");
|
1861
|
-
return {
|
1862
|
-
profile: profileID ? new Ref(
|
1863
|
-
profileID,
|
1864
|
-
this._loadedAs,
|
1865
|
-
this._schema.profile,
|
1866
|
-
this
|
1867
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1868
|
-
) : void 0,
|
1869
|
-
root: rootID ? new Ref(
|
1870
|
-
rootID,
|
1871
|
-
this._loadedAs,
|
1872
|
-
this._schema.root,
|
1873
|
-
this
|
1874
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1875
|
-
) : void 0
|
1876
|
-
};
|
1877
|
-
}
|
1878
|
-
/**
|
1879
|
-
* Whether this account is the currently active account.
|
1880
|
-
*/
|
1881
|
-
get isMe() {
|
1882
|
-
return activeAccountContext.get().id === this.id;
|
1883
|
-
}
|
2083
|
+
var Account = class extends CoValueBase {
|
1884
2084
|
constructor(options) {
|
1885
2085
|
super();
|
1886
2086
|
if (!("fromRaw" in options)) {
|
1887
2087
|
throw new Error("Can only construct account from raw or with .create()");
|
1888
2088
|
}
|
1889
|
-
|
2089
|
+
const proxy = new Proxy(
|
2090
|
+
this,
|
2091
|
+
AccountAndGroupProxyHandler
|
2092
|
+
);
|
1890
2093
|
Object.defineProperties(this, {
|
1891
|
-
|
1892
|
-
|
2094
|
+
[TypeSym]: { value: "Account", enumerable: false },
|
2095
|
+
$jazz: {
|
2096
|
+
value: new AccountJazzApi(proxy, options.fromRaw),
|
1893
2097
|
enumerable: false
|
1894
|
-
}
|
1895
|
-
_raw: { value: options.fromRaw, enumerable: false },
|
1896
|
-
_type: { value: "Account", enumerable: false }
|
2098
|
+
}
|
1897
2099
|
});
|
1898
|
-
|
1899
|
-
this.sessionID = options.fromRaw.core.node.currentSessionID;
|
1900
|
-
}
|
1901
|
-
return new Proxy(this, AccountAndGroupProxyHandler);
|
2100
|
+
return proxy;
|
1902
2101
|
}
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
2102
|
+
/**
|
2103
|
+
* Whether this account is the currently active account.
|
2104
|
+
*/
|
2105
|
+
get isMe() {
|
2106
|
+
return activeAccountContext.get().$jazz.id === this.$jazz.id;
|
2107
|
+
}
|
2108
|
+
/**
|
2109
|
+
* Accept an invite to a `CoValue` or `Group`.
|
2110
|
+
*
|
2111
|
+
* @param valueID The ID of the `CoValue` or `Group` to accept the invite to.
|
2112
|
+
* @param inviteSecret The secret of the invite to accept.
|
2113
|
+
* @param coValueClass The class of the `CoValue` or `Group` to accept the invite to.
|
2114
|
+
* @returns The loaded `CoValue` or `Group`.
|
2115
|
+
*/
|
2116
|
+
async acceptInvite(valueID, inviteSecret, coValueClass) {
|
2117
|
+
if (!this.$jazz.isLocalNodeOwner) {
|
2118
|
+
throw new Error("Only a controlled account can accept invites");
|
1906
2119
|
}
|
2120
|
+
await this.$jazz.localNode.acceptInvite(
|
2121
|
+
valueID,
|
2122
|
+
inviteSecret
|
2123
|
+
);
|
2124
|
+
return loadCoValue(
|
2125
|
+
coValueClassFromCoValueClassOrSchema(coValueClass),
|
2126
|
+
valueID,
|
2127
|
+
{
|
2128
|
+
loadAs: this
|
2129
|
+
}
|
2130
|
+
);
|
1907
2131
|
}
|
1908
2132
|
getRoleOf(member) {
|
1909
2133
|
if (member === "me") {
|
1910
2134
|
return this.isMe ? "admin" : void 0;
|
1911
2135
|
}
|
1912
|
-
if (member === this.id) {
|
2136
|
+
if (member === this.$jazz.id) {
|
1913
2137
|
return "admin";
|
1914
2138
|
}
|
1915
2139
|
return void 0;
|
1916
2140
|
}
|
1917
|
-
getParentGroups() {
|
1918
|
-
return [];
|
1919
|
-
}
|
1920
|
-
get members() {
|
1921
|
-
const ref2 = new Ref(
|
1922
|
-
this.id,
|
1923
|
-
this._loadedAs,
|
1924
|
-
{
|
1925
|
-
ref: () => this.constructor,
|
1926
|
-
optional: false
|
1927
|
-
},
|
1928
|
-
this
|
1929
|
-
);
|
1930
|
-
return [{ id: this.id, role: "admin", ref: ref2, account: this }];
|
1931
|
-
}
|
1932
2141
|
canRead(value) {
|
1933
|
-
const
|
2142
|
+
const valueOwner = value.$jazz.owner;
|
2143
|
+
if (!valueOwner) {
|
2144
|
+
return true;
|
2145
|
+
}
|
2146
|
+
const role = valueOwner.getRoleOf(this.$jazz.id);
|
1934
2147
|
return role === "admin" || role === "writer" || role === "reader" || role === "writeOnly";
|
1935
2148
|
}
|
1936
2149
|
canWrite(value) {
|
1937
|
-
const
|
2150
|
+
const valueOwner = value.$jazz.owner;
|
2151
|
+
if (!valueOwner) {
|
2152
|
+
if (value[TypeSym] === "Group") {
|
2153
|
+
const roleInGroup = value.getRoleOf(this.$jazz.id);
|
2154
|
+
return roleInGroup === "admin" || roleInGroup === "writer";
|
2155
|
+
}
|
2156
|
+
if (value[TypeSym] === "Account") {
|
2157
|
+
return value.$jazz.id === this.$jazz.id;
|
2158
|
+
}
|
2159
|
+
return false;
|
2160
|
+
}
|
2161
|
+
const role = valueOwner.getRoleOf(this.$jazz.id);
|
1938
2162
|
return role === "admin" || role === "writer" || role === "writeOnly";
|
1939
2163
|
}
|
1940
2164
|
canAdmin(value) {
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
}
|
1947
|
-
await this._raw.core.node.acceptInvite(
|
1948
|
-
valueID,
|
1949
|
-
inviteSecret
|
1950
|
-
);
|
1951
|
-
return loadCoValue(
|
1952
|
-
coValueClassFromCoValueClassOrSchema(coValueClass),
|
1953
|
-
valueID,
|
1954
|
-
{
|
1955
|
-
loadAs: this
|
2165
|
+
const valueOwner = value.$jazz.owner;
|
2166
|
+
if (!valueOwner) {
|
2167
|
+
if (value[TypeSym] === "Group") {
|
2168
|
+
const roleInGroup = value.getRoleOf(this.$jazz.id);
|
2169
|
+
return roleInGroup === "admin";
|
1956
2170
|
}
|
1957
|
-
|
2171
|
+
if (value[TypeSym] === "Account") {
|
2172
|
+
return value.$jazz.id === this.$jazz.id;
|
2173
|
+
}
|
2174
|
+
return false;
|
2175
|
+
}
|
2176
|
+
return valueOwner.getRoleOf(this.$jazz.id) === "admin";
|
1958
2177
|
}
|
1959
2178
|
/** @private */
|
1960
2179
|
static async create(options) {
|
1961
|
-
const { node } = await
|
2180
|
+
const { node } = await LocalNode2.withNewlyCreatedAccount({
|
1962
2181
|
...options,
|
1963
2182
|
migration: async (rawAccount, _node, creationProps) => {
|
1964
2183
|
const account = new this({
|
@@ -1972,19 +2191,22 @@ var _Account = class _Account extends CoValueBase {
|
|
1972
2191
|
static getMe() {
|
1973
2192
|
return activeAccountContext.get();
|
1974
2193
|
}
|
2194
|
+
/**
|
2195
|
+
* @deprecated Use `co.account(...).createAs` instead.
|
2196
|
+
*/
|
1975
2197
|
static async createAs(as, options) {
|
1976
2198
|
const connectedPeers = cojsonInternals4.connectedPeers(
|
1977
2199
|
"creatingAccount",
|
1978
2200
|
"createdAccount",
|
1979
2201
|
{ peer1role: "server", peer2role: "client" }
|
1980
2202
|
);
|
1981
|
-
as.
|
2203
|
+
as.$jazz.localNode.syncManager.addPeer(connectedPeers[1]);
|
1982
2204
|
const account = await this.create({
|
1983
2205
|
creationProps: options.creationProps,
|
1984
|
-
crypto: as.
|
2206
|
+
crypto: as.$jazz.localNode.crypto,
|
1985
2207
|
peersToLoadFrom: [connectedPeers[0]]
|
1986
2208
|
});
|
1987
|
-
await account.waitForAllCoValuesSync();
|
2209
|
+
await account.$jazz.waitForAllCoValuesSync();
|
1988
2210
|
return account;
|
1989
2211
|
}
|
1990
2212
|
static fromNode(node) {
|
@@ -1994,10 +2216,7 @@ var _Account = class _Account extends CoValueBase {
|
|
1994
2216
|
}
|
1995
2217
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1996
2218
|
toJSON() {
|
1997
|
-
return {
|
1998
|
-
id: this.id,
|
1999
|
-
_type: this._type
|
2000
|
-
};
|
2219
|
+
return {};
|
2001
2220
|
}
|
2002
2221
|
[inspect]() {
|
2003
2222
|
return this.toJSON();
|
@@ -2006,17 +2225,13 @@ var _Account = class _Account extends CoValueBase {
|
|
2006
2225
|
await this.migrate(creationProps);
|
2007
2226
|
if (this.profile === void 0 && creationProps) {
|
2008
2227
|
const profileGroup = RegisteredSchemas["Group"].create({ owner: this });
|
2009
|
-
this.
|
2228
|
+
this.$jazz.set(
|
2229
|
+
"profile",
|
2230
|
+
Profile.create({ name: creationProps.name }, profileGroup)
|
2231
|
+
);
|
2010
2232
|
profileGroup.addMember("everyone", "reader");
|
2011
|
-
} else if (this.profile && creationProps) {
|
2012
|
-
if (this.profile._owner._type !== "Group") {
|
2013
|
-
throw new Error("Profile must be owned by a Group", {
|
2014
|
-
cause: `The profile of the account "${this.id}" was created with an Account as owner, which is not allowed.`
|
2015
|
-
});
|
2016
|
-
}
|
2017
2233
|
}
|
2018
|
-
const
|
2019
|
-
const profile = node.expectCoValueLoaded(this._raw.get("profile")).getCurrentContent();
|
2234
|
+
const profile = this.$jazz.localNode.expectCoValueLoaded(this.$jazz.raw.get("profile")).getCurrentContent();
|
2020
2235
|
if (!profile.get("inbox")) {
|
2021
2236
|
const inboxRoot = createInboxRoot(this);
|
2022
2237
|
profile.set("inbox", inboxRoot.id);
|
@@ -2027,7 +2242,11 @@ var _Account = class _Account extends CoValueBase {
|
|
2027
2242
|
migrate(creationProps) {
|
2028
2243
|
creationProps;
|
2029
2244
|
}
|
2030
|
-
/**
|
2245
|
+
/**
|
2246
|
+
* Load an `Account`
|
2247
|
+
* @category Subscription & Loading
|
2248
|
+
* @deprecated Use `co.account(...).load` instead.
|
2249
|
+
*/
|
2031
2250
|
static load(id, options) {
|
2032
2251
|
return loadCoValueWithoutMe(this, id, options);
|
2033
2252
|
}
|
@@ -2035,13 +2254,113 @@ var _Account = class _Account extends CoValueBase {
|
|
2035
2254
|
const { options, listener } = parseSubscribeRestArgs(args);
|
2036
2255
|
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
2037
2256
|
}
|
2257
|
+
};
|
2258
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2259
|
+
Account._schema = {
|
2260
|
+
profile: {
|
2261
|
+
ref: () => Profile,
|
2262
|
+
optional: false
|
2263
|
+
},
|
2264
|
+
root: {
|
2265
|
+
ref: () => RegisteredSchemas["CoMap"],
|
2266
|
+
optional: true
|
2267
|
+
}
|
2268
|
+
};
|
2269
|
+
var AccountJazzApi = class extends CoValueJazzApi {
|
2270
|
+
constructor(account, raw) {
|
2271
|
+
super(account);
|
2272
|
+
this.account = account;
|
2273
|
+
this.raw = raw;
|
2274
|
+
this.isLocalNodeOwner = this.raw.id === this.localNode.getCurrentAgent().id;
|
2275
|
+
if (this.isLocalNodeOwner) {
|
2276
|
+
this.sessionID = this.localNode.currentSessionID;
|
2277
|
+
}
|
2278
|
+
}
|
2279
|
+
/**
|
2280
|
+
* The ID of this `Account`
|
2281
|
+
* @category Content
|
2282
|
+
*/
|
2283
|
+
get id() {
|
2284
|
+
return this.raw.id;
|
2285
|
+
}
|
2286
|
+
/**
|
2287
|
+
* Accounts have no owner. They can be accessed by everyone.
|
2288
|
+
*/
|
2289
|
+
get owner() {
|
2290
|
+
return void 0;
|
2291
|
+
}
|
2292
|
+
/**
|
2293
|
+
* Set the value of a key in the account.
|
2294
|
+
*
|
2295
|
+
* @param key The key to set.
|
2296
|
+
* @param value The value to set.
|
2297
|
+
*
|
2298
|
+
* @category Content
|
2299
|
+
*/
|
2300
|
+
set(key, value) {
|
2301
|
+
if (value) {
|
2302
|
+
let refId = value.$jazz?.id;
|
2303
|
+
if (!refId) {
|
2304
|
+
const descriptor = this.schema[key];
|
2305
|
+
const coValue = instantiateRefEncodedWithInit(
|
2306
|
+
descriptor,
|
2307
|
+
value,
|
2308
|
+
accountOrGroupToGroup(this.account)
|
2309
|
+
);
|
2310
|
+
refId = coValue.$jazz.id;
|
2311
|
+
}
|
2312
|
+
this.raw.set(key, refId, "trusting");
|
2313
|
+
}
|
2314
|
+
}
|
2315
|
+
has(key) {
|
2316
|
+
const entry = this.raw.getRaw(key);
|
2317
|
+
return entry?.change !== void 0 && entry.change.op !== "del";
|
2318
|
+
}
|
2319
|
+
/**
|
2320
|
+
* Get the descriptor for a given key
|
2321
|
+
* @internal
|
2322
|
+
*/
|
2323
|
+
getDescriptor(key) {
|
2324
|
+
if (key === "profile") {
|
2325
|
+
return this.schema.profile;
|
2326
|
+
} else if (key === "root") {
|
2327
|
+
return this.schema.root;
|
2328
|
+
}
|
2329
|
+
return void 0;
|
2330
|
+
}
|
2331
|
+
/**
|
2332
|
+
* If property `prop` is a `coField.ref(...)`, you can use `account.$jazz.refs.prop` to access
|
2333
|
+
* the `Ref` instead of the potentially loaded/null value.
|
2334
|
+
*
|
2335
|
+
* This allows you to always get the ID or load the value manually.
|
2336
|
+
*
|
2337
|
+
* @category Content
|
2338
|
+
*/
|
2339
|
+
get refs() {
|
2340
|
+
const profileID = this.raw.get("profile");
|
2341
|
+
const rootID = this.raw.get("root");
|
2342
|
+
return {
|
2343
|
+
profile: profileID ? new Ref(
|
2344
|
+
profileID,
|
2345
|
+
this.loadedAs,
|
2346
|
+
this.schema.profile,
|
2347
|
+
this.account
|
2348
|
+
) : void 0,
|
2349
|
+
root: rootID ? new Ref(
|
2350
|
+
rootID,
|
2351
|
+
this.loadedAs,
|
2352
|
+
this.schema.root,
|
2353
|
+
this.account
|
2354
|
+
) : void 0
|
2355
|
+
};
|
2356
|
+
}
|
2038
2357
|
/** @category Subscription & Loading */
|
2039
2358
|
ensureLoaded(options) {
|
2040
|
-
return ensureCoValueLoaded(this, options);
|
2359
|
+
return ensureCoValueLoaded(this.account, options);
|
2041
2360
|
}
|
2042
2361
|
subscribe(...args) {
|
2043
2362
|
const { options, listener } = parseSubscribeRestArgs(args);
|
2044
|
-
return subscribeToExistingCoValue(this, options, listener);
|
2363
|
+
return subscribeToExistingCoValue(this.account, options, listener);
|
2045
2364
|
}
|
2046
2365
|
/**
|
2047
2366
|
* Wait for the `Account` to be uploaded to the other peers.
|
@@ -2049,7 +2368,7 @@ var _Account = class _Account extends CoValueBase {
|
|
2049
2368
|
* @category Subscription & Loading
|
2050
2369
|
*/
|
2051
2370
|
waitForSync(options) {
|
2052
|
-
return this.
|
2371
|
+
return this.raw.core.waitForSync(options);
|
2053
2372
|
}
|
2054
2373
|
/**
|
2055
2374
|
* Wait for all the available `CoValues` to be uploaded to the other peers.
|
@@ -2057,26 +2376,28 @@ var _Account = class _Account extends CoValueBase {
|
|
2057
2376
|
* @category Subscription & Loading
|
2058
2377
|
*/
|
2059
2378
|
waitForAllCoValuesSync(options) {
|
2060
|
-
return this.
|
2061
|
-
options?.timeout
|
2062
|
-
);
|
2379
|
+
return this.localNode.syncManager.waitForAllCoValuesSync(options?.timeout);
|
2063
2380
|
}
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2381
|
+
/** @internal */
|
2382
|
+
get schema() {
|
2383
|
+
return this.account.constructor._schema;
|
2384
|
+
}
|
2385
|
+
get loadedAs() {
|
2386
|
+
if (this.isLocalNodeOwner) return this.account;
|
2387
|
+
const agent = this.localNode.getCurrentAgent();
|
2388
|
+
if (agent instanceof RawControlledAccount) {
|
2389
|
+
return coValuesCache.get(
|
2390
|
+
agent.account,
|
2391
|
+
() => Account.fromRaw(agent.account)
|
2392
|
+
);
|
2393
|
+
}
|
2394
|
+
return new AnonymousJazzAgent(this.localNode);
|
2073
2395
|
}
|
2074
2396
|
};
|
2075
|
-
var Account = _Account;
|
2076
2397
|
var AccountAndGroupProxyHandler = {
|
2077
2398
|
get(target, key, receiver) {
|
2078
2399
|
if (key === "profile" || key === "root") {
|
2079
|
-
const id = target.
|
2400
|
+
const id = target.$jazz.raw.get(key);
|
2080
2401
|
if (id) {
|
2081
2402
|
return accessChildByKey(target, id, key);
|
2082
2403
|
} else {
|
@@ -2087,26 +2408,13 @@ var AccountAndGroupProxyHandler = {
|
|
2087
2408
|
}
|
2088
2409
|
},
|
2089
2410
|
set(target, key, value, receiver) {
|
2090
|
-
if ((key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
|
2411
|
+
if (target instanceof Account && (key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
|
2091
2412
|
target.constructor._schema ||= {};
|
2092
2413
|
target.constructor._schema[key] = value[SchemaInit];
|
2093
2414
|
return true;
|
2094
|
-
} else if (key === "profile") {
|
2095
|
-
if (value) {
|
2096
|
-
target._raw.set(
|
2097
|
-
"profile",
|
2098
|
-
value.id,
|
2099
|
-
"trusting"
|
2100
|
-
);
|
2101
|
-
}
|
2102
|
-
return true;
|
2103
|
-
} else if (key === "root") {
|
2415
|
+
} else if (target instanceof Account && (key === "profile" || key === "root")) {
|
2104
2416
|
if (value) {
|
2105
|
-
target.
|
2106
|
-
"root",
|
2107
|
-
value.id,
|
2108
|
-
"trusting"
|
2109
|
-
);
|
2417
|
+
target.$jazz.set(key, value);
|
2110
2418
|
}
|
2111
2419
|
return true;
|
2112
2420
|
} else {
|
@@ -2124,35 +2432,12 @@ var AccountAndGroupProxyHandler = {
|
|
2124
2432
|
}
|
2125
2433
|
};
|
2126
2434
|
function isControlledAccount(account) {
|
2127
|
-
return account.isLocalNodeOwner;
|
2435
|
+
return account.$jazz.isLocalNodeOwner;
|
2128
2436
|
}
|
2129
2437
|
RegisteredSchemas["Account"] = Account;
|
2130
2438
|
|
2131
2439
|
// src/tools/coValues/group.ts
|
2132
2440
|
var _Group = class _Group extends CoValueBase {
|
2133
|
-
get _schema() {
|
2134
|
-
return this.constructor._schema;
|
2135
|
-
}
|
2136
|
-
get _refs() {
|
2137
|
-
const profileID = this._raw.get("profile");
|
2138
|
-
const rootID = this._raw.get("root");
|
2139
|
-
return {
|
2140
|
-
profile: profileID ? new Ref(
|
2141
|
-
profileID,
|
2142
|
-
this._loadedAs,
|
2143
|
-
this._schema.profile,
|
2144
|
-
this
|
2145
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2146
|
-
) : void 0,
|
2147
|
-
root: rootID ? new Ref(
|
2148
|
-
rootID,
|
2149
|
-
this._loadedAs,
|
2150
|
-
this._schema.root,
|
2151
|
-
this
|
2152
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2153
|
-
) : void 0
|
2154
|
-
};
|
2155
|
-
}
|
2156
2441
|
/** @deprecated Don't use constructor directly, use .create */
|
2157
2442
|
constructor(options) {
|
2158
2443
|
super();
|
@@ -2162,43 +2447,49 @@ var _Group = class _Group extends CoValueBase {
|
|
2162
2447
|
} else {
|
2163
2448
|
const initOwner = options.owner;
|
2164
2449
|
if (!initOwner) throw new Error("No owner provided");
|
2165
|
-
if (initOwner
|
2166
|
-
const rawOwner = initOwner.
|
2450
|
+
if (initOwner[TypeSym] === "Account" && isControlledAccount(initOwner)) {
|
2451
|
+
const rawOwner = initOwner.$jazz.raw;
|
2167
2452
|
raw = rawOwner.core.node.createGroup();
|
2168
2453
|
} else {
|
2169
2454
|
throw new Error("Can only construct group as a controlled account");
|
2170
2455
|
}
|
2171
2456
|
}
|
2457
|
+
const proxy = new Proxy(
|
2458
|
+
this,
|
2459
|
+
AccountAndGroupProxyHandler
|
2460
|
+
);
|
2172
2461
|
Object.defineProperties(this, {
|
2173
|
-
|
2174
|
-
value: raw
|
2462
|
+
$jazz: {
|
2463
|
+
value: new GroupJazzApi(proxy, raw),
|
2175
2464
|
enumerable: false
|
2176
|
-
}
|
2177
|
-
_raw: { value: raw, enumerable: false }
|
2465
|
+
}
|
2178
2466
|
});
|
2179
|
-
return
|
2467
|
+
return proxy;
|
2180
2468
|
}
|
2181
2469
|
static create(options) {
|
2182
2470
|
return new this(parseGroupCreateOptions(options));
|
2183
2471
|
}
|
2184
2472
|
myRole() {
|
2185
|
-
return this.
|
2473
|
+
return this.$jazz.raw.myRole();
|
2186
2474
|
}
|
2187
2475
|
addMember(member, role) {
|
2188
|
-
if (member !== "everyone" && member
|
2476
|
+
if (member !== "everyone" && member[TypeSym] === "Group") {
|
2189
2477
|
if (role === "writeOnly")
|
2190
2478
|
throw new Error("Cannot add group as member with write-only role");
|
2191
|
-
this.
|
2479
|
+
this.$jazz.raw.extend(member.$jazz.raw, role);
|
2192
2480
|
} else if (role !== void 0 && role !== "inherit") {
|
2193
|
-
this.
|
2481
|
+
this.$jazz.raw.addMember(
|
2482
|
+
member === "everyone" ? member : member.$jazz.raw,
|
2483
|
+
role
|
2484
|
+
);
|
2194
2485
|
}
|
2195
2486
|
}
|
2196
2487
|
removeMember(member) {
|
2197
|
-
if (member !== "everyone" && member
|
2198
|
-
this.
|
2488
|
+
if (member !== "everyone" && member[TypeSym] === "Group") {
|
2489
|
+
this.$jazz.raw.revokeExtend(member.$jazz.raw);
|
2199
2490
|
} else {
|
2200
|
-
return this.
|
2201
|
-
member === "everyone" ? member : member.
|
2491
|
+
return this.$jazz.raw.removeMember(
|
2492
|
+
member === "everyone" ? member : member.$jazz.raw
|
2202
2493
|
);
|
2203
2494
|
}
|
2204
2495
|
}
|
@@ -2210,11 +2501,11 @@ var _Group = class _Group extends CoValueBase {
|
|
2210
2501
|
};
|
2211
2502
|
for (const accountID of accountIDs) {
|
2212
2503
|
if (!isAccountID(accountID)) continue;
|
2213
|
-
const role = this.
|
2504
|
+
const role = this.$jazz.raw.roleOf(accountID);
|
2214
2505
|
if (role === "admin" || role === "writer" || role === "reader" || role === "writeOnly") {
|
2215
2506
|
const ref2 = new Ref(
|
2216
2507
|
accountID,
|
2217
|
-
this.
|
2508
|
+
this.$jazz.loadedAs,
|
2218
2509
|
refEncodedAccountSchema,
|
2219
2510
|
this
|
2220
2511
|
);
|
@@ -2241,7 +2532,7 @@ var _Group = class _Group extends CoValueBase {
|
|
2241
2532
|
* @returns The members of the group.
|
2242
2533
|
*/
|
2243
2534
|
get members() {
|
2244
|
-
return this.getMembersFromKeys(this.
|
2535
|
+
return this.getMembersFromKeys(this.$jazz.raw.getAllMemberKeysSet());
|
2245
2536
|
}
|
2246
2537
|
/**
|
2247
2538
|
* Returns the direct members of the group.
|
@@ -2251,17 +2542,11 @@ var _Group = class _Group extends CoValueBase {
|
|
2251
2542
|
* @returns The direct members of the group.
|
2252
2543
|
*/
|
2253
2544
|
getDirectMembers() {
|
2254
|
-
return this.getMembersFromKeys(this.
|
2545
|
+
return this.getMembersFromKeys(this.$jazz.raw.getMemberKeys());
|
2255
2546
|
}
|
2256
2547
|
getRoleOf(member) {
|
2257
|
-
|
2258
|
-
|
2259
|
-
activeAccountContext.get().id
|
2260
|
-
);
|
2261
|
-
}
|
2262
|
-
return this._raw.roleOf(
|
2263
|
-
member === "everyone" ? member : member
|
2264
|
-
);
|
2548
|
+
const accountId = member === "me" ? activeAccountContext.get().$jazz.id : member === "everyone" ? member : member;
|
2549
|
+
return this.$jazz.raw.roleOf(accountId);
|
2265
2550
|
}
|
2266
2551
|
/**
|
2267
2552
|
* Make the group public, so that everyone can read it.
|
@@ -2275,7 +2560,7 @@ var _Group = class _Group extends CoValueBase {
|
|
2275
2560
|
return this;
|
2276
2561
|
}
|
2277
2562
|
getParentGroups() {
|
2278
|
-
return this.
|
2563
|
+
return this.$jazz.raw.getParentGroups().map((group) => _Group.fromRaw(group));
|
2279
2564
|
}
|
2280
2565
|
/** @category Identity & Permissions
|
2281
2566
|
* Gives members of a parent group membership in this group.
|
@@ -2285,7 +2570,7 @@ var _Group = class _Group extends CoValueBase {
|
|
2285
2570
|
* @returns This group.
|
2286
2571
|
*/
|
2287
2572
|
extend(parent, roleMapping) {
|
2288
|
-
this.
|
2573
|
+
this.$jazz.raw.extend(parent.$jazz.raw, roleMapping);
|
2289
2574
|
return this;
|
2290
2575
|
}
|
2291
2576
|
/** @category Identity & Permissions
|
@@ -2295,7 +2580,7 @@ var _Group = class _Group extends CoValueBase {
|
|
2295
2580
|
* @returns This group.
|
2296
2581
|
*/
|
2297
2582
|
async revokeExtend(parent) {
|
2298
|
-
await this.
|
2583
|
+
await this.$jazz.raw.revokeExtend(parent.$jazz.raw);
|
2299
2584
|
return this;
|
2300
2585
|
}
|
2301
2586
|
/** @category Subscription & Loading */
|
@@ -2306,13 +2591,35 @@ var _Group = class _Group extends CoValueBase {
|
|
2306
2591
|
const { options, listener } = parseSubscribeRestArgs(args);
|
2307
2592
|
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
2308
2593
|
}
|
2594
|
+
};
|
2595
|
+
_Group.prototype[TypeSym] = "Group";
|
2596
|
+
var Group6 = _Group;
|
2597
|
+
var GroupJazzApi = class extends CoValueJazzApi {
|
2598
|
+
constructor(group, raw) {
|
2599
|
+
super(group);
|
2600
|
+
this.group = group;
|
2601
|
+
this.raw = raw;
|
2602
|
+
}
|
2603
|
+
/**
|
2604
|
+
* The ID of this `Group`
|
2605
|
+
* @category Content
|
2606
|
+
*/
|
2607
|
+
get id() {
|
2608
|
+
return this.raw.id;
|
2609
|
+
}
|
2610
|
+
/**
|
2611
|
+
* Groups have no owner. They can be accessed by everyone.
|
2612
|
+
*/
|
2613
|
+
get owner() {
|
2614
|
+
return void 0;
|
2615
|
+
}
|
2309
2616
|
/** @category Subscription & Loading */
|
2310
2617
|
ensureLoaded(options) {
|
2311
|
-
return ensureCoValueLoaded(this, options);
|
2618
|
+
return ensureCoValueLoaded(this.group, options);
|
2312
2619
|
}
|
2313
2620
|
subscribe(...args) {
|
2314
2621
|
const { options, listener } = parseSubscribeRestArgs(args);
|
2315
|
-
return subscribeToExistingCoValue(this, options, listener);
|
2622
|
+
return subscribeToExistingCoValue(this.group, options, listener);
|
2316
2623
|
}
|
2317
2624
|
/**
|
2318
2625
|
* Wait for the `Group` to be uploaded to the other peers.
|
@@ -2320,23 +2627,23 @@ var _Group = class _Group extends CoValueBase {
|
|
2320
2627
|
* @category Subscription & Loading
|
2321
2628
|
*/
|
2322
2629
|
waitForSync(options) {
|
2323
|
-
return this.
|
2630
|
+
return this.raw.core.waitForSync(options);
|
2324
2631
|
}
|
2325
2632
|
};
|
2326
|
-
|
2327
|
-
_Group._schema = {
|
2328
|
-
profile: "json",
|
2329
|
-
root: "json"
|
2330
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2331
|
-
};
|
2332
|
-
Object.defineProperty(_Group.prototype, "_schema", {
|
2333
|
-
get: () => _Group._schema
|
2334
|
-
});
|
2335
|
-
var Group = _Group;
|
2336
|
-
RegisteredSchemas["Group"] = Group;
|
2633
|
+
RegisteredSchemas["Group"] = Group6;
|
2337
2634
|
function isAccountID(id) {
|
2338
2635
|
return id.startsWith("co_");
|
2339
2636
|
}
|
2637
|
+
function getCoValueOwner(coValue) {
|
2638
|
+
const group = accessChildById(coValue, coValue.$jazz.raw.group.id, {
|
2639
|
+
ref: RegisteredSchemas["Group"],
|
2640
|
+
optional: false
|
2641
|
+
});
|
2642
|
+
if (!group) {
|
2643
|
+
throw new Error("CoValue has no owner");
|
2644
|
+
}
|
2645
|
+
return group;
|
2646
|
+
}
|
2340
2647
|
|
2341
2648
|
// src/tools/coValues/profile.ts
|
2342
2649
|
var Profile = class extends CoMap {
|
@@ -2352,10 +2659,11 @@ var Profile = class extends CoMap {
|
|
2352
2659
|
* The owner (a Group) determines access rights to the Profile.
|
2353
2660
|
*
|
2354
2661
|
* @category Creation
|
2662
|
+
* @deprecated Use `co.profile(...).create` instead.
|
2355
2663
|
*/
|
2356
2664
|
static create(init, options) {
|
2357
2665
|
const owner = options !== void 0 && "owner" in options ? options.owner : options;
|
2358
|
-
if (owner?.
|
2666
|
+
if (owner?.[TypeSym] === "Account") {
|
2359
2667
|
throw new Error("Profiles should be owned by a group");
|
2360
2668
|
}
|
2361
2669
|
return super.create(init, options);
|
@@ -2363,7 +2671,7 @@ var Profile = class extends CoMap {
|
|
2363
2671
|
};
|
2364
2672
|
|
2365
2673
|
// src/tools/coValues/inbox.ts
|
2366
|
-
import { RawAccount as
|
2674
|
+
import { RawAccount as RawAccount2 } from "cojson";
|
2367
2675
|
|
2368
2676
|
// src/tools/lib/id.ts
|
2369
2677
|
function isCoValueId(id) {
|
@@ -2372,10 +2680,10 @@ function isCoValueId(id) {
|
|
2372
2680
|
|
2373
2681
|
// src/tools/coValues/inbox.ts
|
2374
2682
|
function createInboxRoot(account) {
|
2375
|
-
if (!account.isLocalNodeOwner) {
|
2683
|
+
if (!account.$jazz.isLocalNodeOwner) {
|
2376
2684
|
throw new Error("Account is not controlled");
|
2377
2685
|
}
|
2378
|
-
const rawAccount = account.
|
2686
|
+
const rawAccount = account.$jazz.raw;
|
2379
2687
|
const group = rawAccount.core.node.createGroup();
|
2380
2688
|
const messagesFeed = group.createStream();
|
2381
2689
|
const inboxRoot = rawAccount.createMap();
|
@@ -2391,18 +2699,18 @@ function createInboxRoot(account) {
|
|
2391
2699
|
};
|
2392
2700
|
}
|
2393
2701
|
async function createInboxMessage(payload, inboxOwner) {
|
2394
|
-
const group = payload.
|
2395
|
-
if (group instanceof
|
2702
|
+
const group = payload.$jazz.raw.group;
|
2703
|
+
if (group instanceof RawAccount2) {
|
2396
2704
|
throw new Error("Inbox messages should be owned by a group");
|
2397
2705
|
}
|
2398
2706
|
group.addMember(inboxOwner, "writer");
|
2399
2707
|
const message = group.createMap({
|
2400
|
-
payload: payload.id,
|
2708
|
+
payload: payload.$jazz.id,
|
2401
2709
|
result: void 0,
|
2402
2710
|
processed: false,
|
2403
2711
|
error: void 0
|
2404
2712
|
});
|
2405
|
-
await payload.
|
2713
|
+
await payload.$jazz.raw.core.waitForSync();
|
2406
2714
|
await message.core.waitForSync();
|
2407
2715
|
return message;
|
2408
2716
|
}
|
@@ -2415,10 +2723,10 @@ var Inbox = class _Inbox {
|
|
2415
2723
|
this.processed = processed;
|
2416
2724
|
this.failed = failed;
|
2417
2725
|
}
|
2418
|
-
subscribe(
|
2726
|
+
subscribe(Schema4, callback, options = {}) {
|
2419
2727
|
const processed = /* @__PURE__ */ new Set();
|
2420
2728
|
const failed = /* @__PURE__ */ new Map();
|
2421
|
-
const node = this.account.
|
2729
|
+
const node = this.account.$jazz.localNode;
|
2422
2730
|
this.processed.subscribe((stream) => {
|
2423
2731
|
for (const items of Object.values(stream.items)) {
|
2424
2732
|
for (const item of items) {
|
@@ -2453,7 +2761,7 @@ var Inbox = class _Inbox {
|
|
2453
2761
|
);
|
2454
2762
|
}
|
2455
2763
|
return loadCoValue(
|
2456
|
-
coValueClassFromCoValueClassOrSchema(
|
2764
|
+
coValueClassFromCoValueClassOrSchema(Schema4),
|
2457
2765
|
message.get("payload"),
|
2458
2766
|
{
|
2459
2767
|
loadAs: account
|
@@ -2469,7 +2777,7 @@ var Inbox = class _Inbox {
|
|
2469
2777
|
}).then((result) => {
|
2470
2778
|
const inboxMessage = node.expectCoValueLoaded(item.value).getCurrentContent();
|
2471
2779
|
if (result) {
|
2472
|
-
inboxMessage.set("result", result.id);
|
2780
|
+
inboxMessage.set("result", result.$jazz.id);
|
2473
2781
|
}
|
2474
2782
|
inboxMessage.set("processed", true);
|
2475
2783
|
this.processed.push(txKey);
|
@@ -2518,7 +2826,7 @@ var Inbox = class _Inbox {
|
|
2518
2826
|
if (!profile.inbox) {
|
2519
2827
|
throw new Error("The account has not set up their inbox");
|
2520
2828
|
}
|
2521
|
-
const node = account.
|
2829
|
+
const node = account.$jazz.localNode;
|
2522
2830
|
const root = await node.load(profile.inbox);
|
2523
2831
|
if (root === "unavailable") {
|
2524
2832
|
throw new Error("Inbox not found");
|
@@ -2563,7 +2871,7 @@ var InboxSender = class _InboxSender {
|
|
2563
2871
|
}
|
2564
2872
|
static async load(inboxOwnerID, currentAccount) {
|
2565
2873
|
currentAccount ||= activeAccountContext.get();
|
2566
|
-
const node = currentAccount.
|
2874
|
+
const node = currentAccount.$jazz.localNode;
|
2567
2875
|
const inboxOwnerRaw = await node.load(
|
2568
2876
|
inboxOwnerID
|
2569
2877
|
);
|
@@ -2574,7 +2882,7 @@ var InboxSender = class _InboxSender {
|
|
2574
2882
|
if (inboxOwnerProfileRaw === "unavailable") {
|
2575
2883
|
throw new Error("Failed to load the inbox owner profile");
|
2576
2884
|
}
|
2577
|
-
if (inboxOwnerProfileRaw.group.roleOf(currentAccount.
|
2885
|
+
if (inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "reader" && inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "writer" && inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "admin") {
|
2578
2886
|
throw new Error(
|
2579
2887
|
"Insufficient permissions to access the inbox, make sure its user profile is publicly readable."
|
2580
2888
|
);
|
@@ -2598,10 +2906,10 @@ async function acceptInvite(invite, account) {
|
|
2598
2906
|
if (!isCoValueId(id) || !inviteSecret.startsWith("inviteSecret_")) {
|
2599
2907
|
throw new Error("Invalid inbox ticket");
|
2600
2908
|
}
|
2601
|
-
if (!account.isLocalNodeOwner) {
|
2909
|
+
if (!account.$jazz.isLocalNodeOwner) {
|
2602
2910
|
throw new Error("Account is not controlled");
|
2603
2911
|
}
|
2604
|
-
await account.
|
2912
|
+
await account.$jazz.localNode.acceptInvite(id, inviteSecret);
|
2605
2913
|
return id;
|
2606
2914
|
}
|
2607
2915
|
function getAccountIDfromSessionID(sessionID) {
|
@@ -2614,44 +2922,9 @@ function getAccountIDfromSessionID(sessionID) {
|
|
2614
2922
|
}
|
2615
2923
|
|
2616
2924
|
// src/tools/coValues/coPlainText.ts
|
2617
|
-
import {
|
2618
|
-
ControlledAccount as ControlledAccount4,
|
2619
|
-
RawAccount as RawAccount5,
|
2620
|
-
stringifyOpID
|
2621
|
-
} from "cojson";
|
2925
|
+
import { stringifyOpID } from "cojson";
|
2622
2926
|
import { calcPatch as calcPatch2 } from "fast-myers-diff";
|
2623
|
-
|
2624
|
-
// src/tools/lib/cache.ts
|
2625
|
-
var weakMap = /* @__PURE__ */ new WeakMap();
|
2626
|
-
var coValuesCache = {
|
2627
|
-
get: (raw, compute) => {
|
2628
|
-
const cached = weakMap.get(raw);
|
2629
|
-
if (cached) {
|
2630
|
-
return cached;
|
2631
|
-
}
|
2632
|
-
const computed = compute();
|
2633
|
-
weakMap.set(raw, computed);
|
2634
|
-
return computed;
|
2635
|
-
}
|
2636
|
-
};
|
2637
|
-
|
2638
|
-
// src/tools/coValues/coPlainText.ts
|
2639
2927
|
var CoPlainText = class extends String {
|
2640
|
-
get _owner() {
|
2641
|
-
return this._raw.group instanceof RawAccount5 ? Account.fromRaw(this._raw.group) : Group.fromRaw(this._raw.group);
|
2642
|
-
}
|
2643
|
-
get _loadedAs() {
|
2644
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
2645
|
-
if (agent instanceof ControlledAccount4) {
|
2646
|
-
return coValuesCache.get(
|
2647
|
-
agent.account,
|
2648
|
-
() => coValueClassFromCoValueClassOrSchema(
|
2649
|
-
RegisteredSchemas["Account"]
|
2650
|
-
).fromRaw(agent.account)
|
2651
|
-
);
|
2652
|
-
}
|
2653
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
2654
|
-
}
|
2655
2928
|
/** @internal */
|
2656
2929
|
constructor(options) {
|
2657
2930
|
if (!options) {
|
@@ -2662,19 +2935,23 @@ var CoPlainText = class extends String {
|
|
2662
2935
|
super(options.fromRaw.toString());
|
2663
2936
|
const raw = options.fromRaw;
|
2664
2937
|
Object.defineProperties(this, {
|
2665
|
-
|
2666
|
-
|
2667
|
-
|
2938
|
+
[TypeSym]: { value: "CoPlainText", enumerable: false },
|
2939
|
+
$jazz: {
|
2940
|
+
value: new CoTextJazzApi(this, raw),
|
2941
|
+
enumerable: false
|
2942
|
+
}
|
2668
2943
|
});
|
2669
2944
|
return;
|
2670
2945
|
}
|
2671
2946
|
if ("text" in options && "owner" in options) {
|
2672
2947
|
super(options.text);
|
2673
|
-
const raw = options.owner.
|
2948
|
+
const raw = options.owner.$jazz.raw.createPlainText(options.text);
|
2674
2949
|
Object.defineProperties(this, {
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2950
|
+
[TypeSym]: { value: "CoPlainText", enumerable: false },
|
2951
|
+
$jazz: {
|
2952
|
+
value: new CoTextJazzApi(this, raw),
|
2953
|
+
enumerable: false
|
2954
|
+
}
|
2678
2955
|
});
|
2679
2956
|
return;
|
2680
2957
|
}
|
@@ -2693,73 +2970,57 @@ var CoPlainText = class extends String {
|
|
2693
2970
|
* ```
|
2694
2971
|
*
|
2695
2972
|
* @category Creation
|
2973
|
+
* @deprecated Use `co.plainText(...).create` instead.
|
2696
2974
|
*/
|
2697
2975
|
static create(text, options) {
|
2698
2976
|
const { owner } = parseCoValueCreateOptions(options);
|
2699
2977
|
return new this({ text, owner });
|
2700
2978
|
}
|
2701
2979
|
get length() {
|
2702
|
-
return this.
|
2980
|
+
return this.$jazz.raw.toString().length;
|
2703
2981
|
}
|
2704
2982
|
toString() {
|
2705
|
-
return this.
|
2983
|
+
return this.$jazz.raw.toString();
|
2706
2984
|
}
|
2707
2985
|
valueOf() {
|
2708
|
-
return this.
|
2986
|
+
return this.$jazz.raw.toString();
|
2709
2987
|
}
|
2710
2988
|
toJSON() {
|
2711
|
-
return this.
|
2989
|
+
return this.$jazz.raw.toString();
|
2712
2990
|
}
|
2713
2991
|
[inspect]() {
|
2714
2992
|
return this.toJSON();
|
2715
2993
|
}
|
2716
2994
|
insertBefore(idx, text) {
|
2717
|
-
this.
|
2995
|
+
this.$jazz.raw.insertBefore(idx, text);
|
2718
2996
|
}
|
2719
2997
|
insertAfter(idx, text) {
|
2720
|
-
this.
|
2998
|
+
this.$jazz.raw.insertAfter(idx, text);
|
2721
2999
|
}
|
2722
3000
|
deleteRange(range) {
|
2723
|
-
this.
|
3001
|
+
this.$jazz.raw.deleteRange(range);
|
2724
3002
|
}
|
2725
3003
|
posBefore(idx) {
|
2726
|
-
return this.
|
3004
|
+
return this.$jazz.raw.mapping.opIDbeforeIdx[idx];
|
2727
3005
|
}
|
2728
3006
|
posAfter(idx) {
|
2729
|
-
return this.
|
3007
|
+
return this.$jazz.raw.mapping.opIDafterIdx[idx];
|
2730
3008
|
}
|
2731
3009
|
idxBefore(pos) {
|
2732
|
-
return this.
|
3010
|
+
return this.$jazz.raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
|
2733
3011
|
}
|
2734
3012
|
idxAfter(pos) {
|
2735
|
-
return this.
|
3013
|
+
return this.$jazz.raw.mapping.idxAfterOpID[stringifyOpID(pos)];
|
2736
3014
|
}
|
3015
|
+
/** @category Internals */
|
2737
3016
|
static fromRaw(raw) {
|
2738
3017
|
return new this({ fromRaw: raw });
|
2739
3018
|
}
|
2740
|
-
/**
|
2741
|
-
* Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
|
2742
|
-
*
|
2743
|
-
* @category Mutation
|
2744
|
-
*/
|
2745
|
-
applyDiff(other) {
|
2746
|
-
const current = this._raw.toString();
|
2747
|
-
const currentGraphemes = this._raw.toGraphemes(current);
|
2748
|
-
const otherGraphemes = this._raw.toGraphemes(other);
|
2749
|
-
const patches = [...calcPatch2(currentGraphemes, otherGraphemes)];
|
2750
|
-
for (const [from, to, insert] of patches.reverse()) {
|
2751
|
-
if (to > from) {
|
2752
|
-
this.deleteRange({ from, to });
|
2753
|
-
}
|
2754
|
-
if (insert.length > 0) {
|
2755
|
-
this.insertBefore(from, this._raw.fromGraphemes(insert));
|
2756
|
-
}
|
2757
|
-
}
|
2758
|
-
}
|
2759
3019
|
/**
|
2760
3020
|
* Load a `CoPlainText` with a given ID, as a given account.
|
2761
3021
|
*
|
2762
3022
|
* @category Subscription & Loading
|
3023
|
+
* @deprecated Use `co.plainText(...).load` instead.
|
2763
3024
|
*/
|
2764
3025
|
static load(id, options) {
|
2765
3026
|
return loadCoValueWithoutMe(this, id, options);
|
@@ -2768,18 +3029,6 @@ var CoPlainText = class extends String {
|
|
2768
3029
|
const { options, listener } = parseSubscribeRestArgs(args);
|
2769
3030
|
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
2770
3031
|
}
|
2771
|
-
/**
|
2772
|
-
* Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
|
2773
|
-
*
|
2774
|
-
* Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
|
2775
|
-
*
|
2776
|
-
* Returns an unsubscribe function that you should call when you no longer need updates.
|
2777
|
-
*
|
2778
|
-
* @category Subscription & Loading
|
2779
|
-
**/
|
2780
|
-
subscribe(listener) {
|
2781
|
-
return subscribeToExistingCoValue(this, {}, listener);
|
2782
|
-
}
|
2783
3032
|
/**
|
2784
3033
|
* Allow CoPlainText to behave like a primitive string in most contexts (e.g.,
|
2785
3034
|
* string concatenation, template literals, React rendering, etc.) by implementing
|
@@ -2792,9 +3041,53 @@ var CoPlainText = class extends String {
|
|
2792
3041
|
*/
|
2793
3042
|
[Symbol.toPrimitive](hint) {
|
2794
3043
|
if (hint === "number") {
|
2795
|
-
return Number(this.
|
3044
|
+
return Number(this.$jazz.raw.toString());
|
3045
|
+
}
|
3046
|
+
return this.$jazz.raw.toString();
|
3047
|
+
}
|
3048
|
+
};
|
3049
|
+
var CoTextJazzApi = class extends CoValueJazzApi {
|
3050
|
+
constructor(coText, raw) {
|
3051
|
+
super(coText);
|
3052
|
+
this.coText = coText;
|
3053
|
+
this.raw = raw;
|
3054
|
+
}
|
3055
|
+
get id() {
|
3056
|
+
return this.raw.id;
|
3057
|
+
}
|
3058
|
+
get owner() {
|
3059
|
+
return getCoValueOwner(this.coText);
|
3060
|
+
}
|
3061
|
+
/**
|
3062
|
+
* Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
|
3063
|
+
*
|
3064
|
+
* @category Mutation
|
3065
|
+
*/
|
3066
|
+
applyDiff(other) {
|
3067
|
+
const current = this.raw.toString();
|
3068
|
+
const currentGraphemes = this.raw.toGraphemes(current);
|
3069
|
+
const otherGraphemes = this.raw.toGraphemes(other);
|
3070
|
+
const patches = [...calcPatch2(currentGraphemes, otherGraphemes)];
|
3071
|
+
for (const [from, to, insert] of patches.reverse()) {
|
3072
|
+
if (to > from) {
|
3073
|
+
this.coText.deleteRange({ from, to });
|
3074
|
+
}
|
3075
|
+
if (insert.length > 0) {
|
3076
|
+
this.coText.insertBefore(from, this.raw.fromGraphemes(insert));
|
3077
|
+
}
|
2796
3078
|
}
|
2797
|
-
|
3079
|
+
}
|
3080
|
+
/**
|
3081
|
+
* Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
|
3082
|
+
*
|
3083
|
+
* Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
|
3084
|
+
*
|
3085
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
3086
|
+
*
|
3087
|
+
* @category Subscription & Loading
|
3088
|
+
**/
|
3089
|
+
subscribe(listener) {
|
3090
|
+
return subscribeToExistingCoValue(this.coText, {}, listener);
|
2798
3091
|
}
|
2799
3092
|
};
|
2800
3093
|
|
@@ -2879,10 +3172,12 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
|
|
2879
3172
|
};
|
2880
3173
|
|
2881
3174
|
// src/tools/implementation/anonymousJazzAgent.ts
|
3175
|
+
var _a;
|
3176
|
+
_a = TypeSym;
|
2882
3177
|
var AnonymousJazzAgent = class {
|
2883
3178
|
constructor(node) {
|
2884
3179
|
this.node = node;
|
2885
|
-
this
|
3180
|
+
this[_a] = "Anonymous";
|
2886
3181
|
}
|
2887
3182
|
};
|
2888
3183
|
|
@@ -3099,19 +3394,19 @@ function instantiateRefEncodedWithInit(schema, init, parentOwner) {
|
|
3099
3394
|
`Cannot automatically create CoValue from value: ${JSON.stringify(init)}. Use the CoValue schema's create() method instead.`
|
3100
3395
|
);
|
3101
3396
|
}
|
3102
|
-
const node = parentOwner.
|
3397
|
+
const node = parentOwner.$jazz.localNode;
|
3103
3398
|
const rawGroup = node.createGroup();
|
3104
|
-
const owner = new
|
3105
|
-
owner.addMember(parentOwner
|
3399
|
+
const owner = new Group6({ fromRaw: rawGroup });
|
3400
|
+
owner.addMember(parentOwner);
|
3106
3401
|
return schema.ref.create(init, owner);
|
3107
3402
|
}
|
3108
3403
|
|
3109
3404
|
// src/tools/lib/migration.ts
|
3110
3405
|
function applyCoValueMigrations(instance) {
|
3111
|
-
const node = instance.
|
3406
|
+
const node = instance.$jazz.raw.core.node;
|
3112
3407
|
const migratedCoValues = node._migratedCoValues ??= /* @__PURE__ */ new Set();
|
3113
|
-
if ("migrate" in instance && typeof instance.migrate === "function" && instance
|
3114
|
-
migratedCoValues.add(instance.id);
|
3408
|
+
if ("migrate" in instance && typeof instance.migrate === "function" && instance[TypeSym] !== "Account" && !migratedCoValues.has(instance.$jazz.id)) {
|
3409
|
+
migratedCoValues.add(instance.$jazz.id);
|
3115
3410
|
const result = instance.migrate?.(instance);
|
3116
3411
|
if (result && "then" in result) {
|
3117
3412
|
throw new Error("Migration function cannot be async");
|
@@ -3212,19 +3507,34 @@ var JazzError = class _JazzError {
|
|
3212
3507
|
};
|
3213
3508
|
|
3214
3509
|
// src/tools/subscribe/utils.ts
|
3215
|
-
import { RawAccount as
|
3216
|
-
|
3217
|
-
|
3218
|
-
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3510
|
+
import { RawAccount as RawAccount3 } from "cojson";
|
3511
|
+
|
3512
|
+
// src/tools/lib/cache.ts
|
3513
|
+
var weakMap = /* @__PURE__ */ new WeakMap();
|
3514
|
+
var coValuesCache = {
|
3515
|
+
get: (raw, compute) => {
|
3516
|
+
const cached = weakMap.get(raw);
|
3517
|
+
if (cached) {
|
3518
|
+
return cached;
|
3519
|
+
}
|
3520
|
+
const computed = compute();
|
3521
|
+
weakMap.set(raw, computed);
|
3522
|
+
return computed;
|
3523
|
+
}
|
3524
|
+
};
|
3525
|
+
|
3526
|
+
// src/tools/subscribe/utils.ts
|
3527
|
+
function myRoleForRawValue(raw) {
|
3528
|
+
const rawOwner = raw.group;
|
3529
|
+
const owner = coValuesCache.get(
|
3530
|
+
rawOwner,
|
3531
|
+
() => rawOwner instanceof RawAccount3 ? RegisteredSchemas["Account"].fromRaw(rawOwner) : RegisteredSchemas["Group"].fromRaw(rawOwner)
|
3223
3532
|
);
|
3533
|
+
return accountOrGroupToGroup(owner).myRole();
|
3224
3534
|
}
|
3225
3535
|
function createCoValue(ref2, raw, subscriptionScope) {
|
3226
3536
|
const freshValueInstance = instantiateRefEncodedFromRaw(ref2, raw);
|
3227
|
-
Object.defineProperty(freshValueInstance, "_subscriptionScope", {
|
3537
|
+
Object.defineProperty(freshValueInstance.$jazz, "_subscriptionScope", {
|
3228
3538
|
value: subscriptionScope,
|
3229
3539
|
writable: false,
|
3230
3540
|
enumerable: false,
|
@@ -3273,7 +3583,7 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3273
3583
|
if (this.shouldSendUpdates()) {
|
3274
3584
|
if (this.value.type === "loaded") {
|
3275
3585
|
this.updateValue(
|
3276
|
-
createCoValue(this.schema, this.value.value.
|
3586
|
+
createCoValue(this.schema, this.value.value.$jazz.raw, this)
|
3277
3587
|
);
|
3278
3588
|
}
|
3279
3589
|
}
|
@@ -3334,7 +3644,7 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3334
3644
|
return;
|
3335
3645
|
}
|
3336
3646
|
const ruleset = update.core.verified.header.ruleset;
|
3337
|
-
const hasAccess = ruleset.type !== "ownedByGroup" ||
|
3647
|
+
const hasAccess = ruleset.type !== "ownedByGroup" || myRoleForRawValue(update) !== void 0;
|
3338
3648
|
if (!hasAccess) {
|
3339
3649
|
if (this.value.type !== "unauthorized") {
|
3340
3650
|
this.updateValue(
|
@@ -3358,9 +3668,9 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3358
3668
|
this.updateValue(createCoValue(this.schema, update, this));
|
3359
3669
|
this.loadChildren();
|
3360
3670
|
} else {
|
3361
|
-
const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || // Checking the identity of the
|
3671
|
+
const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || // Checking the identity of the raw value makes us cover the cases where the group
|
3362
3672
|
// has been updated and the coValues that don't update the totalValidTransactions value (e.g. FileStream)
|
3363
|
-
this.value.value.
|
3673
|
+
this.value.value.$jazz.raw !== update;
|
3364
3674
|
if (this.loadChildren()) {
|
3365
3675
|
this.updateValue(createCoValue(this.schema, update, this));
|
3366
3676
|
} else if (hasChanged) {
|
@@ -3440,13 +3750,13 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3440
3750
|
if (this.value.type !== "loaded") {
|
3441
3751
|
return false;
|
3442
3752
|
}
|
3443
|
-
return this.value.value.
|
3753
|
+
return this.value.value.$jazz.raw.core.verified.isStreaming();
|
3444
3754
|
}
|
3445
3755
|
isFileStream() {
|
3446
3756
|
if (this.value.type !== "loaded") {
|
3447
3757
|
return false;
|
3448
3758
|
}
|
3449
|
-
return this.value.value.
|
3759
|
+
return this.value.value.$jazz.raw.core.verified.header.meta?.type === "binary";
|
3450
3760
|
}
|
3451
3761
|
triggerUpdate() {
|
3452
3762
|
if (!this.shouldSendUpdates()) return;
|
@@ -3486,10 +3796,10 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3486
3796
|
}
|
3487
3797
|
const value = this.value.value;
|
3488
3798
|
this.silenceUpdates = true;
|
3489
|
-
if (value
|
3799
|
+
if (value[TypeSym] === "CoMap" || value[TypeSym] === "Account") {
|
3490
3800
|
const map = value;
|
3491
3801
|
this.loadCoMapKey(map, key, true);
|
3492
|
-
} else if (value
|
3802
|
+
} else if (value[TypeSym] === "CoList") {
|
3493
3803
|
const list = value;
|
3494
3804
|
this.loadCoListKey(list, key, true);
|
3495
3805
|
}
|
@@ -3524,23 +3834,23 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3524
3834
|
const depth = typeof resolve !== "object" || resolve === null ? {} : resolve;
|
3525
3835
|
let hasChanged = false;
|
3526
3836
|
const idsToLoad = new Set(this.idsSubscribed);
|
3527
|
-
const coValueType = value
|
3837
|
+
const coValueType = value[TypeSym];
|
3528
3838
|
if (Object.keys(depth).length > 0) {
|
3529
|
-
if (coValueType === "CoMap" || coValueType === "Account") {
|
3839
|
+
if (coValueType === "CoMap" || coValueType === "Account" || coValueType === "Group") {
|
3530
3840
|
const map = value;
|
3531
|
-
const keys = "$each" in depth ? map.
|
3841
|
+
const keys = "$each" in depth ? map.$jazz.raw.keys() : Object.keys(depth);
|
3532
3842
|
for (const key of keys) {
|
3533
3843
|
const id = this.loadCoMapKey(map, key, depth[key] ?? depth.$each);
|
3534
3844
|
if (id) {
|
3535
3845
|
idsToLoad.add(id);
|
3536
3846
|
}
|
3537
3847
|
}
|
3538
|
-
} else if (value
|
3848
|
+
} else if (value[TypeSym] === "CoList") {
|
3539
3849
|
const list = value;
|
3540
|
-
const descriptor = list.getItemsDescriptor();
|
3850
|
+
const descriptor = list.$jazz.getItemsDescriptor();
|
3541
3851
|
if (descriptor && isRefEncoded(descriptor)) {
|
3542
|
-
list.
|
3543
|
-
const entries = list.
|
3852
|
+
list.$jazz.raw.processNewTransactions();
|
3853
|
+
const entries = list.$jazz.raw.entries();
|
3544
3854
|
const keys = "$each" in depth ? Object.keys(entries) : Object.keys(depth);
|
3545
3855
|
for (const key of keys) {
|
3546
3856
|
const id = this.loadCoListKey(list, key, depth[key] ?? depth.$each);
|
@@ -3549,12 +3859,12 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3549
3859
|
}
|
3550
3860
|
}
|
3551
3861
|
}
|
3552
|
-
} else if (value
|
3862
|
+
} else if (value[TypeSym] === "CoStream") {
|
3553
3863
|
const stream = value;
|
3554
|
-
const descriptor = stream.getItemsDescriptor();
|
3864
|
+
const descriptor = stream.$jazz.getItemsDescriptor();
|
3555
3865
|
if (descriptor && isRefEncoded(descriptor)) {
|
3556
|
-
for (const session of stream.
|
3557
|
-
const values = stream.
|
3866
|
+
for (const session of stream.$jazz.raw.sessions()) {
|
3867
|
+
const values = stream.$jazz.raw.items[session] ?? [];
|
3558
3868
|
for (const [i, item] of values.entries()) {
|
3559
3869
|
const key = `${session}/${i}`;
|
3560
3870
|
if (!depth.$each && !depth[key]) {
|
@@ -3601,8 +3911,8 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3601
3911
|
if (key === "$onError") {
|
3602
3912
|
return void 0;
|
3603
3913
|
}
|
3604
|
-
const id = map.
|
3605
|
-
const descriptor = map.getDescriptor(key);
|
3914
|
+
const id = map.$jazz.raw.get(key);
|
3915
|
+
const descriptor = map.$jazz.getDescriptor(key);
|
3606
3916
|
if (!descriptor) {
|
3607
3917
|
this.childErrors.set(
|
3608
3918
|
key,
|
@@ -3639,11 +3949,11 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3639
3949
|
return void 0;
|
3640
3950
|
}
|
3641
3951
|
loadCoListKey(list, key, depth) {
|
3642
|
-
const descriptor = list.getItemsDescriptor();
|
3952
|
+
const descriptor = list.$jazz.getItemsDescriptor();
|
3643
3953
|
if (!descriptor || !isRefEncoded(descriptor)) {
|
3644
3954
|
return void 0;
|
3645
3955
|
}
|
3646
|
-
const entries = list.
|
3956
|
+
const entries = list.$jazz.raw.entries();
|
3647
3957
|
const entry = entries[Number(key)];
|
3648
3958
|
if (!entry) {
|
3649
3959
|
return void 0;
|
@@ -3704,18 +4014,18 @@ var SubscriptionScope = class _SubscriptionScope {
|
|
3704
4014
|
|
3705
4015
|
// src/tools/subscribe/index.ts
|
3706
4016
|
function getSubscriptionScope(value) {
|
3707
|
-
const subscriptionScope = value._subscriptionScope;
|
4017
|
+
const subscriptionScope = value.$jazz._subscriptionScope;
|
3708
4018
|
if (subscriptionScope) {
|
3709
4019
|
return subscriptionScope;
|
3710
4020
|
}
|
3711
|
-
const node = value.
|
4021
|
+
const node = value.$jazz.raw.core.node;
|
3712
4022
|
const resolve = true;
|
3713
|
-
const id = value.id;
|
4023
|
+
const id = value.$jazz.id;
|
3714
4024
|
const newSubscriptionScope = new SubscriptionScope(node, resolve, id, {
|
3715
4025
|
ref: value.constructor,
|
3716
4026
|
optional: false
|
3717
4027
|
});
|
3718
|
-
Object.defineProperty(value, "_subscriptionScope", {
|
4028
|
+
Object.defineProperty(value.$jazz, "_subscriptionScope", {
|
3719
4029
|
value: subscriptionScope,
|
3720
4030
|
writable: false,
|
3721
4031
|
enumerable: false,
|
@@ -3748,7 +4058,7 @@ function accessChildById(parent, childId, schema) {
|
|
3748
4058
|
|
3749
4059
|
// src/tools/implementation/createContext.ts
|
3750
4060
|
import {
|
3751
|
-
LocalNode as
|
4061
|
+
LocalNode as LocalNode3
|
3752
4062
|
} from "cojson";
|
3753
4063
|
async function randomSessionProvider(accountID, crypto) {
|
3754
4064
|
return {
|
@@ -3772,7 +4082,7 @@ async function createJazzContextFromExistingCredentials({
|
|
3772
4082
|
);
|
3773
4083
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3774
4084
|
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
3775
|
-
const node = await
|
4085
|
+
const node = await LocalNode3.withLoadedAccount({
|
3776
4086
|
accountID: credentials.accountID,
|
3777
4087
|
accountSecret: credentials.secret,
|
3778
4088
|
sessionID,
|
@@ -3812,7 +4122,7 @@ async function createJazzContextForNewAccount({
|
|
3812
4122
|
}) {
|
3813
4123
|
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3814
4124
|
const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
|
3815
|
-
const { node } = await
|
4125
|
+
const { node } = await LocalNode3.withNewlyCreatedAccount({
|
3816
4126
|
creationProps,
|
3817
4127
|
peersToLoadFrom,
|
3818
4128
|
crypto,
|
@@ -3878,7 +4188,7 @@ async function createJazzContext(options) {
|
|
3878
4188
|
});
|
3879
4189
|
if (!options.newAccountProps) {
|
3880
4190
|
await authSecretStorage.setWithoutNotify({
|
3881
|
-
accountID: context.account.id,
|
4191
|
+
accountID: context.account.$jazz.id,
|
3882
4192
|
secretSeed,
|
3883
4193
|
accountSecret: context.node.getCurrentAgent().agentSecret,
|
3884
4194
|
provider: "anonymous"
|
@@ -3896,7 +4206,7 @@ function createAnonymousJazzContext({
|
|
3896
4206
|
storage
|
3897
4207
|
}) {
|
3898
4208
|
const agentSecret = crypto.newRandomAgentSecret();
|
3899
|
-
const node = new
|
4209
|
+
const node = new LocalNode3(
|
3900
4210
|
agentSecret,
|
3901
4211
|
crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
|
3902
4212
|
crypto
|
@@ -4938,7 +5248,7 @@ var JazzContextManager = class {
|
|
4938
5248
|
await this.handleAnonymousAccountMigration(prevContext);
|
4939
5249
|
}
|
4940
5250
|
if (this.context && "me" in this.context) {
|
4941
|
-
return this.context.me.id;
|
5251
|
+
return this.context.me.$jazz.id;
|
4942
5252
|
}
|
4943
5253
|
throw new Error("The registration hasn't created a new account");
|
4944
5254
|
};
|
@@ -5017,8 +5327,8 @@ var JazzContextManager = class {
|
|
5017
5327
|
const currentContext = this.context;
|
5018
5328
|
if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
|
5019
5329
|
const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals5.connectedPeers(
|
5020
|
-
prevContext.me.id,
|
5021
|
-
currentContext.me.id,
|
5330
|
+
prevContext.me.$jazz.id,
|
5331
|
+
currentContext.me.$jazz.id,
|
5022
5332
|
{
|
5023
5333
|
peer1role: "client",
|
5024
5334
|
peer2role: "server"
|
@@ -5029,7 +5339,7 @@ var JazzContextManager = class {
|
|
5029
5339
|
prevContext.node.syncManager.addPeer(currentAccountAsPeer);
|
5030
5340
|
try {
|
5031
5341
|
await this.props.onAnonymousAccountDiscarded?.(prevContext.me);
|
5032
|
-
await prevContext.me.waitForAllCoValuesSync();
|
5342
|
+
await prevContext.me.$jazz.waitForAllCoValuesSync();
|
5033
5343
|
} catch (error) {
|
5034
5344
|
console.error("Error onAnonymousAccountDiscarded", error);
|
5035
5345
|
}
|
@@ -5056,22 +5366,22 @@ function createResolvablePromise() {
|
|
5056
5366
|
globalThis.devtoolsFormatters = [
|
5057
5367
|
{
|
5058
5368
|
header: (object2) => {
|
5059
|
-
if (object2
|
5369
|
+
if (object2[TypeSym] === "CoMap") {
|
5060
5370
|
return ["div", {}, ["span", {}, object2.constructor.name]];
|
5061
|
-
} else if (object2
|
5371
|
+
} else if (object2[TypeSym] === "CoList") {
|
5062
5372
|
return [
|
5063
5373
|
"div",
|
5064
5374
|
{},
|
5065
5375
|
["span", {}, object2.constructor.name + "(" + object2.length + ") "]
|
5066
5376
|
];
|
5067
|
-
} else if (object2
|
5377
|
+
} else if (object2[TypeSym] === "Account") {
|
5068
5378
|
return [
|
5069
5379
|
"div",
|
5070
5380
|
{},
|
5071
5381
|
[
|
5072
5382
|
"span",
|
5073
5383
|
{},
|
5074
|
-
object2.constructor.name + "(" + object2.
|
5384
|
+
object2.constructor.name + "(" + object2.$jazz.refs.profile.value?.name + (object2.isMe ? " ME" : "") + ")"
|
5075
5385
|
]
|
5076
5386
|
];
|
5077
5387
|
} else {
|
@@ -5082,7 +5392,7 @@ globalThis.devtoolsFormatters = [
|
|
5082
5392
|
return true;
|
5083
5393
|
},
|
5084
5394
|
body: function(object2) {
|
5085
|
-
if (object2
|
5395
|
+
if (object2[TypeSym] === "CoMap" || object2[TypeSym] === "Account") {
|
5086
5396
|
return [
|
5087
5397
|
"div",
|
5088
5398
|
{ style: "margin-left: 15px" },
|
@@ -5097,13 +5407,13 @@ globalThis.devtoolsFormatters = [
|
|
5097
5407
|
"span",
|
5098
5408
|
{ style: "opacity: 0.5" },
|
5099
5409
|
` (pending ${object2._schema[k].name} `,
|
5100
|
-
["object", { object: object2.
|
5410
|
+
["object", { object: object2.$jazz.refs[k] }],
|
5101
5411
|
")"
|
5102
5412
|
]
|
5103
5413
|
] : [] : []
|
5104
5414
|
])
|
5105
5415
|
];
|
5106
|
-
} else if (object2
|
5416
|
+
} else if (object2[TypeSym] === "CoList") {
|
5107
5417
|
return [
|
5108
5418
|
"div",
|
5109
5419
|
{ style: "margin-left: 15px" },
|
@@ -5118,7 +5428,7 @@ globalThis.devtoolsFormatters = [
|
|
5118
5428
|
"span",
|
5119
5429
|
{ style: "opacity: 0.5" },
|
5120
5430
|
` (pending ${object2._schema[ItemsSym].name} `,
|
5121
|
-
["object", { object: object2.
|
5431
|
+
["object", { object: object2.$jazz.refs[i] }],
|
5122
5432
|
")"
|
5123
5433
|
]
|
5124
5434
|
] : [] : []
|
@@ -5166,14 +5476,14 @@ function loadCoValue(cls, id, options) {
|
|
5166
5476
|
async function ensureCoValueLoaded(existing, options) {
|
5167
5477
|
const response = await loadCoValue(
|
5168
5478
|
existing.constructor,
|
5169
|
-
existing.id,
|
5479
|
+
existing.$jazz.id,
|
5170
5480
|
{
|
5171
|
-
loadAs: existing.
|
5481
|
+
loadAs: existing.$jazz.loadedAs,
|
5172
5482
|
resolve: options?.resolve
|
5173
5483
|
}
|
5174
5484
|
);
|
5175
5485
|
if (!response) {
|
5176
|
-
throw new Error("Failed to deeply load CoValue " + existing.id);
|
5486
|
+
throw new Error("Failed to deeply load CoValue " + existing.$jazz.id);
|
5177
5487
|
}
|
5178
5488
|
return response;
|
5179
5489
|
}
|
@@ -5213,7 +5523,7 @@ function subscribeToCoValueWithoutMe(cls, id, options, listener) {
|
|
5213
5523
|
}
|
5214
5524
|
function subscribeToCoValue(cls, id, options, listener) {
|
5215
5525
|
const loadAs = options.loadAs ?? activeAccountContext.get();
|
5216
|
-
const node = "node" in loadAs ? loadAs.node : loadAs.
|
5526
|
+
const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
|
5217
5527
|
const resolve = options.resolve ?? true;
|
5218
5528
|
let unsubscribed = false;
|
5219
5529
|
const rootNode = new SubscriptionScope(
|
@@ -5258,9 +5568,9 @@ function subscribeToCoValue(cls, id, options, listener) {
|
|
5258
5568
|
function subscribeToExistingCoValue(existing, options, listener) {
|
5259
5569
|
return subscribeToCoValue(
|
5260
5570
|
existing.constructor,
|
5261
|
-
existing.id,
|
5571
|
+
existing.$jazz.id,
|
5262
5572
|
{
|
5263
|
-
loadAs: existing.
|
5573
|
+
loadAs: existing.$jazz.loadedAs,
|
5264
5574
|
resolve: options?.resolve,
|
5265
5575
|
onUnavailable: options?.onUnavailable,
|
5266
5576
|
onUnauthorized: options?.onUnauthorized
|
@@ -5272,33 +5582,42 @@ function isAccountInstance(instance) {
|
|
5272
5582
|
if (typeof instance !== "object" || instance === null) {
|
5273
5583
|
return false;
|
5274
5584
|
}
|
5275
|
-
return
|
5585
|
+
return TypeSym in instance && instance[TypeSym] === "Account";
|
5276
5586
|
}
|
5277
5587
|
function parseCoValueCreateOptions(options) {
|
5278
|
-
const
|
5588
|
+
const Group16 = RegisteredSchemas["Group"];
|
5279
5589
|
if (!options) {
|
5280
|
-
return { owner:
|
5590
|
+
return { owner: Group16.create(), uniqueness: void 0 };
|
5281
5591
|
}
|
5282
|
-
if (
|
5283
|
-
if (options
|
5592
|
+
if (TypeSym in options) {
|
5593
|
+
if (options[TypeSym] === "Account") {
|
5594
|
+
return { owner: accountOrGroupToGroup(options), uniqueness: void 0 };
|
5595
|
+
} else if (options[TypeSym] === "Group") {
|
5284
5596
|
return { owner: options, uniqueness: void 0 };
|
5285
5597
|
}
|
5286
5598
|
}
|
5287
5599
|
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
5288
|
-
|
5289
|
-
owner: options.owner
|
5600
|
+
const opts = {
|
5601
|
+
owner: options.owner ? accountOrGroupToGroup(options.owner) : Group16.create(),
|
5290
5602
|
uniqueness
|
5291
5603
|
};
|
5604
|
+
return opts;
|
5605
|
+
}
|
5606
|
+
function accountOrGroupToGroup(accountOrGroup) {
|
5607
|
+
if (accountOrGroup[TypeSym] === "Group") {
|
5608
|
+
return accountOrGroup;
|
5609
|
+
}
|
5610
|
+
return RegisteredSchemas["Group"].fromRaw(accountOrGroup.$jazz.raw);
|
5292
5611
|
}
|
5293
5612
|
function parseGroupCreateOptions(options) {
|
5294
5613
|
if (!options) {
|
5295
5614
|
return { owner: activeAccountContext.get() };
|
5296
5615
|
}
|
5297
|
-
return
|
5616
|
+
return TypeSym in options && isAccountInstance(options) ? { owner: options } : { owner: options.owner ?? activeAccountContext.get() };
|
5298
5617
|
}
|
5299
5618
|
async function exportCoValue(cls, id, options) {
|
5300
5619
|
const loadAs = options.loadAs ?? activeAccountContext.get();
|
5301
|
-
const node = "node" in loadAs ? loadAs.node : loadAs.
|
5620
|
+
const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
|
5302
5621
|
const resolve = options.resolve ?? true;
|
5303
5622
|
const rootNode = new SubscriptionScope(
|
5304
5623
|
node,
|
@@ -5338,7 +5657,7 @@ function loadContentPiecesFromSubscription(subscription, valuesExported, content
|
|
5338
5657
|
return;
|
5339
5658
|
}
|
5340
5659
|
valuesExported.add(subscription.id);
|
5341
|
-
const core2 = subscription.getCurrentValue()
|
5660
|
+
const core2 = subscription.getCurrentValue()?.$jazz.raw.core;
|
5342
5661
|
if (core2) {
|
5343
5662
|
loadContentPiecesFromCoValue(core2, valuesExported, contentPieces);
|
5344
5663
|
}
|
@@ -5364,7 +5683,7 @@ function loadContentPiecesFromCoValue(core2, valuesExported, contentPieces) {
|
|
5364
5683
|
}
|
5365
5684
|
function importContentPieces(contentPieces, loadAs) {
|
5366
5685
|
const account = loadAs ?? Account.getMe();
|
5367
|
-
const node = "node" in account ? account.node : account.
|
5686
|
+
const node = "node" in account ? account.node : account.$jazz.localNode;
|
5368
5687
|
for (const piece of contentPieces) {
|
5369
5688
|
node.syncManager.handleNewContent(piece, "import");
|
5370
5689
|
}
|
@@ -5383,7 +5702,7 @@ export {
|
|
5383
5702
|
FileStream,
|
5384
5703
|
Account,
|
5385
5704
|
isControlledAccount,
|
5386
|
-
Group,
|
5705
|
+
Group6 as Group,
|
5387
5706
|
Profile,
|
5388
5707
|
isCoValueId,
|
5389
5708
|
Inbox,
|
@@ -5412,4 +5731,4 @@ export {
|
|
5412
5731
|
JazzContextManager
|
5413
5732
|
};
|
5414
5733
|
/* istanbul ignore file -- @preserve */
|
5415
|
-
//# sourceMappingURL=chunk-
|
5734
|
+
//# sourceMappingURL=chunk-IERUTUXB.js.map
|