@mgamadeus/ddd-web 0.10.0 → 0.11.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 -2
- package/CHANGELOG.md +20 -0
- package/dist/{chunk-PZ6AAETR.js → chunk-XXMTSCOZ.js} +92 -29
- package/dist/chunk-XXMTSCOZ.js.map +1 -0
- package/dist/codegen/cli.js +1 -1
- package/dist/codegen/index.d.ts +19 -2
- package/dist/codegen/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-PZ6AAETR.js.map +0 -1
|
@@ -50,8 +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
|
+
| `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`. The built name is used verbatim (no second camel-casing); your `filterEndpoints` / `endpointOverrides` match it. 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. With `naming: 'document'` every file exports its own schema's name, also when another folder holds it too; importers alias it, the barrel leaves such a name out, and the api file imports each model by its path. `index: false`: no barrel. `enumPropertyType: 'wide'`: the property typed from the plain object (`string` in effect) instead of the Strict one. `objectType: 'const'`: a string `objectType` gets the one-value const of its schema name (`.` → `\\`, key `.` → `_`) and is required. Enum keys camel-case a dash (`gpt-realtime` → `gptRealtime`); an enum on an array schema stays an array. |
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
export default defineConfig({
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `models.index: false`: no barrel `index.ts`; the api file imports every model by its path.
|
|
7
|
+
- `models.enumPropertyType: 'wide'`: an enum property typed from the plain const object (`string` in effect) instead
|
|
8
|
+
of the Strict one (default `strict`, as in 0.9.0).
|
|
9
|
+
- `models.objectType: 'const'`: a string `objectType` gets the one-value const of its schema name
|
|
10
|
+
(`App_Domain_X: "App\\Domain\\X"`) and is required.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- `models.naming: 'document'`: every model file exports its own schema's name, also when another folder holds the
|
|
14
|
+
same name (before: qualified, `MoneyCurrency`); an importer aliases it, the barrel leaves such a name out (it broke
|
|
15
|
+
the closing type check with a duplicate export), the api file imports each model by its path.
|
|
16
|
+
- Enum const keys camel-case a dash (`gpt-realtime` → `gptRealtime`).
|
|
17
|
+
- `endpoints.naming`: the built name is used verbatim — RTK codegen no longer camel-cases it a second time
|
|
18
|
+
(`…FromLegacyDB` stayed `…FromLegacyDb`); `filterEndpoints` and `endpointOverrides` match the built name.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- An enum declared on an array schema stays an array (`Array<…>`).
|
|
22
|
+
|
|
3
23
|
## 0.10.0
|
|
4
24
|
|
|
5
25
|
### Added
|
|
@@ -494,7 +494,8 @@ function buildEndpointNameFromPath(method, path11, stripPathPrefix = DEFAULT_STR
|
|
|
494
494
|
function prepareDocumentForEndpoints(doc, options) {
|
|
495
495
|
const naming = options.naming ?? "rtk";
|
|
496
496
|
const bodyArg = options.bodyArg ?? "rtk";
|
|
497
|
-
|
|
497
|
+
const endpointNamesByPlaceholder = /* @__PURE__ */ new Map();
|
|
498
|
+
if (naming === "rtk" && bodyArg === "rtk") return { doc, endpointNamesByPlaceholder };
|
|
498
499
|
const prepared = structuredClone(doc);
|
|
499
500
|
const pathByName = /* @__PURE__ */ new Map();
|
|
500
501
|
for (const [path11, item] of Object.entries(prepared.paths ?? {})) {
|
|
@@ -512,12 +513,25 @@ function prepareDocumentForEndpoints(doc, options) {
|
|
|
512
513
|
throw new SdkGenerationError(`endpoints.naming: ${other} and ${method.toUpperCase()} ${path11} are both named "${name}".`);
|
|
513
514
|
}
|
|
514
515
|
pathByName.set(name, `${method.toUpperCase()} ${path11}`);
|
|
515
|
-
|
|
516
|
+
const placeholder = `dddEndpoint${endpointNamesByPlaceholder.size}`;
|
|
517
|
+
endpointNamesByPlaceholder.set(placeholder, name);
|
|
518
|
+
operation.operationId = placeholder;
|
|
516
519
|
}
|
|
517
520
|
if (bodyArg === REQUEST_BODY_ARG) titleRequestBody(operation);
|
|
518
521
|
}
|
|
519
522
|
}
|
|
520
|
-
return prepared;
|
|
523
|
+
return { doc: prepared, endpointNamesByPlaceholder };
|
|
524
|
+
}
|
|
525
|
+
function restoreEndpointNames(code, locations, endpointNamesByPlaceholder) {
|
|
526
|
+
if (endpointNamesByPlaceholder.size === 0) return { code, locations };
|
|
527
|
+
const restore = (text) => text.replace(/(d|D)ddEndpoint(\d+)(?!\d)/g, (match, first, number) => {
|
|
528
|
+
const name = endpointNamesByPlaceholder.get(`dddEndpoint${number}`);
|
|
529
|
+
if (name === void 0) return match;
|
|
530
|
+
return first === "D" ? upperFirst(name) : name;
|
|
531
|
+
});
|
|
532
|
+
const restoredLocations = /* @__PURE__ */ new Map();
|
|
533
|
+
for (const [key, location] of locations) restoredLocations.set(restore(key), location);
|
|
534
|
+
return { code: restore(code), locations: restoredLocations };
|
|
521
535
|
}
|
|
522
536
|
function titleRequestBody(operation) {
|
|
523
537
|
const content = operation.requestBody?.content;
|
|
@@ -651,16 +665,21 @@ function findDocumentModel(rtkName, documentModels) {
|
|
|
651
665
|
}
|
|
652
666
|
function enumKeyOf(value) {
|
|
653
667
|
if (value.trim() === "") return "EMPTY";
|
|
654
|
-
const key = value.replace(/[ /\\]+/g, "_");
|
|
668
|
+
const key = value.replace(/-+([A-Za-z0-9])/g, (_, next) => next.toUpperCase()).replace(/[ /\\]+/g, "_");
|
|
655
669
|
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
|
|
656
670
|
}
|
|
657
|
-
function applyEnumConsts(body, modelName,
|
|
671
|
+
function applyEnumConsts(body, modelName, model, options = {}) {
|
|
672
|
+
const { schema, schemaKey } = model;
|
|
658
673
|
const consts = /* @__PURE__ */ new Map();
|
|
659
674
|
const typeTexts = /* @__PURE__ */ new Map();
|
|
675
|
+
const requiredNames = /* @__PURE__ */ new Set();
|
|
660
676
|
for (const [propertyName2, property] of Object.entries(schema.properties ?? {})) {
|
|
661
677
|
if (!isObject(property)) continue;
|
|
662
|
-
const
|
|
663
|
-
const
|
|
678
|
+
const isItemsEnum = isObject(property.items) && Array.isArray(property.items.enum);
|
|
679
|
+
const isArray = isItemsEnum || property.type === "array";
|
|
680
|
+
const isObjectType = options.objectType === "const" && propertyName2 === "objectType" && property.type === "string" && !Array.isArray(property.enum);
|
|
681
|
+
const declaredValues = isObjectType ? [schemaKey.split(".").join("\\")] : isItemsEnum ? property.items.enum : property.enum;
|
|
682
|
+
const values = declaredValues?.filter((value) => typeof value === "string" || typeof value === "number");
|
|
664
683
|
if (!values || values.length === 0) continue;
|
|
665
684
|
const constName = `${modelName}${propertyName2.charAt(0).toUpperCase()}${propertyName2.slice(1)}`;
|
|
666
685
|
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(constName)) continue;
|
|
@@ -672,13 +691,15 @@ ${members}
|
|
|
672
691
|
export const ${constName}Strict = {
|
|
673
692
|
${members}
|
|
674
693
|
} as const;`);
|
|
675
|
-
const
|
|
694
|
+
const typedFrom = options.enumPropertyType === "wide" ? constName : `${constName}Strict`;
|
|
695
|
+
const memberType = `(typeof ${typedFrom})[keyof typeof ${typedFrom}]`;
|
|
676
696
|
const nullable = property.nullable === true || (property.enum ?? []).includes(null);
|
|
677
697
|
typeTexts.set(propertyName2, `${isArray ? `Array<${memberType}>` : memberType}${nullable ? " | null" : ""}`);
|
|
698
|
+
if (isObjectType) requiredNames.add(propertyName2);
|
|
678
699
|
}
|
|
679
|
-
return { body: replacePropertyTypes(body, typeTexts), consts };
|
|
700
|
+
return { body: replacePropertyTypes(body, typeTexts, requiredNames), consts };
|
|
680
701
|
}
|
|
681
|
-
function replacePropertyTypes(body, typeTexts) {
|
|
702
|
+
function replacePropertyTypes(body, typeTexts, requiredNames = /* @__PURE__ */ new Set()) {
|
|
682
703
|
if (typeTexts.size === 0) return body;
|
|
683
704
|
const ts = loadTypeScript();
|
|
684
705
|
const sourceFile = ts.createSourceFile("model.ts", body, ts.ScriptTarget.Latest, true);
|
|
@@ -693,6 +714,9 @@ function replacePropertyTypes(body, typeTexts) {
|
|
|
693
714
|
const name = ts.isIdentifier(member.name) || ts.isStringLiteral(member.name) ? member.name.text : member.name.getText(sourceFile);
|
|
694
715
|
const text = typeTexts.get(name);
|
|
695
716
|
if (text !== void 0) replacements.push({ start: member.type.getStart(sourceFile), end: member.type.getEnd(), text });
|
|
717
|
+
if (requiredNames.has(name) && member.questionToken) {
|
|
718
|
+
replacements.push({ start: member.questionToken.getStart(sourceFile), end: member.questionToken.getEnd(), text: "" });
|
|
719
|
+
}
|
|
696
720
|
}
|
|
697
721
|
let result = body;
|
|
698
722
|
for (const { start, end, text } of replacements.sort((a, b) => b.start - a.start)) {
|
|
@@ -1312,10 +1336,13 @@ function extractModels(input) {
|
|
|
1312
1336
|
const documentModelByNewName = /* @__PURE__ */ new Map();
|
|
1313
1337
|
const targetByNewName = /* @__PURE__ */ new Map();
|
|
1314
1338
|
const nameByPath = /* @__PURE__ */ new Map();
|
|
1339
|
+
const exportNameByUniqueName = /* @__PURE__ */ new Map();
|
|
1340
|
+
const uniqueNameByPath = input.uniqueNameByPath ?? /* @__PURE__ */ new Map();
|
|
1315
1341
|
for (const oldName of originalNames) {
|
|
1316
1342
|
const { filePath, leafName, segments } = placement(oldName);
|
|
1317
1343
|
const pathKey = path4.resolve(filePath).toLowerCase();
|
|
1318
|
-
|
|
1344
|
+
const isDocumentModel = findDocumentModel(oldName, documentModels) !== null;
|
|
1345
|
+
let name = nameByPath.get(pathKey) ?? uniqueNameByPath.get(pathKey) ?? (isDocumentModel ? void 0 : files.get(filePath)?.match(EXPORTED_NAME)?.[1]);
|
|
1319
1346
|
if (!name) {
|
|
1320
1347
|
const owner = (candidate) => nameOwners.get(candidate);
|
|
1321
1348
|
name = leafName;
|
|
@@ -1323,10 +1350,12 @@ function extractModels(input) {
|
|
|
1323
1350
|
name = segments.slice(-depth).join("") + leafName;
|
|
1324
1351
|
}
|
|
1325
1352
|
if (owner(name) !== void 0 && owner(name) !== pathKey) name = oldName;
|
|
1326
|
-
if (name !== leafName) logger.info(` ${oldName}: leaf name ${leafName} is taken \u2014 exported as ${name}`);
|
|
1353
|
+
if (name !== leafName && !isDocumentModel) logger.info(` ${oldName}: leaf name ${leafName} is taken \u2014 exported as ${name}`);
|
|
1327
1354
|
}
|
|
1328
1355
|
nameOwners.set(name, pathKey);
|
|
1329
1356
|
nameByPath.set(pathKey, name);
|
|
1357
|
+
uniqueNameByPath.set(pathKey, name);
|
|
1358
|
+
exportNameByUniqueName.set(name, isDocumentModel ? leafName : name);
|
|
1330
1359
|
renameMap.set(oldName, name);
|
|
1331
1360
|
targetByNewName.set(name, filePath);
|
|
1332
1361
|
const documentModel = findDocumentModel(oldName, documentModels);
|
|
@@ -1353,18 +1382,26 @@ function extractModels(input) {
|
|
|
1353
1382
|
);
|
|
1354
1383
|
const isPresentation = (filePath) => filePath.split(path4.sep).includes("Presentation");
|
|
1355
1384
|
const barrelEntries = [];
|
|
1356
|
-
|
|
1385
|
+
const exportNameOf = (uniqueName) => exportNameByUniqueName.get(uniqueName) ?? uniqueName;
|
|
1386
|
+
const writeIndex = input.writeIndex !== false;
|
|
1387
|
+
for (const { name: uniqueName, body: uniqueBody, filePath } of entries) {
|
|
1357
1388
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1358
1389
|
if (dependencyRegex) {
|
|
1359
|
-
for (const match of
|
|
1360
|
-
if (match[1] && match[1] !==
|
|
1390
|
+
for (const match of uniqueBody.matchAll(new RegExp(dependencyRegex.source, "g"))) {
|
|
1391
|
+
if (match[1] && match[1] !== uniqueName) dependencies.add(match[1]);
|
|
1361
1392
|
}
|
|
1362
1393
|
}
|
|
1363
|
-
const
|
|
1394
|
+
const name = exportNameOf(uniqueName);
|
|
1395
|
+
const localNameOf = /* @__PURE__ */ new Map();
|
|
1396
|
+
for (const dependency of dependencies) localNameOf.set(dependency, dependency === name ? `${dependency}Ref` : dependency);
|
|
1397
|
+
const renames = new Map([[uniqueName, name], ...[...localNameOf].filter(([dependency, local]) => dependency !== local)]);
|
|
1398
|
+
const renameInBody = alternation([...renames.keys()].filter((key) => renames.get(key) !== key));
|
|
1399
|
+
const body = renameInBody ? uniqueBody.replace(renameInBody, (_, found) => renames.get(found) ?? found) : uniqueBody;
|
|
1400
|
+
const kind = kindByName.get(uniqueName);
|
|
1364
1401
|
let typedBody = body;
|
|
1365
|
-
const documentModel = documentModelByNewName.get(
|
|
1402
|
+
const documentModel = documentModelByNewName.get(uniqueName);
|
|
1366
1403
|
if (input.enumConsts && documentModel) {
|
|
1367
|
-
const applied = applyEnumConsts(body, name, documentModel.
|
|
1404
|
+
const applied = applyEnumConsts(body, name, documentModel, input.modelOptions);
|
|
1368
1405
|
typedBody = applied.body;
|
|
1369
1406
|
const fileKey = path4.resolve(filePath).toLowerCase();
|
|
1370
1407
|
const fileConsts2 = constsByFile.get(fileKey) ?? /* @__PURE__ */ new Map();
|
|
@@ -1381,9 +1418,11 @@ function extractModels(input) {
|
|
|
1381
1418
|
}
|
|
1382
1419
|
const importLines = [
|
|
1383
1420
|
...kind === "blob" ? [`import type { DddFileResponse } from '${DDD_WEB_API_IMPORT}';`] : [],
|
|
1384
|
-
...[...dependencies].map(
|
|
1385
|
-
|
|
1386
|
-
|
|
1421
|
+
...[...dependencies].map((dependency) => {
|
|
1422
|
+
const exported = exportNameOf(dependency);
|
|
1423
|
+
const local = localNameOf.get(dependency) ?? dependency;
|
|
1424
|
+
return `import { ${exported === local ? local : `${exported} as ${local}`} } from '${importSpecifier(filePath, pathByName.get(dependency), esm)}';`;
|
|
1425
|
+
})
|
|
1387
1426
|
].join("\n");
|
|
1388
1427
|
const existing = files.isGeneratedThisRun(filePath) ? files.get(filePath) : void 0;
|
|
1389
1428
|
const content = existing !== void 0 ? mergeModel(existing, typedBody, importLines, name, logger) : (importLines ? `${importLines}
|
|
@@ -1395,14 +1434,24 @@ export default ${name};
|
|
|
1395
1434
|
const fileConsts = constsByFile.get(path4.resolve(filePath).toLowerCase());
|
|
1396
1435
|
files.set(filePath, fileConsts ? withEnumConsts(content, name, [...fileConsts.values()]) : content);
|
|
1397
1436
|
if (isPresentation(path4.relative(modelsDir, filePath))) continue;
|
|
1437
|
+
if (name !== uniqueName) continue;
|
|
1398
1438
|
barrelEntries.push(`export * from '${importSpecifier(indexPath, filePath, esm)}';`);
|
|
1399
1439
|
}
|
|
1400
|
-
writeBarrel(files, indexPath, barrelEntries);
|
|
1440
|
+
if (writeIndex) writeBarrel(files, indexPath, barrelEntries);
|
|
1401
1441
|
const others = entries.filter((entry) => path4.relative(modelsDir, entry.filePath).split(path4.sep)[0] === "_others");
|
|
1402
1442
|
if (others.length > 0) {
|
|
1403
1443
|
logger.warn(`${others.length} type(s) without a namespace match placed in _others/: ${others.map((e) => e.name).join(", ")}`);
|
|
1404
1444
|
}
|
|
1405
1445
|
logger.info(` extracted ${entries.length} types`);
|
|
1446
|
+
if (!writeIndex || usedInApi.some((usedName) => exportNameOf(usedName) !== usedName) || documentModels.size > 0) {
|
|
1447
|
+
const importLines = usedInApi.map((usedName) => {
|
|
1448
|
+
const exported = exportNameOf(usedName);
|
|
1449
|
+
return `import { ${exported === usedName ? usedName : `${exported} as ${usedName}`} } from '${importSpecifier(input.apiFilePath, pathByName.get(usedName), esm)}';`;
|
|
1450
|
+
});
|
|
1451
|
+
return `${importLines.join("\n")}
|
|
1452
|
+
|
|
1453
|
+
${strippedSource}`;
|
|
1454
|
+
}
|
|
1406
1455
|
const modelsImport = esm ? importSpecifier(input.apiFilePath, indexPath, true) : importSpecifier(input.apiFilePath, indexPath, false).replace(/\/index$/, "");
|
|
1407
1456
|
return `import {
|
|
1408
1457
|
${usedInApi.join(",\n ")}
|
|
@@ -1794,17 +1843,19 @@ function relativeImport(fromDir, target) {
|
|
|
1794
1843
|
if (!relative6.startsWith(".")) relative6 = `./${relative6}`;
|
|
1795
1844
|
return relative6;
|
|
1796
1845
|
}
|
|
1797
|
-
async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile) {
|
|
1846
|
+
async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile, endpointNameOf = (rtkName) => rtkName) {
|
|
1798
1847
|
fs6.writeFileSync(specFile, JSON.stringify(doc));
|
|
1799
1848
|
const passthrough = {};
|
|
1800
1849
|
for (const [key, value] of Object.entries(api.config)) if (!OWN_KEYS.has(key)) passthrough[key] = value;
|
|
1801
|
-
const userOverrides = passthrough.endpointOverrides ?? []
|
|
1850
|
+
const userOverrides = (passthrough.endpointOverrides ?? []).map(
|
|
1851
|
+
(override) => override.pattern === void 0 ? override : { ...override, pattern: (name, definition) => matches(override.pattern, endpointNameOf(name), definition) }
|
|
1852
|
+
);
|
|
1802
1853
|
const endpointOverrides = mergeEndpointOverrides(userOverrides, endpointTypeOverrides(index));
|
|
1803
1854
|
const suffix = typeof passthrough.operationNameSuffix === "string" ? passthrough.operationNameSuffix : "";
|
|
1804
1855
|
const locations = /* @__PURE__ */ new Map();
|
|
1805
1856
|
const userFilter = passthrough.filterEndpoints;
|
|
1806
1857
|
const filterEndpoints = (name, definition) => {
|
|
1807
|
-
const included = !index.skippedTwins.has(operationKey(definition.verb, definition.path)) && (userFilter === void 0 || matches(userFilter, name, definition));
|
|
1858
|
+
const included = !index.skippedTwins.has(operationKey(definition.verb, definition.path)) && (userFilter === void 0 || matches(userFilter, endpointNameOf(name), definition));
|
|
1808
1859
|
if (included) {
|
|
1809
1860
|
locations.set(suffix ? capitalize(name + suffix) : name, { method: definition.verb, path: definition.path });
|
|
1810
1861
|
}
|
|
@@ -1968,6 +2019,7 @@ async function generateSdk(options = {}) {
|
|
|
1968
2019
|
if (steps.length < pipeline.length) files.seedFromDisk(modelsDir);
|
|
1969
2020
|
const prettierConfigFile = await findPrettierConfigFile(loaded.rootDir);
|
|
1970
2021
|
const constsByFile = /* @__PURE__ */ new Map();
|
|
2022
|
+
const uniqueNameByPath = /* @__PURE__ */ new Map();
|
|
1971
2023
|
const specDir = fs8.mkdtempSync(path9.join(os.tmpdir(), "ddd-web-spec-"));
|
|
1972
2024
|
try {
|
|
1973
2025
|
for (const [i, { api, write, doc: rawDoc }] of steps.entries()) {
|
|
@@ -1977,8 +2029,16 @@ async function generateSdk(options = {}) {
|
|
|
1977
2029
|
if (index.skippedTwins.size > 0) logger.info(` skipping ${index.skippedTwins.size} POST twin(s) of PATCH upserts`);
|
|
1978
2030
|
const modelOptions = loaded.config.models ?? {};
|
|
1979
2031
|
const prepared = prepareDocumentForModels(doc, modelOptions);
|
|
1980
|
-
const
|
|
1981
|
-
const
|
|
2032
|
+
const preparedEndpoints = prepareDocumentForEndpoints(prepared.doc, loaded.config.endpoints ?? {});
|
|
2033
|
+
const generated = await runRtkCodegen(
|
|
2034
|
+
api,
|
|
2035
|
+
preparedEndpoints.doc,
|
|
2036
|
+
index,
|
|
2037
|
+
path9.join(specDir, `${i}.json`),
|
|
2038
|
+
prettierConfigFile,
|
|
2039
|
+
(rtkName) => preparedEndpoints.endpointNamesByPlaceholder.get(rtkName) ?? rtkName
|
|
2040
|
+
);
|
|
2041
|
+
const rtk = restoreEndpointNames(generated.code, generated.locations, preparedEndpoints.endpointNamesByPlaceholder);
|
|
1982
2042
|
const endpoints = parseApiEndpoints(rtk.code, logger, rtk.locations);
|
|
1983
2043
|
const handlerEndpoints = detectResponseHandlerEndpoints(doc, endpoints, api.responseHandlers);
|
|
1984
2044
|
const responseKinds = /* @__PURE__ */ new Map();
|
|
@@ -2002,7 +2062,10 @@ async function generateSdk(options = {}) {
|
|
|
2002
2062
|
responseKinds,
|
|
2003
2063
|
documentModels: prepared.documentModels,
|
|
2004
2064
|
enumConsts: modelOptions.enums === "const",
|
|
2005
|
-
constsByFile
|
|
2065
|
+
constsByFile,
|
|
2066
|
+
modelOptions,
|
|
2067
|
+
writeIndex: modelOptions.index !== false,
|
|
2068
|
+
uniqueNameByPath
|
|
2006
2069
|
});
|
|
2007
2070
|
if (!write) continue;
|
|
2008
2071
|
const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints);
|
|
@@ -2119,4 +2182,4 @@ export {
|
|
|
2119
2182
|
generateSdk,
|
|
2120
2183
|
linkSkills
|
|
2121
2184
|
};
|
|
2122
|
-
//# sourceMappingURL=chunk-
|
|
2185
|
+
//# sourceMappingURL=chunk-XXMTSCOZ.js.map
|