Skip to content

Commit

Permalink
chore: bump deps and clean up tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Oct 11, 2021
1 parent 5334349 commit 4bdc4e4
Show file tree
Hide file tree
Showing 16 changed files with 2,957 additions and 3,069 deletions.
2 changes: 1 addition & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = (api) => ({
targets: { node: 'current' },
},
],
'@babel/preset-typescript',
['@babel/preset-typescript', { allowDeclareFields: true }],
],
plugins: [
'@babel/plugin-proposal-logical-assignment-operators',
Expand Down
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"env": {
"browser": true
},
"rules": {
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-empty-interface": "off"
},
"overrides": [
{
"files": ["test/**"],
Expand Down
57 changes: 29 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,50 +66,51 @@
]
},
"devDependencies": {
"@4c/cli": "^2.1.12",
"@4c/rollout": "^2.1.11",
"@4c/tsconfig": "^0.3.1",
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/plugin-proposal-logical-assignment-operators": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@typescript-eslint/parser": "^4.8.1",
"@4c/cli": "^3.0.1",
"@4c/rollout": "^3.0.1",
"@4c/tsconfig": "^0.4.0",
"@babel/cli": "7.15.7",
"@babel/core": "7.15.8",
"@babel/plugin-proposal-logical-assignment-operators": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.1",
"babel-jest": "^27.2.5",
"babel-plugin-transform-rename-import": "^2.3.0",
"babel-preset-jason": "^6.3.0",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"dirty-chai": "^2.0.1",
"doctoc": "^1.4.0",
"doctoc": "^2.0.1",
"eslint": "^7.12.0",
"eslint-config-jason": "^7.0.1",
"eslint-config-prettier": "^6.14.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-react": "^7.21.5",
"eslint-config-jason": "^8.1.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^25.0.1",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-ts-expect": "^1.0.1",
"eslint-plugin-ts-expect": "^2.0.0",
"eslint-plugin-typescript": "^0.14.0",
"hookem": "^1.0.8",
"jest": "^26.6.1",
"lint-staged": "^11.0.0",
"prettier": "^2.1.2",
"rollup": "^2.32.1",
"hookem": "^2.0.1",
"jest": "^27.2.5",
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"rollup": "^2.58.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-filesize": "^8.0.2",
"rollup-plugin-filesize": "^9.1.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-size-snapshot": "^0.12.0",
"sinon": "^9.2.0",
"sinon-chai": "^3.5.0",
"sinon": "^11.1.2",
"sinon-chai": "^3.7.0",
"synchronous-promise": "^2.0.15",
"typescript": "^4.0.5"
"typescript": "^4.4.3"
},
"dependencies": {
"@babel/runtime": "^7.10.5",
"@types/lodash": "^4.14.165",
"@babel/runtime": "^7.15.4",
"@types/lodash": "^4.14.175",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"nanoclone": "^0.2.1",
Expand Down
3 changes: 1 addition & 2 deletions src/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import MixedSchema from './mixed';
// @ts-ignore
import isoParse from './util/isodate';
import { date as locale, MixedLocale } from './locale';
Expand Down Expand Up @@ -77,7 +76,7 @@ export default class DateSchema<
}

max(max: unknown | Ref, message = locale.max) {
var limit = this.prepareParam(max, 'max');
let limit = this.prepareParam(max, 'max');

return this.test({
message,
Expand Down
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module 'lodash/has' {
// eslint-disable-next-line no-inner-declarations
function has<T extends {}, Key extends PropertyKey>(
obj: T,
prop: Key,
Expand Down
4 changes: 2 additions & 2 deletions src/number.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MixedLocale, number as locale } from './locale';
import isAbsent from './util/isAbsent';
import type { AnyObject, Maybe, Message } from './types';
import type { AnyObject, Maybe } from './types';
import type Reference from './Reference';
import type { Defined, If, Thunk } from './util/types';
import BaseSchema from './schema';
Expand Down Expand Up @@ -112,7 +112,7 @@ export default class NumberSchema<
}

round(method: 'ceil' | 'floor' | 'round' | 'trunc') {
var avail = ['ceil', 'floor', 'round', 'trunc'];
let avail = ['ceil', 'floor', 'round', 'trunc'];
method = (method?.toLowerCase() as any) || ('round' as const);

// this exists for symemtry with the new Math.trunc
Expand Down
13 changes: 6 additions & 7 deletions src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import BaseSchema, {

export type Assign<T extends {}, U extends {}> = {
[P in keyof T]: P extends keyof U ? U[P] : T[P];
} &
U;
} & U;

export type AnyObject = Record<string, any>;

Expand Down Expand Up @@ -78,11 +77,11 @@ export default class ObjectSchema<
TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>,
TOut extends Maybe<AssertsShape<TShape>> =
| AssertsShape<TShape>
| Optionals<TIn>
| Optionals<TIn>,
> extends BaseSchema<TIn, TContext, TOut> {
fields: TShape = Object.create(null);

spec!: ObjectSchemaSpec;
declare spec: ObjectSchemaSpec;

private _sortErrors = defaultSort;
private _nodes: readonly string[] = [];
Expand Down Expand Up @@ -458,7 +457,7 @@ create.prototype = ObjectSchema.prototype;
export interface OptionalObjectSchema<
TShape extends ObjectShape,
TContext extends AnyObject = AnyObject,
TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>
TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>,
> extends ObjectSchema<TShape, TContext, TIn> {
default<TNextDefault extends Maybe<AnyObject>>(
def: TNextDefault | (() => TNextDefault),
Expand Down Expand Up @@ -500,7 +499,7 @@ export interface OptionalObjectSchema<
export interface DefinedObjectSchema<
TShape extends ObjectShape,
TContext extends AnyObject,
TIn extends Maybe<TypeOfShape<TShape>>
TIn extends Maybe<TypeOfShape<TShape>>,
> extends ObjectSchema<
TShape,
TContext,
Expand Down Expand Up @@ -546,7 +545,7 @@ export interface DefinedObjectSchema<
export interface RequiredObjectSchema<
TShape extends ObjectShape,
TContext extends AnyObject,
TIn extends Maybe<TypeOfShape<TShape>>
TIn extends Maybe<TypeOfShape<TShape>>,
> extends ObjectSchema<TShape, TContext, TIn, AssertsShape<TShape>> {
default<TNextDefault extends Maybe<AnyObject>>(
def: TNextDefault | (() => TNextDefault),
Expand Down
50 changes: 25 additions & 25 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export interface SchemaDescription {
export default abstract class BaseSchema<
TCast = any,
TContext = AnyObject,
TOutput = any
TOutput = any,
> {
readonly type: string;

Expand Down Expand Up @@ -183,7 +183,7 @@ export default abstract class BaseSchema<
}

label(label: string) {
var next = this.clone();
let next = this.clone();
next.spec.label = label;
return next;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ export default abstract class BaseSchema<

if (this._typeError) initialTests.push(this._typeError);

let finalTests = [];
let finalTests: any[] = [];
if (this._whitelistError) finalTests.push(this._whitelistError);
if (this._blacklistError) finalTests.push(this._blacklistError);

Expand Down Expand Up @@ -501,7 +501,7 @@ export default abstract class BaseSchema<
}

strict(isStrict = true) {
var next = this.clone();
let next = this.clone();
next.spec.strict = isStrict;
return next;
}
Expand Down Expand Up @@ -535,23 +535,23 @@ export default abstract class BaseSchema<
}

notRequired(): any {
var next = this.clone({ presence: 'optional' });
let next = this.clone({ presence: 'optional' });
next.tests = next.tests.filter((test) => test.OPTIONS.name !== 'required');
return next as any;
}

nullable(isNullable?: true): any;
nullable(isNullable: false): any;
nullable(isNullable = true): any {
var next = this.clone({
let next = this.clone({
nullable: isNullable !== false,
});

return next as any;
}

transform(fn: TransformFunction<this>) {
var next = this.clone();
let next = this.clone();
next.transforms.push(fn as TransformFunction<any>);
return next;
}
Expand Down Expand Up @@ -650,7 +650,7 @@ export default abstract class BaseSchema<
}

typeError(message: Message) {
var next = this.clone();
let next = this.clone();

next._typeError = createValidation({
message,
Expand All @@ -672,7 +672,7 @@ export default abstract class BaseSchema<
enums: Array<Maybe<U> | Reference>,
message = locale.oneOf,
): this {
var next = this.clone();
let next = this.clone();

enums.forEach((val) => {
next._whitelist.add(val);
Expand Down Expand Up @@ -705,7 +705,7 @@ export default abstract class BaseSchema<
enums: Array<Maybe<U> | Reference>,
message = locale.notOneOf,
): this {
var next = this.clone();
let next = this.clone();
enums.forEach((val) => {
next._blacklist.add(val);
next._whitelist.delete(val);
Expand Down Expand Up @@ -757,6 +757,7 @@ export default abstract class BaseSchema<
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default interface BaseSchema<TCast, TContext, TOutput> {
validateAt(
path: string,
Expand All @@ -779,21 +780,20 @@ export default interface BaseSchema<TCast, TContext, TOutput> {
BaseSchema.prototype.__isYupSchema__ = true;

for (const method of ['validate', 'validateSync'])
BaseSchema.prototype[
`${method}At` as 'validateAt' | 'validateSyncAt'
] = function (path: string, value: any, options: ValidateOptions = {}) {
const { parent, parentPath, schema } = getIn(
this,
path,
value,
options.context,
);
return schema[method](parent && parent[parentPath], {
...options,
parent,
path,
});
};
BaseSchema.prototype[`${method}At` as 'validateAt' | 'validateSyncAt'] =
function (path: string, value: any, options: ValidateOptions = {}) {
const { parent, parentPath, schema } = getIn(
this,
path,
value,
options.context,
);
return schema[method](parent && parent[parentPath], {
...options,
parent,
path,
});
};

for (const alias of ['equals', 'is'] as const)
BaseSchema.prototype[alias] = BaseSchema.prototype.oneOf;
Expand Down
6 changes: 4 additions & 2 deletions src/setLocale.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import locale, { LocaleObject } from './locale';

export default function setLocale(custom: LocaleObject) {
Object.keys(custom).forEach(type => {
Object.keys(custom[type]).forEach(method => {
Object.keys(custom).forEach((type) => {
// @ts-ignore
Object.keys(custom[type]).forEach((method) => {
// @ts-ignore
locale[type][method] = custom[type][method];
});
});
Expand Down
16 changes: 9 additions & 7 deletions src/util/createValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ export default function createValidation(config: {

if (!sync) {
try {
Promise.resolve(test.call(ctx, value, ctx)).then((validOrError) => {
if (ValidationError.isError(validOrError)) cb(validOrError);
else if (!validOrError) cb(createError());
else cb(null, validOrError);
}).catch(cb);
} catch (err) {
Promise.resolve(test.call(ctx, value, ctx))
.then((validOrError) => {
if (ValidationError.isError(validOrError)) cb(validOrError);
else if (!validOrError) cb(createError());
else cb(null, validOrError);
})
.catch(cb);
} catch (err: any) {
cb(err);
}

Expand All @@ -138,7 +140,7 @@ export default function createValidation(config: {
`This test will finish after the validate call has returned`,
);
}
} catch (err) {
} catch (err: any) {
cb(err);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/sortFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function sortFields(
let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));

function addNode(depPath: string, key: string) {
var node = split(depPath)[0];
let node = split(depPath)[0];

nodes.add(node);
if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
Expand Down
2 changes: 1 addition & 1 deletion test/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {

plugins: ['ts-expect'],
rules: {
'ts-expect/expect': 'error',
'ts-expect/expect': 'warn',
},
};
Loading

0 comments on commit 4bdc4e4

Please sign in to comment.