@xh/hoist 73.0.0-SNAPSHOT.1745618326968 → 73.0.0-SNAPSHOT.1745689122610

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.
@@ -18,7 +18,7 @@ declare global {
18
18
  * selector will be handled by this method.
19
19
  * @param fn - catch handler
20
20
  */
21
- catchWhen<TResult = undefined>(selector: ((e: any) => boolean) | Some<string>, fn?: (reason: any) => Awaitable<TResult>): Promise<T | TResult>;
21
+ catchWhen<TResult = undefined>(selector: ((e: unknown) => boolean) | Some<string>, fn?: (reason: unknown) => Awaitable<TResult>): Promise<T | TResult>;
22
22
  /**
23
23
  * Version of `catch()` that passes the error onto Hoist's default exception handler for
24
24
  * convention-driven logging and alerting. Typically called last in a Promise chain.
@@ -27,7 +27,7 @@ declare global {
27
27
  /**
28
28
  * Version of `catchDefault()` that will only catch certain exceptions.
29
29
  */
30
- catchDefaultWhen(selector: ((e: any) => boolean) | Some<string>, options: ExceptionHandlerOptions): Promise<T | undefined>;
30
+ catchDefaultWhen(selector: ((e: unknown) => boolean) | Some<string>, options: ExceptionHandlerOptions): Promise<T | undefined>;
31
31
  /**
32
32
  * Wait on a potentially async function before passing on the original value.
33
33
  * Useful when we want to block and do something on the promise chain, but do not want to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "73.0.0-SNAPSHOT.1745618326968",
3
+ "version": "73.0.0-SNAPSHOT.1745689122610",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",
@@ -39,8 +39,8 @@ declare global {
39
39
  * @param fn - catch handler
40
40
  */
41
41
  catchWhen<TResult = undefined>(
42
- selector: ((e: any) => boolean) | Some<string>,
43
- fn?: (reason: any) => Awaitable<TResult>
42
+ selector: ((e: unknown) => boolean) | Some<string>,
43
+ fn?: (reason: unknown) => Awaitable<TResult>
44
44
  ): Promise<T | TResult>;
45
45
 
46
46
  /**
@@ -53,7 +53,7 @@ declare global {
53
53
  * Version of `catchDefault()` that will only catch certain exceptions.
54
54
  */
55
55
  catchDefaultWhen(
56
- selector: ((e: any) => boolean) | Some<string>,
56
+ selector: ((e: unknown) => boolean) | Some<string>,
57
57
  options: ExceptionHandlerOptions
58
58
  ): Promise<T | undefined>;
59
59
 
@@ -169,43 +169,63 @@ export function never<T>(): Promise<T> {
169
169
  //--------------------------------
170
170
  const enhancePromise = promisePrototype => {
171
171
  Object.assign(promisePrototype, {
172
- thenAction(fn) {
172
+ thenAction<T, TResult>(fn: (value: T) => Awaitable<TResult>): Promise<TResult> {
173
173
  return this.then(action(fn));
174
174
  },
175
175
 
176
- catchWhen(selector, fn) {
177
- return this.catch(e => {
176
+ catchWhen<T, TResult = undefined>(
177
+ selector: ((e: unknown) => boolean) | Some<string>,
178
+ fn?: (reason: unknown) => Awaitable<TResult>
179
+ ): Promise<T | TResult> {
180
+ return this.catch((e: unknown) => {
178
181
  this.throwIfFailsSelector(e, selector);
179
182
  return fn ? fn(e) : undefined;
180
183
  });
181
184
  },
182
185
 
183
- catchDefault(options) {
184
- return this.catch(e => XH.handleException(e, options));
186
+ catchDefault<T>(options?: ExceptionHandlerOptions): Promise<T | undefined> {
187
+ return this.catch((e: unknown) => XH.handleException(e, options));
185
188
  },
186
189
 
187
- catchDefaultWhen(selector, options) {
188
- return this.catch(e => {
190
+ catchDefaultWhen<T>(
191
+ selector: ((e: unknown) => boolean) | Some<string>,
192
+ options: ExceptionHandlerOptions
193
+ ): Promise<T | undefined> {
194
+ return this.catch((e: unknown) => {
189
195
  this.throwIfFailsSelector(e, selector);
190
196
  return XH.handleException(e, options);
191
197
  });
192
198
  },
193
199
 
194
- track(options) {
195
- if (!options || (isFunction(options.omit) ? options.omit() : options.omit)) return this;
196
- if (isString(options)) options = {message: options};
197
-
198
- const startTime = Date.now();
199
- return this.finally(() => {
200
- XH.track({
201
- timestamp: startTime,
202
- elapsed: Date.now() - startTime,
203
- ...options
204
- });
205
- });
200
+ track<T>(options: TrackOptions | string): Promise<T> {
201
+ if (!options) return this;
202
+
203
+ const startTime = Date.now(),
204
+ doTrack = (isError: boolean) => {
205
+ const opts: TrackOptions = isString(options)
206
+ ? {message: options}
207
+ : {...options};
208
+
209
+ opts.timestamp = startTime;
210
+ opts.elapsed = Date.now() - startTime;
211
+ if (isError) opts.severity = 'ERROR';
212
+
213
+ XH.track(opts);
214
+ };
215
+
216
+ return this.then(
217
+ (v: T) => {
218
+ doTrack(true);
219
+ return v;
220
+ },
221
+ (t: unknown) => {
222
+ doTrack(false);
223
+ throw t;
224
+ }
225
+ );
206
226
  },
207
227
 
208
- tap(onFulfillment) {
228
+ tap<T>(onFulfillment: (value: T) => any): Promise<T> {
209
229
  let ret = null;
210
230
  const resolveFn = data => {
211
231
  ret = data;
@@ -215,7 +235,7 @@ const enhancePromise = promisePrototype => {
215
235
  return this.then(resolveFn).then(() => ret);
216
236
  },
217
237
 
218
- wait(interval) {
238
+ wait<T>(interval: number): Promise<T> {
219
239
  return this.finally(() => wait(interval));
220
240
  },
221
241
 
@@ -252,7 +272,7 @@ const enhancePromise = promisePrototype => {
252
272
  //--------------------------------
253
273
  // Implementation
254
274
  //--------------------------------
255
- throwIfFailsSelector(e, selector) {
275
+ throwIfFailsSelector(e: any, selector: any) {
256
276
  const fn = isFunction(selector) ? selector : e => castArray(selector).includes(e.name);
257
277
  if (!fn(e)) throw e;
258
278
  }