@modern-js/plugin 2.69.4 → 3.0.0-alpha.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.
Files changed (267) hide show
  1. package/dist/cjs/cli/api.js +119 -0
  2. package/dist/cjs/cli/context.js +85 -0
  3. package/dist/cjs/cli/hooks.js +65 -0
  4. package/dist/cjs/cli/index.js +68 -0
  5. package/dist/cjs/cli/run/config/createLoadedConfig.js +87 -0
  6. package/dist/cjs/cli/run/config/createResolvedConfig.js +48 -0
  7. package/dist/cjs/cli/run/config/loadConfig.js +113 -0
  8. package/dist/cjs/cli/run/create.js +187 -0
  9. package/dist/cjs/cli/run/index.js +56 -0
  10. package/dist/cjs/cli/run/run.js +57 -0
  11. package/dist/cjs/cli/run/types.js +18 -0
  12. package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
  13. package/dist/cjs/cli/run/utils/commander.js +56 -0
  14. package/dist/cjs/cli/run/utils/createFileWatcher.js +112 -0
  15. package/dist/cjs/cli/run/utils/debug.js +37 -0
  16. package/dist/cjs/cli/run/utils/initAppDir.js +55 -0
  17. package/dist/cjs/cli/run/utils/mergeConfig.js +66 -0
  18. package/dist/cjs/hooks.js +169 -0
  19. package/dist/cjs/index.js +53 -26
  20. package/dist/cjs/manager.js +135 -0
  21. package/dist/cjs/runtime/api.js +95 -0
  22. package/dist/cjs/runtime/context.js +60 -0
  23. package/dist/cjs/runtime/hooks.js +46 -0
  24. package/dist/cjs/runtime/index.js +51 -0
  25. package/dist/cjs/runtime/run/create.js +79 -0
  26. package/dist/cjs/runtime/run/index.js +37 -0
  27. package/dist/cjs/runtime/run/types.js +18 -0
  28. package/dist/cjs/server/api.js +96 -0
  29. package/dist/cjs/server/context.js +75 -0
  30. package/dist/cjs/server/hooks.js +43 -0
  31. package/dist/cjs/server/index.js +54 -0
  32. package/dist/cjs/server/run/create.js +79 -0
  33. package/dist/cjs/server/run/index.js +40 -0
  34. package/dist/cjs/server/run/types.js +18 -0
  35. package/dist/cjs/types/cli/api.js +18 -0
  36. package/dist/cjs/types/cli/context.js +18 -0
  37. package/dist/cjs/types/cli/hooks.js +18 -0
  38. package/dist/cjs/types/cli/index.js +18 -0
  39. package/dist/cjs/types/cli/plugin.js +18 -0
  40. package/dist/cjs/types/hooks.js +18 -0
  41. package/dist/cjs/types/index.js +18 -0
  42. package/dist/cjs/types/plugin.js +18 -0
  43. package/dist/cjs/types/runtime/api.js +18 -0
  44. package/dist/cjs/types/runtime/context.js +18 -0
  45. package/dist/cjs/types/runtime/hooks.js +18 -0
  46. package/dist/cjs/types/runtime/index.js +18 -0
  47. package/dist/cjs/types/runtime/plugin.js +18 -0
  48. package/dist/cjs/types/server/api.js +18 -0
  49. package/dist/cjs/types/server/context.js +18 -0
  50. package/dist/cjs/types/server/hooks.js +18 -0
  51. package/dist/cjs/types/server/index.js +18 -0
  52. package/dist/cjs/types/server/plugin.js +18 -0
  53. package/dist/cjs/types/utils.js +18 -0
  54. package/dist/esm/cli/api.mjs +85 -0
  55. package/dist/esm/cli/context.mjs +38 -0
  56. package/dist/esm/cli/hooks.mjs +31 -0
  57. package/dist/esm/cli/index.mjs +7 -0
  58. package/dist/esm/cli/run/config/createLoadedConfig.mjs +53 -0
  59. package/dist/esm/cli/run/config/createResolvedConfig.mjs +14 -0
  60. package/dist/esm/cli/run/config/loadConfig.mjs +59 -0
  61. package/dist/esm/cli/run/create.mjs +150 -0
  62. package/dist/esm/cli/run/index.mjs +7 -0
  63. package/dist/esm/cli/run/run.mjs +23 -0
  64. package/dist/esm/cli/run/types.mjs +0 -0
  65. package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
  66. package/dist/esm/cli/run/utils/commander.mjs +16 -0
  67. package/dist/esm/cli/run/utils/createFileWatcher.mjs +68 -0
  68. package/dist/esm/cli/run/utils/debug.mjs +3 -0
  69. package/dist/esm/cli/run/utils/initAppDir.mjs +11 -0
  70. package/dist/esm/cli/run/utils/mergeConfig.mjs +32 -0
  71. package/dist/esm/hooks.mjs +120 -0
  72. package/dist/esm/index.mjs +3 -0
  73. package/dist/esm/manager.mjs +101 -0
  74. package/dist/esm/runtime/api.mjs +61 -0
  75. package/dist/esm/runtime/context.mjs +23 -0
  76. package/dist/esm/runtime/hooks.mjs +12 -0
  77. package/dist/esm/runtime/index.mjs +5 -0
  78. package/dist/esm/runtime/run/create.mjs +45 -0
  79. package/dist/esm/runtime/run/index.mjs +3 -0
  80. package/dist/esm/runtime/run/types.mjs +0 -0
  81. package/dist/esm/server/api.mjs +59 -0
  82. package/dist/esm/server/context.mjs +38 -0
  83. package/dist/esm/server/hooks.mjs +9 -0
  84. package/dist/esm/server/index.mjs +5 -0
  85. package/dist/esm/server/run/create.mjs +45 -0
  86. package/dist/esm/server/run/index.mjs +3 -0
  87. package/dist/esm/server/run/types.mjs +0 -0
  88. package/dist/esm/types/cli/api.mjs +0 -0
  89. package/dist/esm/types/cli/context.mjs +0 -0
  90. package/dist/esm/types/cli/hooks.mjs +0 -0
  91. package/dist/esm/types/cli/index.mjs +0 -0
  92. package/dist/esm/types/cli/plugin.mjs +0 -0
  93. package/dist/esm/types/hooks.mjs +0 -0
  94. package/dist/esm/types/index.mjs +0 -0
  95. package/dist/esm/types/plugin.mjs +0 -0
  96. package/dist/esm/types/runtime/api.mjs +0 -0
  97. package/dist/esm/types/runtime/context.mjs +0 -0
  98. package/dist/esm/types/runtime/hooks.mjs +0 -0
  99. package/dist/esm/types/runtime/index.mjs +0 -0
  100. package/dist/esm/types/runtime/plugin.mjs +0 -0
  101. package/dist/esm/types/server/api.mjs +0 -0
  102. package/dist/esm/types/server/context.mjs +0 -0
  103. package/dist/esm/types/server/hooks.mjs +0 -0
  104. package/dist/esm/types/server/index.mjs +0 -0
  105. package/dist/esm/types/server/plugin.mjs +0 -0
  106. package/dist/esm/types/utils.mjs +0 -0
  107. package/dist/esm-node/cli/api.mjs +85 -0
  108. package/dist/esm-node/cli/context.mjs +38 -0
  109. package/dist/esm-node/cli/hooks.mjs +31 -0
  110. package/dist/esm-node/cli/index.mjs +7 -0
  111. package/dist/esm-node/cli/run/config/createLoadedConfig.mjs +53 -0
  112. package/dist/esm-node/cli/run/config/createResolvedConfig.mjs +14 -0
  113. package/dist/esm-node/cli/run/config/loadConfig.mjs +59 -0
  114. package/dist/esm-node/cli/run/create.mjs +150 -0
  115. package/dist/esm-node/cli/run/index.mjs +7 -0
  116. package/dist/esm-node/cli/run/run.mjs +23 -0
  117. package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
  118. package/dist/esm-node/cli/run/utils/commander.mjs +16 -0
  119. package/dist/esm-node/cli/run/utils/createFileWatcher.mjs +68 -0
  120. package/dist/esm-node/cli/run/utils/debug.mjs +3 -0
  121. package/dist/esm-node/cli/run/utils/initAppDir.mjs +11 -0
  122. package/dist/esm-node/cli/run/utils/mergeConfig.mjs +32 -0
  123. package/dist/esm-node/hooks.mjs +120 -0
  124. package/dist/esm-node/index.mjs +3 -0
  125. package/dist/esm-node/manager.mjs +101 -0
  126. package/dist/esm-node/runtime/api.mjs +61 -0
  127. package/dist/esm-node/runtime/context.mjs +23 -0
  128. package/dist/esm-node/runtime/hooks.mjs +12 -0
  129. package/dist/esm-node/runtime/index.mjs +5 -0
  130. package/dist/esm-node/runtime/run/create.mjs +45 -0
  131. package/dist/esm-node/runtime/run/index.mjs +3 -0
  132. package/dist/esm-node/runtime/run/types.mjs +0 -0
  133. package/dist/esm-node/server/api.mjs +59 -0
  134. package/dist/esm-node/server/context.mjs +38 -0
  135. package/dist/esm-node/server/hooks.mjs +9 -0
  136. package/dist/esm-node/server/index.mjs +5 -0
  137. package/dist/esm-node/server/run/create.mjs +45 -0
  138. package/dist/esm-node/server/run/index.mjs +3 -0
  139. package/dist/esm-node/server/run/types.mjs +0 -0
  140. package/dist/esm-node/types/cli/api.mjs +0 -0
  141. package/dist/esm-node/types/cli/context.mjs +0 -0
  142. package/dist/esm-node/types/cli/hooks.mjs +0 -0
  143. package/dist/esm-node/types/cli/index.mjs +0 -0
  144. package/dist/esm-node/types/cli/plugin.mjs +0 -0
  145. package/dist/esm-node/types/hooks.mjs +0 -0
  146. package/dist/esm-node/types/index.mjs +0 -0
  147. package/dist/esm-node/types/plugin.mjs +0 -0
  148. package/dist/esm-node/types/runtime/api.mjs +0 -0
  149. package/dist/esm-node/types/runtime/context.mjs +0 -0
  150. package/dist/esm-node/types/runtime/hooks.mjs +0 -0
  151. package/dist/esm-node/types/runtime/index.mjs +0 -0
  152. package/dist/esm-node/types/runtime/plugin.mjs +0 -0
  153. package/dist/esm-node/types/server/api.mjs +0 -0
  154. package/dist/esm-node/types/server/context.mjs +0 -0
  155. package/dist/esm-node/types/server/hooks.mjs +0 -0
  156. package/dist/esm-node/types/server/index.mjs +0 -0
  157. package/dist/esm-node/types/server/plugin.mjs +0 -0
  158. package/dist/esm-node/types/utils.mjs +0 -0
  159. package/dist/types/cli/api.d.ts +8 -0
  160. package/dist/types/cli/context.d.ts +19 -0
  161. package/dist/types/cli/hooks.d.ts +42 -0
  162. package/dist/types/cli/index.d.ts +6 -0
  163. package/dist/types/cli/run/config/createLoadedConfig.d.ts +2 -0
  164. package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
  165. package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
  166. package/dist/types/cli/run/create.d.ts +16 -0
  167. package/dist/types/cli/run/index.d.ts +13 -0
  168. package/dist/types/cli/run/run.d.ts +2 -0
  169. package/dist/types/cli/run/types.d.ts +32 -0
  170. package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
  171. package/dist/types/cli/run/utils/commander.d.ts +5 -0
  172. package/dist/types/cli/run/utils/createFileWatcher.d.ts +3 -0
  173. package/dist/types/cli/run/utils/debug.d.ts +1 -0
  174. package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
  175. package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
  176. package/dist/types/hooks.d.ts +7 -0
  177. package/dist/types/index.d.ts +7 -4
  178. package/dist/types/manager.d.ts +5 -0
  179. package/dist/types/runtime/api.d.ts +9 -0
  180. package/dist/types/runtime/context.d.ts +11 -0
  181. package/dist/types/runtime/hooks.d.ts +2 -0
  182. package/dist/types/runtime/index.d.ts +5 -0
  183. package/dist/types/runtime/run/create.d.ts +7 -0
  184. package/dist/types/runtime/run/index.d.ts +5 -0
  185. package/dist/types/runtime/run/types.d.ts +6 -0
  186. package/dist/types/server/api.d.ts +9 -0
  187. package/dist/types/server/context.d.ts +13 -0
  188. package/dist/types/server/hooks.d.ts +9 -0
  189. package/dist/types/server/index.d.ts +4 -0
  190. package/dist/types/server/run/create.d.ts +7 -0
  191. package/dist/types/server/run/index.d.ts +8 -0
  192. package/dist/types/server/run/types.d.ts +22 -0
  193. package/dist/types/types/cli/api.d.ts +49 -0
  194. package/dist/types/types/cli/context.d.ts +42 -0
  195. package/dist/types/types/cli/hooks.d.ts +72 -0
  196. package/dist/types/types/cli/index.d.ts +4 -0
  197. package/dist/types/types/cli/plugin.d.ts +17 -0
  198. package/dist/types/types/hooks.d.ts +27 -0
  199. package/dist/types/types/index.d.ts +4 -0
  200. package/dist/types/types/plugin.d.ts +46 -0
  201. package/dist/types/types/runtime/api.d.ts +22 -0
  202. package/dist/types/types/runtime/context.d.ts +13 -0
  203. package/dist/types/types/runtime/hooks.d.ts +39 -0
  204. package/dist/types/types/runtime/index.d.ts +4 -0
  205. package/dist/types/types/runtime/plugin.d.ts +14 -0
  206. package/dist/types/types/server/api.d.ts +19 -0
  207. package/dist/types/types/server/context.d.ts +28 -0
  208. package/dist/types/types/server/hooks.d.ts +24 -0
  209. package/dist/types/types/server/index.d.ts +4 -0
  210. package/dist/types/types/server/plugin.d.ts +14 -0
  211. package/dist/types/types/utils.d.ts +7 -0
  212. package/package.json +68 -14
  213. package/rslib.config.mts +4 -0
  214. package/rstest.config.ts +5 -0
  215. package/dist/cjs/farrow-pipeline/context.js +0 -44
  216. package/dist/cjs/farrow-pipeline/counter.js +0 -37
  217. package/dist/cjs/farrow-pipeline/index.js +0 -87
  218. package/dist/cjs/manager/async.js +0 -124
  219. package/dist/cjs/manager/index.js +0 -26
  220. package/dist/cjs/manager/shared.js +0 -60
  221. package/dist/cjs/manager/sync.js +0 -194
  222. package/dist/cjs/manager/types.js +0 -16
  223. package/dist/cjs/waterfall/async.js +0 -68
  224. package/dist/cjs/waterfall/index.js +0 -24
  225. package/dist/cjs/waterfall/sync.js +0 -67
  226. package/dist/cjs/workflow/async.js +0 -60
  227. package/dist/cjs/workflow/index.js +0 -30
  228. package/dist/cjs/workflow/interrupt.js +0 -64
  229. package/dist/cjs/workflow/parallel.js +0 -53
  230. package/dist/cjs/workflow/sync.js +0 -56
  231. package/dist/cjs/workflow/syncParallel.js +0 -55
  232. package/dist/esm/index.js +0 -882
  233. package/dist/esm-node/farrow-pipeline/context.js +0 -20
  234. package/dist/esm-node/farrow-pipeline/counter.js +0 -13
  235. package/dist/esm-node/farrow-pipeline/index.js +0 -60
  236. package/dist/esm-node/index.js +0 -4
  237. package/dist/esm-node/manager/async.js +0 -106
  238. package/dist/esm-node/manager/index.js +0 -3
  239. package/dist/esm-node/manager/shared.js +0 -32
  240. package/dist/esm-node/manager/sync.js +0 -172
  241. package/dist/esm-node/waterfall/async.js +0 -42
  242. package/dist/esm-node/waterfall/index.js +0 -2
  243. package/dist/esm-node/waterfall/sync.js +0 -41
  244. package/dist/esm-node/workflow/async.js +0 -35
  245. package/dist/esm-node/workflow/index.js +0 -5
  246. package/dist/esm-node/workflow/interrupt.js +0 -39
  247. package/dist/esm-node/workflow/parallel.js +0 -28
  248. package/dist/esm-node/workflow/sync.js +0 -31
  249. package/dist/esm-node/workflow/syncParallel.js +0 -30
  250. package/dist/types/farrow-pipeline/context.d.ts +0 -12
  251. package/dist/types/farrow-pipeline/counter.d.ts +0 -11
  252. package/dist/types/farrow-pipeline/index.d.ts +0 -29
  253. package/dist/types/manager/async.d.ts +0 -54
  254. package/dist/types/manager/index.d.ts +0 -3
  255. package/dist/types/manager/shared.d.ts +0 -12
  256. package/dist/types/manager/sync.d.ts +0 -66
  257. package/dist/types/manager/types.d.ts +0 -33
  258. package/dist/types/waterfall/async.d.ts +0 -21
  259. package/dist/types/waterfall/index.d.ts +0 -2
  260. package/dist/types/waterfall/sync.d.ts +0 -20
  261. package/dist/types/workflow/async.d.ts +0 -12
  262. package/dist/types/workflow/index.d.ts +0 -5
  263. package/dist/types/workflow/interrupt.d.ts +0 -12
  264. package/dist/types/workflow/parallel.d.ts +0 -10
  265. package/dist/types/workflow/sync.d.ts +0 -11
  266. package/dist/types/workflow/syncParallel.d.ts +0 -10
  267. /package/dist/esm-node/{manager/types.js → cli/run/types.mjs} +0 -0
@@ -1,11 +0,0 @@
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 type Next<I = unknown, O = unknown> = (input?: I) => O;
6
- export type CounterCallback<I = unknown, O = unknown> = (index: number, input: I, next: Next<I, O>) => O;
7
- export 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>;
@@ -1,29 +0,0 @@
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 { type Context, createContext } from './context';
6
- import { type Next } from './counter';
7
- export type { Next };
8
- export { createContext };
9
- export type { Context };
10
- export type Middleware<I = unknown, O = unknown> = (input: I, next: Next<I, O>) => O;
11
- export type Middlewares<I = unknown, O = unknown> = Middleware<I, O>[];
12
- export declare const isPipeline: (input: any) => input is Pipeline;
13
- declare const PipelineSymbol: unique symbol;
14
- export type RunPipelineOptions<I = unknown, O = unknown> = {
15
- onLast?: (input: I) => O;
16
- };
17
- export type MiddlewareInput<I = unknown, O = unknown> = Middleware<I, O> | {
18
- middleware: Middleware<I, O>;
19
- };
20
- export 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 type MaybeAsync<T> = T | Promise<T>;
28
- export type AsyncPipeline<I = unknown, O = unknown> = Pipeline<I, MaybeAsync<O>>;
29
- export declare const createAsyncPipeline: <I, O>() => AsyncPipeline<I, O>;
@@ -1,54 +0,0 @@
1
- import type { CommonAPI, PluginOptions, ToRunners, ToThreads } from './types';
2
- /** Setup function of async plugin. */
3
- export type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
4
- declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
5
- export type AsyncPlugin<Hooks, API> = {
6
- ASYNC_PLUGIN_SYMBOL: typeof ASYNC_PLUGIN_SYMBOL;
7
- } & Required<PluginOptions<Hooks, AsyncSetup<Hooks, API>>>;
8
- export type AsyncManager<Hooks, API> = {
9
- /**
10
- * Create a sync plugin.
11
- * @param setup the setup function.
12
- * @param options optional plugin options.
13
- */
14
- createPlugin: (setup?: AsyncSetup<Hooks, API>, options?: PluginOptions<Hooks, AsyncSetup<Hooks, API>>) => AsyncPlugin<Hooks, API>;
15
- /**
16
- * Determine if a value is a async plugin.
17
- * @param input
18
- */
19
- isPlugin: (input: unknown) => input is AsyncPlugin<Hooks, API>;
20
- /**
21
- * Register new plugins to current manager.
22
- * @param plugins one or more plugin.
23
- */
24
- usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
25
- /**
26
- * Init manager, it will call the setup function of all registered plugins.
27
- */
28
- init: () => Promise<ToRunners<Hooks>>;
29
- /**
30
- * Run callback function.
31
- * @param callback
32
- */
33
- run: <O>(cb: () => O) => O;
34
- /**
35
- * Register new hooks.
36
- * @param newHooks
37
- */
38
- registerHook: (newHooks: Partial<Hooks>) => void;
39
- /**
40
- * Return a cloned manager.
41
- * @param overrideAPI override the default plugin API.
42
- */
43
- clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => AsyncManager<Hooks, API>;
44
- /**
45
- * Clear all registered plugins.
46
- */
47
- clear: () => void;
48
- /**
49
- * Get all runner functions of the hooks.
50
- */
51
- useRunner: () => ToRunners<Hooks>;
52
- };
53
- export declare const createAsyncManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks>, api?: API) => AsyncManager<Hooks, API>;
54
- export {};
@@ -1,3 +0,0 @@
1
- export * from './sync';
2
- export * from './async';
3
- export * from './types';
@@ -1,12 +0,0 @@
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>;
@@ -1,66 +0,0 @@
1
- import type { CommonAPI, Hook, PluginOptions, ToRunners, ToThreads } from './types';
2
- /** Setup function of sync plugin. */
3
- export type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
4
- declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
5
- export type Plugin<Hooks, API> = {
6
- SYNC_PLUGIN_SYMBOL: typeof SYNC_PLUGIN_SYMBOL;
7
- } & Required<PluginOptions<Hooks, Setup<Hooks, API>>>;
8
- export type Manager<Hooks, API> = {
9
- /**
10
- * Create a sync plugin.
11
- * @param setup the setup function.
12
- * @param options optional plugin options.
13
- */
14
- createPlugin: (setup?: Setup<Hooks, API>, options?: PluginOptions<Hooks, Setup<Hooks, API>>) => Plugin<Hooks, API>;
15
- /**
16
- * Determine if a value is a sync plugin.
17
- * @param input
18
- */
19
- isPlugin: (input: unknown) => input is Plugin<Hooks, API>;
20
- /**
21
- * Register new plugins to current manager.
22
- * @param plugins one or more plugin.
23
- */
24
- usePlugin: (...plugins: Array<Plugin<Hooks, API> | PluginOptions<Hooks, Setup<Hooks, API>> | (() => PluginOptions<Hooks, Setup<Hooks, API>>)>) => Manager<Hooks, API>;
25
- /**
26
- * Init manager, it will call the setup function of all registered plugins.
27
- */
28
- init: () => ToRunners<Hooks>;
29
- /**
30
- * Run callback function.
31
- * @param callback
32
- */
33
- run: <O>(cb: () => O) => O;
34
- /**
35
- * Register new hooks.
36
- * @param newHooks
37
- */
38
- registerHook: (hewHooks: Partial<Hooks>) => void;
39
- /**
40
- * Clear all registered plugins.
41
- */
42
- clear: () => void;
43
- /**
44
- * Return a cloned manager.
45
- * @param overrideAPI override the default plugin API.
46
- */
47
- clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => Manager<Hooks, API>;
48
- /**
49
- * Get all runner functions of the hooks.
50
- */
51
- useRunner: () => ToRunners<Hooks>;
52
- };
53
- export declare const DEFAULT_OPTIONS: {
54
- name: string;
55
- pre: never[];
56
- post: never[];
57
- rivals: never[];
58
- required: never[];
59
- usePlugins: never[];
60
- registerHook: {};
61
- };
62
- export declare const createManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks>, api?: API) => Manager<Hooks, API>;
63
- export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], hooksMap?: Hooks) => ToRunners<Hooks>;
64
- export declare const cloneHook: (hook: Hook) => Hook;
65
- export declare const cloneHooksMap: <Hooks>(record: Hooks) => Hooks;
66
- export {};
@@ -1,33 +0,0 @@
1
- import type { AsyncPipeline, MaybeAsync, Middleware, Pipeline } from '../farrow-pipeline';
2
- import type { AsyncBrook, AsyncWaterfall, Brook, Waterfall } from '../waterfall';
3
- import type { AsyncInterruptWorker, AsyncInterruptWorkflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow, SyncParallelWorkflow, Worker, Workflow } from '../workflow';
4
- /** All hook types. */
5
- export type Hook = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | SyncParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any> | AsyncInterruptWorkflow<any, any>;
6
- export type HooksMap = Record<string, Hook>;
7
- /** Extract the type of callback function from a hook. */
8
- export 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 SyncParallelWorkflow<infer I, infer O> ? Worker<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>> : P extends AsyncInterruptWorkflow<infer I, infer O> ? AsyncInterruptWorker<I, O> : never;
9
- /** Extract types of callback function from hooks. */
10
- export type ToThreads<PS> = {
11
- [K in keyof PS]: PS[K] extends Hook ? ToThread<PS[K]> : PS[K] extends void ? void : never;
12
- };
13
- /** Extract run method from a hook. */
14
- export 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 SyncParallelWorkflow<infer I, infer O> ? SyncParallelWorkflow<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'] : P extends AsyncInterruptWorkflow<infer I, infer O> ? AsyncInterruptWorkflow<I, O>['run'] : never;
15
- /** Extract all run methods from hooks. */
16
- export type ToRunners<PS> = {
17
- [K in keyof PS]: PS[K] extends Hook ? RunnerFromHook<PS[K]> : PS[K] extends void ? void : never;
18
- };
19
- /** All options to define a plugin. */
20
- export type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string, unknown>> = {
21
- name?: string;
22
- pre?: string[];
23
- post?: string[];
24
- setup?: Setup;
25
- rivals?: string[];
26
- required?: string[];
27
- usePlugins?: PluginOptions<any, any>[];
28
- registerHook?: Partial<Hooks & ExtendHooks>;
29
- };
30
- /** Common api of setup function. */
31
- export type CommonAPI<Hooks> = {
32
- useHookRunners: () => ToRunners<Hooks>;
33
- };
@@ -1,21 +0,0 @@
1
- import { type MaybeAsync } from '../farrow-pipeline';
2
- declare const ASYNC_WATERFALL_SYMBOL: unique symbol;
3
- export type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
4
- export type AsyncBrookInput<I = unknown> = AsyncBrook<I> | {
5
- middleware: AsyncBrook<I>;
6
- };
7
- export type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
8
- export type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
9
- export declare const getAsyncBrook: <I>(input: AsyncBrookInput<I>) => AsyncBrook<I>;
10
- export type RunAsyncWaterfallOptions<I = unknown> = {
11
- onLast?: AsyncBrook<I>;
12
- };
13
- export 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 {};
@@ -1,2 +0,0 @@
1
- export * from './sync';
2
- export * from './async';
@@ -1,20 +0,0 @@
1
- declare const WATERFALL_SYMBOL: unique symbol;
2
- export type Brook<I = unknown> = (I: I) => I;
3
- export type BrookInput<I = unknown> = Brook<I> | {
4
- middleware: Brook<I>;
5
- };
6
- export type Brooks<I = unknown> = Brook<I>[];
7
- export type BrookInputs<I = unknown> = BrookInput<I>[];
8
- export declare const getBrook: <I>(input: BrookInput<I>) => Brook<I>;
9
- export type RunWaterfallOptions<I = unknown> = {
10
- onLast?: Brook<I>;
11
- };
12
- export 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 {};
@@ -1,12 +0,0 @@
1
- import { type MaybeAsync } from '../farrow-pipeline';
2
- declare const ASYNC_WORKFLOW_SYMBOL: unique symbol;
3
- export type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
4
- export type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
5
- export 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 {};
@@ -1,5 +0,0 @@
1
- export * from './sync';
2
- export * from './syncParallel';
3
- export * from './parallel';
4
- export * from './async';
5
- export * from './interrupt';
@@ -1,12 +0,0 @@
1
- import { type MaybeAsync } from '../farrow-pipeline';
2
- declare const ASYNC_INTERRUPT_WORKFLOW_SYMBOL: unique symbol;
3
- export type AsyncInterruptWorker<I, O> = (I: I, interrupt: (result: any) => void) => MaybeAsync<O>;
4
- export type AsyncInterruptWorkers<I, O> = AsyncInterruptWorker<I, O>[];
5
- export type AsyncInterruptWorkflow<I, O> = {
6
- run: (input: I) => MaybeAsync<O[]>;
7
- use: (...I: AsyncInterruptWorkers<I, O>) => AsyncInterruptWorkflow<I, O>;
8
- [ASYNC_INTERRUPT_WORKFLOW_SYMBOL]: true;
9
- };
10
- export declare const isAsyncInterruptWorkflow: (input: any) => input is AsyncInterruptWorkflow<any, any>;
11
- export declare const createAsyncInterruptWorkflow: <I = void, O = unknown>() => AsyncInterruptWorkflow<I, O>;
12
- export {};
@@ -1,10 +0,0 @@
1
- import type { AsyncWorkers } from './async';
2
- declare const PARALLEL_WORKFLOW_SYMBOL: unique symbol;
3
- export 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>;
9
- export declare const createParallelWorkflow: <I = void, O = unknown>() => ParallelWorkflow<I, O>;
10
- export {};
@@ -1,11 +0,0 @@
1
- declare const WORKFLOW_SYMBOL: unique symbol;
2
- export type Worker<I, O> = (I: I) => O;
3
- export type Workers<I, O> = Worker<I, O>[];
4
- export 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 {};
@@ -1,10 +0,0 @@
1
- import type { Workers } from './sync';
2
- declare const SYNC_PARALLEL_WORKFLOW_SYMBOL: unique symbol;
3
- export type SyncParallelWorkflow<I, O = any> = {
4
- run: (input: I) => O[];
5
- use: (...I: Workers<I, O>) => SyncParallelWorkflow<I, O>;
6
- [SYNC_PARALLEL_WORKFLOW_SYMBOL]: true;
7
- };
8
- export declare const isSyncParallelWorkflow: (input: any) => input is SyncParallelWorkflow<any>;
9
- export declare const createSyncParallelWorkflow: <I = void, O = unknown>() => SyncParallelWorkflow<I, O>;
10
- export {};