fix(core): update

This commit is contained in:
Philipp Kunz 2023-04-04 20:22:57 +02:00
parent 40642fd6f6
commit 960c23fecd
15 changed files with 4609 additions and 25844 deletions

View File

@ -12,40 +12,36 @@ stages:
- release - release
- metadata - metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm install --production --ignore-scripts - npmci command pnpm audit --audit-level=high --prod
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- lossless
- docker - docker
allow_failure: true
auditDevDependencies: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev - npmci command pnpm audit --audit-level=high --dev
tags: tags:
- lossless
- docker - docker
allow_failure: true allow_failure: true
@ -56,7 +52,6 @@ auditDevDependencies:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
@ -67,10 +62,9 @@ testStable:
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
@ -96,10 +90,9 @@ codequality:
only: only:
- tags - tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -119,11 +112,9 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${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"
} }
] ]
} }

View File

@ -9,7 +9,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smartpromise", "gitrepo": "smartpromise",
"shortDescription": "simple promises and Deferred constructs", "description": "simple promises and Deferred constructs",
"npmPackagename": "@pushrocks/smartpromise", "npmPackagename": "@pushrocks/smartpromise",
"license": "MIT" "license": "MIT"
} }

25702
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,8 @@
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web)" "build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,12 +21,11 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartq#README", "homepage": "https://gitlab.com/pushrocks/smartq#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.65",
"@gitzone/tstest": "^1.0.54", "@gitzone/tsrun": "^1.2.39",
"@pushrocks/tapbundle": "^3.2.14", "@gitzone/tstest": "^1.0.74",
"@types/node": "^15.6.1", "@pushrocks/tapbundle": "^5.0.4",
"tslint": "^6.1.3", "@types/node": "^18.15.11"
"tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -41,5 +41,6 @@
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ],
} "type": "module"
}

4460
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,6 @@ Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](htt
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartpromise)](https://lossless.cloud) PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartpromise)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartpromise)](https://lossless.cloud) PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartpromise)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartpromise)](https://lossless.cloud) BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartpromise)](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)
## Usage ## Usage
@ -92,7 +91,6 @@ We are always happy for code contributions. If you are not the code contributing
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) ## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,19 +1,18 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartpromise from '../ts/index'; import * as smartpromise from '../ts/index.js';
tap.test('should return a Deferred for .defer()', async () => { tap.test('should return a Deferred for .defer()', async () => {
const myDeferred = smartpromise.defer(); const myDeferred = smartpromise.defer();
const expectPromise = expect(myDeferred.promise).to.eventually.be.fulfilled;
myDeferred.resolve(); myDeferred.resolve();
return expectPromise; await myDeferred.promise;
}); });
tap.test('should let types flow through the Promise', async () => { tap.test('should let types flow through the Promise', async () => {
const myString = 'someString'; const myString = 'someString';
const myDeferred = smartpromise.defer<string>(); const myDeferred = smartpromise.defer<string>();
const expectPromise = expect(myDeferred.promise).to.eventually.equal('someString');
myDeferred.resolve(myString); myDeferred.resolve(myString);
return expectPromise; const result = await myDeferred.promise;
expect(result).toEqual('someString');
}); });
tap.test('should map callbacks', async () => { tap.test('should map callbacks', async () => {
@ -21,10 +20,8 @@ tap.test('should map callbacks', async () => {
const myPromisified = async (myInput) => { const myPromisified = async (myInput) => {
return myInput; return myInput;
}; };
const expectPromise = expect( const result = await smartpromise.map(inputArray, myPromisified);
smartpromise.map(inputArray, myPromisified) expect(result).toEqual(inputArray);
).to.eventually.deep.equal(inputArray);
return expectPromise;
}); });
tap.start(); tap.start();

View File

@ -1,4 +1,4 @@
import * as smartpromise from '../ts'; import * as smartpromise from '../ts/index.js';
// using Deferreds // using Deferreds
// simple deferred; // simple deferred;
@ -6,8 +6,7 @@ const done = smartpromise.defer();
done.promise.then((stringArg) => { done.promise.then((stringArg) => {
console.log(stringArg); console.log(stringArg);
}); });
done.resolve('hello') // whenever you are ready done.resolve('hello'); // whenever you are ready
// using deferreds in async functions to cater callback style apis // using deferreds in async functions to cater callback style apis
const myAsyncFunction = async (): Promise<string> => { const myAsyncFunction = async (): Promise<string> => {
@ -48,7 +47,7 @@ smartpromise
console.log(err); console.log(err);
}); });
import {tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@pushrocks/tapbundle';
tap.test('runs through', async () => {}) tap.test('runs through', async () => {});
tap.start(); tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartpromise',
version: '3.1.8',
description: 'simple promises and Deferred constructs'
}

View File

@ -1,50 +1,8 @@
export interface IResolve<T> { import { defer } from './smartpromise.classes.deferred.js';
(value?: T | PromiseLike<T>): void;
}
export interface IReject { export * from './smartpromise.classes.commulativepromise.js';
(reason?: any): void; export * from './smartpromise.classes.deferred.js';
}
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected';
export class Deferred<T> {
public promise: Promise<T>;
public resolve: IResolve<T>;
public reject: IReject;
public status: TDeferredStatus;
public startedAt: number;
public stoppedAt: number;
public get duration(): number {
if (this.stoppedAt) {
return this.stoppedAt - this.startedAt;
} else {
return Date.now() - this.startedAt;
}
}
constructor() {
this.promise = new Promise<T>((resolve, reject) => {
this.resolve = (valueArg: T | PromiseLike<T>) => {
this.status = 'fulfilled';
this.stoppedAt = Date.now();
resolve(valueArg);
};
this.reject = (reason: any) => {
this.status = 'rejected';
this.stoppedAt = Date.now();
reject(reason);
};
this.startedAt = Date.now();
this.status = 'pending';
});
}
}
export const defer = <T>() => {
return new Deferred<T>();
};
/** /**
* Creates a new resolved promise for the provided value. * Creates a new resolved promise for the provided value.
@ -84,7 +42,11 @@ export const map = async <T>(inputArg: T[], functionArg: IAsyncFunction<T>) => {
return resultArray; return resultArray;
}; };
export const timeoutWrap = async <T = any>(promiseArg: Promise<T>, timeoutInMsArg: number, rejectArg = true) => { export const timeoutWrap = async <T = any>(
promiseArg: Promise<T>,
timeoutInMsArg: number,
rejectArg = true
) => {
return new Promise<T>((resolve, reject) => { return new Promise<T>((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
if (rejectArg) { if (rejectArg) {
@ -97,9 +59,12 @@ export const timeoutWrap = async <T = any>(promiseArg: Promise<T>, timeoutInMsAr
}); });
}; };
export const timeoutAndContinue = async <T = any>(promiseArg: Promise<T>, timeoutInMsArg = 60000) => { export const timeoutAndContinue = async <T = any>(
promiseArg: Promise<T>,
timeoutInMsArg = 60000
) => {
return timeoutWrap(promiseArg, timeoutInMsArg, false); return timeoutWrap(promiseArg, timeoutInMsArg, false);
} };
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => { export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
const done = defer<boolean>(); const done = defer<boolean>();

View File

@ -0,0 +1,26 @@
import { defer } from "./smartpromise.classes.deferred.js";
export class ComulativeDeferred {
private accumulatedPromises: Promise<any>[] = [];
private deferred = defer();
public promise = this.deferred.promise;
constructor() {
setTimeout(async () => {
while (this.accumulatedPromises.length > 0) {
const poppedPromise = this.accumulatedPromises.shift();
await poppedPromise;
}
this.deferred.resolve();
}, 0);
}
public addPromise(promiseArg: Promise<any>) {
this.accumulatedPromises.push(promiseArg);
}
}
export const commulativeDefer = () => {
return new ComulativeDeferred();
}

View File

@ -0,0 +1,47 @@
export interface IResolve<T> {
(value?: T | PromiseLike<T>): void;
}
export interface IReject {
(reason?: any): void;
}
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected';
export class Deferred<T> {
public promise: Promise<T>;
public resolve: IResolve<T>;
public reject: IReject;
public status: TDeferredStatus;
public startedAt: number;
public stoppedAt: number;
public get duration(): number {
if (this.stoppedAt) {
return this.stoppedAt - this.startedAt;
} else {
return Date.now() - this.startedAt;
}
}
constructor() {
this.promise = new Promise<T>((resolve, reject) => {
this.resolve = (valueArg: T | PromiseLike<T>) => {
this.status = 'fulfilled';
this.stoppedAt = Date.now();
resolve(valueArg);
};
this.reject = (reason: any) => {
this.status = 'rejected';
this.stoppedAt = Date.now();
reject(reason);
};
this.startedAt = Date.now();
this.status = 'pending';
});
}
}
export const defer = <T>() => {
return new Deferred<T>();
};

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

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