@leitwerk-dev/watcher-utils 0.2.1 → 0.3.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/README.md +5 -0
- package/dist/{chunk-BO52GPAV.js → chunk-B77B4EKW.js} +1 -1
- package/dist/chunk-B77B4EKW.js.map +1 -0
- package/dist/{chunk-ZW3LXDBX.js → chunk-Y4PXUOYO.js} +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -35
- package/dist/index.js.map +1 -1
- package/dist/poll-loop.d.ts +1 -1
- package/dist/poll-loop.d.ts.map +1 -1
- package/dist/poll-loop.js +1 -1
- package/dist/polling-coordinator.js +2 -2
- package/package.json +4 -4
- package/src/index.ts +0 -4
- package/src/poll-loop.ts +1 -1
- package/dist/chunk-BO52GPAV.js.map +0 -1
- package/dist/trigger-files.d.ts +0 -17
- package/dist/trigger-files.d.ts.map +0 -1
- package/src/trigger-files.ts +0 -47
- /package/dist/{chunk-ZW3LXDBX.js.map → chunk-Y4PXUOYO.js.map} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
`createPollSchedule(clock?)` reserves a deadline for each caller-owned key before
|
|
3
|
+
work starts. Invalid intervals use 30 seconds. Extensions use `deps.polling.create`
|
|
4
|
+
for the server polling lifecycle. Trigger-file helpers are private to
|
|
5
|
+
`showcase-processes` and are no longer exported here.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/poll-loop.ts"],"sourcesContent":["import { parseDurationMs } from \"./duration-parse.js\";\n\n/** Reserve the next poll time for a caller-owned key, before starting its work. @public */\nexport function createPollSchedule(now: () => number = () => Date.now()) {\n\tconst dueAt = new Map<string, number>();\n\treturn (key: string, interval = \"30s\", timestamp = now()): boolean => {\n\t\tif ((dueAt.get(key) ?? 0) > timestamp) return false;\n\t\tdueAt.set(key, timestamp + parseDurationMs(interval, 30_000));\n\t\treturn true;\n\t};\n}\n\n/** @public */\nexport interface PollResult {\n\t/** @public */\n\tcreated: string[];\n\t/** @internal */\n\taborted: string[];\n\t/** @internal */\n\tlabelExchanged: string[];\n\t/** @public */\n\tskipped: string[];\n\t/** @public */\n\terrors: string[];\n}\n\n/** @public */\nexport function emptyPollResult(): PollResult {\n\treturn {\n\t\tcreated: [],\n\t\taborted: [],\n\t\tlabelExchanged: [],\n\t\tskipped: [],\n\t\terrors: [],\n\t};\n}\n\n/** @internal */\nexport interface PollResultWithErrors {\n\t/** @internal */\n\treadonly errors: readonly string[];\n}\n\n/** @internal */\nexport interface PollLoop<T extends PollResultWithErrors = PollResult> {\n\t/** @internal */\n\tpoll(): Promise<T>;\n\t/** @internal */\n\tstart(): void;\n\t/** @internal */\n\tstop(): Promise<void>;\n}\n\n/**\n * Create a non-overlapping polling loop. `pollOnce` is the actual work;\n * concurrent calls to `poll()` coalesce into the in-flight promise.\n */\n/** @internal */\nexport function createPollLoop<T extends PollResultWithErrors>(opts: {\n\t/** @internal */\n\tpollOnce: () => Promise<T>;\n\t/** @internal */\n\tisEnabled: () => boolean;\n\t/** @internal */\n\tpollInterval: () => string;\n\t/** @internal */\n\tdefaultIntervalMs?: number;\n\t/** @internal */\n\tonScheduledResult: (result: T, durationMs: number) => void;\n\t/** @internal */\n\tonScheduledError: (error: unknown, durationMs: number) => void;\n}): PollLoop<T> {\n\tlet timer: ReturnType<typeof setInterval> | null = null;\n\tlet pollInFlight: Promise<T> | null = null;\n\tconst defaultMs = opts.defaultIntervalMs ?? 60_000;\n\n\tasync function poll(): Promise<T> {\n\t\tif (pollInFlight) {\n\t\t\treturn pollInFlight;\n\t\t}\n\t\tconst running = (async () => {\n\t\t\ttry {\n\t\t\t\treturn await opts.pollOnce();\n\t\t\t} finally {\n\t\t\t\tpollInFlight = null;\n\t\t\t}\n\t\t})();\n\t\tpollInFlight = running;\n\t\treturn running;\n\t}\n\n\tfunction pollScheduled(): void {\n\t\tconst startedAt = Date.now();\n\t\tvoid poll().then(\n\t\t\t(result) => opts.onScheduledResult(result, Date.now() - startedAt),\n\t\t\t(error: unknown) => opts.onScheduledError(error, Date.now() - startedAt),\n\t\t);\n\t}\n\n\treturn {\n\t\tpoll,\n\t\tstart() {\n\t\t\tif (timer) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!opts.isEnabled()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst ms = parseDurationMs(opts.pollInterval(), defaultMs);\n\t\t\ttimer = setInterval(pollScheduled, ms);\n\t\t\tpollScheduled();\n\t\t},\n\t\tasync stop() {\n\t\t\tif (timer) clearInterval(timer);\n\t\t\ttimer = null;\n\t\t\tawait pollInFlight;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AAGO,SAAS,mBAAmB,MAAoB,MAAM,KAAK,IAAI,GAAG;AACxE,QAAM,QAAQ,oBAAI,IAAoB;AACtC,SAAO,CAAC,KAAa,WAAW,OAAO,YAAY,IAAI,MAAe;AACrE,SAAK,MAAM,IAAI,GAAG,KAAK,KAAK,UAAW,QAAO;AAC9C,UAAM,IAAI,KAAK,YAAY,gBAAgB,UAAU,GAAM,CAAC;AAC5D,WAAO;AAAA,EACR;AACD;AAiBO,SAAS,kBAA8B;AAC7C,SAAO;AAAA,IACN,SAAS,CAAC;AAAA,IACV,SAAS,CAAC;AAAA,IACV,gBAAgB,CAAC;AAAA,IACjB,SAAS,CAAC;AAAA,IACV,QAAQ,CAAC;AAAA,EACV;AACD;AAuBO,SAAS,eAA+C,MAa/C;AACf,MAAI,QAA+C;AACnD,MAAI,eAAkC;AACtC,QAAM,YAAY,KAAK,qBAAqB;AAE5C,iBAAe,OAAmB;AACjC,QAAI,cAAc;AACjB,aAAO;AAAA,IACR;AACA,UAAM,WAAW,YAAY;AAC5B,UAAI;AACH,eAAO,MAAM,KAAK,SAAS;AAAA,MAC5B,UAAE;AACD,uBAAe;AAAA,MAChB;AAAA,IACD,GAAG;AACH,mBAAe;AACf,WAAO;AAAA,EACR;AAEA,WAAS,gBAAsB;AAC9B,UAAM,YAAY,KAAK,IAAI;AAC3B,SAAK,KAAK,EAAE;AAAA,MACX,CAAC,WAAW,KAAK,kBAAkB,QAAQ,KAAK,IAAI,IAAI,SAAS;AAAA,MACjE,CAAC,UAAmB,KAAK,iBAAiB,OAAO,KAAK,IAAI,IAAI,SAAS;AAAA,IACxE;AAAA,EACD;AAEA,SAAO;AAAA,IACN;AAAA,IACA,QAAQ;AACP,UAAI,OAAO;AACV;AAAA,MACD;AACA,UAAI,CAAC,KAAK,UAAU,GAAG;AACtB;AAAA,MACD;AACA,YAAM,KAAK,gBAAgB,KAAK,aAAa,GAAG,SAAS;AACzD,cAAQ,YAAY,eAAe,EAAE;AACrC,oBAAc;AAAA,IACf;AAAA,IACA,MAAM,OAAO;AACZ,UAAI,MAAO,eAAc,KAAK;AAC9B,cAAQ;AACR,YAAM;AAAA,IACP;AAAA,EACD;AACD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPollLoop
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-B77B4EKW.js";
|
|
4
4
|
|
|
5
5
|
// src/polling-coordinator.ts
|
|
6
6
|
function createPollingCoordinator(logger) {
|
|
@@ -43,4 +43,4 @@ function createPollingCoordinator(logger) {
|
|
|
43
43
|
export {
|
|
44
44
|
createPollingCoordinator
|
|
45
45
|
};
|
|
46
|
-
//# sourceMappingURL=chunk-
|
|
46
|
+
//# sourceMappingURL=chunk-Y4PXUOYO.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { parseDurationMs } from "./duration-parse.js";
|
|
2
2
|
export { createPollSchedule, emptyPollResult, type PollResult, } from "./poll-loop.js";
|
|
3
3
|
export { createPollingCoordinator } from "./polling-coordinator.js";
|
|
4
|
-
export { consumeTriggerFile, readTriggerFile, } from "./trigger-files.js";
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,KAAK,UAAU,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,KAAK,UAAU,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPollingCoordinator
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Y4PXUOYO.js";
|
|
4
4
|
import {
|
|
5
5
|
createPollSchedule,
|
|
6
6
|
emptyPollResult
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-B77B4EKW.js";
|
|
8
8
|
import {
|
|
9
9
|
parseDurationMs
|
|
10
10
|
} from "./chunk-D57H46H7.js";
|
|
11
|
-
|
|
12
|
-
// src/trigger-files.ts
|
|
13
|
-
import { readFile, unlink } from "fs/promises";
|
|
14
|
-
function errorCode(error) {
|
|
15
|
-
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const code = error.code;
|
|
19
|
-
return typeof code === "string" ? code : null;
|
|
20
|
-
}
|
|
21
|
-
async function readTriggerFile(filePath) {
|
|
22
|
-
try {
|
|
23
|
-
return { exists: true, content: await readFile(filePath, "utf8") };
|
|
24
|
-
} catch (error) {
|
|
25
|
-
if (errorCode(error) === "ENOENT") {
|
|
26
|
-
return { exists: false };
|
|
27
|
-
}
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async function consumeTriggerFile(filePath) {
|
|
32
|
-
try {
|
|
33
|
-
await unlink(filePath);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
if (errorCode(error) === "ENOENT") {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
11
|
export {
|
|
42
|
-
consumeTriggerFile,
|
|
43
12
|
createPollSchedule,
|
|
44
13
|
createPollingCoordinator,
|
|
45
14
|
emptyPollResult,
|
|
46
|
-
parseDurationMs
|
|
47
|
-
readTriggerFile
|
|
15
|
+
parseDurationMs
|
|
48
16
|
};
|
|
49
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/poll-loop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Reserve the next poll time for a caller-owned key, before starting its work. @
|
|
1
|
+
/** Reserve the next poll time for a caller-owned key, before starting its work. @public */
|
|
2
2
|
export declare function createPollSchedule(now?: () => number): (key: string, interval?: string, timestamp?: number) => boolean;
|
|
3
3
|
/** @public */
|
|
4
4
|
export interface PollResult {
|
package/dist/poll-loop.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll-loop.d.ts","sourceRoot":"","sources":["../src/poll-loop.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"poll-loop.d.ts","sourceRoot":"","sources":["../src/poll-loop.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,MAAyB,IAE9D,KAAK,MAAM,EAAE,iBAAgB,EAAE,kBAAiB,KAAG,OAAO,CAKlE;AAED,cAAc;AACd,MAAM,WAAW,UAAU;IAC1B,cAAc;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,gBAAgB;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,gBAAgB;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,cAAc;AACd,wBAAgB,eAAe,IAAI,UAAU,CAQ5C;AAED,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACpC,gBAAgB;IAChB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,gBAAgB;AAChB,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,oBAAoB,GAAG,UAAU;IACpE,gBAAgB;IAChB,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,gBAAgB;IAChB,KAAK,IAAI,IAAI,CAAC;IACd,gBAAgB;IAChB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB;AAED;;;GAGG;AACH,gBAAgB;AAChB,wBAAgB,cAAc,CAAC,CAAC,SAAS,oBAAoB,EAAE,IAAI,EAAE;IACpE,gBAAgB;IAChB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,gBAAgB;IAChB,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,gBAAgB;IAChB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,gBAAgB;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB;IAChB,iBAAiB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,gBAAgB;IAChB,gBAAgB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/D,GAAG,QAAQ,CAAC,CAAC,CAAC,CA+Cd"}
|
package/dist/poll-loop.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leitwerk-dev/watcher-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"build": "tsup --silent"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@leitwerk-dev/domain": "0.
|
|
22
|
-
"@leitwerk-dev/external-writes": "0.
|
|
23
|
-
"@leitwerk-dev/protocol": "0.
|
|
21
|
+
"@leitwerk-dev/domain": "0.3.0",
|
|
22
|
+
"@leitwerk-dev/external-writes": "0.3.0",
|
|
23
|
+
"@leitwerk-dev/protocol": "0.3.0",
|
|
24
24
|
"ms": "^2.1.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/src/index.ts
CHANGED
package/src/poll-loop.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseDurationMs } from "./duration-parse.js";
|
|
2
2
|
|
|
3
|
-
/** Reserve the next poll time for a caller-owned key, before starting its work. @
|
|
3
|
+
/** Reserve the next poll time for a caller-owned key, before starting its work. @public */
|
|
4
4
|
export function createPollSchedule(now: () => number = () => Date.now()) {
|
|
5
5
|
const dueAt = new Map<string, number>();
|
|
6
6
|
return (key: string, interval = "30s", timestamp = now()): boolean => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/poll-loop.ts"],"sourcesContent":["import { parseDurationMs } from \"./duration-parse.js\";\n\n/** Reserve the next poll time for a caller-owned key, before starting its work. @internal */\nexport function createPollSchedule(now: () => number = () => Date.now()) {\n\tconst dueAt = new Map<string, number>();\n\treturn (key: string, interval = \"30s\", timestamp = now()): boolean => {\n\t\tif ((dueAt.get(key) ?? 0) > timestamp) return false;\n\t\tdueAt.set(key, timestamp + parseDurationMs(interval, 30_000));\n\t\treturn true;\n\t};\n}\n\n/** @public */\nexport interface PollResult {\n\t/** @public */\n\tcreated: string[];\n\t/** @internal */\n\taborted: string[];\n\t/** @internal */\n\tlabelExchanged: string[];\n\t/** @public */\n\tskipped: string[];\n\t/** @public */\n\terrors: string[];\n}\n\n/** @public */\nexport function emptyPollResult(): PollResult {\n\treturn {\n\t\tcreated: [],\n\t\taborted: [],\n\t\tlabelExchanged: [],\n\t\tskipped: [],\n\t\terrors: [],\n\t};\n}\n\n/** @internal */\nexport interface PollResultWithErrors {\n\t/** @internal */\n\treadonly errors: readonly string[];\n}\n\n/** @internal */\nexport interface PollLoop<T extends PollResultWithErrors = PollResult> {\n\t/** @internal */\n\tpoll(): Promise<T>;\n\t/** @internal */\n\tstart(): void;\n\t/** @internal */\n\tstop(): Promise<void>;\n}\n\n/**\n * Create a non-overlapping polling loop. `pollOnce` is the actual work;\n * concurrent calls to `poll()` coalesce into the in-flight promise.\n */\n/** @internal */\nexport function createPollLoop<T extends PollResultWithErrors>(opts: {\n\t/** @internal */\n\tpollOnce: () => Promise<T>;\n\t/** @internal */\n\tisEnabled: () => boolean;\n\t/** @internal */\n\tpollInterval: () => string;\n\t/** @internal */\n\tdefaultIntervalMs?: number;\n\t/** @internal */\n\tonScheduledResult: (result: T, durationMs: number) => void;\n\t/** @internal */\n\tonScheduledError: (error: unknown, durationMs: number) => void;\n}): PollLoop<T> {\n\tlet timer: ReturnType<typeof setInterval> | null = null;\n\tlet pollInFlight: Promise<T> | null = null;\n\tconst defaultMs = opts.defaultIntervalMs ?? 60_000;\n\n\tasync function poll(): Promise<T> {\n\t\tif (pollInFlight) {\n\t\t\treturn pollInFlight;\n\t\t}\n\t\tconst running = (async () => {\n\t\t\ttry {\n\t\t\t\treturn await opts.pollOnce();\n\t\t\t} finally {\n\t\t\t\tpollInFlight = null;\n\t\t\t}\n\t\t})();\n\t\tpollInFlight = running;\n\t\treturn running;\n\t}\n\n\tfunction pollScheduled(): void {\n\t\tconst startedAt = Date.now();\n\t\tvoid poll().then(\n\t\t\t(result) => opts.onScheduledResult(result, Date.now() - startedAt),\n\t\t\t(error: unknown) => opts.onScheduledError(error, Date.now() - startedAt),\n\t\t);\n\t}\n\n\treturn {\n\t\tpoll,\n\t\tstart() {\n\t\t\tif (timer) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!opts.isEnabled()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst ms = parseDurationMs(opts.pollInterval(), defaultMs);\n\t\t\ttimer = setInterval(pollScheduled, ms);\n\t\t\tpollScheduled();\n\t\t},\n\t\tasync stop() {\n\t\t\tif (timer) clearInterval(timer);\n\t\t\ttimer = null;\n\t\t\tawait pollInFlight;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AAGO,SAAS,mBAAmB,MAAoB,MAAM,KAAK,IAAI,GAAG;AACxE,QAAM,QAAQ,oBAAI,IAAoB;AACtC,SAAO,CAAC,KAAa,WAAW,OAAO,YAAY,IAAI,MAAe;AACrE,SAAK,MAAM,IAAI,GAAG,KAAK,KAAK,UAAW,QAAO;AAC9C,UAAM,IAAI,KAAK,YAAY,gBAAgB,UAAU,GAAM,CAAC;AAC5D,WAAO;AAAA,EACR;AACD;AAiBO,SAAS,kBAA8B;AAC7C,SAAO;AAAA,IACN,SAAS,CAAC;AAAA,IACV,SAAS,CAAC;AAAA,IACV,gBAAgB,CAAC;AAAA,IACjB,SAAS,CAAC;AAAA,IACV,QAAQ,CAAC;AAAA,EACV;AACD;AAuBO,SAAS,eAA+C,MAa/C;AACf,MAAI,QAA+C;AACnD,MAAI,eAAkC;AACtC,QAAM,YAAY,KAAK,qBAAqB;AAE5C,iBAAe,OAAmB;AACjC,QAAI,cAAc;AACjB,aAAO;AAAA,IACR;AACA,UAAM,WAAW,YAAY;AAC5B,UAAI;AACH,eAAO,MAAM,KAAK,SAAS;AAAA,MAC5B,UAAE;AACD,uBAAe;AAAA,MAChB;AAAA,IACD,GAAG;AACH,mBAAe;AACf,WAAO;AAAA,EACR;AAEA,WAAS,gBAAsB;AAC9B,UAAM,YAAY,KAAK,IAAI;AAC3B,SAAK,KAAK,EAAE;AAAA,MACX,CAAC,WAAW,KAAK,kBAAkB,QAAQ,KAAK,IAAI,IAAI,SAAS;AAAA,MACjE,CAAC,UAAmB,KAAK,iBAAiB,OAAO,KAAK,IAAI,IAAI,SAAS;AAAA,IACxE;AAAA,EACD;AAEA,SAAO;AAAA,IACN;AAAA,IACA,QAAQ;AACP,UAAI,OAAO;AACV;AAAA,MACD;AACA,UAAI,CAAC,KAAK,UAAU,GAAG;AACtB;AAAA,MACD;AACA,YAAM,KAAK,gBAAgB,KAAK,aAAa,GAAG,SAAS;AACzD,cAAQ,YAAY,eAAe,EAAE;AACrC,oBAAc;AAAA,IACf;AAAA,IACA,MAAM,OAAO;AACZ,UAAI,MAAO,eAAc,KAAK;AAC9B,cAAQ;AACR,YAAM;AAAA,IACP;AAAA,EACD;AACD;","names":[]}
|
package/dist/trigger-files.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** @internal */
|
|
2
|
-
export type TriggerFileReadResult = {
|
|
3
|
-
/** @internal */
|
|
4
|
-
exists: false;
|
|
5
|
-
} | {
|
|
6
|
-
/** @internal */
|
|
7
|
-
exists: true;
|
|
8
|
-
/** @internal */
|
|
9
|
-
content: string;
|
|
10
|
-
};
|
|
11
|
-
/** @internal */
|
|
12
|
-
export declare function errorCode(error: unknown): string | null;
|
|
13
|
-
/** @internal */
|
|
14
|
-
export declare function readTriggerFile(filePath: string): Promise<TriggerFileReadResult>;
|
|
15
|
-
/** @internal */
|
|
16
|
-
export declare function consumeTriggerFile(filePath: string): Promise<void>;
|
|
17
|
-
//# sourceMappingURL=trigger-files.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-files.d.ts","sourceRoot":"","sources":["../src/trigger-files.ts"],"names":[],"mappings":"AAEA,gBAAgB;AAChB,MAAM,MAAM,qBAAqB,GAC9B;IACA,gBAAgB;IAChB,MAAM,EAAE,KAAK,CAAC;CACb,GACD;IACA,gBAAgB;IAChB,MAAM,EAAE,IAAI,CAAC;IACb,gBAAgB;IAChB,OAAO,EAAE,MAAM,CAAC;CACf,CAAC;AAEL,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMvD;AAED,gBAAgB;AAChB,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAStF;AAED,gBAAgB;AAChB,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASxE"}
|
package/src/trigger-files.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { readFile, unlink } from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
/** @internal */
|
|
4
|
-
export type TriggerFileReadResult =
|
|
5
|
-
| {
|
|
6
|
-
/** @internal */
|
|
7
|
-
exists: false;
|
|
8
|
-
}
|
|
9
|
-
| {
|
|
10
|
-
/** @internal */
|
|
11
|
-
exists: true;
|
|
12
|
-
/** @internal */
|
|
13
|
-
content: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/** @internal */
|
|
17
|
-
export function errorCode(error: unknown): string | null {
|
|
18
|
-
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const code = (error as { code?: unknown }).code;
|
|
22
|
-
return typeof code === "string" ? code : null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** @internal */
|
|
26
|
-
export async function readTriggerFile(filePath: string): Promise<TriggerFileReadResult> {
|
|
27
|
-
try {
|
|
28
|
-
return { exists: true, content: await readFile(filePath, "utf8") };
|
|
29
|
-
} catch (error) {
|
|
30
|
-
if (errorCode(error) === "ENOENT") {
|
|
31
|
-
return { exists: false };
|
|
32
|
-
}
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @internal */
|
|
38
|
-
export async function consumeTriggerFile(filePath: string): Promise<void> {
|
|
39
|
-
try {
|
|
40
|
-
await unlink(filePath);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
if (errorCode(error) === "ENOENT") {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
File without changes
|