@homer0/extend-promise 2.0.5 → 2.0.7

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.
Files changed (2) hide show
  1. package/dist/index.d.mts +21 -0
  2. package/package.json +8 -8
@@ -0,0 +1,21 @@
1
+ type ExtractGeneric<Type> = Type extends Promise<infer X> ? X : never;
2
+ type ExtendedPromise<T extends Promise<unknown>, P, V = ExtractGeneric<T>> = Omit<T, 'then' | 'catch' | 'finally'> & P & {
3
+ then: (...args: Parameters<T['then']>) => ExtendedPromise<Promise<V>, P>;
4
+ catch: (...args: Parameters<T['catch']>) => ExtendedPromise<Promise<V>, P>;
5
+ finally: (...args: Parameters<T['finally']>) => ExtendedPromise<Promise<V>, P>;
6
+ };
7
+ /**
8
+ * Extends a {@link Promise} by injecting custom properties using a {@link Proxy}. The
9
+ * custom properties will be available on the promise chain no matter how many `then`s,
10
+ * `catch`s or `finally`s are added.
11
+ *
12
+ * @param promise The promise to extend.
13
+ * @param properties A dictionary of custom properties to _inject_ in the promise
14
+ * chain.
15
+ * @throws {Error} If `promise` is not a valid instance of {@link Promise}.
16
+ * @throws {Error} If `properties` is not an object or if it doesn't have any
17
+ * properties.
18
+ */
19
+ declare const extendPromise: <T extends Promise<unknown>, P extends Record<string, unknown>>(promise: T, properties: P) => ExtendedPromise<T, P, ExtractGeneric<T>>;
20
+
21
+ export { extendPromise };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@homer0/extend-promise",
3
3
  "description": "Extends a promise with custom properties",
4
- "version": "2.0.5",
4
+ "version": "2.0.7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/homer0/packages.git",
@@ -23,12 +23,12 @@
23
23
  "dist/"
24
24
  ],
25
25
  "devDependencies": {
26
- "@homer0/eslint-plugin": "10.3.1",
27
- "@homer0/tsconfig": "1.0.10",
28
- "jest": "^29.5.0",
29
- "ts-jest": "^29.1.0",
30
- "tsup": "^7.0.0",
31
- "typescript": "^5.1.3"
26
+ "@homer0/eslint-plugin": "11.0.0",
27
+ "@homer0/tsconfig": "1.0.11",
28
+ "jest": "^29.6.1",
29
+ "ts-jest": "^29.1.1",
30
+ "tsup": "^7.1.0",
31
+ "typescript": "^5.1.6"
32
32
  },
33
33
  "engine-strict": true,
34
34
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "build": "tsup src/index.ts",
45
45
  "prepublishOnly": "pnpm run build"
46
46
  },
47
- "gitHead": "05356cf2f7d8f158a139c3e2a3fed025f60bbaad"
47
+ "gitHead": "a5b49dc8388a52b256dabccd8c4f1c6e289d09a3"
48
48
  }