semola 0.5.2 → 0.5.4

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 (160) hide show
  1. package/README.md +88 -13
  2. package/dist/index-BhGNDjPq.d.mts +13 -0
  3. package/dist/index-DxSbeGP-.d.cts +13 -0
  4. package/dist/lib/api/index.cjs +522 -4
  5. package/dist/lib/api/index.d.cts +270 -4
  6. package/dist/lib/api/index.d.mts +270 -4
  7. package/dist/lib/api/index.mjs +520 -2
  8. package/dist/lib/cache/index.d.cts +19 -7
  9. package/dist/lib/cache/index.d.mts +19 -7
  10. package/dist/lib/cache/index.mjs +0 -2
  11. package/dist/lib/cron/index.cjs +470 -11
  12. package/dist/lib/cron/index.d.cts +112 -5
  13. package/dist/lib/cron/index.d.mts +112 -5
  14. package/dist/lib/cron/index.mjs +461 -12
  15. package/dist/lib/errors/index.d.cts +2 -13
  16. package/dist/lib/errors/index.d.mts +2 -13
  17. package/dist/lib/errors/index.mjs +0 -2
  18. package/dist/lib/i18n/index.cjs +6 -1
  19. package/dist/lib/i18n/index.d.cts +12 -4
  20. package/dist/lib/i18n/index.d.mts +12 -4
  21. package/dist/lib/i18n/index.mjs +6 -3
  22. package/dist/lib/logging/index.cjs +387 -0
  23. package/dist/lib/logging/index.d.cts +108 -0
  24. package/dist/lib/logging/index.d.mts +108 -0
  25. package/dist/lib/logging/index.mjs +374 -0
  26. package/dist/lib/policy/index.cjs +206 -20
  27. package/dist/lib/policy/index.d.cts +61 -5
  28. package/dist/lib/policy/index.d.mts +61 -5
  29. package/dist/lib/policy/index.mjs +187 -3
  30. package/dist/lib/prompts/index.cjs +374 -14
  31. package/dist/lib/prompts/index.d.cts +77 -12
  32. package/dist/lib/prompts/index.d.mts +77 -12
  33. package/dist/lib/prompts/index.mjs +362 -4
  34. package/dist/lib/pubsub/index.cjs +82 -13
  35. package/dist/lib/pubsub/index.d.cts +23 -9
  36. package/dist/lib/pubsub/index.d.mts +23 -9
  37. package/dist/lib/pubsub/index.mjs +82 -15
  38. package/dist/lib/queue/index.d.cts +46 -4
  39. package/dist/lib/queue/index.d.mts +46 -4
  40. package/dist/lib/queue/index.mjs +0 -2
  41. package/dist/lib/workflow/index.cjs +534 -0
  42. package/dist/lib/workflow/index.d.cts +85 -0
  43. package/dist/lib/workflow/index.d.mts +85 -0
  44. package/dist/lib/workflow/index.mjs +533 -0
  45. package/package.json +29 -3
  46. package/dist/api/core/index.cjs +0 -206
  47. package/dist/api/core/index.d.cts +0 -21
  48. package/dist/api/core/index.d.cts.map +0 -1
  49. package/dist/api/core/index.d.mts +0 -21
  50. package/dist/api/core/index.d.mts.map +0 -1
  51. package/dist/api/core/index.mjs +0 -208
  52. package/dist/api/core/index.mjs.map +0 -1
  53. package/dist/api/core/types.d.cts +0 -107
  54. package/dist/api/core/types.d.cts.map +0 -1
  55. package/dist/api/core/types.d.mts +0 -107
  56. package/dist/api/core/types.d.mts.map +0 -1
  57. package/dist/api/middleware/index.cjs +0 -8
  58. package/dist/api/middleware/index.d.cts +0 -11
  59. package/dist/api/middleware/index.d.cts.map +0 -1
  60. package/dist/api/middleware/index.d.mts +0 -11
  61. package/dist/api/middleware/index.d.mts.map +0 -1
  62. package/dist/api/middleware/index.mjs +0 -10
  63. package/dist/api/middleware/index.mjs.map +0 -1
  64. package/dist/api/middleware/types.d.cts +0 -16
  65. package/dist/api/middleware/types.d.cts.map +0 -1
  66. package/dist/api/middleware/types.d.mts +0 -16
  67. package/dist/api/middleware/types.d.mts.map +0 -1
  68. package/dist/api/openapi/index.cjs +0 -254
  69. package/dist/api/openapi/index.mjs +0 -256
  70. package/dist/api/openapi/index.mjs.map +0 -1
  71. package/dist/api/openapi/types.d.cts +0 -60
  72. package/dist/api/openapi/types.d.cts.map +0 -1
  73. package/dist/api/openapi/types.d.mts +0 -60
  74. package/dist/api/openapi/types.d.mts.map +0 -1
  75. package/dist/api/validation/index.cjs +0 -64
  76. package/dist/api/validation/index.mjs +0 -61
  77. package/dist/api/validation/index.mjs.map +0 -1
  78. package/dist/cache/types.d.cts +0 -17
  79. package/dist/cache/types.d.cts.map +0 -1
  80. package/dist/cache/types.d.mts +0 -17
  81. package/dist/cache/types.d.mts.map +0 -1
  82. package/dist/cron/scanner.cjs +0 -237
  83. package/dist/cron/scanner.mjs +0 -238
  84. package/dist/cron/scanner.mjs.map +0 -1
  85. package/dist/cron/types.d.cts +0 -11
  86. package/dist/cron/types.d.cts.map +0 -1
  87. package/dist/cron/types.d.mts +0 -11
  88. package/dist/cron/types.d.mts.map +0 -1
  89. package/dist/errors/types.d.cts +0 -5
  90. package/dist/errors/types.d.cts.map +0 -1
  91. package/dist/errors/types.d.mts +0 -5
  92. package/dist/errors/types.d.mts.map +0 -1
  93. package/dist/i18n/types.d.cts +0 -13
  94. package/dist/i18n/types.d.cts.map +0 -1
  95. package/dist/i18n/types.d.mts +0 -13
  96. package/dist/i18n/types.d.mts.map +0 -1
  97. package/dist/lib/cache/index.d.cts.map +0 -1
  98. package/dist/lib/cache/index.d.mts.map +0 -1
  99. package/dist/lib/cache/index.mjs.map +0 -1
  100. package/dist/lib/cron/index.d.cts.map +0 -1
  101. package/dist/lib/cron/index.d.mts.map +0 -1
  102. package/dist/lib/cron/index.mjs.map +0 -1
  103. package/dist/lib/errors/index.d.cts.map +0 -1
  104. package/dist/lib/errors/index.d.mts.map +0 -1
  105. package/dist/lib/errors/index.mjs.map +0 -1
  106. package/dist/lib/i18n/index.d.cts.map +0 -1
  107. package/dist/lib/i18n/index.d.mts.map +0 -1
  108. package/dist/lib/i18n/index.mjs.map +0 -1
  109. package/dist/lib/policy/index.d.cts.map +0 -1
  110. package/dist/lib/policy/index.d.mts.map +0 -1
  111. package/dist/lib/policy/index.mjs.map +0 -1
  112. package/dist/lib/prompts/index.d.cts.map +0 -1
  113. package/dist/lib/prompts/index.d.mts.map +0 -1
  114. package/dist/lib/prompts/index.mjs.map +0 -1
  115. package/dist/lib/pubsub/index.d.cts.map +0 -1
  116. package/dist/lib/pubsub/index.d.mts.map +0 -1
  117. package/dist/lib/pubsub/index.mjs.map +0 -1
  118. package/dist/lib/queue/index.d.cts.map +0 -1
  119. package/dist/lib/queue/index.d.mts.map +0 -1
  120. package/dist/lib/queue/index.mjs.map +0 -1
  121. package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
  122. package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
  123. package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
  124. package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
  125. package/dist/policy/helpers.cjs +0 -206
  126. package/dist/policy/helpers.d.cts +0 -50
  127. package/dist/policy/helpers.d.cts.map +0 -1
  128. package/dist/policy/helpers.d.mts +0 -50
  129. package/dist/policy/helpers.d.mts.map +0 -1
  130. package/dist/policy/helpers.mjs +0 -190
  131. package/dist/policy/helpers.mjs.map +0 -1
  132. package/dist/policy/types.d.cts +0 -16
  133. package/dist/policy/types.d.cts.map +0 -1
  134. package/dist/policy/types.d.mts +0 -16
  135. package/dist/policy/types.d.mts.map +0 -1
  136. package/dist/prompts/core/keys.cjs +0 -165
  137. package/dist/prompts/core/keys.mjs +0 -167
  138. package/dist/prompts/core/keys.mjs.map +0 -1
  139. package/dist/prompts/core/runtime.cjs +0 -104
  140. package/dist/prompts/core/runtime.mjs +0 -106
  141. package/dist/prompts/core/runtime.mjs.map +0 -1
  142. package/dist/prompts/core/session.cjs +0 -98
  143. package/dist/prompts/core/session.mjs +0 -100
  144. package/dist/prompts/core/session.mjs.map +0 -1
  145. package/dist/prompts/core/types.d.cts +0 -21
  146. package/dist/prompts/core/types.d.cts.map +0 -1
  147. package/dist/prompts/core/types.d.mts +0 -21
  148. package/dist/prompts/core/types.d.mts.map +0 -1
  149. package/dist/prompts/types.d.cts +0 -52
  150. package/dist/prompts/types.d.cts.map +0 -1
  151. package/dist/prompts/types.d.mts +0 -52
  152. package/dist/prompts/types.d.mts.map +0 -1
  153. package/dist/pubsub/types.d.cts +0 -10
  154. package/dist/pubsub/types.d.cts.map +0 -1
  155. package/dist/pubsub/types.d.mts +0 -10
  156. package/dist/pubsub/types.d.mts.map +0 -1
  157. package/dist/queue/types.d.cts +0 -47
  158. package/dist/queue/types.d.cts.map +0 -1
  159. package/dist/queue/types.d.mts +0 -47
  160. package/dist/queue/types.d.mts.map +0 -1
@@ -1,23 +1,89 @@
1
- import { PromptRuntime } from "../../prompts/core/types.cjs";
2
- import { ConfirmOptions, InputOptions, MultiselectOptions, NumberOptions, PasswordOptions, PromptErrorType, SelectChoice, SelectOptions } from "../../prompts/types.cjs";
1
+ import { i as ok, t as err } from "../../index-DxSbeGP-.cjs";
3
2
 
3
+ //#region src/lib/prompts/core/types.d.ts
4
+ type PromptResultLike<T> = ReturnType<typeof err<string>> | ReturnType<typeof ok<T>>;
5
+ type KeyName = "character" | "enter" | "backspace" | "delete" | "up" | "down" | "left" | "right" | "ctrl_left" | "ctrl_right" | "shift_left" | "shift_right" | "space" | "escape" | "ctrl_c" | "ctrl_backspace" | "ctrl_a" | "home" | "end" | "shift_ctrl_left" | "shift_ctrl_right" | "tab";
6
+ type Key = {
7
+ name: KeyName;
8
+ value?: string;
9
+ };
10
+ type PromptRuntime = {
11
+ isInteractive: () => boolean;
12
+ init: () => PromptResultLike<void>;
13
+ readKey: () => Promise<PromptResultLike<Key>>;
14
+ render: (frame: string) => PromptResultLike<void>;
15
+ done: (frame: string) => PromptResultLike<void>;
16
+ close: () => PromptResultLike<void>;
17
+ interrupt?: (message: string) => PromptResultLike<undefined>;
18
+ };
19
+ //#endregion
20
+ //#region src/lib/prompts/types.d.ts
21
+ type PromptErrorType = "PromptEnvironmentError" | "PromptValidationError" | "PromptCancelledError" | "PromptIOError" | (string & {});
22
+ type MaybePromise<T> = T | Promise<T>;
23
+ type Validate<TValue> = ((value: TValue) => MaybePromise<string | null | undefined>) | undefined;
24
+ type Transform<TValue> = ((value: TValue) => MaybePromise<TValue>) | undefined;
25
+ type BasePromptOptions<TValue> = {
26
+ message: string;
27
+ validate?: Validate<TValue>;
28
+ transform?: Transform<TValue>;
29
+ };
30
+ type InputOptions = BasePromptOptions<string> & {
31
+ defaultValue?: string;
32
+ placeholder?: string;
33
+ required?: boolean;
34
+ requiredMessage?: string;
35
+ };
36
+ type PasswordOptions = InputOptions & {
37
+ mask?: string;
38
+ };
39
+ type ConfirmOptions = BasePromptOptions<boolean> & {
40
+ defaultValue?: boolean;
41
+ activeLabel?: string;
42
+ inactiveLabel?: string;
43
+ };
44
+ type NumberOptions = BasePromptOptions<number> & {
45
+ defaultValue?: number;
46
+ min?: number;
47
+ max?: number;
48
+ requiredMessage?: string;
49
+ invalidMessage?: string;
50
+ minMessage?: string;
51
+ maxMessage?: string;
52
+ };
53
+ type SelectChoice<TValue extends string> = {
54
+ value: TValue;
55
+ label?: string;
56
+ hint?: string;
57
+ disabled?: boolean;
58
+ };
59
+ type SelectOptions<TValue extends string> = BasePromptOptions<TValue> & {
60
+ choices: readonly [SelectChoice<TValue>, ...SelectChoice<TValue>[]];
61
+ defaultValue?: TValue;
62
+ };
63
+ type MultiselectOptions<TValue extends string> = BasePromptOptions<TValue[]> & {
64
+ choices: readonly [SelectChoice<TValue>, ...SelectChoice<TValue>[]];
65
+ defaultValue?: readonly TValue[];
66
+ min?: number;
67
+ max?: number;
68
+ };
69
+ //#endregion
4
70
  //#region src/lib/prompts/index.d.ts
5
- declare const input: (options: InputOptions, runtime?: PromptRuntime) => Promise<readonly [{
71
+ declare const input: (options: InputOptions, runtime?: PromptRuntime) => Promise<readonly [null, string] | readonly [{
6
72
  readonly type: string;
7
73
  readonly message: string;
8
- }, null] | readonly [null, string]>;
9
- declare const password: (options: PasswordOptions, runtime?: PromptRuntime) => Promise<readonly [{
74
+ }, null]>;
75
+ declare const password: (options: PasswordOptions, runtime?: PromptRuntime) => Promise<readonly [null, string] | readonly [{
10
76
  readonly type: string;
11
77
  readonly message: string;
12
- }, null] | readonly [null, string]>;
13
- declare const confirm: (options: ConfirmOptions, runtime?: PromptRuntime) => Promise<readonly [{
78
+ }, null]>;
79
+ declare const confirm: (options: ConfirmOptions, runtime?: PromptRuntime) => Promise<readonly [null, boolean] | readonly [{
14
80
  readonly type: string;
15
81
  readonly message: string;
16
- }, null] | readonly [null, boolean]>;
17
- declare const number: (options: NumberOptions, runtime?: PromptRuntime) => Promise<readonly [{
82
+ }, null]>;
83
+ declare const number: (options: NumberOptions, runtime?: PromptRuntime) => Promise<readonly [null, number] | readonly [{
18
84
  readonly type: string;
19
85
  readonly message: string;
20
- }, null] | readonly [null, number]>;
86
+ }, null]>;
21
87
  declare const select: <TValue extends string>(options: SelectOptions<TValue>, runtime?: PromptRuntime) => Promise<readonly [{
22
88
  readonly type: string;
23
89
  readonly message: string;
@@ -27,5 +93,4 @@ declare const multiselect: <TValue extends string>(options: MultiselectOptions<T
27
93
  readonly message: string;
28
94
  }, null] | readonly [null, TValue[]]>;
29
95
  //#endregion
30
- export { type ConfirmOptions, type InputOptions, type MultiselectOptions, type NumberOptions, type PasswordOptions, type PromptErrorType, type PromptRuntime, type SelectChoice, type SelectOptions, confirm, input, multiselect, number, password, select };
31
- //# sourceMappingURL=index.d.cts.map
96
+ export { type ConfirmOptions, type InputOptions, type MultiselectOptions, type NumberOptions, type PasswordOptions, type PromptErrorType, type PromptRuntime, type SelectChoice, type SelectOptions, confirm, input, multiselect, number, password, select };
@@ -1,23 +1,89 @@
1
- import { PromptRuntime } from "../../prompts/core/types.mjs";
2
- import { ConfirmOptions, InputOptions, MultiselectOptions, NumberOptions, PasswordOptions, PromptErrorType, SelectChoice, SelectOptions } from "../../prompts/types.mjs";
1
+ import { i as ok, t as err } from "../../index-BhGNDjPq.mjs";
3
2
 
3
+ //#region src/lib/prompts/core/types.d.ts
4
+ type PromptResultLike<T> = ReturnType<typeof err<string>> | ReturnType<typeof ok<T>>;
5
+ type KeyName = "character" | "enter" | "backspace" | "delete" | "up" | "down" | "left" | "right" | "ctrl_left" | "ctrl_right" | "shift_left" | "shift_right" | "space" | "escape" | "ctrl_c" | "ctrl_backspace" | "ctrl_a" | "home" | "end" | "shift_ctrl_left" | "shift_ctrl_right" | "tab";
6
+ type Key = {
7
+ name: KeyName;
8
+ value?: string;
9
+ };
10
+ type PromptRuntime = {
11
+ isInteractive: () => boolean;
12
+ init: () => PromptResultLike<void>;
13
+ readKey: () => Promise<PromptResultLike<Key>>;
14
+ render: (frame: string) => PromptResultLike<void>;
15
+ done: (frame: string) => PromptResultLike<void>;
16
+ close: () => PromptResultLike<void>;
17
+ interrupt?: (message: string) => PromptResultLike<undefined>;
18
+ };
19
+ //#endregion
20
+ //#region src/lib/prompts/types.d.ts
21
+ type PromptErrorType = "PromptEnvironmentError" | "PromptValidationError" | "PromptCancelledError" | "PromptIOError" | (string & {});
22
+ type MaybePromise<T> = T | Promise<T>;
23
+ type Validate<TValue> = ((value: TValue) => MaybePromise<string | null | undefined>) | undefined;
24
+ type Transform<TValue> = ((value: TValue) => MaybePromise<TValue>) | undefined;
25
+ type BasePromptOptions<TValue> = {
26
+ message: string;
27
+ validate?: Validate<TValue>;
28
+ transform?: Transform<TValue>;
29
+ };
30
+ type InputOptions = BasePromptOptions<string> & {
31
+ defaultValue?: string;
32
+ placeholder?: string;
33
+ required?: boolean;
34
+ requiredMessage?: string;
35
+ };
36
+ type PasswordOptions = InputOptions & {
37
+ mask?: string;
38
+ };
39
+ type ConfirmOptions = BasePromptOptions<boolean> & {
40
+ defaultValue?: boolean;
41
+ activeLabel?: string;
42
+ inactiveLabel?: string;
43
+ };
44
+ type NumberOptions = BasePromptOptions<number> & {
45
+ defaultValue?: number;
46
+ min?: number;
47
+ max?: number;
48
+ requiredMessage?: string;
49
+ invalidMessage?: string;
50
+ minMessage?: string;
51
+ maxMessage?: string;
52
+ };
53
+ type SelectChoice<TValue extends string> = {
54
+ value: TValue;
55
+ label?: string;
56
+ hint?: string;
57
+ disabled?: boolean;
58
+ };
59
+ type SelectOptions<TValue extends string> = BasePromptOptions<TValue> & {
60
+ choices: readonly [SelectChoice<TValue>, ...SelectChoice<TValue>[]];
61
+ defaultValue?: TValue;
62
+ };
63
+ type MultiselectOptions<TValue extends string> = BasePromptOptions<TValue[]> & {
64
+ choices: readonly [SelectChoice<TValue>, ...SelectChoice<TValue>[]];
65
+ defaultValue?: readonly TValue[];
66
+ min?: number;
67
+ max?: number;
68
+ };
69
+ //#endregion
4
70
  //#region src/lib/prompts/index.d.ts
5
- declare const input: (options: InputOptions, runtime?: PromptRuntime) => Promise<readonly [{
71
+ declare const input: (options: InputOptions, runtime?: PromptRuntime) => Promise<readonly [null, string] | readonly [{
6
72
  readonly type: string;
7
73
  readonly message: string;
8
- }, null] | readonly [null, string]>;
9
- declare const password: (options: PasswordOptions, runtime?: PromptRuntime) => Promise<readonly [{
74
+ }, null]>;
75
+ declare const password: (options: PasswordOptions, runtime?: PromptRuntime) => Promise<readonly [null, string] | readonly [{
10
76
  readonly type: string;
11
77
  readonly message: string;
12
- }, null] | readonly [null, string]>;
13
- declare const confirm: (options: ConfirmOptions, runtime?: PromptRuntime) => Promise<readonly [{
78
+ }, null]>;
79
+ declare const confirm: (options: ConfirmOptions, runtime?: PromptRuntime) => Promise<readonly [null, boolean] | readonly [{
14
80
  readonly type: string;
15
81
  readonly message: string;
16
- }, null] | readonly [null, boolean]>;
17
- declare const number: (options: NumberOptions, runtime?: PromptRuntime) => Promise<readonly [{
82
+ }, null]>;
83
+ declare const number: (options: NumberOptions, runtime?: PromptRuntime) => Promise<readonly [null, number] | readonly [{
18
84
  readonly type: string;
19
85
  readonly message: string;
20
- }, null] | readonly [null, number]>;
86
+ }, null]>;
21
87
  declare const select: <TValue extends string>(options: SelectOptions<TValue>, runtime?: PromptRuntime) => Promise<readonly [{
22
88
  readonly type: string;
23
89
  readonly message: string;
@@ -27,5 +93,4 @@ declare const multiselect: <TValue extends string>(options: MultiselectOptions<T
27
93
  readonly message: string;
28
94
  }, null] | readonly [null, TValue[]]>;
29
95
  //#endregion
30
- export { type ConfirmOptions, type InputOptions, type MultiselectOptions, type NumberOptions, type PasswordOptions, type PromptErrorType, type PromptRuntime, type SelectChoice, type SelectOptions, confirm, input, multiselect, number, password, select };
31
- //# sourceMappingURL=index.d.mts.map
96
+ export { type ConfirmOptions, type InputOptions, type MultiselectOptions, type NumberOptions, type PasswordOptions, type PromptErrorType, type PromptRuntime, type SelectChoice, type SelectOptions, confirm, input, multiselect, number, password, select };
@@ -1,6 +1,366 @@
1
- import { createNodePromptRuntime } from "../../prompts/core/runtime.mjs";
2
- import { runPromptSession } from "../../prompts/core/session.mjs";
1
+ import { err, mightThrow, mightThrowSync, ok } from "../errors/index.mjs";
3
2
  import { styleText } from "node:util";
3
+ //#region src/lib/prompts/core/keys.ts
4
+ const ESC = "\x1B";
5
+ const CSI = "\x1B[";
6
+ const ESC_BACKSPACE = `${ESC}\u007F`;
7
+ const CHAR_KEY_MAP = new Map(Object.values({
8
+ enterCr: {
9
+ value: "\r",
10
+ name: "enter"
11
+ },
12
+ enterLf: {
13
+ value: "\n",
14
+ name: "enter"
15
+ },
16
+ ctrlA: {
17
+ value: "",
18
+ name: "ctrl_a"
19
+ },
20
+ ctrlC: {
21
+ value: "",
22
+ name: "ctrl_c"
23
+ },
24
+ ctrlBackspace: {
25
+ value: "",
26
+ name: "ctrl_backspace"
27
+ },
28
+ backspace: {
29
+ value: "",
30
+ name: "backspace"
31
+ },
32
+ tab: {
33
+ value: " ",
34
+ name: "tab"
35
+ },
36
+ space: {
37
+ value: " ",
38
+ name: "space"
39
+ }
40
+ }).map((entry) => [entry.value, { name: entry.name }]));
41
+ const KNOWN_SEQUENCES = [
42
+ {
43
+ sequence: "\x1B[1;2D",
44
+ key: { name: "shift_left" }
45
+ },
46
+ {
47
+ sequence: "\x1B[1;2C",
48
+ key: { name: "shift_right" }
49
+ },
50
+ {
51
+ sequence: "\x1B[1;5D",
52
+ key: { name: "ctrl_left" }
53
+ },
54
+ {
55
+ sequence: "\x1B[1;5C",
56
+ key: { name: "ctrl_right" }
57
+ },
58
+ {
59
+ sequence: "\x1B[1;6D",
60
+ key: { name: "shift_ctrl_left" }
61
+ },
62
+ {
63
+ sequence: "\x1B[1;6C",
64
+ key: { name: "shift_ctrl_right" }
65
+ },
66
+ {
67
+ sequence: "\x1B[3~",
68
+ key: { name: "delete" }
69
+ },
70
+ {
71
+ sequence: "\x1B[H",
72
+ key: { name: "home" }
73
+ },
74
+ {
75
+ sequence: "\x1B[F",
76
+ key: { name: "end" }
77
+ },
78
+ {
79
+ sequence: "\x1B[A",
80
+ key: { name: "up" }
81
+ },
82
+ {
83
+ sequence: "\x1B[B",
84
+ key: { name: "down" }
85
+ },
86
+ {
87
+ sequence: "\x1B[C",
88
+ key: { name: "right" }
89
+ },
90
+ {
91
+ sequence: "\x1B[D",
92
+ key: { name: "left" }
93
+ }
94
+ ];
95
+ const isControlChar = (char) => {
96
+ return char <= "" || char === "";
97
+ };
98
+ const isCsiFinalByte = (char) => {
99
+ if (!char) return false;
100
+ if (char >= "A" && char <= "Z") return true;
101
+ if (char >= "a" && char <= "z") return true;
102
+ if (char === "~") return true;
103
+ return false;
104
+ };
105
+ const readCsiLength = (remaining) => {
106
+ if (!remaining.startsWith(CSI)) return null;
107
+ let index = 2;
108
+ while (index < remaining.length) {
109
+ if (isCsiFinalByte(remaining[index] ?? "")) return {
110
+ length: index + 1,
111
+ incomplete: false
112
+ };
113
+ index += 1;
114
+ }
115
+ return {
116
+ length: 0,
117
+ incomplete: true
118
+ };
119
+ };
120
+ const parseKeys = (chunk) => {
121
+ const keys = [];
122
+ let cursor = 0;
123
+ while (cursor < chunk.length) {
124
+ const remaining = chunk.slice(cursor);
125
+ if (remaining.startsWith(ESC_BACKSPACE)) {
126
+ keys.push({ name: "ctrl_backspace" });
127
+ cursor += 2;
128
+ continue;
129
+ }
130
+ const knownSequence = KNOWN_SEQUENCES.find((entry) => remaining.startsWith(entry.sequence));
131
+ if (knownSequence) {
132
+ keys.push(knownSequence.key);
133
+ cursor += knownSequence.sequence.length;
134
+ continue;
135
+ }
136
+ const csiLength = readCsiLength(remaining);
137
+ if (csiLength) {
138
+ if (csiLength.incomplete) return {
139
+ keys,
140
+ remaining: chunk.slice(cursor)
141
+ };
142
+ cursor += csiLength.length;
143
+ continue;
144
+ }
145
+ const char = chunk[cursor] ?? "";
146
+ switch (char) {
147
+ case ESC:
148
+ if (cursor === chunk.length - 1) keys.push({ name: "escape" });
149
+ break;
150
+ default: {
151
+ const key = CHAR_KEY_MAP.get(char);
152
+ if (key) keys.push(key);
153
+ else if (!isControlChar(char)) keys.push({
154
+ name: "character",
155
+ value: char
156
+ });
157
+ }
158
+ }
159
+ cursor += 1;
160
+ }
161
+ return {
162
+ keys,
163
+ remaining: ""
164
+ };
165
+ };
166
+ //#endregion
167
+ //#region src/lib/prompts/core/runtime.ts
168
+ const HIDE_CURSOR = "\x1B[?25l";
169
+ const SHOW_CURSOR = "\x1B[?25h";
170
+ const countLines = (text) => {
171
+ let count = 1;
172
+ for (let i = 0; i < text.length; i++) if (text[i] === "\n") count += 1;
173
+ return count;
174
+ };
175
+ var NodePromptRuntime = class {
176
+ stdin;
177
+ stdout;
178
+ queue = [];
179
+ waiters = [];
180
+ initialized = false;
181
+ previousLines = 0;
182
+ buffer = "";
183
+ constructor(stdin = process.stdin, stdout = process.stdout) {
184
+ this.stdin = stdin;
185
+ this.stdout = stdout;
186
+ }
187
+ isInteractive() {
188
+ return Boolean(this.stdin.isTTY && this.stdout.isTTY && typeof this.stdin.setRawMode === "function");
189
+ }
190
+ init() {
191
+ if (!this.isInteractive()) return err("PromptEnvironmentError", "Interactive prompts require a TTY with raw mode support");
192
+ if (this.initialized) return ok(void 0);
193
+ const [initError] = mightThrowSync(() => {
194
+ this.stdin.setRawMode(true);
195
+ this.stdin.setEncoding("utf8");
196
+ this.stdin.resume();
197
+ this.stdin.on("data", this.onData);
198
+ this.stdout.write(HIDE_CURSOR);
199
+ });
200
+ if (initError) return err("PromptIOError", "Unable to initialize prompt runtime");
201
+ this.initialized = true;
202
+ return ok(void 0);
203
+ }
204
+ readKey() {
205
+ const queued = this.queue.shift();
206
+ if (queued) return Promise.resolve(ok(queued));
207
+ return new Promise((resolve) => {
208
+ this.waiters.push(resolve);
209
+ });
210
+ }
211
+ render(frame) {
212
+ const [renderError] = mightThrowSync(() => {
213
+ if (this.previousLines > 1) this.stdout.write(`\u001B[${this.previousLines - 1}A`);
214
+ this.stdout.write("\r\x1B[J");
215
+ this.stdout.write(frame);
216
+ this.previousLines = countLines(frame);
217
+ });
218
+ if (renderError) return err("PromptIOError", "Unable to render prompt frame");
219
+ return ok(void 0);
220
+ }
221
+ done(frame) {
222
+ const [doneError] = mightThrowSync(() => {
223
+ if (this.previousLines > 1) this.stdout.write(`\u001B[${this.previousLines - 1}A`);
224
+ this.stdout.write("\r\x1B[J");
225
+ this.stdout.write(`${frame}\n`);
226
+ this.previousLines = 0;
227
+ });
228
+ if (doneError) return err("PromptIOError", "Unable to finalize prompt frame");
229
+ return ok(void 0);
230
+ }
231
+ close() {
232
+ if (!this.initialized) return ok(void 0);
233
+ this.initialized = false;
234
+ const [closeError] = mightThrowSync(() => {
235
+ this.stdin.off("data", this.onData);
236
+ this.stdin.setRawMode(false);
237
+ this.stdin.pause?.();
238
+ this.stdout.write(SHOW_CURSOR);
239
+ });
240
+ if (closeError) return err("PromptIOError", "Unable to close prompt runtime");
241
+ return ok(void 0);
242
+ }
243
+ interrupt() {
244
+ this.close();
245
+ process.exit(0);
246
+ }
247
+ onData = (chunk) => {
248
+ const value = typeof chunk === "string" ? chunk : chunk.toString("utf8");
249
+ const combined = `${this.buffer}${value}`;
250
+ this.buffer = "";
251
+ const [parseError, result] = mightThrowSync(() => parseKeys(combined));
252
+ if (parseError || !result) {
253
+ for (const waiter of this.waiters.splice(0)) waiter(err("PromptIOError", "Failed to parse input"));
254
+ return;
255
+ }
256
+ this.buffer = result.remaining;
257
+ for (const key of result.keys) {
258
+ const waiter = this.waiters.shift();
259
+ if (waiter) waiter(ok(key));
260
+ else this.queue.push(key);
261
+ }
262
+ };
263
+ };
264
+ const createNodePromptRuntime = () => {
265
+ return new NodePromptRuntime();
266
+ };
267
+ //#endregion
268
+ //#region src/lib/prompts/core/session.ts
269
+ const CANCEL_MESSAGE = "Interrupted, bye!";
270
+ const resolveOutput = async (options, value) => {
271
+ if (!options.transform) return ok(value);
272
+ const [transformError, transformed] = await mightThrow(Promise.resolve().then(() => options.transform?.(value)));
273
+ if (transformError || transformed === null || transformed === void 0) return err("PromptIOError", "Prompt transform callback failed unexpectedly");
274
+ return ok(transformed);
275
+ };
276
+ const runValidation = async (options, value) => {
277
+ if (!options.validate) return ok(null);
278
+ const [validationError, validationMessage] = await mightThrow(Promise.resolve().then(() => options.validate?.(value)));
279
+ if (validationError) return err("PromptIOError", "Prompt validate callback failed unexpectedly");
280
+ if (typeof validationMessage === "string" && validationMessage.length > 0) return ok(validationMessage);
281
+ return ok(null);
282
+ };
283
+ const isCancelKey = (key) => {
284
+ if (key.name === "ctrl_c") return true;
285
+ if (key.name === "escape") return true;
286
+ return false;
287
+ };
288
+ const runPromptSession = async (params) => {
289
+ const [initError] = params.runtime.init();
290
+ if (initError) return err(initError.type, initError.message);
291
+ let state = params.initialState;
292
+ let errorMessage = null;
293
+ const closeAndDone = (message) => {
294
+ const [closeErr] = params.runtime.close();
295
+ if (closeErr) return err(closeErr.type, closeErr.message);
296
+ const [doneErr] = params.runtime.done(message);
297
+ if (doneErr) return err(doneErr.type, doneErr.message);
298
+ return null;
299
+ };
300
+ while (true) {
301
+ const [renderError] = params.runtime.render(params.render({
302
+ options: params.options,
303
+ state,
304
+ errorMessage
305
+ }));
306
+ if (renderError) {
307
+ params.runtime.close();
308
+ return err(renderError.type, renderError.message);
309
+ }
310
+ const [readError, key] = await params.runtime.readKey();
311
+ if (readError || !key) {
312
+ params.runtime.close();
313
+ return err(readError?.type ?? "PromptIOError", readError?.message ?? "Unable to read prompt input");
314
+ }
315
+ if (isCancelKey(key)) {
316
+ const [closeError] = params.runtime.close();
317
+ if (closeError) return err(closeError.type, closeError.message);
318
+ const [doneError] = params.runtime.done(`✖ ${CANCEL_MESSAGE}`);
319
+ if (doneError) return err(doneError.type, doneError.message);
320
+ if (params.runtime.interrupt) {
321
+ const [interruptError] = params.runtime.interrupt(CANCEL_MESSAGE);
322
+ if (interruptError) return err(interruptError.type, interruptError.message);
323
+ }
324
+ return err("PromptCancelledError", CANCEL_MESSAGE);
325
+ }
326
+ if (key.name !== "enter") {
327
+ state = params.onKey(state, key);
328
+ errorMessage = null;
329
+ continue;
330
+ }
331
+ const submitResult = params.onSubmit(state);
332
+ if ("errorMessage" in submitResult) {
333
+ errorMessage = submitResult.errorMessage;
334
+ continue;
335
+ }
336
+ const rawValue = submitResult.value;
337
+ const [validationRunError, validationErrorMessage] = await runValidation(params.options, rawValue);
338
+ if (validationRunError) {
339
+ const closeDoneErr = closeAndDone(`✖ ${params.options.message}`);
340
+ if (closeDoneErr) return closeDoneErr;
341
+ return err(validationRunError.type, validationRunError.message);
342
+ }
343
+ if (validationErrorMessage) {
344
+ errorMessage = validationErrorMessage;
345
+ continue;
346
+ }
347
+ const [transformError, finalValue] = await resolveOutput(params.options, rawValue);
348
+ if (transformError) {
349
+ const closeDoneErr = closeAndDone(`✖ ${params.options.message}`);
350
+ if (closeDoneErr) return closeDoneErr;
351
+ return err(transformError.type, transformError.message);
352
+ }
353
+ if (finalValue === null) return err("PromptIOError", "Unable to transform prompt value");
354
+ const closeDoneErr = closeAndDone(params.complete({
355
+ options: params.options,
356
+ state,
357
+ value: finalValue
358
+ }));
359
+ if (closeDoneErr) return closeDoneErr;
360
+ return ok(finalValue);
361
+ }
362
+ };
363
+ //#endregion
4
364
  //#region src/lib/prompts/index.ts
5
365
  const pointer = (active) => {
6
366
  return active ? paint("cyan", "❯") : " ";
@@ -401,5 +761,3 @@ const multiselect = async (options, runtime) => {
401
761
  };
402
762
  //#endregion
403
763
  export { confirm, input, multiselect, number, password, select };
404
-
405
- //# sourceMappingURL=index.mjs.map