@reliverse/rempts 1.7.29 → 1.7.30
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 +92 -29
- package/bin/{components/animate/animate.js → libs/animate/animate-mod.js} +1 -4
- package/bin/{components → libs}/anykey/anykey-mod.js +2 -2
- package/bin/libs/confirm/confirm-alias.d.ts +1 -0
- package/bin/libs/confirm/confirm-alias.js +2 -0
- package/bin/{components/confirm/confirm-prompt.js → libs/confirm/confirm-mod.js} +1 -1
- package/bin/{components → libs}/editor/editor-mod.js +8 -8
- package/bin/{components → libs}/figures/figures-mod.d.ts +2 -3
- package/bin/{components → libs}/figures/figures-mod.js +1 -2
- package/bin/libs/input/input-alias.d.ts +4 -0
- package/bin/libs/input/input-alias.js +4 -0
- package/bin/{components/input/input-prompt.js → libs/input/input-mod.js} +2 -2
- package/bin/libs/intro/intro-alias.d.ts +2 -0
- package/bin/libs/intro/intro-alias.js +3 -0
- package/bin/{components/intro/intro-start.js → libs/intro/intro-mod.js} +3 -3
- package/bin/libs/launcher/launcher-alias.d.ts +2 -0
- package/bin/libs/launcher/launcher-alias.js +2 -0
- package/bin/{components → libs}/launcher/launcher-mod.d.ts +37 -5
- package/bin/{components → libs}/launcher/launcher-mod.js +326 -205
- package/bin/{components → libs}/launcher/launcher-types.d.ts +1 -1
- package/bin/libs/launcher/trpc-orpc-support/completions.d.ts +4 -0
- package/bin/libs/launcher/trpc-orpc-support/completions.js +45 -0
- package/bin/libs/launcher/trpc-orpc-support/errors.d.ts +11 -0
- package/bin/libs/launcher/trpc-orpc-support/errors.js +10 -0
- package/bin/libs/launcher/trpc-orpc-support/index.d.ts +34 -0
- package/bin/libs/launcher/trpc-orpc-support/index.js +641 -0
- package/bin/libs/launcher/trpc-orpc-support/json-schema.d.ts +17 -0
- package/bin/libs/launcher/trpc-orpc-support/json-schema.js +168 -0
- package/bin/libs/launcher/trpc-orpc-support/json.d.ts +44 -0
- package/bin/libs/launcher/trpc-orpc-support/json.js +41 -0
- package/bin/libs/launcher/trpc-orpc-support/logging.d.ts +11 -0
- package/bin/libs/launcher/trpc-orpc-support/logging.js +26 -0
- package/bin/libs/launcher/trpc-orpc-support/parse-procedure.d.ts +2 -0
- package/bin/libs/launcher/trpc-orpc-support/parse-procedure.js +486 -0
- package/bin/libs/launcher/trpc-orpc-support/prompts.d.ts +18 -0
- package/bin/libs/launcher/trpc-orpc-support/prompts.js +534 -0
- package/bin/libs/launcher/trpc-orpc-support/standard-schema/contract.d.ts +53 -0
- package/bin/libs/launcher/trpc-orpc-support/standard-schema/contract.js +0 -0
- package/bin/libs/launcher/trpc-orpc-support/standard-schema/errors.d.ts +9 -0
- package/bin/libs/launcher/trpc-orpc-support/standard-schema/errors.js +47 -0
- package/bin/libs/launcher/trpc-orpc-support/standard-schema/utils.d.ts +3 -0
- package/bin/libs/launcher/trpc-orpc-support/standard-schema/utils.js +6 -0
- package/bin/libs/launcher/trpc-orpc-support/trpc-compat.d.ts +71 -0
- package/bin/libs/launcher/trpc-orpc-support/trpc-compat.js +11 -0
- package/bin/libs/launcher/trpc-orpc-support/types.d.ts +276 -0
- package/bin/libs/launcher/trpc-orpc-support/types.js +0 -0
- package/bin/libs/launcher/trpc-orpc-support/util.d.ts +9 -0
- package/bin/libs/launcher/trpc-orpc-support/util.js +9 -0
- package/bin/{components → libs}/msg-fmt/logger.js +1 -1
- package/bin/libs/multiselect/multiselect-alias.d.ts +1 -0
- package/bin/libs/multiselect/multiselect-alias.js +2 -0
- package/bin/{components/select → libs/multiselect}/multiselect-prompt.js +1 -1
- package/bin/{components → libs}/number/number-mod.js +1 -4
- package/bin/libs/outro/outro-alias.d.ts +2 -0
- package/bin/libs/outro/outro-alias.js +3 -0
- package/bin/{components/outro/outro-end.js → libs/outro/outro-mod.js} +2 -2
- package/bin/libs/select/aliases-alias.d.ts +1 -0
- package/bin/libs/select/aliases-alias.js +2 -0
- package/bin/{components → libs}/select/select-prompt.js +2 -2
- package/bin/{components → libs}/select/toggle-prompt.js +1 -1
- package/bin/libs/spinner/spinner-alias.d.ts +1 -0
- package/bin/libs/spinner/spinner-alias.js +2 -0
- package/bin/{components → libs}/spinner/spinner-mod.js +3 -1
- package/bin/{components → libs}/task/task-spin.js +1 -1
- package/bin/{utils → libs/utils}/colorize.d.ts +1 -1
- package/bin/{utils → libs/utils}/prevent.d.ts +1 -1
- package/bin/{utils → libs/utils}/prevent.js +2 -2
- package/bin/{utils → libs/utils}/prompt-end.d.ts +1 -1
- package/bin/{utils → libs/utils}/prompt-end.js +2 -2
- package/bin/{utils → libs/utils}/stream-text.d.ts +1 -1
- package/bin/{utils → libs/utils}/stream-text.js +2 -2
- package/bin/mod.d.ts +66 -41
- package/bin/mod.js +102 -66
- package/package.json +16 -2
- package/bin/components/aliases/aliases-mod.d.ts +0 -11
- package/bin/components/aliases/aliases-mod.js +0 -16
- /package/bin/{components/animate/animate.d.ts → libs/animate/animate-mod.d.ts} +0 -0
- /package/bin/{components → libs}/anykey/anykey-mod.d.ts +0 -0
- /package/bin/{components → libs}/cancel/cancel.d.ts +0 -0
- /package/bin/{components → libs}/cancel/cancel.js +0 -0
- /package/bin/{components/confirm/confirm-prompt.d.ts → libs/confirm/confirm-mod.d.ts} +0 -0
- /package/bin/{components → libs}/date/date.d.ts +0 -0
- /package/bin/{components → libs}/date/date.js +0 -0
- /package/bin/{components → libs}/editor/editor-mod.d.ts +0 -0
- /package/bin/{components/input/input-prompt.d.ts → libs/input/input-mod.d.ts} +0 -0
- /package/bin/{components/intro/intro-start.d.ts → libs/intro/intro-mod.d.ts} +0 -0
- /package/bin/{components → libs}/launcher/launcher-types.js +0 -0
- /package/bin/{components → libs}/launcher/run-command.d.ts +0 -0
- /package/bin/{components → libs}/launcher/run-command.js +0 -0
- /package/bin/{components/log/log.d.ts → libs/log/log-alias.d.ts} +0 -0
- /package/bin/{components/log/log.js → libs/log/log-alias.js} +0 -0
- /package/bin/{components → libs}/msg-fmt/colors.d.ts +0 -0
- /package/bin/{components → libs}/msg-fmt/colors.js +0 -0
- /package/bin/{components → libs}/msg-fmt/logger.d.ts +0 -0
- /package/bin/{components → libs}/msg-fmt/mapping.d.ts +0 -0
- /package/bin/{components → libs}/msg-fmt/mapping.js +0 -0
- /package/bin/{components → libs}/msg-fmt/messages.d.ts +0 -0
- /package/bin/{components → libs}/msg-fmt/messages.js +0 -0
- /package/bin/{components → libs}/msg-fmt/terminal.d.ts +0 -0
- /package/bin/{components → libs}/msg-fmt/terminal.js +0 -0
- /package/bin/{components → libs}/msg-fmt/variants.d.ts +0 -0
- /package/bin/{components → libs}/msg-fmt/variants.js +0 -0
- /package/bin/{components/select → libs/multiselect}/multiselect-prompt.d.ts +0 -0
- /package/bin/{components → libs}/next-steps/next-steps.d.ts +0 -0
- /package/bin/{components → libs}/next-steps/next-steps.js +0 -0
- /package/bin/{components → libs}/number/number-mod.d.ts +0 -0
- /package/bin/{components/outro/outro-end.d.ts → libs/outro/outro-mod.d.ts} +0 -0
- /package/bin/{components → libs}/results/results.d.ts +0 -0
- /package/bin/{components → libs}/results/results.js +0 -0
- /package/bin/{components → libs}/select/nummultiselect-prompt.d.ts +0 -0
- /package/bin/{components → libs}/select/nummultiselect-prompt.js +0 -0
- /package/bin/{components → libs}/select/numselect-prompt.d.ts +0 -0
- /package/bin/{components → libs}/select/numselect-prompt.js +0 -0
- /package/bin/{components → libs}/select/select-prompt.d.ts +0 -0
- /package/bin/{components → libs}/select/toggle-prompt.d.ts +0 -0
- /package/bin/{components → libs}/spinner/spinner-mod.d.ts +0 -0
- /package/bin/{components → libs}/task/progress.d.ts +0 -0
- /package/bin/{components → libs}/task/progress.js +0 -0
- /package/bin/{components → libs}/task/task-spin.d.ts +0 -0
- /package/bin/{utils → libs/utils}/colorize.js +0 -0
- /package/bin/{utils → libs/utils}/errors.d.ts +0 -0
- /package/bin/{utils → libs/utils}/errors.js +0 -0
- /package/bin/{utils → libs/utils}/system.d.ts +0 -0
- /package/bin/{utils → libs/utils}/system.js +0 -0
- /package/bin/{utils → libs/utils}/validate.d.ts +0 -0
- /package/bin/{utils → libs/utils}/validate.js +0 -0
- /package/bin/{components/ascii-art/ascii-art.d.ts → libs/visual/visual-mod.d.ts} +0 -0
- /package/bin/{components/ascii-art/ascii-art.js → libs/visual/visual-mod.js} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "./standard-schema/contract";
|
|
2
|
+
/**
|
|
3
|
+
* Type which looks *enough* like a trpc v11(+?) router to infer its types correctly
|
|
4
|
+
* This is written from scratch to avoid any kind of dependency on @trpc/server v11+
|
|
5
|
+
*/
|
|
6
|
+
export interface Trpc11RouterLike {
|
|
7
|
+
_def: {
|
|
8
|
+
_config: {
|
|
9
|
+
$types: {
|
|
10
|
+
meta: any;
|
|
11
|
+
ctx: any;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
procedures: Record<string, Trpc11ProcedureLike | Trpc11ProcedureRecordLike | Record<string, Trpc11ProcedureLike>>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Even though you use `t.router({})` to create a sub-router, the actual type is a record of procedures and sub-routers rather than a root-level router */
|
|
18
|
+
export interface Trpc11ProcedureRecordLike {
|
|
19
|
+
[key: string]: Trpc11ProcedureLike | Trpc11ProcedureRecordLike;
|
|
20
|
+
}
|
|
21
|
+
export interface Trpc11ProcedureLike {
|
|
22
|
+
_def: {
|
|
23
|
+
type: "mutation" | "query" | "subscription";
|
|
24
|
+
_type?: undefined;
|
|
25
|
+
meta?: any;
|
|
26
|
+
inputs?: unknown[];
|
|
27
|
+
$types: {
|
|
28
|
+
input: any;
|
|
29
|
+
output: any;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface Trpc10RouterLike {
|
|
34
|
+
_def: {
|
|
35
|
+
_config: {
|
|
36
|
+
$types: {
|
|
37
|
+
meta: any;
|
|
38
|
+
ctx: any;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
procedures: Record<string, Trpc10ProcedureLike | Trpc10RouterLike>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface Trpc10ProcedureLike {
|
|
45
|
+
_def: {
|
|
46
|
+
type?: undefined;
|
|
47
|
+
mutation?: boolean;
|
|
48
|
+
query?: boolean;
|
|
49
|
+
subscription?: boolean;
|
|
50
|
+
meta?: any;
|
|
51
|
+
inputs: unknown[];
|
|
52
|
+
_input_in: any;
|
|
53
|
+
_output_out: any;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface OrpcProcedureLike<Ctx> {
|
|
57
|
+
"~orpc": {
|
|
58
|
+
__initialContext?: (context: Ctx) => unknown;
|
|
59
|
+
inputSchema?: StandardSchemaV1;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface OrpcRouterLike<Ctx> {
|
|
63
|
+
[key: string]: OrpcProcedureLike<Ctx> | OrpcRouterLike<Ctx>;
|
|
64
|
+
}
|
|
65
|
+
export type CreateCallerFactoryLike<Procedures = Record<string, (input: unknown) => unknown>> = (router: any) => (context: any) => Procedures;
|
|
66
|
+
export type AnyRouter = Trpc10RouterLike | Trpc11RouterLike | OrpcRouterLike<any>;
|
|
67
|
+
export type AnyProcedure = Trpc10ProcedureLike | Trpc11ProcedureLike;
|
|
68
|
+
export type inferRouterContext<R extends AnyRouter> = R extends Trpc10RouterLike | Trpc11RouterLike ? R["_def"]["_config"]["$types"]["ctx"] : R extends OrpcRouterLike<infer Ctx> ? Ctx : never;
|
|
69
|
+
export declare const isTrpc11Procedure: (procedure: AnyProcedure) => procedure is Trpc11ProcedureLike;
|
|
70
|
+
export declare const isTrpc11Router: (router: AnyRouter) => router is Trpc11RouterLike;
|
|
71
|
+
export declare const isOrpcRouter: (router: AnyRouter) => router is OrpcRouterLike<any>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const isTrpc11Procedure = (procedure) => {
|
|
2
|
+
return "type" in procedure._def && typeof procedure._def.type === "string";
|
|
3
|
+
};
|
|
4
|
+
export const isTrpc11Router = (router) => {
|
|
5
|
+
if (isOrpcRouter(router)) return false;
|
|
6
|
+
const procedure = Object.values(router._def.procedures)[0];
|
|
7
|
+
return Boolean(procedure && isTrpc11Procedure(procedure));
|
|
8
|
+
};
|
|
9
|
+
export const isOrpcRouter = (router) => {
|
|
10
|
+
return !("_def" in router) || router._def && "~orpc" in router._def;
|
|
11
|
+
};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
import type { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
|
+
import type { CommandJSON } from "./json";
|
|
4
|
+
import type { AnyRouter, CreateCallerFactoryLike, inferRouterContext } from "./trpc-compat";
|
|
5
|
+
export interface TrpcCliParams<R extends AnyRouter> extends Dependencies {
|
|
6
|
+
/** A tRPC router. Procedures will become CLI commands. */
|
|
7
|
+
router: R;
|
|
8
|
+
name?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
usage?: string | string[];
|
|
12
|
+
/** Context to be supplied when invoking the router. */
|
|
13
|
+
context?: inferRouterContext<R>;
|
|
14
|
+
/** @deprecated this is actually **removed** not deprecated; use `aliases` on each procedure `meta` instead */
|
|
15
|
+
alias?: never;
|
|
16
|
+
/** @deprecated this is actually **removed** not deprecated; set `default: true` on the procedure `meta` instead */
|
|
17
|
+
_default?: never;
|
|
18
|
+
/** The `@trpc/server` module to use for calling procedures. Required when using trpc v10. */
|
|
19
|
+
trpcServer?: TrpcServerModuleLike | Promise<TrpcServerModuleLike>;
|
|
20
|
+
}
|
|
21
|
+
/** Rough shape of the `@trpc/server` (v10) module. Needed to pass in to `createRpcCli` when using trpc v10. */
|
|
22
|
+
export interface TrpcServerModuleLike {
|
|
23
|
+
initTRPC: {
|
|
24
|
+
create: () => {
|
|
25
|
+
createCallerFactory: CreateCallerFactoryLike<{}>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Optional interface for describing procedures via meta - if your router conforms to this meta shape, it will contribute to the CLI help text.
|
|
31
|
+
*/
|
|
32
|
+
export interface TrpcCliMeta {
|
|
33
|
+
/** Version of the script displayed in `--help` output. Use to avoid enabling `--version` option. */
|
|
34
|
+
version?: string;
|
|
35
|
+
/** Description of the script or command to display in `--help` output. */
|
|
36
|
+
description?: string;
|
|
37
|
+
/** Usage code examples to display in `--help` output. */
|
|
38
|
+
usage?: false | string | string[];
|
|
39
|
+
/** Example code snippets to display in `--help` output. */
|
|
40
|
+
examples?: string | string[];
|
|
41
|
+
/** If true, this command will be run if no command is specified. */
|
|
42
|
+
default?: boolean;
|
|
43
|
+
aliases?: {
|
|
44
|
+
/** Aliases for the command. Note: take care to avoid conflicts with other commands. */
|
|
45
|
+
command?: string[];
|
|
46
|
+
/** Aliases for the options. Note: take care to avoid conflicts with other options. An error will be thrown if an alias is defined for a non-existent option. */
|
|
47
|
+
options?: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
/** If true, will use a single CLI option expect the entire input to be parsed in as JSON, e.g. `--input '{"foo": "bar"}`. Can be useful to opt out of the default mapping of input schemas to CLI options. */
|
|
50
|
+
jsonInput?: boolean;
|
|
51
|
+
/** Sub-property for the CLI meta. If present, will take precedence over the top-level meta, to avoid conflicts with other tools. */
|
|
52
|
+
cliMeta?: TrpcCliMeta;
|
|
53
|
+
}
|
|
54
|
+
export interface ParsedProcedure {
|
|
55
|
+
positionalParameters: {
|
|
56
|
+
name: string;
|
|
57
|
+
description: string;
|
|
58
|
+
type: "string" | "number" | "boolean" | (string & {});
|
|
59
|
+
required: boolean;
|
|
60
|
+
array: boolean;
|
|
61
|
+
}[];
|
|
62
|
+
/** JSON Schema type describing the flags for the procedure */
|
|
63
|
+
optionsJsonSchema: JsonSchema7Type;
|
|
64
|
+
/**
|
|
65
|
+
* Function for taking parsed argv output and transforming it so it can be passed into the procedure.
|
|
66
|
+
* Needed because this function is where inspect the input schema(s) and determine how to map the argv to the input
|
|
67
|
+
*/
|
|
68
|
+
getPojoInput: (argv: {
|
|
69
|
+
positionalValues: (string | string[])[];
|
|
70
|
+
options: Record<string, unknown>;
|
|
71
|
+
}) => unknown;
|
|
72
|
+
}
|
|
73
|
+
export type Result<T> = {
|
|
74
|
+
success: true;
|
|
75
|
+
value: T;
|
|
76
|
+
} | {
|
|
77
|
+
success: false;
|
|
78
|
+
error: string;
|
|
79
|
+
};
|
|
80
|
+
/** A function that logs any inputs. e.g. `console.info` */
|
|
81
|
+
export type Log = (...args: unknown[]) => void;
|
|
82
|
+
/**
|
|
83
|
+
* A struct which has `info` and `error` functions for logging. Easiest example: `console`
|
|
84
|
+
* But most loggers like pino, winston etc. have a similar interface.
|
|
85
|
+
*/
|
|
86
|
+
export interface Logger {
|
|
87
|
+
info?: Log;
|
|
88
|
+
error?: Log;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Slim reconstruction of an `omelette` instance. Hand-written here to avoid a hard dependency on `omelette` or its types.
|
|
92
|
+
* Usually you will just pass in an `omelette` instance by doing something like
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* import omelette from 'omelette'
|
|
96
|
+
* import {createRpcCli} from '@reliverse/rempts'
|
|
97
|
+
*
|
|
98
|
+
* const cli = createRpcCli({
|
|
99
|
+
* router: myRouter,
|
|
100
|
+
* completion: omelette('myprogram'),
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* Or it also accepts an async function that resolves to an `omelette` instance, so you can use dynamic import:
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* import {createRpcCli} from '@reliverse/rempts'
|
|
108
|
+
*
|
|
109
|
+
* const cli = await createRpcCli({
|
|
110
|
+
* router: myRouter,
|
|
111
|
+
* completion: () => import('omelette').then(omelette => omelette.default('myprogram')),
|
|
112
|
+
* })
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export interface OmeletteInstanceLike {
|
|
116
|
+
on: (event: "complete", callback: (fragment: string, params: {
|
|
117
|
+
line: string;
|
|
118
|
+
fragment: number;
|
|
119
|
+
reply: (suggestions: string[]) => void;
|
|
120
|
+
}) => void) => void;
|
|
121
|
+
init: () => void;
|
|
122
|
+
setupShellInitFile: () => void;
|
|
123
|
+
cleanupShellInitFile: () => void;
|
|
124
|
+
tree: (value: any) => this;
|
|
125
|
+
}
|
|
126
|
+
export interface InquirerPromptOptions {
|
|
127
|
+
message: string;
|
|
128
|
+
required?: boolean;
|
|
129
|
+
validate?: (input: string) => boolean | string;
|
|
130
|
+
default?: any;
|
|
131
|
+
}
|
|
132
|
+
/** looks like the `@inquirer/prompts` package */
|
|
133
|
+
export interface InquirerPromptsLike {
|
|
134
|
+
input: (params: InquirerPromptOptions) => Promise<string>;
|
|
135
|
+
confirm: (params: InquirerPromptOptions) => Promise<boolean>;
|
|
136
|
+
}
|
|
137
|
+
/** looks like the `prompts` package */
|
|
138
|
+
export interface PromptsLike {
|
|
139
|
+
prompt: Function;
|
|
140
|
+
inject: Function;
|
|
141
|
+
}
|
|
142
|
+
/** looks like the `enquirer` package */
|
|
143
|
+
export interface EnquirerLike {
|
|
144
|
+
prompt: <T>(params: {
|
|
145
|
+
type: "input";
|
|
146
|
+
name: string;
|
|
147
|
+
message: string;
|
|
148
|
+
validate?: (input: string) => boolean | string;
|
|
149
|
+
initial?: unknown;
|
|
150
|
+
}) => Promise<T>;
|
|
151
|
+
}
|
|
152
|
+
export interface ClackPromptsLike {
|
|
153
|
+
intro: (title: string) => void;
|
|
154
|
+
outro: (title: string) => void;
|
|
155
|
+
}
|
|
156
|
+
export type Promptable = InquirerPromptsLike | EnquirerLike | PromptsLike | Prompter | ClackPromptsLike | ((command: CommanderProgramLike) => Prompter);
|
|
157
|
+
export interface TrpcCliRunParams {
|
|
158
|
+
argv?: string[];
|
|
159
|
+
logger?: Logger;
|
|
160
|
+
completion?: OmeletteInstanceLike | (() => Promise<OmeletteInstanceLike>);
|
|
161
|
+
prompts?: Promptable;
|
|
162
|
+
/** Format an error thrown by the root procedure before logging to `logger.error` */
|
|
163
|
+
formatError?: (error: unknown) => string;
|
|
164
|
+
process?: {
|
|
165
|
+
exit: (code: number) => never;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Type that looks like a `commander` Command instance, but doesn't require a dependency on `commander` to avoid awkward typescript errors.
|
|
170
|
+
* If you need to use it as a `Command` instance, just cast it with `as` to `import('commander').Command`.
|
|
171
|
+
*/
|
|
172
|
+
export interface CommanderProgramLike {
|
|
173
|
+
name: () => string;
|
|
174
|
+
parseAsync: (args: string[], options?: {
|
|
175
|
+
from: "user" | "node" | "electron";
|
|
176
|
+
}) => Promise<unknown>;
|
|
177
|
+
helpInformation: () => string;
|
|
178
|
+
}
|
|
179
|
+
export interface TrpcCli {
|
|
180
|
+
/** run the CLI - gets args from `process.argv` by default */
|
|
181
|
+
run: (params?: TrpcCliRunParams, program?: CommanderProgramLike) => Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Build a `Commander` program from the CLI - you can use this to manually customise the program before passing it to `.run(...)`.
|
|
184
|
+
* Note that you will need to cast the return value to `import('commander').Command` to use it as a `Command` instance.
|
|
185
|
+
*/
|
|
186
|
+
buildProgram: (params?: TrpcCliRunParams) => CommanderProgramLike;
|
|
187
|
+
/**
|
|
188
|
+
* @experimental
|
|
189
|
+
* Get a JSON representation of the CLI - useful for generating documentation etc. This function returns basic information about the CLI
|
|
190
|
+
* and each command - to get any extra details you will need to use the `buildProgram` function and walk the tree of commands yourself.
|
|
191
|
+
*/
|
|
192
|
+
toJSON: (program?: CommanderProgramLike) => CommandJSON;
|
|
193
|
+
}
|
|
194
|
+
export interface Dependencies {
|
|
195
|
+
"@valibot/to-json-schema"?: {
|
|
196
|
+
toJsonSchema: (input: unknown, options?: {
|
|
197
|
+
errorMode?: "throw" | "ignore" | "warn";
|
|
198
|
+
}) => JSONSchema7;
|
|
199
|
+
};
|
|
200
|
+
effect?: {
|
|
201
|
+
Schema: {
|
|
202
|
+
isSchema: (input: unknown) => input is "JSONSchemaMakeable";
|
|
203
|
+
};
|
|
204
|
+
JSONSchema: {
|
|
205
|
+
make: (input: "JSONSchemaMakeable") => JSONSchema7;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export interface PromptContext {
|
|
210
|
+
input?: NodeJS.ReadableStream;
|
|
211
|
+
output?: NodeJS.WritableStream;
|
|
212
|
+
clearPromptOnDone?: boolean;
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
/** The command that is being prompted for. Cast this to a `commander.Command` to access the command's name, description, options etc. */
|
|
215
|
+
command: {
|
|
216
|
+
name: () => string;
|
|
217
|
+
};
|
|
218
|
+
/** The original inputs the user provided - if they passed some but not all arguments/options, this will contain the values they did pass. */
|
|
219
|
+
inputs: {
|
|
220
|
+
argv: string[];
|
|
221
|
+
arguments: {
|
|
222
|
+
name: string;
|
|
223
|
+
specified: boolean;
|
|
224
|
+
value: unknown;
|
|
225
|
+
}[];
|
|
226
|
+
options: {
|
|
227
|
+
name: string;
|
|
228
|
+
specified: boolean;
|
|
229
|
+
value: unknown;
|
|
230
|
+
}[];
|
|
231
|
+
};
|
|
232
|
+
/** If set, this is the argument that is being prompted for. Cast to a `commander.Argument`. */
|
|
233
|
+
argument?: {
|
|
234
|
+
name: () => string;
|
|
235
|
+
};
|
|
236
|
+
/** If set, this is the option that is being prompted for. Cast to a `commander.Option`. */
|
|
237
|
+
option?: {
|
|
238
|
+
name: () => string;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
export interface Prompter {
|
|
242
|
+
setup?: (context: PromptContext) => Promise<void>;
|
|
243
|
+
teardown?: (context: PromptContext) => Promise<void>;
|
|
244
|
+
input: (params: {
|
|
245
|
+
message: string;
|
|
246
|
+
validate?: (input: string) => boolean | string;
|
|
247
|
+
required?: boolean;
|
|
248
|
+
default?: string;
|
|
249
|
+
}, context: PromptContext) => Promise<string>;
|
|
250
|
+
select: (params: {
|
|
251
|
+
message: string;
|
|
252
|
+
choices: string[] | {
|
|
253
|
+
name: string;
|
|
254
|
+
value: string;
|
|
255
|
+
description?: string;
|
|
256
|
+
}[];
|
|
257
|
+
required?: boolean;
|
|
258
|
+
default?: string;
|
|
259
|
+
validate?: (input: string) => boolean | string;
|
|
260
|
+
}, context: PromptContext) => Promise<string>;
|
|
261
|
+
confirm: (params: {
|
|
262
|
+
message: string;
|
|
263
|
+
default?: boolean;
|
|
264
|
+
validate?: (input: string) => boolean | string;
|
|
265
|
+
}, context: PromptContext) => Promise<boolean>;
|
|
266
|
+
checkbox: (params: {
|
|
267
|
+
message: string;
|
|
268
|
+
choices: {
|
|
269
|
+
name: string;
|
|
270
|
+
value: string;
|
|
271
|
+
checked?: boolean;
|
|
272
|
+
}[];
|
|
273
|
+
required?: boolean;
|
|
274
|
+
default?: string[];
|
|
275
|
+
}, context: PromptContext) => Promise<string[]>;
|
|
276
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pretty much like the `instanceof` operator, but should work across different realms. Necessary for zod because some installations
|
|
3
|
+
* might result in this library using the commonjs zod export, while the user's code uses the esm export.
|
|
4
|
+
* https://github.com/mmkal/trpc-cli/issues/7
|
|
5
|
+
*
|
|
6
|
+
* Tradeoff: It's possible that this function will return false positives if the target class has the same name as an unrelated class in the current realm.
|
|
7
|
+
* So, only use it for classes that are unlikely to have name conflicts like `ZodAbc` or `TRPCDef`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const looksLikeInstanceof: <T>(value: unknown, target: string | (new (...args: any[]) => T)) => value is T;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const looksLikeInstanceof = (value, target) => {
|
|
2
|
+
let current = value?.constructor;
|
|
3
|
+
while (current?.name) {
|
|
4
|
+
if (current?.name === (typeof target === "string" ? target : target.name))
|
|
5
|
+
return true;
|
|
6
|
+
current = Object.getPrototypeOf(current);
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { streamText, streamTextWithSpinner } from "
|
|
1
|
+
import { streamText, streamTextWithSpinner } from "../utils/stream-text.js";
|
|
2
2
|
import { toSolidColor } from "./colors.js";
|
|
3
3
|
import { msg } from "./messages.js";
|
|
4
4
|
const verboseLogging = false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const multiselect: any;
|
|
@@ -4,7 +4,7 @@ import { stdin as input, stdout as output } from "node:process";
|
|
|
4
4
|
import readline from "node:readline";
|
|
5
5
|
import { msg, symbols } from "../msg-fmt/messages.js";
|
|
6
6
|
import { deleteLastLine } from "../msg-fmt/terminal.js";
|
|
7
|
-
import { completePrompt } from "
|
|
7
|
+
import { completePrompt } from "../utils/prompt-end.js";
|
|
8
8
|
function isSelectOption(option) {
|
|
9
9
|
return !("separator" in option);
|
|
10
10
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { stdin as input, stdout as output } from "node:process";
|
|
2
2
|
import readline from "node:readline/promises";
|
|
3
3
|
import { bar, msg } from "../msg-fmt/messages.js";
|
|
4
|
-
import {
|
|
5
|
-
deleteLastLine,
|
|
6
|
-
deleteLastLines
|
|
7
|
-
} from "../msg-fmt/terminal.js";
|
|
4
|
+
import { deleteLastLine, deleteLastLines } from "../msg-fmt/terminal.js";
|
|
8
5
|
function renderPromptUI(params) {
|
|
9
6
|
const {
|
|
10
7
|
title,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { animateText } from "../animate/animate.js";
|
|
2
|
-
import { createAsciiArt } from "../ascii-art/ascii-art.js";
|
|
1
|
+
import { animateText } from "../animate/animate-mod.js";
|
|
3
2
|
import { msg } from "../msg-fmt/messages.js";
|
|
4
3
|
import { getExactTerminalWidth } from "../msg-fmt/terminal.js";
|
|
4
|
+
import { createAsciiArt } from "../visual/visual-mod.js";
|
|
5
5
|
export async function outroPrompt(optionsOrTitle) {
|
|
6
6
|
const options = typeof optionsOrTitle === "string" ? { title: optionsOrTitle } : optionsOrTitle;
|
|
7
7
|
const {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const select: any;
|
|
@@ -4,8 +4,8 @@ import { stdin as input, stdout as output } from "node:process";
|
|
|
4
4
|
import readline from "node:readline";
|
|
5
5
|
import { msg, symbols } from "../msg-fmt/messages.js";
|
|
6
6
|
import { deleteLastLine } from "../msg-fmt/terminal.js";
|
|
7
|
-
import { completePrompt } from "
|
|
8
|
-
import { streamText } from "
|
|
7
|
+
import { completePrompt } from "../utils/prompt-end.js";
|
|
8
|
+
import { streamText } from "../utils/stream-text.js";
|
|
9
9
|
function isSelectOption(option) {
|
|
10
10
|
return !("separator" in option);
|
|
11
11
|
}
|
|
@@ -4,7 +4,7 @@ import { stdin as input, stdout as output } from "node:process";
|
|
|
4
4
|
import readline from "node:readline";
|
|
5
5
|
import { msg } from "../msg-fmt/messages.js";
|
|
6
6
|
import { deleteLastLine } from "../msg-fmt/terminal.js";
|
|
7
|
-
import { completePrompt } from "
|
|
7
|
+
import { completePrompt } from "../utils/prompt-end.js";
|
|
8
8
|
function renderTogglePrompt(params) {
|
|
9
9
|
const {
|
|
10
10
|
title,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const spinner: any;
|
|
@@ -109,7 +109,9 @@ export function useSpinner(options) {
|
|
|
109
109
|
}
|
|
110
110
|
clearPrevMessage();
|
|
111
111
|
state.prevMessage = state.text;
|
|
112
|
-
const frame = re.magenta(
|
|
112
|
+
const frame = re.magenta(
|
|
113
|
+
(options.frames ?? defaultFrames)[frameIndex] ?? ""
|
|
114
|
+
);
|
|
113
115
|
if (process.env.CI) {
|
|
114
116
|
process.stdout.write(`${frame} ${state.text}...`);
|
|
115
117
|
} else if (options.indicator === "timer") {
|
|
@@ -65,7 +65,7 @@ export async function taskSpinPrompt(options) {
|
|
|
65
65
|
process.stdin.on("data", handleInput);
|
|
66
66
|
}
|
|
67
67
|
interval = setInterval(() => {
|
|
68
|
-
const frame = re.magenta(frames[frameIndex]);
|
|
68
|
+
const frame = re.magenta(frames[frameIndex] ?? "");
|
|
69
69
|
process.stdout.write(
|
|
70
70
|
`${cursor.move(-999, 0)}${erase.line}${frame} ${re.cyan(message)}`
|
|
71
71
|
);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ColorName, TypographyName } from "
|
|
1
|
+
import type { ColorName, TypographyName } from "../../types.js";
|
|
2
2
|
export declare function colorize(text: string, colorName?: ColorName, typography?: TypographyName): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PreventWrongTerminalSizeOptions } from "
|
|
1
|
+
import type { PreventWrongTerminalSizeOptions } from "../../types.js";
|
|
2
2
|
export declare function preventUnsupportedTTY(): void;
|
|
3
3
|
/**
|
|
4
4
|
* Prevents EISDIR errors when trying to read Windows home directory as a file
|
|
@@ -2,11 +2,11 @@ import { re } from "@reliverse/relico";
|
|
|
2
2
|
import { relinka } from "@reliverse/relinka";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import terminalSize from "terminal-size";
|
|
5
|
-
import { msg } from "../
|
|
5
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
6
6
|
import {
|
|
7
7
|
getExactTerminalWidth,
|
|
8
8
|
getTerminalWidth
|
|
9
|
-
} from "../
|
|
9
|
+
} from "../msg-fmt/terminal.js";
|
|
10
10
|
export function preventUnsupportedTTY() {
|
|
11
11
|
if (!process.stdout.isTTY) {
|
|
12
12
|
relinka(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BorderColorName, ColorName, TypographyName, VariantName } from "
|
|
1
|
+
import type { BorderColorName, ColorName, TypographyName, VariantName } from "../../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Ends the prompt by optionally displaying an end message and running the action if confirmed.
|
|
4
4
|
* Preserves the last prompt state unless there's an endTitle.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { re } from "@reliverse/relico";
|
|
2
2
|
import { relinka } from "@reliverse/relinka";
|
|
3
|
-
import { msg, symbols } from "../
|
|
4
|
-
import { getExactTerminalWidth } from "../
|
|
3
|
+
import { msg, symbols } from "../msg-fmt/messages.js";
|
|
4
|
+
import { getExactTerminalWidth } from "../msg-fmt/terminal.js";
|
|
5
5
|
export async function completePrompt(prompt, isCtrlC, _endTitle = "", _endTitleColor = "dim", _titleTypography = "none", _titleVariant = void 0, _border = true, borderColor = "dim", action, value) {
|
|
6
6
|
if (action && value) {
|
|
7
7
|
await action();
|
|
@@ -4,8 +4,8 @@ import ora from "ora";
|
|
|
4
4
|
import { cursor } from "sisteransi";
|
|
5
5
|
import terminalSize from "terminal-size";
|
|
6
6
|
import wrapAnsi from "wrap-ansi";
|
|
7
|
-
import { toBaseColor } from "../
|
|
8
|
-
import { msg } from "../
|
|
7
|
+
import { toBaseColor } from "../msg-fmt/colors.js";
|
|
8
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
9
9
|
function getTerminalWidth() {
|
|
10
10
|
return terminalSize().columns;
|
|
11
11
|
}
|