jazz-tools 0.8.2 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +11 -3
- package/CHANGELOG.md +17 -0
- package/dist/native/coValues/account.js.map +1 -0
- package/dist/native/coValues/coList.js.map +1 -0
- package/dist/native/coValues/coMap.js.map +1 -0
- package/dist/{coValues → native/coValues}/coStream.js +1 -0
- package/dist/native/coValues/coStream.js.map +1 -0
- package/dist/native/coValues/deepLoading.js.map +1 -0
- package/dist/native/coValues/extensions/imageDef.js.map +1 -0
- package/dist/native/coValues/group.js.map +1 -0
- package/dist/native/coValues/interfaces.js.map +1 -0
- package/dist/{implementation → native/implementation}/createContext.js +8 -1
- package/dist/native/implementation/createContext.js.map +1 -0
- package/dist/native/implementation/devtoolsFormatters.js.map +1 -0
- package/dist/{implementation → native/implementation}/errors.js.map +1 -1
- package/dist/native/implementation/inspect.js.map +1 -0
- package/dist/native/implementation/refs.js.map +1 -0
- package/dist/{implementation → native/implementation}/schema.js +14 -9
- package/dist/native/implementation/schema.js.map +1 -0
- package/dist/native/implementation/subscriptionScope.js.map +1 -0
- package/dist/native/implementation/symbols.js.map +1 -0
- package/dist/native/index.native.js +12 -0
- package/dist/native/index.native.js.map +1 -0
- package/dist/native/internal.js.map +1 -0
- package/dist/web/coValues/account.js +208 -0
- package/dist/web/coValues/account.js.map +1 -0
- package/dist/web/coValues/coList.js +395 -0
- package/dist/web/coValues/coList.js.map +1 -0
- package/dist/web/coValues/coMap.js +501 -0
- package/dist/web/coValues/coMap.js.map +1 -0
- package/dist/web/coValues/coStream.js +413 -0
- package/dist/web/coValues/coStream.js.map +1 -0
- package/dist/web/coValues/deepLoading.js +60 -0
- package/dist/web/coValues/deepLoading.js.map +1 -0
- package/dist/web/coValues/extensions/imageDef.js +37 -0
- package/dist/web/coValues/extensions/imageDef.js.map +1 -0
- package/dist/web/coValues/group.js +120 -0
- package/dist/web/coValues/group.js.map +1 -0
- package/dist/web/coValues/interfaces.js +109 -0
- package/dist/web/coValues/interfaces.js.map +1 -0
- package/dist/web/implementation/createContext.js +151 -0
- package/dist/web/implementation/createContext.js.map +1 -0
- package/dist/web/implementation/devtoolsFormatters.js +115 -0
- package/dist/web/implementation/devtoolsFormatters.js.map +1 -0
- package/dist/web/implementation/errors.js +2 -0
- package/dist/web/implementation/errors.js.map +1 -0
- package/dist/web/implementation/inspect.js +2 -0
- package/dist/web/implementation/inspect.js.map +1 -0
- package/dist/web/implementation/refs.js +127 -0
- package/dist/web/implementation/refs.js.map +1 -0
- package/dist/web/implementation/schema.js +96 -0
- package/dist/web/implementation/schema.js.map +1 -0
- package/dist/web/implementation/subscriptionScope.js +97 -0
- package/dist/web/implementation/subscriptionScope.js.map +1 -0
- package/dist/web/implementation/symbols.js +4 -0
- package/dist/web/implementation/symbols.js.map +1 -0
- package/dist/{index.js → web/index.web.js} +3 -3
- package/dist/{index.js.map → web/index.web.js.map} +1 -1
- package/dist/web/internal.js +17 -0
- package/dist/web/internal.js.map +1 -0
- package/package.json +25 -7
- package/src/coValues/account.ts +4 -1
- package/src/coValues/coStream.ts +26 -4
- package/src/coValues/group.ts +4 -1
- package/src/implementation/createContext.ts +12 -10
- package/src/implementation/schema.ts +21 -13
- package/src/{index.ts → index.native.ts} +2 -3
- package/src/index.web.ts +36 -0
- package/src/tests/coList.test.ts +2 -2
- package/src/tests/coMap.test.ts +12 -10
- package/src/tests/coStream.test.ts +2 -2
- package/src/tests/deepLoading.test.ts +2 -2
- package/src/tests/groupsAndAccounts.test.ts +1 -1
- package/src/tests/schema.test.ts +205 -0
- package/tsconfig.json +5 -4
- package/tsconfig.native.json +11 -0
- package/tsconfig.web.json +11 -0
- package/dist/coValues/account.js.map +0 -1
- package/dist/coValues/coList.js.map +0 -1
- package/dist/coValues/coMap.js.map +0 -1
- package/dist/coValues/coStream.js.map +0 -1
- package/dist/coValues/deepLoading.js.map +0 -1
- package/dist/coValues/extensions/imageDef.js.map +0 -1
- package/dist/coValues/group.js.map +0 -1
- package/dist/coValues/interfaces.js.map +0 -1
- package/dist/implementation/createContext.js.map +0 -1
- package/dist/implementation/devtoolsFormatters.js.map +0 -1
- package/dist/implementation/inspect.js.map +0 -1
- package/dist/implementation/refs.js.map +0 -1
- package/dist/implementation/schema.js.map +0 -1
- package/dist/implementation/subscriptionScope.js.map +0 -1
- package/dist/implementation/symbols.js.map +0 -1
- package/dist/internal.js.map +0 -1
- package/dist/tests/coList.test.js +0 -221
- package/dist/tests/coList.test.js.map +0 -1
- package/dist/tests/coMap.test.js +0 -615
- package/dist/tests/coMap.test.js.map +0 -1
- package/dist/tests/coStream.test.js +0 -324
- package/dist/tests/coStream.test.js.map +0 -1
- package/dist/tests/deepLoading.test.js +0 -175
- package/dist/tests/deepLoading.test.js.map +0 -1
- package/dist/tests/groupsAndAccounts.test.js +0 -69
- package/dist/tests/groupsAndAccounts.test.js.map +0 -1
- /package/dist/{coValues → native/coValues}/account.js +0 -0
- /package/dist/{coValues → native/coValues}/coList.js +0 -0
- /package/dist/{coValues → native/coValues}/coMap.js +0 -0
- /package/dist/{coValues → native/coValues}/deepLoading.js +0 -0
- /package/dist/{coValues → native/coValues}/extensions/imageDef.js +0 -0
- /package/dist/{coValues → native/coValues}/group.js +0 -0
- /package/dist/{coValues → native/coValues}/interfaces.js +0 -0
- /package/dist/{implementation → native/implementation}/devtoolsFormatters.js +0 -0
- /package/dist/{implementation → native/implementation}/errors.js +0 -0
- /package/dist/{implementation → native/implementation}/inspect.js +0 -0
- /package/dist/{implementation → native/implementation}/refs.js +0 -0
- /package/dist/{implementation → native/implementation}/subscriptionScope.js +0 -0
- /package/dist/{implementation → native/implementation}/symbols.js +0 -0
- /package/dist/{internal.js → native/internal.js} +0 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
export const subscriptionsScopes = new WeakMap();
|
2
|
+
const TRACE_INVALIDATIONS = false;
|
3
|
+
export class SubscriptionScope {
|
4
|
+
scopeID = `scope-${Math.random().toString(36).slice(2)}`;
|
5
|
+
subscriber;
|
6
|
+
entries = new Map();
|
7
|
+
rootEntry;
|
8
|
+
onUpdate;
|
9
|
+
scheduledUpdate = false;
|
10
|
+
cachedValues = {};
|
11
|
+
parents = {};
|
12
|
+
constructor(root, rootSchema, onUpdate) {
|
13
|
+
this.rootEntry = {
|
14
|
+
state: "loaded",
|
15
|
+
value: root,
|
16
|
+
rawUnsub: () => { }, // placeholder
|
17
|
+
};
|
18
|
+
this.entries.set(root.id, this.rootEntry);
|
19
|
+
subscriptionsScopes.set(root, this);
|
20
|
+
this.subscriber = root._loadedAs;
|
21
|
+
this.onUpdate = onUpdate;
|
22
|
+
this.rootEntry.rawUnsub = root._raw.core.subscribe((rawUpdate) => {
|
23
|
+
if (!rawUpdate)
|
24
|
+
return;
|
25
|
+
this.rootEntry.value = rootSchema.fromRaw(rawUpdate);
|
26
|
+
// console.log("root update", this.rootEntry.value.toJSON());
|
27
|
+
subscriptionsScopes.set(this.rootEntry.value, this);
|
28
|
+
this.scheduleUpdate();
|
29
|
+
});
|
30
|
+
}
|
31
|
+
scheduleUpdate() {
|
32
|
+
this.onUpdate(this.rootEntry.value);
|
33
|
+
}
|
34
|
+
onRefAccessedOrSet(fromId, accessedOrSetId) {
|
35
|
+
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
36
|
+
if (!accessedOrSetId) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
this.parents[accessedOrSetId] =
|
40
|
+
this.parents[accessedOrSetId] || new Set();
|
41
|
+
this.parents[accessedOrSetId].add(fromId);
|
42
|
+
if (!this.entries.has(accessedOrSetId)) {
|
43
|
+
const loadingEntry = {
|
44
|
+
state: "loading",
|
45
|
+
immediatelyUnsub: false,
|
46
|
+
};
|
47
|
+
this.entries.set(accessedOrSetId, loadingEntry);
|
48
|
+
const node = this.subscriber._type === "Account"
|
49
|
+
? this.subscriber._raw.core.node
|
50
|
+
: this.subscriber.node;
|
51
|
+
void node.loadCoValueCore(accessedOrSetId).then((core) => {
|
52
|
+
if (loadingEntry.state === "loading" &&
|
53
|
+
loadingEntry.immediatelyUnsub) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
if (core !== "unavailable") {
|
57
|
+
const entry = {
|
58
|
+
state: "loaded",
|
59
|
+
rawUnsub: () => { }, // placeholder
|
60
|
+
};
|
61
|
+
this.entries.set(accessedOrSetId, entry);
|
62
|
+
const rawUnsub = core.subscribe((rawUpdate) => {
|
63
|
+
// console.log("ref update", this.scopeID, accessedOrSetId, JSON.stringify(rawUpdate))
|
64
|
+
if (!rawUpdate)
|
65
|
+
return;
|
66
|
+
this.invalidate(accessedOrSetId);
|
67
|
+
this.scheduleUpdate();
|
68
|
+
});
|
69
|
+
entry.rawUnsub = rawUnsub;
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
}
|
74
|
+
invalidate(id, fromChild, seen = new Set()) {
|
75
|
+
if (seen.has(id))
|
76
|
+
return;
|
77
|
+
TRACE_INVALIDATIONS &&
|
78
|
+
console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
|
79
|
+
delete this.cachedValues[id];
|
80
|
+
seen.add(id);
|
81
|
+
for (const parent of this.parents[id] || []) {
|
82
|
+
this.invalidate(parent, id, seen);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
unsubscribeAll() {
|
86
|
+
for (const entry of this.entries.values()) {
|
87
|
+
if (entry.state === "loaded") {
|
88
|
+
entry.rawUnsub();
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
entry.immediatelyUnsub = true;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
this.entries.clear();
|
95
|
+
}
|
96
|
+
}
|
97
|
+
//# sourceMappingURL=subscriptionScope.js.map
|
@@ -0,0 +1 @@
|
|
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,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ACJ"}
|
@@ -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,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAG5C,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto
|
1
|
+
export { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto } from "cojson";
|
2
2
|
export { Encoders, co } from "./internal.js";
|
3
3
|
export { CoMap } from "./internal.js";
|
4
4
|
export { CoList } from "./internal.js";
|
@@ -8,5 +8,5 @@ export { Account, isControlledAccount } from "./internal.js";
|
|
8
8
|
export { ImageDefinition } from "./internal.js";
|
9
9
|
export { CoValueBase } from "./internal.js";
|
10
10
|
export { loadCoValue, subscribeToCoValue } from "./internal.js";
|
11
|
-
export { createJazzContext, fixedCredentialsAuth, ephemeralCredentialsAuth, AnonymousJazzAgent, createAnonymousJazzContext, randomSessionProvider } from "./internal.js";
|
12
|
-
//# sourceMappingURL=index.js.map
|
11
|
+
export { createJazzContext, fixedCredentialsAuth, ephemeralCredentialsAuth, AnonymousJazzAgent, createAnonymousJazzContext, randomSessionProvider, } from "./internal.js";
|
12
|
+
//# sourceMappingURL=index.web.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.web.js","sourceRoot":"","sources":["../../src/index.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAa9E,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAkB,MAAM,eAAe,CAAC;AACtD,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,EAAqB,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAqB,MAAM,eAAe,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAGH,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,0BAA0B,EAC1B,qBAAqB,GACxB,MAAM,eAAe,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
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/coStream.js";
|
8
|
+
export * from "./coValues/group.js";
|
9
|
+
export * from "./implementation/errors.js";
|
10
|
+
export * from "./implementation/refs.js";
|
11
|
+
export * from "./implementation/schema.js";
|
12
|
+
export * from "./implementation/subscriptionScope.js";
|
13
|
+
export * from "./coValues/deepLoading.js";
|
14
|
+
export * from "./coValues/extensions/imageDef.js";
|
15
|
+
export * from "./implementation/createContext.js";
|
16
|
+
import "./implementation/devtoolsFormatters.js";
|
17
|
+
//# sourceMappingURL=internal.js.map
|
@@ -0,0 +1 @@
|
|
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,cAAc,mCAAmC,CAAC;AAElD,OAAO,wCAAwC,CAAC"}
|
package/package.json
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-tools",
|
3
|
-
"module": "
|
4
|
-
"main": "
|
5
|
-
"types": "
|
3
|
+
"module": "dist/web/index.web.js",
|
4
|
+
"main": "dist/web/index.web.js",
|
5
|
+
"types": "src/index.web.ts",
|
6
|
+
"react-native": "dist/native/index.native.js",
|
7
|
+
"exports": {
|
8
|
+
".": {
|
9
|
+
"react-native": "./dist/native/index.native.js",
|
10
|
+
"types": "./src/index.web.ts",
|
11
|
+
"default": "./dist/web/index.web.js"
|
12
|
+
},
|
13
|
+
"./native": {
|
14
|
+
"react-native": "./dist/native/index.native.js",
|
15
|
+
"types": "./src/index.native.ts",
|
16
|
+
"default": "./dist/native/index.native.js"
|
17
|
+
},
|
18
|
+
"./src/*": "./src/*"
|
19
|
+
},
|
6
20
|
"type": "module",
|
7
21
|
"license": "MIT",
|
8
|
-
"version": "0.8.
|
22
|
+
"version": "0.8.5",
|
9
23
|
"dependencies": {
|
10
|
-
"
|
11
|
-
"
|
24
|
+
"fast-check": "^3.17.2",
|
25
|
+
"cojson": "0.8.5"
|
12
26
|
},
|
13
27
|
"devDependencies": {
|
14
28
|
"typescript": "^5.3.3",
|
@@ -26,10 +40,14 @@
|
|
26
40
|
"*.{js,jsx,mdx,json}": "prettier --write"
|
27
41
|
},
|
28
42
|
"scripts": {
|
43
|
+
"dev:web": "tsc --sourceMap --watch --outDir dist/web -p tsconfig.web.json",
|
44
|
+
"dev:native": "tsc --sourceMap --watch --outDir dist/native -p tsconfig.native.json",
|
29
45
|
"test": "vitest --run --root ../../ --project jazz-tools",
|
30
46
|
"test:watch": "vitest --watch --root ../../ --project jazz-tools",
|
31
47
|
"lint": "eslint . --ext ts,tsx",
|
32
48
|
"format": "prettier --write './src/**/*.{ts,tsx}'",
|
33
|
-
"build": "
|
49
|
+
"build:web": "tsc --sourceMap --outDir dist/web -p tsconfig.web.json",
|
50
|
+
"build:native": "tsc --sourceMap --outDir dist/native -p tsconfig.native.json",
|
51
|
+
"build": "npm run lint && rm -rf ./dist && pnpm run build:web && pnpm run build:native"
|
34
52
|
}
|
35
53
|
}
|
package/src/coValues/account.ts
CHANGED
@@ -80,7 +80,10 @@ export class Account extends CoValueBase implements CoValue {
|
|
80
80
|
declare profile: Profile | null;
|
81
81
|
declare root: CoMap | null;
|
82
82
|
|
83
|
-
get _refs() {
|
83
|
+
get _refs(): {
|
84
|
+
profile: RefIfCoValue<Profile> | undefined;
|
85
|
+
root: RefIfCoValue<CoMap> | undefined;
|
86
|
+
} {
|
84
87
|
const profileID = this._raw.get("profile") as unknown as
|
85
88
|
| ID<NonNullable<this["profile"]>>
|
86
89
|
| undefined;
|
package/src/coValues/coStream.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
1
2
|
import type {
|
2
3
|
RawAccountID,
|
3
4
|
AgentID,
|
@@ -155,7 +156,12 @@ export class CoStream<Item = any> extends CoValueBase implements CoValue {
|
|
155
156
|
}
|
156
157
|
}
|
157
158
|
|
158
|
-
toJSON() {
|
159
|
+
toJSON(): {
|
160
|
+
id: string;
|
161
|
+
_type: "CoStream";
|
162
|
+
[key: string]: unknown;
|
163
|
+
in: { [key: string]: unknown };
|
164
|
+
} {
|
159
165
|
const itemDescriptor = this._schema[ItemsSym] as Schema;
|
160
166
|
const mapper =
|
161
167
|
itemDescriptor === "json"
|
@@ -182,7 +188,12 @@ export class CoStream<Item = any> extends CoValueBase implements CoValue {
|
|
182
188
|
};
|
183
189
|
}
|
184
190
|
|
185
|
-
[inspect]() {
|
191
|
+
[inspect](): {
|
192
|
+
id: string;
|
193
|
+
_type: "CoStream";
|
194
|
+
[key: string]: unknown;
|
195
|
+
in: { [key: string]: unknown };
|
196
|
+
} {
|
186
197
|
return this.toJSON();
|
187
198
|
}
|
188
199
|
|
@@ -323,7 +334,9 @@ export const CoStreamProxyHandler: ProxyHandler<CoStream> = {
|
|
323
334
|
|
324
335
|
Object.defineProperty(entry, "all", {
|
325
336
|
get: () => {
|
326
|
-
const allRawEntries = target._raw.itemsBy(
|
337
|
+
const allRawEntries = target._raw.itemsBy(
|
338
|
+
key as RawAccountID,
|
339
|
+
);
|
327
340
|
return (function* () {
|
328
341
|
while (true) {
|
329
342
|
const rawEntry = allRawEntries.next();
|
@@ -543,6 +556,7 @@ export class BinaryCoStream extends CoValueBase implements CoValue {
|
|
543
556
|
return undefined;
|
544
557
|
}
|
545
558
|
|
559
|
+
// @ts-ignore
|
546
560
|
return new Blob(chunks.chunks, { type: chunks.mimeType });
|
547
561
|
}
|
548
562
|
|
@@ -626,7 +640,15 @@ export class BinaryCoStream extends CoValueBase implements CoValue {
|
|
626
640
|
return stream;
|
627
641
|
}
|
628
642
|
|
629
|
-
toJSON() {
|
643
|
+
toJSON(): {
|
644
|
+
id: string;
|
645
|
+
_type: "BinaryCoStream";
|
646
|
+
mimeType?: string;
|
647
|
+
totalSizeBytes?: number;
|
648
|
+
fileName?: string;
|
649
|
+
chunks?: Uint8Array[];
|
650
|
+
finished?: boolean;
|
651
|
+
} {
|
630
652
|
return {
|
631
653
|
id: this.id,
|
632
654
|
_type: this._type,
|
package/src/coValues/group.ts
CHANGED
@@ -65,7 +65,10 @@ export class Group extends CoValueBase implements CoValue {
|
|
65
65
|
declare root: CoMap | null;
|
66
66
|
declare [MembersSym]: Account | null;
|
67
67
|
|
68
|
-
get _refs() {
|
68
|
+
get _refs(): {
|
69
|
+
profile: Ref<Profile> | undefined;
|
70
|
+
root: Ref<CoMap> | undefined;
|
71
|
+
} {
|
69
72
|
const profileID = this._raw.get("profile") as unknown as
|
70
73
|
| ID<NonNullable<this["profile"]>>
|
71
74
|
| undefined;
|
@@ -102,7 +102,9 @@ export type JazzContextWithAgent = {
|
|
102
102
|
logOut: () => void;
|
103
103
|
};
|
104
104
|
|
105
|
-
export type JazzContext<Acc extends Account> =
|
105
|
+
export type JazzContext<Acc extends Account> =
|
106
|
+
| JazzContextWithAccount<Acc>
|
107
|
+
| JazzContextWithAgent;
|
106
108
|
|
107
109
|
export async function createJazzContext<Acc extends Account>({
|
108
110
|
AccountSchema,
|
@@ -117,14 +119,10 @@ export async function createJazzContext({
|
|
117
119
|
}: BaseContextParams): Promise<JazzContextWithAgent>;
|
118
120
|
export async function createJazzContext<Acc extends Account>(
|
119
121
|
options: ContextParamsWithAuth<Acc> | BaseContextParams,
|
120
|
-
): Promise<
|
121
|
-
JazzContext<Acc>
|
122
|
-
>
|
122
|
+
): Promise<JazzContext<Acc>>;
|
123
123
|
export async function createJazzContext<Acc extends Account>(
|
124
124
|
options: ContextParamsWithAuth<Acc> | BaseContextParams,
|
125
|
-
): Promise<
|
126
|
-
JazzContext<Acc>
|
127
|
-
> {
|
125
|
+
): Promise<JazzContext<Acc>> {
|
128
126
|
// eslint-disable-next-line no-constant-condition
|
129
127
|
while (true) {
|
130
128
|
if (!("auth" in options)) {
|
@@ -137,8 +135,13 @@ JazzContext<Acc>
|
|
137
135
|
const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
|
138
136
|
const AccountSchema =
|
139
137
|
options.AccountSchema ?? (Account as unknown as AccountClass<Acc>);
|
140
|
-
|
141
|
-
|
138
|
+
let authResult: AuthResult;
|
139
|
+
try {
|
140
|
+
authResult = await auth.start(crypto);
|
141
|
+
} catch (e) {
|
142
|
+
console.error("error", e);
|
143
|
+
throw e;
|
144
|
+
}
|
142
145
|
|
143
146
|
if (authResult.type === "existing") {
|
144
147
|
try {
|
@@ -215,7 +218,6 @@ JazzContext<Acc>
|
|
215
218
|
});
|
216
219
|
|
217
220
|
authResult.onSuccess();
|
218
|
-
|
219
221
|
return {
|
220
222
|
account,
|
221
223
|
done: () => {
|
@@ -4,7 +4,19 @@ import {
|
|
4
4
|
type CoValueClass,
|
5
5
|
isCoValueClass,
|
6
6
|
CoValueFromRaw,
|
7
|
+
SchemaInit,
|
8
|
+
ItemsSym,
|
9
|
+
MembersSym,
|
7
10
|
} from "../internal.js";
|
11
|
+
import { CoJsonValue } from "cojson/src/jsonValue.js";
|
12
|
+
|
13
|
+
/** @category Schema definition */
|
14
|
+
export const Encoders = {
|
15
|
+
Date: {
|
16
|
+
encode: (value: Date) => value.toISOString(),
|
17
|
+
decode: (value: JsonValue) => new Date(value as string),
|
18
|
+
},
|
19
|
+
};
|
8
20
|
|
9
21
|
export type CoMarker = { readonly __co: unique symbol };
|
10
22
|
/** @category Schema definition */
|
@@ -18,7 +30,7 @@ export type UnCo<T> = T extends co<infer A> ? A : T;
|
|
18
30
|
|
19
31
|
const optional = {
|
20
32
|
ref: optionalRef,
|
21
|
-
json<T extends
|
33
|
+
json<T extends CoJsonValue<T>>(): co<T | undefined> {
|
22
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
23
35
|
return { [SchemaInit]: "json" satisfies Schema } as any;
|
24
36
|
},
|
@@ -38,6 +50,9 @@ const optional = {
|
|
38
50
|
null: {
|
39
51
|
[SchemaInit]: "json" satisfies Schema,
|
40
52
|
} as unknown as co<null | undefined>,
|
53
|
+
Date: {
|
54
|
+
[SchemaInit]: { encoded: Encoders.Date } satisfies Schema,
|
55
|
+
} as unknown as co<Date | undefined>,
|
41
56
|
literal<T extends (string | number | boolean)[]>(
|
42
57
|
..._lit: T
|
43
58
|
): co<T[number] | undefined> {
|
@@ -60,13 +75,16 @@ export const co = {
|
|
60
75
|
null: {
|
61
76
|
[SchemaInit]: "json" satisfies Schema,
|
62
77
|
} as unknown as co<null>,
|
78
|
+
Date: {
|
79
|
+
[SchemaInit]: { encoded: Encoders.Date } satisfies Schema,
|
80
|
+
} as unknown as co<Date>,
|
63
81
|
literal<T extends (string | number | boolean)[]>(
|
64
82
|
..._lit: T
|
65
83
|
): co<T[number]> {
|
66
84
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
67
85
|
return { [SchemaInit]: "json" satisfies Schema } as any;
|
68
86
|
},
|
69
|
-
json<T extends
|
87
|
+
json<T extends CoJsonValue<T>>(): co<T> {
|
70
88
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
71
89
|
return { [SchemaInit]: "json" satisfies Schema } as any;
|
72
90
|
},
|
@@ -155,20 +173,10 @@ export type SchemaFor<Field> = NonNullable<Field> extends CoValue
|
|
155
173
|
export type Encoder<V> = {
|
156
174
|
encode: (value: V) => JsonValue;
|
157
175
|
decode: (value: JsonValue) => V;
|
158
|
-
}
|
176
|
+
}
|
159
177
|
export type OptionalEncoder<V> =
|
160
178
|
| Encoder<V>
|
161
179
|
| {
|
162
180
|
encode: (value: V | undefined) => JsonValue;
|
163
181
|
decode: (value: JsonValue) => V | undefined;
|
164
182
|
};
|
165
|
-
|
166
|
-
import { SchemaInit, ItemsSym, MembersSym } from "./symbols.js";
|
167
|
-
|
168
|
-
/** @category Schema definition */
|
169
|
-
export const Encoders = {
|
170
|
-
Date: {
|
171
|
-
encode: (value: Date) => value.toISOString(),
|
172
|
-
decode: (value: JsonValue) => new Date(value as string),
|
173
|
-
},
|
174
|
-
};
|
@@ -1,9 +1,8 @@
|
|
1
1
|
export {
|
2
2
|
cojsonInternals,
|
3
3
|
MAX_RECOMMENDED_TX_SIZE,
|
4
|
-
WasmCrypto,
|
5
4
|
PureJSCrypto,
|
6
|
-
} from "cojson";
|
5
|
+
} from "cojson/native";
|
7
6
|
export type {
|
8
7
|
InviteSecret,
|
9
8
|
Peer,
|
@@ -37,5 +36,5 @@ export {
|
|
37
36
|
ephemeralCredentialsAuth,
|
38
37
|
AnonymousJazzAgent,
|
39
38
|
createAnonymousJazzContext,
|
40
|
-
randomSessionProvider
|
39
|
+
randomSessionProvider,
|
41
40
|
} from "./internal.js";
|
package/src/index.web.ts
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
export { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto } from "cojson";
|
2
|
+
export type {
|
3
|
+
InviteSecret,
|
4
|
+
Peer,
|
5
|
+
SessionID,
|
6
|
+
AgentID,
|
7
|
+
SyncMessage,
|
8
|
+
CryptoProvider,
|
9
|
+
CoValueUniqueness,
|
10
|
+
} from "cojson";
|
11
|
+
|
12
|
+
export type { ID, CoValue } from "./internal.js";
|
13
|
+
|
14
|
+
export { Encoders, co } from "./internal.js";
|
15
|
+
|
16
|
+
export { CoMap, type CoMapInit } from "./internal.js";
|
17
|
+
export { CoList } from "./internal.js";
|
18
|
+
export { CoStream, BinaryCoStream } from "./internal.js";
|
19
|
+
export { Group, Profile } from "./internal.js";
|
20
|
+
export { Account, isControlledAccount, type AccountClass } from "./internal.js";
|
21
|
+
export { ImageDefinition } from "./internal.js";
|
22
|
+
export { CoValueBase, type CoValueClass } from "./internal.js";
|
23
|
+
export type { DepthsIn, DeeplyLoaded } from "./internal.js";
|
24
|
+
|
25
|
+
export { loadCoValue, subscribeToCoValue } from "./internal.js";
|
26
|
+
|
27
|
+
export {
|
28
|
+
type AuthMethod,
|
29
|
+
type AuthResult,
|
30
|
+
createJazzContext,
|
31
|
+
fixedCredentialsAuth,
|
32
|
+
ephemeralCredentialsAuth,
|
33
|
+
AnonymousJazzAgent,
|
34
|
+
createAnonymousJazzContext,
|
35
|
+
randomSessionProvider,
|
36
|
+
} from "./internal.js";
|
package/src/tests/coList.test.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect, describe, test } from "vitest";
|
2
|
-
import { connectedPeers } from "cojson/src/streamUtils.
|
2
|
+
import { connectedPeers } from "cojson/src/streamUtils.ts";
|
3
3
|
import {
|
4
4
|
Account,
|
5
5
|
CoList,
|
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
createJazzContext,
|
10
10
|
isControlledAccount,
|
11
11
|
fixedCredentialsAuth,
|
12
|
-
} from "../index.js";
|
12
|
+
} from "../index.web.js";
|
13
13
|
import { randomSessionProvider } from "../internal.js";
|
14
14
|
|
15
15
|
const Crypto = await WasmCrypto.create();
|
package/src/tests/coMap.test.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect, describe, test, expectTypeOf } from "vitest";
|
2
|
-
import { connectedPeers } from "cojson/src/streamUtils.
|
2
|
+
import { connectedPeers } from "cojson/src/streamUtils.ts";
|
3
3
|
import {
|
4
4
|
Account,
|
5
5
|
Encoders,
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
cojsonInternals,
|
11
11
|
createJazzContext,
|
12
12
|
fixedCredentialsAuth,
|
13
|
-
} from "../index.js";
|
13
|
+
} from "../index.web.js";
|
14
14
|
import { Group, randomSessionProvider } from "../internal.js";
|
15
15
|
|
16
16
|
const Crypto = await WasmCrypto.create();
|
@@ -18,7 +18,7 @@ const Crypto = await WasmCrypto.create();
|
|
18
18
|
class TestMap extends CoMap {
|
19
19
|
color = co.string;
|
20
20
|
_height = co.number;
|
21
|
-
birthday = co.
|
21
|
+
birthday = co.Date;
|
22
22
|
name? = co.string;
|
23
23
|
nullable = co.optional.encoded<string | undefined>({
|
24
24
|
encode: (value: string | undefined) => value || null,
|
@@ -888,13 +888,15 @@ describe("Creating and finding unique CoMaps", async () => {
|
|
888
888
|
owner: me,
|
889
889
|
});
|
890
890
|
|
891
|
-
const alice = TestMap.create(
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
891
|
+
const alice = TestMap.create(
|
892
|
+
{
|
893
|
+
name: "Alice",
|
894
|
+
_height: 100,
|
895
|
+
birthday: new Date("1990-01-01"),
|
896
|
+
color: "red",
|
897
|
+
},
|
898
|
+
{ owner: group, unique: { name: "Alice" } },
|
899
|
+
);
|
898
900
|
|
899
901
|
const foundAlice = TestMap.findUnique({ name: "Alice" }, group.id, me);
|
900
902
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect, describe, test } from "vitest";
|
2
|
-
import { connectedPeers } from "cojson/src/streamUtils.
|
2
|
+
import { connectedPeers } from "cojson/src/streamUtils.ts";
|
3
3
|
import {
|
4
4
|
BinaryCoStream,
|
5
5
|
ID,
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
cojsonInternals,
|
12
12
|
createJazzContext,
|
13
13
|
fixedCredentialsAuth,
|
14
|
-
} from "../index.js";
|
14
|
+
} from "../index.web.js";
|
15
15
|
import { randomSessionProvider } from "../internal.js";
|
16
16
|
|
17
17
|
const Crypto = await WasmCrypto.create();
|
@@ -1,6 +1,6 @@
|
|
1
1
|
const Crypto = await WasmCrypto.create();
|
2
2
|
import { expect, describe, test, expectTypeOf } from "vitest";
|
3
|
-
import { connectedPeers } from "cojson/src/streamUtils.
|
3
|
+
import { connectedPeers } from "cojson/src/streamUtils.ts";
|
4
4
|
import {
|
5
5
|
Account,
|
6
6
|
CoList,
|
@@ -14,7 +14,7 @@ import {
|
|
14
14
|
ID,
|
15
15
|
createJazzContext,
|
16
16
|
fixedCredentialsAuth,
|
17
|
-
} from "../index.js";
|
17
|
+
} from "../index.web.js";
|
18
18
|
import { randomSessionProvider } from "../internal.js";
|
19
19
|
|
20
20
|
class TestMap extends CoMap {
|