@shiengng123/request-context 1.0.0

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.
@@ -0,0 +1,17 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+
3
+ declare const requestContext: AsyncLocalStorage<Map<string, any>>;
4
+ declare const getRequestByContext: (context: string) => any;
5
+ declare const setRequestByContext: (context: string, value: any) => Map<string, any> | undefined;
6
+ declare const deleteRequestByContext: (context: string) => boolean | undefined;
7
+ declare const clearRequestByContext: () => void | undefined;
8
+ declare const hasRequestByContext: (context: string) => boolean | undefined;
9
+ declare const requestContextUtil: {
10
+ get: (context: string) => any;
11
+ set: (context: string, value: any) => Map<string, any> | undefined;
12
+ delete: (context: string) => boolean | undefined;
13
+ clear: () => void | undefined;
14
+ has: (context: string) => boolean | undefined;
15
+ };
16
+
17
+ export { clearRequestByContext, deleteRequestByContext, getRequestByContext, hasRequestByContext, requestContext, requestContextUtil, setRequestByContext };
@@ -0,0 +1,17 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+
3
+ declare const requestContext: AsyncLocalStorage<Map<string, any>>;
4
+ declare const getRequestByContext: (context: string) => any;
5
+ declare const setRequestByContext: (context: string, value: any) => Map<string, any> | undefined;
6
+ declare const deleteRequestByContext: (context: string) => boolean | undefined;
7
+ declare const clearRequestByContext: () => void | undefined;
8
+ declare const hasRequestByContext: (context: string) => boolean | undefined;
9
+ declare const requestContextUtil: {
10
+ get: (context: string) => any;
11
+ set: (context: string, value: any) => Map<string, any> | undefined;
12
+ delete: (context: string) => boolean | undefined;
13
+ clear: () => void | undefined;
14
+ has: (context: string) => boolean | undefined;
15
+ };
16
+
17
+ export { clearRequestByContext, deleteRequestByContext, getRequestByContext, hasRequestByContext, requestContext, requestContextUtil, setRequestByContext };
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ clearRequestByContext: () => clearRequestByContext,
24
+ deleteRequestByContext: () => deleteRequestByContext,
25
+ getRequestByContext: () => getRequestByContext,
26
+ hasRequestByContext: () => hasRequestByContext,
27
+ requestContext: () => requestContext,
28
+ requestContextUtil: () => requestContextUtil,
29
+ setRequestByContext: () => setRequestByContext
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var import_node_async_hooks = require("async_hooks");
33
+ var requestContext = new import_node_async_hooks.AsyncLocalStorage();
34
+ var getRequestByContext = (context) => requestContext.getStore()?.get(context);
35
+ var setRequestByContext = (context, value) => requestContext.getStore()?.set(context, value);
36
+ var deleteRequestByContext = (context) => requestContext.getStore()?.delete(context);
37
+ var clearRequestByContext = () => requestContext.getStore()?.clear();
38
+ var hasRequestByContext = (context) => requestContext.getStore()?.has(context);
39
+ var requestContextUtil = {
40
+ get: getRequestByContext,
41
+ set: setRequestByContext,
42
+ delete: deleteRequestByContext,
43
+ clear: clearRequestByContext,
44
+ has: hasRequestByContext
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ clearRequestByContext,
49
+ deleteRequestByContext,
50
+ getRequestByContext,
51
+ hasRequestByContext,
52
+ requestContext,
53
+ requestContextUtil,
54
+ setRequestByContext
55
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,24 @@
1
+ // src/index.ts
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+ var requestContext = new AsyncLocalStorage();
4
+ var getRequestByContext = (context) => requestContext.getStore()?.get(context);
5
+ var setRequestByContext = (context, value) => requestContext.getStore()?.set(context, value);
6
+ var deleteRequestByContext = (context) => requestContext.getStore()?.delete(context);
7
+ var clearRequestByContext = () => requestContext.getStore()?.clear();
8
+ var hasRequestByContext = (context) => requestContext.getStore()?.has(context);
9
+ var requestContextUtil = {
10
+ get: getRequestByContext,
11
+ set: setRequestByContext,
12
+ delete: deleteRequestByContext,
13
+ clear: clearRequestByContext,
14
+ has: hasRequestByContext
15
+ };
16
+ export {
17
+ clearRequestByContext,
18
+ deleteRequestByContext,
19
+ getRequestByContext,
20
+ hasRequestByContext,
21
+ requestContext,
22
+ requestContextUtil,
23
+ setRequestByContext
24
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@shiengng123/request-context",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight AsyncLocalStorage request context utility",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup"
20
+ },
21
+ "keywords": [
22
+ "async-local-storage",
23
+ "request-context",
24
+ "nestjs",
25
+ "nodejs"
26
+ ],
27
+ "author": "Shi Eng",
28
+ "license": "MIT",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "packageManager": "pnpm@10.11.0",
33
+ "devDependencies": {
34
+ "@types/node": "^25.3.0",
35
+ "tsup": "^8.5.1",
36
+ "typescript": "^5.9.3"
37
+ }
38
+ }