@xylabs/promise 7.0.2 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/neutral/index.d.ts +1 -6
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +2 -56
- package/dist/neutral/index.mjs.map +3 -3
- package/dist/neutral/model.d.ts +1 -2
- package/dist/neutral/model.d.ts.map +1 -1
- package/package.json +19 -12
- package/dist/neutral/PromiseEx.d.ts +0 -24
- package/dist/neutral/PromiseEx.d.ts.map +0 -1
- package/dist/neutral/fulfilled.d.ts +0 -7
- package/dist/neutral/fulfilled.d.ts.map +0 -1
- package/dist/neutral/fulfilledValues.d.ts +0 -20
- package/dist/neutral/fulfilledValues.d.ts.map +0 -1
- package/dist/neutral/rejected.d.ts +0 -7
- package/dist/neutral/rejected.d.ts.map +0 -1
- package/dist/neutral/toPromise.d.ts +0 -8
- package/dist/neutral/toPromise.d.ts.map +0 -1
- package/dist/neutral/types.d.ts +0 -23
- package/dist/neutral/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> **Deprecated.** Use [`@ariestools/sdk`](../../ariestools-sdk/README.md) instead. This package is a backward-compatibility re-export shim.
|
|
2
|
+
|
|
1
3
|
[![logo][]](https://xylabs.com)
|
|
2
4
|
|
|
3
5
|
# @xylabs/promise
|
|
@@ -12,25 +14,25 @@
|
|
|
12
14
|
Using npm:
|
|
13
15
|
|
|
14
16
|
```sh
|
|
15
|
-
npm install
|
|
17
|
+
npm install @xylabs/promise
|
|
16
18
|
```
|
|
17
19
|
|
|
18
20
|
Using yarn:
|
|
19
21
|
|
|
20
22
|
```sh
|
|
21
|
-
yarn add
|
|
23
|
+
yarn add @xylabs/promise
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
Using pnpm:
|
|
25
27
|
|
|
26
28
|
```sh
|
|
27
|
-
pnpm add
|
|
29
|
+
pnpm add @xylabs/promise
|
|
28
30
|
```
|
|
29
31
|
|
|
30
32
|
Using bun:
|
|
31
33
|
|
|
32
34
|
```sh
|
|
33
|
-
bun add
|
|
35
|
+
bun add @xylabs/promise
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { fulfilledValues } from './fulfilledValues.ts';
|
|
3
|
-
export * from './PromiseEx.ts';
|
|
4
|
-
export { rejected } from './rejected.ts';
|
|
5
|
-
export * from './toPromise.ts';
|
|
6
|
-
export * from './types.ts';
|
|
1
|
+
export * from '@ariestools/sdk/promise';
|
|
7
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
return val.status === "fulfilled";
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
// src/fulfilledValues.ts
|
|
7
|
-
var fulfilledValues = (previousValue, currentValue) => {
|
|
8
|
-
if (currentValue.status === "fulfilled") previousValue.push(currentValue.value);
|
|
9
|
-
return previousValue;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/PromiseEx.ts
|
|
13
|
-
var PromiseEx = class extends Promise {
|
|
14
|
-
/** Whether the promise has been cancelled via a value callback. */
|
|
15
|
-
cancelled;
|
|
16
|
-
_value;
|
|
17
|
-
constructor(func, value) {
|
|
18
|
-
super(func);
|
|
19
|
-
this._value = value;
|
|
20
|
-
}
|
|
21
|
-
// eslint-disable-next-line unicorn/no-thenable
|
|
22
|
-
then(onfulfilled, onrejected, onvalue) {
|
|
23
|
-
if (onvalue?.(this._value) === true) {
|
|
24
|
-
this.cancelled = true;
|
|
25
|
-
}
|
|
26
|
-
return super.then(onfulfilled, onrejected);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
|
|
30
|
-
* @param onvalue - A callback that receives the attached value and returns whether to cancel.
|
|
31
|
-
* @returns This instance for chaining.
|
|
32
|
-
*/
|
|
33
|
-
value(onvalue) {
|
|
34
|
-
if (onvalue?.(this._value) === true) {
|
|
35
|
-
this.cancelled = true;
|
|
36
|
-
}
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/rejected.ts
|
|
42
|
-
var rejected = (val) => {
|
|
43
|
-
return val.status === "rejected";
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// src/toPromise.ts
|
|
47
|
-
function toPromise(value) {
|
|
48
|
-
return value instanceof Promise ? value : Promise.resolve(value);
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
PromiseEx,
|
|
52
|
-
fulfilled,
|
|
53
|
-
fulfilledValues,
|
|
54
|
-
rejected,
|
|
55
|
-
toPromise
|
|
56
|
-
};
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "@ariestools/sdk/promise";
|
|
57
3
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from '@ariestools/sdk/promise'\n"],
|
|
5
|
+
"mappings": ";AAAA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/neutral/model.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,mBAAmB,+BAA+B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/promise",
|
|
3
|
-
"version": "7.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.0.3",
|
|
4
|
+
"description": "DEPRECATED — use @ariestools/sdk/promise. Backward-compatibility re-export shim.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"promise",
|
|
7
6
|
"xylabs",
|
|
8
7
|
"utility",
|
|
9
8
|
"typescript",
|
|
@@ -31,11 +30,11 @@
|
|
|
31
30
|
"types": "./dist/neutral/index.d.ts",
|
|
32
31
|
"default": "./dist/neutral/index.mjs"
|
|
33
32
|
},
|
|
33
|
+
"./package.json": "./package.json",
|
|
34
34
|
"./model": {
|
|
35
35
|
"types": "./dist/neutral/model.d.ts",
|
|
36
36
|
"default": "./dist/neutral/model.mjs"
|
|
37
|
-
}
|
|
38
|
-
"./package.json": "./package.json"
|
|
37
|
+
}
|
|
39
38
|
},
|
|
40
39
|
"files": [
|
|
41
40
|
"dist",
|
|
@@ -45,23 +44,31 @@
|
|
|
45
44
|
"README.md"
|
|
46
45
|
],
|
|
47
46
|
"dependencies": {
|
|
48
|
-
"@
|
|
47
|
+
"@ariestools/sdk": "~7.0.3"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
50
|
+
"@opentelemetry/api": "^1.9.1",
|
|
51
|
+
"@opentelemetry/sdk-trace-base": "^2.8.0",
|
|
52
|
+
"@xylabs/toolchain": "^8.5.5",
|
|
53
|
+
"@xylabs/tsconfig": "^8.5.5",
|
|
54
|
+
"async-mutex": "^0.5.0",
|
|
53
55
|
"browserslist": "4.28.4",
|
|
54
56
|
"eslint": "^10.6.0",
|
|
55
57
|
"eslint-import-resolver-typescript": "^4.4.5",
|
|
56
58
|
"typescript": "^6.0.3",
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
"zod": "^4.4.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@opentelemetry/api": "^1.9",
|
|
63
|
+
"@opentelemetry/sdk-trace-base": "^2.7",
|
|
64
|
+
"async-mutex": "^0.5",
|
|
65
|
+
"zod": "^4.4"
|
|
60
66
|
},
|
|
61
67
|
"engines": {
|
|
62
68
|
"node": ">=18"
|
|
63
69
|
},
|
|
64
70
|
"publishConfig": {
|
|
65
71
|
"access": "public"
|
|
66
|
-
}
|
|
72
|
+
},
|
|
73
|
+
"deprecated": "Use @ariestools/sdk/promise instead. @xylabs/promise is a compatibility shim only and will not receive further updates."
|
|
67
74
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** A resolve/reject callback used within PromiseEx. */
|
|
2
|
-
export type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult;
|
|
3
|
-
/** The executor function passed to the PromiseEx constructor. */
|
|
4
|
-
export type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
5
|
-
/** A callback that inspects the attached value and returns whether to cancel the promise. */
|
|
6
|
-
export type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* An extended Promise that carries an optional attached value and supports cancellation.
|
|
9
|
-
* The value can be inspected via the `then` or `value` methods to conditionally cancel.
|
|
10
|
-
*/
|
|
11
|
-
export declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
12
|
-
/** Whether the promise has been cancelled via a value callback. */
|
|
13
|
-
cancelled?: boolean;
|
|
14
|
-
private _value?;
|
|
15
|
-
constructor(func: PromiseExFunc<T>, value?: V);
|
|
16
|
-
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null, onvalue?: (value?: V) => boolean): Promise<TResult1 | TResult2>;
|
|
17
|
-
/**
|
|
18
|
-
* Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
|
|
19
|
-
* @param onvalue - A callback that receives the attached value and returns whether to cancel.
|
|
20
|
-
* @returns This instance for chaining.
|
|
21
|
-
*/
|
|
22
|
-
value(onvalue?: (value?: V) => boolean): this;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=PromiseEx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PromiseEx.d.ts","sourceRoot":"","sources":["../../src/PromiseEx.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAA;AAEpE,iEAAiE;AACjE,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,IAAI,CAAA;AAEhH,6FAA6F;AAC7F,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;AAE1D;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAC;IACpD,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,MAAM,CAAC,CAAG;gBAEN,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;IAMpC,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,EAC1C,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,EACrE,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,EAC3E,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO,GAC/B,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAQ/B;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO;CAMvC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fulfilled.d.ts","sourceRoot":"","sources":["../../src/fulfilled.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,KAAK,oBAAoB,CAAC,CAAC,CAAC,KAAG,GAAG,IAAI,sBAAsB,CAAC,CAAC,CAE1F,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For use with Promise.allSettled to reduce to only successful result values
|
|
3
|
-
* @example <caption>Casting the initialValue provided to reduce</caption>
|
|
4
|
-
* const resolved = Promise.resolve('resolved')
|
|
5
|
-
* const rejected = Promise.reject('rejected')
|
|
6
|
-
* const settled = await Promise.allSettled([resolved, rejected])
|
|
7
|
-
* const results = settled.reduce(fulfilledValues, [] as string[])
|
|
8
|
-
* // results === [ 'resolved' ]
|
|
9
|
-
* @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>
|
|
10
|
-
* const resolved = Promise.resolve('resolved')
|
|
11
|
-
* const rejected = Promise.reject('rejected')
|
|
12
|
-
* const settled = await Promise.allSettled([resolved, rejected])
|
|
13
|
-
* const results = settled.reduce<string[]>(fulfilledValues, [])
|
|
14
|
-
* // results === [ 'resolved' ]
|
|
15
|
-
* @param previousValue
|
|
16
|
-
* @param currentValue
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export declare const fulfilledValues: <T>(previousValue: T[], currentValue: PromiseSettledResult<T>) => T[];
|
|
20
|
-
//# sourceMappingURL=fulfilledValues.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fulfilledValues.d.ts","sourceRoot":"","sources":["../../src/fulfilledValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,eAAe,CAAC,EAAE,EAAE,cAAc,oBAAoB,CAAC,CAAC,CAAC,KAAG,CAAC,EAG/F,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rejected.d.ts","sourceRoot":"","sources":["../../src/rejected.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,KAAK,oBAAoB,CAAC,CAAC,CAAC,KAAG,GAAG,IAAI,qBAEjE,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from './types.ts';
|
|
2
|
-
/**
|
|
3
|
-
* Wraps a value in a Promise if it is not already one.
|
|
4
|
-
* @param value - A value that may or may not be a Promise.
|
|
5
|
-
* @returns A Promise resolving to the value.
|
|
6
|
-
*/
|
|
7
|
-
export declare function toPromise<T>(value: Promisable<T>): Promise<T>;
|
|
8
|
-
//# sourceMappingURL=toPromise.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toPromise.d.ts","sourceRoot":"","sources":["../../src/toPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE7D"}
|
package/dist/neutral/types.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { TypedValue } from '@xylabs/typeof';
|
|
2
|
-
import type { PromiseEx } from './PromiseEx.ts';
|
|
3
|
-
/** A value that may be a Promise, PromiseEx, or a plain synchronous value. */
|
|
4
|
-
export type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T;
|
|
5
|
-
/** A Promisable that resolves to an array. */
|
|
6
|
-
export type PromisableArray<T, V = never> = Promisable<T[], V>;
|
|
7
|
-
/** A Promisable that may resolve to undefined. */
|
|
8
|
-
export type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>;
|
|
9
|
-
/** A Promisable array where elements may be undefined. */
|
|
10
|
-
export type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>;
|
|
11
|
-
/** A Promisable that may resolve to null. */
|
|
12
|
-
export type NullablePromisable<T, V = never> = Promisable<T | null, V>;
|
|
13
|
-
/** A Promisable array where elements may be null. */
|
|
14
|
-
export type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>;
|
|
15
|
-
/** @description Used to document promises that are being used as Mutexes */
|
|
16
|
-
export type AsyncMutex<T> = Promise<T>;
|
|
17
|
-
/** An interface representing any thenable (promise-like) object. */
|
|
18
|
-
export interface PromiseType {
|
|
19
|
-
then: () => unknown;
|
|
20
|
-
}
|
|
21
|
-
/** Any non-promise typed value, excluding thenables. */
|
|
22
|
-
export type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
23
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,8EAA8E;AAC9E,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEvE,8CAA8C;AAC9C,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE9D,kDAAkD;AAClD,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;AAE3E,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;AAErF,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AAEtE,qDAAqD;AACrD,MAAM,MAAM,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AAEhF,4EAA4E;AAC5E,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAA;AAEtC,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,OAAO,CAAA;CACpB;AAED,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA"}
|