@leemour/cli-core 0.1.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/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +52 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +48 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +103 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +36 -0
- package/dist/errors.js.map +1 -0
- package/dist/exit-codes.d.ts +11 -0
- package/dist/exit-codes.d.ts.map +1 -0
- package/dist/exit-codes.js +25 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/http/index.d.ts +20 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +46 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/keyring.d.ts +27 -0
- package/dist/keyring.d.ts.map +1 -0
- package/dist/keyring.js +45 -0
- package/dist/keyring.js.map +1 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +7 -0
- package/dist/logger.js.map +1 -0
- package/dist/logging.d.ts +26 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +55 -0
- package/dist/logging.js.map +1 -0
- package/dist/paths.d.ts +28 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +23 -0
- package/dist/paths.js.map +1 -0
- package/dist/pretty.d.ts +10 -0
- package/dist/pretty.d.ts.map +1 -0
- package/dist/pretty.js +76 -0
- package/dist/pretty.js.map +1 -0
- package/dist/renderer.d.ts +32 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +48 -0
- package/dist/renderer.js.map +1 -0
- package/dist/retry.d.ts +27 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +26 -0
- package/dist/retry.js.map +1 -0
- package/dist/streams.d.ts +24 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +26 -0
- package/dist/streams.js.map +1 -0
- package/dist/testing/index.d.ts +24 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +29 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time.d.ts +21 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +19 -0
- package/dist/time.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seams a test needs, so that "no test touched the real machine" is a property of the code
|
|
3
|
+
* rather than a hope about every test remembering to opt out.
|
|
4
|
+
*/
|
|
5
|
+
export { brokenKeyring, memoryKeyring } from "../keyring.js";
|
|
6
|
+
export { captureStreams } from "../streams.js";
|
|
7
|
+
/**
|
|
8
|
+
* Time that never passes unless a test says so. A retry test that really sleeps 250 ms is a retry
|
|
9
|
+
* test nobody runs, so `sleep` resolves at once and records what it was asked for.
|
|
10
|
+
*/
|
|
11
|
+
export const fakeClock = (startMs = 0) => {
|
|
12
|
+
let elapsed = startMs;
|
|
13
|
+
const waits = [];
|
|
14
|
+
return {
|
|
15
|
+
waits,
|
|
16
|
+
clock: () => elapsed,
|
|
17
|
+
now: () => new Date(startMs + elapsed),
|
|
18
|
+
sleep: async (ms, signal, reason) => {
|
|
19
|
+
if (signal?.aborted)
|
|
20
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
21
|
+
waits.push(reason === undefined ? { ms } : { ms, reason });
|
|
22
|
+
elapsed += ms;
|
|
23
|
+
},
|
|
24
|
+
advance: (ms) => {
|
|
25
|
+
elapsed += ms;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAa9C;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,GAAG,CAAC,EAAa,EAAE;IAClD,IAAI,OAAO,GAAG,OAAO,CAAA;IACrB,MAAM,KAAK,GAAsC,EAAE,CAAA;IAEnD,OAAO;QACL,KAAK;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO;QACpB,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACtC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAClC,IAAI,MAAM,EAAE,OAAO;gBAAE,MAAM,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAA;YACvF,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;YAC1D,OAAO,IAAI,EAAE,CAAA;QACf,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE;YACd,OAAO,IAAI,EAAE,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/dist/time.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two clocks and the one timer core needs. All three are injectable, which is what makes
|
|
3
|
+
* timeout and backoff testable without anything actually waiting.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Why the client is waiting. The real sleep ignores it; a test uses it to tell an attempt's
|
|
7
|
+
* deadline apart from a delay between attempts, which are the only two reasons core ever waits.
|
|
8
|
+
* Without it a test that records waits sees both and cannot assert on either.
|
|
9
|
+
*/
|
|
10
|
+
export type SleepReason = "timeout" | "retry";
|
|
11
|
+
/** Rejects with an `AbortError` if the signal fires first, the way `fetch` does. */
|
|
12
|
+
export type SleepLike = (ms: number, signal?: AbortSignal, reason?: SleepReason) => Promise<void>;
|
|
13
|
+
/** Monotonic milliseconds. Durations come from here; a wall clock can step backwards. */
|
|
14
|
+
export type MonotonicClock = () => number;
|
|
15
|
+
/** Wall time. Timestamps that a person or another system will read come from here. */
|
|
16
|
+
export type WallClock = () => Date;
|
|
17
|
+
export declare const abortError: () => DOMException;
|
|
18
|
+
export declare const realSleep: SleepLike;
|
|
19
|
+
export declare const monotonic: MonotonicClock;
|
|
20
|
+
export declare const wallClock: WallClock;
|
|
21
|
+
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,CAAA;AAE7C,oFAAoF;AACpF,MAAM,MAAM,SAAS,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAEjG,yFAAyF;AACzF,MAAM,MAAM,cAAc,GAAG,MAAM,MAAM,CAAA;AAEzC,sFAAsF;AACtF,MAAM,MAAM,SAAS,GAAG,MAAM,IAAI,CAAA;AAElC,eAAO,MAAM,UAAU,QAAO,YAA4E,CAAA;AAE1G,eAAO,MAAM,SAAS,EAAE,SAgBpB,CAAA;AAEJ,eAAO,MAAM,SAAS,EAAE,cAAwC,CAAA;AAEhE,eAAO,MAAM,SAAS,EAAE,SAA4B,CAAA"}
|
package/dist/time.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two clocks and the one timer core needs. All three are injectable, which is what makes
|
|
3
|
+
* timeout and backoff testable without anything actually waiting.
|
|
4
|
+
*/
|
|
5
|
+
export const abortError = () => new DOMException("The operation was aborted.", "AbortError");
|
|
6
|
+
export const realSleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
7
|
+
if (signal?.aborted) {
|
|
8
|
+
reject(abortError());
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const timer = setTimeout(resolve, ms);
|
|
12
|
+
signal?.addEventListener("abort", () => {
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
reject(abortError());
|
|
15
|
+
}, { once: true });
|
|
16
|
+
});
|
|
17
|
+
export const monotonic = () => performance.now();
|
|
18
|
+
export const wallClock = () => new Date();
|
|
19
|
+
//# sourceMappingURL=time.js.map
|
package/dist/time.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAiB,EAAE,CAAC,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAA;AAE1G,MAAM,CAAC,MAAM,SAAS,GAAc,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CACjD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAA;QACpB,OAAM;IACR,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACrC,MAAM,EAAE,gBAAgB,CACtB,OAAO,EACP,GAAG,EAAE;QACH,YAAY,CAAC,KAAK,CAAC,CAAA;QACnB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAA;IACtB,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,SAAS,GAAmB,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,CAAA;AAEhE,MAAM,CAAC,MAAM,SAAS,GAAc,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leemour/cli-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Viacheslav Ptsarev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/leemour/cli-core.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./testing": {
|
|
26
|
+
"types": "./dist/testing/index.d.ts",
|
|
27
|
+
"default": "./dist/testing/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./http": {
|
|
30
|
+
"types": "./dist/http/index.d.ts",
|
|
31
|
+
"default": "./dist/http/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"cli-table3": "^0.6.5",
|
|
36
|
+
"picocolors": "^1.1.1",
|
|
37
|
+
"env-paths": "^4.0.0",
|
|
38
|
+
"pino": "^10.3.1",
|
|
39
|
+
"valibot": "^1.5.0"
|
|
40
|
+
},
|
|
41
|
+
"optionalDependencies": {
|
|
42
|
+
"@napi-rs/keyring": "^2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@biomejs/biome": "^2.3.14",
|
|
46
|
+
"@types/node": "^22.10.2",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^3.2.4",
|
|
49
|
+
"lefthook": "^2.1.8"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc --build",
|
|
56
|
+
"typecheck": "tsc --build --force --emitDeclarationOnly",
|
|
57
|
+
"lint": "biome check .",
|
|
58
|
+
"lint:fix": "biome check --write .",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"test:watch": "vitest",
|
|
61
|
+
"smoke:bun": "bun run scripts/smoke.ts",
|
|
62
|
+
"secrets:scan": "gitleaks git --no-banner --redact ."
|
|
63
|
+
}
|
|
64
|
+
}
|