@modern-js/plugin 1.21.2-beta.0 → 1.21.2-beta.2

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 (69) hide show
  1. package/dist/js/modern/farrow-pipeline/context.js +38 -0
  2. package/dist/js/modern/farrow-pipeline/counter.js +18 -0
  3. package/dist/js/modern/farrow-pipeline/index.js +5 -0
  4. package/dist/js/modern/farrow-pipeline/pipeline.js +76 -0
  5. package/dist/js/modern/index.js +4 -0
  6. package/dist/js/modern/manager/async.js +112 -0
  7. package/dist/js/modern/manager/index.js +3 -0
  8. package/dist/js/modern/manager/shared.js +44 -0
  9. package/dist/js/modern/manager/sync.js +188 -0
  10. package/dist/js/modern/manager/types.js +0 -0
  11. package/dist/js/modern/waterfall/async.js +47 -0
  12. package/dist/js/modern/waterfall/index.js +2 -0
  13. package/dist/js/modern/waterfall/sync.js +47 -0
  14. package/dist/js/modern/workflow/async.js +43 -0
  15. package/dist/js/modern/workflow/index.js +3 -0
  16. package/dist/js/modern/workflow/parallel.js +31 -0
  17. package/dist/js/modern/workflow/sync.js +34 -0
  18. package/dist/js/node/farrow-pipeline/context.js +47 -0
  19. package/dist/js/node/farrow-pipeline/counter.js +27 -0
  20. package/dist/js/node/farrow-pipeline/index.js +18 -0
  21. package/dist/js/node/farrow-pipeline/pipeline.js +94 -0
  22. package/dist/js/node/index.js +57 -0
  23. package/dist/js/node/manager/async.js +124 -0
  24. package/dist/js/node/manager/index.js +44 -0
  25. package/dist/js/node/manager/shared.js +64 -0
  26. package/dist/js/node/manager/sync.js +212 -0
  27. package/dist/js/node/manager/types.js +0 -0
  28. package/dist/js/node/waterfall/async.js +64 -0
  29. package/dist/js/node/waterfall/index.js +31 -0
  30. package/dist/js/node/waterfall/sync.js +64 -0
  31. package/dist/js/node/workflow/async.js +57 -0
  32. package/dist/js/node/workflow/index.js +44 -0
  33. package/dist/js/node/workflow/parallel.js +45 -0
  34. package/dist/js/node/workflow/sync.js +48 -0
  35. package/dist/js/treeshaking/farrow-pipeline/context.js +42 -0
  36. package/dist/js/treeshaking/farrow-pipeline/counter.js +23 -0
  37. package/dist/js/treeshaking/farrow-pipeline/index.js +5 -0
  38. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +81 -0
  39. package/dist/js/treeshaking/index.js +4 -0
  40. package/dist/js/treeshaking/manager/async.js +146 -0
  41. package/dist/js/treeshaking/manager/index.js +3 -0
  42. package/dist/js/treeshaking/manager/shared.js +79 -0
  43. package/dist/js/treeshaking/manager/sync.js +216 -0
  44. package/dist/js/treeshaking/manager/types.js +0 -0
  45. package/dist/js/treeshaking/waterfall/async.js +84 -0
  46. package/dist/js/treeshaking/waterfall/index.js +2 -0
  47. package/dist/js/treeshaking/waterfall/sync.js +59 -0
  48. package/dist/js/treeshaking/workflow/async.js +108 -0
  49. package/dist/js/treeshaking/workflow/index.js +3 -0
  50. package/dist/js/treeshaking/workflow/parallel.js +62 -0
  51. package/dist/js/treeshaking/workflow/sync.js +42 -0
  52. package/dist/types/farrow-pipeline/context.d.ts +13 -0
  53. package/dist/types/farrow-pipeline/counter.d.ts +11 -0
  54. package/dist/types/farrow-pipeline/index.d.ts +5 -0
  55. package/dist/types/farrow-pipeline/pipeline.d.ts +29 -0
  56. package/dist/types/index.d.ts +4 -0
  57. package/dist/types/manager/async.d.ts +63 -0
  58. package/dist/types/manager/index.d.ts +3 -0
  59. package/dist/types/manager/shared.d.ts +12 -0
  60. package/dist/types/manager/sync.d.ts +75 -0
  61. package/dist/types/manager/types.d.ts +36 -0
  62. package/dist/types/waterfall/async.d.ts +21 -0
  63. package/dist/types/waterfall/index.d.ts +2 -0
  64. package/dist/types/waterfall/sync.d.ts +20 -0
  65. package/dist/types/workflow/async.d.ts +12 -0
  66. package/dist/types/workflow/index.d.ts +3 -0
  67. package/dist/types/workflow/parallel.d.ts +10 -0
  68. package/dist/types/workflow/sync.d.ts +11 -0
  69. package/package.json +2 -2
@@ -0,0 +1,108 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
+ import { createAsyncPipeline } from "../farrow-pipeline";
8
+ var ASYNC_WORKFLOW_SYMBOL = Symbol["for"]('MODERN_ASYNC_WORKFLOW');
9
+ export var isAsyncWorkflow = function isAsyncWorkflow(input) {
10
+ return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
11
+ };
12
+ export var createAsyncWorkflow = function createAsyncWorkflow() {
13
+ var pipeline = createAsyncPipeline();
14
+
15
+ var use = function use() {
16
+ for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
17
+ input[_key] = arguments[_key];
18
+ }
19
+
20
+ pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapAsyncWorkerToAsyncMiddleware)));
21
+ return workflow;
22
+ };
23
+
24
+ var run = /*#__PURE__*/function () {
25
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
26
+ var result;
27
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
28
+ while (1) {
29
+ switch (_context.prev = _context.next) {
30
+ case 0:
31
+ result = pipeline.run(input, {
32
+ onLast: function onLast() {
33
+ return [];
34
+ }
35
+ });
36
+
37
+ if (!isPromise(result)) {
38
+ _context.next = 5;
39
+ break;
40
+ }
41
+
42
+ return _context.abrupt("return", result.then(function (result) {
43
+ return result.filter(Boolean);
44
+ }));
45
+
46
+ case 5:
47
+ return _context.abrupt("return", result.filter(Boolean));
48
+
49
+ case 6:
50
+ case "end":
51
+ return _context.stop();
52
+ }
53
+ }
54
+ }, _callee);
55
+ }));
56
+
57
+ return function run(_x) {
58
+ return _ref.apply(this, arguments);
59
+ };
60
+ }();
61
+
62
+ var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
63
+ use: use,
64
+ run: run
65
+ }, ASYNC_WORKFLOW_SYMBOL, true));
66
+
67
+ return workflow;
68
+ };
69
+
70
+ var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(worker) {
71
+ return /*#__PURE__*/function () {
72
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input, next) {
73
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
74
+ while (1) {
75
+ switch (_context2.prev = _context2.next) {
76
+ case 0:
77
+ _context2.next = 2;
78
+ return worker(input);
79
+
80
+ case 2:
81
+ _context2.t1 = _context2.sent;
82
+ _context2.t0 = [_context2.t1];
83
+ _context2.t2 = _toConsumableArray;
84
+ _context2.next = 7;
85
+ return next(input);
86
+
87
+ case 7:
88
+ _context2.t3 = _context2.sent;
89
+ _context2.t4 = (0, _context2.t2)(_context2.t3);
90
+ return _context2.abrupt("return", _context2.t0.concat.call(_context2.t0, _context2.t4));
91
+
92
+ case 10:
93
+ case "end":
94
+ return _context2.stop();
95
+ }
96
+ }
97
+ }, _callee2);
98
+ }));
99
+
100
+ return function (_x2, _x3) {
101
+ return _ref2.apply(this, arguments);
102
+ };
103
+ }();
104
+ };
105
+
106
+ function isPromise(obj) {
107
+ return Boolean(obj) && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
108
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./sync";
2
+ export * from "./parallel";
3
+ export * from "./async";
@@ -0,0 +1,62 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
6
+ import { createPipeline } from "../farrow-pipeline";
7
+ var PARALLEL_WORKFLOW_SYMBOL = Symbol["for"]('MODERN_PARALLEL_WORKFLOW');
8
+ export var isParallelWorkflow = function isParallelWorkflow(input) {
9
+ return Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
10
+ };
11
+ export var createParallelWorkflow = function createParallelWorkflow() {
12
+ var pipeline = createPipeline();
13
+
14
+ var use = function use() {
15
+ for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
16
+ input[_key] = arguments[_key];
17
+ }
18
+
19
+ pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapParallelWorkerToAsyncMiddleware)));
20
+ return workflow;
21
+ };
22
+
23
+ var run = /*#__PURE__*/function () {
24
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
25
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
26
+ while (1) {
27
+ switch (_context.prev = _context.next) {
28
+ case 0:
29
+ return _context.abrupt("return", Promise.all(pipeline.run(input, {
30
+ onLast: function onLast() {
31
+ return [];
32
+ }
33
+ })).then(function (result) {
34
+ return result.filter(Boolean);
35
+ }));
36
+
37
+ case 1:
38
+ case "end":
39
+ return _context.stop();
40
+ }
41
+ }
42
+ }, _callee);
43
+ }));
44
+
45
+ return function run(_x) {
46
+ return _ref.apply(this, arguments);
47
+ };
48
+ }();
49
+
50
+ var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
51
+ run: run,
52
+ use: use
53
+ }, PARALLEL_WORKFLOW_SYMBOL, true));
54
+
55
+ return workflow;
56
+ };
57
+
58
+ var mapParallelWorkerToAsyncMiddleware = function mapParallelWorkerToAsyncMiddleware(worker) {
59
+ return function (input, next) {
60
+ return [worker(input)].concat(_toConsumableArray(next(input)));
61
+ };
62
+ };
@@ -0,0 +1,42 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import { createPipeline } from "../farrow-pipeline";
5
+ var WORKFLOW_SYMBOL = Symbol["for"]('MODERN_WORKFLOW');
6
+ export var createWorkflow = function createWorkflow() {
7
+ var pipeline = createPipeline();
8
+
9
+ var use = function use() {
10
+ for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
11
+ input[_key] = arguments[_key];
12
+ }
13
+
14
+ pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapWorkerToMiddleware)));
15
+ return workflow;
16
+ };
17
+
18
+ var run = function run(input) {
19
+ var result = pipeline.run(input, {
20
+ onLast: function onLast() {
21
+ return [];
22
+ }
23
+ });
24
+ return result.filter(Boolean);
25
+ };
26
+
27
+ var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
28
+ use: use,
29
+ run: run
30
+ }, WORKFLOW_SYMBOL, true));
31
+
32
+ return workflow;
33
+ };
34
+ export var isWorkflow = function isWorkflow(input) {
35
+ return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
36
+ };
37
+
38
+ var mapWorkerToMiddleware = function mapWorkerToMiddleware(worker) {
39
+ return function (input, next) {
40
+ return [worker(input)].concat(_toConsumableArray(next(input)));
41
+ };
42
+ };
@@ -0,0 +1,13 @@
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 declare type Context<T = any> = {
6
+ create: (value: T) => Context<T>;
7
+ use: () => {
8
+ value: T;
9
+ };
10
+ get: () => T;
11
+ set: (value: T) => void;
12
+ };
13
+ export declare const createContext: <T>(value: T) => Context<T>;
@@ -0,0 +1,11 @@
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 declare type Next<I = unknown, O = unknown> = (input?: I) => O;
6
+ export declare type CounterCallback<I = unknown, O = unknown> = (index: number, input: I, next: Next<I, O>) => O;
7
+ export declare type Counter<I = unknown, O = unknown> = {
8
+ start: (input: I) => O;
9
+ dispatch: (index: number, input: I) => O;
10
+ };
11
+ export declare const createCounter: <I, O>(callback: CounterCallback<I, O>) => Counter<I, O>;
@@ -0,0 +1,5 @@
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 * from './pipeline';
@@ -0,0 +1,29 @@
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 { createContext, Context } from './context';
6
+ import { Next } from './counter';
7
+ export type { Next };
8
+ export { createContext };
9
+ export type { Context };
10
+ export declare type Middleware<I = unknown, O = unknown> = (input: I, next: Next<I, O>) => O;
11
+ export declare type Middlewares<I = unknown, O = unknown> = Middleware<I, O>[];
12
+ export declare const isPipeline: (input: any) => input is Pipeline<unknown, unknown>;
13
+ declare const PipelineSymbol: unique symbol;
14
+ export declare type RunPipelineOptions<I = unknown, O = unknown> = {
15
+ onLast?: (input: I) => O;
16
+ };
17
+ export declare type MiddlewareInput<I = unknown, O = unknown> = Middleware<I, O> | {
18
+ middleware: Middleware<I, O>;
19
+ };
20
+ export declare type Pipeline<I = unknown, O = unknown> = {
21
+ [PipelineSymbol]: true;
22
+ use: (...inputs: MiddlewareInput<I, O>[]) => Pipeline<I, O>;
23
+ run: (input: I, options?: RunPipelineOptions<I, O>) => O;
24
+ middleware: Middleware<I, O>;
25
+ };
26
+ export declare const createPipeline: <I, O>() => Pipeline<I, O>;
27
+ export declare type MaybeAsync<T> = T | Promise<T>;
28
+ export declare type AsyncPipeline<I = unknown, O = unknown> = Pipeline<I, MaybeAsync<O>>;
29
+ export declare const createAsyncPipeline: <I, O>() => AsyncPipeline<I, O>;
@@ -0,0 +1,4 @@
1
+ export * from './farrow-pipeline';
2
+ export * from './waterfall';
3
+ export * from './workflow';
4
+ export * from './manager';
@@ -0,0 +1,63 @@
1
+ import type { ToRunners, ToThreads, CommonAPI, PluginOptions } from './types';
2
+ /** Setup function of async plugin. */
3
+
4
+ export declare type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
5
+ declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
6
+ export declare type AsyncPlugin<Hooks, API> = {
7
+ ASYNC_PLUGIN_SYMBOL: typeof ASYNC_PLUGIN_SYMBOL;
8
+ } & Required<PluginOptions<Hooks, AsyncSetup<Hooks, API>>>;
9
+ export declare type AsyncManager<Hooks, API> = {
10
+ /**
11
+ * Create a sync plugin.
12
+ * @param setup the setup function.
13
+ * @param options optional plugin options.
14
+ */
15
+ createPlugin: (setup?: AsyncSetup<Hooks, API>, options?: PluginOptions<Hooks, AsyncSetup<Hooks, API>>) => AsyncPlugin<Hooks, API>;
16
+ /**
17
+ * Determine if a value is a async plugin.
18
+ * @param input
19
+ */
20
+
21
+ isPlugin: (input: unknown) => input is AsyncPlugin<Hooks, API>;
22
+ /**
23
+ * Register new plugins to current manager.
24
+ * @param plugins one or more plugin.
25
+ */
26
+
27
+ usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
28
+ /**
29
+ * Init manager, it will call the setup function of all registered plugins.
30
+ */
31
+
32
+ init: () => Promise<ToRunners<Hooks>>;
33
+ /**
34
+ * Run callback function.
35
+ * @param callback
36
+ */
37
+
38
+ run: <O>(cb: () => O) => O;
39
+ /**
40
+ * Register new hooks.
41
+ * @param newHooks
42
+ */
43
+
44
+ registerHook: (newHooks: Partial<Hooks>) => void;
45
+ /**
46
+ * Return a cloned manager.
47
+ * @param overrideAPI override the default plugin API.
48
+ */
49
+
50
+ clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => AsyncManager<Hooks, API>;
51
+ /**
52
+ * Clear all registered plugins.
53
+ */
54
+
55
+ clear: () => void;
56
+ /**
57
+ * Get all runner functions of the hooks.
58
+ */
59
+
60
+ useRunner: () => ToRunners<Hooks>;
61
+ };
62
+ export declare const createAsyncManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => AsyncManager<Hooks, API>;
63
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './sync';
2
+ export * from './async';
3
+ export * from './types';
@@ -0,0 +1,12 @@
1
+ import type { AsyncPlugin } from './async';
2
+ import type { Plugin } from './sync';
3
+ export declare const checkPlugins: <Hooks, API>(plugins: Plugin<Hooks, API>[] | AsyncPlugin<Hooks, API>[]) => void;
4
+ export declare function sortPlugins<Hooks, API>(input: Plugin<Hooks, API>[]): Plugin<Hooks, API>[];
5
+ export declare function sortPlugins<Hooks, API>(input: AsyncPlugin<Hooks, API>[]): AsyncPlugin<Hooks, API>[];
6
+ export declare const includePlugin: <P extends {
7
+ name: string;
8
+ }, I extends {
9
+ name: string;
10
+ }>(plugins: P[], input: I) => boolean;
11
+ export declare const isObject: (obj: unknown) => obj is Record<string, any>;
12
+ export declare const hasOwnProperty: <X extends Record<string, unknown>, Y extends PropertyKey>(obj: X, prop: Y) => obj is X & Record<Y, unknown>;
@@ -0,0 +1,75 @@
1
+ import type { Hook, CommonAPI, ToRunners, ToThreads, PluginOptions } from './types';
2
+ /** Setup function of sync plugin. */
3
+
4
+ export declare type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
5
+ declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
6
+ export declare type Plugin<Hooks, API> = {
7
+ SYNC_PLUGIN_SYMBOL: typeof SYNC_PLUGIN_SYMBOL;
8
+ } & Required<PluginOptions<Hooks, Setup<Hooks, API>>>;
9
+ export declare type Manager<Hooks, API> = {
10
+ /**
11
+ * Create a sync plugin.
12
+ * @param setup the setup function.
13
+ * @param options optional plugin options.
14
+ */
15
+ createPlugin: (setup?: Setup<Hooks, API>, options?: PluginOptions<Hooks, Setup<Hooks, API>>) => Plugin<Hooks, API>;
16
+ /**
17
+ * Determine if a value is a sync plugin.
18
+ * @param input
19
+ */
20
+
21
+ isPlugin: (input: unknown) => input is Plugin<Hooks, API>;
22
+ /**
23
+ * Register new plugins to current manager.
24
+ * @param plugins one or more plugin.
25
+ */
26
+
27
+ usePlugin: (...plugins: Array<Plugin<Hooks, API> | PluginOptions<Hooks, Setup<Hooks, API>> | (() => PluginOptions<Hooks, Setup<Hooks, API>>)>) => Manager<Hooks, API>;
28
+ /**
29
+ * Init manager, it will call the setup function of all registered plugins.
30
+ */
31
+
32
+ init: () => ToRunners<Hooks>;
33
+ /**
34
+ * Run callback function.
35
+ * @param callback
36
+ */
37
+
38
+ run: <O>(cb: () => O) => O;
39
+ /**
40
+ * Register new hooks.
41
+ * @param newHooks
42
+ */
43
+
44
+ registerHook: (hewHooks: Partial<Hooks>) => void;
45
+ /**
46
+ * Clear all registered plugins.
47
+ */
48
+
49
+ clear: () => void;
50
+ /**
51
+ * Return a cloned manager.
52
+ * @param overrideAPI override the default plugin API.
53
+ */
54
+
55
+ clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => Manager<Hooks, API>;
56
+ /**
57
+ * Get all runner functions of the hooks.
58
+ */
59
+
60
+ useRunner: () => ToRunners<Hooks>;
61
+ };
62
+ export declare const DEFAULT_OPTIONS: {
63
+ name: string;
64
+ pre: never[];
65
+ post: never[];
66
+ rivals: never[];
67
+ required: never[];
68
+ usePlugins: never[];
69
+ registerHook: {};
70
+ };
71
+ export declare const createManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => Manager<Hooks, API>;
72
+ export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], hooksMap?: Hooks | undefined) => ToRunners<Hooks>;
73
+ export declare const cloneHook: (hook: Hook) => Hook;
74
+ export declare const cloneHooksMap: <Hooks>(record: Hooks) => Hooks;
75
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { Pipeline, MaybeAsync, Middleware, AsyncPipeline } from '../farrow-pipeline';
2
+ import type { Brook, Waterfall, AsyncBrook, AsyncWaterfall } from '../waterfall';
3
+ import type { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
4
+ /** All hook types. */
5
+
6
+ export declare type Hook = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any>;
7
+ export declare type HooksMap = Record<string, Hook>;
8
+ /** Extract the type of callback function from a hook. */
9
+
10
+ export declare type ToThread<P extends Hook> = P extends Workflow<infer I, infer O> ? Worker<I, O> : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends ParallelWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends Waterfall<infer I> ? Brook<I> : P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : P extends Pipeline<infer I, infer O> ? Middleware<I, O> : P extends AsyncPipeline<infer I, infer O> ? Middleware<I, MaybeAsync<O>> : never;
11
+ /** Extract types of callback function from hooks. */
12
+
13
+ export declare type ToThreads<PS> = { [K in keyof PS]: PS[K] extends Hook ? ToThread<PS[K]> : PS[K] extends void ? void : never };
14
+ /** Extract run method from a hook. */
15
+
16
+ export declare type RunnerFromHook<P extends Hook> = P extends Waterfall<infer I> ? Waterfall<I>['run'] : P extends AsyncWaterfall<infer I> ? AsyncWaterfall<I>['run'] : P extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorkflow<I, O>['run'] : P extends ParallelWorkflow<infer I, infer O> ? ParallelWorkflow<I, O>['run'] : P extends Pipeline<infer I, infer O> ? Pipeline<I, O>['run'] : P extends AsyncPipeline<infer I, infer O> ? AsyncPipeline<I, O>['run'] : never;
17
+ /** Extract all run methods from hooks. */
18
+
19
+ export declare type ToRunners<PS> = { [K in keyof PS]: PS[K] extends Hook ? RunnerFromHook<PS[K]> : PS[K] extends void ? void : never };
20
+ /** All options to define a plugin. */
21
+
22
+ export declare type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string, unknown>> = {
23
+ name?: string;
24
+ pre?: string[];
25
+ post?: string[];
26
+ setup?: Setup;
27
+ rivals?: string[];
28
+ required?: string[];
29
+ usePlugins?: PluginOptions<Hooks, Setup>[];
30
+ registerHook?: Partial<Hooks & ExtendHooks>;
31
+ };
32
+ /** Common api of setup function. */
33
+
34
+ export declare type CommonAPI<Hooks> = {
35
+ useHookRunners: () => ToRunners<Hooks>;
36
+ };
@@ -0,0 +1,21 @@
1
+ import { MaybeAsync } from '../farrow-pipeline';
2
+ declare const ASYNC_WATERFALL_SYMBOL: unique symbol;
3
+ export declare type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
4
+ export declare type AsyncBrookInput<I = unknown> = AsyncBrook<I> | {
5
+ middleware: AsyncBrook<I>;
6
+ };
7
+ export declare type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
8
+ export declare type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
9
+ export declare const getAsyncBrook: <I>(input: AsyncBrookInput<I>) => AsyncBrook<I>;
10
+ export declare type RunAsyncWaterfallOptions<I = unknown> = {
11
+ onLast?: AsyncBrook<I>;
12
+ };
13
+ export declare type AsyncWaterfall<I> = {
14
+ run: (input: I, options?: RunAsyncWaterfallOptions<I>) => MaybeAsync<I>;
15
+ use: (...I: AsyncBrookInputs<I>) => AsyncWaterfall<I>;
16
+ middleware: AsyncBrook<I>;
17
+ [ASYNC_WATERFALL_SYMBOL]: true;
18
+ };
19
+ export declare const createAsyncWaterfall: <I = void>() => AsyncWaterfall<I>;
20
+ export declare const isAsyncWaterfall: (input: any) => input is AsyncWaterfall<any>;
21
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './sync';
2
+ export * from './async';
@@ -0,0 +1,20 @@
1
+ declare const WATERFALL_SYMBOL: unique symbol;
2
+ export declare type Brook<I = unknown> = (I: I) => I;
3
+ export declare type BrookInput<I = unknown> = Brook<I> | {
4
+ middleware: Brook<I>;
5
+ };
6
+ export declare type Brooks<I = unknown> = Brook<I>[];
7
+ export declare type BrookInputs<I = unknown> = BrookInput<I>[];
8
+ export declare const getBrook: <I>(input: BrookInput<I>) => Brook<I>;
9
+ export declare type RunWaterfallOptions<I = unknown> = {
10
+ onLast?: Brook<I>;
11
+ };
12
+ export declare type Waterfall<I = void> = {
13
+ run: (input: I, options?: RunWaterfallOptions<I>) => I;
14
+ use: (...I: BrookInputs<I>) => Waterfall<I>;
15
+ middleware: Brook<I>;
16
+ [WATERFALL_SYMBOL]: true;
17
+ };
18
+ export declare const createWaterfall: <I = void>() => Waterfall<I>;
19
+ export declare const isWaterfall: (input: any) => input is Waterfall<any>;
20
+ export {};
@@ -0,0 +1,12 @@
1
+ import { MaybeAsync } from '../farrow-pipeline';
2
+ declare const ASYNC_WORKFLOW_SYMBOL: unique symbol;
3
+ export declare type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
4
+ export declare type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
5
+ export declare type AsyncWorkflow<I, O> = {
6
+ run: (input: I) => MaybeAsync<O[]>;
7
+ use: (...I: AsyncWorkers<I, O>) => AsyncWorkflow<I, O>;
8
+ [ASYNC_WORKFLOW_SYMBOL]: true;
9
+ };
10
+ export declare const isAsyncWorkflow: (input: any) => input is AsyncWorkflow<any, any>;
11
+ export declare const createAsyncWorkflow: <I = void, O = unknown>() => AsyncWorkflow<I, O>;
12
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './sync';
2
+ export * from './parallel';
3
+ export * from './async';
@@ -0,0 +1,10 @@
1
+ import type { AsyncWorkers } from './async';
2
+ declare const PARALLEL_WORKFLOW_SYMBOL: unique symbol;
3
+ export declare type ParallelWorkflow<I, O = any> = {
4
+ run: (input: I) => Promise<O[]>;
5
+ use: (...I: AsyncWorkers<I, O>) => ParallelWorkflow<I, O>;
6
+ [PARALLEL_WORKFLOW_SYMBOL]: true;
7
+ };
8
+ export declare const isParallelWorkflow: (input: any) => input is ParallelWorkflow<any, any>;
9
+ export declare const createParallelWorkflow: <I = void, O = unknown>() => ParallelWorkflow<I, O>;
10
+ export {};
@@ -0,0 +1,11 @@
1
+ declare const WORKFLOW_SYMBOL: unique symbol;
2
+ export declare type Worker<I, O> = (I: I) => O;
3
+ export declare type Workers<I, O> = Worker<I, O>[];
4
+ export declare type Workflow<I, O> = {
5
+ run: (input: I) => O[];
6
+ use: (...I: Workers<I, O>) => Workflow<I, O>;
7
+ [WORKFLOW_SYMBOL]: true;
8
+ };
9
+ export declare const createWorkflow: <I = void, O = unknown>() => Workflow<I, O>;
10
+ export declare const isWorkflow: (input: any) => input is Workflow<unknown, unknown>;
11
+ export {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.21.2-beta.0",
14
+ "version": "1.21.2-beta.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -24,7 +24,7 @@
24
24
  "import": "./dist/js/modern/index.js",
25
25
  "require": "./dist/js/node/index.js"
26
26
  },
27
- "types": "./dist/types/index.d.ts",
27
+ "types": "./dist/types//index.d.js",
28
28
  "default": "./dist/js/treeshaking/index.js"
29
29
  }
30
30
  },