jazz-tools 0.7.0-alpha.9 → 0.7.1
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 +3 -19
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +140 -0
- package/CHANGELOG.md +298 -0
- package/README.md +10 -2
- package/dist/coValues/account.js +59 -41
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +49 -46
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +143 -44
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +144 -35
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/deepLoading.js +60 -0
- package/dist/coValues/deepLoading.js.map +1 -0
- package/dist/coValues/extensions/imageDef.js +10 -7
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +49 -13
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +70 -31
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +114 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -0
- package/dist/implementation/refs.js +58 -18
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +58 -0
- package/dist/implementation/schema.js.map +1 -0
- package/dist/implementation/subscriptionScope.js +19 -1
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/implementation/symbols.js +5 -0
- package/dist/implementation/symbols.js.map +1 -0
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.js +5 -2
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +51 -48
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +131 -74
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +56 -41
- 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 +83 -0
- package/dist/tests/groupsAndAccounts.test.js.map +1 -0
- package/package.json +17 -9
- package/src/coValues/account.ts +113 -125
- package/src/coValues/coList.ts +87 -103
- package/src/coValues/coMap.ts +200 -147
- package/src/coValues/coStream.ts +264 -80
- package/src/coValues/deepLoading.ts +229 -0
- package/src/coValues/extensions/imageDef.ts +17 -13
- package/src/coValues/group.ts +92 -58
- package/src/coValues/interfaces.ts +215 -115
- package/src/implementation/devtoolsFormatters.ts +110 -0
- package/src/implementation/inspect.ts +1 -1
- package/src/implementation/refs.ts +80 -28
- package/src/implementation/schema.ts +138 -0
- package/src/implementation/subscriptionScope.ts +48 -12
- package/src/implementation/symbols.ts +11 -0
- package/src/index.ts +12 -8
- package/src/internal.ts +7 -3
- package/src/tests/coList.test.ts +77 -62
- package/src/tests/coMap.test.ts +201 -114
- package/src/tests/coStream.test.ts +113 -84
- package/src/tests/deepLoading.test.ts +301 -0
- package/src/tests/groupsAndAccounts.test.ts +91 -0
- package/dist/implementation/encoding.js +0 -26
- package/dist/implementation/encoding.js.map +0 -1
- package/src/implementation/encoding.ts +0 -105
@@ -1,53 +1,83 @@
|
|
1
|
-
import { Effect, Sink, Stream } from "effect";
|
1
|
+
import { Effect, Option, Sink, Stream } from "effect";
|
2
2
|
import { RawAccount } from "cojson";
|
3
|
-
import { Account, AccountCtx, Group, SubscriptionScope, Ref, inspect, } from "../internal.js";
|
3
|
+
import { Account, AccountCtx, Group, SubscriptionScope, Ref, inspect, subscriptionsScopes, } from "../internal.js";
|
4
|
+
import { fulfillsDepth } from "./deepLoading.js";
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
4
6
|
export function isCoValue(value) {
|
5
7
|
return value && value._type !== undefined;
|
6
8
|
}
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
|
+
export function isCoValueClass(value) {
|
11
|
+
return typeof value === "function" && value.fromRaw !== undefined;
|
12
|
+
}
|
13
|
+
/** @internal */
|
7
14
|
export class CoValueBase {
|
8
15
|
get _owner() {
|
9
|
-
|
16
|
+
const owner = this._raw.group instanceof RawAccount
|
10
17
|
? Account.fromRaw(this._raw.group)
|
11
18
|
: Group.fromRaw(this._raw.group);
|
19
|
+
const subScope = subscriptionsScopes.get(this);
|
20
|
+
if (subScope) {
|
21
|
+
subScope.onRefAccessedOrSet(this.id, owner.id);
|
22
|
+
subscriptionsScopes.set(owner, subScope);
|
23
|
+
}
|
24
|
+
return owner;
|
12
25
|
}
|
26
|
+
/** @private */
|
13
27
|
get _loadedAs() {
|
14
28
|
return Account.fromNode(this._raw.core.node);
|
15
29
|
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
return Effect.gen(this, function* (_) {
|
22
|
-
const account = yield* _(AccountCtx);
|
23
|
-
return yield* _(new Ref(id, account, {
|
24
|
-
ref: () => this,
|
25
|
-
}).loadEf());
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
31
|
+
constructor(..._args) {
|
32
|
+
Object.defineProperty(this, "_instanceID", {
|
33
|
+
value: `instance-${Math.random().toString(36).slice(2)}`,
|
34
|
+
enumerable: false,
|
26
35
|
});
|
27
36
|
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}).load(options?.onProgress && { onProgress: options.onProgress });
|
37
|
+
/** @category Internals */
|
38
|
+
static fromRaw(raw) {
|
39
|
+
return new this({ fromRaw: raw });
|
32
40
|
}
|
33
|
-
static
|
34
|
-
|
35
|
-
|
41
|
+
static load(...args) {
|
42
|
+
const { id, as, depth } = args.length === 3
|
43
|
+
? { id: args[0], as: args[1], depth: args[2] }
|
44
|
+
: { id: args[0].id, as: args[0]._loadedAs, depth: args[1] };
|
45
|
+
return Effect.runPromise(this.loadEf(id, depth).pipe(Effect.mapError(() => undefined), Effect.merge, Effect.provideService(AccountCtx, as)));
|
36
46
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
void emit.single(update);
|
41
|
-
});
|
42
|
-
yield* _(Effect.addFinalizer(() => Effect.sync(() => subscription.unsubscribeAll())));
|
43
|
-
}))));
|
47
|
+
/** @category Subscription & Loading */
|
48
|
+
static loadEf(id, depth) {
|
49
|
+
return this.subscribeEf(id, depth).pipe(Stream.runHead, Effect.andThen(Effect.mapError((_noSuchElem) => "unavailable")));
|
44
50
|
}
|
45
|
-
subscribe(
|
46
|
-
|
51
|
+
static subscribe(...args) {
|
52
|
+
const { id, as, depth, listener } = args.length === 4
|
53
|
+
? {
|
54
|
+
id: args[0],
|
55
|
+
as: args[1],
|
56
|
+
depth: args[2],
|
57
|
+
listener: args[3],
|
58
|
+
}
|
59
|
+
: {
|
60
|
+
id: args[0].id,
|
61
|
+
as: args[0]._loadedAs,
|
62
|
+
depth: args[1],
|
63
|
+
listener: args[2],
|
64
|
+
};
|
65
|
+
void Effect.runPromise(Effect.provideService(this.subscribeEf(id, depth).pipe(Stream.run(Sink.forEach((update) => Effect.sync(() => listener(update))))), AccountCtx, as));
|
66
|
+
return function unsubscribe() { };
|
47
67
|
}
|
48
|
-
|
49
|
-
|
68
|
+
/** @category Subscription & Loading */
|
69
|
+
static subscribeEf(id, depth) {
|
70
|
+
return AccountCtx.pipe(Effect.andThen((account) => new Ref(id, account, {
|
71
|
+
ref: this,
|
72
|
+
optional: false,
|
73
|
+
}).loadEf()), Stream.fromEffect, Stream.flatMap((value) => Stream.asyncScoped((emit) => Effect.gen(this, function* (_) {
|
74
|
+
const subscription = new SubscriptionScope(value, this, (update) => void emit.single(update));
|
75
|
+
yield* _(Effect.addFinalizer(() => Effect.sync(() => subscription.unsubscribeAll())));
|
76
|
+
}))), Stream.filterMap((update) => Option.fromNullable(fulfillsDepth(depth, update)
|
77
|
+
? update
|
78
|
+
: undefined)));
|
50
79
|
}
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
51
81
|
toJSON() {
|
52
82
|
return {
|
53
83
|
id: this.id,
|
@@ -58,5 +88,14 @@ export class CoValueBase {
|
|
58
88
|
[inspect]() {
|
59
89
|
return this.toJSON();
|
60
90
|
}
|
91
|
+
/** @category Type Helpers*/
|
92
|
+
as(otherSchema) {
|
93
|
+
const cast = otherSchema.fromRaw(this._raw);
|
94
|
+
const subScope = subscriptionsScopes.get(this);
|
95
|
+
if (subScope) {
|
96
|
+
subscriptionsScopes.set(cast, subScope);
|
97
|
+
}
|
98
|
+
return cast;
|
99
|
+
}
|
61
100
|
}
|
62
101
|
//# sourceMappingURL=interfaces.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/coValues/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/coValues/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACH,OAAO,EACP,UAAU,EACV,KAAK,EACL,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAgFjD,8DAA8D;AAC9D,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,OAAO,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AAC9C,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,cAAc,CAAC,KAAU;IACrC,OAAO,OAAO,KAAK,KAAK,UAAU,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC;AACtE,CAAC;AAOD,gBAAgB;AAChB,MAAM,OAAO,WAAW;IAMpB,IAAI,MAAM;QACN,MAAM,KAAK,GACP,I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CAAC,GAAG,EAAE,CACrB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CACb,YAAY,CAAC,cAAc,EAAE,CAChC,CACJ,CACJ,CAAC;QACN,CAAC,CAAC,CACL,CACJ,EACD,MAAM,CAAC,SAAS,CAAC,CAAC,MAAS,EAAE,EAAE,CAC3B,MAAM,CAAC,YAAY,CACf,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;YACxB,CAAC,CAAE,MAAiC;YACpC,CAAC,CAAC,SAAS,CAClB,CACJ,CACJ,CAAC;IACN,CAAC;IAED,8DAA8D;IAC9D,MAAM;QACF,OAAO;YACH,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,uBAAuB;SACjC,CAAC;IACN,CAAC;IAED,CAAC,OAAO,CAAC;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;IAED,4BAA4B;IAC5B,EAAE,CAAyB,WAAc;QACrC,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAoB,CAAC;QAC/D,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,QAAQ,EAAE,CAAC;YACX,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
@@ -0,0 +1,114 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
import { ItemsSym } from "./symbols.js";
|
3
|
+
globalThis.devtoolsFormatters = [
|
4
|
+
{
|
5
|
+
header: (object) => {
|
6
|
+
if (object._type === "CoMap") {
|
7
|
+
return ["div", {}, ["span", {}, object.constructor.name]];
|
8
|
+
}
|
9
|
+
else if (object._type === "CoList") {
|
10
|
+
return [
|
11
|
+
"div",
|
12
|
+
{},
|
13
|
+
[
|
14
|
+
"span",
|
15
|
+
{},
|
16
|
+
object.constructor.name + "(" + object.length + ") ",
|
17
|
+
],
|
18
|
+
];
|
19
|
+
}
|
20
|
+
else if (object._type === "Account") {
|
21
|
+
return [
|
22
|
+
"div",
|
23
|
+
{},
|
24
|
+
[
|
25
|
+
"span",
|
26
|
+
{},
|
27
|
+
object.constructor.name +
|
28
|
+
"(" +
|
29
|
+
object._refs.profile.value?.name +
|
30
|
+
(object.isMe ? " ME" : "") +
|
31
|
+
")",
|
32
|
+
],
|
33
|
+
];
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
},
|
39
|
+
hasBody: function () {
|
40
|
+
return true;
|
41
|
+
},
|
42
|
+
body: function (object) {
|
43
|
+
if (object._type === "CoMap" || object._type === "Account") {
|
44
|
+
return [
|
45
|
+
"div",
|
46
|
+
{ style: "margin-left: 15px" },
|
47
|
+
["div", "id: ", ["object", { object: object.id }]],
|
48
|
+
...Object.entries(object).map(([k, v]) => [
|
49
|
+
"div",
|
50
|
+
{ style: "white-space: nowrap;" },
|
51
|
+
[
|
52
|
+
"span",
|
53
|
+
{ style: "font-weight: bold; opacity: 0.6" },
|
54
|
+
k,
|
55
|
+
": ",
|
56
|
+
],
|
57
|
+
["object", { object: v }],
|
58
|
+
...(typeof object._schema[k] === "function"
|
59
|
+
? v === null
|
60
|
+
? [
|
61
|
+
[
|
62
|
+
"span",
|
63
|
+
{ style: "opacity: 0.5" },
|
64
|
+
` (pending ${object._schema[k].name} `,
|
65
|
+
[
|
66
|
+
"object",
|
67
|
+
{ object: object._refs[k] },
|
68
|
+
],
|
69
|
+
")",
|
70
|
+
],
|
71
|
+
]
|
72
|
+
: []
|
73
|
+
: []),
|
74
|
+
]),
|
75
|
+
];
|
76
|
+
}
|
77
|
+
else if (object._type === "CoList") {
|
78
|
+
return [
|
79
|
+
"div",
|
80
|
+
{ style: "margin-left: 15px" },
|
81
|
+
["div", "id: ", ["object", { object: object.id }]],
|
82
|
+
...object.map((v, i) => [
|
83
|
+
"div",
|
84
|
+
{ style: "white-space: nowrap;" },
|
85
|
+
[
|
86
|
+
"span",
|
87
|
+
{ style: "font-weight: bold; opacity: 0.6" },
|
88
|
+
i,
|
89
|
+
": ",
|
90
|
+
],
|
91
|
+
["object", { object: v }],
|
92
|
+
...(typeof object._schema[ItemsSym] === "function"
|
93
|
+
? v === null
|
94
|
+
? [
|
95
|
+
[
|
96
|
+
"span",
|
97
|
+
{ style: "opacity: 0.5" },
|
98
|
+
` (pending ${object._schema[ItemsSym].name} `,
|
99
|
+
[
|
100
|
+
"object",
|
101
|
+
{ object: object._refs[i] },
|
102
|
+
],
|
103
|
+
")",
|
104
|
+
],
|
105
|
+
]
|
106
|
+
: []
|
107
|
+
: []),
|
108
|
+
]),
|
109
|
+
];
|
110
|
+
}
|
111
|
+
},
|
112
|
+
},
|
113
|
+
];
|
114
|
+
//# sourceMappingURL=devtoolsFormatters.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"devtoolsFormatters.js","sourceRoot":"","sources":["../../src/implementation/devtoolsFormatters.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvC,UAAkB,CAAC,kBAAkB,GAAG;IACrC;QACI,MAAM,EAAE,CAAC,MAAW,EAAE,EAAE;YACpB,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;gBAC3B,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACnC,OAAO;oBACH,KAAK;oBACL,EAAE;oBACF;wBACI,MAAM;wBACN,EAAE;wBACF,MAAM,CAAC,WAAW,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC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;yCAC9B;wCACD,GAAG;qCACN;iCACJ;gCACH,CAAC,CAAC,EAAE;4BACR,CAAC,CAAC,EAAE,CAAC;qBACZ,CAAC;iBACL,CAAC;YACN,CAAC;QACL,CAAC;KACJ;CACJ,CAAC"}
|
@@ -1,22 +1,27 @@
|
|
1
1
|
import { Effect } from "effect";
|
2
|
-
import { subscriptionsScopes } from "../internal.js";
|
2
|
+
import { instantiateRefEncoded, isRefEncoded, subscriptionsScopes, } from "../internal.js";
|
3
|
+
const refCache = new WeakMap();
|
4
|
+
const TRACE_ACCESSES = false;
|
3
5
|
export class Ref {
|
4
|
-
constructor(id, controlledAccount,
|
6
|
+
constructor(id, controlledAccount, schema) {
|
5
7
|
this.id = id;
|
6
8
|
this.controlledAccount = controlledAccount;
|
7
|
-
this.
|
8
|
-
if (!(
|
9
|
-
throw new Error("Ref must be constructed with a ref
|
9
|
+
this.schema = schema;
|
10
|
+
if (!isRefEncoded(schema)) {
|
11
|
+
throw new Error("Ref must be constructed with a ref schema");
|
10
12
|
}
|
11
13
|
}
|
12
14
|
get value() {
|
13
|
-
if (this.cachedValue)
|
14
|
-
return this.cachedValue;
|
15
|
-
// TODO: cache it for object identity!!!
|
16
15
|
const raw = this.controlledAccount._raw.core.node.getLoaded(this.id);
|
17
16
|
if (raw) {
|
18
|
-
|
19
|
-
|
17
|
+
let value = refCache.get(raw);
|
18
|
+
if (value) {
|
19
|
+
// console.log("Using cached value for " + this.id);
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
value = instantiateRefEncoded(this.schema, raw);
|
23
|
+
refCache.set(raw, value);
|
24
|
+
}
|
20
25
|
return value;
|
21
26
|
}
|
22
27
|
else {
|
@@ -45,7 +50,7 @@ export class Ref {
|
|
45
50
|
return "unavailable";
|
46
51
|
}
|
47
52
|
else {
|
48
|
-
return new Ref(this.id, this.controlledAccount, this.
|
53
|
+
return new Ref(this.id, this.controlledAccount, this.schema).value;
|
49
54
|
}
|
50
55
|
}
|
51
56
|
async load(options) {
|
@@ -57,23 +62,45 @@ export class Ref {
|
|
57
62
|
return result;
|
58
63
|
}
|
59
64
|
}
|
60
|
-
accessFrom(fromScopeValue) {
|
65
|
+
accessFrom(fromScopeValue, key) {
|
61
66
|
const subScope = subscriptionsScopes.get(fromScopeValue);
|
62
|
-
subScope?.onRefAccessedOrSet(this.id);
|
67
|
+
subScope?.onRefAccessedOrSet(fromScopeValue.id, this.id);
|
68
|
+
TRACE_ACCESSES &&
|
69
|
+
console.log(subScope?.scopeID, "accessing", fromScopeValue, key, this.id);
|
63
70
|
if (this.value && subScope) {
|
64
71
|
subscriptionsScopes.set(this.value, subScope);
|
65
72
|
}
|
66
|
-
|
73
|
+
if (subScope) {
|
74
|
+
const cached = subScope.cachedValues[this.id];
|
75
|
+
if (cached) {
|
76
|
+
TRACE_ACCESSES && console.log("cached", cached);
|
77
|
+
return cached;
|
78
|
+
}
|
79
|
+
else if (this.value !== null) {
|
80
|
+
const freshValueInstance = instantiateRefEncoded(this.schema, this.value?._raw);
|
81
|
+
TRACE_ACCESSES &&
|
82
|
+
console.log("freshValueInstance", freshValueInstance);
|
83
|
+
subScope.cachedValues[this.id] = freshValueInstance;
|
84
|
+
subscriptionsScopes.set(freshValueInstance, subScope);
|
85
|
+
return freshValueInstance;
|
86
|
+
}
|
87
|
+
else {
|
88
|
+
return null;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
return this.value;
|
93
|
+
}
|
67
94
|
}
|
68
95
|
}
|
69
|
-
export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount,
|
96
|
+
export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, refSchemaForKey) {
|
70
97
|
const refs = {};
|
71
98
|
return new Proxy(refs, {
|
72
|
-
get(
|
99
|
+
get(_target, key) {
|
73
100
|
if (key === Symbol.iterator) {
|
74
101
|
return function* () {
|
75
102
|
for (const key of getKeysWithIds()) {
|
76
|
-
yield new Ref(getIdForKey(key), controlledAccount,
|
103
|
+
yield new Ref(getIdForKey(key), controlledAccount, refSchemaForKey(key));
|
77
104
|
}
|
78
105
|
};
|
79
106
|
}
|
@@ -85,11 +112,24 @@ export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, refEnco
|
|
85
112
|
const id = getIdForKey(key);
|
86
113
|
if (!id)
|
87
114
|
return undefined;
|
88
|
-
return new Ref(id, controlledAccount,
|
115
|
+
return new Ref(id, controlledAccount, refSchemaForKey(key));
|
89
116
|
},
|
90
117
|
ownKeys() {
|
91
118
|
return getKeysWithIds().map((key) => key.toString());
|
92
119
|
},
|
120
|
+
getOwnPropertyDescriptor(target, key) {
|
121
|
+
const id = getIdForKey(key);
|
122
|
+
if (id) {
|
123
|
+
return {
|
124
|
+
enumerable: true,
|
125
|
+
configurable: true,
|
126
|
+
writable: true,
|
127
|
+
};
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
131
|
+
}
|
132
|
+
},
|
93
133
|
});
|
94
134
|
}
|
95
135
|
//# sourceMappingURL=refs.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUhC,OAAO,
|
1
|
+
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUhC,OAAO,EACH,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAuB,CAAC;AAEpD,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,OAAO,GAAG;IACZ,YACa,EAAS,EACT,iBAA0B,EAC1B,MAAqB;QAFrB,OAAE,GAAF,EAAE,CAAO;QACT,sBAAiB,GAAjB,iBAAiB,CAAS;QAC1B,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CAAC;YACD,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAC;YAC9C,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACnB,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC;YACnC,CAAC;YACD,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,CAAC,EAAE;gBAAE,OAAO,SAAS,CAAC;YAC1B,OAAO,IAAI,GAAG,CACV,EAAiB,EACjB,iBAAiB,EACjB,eAAe,CAAC,GAAW,CAAC,CAC/B,CAAC;QACN,CAAC;QACD,OAAO;YACH,OAAO,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,wBAAwB,CAAC,MAAM,EAAE,GAAG;YAChC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,EAAE,EAAE,CAAC;gBACL,OAAO;oBACH,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,IAAI;oBAClB,QAAQ,EAAE,IAAI;iBACjB,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { isCoValueClass, } from "../internal.js";
|
2
|
+
/** @category Schema definition */
|
3
|
+
export const co = {
|
4
|
+
string: {
|
5
|
+
[SchemaInit]: "json",
|
6
|
+
},
|
7
|
+
number: {
|
8
|
+
[SchemaInit]: "json",
|
9
|
+
},
|
10
|
+
boolean: {
|
11
|
+
[SchemaInit]: "json",
|
12
|
+
},
|
13
|
+
null: {
|
14
|
+
[SchemaInit]: "json",
|
15
|
+
},
|
16
|
+
literal(..._lit) {
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
18
|
+
return { [SchemaInit]: "json" };
|
19
|
+
},
|
20
|
+
json() {
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
22
|
+
return { [SchemaInit]: "json" };
|
23
|
+
},
|
24
|
+
encoded(arg) {
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
26
|
+
return { [SchemaInit]: { encoded: arg } };
|
27
|
+
},
|
28
|
+
ref,
|
29
|
+
items: ItemsSym,
|
30
|
+
members: MembersSym,
|
31
|
+
};
|
32
|
+
function ref(arg, options) {
|
33
|
+
return {
|
34
|
+
[SchemaInit]: {
|
35
|
+
ref: arg,
|
36
|
+
optional: options?.optional || false,
|
37
|
+
},
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
39
|
+
};
|
40
|
+
}
|
41
|
+
export function isRefEncoded(schema) {
|
42
|
+
return (typeof schema === "object" &&
|
43
|
+
"ref" in schema &&
|
44
|
+
"optional" in schema &&
|
45
|
+
typeof schema.ref === "function");
|
46
|
+
}
|
47
|
+
export function instantiateRefEncoded(schema, raw) {
|
48
|
+
return isCoValueClass(schema.ref)
|
49
|
+
? schema.ref.fromRaw(raw)
|
50
|
+
: schema.ref(raw).fromRaw(raw);
|
51
|
+
}
|
52
|
+
import { Date } from "@effect/schema/Schema";
|
53
|
+
import { SchemaInit, ItemsSym, MembersSym } from "./symbols.js";
|
54
|
+
/** @category Schema definition */
|
55
|
+
export const Encoders = {
|
56
|
+
Date,
|
57
|
+
};
|
58
|
+
//# sourceMappingURL=schema.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/implementation/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,cAAc,GACjB,MAAM,gBAAgB,CAAC;AAaxB,kCAAkC;AAClC,MAAM,CAAC,MAAM,EAAE,GAAG;IACd,MAAM,EAAE;QACJ,CAAC,UAAU,CAAC,EAAE,MAAuB;KACf;IAC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O,CAC7D,GAAG,CACN,CAAC;AACZ,CAAC;AA4BD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEhE,kCAAkC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,IAAI;CACP,CAAC"}
|
@@ -1,9 +1,12 @@
|
|
1
1
|
export const subscriptionsScopes = new WeakMap();
|
2
|
+
const TRACE_INVALIDATIONS = false;
|
2
3
|
export class SubscriptionScope {
|
3
4
|
constructor(root, rootSchema, onUpdate) {
|
4
5
|
this.scopeID = `scope-${Math.random().toString(36).slice(2)}`;
|
5
6
|
this.entries = new Map();
|
6
7
|
this.scheduledUpdate = false;
|
8
|
+
this.cachedValues = {};
|
9
|
+
this.parents = {};
|
7
10
|
this.rootEntry = {
|
8
11
|
state: "loaded",
|
9
12
|
value: root,
|
@@ -31,11 +34,14 @@ export class SubscriptionScope {
|
|
31
34
|
});
|
32
35
|
}
|
33
36
|
}
|
34
|
-
onRefAccessedOrSet(accessedOrSetId) {
|
37
|
+
onRefAccessedOrSet(fromId, accessedOrSetId) {
|
35
38
|
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
36
39
|
if (!accessedOrSetId) {
|
37
40
|
return;
|
38
41
|
}
|
42
|
+
this.parents[accessedOrSetId] =
|
43
|
+
this.parents[accessedOrSetId] || new Set();
|
44
|
+
this.parents[accessedOrSetId].add(fromId);
|
39
45
|
if (!this.entries.has(accessedOrSetId)) {
|
40
46
|
const loadingEntry = {
|
41
47
|
state: "loading",
|
@@ -59,6 +65,7 @@ export class SubscriptionScope {
|
|
59
65
|
// console.log("ref update", this.scopeID, accessedOrSetId, JSON.stringify(rawUpdate))
|
60
66
|
if (!rawUpdate)
|
61
67
|
return;
|
68
|
+
this.invalidate(accessedOrSetId);
|
62
69
|
this.scheduleUpdate();
|
63
70
|
});
|
64
71
|
entry.rawUnsub = rawUnsub;
|
@@ -66,6 +73,17 @@ export class SubscriptionScope {
|
|
66
73
|
});
|
67
74
|
}
|
68
75
|
}
|
76
|
+
invalidate(id, fromChild, seen = new Set()) {
|
77
|
+
if (seen.has(id))
|
78
|
+
return;
|
79
|
+
TRACE_INVALIDATIONS &&
|
80
|
+
console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
|
81
|
+
delete this.cachedValues[id];
|
82
|
+
seen.add(id);
|
83
|
+
for (const parent of this.parents[id] || []) {
|
84
|
+
this.invalidate(parent, id, seen);
|
85
|
+
}
|
86
|
+
}
|
69
87
|
unsubscribeAll() {
|
70
88
|
for (const entry of this.entries.values()) {
|
71
89
|
if (entry.state === "loaded") {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"subscriptionScope.js","sourceRoot":"","sources":["../../src/implementation/subscriptionScope.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"subscriptionScope.js","sourceRoot":"","sources":["../../src/implementation/subscriptionScope.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAI3C,CAAC;AAEJ,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,MAAM,OAAO,iBAAiB;IAkB1B,YACI,IAAU,EACV,UAA8C,EAC9C,QAAiC;QApBrC,YAAO,GAAW,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAEjE,YAAO,GAAG,IAAI,GAAG,EAId,CAAC;QAOJ,oBAAe,GAAY,KAAK,CAAC;QACjC,iBAAY,GAAmC,EAAE,CAAC;QAClD,YAAO,GAA4C,EAAE,CAAC;QAOlD,IAAI,CAAC,SAAS,GAAG;YACb,KAAK,EAAE,QAAiB;YACxB,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,cAAc;SACrC,CAAC;QACF,IAAI,CAA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AAmB;YACf,OAAO,CAAC,GAAG,CACP,cAAc,EACd,SAAS,EACT,IAAI,EACJ,EAAE,EACF,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CACxB,CAAC;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACb,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC;IACL,CAAC;IAED,cAAc;QACV,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,IAAI,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC3B,KAAK,CAAC,QAAQ,EAAE,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAClC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACJ"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/implementation/symbols.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAGnD,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAGnD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAG5C,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
export {
|
2
|
-
|
3
|
-
cojsonReady as jazzReady, cojsonInternals, MAX_RECOMMENDED_TX_SIZE, } from "cojson";
|
4
|
-
export { Encoders, val } from "./internal.js";
|
1
|
+
export { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto, PureJSCrypto, } from "cojson";
|
2
|
+
export { Encoders, co } from "./internal.js";
|
5
3
|
export { CoMap } from "./internal.js";
|
6
4
|
export { CoList } from "./internal.js";
|
7
5
|
export { CoStream, BinaryCoStream } from "./internal.js";
|
8
6
|
export { Group, Profile } from "./internal.js";
|
9
|
-
export { Account } from "./internal.js";
|
7
|
+
export { Account, isControlledAccount } from "./internal.js";
|
10
8
|
export { ImageDefinition } from "./internal.js";
|
11
9
|
export { CoValueBase } from "./internal.js";
|
12
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,YAAY,GACf,MAAM,QAAQ,CAAC;AAYhB,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAqB,MAAM,eAAe,CAAC"}
|
package/dist/internal.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
export * from
|
1
|
+
export * from "./implementation/symbols.js";
|
2
|
+
export * from "./implementation/inspect.js";
|
2
3
|
export * from "./coValues/interfaces.js";
|
3
4
|
export * from "./coValues/coMap.js";
|
4
5
|
export * from "./coValues/account.js";
|
@@ -7,7 +8,9 @@ export * from "./coValues/coStream.js";
|
|
7
8
|
export * from "./coValues/group.js";
|
8
9
|
export * from "./implementation/errors.js";
|
9
10
|
export * from "./implementation/refs.js";
|
10
|
-
export * from "./implementation/
|
11
|
+
export * from "./implementation/schema.js";
|
11
12
|
export * from "./implementation/subscriptionScope.js";
|
13
|
+
export * from "./coValues/deepLoading.js";
|
12
14
|
export * from "./coValues/extensions/imageDef.js";
|
15
|
+
import "./implementation/devtoolsFormatters.js";
|
13
16
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uCAAuC,CAAC;AACtD,cAAc,2BAA2B,CAAC;AAE1C,cAAc,mCAAmC,CAAC;AAElD,OAAO,wCAAwC,CAAC"}
|