@aptre/protobuf-es-lite 0.2.9 → 0.2.11
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/bin/protoc-gen-es-lite +2 -2
- package/dist/assert.js +4 -11
- package/dist/binary-encoding.js +30 -35
- package/dist/binary.js +84 -96
- package/dist/codegen-info.js +12 -15
- package/dist/create-descriptor-set.js +113 -117
- package/dist/descriptor-set.js +1 -2
- package/dist/enum.js +2 -7
- package/dist/feature-set.js +16 -20
- package/dist/field-wrapper.js +12 -17
- package/dist/field.js +18 -27
- package/dist/google/index.js +9 -41
- package/dist/google/protobuf/any.pb.d.ts +2 -2
- package/dist/google/protobuf/any.pb.js +3 -6
- package/dist/google/protobuf/api.pb.d.ts +2 -2
- package/dist/google/protobuf/api.pb.js +14 -17
- package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
- package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
- package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
- package/dist/google/protobuf/descriptor.pb.js +156 -160
- package/dist/google/protobuf/duration.pb.d.ts +2 -2
- package/dist/google/protobuf/duration.pb.js +3 -6
- package/dist/google/protobuf/empty.pb.d.ts +2 -2
- package/dist/google/protobuf/empty.pb.js +3 -6
- package/dist/google/protobuf/source_context.pb.d.ts +2 -2
- package/dist/google/protobuf/source_context.pb.js +3 -6
- package/dist/google/protobuf/struct.pb.d.ts +3 -3
- package/dist/google/protobuf/struct.pb.js +13 -16
- package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
- package/dist/google/protobuf/timestamp.pb.js +3 -6
- package/dist/google/protobuf/type.pb.d.ts +5 -5
- package/dist/google/protobuf/type.pb.js +31 -34
- package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
- package/dist/google/protobuf/wrappers.pb.js +11 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -60
- package/dist/is-message.js +9 -16
- package/dist/json.js +72 -80
- package/dist/message.js +48 -55
- package/dist/names.js +12 -23
- package/dist/partial.js +13 -17
- package/dist/proto-base64.js +1 -4
- package/dist/proto-double.js +1 -4
- package/dist/proto-int64.js +9 -12
- package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
- package/dist/protoc-gen-es-lite/typescript.js +27 -36
- package/dist/protoplugin/create-es-plugin.js +13 -17
- package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
- package/dist/protoplugin/ecmascript/generated-file.js +16 -20
- package/dist/protoplugin/ecmascript/import-path.js +13 -20
- package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
- package/dist/protoplugin/ecmascript/index.js +2 -7
- package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
- package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
- package/dist/protoplugin/ecmascript/parameter.js +10 -14
- package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
- package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
- package/dist/protoplugin/ecmascript/schema.js +16 -20
- package/dist/protoplugin/ecmascript/target.js +1 -2
- package/dist/protoplugin/ecmascript/transpile.js +15 -42
- package/dist/protoplugin/error.js +3 -9
- package/dist/protoplugin/index.js +2 -7
- package/dist/protoplugin/plugin.js +1 -2
- package/dist/protoplugin/run-node.js +6 -10
- package/dist/scalar.js +9 -15
- package/dist/service-type.js +4 -7
- package/dist/text-format.js +25 -30
- package/dist/type-registry.js +1 -2
- package/dist/unknown.js +7 -12
- package/dist/util.d.ts +1 -1
- package/dist/util.js +49 -55
- package/dist/varint.js +7 -17
- package/example/example.pb.ts +1 -1
- package/package.json +10 -7
- package/tsconfig.base.json +2 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2024 Aperture Robotics, LLC.
|
|
3
2
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
4
3
|
//
|
|
@@ -13,14 +12,12 @@
|
|
|
13
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
13
|
// See the License for the specific language governing permissions and
|
|
15
14
|
// limitations under the License.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const descriptor_pb_js_1 = require("../google/protobuf/descriptor.pb.js");
|
|
23
|
-
function generateTs(schema) {
|
|
15
|
+
import { createImportSymbol } from "../protoplugin/ecmascript/index.js";
|
|
16
|
+
import { getFieldDefaultValueExpression, getFieldTypeInfo } from "../util.js";
|
|
17
|
+
import { localName } from "../names.js";
|
|
18
|
+
import { LongType, ScalarType } from "../scalar.js";
|
|
19
|
+
import { FieldDescriptorProto_Label, FieldDescriptorProto_Type, } from "../google/protobuf/descriptor.pb.js";
|
|
20
|
+
export function generateTs(schema) {
|
|
24
21
|
for (const file of schema.files) {
|
|
25
22
|
const f = schema.generateFile(file.name + ".pb.ts");
|
|
26
23
|
f.preamble(file);
|
|
@@ -66,7 +63,6 @@ function generateTs(schema) {
|
|
|
66
63
|
// We do not generate anything for services or extensions
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
|
-
exports.generateTs = generateTs;
|
|
70
66
|
// topologicalSort sorts the list of messages by dependency order.
|
|
71
67
|
function topologicalSort(messages, dependencies) {
|
|
72
68
|
const result = [];
|
|
@@ -93,7 +89,7 @@ function generateEnum(schema, f, enumeration) {
|
|
|
93
89
|
f.print();
|
|
94
90
|
}
|
|
95
91
|
f.print(f.jsDoc(value, " "));
|
|
96
|
-
f.print(" ",
|
|
92
|
+
f.print(" ", localName(value), " = ", value.number, ",");
|
|
97
93
|
}
|
|
98
94
|
f.print("}");
|
|
99
95
|
f.print();
|
|
@@ -105,12 +101,11 @@ function generateEnum(schema, f, enumeration) {
|
|
|
105
101
|
f.print("]);");
|
|
106
102
|
f.print();
|
|
107
103
|
}
|
|
108
|
-
function checkSupportedSyntax(file) {
|
|
104
|
+
export function checkSupportedSyntax(file) {
|
|
109
105
|
if (file.syntax === "editions") {
|
|
110
106
|
throw new Error(`${file.proto.name ?? ""}: syntax "editions" is not supported`);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
|
-
exports.checkSupportedSyntax = checkSupportedSyntax;
|
|
114
109
|
function generateMessage(schema, f, message) {
|
|
115
110
|
// check if we support this runtime
|
|
116
111
|
checkSupportedSyntax(message.file);
|
|
@@ -154,15 +149,15 @@ function generateField(f, field) {
|
|
|
154
149
|
return;
|
|
155
150
|
}
|
|
156
151
|
f.print(f.jsDoc(field, " "));
|
|
157
|
-
const { typing } =
|
|
158
|
-
f.print(" ",
|
|
152
|
+
const { typing } = getFieldTypeInfo(field);
|
|
153
|
+
f.print(" ", localName(field), "?: ", typing, ";");
|
|
159
154
|
}
|
|
160
155
|
function generateOneof(f, oneof) {
|
|
161
156
|
f.print();
|
|
162
157
|
f.print(f.jsDoc(oneof, " "));
|
|
163
158
|
var oneOfCases = oneof.fields
|
|
164
159
|
.map((field) => {
|
|
165
|
-
const { typing } =
|
|
160
|
+
const { typing } = getFieldTypeInfo(field);
|
|
166
161
|
const doc = f.jsDoc(field, " ");
|
|
167
162
|
return [
|
|
168
163
|
` | {\n`,
|
|
@@ -170,31 +165,28 @@ function generateOneof(f, oneof) {
|
|
|
170
165
|
`\n value: `,
|
|
171
166
|
typing,
|
|
172
167
|
`;\n case: "`,
|
|
173
|
-
|
|
168
|
+
localName(field),
|
|
174
169
|
`";\n }`,
|
|
175
170
|
];
|
|
176
171
|
})
|
|
177
172
|
.flat();
|
|
178
173
|
f.print(" ", oneof.name, "?: {\n value?: undefined,\n case: undefined\n }", oneOfCases, ";");
|
|
179
174
|
}
|
|
180
|
-
function makeImportPath(file) {
|
|
175
|
+
export function makeImportPath(file) {
|
|
181
176
|
return "./" + file.name + ".pb.js";
|
|
182
177
|
}
|
|
183
|
-
|
|
184
|
-
function generateFieldInfo(f, field) {
|
|
178
|
+
export function generateFieldInfo(f, field) {
|
|
185
179
|
f.print(" ", getFieldInfoLiteral(field), ",");
|
|
186
180
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
var name = (0, names_js_1.localName)(desc);
|
|
181
|
+
export const createTypeImport = (desc) => {
|
|
182
|
+
var name = localName(desc);
|
|
190
183
|
if (desc.kind === "enum") {
|
|
191
184
|
name += "_Enum";
|
|
192
185
|
}
|
|
193
186
|
const from = makeImportPath(desc.file);
|
|
194
|
-
return
|
|
187
|
+
return createImportSymbol(name, from);
|
|
195
188
|
};
|
|
196
|
-
|
|
197
|
-
function getFieldInfoLiteral(field) {
|
|
189
|
+
export function getFieldInfoLiteral(field) {
|
|
198
190
|
const e = [];
|
|
199
191
|
e.push("{ no: ", field.number, `, `);
|
|
200
192
|
if (field.kind == "field") {
|
|
@@ -205,16 +197,16 @@ function getFieldInfoLiteral(field) {
|
|
|
205
197
|
}
|
|
206
198
|
switch (field.fieldKind) {
|
|
207
199
|
case "scalar":
|
|
208
|
-
e.push(`kind: "scalar", T: `, field.scalar, ` /* ScalarType.`,
|
|
209
|
-
if (field.longType !=
|
|
210
|
-
e.push(`L: `, field.longType, ` /* LongType.`,
|
|
200
|
+
e.push(`kind: "scalar", T: `, field.scalar, ` /* ScalarType.`, ScalarType[field.scalar], ` */, `);
|
|
201
|
+
if (field.longType != LongType.BIGINT) {
|
|
202
|
+
e.push(`L: `, field.longType, ` /* LongType.`, LongType[field.longType], ` */, `);
|
|
211
203
|
}
|
|
212
204
|
break;
|
|
213
205
|
case "map":
|
|
214
|
-
e.push(`kind: "map", K: `, field.mapKey, ` /* ScalarType.`,
|
|
206
|
+
e.push(`kind: "map", K: `, field.mapKey, ` /* ScalarType.`, ScalarType[field.mapKey], ` */, `);
|
|
215
207
|
switch (field.mapValue.kind) {
|
|
216
208
|
case "scalar":
|
|
217
|
-
e.push(`V: {kind: "scalar", T: `, field.mapValue.scalar, ` /* ScalarType.`,
|
|
209
|
+
e.push(`V: {kind: "scalar", T: `, field.mapValue.scalar, ` /* ScalarType.`, ScalarType[field.mapValue.scalar], ` */}, `);
|
|
218
210
|
break;
|
|
219
211
|
case "message":
|
|
220
212
|
e.push(`V: {kind: "message", T: () => `, field.mapValue.message, `}, `);
|
|
@@ -226,12 +218,12 @@ function getFieldInfoLiteral(field) {
|
|
|
226
218
|
break;
|
|
227
219
|
case "message":
|
|
228
220
|
e.push(`kind: "message", T: () => `, field.message, `, `);
|
|
229
|
-
if (field.proto.type ===
|
|
221
|
+
if (field.proto.type === FieldDescriptorProto_Type.GROUP) {
|
|
230
222
|
e.push(`delimited: true, `);
|
|
231
223
|
}
|
|
232
224
|
break;
|
|
233
225
|
case "enum":
|
|
234
|
-
e.push(`kind: "enum", T: `,
|
|
226
|
+
e.push(`kind: "enum", T: `, createTypeImport(field.enum), `, `);
|
|
235
227
|
break;
|
|
236
228
|
}
|
|
237
229
|
if (field.repeated) {
|
|
@@ -243,10 +235,10 @@ function getFieldInfoLiteral(field) {
|
|
|
243
235
|
if (field.optional) {
|
|
244
236
|
e.push(`opt: true, `);
|
|
245
237
|
}
|
|
246
|
-
else if (field.proto.label ===
|
|
238
|
+
else if (field.proto.label === FieldDescriptorProto_Label.REQUIRED) {
|
|
247
239
|
e.push(`req: true, `);
|
|
248
240
|
}
|
|
249
|
-
const defaultValue =
|
|
241
|
+
const defaultValue = getFieldDefaultValueExpression(field);
|
|
250
242
|
if (defaultValue !== undefined) {
|
|
251
243
|
e.push(`default: `, defaultValue, `, `);
|
|
252
244
|
}
|
|
@@ -260,4 +252,3 @@ function getFieldInfoLiteral(field) {
|
|
|
260
252
|
e.push(" }");
|
|
261
253
|
return e;
|
|
262
254
|
}
|
|
263
|
-
exports.getFieldInfoLiteral = getFieldInfoLiteral;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,27 +11,25 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const plugin_pb_js_1 = require("../google/protobuf/compiler/plugin.pb.js");
|
|
21
|
-
const proto_int64_js_1 = require("../proto-int64.js");
|
|
14
|
+
import { createSchema } from "./ecmascript/schema.js";
|
|
15
|
+
import { transpile } from "./ecmascript/transpile.js";
|
|
16
|
+
import { parseParameter } from "./ecmascript/parameter.js";
|
|
17
|
+
import { CodeGeneratorResponse, CodeGeneratorResponse_Feature, } from "../google/protobuf/compiler/plugin.pb.js";
|
|
18
|
+
import { protoInt64 } from "../proto-int64.js";
|
|
22
19
|
/**
|
|
23
20
|
* Create a new code generator plugin for ECMAScript.
|
|
24
21
|
* The plugin can generate JavaScript, TypeScript, or TypeScript declaration
|
|
25
22
|
* files.
|
|
26
23
|
*/
|
|
27
|
-
function createEcmaScriptPlugin(init) {
|
|
24
|
+
export function createEcmaScriptPlugin(init) {
|
|
28
25
|
let transpileJs = false;
|
|
29
26
|
let transpileDts = false;
|
|
30
27
|
return {
|
|
31
28
|
name: init.name,
|
|
32
29
|
version: init.version,
|
|
33
30
|
run(req) {
|
|
34
|
-
const parameter =
|
|
35
|
-
const schema =
|
|
31
|
+
const parameter = parseParameter(req.parameter, init.parseOption);
|
|
32
|
+
const schema = createSchema(req, parameter, init.name, init.version, init.featureSetDefaults);
|
|
36
33
|
const targetTs = schema.targets.includes("ts");
|
|
37
34
|
const targetJs = schema.targets.includes("js");
|
|
38
35
|
const targetDts = schema.targets.includes("dts");
|
|
@@ -91,7 +88,7 @@ function createEcmaScriptPlugin(init) {
|
|
|
91
88
|
// but no generate function was provided. This also means that we will
|
|
92
89
|
// have generated .ts files above.
|
|
93
90
|
if (transpileJs || transpileDts) {
|
|
94
|
-
const transpileFn = init.transpile ??
|
|
91
|
+
const transpileFn = init.transpile ?? transpile;
|
|
95
92
|
// Transpile the TypeScript files and add to the master list of files
|
|
96
93
|
const transpiledFiles = transpileFn(tsFiles, transpileJs, transpileDts, parameter.jsImportStyle);
|
|
97
94
|
files.push(...transpiledFiles);
|
|
@@ -100,15 +97,14 @@ function createEcmaScriptPlugin(init) {
|
|
|
100
97
|
},
|
|
101
98
|
};
|
|
102
99
|
}
|
|
103
|
-
exports.createEcmaScriptPlugin = createEcmaScriptPlugin;
|
|
104
100
|
function toResponse(files, supportsEditions) {
|
|
105
|
-
let supportedFeatures =
|
|
101
|
+
let supportedFeatures = CodeGeneratorResponse_Feature.PROTO3_OPTIONAL;
|
|
106
102
|
if (supportsEditions) {
|
|
107
103
|
supportedFeatures =
|
|
108
|
-
supportedFeatures |
|
|
104
|
+
supportedFeatures | CodeGeneratorResponse_Feature.SUPPORTS_EDITIONS;
|
|
109
105
|
}
|
|
110
|
-
return
|
|
111
|
-
supportedFeatures:
|
|
106
|
+
return CodeGeneratorResponse.create({
|
|
107
|
+
supportedFeatures: protoInt64.parse(supportedFeatures),
|
|
112
108
|
file: files.map((f) => {
|
|
113
109
|
if (f.preamble !== undefined) {
|
|
114
110
|
f.content = f.preamble + "\n" + f.content;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,10 +11,8 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const descriptor_pb_js_1 = require("../../google/protobuf/descriptor.pb.js");
|
|
18
|
-
function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
|
|
14
|
+
import { Edition } from "../../google/protobuf/descriptor.pb.js";
|
|
15
|
+
export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
|
|
19
16
|
const builder = [];
|
|
20
17
|
const trimSuffix = (str, suffix) => str.endsWith(suffix) ? str.substring(0, str.length - suffix.length) : str;
|
|
21
18
|
const writeLeadingComments = (comments) => {
|
|
@@ -45,14 +42,14 @@ function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck)
|
|
|
45
42
|
builder.push(`package ${file.proto.package}, `);
|
|
46
43
|
}
|
|
47
44
|
switch (file.edition) {
|
|
48
|
-
case
|
|
45
|
+
case Edition.EDITION_PROTO2:
|
|
49
46
|
builder.push(`syntax proto2)\n`);
|
|
50
47
|
break;
|
|
51
|
-
case
|
|
48
|
+
case Edition.EDITION_PROTO3:
|
|
52
49
|
builder.push(`syntax proto3)\n`);
|
|
53
50
|
break;
|
|
54
51
|
default: {
|
|
55
|
-
const editionString =
|
|
52
|
+
const editionString = Edition[file.edition];
|
|
56
53
|
if (typeof editionString == "string") {
|
|
57
54
|
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
58
55
|
builder.push(`edition ${e})\n`);
|
|
@@ -71,4 +68,3 @@ function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck)
|
|
|
71
68
|
writeLeadingComments(file.getPackageComments());
|
|
72
69
|
return trimSuffix(builder.join(""), "\n");
|
|
73
70
|
}
|
|
74
|
-
exports.makeFilePreamble = makeFilePreamble;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,14 +11,12 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const scalar_js_1 = require("../../scalar.js");
|
|
22
|
-
function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
|
|
14
|
+
import { createImportSymbol } from "./import-symbol.js";
|
|
15
|
+
import { makeImportPathRelative } from "./import-path.js";
|
|
16
|
+
import { createJsDocBlock } from "./jsdoc.js";
|
|
17
|
+
import { protoInt64 } from "../../proto-int64.js";
|
|
18
|
+
import { LongType, ScalarType } from "../../scalar.js";
|
|
19
|
+
export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
|
|
23
20
|
let preamble;
|
|
24
21
|
const el = [];
|
|
25
22
|
return {
|
|
@@ -44,7 +41,7 @@ function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath,
|
|
|
44
41
|
el.push("\n");
|
|
45
42
|
},
|
|
46
43
|
export(name) {
|
|
47
|
-
return
|
|
44
|
+
return createImportSymbol(name, importPath);
|
|
48
45
|
},
|
|
49
46
|
exportDecl(declaration, name) {
|
|
50
47
|
return {
|
|
@@ -58,12 +55,12 @@ function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath,
|
|
|
58
55
|
return escapeString(string);
|
|
59
56
|
},
|
|
60
57
|
jsDoc(textOrDesc, indentation) {
|
|
61
|
-
return
|
|
58
|
+
return createJsDocBlock(textOrDesc, indentation);
|
|
62
59
|
},
|
|
63
60
|
import(typeOrName, from) {
|
|
64
61
|
if (typeof typeOrName == "string") {
|
|
65
62
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
66
|
-
return
|
|
63
|
+
return createImportSymbol(typeOrName, from);
|
|
67
64
|
}
|
|
68
65
|
return createTypeImport(typeOrName);
|
|
69
66
|
},
|
|
@@ -77,7 +74,6 @@ function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath,
|
|
|
77
74
|
},
|
|
78
75
|
};
|
|
79
76
|
}
|
|
80
|
-
exports.createGeneratedFile = createGeneratedFile;
|
|
81
77
|
function elToContent(el, importerPath, rewriteImportPath, legacyCommonJs) {
|
|
82
78
|
if (el.length == 0) {
|
|
83
79
|
return "";
|
|
@@ -318,7 +314,7 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
|
|
|
318
314
|
// should never happen
|
|
319
315
|
continue;
|
|
320
316
|
}
|
|
321
|
-
const from =
|
|
317
|
+
const from = makeImportPathRelative(importerPath, rewriteImportPath(s.from));
|
|
322
318
|
if (i.types.size > 0) {
|
|
323
319
|
makeImportStatement(true, from, buildNames(i.types));
|
|
324
320
|
}
|
|
@@ -329,7 +325,7 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
|
|
|
329
325
|
return symbolToIdentifier;
|
|
330
326
|
}
|
|
331
327
|
function elBigint(el, value, runtimeImports) {
|
|
332
|
-
if (value ==
|
|
328
|
+
if (value == protoInt64.zero) {
|
|
333
329
|
// Loose comparison will match between 0n and 0.
|
|
334
330
|
el.push(runtimeImports.protoInt64, ".zero");
|
|
335
331
|
}
|
|
@@ -366,18 +362,18 @@ function elUint8Array(el, value) {
|
|
|
366
362
|
}
|
|
367
363
|
function elProtoInt64(el, literal, runtimeImports) {
|
|
368
364
|
switch (literal.longType) {
|
|
369
|
-
case
|
|
365
|
+
case LongType.STRING:
|
|
370
366
|
el.push(escapeString(literal.value.toString()));
|
|
371
367
|
break;
|
|
372
|
-
case
|
|
373
|
-
if (literal.value ==
|
|
368
|
+
case LongType.BIGINT:
|
|
369
|
+
if (literal.value == protoInt64.zero) {
|
|
374
370
|
// Loose comparison will match between 0n and 0.
|
|
375
371
|
el.push(runtimeImports.protoInt64, ".zero");
|
|
376
372
|
break;
|
|
377
373
|
}
|
|
378
374
|
switch (literal.type) {
|
|
379
|
-
case
|
|
380
|
-
case
|
|
375
|
+
case ScalarType.UINT64:
|
|
376
|
+
case ScalarType.FIXED64:
|
|
381
377
|
el.push(runtimeImports.protoInt64);
|
|
382
378
|
el.push(".uParse(");
|
|
383
379
|
el.push(escapeString(literal.value.toString()));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,15 +11,13 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
exports.makeImportPathRelative = exports.deriveImportPath = exports.relativePathRE = exports.makeImportPath = exports.rewriteImportPath = void 0;
|
|
17
|
-
const codegen_info_js_1 = require("../../codegen-info.js");
|
|
14
|
+
import { codegenInfo } from "../../codegen-info.js";
|
|
18
15
|
const cache = new WeakMap();
|
|
19
16
|
/**
|
|
20
17
|
* Apply import rewrites to the given import path, and change all .js extensions
|
|
21
18
|
* to the given import extension.
|
|
22
19
|
*/
|
|
23
|
-
function rewriteImportPath(importPath, rewriteImports, importExtension) {
|
|
20
|
+
export function rewriteImportPath(importPath, rewriteImports, importExtension) {
|
|
24
21
|
let ri = cache.get(rewriteImports);
|
|
25
22
|
if (ri === undefined) {
|
|
26
23
|
ri = rewriteImports.map(({ pattern, target }) => {
|
|
@@ -33,9 +30,9 @@ function rewriteImportPath(importPath, rewriteImports, importExtension) {
|
|
|
33
30
|
}
|
|
34
31
|
for (const { pattern, target } of ri) {
|
|
35
32
|
if (pattern.test(importPath)) {
|
|
36
|
-
if (
|
|
33
|
+
if (relativePathRE.test(importPath)) {
|
|
37
34
|
importPath =
|
|
38
|
-
target.replace(/\/$/, "") + importPath.replace(
|
|
35
|
+
target.replace(/\/$/, "") + importPath.replace(relativePathRE, "/");
|
|
39
36
|
}
|
|
40
37
|
else {
|
|
41
38
|
importPath = target;
|
|
@@ -49,7 +46,6 @@ function rewriteImportPath(importPath, rewriteImports, importExtension) {
|
|
|
49
46
|
}
|
|
50
47
|
return importPath;
|
|
51
48
|
}
|
|
52
|
-
exports.rewriteImportPath = rewriteImportPath;
|
|
53
49
|
function starToRegExp(star) {
|
|
54
50
|
const r = ["^"];
|
|
55
51
|
for (let i = 0; i < star.length; i++) {
|
|
@@ -89,7 +85,7 @@ function starToRegExp(star) {
|
|
|
89
85
|
* Returns the import path for files generated by the base type generator
|
|
90
86
|
* protoc-gen-es.
|
|
91
87
|
*/
|
|
92
|
-
function makeImportPath(file, bootstrapWkt, filesToGenerate) {
|
|
88
|
+
export function makeImportPath(file, bootstrapWkt, filesToGenerate) {
|
|
93
89
|
// Well-known types are published with the runtime package. We usually want
|
|
94
90
|
// the generated code to import them from the runtime package, with the
|
|
95
91
|
// following exceptions:
|
|
@@ -99,25 +95,23 @@ function makeImportPath(file, bootstrapWkt, filesToGenerate) {
|
|
|
99
95
|
// 2. We were explicitly asked to generate the well-known type.
|
|
100
96
|
if (!bootstrapWkt &&
|
|
101
97
|
!filesToGenerate.includes(file) &&
|
|
102
|
-
|
|
103
|
-
return
|
|
98
|
+
codegenInfo.wktSourceFiles.includes(file.name + ".proto")) {
|
|
99
|
+
return codegenInfo.packageName;
|
|
104
100
|
}
|
|
105
101
|
return "./" + file.name + ".pb.js";
|
|
106
102
|
}
|
|
107
|
-
|
|
108
|
-
exports.relativePathRE = /^\.{1,2}\//;
|
|
103
|
+
export const relativePathRE = /^\.{1,2}\//;
|
|
109
104
|
/**
|
|
110
105
|
* Derives an ECMAScript module import path from a file path. For example,
|
|
111
106
|
* the path `foo/bar.ts` is transformed into `./foo/bar.js`.
|
|
112
107
|
*/
|
|
113
|
-
function deriveImportPath(filename) {
|
|
108
|
+
export function deriveImportPath(filename) {
|
|
114
109
|
let importPath = filename.replace(/\.(js|ts|d.ts)$/, ".js");
|
|
115
|
-
if (!
|
|
110
|
+
if (!relativePathRE.test(importPath)) {
|
|
116
111
|
importPath = "./" + importPath;
|
|
117
112
|
}
|
|
118
113
|
return importPath;
|
|
119
114
|
}
|
|
120
|
-
exports.deriveImportPath = deriveImportPath;
|
|
121
115
|
/**
|
|
122
116
|
* Makes an import path relative to the file importing it. For example,
|
|
123
117
|
* consider the following files:
|
|
@@ -125,8 +119,8 @@ exports.deriveImportPath = deriveImportPath;
|
|
|
125
119
|
* - baz.js
|
|
126
120
|
* If foo.js wants to import baz.js, we return ../baz.js
|
|
127
121
|
*/
|
|
128
|
-
function makeImportPathRelative(importer, importPath) {
|
|
129
|
-
if (!
|
|
122
|
+
export function makeImportPathRelative(importer, importPath) {
|
|
123
|
+
if (!relativePathRE.test(importPath)) {
|
|
130
124
|
// We don't touch absolute imports
|
|
131
125
|
return importPath;
|
|
132
126
|
}
|
|
@@ -151,6 +145,5 @@ function makeImportPathRelative(importer, importPath) {
|
|
|
151
145
|
.map(() => "..")
|
|
152
146
|
.concat(b)
|
|
153
147
|
.join("/");
|
|
154
|
-
return
|
|
148
|
+
return relativePathRE.test(c) ? c : "./" + c;
|
|
155
149
|
}
|
|
156
|
-
exports.makeImportPathRelative = makeImportPathRelative;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,12 +11,10 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.createImportSymbol = void 0;
|
|
17
14
|
/**
|
|
18
15
|
* Create a new import symbol.
|
|
19
16
|
*/
|
|
20
|
-
function createImportSymbol(name, from, typeOnly) {
|
|
17
|
+
export function createImportSymbol(name, from, typeOnly) {
|
|
21
18
|
const id = `import("${from}").${name}`;
|
|
22
19
|
const s = {
|
|
23
20
|
kind: "es_symbol",
|
|
@@ -34,4 +31,3 @@ function createImportSymbol(name, from, typeOnly) {
|
|
|
34
31
|
};
|
|
35
32
|
return typeOnly === true ? s.toTypeOnly() : s;
|
|
36
33
|
}
|
|
37
|
-
exports.createImportSymbol = createImportSymbol;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,9 +11,5 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var reify_wkt_js_1 = require("./reify-wkt.js");
|
|
18
|
-
Object.defineProperty(exports, "reifyWkt", { enumerable: true, get: function () { return reify_wkt_js_1.reifyWkt; } });
|
|
19
|
-
var import_symbol_js_1 = require("./import-symbol.js");
|
|
20
|
-
Object.defineProperty(exports, "createImportSymbol", { enumerable: true, get: function () { return import_symbol_js_1.createImportSymbol; } });
|
|
14
|
+
export { reifyWkt } from "./reify-wkt.js";
|
|
15
|
+
export { createImportSymbol } from "./import-symbol.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,10 +11,8 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.createJsDocBlock = void 0;
|
|
17
14
|
// TODO simplify type JSDocBlock to bring it in line with others in opaque-printables.ts
|
|
18
|
-
function createJsDocBlock(textOrDesc, indentation) {
|
|
15
|
+
export function createJsDocBlock(textOrDesc, indentation) {
|
|
19
16
|
const text = typeof textOrDesc == "string" ? textOrDesc : createTextForDesc(textOrDesc);
|
|
20
17
|
return {
|
|
21
18
|
kind: "es_jsdoc",
|
|
@@ -36,7 +33,6 @@ function createJsDocBlock(textOrDesc, indentation) {
|
|
|
36
33
|
},
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
|
-
exports.createJsDocBlock = createJsDocBlock;
|
|
40
36
|
function createTextForDesc(desc) {
|
|
41
37
|
const comments = desc.getComments();
|
|
42
38
|
let text = "";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,4 +11,4 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
14
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,10 +11,8 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const error_js_1 = require("../error.js");
|
|
18
|
-
function parseParameter(parameter, parseExtraOption) {
|
|
14
|
+
import { PluginOptionError } from "../error.js";
|
|
15
|
+
export function parseParameter(parameter, parseExtraOption) {
|
|
19
16
|
let targets = ["js", "dts"];
|
|
20
17
|
let tsNocheck = true;
|
|
21
18
|
let bootstrapWkt = false;
|
|
@@ -41,7 +38,7 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
41
38
|
}
|
|
42
39
|
break;
|
|
43
40
|
default:
|
|
44
|
-
throw new
|
|
41
|
+
throw new PluginOptionError(raw);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
value.split("+");
|
|
@@ -57,7 +54,7 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
57
54
|
tsNocheck = false;
|
|
58
55
|
break;
|
|
59
56
|
default:
|
|
60
|
-
throw new
|
|
57
|
+
throw new PluginOptionError(raw);
|
|
61
58
|
}
|
|
62
59
|
break;
|
|
63
60
|
case "bootstrap_wkt":
|
|
@@ -71,13 +68,13 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
71
68
|
bootstrapWkt = false;
|
|
72
69
|
break;
|
|
73
70
|
default:
|
|
74
|
-
throw new
|
|
71
|
+
throw new PluginOptionError(raw);
|
|
75
72
|
}
|
|
76
73
|
break;
|
|
77
74
|
case "rewrite_imports": {
|
|
78
75
|
const parts = value.split(":");
|
|
79
76
|
if (parts.length !== 2) {
|
|
80
|
-
throw new
|
|
77
|
+
throw new PluginOptionError(raw, "must be in the form of <pattern>:<target>");
|
|
81
78
|
}
|
|
82
79
|
const [pattern, target] = parts;
|
|
83
80
|
rewriteImports.push({ pattern, target });
|
|
@@ -99,7 +96,7 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
99
96
|
jsImportStyle = value;
|
|
100
97
|
break;
|
|
101
98
|
default:
|
|
102
|
-
throw new
|
|
99
|
+
throw new PluginOptionError(raw);
|
|
103
100
|
}
|
|
104
101
|
break;
|
|
105
102
|
case "keep_empty_files": {
|
|
@@ -113,19 +110,19 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
113
110
|
keepEmptyFiles = false;
|
|
114
111
|
break;
|
|
115
112
|
default:
|
|
116
|
-
throw new
|
|
113
|
+
throw new PluginOptionError(raw);
|
|
117
114
|
}
|
|
118
115
|
break;
|
|
119
116
|
}
|
|
120
117
|
default:
|
|
121
118
|
if (parseExtraOption === undefined) {
|
|
122
|
-
throw new
|
|
119
|
+
throw new PluginOptionError(raw);
|
|
123
120
|
}
|
|
124
121
|
try {
|
|
125
122
|
parseExtraOption(key, value);
|
|
126
123
|
}
|
|
127
124
|
catch (e) {
|
|
128
|
-
throw new
|
|
125
|
+
throw new PluginOptionError(raw, e);
|
|
129
126
|
}
|
|
130
127
|
break;
|
|
131
128
|
}
|
|
@@ -145,7 +142,6 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
145
142
|
sanitizedParameter,
|
|
146
143
|
};
|
|
147
144
|
}
|
|
148
|
-
exports.parseParameter = parseParameter;
|
|
149
145
|
function splitParameter(parameter) {
|
|
150
146
|
if (parameter == undefined) {
|
|
151
147
|
return [];
|