@mgamadeus/ddd-web 0.10.0 → 0.12.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.
@@ -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`); a value that still gives no identifier is its own quoted key; an enum on an array schema stays an array. `scope: 'all'`: the models of every operation are written also when `filterEndpoints` keeps them out of the api file (their argument types are not). With several documents a shared model and its enum consts come from the first-listed one. |
55
55
 
56
56
  ```ts
57
57
  export default defineConfig({
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Added
6
+ - `models.scope: 'all'`: every schema an operation of the document reaches is written, also when `filterEndpoints`
7
+ leaves the operation out of the api file (a models-only pass; its argument and response types are not written).
8
+ Default `reachable` (as before).
9
+
10
+ ### Fixed
11
+ - With several documents, the enum consts of a shared model came from the LAST document while its type came from the
12
+ first: both come from the first-listed document now.
13
+ - An enum value that gives no identifier after the key rules (`gemini/gemini-3.1-flash`) is its own quoted key.
14
+
15
+ ## 0.11.0
16
+
17
+ ### Added
18
+ - `models.index: false`: no barrel `index.ts`; the api file imports every model by its path.
19
+ - `models.enumPropertyType: 'wide'`: an enum property typed from the plain const object (`string` in effect) instead
20
+ of the Strict one (default `strict`, as in 0.9.0).
21
+ - `models.objectType: 'const'`: a string `objectType` gets the one-value const of its schema name
22
+ (`App_Domain_X: "App\\Domain\\X"`) and is required.
23
+
24
+ ### Changed
25
+ - `models.naming: 'document'`: every model file exports its own schema's name, also when another folder holds the
26
+ same name (before: qualified, `MoneyCurrency`); an importer aliases it, the barrel leaves such a name out (it broke
27
+ the closing type check with a duplicate export), the api file imports each model by its path.
28
+ - Enum const keys camel-case a dash (`gpt-realtime` → `gptRealtime`).
29
+ - `endpoints.naming`: the built name is used verbatim — RTK codegen no longer camel-cases it a second time
30
+ (`…FromLegacyDB` stayed `…FromLegacyDb`); `filterEndpoints` and `endpointOverrides` match the built name.
31
+
32
+ ### Fixed
33
+ - An enum declared on an array schema stays an array (`Array<…>`).
34
+
3
35
  ## 0.10.0
4
36
 
5
37
  ### 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
- if (naming === "rtk" && bodyArg === "rtk") return doc;
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
- operation.operationId = name;
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, "_");
655
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
668
+ const key = value.replace(/-+([A-Za-z0-9])/g, (_, next) => next.toUpperCase()).replace(/[ /\\]+/g, "_");
669
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(value);
656
670
  }
657
- function applyEnumConsts(body, modelName, schema) {
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 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");
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 memberType = `(typeof ${constName}Strict)[keyof typeof ${constName}Strict]`;
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
- let name = nameByPath.get(pathKey) ?? files.get(filePath)?.match(EXPORTED_NAME)?.[1];
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);
@@ -1343,6 +1372,7 @@ function extractModels(input) {
1343
1372
  logger.warn(`Re-extracted type "${name}" not in rename map \u2014 skipping.`);
1344
1373
  continue;
1345
1374
  }
1375
+ if (input.modelsOnly && path4.relative(modelsDir, filePath).split(path4.sep)[0] === "_endpoints") continue;
1346
1376
  entries.push({ name, body: text, filePath });
1347
1377
  }
1348
1378
  const pathByName = new Map(entries.map((entry) => [entry.name, entry.filePath]));
@@ -1353,22 +1383,30 @@ function extractModels(input) {
1353
1383
  );
1354
1384
  const isPresentation = (filePath) => filePath.split(path4.sep).includes("Presentation");
1355
1385
  const barrelEntries = [];
1356
- for (const { name, body, filePath } of entries) {
1386
+ const exportNameOf = (uniqueName) => exportNameByUniqueName.get(uniqueName) ?? uniqueName;
1387
+ const writeIndex = input.writeIndex !== false;
1388
+ for (const { name: uniqueName, body: uniqueBody, filePath } of entries) {
1357
1389
  const dependencies = /* @__PURE__ */ new Set();
1358
1390
  if (dependencyRegex) {
1359
- for (const match of body.matchAll(new RegExp(dependencyRegex.source, "g"))) {
1360
- if (match[1] && match[1] !== name) dependencies.add(match[1]);
1391
+ for (const match of uniqueBody.matchAll(new RegExp(dependencyRegex.source, "g"))) {
1392
+ if (match[1] && match[1] !== uniqueName) dependencies.add(match[1]);
1361
1393
  }
1362
1394
  }
1363
- const kind = kindByName.get(name);
1395
+ const name = exportNameOf(uniqueName);
1396
+ const localNameOf = /* @__PURE__ */ new Map();
1397
+ for (const dependency of dependencies) localNameOf.set(dependency, dependency === name ? `${dependency}Ref` : dependency);
1398
+ const renames = new Map([[uniqueName, name], ...[...localNameOf].filter(([dependency, local]) => dependency !== local)]);
1399
+ const renameInBody = alternation([...renames.keys()].filter((key) => renames.get(key) !== key));
1400
+ const body = renameInBody ? uniqueBody.replace(renameInBody, (_, found) => renames.get(found) ?? found) : uniqueBody;
1401
+ const kind = kindByName.get(uniqueName);
1364
1402
  let typedBody = body;
1365
- const documentModel = documentModelByNewName.get(name);
1403
+ const documentModel = documentModelByNewName.get(uniqueName);
1366
1404
  if (input.enumConsts && documentModel) {
1367
- const applied = applyEnumConsts(body, name, documentModel.schema);
1405
+ const applied = applyEnumConsts(body, name, documentModel, input.modelOptions);
1368
1406
  typedBody = applied.body;
1369
1407
  const fileKey = path4.resolve(filePath).toLowerCase();
1370
1408
  const fileConsts2 = constsByFile.get(fileKey) ?? /* @__PURE__ */ new Map();
1371
- for (const [constName, text] of applied.consts) fileConsts2.set(constName, text);
1409
+ for (const [constName, text] of applied.consts) if (!fileConsts2.has(constName)) fileConsts2.set(constName, text);
1372
1410
  if (fileConsts2.size > 0) constsByFile.set(fileKey, fileConsts2);
1373
1411
  }
1374
1412
  if (kind === "text") {
@@ -1381,9 +1419,11 @@ function extractModels(input) {
1381
1419
  }
1382
1420
  const importLines = [
1383
1421
  ...kind === "blob" ? [`import type { DddFileResponse } from '${DDD_WEB_API_IMPORT}';`] : [],
1384
- ...[...dependencies].map(
1385
- (dependency) => `import { ${dependency} } from '${importSpecifier(filePath, pathByName.get(dependency), esm)}';`
1386
- )
1422
+ ...[...dependencies].map((dependency) => {
1423
+ const exported = exportNameOf(dependency);
1424
+ const local = localNameOf.get(dependency) ?? dependency;
1425
+ return `import { ${exported === local ? local : `${exported} as ${local}`} } from '${importSpecifier(filePath, pathByName.get(dependency), esm)}';`;
1426
+ })
1387
1427
  ].join("\n");
1388
1428
  const existing = files.isGeneratedThisRun(filePath) ? files.get(filePath) : void 0;
1389
1429
  const content = existing !== void 0 ? mergeModel(existing, typedBody, importLines, name, logger) : (importLines ? `${importLines}
@@ -1395,14 +1435,24 @@ export default ${name};
1395
1435
  const fileConsts = constsByFile.get(path4.resolve(filePath).toLowerCase());
1396
1436
  files.set(filePath, fileConsts ? withEnumConsts(content, name, [...fileConsts.values()]) : content);
1397
1437
  if (isPresentation(path4.relative(modelsDir, filePath))) continue;
1438
+ if (name !== uniqueName) continue;
1398
1439
  barrelEntries.push(`export * from '${importSpecifier(indexPath, filePath, esm)}';`);
1399
1440
  }
1400
- writeBarrel(files, indexPath, barrelEntries);
1441
+ if (writeIndex) writeBarrel(files, indexPath, barrelEntries);
1401
1442
  const others = entries.filter((entry) => path4.relative(modelsDir, entry.filePath).split(path4.sep)[0] === "_others");
1402
1443
  if (others.length > 0) {
1403
1444
  logger.warn(`${others.length} type(s) without a namespace match placed in _others/: ${others.map((e) => e.name).join(", ")}`);
1404
1445
  }
1405
1446
  logger.info(` extracted ${entries.length} types`);
1447
+ if (!writeIndex || usedInApi.some((usedName) => exportNameOf(usedName) !== usedName) || documentModels.size > 0) {
1448
+ const importLines = usedInApi.map((usedName) => {
1449
+ const exported = exportNameOf(usedName);
1450
+ return `import { ${exported === usedName ? usedName : `${exported} as ${usedName}`} } from '${importSpecifier(input.apiFilePath, pathByName.get(usedName), esm)}';`;
1451
+ });
1452
+ return `${importLines.join("\n")}
1453
+
1454
+ ${strippedSource}`;
1455
+ }
1406
1456
  const modelsImport = esm ? importSpecifier(input.apiFilePath, indexPath, true) : importSpecifier(input.apiFilePath, indexPath, false).replace(/\/index$/, "");
1407
1457
  return `import {
1408
1458
  ${usedInApi.join(",\n ")}
@@ -1794,17 +1844,19 @@ function relativeImport(fromDir, target) {
1794
1844
  if (!relative6.startsWith(".")) relative6 = `./${relative6}`;
1795
1845
  return relative6;
1796
1846
  }
1797
- async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile) {
1847
+ async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile, endpointNameOf = (rtkName) => rtkName) {
1798
1848
  fs6.writeFileSync(specFile, JSON.stringify(doc));
1799
1849
  const passthrough = {};
1800
1850
  for (const [key, value] of Object.entries(api.config)) if (!OWN_KEYS.has(key)) passthrough[key] = value;
1801
- const userOverrides = passthrough.endpointOverrides ?? [];
1851
+ const userOverrides = (passthrough.endpointOverrides ?? []).map(
1852
+ (override) => override.pattern === void 0 ? override : { ...override, pattern: (name, definition) => matches(override.pattern, endpointNameOf(name), definition) }
1853
+ );
1802
1854
  const endpointOverrides = mergeEndpointOverrides(userOverrides, endpointTypeOverrides(index));
1803
1855
  const suffix = typeof passthrough.operationNameSuffix === "string" ? passthrough.operationNameSuffix : "";
1804
1856
  const locations = /* @__PURE__ */ new Map();
1805
1857
  const userFilter = passthrough.filterEndpoints;
1806
1858
  const filterEndpoints = (name, definition) => {
1807
- const included = !index.skippedTwins.has(operationKey(definition.verb, definition.path)) && (userFilter === void 0 || matches(userFilter, name, definition));
1859
+ const included = !index.skippedTwins.has(operationKey(definition.verb, definition.path)) && (userFilter === void 0 || matches(userFilter, endpointNameOf(name), definition));
1808
1860
  if (included) {
1809
1861
  locations.set(suffix ? capitalize(name + suffix) : name, { method: definition.verb, path: definition.path });
1810
1862
  }
@@ -1968,6 +2020,7 @@ async function generateSdk(options = {}) {
1968
2020
  if (steps.length < pipeline.length) files.seedFromDisk(modelsDir);
1969
2021
  const prettierConfigFile = await findPrettierConfigFile(loaded.rootDir);
1970
2022
  const constsByFile = /* @__PURE__ */ new Map();
2023
+ const uniqueNameByPath = /* @__PURE__ */ new Map();
1971
2024
  const specDir = fs8.mkdtempSync(path9.join(os.tmpdir(), "ddd-web-spec-"));
1972
2025
  try {
1973
2026
  for (const [i, { api, write, doc: rawDoc }] of steps.entries()) {
@@ -1977,8 +2030,43 @@ async function generateSdk(options = {}) {
1977
2030
  if (index.skippedTwins.size > 0) logger.info(` skipping ${index.skippedTwins.size} POST twin(s) of PATCH upserts`);
1978
2031
  const modelOptions = loaded.config.models ?? {};
1979
2032
  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);
2033
+ const preparedEndpoints = prepareDocumentForEndpoints(prepared.doc, loaded.config.endpoints ?? {});
2034
+ const generated = await runRtkCodegen(
2035
+ api,
2036
+ preparedEndpoints.doc,
2037
+ index,
2038
+ path9.join(specDir, `${i}.json`),
2039
+ prettierConfigFile,
2040
+ (rtkName) => preparedEndpoints.endpointNamesByPlaceholder.get(rtkName) ?? rtkName
2041
+ );
2042
+ const rtk = restoreEndpointNames(generated.code, generated.locations, preparedEndpoints.endpointNamesByPlaceholder);
2043
+ const extractOptions = {
2044
+ apiFilePath: api.outputFile,
2045
+ modelsDir,
2046
+ registry,
2047
+ files,
2048
+ logger,
2049
+ esm: api.config.esmExtensions === true,
2050
+ documentModels: prepared.documentModels,
2051
+ enumConsts: modelOptions.enums === "const",
2052
+ constsByFile,
2053
+ modelOptions,
2054
+ writeIndex: modelOptions.index !== false,
2055
+ uniqueNameByPath
2056
+ };
2057
+ if (modelOptions.scope === "all" && api.config.filterEndpoints !== void 0) {
2058
+ const unfiltered = await runRtkCodegen(
2059
+ { ...api, config: { ...api.config, filterEndpoints: void 0 } },
2060
+ preparedEndpoints.doc,
2061
+ index,
2062
+ path9.join(specDir, `${i}-all.json`),
2063
+ prettierConfigFile,
2064
+ (rtkName) => preparedEndpoints.endpointNamesByPlaceholder.get(rtkName) ?? rtkName
2065
+ );
2066
+ const unfilteredCode = restoreEndpointNames(unfiltered.code, unfiltered.locations, preparedEndpoints.endpointNamesByPlaceholder).code;
2067
+ extractModels({ ...extractOptions, apiSource: unfilteredCode, modelsOnly: true });
2068
+ logger.info(" models of all operations written (models.scope all)");
2069
+ }
1982
2070
  const endpoints = parseApiEndpoints(rtk.code, logger, rtk.locations);
1983
2071
  const handlerEndpoints = detectResponseHandlerEndpoints(doc, endpoints, api.responseHandlers);
1984
2072
  const responseKinds = /* @__PURE__ */ new Map();
@@ -1991,19 +2079,7 @@ async function generateSdk(options = {}) {
1991
2079
  const multipart = injectMultipartBodies(rtk.code, detectMultipartEndpoints(doc, endpoints), logger);
1992
2080
  if (multipart.injected.length > 0) logger.info(` ${multipart.injected.length} multipart endpoint(s) (multipartFiles)`);
1993
2081
  const esm = api.config.esmExtensions === true;
1994
- const apiSource = extractModels({
1995
- apiSource: multipart.source,
1996
- apiFilePath: api.outputFile,
1997
- modelsDir,
1998
- registry,
1999
- files,
2000
- logger,
2001
- esm,
2002
- responseKinds,
2003
- documentModels: prepared.documentModels,
2004
- enumConsts: modelOptions.enums === "const",
2005
- constsByFile
2006
- });
2082
+ const apiSource = extractModels({ ...extractOptions, apiSource: multipart.source, responseKinds });
2007
2083
  if (!write) continue;
2008
2084
  const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints);
2009
2085
  files.set(api.outputFile, multipart.injected.length > 0 ? `${MULTIPART_IMPORT}
@@ -2119,4 +2195,4 @@ export {
2119
2195
  generateSdk,
2120
2196
  linkSkills
2121
2197
  };
2122
- //# sourceMappingURL=chunk-PZ6AAETR.js.map
2198
+ //# sourceMappingURL=chunk-J2RLNVKK.js.map