@bufbuild/protobuf 0.0.9 → 0.1.1
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/README.md +1 -1
- package/dist/cjs/create-registry-from-desc.js +10 -116
- package/dist/cjs/create-registry.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/empty_pb.js +0 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/varint.js +85 -37
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/private/binary-format-proto2.js +1 -1
- package/dist/cjs/private/json-format-common.js +6 -6
- package/dist/cjs/proto-int64.js +23 -40
- package/dist/esm/create-registry-from-desc.js +9 -114
- package/dist/esm/create-registry.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/empty_pb.js +0 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/varint.js +81 -34
- package/dist/esm/index.js +0 -3
- package/dist/esm/private/binary-format-proto2.js +1 -1
- package/dist/esm/private/json-format-common.js +6 -6
- package/dist/esm/proto-int64.js +24 -41
- package/dist/types/create-registry-from-desc.d.ts +0 -34
- package/dist/types/create-registry.d.ts +1 -1
- package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
- package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
- package/dist/types/google/varint.d.ts +21 -9
- package/dist/types/index.d.ts +0 -3
- package/dist/types/json-format.d.ts +1 -1
- package/dist/types/message.d.ts +3 -1
- package/dist/types/proto-int64.d.ts +14 -13
- package/package.json +5 -8
- package/dist/cjs/legacy-descriptor-registry.js +0 -468
- package/dist/cjs/legacy-descriptor-set.js +0 -453
- package/dist/cjs/legacy-type-registry.js +0 -104
- package/dist/esm/legacy-descriptor-registry.js +0 -464
- package/dist/esm/legacy-descriptor-set.js +0 -449
- package/dist/esm/legacy-type-registry.js +0 -100
- package/dist/types/legacy-descriptor-registry.d.ts +0 -45
- package/dist/types/legacy-descriptor-set.d.ts +0 -152
- package/dist/types/legacy-type-registry.d.ts +0 -44
|
@@ -21,20 +21,32 @@ export declare function varint64write(lo: number, hi: number, bytes: number[]):
|
|
|
21
21
|
/**
|
|
22
22
|
* Parse decimal string of 64 bit integer value as two JS numbers.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
24
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
25
|
+
*
|
|
26
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
27
|
+
*/
|
|
28
|
+
export declare function int64FromString(dec: string): {
|
|
29
|
+
lo: number;
|
|
30
|
+
hi: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Losslessly converts a 64-bit signed integer in 32:32 split representation
|
|
34
|
+
* into a decimal string.
|
|
35
|
+
*
|
|
36
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
28
37
|
*
|
|
29
|
-
*
|
|
38
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
30
39
|
*/
|
|
31
|
-
export declare function
|
|
40
|
+
export declare function int64ToString(lo: number, hi: number): string;
|
|
32
41
|
/**
|
|
33
|
-
*
|
|
42
|
+
* Losslessly converts a 64-bit unsigned integer in 32:32 split representation
|
|
43
|
+
* into a decimal string.
|
|
44
|
+
*
|
|
45
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
34
46
|
*
|
|
35
|
-
*
|
|
47
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
36
48
|
*/
|
|
37
|
-
export declare function
|
|
49
|
+
export declare function uInt64ToString(lo: number, hi: number): string;
|
|
38
50
|
/**
|
|
39
51
|
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
|
|
40
52
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -20,9 +20,6 @@ export { createDescriptorSet } from "./create-descriptor-set.js";
|
|
|
20
20
|
export { IMessageTypeRegistry } from "./type-registry.js";
|
|
21
21
|
export { createRegistry } from "./create-registry.js";
|
|
22
22
|
export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
|
|
23
|
-
export { LegacyDescriptorRegistry } from "./legacy-descriptor-registry.js";
|
|
24
|
-
export { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
|
|
25
|
-
export { TypeRegistry } from "./legacy-type-registry.js";
|
|
26
23
|
export * from "./google/protobuf/compiler/plugin_pb.js";
|
|
27
24
|
export * from "./google/protobuf/api_pb.js";
|
|
28
25
|
export * from "./google/protobuf/any_pb.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Message } from "./message.js";
|
|
2
2
|
import type { MessageType } from "./message-type.js";
|
|
3
3
|
import type { ScalarType } from "./field.js";
|
|
4
|
-
import type { IMessageTypeRegistry } from "./type-registry";
|
|
4
|
+
import type { IMessageTypeRegistry } from "./type-registry.js";
|
|
5
5
|
/**
|
|
6
6
|
* JsonFormat is the contract for serializing messages to and from JSON.
|
|
7
7
|
* Implementations may be specific to a proto syntax, and can be reflection
|
package/dist/types/message.d.ts
CHANGED
|
@@ -67,7 +67,9 @@ export declare class Message<T extends Message<T> = AnyMessage> {
|
|
|
67
67
|
* PlainMessage<T> strips all methods from a message, leaving only fields
|
|
68
68
|
* and oneof groups.
|
|
69
69
|
*/
|
|
70
|
-
export declare type PlainMessage<T extends Message> =
|
|
70
|
+
export declare type PlainMessage<T extends Message> = {
|
|
71
|
+
[P in keyof T as T[P] extends Function ? never : P]: T[P];
|
|
72
|
+
};
|
|
71
73
|
/**
|
|
72
74
|
* PartialMessage<T> constructs a type from a message. The resulting type
|
|
73
75
|
* only contains the protobuf field members of the message, and all of them
|
|
@@ -29,22 +29,23 @@
|
|
|
29
29
|
* ```
|
|
30
30
|
*
|
|
31
31
|
* If you need to manipulate 64-bit integral values that are outside the
|
|
32
|
-
* range of safe representation as Number,
|
|
33
|
-
*
|
|
32
|
+
* range of safe representation as a JavaScript Number, we recommend you
|
|
33
|
+
* use a third party library, for example the npm package "long":
|
|
34
34
|
*
|
|
35
35
|
* ```ts
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* }
|
|
43
|
-
* message.int64Field = protoInt64.dec(t.lo, t.hi);
|
|
44
|
-
* ```
|
|
36
|
+
* // convert the field value to a Long
|
|
37
|
+
* const bits = protoInt64.enc(message.int64Field);
|
|
38
|
+
* const longValue = Long.fromBits(bits.lo, bits.hi);
|
|
39
|
+
*
|
|
40
|
+
* // perform arithmetic
|
|
41
|
+
* const longResult = longValue.subtract(1);
|
|
45
42
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
43
|
+
* // set the result in the field
|
|
44
|
+
* message.int64Field = protoInt64.dec(longResult.low, longResult.high);
|
|
45
|
+
*
|
|
46
|
+
* // Assuming int64Field contains 9223372036854775807:
|
|
47
|
+
* console.log(message.int64Field); // 9223372036854775806
|
|
48
|
+
* ```
|
|
48
49
|
*/
|
|
49
50
|
interface Int64Support {
|
|
50
51
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
|
|
6
6
|
"repository": {
|
|
@@ -12,19 +12,16 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*",
|
|
14
14
|
"build": "npm run build:cjs && npm run build:esm+types",
|
|
15
|
-
"build:cjs": "
|
|
16
|
-
"build:esm+types": "
|
|
15
|
+
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
16
|
+
"build:esm+types": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
|
|
17
17
|
},
|
|
18
|
-
"main": "./dist/
|
|
18
|
+
"main": "./dist/cjs/index.js",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"exports": {
|
|
22
22
|
"import": "./dist/esm/index.js",
|
|
23
23
|
"require": "./dist/cjs/index.js",
|
|
24
|
-
"
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"typescript": "^4.7.4"
|
|
24
|
+
"types": "./dist/types/index.d.ts"
|
|
28
25
|
},
|
|
29
26
|
"files": [
|
|
30
27
|
"dist/**/"
|
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
3
|
-
//
|
|
4
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
// you may not use this file except in compliance with the License.
|
|
6
|
-
// You may obtain a copy of the License at
|
|
7
|
-
//
|
|
8
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
//
|
|
10
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
// See the License for the specific language governing permissions and
|
|
14
|
-
// limitations under the License.
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.LegacyDescriptorRegistry = void 0;
|
|
17
|
-
const descriptor_pb_js_1 = require("./google/protobuf/descriptor_pb.js");
|
|
18
|
-
const assert_js_1 = require("./private/assert.js");
|
|
19
|
-
const proto3_js_1 = require("./proto3.js");
|
|
20
|
-
const proto2_js_1 = require("./proto2.js");
|
|
21
|
-
const field_js_1 = require("./field.js");
|
|
22
|
-
const legacy_descriptor_set_js_1 = require("./legacy-descriptor-set.js");
|
|
23
|
-
const proto_int64_js_1 = require("./proto-int64.js");
|
|
24
|
-
const timestamp_pb_js_1 = require("./google/protobuf/timestamp_pb.js");
|
|
25
|
-
const duration_pb_js_1 = require("./google/protobuf/duration_pb.js");
|
|
26
|
-
const any_pb_js_1 = require("./google/protobuf/any_pb.js");
|
|
27
|
-
const empty_pb_js_1 = require("./google/protobuf/empty_pb.js");
|
|
28
|
-
const field_mask_pb_js_1 = require("./google/protobuf/field_mask_pb.js");
|
|
29
|
-
const struct_pb_js_1 = require("./google/protobuf/struct_pb.js");
|
|
30
|
-
const enum_js_1 = require("./private/enum.js");
|
|
31
|
-
const wrappers_pb_js_1 = require("./google/protobuf/wrappers_pb.js");
|
|
32
|
-
// well-known message types with specialized JSON representation
|
|
33
|
-
const wkMessages = [
|
|
34
|
-
any_pb_js_1.Any,
|
|
35
|
-
duration_pb_js_1.Duration,
|
|
36
|
-
empty_pb_js_1.Empty,
|
|
37
|
-
field_mask_pb_js_1.FieldMask,
|
|
38
|
-
struct_pb_js_1.Struct,
|
|
39
|
-
struct_pb_js_1.Value,
|
|
40
|
-
struct_pb_js_1.ListValue,
|
|
41
|
-
timestamp_pb_js_1.Timestamp,
|
|
42
|
-
duration_pb_js_1.Duration,
|
|
43
|
-
wrappers_pb_js_1.DoubleValue,
|
|
44
|
-
wrappers_pb_js_1.FloatValue,
|
|
45
|
-
wrappers_pb_js_1.Int64Value,
|
|
46
|
-
wrappers_pb_js_1.Int32Value,
|
|
47
|
-
wrappers_pb_js_1.UInt32Value,
|
|
48
|
-
wrappers_pb_js_1.UInt64Value,
|
|
49
|
-
wrappers_pb_js_1.BoolValue,
|
|
50
|
-
wrappers_pb_js_1.StringValue,
|
|
51
|
-
wrappers_pb_js_1.BytesValue,
|
|
52
|
-
];
|
|
53
|
-
// well-known enum types with specialized JSON representation
|
|
54
|
-
const wkEnums = [(0, enum_js_1.getEnumType)(struct_pb_js_1.NullValue)];
|
|
55
|
-
/**
|
|
56
|
-
* LegacyDescriptorRegistry is a type registry that dynamically creates types
|
|
57
|
-
* from a set of google.protobuf.FileDescriptorProto.
|
|
58
|
-
*
|
|
59
|
-
* By default, all well-known types with a specialized JSON representation
|
|
60
|
-
* are replaced with their generated counterpart in this package.
|
|
61
|
-
*
|
|
62
|
-
* @deprecated
|
|
63
|
-
*/
|
|
64
|
-
class LegacyDescriptorRegistry {
|
|
65
|
-
constructor(descriptorSet, replaceWkt = true) {
|
|
66
|
-
this.enums = {};
|
|
67
|
-
this.messages = {};
|
|
68
|
-
this.services = {};
|
|
69
|
-
this.ds = descriptorSet !== null && descriptorSet !== void 0 ? descriptorSet : new legacy_descriptor_set_js_1.LegacyDescriptorSet();
|
|
70
|
-
if (replaceWkt) {
|
|
71
|
-
for (const mt of wkMessages) {
|
|
72
|
-
this.messages["." + mt.typeName] = mt;
|
|
73
|
-
}
|
|
74
|
-
for (const et of wkEnums) {
|
|
75
|
-
this.enums["." + et.typeName] = et;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Conveniently create a DescriptorRegistry from a FileDescriptorSet
|
|
81
|
-
* instance or a FileDescriptorSet in binary format.
|
|
82
|
-
*/
|
|
83
|
-
static fromFileDescriptorSet(bytesOrSet) {
|
|
84
|
-
const set = bytesOrSet instanceof Uint8Array
|
|
85
|
-
? descriptor_pb_js_1.FileDescriptorSet.fromBinary(bytesOrSet)
|
|
86
|
-
: new descriptor_pb_js_1.FileDescriptorSet(bytesOrSet);
|
|
87
|
-
const dr = new LegacyDescriptorRegistry();
|
|
88
|
-
dr.add(...set.file);
|
|
89
|
-
return dr;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* May raise an error on invalid descriptors.
|
|
93
|
-
*/
|
|
94
|
-
add(...files) {
|
|
95
|
-
this.ds.add(...files);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* May raise an error on invalid descriptors.
|
|
99
|
-
*/
|
|
100
|
-
findEnum(typeName) {
|
|
101
|
-
const protoTypeName = "." + typeName;
|
|
102
|
-
const existing = this.enums[protoTypeName];
|
|
103
|
-
if (existing) {
|
|
104
|
-
return existing;
|
|
105
|
-
}
|
|
106
|
-
const raw = this.ds.enums[protoTypeName];
|
|
107
|
-
if (!raw) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
const runtime = raw.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
|
|
111
|
-
const type = runtime.makeEnumType(typeName, raw.values.map((u) => ({
|
|
112
|
-
no: u.number,
|
|
113
|
-
name: u.name,
|
|
114
|
-
localName: u.name,
|
|
115
|
-
})), {});
|
|
116
|
-
this.enums[protoTypeName] = type;
|
|
117
|
-
return type;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* May raise an error on invalid descriptors.
|
|
121
|
-
*/
|
|
122
|
-
findMessage(typeName) {
|
|
123
|
-
const protoTypeName = "." + typeName;
|
|
124
|
-
const existing = this.messages[protoTypeName];
|
|
125
|
-
if (existing) {
|
|
126
|
-
return existing;
|
|
127
|
-
}
|
|
128
|
-
const raw = this.ds.messages[protoTypeName];
|
|
129
|
-
if (!raw) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
const runtime = raw.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
|
|
133
|
-
const fields = [];
|
|
134
|
-
const type = runtime.makeMessageType(typeName, () => fields, {
|
|
135
|
-
localName: makeTypeLocalName(raw),
|
|
136
|
-
});
|
|
137
|
-
this.messages[protoTypeName] = type;
|
|
138
|
-
for (const field of raw.fields.map((f) => f.resolve(this.ds))) {
|
|
139
|
-
const fieldInfo = makeFieldInfo(field, this);
|
|
140
|
-
fields.push(fieldInfo);
|
|
141
|
-
}
|
|
142
|
-
return type;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* May raise an error on invalid descriptors.
|
|
146
|
-
*/
|
|
147
|
-
findService(typeName) {
|
|
148
|
-
const protoTypeName = "." + typeName;
|
|
149
|
-
const existing = this.services[protoTypeName];
|
|
150
|
-
if (existing) {
|
|
151
|
-
return existing;
|
|
152
|
-
}
|
|
153
|
-
const raw = this.ds.services[protoTypeName];
|
|
154
|
-
if (!raw) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
const methods = {};
|
|
158
|
-
for (const u of raw.methods) {
|
|
159
|
-
const it = this.findMessage(u.inputTypeName);
|
|
160
|
-
const ot = this.findMessage(u.outputTypeName);
|
|
161
|
-
(0, assert_js_1.assert)(it, `message "${u.inputTypeName}" for ${u.toString()} not found`);
|
|
162
|
-
(0, assert_js_1.assert)(ot, `output message "${u.outputTypeName}" for ${u.toString()} not found`);
|
|
163
|
-
const m = {
|
|
164
|
-
name: u.name,
|
|
165
|
-
localName: localMethodName(u.name),
|
|
166
|
-
I: it,
|
|
167
|
-
O: ot,
|
|
168
|
-
kind: u.kind,
|
|
169
|
-
idempotency: u.idempotency,
|
|
170
|
-
options: {},
|
|
171
|
-
};
|
|
172
|
-
methods[m.localName] = m;
|
|
173
|
-
}
|
|
174
|
-
return (this.services[protoTypeName] = {
|
|
175
|
-
typeName: raw.typeName,
|
|
176
|
-
methods,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.LegacyDescriptorRegistry = LegacyDescriptorRegistry;
|
|
181
|
-
function localMethodName(protoName) {
|
|
182
|
-
if (protoName.length == 0) {
|
|
183
|
-
return protoName;
|
|
184
|
-
}
|
|
185
|
-
return protoName[0].toLowerCase() + protoName.substring(1);
|
|
186
|
-
}
|
|
187
|
-
function makeTypeLocalName(type) {
|
|
188
|
-
var _a;
|
|
189
|
-
const typeName = type.typeName;
|
|
190
|
-
const packagePrefix = ((_a = type.file.proto.package) !== null && _a !== void 0 ? _a : "") + ".";
|
|
191
|
-
if (!typeName.startsWith(packagePrefix)) {
|
|
192
|
-
return type.name;
|
|
193
|
-
}
|
|
194
|
-
return typeName.substring(packagePrefix.length).split(".").join("_");
|
|
195
|
-
}
|
|
196
|
-
function makeFieldInfo(field, resolver) {
|
|
197
|
-
if (field.map !== undefined) {
|
|
198
|
-
return makeMapFieldInfo(field, resolver);
|
|
199
|
-
}
|
|
200
|
-
if (field.message) {
|
|
201
|
-
return makeMessageFieldInfo(field, resolver);
|
|
202
|
-
}
|
|
203
|
-
const fi = field.enum
|
|
204
|
-
? makeEnumFieldInfo(field, resolver)
|
|
205
|
-
: makeScalarFieldInfo(field);
|
|
206
|
-
fi.default = parseDefaultValue(field);
|
|
207
|
-
return fi;
|
|
208
|
-
}
|
|
209
|
-
function makeMapFieldInfo(field, resolver) {
|
|
210
|
-
const base = {
|
|
211
|
-
kind: "map",
|
|
212
|
-
name: field.name,
|
|
213
|
-
no: field.number,
|
|
214
|
-
K: field.map.key,
|
|
215
|
-
};
|
|
216
|
-
if (field.map.value.message) {
|
|
217
|
-
const messageType = resolver.findMessage(field.map.value.message.typeName);
|
|
218
|
-
(0, assert_js_1.assert)(messageType, `message "${field.map.value.message.typeName}" for ${field.toString()} not found`);
|
|
219
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
220
|
-
kind: "message",
|
|
221
|
-
T: messageType,
|
|
222
|
-
} });
|
|
223
|
-
}
|
|
224
|
-
if (field.map.value.enum) {
|
|
225
|
-
const enumType = resolver.findEnum(field.map.value.enum.typeName);
|
|
226
|
-
(0, assert_js_1.assert)(enumType, `enum "${field.map.value.enum.typeName}" for ${field.toString()} not found`);
|
|
227
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
228
|
-
kind: "enum",
|
|
229
|
-
T: enumType,
|
|
230
|
-
} });
|
|
231
|
-
}
|
|
232
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
233
|
-
kind: "scalar",
|
|
234
|
-
T: field.map.value.scalarType,
|
|
235
|
-
} });
|
|
236
|
-
}
|
|
237
|
-
function makeScalarFieldInfo(field) {
|
|
238
|
-
const base = {
|
|
239
|
-
no: field.number,
|
|
240
|
-
name: field.name,
|
|
241
|
-
kind: "scalar",
|
|
242
|
-
T: field.scalarType,
|
|
243
|
-
};
|
|
244
|
-
if (field.repeated) {
|
|
245
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined, T: field.scalarType });
|
|
246
|
-
}
|
|
247
|
-
if (field.oneof) {
|
|
248
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
249
|
-
}
|
|
250
|
-
if (field.optional) {
|
|
251
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
252
|
-
}
|
|
253
|
-
return base;
|
|
254
|
-
}
|
|
255
|
-
function makeMessageFieldInfo(field, resolver) {
|
|
256
|
-
const messageType = resolver.findMessage(field.message.typeName);
|
|
257
|
-
(0, assert_js_1.assert)(messageType, `message "${field.message.typeName}" for ${field.toString()} not found`);
|
|
258
|
-
const base = {
|
|
259
|
-
no: field.number,
|
|
260
|
-
name: field.name,
|
|
261
|
-
kind: "message",
|
|
262
|
-
T: messageType,
|
|
263
|
-
};
|
|
264
|
-
if (field.repeated) {
|
|
265
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
266
|
-
}
|
|
267
|
-
if (field.oneof) {
|
|
268
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
269
|
-
}
|
|
270
|
-
if (field.optional) {
|
|
271
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
272
|
-
}
|
|
273
|
-
return base;
|
|
274
|
-
}
|
|
275
|
-
function makeEnumFieldInfo(field, resolver) {
|
|
276
|
-
const enumType = resolver.findEnum(field.enum.typeName);
|
|
277
|
-
(0, assert_js_1.assert)(enumType, `message "${field.enum.typeName}" for ${field.toString()} not found`);
|
|
278
|
-
const base = {
|
|
279
|
-
no: field.number,
|
|
280
|
-
name: field.name,
|
|
281
|
-
kind: "enum",
|
|
282
|
-
T: enumType,
|
|
283
|
-
};
|
|
284
|
-
if (field.repeated) {
|
|
285
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
286
|
-
}
|
|
287
|
-
if (field.oneof) {
|
|
288
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
289
|
-
}
|
|
290
|
-
if (field.optional) {
|
|
291
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
292
|
-
}
|
|
293
|
-
return base;
|
|
294
|
-
}
|
|
295
|
-
function parseDefaultValue(field) {
|
|
296
|
-
const d = field.proto.defaultValue;
|
|
297
|
-
if (d === undefined) {
|
|
298
|
-
return undefined;
|
|
299
|
-
}
|
|
300
|
-
if (field.enum) {
|
|
301
|
-
const enumValue = field.enum.values.find((v) => v.name === d);
|
|
302
|
-
(0, assert_js_1.assert)(enumValue, `cannot parse ${field.toString()} default value: ${d}`);
|
|
303
|
-
return enumValue.number;
|
|
304
|
-
}
|
|
305
|
-
if (field.scalarType) {
|
|
306
|
-
switch (field.scalarType) {
|
|
307
|
-
case field_js_1.ScalarType.STRING:
|
|
308
|
-
return d;
|
|
309
|
-
case field_js_1.ScalarType.BYTES: {
|
|
310
|
-
const u = unescapeBytesDefaultValue(d);
|
|
311
|
-
if (u === false) {
|
|
312
|
-
throw new Error(`cannot parse ${field.toString()} default value: ${d}`);
|
|
313
|
-
}
|
|
314
|
-
return u;
|
|
315
|
-
}
|
|
316
|
-
case field_js_1.ScalarType.INT64:
|
|
317
|
-
case field_js_1.ScalarType.SFIXED64:
|
|
318
|
-
case field_js_1.ScalarType.SINT64:
|
|
319
|
-
return proto_int64_js_1.protoInt64.parse(d);
|
|
320
|
-
case field_js_1.ScalarType.UINT64:
|
|
321
|
-
case field_js_1.ScalarType.FIXED64:
|
|
322
|
-
return proto_int64_js_1.protoInt64.uParse(d);
|
|
323
|
-
case field_js_1.ScalarType.DOUBLE:
|
|
324
|
-
case field_js_1.ScalarType.FLOAT:
|
|
325
|
-
switch (d) {
|
|
326
|
-
case "inf":
|
|
327
|
-
return Number.POSITIVE_INFINITY;
|
|
328
|
-
case "-inf":
|
|
329
|
-
return Number.NEGATIVE_INFINITY;
|
|
330
|
-
case "nan":
|
|
331
|
-
return Number.NaN;
|
|
332
|
-
default:
|
|
333
|
-
return parseFloat(d);
|
|
334
|
-
}
|
|
335
|
-
case field_js_1.ScalarType.BOOL:
|
|
336
|
-
return Boolean(d);
|
|
337
|
-
case field_js_1.ScalarType.INT32:
|
|
338
|
-
case field_js_1.ScalarType.UINT32:
|
|
339
|
-
case field_js_1.ScalarType.SINT32:
|
|
340
|
-
case field_js_1.ScalarType.FIXED32:
|
|
341
|
-
case field_js_1.ScalarType.SFIXED32:
|
|
342
|
-
return parseInt(d, 10);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
347
|
-
// unescapeBytesDefaultValue parses a text-encoded default value (proto2) of a
|
|
348
|
-
// BYTES field.
|
|
349
|
-
function unescapeBytesDefaultValue(str) {
|
|
350
|
-
const b = [];
|
|
351
|
-
const input = {
|
|
352
|
-
tail: str,
|
|
353
|
-
c: "",
|
|
354
|
-
next() {
|
|
355
|
-
if (this.tail.length == 0) {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
this.c = this.tail[0];
|
|
359
|
-
this.tail = this.tail.substring(1);
|
|
360
|
-
return true;
|
|
361
|
-
},
|
|
362
|
-
take(n) {
|
|
363
|
-
if (this.tail.length >= n) {
|
|
364
|
-
const r = this.tail.substring(0, n);
|
|
365
|
-
this.tail = this.tail.substring(n);
|
|
366
|
-
return r;
|
|
367
|
-
}
|
|
368
|
-
return false;
|
|
369
|
-
},
|
|
370
|
-
};
|
|
371
|
-
while (input.next()) {
|
|
372
|
-
switch (input.c) {
|
|
373
|
-
case "\\":
|
|
374
|
-
if (input.next()) {
|
|
375
|
-
switch (input.c) {
|
|
376
|
-
case "\\":
|
|
377
|
-
b.push(input.c.charCodeAt(0));
|
|
378
|
-
break;
|
|
379
|
-
case "b":
|
|
380
|
-
b.push(0x08);
|
|
381
|
-
break;
|
|
382
|
-
case "f":
|
|
383
|
-
b.push(0x0c);
|
|
384
|
-
break;
|
|
385
|
-
case "n":
|
|
386
|
-
b.push(0x0a);
|
|
387
|
-
break;
|
|
388
|
-
case "r":
|
|
389
|
-
b.push(0x0d);
|
|
390
|
-
break;
|
|
391
|
-
case "t":
|
|
392
|
-
b.push(0x09);
|
|
393
|
-
break;
|
|
394
|
-
case "v":
|
|
395
|
-
b.push(0x0b);
|
|
396
|
-
break;
|
|
397
|
-
case "0":
|
|
398
|
-
case "1":
|
|
399
|
-
case "2":
|
|
400
|
-
case "3":
|
|
401
|
-
case "4":
|
|
402
|
-
case "5":
|
|
403
|
-
case "6":
|
|
404
|
-
case "7": {
|
|
405
|
-
const s = input.c;
|
|
406
|
-
const t = input.take(2);
|
|
407
|
-
if (t === false) {
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
const n = parseInt(s + t, 8);
|
|
411
|
-
if (isNaN(n)) {
|
|
412
|
-
return false;
|
|
413
|
-
}
|
|
414
|
-
b.push(n);
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
case "x": {
|
|
418
|
-
const s = input.c;
|
|
419
|
-
const t = input.take(2);
|
|
420
|
-
if (t === false) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
const n = parseInt(s + t, 16);
|
|
424
|
-
if (isNaN(n)) {
|
|
425
|
-
return false;
|
|
426
|
-
}
|
|
427
|
-
b.push(n);
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
case "u": {
|
|
431
|
-
const s = input.c;
|
|
432
|
-
const t = input.take(4);
|
|
433
|
-
if (t === false) {
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
const n = parseInt(s + t, 16);
|
|
437
|
-
if (isNaN(n)) {
|
|
438
|
-
return false;
|
|
439
|
-
}
|
|
440
|
-
const chunk = new Uint8Array(4);
|
|
441
|
-
const view = new DataView(chunk.buffer);
|
|
442
|
-
view.setInt32(0, n, true);
|
|
443
|
-
b.push(chunk[0], chunk[1], chunk[2], chunk[3]);
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
case "U": {
|
|
447
|
-
const s = input.c;
|
|
448
|
-
const t = input.take(8);
|
|
449
|
-
if (t === false) {
|
|
450
|
-
return false;
|
|
451
|
-
}
|
|
452
|
-
const tc = proto_int64_js_1.protoInt64.uEnc(s + t);
|
|
453
|
-
const chunk = new Uint8Array(8);
|
|
454
|
-
const view = new DataView(chunk.buffer);
|
|
455
|
-
view.setInt32(0, tc.lo, true);
|
|
456
|
-
view.setInt32(4, tc.hi, true);
|
|
457
|
-
b.push(chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], chunk[5], chunk[6], chunk[7]);
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
break;
|
|
463
|
-
default:
|
|
464
|
-
b.push(input.c.charCodeAt(0));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return new Uint8Array(b);
|
|
468
|
-
}
|