Compare commits

...

15 Commits

Author SHA1 Message Date
a5074dd496 1.0.14 2024-06-06 19:20:29 +02:00
5b8a951c45 fix(core): update 2024-06-06 19:20:28 +02:00
462d5cd3ff 1.0.13 2024-06-06 18:26:12 +02:00
8fcee684fd fix(core): update 2024-06-06 18:26:11 +02:00
81c227fac1 update description 2024-05-29 14:12:15 +02:00
c33c5d2678 update tsconfig 2024-04-14 17:25:46 +02:00
2c00895c1d update npmextra.json: githost 2024-04-01 21:34:16 +02:00
996ed474a4 update npmextra.json: githost 2024-04-01 19:57:53 +02:00
091692fe2d update npmextra.json: githost 2024-03-30 21:46:50 +01:00
6f2c433632 switch to new org scheme 2023-07-11 00:28:36 +02:00
3bf670d5d6 switch to new org scheme 2023-07-10 02:42:47 +02:00
f8dfeb3646 1.0.12 2021-10-06 18:00:33 +02:00
51df4c45c2 fix(core): update 2021-10-06 18:00:32 +02:00
688be71399 1.0.11 2021-09-17 19:35:26 +02:00
af973c47a1 fix(core): update 2021-09-17 19:35:26 +02:00
14 changed files with 7249 additions and 27042 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -36,6 +36,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
@ -120,7 +121,7 @@ pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci command npm install -g @git.zone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc

View File

@ -6,12 +6,26 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartcls",
"shortDescription": "continuation-local-storage using native AsyncLocalStorage",
"npmPackagename": "@pushrocks/smartcls",
"license": "MIT"
"npmPackagename": "@push.rocks/smartcls",
"license": "MIT",
"description": "Provides a wrapper for native AsyncLocalStorage to manage continuation-local storage.",
"keywords": [
"async local storage",
"continuation-local storage",
"context management",
"async_hooks",
"node.js",
"typescript",
"asynchronous storage",
"thread local storage"
]
}
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

26974
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,23 @@
{
"name": "@pushrocks/smartcls",
"version": "1.0.10",
"description": "continuation-local-storage using native AsyncLocalStorage",
"name": "@push.rocks/smartcls",
"version": "1.0.14",
"description": "Provides a wrapper for native AsyncLocalStorage to manage continuation-local storage.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "tstest test/",
"build": "tsbuild --web"
"build": "tsbuild --web",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.27",
"@gitzone/tsbundle": "^1.0.87",
"@gitzone/tstest": "^1.0.57",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^16.9.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsbundle": "^2.0.8",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.14.2"
},
"private": false,
"browserslist": [
@ -34,5 +34,24 @@
"cli.js",
"npmextra.json",
"readme.md"
]
],
"keywords": [
"async local storage",
"continuation-local storage",
"context management",
"async_hooks",
"node.js",
"typescript",
"asynchronous storage",
"thread local storage"
],
"homepage": "https://code.foss.global/push.rocks/smartcls#readme",
"repository": {
"type": "git",
"url": "git+https://code.foss.global/push.rocks/smartcls.git"
},
"bugs": {
"url": "https://code.foss.global/push.rocks/smartcls/issues"
},
"type": "module"
}

6846
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

159
readme.md
View File

@ -1,39 +1,144 @@
# @pushrocks/smartcls
# @push.rocks/smartcls
continuation-local-storage using native AsyncLocalStorage
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartcls)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartcls)
* [github.com (source mirror)](https://github.com/pushrocks/smartcls)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcls/)
## Install
## Status for master
To install `@push.rocks/smartcls`, use the following command with npm:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartcls/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartcls/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartcls)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartcls)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartcls)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartcls)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartcls)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
```sh
npm install @push.rocks/smartcls
```
or if you prefer using Yarn:
```sh
yarn add @push.rocks/smartcls
```
## Usage
Use TypeScript for best in class instellisense.
`@push.rocks/smartcls` simplifies the usage of native AsyncLocalStorage in Node.js, allowing for a more convenient approach to work with continuation-local storage. This can be especially handy in scenarios where context passing through asynchronous calls is essential, such as in web servers or complex application flows that involve async operations.
## Contribution
### Basic Setup and Running Context
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
To start using `@push.rocks/smartcls`, you first need to import it and create an instance of `SmartCls`.
For further information read the linked docs at the top of this readme.
```typescript
import { SmartCls } from '@push.rocks/smartcls';
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
const mySmartCls = new SmartCls();
```
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
Once you have an instance, you can utilize the `run` method to establish a new context. Within this context, you can set and get values that are scoped to the lifetime of the context.
```typescript
mySmartCls.run(() => {
mySmartCls.set('key', 'value');
// later in the async flow
console.log(mySmartCls.get('key')); // Outputs: 'value'
});
```
### Asynchronous Example
The power of `SmartCls` becomes evident when working with asynchronous operations. Values set in a specific context are accessible throughout the async flow initiated within that context.
```typescript
import { SmartCls } from '@push.rocks/smartcls';
const mySmartCls = new SmartCls();
mySmartCls.run(async () => {
mySmartCls.set('asyncKey', 'asyncValue');
await someAsyncFunction();
console.log(mySmartCls.get('asyncKey')); // Outputs: 'asyncValue', even after async operations
});
```
Ensure all asynchronous operations initiated in the context are awaited or properly handled to maintain the context's integrity.
### Nested Contexts
`@push.rocks/smartcls` supports nested contexts, allowing you to create sub-contexts within a main context. This can be useful for overriding values or isolating sections of your async flow.
```typescript
import { SmartCls } from '@push.rocks/smartcls';
const mySmartCls = new SmartCls();
mySmartCls.run(() => {
mySmartCls.set('level', 'top');
mySmartCls.run(() => {
mySmartCls.set('level', 'nested');
console.log(mySmartCls.get('level')); // Outputs: 'nested'
});
console.log(mySmartCls.get('level')); // Outputs: 'top', reverting back to the parent context
});
```
### Working with Express or Similar Frameworks
In a web server scenario using Express or a similar framework, you can integrate `SmartCls` to track request-specific data across asynchronous operations without explicitly passing the request object.
```typescript
import express from 'express';
import { SmartCls } from '@push.rocks/smartcls';
const app = express();
const mySmartCls = new SmartCls();
app.use((req, res, next) => {
mySmartCls.run(() => {
mySmartCls.set('requestId', req.header('X-Request-Id') || Math.random().toString());
next();
});
});
app.get('/', async (req, res) => {
// Simulate an async operation
await new Promise(resolve => setTimeout(resolve, 100));
// Access the requestId set at the beginning of the request
res.send(`Request ID: ${mySmartCls.get('requestId')}`);
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
```
This example demonstrates how to maintain a unique `requestId` for logging or tracking purposes across asynchronous operations within a single request-response cycle.
### Important Considerations
- Ensure that all async operations in a context are awaited to prevent context leakage.
- Be mindful of memory usage when storing large objects in the context, as each context retains its values until completion.
- `SmartCls` leverages Node.js's native `AsyncLocalStorage`, so it's dependent on the Node.js version supporting this feature.
### Conclusion
`@push.rocks/smartcls` offers a straightforward and efficient approach to managing continuation-local storage in Node.js applications, simplifying context management across asynchronous operations.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,5 +1,5 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartcls from '../ts/index';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartcls from '../ts/index.js';
const testSmartcls = new smartcls.SmartCls();
@ -7,9 +7,9 @@ tap.testParallel('should get namespace', async (tools) => {
testSmartcls.run(async () => {
testSmartcls.set('some', 'anything');
await tools.delayFor(1000);
expect(testSmartcls.get('some')).to.equal('anything');
expect(testSmartcls.get('some')).toEqual('anything');
tools.delayFor(200).then(() => {
expect(testSmartcls.get('some')).to.equal('anything');
expect(testSmartcls.get('some')).toEqual('anything');
});
});
});
@ -18,9 +18,9 @@ tap.testParallel('should get namespace with other values', async (tools) => {
testSmartcls.run(async () => {
testSmartcls.set('some', 'otherthing');
await tools.delayFor(500);
expect(testSmartcls.get('some')).to.equal('otherthing');
expect(testSmartcls.get('some')).toEqual('otherthing');
tools.delayFor(200).then(() => {
expect(testSmartcls.get('some')).to.equal('otherthing');
expect(testSmartcls.get('some')).toEqual('otherthing');
});
});
});

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartcls',
version: '1.0.14',
description: 'Provides a wrapper for native AsyncLocalStorage to manage continuation-local storage.'
}

View File

@ -1,4 +1,4 @@
import * as plugins from './smartcls.plugins';
import * as plugins from './smartcls.plugins.js';
export class SmartCls {
private asyncLocalStorage = new plugins.AsyncLocalStorage();

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}