@ahoo-wang/wow-generator 10.0.0-alpha.3 → 10.0.0-alpha.4
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 +99 -62
- package/README.zh-CN.md +85 -48
- package/dist/analysis/analyze.d.cts +5 -8
- package/dist/analysis/analyze.d.ts +5 -8
- package/dist/analysis/apiClients.d.cts +3 -4
- package/dist/analysis/apiClients.d.ts +3 -4
- package/dist/analysis/clientNames.d.cts +0 -20
- package/dist/analysis/clientNames.d.ts +0 -20
- package/dist/analysis/model.d.cts +2 -102
- package/dist/analysis/model.d.ts +2 -102
- package/dist/analysis/modelInfo.d.cts +12 -3
- package/dist/analysis/modelInfo.d.ts +12 -3
- package/dist/analysis/models.d.cts +3 -11
- package/dist/analysis/models.d.ts +3 -11
- package/dist/api/configuration.d.cts +1 -5
- package/dist/api/configuration.d.ts +1 -5
- package/dist/cli/program.d.cts +0 -5
- package/dist/cli/program.d.ts +0 -5
- package/dist/cli.cjs +9 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +102 -3
- package/dist/cli.js.map +1 -1
- package/dist/{codeGenerator-CXBTLKZP.js → codeGenerator-CU1TGcUI.js} +716 -1327
- package/dist/codeGenerator-CU1TGcUI.js.map +1 -0
- package/dist/codeGenerator-DzI0zCgM.cjs +27 -0
- package/dist/codeGenerator-DzI0zCgM.cjs.map +1 -0
- package/dist/emit/imports.d.cts +0 -9
- package/dist/emit/imports.d.ts +0 -9
- package/dist/emitters/decorators.d.cts +3 -18
- package/dist/emitters/decorators.d.ts +3 -18
- package/dist/emitters/emit.d.cts +2 -3
- package/dist/emitters/emit.d.ts +2 -3
- package/dist/emitters/manifestClients.d.cts +3 -3
- package/dist/emitters/manifestClients.d.ts +3 -3
- package/dist/emitters/models.d.cts +1 -1
- package/dist/emitters/models.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/input/configuration.d.cts +2 -4
- package/dist/input/configuration.d.ts +2 -4
- package/dist/manifest/analyze.d.cts +18 -2
- package/dist/manifest/analyze.d.ts +18 -2
- package/dist/naming/modelInfo.d.cts +1 -2
- package/dist/naming/modelInfo.d.ts +1 -2
- package/dist/naming/paths.d.cts +0 -5
- package/dist/naming/paths.d.ts +0 -5
- package/dist/output/outputStore.d.cts +2 -6
- package/dist/output/outputStore.d.ts +2 -6
- package/dist/pipeline/codeGenerator.d.cts +13 -12
- package/dist/pipeline/codeGenerator.d.ts +13 -12
- package/package.json +8 -8
- package/dist/analysis/aggregates.d.cts +0 -21
- package/dist/analysis/aggregates.d.ts +0 -21
- package/dist/codeGenerator-Ba5Cz8XW.cjs +0 -31
- package/dist/codeGenerator-Ba5Cz8XW.cjs.map +0 -1
- package/dist/codeGenerator-CXBTLKZP.js.map +0 -1
- package/dist/emitters/commandClients.d.cts +0 -14
- package/dist/emitters/commandClients.d.ts +0 -14
- package/dist/emitters/queryClients.d.cts +0 -11
- package/dist/emitters/queryClients.d.ts +0 -11
- package/dist/fetcherGeneratorCli.cjs +0 -3
- package/dist/fetcherGeneratorCli.cjs.map +0 -1
- package/dist/fetcherGeneratorCli.d.cts +0 -8
- package/dist/fetcherGeneratorCli.d.ts +0 -8
- package/dist/fetcherGeneratorCli.js +0 -6
- package/dist/fetcherGeneratorCli.js.map +0 -1
- package/dist/program-BnfzUfUQ.cjs +0 -10
- package/dist/program-BnfzUfUQ.cjs.map +0 -1
- package/dist/program-CU0GCZqM.js +0 -103
- package/dist/program-CU0GCZqM.js.map +0 -1
- package/dist/wow/conventions.d.cts +0 -154
- package/dist/wow/conventions.d.ts +0 -154
- package/dist/wow/model.d.cts +0 -116
- package/dist/wow/model.d.ts +0 -116
- package/dist/wow/resolveWowModel.d.cts +0 -21
- package/dist/wow/resolveWowModel.d.ts +0 -21
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AggregateModel } from '../analysis/model.cjs';
|
|
2
|
-
import { EmitTarget } from './target.cjs';
|
|
3
|
-
/**
|
|
4
|
-
* Writes the command client of an aggregate: the enum of its command routes,
|
|
5
|
-
* a type per command body whose name does not already end in `Command`, the client, whose methods send the commands, and
|
|
6
|
-
* the streaming client, which waits on their results as server-sent events.
|
|
7
|
-
* An aggregate the document routes no command to (every command route
|
|
8
|
-
* disabled or closed by the service) gets none: a client without a method
|
|
9
|
-
* sends nothing, and its result type would go unused.
|
|
10
|
-
*
|
|
11
|
-
* @param aggregate - The aggregate
|
|
12
|
-
* @param target - Where it is written
|
|
13
|
-
*/
|
|
14
|
-
export declare function emitCommandClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AggregateModel } from '../analysis/model.js';
|
|
2
|
-
import { EmitTarget } from './target.js';
|
|
3
|
-
/**
|
|
4
|
-
* Writes the command client of an aggregate: the enum of its command routes,
|
|
5
|
-
* a type per command body whose name does not already end in `Command`, the client, whose methods send the commands, and
|
|
6
|
-
* the streaming client, which waits on their results as server-sent events.
|
|
7
|
-
* An aggregate the document routes no command to (every command route
|
|
8
|
-
* disabled or closed by the service) gets none: a client without a method
|
|
9
|
-
* sends nothing, and its result type would go unused.
|
|
10
|
-
*
|
|
11
|
-
* @param aggregate - The aggregate
|
|
12
|
-
* @param target - Where it is written
|
|
13
|
-
*/
|
|
14
|
-
export declare function emitCommandClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AggregateModel } from '../analysis/model.cjs';
|
|
2
|
-
import { EmitTarget } from './target.cjs';
|
|
3
|
-
/**
|
|
4
|
-
* Writes the query client of an aggregate: the enum of its event titles, the
|
|
5
|
-
* union of its event types, and the factory of its snapshot and event
|
|
6
|
-
* stream query clients.
|
|
7
|
-
*
|
|
8
|
-
* @param aggregate - The aggregate
|
|
9
|
-
* @param target - Where it is written
|
|
10
|
-
*/
|
|
11
|
-
export declare function emitQueryClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AggregateModel } from '../analysis/model.js';
|
|
2
|
-
import { EmitTarget } from './target.js';
|
|
3
|
-
/**
|
|
4
|
-
* Writes the query client of an aggregate: the enum of its event titles, the
|
|
5
|
-
* union of its event types, and the factory of its snapshot and event
|
|
6
|
-
* stream query clients.
|
|
7
|
-
*
|
|
8
|
-
* @param aggregate - The aggregate
|
|
9
|
-
* @param target - Where it is written
|
|
10
|
-
*/
|
|
11
|
-
export declare function emitQueryClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetcherGeneratorCli.cjs","names":["DEPRECATED_BIN_NOTICE","runCLI","require_program"],"sources":["../src/fetcherGeneratorCli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * The `fetcher-generator` bin: the CLI under the name it had in fetcher. It\n * says on stderr that the name is deprecated, then runs as `wow-generator`;\n * stdout stays the same, so `fetcher-generator --version` still prints only\n * the version.\n */\n\nimport { DEPRECATED_BIN_NOTICE, runCLI } from './cli/program';\n\n// compat(fetcher): the `fetcher-generator` bin of package.json; delete this\n// file and that bin entry in v10.\nprocess.stderr.write(`${DEPRECATED_BIN_NOTICE}\\n`);\nvoid runCLI();\n"],"mappings":";0CAaA,QAAQ,OAAO,MAAM,GAAGA,EAAAA,EAAsB,GAAG,EAC5CC,EAAAA,EAAO"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* The `fetcher-generator` bin: the CLI under the name it had in fetcher. It
|
|
4
|
-
* says on stderr that the name is deprecated, then runs as `wow-generator`;
|
|
5
|
-
* stdout stays the same, so `fetcher-generator --version` still prints only
|
|
6
|
-
* the version.
|
|
7
|
-
*/
|
|
8
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* The `fetcher-generator` bin: the CLI under the name it had in fetcher. It
|
|
4
|
-
* says on stderr that the name is deprecated, then runs as `wow-generator`;
|
|
5
|
-
* stdout stays the same, so `fetcher-generator --version` still prints only
|
|
6
|
-
* the version.
|
|
7
|
-
*/
|
|
8
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetcherGeneratorCli.js","names":["runCLI","DEPRECATED_BIN_NOTICE"],"sources":["../src/fetcherGeneratorCli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * The `fetcher-generator` bin: the CLI under the name it had in fetcher. It\n * says on stderr that the name is deprecated, then runs as `wow-generator`;\n * stdout stays the same, so `fetcher-generator --version` still prints only\n * the version.\n */\n\nimport { DEPRECATED_BIN_NOTICE, runCLI } from './cli/program';\n\n// compat(fetcher): the `fetcher-generator` bin of package.json; delete this\n// file and that bin entry in v10.\nprocess.stderr.write(`${DEPRECATED_BIN_NOTICE}\\n`);\nvoid runCLI();\n"],"mappings":";;AAaA,QAAQ,OAAO,MAAM,GAAGC,EAAsB,GAAG,GAC5CD,EAAO"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const e=require("./codeGenerator-Ba5Cz8XW.cjs");let t=require("path"),n=require("commander");var r=`10.0.0-alpha.3`;function i(e){if(!e)return!1;let t;try{t=new URL(e)}catch{return!0}return/^[a-z]:$/i.test(t.protocol)?!0:t.protocol===`http:`||t.protocol===`https:`}function a(t=[]){let n={};for(let r of t){let t=r.indexOf(`:`),i=t>0?r.slice(0,t).trim():``;if(!i)throw new e.s(`input`,`Invalid --header "${r}": expected "Name: value".`);n[i]=r.slice(t+1).trim()}return n}function o(t){if(t===void 0)return;let n=Number(t);if(!Number.isInteger(n)||n<=0)throw new e.s(`input`,`Invalid --timeout "${t}": expected a positive number of milliseconds.`);return n}function s(t){if(t===void 0||t===`summary`)return`summary`;if(t===`full`)return`full`;throw new e.s(`input`,`Invalid --schema-docs "${t}": expected "summary" or "full".`)}function c(e){return e.verbose?`verbose`:e.quiet?`quiet`:`normal`}function l(t,n,r){if(n instanceof e.s)return t.error(n.message),r&&n.cause!==void 0&&t.error(`Caused by:`,n.cause),n.exitCode;let i=n instanceof Error?n.message:String(n);return t.error(`Code generation failed: ${i}`),r?t.error(``,n):t.error(`Rerun with --verbose for the stack trace, and report it at https://github.com/Ahoo-Wang/Wow/issues if the input is valid.`),e.o.internal}async function u(n,u=new e.i({level:c(n)}),d={}){if(!i(n.input))return u.error(`Invalid input "${n.input}": expected a file path or an http(s) URL.`),e.o.input;try{u.debug(`wow-generator v${r}`);let i={...d,inputPath:n.input,outputDir:n.output,configPath:n.config,tsConfigFilePath:n.tsConfigFilePath,headers:a(n.header),timeoutMs:o(n.timeout),schemaDocs:s(n.schemaDocs),logger:u},c=await new e.t(i).generate(),l=c.warnings?`, ${c.warnings} warning${c.warnings===1?``:`s`}`:``,f=c.configPath?` with ${(0,t.relative)(process.cwd(),c.configPath)||c.configPath}`:``;return u.info(`Generated ${c.files.length} files into ${n.output}${f}${l}`),n.strict&&c.warnings>0?(u.error(`--strict: the run logged ${c.warnings} warning${c.warnings===1?``:`s`}.`),e.o.specification):e.o.success}catch(t){return d[e.n]?.aborted?e.o.interrupted:l(u,t,!!n.verbose)}}async function d(t){let n=new AbortController;process.once(`SIGINT`,()=>{console.error(`Generation interrupted by user`),n.abort()}),process.exitCode=await u(t,void 0,{[e.n]:n.signal})}var f=`
|
|
2
|
-
Exit codes:
|
|
3
|
-
${e.o.success} generated; or --help, help or --version printed
|
|
4
|
-
${e.o.internal} internal error; rerun with --verbose for the stack trace
|
|
5
|
-
${e.o.input} input or usage: unreadable, unfetchable or not OpenAPI 3.x; an invalid option
|
|
6
|
-
${e.o.configuration} configuration: cannot be read, parsed or validated
|
|
7
|
-
${e.o.specification} specification: cannot be generated, or --strict and the run had warnings
|
|
8
|
-
${e.o.output} output: the manifest, a path outside the output, or a failed write
|
|
9
|
-
${e.o.interrupted} interrupted (Ctrl-C)`,p=`fetcher-generator is deprecated and will be removed in v10; run wow-generator instead.`;function m(e,t=[]){return[...t,e]}function h(t=n.program){return t.exitOverride(),t.name(`wow-generator`).description(`OpenAPI Specification TypeScript code generator for Wow`).version(r,`-v, --version`),t.command(`generate`).description(`Generate TypeScript code from an OpenAPI specification or a Wow V10 Manifest`).requiredOption(`-i, --input <file>`,`Input OpenAPI specification or Wow Manifest (GET /wow/manifest) file path or URL (http/https)`).option(`-o, --output <path>`,`Output directory path`,`src/generated`).option(`-c, --config <file>`,`Configuration file path (default: ${e.c})`).option(`-t, --ts-config-file-path <file>`,`TypeScript configuration file path`).option(`-H, --header <header>`,`Request header for an http(s) input or configuration, as "Name: value"; repeatable`,m).option(`--timeout <ms>`,`Milliseconds before fetching an http(s) input is abandoned (default: ${e.r})`).option(`--schema-docs <mode>`,`What model doc comments carry: "summary" (title, description, constraints) or "full" (also the JSON schema)`,`summary`).option(`--strict`,`Exit with code 4 when the run logs a warning`).option(`--verbose`,`Log every step, and the stack trace of a failure`).option(`--quiet`,`Log only warnings and errors`).addHelpText(`after`,f).action(d),t}function g(t){return t.exitCode===0?e.o.success:e.o.input}async function _(e,t=h()){try{e===void 0?await t.parseAsync():await t.parseAsync(e,{from:`user`})}catch(e){if(!(e instanceof n.CommanderError))throw e;process.exitCode=g(e)}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return p}});
|
|
10
|
-
//# sourceMappingURL=program-BnfzUfUQ.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"program-BnfzUfUQ.cjs","names":["GeneratorError","EXIT_CODES","ConsoleLogger","CodeGenerator","relative","SIGNAL_SEAM","EXIT_CODES","program","DEFAULT_CONFIG_PATH","DEFAULT_HTTP_TIMEOUT_MS","CommanderError","require_codeGenerator","path","commander","VERSION","validateInput","input","url","parseHeaders","parsed","header","headers","separator","name","parseTimeout","timeout","value","parseSchemaDocs","schemaDocs","logLevel","options","reportFailure","error","logger","verbose","message","runGenerate","generatorOptions","seams","result","warnings","config","generateAction","interruption","EXIT_CODE_HELP","DEPRECATED_BIN_NOTICE","collect","previous","setupCLI","target","commanderExitCode","runCLI","args"],"sources":["../src/version.ts","../src/cli/runGenerate.ts","../src/cli/program.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Replaced at build time with the `version` of this package's package.json\n// (`define` in vite.config.ts, which Vitest shares), so only the version string\n// reaches dist, not the manifest with its dependencies and workspace ranges.\ndeclare const __WOW_GENERATOR_VERSION__: string;\n\n/** The version of this package, as its package.json named it at build time. */\nexport const VERSION: string = __WOW_GENERATOR_VERSION__;\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { relative } from 'path';\nimport { VERSION } from '../version';\nimport { EXIT_CODES, GeneratorError } from '../api/errors';\nimport { CodeGenerator } from '../pipeline/codeGenerator';\nimport type { Logger, LogLevel } from '../api/logger';\nimport { ConsoleLogger } from '../api/logger';\nimport type { SchemaDocs } from '../api/options';\nimport type { SeamOptions, Seams } from '../pipeline/seams';\nimport { SIGNAL_SEAM } from '../pipeline/seams';\n\n/**\n * Options of the `generate` command, as commander parses them.\n */\nexport interface GenerateCommandOptions {\n input: string;\n output: string;\n config?: string;\n tsConfigFilePath?: string;\n /** `Name: value` request headers for an http(s) input or configuration. */\n header?: string[];\n /** Milliseconds, as typed on the command line. */\n timeout?: string;\n /** `summary` or `full`. */\n schemaDocs?: string;\n /** Exit with a non-zero code when the run logged a warning. */\n strict?: boolean;\n verbose?: boolean;\n quiet?: boolean;\n}\n\n/**\n * Validates the input path or URL.\n *\n * Any file path is accepted here and checked when it is read. A URL must use\n * http or https; its host is not restricted, because the generator runs on\n * the developer's own machine against a document they chose, and fetching an\n * intranet service's `/v3/api-docs` is the common case.\n *\n * @param input - Input path or URL\n * @returns true if valid\n */\nexport function validateInput(input: string): boolean {\n if (!input) return false;\n let url: URL;\n try {\n url = new URL(input);\n } catch {\n // Not a URL: a file path, which parseOpenAPI reads.\n return true;\n }\n // A Windows path such as C:\\spec.json parses as a URL with scheme \"c:\".\n if (/^[a-z]:$/i.test(url.protocol)) return true;\n return url.protocol === 'http:' || url.protocol === 'https:';\n}\n\n/**\n * Parses `Name: value` header arguments.\n *\n * @param headers - The raw `--header` values\n * @returns The headers by name\n * @throws GeneratorError of kind `input` for a value without a name\n */\nexport function parseHeaders(\n headers: readonly string[] = [],\n): Record<string, string> {\n const parsed: Record<string, string> = {};\n for (const header of headers) {\n const separator = header.indexOf(':');\n const name = separator > 0 ? header.slice(0, separator).trim() : '';\n if (!name) {\n throw new GeneratorError(\n 'input',\n `Invalid --header \"${header}\": expected \"Name: value\".`,\n );\n }\n parsed[name] = header.slice(separator + 1).trim();\n }\n return parsed;\n}\n\nfunction parseTimeout(timeout: string | undefined): number | undefined {\n if (timeout === undefined) return undefined;\n const value = Number(timeout);\n if (!Number.isInteger(value) || value <= 0) {\n throw new GeneratorError(\n 'input',\n `Invalid --timeout \"${timeout}\": expected a positive number of milliseconds.`,\n );\n }\n return value;\n}\n\nfunction parseSchemaDocs(schemaDocs: string | undefined): SchemaDocs {\n if (schemaDocs === undefined || schemaDocs === 'summary') return 'summary';\n if (schemaDocs === 'full') return 'full';\n throw new GeneratorError(\n 'input',\n `Invalid --schema-docs \"${schemaDocs}\": expected \"summary\" or \"full\".`,\n );\n}\n\nfunction logLevel(options: GenerateCommandOptions): LogLevel {\n if (options.verbose) return 'verbose';\n if (options.quiet) return 'quiet';\n return 'normal';\n}\n\n/**\n * Reports a failure as one actionable line; the stack and the causes only\n * with `--verbose`.\n *\n * @returns The exit code the failure maps to\n */\nfunction reportFailure(\n logger: Logger,\n error: unknown,\n verbose: boolean,\n): number {\n if (error instanceof GeneratorError) {\n logger.error(error.message);\n if (verbose && error.cause !== undefined) {\n logger.error('Caused by:', error.cause);\n }\n return error.exitCode;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Code generation failed: ${message}`);\n if (verbose) {\n logger.error('', error);\n } else {\n logger.error(\n 'Rerun with --verbose for the stack trace, and report it at https://github.com/Ahoo-Wang/Wow/issues if the input is valid.',\n );\n }\n return EXIT_CODES.internal;\n}\n\n/**\n * Runs the `generate` command.\n *\n * @param options - The parsed command options\n * @param logger - Where to report; a console logger at the level the options ask for by default\n * @param seams - What the package hands the generator beyond the options;\n * a run stopped by the {@link SIGNAL_SEAM} exits with\n * {@link EXIT_CODES.interrupted}\n * @returns The exit code: see {@link EXIT_CODES}\n */\nexport async function runGenerate(\n options: GenerateCommandOptions,\n logger: Logger = new ConsoleLogger({ level: logLevel(options) }),\n seams: Seams = {},\n): Promise<number> {\n if (!validateInput(options.input)) {\n logger.error(\n `Invalid input \"${options.input}\": expected a file path or an http(s) URL.`,\n );\n return EXIT_CODES.input;\n }\n try {\n logger.debug(`wow-generator v${VERSION}`);\n const generatorOptions: SeamOptions = {\n ...seams,\n inputPath: options.input,\n outputDir: options.output,\n configPath: options.config,\n tsConfigFilePath: options.tsConfigFilePath,\n headers: parseHeaders(options.header),\n timeoutMs: parseTimeout(options.timeout),\n schemaDocs: parseSchemaDocs(options.schemaDocs),\n logger,\n };\n const result = await new CodeGenerator(generatorOptions).generate();\n const warnings = result.warnings\n ? `, ${result.warnings} warning${result.warnings === 1 ? '' : 's'}`\n : '';\n const config = result.configPath\n ? ` with ${relative(process.cwd(), result.configPath) || result.configPath}`\n : '';\n logger.info(\n `Generated ${result.files.length} files into ${options.output}${config}${warnings}`,\n );\n if (options.strict && result.warnings > 0) {\n logger.error(\n `--strict: the run logged ${result.warnings} warning${result.warnings === 1 ? '' : 's'}.`,\n );\n return EXIT_CODES.specification;\n }\n return EXIT_CODES.success;\n } catch (error) {\n if (seams[SIGNAL_SEAM]?.aborted) return EXIT_CODES.interrupted;\n return reportFailure(logger, error, !!options.verbose);\n }\n}\n\n/**\n * Action handler for the generate command: runs it and sets the process exit\n * code.\n *\n * Ctrl-C stops the run at its next step and exits with\n * {@link EXIT_CODES.interrupted}. A run that has begun writing finishes\n * writing its files, then stops: it removes no stale file and leaves the\n * manifest as the last complete run wrote it, so the manifest never records\n * a run that did not finish. A second Ctrl-C ends the process at once.\n *\n * @param options - Command options\n */\nexport async function generateAction(options: GenerateCommandOptions) {\n const interruption = new AbortController();\n process.once('SIGINT', () => {\n console.error('Generation interrupted by user');\n interruption.abort();\n });\n process.exitCode = await runGenerate(options, undefined, {\n [SIGNAL_SEAM]: interruption.signal,\n });\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Command } from 'commander';\nimport { CommanderError, program } from 'commander';\nimport { VERSION } from '../version';\nimport { DEFAULT_CONFIG_PATH } from '../api/configuration';\nimport { EXIT_CODES } from '../api/errors';\nimport { DEFAULT_HTTP_TIMEOUT_MS } from '../input/resources';\nimport { generateAction } from './runGenerate';\n\n/** The exit codes `generate --help` lists, as the README's table does. */\nexport const EXIT_CODE_HELP = `\nExit codes:\n ${EXIT_CODES.success} generated; or --help, help or --version printed\n ${EXIT_CODES.internal} internal error; rerun with --verbose for the stack trace\n ${EXIT_CODES.input} input or usage: unreadable, unfetchable or not OpenAPI 3.x; an invalid option\n ${EXIT_CODES.configuration} configuration: cannot be read, parsed or validated\n ${EXIT_CODES.specification} specification: cannot be generated, or --strict and the run had warnings\n ${EXIT_CODES.output} output: the manifest, a path outside the output, or a failed write\n ${EXIT_CODES.interrupted} interrupted (Ctrl-C)`;\n\n/**\n * What the `fetcher-generator` bin prints to stderr before it runs: the name\n * still works, and goes in v10.\n */\nexport const DEPRECATED_BIN_NOTICE =\n 'fetcher-generator is deprecated and will be removed in v10; run wow-generator instead.';\n\n/** Collects the values of an option given more than once, such as `--header`. */\nexport function collect(value: string, previous: string[] = []): string[] {\n return [...previous, value];\n}\n\n/**\n * Sets up the CLI program with all commands and options.\n *\n * Commander does not exit the process: a usage error (a missing required\n * option, an unknown option or command, a missing argument, no command at\n * all) is thrown as a `CommanderError`, which {@link runCLI} maps to an exit\n * code.\n *\n * @param target - The program to set up; commander's global one by default.\n * Settings made on it before this call, such as `configureOutput`, reach the\n * `generate` command too.\n * @returns The configured commander program instance\n */\nexport function setupCLI(target: Command = program): Command {\n // Before `command()`: a subcommand copies the exit override when it is\n // created.\n target.exitOverride();\n // compat(fetcher): package.json also installs this CLI as `fetcher-generator`\n // (src/fetcherGeneratorCli.ts), the name existing scripts call; drop that\n // bin alias in v10.\n target\n .name('wow-generator')\n .description('OpenAPI Specification TypeScript code generator for Wow')\n .version(VERSION, '-v, --version');\n\n target\n .command('generate')\n .description(\n 'Generate TypeScript code from an OpenAPI specification or a Wow V10 Manifest',\n )\n .requiredOption(\n '-i, --input <file>',\n 'Input OpenAPI specification or Wow Manifest (GET /wow/manifest) file path or URL (http/https)',\n )\n .option('-o, --output <path>', 'Output directory path', 'src/generated')\n // No commander default: an omitted -c falls back to DEFAULT_CONFIG_PATH,\n // which may be absent, while a path the user named has to exist.\n .option(\n '-c, --config <file>',\n `Configuration file path (default: ${DEFAULT_CONFIG_PATH})`,\n )\n .option(\n '-t, --ts-config-file-path <file>',\n 'TypeScript configuration file path',\n )\n .option(\n '-H, --header <header>',\n 'Request header for an http(s) input or configuration, as \"Name: value\"; repeatable',\n collect,\n )\n .option(\n '--timeout <ms>',\n `Milliseconds before fetching an http(s) input is abandoned (default: ${DEFAULT_HTTP_TIMEOUT_MS})`,\n )\n .option(\n '--schema-docs <mode>',\n 'What model doc comments carry: \"summary\" (title, description, constraints) or \"full\" (also the JSON schema)',\n 'summary',\n )\n .option('--strict', 'Exit with code 4 when the run logs a warning')\n .option('--verbose', 'Log every step, and the stack trace of a failure')\n .option('--quiet', 'Log only warnings and errors')\n .addHelpText('after', EXIT_CODE_HELP)\n .action(generateAction);\n\n return target;\n}\n\n/**\n * The exit code of a command line commander stopped at: 0 for `--help`,\n * `help` and `--version`; {@link EXIT_CODES.input} for a usage error, which\n * commander has already reported. A usage error is an invalid command line,\n * the same category as an invalid option value such as `--timeout abc`.\n */\nexport function commanderExitCode(error: CommanderError): number {\n return error.exitCode === 0 ? EXIT_CODES.success : EXIT_CODES.input;\n}\n\n/**\n * Parses the command line and runs the command it names. The `generate`\n * command sets the process exit code itself; a command line commander stops\n * at sets it to {@link commanderExitCode}.\n *\n * @param args - The arguments after the executable and script;\n * `process.argv` by default\n * @param target - The program to run; {@link setupCLI} on commander's global\n * one by default\n */\nexport async function runCLI(\n args?: readonly string[],\n target: Command = setupCLI(),\n): Promise<void> {\n try {\n if (args === undefined) {\n await target.parseAsync();\n } else {\n await target.parseAsync(args, { from: 'user' });\n }\n } catch (error) {\n if (!(error instanceof CommanderError)) throw error;\n process.exitCode = commanderExitCode(error);\n }\n}\n"],"mappings":"6FAmBA,IAAac,EAAA,iBCmCb,SAAgBC,EAAc,EAAwB,CACpD,GAAI,CAACC,EAAO,MAAO,GACnB,IAAIC,EACJ,GAAI,CACF,EAAM,IAAI,IAAID,CAAK,CACrB,MAAQ,CAEN,MAAO,EACT,CAGA,MADI,YAAY,KAAKC,EAAI,QAAQ,EAAU,GACpCA,EAAI,WAAa,SAAWA,EAAI,WAAa,QACtD,CASA,SAAgBC,EACd,EAA6B,CAAC,EACN,CACxB,IAAMC,EAAiC,CAAC,EACxC,IAAK,IAAMC,KAAUC,EAAS,CAC5B,IAAMC,EAAYF,EAAO,QAAQ,GAAG,EAC9BG,EAAOD,EAAY,EAAIF,EAAO,MAAM,EAAGE,CAAS,CAAC,CAAC,KAAK,EAAI,GACjE,GAAI,CAACC,EACH,MAAM,IAAIvB,EAAAA,EACR,QACA,qBAAqBoB,EAAO,2BAC9B,EAEF,EAAOG,GAAQH,EAAO,MAAME,EAAY,CAAC,CAAC,CAAC,KAAK,CAClD,CACA,OAAOH,CACT,CAEA,SAASK,EAAa,EAAiD,CACrE,GAAIC,IAAY,IAAA,GAAW,OAC3B,IAAMC,EAAQ,OAAOD,CAAO,EAC5B,GAAI,CAAC,OAAO,UAAUC,CAAK,GAAKA,GAAS,EACvC,MAAM,IAAI1B,EAAAA,EACR,QACA,sBAAsByB,EAAQ,+CAChC,EAEF,OAAOC,CACT,CAEA,SAASC,EAAgB,EAA4C,CACnE,GAAIC,IAAe,IAAA,IAAaA,IAAe,UAAW,MAAO,UACjE,GAAIA,IAAe,OAAQ,MAAO,OAClC,MAAM,IAAI5B,EAAAA,EACR,QACA,0BAA0B4B,EAAW,iCACvC,CACF,CAEA,SAASC,EAAS,EAA2C,CAG3D,OAFIC,EAAQ,QAAgB,UACxBA,EAAQ,MAAc,QACnB,QACT,CAQA,SAASC,EACP,EACA,EACA,EACQ,CACR,GAAIC,aAAiBhC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ACC,iBACA,wEAAwErC,EAAAA,EAAwB,EAClG,CAAC,CACA,OACC,uBACA,8GACA,SACF,CAAC,CACA,OAAO,WAAY,8CAA8C,CAAC,CAClE,OAAO,YAAa,kDAAkD,CAAC,CACvE,OAAO,UAAW,8BAA8B,CAAC,CACjD,YAAY,QAASmC,CAAc,CAAC,CACpC,OAAOF,CAAc,EAEjBO,CACT,CAQA,SAAgBC,EAAkB,EAA+B,CAC/D,OAAOlB,EAAM,WAAa,EAAI1B,EAAAA,EAAW,QAAUA,EAAAA,EAAW,KAChE,CAYA,eAAsB6C,EACpB,EACA,EAAkBH,EAAS,EACZ,CACf,GAAI,CACEI,IAAS,IAAA,GACX,MAAMH,EAAO,WAAW,EAExB,MAAMA,EAAO,WAAWG,EAAM,CAAE,KAAM,MAAO,CAAC,CAElD,OAASpB,EAAO,CACd,GAAI,EAAEA,aAAiBtB,EAAAA,gBAAiB,MAAMsB,EAC9C,QAAQ,SAAWkB,EAAkBlB,CAAK,CAC5C,CACF"}
|
package/dist/program-CU0GCZqM.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { c as e, i as t, n, o as r, r as i, s as a, t as o } from "./codeGenerator-CXBTLKZP.js";
|
|
2
|
-
import { relative as s } from "path";
|
|
3
|
-
import { CommanderError as c, program as l } from "commander";
|
|
4
|
-
//#region src/version.ts
|
|
5
|
-
var u = "10.0.0-alpha.3";
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/cli/runGenerate.ts
|
|
8
|
-
function d(e) {
|
|
9
|
-
if (!e) return !1;
|
|
10
|
-
let t;
|
|
11
|
-
try {
|
|
12
|
-
t = new URL(e);
|
|
13
|
-
} catch {
|
|
14
|
-
return !0;
|
|
15
|
-
}
|
|
16
|
-
return /^[a-z]:$/i.test(t.protocol) ? !0 : t.protocol === "http:" || t.protocol === "https:";
|
|
17
|
-
}
|
|
18
|
-
function f(e = []) {
|
|
19
|
-
let t = {};
|
|
20
|
-
for (let n of e) {
|
|
21
|
-
let e = n.indexOf(":"), r = e > 0 ? n.slice(0, e).trim() : "";
|
|
22
|
-
if (!r) throw new a("input", `Invalid --header "${n}": expected "Name: value".`);
|
|
23
|
-
t[r] = n.slice(e + 1).trim();
|
|
24
|
-
}
|
|
25
|
-
return t;
|
|
26
|
-
}
|
|
27
|
-
function p(e) {
|
|
28
|
-
if (e === void 0) return;
|
|
29
|
-
let t = Number(e);
|
|
30
|
-
if (!Number.isInteger(t) || t <= 0) throw new a("input", `Invalid --timeout "${e}": expected a positive number of milliseconds.`);
|
|
31
|
-
return t;
|
|
32
|
-
}
|
|
33
|
-
function m(e) {
|
|
34
|
-
if (e === void 0 || e === "summary") return "summary";
|
|
35
|
-
if (e === "full") return "full";
|
|
36
|
-
throw new a("input", `Invalid --schema-docs "${e}": expected "summary" or "full".`);
|
|
37
|
-
}
|
|
38
|
-
function h(e) {
|
|
39
|
-
return e.verbose ? "verbose" : e.quiet ? "quiet" : "normal";
|
|
40
|
-
}
|
|
41
|
-
function g(e, t, n) {
|
|
42
|
-
if (t instanceof a) return e.error(t.message), n && t.cause !== void 0 && e.error("Caused by:", t.cause), t.exitCode;
|
|
43
|
-
let i = t instanceof Error ? t.message : String(t);
|
|
44
|
-
return e.error(`Code generation failed: ${i}`), n ? e.error("", t) : e.error("Rerun with --verbose for the stack trace, and report it at https://github.com/Ahoo-Wang/Wow/issues if the input is valid."), r.internal;
|
|
45
|
-
}
|
|
46
|
-
async function _(e, i = new t({ level: h(e) }), a = {}) {
|
|
47
|
-
if (!d(e.input)) return i.error(`Invalid input "${e.input}": expected a file path or an http(s) URL.`), r.input;
|
|
48
|
-
try {
|
|
49
|
-
i.debug(`wow-generator v${u}`);
|
|
50
|
-
let t = {
|
|
51
|
-
...a,
|
|
52
|
-
inputPath: e.input,
|
|
53
|
-
outputDir: e.output,
|
|
54
|
-
configPath: e.config,
|
|
55
|
-
tsConfigFilePath: e.tsConfigFilePath,
|
|
56
|
-
headers: f(e.header),
|
|
57
|
-
timeoutMs: p(e.timeout),
|
|
58
|
-
schemaDocs: m(e.schemaDocs),
|
|
59
|
-
logger: i
|
|
60
|
-
}, n = await new o(t).generate(), c = n.warnings ? `, ${n.warnings} warning${n.warnings === 1 ? "" : "s"}` : "", l = n.configPath ? ` with ${s(process.cwd(), n.configPath) || n.configPath}` : "";
|
|
61
|
-
return i.info(`Generated ${n.files.length} files into ${e.output}${l}${c}`), e.strict && n.warnings > 0 ? (i.error(`--strict: the run logged ${n.warnings} warning${n.warnings === 1 ? "" : "s"}.`), r.specification) : r.success;
|
|
62
|
-
} catch (t) {
|
|
63
|
-
return a[n]?.aborted ? r.interrupted : g(i, t, !!e.verbose);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async function v(e) {
|
|
67
|
-
let t = new AbortController();
|
|
68
|
-
process.once("SIGINT", () => {
|
|
69
|
-
console.error("Generation interrupted by user"), t.abort();
|
|
70
|
-
}), process.exitCode = await _(e, void 0, { [n]: t.signal });
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/cli/program.ts
|
|
74
|
-
var y = `
|
|
75
|
-
Exit codes:
|
|
76
|
-
${r.success} generated; or --help, help or --version printed
|
|
77
|
-
${r.internal} internal error; rerun with --verbose for the stack trace
|
|
78
|
-
${r.input} input or usage: unreadable, unfetchable or not OpenAPI 3.x; an invalid option
|
|
79
|
-
${r.configuration} configuration: cannot be read, parsed or validated
|
|
80
|
-
${r.specification} specification: cannot be generated, or --strict and the run had warnings
|
|
81
|
-
${r.output} output: the manifest, a path outside the output, or a failed write
|
|
82
|
-
${r.interrupted} interrupted (Ctrl-C)`, b = "fetcher-generator is deprecated and will be removed in v10; run wow-generator instead.";
|
|
83
|
-
function x(e, t = []) {
|
|
84
|
-
return [...t, e];
|
|
85
|
-
}
|
|
86
|
-
function S(t = l) {
|
|
87
|
-
return t.exitOverride(), t.name("wow-generator").description("OpenAPI Specification TypeScript code generator for Wow").version(u, "-v, --version"), t.command("generate").description("Generate TypeScript code from an OpenAPI specification or a Wow V10 Manifest").requiredOption("-i, --input <file>", "Input OpenAPI specification or Wow Manifest (GET /wow/manifest) file path or URL (http/https)").option("-o, --output <path>", "Output directory path", "src/generated").option("-c, --config <file>", `Configuration file path (default: ${e})`).option("-t, --ts-config-file-path <file>", "TypeScript configuration file path").option("-H, --header <header>", "Request header for an http(s) input or configuration, as \"Name: value\"; repeatable", x).option("--timeout <ms>", `Milliseconds before fetching an http(s) input is abandoned (default: ${i})`).option("--schema-docs <mode>", "What model doc comments carry: \"summary\" (title, description, constraints) or \"full\" (also the JSON schema)", "summary").option("--strict", "Exit with code 4 when the run logs a warning").option("--verbose", "Log every step, and the stack trace of a failure").option("--quiet", "Log only warnings and errors").addHelpText("after", y).action(v), t;
|
|
88
|
-
}
|
|
89
|
-
function C(e) {
|
|
90
|
-
return e.exitCode === 0 ? r.success : r.input;
|
|
91
|
-
}
|
|
92
|
-
async function w(e, t = S()) {
|
|
93
|
-
try {
|
|
94
|
-
e === void 0 ? await t.parseAsync() : await t.parseAsync(e, { from: "user" });
|
|
95
|
-
} catch (e) {
|
|
96
|
-
if (!(e instanceof c)) throw e;
|
|
97
|
-
process.exitCode = C(e);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//#endregion
|
|
101
|
-
export { S as i, x as n, w as r, b as t };
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=program-CU0GCZqM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"program-CU0GCZqM.js","names":["DEFAULT_CONFIG_PATH","ConsoleLogger","EXIT_CODES","DEFAULT_HTTP_TIMEOUT_MS","GeneratorError","CodeGenerator","VERSION","validateInput","input","url","parseHeaders","parsed","header","headers","separator","name","parseTimeout","timeout","value","parseSchemaDocs","schemaDocs","logLevel","options","reportFailure","error","logger","verbose","message","runGenerate","generatorOptions","seams","result","warnings","config","relative","SIGNAL_SEAM","generateAction","interruption","EXIT_CODE_HELP","DEPRECATED_BIN_NOTICE","collect","previous","setupCLI","program","target","commanderExitCode","runCLI","args","CommanderError"],"sources":["../src/version.ts","../src/cli/runGenerate.ts","../src/cli/program.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Replaced at build time with the `version` of this package's package.json\n// (`define` in vite.config.ts, which Vitest shares), so only the version string\n// reaches dist, not the manifest with its dependencies and workspace ranges.\ndeclare const __WOW_GENERATOR_VERSION__: string;\n\n/** The version of this package, as its package.json named it at build time. */\nexport const VERSION: string = __WOW_GENERATOR_VERSION__;\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { relative } from 'path';\nimport { VERSION } from '../version';\nimport { EXIT_CODES, GeneratorError } from '../api/errors';\nimport { CodeGenerator } from '../pipeline/codeGenerator';\nimport type { Logger, LogLevel } from '../api/logger';\nimport { ConsoleLogger } from '../api/logger';\nimport type { SchemaDocs } from '../api/options';\nimport type { SeamOptions, Seams } from '../pipeline/seams';\nimport { SIGNAL_SEAM } from '../pipeline/seams';\n\n/**\n * Options of the `generate` command, as commander parses them.\n */\nexport interface GenerateCommandOptions {\n input: string;\n output: string;\n config?: string;\n tsConfigFilePath?: string;\n /** `Name: value` request headers for an http(s) input or configuration. */\n header?: string[];\n /** Milliseconds, as typed on the command line. */\n timeout?: string;\n /** `summary` or `full`. */\n schemaDocs?: string;\n /** Exit with a non-zero code when the run logged a warning. */\n strict?: boolean;\n verbose?: boolean;\n quiet?: boolean;\n}\n\n/**\n * Validates the input path or URL.\n *\n * Any file path is accepted here and checked when it is read. A URL must use\n * http or https; its host is not restricted, because the generator runs on\n * the developer's own machine against a document they chose, and fetching an\n * intranet service's `/v3/api-docs` is the common case.\n *\n * @param input - Input path or URL\n * @returns true if valid\n */\nexport function validateInput(input: string): boolean {\n if (!input) return false;\n let url: URL;\n try {\n url = new URL(input);\n } catch {\n // Not a URL: a file path, which parseOpenAPI reads.\n return true;\n }\n // A Windows path such as C:\\spec.json parses as a URL with scheme \"c:\".\n if (/^[a-z]:$/i.test(url.protocol)) return true;\n return url.protocol === 'http:' || url.protocol === 'https:';\n}\n\n/**\n * Parses `Name: value` header arguments.\n *\n * @param headers - The raw `--header` values\n * @returns The headers by name\n * @throws GeneratorError of kind `input` for a value without a name\n */\nexport function parseHeaders(\n headers: readonly string[] = [],\n): Record<string, string> {\n const parsed: Record<string, string> = {};\n for (const header of headers) {\n const separator = header.indexOf(':');\n const name = separator > 0 ? header.slice(0, separator).trim() : '';\n if (!name) {\n throw new GeneratorError(\n 'input',\n `Invalid --header \"${header}\": expected \"Name: value\".`,\n );\n }\n parsed[name] = header.slice(separator + 1).trim();\n }\n return parsed;\n}\n\nfunction parseTimeout(timeout: string | undefined): number | undefined {\n if (timeout === undefined) return undefined;\n const value = Number(timeout);\n if (!Number.isInteger(value) || value <= 0) {\n throw new GeneratorError(\n 'input',\n `Invalid --timeout \"${timeout}\": expected a positive number of milliseconds.`,\n );\n }\n return value;\n}\n\nfunction parseSchemaDocs(schemaDocs: string | undefined): SchemaDocs {\n if (schemaDocs === undefined || schemaDocs === 'summary') return 'summary';\n if (schemaDocs === 'full') return 'full';\n throw new GeneratorError(\n 'input',\n `Invalid --schema-docs \"${schemaDocs}\": expected \"summary\" or \"full\".`,\n );\n}\n\nfunction logLevel(options: GenerateCommandOptions): LogLevel {\n if (options.verbose) return 'verbose';\n if (options.quiet) return 'quiet';\n return 'normal';\n}\n\n/**\n * Reports a failure as one actionable line; the stack and the causes only\n * with `--verbose`.\n *\n * @returns The exit code the failure maps to\n */\nfunction reportFailure(\n logger: Logger,\n error: unknown,\n verbose: boolean,\n): number {\n if (error instanceof GeneratorError) {\n logger.error(error.message);\n if (verbose && error.cause !== undefined) {\n logger.error('Caused by:', error.cause);\n }\n return error.exitCode;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Code generation failed: ${message}`);\n if (verbose) {\n logger.error('', error);\n } else {\n logger.error(\n 'Rerun with --verbose for the stack trace, and report it at https://github.com/Ahoo-Wang/Wow/issues if the input is valid.',\n );\n }\n return EXIT_CODES.internal;\n}\n\n/**\n * Runs the `generate` command.\n *\n * @param options - The parsed command options\n * @param logger - Where to report; a console logger at the level the options ask for by default\n * @param seams - What the package hands the generator beyond the options;\n * a run stopped by the {@link SIGNAL_SEAM} exits with\n * {@link EXIT_CODES.interrupted}\n * @returns The exit code: see {@link EXIT_CODES}\n */\nexport async function runGenerate(\n options: GenerateCommandOptions,\n logger: Logger = new ConsoleLogger({ level: logLevel(options) }),\n seams: Seams = {},\n): Promise<number> {\n if (!validateInput(options.input)) {\n logger.error(\n `Invalid input \"${options.input}\": expected a file path or an http(s) URL.`,\n );\n return EXIT_CODES.input;\n }\n try {\n logger.debug(`wow-generator v${VERSION}`);\n const generatorOptions: SeamOptions = {\n ...seams,\n inputPath: options.input,\n outputDir: options.output,\n configPath: options.config,\n tsConfigFilePath: options.tsConfigFilePath,\n headers: parseHeaders(options.header),\n timeoutMs: parseTimeout(options.timeout),\n schemaDocs: parseSchemaDocs(options.schemaDocs),\n logger,\n };\n const result = await new CodeGenerator(generatorOptions).generate();\n const warnings = result.warnings\n ? `, ${result.warnings} warning${result.warnings === 1 ? '' : 's'}`\n : '';\n const config = result.configPath\n ? ` with ${relative(process.cwd(), result.configPath) || result.configPath}`\n : '';\n logger.info(\n `Generated ${result.files.length} files into ${options.output}${config}${warnings}`,\n );\n if (options.strict && result.warnings > 0) {\n logger.error(\n `--strict: the run logged ${result.warnings} warning${result.warnings === 1 ? '' : 's'}.`,\n );\n return EXIT_CODES.specification;\n }\n return EXIT_CODES.success;\n } catch (error) {\n if (seams[SIGNAL_SEAM]?.aborted) return EXIT_CODES.interrupted;\n return reportFailure(logger, error, !!options.verbose);\n }\n}\n\n/**\n * Action handler for the generate command: runs it and sets the process exit\n * code.\n *\n * Ctrl-C stops the run at its next step and exits with\n * {@link EXIT_CODES.interrupted}. A run that has begun writing finishes\n * writing its files, then stops: it removes no stale file and leaves the\n * manifest as the last complete run wrote it, so the manifest never records\n * a run that did not finish. A second Ctrl-C ends the process at once.\n *\n * @param options - Command options\n */\nexport async function generateAction(options: GenerateCommandOptions) {\n const interruption = new AbortController();\n process.once('SIGINT', () => {\n console.error('Generation interrupted by user');\n interruption.abort();\n });\n process.exitCode = await runGenerate(options, undefined, {\n [SIGNAL_SEAM]: interruption.signal,\n });\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Command } from 'commander';\nimport { CommanderError, program } from 'commander';\nimport { VERSION } from '../version';\nimport { DEFAULT_CONFIG_PATH } from '../api/configuration';\nimport { EXIT_CODES } from '../api/errors';\nimport { DEFAULT_HTTP_TIMEOUT_MS } from '../input/resources';\nimport { generateAction } from './runGenerate';\n\n/** The exit codes `generate --help` lists, as the README's table does. */\nexport const EXIT_CODE_HELP = `\nExit codes:\n ${EXIT_CODES.success} generated; or --help, help or --version printed\n ${EXIT_CODES.internal} internal error; rerun with --verbose for the stack trace\n ${EXIT_CODES.input} input or usage: unreadable, unfetchable or not OpenAPI 3.x; an invalid option\n ${EXIT_CODES.configuration} configuration: cannot be read, parsed or validated\n ${EXIT_CODES.specification} specification: cannot be generated, or --strict and the run had warnings\n ${EXIT_CODES.output} output: the manifest, a path outside the output, or a failed write\n ${EXIT_CODES.interrupted} interrupted (Ctrl-C)`;\n\n/**\n * What the `fetcher-generator` bin prints to stderr before it runs: the name\n * still works, and goes in v10.\n */\nexport const DEPRECATED_BIN_NOTICE =\n 'fetcher-generator is deprecated and will be removed in v10; run wow-generator instead.';\n\n/** Collects the values of an option given more than once, such as `--header`. */\nexport function collect(value: string, previous: string[] = []): string[] {\n return [...previous, value];\n}\n\n/**\n * Sets up the CLI program with all commands and options.\n *\n * Commander does not exit the process: a usage error (a missing required\n * option, an unknown option or command, a missing argument, no command at\n * all) is thrown as a `CommanderError`, which {@link runCLI} maps to an exit\n * code.\n *\n * @param target - The program to set up; commander's global one by default.\n * Settings made on it before this call, such as `configureOutput`, reach the\n * `generate` command too.\n * @returns The configured commander program instance\n */\nexport function setupCLI(target: Command = program): Command {\n // Before `command()`: a subcommand copies the exit override when it is\n // created.\n target.exitOverride();\n // compat(fetcher): package.json also installs this CLI as `fetcher-generator`\n // (src/fetcherGeneratorCli.ts), the name existing scripts call; drop that\n // bin alias in v10.\n target\n .name('wow-generator')\n .description('OpenAPI Specification TypeScript code generator for Wow')\n .version(VERSION, '-v, --version');\n\n target\n .command('generate')\n .description(\n 'Generate TypeScript code from an OpenAPI specification or a Wow V10 Manifest',\n )\n .requiredOption(\n '-i, --input <file>',\n 'Input OpenAPI specification or Wow Manifest (GET /wow/manifest) file path or URL (http/https)',\n )\n .option('-o, --output <path>', 'Output directory path', 'src/generated')\n // No commander default: an omitted -c falls back to DEFAULT_CONFIG_PATH,\n // which may be absent, while a path the user named has to exist.\n .option(\n '-c, --config <file>',\n `Configuration file path (default: ${DEFAULT_CONFIG_PATH})`,\n )\n .option(\n '-t, --ts-config-file-path <file>',\n 'TypeScript configuration file path',\n )\n .option(\n '-H, --header <header>',\n 'Request header for an http(s) input or configuration, as \"Name: value\"; repeatable',\n collect,\n )\n .option(\n '--timeout <ms>',\n `Milliseconds before fetching an http(s) input is abandoned (default: ${DEFAULT_HTTP_TIMEOUT_MS})`,\n )\n .option(\n '--schema-docs <mode>',\n 'What model doc comments carry: \"summary\" (title, description, constraints) or \"full\" (also the JSON schema)',\n 'summary',\n )\n .option('--strict', 'Exit with code 4 when the run logs a warning')\n .option('--verbose', 'Log every step, and the stack trace of a failure')\n .option('--quiet', 'Log only warnings and errors')\n .addHelpText('after', EXIT_CODE_HELP)\n .action(generateAction);\n\n return target;\n}\n\n/**\n * The exit code of a command line commander stopped at: 0 for `--help`,\n * `help` and `--version`; {@link EXIT_CODES.input} for a usage error, which\n * commander has already reported. A usage error is an invalid command line,\n * the same category as an invalid option value such as `--timeout abc`.\n */\nexport function commanderExitCode(error: CommanderError): number {\n return error.exitCode === 0 ? EXIT_CODES.success : EXIT_CODES.input;\n}\n\n/**\n * Parses the command line and runs the command it names. The `generate`\n * command sets the process exit code itself; a command line commander stops\n * at sets it to {@link commanderExitCode}.\n *\n * @param args - The arguments after the executable and script;\n * `process.argv` by default\n * @param target - The program to run; {@link setupCLI} on commander's global\n * one by default\n */\nexport async function runCLI(\n args?: readonly string[],\n target: Command = setupCLI(),\n): Promise<void> {\n try {\n if (args === undefined) {\n await target.parseAsync();\n } else {\n await target.parseAsync(args, { from: 'user' });\n }\n } catch (error) {\n if (!(error instanceof CommanderError)) throw error;\n process.exitCode = commanderExitCode(error);\n }\n}\n"],"mappings":";;;;AAmBA,IAAaM,IAAA;;;ACmCb,SAAgBC,EAAc,GAAwB;CACpD,IAAI,CAACC,GAAO,OA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W;AAChE;AAYA,eAAsB4C,EACpB,GACA,IAAkBJ,EAAS,GACZ;CACf,IAAI;EACF,AAAIK,MAAS,KAAA,IACX,MAAMH,EAAO,WAAW,IAExB,MAAMA,EAAO,WAAWG,GAAM,EAAE,MAAM,OAAO,CAAC;CAElD,SAASvB,GAAO;EACd,IAAI,EAAEA,aAAiBwB,IAAiB,MAAMxB;EAC9C,QAAQ,WAAWqB,EAAkBrB,CAAK;CAC5C;AACF"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { OpenAPI, Tag } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
-
import { AggregateDefinition, TagAliasAggregate } from './model.cjs';
|
|
3
|
-
/** The oldest Wow server whose OpenAPI metadata the generator reads fully. */
|
|
4
|
-
export declare const MINIMUM_WOW_VERSION = "8.10";
|
|
5
|
-
/** The `info` extension naming the bounded context the document serves. */
|
|
6
|
-
export declare const CONTEXT_ALIAS_EXTENSION = "x-wow-context-alias";
|
|
7
|
-
/** The bounded context a document names, if it is a Wow service's. */
|
|
8
|
-
export declare function contextAliasOf(openAPI: OpenAPI): string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Reads an aggregate off a tag named `<contextAlias>.<aggregateName>`.
|
|
11
|
-
*
|
|
12
|
-
* @param tagName - The tag name
|
|
13
|
-
* @returns `[contextAlias, aggregateName]`, or null when the tag names no aggregate
|
|
14
|
-
*/
|
|
15
|
-
export declare function isAliasAggregate(tagName: string): [string, string] | null;
|
|
16
|
-
/**
|
|
17
|
-
* The aggregate a tag names, or null when it names none.
|
|
18
|
-
*
|
|
19
|
-
* @param tag - The tag
|
|
20
|
-
*/
|
|
21
|
-
export declare function tagToAggregate(tag: Tag): TagAliasAggregate | null;
|
|
22
|
-
/**
|
|
23
|
-
* The command an operation sends, read off its id
|
|
24
|
-
* `<contextAlias>.<aggregateName>.<command>`.
|
|
25
|
-
*
|
|
26
|
-
* @param operationId - The operation id
|
|
27
|
-
* @returns The command name, or null when the id has another shape
|
|
28
|
-
*/
|
|
29
|
-
export declare function operationIdToCommandName(operationId?: string): string | null;
|
|
30
|
-
/** The operation that sends any command; it belongs to no aggregate. */
|
|
31
|
-
export declare const SEND_COMMAND_OPERATION_ID = "wow.command.send";
|
|
32
|
-
/** The response every command operation answers with. */
|
|
33
|
-
export declare const COMMAND_OK_RESPONSE_REF = "#/components/responses/wow.CommandOk";
|
|
34
|
-
/** The operation id suffix of the operation that loads an aggregate's state. */
|
|
35
|
-
export declare const STATE_OPERATION_SUFFIX = ".snapshot_state.single";
|
|
36
|
-
/** The operation id suffix of the operation that lists an aggregate's events. */
|
|
37
|
-
export declare const EVENTS_OPERATION_SUFFIX = ".event.list_query";
|
|
38
|
-
/** The operation id suffix of the operation that counts snapshots by a condition. */
|
|
39
|
-
export declare const FIELDS_OPERATION_SUFFIX = ".snapshot.count";
|
|
40
|
-
/** The request body extension naming an aggregate's query fields (Wow 8.11.1+). */
|
|
41
|
-
export declare const QUERY_FIELDS_EXTENSION = "x-wow-query-fields";
|
|
42
|
-
/**
|
|
43
|
-
* The route segment of an aggregate, read off one of its snapshot routes:
|
|
44
|
-
* `/tenant/{tenantId}/owner/{ownerId}/sales-order/snapshot/count` →
|
|
45
|
-
* `sales-order`. It differs from the aggregate name when the aggregate sets
|
|
46
|
-
* a resource name (`@AggregateRoute(resourceName = "sales-order")`).
|
|
47
|
-
*/
|
|
48
|
-
export declare const SNAPSHOT_ROUTE: RegExp;
|
|
49
|
-
/**
|
|
50
|
-
* The suffixes of the types Wow derives from an aggregate's state; the
|
|
51
|
-
* wow-client generics stand for them, so they generate no model.
|
|
52
|
-
*/
|
|
53
|
-
export declare const AGGREGATED_SCHEMA_SUFFIXES: readonly string[];
|
|
54
|
-
/**
|
|
55
|
-
* The names of the types Wow derives from an aggregate's state model.
|
|
56
|
-
*
|
|
57
|
-
* @param stateName - The name of the state model
|
|
58
|
-
*/
|
|
59
|
-
export declare function aggregatedTypeNames(stateName: string): string[];
|
|
60
|
-
/**
|
|
61
|
-
* Tells whether a schema is Wow's own, which wow-client already declares, so
|
|
62
|
-
* it generates no model: every `wow.` schema but the paged lists and operator
|
|
63
|
-
* maps of the query API, the aggregated query and event stream types, and
|
|
64
|
-
* the types derived from an aggregate's state.
|
|
65
|
-
*
|
|
66
|
-
* @param schemaKey - The schema's component key
|
|
67
|
-
* @param modelName - The name of the model the schema would generate, read
|
|
68
|
-
* only when the key alone does not decide
|
|
69
|
-
* @param aggregatedNames - The names of the types derived from the aggregates' states
|
|
70
|
-
*/
|
|
71
|
-
export declare function isWowSchema(schemaKey: string, modelName: () => string, aggregatedNames: ReadonlySet<string>): boolean;
|
|
72
|
-
/** Import path for the WOW framework types */
|
|
73
|
-
export declare const IMPORT_WOW_PATH = "@ahoo-wang/wow-client";
|
|
74
|
-
/**
|
|
75
|
-
* Import path for the deprecated Condition query model, which
|
|
76
|
-
* `@ahoo-wang/wow-client` keeps on its `/legacy` subpath for Wow 8.10 servers.
|
|
77
|
-
*/
|
|
78
|
-
export declare const IMPORT_WOW_LEGACY_PATH = "@ahoo-wang/wow-client/legacy";
|
|
79
|
-
/** The mapped type names that `IMPORT_WOW_LEGACY_PATH` exports. */
|
|
80
|
-
export declare const WOW_LEGACY_TYPES: ReadonlySet<string>;
|
|
81
|
-
/** Mapping of OpenAPI schema keys to WOW framework types */
|
|
82
|
-
export declare const WOW_TYPE_MAPPING: {
|
|
83
|
-
'wow.command.CommandResult': string;
|
|
84
|
-
'wow.command.CommandResultArray': string;
|
|
85
|
-
'wow.MessageHeaderSqlType': string;
|
|
86
|
-
'wow.api.BindingError': string;
|
|
87
|
-
'wow.api.DefaultErrorInfo': string;
|
|
88
|
-
'wow.api.RecoverableType': string;
|
|
89
|
-
'wow.api.command.DefaultDeleteAggregate': string;
|
|
90
|
-
'wow.api.command.DefaultRecoverAggregate': string;
|
|
91
|
-
'wow.api.abac.DefaultApplyResourceTags': string;
|
|
92
|
-
'wow.api.messaging.FunctionInfoData': string;
|
|
93
|
-
'wow.api.messaging.FunctionKind': string;
|
|
94
|
-
'wow.api.modeling.AggregateId': string;
|
|
95
|
-
'wow.api.query.Condition': string;
|
|
96
|
-
'wow.api.query.ConditionOptions': string;
|
|
97
|
-
'wow.api.query.ListQuery': string;
|
|
98
|
-
'wow.api.query.Operator': string;
|
|
99
|
-
'wow.api.query.PagedQuery': string;
|
|
100
|
-
'wow.api.query.Pagination': string;
|
|
101
|
-
'wow.api.query.Projection': string;
|
|
102
|
-
'wow.api.query.Sort': string;
|
|
103
|
-
'wow.api.query.Sort.Direction': string;
|
|
104
|
-
'wow.api.query.DynamicDocument': string;
|
|
105
|
-
'wow.api.query.DynamicDocumentArray': string;
|
|
106
|
-
'wow.command.CommandStage': string;
|
|
107
|
-
'wow.command.SimpleWaitSignal': string;
|
|
108
|
-
'wow.configuration.Aggregate': string;
|
|
109
|
-
'wow.configuration.BoundedContext': string;
|
|
110
|
-
'wow.configuration.WowMetadata': string;
|
|
111
|
-
'wow.modeling.DomainEvent': string;
|
|
112
|
-
'wow.openapi.BatchResult': string;
|
|
113
|
-
'wow.messaging.CompensationTarget': string;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* The wow-client type a schema maps to, and the module that exports it.
|
|
117
|
-
*
|
|
118
|
-
* @param schemaKey - The schema's component key
|
|
119
|
-
* @param properties - The schema's properties, if the caller has the schema:
|
|
120
|
-
* a ListQuery or PagedQuery that carries `filter` is the filter model's
|
|
121
|
-
* @returns The type, or undefined when the schema is not one of Wow's own
|
|
122
|
-
*/
|
|
123
|
-
export declare function wowTypeOf(schemaKey: string, properties?: Record<string, unknown>): {
|
|
124
|
-
name: string;
|
|
125
|
-
path: string;
|
|
126
|
-
} | undefined;
|
|
127
|
-
/**
|
|
128
|
-
* Tags whose operations generate no API client: Wow's own endpoints and
|
|
129
|
-
* Spring's actuator. The tags of aggregates are left out as well; their
|
|
130
|
-
* operations go to the command and query clients.
|
|
131
|
-
*/
|
|
132
|
-
export declare const IGNORED_API_CLIENT_TAGS: ReadonlySet<string>;
|
|
133
|
-
/**
|
|
134
|
-
* The resource-attribution path parameters Wow's CoSec interceptor fills,
|
|
135
|
-
* which generated clients therefore leave out.
|
|
136
|
-
*/
|
|
137
|
-
export declare const RESOURCE_ATTRIBUTION_PATH_PARAMETERS: readonly string[];
|
|
138
|
-
/** The route prefix of a tenant's resources (wow-client `ResourceAttributionPathSpec.TENANT`). */
|
|
139
|
-
export declare const TENANT_PATH_PREFIX = "/tenant/{tenantId}";
|
|
140
|
-
/** The route prefix of an owner's resources (wow-client `ResourceAttributionPathSpec.OWNER`). */
|
|
141
|
-
export declare const OWNER_PATH_PREFIX = "/owner/{ownerId}";
|
|
142
|
-
/**
|
|
143
|
-
* The resource attribution a query client of an aggregate uses, as the
|
|
144
|
-
* `ResourceAttributionPathSpec` member it generates: the prefix most of the
|
|
145
|
-
* aggregate's command routes start with, owner on a tie, none when no route
|
|
146
|
-
* starts with either.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* // commands at /tenant/{tenantId}/users, /tenant/{tenantId}/orders and /owner/{ownerId}/profile
|
|
151
|
-
* inferPathSpecType(aggregate); // 'ResourceAttributionPathSpec.TENANT'
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export declare function inferPathSpecType(aggregateDefinition: Pick<AggregateDefinition, 'commands'>): string;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { OpenAPI, Tag } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
-
import { AggregateDefinition, TagAliasAggregate } from './model.js';
|
|
3
|
-
/** The oldest Wow server whose OpenAPI metadata the generator reads fully. */
|
|
4
|
-
export declare const MINIMUM_WOW_VERSION = "8.10";
|
|
5
|
-
/** The `info` extension naming the bounded context the document serves. */
|
|
6
|
-
export declare const CONTEXT_ALIAS_EXTENSION = "x-wow-context-alias";
|
|
7
|
-
/** The bounded context a document names, if it is a Wow service's. */
|
|
8
|
-
export declare function contextAliasOf(openAPI: OpenAPI): string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Reads an aggregate off a tag named `<contextAlias>.<aggregateName>`.
|
|
11
|
-
*
|
|
12
|
-
* @param tagName - The tag name
|
|
13
|
-
* @returns `[contextAlias, aggregateName]`, or null when the tag names no aggregate
|
|
14
|
-
*/
|
|
15
|
-
export declare function isAliasAggregate(tagName: string): [string, string] | null;
|
|
16
|
-
/**
|
|
17
|
-
* The aggregate a tag names, or null when it names none.
|
|
18
|
-
*
|
|
19
|
-
* @param tag - The tag
|
|
20
|
-
*/
|
|
21
|
-
export declare function tagToAggregate(tag: Tag): TagAliasAggregate | null;
|
|
22
|
-
/**
|
|
23
|
-
* The command an operation sends, read off its id
|
|
24
|
-
* `<contextAlias>.<aggregateName>.<command>`.
|
|
25
|
-
*
|
|
26
|
-
* @param operationId - The operation id
|
|
27
|
-
* @returns The command name, or null when the id has another shape
|
|
28
|
-
*/
|
|
29
|
-
export declare function operationIdToCommandName(operationId?: string): string | null;
|
|
30
|
-
/** The operation that sends any command; it belongs to no aggregate. */
|
|
31
|
-
export declare const SEND_COMMAND_OPERATION_ID = "wow.command.send";
|
|
32
|
-
/** The response every command operation answers with. */
|
|
33
|
-
export declare const COMMAND_OK_RESPONSE_REF = "#/components/responses/wow.CommandOk";
|
|
34
|
-
/** The operation id suffix of the operation that loads an aggregate's state. */
|
|
35
|
-
export declare const STATE_OPERATION_SUFFIX = ".snapshot_state.single";
|
|
36
|
-
/** The operation id suffix of the operation that lists an aggregate's events. */
|
|
37
|
-
export declare const EVENTS_OPERATION_SUFFIX = ".event.list_query";
|
|
38
|
-
/** The operation id suffix of the operation that counts snapshots by a condition. */
|
|
39
|
-
export declare const FIELDS_OPERATION_SUFFIX = ".snapshot.count";
|
|
40
|
-
/** The request body extension naming an aggregate's query fields (Wow 8.11.1+). */
|
|
41
|
-
export declare const QUERY_FIELDS_EXTENSION = "x-wow-query-fields";
|
|
42
|
-
/**
|
|
43
|
-
* The route segment of an aggregate, read off one of its snapshot routes:
|
|
44
|
-
* `/tenant/{tenantId}/owner/{ownerId}/sales-order/snapshot/count` →
|
|
45
|
-
* `sales-order`. It differs from the aggregate name when the aggregate sets
|
|
46
|
-
* a resource name (`@AggregateRoute(resourceName = "sales-order")`).
|
|
47
|
-
*/
|
|
48
|
-
export declare const SNAPSHOT_ROUTE: RegExp;
|
|
49
|
-
/**
|
|
50
|
-
* The suffixes of the types Wow derives from an aggregate's state; the
|
|
51
|
-
* wow-client generics stand for them, so they generate no model.
|
|
52
|
-
*/
|
|
53
|
-
export declare const AGGREGATED_SCHEMA_SUFFIXES: readonly string[];
|
|
54
|
-
/**
|
|
55
|
-
* The names of the types Wow derives from an aggregate's state model.
|
|
56
|
-
*
|
|
57
|
-
* @param stateName - The name of the state model
|
|
58
|
-
*/
|
|
59
|
-
export declare function aggregatedTypeNames(stateName: string): string[];
|
|
60
|
-
/**
|
|
61
|
-
* Tells whether a schema is Wow's own, which wow-client already declares, so
|
|
62
|
-
* it generates no model: every `wow.` schema but the paged lists and operator
|
|
63
|
-
* maps of the query API, the aggregated query and event stream types, and
|
|
64
|
-
* the types derived from an aggregate's state.
|
|
65
|
-
*
|
|
66
|
-
* @param schemaKey - The schema's component key
|
|
67
|
-
* @param modelName - The name of the model the schema would generate, read
|
|
68
|
-
* only when the key alone does not decide
|
|
69
|
-
* @param aggregatedNames - The names of the types derived from the aggregates' states
|
|
70
|
-
*/
|
|
71
|
-
export declare function isWowSchema(schemaKey: string, modelName: () => string, aggregatedNames: ReadonlySet<string>): boolean;
|
|
72
|
-
/** Import path for the WOW framework types */
|
|
73
|
-
export declare const IMPORT_WOW_PATH = "@ahoo-wang/wow-client";
|
|
74
|
-
/**
|
|
75
|
-
* Import path for the deprecated Condition query model, which
|
|
76
|
-
* `@ahoo-wang/wow-client` keeps on its `/legacy` subpath for Wow 8.10 servers.
|
|
77
|
-
*/
|
|
78
|
-
export declare const IMPORT_WOW_LEGACY_PATH = "@ahoo-wang/wow-client/legacy";
|
|
79
|
-
/** The mapped type names that `IMPORT_WOW_LEGACY_PATH` exports. */
|
|
80
|
-
export declare const WOW_LEGACY_TYPES: ReadonlySet<string>;
|
|
81
|
-
/** Mapping of OpenAPI schema keys to WOW framework types */
|
|
82
|
-
export declare const WOW_TYPE_MAPPING: {
|
|
83
|
-
'wow.command.CommandResult': string;
|
|
84
|
-
'wow.command.CommandResultArray': string;
|
|
85
|
-
'wow.MessageHeaderSqlType': string;
|
|
86
|
-
'wow.api.BindingError': string;
|
|
87
|
-
'wow.api.DefaultErrorInfo': string;
|
|
88
|
-
'wow.api.RecoverableType': string;
|
|
89
|
-
'wow.api.command.DefaultDeleteAggregate': string;
|
|
90
|
-
'wow.api.command.DefaultRecoverAggregate': string;
|
|
91
|
-
'wow.api.abac.DefaultApplyResourceTags': string;
|
|
92
|
-
'wow.api.messaging.FunctionInfoData': string;
|
|
93
|
-
'wow.api.messaging.FunctionKind': string;
|
|
94
|
-
'wow.api.modeling.AggregateId': string;
|
|
95
|
-
'wow.api.query.Condition': string;
|
|
96
|
-
'wow.api.query.ConditionOptions': string;
|
|
97
|
-
'wow.api.query.ListQuery': string;
|
|
98
|
-
'wow.api.query.Operator': string;
|
|
99
|
-
'wow.api.query.PagedQuery': string;
|
|
100
|
-
'wow.api.query.Pagination': string;
|
|
101
|
-
'wow.api.query.Projection': string;
|
|
102
|
-
'wow.api.query.Sort': string;
|
|
103
|
-
'wow.api.query.Sort.Direction': string;
|
|
104
|
-
'wow.api.query.DynamicDocument': string;
|
|
105
|
-
'wow.api.query.DynamicDocumentArray': string;
|
|
106
|
-
'wow.command.CommandStage': string;
|
|
107
|
-
'wow.command.SimpleWaitSignal': string;
|
|
108
|
-
'wow.configuration.Aggregate': string;
|
|
109
|
-
'wow.configuration.BoundedContext': string;
|
|
110
|
-
'wow.configuration.WowMetadata': string;
|
|
111
|
-
'wow.modeling.DomainEvent': string;
|
|
112
|
-
'wow.openapi.BatchResult': string;
|
|
113
|
-
'wow.messaging.CompensationTarget': string;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* The wow-client type a schema maps to, and the module that exports it.
|
|
117
|
-
*
|
|
118
|
-
* @param schemaKey - The schema's component key
|
|
119
|
-
* @param properties - The schema's properties, if the caller has the schema:
|
|
120
|
-
* a ListQuery or PagedQuery that carries `filter` is the filter model's
|
|
121
|
-
* @returns The type, or undefined when the schema is not one of Wow's own
|
|
122
|
-
*/
|
|
123
|
-
export declare function wowTypeOf(schemaKey: string, properties?: Record<string, unknown>): {
|
|
124
|
-
name: string;
|
|
125
|
-
path: string;
|
|
126
|
-
} | undefined;
|
|
127
|
-
/**
|
|
128
|
-
* Tags whose operations generate no API client: Wow's own endpoints and
|
|
129
|
-
* Spring's actuator. The tags of aggregates are left out as well; their
|
|
130
|
-
* operations go to the command and query clients.
|
|
131
|
-
*/
|
|
132
|
-
export declare const IGNORED_API_CLIENT_TAGS: ReadonlySet<string>;
|
|
133
|
-
/**
|
|
134
|
-
* The resource-attribution path parameters Wow's CoSec interceptor fills,
|
|
135
|
-
* which generated clients therefore leave out.
|
|
136
|
-
*/
|
|
137
|
-
export declare const RESOURCE_ATTRIBUTION_PATH_PARAMETERS: readonly string[];
|
|
138
|
-
/** The route prefix of a tenant's resources (wow-client `ResourceAttributionPathSpec.TENANT`). */
|
|
139
|
-
export declare const TENANT_PATH_PREFIX = "/tenant/{tenantId}";
|
|
140
|
-
/** The route prefix of an owner's resources (wow-client `ResourceAttributionPathSpec.OWNER`). */
|
|
141
|
-
export declare const OWNER_PATH_PREFIX = "/owner/{ownerId}";
|
|
142
|
-
/**
|
|
143
|
-
* The resource attribution a query client of an aggregate uses, as the
|
|
144
|
-
* `ResourceAttributionPathSpec` member it generates: the prefix most of the
|
|
145
|
-
* aggregate's command routes start with, owner on a tie, none when no route
|
|
146
|
-
* starts with either.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* // commands at /tenant/{tenantId}/users, /tenant/{tenantId}/orders and /owner/{ownerId}/profile
|
|
151
|
-
* inferPathSpecType(aggregate); // 'ResourceAttributionPathSpec.TENANT'
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export declare function inferPathSpecType(aggregateDefinition: Pick<AggregateDefinition, 'commands'>): string;
|