Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
@@ -0,1 +1,2 @@ | ||
import type { JsonValue } from '../../types/json-value'; | ||
import type { Schema } from '../../types/schema'; | ||
@@ -6,4 +7,4 @@ import type { SerDes } from '../../types/ser-des'; | ||
export declare type CustomValidation<ValueT> = (value: ValueT) => ValidationResult; | ||
export interface CustomSchemaOptions<ValueT> extends CommonSchemaOptions { | ||
serDes: SerDes<ValueT>; | ||
export interface CustomSchemaOptions<ValueT, SerializedT extends JsonValue> extends CommonSchemaOptions { | ||
serDes: SerDes<ValueT, SerializedT>; | ||
typeName: string; | ||
@@ -14,3 +15,3 @@ /** Performs validation logic. By default, only `isValueType` is checked, using the `serDes` field. */ | ||
/** Used for adding custom schemas for complex types. */ | ||
export interface CustomSchema<ValueT> extends Schema<ValueT>, CustomSchemaOptions<ValueT> { | ||
export interface CustomSchema<ValueT, SerializedT extends JsonValue> extends Schema<ValueT>, CustomSchemaOptions<ValueT, SerializedT> { | ||
schemaType: 'custom'; | ||
@@ -24,3 +25,3 @@ } | ||
*/ | ||
export declare const custom: <ValueT>({ serDes, typeName, customValidation, ...options }: CustomSchemaOptions<ValueT>) => CustomSchema<ValueT>; | ||
export declare const custom: <ValueT, SerializedT extends JsonValue>({ serDes, typeName, customValidation, ...options }: CustomSchemaOptions<ValueT, SerializedT>) => CustomSchema<ValueT, SerializedT>; | ||
//# sourceMappingURL=custom.d.ts.map |
@@ -6,5 +6,5 @@ import type { DeserializationResult } from './deserializer'; | ||
/** A serializer-deserializer */ | ||
export interface SerDes<ValueT> { | ||
export interface SerDes<ValueT, SerializedT extends JsonValue> { | ||
/** Deserialize (and validate) a value */ | ||
deserialize: (value: JsonValue) => DeserializationResult<ValueT>; | ||
deserialize: (value: SerializedT) => DeserializationResult<ValueT>; | ||
/** Checks if the specified value is the expected type, which is checked before serialization is attempted */ | ||
@@ -15,6 +15,6 @@ isValueType: (value: any) => value is ValueT; | ||
/** A schema for the serialized form, which is checked before deserialization is attempted */ | ||
serializedSchema: () => Schema; | ||
serializedSchema: () => Schema<SerializedT>; | ||
} | ||
/** Make a custom serializer-deserializer */ | ||
export declare const makeSerDes: <ValueT>(serDes: SerDes<ValueT>) => SerDes<ValueT>; | ||
export declare const makeSerDes: <ValueT, SerializedT extends JsonValue>(serDes: SerDes<ValueT, SerializedT>) => SerDes<ValueT, SerializedT>; | ||
//# sourceMappingURL=ser-des.d.ts.map |
{ | ||
"name": "yaschema", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Yet another schema", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -191,5 +191,5 @@ # yaschema | ||
// Defining the serializer-deserializer and a couple pre-requisite checking functions | ||
const bigNumberSerDes = makeSerDes<BigNumber>({ | ||
const bigNumberSerDes = makeSerDes({ | ||
// Converts from a JSON-compatible value to a BigNumber object | ||
deserialize: (value) => ({ deserialized: new BigNumber((value as { bignumber: string }).bignumber) }), | ||
deserialize: (value) => ({ deserialized: new BigNumber(value.bignumber) }), | ||
// Checks if the specified value is a BigNumber object. This is called before serialization is attempted to avoid dealing with exceptions | ||
@@ -217,3 +217,3 @@ // and other error logic if this isn't the expected type (which will commonly happen when using oneOf, for example) | ||
// Defining a custom schema | ||
export const bigNumberSchema = schema.custom<BigNumber>({ | ||
export const bigNumberSchema = schema.custom({ | ||
typeName: 'BigNumber', | ||
@@ -220,0 +220,0 @@ serDes: bigNumberSerDes, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284833
3111