@kubb/plugin-faker 5.0.0-beta.85 → 5.0.0-beta.87

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 CHANGED
@@ -135,7 +135,7 @@ const reservedWords = /* @__PURE__ */ new Set([
135
135
  */
136
136
  function isValidVarName(name) {
137
137
  if (!name || reservedWords.has(name)) return false;
138
- return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
138
+ return isIdentifier(name);
139
139
  }
140
140
  /**
141
141
  * Returns `name` when it's a syntactically valid JavaScript variable name,
@@ -488,7 +488,6 @@ const SCALAR_TYPES$1 = /* @__PURE__ */ new Set([
488
488
  "blob",
489
489
  "enum"
490
490
  ]);
491
- const ARRAY_TYPES$1 = /* @__PURE__ */ new Set(["array"]);
492
491
  function toRelativeImportPath(from, to) {
493
492
  const relativePath = node_path.posix.relative(node_path.posix.dirname(from), to);
494
493
  return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
@@ -533,7 +532,7 @@ function getScalarType(node, typeName) {
533
532
  * Determines the data type, return type, and whether it uses the type name.
534
533
  */
535
534
  function resolveFakerTypeUsage(node, typeName, canOverride) {
536
- const isArray = ARRAY_TYPES$1.has(node.type);
535
+ const isArray = node.type === "array";
537
536
  const isTuple = node.type === "tuple";
538
537
  const isScalar = SCALAR_TYPES$1.has(node.type);
539
538
  let dataType = `Partial<${typeName}>`;
@@ -550,7 +549,6 @@ function resolveFakerTypeUsage(node, typeName, canOverride) {
550
549
  //#endregion
551
550
  //#region src/components/Faker.tsx
552
551
  const OBJECT_TYPES = /* @__PURE__ */ new Set(["object", "intersection"]);
553
- const ARRAY_TYPES = /* @__PURE__ */ new Set(["array"]);
554
552
  const SCALAR_TYPES = /* @__PURE__ */ new Set([
555
553
  "string",
556
554
  "email",
@@ -569,7 +567,7 @@ const SCALAR_TYPES = /* @__PURE__ */ new Set([
569
567
  const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
570
568
  function Faker({ node, description, name, typeName, printer, seed, canOverride }) {
571
569
  const fakerText = printer.print(node) ?? "undefined";
572
- const isArray = ARRAY_TYPES.has(node.type);
570
+ const isArray = node.type === "array";
573
571
  const isObject = OBJECT_TYPES.has(node.type);
574
572
  const isTuple = node.type === "tuple";
575
573
  const isScalar = SCALAR_TYPES.has(node.type);
@@ -730,6 +728,24 @@ function getOperationParameters(node, options = {}) {
730
728
  };
731
729
  }
732
730
  //#endregion
731
+ //#region ../../internals/shared/src/adapter.ts
732
+ /**
733
+ * Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
734
+ * so OAS-only options (`dateType`, `nameMapping`) and the parsed `document` are typed.
735
+ *
736
+ * Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
737
+ * clear, actionable error at the point of use.
738
+ *
739
+ * @example
740
+ * ```ts
741
+ * const { dateType } = getOasAdapter(ctx.adapter).options
742
+ * ```
743
+ */
744
+ function getOasAdapter(adapter) {
745
+ if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
746
+ return adapter;
747
+ }
748
+ //#endregion
733
749
  //#region ../../internals/shared/src/group.ts
734
750
  /**
735
751
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
@@ -1015,7 +1031,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1015
1031
  regexGenerator,
1016
1032
  nodes: printer?.nodes,
1017
1033
  cyclicSchemas,
1018
- nameMapping: adapter.options.nameMapping
1034
+ nameMapping: getOasAdapter(adapter).options.nameMapping
1019
1035
  });
1020
1036
  const fakerText = printerInstance.print(node) ?? "undefined";
1021
1037
  const typeReference = resolveTypeReference({
@@ -1222,7 +1238,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1222
1238
  regexGenerator,
1223
1239
  nodes: printer?.nodes,
1224
1240
  cyclicSchemas,
1225
- nameMapping: adapter.options.nameMapping
1241
+ nameMapping: getOasAdapter(adapter).options.nameMapping
1226
1242
  });
1227
1243
  const fakerText = printerInstance.print(schema) ?? "undefined";
1228
1244
  const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);
@@ -1396,7 +1412,7 @@ const pluginFakerName = "plugin-faker";
1396
1412
  * import { pluginFaker } from '@kubb/plugin-faker'
1397
1413
  *
1398
1414
  * export default defineConfig({
1399
- * input: { path: './petStore.yaml' },
1415
+ * input: './petStore.yaml',
1400
1416
  * output: { path: './src/gen' },
1401
1417
  * plugins: [
1402
1418
  * pluginTs(),