@evolu/common 6.0.1-preview.32 → 6.0.1-preview.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/src/Array.d.ts +193 -41
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +155 -48
- package/dist/src/Crypto.d.ts +6 -8
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +9 -9
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +4 -4
- package/dist/src/Evolu/Evolu.d.ts +9 -4
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +11 -11
- package/dist/src/Evolu/Protocol.d.ts +24 -1
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +59 -30
- package/dist/src/Evolu/Query.d.ts +1 -1
- package/dist/src/Evolu/Query.d.ts.map +1 -1
- package/dist/src/Evolu/Query.js +1 -1
- package/dist/src/Evolu/Schema.d.ts +24 -20
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +36 -27
- package/dist/src/Evolu/Storage.d.ts +10 -2
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +18 -4
- package/dist/src/Evolu/Sync.d.ts +2 -1
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +45 -33
- package/dist/src/Evolu/Timestamp.d.ts +12 -17
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +5 -19
- package/dist/src/Object.d.ts +10 -4
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +9 -3
- package/dist/src/Type.d.ts +57 -11
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +58 -28
- package/package.json +2 -2
- package/src/Array.ts +213 -55
- package/src/Crypto.ts +11 -9
- package/src/Evolu/Db.ts +7 -7
- package/src/Evolu/Evolu.ts +21 -20
- package/src/Evolu/Protocol.ts +70 -35
- package/src/Evolu/Query.ts +2 -2
- package/src/Evolu/Schema.ts +44 -32
- package/src/Evolu/Storage.ts +40 -2
- package/src/Evolu/Sync.ts +54 -32
- package/src/Evolu/Timestamp.ts +7 -28
- package/src/Object.ts +13 -5
- package/src/Type.ts +58 -32
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Evolu
|
|
2
2
|
|
|
3
|
-
Evolu is TypeScript library and local-first
|
|
3
|
+
Evolu is TypeScript library and local-first platform.
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
6
|
|
|
@@ -24,7 +24,7 @@ The Evolu Relay source along with the Docker files can be in the [/apps/relay](/
|
|
|
24
24
|
|
|
25
25
|
Alternatively, a pre-built image `evoluhq/relay:latest` is hosted on [Docker Hub](https://hub.docker.com/r/evoluhq/relay).
|
|
26
26
|
|
|
27
|
-
For more information, reference the [Evolu Relay](https://www.evolu.dev/docs/
|
|
27
|
+
For more information, reference the [Evolu Relay](https://www.evolu.dev/docs/relay) documentation.
|
|
28
28
|
|
|
29
29
|
## Developing
|
|
30
30
|
|
package/dist/src/Array.d.ts
CHANGED
|
@@ -1,56 +1,157 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 🔒 Immutable, type-safe array
|
|
2
|
+
* 🔒 Immutable, type-safe array helpers
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* methods return mutable arrays even when called on readonly arrays. These
|
|
6
|
-
* helpers ensure transformations return readonly types.
|
|
4
|
+
* Array types, guards, operations, transformations, accessors, and mutations.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Prepared for TC39 Hack pipes:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Problem: nested functions can be hard to follow
|
|
10
|
+
* const result = firstInArray(
|
|
11
|
+
* mapArray(dedupeArray(appendToArray(value, 2)), (x) => x * 2),
|
|
12
|
+
* );
|
|
13
|
+
*
|
|
14
|
+
* // Ideal solution: TC39 Hack pipes (when available)
|
|
15
|
+
* // const result = value
|
|
16
|
+
* // |> appendToArray(%, 2)
|
|
17
|
+
* // |> dedupeArray(%)
|
|
18
|
+
* // |> mapArray(%, (x) => x * 2)
|
|
19
|
+
* // |> firstInArray(%);
|
|
20
|
+
*
|
|
21
|
+
* // Current solution: name each step (or use p1, p2 if lazy)
|
|
22
|
+
* const p1 = appendToArray(value, 2);
|
|
23
|
+
* const p2 = dedupeArray(p1);
|
|
24
|
+
* const p3 = mapArray(p2, (x) => x * 2);
|
|
25
|
+
* const p4 = firstInArray(p3);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Of course it's possible to use array instance methods, but they mutate and do
|
|
29
|
+
* not preserve {@link NonEmptyArray} and {@link NonEmptyReadonlyArray} types.
|
|
11
30
|
*
|
|
12
31
|
* ### Example
|
|
13
32
|
*
|
|
14
33
|
* ```ts
|
|
15
|
-
* //
|
|
34
|
+
* // Types - compile-time guarantee of at least one element
|
|
35
|
+
* const _valid: NonEmptyReadonlyArray<number> = [1, 2, 3];
|
|
36
|
+
* // ts-expect-error - empty array is not a valid NonEmptyReadonlyArray
|
|
37
|
+
* const _invalid: NonEmptyReadonlyArray<number> = [];
|
|
38
|
+
*
|
|
39
|
+
* // Guards
|
|
40
|
+
* const arr: ReadonlyArray<number> = [1, 2, 3];
|
|
41
|
+
* if (isNonEmptyReadonlyArray(arr)) {
|
|
42
|
+
* firstInArray(arr);
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* // Operations
|
|
46
|
+
* const appended = appendToArray([1, 2, 3], 4); // [1, 2, 3, 4]
|
|
47
|
+
* const prepended = prependToArray([2, 3], 1); // [1, 2, 3]
|
|
48
|
+
*
|
|
49
|
+
* // Transformations
|
|
16
50
|
* const readonly: ReadonlyArray<number> = [1, 2, 3];
|
|
17
|
-
* const mapped = readonly
|
|
18
|
-
*
|
|
19
|
-
* //
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const
|
|
24
|
-
*
|
|
51
|
+
* const mapped = mapArray(readonly, (x) => x * 2); // [2, 4, 6]
|
|
52
|
+
* const filtered = filterArray(readonly, (x) => x > 1); // [2, 3]
|
|
53
|
+
* const deduped = dedupeArray([1, 2, 1, 3, 2]); // [1, 2, 3]
|
|
54
|
+
*
|
|
55
|
+
* // Accessors
|
|
56
|
+
* const first = firstInArray(["a", "b", "c"]); // "a"
|
|
57
|
+
* const last = lastInArray(["a", "b", "c"]); // "c"
|
|
58
|
+
*
|
|
59
|
+
* // Mutations
|
|
60
|
+
* const mutable: NonEmptyArray<number> = [1, 2, 3];
|
|
61
|
+
* shiftArray(mutable); // 1 (guaranteed to exist)
|
|
62
|
+
* mutable; // [2, 3]
|
|
25
63
|
* ```
|
|
26
64
|
*
|
|
27
65
|
* @module
|
|
28
66
|
*/
|
|
29
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* An array with at least one element.
|
|
69
|
+
*
|
|
70
|
+
* @category Types
|
|
71
|
+
*/
|
|
30
72
|
export type NonEmptyArray<T> = [T, ...Array<T>];
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
73
|
+
/**
|
|
74
|
+
* A readonly array with at least one element.
|
|
75
|
+
*
|
|
76
|
+
* @category Types
|
|
77
|
+
*/
|
|
34
78
|
export type NonEmptyReadonlyArray<T> = readonly [T, ...ReadonlyArray<T>];
|
|
35
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Checks if an array is non-empty and narrows its type to {@link NonEmptyArray}.
|
|
81
|
+
*
|
|
82
|
+
* Use `if (!isNonEmptyArray(arr))` for empty checks.
|
|
83
|
+
*
|
|
84
|
+
* ### Example
|
|
85
|
+
*
|
|
86
|
+
* ```ts
|
|
87
|
+
* const arr: Array<number> = [1, 2, 3];
|
|
88
|
+
* if (isNonEmptyArray(arr)) {
|
|
89
|
+
* firstInArray(arr); // arr is NonEmptyArray<number>
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @category Type Guards
|
|
94
|
+
*/
|
|
95
|
+
export declare const isNonEmptyArray: <T>(array: Array<T>) => array is NonEmptyArray<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Checks if a readonly array is non-empty and narrows its type to
|
|
98
|
+
* {@link NonEmptyReadonlyArray}.
|
|
99
|
+
*
|
|
100
|
+
* Use `if (!isNonEmptyReadonlyArray(arr))` for empty checks.
|
|
101
|
+
*
|
|
102
|
+
* ### Example
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* const arr: ReadonlyArray<number> = [1, 2, 3];
|
|
106
|
+
* if (isNonEmptyReadonlyArray(arr)) {
|
|
107
|
+
* firstInArray(arr); // arr is NonEmptyReadonlyArray<number>
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @category Type Guards
|
|
112
|
+
*/
|
|
36
113
|
export declare const isNonEmptyReadonlyArray: <T>(array: ReadonlyArray<T>) => array is NonEmptyReadonlyArray<T>;
|
|
37
114
|
/**
|
|
38
115
|
* Appends an item to an array, returning a new non-empty readonly array.
|
|
39
116
|
*
|
|
40
117
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
118
|
+
*
|
|
119
|
+
* ### Example
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* appendToArray([1, 2, 3], 4); // [1, 2, 3, 4]
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @category Operations
|
|
41
126
|
*/
|
|
42
|
-
export declare const appendToArray: <T>(
|
|
127
|
+
export declare const appendToArray: <T>(array: ReadonlyArray<T>, item: T) => NonEmptyReadonlyArray<T>;
|
|
43
128
|
/**
|
|
44
129
|
* Prepends an item to an array, returning a new non-empty readonly array.
|
|
45
130
|
*
|
|
46
131
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
132
|
+
*
|
|
133
|
+
* ### Example
|
|
134
|
+
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* prependToArray([2, 3], 1); // [1, 2, 3]
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @category Operations
|
|
47
140
|
*/
|
|
48
|
-
export declare const prependToArray: <T>(
|
|
141
|
+
export declare const prependToArray: <T>(array: ReadonlyArray<T>, item: T) => NonEmptyReadonlyArray<T>;
|
|
49
142
|
/**
|
|
50
|
-
* Maps an array using a mapper function
|
|
51
|
-
* applicable.
|
|
143
|
+
* Maps an array using a mapper function.
|
|
52
144
|
*
|
|
53
145
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
146
|
+
* Preserves non-empty type.
|
|
147
|
+
*
|
|
148
|
+
* ### Example
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* mapArray([1, 2, 3], (x) => x * 2); // [2, 4, 6]
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @category Transformations
|
|
54
155
|
*/
|
|
55
156
|
export declare function mapArray<T, U>(array: NonEmptyReadonlyArray<T> | NonEmptyArray<T>, mapper: (item: T, index: number) => U): NonEmptyReadonlyArray<U>;
|
|
56
157
|
export declare function mapArray<T, U>(array: ReadonlyArray<T> | Array<T>, mapper: (item: T, index: number) => U): ReadonlyArray<U>;
|
|
@@ -58,37 +159,88 @@ export declare function mapArray<T, U>(array: ReadonlyArray<T> | Array<T>, mappe
|
|
|
58
159
|
* Filters an array using a predicate function, returning a new readonly array.
|
|
59
160
|
*
|
|
60
161
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
162
|
+
*
|
|
163
|
+
* ### Example
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* filterArray([1, 2, 3, 4, 5], (x) => x % 2 === 0); // [2, 4]
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @category Transformations
|
|
61
170
|
*/
|
|
62
171
|
export declare const filterArray: <T>(array: ReadonlyArray<T>, predicate: (item: T, index: number) => boolean) => ReadonlyArray<T>;
|
|
63
172
|
/**
|
|
64
|
-
*
|
|
173
|
+
* Returns a new readonly array with duplicate items removed. If `by` is
|
|
174
|
+
* provided, it will be used to derive the key for uniqueness; otherwise values
|
|
175
|
+
* are used directly. Dedupes by reference equality of values (or extracted keys
|
|
176
|
+
* when `by` is used).
|
|
177
|
+
*
|
|
178
|
+
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
179
|
+
* Preserves non-empty type.
|
|
65
180
|
*
|
|
66
|
-
*
|
|
181
|
+
* ### Example
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* // Dedupe primitives by value
|
|
185
|
+
* dedupeArray([1, 2, 1, 3, 2]); // [1, 2, 3]
|
|
186
|
+
*
|
|
187
|
+
* // Dedupe objects by property
|
|
188
|
+
* dedupeArray(
|
|
189
|
+
* [
|
|
190
|
+
* { id: 1, name: "Alice" },
|
|
191
|
+
* { id: 2, name: "Bob" },
|
|
192
|
+
* { id: 1, name: "Alice 2" },
|
|
193
|
+
* ],
|
|
194
|
+
* (item) => item.id,
|
|
195
|
+
* ); // [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @category Transformations
|
|
67
199
|
*/
|
|
68
|
-
export declare
|
|
200
|
+
export declare function dedupeArray<T>(array: NonEmptyReadonlyArray<T> | NonEmptyArray<T>, by?: (item: T) => unknown): NonEmptyReadonlyArray<T>;
|
|
201
|
+
export declare function dedupeArray<T>(array: ReadonlyArray<T> | Array<T>, by?: (item: T) => unknown): ReadonlyArray<T>;
|
|
69
202
|
/**
|
|
70
|
-
* Returns the first element of a non-empty
|
|
203
|
+
* Returns the first element of a non-empty array.
|
|
204
|
+
*
|
|
205
|
+
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
71
206
|
*
|
|
72
|
-
*
|
|
207
|
+
* ### Example
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* firstInArray(["a", "b", "c"]); // "a"
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @category Accessors
|
|
73
214
|
*/
|
|
74
215
|
export declare const firstInArray: <T>(array: NonEmptyReadonlyArray<T>) => T;
|
|
75
216
|
/**
|
|
76
|
-
* Returns the last element of a non-empty
|
|
217
|
+
* Returns the last element of a non-empty array.
|
|
218
|
+
*
|
|
219
|
+
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
220
|
+
*
|
|
221
|
+
* ### Example
|
|
222
|
+
*
|
|
223
|
+
* ```ts
|
|
224
|
+
* lastInArray(["a", "b", "c"]); // "c"
|
|
225
|
+
* ```
|
|
77
226
|
*
|
|
78
|
-
*
|
|
227
|
+
* @category Accessors
|
|
79
228
|
*/
|
|
80
229
|
export declare const lastInArray: <T>(array: NonEmptyReadonlyArray<T>) => T;
|
|
81
230
|
/**
|
|
82
|
-
*
|
|
83
|
-
* extractor function. Preserves the first occurrence of each distinct key.
|
|
231
|
+
* Shifts an item from a non-empty mutable array, guaranteed to return T.
|
|
84
232
|
*
|
|
85
|
-
*
|
|
86
|
-
*/
|
|
87
|
-
/**
|
|
88
|
-
* Deduplicates items in an array. If `by` is provided, it will be used to
|
|
89
|
-
* derive the key for uniqueness; otherwise values are used directly.
|
|
233
|
+
* **Mutates** the original array.
|
|
90
234
|
*
|
|
91
|
-
*
|
|
235
|
+
* ### Example
|
|
236
|
+
*
|
|
237
|
+
* ```ts
|
|
238
|
+
* const arr: NonEmptyArray<number> = [1, 2, 3];
|
|
239
|
+
* shiftArray(arr); // 1
|
|
240
|
+
* arr; // [2, 3]
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @category Mutations
|
|
92
244
|
*/
|
|
93
|
-
export declare const
|
|
245
|
+
export declare const shiftArray: <T>(array: NonEmptyArray<T>) => T;
|
|
94
246
|
//# sourceMappingURL=Array.d.ts.map
|
package/dist/src/Array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../src/Array.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../src/Array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,KACd,KAAK,IAAI,aAAa,CAAC,CAAC,CAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,EACvC,OAAO,aAAa,CAAC,CAAC,CAAC,KACtB,KAAK,IAAI,qBAAqB,CAAC,CAAC,CAAqB,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,OAAO,aAAa,CAAC,CAAC,CAAC,EACvB,MAAM,CAAC,KACN,qBAAqB,CAAC,CAAC,CACwC,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,OAAO,aAAa,CAAC,CAAC,CAAC,EACvB,MAAM,CAAC,KACN,qBAAqB,CAAC,CAAC,CAAiD,CAAC;AAE5E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,CAAC,E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;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,qBAAqB,CAAC,CAAC,CAAC,KAAG,CACxC,CAAC;AAE1B;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,OAAO,aAAa,CAAC,CAAC,CAAC,KAAG,CAAuB,CAAC"}
|
package/dist/src/Array.js
CHANGED
|
@@ -1,47 +1,132 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 🔒 Immutable, type-safe array
|
|
2
|
+
* 🔒 Immutable, type-safe array helpers
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* methods return mutable arrays even when called on readonly arrays. These
|
|
6
|
-
* helpers ensure transformations return readonly types.
|
|
4
|
+
* Array types, guards, operations, transformations, accessors, and mutations.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Prepared for TC39 Hack pipes:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Problem: nested functions can be hard to follow
|
|
10
|
+
* const result = firstInArray(
|
|
11
|
+
* mapArray(dedupeArray(appendToArray(value, 2)), (x) => x * 2),
|
|
12
|
+
* );
|
|
13
|
+
*
|
|
14
|
+
* // Ideal solution: TC39 Hack pipes (when available)
|
|
15
|
+
* // const result = value
|
|
16
|
+
* // |> appendToArray(%, 2)
|
|
17
|
+
* // |> dedupeArray(%)
|
|
18
|
+
* // |> mapArray(%, (x) => x * 2)
|
|
19
|
+
* // |> firstInArray(%);
|
|
20
|
+
*
|
|
21
|
+
* // Current solution: name each step (or use p1, p2 if lazy)
|
|
22
|
+
* const p1 = appendToArray(value, 2);
|
|
23
|
+
* const p2 = dedupeArray(p1);
|
|
24
|
+
* const p3 = mapArray(p2, (x) => x * 2);
|
|
25
|
+
* const p4 = firstInArray(p3);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Of course it's possible to use array instance methods, but they mutate and do
|
|
29
|
+
* not preserve {@link NonEmptyArray} and {@link NonEmptyReadonlyArray} types.
|
|
11
30
|
*
|
|
12
31
|
* ### Example
|
|
13
32
|
*
|
|
14
33
|
* ```ts
|
|
15
|
-
* //
|
|
34
|
+
* // Types - compile-time guarantee of at least one element
|
|
35
|
+
* const _valid: NonEmptyReadonlyArray<number> = [1, 2, 3];
|
|
36
|
+
* // ts-expect-error - empty array is not a valid NonEmptyReadonlyArray
|
|
37
|
+
* const _invalid: NonEmptyReadonlyArray<number> = [];
|
|
38
|
+
*
|
|
39
|
+
* // Guards
|
|
40
|
+
* const arr: ReadonlyArray<number> = [1, 2, 3];
|
|
41
|
+
* if (isNonEmptyReadonlyArray(arr)) {
|
|
42
|
+
* firstInArray(arr);
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* // Operations
|
|
46
|
+
* const appended = appendToArray([1, 2, 3], 4); // [1, 2, 3, 4]
|
|
47
|
+
* const prepended = prependToArray([2, 3], 1); // [1, 2, 3]
|
|
48
|
+
*
|
|
49
|
+
* // Transformations
|
|
16
50
|
* const readonly: ReadonlyArray<number> = [1, 2, 3];
|
|
17
|
-
* const mapped = readonly
|
|
51
|
+
* const mapped = mapArray(readonly, (x) => x * 2); // [2, 4, 6]
|
|
52
|
+
* const filtered = filterArray(readonly, (x) => x > 1); // [2, 3]
|
|
53
|
+
* const deduped = dedupeArray([1, 2, 1, 3, 2]); // [1, 2, 3]
|
|
18
54
|
*
|
|
19
|
-
* //
|
|
20
|
-
* const
|
|
55
|
+
* // Accessors
|
|
56
|
+
* const first = firstInArray(["a", "b", "c"]); // "a"
|
|
57
|
+
* const last = lastInArray(["a", "b", "c"]); // "c"
|
|
21
58
|
*
|
|
22
|
-
* //
|
|
23
|
-
* const
|
|
24
|
-
*
|
|
59
|
+
* // Mutations
|
|
60
|
+
* const mutable: NonEmptyArray<number> = [1, 2, 3];
|
|
61
|
+
* shiftArray(mutable); // 1 (guaranteed to exist)
|
|
62
|
+
* mutable; // [2, 3]
|
|
25
63
|
* ```
|
|
26
64
|
*
|
|
27
65
|
* @module
|
|
28
66
|
*/
|
|
29
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Checks if an array is non-empty and narrows its type to {@link NonEmptyArray}.
|
|
69
|
+
*
|
|
70
|
+
* Use `if (!isNonEmptyArray(arr))` for empty checks.
|
|
71
|
+
*
|
|
72
|
+
* ### Example
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* const arr: Array<number> = [1, 2, 3];
|
|
76
|
+
* if (isNonEmptyArray(arr)) {
|
|
77
|
+
* firstInArray(arr); // arr is NonEmptyArray<number>
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @category Type Guards
|
|
82
|
+
*/
|
|
30
83
|
export const isNonEmptyArray = (array) => array.length > 0;
|
|
31
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Checks if a readonly array is non-empty and narrows its type to
|
|
86
|
+
* {@link NonEmptyReadonlyArray}.
|
|
87
|
+
*
|
|
88
|
+
* Use `if (!isNonEmptyReadonlyArray(arr))` for empty checks.
|
|
89
|
+
*
|
|
90
|
+
* ### Example
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* const arr: ReadonlyArray<number> = [1, 2, 3];
|
|
94
|
+
* if (isNonEmptyReadonlyArray(arr)) {
|
|
95
|
+
* firstInArray(arr); // arr is NonEmptyReadonlyArray<number>
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @category Type Guards
|
|
100
|
+
*/
|
|
32
101
|
export const isNonEmptyReadonlyArray = (array) => array.length > 0;
|
|
33
102
|
/**
|
|
34
103
|
* Appends an item to an array, returning a new non-empty readonly array.
|
|
35
104
|
*
|
|
36
105
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
106
|
+
*
|
|
107
|
+
* ### Example
|
|
108
|
+
*
|
|
109
|
+
* ```ts
|
|
110
|
+
* appendToArray([1, 2, 3], 4); // [1, 2, 3, 4]
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @category Operations
|
|
37
114
|
*/
|
|
38
|
-
export const appendToArray = (
|
|
115
|
+
export const appendToArray = (array, item) => [...array, item];
|
|
39
116
|
/**
|
|
40
117
|
* Prepends an item to an array, returning a new non-empty readonly array.
|
|
41
118
|
*
|
|
42
119
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
120
|
+
*
|
|
121
|
+
* ### Example
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* prependToArray([2, 3], 1); // [1, 2, 3]
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @category Operations
|
|
43
128
|
*/
|
|
44
|
-
export const prependToArray = (
|
|
129
|
+
export const prependToArray = (array, item) => [item, ...array];
|
|
45
130
|
export function mapArray(array, mapper) {
|
|
46
131
|
return array.map(mapper);
|
|
47
132
|
}
|
|
@@ -49,39 +134,17 @@ export function mapArray(array, mapper) {
|
|
|
49
134
|
* Filters an array using a predicate function, returning a new readonly array.
|
|
50
135
|
*
|
|
51
136
|
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
52
|
-
*/
|
|
53
|
-
export const filterArray = (array, predicate) => array.filter(predicate);
|
|
54
|
-
/**
|
|
55
|
-
* Shifts an item from a non-empty mutable array, guaranteed to return T.
|
|
56
|
-
*
|
|
57
|
-
* **Mutates** the original array. Use only with mutable arrays.
|
|
58
|
-
*/
|
|
59
|
-
export const shiftArray = (array) => array.shift();
|
|
60
|
-
/**
|
|
61
|
-
* Returns the first element of a non-empty readonly array.
|
|
62
137
|
*
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
export const firstInArray = (array) => array[0];
|
|
66
|
-
/**
|
|
67
|
-
* Returns the last element of a non-empty readonly array.
|
|
68
|
-
*
|
|
69
|
-
* Does not mutate the original array.
|
|
70
|
-
*/
|
|
71
|
-
export const lastInArray = (array) => array[array.length - 1];
|
|
72
|
-
/**
|
|
73
|
-
* Returns a new readonly array with duplicate items removed based on a key
|
|
74
|
-
* extractor function. Preserves the first occurrence of each distinct key.
|
|
138
|
+
* ### Example
|
|
75
139
|
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* Deduplicates items in an array. If `by` is provided, it will be used to
|
|
80
|
-
* derive the key for uniqueness; otherwise values are used directly.
|
|
140
|
+
* ```ts
|
|
141
|
+
* filterArray([1, 2, 3, 4, 5], (x) => x % 2 === 0); // [2, 4]
|
|
142
|
+
* ```
|
|
81
143
|
*
|
|
82
|
-
*
|
|
144
|
+
* @category Transformations
|
|
83
145
|
*/
|
|
84
|
-
export const
|
|
146
|
+
export const filterArray = (array, predicate) => array.filter(predicate);
|
|
147
|
+
export function dedupeArray(array, by) {
|
|
85
148
|
if (by == null) {
|
|
86
149
|
return Array.from(new Set(array));
|
|
87
150
|
}
|
|
@@ -93,4 +156,48 @@ export const dedupeArray = (array, by) => {
|
|
|
93
156
|
seen.add(key);
|
|
94
157
|
return true;
|
|
95
158
|
});
|
|
96
|
-
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the first element of a non-empty array.
|
|
162
|
+
*
|
|
163
|
+
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
164
|
+
*
|
|
165
|
+
* ### Example
|
|
166
|
+
*
|
|
167
|
+
* ```ts
|
|
168
|
+
* firstInArray(["a", "b", "c"]); // "a"
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @category Accessors
|
|
172
|
+
*/
|
|
173
|
+
export const firstInArray = (array) => array[0];
|
|
174
|
+
/**
|
|
175
|
+
* Returns the last element of a non-empty array.
|
|
176
|
+
*
|
|
177
|
+
* Accepts both mutable and readonly arrays. Does not mutate the original array.
|
|
178
|
+
*
|
|
179
|
+
* ### Example
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* lastInArray(["a", "b", "c"]); // "c"
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @category Accessors
|
|
186
|
+
*/
|
|
187
|
+
export const lastInArray = (array) => array[array.length - 1];
|
|
188
|
+
/**
|
|
189
|
+
* Shifts an item from a non-empty mutable array, guaranteed to return T.
|
|
190
|
+
*
|
|
191
|
+
* **Mutates** the original array.
|
|
192
|
+
*
|
|
193
|
+
* ### Example
|
|
194
|
+
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* const arr: NonEmptyArray<number> = [1, 2, 3];
|
|
197
|
+
* shiftArray(arr); // 1
|
|
198
|
+
* arr; // [2, 3]
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @category Mutations
|
|
202
|
+
*/
|
|
203
|
+
export const shiftArray = (array) => array.shift();
|
package/dist/src/Crypto.d.ts
CHANGED
|
@@ -85,15 +85,13 @@ export declare const createSymmetricCrypto: (deps: RandomBytesDep) => SymmetricC
|
|
|
85
85
|
* Returns the PADMÉ padded length for a given input length.
|
|
86
86
|
*
|
|
87
87
|
* PADMÉ limits information leakage about the length of the plain-text for a
|
|
88
|
-
* wide range of encrypted data sizes.
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
export declare const padmePaddedLength: (length: NonNegativeInt) => NonNegativeInt;
|
|
92
|
-
/**
|
|
93
|
-
* Returns the PADMÉ padding length for a given input length. Uses
|
|
94
|
-
* {@link padmePaddedLength}.
|
|
88
|
+
* wide range of encrypted data sizes.
|
|
89
|
+
*
|
|
90
|
+
* See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
|
|
95
91
|
*/
|
|
96
|
-
export declare const
|
|
92
|
+
export declare const createPadmePaddedLength: (length: NonNegativeInt) => NonNegativeInt;
|
|
93
|
+
/** Creates a PADMÉ padding array of zeros for the given input length. */
|
|
94
|
+
export declare const createPadmePadding: (length: NonNegativeInt) => Uint8Array;
|
|
97
95
|
/**
|
|
98
96
|
* Performs a timing-safe comparison of two Uint8Arrays. Returns true if they
|
|
99
97
|
* are equal, false otherwise. Takes constant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AAE,UAAU,CAAC;KACjC,CAAC;IAEF,QAAQ,CAAC,OAAO,EAAE,CAChB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,UAAU,KACd,MAAM,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,IAAI,EAAE,6BAA6B,CAAC;IAC7C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAChC,MAAM,cAAc,KACnB,eAyBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,cAAc,KACrB,cAOF,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,kBAAkB,GAAI,QAAQ,cAAc,KAAG,UAI3D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC;AAExE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C"}
|
package/dist/src/Crypto.js
CHANGED
|
@@ -68,10 +68,11 @@ export const createSymmetricCrypto = (deps) => {
|
|
|
68
68
|
* Returns the PADMÉ padded length for a given input length.
|
|
69
69
|
*
|
|
70
70
|
* PADMÉ limits information leakage about the length of the plain-text for a
|
|
71
|
-
* wide range of encrypted data sizes.
|
|
72
|
-
*
|
|
71
|
+
* wide range of encrypted data sizes.
|
|
72
|
+
*
|
|
73
|
+
* See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
|
|
73
74
|
*/
|
|
74
|
-
export const
|
|
75
|
+
export const createPadmePaddedLength = (length) => {
|
|
75
76
|
if (length <= 0)
|
|
76
77
|
return NonNegativeInt.orThrow(0);
|
|
77
78
|
const e = 31 - Math.clz32(length >>> 0);
|
|
@@ -80,10 +81,9 @@ export const padmePaddedLength = (length) => {
|
|
|
80
81
|
const mask = (1 << z) - 1;
|
|
81
82
|
return NonNegativeInt.orThrow((length + mask) & ~mask);
|
|
82
83
|
};
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return NonNegativeInt.orThrow(padmePaddedLength(length) - length);
|
|
84
|
+
/** Creates a PADMÉ padding array of zeros for the given input length. */
|
|
85
|
+
export const createPadmePadding = (length) => {
|
|
86
|
+
const paddedLength = createPadmePaddedLength(length);
|
|
87
|
+
const paddingLength = NonNegativeInt.orThrow(paddedLength - length);
|
|
88
|
+
return new globalThis.Uint8Array(paddingLength);
|
|
89
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAEL,aAAa,EACb,cAAc,EACd,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAEL,qBAAqB,EAIrB,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAGL,MAAM,EACP,MAAM,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