@evolu/common 6.0.1-preview.27 → 6.0.1-preview.29
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/Array.d.ts +58 -5
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +53 -5
- package/dist/src/Evolu/Evolu.d.ts +7 -12
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +18 -23
- package/dist/src/Evolu/Owner.d.ts +48 -19
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +11 -2
- package/dist/src/Evolu/Protocol.d.ts +31 -31
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +51 -28
- package/dist/src/Evolu/Relay.d.ts +40 -25
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +106 -49
- package/dist/src/Evolu/Storage.d.ts +59 -12
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +77 -50
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +14 -5
- package/dist/src/Evolu/Timestamp.d.ts +25 -0
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +25 -0
- package/dist/src/Instances.d.ts +34 -0
- package/dist/src/Instances.d.ts.map +1 -0
- package/dist/src/Instances.js +44 -0
- package/dist/src/Sqlite.d.ts +6 -0
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +6 -0
- package/dist/src/Task.d.ts +75 -0
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +29 -6
- package/dist/src/Time.d.ts +7 -1
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +13 -2
- package/dist/src/Type.d.ts +56 -9
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +40 -8
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/package.json +1 -1
- package/src/Array.ts +76 -11
- package/src/Evolu/Evolu.ts +27 -27
- package/src/Evolu/Owner.ts +75 -26
- package/src/Evolu/Protocol.ts +90 -61
- package/src/Evolu/Relay.ts +182 -77
- package/src/Evolu/Storage.ts +157 -67
- package/src/Evolu/Sync.ts +18 -6
- package/src/Evolu/Timestamp.ts +25 -0
- package/src/Instances.ts +90 -0
- package/src/Sqlite.ts +6 -0
- package/src/Task.ts +88 -7
- package/src/Time.ts +13 -2
- package/src/Type.ts +56 -9
- package/src/index.ts +1 -0
package/src/Time.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { assert } from "./Assert.js";
|
|
7
8
|
import { DateIso, NonNegativeInt } from "./Type.js";
|
|
8
9
|
|
|
9
10
|
/** Retrieves the current time in milliseconds, similar to `Date.now()`. */
|
|
@@ -16,14 +17,24 @@ export interface TimeDep {
|
|
|
16
17
|
readonly time: Time;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Creates a {@link Time} using Date.now().
|
|
22
|
+
*
|
|
23
|
+
* If the system clock is misconfigured (out of allowed range), the application
|
|
24
|
+
* will fail with an assertion error. This is intentional - there's no
|
|
25
|
+
* reasonable fallback when the system clock is fundamentally wrong.
|
|
26
|
+
*/
|
|
20
27
|
export const createTime = (): Time => {
|
|
21
28
|
const time: Time = {
|
|
22
29
|
now: () => {
|
|
23
30
|
const iso = time.nowIso();
|
|
24
31
|
return new globalThis.Date(iso).getTime();
|
|
25
32
|
},
|
|
26
|
-
nowIso: () =>
|
|
33
|
+
nowIso: () => {
|
|
34
|
+
const iso = new globalThis.Date().toISOString();
|
|
35
|
+
assert(DateIso.is(iso), "System clock returned invalid ISO date");
|
|
36
|
+
return iso;
|
|
37
|
+
},
|
|
27
38
|
};
|
|
28
39
|
return time;
|
|
29
40
|
};
|
package/src/Type.ts
CHANGED
|
@@ -215,6 +215,9 @@ export interface Type<
|
|
|
215
215
|
/**
|
|
216
216
|
* Creates `T` from an `Input` value, throwing an error if validation fails.
|
|
217
217
|
*
|
|
218
|
+
* Throws an Error with the Type validation error in its `cause` property,
|
|
219
|
+
* making it debuggable while avoiding the need for custom error messages.
|
|
220
|
+
*
|
|
218
221
|
* This is a convenience method that combines `from` with `getOrThrow`.
|
|
219
222
|
*
|
|
220
223
|
* **When to use:**
|
|
@@ -222,7 +225,11 @@ export interface Type<
|
|
|
222
225
|
* - Configuration values that are guaranteed to be valid (e.g., hardcoded
|
|
223
226
|
* constants)
|
|
224
227
|
* - Application startup where failure should crash the program
|
|
225
|
-
* -
|
|
228
|
+
* - As an alternative to assertions when the Type error in the thrown Error's
|
|
229
|
+
* `cause` provides sufficient debugging information
|
|
230
|
+
* - Test code with known valid inputs (when error message clarity is not
|
|
231
|
+
* critical; for better test error messages, use Vitest `schemaMatching` +
|
|
232
|
+
* `assert` with `.is()`)
|
|
226
233
|
*
|
|
227
234
|
* ### Example
|
|
228
235
|
*
|
|
@@ -233,6 +240,14 @@ export interface Type<
|
|
|
233
240
|
* // ✅ Good: App configuration that should crash on invalid values
|
|
234
241
|
* const appName = SimpleName.orThrow("MyApp");
|
|
235
242
|
*
|
|
243
|
+
* // ✅ Good: Instead of assert when Type error is clear enough
|
|
244
|
+
* // Context makes it obvious: count increments from non-negative value
|
|
245
|
+
* const currentCount = counts.get(id) ?? 0;
|
|
246
|
+
* const newCount = PositiveInt.orThrow(currentCount + 1);
|
|
247
|
+
*
|
|
248
|
+
* // ✅ Good: Test setup with known valid values
|
|
249
|
+
* const testUser = User.orThrow({ name: "Alice", age: 30 });
|
|
250
|
+
*
|
|
236
251
|
* // ❌ Avoid: User input (use `from` instead)
|
|
237
252
|
* const userAge = PositiveInt.orThrow(userInput); // Could crash!
|
|
238
253
|
*
|
|
@@ -1822,19 +1837,35 @@ export const formatNonNegativeError =
|
|
|
1822
1837
|
(error) => `The value ${error.value} must be non-negative (≥ 0).`,
|
|
1823
1838
|
);
|
|
1824
1839
|
|
|
1825
|
-
/**
|
|
1840
|
+
/**
|
|
1841
|
+
* Non-negative number (≥ 0).
|
|
1842
|
+
*
|
|
1843
|
+
* @category Number
|
|
1844
|
+
*/
|
|
1826
1845
|
export const NonNegativeNumber = nonNegative(Number);
|
|
1827
1846
|
export type NonNegativeNumber = typeof NonNegativeNumber.Type;
|
|
1828
1847
|
|
|
1829
|
-
/**
|
|
1848
|
+
/**
|
|
1849
|
+
* Positive number (> 0).
|
|
1850
|
+
*
|
|
1851
|
+
* @category Number
|
|
1852
|
+
*/
|
|
1830
1853
|
export const PositiveNumber = positive(NonNegativeNumber);
|
|
1831
1854
|
export type PositiveNumber = typeof PositiveNumber.Type;
|
|
1832
1855
|
|
|
1833
|
-
/**
|
|
1856
|
+
/**
|
|
1857
|
+
* Non-positive number (≤ 0).
|
|
1858
|
+
*
|
|
1859
|
+
* @category Number
|
|
1860
|
+
*/
|
|
1834
1861
|
export const NonPositiveNumber = nonPositive(Number);
|
|
1835
1862
|
export type NonPositiveNumber = typeof NonPositiveNumber.Type;
|
|
1836
1863
|
|
|
1837
|
-
/**
|
|
1864
|
+
/**
|
|
1865
|
+
* Negative number (< 0).
|
|
1866
|
+
*
|
|
1867
|
+
* @category Number
|
|
1868
|
+
*/
|
|
1838
1869
|
export const NegativeNumber = negative(NonPositiveNumber);
|
|
1839
1870
|
export type NegativeNumber = typeof NegativeNumber.Type;
|
|
1840
1871
|
|
|
@@ -1870,11 +1901,19 @@ export const formatIntError = createTypeErrorFormatter<IntError>(
|
|
|
1870
1901
|
export const Int = int(Number);
|
|
1871
1902
|
export type Int = typeof Int.Type;
|
|
1872
1903
|
|
|
1873
|
-
/**
|
|
1904
|
+
/**
|
|
1905
|
+
* Non-negative integer (≥ 0).
|
|
1906
|
+
*
|
|
1907
|
+
* @category Number
|
|
1908
|
+
*/
|
|
1874
1909
|
export const NonNegativeInt = nonNegative(Int);
|
|
1875
1910
|
export type NonNegativeInt = typeof NonNegativeInt.Type;
|
|
1876
1911
|
|
|
1877
|
-
/**
|
|
1912
|
+
/**
|
|
1913
|
+
* Positive integer (> 0).
|
|
1914
|
+
*
|
|
1915
|
+
* @category Number
|
|
1916
|
+
*/
|
|
1878
1917
|
export const PositiveInt = positive(NonNegativeInt);
|
|
1879
1918
|
export type PositiveInt = typeof PositiveInt.Type;
|
|
1880
1919
|
|
|
@@ -1883,11 +1922,19 @@ export const maxPositiveInt = PositiveInt.orThrow(
|
|
|
1883
1922
|
globalThis.Number.MAX_SAFE_INTEGER,
|
|
1884
1923
|
);
|
|
1885
1924
|
|
|
1886
|
-
/**
|
|
1925
|
+
/**
|
|
1926
|
+
* Non-positive integer (≤ 0).
|
|
1927
|
+
*
|
|
1928
|
+
* @category Number
|
|
1929
|
+
*/
|
|
1887
1930
|
export const NonPositiveInt = nonPositive(Int);
|
|
1888
1931
|
export type NonPositiveInt = typeof NonPositiveInt.Type;
|
|
1889
1932
|
|
|
1890
|
-
/**
|
|
1933
|
+
/**
|
|
1934
|
+
* Negative integer (< 0).
|
|
1935
|
+
*
|
|
1936
|
+
* @category Number
|
|
1937
|
+
*/
|
|
1891
1938
|
export const NegativeInt = negative(NonPositiveInt);
|
|
1892
1939
|
export type NegativeInt = typeof NegativeInt.Type;
|
|
1893
1940
|
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./Error.js";
|
|
|
12
12
|
export * from "./Evolu/Public.js";
|
|
13
13
|
export * from "./Function.js";
|
|
14
14
|
export * from "./Identicon.js";
|
|
15
|
+
export * from "./Instances.js";
|
|
15
16
|
export * from "./ManyToManyMap.js";
|
|
16
17
|
export * from "./Number.js";
|
|
17
18
|
export * from "./Object.js";
|