Socket
Socket
Sign inDemoInstall

zod

Package Overview
Dependencies
Maintainers
1
Versions
361
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod - npm Package Compare versions

Comparing version 1.11.0-alpha.1 to 1.11.0-alpha.2

lib/src/types/transformer.d.ts

2

lib/src/codegen.js

@@ -133,3 +133,3 @@ "use strict";

return _this.setType(id, _this.generate(lazyType).id);
case z.ZodTypes.codec:
case z.ZodTypes.transformer:
var codecOutput = def.output;

@@ -136,0 +136,0 @@ return _this.setType(id, _this.generate(codecOutput).id);

@@ -22,3 +22,3 @@ import { ZodString, ZodStringDef } from './types/string';

import { ZodPromise, ZodPromiseDef } from './types/promise';
import { ZodCodec, ZodCodecDef } from './types/codec';
import { ZodTransformer, ZodTransformerDef } from './types/transformer';
import { TypeOf, ZodType, ZodTypeAny, ZodTypeDef, ZodTypes } from './types/base';

@@ -30,3 +30,3 @@ import { ZodError, ZodErrorCode } from './ZodError';

export { ZodTypeDef, ZodTypes };
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodVoidDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef | ZodCodecDef;
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodVoidDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef | ZodTransformerDef;
declare const stringType: () => ZodString;

@@ -55,3 +55,3 @@ declare const numberType: () => ZodNumber;

declare const promiseType: <T extends ZodType<any, any>>(schema: T) => ZodPromise<T>;
declare const codecType: <I extends ZodType<any, any>, O extends ZodType<any, any>>(input: I, output: O, transformer: (arg: I["_type"]) => O["_type"]) => ZodCodec<I, O>;
declare const transformerType: <I extends ZodType<any, any>, O extends ZodType<any, any>>(input: I, output: O, transformer: (arg: I["_type"]) => O["_type"]) => ZodTransformer<I, O>;
declare const ostring: () => ZodUnion<[ZodString, ZodUndefined]>;

@@ -65,3 +65,3 @@ declare const onumber: () => ZodUnion<[ZodNumber, ZodUndefined]>;

} & Pick<import("./ZodError").CustomError, "message" | "params">, "message" | "path" | "params"> | undefined) => ZodType<InstanceType<T>, ZodTypeDef>;
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, voidType as void, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, codecType as codec, instanceOfType as instanceof, ostring, onumber, oboolean, codegen, };
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, voidType as void, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, transformerType as transformer, instanceOfType as instanceof, ostring, onumber, oboolean, codegen, };
export declare const late: {

@@ -72,3 +72,3 @@ object: <T extends import("./types/base").ZodRawShape>(shape: () => T) => ZodObject<T, {

};
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodCodec, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodTransformer, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
export { TypeOf, TypeOf as infer };

@@ -46,4 +46,4 @@ "use strict";

exports.ZodPromise = promise_1.ZodPromise;
var codec_1 = require("./types/codec");
exports.ZodCodec = codec_1.ZodCodec;
var transformer_1 = require("./types/transformer");
exports.ZodTransformer = transformer_1.ZodTransformer;
var base_1 = require("./types/base");

@@ -103,4 +103,4 @@ exports.ZodType = base_1.ZodType;

exports.promise = promiseType;
var codecType = codec_1.ZodCodec.create;
exports.codec = codecType;
var transformerType = transformer_1.ZodTransformer.create;
exports.transformer = transformerType;
var ostring = function () { return stringType().optional(); };

@@ -107,0 +107,0 @@ exports.ostring = ostring;

@@ -443,6 +443,9 @@ "use strict";

}); });
case z.ZodTypes.codec:
def.input.parse(obj);
returnValue = def.transformer(obj);
def.output.parse(returnValue);
case z.ZodTypes.transformer:
// console.log(`input: "${obj}"`);
var inputParseResult = def.input.parse(obj);
// console.log(`inputParseResult: "${inputParseResult}"`);
var transformedResult = def.transformer(inputParseResult);
// console.log(`transformedResult: "${transformedResult}"`);
returnValue = def.output.parse(transformedResult);
break;

@@ -455,3 +458,3 @@ default:

var check = customChecks_1[_b];
if (!check.check(obj)) {
if (!check.check(returnValue)) {
var checkMethod = check.check, noMethodCheck = __rest(check, ["check"]);

@@ -458,0 +461,0 @@ error.addError(makeError(noMethodCheck));

@@ -11,10 +11,16 @@ "use strict";

var z = __importStar(require("."));
var trimAndMultiply = z.ZodCodec.fromSchema(z.string())
.transform(z.number(), function (x) { return parseFloat(x); })
.transform(z.number(), function (num) { return num * 5; })
var trimAndMultiply = z
.transformer(z.string(), z.string(), function (x) {
return x.trim();
})
.transform(z.number(), function (x) {
return parseFloat(x);
})
.transform(z.number(), function (num) {
return num * 5;
})
.refine(function (x) {
console.log("x: " + x);
return x > 30;
return x > 20;
}, 'Number is too small');
console.log(trimAndMultiply.parse('5'));
console.log(trimAndMultiply.parse(' 5 '));
//# sourceMappingURL=playground.js.map
import { ParseParams, MakeErrorData } from '../parser';
import { util } from '../helpers/util';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined, ZodCodec } from '..';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined } from '..';
import { CustomError } from '../ZodError';

@@ -27,3 +27,3 @@ export declare enum ZodTypes {

void = "void",
codec = "codec"
transformer = "transformer"
}

@@ -67,5 +67,4 @@ export declare type ZodTypeAny = ZodType<any, any>;

array: () => ZodArray<this>;
accepts: <U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(x: U, transformer: Tx) => ZodCodec<U, this>;
or: <U extends ZodType<any>>(arg: U) => ZodUnion<[this, U]>;
}
export {};

@@ -39,3 +39,3 @@ "use strict";

ZodTypes["void"] = "void";
ZodTypes["codec"] = "codec";
ZodTypes["transformer"] = "transformer";
})(ZodTypes = exports.ZodTypes || (exports.ZodTypes = {}));

@@ -77,5 +77,8 @@ var ZodType = /** @class */ (function () {

// ) => any = (input, transformer) => 'adsf';
this.accepts = function (input, transformer) {
return __1.ZodCodec.create(input, _this, transformer);
};
// accepts: <U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(
// x: U,
// transformer: Tx,
// ) => ZodCodec<U, this> = (input, transformer) => {
// return ZodCodec.create(input, this, transformer);
// };
// codec = (): ZodCodec<this, this> => {

@@ -82,0 +85,0 @@ // return ZodCodec.create(this, this, x => x);

{
"name": "zod",
"version": "1.11.0-alpha.1",
"version": "1.11.0-alpha.2",
"description": "TypeScript-first schema declaration and validation library with static type inference",

@@ -58,2 +58,2 @@ "main": "./lib/src/index.js",

}
}
}

@@ -1353,3 +1353,3 @@ <p align="center">

- Supports codecs with seria\lization & deserialization transforms
- Supports codecs with serialization & deserialization transforms
- Supports branded types

@@ -1356,0 +1356,0 @@ - Supports advanced functional programming, higher-kinded types, `fp-ts` compatibility

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