jazz-tools 0.7.34 → 0.7.35-unique.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +60 -45
- package/CHANGELOG.md +14 -0
- package/dist/coValues/account.js +20 -35
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +14 -19
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +28 -19
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +14 -19
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +3 -8
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +20 -23
- package/dist/coValues/group.js.map +1 -1
- package/dist/implementation/createContext.js +94 -0
- package/dist/implementation/createContext.js.map +1 -0
- package/dist/implementation/refs.js +3 -0
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +8 -5
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +23 -15
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +76 -102
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +26 -22
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +24 -36
- package/dist/tests/deepLoading.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +8 -22
- package/dist/tests/groupsAndAccounts.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +5 -28
- package/src/coValues/coList.ts +4 -4
- package/src/coValues/coMap.ts +44 -6
- package/src/coValues/coStream.ts +4 -4
- package/src/coValues/group.ts +2 -2
- package/src/coValues/interfaces.ts +4 -4
- package/src/implementation/createContext.ts +162 -0
- package/src/index.ts +9 -1
- package/src/internal.ts +2 -0
- package/src/tests/coList.test.ts +30 -14
- package/src/tests/coMap.test.ts +113 -84
- package/src/tests/coStream.test.ts +27 -21
- package/src/tests/deepLoading.test.ts +18 -13
- package/tsconfig.json +1 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.7.
|
2
|
+
> jazz-tools@0.7.35-new-auth.0 build /Users/anselm/jazz/jazz/packages/jazz-tools
|
3
3
|
> npm run lint && rm -rf ./dist && tsc --sourceMap --outDir dist
|
4
4
|
|
5
5
|
|
6
|
-
> jazz-tools@0.7.
|
6
|
+
> jazz-tools@0.7.35-new-auth.0 lint
|
7
7
|
> eslint . --ext ts,tsx
|
8
8
|
|
package/.turbo/turbo-test.log
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.7.
|
2
|
+
> jazz-tools@0.7.35-new-auth.0 test /Users/anselm/jazz/jazz/packages/jazz-tools
|
3
3
|
> vitest --run
|
4
4
|
|
5
5
|
|
6
6
|
RUN v0.34.6 /Users/anselm/jazz/jazz/packages/jazz-tools
|
7
7
|
|
8
|
-
✓ src/tests/groupsAndAccounts.test.ts (1 test)
|
8
|
+
✓ src/tests/groupsAndAccounts.test.ts (1 test) 35ms
|
9
|
+
❯ src/tests/coMap.test.ts (0 test)
|
9
10
|
stdout | unknown test
|
10
11
|
TestMap schema [90mundefined[39m
|
12
|
+
{ uniqueness: { name: [32m'Alice'[39m } }
|
11
13
|
|
12
|
-
✓ src/tests/deepLoading.test.ts (3 tests)
|
14
|
+
✓ src/tests/deepLoading.test.ts (3 tests) 48ms
|
13
15
|
✓ src/tests/coList.test.ts (10 tests) 80ms
|
14
16
|
stdout | src/tests/coList.test.ts > Simple CoList operations > Mutation > splice
|
15
17
|
[ [32m'bread'[39m, [32m'onion'[39m ] [33m0[39m
|
@@ -23,19 +25,15 @@ subscribedList?.[0]?.[0]?.[0] x
|
|
23
25
|
subscribedList?.[0]?.[0]?.[0] y
|
24
26
|
subscribedList?.[0]?.[0]?.[0] w
|
25
27
|
|
26
|
-
|
27
|
-
subscribedMap.nested?.twiceNested?.taste [90mundefined[39m
|
28
|
-
subscribedMap.nested?.twiceNested?.taste [90mundefined[39m
|
29
|
-
subscribedMap.nested?.twiceNested?.taste sour
|
30
|
-
|
28
|
+
✓ src/tests/coStream.test.ts (10 tests) 112ms
|
31
29
|
stdout | src/tests/coStream.test.ts > CoStream resolution > Subscription & auto-resolution
|
32
30
|
subscribedStream[me.id] {
|
33
31
|
value: [36m[Getter][39m,
|
34
32
|
ref: [36m[Getter][39m,
|
35
33
|
by: [36m[Getter][39m,
|
36
|
-
madeAt: [35m2024-
|
34
|
+
madeAt: [35m2024-09-02T15:58:37.233Z[39m,
|
37
35
|
tx: {
|
38
|
-
sessionID: [32m'
|
36
|
+
sessionID: [32m'co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zgjgVWiVqbKN'[39m,
|
39
37
|
txIndex: [33m0[39m
|
40
38
|
}
|
41
39
|
}
|
@@ -45,9 +43,9 @@ subscribedStream[me.id] {
|
|
45
43
|
value: [36m[Getter][39m,
|
46
44
|
ref: [36m[Getter][39m,
|
47
45
|
by: [36m[Getter][39m,
|
48
|
-
madeAt: [35m2024-
|
46
|
+
madeAt: [35m2024-09-02T15:58:37.233Z[39m,
|
49
47
|
tx: {
|
50
|
-
sessionID: [32m'
|
48
|
+
sessionID: [32m'co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zgjgVWiVqbKN'[39m,
|
51
49
|
txIndex: [33m0[39m
|
52
50
|
}
|
53
51
|
}
|
@@ -57,36 +55,38 @@ subscribedStream[me.id] {
|
|
57
55
|
value: [36m[Getter][39m,
|
58
56
|
ref: [36m[Getter][39m,
|
59
57
|
by: [36m[Getter][39m,
|
60
|
-
madeAt: [35m2024-
|
58
|
+
madeAt: [35m2024-09-02T15:58:37.233Z[39m,
|
61
59
|
tx: {
|
62
|
-
sessionID: [32m'
|
60
|
+
sessionID: [32m'co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zgjgVWiVqbKN'[39m,
|
63
61
|
txIndex: [33m0[39m
|
64
62
|
}
|
65
63
|
}
|
66
64
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
67
|
-
id: [32m'
|
65
|
+
id: [32m'co_zD7LEqeGULHGVhuTADKb4QZ8dCk'[39m,
|
68
66
|
_type: [32m'CoStream'[39m,
|
69
|
-
|
70
|
-
|
67
|
+
perSession: [90mundefined[39m,
|
68
|
+
co_zcfiWRCYawAMLoR2whhpDpKXn1t: [32m'milk'[39m,
|
69
|
+
in: { co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zgjgVWiVqbKN: [32m'milk'[39m }
|
71
70
|
}
|
72
71
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value milk
|
73
72
|
subscribedStream[me.id] {
|
74
73
|
value: [36m[Getter][39m,
|
75
74
|
ref: [36m[Getter][39m,
|
76
75
|
by: [36m[Getter][39m,
|
77
|
-
madeAt: [35m2024-
|
76
|
+
madeAt: [35m2024-09-02T15:58:37.233Z[39m,
|
78
77
|
tx: {
|
79
|
-
sessionID: [32m'
|
78
|
+
sessionID: [32m'co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zgjgVWiVqbKN'[39m,
|
80
79
|
txIndex: [33m0[39m
|
81
80
|
}
|
82
81
|
}
|
83
82
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
84
|
-
id: [32m'
|
83
|
+
id: [32m'co_zD7LEqeGULHGVhuTADKb4QZ8dCk'[39m,
|
85
84
|
_type: [32m'CoStream'[39m,
|
86
|
-
|
85
|
+
perSession: [90mundefined[39m,
|
86
|
+
co_zcfiWRCYawAMLoR2whhpDpKXn1t: [32m'bread'[39m,
|
87
87
|
in: {
|
88
|
-
|
89
|
-
|
88
|
+
co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zgjgVWiVqbKN: [32m'milk'[39m,
|
89
|
+
co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zJtVGvKSSDZS: [32m'bread'[39m
|
90
90
|
}
|
91
91
|
}
|
92
92
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value bread
|
@@ -94,49 +94,64 @@ subscribedStream[me.id] {
|
|
94
94
|
value: [36m[Getter][39m,
|
95
95
|
ref: [36m[Getter][39m,
|
96
96
|
by: [36m[Getter][39m,
|
97
|
-
madeAt: [35m2024-
|
97
|
+
madeAt: [35m2024-09-02T15:58:37.243Z[39m,
|
98
98
|
tx: {
|
99
|
-
sessionID: [32m'
|
99
|
+
sessionID: [32m'co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zJtVGvKSSDZS'[39m,
|
100
100
|
txIndex: [33m0[39m
|
101
101
|
}
|
102
102
|
}
|
103
103
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
104
|
-
id: [32m'
|
104
|
+
id: [32m'co_zJ1jXP9StL3983bfdStM2e9UgMz'[39m,
|
105
105
|
_type: [32m'CoStream'[39m,
|
106
|
-
|
107
|
-
|
106
|
+
perSession: [90mundefined[39m,
|
107
|
+
co_zcfiWRCYawAMLoR2whhpDpKXn1t: [32m'butter'[39m,
|
108
|
+
in: { co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zJtVGvKSSDZS: [32m'butter'[39m }
|
108
109
|
}
|
109
110
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value butter
|
110
111
|
subscribedStream[me.id] {
|
111
112
|
value: [36m[Getter][39m,
|
112
113
|
ref: [36m[Getter][39m,
|
113
114
|
by: [36m[Getter][39m,
|
114
|
-
madeAt: [35m2024-
|
115
|
+
madeAt: [35m2024-09-02T15:58:37.243Z[39m,
|
115
116
|
tx: {
|
116
|
-
sessionID: [32m'
|
117
|
+
sessionID: [32m'co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zJtVGvKSSDZS'[39m,
|
117
118
|
txIndex: [33m0[39m
|
118
119
|
}
|
119
120
|
}
|
120
121
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
121
|
-
id: [32m'
|
122
|
+
id: [32m'co_zJ1jXP9StL3983bfdStM2e9UgMz'[39m,
|
122
123
|
_type: [32m'CoStream'[39m,
|
123
|
-
|
124
|
-
|
124
|
+
perSession: [90mundefined[39m,
|
125
|
+
co_zcfiWRCYawAMLoR2whhpDpKXn1t: [32m'jam'[39m,
|
126
|
+
in: { co_zcfiWRCYawAMLoR2whhpDpKXn1t_session_zJtVGvKSSDZS: [32m'jam'[39m }
|
125
127
|
}
|
126
128
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value jam
|
127
129
|
|
128
|
-
✓ src/tests/coStream.test.ts (10 tests) 110ms
|
129
|
-
stdout | src/tests/coMap.test.ts > CoMap resolution > Subscription & auto-resolution
|
130
|
-
subscribedMap.nested?.twiceNested?.taste sour
|
131
|
-
subscribedMap.nested?.twiceNested?.taste sweet
|
132
|
-
subscribedMap.nested?.twiceNested?.taste sweet
|
133
|
-
subscribedMap.nested?.twiceNested?.taste salty
|
134
|
-
subscribedMap.nested?.twiceNested?.taste umami
|
135
130
|
|
136
|
-
|
131
|
+
⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯
|
132
|
+
|
133
|
+
FAIL src/tests/coMap.test.ts [ src/tests/coMap.test.ts ]
|
134
|
+
AssertionError: expected 'co_zaQaTtTxJoCWMFtuph2MUA5Y89B' to deeply equal 'co_zgryUM2xk2PqvUuyfZjQHs7umXm'
|
135
|
+
|
136
|
+
- Expected
|
137
|
+
+ Received
|
138
|
+
|
139
|
+
- co_zgryUM2xk2PqvUuyfZjQHs7umXm
|
140
|
+
+ co_zaQaTtTxJoCWMFtuph2MUA5Y89B
|
141
|
+
|
142
|
+
❯ src/tests/coMap.test.ts:762:24
|
143
|
+
760| }, me.id, me);
|
144
|
+
761|
|
145
|
+
762| expect(foundAlice).toEqual(alice.id);
|
146
|
+
| ^
|
147
|
+
763| });
|
148
|
+
764|
|
149
|
+
|
150
|
+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
|
137
151
|
|
138
|
-
Test Files
|
139
|
-
Tests
|
140
|
-
Start at
|
141
|
-
Duration
|
152
|
+
Test Files 1 failed | 4 passed (5)
|
153
|
+
Tests 24 passed (24)
|
154
|
+
Start at 16:58:36
|
155
|
+
Duration 801ms (transform 547ms, setup 0ms, collect 1.78s, tests 275ms, environment 1ms, prepare 400ms)
|
142
156
|
|
157
|
+
ELIFECYCLE Test failed. See above for more details.
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# jazz-autosub
|
2
2
|
|
3
|
+
## 0.7.35-unique.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- First sketch of API for creating and finding unique CoValues
|
8
|
+
- Updated dependencies
|
9
|
+
- cojson@0.7.35-unique.2
|
10
|
+
|
11
|
+
## 0.7.35-new-auth.0
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- Implement new top-level context creation and auth method API
|
16
|
+
|
3
17
|
## 0.7.34
|
4
18
|
|
5
19
|
### Patch Changes
|
package/dist/coValues/account.js
CHANGED
@@ -1,17 +1,30 @@
|
|
1
|
-
var _a;
|
2
1
|
import { LocalNode, cojsonInternals } from "cojson";
|
3
2
|
import { CoMap, } from "../internal.js";
|
4
3
|
import { Group, CoValueBase, MembersSym, Profile, Ref, SchemaInit, inspect, subscriptionsScopes, loadCoValue, subscribeToCoValue, ensureCoValueLoaded, subscribeToExistingCoValue, } from "../internal.js";
|
5
4
|
/** @category Identity & Permissions */
|
6
5
|
export class Account extends CoValueBase {
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
7
|
+
static _schema;
|
7
8
|
get _schema() {
|
8
9
|
return this.constructor._schema;
|
9
10
|
}
|
11
|
+
static {
|
12
|
+
this._schema = {
|
13
|
+
profile: {
|
14
|
+
ref: () => Profile,
|
15
|
+
optional: false,
|
16
|
+
},
|
17
|
+
root: {
|
18
|
+
ref: () => CoMap,
|
19
|
+
optional: true,
|
20
|
+
},
|
21
|
+
};
|
22
|
+
}
|
10
23
|
get _owner() {
|
11
24
|
return this;
|
12
25
|
}
|
13
26
|
get _loadedAs() {
|
14
|
-
return this.isMe ? this :
|
27
|
+
return this.isMe ? this : Account.fromNode(this._raw.core.node);
|
15
28
|
}
|
16
29
|
get _refs() {
|
17
30
|
const profileID = this._raw.get("profile");
|
@@ -23,6 +36,8 @@ export class Account extends CoValueBase {
|
|
23
36
|
new Ref(rootID, this._loadedAs, this._schema.root),
|
24
37
|
};
|
25
38
|
}
|
39
|
+
isMe;
|
40
|
+
sessionID;
|
26
41
|
constructor(options) {
|
27
42
|
super();
|
28
43
|
if (!("fromRaw" in options)) {
|
@@ -55,6 +70,7 @@ export class Account extends CoValueBase {
|
|
55
70
|
return loadCoValue(coValueClass, valueID, this, []);
|
56
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
57
72
|
}
|
73
|
+
/** @private */
|
58
74
|
static async create(options) {
|
59
75
|
const { node } = await LocalNode.withNewlyCreatedAccount({
|
60
76
|
...options,
|
@@ -67,22 +83,6 @@ export class Account extends CoValueBase {
|
|
67
83
|
});
|
68
84
|
return this.fromNode(node);
|
69
85
|
}
|
70
|
-
static async become(options) {
|
71
|
-
const node = await LocalNode.withLoadedAccount({
|
72
|
-
accountID: options.accountID,
|
73
|
-
accountSecret: options.accountSecret,
|
74
|
-
sessionID: options.sessionID,
|
75
|
-
peersToLoadFrom: options.peersToLoadFrom,
|
76
|
-
crypto: options.crypto,
|
77
|
-
migration: async (rawAccount, _node, creationProps) => {
|
78
|
-
const account = new this({
|
79
|
-
fromRaw: rawAccount,
|
80
|
-
});
|
81
|
-
await account.migrate?.(creationProps);
|
82
|
-
},
|
83
|
-
});
|
84
|
-
return this.fromNode(node);
|
85
|
-
}
|
86
86
|
static async createAs(as, options) {
|
87
87
|
// TODO: is there a cleaner way to do this?
|
88
88
|
const connectedPeers = cojsonInternals.connectedPeers("creatingAccount", "createdAccount", { peer1role: "server", peer2role: "client" });
|
@@ -132,19 +132,6 @@ export class Account extends CoValueBase {
|
|
132
132
|
return subscribeToExistingCoValue(this, depth, listener);
|
133
133
|
}
|
134
134
|
}
|
135
|
-
_a = Account;
|
136
|
-
(() => {
|
137
|
-
_a._schema = {
|
138
|
-
profile: {
|
139
|
-
ref: () => Profile,
|
140
|
-
optional: false,
|
141
|
-
},
|
142
|
-
root: {
|
143
|
-
ref: () => CoMap,
|
144
|
-
optional: true,
|
145
|
-
},
|
146
|
-
};
|
147
|
-
})();
|
148
135
|
export const AccountAndGroupProxyHandler = {
|
149
136
|
get(target, key, receiver) {
|
150
137
|
if (key === "profile") {
|
@@ -164,11 +151,10 @@ export const AccountAndGroupProxyHandler = {
|
|
164
151
|
}
|
165
152
|
},
|
166
153
|
set(target, key, value, receiver) {
|
167
|
-
var _b;
|
168
154
|
if ((key === "profile" || key === "root" || key === MembersSym) &&
|
169
155
|
typeof value === "object" &&
|
170
156
|
SchemaInit in value) {
|
171
|
-
|
157
|
+
target.constructor._schema ||= {};
|
172
158
|
target.constructor._schema[key] =
|
173
159
|
value[SchemaInit];
|
174
160
|
return true;
|
@@ -196,11 +182,10 @@ export const AccountAndGroupProxyHandler = {
|
|
196
182
|
}
|
197
183
|
},
|
198
184
|
defineProperty(target, key, descriptor) {
|
199
|
-
var _b;
|
200
185
|
if ((key === "profile" || key === "root" || key === MembersSym) &&
|
201
186
|
typeof descriptor.value === "object" &&
|
202
187
|
SchemaInit in descriptor.value) {
|
203
|
-
|
188
|
+
target.constructor._schema ||= {};
|
204
189
|
target.constructor._schema[key] =
|
205
190
|
descriptor.value[SchemaInit];
|
206
191
|
return true;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/coValues/account.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/co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;YACjC,OAAO,IAAI,CAAC;QAChB,CAAC;aAAM,CAAC;YACJ,OAAO,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;CACJ,CAAC;AAEF,uCAAuC;AACvC,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAKhD,OAAO,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC"}
|
package/dist/coValues/coList.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
var _a;
|
2
1
|
import { RawAccount } from "cojson";
|
3
2
|
import { Account, Group, ItemsSym, Ref, SchemaInit, co, ensureCoValueLoaded, inspect, isRefEncoded, loadCoValue, makeRefs, subscribeToCoValue, subscribeToExistingCoValue, subscriptionsScopes, } from "../internal.js";
|
4
3
|
/**
|
@@ -36,16 +35,10 @@ export class CoList extends Array {
|
|
36
35
|
* @category Declaration
|
37
36
|
*/
|
38
37
|
static Of(item) {
|
39
|
-
var _b, _c;
|
40
38
|
// TODO: cache superclass for item class
|
41
|
-
return
|
42
|
-
|
43
|
-
|
44
|
-
this[_b] = item;
|
45
|
-
}
|
46
|
-
},
|
47
|
-
_b = co.items,
|
48
|
-
_c;
|
39
|
+
return class CoListOf extends CoList {
|
40
|
+
[co.items] = item;
|
41
|
+
};
|
49
42
|
}
|
50
43
|
/**
|
51
44
|
* @ignore
|
@@ -53,6 +46,14 @@ export class CoList extends Array {
|
|
53
46
|
static of(..._args) {
|
54
47
|
throw new Error("Can't use Array.of with CoLists");
|
55
48
|
}
|
49
|
+
static {
|
50
|
+
this.prototype._type = "CoList";
|
51
|
+
}
|
52
|
+
/** @internal This is only a marker type and doesn't exist at runtime */
|
53
|
+
[ItemsSym];
|
54
|
+
/** @internal */
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
56
|
+
static _schema;
|
56
57
|
/** @internal */
|
57
58
|
get _schema() {
|
58
59
|
return this.constructor._schema;
|
@@ -208,7 +209,7 @@ export class CoList extends Array {
|
|
208
209
|
}
|
209
210
|
/** @internal */
|
210
211
|
static schema(def) {
|
211
|
-
this._schema
|
212
|
+
this._schema ||= {};
|
212
213
|
Object.assign(this._schema, def);
|
213
214
|
}
|
214
215
|
/**
|
@@ -299,10 +300,6 @@ export class CoList extends Array {
|
|
299
300
|
return casted;
|
300
301
|
}
|
301
302
|
}
|
302
|
-
_a = CoList;
|
303
|
-
(() => {
|
304
|
-
_a.prototype._type = "CoList";
|
305
|
-
})();
|
306
303
|
function toRawItems(items, itemDescriptor) {
|
307
304
|
const rawItems = itemDescriptor === "json"
|
308
305
|
? items
|
@@ -342,11 +339,10 @@ const CoListProxyHandler = {
|
|
342
339
|
}
|
343
340
|
},
|
344
341
|
set(target, key, value, receiver) {
|
345
|
-
var _b;
|
346
342
|
if (key === ItemsSym &&
|
347
343
|
typeof value === "object" &&
|
348
344
|
SchemaInit in value) {
|
349
|
-
|
345
|
+
target.constructor._schema ||= {};
|
350
346
|
target.constructor._schema[ItemsSym] =
|
351
347
|
value[SchemaInit];
|
352
348
|
return true;
|
@@ -371,12 +367,11 @@ const CoListProxyHandler = {
|
|
371
367
|
}
|
372
368
|
},
|
373
369
|
defineProperty(target, key, descriptor) {
|
374
|
-
var _b;
|
375
370
|
if (descriptor.value &&
|
376
371
|
key === ItemsSym &&
|
377
372
|
typeof descriptor.value === "object" &&
|
378
373
|
SchemaInit in descriptor.value) {
|
379
|
-
|
374
|
+
target.constructor._schema ||= {};
|
380
375
|
target.constructor._schema[ItemsSym] =
|
381
376
|
descriptor.value[SchemaInit];
|
382
377
|
return true;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"coList.js","sourceRoot":"","sources":["../../src/coValues/coList.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"coList.js","sourceRoot":"","sources":["../../src/coValues/coList.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAapC,OAAO,EACH,OAAO,EAC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AAK,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IACD,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU;QAClC,IACI,UAAU,CAAC,KAAK;YAChB,GAAG,KAAK,QAAQ;YAChB,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ;YACpC,UAAU,IAAI,UAAU,CAAC,KAAK,EAChC,CAAC;YACE,MAAM,CAAC,WAA6B,CAAC,OAAO,KAAK,EAAE,CAAC;YACpD,MAAM,CAAC,WAA6B,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACnD,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC;QAChB,CAAC;aAAM,CAAC;YACJ,OAAO,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;IACD,GAAG,CAAC,MAAM,EAAE,GAAG;QACX,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1C,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC;QACtD,CAAC;aAAM,CAAC;YACJ,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;CACJ,CAAC"}
|
package/dist/coValues/coMap.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
import { cojsonInternals, } from "cojson";
|
2
2
|
import { Account, CoValueBase, Ref, SchemaInit, inspect, makeRefs, subscriptionsScopes, ItemsSym, isRefEncoded, loadCoValue, subscribeToCoValue, ensureCoValueLoaded, subscribeToExistingCoValue, } from "../internal.js";
|
3
3
|
/**
|
4
4
|
* CoMaps are collaborative versions of plain objects, mapping string-like keys to values.
|
@@ -34,6 +34,12 @@ import { Account, CoValueBase, Ref, SchemaInit, inspect, makeRefs, subscriptions
|
|
34
34
|
* @category CoValues
|
35
35
|
* */
|
36
36
|
export class CoMap extends CoValueBase {
|
37
|
+
static {
|
38
|
+
this.prototype._type = "CoMap";
|
39
|
+
}
|
40
|
+
/** @internal */
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
42
|
+
static _schema;
|
37
43
|
/** @internal */
|
38
44
|
get _schema() {
|
39
45
|
return this.constructor._schema;
|
@@ -137,7 +143,9 @@ export class CoMap extends CoValueBase {
|
|
137
143
|
**/
|
138
144
|
static create(init, options) {
|
139
145
|
const instance = new this();
|
140
|
-
const raw = instance.rawFromInit(init, options.owner
|
146
|
+
const raw = instance.rawFromInit(init, options.owner, options.unique === undefined
|
147
|
+
? undefined
|
148
|
+
: { uniqueness: options.unique });
|
141
149
|
Object.defineProperties(instance, {
|
142
150
|
id: {
|
143
151
|
value: raw.id,
|
@@ -184,7 +192,7 @@ export class CoMap extends CoValueBase {
|
|
184
192
|
}
|
185
193
|
/** @internal */
|
186
194
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
187
|
-
rawFromInit(init, owner) {
|
195
|
+
rawFromInit(init, owner, uniqueness) {
|
188
196
|
const rawOwner = owner._raw;
|
189
197
|
const rawInit = {};
|
190
198
|
if (init)
|
@@ -208,7 +216,7 @@ export class CoMap extends CoValueBase {
|
|
208
216
|
initValue);
|
209
217
|
}
|
210
218
|
}
|
211
|
-
return rawOwner.createMap(rawInit);
|
219
|
+
return rawOwner.createMap(rawInit, null, "private", uniqueness);
|
212
220
|
}
|
213
221
|
/**
|
214
222
|
* Declare a Record-like CoMap schema, by extending `CoMap.Record(...)` and passing the value schema using `co`. Keys are always `string`.
|
@@ -229,15 +237,10 @@ export class CoMap extends CoValueBase {
|
|
229
237
|
* @category Declaration
|
230
238
|
*/
|
231
239
|
static Record(value) {
|
232
|
-
var _b;
|
233
240
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
234
|
-
class RecordLikeCoMap extends
|
235
|
-
|
236
|
-
super(...arguments);
|
237
|
-
this[_b] = value;
|
238
|
-
}
|
241
|
+
class RecordLikeCoMap extends CoMap {
|
242
|
+
[ItemsSym] = value;
|
239
243
|
}
|
240
|
-
_b = ItemsSym;
|
241
244
|
return RecordLikeCoMap;
|
242
245
|
}
|
243
246
|
/**
|
@@ -295,6 +298,18 @@ export class CoMap extends CoValueBase {
|
|
295
298
|
static subscribe(id, as, depth, listener) {
|
296
299
|
return subscribeToCoValue(this, id, as, depth, listener);
|
297
300
|
}
|
301
|
+
static findUnique(unique, ownerID, as) {
|
302
|
+
const header = {
|
303
|
+
type: "comap",
|
304
|
+
ruleset: {
|
305
|
+
type: "ownedByGroup",
|
306
|
+
group: ownerID,
|
307
|
+
},
|
308
|
+
meta: null,
|
309
|
+
uniqueness: unique,
|
310
|
+
};
|
311
|
+
return cojsonInternals.idforHeader(header, as._raw.core.crypto);
|
312
|
+
}
|
298
313
|
/**
|
299
314
|
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
300
315
|
*
|
@@ -347,10 +362,6 @@ export class CoMap extends CoValueBase {
|
|
347
362
|
return this;
|
348
363
|
}
|
349
364
|
}
|
350
|
-
_a = CoMap;
|
351
|
-
(() => {
|
352
|
-
_a.prototype._type = "CoMap";
|
353
|
-
})();
|
354
365
|
// TODO: cache handlers per descriptor for performance?
|
355
366
|
const CoMapProxyHandler = {
|
356
367
|
get(target, key, receiver) {
|
@@ -385,12 +396,11 @@ const CoMapProxyHandler = {
|
|
385
396
|
}
|
386
397
|
},
|
387
398
|
set(target, key, value, receiver) {
|
388
|
-
var _b;
|
389
399
|
if ((typeof key === "string" || ItemsSym) &&
|
390
400
|
typeof value === "object" &&
|
391
401
|
value !== null &&
|
392
402
|
SchemaInit in value) {
|
393
|
-
|
403
|
+
target.constructor._schema ||= {};
|
394
404
|
target.constructor._schema[key] =
|
395
405
|
value[SchemaInit];
|
396
406
|
return true;
|
@@ -417,11 +427,10 @@ const CoMapProxyHandler = {
|
|
417
427
|
}
|
418
428
|
},
|
419
429
|
defineProperty(target, key, attributes) {
|
420
|
-
var _b;
|
421
430
|
if ("value" in attributes &&
|
422
431
|
typeof attributes.value === "object" &&
|
423
432
|
SchemaInit in attributes.value) {
|
424
|
-
|
433
|
+
target.constructor._schema ||= {};
|
425
434
|
target.constructor._schema[key] =
|
426
435
|
attributes.value[SchemaInit];
|
427
436
|
return true;
|