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

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: unknown) => boolean) | Some<string>, fn?: (reason: unknown) => Awaitable<TResult>): Promise<T | TResult>;
21
+ catchWhen<TResult = undefined>(selector: ((e: any) => boolean) | Some<string>, fn?: (reason: any) => 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: unknown) => boolean) | Some<string>, options: ExceptionHandlerOptions): Promise<T | undefined>;
30
+ catchDefaultWhen(selector: ((e: any) => 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.1745589992773",
3
+ "version": "73.0.0-SNAPSHOT.1745618326968",
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",
@@ -12,13 +12,11 @@ import {
12
12
  TrackOptions,
13
13
  XH,
14
14
  Some,
15
- Awaitable,
16
- TimeoutExceptionConfig
15
+ Awaitable
17
16
  } from '@xh/hoist/core';
18
17
  import {action} from '@xh/hoist/mobx';
19
18
  import {olderThan, SECONDS} from '@xh/hoist/utils/datetime';
20
19
  import {castArray, isFunction, isNumber, isString} from 'lodash';
21
- import {isOmitted} from '@xh/hoist/utils/impl';
22
20
 
23
21
  /**
24
22
  * Enhancements to the Global Promise object.
@@ -41,8 +39,8 @@ declare global {
41
39
  * @param fn - catch handler
42
40
  */
43
41
  catchWhen<TResult = undefined>(
44
- selector: ((e: unknown) => boolean) | Some<string>,
45
- fn?: (reason: unknown) => Awaitable<TResult>
42
+ selector: ((e: any) => boolean) | Some<string>,
43
+ fn?: (reason: any) => Awaitable<TResult>
46
44
  ): Promise<T | TResult>;
47
45
 
48
46
  /**
@@ -55,7 +53,7 @@ declare global {
55
53
  * Version of `catchDefault()` that will only catch certain exceptions.
56
54
  */
57
55
  catchDefaultWhen(
58
- selector: ((e: unknown) => boolean) | Some<string>,
56
+ selector: ((e: any) => boolean) | Some<string>,
59
57
  options: ExceptionHandlerOptions
60
58
  ): Promise<T | undefined>;
61
59
 
@@ -171,63 +169,43 @@ export function never<T>(): Promise<T> {
171
169
  //--------------------------------
172
170
  const enhancePromise = promisePrototype => {
173
171
  Object.assign(promisePrototype, {
174
- thenAction<T, TResult>(fn: (value: T) => Awaitable<TResult>): Promise<TResult> {
172
+ thenAction(fn) {
175
173
  return this.then(action(fn));
176
174
  },
177
175
 
178
- catchWhen<T, TResult = undefined>(
179
- selector: ((e: unknown) => boolean) | Some<string>,
180
- fn?: (reason: unknown) => Awaitable<TResult>
181
- ): Promise<T | TResult> {
182
- return this.catch((e: unknown) => {
176
+ catchWhen(selector, fn) {
177
+ return this.catch(e => {
183
178
  this.throwIfFailsSelector(e, selector);
184
179
  return fn ? fn(e) : undefined;
185
180
  });
186
181
  },
187
182
 
188
- catchDefault<T>(options?: ExceptionHandlerOptions): Promise<T | undefined> {
189
- return this.catch((e: unknown) => XH.handleException(e, options));
183
+ catchDefault(options) {
184
+ return this.catch(e => XH.handleException(e, options));
190
185
  },
191
186
 
192
- catchDefaultWhen<T>(
193
- selector: ((e: unknown) => boolean) | Some<string>,
194
- options: ExceptionHandlerOptions
195
- ): Promise<T | undefined> {
196
- return this.catch((e: unknown) => {
187
+ catchDefaultWhen(selector, options) {
188
+ return this.catch(e => {
197
189
  this.throwIfFailsSelector(e, selector);
198
190
  return XH.handleException(e, options);
199
191
  });
200
192
  },
201
193
 
202
- track<T>(options: TrackOptions | string): Promise<T> {
203
- if (!options) return this;
204
-
205
- const startTime = Date.now(),
206
- doTrack = (isError: boolean) => {
207
- const opts: TrackOptions = isString(options)
208
- ? {message: options}
209
- : {...options};
210
-
211
- opts.timestamp = startTime;
212
- opts.elapsed = Date.now() - startTime;
213
- if (isError) opts.severity = 'ERROR';
214
-
215
- XH.track(opts);
216
- };
217
-
218
- return this.then(
219
- (v: T) => {
220
- doTrack(true);
221
- return v;
222
- },
223
- (t: unknown) => {
224
- doTrack(false);
225
- throw t;
226
- }
227
- );
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
+ });
228
206
  },
229
207
 
230
- tap<T>(onFulfillment: (value: T) => any): Promise<T> {
208
+ tap(onFulfillment) {
231
209
  let ret = null;
232
210
  const resolveFn = data => {
233
211
  ret = data;
@@ -237,14 +215,13 @@ const enhancePromise = promisePrototype => {
237
215
  return this.then(resolveFn).then(() => ret);
238
216
  },
239
217
 
240
- wait<T>(interval: number): Promise<T> {
218
+ wait(interval) {
241
219
  return this.finally(() => wait(interval));
242
220
  },
243
221
 
244
- timeout<T>(spec: PromiseTimeoutSpec): Promise<T> {
245
- if (spec == null) return this;
246
-
247
- const config: TimeoutExceptionConfig = isNumber(spec) ? {interval: spec} : spec;
222
+ timeout(config) {
223
+ if (config == null) return this;
224
+ if (isNumber(config)) config = {interval: config};
248
225
  const interval = config.interval;
249
226
 
250
227
  let completed = false;
@@ -259,14 +236,14 @@ const enhancePromise = promisePrototype => {
259
236
  return Promise.race([deadline, promise]);
260
237
  },
261
238
 
262
- linkTo<T>(cfg: PromiseLinkSpec): Promise<T> {
239
+ linkTo(cfg) {
263
240
  if (!cfg) return this;
264
241
 
265
- if (cfg instanceof TaskObserver) {
242
+ if (cfg.isTaskObserver) {
266
243
  cfg = {observer: cfg};
267
244
  }
268
245
 
269
- if (cfg.observer && !isOmitted(cfg)) {
246
+ if (cfg.observer && !(isFunction(cfg.omit) ? cfg.omit() : cfg.omit)) {
270
247
  cfg.observer.linkTo(TaskObserver.forPromise({promise: this, message: cfg.message}));
271
248
  }
272
249
  return this;
@@ -275,7 +252,7 @@ const enhancePromise = promisePrototype => {
275
252
  //--------------------------------
276
253
  // Implementation
277
254
  //--------------------------------
278
- throwIfFailsSelector(e: any, selector: any) {
255
+ throwIfFailsSelector(e, selector) {
279
256
  const fn = isFunction(selector) ? selector : e => castArray(selector).includes(e.name);
280
257
  if (!fn(e)) throw e;
281
258
  }