@appliedblockchain/assert-combinators
Advanced tools
Comparing version 5.3.2 to 5.4.0
# Changelog | ||
## [v5.4.0](../../compare/v5.3.2...v5.4.0) (2022-09-21) | ||
* Feat(eventually): custom error constructor with last result inspection. | ||
* Chore: bumping dev deps. | ||
* Renaming nil to nullish. | ||
* Bumping deps. | ||
* Updating changelog. | ||
## [v5.3.2](../../compare/v5.3.1...v5.3.2) (2022-03-28) | ||
@@ -4,0 +12,0 @@ |
@@ -1,5 +0,7 @@ | ||
declare const eventually: <T, U>(assert: (result: T) => U, poll: () => Promise<T>, { retries, delay }?: { | ||
declare const eventually: <T, U>(assert: (result: T) => U, poll: () => Promise<T>, { retries, delay, error }?: { | ||
retries?: number | undefined; | ||
delay?: number | undefined; | ||
/** Error constructor based on thrown assertion error and last polled result. */ | ||
error?: ((err: unknown, result: T) => unknown) | undefined; | ||
}) => Promise<U>; | ||
export default eventually; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const eventually = async (assert, poll, { retries = 10, delay = 1000 } = {}) => { | ||
const defaultError = (err, result) => new Error((err instanceof Error ? err.message : String(err)) + ' Last result was ' + JSON.stringify(result) + '.'); | ||
const eventually = async (assert, poll, { retries = 10, delay = 1000, error = defaultError } = {}) => { | ||
for (let retry = 1; retry <= retries; retry++) { | ||
@@ -12,3 +13,3 @@ const before = Date.now(); | ||
if (retry === retries) { | ||
throw err; | ||
throw error(err, result); | ||
} | ||
@@ -15,0 +16,0 @@ } |
@@ -23,7 +23,7 @@ import and from './and.js'; | ||
import never_ from './never.js'; | ||
import nil from './nil.js'; | ||
import nilOr from './nil-or.js'; | ||
import nonBlankString from './non-blank-string.js'; | ||
import nonNullish from './non-nullish.js'; | ||
import null_ from './null.js'; | ||
import nullish from './nullish.js'; | ||
import nullishOr from './nullish-or.js'; | ||
import nullOr from './null-or.js'; | ||
@@ -52,2 +52,2 @@ import number from './number.js'; | ||
export * from './prelude.js'; | ||
export { and, array, boolean, dateString, defined, eq, errorOf, eventually, exact, false_ as false, finite, gt, gte, if_ as if, ignore, implies, in_ as in, instance, keyed, lt, lte, never_ as never, nil, nilOr, nonBlankString, nonNullish, null_ as null, nullOr, number, object, ok, oneOf, or, partial, positive, predicate, record, regexp, rethrow, safeInteger, sequence, strftime, string, true_ as true, tuple, undefined_ as undefined, undefinedOr, unique, unknown }; | ||
export { and, array, boolean, dateString, defined, eq, errorOf, eventually, exact, false_ as false, finite, gt, gte, if_ as if, ignore, implies, in_ as in, instance, keyed, lt, lte, never_ as never, nonBlankString, nonNullish, null_ as null, nullish, nullishOr, nullOr, number, object, ok, oneOf, or, partial, positive, predicate, record, regexp, rethrow, safeInteger, sequence, strftime, string, true_ as true, tuple, undefined_ as undefined, undefinedOr, unique, unknown }; |
@@ -20,3 +20,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unknown = exports.unique = exports.undefinedOr = exports.undefined = exports.tuple = exports.true = exports.string = exports.strftime = exports.sequence = exports.safeInteger = exports.rethrow = exports.regexp = exports.record = exports.predicate = exports.positive = exports.partial = exports.or = exports.oneOf = exports.ok = exports.object = exports.number = exports.nullOr = exports.null = exports.nonNullish = exports.nonBlankString = exports.nilOr = exports.nil = exports.never = exports.lte = exports.lt = exports.keyed = exports.instance = exports.in = exports.implies = exports.ignore = exports.if = exports.gte = exports.gt = exports.finite = exports.false = exports.exact = exports.eventually = exports.errorOf = exports.eq = exports.defined = exports.dateString = exports.boolean = exports.array = exports.and = void 0; | ||
exports.unknown = exports.unique = exports.undefinedOr = exports.undefined = exports.tuple = exports.true = exports.string = exports.strftime = exports.sequence = exports.safeInteger = exports.rethrow = exports.regexp = exports.record = exports.predicate = exports.positive = exports.partial = exports.or = exports.oneOf = exports.ok = exports.object = exports.number = exports.nullOr = exports.nullishOr = exports.nullish = exports.null = exports.nonNullish = exports.nonBlankString = exports.never = exports.lte = exports.lt = exports.keyed = exports.instance = exports.in = exports.implies = exports.ignore = exports.if = exports.gte = exports.gt = exports.finite = exports.false = exports.exact = exports.eventually = exports.errorOf = exports.eq = exports.defined = exports.dateString = exports.boolean = exports.array = exports.and = void 0; | ||
const and_js_1 = __importDefault(require("./and.js")); | ||
@@ -66,6 +66,2 @@ exports.and = and_js_1.default; | ||
exports.never = never_js_1.default; | ||
const nil_js_1 = __importDefault(require("./nil.js")); | ||
exports.nil = nil_js_1.default; | ||
const nil_or_js_1 = __importDefault(require("./nil-or.js")); | ||
exports.nilOr = nil_or_js_1.default; | ||
const non_blank_string_js_1 = __importDefault(require("./non-blank-string.js")); | ||
@@ -77,2 +73,6 @@ exports.nonBlankString = non_blank_string_js_1.default; | ||
exports.null = null_js_1.default; | ||
const nullish_js_1 = __importDefault(require("./nullish.js")); | ||
exports.nullish = nullish_js_1.default; | ||
const nullish_or_js_1 = __importDefault(require("./nullish-or.js")); | ||
exports.nullishOr = nullish_or_js_1.default; | ||
const null_or_js_1 = __importDefault(require("./null-or.js")); | ||
@@ -79,0 +79,0 @@ exports.nullOr = null_or_js_1.default; |
@@ -9,5 +9,5 @@ /** Helper no-op, parametric type to expand intellisense for alias types. */ | ||
export declare type Keyed<T = unknown> = Record<string, T | undefined>; | ||
export declare type NilOr<T> = undefined | null | T; | ||
export declare type Nullish<T> = undefined | null | T; | ||
export declare type UndefinedOr<T> = undefined | T; | ||
export declare type NullOr<T> = null | T; | ||
export declare type Nullable<T> = null | T; | ||
export declare type Defined<T> = Exclude<T, undefined>; | ||
@@ -17,1 +17,2 @@ export declare type NonNullish<T> = Exclude<T, undefined | null>; | ||
export declare type Primitive = undefined | null | boolean | number | string | symbol; | ||
export declare type Exact<T, I> = T extends I ? Exclude<keyof T, keyof I> extends never ? T : never : never; |
@@ -1,5 +0,7 @@ | ||
declare const eventually: <T, U>(assert: (result: T) => U, poll: () => Promise<T>, { retries, delay }?: { | ||
declare const eventually: <T, U>(assert: (result: T) => U, poll: () => Promise<T>, { retries, delay, error }?: { | ||
retries?: number | undefined; | ||
delay?: number | undefined; | ||
/** Error constructor based on thrown assertion error and last polled result. */ | ||
error?: ((err: unknown, result: T) => unknown) | undefined; | ||
}) => Promise<U>; | ||
export default eventually; |
@@ -1,2 +0,3 @@ | ||
const eventually = async (assert, poll, { retries = 10, delay = 1000 } = {}) => { | ||
const defaultError = (err, result) => new Error((err instanceof Error ? err.message : String(err)) + ' Last result was ' + JSON.stringify(result) + '.'); | ||
const eventually = async (assert, poll, { retries = 10, delay = 1000, error = defaultError } = {}) => { | ||
for (let retry = 1; retry <= retries; retry++) { | ||
@@ -10,3 +11,3 @@ const before = Date.now(); | ||
if (retry === retries) { | ||
throw err; | ||
throw error(err, result); | ||
} | ||
@@ -13,0 +14,0 @@ } |
@@ -23,7 +23,7 @@ import and from './and.js'; | ||
import never_ from './never.js'; | ||
import nil from './nil.js'; | ||
import nilOr from './nil-or.js'; | ||
import nonBlankString from './non-blank-string.js'; | ||
import nonNullish from './non-nullish.js'; | ||
import null_ from './null.js'; | ||
import nullish from './nullish.js'; | ||
import nullishOr from './nullish-or.js'; | ||
import nullOr from './null-or.js'; | ||
@@ -52,2 +52,2 @@ import number from './number.js'; | ||
export * from './prelude.js'; | ||
export { and, array, boolean, dateString, defined, eq, errorOf, eventually, exact, false_ as false, finite, gt, gte, if_ as if, ignore, implies, in_ as in, instance, keyed, lt, lte, never_ as never, nil, nilOr, nonBlankString, nonNullish, null_ as null, nullOr, number, object, ok, oneOf, or, partial, positive, predicate, record, regexp, rethrow, safeInteger, sequence, strftime, string, true_ as true, tuple, undefined_ as undefined, undefinedOr, unique, unknown }; | ||
export { and, array, boolean, dateString, defined, eq, errorOf, eventually, exact, false_ as false, finite, gt, gte, if_ as if, ignore, implies, in_ as in, instance, keyed, lt, lte, never_ as never, nonBlankString, nonNullish, null_ as null, nullish, nullishOr, nullOr, number, object, ok, oneOf, or, partial, positive, predicate, record, regexp, rethrow, safeInteger, sequence, strftime, string, true_ as true, tuple, undefined_ as undefined, undefinedOr, unique, unknown }; |
@@ -23,7 +23,7 @@ import and from './and.js'; | ||
import never_ from './never.js'; | ||
import nil from './nil.js'; | ||
import nilOr from './nil-or.js'; | ||
import nonBlankString from './non-blank-string.js'; | ||
import nonNullish from './non-nullish.js'; | ||
import null_ from './null.js'; | ||
import nullish from './nullish.js'; | ||
import nullishOr from './nullish-or.js'; | ||
import nullOr from './null-or.js'; | ||
@@ -52,3 +52,3 @@ import number from './number.js'; | ||
export * from './prelude.js'; | ||
export { and, array, boolean, dateString, defined, eq, errorOf, eventually, exact, false_ as false, finite, gt, gte, if_ as if, ignore, implies, in_ as in, instance, keyed, lt, lte, never_ as never, nil, nilOr, nonBlankString, nonNullish, null_ as null, nullOr, number, object, ok, oneOf, or, partial, positive, predicate, record, regexp, rethrow, safeInteger, sequence, strftime, string, true_ as true, tuple, undefined_ as undefined, undefinedOr, unique, unknown }; | ||
export { and, array, boolean, dateString, defined, eq, errorOf, eventually, exact, false_ as false, finite, gt, gte, if_ as if, ignore, implies, in_ as in, instance, keyed, lt, lte, never_ as never, nonBlankString, nonNullish, null_ as null, nullish, nullishOr, nullOr, number, object, ok, oneOf, or, partial, positive, predicate, record, regexp, rethrow, safeInteger, sequence, strftime, string, true_ as true, tuple, undefined_ as undefined, undefinedOr, unique, unknown }; | ||
//# sourceMappingURL=index.js.map |
@@ -9,5 +9,5 @@ /** Helper no-op, parametric type to expand intellisense for alias types. */ | ||
export declare type Keyed<T = unknown> = Record<string, T | undefined>; | ||
export declare type NilOr<T> = undefined | null | T; | ||
export declare type Nullish<T> = undefined | null | T; | ||
export declare type UndefinedOr<T> = undefined | T; | ||
export declare type NullOr<T> = null | T; | ||
export declare type Nullable<T> = null | T; | ||
export declare type Defined<T> = Exclude<T, undefined>; | ||
@@ -17,1 +17,2 @@ export declare type NonNullish<T> = Exclude<T, undefined | null>; | ||
export declare type Primitive = undefined | null | boolean | number | string | symbol; | ||
export declare type Exact<T, I> = T extends I ? Exclude<keyof T, keyof I> extends never ? T : never : never; |
{ | ||
"name": "@appliedblockchain/assert-combinators", | ||
"version": "5.3.2", | ||
"version": "5.4.0", | ||
"description": "Assertion combinators.", | ||
@@ -31,14 +31,13 @@ "type": "module", | ||
"@appliedblockchain/changelog": "1.2.1", | ||
"@appliedblockchain/eslint-config": "3.0.0", | ||
"@tsconfig/node16": "1.0.2", | ||
"@types/jest": "27.4.1", | ||
"@typescript-eslint/eslint-plugin": "5.17.0", | ||
"@typescript-eslint/parser": "5.17.0", | ||
"eslint": "8.12.0", | ||
"eslint-plugin-jest": "26.1.3", | ||
"jest": "27.5.1", | ||
"npm-check": "5.9.2", | ||
"ts-jest": "27.1.4", | ||
"typescript": "4.6.3" | ||
"@appliedblockchain/eslint-config": "3.1.1", | ||
"@tsconfig/node16": "1.0.3", | ||
"@types/jest": "29.0.3", | ||
"@typescript-eslint/eslint-plugin": "5.38.0", | ||
"@typescript-eslint/parser": "5.38.0", | ||
"eslint": "8.23.1", | ||
"eslint-plugin-jest": "27.0.4", | ||
"jest": "29.0.3", | ||
"npm-check": "6.0.1", | ||
"typescript": "4.8.3" | ||
} | ||
} |
@@ -0,8 +1,16 @@ | ||
const defaultError = | ||
<T>(err: unknown, result: T) => | ||
new Error((err instanceof Error ? err.message : String(err)) + ' Last result was ' + JSON.stringify(result) + '.') | ||
const eventually = | ||
async <T, U>(assert: (result: T) => U, poll: () => Promise<T>, { | ||
retries = 10, | ||
delay = 1000 | ||
delay = 1000, | ||
error = defaultError | ||
}: { | ||
retries?: number, | ||
delay?: number | ||
delay?: number, | ||
/** Error constructor based on thrown assertion error and last polled result. */ | ||
error?: (err: unknown, result: T) => unknown | ||
} = {}): Promise<U> => { | ||
@@ -16,3 +24,3 @@ for (let retry = 1; retry <= retries; retry++) { | ||
if (retry === retries) { | ||
throw err | ||
throw error(err, result) | ||
} | ||
@@ -19,0 +27,0 @@ } |
@@ -23,7 +23,7 @@ import and from './and.js' | ||
import never_ from './never.js' | ||
import nil from './nil.js' | ||
import nilOr from './nil-or.js' | ||
import nonBlankString from './non-blank-string.js' | ||
import nonNullish from './non-nullish.js' | ||
import null_ from './null.js' | ||
import nullish from './nullish.js' | ||
import nullishOr from './nullish-or.js' | ||
import nullOr from './null-or.js' | ||
@@ -77,7 +77,7 @@ import number from './number.js' | ||
never_ as never, | ||
nil, | ||
nilOr, | ||
nonBlankString, | ||
nonNullish, | ||
null_ as null, | ||
nullish, | ||
nullishOr, | ||
nullOr, | ||
@@ -84,0 +84,0 @@ number, |
@@ -23,3 +23,3 @@ /** Helper no-op, parametric type to expand intellisense for alias types. */ | ||
export type NilOr<T> = | ||
export type Nullish<T> = | ||
| undefined | ||
@@ -33,3 +33,3 @@ | null | ||
export type NullOr<T> = | ||
export type Nullable<T> = | ||
| null | ||
@@ -54,1 +54,8 @@ | T | ||
| symbol | ||
export type Exact<T, I> = | ||
T extends I ? | ||
Exclude<keyof T, keyof I> extends never ? | ||
T : | ||
never : | ||
never |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181144
11
3027