@mgamadeus/ddd-web 0.6.0 → 0.6.2
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/SKILL.md +1 -1
- package/.claude/skills/ddd-web-specialist/references/consumer.md +4 -1
- package/CHANGELOG.md +20 -0
- package/dist/{chunk-XAROVCAW.js → chunk-RCXFU5IA.js} +137 -75
- package/dist/chunk-RCXFU5IA.js.map +1 -0
- package/dist/codegen/cli.js +1 -1
- package/dist/codegen/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-XAROVCAW.js.map +0 -1
|
@@ -3,7 +3,7 @@ name: ddd-web-specialist
|
|
|
3
3
|
description: "Use and maintain @mgamadeus/ddd-web, the TS client of mgamadeus/ddd: openapi-config.ts with defineConfig (schemaFile, sideEffects, responseHandlers, invalidation), the RTK Query SDK from ddd-web-sdk (Enhanced/Tags files, cache tags by entity identity, typed tagTypes via mergeDddTagTypes, downloads via blobResponseHandler, file uploads: multipartFiles argument, buildDddMultipartBody, upload with progress via baseQuery.upload), QueryOptions builders (buildQueryOptions, combineFilters, buildInFilter), createDddBaseQuery (Bearer, shared refresh + retry, relogin for sessions without refresh token, session-bound requests via getSessionKey, shouldRefresh, normalizeDddError), token storage, JWT helpers, link-skills, release. Use when wiring a frontend to a DDD backend, regenerating the SDK, building filters, uploading files, FormData, upload progress, fixing token refresh, guest login, a request sent under the wrong account after an account switch, stale cache tags, downloading an export, or releasing ddd-web."
|
|
4
4
|
metadata:
|
|
5
5
|
author: mgamadeus
|
|
6
|
-
version: "1.4.
|
|
6
|
+
version: "1.4.2"
|
|
7
7
|
package: "@mgamadeus/ddd-web"
|
|
8
8
|
---
|
|
9
9
|
|
|
@@ -96,7 +96,7 @@ Add a script: `"gen:sdk": "ddd-web-sdk"`. Commit the generated files and, if you
|
|
|
96
96
|
|---|---|
|
|
97
97
|
| `<stem>.ts` | RTK `injectEndpoints` on the base api: endpoints, hooks (names path-derived) |
|
|
98
98
|
| `<stem>Enhanced.ts` | `baseApi.enhanceEndpoints({ addTagTypes, endpoints })` — `providesTags` / `invalidatesTags`; import once |
|
|
99
|
-
| `<stem>Tags.ts` | `<stem>TagTypes` (const list) and `<Stem>TagType` (union) |
|
|
99
|
+
| `<stem>Tags.ts` | `<stem>TagTypes` (const list) and `<Stem>TagType` (union): the tags of the generated endpoints. A tag whose operations are all left out by `filterEndpoints` is not listed; hand-written endpoints name it as an own tag |
|
|
100
100
|
| `models/…` | one file per schema in its namespace folder (`App/Domain/…`), barrel `index.ts`; same leaf names in different namespaces get unique exported names |
|
|
101
101
|
|
|
102
102
|
Tag per endpoint: the entity of `x-ddd-entity` when present, else the operation tag, else the last path segment that
|
|
@@ -412,6 +412,9 @@ Idempotent; an existing symlink is repointed, a real file or directory is never
|
|
|
412
412
|
| `No tag for <endpoint> — no cache tags generated` | Operation without a matching tag: add a tag on the backend controller or an `endpointOverrides` |
|
|
413
413
|
| `--schema needs exactly one api` | Combine with `--api <exportName>` |
|
|
414
414
|
| `All apis must share one output directory when modelsDir is not set` | Set `modelsDir` |
|
|
415
|
+
| `Cannot find module 'ajv/dist/core'` (or another ajv 8 module) while the generator loads | A consumer with `legacy-peer-deps` and an `ajv` 6 at the top of `node_modules`: since 0.6.2 the generator answers the parser's `ajv` from its own `ajv` 8 — update the package |
|
|
416
|
+
| The type check is slow or reports errors your compiler does not | It ran another compiler: since 0.6.2 it takes the project's `typescript` through its package.json `bin` (TypeScript 7 included) and logs `Type check with TypeScript <version> (the project's compiler)` |
|
|
417
|
+
| A polling read aborts with no visible reason (`subscribe: false`, `keepUnusedDataFor: 0`) | The removal timer of the previous answer removes the cache entry and aborts the next identical read. Subscribe while the read runs and unsubscribe after the answer: `const read = dispatch(api.endpoints.x.initiate(arg, { forceRefetch: true })); try { return await read.unwrap(); } finally { read.unsubscribe(); }` |
|
|
415
418
|
| `type check failed — previous output restored` | Fix the reported type error (often app code using a renamed hook), or `--skip-tsc` to inspect |
|
|
416
419
|
| A list does not refresh after a write | `<stem>Enhanced.ts` not imported; or the write has no tag — see section 3 |
|
|
417
420
|
| A screen shows stale data after a write that changes more than its own entity | Writes invalidate by identity since 0.3 — add an `invalidation` resolver for that endpoint (section 3), or `broadInvalidation` for the 0.2 behaviour |
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.2
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- The generator loads in a consumer that installs with `legacy-peer-deps` and has `ajv` 6 at the top of
|
|
7
|
+
`node_modules`: the `ajv` lookups of `ajv-draft-04` (the OpenAPI parser's) are answered from the parser's own `ajv`
|
|
8
|
+
8, and the codegen is loaded after that hook.
|
|
9
|
+
- The closing type check runs the PROJECT's compiler, found through `typescript/package.json` `bin` (TypeScript 7
|
|
10
|
+
exports no `typescript/bin/tsc`; the check fell back silently to the codegen's older TypeScript), and logs which one
|
|
11
|
+
ran. The generator's own compiler only when the project has no `typescript`.
|
|
12
|
+
- Troubleshooting: a polling read with `subscribe: false` and `keepUnusedDataFor: 0` is aborted by the removal timer of
|
|
13
|
+
the previous answer — subscribe while the read runs, unsubscribe after the answer.
|
|
14
|
+
|
|
15
|
+
## 0.6.1
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- codegen: `<stem>Tags.ts` lists only the tags of the endpoints that are generated. A tag whose operations are all
|
|
19
|
+
left out by `filterEndpoints` (or by `skipUpdatePostTwins`) was still listed, although no generated endpoint
|
|
20
|
+
provides or invalidates it. **If hand-written endpoints use such a tag, name it as an own tag**:
|
|
21
|
+
`mergeDddTagTypes([...adminApiTagTypes], ['Tracks'])`.
|
|
22
|
+
|
|
3
23
|
## 0.6.0
|
|
4
24
|
|
|
5
25
|
### Changed
|
|
@@ -96,17 +96,17 @@ var SdkGenerationError = class extends Error {
|
|
|
96
96
|
var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
97
97
|
function listOperations(doc) {
|
|
98
98
|
const result = [];
|
|
99
|
-
for (const [
|
|
99
|
+
for (const [path11, item] of Object.entries(doc.paths ?? {})) {
|
|
100
100
|
if (!item) continue;
|
|
101
101
|
for (const method of HTTP_METHODS) {
|
|
102
102
|
const operation = item[method];
|
|
103
|
-
if (operation) result.push({ method, path:
|
|
103
|
+
if (operation) result.push({ method, path: path11, operation });
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
return result;
|
|
107
107
|
}
|
|
108
|
-
function operationKey(method,
|
|
109
|
-
return `${method.toUpperCase()} ${
|
|
108
|
+
function operationKey(method, path11) {
|
|
109
|
+
return `${method.toUpperCase()} ${path11}`;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
// src/codegen/tags.ts
|
|
@@ -163,9 +163,9 @@ function segmentToPascal(segment) {
|
|
|
163
163
|
if (/[A-Z]/.test(segment)) return segment;
|
|
164
164
|
return segment.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
165
165
|
}
|
|
166
|
-
function tagFromPath(
|
|
166
|
+
function tagFromPath(path11, lookup) {
|
|
167
167
|
let matched = null;
|
|
168
|
-
for (const segment of
|
|
168
|
+
for (const segment of path11.replace(/\{[^}]+\}/g, "").split("/").filter(Boolean)) {
|
|
169
169
|
matched = lookup.get(segmentToPascal(segment).toLowerCase()) ?? matched;
|
|
170
170
|
}
|
|
171
171
|
return matched;
|
|
@@ -177,11 +177,11 @@ function tagFromOperation(info, audience, lookup) {
|
|
|
177
177
|
}
|
|
178
178
|
return null;
|
|
179
179
|
}
|
|
180
|
-
function trailingPlaceholder(
|
|
181
|
-
return
|
|
180
|
+
function trailingPlaceholder(path11) {
|
|
181
|
+
return path11.match(/\{([^}]+)\}\/?$/)?.[1] ?? null;
|
|
182
182
|
}
|
|
183
|
-
function isPrimaryEntityPath(
|
|
184
|
-
const segments =
|
|
183
|
+
function isPrimaryEntityPath(path11, tag) {
|
|
184
|
+
const segments = path11.replace(/\{[^}]+\}\/?$/, "").split("/").filter(Boolean);
|
|
185
185
|
const last = segments[segments.length - 1];
|
|
186
186
|
return last !== void 0 && segmentToPascal(last).toLowerCase() === tag.toLowerCase();
|
|
187
187
|
}
|
|
@@ -220,9 +220,9 @@ function singularForms(tag) {
|
|
|
220
220
|
if (lower.endsWith("s")) forms.add(lower.slice(0, -1));
|
|
221
221
|
return [...forms];
|
|
222
222
|
}
|
|
223
|
-
function identityPathParameter(
|
|
223
|
+
function identityPathParameter(path11, tag) {
|
|
224
224
|
const singulars = singularForms(tag);
|
|
225
|
-
const segments =
|
|
225
|
+
const segments = path11.split("/").filter(Boolean);
|
|
226
226
|
let found = null;
|
|
227
227
|
segments.forEach((segment, index) => {
|
|
228
228
|
const name = segment.match(/^\{([^}]+)\}$/)?.[1];
|
|
@@ -368,7 +368,7 @@ function buildEnhancedEndpoints(input) {
|
|
|
368
368
|
const doc = input.doc ?? {};
|
|
369
369
|
const resolvers = input.invalidation ?? [];
|
|
370
370
|
const lookup = new Map(input.operationTags.map((tag) => [tag.toLowerCase(), tag]));
|
|
371
|
-
const allTags = new Set(
|
|
371
|
+
const allTags = /* @__PURE__ */ new Set();
|
|
372
372
|
const used = /* @__PURE__ */ new Set();
|
|
373
373
|
const lines = [];
|
|
374
374
|
let skipped = 0;
|
|
@@ -377,6 +377,10 @@ function buildEnhancedEndpoints(input) {
|
|
|
377
377
|
let wholeType = 0;
|
|
378
378
|
for (const endpoint of endpoints) {
|
|
379
379
|
const info = index.byKey.get(operationKey(endpoint.method, endpoint.path));
|
|
380
|
+
for (const raw of info?.operation.tags ?? []) {
|
|
381
|
+
const known = lookup.get(normalizeTag(raw, audience).toLowerCase());
|
|
382
|
+
if (known) allTags.add(known);
|
|
383
|
+
}
|
|
380
384
|
let tag;
|
|
381
385
|
if (info?.entity) {
|
|
382
386
|
tag = entityTag(info.entity.schema, lookup);
|
|
@@ -388,6 +392,7 @@ function buildEnhancedEndpoints(input) {
|
|
|
388
392
|
tag = tagFromPath(endpoint.path, lookup);
|
|
389
393
|
if (tag) urlFallbacks++;
|
|
390
394
|
}
|
|
395
|
+
if (tag) allTags.add(tag);
|
|
391
396
|
}
|
|
392
397
|
let expression = null;
|
|
393
398
|
if (endpoint.buildType === "query") {
|
|
@@ -523,7 +528,7 @@ function validateSpec(doc, source, logger) {
|
|
|
523
528
|
// src/codegen/generate.ts
|
|
524
529
|
import * as fs8 from "fs";
|
|
525
530
|
import * as os from "os";
|
|
526
|
-
import * as
|
|
531
|
+
import * as path9 from "path";
|
|
527
532
|
|
|
528
533
|
// src/codegen/typescript.ts
|
|
529
534
|
import { createRequire } from "module";
|
|
@@ -599,8 +604,8 @@ function readEndpoint(ts, key, buildType, call, sourceFile, location, logger) {
|
|
|
599
604
|
logger.warn(`No extractable URL for endpoint "${key}" \u2014 skipping.`);
|
|
600
605
|
return null;
|
|
601
606
|
}
|
|
602
|
-
const
|
|
603
|
-
const placeholders = [...
|
|
607
|
+
const path11 = location?.path ?? toOpenApiPath(url);
|
|
608
|
+
const placeholders = [...path11.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
|
|
604
609
|
const pathArgs = {};
|
|
605
610
|
placeholders.forEach((name, index) => {
|
|
606
611
|
const accessor = accessors[index];
|
|
@@ -611,7 +616,7 @@ function readEndpoint(ts, key, buildType, call, sourceFile, location, logger) {
|
|
|
611
616
|
buildType,
|
|
612
617
|
url,
|
|
613
618
|
method: (location?.method ?? method ?? "GET").toUpperCase(),
|
|
614
|
-
path:
|
|
619
|
+
path: path11,
|
|
615
620
|
pathArgs,
|
|
616
621
|
...bodyArg ? { bodyArg } : {},
|
|
617
622
|
...responseType ? { responseType } : {}
|
|
@@ -697,24 +702,46 @@ async function formatFiles(files) {
|
|
|
697
702
|
files.set(filePath, await prettier.format(files.get(filePath), { ...options, filepath: filePath }));
|
|
698
703
|
}
|
|
699
704
|
}
|
|
700
|
-
function
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
}
|
|
705
|
+
function resolveTscOfInstallation(base) {
|
|
706
|
+
let packageJsonPath;
|
|
707
|
+
try {
|
|
708
|
+
packageJsonPath = createRequire2(base).resolve("typescript/package.json");
|
|
709
|
+
} catch {
|
|
710
|
+
return null;
|
|
707
711
|
}
|
|
708
|
-
const
|
|
709
|
-
|
|
712
|
+
const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
|
|
713
|
+
const binEntry = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.tsc;
|
|
714
|
+
if (!binEntry) return null;
|
|
715
|
+
const executable = path3.resolve(path3.dirname(packageJsonPath), binEntry);
|
|
716
|
+
return fs4.existsSync(executable) ? { executable, version: packageJson.version ?? "unknown" } : null;
|
|
717
|
+
}
|
|
718
|
+
function resolveTypeScriptCompiler(rootDir) {
|
|
719
|
+
const projectCompiler = resolveTscOfInstallation(path3.join(rootDir, "package.json"));
|
|
720
|
+
if (projectCompiler) return { ...projectCompiler, origin: "project" };
|
|
721
|
+
const ownRequire = createRequire2(import.meta.url);
|
|
722
|
+
for (const base of [import.meta.url, ownRequire.resolve("@rtk-query/codegen-openapi")]) {
|
|
723
|
+
const generatorCompiler = resolveTscOfInstallation(base);
|
|
724
|
+
if (generatorCompiler) return { ...generatorCompiler, origin: "generator" };
|
|
725
|
+
}
|
|
726
|
+
throw new SdkGenerationError("No TypeScript compiler found for the type check (install typescript in the project, or pass --skip-tsc).");
|
|
727
|
+
}
|
|
728
|
+
function buildCompilerCommand(executable, args) {
|
|
729
|
+
if (/\.(c|m)?js$/.test(executable)) return [process.execPath, [executable, ...args]];
|
|
730
|
+
const head = fs4.readFileSync(executable).subarray(0, 100).toString("latin1");
|
|
731
|
+
return head.startsWith("#!") && head.split("\n", 1)[0].includes("node") ? [process.execPath, [executable, ...args]] : [executable, args];
|
|
710
732
|
}
|
|
711
733
|
function typecheck(rootDir, tsconfig, logger) {
|
|
712
734
|
if (!fs4.existsSync(tsconfig)) {
|
|
713
735
|
logger.warn(`No ${path3.relative(rootDir, tsconfig) || tsconfig} \u2014 skipping the type check.`);
|
|
714
736
|
return false;
|
|
715
737
|
}
|
|
738
|
+
const compiler = resolveTypeScriptCompiler(rootDir);
|
|
739
|
+
logger.info(
|
|
740
|
+
`Type check with TypeScript ${compiler.version} (${compiler.origin === "project" ? "the project's compiler" : "the generator's own compiler \u2014 the project has no typescript"}).`
|
|
741
|
+
);
|
|
742
|
+
const [command, args] = buildCompilerCommand(compiler.executable, ["--noEmit", "-p", tsconfig]);
|
|
716
743
|
try {
|
|
717
|
-
execFileSync(
|
|
744
|
+
execFileSync(command, args, {
|
|
718
745
|
cwd: rootDir,
|
|
719
746
|
stdio: ["ignore", "pipe", "pipe"],
|
|
720
747
|
encoding: "utf-8"
|
|
@@ -746,9 +773,9 @@ function testPattern(pattern, value) {
|
|
|
746
773
|
pattern.lastIndex = 0;
|
|
747
774
|
return result;
|
|
748
775
|
}
|
|
749
|
-
function matchesOperation(override, method,
|
|
776
|
+
function matchesOperation(override, method, path11) {
|
|
750
777
|
if (override.method && override.method.toLowerCase() !== method) return false;
|
|
751
|
-
return typeof override.path === "string" ? override.path ===
|
|
778
|
+
return typeof override.path === "string" ? override.path === path11 : testPattern(override.path, path11);
|
|
752
779
|
}
|
|
753
780
|
function canonical(value) {
|
|
754
781
|
return JSON.stringify(
|
|
@@ -772,9 +799,9 @@ function isEntityExtension(value) {
|
|
|
772
799
|
}
|
|
773
800
|
function indexOperations(doc, overrides, skipUpdatePostTwins) {
|
|
774
801
|
const byKey = /* @__PURE__ */ new Map();
|
|
775
|
-
for (const { method, path:
|
|
802
|
+
for (const { method, path: path11, operation } of listOperations(doc)) {
|
|
776
803
|
const extension = operation["x-ddd-side-effects"];
|
|
777
|
-
const override = overrides.find((candidate) => matchesOperation(candidate, method,
|
|
804
|
+
const override = overrides.find((candidate) => matchesOperation(candidate, method, path11));
|
|
778
805
|
let sideEffects = hasSideEffects(method, operation);
|
|
779
806
|
let explicit = false;
|
|
780
807
|
if (typeof extension === "boolean") {
|
|
@@ -788,9 +815,9 @@ function indexOperations(doc, overrides, skipUpdatePostTwins) {
|
|
|
788
815
|
const classifiedType = explicit ? sideEffects ? "mutation" : "query" : naturalType;
|
|
789
816
|
const endpointType = typeof extension !== "boolean" && override?.endpointType || classifiedType;
|
|
790
817
|
const entity = isEntityExtension(operation["x-ddd-entity"]) ? operation["x-ddd-entity"] : void 0;
|
|
791
|
-
byKey.set(operationKey(method,
|
|
818
|
+
byKey.set(operationKey(method, path11), {
|
|
792
819
|
method,
|
|
793
|
-
path:
|
|
820
|
+
path: path11,
|
|
794
821
|
operation,
|
|
795
822
|
sideEffects,
|
|
796
823
|
sideEffectsExplicit: explicit,
|
|
@@ -800,11 +827,11 @@ function indexOperations(doc, overrides, skipUpdatePostTwins) {
|
|
|
800
827
|
}
|
|
801
828
|
const skippedTwins = /* @__PURE__ */ new Set();
|
|
802
829
|
if (skipUpdatePostTwins) {
|
|
803
|
-
for (const [
|
|
830
|
+
for (const [path11, item] of Object.entries(doc.paths ?? {})) {
|
|
804
831
|
const post = item?.post;
|
|
805
832
|
const patch = item?.patch;
|
|
806
833
|
if (post && patch && isUpsertTwin(post, patch)) {
|
|
807
|
-
skippedTwins.add(operationKey("post",
|
|
834
|
+
skippedTwins.add(operationKey("post", path11));
|
|
808
835
|
}
|
|
809
836
|
}
|
|
810
837
|
}
|
|
@@ -858,10 +885,10 @@ function detectResponseKind(responses) {
|
|
|
858
885
|
}
|
|
859
886
|
function detectResponseHandlerEndpoints(doc, endpoints, overrides = []) {
|
|
860
887
|
const kinds = /* @__PURE__ */ new Map();
|
|
861
|
-
for (const { method, path:
|
|
862
|
-
const override = overrides.find((candidate) => matchesOperation(candidate, method,
|
|
888
|
+
for (const { method, path: path11, operation } of listOperations(doc)) {
|
|
889
|
+
const override = overrides.find((candidate) => matchesOperation(candidate, method, path11));
|
|
863
890
|
const kind = override ? override.handler : detectResponseKind(operation.responses);
|
|
864
|
-
if (kind !== "json") kinds.set(operationKey(method,
|
|
891
|
+
if (kind !== "json") kinds.set(operationKey(method, path11), kind);
|
|
865
892
|
}
|
|
866
893
|
const keys = /* @__PURE__ */ new Map();
|
|
867
894
|
if (kinds.size === 0) return keys;
|
|
@@ -1253,9 +1280,9 @@ function readMultipartOperation(doc, requestBody) {
|
|
|
1253
1280
|
}
|
|
1254
1281
|
function detectMultipartEndpoints(doc, endpoints) {
|
|
1255
1282
|
const byOperation = /* @__PURE__ */ new Map();
|
|
1256
|
-
for (const { method, path:
|
|
1283
|
+
for (const { method, path: path11, operation } of listOperations(doc)) {
|
|
1257
1284
|
const multipart = readMultipartOperation(doc, operation.requestBody);
|
|
1258
|
-
if (multipart) byOperation.set(operationKey(method,
|
|
1285
|
+
if (multipart) byOperation.set(operationKey(method, path11), multipart);
|
|
1259
1286
|
}
|
|
1260
1287
|
const keys = /* @__PURE__ */ new Map();
|
|
1261
1288
|
if (byOperation.size === 0) return keys;
|
|
@@ -1483,34 +1510,68 @@ function resolveParameter(doc, parameter) {
|
|
|
1483
1510
|
}
|
|
1484
1511
|
function repairMissingPathParameters(doc, logger) {
|
|
1485
1512
|
const repairs = [];
|
|
1486
|
-
for (const { method, path:
|
|
1487
|
-
const placeholders = [...
|
|
1513
|
+
for (const { method, path: path11, operation } of listOperations(doc)) {
|
|
1514
|
+
const placeholders = [...path11.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
|
|
1488
1515
|
if (placeholders.length === 0) continue;
|
|
1489
|
-
const pathLevel = doc.paths?.[
|
|
1516
|
+
const pathLevel = doc.paths?.[path11]?.parameters ?? [];
|
|
1490
1517
|
const declared = new Set(
|
|
1491
1518
|
[...pathLevel, ...operation.parameters ?? []].map((parameter) => resolveParameter(doc, parameter)).filter((parameter) => parameter !== null && parameter.in === "path").map((parameter) => parameter.name)
|
|
1492
1519
|
);
|
|
1493
1520
|
const missing = placeholders.filter((name) => !declared.has(name));
|
|
1494
|
-
if (missing.length > 0) repairs.push({ path:
|
|
1521
|
+
if (missing.length > 0) repairs.push({ path: path11, method, names: missing });
|
|
1495
1522
|
}
|
|
1496
1523
|
if (repairs.length === 0) return doc;
|
|
1497
1524
|
const copy = structuredClone(doc);
|
|
1498
|
-
for (const { path:
|
|
1499
|
-
const operation = copy.paths[
|
|
1525
|
+
for (const { path: path11, method, names } of repairs) {
|
|
1526
|
+
const operation = copy.paths[path11][method];
|
|
1500
1527
|
operation.parameters = [
|
|
1501
1528
|
...names.map((name) => ({ name, in: "path", required: true, schema: { type: "string" } })),
|
|
1502
1529
|
...operation.parameters ?? []
|
|
1503
1530
|
];
|
|
1504
|
-
logger.warn(`${method.toUpperCase()} ${
|
|
1531
|
+
logger.warn(`${method.toUpperCase()} ${path11}: path parameter(s) ${names.join(", ")} not declared in the spec \u2014 added as string.`);
|
|
1505
1532
|
}
|
|
1506
1533
|
return copy;
|
|
1507
1534
|
}
|
|
1508
1535
|
|
|
1509
1536
|
// src/codegen/rtk.ts
|
|
1510
1537
|
import * as fs6 from "fs";
|
|
1511
|
-
import * as
|
|
1512
|
-
import { generateEndpoints } from "@rtk-query/codegen-openapi";
|
|
1538
|
+
import * as path7 from "path";
|
|
1513
1539
|
import prettier2 from "prettier";
|
|
1540
|
+
|
|
1541
|
+
// src/codegen/module-resolution.ts
|
|
1542
|
+
import Module, { createRequire as createRequire3 } from "module";
|
|
1543
|
+
import * as path6 from "path";
|
|
1544
|
+
var installed = false;
|
|
1545
|
+
function installParserModuleResolution() {
|
|
1546
|
+
if (installed) return;
|
|
1547
|
+
installed = true;
|
|
1548
|
+
const require2 = createRequire3(import.meta.url);
|
|
1549
|
+
let parserRequire;
|
|
1550
|
+
try {
|
|
1551
|
+
const codegenRequire = createRequire3(require2.resolve("@rtk-query/codegen-openapi"));
|
|
1552
|
+
parserRequire = createRequire3(codegenRequire.resolve("@apidevtools/swagger-parser"));
|
|
1553
|
+
} catch {
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
const ajvDraft04Folder = `${path6.sep}ajv-draft-04${path6.sep}`;
|
|
1557
|
+
const moduleWithResolver = Module;
|
|
1558
|
+
const defaultResolveFilename = moduleWithResolver._resolveFilename;
|
|
1559
|
+
moduleWithResolver._resolveFilename = function resolveAjvOfTheParser(request, parent, ...rest) {
|
|
1560
|
+
if ((request === "ajv" || request.startsWith("ajv/")) && parent?.filename?.includes(ajvDraft04Folder)) {
|
|
1561
|
+
try {
|
|
1562
|
+
return parserRequire.resolve(request);
|
|
1563
|
+
} catch {
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
return defaultResolveFilename.call(this, request, parent, ...rest);
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
async function loadRtkCodegen() {
|
|
1570
|
+
installParserModuleResolution();
|
|
1571
|
+
return import("@rtk-query/codegen-openapi");
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
// src/codegen/rtk.ts
|
|
1514
1575
|
var OWN_KEYS = /* @__PURE__ */ new Set(["schemaFile", "apiFile", "outputFile", "audience", "baseApiImport", "skipUpdatePostTwins", "sideEffects", "responseHandlers", "invalidation"]);
|
|
1515
1576
|
function matches(matcher, name, definition) {
|
|
1516
1577
|
if (matcher === void 0) return true;
|
|
@@ -1536,7 +1597,7 @@ function mergeEndpointOverrides(userOverrides, typeOverrides) {
|
|
|
1536
1597
|
}
|
|
1537
1598
|
function relativeImport(fromDir, target) {
|
|
1538
1599
|
if (!isPathLike(target)) return target;
|
|
1539
|
-
let relative6 =
|
|
1600
|
+
let relative6 = path7.relative(fromDir, target).replace(/\\/g, "/");
|
|
1540
1601
|
if (!relative6.startsWith(".")) relative6 = `./${relative6}`;
|
|
1541
1602
|
return relative6;
|
|
1542
1603
|
}
|
|
@@ -1569,17 +1630,18 @@ async function runRtkCodegen(api, doc, index, specFile, prettierConfigFile) {
|
|
|
1569
1630
|
filterEndpoints,
|
|
1570
1631
|
...prettierConfigFile ? { prettierConfigFile } : {}
|
|
1571
1632
|
};
|
|
1572
|
-
const
|
|
1633
|
+
const { generateEndpoints: generateRtkEndpoints } = await loadRtkCodegen();
|
|
1634
|
+
const code = await generateRtkEndpoints(options);
|
|
1573
1635
|
if (typeof code !== "string") throw new Error(`RTK codegen returned no code for ${api.stem}.`);
|
|
1574
1636
|
return { code, locations };
|
|
1575
1637
|
}
|
|
1576
1638
|
async function findPrettierConfigFile(rootDir) {
|
|
1577
|
-
return await prettier2.resolveConfigFile(
|
|
1639
|
+
return await prettier2.resolveConfigFile(path7.join(rootDir, "openapi-config.ts")) ?? void 0;
|
|
1578
1640
|
}
|
|
1579
1641
|
|
|
1580
1642
|
// src/codegen/workspace.ts
|
|
1581
1643
|
import * as fs7 from "fs";
|
|
1582
|
-
import * as
|
|
1644
|
+
import * as path8 from "path";
|
|
1583
1645
|
import * as readline from "readline";
|
|
1584
1646
|
var DEFAULT_ENV_FILES = [".env", ".env.local"];
|
|
1585
1647
|
var DEFAULT_URL_KEYS = ["NEXT_PUBLIC_API_URL", "EXPO_PUBLIC_API_URL", "VITE_API_URL", "VITE_API_ENDPOINT", "API_URL"];
|
|
@@ -1604,7 +1666,7 @@ function firstHostLabel(url) {
|
|
|
1604
1666
|
}
|
|
1605
1667
|
function sniffWorkspace(rootDir, options) {
|
|
1606
1668
|
for (const file of options.envFiles ?? DEFAULT_ENV_FILES) {
|
|
1607
|
-
const vars = parseEnvFile(
|
|
1669
|
+
const vars = parseEnvFile(path8.join(rootDir, file));
|
|
1608
1670
|
for (const key of options.urlKeys ?? DEFAULT_URL_KEYS) {
|
|
1609
1671
|
const value = vars[key];
|
|
1610
1672
|
const label = value ? firstHostLabel(value) : null;
|
|
@@ -1614,11 +1676,11 @@ function sniffWorkspace(rootDir, options) {
|
|
|
1614
1676
|
return null;
|
|
1615
1677
|
}
|
|
1616
1678
|
function ask(question) {
|
|
1617
|
-
return new Promise((
|
|
1679
|
+
return new Promise((resolve7) => {
|
|
1618
1680
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1619
|
-
rl.on("close", () =>
|
|
1681
|
+
rl.on("close", () => resolve7(""));
|
|
1620
1682
|
rl.question(question, (answer) => {
|
|
1621
|
-
|
|
1683
|
+
resolve7(answer.trim());
|
|
1622
1684
|
rl.close();
|
|
1623
1685
|
});
|
|
1624
1686
|
});
|
|
@@ -1644,9 +1706,9 @@ async function resolveWorkspace(rootDir, options, explicit, logger) {
|
|
|
1644
1706
|
// src/codegen/generate.ts
|
|
1645
1707
|
async function load(options, cwd) {
|
|
1646
1708
|
if (options.config && typeof options.config === "object") {
|
|
1647
|
-
return { config: options.config, configPath:
|
|
1709
|
+
return { config: options.config, configPath: path9.join(cwd, "<inline config>"), rootDir: cwd };
|
|
1648
1710
|
}
|
|
1649
|
-
return loadConfig(
|
|
1711
|
+
return loadConfig(path9.resolve(cwd, options.config ?? "openapi-config.ts"));
|
|
1650
1712
|
}
|
|
1651
1713
|
function selectApis(all, options) {
|
|
1652
1714
|
let selected = all;
|
|
@@ -1658,14 +1720,14 @@ function selectApis(all, options) {
|
|
|
1658
1720
|
}
|
|
1659
1721
|
if (options.schema) {
|
|
1660
1722
|
if (selected.length !== 1) throw new SdkGenerationError("--schema needs exactly one api (use --api).");
|
|
1661
|
-
const schemaSource = isUrl(options.schema) ? options.schema :
|
|
1723
|
+
const schemaSource = isUrl(options.schema) ? options.schema : path9.resolve(options.cwd ?? process.cwd(), options.schema);
|
|
1662
1724
|
selected = [{ ...selected[0], schemaSource }];
|
|
1663
1725
|
}
|
|
1664
1726
|
return selected;
|
|
1665
1727
|
}
|
|
1666
1728
|
async function generateSdk(options = {}) {
|
|
1667
1729
|
const logger = options.logger ?? consoleLogger;
|
|
1668
|
-
const cwd =
|
|
1730
|
+
const cwd = path9.resolve(options.cwd ?? process.cwd());
|
|
1669
1731
|
let loaded = await load(options, cwd);
|
|
1670
1732
|
if (loaded.config.workspace) {
|
|
1671
1733
|
const value = await resolveWorkspace(loaded.rootDir, loaded.config.workspace, options.workspace, logger);
|
|
@@ -1712,14 +1774,14 @@ async function generateSdk(options = {}) {
|
|
|
1712
1774
|
const files = new OutputFiles();
|
|
1713
1775
|
if (steps.length < pipeline.length) files.seedFromDisk(modelsDir);
|
|
1714
1776
|
const prettierConfigFile = await findPrettierConfigFile(loaded.rootDir);
|
|
1715
|
-
const specDir = fs8.mkdtempSync(
|
|
1777
|
+
const specDir = fs8.mkdtempSync(path9.join(os.tmpdir(), "ddd-web-spec-"));
|
|
1716
1778
|
try {
|
|
1717
1779
|
for (const [i, { api, write, doc: rawDoc }] of steps.entries()) {
|
|
1718
1780
|
const doc = repairMissingPathParameters(rawDoc, logger);
|
|
1719
1781
|
logger.info(`\u2500\u2500 ${api.stem} (${i + 1}/${steps.length})${write ? "" : " (models only)"}`);
|
|
1720
1782
|
const index = indexOperations(doc, api.sideEffects, api.skipUpdatePostTwins);
|
|
1721
1783
|
if (index.skippedTwins.size > 0) logger.info(` skipping ${index.skippedTwins.size} POST twin(s) of PATCH upserts`);
|
|
1722
|
-
const rtk = await runRtkCodegen(api, doc, index,
|
|
1784
|
+
const rtk = await runRtkCodegen(api, doc, index, path9.join(specDir, `${i}.json`), prettierConfigFile);
|
|
1723
1785
|
const endpoints = parseApiEndpoints(rtk.code, logger, rtk.locations);
|
|
1724
1786
|
const handlerEndpoints = detectResponseHandlerEndpoints(doc, endpoints, api.responseHandlers);
|
|
1725
1787
|
const responseKinds = /* @__PURE__ */ new Map();
|
|
@@ -1761,8 +1823,8 @@ ${withHandlers}` : withHandlers);
|
|
|
1761
1823
|
invalidation: api.invalidation,
|
|
1762
1824
|
logger
|
|
1763
1825
|
});
|
|
1764
|
-
files.set(
|
|
1765
|
-
files.set(
|
|
1826
|
+
files.set(path9.join(api.outputDir, `${api.stem}Enhanced.ts`), enhanced.source);
|
|
1827
|
+
files.set(path9.join(api.outputDir, `${api.stem}Tags.ts`), renderTagsFile(api.stem, enhanced.tagTypes));
|
|
1766
1828
|
}
|
|
1767
1829
|
} finally {
|
|
1768
1830
|
fs8.rmSync(specDir, { recursive: true, force: true });
|
|
@@ -1776,7 +1838,7 @@ ${withHandlers}` : withHandlers);
|
|
|
1776
1838
|
if (!options.skipTsc) {
|
|
1777
1839
|
logger.info("type check (tsc --noEmit)");
|
|
1778
1840
|
try {
|
|
1779
|
-
typechecked = typecheck(loaded.rootDir,
|
|
1841
|
+
typechecked = typecheck(loaded.rootDir, path9.resolve(loaded.rootDir, loaded.config.tsconfig ?? "tsconfig.json"), logger);
|
|
1780
1842
|
} catch (error) {
|
|
1781
1843
|
committed.rollback();
|
|
1782
1844
|
logger.error("type check failed \u2014 previous output restored");
|
|
@@ -1790,11 +1852,11 @@ ${withHandlers}` : withHandlers);
|
|
|
1790
1852
|
|
|
1791
1853
|
// src/codegen/link-skills.ts
|
|
1792
1854
|
import * as fs9 from "fs";
|
|
1793
|
-
import * as
|
|
1855
|
+
import * as path10 from "path";
|
|
1794
1856
|
function packageLabel(packageDir) {
|
|
1795
1857
|
if (packageDir) {
|
|
1796
1858
|
try {
|
|
1797
|
-
const version = JSON.parse(fs9.readFileSync(
|
|
1859
|
+
const version = JSON.parse(fs9.readFileSync(path10.join(packageDir, "package.json"), "utf-8")).version;
|
|
1798
1860
|
if (typeof version === "string") return `@mgamadeus/ddd-web ${version}`;
|
|
1799
1861
|
} catch {
|
|
1800
1862
|
}
|
|
@@ -1802,10 +1864,10 @@ function packageLabel(packageDir) {
|
|
|
1802
1864
|
return "@mgamadeus/ddd-web";
|
|
1803
1865
|
}
|
|
1804
1866
|
function linkSkills(options = {}) {
|
|
1805
|
-
const cwd =
|
|
1867
|
+
const cwd = path10.resolve(options.cwd ?? process.cwd());
|
|
1806
1868
|
const logger = options.logger ?? consoleLogger;
|
|
1807
|
-
const packageDir =
|
|
1808
|
-
const sourceDir = options.sourceDir ?
|
|
1869
|
+
const packageDir = path10.join(cwd, "node_modules", "@mgamadeus", "ddd-web");
|
|
1870
|
+
const sourceDir = options.sourceDir ? path10.resolve(cwd, options.sourceDir) : path10.join(packageDir, ".claude", "skills");
|
|
1809
1871
|
if (!options.sourceDir && !fs9.existsSync(packageDir)) {
|
|
1810
1872
|
logger.warn(`@mgamadeus/ddd-web is not installed in ${cwd} (no ${packageDir}) \u2014 nothing to link.`);
|
|
1811
1873
|
return [];
|
|
@@ -1815,12 +1877,12 @@ function linkSkills(options = {}) {
|
|
|
1815
1877
|
logger.info(`${packageLabel(options.sourceDir ? void 0 : packageDir)} ships no agent skills (${sourceDir}) \u2014 nothing to link.`);
|
|
1816
1878
|
return [];
|
|
1817
1879
|
}
|
|
1818
|
-
const targetDir =
|
|
1880
|
+
const targetDir = path10.join(cwd, ".claude", "skills");
|
|
1819
1881
|
fs9.mkdirSync(targetDir, { recursive: true });
|
|
1820
1882
|
const results = [];
|
|
1821
1883
|
for (const entry of skills) {
|
|
1822
|
-
const linkPath =
|
|
1823
|
-
const linkTarget =
|
|
1884
|
+
const linkPath = path10.join(targetDir, entry.name);
|
|
1885
|
+
const linkTarget = path10.relative(targetDir, path10.join(sourceDir, entry.name));
|
|
1824
1886
|
let action;
|
|
1825
1887
|
const existing = fs9.lstatSync(linkPath, { throwIfNoEntry: false });
|
|
1826
1888
|
if (!existing) {
|
|
@@ -1856,4 +1918,4 @@ export {
|
|
|
1856
1918
|
generateSdk,
|
|
1857
1919
|
linkSkills
|
|
1858
1920
|
};
|
|
1859
|
-
//# sourceMappingURL=chunk-
|
|
1921
|
+
//# sourceMappingURL=chunk-RCXFU5IA.js.map
|