jazz-tools 0.7.34 → 0.7.35-guest-auth.4
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 +41 -39
- package/CHANGELOG.md +26 -0
- package/dist/coValues/account.js +27 -36
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +19 -21
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +29 -23
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +26 -21
- 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/coValues/interfaces.js +5 -2
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/createContext.js +121 -0
- package/dist/implementation/createContext.js.map +1 -0
- package/dist/implementation/refs.js +11 -2
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +12 -8
- 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 +14 -31
- package/src/coValues/coList.ts +9 -5
- package/src/coValues/coMap.ts +44 -11
- package/src/coValues/coStream.ts +16 -7
- package/src/coValues/group.ts +2 -2
- package/src/coValues/interfaces.ts +12 -8
- package/src/implementation/createContext.ts +230 -0
- package/src/implementation/refs.ts +13 -6
- package/src/implementation/subscriptionScope.ts +28 -25
- package/src/index.ts +11 -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-guest-auth.3 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-guest-auth.3 lint
|
7
7
|
> eslint . --ext ts,tsx
|
8
8
|
|
package/.turbo/turbo-test.log
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.7.
|
2
|
+
> jazz-tools@0.7.35-unique.2 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) 64ms
|
9
9
|
stdout | unknown test
|
10
10
|
TestMap schema [90mundefined[39m
|
11
11
|
|
12
|
-
✓ src/tests/deepLoading.test.ts (3 tests)
|
13
|
-
✓ src/tests/coList.test.ts (10 tests) 80ms
|
12
|
+
✓ src/tests/deepLoading.test.ts (3 tests) 83ms
|
14
13
|
stdout | src/tests/coList.test.ts > Simple CoList operations > Mutation > splice
|
15
14
|
[ [32m'bread'[39m, [32m'onion'[39m ] [33m0[39m
|
16
15
|
[ [32m'bread'[39m, [32m'salt'[39m, [32m'onion'[39m ] [33m1[39m
|
@@ -23,19 +22,15 @@ subscribedList?.[0]?.[0]?.[0] x
|
|
23
22
|
subscribedList?.[0]?.[0]?.[0] y
|
24
23
|
subscribedList?.[0]?.[0]?.[0] w
|
25
24
|
|
26
|
-
|
27
|
-
subscribedMap.nested?.twiceNested?.taste [90mundefined[39m
|
28
|
-
subscribedMap.nested?.twiceNested?.taste [90mundefined[39m
|
29
|
-
subscribedMap.nested?.twiceNested?.taste sour
|
30
|
-
|
25
|
+
✓ src/tests/coList.test.ts (10 tests) 190ms
|
31
26
|
stdout | src/tests/coStream.test.ts > CoStream resolution > Subscription & auto-resolution
|
32
27
|
subscribedStream[me.id] {
|
33
28
|
value: [36m[Getter][39m,
|
34
29
|
ref: [36m[Getter][39m,
|
35
30
|
by: [36m[Getter][39m,
|
36
|
-
madeAt: [35m2024-
|
31
|
+
madeAt: [35m2024-09-05T17:35:38.414Z[39m,
|
37
32
|
tx: {
|
38
|
-
sessionID: [32m'
|
33
|
+
sessionID: [32m'co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_ziAMdGVstAxF'[39m,
|
39
34
|
txIndex: [33m0[39m
|
40
35
|
}
|
41
36
|
}
|
@@ -45,9 +40,9 @@ subscribedStream[me.id] {
|
|
45
40
|
value: [36m[Getter][39m,
|
46
41
|
ref: [36m[Getter][39m,
|
47
42
|
by: [36m[Getter][39m,
|
48
|
-
madeAt: [35m2024-
|
43
|
+
madeAt: [35m2024-09-05T17:35:38.414Z[39m,
|
49
44
|
tx: {
|
50
|
-
sessionID: [32m'
|
45
|
+
sessionID: [32m'co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_ziAMdGVstAxF'[39m,
|
51
46
|
txIndex: [33m0[39m
|
52
47
|
}
|
53
48
|
}
|
@@ -57,36 +52,38 @@ subscribedStream[me.id] {
|
|
57
52
|
value: [36m[Getter][39m,
|
58
53
|
ref: [36m[Getter][39m,
|
59
54
|
by: [36m[Getter][39m,
|
60
|
-
madeAt: [35m2024-
|
55
|
+
madeAt: [35m2024-09-05T17:35:38.414Z[39m,
|
61
56
|
tx: {
|
62
|
-
sessionID: [32m'
|
57
|
+
sessionID: [32m'co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_ziAMdGVstAxF'[39m,
|
63
58
|
txIndex: [33m0[39m
|
64
59
|
}
|
65
60
|
}
|
66
61
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
67
|
-
id: [32m'
|
62
|
+
id: [32m'co_zHELVqRmAN6YuGDpKqVrSXJ5qe1'[39m,
|
68
63
|
_type: [32m'CoStream'[39m,
|
69
|
-
|
70
|
-
|
64
|
+
perSession: [90mundefined[39m,
|
65
|
+
co_zURWEpvoH1e35FGHVxadgXKU8Ri: [32m'milk'[39m,
|
66
|
+
in: { co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_ziAMdGVstAxF: [32m'milk'[39m }
|
71
67
|
}
|
72
68
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value milk
|
73
69
|
subscribedStream[me.id] {
|
74
70
|
value: [36m[Getter][39m,
|
75
71
|
ref: [36m[Getter][39m,
|
76
72
|
by: [36m[Getter][39m,
|
77
|
-
madeAt: [35m2024-
|
73
|
+
madeAt: [35m2024-09-05T17:35:38.414Z[39m,
|
78
74
|
tx: {
|
79
|
-
sessionID: [32m'
|
75
|
+
sessionID: [32m'co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_ziAMdGVstAxF'[39m,
|
80
76
|
txIndex: [33m0[39m
|
81
77
|
}
|
82
78
|
}
|
83
79
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
84
|
-
id: [32m'
|
80
|
+
id: [32m'co_zHELVqRmAN6YuGDpKqVrSXJ5qe1'[39m,
|
85
81
|
_type: [32m'CoStream'[39m,
|
86
|
-
|
82
|
+
perSession: [90mundefined[39m,
|
83
|
+
co_zURWEpvoH1e35FGHVxadgXKU8Ri: [32m'bread'[39m,
|
87
84
|
in: {
|
88
|
-
|
89
|
-
|
85
|
+
co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_ziAMdGVstAxF: [32m'milk'[39m,
|
86
|
+
co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_zgik2JjD86Qa: [32m'bread'[39m
|
90
87
|
}
|
91
88
|
}
|
92
89
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value bread
|
@@ -94,49 +91,54 @@ subscribedStream[me.id] {
|
|
94
91
|
value: [36m[Getter][39m,
|
95
92
|
ref: [36m[Getter][39m,
|
96
93
|
by: [36m[Getter][39m,
|
97
|
-
madeAt: [35m2024-
|
94
|
+
madeAt: [35m2024-09-05T17:35:38.424Z[39m,
|
98
95
|
tx: {
|
99
|
-
sessionID: [32m'
|
96
|
+
sessionID: [32m'co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_zgik2JjD86Qa'[39m,
|
100
97
|
txIndex: [33m0[39m
|
101
98
|
}
|
102
99
|
}
|
103
100
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
104
|
-
id: [32m'
|
101
|
+
id: [32m'co_zJmdvJY15XJkWF3n3rwPgGfebxa'[39m,
|
105
102
|
_type: [32m'CoStream'[39m,
|
106
|
-
|
107
|
-
|
103
|
+
perSession: [90mundefined[39m,
|
104
|
+
co_zURWEpvoH1e35FGHVxadgXKU8Ri: [32m'butter'[39m,
|
105
|
+
in: { co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_zgik2JjD86Qa: [32m'butter'[39m }
|
108
106
|
}
|
109
107
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value butter
|
110
108
|
subscribedStream[me.id] {
|
111
109
|
value: [36m[Getter][39m,
|
112
110
|
ref: [36m[Getter][39m,
|
113
111
|
by: [36m[Getter][39m,
|
114
|
-
madeAt: [35m2024-
|
112
|
+
madeAt: [35m2024-09-05T17:35:38.424Z[39m,
|
115
113
|
tx: {
|
116
|
-
sessionID: [32m'
|
114
|
+
sessionID: [32m'co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_zgik2JjD86Qa'[39m,
|
117
115
|
txIndex: [33m0[39m
|
118
116
|
}
|
119
117
|
}
|
120
118
|
subscribedStream[me.id]?.value?.[me.id]?.value {
|
121
|
-
id: [32m'
|
119
|
+
id: [32m'co_zJmdvJY15XJkWF3n3rwPgGfebxa'[39m,
|
122
120
|
_type: [32m'CoStream'[39m,
|
123
|
-
|
124
|
-
|
121
|
+
perSession: [90mundefined[39m,
|
122
|
+
co_zURWEpvoH1e35FGHVxadgXKU8Ri: [32m'jam'[39m,
|
123
|
+
in: { co_zURWEpvoH1e35FGHVxadgXKU8Ri_session_zgik2JjD86Qa: [32m'jam'[39m }
|
125
124
|
}
|
126
125
|
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value jam
|
127
126
|
|
128
|
-
✓ src/tests/coStream.test.ts (10 tests)
|
127
|
+
✓ src/tests/coStream.test.ts (10 tests) 205ms
|
129
128
|
stdout | src/tests/coMap.test.ts > CoMap resolution > Subscription & auto-resolution
|
129
|
+
subscribedMap.nested?.twiceNested?.taste [90mundefined[39m
|
130
|
+
subscribedMap.nested?.twiceNested?.taste [90mundefined[39m
|
131
|
+
subscribedMap.nested?.twiceNested?.taste sour
|
130
132
|
subscribedMap.nested?.twiceNested?.taste sour
|
131
133
|
subscribedMap.nested?.twiceNested?.taste sweet
|
132
134
|
subscribedMap.nested?.twiceNested?.taste sweet
|
133
135
|
subscribedMap.nested?.twiceNested?.taste salty
|
134
136
|
subscribedMap.nested?.twiceNested?.taste umami
|
135
137
|
|
136
|
-
✓ src/tests/coMap.test.ts (
|
138
|
+
✓ src/tests/coMap.test.ts (20 tests) 257ms
|
137
139
|
|
138
140
|
Test Files 5 passed (5)
|
139
|
-
Tests
|
140
|
-
Start at
|
141
|
-
Duration
|
141
|
+
Tests 44 passed (44)
|
142
|
+
Start at 18:35:37
|
143
|
+
Duration 929ms (transform 419ms, setup 0ms, collect 2.29s, tests 799ms, environment 0ms, prepare 298ms)
|
142
144
|
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# jazz-autosub
|
2
2
|
|
3
|
+
## 0.7.35-guest-auth.4
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Make anonymous auth work better
|
8
|
+
|
9
|
+
## 0.7.35-guest-auth.3
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- Implement guest auth without account
|
14
|
+
|
15
|
+
## 0.7.35-unique.2
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- First sketch of API for creating and finding unique CoValues
|
20
|
+
- Updated dependencies
|
21
|
+
- cojson@0.7.35-unique.2
|
22
|
+
|
23
|
+
## 0.7.35-new-auth.0
|
24
|
+
|
25
|
+
### Patch Changes
|
26
|
+
|
27
|
+
- Implement new top-level context creation and auth method API
|
28
|
+
|
3
29
|
## 0.7.34
|
4
30
|
|
5
31
|
### Patch Changes
|
package/dist/coValues/account.js
CHANGED
@@ -1,17 +1,36 @@
|
|
1
|
-
var _a;
|
2
1
|
import { LocalNode, cojsonInternals } from "cojson";
|
3
|
-
import {
|
2
|
+
import { RawAccount, } from "cojson";
|
3
|
+
import { CoMap, AnonymousJazzAgent, } from "../internal.js";
|
4
4
|
import { Group, CoValueBase, MembersSym, Profile, Ref, SchemaInit, inspect, subscriptionsScopes, loadCoValue, subscribeToCoValue, ensureCoValueLoaded, subscribeToExistingCoValue, } from "../internal.js";
|
5
5
|
/** @category Identity & Permissions */
|
6
6
|
export class Account extends CoValueBase {
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8
|
+
static _schema;
|
7
9
|
get _schema() {
|
8
10
|
return this.constructor._schema;
|
9
11
|
}
|
12
|
+
static {
|
13
|
+
this._schema = {
|
14
|
+
profile: {
|
15
|
+
ref: () => Profile,
|
16
|
+
optional: false,
|
17
|
+
},
|
18
|
+
root: {
|
19
|
+
ref: () => CoMap,
|
20
|
+
optional: true,
|
21
|
+
},
|
22
|
+
};
|
23
|
+
}
|
10
24
|
get _owner() {
|
11
25
|
return this;
|
12
26
|
}
|
13
27
|
get _loadedAs() {
|
14
|
-
|
28
|
+
if (this.isMe)
|
29
|
+
return this;
|
30
|
+
if (this._raw.core.node.account instanceof RawAccount) {
|
31
|
+
return Account.fromRaw(this._raw.core.node.account);
|
32
|
+
}
|
33
|
+
return new AnonymousJazzAgent(this._raw.core.node);
|
15
34
|
}
|
16
35
|
get _refs() {
|
17
36
|
const profileID = this._raw.get("profile");
|
@@ -23,6 +42,8 @@ export class Account extends CoValueBase {
|
|
23
42
|
new Ref(rootID, this._loadedAs, this._schema.root),
|
24
43
|
};
|
25
44
|
}
|
45
|
+
isMe;
|
46
|
+
sessionID;
|
26
47
|
constructor(options) {
|
27
48
|
super();
|
28
49
|
if (!("fromRaw" in options)) {
|
@@ -55,6 +76,7 @@ export class Account extends CoValueBase {
|
|
55
76
|
return loadCoValue(coValueClass, valueID, this, []);
|
56
77
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
57
78
|
}
|
79
|
+
/** @private */
|
58
80
|
static async create(options) {
|
59
81
|
const { node } = await LocalNode.withNewlyCreatedAccount({
|
60
82
|
...options,
|
@@ -67,22 +89,6 @@ export class Account extends CoValueBase {
|
|
67
89
|
});
|
68
90
|
return this.fromNode(node);
|
69
91
|
}
|
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
92
|
static async createAs(as, options) {
|
87
93
|
// TODO: is there a cleaner way to do this?
|
88
94
|
const connectedPeers = cojsonInternals.connectedPeers("creatingAccount", "createdAccount", { peer1role: "server", peer2role: "client" });
|
@@ -132,19 +138,6 @@ export class Account extends CoValueBase {
|
|
132
138
|
return subscribeToExistingCoValue(this, depth, listener);
|
133
139
|
}
|
134
140
|
}
|
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
141
|
export const AccountAndGroupProxyHandler = {
|
149
142
|
get(target, key, receiver) {
|
150
143
|
if (key === "profile") {
|
@@ -164,11 +157,10 @@ export const AccountAndGroupProxyHandler = {
|
|
164
157
|
}
|
165
158
|
},
|
166
159
|
set(target, key, value, receiver) {
|
167
|
-
var _b;
|
168
160
|
if ((key === "profile" || key === "root" || key === MembersSym) &&
|
169
161
|
typeof value === "object" &&
|
170
162
|
SchemaInit in value) {
|
171
|
-
|
163
|
+
target.constructor._schema ||= {};
|
172
164
|
target.constructor._schema[key] =
|
173
165
|
value[SchemaInit];
|
174
166
|
return true;
|
@@ -196,11 +188,10 @@ export const AccountAndGroupProxyHandler = {
|
|
196
188
|
}
|
197
189
|
},
|
198
190
|
defineProperty(target, key, descriptor) {
|
199
|
-
var _b;
|
200
191
|
if ((key === "profile" || key === "root" || key === MembersSym) &&
|
201
192
|
typeof descriptor.value === "object" &&
|
202
193
|
SchemaInit in descriptor.value) {
|
203
|
-
|
194
|
+
target.constructor._schema ||= {};
|
204
195
|
target.constructor._schema[key] =
|
205
196
|
descriptor.value[SchemaInit];
|
206
197
|
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/coValues/account.ts"],"names":[],"mappings":"AAA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AC,KAAK,KAAK,QAAQ;YACpC,UAAU,IAAI,UAAU,CAAC,KAAK,EAChC,CAAC;YACE,MAAM,CAAC,WAA4B,CAAC,OAAO,KAAK,EAAE,CAAC;YACnD,MAAM,CAAC,WAA4B,CAAC,OAAO,CAAC,GAAG,CAAC;gBAC7C,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;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,6 +1,5 @@
|
|
1
|
-
var _a;
|
2
1
|
import { RawAccount } from "cojson";
|
3
|
-
import { Account, Group, ItemsSym, Ref, SchemaInit, co, ensureCoValueLoaded, inspect, isRefEncoded, loadCoValue, makeRefs, subscribeToCoValue, subscribeToExistingCoValue, subscriptionsScopes, } from "../internal.js";
|
2
|
+
import { Account, AnonymousJazzAgent, Group, ItemsSym, Ref, SchemaInit, co, ensureCoValueLoaded, inspect, isRefEncoded, loadCoValue, makeRefs, subscribeToCoValue, subscribeToExistingCoValue, subscriptionsScopes, } from "../internal.js";
|
4
3
|
/**
|
5
4
|
* CoLists are collaborative versions of plain arrays.
|
6
5
|
*
|
@@ -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;
|
@@ -86,7 +87,10 @@ export class CoList extends Array {
|
|
86
87
|
throw new Error("Not implemented");
|
87
88
|
}
|
88
89
|
get _loadedAs() {
|
89
|
-
|
90
|
+
if (this._raw.core.node.account instanceof RawAccount) {
|
91
|
+
return Account.fromRaw(this._raw.core.node.account);
|
92
|
+
}
|
93
|
+
return new AnonymousJazzAgent(this._raw.core.node);
|
90
94
|
}
|
91
95
|
static get [Symbol.species]() {
|
92
96
|
return Array;
|
@@ -208,7 +212,7 @@ export class CoList extends Array {
|
|
208
212
|
}
|
209
213
|
/** @internal */
|
210
214
|
static schema(def) {
|
211
|
-
this._schema
|
215
|
+
this._schema ||= {};
|
212
216
|
Object.assign(this._schema, def);
|
213
217
|
}
|
214
218
|
/**
|
@@ -299,10 +303,6 @@ export class CoList extends Array {
|
|
299
303
|
return casted;
|
300
304
|
}
|
301
305
|
}
|
302
|
-
_a = CoList;
|
303
|
-
(() => {
|
304
|
-
_a.prototype._type = "CoList";
|
305
|
-
})();
|
306
306
|
function toRawItems(items, itemDescriptor) {
|
307
307
|
const rawItems = itemDescriptor === "json"
|
308
308
|
? items
|
@@ -342,11 +342,10 @@ const CoListProxyHandler = {
|
|
342
342
|
}
|
343
343
|
},
|
344
344
|
set(target, key, value, receiver) {
|
345
|
-
var _b;
|
346
345
|
if (key === ItemsSym &&
|
347
346
|
typeof value === "object" &&
|
348
347
|
SchemaInit in value) {
|
349
|
-
|
348
|
+
target.constructor._schema ||= {};
|
350
349
|
target.constructor._schema[ItemsSym] =
|
351
350
|
value[SchemaInit];
|
352
351
|
return true;
|
@@ -371,12 +370,11 @@ const CoListProxyHandler = {
|
|
371
370
|
}
|
372
371
|
},
|
373
372
|
defineProperty(target, key, descriptor) {
|
374
|
-
var _b;
|
375
373
|
if (descriptor.value &&
|
376
374
|
key === ItemsSym &&
|
377
375
|
typeof descriptor.value === "object" &&
|
378
376
|
SchemaInit in descriptor.value) {
|
379
|
-
|
377
|
+
target.constructor._schema ||= {};
|
380
378
|
target.constructor._schema[ItemsSym] =
|
381
379
|
descriptor.value[SchemaInit];
|
382
380
|
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,EACP,kBAAkB,EAClB,KAAK,EACL,QAAQ,EACR,GAAG,EACH,UAAU,EACV,EAAE,EACF,mBAAmB,EACnB,OAAO,EACP,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,0BAA0B,EAC1B,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;;;;;;;GAgBG;AACH,8DAA8D;AAC9D,MAAM,OAAO,MAAmB,SAAQ,KAAW;IAC/C;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,EAAE,CAAO,IAAU;QACtB,wCAAwC;QACxC,OAAO,MAAM,QAAS,SAAQ,MAAY;YACtC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;SACrB,CAAC;IACN,CAAC;IAED;;wDAEoD;IACpD,MAAM,CAAC,EAAE,CAAC,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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;
|
@@ -93,10 +99,6 @@ export class CoMap extends CoValueBase {
|
|
93
99
|
});
|
94
100
|
}
|
95
101
|
/** @internal */
|
96
|
-
get _loadedAs() {
|
97
|
-
return Account.fromNode(this._raw.core.node);
|
98
|
-
}
|
99
|
-
/** @internal */
|
100
102
|
constructor(
|
101
103
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
102
104
|
options) {
|
@@ -137,7 +139,9 @@ export class CoMap extends CoValueBase {
|
|
137
139
|
**/
|
138
140
|
static create(init, options) {
|
139
141
|
const instance = new this();
|
140
|
-
const raw = instance.rawFromInit(init, options.owner
|
142
|
+
const raw = instance.rawFromInit(init, options.owner, options.unique === undefined
|
143
|
+
? undefined
|
144
|
+
: { uniqueness: options.unique });
|
141
145
|
Object.defineProperties(instance, {
|
142
146
|
id: {
|
143
147
|
value: raw.id,
|
@@ -184,7 +188,7 @@ export class CoMap extends CoValueBase {
|
|
184
188
|
}
|
185
189
|
/** @internal */
|
186
190
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
187
|
-
rawFromInit(init, owner) {
|
191
|
+
rawFromInit(init, owner, uniqueness) {
|
188
192
|
const rawOwner = owner._raw;
|
189
193
|
const rawInit = {};
|
190
194
|
if (init)
|
@@ -208,7 +212,7 @@ export class CoMap extends CoValueBase {
|
|
208
212
|
initValue);
|
209
213
|
}
|
210
214
|
}
|
211
|
-
return rawOwner.createMap(rawInit);
|
215
|
+
return rawOwner.createMap(rawInit, null, "private", uniqueness);
|
212
216
|
}
|
213
217
|
/**
|
214
218
|
* Declare a Record-like CoMap schema, by extending `CoMap.Record(...)` and passing the value schema using `co`. Keys are always `string`.
|
@@ -229,15 +233,10 @@ export class CoMap extends CoValueBase {
|
|
229
233
|
* @category Declaration
|
230
234
|
*/
|
231
235
|
static Record(value) {
|
232
|
-
var _b;
|
233
236
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
234
|
-
class RecordLikeCoMap extends
|
235
|
-
|
236
|
-
super(...arguments);
|
237
|
-
this[_b] = value;
|
238
|
-
}
|
237
|
+
class RecordLikeCoMap extends CoMap {
|
238
|
+
[ItemsSym] = value;
|
239
239
|
}
|
240
|
-
_b = ItemsSym;
|
241
240
|
return RecordLikeCoMap;
|
242
241
|
}
|
243
242
|
/**
|
@@ -295,6 +294,19 @@ export class CoMap extends CoValueBase {
|
|
295
294
|
static subscribe(id, as, depth, listener) {
|
296
295
|
return subscribeToCoValue(this, id, as, depth, listener);
|
297
296
|
}
|
297
|
+
static findUnique(unique, ownerID, as) {
|
298
|
+
const header = {
|
299
|
+
type: "comap",
|
300
|
+
ruleset: {
|
301
|
+
type: "ownedByGroup",
|
302
|
+
group: ownerID,
|
303
|
+
},
|
304
|
+
meta: null,
|
305
|
+
uniqueness: unique,
|
306
|
+
};
|
307
|
+
const crypto = as._type === "Anonymous" ? as.node.crypto : as._raw.core.crypto;
|
308
|
+
return cojsonInternals.idforHeader(header, crypto);
|
309
|
+
}
|
298
310
|
/**
|
299
311
|
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
300
312
|
*
|
@@ -347,10 +359,6 @@ export class CoMap extends CoValueBase {
|
|
347
359
|
return this;
|
348
360
|
}
|
349
361
|
}
|
350
|
-
_a = CoMap;
|
351
|
-
(() => {
|
352
|
-
_a.prototype._type = "CoMap";
|
353
|
-
})();
|
354
362
|
// TODO: cache handlers per descriptor for performance?
|
355
363
|
const CoMapProxyHandler = {
|
356
364
|
get(target, key, receiver) {
|
@@ -385,12 +393,11 @@ const CoMapProxyHandler = {
|
|
385
393
|
}
|
386
394
|
},
|
387
395
|
set(target, key, value, receiver) {
|
388
|
-
var _b;
|
389
396
|
if ((typeof key === "string" || ItemsSym) &&
|
390
397
|
typeof value === "object" &&
|
391
398
|
value !== null &&
|
392
399
|
SchemaInit in value) {
|
393
|
-
|
400
|
+
target.constructor._schema ||= {};
|
394
401
|
target.constructor._schema[key] =
|
395
402
|
value[SchemaInit];
|
396
403
|
return true;
|
@@ -417,11 +424,10 @@ const CoMapProxyHandler = {
|
|
417
424
|
}
|
418
425
|
},
|
419
426
|
defineProperty(target, key, attributes) {
|
420
|
-
var _b;
|
421
427
|
if ("value" in attributes &&
|
422
428
|
typeof attributes.value === "object" &&
|
423
429
|
SchemaInit in attributes.value) {
|
424
|
-
|
430
|
+
target.constructor._schema ||= {};
|
425
431
|
target.constructor._schema[key] =
|
426
432
|
attributes.value[SchemaInit];
|
427
433
|
return true;
|