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
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/implementation/errors.ts"],"names":[],"mappings":""}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../../src/implementation/inspect.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC"}
|
@@ -1,115 +0,0 @@
|
|
1
|
-
import { instantiateRefEncoded, isRefEncoded, subscriptionsScopes, } from "../internal.js";
|
2
|
-
import { coValuesCache } from "../lib/cache.js";
|
3
|
-
const TRACE_ACCESSES = false;
|
4
|
-
export class Ref {
|
5
|
-
constructor(id, controlledAccount, schema) {
|
6
|
-
this.id = id;
|
7
|
-
this.controlledAccount = controlledAccount;
|
8
|
-
this.schema = schema;
|
9
|
-
if (!isRefEncoded(schema)) {
|
10
|
-
throw new Error("Ref must be constructed with a ref schema");
|
11
|
-
}
|
12
|
-
}
|
13
|
-
get value() {
|
14
|
-
const node = "node" in this.controlledAccount
|
15
|
-
? this.controlledAccount.node
|
16
|
-
: this.controlledAccount._raw.core.node;
|
17
|
-
const raw = node.getLoaded(this.id);
|
18
|
-
if (raw) {
|
19
|
-
return coValuesCache.get(raw, () => instantiateRefEncoded(this.schema, raw));
|
20
|
-
}
|
21
|
-
else {
|
22
|
-
return null;
|
23
|
-
}
|
24
|
-
}
|
25
|
-
async loadHelper() {
|
26
|
-
const node = "node" in this.controlledAccount
|
27
|
-
? this.controlledAccount.node
|
28
|
-
: this.controlledAccount._raw.core.node;
|
29
|
-
const raw = await node.load(this.id);
|
30
|
-
if (raw === "unavailable") {
|
31
|
-
return "unavailable";
|
32
|
-
}
|
33
|
-
else {
|
34
|
-
return new Ref(this.id, this.controlledAccount, this.schema).value;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
async load() {
|
38
|
-
const result = await this.loadHelper();
|
39
|
-
if (result === "unavailable") {
|
40
|
-
return undefined;
|
41
|
-
}
|
42
|
-
else {
|
43
|
-
return result;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
accessFrom(fromScopeValue, key) {
|
47
|
-
const subScope = subscriptionsScopes.get(fromScopeValue);
|
48
|
-
subScope?.onRefAccessedOrSet(fromScopeValue.id, this.id);
|
49
|
-
TRACE_ACCESSES &&
|
50
|
-
console.log(subScope?.scopeID, "accessing", fromScopeValue, key, this.id);
|
51
|
-
if (this.value && subScope) {
|
52
|
-
subscriptionsScopes.set(this.value, subScope);
|
53
|
-
}
|
54
|
-
if (subScope) {
|
55
|
-
const cached = subScope.cachedValues[this.id];
|
56
|
-
if (cached) {
|
57
|
-
TRACE_ACCESSES && console.log("cached", cached);
|
58
|
-
return cached;
|
59
|
-
}
|
60
|
-
else if (this.value !== null) {
|
61
|
-
const freshValueInstance = instantiateRefEncoded(this.schema, this.value?._raw);
|
62
|
-
TRACE_ACCESSES && console.log("freshValueInstance", freshValueInstance);
|
63
|
-
subScope.cachedValues[this.id] = freshValueInstance;
|
64
|
-
subscriptionsScopes.set(freshValueInstance, subScope);
|
65
|
-
return freshValueInstance;
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
return null;
|
69
|
-
}
|
70
|
-
}
|
71
|
-
else {
|
72
|
-
return this.value;
|
73
|
-
}
|
74
|
-
}
|
75
|
-
}
|
76
|
-
export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, refSchemaForKey) {
|
77
|
-
const refs = {};
|
78
|
-
return new Proxy(refs, {
|
79
|
-
get(_target, key) {
|
80
|
-
if (key === Symbol.iterator) {
|
81
|
-
return function* () {
|
82
|
-
for (const key of getKeysWithIds()) {
|
83
|
-
yield new Ref(getIdForKey(key), controlledAccount, refSchemaForKey(key));
|
84
|
-
}
|
85
|
-
};
|
86
|
-
}
|
87
|
-
if (typeof key === "symbol")
|
88
|
-
return undefined;
|
89
|
-
if (key === "length") {
|
90
|
-
return getKeysWithIds().length;
|
91
|
-
}
|
92
|
-
const id = getIdForKey(key);
|
93
|
-
if (!id)
|
94
|
-
return undefined;
|
95
|
-
return new Ref(id, controlledAccount, refSchemaForKey(key));
|
96
|
-
},
|
97
|
-
ownKeys() {
|
98
|
-
return getKeysWithIds().map((key) => key.toString());
|
99
|
-
},
|
100
|
-
getOwnPropertyDescriptor(target, key) {
|
101
|
-
const id = getIdForKey(key);
|
102
|
-
if (id) {
|
103
|
-
return {
|
104
|
-
enumerable: true,
|
105
|
-
configurable: true,
|
106
|
-
writable: true,
|
107
|
-
};
|
108
|
-
}
|
109
|
-
else {
|
110
|
-
return Reflect.getOwnPropertyDescriptor(target, key);
|
111
|
-
}
|
112
|
-
},
|
113
|
-
});
|
114
|
-
}
|
115
|
-
//# sourceMappingURL=refs.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../../src/implementation/refs.ts"],"names":[],"mappings":"AASA,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,OAAO,GAAG;IACd,YACW,EAAS,EACT,iBAA+C,EAC/C,MAAqB;QAFrB,OAAE,GAAF,EAAE,CAAO;QACT,sBAAiB,GAAjB,iBAAiB,CAA8B;QAC/C,WAAM,GAAN,MAAM,CAAe;QAE9B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,IAAI,KAAK;QACP,MAAM,IAAI,GACR,MAAM,IAAI,IAAI,CAAC,iBAAiB;YAC9B,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI;YAC7B,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAiC,CAAC,CAAC;QACnE,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CACjC,qBAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,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M,IAAI,GAAG,CACX,WAAW,CAAC,GAAG,CAAE,EACjB,iBAAiB,EACjB,eAAe,CAAC,GAAG,CAAC,CACrB,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC;YACJ,CAAC;YACD,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAC;YAC9C,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACrB,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC;YACjC,CAAC;YACD,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,CAAC,EAAE;gBAAE,OAAO,SAAS,CAAC;YAC1B,OAAO,IAAI,GAAG,CACZ,EAAiB,EACjB,iBAAiB,EACjB,eAAe,CAAC,GAAW,CAAC,CAC7B,CAAC;QACJ,CAAC;QACD,OAAO;YACL,OAAO,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,wBAAwB,CAAC,MAAM,EAAE,GAAG;YAClC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,EAAE,EAAE,CAAC;gBACP,OAAO;oBACL,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,IAAI;oBAClB,QAAQ,EAAE,IAAI;iBACf,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
@@ -1,96 +0,0 @@
|
|
1
|
-
import { ItemsSym, MembersSym, SchemaInit, isCoValueClass, } from "../internal.js";
|
2
|
-
/** @category Schema definition */
|
3
|
-
export const Encoders = {
|
4
|
-
Date: {
|
5
|
-
encode: (value) => value.toISOString(),
|
6
|
-
decode: (value) => new Date(value),
|
7
|
-
},
|
8
|
-
};
|
9
|
-
const optional = {
|
10
|
-
ref: optionalRef,
|
11
|
-
json() {
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
13
|
-
return { [SchemaInit]: "json" };
|
14
|
-
},
|
15
|
-
encoded(arg) {
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
17
|
-
return { [SchemaInit]: { encoded: arg } };
|
18
|
-
},
|
19
|
-
string: {
|
20
|
-
[SchemaInit]: "json",
|
21
|
-
},
|
22
|
-
number: {
|
23
|
-
[SchemaInit]: "json",
|
24
|
-
},
|
25
|
-
boolean: {
|
26
|
-
[SchemaInit]: "json",
|
27
|
-
},
|
28
|
-
null: {
|
29
|
-
[SchemaInit]: "json",
|
30
|
-
},
|
31
|
-
Date: {
|
32
|
-
[SchemaInit]: { encoded: Encoders.Date },
|
33
|
-
},
|
34
|
-
literal(..._lit) {
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
36
|
-
return { [SchemaInit]: "json" };
|
37
|
-
},
|
38
|
-
};
|
39
|
-
/** @category Schema definition */
|
40
|
-
export const co = {
|
41
|
-
string: {
|
42
|
-
[SchemaInit]: "json",
|
43
|
-
},
|
44
|
-
number: {
|
45
|
-
[SchemaInit]: "json",
|
46
|
-
},
|
47
|
-
boolean: {
|
48
|
-
[SchemaInit]: "json",
|
49
|
-
},
|
50
|
-
null: {
|
51
|
-
[SchemaInit]: "json",
|
52
|
-
},
|
53
|
-
Date: {
|
54
|
-
[SchemaInit]: { encoded: Encoders.Date },
|
55
|
-
},
|
56
|
-
literal(..._lit) {
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
58
|
-
return { [SchemaInit]: "json" };
|
59
|
-
},
|
60
|
-
json() {
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
62
|
-
return { [SchemaInit]: "json" };
|
63
|
-
},
|
64
|
-
encoded(arg) {
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
66
|
-
return { [SchemaInit]: { encoded: arg } };
|
67
|
-
},
|
68
|
-
ref,
|
69
|
-
items: ItemsSym,
|
70
|
-
members: MembersSym,
|
71
|
-
optional,
|
72
|
-
};
|
73
|
-
function optionalRef(arg) {
|
74
|
-
return ref(arg, { optional: true });
|
75
|
-
}
|
76
|
-
function ref(arg, options) {
|
77
|
-
return {
|
78
|
-
[SchemaInit]: {
|
79
|
-
ref: arg,
|
80
|
-
optional: options?.optional || false,
|
81
|
-
},
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
83
|
-
};
|
84
|
-
}
|
85
|
-
export function isRefEncoded(schema) {
|
86
|
-
return (typeof schema === "object" &&
|
87
|
-
"ref" in schema &&
|
88
|
-
"optional" in schema &&
|
89
|
-
typeof schema.ref === "function");
|
90
|
-
}
|
91
|
-
export function instantiateRefEncoded(schema, raw) {
|
92
|
-
return isCoValueClass(schema.ref)
|
93
|
-
? schema.ref.fromRaw(raw)
|
94
|
-
: schema.ref(raw).fromRaw(raw);
|
95
|
-
}
|
96
|
-
//# sourceMappingURL=schema.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/implementation/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,kCAAkC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE;QACJ,MAAM,EAAE,CAAC,KAAW,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE;QAC5C,MAAM,EAAE,CAAC,KAAgB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAe,CAAC;KACxD;CACF,CAAC;AAYF,MAAM,QAAQ,GAAG;IACf,GAAG,EAAE,WAAW;IAChB,IAAI;QACF,8DAA8D;QAC9D,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,MAAuB,EAAS,CAAC;IAC1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,CAAI,GAAe;QACxB,8DAA8D;QAC9D,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAmB,EAAS,CAAC;IACpE,CAAC;IACD,GAAG;IACH,KAAK,EAAE,QAAoB;IAC3B,OAAO,EAAE,UAAwB;IACjC,QAAQ;CACT,CAAC;AAEF,SAAS,WAAW,CAClB,GAA+C;IAE/C,OAAO,GAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC;AAUD,SAAS,GAAG,CAIV,GAA+C,EAC/C,OAAiB;IAIjB,OAAO;QACL,CAAC,UAAU,CAAC,EAAE;YACZ,GAAG,EAAE,GAAG;YACR,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,KAAK;SACpB;QAClB,8DAA8D;KACxD,CAAC;AACX,CAAC;AASD,MAAM,UAAU,YAAY,CAC1B,MAAc;IAEd,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,IAAI,MAAM;QACf,UAAU,IAAI,MAAM;QACpB,OAAO,MAAM,CAAC,GAAG,KAAK,UAAU,CACjC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,MAAqB,EACrB,GAAe;IAEf,OAAO,cAAc,CAAI,MAAM,CAAC,GAAG,CAAC;QAClC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;QACzB,CAAC,CAAE,MAAM,CAAC,GAAgE,CACtE,GAAG,CACJ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
|
@@ -1,91 +0,0 @@
|
|
1
|
-
export const subscriptionsScopes = new WeakMap();
|
2
|
-
const TRACE_INVALIDATIONS = false;
|
3
|
-
export class SubscriptionScope {
|
4
|
-
constructor(root, rootSchema, onUpdate) {
|
5
|
-
this.scopeID = `scope-${Math.random().toString(36).slice(2)}`;
|
6
|
-
this.entries = new Map();
|
7
|
-
this.scheduledUpdate = false;
|
8
|
-
this.cachedValues = {};
|
9
|
-
this.parents = {};
|
10
|
-
this.rootEntry = {
|
11
|
-
state: "loaded",
|
12
|
-
value: root._raw,
|
13
|
-
rawUnsub: () => { }, // placeholder
|
14
|
-
};
|
15
|
-
this.entries.set(root.id, this.rootEntry);
|
16
|
-
subscriptionsScopes.set(root, this);
|
17
|
-
this.subscriber = root._loadedAs;
|
18
|
-
this.scheduleUpdate = () => {
|
19
|
-
const value = rootSchema.fromRaw(this.rootEntry.value);
|
20
|
-
subscriptionsScopes.set(value, this);
|
21
|
-
onUpdate(value);
|
22
|
-
};
|
23
|
-
this.rootEntry.rawUnsub = root._raw.core.subscribe((rawUpdate) => {
|
24
|
-
if (!rawUpdate)
|
25
|
-
return;
|
26
|
-
this.rootEntry.value = rawUpdate;
|
27
|
-
this.scheduleUpdate();
|
28
|
-
});
|
29
|
-
}
|
30
|
-
onRefAccessedOrSet(fromId, accessedOrSetId) {
|
31
|
-
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
32
|
-
if (!accessedOrSetId) {
|
33
|
-
return;
|
34
|
-
}
|
35
|
-
this.parents[accessedOrSetId] = this.parents[accessedOrSetId] || new Set();
|
36
|
-
this.parents[accessedOrSetId].add(fromId);
|
37
|
-
if (!this.entries.has(accessedOrSetId)) {
|
38
|
-
const loadingEntry = {
|
39
|
-
state: "loading",
|
40
|
-
immediatelyUnsub: false,
|
41
|
-
};
|
42
|
-
this.entries.set(accessedOrSetId, loadingEntry);
|
43
|
-
const node = this.subscriber._type === "Account"
|
44
|
-
? this.subscriber._raw.core.node
|
45
|
-
: this.subscriber.node;
|
46
|
-
void node.loadCoValueCore(accessedOrSetId).then((core) => {
|
47
|
-
if (loadingEntry.state === "loading" && loadingEntry.immediatelyUnsub) {
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
if (core !== "unavailable") {
|
51
|
-
const entry = {
|
52
|
-
state: "loaded",
|
53
|
-
rawUnsub: () => { }, // placeholder
|
54
|
-
};
|
55
|
-
this.entries.set(accessedOrSetId, entry);
|
56
|
-
const rawUnsub = core.subscribe((rawUpdate) => {
|
57
|
-
// console.log("ref update", this.scopeID, accessedOrSetId, JSON.stringify(rawUpdate))
|
58
|
-
if (!rawUpdate)
|
59
|
-
return;
|
60
|
-
this.invalidate(accessedOrSetId);
|
61
|
-
this.scheduleUpdate();
|
62
|
-
});
|
63
|
-
entry.rawUnsub = rawUnsub;
|
64
|
-
}
|
65
|
-
});
|
66
|
-
}
|
67
|
-
}
|
68
|
-
invalidate(id, fromChild, seen = new Set()) {
|
69
|
-
if (seen.has(id))
|
70
|
-
return;
|
71
|
-
TRACE_INVALIDATIONS &&
|
72
|
-
console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
|
73
|
-
delete this.cachedValues[id];
|
74
|
-
seen.add(id);
|
75
|
-
for (const parent of this.parents[id] || []) {
|
76
|
-
this.invalidate(parent, id, seen);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
unsubscribeAll() {
|
80
|
-
for (const entry of this.entries.values()) {
|
81
|
-
if (entry.state === "loaded") {
|
82
|
-
entry.rawUnsub();
|
83
|
-
}
|
84
|
-
else {
|
85
|
-
entry.immediatelyUnsub = true;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
this.entries.clear();
|
89
|
-
}
|
90
|
-
}
|
91
|
-
//# sourceMappingURL=subscriptionScope.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"subscriptionScope.js","sourceRoot":"","sources":["../../../src/implementation/subscriptionScope.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAI3C,CAAC;AAEJ,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,MAAM,OAAO,iBAAiB;IAkB5B,YACE,IAAU,EACV,UAAqD,EACrD,QAAiC;QApBnC,YAAO,GAAW,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,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MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAG5C,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.native.js","sourceRoot":"","sources":["../../src/index.native.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,eAAe,GAChB,MAAM,eAAe,CAAC"}
|
package/dist/native/internal.js
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
export * from "./implementation/symbols.js";
|
2
|
-
export * from "./implementation/inspect.js";
|
3
|
-
export * from "./coValues/interfaces.js";
|
4
|
-
export * from "./coValues/coMap.js";
|
5
|
-
export * from "./coValues/account.js";
|
6
|
-
export * from "./coValues/coList.js";
|
7
|
-
export * from "./coValues/coFeed.js";
|
8
|
-
export * from "./coValues/schemaUnion.js";
|
9
|
-
export * from "./coValues/group.js";
|
10
|
-
export * from "./implementation/errors.js";
|
11
|
-
export * from "./implementation/refs.js";
|
12
|
-
export * from "./implementation/schema.js";
|
13
|
-
export * from "./implementation/subscriptionScope.js";
|
14
|
-
export * from "./coValues/deepLoading.js";
|
15
|
-
export * from "./coValues/extensions/imageDef.js";
|
16
|
-
export * from "./implementation/createContext.js";
|
17
|
-
import "./implementation/devtoolsFormatters.js";
|
18
|
-
//# sourceMappingURL=internal.js.map
|
@@ -1 +0,0 @@
|
|
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,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,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,cAAc,mCAAmC,CAAC;AAElD,OAAO,wCAAwC,CAAC"}
|
package/dist/native/lib/cache.js
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
const weakMap = new WeakMap();
|
2
|
-
export const coValuesCache = {
|
3
|
-
get: (raw, compute) => {
|
4
|
-
const cached = weakMap.get(raw);
|
5
|
-
if (cached) {
|
6
|
-
return cached;
|
7
|
-
}
|
8
|
-
const computed = compute();
|
9
|
-
weakMap.set(raw, computed);
|
10
|
-
return computed;
|
11
|
-
},
|
12
|
-
};
|
13
|
-
//# sourceMappingURL=cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/lib/cache.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,GAAG,IAAI,OAAO,EAAuB,CAAC;AAEnD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,CAAoB,GAAe,EAAE,OAAgB,EAAE,EAAE;QAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAW,CAAC;QACrB,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
2
|
-
import { coValuesCache } from "./cache.js";
|
3
|
-
describe("coValuesCache", () => {
|
4
|
-
test("should return computed value when not cached", () => {
|
5
|
-
const mockRawValue = { type: "comap" };
|
6
|
-
const mockCoValue = { id: "test" };
|
7
|
-
let computeCalls = 0;
|
8
|
-
const result = coValuesCache.get(mockRawValue, () => {
|
9
|
-
computeCalls++;
|
10
|
-
return mockCoValue;
|
11
|
-
});
|
12
|
-
expect(result).toBe(mockCoValue);
|
13
|
-
expect(computeCalls).toBe(1);
|
14
|
-
});
|
15
|
-
test("should return cached value on subsequent calls", () => {
|
16
|
-
const mockRawValue = { type: "comap" };
|
17
|
-
const mockCoValue = { id: "test" };
|
18
|
-
let computeCalls = 0;
|
19
|
-
// First call
|
20
|
-
const result1 = coValuesCache.get(mockRawValue, () => {
|
21
|
-
computeCalls++;
|
22
|
-
return mockCoValue;
|
23
|
-
});
|
24
|
-
// Second call with same raw value
|
25
|
-
const result2 = coValuesCache.get(mockRawValue, () => {
|
26
|
-
computeCalls++;
|
27
|
-
return mockCoValue;
|
28
|
-
});
|
29
|
-
expect(result1).toBe(mockCoValue);
|
30
|
-
expect(result2).toBe(mockCoValue);
|
31
|
-
expect(computeCalls).toBe(1); // Compute should only be called once
|
32
|
-
});
|
33
|
-
test("should cache different values for different raw values", () => {
|
34
|
-
const mockRawValue1 = { type: "comap" };
|
35
|
-
const mockRawValue2 = { type: "colist" };
|
36
|
-
const mockCoValue1 = { id: "test1" };
|
37
|
-
const mockCoValue2 = { id: "test2" };
|
38
|
-
let computeCalls = 0;
|
39
|
-
const result1 = coValuesCache.get(mockRawValue1, () => {
|
40
|
-
computeCalls++;
|
41
|
-
return mockCoValue1;
|
42
|
-
});
|
43
|
-
const result2 = coValuesCache.get(mockRawValue2, () => {
|
44
|
-
computeCalls++;
|
45
|
-
return mockCoValue2;
|
46
|
-
});
|
47
|
-
expect(result1).toBe(mockCoValue1);
|
48
|
-
expect(result2).toBe(mockCoValue2);
|
49
|
-
expect(computeCalls).toBe(2); // Should compute once for each unique raw value
|
50
|
-
});
|
51
|
-
});
|
52
|
-
//# sourceMappingURL=cache.test.js.map
|
@@ -1 +0,0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