@mgamadeus/ddd-web 0.11.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.
@@ -51,7 +51,7 @@ too). A plain RTK-codegen file with `export const apis = [...]` is accepted as w
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
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
+ | `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,17 @@
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
+
3
15
  ## 0.11.0
4
16
 
5
17
  ### Added
@@ -666,7 +666,7 @@ function findDocumentModel(rtkName, documentModels) {
666
666
  function enumKeyOf(value) {
667
667
  if (value.trim() === "") return "EMPTY";
668
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(key);
669
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(value);
670
670
  }
671
671
  function applyEnumConsts(body, modelName, model, options = {}) {
672
672
  const { schema, schemaKey } = model;
@@ -1372,6 +1372,7 @@ function extractModels(input) {
1372
1372
  logger.warn(`Re-extracted type "${name}" not in rename map \u2014 skipping.`);
1373
1373
  continue;
1374
1374
  }
1375
+ if (input.modelsOnly && path4.relative(modelsDir, filePath).split(path4.sep)[0] === "_endpoints") continue;
1375
1376
  entries.push({ name, body: text, filePath });
1376
1377
  }
1377
1378
  const pathByName = new Map(entries.map((entry) => [entry.name, entry.filePath]));
@@ -1405,7 +1406,7 @@ function extractModels(input) {
1405
1406
  typedBody = applied.body;
1406
1407
  const fileKey = path4.resolve(filePath).toLowerCase();
1407
1408
  const fileConsts2 = constsByFile.get(fileKey) ?? /* @__PURE__ */ new Map();
1408
- 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);
1409
1410
  if (fileConsts2.size > 0) constsByFile.set(fileKey, fileConsts2);
1410
1411
  }
1411
1412
  if (kind === "text") {
@@ -2039,6 +2040,33 @@ async function generateSdk(options = {}) {
2039
2040
  (rtkName) => preparedEndpoints.endpointNamesByPlaceholder.get(rtkName) ?? rtkName
2040
2041
  );
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
+ }
2042
2070
  const endpoints = parseApiEndpoints(rtk.code, logger, rtk.locations);
2043
2071
  const handlerEndpoints = detectResponseHandlerEndpoints(doc, endpoints, api.responseHandlers);
2044
2072
  const responseKinds = /* @__PURE__ */ new Map();
@@ -2051,22 +2079,7 @@ async function generateSdk(options = {}) {
2051
2079
  const multipart = injectMultipartBodies(rtk.code, detectMultipartEndpoints(doc, endpoints), logger);
2052
2080
  if (multipart.injected.length > 0) logger.info(` ${multipart.injected.length} multipart endpoint(s) (multipartFiles)`);
2053
2081
  const esm = api.config.esmExtensions === true;
2054
- const apiSource = extractModels({
2055
- apiSource: multipart.source,
2056
- apiFilePath: api.outputFile,
2057
- modelsDir,
2058
- registry,
2059
- files,
2060
- logger,
2061
- esm,
2062
- responseKinds,
2063
- documentModels: prepared.documentModels,
2064
- enumConsts: modelOptions.enums === "const",
2065
- constsByFile,
2066
- modelOptions,
2067
- writeIndex: modelOptions.index !== false,
2068
- uniqueNameByPath
2069
- });
2082
+ const apiSource = extractModels({ ...extractOptions, apiSource: multipart.source, responseKinds });
2070
2083
  if (!write) continue;
2071
2084
  const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints);
2072
2085
  files.set(api.outputFile, multipart.injected.length > 0 ? `${MULTIPART_IMPORT}
@@ -2182,4 +2195,4 @@ export {
2182
2195
  generateSdk,
2183
2196
  linkSkills
2184
2197
  };
2185
- //# sourceMappingURL=chunk-XXMTSCOZ.js.map
2198
+ //# sourceMappingURL=chunk-J2RLNVKK.js.map