@modern-js/plugin 1.3.3 → 1.3.6

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 (71) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +74 -0
  3. package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +12 -0
  4. package/dist/js/modern/farrow-pipeline/context.js +99 -0
  5. package/dist/js/modern/farrow-pipeline/counter.js +18 -0
  6. package/dist/js/modern/farrow-pipeline/hook.js +42 -0
  7. package/dist/js/modern/farrow-pipeline/index.js +19 -0
  8. package/dist/js/modern/farrow-pipeline/pipeline.js +93 -0
  9. package/dist/js/modern/index.js +1 -1
  10. package/dist/js/modern/manager/async.js +1 -1
  11. package/dist/js/modern/manager/runner.js +1 -1
  12. package/dist/js/modern/manager/sync.js +1 -1
  13. package/dist/js/modern/waterfall/async.js +3 -5
  14. package/dist/js/modern/waterfall/sync.js +3 -5
  15. package/dist/js/modern/workflow/async.js +2 -2
  16. package/dist/js/modern/workflow/parallel.js +2 -2
  17. package/dist/js/modern/workflow/sync.js +2 -2
  18. package/dist/js/node/farrow-pipeline/asyncHooks.node.js +93 -0
  19. package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +26 -0
  20. package/dist/js/node/farrow-pipeline/context.js +120 -0
  21. package/dist/js/node/farrow-pipeline/counter.js +27 -0
  22. package/dist/js/node/farrow-pipeline/hook.js +52 -0
  23. package/dist/js/node/farrow-pipeline/index.js +18 -0
  24. package/dist/js/node/farrow-pipeline/pipeline.js +129 -0
  25. package/dist/js/node/index.js +1 -1
  26. package/dist/js/node/manager/async.js +1 -1
  27. package/dist/js/node/manager/runner.js +1 -1
  28. package/dist/js/node/manager/sync.js +1 -1
  29. package/dist/js/node/waterfall/async.js +3 -5
  30. package/dist/js/node/waterfall/sync.js +3 -5
  31. package/dist/js/node/workflow/async.js +2 -2
  32. package/dist/js/node/workflow/parallel.js +2 -2
  33. package/dist/js/node/workflow/sync.js +2 -2
  34. package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +74 -0
  35. package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +12 -0
  36. package/dist/js/treeshaking/farrow-pipeline/context.js +103 -0
  37. package/dist/js/treeshaking/farrow-pipeline/counter.js +23 -0
  38. package/dist/js/treeshaking/farrow-pipeline/hook.js +46 -0
  39. package/dist/js/treeshaking/farrow-pipeline/index.js +19 -0
  40. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +100 -0
  41. package/dist/js/treeshaking/index.js +1 -1
  42. package/dist/js/treeshaking/manager/async.js +8 -29
  43. package/dist/js/treeshaking/manager/runner.js +1 -1
  44. package/dist/js/treeshaking/manager/sync.js +5 -23
  45. package/dist/js/treeshaking/waterfall/async.js +10 -31
  46. package/dist/js/treeshaking/waterfall/sync.js +6 -23
  47. package/dist/js/treeshaking/workflow/async.js +12 -32
  48. package/dist/js/treeshaking/workflow/parallel.js +9 -28
  49. package/dist/js/treeshaking/workflow/sync.js +9 -28
  50. package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +2 -0
  51. package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +19 -0
  52. package/dist/types/farrow-pipeline/context.d.ts +28 -0
  53. package/dist/types/farrow-pipeline/counter.d.ts +11 -0
  54. package/dist/types/farrow-pipeline/hook.d.ts +9 -0
  55. package/dist/types/farrow-pipeline/index.d.ts +19 -0
  56. package/dist/types/farrow-pipeline/pipeline.d.ts +38 -0
  57. package/dist/types/index.d.ts +1 -1
  58. package/dist/types/manager/runner.d.ts +1 -1
  59. package/dist/types/manager/sync.d.ts +1 -1
  60. package/dist/types/manager/types.d.ts +1 -1
  61. package/dist/types/waterfall/async.d.ts +1 -1
  62. package/dist/types/waterfall/sync.d.ts +1 -1
  63. package/dist/types/workflow/async.d.ts +1 -1
  64. package/dist/types/workflow/sync.d.ts +1 -1
  65. package/package.json +37 -8
  66. package/.eslintrc.js +0 -8
  67. package/jest.config.js +0 -7
  68. package/modern.config.js +0 -2
  69. package/node.d.ts +0 -1
  70. package/node.js +0 -1
  71. package/tsconfig.json +0 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 1.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - a1198d509: feat: bump babel 7.18.0
8
+
9
+ ## 1.3.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 54fa1dbd6: fix(plugin): allow multiple versions to be installed
14
+
15
+ ## 1.3.4
16
+
17
+ ### Patch Changes
18
+
19
+ - d5913bd96: feat: fork farrow-pipeline to remove tslib and reduce bundle size
20
+ - d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
21
+
3
22
  ## 1.3.3
4
23
 
5
24
  ### Patch Changes
@@ -0,0 +1,74 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ import NodeAsyncHooks from 'async_hooks';
6
+ import * as asyncHooksInterface from "./asyncHooksInterface";
7
+
8
+ const createAsyncHooks = () => {
9
+ const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
10
+
11
+ const hooks = NodeAsyncHooks.createHook({
12
+ init: (asyncId, _, triggerAsyncId) => {
13
+ if (store.has(triggerAsyncId)) {
14
+ const value = store.get(triggerAsyncId);
15
+
16
+ if (value) {
17
+ store.set(asyncId, value);
18
+ }
19
+ }
20
+ },
21
+ destroy: asyncId => {
22
+ if (store.has(asyncId)) {
23
+ store.delete(asyncId);
24
+ }
25
+ }
26
+ });
27
+
28
+ const set = value => {
29
+ store.set(NodeAsyncHooks.executionAsyncId(), value);
30
+ };
31
+
32
+ const get = () => {
33
+ return store.get(NodeAsyncHooks.executionAsyncId());
34
+ };
35
+
36
+ const clear = () => {
37
+ store.clear();
38
+ };
39
+
40
+ const enable = () => {
41
+ hooks.enable();
42
+ };
43
+
44
+ const disable = () => {
45
+ hooks.disable();
46
+ store.clear();
47
+ };
48
+
49
+ const entries = () => {
50
+ return store.entries();
51
+ };
52
+
53
+ return {
54
+ enable,
55
+ disable,
56
+ set,
57
+ get,
58
+ clear,
59
+ entries
60
+ };
61
+ };
62
+
63
+ export const enable = () => {
64
+ const hooks = createAsyncHooks();
65
+ disable();
66
+ asyncHooksInterface.impl(hooks);
67
+ hooks.enable();
68
+ };
69
+ export const disable = () => {
70
+ var _asyncHooksInterface$;
71
+
72
+ (_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
73
+ asyncHooksInterface.reset();
74
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ // eslint-disable-next-line import/no-mutable-exports
6
+ export let asyncHooks;
7
+ export const impl = implimentations => {
8
+ asyncHooks = implimentations;
9
+ };
10
+ export const reset = () => {
11
+ asyncHooks = undefined;
12
+ };
@@ -0,0 +1,99 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ import { createHooks } from "./hook";
6
+ const ContextSymbol = Symbol.for('MODERN_CONTEXT');
7
+ export const createContext = value => {
8
+ const id = Symbol('MODERN_CONTEXT_ID');
9
+
10
+ const create = value => {
11
+ const use = () => {
12
+ const container = useContainer();
13
+ return Object.seal({
14
+ get value() {
15
+ return container.read(Context);
16
+ },
17
+
18
+ set value(v) {
19
+ container.write(Context, v);
20
+ }
21
+
22
+ });
23
+ };
24
+
25
+ const get = () => {
26
+ const container = useContainer();
27
+ return container.read(Context);
28
+ };
29
+
30
+ const set = v => {
31
+ const container = useContainer();
32
+ container.write(Context, v);
33
+ };
34
+
35
+ const Context = {
36
+ id,
37
+ [ContextSymbol]: value,
38
+ create,
39
+ use,
40
+ get,
41
+ set
42
+ };
43
+ return Context;
44
+ };
45
+
46
+ return create(value);
47
+ };
48
+
49
+ const createContextMap = storage => {
50
+ const contextMap = new Map();
51
+ const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
52
+
53
+ for (let i = 0; i < contexts.length; i++) {
54
+ contextMap.set(contexts[i].id, contexts[i]);
55
+ }
56
+
57
+ return contextMap;
58
+ };
59
+
60
+ export const createContainer = (ContextStorage = {}) => {
61
+ const contextMap = createContextMap(ContextStorage);
62
+
63
+ const read = context => {
64
+ const target = contextMap.get(context.id);
65
+
66
+ if (target) {
67
+ return target[ContextSymbol];
68
+ }
69
+
70
+ return context[ContextSymbol];
71
+ };
72
+
73
+ const write = (context, value) => {
74
+ contextMap.set(context.id, context.create(value));
75
+ };
76
+
77
+ return Object.freeze({
78
+ read,
79
+ write
80
+ });
81
+ };
82
+ const {
83
+ run,
84
+ hooks
85
+ } = createHooks({
86
+ useContainer: () => {
87
+ throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
88
+ }
89
+ });
90
+ export const runHooks = run;
91
+ export const {
92
+ useContainer
93
+ } = hooks;
94
+ export const fromContainer = container => ({
95
+ useContainer: () => {
96
+ return container;
97
+ }
98
+ });
99
+ export const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
@@ -0,0 +1,18 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ export const createCounter = callback => {
6
+ const dispatch = (index, input) => {
7
+ const next = (nextInput = input) => dispatch(index + 1, nextInput);
8
+
9
+ return callback(index, input, next);
10
+ };
11
+
12
+ const start = input => dispatch(0, input);
13
+
14
+ return {
15
+ start,
16
+ dispatch
17
+ };
18
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ import { asyncHooks } from "./asyncHooksInterface";
6
+ export const createHooks = defaultHooks => {
7
+ let currentHooks = {};
8
+ const hooks = {};
9
+
10
+ for (const key in defaultHooks) {
11
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
12
+ const f = (...args) => {
13
+ var _asyncHooks$get;
14
+
15
+ const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
16
+ let handler = hooks[key];
17
+
18
+ if (typeof handler !== 'function') {
19
+ handler = defaultHooks[key];
20
+ }
21
+
22
+ return handler(...args);
23
+ };
24
+
25
+ hooks[key] = f;
26
+ }
27
+
28
+ const run = (f, implementations) => {
29
+ try {
30
+ currentHooks = implementations || defaultHooks;
31
+ asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
32
+ return f();
33
+ } finally {
34
+ currentHooks = defaultHooks;
35
+ }
36
+ };
37
+
38
+ return {
39
+ run,
40
+ hooks
41
+ };
42
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ *
5
+ * removed:
6
+ * - dependencies:
7
+ * - tslib
8
+ * - files
9
+ * - compose.ts
10
+ * - methods:
11
+ * - usePipeline
12
+ * - assertContainer
13
+ * - assertContext
14
+ * - isContext
15
+ * - isContainer
16
+ * - pipeline.useLazy
17
+ * - context.assert
18
+ */
19
+ export * from "./pipeline";
@@ -0,0 +1,93 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ /**
8
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
9
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
10
+ */
11
+ import { createContext, createContainer, fromContainer, runHooks, useContainer, runWithContainer } from "./context";
12
+ import { createCounter } from "./counter";
13
+ export { createContext, createContainer, useContainer, runWithContainer };
14
+ export const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
15
+ const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
16
+
17
+ const getMiddleware = input => {
18
+ if (typeof input === 'function') {
19
+ return input;
20
+ } else if (input && typeof input.middleware === 'function') {
21
+ return input.middleware;
22
+ }
23
+
24
+ throw new Error(`${input} is not a Middleware`);
25
+ };
26
+
27
+ export const createPipeline = options => {
28
+ const config = _objectSpread({}, options);
29
+
30
+ const middlewares = [];
31
+
32
+ const use = (...inputs) => {
33
+ middlewares.push(...inputs.map(getMiddleware));
34
+ return pipeline;
35
+ };
36
+
37
+ const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
38
+ return createCounter((index, input, next) => {
39
+ if (index >= middlewares.length) {
40
+ if (onLast) {
41
+ if (onLastWithContext) {
42
+ return runHooks(() => onLast(input), hooks);
43
+ }
44
+
45
+ return onLast(input);
46
+ }
47
+
48
+ throw new Error(`Expect returning a value, but all middlewares just calling next()`);
49
+ }
50
+
51
+ return runHooks(() => middlewares[index](input, next), hooks);
52
+ });
53
+ };
54
+
55
+ const currentContainer = createContainer(config.contexts);
56
+ const currentHooks = fromContainer(currentContainer);
57
+ const currentCounter = createCurrentCounter(currentHooks);
58
+
59
+ const getCounter = options => {
60
+ if (!options) {
61
+ return currentCounter;
62
+ }
63
+
64
+ if (options !== null && options !== void 0 && options.container) {
65
+ const hooks = fromContainer(options === null || options === void 0 ? void 0 : options.container);
66
+ return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
67
+ }
68
+
69
+ return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
70
+ };
71
+
72
+ const run = (input, options) => getCounter(options).start(input);
73
+
74
+ const middleware = (input, next) => {
75
+ const container = useContainer();
76
+ return run(input, {
77
+ container,
78
+ onLast: next
79
+ });
80
+ };
81
+
82
+ const pipeline = {
83
+ [PipelineSymbol]: true,
84
+ use,
85
+ run,
86
+ middleware
87
+ };
88
+ return pipeline;
89
+ };
90
+ export const createAsyncPipeline = options => {
91
+ const pipeline = createPipeline(options);
92
+ return _objectSpread({}, pipeline);
93
+ };
@@ -1,4 +1,4 @@
1
- export * from 'farrow-pipeline';
1
+ export * from "./farrow-pipeline";
2
2
  export * from "./waterfall";
3
3
  export * from "./workflow";
4
4
  export * from "./manager";
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { runWithContainer, createContainer } from 'farrow-pipeline';
7
+ import { runWithContainer, createContainer } from "../farrow-pipeline";
8
8
  import { isObject, generateRunner, hasOwnProperty, DEFAULT_OPTIONS } from "./sync";
9
9
  import { useRunner } from "./runner";
10
10
  const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
@@ -1,4 +1,4 @@
1
- import { createContext } from 'farrow-pipeline';
1
+ import { createContext } from "../farrow-pipeline";
2
2
  export const RunnerContext = createContext(null);
3
3
  export const useRunner = () => {
4
4
  const runner = RunnerContext.use().value;
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { isPipeline, createPipeline, runWithContainer, createContainer } from 'farrow-pipeline';
7
+ import { isPipeline, createPipeline, runWithContainer, createContainer } from "../farrow-pipeline";
8
8
  import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
9
9
  import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
10
10
  import { RunnerContext, useRunner } from "./runner";
@@ -4,15 +4,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { createAsyncPipeline, useContainer } from 'farrow-pipeline';
8
- const ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
7
+ import { createAsyncPipeline, useContainer } from "../farrow-pipeline";
8
+ const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
9
9
  export const getAsyncBrook = input => {
10
10
  if (typeof input === 'function') {
11
11
  return input;
12
12
  } else if (input && typeof input.middleware === 'function') {
13
13
  return input.middleware;
14
- } // eslint-disable-next-line @typescript-eslint/no-base-to-string
15
-
14
+ }
16
15
 
17
16
  throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
18
17
  };
@@ -29,7 +28,6 @@ export const createAsyncWaterfall = () => {
29
28
  }));
30
29
 
31
30
  const middleware = input => {
32
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
31
  const container = useContainer();
34
32
  return pipeline.run(input, {
35
33
  container,
@@ -4,15 +4,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { useContainer, createPipeline } from 'farrow-pipeline';
8
- const WATERFALL_SYMBOL = Symbol('WATERFALL_SYMBOL');
7
+ import { useContainer, createPipeline } from "../farrow-pipeline";
8
+ const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
9
9
  export const getBrook = input => {
10
10
  if (typeof input === 'function') {
11
11
  return input;
12
12
  } else if (input && typeof input.middleware === 'function') {
13
13
  return input.middleware;
14
- } // eslint-disable-next-line @typescript-eslint/no-base-to-string
15
-
14
+ }
16
15
 
17
16
  throw new Error(`${input} is not a Brook or { brook: Brook }`);
18
17
  };
@@ -29,7 +28,6 @@ export const createWaterfall = () => {
29
28
  }));
30
29
 
31
30
  const middleware = input => {
32
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
31
  const container = useContainer();
34
32
  return pipeline.run(input, {
35
33
  container,
@@ -4,8 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { createAsyncPipeline } from 'farrow-pipeline';
8
- const ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
7
+ import { createAsyncPipeline } from "../farrow-pipeline";
8
+ const ASYNC_WORKFLOW_SYMBOL = Symbol.for('MODERN_ASYNC_WORKFLOW');
9
9
  export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
10
10
  export const createAsyncWorkflow = () => {
11
11
  const pipeline = createAsyncPipeline();
@@ -4,8 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { createPipeline } from 'farrow-pipeline';
8
- const PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
7
+ import { createPipeline } from "../farrow-pipeline";
8
+ const PARALLEL_WORKFLOW_SYMBOL = Symbol.for('MODERN_PARALLEL_WORKFLOW');
9
9
  export const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
10
10
  export const createParallelWorkflow = () => {
11
11
  const pipeline = createPipeline();
@@ -4,8 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { createPipeline } from 'farrow-pipeline';
8
- const WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
7
+ import { createPipeline } from "../farrow-pipeline";
8
+ const WORKFLOW_SYMBOL = Symbol.for('MODERN_WORKFLOW');
9
9
  export const createWorkflow = () => {
10
10
  const pipeline = createPipeline();
11
11
 
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.enable = exports.disable = void 0;
7
+
8
+ var _async_hooks = _interopRequireDefault(require("async_hooks"));
9
+
10
+ var asyncHooksInterface = _interopRequireWildcard(require("./asyncHooksInterface"));
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ /**
19
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
20
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
21
+ */
22
+ const createAsyncHooks = () => {
23
+ const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
24
+
25
+ const hooks = _async_hooks.default.createHook({
26
+ init: (asyncId, _, triggerAsyncId) => {
27
+ if (store.has(triggerAsyncId)) {
28
+ const value = store.get(triggerAsyncId);
29
+
30
+ if (value) {
31
+ store.set(asyncId, value);
32
+ }
33
+ }
34
+ },
35
+ destroy: asyncId => {
36
+ if (store.has(asyncId)) {
37
+ store.delete(asyncId);
38
+ }
39
+ }
40
+ });
41
+
42
+ const set = value => {
43
+ store.set(_async_hooks.default.executionAsyncId(), value);
44
+ };
45
+
46
+ const get = () => {
47
+ return store.get(_async_hooks.default.executionAsyncId());
48
+ };
49
+
50
+ const clear = () => {
51
+ store.clear();
52
+ };
53
+
54
+ const enable = () => {
55
+ hooks.enable();
56
+ };
57
+
58
+ const disable = () => {
59
+ hooks.disable();
60
+ store.clear();
61
+ };
62
+
63
+ const entries = () => {
64
+ return store.entries();
65
+ };
66
+
67
+ return {
68
+ enable,
69
+ disable,
70
+ set,
71
+ get,
72
+ clear,
73
+ entries
74
+ };
75
+ };
76
+
77
+ const enable = () => {
78
+ const hooks = createAsyncHooks();
79
+ disable();
80
+ asyncHooksInterface.impl(hooks);
81
+ hooks.enable();
82
+ };
83
+
84
+ exports.enable = enable;
85
+
86
+ const disable = () => {
87
+ var _asyncHooksInterface$;
88
+
89
+ (_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
90
+ asyncHooksInterface.reset();
91
+ };
92
+
93
+ exports.disable = disable;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.reset = exports.impl = exports.asyncHooks = void 0;
7
+
8
+ /**
9
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
10
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
11
+ */
12
+ // eslint-disable-next-line import/no-mutable-exports
13
+ let asyncHooks;
14
+ exports.asyncHooks = asyncHooks;
15
+
16
+ const impl = implimentations => {
17
+ exports.asyncHooks = asyncHooks = implimentations;
18
+ };
19
+
20
+ exports.impl = impl;
21
+
22
+ const reset = () => {
23
+ exports.asyncHooks = asyncHooks = undefined;
24
+ };
25
+
26
+ exports.reset = reset;