@evolu/common 8.9.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/Bytes.d.ts +647 -0
- package/dist/src/Bytes.d.ts.map +1 -0
- package/dist/src/{Binary.js → Bytes.js} +266 -16
- package/dist/src/Config.d.ts +142 -0
- package/dist/src/Config.d.ts.map +1 -0
- package/dist/src/Config.js +181 -0
- 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 +376 -0
- package/dist/src/Fs.d.ts.map +1 -0
- package/dist/src/Fs.js +113 -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/Number.d.ts +50 -7
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +47 -8
- package/dist/src/Object.d.ts +32 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +46 -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 +64 -10
- 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 +179 -20
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +95 -6
- package/dist/src/Type.d.ts +3056 -1539
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +2548 -584
- 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 +9 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -4
- package/dist/src/intl/_en.d.ts +24 -1
- package/dist/src/intl/_en.d.ts.map +1 -1
- package/dist/src/intl/_en.js +20 -0
- package/dist/src/intl/ar.d.ts +24 -1
- package/dist/src/intl/ar.d.ts.map +1 -1
- package/dist/src/intl/ar.js +20 -0
- package/dist/src/intl/bn.d.ts +24 -1
- package/dist/src/intl/bn.d.ts.map +1 -1
- package/dist/src/intl/bn.js +20 -0
- package/dist/src/intl/ca.d.ts +24 -1
- package/dist/src/intl/ca.d.ts.map +1 -1
- package/dist/src/intl/ca.js +20 -0
- package/dist/src/intl/cs.d.ts +24 -1
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +20 -0
- package/dist/src/intl/da.d.ts +24 -1
- package/dist/src/intl/da.d.ts.map +1 -1
- package/dist/src/intl/da.js +20 -0
- package/dist/src/intl/de.d.ts +24 -1
- package/dist/src/intl/de.d.ts.map +1 -1
- package/dist/src/intl/de.js +20 -0
- package/dist/src/intl/el.d.ts +24 -1
- package/dist/src/intl/el.d.ts.map +1 -1
- package/dist/src/intl/el.js +20 -0
- package/dist/src/intl/es.d.ts +24 -1
- package/dist/src/intl/es.d.ts.map +1 -1
- package/dist/src/intl/es.js +20 -0
- package/dist/src/intl/fa.d.ts +24 -1
- package/dist/src/intl/fa.d.ts.map +1 -1
- package/dist/src/intl/fa.js +20 -0
- package/dist/src/intl/fi.d.ts +24 -1
- package/dist/src/intl/fi.d.ts.map +1 -1
- package/dist/src/intl/fi.js +20 -0
- package/dist/src/intl/fil.d.ts +24 -1
- package/dist/src/intl/fil.d.ts.map +1 -1
- package/dist/src/intl/fil.js +20 -0
- package/dist/src/intl/fr.d.ts +24 -1
- package/dist/src/intl/fr.d.ts.map +1 -1
- package/dist/src/intl/fr.js +20 -0
- package/dist/src/intl/he.d.ts +24 -1
- package/dist/src/intl/he.d.ts.map +1 -1
- package/dist/src/intl/he.js +20 -0
- package/dist/src/intl/hi.d.ts +24 -1
- package/dist/src/intl/hi.d.ts.map +1 -1
- package/dist/src/intl/hi.js +20 -0
- package/dist/src/intl/hr.d.ts +24 -1
- package/dist/src/intl/hr.d.ts.map +1 -1
- package/dist/src/intl/hr.js +20 -0
- package/dist/src/intl/hu.d.ts +22 -1
- package/dist/src/intl/hu.d.ts.map +1 -1
- package/dist/src/intl/hu.js +18 -0
- package/dist/src/intl/id.d.ts +24 -1
- package/dist/src/intl/id.d.ts.map +1 -1
- package/dist/src/intl/id.js +20 -0
- package/dist/src/intl/it.d.ts +24 -1
- package/dist/src/intl/it.d.ts.map +1 -1
- package/dist/src/intl/it.js +20 -0
- package/dist/src/intl/ja.d.ts +24 -1
- package/dist/src/intl/ja.d.ts.map +1 -1
- package/dist/src/intl/ja.js +20 -0
- package/dist/src/intl/ko.d.ts +24 -1
- package/dist/src/intl/ko.d.ts.map +1 -1
- package/dist/src/intl/ko.js +20 -0
- package/dist/src/intl/ml.d.ts +24 -1
- package/dist/src/intl/ml.d.ts.map +1 -1
- package/dist/src/intl/ml.js +20 -0
- package/dist/src/intl/mr.d.ts +24 -1
- package/dist/src/intl/mr.d.ts.map +1 -1
- package/dist/src/intl/mr.js +20 -0
- package/dist/src/intl/ms.d.ts +24 -1
- package/dist/src/intl/ms.d.ts.map +1 -1
- package/dist/src/intl/ms.js +20 -0
- package/dist/src/intl/nb.d.ts +22 -1
- package/dist/src/intl/nb.d.ts.map +1 -1
- package/dist/src/intl/nb.js +18 -0
- package/dist/src/intl/nl.d.ts +24 -1
- package/dist/src/intl/nl.d.ts.map +1 -1
- package/dist/src/intl/nl.js +20 -0
- package/dist/src/intl/pa.d.ts +24 -1
- package/dist/src/intl/pa.d.ts.map +1 -1
- package/dist/src/intl/pa.js +20 -0
- package/dist/src/intl/pl.d.ts +23 -0
- package/dist/src/intl/pl.d.ts.map +1 -1
- package/dist/src/intl/pl.js +20 -0
- package/dist/src/intl/pt-BR.d.ts +24 -1
- package/dist/src/intl/pt-BR.d.ts.map +1 -1
- package/dist/src/intl/pt-BR.js +20 -0
- package/dist/src/intl/pt.d.ts +24 -1
- package/dist/src/intl/pt.d.ts.map +1 -1
- package/dist/src/intl/pt.js +20 -0
- package/dist/src/intl/ro.d.ts +24 -1
- package/dist/src/intl/ro.d.ts.map +1 -1
- package/dist/src/intl/ro.js +20 -0
- package/dist/src/intl/sk.d.ts +24 -1
- package/dist/src/intl/sk.d.ts.map +1 -1
- package/dist/src/intl/sk.js +20 -0
- package/dist/src/intl/sl.d.ts +24 -1
- package/dist/src/intl/sl.d.ts.map +1 -1
- package/dist/src/intl/sl.js +20 -0
- package/dist/src/intl/sv.d.ts +24 -1
- package/dist/src/intl/sv.d.ts.map +1 -1
- package/dist/src/intl/sv.js +20 -0
- package/dist/src/intl/sw.d.ts +21 -0
- package/dist/src/intl/sw.d.ts.map +1 -1
- package/dist/src/intl/sw.js +18 -0
- package/dist/src/intl/ta.d.ts +24 -1
- package/dist/src/intl/ta.d.ts.map +1 -1
- package/dist/src/intl/ta.js +20 -0
- package/dist/src/intl/te.d.ts +24 -1
- package/dist/src/intl/te.d.ts.map +1 -1
- package/dist/src/intl/te.js +20 -0
- package/dist/src/intl/th.d.ts +24 -1
- package/dist/src/intl/th.d.ts.map +1 -1
- package/dist/src/intl/th.js +20 -0
- package/dist/src/intl/tr.d.ts +24 -1
- package/dist/src/intl/tr.d.ts.map +1 -1
- package/dist/src/intl/tr.js +20 -0
- package/dist/src/intl/uk.d.ts +80 -57
- package/dist/src/intl/uk.d.ts.map +1 -1
- package/dist/src/intl/uk.js +174 -149
- package/dist/src/intl/ur.d.ts +24 -1
- package/dist/src/intl/ur.d.ts.map +1 -1
- package/dist/src/intl/ur.js +20 -0
- package/dist/src/intl/vi.d.ts +24 -1
- package/dist/src/intl/vi.d.ts.map +1 -1
- package/dist/src/intl/vi.js +20 -0
- package/dist/src/intl/zh-CN.d.ts +24 -1
- package/dist/src/intl/zh-CN.d.ts.map +1 -1
- package/dist/src/intl/zh-CN.js +20 -0
- package/dist/src/intl/zh-TW.d.ts +24 -1
- package/dist/src/intl/zh-TW.d.ts.map +1 -1
- package/dist/src/intl/zh-TW.js +20 -0
- 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 +95 -17
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +119 -39
- 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 +345 -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 +82 -21
- 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 +404 -82
- 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/{Binary.test.ts → Bytes.test.ts} +286 -1
- package/src/{Binary.ts → Bytes.ts} +652 -21
- package/src/Config.test.ts +668 -0
- package/src/Config.ts +410 -0
- 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.test.ts +105 -0
- package/src/Fs.ts +488 -0
- package/src/Identicon.ts +2 -2
- package/src/LeakDetector.ts +22 -3
- package/src/LockManager.ts +8 -0
- package/src/Number.test.ts +82 -18
- package/src/Number.ts +76 -8
- package/src/Object.test.ts +139 -10
- package/src/Object.ts +49 -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 +138 -18
- package/src/Task.test.ts +189 -8
- package/src/Task.ts +56 -17
- package/src/Test.ts +9 -0
- package/src/Time.test.ts +82 -11
- package/src/Time.ts +246 -24
- package/src/Type.test.ts +3994 -1119
- package/src/Type.ts +7258 -3842
- package/src/Types.test.ts +4 -14
- package/src/WebSocket.ts +313 -40
- package/src/Worker.ts +90 -8
- package/src/index.ts +18 -7
- package/src/intl/_en.ts +70 -0
- package/src/intl/ar.ts +71 -0
- package/src/intl/bn.ts +70 -0
- package/src/intl/ca.ts +70 -0
- package/src/intl/cs.ts +70 -0
- package/src/intl/da.ts +70 -0
- package/src/intl/de.ts +70 -0
- package/src/intl/el.ts +70 -0
- package/src/intl/es.ts +70 -0
- package/src/intl/fa.ts +70 -0
- package/src/intl/fi.ts +70 -0
- package/src/intl/fil.ts +70 -0
- package/src/intl/fr.ts +70 -0
- package/src/intl/he.ts +70 -0
- package/src/intl/hi.ts +70 -0
- package/src/intl/hr.ts +70 -0
- package/src/intl/hu.ts +69 -0
- package/src/intl/id.ts +70 -0
- package/src/intl/intl.test.ts +819 -1
- package/src/intl/it.ts +70 -0
- package/src/intl/ja.ts +70 -0
- package/src/intl/ko.ts +68 -0
- package/src/intl/ml.ts +70 -0
- package/src/intl/mr.ts +70 -0
- package/src/intl/ms.ts +71 -0
- package/src/intl/nb.ts +69 -0
- package/src/intl/nl.ts +70 -0
- package/src/intl/pa.ts +70 -0
- package/src/intl/pl.ts +63 -0
- package/src/intl/pt-BR.ts +70 -0
- package/src/intl/pt.ts +71 -0
- package/src/intl/ro.ts +70 -0
- package/src/intl/sk.ts +71 -0
- package/src/intl/sl.ts +70 -0
- package/src/intl/sv.ts +70 -0
- package/src/intl/sw.ts +62 -0
- package/src/intl/ta.ts +70 -0
- package/src/intl/te.ts +70 -0
- package/src/intl/th.ts +68 -0
- package/src/intl/tr.ts +70 -0
- package/src/intl/uk.ts +228 -155
- package/src/intl/ur.ts +70 -0
- package/src/intl/vi.ts +70 -0
- package/src/intl/zh-CN.ts +68 -0
- package/src/intl/zh-TW.ts +68 -0
- 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 +618 -11
- package/src/local-first/Protocol.ts +197 -73
- package/src/local-first/Query.ts +8 -15
- package/src/local-first/Schema.test.ts +143 -0
- package/src/local-first/Schema.ts +374 -24
- package/src/local-first/Shared.test.ts +7731 -559
- package/src/local-first/Shared.ts +2036 -267
- package/src/local-first/Storage.ts +219 -33
- package/src/local-first/Timestamp.test.ts +344 -70
- package/src/local-first/Timestamp.ts +435 -119
- package/src/local-first/index.ts +0 -1
- package/dist/src/Binary.d.ts +0 -254
- package/dist/src/Binary.d.ts.map +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
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system operations for {@link Task}s.
|
|
3
|
+
*
|
|
4
|
+
* {@link Fs} reads, writes, copies, and renames files; lists and manages
|
|
5
|
+
* directories; and provides metadata and existence checks. Each operation
|
|
6
|
+
* returns a Task.
|
|
7
|
+
*
|
|
8
|
+
* Tasks can sequence file operations without synchronous I/O. Node.js's
|
|
9
|
+
* synchronous methods are intentionally omitted to avoid accidentally blocking
|
|
10
|
+
* the event loop.
|
|
11
|
+
*
|
|
12
|
+
* Inject {@link @evolu/nodejs!createNodeFs | createNodeFs} through
|
|
13
|
+
* {@link @evolu/nodejs!runMain | runMain} or {@link createRun}. Tasks declare
|
|
14
|
+
* {@link FsDep} and access the file system through `run.deps.fs`.
|
|
15
|
+
*
|
|
16
|
+
* {@link FsError} includes the path, a diagnostic message, and a
|
|
17
|
+
* {@link FsErrorReason} such as `NotFound` or `PermissionDenied`.
|
|
18
|
+
* {@link Fs.exists} returns `false` for `NotFound` and preserves other errors.
|
|
19
|
+
*
|
|
20
|
+
* ### Example
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import {
|
|
24
|
+
* assertEqual,
|
|
25
|
+
* ok,
|
|
26
|
+
* type FsDep,
|
|
27
|
+
* type FsError,
|
|
28
|
+
* type Task,
|
|
29
|
+
* } from "@evolu/common";
|
|
30
|
+
* import { createNodeFs, runMain } from "@evolu/nodejs";
|
|
31
|
+
* import { join } from "node:path";
|
|
32
|
+
*
|
|
33
|
+
* const main: Task<void, FsError, FsDep> = async (run) => {
|
|
34
|
+
* const { fs } = run.deps;
|
|
35
|
+
* const temp = await run(
|
|
36
|
+
* fs.createTempDirectory({ prefix: "evolu-fs-" }),
|
|
37
|
+
* );
|
|
38
|
+
* if (!temp.ok) return temp;
|
|
39
|
+
*
|
|
40
|
+
* await using directory = temp.value;
|
|
41
|
+
* const path = join(directory.path, "message.txt");
|
|
42
|
+
*
|
|
43
|
+
* const result = await run(fs.writeFile(path, "hello"));
|
|
44
|
+
* if (!result.ok) return result;
|
|
45
|
+
*
|
|
46
|
+
* const text = await run(fs.readFile(path, "utf8"));
|
|
47
|
+
* if (!text.ok) return text;
|
|
48
|
+
* assertEqual(text.value, "hello");
|
|
49
|
+
*
|
|
50
|
+
* return ok();
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* await runMain({ fs: createNodeFs() }, { mode: "command" })(main);
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @module
|
|
57
|
+
*/
|
|
58
|
+
import type { ByteLength } from "./Bytes.ts";
|
|
59
|
+
import type { Task } from "./Task.ts";
|
|
60
|
+
import type { Typed } from "./Type.ts";
|
|
61
|
+
/**
|
|
62
|
+
* Asynchronous file system operations.
|
|
63
|
+
*
|
|
64
|
+
* @group Core
|
|
65
|
+
*/
|
|
66
|
+
export interface Fs {
|
|
67
|
+
/**
|
|
68
|
+
* Reads a whole file, as bytes by default or as a string with an encoding. An
|
|
69
|
+
* abort requests cancellation; pending operating system reads may still
|
|
70
|
+
* finish.
|
|
71
|
+
*/
|
|
72
|
+
readonly readFile: FsReadFile;
|
|
73
|
+
/**
|
|
74
|
+
* Writes a file, creating it or truncating an existing file by default. An
|
|
75
|
+
* abort requests cancellation and can leave the file partially written or
|
|
76
|
+
* truncated.
|
|
77
|
+
*/
|
|
78
|
+
readonly writeFile: (path: FsPath, data: string | Uint8Array, options?: FsWriteFileOptions) => Task<void, FsError>;
|
|
79
|
+
/**
|
|
80
|
+
* Lists entry names relative to `path`, in unspecified order. With
|
|
81
|
+
* `recursive`, includes nested entries with their relative paths.
|
|
82
|
+
*/
|
|
83
|
+
readonly readDirectory: (path: FsPath, options?: FsReadDirectoryOptions) => Task<ReadonlyArray<string>, FsError>;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a directory. Without `recursive`, an existing directory fails with
|
|
86
|
+
* `AlreadyExists` and a missing parent with `NotFound`.
|
|
87
|
+
*/
|
|
88
|
+
readonly createDirectory: (path: FsPath, options?: FsCreateDirectoryOptions) => Task<void, FsError>;
|
|
89
|
+
/**
|
|
90
|
+
* Copies a file or directory tree using Node's recursive `cp` semantics. By
|
|
91
|
+
* default, existing directories are merged and files are replaced. Symbolic
|
|
92
|
+
* links follow Node's rules: `force: false` and `errorOnExist` do not
|
|
93
|
+
* guarantee that destination links are preserved.
|
|
94
|
+
*
|
|
95
|
+
* Copying is neither exclusive nor atomic, and a failure can leave a partial
|
|
96
|
+
* copy. Use {@link Fs.copyFile} for exclusive creation of a single file.
|
|
97
|
+
*/
|
|
98
|
+
readonly copy: (source: FsPath, destination: FsPath, options?: FsCopyOptions) => Task<void, FsError>;
|
|
99
|
+
/**
|
|
100
|
+
* Copies a single file. An existing destination fails with `AlreadyExists`
|
|
101
|
+
* unless `overwrite` is enabled. Without overwrite, destination creation is
|
|
102
|
+
* exclusive even when other copies run concurrently. File contents are not
|
|
103
|
+
* published atomically; a failure can leave a partial copy.
|
|
104
|
+
*/
|
|
105
|
+
readonly copyFile: (source: FsPath, destination: FsPath, options?: FsCopyFileOptions) => Task<void, FsError>;
|
|
106
|
+
/**
|
|
107
|
+
* Renames or moves a file or directory using the platform's rename semantics.
|
|
108
|
+
* An existing destination file can be replaced.
|
|
109
|
+
*/
|
|
110
|
+
readonly rename: (source: FsPath, destination: FsPath) => Task<void, FsError>;
|
|
111
|
+
/**
|
|
112
|
+
* Removes a file, or a directory with `recursive`. Removing a directory
|
|
113
|
+
* without `recursive` fails with `IsDirectory`. With `force`, a missing path
|
|
114
|
+
* succeeds.
|
|
115
|
+
*/
|
|
116
|
+
readonly remove: (path: FsPath, options?: FsRemoveOptions) => Task<void, FsError>;
|
|
117
|
+
/** Reads file metadata, following symbolic links. */
|
|
118
|
+
readonly getMetadata: (path: FsPath) => Task<FsMetadata, FsError>;
|
|
119
|
+
/**
|
|
120
|
+
* Checks whether a path exists. `NotFound` produces `false`; other errors are
|
|
121
|
+
* returned. A `true` result does not establish read or write permission.
|
|
122
|
+
*/
|
|
123
|
+
readonly exists: (path: FsPath) => Task<boolean, FsError>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a unique directory in the system temporary directory by default.
|
|
126
|
+
* Options can specify a parent directory and a name prefix. The returned
|
|
127
|
+
* resource removes the directory and its contents on disposal. Use `await
|
|
128
|
+
* using` for cleanup; disposal can throw if removal fails.
|
|
129
|
+
*
|
|
130
|
+
* Once started, this operation returns its result even if its Run aborts.
|
|
131
|
+
*/
|
|
132
|
+
readonly createTempDirectory: (options?: FsCreateTempDirectoryOptions) => Task<FsTempDirectory, FsError>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Dependency wrapper for {@link Fs}.
|
|
136
|
+
*
|
|
137
|
+
* @group Core
|
|
138
|
+
*/
|
|
139
|
+
export interface FsDep {
|
|
140
|
+
readonly fs: Fs;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A file system path, or a `file:` URL.
|
|
144
|
+
*
|
|
145
|
+
* @group Core
|
|
146
|
+
*/
|
|
147
|
+
export type FsPath = string | URL;
|
|
148
|
+
/**
|
|
149
|
+
* Supported text encodings.
|
|
150
|
+
*
|
|
151
|
+
* @group Core
|
|
152
|
+
*/
|
|
153
|
+
export type FsEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "utf-16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
154
|
+
/**
|
|
155
|
+
* Supported file opening modes for {@link Fs.writeFile}.
|
|
156
|
+
*
|
|
157
|
+
* @group Core
|
|
158
|
+
*/
|
|
159
|
+
export type FsOpenFlag = "a" | "ax" | "a+" | "ax+" | "as" | "as+" | "r" | "r+" | "rs+" | "w" | "wx" | "w+" | "wx+";
|
|
160
|
+
/**
|
|
161
|
+
* Reads bytes by default, or text when an encoding is specified.
|
|
162
|
+
*
|
|
163
|
+
* @group Core
|
|
164
|
+
*/
|
|
165
|
+
export interface FsReadFile {
|
|
166
|
+
(path: FsPath): Task<Uint8Array, FsError>;
|
|
167
|
+
(path: FsPath, encoding: FsEncoding | {
|
|
168
|
+
readonly encoding: FsEncoding;
|
|
169
|
+
}): Task<string, FsError>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Options for {@link Fs.writeFile}.
|
|
173
|
+
*
|
|
174
|
+
* @group Options
|
|
175
|
+
*/
|
|
176
|
+
export interface FsWriteFileOptions {
|
|
177
|
+
/** Encoding of string data. Defaults to `utf8`. */
|
|
178
|
+
readonly encoding?: FsEncoding;
|
|
179
|
+
/** File mode of a created file. Defaults to `0o666`. */
|
|
180
|
+
readonly mode?: number;
|
|
181
|
+
/** Open flag. Defaults to `w`; use `wx` to fail when the file exists. */
|
|
182
|
+
readonly flag?: FsOpenFlag;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Options for {@link Fs.readDirectory}.
|
|
186
|
+
*
|
|
187
|
+
* @group Options
|
|
188
|
+
*/
|
|
189
|
+
export interface FsReadDirectoryOptions {
|
|
190
|
+
/** Includes entries from nested directories. Defaults to `false`. */
|
|
191
|
+
readonly recursive?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Options for {@link Fs.createDirectory}.
|
|
195
|
+
*
|
|
196
|
+
* @group Options
|
|
197
|
+
*/
|
|
198
|
+
export interface FsCreateDirectoryOptions {
|
|
199
|
+
/** Creates missing parents and accepts an existing directory. */
|
|
200
|
+
readonly recursive?: boolean;
|
|
201
|
+
/** Directory mode. Defaults to `0o777`. */
|
|
202
|
+
readonly mode?: number;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Options for {@link Fs.copy}.
|
|
206
|
+
*
|
|
207
|
+
* @group Options
|
|
208
|
+
*/
|
|
209
|
+
export interface FsCopyOptions {
|
|
210
|
+
/**
|
|
211
|
+
* Node's `force` option. Replaces existing files; `false` skips them unless
|
|
212
|
+
* `errorOnExist` is enabled. Defaults to `true`. This does not protect
|
|
213
|
+
* destination symbolic links.
|
|
214
|
+
*/
|
|
215
|
+
readonly force?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Node's `errorOnExist` option. With `force: false`, existing files and
|
|
218
|
+
* directories fail with `AlreadyExists`. Defaults to `false`. Symbolic links
|
|
219
|
+
* retain Node's behavior and may still be replaced.
|
|
220
|
+
*/
|
|
221
|
+
readonly errorOnExist?: boolean;
|
|
222
|
+
/** Preserves access and modification times. Defaults to `false`. */
|
|
223
|
+
readonly preserveTimestamps?: boolean;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Options for {@link Fs.copyFile}.
|
|
227
|
+
*
|
|
228
|
+
* @group Options
|
|
229
|
+
*/
|
|
230
|
+
export interface FsCopyFileOptions {
|
|
231
|
+
/** Replaces an existing destination file. Defaults to `false`. */
|
|
232
|
+
readonly overwrite?: boolean;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Options for {@link Fs.remove}.
|
|
236
|
+
*
|
|
237
|
+
* @group Options
|
|
238
|
+
*/
|
|
239
|
+
export interface FsRemoveOptions {
|
|
240
|
+
/** Removes directories and their contents. */
|
|
241
|
+
readonly recursive?: boolean;
|
|
242
|
+
/** Ignores a missing path. */
|
|
243
|
+
readonly force?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Number of retries for `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM`
|
|
246
|
+
* on Node.js. Applies only with `recursive: true`. Defaults to `0`.
|
|
247
|
+
*/
|
|
248
|
+
readonly maxRetries?: number;
|
|
249
|
+
/**
|
|
250
|
+
* Base retry delay in milliseconds. Each retry waits one additional interval.
|
|
251
|
+
* Applies only with `recursive: true`. Defaults to `100`.
|
|
252
|
+
*/
|
|
253
|
+
readonly retryDelay?: number;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* File metadata as data, with Node's numeric and timestamp field names.
|
|
257
|
+
*
|
|
258
|
+
* @group Core
|
|
259
|
+
*/
|
|
260
|
+
export interface FsMetadata {
|
|
261
|
+
readonly type: FsEntryType;
|
|
262
|
+
readonly dev: number;
|
|
263
|
+
readonly ino: number;
|
|
264
|
+
readonly mode: number;
|
|
265
|
+
readonly nlink: number;
|
|
266
|
+
readonly uid: number;
|
|
267
|
+
readonly gid: number;
|
|
268
|
+
readonly rdev: number;
|
|
269
|
+
readonly size: ByteLength;
|
|
270
|
+
readonly blksize: number;
|
|
271
|
+
readonly blocks: number;
|
|
272
|
+
readonly atimeMs: number;
|
|
273
|
+
readonly mtimeMs: number;
|
|
274
|
+
readonly ctimeMs: number;
|
|
275
|
+
readonly birthtimeMs: number;
|
|
276
|
+
readonly atime: Date;
|
|
277
|
+
readonly mtime: Date;
|
|
278
|
+
readonly ctime: Date;
|
|
279
|
+
readonly birthtime: Date;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The kind of file system entry described by {@link FsMetadata}.
|
|
283
|
+
*
|
|
284
|
+
* @group Core
|
|
285
|
+
*/
|
|
286
|
+
export type FsEntryType = "File" | "Directory" | "SymbolicLink" | "BlockDevice" | "CharacterDevice" | "FIFO" | "Socket" | "Unknown";
|
|
287
|
+
/**
|
|
288
|
+
* Options for {@link Fs.createTempDirectory}.
|
|
289
|
+
*
|
|
290
|
+
* @group Options
|
|
291
|
+
*/
|
|
292
|
+
export interface FsCreateTempDirectoryOptions {
|
|
293
|
+
/** Existing parent directory. Defaults to the system temporary directory. */
|
|
294
|
+
readonly directory?: string;
|
|
295
|
+
/** Prefix for the directory name. Defaults to an empty string. */
|
|
296
|
+
readonly prefix?: string;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* A temporary directory removed, with its contents, on asynchronous disposal.
|
|
300
|
+
*
|
|
301
|
+
* @group Core
|
|
302
|
+
*/
|
|
303
|
+
export interface FsTempDirectory extends AsyncDisposable {
|
|
304
|
+
readonly path: string;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* A failed file system operation.
|
|
308
|
+
*
|
|
309
|
+
* @group Errors
|
|
310
|
+
*/
|
|
311
|
+
export interface FsError extends Typed<"FsError"> {
|
|
312
|
+
readonly reason: FsErrorReason;
|
|
313
|
+
/**
|
|
314
|
+
* The operation's path, or source for copying and renaming. URL inputs use
|
|
315
|
+
* their `href`. Temporary directories use the supplied parent if its
|
|
316
|
+
* resolution fails, or the resolved parent combined with the name prefix if
|
|
317
|
+
* creation fails.
|
|
318
|
+
*/
|
|
319
|
+
readonly path: string;
|
|
320
|
+
/**
|
|
321
|
+
* Destination for copying and renaming, with URL inputs represented by
|
|
322
|
+
* `href`.
|
|
323
|
+
*/
|
|
324
|
+
readonly destination?: string;
|
|
325
|
+
/** The failing system call, or the method name when the platform reports none. */
|
|
326
|
+
readonly syscall: string;
|
|
327
|
+
/** The platform's diagnostic message. */
|
|
328
|
+
readonly message: string;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Why a file system operation failed, mapped from the platform's error code.
|
|
332
|
+
*
|
|
333
|
+
* @group Errors
|
|
334
|
+
*/
|
|
335
|
+
export type FsErrorReason = "NotFound" | "AlreadyExists" | "PermissionDenied" | "IsDirectory" | "NotDirectory" | "NotEmpty" | "Busy" | "Unknown";
|
|
336
|
+
/**
|
|
337
|
+
* Creates a test {@link Fs} with the supplied operation overrides.
|
|
338
|
+
*
|
|
339
|
+
* Unconfigured operations throw a defect naming the method when their Task
|
|
340
|
+
* runs. Constructing a Task does not execute it. This helper performs no file
|
|
341
|
+
* system I/O; overrides provide the behavior needed by each test.
|
|
342
|
+
*
|
|
343
|
+
* ### Example
|
|
344
|
+
*
|
|
345
|
+
* ```ts
|
|
346
|
+
* import {
|
|
347
|
+
* assertEqual,
|
|
348
|
+
* assertOk,
|
|
349
|
+
* ok,
|
|
350
|
+
* testCreateFs,
|
|
351
|
+
* testCreateRun,
|
|
352
|
+
* type FsDep,
|
|
353
|
+
* type FsError,
|
|
354
|
+
* type Task,
|
|
355
|
+
* } from "@evolu/common";
|
|
356
|
+
*
|
|
357
|
+
* const saveMessage: Task<void, FsError, FsDep> = (run) =>
|
|
358
|
+
* run(run.deps.fs.writeFile("message.txt", "hello"));
|
|
359
|
+
*
|
|
360
|
+
* await using run = testCreateRun({
|
|
361
|
+
* fs: testCreateFs({
|
|
362
|
+
* writeFile: (path, data) => () => {
|
|
363
|
+
* assertEqual(path, "message.txt");
|
|
364
|
+
* assertEqual(data, "hello");
|
|
365
|
+
* return ok();
|
|
366
|
+
* },
|
|
367
|
+
* }),
|
|
368
|
+
* });
|
|
369
|
+
*
|
|
370
|
+
* assertOk(await run(saveMessage));
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @group Testing
|
|
374
|
+
*/
|
|
375
|
+
export declare const testCreateFs: (overrides?: Partial<Fs>) => Fs;
|
|
376
|
+
//# sourceMappingURL=Fs.d.ts.map
|
|
@@ -0,0 +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;;;;GAIG;AACH,MAAM,WAAW,EAAE;IACjB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,CAAC,EAAE,kBAAkB,KACzB,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,CACtB,IAAI,EAAE,MAA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