@c4a/extract-thrift 0.7.4 → 0.7.8
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/index.js +63 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12018,6 +12018,59 @@ var INDEXABLE_EXTENSIONS = new Set([
|
|
|
12018
12018
|
var UPLOAD_ALLOWED_EXTENSIONS = collectExtensions(() => true);
|
|
12019
12019
|
var TEXT_EXTENSIONS = collectExtensions((definition) => definition.cas.encoding === "utf8");
|
|
12020
12020
|
var UPLOAD_MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
12021
|
+
// src/thriftFields.ts
|
|
12022
|
+
function thriftFields(tokens) {
|
|
12023
|
+
const fields = [];
|
|
12024
|
+
for (let index = 0;index < tokens.length; index++) {
|
|
12025
|
+
if (tokens[index]?.kind !== "number" || tokens[index + 1]?.value !== ":")
|
|
12026
|
+
continue;
|
|
12027
|
+
const number = tokens[index].value;
|
|
12028
|
+
let cursor = index + 2;
|
|
12029
|
+
const label = tokens[cursor]?.value;
|
|
12030
|
+
if (label === "optional" || label === "required")
|
|
12031
|
+
cursor++;
|
|
12032
|
+
const typeStart = cursor++;
|
|
12033
|
+
if (tokens[cursor]?.value === "<") {
|
|
12034
|
+
let depth = 0;
|
|
12035
|
+
do {
|
|
12036
|
+
if (tokens[cursor]?.value === "<")
|
|
12037
|
+
depth++;
|
|
12038
|
+
if (tokens[cursor]?.value === ">")
|
|
12039
|
+
depth--;
|
|
12040
|
+
cursor++;
|
|
12041
|
+
} while (cursor < tokens.length && depth > 0);
|
|
12042
|
+
}
|
|
12043
|
+
const name = tokens[cursor];
|
|
12044
|
+
if (name?.kind !== "identifier")
|
|
12045
|
+
continue;
|
|
12046
|
+
const type = tokens.slice(typeStart, cursor).map((token) => token.value).join("");
|
|
12047
|
+
cursor++;
|
|
12048
|
+
let defaultValue;
|
|
12049
|
+
if (tokens[cursor]?.value === "=") {
|
|
12050
|
+
const start = ++cursor;
|
|
12051
|
+
let depth = 0;
|
|
12052
|
+
do {
|
|
12053
|
+
if (["[", "{"].includes(tokens[cursor]?.value ?? ""))
|
|
12054
|
+
depth++;
|
|
12055
|
+
if (["]", "}"].includes(tokens[cursor]?.value ?? ""))
|
|
12056
|
+
depth--;
|
|
12057
|
+
cursor++;
|
|
12058
|
+
} while (cursor < tokens.length && depth > 0);
|
|
12059
|
+
defaultValue = tokens.slice(start, cursor).map((token) => token.kind === "string" ? JSON.stringify(token.value) : token.value).join("");
|
|
12060
|
+
}
|
|
12061
|
+
fields.push({
|
|
12062
|
+
name: name.value,
|
|
12063
|
+
type,
|
|
12064
|
+
number,
|
|
12065
|
+
...label === "optional" ? { optional: true } : label === "required" ? { optional: false } : {},
|
|
12066
|
+
...defaultValue === undefined ? {} : { defaultValue },
|
|
12067
|
+
location: { line: name.line, column: name.column }
|
|
12068
|
+
});
|
|
12069
|
+
index = cursor - 1;
|
|
12070
|
+
}
|
|
12071
|
+
return fields;
|
|
12072
|
+
}
|
|
12073
|
+
|
|
12021
12074
|
// src/thriftParser.ts
|
|
12022
12075
|
import { posix } from "node:path";
|
|
12023
12076
|
|
|
@@ -12206,11 +12259,14 @@ function parseMethods(path2, serviceName, tokens) {
|
|
|
12206
12259
|
name: nameToken.value,
|
|
12207
12260
|
return_type: tokenText(returnTokens),
|
|
12208
12261
|
oneway,
|
|
12262
|
+
fields: thriftFields(tokens.slice(open + 1, matching(tokens, open, "(", ")"))),
|
|
12209
12263
|
locator: { path: path2, line: nameToken.line, column: nameToken.column }
|
|
12210
12264
|
});
|
|
12211
12265
|
index = matching(tokens, open, "(", ")") + 1;
|
|
12212
12266
|
if (tokens[index]?.value === "throws" && tokens[index + 1]?.value === "(") {
|
|
12213
|
-
|
|
12267
|
+
const end = matching(tokens, index + 1, "(", ")");
|
|
12268
|
+
methods.at(-1).throws = thriftFields(tokens.slice(index + 2, end));
|
|
12269
|
+
index = end + 1;
|
|
12214
12270
|
}
|
|
12215
12271
|
if (tokens[index]?.value === "(") {
|
|
12216
12272
|
const parsed = parseAnnotationGroup(`service:${serviceName}:method:${nameToken.value}`, path2, tokens, index);
|
|
@@ -12281,7 +12337,12 @@ function parseThriftSources(files) {
|
|
|
12281
12337
|
const open = tokens.findIndex((candidate, candidateIndex) => candidateIndex > index && candidate.value === "{");
|
|
12282
12338
|
if (open < 0)
|
|
12283
12339
|
throw new ThriftSyntaxError(`${token.value} body is missing`, token.line, token.column);
|
|
12284
|
-
document.types.push({
|
|
12340
|
+
document.types.push({
|
|
12341
|
+
kind: token.value,
|
|
12342
|
+
name: name.value,
|
|
12343
|
+
fields: thriftFields(tokens.slice(open + 1, matching(tokens, open, "{", "}"))),
|
|
12344
|
+
locator: { path: path2, line: name.line, column: name.column }
|
|
12345
|
+
});
|
|
12285
12346
|
index = matching(tokens, open, "{", "}") + 1;
|
|
12286
12347
|
if (tokens[index]?.value === "(") {
|
|
12287
12348
|
const parsed = parseAnnotationGroup(`type:${name.value}`, path2, tokens, index);
|