fix(ci): Remove .gitlab-ci.yml and update dependencies and metadata

This commit is contained in:
Philipp Kunz 2024-06-23 23:46:42 +02:00
parent b8e7063bab
commit 8c18dcd0e6
9 changed files with 5511 additions and 3379 deletions

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

88
changelog.md Normal file
View File

@ -0,0 +1,88 @@
# Changelog
## 2024-06-23 - 4.0.4 - fix(ci)
Remove .gitlab-ci.yml and update dependencies and metadata
- Removed .gitlab-ci.yml file
- Updated dependencies in package.json and npmextra.json
- Improved description and keywords for better package definition
## 2024-05-29 - 4.0.3 - Maintenance
Update project configuration and descriptions.
- Update project description
- Update tsconfig
- Update npmextra.json with githost field
## 2023-07-10 - 4.0.2 - Standards
Updates to adhere to new organizational standards.
- Switch to new org scheme
- Fix(core): update project settings
## 2023-04-17 - 4.0.0 - Major Release
Significant updates and switching to ESM.
- Fix(core): update project settings
## 2023-04-04 - 3.1.9 - Major Release
Breaking change: switch to ESM (ECMAScript Module).
## 2021-05-31 - 3.1.6 - Maintenance
Update project settings.
- Fix(core): update project settings
## 2021-04-23 - 3.1.4 - Maintenance
Update project settings.
- Fix(core): update project settings
## 2020-10-16 - 3.1.2 - Maintenance
Update project settings.
- Fix(core): update project settings
## 2020-10-15 - 3.0.9 - Feature
Added functionality for wrapping promises in timeouts.
- Feat(timeouts): allows the wrapping of promises in timeouts
## 2019-10-01 - 3.0.5 - Maintenance
Update project settings.
- Fix(core): update project settings
## 2019-03-26 - 3.0.0 - Major Release
Breaking change: remove util dependency.
- BREAKING CHANGE(remove util dependency and promisify functionality): update
## 2018-07-03 - 2.0.2 - Dependencies
Project now has zero dependencies.
- Fix(core): now has 0 dependencies
## 2018-03-16 - 1.1.8 - Major Release
Breaking change: switch scope to pushrocks.
- BREAKING CHANGE(scope): switch scope to pushrocks
## 2017-07-27 - 1.1.7 - Standards
Update to latest coding standards.
- Update to latest standards
## 2017-07-06 - 1.1.4 - Features and Improvements
Added polyfill and npmextra.json.
- Add polyfill
- Add npmextra.json
## 2017-07-06 - 1.1.2 - CI Maintenance
Updated continuous integration configuration.
- Update ci
```

View File

@ -9,7 +9,7 @@
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartpromise",
"description": "A library for simple promises and Deferred constructs with TypeScript support.",
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
"npmPackagename": "@push.rocks/smartpromise",
"license": "MIT",
"keywords": [
@ -18,9 +18,10 @@
"async",
"promisify",
"cumulative deferred",
"map",
"timeout",
"typescript"
"typescript",
"asynchronous",
"utilities"
]
}
},

View File

@ -2,7 +2,7 @@
"name": "@push.rocks/smartpromise",
"private": false,
"version": "4.0.3",
"description": "A library for simple promises and Deferred constructs with TypeScript support.",
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
@ -21,11 +21,11 @@
},
"homepage": "https://code.foss.global/push.rocks/smartpromise",
"devDependencies": {
"@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.42",
"@gitzone/tstest": "^1.0.74",
"@pushrocks/tapbundle": "^5.0.8",
"@types/node": "^20.4.1"
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.14.8"
},
"files": [
"ts/**/*",
@ -49,8 +49,9 @@
"async",
"promisify",
"cumulative deferred",
"map",
"timeout",
"typescript"
"typescript",
"asynchronous",
"utilities"
]
}

File diff suppressed because it is too large Load Diff

163
readme.md
View File

@ -1,5 +1,6 @@
# @push.rocks/smartpromise
simple promises and Deferred constructs
A library for simple promises and Deferred constructs with TypeScript support.
## Install
@ -86,7 +87,7 @@ rejectedPromise('immediately rejected').catch(console.error);
#### Promisify Callback Functions
`@push.rocks/smartpromise` does not directly provide a `promisify` function like Node.js util module, but you can easily integrate existing functions or use third-party libraries to convert callback-based functions into promises.
`@push.rocks/smartpromise` does not directly provide a `promisify` function like Node.js `util` module, but you can easily integrate existing functions or use third-party libraries to convert callback-based functions into promises.
#### Handling Timeouts and Continuations
@ -132,9 +133,163 @@ async function processData(items: string[]): Promise<string[]> {
processData(['hello', 'world']).then(console.log);
```
### Conclusion
### Handling Complex Promise Scenarios
`@push.rocks/smartpromise` offers a refined and accessible approach to handling promises and asynchronous operations in TypeScript. Whether you're dealing with individual promises, a group of asynchronous tasks, or integrating callback-based APIs into your promise flows, this library provides the necessary tools to make your code more readable and easier to manage. With straightforward utility functions and TypeScript support, it enhances the native Promise API, making it an essential tool for modern TypeScript development.
#### Managing Multiple Deferreds
If you have multiple deferred objects and you want to manage them collectively, you can do so using the `CumulativeDeferred` class. This is especially useful when you have a dynamic number of deferreds to resolve.
```typescript
import { defer, cumulativeDefer } from '@push.rocks/smartpromise';
async function exampleComplexDeferred(): Promise<void> {
const task1 = defer<string>();
const task2 = defer<string>();
const cumulative = cumulativeDefer();
cumulative.addPromise(task1.promise);
cumulative.addPromise(task2.promise);
// Simulate async tasks
setTimeout(() => task1.resolve('Task 1 complete'), 1000);
setTimeout(() => task2.resolve('Task 2 complete'), 2000);
await cumulative.promise;
console.log('All tasks completed');
}
exampleComplexDeferred();
```
### Other Utilities
#### Race Condition Handling with `getFirstTrueOrFalse`
This helper function resolves immediately when one of the provided promises resolves to `true` or when all promises are resolved to `false`.
```typescript
import { getFirstTrueOrFalse } from '@push.rocks/smartpromise';
async function exampleRaceCondition() {
const task1 = new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 1000));
const task2 = new Promise<boolean>((resolve) => setTimeout(() => resolve(false), 2000));
const result = await getFirstTrueOrFalse([task1, task2]);
console.log(result); // Outputs: true
}
exampleRaceCondition();
```
### Complete Use Case
Let's create a comprehensive example that showcases multiple features of `@push.rocks/smartpromise`.
```typescript
import {
defer,
cumulativeDefer,
resolvedPromise,
rejectedPromise,
timeoutWrap,
timeoutAndContinue,
map,
getFirstTrueOrFalse,
} from '@push.rocks/smartpromise';
async function completeUseCaseExample() {
console.log('Starting Complete Use Case Example!');
// Using Deferred
const myDeferred = defer<string>();
setTimeout(() => myDeferred.resolve('Deferred Resolved!'), 500);
console.log(await myDeferred.promise); // Outputs: "Deferred Resolved!"
// Using Cumulative Deferred
const myCumulativeDeferred = cumulativeDefer();
myCumulativeDeferred.addPromise(new Promise((resolve) => setTimeout(() => resolve('Task 1'), 1000)));
myCumulativeDeferred.addPromise(new Promise((resolve) => setTimeout(() => resolve('Task 2'), 2000)));
await myCumulativeDeferred.promise;
console.log('All cumulative tasks completed');
// Using Resolved and Rejected Promises
await resolvedPromise('Instant Resolve').then(console.log); // Outputs: "Instant Resolve"
await rejectedPromise('Instant Reject').catch(console.error); // Outputs: "Instant Reject"
// Using timeoutWrap
try {
const delayedPromise = new Promise((resolve) => setTimeout(() => resolve('Finished'), 3000));
const result = await timeoutWrap(delayedPromise, 1000);
console.log(result);
} catch (e) {
console.error('Timeout occurred'); // Outputs: "Timeout occurred"
}
// Using timeoutAndContinue
const resultContinue = await timeoutAndContinue(
new Promise((resolve) => setTimeout(() => resolve('Finished eventually'), 3000)),
1000
);
console.log(resultContinue); // Outputs: null (since it didn't resolve in 1 second)
// Using Map
const items = ['a', 'b', 'c'];
const processedItems = await map(items, async (item) => {
await new Promise((resolve) => setTimeout(resolve, 500));
return item.toUpperCase();
});
console.log(processedItems); // Outputs: ['A', 'B', 'C']
// Using getFirstTrueOrFalse
const raceResults = await getFirstTrueOrFalse([
new Promise<boolean>((resolve) => setTimeout(() => resolve(false), 1000)),
new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 2000)),
]);
console.log(raceResults); // Outputs: true
console.log('Complete Use Case Example Finished!');
}
completeUseCaseExample();
```
### Testing Your Code
Testing is crucial to ensure the reliability of your asynchronous workflows. You can write tests using the `@push.rocks/tapbundle` library to create unit tests for your promises and deferred constructs.
```typescript
import { tap, expect } from '@push.rocks/tapbundle';
import * as smartpromise from '@push.rocks/smartpromise';
tap.test('should resolve a deferred promise', async () => {
const deferred = smartpromise.defer<string>();
deferred.resolve('Resolved!');
const result = await deferred.promise;
expect(result).toEqual('Resolved!');
});
tap.test('should timeout a long-running promise', async () => {
const longRunningPromise = new Promise((resolve) => setTimeout(resolve, 2000));
try {
await smartpromise.timeoutWrap(longRunningPromise, 1000);
} catch (err) {
expect(err.message).toEqual('timeout');
}
});
tap.test('should map async function to an array', async () => {
const inputArray = ['a', 'b'];
const result = await smartpromise.map(inputArray, async (item) => item.toUpperCase());
expect(result).toEqual(['A', 'B']);
});
tap.start();
```
By following this guide and using the examples provided, you should be able to effectively use `@push.rocks/smartpromise` for managing promises and deferred constructs in your TypeScript project. The library's extensive utility functions, combined with TypeScript support, make it a powerful tool for modern asynchronous programming needs.
Explore the full range of features and feel free to read through the source code to learn more about the implementation details. Happy coding!
## License and Legal Information

View File

@ -1,4 +1,4 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartpromise from '../ts/index.js';
tap.test('should return a Deferred for .defer()', async () => {
@ -24,4 +24,4 @@ tap.test('should map callbacks', async () => {
expect(result).toEqual(inputArray);
});
tap.start();
export default tap.start();

View File

@ -47,7 +47,7 @@ smartpromise
console.log(err);
});
import { tap, expect } from '@pushrocks/tapbundle';
import { tap, expect } from '@push.rocks/tapbundle';
tap.test('runs through', async () => {});
tap.start();
export default tap.start();

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartpromise',
version: '4.0.3',
description: 'simple promises and Deferred constructs'
version: '4.0.4',
description: 'A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.'
}