{"id":23752761,"url":"https://github.com/ziv/async-hooks-state","last_synced_at":"2025-06-11T20:35:00.059Z","repository":{"id":57185594,"uuid":"361195557","full_name":"ziv/async-hooks-state","owner":"ziv","description":"A (very) simple AsyncLocalStorage wrapper \u0026 expressjs middleware.","archived":false,"fork":false,"pushed_at":"2021-05-09T09:34:24.000Z","size":1212,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-25T00:22:59.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ziv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-24T15:19:12.000Z","updated_at":"2021-05-09T09:35:23.000Z","dependencies_parsed_at":"2022-09-06T04:11:18.647Z","dependency_job_id":null,"html_url":"https://github.com/ziv/async-hooks-state","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ziv/async-hooks-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Fasync-hooks-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Fasync-hooks-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Fasync-hooks-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Fasync-hooks-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziv","download_url":"https://codeload.github.com/ziv/async-hooks-state/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Fasync-hooks-state/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259335044,"owners_count":22842481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-31T17:55:39.093Z","updated_at":"2025-06-11T20:35:00.021Z","avatar_url":"https://github.com/ziv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-hooks-state\nA (very) simple AsyncLocalStorage wrapper \u0026 `expressjs` middleware.\n\n### Install\n```shell\nnpm i async-hooks-state\n```\n\n\n### Usage\n`expressjs` example:\n```typescript\nimport {hooked, getStorage, getRequest} from 'async-hooks-state';\nimport {NextFunction, Request, Response} from 'express';\n\nconst app = express();\n\nconst optionalContext = { foo: 'bar' };\napp.use(hooked(optionalContext));\n\n// later, in any async context\nconst route = (req: Request, res: Response, next: NextFunction) =\u003e {\n    const r = getRequest();\n    assert(r === req);\n    assert(getStorage().getStore().get('foo') === 'bar');\n}\n```\n\n\n\n\n### Type aliases\n\n- [Context](#context)\n- [ContextKey](#contextkey)\n\n### Variables\n\n- [RequestSymbol](#requestsymbol)\n- [ResponseSymbol](#responsesymbol)\n\n### Functions\n\n- [getRequest](#getrequest)\n- [getResponse](#getresponse)\n- [getStorage](#getstorage)\n- [getStore](#getstore)\n- [hooked](#hooked)\n\n## Type aliases\n\n### Context\n\nƬ **Context**: *Map*\u003c[*ContextKey*](#contextkey), any\\\u003e\n\nDefined in: [lib/async-hooks-state.ts:5](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L5)\n\n___\n\n### ContextKey\n\nƬ **ContextKey**: *number* \\| *string* \\| *symbol*\n\nDefined in: [lib/async-hooks-state.ts:4](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L4)\n\n## Variables\n\n### RequestSymbol\n\n• `Const` **RequestSymbol**: *typeof* [*RequestSymbol*](#requestsymbol)\n\nDefined in: [lib/async-hooks-state.ts:9](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L9)\n\n___\n\n### ResponseSymbol\n\n• `Const` **ResponseSymbol**: *typeof* [*ResponseSymbol*](#responsesymbol)\n\nDefined in: [lib/async-hooks-state.ts:10](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L10)\n\n## Functions\n\n### getRequest\n\n▸ `Const` **getRequest**(): *Request*\u003cParamsDictionary, any, any, ParsedQs, Record\u003cstring, any\\\u003e\\\u003e\n\n**Returns:** *Request*\u003cParamsDictionary, any, any, ParsedQs, Record\u003cstring, any\\\u003e\\\u003e\n\nDefined in: [lib/async-hooks-state.ts:23](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L23)\n\n___\n\n### getResponse\n\n▸ `Const` **getResponse**(): *Response*\u003cany, Record\u003cstring, any\\\u003e\\\u003e\n\n**Returns:** *Response*\u003cany, Record\u003cstring, any\\\u003e\\\u003e\n\nDefined in: [lib/async-hooks-state.ts:25](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L25)\n\n___\n\n### getStorage\n\n▸ `Const` **getStorage**(): *AsyncLocalStorage*\u003c[*Context*](#context)\\\u003e\n\n**Returns:** *AsyncLocalStorage*\u003c[*Context*](#context)\\\u003e\n\nDefined in: [lib/async-hooks-state.ts:13](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L13)\n\n___\n\n### getStore\n\n▸ `Const` **getStore**(): [*Context*](#context)\n\n**Returns:** [*Context*](#context)\n\nDefined in: [lib/async-hooks-state.ts:15](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L15)\n\n___\n\n### hooked\n\n▸ `Const` **hooked**(`defaultContext?`: *Record*\u003cstring \\| number \\| symbol, unknown\\\u003e): *function*\n\n#### Parameters\n\n| Name | Type | Default value |\n| :------ | :------ | :------ |\n| `defaultContext` | *Record*\u003cstring \\| number \\| symbol, unknown\\\u003e | {} |\n\n**Returns:** (`req`: *Request*\u003cParamsDictionary, any, any, ParsedQs, Record\u003cstring, any\\\u003e\\\u003e, `res`: *Response*\u003cany, Record\u003cstring, any\\\u003e\\\u003e, `next`: NextFunction) =\u003e *void*\n\nDefined in: [lib/async-hooks-state.ts:27](https://github.com/ziv/async-hooks-state/blob/d3fdba2/lib/async-hooks-state.ts#L27)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziv%2Fasync-hooks-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziv%2Fasync-hooks-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziv%2Fasync-hooks-state/lists"}