jazz-tools 0.8.44 → 0.8.48
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +16 -10
- package/CHANGELOG.md +21 -0
- package/dist/chunk-6OHBW32Q.js +2853 -0
- package/dist/chunk-6OHBW32Q.js.map +1 -0
- package/dist/index.native.js +63 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.web.js +61 -0
- package/dist/index.web.js.map +1 -0
- package/package.json +9 -12
- package/src/coValues/account.ts +29 -10
- package/src/coValues/coFeed.ts +4 -3
- package/src/coValues/coList.ts +8 -5
- package/src/coValues/coMap.ts +14 -5
- package/src/coValues/deepLoading.ts +6 -12
- package/src/coValues/extensions/imageDef.ts +3 -1
- package/src/coValues/group.ts +8 -11
- package/src/coValues/inbox.ts +377 -0
- package/src/coValues/interfaces.ts +9 -6
- package/src/coValues/profile.ts +11 -0
- package/src/coValues/registeredSchemas.ts +12 -0
- package/src/exports.ts +21 -15
- package/src/implementation/anonymousJazzAgent.ts +6 -0
- package/src/implementation/createContext.ts +8 -9
- package/src/implementation/refs.ts +1 -1
- package/src/implementation/subscriptionScope.ts +1 -1
- package/src/index.native.ts +0 -1
- package/src/internal.ts +1 -9
- package/src/tests/account.test.ts +2 -2
- package/src/tests/coFeed.test.ts +0 -9
- package/src/tests/coMap.test.ts +11 -8
- package/src/tests/groupsAndAccounts.test.ts +1 -63
- package/src/tests/inbox.test.ts +299 -0
- package/src/tests/schemaUnion.test.ts +1 -1
- package/src/tests/utils.ts +14 -0
- package/tsup.config.ts +13 -0
- package/dist/native/coValues/account.js +0 -221
- package/dist/native/coValues/account.js.map +0 -1
- package/dist/native/coValues/coFeed.js +0 -571
- package/dist/native/coValues/coFeed.js.map +0 -1
- package/dist/native/coValues/coList.js +0 -404
- package/dist/native/coValues/coList.js.map +0 -1
- package/dist/native/coValues/coMap.js +0 -537
- package/dist/native/coValues/coMap.js.map +0 -1
- package/dist/native/coValues/deepLoading.js +0 -63
- package/dist/native/coValues/deepLoading.js.map +0 -1
- package/dist/native/coValues/extensions/imageDef.js +0 -42
- package/dist/native/coValues/extensions/imageDef.js.map +0 -1
- package/dist/native/coValues/group.js +0 -136
- package/dist/native/coValues/group.js.map +0 -1
- package/dist/native/coValues/interfaces.js +0 -135
- package/dist/native/coValues/interfaces.js.map +0 -1
- package/dist/native/coValues/schemaUnion.js +0 -89
- package/dist/native/coValues/schemaUnion.js.map +0 -1
- package/dist/native/exports.js +0 -5
- package/dist/native/exports.js.map +0 -1
- package/dist/native/implementation/createContext.js +0 -157
- package/dist/native/implementation/createContext.js.map +0 -1
- package/dist/native/implementation/devtoolsFormatters.js +0 -95
- package/dist/native/implementation/devtoolsFormatters.js.map +0 -1
- package/dist/native/implementation/errors.js +0 -2
- package/dist/native/implementation/errors.js.map +0 -1
- package/dist/native/implementation/inspect.js +0 -2
- package/dist/native/implementation/inspect.js.map +0 -1
- package/dist/native/implementation/refs.js +0 -115
- package/dist/native/implementation/refs.js.map +0 -1
- package/dist/native/implementation/schema.js +0 -96
- package/dist/native/implementation/schema.js.map +0 -1
- package/dist/native/implementation/subscriptionScope.js +0 -91
- package/dist/native/implementation/subscriptionScope.js.map +0 -1
- package/dist/native/implementation/symbols.js +0 -4
- package/dist/native/implementation/symbols.js.map +0 -1
- package/dist/native/index.native.js +0 -3
- package/dist/native/index.native.js.map +0 -1
- package/dist/native/internal.js +0 -18
- package/dist/native/internal.js.map +0 -1
- package/dist/native/lib/cache.js +0 -13
- package/dist/native/lib/cache.js.map +0 -1
- package/dist/native/lib/cache.test.js +0 -52
- package/dist/native/lib/cache.test.js.map +0 -1
- package/dist/web/coValues/account.js +0 -221
- package/dist/web/coValues/account.js.map +0 -1
- package/dist/web/coValues/coFeed.js +0 -571
- package/dist/web/coValues/coFeed.js.map +0 -1
- package/dist/web/coValues/coList.js +0 -404
- package/dist/web/coValues/coList.js.map +0 -1
- package/dist/web/coValues/coMap.js +0 -537
- package/dist/web/coValues/coMap.js.map +0 -1
- package/dist/web/coValues/deepLoading.js +0 -63
- package/dist/web/coValues/deepLoading.js.map +0 -1
- package/dist/web/coValues/extensions/imageDef.js +0 -42
- package/dist/web/coValues/extensions/imageDef.js.map +0 -1
- package/dist/web/coValues/group.js +0 -136
- package/dist/web/coValues/group.js.map +0 -1
- package/dist/web/coValues/interfaces.js +0 -135
- package/dist/web/coValues/interfaces.js.map +0 -1
- package/dist/web/coValues/schemaUnion.js +0 -89
- package/dist/web/coValues/schemaUnion.js.map +0 -1
- package/dist/web/exports.js +0 -5
- package/dist/web/exports.js.map +0 -1
- package/dist/web/implementation/createContext.js +0 -157
- package/dist/web/implementation/createContext.js.map +0 -1
- package/dist/web/implementation/devtoolsFormatters.js +0 -95
- package/dist/web/implementation/devtoolsFormatters.js.map +0 -1
- package/dist/web/implementation/errors.js +0 -2
- package/dist/web/implementation/errors.js.map +0 -1
- package/dist/web/implementation/inspect.js +0 -2
- package/dist/web/implementation/inspect.js.map +0 -1
- package/dist/web/implementation/refs.js +0 -115
- package/dist/web/implementation/refs.js.map +0 -1
- package/dist/web/implementation/schema.js +0 -96
- package/dist/web/implementation/schema.js.map +0 -1
- package/dist/web/implementation/subscriptionScope.js +0 -91
- package/dist/web/implementation/subscriptionScope.js.map +0 -1
- package/dist/web/implementation/symbols.js +0 -4
- package/dist/web/implementation/symbols.js.map +0 -1
- package/dist/web/index.web.js +0 -3
- package/dist/web/index.web.js.map +0 -1
- package/dist/web/internal.js +0 -18
- package/dist/web/internal.js.map +0 -1
- package/dist/web/lib/cache.js +0 -13
- package/dist/web/lib/cache.js.map +0 -1
- package/dist/web/lib/cache.test.js +0 -52
- package/dist/web/lib/cache.test.js.map +0 -1
package/package.json
CHANGED
@@ -6,25 +6,25 @@
|
|
6
6
|
"react-native": "dist/native/index.native.js",
|
7
7
|
"exports": {
|
8
8
|
".": {
|
9
|
-
"react-native": "./dist/
|
9
|
+
"react-native": "./dist/index.native.js",
|
10
10
|
"types": "./src/index.web.ts",
|
11
|
-
"default": "./dist/
|
11
|
+
"default": "./dist/index.web.js"
|
12
12
|
},
|
13
13
|
"./native": {
|
14
|
-
"react-native": "./dist/
|
14
|
+
"react-native": "./dist/index.native.js",
|
15
15
|
"types": "./src/index.native.ts",
|
16
|
-
"default": "./dist/
|
16
|
+
"default": "./dist/index.native.js"
|
17
17
|
},
|
18
18
|
"./src/*": "./src/*"
|
19
19
|
},
|
20
20
|
"type": "module",
|
21
21
|
"license": "MIT",
|
22
|
-
"version": "0.8.
|
22
|
+
"version": "0.8.48",
|
23
23
|
"dependencies": {
|
24
|
-
"
|
25
|
-
"cojson": "0.8.44"
|
24
|
+
"cojson": "0.8.48"
|
26
25
|
},
|
27
26
|
"devDependencies": {
|
27
|
+
"tsup": "8.3.5",
|
28
28
|
"typescript": "~5.6.2",
|
29
29
|
"vitest": "1.5.3"
|
30
30
|
},
|
@@ -38,12 +38,9 @@
|
|
38
38
|
"scripts": {
|
39
39
|
"format-and-lint": "biome check .",
|
40
40
|
"format-and-lint:fix": "biome check . --write",
|
41
|
-
"dev
|
42
|
-
"dev:native": "tsc --sourceMap --watch --outDir dist/native -p tsconfig.native.json",
|
41
|
+
"dev": "tsup --watch",
|
43
42
|
"test": "vitest --run --root ../../ --project jazz-tools",
|
44
43
|
"test:watch": "vitest --watch --root ../../ --project jazz-tools",
|
45
|
-
"build
|
46
|
-
"build:native": "tsc --sourceMap --outDir dist/native -p tsconfig.native.json",
|
47
|
-
"build": "rm -rf ./dist && pnpm run build:web && pnpm run build:native"
|
44
|
+
"build": "tsup"
|
48
45
|
}
|
49
46
|
}
|
package/src/coValues/account.ts
CHANGED
@@ -14,16 +14,13 @@ import {
|
|
14
14
|
} from "cojson";
|
15
15
|
import {
|
16
16
|
AnonymousJazzAgent,
|
17
|
-
CoMap,
|
18
17
|
type CoValue,
|
19
18
|
CoValueBase,
|
20
19
|
CoValueClass,
|
21
20
|
DeeplyLoaded,
|
22
21
|
DepthsIn,
|
23
|
-
Group,
|
24
22
|
ID,
|
25
23
|
MembersSym,
|
26
|
-
Profile,
|
27
24
|
Ref,
|
28
25
|
type RefEncoded,
|
29
26
|
RefIfCoValue,
|
@@ -37,6 +34,11 @@ import {
|
|
37
34
|
subscriptionsScopes,
|
38
35
|
} from "../internal.js";
|
39
36
|
import { coValuesCache } from "../lib/cache.js";
|
37
|
+
import { type CoMap } from "./coMap.js";
|
38
|
+
import { type Group } from "./group.js";
|
39
|
+
import { createInboxRoot } from "./inbox.js";
|
40
|
+
import { Profile } from "./profile.js";
|
41
|
+
import { RegisteredSchemas } from "./registeredSchemas.js";
|
40
42
|
|
41
43
|
/** @category Identity & Permissions */
|
42
44
|
export class Account extends CoValueBase implements CoValue {
|
@@ -59,7 +61,7 @@ export class Account extends CoValueBase implements CoValue {
|
|
59
61
|
optional: false,
|
60
62
|
} satisfies RefEncoded<Profile>,
|
61
63
|
root: {
|
62
|
-
ref: () => CoMap,
|
64
|
+
ref: () => RegisteredSchemas["CoMap"],
|
63
65
|
optional: true,
|
64
66
|
} satisfies RefEncoded<CoMap>,
|
65
67
|
};
|
@@ -183,7 +185,7 @@ export class Account extends CoValueBase implements CoValue {
|
|
183
185
|
fromRaw: rawAccount,
|
184
186
|
}) as A;
|
185
187
|
|
186
|
-
await account.
|
188
|
+
await account.applyMigration?.(creationProps);
|
187
189
|
},
|
188
190
|
});
|
189
191
|
|
@@ -234,18 +236,33 @@ export class Account extends CoValueBase implements CoValue {
|
|
234
236
|
return this.toJSON();
|
235
237
|
}
|
236
238
|
|
237
|
-
|
238
|
-
this: Account,
|
239
|
-
creationProps?: { name: string },
|
240
|
-
): void | Promise<void> {
|
239
|
+
async applyMigration(creationProps?: { name: string }) {
|
241
240
|
if (creationProps) {
|
242
|
-
const profileGroup = Group.create({ owner: this });
|
241
|
+
const profileGroup = RegisteredSchemas["Group"].create({ owner: this });
|
243
242
|
profileGroup.addMember("everyone", "reader");
|
244
243
|
this.profile = Profile.create(
|
245
244
|
{ name: creationProps.name },
|
246
245
|
{ owner: profileGroup },
|
247
246
|
);
|
248
247
|
}
|
248
|
+
|
249
|
+
const node = this._raw.core.node;
|
250
|
+
const profile = node
|
251
|
+
.expectCoValueLoaded(this._raw.get("profile")!)
|
252
|
+
.getCurrentContent() as RawCoMap;
|
253
|
+
|
254
|
+
if (!profile.get("inbox")) {
|
255
|
+
const inboxRoot = createInboxRoot(this);
|
256
|
+
profile.set("inbox", inboxRoot.id);
|
257
|
+
profile.set("inboxInvite", inboxRoot.inviteLink);
|
258
|
+
}
|
259
|
+
|
260
|
+
await this.migrate(creationProps);
|
261
|
+
}
|
262
|
+
|
263
|
+
// Placeholder method for subclasses to override
|
264
|
+
migrate(creationProps?: { name: string }) {
|
265
|
+
creationProps; // To avoid unused parameter warning
|
249
266
|
}
|
250
267
|
|
251
268
|
/** @category Subscription & Loading */
|
@@ -388,3 +405,5 @@ export function isControlledAccount(account: Account): account is Account & {
|
|
388
405
|
export type AccountClass<Acc extends Account> = CoValueClass<Acc> & {
|
389
406
|
fromNode: (typeof Account)["fromNode"];
|
390
407
|
};
|
408
|
+
|
409
|
+
RegisteredSchemas["Account"] = Account;
|
package/src/coValues/coFeed.ts
CHANGED
@@ -16,7 +16,6 @@ import type {
|
|
16
16
|
CoValueClass,
|
17
17
|
DeeplyLoaded,
|
18
18
|
DepthsIn,
|
19
|
-
Group,
|
20
19
|
ID,
|
21
20
|
IfCo,
|
22
21
|
Schema,
|
@@ -24,7 +23,6 @@ import type {
|
|
24
23
|
UnCo,
|
25
24
|
} from "../internal.js";
|
26
25
|
import {
|
27
|
-
Account,
|
28
26
|
CoValueBase,
|
29
27
|
ItemsSym,
|
30
28
|
Ref,
|
@@ -37,6 +35,9 @@ import {
|
|
37
35
|
subscribeToCoValue,
|
38
36
|
subscribeToExistingCoValue,
|
39
37
|
} from "../internal.js";
|
38
|
+
import { type Account } from "./account.js";
|
39
|
+
import { type Group } from "./group.js";
|
40
|
+
import { RegisteredSchemas } from "./registeredSchemas.js";
|
40
41
|
|
41
42
|
/** @deprecated Use CoFeedEntry instead */
|
42
43
|
export type CoStreamEntry<Item> = CoFeedEntry<Item>;
|
@@ -436,7 +437,7 @@ function entryFromRawEntry<Item>(
|
|
436
437
|
return (
|
437
438
|
accountID &&
|
438
439
|
new Ref<Account>(accountID as unknown as ID<Account>, loadedAs, {
|
439
|
-
ref: Account,
|
440
|
+
ref: RegisteredSchemas["Account"],
|
440
441
|
optional: false,
|
441
442
|
})?.accessFrom(
|
442
443
|
accessFrom,
|
package/src/coValues/coList.ts
CHANGED
@@ -13,9 +13,7 @@ import type {
|
|
13
13
|
UnCo,
|
14
14
|
} from "../internal.js";
|
15
15
|
import {
|
16
|
-
Account,
|
17
16
|
AnonymousJazzAgent,
|
18
|
-
Group,
|
19
17
|
ItemsSym,
|
20
18
|
Ref,
|
21
19
|
SchemaInit,
|
@@ -30,6 +28,9 @@ import {
|
|
30
28
|
subscriptionsScopes,
|
31
29
|
} from "../internal.js";
|
32
30
|
import { coValuesCache } from "../lib/cache.js";
|
31
|
+
import { type Account } from "./account.js";
|
32
|
+
import { type Group } from "./group.js";
|
33
|
+
import { RegisteredSchemas } from "./registeredSchemas.js";
|
33
34
|
|
34
35
|
/**
|
35
36
|
* CoLists are collaborative versions of plain arrays.
|
@@ -108,8 +109,8 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
|
|
108
109
|
/** @category Collaboration */
|
109
110
|
get _owner(): Account | Group {
|
110
111
|
return this._raw.group instanceof RawAccount
|
111
|
-
? Account.fromRaw(this._raw.group)
|
112
|
-
: Group.fromRaw(this._raw.group);
|
112
|
+
? RegisteredSchemas["Account"].fromRaw(this._raw.group)
|
113
|
+
: RegisteredSchemas["Group"].fromRaw(this._raw.group);
|
113
114
|
}
|
114
115
|
|
115
116
|
/**
|
@@ -162,7 +163,9 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
|
|
162
163
|
const rawAccount = this._raw.core.node.account;
|
163
164
|
|
164
165
|
if (rawAccount instanceof RawAccount) {
|
165
|
-
return coValuesCache.get(rawAccount, () =>
|
166
|
+
return coValuesCache.get(rawAccount, () =>
|
167
|
+
RegisteredSchemas["Account"].fromRaw(rawAccount),
|
168
|
+
);
|
166
169
|
}
|
167
170
|
|
168
171
|
return new AnonymousJazzAgent(this._raw.core.node);
|
package/src/coValues/coMap.ts
CHANGED
@@ -13,7 +13,6 @@ import type {
|
|
13
13
|
CoValueClass,
|
14
14
|
DeeplyLoaded,
|
15
15
|
DepthsIn,
|
16
|
-
Group,
|
17
16
|
ID,
|
18
17
|
IfCo,
|
19
18
|
RefEncoded,
|
@@ -22,7 +21,6 @@ import type {
|
|
22
21
|
co,
|
23
22
|
} from "../internal.js";
|
24
23
|
import {
|
25
|
-
Account,
|
26
24
|
CoValueBase,
|
27
25
|
ItemsSym,
|
28
26
|
Ref,
|
@@ -36,6 +34,9 @@ import {
|
|
36
34
|
subscribeToExistingCoValue,
|
37
35
|
subscriptionsScopes,
|
38
36
|
} from "../internal.js";
|
37
|
+
import { type Account } from "./account.js";
|
38
|
+
import { type Group } from "./group.js";
|
39
|
+
import { RegisteredSchemas } from "./registeredSchemas.js";
|
39
40
|
|
40
41
|
type CoMapEdit<V> = {
|
41
42
|
value?: V;
|
@@ -178,7 +179,7 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
178
179
|
by:
|
179
180
|
rawEdit.by &&
|
180
181
|
new Ref<Account>(rawEdit.by as ID<Account>, target._loadedAs, {
|
181
|
-
ref: Account,
|
182
|
+
ref: RegisteredSchemas["Account"],
|
182
183
|
optional: false,
|
183
184
|
}).accessFrom(target, "_edits." + key + ".by"),
|
184
185
|
madeAt: rawEdit.at,
|
@@ -616,8 +617,14 @@ const CoMapProxyHandler: ProxyHandler<CoMap> = {
|
|
616
617
|
} else if (key in target) {
|
617
618
|
return Reflect.get(target, key, receiver);
|
618
619
|
} else {
|
619
|
-
const
|
620
|
-
|
620
|
+
const schema = target._schema;
|
621
|
+
|
622
|
+
if (!schema) {
|
623
|
+
return undefined;
|
624
|
+
}
|
625
|
+
|
626
|
+
const descriptor = (schema[key as keyof CoMap["_schema"]] ||
|
627
|
+
schema[ItemsSym]) as Schema;
|
621
628
|
if (descriptor && typeof key === "string") {
|
622
629
|
const raw = target._raw.get(key);
|
623
630
|
|
@@ -742,3 +749,5 @@ const CoMapProxyHandler: ProxyHandler<CoMap> = {
|
|
742
749
|
}
|
743
750
|
},
|
744
751
|
};
|
752
|
+
|
753
|
+
RegisteredSchemas["CoMap"] = CoMap;
|
@@ -1,16 +1,10 @@
|
|
1
1
|
import { SessionID } from "cojson";
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Ref,
|
9
|
-
RefEncoded,
|
10
|
-
UnCo,
|
11
|
-
} from "../internal.js";
|
12
|
-
import { CoKeys, CoMap } from "./coMap.js";
|
13
|
-
import { CoValue, ID } from "./interfaces.js";
|
2
|
+
import { ItemsSym, type Ref, RefEncoded, UnCo } from "../internal.js";
|
3
|
+
import { type Account } from "./account.js";
|
4
|
+
import { type CoFeed, CoFeedEntry } from "./coFeed.js";
|
5
|
+
import { type CoList } from "./coList.js";
|
6
|
+
import { type CoKeys, type CoMap } from "./coMap.js";
|
7
|
+
import { type CoValue, type ID } from "./interfaces.js";
|
14
8
|
|
15
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
16
10
|
export function fulfillsDepth(depth: any, value: CoValue): boolean {
|
@@ -1,4 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { co, subscriptionsScopes } from "../../internal.js";
|
2
|
+
import { FileStream } from "../coFeed.js";
|
3
|
+
import { CoMap } from "../coMap.js";
|
2
4
|
|
3
5
|
/** @category Media */
|
4
6
|
export class ImageDefinition extends CoMap {
|
package/src/coValues/group.ts
CHANGED
@@ -9,24 +9,19 @@ import type {
|
|
9
9
|
Schema,
|
10
10
|
} from "../internal.js";
|
11
11
|
import {
|
12
|
-
Account,
|
13
|
-
AccountAndGroupProxyHandler,
|
14
|
-
CoMap,
|
15
12
|
CoValueBase,
|
16
13
|
MembersSym,
|
17
14
|
Ref,
|
18
|
-
co,
|
19
15
|
ensureCoValueLoaded,
|
20
|
-
isControlledAccount,
|
21
16
|
loadCoValue,
|
22
17
|
subscribeToCoValue,
|
23
18
|
subscribeToExistingCoValue,
|
24
19
|
} from "../internal.js";
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
20
|
+
import { AccountAndGroupProxyHandler, isControlledAccount } from "./account.js";
|
21
|
+
import { type Account } from "./account.js";
|
22
|
+
import { type CoMap } from "./coMap.js";
|
23
|
+
import { type Profile } from "./profile.js";
|
24
|
+
import { RegisteredSchemas } from "./registeredSchemas.js";
|
30
25
|
|
31
26
|
/** @category Identity & Permissions */
|
32
27
|
export class Group extends CoValueBase implements CoValue {
|
@@ -51,7 +46,7 @@ export class Group extends CoValueBase implements CoValue {
|
|
51
46
|
profile: "json" satisfies Schema,
|
52
47
|
root: "json" satisfies Schema,
|
53
48
|
[MembersSym]: {
|
54
|
-
ref: () => Account,
|
49
|
+
ref: () => RegisteredSchemas["Account"],
|
55
50
|
optional: false,
|
56
51
|
} satisfies RefEncoded<Account>,
|
57
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -229,3 +224,5 @@ export class Group extends CoValueBase implements CoValue {
|
|
229
224
|
return this._raw.core.waitForSync(options);
|
230
225
|
}
|
231
226
|
}
|
227
|
+
|
228
|
+
RegisteredSchemas["Group"] = Group;
|