@fbltd/async 1.0.14 → 1.0.16

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 (29) hide show
  1. package/README.md +8 -10
  2. package/dist/bin/constants.js +1 -4
  3. package/dist/bin/delay.js +3 -6
  4. package/dist/bin/dependency-stream/contracts.js +1 -2
  5. package/dist/bin/dependency-stream/dependency-stream.js +6 -10
  6. package/dist/bin/dependency-stream/index.js +4 -20
  7. package/dist/bin/dependency-stream/integrations/index.js +1 -17
  8. package/dist/bin/dependency-stream/integrations/react/index.js +1 -1
  9. package/dist/bin/dependency-stream/integrations/react/src/index.js +1 -1
  10. package/dist/bin/dependency-stream/utils/index.js +3 -19
  11. package/dist/bin/dependency-stream/utils/next.js +4 -8
  12. package/dist/bin/dependency-stream/utils/once.stream.js +6 -9
  13. package/dist/bin/dependency-stream/utils/race.stream.js +6 -9
  14. package/dist/bin/get-promise.js +28 -30
  15. package/dist/bin/index.js +4 -20
  16. package/dist/types/dependency-stream/dependency-stream.d.ts +3 -3
  17. package/dist/types/dependency-stream/index.d.ts +4 -4
  18. package/dist/types/dependency-stream/integrations/index.d.ts +1 -1
  19. package/dist/types/dependency-stream/integrations/react/index.d.ts +1 -1
  20. package/dist/types/dependency-stream/integrations/react/src/index.d.ts +1 -1
  21. package/dist/types/dependency-stream/utils/index.d.ts +3 -3
  22. package/dist/types/dependency-stream/utils/next.d.ts +5 -1
  23. package/dist/types/dependency-stream/utils/once.stream.d.ts +2 -2
  24. package/dist/types/dependency-stream/utils/race.stream.d.ts +2 -2
  25. package/dist/types/get-promise.d.ts +11 -8
  26. package/dist/types/index.d.ts +4 -4
  27. package/package.json +3 -2
  28. package/tsconfig.base.json +1 -0
  29. package/tsconfig.json +2 -3
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Async tools
2
-
3
- ## Disclaimer
4
- Now this package is CommonJS module but should be an ESM.
2
+ R&D async tools tree-shakable ES module
5
3
 
6
4
  ## Installation
7
5
  You can install this package with your favorite package manager.<br/>
@@ -21,15 +19,15 @@ await delay(number);
21
19
  delay(number, 'sync');
22
20
  ```
23
21
 
24
- ### getPromise
25
- getPromise is a function that creates and returns promise, its fulfillment functions
26
- and status flags.
27
- Returned type is:
22
+ ### PromiseConfiguration
23
+ PromiseConfiguration is a class that creates and provide promise,
24
+ its fulfillment functions and status flags.
25
+ Instance of the class is represented by the following type:
28
26
  ```typescript
29
27
  type IPromiseConfiguration<T> = {
30
- resolve(arg: T): void, // function that resolves promise
31
- reject(err: Error): void, // function that rejects promise
32
- promise: Promise<T>, // promise itself
28
+ readonly resolve: (arg: T) => void, // function that resolves promise
29
+ readonly reject: (err: Error) => void, // function that rejects promise
30
+ readonly promise: Promise<T>, // promise itself
33
31
  readonly isPending: boolean, // promise status flag
34
32
  readonly isFulfilled: boolean, // reverted promise status flag
35
33
  }
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.symAI = void 0;
4
- exports.symAI = Symbol.asyncIterator;
1
+ export const symAI = Symbol.asyncIterator;
package/dist/bin/delay.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.delay = delay;
4
- const get_promise_1 = require("./get-promise");
5
- function delay(ms = 0, syncKey) {
1
+ import { PromiseConfiguration } from "./get-promise.js";
2
+ export function delay(ms = 0, syncKey) {
6
3
  ms = Math.max(ms, 0);
7
4
  return delay.methods[typeof syncKey](ms);
8
5
  }
@@ -17,7 +14,7 @@ Object.defineProperty(delay, 'methods', {
17
14
  }
18
15
  },
19
16
  undefined: (ms) => {
20
- const { promise, resolve } = (0, get_promise_1.getPromise)();
17
+ const { promise, resolve } = new PromiseConfiguration();
21
18
  setTimeout(() => {
22
19
  resolve();
23
20
  }, ms);
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DependencyStream = void 0;
4
- const get_promise_1 = require("../get-promise");
1
+ import { PromiseConfiguration } from "../get-promise.js";
5
2
  function baseComparer(prev, cur) {
6
3
  return prev === cur;
7
4
  }
8
- class DependencyStream {
5
+ export class DependencyStream {
9
6
  _value;
10
7
  reactionPromise;
11
- abortPromise = (0, get_promise_1.getPromise)();
8
+ abortPromise = new PromiseConfiguration();
12
9
  config;
13
10
  constructor(_value, config = {}) {
14
11
  this._value = _value;
@@ -40,7 +37,7 @@ class DependencyStream {
40
37
  let firstPromise;
41
38
  const withReactionOnSubscribe = this.config.withReactionOnSubscribe || thisStreamConfig.withReactionOnSubscribe;
42
39
  if (withReactionOnSubscribe) {
43
- firstPromise = (0, get_promise_1.getPromise)();
40
+ firstPromise = new PromiseConfiguration();
44
41
  firstPromise.resolve(this.value);
45
42
  externalPromises.push(firstPromise.promise);
46
43
  }
@@ -57,7 +54,7 @@ class DependencyStream {
57
54
  },
58
55
  next: async () => {
59
56
  if (!this.reactionPromise) {
60
- this.reactionPromise = (0, get_promise_1.getPromise)();
57
+ this.reactionPromise = new PromiseConfiguration();
61
58
  this._set(this._value);
62
59
  }
63
60
  await Promise.race([
@@ -83,8 +80,7 @@ class DependencyStream {
83
80
  }
84
81
  dispose() {
85
82
  this.abortPromise.resolve();
86
- this.abortPromise = (0, get_promise_1.getPromise)();
83
+ this.abortPromise = new PromiseConfiguration();
87
84
  this.reactionPromise = undefined;
88
85
  }
89
86
  }
90
- exports.DependencyStream = DependencyStream;
@@ -1,20 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./dependency-stream"), exports);
18
- __exportStar(require("./utils"), exports);
19
- __exportStar(require("./integrations"), exports);
20
- __exportStar(require("./contracts"), exports);
1
+ export * from "./dependency-stream.js";
2
+ export * from "./utils/index.js";
3
+ export * from "./integrations/index.js";
4
+ export * from "./contracts.js";
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./react"), exports);
1
+ export * from "./react/index.js";
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src"), exports);
17
+ __exportStar(require("./src/index.js"), exports);
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./use-stream"), exports);
17
+ __exportStar(require("./use-stream.js"), exports);
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./once.stream"), exports);
18
- __exportStar(require("./race.stream"), exports);
19
- __exportStar(require("./next"), exports);
1
+ export * from "./once.stream.js";
2
+ export * from "./race.stream.js";
3
+ export * from "./next.js";
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternalStreamFinishError = void 0;
4
- exports.next = next;
5
- const constants_1 = require("../../constants");
1
+ import { symAI } from "../../constants.js";
6
2
  const StreamFinishError = new Error("Stream is done");
7
- async function next(dep) {
8
- const res = await dep[constants_1.symAI]().next();
3
+ export async function next(dep) {
4
+ const res = await dep[symAI]().next();
9
5
  if (res.done) {
10
6
  throw StreamFinishError;
11
7
  }
@@ -14,4 +10,4 @@ async function next(dep) {
14
10
  /**
15
11
  * @internal
16
12
  */
17
- exports.InternalStreamFinishError = StreamFinishError;
13
+ export const InternalStreamFinishError = StreamFinishError;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onceStream = onceStream;
4
- const get_promise_1 = require("../../get-promise");
5
- const constants_1 = require("../../constants");
6
- function onceStream(dep) {
7
- const externalDispose = (0, get_promise_1.getPromise)();
8
- const iterator = dep[constants_1.symAI]({ externalDispose });
1
+ import { PromiseConfiguration } from "../../get-promise.js";
2
+ import { symAI } from "../../constants.js";
3
+ export function onceStream(dep) {
4
+ const externalDispose = new PromiseConfiguration();
5
+ const iterator = dep[symAI]({ externalDispose });
9
6
  function isDisposed() {
10
7
  return externalDispose.isFulfilled || iterator.isDisposed;
11
8
  }
@@ -14,7 +11,7 @@ function onceStream(dep) {
14
11
  return isDisposed();
15
12
  },
16
13
  dispose: externalDispose.resolve,
17
- [constants_1.symAI]() {
14
+ [symAI]() {
18
15
  return {
19
16
  next: async () => {
20
17
  const result = await iterator.next();
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.raceStream = raceStream;
4
- const constants_1 = require("../../constants");
5
- const get_promise_1 = require("../../get-promise");
6
- function raceStream(...deps) {
7
- let selfDisposePromise = (0, get_promise_1.getPromise)();
1
+ import { symAI } from "../../constants.js";
2
+ import { PromiseConfiguration } from "../../get-promise.js";
3
+ export function raceStream(...deps) {
4
+ let selfDisposePromise = new PromiseConfiguration();
8
5
  let isDisposed = false;
9
- const streams = deps.map((dep) => dep[constants_1.symAI]({
6
+ const streams = deps.map((dep) => dep[symAI]({
10
7
  externalDispose: selfDisposePromise
11
8
  }));
12
9
  return {
@@ -14,7 +11,7 @@ function raceStream(...deps) {
14
11
  get isDisposed() {
15
12
  return isDisposed;
16
13
  },
17
- [constants_1.symAI]() {
14
+ [symAI]() {
18
15
  return {
19
16
  next: async () => {
20
17
  const res = await Promise.race([selfDisposePromise.promise, ...streams.map(s => s.next())]);
@@ -1,32 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPromise = getPromise;
4
- function getPromise() {
5
- let resolve;
6
- let reject;
7
- let isPending = true;
8
- let isFulfilled = false;
9
- const promise = new Promise((res, rej) => {
10
- resolve = ((value) => {
11
- res(value);
12
- isPending = false;
13
- isFulfilled = true;
1
+ export class PromiseConfiguration {
2
+ promise;
3
+ _resolve;
4
+ _reject;
5
+ _isFulfilled = false;
6
+ constructor() {
7
+ this.promise = new Promise((res, rej) => {
8
+ this._resolve = ((value) => {
9
+ res(value);
10
+ this._isFulfilled = true;
11
+ });
12
+ this._reject = (error) => {
13
+ rej(error);
14
+ this._isFulfilled = true;
15
+ };
14
16
  });
15
- reject = (error) => {
16
- rej(error);
17
- isPending = false;
18
- isFulfilled = true;
19
- };
20
- });
21
- return {
22
- resolve,
23
- reject,
24
- get isPending() {
25
- return isPending;
26
- },
27
- get isFulfilled() {
28
- return isFulfilled;
29
- },
30
- promise
31
- };
17
+ }
18
+ get reject() {
19
+ return this._reject;
20
+ }
21
+ get resolve() {
22
+ return this._resolve;
23
+ }
24
+ get isFulfilled() {
25
+ return this._isFulfilled;
26
+ }
27
+ get isPending() {
28
+ return !this.isFulfilled;
29
+ }
32
30
  }
package/dist/bin/index.js CHANGED
@@ -1,20 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./dependency-stream"), exports);
18
- __exportStar(require("./dependency-stream/integrations/react"), exports);
19
- __exportStar(require("./delay"), exports);
20
- __exportStar(require("./get-promise"), exports);
1
+ export * from "./dependency-stream/index.js";
2
+ export * from "./dependency-stream/integrations/react/index.js";
3
+ export * from "./delay.js";
4
+ export * from "./get-promise.js";
@@ -1,5 +1,5 @@
1
- import { IPromiseConfiguration } from "../get-promise";
2
- import { IIteratorOwner, IStreamIterator } from "./contracts";
1
+ import { IIteratorOwner, IStreamIterator } from "./contracts.ts";
2
+ import { PromiseConfiguration } from "../get-promise.ts";
3
3
  interface IIsEquals<T> {
4
4
  (prev: T, cur: T): boolean;
5
5
  }
@@ -9,7 +9,7 @@ type IAllStreamConfig<T> = {
9
9
  };
10
10
  type IThisStreamConfig = Partial<{
11
11
  withReactionOnSubscribe: boolean;
12
- externalDispose: IPromiseConfiguration<any>;
12
+ externalDispose: PromiseConfiguration<any>;
13
13
  }>;
14
14
  export declare class DependencyStream<T = any> implements IIteratorOwner<T> {
15
15
  private _value;
@@ -1,4 +1,4 @@
1
- export * from './dependency-stream';
2
- export * from './utils';
3
- export * from './integrations';
4
- export * from './contracts';
1
+ export * from './dependency-stream.ts';
2
+ export * from './utils/index.ts';
3
+ export * from './integrations/index.ts';
4
+ export * from './contracts.ts';
@@ -1 +1 @@
1
- export * from './react';
1
+ export * from './react/index.ts';
@@ -1 +1 @@
1
- export * from './src';
1
+ export * from './src/index.ts';
@@ -1 +1 @@
1
- export * from './use-stream';
1
+ export * from './use-stream.ts';
@@ -1,3 +1,3 @@
1
- export * from "./once.stream";
2
- export * from "./race.stream";
3
- export * from "./next";
1
+ export * from "./once.stream.ts";
2
+ export * from "./race.stream.ts";
3
+ export * from "./next.ts";
@@ -1,2 +1,6 @@
1
- import { DependencyStream } from "../dependency-stream";
1
+ import { DependencyStream } from "../dependency-stream.ts";
2
2
  export declare function next<T>(dep: DependencyStream<T>): Promise<T>;
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const InternalStreamFinishError: Error;
@@ -1,3 +1,3 @@
1
- import { DependencyStream } from "../dependency-stream";
2
- import { IStreamOwner } from "../contracts";
1
+ import { DependencyStream } from "../dependency-stream.ts";
2
+ import { IStreamOwner } from "../contracts.ts";
3
3
  export declare function onceStream<T>(dep: DependencyStream<T>): IStreamOwner<T>;
@@ -1,5 +1,5 @@
1
- import { DependencyStream } from "../dependency-stream";
2
- import { symAI } from "../../constants";
1
+ import { DependencyStream } from "../dependency-stream.ts";
2
+ import { symAI } from "../../constants.ts";
3
3
  export declare function raceStream<TArray extends DependencyStream[]>(...deps: NoInfer<TArray>): {
4
4
  dispose: () => void;
5
5
  readonly isDisposed: boolean;
@@ -1,8 +1,11 @@
1
- export declare function getPromise<TReturn = void>(): {
2
- resolve: (value: TReturn) => void;
3
- reject: (value: Error) => void;
4
- readonly isPending: boolean;
5
- readonly isFulfilled: boolean;
6
- promise: Promise<TReturn>;
7
- };
8
- export type IPromiseConfiguration<T = void> = ReturnType<typeof getPromise<T>>;
1
+ export declare class PromiseConfiguration<TReturn = void> {
2
+ readonly promise: Promise<TReturn>;
3
+ _resolve: (value: TReturn) => void;
4
+ _reject: (value: Error) => void;
5
+ _isFulfilled: boolean;
6
+ constructor();
7
+ get reject(): (value: Error) => void;
8
+ get resolve(): (value: TReturn) => void;
9
+ get isFulfilled(): boolean;
10
+ get isPending(): boolean;
11
+ }
@@ -1,4 +1,4 @@
1
- export * from './dependency-stream';
2
- export * from './dependency-stream/integrations/react';
3
- export * from './delay';
4
- export * from './get-promise';
1
+ export * from './dependency-stream/index.ts';
2
+ export * from './dependency-stream/integrations/react/index.ts';
3
+ export * from './delay.ts';
4
+ export * from './get-promise.ts';
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@fbltd/async",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Miscellaneous async utils",
5
5
  "homepage": "https://github.com/GlennMiller1991/async",
6
+ "type": "module",
6
7
  "keywords": [
7
8
  "Reactivity",
8
9
  "State Management",
@@ -24,7 +25,7 @@
24
25
  "clearModules": "rm node_modules -rf || true",
25
26
  "clearAll": "npm run clearDist && npm run clearModules",
26
27
  "build": "cd src/dependency-stream/integrations/react && npm run build && cd ../../../../ && npm run clearAll && npm i && mkdir dist && tsc",
27
- "test": "jest --config=./__tests__/jest.config.js",
28
+ "test": "jest --config=./__tests__/jest.config.cjs",
28
29
  "postVersionCommit": "git commit -m='post version commit' || true",
29
30
  "postVersionPush": "git push || true",
30
31
  "patch": "npm version patch && npm run postVersionCommit && npm run postVersionPush",
@@ -17,6 +17,7 @@
17
17
  "allowJs": false,
18
18
 
19
19
  // emit
20
+ "rewriteRelativeImportExtensions": true,
20
21
  "target": "ESNext",
21
22
  "noEmitOnError": true,
22
23
  "removeComments": false,
package/tsconfig.json CHANGED
@@ -2,9 +2,8 @@
2
2
  {
3
3
  "extends": "./tsconfig.base.json",
4
4
  "compilerOptions": {
5
- "module": "CommonJS",
6
- "moduleResolution": "node",
7
- "stripInternal": true,
5
+ "module": "NodeNext",
6
+ "moduleResolution": "NodeNext",
8
7
  },
9
8
  }
10
9
  // @formatter:on