fix(core): update
This commit is contained in:
parent
40642fd6f6
commit
960c23fecd
@ -12,40 +12,36 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
- 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 npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- 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:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
@ -56,7 +52,6 @@ auditDevDependencies:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
@ -67,10 +62,9 @@ testStable:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
@ -96,10 +90,9 @@ codequality:
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -119,11 +112,9 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"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"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartpromise",
|
||||
"shortDescription": "simple promises and Deferred constructs",
|
||||
"description": "simple promises and Deferred constructs",
|
||||
"npmPackagename": "@pushrocks/smartpromise",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
25702
package-lock.json
generated
25702
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -7,7 +7,8 @@
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -20,12 +21,11 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartq#README",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tstest": "^1.0.54",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"@types/node": "^15.6.1",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@gitzone/tsbuild": "^2.1.65",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.74",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.15.11"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -41,5 +41,6 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
],
|
||||
"type": "module"
|
||||
}
|
4460
pnpm-lock.yaml
generated
Normal file
4460
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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 (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)
|
||||
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
|
||||
|
||||
@ -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.
|
||||
|
||||
> 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)
|
||||
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
|
@ -1,19 +1,18 @@
|
||||
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 () => {
|
||||
const myDeferred = smartpromise.defer();
|
||||
const expectPromise = expect(myDeferred.promise).to.eventually.be.fulfilled;
|
||||
myDeferred.resolve();
|
||||
return expectPromise;
|
||||
await myDeferred.promise;
|
||||
});
|
||||
|
||||
tap.test('should let types flow through the Promise', async () => {
|
||||
const myString = 'someString';
|
||||
const myDeferred = smartpromise.defer<string>();
|
||||
const expectPromise = expect(myDeferred.promise).to.eventually.equal('someString');
|
||||
myDeferred.resolve(myString);
|
||||
return expectPromise;
|
||||
const result = await myDeferred.promise;
|
||||
expect(result).toEqual('someString');
|
||||
});
|
||||
|
||||
tap.test('should map callbacks', async () => {
|
||||
@ -21,10 +20,8 @@ tap.test('should map callbacks', async () => {
|
||||
const myPromisified = async (myInput) => {
|
||||
return myInput;
|
||||
};
|
||||
const expectPromise = expect(
|
||||
smartpromise.map(inputArray, myPromisified)
|
||||
).to.eventually.deep.equal(inputArray);
|
||||
return expectPromise;
|
||||
const result = await smartpromise.map(inputArray, myPromisified);
|
||||
expect(result).toEqual(inputArray);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as smartpromise from '../ts';
|
||||
import * as smartpromise from '../ts/index.js';
|
||||
|
||||
// using Deferreds
|
||||
// simple deferred;
|
||||
@ -6,8 +6,7 @@ const done = smartpromise.defer();
|
||||
done.promise.then((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
|
||||
const myAsyncFunction = async (): Promise<string> => {
|
||||
@ -48,7 +47,7 @@ smartpromise
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
import {tap, expect } from '@pushrocks/tapbundle';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
tap.test('runs through', async () => {})
|
||||
tap.start();
|
||||
tap.test('runs through', async () => {});
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal 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'
|
||||
}
|
61
ts/index.ts
61
ts/index.ts
@ -1,50 +1,8 @@
|
||||
export interface IResolve<T> {
|
||||
(value?: T | PromiseLike<T>): void;
|
||||
}
|
||||
import { defer } from './smartpromise.classes.deferred.js';
|
||||
|
||||
export interface IReject {
|
||||
(reason?: any): void;
|
||||
}
|
||||
export * from './smartpromise.classes.commulativepromise.js';
|
||||
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.
|
||||
@ -84,7 +42,11 @@ export const map = async <T>(inputArg: T[], functionArg: IAsyncFunction<T>) => {
|
||||
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) => {
|
||||
setTimeout(() => {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
|
||||
const done = defer<boolean>();
|
||||
|
26
ts/smartpromise.classes.commulativepromise.ts
Normal file
26
ts/smartpromise.classes.commulativepromise.ts
Normal 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();
|
||||
}
|
47
ts/smartpromise.classes.deferred.ts
Normal file
47
ts/smartpromise.classes.deferred.ts
Normal 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
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -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"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user