@cmtlyt/json-schema
Version:
json schema 处理相关方法
60 lines (54 loc) • 2.07 kB
TypeScript
import { TObject as TObject$1 } from '@cmtlyt/base';
declare function encodeDataSchema(data: any): string;
declare function decodeDataSchema(dataSchema: string): any;
declare const baseTypeDefaultValue: {
string: () => string;
number: () => number;
boolean: () => boolean;
array: () => never[];
object: () => {};
map: () => Map<any, any>;
set: () => Set<unknown>;
function: () => () => void;
asyncfunction: () => () => Promise<void>;
date: () => Date;
regexp: () => RegExp;
bigint: () => bigint;
symbol: () => symbol;
weakmap: () => WeakMap<WeakKey, any>;
weakset: () => WeakSet<WeakKey>;
promise: () => Promise<void>;
error: () => Error;
int8array: () => Int8Array<ArrayBuffer>;
uint8array: () => Uint8Array<ArrayBuffer>;
uint8clampedarray: () => Uint8ClampedArray<ArrayBuffer>;
int16array: () => Int16Array<ArrayBuffer>;
uint16array: () => Uint16Array<ArrayBuffer>;
int32array: () => Int32Array<ArrayBuffer>;
uint32array: () => Uint32Array<ArrayBuffer>;
float32array: () => Float32Array<ArrayBuffer>;
float64array: () => Float64Array<ArrayBuffer>;
file: () => File;
blob: () => Blob;
};
interface Schema {
type: string;
description: string;
properties?: Record<string, Schema>;
required?: string[];
items?: Schema;
minItems?: number;
maxItems?: number;
uniqueItems?: boolean;
}
type TObject<T> = Record<string | number | symbol, T>;
declare function jsonSchemaGenerator(data: TObject<any>): string;
type MockHandlerMap = typeof baseTypeDefaultValue;
declare function mockFromSchema(schema: string, handlerMap?: Partial<MockHandlerMap>): any;
interface ErrorItem {
path: string;
message: string;
}
declare function verifyBySchema(schema: string, data: any): [boolean, ErrorItem[]];
declare function typeObjectToSchema(obj: TObject$1<any>): string;
export { type ErrorItem, type Schema, type TObject, decodeDataSchema, encodeDataSchema, jsonSchemaGenerator, mockFromSchema, typeObjectToSchema, verifyBySchema };