jazz-tools 0.7.35-unique.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +44 -57
- package/CHANGELOG.md +27 -7
- package/dist/coValues/account.js +8 -2
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +5 -2
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +16 -9
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +30 -3
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/interfaces.js +5 -2
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/createContext.js +55 -5
- package/dist/implementation/createContext.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +1 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/implementation/refs.js +8 -2
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +4 -3
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tests/coMap.test.js +92 -1
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +37 -0
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +7 -7
- package/dist/tests/deepLoading.test.js.map +1 -1
- package/package.json +4 -4
- package/src/coValues/account.ts +9 -3
- package/src/coValues/coList.ts +5 -1
- package/src/coValues/coMap.ts +56 -17
- package/src/coValues/coStream.ts +38 -4
- package/src/coValues/interfaces.ts +8 -4
- package/src/implementation/createContext.ts +117 -11
- package/src/implementation/devtoolsFormatters.ts +1 -0
- package/src/implementation/refs.ts +13 -6
- package/src/implementation/schema.ts +1 -0
- package/src/implementation/subscriptionScope.ts +28 -25
- package/src/index.ts +3 -0
- package/src/tests/coMap.test.ts +139 -1
- package/src/tests/coStream.test.ts +53 -0
- package/src/tests/deepLoading.test.ts +7 -7
@@ -40,15 +40,16 @@ describe("Deep loading with depth arg", async () => {
|
|
40
40
|
crypto: Crypto,
|
41
41
|
});
|
42
42
|
test("loading a deeply nested object will wait until all required refs are loaded", async () => {
|
43
|
+
const ownership = { owner: me };
|
43
44
|
const map = TestMap.create({
|
44
45
|
list: TestList.create([
|
45
46
|
InnerMap.create({
|
46
47
|
stream: TestStream.create([
|
47
|
-
InnermostMap.create({ value: "hello" },
|
48
|
-
],
|
49
|
-
},
|
50
|
-
],
|
51
|
-
},
|
48
|
+
InnermostMap.create({ value: "hello" }, ownership),
|
49
|
+
], ownership),
|
50
|
+
}, ownership),
|
51
|
+
], ownership),
|
52
|
+
}, ownership);
|
52
53
|
const map1 = await TestMap.load(map.id, meOnSecondPeer, {});
|
53
54
|
expectTypeOf(map1).toEqualTypeOf();
|
54
55
|
if (map1 === undefined) {
|
@@ -81,8 +82,7 @@ describe("Deep loading with depth arg", async () => {
|
|
81
82
|
throw new Error("map4 is undefined");
|
82
83
|
}
|
83
84
|
expect(map4.list[0]?.stream).not.toBe(null);
|
84
|
-
|
85
|
-
// expect(map4.list[0]?.stream?.[me.id]).toBe(undefined)
|
85
|
+
expect(map4.list[0]?.stream?.[me.id]).not.toBe(null);
|
86
86
|
expect(map4.list[0]?.stream?.byMe?.value).toBe(null);
|
87
87
|
const map5 = await TestMap.load(map.id, meOnSecondPeer, {
|
88
88
|
list: [{ stream: [{}] }],
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deepLoading.test.js","sourceRoot":"","sources":["../../src/tests/deepLoading.test.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACH,OAAO,EAC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AAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
"types": "./src/index.ts",
|
6
6
|
"type": "module",
|
7
7
|
"license": "MIT",
|
8
|
-
"version": "0.
|
8
|
+
"version": "0.8.0",
|
9
9
|
"dependencies": {
|
10
|
-
"
|
11
|
-
"
|
10
|
+
"cojson": "0.8.0",
|
11
|
+
"fast-check": "^3.17.2"
|
12
12
|
},
|
13
13
|
"devDependencies": {
|
14
14
|
"typescript": "^5.3.3",
|
15
|
-
"vitest": "
|
15
|
+
"vitest": "1.5.3"
|
16
16
|
},
|
17
17
|
"madge": {
|
18
18
|
"detectiveOptions": {
|
package/src/coValues/account.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { LocalNode, cojsonInternals } from "cojson";
|
2
|
-
import
|
2
|
+
import {
|
3
3
|
AgentSecret,
|
4
4
|
CoID,
|
5
5
|
CryptoProvider,
|
@@ -21,6 +21,7 @@ import {
|
|
21
21
|
RefIfCoValue,
|
22
22
|
DeeplyLoaded,
|
23
23
|
DepthsIn,
|
24
|
+
AnonymousJazzAgent,
|
24
25
|
} from "../internal.js";
|
25
26
|
import {
|
26
27
|
Group,
|
@@ -67,8 +68,13 @@ export class Account extends CoValueBase implements CoValue {
|
|
67
68
|
get _owner(): Account {
|
68
69
|
return this as Account;
|
69
70
|
}
|
70
|
-
get _loadedAs(): Account {
|
71
|
-
|
71
|
+
get _loadedAs(): Account | AnonymousJazzAgent {
|
72
|
+
if (this.isMe) return this;
|
73
|
+
|
74
|
+
if (this._raw.core.node.account instanceof RawAccount) {
|
75
|
+
return Account.fromRaw(this._raw.core.node.account);
|
76
|
+
}
|
77
|
+
return new AnonymousJazzAgent(this._raw.core.node);
|
72
78
|
}
|
73
79
|
|
74
80
|
declare profile: Profile | null;
|
package/src/coValues/coList.ts
CHANGED
@@ -14,6 +14,7 @@ import type {
|
|
14
14
|
} from "../internal.js";
|
15
15
|
import {
|
16
16
|
Account,
|
17
|
+
AnonymousJazzAgent,
|
17
18
|
Group,
|
18
19
|
ItemsSym,
|
19
20
|
Ref,
|
@@ -163,7 +164,10 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
|
|
163
164
|
}
|
164
165
|
|
165
166
|
get _loadedAs() {
|
166
|
-
|
167
|
+
if (this._raw.core.node.account instanceof RawAccount) {
|
168
|
+
return Account.fromRaw(this._raw.core.node.account);
|
169
|
+
}
|
170
|
+
return new AnonymousJazzAgent(this._raw.core.node);
|
167
171
|
}
|
168
172
|
|
169
173
|
static get [Symbol.species]() {
|
package/src/coValues/coMap.ts
CHANGED
@@ -15,6 +15,8 @@ import type {
|
|
15
15
|
DepthsIn,
|
16
16
|
DeeplyLoaded,
|
17
17
|
CoValueClass,
|
18
|
+
AnonymousJazzAgent,
|
19
|
+
co,
|
18
20
|
} from "../internal.js";
|
19
21
|
import {
|
20
22
|
Account,
|
@@ -194,11 +196,6 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
194
196
|
};
|
195
197
|
}
|
196
198
|
|
197
|
-
/** @internal */
|
198
|
-
get _loadedAs() {
|
199
|
-
return Account.fromNode(this._raw.core.node);
|
200
|
-
}
|
201
|
-
|
202
199
|
/** @internal */
|
203
200
|
constructor(
|
204
201
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -445,9 +442,9 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
445
442
|
|
446
443
|
static findUnique<M extends CoMap>(
|
447
444
|
this: CoValueClass<M>,
|
448
|
-
unique: CoValueUniqueness[
|
445
|
+
unique: CoValueUniqueness["uniqueness"],
|
449
446
|
ownerID: ID<Account> | ID<Group>,
|
450
|
-
as: Account | Group,
|
447
|
+
as: Account | Group | AnonymousJazzAgent,
|
451
448
|
) {
|
452
449
|
const header = {
|
453
450
|
type: "comap" as const,
|
@@ -458,10 +455,9 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
458
455
|
meta: null,
|
459
456
|
uniqueness: unique,
|
460
457
|
};
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
) as ID<M>;
|
458
|
+
const crypto =
|
459
|
+
as._type === "Anonymous" ? as.node.crypto : as._raw.core.crypto;
|
460
|
+
return cojsonInternals.idforHeader(header, crypto) as ID<M>;
|
465
461
|
}
|
466
462
|
|
467
463
|
/**
|
@@ -532,11 +528,44 @@ export type CoKeys<Map extends object> = Exclude<
|
|
532
528
|
keyof CoMap
|
533
529
|
>;
|
534
530
|
|
531
|
+
/**
|
532
|
+
* Force required ref fields to be non nullable
|
533
|
+
*
|
534
|
+
* Considering that:
|
535
|
+
* - Optional refs are typed as co<InstanceType<CoValueClass> | null | undefined>
|
536
|
+
* - Required refs are typed as co<InstanceType<CoValueClass> | null>
|
537
|
+
*
|
538
|
+
* This type works in two steps:
|
539
|
+
* - Remove the null from both types
|
540
|
+
* - Then we check if the input type accepts undefined, if positive we put the null union back
|
541
|
+
*
|
542
|
+
* So the optional refs stays unchanged while we safely remove the null union
|
543
|
+
* from required refs
|
544
|
+
*
|
545
|
+
* This way required refs can be marked as required in the CoMapInit while
|
546
|
+
* staying a nullable property for value access.
|
547
|
+
*
|
548
|
+
* Example:
|
549
|
+
*
|
550
|
+
* const map = MyCoMap.create({
|
551
|
+
* requiredRef: NestedMap.create({}) // null is not valid here
|
552
|
+
* })
|
553
|
+
*
|
554
|
+
* map.requiredRef // this value is still nullable
|
555
|
+
*/
|
556
|
+
type ForceRequiredRef<V> = V extends co<InstanceType<CoValueClass> | null>
|
557
|
+
? NonNullable<V>
|
558
|
+
: V extends co<InstanceType<CoValueClass> | undefined>
|
559
|
+
? V | null
|
560
|
+
: V;
|
561
|
+
|
535
562
|
export type CoMapInit<Map extends object> = {
|
536
563
|
[Key in CoKeys<Map> as undefined extends Map[Key]
|
537
564
|
? never
|
538
|
-
: IfCo<Map[Key], Key>]: Map[Key]
|
539
|
-
} & {
|
565
|
+
: IfCo<Map[Key], Key>]: ForceRequiredRef<Map[Key]>;
|
566
|
+
} & {
|
567
|
+
[Key in CoKeys<Map> as IfCo<Map[Key], Key>]?: ForceRequiredRef<Map[Key]>;
|
568
|
+
};
|
540
569
|
|
541
570
|
// TODO: cache handlers per descriptor for performance?
|
542
571
|
const CoMapProxyHandler: ProxyHandler<CoMap> = {
|
@@ -592,10 +621,20 @@ const CoMapProxyHandler: ProxyHandler<CoMap> = {
|
|
592
621
|
} else if ("encoded" in descriptor) {
|
593
622
|
target._raw.set(key, descriptor.encoded.encode(value));
|
594
623
|
} else if (isRefEncoded(descriptor)) {
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
624
|
+
if (value === null) {
|
625
|
+
if (descriptor.optional) {
|
626
|
+
target._raw.set(key, null);
|
627
|
+
} else {
|
628
|
+
throw new Error(
|
629
|
+
`Cannot set required reference ${key} to null`,
|
630
|
+
);
|
631
|
+
}
|
632
|
+
} else {
|
633
|
+
target._raw.set(key, value.id);
|
634
|
+
subscriptionsScopes
|
635
|
+
.get(target)
|
636
|
+
?.onRefAccessedOrSet(target.id, value.id);
|
637
|
+
}
|
599
638
|
}
|
600
639
|
return true;
|
601
640
|
} else {
|
package/src/coValues/coStream.ts
CHANGED
@@ -20,6 +20,7 @@ import type {
|
|
20
20
|
CoValueClass,
|
21
21
|
DeeplyLoaded,
|
22
22
|
DepthsIn,
|
23
|
+
AnonymousJazzAgent,
|
23
24
|
} from "../internal.js";
|
24
25
|
import {
|
25
26
|
ItemsSym,
|
@@ -77,13 +78,21 @@ export class CoStream<Item = any> extends CoValueBase implements CoValue {
|
|
77
78
|
[key: ID<Account>]: CoStreamEntry<Item>;
|
78
79
|
|
79
80
|
get byMe(): CoStreamEntry<Item> | undefined {
|
80
|
-
|
81
|
+
if (this._loadedAs._type === "Account") {
|
82
|
+
return this[this._loadedAs.id];
|
83
|
+
} else {
|
84
|
+
return undefined;
|
85
|
+
}
|
81
86
|
}
|
82
87
|
perSession!: {
|
83
88
|
[key: SessionID]: CoStreamEntry<Item>;
|
84
89
|
};
|
85
90
|
get inCurrentSession(): CoStreamEntry<Item> | undefined {
|
86
|
-
|
91
|
+
if (this._loadedAs._type === "Account") {
|
92
|
+
return this.perSession[this._loadedAs.sessionID!];
|
93
|
+
} else {
|
94
|
+
return undefined;
|
95
|
+
}
|
87
96
|
}
|
88
97
|
|
89
98
|
constructor(
|
@@ -233,7 +242,7 @@ function entryFromRawEntry<Item>(
|
|
233
242
|
at: Date;
|
234
243
|
value: JsonValue;
|
235
244
|
},
|
236
|
-
loadedAs: Account,
|
245
|
+
loadedAs: Account | AnonymousJazzAgent,
|
237
246
|
accountID: ID<Account> | undefined,
|
238
247
|
itemField: Schema,
|
239
248
|
): Omit<CoStreamEntry<Item>, "all"> {
|
@@ -509,6 +518,10 @@ export class BinaryCoStream extends CoValueBase implements CoValue {
|
|
509
518
|
return this._raw.getBinaryChunks(options?.allowUnfinished);
|
510
519
|
}
|
511
520
|
|
521
|
+
isBinaryStreamEnded(): boolean {
|
522
|
+
return this._raw.isBinaryStreamEnded();
|
523
|
+
}
|
524
|
+
|
512
525
|
start(options: BinaryStreamInfo): void {
|
513
526
|
this._raw.startBinaryStream(options);
|
514
527
|
}
|
@@ -540,7 +553,28 @@ export class BinaryCoStream extends CoValueBase implements CoValue {
|
|
540
553
|
allowUnfinished?: boolean;
|
541
554
|
},
|
542
555
|
): Promise<Blob | undefined> {
|
543
|
-
|
556
|
+
let stream = await this.load(id, as, []);
|
557
|
+
|
558
|
+
/**
|
559
|
+
* If the user hasn't requested an incomplete blob and the
|
560
|
+
* stream isn't complete wait for the stream download before progressing
|
561
|
+
*/
|
562
|
+
if (!options?.allowUnfinished && !stream?.isBinaryStreamEnded()) {
|
563
|
+
stream = await new Promise<BinaryCoStream>((resolve) => {
|
564
|
+
const unsubscribe = subscribeToCoValue(
|
565
|
+
this,
|
566
|
+
id,
|
567
|
+
as,
|
568
|
+
[],
|
569
|
+
(value) => {
|
570
|
+
if (value.isBinaryStreamEnded()) {
|
571
|
+
unsubscribe();
|
572
|
+
resolve(value);
|
573
|
+
}
|
574
|
+
},
|
575
|
+
);
|
576
|
+
});
|
577
|
+
}
|
544
578
|
|
545
579
|
return stream?.toBlob({
|
546
580
|
allowUnfinished: options?.allowUnfinished,
|
@@ -8,6 +8,7 @@ import {
|
|
8
8
|
Ref,
|
9
9
|
inspect,
|
10
10
|
subscriptionsScopes,
|
11
|
+
AnonymousJazzAgent,
|
11
12
|
} from "../internal.js";
|
12
13
|
import { fulfillsDepth } from "./deepLoading.js";
|
13
14
|
|
@@ -35,7 +36,7 @@ export interface CoValue {
|
|
35
36
|
/** @category Internals */
|
36
37
|
_raw: RawCoValue;
|
37
38
|
/** @internal */
|
38
|
-
readonly _loadedAs: Account;
|
39
|
+
readonly _loadedAs: Account | AnonymousJazzAgent;
|
39
40
|
/** @category Stringifying & Inspection */
|
40
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
41
42
|
toJSON(key?: string, seenAbove?: ID<CoValue>[]): any[] | object | string;
|
@@ -86,7 +87,10 @@ export class CoValueBase implements CoValue {
|
|
86
87
|
|
87
88
|
/** @private */
|
88
89
|
get _loadedAs() {
|
89
|
-
|
90
|
+
if (this._raw.core.node.account instanceof RawAccount) {
|
91
|
+
return Account.fromRaw(this._raw.core.node.account);
|
92
|
+
}
|
93
|
+
return new AnonymousJazzAgent(this._raw.core.node);
|
90
94
|
}
|
91
95
|
|
92
96
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -134,7 +138,7 @@ export class CoValueBase implements CoValue {
|
|
134
138
|
export function loadCoValue<V extends CoValue, Depth>(
|
135
139
|
cls: CoValueClass<V>,
|
136
140
|
id: ID<V>,
|
137
|
-
as: Account,
|
141
|
+
as: Account | AnonymousJazzAgent,
|
138
142
|
depth: Depth & DepthsIn<V>,
|
139
143
|
): Promise<DeeplyLoaded<V, Depth> | undefined> {
|
140
144
|
return new Promise((resolve) => {
|
@@ -170,7 +174,7 @@ export function ensureCoValueLoaded<V extends CoValue, Depth>(
|
|
170
174
|
export function subscribeToCoValue<V extends CoValue, Depth>(
|
171
175
|
cls: CoValueClass<V>,
|
172
176
|
id: ID<V>,
|
173
|
-
as: Account,
|
177
|
+
as: Account | AnonymousJazzAgent,
|
174
178
|
depth: Depth & DepthsIn<V>,
|
175
179
|
listener: (value: DeeplyLoaded<V, Depth>) => void,
|
176
180
|
onUnavailable?: () => void,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
AgentSecret,
|
3
3
|
CoID,
|
4
|
-
|
4
|
+
ControlledAgent,
|
5
5
|
CryptoProvider,
|
6
6
|
LocalNode,
|
7
7
|
Peer,
|
@@ -17,6 +17,7 @@ export type AuthResult =
|
|
17
17
|
credentials: { accountID: ID<Account>; secret: AgentSecret };
|
18
18
|
onSuccess: () => void;
|
19
19
|
onError: (error: string | Error) => void;
|
20
|
+
logOut: () => void;
|
20
21
|
}
|
21
22
|
| {
|
22
23
|
type: "new";
|
@@ -28,6 +29,7 @@ export type AuthResult =
|
|
28
29
|
}) => Promise<void>;
|
29
30
|
onSuccess: () => void;
|
30
31
|
onError: (error: string | Error) => void;
|
32
|
+
logOut: () => void;
|
31
33
|
};
|
32
34
|
|
33
35
|
export interface AuthMethod {
|
@@ -44,42 +46,105 @@ export const fixedCredentialsAuth = (credentials: {
|
|
44
46
|
credentials,
|
45
47
|
onSuccess: () => {},
|
46
48
|
onError: () => {},
|
49
|
+
logOut: () => {},
|
47
50
|
}),
|
48
51
|
};
|
49
52
|
};
|
50
53
|
|
51
|
-
export
|
54
|
+
export const ephemeralCredentialsAuth = (): AuthMethod => {
|
52
55
|
return {
|
53
|
-
|
56
|
+
start: async () => ({
|
57
|
+
type: "new",
|
58
|
+
creationProps: { name: "Ephemeral" },
|
59
|
+
saveCredentials: async () => {},
|
60
|
+
onSuccess: () => {},
|
61
|
+
onError: () => {},
|
62
|
+
logOut: () => {},
|
63
|
+
}),
|
64
|
+
};
|
65
|
+
};
|
66
|
+
|
67
|
+
export async function randomSessionProvider(
|
68
|
+
accountID: ID<Account>,
|
69
|
+
crypto: CryptoProvider,
|
70
|
+
) {
|
71
|
+
return {
|
72
|
+
sessionID: crypto.newRandomSessionID(
|
54
73
|
accountID as unknown as RawAccountID,
|
55
74
|
),
|
56
75
|
sessionDone: () => {},
|
57
76
|
};
|
58
77
|
}
|
59
78
|
|
60
|
-
|
61
|
-
AccountSchema = Account as unknown as AccountClass<Acc>,
|
62
|
-
auth,
|
63
|
-
sessionProvider,
|
64
|
-
peersToLoadFrom,
|
65
|
-
crypto,
|
66
|
-
}: {
|
79
|
+
type ContextParamsWithAuth<Acc extends Account> = {
|
67
80
|
AccountSchema?: AccountClass<Acc>;
|
68
81
|
auth: AuthMethod;
|
69
82
|
sessionProvider: (
|
70
83
|
accountID: ID<Account>,
|
84
|
+
crypto: CryptoProvider,
|
71
85
|
) => Promise<{ sessionID: SessionID; sessionDone: () => void }>;
|
86
|
+
} & BaseContextParams;
|
87
|
+
|
88
|
+
type BaseContextParams = {
|
72
89
|
peersToLoadFrom: Peer[];
|
73
90
|
crypto: CryptoProvider;
|
74
|
-
}
|
91
|
+
};
|
92
|
+
|
93
|
+
export type JazzContextWithAccount<Acc extends Account> = {
|
94
|
+
account: Acc;
|
95
|
+
done: () => void;
|
96
|
+
logOut: () => void;
|
97
|
+
};
|
98
|
+
|
99
|
+
export type JazzContextWithAgent = {
|
100
|
+
agent: AnonymousJazzAgent;
|
101
|
+
done: () => void;
|
102
|
+
logOut: () => void;
|
103
|
+
};
|
104
|
+
|
105
|
+
export type JazzContext<Acc extends Account> = JazzContextWithAccount<Acc> | JazzContextWithAgent;
|
106
|
+
|
107
|
+
export async function createJazzContext<Acc extends Account>({
|
108
|
+
AccountSchema,
|
109
|
+
auth,
|
110
|
+
sessionProvider,
|
111
|
+
peersToLoadFrom,
|
112
|
+
crypto,
|
113
|
+
}: ContextParamsWithAuth<Acc>): Promise<JazzContextWithAccount<Acc>>;
|
114
|
+
export async function createJazzContext({
|
115
|
+
peersToLoadFrom,
|
116
|
+
crypto,
|
117
|
+
}: BaseContextParams): Promise<JazzContextWithAgent>;
|
118
|
+
export async function createJazzContext<Acc extends Account>(
|
119
|
+
options: ContextParamsWithAuth<Acc> | BaseContextParams,
|
120
|
+
): Promise<
|
121
|
+
JazzContext<Acc>
|
122
|
+
>
|
123
|
+
export async function createJazzContext<Acc extends Account>(
|
124
|
+
options: ContextParamsWithAuth<Acc> | BaseContextParams,
|
125
|
+
): Promise<
|
126
|
+
JazzContext<Acc>
|
127
|
+
> {
|
75
128
|
// eslint-disable-next-line no-constant-condition
|
76
129
|
while (true) {
|
130
|
+
if (!("auth" in options)) {
|
131
|
+
return createAnonymousJazzContext({
|
132
|
+
peersToLoadFrom: options.peersToLoadFrom,
|
133
|
+
crypto: options.crypto,
|
134
|
+
});
|
135
|
+
}
|
136
|
+
|
137
|
+
const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
|
138
|
+
const AccountSchema =
|
139
|
+
options.AccountSchema ?? (Account as unknown as AccountClass<Acc>);
|
140
|
+
|
77
141
|
const authResult = await auth.start(crypto);
|
78
142
|
|
79
143
|
if (authResult.type === "existing") {
|
80
144
|
try {
|
81
145
|
const { sessionID, sessionDone } = await sessionProvider(
|
82
146
|
authResult.credentials.accountID,
|
147
|
+
crypto,
|
83
148
|
);
|
84
149
|
|
85
150
|
try {
|
@@ -108,6 +173,11 @@ export async function createJazzContext<Acc extends Account>({
|
|
108
173
|
node.gracefulShutdown();
|
109
174
|
sessionDone();
|
110
175
|
},
|
176
|
+
logOut: () => {
|
177
|
+
node.gracefulShutdown();
|
178
|
+
sessionDone();
|
179
|
+
authResult.logOut();
|
180
|
+
},
|
111
181
|
};
|
112
182
|
} catch (e) {
|
113
183
|
authResult.onError(
|
@@ -151,6 +221,10 @@ export async function createJazzContext<Acc extends Account>({
|
|
151
221
|
done: () => {
|
152
222
|
node.gracefulShutdown();
|
153
223
|
},
|
224
|
+
logOut: () => {
|
225
|
+
node.gracefulShutdown();
|
226
|
+
authResult.logOut();
|
227
|
+
},
|
154
228
|
};
|
155
229
|
} catch (e) {
|
156
230
|
authResult.onError(
|
@@ -160,3 +234,35 @@ export async function createJazzContext<Acc extends Account>({
|
|
160
234
|
}
|
161
235
|
}
|
162
236
|
}
|
237
|
+
|
238
|
+
export class AnonymousJazzAgent {
|
239
|
+
_type = "Anonymous" as const;
|
240
|
+
constructor(public node: LocalNode) {}
|
241
|
+
}
|
242
|
+
|
243
|
+
export async function createAnonymousJazzContext({
|
244
|
+
peersToLoadFrom,
|
245
|
+
crypto,
|
246
|
+
}: {
|
247
|
+
peersToLoadFrom: Peer[];
|
248
|
+
crypto: CryptoProvider;
|
249
|
+
}): Promise<JazzContextWithAgent> {
|
250
|
+
const agentSecret = crypto.newRandomAgentSecret();
|
251
|
+
const rawAgent = new ControlledAgent(agentSecret, crypto);
|
252
|
+
|
253
|
+
const node = new LocalNode(
|
254
|
+
rawAgent,
|
255
|
+
crypto.newRandomSessionID(rawAgent.id),
|
256
|
+
crypto,
|
257
|
+
);
|
258
|
+
|
259
|
+
for (const peer of peersToLoadFrom) {
|
260
|
+
node.syncManager.addPeer(peer);
|
261
|
+
}
|
262
|
+
|
263
|
+
return {
|
264
|
+
agent: new AnonymousJazzAgent(node),
|
265
|
+
done: () => {},
|
266
|
+
logOut: () => {},
|
267
|
+
};
|
268
|
+
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { CoID, RawCoValue } from "cojson";
|
2
2
|
import type {
|
3
3
|
Account,
|
4
|
+
AnonymousJazzAgent,
|
4
5
|
CoValue,
|
5
6
|
ID,
|
6
7
|
RefEncoded,
|
@@ -19,7 +20,7 @@ const TRACE_ACCESSES = false;
|
|
19
20
|
export class Ref<out V extends CoValue> {
|
20
21
|
constructor(
|
21
22
|
readonly id: ID<V>,
|
22
|
-
readonly controlledAccount: Account,
|
23
|
+
readonly controlledAccount: Account | AnonymousJazzAgent,
|
23
24
|
readonly schema: RefEncoded<V>,
|
24
25
|
) {
|
25
26
|
if (!isRefEncoded(schema)) {
|
@@ -28,9 +29,11 @@ export class Ref<out V extends CoValue> {
|
|
28
29
|
}
|
29
30
|
|
30
31
|
get value() {
|
31
|
-
const
|
32
|
-
this.
|
33
|
-
|
32
|
+
const node =
|
33
|
+
"node" in this.controlledAccount
|
34
|
+
? this.controlledAccount.node
|
35
|
+
: this.controlledAccount._raw.core.node;
|
36
|
+
const raw = node.getLoaded(this.id as unknown as CoID<RawCoValue>);
|
34
37
|
if (raw) {
|
35
38
|
let value = refCache.get(raw);
|
36
39
|
if (value) {
|
@@ -48,7 +51,11 @@ export class Ref<out V extends CoValue> {
|
|
48
51
|
private async loadHelper(options?: {
|
49
52
|
onProgress: (p: number) => void;
|
50
53
|
}): Promise<V | "unavailable"> {
|
51
|
-
const
|
54
|
+
const node =
|
55
|
+
"node" in this.controlledAccount
|
56
|
+
? this.controlledAccount.node
|
57
|
+
: this.controlledAccount._raw.core.node;
|
58
|
+
const raw = await node.load(
|
52
59
|
this.id as unknown as CoID<RawCoValue>,
|
53
60
|
options?.onProgress,
|
54
61
|
);
|
@@ -117,7 +124,7 @@ export class Ref<out V extends CoValue> {
|
|
117
124
|
export function makeRefs<Keys extends string | number>(
|
118
125
|
getIdForKey: (key: Keys) => ID<CoValue> | undefined,
|
119
126
|
getKeysWithIds: () => Keys[],
|
120
|
-
controlledAccount: Account,
|
127
|
+
controlledAccount: Account | AnonymousJazzAgent,
|
121
128
|
refSchemaForKey: (key: Keys) => RefEncoded<CoValue>,
|
122
129
|
): { [K in Keys]: Ref<CoValue> } & {
|
123
130
|
[Symbol.iterator]: () => IterableIterator<Ref<CoValue>>;
|
@@ -88,6 +88,7 @@ function optionalRef<C extends CoValueClass>(
|
|
88
88
|
|
89
89
|
function ref<C extends CoValueClass>(
|
90
90
|
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
91
|
+
options?: never,
|
91
92
|
): co<InstanceType<C> | null>;
|
92
93
|
function ref<C extends CoValueClass>(
|
93
94
|
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|