From 7526d152c8109e40f1ecc0b7f0015b70dd4d4e3d Mon Sep 17 00:00:00 2001 From: Evyatar Date: Wed, 22 Jul 2020 11:44:29 +0300 Subject: [PATCH] conf: add type declarations for all modules (#265) --- config/builds/vest.js | 3 +- packages/vest/any.d.ts | 3 + packages/vest/classNames.d.ts | 12 + packages/vest/enforceExtended.d.ts | 19 + packages/vest/package.json | 2 +- packages/vest/src/spec/infra.spec.js | 13 +- packages/vest/src/utilities/any.d.ts | 3 + packages/vest/src/utilities/classNames.d.ts | 12 + .../vest/src/utilities/enforceExtended.d.ts | 19 + packages/vest/src/vest.d.ts | 412 ++++++++++++++++++ packages/vest/vest.d.ts | 392 +++++++++-------- scripts/steps/copyDistFiles.js | 17 + 12 files changed, 705 insertions(+), 202 deletions(-) create mode 100644 packages/vest/any.d.ts create mode 100644 packages/vest/classNames.d.ts create mode 100644 packages/vest/enforceExtended.d.ts create mode 100644 packages/vest/src/utilities/any.d.ts create mode 100644 packages/vest/src/utilities/classNames.d.ts create mode 100644 packages/vest/src/utilities/enforceExtended.d.ts create mode 100644 packages/vest/src/vest.d.ts diff --git a/config/builds/vest.js b/config/builds/vest.js index 3fea4ca04..cbde96d0c 100644 --- a/config/builds/vest.js +++ b/config/builds/vest.js @@ -29,6 +29,7 @@ const PLUGINS = [ LIBRARY_NAME: JSON.stringify(PACKAGE_VEST), }), compiler(), + terser(), ]; const buildConfig = ({ format = DEFAULT_FORMAT, min = false } = {}) => ({ @@ -45,7 +46,7 @@ const buildConfig = ({ format = DEFAULT_FORMAT, min = false } = {}) => ({ format, name: PACKAGE_VEST, }, - plugins: min ? [...PLUGINS, terser()] : PLUGINS, + plugins: PLUGINS, }); export default [buildConfig(), buildConfig({ min: true })]; diff --git a/packages/vest/any.d.ts b/packages/vest/any.d.ts new file mode 100644 index 000000000..07f22ba9a --- /dev/null +++ b/packages/vest/any.d.ts @@ -0,0 +1,3 @@ +declare function any(...args: any[]): boolean; + +export default any; diff --git a/packages/vest/classNames.d.ts b/packages/vest/classNames.d.ts new file mode 100644 index 000000000..810255c9b --- /dev/null +++ b/packages/vest/classNames.d.ts @@ -0,0 +1,12 @@ +declare function classNames( + res: Partial, + classes?: { + valid?: string; + tested?: string; + invalid?: string; + warning?: string; + untested?: string; + } +): (fieldName: string) => string; + +export default classNames; diff --git a/packages/vest/enforceExtended.d.ts b/packages/vest/enforceExtended.d.ts new file mode 100644 index 000000000..56a164f8e --- /dev/null +++ b/packages/vest/enforceExtended.d.ts @@ -0,0 +1,19 @@ +interface ExtendedRules { + isAlphanumeric: (...args: any) => IEnforceRules; + isCreditCard: (...args: any) => IEnforceRules; + isCurrency: (...args: any) => IEnforceRules; + isEmail: (...args: any) => IEnforceRules; + isIP: (...args: any) => IEnforceRules; + isIdentityCard: (...args: any) => IEnforceRules; + isJSON: (...args: any) => IEnforceRules; + isLocale: (...args: any) => IEnforceRules; + isMimeType: (...args: any) => IEnforceRules; + isMobilePhone: (...args: any) => IEnforceRules; + isPassportNumber: (...args: any) => IEnforceRules; + isPostalCode: (...args: any) => IEnforceRules; + isURL: (...args: any) => IEnforceRules; +} + +declare function enforceExtended(value: any): EnforceExtendMap; + +export default enforceExtended; diff --git a/packages/vest/package.json b/packages/vest/package.json index 2807e61e0..db5674859 100644 --- a/packages/vest/package.json +++ b/packages/vest/package.json @@ -2,7 +2,7 @@ "name": "vest", "version": "2.0.0", "description": "Validation Test", - "main": "./vest.min.js", + "main": "./vest.js", "types": "./vest.d.ts", "author": "ealush", "license": "MIT", diff --git a/packages/vest/src/spec/infra.spec.js b/packages/vest/src/spec/infra.spec.js index a6bb8817f..61679e723 100644 --- a/packages/vest/src/spec/infra.spec.js +++ b/packages/vest/src/spec/infra.spec.js @@ -1,4 +1,5 @@ const { execSync } = require('child_process'); +const glob = require('glob'); const vest = require('..'); const packagePath = require('../../../../util/packagePath'); const { version } = require('../../package.json'); @@ -130,9 +131,17 @@ describe('General scenario tests', () => { }); describe('TypeScript Typings', () => { - it('Should Pass tsc validation on a valid file', () => { + const declarationFiles = glob + .sync('src/**/*.d.ts', { + cwd: packagePath('vest'), + absolute: true, + ignore: '**/spec/*', + }) + .join(' '); + + it(`Should pass tsc validation`, () => { expect(() => { - execSync(`node_modules/.bin/tsc ${packagePath('vest', 'vest.d.ts')}`); + execSync(`node_modules/.bin/tsc ${declarationFiles}`); }).not.toThrow(); }); diff --git a/packages/vest/src/utilities/any.d.ts b/packages/vest/src/utilities/any.d.ts new file mode 100644 index 000000000..07f22ba9a --- /dev/null +++ b/packages/vest/src/utilities/any.d.ts @@ -0,0 +1,3 @@ +declare function any(...args: any[]): boolean; + +export default any; diff --git a/packages/vest/src/utilities/classNames.d.ts b/packages/vest/src/utilities/classNames.d.ts new file mode 100644 index 000000000..810255c9b --- /dev/null +++ b/packages/vest/src/utilities/classNames.d.ts @@ -0,0 +1,12 @@ +declare function classNames( + res: Partial, + classes?: { + valid?: string; + tested?: string; + invalid?: string; + warning?: string; + untested?: string; + } +): (fieldName: string) => string; + +export default classNames; diff --git a/packages/vest/src/utilities/enforceExtended.d.ts b/packages/vest/src/utilities/enforceExtended.d.ts new file mode 100644 index 000000000..56a164f8e --- /dev/null +++ b/packages/vest/src/utilities/enforceExtended.d.ts @@ -0,0 +1,19 @@ +interface ExtendedRules { + isAlphanumeric: (...args: any) => IEnforceRules; + isCreditCard: (...args: any) => IEnforceRules; + isCurrency: (...args: any) => IEnforceRules; + isEmail: (...args: any) => IEnforceRules; + isIP: (...args: any) => IEnforceRules; + isIdentityCard: (...args: any) => IEnforceRules; + isJSON: (...args: any) => IEnforceRules; + isLocale: (...args: any) => IEnforceRules; + isMimeType: (...args: any) => IEnforceRules; + isMobilePhone: (...args: any) => IEnforceRules; + isPassportNumber: (...args: any) => IEnforceRules; + isPostalCode: (...args: any) => IEnforceRules; + isURL: (...args: any) => IEnforceRules; +} + +declare function enforceExtended(value: any): EnforceExtendMap; + +export default enforceExtended; diff --git a/packages/vest/src/vest.d.ts b/packages/vest/src/vest.d.ts new file mode 100644 index 000000000..21fae7d02 --- /dev/null +++ b/packages/vest/src/vest.d.ts @@ -0,0 +1,412 @@ +type TestCB = () => void | Promise | false; +type DraftResult = Omit; +type DoneCB = (res: DraftResult) => void; +type ExclusionArg = string | string[] | void; + +interface IVestResult { + name: string; + errorCount: number; + warnCount: number; + testCount: number; + tests: { + [fieldName: string]: { + errorCount: number; + warnCount: number; + testCount: number; + errors?: string[]; + warnings?: string[]; + }; + }; + groups: { + [groupName: string]: { + [fieldName: string]: { + errorCount: number; + warnCount: number; + testCount: number; + errors?: string[]; + warnings?: string[]; + }; + }; + }; + + /** + * Returns whether the specified field has errors + */ + hasErrors: (fieldName?: string) => boolean; + /** + * Returns whether the specified field has warnings + */ + hasWarnings: (fieldName?: string) => boolean; + /** + * Returns the error messages for all fields + */ + getErrors(): { [fieldName: string]: string[] }; + /** + * Returns the error messages for the specified test + */ + getErrors(fieldName: string): string[]; + /** + * Returns the warning messages for all fields + */ + getWarnings(): { [fieldName: string]: string[] }; + /** + * Returns the warning messages for the specified test + */ + getWarnings(fieldName: string): string[]; + + /** + * Returns whether the specified group has errors + */ + hasErrorsByGroup(groupName: string): boolean; + /** + * Returns whether the specified group and field combination has errors + */ + hasErrorsByGroup(groupName: string, fieldName: string): boolean; + /** + * Returns whether the specified group has warnings + */ + hasWarningsByGroup(groupName: string): boolean; + /** + * Returns whether the specified group and field combination has warnings + */ + hasWarningsByGroup(groupName: string, fieldName: string): boolean; + + /** + * Returns all the error messages for the specified group + */ + getErrorsByGroup(groupName: string): { [fieldName: string]: string[] }; + /** + * Returns all the error messages for the specified group and field + */ + getErrorsByGroup(groupName: string, fieldName: string): string[]; + /** + * Returns all the warning messages for the specified group + */ + getWarningsByGroup(groupName: string): { [fieldName: string]: string[] }; + /** + * Returns all the warning messages for the specified group and field + */ + getWarningsByGroup(groupName: string, fieldName: string): string[]; + /** + * Runs a callback when all tests are finished running + */ + done(cb: DoneCB): void; + /** + * Runs a callback when all tests of the specified field finished running + */ + done(fieldName: string, cb: DoneCB): void; +} + +type EnforceExtendMap = { + [K in keyof T]: (...args: any[]) => IEnforceRules & EnforceExtendMap; +}; + +interface IEnforceRules { + equals: (expected: any) => IEnforceRules & EnforceExtendMap; + notEquls: (expected: any) => IEnforceRules & EnforceExtendMap; + numberEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + greaterThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + greaterThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + lessThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + lessThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + longerThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + longerThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + shorterThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + shorterThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + gt: (expected: number | string) => IEnforceRules & EnforceExtendMap; + gte: (expected: number | string) => IEnforceRules & EnforceExtendMap; + lt: (expected: number | string) => IEnforceRules & EnforceExtendMap; + lte: (expected: number | string) => IEnforceRules & EnforceExtendMap; + numberNotEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + matches: ( + expected: string | RegExp + ) => IEnforceRules & EnforceExtendMap; + notMatches: ( + expected: string | RegExp + ) => IEnforceRules & EnforceExtendMap; + isArray: () => IEnforceRules & EnforceExtendMap; + isEmpty: () => IEnforceRules & EnforceExtendMap; + isEven: () => IEnforceRules & EnforceExtendMap; + isNumber: () => IEnforceRules & EnforceExtendMap; + isNumeric: () => IEnforceRules & EnforceExtendMap; + isOdd: () => IEnforceRules & EnforceExtendMap; + isTruthy: () => IEnforceRules & EnforceExtendMap; + isFalsy: () => IEnforceRules & EnforceExtendMap; + isString: () => IEnforceRules & EnforceExtendMap; + isNotArray: () => IEnforceRules & EnforceExtendMap; + isNotEmpty: () => IEnforceRules & EnforceExtendMap; + isNotNumber: () => IEnforceRules & EnforceExtendMap; + isNotNumeric: () => IEnforceRules & EnforceExtendMap; + isNotString: () => IEnforceRules & EnforceExtendMap; + inside: ( + expected: Array | string + ) => IEnforceRules & EnforceExtendMap; + notInside: ( + expected: Array | string + ) => IEnforceRules & EnforceExtendMap; + lengthEquals: (expected: number) => IEnforceRules & EnforceExtendMap; + lengthNotEquals: (expected: number) => IEnforceRules & EnforceExtendMap; +} + +interface IEnforce { + /** + * Assertion function. Throws an error on failure. + * @param value Value being enforced + */ + (value: any): IEnforceRules; + + /** + * Adds custom rules to enforce + * @param rules Rules object to add onto enforce + * + * @example + * + * const customEnforce = enforce.extend({ + * isValidEmail: (email) => email.includes('@') + * }); + * + * customEnforce('notAnEmail') // throws an error + */ + extend boolean }>( + obj: T + ): (value: any) => IEnforceRules & EnforceExtendMap; +} + +declare module 'vest' { + interface VestTest { + failed: boolean; + fieldName: string; + id: string; + isWarning: boolean; + statement: string; + suiteId: string; + testFn: TestCB; + asyncTest?: Promise; + } + + interface ISkip { + /** + * Skips provided field from current run. + * When undefined, the expression is ignored. + * @param [fieldName] Field name or a list of fields to exclude + * + * @example + * + * vest.skip('username'); + * vest.skip(['username', 'password']); + */ + (fieldName?: ExclusionArg): void; + /** + * Skips provided group from current run. + * When undefined, the expression is ignored. + * @param [groupName] group name or a list of groups to exclude. + * + * @example + * + * vest.skip.group('username'); + * vest.skip.group(['username', 'password']); + */ + group(groupName?: ExclusionArg): void; + } + + interface IOnly { + /** + * Singles out a field name to be tested. + * When fieldName is undefined, the expression is ignored. + * @param [fieldName] Field name or a list of fields to include + * + * @example + * + * vest.only('username'); + * vest.only(['username', 'password']); + */ + (fieldName?: ExclusionArg): void; + /** + * Singles out a group name to be tested. + * When groupName is undefined, the expression is ignored. + * @param [groupName] Field name or a list of groups to include. + * + * @example + * + * vest.only.group('username'); + * vest.only.group(['username', 'password']); + */ + group(groupName?: ExclusionArg): void; + } + + interface ITest { + /** + * Runs a single test + * @param fieldName The name of the field being validated + * @param message Descriptive message to display on failure + * @param testFn Test body + * + * @example + * + * test('username', 'Username is required', () => { + * enforce(username).isNotEmpty(); + * }); + */ + (fieldName: string, message: string, testFn: TestCB): VestTest; + /** + * Runs a single test + * @param fieldName The name of the field being validated + * @param testFn Test body + * + * @example + * + * test('username', () => { + * enforce(username).isNotEmpty(); + * }); + */ + (fieldName: string, testFn: TestCB): VestTest; + + /** + * Runs a single test. Memoizes the result based on the dependency array. + * @param fieldName The name of the field being validated + * @param message Descriptive message to display on failure + * @param testFn Test body + * @param dependencies An array of values to be checked for strict equality ('===') + * + * @example + * + * test.memo('username', 'Username already exists', () => doesUserExist(username), [username]) + */ + memo( + fieldName: string, + message: string, + testFn: TestCB, + dependencies: any[] + ): VestTest; + /** + * Runs a single test. Memoizes the result based on the dependency array. + * @param fieldName The name of the field being validated + * @param testFn Test body + * @param dependencies An array of values to be checked for strict equality ('===') + * + * @example + * + * test.memo('username', () => doesUserExist(username), [username]) + */ + memo(fieldName: string, testFn: TestCB, dependencies: any[]): VestTest; + } + + interface Vest { + test: ITest; + enforce: IEnforce; + only: IOnly; + skip: ISkip; + + /** + * Runs a stateless validation suite. + * @param suiteName Unique suite name. + * @param tests Suite body. + * + * const res = validate('form_name', () => { + * // your tests go here + * }); + */ + validate(suiteName: string, tests: () => void): IVestResult; + + /** + * Runs a stateful validation suite. + * @param suiteName Unique suite name. + * @param tests Suite body. + * + * @example + * + * const validate = vest.create('form_name', (data = {}) => { + * // your tests go here + * }); + * + * const res = validate({username: 'example'}); + */ + create( + suiteName: string, + tests: (...args: any[]) => void + ): (...args: any[]) => IVestResult; + + /** + * Allows grouping tests so you can handle them together + * @param groupName Group name. + * @param testFn Group body. + * + * @example + * + * group('sign_up', () => { + * // your tests go here + * }); + */ + group(groupName: string, testFn: () => void): void; + + /** + * Marks a test as warning. + * Needs to run within a test body. + * + * @example + * + * test('password', 'Consider using a longer password.', () => { + * vest.warn(); + * + * enforce(password).longerThan(10); + * }); + */ + warn(): void; + + /** + * Retrieves an intermediate validation result during the validation runtime. + */ + draft(): DraftResult; + VERSION: string; + } + + const { + test, + validate, + create, + warn, + draft, + VERSION, + enforce, + skip, + only, + group, + }: Vest; + + export { + test, + validate, + create, + warn, + draft, + VERSION, + enforce, + skip, + only, + group, + }; + + const vest: Vest; + + export default vest; +} diff --git a/packages/vest/vest.d.ts b/packages/vest/vest.d.ts index 6b499fd54..21fae7d02 100644 --- a/packages/vest/vest.d.ts +++ b/packages/vest/vest.d.ts @@ -1,9 +1,198 @@ -declare module 'vest' { - type TestCB = () => void | Promise | false; - type DraftResult = Omit; - type DoneCB = (res: DraftResult) => void; - type ExclusionArg = string | string[] | void; +type TestCB = () => void | Promise | false; +type DraftResult = Omit; +type DoneCB = (res: DraftResult) => void; +type ExclusionArg = string | string[] | void; + +interface IVestResult { + name: string; + errorCount: number; + warnCount: number; + testCount: number; + tests: { + [fieldName: string]: { + errorCount: number; + warnCount: number; + testCount: number; + errors?: string[]; + warnings?: string[]; + }; + }; + groups: { + [groupName: string]: { + [fieldName: string]: { + errorCount: number; + warnCount: number; + testCount: number; + errors?: string[]; + warnings?: string[]; + }; + }; + }; + + /** + * Returns whether the specified field has errors + */ + hasErrors: (fieldName?: string) => boolean; + /** + * Returns whether the specified field has warnings + */ + hasWarnings: (fieldName?: string) => boolean; + /** + * Returns the error messages for all fields + */ + getErrors(): { [fieldName: string]: string[] }; + /** + * Returns the error messages for the specified test + */ + getErrors(fieldName: string): string[]; + /** + * Returns the warning messages for all fields + */ + getWarnings(): { [fieldName: string]: string[] }; + /** + * Returns the warning messages for the specified test + */ + getWarnings(fieldName: string): string[]; + + /** + * Returns whether the specified group has errors + */ + hasErrorsByGroup(groupName: string): boolean; + /** + * Returns whether the specified group and field combination has errors + */ + hasErrorsByGroup(groupName: string, fieldName: string): boolean; + /** + * Returns whether the specified group has warnings + */ + hasWarningsByGroup(groupName: string): boolean; + /** + * Returns whether the specified group and field combination has warnings + */ + hasWarningsByGroup(groupName: string, fieldName: string): boolean; + + /** + * Returns all the error messages for the specified group + */ + getErrorsByGroup(groupName: string): { [fieldName: string]: string[] }; + /** + * Returns all the error messages for the specified group and field + */ + getErrorsByGroup(groupName: string, fieldName: string): string[]; + /** + * Returns all the warning messages for the specified group + */ + getWarningsByGroup(groupName: string): { [fieldName: string]: string[] }; + /** + * Returns all the warning messages for the specified group and field + */ + getWarningsByGroup(groupName: string, fieldName: string): string[]; + /** + * Runs a callback when all tests are finished running + */ + done(cb: DoneCB): void; + /** + * Runs a callback when all tests of the specified field finished running + */ + done(fieldName: string, cb: DoneCB): void; +} + +type EnforceExtendMap = { + [K in keyof T]: (...args: any[]) => IEnforceRules & EnforceExtendMap; +}; + +interface IEnforceRules { + equals: (expected: any) => IEnforceRules & EnforceExtendMap; + notEquls: (expected: any) => IEnforceRules & EnforceExtendMap; + numberEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + greaterThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + greaterThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + lessThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + lessThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + longerThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + longerThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + shorterThan: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + shorterThanOrEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + gt: (expected: number | string) => IEnforceRules & EnforceExtendMap; + gte: (expected: number | string) => IEnforceRules & EnforceExtendMap; + lt: (expected: number | string) => IEnforceRules & EnforceExtendMap; + lte: (expected: number | string) => IEnforceRules & EnforceExtendMap; + numberNotEquals: ( + expected: number | string + ) => IEnforceRules & EnforceExtendMap; + matches: ( + expected: string | RegExp + ) => IEnforceRules & EnforceExtendMap; + notMatches: ( + expected: string | RegExp + ) => IEnforceRules & EnforceExtendMap; + isArray: () => IEnforceRules & EnforceExtendMap; + isEmpty: () => IEnforceRules & EnforceExtendMap; + isEven: () => IEnforceRules & EnforceExtendMap; + isNumber: () => IEnforceRules & EnforceExtendMap; + isNumeric: () => IEnforceRules & EnforceExtendMap; + isOdd: () => IEnforceRules & EnforceExtendMap; + isTruthy: () => IEnforceRules & EnforceExtendMap; + isFalsy: () => IEnforceRules & EnforceExtendMap; + isString: () => IEnforceRules & EnforceExtendMap; + isNotArray: () => IEnforceRules & EnforceExtendMap; + isNotEmpty: () => IEnforceRules & EnforceExtendMap; + isNotNumber: () => IEnforceRules & EnforceExtendMap; + isNotNumeric: () => IEnforceRules & EnforceExtendMap; + isNotString: () => IEnforceRules & EnforceExtendMap; + inside: ( + expected: Array | string + ) => IEnforceRules & EnforceExtendMap; + notInside: ( + expected: Array | string + ) => IEnforceRules & EnforceExtendMap; + lengthEquals: (expected: number) => IEnforceRules & EnforceExtendMap; + lengthNotEquals: (expected: number) => IEnforceRules & EnforceExtendMap; +} + +interface IEnforce { + /** + * Assertion function. Throws an error on failure. + * @param value Value being enforced + */ + (value: any): IEnforceRules; + + /** + * Adds custom rules to enforce + * @param rules Rules object to add onto enforce + * + * @example + * + * const customEnforce = enforce.extend({ + * isValidEmail: (email) => email.includes('@') + * }); + * + * customEnforce('notAnEmail') // throws an error + */ + extend boolean }>( + obj: T + ): (value: any) => IEnforceRules & EnforceExtendMap; +} +declare module 'vest' { interface VestTest { failed: boolean; fieldName: string; @@ -122,32 +311,6 @@ declare module 'vest' { memo(fieldName: string, testFn: TestCB, dependencies: any[]): VestTest; } - interface IEnforce { - /** - * Assertion function. Throws an error on failure. - * @param value Value being enforced - */ - (value: any): IEnforceRules; - - /** - * Adds custom rules to enforce - * @param rules Rules object to add onto enforce - * - * @example - * - * const customEnforce = enforce.extend({ - * isValidEmail: (email) => email.includes('@') - * }); - * - * customEnforce('notAnEmail') // throws an error - */ - extend< - T extends { [key: string]: (value: any, ...args: any[]) => boolean } - >( - obj: T - ): (value: any) => IEnforceRules & EnforceExtendMap; - } - interface Vest { test: ITest; enforce: IEnforce; @@ -217,173 +380,6 @@ declare module 'vest' { VERSION: string; } - interface IVestResult { - name: string; - errorCount: number; - warnCount: number; - testCount: number; - tests: { - [fieldName: string]: { - errorCount: number; - warnCount: number; - testCount: number; - errors?: string[]; - warnings?: string[]; - }; - }; - groups: { - [groupName: string]: { - [fieldName: string]: { - errorCount: number; - warnCount: number; - testCount: number; - errors?: string[]; - warnings?: string[]; - }; - }; - }; - - /** - * Returns whether the specified field has errors - */ - hasErrors: (fieldName?: string) => boolean; - /** - * Returns whether the specified field has warnings - */ - hasWarnings: (fieldName?: string) => boolean; - /** - * Returns the error messages for all fields - */ - getErrors(): { [fieldName: string]: string[] }; - /** - * Returns the error messages for the specified test - */ - getErrors(fieldName: string): string[]; - /** - * Returns the warning messages for all fields - */ - getWarnings(): { [fieldName: string]: string[] }; - /** - * Returns the warning messages for the specified test - */ - getWarnings(fieldName: string): string[]; - - /** - * Returns whether the specified group has errors - */ - hasErrorsByGroup(groupName: string): boolean; - /** - * Returns whether the specified group and field combination has errors - */ - hasErrorsByGroup(groupName: string, fieldName: string): boolean; - /** - * Returns whether the specified group has warnings - */ - hasWarningsByGroup(groupName: string): boolean; - /** - * Returns whether the specified group and field combination has warnings - */ - hasWarningsByGroup(groupName: string, fieldName: string): boolean; - - /** - * Returns all the error messages for the specified group - */ - getErrorsByGroup(groupName: string): { [fieldName: string]: string[] }; - /** - * Returns all the error messages for the specified group and field - */ - getErrorsByGroup(groupName: string, fieldName: string): string[]; - /** - * Returns all the warning messages for the specified group - */ - getWarningsByGroup(groupName: string): { [fieldName: string]: string[] }; - /** - * Returns all the warning messages for the specified group and field - */ - getWarningsByGroup(groupName: string, fieldName: string): string[]; - /** - * Runs a callback when all tests are finished running - */ - done(cb: DoneCB): void; - /** - * Runs a callback when all tests of the specified field finished running - */ - done(fieldName: string, cb: DoneCB): void; - } - - type EnforceExtendMap = { - [K in keyof T]: (...args: any[]) => IEnforceRules & EnforceExtendMap; - }; - - interface IEnforceRules { - equals: (expected: any) => IEnforceRules & EnforceExtendMap; - notEquls: (expected: any) => IEnforceRules & EnforceExtendMap; - numberEquals: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - greaterThan: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - greaterThanOrEquals: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - lessThan: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - lessThanOrEquals: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - longerThan: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - longerThanOrEquals: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - shorterThan: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - shorterThanOrEquals: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - gt: (expected: number | string) => IEnforceRules & EnforceExtendMap; - gte: (expected: number | string) => IEnforceRules & EnforceExtendMap; - lt: (expected: number | string) => IEnforceRules & EnforceExtendMap; - lte: (expected: number | string) => IEnforceRules & EnforceExtendMap; - numberNotEquals: ( - expected: number | string - ) => IEnforceRules & EnforceExtendMap; - matches: ( - expected: string | RegExp - ) => IEnforceRules & EnforceExtendMap; - notMatches: ( - expected: string | RegExp - ) => IEnforceRules & EnforceExtendMap; - isArray: () => IEnforceRules & EnforceExtendMap; - isEmpty: () => IEnforceRules & EnforceExtendMap; - isEven: () => IEnforceRules & EnforceExtendMap; - isNumber: () => IEnforceRules & EnforceExtendMap; - isNumeric: () => IEnforceRules & EnforceExtendMap; - isOdd: () => IEnforceRules & EnforceExtendMap; - isTruthy: () => IEnforceRules & EnforceExtendMap; - isFalsy: () => IEnforceRules & EnforceExtendMap; - isString: () => IEnforceRules & EnforceExtendMap; - isNotArray: () => IEnforceRules & EnforceExtendMap; - isNotEmpty: () => IEnforceRules & EnforceExtendMap; - isNotNumber: () => IEnforceRules & EnforceExtendMap; - isNotNumeric: () => IEnforceRules & EnforceExtendMap; - isNotString: () => IEnforceRules & EnforceExtendMap; - inside: ( - expected: Array | string - ) => IEnforceRules & EnforceExtendMap; - notInside: ( - expected: Array | string - ) => IEnforceRules & EnforceExtendMap; - lengthEquals: (expected: number) => IEnforceRules & EnforceExtendMap; - lengthNotEquals: ( - expected: number - ) => IEnforceRules & EnforceExtendMap; - } - const { test, validate, diff --git a/scripts/steps/copyDistFiles.js b/scripts/steps/copyDistFiles.js index 6e68292d6..9f6ed3d75 100644 --- a/scripts/steps/copyDistFiles.js +++ b/scripts/steps/copyDistFiles.js @@ -1,9 +1,26 @@ +const path = require('path'); const { copySync, pathExistsSync } = require('fs-extra'); +const glob = require('glob'); + const { packagePath, logger } = require('../../util'); function copyDistFiles(packageName) { logger.info('📑 Copying distribution files'); + // Gather all non-spec type declarations from the package + // And copy them over to the root folder + // This is good enough until I add a ts build + glob + .sync('src/**/*.d.ts', { + cwd: packagePath(packageName), + absolute: true, + ignore: '**/spec/*', + }) + .forEach(filePath => { + copySync(filePath, packagePath(packageName, path.basename(filePath))); + }); + + // Copy all distribution files into root folder const distPath = packagePath(packageName, 'dist'); if (pathExistsSync(distPath)) {