jazz-tools 0.7.0-alpha.37 → 0.7.0-alpha.39
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +3 -10
- package/.prettierrc.js +9 -0
- package/.turbo/turbo-build.log +1 -95
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +140 -0
- package/CHANGELOG.md +19 -0
- package/README.md +10 -2
- package/dist/coValues/account.js +22 -12
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +7 -9
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +11 -3
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +15 -8
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/deepLoading.js +57 -0
- package/dist/coValues/deepLoading.js.map +1 -0
- package/dist/coValues/extensions/imageDef.js +1 -1
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +1 -0
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +34 -28
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +1 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/implementation/refs.js +4 -2
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +5 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +9 -4
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/implementation/symbols.js.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.js +2 -1
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +20 -17
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +27 -17
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +39 -24
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +188 -0
- package/dist/tests/deepLoading.test.js.map +1 -0
- package/dist/tests/groupsAndAccounts.test.js +6 -11
- package/dist/tests/groupsAndAccounts.test.js.map +1 -1
- package/package.json +12 -6
- package/src/coValues/account.ts +60 -58
- package/src/coValues/coList.ts +31 -51
- package/src/coValues/coMap.ts +27 -21
- package/src/coValues/coStream.ts +44 -32
- package/src/coValues/deepLoading.ts +215 -0
- package/src/coValues/extensions/imageDef.ts +3 -3
- package/src/coValues/group.ts +11 -13
- package/src/coValues/interfaces.ts +151 -93
- package/src/implementation/devtoolsFormatters.ts +1 -0
- package/src/implementation/inspect.ts +1 -1
- package/src/implementation/refs.ts +29 -15
- package/src/implementation/schema.ts +21 -6
- package/src/implementation/subscriptionScope.ts +33 -17
- package/src/implementation/symbols.ts +0 -1
- package/src/index.ts +5 -3
- package/src/internal.ts +3 -2
- package/src/tests/coList.test.ts +33 -28
- package/src/tests/coMap.test.ts +63 -55
- package/src/tests/coStream.test.ts +82 -67
- package/src/tests/deepLoading.test.ts +301 -0
- package/src/tests/groupsAndAccounts.test.ts +9 -18
@@ -1,2 +1,2 @@
|
|
1
1
|
export const inspect = Symbol.for("nodejs.util.inspect.custom");
|
2
|
-
export type inspect = typeof inspect;
|
2
|
+
export type inspect = typeof inspect;
|
@@ -4,8 +4,8 @@ import type {
|
|
4
4
|
Account,
|
5
5
|
CoValue,
|
6
6
|
ID,
|
7
|
-
Me,
|
8
7
|
RefEncoded,
|
8
|
+
UnCo,
|
9
9
|
UnavailableError,
|
10
10
|
} from "../internal.js";
|
11
11
|
import {
|
@@ -21,8 +21,8 @@ const TRACE_ACCESSES = false;
|
|
21
21
|
export class Ref<out V extends CoValue> {
|
22
22
|
constructor(
|
23
23
|
readonly id: ID<V>,
|
24
|
-
readonly controlledAccount: Account
|
25
|
-
readonly schema: RefEncoded<V
|
24
|
+
readonly controlledAccount: Account,
|
25
|
+
readonly schema: RefEncoded<V>,
|
26
26
|
) {
|
27
27
|
if (!isRefEncoded(schema)) {
|
28
28
|
throw new Error("Ref must be constructed with a ref schema");
|
@@ -31,7 +31,7 @@ export class Ref<out V extends CoValue> {
|
|
31
31
|
|
32
32
|
get value() {
|
33
33
|
const raw = this.controlledAccount._raw.core.node.getLoaded(
|
34
|
-
this.id as unknown as CoID<RawCoValue
|
34
|
+
this.id as unknown as CoID<RawCoValue>,
|
35
35
|
);
|
36
36
|
if (raw) {
|
37
37
|
let value = refCache.get(raw);
|
@@ -68,7 +68,7 @@ export class Ref<out V extends CoValue> {
|
|
68
68
|
}): Promise<V | "unavailable"> {
|
69
69
|
const raw = await this.controlledAccount._raw.core.node.load(
|
70
70
|
this.id as unknown as CoID<RawCoValue>,
|
71
|
-
options?.onProgress
|
71
|
+
options?.onProgress,
|
72
72
|
);
|
73
73
|
if (raw === "unavailable") {
|
74
74
|
return "unavailable";
|
@@ -88,11 +88,21 @@ export class Ref<out V extends CoValue> {
|
|
88
88
|
}
|
89
89
|
}
|
90
90
|
|
91
|
-
accessFrom(
|
91
|
+
accessFrom(
|
92
|
+
fromScopeValue: CoValue,
|
93
|
+
key: string | number | symbol,
|
94
|
+
): V | null {
|
92
95
|
const subScope = subscriptionsScopes.get(fromScopeValue);
|
93
96
|
|
94
97
|
subScope?.onRefAccessedOrSet(fromScopeValue.id, this.id);
|
95
|
-
TRACE_ACCESSES &&
|
98
|
+
TRACE_ACCESSES &&
|
99
|
+
console.log(
|
100
|
+
subScope?.scopeID,
|
101
|
+
"accessing",
|
102
|
+
fromScopeValue,
|
103
|
+
key,
|
104
|
+
this.id,
|
105
|
+
);
|
96
106
|
|
97
107
|
if (this.value && subScope) {
|
98
108
|
subscriptionsScopes.set(this.value, subScope);
|
@@ -104,13 +114,17 @@ export class Ref<out V extends CoValue> {
|
|
104
114
|
TRACE_ACCESSES && console.log("cached", cached);
|
105
115
|
return cached as V;
|
106
116
|
} else if (this.value !== null) {
|
107
|
-
const freshValueInstance = instantiateRefEncoded(
|
108
|
-
|
117
|
+
const freshValueInstance = instantiateRefEncoded(
|
118
|
+
this.schema,
|
119
|
+
this.value?._raw,
|
120
|
+
);
|
121
|
+
TRACE_ACCESSES &&
|
122
|
+
console.log("freshValueInstance", freshValueInstance);
|
109
123
|
subScope.cachedValues[this.id] = freshValueInstance;
|
110
124
|
subscriptionsScopes.set(freshValueInstance, subScope);
|
111
125
|
return freshValueInstance as V;
|
112
126
|
} else {
|
113
|
-
return null
|
127
|
+
return null;
|
114
128
|
}
|
115
129
|
} else {
|
116
130
|
return this.value;
|
@@ -121,8 +135,8 @@ export class Ref<out V extends CoValue> {
|
|
121
135
|
export function makeRefs<Keys extends string | number>(
|
122
136
|
getIdForKey: (key: Keys) => ID<CoValue> | undefined,
|
123
137
|
getKeysWithIds: () => Keys[],
|
124
|
-
controlledAccount: Account
|
125
|
-
refSchemaForKey: (key: Keys) => RefEncoded<CoValue
|
138
|
+
controlledAccount: Account,
|
139
|
+
refSchemaForKey: (key: Keys) => RefEncoded<CoValue>,
|
126
140
|
): { [K in Keys]: Ref<CoValue> } & {
|
127
141
|
[Symbol.iterator]: () => IterableIterator<Ref<CoValue>>;
|
128
142
|
length: number;
|
@@ -139,7 +153,7 @@ export function makeRefs<Keys extends string | number>(
|
|
139
153
|
yield new Ref(
|
140
154
|
getIdForKey(key)!,
|
141
155
|
controlledAccount,
|
142
|
-
refSchemaForKey(key)
|
156
|
+
refSchemaForKey(key),
|
143
157
|
);
|
144
158
|
}
|
145
159
|
};
|
@@ -153,7 +167,7 @@ export function makeRefs<Keys extends string | number>(
|
|
153
167
|
return new Ref(
|
154
168
|
id as ID<CoValue>,
|
155
169
|
controlledAccount,
|
156
|
-
refSchemaForKey(key as Keys)
|
170
|
+
refSchemaForKey(key as Keys),
|
157
171
|
);
|
158
172
|
},
|
159
173
|
ownKeys() {
|
@@ -175,5 +189,5 @@ export function makeRefs<Keys extends string | number>(
|
|
175
189
|
}
|
176
190
|
|
177
191
|
export type RefIfCoValue<V> = NonNullable<V> extends CoValue
|
178
|
-
? Ref<NonNullable<V
|
192
|
+
? Ref<UnCo<NonNullable<V>>>
|
179
193
|
: never;
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import type { JsonValue, RawCoValue } from "cojson";
|
2
|
-
import {
|
3
|
-
|
2
|
+
import {
|
3
|
+
type CoValue,
|
4
|
+
type CoValueClass,
|
5
|
+
isCoValueClass,
|
6
|
+
} from "../internal.js";
|
7
|
+
import type { Schema as EffectSchema, TypeId } from "@effect/schema/Schema";
|
4
8
|
|
5
9
|
export type CoMarker = { readonly __co: unique symbol };
|
6
10
|
/** @category Schema definition */
|
@@ -26,18 +30,24 @@ export const co = {
|
|
26
30
|
null: {
|
27
31
|
[SchemaInit]: "json" satisfies Schema,
|
28
32
|
} as unknown as co<null>,
|
29
|
-
literal: <T extends (string | number | boolean)[]>(
|
33
|
+
literal: <T extends (string | number | boolean)[]>(
|
34
|
+
..._lit: T
|
35
|
+
): co<T[number]> => {
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
30
37
|
return { [SchemaInit]: "json" satisfies Schema } as any;
|
31
38
|
},
|
32
39
|
json: <T extends JsonValue>(): co<T> => {
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
33
41
|
return { [SchemaInit]: "json" satisfies Schema } as any;
|
34
42
|
},
|
35
43
|
encoded: <T>(arg: Encoder<T>): co<T> => {
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
36
45
|
return { [SchemaInit]: { encoded: arg } satisfies Schema } as any;
|
37
46
|
},
|
38
47
|
ref: <C extends CoValueClass>(
|
39
|
-
arg: C | ((_raw: InstanceType<C>["_raw"]) => C)
|
48
|
+
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
40
49
|
): co<InstanceType<C> | null> => {
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
41
51
|
return { [SchemaInit]: arg satisfies Schema } as any;
|
42
52
|
},
|
43
53
|
items: ItemsSym as ItemsSym,
|
@@ -51,20 +61,21 @@ export type RefEncoded<V extends CoValue> =
|
|
51
61
|
| ((raw: RawCoValue) => CoValueClass<V>);
|
52
62
|
|
53
63
|
export function isRefEncoded<V extends CoValue>(
|
54
|
-
schema: Schema
|
64
|
+
schema: Schema,
|
55
65
|
): schema is RefEncoded<V> {
|
56
66
|
return typeof schema === "function";
|
57
67
|
}
|
58
68
|
|
59
69
|
export function instantiateRefEncoded<V extends CoValue>(
|
60
70
|
schema: RefEncoded<V>,
|
61
|
-
raw: RawCoValue
|
71
|
+
raw: RawCoValue,
|
62
72
|
): V {
|
63
73
|
return isCoValueClass(schema)
|
64
74
|
? schema.fromRaw(raw)
|
65
75
|
: (schema as (raw: RawCoValue) => CoValueClass<V>)(raw).fromRaw(raw);
|
66
76
|
}
|
67
77
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
68
79
|
export type Schema = JsonEncoded | RefEncoded<CoValue> | EncodedAs<any>;
|
69
80
|
|
70
81
|
export type SchemaFor<Field> = NonNullable<Field> extends CoValue
|
@@ -74,12 +85,16 @@ export type SchemaFor<Field> = NonNullable<Field> extends CoValue
|
|
74
85
|
: EncodedAs<NonNullable<Field>>;
|
75
86
|
|
76
87
|
export type EffectSchemaWithInputAndOutput<A, I = A> = EffectSchema<
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
77
89
|
any,
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
78
91
|
any,
|
79
92
|
never
|
80
93
|
> & {
|
81
94
|
[TypeId]: {
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
82
96
|
_A: (_: any) => A;
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
83
98
|
_I: (_: any) => I;
|
84
99
|
};
|
85
100
|
};
|
@@ -1,18 +1,23 @@
|
|
1
1
|
import type { RawCoValue } from "cojson";
|
2
|
-
import type {
|
2
|
+
import type {
|
3
|
+
Account,
|
4
|
+
CoValue,
|
5
|
+
CoValueBase,
|
6
|
+
ID,
|
7
|
+
ClassOf,
|
8
|
+
} from "../internal.js";
|
3
9
|
|
4
10
|
export const subscriptionsScopes = new WeakMap<
|
5
11
|
CoValue,
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
6
13
|
SubscriptionScope<any>
|
7
14
|
>();
|
8
15
|
|
9
16
|
const TRACE_INVALIDATIONS = false;
|
10
17
|
|
11
|
-
export class SubscriptionScope<
|
12
|
-
Root extends CoValue
|
13
|
-
> {
|
18
|
+
export class SubscriptionScope<Root extends CoValue> {
|
14
19
|
scopeID: string = `scope-${Math.random().toString(36).slice(2)}`;
|
15
|
-
subscriber: Account
|
20
|
+
subscriber: Account;
|
16
21
|
entries = new Map<
|
17
22
|
ID<CoValue>,
|
18
23
|
| { state: "loading"; immediatelyUnsub?: boolean }
|
@@ -25,13 +30,13 @@ export class SubscriptionScope<
|
|
25
30
|
};
|
26
31
|
onUpdate: (newRoot: Root) => void;
|
27
32
|
scheduledUpdate: boolean = false;
|
28
|
-
cachedValues: {[id: ID<CoValue>]: CoValue} = {};
|
29
|
-
parents: {[id: ID<CoValue>]: Set<ID<CoValue>>} = {};
|
33
|
+
cachedValues: { [id: ID<CoValue>]: CoValue } = {};
|
34
|
+
parents: { [id: ID<CoValue>]: Set<ID<CoValue>> } = {};
|
30
35
|
|
31
36
|
constructor(
|
32
37
|
root: Root,
|
33
38
|
rootSchema: ClassOf<Root> & typeof CoValueBase,
|
34
|
-
onUpdate: (newRoot: Root) => void
|
39
|
+
onUpdate: (newRoot: Root) => void,
|
35
40
|
) {
|
36
41
|
this.rootEntry = {
|
37
42
|
state: "loaded" as const,
|
@@ -47,13 +52,11 @@ export class SubscriptionScope<
|
|
47
52
|
this.rootEntry.rawUnsub = root._raw.core.subscribe(
|
48
53
|
(rawUpdate: RawCoValue | undefined) => {
|
49
54
|
if (!rawUpdate) return;
|
50
|
-
this.rootEntry.value = rootSchema.fromRaw(
|
51
|
-
rawUpdate
|
52
|
-
) as Root;
|
55
|
+
this.rootEntry.value = rootSchema.fromRaw(rawUpdate) as Root;
|
53
56
|
// console.log("root update", this.rootEntry.value.toJSON());
|
54
57
|
subscriptionsScopes.set(this.rootEntry.value, this);
|
55
58
|
this.scheduleUpdate();
|
56
|
-
}
|
59
|
+
},
|
57
60
|
);
|
58
61
|
}
|
59
62
|
|
@@ -67,13 +70,17 @@ export class SubscriptionScope<
|
|
67
70
|
}
|
68
71
|
}
|
69
72
|
|
70
|
-
onRefAccessedOrSet(
|
73
|
+
onRefAccessedOrSet(
|
74
|
+
fromId: ID<CoValue>,
|
75
|
+
accessedOrSetId: ID<CoValue> | undefined,
|
76
|
+
) {
|
71
77
|
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
72
78
|
if (!accessedOrSetId) {
|
73
79
|
return;
|
74
80
|
}
|
75
81
|
|
76
|
-
this.parents[accessedOrSetId] =
|
82
|
+
this.parents[accessedOrSetId] =
|
83
|
+
this.parents[accessedOrSetId] || new Set();
|
77
84
|
this.parents[accessedOrSetId]!.add(fromId);
|
78
85
|
|
79
86
|
if (!this.entries.has(accessedOrSetId)) {
|
@@ -111,11 +118,20 @@ export class SubscriptionScope<
|
|
111
118
|
}
|
112
119
|
}
|
113
120
|
|
114
|
-
invalidate(id: ID<CoValue>, fromChild?: ID<CoValue
|
115
|
-
|
121
|
+
invalidate(id: ID<CoValue>, fromChild?: ID<CoValue>, seen: Set<ID<CoValue>> = new Set()) {
|
122
|
+
if (seen.has(id)) return;
|
123
|
+
TRACE_INVALIDATIONS &&
|
124
|
+
console.log(
|
125
|
+
"invalidating",
|
126
|
+
fromChild,
|
127
|
+
"->",
|
128
|
+
id,
|
129
|
+
this.cachedValues[id],
|
130
|
+
);
|
116
131
|
delete this.cachedValues[id];
|
132
|
+
seen.add(id);
|
117
133
|
for (const parent of this.parents[id] || []) {
|
118
|
-
this.invalidate(parent, id);
|
134
|
+
this.invalidate(parent, id, seen);
|
119
135
|
}
|
120
136
|
}
|
121
137
|
|
package/src/index.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
export {
|
2
|
-
/** @category Internal types */
|
3
|
-
cojsonReady as jazzReady,
|
4
2
|
cojsonInternals,
|
5
3
|
MAX_RECOMMENDED_TX_SIZE,
|
4
|
+
WasmCrypto,
|
5
|
+
PureJSCrypto,
|
6
6
|
} from "cojson";
|
7
7
|
export type {
|
8
8
|
InviteSecret,
|
@@ -10,6 +10,7 @@ export type {
|
|
10
10
|
SessionID,
|
11
11
|
AgentID,
|
12
12
|
SyncMessage,
|
13
|
+
CryptoProvider,
|
13
14
|
} from "cojson";
|
14
15
|
|
15
16
|
export type { ID, CoValue } from "./internal.js";
|
@@ -20,6 +21,7 @@ export { CoMap } from "./internal.js";
|
|
20
21
|
export { CoList } from "./internal.js";
|
21
22
|
export { CoStream, BinaryCoStream } from "./internal.js";
|
22
23
|
export { Group, Profile } from "./internal.js";
|
23
|
-
export { Account,
|
24
|
+
export { Account, isControlledAccount } from "./internal.js";
|
24
25
|
export { ImageDefinition } from "./internal.js";
|
25
26
|
export { CoValueBase, type CoValueClass } from "./internal.js";
|
27
|
+
export type { DepthsIn, DeeplyLoaded } from "./internal.js";
|
package/src/internal.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export * from "./implementation/symbols.js";
|
2
|
-
export * from
|
2
|
+
export * from "./implementation/inspect.js";
|
3
3
|
export * from "./coValues/interfaces.js";
|
4
4
|
|
5
5
|
export * from "./coValues/coMap.js";
|
@@ -12,7 +12,8 @@ export * from "./implementation/errors.js";
|
|
12
12
|
export * from "./implementation/refs.js";
|
13
13
|
export * from "./implementation/schema.js";
|
14
14
|
export * from "./implementation/subscriptionScope.js";
|
15
|
+
export * from "./coValues/deepLoading.js";
|
15
16
|
|
16
17
|
export * from "./coValues/extensions/imageDef.js";
|
17
18
|
|
18
|
-
import "./implementation/devtoolsFormatters.js"
|
19
|
+
import "./implementation/devtoolsFormatters.js";
|
package/src/tests/coList.test.ts
CHANGED
@@ -1,23 +1,15 @@
|
|
1
|
-
import { expect, describe, test
|
2
|
-
|
3
|
-
import { webcrypto } from "node:crypto";
|
1
|
+
import { expect, describe, test } from "vitest";
|
4
2
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
5
3
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
4
|
import { Effect, Queue } from "effect";
|
7
|
-
import { Account, CoList, co,
|
8
|
-
|
9
|
-
if (!("crypto" in globalThis)) {
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
11
|
-
(globalThis as any).crypto = webcrypto;
|
12
|
-
}
|
5
|
+
import { Account, CoList, WasmCrypto, co, isControlledAccount } from "../index.js";
|
13
6
|
|
14
|
-
|
15
|
-
await jazzReady;
|
16
|
-
});
|
7
|
+
const Crypto = await WasmCrypto.create();
|
17
8
|
|
18
9
|
describe("Simple CoList operations", async () => {
|
19
10
|
const me = await Account.create({
|
20
11
|
creationProps: { name: "Hermes Puggington" },
|
12
|
+
crypto: Crypto,
|
21
13
|
});
|
22
14
|
|
23
15
|
class TestList extends CoList.Of(co.string) {}
|
@@ -127,20 +119,21 @@ describe("CoList resolution", async () => {
|
|
127
119
|
const initNodeAndList = async () => {
|
128
120
|
const me = await Account.create({
|
129
121
|
creationProps: { name: "Hermes Puggington" },
|
122
|
+
crypto: Crypto,
|
130
123
|
});
|
131
124
|
|
132
125
|
const list = TestList.create(
|
133
126
|
[
|
134
127
|
NestedList.create(
|
135
128
|
[TwiceNestedList.create(["a", "b"], { owner: me })],
|
136
|
-
{ owner: me }
|
129
|
+
{ owner: me },
|
137
130
|
),
|
138
131
|
NestedList.create(
|
139
132
|
[TwiceNestedList.create(["c", "d"], { owner: me })],
|
140
|
-
{ owner: me }
|
133
|
+
{ owner: me },
|
141
134
|
),
|
142
135
|
],
|
143
|
-
{ owner: me }
|
136
|
+
{ owner: me },
|
144
137
|
);
|
145
138
|
|
146
139
|
return { me, list };
|
@@ -161,24 +154,29 @@ describe("CoList resolution", async () => {
|
|
161
154
|
const [initialAsPeer, secondPeer] = connectedPeers(
|
162
155
|
"initial",
|
163
156
|
"second",
|
164
|
-
{ peer1role: "server", peer2role: "client" }
|
157
|
+
{ peer1role: "server", peer2role: "client" },
|
165
158
|
);
|
159
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
166
160
|
me._raw.core.node.syncManager.addPeer(secondPeer);
|
167
161
|
const meOnSecondPeer = await Account.become({
|
168
162
|
accountID: me.id,
|
169
163
|
accountSecret: me._raw.agentSecret,
|
170
164
|
peersToLoadFrom: [initialAsPeer],
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
171
166
|
sessionID: newRandomSessionID(me.id as any),
|
167
|
+
crypto: Crypto,
|
172
168
|
});
|
173
169
|
|
174
|
-
const loadedList = await TestList.load(list.id,
|
170
|
+
const loadedList = await TestList.load(list.id, meOnSecondPeer, []);
|
175
171
|
|
176
172
|
expect(loadedList?.[0]).toBe(null);
|
177
173
|
expect(loadedList?._refs[0]?.id).toEqual(list[0]!.id);
|
178
174
|
|
179
|
-
const loadedNestedList = await NestedList.load(
|
180
|
-
|
181
|
-
|
175
|
+
const loadedNestedList = await NestedList.load(
|
176
|
+
list[0]!.id,
|
177
|
+
meOnSecondPeer,
|
178
|
+
[],
|
179
|
+
);
|
182
180
|
|
183
181
|
expect(loadedList?.[0]).toBeDefined();
|
184
182
|
expect(loadedList?.[0]?.[0]).toBe(null);
|
@@ -187,7 +185,8 @@ describe("CoList resolution", async () => {
|
|
187
185
|
|
188
186
|
const loadedTwiceNestedList = await TwiceNestedList.load(
|
189
187
|
list[0]![0]!.id,
|
190
|
-
|
188
|
+
meOnSecondPeer,
|
189
|
+
[],
|
191
190
|
);
|
192
191
|
|
193
192
|
expect(loadedList?.[0]?.[0]).toBeDefined();
|
@@ -198,7 +197,7 @@ describe("CoList resolution", async () => {
|
|
198
197
|
|
199
198
|
const otherNestedList = NestedList.create(
|
200
199
|
[TwiceNestedList.create(["e", "f"], { owner: meOnSecondPeer })],
|
201
|
-
{ owner: meOnSecondPeer }
|
200
|
+
{ owner: meOnSecondPeer },
|
202
201
|
);
|
203
202
|
|
204
203
|
loadedList![0] = otherNestedList;
|
@@ -212,14 +211,17 @@ describe("CoList resolution", async () => {
|
|
212
211
|
const [initialAsPeer, secondPeer] = connectedPeers(
|
213
212
|
"initial",
|
214
213
|
"second",
|
215
|
-
{ peer1role: "server", peer2role: "client" }
|
214
|
+
{ peer1role: "server", peer2role: "client" },
|
216
215
|
);
|
216
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
217
217
|
me._raw.core.node.syncManager.addPeer(secondPeer);
|
218
218
|
const meOnSecondPeer = await Account.become({
|
219
219
|
accountID: me.id,
|
220
220
|
accountSecret: me._raw.agentSecret,
|
221
221
|
peersToLoadFrom: [initialAsPeer],
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
222
223
|
sessionID: newRandomSessionID(me.id as any),
|
224
|
+
crypto: Crypto,
|
223
225
|
});
|
224
226
|
|
225
227
|
await Effect.runPromise(
|
@@ -228,14 +230,17 @@ describe("CoList resolution", async () => {
|
|
228
230
|
|
229
231
|
TestList.subscribe(
|
230
232
|
list.id,
|
231
|
-
|
233
|
+
meOnSecondPeer,
|
234
|
+
[],
|
232
235
|
(subscribedList) => {
|
233
236
|
console.log(
|
234
237
|
"subscribedList?.[0]?.[0]?.[0]",
|
235
|
-
subscribedList?.[0]?.[0]?.[0]
|
238
|
+
subscribedList?.[0]?.[0]?.[0],
|
239
|
+
);
|
240
|
+
void Effect.runPromise(
|
241
|
+
Queue.offer(queue, subscribedList),
|
236
242
|
);
|
237
|
-
|
238
|
-
}
|
243
|
+
},
|
239
244
|
);
|
240
245
|
|
241
246
|
const update1 = yield* $(Queue.take(queue));
|
@@ -275,7 +280,7 @@ describe("CoList resolution", async () => {
|
|
275
280
|
newTwiceNestedList[0] = "w";
|
276
281
|
const update6 = yield* $(Queue.take(queue));
|
277
282
|
expect(update6?.[0]?.[0]?.[0]).toBe("w");
|
278
|
-
})
|
283
|
+
}),
|
279
284
|
);
|
280
285
|
});
|
281
286
|
});
|