toolcraft-openapi 0.0.164 → 0.0.166

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.
@@ -33,12 +33,12 @@
33
33
  },
34
34
  {
35
35
  "name": "toolcraft-openapi",
36
- "version": "0.0.164",
36
+ "version": "0.0.166",
37
37
  "license": "MIT"
38
38
  },
39
39
  {
40
40
  "name": "toolcraft-schema",
41
- "version": "0.0.164",
41
+ "version": "0.0.166",
42
42
  "license": "MIT"
43
43
  },
44
44
  {
@@ -48,7 +48,7 @@ export declare class Prompt<Value> extends EventEmitter {
48
48
  get cursor(): number;
49
49
  prompt(): Promise<Value | typeof CANCEL>;
50
50
  protected promptNonTty(): Promise<Value | typeof CANCEL>;
51
- protected readNonTtyLine(): Promise<string>;
51
+ protected readNonTtyLine(): Promise<string | typeof CANCEL>;
52
52
  protected setValue(value: Value | undefined): void;
53
53
  protected setError(message: string): void;
54
54
  protected setUserInput(value: string): void;
@@ -109,19 +109,48 @@ export class Prompt extends EventEmitter {
109
109
  return Promise.reject(new Error(nonTtyPromptMessage()));
110
110
  }
111
111
  readNonTtyLine() {
112
+ if (this.input.readableEnded) {
113
+ return Promise.resolve("");
114
+ }
115
+ if (this.input.destroyed) {
116
+ this.state = "cancel";
117
+ return Promise.resolve(CANCEL);
118
+ }
112
119
  return new Promise((resolve) => {
113
- const rl = readline.createInterface({ input: this.input, terminal: false });
120
+ let rl = null;
114
121
  let settled = false;
115
122
  const settle = (value) => {
116
123
  if (settled) {
117
124
  return;
118
125
  }
119
126
  settled = true;
120
- rl.close();
127
+ this.input.removeListener("close", onCancel);
128
+ this.signal?.removeEventListener("abort", onCancel);
129
+ rl?.close();
121
130
  resolve(value);
122
131
  };
132
+ const onCancel = () => {
133
+ this.state = "cancel";
134
+ settle(CANCEL);
135
+ };
136
+ this.input.once("close", onCancel);
137
+ rl = readline.createInterface({ input: this.input, terminal: false });
138
+ if (settled) {
139
+ rl.close();
140
+ return;
141
+ }
123
142
  rl.once("line", settle);
124
- rl.once("close", () => settle(rl.line));
143
+ rl.once("close", () => settle(rl?.line ?? ""));
144
+ this.signal?.addEventListener("abort", onCancel, { once: true });
145
+ if (this.signal?.aborted) {
146
+ onCancel();
147
+ }
148
+ else if (this.input.readableEnded) {
149
+ settle(rl.line);
150
+ }
151
+ else if (this.input.destroyed) {
152
+ onCancel();
153
+ }
125
154
  });
126
155
  }
127
156
  setValue(value) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.164",
3
+ "version": "0.0.166",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-openapi",
3
- "version": "0.0.164",
3
+ "version": "0.0.166",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "toolcraft-openapi-generate": "dist/bin/generate.js"
31
31
  },
32
32
  "dependencies": {
33
- "toolcraft": "0.0.164",
33
+ "toolcraft": "0.0.166",
34
34
  "fast-string-width": "^3.0.2",
35
35
  "fast-wrap-ansi": "^0.2.0",
36
36
  "sisteransi": "^1.0.5",
@@ -45,7 +45,7 @@
45
45
  "directory": "packages/toolcraft-openapi"
46
46
  },
47
47
  "optionalDependencies": {
48
- "toolcraft-schema": "0.0.164",
48
+ "toolcraft-schema": "0.0.166",
49
49
  "toolcraft-design": "*",
50
50
  "@poe-code/frontmatter": "*"
51
51
  },