@haddowg/json-api-codegen 1.6.0 → 1.6.1
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/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{index-CU-kUx70.d.mts → index-CjNGhJJH.d.mts} +11 -2
- package/dist/{index-CU-kUx70.d.mts.map → index-CjNGhJJH.d.mts.map} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-C2INS1Wd.mjs → src-CKsM7dXw.mjs} +186 -44
- package/dist/src-CKsM7dXw.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/src-C2INS1Wd.mjs.map +0 -1
package/dist/cli.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CodegenConfig } from "./index-
|
|
1
|
+
import { r as CodegenConfig } from "./index-CjNGhJJH.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/cli.d.ts
|
|
4
4
|
declare const USAGE = "Usage: json-api-codegen --input <url|file> --output <file> [--server <name>] [--schemas <url|file>] [--check]";
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as generate, r as schemasOutputPath, t as check } from "./src-
|
|
2
|
+
import { n as generate, r as schemasOutputPath, t as check } from "./src-CKsM7dXw.mjs";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
//#region src/cli.ts
|
|
@@ -295,6 +295,10 @@ declare class Emitter {
|
|
|
295
295
|
* already-named attribute type. Populated as interfaces are emitted.
|
|
296
296
|
*/
|
|
297
297
|
private readonly emittedInterfaces;
|
|
298
|
+
/** Enum component name -> the alias name it's emitted under. */
|
|
299
|
+
private readonly enumNames;
|
|
300
|
+
/** Type names already spoken for: the module's own, the per-type interfaces and enum aliases. */
|
|
301
|
+
private readonly takenNames;
|
|
298
302
|
/** Component names mid-expansion in {@link tsType} — a cycle guard for self/mutually-referential `$ref`s. */
|
|
299
303
|
private readonly expanding;
|
|
300
304
|
/**
|
|
@@ -307,6 +311,11 @@ declare class Emitter {
|
|
|
307
311
|
private readonly provenance;
|
|
308
312
|
private readonly doc;
|
|
309
313
|
constructor(source: OpenApiDocument, descriptor: ApiDescriptor, atomic: AtomicDescriptor | null);
|
|
314
|
+
/**
|
|
315
|
+
* The alias an enum component is emitted under: its own name when that's a usable type name,
|
|
316
|
+
* else one derived from it (with a warning), kept clear of every other name in the module.
|
|
317
|
+
*/
|
|
318
|
+
private enumName;
|
|
310
319
|
/** Map each declared wire type back to the `Base` of its resource schema. */
|
|
311
320
|
private indexBases;
|
|
312
321
|
emit(): string;
|
|
@@ -502,7 +511,7 @@ declare function hashJson(value: unknown): string;
|
|
|
502
511
|
declare function deriveProvenance(doc: OpenApiDocument): Provenance;
|
|
503
512
|
/**
|
|
504
513
|
* Render the provenance record as the JSDoc header lines stamped into a generated artifact
|
|
505
|
-
* (each already prefixed with ` * `). Deterministic: no timestamp, so re-generating from the
|
|
514
|
+
* (each already prefixed with ` * `), with the document's text kept to one comment line. Deterministic: no timestamp, so re-generating from the
|
|
506
515
|
* same spec yields byte-identical output.
|
|
507
516
|
*/
|
|
508
517
|
declare function provenanceLines(provenance: Provenance): string[];
|
|
@@ -565,4 +574,4 @@ declare function generate(config: CodegenConfig): Promise<string>;
|
|
|
565
574
|
declare function check(config: CodegenConfig): Promise<CheckResult>;
|
|
566
575
|
//#endregion
|
|
567
576
|
export { InfoObject as A, MAXIMUM_CONTRACT as C, buildAtomic as D, DescriptorBuilder as E, PathItemObject as F, RequestBodyObject as I, ResponseObject as L, OpenApiDocument as M, OperationObject as N, buildDescriptor as O, ParameterObject as P, SchemaObject as R, emit as S, checkContract as T, emitErrorCodes as _, generate as a, VerbCollision as b, deriveProvenance as c, emitSchemas as d, SchemaBundle as f, ErrorCatalogue as g, DocumentedErrorCode as h, check as i, MediaTypeObject as j, HttpMethod as k, hashJson as l, readSchemas as m, CheckResult as n, schemasOutputPath as o, readDocument as p, CodegenConfig as r, Provenance as s, ArtifactDrift as t, provenanceLines as u, readErrorCatalogue as v, MINIMUM_CONTRACT as w, detectVerbCollisions as x, Emitter as y, SchemaOrBool as z };
|
|
568
|
-
//# sourceMappingURL=index-
|
|
577
|
+
//# sourceMappingURL=index-CjNGhJJH.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-CjNGhJJH.d.mts","names":[],"sources":["../src/openapi.ts","../src/build-descriptor.ts","../src/contract.ts","../src/emit.ts","../src/error-codes.ts","../src/reader.ts","../src/emit-schemas.ts","../src/provenance.ts","../src/index.ts"],"mappings":";;;;;;AAQA;;;;UAAiB,YAAA;EACf,IAAA;EACA,IAAA;EACA,KAAA;EACA,MAAA;EACA,WAAA;EACA,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,YAAA;EAC5B,KAAA,GAAQ,YAAA;EACR,QAAA;EACA,KAAA,YAAiB,YAAA;EACjB,KAAA,YAAiB,YAAA;EACjB,KAAA,YAAiB,YAAA;EACjB,iBAAA;EACA,qBAAA;EAAA,CACC,GAAA;AAAA;;KAIS,YAAA,GAAe,YAAY;AAAA,UAEtB,eAAA;EACf,MAAA,GAAS,YAAY;AAAA;AAAA,UAGN,iBAAA;EACf,OAAA,GAAU,MAAM,SAAS,eAAA;EACzB,QAAA;AAAA;AAAA,UAGe,cAAA;EACf,OAAA,GAAU,MAAM,SAAS,eAAA;AAAA;AAAA,UAGV,eAAA;EACf,IAAA;EACA,EAAA;EACA,IAAA;EACA,MAAA,GAAS,YAAY;EACrB,KAAA;EACA,OAAA;EAnB8B;EAqB9B,WAAA;AAAA;AAAA,UAGe,eAAA;EACf,WAAA;EACA,UAAA,YAAsB,eAAA;EACtB,WAAA,GAAc,iBAAA;EACd,SAAA,GAAY,MAAA,SAAe,cAAA;AAAA;AAAA,KAGjB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D;;;;UOEiB,UAAA;EPMP;EAAA,SOJC,MAAA;EPOQ;EAAA,SOLR,MAAA;EPMoB;EAAA,SOJpB,IAAA;AAAA;;iBAwBK,QAAA,CAAS,KAAc;;;;;;iBAYvB,gBAAA,CAAiB,GAAA,EAAK,eAAA,GAAkB,UAAU;;;;;;iBAelD,eAAA,CAAgB,UAAsB,EAAV,UAAU;;;UCjCrC,aAAA;ERjBf;EQmBA,KAAA;ERlBiB;EQoBjB,MAAA;ERnBiB;EQqBjB,MAAA;ERpBiB;EQsBjB,OAAA;ERpBA;;;AACY;AAId;EQqBE,KAAA;AAAA;;UAIe,aAAA;ERvBA;EQyBf,IAAA;;EAEA,QAAQ;AAAA;ARvBV;AAAA,UQ2BiB,WAAA;EACf,EAAA;EACA,SAAA,EAAW,aAAa;AAAA;;;;;iBAOV,iBAAA,CAAkB,MAAc;AR/BhD;;;;;;;;AAC0C;AAG1C;;;;;AAJA,iBQmGsB,QAAA,CAAS,MAAA,EAAQ,aAAA,GAAgB,OAAO;;;;;;;iBAgBxC,KAAA,CAAM,MAAA,EAAQ,aAAA,GAAgB,OAAA,CAAQ,WAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as InfoObject, C as MAXIMUM_CONTRACT, D as buildAtomic, E as DescriptorBuilder, F as PathItemObject, I as RequestBodyObject, L as ResponseObject, M as OpenApiDocument, N as OperationObject, O as buildDescriptor, P as ParameterObject, R as SchemaObject, S as emit, T as checkContract, _ as emitErrorCodes, a as generate, b as VerbCollision, c as deriveProvenance, d as emitSchemas, f as SchemaBundle, g as ErrorCatalogue, h as DocumentedErrorCode, i as check, j as MediaTypeObject, k as HttpMethod, l as hashJson, m as readSchemas, n as CheckResult, o as schemasOutputPath, p as readDocument, r as CodegenConfig, s as Provenance, t as ArtifactDrift, u as provenanceLines, v as readErrorCatalogue, w as MINIMUM_CONTRACT, x as detectVerbCollisions, y as Emitter, z as SchemaOrBool } from "./index-
|
|
1
|
+
import { A as InfoObject, C as MAXIMUM_CONTRACT, D as buildAtomic, E as DescriptorBuilder, F as PathItemObject, I as RequestBodyObject, L as ResponseObject, M as OpenApiDocument, N as OperationObject, O as buildDescriptor, P as ParameterObject, R as SchemaObject, S as emit, T as checkContract, _ as emitErrorCodes, a as generate, b as VerbCollision, c as deriveProvenance, d as emitSchemas, f as SchemaBundle, g as ErrorCatalogue, h as DocumentedErrorCode, i as check, j as MediaTypeObject, k as HttpMethod, l as hashJson, m as readSchemas, n as CheckResult, o as schemasOutputPath, p as readDocument, r as CodegenConfig, s as Provenance, t as ArtifactDrift, u as provenanceLines, v as readErrorCatalogue, w as MINIMUM_CONTRACT, x as detectVerbCollisions, y as Emitter, z as SchemaOrBool } from "./index-CjNGhJJH.mjs";
|
|
2
2
|
export { ArtifactDrift, CheckResult, CodegenConfig, DescriptorBuilder, type DocumentedErrorCode, Emitter, type ErrorCatalogue, type HttpMethod, type InfoObject, MAXIMUM_CONTRACT, MINIMUM_CONTRACT, type MediaTypeObject, type OpenApiDocument, type OperationObject, type ParameterObject, type PathItemObject, type Provenance, type RequestBodyObject, type ResponseObject, type SchemaBundle, type SchemaObject, type SchemaOrBool, type VerbCollision, buildAtomic, buildDescriptor, check, checkContract, deriveProvenance, detectVerbCollisions, emit, emitErrorCodes, emitSchemas, generate, hashJson, provenanceLines, readDocument, readErrorCatalogue, readSchemas, schemasOutputPath };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as checkContract, a as readSchemas, b as buildDescriptor, c as detectVerbCollisions, d as hashJson, f as provenanceLines, g as MINIMUM_CONTRACT, h as MAXIMUM_CONTRACT, i as readDocument, l as emit, m as readErrorCatalogue, n as generate, o as emitSchemas, p as emitErrorCodes, r as schemasOutputPath, s as Emitter, t as check, u as deriveProvenance, v as DescriptorBuilder, y as buildAtomic } from "./src-
|
|
1
|
+
import { _ as checkContract, a as readSchemas, b as buildDescriptor, c as detectVerbCollisions, d as hashJson, f as provenanceLines, g as MINIMUM_CONTRACT, h as MAXIMUM_CONTRACT, i as readDocument, l as emit, m as readErrorCatalogue, n as generate, o as emitSchemas, p as emitErrorCodes, r as schemasOutputPath, s as Emitter, t as check, u as deriveProvenance, v as DescriptorBuilder, y as buildAtomic } from "./src-CKsM7dXw.mjs";
|
|
2
2
|
export { DescriptorBuilder, Emitter, MAXIMUM_CONTRACT, MINIMUM_CONTRACT, buildAtomic, buildDescriptor, check, checkContract, deriveProvenance, detectVerbCollisions, emit, emitErrorCodes, emitSchemas, generate, hashJson, provenanceLines, readDocument, readErrorCatalogue, readSchemas, schemasOutputPath };
|
|
@@ -919,6 +919,106 @@ function checkContract(doc) {
|
|
|
919
919
|
if (contract > 9) return `the document declares contract ${contract} and this codegen reads up to 9. It describes capabilities that were not generated; upgrade the codegen to pick them up.`;
|
|
920
920
|
}
|
|
921
921
|
//#endregion
|
|
922
|
+
//#region src/source.ts
|
|
923
|
+
/**
|
|
924
|
+
* Helpers for writing strings read from the OpenAPI document into generated TypeScript. Every
|
|
925
|
+
* name, literal and comment the emitters take from the document goes through one of these.
|
|
926
|
+
*/
|
|
927
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
928
|
+
/** Line terminators as JavaScript counts them. */
|
|
929
|
+
const LINE_BREAK = /\r\n|[\n\r\u2028\u2029]/;
|
|
930
|
+
/** A string as a TS string literal. U+2028/U+2029 are escaped too, which JSON leaves raw. */
|
|
931
|
+
function stringLiteral(value) {
|
|
932
|
+
return JSON.stringify(value).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
933
|
+
}
|
|
934
|
+
/** True when a string is a bare identifier. */
|
|
935
|
+
function isIdentifier(value) {
|
|
936
|
+
return IDENTIFIER.test(value);
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* A property key for an object literal or an interface: bare when it's an identifier, quoted
|
|
940
|
+
* otherwise. `__proto__` is written as a computed key, which a runtime literal keeps as an own
|
|
941
|
+
* property instead of setting the prototype.
|
|
942
|
+
*/
|
|
943
|
+
function propertyKey(name) {
|
|
944
|
+
if (name === "__proto__") return `[${stringLiteral(name)}]`;
|
|
945
|
+
return isIdentifier(name) ? name : stringLiteral(name);
|
|
946
|
+
}
|
|
947
|
+
/** Text that can sit inside a block comment: any `*\/` is broken up so it can't close it. */
|
|
948
|
+
function commentText(text) {
|
|
949
|
+
return text.replace(/\*\//g, "* /");
|
|
950
|
+
}
|
|
951
|
+
/** {@link commentText} split into lines, for a multi-line block comment. */
|
|
952
|
+
function commentLines(text) {
|
|
953
|
+
return commentText(text).split(LINE_BREAK);
|
|
954
|
+
}
|
|
955
|
+
/** {@link commentText} on one line, for a single comment line such as the provenance header. */
|
|
956
|
+
function commentLine(text) {
|
|
957
|
+
return commentText(text).split(LINE_BREAK).join(" ");
|
|
958
|
+
}
|
|
959
|
+
/** Words a type alias can't be named: reserved words and the built-in type names. */
|
|
960
|
+
const RESERVED_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
961
|
+
"any",
|
|
962
|
+
"bigint",
|
|
963
|
+
"boolean",
|
|
964
|
+
"break",
|
|
965
|
+
"case",
|
|
966
|
+
"catch",
|
|
967
|
+
"class",
|
|
968
|
+
"const",
|
|
969
|
+
"continue",
|
|
970
|
+
"debugger",
|
|
971
|
+
"default",
|
|
972
|
+
"delete",
|
|
973
|
+
"do",
|
|
974
|
+
"else",
|
|
975
|
+
"enum",
|
|
976
|
+
"export",
|
|
977
|
+
"extends",
|
|
978
|
+
"false",
|
|
979
|
+
"finally",
|
|
980
|
+
"for",
|
|
981
|
+
"function",
|
|
982
|
+
"if",
|
|
983
|
+
"implements",
|
|
984
|
+
"import",
|
|
985
|
+
"in",
|
|
986
|
+
"instanceof",
|
|
987
|
+
"interface",
|
|
988
|
+
"let",
|
|
989
|
+
"never",
|
|
990
|
+
"new",
|
|
991
|
+
"null",
|
|
992
|
+
"number",
|
|
993
|
+
"object",
|
|
994
|
+
"package",
|
|
995
|
+
"private",
|
|
996
|
+
"protected",
|
|
997
|
+
"public",
|
|
998
|
+
"return",
|
|
999
|
+
"static",
|
|
1000
|
+
"string",
|
|
1001
|
+
"super",
|
|
1002
|
+
"switch",
|
|
1003
|
+
"symbol",
|
|
1004
|
+
"this",
|
|
1005
|
+
"throw",
|
|
1006
|
+
"true",
|
|
1007
|
+
"try",
|
|
1008
|
+
"typeof",
|
|
1009
|
+
"undefined",
|
|
1010
|
+
"unknown",
|
|
1011
|
+
"var",
|
|
1012
|
+
"void",
|
|
1013
|
+
"while",
|
|
1014
|
+
"with",
|
|
1015
|
+
"yield"
|
|
1016
|
+
]);
|
|
1017
|
+
/** True when `name` can be used as is for an exported type. */
|
|
1018
|
+
function isTypeName(name) {
|
|
1019
|
+
return isIdentifier(name) && !RESERVED_TYPE_NAMES.has(name);
|
|
1020
|
+
}
|
|
1021
|
+
//#endregion
|
|
922
1022
|
//#region src/error-codes.ts
|
|
923
1023
|
const REF_PREFIX$1 = "#/components/schemas/";
|
|
924
1024
|
const ERROR_DOCUMENT = /^ErrorDocument(\d{3})?$/;
|
|
@@ -981,24 +1081,20 @@ function readErrorCatalogue(doc) {
|
|
|
981
1081
|
/** A TSDoc block for one code: its description, then each example detail as an `@example`. */
|
|
982
1082
|
function codeDoc(entry, indent) {
|
|
983
1083
|
const lines = [];
|
|
984
|
-
if (entry.description !== void 0) lines.push(...entry.description
|
|
1084
|
+
if (entry.description !== void 0) lines.push(...commentLines(entry.description));
|
|
985
1085
|
for (const example of entry.examples) {
|
|
986
1086
|
if (lines.length > 0) lines.push("");
|
|
987
1087
|
const text = typeof example === "string" ? example : JSON.stringify(example);
|
|
988
|
-
lines.push(
|
|
1088
|
+
lines.push(...commentLines(`@example ${text}`));
|
|
989
1089
|
}
|
|
990
1090
|
if (lines.length === 0) return;
|
|
991
|
-
if (lines.length === 1) return `${indent}/** ${lines[0]
|
|
1091
|
+
if (lines.length === 1) return `${indent}/** ${lines[0]} */`;
|
|
992
1092
|
return [
|
|
993
1093
|
`${indent}/**`,
|
|
994
|
-
...lines.map((line) => `${indent} * ${line
|
|
1094
|
+
...lines.map((line) => `${indent} * ${line}`.trimEnd()),
|
|
995
1095
|
`${indent} */`
|
|
996
1096
|
].join("\n");
|
|
997
1097
|
}
|
|
998
|
-
/** A bare object key when the code is a valid identifier, else a quoted one. */
|
|
999
|
-
function codeKey(code) {
|
|
1000
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(code) ? code : JSON.stringify(code);
|
|
1001
|
-
}
|
|
1002
1098
|
/**
|
|
1003
1099
|
* Emit `ErrorCodes`, a const object keyed by every documented code with its TSDoc on the key
|
|
1004
1100
|
* (editors show TSDoc on an object key, not on a string-literal union member), the `ErrorCode`
|
|
@@ -1021,7 +1117,7 @@ function emitErrorCodes(catalogue) {
|
|
|
1021
1117
|
"export const ErrorCodes = {",
|
|
1022
1118
|
...catalogue.codes.flatMap((entry) => {
|
|
1023
1119
|
const doc = codeDoc(entry, " ");
|
|
1024
|
-
const member = ` ${
|
|
1120
|
+
const member = ` ${propertyKey(entry.code)}: ${stringLiteral(entry.code)},`;
|
|
1025
1121
|
return doc === void 0 ? [member] : [doc, member];
|
|
1026
1122
|
}),
|
|
1027
1123
|
"} as const",
|
|
@@ -1033,7 +1129,7 @@ function emitErrorCodes(catalogue) {
|
|
|
1033
1129
|
"export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes]"
|
|
1034
1130
|
].join("\n");
|
|
1035
1131
|
const statusLines = [...catalogue.byStatus].map(([status, codes]) => {
|
|
1036
|
-
const members = codes.map((c) =>
|
|
1132
|
+
const members = codes.map((c) => stringLiteral(c));
|
|
1037
1133
|
const line = ` ${status}: ${members.length === 0 ? "never" : members.join(" | ")}`;
|
|
1038
1134
|
return line.length <= 100 ? line : ` ${status}:\n${members.map((m) => ` | ${m}`).join("\n")}`;
|
|
1039
1135
|
});
|
|
@@ -1090,12 +1186,12 @@ function deriveProvenance(doc) {
|
|
|
1090
1186
|
}
|
|
1091
1187
|
/**
|
|
1092
1188
|
* Render the provenance record as the JSDoc header lines stamped into a generated artifact
|
|
1093
|
-
* (each already prefixed with ` * `). Deterministic: no timestamp, so re-generating from the
|
|
1189
|
+
* (each already prefixed with ` * `), with the document's text kept to one comment line. Deterministic: no timestamp, so re-generating from the
|
|
1094
1190
|
* same spec yields byte-identical output.
|
|
1095
1191
|
*/
|
|
1096
1192
|
function provenanceLines(provenance) {
|
|
1097
|
-
const lines = [` * Source spec: ${provenance.source}`, ` * Spec hash: ${provenance.hash}`];
|
|
1098
|
-
if (provenance.server !== void 0) lines.splice(1, 0, ` * Server: ${provenance.server}`);
|
|
1193
|
+
const lines = [` * Source spec: ${commentLine(provenance.source)}`, ` * Spec hash: ${provenance.hash}`];
|
|
1194
|
+
if (provenance.server !== void 0) lines.splice(1, 0, ` * Server: ${commentLine(provenance.server)}`);
|
|
1099
1195
|
return lines;
|
|
1100
1196
|
}
|
|
1101
1197
|
//#endregion
|
|
@@ -1140,17 +1236,25 @@ function isSchema(value) {
|
|
|
1140
1236
|
function pascalCase(value) {
|
|
1141
1237
|
return value.split(/[^a-zA-Z0-9]+/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
1142
1238
|
}
|
|
1143
|
-
/**
|
|
1144
|
-
function
|
|
1145
|
-
|
|
1146
|
-
}
|
|
1147
|
-
/** True when a string is a safe bare object-key identifier. */
|
|
1148
|
-
function isIdentifier(value) {
|
|
1149
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);
|
|
1150
|
-
}
|
|
1151
|
-
function objectKey(value) {
|
|
1152
|
-
return isIdentifier(value) ? value : quote(value);
|
|
1239
|
+
/** The identifier stem for a wire type's interfaces, `Type`-prefixed when it would start with a digit. */
|
|
1240
|
+
function typeStem(type) {
|
|
1241
|
+
const pascal = pascalCase(type);
|
|
1242
|
+
return /^[A-Za-z]/.test(pascal) ? pascal : `Type${pascal}`;
|
|
1153
1243
|
}
|
|
1244
|
+
/** Names the generated module declares or relies on, which an enum alias must not take. */
|
|
1245
|
+
const MODULE_NAMES = [
|
|
1246
|
+
"ActionTypes",
|
|
1247
|
+
"ApiDescriptor",
|
|
1248
|
+
"Attributes",
|
|
1249
|
+
"ClientOptions",
|
|
1250
|
+
"ErrorCode",
|
|
1251
|
+
"ErrorCodeByStatus",
|
|
1252
|
+
"ErrorCodeGuard",
|
|
1253
|
+
"ErrorCodes",
|
|
1254
|
+
"Record",
|
|
1255
|
+
"ResourceMap",
|
|
1256
|
+
"WriteAttributes"
|
|
1257
|
+
];
|
|
1154
1258
|
/**
|
|
1155
1259
|
* Render a description as a JSDoc comment at the given indent — single-line when it fits,
|
|
1156
1260
|
* a block otherwise. Returns `undefined` for empty text. Neutralises any `*\/` so a
|
|
@@ -1159,7 +1263,7 @@ function objectKey(value) {
|
|
|
1159
1263
|
function jsDoc(text, indent) {
|
|
1160
1264
|
const trimmed = text?.trim();
|
|
1161
1265
|
if (!trimmed) return;
|
|
1162
|
-
const lines = trimmed
|
|
1266
|
+
const lines = commentLines(trimmed);
|
|
1163
1267
|
if (lines.length === 1) return `${indent}/** ${lines[0]} */`;
|
|
1164
1268
|
return [
|
|
1165
1269
|
`${indent}/**`,
|
|
@@ -1229,6 +1333,10 @@ var Emitter = class {
|
|
|
1229
1333
|
* already-named attribute type. Populated as interfaces are emitted.
|
|
1230
1334
|
*/
|
|
1231
1335
|
emittedInterfaces = /* @__PURE__ */ new Set();
|
|
1336
|
+
/** Enum component name -> the alias name it's emitted under. */
|
|
1337
|
+
enumNames = /* @__PURE__ */ new Map();
|
|
1338
|
+
/** Type names already spoken for: the module's own, the per-type interfaces and enum aliases. */
|
|
1339
|
+
takenNames;
|
|
1232
1340
|
/** Component names mid-expansion in {@link tsType} — a cycle guard for self/mutually-referential `$ref`s. */
|
|
1233
1341
|
expanding = /* @__PURE__ */ new Set();
|
|
1234
1342
|
/**
|
|
@@ -1247,6 +1355,39 @@ var Emitter = class {
|
|
|
1247
1355
|
this.schemas = this.doc.components?.schemas ?? {};
|
|
1248
1356
|
this.baseByType = this.indexBases();
|
|
1249
1357
|
this.provenance = deriveProvenance(source);
|
|
1358
|
+
this.takenNames = new Set(MODULE_NAMES);
|
|
1359
|
+
for (const type of Object.keys(descriptor)) {
|
|
1360
|
+
const stem = typeStem(type);
|
|
1361
|
+
for (const suffix of [
|
|
1362
|
+
"Attributes",
|
|
1363
|
+
"CreateAttributes",
|
|
1364
|
+
"UpdateAttributes"
|
|
1365
|
+
]) this.takenNames.add(`${stem}${suffix}`);
|
|
1366
|
+
for (const action of Object.keys(descriptor[type]?.actions ?? {})) {
|
|
1367
|
+
this.takenNames.add(`${stem}${pascalCase(action)}Input`);
|
|
1368
|
+
this.takenNames.add(`${stem}${pascalCase(action)}Output`);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* The alias an enum component is emitted under: its own name when that's a usable type name,
|
|
1374
|
+
* else one derived from it (with a warning), kept clear of every other name in the module.
|
|
1375
|
+
*/
|
|
1376
|
+
enumName(component) {
|
|
1377
|
+
const known = this.enumNames.get(component);
|
|
1378
|
+
if (known !== void 0) return known;
|
|
1379
|
+
let name = component;
|
|
1380
|
+
if (!isTypeName(component) || this.takenNames.has(component)) {
|
|
1381
|
+
const pascal = pascalCase(component);
|
|
1382
|
+
let stem = /^[A-Za-z]/.test(pascal) ? pascal : `Enum${pascal}`;
|
|
1383
|
+
if (!isTypeName(stem) || this.takenNames.has(stem)) stem = `${stem}Enum`;
|
|
1384
|
+
name = stem;
|
|
1385
|
+
for (let n = 2; this.takenNames.has(name); n++) name = `${stem}${n}`;
|
|
1386
|
+
console.warn(`Enum component ${stringLiteral(component)} can't be used as a TypeScript type name; emitting it as ${name}.`);
|
|
1387
|
+
}
|
|
1388
|
+
this.takenNames.add(name);
|
|
1389
|
+
this.enumNames.set(component, name);
|
|
1390
|
+
return name;
|
|
1250
1391
|
}
|
|
1251
1392
|
/** Map each declared wire type back to the `Base` of its resource schema. */
|
|
1252
1393
|
indexBases() {
|
|
@@ -1307,7 +1448,7 @@ var Emitter = class {
|
|
|
1307
1448
|
const base = this.baseByType.get(type);
|
|
1308
1449
|
const props = base ? this.schemas[`${base}Attributes`]?.properties : void 0;
|
|
1309
1450
|
const fields = Object.keys(this.descriptor[type].attributes);
|
|
1310
|
-
return this.renderInterface(`${
|
|
1451
|
+
return this.renderInterface(`${typeStem(type)}Attributes`, props, fields, () => true);
|
|
1311
1452
|
}
|
|
1312
1453
|
/**
|
|
1313
1454
|
* The per-type WRITE attribute interfaces — `<Pascal>CreateAttributes` and
|
|
@@ -1319,7 +1460,7 @@ var Emitter = class {
|
|
|
1319
1460
|
writeAttributeInterfaces(type) {
|
|
1320
1461
|
const base = this.baseByType.get(type);
|
|
1321
1462
|
if (base === void 0) return [];
|
|
1322
|
-
const pascal =
|
|
1463
|
+
const pascal = typeStem(type);
|
|
1323
1464
|
const out = [];
|
|
1324
1465
|
const create = this.schemas[`${base}CreateAttributes`];
|
|
1325
1466
|
if (create !== void 0) {
|
|
@@ -1346,7 +1487,7 @@ var Emitter = class {
|
|
|
1346
1487
|
for (const type of Object.keys(this.descriptor)) {
|
|
1347
1488
|
const actions = this.descriptor[type]?.actions;
|
|
1348
1489
|
if (actions === void 0) continue;
|
|
1349
|
-
const pascal =
|
|
1490
|
+
const pascal = typeStem(type);
|
|
1350
1491
|
for (const [actionName, action] of Object.entries(actions)) {
|
|
1351
1492
|
const member = `${pascal}${pascalCase(actionName)}`;
|
|
1352
1493
|
const names = {};
|
|
@@ -1390,9 +1531,9 @@ var Emitter = class {
|
|
|
1390
1531
|
const members = [];
|
|
1391
1532
|
if (names.input !== void 0) members.push(`input: ${names.input}`);
|
|
1392
1533
|
if (names.output !== void 0) members.push(`output: ${names.output}`);
|
|
1393
|
-
actionLines.push(` ${
|
|
1534
|
+
actionLines.push(` ${propertyKey(actionName)}: { ${members.join("; ")} }`);
|
|
1394
1535
|
}
|
|
1395
|
-
typeLines.push(` ${
|
|
1536
|
+
typeLines.push(` ${propertyKey(type)}: {\n${actionLines.join("\n")}\n }`);
|
|
1396
1537
|
}
|
|
1397
1538
|
if (typeLines.length === 0) return "export interface ActionTypes {}";
|
|
1398
1539
|
return `export interface ActionTypes {\n${typeLines.join("\n")}\n}`;
|
|
@@ -1440,10 +1581,10 @@ var Emitter = class {
|
|
|
1440
1581
|
if (schema.oneOf !== void 0) for (const arm of schema.oneOf) {
|
|
1441
1582
|
const kind = isSchema(arm.properties?.["kind"]) ? arm.properties["kind"].const : void 0;
|
|
1442
1583
|
const members = this.pageMemberLimits(arm, " ");
|
|
1443
|
-
if (typeof kind === "string" && members.length > 0) body.push(` ${
|
|
1584
|
+
if (typeof kind === "string" && members.length > 0) body.push(` ${propertyKey(kind)}: {\n${members.join("\n")}\n },`);
|
|
1444
1585
|
}
|
|
1445
1586
|
else body = this.pageMemberLimits(schema, " ");
|
|
1446
|
-
if (body.length > 0) typeLines.push(` ${
|
|
1587
|
+
if (body.length > 0) typeLines.push(` ${propertyKey(type)}: {\n${body.join("\n")}\n },`);
|
|
1447
1588
|
}
|
|
1448
1589
|
return `${[
|
|
1449
1590
|
"/**",
|
|
@@ -1468,7 +1609,7 @@ var Emitter = class {
|
|
|
1468
1609
|
if (limits.length === 0) continue;
|
|
1469
1610
|
const doc = jsDoc(memberDoc(prop), indent);
|
|
1470
1611
|
if (doc !== void 0) lines.push(doc);
|
|
1471
|
-
lines.push(`${indent}${
|
|
1612
|
+
lines.push(`${indent}${propertyKey(name)}: { ${limits.join(", ")} },`);
|
|
1472
1613
|
}
|
|
1473
1614
|
return lines;
|
|
1474
1615
|
}
|
|
@@ -1485,7 +1626,7 @@ var Emitter = class {
|
|
|
1485
1626
|
const doc = isSchema(schema) ? jsDoc(memberDoc(schema), " ") : void 0;
|
|
1486
1627
|
if (doc) lines.push(doc);
|
|
1487
1628
|
const optional = required(field) ? "" : "?";
|
|
1488
|
-
lines.push(` ${
|
|
1629
|
+
lines.push(` ${propertyKey(field)}${optional}: ${tsType}`);
|
|
1489
1630
|
}
|
|
1490
1631
|
this.emittedInterfaces.add(name);
|
|
1491
1632
|
if (lines.length === 0) return `export interface ${name} {}`;
|
|
@@ -1498,7 +1639,7 @@ var Emitter = class {
|
|
|
1498
1639
|
const resolved = target ? this.schemas[target] : void 0;
|
|
1499
1640
|
if (target && resolved && Array.isArray(resolved.enum)) {
|
|
1500
1641
|
this.usedEnums.set(target, resolved);
|
|
1501
|
-
return target;
|
|
1642
|
+
return this.enumName(target);
|
|
1502
1643
|
}
|
|
1503
1644
|
if (target && this.emittedInterfaces.has(target)) return target;
|
|
1504
1645
|
if (resolved === void 0 || target === void 0 || this.expanding.has(target)) return "unknown";
|
|
@@ -1523,7 +1664,7 @@ var Emitter = class {
|
|
|
1523
1664
|
}
|
|
1524
1665
|
/** The non-nullable TS type for the declared JSON type(s). */
|
|
1525
1666
|
baseTsType(schema, types) {
|
|
1526
|
-
if (Array.isArray(schema.enum) && schema.enum.length > 0) return schema.enum.map((value) =>
|
|
1667
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) return schema.enum.map((value) => stringLiteral(String(value))).join(" | ");
|
|
1527
1668
|
if (types.length === 0) return "unknown";
|
|
1528
1669
|
const mapped = types.map((t) => this.scalarOrComposite(schema, t));
|
|
1529
1670
|
return [...new Set(mapped)].join(" | ");
|
|
@@ -1548,7 +1689,7 @@ var Emitter = class {
|
|
|
1548
1689
|
for (const [name, prop] of Object.entries(props)) {
|
|
1549
1690
|
if (!isSchema(prop)) continue;
|
|
1550
1691
|
const optional = required.has(name) ? "" : "?";
|
|
1551
|
-
members.push(`${
|
|
1692
|
+
members.push(`${propertyKey(name)}${optional}: ${this.tsType(prop)}`);
|
|
1552
1693
|
}
|
|
1553
1694
|
if (members.length === 0) return "Record<string, unknown>";
|
|
1554
1695
|
return `{ ${members.join("; ")} }`;
|
|
@@ -1565,7 +1706,8 @@ var Emitter = class {
|
|
|
1565
1706
|
if (this.usedEnums.size === 0) return;
|
|
1566
1707
|
return [...this.usedEnums.keys()].sort().map((name) => {
|
|
1567
1708
|
const schema = this.usedEnums.get(name);
|
|
1568
|
-
const
|
|
1709
|
+
const union = (schema.enum ?? []).map((value) => stringLiteral(String(value))).join(" | ");
|
|
1710
|
+
const alias = `export type ${this.enumName(name)} = ${union}`;
|
|
1569
1711
|
const doc = jsDoc(this.enumDoc(schema), "");
|
|
1570
1712
|
return doc ? `${doc}\n${alias}` : alias;
|
|
1571
1713
|
}).join("\n\n");
|
|
@@ -1588,7 +1730,7 @@ var Emitter = class {
|
|
|
1588
1730
|
* argument to the runtime factory).
|
|
1589
1731
|
*/
|
|
1590
1732
|
attributesMap() {
|
|
1591
|
-
return `export interface Attributes {\n${Object.keys(this.descriptor).map((type) => ` ${
|
|
1733
|
+
return `export interface Attributes {\n${Object.keys(this.descriptor).map((type) => ` ${propertyKey(type)}: ${typeStem(type)}Attributes`).join("\n")}\n}`;
|
|
1592
1734
|
}
|
|
1593
1735
|
/**
|
|
1594
1736
|
* Emit the `WriteAttributes` interface mapping each writable wire type to its
|
|
@@ -1603,11 +1745,11 @@ var Emitter = class {
|
|
|
1603
1745
|
const hasCreate = base !== void 0 && this.schemas[`${base}CreateAttributes`] !== void 0;
|
|
1604
1746
|
const hasUpdate = base !== void 0 && this.schemas[`${base}UpdateAttributes`] !== void 0;
|
|
1605
1747
|
if (!hasCreate && !hasUpdate) continue;
|
|
1606
|
-
const pascal =
|
|
1748
|
+
const pascal = typeStem(type);
|
|
1607
1749
|
const members = [];
|
|
1608
1750
|
if (hasCreate) members.push(`create: ${pascal}CreateAttributes`);
|
|
1609
1751
|
if (hasUpdate) members.push(`update: ${pascal}UpdateAttributes`);
|
|
1610
|
-
lines.push(` ${
|
|
1752
|
+
lines.push(` ${propertyKey(type)}: { ${members.join("; ")} }`);
|
|
1611
1753
|
}
|
|
1612
1754
|
if (lines.length === 0) return "export interface WriteAttributes {}";
|
|
1613
1755
|
return `export interface WriteAttributes {\n${lines.join("\n")}\n}`;
|
|
@@ -1627,9 +1769,9 @@ var Emitter = class {
|
|
|
1627
1769
|
if (value !== null && typeof value === "object") {
|
|
1628
1770
|
const entries = Object.entries(value);
|
|
1629
1771
|
if (entries.length === 0) return "{}";
|
|
1630
|
-
return `{\n${entries.map(([key, v]) => `${inner}${
|
|
1772
|
+
return `{\n${entries.map(([key, v]) => `${inner}${propertyKey(key)}: ${this.literal(v, depth + 1)}`).join(",\n")}\n${indent}}`;
|
|
1631
1773
|
}
|
|
1632
|
-
return JSON.stringify(value);
|
|
1774
|
+
return typeof value === "string" ? stringLiteral(value) : JSON.stringify(value);
|
|
1633
1775
|
}
|
|
1634
1776
|
boundFactory() {
|
|
1635
1777
|
return [
|
|
@@ -1688,7 +1830,7 @@ function header(bundle) {
|
|
|
1688
1830
|
].join("\n");
|
|
1689
1831
|
}
|
|
1690
1832
|
function body(bundle) {
|
|
1691
|
-
return `export const schemas = ${JSON.stringify(bundle, null, 2)} as const`;
|
|
1833
|
+
return `export const schemas = ${JSON.stringify(bundle, null, 2).replace(/^(\s*)"__proto__":/gm, "$1[\"__proto__\"]:").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029")} as const`;
|
|
1692
1834
|
}
|
|
1693
1835
|
//#endregion
|
|
1694
1836
|
//#region src/reader.ts
|
|
@@ -1832,4 +1974,4 @@ async function check(config) {
|
|
|
1832
1974
|
//#endregion
|
|
1833
1975
|
export { checkContract as _, readSchemas as a, buildDescriptor as b, detectVerbCollisions as c, hashJson as d, provenanceLines as f, MINIMUM_CONTRACT as g, MAXIMUM_CONTRACT as h, readDocument as i, emit as l, readErrorCatalogue as m, generate as n, emitSchemas as o, emitErrorCodes as p, schemasOutputPath as r, Emitter as s, check as t, deriveProvenance as u, DescriptorBuilder as v, buildAtomic as y };
|
|
1834
1976
|
|
|
1835
|
-
//# sourceMappingURL=src-
|
|
1977
|
+
//# sourceMappingURL=src-CKsM7dXw.mjs.map
|