@wireio/protoc-gen-solana 1.0.8 → 1.0.9
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/bin/protoc-gen-solana +0 -0
- package/dist/bundle/protoc-gen-solana.cjs +168 -22
- package/dist/bundle/protoc-gen-solana.cjs.map +4 -4
- package/lib/generator/field.js +5 -5
- package/lib/generator/message.d.ts +1 -1
- package/lib/generator/message.d.ts.map +1 -1
- package/lib/generator/message.js +88 -2
- package/lib/plugin.js +2 -2
- package/lib/util/names.d.ts +13 -0
- package/lib/util/names.d.ts.map +1 -1
- package/lib/util/names.js +36 -1
- package/package.json +1 -1
|
Binary file
|
|
@@ -1822,9 +1822,9 @@ var require_buffer_from = __commonJS({
|
|
|
1822
1822
|
}
|
|
1823
1823
|
});
|
|
1824
1824
|
|
|
1825
|
-
// ../../node_modules/.pnpm/source-map-support@0.5.
|
|
1825
|
+
// ../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js
|
|
1826
1826
|
var require_source_map_support = __commonJS({
|
|
1827
|
-
"../../node_modules/.pnpm/source-map-support@0.5.
|
|
1827
|
+
"../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js"(exports2, module2) {
|
|
1828
1828
|
var SourceMapConsumer = require_source_map().SourceMapConsumer;
|
|
1829
1829
|
var path2 = require("path");
|
|
1830
1830
|
var fs;
|
|
@@ -1836,6 +1836,9 @@ var require_source_map_support = __commonJS({
|
|
|
1836
1836
|
} catch (err) {
|
|
1837
1837
|
}
|
|
1838
1838
|
var bufferFrom = require_buffer_from();
|
|
1839
|
+
function dynamicRequire(mod2, request) {
|
|
1840
|
+
return mod2.require(request);
|
|
1841
|
+
}
|
|
1839
1842
|
var errorFormatterInstalled = false;
|
|
1840
1843
|
var uncaughtShimInstalled = false;
|
|
1841
1844
|
var emptyCacheBetweenOperations = false;
|
|
@@ -1855,6 +1858,23 @@ var require_source_map_support = __commonJS({
|
|
|
1855
1858
|
function hasGlobalProcessEventEmitter() {
|
|
1856
1859
|
return typeof process === "object" && process !== null && typeof process.on === "function";
|
|
1857
1860
|
}
|
|
1861
|
+
function globalProcessVersion() {
|
|
1862
|
+
if (typeof process === "object" && process !== null) {
|
|
1863
|
+
return process.version;
|
|
1864
|
+
} else {
|
|
1865
|
+
return "";
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
function globalProcessStderr() {
|
|
1869
|
+
if (typeof process === "object" && process !== null) {
|
|
1870
|
+
return process.stderr;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
function globalProcessExit(code) {
|
|
1874
|
+
if (typeof process === "object" && process !== null && typeof process.exit === "function") {
|
|
1875
|
+
return process.exit(code);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1858
1878
|
function handlerExec(list) {
|
|
1859
1879
|
return function(arg) {
|
|
1860
1880
|
for (var i = 0; i < list.length; i++) {
|
|
@@ -2079,15 +2099,20 @@ var require_source_map_support = __commonJS({
|
|
|
2079
2099
|
object.toString = CallSiteToString;
|
|
2080
2100
|
return object;
|
|
2081
2101
|
}
|
|
2082
|
-
function wrapCallSite(frame) {
|
|
2102
|
+
function wrapCallSite(frame, state) {
|
|
2103
|
+
if (state === void 0) {
|
|
2104
|
+
state = { nextPosition: null, curPosition: null };
|
|
2105
|
+
}
|
|
2083
2106
|
if (frame.isNative()) {
|
|
2107
|
+
state.curPosition = null;
|
|
2084
2108
|
return frame;
|
|
2085
2109
|
}
|
|
2086
2110
|
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
2087
2111
|
if (source) {
|
|
2088
2112
|
var line = frame.getLineNumber();
|
|
2089
2113
|
var column = frame.getColumnNumber() - 1;
|
|
2090
|
-
var
|
|
2114
|
+
var noHeader = /^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/;
|
|
2115
|
+
var headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
|
|
2091
2116
|
if (line === 1 && column > headerLength && !isInBrowser() && !frame.isEval()) {
|
|
2092
2117
|
column -= headerLength;
|
|
2093
2118
|
}
|
|
@@ -2096,10 +2121,14 @@ var require_source_map_support = __commonJS({
|
|
|
2096
2121
|
line,
|
|
2097
2122
|
column
|
|
2098
2123
|
});
|
|
2124
|
+
state.curPosition = position;
|
|
2099
2125
|
frame = cloneCallSite(frame);
|
|
2100
2126
|
var originalFunctionName = frame.getFunctionName;
|
|
2101
2127
|
frame.getFunctionName = function() {
|
|
2102
|
-
|
|
2128
|
+
if (state.nextPosition == null) {
|
|
2129
|
+
return originalFunctionName();
|
|
2130
|
+
}
|
|
2131
|
+
return state.nextPosition.name || originalFunctionName();
|
|
2103
2132
|
};
|
|
2104
2133
|
frame.getFileName = function() {
|
|
2105
2134
|
return position.source;
|
|
@@ -2134,9 +2163,14 @@ var require_source_map_support = __commonJS({
|
|
|
2134
2163
|
var name = error.name || "Error";
|
|
2135
2164
|
var message = error.message || "";
|
|
2136
2165
|
var errorString = name + ": " + message;
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2166
|
+
var state = { nextPosition: null, curPosition: null };
|
|
2167
|
+
var processedStack = [];
|
|
2168
|
+
for (var i = stack.length - 1; i >= 0; i--) {
|
|
2169
|
+
processedStack.push("\n at " + wrapCallSite(stack[i], state));
|
|
2170
|
+
state.nextPosition = state.curPosition;
|
|
2171
|
+
}
|
|
2172
|
+
state.curPosition = state.nextPosition = null;
|
|
2173
|
+
return errorString + processedStack.reverse().join("");
|
|
2140
2174
|
}
|
|
2141
2175
|
function getErrorSource(error) {
|
|
2142
2176
|
var match = /\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
|
|
@@ -2163,15 +2197,16 @@ var require_source_map_support = __commonJS({
|
|
|
2163
2197
|
}
|
|
2164
2198
|
function printErrorAndExit(error) {
|
|
2165
2199
|
var source = getErrorSource(error);
|
|
2166
|
-
|
|
2167
|
-
|
|
2200
|
+
var stderr = globalProcessStderr();
|
|
2201
|
+
if (stderr && stderr._handle && stderr._handle.setBlocking) {
|
|
2202
|
+
stderr._handle.setBlocking(true);
|
|
2168
2203
|
}
|
|
2169
2204
|
if (source) {
|
|
2170
2205
|
console.error();
|
|
2171
2206
|
console.error(source);
|
|
2172
2207
|
}
|
|
2173
2208
|
console.error(error.stack);
|
|
2174
|
-
|
|
2209
|
+
globalProcessExit(1);
|
|
2175
2210
|
}
|
|
2176
2211
|
function shimEmitUncaughtException() {
|
|
2177
2212
|
var origEmit = process.emit;
|
|
@@ -2213,11 +2248,7 @@ var require_source_map_support = __commonJS({
|
|
|
2213
2248
|
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
|
2214
2249
|
}
|
|
2215
2250
|
if (options.hookRequire && !isInBrowser()) {
|
|
2216
|
-
var Module;
|
|
2217
|
-
try {
|
|
2218
|
-
Module = require("module");
|
|
2219
|
-
} catch (err) {
|
|
2220
|
-
}
|
|
2251
|
+
var Module = dynamicRequire(module2, "module");
|
|
2221
2252
|
var $compile = Module.prototype._compile;
|
|
2222
2253
|
if (!$compile.__sourceMapSupport) {
|
|
2223
2254
|
Module.prototype._compile = function(content, filename) {
|
|
@@ -2237,6 +2268,13 @@ var require_source_map_support = __commonJS({
|
|
|
2237
2268
|
}
|
|
2238
2269
|
if (!uncaughtShimInstalled) {
|
|
2239
2270
|
var installHandler = "handleUncaughtExceptions" in options ? options.handleUncaughtExceptions : true;
|
|
2271
|
+
try {
|
|
2272
|
+
var worker_threads = dynamicRequire(module2, "worker_threads");
|
|
2273
|
+
if (worker_threads.isMainThread === false) {
|
|
2274
|
+
installHandler = false;
|
|
2275
|
+
}
|
|
2276
|
+
} catch (e) {
|
|
2277
|
+
}
|
|
2240
2278
|
if (installHandler && hasGlobalProcessEventEmitter()) {
|
|
2241
2279
|
uncaughtShimInstalled = true;
|
|
2242
2280
|
shimEmitUncaughtException();
|
|
@@ -220855,6 +220893,67 @@ function protoNameToRust(fqn) {
|
|
|
220855
220893
|
function toSnakeCase(name) {
|
|
220856
220894
|
return name.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
220857
220895
|
}
|
|
220896
|
+
var RUST_RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
220897
|
+
// Strict keywords
|
|
220898
|
+
"as",
|
|
220899
|
+
"async",
|
|
220900
|
+
"await",
|
|
220901
|
+
"break",
|
|
220902
|
+
"const",
|
|
220903
|
+
"continue",
|
|
220904
|
+
"crate",
|
|
220905
|
+
"dyn",
|
|
220906
|
+
"else",
|
|
220907
|
+
"enum",
|
|
220908
|
+
"extern",
|
|
220909
|
+
"false",
|
|
220910
|
+
"fn",
|
|
220911
|
+
"for",
|
|
220912
|
+
"if",
|
|
220913
|
+
"impl",
|
|
220914
|
+
"in",
|
|
220915
|
+
"let",
|
|
220916
|
+
"loop",
|
|
220917
|
+
"match",
|
|
220918
|
+
"mod",
|
|
220919
|
+
"move",
|
|
220920
|
+
"mut",
|
|
220921
|
+
"pub",
|
|
220922
|
+
"ref",
|
|
220923
|
+
"return",
|
|
220924
|
+
"self",
|
|
220925
|
+
"Self",
|
|
220926
|
+
"static",
|
|
220927
|
+
"struct",
|
|
220928
|
+
"super",
|
|
220929
|
+
"trait",
|
|
220930
|
+
"true",
|
|
220931
|
+
"type",
|
|
220932
|
+
"unsafe",
|
|
220933
|
+
"use",
|
|
220934
|
+
"where",
|
|
220935
|
+
"while",
|
|
220936
|
+
// Reserved for future use
|
|
220937
|
+
"abstract",
|
|
220938
|
+
"become",
|
|
220939
|
+
"box",
|
|
220940
|
+
"do",
|
|
220941
|
+
"final",
|
|
220942
|
+
"macro",
|
|
220943
|
+
"override",
|
|
220944
|
+
"priv",
|
|
220945
|
+
"try",
|
|
220946
|
+
"typeof",
|
|
220947
|
+
"unsized",
|
|
220948
|
+
"virtual",
|
|
220949
|
+
"yield"
|
|
220950
|
+
]);
|
|
220951
|
+
function sanitizeRustFieldName(name) {
|
|
220952
|
+
return RUST_RESERVED_WORDS.has(name) ? `${name}_` : name;
|
|
220953
|
+
}
|
|
220954
|
+
function toRustFieldName(protoFieldName) {
|
|
220955
|
+
return sanitizeRustFieldName(toSnakeCase(protoFieldName));
|
|
220956
|
+
}
|
|
220858
220957
|
function protoFileToRsFile(protoFile, packageName) {
|
|
220859
220958
|
const base = protoFile.replace(/\.proto$/, "");
|
|
220860
220959
|
const parts = base.split("/");
|
|
@@ -221064,7 +221163,7 @@ function isMessage(field) {
|
|
|
221064
221163
|
return field.type === 11;
|
|
221065
221164
|
}
|
|
221066
221165
|
function genStructMember(field) {
|
|
221067
|
-
const rustName =
|
|
221166
|
+
const rustName = toRustFieldName(field.name);
|
|
221068
221167
|
let rustType = resolveRustType(field.type, field.typeName);
|
|
221069
221168
|
if (field.mapEntry) {
|
|
221070
221169
|
const keyType = resolveRustType(field.mapEntry.keyType, void 0);
|
|
@@ -221083,7 +221182,7 @@ function genStructMember(field) {
|
|
|
221083
221182
|
return ` pub ${rustName}: ${rustType},`;
|
|
221084
221183
|
}
|
|
221085
221184
|
function genFieldEncode(field) {
|
|
221086
|
-
const rustName =
|
|
221185
|
+
const rustName = toRustFieldName(field.name);
|
|
221087
221186
|
const typeInfo = PROTO_TYPE_MAP[field.type];
|
|
221088
221187
|
if (!typeInfo) {
|
|
221089
221188
|
log.warn(`Skipping unsupported field type ${field.type} for ${field.name}`);
|
|
@@ -221106,7 +221205,7 @@ function genFieldEncode(field) {
|
|
|
221106
221205
|
return genScalarEncode(field, rustName, typeInfo, tagHex);
|
|
221107
221206
|
}
|
|
221108
221207
|
function genFieldDecode(field) {
|
|
221109
|
-
const rustName =
|
|
221208
|
+
const rustName = toRustFieldName(field.name);
|
|
221110
221209
|
const typeInfo = PROTO_TYPE_MAP[field.type];
|
|
221111
221210
|
if (!typeInfo) {
|
|
221112
221211
|
return ` // TODO: unsupported field type ${field.type} for ${field.name}`;
|
|
@@ -221183,7 +221282,7 @@ function genRepeatedEncode(field, rustName, typeInfo, tagHex) {
|
|
|
221183
221282
|
return lines.join("\n");
|
|
221184
221283
|
}
|
|
221185
221284
|
function genMapEncode(field, tagHex) {
|
|
221186
|
-
const rustName =
|
|
221285
|
+
const rustName = toRustFieldName(field.name);
|
|
221187
221286
|
const me = field.mapEntry;
|
|
221188
221287
|
const keyInfo = PROTO_TYPE_MAP[me.keyType];
|
|
221189
221288
|
const valInfo = PROTO_TYPE_MAP[me.valueType];
|
|
@@ -221363,7 +221462,50 @@ function genMapDecode(field, rustName, tag) {
|
|
|
221363
221462
|
}
|
|
221364
221463
|
|
|
221365
221464
|
// src/generator/message.ts
|
|
221366
|
-
function
|
|
221465
|
+
function collectExternalTypes(messages, currentProtoPackage) {
|
|
221466
|
+
const localNames = new Set(messages.map((m) => m.fullName));
|
|
221467
|
+
for (const m of messages) {
|
|
221468
|
+
for (const nm of m.nestedMessages) {
|
|
221469
|
+
localNames.add(nm.fullName);
|
|
221470
|
+
}
|
|
221471
|
+
}
|
|
221472
|
+
const external = /* @__PURE__ */ new Set();
|
|
221473
|
+
for (const msg of messages) {
|
|
221474
|
+
for (const field of msg.fields) {
|
|
221475
|
+
if (field.type === 11 && field.typeName) {
|
|
221476
|
+
const fqn = field.typeName.startsWith(".") ? field.typeName : `.${field.typeName}`;
|
|
221477
|
+
if (!localNames.has(fqn)) {
|
|
221478
|
+
external.add(fqn);
|
|
221479
|
+
}
|
|
221480
|
+
}
|
|
221481
|
+
}
|
|
221482
|
+
}
|
|
221483
|
+
return external;
|
|
221484
|
+
}
|
|
221485
|
+
function genExternalImports(messages, currentProtoPackage) {
|
|
221486
|
+
const external = collectExternalTypes(messages, currentProtoPackage);
|
|
221487
|
+
if (external.size === 0) return [];
|
|
221488
|
+
const currentModulePath = currentProtoPackage ? `crate::${currentProtoPackage.split(".").join("::")}::${currentProtoPackage.split(".").pop()}` : "";
|
|
221489
|
+
const modules = /* @__PURE__ */ new Map();
|
|
221490
|
+
for (const fqn of external) {
|
|
221491
|
+
const parts = fqn.replace(/^\./, "").split(".");
|
|
221492
|
+
if (parts.length < 2) continue;
|
|
221493
|
+
const typeName = parts[parts.length - 1];
|
|
221494
|
+
const packageParts = parts.slice(0, -1);
|
|
221495
|
+
const modulePath = `crate::${packageParts.join("::")}::${packageParts[packageParts.length - 1]}`;
|
|
221496
|
+
if (modulePath === currentModulePath) continue;
|
|
221497
|
+
if (!modules.has(modulePath)) {
|
|
221498
|
+
modules.set(modulePath, /* @__PURE__ */ new Set());
|
|
221499
|
+
}
|
|
221500
|
+
modules.get(modulePath).add(typeName);
|
|
221501
|
+
}
|
|
221502
|
+
const lines = [];
|
|
221503
|
+
for (const [mod2, _types] of modules) {
|
|
221504
|
+
lines.push(`use ${mod2}::*;`);
|
|
221505
|
+
}
|
|
221506
|
+
return lines;
|
|
221507
|
+
}
|
|
221508
|
+
function generateRsFile(messages, protoFileName, protoPackage) {
|
|
221367
221509
|
const lines = [];
|
|
221368
221510
|
lines.push(`// Auto-generated by protoc-gen-solana from ${protoFileName}`);
|
|
221369
221511
|
lines.push(`// DO NOT EDIT`);
|
|
@@ -221371,6 +221513,10 @@ function generateRsFile(messages, protoFileName) {
|
|
|
221371
221513
|
lines.push(`#![allow(unused_imports, non_camel_case_types, dead_code)]`);
|
|
221372
221514
|
lines.push(``);
|
|
221373
221515
|
lines.push(`use crate::protobuf_runtime::*;`);
|
|
221516
|
+
const externalImports = genExternalImports(messages, protoPackage || "");
|
|
221517
|
+
for (const imp of externalImports) {
|
|
221518
|
+
lines.push(imp);
|
|
221519
|
+
}
|
|
221374
221520
|
lines.push(``);
|
|
221375
221521
|
for (const msg of messages) {
|
|
221376
221522
|
if (msg.isMapEntry) continue;
|
|
@@ -221554,7 +221700,7 @@ function processRequest(stdin) {
|
|
|
221554
221700
|
continue;
|
|
221555
221701
|
}
|
|
221556
221702
|
const rsFileName = protoFileToRsFile(fileName, protoFile.package ?? "");
|
|
221557
|
-
const rsContent = generateRsFile(messages, fileName);
|
|
221703
|
+
const rsContent = generateRsFile(messages, fileName, protoFile.package ?? "");
|
|
221558
221704
|
files.push({ name: rsFileName, content: rsContent });
|
|
221559
221705
|
log.info("Generated %s (%d messages)", rsFileName, messages.length);
|
|
221560
221706
|
}
|