@bufbuild/protobuf 0.0.1-alpha.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 +6 -0
- package/dist/cjs/binary-encoding.js +434 -0
- package/dist/cjs/binary-format.js +2 -0
- package/dist/cjs/descriptor-registry.js +518 -0
- package/dist/cjs/descriptor-set.js +557 -0
- package/dist/cjs/enum.js +2 -0
- package/dist/cjs/field-list.js +2 -0
- package/dist/cjs/field.js +40 -0
- package/dist/cjs/google/protobuf/any_pb.js +280 -0
- package/dist/cjs/google/protobuf/api_pb.js +383 -0
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +334 -0
- package/dist/cjs/google/protobuf/descriptor_pb.js +2311 -0
- package/dist/cjs/google/protobuf/duration_pb.js +201 -0
- package/dist/cjs/google/protobuf/empty_pb.js +72 -0
- package/dist/cjs/google/protobuf/field_mask_pb.js +347 -0
- package/dist/cjs/google/protobuf/source_context_pb.js +74 -0
- package/dist/cjs/google/protobuf/struct_pb.js +288 -0
- package/dist/cjs/google/protobuf/timestamp_pb.js +271 -0
- package/dist/cjs/google/protobuf/type_pb.js +613 -0
- package/dist/cjs/google/protobuf/wrappers_pb.js +658 -0
- package/dist/cjs/google/varint.js +280 -0
- package/dist/cjs/index.js +148 -0
- package/dist/cjs/json-format.js +2 -0
- package/dist/cjs/message-type.js +2 -0
- package/dist/cjs/message.js +98 -0
- package/dist/cjs/private/assert.js +52 -0
- package/dist/cjs/private/base64.js +118 -0
- package/dist/cjs/private/binary-format-common.js +253 -0
- package/dist/cjs/private/binary-format-proto2.js +120 -0
- package/dist/cjs/private/binary-format-proto3.js +102 -0
- package/dist/cjs/private/enum.js +70 -0
- package/dist/cjs/private/field-list.js +62 -0
- package/dist/cjs/private/field-wrapper.js +25 -0
- package/dist/cjs/private/field.js +34 -0
- package/dist/cjs/private/json-format-common.js +482 -0
- package/dist/cjs/private/json-format-proto2.js +100 -0
- package/dist/cjs/private/json-format-proto3.js +103 -0
- package/dist/cjs/private/message-type.js +37 -0
- package/dist/cjs/private/names.js +101 -0
- package/dist/cjs/private/options-map.js +2 -0
- package/dist/cjs/private/proto-runtime.js +24 -0
- package/dist/cjs/private/scalars.js +138 -0
- package/dist/cjs/private/util-common.js +229 -0
- package/dist/cjs/private/util.js +2 -0
- package/dist/cjs/proto-int64.js +121 -0
- package/dist/cjs/proto2.js +86 -0
- package/dist/cjs/proto3.js +99 -0
- package/dist/cjs/service-type.js +43 -0
- package/dist/cjs/type-registry.js +42 -0
- package/dist/esm/binary-encoding.js +434 -0
- package/dist/esm/binary-format.js +1 -0
- package/dist/esm/descriptor-registry.js +521 -0
- package/dist/esm/descriptor-set.js +517 -0
- package/dist/esm/enum.js +1 -0
- package/dist/esm/field-list.js +1 -0
- package/dist/esm/field.js +37 -0
- package/dist/esm/google/protobuf/any_pb.js +276 -0
- package/dist/esm/google/protobuf/api_pb.js +350 -0
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +318 -0
- package/dist/esm/google/protobuf/descriptor_pb.js +2213 -0
- package/dist/esm/google/protobuf/duration_pb.js +197 -0
- package/dist/esm/google/protobuf/empty_pb.js +68 -0
- package/dist/esm/google/protobuf/field_mask_pb.js +343 -0
- package/dist/esm/google/protobuf/source_context_pb.js +70 -0
- package/dist/esm/google/protobuf/struct_pb.js +282 -0
- package/dist/esm/google/protobuf/timestamp_pb.js +267 -0
- package/dist/esm/google/protobuf/type_pb.js +569 -0
- package/dist/esm/google/protobuf/wrappers_pb.js +574 -0
- package/dist/esm/google/varint.js +265 -0
- package/dist/esm/index.js +24 -0
- package/dist/esm/json-format.js +1 -0
- package/dist/esm/message-type.js +1 -0
- package/dist/esm/message.js +94 -0
- package/dist/esm/private/assert.js +41 -0
- package/dist/esm/private/base64.js +113 -0
- package/dist/esm/private/binary-format-common.js +243 -0
- package/dist/esm/private/binary-format-proto2.js +87 -0
- package/dist/esm/private/binary-format-proto3.js +74 -0
- package/dist/esm/private/enum.js +64 -0
- package/dist/esm/private/field-list.js +58 -0
- package/dist/esm/private/field-wrapper.js +20 -0
- package/dist/esm/private/field.js +27 -0
- package/dist/esm/private/json-format-common.js +473 -0
- package/dist/esm/private/json-format-proto2.js +90 -0
- package/dist/esm/private/json-format-proto3.js +89 -0
- package/dist/esm/private/message-type.js +33 -0
- package/dist/esm/private/names.js +90 -0
- package/dist/esm/private/options-map.js +1 -0
- package/dist/esm/private/proto-runtime.js +15 -0
- package/dist/esm/private/scalars.js +129 -0
- package/dist/esm/private/util-common.js +207 -0
- package/dist/esm/private/util.js +1 -0
- package/dist/esm/proto-int64.js +118 -0
- package/dist/esm/proto2.js +77 -0
- package/dist/esm/proto3.js +90 -0
- package/dist/esm/service-type.js +37 -0
- package/dist/esm/type-registry.js +38 -0
- package/dist/types/binary-encoding.d.ts +421 -0
- package/dist/types/binary-format.d.ts +109 -0
- package/dist/types/descriptor-registry.d.ts +42 -0
- package/dist/types/descriptor-set.d.ts +171 -0
- package/dist/types/enum.d.ts +31 -0
- package/dist/types/field-list.d.ts +27 -0
- package/dist/types/field.d.ts +295 -0
- package/dist/types/google/protobuf/any_pb.d.ts +167 -0
- package/dist/types/google/protobuf/api_pb.d.ts +296 -0
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +294 -0
- package/dist/types/google/protobuf/descriptor_pb.d.ts +1959 -0
- package/dist/types/google/protobuf/duration_pb.d.ts +117 -0
- package/dist/types/google/protobuf/empty_pb.d.ts +44 -0
- package/dist/types/google/protobuf/field_mask_pb.d.ts +243 -0
- package/dist/types/google/protobuf/source_context_pb.d.ts +44 -0
- package/dist/types/google/protobuf/struct_pb.d.ts +205 -0
- package/dist/types/google/protobuf/timestamp_pb.d.ts +151 -0
- package/dist/types/google/protobuf/type_pb.d.ts +482 -0
- package/dist/types/google/protobuf/wrappers_pb.d.ts +379 -0
- package/dist/types/google/varint.d.ts +65 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/json-format.d.ts +129 -0
- package/dist/types/message-type.d.ts +58 -0
- package/dist/types/message.d.ts +124 -0
- package/dist/types/private/assert.d.ts +19 -0
- package/dist/types/private/base64.d.ts +18 -0
- package/dist/types/private/binary-format-common.d.ts +38 -0
- package/dist/types/private/binary-format-proto2.d.ts +2 -0
- package/dist/types/private/binary-format-proto3.d.ts +2 -0
- package/dist/types/private/enum.d.ts +29 -0
- package/dist/types/private/field-list.d.ts +25 -0
- package/dist/types/private/field-wrapper.d.ts +27 -0
- package/dist/types/private/field.d.ts +15 -0
- package/dist/types/private/json-format-common.d.ts +30 -0
- package/dist/types/private/json-format-proto2.d.ts +2 -0
- package/dist/types/private/json-format-proto3.d.ts +2 -0
- package/dist/types/private/message-type.d.ts +15 -0
- package/dist/types/private/names.d.ts +19 -0
- package/dist/types/private/options-map.d.ts +7 -0
- package/dist/types/private/proto-runtime.d.ts +55 -0
- package/dist/types/private/scalars.d.ts +33 -0
- package/dist/types/private/util-common.d.ts +5 -0
- package/dist/types/private/util.d.ts +55 -0
- package/dist/types/proto-int64.d.ts +94 -0
- package/dist/types/proto2.d.ts +4 -0
- package/dist/types/proto3.d.ts +4 -0
- package/dist/types/service-type.d.ts +118 -0
- package/dist/types/type-registry.d.ts +37 -0
- package/package.json +31 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeUtilCommon = void 0;
|
|
4
|
+
const enum_js_1 = require("./enum.js");
|
|
5
|
+
const field_js_1 = require("../field.js");
|
|
6
|
+
const scalars_js_1 = require("./scalars.js");
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument,no-case-declarations */
|
|
8
|
+
function makeUtilCommon() {
|
|
9
|
+
return {
|
|
10
|
+
setEnumType: enum_js_1.setEnumType,
|
|
11
|
+
initPartial(source, target) {
|
|
12
|
+
if (source === undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const type = target.getType();
|
|
16
|
+
for (const member of type.fields.byMember()) {
|
|
17
|
+
const localName = member.localName,
|
|
18
|
+
t = target,
|
|
19
|
+
s = source;
|
|
20
|
+
if (s[localName] === undefined) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
switch (member.kind) {
|
|
24
|
+
case "oneof":
|
|
25
|
+
const sk = s[localName].case;
|
|
26
|
+
if (sk === undefined) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const sourceField = member.findField(sk);
|
|
30
|
+
let val = s[localName].value;
|
|
31
|
+
if (
|
|
32
|
+
sourceField &&
|
|
33
|
+
sourceField.kind == "message" &&
|
|
34
|
+
!(val instanceof sourceField.T)
|
|
35
|
+
) {
|
|
36
|
+
val = new sourceField.T(val);
|
|
37
|
+
}
|
|
38
|
+
t[localName] = { case: sk, value: val };
|
|
39
|
+
break;
|
|
40
|
+
case "scalar":
|
|
41
|
+
case "enum":
|
|
42
|
+
t[localName] = s[localName];
|
|
43
|
+
break;
|
|
44
|
+
case "map":
|
|
45
|
+
switch (member.V.kind) {
|
|
46
|
+
case "scalar":
|
|
47
|
+
case "enum":
|
|
48
|
+
Object.assign(t[localName], s[localName]);
|
|
49
|
+
break;
|
|
50
|
+
case "message":
|
|
51
|
+
const messageType = member.V.T;
|
|
52
|
+
for (const k of Object.keys(s[localName])) {
|
|
53
|
+
let val = s[localName][k];
|
|
54
|
+
if (!messageType.fieldWrapper) {
|
|
55
|
+
// We only take partial input for messages that are not a wrapper type.
|
|
56
|
+
// For those messages, we recursively normalize the partial input.
|
|
57
|
+
val = new messageType(val);
|
|
58
|
+
}
|
|
59
|
+
t[localName][k] = val;
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case "message":
|
|
65
|
+
const mt = member.T;
|
|
66
|
+
if (member.repeated) {
|
|
67
|
+
t[localName] = s[localName].map((val) =>
|
|
68
|
+
val instanceof mt ? val : new mt(val)
|
|
69
|
+
);
|
|
70
|
+
} else if (s[localName] !== undefined) {
|
|
71
|
+
const val = s[localName];
|
|
72
|
+
if (mt.fieldWrapper) {
|
|
73
|
+
t[localName] = val;
|
|
74
|
+
} else {
|
|
75
|
+
t[localName] = val instanceof mt ? mt : new mt(val);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
equals(type, a, b) {
|
|
83
|
+
if (a === b) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (!a || !b) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return type.fields.byMember().every((m) => {
|
|
90
|
+
const va = a[m.localName];
|
|
91
|
+
const vb = b[m.localName];
|
|
92
|
+
if (m.repeated) {
|
|
93
|
+
if (va.length !== vb.length) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- repeated fields are never "map"
|
|
97
|
+
switch (m.kind) {
|
|
98
|
+
case "message":
|
|
99
|
+
return va.every((a, i) => m.T.equals(a, vb[i]));
|
|
100
|
+
case "scalar":
|
|
101
|
+
return va.every((a, i) =>
|
|
102
|
+
(0, scalars_js_1.scalarEquals)(m.T, a, vb[i])
|
|
103
|
+
);
|
|
104
|
+
case "enum":
|
|
105
|
+
return va.every((a, i) =>
|
|
106
|
+
(0, scalars_js_1.scalarEquals)(
|
|
107
|
+
field_js_1.ScalarType.INT32,
|
|
108
|
+
a,
|
|
109
|
+
vb[i]
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
throw new Error(`repeated cannot contain ${m.kind}`);
|
|
114
|
+
}
|
|
115
|
+
switch (m.kind) {
|
|
116
|
+
case "message":
|
|
117
|
+
return m.T.equals(va, vb);
|
|
118
|
+
case "enum":
|
|
119
|
+
return (0, scalars_js_1.scalarEquals)(
|
|
120
|
+
field_js_1.ScalarType.INT32,
|
|
121
|
+
va,
|
|
122
|
+
vb
|
|
123
|
+
);
|
|
124
|
+
case "scalar":
|
|
125
|
+
return (0, scalars_js_1.scalarEquals)(m.T, va, vb);
|
|
126
|
+
case "oneof":
|
|
127
|
+
if (va.case !== vb.case) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const k = va.case,
|
|
131
|
+
s = m.findField(k);
|
|
132
|
+
if (s === undefined) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- oneof fields are never "map"
|
|
136
|
+
switch (s.kind) {
|
|
137
|
+
case "message":
|
|
138
|
+
return s.T.equals(va[k], vb[k]);
|
|
139
|
+
case "enum":
|
|
140
|
+
return (0, scalars_js_1.scalarEquals)(
|
|
141
|
+
field_js_1.ScalarType.INT32,
|
|
142
|
+
va,
|
|
143
|
+
vb
|
|
144
|
+
);
|
|
145
|
+
case "scalar":
|
|
146
|
+
return (0, scalars_js_1.scalarEquals)(s.T, va, vb);
|
|
147
|
+
}
|
|
148
|
+
throw new Error(`oneof cannot contain ${s.kind}`);
|
|
149
|
+
case "map":
|
|
150
|
+
const keys = Object.keys(va);
|
|
151
|
+
if (keys.some((k) => vb[k] === undefined)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
switch (m.V.kind) {
|
|
155
|
+
case "message":
|
|
156
|
+
const messageType = m.V.T;
|
|
157
|
+
return keys.every((k) => messageType.equals(va[k], vb[k]));
|
|
158
|
+
case "enum":
|
|
159
|
+
return keys.every((k) =>
|
|
160
|
+
(0, scalars_js_1.scalarEquals)(
|
|
161
|
+
field_js_1.ScalarType.INT32,
|
|
162
|
+
va[k],
|
|
163
|
+
vb[k]
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
case "scalar":
|
|
167
|
+
const scalarType = m.V.T;
|
|
168
|
+
return keys.every((k) =>
|
|
169
|
+
(0, scalars_js_1.scalarEquals)(scalarType, va[k], vb[k])
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
clone(message) {
|
|
177
|
+
const type = message.getType(),
|
|
178
|
+
target = new type(),
|
|
179
|
+
any = target;
|
|
180
|
+
for (const member of type.fields.byMember()) {
|
|
181
|
+
const source = message[member.localName];
|
|
182
|
+
let copy;
|
|
183
|
+
if (member.repeated) {
|
|
184
|
+
copy = source.map((e) => cloneSingularField(member, e));
|
|
185
|
+
} else if (member.kind == "map") {
|
|
186
|
+
copy = any[member.localName];
|
|
187
|
+
for (const [key, v] of Object.entries(source)) {
|
|
188
|
+
copy[key] = cloneSingularField(member.V, v);
|
|
189
|
+
}
|
|
190
|
+
} else if (member.kind == "oneof") {
|
|
191
|
+
const f = member.findField(source.case);
|
|
192
|
+
copy = f
|
|
193
|
+
? { case: source.case, value: cloneSingularField(f, source.value) }
|
|
194
|
+
: { case: undefined };
|
|
195
|
+
} else {
|
|
196
|
+
copy = cloneSingularField(member, source);
|
|
197
|
+
}
|
|
198
|
+
any[member.localName] = copy;
|
|
199
|
+
}
|
|
200
|
+
return target;
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
exports.makeUtilCommon = makeUtilCommon;
|
|
205
|
+
// clone a single field value - i.e. the element type of repeated fields, the value type of maps
|
|
206
|
+
function cloneSingularField(field, value) {
|
|
207
|
+
if (value === undefined) {
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- unmatched "map" is unsupported
|
|
211
|
+
switch (field.kind) {
|
|
212
|
+
case "enum":
|
|
213
|
+
return value;
|
|
214
|
+
case "scalar":
|
|
215
|
+
if (field.T === field_js_1.ScalarType.BYTES) {
|
|
216
|
+
const c = new Uint8Array(value.byteLength);
|
|
217
|
+
c.set(value);
|
|
218
|
+
return c;
|
|
219
|
+
}
|
|
220
|
+
return value;
|
|
221
|
+
case "message":
|
|
222
|
+
if (field.T.fieldWrapper) {
|
|
223
|
+
return field.T.fieldWrapper.unwrapField(
|
|
224
|
+
field.T.fieldWrapper.wrapField(value).clone()
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return value.clone();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.protoInt64 = void 0;
|
|
4
|
+
const varint_js_1 = require("./google/varint.js");
|
|
5
|
+
function makeInt64Support() {
|
|
6
|
+
const dv = new DataView(new ArrayBuffer(8));
|
|
7
|
+
// note that Safari 14 implements BigInt, but not the DataView methods
|
|
8
|
+
const ok =
|
|
9
|
+
globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
|
|
10
|
+
typeof dv.getBigInt64 === "function" &&
|
|
11
|
+
typeof dv.getBigUint64 === "function" &&
|
|
12
|
+
typeof dv.setBigInt64 === "function" &&
|
|
13
|
+
typeof dv.setBigUint64 === "function";
|
|
14
|
+
if (ok) {
|
|
15
|
+
const MIN = BigInt("-9223372036854775808"),
|
|
16
|
+
MAX = BigInt("9223372036854775807"),
|
|
17
|
+
UMIN = BigInt("0"),
|
|
18
|
+
UMAX = BigInt("18446744073709551615");
|
|
19
|
+
return {
|
|
20
|
+
zero: BigInt(0),
|
|
21
|
+
supported: true,
|
|
22
|
+
parse(value) {
|
|
23
|
+
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
24
|
+
if (bi > MAX || bi < MIN) {
|
|
25
|
+
throw new Error(`int64 invalid: ${value}`);
|
|
26
|
+
}
|
|
27
|
+
return bi;
|
|
28
|
+
},
|
|
29
|
+
uParse(value) {
|
|
30
|
+
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
31
|
+
if (bi > UMAX || bi < UMIN) {
|
|
32
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
33
|
+
}
|
|
34
|
+
return bi;
|
|
35
|
+
},
|
|
36
|
+
enc(value) {
|
|
37
|
+
dv.setBigInt64(0, this.parse(value), true);
|
|
38
|
+
return {
|
|
39
|
+
lo: dv.getInt32(0, true),
|
|
40
|
+
hi: dv.getInt32(4, true),
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
uEnc(value) {
|
|
44
|
+
dv.setBigInt64(0, this.uParse(value), true);
|
|
45
|
+
return {
|
|
46
|
+
lo: dv.getInt32(0, true),
|
|
47
|
+
hi: dv.getInt32(4, true),
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
dec(lo, hi) {
|
|
51
|
+
dv.setInt32(0, lo, true);
|
|
52
|
+
dv.setInt32(4, hi, true);
|
|
53
|
+
return dv.getBigInt64(0, true);
|
|
54
|
+
},
|
|
55
|
+
uDec(lo, hi) {
|
|
56
|
+
dv.setInt32(0, lo, true);
|
|
57
|
+
dv.setInt32(4, hi, true);
|
|
58
|
+
return dv.getBigUint64(0, true);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
zero: "0",
|
|
64
|
+
supported: false,
|
|
65
|
+
parse(value) {
|
|
66
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
67
|
+
throw new Error(`int64 invalid: ${value}`);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
},
|
|
71
|
+
uParse(value) {
|
|
72
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
73
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
},
|
|
77
|
+
enc(value) {
|
|
78
|
+
if (typeof value == "string") {
|
|
79
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
80
|
+
throw new Error(`int64 invalid: ${value}`);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
value = value.toString(10);
|
|
84
|
+
}
|
|
85
|
+
const [, lo, hi] = (0, varint_js_1.int64fromString)(value);
|
|
86
|
+
return { lo, hi };
|
|
87
|
+
},
|
|
88
|
+
uEnc(value) {
|
|
89
|
+
if (typeof value == "string") {
|
|
90
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
91
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
value = value.toString(10);
|
|
95
|
+
}
|
|
96
|
+
const [minus, lo, hi] = (0, varint_js_1.int64fromString)(value);
|
|
97
|
+
if (minus) {
|
|
98
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
99
|
+
}
|
|
100
|
+
return { lo, hi };
|
|
101
|
+
},
|
|
102
|
+
dec(lo, hi) {
|
|
103
|
+
const minus = (hi & 0x80000000) !== 0;
|
|
104
|
+
if (minus) {
|
|
105
|
+
// negate
|
|
106
|
+
hi = ~hi;
|
|
107
|
+
if (lo) {
|
|
108
|
+
lo = ~lo + 1;
|
|
109
|
+
} else {
|
|
110
|
+
hi += 1;
|
|
111
|
+
}
|
|
112
|
+
return "-" + (0, varint_js_1.int64toString)(lo, hi);
|
|
113
|
+
}
|
|
114
|
+
return (0, varint_js_1.int64toString)(lo, hi);
|
|
115
|
+
},
|
|
116
|
+
uDec(lo, hi) {
|
|
117
|
+
return (0, varint_js_1.int64toString)(lo, hi);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.protoInt64 = makeInt64Support();
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proto2 = void 0;
|
|
4
|
+
const proto_runtime_js_1 = require("./private/proto-runtime.js");
|
|
5
|
+
const binary_format_proto2_js_1 = require("./private/binary-format-proto2.js");
|
|
6
|
+
const util_common_js_1 = require("./private/util-common.js");
|
|
7
|
+
const field_list_js_1 = require("./private/field-list.js");
|
|
8
|
+
const field_js_1 = require("./private/field.js");
|
|
9
|
+
const names_js_1 = require("./private/names.js");
|
|
10
|
+
const json_format_proto2_js_1 = require("./private/json-format-proto2.js");
|
|
11
|
+
/**
|
|
12
|
+
* Provides functionality for messages defined with the proto2 syntax.
|
|
13
|
+
*/
|
|
14
|
+
exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)(
|
|
15
|
+
"proto2",
|
|
16
|
+
(0, json_format_proto2_js_1.makeJsonFormatProto2)(),
|
|
17
|
+
(0, binary_format_proto2_js_1.makeBinaryFormatProto2)(),
|
|
18
|
+
{
|
|
19
|
+
...(0, util_common_js_1.makeUtilCommon)(),
|
|
20
|
+
newFieldList(fields) {
|
|
21
|
+
return new field_list_js_1.InternalFieldList(
|
|
22
|
+
fields,
|
|
23
|
+
normalizeFieldInfosProto2
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
initFields(target) {
|
|
27
|
+
for (const member of target.getType().fields.byMember()) {
|
|
28
|
+
const name = member.localName,
|
|
29
|
+
t = target;
|
|
30
|
+
if (member.repeated) {
|
|
31
|
+
t[name] = [];
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
switch (member.kind) {
|
|
35
|
+
case "oneof":
|
|
36
|
+
t[name] = { case: undefined };
|
|
37
|
+
break;
|
|
38
|
+
case "map":
|
|
39
|
+
t[name] = {};
|
|
40
|
+
break;
|
|
41
|
+
case "scalar":
|
|
42
|
+
case "enum":
|
|
43
|
+
case "message":
|
|
44
|
+
// In contrast to proto3, enum and scalar fields have no intrinsic default value,
|
|
45
|
+
// only an optional explicit default value.
|
|
46
|
+
// Unlike proto3 intrinsic default values, proto2 explicit default values are not
|
|
47
|
+
// set on construction, because they are not omitted on the wire. If we did set
|
|
48
|
+
// default values on construction, a deserialize-serialize round-trip would add
|
|
49
|
+
// fields to a message.
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
57
|
+
function normalizeFieldInfosProto2(fieldInfos) {
|
|
58
|
+
const r = [];
|
|
59
|
+
let o;
|
|
60
|
+
for (const field of typeof fieldInfos == "function"
|
|
61
|
+
? fieldInfos()
|
|
62
|
+
: fieldInfos) {
|
|
63
|
+
const f = field;
|
|
64
|
+
f.localName = (0, names_js_1.makeFieldName)(
|
|
65
|
+
field.name,
|
|
66
|
+
field.oneof !== undefined
|
|
67
|
+
);
|
|
68
|
+
f.jsonName = field.jsonName ?? (0, names_js_1.makeJsonName)(field.name);
|
|
69
|
+
f.repeated = field.repeated ?? false;
|
|
70
|
+
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
71
|
+
f.packed = field.packed ?? false;
|
|
72
|
+
// We do not surface options at this time
|
|
73
|
+
// f.options = field.options ?? emptyReadonlyObject;
|
|
74
|
+
if (field.oneof !== undefined) {
|
|
75
|
+
const ooname =
|
|
76
|
+
typeof field.oneof == "string" ? field.oneof : field.oneof.name;
|
|
77
|
+
if (!o || o.name != ooname) {
|
|
78
|
+
o = new field_js_1.InternalOneofInfo(ooname);
|
|
79
|
+
}
|
|
80
|
+
f.oneof = o;
|
|
81
|
+
o.addField(f);
|
|
82
|
+
}
|
|
83
|
+
r.push(f);
|
|
84
|
+
}
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proto3 = void 0;
|
|
4
|
+
const proto_runtime_js_1 = require("./private/proto-runtime.js");
|
|
5
|
+
const binary_format_proto3_js_1 = require("./private/binary-format-proto3.js");
|
|
6
|
+
const json_format_proto3_js_1 = require("./private/json-format-proto3.js");
|
|
7
|
+
const util_common_js_1 = require("./private/util-common.js");
|
|
8
|
+
const field_list_js_1 = require("./private/field-list.js");
|
|
9
|
+
const scalars_js_1 = require("./private/scalars.js");
|
|
10
|
+
const field_js_1 = require("./field.js");
|
|
11
|
+
const field_js_2 = require("./private/field.js");
|
|
12
|
+
const names_js_1 = require("./private/names.js");
|
|
13
|
+
/**
|
|
14
|
+
* Provides functionality for messages defined with the proto3 syntax.
|
|
15
|
+
*/
|
|
16
|
+
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)(
|
|
17
|
+
"proto3",
|
|
18
|
+
(0, json_format_proto3_js_1.makeJsonFormatProto3)(),
|
|
19
|
+
(0, binary_format_proto3_js_1.makeBinaryFormatProto3)(),
|
|
20
|
+
{
|
|
21
|
+
...(0, util_common_js_1.makeUtilCommon)(),
|
|
22
|
+
newFieldList(fields) {
|
|
23
|
+
return new field_list_js_1.InternalFieldList(
|
|
24
|
+
fields,
|
|
25
|
+
normalizeFieldInfosProto3
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
initFields(target) {
|
|
29
|
+
for (const member of target.getType().fields.byMember()) {
|
|
30
|
+
if (member.opt) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const name = member.localName,
|
|
34
|
+
t = target;
|
|
35
|
+
if (member.repeated) {
|
|
36
|
+
t[name] = [];
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
switch (member.kind) {
|
|
40
|
+
case "oneof":
|
|
41
|
+
t[name] = { case: undefined };
|
|
42
|
+
break;
|
|
43
|
+
case "enum":
|
|
44
|
+
t[name] = 0;
|
|
45
|
+
break;
|
|
46
|
+
case "map":
|
|
47
|
+
t[name] = {};
|
|
48
|
+
break;
|
|
49
|
+
case "scalar":
|
|
50
|
+
t[name] = (0, scalars_js_1.scalarDefaultValue)(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
51
|
+
break;
|
|
52
|
+
case "message":
|
|
53
|
+
// message fields are always optional in proto3
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
61
|
+
function normalizeFieldInfosProto3(fieldInfos) {
|
|
62
|
+
const r = [];
|
|
63
|
+
let o;
|
|
64
|
+
for (const field of typeof fieldInfos == "function"
|
|
65
|
+
? fieldInfos()
|
|
66
|
+
: fieldInfos) {
|
|
67
|
+
const f = field;
|
|
68
|
+
f.localName = (0, names_js_1.makeFieldName)(
|
|
69
|
+
field.name,
|
|
70
|
+
field.oneof !== undefined
|
|
71
|
+
);
|
|
72
|
+
f.jsonName = field.jsonName ?? (0, names_js_1.makeJsonName)(field.name);
|
|
73
|
+
f.repeated = field.repeated ?? false;
|
|
74
|
+
// From the proto3 language guide:
|
|
75
|
+
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
76
|
+
// This information is incomplete - according to the conformance tests, BOOL
|
|
77
|
+
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
78
|
+
// are not packed by default, which makes sense because they are length-delimited.
|
|
79
|
+
f.packed =
|
|
80
|
+
field.packed ??
|
|
81
|
+
(field.kind == "enum" ||
|
|
82
|
+
(field.kind == "scalar" &&
|
|
83
|
+
field.T != field_js_1.ScalarType.BYTES &&
|
|
84
|
+
field.T != field_js_1.ScalarType.STRING));
|
|
85
|
+
// We do not surface options at this time
|
|
86
|
+
// f.options = field.options ?? emptyReadonlyObject;
|
|
87
|
+
if (field.oneof !== undefined) {
|
|
88
|
+
const ooname =
|
|
89
|
+
typeof field.oneof == "string" ? field.oneof : field.oneof.name;
|
|
90
|
+
if (!o || o.name != ooname) {
|
|
91
|
+
o = new field_js_2.InternalOneofInfo(ooname);
|
|
92
|
+
}
|
|
93
|
+
f.oneof = o;
|
|
94
|
+
o.addField(f);
|
|
95
|
+
}
|
|
96
|
+
r.push(f);
|
|
97
|
+
}
|
|
98
|
+
return r;
|
|
99
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MethodIdempotency = exports.MethodKind = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* MethodKind represents the four method types that can be declared in
|
|
6
|
+
* protobuf with the `stream` keyword:
|
|
7
|
+
*
|
|
8
|
+
* 1. Unary: rpc (Input) returns (Output)
|
|
9
|
+
* 2. ServerStreaming: rpc (Input) returns (stream Output)
|
|
10
|
+
* 3. ClientStreaming: rpc (stream Input) returns (Output)
|
|
11
|
+
* 4. BiDiStreaming: rpc (stream Input) returns (stream Output)
|
|
12
|
+
*/
|
|
13
|
+
var MethodKind;
|
|
14
|
+
(function (MethodKind) {
|
|
15
|
+
MethodKind[(MethodKind["Unary"] = 0)] = "Unary";
|
|
16
|
+
MethodKind[(MethodKind["ServerStreaming"] = 1)] = "ServerStreaming";
|
|
17
|
+
MethodKind[(MethodKind["ClientStreaming"] = 2)] = "ClientStreaming";
|
|
18
|
+
MethodKind[(MethodKind["BiDiStreaming"] = 3)] = "BiDiStreaming";
|
|
19
|
+
})((MethodKind = exports.MethodKind || (exports.MethodKind = {})));
|
|
20
|
+
/**
|
|
21
|
+
* Is this method side-effect-free (or safe in HTTP parlance), or just
|
|
22
|
+
* idempotent, or neither? HTTP based RPC implementation may choose GET verb
|
|
23
|
+
* for safe methods, and PUT verb for idempotent methods instead of the
|
|
24
|
+
* default POST.
|
|
25
|
+
*
|
|
26
|
+
* This enum matches the protobuf enum google.protobuf.MethodOptions.IdempotencyLevel,
|
|
27
|
+
* defined in the well-known type google/protobuf/descriptor.proto, but
|
|
28
|
+
* drops UNKNOWN.
|
|
29
|
+
*/
|
|
30
|
+
var MethodIdempotency;
|
|
31
|
+
(function (MethodIdempotency) {
|
|
32
|
+
/**
|
|
33
|
+
* Idempotent, no side effects.
|
|
34
|
+
*/
|
|
35
|
+
MethodIdempotency[(MethodIdempotency["NoSideEffects"] = 1)] = "NoSideEffects";
|
|
36
|
+
/**
|
|
37
|
+
* Idempotent, but may have side effects.
|
|
38
|
+
*/
|
|
39
|
+
MethodIdempotency[(MethodIdempotency["Idempotent"] = 2)] = "Idempotent";
|
|
40
|
+
})(
|
|
41
|
+
(MethodIdempotency =
|
|
42
|
+
exports.MethodIdempotency || (exports.MethodIdempotency = {}))
|
|
43
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TypeRegistry is a basic type registry
|
|
6
|
+
*/
|
|
7
|
+
class TypeRegistry {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.messages = {};
|
|
10
|
+
this.enums = {};
|
|
11
|
+
this.services = {};
|
|
12
|
+
}
|
|
13
|
+
findMessage(typeName) {
|
|
14
|
+
return this.messages[typeName];
|
|
15
|
+
}
|
|
16
|
+
findEnum(typeName) {
|
|
17
|
+
return this.enums[typeName];
|
|
18
|
+
}
|
|
19
|
+
findService(typeName) {
|
|
20
|
+
return this.services[typeName];
|
|
21
|
+
}
|
|
22
|
+
add(type) {
|
|
23
|
+
if ("fields" in type) {
|
|
24
|
+
this.messages[type.typeName] = type;
|
|
25
|
+
} else if ("methods" in type) {
|
|
26
|
+
this.services[type.typeName] = type;
|
|
27
|
+
} else {
|
|
28
|
+
this.enums[type.typeName] = type;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
static fromIterable(types) {
|
|
32
|
+
const r = new TypeRegistry();
|
|
33
|
+
for (const t of types) {
|
|
34
|
+
r.add(t);
|
|
35
|
+
}
|
|
36
|
+
return r;
|
|
37
|
+
}
|
|
38
|
+
static fromTypes(...types) {
|
|
39
|
+
return TypeRegistry.fromIterable(types);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.TypeRegistry = TypeRegistry;
|