jazz-tools 0.8.15 → 0.8.16
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +276 -269
- package/dist/native/coValues/account.js +3 -6
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +3 -7
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +8 -14
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coStream.js +7 -12
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/deepLoading.js +6 -3
- package/dist/native/coValues/deepLoading.js.map +1 -1
- package/dist/native/coValues/extensions/imageDef.js.map +1 -1
- package/dist/native/coValues/group.js +3 -6
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coValues/interfaces.js +4 -3
- package/dist/native/coValues/interfaces.js.map +1 -1
- package/dist/native/exports.js +3 -9
- package/dist/native/exports.js.map +1 -1
- package/dist/native/implementation/createContext.js +1 -2
- package/dist/native/implementation/createContext.js.map +1 -1
- package/dist/native/implementation/devtoolsFormatters.js +5 -25
- package/dist/native/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/native/implementation/refs.js +1 -2
- package/dist/native/implementation/refs.js.map +1 -1
- package/dist/native/implementation/schema.js +1 -1
- package/dist/native/implementation/schema.js.map +1 -1
- package/dist/native/implementation/subscriptionScope.js +2 -4
- package/dist/native/implementation/subscriptionScope.js.map +1 -1
- package/dist/native/index.native.js +1 -1
- package/dist/native/index.native.js.map +1 -1
- package/dist/native/lib/cache.js.map +1 -1
- package/dist/native/lib/cache.test.js +1 -1
- package/dist/native/lib/cache.test.js.map +1 -1
- package/dist/web/coValues/account.js +3 -6
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +3 -7
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +8 -14
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coStream.js +7 -12
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/deepLoading.js +6 -3
- package/dist/web/coValues/deepLoading.js.map +1 -1
- package/dist/web/coValues/extensions/imageDef.js.map +1 -1
- package/dist/web/coValues/group.js +3 -6
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coValues/interfaces.js +4 -3
- package/dist/web/coValues/interfaces.js.map +1 -1
- package/dist/web/exports.js +3 -9
- package/dist/web/exports.js.map +1 -1
- package/dist/web/implementation/createContext.js +1 -2
- package/dist/web/implementation/createContext.js.map +1 -1
- package/dist/web/implementation/devtoolsFormatters.js +5 -25
- package/dist/web/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/web/implementation/refs.js +1 -2
- package/dist/web/implementation/refs.js.map +1 -1
- package/dist/web/implementation/schema.js +1 -1
- package/dist/web/implementation/schema.js.map +1 -1
- package/dist/web/implementation/subscriptionScope.js +2 -4
- package/dist/web/implementation/subscriptionScope.js.map +1 -1
- package/dist/web/lib/cache.js.map +1 -1
- package/dist/web/lib/cache.test.js +1 -1
- package/dist/web/lib/cache.test.js.map +1 -1
- package/package.json +5 -9
- package/src/coValues/account.ts +330 -339
- package/src/coValues/coList.ts +474 -495
- package/src/coValues/coMap.ts +584 -604
- package/src/coValues/coStream.ts +624 -650
- package/src/coValues/deepLoading.ts +184 -200
- package/src/coValues/extensions/imageDef.ts +44 -44
- package/src/coValues/group.ts +196 -210
- package/src/coValues/interfaces.ts +197 -199
- package/src/exports.ts +38 -26
- package/src/implementation/createContext.ts +206 -213
- package/src/implementation/devtoolsFormatters.ts +80 -100
- package/src/implementation/refs.ts +127 -139
- package/src/implementation/schema.ts +124 -128
- package/src/implementation/subscriptionScope.ts +111 -121
- package/src/index.native.ts +3 -3
- package/src/lib/cache.test.ts +48 -48
- package/src/lib/cache.ts +9 -9
- package/src/tests/coList.test.ts +264 -283
- package/src/tests/coMap.test.ts +741 -761
- package/src/tests/coStream.test.ts +405 -438
- package/src/tests/deepLoading.test.ts +251 -256
- package/src/tests/groupsAndAccounts.test.ts +70 -74
- package/src/tests/schema.test.ts +198 -198
- package/src/tests/subscribe.test.ts +312 -299
- package/tsconfig.json +2 -4
- package/tsconfig.native.json +4 -10
- package/tsconfig.web.json +4 -10
- package/.eslintrc.cjs +0 -24
- package/.prettierrc.js +0 -9
@@ -1,229 +1,213 @@
|
|
1
1
|
import { SessionID } from "cojson";
|
2
2
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
Account,
|
4
|
+
CoList,
|
5
|
+
CoStream,
|
6
|
+
CoStreamEntry,
|
7
|
+
ItemsSym,
|
8
|
+
Ref,
|
9
|
+
RefEncoded,
|
10
|
+
UnCo,
|
11
11
|
} from "../internal.js";
|
12
12
|
import { CoKeys, CoMap } from "./coMap.js";
|
13
13
|
import { CoValue, ID } from "./interfaces.js";
|
14
14
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
16
16
|
export function fulfillsDepth(depth: any, value: CoValue): boolean {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
continue;
|
43
|
-
}
|
44
|
-
if (!map[key]) {
|
45
|
-
return false;
|
46
|
-
}
|
47
|
-
if (!fulfillsDepth(depth[key], map[key])) {
|
48
|
-
return false;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
return true;
|
17
|
+
if (
|
18
|
+
value._type === "CoMap" ||
|
19
|
+
value._type === "Group" ||
|
20
|
+
value._type === "Account"
|
21
|
+
) {
|
22
|
+
if (Array.isArray(depth) && depth.length === 1) {
|
23
|
+
return Object.entries(value).every(([key, item]) => {
|
24
|
+
return (
|
25
|
+
value as unknown as {
|
26
|
+
_refs: { [key: string]: Ref<CoValue> | undefined };
|
27
|
+
}
|
28
|
+
)._refs[key]
|
29
|
+
? item && fulfillsDepth(depth[0], item)
|
30
|
+
: ((value as CoMap)._schema[ItemsSym] as RefEncoded<CoValue>)!
|
31
|
+
.optional;
|
32
|
+
});
|
33
|
+
} else {
|
34
|
+
for (const key of Object.keys(depth)) {
|
35
|
+
const map = value as unknown as {
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
37
|
+
[key: string]: any;
|
38
|
+
_refs: { [key: string]: Ref<CoValue> | undefined };
|
39
|
+
};
|
40
|
+
if (!map._refs[key] && map._schema[key].optional) {
|
41
|
+
continue;
|
52
42
|
}
|
53
|
-
|
54
|
-
|
55
|
-
return true;
|
56
|
-
} else {
|
57
|
-
const itemDepth = depth[0];
|
58
|
-
return (value as CoList).every((item, i) =>
|
59
|
-
(value as CoList)._refs[i]
|
60
|
-
? item && fulfillsDepth(itemDepth, item)
|
61
|
-
: (
|
62
|
-
(value as CoList)._schema[
|
63
|
-
ItemsSym
|
64
|
-
] as RefEncoded<CoValue>
|
65
|
-
).optional,
|
66
|
-
);
|
43
|
+
if (!map[key]) {
|
44
|
+
return false;
|
67
45
|
}
|
68
|
-
|
69
|
-
|
70
|
-
return true;
|
71
|
-
} else {
|
72
|
-
const itemDepth = depth[0];
|
73
|
-
return Object.values((value as CoStream).perSession).every(
|
74
|
-
(entry) =>
|
75
|
-
entry.ref
|
76
|
-
? entry.value && fulfillsDepth(itemDepth, entry.value)
|
77
|
-
: (
|
78
|
-
(value as CoStream)._schema[
|
79
|
-
ItemsSym
|
80
|
-
] as RefEncoded<CoValue>
|
81
|
-
).optional,
|
82
|
-
);
|
46
|
+
if (!fulfillsDepth(depth[key], map[key])) {
|
47
|
+
return false;
|
83
48
|
}
|
84
|
-
|
85
|
-
|
49
|
+
}
|
50
|
+
return true;
|
51
|
+
}
|
52
|
+
} else if (value._type === "CoList") {
|
53
|
+
if (depth.length === 0) {
|
54
|
+
return true;
|
86
55
|
} else {
|
87
|
-
|
88
|
-
|
56
|
+
const itemDepth = depth[0];
|
57
|
+
return (value as CoList).every((item, i) =>
|
58
|
+
(value as CoList)._refs[i]
|
59
|
+
? item && fulfillsDepth(itemDepth, item)
|
60
|
+
: ((value as CoList)._schema[ItemsSym] as RefEncoded<CoValue>)
|
61
|
+
.optional,
|
62
|
+
);
|
89
63
|
}
|
64
|
+
} else if (value._type === "CoStream") {
|
65
|
+
if (depth.length === 0) {
|
66
|
+
return true;
|
67
|
+
} else {
|
68
|
+
const itemDepth = depth[0];
|
69
|
+
return Object.values((value as CoStream).perSession).every((entry) =>
|
70
|
+
entry.ref
|
71
|
+
? entry.value && fulfillsDepth(itemDepth, entry.value)
|
72
|
+
: ((value as CoStream)._schema[ItemsSym] as RefEncoded<CoValue>)
|
73
|
+
.optional,
|
74
|
+
);
|
75
|
+
}
|
76
|
+
} else if (value._type === "BinaryCoStream") {
|
77
|
+
return true;
|
78
|
+
} else {
|
79
|
+
console.error(value);
|
80
|
+
throw new Error("Unexpected value type: " + value._type);
|
81
|
+
}
|
90
82
|
}
|
91
83
|
|
92
84
|
type UnCoNotNull<T> = UnCo<Exclude<T, null>>;
|
93
85
|
type Clean<T> = UnCo<NonNullable<T>>;
|
94
86
|
|
95
87
|
export type DepthsIn<
|
96
|
-
|
97
|
-
|
98
|
-
|
88
|
+
V,
|
89
|
+
DepthLimit extends number = 5,
|
90
|
+
CurrentDepth extends number[] = [],
|
99
91
|
> =
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
92
|
+
| (DepthLimit extends CurrentDepth["length"]
|
93
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
94
|
+
any
|
95
|
+
: // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
|
96
|
+
V extends Array<infer Item>
|
97
|
+
?
|
98
|
+
| [DepthsIn<UnCoNotNull<Item>, DepthLimit, [0, ...CurrentDepth]>]
|
99
|
+
| never[]
|
100
|
+
: // Basically V extends CoMap | Group | Account - but if we used that we'd introduce circularity into the definition of CoMap itself
|
101
|
+
V extends { _type: "CoMap" | "Group" | "Account" }
|
102
|
+
?
|
103
|
+
| {
|
104
|
+
[Key in CoKeys<V> as Clean<V[Key]> extends CoValue
|
105
|
+
? Key
|
106
|
+
: never]?: DepthsIn<
|
107
|
+
Clean<V[Key]>,
|
108
|
+
DepthLimit,
|
109
|
+
[0, ...CurrentDepth]
|
110
|
+
>;
|
111
|
+
}
|
112
|
+
| (ItemsSym extends keyof V
|
113
|
+
? [
|
114
|
+
DepthsIn<
|
115
|
+
Clean<V[ItemsSym]>,
|
116
|
+
DepthLimit,
|
117
|
+
[0, ...CurrentDepth]
|
118
|
+
>,
|
112
119
|
]
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
DepthLimit,
|
131
|
-
[0, ...CurrentDepth]
|
132
|
-
>,
|
133
|
-
]
|
134
|
-
: never)
|
135
|
-
| never[]
|
136
|
-
: V extends {
|
137
|
-
_type: "CoStream";
|
138
|
-
byMe: CoStreamEntry<infer Item> | undefined;
|
139
|
-
}
|
140
|
-
?
|
141
|
-
| [
|
142
|
-
DepthsIn<
|
143
|
-
UnCoNotNull<Item>,
|
144
|
-
DepthLimit,
|
145
|
-
[0, ...CurrentDepth]
|
146
|
-
>,
|
147
|
-
]
|
148
|
-
| never[]
|
149
|
-
: never[])
|
150
|
-
| never[];
|
120
|
+
: never)
|
121
|
+
| never[]
|
122
|
+
: V extends {
|
123
|
+
_type: "CoStream";
|
124
|
+
byMe: CoStreamEntry<infer Item> | undefined;
|
125
|
+
}
|
126
|
+
?
|
127
|
+
| [
|
128
|
+
DepthsIn<
|
129
|
+
UnCoNotNull<Item>,
|
130
|
+
DepthLimit,
|
131
|
+
[0, ...CurrentDepth]
|
132
|
+
>,
|
133
|
+
]
|
134
|
+
| never[]
|
135
|
+
: never[])
|
136
|
+
| never[];
|
151
137
|
|
152
138
|
export type DeeplyLoaded<
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
139
|
+
V,
|
140
|
+
Depth,
|
141
|
+
DepthLimit extends number = 5,
|
142
|
+
CurrentDepth extends number[] = [],
|
157
143
|
> = DepthLimit extends CurrentDepth["length"]
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
144
|
+
? V
|
145
|
+
: // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
|
146
|
+
[V] extends [Array<infer Item>]
|
147
|
+
? Depth extends never[] // []
|
148
|
+
? V
|
149
|
+
: UnCoNotNull<Item> extends CoValue
|
150
|
+
? Depth extends Array<infer ItemDepth> // [item-depth]
|
151
|
+
? (UnCoNotNull<Item> &
|
152
|
+
DeeplyLoaded<
|
153
|
+
UnCoNotNull<Item>,
|
154
|
+
ItemDepth,
|
155
|
+
DepthLimit,
|
156
|
+
[0, ...CurrentDepth]
|
157
|
+
>)[] &
|
158
|
+
V
|
159
|
+
: never
|
160
|
+
: V
|
161
|
+
: // Basically V extends CoMap | Group | Account - but if we used that we'd introduce circularity into the definition of CoMap itself
|
162
|
+
[V] extends [{ _type: "CoMap" | "Group" | "Account" }]
|
163
|
+
? Depth extends never[]
|
164
|
+
? V
|
165
|
+
: Depth extends Array<infer ItemDepth>
|
166
|
+
? ItemsSym extends keyof V
|
167
|
+
? V & {
|
168
|
+
[key: string]: DeeplyLoaded<
|
169
|
+
Clean<V[ItemsSym]>,
|
170
|
+
ItemDepth,
|
171
|
+
DepthLimit,
|
172
|
+
[0, ...CurrentDepth]
|
173
|
+
>;
|
174
|
+
}
|
175
|
+
: never
|
176
|
+
: keyof Depth extends never
|
178
177
|
? V
|
179
|
-
:
|
180
|
-
|
181
|
-
? V
|
182
|
-
|
183
|
-
|
184
|
-
|
178
|
+
: {
|
179
|
+
[Key in keyof Depth]-?: Key extends CoKeys<V>
|
180
|
+
? Clean<V[Key]> extends CoValue
|
181
|
+
?
|
182
|
+
| DeeplyLoaded<
|
183
|
+
Clean<V[Key]>,
|
184
|
+
Depth[Key],
|
185
185
|
DepthLimit,
|
186
186
|
[0, ...CurrentDepth]
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
} & V
|
187
|
+
>
|
188
|
+
| (undefined extends V[Key] ? undefined : never)
|
189
|
+
: never
|
190
|
+
: never;
|
191
|
+
} & V
|
192
|
+
: [V] extends [
|
193
|
+
{
|
194
|
+
_type: "CoStream";
|
195
|
+
byMe: CoStreamEntry<infer Item> | undefined;
|
196
|
+
},
|
197
|
+
]
|
198
|
+
? Depth extends never[]
|
199
|
+
? V
|
200
|
+
: V & {
|
201
|
+
byMe?: { value: UnCoNotNull<Item> };
|
202
|
+
inCurrentSession?: { value: UnCoNotNull<Item> };
|
203
|
+
perSession: {
|
204
|
+
[key: SessionID]: { value: UnCoNotNull<Item> };
|
205
|
+
};
|
206
|
+
} & { [key: ID<Account>]: { value: UnCoNotNull<Item> } }
|
208
207
|
: [V] extends [
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
},
|
208
|
+
{
|
209
|
+
_type: "BinaryCoStream";
|
210
|
+
},
|
213
211
|
]
|
214
|
-
?
|
215
|
-
|
216
|
-
: V & {
|
217
|
-
byMe?: { value: UnCoNotNull<Item> };
|
218
|
-
inCurrentSession?: { value: UnCoNotNull<Item> };
|
219
|
-
perSession: {
|
220
|
-
[key: SessionID]: { value: UnCoNotNull<Item> };
|
221
|
-
};
|
222
|
-
} & { [key: ID<Account>]: { value: UnCoNotNull<Item> } }
|
223
|
-
: [V] extends [
|
224
|
-
{
|
225
|
-
_type: "BinaryCoStream";
|
226
|
-
},
|
227
|
-
]
|
228
|
-
? V
|
229
|
-
: never;
|
212
|
+
? V
|
213
|
+
: never;
|
@@ -1,59 +1,59 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
BinaryCoStream,
|
3
|
+
CoMap,
|
4
|
+
co,
|
5
|
+
subscriptionsScopes,
|
6
6
|
} from "../../internal.js";
|
7
7
|
|
8
8
|
/** @category Media */
|
9
9
|
export class ImageDefinition extends CoMap {
|
10
|
-
|
11
|
-
|
10
|
+
originalSize = co.json<[number, number]>();
|
11
|
+
placeholderDataURL? = co.string;
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
[co.items] = co.ref(BinaryCoStream);
|
14
|
+
[res: `${number}x${number}`]: co<BinaryCoStream | null>;
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
highestResAvailable(options?: {
|
17
|
+
maxWidth?: number;
|
18
|
+
}): { res: `${number}x${number}`; stream: BinaryCoStream } | undefined {
|
19
|
+
if (!subscriptionsScopes.get(this)) {
|
20
|
+
console.warn(
|
21
|
+
"highestResAvailable() only makes sense when used within a subscription.",
|
22
|
+
);
|
23
|
+
}
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
const resolutions = Object.keys(this).filter(
|
26
|
+
(key) =>
|
27
|
+
key.match(/^\d+x\d+$/) &&
|
28
|
+
(options?.maxWidth === undefined ||
|
29
|
+
Number(key.split("x")[0]) <= options.maxWidth),
|
30
|
+
) as `${number}x${number}`[];
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
resolutions.sort((a, b) => {
|
33
|
+
const aWidth = Number(a.split("x")[0]);
|
34
|
+
const bWidth = Number(b.split("x")[0]);
|
35
|
+
return aWidth - bWidth;
|
36
|
+
});
|
37
37
|
|
38
|
-
|
38
|
+
let highestAvailableResolution: `${number}x${number}` | undefined;
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
return (
|
45
|
-
highestAvailableResolution && {
|
46
|
-
res: highestAvailableResolution,
|
47
|
-
stream: this[highestAvailableResolution]!,
|
48
|
-
}
|
49
|
-
);
|
50
|
-
}
|
51
|
-
}
|
40
|
+
for (const resolution of resolutions) {
|
41
|
+
if (this[resolution] && this[resolution]?.getChunks()) {
|
42
|
+
highestAvailableResolution = resolution;
|
43
|
+
} else {
|
52
44
|
return (
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
45
|
+
highestAvailableResolution && {
|
46
|
+
res: highestAvailableResolution,
|
47
|
+
stream: this[highestAvailableResolution]!,
|
48
|
+
}
|
57
49
|
);
|
50
|
+
}
|
58
51
|
}
|
52
|
+
return (
|
53
|
+
highestAvailableResolution && {
|
54
|
+
res: highestAvailableResolution,
|
55
|
+
stream: this[highestAvailableResolution]!,
|
56
|
+
}
|
57
|
+
);
|
58
|
+
}
|
59
59
|
}
|