@bufbuild/protoplugin 1.3.3 → 1.4.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/ecmascript/gencommon.d.ts +2 -2
- package/dist/cjs/ecmascript/gencommon.js +11 -5
- package/dist/cjs/ecmascript/runtime-imports.d.ts +1 -0
- package/dist/cjs/ecmascript/runtime-imports.js +1 -0
- package/dist/esm/ecmascript/gencommon.d.ts +2 -2
- package/dist/esm/ecmascript/gencommon.js +12 -6
- package/dist/esm/ecmascript/runtime-imports.d.ts +1 -0
- package/dist/esm/ecmascript/runtime-imports.js +1 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DescEnum, DescEnumValue, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, ScalarType } from "@bufbuild/protobuf";
|
|
1
|
+
import { DescEnum, DescEnumValue, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, LongType, ScalarType } from "@bufbuild/protobuf";
|
|
2
2
|
import type { GeneratedFile, Printable } from "./generated-file.js";
|
|
3
3
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
4
4
|
export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
|
|
@@ -12,7 +12,7 @@ export declare function getFieldTyping(field: DescField, file: GeneratedFile): {
|
|
|
12
12
|
typing: Printable;
|
|
13
13
|
optional: boolean;
|
|
14
14
|
};
|
|
15
|
-
export declare function scalarTypeScriptType(type: ScalarType): Printable;
|
|
15
|
+
export declare function scalarTypeScriptType(type: ScalarType, longType: LongType): Printable;
|
|
16
16
|
export declare function literalString(value: string): string;
|
|
17
17
|
export declare function getFieldExplicitDefaultValue(field: DescField, protoInt64Symbol: ImportSymbol): Printable | undefined;
|
|
18
18
|
export declare function getFieldIntrinsicDefaultValue(field: DescField): {
|
|
@@ -138,13 +138,13 @@ function getFieldTyping(field, file) {
|
|
|
138
138
|
let optional = false;
|
|
139
139
|
switch (field.fieldKind) {
|
|
140
140
|
case "scalar":
|
|
141
|
-
typing.push(scalarTypeScriptType(field.scalar));
|
|
141
|
+
typing.push(scalarTypeScriptType(field.scalar, field.longType));
|
|
142
142
|
optional = field.optional;
|
|
143
143
|
break;
|
|
144
144
|
case "message": {
|
|
145
145
|
const baseType = getUnwrappedFieldType(field);
|
|
146
146
|
if (baseType !== undefined) {
|
|
147
|
-
typing.push(scalarTypeScriptType(baseType));
|
|
147
|
+
typing.push(scalarTypeScriptType(baseType, protobuf_1.LongType.BIGINT));
|
|
148
148
|
}
|
|
149
149
|
else {
|
|
150
150
|
typing.push(file.import(field.message).toTypeOnly());
|
|
@@ -173,7 +173,7 @@ function getFieldTyping(field, file) {
|
|
|
173
173
|
let valueType;
|
|
174
174
|
switch (field.mapValue.kind) {
|
|
175
175
|
case "scalar":
|
|
176
|
-
valueType = scalarTypeScriptType(field.mapValue.scalar);
|
|
176
|
+
valueType = scalarTypeScriptType(field.mapValue.scalar, protobuf_1.LongType.BIGINT);
|
|
177
177
|
break;
|
|
178
178
|
case "message":
|
|
179
179
|
valueType = file.import(field.mapValue.message).toTypeOnly();
|
|
@@ -194,7 +194,7 @@ function getFieldTyping(field, file) {
|
|
|
194
194
|
return { typing, optional };
|
|
195
195
|
}
|
|
196
196
|
exports.getFieldTyping = getFieldTyping;
|
|
197
|
-
function scalarTypeScriptType(type) {
|
|
197
|
+
function scalarTypeScriptType(type, longType) {
|
|
198
198
|
switch (type) {
|
|
199
199
|
case protobuf_1.ScalarType.STRING:
|
|
200
200
|
return "string";
|
|
@@ -205,6 +205,9 @@ function scalarTypeScriptType(type) {
|
|
|
205
205
|
case protobuf_1.ScalarType.FIXED64:
|
|
206
206
|
case protobuf_1.ScalarType.SINT64:
|
|
207
207
|
case protobuf_1.ScalarType.INT64:
|
|
208
|
+
if (longType === protobuf_1.LongType.STRING) {
|
|
209
|
+
return "string";
|
|
210
|
+
}
|
|
208
211
|
return "bigint";
|
|
209
212
|
case protobuf_1.ScalarType.BYTES:
|
|
210
213
|
return "Uint8Array";
|
|
@@ -319,7 +322,10 @@ function getFieldIntrinsicDefaultValue(field) {
|
|
|
319
322
|
}
|
|
320
323
|
else {
|
|
321
324
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
322
|
-
defaultValue = scalarDefaultValue(field.scalar);
|
|
325
|
+
defaultValue = scalarDefaultValue(field.scalar, field.longType);
|
|
326
|
+
if (typeof defaultValue === "string") {
|
|
327
|
+
defaultValue = literalString(defaultValue);
|
|
328
|
+
}
|
|
323
329
|
}
|
|
324
330
|
}
|
|
325
331
|
break;
|
|
@@ -35,6 +35,7 @@ function createRuntimeImports(bootstrapWkt) {
|
|
|
35
35
|
protoDouble: infoToSymbol("protoDouble", bootstrapWkt),
|
|
36
36
|
protoInt64: infoToSymbol("protoInt64", bootstrapWkt),
|
|
37
37
|
ScalarType: infoToSymbol("ScalarType", bootstrapWkt),
|
|
38
|
+
LongType: infoToSymbol("LongType", bootstrapWkt),
|
|
38
39
|
MethodKind: infoToSymbol("MethodKind", bootstrapWkt),
|
|
39
40
|
MethodIdempotency: infoToSymbol("MethodIdempotency", bootstrapWkt),
|
|
40
41
|
IMessageTypeRegistry: infoToSymbol("IMessageTypeRegistry", bootstrapWkt),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DescEnum, DescEnumValue, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, ScalarType } from "@bufbuild/protobuf";
|
|
1
|
+
import { DescEnum, DescEnumValue, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, LongType, ScalarType } from "@bufbuild/protobuf";
|
|
2
2
|
import type { GeneratedFile, Printable } from "./generated-file.js";
|
|
3
3
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
4
4
|
export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
|
|
@@ -12,7 +12,7 @@ export declare function getFieldTyping(field: DescField, file: GeneratedFile): {
|
|
|
12
12
|
typing: Printable;
|
|
13
13
|
optional: boolean;
|
|
14
14
|
};
|
|
15
|
-
export declare function scalarTypeScriptType(type: ScalarType): Printable;
|
|
15
|
+
export declare function scalarTypeScriptType(type: ScalarType, longType: LongType): Printable;
|
|
16
16
|
export declare function literalString(value: string): string;
|
|
17
17
|
export declare function getFieldExplicitDefaultValue(field: DescField, protoInt64Symbol: ImportSymbol): Printable | undefined;
|
|
18
18
|
export declare function getFieldIntrinsicDefaultValue(field: DescField): {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import { codegenInfo, ScalarType, } from "@bufbuild/protobuf";
|
|
14
|
+
import { codegenInfo, LongType, ScalarType, } from "@bufbuild/protobuf";
|
|
15
15
|
const { localName, getUnwrappedFieldType, scalarDefaultValue } = codegenInfo;
|
|
16
16
|
export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
|
|
17
17
|
const builder = [];
|
|
@@ -132,13 +132,13 @@ export function getFieldTyping(field, file) {
|
|
|
132
132
|
let optional = false;
|
|
133
133
|
switch (field.fieldKind) {
|
|
134
134
|
case "scalar":
|
|
135
|
-
typing.push(scalarTypeScriptType(field.scalar));
|
|
135
|
+
typing.push(scalarTypeScriptType(field.scalar, field.longType));
|
|
136
136
|
optional = field.optional;
|
|
137
137
|
break;
|
|
138
138
|
case "message": {
|
|
139
139
|
const baseType = getUnwrappedFieldType(field);
|
|
140
140
|
if (baseType !== undefined) {
|
|
141
|
-
typing.push(scalarTypeScriptType(baseType));
|
|
141
|
+
typing.push(scalarTypeScriptType(baseType, LongType.BIGINT));
|
|
142
142
|
}
|
|
143
143
|
else {
|
|
144
144
|
typing.push(file.import(field.message).toTypeOnly());
|
|
@@ -167,7 +167,7 @@ export function getFieldTyping(field, file) {
|
|
|
167
167
|
let valueType;
|
|
168
168
|
switch (field.mapValue.kind) {
|
|
169
169
|
case "scalar":
|
|
170
|
-
valueType = scalarTypeScriptType(field.mapValue.scalar);
|
|
170
|
+
valueType = scalarTypeScriptType(field.mapValue.scalar, LongType.BIGINT);
|
|
171
171
|
break;
|
|
172
172
|
case "message":
|
|
173
173
|
valueType = file.import(field.mapValue.message).toTypeOnly();
|
|
@@ -187,7 +187,7 @@ export function getFieldTyping(field, file) {
|
|
|
187
187
|
}
|
|
188
188
|
return { typing, optional };
|
|
189
189
|
}
|
|
190
|
-
export function scalarTypeScriptType(type) {
|
|
190
|
+
export function scalarTypeScriptType(type, longType) {
|
|
191
191
|
switch (type) {
|
|
192
192
|
case ScalarType.STRING:
|
|
193
193
|
return "string";
|
|
@@ -198,6 +198,9 @@ export function scalarTypeScriptType(type) {
|
|
|
198
198
|
case ScalarType.FIXED64:
|
|
199
199
|
case ScalarType.SINT64:
|
|
200
200
|
case ScalarType.INT64:
|
|
201
|
+
if (longType === LongType.STRING) {
|
|
202
|
+
return "string";
|
|
203
|
+
}
|
|
201
204
|
return "bigint";
|
|
202
205
|
case ScalarType.BYTES:
|
|
203
206
|
return "Uint8Array";
|
|
@@ -309,7 +312,10 @@ export function getFieldIntrinsicDefaultValue(field) {
|
|
|
309
312
|
}
|
|
310
313
|
else {
|
|
311
314
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
312
|
-
defaultValue = scalarDefaultValue(field.scalar);
|
|
315
|
+
defaultValue = scalarDefaultValue(field.scalar, field.longType);
|
|
316
|
+
if (typeof defaultValue === "string") {
|
|
317
|
+
defaultValue = literalString(defaultValue);
|
|
318
|
+
}
|
|
313
319
|
}
|
|
314
320
|
}
|
|
315
321
|
break;
|
|
@@ -32,6 +32,7 @@ export function createRuntimeImports(bootstrapWkt) {
|
|
|
32
32
|
protoDouble: infoToSymbol("protoDouble", bootstrapWkt),
|
|
33
33
|
protoInt64: infoToSymbol("protoInt64", bootstrapWkt),
|
|
34
34
|
ScalarType: infoToSymbol("ScalarType", bootstrapWkt),
|
|
35
|
+
LongType: infoToSymbol("LongType", bootstrapWkt),
|
|
35
36
|
MethodKind: infoToSymbol("MethodKind", bootstrapWkt),
|
|
36
37
|
MethodIdempotency: infoToSymbol("MethodIdempotency", bootstrapWkt),
|
|
37
38
|
IMessageTypeRegistry: infoToSymbol("IMessageTypeRegistry", bootstrapWkt),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoplugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "Helps to create your own Protocol Buffers code generators.",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@bufbuild/protobuf": "1.
|
|
42
|
+
"@bufbuild/protobuf": "1.4.0",
|
|
43
43
|
"@typescript/vfs": "^1.4.0",
|
|
44
44
|
"typescript": "4.5.2"
|
|
45
45
|
},
|