fix(typescript): tighten TypeScript typings and modernize project tooling configuration
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"@git.zone/cli": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartpromise",
|
||||
"shortDescription": "promise and deferred utilities",
|
||||
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
|
||||
"npmPackagename": "@push.rocks/smartpromise",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"promise",
|
||||
"deferred",
|
||||
"async",
|
||||
"promisify",
|
||||
"cumulative deferred",
|
||||
"timeout",
|
||||
"typescript",
|
||||
"asynchronous",
|
||||
"utilities"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"registries": [
|
||||
"https://verdaccio.lossless.digital",
|
||||
"https://registry.npmjs.org"
|
||||
],
|
||||
"accessLevel": "public"
|
||||
}
|
||||
},
|
||||
"@git.zone/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"
|
||||
},
|
||||
"@ship.zone/szci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmRegistryUrl": "registry.npmjs.org"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-05-01 - 4.2.4 - fix(typescript)
|
||||
tighten TypeScript typings and modernize project tooling configuration
|
||||
|
||||
- replace custom async map implementation with Promise.all while preserving result order
|
||||
- add explicit generic overloads and unknown-based typings across promise utilities and deferred classes
|
||||
- enable noImplicitAny and update tests to use the current tstest tapbundle import
|
||||
- refresh package and project config for newer git.zone tooling and npm release settings
|
||||
|
||||
## 2025-02-20 - 4.2.3 - fix(test)
|
||||
Refactor test suite for improved readability and maintainability.
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+14
-6
@@ -1,14 +1,11 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"@git.zone/cli": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartpromise",
|
||||
"shortDescription": "promise and deferred utilities",
|
||||
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
|
||||
"npmPackagename": "@push.rocks/smartpromise",
|
||||
"license": "MIT",
|
||||
@@ -23,9 +20,20 @@
|
||||
"asynchronous",
|
||||
"utilities"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"registries": [
|
||||
"https://verdaccio.lossless.digital",
|
||||
"https://registry.npmjs.org"
|
||||
],
|
||||
"accessLevel": "public"
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"@git.zone/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"
|
||||
},
|
||||
"@ship.zone/szci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmRegistryUrl": "registry.npmjs.org"
|
||||
}
|
||||
}
|
||||
+11
-9
@@ -6,26 +6,26 @@
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"test": "tstest test/ --web",
|
||||
"format": "gitzone format",
|
||||
"build": "tsbuild --web",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartpromise.git"
|
||||
},
|
||||
"author": "Lossless GmbH",
|
||||
"author": "Task Venture Capital GmbH <hello@task.vc>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartq/issues"
|
||||
"url": "https://code.foss.global/push.rocks/smartpromise/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartpromise",
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.2.0",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^1.0.92",
|
||||
"@push.rocks/tapbundle": "^5.5.6",
|
||||
"@types/node": "^22.10.10"
|
||||
"@git.zone/tsbuild": "^4.4.0",
|
||||
"@git.zone/tsrun": "^2.0.3",
|
||||
"@git.zone/tstest": "^3.6.3",
|
||||
"@types/node": "^25.6.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@@ -36,6 +36,8 @@
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
".smartconfig.json",
|
||||
"license",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
|
||||
Generated
+3829
-5666
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartpromise from '../ts/index.js';
|
||||
|
||||
tap.test('should return a Deferred for .defer()', async () => {
|
||||
@@ -17,7 +17,7 @@ tap.test('should let types flow through the Promise', async () => {
|
||||
|
||||
tap.test('should map callbacks', async () => {
|
||||
const inputArray = ['hi', 'awesome'];
|
||||
const myPromisified = async (myInput) => {
|
||||
const myPromisified = async (myInput: string) => {
|
||||
return myInput;
|
||||
};
|
||||
const result = await smartpromise.map(inputArray, myPromisified);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as smartpromise from '../ts/index.js';
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
tap.test('simple deferred should resolve with correct value', async () => {
|
||||
const done = smartpromise.defer<string>();
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartpromise',
|
||||
version: '4.2.3',
|
||||
version: '4.2.4',
|
||||
description: 'A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.'
|
||||
}
|
||||
|
||||
+18
-24
@@ -3,23 +3,24 @@ import { defer } from './smartpromise.classes.deferred.js';
|
||||
export * from './smartpromise.classes.cumulativedeferred.js';
|
||||
export * from './smartpromise.classes.deferred.js';
|
||||
|
||||
|
||||
export function resolvedPromise(): Promise<void>;
|
||||
export function resolvedPromise<T>(value: T): Promise<T>;
|
||||
/**
|
||||
* Creates a new resolved promise for the provided value.
|
||||
*/
|
||||
export const resolvedPromise = <T>(value?: T): Promise<T> => {
|
||||
export function resolvedPromise<T>(value?: T): Promise<T | void> {
|
||||
return Promise.resolve(value);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new rejected promise for the provided reason.
|
||||
*/
|
||||
export const rejectedPromise = (err) => {
|
||||
export const rejectedPromise = (err: unknown): Promise<never> => {
|
||||
return Promise.reject(err);
|
||||
};
|
||||
|
||||
interface IAsyncFunction<T> {
|
||||
(someArg: T): Promise<T>;
|
||||
interface IAsyncFunction<TInput, TOutput> {
|
||||
(someArg: TInput): Promise<TOutput>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,26 +29,19 @@ interface IAsyncFunction<T> {
|
||||
* @param inputArg
|
||||
* @param functionArg
|
||||
*/
|
||||
export const map = async <T>(inputArg: T[], functionArg: IAsyncFunction<T>) => {
|
||||
const promiseArray: Promise<any>[] = [];
|
||||
const resultArray = [];
|
||||
for (const item of inputArg) {
|
||||
const promise: Promise<any> = functionArg(item);
|
||||
promiseArray.push(promise);
|
||||
promise.then((x) => {
|
||||
resultArray.push(x);
|
||||
});
|
||||
}
|
||||
await Promise.all(promiseArray);
|
||||
return resultArray;
|
||||
export const map = async <TInput, TOutput = TInput>(
|
||||
inputArg: TInput[],
|
||||
functionArg: IAsyncFunction<TInput, TOutput>
|
||||
): Promise<TOutput[]> => {
|
||||
return Promise.all(inputArg.map(functionArg));
|
||||
};
|
||||
|
||||
export const timeoutWrap = async <T = any>(
|
||||
export const timeoutWrap = async <T = unknown>(
|
||||
promiseArg: Promise<T>,
|
||||
timeoutInMsArg: number,
|
||||
rejectArg = true
|
||||
) => {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
): Promise<T | null> => {
|
||||
return new Promise<T | null>((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (rejectArg) {
|
||||
reject(new Error('timeout'));
|
||||
@@ -59,14 +53,14 @@ export const timeoutWrap = async <T = any>(
|
||||
});
|
||||
};
|
||||
|
||||
export const timeoutAndContinue = async <T = any>(
|
||||
export const timeoutAndContinue = async <T = unknown>(
|
||||
promiseArg: Promise<T>,
|
||||
timeoutInMsArg = 60000
|
||||
) => {
|
||||
): Promise<T | null> => {
|
||||
return timeoutWrap(promiseArg, timeoutInMsArg, false);
|
||||
};
|
||||
|
||||
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
|
||||
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]): Promise<boolean> => {
|
||||
const done = defer<boolean>();
|
||||
for (const promiseArg of promisesArg) {
|
||||
promiseArg.then((resultArg) => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { defer } from "./smartpromise.classes.deferred.js";
|
||||
import { defer } from './smartpromise.classes.deferred.js';
|
||||
|
||||
export class CumulativeDeferred {
|
||||
private accumulatedPromises: Promise<any>[] = [];
|
||||
private deferred = defer();
|
||||
private accumulatedPromises: Promise<unknown>[] = [];
|
||||
private deferred = defer<void>();
|
||||
public promise = this.deferred.promise;
|
||||
|
||||
constructor() {
|
||||
@@ -16,17 +16,16 @@ export class CumulativeDeferred {
|
||||
}
|
||||
|
||||
public subDefer() {
|
||||
const done = defer();
|
||||
const done = defer<void>();
|
||||
this.addPromise(done.promise);
|
||||
return done;
|
||||
}
|
||||
|
||||
public addPromise(promiseArg: Promise<any>) {
|
||||
public addPromise(promiseArg: Promise<unknown>): void {
|
||||
this.accumulatedPromises.push(promiseArg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const cumulativeDefer = () => {
|
||||
return new CumulativeDeferred();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,16 +3,16 @@ export interface IResolve<T> {
|
||||
}
|
||||
|
||||
export interface IReject {
|
||||
(reason?: any): void;
|
||||
(reason?: unknown): 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 resolve!: IResolve<T>;
|
||||
public reject!: IReject;
|
||||
public status!: TDeferredStatus;
|
||||
public claimed = false;
|
||||
public claim() {
|
||||
if (this.claimed) {
|
||||
@@ -21,8 +21,8 @@ export class Deferred<T> {
|
||||
this.claimed = true;
|
||||
}
|
||||
|
||||
public startedAt: number;
|
||||
public stoppedAt: number;
|
||||
public startedAt!: number;
|
||||
public stoppedAt!: number;
|
||||
public get duration(): number {
|
||||
if (this.stoppedAt) {
|
||||
return this.stoppedAt - this.startedAt;
|
||||
@@ -33,12 +33,12 @@ export class Deferred<T> {
|
||||
|
||||
constructor() {
|
||||
this.promise = new Promise<T>((resolve, reject) => {
|
||||
this.resolve = (valueArg: T | PromiseLike<T>) => {
|
||||
this.resolve = (valueArg?: T | PromiseLike<T>) => {
|
||||
this.status = 'fulfilled';
|
||||
this.stoppedAt = Date.now();
|
||||
resolve(valueArg);
|
||||
resolve(valueArg as T | PromiseLike<T>);
|
||||
};
|
||||
this.reject = (reason: any) => {
|
||||
this.reject = (reason?: unknown) => {
|
||||
this.status = 'rejected';
|
||||
this.stoppedAt = Date.now();
|
||||
reject(reason);
|
||||
@@ -49,6 +49,6 @@ export class Deferred<T> {
|
||||
}
|
||||
}
|
||||
|
||||
export const defer = <T>() => {
|
||||
export const defer = <T = void>() => {
|
||||
return new Deferred<T>();
|
||||
};
|
||||
+4
-4
@@ -5,10 +5,10 @@
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
"exclude": ["dist_*/**/*.d.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user