@hg-ts/validation 0.1.15 → 0.1.17

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/.eslintcache CHANGED
@@ -1 +1 @@
1
- [{"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.not-found.exception.ts":"1","/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.provider.ts":"2","/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.test-suite.ts":"3","/Volumes/Work/ts/hg/framework/packages/async-context/src/index.ts":"4","/Volumes/Work/ts/hg/framework/packages/validation/src/extensions.ts":"5","/Volumes/Work/ts/hg/framework/packages/validation/src/index.ts":"6"},{"size":186,"mtime":1698022585968,"results":"7","hashOfConfig":"8"},{"size":2161,"mtime":1698022585968,"results":"9","hashOfConfig":"8"},{"size":3714,"mtime":1698022585968,"results":"10","hashOfConfig":"8"},{"size":95,"mtime":1698022585968,"results":"11","hashOfConfig":"8"},{"size":1062,"mtime":1713665782754,"results":"12","hashOfConfig":"13"},{"size":88,"mtime":1713662918071,"results":"14","hashOfConfig":"13"},{"filePath":"15","messages":"16","suppressedMessages":"17","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1o9szx6",{"filePath":"18","messages":"19","suppressedMessages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"21","messages":"22","suppressedMessages":"23","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","suppressedMessages":"26","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"27","messages":"28","suppressedMessages":"29","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"xqlb75",{"filePath":"30","messages":"31","suppressedMessages":"32","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.not-found.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.provider.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.test-suite.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/validation/src/extensions.ts",[],["33"],"/Volumes/Work/ts/hg/framework/packages/validation/src/index.ts",[],[],{"ruleId":"34","severity":2,"message":"35","line":13,"column":12,"nodeType":"36","messageId":"37","endLine":13,"endColumn":21,"fix":"38","suppressions":"39"},"@typescript-eslint/consistent-type-definitions","Use a `type` instead of an `interface`.","Identifier","typeOverInterface",{"range":"40","text":"41"},["42"],[234,321],"type ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> = ",{"kind":"43","justification":"44"},"directive",""]
1
+ [{"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.not-found.exception.ts":"1","/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.provider.ts":"2","/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.test-suite.ts":"3","/Volumes/Work/ts/hg/framework/packages/async-context/src/index.ts":"4","/Volumes/Work/ts/hg/framework/packages/validation/src/extensions.ts":"5","/Volumes/Work/ts/hg/framework/packages/validation/src/index.ts":"6","/Volumes/Work/ts/hg/framework/packages/validation/src/dto.ts":"7"},{"size":186,"mtime":1698022585968,"results":"8","hashOfConfig":"9"},{"size":2161,"mtime":1698022585968,"results":"10","hashOfConfig":"9"},{"size":3714,"mtime":1698022585968,"results":"11","hashOfConfig":"9"},{"size":95,"mtime":1698022585968,"results":"12","hashOfConfig":"9"},{"size":1335,"mtime":1713905441410,"results":"13","hashOfConfig":"14"},{"size":88,"mtime":1713662918071,"results":"15","hashOfConfig":"14"},{"size":595,"mtime":1713903104633,"results":"16","hashOfConfig":"14"},{"filePath":"17","messages":"18","suppressedMessages":"19","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1o9szx6",{"filePath":"20","messages":"21","suppressedMessages":"22","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"23","messages":"24","suppressedMessages":"25","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","suppressedMessages":"28","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"29","messages":"30","suppressedMessages":"31","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"xqlb75",{"filePath":"32","messages":"33","suppressedMessages":"34","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","suppressedMessages":"37","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.not-found.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.provider.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.test-suite.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/validation/src/extensions.ts",[],["38"],"/Volumes/Work/ts/hg/framework/packages/validation/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/validation/src/dto.ts",[],[],{"ruleId":"39","severity":2,"message":"40","line":17,"column":12,"nodeType":"41","messageId":"42","endLine":17,"endColumn":21,"fix":"43","suppressions":"44"},"@typescript-eslint/consistent-type-definitions","Use a `type` instead of an `interface`.","Identifier","typeOverInterface",{"range":"45","text":"46"},["47"],[283,370],"type ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> = ",{"kind":"48","justification":"49"},"directive",""]
package/dist/dto.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { ZodSchema, ZodTypeDef } from 'zod';
2
+ export type ZodDto<TOutput = any> = {
3
+ new (): TOutput;
4
+ isZodDto: true;
5
+ schema: ZodSchema<TOutput, ZodTypeDef, unknown>;
6
+ create(input: unknown): TOutput;
7
+ };
8
+ export declare function createZodDto<TOutput = any>(schema: ZodSchema<TOutput, ZodTypeDef, unknown>): ZodDto<TOutput>;
9
+ //# sourceMappingURL=dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,UAAU,EACV,MAAM,KAAK,CAAC;AAEb,MAAM,MAAM,MAAM,CAAC,OAAO,GAAG,GAAG,IAAI;IACnC,QAAQ,OAAO,CAAC;IAChB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAChC,CAAA;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAG,GAAG,EACzC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,GAC7C,MAAM,CAAC,OAAO,CAAC,CAWjB"}
package/dist/dto.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createZodDto = void 0;
4
+ function createZodDto(schema) {
5
+ class AugmentedZodDto {
6
+ static isZodDto = true;
7
+ static schema = schema;
8
+ static create(input) {
9
+ return this.schema.parse(input);
10
+ }
11
+ }
12
+ return AugmentedZodDto;
13
+ }
14
+ exports.createZodDto = createZodDto;
15
+ //# sourceMappingURL=dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto.js","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":";;;AAYA,SAAgB,YAAY,CAC3B,MAA+C;IAE/C,MAAM,eAAe;QACb,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAEvB,MAAM,CAAC,MAAM,CAAC,KAAc;YAClC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAoB,CAAC;QACpD,CAAC;;IAGF,OAAO,eAA6C,CAAC;AACtD,CAAC;AAbD,oCAaC"}
@@ -1,8 +1,10 @@
1
1
  import { ZodEffects, ZodTypeDef, infer as ZodInfer, input as ZodInput, ZodPipeline, ZodBoolean } from 'zod';
2
+ import { ZodDto } from './dto';
2
3
  declare module 'zod' {
3
4
  interface ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
4
5
  enforceEnv<T extends ZodSchema<Output, Def, Input>>(this: T, name: string): ZodEffects<T, ZodInfer<T> | string>;
5
6
  transformBooleanString<T extends ZodSchema<Output, Def, Input>>(this: T): ZodPipeline<ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean>;
7
+ toClass<T extends ZodSchema<Output, Def, Input>>(this: T): ZodDto<ZodInfer<T>>;
6
8
  }
7
9
  }
8
10
  //# sourceMappingURL=extensions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAY,EACX,UAAU,EAEV,UAAU,EACV,KAAK,IAAI,QAAQ,EACjB,KAAK,IAAI,QAAQ,EACjB,WAAW,EACX,UAAU,EACV,MAAM,KAAK,CAAC;AAEb,OAAO,QAAQ,KAAK,CAAC;IAEpB,UAAU,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,UAAU,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM;QACpF,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAChH,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAC7D,IAAI,EAAE,CAAC,GACL,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;KAChE;CACD"}
1
+ {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAY,EACX,UAAU,EAEV,UAAU,EACV,KAAK,IAAI,QAAQ,EACjB,KAAK,IAAI,QAAQ,EACjB,WAAW,EACX,UAAU,EACV,MAAM,KAAK,CAAC;AACb,OAAO,EAEN,MAAM,EACN,MAAM,OAAO,CAAC;AAEf,OAAO,QAAQ,KAAK,CAAC;IAEpB,UAAU,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,UAAU,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM;QACpF,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAChH,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAC7D,IAAI,EAAE,CAAC,GACL,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAChE,OAAO,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;KAC/E;CACD"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const zod_1 = tslib_1.__importDefault(require("zod"));
5
+ const dto_1 = require("./dto");
5
6
  zod_1.default.Schema.prototype.enforceEnv = function (name) {
6
7
  return this.transform(value => process.env[name] ?? value);
7
8
  };
@@ -10,4 +11,7 @@ zod_1.default.Schema.prototype.transformBooleanString = function () {
10
11
  .transform(value => (typeof value === 'boolean' ? value : value === 'true'))
11
12
  .pipe(zod_1.default.boolean());
12
13
  };
14
+ zod_1.default.Schema.prototype.toClass = function () {
15
+ return (0, dto_1.createZodDto)(this);
16
+ };
13
17
  //# sourceMappingURL=extensions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":";;;AAAA,sDAQa;AAYb,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAEjC,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAG7C,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;SAC3E,IAAI,CAAC,aAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC"}
1
+ {"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":";;;AAAA,sDAQa;AACb,+BAGe;AAaf,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAEjC,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAG7C,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;SAC3E,IAAI,CAAC,aAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,GAAG;IAG9B,OAAO,IAAA,kBAAY,EAAc,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ZodSchema, ZodTypeDef } from 'zod';
2
+ export type ZodDto<TOutput = any> = {
3
+ new (): TOutput;
4
+ isZodDto: true;
5
+ schema: ZodSchema<TOutput, ZodTypeDef, unknown>;
6
+ create(input: unknown): TOutput;
7
+ };
8
+ export declare function createZodDto<TOutput = any>(schema: ZodSchema<TOutput, ZodTypeDef, unknown>): ZodDto<TOutput>;
9
+ //# sourceMappingURL=dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,UAAU,EACV,MAAM,KAAK,CAAC;AAEb,MAAM,MAAM,MAAM,CAAC,OAAO,GAAG,GAAG,IAAI;IACnC,QAAQ,OAAO,CAAC;IAChB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAChC,CAAA;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAG,GAAG,EACzC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,GAC7C,MAAM,CAAC,OAAO,CAAC,CAWjB"}
@@ -0,0 +1,11 @@
1
+ export function createZodDto(schema) {
2
+ class AugmentedZodDto {
3
+ static isZodDto = true;
4
+ static schema = schema;
5
+ static create(input) {
6
+ return this.schema.parse(input);
7
+ }
8
+ }
9
+ return AugmentedZodDto;
10
+ }
11
+ //# sourceMappingURL=dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto.js","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,YAAY,CAC3B,MAA+C;IAE/C,MAAM,eAAe;QACb,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAEvB,MAAM,CAAC,MAAM,CAAC,KAAc;YAClC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAoB,CAAC;QACpD,CAAC;;IAGF,OAAO,eAA6C,CAAC;AACtD,CAAC"}
@@ -1,8 +1,10 @@
1
1
  import { ZodEffects, ZodTypeDef, infer as ZodInfer, input as ZodInput, ZodPipeline, ZodBoolean } from 'zod';
2
+ import { ZodDto } from './dto';
2
3
  declare module 'zod' {
3
4
  interface ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
4
5
  enforceEnv<T extends ZodSchema<Output, Def, Input>>(this: T, name: string): ZodEffects<T, ZodInfer<T> | string>;
5
6
  transformBooleanString<T extends ZodSchema<Output, Def, Input>>(this: T): ZodPipeline<ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean>;
7
+ toClass<T extends ZodSchema<Output, Def, Input>>(this: T): ZodDto<ZodInfer<T>>;
6
8
  }
7
9
  }
8
10
  //# sourceMappingURL=extensions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAY,EACX,UAAU,EAEV,UAAU,EACV,KAAK,IAAI,QAAQ,EACjB,KAAK,IAAI,QAAQ,EACjB,WAAW,EACX,UAAU,EACV,MAAM,KAAK,CAAC;AAEb,OAAO,QAAQ,KAAK,CAAC;IAEpB,UAAU,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,UAAU,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM;QACpF,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAChH,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAC7D,IAAI,EAAE,CAAC,GACL,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;KAChE;CACD"}
1
+ {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAY,EACX,UAAU,EAEV,UAAU,EACV,KAAK,IAAI,QAAQ,EACjB,KAAK,IAAI,QAAQ,EACjB,WAAW,EACX,UAAU,EACV,MAAM,KAAK,CAAC;AACb,OAAO,EAEN,MAAM,EACN,MAAM,OAAO,CAAC;AAEf,OAAO,QAAQ,KAAK,CAAC;IAEpB,UAAU,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,UAAU,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM;QACpF,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAChH,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAC7D,IAAI,EAAE,CAAC,GACL,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAChE,OAAO,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;KAC/E;CACD"}
@@ -1,4 +1,5 @@
1
1
  import zod from 'zod';
2
+ import { createZodDto, } from './dto';
2
3
  zod.Schema.prototype.enforceEnv = function (name) {
3
4
  return this.transform(value => process.env[name] ?? value);
4
5
  };
@@ -7,4 +8,7 @@ zod.Schema.prototype.transformBooleanString = function () {
7
8
  .transform(value => (typeof value === 'boolean' ? value : value === 'true'))
8
9
  .pipe(zod.boolean());
9
10
  };
11
+ zod.Schema.prototype.toClass = function () {
12
+ return createZodDto(this);
13
+ };
10
14
  //# sourceMappingURL=extensions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,GAQN,MAAM,KAAK,CAAC;AAYb,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAEjC,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAG7C,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;SAC3E,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC"}
1
+ {"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,GAQN,MAAM,KAAK,CAAC;AACb,OAAO,EACN,YAAY,GAEZ,MAAM,OAAO,CAAC;AAaf,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAEjC,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAG7C,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;SAC3E,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,GAAG;IAG9B,OAAO,YAAY,CAAc,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hg-ts/validation",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist-esm/index.js",
6
6
  "repository": "git@gitlab.com:hyper-graph/framework.git",
@@ -12,10 +12,10 @@
12
12
  "lint:fix": "hg lint:fix"
13
13
  },
14
14
  "devDependencies": {
15
- "@hg-ts-config/eslint-config": "0.1.15",
16
- "@hg-ts-config/typescript": "0.1.15",
17
- "@hg-ts/cli": "0.1.15",
18
- "@hg-ts/types": "0.1.15",
15
+ "@hg-ts-config/eslint-config": "0.1.17",
16
+ "@hg-ts-config/typescript": "0.1.17",
17
+ "@hg-ts/cli": "0.1.17",
18
+ "@hg-ts/types": "0.1.17",
19
19
  "@types/node": "20.8.7",
20
20
  "@typescript-eslint/eslint-plugin": "6.8.0",
21
21
  "@typescript-eslint/parser": "6.8.0",
package/src/dto.ts ADDED
@@ -0,0 +1,26 @@
1
+ import {
2
+ ZodSchema,
3
+ ZodTypeDef,
4
+ } from 'zod';
5
+
6
+ export type ZodDto<TOutput = any> = {
7
+ new (): TOutput;
8
+ isZodDto: true;
9
+ schema: ZodSchema<TOutput, ZodTypeDef, unknown>;
10
+ create(input: unknown): TOutput;
11
+ }
12
+
13
+ export function createZodDto<TOutput = any>(
14
+ schema: ZodSchema<TOutput, ZodTypeDef, unknown>,
15
+ ): ZodDto<TOutput> {
16
+ class AugmentedZodDto {
17
+ public static isZodDto = true;
18
+ public static schema = schema;
19
+
20
+ public static create(input: unknown): AugmentedZodDto {
21
+ return this.schema.parse(input) as AugmentedZodDto;
22
+ }
23
+ }
24
+
25
+ return AugmentedZodDto as unknown as ZodDto<TOutput>;
26
+ }
package/src/extensions.ts CHANGED
@@ -7,6 +7,10 @@ import zod, {
7
7
  ZodPipeline,
8
8
  ZodBoolean,
9
9
  } from 'zod';
10
+ import {
11
+ createZodDto,
12
+ ZodDto,
13
+ } from './dto';
10
14
 
11
15
  declare module 'zod' {
12
16
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
@@ -15,6 +19,7 @@ declare module 'zod' {
15
19
  transformBooleanString<T extends ZodSchema<Output, Def, Input>>(
16
20
  this: T,
17
21
  ): ZodPipeline<ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean>;
22
+ toClass<T extends ZodSchema<Output, Def, Input>>(this: T): ZodDto<ZodInfer<T>>;
18
23
  }
19
24
  }
20
25
 
@@ -32,3 +37,9 @@ zod.Schema.prototype.transformBooleanString = function<T extends ZodSchema>(
32
37
  .transform(value => (typeof value === 'boolean' ? value : value === 'true'))
33
38
  .pipe(zod.boolean());
34
39
  };
40
+
41
+ zod.Schema.prototype.toClass = function<T extends ZodSchema>(
42
+ this: T,
43
+ ): ZodDto<ZodInfer<T>> {
44
+ return createZodDto<ZodInfer<T>>(this);
45
+ };