@xyd-js/opencli 0.1.0-build.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/biome.json +25 -0
- package/dist/index.cjs +336 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +522 -0
- package/dist/index.d.ts +522 -0
- package/dist/index.js +291 -0
- package/dist/index.js.map +1 -0
- package/index.ts +1 -0
- package/opencli-spec.json +588 -0
- package/package.json +25 -0
- package/src/__tests__/opencli.test.ts +61 -0
- package/src/converters.test.ts +68 -0
- package/src/converters.ts +140 -0
- package/src/generate.ts +206 -0
- package/src/index.ts +20 -0
- package/src/spec.ts +106 -0
- package/src/types.ts +432 -0
- package/tsconfig.json +18 -0
- package/tsup.config.ts +19 -0
- package/vitest.config.ts +8 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The OpenCLI description
|
|
10
|
+
*/
|
|
11
|
+
export interface OpencliSpecJson {
|
|
12
|
+
/**
|
|
13
|
+
* The OpenCLI version number
|
|
14
|
+
*/
|
|
15
|
+
opencli: string;
|
|
16
|
+
info: CliInfo;
|
|
17
|
+
conventions?: Conventions;
|
|
18
|
+
/**
|
|
19
|
+
* Root command arguments
|
|
20
|
+
*/
|
|
21
|
+
arguments?: Argument[];
|
|
22
|
+
/**
|
|
23
|
+
* Root command options
|
|
24
|
+
*/
|
|
25
|
+
options?: Option[];
|
|
26
|
+
/**
|
|
27
|
+
* Root command sub commands
|
|
28
|
+
*/
|
|
29
|
+
commands?: Command[];
|
|
30
|
+
/**
|
|
31
|
+
* Root command exit codes
|
|
32
|
+
*/
|
|
33
|
+
exitCodes?: ExitCode[];
|
|
34
|
+
/**
|
|
35
|
+
* Examples of how to use the CLI
|
|
36
|
+
*/
|
|
37
|
+
examples?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Indicates whether or not the command requires interactive input
|
|
40
|
+
*/
|
|
41
|
+
interactive?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Custom metadata
|
|
44
|
+
*/
|
|
45
|
+
metadata?: Metadata[];
|
|
46
|
+
"x-openapi"?: XOpenApiRoot;
|
|
47
|
+
[k: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Information about the CLI
|
|
51
|
+
*/
|
|
52
|
+
export interface CliInfo {
|
|
53
|
+
/**
|
|
54
|
+
* The application title
|
|
55
|
+
*/
|
|
56
|
+
title: string;
|
|
57
|
+
/**
|
|
58
|
+
* A short summary of the application
|
|
59
|
+
*/
|
|
60
|
+
summary?: string;
|
|
61
|
+
/**
|
|
62
|
+
* A description of the application
|
|
63
|
+
*/
|
|
64
|
+
description?: string;
|
|
65
|
+
contact?: Contact;
|
|
66
|
+
license?: License;
|
|
67
|
+
/**
|
|
68
|
+
* The application version
|
|
69
|
+
*/
|
|
70
|
+
version: string;
|
|
71
|
+
[k: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The contact information
|
|
75
|
+
*/
|
|
76
|
+
export interface Contact {
|
|
77
|
+
/**
|
|
78
|
+
* The identifying name of the contact person/organization
|
|
79
|
+
*/
|
|
80
|
+
name?: string;
|
|
81
|
+
/**
|
|
82
|
+
* The URI for the contact information. This MUST be in the form of a URI.
|
|
83
|
+
*/
|
|
84
|
+
url?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The email address of the contact person/organization. This MUST be in the form of an email address.
|
|
87
|
+
*/
|
|
88
|
+
email?: string;
|
|
89
|
+
[k: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The application license
|
|
93
|
+
*/
|
|
94
|
+
export interface License {
|
|
95
|
+
/**
|
|
96
|
+
* The license name
|
|
97
|
+
*/
|
|
98
|
+
name?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The SPDX license identifier
|
|
101
|
+
*/
|
|
102
|
+
identifier?: string;
|
|
103
|
+
/**
|
|
104
|
+
* The URI for the license. This MUST be in the form of a URI
|
|
105
|
+
*/
|
|
106
|
+
url?: string;
|
|
107
|
+
[k: string]: unknown;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The conventions used by the CLI
|
|
111
|
+
*/
|
|
112
|
+
export interface Conventions {
|
|
113
|
+
/**
|
|
114
|
+
* Whether or not grouping of short options are allowed
|
|
115
|
+
*/
|
|
116
|
+
groupOptions?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* The option argument separator
|
|
119
|
+
*/
|
|
120
|
+
optionSeparator?: string;
|
|
121
|
+
[k: string]: unknown;
|
|
122
|
+
}
|
|
123
|
+
export interface Argument {
|
|
124
|
+
/**
|
|
125
|
+
* The argument name
|
|
126
|
+
*/
|
|
127
|
+
name: string;
|
|
128
|
+
/**
|
|
129
|
+
* Whether or not the argument is required
|
|
130
|
+
*/
|
|
131
|
+
required?: boolean;
|
|
132
|
+
arity?: Arity;
|
|
133
|
+
/**
|
|
134
|
+
* A list of accepted values
|
|
135
|
+
*/
|
|
136
|
+
acceptedValues?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* The argument group
|
|
139
|
+
*/
|
|
140
|
+
group?: string;
|
|
141
|
+
/**
|
|
142
|
+
* The argument description
|
|
143
|
+
*/
|
|
144
|
+
description?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Whether or not the argument is hidden
|
|
147
|
+
*/
|
|
148
|
+
hidden?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Custom metadata
|
|
151
|
+
*/
|
|
152
|
+
metadata?: Metadata[];
|
|
153
|
+
[k: string]: unknown;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The argument arity. Arity defines the minimum and maximum number of argument values
|
|
157
|
+
*/
|
|
158
|
+
export interface Arity {
|
|
159
|
+
/**
|
|
160
|
+
* The minimum number of values allowed
|
|
161
|
+
*/
|
|
162
|
+
minimum?: number;
|
|
163
|
+
/**
|
|
164
|
+
* The maximum number of values allowed
|
|
165
|
+
*/
|
|
166
|
+
maximum?: number;
|
|
167
|
+
[k: string]: unknown;
|
|
168
|
+
}
|
|
169
|
+
export interface Metadata {
|
|
170
|
+
name: string;
|
|
171
|
+
value?: unknown;
|
|
172
|
+
[k: string]: unknown;
|
|
173
|
+
}
|
|
174
|
+
export interface Option {
|
|
175
|
+
/**
|
|
176
|
+
* The option name
|
|
177
|
+
*/
|
|
178
|
+
name: string;
|
|
179
|
+
/**
|
|
180
|
+
* Whether or not the option is required
|
|
181
|
+
*/
|
|
182
|
+
required?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The option's aliases
|
|
185
|
+
*/
|
|
186
|
+
aliases?: string[];
|
|
187
|
+
/**
|
|
188
|
+
* The option's arguments
|
|
189
|
+
*/
|
|
190
|
+
arguments?: Argument[];
|
|
191
|
+
/**
|
|
192
|
+
* The option group
|
|
193
|
+
*/
|
|
194
|
+
group?: string;
|
|
195
|
+
/**
|
|
196
|
+
* The option description
|
|
197
|
+
*/
|
|
198
|
+
description?: string;
|
|
199
|
+
/**
|
|
200
|
+
* Specifies whether the option is accessible from the immediate parent command and, recursively, from its subcommands
|
|
201
|
+
*/
|
|
202
|
+
recursive?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Whether or not the option is hidden
|
|
205
|
+
*/
|
|
206
|
+
hidden?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Custom metadata
|
|
209
|
+
*/
|
|
210
|
+
metadata?: Metadata[];
|
|
211
|
+
[k: string]: unknown;
|
|
212
|
+
}
|
|
213
|
+
export interface Command {
|
|
214
|
+
/**
|
|
215
|
+
* The command name
|
|
216
|
+
*/
|
|
217
|
+
name: string;
|
|
218
|
+
/**
|
|
219
|
+
* The command aliases
|
|
220
|
+
*/
|
|
221
|
+
aliases?: string[];
|
|
222
|
+
/**
|
|
223
|
+
* The command options
|
|
224
|
+
*/
|
|
225
|
+
options?: Option[];
|
|
226
|
+
/**
|
|
227
|
+
* The command arguments
|
|
228
|
+
*/
|
|
229
|
+
arguments?: Argument[];
|
|
230
|
+
/**
|
|
231
|
+
* The command's sub commands
|
|
232
|
+
*/
|
|
233
|
+
commands?: Command[];
|
|
234
|
+
/**
|
|
235
|
+
* The command's exit codes
|
|
236
|
+
*/
|
|
237
|
+
exitCodes?: ExitCode[];
|
|
238
|
+
/**
|
|
239
|
+
* The command description
|
|
240
|
+
*/
|
|
241
|
+
description?: string;
|
|
242
|
+
/**
|
|
243
|
+
* Whether or not the command is hidden
|
|
244
|
+
*/
|
|
245
|
+
hidden?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Examples of how to use the command
|
|
248
|
+
*/
|
|
249
|
+
examples?: string[];
|
|
250
|
+
/**
|
|
251
|
+
* Indicate whether or not the command requires interactive input
|
|
252
|
+
*/
|
|
253
|
+
interactive?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Custom metadata
|
|
256
|
+
*/
|
|
257
|
+
metadata?: Metadata[];
|
|
258
|
+
"x-openapi"?: XOpenApiCommand;
|
|
259
|
+
[k: string]: unknown;
|
|
260
|
+
}
|
|
261
|
+
export interface ExitCode {
|
|
262
|
+
/**
|
|
263
|
+
* The exit code
|
|
264
|
+
*/
|
|
265
|
+
code: number;
|
|
266
|
+
/**
|
|
267
|
+
* The exit code description
|
|
268
|
+
*/
|
|
269
|
+
description?: string;
|
|
270
|
+
[k: string]: unknown;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* xyd extension: OpenAPI/HTTP binding for this command's operation (method, path, params, body). Consumed by the opencli2* code generators to build real API requests.
|
|
274
|
+
*/
|
|
275
|
+
export interface XOpenApiCommand {
|
|
276
|
+
/**
|
|
277
|
+
* The source OpenAPI operationId, when present
|
|
278
|
+
*/
|
|
279
|
+
operationId?: string;
|
|
280
|
+
/**
|
|
281
|
+
* HTTP method (lowercase)
|
|
282
|
+
*/
|
|
283
|
+
method: string;
|
|
284
|
+
/**
|
|
285
|
+
* HTTP path template (e.g. /chat/completions/{completion_id})
|
|
286
|
+
*/
|
|
287
|
+
path: string;
|
|
288
|
+
/**
|
|
289
|
+
* Override base URL for this operation, if any
|
|
290
|
+
*/
|
|
291
|
+
server?: string;
|
|
292
|
+
/**
|
|
293
|
+
* Request body content type
|
|
294
|
+
*/
|
|
295
|
+
contentType?: string;
|
|
296
|
+
/**
|
|
297
|
+
* Per-operation security requirements (overrides root)
|
|
298
|
+
*/
|
|
299
|
+
security?: XOpenApiSecurity[];
|
|
300
|
+
/**
|
|
301
|
+
* How CLI arguments/options map to HTTP parameters
|
|
302
|
+
*/
|
|
303
|
+
params?: XOpenApiParam[];
|
|
304
|
+
body?: XOpenApiBody;
|
|
305
|
+
[k: string]: unknown;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A single security scheme mapped from the OpenAPI securitySchemes.
|
|
309
|
+
*/
|
|
310
|
+
export interface XOpenApiSecurity {
|
|
311
|
+
/**
|
|
312
|
+
* Normalized scheme a generator branches on: bearer | apiKey-header | apiKey-query | apiKey-cookie | basic | other
|
|
313
|
+
*/
|
|
314
|
+
kind?: string;
|
|
315
|
+
/**
|
|
316
|
+
* The OpenAPI security scheme type (e.g. http, apiKey, oauth2)
|
|
317
|
+
*/
|
|
318
|
+
type: string;
|
|
319
|
+
/**
|
|
320
|
+
* The HTTP auth scheme (e.g. bearer, basic) when type is http
|
|
321
|
+
*/
|
|
322
|
+
scheme?: string;
|
|
323
|
+
/**
|
|
324
|
+
* Location for an apiKey scheme (header, query or cookie)
|
|
325
|
+
*/
|
|
326
|
+
in?: string;
|
|
327
|
+
/**
|
|
328
|
+
* Header/query/cookie name for an apiKey scheme
|
|
329
|
+
*/
|
|
330
|
+
name?: string;
|
|
331
|
+
/**
|
|
332
|
+
* The bearer token format hint (e.g. JWT)
|
|
333
|
+
*/
|
|
334
|
+
bearerFormat?: string;
|
|
335
|
+
/**
|
|
336
|
+
* Environment variable a generated CLI reads the credential from (e.g. OPENAI_API_KEY)
|
|
337
|
+
*/
|
|
338
|
+
envVar?: string;
|
|
339
|
+
[k: string]: unknown;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Maps one CLI argument/option onto an HTTP parameter.
|
|
343
|
+
*/
|
|
344
|
+
export interface XOpenApiParam {
|
|
345
|
+
/**
|
|
346
|
+
* Parameter location (path, query, header or cookie)
|
|
347
|
+
*/
|
|
348
|
+
in: string;
|
|
349
|
+
/**
|
|
350
|
+
* The wire name of the HTTP parameter
|
|
351
|
+
*/
|
|
352
|
+
name: string;
|
|
353
|
+
/**
|
|
354
|
+
* Source CLI token: 'argument:<name>' or 'option:<name>'
|
|
355
|
+
*/
|
|
356
|
+
from: string;
|
|
357
|
+
/**
|
|
358
|
+
* Whether the HTTP parameter is required
|
|
359
|
+
*/
|
|
360
|
+
required?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* OpenAPI explode flag for array/object serialization
|
|
363
|
+
*/
|
|
364
|
+
explode?: boolean;
|
|
365
|
+
/**
|
|
366
|
+
* OpenAPI serialization style
|
|
367
|
+
*/
|
|
368
|
+
style?: string;
|
|
369
|
+
[k: string]: unknown;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* How CLI options map to the request body
|
|
373
|
+
*/
|
|
374
|
+
export interface XOpenApiBody {
|
|
375
|
+
/**
|
|
376
|
+
* How the body is assembled: 'flatten' (per-property flags), 'json' (single JSON flag) or 'multipart'
|
|
377
|
+
*/
|
|
378
|
+
style: string;
|
|
379
|
+
/**
|
|
380
|
+
* Body content type
|
|
381
|
+
*/
|
|
382
|
+
contentType?: string;
|
|
383
|
+
/**
|
|
384
|
+
* Source CLI token when the whole body comes from one option (style=json)
|
|
385
|
+
*/
|
|
386
|
+
from?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Per-property body field mappings (style=flatten/multipart)
|
|
389
|
+
*/
|
|
390
|
+
properties?: XOpenApiBodyProp[];
|
|
391
|
+
[k: string]: unknown;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Maps one CLI option onto a request body field.
|
|
395
|
+
*/
|
|
396
|
+
export interface XOpenApiBodyProp {
|
|
397
|
+
/**
|
|
398
|
+
* The wire name of the body field
|
|
399
|
+
*/
|
|
400
|
+
name: string;
|
|
401
|
+
/**
|
|
402
|
+
* Source CLI token: 'option:<name>'
|
|
403
|
+
*/
|
|
404
|
+
from: string;
|
|
405
|
+
/**
|
|
406
|
+
* Dot path of the field within the JSON body
|
|
407
|
+
*/
|
|
408
|
+
jsonPath?: string;
|
|
409
|
+
/**
|
|
410
|
+
* How the CLI value is encoded into the field: 'string', 'number', 'integer', 'boolean', 'json' (parse as JSON), 'array' or 'file'
|
|
411
|
+
*/
|
|
412
|
+
encoding?: string;
|
|
413
|
+
/**
|
|
414
|
+
* Whether the body field is required
|
|
415
|
+
*/
|
|
416
|
+
required?: boolean;
|
|
417
|
+
[k: string]: unknown;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* xyd extension: OpenAPI/HTTP binding for the CLI as a whole (servers + security). Emitted by @xyd-js/openapi2opencli and consumed by the opencli2* code generators to build real API requests.
|
|
421
|
+
*/
|
|
422
|
+
export interface XOpenApiRoot {
|
|
423
|
+
/**
|
|
424
|
+
* Available API base URLs (from the OpenAPI servers list)
|
|
425
|
+
*/
|
|
426
|
+
servers?: string[];
|
|
427
|
+
/**
|
|
428
|
+
* Default security requirements for the CLI
|
|
429
|
+
*/
|
|
430
|
+
security?: XOpenApiSecurity[];
|
|
431
|
+
[k: string]: unknown;
|
|
432
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationMap": true,
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
|
|
15
|
+
},
|
|
16
|
+
"include": ["index.ts", "src/**/*.ts"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ['index.ts'],
|
|
5
|
+
format: ['esm', 'cjs'], // Output both ESM and CJS formats
|
|
6
|
+
target: 'node16', // Ensure compatibility with Node.js 16
|
|
7
|
+
dts: {
|
|
8
|
+
entry: 'index.ts', // Specify the entry for DTS
|
|
9
|
+
resolve: true, // Resolve external types
|
|
10
|
+
},
|
|
11
|
+
splitting: false, // Disable code splitting
|
|
12
|
+
sourcemap: true, // Generate source maps
|
|
13
|
+
clean: true, // Clean the output directory before each build
|
|
14
|
+
esbuildOptions: (options) => {
|
|
15
|
+
options.platform = 'node'; // Ensure the platform is set to Node.js
|
|
16
|
+
options.external = ['node:fs/promises']; // Mark 'node:fs/promises' as external
|
|
17
|
+
options.loader = { '.js': 'jsx' }; // Ensure proper handling of .js files
|
|
18
|
+
},
|
|
19
|
+
});
|