Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zod-class

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-class - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

18

lib/cjs/index.d.ts

@@ -11,3 +11,2 @@ import { ZodObject, ZodRawShape, ZodType, ParseParams, SafeParseReturnType } from "zod";

export declare function isZodClass(a: any): a is Ctor;
export declare function Z<Shape extends ZodRawShape = ZodRawShape>(shape: Shape): ZodClass<Shape>;
export declare function Z<Super extends Ctor>(Super: Super): {

@@ -27,19 +26,2 @@ parse(value: unknown): InstanceType<Super>;

}
/**
* Creates a class and a Zod schema in one line.
*
* ```ts
* class HelloObject extends ZodClass({
* key: z.string()
* }) { }
*
* new HelloObject({
* key: "key"
* })
* ```
* @param shape
* @returns
* @deprecated - use {@link Z}({ shape }) instead
*/
export declare function ZodClass<T extends ZodRawShape>(shape: T): ZodClass<T>;
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;

@@ -46,0 +28,0 @@ type ZodValue<T extends ZodType> = T extends ZodType<infer Output> ? UnionToIntersection<Output> : never;

50

lib/cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodClass = exports.Z = exports.isZodClass = void 0;
exports.Z = exports.isZodClass = void 0;
const zod_1 = require("zod");

@@ -10,25 +10,21 @@ const IS_ZOD_CLASS = Symbol.for("zod-class");

exports.isZodClass = isZodClass;
function Z(shapeOrSuper) {
if (isZodClass(shapeOrSuper)) {
const Super = shapeOrSuper;
return {
parse(value) {
return Super.parse(value);
},
extend(augmentation) {
var _a;
const augmented = Super.schema.extend(augmentation);
// @ts-ignore
return _a = class extends Super {
constructor(value) {
super(value);
Object.assign(this, augmented.parse(value));
}
},
_a.schema = augmented,
_a;
},
};
}
return ZodClass(shapeOrSuper);
function Z(Super) {
return {
parse(value) {
return Super.parse(value);
},
extend(augmentation) {
var _a;
const augmented = Super.schema.extend(augmentation);
// @ts-ignore
return _a = class extends Super {
constructor(value) {
super(value);
Object.assign(this, augmented.parse(value));
}
},
_a.schema = augmented,
_a;
},
};
}

@@ -50,5 +46,4 @@ exports.Z = Z;

* @returns
* @deprecated - use {@link Z}({ shape }) instead
*/
function ZodClass(shape) {
Z["class"] = function (shape) {
var _a, _b;

@@ -81,4 +76,3 @@ const _schema = (0, zod_1.object)(shape);

_b;
}
exports.ZodClass = ZodClass;
};
function coerceSafeParse(clazz, result) {

@@ -85,0 +79,0 @@ if (result.success) {

@@ -11,3 +11,2 @@ import { ZodObject, ZodRawShape, ZodType, ParseParams, SafeParseReturnType } from "zod";

export declare function isZodClass(a: any): a is Ctor;
export declare function Z<Shape extends ZodRawShape = ZodRawShape>(shape: Shape): ZodClass<Shape>;
export declare function Z<Super extends Ctor>(Super: Super): {

@@ -27,19 +26,2 @@ parse(value: unknown): InstanceType<Super>;

}
/**
* Creates a class and a Zod schema in one line.
*
* ```ts
* class HelloObject extends ZodClass({
* key: z.string()
* }) { }
*
* new HelloObject({
* key: "key"
* })
* ```
* @param shape
* @returns
* @deprecated - use {@link Z}({ shape }) instead
*/
export declare function ZodClass<T extends ZodRawShape>(shape: T): ZodClass<T>;
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;

@@ -46,0 +28,0 @@ type ZodValue<T extends ZodType> = T extends ZodType<infer Output> ? UnionToIntersection<Output> : never;

@@ -6,25 +6,21 @@ import { object, } from "zod";

}
export function Z(shapeOrSuper) {
if (isZodClass(shapeOrSuper)) {
const Super = shapeOrSuper;
return {
parse(value) {
return Super.parse(value);
},
extend(augmentation) {
var _a;
const augmented = Super.schema.extend(augmentation);
// @ts-ignore
return _a = class extends Super {
constructor(value) {
super(value);
Object.assign(this, augmented.parse(value));
}
},
_a.schema = augmented,
_a;
},
};
}
return ZodClass(shapeOrSuper);
export function Z(Super) {
return {
parse(value) {
return Super.parse(value);
},
extend(augmentation) {
var _a;
const augmented = Super.schema.extend(augmentation);
// @ts-ignore
return _a = class extends Super {
constructor(value) {
super(value);
Object.assign(this, augmented.parse(value));
}
},
_a.schema = augmented,
_a;
},
};
}

@@ -45,5 +41,4 @@ /**

* @returns
* @deprecated - use {@link Z}({ shape }) instead
*/
export function ZodClass(shape) {
Z["class"] = function (shape) {
var _a, _b;

@@ -76,3 +71,3 @@ const _schema = object(shape);

_b;
}
};
function coerceSafeParse(clazz, result) {

@@ -79,0 +74,0 @@ if (result.success) {

{
"name": "zod-class",
"description": "Create classes from Zod Object schemas all in one line",
"version": "0.0.5",
"version": "0.0.6",
"repository": {

@@ -6,0 +6,0 @@ "url": "https://github.com/sam-goodwin/zod-class"

@@ -13,3 +13,3 @@ # zod-class

The `$` utility function is the swiss army knife in `zod-class` - you use it for everything.
The `Z` utility function is the swiss army knife in `zod-class` - you use it for everything.

@@ -23,3 +23,3 @@ 1. Define a new class

// define a class using a zod schema
export class Hello extends Z({
export class Hello extends Z.class({
name: z.string(),

@@ -78,3 +78,3 @@ }) {

```ts
export class Person extends ZodClass({
export class Person extends Z.class({
firstName: z.string(),

@@ -81,0 +81,0 @@ lastName: z.string(),

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc