Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc.js

This file was deleted.

46 changes: 23 additions & 23 deletions declarations/ValidationError.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export type PostFormatter = import("./validate").PostFormatter;
export type SchemaUtilErrorObject = import("./validate").SchemaUtilErrorObject;
declare class ValidationError extends Error {
/**
* @param {Array<SchemaUtilErrorObject>} errors
* @param {Schema} schema
* @param {ValidationErrorConfiguration} configuration
* @param {Array<SchemaUtilErrorObject>} errors array of error objects
* @param {Schema} schema schema
* @param {ValidationErrorConfiguration} configuration configuration
*/
constructor(
errors: Array<SchemaUtilErrorObject>,
schema: Schema,
configuration?: ValidationErrorConfiguration
configuration?: ValidationErrorConfiguration,
);
/** @type {Array<SchemaUtilErrorObject>} */
errors: Array<SchemaUtilErrorObject>;
Expand All @@ -28,47 +28,47 @@ declare class ValidationError extends Error {
/** @type {PostFormatter | null} */
postFormatter: PostFormatter | null;
/**
* @param {string} path
* @returns {Schema}
* @param {string} path path
* @returns {Schema} schema
*/
getSchemaPart(path: string): Schema;
/**
* @param {Schema} schema
* @param {boolean} logic
* @param {Array<Object>} prevSchemas
* @returns {string}
* @param {Schema} schema schema
* @param {boolean} logic logic
* @param {Array<object>} prevSchemas prev schemas
* @returns {string} formatted schema
*/
formatSchema(
schema: Schema,
logic?: boolean,
prevSchemas?: Array<Object>
prevSchemas?: Array<object>,
): string;
/**
* @param {Schema=} schemaPart
* @param {(boolean | Array<string>)=} additionalPath
* @param {boolean=} needDot
* @param {boolean=} logic
* @returns {string}
* @param {Schema=} schemaPart schema part
* @param {(boolean | Array<string>)=} additionalPath additional path
* @param {boolean=} needDot true when need dot
* @param {boolean=} logic logic
* @returns {string} schema part text
*/
getSchemaPartText(
schemaPart?: Schema | undefined,
additionalPath?: (boolean | Array<string>) | undefined,
needDot?: boolean | undefined,
logic?: boolean | undefined
logic?: boolean | undefined,
): string;
/**
* @param {Schema=} schemaPart
* @returns {string}
* @param {Schema=} schemaPart schema part
* @returns {string} schema part description
*/
getSchemaPartDescription(schemaPart?: Schema | undefined): string;
/**
* @param {SchemaUtilErrorObject} error
* @returns {string}
* @param {SchemaUtilErrorObject} error error object
* @returns {string} formatted error object
*/
formatValidationError(error: SchemaUtilErrorObject): string;
/**
* @param {Array<SchemaUtilErrorObject>} errors
* @returns {string}
* @param {Array<SchemaUtilErrorObject>} errors errors
* @returns {string} formatted errors
*/
formatValidationErrors(errors: Array<SchemaUtilErrorObject>): string;
}
5 changes: 2 additions & 3 deletions declarations/keywords/absolutePath.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export type SchemaValidateFunction = import("ajv").SchemaValidateFunction;
export type AnySchemaObject = import("ajv").AnySchemaObject;
export type SchemaUtilErrorObject = import("../validate").SchemaUtilErrorObject;
/**
*
* @param {Ajv} ajv
* @returns {Ajv}
* @param {Ajv} ajv ajv
* @returns {Ajv} configured ajv
*/
declare function addAbsolutePathKeyword(ajv: Ajv): Ajv;
4 changes: 2 additions & 2 deletions declarations/keywords/limit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type KeywordErrorDefinition = import("ajv").KeywordErrorDefinition;
/** @typedef {import("ajv").Name} Name */
/** @typedef {import("ajv").KeywordErrorDefinition} KeywordErrorDefinition */
/**
* @param {Ajv} ajv
* @returns {Ajv}
* @param {Ajv} ajv ajv
* @returns {Ajv} ajv with limit keyword
*/
declare function addLimitKeyword(ajv: Ajv): Ajv;
5 changes: 2 additions & 3 deletions declarations/keywords/undefinedAsNull.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export type ValidateFunction = import("ajv").ValidateFunction;
/** @typedef {import("ajv").AnySchemaObject} AnySchemaObject */
/** @typedef {import("ajv").ValidateFunction} ValidateFunction */
/**
*
* @param {Ajv} ajv
* @returns {Ajv}
* @param {Ajv} ajv ajv
* @returns {Ajv} configured ajv
*/
declare function addUndefinedAsNullKeyword(ajv: Ajv): Ajv;
34 changes: 17 additions & 17 deletions declarations/util/Range.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ export = Range;
*/
declare class Range {
/**
* @param {"left" | "right"} side
* @param {boolean} exclusive
* @returns {">" | ">=" | "<" | "<="}
* @param {"left" | "right"} side side
* @param {boolean} exclusive exclusive
* @returns {">" | ">=" | "<" | "<="} operator
*/
static getOperator(
side: "left" | "right",
exclusive: boolean
exclusive: boolean,
): ">" | ">=" | "<" | "<=";
/**
* @param {number} value
* @param {number} value value
* @param {boolean} logic is not logic applied
* @param {boolean} exclusive is range exclusive
* @returns {string}
* @returns {string} formatted right
*/
static formatRight(value: number, logic: boolean, exclusive: boolean): string;
/**
* @param {number} value
* @param {number} value value
* @param {boolean} logic is not logic applied
* @param {boolean} exclusive is range exclusive
* @returns {string}
* @returns {string} formatted left
*/
static formatLeft(value: number, logic: boolean, exclusive: boolean): string;
/**
Expand All @@ -37,38 +37,38 @@ declare class Range {
* @param {boolean} startExclusive is range exclusive from left side
* @param {boolean} endExclusive is range exclusive from right side
* @param {boolean} logic is not logic applied
* @returns {string}
* @returns {string} formatted range
*/
static formatRange(
start: number,
end: number,
startExclusive: boolean,
endExclusive: boolean,
logic: boolean
logic: boolean,
): string;
/**
* @param {Array<RangeValue>} values
* @param {Array<RangeValue>} values values
* @param {boolean} logic is not logic applied
* @return {RangeValue} computed value and it's exclusive flag
* @returns {RangeValue} computed value and it's exclusive flag
*/
static getRangeValue(values: Array<RangeValue>, logic: boolean): RangeValue;
/** @type {Array<RangeValue>} */
_left: Array<RangeValue>;
/** @type {Array<RangeValue>} */
_right: Array<RangeValue>;
/**
* @param {number} value
* @param {boolean=} exclusive
* @param {number} value value
* @param {boolean=} exclusive true when exclusive, otherwise false
*/
left(value: number, exclusive?: boolean | undefined): void;
/**
* @param {number} value
* @param {boolean=} exclusive
* @param {number} value value
* @param {boolean=} exclusive true when exclusive, otherwise false
*/
right(value: number, exclusive?: boolean | undefined): void;
/**
* @param {boolean} logic is not logic applied
* @return {string} "smart" range string representation
* @returns {string} "smart" range string representation
*/
format(logic?: boolean): string;
}
Expand Down
11 changes: 8 additions & 3 deletions declarations/util/memorize.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export default memoize;
export type FunctionReturning<T> = () => T;
/**
* @template T
* @param fn {(function(): any) | undefined}
* @returns {function(): T}
* @typedef {() => T} FunctionReturning
*/
declare function memoize<T>(fn: (() => any) | undefined): () => T;
/**
* @template T
* @param {FunctionReturning<T>} fn memorized function
* @returns {FunctionReturning<T>} new function
*/
declare function memoize<T>(fn: FunctionReturning<T>): FunctionReturning<T>;
49 changes: 42 additions & 7 deletions declarations/validate.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
export { default as ValidationError } from "./ValidationError";
export type JSONSchema4 = import("json-schema").JSONSchema4;
export type JSONSchema6 = import("json-schema").JSONSchema6;
export type JSONSchema7 = import("json-schema").JSONSchema7;
export type ErrorObject = import("ajv").ErrorObject;
export type ExtendedSchema = {
/**
* format minimum
*/
formatMinimum?: (string | number) | undefined;
/**
* format maximum
*/
formatMaximum?: (string | number) | undefined;
/**
* format exclusive minimum
*/
formatExclusiveMinimum?: (string | boolean) | undefined;
/**
* format exclusive maximum
*/
formatExclusiveMaximum?: (string | boolean) | undefined;
/**
* link
*/
link?: string | undefined;
/**
* undefined will be resolved as null
*/
undefinedAsNull?: boolean | undefined;
};
export type Extend = ExtendedSchema;
Expand All @@ -17,26 +36,42 @@ export type SchemaUtilErrorObject = ErrorObject & {
};
export type PostFormatter = (
formattedError: string,
error: SchemaUtilErrorObject
error: SchemaUtilErrorObject,
) => string;
export type ValidationErrorConfiguration = {
/**
* name
*/
name?: string | undefined;
/**
* base data path
*/
baseDataPath?: string | undefined;
/**
* post formatter
*/
postFormatter?: PostFormatter | undefined;
};
/**
* @param {Schema} schema
* @param {Array<object> | object} options
* @param {ValidationErrorConfiguration=} configuration
* @param {Schema} schema schema
* @param {Array<object> | object} options options
* @param {ValidationErrorConfiguration=} configuration configuration
* @returns {void}
*/
export function validate(
schema: Schema,
options: Array<object> | object,
configuration?: ValidationErrorConfiguration | undefined
configuration?: ValidationErrorConfiguration | undefined,
): void;
/**
* @returns {void}
*/
export function enableValidation(): void;
/**
* @returns {void}
*/
export function disableValidation(): void;
/**
* @returns {boolean} true when need validate, otherwise false
*/
export function needValidate(): boolean;
import ValidationError from "./ValidationError";
export { ValidationError };
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from "eslint/config";
import configs from "eslint-config-webpack/configs.js";

export default defineConfig([
{
extends: [configs["recommended-dirty"]],
rules: {
"n/prefer-node-protocol": "off",
},
},
]);
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('jest').Config} */
const config = {
prettierPath: require.resolve("prettier-2"),
};

module.exports = config;
Loading
Loading