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,6 +1,63 @@
1
- import { ConditionHelper, and, endsWith, eq, gt, gte, has, hasAny, hasLength, includes, isDefined, isEmpty, isNullish, lt, lte, matches, neq, not, or, startsWith } from "../../policy/helpers.mjs";
2
- import { Action, AllowParams, ForbidParams } from "../../policy/types.mjs";
3
-
1
+ //#region src/lib/policy/helpers.d.ts
2
+ declare const _brand: unique symbol;
3
+ type ConditionHelper<V> = {
4
+ readonly [_brand]: (actual: V) => boolean;
5
+ operator: string;
6
+ value: unknown;
7
+ fn: (actual: V) => boolean;
8
+ };
9
+ declare const eq: <V>(value: V) => ConditionHelper<V>;
10
+ declare const neq: <V>(value: V) => ConditionHelper<V>;
11
+ declare const gt: {
12
+ (value: Date): ConditionHelper<Date>;
13
+ (value: number): ConditionHelper<number>;
14
+ (value: string): ConditionHelper<string>;
15
+ };
16
+ declare const gte: {
17
+ (value: Date): ConditionHelper<Date>;
18
+ (value: number): ConditionHelper<number>;
19
+ (value: string): ConditionHelper<string>;
20
+ };
21
+ declare const lt: {
22
+ (value: Date): ConditionHelper<Date>;
23
+ (value: number): ConditionHelper<number>;
24
+ (value: string): ConditionHelper<string>;
25
+ };
26
+ declare const lte: {
27
+ (value: Date): ConditionHelper<Date>;
28
+ (value: number): ConditionHelper<number>;
29
+ (value: string): ConditionHelper<string>;
30
+ };
31
+ declare const not: <V>(inner: ConditionHelper<V>) => ConditionHelper<V>;
32
+ declare const and: <V>(...helpers: ConditionHelper<V>[]) => ConditionHelper<V>;
33
+ declare const or: <V>(...helpers: ConditionHelper<V>[]) => ConditionHelper<V>;
34
+ declare const startsWith: (prefix: string) => ConditionHelper<string>;
35
+ declare const endsWith: (suffix: string) => ConditionHelper<string>;
36
+ declare const includes: (substring: string) => ConditionHelper<string>;
37
+ declare const matches: (pattern: RegExp) => ConditionHelper<string>;
38
+ declare const has: <V>(items: V | V[]) => ConditionHelper<V[]>;
39
+ declare const hasAny: <V>(items: V | V[]) => ConditionHelper<V[]>;
40
+ type HasLengthArg = number | {
41
+ min?: number;
42
+ max?: number;
43
+ };
44
+ declare const hasLength: (length: HasLengthArg) => ConditionHelper<string | unknown[]>;
45
+ declare const isEmpty: () => ConditionHelper<string | unknown[]>;
46
+ declare const isDefined: () => ConditionHelper<unknown>;
47
+ declare const isNullish: () => ConditionHelper<unknown>;
48
+ //#endregion
49
+ //#region src/lib/policy/types.d.ts
50
+ type Action = "read" | "create" | "update" | "delete" | (string & {});
51
+ type ConditionValue<V> = V extends Record<string, unknown> ? ConditionHelper<V> | Conditions<V> : ConditionHelper<V>;
52
+ type Conditions<T = Record<string, unknown>> = { [K in keyof T]?: ConditionValue<T[K]> };
53
+ type PolicyRuleParams<T = Record<string, unknown>> = {
54
+ action: Action | Action[];
55
+ conditions?: Conditions<T>;
56
+ reason?: string;
57
+ };
58
+ type AllowParams<T = Record<string, unknown>> = PolicyRuleParams<T>;
59
+ type ForbidParams<T = Record<string, unknown>> = PolicyRuleParams<T>;
60
+ //#endregion
4
61
  //#region src/lib/policy/index.d.ts
5
62
  declare class Policy<TEntity extends Record<string, unknown> = Record<string, unknown>> {
6
63
  private rules;
@@ -17,5 +74,4 @@ declare class Policy<TEntity extends Record<string, unknown> = Record<string, un
17
74
  private matchValue;
18
75
  }
19
76
  //#endregion
20
- export { type ConditionHelper, Policy, and, endsWith, eq, gt, gte, has, hasAny, hasLength, includes, isDefined, isEmpty, isNullish, lt, lte, matches, neq, not, or, startsWith };
21
- //# sourceMappingURL=index.d.mts.map
77
+ export { type ConditionHelper, Policy, and, endsWith, eq, gt, gte, has, hasAny, hasLength, includes, isDefined, isEmpty, isNullish, lt, lte, matches, neq, not, or, startsWith };
@@ -1,4 +1,190 @@
1
- import { and, endsWith, eq, gt, gte, has, hasAny, hasLength, includes, isDefined, isEmpty, isNullish, lt, lte, matches, neq, not, or, startsWith } from "../../policy/helpers.mjs";
1
+ //#region src/lib/policy/helpers.ts
2
+ const _brand = Symbol("conditionHelper");
3
+ const eq = (value) => {
4
+ const fn = (actual) => actual === value;
5
+ return {
6
+ [_brand]: fn,
7
+ operator: "eq",
8
+ value,
9
+ fn
10
+ };
11
+ };
12
+ const neq = (value) => {
13
+ const fn = (actual) => actual !== value;
14
+ return {
15
+ [_brand]: fn,
16
+ operator: "neq",
17
+ value,
18
+ fn
19
+ };
20
+ };
21
+ const gt = (value) => {
22
+ const fn = (actual) => actual > value;
23
+ return {
24
+ [_brand]: fn,
25
+ operator: "gt",
26
+ value,
27
+ fn
28
+ };
29
+ };
30
+ const gte = (value) => {
31
+ const fn = (actual) => actual >= value;
32
+ return {
33
+ [_brand]: fn,
34
+ operator: "gte",
35
+ value,
36
+ fn
37
+ };
38
+ };
39
+ const lt = (value) => {
40
+ const fn = (actual) => actual < value;
41
+ return {
42
+ [_brand]: fn,
43
+ operator: "lt",
44
+ value,
45
+ fn
46
+ };
47
+ };
48
+ const lte = (value) => {
49
+ const fn = (actual) => actual <= value;
50
+ return {
51
+ [_brand]: fn,
52
+ operator: "lte",
53
+ value,
54
+ fn
55
+ };
56
+ };
57
+ const not = (inner) => {
58
+ const fn = (actual) => !inner.fn(actual);
59
+ return {
60
+ [_brand]: fn,
61
+ operator: "not",
62
+ value: inner,
63
+ fn
64
+ };
65
+ };
66
+ const and = (...helpers) => {
67
+ const fn = (actual) => helpers.every((h) => h.fn(actual));
68
+ return {
69
+ [_brand]: fn,
70
+ operator: "and",
71
+ value: helpers,
72
+ fn
73
+ };
74
+ };
75
+ const or = (...helpers) => {
76
+ const fn = (actual) => helpers.some((h) => h.fn(actual));
77
+ return {
78
+ [_brand]: fn,
79
+ operator: "or",
80
+ value: helpers,
81
+ fn
82
+ };
83
+ };
84
+ const startsWith = (prefix) => {
85
+ const fn = (actual) => actual.startsWith(prefix);
86
+ return {
87
+ [_brand]: fn,
88
+ operator: "startsWith",
89
+ value: prefix,
90
+ fn
91
+ };
92
+ };
93
+ const endsWith = (suffix) => {
94
+ const fn = (actual) => actual.endsWith(suffix);
95
+ return {
96
+ [_brand]: fn,
97
+ operator: "endsWith",
98
+ value: suffix,
99
+ fn
100
+ };
101
+ };
102
+ const includes = (substring) => {
103
+ const fn = (actual) => actual.includes(substring);
104
+ return {
105
+ [_brand]: fn,
106
+ operator: "includes",
107
+ value: substring,
108
+ fn
109
+ };
110
+ };
111
+ const matches = (pattern) => {
112
+ const fn = (actual) => {
113
+ pattern.lastIndex = 0;
114
+ return pattern.test(actual);
115
+ };
116
+ return {
117
+ [_brand]: fn,
118
+ operator: "matches",
119
+ value: pattern,
120
+ fn
121
+ };
122
+ };
123
+ const has = (items) => {
124
+ const fn = (actual) => {
125
+ if (Array.isArray(items)) return items.every((item) => actual.includes(item));
126
+ return actual.includes(items);
127
+ };
128
+ return {
129
+ [_brand]: fn,
130
+ operator: "has",
131
+ value: items,
132
+ fn
133
+ };
134
+ };
135
+ const hasAny = (items) => {
136
+ const normalized = Array.isArray(items) ? items : [items];
137
+ const fn = (actual) => normalized.some((item) => actual.includes(item));
138
+ return {
139
+ [_brand]: fn,
140
+ operator: "hasAny",
141
+ value: items,
142
+ fn
143
+ };
144
+ };
145
+ const hasLength = (length) => {
146
+ const fn = (actual) => {
147
+ const len = actual.length;
148
+ if (typeof length === "number") return len === length;
149
+ if (length.min !== void 0 && len < length.min) return false;
150
+ if (length.max !== void 0 && len > length.max) return false;
151
+ return true;
152
+ };
153
+ return {
154
+ [_brand]: fn,
155
+ operator: "hasLength",
156
+ value: length,
157
+ fn
158
+ };
159
+ };
160
+ const isEmpty = () => {
161
+ const fn = (actual) => actual.length === 0;
162
+ return {
163
+ [_brand]: fn,
164
+ operator: "isEmpty",
165
+ value: void 0,
166
+ fn
167
+ };
168
+ };
169
+ const isDefined = () => {
170
+ const fn = (actual) => actual !== null && actual !== void 0;
171
+ return {
172
+ [_brand]: fn,
173
+ operator: "isDefined",
174
+ value: void 0,
175
+ fn
176
+ };
177
+ };
178
+ const isNullish = () => {
179
+ const fn = (actual) => actual === null || actual === void 0;
180
+ return {
181
+ [_brand]: fn,
182
+ operator: "isNullish",
183
+ value: void 0,
184
+ fn
185
+ };
186
+ };
187
+ //#endregion
2
188
  //#region src/lib/policy/index.ts
3
189
  var Policy = class {
4
190
  rules = [];
@@ -77,5 +263,3 @@ var Policy = class {
77
263
  };
78
264
  //#endregion
79
265
  export { Policy, and, endsWith, eq, gt, gte, has, hasAny, hasLength, includes, isDefined, isEmpty, isNullish, lt, lte, matches, neq, not, or, startsWith };
80
-
81
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,367 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_runtime = require("../../prompts/core/runtime.cjs");
3
- const require_session = require("../../prompts/core/session.cjs");
2
+ const require_lib_errors_index = require("../errors/index.cjs");
4
3
  let node_util = require("node:util");
4
+ //#region src/lib/prompts/core/keys.ts
5
+ const ESC = "\x1B";
6
+ const CSI = "\x1B[";
7
+ const ESC_BACKSPACE = `${ESC}\u007F`;
8
+ const CHAR_KEY_MAP = new Map(Object.values({
9
+ enterCr: {
10
+ value: "\r",
11
+ name: "enter"
12
+ },
13
+ enterLf: {
14
+ value: "\n",
15
+ name: "enter"
16
+ },
17
+ ctrlA: {
18
+ value: "",
19
+ name: "ctrl_a"
20
+ },
21
+ ctrlC: {
22
+ value: "",
23
+ name: "ctrl_c"
24
+ },
25
+ ctrlBackspace: {
26
+ value: "",
27
+ name: "ctrl_backspace"
28
+ },
29
+ backspace: {
30
+ value: "",
31
+ name: "backspace"
32
+ },
33
+ tab: {
34
+ value: " ",
35
+ name: "tab"
36
+ },
37
+ space: {
38
+ value: " ",
39
+ name: "space"
40
+ }
41
+ }).map((entry) => [entry.value, { name: entry.name }]));
42
+ const KNOWN_SEQUENCES = [
43
+ {
44
+ sequence: "\x1B[1;2D",
45
+ key: { name: "shift_left" }
46
+ },
47
+ {
48
+ sequence: "\x1B[1;2C",
49
+ key: { name: "shift_right" }
50
+ },
51
+ {
52
+ sequence: "\x1B[1;5D",
53
+ key: { name: "ctrl_left" }
54
+ },
55
+ {
56
+ sequence: "\x1B[1;5C",
57
+ key: { name: "ctrl_right" }
58
+ },
59
+ {
60
+ sequence: "\x1B[1;6D",
61
+ key: { name: "shift_ctrl_left" }
62
+ },
63
+ {
64
+ sequence: "\x1B[1;6C",
65
+ key: { name: "shift_ctrl_right" }
66
+ },
67
+ {
68
+ sequence: "\x1B[3~",
69
+ key: { name: "delete" }
70
+ },
71
+ {
72
+ sequence: "\x1B[H",
73
+ key: { name: "home" }
74
+ },
75
+ {
76
+ sequence: "\x1B[F",
77
+ key: { name: "end" }
78
+ },
79
+ {
80
+ sequence: "\x1B[A",
81
+ key: { name: "up" }
82
+ },
83
+ {
84
+ sequence: "\x1B[B",
85
+ key: { name: "down" }
86
+ },
87
+ {
88
+ sequence: "\x1B[C",
89
+ key: { name: "right" }
90
+ },
91
+ {
92
+ sequence: "\x1B[D",
93
+ key: { name: "left" }
94
+ }
95
+ ];
96
+ const isControlChar = (char) => {
97
+ return char <= "" || char === "";
98
+ };
99
+ const isCsiFinalByte = (char) => {
100
+ if (!char) return false;
101
+ if (char >= "A" && char <= "Z") return true;
102
+ if (char >= "a" && char <= "z") return true;
103
+ if (char === "~") return true;
104
+ return false;
105
+ };
106
+ const readCsiLength = (remaining) => {
107
+ if (!remaining.startsWith(CSI)) return null;
108
+ let index = 2;
109
+ while (index < remaining.length) {
110
+ if (isCsiFinalByte(remaining[index] ?? "")) return {
111
+ length: index + 1,
112
+ incomplete: false
113
+ };
114
+ index += 1;
115
+ }
116
+ return {
117
+ length: 0,
118
+ incomplete: true
119
+ };
120
+ };
121
+ const parseKeys = (chunk) => {
122
+ const keys = [];
123
+ let cursor = 0;
124
+ while (cursor < chunk.length) {
125
+ const remaining = chunk.slice(cursor);
126
+ if (remaining.startsWith(ESC_BACKSPACE)) {
127
+ keys.push({ name: "ctrl_backspace" });
128
+ cursor += 2;
129
+ continue;
130
+ }
131
+ const knownSequence = KNOWN_SEQUENCES.find((entry) => remaining.startsWith(entry.sequence));
132
+ if (knownSequence) {
133
+ keys.push(knownSequence.key);
134
+ cursor += knownSequence.sequence.length;
135
+ continue;
136
+ }
137
+ const csiLength = readCsiLength(remaining);
138
+ if (csiLength) {
139
+ if (csiLength.incomplete) return {
140
+ keys,
141
+ remaining: chunk.slice(cursor)
142
+ };
143
+ cursor += csiLength.length;
144
+ continue;
145
+ }
146
+ const char = chunk[cursor] ?? "";
147
+ switch (char) {
148
+ case ESC:
149
+ if (cursor === chunk.length - 1) keys.push({ name: "escape" });
150
+ break;
151
+ default: {
152
+ const key = CHAR_KEY_MAP.get(char);
153
+ if (key) keys.push(key);
154
+ else if (!isControlChar(char)) keys.push({
155
+ name: "character",
156
+ value: char
157
+ });
158
+ }
159
+ }
160
+ cursor += 1;
161
+ }
162
+ return {
163
+ keys,
164
+ remaining: ""
165
+ };
166
+ };
167
+ //#endregion
168
+ //#region src/lib/prompts/core/runtime.ts
169
+ const HIDE_CURSOR = "\x1B[?25l";
170
+ const SHOW_CURSOR = "\x1B[?25h";
171
+ const countLines = (text) => {
172
+ let count = 1;
173
+ for (let i = 0; i < text.length; i++) if (text[i] === "\n") count += 1;
174
+ return count;
175
+ };
176
+ var NodePromptRuntime = class {
177
+ stdin;
178
+ stdout;
179
+ queue = [];
180
+ waiters = [];
181
+ initialized = false;
182
+ previousLines = 0;
183
+ buffer = "";
184
+ constructor(stdin = process.stdin, stdout = process.stdout) {
185
+ this.stdin = stdin;
186
+ this.stdout = stdout;
187
+ }
188
+ isInteractive() {
189
+ return Boolean(this.stdin.isTTY && this.stdout.isTTY && typeof this.stdin.setRawMode === "function");
190
+ }
191
+ init() {
192
+ if (!this.isInteractive()) return require_lib_errors_index.err("PromptEnvironmentError", "Interactive prompts require a TTY with raw mode support");
193
+ if (this.initialized) return require_lib_errors_index.ok(void 0);
194
+ const [initError] = require_lib_errors_index.mightThrowSync(() => {
195
+ this.stdin.setRawMode(true);
196
+ this.stdin.setEncoding("utf8");
197
+ this.stdin.resume();
198
+ this.stdin.on("data", this.onData);
199
+ this.stdout.write(HIDE_CURSOR);
200
+ });
201
+ if (initError) return require_lib_errors_index.err("PromptIOError", "Unable to initialize prompt runtime");
202
+ this.initialized = true;
203
+ return require_lib_errors_index.ok(void 0);
204
+ }
205
+ readKey() {
206
+ const queued = this.queue.shift();
207
+ if (queued) return Promise.resolve(require_lib_errors_index.ok(queued));
208
+ return new Promise((resolve) => {
209
+ this.waiters.push(resolve);
210
+ });
211
+ }
212
+ render(frame) {
213
+ const [renderError] = require_lib_errors_index.mightThrowSync(() => {
214
+ if (this.previousLines > 1) this.stdout.write(`\u001B[${this.previousLines - 1}A`);
215
+ this.stdout.write("\r\x1B[J");
216
+ this.stdout.write(frame);
217
+ this.previousLines = countLines(frame);
218
+ });
219
+ if (renderError) return require_lib_errors_index.err("PromptIOError", "Unable to render prompt frame");
220
+ return require_lib_errors_index.ok(void 0);
221
+ }
222
+ done(frame) {
223
+ const [doneError] = require_lib_errors_index.mightThrowSync(() => {
224
+ if (this.previousLines > 1) this.stdout.write(`\u001B[${this.previousLines - 1}A`);
225
+ this.stdout.write("\r\x1B[J");
226
+ this.stdout.write(`${frame}\n`);
227
+ this.previousLines = 0;
228
+ });
229
+ if (doneError) return require_lib_errors_index.err("PromptIOError", "Unable to finalize prompt frame");
230
+ return require_lib_errors_index.ok(void 0);
231
+ }
232
+ close() {
233
+ if (!this.initialized) return require_lib_errors_index.ok(void 0);
234
+ this.initialized = false;
235
+ const [closeError] = require_lib_errors_index.mightThrowSync(() => {
236
+ this.stdin.off("data", this.onData);
237
+ this.stdin.setRawMode(false);
238
+ this.stdin.pause?.();
239
+ this.stdout.write(SHOW_CURSOR);
240
+ });
241
+ if (closeError) return require_lib_errors_index.err("PromptIOError", "Unable to close prompt runtime");
242
+ return require_lib_errors_index.ok(void 0);
243
+ }
244
+ interrupt() {
245
+ this.close();
246
+ process.exit(0);
247
+ }
248
+ onData = (chunk) => {
249
+ const value = typeof chunk === "string" ? chunk : chunk.toString("utf8");
250
+ const combined = `${this.buffer}${value}`;
251
+ this.buffer = "";
252
+ const [parseError, result] = require_lib_errors_index.mightThrowSync(() => parseKeys(combined));
253
+ if (parseError || !result) {
254
+ for (const waiter of this.waiters.splice(0)) waiter(require_lib_errors_index.err("PromptIOError", "Failed to parse input"));
255
+ return;
256
+ }
257
+ this.buffer = result.remaining;
258
+ for (const key of result.keys) {
259
+ const waiter = this.waiters.shift();
260
+ if (waiter) waiter(require_lib_errors_index.ok(key));
261
+ else this.queue.push(key);
262
+ }
263
+ };
264
+ };
265
+ const createNodePromptRuntime = () => {
266
+ return new NodePromptRuntime();
267
+ };
268
+ //#endregion
269
+ //#region src/lib/prompts/core/session.ts
270
+ const CANCEL_MESSAGE = "Interrupted, bye!";
271
+ const resolveOutput = async (options, value) => {
272
+ if (!options.transform) return require_lib_errors_index.ok(value);
273
+ const [transformError, transformed] = await require_lib_errors_index.mightThrow(Promise.resolve().then(() => options.transform?.(value)));
274
+ if (transformError || transformed === null || transformed === void 0) return require_lib_errors_index.err("PromptIOError", "Prompt transform callback failed unexpectedly");
275
+ return require_lib_errors_index.ok(transformed);
276
+ };
277
+ const runValidation = async (options, value) => {
278
+ if (!options.validate) return require_lib_errors_index.ok(null);
279
+ const [validationError, validationMessage] = await require_lib_errors_index.mightThrow(Promise.resolve().then(() => options.validate?.(value)));
280
+ if (validationError) return require_lib_errors_index.err("PromptIOError", "Prompt validate callback failed unexpectedly");
281
+ if (typeof validationMessage === "string" && validationMessage.length > 0) return require_lib_errors_index.ok(validationMessage);
282
+ return require_lib_errors_index.ok(null);
283
+ };
284
+ const isCancelKey = (key) => {
285
+ if (key.name === "ctrl_c") return true;
286
+ if (key.name === "escape") return true;
287
+ return false;
288
+ };
289
+ const runPromptSession = async (params) => {
290
+ const [initError] = params.runtime.init();
291
+ if (initError) return require_lib_errors_index.err(initError.type, initError.message);
292
+ let state = params.initialState;
293
+ let errorMessage = null;
294
+ const closeAndDone = (message) => {
295
+ const [closeErr] = params.runtime.close();
296
+ if (closeErr) return require_lib_errors_index.err(closeErr.type, closeErr.message);
297
+ const [doneErr] = params.runtime.done(message);
298
+ if (doneErr) return require_lib_errors_index.err(doneErr.type, doneErr.message);
299
+ return null;
300
+ };
301
+ while (true) {
302
+ const [renderError] = params.runtime.render(params.render({
303
+ options: params.options,
304
+ state,
305
+ errorMessage
306
+ }));
307
+ if (renderError) {
308
+ params.runtime.close();
309
+ return require_lib_errors_index.err(renderError.type, renderError.message);
310
+ }
311
+ const [readError, key] = await params.runtime.readKey();
312
+ if (readError || !key) {
313
+ params.runtime.close();
314
+ return require_lib_errors_index.err(readError?.type ?? "PromptIOError", readError?.message ?? "Unable to read prompt input");
315
+ }
316
+ if (isCancelKey(key)) {
317
+ const [closeError] = params.runtime.close();
318
+ if (closeError) return require_lib_errors_index.err(closeError.type, closeError.message);
319
+ const [doneError] = params.runtime.done(`✖ ${CANCEL_MESSAGE}`);
320
+ if (doneError) return require_lib_errors_index.err(doneError.type, doneError.message);
321
+ if (params.runtime.interrupt) {
322
+ const [interruptError] = params.runtime.interrupt(CANCEL_MESSAGE);
323
+ if (interruptError) return require_lib_errors_index.err(interruptError.type, interruptError.message);
324
+ }
325
+ return require_lib_errors_index.err("PromptCancelledError", CANCEL_MESSAGE);
326
+ }
327
+ if (key.name !== "enter") {
328
+ state = params.onKey(state, key);
329
+ errorMessage = null;
330
+ continue;
331
+ }
332
+ const submitResult = params.onSubmit(state);
333
+ if ("errorMessage" in submitResult) {
334
+ errorMessage = submitResult.errorMessage;
335
+ continue;
336
+ }
337
+ const rawValue = submitResult.value;
338
+ const [validationRunError, validationErrorMessage] = await runValidation(params.options, rawValue);
339
+ if (validationRunError) {
340
+ const closeDoneErr = closeAndDone(`✖ ${params.options.message}`);
341
+ if (closeDoneErr) return closeDoneErr;
342
+ return require_lib_errors_index.err(validationRunError.type, validationRunError.message);
343
+ }
344
+ if (validationErrorMessage) {
345
+ errorMessage = validationErrorMessage;
346
+ continue;
347
+ }
348
+ const [transformError, finalValue] = await resolveOutput(params.options, rawValue);
349
+ if (transformError) {
350
+ const closeDoneErr = closeAndDone(`✖ ${params.options.message}`);
351
+ if (closeDoneErr) return closeDoneErr;
352
+ return require_lib_errors_index.err(transformError.type, transformError.message);
353
+ }
354
+ if (finalValue === null) return require_lib_errors_index.err("PromptIOError", "Unable to transform prompt value");
355
+ const closeDoneErr = closeAndDone(params.complete({
356
+ options: params.options,
357
+ state,
358
+ value: finalValue
359
+ }));
360
+ if (closeDoneErr) return closeDoneErr;
361
+ return require_lib_errors_index.ok(finalValue);
362
+ }
363
+ };
364
+ //#endregion
5
365
  //#region src/lib/prompts/index.ts
6
366
  const pointer = (active) => {
7
367
  return active ? paint("cyan", "❯") : " ";
@@ -154,8 +514,8 @@ const textOnKey = (state, key) => {
154
514
  }
155
515
  };
156
516
  const input = async (options, runtime) => {
157
- return require_session.runPromptSession({
158
- runtime: runtime ?? require_runtime.createNodePromptRuntime(),
517
+ return runPromptSession({
518
+ runtime: runtime ?? createNodePromptRuntime(),
159
519
  options,
160
520
  initialState: createTextState(options.defaultValue ?? ""),
161
521
  render: ({ options: currentOptions, state, errorMessage }) => {
@@ -173,10 +533,10 @@ const input = async (options, runtime) => {
173
533
  });
174
534
  };
175
535
  const password = async (options, runtime) => {
176
- const promptRuntime = runtime ?? require_runtime.createNodePromptRuntime();
536
+ const promptRuntime = runtime ?? createNodePromptRuntime();
177
537
  const initialValue = options.defaultValue ?? "";
178
538
  const mask = options.mask;
179
- return require_session.runPromptSession({
539
+ return runPromptSession({
180
540
  runtime: promptRuntime,
181
541
  options,
182
542
  initialState: createTextState(initialValue),
@@ -197,8 +557,8 @@ const password = async (options, runtime) => {
197
557
  });
198
558
  };
199
559
  const confirm = async (options, runtime) => {
200
- return require_session.runPromptSession({
201
- runtime: runtime ?? require_runtime.createNodePromptRuntime(),
560
+ return runPromptSession({
561
+ runtime: runtime ?? createNodePromptRuntime(),
202
562
  options,
203
563
  initialState: { value: options.defaultValue ?? false },
204
564
  render: ({ options: currentOptions, state, errorMessage }) => {
@@ -231,8 +591,8 @@ const confirm = async (options, runtime) => {
231
591
  });
232
592
  };
233
593
  const number = async (options, runtime) => {
234
- return require_session.runPromptSession({
235
- runtime: runtime ?? require_runtime.createNodePromptRuntime(),
594
+ return runPromptSession({
595
+ runtime: runtime ?? createNodePromptRuntime(),
236
596
  options,
237
597
  initialState: createTextState(options.defaultValue === void 0 ? "" : String(options.defaultValue)),
238
598
  render: ({ options: currentOptions, state, errorMessage }) => {
@@ -290,8 +650,8 @@ const findDefaultIndex = (choices, defaultValue) => {
290
650
  return findFirstEnabledIndex(choices);
291
651
  };
292
652
  const select = async (options, runtime) => {
293
- return require_session.runPromptSession({
294
- runtime: runtime ?? require_runtime.createNodePromptRuntime(),
653
+ return runPromptSession({
654
+ runtime: runtime ?? createNodePromptRuntime(),
295
655
  options,
296
656
  initialState: { cursor: findDefaultIndex(options.choices, options.defaultValue) },
297
657
  render: ({ options: currentOptions, state, errorMessage }) => {
@@ -327,8 +687,8 @@ const select = async (options, runtime) => {
327
687
  });
328
688
  };
329
689
  const multiselect = async (options, runtime) => {
330
- return require_session.runPromptSession({
331
- runtime: runtime ?? require_runtime.createNodePromptRuntime(),
690
+ return runPromptSession({
691
+ runtime: runtime ?? createNodePromptRuntime(),
332
692
  options,
333
693
  initialState: {
334
694
  cursor: findFirstEnabledIndex(options.choices),