@mgamadeus/ddd-web 0.13.0 → 0.14.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 +8 -0
- package/dist/{chunk-J2RLNVKK.js → chunk-HVYT2X4V.js} +107 -3
- package/dist/chunk-HVYT2X4V.js.map +1 -0
- package/dist/codegen/cli.js +1 -1
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-J2RLNVKK.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. 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. 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,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `endpoints.requestBuilders: true`: the request builder of every endpoint (its `query`) goes into
|
|
7
|
+
`<stem>Requests.ts` next to the api file — `export const <stem>Requests = { <endpoint>: (queryArg: <Arg>): string |
|
|
8
|
+
FetchArgs => ({ url, params, body, … }) }` — and the endpoint uses it (`query: <stem>Requests.<endpoint>`). A bundle
|
|
9
|
+
that only builds requests imports that module without the endpoint injection. Off by default.
|
|
10
|
+
|
|
3
11
|
## 0.13.0
|
|
4
12
|
|
|
5
13
|
### Added
|
|
@@ -725,6 +725,101 @@ function replacePropertyTypes(body, typeTexts, requiredNames = /* @__PURE__ */ n
|
|
|
725
725
|
return result;
|
|
726
726
|
}
|
|
727
727
|
|
|
728
|
+
// src/codegen/request-builders.ts
|
|
729
|
+
function splitRequestBuilders(apiSource, requestsObjectName, requestsModuleSpecifier) {
|
|
730
|
+
const ts = loadTypeScript();
|
|
731
|
+
const sourceFile = ts.createSourceFile("api.ts", apiSource, ts.ScriptTarget.Latest, true);
|
|
732
|
+
const builders = [];
|
|
733
|
+
const replacements = [];
|
|
734
|
+
const visit = (node) => {
|
|
735
|
+
if (ts.isPropertyAssignment(node) && ts.isCallExpression(node.initializer)) {
|
|
736
|
+
const call = node.initializer;
|
|
737
|
+
const callee = call.expression;
|
|
738
|
+
const isBuildCall2 = ts.isPropertyAccessExpression(callee) && ["query", "mutation"].includes(callee.name.text) && ts.isIdentifier(callee.expression);
|
|
739
|
+
const definition = call.arguments[0];
|
|
740
|
+
if (isBuildCall2 && definition && ts.isObjectLiteralExpression(definition)) {
|
|
741
|
+
const endpointName = node.name.getText(sourceFile).replace(/^["']|["']$/g, "");
|
|
742
|
+
const queryProperty = definition.properties.find(
|
|
743
|
+
(property) => ts.isPropertyAssignment(property) && property.name.getText(sourceFile) === "query" && ts.isArrowFunction(property.initializer)
|
|
744
|
+
);
|
|
745
|
+
if (queryProperty && ts.isArrowFunction(queryProperty.initializer)) {
|
|
746
|
+
const builder = queryProperty.initializer;
|
|
747
|
+
const argType = call.typeArguments?.[1]?.getText(sourceFile);
|
|
748
|
+
const parameter = builder.parameters[0];
|
|
749
|
+
const parameterText = parameter && !parameter.type && argType && argType !== "void" ? `(${parameter.name.getText(sourceFile)}: ${argType})` : `(${builder.parameters.map((current) => current.getText(sourceFile)).join(", ")})`;
|
|
750
|
+
const bodyText = builder.body.getText(sourceFile);
|
|
751
|
+
builders.push({ name: endpointName, text: `${parameterText}: string | FetchArgs => ${bodyText}` });
|
|
752
|
+
replacements.push({
|
|
753
|
+
start: builder.getStart(sourceFile),
|
|
754
|
+
end: builder.getEnd(),
|
|
755
|
+
text: `${requestsObjectName}.${endpointName}`
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
ts.forEachChild(node, visit);
|
|
761
|
+
};
|
|
762
|
+
visit(sourceFile);
|
|
763
|
+
if (builders.length === 0) return { apiSource, requestsSource: "", count: 0 };
|
|
764
|
+
let replacedApiSource = apiSource;
|
|
765
|
+
for (const { start, end, text } of replacements.sort((a, b) => b.start - a.start)) {
|
|
766
|
+
replacedApiSource = replacedApiSource.slice(0, start) + text + replacedApiSource.slice(end);
|
|
767
|
+
}
|
|
768
|
+
const importDeclarations = sourceFile.statements.filter(ts.isImportDeclaration);
|
|
769
|
+
const importTexts = importDeclarations.map((declaration) => declaration.getText(sourceFile));
|
|
770
|
+
const requestsBody = `export const ${requestsObjectName} = {
|
|
771
|
+
` + builders.map(({ name, text }) => ` ${/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : JSON.stringify(name)}: ${text},`).join("\n") + "\n};\n";
|
|
772
|
+
const requestsSource = [
|
|
773
|
+
`import type { FetchArgs } from '@reduxjs/toolkit/query';`,
|
|
774
|
+
...keepUsedImports(ts, importTexts, requestsBody)
|
|
775
|
+
].join("\n") + `
|
|
776
|
+
|
|
777
|
+
${requestsBody}`;
|
|
778
|
+
const apiWithoutImports = stripImports(ts, replacedApiSource);
|
|
779
|
+
const apiImports = [
|
|
780
|
+
...keepUsedImports(ts, importTexts, apiWithoutImports),
|
|
781
|
+
`import { ${requestsObjectName} } from '${requestsModuleSpecifier}';`
|
|
782
|
+
];
|
|
783
|
+
return { apiSource: `${apiImports.join("\n")}
|
|
784
|
+
${apiWithoutImports}`, requestsSource, count: builders.length };
|
|
785
|
+
}
|
|
786
|
+
function stripImports(ts, source) {
|
|
787
|
+
const sourceFile = ts.createSourceFile("api.ts", source, ts.ScriptTarget.Latest, true);
|
|
788
|
+
let result = source;
|
|
789
|
+
for (const declaration of [...sourceFile.statements.filter(ts.isImportDeclaration)].reverse()) {
|
|
790
|
+
result = result.slice(0, declaration.getFullStart()) + result.slice(declaration.getEnd());
|
|
791
|
+
}
|
|
792
|
+
return result.replace(/^\s+/, "\n");
|
|
793
|
+
}
|
|
794
|
+
function keepUsedImports(ts, importTexts, body) {
|
|
795
|
+
const usedNames = /* @__PURE__ */ new Set();
|
|
796
|
+
const bodyFile = ts.createSourceFile("body.ts", body, ts.ScriptTarget.Latest, true);
|
|
797
|
+
const collect = (node) => {
|
|
798
|
+
if (ts.isIdentifier(node) && !(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) && !(ts.isPropertyAssignment(node.parent) && node.parent.name === node)) {
|
|
799
|
+
usedNames.add(node.text);
|
|
800
|
+
}
|
|
801
|
+
ts.forEachChild(node, collect);
|
|
802
|
+
};
|
|
803
|
+
collect(bodyFile);
|
|
804
|
+
const used = (name) => usedNames.has(name);
|
|
805
|
+
const kept = [];
|
|
806
|
+
for (const importText of importTexts) {
|
|
807
|
+
const sourceFile = ts.createSourceFile("import.ts", importText, ts.ScriptTarget.Latest, true);
|
|
808
|
+
const declaration = sourceFile.statements.find(ts.isImportDeclaration);
|
|
809
|
+
const bindings = declaration?.importClause?.namedBindings;
|
|
810
|
+
if (!declaration || !bindings || !ts.isNamedImports(bindings) || declaration.importClause?.name) {
|
|
811
|
+
kept.push(importText);
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
const elements = bindings.elements.filter((element) => used(element.name.text));
|
|
815
|
+
if (elements.length === 0) continue;
|
|
816
|
+
const typeOnly = declaration.importClause?.isTypeOnly ? "type " : "";
|
|
817
|
+
const specifier = declaration.moduleSpecifier.getText(sourceFile);
|
|
818
|
+
kept.push(`import ${typeOnly}{ ${elements.map((element) => element.getText(sourceFile)).join(", ")} } from ${specifier};`);
|
|
819
|
+
}
|
|
820
|
+
return kept;
|
|
821
|
+
}
|
|
822
|
+
|
|
728
823
|
// src/codegen/endpoints.ts
|
|
729
824
|
function toOpenApiPath(url) {
|
|
730
825
|
return url.replace(/\$\{encodeURIComponent\(String\(queryArg\.([A-Za-z0-9_]+)\)\)\}/g, "{$1}").replace(/\$\{queryArg\.([A-Za-z0-9_]+)\}/g, "{$1}");
|
|
@@ -2082,8 +2177,17 @@ async function generateSdk(options = {}) {
|
|
|
2082
2177
|
const apiSource = extractModels({ ...extractOptions, apiSource: multipart.source, responseKinds });
|
|
2083
2178
|
if (!write) continue;
|
|
2084
2179
|
const withHandlers = injectResponseHandlers(apiSource, handlerEndpoints);
|
|
2085
|
-
|
|
2086
|
-
${withHandlers}` : withHandlers
|
|
2180
|
+
const finalApiSource = multipart.injected.length > 0 ? `${MULTIPART_IMPORT}
|
|
2181
|
+
${withHandlers}` : withHandlers;
|
|
2182
|
+
if (loaded.config.endpoints?.requestBuilders) {
|
|
2183
|
+
const requestsStem = `${api.stem}Requests`;
|
|
2184
|
+
const split = splitRequestBuilders(finalApiSource, requestsStem, esm ? `./${requestsStem}.js` : `./${requestsStem}`);
|
|
2185
|
+
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) in ${requestsStem}.ts`);
|
|
2188
|
+
} else {
|
|
2189
|
+
files.set(api.outputFile, finalApiSource);
|
|
2190
|
+
}
|
|
2087
2191
|
const withExtension = (specifier) => esm ? `${specifier}.js` : specifier;
|
|
2088
2192
|
const enhanced = buildEnhancedEndpoints({
|
|
2089
2193
|
stem: api.stem,
|
|
@@ -2195,4 +2299,4 @@ export {
|
|
|
2195
2299
|
generateSdk,
|
|
2196
2300
|
linkSkills
|
|
2197
2301
|
};
|
|
2198
|
-
//# sourceMappingURL=chunk-
|
|
2302
|
+
//# sourceMappingURL=chunk-HVYT2X4V.js.map
|