wrapper-fns 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contract/index.d.ts +5 -3
- package/dist/contract/index.js +19 -3
- package/dist/contract/index.js.map +1 -1
- package/dist/domain.objects/Wrapper.d.ts +6 -0
- package/dist/domain.objects/Wrapper.js +3 -0
- package/dist/domain.objects/Wrapper.js.map +1 -0
- package/dist/domain.operations/withBottleneck.js.map +1 -0
- package/dist/domain.operations/withRetry.d.ts +5 -0
- package/dist/domain.operations/withRetry.js +33 -0
- package/dist/domain.operations/withRetry.js.map +1 -0
- package/dist/{logic → domain.operations}/withTimeout.d.ts +2 -2
- package/dist/domain.operations/withTimeout.js.map +1 -0
- package/dist/domain.operations/withWrappers.d.ts +16 -0
- package/dist/domain.operations/withWrappers.js +20 -0
- package/dist/domain.operations/withWrappers.js.map +1 -0
- package/license.md +21 -0
- package/package.json +53 -41
- package/readme.md +20 -0
- package/dist/logic/withBottleneck.js.map +0 -1
- package/dist/logic/withRetry.d.ts +0 -4
- package/dist/logic/withRetry.js +0 -26
- package/dist/logic/withRetry.js.map +0 -1
- package/dist/logic/withTimeout.js.map +0 -1
- /package/dist/{logic → domain.operations}/withBottleneck.d.ts +0 -0
- /package/dist/{logic → domain.operations}/withBottleneck.js +0 -0
- /package/dist/{logic → domain.operations}/withTimeout.js +0 -0
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export * from '../domain.objects/Wrapper';
|
|
2
|
+
export { withBottleneck } from '../domain.operations/withBottleneck';
|
|
3
|
+
export { withRetry } from '../domain.operations/withRetry';
|
|
4
|
+
export { withTimeout } from '../domain.operations/withTimeout';
|
|
5
|
+
export * from '../domain.operations/withWrappers';
|
package/dist/contract/index.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.withTimeout = exports.withRetry = exports.withBottleneck = void 0;
|
|
4
|
-
|
|
18
|
+
__exportStar(require("../domain.objects/Wrapper"), exports);
|
|
19
|
+
var withBottleneck_1 = require("../domain.operations/withBottleneck");
|
|
5
20
|
Object.defineProperty(exports, "withBottleneck", { enumerable: true, get: function () { return withBottleneck_1.withBottleneck; } });
|
|
6
|
-
var withRetry_1 = require("../
|
|
21
|
+
var withRetry_1 = require("../domain.operations/withRetry");
|
|
7
22
|
Object.defineProperty(exports, "withRetry", { enumerable: true, get: function () { return withRetry_1.withRetry; } });
|
|
8
|
-
var withTimeout_1 = require("../
|
|
23
|
+
var withTimeout_1 = require("../domain.operations/withTimeout");
|
|
9
24
|
Object.defineProperty(exports, "withTimeout", { enumerable: true, get: function () { return withTimeout_1.withTimeout; } });
|
|
25
|
+
__exportStar(require("../domain.operations/withWrappers"), exports);
|
|
10
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,wEAAuE;AAA9D,gHAAA,cAAc,OAAA;AACvB,8DAA6D;AAApD,sGAAA,SAAS,OAAA;AAClB,kEAAiE;AAAxD,0GAAA,WAAW,OAAA;AACpB,sEAAoD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Procedure } from 'domain-glossary-procedure';
|
|
2
|
+
export type Wrapper<TProcedure extends Procedure, TOptions> = (logic: TProcedure, options: TOptions) => TProcedure;
|
|
3
|
+
export type WrapperChoice<TProcedure extends Procedure, TOptions> = {
|
|
4
|
+
wrapper: Wrapper<TProcedure, TOptions>;
|
|
5
|
+
options: TOptions;
|
|
6
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../src/domain.objects/Wrapper.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withBottleneck.js","sourceRoot":"","sources":["../../src/domain.operations/withBottleneck.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAEpC,MAAM,4BAA4B,GAAG,IAAI,oBAAU,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;AAEnE,MAAM,cAAc,GAAG,CAK5B,KAAQ,EACR,UAEI,EAAE,UAAU,EAAE,4BAA4B,EAAE,EAC7C,EAAE;IACL,MAAM,OAAO,GAAG,CAAC,GAAG,IAAO,EAAE,EAAE,CAC7B,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACvD,OAAO,OAAY,CAAC;AACtB,CAAC,CAAC;AAbW,QAAA,cAAc,kBAazB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Procedure } from 'as-procedure';
|
|
2
|
+
import type { ContextLogTrail } from 'simple-log-methods';
|
|
3
|
+
export declare function withRetry<TOutput>(logic: () => TOutput): typeof logic;
|
|
4
|
+
export declare function withRetry<TInput, TOutput>(logic: (input: TInput) => TOutput): typeof logic;
|
|
5
|
+
export declare function withRetry<TInput, TContext extends ContextLogTrail, TOutput>(logic: Procedure<TInput, TContext, TOutput>): typeof logic;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withRetry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = wraps a procedure to retry once on error
|
|
6
|
+
* .why = provides resilience against transient failures
|
|
7
|
+
* .note = logs retry attempts if context.log is available, otherwise retries silently
|
|
8
|
+
*/
|
|
9
|
+
function withRetry(logic) {
|
|
10
|
+
return (async (input, context) => {
|
|
11
|
+
try {
|
|
12
|
+
return await logic(input, context);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (!(error instanceof Error))
|
|
16
|
+
throw error;
|
|
17
|
+
// log retry attempt if context.log is available
|
|
18
|
+
const log = context
|
|
19
|
+
?.log;
|
|
20
|
+
if (log?.warn) {
|
|
21
|
+
log.warn('withRetry.progress: caught an error, will retry', {
|
|
22
|
+
error: {
|
|
23
|
+
message: error.message,
|
|
24
|
+
stack: error.stack,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return await logic(input, context);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.withRetry = withRetry;
|
|
33
|
+
//# sourceMappingURL=withRetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withRetry.js","sourceRoot":"","sources":["../../src/domain.operations/withRetry.ts"],"names":[],"mappings":";;;AAgBA;;;;GAIG;AACH,SAAgB,SAAS,CACvB,KAA2C;IAE3C,OAAO,CAAC,KAAK,EACX,KAAmC,EACnC,OAAuC,EACC,EAAE;QAC1C,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;gBAAE,MAAM,KAAK,CAAC;YAE3C,gDAAgD;YAChD,MAAM,GAAG,GAAI,OAA6D;gBACxE,EAAE,GAAG,CAAC;YACR,IAAI,GAAG,EAAE,IAAI,EAAE,CAAC;gBACd,GAAG,CAAC,IAAI,CAAC,iDAAiD,EAAE;oBAC1D,KAAK,EAAE;wBACL,OAAO,EAAE,KAAK,CAAC,OAAO;wBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;qBACnB;iBACF,CAAC,CAAC;YACL,CAAC;YAED,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAiB,CAAC;AACrB,CAAC;AA3BD,8BA2BC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UniDuration } from '@ehmpathy/uni-time';
|
|
2
|
-
import { Procedure } from '
|
|
1
|
+
import { type UniDuration } from '@ehmpathy/uni-time';
|
|
2
|
+
import type { Procedure } from 'as-procedure';
|
|
3
3
|
export declare function withTimeout<TInput, TContext, TOutput>(logic: () => TOutput, // empty inputs override
|
|
4
4
|
options: {
|
|
5
5
|
threshold: UniDuration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withTimeout.js","sourceRoot":"","sources":["../../src/domain.operations/withTimeout.ts"],"names":[],"mappings":";;;AAAA,iDAAsE;AAiBtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,WAAW,CACzB,KAA2C,EAC3C,OAAmC;IAEnC,MAAM,WAAW,GAAG,IAAA,yBAAc,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,CACL,KAAmC,EACnC,OAAuC,EACR,EAAE;QACjC,6HAA6H;QAC7H,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9C,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzB,YAAY,CAAC,EAAE,CAAC,CAAC;gBACjB,MAAM,CACJ,IAAI,KAAK,CACP,4BAA4B,WAAW,qBAAqB,CAC7D,CACF,CAAC;YACJ,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,4BAA4B;QAC/C,CAAC,CAAC,CAAC;QAEH,uFAAuF;QACvF,OAAO,OAAO,CAAC,IAAI,CAAC;YAClB,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,+CAA+C;YACtE,OAAO,EAAE,cAAc;SACxB,CAAkC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC;AA3BD,kCA2BC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Procedure } from 'as-procedure';
|
|
2
|
+
import type { WrapperChoice } from '../domain.objects/Wrapper';
|
|
3
|
+
/**
|
|
4
|
+
* .what = a helper procedure to ensure that the choice.options matches the wrapper.options
|
|
5
|
+
*/
|
|
6
|
+
export declare const setWrapper: <TProc extends Procedure, TOptions>(input: WrapperChoice<TProc, TOptions>) => WrapperChoice<TProc, TOptions> & {
|
|
7
|
+
_safe: true;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* .what = a wrapper of wrappers
|
|
11
|
+
* .why =
|
|
12
|
+
* - eliminates nested indentation when multiple wrappers are used
|
|
13
|
+
*/
|
|
14
|
+
export declare function withWrappers<TProcedure extends Procedure, TChoices extends ReadonlyArray<WrapperChoice<TProcedure, any> & {
|
|
15
|
+
_safe: true;
|
|
16
|
+
}>>(logic: TProcedure, wrappers: TChoices): TProcedure;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withWrappers = exports.setWrapper = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = a helper procedure to ensure that the choice.options matches the wrapper.options
|
|
6
|
+
*/
|
|
7
|
+
const setWrapper = (input) => {
|
|
8
|
+
return Object.assign(input, { _safe: true }); // add the safe flag to compile-time warn if setter was not used; // todo: use a symbol instead
|
|
9
|
+
};
|
|
10
|
+
exports.setWrapper = setWrapper;
|
|
11
|
+
/**
|
|
12
|
+
* .what = a wrapper of wrappers
|
|
13
|
+
* .why =
|
|
14
|
+
* - eliminates nested indentation when multiple wrappers are used
|
|
15
|
+
*/
|
|
16
|
+
function withWrappers(logic, wrappers) {
|
|
17
|
+
return wrappers.reduce((wrapped, { wrapper, options }) => wrapper(wrapped, options), logic);
|
|
18
|
+
}
|
|
19
|
+
exports.withWrappers = withWrappers;
|
|
20
|
+
//# sourceMappingURL=withWrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withWrappers.js","sourceRoot":"","sources":["../../src/domain.operations/withWrappers.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACI,MAAM,UAAU,GAAG,CACxB,KAAqC,EACa,EAAE;IACpD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAa,EAAE,CAAC,CAAC,CAAC,+FAA+F;AACxJ,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB;AAEF;;;;GAIG;AACH,SAAgB,YAAY,CAK1B,KAAiB,EAAE,QAAkB;IACrC,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAC5D,KAAK,CACN,CAAC;AACJ,CAAC;AAVD,oCAUC"}
|
package/license.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 ehmpathy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "wrapper-fns",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "Use wrappers for simpler, safer, and more readable code",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.1.1",
|
|
6
6
|
"repository": "ehmpathy/wrapper-fns",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/wrapper-fns",
|
|
8
8
|
"keywords": [
|
|
@@ -23,64 +23,76 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build:ts": "tsc -p ./tsconfig.build.json",
|
|
25
25
|
"commit:with-cli": "npx cz",
|
|
26
|
-
"fix:format:
|
|
27
|
-
"fix:format": "npm run fix:format:
|
|
28
|
-
"fix:lint": "
|
|
29
|
-
"
|
|
30
|
-
"build:
|
|
31
|
-
"build": "
|
|
26
|
+
"fix:format:biome": "biome check --write",
|
|
27
|
+
"fix:format": "npm run fix:format:biome",
|
|
28
|
+
"fix:lint": "biome check --write",
|
|
29
|
+
"fix": "npm run fix:format && npm run fix:lint",
|
|
30
|
+
"build:clean": "chmod -R u+w dist 2>/dev/null; rm -rf dist/",
|
|
31
|
+
"build:compile": "tsc -p ./tsconfig.build.json && tsc-alias -p ./tsconfig.build.json",
|
|
32
|
+
"build": "npm run build:clean && npm run build:compile && npm run build:complete --if-present",
|
|
32
33
|
"test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
|
|
33
|
-
"test:types": "tsc -p ./tsconfig.
|
|
34
|
-
"test:format:
|
|
35
|
-
"test:format": "npm run test:format:
|
|
36
|
-
"test:lint:deps": "npx depcheck -c
|
|
37
|
-
"test:lint:
|
|
38
|
-
"test:lint": "
|
|
39
|
-
"test:
|
|
40
|
-
"test:
|
|
41
|
-
"test:
|
|
34
|
+
"test:types": "tsc -p ./tsconfig.json --noEmit",
|
|
35
|
+
"test:format:biome": "biome format",
|
|
36
|
+
"test:format": "npm run test:format:biome",
|
|
37
|
+
"test:lint:deps": "npx depcheck -c ./.depcheckrc.yml",
|
|
38
|
+
"test:lint:biome": "biome check --diagnostic-level=error",
|
|
39
|
+
"test:lint:biome:all": "biome check",
|
|
40
|
+
"test:lint": "npm run test:lint:biome && npm run test:lint:deps",
|
|
41
|
+
"test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
42
|
+
"test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
43
|
+
"test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
42
44
|
"test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
|
|
43
|
-
"test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
|
|
45
|
+
"test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
44
46
|
"prepush": "npm run test && npm run build",
|
|
45
47
|
"prepublish": "npm run build",
|
|
46
48
|
"preversion": "npm run prepush",
|
|
47
49
|
"postversion": "git push origin HEAD --tags --no-verify",
|
|
48
|
-
"
|
|
49
|
-
"prepare:
|
|
50
|
+
"prepare:husky": "husky install && chmod ug+x .husky/*",
|
|
51
|
+
"prepare:rhachet": "rhachet init && rhachet roles link --repo ehmpathy --role mechanic && rhachet roles link --repo bhuild --role behaver && rhachet roles link --repo bhrain --role reviewer && rhachet roles init --role mechanic && rhachet roles init --role behaver",
|
|
52
|
+
"prepare": "if [ -e .git ] && [ -z $CI ]; then npm run prepare:husky && npm run prepare:rhachet; fi"
|
|
50
53
|
},
|
|
51
54
|
"dependencies": {
|
|
52
55
|
"@ehmpathy/uni-time": "1.7.4",
|
|
56
|
+
"as-procedure": "1.1.10",
|
|
53
57
|
"bottleneck": "2.19.5",
|
|
54
|
-
"
|
|
58
|
+
"domain-glossary-procedure": "1.0.0",
|
|
59
|
+
"domain-objects": "0.31.7",
|
|
60
|
+
"helpful-errors": "1.5.3",
|
|
61
|
+
"simple-log-methods": "0.6.5"
|
|
55
62
|
},
|
|
56
63
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@commitlint/
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"
|
|
64
|
+
"@biomejs/biome": "2.3.8",
|
|
65
|
+
"@commitlint/cli": "19.5.0",
|
|
66
|
+
"@commitlint/config-conventional": "19.5.0",
|
|
67
|
+
"@swc/core": "1.15.3",
|
|
68
|
+
"@swc/jest": "0.2.39",
|
|
69
|
+
"@tsconfig/node20": "20.1.5",
|
|
70
|
+
"@tsconfig/strictest": "2.0.5",
|
|
71
|
+
"@types/jest": "30.0.0",
|
|
72
|
+
"@types/node": "22.15.21",
|
|
65
73
|
"cz-conventional-changelog": "3.3.0",
|
|
66
|
-
"declapract": "0.
|
|
67
|
-
"declapract-typescript-ehmpathy": "0.
|
|
74
|
+
"declapract": "0.13.11",
|
|
75
|
+
"declapract-typescript-ehmpathy": "0.47.8",
|
|
76
|
+
"declastruct": "1.7.3",
|
|
77
|
+
"declastruct-github": "1.3.0",
|
|
68
78
|
"depcheck": "1.4.3",
|
|
69
|
-
"
|
|
70
|
-
"eslint-config-airbnb-typescript": "18.0.0",
|
|
71
|
-
"eslint-config-prettier": "8.5.0",
|
|
72
|
-
"eslint-plugin-import": "2.26.0",
|
|
73
|
-
"eslint-plugin-prettier": "4.2.1",
|
|
79
|
+
"esbuild-register": "3.6.0",
|
|
74
80
|
"husky": "8.0.3",
|
|
75
|
-
"jest": "
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
81
|
+
"jest": "30.2.0",
|
|
82
|
+
"rhachet": "1.19.1",
|
|
83
|
+
"rhachet-roles-bhrain": "0.5.7",
|
|
84
|
+
"rhachet-roles-bhuild": "0.5.0",
|
|
85
|
+
"rhachet-roles-ehmpathy": "1.15.25",
|
|
86
|
+
"test-fns": "1.5.0",
|
|
87
|
+
"tsc-alias": "1.8.10",
|
|
88
|
+
"tsx": "4.20.6",
|
|
89
|
+
"typescript": "5.4.5",
|
|
90
|
+
"yalc": "1.0.0-pre.53"
|
|
80
91
|
},
|
|
81
92
|
"config": {
|
|
82
93
|
"commitizen": {
|
|
83
94
|
"path": "./node_modules/cz-conventional-changelog"
|
|
84
95
|
}
|
|
85
|
-
}
|
|
96
|
+
},
|
|
97
|
+
"packageManager": "pnpm@10.24.0"
|
|
86
98
|
}
|
package/readme.md
CHANGED
|
@@ -16,6 +16,26 @@ npm install wrapper-fns
|
|
|
16
16
|
|
|
17
17
|
# use
|
|
18
18
|
|
|
19
|
+
### `withWrappers`
|
|
20
|
+
|
|
21
|
+
applies wrappers chosen in a list, to avoid nested indentations
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const wrapped = withWrappers(doGreatThing, [
|
|
25
|
+
setWrapper({
|
|
26
|
+
wrapper: withLogTrail,
|
|
27
|
+
options: { name: 'doGreatThing' },
|
|
28
|
+
}),
|
|
29
|
+
setWrapper({
|
|
30
|
+
wrapper: withTimeout,
|
|
31
|
+
options: { threshold: 100 },
|
|
32
|
+
}),
|
|
33
|
+
]);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
*note, we use `setWrapper` to allow typescript to enforce the relationship between `options` and the `wrapper`*
|
|
37
|
+
|
|
38
|
+
|
|
19
39
|
### `withRetry`
|
|
20
40
|
|
|
21
41
|
retries the wrapped logic execution in case of failure
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withBottleneck.js","sourceRoot":"","sources":["../../src/logic/withBottleneck.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAEpC,MAAM,4BAA4B,GAAG,IAAI,oBAAU,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;AAEnE,MAAM,cAAc,GAAG,CAK5B,KAAQ,EACR,UAEI,EAAE,UAAU,EAAE,4BAA4B,EAAE,EAC7C,EAAE;IACL,MAAM,OAAO,GAAG,CAAC,GAAG,IAAO,EAAE,EAAE,CAC7B,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACvD,OAAO,OAAY,CAAC;AACtB,CAAC,CAAC;AAbW,QAAA,cAAc,kBAazB"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Procedure, VisualogicContext } from 'visualogic';
|
|
2
|
-
export declare function withRetry<TInput, TContext extends VisualogicContext, TOutput>(logic: () => TOutput): typeof logic;
|
|
3
|
-
export declare function withRetry<TInput, TContext extends VisualogicContext, TOutput>(logic: (input: TInput) => TOutput): typeof logic;
|
|
4
|
-
export declare function withRetry<TInput, TContext extends VisualogicContext, TOutput>(logic: Procedure<TInput, TContext, TOutput>): typeof logic;
|
package/dist/logic/withRetry.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withRetry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* function which calls the wrapped function and runs it again one time if an error is caught
|
|
6
|
-
*/
|
|
7
|
-
function withRetry(logic) {
|
|
8
|
-
return (async (input, context) => {
|
|
9
|
-
try {
|
|
10
|
-
return await logic(input, context);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
if (!(error instanceof Error))
|
|
14
|
-
throw error;
|
|
15
|
-
context.log.warn('withRetry.progress: caught an error, will retry', {
|
|
16
|
-
error: {
|
|
17
|
-
message: error.message,
|
|
18
|
-
stack: error.stack,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
return await logic(input, context);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
exports.withRetry = withRetry;
|
|
26
|
-
//# sourceMappingURL=withRetry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withRetry.js","sourceRoot":"","sources":["../../src/logic/withRetry.ts"],"names":[],"mappings":";;;AAkBA;;GAEG;AACH,SAAgB,SAAS,CACvB,KAA2C;IAE3C,OAAO,CAAC,KAAK,EACX,KAAmC,EACnC,OAAuC,EACC,EAAE;QAC1C,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;gBAAE,MAAM,KAAK,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,iDAAiD,EAAE;gBAClE,KAAK,EAAE;oBACL,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;aACF,CAAC,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAiB,CAAC;AACrB,CAAC;AApBD,8BAoBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withTimeout.js","sourceRoot":"","sources":["../../src/logic/withTimeout.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;AAiBjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,WAAW,CACzB,KAA2C,EAC3C,OAAmC;IAEnC,MAAM,WAAW,GAAG,IAAA,yBAAc,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,CACL,KAAmC,EACnC,OAAuC,EACR,EAAE;QACjC,6HAA6H;QAC7H,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9C,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzB,YAAY,CAAC,EAAE,CAAC,CAAC;gBACjB,MAAM,CACJ,IAAI,KAAK,CACP,4BAA4B,WAAW,qBAAqB,CAC7D,CACF,CAAC;YACJ,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,4BAA4B;QAC/C,CAAC,CAAC,CAAC;QAEH,uFAAuF;QACvF,OAAO,OAAO,CAAC,IAAI,CAAC;YAClB,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,+CAA+C;YACtE,OAAO,EAAE,cAAc;SACxB,CAAkC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC;AA3BD,kCA2BC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|