zod-to-x 1.4.6-dev.1 → 1.4.6-dev.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.
@@ -1,4 +1,4 @@
1
- import { ASTCommon } from "./ast_common";
1
+ import { ASTCommon, ASTDefintion } from "./ast_common";
2
2
  /**
3
3
  * Handle ZodString
4
4
  */
@@ -29,7 +29,7 @@ export declare class ASTNumber extends ASTCommon {
29
29
  export declare class ASTLiteral extends ASTCommon {
30
30
  name?: string;
31
31
  value: any;
32
- parentEnumName?: string;
32
+ parentEnum?: ASTDefintion;
33
33
  parentEnumKey?: string;
34
34
  constructor(data: ASTLiteral & ASTCommon);
35
35
  }
@@ -32,7 +32,7 @@ class ASTLiteral extends ast_common_1.ASTCommon {
32
32
  super(data);
33
33
  this.name = data.name;
34
34
  this.value = data.value;
35
- this.parentEnumName = data.parentEnumName;
35
+ this.parentEnum = data.parentEnum;
36
36
  this.parentEnumKey = data.parentEnumKey;
37
37
  }
38
38
  }
@@ -416,7 +416,7 @@ class Zod2Ast {
416
416
  * @returns
417
417
  */
418
418
  _zodToAST(schema, opt) {
419
- var _a, _b, _c, _d, _e, _f, _g;
419
+ var _a, _b, _c, _d, _e;
420
420
  const def = schema._def;
421
421
  if (zod_helpers_1.ZodHelpers.isZodString(schema)) {
422
422
  return new core_1.ASTString({ description: schema.description });
@@ -474,17 +474,18 @@ class Zod2Ast {
474
474
  });
475
475
  }
476
476
  else if (zod_helpers_1.ZodHelpers.isZodLiteral(schema)) {
477
- let parentEnumName = undefined;
477
+ let parentEnum = undefined;
478
478
  let parentEnumKey = undefined;
479
479
  if ((_b = schema._zod2x) === null || _b === void 0 ? void 0 : _b.parentEnum) {
480
- parentEnumName = (_d = (_c = schema._zod2x) === null || _c === void 0 ? void 0 : _c.parentEnum._zod2x) === null || _d === void 0 ? void 0 : _d.typeName;
481
- parentEnumKey = (_f = this._getEnumValues((_e = schema._zod2x) === null || _e === void 0 ? void 0 : _e.parentEnum).find((i) => i[1] === def.value)) === null || _f === void 0 ? void 0 : _f[0];
482
- this._zodToAST((_g = schema._zod2x) === null || _g === void 0 ? void 0 : _g.parentEnum, { isInjectedEnum: true });
480
+ parentEnumKey = (_d = this._getEnumValues((_c = schema._zod2x) === null || _c === void 0 ? void 0 : _c.parentEnum).find((i) => i[1] === def.value)) === null || _d === void 0 ? void 0 : _d[0];
481
+ parentEnum = this._zodToAST((_e = schema._zod2x) === null || _e === void 0 ? void 0 : _e.parentEnum, {
482
+ isInjectedEnum: true,
483
+ });
483
484
  }
484
485
  return new core_1.ASTLiteral({
485
486
  value: def.value,
486
487
  description: schema.description,
487
- parentEnumName,
488
+ parentEnum: parentEnum,
488
489
  parentEnumKey,
489
490
  });
490
491
  }
@@ -87,8 +87,8 @@ class Zod2X {
87
87
  varType = this.getDateType();
88
88
  }
89
89
  else if (token instanceof core_1.ASTLiteral) {
90
- const parentEnum = token.parentEnumName && token.parentEnumKey
91
- ? [token.parentEnumName, token.parentEnumKey]
90
+ const parentEnum = token.parentEnumKey && token.parentEnum
91
+ ? [this.getAttributeType(token.parentEnum), token.parentEnumKey]
92
92
  : undefined;
93
93
  varType = this.getLiteralStringType(token.value, parentEnum);
94
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-to-x",
3
- "version": "1.4.6-dev.1",
3
+ "version": "1.4.6-dev.2",
4
4
  "description": "Multi language types generation from Zod schemas.",
5
5
  "main": "dist/index.js",
6
6
  "files": [