mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
remove ajv because the package bundles its own types (#13028)
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
/// <reference types="ajv" />
|
||||
|
||||
import * as Ajv from 'ajv';
|
||||
var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
|
||||
var validate = ajv.compile({});
|
||||
var valid = validate({});
|
||||
if (!valid) console.log(validate.errors);
|
||||
|
||||
var valid = ajv.validate({}, {});
|
||||
if (!valid) console.log(ajv.errors);
|
||||
|
||||
ajv.addSchema({}, 'mySchema');
|
||||
var valid = ajv.validate('mySchema', {});
|
||||
if (!valid) console.log(ajv.errorsText());
|
||||
|
||||
ajv.addKeyword('range', {
|
||||
type: 'number', compile: function (sch, parentSchema) {
|
||||
var min: any = sch[0];
|
||||
var max: any = sch[1];
|
||||
|
||||
return parentSchema.exclusiveRange === true
|
||||
? function (data) { return data > min && data < max; }
|
||||
: function (data) { return data >= min && data <= max; }
|
||||
}
|
||||
});
|
||||
|
||||
var schema = { "range": [2, 4], "exclusiveRange": true };
|
||||
var validate = ajv.compile(schema);
|
||||
console.log(validate(2.01)); // true
|
||||
console.log(validate(3.99)); // true
|
||||
console.log(validate(2)); // false
|
||||
console.log(validate(4)); // false
|
||||
|
||||
declare var request: any;
|
||||
function loadSchema(uri: any, callback: any) {
|
||||
request.json(uri, function (err: any, res: any, body: any) {
|
||||
if (err || res.statusCode >= 400)
|
||||
callback(err || new Error('Loading error: ' + res.statusCode));
|
||||
else
|
||||
callback(null, body);
|
||||
});
|
||||
}
|
||||
var ajv = new Ajv({ loadSchema: loadSchema });
|
||||
|
||||
ajv.compileAsync(schema, function (err, validate) {
|
||||
if (err) return;
|
||||
var valid = validate({});
|
||||
});
|
||||
|
||||
declare var knex: any;
|
||||
function checkIdExists(schema: any, data: any) {
|
||||
return knex(schema.table)
|
||||
.select('id')
|
||||
.where('id', data)
|
||||
.then(function (rows: any) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
var validate = ajv.compile(schema);
|
||||
|
||||
(validate({ userId: 1, postId: 19 }) as PromiseLike<boolean>)
|
||||
.then(function (valid) {
|
||||
// "valid" is always true here
|
||||
console.log('Data is valid');
|
||||
}, function (err) {
|
||||
if (!(err instanceof Ajv.ValidationError)) throw err;
|
||||
// data is invalid
|
||||
console.log('Validation errors:', err.errors);
|
||||
});
|
||||
|
||||
var ajv = new Ajv({ /* async: 'es7', */ transpile: 'nodent' });
|
||||
var validate = ajv.compile(schema); // transpiled es7 async function
|
||||
(validate({}) as PromiseLike<any>).then(() => { }, () => { });
|
||||
114
ajv/index.d.ts
vendored
114
ajv/index.d.ts
vendored
@@ -1,114 +0,0 @@
|
||||
// Type definitions for ajv
|
||||
// Project: https://github.com/epoberezkin/ajv
|
||||
// Definitions by: York Yao <https://github.com/plantain-00/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class Ajv {
|
||||
/**
|
||||
* Create Ajv instance.
|
||||
*/
|
||||
constructor(options?: Ajv.AjvOptions);
|
||||
/**
|
||||
* Generate validating function and cache the compiled schema for future use.
|
||||
*/
|
||||
compile(schema: any): Ajv.AjvValidate;
|
||||
/**
|
||||
* Asyncronous version of compile method that loads missing remote schemas using asynchronous function in options.loadSchema.
|
||||
*/
|
||||
compileAsync(schema: any, callback: (error: Error, validate: Ajv.AjvValidate) => void): void;
|
||||
/**
|
||||
* Validate data using passed schema (it will be compiled and cached).
|
||||
*/
|
||||
validate(schema: any, data: any): boolean | PromiseLike<boolean>;
|
||||
errors: Ajv.ValidationError[];
|
||||
/**
|
||||
* Add schema(s) to validator instance.
|
||||
*/
|
||||
addSchema(schema: any, key: string): void;
|
||||
/**
|
||||
* Adds meta schema(s) that can be used to validate other schemas.
|
||||
* That function should be used instead of addSchema because there may be instance options that would compile a meta schema incorrectly (at the moment it is removeAdditional option).
|
||||
*/
|
||||
addMetaSchema(schema: any, key: string): void;
|
||||
/**
|
||||
* Validates schema.
|
||||
* This method should be used to validate schemas rather than validate due to the inconsistency of uri format in JSON-Schema standard.
|
||||
*/
|
||||
validateSchema(schema: any): Boolean;
|
||||
/**
|
||||
* Retrieve compiled schema previously added with addSchema by the key passed to addSchema or by its full reference (id).
|
||||
* Returned validating function has schema property with the reference to the original schema.
|
||||
*/
|
||||
getSchema(key: string): Ajv.AjvValidate;
|
||||
/**
|
||||
* Remove added/cached schema.
|
||||
* Even if schema is referenced by other schemas it can be safely removed as dependent schemas have local references.
|
||||
*/
|
||||
removeSchema(schema: any): void;
|
||||
/**
|
||||
* Add custom format to validate strings. It can also be used to replace pre-defined formats for Ajv instance.
|
||||
*/
|
||||
addFormat(name: string, format: any): void;
|
||||
/**
|
||||
* Add custom validation keyword to Ajv instance.
|
||||
*/
|
||||
addKeyword(keyword: string, definition: Ajv.AjxKeywordDefinition): void;
|
||||
errorsText(): any;
|
||||
static ValidationError: Function;
|
||||
}
|
||||
declare namespace Ajv {
|
||||
type AjvOptions = {
|
||||
v5?: boolean;
|
||||
allErrors?: boolean;
|
||||
verbose?: boolean;
|
||||
jsonPointers?: boolean;
|
||||
uniqueItems?: boolean;
|
||||
unicode?: boolean;
|
||||
format?: string;
|
||||
formats?: any;
|
||||
unknownFormats?: true | string[] | "ignore";
|
||||
schemas?: any;
|
||||
missingRefs?: true | "ignore" | "fail";
|
||||
extendRefs?: true | "ignore" | "fail";
|
||||
loadSchema?(uri: string, callback: (error: Error, body: any) => void): void;
|
||||
removeAdditional?: boolean | "all" | "failing";
|
||||
useDefaults?: boolean | "shared";
|
||||
coerceTypes?: boolean | "array";
|
||||
async?: any;
|
||||
transpile?: string;
|
||||
meta?: boolean;
|
||||
validateSchema?: boolean | "log";
|
||||
addUsedSchema?: boolean;
|
||||
inlineRefs?: boolean | number;
|
||||
passContext?: boolean;
|
||||
loopRequired?: number;
|
||||
ownProperties?: boolean;
|
||||
multipleOfPrecision?: boolean | number;
|
||||
errorDataPath?: string,
|
||||
messages?: boolean;
|
||||
beautify?: boolean;
|
||||
cache?: any;
|
||||
}
|
||||
type AjvValidate = ((data: any) => boolean | PromiseLike<boolean>) & {
|
||||
errors: ValidationError[];
|
||||
}
|
||||
type AjxKeywordDefinition = {
|
||||
async?: boolean;
|
||||
type: string;
|
||||
compile?: (schema: any, parentsSchema: any) => ((data: any) => boolean | PromiseLike<boolean>);
|
||||
validate?: (schema: any, data: any) => boolean;
|
||||
}
|
||||
type ValidationError = {
|
||||
keyword: string;
|
||||
dataPath: string;
|
||||
schemaPath: string;
|
||||
params: any;
|
||||
message: string;
|
||||
schema: any;
|
||||
parentSchema: any;
|
||||
data: any;
|
||||
}
|
||||
}
|
||||
|
||||
export = Ajv;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ajv-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -94,6 +94,12 @@
|
||||
"typingsPackageName": "normalizr",
|
||||
"sourceRepoURL": "https://github.com/paularmstrong/normalizr",
|
||||
"asOfVersion": "2.0.18"
|
||||
},
|
||||
{
|
||||
"libraryName": "ajv",
|
||||
"typingsPackageName": "ajv",
|
||||
"sourceRepoURL": "https://github.com/epoberezkin/ajv",
|
||||
"asOfVersion": "1.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user