@naturalcycles/js-lib 14.200.0 → 14.201.0

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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Like AbortSignal, but it can "abort itself" via the `.abort()` method.
3
+ *
4
+ * Similar to how DeferredPromise is both a Promise and has `.resolve()` and `.reject()` methods.
5
+ *
6
+ * This is to simplify the AbortController/AbortSignal usage.
7
+ *
8
+ * Before this - you need to keep track of 2 things: AbortController and AbortSignal.
9
+ *
10
+ * After - you are good with only AbortableSignal, which can do both.
11
+ * And it's compatible with AbortSignal (because it extends it).
12
+ *
13
+ * @experimental
14
+ */
15
+ export interface AbortableSignal extends AbortSignal {
16
+ abort: AbortController['abort'];
17
+ }
18
+ /**
19
+ * Creates AbortableSignal,
20
+ * which is like AbortSignal, but can "abort itself" with `.abort()` method.
21
+ *
22
+ * @experimental
23
+ */
24
+ export declare function createAbortableSignal(): AbortableSignal;
package/dist/abort.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAbortableSignal = void 0;
4
+ /**
5
+ * Creates AbortableSignal,
6
+ * which is like AbortSignal, but can "abort itself" with `.abort()` method.
7
+ *
8
+ * @experimental
9
+ */
10
+ function createAbortableSignal() {
11
+ const ac = new AbortController();
12
+ return Object.assign(ac.signal, {
13
+ abort: ac.abort.bind(ac),
14
+ });
15
+ }
16
+ exports.createAbortableSignal = createAbortableSignal;
package/dist/index.d.ts CHANGED
@@ -81,6 +81,7 @@ export * from './env/buildInfo';
81
81
  export * from './form.util';
82
82
  export * from './semver';
83
83
  export * from './web';
84
+ export * from './abort';
84
85
  export * from './polyfill';
85
86
  export * from './zod/zod.util';
86
87
  export * from './zod/zod.shared.schemas';
package/dist/index.js CHANGED
@@ -85,6 +85,7 @@ tslib_1.__exportStar(require("./env/buildInfo"), exports);
85
85
  tslib_1.__exportStar(require("./form.util"), exports);
86
86
  tslib_1.__exportStar(require("./semver"), exports);
87
87
  tslib_1.__exportStar(require("./web"), exports);
88
+ tslib_1.__exportStar(require("./abort"), exports);
88
89
  tslib_1.__exportStar(require("./polyfill"), exports);
89
90
  tslib_1.__exportStar(require("./zod/zod.util"), exports);
90
91
  tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Creates AbortableSignal,
3
+ * which is like AbortSignal, but can "abort itself" with `.abort()` method.
4
+ *
5
+ * @experimental
6
+ */
7
+ export function createAbortableSignal() {
8
+ const ac = new AbortController();
9
+ return Object.assign(ac.signal, {
10
+ abort: ac.abort.bind(ac),
11
+ });
12
+ }
package/dist-esm/index.js CHANGED
@@ -81,6 +81,7 @@ export * from './env/buildInfo';
81
81
  export * from './form.util';
82
82
  export * from './semver';
83
83
  export * from './web';
84
+ export * from './abort';
84
85
  export * from './polyfill';
85
86
  export * from './zod/zod.util';
86
87
  export * from './zod/zod.shared.schemas';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.200.0",
3
+ "version": "14.201.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
package/src/abort.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Like AbortSignal, but it can "abort itself" via the `.abort()` method.
3
+ *
4
+ * Similar to how DeferredPromise is both a Promise and has `.resolve()` and `.reject()` methods.
5
+ *
6
+ * This is to simplify the AbortController/AbortSignal usage.
7
+ *
8
+ * Before this - you need to keep track of 2 things: AbortController and AbortSignal.
9
+ *
10
+ * After - you are good with only AbortableSignal, which can do both.
11
+ * And it's compatible with AbortSignal (because it extends it).
12
+ *
13
+ * @experimental
14
+ */
15
+ export interface AbortableSignal extends AbortSignal {
16
+ abort: AbortController['abort']
17
+ }
18
+
19
+ /**
20
+ * Creates AbortableSignal,
21
+ * which is like AbortSignal, but can "abort itself" with `.abort()` method.
22
+ *
23
+ * @experimental
24
+ */
25
+ export function createAbortableSignal(): AbortableSignal {
26
+ const ac = new AbortController()
27
+ return Object.assign(ac.signal, {
28
+ abort: ac.abort.bind(ac),
29
+ })
30
+ }
package/src/index.ts CHANGED
@@ -81,6 +81,7 @@ export * from './env/buildInfo'
81
81
  export * from './form.util'
82
82
  export * from './semver'
83
83
  export * from './web'
84
+ export * from './abort'
84
85
  export * from './polyfill'
85
86
  export * from './zod/zod.util'
86
87
  export * from './zod/zod.shared.schemas'