@c4a/extract-proto 0.7.5 → 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 +53 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12018,6 +12018,55 @@ 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/protoFields.ts
|
|
12022
|
+
function protoFields(tokens, kind, oneof) {
|
|
12023
|
+
const fields = [];
|
|
12024
|
+
let start = 0;
|
|
12025
|
+
for (let index = 0;index < tokens.length; index++) {
|
|
12026
|
+
if (tokens[index].value === "{") {
|
|
12027
|
+
let end = index + 1;
|
|
12028
|
+
let depth = 1;
|
|
12029
|
+
for (;end < tokens.length && depth > 0; end++) {
|
|
12030
|
+
if (tokens[end].value === "{")
|
|
12031
|
+
depth++;
|
|
12032
|
+
if (tokens[end].value === "}")
|
|
12033
|
+
depth--;
|
|
12034
|
+
}
|
|
12035
|
+
if (tokens[start]?.value === "oneof")
|
|
12036
|
+
fields.push(...protoFields(tokens.slice(index + 1, end - 1), "message", tokens[start + 1]?.value));
|
|
12037
|
+
index = end - 1;
|
|
12038
|
+
start = end;
|
|
12039
|
+
continue;
|
|
12040
|
+
}
|
|
12041
|
+
if (tokens[index].value !== ";")
|
|
12042
|
+
continue;
|
|
12043
|
+
const statement = tokens.slice(start, index);
|
|
12044
|
+
start = index + 1;
|
|
12045
|
+
if (["option", "reserved", "extensions"].includes(statement[0]?.value ?? ""))
|
|
12046
|
+
continue;
|
|
12047
|
+
const equals = statement.findIndex((token) => token.value === "=");
|
|
12048
|
+
const name = statement[equals - 1];
|
|
12049
|
+
const number = statement[equals + 1];
|
|
12050
|
+
if (name?.kind !== "identifier" || number === undefined)
|
|
12051
|
+
continue;
|
|
12052
|
+
const label = statement[0]?.value;
|
|
12053
|
+
const offset = ["optional", "required", "repeated"].includes(label ?? "") ? 1 : 0;
|
|
12054
|
+
const defaultIndex = statement.findIndex((token, at) => token.value === "default" && statement[at + 1]?.value === "=");
|
|
12055
|
+
const defaultToken = statement[defaultIndex + 2];
|
|
12056
|
+
fields.push({
|
|
12057
|
+
name: name.value,
|
|
12058
|
+
number: number.value,
|
|
12059
|
+
type: kind === "enum" ? "enum value" : statement.slice(offset, equals - 1).map((token) => token.value).join(""),
|
|
12060
|
+
...label === "optional" ? { optional: true } : label === "required" ? { optional: false } : {},
|
|
12061
|
+
repeated: label === "repeated",
|
|
12062
|
+
...oneof === undefined ? {} : { oneof },
|
|
12063
|
+
...defaultIndex < 0 || defaultToken === undefined ? {} : { defaultValue: defaultToken.kind === "string" ? JSON.stringify(defaultToken.value) : defaultToken.value },
|
|
12064
|
+
location: { line: name.line, column: name.column }
|
|
12065
|
+
});
|
|
12066
|
+
}
|
|
12067
|
+
return fields;
|
|
12068
|
+
}
|
|
12069
|
+
|
|
12021
12070
|
// src/protoParser.ts
|
|
12022
12071
|
import { posix } from "node:path";
|
|
12023
12072
|
|
|
@@ -12276,8 +12325,10 @@ class ProtoDocumentParser {
|
|
|
12276
12325
|
const kind = this.take().value;
|
|
12277
12326
|
const name = this.identifier(`${kind} name`);
|
|
12278
12327
|
const qualifiedName = prefix ? `${prefix}.${name.value}` : name.value;
|
|
12279
|
-
|
|
12328
|
+
const declaration = { kind, name: name.value, qualified_name: qualifiedName, locator: { path: this.path, line: name.line, column: name.column } };
|
|
12329
|
+
this.document.types.push(declaration);
|
|
12280
12330
|
this.take("{");
|
|
12331
|
+
const fieldStart = this.index;
|
|
12281
12332
|
while (this.token() && this.token().value !== "}") {
|
|
12282
12333
|
if (this.token().value === ";") {
|
|
12283
12334
|
this.index += 1;
|
|
@@ -12293,6 +12344,7 @@ class ProtoDocumentParser {
|
|
|
12293
12344
|
}
|
|
12294
12345
|
this.skipDeclaration();
|
|
12295
12346
|
}
|
|
12347
|
+
declaration.fields = protoFields(this.tokens.slice(fieldStart, this.index), kind);
|
|
12296
12348
|
this.take("}");
|
|
12297
12349
|
}
|
|
12298
12350
|
parseService() {
|