@kubb/plugin-faker 5.0.0-beta.100 → 5.0.0-beta.104
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/dist/index.cjs +56 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +56 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -647,6 +647,45 @@ function dedupeParams(params) {
|
|
|
647
647
|
//#endregion
|
|
648
648
|
//#region ../../internals/shared/src/operation.ts
|
|
649
649
|
/**
|
|
650
|
+
* Builds the `ResolverFileParams` every operation generator passes to
|
|
651
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
652
|
+
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
653
|
+
* that was repeated at dozens of call sites across the client and query plugins.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
function operationFileEntry(node, name, extname = ".ts") {
|
|
661
|
+
return {
|
|
662
|
+
name,
|
|
663
|
+
extname,
|
|
664
|
+
tag: node.tags[0] ?? "default",
|
|
665
|
+
path: node.path
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
|
|
670
|
+
* current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
|
|
671
|
+
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
672
|
+
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
673
|
+
*
|
|
674
|
+
* @example Cache `plugin-ts`'s file for the current operation
|
|
675
|
+
* ```ts
|
|
676
|
+
* const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
function resolveDependencyOperationFile(options) {
|
|
680
|
+
const { cache, node, resolver, root, output, group } = options;
|
|
681
|
+
return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
|
|
682
|
+
...operationFileEntry(node, node.operationId),
|
|
683
|
+
root,
|
|
684
|
+
output,
|
|
685
|
+
group: group ?? void 0
|
|
686
|
+
}));
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
650
689
|
* Maps a content type to the PascalCase suffix used to name per-content-type variants
|
|
651
690
|
* (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).
|
|
652
691
|
*/
|
|
@@ -694,13 +733,24 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
694
733
|
};
|
|
695
734
|
});
|
|
696
735
|
}
|
|
736
|
+
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
737
|
+
/**
|
|
738
|
+
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
739
|
+
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
740
|
+
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
741
|
+
* same parameters once per plugin.
|
|
742
|
+
*/
|
|
697
743
|
function getOperationParameters(node) {
|
|
698
|
-
|
|
744
|
+
const cached = operationParameterGroupsByNode.get(node);
|
|
745
|
+
if (cached) return cached;
|
|
746
|
+
const groups = {
|
|
699
747
|
path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
|
|
700
748
|
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
701
749
|
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
702
750
|
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
703
751
|
};
|
|
752
|
+
operationParameterGroupsByNode.set(node, groups);
|
|
753
|
+
return groups;
|
|
704
754
|
}
|
|
705
755
|
//#endregion
|
|
706
756
|
//#region ../../internals/shared/src/resolver.ts
|
|
@@ -1253,14 +1303,13 @@ const fakerGenerator = defineGenerator({
|
|
|
1253
1303
|
output,
|
|
1254
1304
|
group: group ?? void 0
|
|
1255
1305
|
}),
|
|
1256
|
-
typeFile:
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
path: node.path,
|
|
1306
|
+
typeFile: resolveDependencyOperationFile({
|
|
1307
|
+
cache: ctx.cache,
|
|
1308
|
+
node,
|
|
1309
|
+
resolver: tsResolver,
|
|
1261
1310
|
root,
|
|
1262
1311
|
output: pluginTs.options?.output ?? output,
|
|
1263
|
-
group: pluginTs.options?.group
|
|
1312
|
+
group: pluginTs.options?.group
|
|
1264
1313
|
})
|
|
1265
1314
|
};
|
|
1266
1315
|
function resolveMockImports(schema) {
|