@zodec/core 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zodec/core
2
2
 
3
- zod+decorator
3
+ zod + decorator
4
4
 
5
5
  zodec = zod[functional-schema] ++ class-validator[clean-declarative-style]
6
6
 
@@ -1,2 +1,5 @@
1
- export const ZODEC__SCHEMA = "zodec:schema";
2
- export const ZODEC__TYPE = "zodec:type";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZODEC__TYPE = exports.ZODEC__SCHEMA = void 0;
4
+ exports.ZODEC__SCHEMA = "zodec:schema";
5
+ exports.ZODEC__TYPE = "zodec:type";
@@ -1,5 +1,9 @@
1
- import { ZODEC__SCHEMA } from "../constants.zodec.js";
2
- import * as z from "zod";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zatt = zatt;
4
+ const tslib_1 = require("tslib");
5
+ const constants_zodec_js_1 = require("../constants.zodec.js");
6
+ const z = tslib_1.__importStar(require("zod"));
3
7
  /**
4
8
  * zatt: zod attribute
5
9
  * decorate a property with a zod schema
@@ -8,11 +12,11 @@ import * as z from "zod";
8
12
  * @param attributeSchema
9
13
  * @returns
10
14
  */
11
- export function zatt(attributeSchema) {
15
+ function zatt(attributeSchema) {
12
16
  return (target, propertyKey) => {
13
17
  try {
14
18
  // check if the target has existing ZODEC__SCHEMA
15
- let targetSchema = Reflect.getMetadata(ZODEC__SCHEMA, target.constructor);
19
+ let targetSchema = Reflect.getMetadata(constants_zodec_js_1.ZODEC__SCHEMA, target.constructor);
16
20
  if (!targetSchema) {
17
21
  // create a new ZodObject schema if none exists
18
22
  targetSchema = z.object({});
@@ -23,7 +27,7 @@ export function zatt(attributeSchema) {
23
27
  [propertyKey.toString()]: attributeSchema,
24
28
  });
25
29
  }
26
- Reflect.defineMetadata(ZODEC__SCHEMA, targetSchema, target.constructor);
30
+ Reflect.defineMetadata(constants_zodec_js_1.ZODEC__SCHEMA, targetSchema, target.constructor);
27
31
  }
28
32
  catch (ex) {
29
33
  console.error("zatt/decorator/ex", ex);
@@ -1,14 +1,17 @@
1
- import 'reflect-metadata';
2
- import { ZODEC__SCHEMA } from '../constants.zodec.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zclass = zclass;
4
+ require("reflect-metadata");
5
+ const constants_zodec_js_1 = require("../constants.zodec.js");
3
6
  /**
4
7
  * decorate a class by providing defined zod schema object
5
8
  * @param schema
6
9
  * @returns
7
10
  */
8
- export function zclass(schema) {
11
+ function zclass(schema) {
9
12
  return (target) => {
10
13
  // schema
11
- Reflect.defineMetadata(ZODEC__SCHEMA, schema, target);
14
+ Reflect.defineMetadata(constants_zodec_js_1.ZODEC__SCHEMA, schema, target);
12
15
  // inferred type > is not a runtime entity
13
16
  // type inferred = z.infer<typeof schema>;
14
17
  // Reflect.defineMetadata(ZODIFY__TYPE, inferred, target)
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
- export * from './zodec.js';
2
- export * from './decorators/zatt.decorator.js';
3
- export * from './decorators/zclass.decorator.js';
4
- export * from './constants.zodec.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./zodec.js"), exports);
5
+ tslib_1.__exportStar(require("./decorators/zatt.decorator.js"), exports);
6
+ tslib_1.__exportStar(require("./decorators/zclass.decorator.js"), exports);
7
+ tslib_1.__exportStar(require("./constants.zodec.js"), exports);
package/dist/zodec.d.ts CHANGED
@@ -11,6 +11,12 @@ export declare class Zodec {
11
11
  * @returns The Zod schema if found, otherwise undefined.
12
12
  */
13
13
  static of(target: any): ZodType<any> | undefined;
14
+ /**
15
+ * checks if a target class has schema defined or not
16
+ * @param target
17
+ * @returns
18
+ */
19
+ static hasSchema(target: any): boolean;
14
20
  static validate(input: any, target?: any): z.ZodSafeParseResult<any>;
15
21
  }
16
22
  //# sourceMappingURL=zodec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"zodec.d.ts","sourceRoot":"","sources":["../src/zodec.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAKjC;;GAEG;AACH,qBAAa,KAAK;IACd;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS;IAIhD,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,GAAE,GAAU,GAAG,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC;CA4B7E"}
1
+ {"version":3,"file":"zodec.d.ts","sourceRoot":"","sources":["../src/zodec.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAKjC;;GAEG;AACH,qBAAa,KAAK;IACd;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS;IAIhD;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO;IAItC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,GAAE,GAAU,GAAG,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC;CA4B7E"}
package/dist/zodec.js CHANGED
@@ -1,10 +1,13 @@
1
- import "reflect-metadata";
2
- import { z } from "zod";
3
- import { ZODEC__SCHEMA } from "./constants.zodec.js";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Zodec = void 0;
4
+ require("reflect-metadata");
5
+ const zod_1 = require("zod");
6
+ const constants_zodec_js_1 = require("./constants.zodec.js");
4
7
  /**
5
8
  * Utility class for schemas and classes.
6
9
  */
7
- export class Zodec {
10
+ class Zodec {
8
11
  /**
9
12
  * Retrieves the Zod schema associated with a class.
10
13
  *
@@ -12,7 +15,15 @@ export class Zodec {
12
15
  * @returns The Zod schema if found, otherwise undefined.
13
16
  */
14
17
  static of(target) {
15
- return Reflect.getMetadata(ZODEC__SCHEMA, target);
18
+ return Reflect.getMetadata(constants_zodec_js_1.ZODEC__SCHEMA, target);
19
+ }
20
+ /**
21
+ * checks if a target class has schema defined or not
22
+ * @param target
23
+ * @returns
24
+ */
25
+ static hasSchema(target) {
26
+ return Reflect.hasMetadata(constants_zodec_js_1.ZODEC__SCHEMA, target);
16
27
  }
17
28
  static validate(input, target = null) {
18
29
  if (!target) {
@@ -28,7 +39,7 @@ export class Zodec {
28
39
  if (schema) {
29
40
  let validtn = schema.safeParse(input);
30
41
  if (!validtn.success) {
31
- validtn.data = z.treeifyError(validtn.error);
42
+ validtn.data = zod_1.z.treeifyError(validtn.error);
32
43
  }
33
44
  return validtn;
34
45
  }
@@ -39,3 +50,4 @@ export class Zodec {
39
50
  }
40
51
  }
41
52
  }
53
+ exports.Zodec = Zodec;
package/package.json CHANGED
@@ -1,67 +1,67 @@
1
- {
2
- "name": "@zodec/core",
3
- "version": "0.0.6",
4
- "description": "Generate Zod schemas using TypeScript decorators. Define validation inline with class definitions - combining Zod's power with decorator syntax.",
5
- "author": "Vizhy",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/vizhy/js",
10
- "directory": "packages/zodec/core"
11
- },
12
- "homepage": "https://github.com/vizhy/js/tree/main/packages/zodec/core#readme",
13
- "bugs": {
14
- "url": "https://github.com/vizhy/js/issues"
15
- },
16
- "type": "module",
17
- "main": "./dist/index.js",
18
- "module": "./dist/index.js",
19
- "types": "./dist/index.d.ts",
20
- "exports": {
21
- "./package.json": "./package.json",
22
- ".": {
23
- "@vizhy/source": "./src/index.ts",
24
- "types": "./dist/index.d.ts",
25
- "import": "./dist/index.js",
26
- "default": "./dist/index.js"
27
- }
28
- },
29
- "files": [
30
- "dist",
31
- "!**/*.tsbuildinfo"
32
- ],
33
- "nx": {
34
- "name": "zodec-core"
35
- },
36
- "dependencies": {
37
- "tslib": "^2.3.0"
38
- },
39
- "publishConfig": {
40
- "access": "public"
41
- },
42
- "keywords": [
43
- "zod",
44
- "decorators",
45
- "schema",
46
- "validation",
47
- "typescript",
48
- "class-validator",
49
- "class-validator-alternative",
50
- "schema-validation",
51
- "runtime-validation",
52
- "type-safe",
53
- "zod-decorators",
54
- "decorator-validation",
55
- "model",
56
- "dto",
57
- "data-validation",
58
- "functional-schema",
59
- "declarative-validation",
60
- "declarative-style",
61
- "metadata",
62
- "reflection",
63
- "reflect-metadata",
64
- "typescript-decorators",
65
- "zodec"
66
- ]
67
- }
1
+ {
2
+ "name": "@zodec/core",
3
+ "version": "0.0.7",
4
+ "description": "Generate Zod schemas using TypeScript decorators. Define validation inline with class definitions - combining Zod's power with decorator syntax.",
5
+ "author": "Vizhy",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/vizhy/js",
10
+ "directory": "packages/zodec/core"
11
+ },
12
+ "homepage": "https://github.com/vizhy/js/tree/main/packages/zodec/core#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/vizhy/js/issues"
15
+ },
16
+ "type": "commonjs",
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "@vizhy/source": "./src/index.ts",
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "!**/*.tsbuildinfo"
32
+ ],
33
+ "nx": {
34
+ "name": "zodec-core"
35
+ },
36
+ "dependencies": {
37
+ "tslib": "^2.3.0"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "keywords": [
43
+ "zod",
44
+ "decorators",
45
+ "schema",
46
+ "validation",
47
+ "typescript",
48
+ "class-validator",
49
+ "class-validator-alternative",
50
+ "schema-validation",
51
+ "runtime-validation",
52
+ "type-safe",
53
+ "zod-decorators",
54
+ "decorator-validation",
55
+ "model",
56
+ "dto",
57
+ "data-validation",
58
+ "functional-schema",
59
+ "declarative-validation",
60
+ "declarative-style",
61
+ "metadata",
62
+ "reflection",
63
+ "reflect-metadata",
64
+ "typescript-decorators",
65
+ "zodec"
66
+ ]
67
+ }