@mgamadeus/ddd-web 0.14.0 → 0.15.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 +1 -1
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-HVYT2X4V.js → chunk-6CQEUZ3B.js} +73 -43
- package/dist/chunk-6CQEUZ3B.js.map +1 -0
- package/dist/codegen/cli.js +1 -1
- package/dist/codegen/index.d.ts +8 -2
- package/dist/codegen/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-HVYT2X4V.js.map +0 -1
|
@@ -50,7 +50,7 @@ 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`. 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. `requestBuilders: true`: every endpoint's request builder goes into `<stem>Requests.ts` (`export const <stem>Requests = { <endpoint>: (queryArg: <Arg>): string \| FetchArgs => ({ url, params, body, … }) }`) and the endpoint uses it — a bundle that only builds requests imports that module without the endpoint injection. Query and path parameters stay flat in the argument. |
|
|
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. `requestBuilders: true`: every endpoint's request builder goes into `<stem>Requests.ts` (`export const <stem>Requests = { <endpoint>: (queryArg: <Arg>): string \| FetchArgs => ({ url, params, body, … }) }`) and the endpoint uses it — a bundle that only builds requests imports that module without the endpoint injection. `requestBuilders: 'all'`: the module holds the builder of every operation (their argument types are written) while `filterEndpoints` still decides what the api file injects. `cookieParameters: 'drop'` (default): parameters `in: cookie` leave the endpoints (a browser sends cookies itself; `FetchArgs` has no field for them); `'keep'` restores RTK's output. Query and path parameters stay flat in the argument. |
|
|
54
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
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `endpoints.requestBuilders: 'all'`: `<stem>Requests.ts` holds the request builder of every operation of the
|
|
7
|
+
document (their argument types are written), while the api file injects only what `filterEndpoints` keeps.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Parameters `in: cookie` leave the generated endpoints by default (`endpoints.cookieParameters: 'drop'`): a browser
|
|
11
|
+
sends its cookies itself and RTK Query's `FetchArgs` has no field for them — a request builder carrying `cookies`
|
|
12
|
+
failed the type check. `cookieParameters: 'keep'` restores the former output.
|
|
13
|
+
|
|
3
14
|
## 0.14.0
|
|
4
15
|
|
|
5
16
|
### Added
|
|
@@ -494,9 +494,13 @@ 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
|
+
const dropsCookieParameters = (options.cookieParameters ?? "drop") === "drop";
|
|
497
498
|
const endpointNamesByPlaceholder = /* @__PURE__ */ new Map();
|
|
498
|
-
if (naming === "rtk" && bodyArg === "rtk"
|
|
499
|
+
if (naming === "rtk" && bodyArg === "rtk" && !(dropsCookieParameters && hasCookieParameters(doc))) {
|
|
500
|
+
return { doc, endpointNamesByPlaceholder };
|
|
501
|
+
}
|
|
499
502
|
const prepared = structuredClone(doc);
|
|
503
|
+
if (dropsCookieParameters) dropCookieParameters(prepared);
|
|
500
504
|
const pathByName = /* @__PURE__ */ new Map();
|
|
501
505
|
for (const [path11, item] of Object.entries(prepared.paths ?? {})) {
|
|
502
506
|
if (!item) continue;
|
|
@@ -533,6 +537,35 @@ function restoreEndpointNames(code, locations, endpointNamesByPlaceholder) {
|
|
|
533
537
|
for (const [key, location] of locations) restoredLocations.set(restore(key), location);
|
|
534
538
|
return { code: restore(code), locations: restoredLocations };
|
|
535
539
|
}
|
|
540
|
+
var isCookieParameter = (parameter, doc) => {
|
|
541
|
+
const resolved = resolveParameter(parameter, doc);
|
|
542
|
+
return typeof resolved === "object" && resolved !== null && resolved.in === "cookie";
|
|
543
|
+
};
|
|
544
|
+
function resolveParameter(parameter, doc) {
|
|
545
|
+
const ref = parameter?.$ref;
|
|
546
|
+
if (typeof ref !== "string" || !ref.startsWith("#/components/parameters/")) return parameter;
|
|
547
|
+
return doc.components?.parameters?.[ref.slice("#/components/parameters/".length)];
|
|
548
|
+
}
|
|
549
|
+
function hasCookieParameters(doc) {
|
|
550
|
+
for (const item of Object.values(doc.paths ?? {})) {
|
|
551
|
+
if (!item) continue;
|
|
552
|
+
const lists = [item.parameters, ...HTTP_METHODS.map((method) => item[method]?.parameters)];
|
|
553
|
+
if (lists.some((list2) => Array.isArray(list2) && list2.some((parameter) => isCookieParameter(parameter, doc)))) return true;
|
|
554
|
+
}
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
function dropCookieParameters(doc) {
|
|
558
|
+
for (const item of Object.values(doc.paths ?? {})) {
|
|
559
|
+
if (!item) continue;
|
|
560
|
+
if (Array.isArray(item.parameters)) item.parameters = item.parameters.filter((parameter) => !isCookieParameter(parameter, doc));
|
|
561
|
+
for (const method of HTTP_METHODS) {
|
|
562
|
+
const operation = item[method];
|
|
563
|
+
if (operation && Array.isArray(operation.parameters)) {
|
|
564
|
+
operation.parameters = operation.parameters.filter((parameter) => !isCookieParameter(parameter, doc));
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
536
569
|
function titleRequestBody(operation) {
|
|
537
570
|
const content = operation.requestBody?.content;
|
|
538
571
|
for (const media of Object.values(content ?? {})) {
|
|
@@ -1836,7 +1869,7 @@ function buildRegistry(docs, logger) {
|
|
|
1836
1869
|
}
|
|
1837
1870
|
|
|
1838
1871
|
// src/codegen/repair.ts
|
|
1839
|
-
function
|
|
1872
|
+
function resolveParameter2(doc, parameter) {
|
|
1840
1873
|
let current = parameter;
|
|
1841
1874
|
for (let hops = 0; current?.$ref !== void 0 && hops < 10; hops++) {
|
|
1842
1875
|
const match = /^#\/components\/parameters\/(.+)$/.exec(current.$ref);
|
|
@@ -1853,7 +1886,7 @@ function repairMissingPathParameters(doc, logger) {
|
|
|
1853
1886
|
if (placeholders.length === 0) continue;
|
|
1854
1887
|
const pathLevel = doc.paths?.[path11]?.parameters ?? [];
|
|
1855
1888
|
const declared = new Set(
|
|
1856
|
-
[...pathLevel, ...operation.parameters ?? []].map((parameter) =>
|
|
1889
|
+
[...pathLevel, ...operation.parameters ?? []].map((parameter) => resolveParameter2(doc, parameter)).filter((parameter) => parameter !== null && parameter.in === "path").map((parameter) => parameter.name)
|
|
1857
1890
|
);
|
|
1858
1891
|
const missing = placeholders.filter((name) => !declared.has(name));
|
|
1859
1892
|
if (missing.length > 0) repairs.push({ path: path11, method, names: missing });
|
|
@@ -2126,22 +2159,15 @@ async function generateSdk(options = {}) {
|
|
|
2126
2159
|
const modelOptions = loaded.config.models ?? {};
|
|
2127
2160
|
const prepared = prepareDocumentForModels(doc, modelOptions);
|
|
2128
2161
|
const preparedEndpoints = prepareDocumentForEndpoints(prepared.doc, loaded.config.endpoints ?? {});
|
|
2129
|
-
const
|
|
2130
|
-
|
|
2131
|
-
preparedEndpoints.doc,
|
|
2132
|
-
index,
|
|
2133
|
-
path9.join(specDir, `${i}.json`),
|
|
2134
|
-
prettierConfigFile,
|
|
2135
|
-
(rtkName) => preparedEndpoints.endpointNamesByPlaceholder.get(rtkName) ?? rtkName
|
|
2136
|
-
);
|
|
2137
|
-
const rtk = restoreEndpointNames(generated.code, generated.locations, preparedEndpoints.endpointNamesByPlaceholder);
|
|
2162
|
+
const endpointOptions = loaded.config.endpoints ?? {};
|
|
2163
|
+
const esm = api.config.esmExtensions === true;
|
|
2138
2164
|
const extractOptions = {
|
|
2139
2165
|
apiFilePath: api.outputFile,
|
|
2140
2166
|
modelsDir,
|
|
2141
2167
|
registry,
|
|
2142
2168
|
files,
|
|
2143
2169
|
logger,
|
|
2144
|
-
esm
|
|
2170
|
+
esm,
|
|
2145
2171
|
documentModels: prepared.documentModels,
|
|
2146
2172
|
enumConsts: modelOptions.enums === "const",
|
|
2147
2173
|
constsByFile,
|
|
@@ -2149,42 +2175,46 @@ async function generateSdk(options = {}) {
|
|
|
2149
2175
|
writeIndex: modelOptions.index !== false,
|
|
2150
2176
|
uniqueNameByPath
|
|
2151
2177
|
};
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2178
|
+
const endpointNameOf = (rtkName) => preparedEndpoints.endpointNamesByPlaceholder.get(rtkName) ?? rtkName;
|
|
2179
|
+
const runPass = async (passApi, specName, modelsOnly) => {
|
|
2180
|
+
const generated = await runRtkCodegen(passApi, preparedEndpoints.doc, index, path9.join(specDir, specName), prettierConfigFile, endpointNameOf);
|
|
2181
|
+
const rtk = restoreEndpointNames(generated.code, generated.locations, preparedEndpoints.endpointNamesByPlaceholder);
|
|
2182
|
+
const endpoints2 = parseApiEndpoints(rtk.code, logger, rtk.locations);
|
|
2183
|
+
const handlerEndpoints2 = detectResponseHandlerEndpoints(doc, endpoints2, api.responseHandlers);
|
|
2184
|
+
const responseKinds = /* @__PURE__ */ new Map();
|
|
2185
|
+
for (const endpoint of endpoints2) {
|
|
2186
|
+
const kind = handlerEndpoints2.get(endpoint.key);
|
|
2187
|
+
if (kind && endpoint.responseType) responseKinds.set(endpoint.responseType, kind);
|
|
2188
|
+
}
|
|
2189
|
+
const multipart = injectMultipartBodies(rtk.code, detectMultipartEndpoints(doc, endpoints2), logger);
|
|
2190
|
+
const apiSource = extractModels({ ...extractOptions, apiSource: multipart.source, responseKinds, modelsOnly });
|
|
2191
|
+
const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints2);
|
|
2192
|
+
const finalApiSource2 = multipart.injected.length > 0 ? `${MULTIPART_IMPORT}
|
|
2193
|
+
${withHandlers}` : withHandlers;
|
|
2194
|
+
return { endpoints: endpoints2, handlerEndpoints: handlerEndpoints2, multipartCount: multipart.injected.length, finalApiSource: finalApiSource2 };
|
|
2195
|
+
};
|
|
2196
|
+
const buildersOfAllOperations = endpointOptions.requestBuilders === "all" && api.config.filterEndpoints !== void 0;
|
|
2197
|
+
let requestsSourceOfAllOperations = null;
|
|
2198
|
+
if ((modelOptions.scope === "all" || buildersOfAllOperations) && api.config.filterEndpoints !== void 0) {
|
|
2199
|
+
const unfiltered = await runPass({ ...api, config: { ...api.config, filterEndpoints: void 0 } }, `${i}-all.json`, !buildersOfAllOperations);
|
|
2200
|
+
if (buildersOfAllOperations) {
|
|
2201
|
+
const requestsStem = `${api.stem}Requests`;
|
|
2202
|
+
requestsSourceOfAllOperations = splitRequestBuilders(unfiltered.finalApiSource, requestsStem, `./${requestsStem}`).requestsSource;
|
|
2203
|
+
logger.info(" request builders of all operations (endpoints.requestBuilders all)");
|
|
2204
|
+
}
|
|
2205
|
+
if (modelOptions.scope === "all") logger.info(" models of all operations written (models.scope all)");
|
|
2171
2206
|
}
|
|
2207
|
+
const { endpoints, handlerEndpoints, multipartCount, finalApiSource } = await runPass(api, `${i}.json`, false);
|
|
2172
2208
|
const fileCount = [...handlerEndpoints.values()].filter((kind) => kind === "blob").length;
|
|
2173
2209
|
if (fileCount > 0) logger.info(` ${fileCount} file download endpoint(s) (blobResponseHandler)`);
|
|
2174
|
-
|
|
2175
|
-
if (multipart.injected.length > 0) logger.info(` ${multipart.injected.length} multipart endpoint(s) (multipartFiles)`);
|
|
2176
|
-
const esm = api.config.esmExtensions === true;
|
|
2177
|
-
const apiSource = extractModels({ ...extractOptions, apiSource: multipart.source, responseKinds });
|
|
2210
|
+
if (multipartCount > 0) logger.info(` ${multipartCount} multipart endpoint(s) (multipartFiles)`);
|
|
2178
2211
|
if (!write) continue;
|
|
2179
|
-
|
|
2180
|
-
const finalApiSource = multipart.injected.length > 0 ? `${MULTIPART_IMPORT}
|
|
2181
|
-
${withHandlers}` : withHandlers;
|
|
2182
|
-
if (loaded.config.endpoints?.requestBuilders) {
|
|
2212
|
+
if (endpointOptions.requestBuilders) {
|
|
2183
2213
|
const requestsStem = `${api.stem}Requests`;
|
|
2184
2214
|
const split = splitRequestBuilders(finalApiSource, requestsStem, esm ? `./${requestsStem}.js` : `./${requestsStem}`);
|
|
2185
2215
|
files.set(api.outputFile, split.apiSource);
|
|
2186
|
-
files.set(path9.join(api.outputDir, `${requestsStem}.ts`), split.requestsSource);
|
|
2187
|
-
logger.info(` ${split.count} request builder(s)
|
|
2216
|
+
files.set(path9.join(api.outputDir, `${requestsStem}.ts`), requestsSourceOfAllOperations ?? split.requestsSource);
|
|
2217
|
+
logger.info(` ${split.count} request builder(s) used by ${api.stem}.ts`);
|
|
2188
2218
|
} else {
|
|
2189
2219
|
files.set(api.outputFile, finalApiSource);
|
|
2190
2220
|
}
|
|
@@ -2299,4 +2329,4 @@ export {
|
|
|
2299
2329
|
generateSdk,
|
|
2300
2330
|
linkSkills
|
|
2301
2331
|
};
|
|
2302
|
-
//# sourceMappingURL=chunk-
|
|
2332
|
+
//# sourceMappingURL=chunk-6CQEUZ3B.js.map
|