@cedvict/http-guardian-plugin-timeout 0.0.1-next.10
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/index.cjs +31 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cedvict
|
|
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/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function timeoutPlugin(opts) {
|
|
5
|
+
const ms = opts.ms;
|
|
6
|
+
const maxMs = opts.maxMs;
|
|
7
|
+
const applyTo = opts.applyTo ?? (() => true);
|
|
8
|
+
const guard = async (ctx, next) => {
|
|
9
|
+
if (!applyTo(ctx)) return next(ctx);
|
|
10
|
+
const existing = ctx.timeoutMs;
|
|
11
|
+
if (typeof existing === "number") {
|
|
12
|
+
if (typeof maxMs === "number") {
|
|
13
|
+
return next(Object.assign({}, ctx, { timeoutMs: Math.min(existing, maxMs) }));
|
|
14
|
+
}
|
|
15
|
+
return next(ctx);
|
|
16
|
+
}
|
|
17
|
+
const applied = typeof maxMs === "number" ? Math.min(ms, maxMs) : ms;
|
|
18
|
+
return next(Object.assign({}, ctx, { timeoutMs: applied }));
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
name: "timeout",
|
|
22
|
+
apply: (draft) => {
|
|
23
|
+
draft.guards = [...draft.guards ?? [], guard];
|
|
24
|
+
draft.defaults = { ...draft.defaults ?? {}, timeoutMs: draft.defaults?.timeoutMs ?? ms };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.timeoutPlugin = timeoutPlugin;
|
|
30
|
+
//# sourceMappingURL=index.cjs.map
|
|
31
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AASO,SAAS,cAAc,IAAA,EAA+F;AAC3H,EAAA,MAAM,KAAK,IAAA,CAAK,EAAA;AAChB,EAAA,MAAM,QAAQ,IAAA,CAAK,KAAA;AACnB,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,OAAA,KAAY,MAAM,IAAA,CAAA;AAEvC,EAAA,MAAM,KAAA,GAAe,OAAO,GAAA,EAAK,IAAA,KAAS;AACxC,IAAA,IAAI,CAAC,OAAA,CAAQ,GAAG,CAAA,EAAG,OAAO,KAAK,GAAG,CAAA;AAElC,IAAA,MAAM,WAAW,GAAA,CAAI,SAAA;AACrB,IAAA,IAAI,OAAO,aAAa,QAAA,EAAU;AAChC,MAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,QAAA,OAAO,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,IAAI,GAAA,EAAK,EAAE,SAAA,EAAW,IAAA,CAAK,GAAA,CAAI,QAAA,EAAU,KAAK,CAAA,EAAG,CAAmB,CAAA;AAAA,MAChG;AACA,MAAA,OAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,MAAM,OAAA,GAAU,OAAO,KAAA,KAAU,QAAA,GAAW,KAAK,GAAA,CAAI,EAAA,EAAI,KAAK,CAAA,GAAI,EAAA;AAClE,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,EAAC,EAAG,KAAK,EAAE,SAAA,EAAW,OAAA,EAAS,CAAmB,CAAA;AAAA,EAC9E,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAA;AAAA,IACN,KAAA,EAAO,CAAC,KAAA,KAAU;AAChB,MAAA,KAAA,CAAM,SAAS,CAAC,GAAI,MAAM,MAAA,IAAU,IAAK,KAAK,CAAA;AAC9C,MAAA,KAAA,CAAM,QAAA,GAAW,EAAE,GAAI,KAAA,CAAM,QAAA,IAAY,EAAC,EAAI,SAAA,EAAW,KAAA,CAAM,QAAA,EAAU,SAAA,IAAa,EAAA,EAAG;AAAA,IAC3F;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { HttpPlugin } from \"@cedvict/http-guardian\";\nimport type { Guard } from \"@cedvict/http-guardian\";\nimport type { RequestContext } from \"@cedvict/http-guardian\";\n\n/**\n * Timeout plugin:\n * - sets a client default timeout (ctx.timeoutMs), while allowing per-request override\n * - does NOT replace user's AbortSignal; it only sets timeoutMs which core uses to abort safely.\n */\nexport function timeoutPlugin(opts: { ms: number; maxMs?: number; applyTo?: (ctx: RequestContext) => boolean } ): HttpPlugin {\n const ms = opts.ms;\n const maxMs = opts.maxMs;\n const applyTo = opts.applyTo ?? (() => true);\n\n const guard: Guard = async (ctx, next) => {\n if (!applyTo(ctx)) return next(ctx);\n\n const existing = ctx.timeoutMs;\n if (typeof existing === \"number\") {\n if (typeof maxMs === \"number\") {\n return next(Object.assign({}, ctx, { timeoutMs: Math.min(existing, maxMs) }) as RequestContext);\n }\n return next(ctx);\n }\n\n const applied = typeof maxMs === \"number\" ? Math.min(ms, maxMs) : ms;\n return next(Object.assign({}, ctx, { timeoutMs: applied }) as RequestContext);\n };\n\n return {\n name: \"timeout\",\n apply: (draft) => {\n draft.guards = [...(draft.guards ?? []), guard];\n draft.defaults = { ...(draft.defaults ?? {}), timeoutMs: draft.defaults?.timeoutMs ?? ms };\n },\n };\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestContext, HttpPlugin } from '@cedvict/http-guardian';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Timeout plugin:
|
|
5
|
+
* - sets a client default timeout (ctx.timeoutMs), while allowing per-request override
|
|
6
|
+
* - does NOT replace user's AbortSignal; it only sets timeoutMs which core uses to abort safely.
|
|
7
|
+
*/
|
|
8
|
+
declare function timeoutPlugin(opts: {
|
|
9
|
+
ms: number;
|
|
10
|
+
maxMs?: number;
|
|
11
|
+
applyTo?: (ctx: RequestContext) => boolean;
|
|
12
|
+
}): HttpPlugin;
|
|
13
|
+
|
|
14
|
+
export { timeoutPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestContext, HttpPlugin } from '@cedvict/http-guardian';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Timeout plugin:
|
|
5
|
+
* - sets a client default timeout (ctx.timeoutMs), while allowing per-request override
|
|
6
|
+
* - does NOT replace user's AbortSignal; it only sets timeoutMs which core uses to abort safely.
|
|
7
|
+
*/
|
|
8
|
+
declare function timeoutPlugin(opts: {
|
|
9
|
+
ms: number;
|
|
10
|
+
maxMs?: number;
|
|
11
|
+
applyTo?: (ctx: RequestContext) => boolean;
|
|
12
|
+
}): HttpPlugin;
|
|
13
|
+
|
|
14
|
+
export { timeoutPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function timeoutPlugin(opts) {
|
|
3
|
+
const ms = opts.ms;
|
|
4
|
+
const maxMs = opts.maxMs;
|
|
5
|
+
const applyTo = opts.applyTo ?? (() => true);
|
|
6
|
+
const guard = async (ctx, next) => {
|
|
7
|
+
if (!applyTo(ctx)) return next(ctx);
|
|
8
|
+
const existing = ctx.timeoutMs;
|
|
9
|
+
if (typeof existing === "number") {
|
|
10
|
+
if (typeof maxMs === "number") {
|
|
11
|
+
return next(Object.assign({}, ctx, { timeoutMs: Math.min(existing, maxMs) }));
|
|
12
|
+
}
|
|
13
|
+
return next(ctx);
|
|
14
|
+
}
|
|
15
|
+
const applied = typeof maxMs === "number" ? Math.min(ms, maxMs) : ms;
|
|
16
|
+
return next(Object.assign({}, ctx, { timeoutMs: applied }));
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
name: "timeout",
|
|
20
|
+
apply: (draft) => {
|
|
21
|
+
draft.guards = [...draft.guards ?? [], guard];
|
|
22
|
+
draft.defaults = { ...draft.defaults ?? {}, timeoutMs: draft.defaults?.timeoutMs ?? ms };
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { timeoutPlugin };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.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,IAAa,EAAA,EAAG;AAAA,IAC3F;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { HttpPlugin } from \"@cedvict/http-guardian\";\nimport type { Guard } from \"@cedvict/http-guardian\";\nimport type { RequestContext } from \"@cedvict/http-guardian\";\n\n/**\n * Timeout plugin:\n * - sets a client default timeout (ctx.timeoutMs), while allowing per-request override\n * - does NOT replace user's AbortSignal; it only sets timeoutMs which core uses to abort safely.\n */\nexport function timeoutPlugin(opts: { ms: number; maxMs?: number; applyTo?: (ctx: RequestContext) => boolean } ): HttpPlugin {\n const ms = opts.ms;\n const maxMs = opts.maxMs;\n const applyTo = opts.applyTo ?? (() => true);\n\n const guard: Guard = async (ctx, next) => {\n if (!applyTo(ctx)) return next(ctx);\n\n const existing = ctx.timeoutMs;\n if (typeof existing === \"number\") {\n if (typeof maxMs === \"number\") {\n return next(Object.assign({}, ctx, { timeoutMs: Math.min(existing, maxMs) }) as RequestContext);\n }\n return next(ctx);\n }\n\n const applied = typeof maxMs === \"number\" ? Math.min(ms, maxMs) : ms;\n return next(Object.assign({}, ctx, { timeoutMs: applied }) as RequestContext);\n };\n\n return {\n name: \"timeout\",\n apply: (draft) => {\n draft.guards = [...(draft.guards ?? []), guard];\n draft.defaults = { ...(draft.defaults ?? {}), timeoutMs: draft.defaults?.timeoutMs ?? ms };\n },\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cedvict/http-guardian-plugin-timeout",
|
|
3
|
+
"version": "0.0.1-next.10",
|
|
4
|
+
"description": "Request timeout plugin for http-guardian.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"browser": "./dist/index.js",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"CHANGELOG.md"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/cedvict/http-guardian.git"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@cedvict/http-guardian": "^0.0.1-next.6"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"dev": "tsup --watch",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"lint": "eslint . --max-warnings=0",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
|
|
42
|
+
"prepublishOnly": "npm -w @cedvict/http-guardian run build && npm run test && npm run lint && npm run typecheck && npm run build",
|
|
43
|
+
"prebuild": "npm -w @cedvict/http-guardian run build",
|
|
44
|
+
"pretypecheck": "npm -w @cedvict/http-guardian run build"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^20.0.0",
|
|
48
|
+
"eslint": "^9.0.0",
|
|
49
|
+
"typescript": "^5.4.0",
|
|
50
|
+
"tsup": "^8.0.0",
|
|
51
|
+
"vitest": "^1.5.0",
|
|
52
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@cedvict/http-guardian": "^0.0.1-next.10"
|
|
57
|
+
}
|
|
58
|
+
}
|