@kubb/plugin-faker 5.0.0-beta.95 → 5.0.0-beta.99
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 +49 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -10
- package/dist/index.js +49 -46
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
3
|
import { KubbReactNode } from "kubb/jsx";
|
|
4
|
-
|
|
5
4
|
//#region src/types.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Resolver for Faker that provides naming methods for mock functions.
|
|
@@ -234,15 +233,7 @@ type Props = {
|
|
|
234
233
|
description?: string;
|
|
235
234
|
canOverride: boolean;
|
|
236
235
|
};
|
|
237
|
-
declare function Faker({
|
|
238
|
-
node,
|
|
239
|
-
description,
|
|
240
|
-
name,
|
|
241
|
-
typeName,
|
|
242
|
-
printer,
|
|
243
|
-
seed,
|
|
244
|
-
canOverride
|
|
245
|
-
}: Props): KubbReactNode;
|
|
236
|
+
declare function Faker({ node, description, name, typeName, printer, seed, canOverride }: Props): KubbReactNode;
|
|
246
237
|
//#endregion
|
|
247
238
|
//#region src/generators/fakerGenerator.d.ts
|
|
248
239
|
/**
|
package/dist/index.js
CHANGED
|
@@ -628,39 +628,19 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
|
|
|
628
628
|
}
|
|
629
629
|
//#endregion
|
|
630
630
|
//#region ../../internals/shared/src/params.ts
|
|
631
|
-
const caseParamsCache = /* @__PURE__ */ new WeakMap();
|
|
632
631
|
/**
|
|
633
|
-
*
|
|
632
|
+
* Drops parameters that share the same name, keeping the first.
|
|
634
633
|
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
634
|
+
* A malformed spec can declare the same parameter name twice within one `in` location. Both would
|
|
635
|
+
* resolve to the same output property, so emitting both would yield an object type with a duplicate
|
|
636
|
+
* member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
|
|
637
|
+
* parameter names flow through unchanged, so no two distinct names ever collide here anymore.
|
|
638
638
|
*/
|
|
639
|
-
function
|
|
640
|
-
if (!casing) return params;
|
|
641
|
-
const cached = caseParamsCache.get(params);
|
|
642
|
-
if (cached) return cached;
|
|
643
|
-
const result = params.map((param) => ({
|
|
644
|
-
...param,
|
|
645
|
-
name: camelCase(param.name)
|
|
646
|
-
}));
|
|
647
|
-
caseParamsCache.set(params, result);
|
|
648
|
-
return result;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Drops parameters that collapse to the same property identity once camelCased, keeping the first.
|
|
652
|
-
*
|
|
653
|
-
* Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
|
|
654
|
-
* `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
|
|
655
|
-
* an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
|
|
656
|
-
* identity so the resulting group is collision-free regardless of the names each caller carries.
|
|
657
|
-
*/
|
|
658
|
-
function dedupeByCasedName(params) {
|
|
639
|
+
function dedupeParams(params) {
|
|
659
640
|
const seen = /* @__PURE__ */ new Set();
|
|
660
641
|
return params.filter((param) => {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
seen.add(key);
|
|
642
|
+
if (seen.has(param.name)) return false;
|
|
643
|
+
seen.add(param.name);
|
|
664
644
|
return true;
|
|
665
645
|
});
|
|
666
646
|
}
|
|
@@ -714,13 +694,15 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
714
694
|
};
|
|
715
695
|
});
|
|
716
696
|
}
|
|
717
|
-
function getOperationParameters(node
|
|
718
|
-
const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
|
|
697
|
+
function getOperationParameters(node) {
|
|
719
698
|
return {
|
|
720
|
-
path:
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
699
|
+
path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
|
|
700
|
+
...param,
|
|
701
|
+
name: camelCase(param.name)
|
|
702
|
+
})),
|
|
703
|
+
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
704
|
+
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
705
|
+
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
724
706
|
};
|
|
725
707
|
}
|
|
726
708
|
//#endregion
|
|
@@ -830,6 +812,28 @@ function createGroupConfig(group) {
|
|
|
830
812
|
};
|
|
831
813
|
}
|
|
832
814
|
//#endregion
|
|
815
|
+
//#region ../../internals/shared/src/schemaTraversal.ts
|
|
816
|
+
/**
|
|
817
|
+
* Maps each member of a union or intersection schema to its transformed output, pairing every
|
|
818
|
+
* result with the original member.
|
|
819
|
+
*/
|
|
820
|
+
function mapSchemaMembers(node, transform) {
|
|
821
|
+
return (node.members ?? []).map((schema) => ({
|
|
822
|
+
schema,
|
|
823
|
+
output: transform(schema)
|
|
824
|
+
}));
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Maps each item of an array or tuple schema to its transformed output, pairing every result with
|
|
828
|
+
* the original item.
|
|
829
|
+
*/
|
|
830
|
+
function mapSchemaItems(node, transform) {
|
|
831
|
+
return (node.items ?? []).map((schema) => ({
|
|
832
|
+
schema,
|
|
833
|
+
output: transform(schema)
|
|
834
|
+
}));
|
|
835
|
+
}
|
|
836
|
+
//#endregion
|
|
833
837
|
//#region src/printers/printerFaker.ts
|
|
834
838
|
const fakerKeywordMapper = {
|
|
835
839
|
any: () => "undefined",
|
|
@@ -981,12 +985,15 @@ const printerFaker = ast.createPrinter((options) => {
|
|
|
981
985
|
union(node) {
|
|
982
986
|
const { discriminatorPropertyName } = node;
|
|
983
987
|
const baseTypeName = this.options.typeName;
|
|
984
|
-
const items =
|
|
988
|
+
const items = mapSchemaMembers(node, (member) => {
|
|
985
989
|
const value = discriminatorPropertyName ? getDiscriminatorValue(member, discriminatorPropertyName) : void 0;
|
|
986
|
-
if (baseTypeName && value !== void 0)
|
|
987
|
-
typeName
|
|
988
|
-
|
|
989
|
-
|
|
990
|
+
if (baseTypeName && value !== void 0) {
|
|
991
|
+
const typeName = `Extract<NonNullable<${baseTypeName}>, { ${JSON.stringify(discriminatorPropertyName)}: ${parseEnumValue(value)} }>`;
|
|
992
|
+
return printNested(member, {
|
|
993
|
+
typeName,
|
|
994
|
+
nestedInObject: true
|
|
995
|
+
});
|
|
996
|
+
}
|
|
990
997
|
return printNested(member, {
|
|
991
998
|
typeName: baseTypeName,
|
|
992
999
|
nestedInObject: true,
|
|
@@ -996,11 +1003,11 @@ const printerFaker = ast.createPrinter((options) => {
|
|
|
996
1003
|
return fakerKeywordMapper.union(items);
|
|
997
1004
|
},
|
|
998
1005
|
intersection(node) {
|
|
999
|
-
const items =
|
|
1006
|
+
const items = mapSchemaMembers(node, (member) => printNested(member, { nestedInObject: true })).map(({ output }) => output).filter((item) => Boolean(item) && item !== "undefined");
|
|
1000
1007
|
return fakerKeywordMapper.and(items);
|
|
1001
1008
|
},
|
|
1002
1009
|
array(node) {
|
|
1003
|
-
const items =
|
|
1010
|
+
const items = mapSchemaItems(node, (member) => printNested(member, {
|
|
1004
1011
|
typeName: this.options.typeName ? `NonNullable<${this.options.typeName}>[number]` : void 0,
|
|
1005
1012
|
nestedInObject: true
|
|
1006
1013
|
})).map(({ output }) => output).filter((item) => Boolean(item));
|
|
@@ -1169,11 +1176,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1169
1176
|
const pluginTs = ctx.driver.getPlugin(pluginTsName);
|
|
1170
1177
|
if (!pluginTs) return;
|
|
1171
1178
|
const tsResolver = ctx.driver.getResolver(pluginTsName);
|
|
1172
|
-
const
|
|
1173
|
-
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters({
|
|
1174
|
-
...node,
|
|
1175
|
-
parameters: params
|
|
1176
|
-
}, { paramsCasing: "original" });
|
|
1179
|
+
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node);
|
|
1177
1180
|
const paramGroups = [
|
|
1178
1181
|
{
|
|
1179
1182
|
params: pathParams,
|