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.3 to 0.0.4

15

lib/cjs/index.d.ts
import { ZodObject, ZodRawShape, ZodType, ParseParams, SafeParseReturnType } from "zod";
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
type ZodValue<T extends ZodType> = T extends ZodType<infer Output> ? UnionToIntersection<Output> : never;
export interface ZodClass<T extends ZodRawShape> extends Omit<ZodObject<T>, "parse" | "parseAsync" | "safeParse" | "safeParseAsync" | "extend"> {
extend<U extends ZodRawShape>(augmentation: U): ZodClass<Omit<T, keyof U> & U>;
type Ctor<Shape extends ZodRawShape = ZodRawShape, Self = any> = {
shape: Shape;
schema: ZodObject<Shape>;
new (input: any): Self;
};
export declare function $<Super extends Ctor>(Super: Super): {
extend<Shape extends ZodRawShape>(shape: Shape): ZodClass<Omit<Super["shape"], keyof Shape> & Shape, InstanceType<Super>>;
};
export interface ZodClass<T extends ZodRawShape, Self = {}> extends Omit<ZodObject<T>, "parse" | "parseAsync" | "safeParse" | "safeParseAsync"> {
shape: T;
schema: ZodObject<T>;
parse<T extends InstanceType<this> = InstanceType<this>>(value: unknown): T;

@@ -10,3 +19,3 @@ parseAsync<Output extends InstanceType<this> = InstanceType<this>>(value: unknown): Promise<Output>;

safeParseAsync<Output extends InstanceType<this> = InstanceType<this>>(value: unknown): Promise<SafeParseReturnType<ZodValue<ZodObject<T>>, Output>>;
new (data: ZodValue<ZodObject<T>>): ZodValue<ZodObject<T>>;
new (data: ZodValue<ZodObject<T>>): Self & ZodValue<ZodObject<T>>;
}

@@ -13,0 +22,0 @@ /**

33

lib/cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodClass = void 0;
exports.ZodClass = exports.$ = void 0;
const zod_1 = require("zod");
function $(Super) {
return {
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;
},
};
}
exports.$ = $;
/**

@@ -24,15 +42,2 @@ * Creates a class and a Zod schema in one line.

return _a = class {
static extend(augmentation) {
var _b;
const augmented = this.schema.extend(augmentation);
// @ts-ignore
return _b = class extends this {
constructor(value) {
super(value);
Object.assign(this, augmented.parse(value));
}
},
_b.schema = augmented,
_b;
}
static parse(value, params) {

@@ -39,0 +44,0 @@ return new this(this.schema.parse(value, params));

import { ZodObject, ZodRawShape, ZodType, ParseParams, SafeParseReturnType } from "zod";
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
type ZodValue<T extends ZodType> = T extends ZodType<infer Output> ? UnionToIntersection<Output> : never;
export interface ZodClass<T extends ZodRawShape> extends Omit<ZodObject<T>, "parse" | "parseAsync" | "safeParse" | "safeParseAsync" | "extend"> {
extend<U extends ZodRawShape>(augmentation: U): ZodClass<Omit<T, keyof U> & U>;
type Ctor<Shape extends ZodRawShape = ZodRawShape, Self = any> = {
shape: Shape;
schema: ZodObject<Shape>;
new (input: any): Self;
};
export declare function $<Super extends Ctor>(Super: Super): {
extend<Shape extends ZodRawShape>(shape: Shape): ZodClass<Omit<Super["shape"], keyof Shape> & Shape, InstanceType<Super>>;
};
export interface ZodClass<T extends ZodRawShape, Self = {}> extends Omit<ZodObject<T>, "parse" | "parseAsync" | "safeParse" | "safeParseAsync"> {
shape: T;
schema: ZodObject<T>;
parse<T extends InstanceType<this> = InstanceType<this>>(value: unknown): T;

@@ -10,3 +19,3 @@ parseAsync<Output extends InstanceType<this> = InstanceType<this>>(value: unknown): Promise<Output>;

safeParseAsync<Output extends InstanceType<this> = InstanceType<this>>(value: unknown): Promise<SafeParseReturnType<ZodValue<ZodObject<T>>, Output>>;
new (data: ZodValue<ZodObject<T>>): ZodValue<ZodObject<T>>;
new (data: ZodValue<ZodObject<T>>): Self & ZodValue<ZodObject<T>>;
}

@@ -13,0 +22,0 @@ /**

import { object, } from "zod";
export function $(Super) {
return {
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;
},
};
}
/**

@@ -21,15 +38,2 @@ * Creates a class and a Zod schema in one line.

return _a = class {
static extend(augmentation) {
var _b;
const augmented = this.schema.extend(augmentation);
// @ts-ignore
return _b = class extends this {
constructor(value) {
super(value);
Object.assign(this, augmented.parse(value));
}
},
_b.schema = augmented,
_b;
}
static parse(value, params) {

@@ -36,0 +40,0 @@ return new this(this.schema.parse(value, params));

{
"name": "zod-class",
"description": "Create classes from Zod Object schemas all in one line",
"version": "0.0.3",
"version": "0.0.4",
"exports": {

@@ -29,3 +29,3 @@ ".": {

"jest": "^29.7.0",
"prettier": "^3.0.3",
"prettier": "^2",
"ts-jest": "^29.1.1",

@@ -32,0 +32,0 @@ "ts-node": "^10.9.1",

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