mepcli 1.4.0 → 2.0.0-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.
- package/README.md +43 -12
- package/dist/{ansi.js → src/ansi.js} +17 -9
- package/dist/src/ansi.js.map +1 -0
- package/dist/{base.js → src/base.js} +82 -70
- package/dist/src/base.js.map +1 -0
- package/dist/{core.js → src/core.js} +266 -322
- package/dist/src/core.js.map +1 -0
- package/dist/src/data/countries.js +569 -0
- package/dist/src/data/countries.js.map +1 -0
- package/dist/src/data/licenses.js +480 -0
- package/dist/src/data/licenses.js.map +1 -0
- package/dist/{highlight.js → src/highlight.js} +77 -69
- package/dist/src/highlight.js.map +1 -0
- package/dist/src/index.js +66 -0
- package/dist/src/index.js.map +1 -0
- package/dist/{input.js → src/input.js} +47 -41
- package/dist/src/input.js.map +1 -0
- package/dist/{pipeline.js → src/pipeline.js} +120 -93
- package/dist/src/pipeline.js.map +1 -0
- package/dist/{prompts → src/prompts}/autocomplete.js +58 -57
- package/dist/src/prompts/autocomplete.js.map +1 -0
- package/dist/{prompts → src/prompts}/box.js +86 -53
- package/dist/src/prompts/box.js.map +1 -0
- package/dist/{prompts → src/prompts}/breadcrumb-search.js +110 -98
- package/dist/src/prompts/breadcrumb-search.js.map +1 -0
- package/dist/{prompts → src/prompts}/breadcrumb.js +126 -121
- package/dist/src/prompts/breadcrumb.js.map +1 -0
- package/dist/{prompts → src/prompts}/byte.js +69 -52
- package/dist/src/prompts/byte.js.map +1 -0
- package/dist/{prompts → src/prompts}/calculator.js +79 -56
- package/dist/src/prompts/calculator.js.map +1 -0
- package/dist/{prompts → src/prompts}/calendar.js +167 -127
- package/dist/src/prompts/calendar.js.map +1 -0
- package/dist/{prompts → src/prompts}/checkbox.js +53 -49
- package/dist/src/prompts/checkbox.js.map +1 -0
- package/dist/{prompts → src/prompts}/code.js +88 -76
- package/dist/src/prompts/code.js.map +1 -0
- package/dist/{prompts → src/prompts}/color.js +68 -50
- package/dist/src/prompts/color.js.map +1 -0
- package/dist/{prompts → src/prompts}/confirm.js +22 -15
- package/dist/src/prompts/confirm.js.map +1 -0
- package/dist/{prompts → src/prompts}/connection-string.js +59 -36
- package/dist/src/prompts/connection-string.js.map +1 -0
- package/dist/{prompts → src/prompts}/cron.js +90 -59
- package/dist/src/prompts/cron.js.map +1 -0
- package/dist/src/prompts/curl-utils.js +71 -0
- package/dist/src/prompts/curl-utils.js.map +1 -0
- package/dist/{prompts → src/prompts}/curl.js +153 -132
- package/dist/src/prompts/curl.js.map +1 -0
- package/dist/{prompts → src/prompts}/data-inspector.js +96 -91
- package/dist/src/prompts/data-inspector.js.map +1 -0
- package/dist/{prompts → src/prompts}/date.js +64 -57
- package/dist/src/prompts/date.js.map +1 -0
- package/dist/{prompts → src/prompts}/dependency.js +84 -80
- package/dist/src/prompts/dependency.js.map +1 -0
- package/dist/{prompts → src/prompts}/dial.js +49 -35
- package/dist/src/prompts/dial.js.map +1 -0
- package/dist/src/prompts/diff.js +118 -0
- package/dist/src/prompts/diff.js.map +1 -0
- package/dist/{prompts → src/prompts}/draw.js +83 -80
- package/dist/src/prompts/draw.js.map +1 -0
- package/dist/src/prompts/editor.js +234 -0
- package/dist/src/prompts/editor.js.map +1 -0
- package/dist/{prompts → src/prompts}/emoji.js +80 -82
- package/dist/src/prompts/emoji.js.map +1 -0
- package/dist/{prompts → src/prompts}/exec.js +60 -46
- package/dist/src/prompts/exec.js.map +1 -0
- package/dist/src/prompts/file.js +217 -0
- package/dist/src/prompts/file.js.map +1 -0
- package/dist/{prompts → src/prompts}/form.js +63 -54
- package/dist/src/prompts/form.js.map +1 -0
- package/dist/{prompts → src/prompts}/fuzzy-multi-column.js +65 -53
- package/dist/src/prompts/fuzzy-multi-column.js.map +1 -0
- package/dist/{prompts → src/prompts}/fuzzy.js +66 -55
- package/dist/src/prompts/fuzzy.js.map +1 -0
- package/dist/src/prompts/gauge.js +137 -0
- package/dist/src/prompts/gauge.js.map +1 -0
- package/dist/{prompts → src/prompts}/grid.js +70 -57
- package/dist/src/prompts/grid.js.map +1 -0
- package/dist/{prompts → src/prompts}/heatmap.js +70 -64
- package/dist/src/prompts/heatmap.js.map +1 -0
- package/dist/{prompts → src/prompts}/ip.js +56 -36
- package/dist/src/prompts/ip.js.map +1 -0
- package/dist/{prompts → src/prompts}/kanban.js +63 -58
- package/dist/src/prompts/kanban.js.map +1 -0
- package/dist/src/prompts/keypress.js +54 -0
- package/dist/src/prompts/keypress.js.map +1 -0
- package/dist/src/prompts/license.js +144 -0
- package/dist/src/prompts/license.js.map +1 -0
- package/dist/{prompts → src/prompts}/list.js +46 -31
- package/dist/src/prompts/list.js.map +1 -0
- package/dist/{prompts → src/prompts}/map.js +93 -77
- package/dist/src/prompts/map.js.map +1 -0
- package/dist/{prompts → src/prompts}/match.js +91 -95
- package/dist/src/prompts/match.js.map +1 -0
- package/dist/{prompts → src/prompts}/miller.js +74 -67
- package/dist/src/prompts/miller.js.map +1 -0
- package/dist/{prompts → src/prompts}/multi-column-select.js +54 -44
- package/dist/src/prompts/multi-column-select.js.map +1 -0
- package/dist/{prompts → src/prompts}/multi-range.js +70 -52
- package/dist/src/prompts/multi-range.js.map +1 -0
- package/dist/{prompts → src/prompts}/multi-select.js +67 -58
- package/dist/src/prompts/multi-select.js.map +1 -0
- package/dist/{prompts → src/prompts}/number.js +51 -39
- package/dist/src/prompts/number.js.map +1 -0
- package/dist/{prompts → src/prompts}/otp.js +43 -27
- package/dist/src/prompts/otp.js.map +1 -0
- package/dist/{prompts → src/prompts}/pattern.js +74 -71
- package/dist/src/prompts/pattern.js.map +1 -0
- package/dist/{prompts → src/prompts}/phone.js +107 -118
- package/dist/src/prompts/phone.js.map +1 -0
- package/dist/src/prompts/quiz-select.js +114 -0
- package/dist/src/prompts/quiz-select.js.map +1 -0
- package/dist/src/prompts/quiz-text.js +98 -0
- package/dist/src/prompts/quiz-text.js.map +1 -0
- package/dist/{prompts → src/prompts}/range.js +85 -61
- package/dist/src/prompts/range.js.map +1 -0
- package/dist/{prompts → src/prompts}/rating.js +29 -24
- package/dist/src/prompts/rating.js.map +1 -0
- package/dist/{prompts → src/prompts}/regex.js +50 -36
- package/dist/src/prompts/regex.js.map +1 -0
- package/dist/{prompts → src/prompts}/region.js +62 -56
- package/dist/src/prompts/region.js.map +1 -0
- package/dist/{prompts → src/prompts}/schedule.js +82 -75
- package/dist/src/prompts/schedule.js.map +1 -0
- package/dist/{prompts → src/prompts}/scroll.js +61 -58
- package/dist/src/prompts/scroll.js.map +1 -0
- package/dist/src/prompts/seat.js +164 -0
- package/dist/src/prompts/seat.js.map +1 -0
- package/dist/{prompts → src/prompts}/select-range.js +58 -46
- package/dist/src/prompts/select-range.js.map +1 -0
- package/dist/{prompts → src/prompts}/select.js +65 -66
- package/dist/src/prompts/select.js.map +1 -0
- package/dist/{prompts → src/prompts}/semver.js +24 -13
- package/dist/src/prompts/semver.js.map +1 -0
- package/dist/src/prompts/shortcut.js +133 -0
- package/dist/src/prompts/shortcut.js.map +1 -0
- package/dist/{prompts → src/prompts}/slider.js +28 -23
- package/dist/src/prompts/slider.js.map +1 -0
- package/dist/src/prompts/slot.js +117 -0
- package/dist/src/prompts/slot.js.map +1 -0
- package/dist/{prompts → src/prompts}/snippet.js +82 -61
- package/dist/src/prompts/snippet.js.map +1 -0
- package/dist/{prompts → src/prompts}/sort-grid.js +64 -59
- package/dist/src/prompts/sort-grid.js.map +1 -0
- package/dist/{prompts → src/prompts}/sort.js +59 -49
- package/dist/src/prompts/sort.js.map +1 -0
- package/dist/src/prompts/spam.js +80 -0
- package/dist/src/prompts/spam.js.map +1 -0
- package/dist/{prompts → src/prompts}/spreadsheet.js +71 -70
- package/dist/src/prompts/spreadsheet.js.map +1 -0
- package/dist/{prompts → src/prompts}/table.js +52 -38
- package/dist/src/prompts/table.js.map +1 -0
- package/dist/{prompts → src/prompts}/text.js +74 -70
- package/dist/src/prompts/text.js.map +1 -0
- package/dist/{prompts → src/prompts}/time.js +105 -96
- package/dist/src/prompts/time.js.map +1 -0
- package/dist/src/prompts/toggle.js +53 -0
- package/dist/src/prompts/toggle.js.map +1 -0
- package/dist/{prompts → src/prompts}/transfer.js +71 -67
- package/dist/src/prompts/transfer.js.map +1 -0
- package/dist/{prompts → src/prompts}/tree-select.js +83 -86
- package/dist/src/prompts/tree-select.js.map +1 -0
- package/dist/{prompts → src/prompts}/tree.js +69 -67
- package/dist/src/prompts/tree.js.map +1 -0
- package/dist/src/prompts/wait.js +79 -0
- package/dist/src/prompts/wait.js.map +1 -0
- package/dist/src/spinner.js +105 -0
- package/dist/src/spinner.js.map +1 -0
- package/dist/{symbols.js → src/symbols.js} +32 -7
- package/dist/src/symbols.js.map +1 -0
- package/dist/{tasks.js → src/tasks.js} +104 -79
- package/dist/src/tasks.js.map +1 -0
- package/dist/src/theme.js +29 -0
- package/dist/src/theme.js.map +1 -0
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -0
- package/dist/{utils.js → src/utils.js} +196 -152
- package/dist/src/utils.js.map +1 -0
- package/package.json +15 -16
- package/dist/ansi.d.ts +0 -36
- package/dist/base.d.ts +0 -60
- package/dist/core.d.ts +0 -1072
- package/dist/data/countries.d.ts +0 -2
- package/dist/data/countries.js +0 -105
- package/dist/data/licenses.d.ts +0 -2
- package/dist/data/licenses.js +0 -109
- package/dist/highlight.d.ts +0 -7
- package/dist/index.d.ts +0 -48
- package/dist/index.js +0 -64
- package/dist/input.d.ts +0 -14
- package/dist/pipeline.d.ts +0 -90
- package/dist/prompts/autocomplete.d.ts +0 -22
- package/dist/prompts/box.d.ts +0 -21
- package/dist/prompts/breadcrumb-search.d.ts +0 -14
- package/dist/prompts/breadcrumb.d.ts +0 -32
- package/dist/prompts/byte.d.ts +0 -13
- package/dist/prompts/calculator.d.ts +0 -17
- package/dist/prompts/calendar.d.ts +0 -33
- package/dist/prompts/checkbox.d.ts +0 -13
- package/dist/prompts/code.d.ts +0 -19
- package/dist/prompts/color.d.ts +0 -14
- package/dist/prompts/confirm.d.ts +0 -8
- package/dist/prompts/connection-string.d.ts +0 -18
- package/dist/prompts/cron.d.ts +0 -13
- package/dist/prompts/curl-utils.d.ts +0 -25
- package/dist/prompts/curl-utils.js +0 -41
- package/dist/prompts/curl.d.ts +0 -41
- package/dist/prompts/data-inspector.d.ts +0 -22
- package/dist/prompts/date.d.ts +0 -12
- package/dist/prompts/dependency.d.ts +0 -16
- package/dist/prompts/dial.d.ts +0 -10
- package/dist/prompts/diff.d.ts +0 -10
- package/dist/prompts/diff.js +0 -101
- package/dist/prompts/draw.d.ts +0 -20
- package/dist/prompts/editor.d.ts +0 -14
- package/dist/prompts/editor.js +0 -203
- package/dist/prompts/emoji.d.ts +0 -18
- package/dist/prompts/exec.d.ts +0 -17
- package/dist/prompts/file.d.ts +0 -21
- package/dist/prompts/file.js +0 -210
- package/dist/prompts/form.d.ts +0 -18
- package/dist/prompts/fuzzy-multi-column.d.ts +0 -12
- package/dist/prompts/fuzzy.d.ts +0 -12
- package/dist/prompts/gauge.d.ts +0 -21
- package/dist/prompts/gauge.js +0 -130
- package/dist/prompts/grid.d.ts +0 -14
- package/dist/prompts/heatmap.d.ts +0 -13
- package/dist/prompts/ip.d.ts +0 -11
- package/dist/prompts/kanban.d.ts +0 -17
- package/dist/prompts/keypress.d.ts +0 -7
- package/dist/prompts/keypress.js +0 -55
- package/dist/prompts/license.d.ts +0 -9
- package/dist/prompts/license.js +0 -105
- package/dist/prompts/list.d.ts +0 -9
- package/dist/prompts/map.d.ts +0 -17
- package/dist/prompts/match.d.ts +0 -19
- package/dist/prompts/miller.d.ts +0 -15
- package/dist/prompts/multi-column-select.d.ts +0 -10
- package/dist/prompts/multi-range.d.ts +0 -9
- package/dist/prompts/multi-select.d.ts +0 -15
- package/dist/prompts/number.d.ts +0 -11
- package/dist/prompts/otp.d.ts +0 -10
- package/dist/prompts/pattern.d.ts +0 -22
- package/dist/prompts/phone.d.ts +0 -41
- package/dist/prompts/quiz-select.d.ts +0 -10
- package/dist/prompts/quiz-select.js +0 -104
- package/dist/prompts/quiz-text.d.ts +0 -11
- package/dist/prompts/quiz-text.js +0 -82
- package/dist/prompts/range.d.ts +0 -9
- package/dist/prompts/rating.d.ts +0 -8
- package/dist/prompts/regex.d.ts +0 -13
- package/dist/prompts/region.d.ts +0 -11
- package/dist/prompts/schedule.d.ts +0 -20
- package/dist/prompts/scroll.d.ts +0 -13
- package/dist/prompts/seat.d.ts +0 -17
- package/dist/prompts/seat.js +0 -165
- package/dist/prompts/select-range.d.ts +0 -8
- package/dist/prompts/select.d.ts +0 -15
- package/dist/prompts/semver.d.ts +0 -6
- package/dist/prompts/shortcut.d.ts +0 -9
- package/dist/prompts/shortcut.js +0 -135
- package/dist/prompts/slider.d.ts +0 -8
- package/dist/prompts/slot.d.ts +0 -16
- package/dist/prompts/slot.js +0 -107
- package/dist/prompts/snippet.d.ts +0 -19
- package/dist/prompts/sort-grid.d.ts +0 -16
- package/dist/prompts/sort.d.ts +0 -14
- package/dist/prompts/spam.d.ts +0 -17
- package/dist/prompts/spam.js +0 -62
- package/dist/prompts/spreadsheet.d.ts +0 -21
- package/dist/prompts/table.d.ts +0 -14
- package/dist/prompts/text.d.ts +0 -17
- package/dist/prompts/time.d.ts +0 -12
- package/dist/prompts/toggle.d.ts +0 -8
- package/dist/prompts/toggle.js +0 -47
- package/dist/prompts/transfer.d.ts +0 -18
- package/dist/prompts/tree-select.d.ts +0 -31
- package/dist/prompts/tree.d.ts +0 -20
- package/dist/prompts/wait.d.ts +0 -18
- package/dist/prompts/wait.js +0 -62
- package/dist/spinner.d.ts +0 -33
- package/dist/spinner.js +0 -89
- package/dist/symbols.d.ts +0 -33
- package/dist/tasks.d.ts +0 -57
- package/dist/theme.d.ts +0 -2
- package/dist/theme.js +0 -20
- package/dist/types.d.ts +0 -503
- package/dist/types.js +0 -5
- package/dist/utils.d.ts +0 -81
|
@@ -1,103 +1,118 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get Pipeline () {
|
|
13
|
+
return Pipeline;
|
|
14
|
+
},
|
|
15
|
+
get PipelineAbortError () {
|
|
16
|
+
return PipelineAbortError;
|
|
17
|
+
},
|
|
18
|
+
get PipelineExit () {
|
|
19
|
+
return PipelineExit;
|
|
20
|
+
},
|
|
21
|
+
get PipelineTimeoutError () {
|
|
22
|
+
return PipelineTimeoutError;
|
|
23
|
+
},
|
|
24
|
+
get PipelineValidationError () {
|
|
25
|
+
return PipelineValidationError;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
function _define_property(obj, key, value) {
|
|
29
|
+
if (key in obj) {
|
|
30
|
+
Object.defineProperty(obj, key, {
|
|
31
|
+
value: value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
obj[key] = value;
|
|
38
|
+
}
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
const PipelineExit = Symbol.for('PipelineExit');
|
|
42
|
+
let PipelineValidationError = class PipelineValidationError extends Error {
|
|
43
|
+
constructor(message, step, context){
|
|
44
|
+
super(message), _define_property(this, "step", void 0), _define_property(this, "context", void 0);
|
|
8
45
|
this.name = 'PipelineValidationError';
|
|
9
46
|
this.step = step;
|
|
10
47
|
this.context = context;
|
|
11
48
|
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
super(message);
|
|
49
|
+
};
|
|
50
|
+
let PipelineTimeoutError = class PipelineTimeoutError extends Error {
|
|
51
|
+
constructor(message, step, context){
|
|
52
|
+
super(message), _define_property(this, "step", void 0), _define_property(this, "context", void 0);
|
|
17
53
|
this.name = 'PipelineTimeoutError';
|
|
18
54
|
this.step = step;
|
|
19
55
|
this.context = context;
|
|
20
56
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
constructor(message = 'Pipeline aborted') {
|
|
57
|
+
};
|
|
58
|
+
let PipelineAbortError = class PipelineAbortError extends Error {
|
|
59
|
+
constructor(message = 'Pipeline aborted'){
|
|
25
60
|
super(message);
|
|
26
61
|
this.name = 'PipelineAbortError';
|
|
27
62
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Pipeline (Workflow Engine)
|
|
32
|
-
*
|
|
33
|
-
* Implements a sequential workflow where steps are executed one by one,
|
|
34
|
-
* accumulating results into a Context object.
|
|
35
|
-
*
|
|
36
|
-
* Philosophy: Enter-and-Forget (EAF), Zero-Dependency, Method Chaining.
|
|
37
|
-
*/
|
|
38
|
-
class Pipeline {
|
|
39
|
-
constructor(options) {
|
|
40
|
-
this.steps = [];
|
|
41
|
-
this.options = options || {};
|
|
42
|
-
}
|
|
63
|
+
};
|
|
64
|
+
let Pipeline = class Pipeline {
|
|
43
65
|
step(nameOrAction, actionOrConfig, config) {
|
|
44
66
|
if (typeof nameOrAction === 'function' || nameOrAction instanceof Pipeline) {
|
|
45
|
-
const action = nameOrAction instanceof Pipeline
|
|
46
|
-
? ((ctx, tasks) => nameOrAction.run(ctx, tasks))
|
|
47
|
-
: nameOrAction;
|
|
67
|
+
const action = nameOrAction instanceof Pipeline ? (ctx, tasks)=>nameOrAction.run(ctx, tasks) : nameOrAction;
|
|
48
68
|
this.steps.push({
|
|
49
69
|
action: action,
|
|
50
|
-
...
|
|
70
|
+
...actionOrConfig || {}
|
|
51
71
|
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const action = actionOrConfig instanceof Pipeline
|
|
55
|
-
? ((ctx, tasks) => actionOrConfig.run(ctx, tasks))
|
|
56
|
-
: actionOrConfig;
|
|
72
|
+
} else {
|
|
73
|
+
const action = actionOrConfig instanceof Pipeline ? (ctx, tasks)=>actionOrConfig.run(ctx, tasks) : actionOrConfig;
|
|
57
74
|
this.steps.push({
|
|
58
75
|
name: nameOrAction,
|
|
59
76
|
action: action,
|
|
60
|
-
...
|
|
77
|
+
...config || {}
|
|
61
78
|
});
|
|
62
79
|
}
|
|
63
80
|
return this;
|
|
64
81
|
}
|
|
65
82
|
stepIf(condition, nameOrAction, actionOrConfig, config) {
|
|
66
83
|
if (typeof nameOrAction === 'function' || nameOrAction instanceof Pipeline) {
|
|
67
|
-
const action = nameOrAction instanceof Pipeline
|
|
68
|
-
? ((ctx, tasks) => nameOrAction.run(ctx, tasks))
|
|
69
|
-
: nameOrAction;
|
|
84
|
+
const action = nameOrAction instanceof Pipeline ? (ctx, tasks)=>nameOrAction.run(ctx, tasks) : nameOrAction;
|
|
70
85
|
this.steps.push({
|
|
71
86
|
condition,
|
|
72
87
|
action: action,
|
|
73
|
-
...
|
|
88
|
+
...actionOrConfig || {}
|
|
74
89
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const action = actionOrConfig instanceof Pipeline
|
|
78
|
-
? ((ctx, tasks) => actionOrConfig.run(ctx, tasks))
|
|
79
|
-
: actionOrConfig;
|
|
90
|
+
} else {
|
|
91
|
+
const action = actionOrConfig instanceof Pipeline ? (ctx, tasks)=>actionOrConfig.run(ctx, tasks) : actionOrConfig;
|
|
80
92
|
this.steps.push({
|
|
81
93
|
condition,
|
|
82
94
|
name: nameOrAction,
|
|
83
95
|
action: action,
|
|
84
|
-
...
|
|
96
|
+
...config || {}
|
|
85
97
|
});
|
|
86
98
|
}
|
|
87
99
|
return this;
|
|
88
100
|
}
|
|
89
101
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
* Executes the pipeline steps sequentially.
|
|
103
|
+
* @param initialContext Optional initial context.
|
|
104
|
+
* @param tasks Optional TaskRunner instance to pass to steps.
|
|
105
|
+
*/ async run(initialContext = {}, tasks) {
|
|
106
|
+
const context = {
|
|
107
|
+
...initialContext
|
|
108
|
+
};
|
|
96
109
|
if (this.options.onPipelineStart) {
|
|
97
|
-
await this.options.onPipelineStart({
|
|
110
|
+
await this.options.onPipelineStart({
|
|
111
|
+
...context
|
|
112
|
+
});
|
|
98
113
|
}
|
|
99
114
|
try {
|
|
100
|
-
for
|
|
115
|
+
for(let i = 0; i < this.steps.length; i++){
|
|
101
116
|
if (this.options.signal?.aborted) {
|
|
102
117
|
throw new PipelineAbortError();
|
|
103
118
|
}
|
|
@@ -111,22 +126,26 @@ class Pipeline {
|
|
|
111
126
|
continue;
|
|
112
127
|
}
|
|
113
128
|
if (this.options.onStepStart) {
|
|
114
|
-
await this.options.onStepStart(meta, {
|
|
129
|
+
await this.options.onStepStart(meta, {
|
|
130
|
+
...context
|
|
131
|
+
});
|
|
115
132
|
}
|
|
116
133
|
try {
|
|
117
134
|
let result;
|
|
118
135
|
if (step.timeout && step.timeout > 0) {
|
|
119
|
-
const timeoutPromise = new Promise((_, reject)
|
|
120
|
-
setTimeout(()
|
|
136
|
+
const timeoutPromise = new Promise((_, reject)=>{
|
|
137
|
+
setTimeout(()=>{
|
|
121
138
|
reject(new PipelineTimeoutError(`Step timed out after ${step.timeout}ms`, meta, context));
|
|
122
139
|
}, step.timeout);
|
|
123
140
|
});
|
|
124
|
-
result = await Promise.race([
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
result = await Promise.race([
|
|
142
|
+
step.action(context, tasks),
|
|
143
|
+
timeoutPromise
|
|
144
|
+
]);
|
|
145
|
+
} else {
|
|
127
146
|
result = await step.action(context, tasks);
|
|
128
147
|
}
|
|
129
|
-
if (result ===
|
|
148
|
+
if (result === PipelineExit) {
|
|
130
149
|
break;
|
|
131
150
|
}
|
|
132
151
|
if (!step.name) {
|
|
@@ -134,11 +153,12 @@ class Pipeline {
|
|
|
134
153
|
if (result && typeof result === 'object' && !Array.isArray(result)) {
|
|
135
154
|
Object.assign(context, result);
|
|
136
155
|
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
156
|
+
} else {
|
|
139
157
|
// Named action
|
|
140
158
|
if (step.transform) {
|
|
141
|
-
result = await step.transform(result, {
|
|
159
|
+
result = await step.transform(result, {
|
|
160
|
+
...context
|
|
161
|
+
});
|
|
142
162
|
}
|
|
143
163
|
if (step.validate) {
|
|
144
164
|
const validator = step.validate;
|
|
@@ -150,8 +170,7 @@ class Pipeline {
|
|
|
150
170
|
if (typeof valid === 'string') {
|
|
151
171
|
throw new PipelineValidationError(valid, meta, context);
|
|
152
172
|
}
|
|
153
|
-
}
|
|
154
|
-
else if (typeof validator === 'object') {
|
|
173
|
+
} else if (typeof validator === 'object') {
|
|
155
174
|
if (typeof validator.safeParse === 'function') {
|
|
156
175
|
const res = validator.safeParse(result);
|
|
157
176
|
if (!res.success) {
|
|
@@ -159,13 +178,11 @@ class Pipeline {
|
|
|
159
178
|
throw new PipelineValidationError(`Validation failed: ${errorMsg}`, meta, context);
|
|
160
179
|
}
|
|
161
180
|
result = res.data !== undefined ? res.data : result;
|
|
162
|
-
}
|
|
163
|
-
else if (typeof validator.parse === 'function') {
|
|
181
|
+
} else if (typeof validator.parse === 'function') {
|
|
164
182
|
try {
|
|
165
183
|
const parsed = validator.parse(result);
|
|
166
184
|
result = parsed !== undefined ? parsed : result;
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
185
|
+
} catch (err) {
|
|
169
186
|
throw new PipelineValidationError(`Validation failed: ${err.message || 'Schema parsing error'}`, meta, context);
|
|
170
187
|
}
|
|
171
188
|
}
|
|
@@ -174,22 +191,26 @@ class Pipeline {
|
|
|
174
191
|
context[step.name] = result;
|
|
175
192
|
}
|
|
176
193
|
if (this.options.onStepComplete) {
|
|
177
|
-
await this.options.onStepComplete(meta, {
|
|
194
|
+
await this.options.onStepComplete(meta, {
|
|
195
|
+
...context
|
|
196
|
+
});
|
|
178
197
|
}
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
198
|
+
} catch (err) {
|
|
181
199
|
let handled = false;
|
|
182
200
|
if (step.onError) {
|
|
183
|
-
await step.onError(err, {
|
|
201
|
+
await step.onError(err, {
|
|
202
|
+
...context
|
|
203
|
+
});
|
|
184
204
|
}
|
|
185
205
|
if ('fallback' in step) {
|
|
186
|
-
const fallbackValue = typeof step.fallback === 'function' ? await step.fallback(err, {
|
|
206
|
+
const fallbackValue = typeof step.fallback === 'function' ? await step.fallback(err, {
|
|
207
|
+
...context
|
|
208
|
+
}) : step.fallback;
|
|
187
209
|
if (step.name) {
|
|
188
210
|
context[step.name] = fallbackValue;
|
|
189
211
|
}
|
|
190
212
|
handled = true;
|
|
191
|
-
}
|
|
192
|
-
else if (step.optional) {
|
|
213
|
+
} else if (step.optional) {
|
|
193
214
|
if (step.name) {
|
|
194
215
|
context[step.name] = undefined;
|
|
195
216
|
}
|
|
@@ -197,7 +218,9 @@ class Pipeline {
|
|
|
197
218
|
}
|
|
198
219
|
if (!handled) {
|
|
199
220
|
if (this.options.onError) {
|
|
200
|
-
await this.options.onError(err, meta, {
|
|
221
|
+
await this.options.onError(err, meta, {
|
|
222
|
+
...context
|
|
223
|
+
});
|
|
201
224
|
}
|
|
202
225
|
throw err;
|
|
203
226
|
}
|
|
@@ -213,8 +236,7 @@ class Pipeline {
|
|
|
213
236
|
if (typeof valid === 'string') {
|
|
214
237
|
throw new PipelineValidationError(valid);
|
|
215
238
|
}
|
|
216
|
-
}
|
|
217
|
-
else if (typeof validator === 'object') {
|
|
239
|
+
} else if (typeof validator === 'object') {
|
|
218
240
|
if (typeof validator.safeParse === 'function') {
|
|
219
241
|
const res = validator.safeParse(context);
|
|
220
242
|
if (!res.success) {
|
|
@@ -222,25 +244,30 @@ class Pipeline {
|
|
|
222
244
|
throw new PipelineValidationError(`Final validation failed: ${errorMsg}`);
|
|
223
245
|
}
|
|
224
246
|
Object.assign(context, res.data !== undefined ? res.data : context);
|
|
225
|
-
}
|
|
226
|
-
else if (typeof validator.parse === 'function') {
|
|
247
|
+
} else if (typeof validator.parse === 'function') {
|
|
227
248
|
try {
|
|
228
249
|
const parsed = validator.parse(context);
|
|
229
250
|
Object.assign(context, parsed !== undefined ? parsed : context);
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
251
|
+
} catch (err) {
|
|
232
252
|
throw new PipelineValidationError(`Final validation failed: ${err.message || 'Schema parsing error'}`);
|
|
233
253
|
}
|
|
234
254
|
}
|
|
235
255
|
}
|
|
236
256
|
}
|
|
237
|
-
}
|
|
238
|
-
finally {
|
|
257
|
+
} finally{
|
|
239
258
|
if (this.options.onPipelineComplete) {
|
|
240
|
-
await this.options.onPipelineComplete({
|
|
259
|
+
await this.options.onPipelineComplete({
|
|
260
|
+
...context
|
|
261
|
+
});
|
|
241
262
|
}
|
|
242
263
|
}
|
|
243
264
|
return context;
|
|
244
265
|
}
|
|
245
|
-
|
|
246
|
-
|
|
266
|
+
constructor(options){
|
|
267
|
+
_define_property(this, "steps", []);
|
|
268
|
+
_define_property(this, "options", void 0);
|
|
269
|
+
this.options = options || {};
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/pipeline.ts"],"sourcesContent":["import { TaskRunner } from './tasks';\n\nexport const PipelineExit = Symbol.for('PipelineExit');\n\nexport type PipelineAction<Ctx, T> = (context: Ctx, tasks?: TaskRunner) => Promise<T | typeof PipelineExit> | T | typeof PipelineExit;\nexport type PipelineCondition<Ctx> = (context: Readonly<Ctx>) => boolean;\n\nexport interface ValidationSchema {\n parse?: (data: any) => any;\n safeParse?: (data: any) => { success: boolean; error?: any; issues?: any; data?: any };\n}\n\nexport type Validator = ((value: any) => boolean | string | Promise<boolean | string>) | ValidationSchema;\nexport type Transformer<Ctx> = (value: any, context: Readonly<Ctx>) => any | Promise<any>;\n\nexport interface PipelineStep<Ctx> extends StepConfig<Ctx> {\n name?: keyof Ctx;\n action: PipelineAction<Ctx, any>;\n condition?: PipelineCondition<Ctx>;\n}\n\nexport interface StepConfig<Ctx> {\n validate?: Validator;\n transform?: Transformer<Ctx>;\n onError?: (error: unknown, context: Readonly<Ctx>) => void | Promise<void>;\n fallback?: any | ((error: unknown, context: Readonly<Ctx>) => any | Promise<any>);\n optional?: boolean;\n timeout?: number;\n}\n\nexport interface StepMetadata {\n index: number;\n name?: string;\n type: 'named' | 'anonymous';\n}\n\nexport interface PipelineOptions<Ctx> {\n onStepStart?: (meta: StepMetadata, context: Readonly<Ctx>) => void | Promise<void>;\n onStepComplete?: (meta: StepMetadata, context: Readonly<Ctx>) => void | Promise<void>;\n onError?: (error: unknown, meta: StepMetadata, context: Readonly<Ctx>) => void | Promise<void>;\n validate?: Validator;\n onPipelineStart?: (context: Readonly<Ctx>) => void | Promise<void>;\n onPipelineComplete?: (context: Readonly<Ctx>) => void | Promise<void>;\n signal?: AbortSignal;\n}\n\nexport class PipelineValidationError<Ctx = any> extends Error {\n public step?: StepMetadata;\n public context?: Ctx;\n\n constructor(message: string, step?: StepMetadata, context?: Ctx) {\n super(message);\n this.name = 'PipelineValidationError';\n this.step = step;\n this.context = context;\n }\n}\n\nexport class PipelineTimeoutError<Ctx = any> extends Error {\n public step?: StepMetadata;\n public context?: Ctx;\n\n constructor(message: string, step?: StepMetadata, context?: Ctx) {\n super(message);\n this.name = 'PipelineTimeoutError';\n this.step = step;\n this.context = context;\n }\n}\n\nexport class PipelineAbortError extends Error {\n constructor(message: string = 'Pipeline aborted') {\n super(message);\n this.name = 'PipelineAbortError';\n }\n}\n\n/**\n * Pipeline (Workflow Engine)\n * \n * Implements a sequential workflow where steps are executed one by one,\n * accumulating results into a Context object.\n * \n * Philosophy: Enter-and-Forget (EAF), Zero-Dependency, Method Chaining.\n */\nexport class Pipeline<Ctx extends Record<string, any> = Record<string, any>> {\n private steps: PipelineStep<Ctx>[] = [];\n private options: PipelineOptions<Ctx>;\n\n constructor(options?: PipelineOptions<Ctx>) {\n this.options = options || {};\n }\n\n /**\n * Adds a named step to the pipeline. The result of the action is stored in the context under the given name.\n */\n public step<K extends keyof Ctx>(name: K, action: PipelineAction<Ctx, Ctx[K]> | Pipeline<any>, config?: StepConfig<Ctx>): this;\n /**\n * Adds an anonymous step to the pipeline. The action can mutate the context directly or return a partial context to merge in.\n */\n public step(action: PipelineAction<Ctx, void | Partial<Ctx>> | Pipeline<any>, config?: StepConfig<Ctx>): this;\n public step(\n nameOrAction: keyof Ctx | PipelineAction<Ctx, any> | Pipeline<any>,\n actionOrConfig?: PipelineAction<Ctx, any> | Pipeline<any> | StepConfig<Ctx>,\n config?: StepConfig<Ctx>\n ): this {\n if (typeof nameOrAction === 'function' || nameOrAction instanceof Pipeline) {\n const action = nameOrAction instanceof Pipeline\n ? ((ctx: Ctx, tasks?: TaskRunner) => nameOrAction.run(ctx, tasks))\n : nameOrAction;\n this.steps.push({\n action: action as PipelineAction<Ctx, any>,\n ...(actionOrConfig as StepConfig<Ctx> || {})\n });\n } else {\n const action = actionOrConfig instanceof Pipeline\n ? ((ctx: Ctx, tasks?: TaskRunner) => actionOrConfig.run(ctx, tasks))\n : actionOrConfig as PipelineAction<Ctx, any>;\n this.steps.push({\n name: nameOrAction as keyof Ctx,\n action: action,\n ...(config || {})\n });\n }\n return this;\n }\n\n /**\n * Adds a conditional named step to the pipeline.\n */\n public stepIf<K extends keyof Ctx>(condition: PipelineCondition<Ctx>, name: K, action: PipelineAction<Ctx, Ctx[K]> | Pipeline<any>, config?: StepConfig<Ctx>): this;\n /**\n * Adds a conditional anonymous step to the pipeline.\n */\n public stepIf(condition: PipelineCondition<Ctx>, action: PipelineAction<Ctx, void | Partial<Ctx>> | Pipeline<any>, config?: StepConfig<Ctx>): this;\n public stepIf(\n condition: PipelineCondition<Ctx>,\n nameOrAction: keyof Ctx | PipelineAction<Ctx, any> | Pipeline<any>,\n actionOrConfig?: PipelineAction<Ctx, any> | Pipeline<any> | StepConfig<Ctx>,\n config?: StepConfig<Ctx>\n ): this {\n if (typeof nameOrAction === 'function' || nameOrAction instanceof Pipeline) {\n const action = nameOrAction instanceof Pipeline\n ? ((ctx: Ctx, tasks?: TaskRunner) => nameOrAction.run(ctx, tasks))\n : nameOrAction;\n this.steps.push({\n condition,\n action: action as PipelineAction<Ctx, any>,\n ...(actionOrConfig as StepConfig<Ctx> || {})\n });\n } else {\n const action = actionOrConfig instanceof Pipeline\n ? ((ctx: Ctx, tasks?: TaskRunner) => actionOrConfig.run(ctx, tasks))\n : actionOrConfig as PipelineAction<Ctx, any>;\n this.steps.push({\n condition,\n name: nameOrAction as keyof Ctx,\n action: action,\n ...(config || {})\n });\n }\n return this;\n }\n\n /**\n * Executes the pipeline steps sequentially.\n * @param initialContext Optional initial context.\n * @param tasks Optional TaskRunner instance to pass to steps.\n */\n public async run(initialContext: Partial<Ctx> = {}, tasks?: TaskRunner): Promise<Ctx> {\n const context: Ctx = { ...initialContext } as Ctx;\n\n if (this.options.onPipelineStart) {\n await this.options.onPipelineStart({ ...context });\n }\n\n try {\n for (let i = 0; i < this.steps.length; i++) {\n if (this.options.signal?.aborted) {\n throw new PipelineAbortError();\n }\n\n const step = this.steps[i];\n const meta: StepMetadata = {\n index: i,\n name: step.name as string | undefined,\n type: step.name ? 'named' : 'anonymous'\n };\n\n if (step.condition && !step.condition(context)) {\n continue;\n }\n\n if (this.options.onStepStart) {\n await this.options.onStepStart(meta, { ...context });\n }\n\n try {\n let result: any;\n if (step.timeout && step.timeout > 0) {\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => {\n reject(new PipelineTimeoutError(`Step timed out after ${step.timeout}ms`, meta, context));\n }, step.timeout);\n });\n result = await Promise.race([step.action(context, tasks), timeoutPromise]);\n } else {\n result = await step.action(context, tasks);\n }\n\n if (result === PipelineExit) {\n break;\n }\n\n if (!step.name) {\n // Anonymous action\n if (result && typeof result === 'object' && !Array.isArray(result)) {\n Object.assign(context, result);\n }\n } else {\n // Named action\n if (step.transform) {\n result = await step.transform(result, { ...context });\n }\n\n if (step.validate) {\n const validator = step.validate;\n if (typeof validator === 'function') {\n const valid = await validator(result);\n if (valid === false) {\n throw new PipelineValidationError(`Validation failed for step at index ${i} (${String(step.name)})`, meta, context);\n }\n if (typeof valid === 'string') {\n throw new PipelineValidationError(valid, meta, context);\n }\n } else if (typeof validator === 'object') {\n if (typeof validator.safeParse === 'function') {\n const res = validator.safeParse(result);\n if (!res.success) {\n const errorMsg = res.error?.message || res.issues?.[0]?.message || 'Schema validation failed';\n throw new PipelineValidationError(`Validation failed: ${errorMsg}`, meta, context);\n }\n result = res.data !== undefined ? res.data : result;\n } else if (typeof validator.parse === 'function') {\n try {\n const parsed = validator.parse(result);\n result = parsed !== undefined ? parsed : result;\n } catch (err: any) {\n throw new PipelineValidationError(`Validation failed: ${err.message || 'Schema parsing error'}`, meta, context);\n }\n }\n }\n }\n\n context[step.name] = result;\n }\n\n if (this.options.onStepComplete) {\n await this.options.onStepComplete(meta, { ...context });\n }\n } catch (err) {\n let handled = false;\n\n if (step.onError) {\n await step.onError(err, { ...context });\n }\n\n if ('fallback' in step) {\n const fallbackValue = typeof step.fallback === 'function' ? await step.fallback(err, { ...context }) : step.fallback;\n if (step.name) {\n context[step.name] = fallbackValue;\n }\n handled = true;\n } else if (step.optional) {\n if (step.name) {\n context[step.name] = undefined as any;\n }\n handled = true;\n }\n\n if (!handled) {\n if (this.options.onError) {\n await this.options.onError(err, meta, { ...context });\n }\n throw err;\n }\n }\n }\n\n if (this.options.validate) {\n const validator = this.options.validate;\n if (typeof validator === 'function') {\n const valid = await validator(context);\n if (valid === false) {\n throw new PipelineValidationError(`Final validation failed`);\n }\n if (typeof valid === 'string') {\n throw new PipelineValidationError(valid);\n }\n } else if (typeof validator === 'object') {\n if (typeof validator.safeParse === 'function') {\n const res = validator.safeParse(context);\n if (!res.success) {\n const errorMsg = res.error?.message || res.issues?.[0]?.message || 'Schema validation failed';\n throw new PipelineValidationError(`Final validation failed: ${errorMsg}`);\n }\n Object.assign(context, res.data !== undefined ? res.data : context);\n } else if (typeof validator.parse === 'function') {\n try {\n const parsed = validator.parse(context);\n Object.assign(context, parsed !== undefined ? parsed : context);\n } catch (err: any) {\n throw new PipelineValidationError(`Final validation failed: ${err.message || 'Schema parsing error'}`);\n }\n }\n }\n }\n } finally {\n if (this.options.onPipelineComplete) {\n await this.options.onPipelineComplete({ ...context });\n }\n }\n\n return context;\n }\n}\n\n"],"names":["Pipeline","PipelineAbortError","PipelineExit","PipelineTimeoutError","PipelineValidationError","Symbol","for","Error","message","step","context","name","nameOrAction","actionOrConfig","config","action","ctx","tasks","run","steps","push","stepIf","condition","initialContext","options","onPipelineStart","i","length","signal","aborted","meta","index","type","onStepStart","result","timeout","timeoutPromise","Promise","_","reject","setTimeout","race","Array","isArray","Object","assign","transform","validate","validator","valid","String","safeParse","res","success","errorMsg","error","issues","data","undefined","parse","parsed","err","onStepComplete","handled","onError","fallbackValue","fallback","optional","onPipelineComplete"],"mappings":";;;;;;;;;;;QAqFaA;eAAAA;;QAfAC;eAAAA;;QApEAC;eAAAA;;QAwDAC;eAAAA;;QAZAC;eAAAA;;;;;;;;;;;;;;;;AA5CN,MAAMF,eAAeG,OAAOC,GAAG,CAAC;AA4ChC,IAAA,AAAMF,0BAAN,MAAMA,gCAA2CG;IAItD,YAAYC,OAAe,EAAEC,IAAmB,EAAEC,OAAa,CAAE;QAC/D,KAAK,CAACF,UAJR,uBAAOC,QAAP,KAAA,IACA,uBAAOC,WAAP,KAAA;QAIE,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACF,IAAI,GAAGA;QACZ,IAAI,CAACC,OAAO,GAAGA;IACjB;AACF;AAEO,IAAA,AAAMP,uBAAN,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SAASkD,WAAWF,YAAYE,SAASlD;wBACzD,EAAE,OAAOmD,KAAU;4BACjB,MAAM,IAAIzD,wBAAwB,CAAC,yBAAyB,EAAEyD,IAAIrD,OAAO,IAAI,wBAAwB;wBACvG;oBACF;gBACF;YACF;QACF,SAAU;YACR,IAAI,IAAI,CAACgB,OAAO,CAAC4C,kBAAkB,EAAE;gBACnC,MAAM,IAAI,CAAC5C,OAAO,CAAC4C,kBAAkB,CAAC;oBAAE,GAAG1D,OAAO;gBAAC;YACrD;QACF;QAEA,OAAOA;IACT;IA3OA,YAAYc,OAA8B,CAAE;QAH5C,uBAAQL,SAA6B,EAAE;QACvC,uBAAQK,WAAR,KAAA;QAGE,IAAI,CAACA,OAAO,GAAGA,WAAW,CAAC;IAC7B;AA0OF"}
|
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "AutocompletePrompt", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AutocompletePrompt;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ansi = require("../ansi");
|
|
12
|
+
const _base = require("../base");
|
|
13
|
+
const _theme = require("../theme");
|
|
14
|
+
const _symbols = require("../symbols");
|
|
15
|
+
const _utils = require("../utils");
|
|
16
|
+
function _define_property(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
22
26
|
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
let AutocompletePrompt = class AutocompletePrompt extends _base.Prompt {
|
|
23
30
|
search(query) {
|
|
24
|
-
if (this.debounceTimer)
|
|
25
|
-
clearTimeout(this.debounceTimer);
|
|
31
|
+
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
26
32
|
this.loading = true;
|
|
27
33
|
this.startSpinner();
|
|
28
34
|
this.render(false);
|
|
29
|
-
this.debounceTimer = setTimeout(async ()
|
|
35
|
+
this.debounceTimer = setTimeout(async ()=>{
|
|
30
36
|
try {
|
|
31
37
|
const results = await this.options.suggest(query);
|
|
32
|
-
if (query !== this.input)
|
|
33
|
-
return;
|
|
38
|
+
if (query !== this.input) return;
|
|
34
39
|
this.choices = results.slice(0, this.options.limit || 10);
|
|
35
40
|
this.selectedIndex = 0;
|
|
36
41
|
this.scrollTop = 0;
|
|
37
42
|
this.hasSearched = true;
|
|
38
|
-
}
|
|
39
|
-
catch (_err) {
|
|
43
|
+
} catch (_err) {
|
|
40
44
|
this.choices = [];
|
|
41
|
-
}
|
|
42
|
-
finally {
|
|
45
|
+
} finally{
|
|
43
46
|
this.loading = false;
|
|
44
47
|
this.stopSpinner();
|
|
45
48
|
this.render(false);
|
|
@@ -47,10 +50,9 @@ class AutocompletePrompt extends base_1.Prompt {
|
|
|
47
50
|
}, 300); // 300ms debounce
|
|
48
51
|
}
|
|
49
52
|
startSpinner() {
|
|
50
|
-
if (this.spinnerTimer)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.spinnerFrame = (this.spinnerFrame + 1) % symbols_1.symbols.spinner.length;
|
|
53
|
+
if (this.spinnerTimer) return;
|
|
54
|
+
this.spinnerTimer = setInterval(()=>{
|
|
55
|
+
this.spinnerFrame = (this.spinnerFrame + 1) % _symbols.symbols.spinner.length;
|
|
54
56
|
this.render(false);
|
|
55
57
|
}, 80);
|
|
56
58
|
}
|
|
@@ -70,32 +72,27 @@ class AutocompletePrompt extends base_1.Prompt {
|
|
|
70
72
|
}
|
|
71
73
|
let output = '';
|
|
72
74
|
// Header
|
|
73
|
-
const icon = this.loading ? `${
|
|
74
|
-
output += `${icon} ${
|
|
75
|
+
const icon = this.loading ? `${_theme.theme.main}${_symbols.symbols.spinner[this.spinnerFrame]}${_ansi.ANSI.RESET}` : `${_theme.theme.success}?${_ansi.ANSI.RESET}`;
|
|
76
|
+
output += `${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} ${this.input}`;
|
|
75
77
|
output += '\n';
|
|
76
78
|
if (this.loading) {
|
|
77
|
-
output += ` ${
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else if (this.choices.length > 0) {
|
|
79
|
+
output += ` ${_theme.theme.muted}Searching...${_ansi.ANSI.RESET}`;
|
|
80
|
+
} else if (this.choices.length === 0 && this.hasSearched) {
|
|
81
|
+
output += ` ${_theme.theme.muted}${this.options.fallback || 'No results found.'}${_ansi.ANSI.RESET}`;
|
|
82
|
+
} else if (this.choices.length > 0) {
|
|
83
83
|
// Render list similar to SelectPrompt
|
|
84
84
|
if (this.selectedIndex < this.scrollTop) {
|
|
85
85
|
this.scrollTop = this.selectedIndex;
|
|
86
|
-
}
|
|
87
|
-
else if (this.selectedIndex >= this.scrollTop + this.pageSize) {
|
|
86
|
+
} else if (this.selectedIndex >= this.scrollTop + this.pageSize) {
|
|
88
87
|
this.scrollTop = this.selectedIndex - this.pageSize + 1;
|
|
89
88
|
}
|
|
90
89
|
const visibleChoices = this.choices.slice(this.scrollTop, this.scrollTop + this.pageSize);
|
|
91
|
-
visibleChoices.forEach((choice, index)
|
|
90
|
+
visibleChoices.forEach((choice, index)=>{
|
|
92
91
|
const actualIndex = this.scrollTop + index;
|
|
93
|
-
if (index > 0)
|
|
94
|
-
output += '\n';
|
|
92
|
+
if (index > 0) output += '\n';
|
|
95
93
|
if (actualIndex === this.selectedIndex) {
|
|
96
|
-
output += `${
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
94
|
+
output += `${_theme.theme.main}${_symbols.symbols.pointer} ${choice.title}${_ansi.ANSI.RESET}`;
|
|
95
|
+
} else {
|
|
99
96
|
output += ` ${choice.title}`;
|
|
100
97
|
}
|
|
101
98
|
});
|
|
@@ -110,9 +107,9 @@ class AutocompletePrompt extends base_1.Prompt {
|
|
|
110
107
|
}
|
|
111
108
|
this.print(`\r`);
|
|
112
109
|
const firstLine = lines[0];
|
|
113
|
-
const visualLen = (0,
|
|
110
|
+
const visualLen = (0, _utils.stringWidth)(this.stripAnsi(firstLine));
|
|
114
111
|
this.print(`\x1b[${visualLen}C`);
|
|
115
|
-
this.print(
|
|
112
|
+
this.print(_ansi.ANSI.SHOW_CURSOR);
|
|
116
113
|
}
|
|
117
114
|
handleInput(char) {
|
|
118
115
|
// Enter
|
|
@@ -153,18 +150,22 @@ class AutocompletePrompt extends base_1.Prompt {
|
|
|
153
150
|
}
|
|
154
151
|
}
|
|
155
152
|
handleMouse(event) {
|
|
156
|
-
if (this.choices.length === 0)
|
|
157
|
-
return;
|
|
153
|
+
if (this.choices.length === 0) return;
|
|
158
154
|
if (event.action === 'scroll') {
|
|
159
155
|
if (event.scroll === 'up') {
|
|
160
156
|
this.selectedIndex = this.selectedIndex > 0 ? this.selectedIndex - 1 : this.choices.length - 1;
|
|
161
157
|
this.render(false);
|
|
162
|
-
}
|
|
163
|
-
else if (event.scroll === 'down') {
|
|
158
|
+
} else if (event.scroll === 'down') {
|
|
164
159
|
this.selectedIndex = this.selectedIndex < this.choices.length - 1 ? this.selectedIndex + 1 : 0;
|
|
165
160
|
this.render(false);
|
|
166
161
|
}
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
constructor(options){
|
|
165
|
+
super(options), _define_property(this, "input", ''), _define_property(this, "choices", []), _define_property(this, "selectedIndex", 0), _define_property(this, "loading", false), _define_property(this, "debounceTimer", void 0), _define_property(this, "spinnerFrame", 0), _define_property(this, "spinnerTimer", void 0), _define_property(this, "scrollTop", 0), _define_property(this, "pageSize", 7), _define_property(this, "hasSearched", false);
|
|
166
|
+
this.input = options.initial || '';
|
|
167
|
+
this.search(this.input);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=autocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prompts/autocomplete.ts"],"sourcesContent":["import { ANSI } from '../ansi';\nimport { Prompt } from '../base';\nimport { theme } from '../theme';\nimport { symbols } from '../symbols';\nimport { AutocompleteOptions, SelectChoice, MouseEvent } from '../types';\nimport { stringWidth } from '../utils';\n\nexport class AutocompletePrompt<V> extends Prompt<V, AutocompleteOptions<V>> {\n private input: string = '';\n private choices: SelectChoice<V>[] = [];\n private selectedIndex: number = 0;\n private loading: boolean = false;\n private debounceTimer?: any;\n private spinnerFrame: number = 0;\n private spinnerTimer?: any;\n private scrollTop: number = 0;\n private readonly pageSize: number = 7;\n private hasSearched: boolean = false;\n\n constructor(options: AutocompleteOptions<V>) {\n super(options);\n this.input = options.initial || '';\n this.search(this.input);\n }\n\n private search(query: string) {\n if (this.debounceTimer) clearTimeout(this.debounceTimer);\n\n this.loading = true;\n this.startSpinner();\n this.render(false);\n\n this.debounceTimer = setTimeout(async () => {\n try {\n const results = await this.options.suggest(query);\n if (query !== this.input) return;\n\n this.choices = results.slice(0, this.options.limit || 10);\n this.selectedIndex = 0;\n this.scrollTop = 0;\n this.hasSearched = true;\n } catch (_err) {\n this.choices = [];\n } finally {\n this.loading = false;\n this.stopSpinner();\n this.render(false);\n }\n }, 300); // 300ms debounce\n }\n\n private startSpinner() {\n if (this.spinnerTimer) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerFrame = (this.spinnerFrame + 1) % symbols.spinner.length;\n this.render(false);\n }, 80);\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = undefined;\n }\n }\n\n protected cleanup() {\n this.stopSpinner();\n super.cleanup();\n }\n\n protected render(_firstRender: boolean) {\n if (this.lastRenderHeight > 1) {\n this.print(`\\x1b[${this.lastRenderHeight - 1}B`); // Move down\n }\n\n let output = '';\n\n // Header\n const icon = this.loading ? `${theme.main}${symbols.spinner[this.spinnerFrame]}${ANSI.RESET}` : `${theme.success}?${ANSI.RESET}`;\n output += `${icon} ${ANSI.BOLD}${theme.title}${this.options.message}${ANSI.RESET} ${this.input}`;\n\n output += '\\n';\n\n if (this.loading) {\n output += ` ${theme.muted}Searching...${ANSI.RESET}`;\n } else if (this.choices.length === 0 && this.hasSearched) {\n output += ` ${theme.muted}${this.options.fallback || 'No results found.'}${ANSI.RESET}`;\n } else if (this.choices.length > 0) {\n // Render list similar to SelectPrompt\n if (this.selectedIndex < this.scrollTop) {\n this.scrollTop = this.selectedIndex;\n } else if (this.selectedIndex >= this.scrollTop + this.pageSize) {\n this.scrollTop = this.selectedIndex - this.pageSize + 1;\n }\n\n const visibleChoices = this.choices.slice(this.scrollTop, this.scrollTop + this.pageSize);\n\n visibleChoices.forEach((choice, index) => {\n const actualIndex = this.scrollTop + index;\n if (index > 0) output += '\\n';\n\n if (actualIndex === this.selectedIndex) {\n output += `${theme.main}${symbols.pointer} ${choice.title}${ANSI.RESET}`;\n } else {\n output += ` ${choice.title}`;\n }\n });\n }\n\n this.renderFrame(output);\n\n // Position cursor at the end of the input string on the first line\n const lines = output.split('\\n');\n const height = lines.length;\n\n // Move up (height - 1)\n if (height > 1) {\n this.print(`\\x1b[${height - 1}A`);\n }\n\n this.print(`\\r`);\n\n const firstLine = lines[0];\n const visualLen = stringWidth(this.stripAnsi(firstLine));\n\n this.print(`\\x1b[${visualLen}C`);\n this.print(ANSI.SHOW_CURSOR);\n }\n\n protected handleInput(char: string) {\n // Enter\n if (char === '\\r' || char === '\\n') {\n if (this.choices.length > 0) {\n this.submit(this.choices[this.selectedIndex].value);\n }\n return;\n }\n\n // Backspace\n if (char === '\\u0008' || char === '\\x7f') {\n if (this.input.length > 0) {\n this.input = this.input.slice(0, -1);\n this.search(this.input);\n }\n return;\n }\n\n // Up\n if (this.isUp(char)) {\n if (this.choices.length > 0) {\n this.selectedIndex = this.selectedIndex > 0 ? this.selectedIndex - 1 : this.choices.length - 1;\n this.render(false);\n }\n return;\n }\n\n // Down\n if (this.isDown(char)) {\n if (this.choices.length > 0) {\n this.selectedIndex = this.selectedIndex < this.choices.length - 1 ? this.selectedIndex + 1 : 0;\n this.render(false);\n }\n return;\n }\n\n // Typing\n if (char.length === 1 && !/^[\\x00-\\x1F]/.test(char)) {\n this.input += char;\n this.search(this.input);\n }\n }\n\n protected handleMouse(event: MouseEvent) {\n if (this.choices.length === 0) return;\n\n if (event.action === 'scroll') {\n if (event.scroll === 'up') {\n this.selectedIndex = this.selectedIndex > 0 ? this.selectedIndex - 1 : this.choices.length - 1;\n this.render(false);\n } else if (event.scroll === 'down') {\n this.selectedIndex = this.selectedIndex < this.choices.length - 1 ? this.selectedIndex + 1 : 0;\n this.render(false);\n }\n }\n }\n}\n"],"names":["AutocompletePrompt","Prompt","search","query","debounceTimer","clearTimeout","loading","startSpinner","render","setTimeout","results","options","suggest","input","choices","slice","limit","selectedIndex","scrollTop","hasSearched","_err","stopSpinner","spinnerTimer","setInterval","spinnerFrame","symbols","spinner","length","clearInterval","undefined","cleanup","_firstRender","lastRenderHeight","print","output","icon","theme","main","ANSI","RESET","success","BOLD","title","message","muted","fallback","pageSize","visibleChoices","forEach","choice","index","actualIndex","pointer","renderFrame","lines","split","height","firstLine","visualLen","stringWidth","stripAnsi","SHOW_CURSOR","handleInput","char","submit","value","isUp","isDown","test","handleMouse","event","action","scroll","initial"],"mappings":";;;;+BAOaA;;;eAAAA;;;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