@evolu/common 8.10.0 → 8.12.0
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/dist/src/Bytes.d.ts +39 -2
- package/dist/src/Bytes.d.ts.map +1 -1
- package/dist/src/Bytes.js +50 -2
- package/dist/src/Config.d.ts +22 -22
- package/dist/src/Config.d.ts.map +1 -1
- package/dist/src/Console.d.ts +62 -7
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +20 -4
- package/dist/src/Crypto.d.ts +76 -4
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +55 -4
- package/dist/src/Error.d.ts +45 -0
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +69 -0
- package/dist/src/Fs.d.ts +92 -18
- package/dist/src/Fs.d.ts.map +1 -1
- package/dist/src/Fs.js +2 -0
- package/dist/src/Identicon.d.ts +2 -2
- package/dist/src/Identicon.js +2 -2
- package/dist/src/LeakDetector.d.ts +22 -3
- package/dist/src/LeakDetector.d.ts.map +1 -1
- package/dist/src/LeakDetector.js +12 -2
- package/dist/src/LockManager.d.ts +8 -0
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +6 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +5 -0
- package/dist/src/Platform.d.ts +47 -7
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +24 -5
- package/dist/src/Random.d.ts +25 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +14 -2
- package/dist/src/Resource.d.ts +156 -1
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +201 -72
- package/dist/src/Schedule.d.ts +11 -10
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +1 -1
- package/dist/src/Sqlite.d.ts +132 -16
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +63 -9
- package/dist/src/Task.d.ts +15 -4
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +41 -15
- package/dist/src/Test.d.ts +9 -0
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +4 -0
- package/dist/src/Time.d.ts +106 -9
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +55 -4
- package/dist/src/Type.d.ts +1455 -1310
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1274 -517
- package/dist/src/WebSocket.d.ts +164 -13
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +133 -24
- package/dist/src/Worker.d.ts +90 -8
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +28 -2
- package/dist/src/index.d.ts +6 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -3
- package/dist/src/local-first/Db.d.ts +52 -3
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +412 -137
- package/dist/src/local-first/Evolu.d.ts +412 -213
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +181 -18
- package/dist/src/local-first/Owner.d.ts +13 -30
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +13 -30
- package/dist/src/local-first/Protocol.d.ts +106 -19
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +162 -60
- package/dist/src/local-first/Query.d.ts +8 -15
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Relay.js +4 -2
- package/dist/src/local-first/Schema.d.ts +346 -23
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +214 -17
- package/dist/src/local-first/Shared.d.ts +537 -22
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +1437 -234
- package/dist/src/local-first/Storage.d.ts +195 -17
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +85 -22
- package/dist/src/local-first/Timestamp.d.ts +392 -41
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +403 -81
- package/dist/src/local-first/index.d.ts +0 -1
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +0 -1
- package/package.json +1 -1
- package/src/Assert.test.ts +2 -5
- package/src/Bytes.test.ts +27 -0
- package/src/Bytes.ts +58 -2
- package/src/Config.test.ts +2 -6
- package/src/Config.ts +133 -133
- package/src/Console.ts +62 -7
- package/src/Crypto.ts +76 -4
- package/src/Eq.test.ts +2 -3
- package/src/Error.test.ts +76 -3
- package/src/Error.ts +71 -0
- package/src/Fs.ts +92 -18
- package/src/Identicon.ts +2 -2
- package/src/LeakDetector.ts +22 -3
- package/src/LockManager.ts +8 -0
- package/src/Object.test.ts +27 -12
- package/src/Object.ts +5 -0
- package/src/Platform.ts +50 -8
- package/src/Random.ts +25 -2
- package/src/Resource.test.ts +837 -0
- package/src/Resource.ts +235 -15
- package/src/Schedule.test.ts +50 -12
- package/src/Schedule.ts +24 -14
- package/src/Sqlite.ts +137 -17
- package/src/Task.test.ts +189 -8
- package/src/Task.ts +56 -17
- package/src/Test.ts +9 -0
- package/src/Time.ts +106 -9
- package/src/Type.test.ts +946 -1028
- package/src/Type.ts +4195 -3136
- package/src/Types.test.ts +4 -14
- package/src/WebSocket.ts +313 -40
- package/src/Worker.ts +90 -8
- package/src/index.ts +20 -6
- package/src/local-first/Db.ts +644 -339
- package/src/local-first/Evolu.test.ts +994 -22
- package/src/local-first/Evolu.ts +625 -232
- package/src/local-first/Owner.ts +13 -30
- package/src/local-first/Protocol.test.ts +634 -10
- package/src/local-first/Protocol.ts +255 -109
- package/src/local-first/Query.ts +8 -15
- package/src/local-first/Relay.ts +4 -2
- package/src/local-first/Schema.test.ts +143 -0
- package/src/local-first/Schema.ts +376 -26
- package/src/local-first/Shared.test.ts +7731 -559
- package/src/local-first/Shared.ts +2036 -267
- package/src/local-first/Storage.ts +224 -36
- package/src/local-first/Timestamp.test.ts +344 -70
- package/src/local-first/Timestamp.ts +434 -118
- package/src/local-first/index.ts +0 -1
- package/dist/src/local-first/Error.d.ts +0 -12
- package/dist/src/local-first/Error.d.ts.map +0 -1
- package/dist/src/local-first/Error.js +0 -6
- package/dist/src/local-first/LocalAuth.d.ts +0 -150
- package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
- package/dist/src/local-first/LocalAuth.js +0 -179
- package/src/local-first/Error.ts +0 -17
- package/src/local-first/LocalAuth.ts +0 -457
package/dist/src/Time.js
CHANGED
|
@@ -27,6 +27,8 @@ import { brand, createTypeWithError, Digit, Digit1To23, Digit1To51, Digit1To59,
|
|
|
27
27
|
*
|
|
28
28
|
* Throws if the system clock returns an out-of-range value. This is intentional
|
|
29
29
|
* — there's no reasonable fallback for a misconfigured clock.
|
|
30
|
+
*
|
|
31
|
+
* @group Core
|
|
30
32
|
*/
|
|
31
33
|
export const createTime = () => {
|
|
32
34
|
const timeoutOwner = Symbol("Time");
|
|
@@ -106,6 +108,8 @@ const clearTimeoutId = (owner, id) => {
|
|
|
106
108
|
* wall-clock or performance `now()` call. `"microtask"` increments after the
|
|
107
109
|
* current turn, while `"sync"` increments immediately after each read. Omit it
|
|
108
110
|
* to keep time fixed until `advance()` is called.
|
|
111
|
+
*
|
|
112
|
+
* @group Testing
|
|
109
113
|
*/
|
|
110
114
|
export const testCreateTime = (options) => {
|
|
111
115
|
const startAt = options?.startAt ?? minMillis;
|
|
@@ -200,18 +204,34 @@ const maxMillisWithInfinity = 281474976710655;
|
|
|
200
204
|
*
|
|
201
205
|
* If a system clock exceeds this range, operations will throw. This is
|
|
202
206
|
* intentional — there's no reasonable fallback for a misconfigured clock.
|
|
207
|
+
*
|
|
208
|
+
* @group Millis
|
|
203
209
|
*/
|
|
204
210
|
export const Millis = /*#__PURE__*/ brand("Millis",
|
|
205
211
|
/*#__PURE__*/ lessThan(maxMillisWithInfinity)(NonNegativeInt));
|
|
206
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* Positive {@link Millis} value.
|
|
214
|
+
*
|
|
215
|
+
* @group Millis
|
|
216
|
+
*/
|
|
207
217
|
export const PositiveMillis = /*#__PURE__*/ positive(Millis);
|
|
208
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Minimum {@link Millis} value.
|
|
220
|
+
*
|
|
221
|
+
* @group Millis
|
|
222
|
+
*/
|
|
209
223
|
export const minMillis = 0;
|
|
210
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* Maximum {@link Millis} value.
|
|
226
|
+
*
|
|
227
|
+
* @group Millis
|
|
228
|
+
*/
|
|
211
229
|
export const maxMillis = (maxMillisWithInfinity - 1);
|
|
212
230
|
/**
|
|
213
231
|
* Converts a number to {@link Millis}, rounding to the nearest millisecond and
|
|
214
232
|
* saturating overflow at {@link maxMillis}.
|
|
233
|
+
*
|
|
234
|
+
* @group Millis
|
|
215
235
|
*/
|
|
216
236
|
export const saturateMillis = (value) => Millis.orNull(Math.max(0, Math.round(value))) ?? maxMillis;
|
|
217
237
|
/**
|
|
@@ -219,12 +239,16 @@ export const saturateMillis = (value) => Millis.orNull(Math.max(0, Math.round(va
|
|
|
219
239
|
*
|
|
220
240
|
* This is a safe cast because {@link Millis} guarantees a valid timestamp range
|
|
221
241
|
* that always produces a valid ISO string.
|
|
242
|
+
*
|
|
243
|
+
* @group Millis
|
|
222
244
|
*/
|
|
223
245
|
export const millisToDateIso = (value) => new Date(value).toISOString();
|
|
224
246
|
/**
|
|
225
247
|
* Returns the elapsed fractional milliseconds between two performance times.
|
|
226
248
|
*
|
|
227
249
|
* Throws if `end` precedes `start`.
|
|
250
|
+
*
|
|
251
|
+
* @group Performance
|
|
228
252
|
*/
|
|
229
253
|
export const performanceDurationBetween = (start, end) => {
|
|
230
254
|
assert(end >= start, "Performance end time must not precede start time");
|
|
@@ -232,7 +256,11 @@ export const performanceDurationBetween = (start, end) => {
|
|
|
232
256
|
};
|
|
233
257
|
// Keep these annotations concrete. Generic unit wrappers add thousands of
|
|
234
258
|
// compiler instantiations to pnpm bench:type.
|
|
235
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Milliseconds duration: `"1ms"` to `"999ms"`. See {@link DurationLiteral}.
|
|
261
|
+
*
|
|
262
|
+
* @group Durations
|
|
263
|
+
*/
|
|
236
264
|
export const DurationLiteralMilliseconds = /*#__PURE__*/ union(
|
|
237
265
|
/*#__PURE__*/ templateLiteral(Digit1To9, "ms"),
|
|
238
266
|
/*#__PURE__*/ templateLiteral(Digit1To9, Digit, "ms"),
|
|
@@ -240,6 +268,8 @@ export const DurationLiteralMilliseconds = /*#__PURE__*/ union(
|
|
|
240
268
|
/**
|
|
241
269
|
* Seconds duration: `"1s"` to `"59s"` or `"1.1s"` to `"59.9s"`. See
|
|
242
270
|
* {@link DurationLiteral}.
|
|
271
|
+
*
|
|
272
|
+
* @group Durations
|
|
243
273
|
*/
|
|
244
274
|
export const DurationLiteralSeconds = /*#__PURE__*/ union(
|
|
245
275
|
/*#__PURE__*/ templateLiteral(Digit1To59, "s"),
|
|
@@ -247,6 +277,8 @@ export const DurationLiteralSeconds = /*#__PURE__*/ union(
|
|
|
247
277
|
/**
|
|
248
278
|
* Minutes duration: `"1m"` to `"59m"` or `"1.1m"` to `"59.9m"`. See
|
|
249
279
|
* {@link DurationLiteral}.
|
|
280
|
+
*
|
|
281
|
+
* @group Durations
|
|
250
282
|
*/
|
|
251
283
|
export const DurationLiteralMinutes = /*#__PURE__*/ union(
|
|
252
284
|
/*#__PURE__*/ templateLiteral(Digit1To59, "m"),
|
|
@@ -254,6 +286,8 @@ export const DurationLiteralMinutes = /*#__PURE__*/ union(
|
|
|
254
286
|
/**
|
|
255
287
|
* Hours duration: `"1h"` to `"23h"` or `"1.1h"` to `"23.9h"`. See
|
|
256
288
|
* {@link DurationLiteral}.
|
|
289
|
+
*
|
|
290
|
+
* @group Durations
|
|
257
291
|
*/
|
|
258
292
|
export const DurationLiteralHours = /*#__PURE__*/ union(
|
|
259
293
|
/*#__PURE__*/ templateLiteral(Digit1To23, "h"),
|
|
@@ -261,6 +295,8 @@ export const DurationLiteralHours = /*#__PURE__*/ union(
|
|
|
261
295
|
/**
|
|
262
296
|
* Days duration: `"1d"` to `"6d"` or `"1.1d"` to `"6.9d"`. See
|
|
263
297
|
* {@link DurationLiteral}.
|
|
298
|
+
*
|
|
299
|
+
* @group Durations
|
|
264
300
|
*/
|
|
265
301
|
export const DurationLiteralDays = /*#__PURE__*/ union(
|
|
266
302
|
/*#__PURE__*/ templateLiteral(Digit1To6, "d"),
|
|
@@ -268,6 +304,8 @@ export const DurationLiteralDays = /*#__PURE__*/ union(
|
|
|
268
304
|
/**
|
|
269
305
|
* Weeks duration: `"1w"` to `"51w"` or `"1.1w"` to `"51.9w"`. See
|
|
270
306
|
* {@link DurationLiteral}.
|
|
307
|
+
*
|
|
308
|
+
* @group Durations
|
|
271
309
|
*/
|
|
272
310
|
export const DurationLiteralWeeks = /*#__PURE__*/ union(
|
|
273
311
|
/*#__PURE__*/ templateLiteral(Digit1To51, "w"),
|
|
@@ -275,6 +313,8 @@ export const DurationLiteralWeeks = /*#__PURE__*/ union(
|
|
|
275
313
|
/**
|
|
276
314
|
* Years duration: `"1y"` to `"99y"` or `"1.1y"` to `"99.9y"`. See
|
|
277
315
|
* {@link DurationLiteral}.
|
|
316
|
+
*
|
|
317
|
+
* @group Durations
|
|
278
318
|
*/
|
|
279
319
|
export const DurationLiteralYears = /*#__PURE__*/ union(
|
|
280
320
|
/*#__PURE__*/ templateLiteral(Digit1To99, "y"),
|
|
@@ -328,6 +368,8 @@ const durationLiteralSyntax = /*#__PURE__*/ union(DurationLiteralMilliseconds, D
|
|
|
328
368
|
* assertOk(DurationLiteral.fromUnknown(literal), "1.5s");
|
|
329
369
|
* assertFalse(DurationLiteral.is("1000ms"));
|
|
330
370
|
* ```
|
|
371
|
+
*
|
|
372
|
+
* @group Durations
|
|
331
373
|
*/
|
|
332
374
|
export const DurationLiteral = /*#__PURE__*/ createTypeWithError("DurationLiteral", durationLiteralSyntax, (cause, value) => ({
|
|
333
375
|
type: "DurationLiteral",
|
|
@@ -357,12 +399,16 @@ const durationUnits = {
|
|
|
357
399
|
* Frame budget at 60fps (16ms).
|
|
358
400
|
*
|
|
359
401
|
* Work exceeding this blocks a frame, causing visible jank in animations.
|
|
402
|
+
*
|
|
403
|
+
* @group Millis
|
|
360
404
|
*/
|
|
361
405
|
export const ms60fps = 16;
|
|
362
406
|
/**
|
|
363
407
|
* Frame budget at 120fps (8ms).
|
|
364
408
|
*
|
|
365
409
|
* For high refresh rate displays. Work exceeding this blocks a frame.
|
|
410
|
+
*
|
|
411
|
+
* @group Millis
|
|
366
412
|
*/
|
|
367
413
|
export const ms120fps = 8;
|
|
368
414
|
/**
|
|
@@ -371,6 +417,7 @@ export const ms120fps = 8;
|
|
|
371
417
|
* Tasks exceeding this are "long tasks" per web standards. Use with
|
|
372
418
|
* {@link yieldNow} to yield periodically and keep UI responsive.
|
|
373
419
|
*
|
|
420
|
+
* @group Millis
|
|
374
421
|
* @see https://web.dev/articles/optimize-long-tasks
|
|
375
422
|
*/
|
|
376
423
|
export const msLongTask = 50;
|
|
@@ -402,6 +449,8 @@ export const msLongTask = 50;
|
|
|
402
449
|
* "1d1h1m1.000s",
|
|
403
450
|
* );
|
|
404
451
|
* ```
|
|
452
|
+
*
|
|
453
|
+
* @group Millis
|
|
405
454
|
*/
|
|
406
455
|
export const formatMillisAsDuration = (millis) => {
|
|
407
456
|
const seconds = ((millis % durationUnits.m) / durationUnits.s).toFixed(3);
|
|
@@ -441,6 +490,8 @@ export const formatMillisAsDuration = (millis) => {
|
|
|
441
490
|
* "14:32:15.234",
|
|
442
491
|
* );
|
|
443
492
|
* ```
|
|
493
|
+
*
|
|
494
|
+
* @group Millis
|
|
444
495
|
*/
|
|
445
496
|
export const formatMillisAsClockTime = (millis) => {
|
|
446
497
|
const date = new Date(millis);
|