@zukhruf/single-flight 0.3.16 → 0.3.18

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.
Files changed (107) hide show
  1. package/README.md +13 -12
  2. package/dist/client/flight-client.d.ts +4 -4
  3. package/dist/client/flight-client.d.ts.map +1 -1
  4. package/dist/client/flight-client.js +20 -10
  5. package/dist/client/flight-client.js.map +1 -1
  6. package/dist/connection/connection-supervisor.d.ts +4 -4
  7. package/dist/connection/connection-supervisor.d.ts.map +1 -1
  8. package/dist/connection/connection-supervisor.js.map +1 -1
  9. package/dist/connection/connection.d.ts +4 -3
  10. package/dist/connection/connection.d.ts.map +1 -1
  11. package/dist/connection/connector.d.ts +5 -5
  12. package/dist/connection/connector.d.ts.map +1 -1
  13. package/dist/connection/electing-connector.d.ts +4 -5
  14. package/dist/connection/electing-connector.d.ts.map +1 -1
  15. package/dist/connection/electing-connector.js +38 -42
  16. package/dist/connection/electing-connector.js.map +1 -1
  17. package/dist/connection/flight-election.d.ts +11 -0
  18. package/dist/connection/flight-election.d.ts.map +1 -0
  19. package/dist/connection/flight-election.js +18 -0
  20. package/dist/connection/flight-election.js.map +1 -0
  21. package/dist/connection/handshake.d.ts.map +1 -1
  22. package/dist/connection/handshake.js +6 -5
  23. package/dist/connection/handshake.js.map +1 -1
  24. package/dist/connection/json-line.d.ts +6 -0
  25. package/dist/connection/json-line.d.ts.map +1 -0
  26. package/dist/connection/json-line.js +8 -0
  27. package/dist/connection/json-line.js.map +1 -0
  28. package/dist/connection/leave-errors-to-close.d.ts +9 -0
  29. package/dist/connection/leave-errors-to-close.d.ts.map +1 -0
  30. package/dist/connection/leave-errors-to-close.js +10 -0
  31. package/dist/connection/leave-errors-to-close.js.map +1 -0
  32. package/dist/connection/local-directory-connector.d.ts.map +1 -1
  33. package/dist/connection/local-directory-connector.js +1 -1
  34. package/dist/connection/local-directory-connector.js.map +1 -1
  35. package/dist/connection/socket-connection.d.ts +5 -5
  36. package/dist/connection/socket-connection.d.ts.map +1 -1
  37. package/dist/connection/socket-connection.js +21 -23
  38. package/dist/connection/socket-connection.js.map +1 -1
  39. package/dist/coordinator/flight-coordinator.d.ts +3 -3
  40. package/dist/coordinator/flight-coordinator.d.ts.map +1 -1
  41. package/dist/coordinator/flight-coordinator.js +12 -18
  42. package/dist/coordinator/flight-coordinator.js.map +1 -1
  43. package/dist/coordinator/flight-server.d.ts +7 -3
  44. package/dist/coordinator/flight-server.d.ts.map +1 -1
  45. package/dist/coordinator/flight-server.js +29 -25
  46. package/dist/coordinator/flight-server.js.map +1 -1
  47. package/dist/coordinator/flight.d.ts +4 -2
  48. package/dist/coordinator/flight.d.ts.map +1 -1
  49. package/dist/coordinator/flight.js +9 -5
  50. package/dist/coordinator/flight.js.map +1 -1
  51. package/dist/coordinator/party.d.ts +11 -2
  52. package/dist/coordinator/party.d.ts.map +1 -1
  53. package/dist/coordinator/party.js +15 -15
  54. package/dist/coordinator/party.js.map +1 -1
  55. package/dist/coordinator/session.d.ts +2 -2
  56. package/dist/coordinator/session.d.ts.map +1 -1
  57. package/dist/coordinator/session.js +9 -4
  58. package/dist/coordinator/session.js.map +1 -1
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +1 -1
  62. package/dist/index.js.map +1 -1
  63. package/dist/protocol/flight-protocol.d.ts +6 -2
  64. package/dist/protocol/flight-protocol.d.ts.map +1 -1
  65. package/dist/protocol/flight-protocol.js +17 -10
  66. package/dist/protocol/flight-protocol.js.map +1 -1
  67. package/dist/single-flight.d.ts +7 -5
  68. package/dist/single-flight.d.ts.map +1 -1
  69. package/dist/single-flight.js +21 -16
  70. package/dist/single-flight.js.map +1 -1
  71. package/package.json +6 -5
  72. package/dist/election/leader-election.d.ts +0 -24
  73. package/dist/election/leader-election.d.ts.map +0 -1
  74. package/dist/election/leader-election.js +0 -80
  75. package/dist/election/leader-election.js.map +0 -1
  76. package/dist/election/leadership.d.ts +0 -14
  77. package/dist/election/leadership.d.ts.map +0 -1
  78. package/dist/election/leadership.js +0 -23
  79. package/dist/election/leadership.js.map +0 -1
  80. package/dist/local-directory/local-directory.d.ts +0 -7
  81. package/dist/local-directory/local-directory.d.ts.map +0 -1
  82. package/dist/local-directory/local-directory.js +0 -75
  83. package/dist/local-directory/local-directory.js.map +0 -1
  84. package/dist/local-directory/network-directory-error.d.ts +0 -8
  85. package/dist/local-directory/network-directory-error.d.ts.map +0 -1
  86. package/dist/local-directory/network-directory-error.js +0 -13
  87. package/dist/local-directory/network-directory-error.js.map +0 -1
  88. package/dist/shared/fs/durable-write.d.ts +0 -7
  89. package/dist/shared/fs/durable-write.d.ts.map +0 -1
  90. package/dist/shared/fs/durable-write.js +0 -47
  91. package/dist/shared/fs/durable-write.js.map +0 -1
  92. package/dist/shared/fs/errno.d.ts +0 -2
  93. package/dist/shared/fs/errno.d.ts.map +0 -1
  94. package/dist/shared/fs/errno.js +0 -4
  95. package/dist/shared/fs/errno.js.map +0 -1
  96. package/dist/shared/fs/patiently.d.ts +0 -3
  97. package/dist/shared/fs/patiently.d.ts.map +0 -1
  98. package/dist/shared/fs/patiently.js +0 -30
  99. package/dist/shared/fs/patiently.js.map +0 -1
  100. package/dist/shared/fs/replace-file.d.ts +0 -8
  101. package/dist/shared/fs/replace-file.d.ts.map +0 -1
  102. package/dist/shared/fs/replace-file.js +0 -12
  103. package/dist/shared/fs/replace-file.js.map +0 -1
  104. package/dist/shared/sqlite/is-busy.d.ts +0 -3
  105. package/dist/shared/sqlite/is-busy.d.ts.map +0 -1
  106. package/dist/shared/sqlite/is-busy.js +0 -10
  107. package/dist/shared/sqlite/is-busy.js.map +0 -1
@@ -1,75 +0,0 @@
1
- import { statfs } from 'node:fs/promises';
2
- import { dirname, resolve } from 'node:path';
3
- import { isErrno } from "../shared/fs/errno.js";
4
- import { NetworkDirectoryError } from "./network-directory-error.js";
5
- /**
6
- * The `f_type` Linux's statfs reports for each network file system: from the
7
- * kernel's uapi/linux/magic.h, gfs2_ondisk.h (GFS2) and Lustre's lustre_user.h.
8
- * FUSE is left out on purpose: on one kernel, its mounts hold SQLite's locks.
9
- */
10
- const linuxNetworkFileSystems = new Map([
11
- [0x6969n, 'NFS'],
12
- [0x517bn, 'SMB'],
13
- [0xff534d42n, 'CIFS'],
14
- [0xfe534d42n, 'SMB2'],
15
- [0x00c36400n, 'Ceph'],
16
- [0x5346414fn, 'AFS'],
17
- [0x6b414653n, 'kAFS'],
18
- [0x73757245n, 'Coda'],
19
- [0x564cn, 'NCP'],
20
- [0x7461636fn, 'OCFS2'],
21
- [0x01161970n, 'GFS2'],
22
- [0x0bd00bd0n, 'Lustre'],
23
- [0x01021997n, '9p'],
24
- ]);
25
- const local = { kind: 'local' };
26
- const unknown = { kind: 'unknown' };
27
- /**
28
- * How each platform judges a directory. Only Linux reports a stable file
29
- * system type; macOS numbers its file systems as they load, so it has no
30
- * judge, and every directory counts as local there.
31
- */
32
- const judges = {
33
- linux: (path) => statfsOfNearest(path).then(({ type }) => {
34
- // f_type is a signed long, so a magic with its high bit set can arrive sign-extended.
35
- const fileSystem = linuxNetworkFileSystems.get(BigInt.asUintN(32, type));
36
- return fileSystem ? { kind: 'network', fileSystem } : local;
37
- }, () => unknown),
38
- win32: async (path) => isUncPath(path) ? { kind: 'network', fileSystem: 'UNC share' } : local,
39
- };
40
- /** A directory's file system does not change under a running process, so each local one is judged once. */
41
- const localDirectories = new Set();
42
- /**
43
- * Rejects with `NetworkDirectoryError` when `directory` is on a network file
44
- * system, where the election's lock is not shared reliably between machines.
45
- * A directory that does not exist yet is judged by its nearest existing parent.
46
- */
47
- export async function assertLocalDirectory(directory) {
48
- const path = resolve(directory);
49
- if (localDirectories.has(path))
50
- return;
51
- const judgement = (await judges[process.platform]?.(path)) ?? local;
52
- if (judgement.kind === 'network') {
53
- throw new NetworkDirectoryError(directory, judgement.fileSystem);
54
- }
55
- if (judgement.kind === 'local')
56
- localDirectories.add(path);
57
- }
58
- async function statfsOfNearest(path) {
59
- try {
60
- return await statfs(path, { bigint: true });
61
- }
62
- catch (error) {
63
- const parent = dirname(path);
64
- if (!isErrno(error, 'ENOENT') || parent === path)
65
- throw error;
66
- return statfsOfNearest(parent);
67
- }
68
- }
69
- /** `\\server\share`, `\\?\UNC\server\share` and `\\.\UNC\server\share`; `\\?\C:\` names a local drive. */
70
- function isUncPath(path) {
71
- if (/^\\\\[?.]\\/.test(path))
72
- return /^\\\\[?.]\\UNC\\/i.test(path);
73
- return path.startsWith('\\\\');
74
- }
75
- //# sourceMappingURL=local-directory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-directory.js","sourceRoot":"","sources":["../../src/local-directory/local-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAiB;IACtD,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,WAAW,EAAE,KAAK,CAAC;IACpB,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,WAAW,EAAE,OAAO,CAAC;IACtB,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,WAAW,EAAE,QAAQ,CAAC;IACvB,CAAC,WAAW,EAAE,IAAI,CAAC;CACpB,CAAC,CAAC;AASH,MAAM,KAAK,GAAc,EAA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C;IACD,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,IAAY;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,MAAM,KAAK,IAAI;YAAE,MAAM,KAAK,CAAC;QAC9D,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,0GAA0G;AAC1G,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
@@ -1,8 +0,0 @@
1
- /** The flight directory is on a file system that other machines share, where its election does not hold. */
2
- export declare class NetworkDirectoryError extends Error {
3
- readonly directory: string;
4
- /** The network file system the directory is on, for example `NFS`. */
5
- readonly fileSystem: string;
6
- constructor(directory: string, fileSystem: string);
7
- }
8
- //# sourceMappingURL=network-directory-error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"network-directory-error.d.ts","sourceRoot":"","sources":["../../src/local-directory/network-directory-error.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sEAAsE;IACtE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAQlD"}
@@ -1,13 +0,0 @@
1
- /** The flight directory is on a file system that other machines share, where its election does not hold. */
2
- export class NetworkDirectoryError extends Error {
3
- directory;
4
- /** The network file system the directory is on, for example `NFS`. */
5
- fileSystem;
6
- constructor(directory, fileSystem) {
7
- super(`The flight directory ${JSON.stringify(directory)} is on a network file system (${fileSystem}), where its election is not shared reliably between machines. Use a local directory.`);
8
- this.name = 'NetworkDirectoryError';
9
- this.directory = directory;
10
- this.fileSystem = fileSystem;
11
- }
12
- }
13
- //# sourceMappingURL=network-directory-error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"network-directory-error.js","sourceRoot":"","sources":["../../src/local-directory/network-directory-error.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,SAAS,CAAS;IAC3B,sEAAsE;IAC7D,UAAU,CAAS;IAE5B,YAAY,SAAiB,EAAE,UAAkB;QAC/C,KAAK,CACH,wBAAwB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,iCAAiC,UAAU,uFAAuF,CACpL,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Replaces `path` in one step like `atomicWrite`, and returns only once both
3
- * the new content and the replacement survive a power loss: a counter that
4
- * goes back after a crash would hand out a token twice.
5
- */
6
- export declare function durableWrite(path: string, content: string): Promise<void>;
7
- //# sourceMappingURL=durable-write.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-write.d.ts","sourceRoot":"","sources":["../../../src/shared/fs/durable-write.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAW/D"}
@@ -1,47 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { open, rm } from 'node:fs/promises';
3
- import { dirname } from 'node:path';
4
- import { isErrno } from "./errno.js";
5
- import { replaceFile } from "./replace-file.js";
6
- const draftOf = (path) => `${path}.${randomUUID()}.tmp`;
7
- /**
8
- * Replaces `path` in one step like `atomicWrite`, and returns only once both
9
- * the new content and the replacement survive a power loss: a counter that
10
- * goes back after a crash would hand out a token twice.
11
- */
12
- export async function durableWrite(path, content) {
13
- const draft = draftOf(path);
14
- try {
15
- await writeSynced(draft, content);
16
- await replaceFile(draft, path);
17
- }
18
- catch (error) {
19
- // A draft that never replaced `path` would only pile up, one per failed write.
20
- await rm(draft, { force: true });
21
- throw error;
22
- }
23
- await syncDirectory(dirname(path));
24
- }
25
- async function writeSynced(path, content) {
26
- await using handle = await open(path, 'wx');
27
- await handle.writeFile(content);
28
- await handle.sync();
29
- }
30
- /**
31
- * A rename lives in its directory, so the directory must reach the disk too.
32
- * Windows cannot open a directory to sync it, and some file systems refuse to
33
- * sync one; there the rename is as durable as that system makes it.
34
- */
35
- async function syncDirectory(directory) {
36
- if (process.platform === 'win32')
37
- return;
38
- await using handle = await open(directory, 'r');
39
- try {
40
- await handle.sync();
41
- }
42
- catch (error) {
43
- if (!isErrno(error, 'EINVAL') && !isErrno(error, 'ENOTSUP'))
44
- throw error;
45
- }
46
- }
47
- //# sourceMappingURL=durable-write.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-write.js","sourceRoot":"","sources":["../../../src/shared/fs/durable-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEh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,CAAC;AACH,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function isErrno(error: unknown, code: string): boolean;
2
- //# sourceMappingURL=errno.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errno.d.ts","sourceRoot":"","sources":["../../../src/shared/fs/errno.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D"}
@@ -1,4 +0,0 @@
1
- export function isErrno(error, code) {
2
- return error instanceof Error && 'code' in error && error.code === code;
3
- }
4
- //# sourceMappingURL=errno.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errno.js","sourceRoot":"","sources":["../../../src/shared/fs/errno.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAC,KAAc,EAAE,IAAY;IAClD,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC1E,CAAC"}
@@ -1,3 +0,0 @@
1
- /** Runs `operation`, and runs it again while Windows refuses the file for a moment; after that, the error reaches the caller. */
2
- export declare function patiently<T>(operation: () => Promise<T>): Promise<T>;
3
- //# sourceMappingURL=patiently.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"patiently.d.ts","sourceRoot":"","sources":["../../../src/shared/fs/patiently.ts"],"names":[],"mappings":"AAoBA,iIAAiI;AACjI,wBAAsB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAc1E"}
@@ -1,30 +0,0 @@
1
- import { setTimeout as delay } from 'node:timers/promises';
2
- import { isErrno } from "./errno.js";
3
- /** How long to retry a file operation that Windows refuses for a moment. */
4
- const WINDOWS_PATIENCE = 1000;
5
- /**
6
- * Windows refuses a file for a moment while another program holds it open
7
- * with no sharing, as a virus scanner can, or while a delete of it is in
8
- * progress. The error code is the same as for a real permission denial, so a
9
- * refusal is retried only for a limited time.
10
- */
11
- function isRefusedForNow(error) {
12
- return (process.platform === 'win32' &&
13
- ['EPERM', 'EACCES', 'EBUSY'].some((code) => isErrno(error, code)));
14
- }
15
- /** Runs `operation`, and runs it again while Windows refuses the file for a moment; after that, the error reaches the caller. */
16
- export async function patiently(operation) {
17
- const started = performance.now();
18
- for (let attempt = 0;; attempt++) {
19
- try {
20
- return await operation();
21
- }
22
- catch (error) {
23
- if (!isRefusedForNow(error) ||
24
- performance.now() - started > WINDOWS_PATIENCE)
25
- throw error;
26
- await delay(Math.min(5 * 2 ** attempt, 100));
27
- }
28
- }
29
- }
30
- //# sourceMappingURL=patiently.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"patiently.js","sourceRoot":"","sources":["../../../src/shared/fs/patiently.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC5B,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAClE,CAAC;AACJ,CAAC;AAED,iIAAiI;AACjI,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,SAA2B;IAC5D,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAClC,KAAK,IAAI,OAAO,GAAG,CAAC,GAAI,OAAO,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IACE,CAAC,eAAe,CAAC,KAAK,CAAC;gBACvB,WAAW,CAAC,GAAG,EAAE,GAAG,OAAO,GAAG,gBAAgB;gBAE9C,MAAM,KAAK,CAAC;YACd,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,8 +0,0 @@
1
- /**
2
- * Moves `draft` over `path` in one step. On Windows, a rename over a file
3
- * fails while another process has that file open, for example a waiter that
4
- * reads it at that moment. The refusal is brief, so the rename is tried again;
5
- * it stays the single commit point.
6
- */
7
- export declare function replaceFile(draft: string, path: string): Promise<void>;
8
- //# sourceMappingURL=replace-file.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replace-file.d.ts","sourceRoot":"","sources":["../../../src/shared/fs/replace-file.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAEtD"}
@@ -1,12 +0,0 @@
1
- import { rename } from 'node:fs/promises';
2
- import { patiently } from "./patiently.js";
3
- /**
4
- * Moves `draft` over `path` in one step. On Windows, a rename over a file
5
- * fails while another process has that file open, for example a waiter that
6
- * reads it at that moment. The refusal is brief, so the rename is tried again;
7
- * it stays the single commit point.
8
- */
9
- export function replaceFile(draft, path) {
10
- return patiently(() => rename(draft, path));
11
- }
12
- //# sourceMappingURL=replace-file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replace-file.js","sourceRoot":"","sources":["../../../src/shared/fs/replace-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,IAAY;IACrD,OAAO,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC"}
@@ -1,3 +0,0 @@
1
- /** Whether `error` means another connection holds a conflicting lock right now. */
2
- export declare function isBusy(error: unknown): boolean;
3
- //# sourceMappingURL=is-busy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-busy.d.ts","sourceRoot":"","sources":["../../../src/shared/sqlite/is-busy.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAQ9C"}
@@ -1,10 +0,0 @@
1
- const SQLITE_BUSY = 5;
2
- /** Whether `error` means another connection holds a conflicting lock right now. */
3
- export function isBusy(error) {
4
- return (error instanceof Error &&
5
- 'errcode' in error &&
6
- typeof error.errcode === 'number' &&
7
- // The low byte is the primary result code, covering SQLITE_BUSY_* variants.
8
- (error.errcode & 0xff) === SQLITE_BUSY);
9
- }
10
- //# sourceMappingURL=is-busy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-busy.js","sourceRoot":"","sources":["../../../src/shared/sqlite/is-busy.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,mFAAmF;AACnF,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,4EAA4E;QAC5E,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,WAAW,CACvC,CAAC;AACJ,CAAC"}