sdk-environment 0.1.4 → 0.1.7
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/bin/run.bun.sdk-environment.bc +2 -2
- package/dist/contract/cli/getCommit.js.map +1 -1
- package/dist/domain.operations/getEnvironment/getEnvironment.d.ts +11 -3
- package/dist/domain.operations/getEnvironment/getEnvironment.js +26 -27
- package/dist/domain.operations/getEnvironment/getEnvironment.js.map +1 -1
- package/dist/domain.operations/parsers/access/asCacheKeyFromAccessKeyId.d.ts +8 -0
- package/dist/domain.operations/parsers/access/asCacheKeyFromAccessKeyId.js +12 -0
- package/dist/domain.operations/parsers/access/asCacheKeyFromAccessKeyId.js.map +1 -0
- package/dist/domain.operations/parsers/access/getAccessKeyIdFromAccountClient.d.ts +15 -0
- package/dist/domain.operations/parsers/access/getAccessKeyIdFromAccountClient.js +18 -0
- package/dist/domain.operations/parsers/access/getAccessKeyIdFromAccountClient.js.map +1 -0
- package/dist/domain.operations/parsers/access/getEnvAccess.d.ts +4 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountAlias.js +6 -24
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountAlias.js.map +1 -1
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.d.ts +23 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.js +67 -48
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.js.map +1 -1
- package/dist/domain.operations/parsers/access/getEnvAccessFromEnvar.js +1 -1
- package/dist/domain.operations/parsers/access/getEnvAccessFromEnvar.js.map +1 -1
- package/dist/domain.operations/parsers/access/isCredentialError.d.ts +9 -0
- package/dist/domain.operations/parsers/access/isCredentialError.js +38 -0
- package/dist/domain.operations/parsers/access/isCredentialError.js.map +1 -0
- package/dist/domain.operations/parsers/access/isModuleNotFoundError.d.ts +8 -0
- package/dist/domain.operations/parsers/access/isModuleNotFoundError.js +15 -0
- package/dist/domain.operations/parsers/access/isModuleNotFoundError.js.map +1 -0
- package/dist/domain.operations/parsers/access/isServerTransientError.d.ts +11 -0
- package/dist/domain.operations/parsers/access/isServerTransientError.js +22 -0
- package/dist/domain.operations/parsers/access/isServerTransientError.js.map +1 -0
- package/dist/domain.operations/parsers/access/isThrottleError.d.ts +10 -0
- package/dist/domain.operations/parsers/access/isThrottleError.js +30 -0
- package/dist/domain.operations/parsers/access/isThrottleError.js.map +1 -0
- package/dist/domain.operations/parsers/access/sleep.d.ts +6 -0
- package/dist/domain.operations/parsers/access/sleep.js +11 -0
- package/dist/domain.operations/parsers/access/sleep.js.map +1 -0
- package/dist/domain.operations/parsers/access/withCacheAcrossProcesses.d.ts +29 -0
- package/dist/domain.operations/parsers/access/withCacheAcrossProcesses.js +451 -0
- package/dist/domain.operations/parsers/access/withCacheAcrossProcesses.js.map +1 -0
- package/dist/domain.operations/parsers/access/withRetryOnThrottle.d.ts +11 -0
- package/dist/domain.operations/parsers/access/withRetryOnThrottle.js +44 -0
- package/dist/domain.operations/parsers/access/withRetryOnThrottle.js.map +1 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromEnvar.js +1 -1
- package/dist/domain.operations/parsers/commit/getEnvCommitFromEnvar.js.map +1 -1
- package/dist/domain.operations/parsers/config/getEnvConfigFromEnvar.js +1 -1
- package/dist/domain.operations/parsers/config/getEnvConfigFromEnvar.js.map +1 -1
- package/dist/domain.operations/parsers/factories.d.ts +2 -1
- package/dist/domain.operations/parsers/factories.js +4 -1
- package/dist/domain.operations/parsers/factories.js.map +1 -1
- package/dist/domain.operations/parsers/server/getEnvServerFromEnvar.js +1 -1
- package/dist/domain.operations/parsers/server/getEnvServerFromEnvar.js.map +1 -1
- package/dist/domain.operations/validators/isEnvironmentConfigSlug.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +48 -31
- package/readme.md +36 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = decide whether an aws error says the service is briefly unable to answer
|
|
3
|
+
* .why = such an error may clear for the next caller, so the shared cache keeps its
|
|
4
|
+
* waiters in a queue, one call at a time; any other error (a credential refusal,
|
|
5
|
+
* an unknown host, a refused connection) fails each caller the same way, so the
|
|
6
|
+
* waiters are freed to see their own error at once
|
|
7
|
+
* .note = a throttle, or a server fault: the sdk marks a 5xx with `$fault: 'server'`
|
|
8
|
+
*/
|
|
9
|
+
export declare const isServerTransientError: (input: {
|
|
10
|
+
error: unknown;
|
|
11
|
+
}) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isServerTransientError = void 0;
|
|
4
|
+
const isThrottleError_1 = require("./isThrottleError");
|
|
5
|
+
/**
|
|
6
|
+
* .what = decide whether an aws error says the service is briefly unable to answer
|
|
7
|
+
* .why = such an error may clear for the next caller, so the shared cache keeps its
|
|
8
|
+
* waiters in a queue, one call at a time; any other error (a credential refusal,
|
|
9
|
+
* an unknown host, a refused connection) fails each caller the same way, so the
|
|
10
|
+
* waiters are freed to see their own error at once
|
|
11
|
+
* .note = a throttle, or a server fault: the sdk marks a 5xx with `$fault: 'server'`
|
|
12
|
+
*/
|
|
13
|
+
const isServerTransientError = (input) => {
|
|
14
|
+
if ((0, isThrottleError_1.isThrottleError)(input))
|
|
15
|
+
return true;
|
|
16
|
+
return (typeof input.error === 'object' &&
|
|
17
|
+
input.error !== null &&
|
|
18
|
+
'$fault' in input.error &&
|
|
19
|
+
input.error.$fault === 'server');
|
|
20
|
+
};
|
|
21
|
+
exports.isServerTransientError = isServerTransientError;
|
|
22
|
+
//# sourceMappingURL=isServerTransientError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isServerTransientError.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/isServerTransientError.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAEpD;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAAyB,EAAW,EAAE;IAC3E,IAAI,IAAA,iCAAe,EAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,CACL,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,KAAK,CAAC,KAAK,KAAK,IAAI;QACpB,QAAQ,IAAI,KAAK,CAAC,KAAK;QACvB,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAChC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = decide whether an error is an aws throttle reply
|
|
3
|
+
* .why = only a throttle earns a retry; all other errors surface at once
|
|
4
|
+
* .note = reads `name` and the http status by shape, never `instanceof Error`: errors may
|
|
5
|
+
* cross realms. the name is what the account api sends; a 429 status covers a
|
|
6
|
+
* throttle that arrives under another name
|
|
7
|
+
*/
|
|
8
|
+
export declare const isThrottleError: (input: {
|
|
9
|
+
error: unknown;
|
|
10
|
+
}) => boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isThrottleError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = decide whether an error is an aws throttle reply
|
|
6
|
+
* .why = only a throttle earns a retry; all other errors surface at once
|
|
7
|
+
* .note = reads `name` and the http status by shape, never `instanceof Error`: errors may
|
|
8
|
+
* cross realms. the name is what the account api sends; a 429 status covers a
|
|
9
|
+
* throttle that arrives under another name
|
|
10
|
+
*/
|
|
11
|
+
const isThrottleError = (input) => {
|
|
12
|
+
if (!(typeof input.error === 'object' && input.error !== null))
|
|
13
|
+
return false;
|
|
14
|
+
if ('name' in input.error && input.error.name === 'TooManyRequestsException')
|
|
15
|
+
return true;
|
|
16
|
+
return getHttpStatusCode({ error: input.error }) === 429;
|
|
17
|
+
};
|
|
18
|
+
exports.isThrottleError = isThrottleError;
|
|
19
|
+
/**
|
|
20
|
+
* .what = read the http status an aws sdk v3 error carries, if any
|
|
21
|
+
* .why = the sdk sets `$metadata.httpStatusCode` on every service error
|
|
22
|
+
*/
|
|
23
|
+
const getHttpStatusCode = (input) => {
|
|
24
|
+
const metadata = '$metadata' in input.error ? input.error.$metadata : null;
|
|
25
|
+
if (!(typeof metadata === 'object' && metadata !== null))
|
|
26
|
+
return null;
|
|
27
|
+
const status = 'httpStatusCode' in metadata ? metadata.httpStatusCode : null;
|
|
28
|
+
return typeof status === 'number' ? status : null;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=isThrottleError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isThrottleError.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/isThrottleError.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAAC,KAAyB,EAAW,EAAE;IACpE,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7E,IAAI,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,0BAA0B;QAC1E,OAAO,IAAI,CAAC;IACd,OAAO,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC;AAC3D,CAAC,CAAC;AALW,QAAA,eAAe,mBAK1B;AAEF;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAwB,EAAiB,EAAE;IACpE,MAAM,QAAQ,GAAG,WAAW,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,IAAI,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACtE,MAAM,MAAM,GAAG,gBAAgB,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7E,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleep = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = wait for the given milliseconds
|
|
6
|
+
* .why = the parsers load at import time for every caller, so they use only apis
|
|
7
|
+
* every supported node holds; `timers/promises` needs node 15+
|
|
8
|
+
*/
|
|
9
|
+
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
10
|
+
exports.sleep = sleep;
|
|
11
|
+
//# sourceMappingURL=sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/sleep.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CACjD,IAAI,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;AADjC,QAAA,KAAK,SAC4B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = wrap an async fetch with a file cache shared by every process on this host
|
|
3
|
+
* .why = N cold processes make one fetch: one takes the lock and fetches; the rest
|
|
4
|
+
* wait, then read its file
|
|
5
|
+
* .note = the caller's `isQueueKeptOnError` sorts a holder's failure. one it rejects
|
|
6
|
+
* marks the failure, and every waiter fetches direct, in parallel. one it keeps,
|
|
7
|
+
* or a holder's death, leaves the next waiter to take the lock, so the api
|
|
8
|
+
* sees one caller at a time.
|
|
9
|
+
* a wait never passes the stale bound; past it, the waiter fetches direct
|
|
10
|
+
* .note = a lock is deleted only by pid match, so neither a holder nor a waiter
|
|
11
|
+
* frees a lock taken since it looked. the residual race (two waiters that
|
|
12
|
+
* break one dead lock within the same instant) costs one extra fetch,
|
|
13
|
+
* benign since the fetch is a read and the write is atomic
|
|
14
|
+
* .note = any fs fault, or a cache dir that is not ours, runs the fetch direct, as before
|
|
15
|
+
* .note = cache 'skip' never reads the shared file: it fetches fresh, then writes
|
|
16
|
+
* the file, so later callers on this host read the fresh value
|
|
17
|
+
*/
|
|
18
|
+
export declare const withCacheAcrossProcesses: <T>(fetch: () => Promise<T>, options: {
|
|
19
|
+
dir: string;
|
|
20
|
+
ttlMs: number;
|
|
21
|
+
staleMs: number;
|
|
22
|
+
pollMs: number;
|
|
23
|
+
isQueueKeptOnError: (input: {
|
|
24
|
+
error: unknown;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
}) => ((input: {
|
|
27
|
+
key: string;
|
|
28
|
+
cache: 'skip' | null;
|
|
29
|
+
}) => Promise<T>);
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withCacheAcrossProcesses = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const sleep_1 = require("./sleep");
|
|
8
|
+
// .note = bare core module names and `fs.promises`: this module loads at import time
|
|
9
|
+
// for every caller, so it avoids newer apis; its floor is node 14.14 (`fs.promises.rm`)
|
|
10
|
+
const { chmod, lstat, mkdir, readFile, rename, rm, stat, writeFile } = fs_1.promises;
|
|
11
|
+
/**
|
|
12
|
+
* .what = decide whether an error carries a given fs error code
|
|
13
|
+
* .why = some fs codes carry sense of their own (EEXIST = held, ESRCH = dead)
|
|
14
|
+
* .note = reads `code` by shape, never `instanceof Error`: under jest, node core
|
|
15
|
+
* errors come from another realm and fail an instanceof check
|
|
16
|
+
*/
|
|
17
|
+
const isErrnoCode = (input) => typeof input.error === 'object' &&
|
|
18
|
+
input.error !== null &&
|
|
19
|
+
'code' in input.error &&
|
|
20
|
+
typeof input.error.code === 'string' &&
|
|
21
|
+
input.codes.includes(input.error.code);
|
|
22
|
+
/**
|
|
23
|
+
* .what = decide whether an error is a node system error (an fs fault)
|
|
24
|
+
* .why = the shared cache is an optimization: any fs fault (denied, full disk,
|
|
25
|
+
* not a dir, too many open files) degrades to a direct fetch, never fails the caller
|
|
26
|
+
* .note = node system errors carry a string `code` and a string `syscall`;
|
|
27
|
+
* a code defect (TypeError, RangeError) carries neither, so it still surfaces
|
|
28
|
+
*/
|
|
29
|
+
const isFsFault = (input) => typeof input.error === 'object' &&
|
|
30
|
+
input.error !== null &&
|
|
31
|
+
'code' in input.error &&
|
|
32
|
+
typeof input.error.code === 'string' &&
|
|
33
|
+
'syscall' in input.error &&
|
|
34
|
+
typeof input.error.syscall === 'string';
|
|
35
|
+
/**
|
|
36
|
+
* .what = decide whether an error is a json parse failure
|
|
37
|
+
* .why = a corrupt cache file reads as a cold cache
|
|
38
|
+
* .note = reads `name` by shape, for the same cross-realm reason as isErrnoCode
|
|
39
|
+
*/
|
|
40
|
+
const isSyntaxError = (input) => typeof input.error === 'object' &&
|
|
41
|
+
input.error !== null &&
|
|
42
|
+
'name' in input.error &&
|
|
43
|
+
input.error.name === 'SyntaxError';
|
|
44
|
+
/**
|
|
45
|
+
* .what = decide whether this process's os account owns a file
|
|
46
|
+
* .why = on a shared host another os account could plant a cache file; only our own is trusted
|
|
47
|
+
* .note = hosts with no uid (windows) have a temp dir per os account, so all files pass
|
|
48
|
+
*/
|
|
49
|
+
const isOwnedByThisUser = (input) => {
|
|
50
|
+
const uidThis = process.getuid?.();
|
|
51
|
+
return uidThis === undefined || input.uid === uidThis;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* .what = decide whether a file or dir was last modified at least ageMs ago
|
|
55
|
+
* .why = one name for the cache ttl, the lock stale bound, and the wait deadline
|
|
56
|
+
*/
|
|
57
|
+
const isOlderThan = (input) => Date.now() - input.mtimeMs >= input.ageMs;
|
|
58
|
+
/**
|
|
59
|
+
* .what = compute one jittered wait between lock polls: 0.5x to 1.5x of pollMs
|
|
60
|
+
* .why = desyncs waiters so they do not poll in lockstep
|
|
61
|
+
*/
|
|
62
|
+
const getOnePollDelayMs = (input) => input.pollMs * (0.5 + Math.random());
|
|
63
|
+
/**
|
|
64
|
+
* .what = cast cache file content to its entry, or null if the shape is off
|
|
65
|
+
* .why = a file of the wrong shape reads as a cold cache, never as a value
|
|
66
|
+
* .note = the `as T` sits at the disk boundary: disk holds no type, and only
|
|
67
|
+
* setCache writes `{ value }` from the fetch's own T. no removal path:
|
|
68
|
+
* the generic wrapper cannot validate an arbitrary T at runtime
|
|
69
|
+
*/
|
|
70
|
+
const asCacheEntry = (input) => {
|
|
71
|
+
const parsed = JSON.parse(input.content);
|
|
72
|
+
if (typeof parsed !== 'object' || parsed === null || !('value' in parsed))
|
|
73
|
+
return null;
|
|
74
|
+
return { value: parsed.value };
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* .what = decide whether a file mode grants any permission to group or other
|
|
78
|
+
* .why = a cache dir open to other os accounts lets them plant files or locks
|
|
79
|
+
*/
|
|
80
|
+
const isModeOpenToOthers = (input) => (input.mode & 0o077) !== 0;
|
|
81
|
+
/**
|
|
82
|
+
* .what = cast a file mode to its owner-only subset
|
|
83
|
+
* .why = closes a dir of ours to other os accounts, and keeps the owner's own bits
|
|
84
|
+
*/
|
|
85
|
+
const asModeOwnerOnly = (input) => input.mode & 0o700;
|
|
86
|
+
/**
|
|
87
|
+
* .what = ensure the cache dir exists, is ours, and admits no other os account
|
|
88
|
+
* .why = a dir another account owns, or a symlink to one, could hold planted
|
|
89
|
+
* locks that stall us; such a dir is never used
|
|
90
|
+
* .note = returns false on any fs fault or an untrusted dir, so the fetch runs direct
|
|
91
|
+
*/
|
|
92
|
+
const genCacheDirTrusted = async (input) => {
|
|
93
|
+
try {
|
|
94
|
+
await mkdir(input.dir, { recursive: true, mode: 0o700 });
|
|
95
|
+
const stats = await lstat(input.dir);
|
|
96
|
+
if (stats.isSymbolicLink() || !stats.isDirectory())
|
|
97
|
+
return false;
|
|
98
|
+
if (!isOwnedByThisUser({ uid: stats.uid }))
|
|
99
|
+
return false;
|
|
100
|
+
// drop group and other bits from a dir of ours that was made loose
|
|
101
|
+
if (isModeOpenToOthers({ mode: stats.mode }))
|
|
102
|
+
await chmod(input.dir, asModeOwnerOnly({ mode: stats.mode }));
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (isFsFault({ error }))
|
|
107
|
+
return false;
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* .what = read the cached value if its file is ours and younger than the ttl
|
|
113
|
+
* .why = a fresh file answers the caller with no aws call
|
|
114
|
+
* .note = a file another os account owns reads as a cold cache, so a planted name never answers
|
|
115
|
+
* .note = an fs fault or a corrupt file reads as a cold cache
|
|
116
|
+
*/
|
|
117
|
+
const getOneCacheFresh = async (input) => {
|
|
118
|
+
try {
|
|
119
|
+
const stats = await stat(input.path);
|
|
120
|
+
if (!isOwnedByThisUser({ uid: stats.uid }))
|
|
121
|
+
return null;
|
|
122
|
+
if (isOlderThan({ mtimeMs: stats.mtimeMs, ageMs: input.ttlMs }))
|
|
123
|
+
return null;
|
|
124
|
+
const content = await readFile(input.path, 'utf8');
|
|
125
|
+
return asCacheEntry({ content });
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (isFsFault({ error }))
|
|
129
|
+
return null;
|
|
130
|
+
if (isSyntaxError({ error }))
|
|
131
|
+
return null;
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* .what = remove a file or dir of ours; an fs fault is swallowed
|
|
137
|
+
* .why = cleanup must never replace the caller's value or error
|
|
138
|
+
*/
|
|
139
|
+
const delPathBestEffort = async (input) => {
|
|
140
|
+
try {
|
|
141
|
+
await rm(input.path, { recursive: true, force: true });
|
|
142
|
+
return { isGone: true };
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (!isFsFault({ error }))
|
|
146
|
+
throw error;
|
|
147
|
+
return { isGone: false };
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* .what = write the cached value atomically, best effort
|
|
152
|
+
* .why = write-then-rename means a reader never sees a torn file
|
|
153
|
+
* .note = an fs fault leaves the cache cold; the caller still gets its value
|
|
154
|
+
*/
|
|
155
|
+
const setCache = async (input) => {
|
|
156
|
+
const pathTemp = `${input.path}.${process.pid}.${(0, crypto_1.randomBytes)(8).toString('hex')}.tmp`;
|
|
157
|
+
try {
|
|
158
|
+
await writeFile(pathTemp, JSON.stringify({ value: input.value }), {
|
|
159
|
+
mode: 0o600,
|
|
160
|
+
});
|
|
161
|
+
await rename(pathTemp, input.path);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (!isFsFault({ error }))
|
|
165
|
+
throw error;
|
|
166
|
+
await delPathBestEffort({ path: pathTemp });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* .what = try to take the lock; record this process's pid inside it
|
|
171
|
+
* .why = mkdir is atomic, so exactly one process wins a cold burst
|
|
172
|
+
* .note = TAKEN = this process holds it; HELD = another holder does;
|
|
173
|
+
* DENIED = an fs fault refuses the lock, so the shared cache is skipped
|
|
174
|
+
*/
|
|
175
|
+
const setLock = async (input) => {
|
|
176
|
+
try {
|
|
177
|
+
await mkdir(input.path, { mode: 0o700 });
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (isErrnoCode({ error, codes: ['EEXIST'] }))
|
|
181
|
+
return 'HELD';
|
|
182
|
+
if (isFsFault({ error }))
|
|
183
|
+
return 'DENIED';
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
// record the pid; a failed write must not strand an empty lock for the stale bound
|
|
187
|
+
try {
|
|
188
|
+
await writeFile((0, path_1.join)(input.path, 'pid'), String(process.pid));
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
await delPathBestEffort({ path: input.path }); // the stale bound breaks it if this fails
|
|
192
|
+
if (!isFsFault({ error }))
|
|
193
|
+
throw error;
|
|
194
|
+
return 'DENIED';
|
|
195
|
+
}
|
|
196
|
+
return 'TAKEN';
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* .what = read the holder's pid from the lock, if readable
|
|
200
|
+
* .why = a waiter checks whether the holder still lives
|
|
201
|
+
* .note = an fs fault (lock gone, torn write) reads as no pid
|
|
202
|
+
*/
|
|
203
|
+
const getOneLockPid = async (input) => {
|
|
204
|
+
try {
|
|
205
|
+
const content = await readFile((0, path_1.join)(input.path, 'pid'), 'utf8');
|
|
206
|
+
const pid = Number.parseInt(content, 10);
|
|
207
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
if (isFsFault({ error }))
|
|
211
|
+
return null;
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* .what = release the lock, only if it still holds the given pid; best effort
|
|
217
|
+
* .why = a process must never delete a lock another process took since:
|
|
218
|
+
* the holder frees only its own, a waiter breaks only the one it judged abandoned
|
|
219
|
+
* .note = pid null = the torn lock (no readable pid) that was judged abandoned
|
|
220
|
+
* .note = an fs fault is swallowed, so a release never replaces the caller's value
|
|
221
|
+
* or error; the stale bound and the wait deadline cover a lock left behind
|
|
222
|
+
* .note = isGone = the lock judged by that pid no longer stands (deleted, or replaced
|
|
223
|
+
* by another holder's); false only when the fs refused the delete
|
|
224
|
+
*/
|
|
225
|
+
const delLock = async (input) => {
|
|
226
|
+
const pidNow = await getOneLockPid({ path: input.path });
|
|
227
|
+
if (pidNow !== input.pid)
|
|
228
|
+
return { isGone: true };
|
|
229
|
+
return delPathBestEffort({ path: input.path });
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* .what = record that a holder's fetch failed, and when; best effort
|
|
233
|
+
* .why = tells waiters "the holder failed" apart from "the holder died": a failure
|
|
234
|
+
* frees them to fetch direct, a death leaves the next one to take the lock
|
|
235
|
+
* .note = the time rides in the content, not the mtime, so no fs clock grain blurs it
|
|
236
|
+
*/
|
|
237
|
+
const setFailureMark = async (input) => {
|
|
238
|
+
try {
|
|
239
|
+
await writeFile(input.path, String(Date.now()), { mode: 0o600 });
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (!isFsFault({ error }))
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* .what = decide whether a holder marked a failure at or after a given time
|
|
248
|
+
* .why = only a failure since the waiter began to wait is its holder's failure
|
|
249
|
+
* .note = an absent, foreign, unreadable, or malformed mark reads as no failure;
|
|
250
|
+
* the waiter then queues for the lock, bounded by the wait deadline
|
|
251
|
+
*/
|
|
252
|
+
const isFailureMarkedSince = async (input) => {
|
|
253
|
+
try {
|
|
254
|
+
const stats = await stat(input.path);
|
|
255
|
+
if (!isOwnedByThisUser({ uid: stats.uid }))
|
|
256
|
+
return false;
|
|
257
|
+
const markedAt = Number.parseInt(await readFile(input.path, 'utf8'), 10);
|
|
258
|
+
return Number.isInteger(markedAt) && markedAt >= input.sinceMs;
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (isFsFault({ error }))
|
|
262
|
+
return false;
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* .what = decide whether a waiter's wait is over
|
|
268
|
+
* .why = a waiter ends its wait and fetches direct when its wait passed the stale bound, or when its
|
|
269
|
+
* holder marked a failure that keeps no queue since the wait began
|
|
270
|
+
* .note = a caller that has not waited (waitBeganAt null) has no wait to end
|
|
271
|
+
*/
|
|
272
|
+
const isWaitOver = async (input) => {
|
|
273
|
+
if (input.waitBeganAt === null)
|
|
274
|
+
return false;
|
|
275
|
+
if (isOlderThan({ mtimeMs: input.waitBeganAt, ageMs: input.staleMs }))
|
|
276
|
+
return true;
|
|
277
|
+
return isFailureMarkedSince({
|
|
278
|
+
path: input.pathFail,
|
|
279
|
+
sinceMs: input.waitBeganAt,
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* .what = decide whether a process with this pid lives on this host
|
|
284
|
+
* .why = a dead holder's lock can be broken at once
|
|
285
|
+
*/
|
|
286
|
+
const isPidAlive = (input) => {
|
|
287
|
+
try {
|
|
288
|
+
process.kill(input.pid, 0); // signal 0 = probe only
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
// ESRCH = no such process; EPERM = it lives, under another os account
|
|
293
|
+
if (isErrnoCode({ error, codes: ['ESRCH'] }))
|
|
294
|
+
return false;
|
|
295
|
+
if (isErrnoCode({ error, codes: ['EPERM'] }))
|
|
296
|
+
return true;
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* .what = decide whether a held lock was abandoned
|
|
302
|
+
* .why = a waiter must never wait on a dead holder
|
|
303
|
+
* .note = abandoned when older than the stale bound (covers torn pid and pid reuse),
|
|
304
|
+
* or when its pid is readable and dead. an fs fault reads as not abandoned;
|
|
305
|
+
* the wait deadline bounds it
|
|
306
|
+
*/
|
|
307
|
+
const isLockAbandoned = async (input) => {
|
|
308
|
+
try {
|
|
309
|
+
const stats = await stat(input.path);
|
|
310
|
+
if (isOlderThan({ mtimeMs: stats.mtimeMs, ageMs: input.staleMs }))
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
if (isFsFault({ error }))
|
|
315
|
+
return false;
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
if (input.pid === null)
|
|
319
|
+
return false;
|
|
320
|
+
return !isPidAlive({ pid: input.pid });
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* .what = break the lock if its holder abandoned it; report the outcome
|
|
324
|
+
* .why = a waiter must never wait on a dead holder, and never spin on a lock it cannot break
|
|
325
|
+
* .note = HELD = a live holder; BROKEN = the abandoned lock is gone; DENIED = abandoned,
|
|
326
|
+
* but the fs refused the delete
|
|
327
|
+
* .note = the pid is read once: the waiter judges and deletes by that same pid,
|
|
328
|
+
* so a lock another process took since is never freed
|
|
329
|
+
*/
|
|
330
|
+
const delLockIfAbandoned = async (input) => {
|
|
331
|
+
const pidHolder = await getOneLockPid({ path: input.path });
|
|
332
|
+
const isAbandoned = await isLockAbandoned({
|
|
333
|
+
path: input.path,
|
|
334
|
+
pid: pidHolder,
|
|
335
|
+
staleMs: input.staleMs,
|
|
336
|
+
});
|
|
337
|
+
if (!isAbandoned)
|
|
338
|
+
return 'HELD';
|
|
339
|
+
const { isGone } = await delLock({ path: input.path, pid: pidHolder });
|
|
340
|
+
return isGone ? 'BROKEN' : 'DENIED';
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* .what = wrap an async fetch with a file cache shared by every process on this host
|
|
344
|
+
* .why = N cold processes make one fetch: one takes the lock and fetches; the rest
|
|
345
|
+
* wait, then read its file
|
|
346
|
+
* .note = the caller's `isQueueKeptOnError` sorts a holder's failure. one it rejects
|
|
347
|
+
* marks the failure, and every waiter fetches direct, in parallel. one it keeps,
|
|
348
|
+
* or a holder's death, leaves the next waiter to take the lock, so the api
|
|
349
|
+
* sees one caller at a time.
|
|
350
|
+
* a wait never passes the stale bound; past it, the waiter fetches direct
|
|
351
|
+
* .note = a lock is deleted only by pid match, so neither a holder nor a waiter
|
|
352
|
+
* frees a lock taken since it looked. the residual race (two waiters that
|
|
353
|
+
* break one dead lock within the same instant) costs one extra fetch,
|
|
354
|
+
* benign since the fetch is a read and the write is atomic
|
|
355
|
+
* .note = any fs fault, or a cache dir that is not ours, runs the fetch direct, as before
|
|
356
|
+
* .note = cache 'skip' never reads the shared file: it fetches fresh, then writes
|
|
357
|
+
* the file, so later callers on this host read the fresh value
|
|
358
|
+
*/
|
|
359
|
+
const withCacheAcrossProcesses = (fetch, options) => {
|
|
360
|
+
return async (input) => {
|
|
361
|
+
const pathFile = (0, path_1.join)(options.dir, `${input.key}.json`);
|
|
362
|
+
const pathLock = (0, path_1.join)(options.dir, `${input.key}.lock`);
|
|
363
|
+
const pathFail = (0, path_1.join)(options.dir, `${input.key}.failed`);
|
|
364
|
+
// skip the shared cache when its dir is not ours or the fs refuses it
|
|
365
|
+
const isDirTrusted = await genCacheDirTrusted({ dir: options.dir });
|
|
366
|
+
if (!isDirTrusted)
|
|
367
|
+
return fetch();
|
|
368
|
+
/**
|
|
369
|
+
* .what = fetch with no lock, then write the cache best effort
|
|
370
|
+
* .why = a waiter whose holder failed or stalled still answers, and still shares
|
|
371
|
+
*/
|
|
372
|
+
const getOneDirectThenShare = async () => {
|
|
373
|
+
const value = await fetch();
|
|
374
|
+
await setCache({ path: pathFile, value });
|
|
375
|
+
return value;
|
|
376
|
+
};
|
|
377
|
+
// a caller that asked to skip the cache fetches fresh, then shares
|
|
378
|
+
if (input.cache === 'skip')
|
|
379
|
+
return getOneDirectThenShare();
|
|
380
|
+
/**
|
|
381
|
+
* .what = fetch as the lock holder, write the cache, then release the lock
|
|
382
|
+
* .why = one holder per cold burst answers every waiter via the cache file
|
|
383
|
+
* .note = the release sits in `finally`, so a failed fetch frees the waiters too
|
|
384
|
+
*/
|
|
385
|
+
const getOneAsHolder = async () => {
|
|
386
|
+
try {
|
|
387
|
+
// another holder may have written just before this one took the lock
|
|
388
|
+
const cachedNow = await getOneCacheFresh({
|
|
389
|
+
path: pathFile,
|
|
390
|
+
ttlMs: options.ttlMs,
|
|
391
|
+
});
|
|
392
|
+
if (cachedNow)
|
|
393
|
+
return cachedNow.value;
|
|
394
|
+
// fetch, then share
|
|
395
|
+
return await getOneDirectThenShare();
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
// a failure that keeps no queue frees the waiters to fetch direct, in parallel;
|
|
399
|
+
// the mark lands before the release, so a waiter sees it once the lock is gone
|
|
400
|
+
if (!options.isQueueKeptOnError({ error }))
|
|
401
|
+
await setFailureMark({ path: pathFail });
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
await delLock({ path: pathLock, pid: process.pid });
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* .what = read the cache, else take the lock and fetch, else wait and look again
|
|
410
|
+
* .why = the one loop every caller runs; each pass ends in a value or a wait
|
|
411
|
+
* .note = state.waitBeganAt = when this caller first waited; null until it waits
|
|
412
|
+
*/
|
|
413
|
+
const getOneViaCache = async (state) => {
|
|
414
|
+
const cached = await getOneCacheFresh({
|
|
415
|
+
path: pathFile,
|
|
416
|
+
ttlMs: options.ttlMs,
|
|
417
|
+
});
|
|
418
|
+
if (cached)
|
|
419
|
+
return cached.value;
|
|
420
|
+
// a waiter whose wait is over fetches direct, rather than wait or queue
|
|
421
|
+
const isWaitDone = await isWaitOver({
|
|
422
|
+
waitBeganAt: state.waitBeganAt,
|
|
423
|
+
staleMs: options.staleMs,
|
|
424
|
+
pathFail,
|
|
425
|
+
});
|
|
426
|
+
if (isWaitDone)
|
|
427
|
+
return getOneDirectThenShare();
|
|
428
|
+
// take the lock if free
|
|
429
|
+
const lock = await setLock({ path: pathLock });
|
|
430
|
+
if (lock === 'DENIED')
|
|
431
|
+
return fetch();
|
|
432
|
+
if (lock === 'TAKEN')
|
|
433
|
+
return getOneAsHolder();
|
|
434
|
+
// break a lock whose holder is gone, then try again at once; a break the fs refuses fetches direct
|
|
435
|
+
const lockBreak = await delLockIfAbandoned({
|
|
436
|
+
path: pathLock,
|
|
437
|
+
staleMs: options.staleMs,
|
|
438
|
+
});
|
|
439
|
+
if (lockBreak === 'BROKEN')
|
|
440
|
+
return getOneViaCache(state);
|
|
441
|
+
if (lockBreak === 'DENIED')
|
|
442
|
+
return fetch();
|
|
443
|
+
// wait for the live holder, then look again
|
|
444
|
+
await (0, sleep_1.sleep)(getOnePollDelayMs({ pollMs: options.pollMs }));
|
|
445
|
+
return getOneViaCache({ waitBeganAt: state.waitBeganAt ?? Date.now() });
|
|
446
|
+
};
|
|
447
|
+
return getOneViaCache({ waitBeganAt: null });
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
exports.withCacheAcrossProcesses = withCacheAcrossProcesses;
|
|
451
|
+
//# sourceMappingURL=withCacheAcrossProcesses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withCacheAcrossProcesses.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/withCacheAcrossProcesses.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AACrC,2BAAoC;AACpC,+BAA4B;AAE5B,mCAAgC;AAEhC,qFAAqF;AACrF,gGAAgG;AAChG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,aAAE,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,WAAW,GAAG,CAAC,KAA0C,EAAW,EAAE,CAC1E,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;IAC/B,KAAK,CAAC,KAAK,KAAK,IAAI;IACpB,MAAM,IAAI,KAAK,CAAC,KAAK;IACrB,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ;IACpC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAA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E,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC,CAAC;QAEF,OAAO,cAAc,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC,CAAC;AArGW,QAAA,wBAAwB,4BAqGnC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = wrap an async fetch so an aws throttle reply backs off and retries
|
|
3
|
+
* .why = a TooManyRequestsException must not fail the caller; the sdk's own
|
|
4
|
+
* 3 attempts are not enough under a burst, so this layer is more patient
|
|
5
|
+
* .note = non-throttle errors surface at once, with no retry
|
|
6
|
+
*/
|
|
7
|
+
export declare const withRetryOnThrottle: <T>(fetch: () => Promise<T>, options: {
|
|
8
|
+
attempts: number;
|
|
9
|
+
baseMs: number;
|
|
10
|
+
capMs: number;
|
|
11
|
+
}) => (() => Promise<T>);
|