@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/Crypto.d.ts
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
import type { RandomLibDep } from "./Random.ts";
|
|
11
11
|
import type { Result } from "./Result.ts";
|
|
12
12
|
import { NonNegativeInt, type Typed } from "./Type.ts";
|
|
13
|
+
/**
|
|
14
|
+
* Cryptographically secure random bytes with length-branded results.
|
|
15
|
+
*
|
|
16
|
+
* @group Random bytes
|
|
17
|
+
*/
|
|
13
18
|
export interface RandomBytes {
|
|
14
19
|
/**
|
|
15
20
|
* Creates cryptographically secure random bytes with type-safe length
|
|
@@ -62,42 +67,89 @@ export interface RandomBytes {
|
|
|
62
67
|
create(bytesLength: 64): Entropy64;
|
|
63
68
|
create(bytesLength: number): Entropy;
|
|
64
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Dependency wrapper for {@link RandomBytes}.
|
|
72
|
+
*
|
|
73
|
+
* @group Random bytes
|
|
74
|
+
*/
|
|
65
75
|
export interface RandomBytesDep {
|
|
66
76
|
readonly randomBytes: RandomBytes;
|
|
67
77
|
}
|
|
68
78
|
declare const Entropy: import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>;
|
|
69
79
|
type Entropy = typeof Entropy.Output;
|
|
80
|
+
/**
|
|
81
|
+
* Cryptographic entropy of exactly 16 bytes.
|
|
82
|
+
*
|
|
83
|
+
* @group Random bytes
|
|
84
|
+
*/
|
|
70
85
|
export declare const Entropy16: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length16", import("./Type.ts").LengthError<16>>;
|
|
71
86
|
export type Entropy16 = typeof Entropy16.Output;
|
|
87
|
+
/**
|
|
88
|
+
* Cryptographic entropy of exactly 24 bytes.
|
|
89
|
+
*
|
|
90
|
+
* @group Random bytes
|
|
91
|
+
*/
|
|
72
92
|
export declare const Entropy24: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length24", import("./Type.ts").LengthError<24>>;
|
|
73
93
|
export type Entropy24 = typeof Entropy24.Output;
|
|
94
|
+
/**
|
|
95
|
+
* Cryptographic entropy of exactly 32 bytes.
|
|
96
|
+
*
|
|
97
|
+
* @group Random bytes
|
|
98
|
+
*/
|
|
74
99
|
export declare const Entropy32: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length32", import("./Type.ts").LengthError<32>>;
|
|
75
100
|
export type Entropy32 = typeof Entropy32.Output;
|
|
101
|
+
/**
|
|
102
|
+
* Cryptographic entropy of exactly 64 bytes.
|
|
103
|
+
*
|
|
104
|
+
* @group Random bytes
|
|
105
|
+
*/
|
|
76
106
|
export declare const Entropy64: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length64", import("./Type.ts").LengthError<64>>;
|
|
77
107
|
export type Entropy64 = typeof Entropy64.Output;
|
|
108
|
+
/**
|
|
109
|
+
* Creates {@link RandomBytes} backed by the platform's secure random number
|
|
110
|
+
* generator.
|
|
111
|
+
*
|
|
112
|
+
* @group Random bytes
|
|
113
|
+
*/
|
|
78
114
|
export declare const createRandomBytes: () => RandomBytes;
|
|
79
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Creates seeded random bytes for deterministic tests.
|
|
117
|
+
*
|
|
118
|
+
* @group Testing
|
|
119
|
+
*/
|
|
80
120
|
export declare const testCreateRandomBytes: (deps: RandomLibDep) => RandomBytes;
|
|
81
121
|
/**
|
|
82
122
|
* SLIP21.
|
|
83
123
|
*
|
|
84
124
|
* https://github.com/satoshilabs/slips/blob/master/slip-0021.md
|
|
125
|
+
*
|
|
126
|
+
* @group Key derivation
|
|
85
127
|
*/
|
|
86
128
|
export declare const createSlip21: (seed: Entropy16 | Entropy32 | Entropy64, path: ReadonlyArray<string | number>) => Entropy32;
|
|
87
129
|
/**
|
|
88
130
|
* Derives a single node in the SLIP-21 hierarchical key derivation.
|
|
89
131
|
*
|
|
132
|
+
* @group Key derivation
|
|
90
133
|
* @see {@link createSlip21}
|
|
91
134
|
*/
|
|
92
135
|
export declare const deriveSlip21Node: (label: string, parentNode: Entropy64) => Entropy64;
|
|
93
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* The encryption key for symmetric encryption.
|
|
138
|
+
*
|
|
139
|
+
* @group Encryption
|
|
140
|
+
*/
|
|
94
141
|
export declare const EncryptionKey: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length32", import("./Type.ts").LengthError<32>>, "EncryptionKey", never>;
|
|
95
142
|
export type EncryptionKey = typeof EncryptionKey.Output;
|
|
96
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* The nonce length for XChaCha20-Poly1305 encryption.
|
|
145
|
+
*
|
|
146
|
+
* @group Encryption
|
|
147
|
+
*/
|
|
97
148
|
export declare const xChaCha20Poly1305NonceLength = 24;
|
|
98
149
|
/**
|
|
99
150
|
* Branded Uint8Array for XChaCha20-Poly1305 encryption.
|
|
100
151
|
*
|
|
152
|
+
* @group Encryption
|
|
101
153
|
* @see {@link encryptWithXChaCha20Poly1305}
|
|
102
154
|
*/
|
|
103
155
|
export declare const XChaCha20Poly1305Ciphertext: import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "XChaCha20Poly1305Ciphertext", never>;
|
|
@@ -131,9 +183,15 @@ export type XChaCha20Poly1305Ciphertext = typeof XChaCha20Poly1305Ciphertext.Out
|
|
|
131
183
|
* assertEqual(nonce.length, 24);
|
|
132
184
|
* ```
|
|
133
185
|
*
|
|
186
|
+
* @group Encryption
|
|
134
187
|
* @see https://github.com/paulmillr/noble-ciphers
|
|
135
188
|
*/
|
|
136
189
|
export declare const encryptWithXChaCha20Poly1305: (deps: RandomBytesDep) => (plaintext: Uint8Array, encryptionKey: EncryptionKey) => [XChaCha20Poly1305Ciphertext, Entropy24];
|
|
190
|
+
/**
|
|
191
|
+
* Error returned by {@link decryptWithXChaCha20Poly1305} when decryption fails.
|
|
192
|
+
*
|
|
193
|
+
* @group Encryption
|
|
194
|
+
*/
|
|
137
195
|
export interface DecryptWithXChaCha20Poly1305Error extends Typed<"DecryptWithXChaCha20Poly1305Error"> {
|
|
138
196
|
readonly error: unknown;
|
|
139
197
|
}
|
|
@@ -176,6 +234,8 @@ export interface DecryptWithXChaCha20Poly1305Error extends Typed<"DecryptWithXCh
|
|
|
176
234
|
*
|
|
177
235
|
* assertOk(decryptMessage(), "secret message");
|
|
178
236
|
* ```
|
|
237
|
+
*
|
|
238
|
+
* @group Encryption
|
|
179
239
|
*/
|
|
180
240
|
export declare const decryptWithXChaCha20Poly1305: (ciphertext: XChaCha20Poly1305Ciphertext, nonce: Entropy24, encryptionKey: EncryptionKey) => Result<Uint8Array, DecryptWithXChaCha20Poly1305Error>;
|
|
181
241
|
/**
|
|
@@ -185,18 +245,30 @@ export declare const decryptWithXChaCha20Poly1305: (ciphertext: XChaCha20Poly130
|
|
|
185
245
|
* wide range of encrypted data sizes.
|
|
186
246
|
*
|
|
187
247
|
* See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
|
|
248
|
+
*
|
|
249
|
+
* @group Padding
|
|
188
250
|
*/
|
|
189
251
|
export declare const createPadmePaddedLength: (length: NonNegativeInt) => NonNegativeInt;
|
|
190
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* Creates a PADMÉ padding array of zeros for the given input length.
|
|
254
|
+
*
|
|
255
|
+
* @group Padding
|
|
256
|
+
*/
|
|
191
257
|
export declare const createPadmePadding: (length: NonNegativeInt) => Uint8Array;
|
|
192
258
|
/**
|
|
193
259
|
* Performs a timing-safe comparison of two Uint8Arrays. Returns true if they
|
|
194
260
|
* are equal, false otherwise. Takes constant time regardless of where the
|
|
195
261
|
* arrays differ.
|
|
196
262
|
*
|
|
263
|
+
* @group Comparison
|
|
197
264
|
* @see https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
|
|
198
265
|
*/
|
|
199
266
|
export type TimingSafeEqual = (a: Uint8Array, b: Uint8Array) => boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Dependency wrapper for {@link TimingSafeEqual}.
|
|
269
|
+
*
|
|
270
|
+
* @group Comparison
|
|
271
|
+
*/
|
|
200
272
|
export interface TimingSafeEqualDep {
|
|
201
273
|
readonly timingSafeEqual: TimingSafeEqual;
|
|
202
274
|
}
|
package/dist/src/Crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAGL,cAAc,EAEd,KAAK,KAAK,EAEX,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,QAAA,MAAM,OAAO,uSAA6C,CAAC;AAC3D,KAAK,OAAO,GAAG,O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;;;;;;;GA+BG;AACH,eAAO,MAAM,4BAA4B,SAChC,cAAc,iBAER,UAAU,iBACN,aAAa,KAC3B,CAAC,2BAA2B,EAAE,SAAS,CAMzC,CAAC;AAEJ;;;;GAIG;AACH,MAAM,WAAW,iCAAkC,SAAQ,KAAK,CAAC,mCAAmC,CAAC;IACnG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,4BAA4B,eAC3B,2BAA2B,SAChC,SAAS,iBACD,aAAa,KAC3B,MAAM,CAAC,UAAU,EAAE,iCAAiC,CAOpD,CAAC;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,WAC1B,cAAc,KACrB,cAOF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,WAAY,cAAc,KAAG,UAI3D,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C"}
|
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
|
-
{"version":3,"file":"Fs.d.ts","sourceRoot":"","sources":["../../src/Fs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAa,IAAI,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"Fs.d.ts","sourceRoot":"","sources":["../../src/Fs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAa,IAAI,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CA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