@evolu/common 8.10.0 → 8.11.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/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 +336 -211
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +102 -15
- 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 +94 -16
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +118 -38
- 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/Schema.d.ts +335 -21
- 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 +192 -14
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +81 -20
- 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/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 +15 -6
- package/src/local-first/Db.ts +644 -339
- package/src/local-first/Evolu.test.ts +686 -21
- package/src/local-first/Evolu.ts +450 -228
- package/src/local-first/Owner.ts +13 -30
- package/src/local-first/Protocol.test.ts +617 -10
- package/src/local-first/Protocol.ts +196 -72
- package/src/local-first/Query.ts +8 -15
- package/src/local-first/Schema.test.ts +143 -0
- package/src/local-first/Schema.ts +363 -24
- package/src/local-first/Shared.test.ts +7731 -559
- package/src/local-first/Shared.ts +2036 -267
- package/src/local-first/Storage.ts +218 -32
- 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/Crypto.js
CHANGED
|
@@ -14,14 +14,44 @@ import { randomBytes, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
|
14
14
|
import { trySync } from "./Result.js";
|
|
15
15
|
import { brand, length, NonNegativeInt, Uint8Array, zeroNonNegativeInt, } from "./Type.js";
|
|
16
16
|
const Entropy = /*#__PURE__*/ brand("Entropy", Uint8Array);
|
|
17
|
+
/**
|
|
18
|
+
* Cryptographic entropy of exactly 16 bytes.
|
|
19
|
+
*
|
|
20
|
+
* @group Random bytes
|
|
21
|
+
*/
|
|
17
22
|
export const Entropy16 = /*#__PURE__*/ length(16)(Entropy);
|
|
23
|
+
/**
|
|
24
|
+
* Cryptographic entropy of exactly 24 bytes.
|
|
25
|
+
*
|
|
26
|
+
* @group Random bytes
|
|
27
|
+
*/
|
|
18
28
|
export const Entropy24 = /*#__PURE__*/ length(24)(Entropy);
|
|
29
|
+
/**
|
|
30
|
+
* Cryptographic entropy of exactly 32 bytes.
|
|
31
|
+
*
|
|
32
|
+
* @group Random bytes
|
|
33
|
+
*/
|
|
19
34
|
export const Entropy32 = /*#__PURE__*/ length(32)(Entropy);
|
|
35
|
+
/**
|
|
36
|
+
* Cryptographic entropy of exactly 64 bytes.
|
|
37
|
+
*
|
|
38
|
+
* @group Random bytes
|
|
39
|
+
*/
|
|
20
40
|
export const Entropy64 = /*#__PURE__*/ length(64)(Entropy);
|
|
41
|
+
/**
|
|
42
|
+
* Creates {@link RandomBytes} backed by the platform's secure random number
|
|
43
|
+
* generator.
|
|
44
|
+
*
|
|
45
|
+
* @group Random bytes
|
|
46
|
+
*/
|
|
21
47
|
export const createRandomBytes = () => ({
|
|
22
48
|
create: randomBytes,
|
|
23
49
|
});
|
|
24
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Creates seeded random bytes for deterministic tests.
|
|
52
|
+
*
|
|
53
|
+
* @group Testing
|
|
54
|
+
*/
|
|
25
55
|
export const testCreateRandomBytes = (deps) => ({
|
|
26
56
|
create: (bytesLength) => globalThis.Uint8Array.from({ length: bytesLength }, () => deps.randomLib.int(0, 255)),
|
|
27
57
|
});
|
|
@@ -29,6 +59,8 @@ export const testCreateRandomBytes = (deps) => ({
|
|
|
29
59
|
* SLIP21.
|
|
30
60
|
*
|
|
31
61
|
* https://github.com/satoshilabs/slips/blob/master/slip-0021.md
|
|
62
|
+
*
|
|
63
|
+
* @group Key derivation
|
|
32
64
|
*/
|
|
33
65
|
export const createSlip21 = (seed, path) => {
|
|
34
66
|
let currentNode = hmac(sha512, utf8ToBytes("Symmetric key seed"), seed);
|
|
@@ -41,6 +73,7 @@ export const createSlip21 = (seed, path) => {
|
|
|
41
73
|
/**
|
|
42
74
|
* Derives a single node in the SLIP-21 hierarchical key derivation.
|
|
43
75
|
*
|
|
76
|
+
* @group Key derivation
|
|
44
77
|
* @see {@link createSlip21}
|
|
45
78
|
*/
|
|
46
79
|
export const deriveSlip21Node = (label, parentNode) => {
|
|
@@ -50,13 +83,22 @@ export const deriveSlip21Node = (label, parentNode) => {
|
|
|
50
83
|
message.set(labelBytes, 1);
|
|
51
84
|
return hmac(sha512, parentNode.slice(0, 32), message);
|
|
52
85
|
};
|
|
53
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* The encryption key for symmetric encryption.
|
|
88
|
+
*
|
|
89
|
+
* @group Encryption
|
|
90
|
+
*/
|
|
54
91
|
export const EncryptionKey = /*#__PURE__*/ brand("EncryptionKey", Entropy32);
|
|
55
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* The nonce length for XChaCha20-Poly1305 encryption.
|
|
94
|
+
*
|
|
95
|
+
* @group Encryption
|
|
96
|
+
*/
|
|
56
97
|
export const xChaCha20Poly1305NonceLength = 24;
|
|
57
98
|
/**
|
|
58
99
|
* Branded Uint8Array for XChaCha20-Poly1305 encryption.
|
|
59
100
|
*
|
|
101
|
+
* @group Encryption
|
|
60
102
|
* @see {@link encryptWithXChaCha20Poly1305}
|
|
61
103
|
*/
|
|
62
104
|
export const XChaCha20Poly1305Ciphertext = /*#__PURE__*/ brand("XChaCha20Poly1305Ciphertext", Uint8Array);
|
|
@@ -89,6 +131,7 @@ export const XChaCha20Poly1305Ciphertext = /*#__PURE__*/ brand("XChaCha20Poly130
|
|
|
89
131
|
* assertEqual(nonce.length, 24);
|
|
90
132
|
* ```
|
|
91
133
|
*
|
|
134
|
+
* @group Encryption
|
|
92
135
|
* @see https://github.com/paulmillr/noble-ciphers
|
|
93
136
|
*/
|
|
94
137
|
export const encryptWithXChaCha20Poly1305 = (deps) => (plaintext, encryptionKey) => {
|
|
@@ -135,6 +178,8 @@ export const encryptWithXChaCha20Poly1305 = (deps) => (plaintext, encryptionKey)
|
|
|
135
178
|
*
|
|
136
179
|
* assertOk(decryptMessage(), "secret message");
|
|
137
180
|
* ```
|
|
181
|
+
*
|
|
182
|
+
* @group Encryption
|
|
138
183
|
*/
|
|
139
184
|
export const decryptWithXChaCha20Poly1305 = (ciphertext, nonce, encryptionKey) => trySync(() => xchacha20poly1305(encryptionKey, nonce).decrypt(ciphertext), (error) => ({
|
|
140
185
|
type: "DecryptWithXChaCha20Poly1305Error",
|
|
@@ -147,6 +192,8 @@ export const decryptWithXChaCha20Poly1305 = (ciphertext, nonce, encryptionKey) =
|
|
|
147
192
|
* wide range of encrypted data sizes.
|
|
148
193
|
*
|
|
149
194
|
* See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
|
|
195
|
+
*
|
|
196
|
+
* @group Padding
|
|
150
197
|
*/
|
|
151
198
|
export const createPadmePaddedLength = (length) => {
|
|
152
199
|
if (length <= 0)
|
|
@@ -157,7 +204,11 @@ export const createPadmePaddedLength = (length) => {
|
|
|
157
204
|
const mask = (1 << z) - 1;
|
|
158
205
|
return NonNegativeInt.orThrow((length + mask) & ~mask);
|
|
159
206
|
};
|
|
160
|
-
/**
|
|
207
|
+
/**
|
|
208
|
+
* Creates a PADMÉ padding array of zeros for the given input length.
|
|
209
|
+
*
|
|
210
|
+
* @group Padding
|
|
211
|
+
*/
|
|
161
212
|
export const createPadmePadding = (length) => {
|
|
162
213
|
const paddedLength = createPadmePaddedLength(length);
|
|
163
214
|
const paddingLength = NonNegativeInt.orThrow(paddedLength - length);
|
package/dist/src/Error.d.ts
CHANGED
|
@@ -29,4 +29,49 @@ export interface UnknownError extends InferType<typeof UnknownError> {
|
|
|
29
29
|
* non-enumerable. This function extracts those properties into a plain object.
|
|
30
30
|
*/
|
|
31
31
|
export declare const createUnknownError: (error: unknown) => UnknownError;
|
|
32
|
+
/**
|
|
33
|
+
* Converts a reported defect to an `Error` that a host error reporter shows
|
|
34
|
+
* readably.
|
|
35
|
+
*
|
|
36
|
+
* Hosts such as browsers and React Native show a reported value that is not an
|
|
37
|
+
* `Error` only as text such as "[object Object]", and a worker's error reaches
|
|
38
|
+
* its page, including an error tracker listening there, as that text alone. A
|
|
39
|
+
* panic reports a plain {@link AbortError}, so its defect is converted instead.
|
|
40
|
+
* An `Error` is returned as it is, including one from another realm, such as an
|
|
41
|
+
* iframe. A `DOMException` is described in an `Error` with its name and
|
|
42
|
+
* message, because Chromium reports one from a worker without them. Any other
|
|
43
|
+
* value is described in an `Error` whose cause is what was reported.
|
|
44
|
+
*
|
|
45
|
+
* Platform {@link createRun} adapters use it for their default reporting. A
|
|
46
|
+
* custom {@link ReportDefect} can use it too, such as before passing a defect to
|
|
47
|
+
* an error tracker.
|
|
48
|
+
*
|
|
49
|
+
* ### Example
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import {
|
|
53
|
+
* assertEqual,
|
|
54
|
+
* assertSame,
|
|
55
|
+
* createRun,
|
|
56
|
+
* defectToError,
|
|
57
|
+
* } from "@evolu/common";
|
|
58
|
+
*
|
|
59
|
+
* const errors: Array<Error> = [];
|
|
60
|
+
* await using run = createRun({
|
|
61
|
+
* reportDefect: (reported) => {
|
|
62
|
+
* errors.push(defectToError(reported));
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
* const defect = new Error("boom");
|
|
66
|
+
*
|
|
67
|
+
* run.panic(defect);
|
|
68
|
+
*
|
|
69
|
+
* assertSame(errors[0], defect);
|
|
70
|
+
* assertEqual(
|
|
71
|
+
* defectToError({ type: "UnexpectedState" }).message,
|
|
72
|
+
* 'Defect: {"type":"UnexpectedState"}',
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare const defectToError: (reported: unknown) => Error;
|
|
32
77
|
//# sourceMappingURL=Error.d.ts.map
|
package/dist/src/Error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,KAAK,SAAS,EAAS,KAAK,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,CAClC,cAAc,EACd;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,OAAO,CAAA;CAAE,CAGlC,CAAC;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,OAAO,YAAY,CAAC;CAAG;AAEvE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,YAkDnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,aAAa,aAAc,OAAO,KAAG,KAuBjD,CAAC"}
|
package/dist/src/Error.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import { safelyStringifyUnknownValue } from "./String.js";
|
|
7
|
+
import { AbortError } from "./Task.js";
|
|
6
8
|
import { typed, Unknown } from "./Type.js";
|
|
7
9
|
/**
|
|
8
10
|
* A wrapper for unknown errors caught at runtime.
|
|
@@ -76,3 +78,70 @@ export const createUnknownError = (error) => {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Converts a reported defect to an `Error` that a host error reporter shows
|
|
83
|
+
* readably.
|
|
84
|
+
*
|
|
85
|
+
* Hosts such as browsers and React Native show a reported value that is not an
|
|
86
|
+
* `Error` only as text such as "[object Object]", and a worker's error reaches
|
|
87
|
+
* its page, including an error tracker listening there, as that text alone. A
|
|
88
|
+
* panic reports a plain {@link AbortError}, so its defect is converted instead.
|
|
89
|
+
* An `Error` is returned as it is, including one from another realm, such as an
|
|
90
|
+
* iframe. A `DOMException` is described in an `Error` with its name and
|
|
91
|
+
* message, because Chromium reports one from a worker without them. Any other
|
|
92
|
+
* value is described in an `Error` whose cause is what was reported.
|
|
93
|
+
*
|
|
94
|
+
* Platform {@link createRun} adapters use it for their default reporting. A
|
|
95
|
+
* custom {@link ReportDefect} can use it too, such as before passing a defect to
|
|
96
|
+
* an error tracker.
|
|
97
|
+
*
|
|
98
|
+
* ### Example
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import {
|
|
102
|
+
* assertEqual,
|
|
103
|
+
* assertSame,
|
|
104
|
+
* createRun,
|
|
105
|
+
* defectToError,
|
|
106
|
+
* } from "@evolu/common";
|
|
107
|
+
*
|
|
108
|
+
* const errors: Array<Error> = [];
|
|
109
|
+
* await using run = createRun({
|
|
110
|
+
* reportDefect: (reported) => {
|
|
111
|
+
* errors.push(defectToError(reported));
|
|
112
|
+
* },
|
|
113
|
+
* });
|
|
114
|
+
* const defect = new Error("boom");
|
|
115
|
+
*
|
|
116
|
+
* run.panic(defect);
|
|
117
|
+
*
|
|
118
|
+
* assertSame(errors[0], defect);
|
|
119
|
+
* assertEqual(
|
|
120
|
+
* defectToError({ type: "UnexpectedState" }).message,
|
|
121
|
+
* 'Defect: {"type":"UnexpectedState"}',
|
|
122
|
+
* );
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export const defectToError = (reported) => {
|
|
126
|
+
const defect = AbortError.is(reported) && reported.reason.type === "PanicAbortReason"
|
|
127
|
+
? reported.reason.defect
|
|
128
|
+
: reported;
|
|
129
|
+
// The internal tag survives crossing realms, such as from an iframe, where
|
|
130
|
+
// instanceof fails.
|
|
131
|
+
const tag = Object.prototype.toString.call(defect);
|
|
132
|
+
// Chromium reports a DOMException from a worker without its name or message,
|
|
133
|
+
// so it is described in an Error.
|
|
134
|
+
if (tag === "[object DOMException]") {
|
|
135
|
+
const { name, message } = defect;
|
|
136
|
+
return new Error(`${name}: ${message}`, { cause: defect });
|
|
137
|
+
}
|
|
138
|
+
if (defect instanceof Error || tag === "[object Error]") {
|
|
139
|
+
return defect;
|
|
140
|
+
}
|
|
141
|
+
// A value with a cycle or a bigint falls back to String, often
|
|
142
|
+
// "[object Object]", and a nested Error shows as "{}". That is enough:
|
|
143
|
+
// Evolu's own defects are Errors, and the cause still holds the value.
|
|
144
|
+
return new Error(`Defect: ${safelyStringifyUnknownValue(defect)}`, {
|
|
145
|
+
cause: reported,
|
|
146
|
+
});
|
|
147
|
+
};
|
package/dist/src/Fs.d.ts
CHANGED
|
@@ -58,7 +58,11 @@
|
|
|
58
58
|
import type { ByteLength } from "./Bytes.ts";
|
|
59
59
|
import type { Task } from "./Task.ts";
|
|
60
60
|
import type { Typed } from "./Type.ts";
|
|
61
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Asynchronous file system operations.
|
|
63
|
+
*
|
|
64
|
+
* @group Core
|
|
65
|
+
*/
|
|
62
66
|
export interface Fs {
|
|
63
67
|
/**
|
|
64
68
|
* Reads a whole file, as bytes by default or as a string with an encoding. An
|
|
@@ -127,24 +131,48 @@ export interface Fs {
|
|
|
127
131
|
*/
|
|
128
132
|
readonly createTempDirectory: (options?: FsCreateTempDirectoryOptions) => Task<FsTempDirectory, FsError>;
|
|
129
133
|
}
|
|
130
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Dependency wrapper for {@link Fs}.
|
|
136
|
+
*
|
|
137
|
+
* @group Core
|
|
138
|
+
*/
|
|
131
139
|
export interface FsDep {
|
|
132
140
|
readonly fs: Fs;
|
|
133
141
|
}
|
|
134
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* A file system path, or a `file:` URL.
|
|
144
|
+
*
|
|
145
|
+
* @group Core
|
|
146
|
+
*/
|
|
135
147
|
export type FsPath = string | URL;
|
|
136
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* Supported text encodings.
|
|
150
|
+
*
|
|
151
|
+
* @group Core
|
|
152
|
+
*/
|
|
137
153
|
export type FsEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "utf-16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
138
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* Supported file opening modes for {@link Fs.writeFile}.
|
|
156
|
+
*
|
|
157
|
+
* @group Core
|
|
158
|
+
*/
|
|
139
159
|
export type FsOpenFlag = "a" | "ax" | "a+" | "ax+" | "as" | "as+" | "r" | "r+" | "rs+" | "w" | "wx" | "w+" | "wx+";
|
|
140
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Reads bytes by default, or text when an encoding is specified.
|
|
162
|
+
*
|
|
163
|
+
* @group Core
|
|
164
|
+
*/
|
|
141
165
|
export interface FsReadFile {
|
|
142
166
|
(path: FsPath): Task<Uint8Array, FsError>;
|
|
143
167
|
(path: FsPath, encoding: FsEncoding | {
|
|
144
168
|
readonly encoding: FsEncoding;
|
|
145
169
|
}): Task<string, FsError>;
|
|
146
170
|
}
|
|
147
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Options for {@link Fs.writeFile}.
|
|
173
|
+
*
|
|
174
|
+
* @group Options
|
|
175
|
+
*/
|
|
148
176
|
export interface FsWriteFileOptions {
|
|
149
177
|
/** Encoding of string data. Defaults to `utf8`. */
|
|
150
178
|
readonly encoding?: FsEncoding;
|
|
@@ -153,19 +181,31 @@ export interface FsWriteFileOptions {
|
|
|
153
181
|
/** Open flag. Defaults to `w`; use `wx` to fail when the file exists. */
|
|
154
182
|
readonly flag?: FsOpenFlag;
|
|
155
183
|
}
|
|
156
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* Options for {@link Fs.readDirectory}.
|
|
186
|
+
*
|
|
187
|
+
* @group Options
|
|
188
|
+
*/
|
|
157
189
|
export interface FsReadDirectoryOptions {
|
|
158
190
|
/** Includes entries from nested directories. Defaults to `false`. */
|
|
159
191
|
readonly recursive?: boolean;
|
|
160
192
|
}
|
|
161
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Options for {@link Fs.createDirectory}.
|
|
195
|
+
*
|
|
196
|
+
* @group Options
|
|
197
|
+
*/
|
|
162
198
|
export interface FsCreateDirectoryOptions {
|
|
163
199
|
/** Creates missing parents and accepts an existing directory. */
|
|
164
200
|
readonly recursive?: boolean;
|
|
165
201
|
/** Directory mode. Defaults to `0o777`. */
|
|
166
202
|
readonly mode?: number;
|
|
167
203
|
}
|
|
168
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Options for {@link Fs.copy}.
|
|
206
|
+
*
|
|
207
|
+
* @group Options
|
|
208
|
+
*/
|
|
169
209
|
export interface FsCopyOptions {
|
|
170
210
|
/**
|
|
171
211
|
* Node's `force` option. Replaces existing files; `false` skips them unless
|
|
@@ -182,12 +222,20 @@ export interface FsCopyOptions {
|
|
|
182
222
|
/** Preserves access and modification times. Defaults to `false`. */
|
|
183
223
|
readonly preserveTimestamps?: boolean;
|
|
184
224
|
}
|
|
185
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* Options for {@link Fs.copyFile}.
|
|
227
|
+
*
|
|
228
|
+
* @group Options
|
|
229
|
+
*/
|
|
186
230
|
export interface FsCopyFileOptions {
|
|
187
231
|
/** Replaces an existing destination file. Defaults to `false`. */
|
|
188
232
|
readonly overwrite?: boolean;
|
|
189
233
|
}
|
|
190
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* Options for {@link Fs.remove}.
|
|
236
|
+
*
|
|
237
|
+
* @group Options
|
|
238
|
+
*/
|
|
191
239
|
export interface FsRemoveOptions {
|
|
192
240
|
/** Removes directories and their contents. */
|
|
193
241
|
readonly recursive?: boolean;
|
|
@@ -204,7 +252,11 @@ export interface FsRemoveOptions {
|
|
|
204
252
|
*/
|
|
205
253
|
readonly retryDelay?: number;
|
|
206
254
|
}
|
|
207
|
-
/**
|
|
255
|
+
/**
|
|
256
|
+
* File metadata as data, with Node's numeric and timestamp field names.
|
|
257
|
+
*
|
|
258
|
+
* @group Core
|
|
259
|
+
*/
|
|
208
260
|
export interface FsMetadata {
|
|
209
261
|
readonly type: FsEntryType;
|
|
210
262
|
readonly dev: number;
|
|
@@ -226,20 +278,36 @@ export interface FsMetadata {
|
|
|
226
278
|
readonly ctime: Date;
|
|
227
279
|
readonly birthtime: Date;
|
|
228
280
|
}
|
|
229
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* The kind of file system entry described by {@link FsMetadata}.
|
|
283
|
+
*
|
|
284
|
+
* @group Core
|
|
285
|
+
*/
|
|
230
286
|
export type FsEntryType = "File" | "Directory" | "SymbolicLink" | "BlockDevice" | "CharacterDevice" | "FIFO" | "Socket" | "Unknown";
|
|
231
|
-
/**
|
|
287
|
+
/**
|
|
288
|
+
* Options for {@link Fs.createTempDirectory}.
|
|
289
|
+
*
|
|
290
|
+
* @group Options
|
|
291
|
+
*/
|
|
232
292
|
export interface FsCreateTempDirectoryOptions {
|
|
233
293
|
/** Existing parent directory. Defaults to the system temporary directory. */
|
|
234
294
|
readonly directory?: string;
|
|
235
295
|
/** Prefix for the directory name. Defaults to an empty string. */
|
|
236
296
|
readonly prefix?: string;
|
|
237
297
|
}
|
|
238
|
-
/**
|
|
298
|
+
/**
|
|
299
|
+
* A temporary directory removed, with its contents, on asynchronous disposal.
|
|
300
|
+
*
|
|
301
|
+
* @group Core
|
|
302
|
+
*/
|
|
239
303
|
export interface FsTempDirectory extends AsyncDisposable {
|
|
240
304
|
readonly path: string;
|
|
241
305
|
}
|
|
242
|
-
/**
|
|
306
|
+
/**
|
|
307
|
+
* A failed file system operation.
|
|
308
|
+
*
|
|
309
|
+
* @group Errors
|
|
310
|
+
*/
|
|
243
311
|
export interface FsError extends Typed<"FsError"> {
|
|
244
312
|
readonly reason: FsErrorReason;
|
|
245
313
|
/**
|
|
@@ -259,7 +327,11 @@ export interface FsError extends Typed<"FsError"> {
|
|
|
259
327
|
/** The platform's diagnostic message. */
|
|
260
328
|
readonly message: string;
|
|
261
329
|
}
|
|
262
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
* Why a file system operation failed, mapped from the platform's error code.
|
|
332
|
+
*
|
|
333
|
+
* @group Errors
|
|
334
|
+
*/
|
|
263
335
|
export type FsErrorReason = "NotFound" | "AlreadyExists" | "PermissionDenied" | "IsDirectory" | "NotDirectory" | "NotEmpty" | "Busy" | "Unknown";
|
|
264
336
|
/**
|
|
265
337
|
* Creates a test {@link Fs} with the supplied operation overrides.
|
|
@@ -297,6 +369,8 @@ export type FsErrorReason = "NotFound" | "AlreadyExists" | "PermissionDenied" |
|
|
|
297
369
|
*
|
|
298
370
|
* assertOk(await run(saveMessage));
|
|
299
371
|
* ```
|
|
372
|
+
*
|
|
373
|
+
* @group Testing
|
|
300
374
|
*/
|
|
301
375
|
export declare const testCreateFs: (overrides?: Partial<Fs>) => Fs;
|
|
302
376
|
//# sourceMappingURL=Fs.d.ts.map
|
package/dist/src/Fs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1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,EAazD,CAAC"}
|
package/dist/src/Fs.js
CHANGED
package/dist/src/Identicon.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type IdenticonStyle = "github" | "quadrant" | "gradient" | "sutnar";
|
|
|
32
32
|
* assertTrue,
|
|
33
33
|
* createIdFromString,
|
|
34
34
|
* createIdenticon,
|
|
35
|
+
* testTodoId,
|
|
35
36
|
* } from "@evolu/common";
|
|
36
37
|
*
|
|
37
38
|
* const id = createIdFromString("identicon-example");
|
|
@@ -42,8 +43,7 @@ export type IdenticonStyle = "github" | "quadrant" | "gradient" | "sutnar";
|
|
|
42
43
|
* );
|
|
43
44
|
*
|
|
44
45
|
* // Branded IDs work too.
|
|
45
|
-
* const
|
|
46
|
-
* const todoSvg = createIdenticon(todoId);
|
|
46
|
+
* const todoSvg = createIdenticon(testTodoId);
|
|
47
47
|
*
|
|
48
48
|
* assertTrue(svg.startsWith("<svg"));
|
|
49
49
|
* assertEqual(new Set([svg, ...alternativeSvgs]).size, 4);
|
package/dist/src/Identicon.js
CHANGED
|
@@ -25,6 +25,7 @@ import { Id, idToIdBytes } from "./Type.js";
|
|
|
25
25
|
* assertTrue,
|
|
26
26
|
* createIdFromString,
|
|
27
27
|
* createIdenticon,
|
|
28
|
+
* testTodoId,
|
|
28
29
|
* } from "@evolu/common";
|
|
29
30
|
*
|
|
30
31
|
* const id = createIdFromString("identicon-example");
|
|
@@ -35,8 +36,7 @@ import { Id, idToIdBytes } from "./Type.js";
|
|
|
35
36
|
* );
|
|
36
37
|
*
|
|
37
38
|
* // Branded IDs work too.
|
|
38
|
-
* const
|
|
39
|
-
* const todoSvg = createIdenticon(todoId);
|
|
39
|
+
* const todoSvg = createIdenticon(testTodoId);
|
|
40
40
|
*
|
|
41
41
|
* assertTrue(svg.startsWith("<svg"));
|
|
42
42
|
* assertEqual(new Set([svg, ...alternativeSvgs]).size, 4);
|
|
@@ -19,6 +19,8 @@ import { type ConsoleDep } from "./Console.ts";
|
|
|
19
19
|
* a warning may come late or, in short-lived processes, never. It is a
|
|
20
20
|
* development canary, not a guarantee. Production uses
|
|
21
21
|
* {@link noopLeakDetector}.
|
|
22
|
+
*
|
|
23
|
+
* @group Core
|
|
22
24
|
*/
|
|
23
25
|
export interface LeakDetector {
|
|
24
26
|
/**
|
|
@@ -33,7 +35,11 @@ export interface LeakDetector {
|
|
|
33
35
|
/** Stops tracking the target registered with `unregisterToken`. */
|
|
34
36
|
readonly untrack: (unregisterToken: object) => void;
|
|
35
37
|
}
|
|
36
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Describes a tracked handle for {@link LeakDetector.track}.
|
|
40
|
+
*
|
|
41
|
+
* @group Core
|
|
42
|
+
*/
|
|
37
43
|
export interface Leak {
|
|
38
44
|
/** Handle name used in the warning, for example `"Lease"`. */
|
|
39
45
|
readonly name: string;
|
|
@@ -43,6 +49,7 @@ export interface Leak {
|
|
|
43
49
|
/**
|
|
44
50
|
* Dependency wrapper for {@link LeakDetector}.
|
|
45
51
|
*
|
|
52
|
+
* @group Core
|
|
46
53
|
* @see {@link LeakDetector}
|
|
47
54
|
*/
|
|
48
55
|
export interface LeakDetectorDep {
|
|
@@ -53,13 +60,20 @@ export interface LeakDetectorDep {
|
|
|
53
60
|
*
|
|
54
61
|
* Capturing a stack per track call is too expensive for production; use
|
|
55
62
|
* {@link noopLeakDetector} there.
|
|
63
|
+
*
|
|
64
|
+
* @group Core
|
|
56
65
|
*/
|
|
57
66
|
export declare const createLeakDetector: (deps: ConsoleDep) => LeakDetector;
|
|
58
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* No-op {@link LeakDetector} for production.
|
|
69
|
+
*
|
|
70
|
+
* @group Core
|
|
71
|
+
*/
|
|
59
72
|
export declare const noopLeakDetector: LeakDetector;
|
|
60
73
|
/**
|
|
61
74
|
* Test {@link LeakDetector} with deterministic collection.
|
|
62
75
|
*
|
|
76
|
+
* @group Testing
|
|
63
77
|
* @see {@link testCreateLeakDetector}
|
|
64
78
|
*/
|
|
65
79
|
export interface TestLeakDetector extends LeakDetector {
|
|
@@ -78,11 +92,16 @@ export interface TestLeakDetector extends LeakDetector {
|
|
|
78
92
|
/**
|
|
79
93
|
* Dependency wrapper for {@link TestLeakDetector}.
|
|
80
94
|
*
|
|
95
|
+
* @group Testing
|
|
81
96
|
* @see {@link TestLeakDetector}
|
|
82
97
|
*/
|
|
83
98
|
export interface TestLeakDetectorDep extends LeakDetectorDep {
|
|
84
99
|
readonly leakDetector: TestLeakDetector;
|
|
85
100
|
}
|
|
86
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Creates {@link TestLeakDetector}.
|
|
103
|
+
*
|
|
104
|
+
* @group Testing
|
|
105
|
+
*/
|
|
87
106
|
export declare const testCreateLeakDetector: (deps: ConsoleDep) => TestLeakDetector;
|
|
88
107
|
//# sourceMappingURL=LeakDetector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LeakDetector.d.ts","sourceRoot":"","sources":["../../src/LeakDetector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C
|
|
1
|
+
{"version":3,"file":"LeakDetector.d.ts","sourceRoot":"","sources":["../../src/LeakDetector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,KAAK,IAAI,CAAC;IAE9E,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,CAAC,eAAe,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACnB,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,SAAU,UAAU,KAAG,YAsBrD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,YAG9B,CAAC;AAyBF;;;;;GAKG;AACH,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC;IAE/B,uDAAuD;IACvD,QAAQ,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CACnE;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,QAAQ,CAAC,YAAY,EAAE,gBAAgB,CAAC;CACzC;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,SAAU,UAAU,KAAG,gBAsCzD,CAAC"}
|
package/dist/src/LeakDetector.js
CHANGED
|
@@ -10,6 +10,8 @@ import { constVoid } from "./Function.js";
|
|
|
10
10
|
*
|
|
11
11
|
* Capturing a stack per track call is too expensive for production; use
|
|
12
12
|
* {@link noopLeakDetector} there.
|
|
13
|
+
*
|
|
14
|
+
* @group Core
|
|
13
15
|
*/
|
|
14
16
|
export const createLeakDetector = (deps) => {
|
|
15
17
|
if (typeof globalThis.FinalizationRegistry !== "function")
|
|
@@ -28,7 +30,11 @@ export const createLeakDetector = (deps) => {
|
|
|
28
30
|
},
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* No-op {@link LeakDetector} for production.
|
|
35
|
+
*
|
|
36
|
+
* @group Core
|
|
37
|
+
*/
|
|
32
38
|
export const noopLeakDetector = {
|
|
33
39
|
track: constVoid,
|
|
34
40
|
untrack: constVoid,
|
|
@@ -47,7 +53,11 @@ const reportLeak = (deps) => (leak) => {
|
|
|
47
53
|
deps.console.warn(`${leak.name} was garbage-collected without cleanup. Tracked at:`, leak.stack);
|
|
48
54
|
return true;
|
|
49
55
|
};
|
|
50
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Creates {@link TestLeakDetector}.
|
|
58
|
+
*
|
|
59
|
+
* @group Testing
|
|
60
|
+
*/
|
|
51
61
|
export const testCreateLeakDetector = (deps) => {
|
|
52
62
|
const trackedLeaksByToken = new Map();
|
|
53
63
|
const report = reportLeak(deps);
|