@mgamadeus/ddd-web 0.9.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.
@@ -50,7 +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
- | `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. |
54
55
 
55
56
  ```ts
56
57
  export default defineConfig({
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
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
+
23
+ ## 0.10.0
24
+
25
+ ### Added
26
+ - Codegen option `endpoints` (off by default, output unchanged without it):
27
+ - `naming: 'path'`: endpoint (and hook) names as a pure function of verb and path — the prefix
28
+ (`stripPathPrefix`, default `/api` or `/app/api`) cut, every `{param}/` cut out and only the last one kept, the
29
+ rest capitalised behind the verb, `By<LastInner>` appended, a trailing `{param}` as `By<Param>` where it stands;
30
+ `naming` may also be a function. Two operations with the same name stop the run. `buildEndpointNameFromPath` is
31
+ exported.
32
+ - `bodyArg: 'requestBody'`: the request body is the argument's `requestBody`, independent of the DTO's schema
33
+ name.
34
+
3
35
  ## 0.9.0
4
36
 
5
37
  ### Added
@@ -476,6 +476,72 @@ function buildEnhancedEndpoints(input) {
476
476
  return { source, tagTypes: [...allTags].sort() };
477
477
  }
478
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
+ const endpointNamesByPlaceholder = /* @__PURE__ */ new Map();
498
+ if (naming === "rtk" && bodyArg === "rtk") return { doc, endpointNamesByPlaceholder };
499
+ const prepared = structuredClone(doc);
500
+ const pathByName = /* @__PURE__ */ new Map();
501
+ for (const [path11, item] of Object.entries(prepared.paths ?? {})) {
502
+ if (!item) continue;
503
+ for (const method of HTTP_METHODS) {
504
+ const operation = item[method];
505
+ if (!operation) continue;
506
+ if (naming !== "rtk") {
507
+ const name = naming === "path" ? buildEndpointNameFromPath(method, path11, options.stripPathPrefix) : naming({ method, path: path11, operation });
508
+ if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) {
509
+ throw new SdkGenerationError(`endpoints.naming: "${name}" (${method.toUpperCase()} ${path11}) is no identifier.`);
510
+ }
511
+ const other = pathByName.get(name);
512
+ if (other !== void 0) {
513
+ throw new SdkGenerationError(`endpoints.naming: ${other} and ${method.toUpperCase()} ${path11} are both named "${name}".`);
514
+ }
515
+ pathByName.set(name, `${method.toUpperCase()} ${path11}`);
516
+ const placeholder = `dddEndpoint${endpointNamesByPlaceholder.size}`;
517
+ endpointNamesByPlaceholder.set(placeholder, name);
518
+ operation.operationId = placeholder;
519
+ }
520
+ if (bodyArg === REQUEST_BODY_ARG) titleRequestBody(operation);
521
+ }
522
+ }
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 };
535
+ }
536
+ function titleRequestBody(operation) {
537
+ const content = operation.requestBody?.content;
538
+ for (const media of Object.values(content ?? {})) {
539
+ const schema = media?.schema;
540
+ if (!schema) continue;
541
+ media.schema = typeof schema.$ref === "string" ? { title: REQUEST_BODY_ARG, allOf: [{ $ref: schema.$ref }] } : { ...schema, title: REQUEST_BODY_ARG };
542
+ }
543
+ }
544
+
479
545
  // src/codegen/spec.ts
480
546
  import * as fs2 from "fs";
481
547
  var SUPPORTED_CONTRACT = { min: 1, max: 1 };
@@ -599,16 +665,21 @@ function findDocumentModel(rtkName, documentModels) {
599
665
  }
600
666
  function enumKeyOf(value) {
601
667
  if (value.trim() === "") return "EMPTY";
602
- const key = value.replace(/[ /\\]+/g, "_");
668
+ const key = value.replace(/-+([A-Za-z0-9])/g, (_, next) => next.toUpperCase()).replace(/[ /\\]+/g, "_");
603
669
  return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
604
670
  }
605
- function applyEnumConsts(body, modelName, schema) {
671
+ function applyEnumConsts(body, modelName, model, options = {}) {
672
+ const { schema, schemaKey } = model;
606
673
  const consts = /* @__PURE__ */ new Map();
607
674
  const typeTexts = /* @__PURE__ */ new Map();
675
+ const requiredNames = /* @__PURE__ */ new Set();
608
676
  for (const [propertyName2, property] of Object.entries(schema.properties ?? {})) {
609
677
  if (!isObject(property)) continue;
610
- const isArray = isObject(property.items) && Array.isArray(property.items.enum);
611
- 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");
612
683
  if (!values || values.length === 0) continue;
613
684
  const constName = `${modelName}${propertyName2.charAt(0).toUpperCase()}${propertyName2.slice(1)}`;
614
685
  if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(constName)) continue;
@@ -620,13 +691,15 @@ ${members}
620
691
  export const ${constName}Strict = {
621
692
  ${members}
622
693
  } as const;`);
623
- 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}]`;
624
696
  const nullable = property.nullable === true || (property.enum ?? []).includes(null);
625
697
  typeTexts.set(propertyName2, `${isArray ? `Array<${memberType}>` : memberType}${nullable ? " | null" : ""}`);
698
+ if (isObjectType) requiredNames.add(propertyName2);
626
699
  }
627
- return { body: replacePropertyTypes(body, typeTexts), consts };
700
+ return { body: replacePropertyTypes(body, typeTexts, requiredNames), consts };
628
701
  }
629
- function replacePropertyTypes(body, typeTexts) {
702
+ function replacePropertyTypes(body, typeTexts, requiredNames = /* @__PURE__ */ new Set()) {
630
703
  if (typeTexts.size === 0) return body;
631
704
  const ts = loadTypeScript();
632
705
  const sourceFile = ts.createSourceFile("model.ts", body, ts.ScriptTarget.Latest, true);
@@ -641,6 +714,9 @@ function replacePropertyTypes(body, typeTexts) {
641
714
  const name = ts.isIdentifier(member.name) || ts.isStringLiteral(member.name) ? member.name.text : member.name.getText(sourceFile);
642
715
  const text = typeTexts.get(name);
643
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
+ }
644
720
  }
645
721
  let result = body;
646
722
  for (const { start, end, text } of replacements.sort((a, b) => b.start - a.start)) {
@@ -1260,10 +1336,13 @@ function extractModels(input) {
1260
1336
  const documentModelByNewName = /* @__PURE__ */ new Map();
1261
1337
  const targetByNewName = /* @__PURE__ */ new Map();
1262
1338
  const nameByPath = /* @__PURE__ */ new Map();
1339
+ const exportNameByUniqueName = /* @__PURE__ */ new Map();
1340
+ const uniqueNameByPath = input.uniqueNameByPath ?? /* @__PURE__ */ new Map();
1263
1341
  for (const oldName of originalNames) {
1264
1342
  const { filePath, leafName, segments } = placement(oldName);
1265
1343
  const pathKey = path4.resolve(filePath).toLowerCase();
1266
- 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]);
1267
1346
  if (!name) {
1268
1347
  const owner = (candidate) => nameOwners.get(candidate);
1269
1348
  name = leafName;
@@ -1271,10 +1350,12 @@ function extractModels(input) {
1271
1350
  name = segments.slice(-depth).join("") + leafName;
1272
1351
  }
1273
1352
  if (owner(name) !== void 0 && owner(name) !== pathKey) name = oldName;
1274
- 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}`);
1275
1354
  }
1276
1355
  nameOwners.set(name, pathKey);
1277
1356
  nameByPath.set(pathKey, name);
1357
+ uniqueNameByPath.set(pathKey, name);
1358
+ exportNameByUniqueName.set(name, isDocumentModel ? leafName : name);
1278
1359
  renameMap.set(oldName, name);
1279
1360
  targetByNewName.set(name, filePath);
1280
1361
  const documentModel = findDocumentModel(oldName, documentModels);
@@ -1301,18 +1382,26 @@ function extractModels(input) {
1301
1382
  );
1302
1383
  const isPresentation = (filePath) => filePath.split(path4.sep).includes("Presentation");
1303
1384
  const barrelEntries = [];
1304
- for (const { name, body, filePath } of entries) {
1385
+ const exportNameOf = (uniqueName) => exportNameByUniqueName.get(uniqueName) ?? uniqueName;
1386
+ const writeIndex = input.writeIndex !== false;
1387
+ for (const { name: uniqueName, body: uniqueBody, filePath } of entries) {
1305
1388
  const dependencies = /* @__PURE__ */ new Set();
1306
1389
  if (dependencyRegex) {
1307
- for (const match of body.matchAll(new RegExp(dependencyRegex.source, "g"))) {
1308
- if (match[1] && match[1] !== name) dependencies.add(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]);
1309
1392
  }
1310
1393
  }
1311
- const kind = kindByName.get(name);
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);
1312
1401
  let typedBody = body;
1313
- const documentModel = documentModelByNewName.get(name);
1402
+ const documentModel = documentModelByNewName.get(uniqueName);
1314
1403
  if (input.enumConsts && documentModel) {
1315
- const applied = applyEnumConsts(body, name, documentModel.schema);
1404
+ const applied = applyEnumConsts(body, name, documentModel, input.modelOptions);
1316
1405
  typedBody = applied.body;
1317
1406
  const fileKey = path4.resolve(filePath).toLowerCase();
1318
1407
  const fileConsts2 = constsByFile.get(fileKey) ?? /* @__PURE__ */ new Map();
@@ -1329,9 +1418,11 @@ function extractModels(input) {
1329
1418
  }
1330
1419
  const importLines = [
1331
1420
  ...kind === "blob" ? [`import type { DddFileResponse } from '${DDD_WEB_API_IMPORT}';`] : [],
1332
- ...[...dependencies].map(
1333
- (dependency) => `import { ${dependency} } from '${importSpecifier(filePath, pathByName.get(dependency), esm)}';`
1334
- )
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
+ })
1335
1426
  ].join("\n");
1336
1427
  const existing = files.isGeneratedThisRun(filePath) ? files.get(filePath) : void 0;
1337
1428
  const content = existing !== void 0 ? mergeModel(existing, typedBody, importLines, name, logger) : (importLines ? `${importLines}
@@ -1343,14 +1434,24 @@ export default ${name};
1343
1434
  const fileConsts = constsByFile.get(path4.resolve(filePath).toLowerCase());
1344
1435
  files.set(filePath, fileConsts ? withEnumConsts(content, name, [...fileConsts.values()]) : content);
1345
1436
  if (isPresentation(path4.relative(modelsDir, filePath))) continue;
1437
+ if (name !== uniqueName) continue;
1346
1438
  barrelEntries.push(`export * from '${importSpecifier(indexPath, filePath, esm)}';`);
1347
1439
  }
1348
- writeBarrel(files, indexPath, barrelEntries);
1440
+ if (writeIndex) writeBarrel(files, indexPath, barrelEntries);
1349
1441
  const others = entries.filter((entry) => path4.relative(modelsDir, entry.filePath).split(path4.sep)[0] === "_others");
1350
1442
  if (others.length > 0) {
1351
1443
  logger.warn(`${others.length} type(s) without a namespace match placed in _others/: ${others.map((e) => e.name).join(", ")}`);
1352
1444
  }
1353
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
+ }
1354
1455
  const modelsImport = esm ? importSpecifier(input.apiFilePath, indexPath, true) : importSpecifier(input.apiFilePath, indexPath, false).replace(/\/index$/, "");
1355
1456
  return `import {
1356
1457
  ${usedInApi.join(",\n ")}
@@ -1742,17 +1843,19 @@ function relativeImport(fromDir, target) {
1742
1843
  if (!relative6.startsWith(".")) relative6 = `./${relative6}`;
1743
1844
  return relative6;
1744
1845
  }
1745
- async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile) {
1846
+ async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile, endpointNameOf = (rtkName) => rtkName) {
1746
1847
  fs6.writeFileSync(specFile, JSON.stringify(doc));
1747
1848
  const passthrough = {};
1748
1849
  for (const [key, value] of Object.entries(api.config)) if (!OWN_KEYS.has(key)) passthrough[key] = value;
1749
- 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
+ );
1750
1853
  const endpointOverrides = mergeEndpointOverrides(userOverrides, endpointTypeOverrides(index));
1751
1854
  const suffix = typeof passthrough.operationNameSuffix === "string" ? passthrough.operationNameSuffix : "";
1752
1855
  const locations = /* @__PURE__ */ new Map();
1753
1856
  const userFilter = passthrough.filterEndpoints;
1754
1857
  const filterEndpoints = (name, definition) => {
1755
- 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));
1756
1859
  if (included) {
1757
1860
  locations.set(suffix ? capitalize(name + suffix) : name, { method: definition.verb, path: definition.path });
1758
1861
  }
@@ -1916,6 +2019,7 @@ async function generateSdk(options = {}) {
1916
2019
  if (steps.length < pipeline.length) files.seedFromDisk(modelsDir);
1917
2020
  const prettierConfigFile = await findPrettierConfigFile(loaded.rootDir);
1918
2021
  const constsByFile = /* @__PURE__ */ new Map();
2022
+ const uniqueNameByPath = /* @__PURE__ */ new Map();
1919
2023
  const specDir = fs8.mkdtempSync(path9.join(os.tmpdir(), "ddd-web-spec-"));
1920
2024
  try {
1921
2025
  for (const [i, { api, write, doc: rawDoc }] of steps.entries()) {
@@ -1925,7 +2029,16 @@ async function generateSdk(options = {}) {
1925
2029
  if (index.skippedTwins.size > 0) logger.info(` skipping ${index.skippedTwins.size} POST twin(s) of PATCH upserts`);
1926
2030
  const modelOptions = loaded.config.models ?? {};
1927
2031
  const prepared = prepareDocumentForModels(doc, modelOptions);
1928
- const rtk = await runRtkCodegen(api, prepared.doc, index, path9.join(specDir, `${i}.json`), prettierConfigFile);
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);
1929
2042
  const endpoints = parseApiEndpoints(rtk.code, logger, rtk.locations);
1930
2043
  const handlerEndpoints = detectResponseHandlerEndpoints(doc, endpoints, api.responseHandlers);
1931
2044
  const responseKinds = /* @__PURE__ */ new Map();
@@ -1949,7 +2062,10 @@ async function generateSdk(options = {}) {
1949
2062
  responseKinds,
1950
2063
  documentModels: prepared.documentModels,
1951
2064
  enumConsts: modelOptions.enums === "const",
1952
- constsByFile
2065
+ constsByFile,
2066
+ modelOptions,
2067
+ writeIndex: modelOptions.index !== false,
2068
+ uniqueNameByPath
1953
2069
  });
1954
2070
  if (!write) continue;
1955
2071
  const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints);
@@ -2059,10 +2175,11 @@ export {
2059
2175
  silentLogger,
2060
2176
  SdkGenerationError,
2061
2177
  broadInvalidation,
2178
+ buildEndpointNameFromPath,
2062
2179
  SUPPORTED_CONTRACT,
2063
2180
  loadSpec,
2064
2181
  validateSpec,
2065
2182
  generateSdk,
2066
2183
  linkSkills
2067
2184
  };
2068
- //# sourceMappingURL=chunk-TPFRUK5O.js.map
2185
+ //# sourceMappingURL=chunk-XXMTSCOZ.js.map