jazz-tools 0.7.0-alpha.1 → 0.7.0-alpha.12
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +79 -9
- package/CHANGELOG.md +74 -0
- package/dist/coValues/account.js +63 -30
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +143 -93
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +145 -159
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +140 -66
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +9 -11
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +14 -39
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +6 -3
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/refs.js +13 -10
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +36 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/index.js +4 -19
- package/dist/index.js.map +1 -1
- package/dist/tests/coList.test.js +5 -9
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +107 -61
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +51 -56
- package/dist/tests/coStream.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +94 -64
- package/src/coValues/coList.ts +186 -115
- package/src/coValues/coMap.ts +226 -260
- package/src/coValues/coStream.ts +190 -111
- package/src/coValues/extensions/imageDef.ts +12 -16
- package/src/coValues/group.ts +27 -75
- package/src/coValues/interfaces.ts +10 -8
- package/src/implementation/refs.ts +43 -18
- package/src/implementation/schema.ts +86 -31
- package/src/index.ts +10 -25
- package/src/tests/coList.test.ts +5 -9
- package/src/tests/coMap.test.ts +86 -74
- package/src/tests/coStream.test.ts +66 -71
package/.turbo/turbo-build.log
CHANGED
@@ -1,24 +1,94 @@
|
|
1
1
|
|
2
|
-
> jazz-
|
2
|
+
> jazz-tools@0.7.0-alpha.11 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-
|
6
|
+
> jazz-tools@0.7.0-alpha.11 lint
|
7
7
|
> eslint src/**/*.ts
|
8
8
|
|
9
9
|
|
10
|
-
/Users/anselm/jazz/jazz/packages/jazz-
|
11
|
-
|
10
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/coValues/account.ts
|
11
|
+
48:21 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
12
|
+
59:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
13
|
+
97:22 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
14
|
+
106:22 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
15
|
+
180:11 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
16
|
+
239:24 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
17
|
+
257:67 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
18
|
+
260:67 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
19
|
+
311:12 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
20
|
+
317:29 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
21
|
+
317:39 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
22
|
+
|
23
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/coValues/coList.ts
|
24
|
+
31:62 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
25
|
+
35:56 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
26
|
+
57:21 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
27
|
+
89:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
28
|
+
236:71 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
29
|
+
241:75 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
30
|
+
274:31 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
31
|
+
|
32
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/coValues/coMap.ts
|
33
|
+
27:50 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
34
|
+
27:68 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
35
|
+
55:20 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
36
|
+
56:18 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
37
|
+
92:21 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
38
|
+
116:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
39
|
+
212:44 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
40
|
+
230:56 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
41
|
+
256:38 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
42
|
+
283:42 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
43
|
+
|
44
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/coValues/coStream.ts
|
45
|
+
43:66 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
46
|
+
47:58 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
47
|
+
64:21 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
48
|
+
164:31 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
49
|
+
|
50
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/coValues/group.ts
|
51
|
+
33:21 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
52
|
+
48:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
53
|
+
79:22 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
54
|
+
86:22 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
55
|
+
91:23 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
56
|
+
|
57
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/coValues/interfaces.ts
|
58
|
+
15:19 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
59
|
+
18:71 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
60
|
+
57:62 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
61
|
+
73:15 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
62
|
+
75:18 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
63
|
+
78:34 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
64
|
+
81:39 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
65
|
+
105:27 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
66
|
+
207:24 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
67
|
+
|
68
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/implementation/schema.ts
|
69
|
+
33:61 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
70
|
+
36:61 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
71
|
+
39:71 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
72
|
+
44:58 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
73
|
+
70:68 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
74
|
+
79:5 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
75
|
+
80:5 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
76
|
+
84:17 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
77
|
+
85:17 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
78
|
+
119:11 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
79
|
+
124:7 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
80
|
+
|
81
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/implementation/subscriptionScope.ts
|
82
|
+
6:23 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
12
83
|
|
13
|
-
/Users/anselm/jazz/jazz/packages/jazz-
|
84
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/tests/coList.test.ts
|
14
85
|
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
|
15
86
|
|
16
|
-
/Users/anselm/jazz/jazz/packages/jazz-
|
87
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/tests/coMap.test.ts
|
17
88
|
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
|
18
89
|
|
19
|
-
/Users/anselm/jazz/jazz/packages/jazz-
|
90
|
+
/Users/anselm/jazz/jazz/packages/jazz-tools/src/tests/coStream.test.ts
|
20
91
|
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
|
21
92
|
|
22
|
-
✖
|
93
|
+
✖ 61 problems (0 errors, 61 warnings)
|
23
94
|
|
24
|
-
ELIFECYCLE Command failed.
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,79 @@
|
|
1
1
|
# jazz-autosub
|
2
2
|
|
3
|
+
## 0.7.0-alpha.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Fix variance of ID.\_\_type
|
8
|
+
|
9
|
+
## 0.7.0-alpha.11
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- Support stricter TS lint rules
|
14
|
+
- Updated dependencies
|
15
|
+
- cojson@0.7.0-alpha.11
|
16
|
+
|
17
|
+
## 0.7.0-alpha.10
|
18
|
+
|
19
|
+
### Patch Changes
|
20
|
+
|
21
|
+
- Clean up API more & re-add jazz-nodejs
|
22
|
+
- Updated dependencies
|
23
|
+
- cojson@0.7.0-alpha.10
|
24
|
+
|
25
|
+
## 0.7.0-alpha.9
|
26
|
+
|
27
|
+
### Patch Changes
|
28
|
+
|
29
|
+
- Even friendlier for subclassing CoMap
|
30
|
+
|
31
|
+
## 0.7.0-alpha.8
|
32
|
+
|
33
|
+
### Patch Changes
|
34
|
+
|
35
|
+
- More subclass-friendly types in CoMap
|
36
|
+
|
37
|
+
## 0.7.0-alpha.7
|
38
|
+
|
39
|
+
### Patch Changes
|
40
|
+
|
41
|
+
- Consistent proxy based API
|
42
|
+
- Updated dependencies
|
43
|
+
- cojson@0.7.0-alpha.7
|
44
|
+
|
45
|
+
## 0.7.0-alpha.6
|
46
|
+
|
47
|
+
### Patch Changes
|
48
|
+
|
49
|
+
- CoMap fix
|
50
|
+
|
51
|
+
## 0.7.0-alpha.5
|
52
|
+
|
53
|
+
### Patch Changes
|
54
|
+
|
55
|
+
- Refactoring
|
56
|
+
- Updated dependencies
|
57
|
+
- cojson@0.7.0-alpha.5
|
58
|
+
|
59
|
+
## 0.7.0-alpha.4
|
60
|
+
|
61
|
+
### Patch Changes
|
62
|
+
|
63
|
+
- Make refs on list more precise
|
64
|
+
|
65
|
+
## 0.7.0-alpha.3
|
66
|
+
|
67
|
+
### Patch Changes
|
68
|
+
|
69
|
+
- Make refs type more precise
|
70
|
+
|
71
|
+
## 0.7.0-alpha.2
|
72
|
+
|
73
|
+
### Patch Changes
|
74
|
+
|
75
|
+
- Get rid of Co namespace
|
76
|
+
|
3
77
|
## 0.7.0-alpha.1
|
4
78
|
|
5
79
|
### Patch Changes
|
package/dist/coValues/account.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
var _a;
|
2
2
|
import { LocalNode } from "cojson";
|
3
3
|
import { Context } from "effect";
|
4
|
-
import { CoValueBase, Profile,
|
4
|
+
import { CoValueBase, Profile, Ref, SchemaInit, inspect, subscriptionsScopes, } from "../internal.js";
|
5
5
|
export class Account extends CoValueBase {
|
6
6
|
get _schema() {
|
7
7
|
return this.constructor._schema;
|
@@ -18,12 +18,13 @@ export class Account extends CoValueBase {
|
|
18
18
|
const profileID = this._raw.get("profile");
|
19
19
|
const rootID = this._raw.get("root");
|
20
20
|
return {
|
21
|
-
profile: profileID &&
|
21
|
+
profile: profileID &&
|
22
|
+
new Ref(profileID, this._loadedAs, this._schema.profile),
|
22
23
|
root: rootID &&
|
23
|
-
new
|
24
|
+
new Ref(rootID, this._loadedAs, this._schema.root),
|
24
25
|
};
|
25
26
|
}
|
26
|
-
constructor(
|
27
|
+
constructor(_init, options) {
|
27
28
|
super();
|
28
29
|
this.acceptInvite = (async (valueID, inviteSecret, coValueClass) => {
|
29
30
|
if (!this.isMe) {
|
@@ -44,33 +45,12 @@ export class Account extends CoValueBase {
|
|
44
45
|
enumerable: false,
|
45
46
|
},
|
46
47
|
_raw: { value: options.fromRaw, enumerable: false },
|
47
|
-
profile: {
|
48
|
-
get: () => {
|
49
|
-
const ref = this._refs.profile;
|
50
|
-
return ref ? ref.accessFrom(this) : undefined;
|
51
|
-
},
|
52
|
-
set: (value) => {
|
53
|
-
if (value) {
|
54
|
-
this._raw.set("profile", value.id);
|
55
|
-
}
|
56
|
-
},
|
57
|
-
},
|
58
|
-
root: {
|
59
|
-
get: () => {
|
60
|
-
const ref = this._refs.root;
|
61
|
-
return ref ? ref.accessFrom(this) : undefined;
|
62
|
-
},
|
63
|
-
set: (value) => {
|
64
|
-
if (value) {
|
65
|
-
this._raw.set("root", value.id);
|
66
|
-
}
|
67
|
-
},
|
68
|
-
},
|
69
48
|
});
|
70
49
|
if (this.isMe) {
|
71
50
|
this.sessionID =
|
72
51
|
options.fromRaw.core.node.currentSessionID;
|
73
52
|
}
|
53
|
+
return new Proxy(this, AccountAndGroupProxyHandler);
|
74
54
|
}
|
75
55
|
myRole() {
|
76
56
|
if (this.isMe) {
|
@@ -118,10 +98,6 @@ export class Account extends CoValueBase {
|
|
118
98
|
[inspect]() {
|
119
99
|
return this.toJSON();
|
120
100
|
}
|
121
|
-
static encoding(fields) {
|
122
|
-
this._schema || (this._schema = {});
|
123
|
-
Object.assign(this._schema, fields);
|
124
|
-
}
|
125
101
|
}
|
126
102
|
_a = Account;
|
127
103
|
(() => {
|
@@ -130,6 +106,63 @@ _a = Account;
|
|
130
106
|
root: { json: true },
|
131
107
|
};
|
132
108
|
})();
|
109
|
+
export const AccountAndGroupProxyHandler = {
|
110
|
+
get(target, key, receiver) {
|
111
|
+
if (key === "profile") {
|
112
|
+
const ref = target._refs.profile;
|
113
|
+
return ref ? ref.accessFrom(receiver) : undefined;
|
114
|
+
}
|
115
|
+
else if (key === "root") {
|
116
|
+
const ref = target._refs.root;
|
117
|
+
return ref ? ref.accessFrom(receiver) : undefined;
|
118
|
+
}
|
119
|
+
else {
|
120
|
+
return Reflect.get(target, key, receiver);
|
121
|
+
}
|
122
|
+
},
|
123
|
+
set(target, key, value, receiver) {
|
124
|
+
var _b;
|
125
|
+
if ((key === "profile" || key === "root") &&
|
126
|
+
typeof value === "object" &&
|
127
|
+
SchemaInit in value) {
|
128
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
129
|
+
target.constructor._schema[key] =
|
130
|
+
value[SchemaInit];
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
else if (key === "profile") {
|
134
|
+
if (value) {
|
135
|
+
target._raw.set("profile", value.id);
|
136
|
+
}
|
137
|
+
subscriptionsScopes.get(receiver)?.onRefAccessedOrSet(value.id);
|
138
|
+
return true;
|
139
|
+
}
|
140
|
+
else if (key === "root") {
|
141
|
+
if (value) {
|
142
|
+
target._raw.set("root", value.id);
|
143
|
+
}
|
144
|
+
subscriptionsScopes.get(receiver)?.onRefAccessedOrSet(value.id);
|
145
|
+
return true;
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
return Reflect.set(target, key, value, receiver);
|
149
|
+
}
|
150
|
+
},
|
151
|
+
defineProperty(target, key, descriptor) {
|
152
|
+
var _b;
|
153
|
+
if ((key === "profile" || key === "root") &&
|
154
|
+
typeof descriptor.value === "object" &&
|
155
|
+
SchemaInit in descriptor.value) {
|
156
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
157
|
+
target.constructor._schema[key] =
|
158
|
+
descriptor.value[SchemaInit];
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
else {
|
162
|
+
return Reflect.defineProperty(target, key, descriptor);
|
163
|
+
}
|
164
|
+
},
|
165
|
+
};
|
133
166
|
export class AccountCtx extends Context.Tag("Account")() {
|
134
167
|
}
|
135
168
|
export function isControlledAccount(account) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/coValues/account.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAYnC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAYjC,OAAO,
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/coValues/account.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAYnC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAYjC,OAAO,EACH,WAAW,EACX,OAAO,EACP,GAAG,EACH,UAAU,EACV,OAAO,EACP,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,OAAO,OAMT,SAAQ,WAAW;IAQnB,IAAI,OAAO;QAIP,OAAQ,IAAI,CAAC,WAA8B,CAAC,OAAO,CAAC;IACxD,CAAC;IAQD,IAAI,MAAM;QACN,OAAO,IAAe,CAAC;IAC3B,CAAC;IACD,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,IAAI;YACZ,CAAC,CAAE,IAAqB;YACxB,CAAC,CAAC,EAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAKD,IAAI,KAAK;QAQL,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAE1B,CAAC;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,C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S,IAAI,GAAG,KAAK,MAAM,CAAC;YACrC,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ;YACpC,UAAU,IAAI,UAAU,CAAC,KAAK,EAChC,CAAC;YACC,MAAC,MAAM,CAAC,WAA4B,EAAC,OAAO,QAAP,OAAO,GAAK,EAAE,EAAC;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;AAYF,MAAM,OAAO,UAAW,SAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAGnD;CAAG;AAEN,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC"}
|
package/dist/coValues/coList.js
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
var _a;
|
2
2
|
import { RawAccount } from "cojson";
|
3
|
-
import { Account, CoValueBase, Group,
|
4
|
-
import { Schema } from "@effect/schema";
|
3
|
+
import { Account, CoValueBase, Group, InitValues, ItemsSym, Ref, SchemaInit, co, inspect, isRefEncoded, makeRefs, } from "../internal.js";
|
4
|
+
import { Schema as EffectSchema } from "@effect/schema";
|
5
5
|
export class CoList extends Array {
|
6
|
+
static Of(item) {
|
7
|
+
var _b, _c;
|
8
|
+
return _c = class CoListOf extends _a {
|
9
|
+
constructor() {
|
10
|
+
super(...arguments);
|
11
|
+
this[_b] = item;
|
12
|
+
}
|
13
|
+
},
|
14
|
+
_b = co.items,
|
15
|
+
_c;
|
16
|
+
}
|
17
|
+
/** @deprecated Use UPPERCASE `CoList.Of` instead! */
|
18
|
+
static of(..._args) {
|
19
|
+
throw new Error("Can't use Array.of with CoLists");
|
20
|
+
}
|
6
21
|
get _schema() {
|
7
22
|
return this.constructor._schema;
|
8
23
|
}
|
@@ -12,7 +27,7 @@ export class CoList extends Array {
|
|
12
27
|
: Group.fromRaw(this._raw.group);
|
13
28
|
}
|
14
29
|
get _refs() {
|
15
|
-
return makeRefs((idx) => this._raw.get(idx), () => Array.from({ length: this._raw.entries().length }, (_, idx) => idx), this._loadedAs, (_idx) => this._schema
|
30
|
+
return makeRefs((idx) => this._raw.get(idx), () => Array.from({ length: this._raw.entries().length }, (_, idx) => idx), this._loadedAs, (_idx) => this._schema[ItemsSym]);
|
16
31
|
}
|
17
32
|
get _edits() {
|
18
33
|
throw new Error("Not implemented");
|
@@ -20,56 +35,39 @@ export class CoList extends Array {
|
|
20
35
|
get _loadedAs() {
|
21
36
|
return Account.fromNode(this._raw.core.node);
|
22
37
|
}
|
38
|
+
static get [Symbol.species]() {
|
39
|
+
return Array;
|
40
|
+
}
|
23
41
|
constructor(init, options) {
|
24
|
-
if (typeof init === "number") {
|
25
|
-
// this might be called from an intrinsic, like map, trying to create an empty array
|
26
|
-
// passing `0` as the only parameter
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
28
|
-
return new Array(init);
|
29
|
-
}
|
30
42
|
super();
|
31
43
|
if (!options) {
|
32
44
|
throw new Error("Must provide options");
|
33
45
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
46
|
+
if (init && "owner" in options) {
|
47
|
+
this[InitValues] = {
|
48
|
+
init,
|
49
|
+
owner: options.owner,
|
50
|
+
};
|
37
51
|
}
|
38
|
-
else {
|
39
|
-
|
40
|
-
|
41
|
-
|
52
|
+
else if ("fromRaw" in options) {
|
53
|
+
Object.defineProperties(this, {
|
54
|
+
id: {
|
55
|
+
value: options.fromRaw.id,
|
56
|
+
enumerable: false,
|
57
|
+
},
|
58
|
+
_raw: { value: options.fromRaw, enumerable: false },
|
59
|
+
});
|
42
60
|
}
|
43
|
-
|
44
|
-
id: {
|
45
|
-
value: raw.id,
|
46
|
-
enumerable: false,
|
47
|
-
},
|
48
|
-
_raw: { value: raw, enumerable: false },
|
49
|
-
});
|
50
|
-
return new Proxy(this, CoListProxyHandler(this._schema._item));
|
51
|
-
}
|
52
|
-
toRawItems(items) {
|
53
|
-
const itemDescriptor = this._schema._item;
|
54
|
-
const rawItems = itemDescriptor === "json"
|
55
|
-
? items
|
56
|
-
: "encoded" in itemDescriptor
|
57
|
-
? items?.map((e) => Schema.encodeSync(itemDescriptor.encoded)(e))
|
58
|
-
: "ref" in itemDescriptor
|
59
|
-
? items?.map((v) => v.id)
|
60
|
-
: (() => {
|
61
|
-
throw new Error("Invalid element descriptor");
|
62
|
-
})();
|
63
|
-
return rawItems;
|
61
|
+
return new Proxy(this, CoListProxyHandler);
|
64
62
|
}
|
65
63
|
push(...items) {
|
66
|
-
for (const item of
|
64
|
+
for (const item of toRawItems(items, this._schema[ItemsSym])) {
|
67
65
|
this._raw.append(item);
|
68
66
|
}
|
69
67
|
return this._raw.entries().length;
|
70
68
|
}
|
71
69
|
unshift(...items) {
|
72
|
-
for (const item of
|
70
|
+
for (const item of toRawItems(items, this._schema[ItemsSym])) {
|
73
71
|
this._raw.prepend(item);
|
74
72
|
}
|
75
73
|
return this._raw.entries().length;
|
@@ -90,23 +88,23 @@ export class CoList extends Array {
|
|
90
88
|
this._raw.delete(idxToDelete);
|
91
89
|
}
|
92
90
|
let appendAfter = start;
|
93
|
-
for (const item of
|
91
|
+
for (const item of toRawItems(items, this._schema[ItemsSym])) {
|
94
92
|
this._raw.append(item, appendAfter);
|
95
93
|
appendAfter++;
|
96
94
|
}
|
97
95
|
return deleted;
|
98
96
|
}
|
99
97
|
toJSON() {
|
100
|
-
const itemDescriptor = this._schema
|
98
|
+
const itemDescriptor = this._schema[ItemsSym];
|
101
99
|
if (itemDescriptor === "json") {
|
102
100
|
return this._raw.asArray();
|
103
101
|
}
|
104
102
|
else if ("encoded" in itemDescriptor) {
|
105
103
|
return this._raw
|
106
104
|
.asArray()
|
107
|
-
.map((e) =>
|
105
|
+
.map((e) => EffectSchema.encodeSync(itemDescriptor.encoded)(e));
|
108
106
|
}
|
109
|
-
else if (
|
107
|
+
else if (isRefEncoded(itemDescriptor)) {
|
110
108
|
return this.map((item) => item?.toJSON());
|
111
109
|
}
|
112
110
|
else {
|
@@ -119,7 +117,7 @@ export class CoList extends Array {
|
|
119
117
|
static fromRaw(raw) {
|
120
118
|
return new this(undefined, { fromRaw: raw });
|
121
119
|
}
|
122
|
-
static
|
120
|
+
static schema(def) {
|
123
121
|
this._schema || (this._schema = {});
|
124
122
|
Object.assign(this._schema, def);
|
125
123
|
}
|
@@ -138,59 +136,111 @@ CoList.loadEf = CoValueBase.loadEf;
|
|
138
136
|
CoList.load = CoValueBase.load;
|
139
137
|
CoList.subscribeEf = CoValueBase.subscribeEf;
|
140
138
|
CoList.subscribe = CoValueBase.subscribe;
|
141
|
-
function
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
139
|
+
function toRawItems(items, itemDescriptor) {
|
140
|
+
const rawItems = itemDescriptor === "json"
|
141
|
+
? items
|
142
|
+
: "encoded" in itemDescriptor
|
143
|
+
? items?.map((e) => EffectSchema.encodeSync(itemDescriptor.encoded)(e))
|
144
|
+
: isRefEncoded(itemDescriptor)
|
145
|
+
? items?.map((v) => v.id)
|
146
|
+
: (() => {
|
147
|
+
throw new Error("Invalid element descriptor");
|
148
|
+
})();
|
149
|
+
return rawItems;
|
150
|
+
}
|
151
|
+
function init(list) {
|
152
|
+
if (list[InitValues]) {
|
153
|
+
const { init, owner } = list[InitValues];
|
154
|
+
const raw = owner._raw.createList(toRawItems(init, list._schema[ItemsSym]));
|
155
|
+
Object.defineProperties(list, {
|
156
|
+
id: {
|
157
|
+
value: raw.id,
|
158
|
+
enumerable: false,
|
159
|
+
},
|
160
|
+
_raw: { value: raw, enumerable: false },
|
161
|
+
});
|
162
|
+
delete list[InitValues];
|
163
|
+
}
|
164
|
+
}
|
165
|
+
const CoListProxyHandler = {
|
166
|
+
get(target, key, receiver) {
|
167
|
+
if (typeof key === "string" && !isNaN(+key)) {
|
168
|
+
const itemDescriptor = target._schema[ItemsSym];
|
169
|
+
const rawValue = target._raw.get(Number(key));
|
170
|
+
if (itemDescriptor === "json") {
|
171
|
+
return rawValue;
|
162
172
|
}
|
163
|
-
else {
|
164
|
-
return
|
173
|
+
else if ("encoded" in itemDescriptor) {
|
174
|
+
return rawValue === undefined
|
175
|
+
? undefined
|
176
|
+
: EffectSchema.decodeSync(itemDescriptor.encoded)(rawValue);
|
165
177
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
if (itemDescriptor === "json") {
|
171
|
-
rawValue = value;
|
172
|
-
}
|
173
|
-
else if ("encoded" in itemDescriptor) {
|
174
|
-
rawValue = Schema.encodeSync(itemDescriptor.encoded)(value);
|
175
|
-
}
|
176
|
-
else if ("ref" in itemDescriptor) {
|
177
|
-
rawValue = value.id;
|
178
|
-
}
|
179
|
-
target._raw.replace(Number(key), rawValue);
|
180
|
-
return true;
|
178
|
+
else if (isRefEncoded(itemDescriptor)) {
|
179
|
+
return rawValue === undefined
|
180
|
+
? undefined
|
181
|
+
: new Ref(rawValue, target._loadedAs, itemDescriptor).accessFrom(receiver);
|
181
182
|
}
|
182
|
-
|
183
|
-
|
183
|
+
}
|
184
|
+
else if (key === "length") {
|
185
|
+
return target._raw.entries().length;
|
186
|
+
}
|
187
|
+
else {
|
188
|
+
return Reflect.get(target, key, receiver);
|
189
|
+
}
|
190
|
+
},
|
191
|
+
set(target, key, value, receiver) {
|
192
|
+
var _b;
|
193
|
+
if (key === ItemsSym &&
|
194
|
+
typeof value === "object" &&
|
195
|
+
SchemaInit in value) {
|
196
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
197
|
+
target.constructor._schema[ItemsSym] =
|
198
|
+
value[SchemaInit];
|
199
|
+
init(target);
|
200
|
+
return true;
|
201
|
+
}
|
202
|
+
if (typeof key === "string" && !isNaN(+key)) {
|
203
|
+
const itemDescriptor = target._schema[ItemsSym];
|
204
|
+
let rawValue;
|
205
|
+
if (itemDescriptor === "json") {
|
206
|
+
rawValue = value;
|
184
207
|
}
|
185
|
-
|
186
|
-
|
187
|
-
if (typeof key === "string" && !isNaN(+key)) {
|
188
|
-
return Number(key) < target._raw.entries().length;
|
208
|
+
else if ("encoded" in itemDescriptor) {
|
209
|
+
rawValue = EffectSchema.encodeSync(itemDescriptor.encoded)(value);
|
189
210
|
}
|
190
|
-
else {
|
191
|
-
|
211
|
+
else if (isRefEncoded(itemDescriptor)) {
|
212
|
+
rawValue = value.id;
|
192
213
|
}
|
193
|
-
|
194
|
-
|
195
|
-
}
|
214
|
+
target._raw.replace(Number(key), rawValue);
|
215
|
+
return true;
|
216
|
+
}
|
217
|
+
else {
|
218
|
+
return Reflect.set(target, key, value, receiver);
|
219
|
+
}
|
220
|
+
},
|
221
|
+
defineProperty(target, key, descriptor) {
|
222
|
+
var _b;
|
223
|
+
if (descriptor.value &&
|
224
|
+
key === ItemsSym &&
|
225
|
+
typeof descriptor.value === "object" &&
|
226
|
+
SchemaInit in descriptor.value) {
|
227
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
228
|
+
target.constructor._schema[ItemsSym] =
|
229
|
+
descriptor.value[SchemaInit];
|
230
|
+
init(target);
|
231
|
+
return true;
|
232
|
+
}
|
233
|
+
else {
|
234
|
+
return Reflect.defineProperty(target, key, descriptor);
|
235
|
+
}
|
236
|
+
},
|
237
|
+
has(target, key) {
|
238
|
+
if (typeof key === "string" && !isNaN(+key)) {
|
239
|
+
return Number(key) < target._raw.entries().length;
|
240
|
+
}
|
241
|
+
else {
|
242
|
+
return Reflect.has(target, key);
|
243
|
+
}
|
244
|
+
},
|
245
|
+
};
|
196
246
|
//# sourceMappingURL=coList.js.map
|