Compare commits

...

11 Commits

Author SHA1 Message Date
d16f557e7b update description 2024-05-29 14:12:54 +02:00
b175669135 update tsconfig 2024-04-14 17:33:00 +02:00
11f60dc2f5 update npmextra.json: githost 2024-04-01 21:34:50 +02:00
17edccc007 update npmextra.json: githost 2024-04-01 19:58:09 +02:00
d66356585e update npmextra.json: githost 2024-03-30 21:47:07 +01:00
46e93f1f89 switch to new org scheme 2023-07-11 00:37:50 +02:00
cd2d9f8168 switch to new org scheme 2023-07-10 02:48:58 +02:00
9f16f7d1fe 2.0.5 2020-02-21 10:05:52 +00:00
673de41d38 fix(core): update 2020-02-21 10:05:52 +00:00
582ed2b641 2.0.4 2020-02-21 09:53:45 +00:00
8b3c1f3a79 fix(core): update 2020-02-21 09:53:44 +00:00
14 changed files with 3177 additions and 552 deletions

23
.gitignore vendored
View File

@ -1,3 +1,22 @@
node_modules/
.yarn/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,16 +1,16 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@ -18,102 +18,103 @@ stages:
mirror:
stage: security
script:
- npmci git mirror
- npmci git mirror
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@ -121,5 +122,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

View File

@ -3,5 +3,28 @@
"npmGlobalTools": [],
"npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartevent",
"shortDescription": "handle events in smart ways",
"npmPackagename": "@push.rocks/smartevent",
"license": "MIT",
"description": "A library to handle events in smart ways, integrating features to work with promises.",
"keywords": [
"event handling",
"smart event management",
"typescript",
"promises integration",
"asynchronous programming",
"event-driven development"
]
}
},
"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"
}
}

1509
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
{
"name": "@pushrocks/smartevent",
"version": "2.0.3",
"name": "@push.rocks/smartevent",
"version": "2.0.5",
"private": false,
"description": "handle events in smart ways",
"description": "A library to handle events in smart ways, integrating features to work with promises.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
@ -11,24 +11,45 @@
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartevent.git"
"url": "https://code.foss.global/push.rocks/smartevent.git"
},
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartevent/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartevent#README",
"homepage": "https://code.foss.global/push.rocks/smartevent",
"dependencies": {
"@pushrocks/smartpromise": "^2.0.5"
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.5",
"events": "^3.1.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsrun": "^1.1.12",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.5",
"@types/node": "^10.9.4",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.17.0"
}
}
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^13.7.4",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"keywords": [
"event handling",
"smart event management",
"typescript",
"promises integration",
"asynchronous programming",
"event-driven development"
]
}

1796
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 @@

103
readme.md Normal file
View File

@ -0,0 +1,103 @@
# @push.rocks/smartevent
handle events in smart ways
## Install
To install @push.rocks/smartevent for use in your project, run the following command in your project root:
```bash
npm install @push.rocks/smartevent --save
```
This command will add `@push.rocks/smartevent` to your project's dependencies, ensuring that its functionality is available for import and use within your application.
## Usage
The `@push.rocks/smartevent` package provides an enhanced event handling mechanism on top of the native Node.js `EventEmitter`. It leverages TypeScript and modern JavaScript features to smartly handle events within your application.
### Importing the Module
Begin by importing the necessary classes and functions from the module. This can be done as follows:
```typescript
import { SmartEventEmitter, once } from '@push.rocks/smartevent';
```
### Using `SmartEventEmitter`
The `SmartEventEmitter` class is an extension of the native `EventEmitter` provided by Node.js but with additional capabilities. Let's see how to use it.
#### Creating an Instance
```typescript
const mySmartEventEmitter = new SmartEventEmitter();
```
#### Emitting Events
With an instance of `SmartEventEmitter`, emitting events is straightforward. You simply use the `emit` method.
```typescript
mySmartEventEmitter.emit('myCustomEvent', { key: 'value' });
```
#### Listening for Events
To listen for events, use the `on` method, passing the event name and a callback function that will be executed when the event is emitted.
```typescript
mySmartEventEmitter.on('myCustomEvent', (data) => {
console.log('Event data:', data);
});
```
#### Listening for an Event Once
You might want to listen for an event only once and then automatically remove the listener. This can be achieved with the `once` method.
```typescript
mySmartEventEmitter.once('myCustomEvent', (data) => {
console.log('This will be logged only once:', data);
});
```
### Using `once` Async Function
The `once` function provides a way to wait for an event to occur exactly once before proceeding. It returns a promise that resolves when the specified event is emitted.
```typescript
(async () => {
const eventData = await once<string>(mySmartEventEmitter, 'myCustomEvent');
console.log('Event data received asynchronously:', eventData);
})();
```
This functionality is particularly useful when dealing with asynchronous operations that trigger events on completion.
### Advanced Use Cases
The simplicity and power of `@push.rocks/smartevent` enable a variety of advanced use cases, such as coordinating complex event-driven flows, or integrating with other promise-based or async/await code seamlessly.
Given its reliance on TypeScript, developers can benefit from strong typing, which adds to code robustness and maintainability. When defining event payloads, consider specifying interfaces or types for the data objects being passed around to ensure type safety across your event listeners.
For those working in environments that support Observables, `@push.rocks/smartevent` can interoperate with libraries like RxJS, allowing events to be transformed into Observable streams for more complex event handling strategies.
### Final Thoughts
`@push.rocks/smartevent` is a utilities suite that extends the native event handling capabilities provided by Node.js, giving developers a smarter way to manage events within their applications. Its integration with TypeScript enhances developer experience through better tooling support and type safety. Whether you're building a small utility library or a large-scale application, `@push.rocks/smartevent` provides a solid foundation for your event management needs.
Remember, the most effective way to use `@push.rocks/smartevent` is by thoroughly understanding the events in your application and how they interact with various components. With smart events, you can design a more reactive, maintainable, and scalable application architecture.
For further exploration, the module includes types and interfaces that encourage best practices for event-driven programming in TypeScript, ensuring that you get the most out of your event handling logic.
By integrating `@push.rocks/smartevent` into your project, you empower yourself with a flexible and powerful tool for managing events, which is essential for building responsive and interactive Node.js applications.
## 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,9 +1,28 @@
import * as plugins from './smartevent.plugins';
import { EventEmitter } from 'events';
export { EventEmitter };
export {
};
export const once = async <T>(eventEmitter: EventEmitter, eventName: string): Promise<T> => {
export class SmartEventEmitter {
public eventSubject = new plugins.
public once () {
};
public emit () {
}
public on () {}
}
// instrument globalThis
export const once = async <T>(eventEmitter: SmartEventEmitter, eventName: string): Promise<T> => {
const done = plugins.smartpromise.defer<T>();
eventEmitter.once(eventName, eventPayload => {
done.resolve(eventPayload);

View File

@ -1,4 +1,5 @@
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import events = require('events');
import * as events from 'events';
export { events, smartpromise };

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"
}