@hop-top/kit 0.5.0-alpha.0 → 0.5.0-alpha.10
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/CHANGELOG.md +262 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-2JV3A7OP.js +1894 -0
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-72XZWQX7.js +504 -0
- package/dist/chunk-ABQSE7AI.js +513 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BLS2OBIQ.js +263 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-GGWJRWWA.js +309 -0
- package/dist/chunk-GHPJJV5L.js +613 -0
- package/dist/chunk-IXVQ62NZ.js +334 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-JZ22ZUFA.js +1131 -0
- package/dist/chunk-K7VCKJ27.js +814 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-MUIQVU6E.js +251 -0
- package/dist/chunk-NLMS7HGP.js +178 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-PSFYJGDG.js +1445 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QPUCXQXT.js +67 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T46YPHKN.js +669 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-WWUKGJB5.js +90 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YGYQUFGY.js +219 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-C5B5tnpA.d.ts +400 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +70 -885
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-DCe1boBz.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +184 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +137 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +18 -322
- package/dist/upgrade-p_zh3pvV.d.ts +102 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +236 -46
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +195 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +297 -0
- package/src/completion.test.ts +256 -145
- package/src/completion.ts +767 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +222 -0
- package/src/mcp/bridge.ts +291 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +410 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +142 -0
- package/src/tui/parity.ts +59 -13
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { C as CliError$1, b as CODE_CONFLICT, c as CODE_CONSENT_REFUSED, d as CODE_GENERIC, e as CODE_NOT_FOUND, f as CODE_OK, g as CODE_PREREQUISITE, h as CODE_PROVENANCE_MISSING, i as CODE_RATE_LIMITED, a as CODE_TRANSIENT, j as CODE_UNAUTHORIZED, k as CODE_USAGE, E as EXIT_CONFLICT, l as EXIT_CONSENT_REFUSED, m as EXIT_GENERIC, n as EXIT_NOT_FOUND, o as EXIT_OK, p as EXIT_PREREQUISITE, q as EXIT_PROVENANCE_MISSING, r as EXIT_RATE_LIMITED, s as EXIT_TRANSIENT, t as EXIT_UNAUTHORIZED, u as EXIT_USAGE, T as TRANSIENCE_PERMANENT, v as TRANSIENCE_TRANSIENT, w as TRANSIENCE_UNKNOWN, x as conflictError, y as consentRefusedError, z as exitClasses, A as exitCodeForClass, B as genericError, D as notFoundError, F as prerequisiteError, G as provenanceMissingError, H as rateLimitedError, I as renderError, J as transienceForCode, K as transientError, L as unauthorizedError, M as unwrapError, N as usageError, O as withTransience, P as wrapError } from './error-Do8Qji43.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module output/formatter
|
|
6
|
+
*
|
|
7
|
+
* Core Formatter interface + Options/OptionSpec/ColumnSpec types and
|
|
8
|
+
* parseOptions helper. Mirrors Go's go/console/output Formatter interface.
|
|
9
|
+
*/
|
|
10
|
+
/** Kinds of values an OptionSpec accepts. */
|
|
11
|
+
type OptionType = 'string' | 'int' | 'bool' | 'enum';
|
|
12
|
+
/** Describes one option accepted by a Formatter via --format-opt key=value. */
|
|
13
|
+
interface OptionSpec {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly type: OptionType;
|
|
16
|
+
readonly default?: string | number | boolean;
|
|
17
|
+
readonly usage: string;
|
|
18
|
+
readonly enum?: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validated map of option values produced by parseOptions. Keys are
|
|
22
|
+
* OptionSpec.name; values are coerced to the spec's declared type.
|
|
23
|
+
*/
|
|
24
|
+
type Options = Readonly<Record<string, string | number | boolean>>;
|
|
25
|
+
/**
|
|
26
|
+
* Column metadata used by every built-in formatter and by --cols validation.
|
|
27
|
+
*
|
|
28
|
+
* - `header` is the user-visible label, the name matched against --cols, AND
|
|
29
|
+
* the property read off the row object: header == key, universally. Go
|
|
30
|
+
* cannot express a header/key split through `table:""` struct tags, so no
|
|
31
|
+
* SDK offers one.
|
|
32
|
+
* - `key` is retained for source compatibility and must equal `header`;
|
|
33
|
+
* `columnName` reports the single effective name.
|
|
34
|
+
* - `priority` is accepted and stored but ignored — hide-on-overflow is a
|
|
35
|
+
* Go-only feature today.
|
|
36
|
+
*/
|
|
37
|
+
interface ColumnSpec {
|
|
38
|
+
readonly header: string;
|
|
39
|
+
readonly key: string;
|
|
40
|
+
readonly priority?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns a ColumnSpec's effective column name, rejecting a header/key split.
|
|
44
|
+
*
|
|
45
|
+
* Validating at read time keeps drift impossible while `key` still exists as
|
|
46
|
+
* a field.
|
|
47
|
+
*/
|
|
48
|
+
declare function columnName(c: ColumnSpec): string;
|
|
49
|
+
/**
|
|
50
|
+
* A Formatter encodes structured data to a writable stream.
|
|
51
|
+
*
|
|
52
|
+
* Implementations declare their key, file extensions, and the option keys
|
|
53
|
+
* they accept. The dispatch helper validates --format-opt input against
|
|
54
|
+
* options() before invoking render(), so render() may trust opts to only
|
|
55
|
+
* contain declared keys with values coerced to declared types.
|
|
56
|
+
*/
|
|
57
|
+
interface Formatter<T = unknown> {
|
|
58
|
+
/** Unique format identifier exposed via --format <key>. */
|
|
59
|
+
readonly key: string;
|
|
60
|
+
/**
|
|
61
|
+
* File extensions (with leading dot, e.g. ".csv") that map to this
|
|
62
|
+
* formatter for --output extension inference. May be empty.
|
|
63
|
+
*/
|
|
64
|
+
readonly extensions: readonly string[];
|
|
65
|
+
/** Option specs accepted by this formatter via --format-opt key=value. */
|
|
66
|
+
readonly options: readonly OptionSpec[];
|
|
67
|
+
/**
|
|
68
|
+
* Renders data to out.
|
|
69
|
+
*
|
|
70
|
+
* @param out Destination writable stream.
|
|
71
|
+
* @param data Single row or readonly array of rows.
|
|
72
|
+
* @param opts Validated options; only declared keys with coerced values.
|
|
73
|
+
* @param cols Effective column list, already resolved by dispatch: the
|
|
74
|
+
* user's `--cols` when supplied, else the caller's ColumnSpec headers in
|
|
75
|
+
* list order, else empty meaning "fall back to payload key order".
|
|
76
|
+
* Render columns in exactly this order — it is both the labels and, since
|
|
77
|
+
* header == key, the lookup names on each row.
|
|
78
|
+
*/
|
|
79
|
+
render(out: NodeJS.WritableStream, data: T | readonly T[], opts: Options, cols: readonly string[]): Promise<void> | void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validates raw `key=value` pairs against specs and returns a coerced
|
|
83
|
+
* Options map. Unknown keys, type errors, and out-of-enum values throw an
|
|
84
|
+
* Error listing the offending key and the valid set.
|
|
85
|
+
*
|
|
86
|
+
* A pair without `=` (e.g. `"no-header"`) is treated as bool true; only
|
|
87
|
+
* valid when the matching spec has type `'bool'`.
|
|
88
|
+
*
|
|
89
|
+
* Defaults from specs fill in any keys not present in pairs.
|
|
90
|
+
*/
|
|
91
|
+
declare function parseOptions(pairs: readonly string[], specs: readonly OptionSpec[]): Options;
|
|
92
|
+
/** Pretty-print an OptionType. */
|
|
93
|
+
declare function optionTypeName(t: OptionType): string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @module output/projection
|
|
97
|
+
*
|
|
98
|
+
* Helpers for projecting structured data through ColumnSpec lists. Mirrors
|
|
99
|
+
* Go's projection.go (projectToMaps / TableHeaders).
|
|
100
|
+
*
|
|
101
|
+
* Unlike Go (which uses `table:""` struct tags), TS callers pass an explicit
|
|
102
|
+
* ColumnSpec[] list. When no columns are provided, callers fall back to
|
|
103
|
+
* deriving headers from the first row's own enumerable keys.
|
|
104
|
+
*
|
|
105
|
+
* A ColumnSpec's `header` and `key` are the same name: validation and value
|
|
106
|
+
* lookup are one operation, matching what Go's `table:""` tag can express.
|
|
107
|
+
* `--cols` reorders as well as selects, so the user's order wins over the
|
|
108
|
+
* ColumnSpec list's.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/** Returns the list of headers for a row source given an optional ColumnSpec list. */
|
|
112
|
+
declare function deriveHeaders(rows: readonly unknown[], columns?: readonly ColumnSpec[]): readonly string[];
|
|
113
|
+
/**
|
|
114
|
+
* Resolves the effective column list a formatter should render.
|
|
115
|
+
*
|
|
116
|
+
* Precedence, per the settled ordering contract:
|
|
117
|
+
* - `cols` non-empty → the user's `--cols`, verbatim and in user order
|
|
118
|
+
* (rule 2: --cols reorders as well as selects).
|
|
119
|
+
* - else a ColumnSpec list → its headers, in list order (rule 1).
|
|
120
|
+
* - else → empty, meaning "fall back to payload key order".
|
|
121
|
+
*
|
|
122
|
+
* Because header == key (rule 3), an ordered array of names carries
|
|
123
|
+
* everything a formatter needs: the labels and the row lookup keys are the
|
|
124
|
+
* same strings. Resolving here keeps precedence in one place and leaves the
|
|
125
|
+
* public Formatter signature untouched.
|
|
126
|
+
*/
|
|
127
|
+
declare function resolveEffectiveCols(cols: readonly string[], columns: readonly ColumnSpec[] | undefined): readonly string[];
|
|
128
|
+
/**
|
|
129
|
+
* Projects rows to plain objects keyed by column name, in `cols` order.
|
|
130
|
+
* An empty `cols` passes rows through untouched, so JSON/YAML keep whatever
|
|
131
|
+
* shape the caller handed in.
|
|
132
|
+
*/
|
|
133
|
+
declare function projectRows(rows: readonly unknown[], cols: readonly string[]): readonly Record<string, unknown>[];
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @module output/registry
|
|
137
|
+
*
|
|
138
|
+
* Registry holds Formatter implementations keyed by Formatter.key. Mirrors
|
|
139
|
+
* Go's *Registry. Built-in formatters register against `defaultRegistry` at
|
|
140
|
+
* module-load time.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Registry holds Formatter implementations.
|
|
145
|
+
*
|
|
146
|
+
* - `register` throws on duplicate keys (init-time fail-loud).
|
|
147
|
+
* - `override` quietly replaces — use when intentionally swapping a built-in.
|
|
148
|
+
* - `lookup` returns the formatter for a key, or undefined.
|
|
149
|
+
* - `keys` returns sorted format identifiers.
|
|
150
|
+
* - `formatters` returns sorted formatters.
|
|
151
|
+
* - `extensionMap` returns ext→key (e.g. ".csv" → "csv"); later
|
|
152
|
+
* registrations win on collision (alphabetical key order is the tie-break).
|
|
153
|
+
*/
|
|
154
|
+
declare class Registry {
|
|
155
|
+
private readonly byKey;
|
|
156
|
+
/**
|
|
157
|
+
* Adds f to the registry. Throws Error on duplicate key or empty key.
|
|
158
|
+
* Use `override` to intentionally replace.
|
|
159
|
+
*/
|
|
160
|
+
register<T>(f: Formatter<T>): void;
|
|
161
|
+
/** Replaces (or registers) the formatter for f.key. */
|
|
162
|
+
override<T>(f: Formatter<T>): void;
|
|
163
|
+
/** Returns the formatter registered under key, if any. */
|
|
164
|
+
lookup(key: string): Formatter | undefined;
|
|
165
|
+
/** Returns all registered format keys, sorted alphabetically. */
|
|
166
|
+
keys(): readonly string[];
|
|
167
|
+
/** Returns all registered formatters in key order. */
|
|
168
|
+
formatters(): readonly Formatter[];
|
|
169
|
+
/**
|
|
170
|
+
* Returns extension→key mappings (e.g. ".csv" → "csv") across all
|
|
171
|
+
* registered formatters. Later registrations win on collision; iteration
|
|
172
|
+
* is in sorted-key order so resolution is deterministic.
|
|
173
|
+
*/
|
|
174
|
+
extensionMap(): ReadonlyMap<string, string>;
|
|
175
|
+
}
|
|
176
|
+
/** Module-level Registry. Built-ins register here at module-load time. */
|
|
177
|
+
declare const defaultRegistry: Registry;
|
|
178
|
+
/** Returns a new, empty Registry — no built-ins registered. */
|
|
179
|
+
declare function newRegistry(): Registry;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @module output/formatters/json
|
|
183
|
+
*
|
|
184
|
+
* Built-in JSON formatter. Honors `indent` option (default 2) + trailing
|
|
185
|
+
* newline. Emitted key order follows the ColumnSpec list, narrowed and
|
|
186
|
+
* reordered by `cols`; without either, the payload passes through untouched.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
declare const jsonFormatter: Formatter;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @module output/formatters/yaml
|
|
193
|
+
*
|
|
194
|
+
* Built-in YAML formatter. Honors `flow-level` option (default -1, mapping
|
|
195
|
+
* to js-yaml's default block style). Emitted key order follows the ColumnSpec
|
|
196
|
+
* list, narrowed and reordered by `cols`; without either, the payload passes
|
|
197
|
+
* through untouched.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
declare const yamlFormatter: Formatter;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @module output/formatters/table
|
|
204
|
+
*
|
|
205
|
+
* Built-in table formatter. Hand-rolled aligner (matches the original
|
|
206
|
+
* output.ts behaviour). Column order comes from the ColumnSpec list, or the
|
|
207
|
+
* first row's key order when none was supplied; `cols` narrows and reorders.
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
declare const tableFormatter: Formatter;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @module output/flags
|
|
214
|
+
*
|
|
215
|
+
* Commander integration: registerOutputFlags adds the standard output
|
|
216
|
+
* flag suite (--format, --format-opt, --format-help, --cols, --template,
|
|
217
|
+
* --output|-o) to a Commander program. Mirrors Go's RegisterFlagsWith.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
/** Returns the Registry attached to cmd (walks parents) or defaultRegistry. */
|
|
221
|
+
declare function registryFor(cmd: Command): Registry;
|
|
222
|
+
/** Options for registerOutputFlags. */
|
|
223
|
+
interface RegisterOutputFlagsOptions {
|
|
224
|
+
/** Custom registry (default: defaultRegistry). */
|
|
225
|
+
registry?: Registry;
|
|
226
|
+
/** Per-flag opt-out. */
|
|
227
|
+
disable?: {
|
|
228
|
+
format?: boolean;
|
|
229
|
+
formatOpt?: boolean;
|
|
230
|
+
formatHelp?: boolean;
|
|
231
|
+
cols?: boolean;
|
|
232
|
+
template?: boolean;
|
|
233
|
+
output?: boolean;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Adds the output flag suite to a Commander program. Each flag is opt-out
|
|
238
|
+
* via `opts.disable.<flag>`. The active registry can be swapped via
|
|
239
|
+
* `opts.registry`; tests + multi-CLI binaries use this for isolated sets.
|
|
240
|
+
*/
|
|
241
|
+
declare function registerOutputFlags(program: Command, opts?: RegisterOutputFlagsOptions): void;
|
|
242
|
+
/**
|
|
243
|
+
* Merges --cols + --columns from a Commander opts object into a single
|
|
244
|
+
* ordered, deduped string[]. Trims whitespace, drops empty entries.
|
|
245
|
+
*/
|
|
246
|
+
declare function resolveCols(opts: Record<string, unknown>): string[];
|
|
247
|
+
|
|
248
|
+
/** Optional inputs to dispatch. */
|
|
249
|
+
interface DispatchOptions<T = unknown> {
|
|
250
|
+
/** ColumnSpec list for projection + --cols validation. */
|
|
251
|
+
columns?: readonly ColumnSpec[];
|
|
252
|
+
/** Override registry (default: registry stashed on cmd, else defaultRegistry). */
|
|
253
|
+
registry?: Registry;
|
|
254
|
+
/** Default format when --format isn't explicit (default: "table"). */
|
|
255
|
+
defaultFormat?: string;
|
|
256
|
+
_phantom?: T;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Renders `data` through the active formatter resolved from cmd's flags.
|
|
260
|
+
*
|
|
261
|
+
* Resolution order:
|
|
262
|
+
* 1. Resolve writer: empty/'-' → cmd.stdout (process.stdout), else file.
|
|
263
|
+
* 2. --format-help short-circuit: list registry or show one formatter.
|
|
264
|
+
* 3. Resolve format: explicit --format wins; else infer from --output ext.
|
|
265
|
+
* 4. Mismatch detection: explicit --format + ext mapping to different
|
|
266
|
+
* formatter is a hard error.
|
|
267
|
+
* 5. --template: build {items, cols} input, run eta, return.
|
|
268
|
+
* 6. Else: parseOptions, validateCols, formatter.render.
|
|
269
|
+
*/
|
|
270
|
+
declare function dispatch<T>(cmd: Command, data: T | readonly T[], options?: DispatchOptions<T>): Promise<void>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @module output
|
|
274
|
+
* @package @hop-top/kit
|
|
275
|
+
*
|
|
276
|
+
* Output rendering — writes structured values to a writable stream in one of
|
|
277
|
+
* the registered formats: table, JSON, YAML, CSV, text, etc.
|
|
278
|
+
*
|
|
279
|
+
* ## Quick start
|
|
280
|
+
*
|
|
281
|
+
* ```ts
|
|
282
|
+
* import { render, TABLE_FORMAT, JSON_FORMAT, YAML_FORMAT } from '@hop-top/kit/output';
|
|
283
|
+
*
|
|
284
|
+
* // Write a table to stdout
|
|
285
|
+
* render(process.stdout, TABLE_FORMAT, [{ id: '1', name: 'Alice' }]);
|
|
286
|
+
*
|
|
287
|
+
* // Write indented JSON
|
|
288
|
+
* render(process.stdout, JSON_FORMAT, { ok: true });
|
|
289
|
+
*
|
|
290
|
+
* // Write YAML
|
|
291
|
+
* render(process.stdout, YAML_FORMAT, { version: 1 });
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* ## Programmatic Formatter API
|
|
295
|
+
*
|
|
296
|
+
* For typed flag wiring + custom formatters use the Formatter / Registry
|
|
297
|
+
* surface from `output/formatter` and `output/registry`. The `render()`
|
|
298
|
+
* helper exported here is a thin shim over `defaultRegistry`.
|
|
299
|
+
*
|
|
300
|
+
* ## Backward compatibility
|
|
301
|
+
*
|
|
302
|
+
* `render(w, format, v)` keeps its original signature and renders every
|
|
303
|
+
* column in payload key order. New per-format options and column ordering
|
|
304
|
+
* (ColumnSpec lists, `--cols`) are accessed via `dispatch()`.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Structured error envelope; see `output/error`.
|
|
309
|
+
*
|
|
310
|
+
* A local alias, not `export type { CliError } from`: the declaration
|
|
311
|
+
* bundler rewrites a namespace member imported from another chunk as a
|
|
312
|
+
* value (`declare const ...: typeof CliError`), so the root barrel's
|
|
313
|
+
* `output` namespace would fail consumer type-checks (TS2693). A type
|
|
314
|
+
* declared in this module stays a type.
|
|
315
|
+
*/
|
|
316
|
+
type CliError = CliError$1;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Supported output formats. Includes the original three for backward-compat
|
|
320
|
+
* + new built-ins (csv, text) registered on the default registry.
|
|
321
|
+
*/
|
|
322
|
+
type Format = string;
|
|
323
|
+
/** Constant for the JSON output format. */
|
|
324
|
+
declare const JSON_FORMAT: "json";
|
|
325
|
+
/** Constant for the YAML output format. */
|
|
326
|
+
declare const YAML_FORMAT: "yaml";
|
|
327
|
+
/** Constant for the table output format. */
|
|
328
|
+
declare const TABLE_FORMAT: "table";
|
|
329
|
+
/** Constant for the CSV output format. */
|
|
330
|
+
declare const CSV_FORMAT: "csv";
|
|
331
|
+
/** Constant for the text output format. */
|
|
332
|
+
declare const TEXT_FORMAT: "text";
|
|
333
|
+
/**
|
|
334
|
+
* Renders `v` to `w` in the requested `format`.
|
|
335
|
+
*
|
|
336
|
+
* Backward-compatible thin shim over `defaultRegistry.lookup(format).render`.
|
|
337
|
+
*
|
|
338
|
+
* @throws {Error} For unknown format strings.
|
|
339
|
+
*/
|
|
340
|
+
declare function render(w: NodeJS.WritableStream, format: Format, v: unknown): void;
|
|
341
|
+
|
|
342
|
+
declare const output_CODE_CONFLICT: typeof CODE_CONFLICT;
|
|
343
|
+
declare const output_CODE_CONSENT_REFUSED: typeof CODE_CONSENT_REFUSED;
|
|
344
|
+
declare const output_CODE_GENERIC: typeof CODE_GENERIC;
|
|
345
|
+
declare const output_CODE_NOT_FOUND: typeof CODE_NOT_FOUND;
|
|
346
|
+
declare const output_CODE_OK: typeof CODE_OK;
|
|
347
|
+
declare const output_CODE_PREREQUISITE: typeof CODE_PREREQUISITE;
|
|
348
|
+
declare const output_CODE_PROVENANCE_MISSING: typeof CODE_PROVENANCE_MISSING;
|
|
349
|
+
declare const output_CODE_RATE_LIMITED: typeof CODE_RATE_LIMITED;
|
|
350
|
+
declare const output_CODE_TRANSIENT: typeof CODE_TRANSIENT;
|
|
351
|
+
declare const output_CODE_UNAUTHORIZED: typeof CODE_UNAUTHORIZED;
|
|
352
|
+
declare const output_CODE_USAGE: typeof CODE_USAGE;
|
|
353
|
+
declare const output_CSV_FORMAT: typeof CSV_FORMAT;
|
|
354
|
+
type output_CliError = CliError;
|
|
355
|
+
type output_ColumnSpec = ColumnSpec;
|
|
356
|
+
type output_DispatchOptions<T = unknown> = DispatchOptions<T>;
|
|
357
|
+
declare const output_EXIT_CONFLICT: typeof EXIT_CONFLICT;
|
|
358
|
+
declare const output_EXIT_CONSENT_REFUSED: typeof EXIT_CONSENT_REFUSED;
|
|
359
|
+
declare const output_EXIT_GENERIC: typeof EXIT_GENERIC;
|
|
360
|
+
declare const output_EXIT_NOT_FOUND: typeof EXIT_NOT_FOUND;
|
|
361
|
+
declare const output_EXIT_OK: typeof EXIT_OK;
|
|
362
|
+
declare const output_EXIT_PREREQUISITE: typeof EXIT_PREREQUISITE;
|
|
363
|
+
declare const output_EXIT_PROVENANCE_MISSING: typeof EXIT_PROVENANCE_MISSING;
|
|
364
|
+
declare const output_EXIT_RATE_LIMITED: typeof EXIT_RATE_LIMITED;
|
|
365
|
+
declare const output_EXIT_TRANSIENT: typeof EXIT_TRANSIENT;
|
|
366
|
+
declare const output_EXIT_UNAUTHORIZED: typeof EXIT_UNAUTHORIZED;
|
|
367
|
+
declare const output_EXIT_USAGE: typeof EXIT_USAGE;
|
|
368
|
+
type output_Format = Format;
|
|
369
|
+
type output_Formatter<T = unknown> = Formatter<T>;
|
|
370
|
+
declare const output_JSON_FORMAT: typeof JSON_FORMAT;
|
|
371
|
+
type output_OptionSpec = OptionSpec;
|
|
372
|
+
type output_OptionType = OptionType;
|
|
373
|
+
type output_Options = Options;
|
|
374
|
+
type output_RegisterOutputFlagsOptions = RegisterOutputFlagsOptions;
|
|
375
|
+
type output_Registry = Registry;
|
|
376
|
+
declare const output_Registry: typeof Registry;
|
|
377
|
+
declare const output_TABLE_FORMAT: typeof TABLE_FORMAT;
|
|
378
|
+
declare const output_TEXT_FORMAT: typeof TEXT_FORMAT;
|
|
379
|
+
declare const output_TRANSIENCE_PERMANENT: typeof TRANSIENCE_PERMANENT;
|
|
380
|
+
declare const output_TRANSIENCE_TRANSIENT: typeof TRANSIENCE_TRANSIENT;
|
|
381
|
+
declare const output_TRANSIENCE_UNKNOWN: typeof TRANSIENCE_UNKNOWN;
|
|
382
|
+
declare const output_YAML_FORMAT: typeof YAML_FORMAT;
|
|
383
|
+
declare const output_columnName: typeof columnName;
|
|
384
|
+
declare const output_conflictError: typeof conflictError;
|
|
385
|
+
declare const output_consentRefusedError: typeof consentRefusedError;
|
|
386
|
+
declare const output_defaultRegistry: typeof defaultRegistry;
|
|
387
|
+
declare const output_deriveHeaders: typeof deriveHeaders;
|
|
388
|
+
declare const output_dispatch: typeof dispatch;
|
|
389
|
+
declare const output_exitClasses: typeof exitClasses;
|
|
390
|
+
declare const output_exitCodeForClass: typeof exitCodeForClass;
|
|
391
|
+
declare const output_genericError: typeof genericError;
|
|
392
|
+
declare const output_jsonFormatter: typeof jsonFormatter;
|
|
393
|
+
declare const output_newRegistry: typeof newRegistry;
|
|
394
|
+
declare const output_notFoundError: typeof notFoundError;
|
|
395
|
+
declare const output_optionTypeName: typeof optionTypeName;
|
|
396
|
+
declare const output_parseOptions: typeof parseOptions;
|
|
397
|
+
declare const output_prerequisiteError: typeof prerequisiteError;
|
|
398
|
+
declare const output_projectRows: typeof projectRows;
|
|
399
|
+
declare const output_provenanceMissingError: typeof provenanceMissingError;
|
|
400
|
+
declare const output_rateLimitedError: typeof rateLimitedError;
|
|
401
|
+
declare const output_registerOutputFlags: typeof registerOutputFlags;
|
|
402
|
+
declare const output_registryFor: typeof registryFor;
|
|
403
|
+
declare const output_render: typeof render;
|
|
404
|
+
declare const output_renderError: typeof renderError;
|
|
405
|
+
declare const output_resolveCols: typeof resolveCols;
|
|
406
|
+
declare const output_resolveEffectiveCols: typeof resolveEffectiveCols;
|
|
407
|
+
declare const output_tableFormatter: typeof tableFormatter;
|
|
408
|
+
declare const output_transienceForCode: typeof transienceForCode;
|
|
409
|
+
declare const output_transientError: typeof transientError;
|
|
410
|
+
declare const output_unauthorizedError: typeof unauthorizedError;
|
|
411
|
+
declare const output_unwrapError: typeof unwrapError;
|
|
412
|
+
declare const output_usageError: typeof usageError;
|
|
413
|
+
declare const output_withTransience: typeof withTransience;
|
|
414
|
+
declare const output_wrapError: typeof wrapError;
|
|
415
|
+
declare const output_yamlFormatter: typeof yamlFormatter;
|
|
416
|
+
declare namespace output {
|
|
417
|
+
export { output_CODE_CONFLICT as CODE_CONFLICT, output_CODE_CONSENT_REFUSED as CODE_CONSENT_REFUSED, output_CODE_GENERIC as CODE_GENERIC, output_CODE_NOT_FOUND as CODE_NOT_FOUND, output_CODE_OK as CODE_OK, output_CODE_PREREQUISITE as CODE_PREREQUISITE, output_CODE_PROVENANCE_MISSING as CODE_PROVENANCE_MISSING, output_CODE_RATE_LIMITED as CODE_RATE_LIMITED, output_CODE_TRANSIENT as CODE_TRANSIENT, output_CODE_UNAUTHORIZED as CODE_UNAUTHORIZED, output_CODE_USAGE as CODE_USAGE, output_CSV_FORMAT as CSV_FORMAT, type output_CliError as CliError, type output_ColumnSpec as ColumnSpec, type output_DispatchOptions as DispatchOptions, output_EXIT_CONFLICT as EXIT_CONFLICT, output_EXIT_CONSENT_REFUSED as EXIT_CONSENT_REFUSED, output_EXIT_GENERIC as EXIT_GENERIC, output_EXIT_NOT_FOUND as EXIT_NOT_FOUND, output_EXIT_OK as EXIT_OK, output_EXIT_PREREQUISITE as EXIT_PREREQUISITE, output_EXIT_PROVENANCE_MISSING as EXIT_PROVENANCE_MISSING, output_EXIT_RATE_LIMITED as EXIT_RATE_LIMITED, output_EXIT_TRANSIENT as EXIT_TRANSIENT, output_EXIT_UNAUTHORIZED as EXIT_UNAUTHORIZED, output_EXIT_USAGE as EXIT_USAGE, type output_Format as Format, type output_Formatter as Formatter, output_JSON_FORMAT as JSON_FORMAT, type output_OptionSpec as OptionSpec, type output_OptionType as OptionType, type output_Options as Options, type output_RegisterOutputFlagsOptions as RegisterOutputFlagsOptions, output_Registry as Registry, output_TABLE_FORMAT as TABLE_FORMAT, output_TEXT_FORMAT as TEXT_FORMAT, output_TRANSIENCE_PERMANENT as TRANSIENCE_PERMANENT, output_TRANSIENCE_TRANSIENT as TRANSIENCE_TRANSIENT, output_TRANSIENCE_UNKNOWN as TRANSIENCE_UNKNOWN, output_YAML_FORMAT as YAML_FORMAT, output_columnName as columnName, output_conflictError as conflictError, output_consentRefusedError as consentRefusedError, output_defaultRegistry as defaultRegistry, output_deriveHeaders as deriveHeaders, output_dispatch as dispatch, output_exitClasses as exitClasses, output_exitCodeForClass as exitCodeForClass, output_genericError as genericError, output_jsonFormatter as jsonFormatter, output_newRegistry as newRegistry, output_notFoundError as notFoundError, output_optionTypeName as optionTypeName, output_parseOptions as parseOptions, output_prerequisiteError as prerequisiteError, output_projectRows as projectRows, output_provenanceMissingError as provenanceMissingError, output_rateLimitedError as rateLimitedError, output_registerOutputFlags as registerOutputFlags, output_registryFor as registryFor, output_render as render, output_renderError as renderError, output_resolveCols as resolveCols, output_resolveEffectiveCols as resolveEffectiveCols, output_tableFormatter as tableFormatter, output_transienceForCode as transienceForCode, output_transientError as transientError, output_unauthorizedError as unauthorizedError, output_unwrapError as unwrapError, output_usageError as usageError, output_withTransience as withTransience, output_wrapError as wrapError, output_yamlFormatter as yamlFormatter };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export { CSV_FORMAT as C, type DispatchOptions as D, type Format as F, JSON_FORMAT as J, type OptionSpec as O, type RegisterOutputFlagsOptions as R, TABLE_FORMAT as T, YAML_FORMAT as Y, type CliError as a, type ColumnSpec as b, type Formatter as c, type OptionType as d, type Options as e, Registry as f, TEXT_FORMAT as g, columnName as h, defaultRegistry as i, deriveHeaders as j, dispatch as k, jsonFormatter as l, optionTypeName as m, newRegistry as n, output as o, parseOptions as p, projectRows as q, registerOutputFlags as r, registryFor as s, render as t, resolveCols as u, resolveEffectiveCols as v, tableFormatter as w, yamlFormatter as y };
|
package/dist/output.d.ts
CHANGED
|
@@ -1,213 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Core Formatter interface + Options/OptionSpec/ColumnSpec types and
|
|
5
|
-
* parseOptions helper. Mirrors Go's go/console/output Formatter interface.
|
|
6
|
-
*/
|
|
7
|
-
/** Kinds of values an OptionSpec accepts. */
|
|
8
|
-
type OptionType = 'string' | 'int' | 'bool' | 'enum';
|
|
9
|
-
/** Describes one option accepted by a Formatter via --format-opt key=value. */
|
|
10
|
-
interface OptionSpec {
|
|
11
|
-
readonly name: string;
|
|
12
|
-
readonly type: OptionType;
|
|
13
|
-
readonly default?: string | number | boolean;
|
|
14
|
-
readonly usage: string;
|
|
15
|
-
readonly enum?: readonly string[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Validated map of option values produced by parseOptions. Keys are
|
|
19
|
-
* OptionSpec.name; values are coerced to the spec's declared type.
|
|
20
|
-
*/
|
|
21
|
-
type Options = Readonly<Record<string, string | number | boolean>>;
|
|
22
|
-
/**
|
|
23
|
-
* Column metadata used by table/csv/text formatters and --cols validation.
|
|
24
|
-
*
|
|
25
|
-
* - `header` is the user-visible label and the value matched against --cols.
|
|
26
|
-
* - `key` is the property name on the row object.
|
|
27
|
-
* - `priority` (optional) controls hide-on-overflow for table; higher wins.
|
|
28
|
-
*/
|
|
29
|
-
interface ColumnSpec {
|
|
30
|
-
readonly header: string;
|
|
31
|
-
readonly key: string;
|
|
32
|
-
readonly priority?: number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* A Formatter encodes structured data to a writable stream.
|
|
36
|
-
*
|
|
37
|
-
* Implementations declare their key, file extensions, and the option keys
|
|
38
|
-
* they accept. The dispatch helper validates --format-opt input against
|
|
39
|
-
* options() before invoking render(), so render() may trust opts to only
|
|
40
|
-
* contain declared keys with values coerced to declared types.
|
|
41
|
-
*/
|
|
42
|
-
interface Formatter<T = unknown> {
|
|
43
|
-
/** Unique format identifier exposed via --format <key>. */
|
|
44
|
-
readonly key: string;
|
|
45
|
-
/**
|
|
46
|
-
* File extensions (with leading dot, e.g. ".csv") that map to this
|
|
47
|
-
* formatter for --output extension inference. May be empty.
|
|
48
|
-
*/
|
|
49
|
-
readonly extensions: readonly string[];
|
|
50
|
-
/** Option specs accepted by this formatter via --format-opt key=value. */
|
|
51
|
-
readonly options: readonly OptionSpec[];
|
|
52
|
-
/**
|
|
53
|
-
* Renders data to out.
|
|
54
|
-
*
|
|
55
|
-
* @param out Destination writable stream.
|
|
56
|
-
* @param data Single row or readonly array of rows.
|
|
57
|
-
* @param opts Validated options; only declared keys with coerced values.
|
|
58
|
-
* @param cols User-requested column projection; empty means "all columns".
|
|
59
|
-
*/
|
|
60
|
-
render(out: NodeJS.WritableStream, data: T | readonly T[], opts: Options, cols: readonly string[]): Promise<void> | void;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Validates raw `key=value` pairs against specs and returns a coerced
|
|
64
|
-
* Options map. Unknown keys, type errors, and out-of-enum values throw an
|
|
65
|
-
* Error listing the offending key and the valid set.
|
|
66
|
-
*
|
|
67
|
-
* A pair without `=` (e.g. `"no-header"`) is treated as bool true; only
|
|
68
|
-
* valid when the matching spec has type `'bool'`.
|
|
69
|
-
*
|
|
70
|
-
* Defaults from specs fill in any keys not present in pairs.
|
|
71
|
-
*/
|
|
72
|
-
declare function parseOptions(pairs: readonly string[], specs: readonly OptionSpec[]): Options;
|
|
73
|
-
/** Pretty-print an OptionType. */
|
|
74
|
-
declare function optionTypeName(t: OptionType): string;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @module output/registry
|
|
78
|
-
*
|
|
79
|
-
* Registry holds Formatter implementations keyed by Formatter.key. Mirrors
|
|
80
|
-
* Go's *Registry. Built-in formatters register against `defaultRegistry` at
|
|
81
|
-
* module-load time.
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Registry holds Formatter implementations.
|
|
86
|
-
*
|
|
87
|
-
* - `register` throws on duplicate keys (init-time fail-loud).
|
|
88
|
-
* - `override` quietly replaces — use when intentionally swapping a built-in.
|
|
89
|
-
* - `lookup` returns the formatter for a key, or undefined.
|
|
90
|
-
* - `keys` returns sorted format identifiers.
|
|
91
|
-
* - `formatters` returns sorted formatters.
|
|
92
|
-
* - `extensionMap` returns ext→key (e.g. ".csv" → "csv"); later
|
|
93
|
-
* registrations win on collision (alphabetical key order is the tie-break).
|
|
94
|
-
*/
|
|
95
|
-
declare class Registry {
|
|
96
|
-
private readonly byKey;
|
|
97
|
-
/**
|
|
98
|
-
* Adds f to the registry. Throws Error on duplicate key or empty key.
|
|
99
|
-
* Use `override` to intentionally replace.
|
|
100
|
-
*/
|
|
101
|
-
register<T>(f: Formatter<T>): void;
|
|
102
|
-
/** Replaces (or registers) the formatter for f.key. */
|
|
103
|
-
override<T>(f: Formatter<T>): void;
|
|
104
|
-
/** Returns the formatter registered under key, if any. */
|
|
105
|
-
lookup(key: string): Formatter | undefined;
|
|
106
|
-
/** Returns all registered format keys, sorted alphabetically. */
|
|
107
|
-
keys(): readonly string[];
|
|
108
|
-
/** Returns all registered formatters in key order. */
|
|
109
|
-
formatters(): readonly Formatter[];
|
|
110
|
-
/**
|
|
111
|
-
* Returns extension→key mappings (e.g. ".csv" → "csv") across all
|
|
112
|
-
* registered formatters. Later registrations win on collision; iteration
|
|
113
|
-
* is in sorted-key order so resolution is deterministic.
|
|
114
|
-
*/
|
|
115
|
-
extensionMap(): ReadonlyMap<string, string>;
|
|
116
|
-
}
|
|
117
|
-
/** Module-level Registry. Built-ins register here at module-load time. */
|
|
118
|
-
declare const defaultRegistry: Registry;
|
|
119
|
-
/** Returns a new, empty Registry — no built-ins registered. */
|
|
120
|
-
declare function newRegistry(): Registry;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @module output/formatters/json
|
|
124
|
-
*
|
|
125
|
-
* Built-in JSON formatter. Honors `indent` option (default 2) + trailing
|
|
126
|
-
* newline. When `cols` is non-empty, projects rows to header-keyed objects.
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Build the JSON formatter. The `columns` ref is optional; when provided
|
|
131
|
-
* (via dispatch with a ColumnSpec list), rows are projected before encode.
|
|
132
|
-
*/
|
|
133
|
-
declare const jsonFormatter: Formatter;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @module output/formatters/yaml
|
|
137
|
-
*
|
|
138
|
-
* Built-in YAML formatter. Honors `flow-level` option (default -1, mapping
|
|
139
|
-
* to js-yaml's default block style). When `cols` is non-empty, projects
|
|
140
|
-
* rows to header-keyed objects.
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
declare const yamlFormatter: Formatter;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @module output/formatters/table
|
|
147
|
-
*
|
|
148
|
-
* Built-in table formatter. Hand-rolled aligner (matches the original
|
|
149
|
-
* output.ts behaviour). Honors `cols` to filter columns; preserves first-
|
|
150
|
-
* row key order otherwise.
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
declare const tableFormatter: Formatter;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @module output
|
|
157
|
-
* @package @hop-top/kit
|
|
158
|
-
*
|
|
159
|
-
* Output rendering — writes structured values to a writable stream in one of
|
|
160
|
-
* the registered formats: table, JSON, YAML, CSV, text, etc.
|
|
161
|
-
*
|
|
162
|
-
* ## Quick start
|
|
163
|
-
*
|
|
164
|
-
* ```ts
|
|
165
|
-
* import { render, TABLE_FORMAT, JSON_FORMAT, YAML_FORMAT } from '@hop-top/kit/output';
|
|
166
|
-
*
|
|
167
|
-
* // Write a table to stdout
|
|
168
|
-
* render(process.stdout, TABLE_FORMAT, [{ id: '1', name: 'Alice' }]);
|
|
169
|
-
*
|
|
170
|
-
* // Write indented JSON
|
|
171
|
-
* render(process.stdout, JSON_FORMAT, { ok: true });
|
|
172
|
-
*
|
|
173
|
-
* // Write YAML
|
|
174
|
-
* render(process.stdout, YAML_FORMAT, { version: 1 });
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* ## Programmatic Formatter API
|
|
178
|
-
*
|
|
179
|
-
* For typed flag wiring + custom formatters use the Formatter / Registry
|
|
180
|
-
* surface from `output/formatter` and `output/registry`. The `render()`
|
|
181
|
-
* helper exported here is a thin shim over `defaultRegistry`.
|
|
182
|
-
*
|
|
183
|
-
* ## Backward compatibility
|
|
184
|
-
*
|
|
185
|
-
* `render(w, format, v)` keeps its original signature. New per-format
|
|
186
|
-
* options + column projection are accessed via `dispatch()`.
|
|
187
|
-
*/
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Supported output formats. Includes the original three for backward-compat
|
|
191
|
-
* + new built-ins (csv, text) registered on the default registry.
|
|
192
|
-
*/
|
|
193
|
-
type Format = string;
|
|
194
|
-
/** Constant for the JSON output format. */
|
|
195
|
-
declare const JSON_FORMAT: "json";
|
|
196
|
-
/** Constant for the YAML output format. */
|
|
197
|
-
declare const YAML_FORMAT: "yaml";
|
|
198
|
-
/** Constant for the table output format. */
|
|
199
|
-
declare const TABLE_FORMAT: "table";
|
|
200
|
-
/** Constant for the CSV output format. */
|
|
201
|
-
declare const CSV_FORMAT: "csv";
|
|
202
|
-
/** Constant for the text output format. */
|
|
203
|
-
declare const TEXT_FORMAT: "text";
|
|
204
|
-
/**
|
|
205
|
-
* Renders `v` to `w` in the requested `format`.
|
|
206
|
-
*
|
|
207
|
-
* Backward-compatible thin shim over `defaultRegistry.lookup(format).render`.
|
|
208
|
-
*
|
|
209
|
-
* @throws {Error} For unknown format strings.
|
|
210
|
-
*/
|
|
211
|
-
declare function render(w: NodeJS.WritableStream, format: Format, v: unknown): void;
|
|
212
|
-
|
|
213
|
-
export { CSV_FORMAT, type ColumnSpec, type Format, type Formatter, JSON_FORMAT, type OptionSpec, type OptionType, type Options, Registry, TABLE_FORMAT, TEXT_FORMAT, YAML_FORMAT, defaultRegistry, jsonFormatter, newRegistry, optionTypeName, parseOptions, render, tableFormatter, yamlFormatter };
|
|
1
|
+
export { C as CSV_FORMAT, a as CliError, b as ColumnSpec, D as DispatchOptions, F as Format, c as Formatter, J as JSON_FORMAT, O as OptionSpec, d as OptionType, e as Options, R as RegisterOutputFlagsOptions, f as Registry, T as TABLE_FORMAT, g as TEXT_FORMAT, Y as YAML_FORMAT, h as columnName, i as defaultRegistry, j as deriveHeaders, k as dispatch, l as jsonFormatter, n as newRegistry, m as optionTypeName, p as parseOptions, q as projectRows, r as registerOutputFlags, s as registryFor, t as render, u as resolveCols, v as resolveEffectiveCols, w as tableFormatter, y as yamlFormatter } from './output-CjZWmL8s.js';
|
|
2
|
+
export { b as CODE_CONFLICT, c as CODE_CONSENT_REFUSED, d as CODE_GENERIC, e as CODE_NOT_FOUND, f as CODE_OK, g as CODE_PREREQUISITE, h as CODE_PROVENANCE_MISSING, i as CODE_RATE_LIMITED, a as CODE_TRANSIENT, j as CODE_UNAUTHORIZED, k as CODE_USAGE, E as EXIT_CONFLICT, l as EXIT_CONSENT_REFUSED, m as EXIT_GENERIC, n as EXIT_NOT_FOUND, o as EXIT_OK, p as EXIT_PREREQUISITE, q as EXIT_PROVENANCE_MISSING, r as EXIT_RATE_LIMITED, s as EXIT_TRANSIENT, t as EXIT_UNAUTHORIZED, u as EXIT_USAGE, T as TRANSIENCE_PERMANENT, v as TRANSIENCE_TRANSIENT, w as TRANSIENCE_UNKNOWN, x as conflictError, y as consentRefusedError, z as exitClasses, A as exitCodeForClass, B as genericError, D as notFoundError, F as prerequisiteError, G as provenanceMissingError, H as rateLimitedError, I as renderError, J as transienceForCode, K as transientError, L as unauthorizedError, M as unwrapError, N as usageError, O as withTransience, P as wrapError } from './error-Do8Qji43.js';
|
|
3
|
+
import 'commander';
|