@modern-js/plugin 1.2.0 → 1.3.1
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.
- package/CHANGELOG.md +16 -0
- package/dist/js/modern/manager/async.js +59 -28
- package/dist/js/modern/manager/index.js +2 -1
- package/dist/js/modern/manager/sync.js +79 -60
- package/dist/js/modern/manager/types.js +0 -0
- package/dist/js/modern/waterfall/async.js +4 -5
- package/dist/js/modern/waterfall/sync.js +0 -1
- package/dist/js/modern/workflow/async.js +1 -2
- package/dist/js/modern/workflow/sync.js +0 -1
- package/dist/js/node/manager/async.js +57 -25
- package/dist/js/node/manager/index.js +13 -0
- package/dist/js/node/manager/sync.js +84 -58
- package/dist/js/node/manager/types.js +0 -0
- package/dist/js/node/waterfall/async.js +4 -5
- package/dist/js/node/waterfall/sync.js +0 -1
- package/dist/js/node/workflow/async.js +1 -2
- package/dist/js/node/workflow/sync.js +0 -1
- package/dist/js/treeshaking/manager/async.js +63 -34
- package/dist/js/treeshaking/manager/index.js +2 -1
- package/dist/js/treeshaking/manager/sync.js +85 -62
- package/dist/js/treeshaking/manager/types.js +0 -0
- package/dist/js/treeshaking/waterfall/async.js +4 -5
- package/dist/js/treeshaking/waterfall/sync.js +0 -1
- package/dist/js/treeshaking/workflow/async.js +1 -2
- package/dist/js/treeshaking/workflow/sync.js +0 -1
- package/dist/types/manager/async.d.ts +60 -21
- package/dist/types/manager/index.d.ts +2 -1
- package/dist/types/manager/sync.d.ts +74 -43
- package/dist/types/manager/types.d.ts +41 -0
- package/dist/types/waterfall/async.d.ts +2 -2
- package/package.json +2 -1
- package/tests/async.test.ts +143 -22
- package/tests/fixtures/async/core/index.ts +12 -4
- package/tests/fixtures/async/dynamic/foo.ts +2 -2
- package/tests/fixtures/sync/core/index.ts +9 -4
- package/tests/fixtures/sync/dynamic/foo.ts +2 -2
- package/tests/sync.test.ts +136 -21
- package/src/index.ts +0 -5
- package/src/manager/async.ts +0 -248
- package/src/manager/index.ts +0 -3
- package/src/manager/runner.ts +0 -15
- package/src/manager/sync.ts +0 -458
- package/src/waterfall/async.ts +0 -109
- package/src/waterfall/index.ts +0 -2
- package/src/waterfall/sync.ts +0 -110
- package/src/workflow/async.ts +0 -96
- package/src/workflow/index.ts +0 -3
- package/src/workflow/parallel.ts +0 -97
- package/src/workflow/sync.ts +0 -82
package/src/workflow/async.ts
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
import { MaybeAsync, createAsyncPipeline, Middleware } from 'farrow-pipeline';
|
2
|
-
import type { RunWorkflowOptions } from './sync';
|
3
|
-
|
4
|
-
const ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
|
5
|
-
|
6
|
-
export type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
|
7
|
-
export type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
|
8
|
-
|
9
|
-
export type AsyncWorkflow<I, O> = {
|
10
|
-
run: (input: I, options?: RunWorkflowOptions) => MaybeAsync<O[]>;
|
11
|
-
use: (...I: AsyncWorkers<I, O>) => AsyncWorkflow<I, O>;
|
12
|
-
[ASYNC_WORKFLOW_SYMBOL]: true;
|
13
|
-
};
|
14
|
-
|
15
|
-
export type AsyncWorkflow2AsyncWorker<W extends AsyncWorkflow<any, any>> =
|
16
|
-
W extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : never;
|
17
|
-
|
18
|
-
export type AsyncWorkflowRecord = Record<string, AsyncWorkflow<any, any>>;
|
19
|
-
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
21
|
-
export type AsyncWorkflows2AsyncWorkers<PS extends AsyncWorkflowRecord | void> =
|
22
|
-
{
|
23
|
-
[K in keyof PS]: PS[K] extends AsyncWorkflow<any, any>
|
24
|
-
? AsyncWorkflow2AsyncWorker<PS[K]>
|
25
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
26
|
-
PS[K] extends void
|
27
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
28
|
-
void
|
29
|
-
: never;
|
30
|
-
};
|
31
|
-
|
32
|
-
export type RunnerFromAsyncWorkflow<W extends AsyncWorkflow<any, any>> =
|
33
|
-
W extends AsyncWorkflow<infer I, infer O>
|
34
|
-
? AsyncWorkflow<I, O>['run']
|
35
|
-
: never;
|
36
|
-
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
38
|
-
export type AsyncWorkflows2Runners<PS extends AsyncWorkflowRecord | void> = {
|
39
|
-
[K in keyof PS]: PS[K] extends AsyncWorkflow<any, any>
|
40
|
-
? RunnerFromAsyncWorkflow<PS[K]>
|
41
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
42
|
-
PS[K] extends void
|
43
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
44
|
-
void
|
45
|
-
: never;
|
46
|
-
};
|
47
|
-
|
48
|
-
export const isAsyncWorkflow = (input: any): input is AsyncWorkflow<any, any> =>
|
49
|
-
Boolean(input?.[ASYNC_WORKFLOW_SYMBOL]);
|
50
|
-
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
52
|
-
export const createAsyncWorkflow = <I = void, O = unknown>(): AsyncWorkflow<
|
53
|
-
I,
|
54
|
-
O
|
55
|
-
> => {
|
56
|
-
const pipeline = createAsyncPipeline<I, O[]>();
|
57
|
-
|
58
|
-
const use: AsyncWorkflow<I, O>['use'] = (...input) => {
|
59
|
-
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
60
|
-
return workflow;
|
61
|
-
};
|
62
|
-
|
63
|
-
const run: AsyncWorkflow<I, O>['run'] = async (input, options) => {
|
64
|
-
const result = pipeline.run(input, { ...options, onLast: () => [] });
|
65
|
-
if (isPromise(result)) {
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow,promise/prefer-await-to-then
|
67
|
-
return result.then(result => result.filter(Boolean));
|
68
|
-
} else {
|
69
|
-
return result.filter(Boolean);
|
70
|
-
}
|
71
|
-
};
|
72
|
-
|
73
|
-
const workflow: AsyncWorkflow<I, O> = {
|
74
|
-
...pipeline,
|
75
|
-
use,
|
76
|
-
run,
|
77
|
-
[ASYNC_WORKFLOW_SYMBOL]: true as const,
|
78
|
-
};
|
79
|
-
|
80
|
-
return workflow;
|
81
|
-
};
|
82
|
-
|
83
|
-
const mapAsyncWorkerToAsyncMiddleware =
|
84
|
-
<I, O>(worker: AsyncWorker<I, O>): Middleware<I, MaybeAsync<O[]>> =>
|
85
|
-
async (input, next) =>
|
86
|
-
[await worker(input), ...(await next(input))];
|
87
|
-
|
88
|
-
function isPromise(obj: any): obj is Promise<any> {
|
89
|
-
/* eslint-disable promise/prefer-await-to-then */
|
90
|
-
return (
|
91
|
-
Boolean(obj) &&
|
92
|
-
(typeof obj === 'object' || typeof obj === 'function') &&
|
93
|
-
typeof obj.then === 'function'
|
94
|
-
);
|
95
|
-
/* eslint-enable promise/prefer-await-to-then */
|
96
|
-
}
|
package/src/workflow/index.ts
DELETED
package/src/workflow/parallel.ts
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
import { MaybeAsync, createPipeline, Middleware } from 'farrow-pipeline';
|
2
|
-
import type { AsyncWorker, AsyncWorkers } from './async';
|
3
|
-
import type { RunWorkflowOptions } from './sync';
|
4
|
-
|
5
|
-
const PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
|
6
|
-
|
7
|
-
export type ParallelWorkflow<I, O = any> = {
|
8
|
-
run: (input: I, options?: RunWorkflowOptions) => Promise<O[]>;
|
9
|
-
use: (...I: AsyncWorkers<I, O>) => ParallelWorkflow<I, O>;
|
10
|
-
[PARALLEL_WORKFLOW_SYMBOL]: true;
|
11
|
-
};
|
12
|
-
|
13
|
-
export type ParallelWorkflow2Worker<W extends ParallelWorkflow<any>> =
|
14
|
-
W extends ParallelWorkflow<infer CS, infer O> ? AsyncWorker<CS, O> : never;
|
15
|
-
|
16
|
-
export type ParallelWorkflowRecord = Record<string, ParallelWorkflow<any>>;
|
17
|
-
|
18
|
-
export type ParallelWorkflows2Workers<
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
20
|
-
PS extends ParallelWorkflowRecord | void,
|
21
|
-
> = {
|
22
|
-
[K in keyof PS]: PS[K] extends ParallelWorkflow<any>
|
23
|
-
? ParallelWorkflow2Worker<PS[K]>
|
24
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
25
|
-
PS[K] extends void
|
26
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
27
|
-
void
|
28
|
-
: never;
|
29
|
-
};
|
30
|
-
|
31
|
-
export type ParallelWorkflows2AsyncWorkers<
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
33
|
-
PS extends ParallelWorkflowRecord | void,
|
34
|
-
> = {
|
35
|
-
[K in keyof PS]: PS[K] extends ParallelWorkflow<any>
|
36
|
-
? ParallelWorkflow2Worker<PS[K]>
|
37
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
38
|
-
PS[K] extends void
|
39
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
40
|
-
void
|
41
|
-
: never;
|
42
|
-
};
|
43
|
-
|
44
|
-
export type RunnerFromParallelWorkflow<W extends ParallelWorkflow<any>> =
|
45
|
-
W extends ParallelWorkflow<infer CS, infer O>
|
46
|
-
? ParallelWorkflow<CS, O>['run']
|
47
|
-
: never;
|
48
|
-
|
49
|
-
export type ParallelWorkflows2Runners<
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
51
|
-
PS extends ParallelWorkflowRecord | void,
|
52
|
-
> = {
|
53
|
-
[K in keyof PS]: PS[K] extends ParallelWorkflow<any>
|
54
|
-
? RunnerFromParallelWorkflow<PS[K]>
|
55
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
56
|
-
PS[K] extends void
|
57
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
58
|
-
void
|
59
|
-
: never;
|
60
|
-
};
|
61
|
-
|
62
|
-
export const isParallelWorkflow = (
|
63
|
-
input: any,
|
64
|
-
): input is ParallelWorkflow<any> => Boolean(input?.[PARALLEL_WORKFLOW_SYMBOL]);
|
65
|
-
|
66
|
-
export const createParallelWorkflow = <
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
68
|
-
I = void,
|
69
|
-
O = unknown,
|
70
|
-
>(): ParallelWorkflow<I, O> => {
|
71
|
-
const pipeline = createPipeline<I, MaybeAsync<O>[]>();
|
72
|
-
|
73
|
-
const use: ParallelWorkflow<I, O>['use'] = (...input) => {
|
74
|
-
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
75
|
-
return workflow;
|
76
|
-
};
|
77
|
-
|
78
|
-
const run: ParallelWorkflow<I, O>['run'] = async (input, options) =>
|
79
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
80
|
-
Promise.all(pipeline.run(input, { ...options, onLast: () => [] })).then(
|
81
|
-
result => result.filter(Boolean),
|
82
|
-
);
|
83
|
-
|
84
|
-
const workflow: ParallelWorkflow<I, O> = {
|
85
|
-
...pipeline,
|
86
|
-
run,
|
87
|
-
use,
|
88
|
-
[PARALLEL_WORKFLOW_SYMBOL]: true as const,
|
89
|
-
};
|
90
|
-
|
91
|
-
return workflow;
|
92
|
-
};
|
93
|
-
|
94
|
-
const mapParallelWorkerToAsyncMiddleware =
|
95
|
-
<I, O>(worker: AsyncWorker<I, O>): Middleware<I, MaybeAsync<O>[]> =>
|
96
|
-
(input, next) =>
|
97
|
-
[worker(input), ...next(input)];
|
package/src/workflow/sync.ts
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
import { Container, createPipeline, Middleware } from 'farrow-pipeline';
|
2
|
-
|
3
|
-
const WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
4
|
-
|
5
|
-
export type Worker<I, O> = (I: I) => O;
|
6
|
-
export type Workers<I, O> = Worker<I, O>[];
|
7
|
-
|
8
|
-
export type RunWorkflowOptions = {
|
9
|
-
container?: Container;
|
10
|
-
};
|
11
|
-
|
12
|
-
export type Workflow<I, O> = {
|
13
|
-
run: (input: I, options?: RunWorkflowOptions) => void;
|
14
|
-
use: (...I: Workers<I, O>) => Workflow<I, O>;
|
15
|
-
[WORKFLOW_SYMBOL]: true;
|
16
|
-
};
|
17
|
-
|
18
|
-
export type Workflow2Worker<W extends Workflow<any, any>> = W extends Workflow<
|
19
|
-
infer I,
|
20
|
-
infer O
|
21
|
-
>
|
22
|
-
? Worker<I, O>
|
23
|
-
: never;
|
24
|
-
|
25
|
-
export type WorkflowRecord = Record<string, Workflow<any, any>>;
|
26
|
-
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
28
|
-
export type Workflows2Workers<PS extends WorkflowRecord | void> = {
|
29
|
-
[K in keyof PS]: PS[K] extends Workflow<any, any>
|
30
|
-
? Workflow2Worker<PS[K]>
|
31
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
32
|
-
PS[K] extends void
|
33
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
34
|
-
void
|
35
|
-
: never;
|
36
|
-
};
|
37
|
-
|
38
|
-
export type RunnerFromWorkflow<W extends Workflow<any, any>> =
|
39
|
-
W extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : never;
|
40
|
-
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
42
|
-
export type Workflows2Runners<PS extends WorkflowRecord | void> = {
|
43
|
-
[K in keyof PS]: PS[K] extends Workflow<any, any>
|
44
|
-
? RunnerFromWorkflow<PS[K]>
|
45
|
-
: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
46
|
-
PS[K] extends void
|
47
|
-
? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
48
|
-
void
|
49
|
-
: never;
|
50
|
-
};
|
51
|
-
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
53
|
-
export const createWorkflow = <I = void, O = unknown>(): Workflow<I, O> => {
|
54
|
-
const pipeline = createPipeline<I, O[]>();
|
55
|
-
|
56
|
-
const use: Workflow<I, O>['use'] = (...input) => {
|
57
|
-
pipeline.use(...input.map(mapWorkerToMiddleware));
|
58
|
-
return workflow;
|
59
|
-
};
|
60
|
-
|
61
|
-
const run: Workflow<I, O>['run'] = async (input, options) => {
|
62
|
-
const result = pipeline.run(input, { ...options, onLast: () => [] });
|
63
|
-
return result.filter(Boolean);
|
64
|
-
};
|
65
|
-
|
66
|
-
const workflow: Workflow<I, O> = {
|
67
|
-
...pipeline,
|
68
|
-
use,
|
69
|
-
run,
|
70
|
-
[WORKFLOW_SYMBOL]: true as const,
|
71
|
-
};
|
72
|
-
|
73
|
-
return workflow;
|
74
|
-
};
|
75
|
-
|
76
|
-
export const isWorkflow = (input: any): input is Workflow<unknown, unknown> =>
|
77
|
-
Boolean(input?.[WORKFLOW_SYMBOL]);
|
78
|
-
|
79
|
-
const mapWorkerToMiddleware =
|
80
|
-
<I, O>(worker: Worker<I, O>): Middleware<I, O[]> =>
|
81
|
-
(input, next) =>
|
82
|
-
[worker(input), ...next(input)];
|