@mgamadeus/ddd-web 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/ddd-web-specialist/references/consumer.md +2 -0
- package/CHANGELOG.md +26 -0
- package/dist/{chunk-RCXFU5IA.js → chunk-PZ6AAETR.js} +212 -11
- package/dist/chunk-PZ6AAETR.js.map +1 -0
- package/dist/codegen/cli.js +1 -1
- package/dist/codegen/index.d.ts +70 -2
- package/dist/codegen/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-RCXFU5IA.js.map +0 -1
|
@@ -50,6 +50,8 @@ too). A plain RTK-codegen file with `export const apis = [...]` is accepted as w
|
|
|
50
50
|
| `invalidation` | `(operation: InvalidationOperation) => InvalidationTag[] \| undefined`: overrides the tags a mutation invalidates; `undefined` keeps the default. `broadInvalidation` (exported) restores the 0.2 behaviour. See section 3. |
|
|
51
51
|
| `workspace` | `{ envVar, envFiles?, urlKeys?, prompt? }`: resolves a workspace / subdomain value (CLI `--workspace` → env → URL sniffed from `.env` / `.env.local` → TTY prompt) into `process.env[envVar]` before the config is evaluated again. |
|
|
52
52
|
| `tsconfig` | tsconfig of the final type check. Default `tsconfig.json` next to the config. |
|
|
53
|
+
| `endpoints` | How endpoints and their body argument are named; off by default. `naming: 'path'`: a pure function of verb and path — `stripPathPrefix` (default `/api` or `/app/api`) cut, every `{param}/` cut out and only the LAST one kept, the rest split on `/ _ - .` and capitalised behind the verb, `By<LastInner>` appended, a trailing `{param}` becomes `By<Param>` where it stands (`POST /api/client/ai/conversations/{locationId}/purposed/{purposeName}` → `postClientAiConversationsPurposedByPurposeNameByLocationId`; `buildEndpointNameFromPath` is exported). `naming` may be a function `({ method, path, operation }) => name`. Two operations with one name stop the run. `bodyArg: 'requestBody'`: the body is the argument's `requestBody`, whatever its DTO is called. Query and path parameters stay flat in the argument. |
|
|
54
|
+
| `models` | How the models of the component schemas are written; every option off by default. `naming: 'document'`: the model is named by the schema name's last dot segment exactly (`AIConversationMessage`, not `AiConversationMessage`), the segments before it are its folders — a neighbour namespace that prefixes the name never splits it. `enums: 'const'` (needs `naming: 'document'`): an enum property becomes `export const <Model><Property> = {…}` and `<Model><Property>Strict = {…} as const` in the model's file, the property typed `(typeof XStrict)[keyof typeof XStrict]` (`\| null` when nullable; `Array<…>` for an enum of array items); keys are the values with spaces, `/`, `\` as `_`, `""` as `EMPTY`. `nullableRefs: true`: `\| null` beside a nullable `$ref`. `idType: 'number' \| 'string'`: an `id` declared `string \| integer` gets that type. |
|
|
53
55
|
|
|
54
56
|
```ts
|
|
55
57
|
export default defineConfig({
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Codegen option `endpoints` (off by default, output unchanged without it):
|
|
7
|
+
- `naming: 'path'`: endpoint (and hook) names as a pure function of verb and path — the prefix
|
|
8
|
+
(`stripPathPrefix`, default `/api` or `/app/api`) cut, every `{param}/` cut out and only the last one kept, the
|
|
9
|
+
rest capitalised behind the verb, `By<LastInner>` appended, a trailing `{param}` as `By<Param>` where it stands;
|
|
10
|
+
`naming` may also be a function. Two operations with the same name stop the run. `buildEndpointNameFromPath` is
|
|
11
|
+
exported.
|
|
12
|
+
- `bodyArg: 'requestBody'`: the request body is the argument's `requestBody`, independent of the DTO's schema
|
|
13
|
+
name.
|
|
14
|
+
|
|
15
|
+
## 0.9.0
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- Codegen option `models` (every option off by default, output unchanged without it):
|
|
19
|
+
- `naming: 'document'`: a model is named by the last dot segment of its schema name, unchanged
|
|
20
|
+
(`AIConversationMessage`, not `AiConversationMessage`), and placed in the folders of the segments before it; a
|
|
21
|
+
neighbour namespace that prefixes the name never splits it (`…Messages.DelegationResults` stays
|
|
22
|
+
`Messages/DelegationResults.ts` beside `Messages/Delegation/`).
|
|
23
|
+
- `enums: 'const'` (with `naming: 'document'`): an enum property becomes `export const <Model><Property>` and
|
|
24
|
+
`<Model><Property>Strict` (`as const`) in its model's file, the property typed from the Strict object
|
|
25
|
+
(`| null` when nullable, `Array<…>` for an enum of array items).
|
|
26
|
+
- `nullableRefs: true`: `| null` beside a nullable `$ref`.
|
|
27
|
+
- `idType: 'number' | 'string'`: the type of an `id` declared `string | integer`.
|
|
28
|
+
|
|
3
29
|
## 0.8.0
|
|
4
30
|
|
|
5
31
|
### Added
|
|
@@ -31,6 +31,9 @@ function resolveApis(loaded) {
|
|
|
31
31
|
if (!Array.isArray(config.apis) || config.apis.length === 0) {
|
|
32
32
|
throw new Error(`No apis configured in ${loaded.configPath}.`);
|
|
33
33
|
}
|
|
34
|
+
if (config.models?.enums === "const" && config.models.naming !== "document") {
|
|
35
|
+
throw new Error(`models.enums 'const' needs models.naming 'document' (${loaded.configPath}).`);
|
|
36
|
+
}
|
|
34
37
|
return config.apis.map((entry, index) => {
|
|
35
38
|
for (const key of ["schemaFile", "apiFile", "outputFile"]) {
|
|
36
39
|
if (typeof entry[key] !== "string" || entry[key] === "") {
|
|
@@ -473,6 +476,58 @@ function buildEnhancedEndpoints(input) {
|
|
|
473
476
|
return { source, tagTypes: [...allTags].sort() };
|
|
474
477
|
}
|
|
475
478
|
|
|
479
|
+
// src/codegen/document-endpoints.ts
|
|
480
|
+
var REQUEST_BODY_ARG = "requestBody";
|
|
481
|
+
var DEFAULT_STRIP_PATH_PREFIX = /^\/(?:app\/)?api(?=\/)/;
|
|
482
|
+
var upperFirst = (value) => value.charAt(0).toUpperCase() + value.slice(1);
|
|
483
|
+
function buildEndpointNameFromPath(method, path11, stripPathPrefix = DEFAULT_STRIP_PATH_PREFIX) {
|
|
484
|
+
const stripped = typeof stripPathPrefix === "string" ? path11.startsWith(stripPathPrefix) ? path11.slice(stripPathPrefix.length) : path11 : path11.replace(stripPathPrefix, "");
|
|
485
|
+
let lastInnerParameter = null;
|
|
486
|
+
const withoutInnerParameters = stripped.replace(/\{([^}]+)\}\//g, (_, parameter) => {
|
|
487
|
+
lastInnerParameter = parameter;
|
|
488
|
+
return "";
|
|
489
|
+
});
|
|
490
|
+
const pieces = withoutInnerParameters.split(/[/_.-]/).filter((piece) => piece !== "").map(upperFirst).join("");
|
|
491
|
+
const name = `${method.toLowerCase()}${pieces}${lastInnerParameter ? `By${upperFirst(lastInnerParameter)}` : ""}`;
|
|
492
|
+
return name.replace(/\{([^}]+)\}/g, (_, parameter) => `By${upperFirst(parameter)}`);
|
|
493
|
+
}
|
|
494
|
+
function prepareDocumentForEndpoints(doc, options) {
|
|
495
|
+
const naming = options.naming ?? "rtk";
|
|
496
|
+
const bodyArg = options.bodyArg ?? "rtk";
|
|
497
|
+
if (naming === "rtk" && bodyArg === "rtk") return doc;
|
|
498
|
+
const prepared = structuredClone(doc);
|
|
499
|
+
const pathByName = /* @__PURE__ */ new Map();
|
|
500
|
+
for (const [path11, item] of Object.entries(prepared.paths ?? {})) {
|
|
501
|
+
if (!item) continue;
|
|
502
|
+
for (const method of HTTP_METHODS) {
|
|
503
|
+
const operation = item[method];
|
|
504
|
+
if (!operation) continue;
|
|
505
|
+
if (naming !== "rtk") {
|
|
506
|
+
const name = naming === "path" ? buildEndpointNameFromPath(method, path11, options.stripPathPrefix) : naming({ method, path: path11, operation });
|
|
507
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) {
|
|
508
|
+
throw new SdkGenerationError(`endpoints.naming: "${name}" (${method.toUpperCase()} ${path11}) is no identifier.`);
|
|
509
|
+
}
|
|
510
|
+
const other = pathByName.get(name);
|
|
511
|
+
if (other !== void 0) {
|
|
512
|
+
throw new SdkGenerationError(`endpoints.naming: ${other} and ${method.toUpperCase()} ${path11} are both named "${name}".`);
|
|
513
|
+
}
|
|
514
|
+
pathByName.set(name, `${method.toUpperCase()} ${path11}`);
|
|
515
|
+
operation.operationId = name;
|
|
516
|
+
}
|
|
517
|
+
if (bodyArg === REQUEST_BODY_ARG) titleRequestBody(operation);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return prepared;
|
|
521
|
+
}
|
|
522
|
+
function titleRequestBody(operation) {
|
|
523
|
+
const content = operation.requestBody?.content;
|
|
524
|
+
for (const media of Object.values(content ?? {})) {
|
|
525
|
+
const schema = media?.schema;
|
|
526
|
+
if (!schema) continue;
|
|
527
|
+
media.schema = typeof schema.$ref === "string" ? { title: REQUEST_BODY_ARG, allOf: [{ $ref: schema.$ref }] } : { ...schema, title: REQUEST_BODY_ARG };
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
476
531
|
// src/codegen/spec.ts
|
|
477
532
|
import * as fs2 from "fs";
|
|
478
533
|
var SUPPORTED_CONTRACT = { min: 1, max: 1 };
|
|
@@ -541,6 +596,111 @@ function loadTypeScript() {
|
|
|
541
596
|
return cached;
|
|
542
597
|
}
|
|
543
598
|
|
|
599
|
+
// src/codegen/document-models.ts
|
|
600
|
+
var titleOfSchema = (index) => `DddModel${index}`;
|
|
601
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
602
|
+
function prepareDocumentForModels(doc, options) {
|
|
603
|
+
const documentModels = /* @__PURE__ */ new Map();
|
|
604
|
+
const naming = options.naming === "document";
|
|
605
|
+
const enumConsts = options.enums === "const";
|
|
606
|
+
if (!naming && !enumConsts && !options.nullableRefs && (options.idType ?? "document") === "document") {
|
|
607
|
+
return { doc, documentModels };
|
|
608
|
+
}
|
|
609
|
+
const prepared = structuredClone(doc);
|
|
610
|
+
const schemas = prepared.components?.schemas ?? {};
|
|
611
|
+
const original = doc.components?.schemas ?? {};
|
|
612
|
+
Object.keys(schemas).forEach((schemaKey, index) => {
|
|
613
|
+
const schema = schemas[schemaKey];
|
|
614
|
+
if (!isObject(schema)) return;
|
|
615
|
+
if (naming) {
|
|
616
|
+
schema.title = titleOfSchema(index);
|
|
617
|
+
documentModels.set(titleOfSchema(index), { schemaKey, schema: original[schemaKey] });
|
|
618
|
+
}
|
|
619
|
+
for (const [propertyName2, property] of Object.entries(schema.properties ?? {})) {
|
|
620
|
+
if (!isObject(property)) continue;
|
|
621
|
+
if (options.nullableRefs && typeof property.$ref === "string" && property.nullable === true) {
|
|
622
|
+
schema.properties[propertyName2] = { allOf: [{ $ref: property.$ref }], nullable: true };
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
const idType = options.idType ?? "document";
|
|
626
|
+
if (propertyName2 === "id" && idType !== "document" && isStringOrIntegerUnion(property)) {
|
|
627
|
+
schema.properties[propertyName2] = {
|
|
628
|
+
type: idType === "number" ? "integer" : "string",
|
|
629
|
+
...isNullable(property) ? { nullable: true } : {}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
return { doc: prepared, documentModels };
|
|
635
|
+
}
|
|
636
|
+
function isStringOrIntegerUnion(property) {
|
|
637
|
+
const types = new Set((property.oneOf ?? []).map((variant) => isObject(variant) ? variant.type : void 0));
|
|
638
|
+
return types.has("string") && (types.has("integer") || types.has("number"));
|
|
639
|
+
}
|
|
640
|
+
function isNullable(property) {
|
|
641
|
+
return property.nullable === true || (property.oneOf ?? []).some((variant) => isObject(variant) && variant.nullable === true);
|
|
642
|
+
}
|
|
643
|
+
function placeDocumentModel(model) {
|
|
644
|
+
const parts = model.schemaKey.split(".");
|
|
645
|
+
return { segments: parts.slice(0, -1), leafName: parts[parts.length - 1] };
|
|
646
|
+
}
|
|
647
|
+
function findDocumentModel(rtkName, documentModels) {
|
|
648
|
+
const match = rtkName.match(/^(DddModel\d+)(Read|Write)?$/);
|
|
649
|
+
const model = match ? documentModels.get(match[1]) : void 0;
|
|
650
|
+
return model ? { model, suffix: match[2] ?? "" } : null;
|
|
651
|
+
}
|
|
652
|
+
function enumKeyOf(value) {
|
|
653
|
+
if (value.trim() === "") return "EMPTY";
|
|
654
|
+
const key = value.replace(/[ /\\]+/g, "_");
|
|
655
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
|
|
656
|
+
}
|
|
657
|
+
function applyEnumConsts(body, modelName, schema) {
|
|
658
|
+
const consts = /* @__PURE__ */ new Map();
|
|
659
|
+
const typeTexts = /* @__PURE__ */ new Map();
|
|
660
|
+
for (const [propertyName2, property] of Object.entries(schema.properties ?? {})) {
|
|
661
|
+
if (!isObject(property)) continue;
|
|
662
|
+
const isArray = isObject(property.items) && Array.isArray(property.items.enum);
|
|
663
|
+
const values = (isArray ? property.items.enum : property.enum)?.filter((value) => typeof value === "string" || typeof value === "number");
|
|
664
|
+
if (!values || values.length === 0) continue;
|
|
665
|
+
const constName = `${modelName}${propertyName2.charAt(0).toUpperCase()}${propertyName2.slice(1)}`;
|
|
666
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(constName)) continue;
|
|
667
|
+
const members = [...new Set(values.map(String))].map((value) => ` ${enumKeyOf(value)}: ${JSON.stringify(value)},`).join("\n");
|
|
668
|
+
consts.set(constName, `export const ${constName} = {
|
|
669
|
+
${members}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
export const ${constName}Strict = {
|
|
673
|
+
${members}
|
|
674
|
+
} as const;`);
|
|
675
|
+
const memberType = `(typeof ${constName}Strict)[keyof typeof ${constName}Strict]`;
|
|
676
|
+
const nullable = property.nullable === true || (property.enum ?? []).includes(null);
|
|
677
|
+
typeTexts.set(propertyName2, `${isArray ? `Array<${memberType}>` : memberType}${nullable ? " | null" : ""}`);
|
|
678
|
+
}
|
|
679
|
+
return { body: replacePropertyTypes(body, typeTexts), consts };
|
|
680
|
+
}
|
|
681
|
+
function replacePropertyTypes(body, typeTexts) {
|
|
682
|
+
if (typeTexts.size === 0) return body;
|
|
683
|
+
const ts = loadTypeScript();
|
|
684
|
+
const sourceFile = ts.createSourceFile("model.ts", body, ts.ScriptTarget.Latest, true);
|
|
685
|
+
const declaration = sourceFile.statements.find(
|
|
686
|
+
(statement) => ts.isTypeAliasDeclaration(statement) || ts.isInterfaceDeclaration(statement)
|
|
687
|
+
);
|
|
688
|
+
if (!declaration) return body;
|
|
689
|
+
const members = ts.isInterfaceDeclaration(declaration) ? declaration.members : ts.isTypeLiteralNode(declaration.type) ? declaration.type.members : ts.isIntersectionTypeNode(declaration.type) ? declaration.type.types.flatMap((part) => ts.isTypeLiteralNode(part) ? [...part.members] : []) : [];
|
|
690
|
+
const replacements = [];
|
|
691
|
+
for (const member of members) {
|
|
692
|
+
if (!ts.isPropertySignature(member) || !member.type || !member.name) continue;
|
|
693
|
+
const name = ts.isIdentifier(member.name) || ts.isStringLiteral(member.name) ? member.name.text : member.name.getText(sourceFile);
|
|
694
|
+
const text = typeTexts.get(name);
|
|
695
|
+
if (text !== void 0) replacements.push({ start: member.type.getStart(sourceFile), end: member.type.getEnd(), text });
|
|
696
|
+
}
|
|
697
|
+
let result = body;
|
|
698
|
+
for (const { start, end, text } of replacements.sort((a, b) => b.start - a.start)) {
|
|
699
|
+
result = result.slice(0, start) + text + result.slice(end);
|
|
700
|
+
}
|
|
701
|
+
return result;
|
|
702
|
+
}
|
|
703
|
+
|
|
544
704
|
// src/codegen/endpoints.ts
|
|
545
705
|
function toOpenApiPath(url) {
|
|
546
706
|
return url.replace(/\$\{encodeURIComponent\(String\(queryArg\.([A-Za-z0-9_]+)\)\)\}/g, "{$1}").replace(/\$\{queryArg\.([A-Za-z0-9_]+)\}/g, "{$1}");
|
|
@@ -1130,7 +1290,15 @@ function extractModels(input) {
|
|
|
1130
1290
|
const name = files.get(filePath)?.match(EXPORTED_NAME)?.[1];
|
|
1131
1291
|
if (name && !nameOwners.has(name)) nameOwners.set(name, path4.resolve(filePath).toLowerCase());
|
|
1132
1292
|
}
|
|
1293
|
+
const documentModels = input.documentModels ?? /* @__PURE__ */ new Map();
|
|
1294
|
+
const constsByFile = input.constsByFile ?? /* @__PURE__ */ new Map();
|
|
1133
1295
|
const placement = (oldName) => {
|
|
1296
|
+
const documentModel = findDocumentModel(oldName, documentModels);
|
|
1297
|
+
if (documentModel) {
|
|
1298
|
+
const { segments, leafName } = placeDocumentModel(documentModel.model);
|
|
1299
|
+
const planned = path4.join(modelsDir, ...segments, `${leafName}${documentModel.suffix}.ts`);
|
|
1300
|
+
return { filePath: files.findPath(planned) ?? planned, leafName: `${leafName}${documentModel.suffix}`, segments };
|
|
1301
|
+
}
|
|
1134
1302
|
const match = registryMatch(oldName, registry);
|
|
1135
1303
|
if (match) {
|
|
1136
1304
|
const planned = path4.join(modelsDir, ...match.segments, `${match.leafName}.ts`);
|
|
@@ -1141,6 +1309,7 @@ function extractModels(input) {
|
|
|
1141
1309
|
};
|
|
1142
1310
|
const originalNames = exportedTypeDeclarations(input.apiSource).map((declaration) => declaration.name);
|
|
1143
1311
|
const renameMap = /* @__PURE__ */ new Map();
|
|
1312
|
+
const documentModelByNewName = /* @__PURE__ */ new Map();
|
|
1144
1313
|
const targetByNewName = /* @__PURE__ */ new Map();
|
|
1145
1314
|
const nameByPath = /* @__PURE__ */ new Map();
|
|
1146
1315
|
for (const oldName of originalNames) {
|
|
@@ -1160,6 +1329,8 @@ function extractModels(input) {
|
|
|
1160
1329
|
nameByPath.set(pathKey, name);
|
|
1161
1330
|
renameMap.set(oldName, name);
|
|
1162
1331
|
targetByNewName.set(name, filePath);
|
|
1332
|
+
const documentModel = findDocumentModel(oldName, documentModels);
|
|
1333
|
+
if (documentModel && documentModel.suffix === "") documentModelByNewName.set(name, documentModel.model);
|
|
1163
1334
|
}
|
|
1164
1335
|
const renameRegex = alternation([...renameMap.keys()]);
|
|
1165
1336
|
const renamedSource = renameRegex ? input.apiSource.replace(renameRegex, (_, name) => renameMap.get(name) ?? name) : input.apiSource;
|
|
@@ -1191,6 +1362,15 @@ function extractModels(input) {
|
|
|
1191
1362
|
}
|
|
1192
1363
|
const kind = kindByName.get(name);
|
|
1193
1364
|
let typedBody = body;
|
|
1365
|
+
const documentModel = documentModelByNewName.get(name);
|
|
1366
|
+
if (input.enumConsts && documentModel) {
|
|
1367
|
+
const applied = applyEnumConsts(body, name, documentModel.schema);
|
|
1368
|
+
typedBody = applied.body;
|
|
1369
|
+
const fileKey = path4.resolve(filePath).toLowerCase();
|
|
1370
|
+
const fileConsts2 = constsByFile.get(fileKey) ?? /* @__PURE__ */ new Map();
|
|
1371
|
+
for (const [constName, text] of applied.consts) fileConsts2.set(constName, text);
|
|
1372
|
+
if (fileConsts2.size > 0) constsByFile.set(fileKey, fileConsts2);
|
|
1373
|
+
}
|
|
1194
1374
|
if (kind === "text") {
|
|
1195
1375
|
const replaced = body.replace(/(=\s*\/\*\* status \d+[^*]*\*\/)\s*\{\}/g, "$1 string");
|
|
1196
1376
|
typedBody = replaced !== body ? replaced : `export type ${name} = string;`;
|
|
@@ -1212,7 +1392,8 @@ function extractModels(input) {
|
|
|
1212
1392
|
|
|
1213
1393
|
export default ${name};
|
|
1214
1394
|
`;
|
|
1215
|
-
|
|
1395
|
+
const fileConsts = constsByFile.get(path4.resolve(filePath).toLowerCase());
|
|
1396
|
+
files.set(filePath, fileConsts ? withEnumConsts(content, name, [...fileConsts.values()]) : content);
|
|
1216
1397
|
if (isPresentation(path4.relative(modelsDir, filePath))) continue;
|
|
1217
1398
|
barrelEntries.push(`export * from '${importSpecifier(indexPath, filePath, esm)}';`);
|
|
1218
1399
|
}
|
|
@@ -1245,30 +1426,42 @@ function writeBarrel(files, indexPath, newEntries) {
|
|
|
1245
1426
|
files.set(indexPath, `${merged.join("\n")}
|
|
1246
1427
|
`);
|
|
1247
1428
|
}
|
|
1429
|
+
function withEnumConsts(content, name, constTexts) {
|
|
1430
|
+
const defaultExport = `export default ${name};`;
|
|
1431
|
+
const withoutConsts = content.replace(/\nexport const \w+ = \{[\s\S]*?\n\}(?: as const)?;\n/g, "\n");
|
|
1432
|
+
const at = withoutConsts.lastIndexOf(defaultExport);
|
|
1433
|
+
const head = (at >= 0 ? withoutConsts.slice(0, at) : withoutConsts).replace(/\s+$/, "");
|
|
1434
|
+
return `${head}
|
|
1435
|
+
|
|
1436
|
+
${constTexts.join("\n\n")}
|
|
1437
|
+
|
|
1438
|
+
${defaultExport}
|
|
1439
|
+
`;
|
|
1440
|
+
}
|
|
1248
1441
|
|
|
1249
1442
|
// src/codegen/multipart.ts
|
|
1250
1443
|
var MULTIPART_FILES_ARG = "multipartFiles";
|
|
1251
1444
|
var BODY_FIELD = "body";
|
|
1252
1445
|
var FILE_PART_TYPE = "(Blob | { uri: string; name: string; type: string })";
|
|
1253
|
-
var
|
|
1446
|
+
var isObject2 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
1254
1447
|
function resolveRef(doc, value) {
|
|
1255
1448
|
let current = value;
|
|
1256
|
-
for (let depth = 0; depth < 5 &&
|
|
1449
|
+
for (let depth = 0; depth < 5 && isObject2(current) && typeof current.$ref === "string"; depth++) {
|
|
1257
1450
|
const segments = current.$ref.replace(/^#\//, "").split("/");
|
|
1258
1451
|
let target = doc;
|
|
1259
|
-
for (const segment of segments) target =
|
|
1452
|
+
for (const segment of segments) target = isObject2(target) ? target[segment.replace(/~1/g, "/").replace(/~0/g, "~")] : void 0;
|
|
1260
1453
|
current = target;
|
|
1261
1454
|
}
|
|
1262
|
-
return
|
|
1455
|
+
return isObject2(current) ? current : void 0;
|
|
1263
1456
|
}
|
|
1264
1457
|
var isJsonMediaType = (type) => /(^|\/|\+)json$/.test(type.split(";")[0].trim().toLowerCase());
|
|
1265
1458
|
function readMultipartOperation(doc, requestBody) {
|
|
1266
1459
|
const content = resolveRef(doc, requestBody)?.content;
|
|
1267
|
-
if (!
|
|
1460
|
+
if (!isObject2(content)) return null;
|
|
1268
1461
|
const multipartKey = Object.keys(content).find((type) => type.split(";")[0].trim().toLowerCase() === "multipart/form-data");
|
|
1269
|
-
if (!multipartKey || !
|
|
1462
|
+
if (!multipartKey || !isObject2(content[multipartKey])) return null;
|
|
1270
1463
|
const schema = resolveRef(doc, content[multipartKey].schema);
|
|
1271
|
-
const properties =
|
|
1464
|
+
const properties = isObject2(schema?.properties) ? schema.properties : {};
|
|
1272
1465
|
const fields = Object.keys(properties).filter((name) => name !== BODY_FIELD);
|
|
1273
1466
|
if (fields.length === 0) return null;
|
|
1274
1467
|
const requiredList = Array.isArray(schema?.required) ? schema.required.filter((name) => typeof name === "string") : [];
|
|
@@ -1774,6 +1967,7 @@ async function generateSdk(options = {}) {
|
|
|
1774
1967
|
const files = new OutputFiles();
|
|
1775
1968
|
if (steps.length < pipeline.length) files.seedFromDisk(modelsDir);
|
|
1776
1969
|
const prettierConfigFile = await findPrettierConfigFile(loaded.rootDir);
|
|
1970
|
+
const constsByFile = /* @__PURE__ */ new Map();
|
|
1777
1971
|
const specDir = fs8.mkdtempSync(path9.join(os.tmpdir(), "ddd-web-spec-"));
|
|
1778
1972
|
try {
|
|
1779
1973
|
for (const [i, { api, write, doc: rawDoc }] of steps.entries()) {
|
|
@@ -1781,7 +1975,10 @@ async function generateSdk(options = {}) {
|
|
|
1781
1975
|
logger.info(`\u2500\u2500 ${api.stem} (${i + 1}/${steps.length})${write ? "" : " (models only)"}`);
|
|
1782
1976
|
const index = indexOperations(doc, api.sideEffects, api.skipUpdatePostTwins);
|
|
1783
1977
|
if (index.skippedTwins.size > 0) logger.info(` skipping ${index.skippedTwins.size} POST twin(s) of PATCH upserts`);
|
|
1784
|
-
const
|
|
1978
|
+
const modelOptions = loaded.config.models ?? {};
|
|
1979
|
+
const prepared = prepareDocumentForModels(doc, modelOptions);
|
|
1980
|
+
const rtkDoc = prepareDocumentForEndpoints(prepared.doc, loaded.config.endpoints ?? {});
|
|
1981
|
+
const rtk = await runRtkCodegen(api, rtkDoc, index, path9.join(specDir, `${i}.json`), prettierConfigFile);
|
|
1785
1982
|
const endpoints = parseApiEndpoints(rtk.code, logger, rtk.locations);
|
|
1786
1983
|
const handlerEndpoints = detectResponseHandlerEndpoints(doc, endpoints, api.responseHandlers);
|
|
1787
1984
|
const responseKinds = /* @__PURE__ */ new Map();
|
|
@@ -1802,7 +1999,10 @@ async function generateSdk(options = {}) {
|
|
|
1802
1999
|
files,
|
|
1803
2000
|
logger,
|
|
1804
2001
|
esm,
|
|
1805
|
-
responseKinds
|
|
2002
|
+
responseKinds,
|
|
2003
|
+
documentModels: prepared.documentModels,
|
|
2004
|
+
enumConsts: modelOptions.enums === "const",
|
|
2005
|
+
constsByFile
|
|
1806
2006
|
});
|
|
1807
2007
|
if (!write) continue;
|
|
1808
2008
|
const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints);
|
|
@@ -1912,10 +2112,11 @@ export {
|
|
|
1912
2112
|
silentLogger,
|
|
1913
2113
|
SdkGenerationError,
|
|
1914
2114
|
broadInvalidation,
|
|
2115
|
+
buildEndpointNameFromPath,
|
|
1915
2116
|
SUPPORTED_CONTRACT,
|
|
1916
2117
|
loadSpec,
|
|
1917
2118
|
validateSpec,
|
|
1918
2119
|
generateSdk,
|
|
1919
2120
|
linkSkills
|
|
1920
2121
|
};
|
|
1921
|
-
//# sourceMappingURL=chunk-
|
|
2122
|
+
//# sourceMappingURL=chunk-PZ6AAETR.js.map
|