From 82a7a166dbf34c10dbc6b0d05b8a0437d085ba34 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Tue, 12 Nov 2019 13:04:44 +0200 Subject: [PATCH] refactor: add declarations to git (#76) --- .gitignore | 4 +- declarations/ValidationError.d.ts | 115 ++++++++++++++++++++++++ declarations/index.d.ts | 2 + declarations/keywords/absolutePath.d.ts | 13 +++ declarations/util/Range.d.ts | 43 +++++++++ declarations/validate.d.ts | 41 +++++++++ package-lock.json | 35 +++++++- package.json | 9 +- 8 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 declarations/ValidationError.d.ts create mode 100644 declarations/index.d.ts create mode 100644 declarations/keywords/absolutePath.d.ts create mode 100644 declarations/util/Range.d.ts create mode 100644 declarations/validate.d.ts diff --git a/.gitignore b/.gitignore index bef4a2b..c08acfd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ yarn-debug.log* .eslintcache -/dist /local /reports /coverage @@ -27,3 +26,6 @@ DS_Store .DS_Store Thumbs.db *.iml + +#build +dist diff --git a/declarations/ValidationError.d.ts b/declarations/ValidationError.d.ts new file mode 100644 index 0000000..bd8acc4 --- /dev/null +++ b/declarations/ValidationError.d.ts @@ -0,0 +1,115 @@ +export default ValidationError; +export type JSONSchema6 = import('json-schema').JSONSchema6; +export type JSONSchema7 = import('json-schema').JSONSchema7; +export type Schema = + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7; +export type ValidationErrorConfiguration = { + name?: string | undefined; + baseDataPath?: string | undefined; + postFormatter?: import('./validate').PostFormatter | undefined; +}; +export type PostFormatter = ( + formattedError: string, + error: import('ajv').ErrorObject & { + children?: import('ajv').ErrorObject[] | undefined; + } +) => string; +export type SchemaUtilErrorObject = import('ajv').ErrorObject & { + children?: import('ajv').ErrorObject[] | undefined; +}; +export type SPECIFICITY = number; +declare class ValidationError extends Error { + /** + * @param {Array} errors + * @param {Schema} schema + * @param {ValidationErrorConfiguration} configuration + */ + constructor( + errors: (import('ajv').ErrorObject & { + children?: import('ajv').ErrorObject[] | undefined; + })[], + schema: + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7, + configuration?: import('./validate').ValidationErrorConfiguration + ); + /** @type {Array} */ + errors: Array; + /** @type {Schema} */ + schema: Schema; + /** @type {string} */ + headerName: string; + /** @type {string} */ + baseDataPath: string; + /** @type {PostFormatter | null} */ + postFormatter: PostFormatter | null; + /** + * @param {string} path + * @returns {Schema} + */ + getSchemaPart( + path: string + ): + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7; + /** + * @param {Schema} schema + * @param {Array} prevSchemas + * @returns {string} + */ + formatSchema( + schema: + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7, + prevSchemas?: Object[] + ): string; + /** + * @param {Schema=} schemaPart + * @param {(boolean | Array)=} additionalPath + * @param {boolean=} needDot + * @returns {string} + */ + getSchemaPartText( + schemaPart?: + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7 + | undefined, + additionalPath?: boolean | string[] | undefined, + needDot?: boolean | undefined + ): string; + /** + * @param {Schema=} schemaPart + * @returns {string} + */ + getSchemaPartDescription( + schemaPart?: + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7 + | undefined + ): string; + /** + * @param {SchemaUtilErrorObject} error + * @returns {string} + */ + formatValidationError( + error: import('ajv').ErrorObject & { + children?: import('ajv').ErrorObject[] | undefined; + } + ): string; + /** + * @param {Array} errors + * @returns {string} + */ + formatValidationErrors( + errors: (import('ajv').ErrorObject & { + children?: import('ajv').ErrorObject[] | undefined; + })[] + ): string; +} diff --git a/declarations/index.d.ts b/declarations/index.d.ts new file mode 100644 index 0000000..2ee7d9e --- /dev/null +++ b/declarations/index.d.ts @@ -0,0 +1,2 @@ +declare const _exports: typeof import('./validate').default; +export = _exports; diff --git a/declarations/keywords/absolutePath.d.ts b/declarations/keywords/absolutePath.d.ts new file mode 100644 index 0000000..5810793 --- /dev/null +++ b/declarations/keywords/absolutePath.d.ts @@ -0,0 +1,13 @@ +export default addAbsolutePathKeyword; +export type Ajv = import('ajv').Ajv; +export type SchemaUtilErrorObject = import('ajv').ErrorObject & { + children?: import('ajv').ErrorObject[] | undefined; +}; +/** + * + * @param {Ajv} ajv + * @returns {Ajv} + */ +declare function addAbsolutePathKeyword( + ajv: import('ajv').Ajv +): import('ajv').Ajv; diff --git a/declarations/util/Range.d.ts b/declarations/util/Range.d.ts new file mode 100644 index 0000000..00009e6 --- /dev/null +++ b/declarations/util/Range.d.ts @@ -0,0 +1,43 @@ +export = Range; +/** + * @typedef {[number, boolean]} RangeValue + */ +/** + * @callback RangeValueCallback + * @param {RangeValue} rangeValue + * @returns {boolean} + */ +declare class Range { + /** @type {Array} */ + _left: Array; + /** @type {Array} */ + _right: Array; + /** + * @param {number} value + * @param {boolean=} exclusive + */ + left(value: number, exclusive?: boolean | undefined): void; + /** + * @param {number} value + * @param {boolean=} exclusive + */ + right(value: number, exclusive?: boolean | undefined): void; + /** + * @param {boolean} logic is not logic applied + * @return {string} "smart" range string representation + */ + format(logic?: boolean): string; +} +declare namespace Range { + export { + getOperator, + formatRight, + formatLeft, + formatRange, + getRangeValue, + RangeValue, + RangeValueCallback, + }; +} +type RangeValue = [number, boolean]; +type RangeValueCallback = (rangeValue: [number, boolean]) => boolean; diff --git a/declarations/validate.d.ts b/declarations/validate.d.ts new file mode 100644 index 0000000..fbba224 --- /dev/null +++ b/declarations/validate.d.ts @@ -0,0 +1,41 @@ +export default validate; +export type JSONSchema4 = import('json-schema').JSONSchema4; +export type JSONSchema6 = import('json-schema').JSONSchema6; +export type JSONSchema7 = import('json-schema').JSONSchema7; +export type ErrorObject = Ajv.ErrorObject; +export type Schema = + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7; +export type SchemaUtilErrorObject = Ajv.ErrorObject & { + children?: Ajv.ErrorObject[] | undefined; +}; +export type PostFormatter = ( + formattedError: string, + error: Ajv.ErrorObject & { + children?: Ajv.ErrorObject[] | undefined; + } +) => string; +export type ValidationErrorConfiguration = { + name?: string | undefined; + baseDataPath?: string | undefined; + postFormatter?: PostFormatter | undefined; +}; +/** + * @param {Schema} schema + * @param {Array | object} options + * @param {ValidationErrorConfiguration=} configuration + * @returns {void} + */ +declare function validate( + schema: + | import('json-schema').JSONSchema4 + | import('json-schema').JSONSchema6 + | import('json-schema').JSONSchema7, + options: any, + configuration?: ValidationErrorConfiguration | undefined +): void; +declare namespace validate { + export { _default as ValidationError, _default as ValidateError }; +} +import Ajv from 'ajv'; diff --git a/package-lock.json b/package-lock.json index 19193f1..901b5e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1171,6 +1171,15 @@ "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", @@ -1336,6 +1345,17 @@ "graceful-fs": "^4.1.3", "mkdirp": "^0.5.1", "rimraf": "^2.5.2" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, "@nodelib/fs.scandir": { @@ -6152,6 +6172,15 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -8727,9 +8756,9 @@ "dev": true }, "rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz", + "integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==", "dev": true, "requires": { "glob": "^7.1.3" diff --git a/package.json b/package.json index c8cbc0b..0a039d8 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,14 @@ "homepage": "https://github.com/webpack/schema-utils", "bugs": "https://github.com/webpack/schema-utils/issues", "main": "dist/index.js", - "types": "dist/index.d.ts", + "types": "declarations/index.d.ts", "engines": { "node": ">= 8.9.0" }, "scripts": { "start": "npm run build -- -w", "prebuild": "npm-run-all --serial clean build:types", - "build:types": "tsc --declaration --emitDeclarationOnly --outDir dist", + "build:types": "rimraf declarations && tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write", "build": "cross-env NODE_ENV=production babel src -d dist --copy-files", "clean": "del-cli dist", "commitlint": "commitlint --from=master", @@ -34,7 +34,9 @@ "defaults": "webpack-defaults" }, "files": [ - "dist" + "dist", + "declarations", + "README.md" ], "dependencies": { "ajv": "^6.10.2", @@ -63,6 +65,7 @@ "lint-staged": "^9.4.0", "npm-run-all": "^4.1.5", "prettier": "^1.18.2", + "rimraf": "^3.0.0", "standard-version": "^7.0.0", "typescript": "^3.7.2" },