@dereekb/dbx-cli 13.11.10 → 13.11.12

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.
@@ -1,5 +1,7 @@
1
1
  import { type Argv, type CommandModule } from 'yargs';
2
+ import { type ActionCommandSpec } from '../action/action.command.factory';
2
3
  import { type CliEnvDefault } from '../config/env';
4
+ import { type CliContext } from '../context/cli.context';
3
5
  import { type DoctorCheck } from '../doctor/doctor.command.factory';
4
6
  import { type CliModelManifest } from '../manifest/types';
5
7
  /**
@@ -26,6 +28,18 @@ export interface CreateCliInput {
26
28
  * it returns a single parent `model <model>` command so the top-level `--help` stays focused.
27
29
  */
28
30
  readonly apiCommands?: CommandModule[];
31
+ /**
32
+ * App-defined composite actions surfaced under `<cli> action <action>` (root) or
33
+ * `<cli> action <model> <action>` (model-scoped).
34
+ *
35
+ * Each action runs after the auth middleware so the handler receives the live
36
+ * {@link CliContext}. Use for high-leverage workflows that chain multiple
37
+ * `callModel` / `getModel` / `getMultipleModels` calls in-process so the caller
38
+ * does not pay one CLI round-trip per call.
39
+ *
40
+ * When omitted or empty, no `action` parent command is registered.
41
+ */
42
+ readonly actionCommands?: readonly ActionCommandSpec[];
29
43
  /**
30
44
  * Extra checks appended to the doctor's default check list.
31
45
  */
@@ -87,6 +101,33 @@ export interface CreateCliInput {
87
101
  * not want to surface the key-decode command itself.
88
102
  */
89
103
  readonly disableModelDecode?: boolean;
104
+ /**
105
+ * Test-only override that bypasses the auth middleware entirely and attaches the supplied
106
+ * {@link CliContext} on every command invocation.
107
+ *
108
+ * When set, the default auth middleware (OIDC discovery, disk token load, refresh, `process.exit`
109
+ * on failure) is replaced with a passthrough that just calls `setCliContext(testCliContext)`. The
110
+ * output middleware still runs.
111
+ *
112
+ * @internal Intended for use from `@dereekb/dbx-cli/test`. Not for production wiring.
113
+ */
114
+ readonly testCliContext?: CliContext;
115
+ /**
116
+ * Optional version string. When set, yargs registers `--version` / `-V` on the root parser
117
+ * returning this value. Defaults to omitted (no `--version` flag).
118
+ *
119
+ * Consumers typically pass their `package.json` version (read at build time, e.g. via a
120
+ * bundler `define` or a generated module).
121
+ */
122
+ readonly version?: string;
123
+ /**
124
+ * Optional shell-completion command name. When set, yargs registers
125
+ * `<cli> <completionCommandName>` (defaults to `completion`) that emits a bash/zsh script.
126
+ * Pass `false` to disable.
127
+ *
128
+ * @default 'completion'
129
+ */
130
+ readonly completionCommandName?: string | false;
90
131
  }
91
132
  /**
92
133
  * Top-level CLI builder.
@@ -2,12 +2,28 @@ import type { Arguments } from 'yargs';
2
2
  /**
3
3
  * Wraps a yargs command handler with the standard structured-error boilerplate:
4
4
  * any thrown error is converted to a `{ ok: false, ... }` envelope via {@link outputError}
5
- * and the process exits with code 1.
5
+ * and the process exits with the supplied code (default {@link CLI_EXIT_CODE_HANDLER} = 1).
6
6
  *
7
7
  * Lets command files drop the per-handler `try { ... } catch (e) { outputError(e); process.exit(1); }`
8
8
  * block while keeping the same observable behavior.
9
9
  *
10
10
  * @param handler - The inner command handler to invoke. May be sync or async.
11
+ * @param exitCode - Optional override for the exit code on failure (defaults to {@link CLI_EXIT_CODE_HANDLER}).
11
12
  * @returns An async handler that delegates to `handler` and converts thrown errors into the standard envelope.
12
13
  */
13
- export declare function wrapCommandHandler<T>(handler: (argv: Arguments<T>) => Promise<void> | void): (argv: Arguments<T>) => Promise<void>;
14
+ export declare function wrapCommandHandler<T>(handler: (argv: Arguments<T>) => Promise<void> | void, exitCode?: number): (argv: Arguments<T>) => Promise<void>;
15
+ /**
16
+ * Sync variant of {@link wrapCommandHandler} for handlers that never return a Promise.
17
+ *
18
+ * Yargs invokes the wrapped function synchronously when registered, so errors thrown by the
19
+ * inner handler (and by `process.exit` itself when stubbed in tests) propagate synchronously —
20
+ * which is what `parseSync()`-based tests assert against via `expect(() => ...).toThrow(...)`.
21
+ *
22
+ * Use this when the inner handler does not perform any I/O. For async handlers (HTTP calls,
23
+ * disk reads, prompts) keep using {@link wrapCommandHandler}.
24
+ *
25
+ * @param handler - The inner sync command handler.
26
+ * @param exitCode - Optional override for the exit code on failure.
27
+ * @returns A sync handler that converts thrown errors into the standard envelope.
28
+ */
29
+ export declare function wrapSyncCommandHandler<T>(handler: (argv: Arguments<T>) => void, exitCode?: number): (argv: Arguments<T>) => void;
@@ -4,3 +4,4 @@ export * from './handler';
4
4
  export * from './interactive';
5
5
  export * from './output';
6
6
  export * from './pagination';
7
+ export * from './stdin';
@@ -20,7 +20,23 @@ export interface CliOutputOptions {
20
20
  readonly dumpDir?: string;
21
21
  readonly pick?: string;
22
22
  readonly commandPath?: string[];
23
+ /**
24
+ * When true, the stdout JSON envelope is rendered with 2-space indent instead of compact.
25
+ * Driven by the global `--pretty` flag.
26
+ */
27
+ readonly pretty?: boolean;
23
28
  }
29
+ /**
30
+ * Standard exit code used when a CLI command handler throws.
31
+ *
32
+ * Used by {@link wrapCommandHandler} when no override is supplied.
33
+ */
34
+ export declare const CLI_EXIT_CODE_HANDLER = 1;
35
+ /**
36
+ * Exit code used when the auth middleware itself fails (no env, no token, expired refresh,
37
+ * etc.) — distinct from a handler error so scripts can disambiguate auth from logic failures.
38
+ */
39
+ export declare const CLI_EXIT_CODE_AUTH = 4;
24
40
  /**
25
41
  * Patterns that indicate a string may contain a secret token or credential.
26
42
  */
@@ -54,6 +70,51 @@ export declare function configureOutputOptions(options: CliOutputOptions): void;
54
70
  * @returns The active output options (empty object when never configured).
55
71
  */
56
72
  export declare function getOutputOptions(): CliOutputOptions;
73
+ /**
74
+ * Toggles the process-wide verbose flag. The HTTP layer (`call-model.client.ts`,
75
+ * `oidc.client.ts`) checks {@link isCliVerbose} before each request and emits a
76
+ * `[<method> <url>]` trace line to stderr when enabled.
77
+ *
78
+ * @param value - Whether verbose tracing is on.
79
+ */
80
+ export declare function setCliVerbose(value: boolean): void;
81
+ /**
82
+ * @returns Whether the verbose flag is currently enabled.
83
+ */
84
+ export declare function isCliVerbose(): boolean;
85
+ /**
86
+ * Writes a one-line stderr trace prefixed with `[verbose]` when the verbose
87
+ * flag is on. No-op otherwise. Kept off stdout so the JSON envelope on stdout
88
+ * stays parseable.
89
+ *
90
+ * @param message - The trace message.
91
+ */
92
+ export declare function verboseLog(message: string): void;
93
+ /**
94
+ * Drop-in `fetch` replacement that wraps the request with the configured verbose-trace
95
+ * and `--timeout` behavior. Aborts via `AbortController` after the configured timeout.
96
+ *
97
+ * Translates an aborted request into a {@link CliError} with code `TIMEOUT`.
98
+ *
99
+ * @param fetcher - The underlying fetch impl (defaults to global `fetch`). Allows tests to inject.
100
+ * @param input - The first arg to fetch (URL or Request).
101
+ * @param init - The RequestInit. Any existing `signal` is preserved; we only attach our own when no signal was supplied.
102
+ * @returns The fetch Response.
103
+ */
104
+ export declare function tracedFetch(fetcher: typeof fetch | undefined, input: string | URL | Request, init?: RequestInit): Promise<Response>;
105
+ /**
106
+ * Sets the process-wide HTTP timeout (in milliseconds) honored by the HTTP layer.
107
+ *
108
+ * Pass `undefined` to clear. The HTTP helpers thread this into an `AbortController`
109
+ * so individual `fetch` calls cancel after the configured duration.
110
+ *
111
+ * @param ms - Timeout in ms, or `undefined` to clear.
112
+ */
113
+ export declare function setCliTimeoutMs(ms: Maybe<number>): void;
114
+ /**
115
+ * @returns The current process-wide HTTP timeout in ms, or `undefined` when unset.
116
+ */
117
+ export declare function getCliTimeoutMs(): Maybe<number>;
57
118
  /**
58
119
  * Replaces the active secret-redaction pattern list with the given patterns.
59
120
  *
@@ -110,7 +171,8 @@ export declare function pickFields<T>(data: T, pick: string): T;
110
171
  * Prints a successful command result as a `{ ok: true, data, meta? }` JSON envelope on stdout.
111
172
  *
112
173
  * Also writes a full unfiltered dump to disk when `dumpDir` is configured, then applies any
113
- * configured `pick` filter to the stdout payload.
174
+ * configured `pick` filter to the stdout payload. Honors the global `--pretty` flag for the
175
+ * stdout payload only (the dump-to-disk path is always pretty-printed).
114
176
  *
115
177
  * @param data - The command result to emit.
116
178
  * @param meta - Optional additional metadata to attach to the envelope.
@@ -119,6 +181,8 @@ export declare function outputResult<T>(data: T, meta?: Record<string, unknown>)
119
181
  /**
120
182
  * Prints a failed command result as a `{ ok: false, error, code, suggestion? }` JSON envelope on stdout.
121
183
  *
184
+ * Honors the global `--pretty` flag.
185
+ *
122
186
  * @param error - The thrown value to convert. Mapped via {@link buildErrorOutput} (which consults any registered {@link CliErrorMapper}).
123
187
  */
124
188
  export declare function outputError(error: unknown): void;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Returns `true` when the user passed `-` (the conventional "read from stdin" sentinel) as a
3
+ * positional or flag value. Centralizes the convention so command handlers can pattern-match
4
+ * consistently.
5
+ *
6
+ * @param value - The raw argv value to inspect.
7
+ * @returns `true` when the value is exactly `'-'`.
8
+ * @__NO_SIDE_EFFECTS__
9
+ */
10
+ export declare function isStdinSentinel(value: unknown): boolean;
11
+ /**
12
+ * Reads the entire contents of `process.stdin` as a UTF-8 string.
13
+ *
14
+ * Used by command handlers that accept `-` to mean "read from stdin" (e.g. `--data -`,
15
+ * `get-many -`). Resolves once the stream emits `end`; no timeout is applied — callers that
16
+ * need one should wrap with `Promise.race`.
17
+ *
18
+ * @returns The UTF-8 decoded stdin contents.
19
+ */
20
+ export declare function readAllStdin(): Promise<string>;
21
+ /**
22
+ * Reads stdin as a list of whitespace-separated tokens (newlines, spaces, tabs).
23
+ *
24
+ * Empty tokens are dropped so a trailing newline doesn't introduce a phantom entry.
25
+ *
26
+ * @returns The tokens parsed from stdin.
27
+ */
28
+ export declare function readStdinTokens(): Promise<string[]>;
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
@@ -0,0 +1,381 @@
1
+ 'use strict';
2
+
3
+ var vitest = require('vitest');
4
+ var dbxCli = require('@dereekb/dbx-cli');
5
+
6
+ function _array_like_to_array(arr, len) {
7
+ if (len == null || len > arr.length) len = arr.length;
8
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
9
+ return arr2;
10
+ }
11
+ function _array_without_holes(arr) {
12
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
13
+ }
14
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
15
+ try {
16
+ var info = gen[key](arg);
17
+ var value = info.value;
18
+ } catch (error) {
19
+ reject(error);
20
+ return;
21
+ }
22
+ if (info.done) {
23
+ resolve(value);
24
+ } else {
25
+ Promise.resolve(value).then(_next, _throw);
26
+ }
27
+ }
28
+ function _async_to_generator(fn) {
29
+ return function() {
30
+ var self = this, args = arguments;
31
+ return new Promise(function(resolve, reject) {
32
+ var gen = fn.apply(self, args);
33
+ function _next(value) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
+ }
36
+ function _throw(err) {
37
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
38
+ }
39
+ _next(undefined);
40
+ });
41
+ };
42
+ }
43
+ function _instanceof(left, right) {
44
+ "@swc/helpers - instanceof";
45
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
46
+ return !!right[Symbol.hasInstance](left);
47
+ } else {
48
+ return left instanceof right;
49
+ }
50
+ }
51
+ function _iterable_to_array(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _non_iterable_spread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _to_consumable_array(arr) {
58
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
59
+ }
60
+ function _type_of(obj) {
61
+ "@swc/helpers - typeof";
62
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
63
+ }
64
+ function _unsupported_iterable_to_array(o, minLen) {
65
+ if (!o) return;
66
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
67
+ var n = Object.prototype.toString.call(o).slice(8, -1);
68
+ if (n === "Object" && o.constructor) n = o.constructor.name;
69
+ if (n === "Map" || n === "Set") return Array.from(n);
70
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
71
+ }
72
+ function _ts_generator(thisArg, body) {
73
+ var f, y, t, _ = {
74
+ label: 0,
75
+ sent: function() {
76
+ if (t[0] & 1) throw t[1];
77
+ return t[1];
78
+ },
79
+ trys: [],
80
+ ops: []
81
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
82
+ return d(g, "next", {
83
+ value: verb(0)
84
+ }), d(g, "throw", {
85
+ value: verb(1)
86
+ }), d(g, "return", {
87
+ value: verb(2)
88
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
89
+ value: function() {
90
+ return this;
91
+ }
92
+ }), g;
93
+ function verb(n) {
94
+ return function(v) {
95
+ return step([
96
+ n,
97
+ v
98
+ ]);
99
+ };
100
+ }
101
+ function step(op) {
102
+ if (f) throw new TypeError("Generator is already executing.");
103
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
104
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
105
+ if (y = 0, t) op = [
106
+ op[0] & 2,
107
+ t.value
108
+ ];
109
+ switch(op[0]){
110
+ case 0:
111
+ case 1:
112
+ t = op;
113
+ break;
114
+ case 4:
115
+ _.label++;
116
+ return {
117
+ value: op[1],
118
+ done: false
119
+ };
120
+ case 5:
121
+ _.label++;
122
+ y = op[1];
123
+ op = [
124
+ 0
125
+ ];
126
+ continue;
127
+ case 7:
128
+ op = _.ops.pop();
129
+ _.trys.pop();
130
+ continue;
131
+ default:
132
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
133
+ _ = 0;
134
+ continue;
135
+ }
136
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
137
+ _.label = op[1];
138
+ break;
139
+ }
140
+ if (op[0] === 6 && _.label < t[1]) {
141
+ _.label = t[1];
142
+ t = op;
143
+ break;
144
+ }
145
+ if (t && _.label < t[2]) {
146
+ _.label = t[2];
147
+ _.ops.push(op);
148
+ break;
149
+ }
150
+ if (t[2]) _.ops.pop();
151
+ _.trys.pop();
152
+ continue;
153
+ }
154
+ op = body.call(thisArg, _);
155
+ } catch (e) {
156
+ op = [
157
+ 6,
158
+ e
159
+ ];
160
+ y = 0;
161
+ } finally{
162
+ f = t = 0;
163
+ }
164
+ if (op[0] & 5) throw op[1];
165
+ return {
166
+ value: op[0] ? op[1] : void 0,
167
+ done: true
168
+ };
169
+ }
170
+ }
171
+ /**
172
+ * Builds a {@link CliContext} for use as `testCliContext` on {@link createCli}.
173
+ *
174
+ * Thin wrapper around {@link createCliContext} that exists so test code can import from a single
175
+ * test-only entry without pulling in production-only types.
176
+ *
177
+ * @param input - The context inputs (cliName, envName, env, accessToken, optional modelManifest).
178
+ * @returns The constructed {@link CliContext} that drives `callModel` / `getModel` / `getMultipleModels`
179
+ * against `input.env.apiBaseUrl` with `input.accessToken` as the Bearer token.
180
+ * @__NO_SIDE_EFFECTS__
181
+ */ function buildTestCliContext(input) {
182
+ return dbxCli.createCliContext({
183
+ cliName: input.cliName,
184
+ envName: input.envName,
185
+ env: input.env,
186
+ accessToken: input.accessToken,
187
+ modelManifest: input.modelManifest
188
+ });
189
+ }
190
+ /**
191
+ * Drives a CLI invocation in-process and captures all output.
192
+ *
193
+ * Creates a fresh yargs `Argv` per call (so middleware/option defaults can't leak across tests),
194
+ * parses `args`, and collects `process.stdout.write` / `process.stderr.write` / `console.log` /
195
+ * `console.error` output via `vi.spyOn`. The spies are always restored on completion.
196
+ *
197
+ * Always resolves — handler errors and yargs failures are surfaced in {@link RunCliCommandResult.error}
198
+ * instead of being thrown.
199
+ *
200
+ * @param input - The {@link CreateCliInput} used to build the CLI for this invocation. Pass a fresh
201
+ * object each call (or rely on the caller-side factory) — yargs `Argv` state is not reused across
202
+ * invocations.
203
+ * @param args - The argv vector to parse (e.g. `['get', 'p/abc']`).
204
+ * @returns The captured output envelope.
205
+ */ function runCliCommand(input, args) {
206
+ return _async_to_generator(function() {
207
+ var stdoutChunks, stderrChunks, writeSpy, errSpy, logSpy, errLogSpy, capturedExitCode, exitSentinel, exitSpy, capturedArgv, capturedError, helpOutput, e, result;
208
+ return _ts_generator(this, function(_state) {
209
+ switch(_state.label){
210
+ case 0:
211
+ stdoutChunks = [];
212
+ stderrChunks = [];
213
+ writeSpy = vitest.vi.spyOn(process.stdout, 'write').mockImplementation(function(chunk) {
214
+ stdoutChunks.push(toChunkString(chunk));
215
+ return true;
216
+ });
217
+ errSpy = vitest.vi.spyOn(process.stderr, 'write').mockImplementation(function(chunk) {
218
+ stderrChunks.push(toChunkString(chunk));
219
+ return true;
220
+ });
221
+ logSpy = vitest.vi.spyOn(console, 'log').mockImplementation(function() {
222
+ for(var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++){
223
+ parts[_key] = arguments[_key];
224
+ }
225
+ stdoutChunks.push(parts.map(function(p) {
226
+ return stringifyConsolePart(p);
227
+ }).join(' ') + '\n');
228
+ });
229
+ errLogSpy = vitest.vi.spyOn(console, 'error').mockImplementation(function() {
230
+ for(var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++){
231
+ parts[_key] = arguments[_key];
232
+ }
233
+ stderrChunks.push(parts.map(function(p) {
234
+ return stringifyConsolePart(p);
235
+ }).join(' ') + '\n');
236
+ });
237
+ exitSentinel = new Error('__cli_test_process_exit__');
238
+ exitSpy = vitest.vi.spyOn(process, 'exit').mockImplementation(function(code) {
239
+ capturedExitCode = typeof code === 'number' ? code : 0;
240
+ throw exitSentinel;
241
+ });
242
+ helpOutput = '';
243
+ _state.label = 1;
244
+ case 1:
245
+ _state.trys.push([
246
+ 1,
247
+ 3,
248
+ 4,
249
+ 5
250
+ ]);
251
+ return [
252
+ 4,
253
+ dbxCli.createCli(input).exitProcess(false).parse(_to_consumable_array(args), function(err, argv, output) {
254
+ capturedArgv = argv;
255
+ if (err) capturedError = err;
256
+ helpOutput = output;
257
+ })
258
+ ];
259
+ case 2:
260
+ _state.sent();
261
+ return [
262
+ 3,
263
+ 5
264
+ ];
265
+ case 3:
266
+ e = _state.sent();
267
+ if (e !== exitSentinel) {
268
+ capturedError = _instanceof(e, Error) ? e : new Error(String(e));
269
+ }
270
+ return [
271
+ 3,
272
+ 5
273
+ ];
274
+ case 4:
275
+ writeSpy.mockRestore();
276
+ errSpy.mockRestore();
277
+ logSpy.mockRestore();
278
+ errLogSpy.mockRestore();
279
+ exitSpy.mockRestore();
280
+ return [
281
+ 7
282
+ ];
283
+ case 5:
284
+ result = {
285
+ stdout: stdoutChunks,
286
+ stderr: stderrChunks,
287
+ stdoutText: stdoutChunks.join(''),
288
+ stderrText: stderrChunks.join(''),
289
+ argv: capturedArgv,
290
+ helpOutput: helpOutput,
291
+ error: capturedError,
292
+ exitCode: capturedExitCode
293
+ };
294
+ return [
295
+ 2,
296
+ result
297
+ ];
298
+ }
299
+ });
300
+ })();
301
+ }
302
+ /**
303
+ * Idempotently binds the fixture's NestJS application to `127.0.0.1:0` (or the supplied host) and
304
+ * returns the live `apiBaseUrl` so the CLI's `fetch` calls have a real socket to hit.
305
+ *
306
+ * Safe to call multiple times against the same app — when `app.getHttpServer().listening` is true,
307
+ * skips re-binding and just resolves the current address.
308
+ *
309
+ * The caller does NOT need to `.close()` explicitly: the demoApi/firebase-admin-nest fixture closes
310
+ * the underlying NestJS app at the end of its describe block, which closes the HTTP listener.
311
+ *
312
+ * @param input - The fixture app + optional global route prefix (defaults to `'api'` to match
313
+ * demo-api's production prefix) and host (defaults to `127.0.0.1`).
314
+ * @returns The bound `apiBaseUrl` (e.g. `http://127.0.0.1:54321/api`) and the resolved port.
315
+ */ function listenOnNestAppForTest(input) {
316
+ return _async_to_generator(function() {
317
+ var _input_host, _input_apiPrefix, host, prefix, server, address, port, trimmedPrefix, apiBaseUrl;
318
+ return _ts_generator(this, function(_state) {
319
+ switch(_state.label){
320
+ case 0:
321
+ host = (_input_host = input.host) !== null && _input_host !== void 0 ? _input_host : '127.0.0.1';
322
+ prefix = (_input_apiPrefix = input.apiPrefix) !== null && _input_apiPrefix !== void 0 ? _input_apiPrefix : 'api';
323
+ server = input.app.getHttpServer();
324
+ if (!!server.listening) return [
325
+ 3,
326
+ 2
327
+ ];
328
+ return [
329
+ 4,
330
+ input.app.listen(0, host)
331
+ ];
332
+ case 1:
333
+ _state.sent();
334
+ _state.label = 2;
335
+ case 2:
336
+ address = server.address();
337
+ port = (typeof address === "undefined" ? "undefined" : _type_of(address)) === 'object' && address ? address.port : 0;
338
+ trimmedPrefix = prefix.replace(/^\/+|\/+$/g, '');
339
+ apiBaseUrl = trimmedPrefix.length > 0 ? "http://".concat(host, ":").concat(port, "/").concat(trimmedPrefix) : "http://".concat(host, ":").concat(port);
340
+ return [
341
+ 2,
342
+ {
343
+ apiBaseUrl: apiBaseUrl,
344
+ port: port
345
+ }
346
+ ];
347
+ }
348
+ });
349
+ })();
350
+ }
351
+ function toChunkString(chunk) {
352
+ var result;
353
+ if (typeof chunk === 'string') {
354
+ result = chunk;
355
+ } else if (_instanceof(chunk, Uint8Array)) {
356
+ result = Buffer.from(chunk).toString('utf8');
357
+ } else {
358
+ result = String(chunk);
359
+ }
360
+ return result;
361
+ }
362
+ function stringifyConsolePart(part) {
363
+ var result;
364
+ if (typeof part === 'string') {
365
+ result = part;
366
+ } else if (_instanceof(part, Error)) {
367
+ var _part_stack;
368
+ result = (_part_stack = part.stack) !== null && _part_stack !== void 0 ? _part_stack : part.message;
369
+ } else {
370
+ try {
371
+ result = JSON.stringify(part);
372
+ } catch (unused) {
373
+ result = String(part);
374
+ }
375
+ }
376
+ return result;
377
+ }
378
+
379
+ exports.buildTestCliContext = buildTestCliContext;
380
+ exports.listenOnNestAppForTest = listenOnNestAppForTest;
381
+ exports.runCliCommand = runCliCommand;
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
@@ -0,0 +1 @@
1
+ export * from "./src/index";