toolcraft-openapi 0.0.168 → 0.0.170
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/dist/composition.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { graphemes } from "../dashboard/terminal-width.js";
|
|
1
2
|
const MATCH_SCORE = 10;
|
|
2
3
|
const CONSECUTIVE_BONUS = 14;
|
|
3
4
|
const WORD_START_BONUS = 10;
|
|
@@ -13,7 +14,11 @@ export function filterRows(query, rows, opts = {}) {
|
|
|
13
14
|
const preparedText = opts.caseSensitive === true ? text : text.toLocaleLowerCase();
|
|
14
15
|
const match = matchSubsequence(preparedQuery, preparedText);
|
|
15
16
|
if (match !== undefined) {
|
|
16
|
-
matches.push({
|
|
17
|
+
matches.push({
|
|
18
|
+
index,
|
|
19
|
+
...match,
|
|
20
|
+
positions: text === preparedText ? match.positions : projectPositions(text, match.positions)
|
|
21
|
+
});
|
|
17
22
|
}
|
|
18
23
|
});
|
|
19
24
|
return matches.sort((left, right) => right.score - left.score || left.index - right.index);
|
|
@@ -27,6 +32,33 @@ function searchableText(row) {
|
|
|
27
32
|
function stripAnsi(value) {
|
|
28
33
|
return value.replace(/\u001b\[[0-9;]*m/g, "");
|
|
29
34
|
}
|
|
35
|
+
function projectPositions(text, positions) {
|
|
36
|
+
const projected = [];
|
|
37
|
+
let originalOffset = 0;
|
|
38
|
+
let foldedOffset = 0;
|
|
39
|
+
let matchIndex = 0;
|
|
40
|
+
for (const segment of graphemes(text)) {
|
|
41
|
+
const foldedLength = segment.toLocaleLowerCase().length;
|
|
42
|
+
const firstMatch = matchIndex;
|
|
43
|
+
while (matchIndex < positions.length && positions[matchIndex] < foldedOffset + foldedLength) {
|
|
44
|
+
if (segment.length === foldedLength) {
|
|
45
|
+
projected.push(originalOffset + positions[matchIndex] - foldedOffset);
|
|
46
|
+
}
|
|
47
|
+
matchIndex += 1;
|
|
48
|
+
}
|
|
49
|
+
if (matchIndex > firstMatch && segment.length !== foldedLength) {
|
|
50
|
+
for (let offset = 0; offset < segment.length; offset += 1) {
|
|
51
|
+
projected.push(originalOffset + offset);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (matchIndex === positions.length) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
originalOffset += segment.length;
|
|
58
|
+
foldedOffset += foldedLength;
|
|
59
|
+
}
|
|
60
|
+
return projected;
|
|
61
|
+
}
|
|
30
62
|
function matchSubsequence(query, text) {
|
|
31
63
|
const queryCharacters = Array.from(query);
|
|
32
64
|
const textCharacters = Array.from(text);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import * as readline from "node:readline";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
5
|
import { graphemes } from "../../dashboard/terminal-width.js";
|
|
4
6
|
import { CANCEL } from "./cancel-symbol.js";
|
|
5
7
|
import { mapKey } from "./keys.js";
|
|
6
8
|
import { wrapFrame } from "./wrap.js";
|
|
9
|
+
const pendingCarriageReturns = new WeakMap();
|
|
7
10
|
const cursor = {
|
|
8
11
|
hide: "\x1b[?25l",
|
|
9
12
|
show: "\x1b[?25h",
|
|
@@ -128,6 +131,88 @@ export class Prompt extends EventEmitter {
|
|
|
128
131
|
this.state = "cancel";
|
|
129
132
|
return Promise.resolve(CANCEL);
|
|
130
133
|
}
|
|
134
|
+
const input = this.input;
|
|
135
|
+
if (input instanceof Readable) {
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
const decoder = new StringDecoder("utf8");
|
|
138
|
+
let line = "";
|
|
139
|
+
let settled = false;
|
|
140
|
+
const settle = (value, remainder) => {
|
|
141
|
+
if (settled)
|
|
142
|
+
return;
|
|
143
|
+
settled = true;
|
|
144
|
+
input.removeListener("data", onData);
|
|
145
|
+
input.removeListener("end", onEnd);
|
|
146
|
+
input.removeListener("close", onCancel);
|
|
147
|
+
input.removeListener("error", settle);
|
|
148
|
+
this.signal?.removeEventListener("abort", onCancel);
|
|
149
|
+
input.pause();
|
|
150
|
+
if (remainder?.length)
|
|
151
|
+
input.unshift(remainder, input.readableEncoding ?? undefined);
|
|
152
|
+
if (value instanceof Error)
|
|
153
|
+
reject(value);
|
|
154
|
+
else
|
|
155
|
+
resolve(value);
|
|
156
|
+
};
|
|
157
|
+
const onCancel = () => {
|
|
158
|
+
this.state = "cancel";
|
|
159
|
+
settle(CANCEL);
|
|
160
|
+
};
|
|
161
|
+
const onEnd = () => settle(line + decoder.end());
|
|
162
|
+
const onData = (chunk) => {
|
|
163
|
+
if (chunk.length === 0)
|
|
164
|
+
return;
|
|
165
|
+
if (settled) {
|
|
166
|
+
if (!input.destroyed)
|
|
167
|
+
input.unshift(chunk, input.readableEncoding ?? undefined);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
let offset = 0;
|
|
171
|
+
const previousCarriageReturn = pendingCarriageReturns.get(input);
|
|
172
|
+
if (previousCarriageReturn !== undefined) {
|
|
173
|
+
pendingCarriageReturns.delete(input);
|
|
174
|
+
const isLineFeed = typeof chunk === "string" ? chunk[0] === "\n" : chunk[0] === 10;
|
|
175
|
+
if (isLineFeed && Date.now() - previousCarriageReturn <= 100)
|
|
176
|
+
offset = 1;
|
|
177
|
+
}
|
|
178
|
+
for (; offset < chunk.length; offset += 1) {
|
|
179
|
+
const character = typeof chunk === "string" ? chunk[offset] : decoder.write(chunk.subarray(offset, offset + 1));
|
|
180
|
+
if (character.endsWith("\r") || character.endsWith("\n")) {
|
|
181
|
+
line += character.slice(0, -1);
|
|
182
|
+
offset += 1;
|
|
183
|
+
if (character.endsWith("\r")) {
|
|
184
|
+
if (offset === chunk.length) {
|
|
185
|
+
pendingCarriageReturns.set(input, Date.now());
|
|
186
|
+
}
|
|
187
|
+
else if (typeof chunk === "string" ? chunk[offset] === "\n" : chunk[offset] === 10) {
|
|
188
|
+
offset += 1;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
settle(line, chunk.slice(offset));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
line += character;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
input.once("end", onEnd);
|
|
198
|
+
input.once("close", onCancel);
|
|
199
|
+
input.once("error", settle);
|
|
200
|
+
this.signal?.addEventListener("abort", onCancel, { once: true });
|
|
201
|
+
if (this.signal?.aborted)
|
|
202
|
+
onCancel();
|
|
203
|
+
else if (input.readableEnded)
|
|
204
|
+
onEnd();
|
|
205
|
+
else if (input.destroyed)
|
|
206
|
+
onCancel();
|
|
207
|
+
else if (!settled) {
|
|
208
|
+
input.on("data", onData);
|
|
209
|
+
if (!settled)
|
|
210
|
+
input.resume();
|
|
211
|
+
if (settled)
|
|
212
|
+
input.pause();
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
131
216
|
return new Promise((resolve, reject) => {
|
|
132
217
|
let rl = null;
|
|
133
218
|
let settled = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft-openapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.170",
|
|
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.
|
|
33
|
+
"toolcraft": "0.0.170",
|
|
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.
|
|
48
|
+
"toolcraft-schema": "0.0.170",
|
|
49
49
|
"toolcraft-design": "*",
|
|
50
50
|
"@poe-code/frontmatter": "*"
|
|
51
51
|
},
|