@bufbuild/protoc-gen-es 1.0.0 → 1.1.0
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/cjs/package.json +3 -3
- package/dist/cjs/src/declaration.js +1 -1
- package/dist/cjs/src/javascript.js +9 -3
- package/dist/cjs/src/protoc-gen-es-plugin.js +1 -1
- package/dist/cjs/src/typescript.js +12 -4
- package/package.json +3 -3
- package/src/declaration.ts +1 -1
- package/src/javascript.ts +9 -3
- package/src/protoc-gen-es-plugin.ts +1 -1
- package/src/typescript.ts +12 -4
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"preferUnplugged": true,
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@bufbuild/protoplugin": "1.
|
|
23
|
+
"@bufbuild/protoplugin": "1.1.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@bufbuild/protobuf": "1.
|
|
26
|
+
"@bufbuild/protobuf": "1.1.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@bufbuild/protobuf": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -323,7 +323,7 @@ function generateWktMethods(schema, f, message) {
|
|
|
323
323
|
f.print(` if (typeof match[2] == "string") {`);
|
|
324
324
|
f.print(` const nanosStr = match[2] + "0".repeat(9 - match[2].length);`);
|
|
325
325
|
f.print(" this.", (0, ecmascript_1.localName)(ref.nanos), " = parseInt(nanosStr);");
|
|
326
|
-
f.print(" if (longSeconds <
|
|
326
|
+
f.print(" if (longSeconds < 0 || Object.is(longSeconds, -0)) {");
|
|
327
327
|
f.print(" this.", (0, ecmascript_1.localName)(ref.nanos), " = -this.", (0, ecmascript_1.localName)(ref.nanos), ";");
|
|
328
328
|
f.print(" }");
|
|
329
329
|
f.print(" }");
|
|
@@ -344,6 +344,9 @@ function generateWktMethods(schema, f, message) {
|
|
|
344
344
|
f.print(" nanosStr = nanosStr.substring(0, 6);");
|
|
345
345
|
f.print(` }`);
|
|
346
346
|
f.print(` text += "." + nanosStr;`);
|
|
347
|
+
f.print(" if (this.", (0, ecmascript_1.localName)(ref.nanos), " < 0 && this.", (0, ecmascript_1.localName)(ref.seconds), " === ", protoInt64, ".zero) {");
|
|
348
|
+
f.print(` text = "-" + text;`);
|
|
349
|
+
f.print(` }`);
|
|
347
350
|
f.print(" }");
|
|
348
351
|
f.print(` return text + "s";`);
|
|
349
352
|
f.print("};");
|
|
@@ -374,8 +377,11 @@ function generateWktMethods(schema, f, message) {
|
|
|
374
377
|
f.print(" switch (this.", (0, ecmascript_1.localName)(ref.kind), ".case) {");
|
|
375
378
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.nullValue), `":`);
|
|
376
379
|
f.print(" return null;");
|
|
377
|
-
f.print(` case "`, (0, ecmascript_1.localName)(ref.boolValue), `":`);
|
|
378
380
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.numberValue), `":`);
|
|
381
|
+
f.print(` if (!Number.isFinite(this.`, (0, ecmascript_1.localName)(ref.kind), `.value)) {`);
|
|
382
|
+
f.print(` throw new Error("google.protobuf.Value cannot be NaN or Infinity");`);
|
|
383
|
+
f.print(` }`);
|
|
384
|
+
f.print(` case "`, (0, ecmascript_1.localName)(ref.boolValue), `":`);
|
|
379
385
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.stringValue), `":`);
|
|
380
386
|
f.print(" return this.", (0, ecmascript_1.localName)(ref.kind), ".value;");
|
|
381
387
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.structValue), `":`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -76,7 +76,7 @@ function generateMessage(schema, f, message) {
|
|
|
76
76
|
f.print(" }");
|
|
77
77
|
f.print();
|
|
78
78
|
generateWktMethods(schema, f, message);
|
|
79
|
-
f.print(" static readonly runtime = ", protoN, ";");
|
|
79
|
+
f.print(" static readonly runtime: typeof ", protoN, " = ", protoN, ";");
|
|
80
80
|
f.print(' static readonly typeName = ', (0, ecmascript_2.literalString)(message.typeName), ';');
|
|
81
81
|
f.print(" static readonly fields: ", FieldList, " = ", protoN, ".util.newFieldList(() => [");
|
|
82
82
|
for (const field of message.fields) {
|
|
@@ -324,7 +324,7 @@ function generateWktMethods(schema, f, message) {
|
|
|
324
324
|
f.print(` if (typeof match[2] == "string") {`);
|
|
325
325
|
f.print(` const nanosStr = match[2] + "0".repeat(9 - match[2].length);`);
|
|
326
326
|
f.print(" this.", (0, ecmascript_1.localName)(ref.nanos), " = parseInt(nanosStr);");
|
|
327
|
-
f.print(" if (longSeconds <
|
|
327
|
+
f.print(" if (longSeconds < 0 || Object.is(longSeconds, -0)) {");
|
|
328
328
|
f.print(" this.", (0, ecmascript_1.localName)(ref.nanos), " = -this.", (0, ecmascript_1.localName)(ref.nanos), ";");
|
|
329
329
|
f.print(" }");
|
|
330
330
|
f.print(" }");
|
|
@@ -345,6 +345,9 @@ function generateWktMethods(schema, f, message) {
|
|
|
345
345
|
f.print(" nanosStr = nanosStr.substring(0, 6);");
|
|
346
346
|
f.print(` }`);
|
|
347
347
|
f.print(` text += "." + nanosStr;`);
|
|
348
|
+
f.print(" if (this.", (0, ecmascript_1.localName)(ref.nanos), " < 0 && this.", (0, ecmascript_1.localName)(ref.seconds), " === ", protoInt64, ".zero) {");
|
|
349
|
+
f.print(` text = "-" + text;`);
|
|
350
|
+
f.print(` }`);
|
|
348
351
|
f.print(" }");
|
|
349
352
|
f.print(` return text + "s";`);
|
|
350
353
|
f.print(" }");
|
|
@@ -375,8 +378,13 @@ function generateWktMethods(schema, f, message) {
|
|
|
375
378
|
f.print(" switch (this.", (0, ecmascript_1.localName)(ref.kind), ".case) {");
|
|
376
379
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.nullValue), `":`);
|
|
377
380
|
f.print(" return null;");
|
|
378
|
-
f.print(` case "`, (0, ecmascript_1.localName)(ref.boolValue), `":`);
|
|
379
381
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.numberValue), `":`);
|
|
382
|
+
f.print(` if (!Number.isFinite(this.`, (0, ecmascript_1.localName)(ref.kind), `.value)) {`);
|
|
383
|
+
f.print(` throw new Error("google.protobuf.Value cannot be NaN or Infinity");`);
|
|
384
|
+
f.print(` }`);
|
|
385
|
+
f.print(` return this.`, (0, ecmascript_1.localName)(ref.kind), `.value;`);
|
|
386
|
+
f.print(` case "`, (0, ecmascript_1.localName)(ref.boolValue), `":`);
|
|
387
|
+
f.print(` return this.`, (0, ecmascript_1.localName)(ref.kind), `.value;`);
|
|
380
388
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.stringValue), `":`);
|
|
381
389
|
f.print(" return this.", (0, ecmascript_1.localName)(ref.kind), ".value;");
|
|
382
390
|
f.print(` case "`, (0, ecmascript_1.localName)(ref.structValue), `":`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"preferUnplugged": true,
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@bufbuild/protoplugin": "1.
|
|
23
|
+
"@bufbuild/protoplugin": "1.1.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@bufbuild/protobuf": "1.
|
|
26
|
+
"@bufbuild/protobuf": "1.1.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@bufbuild/protobuf": {
|
package/src/declaration.ts
CHANGED
package/src/javascript.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -336,7 +336,7 @@ function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessa
|
|
|
336
336
|
f.print(` if (typeof match[2] == "string") {`)
|
|
337
337
|
f.print(` const nanosStr = match[2] + "0".repeat(9 - match[2].length);`)
|
|
338
338
|
f.print(" this.", localName(ref.nanos), " = parseInt(nanosStr);")
|
|
339
|
-
f.print(" if (longSeconds <
|
|
339
|
+
f.print(" if (longSeconds < 0 || Object.is(longSeconds, -0)) {");
|
|
340
340
|
f.print(" this.", localName(ref.nanos), " = -this.", localName(ref.nanos), ";")
|
|
341
341
|
f.print(" }")
|
|
342
342
|
f.print(" }")
|
|
@@ -357,6 +357,9 @@ function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessa
|
|
|
357
357
|
f.print(" nanosStr = nanosStr.substring(0, 6);")
|
|
358
358
|
f.print(` }`)
|
|
359
359
|
f.print(` text += "." + nanosStr;`)
|
|
360
|
+
f.print(" if (this.", localName(ref.nanos), " < 0 && this.", localName(ref.seconds), " === ", protoInt64, ".zero) {");
|
|
361
|
+
f.print(` text = "-" + text;`);
|
|
362
|
+
f.print(` }`);
|
|
360
363
|
f.print(" }")
|
|
361
364
|
f.print(` return text + "s";`)
|
|
362
365
|
f.print("};");
|
|
@@ -387,8 +390,11 @@ function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessa
|
|
|
387
390
|
f.print(" switch (this.", localName(ref.kind), ".case) {")
|
|
388
391
|
f.print(` case "`, localName(ref.nullValue), `":`)
|
|
389
392
|
f.print(" return null;")
|
|
390
|
-
f.print(` case "`, localName(ref.boolValue), `":`)
|
|
391
393
|
f.print(` case "`, localName(ref.numberValue), `":`)
|
|
394
|
+
f.print(` if (!Number.isFinite(this.`, localName(ref.kind), `.value)) {`);
|
|
395
|
+
f.print(` throw new Error("google.protobuf.Value cannot be NaN or Infinity");`);
|
|
396
|
+
f.print(` }`);
|
|
397
|
+
f.print(` case "`, localName(ref.boolValue), `":`)
|
|
392
398
|
f.print(` case "`, localName(ref.stringValue), `":`)
|
|
393
399
|
f.print(" return this.", localName(ref.kind), ".value;")
|
|
394
400
|
f.print(` case "`, localName(ref.structValue), `":`)
|
package/src/typescript.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -101,7 +101,7 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
101
101
|
f.print(" }");
|
|
102
102
|
f.print();
|
|
103
103
|
generateWktMethods(schema, f, message);
|
|
104
|
-
f.print(" static readonly runtime = ", protoN, ";");
|
|
104
|
+
f.print(" static readonly runtime: typeof ", protoN, " = ", protoN, ";");
|
|
105
105
|
f.print(' static readonly typeName = ', literalString(message.typeName), ';');
|
|
106
106
|
f.print(" static readonly fields: ", FieldList, " = ", protoN, ".util.newFieldList(() => [");
|
|
107
107
|
for (const field of message.fields) {
|
|
@@ -361,7 +361,7 @@ function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessa
|
|
|
361
361
|
f.print(` if (typeof match[2] == "string") {`)
|
|
362
362
|
f.print(` const nanosStr = match[2] + "0".repeat(9 - match[2].length);`)
|
|
363
363
|
f.print(" this.", localName(ref.nanos), " = parseInt(nanosStr);")
|
|
364
|
-
f.print(" if (longSeconds <
|
|
364
|
+
f.print(" if (longSeconds < 0 || Object.is(longSeconds, -0)) {");
|
|
365
365
|
f.print(" this.", localName(ref.nanos), " = -this.", localName(ref.nanos), ";")
|
|
366
366
|
f.print(" }")
|
|
367
367
|
f.print(" }")
|
|
@@ -382,6 +382,9 @@ function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessa
|
|
|
382
382
|
f.print(" nanosStr = nanosStr.substring(0, 6);")
|
|
383
383
|
f.print(` }`)
|
|
384
384
|
f.print(` text += "." + nanosStr;`)
|
|
385
|
+
f.print(" if (this.", localName(ref.nanos), " < 0 && this.", localName(ref.seconds), " === ", protoInt64, ".zero) {");
|
|
386
|
+
f.print(` text = "-" + text;`);
|
|
387
|
+
f.print(` }`);
|
|
385
388
|
f.print(" }")
|
|
386
389
|
f.print(` return text + "s";`)
|
|
387
390
|
f.print(" }")
|
|
@@ -412,8 +415,13 @@ function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessa
|
|
|
412
415
|
f.print(" switch (this.", localName(ref.kind), ".case) {")
|
|
413
416
|
f.print(` case "`, localName(ref.nullValue), `":`)
|
|
414
417
|
f.print(" return null;")
|
|
415
|
-
f.print(` case "`, localName(ref.boolValue), `":`)
|
|
416
418
|
f.print(` case "`, localName(ref.numberValue), `":`)
|
|
419
|
+
f.print(` if (!Number.isFinite(this.`, localName(ref.kind), `.value)) {`);
|
|
420
|
+
f.print(` throw new Error("google.protobuf.Value cannot be NaN or Infinity");`);
|
|
421
|
+
f.print(` }`);
|
|
422
|
+
f.print(` return this.`, localName(ref.kind), `.value;`);
|
|
423
|
+
f.print(` case "`, localName(ref.boolValue), `":`)
|
|
424
|
+
f.print(` return this.`, localName(ref.kind), `.value;`);
|
|
417
425
|
f.print(` case "`, localName(ref.stringValue), `":`)
|
|
418
426
|
f.print(" return this.", localName(ref.kind), ".value;")
|
|
419
427
|
f.print(` case "`, localName(ref.structValue), `":`)
|