@openfeature/flagd-provider 0.7.4 → 0.7.6
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 +9 -6
- package/index.cjs +330 -3115
- package/index.js +190 -2978
- package/package.json +7 -5
- package/src/lib/configuration.d.ts +22 -0
- package/src/lib/constants.d.ts +5 -0
- package/src/lib/flagd-provider.d.ts +11 -1
- package/src/lib/service/grpc/service.d.ts +32 -3
- package/src/lib/service/service.d.ts +1 -0
- package/src/proto/ts/sync/v1/sync_service.client.d.ts +46 -0
- package/src/proto/ts/sync/v1/sync_service.d.ts +183 -0
package/index.cjs
CHANGED
|
@@ -5,8 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var grpc = require('@grpc/grpc-js');
|
|
6
6
|
var jsSdk = require('@openfeature/js-sdk');
|
|
7
7
|
var grpcTransport = require('@protobuf-ts/grpc-transport');
|
|
8
|
+
var LRU = require('lru-cache');
|
|
9
|
+
var runtime = require('@protobuf-ts/runtime');
|
|
8
10
|
var runtimeRpc = require('@protobuf-ts/runtime-rpc');
|
|
9
11
|
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
10
14
|
function _interopNamespace(e) {
|
|
11
15
|
if (e && e.__esModule) return e;
|
|
12
16
|
var n = Object.create(null);
|
|
@@ -26,11 +30,21 @@ function _interopNamespace(e) {
|
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
var grpc__namespace = /*#__PURE__*/_interopNamespace(grpc);
|
|
33
|
+
var LRU__default = /*#__PURE__*/_interopDefaultLegacy(LRU);
|
|
34
|
+
|
|
35
|
+
const BASE_EVENT_STREAM_RETRY_BACKOFF_MS = 1000;
|
|
36
|
+
const DEFAULT_MAX_EVENT_STREAM_RETRIES = 5;
|
|
37
|
+
const EVENT_CONFIGURATION_CHANGE = 'configuration_change';
|
|
38
|
+
const EVENT_PROVIDER_READY = 'provider_ready';
|
|
39
|
+
const DEFAULT_MAX_CACHE_SIZE = 1000;
|
|
29
40
|
|
|
30
41
|
const DEFAULT_CONFIG = {
|
|
31
42
|
host: 'localhost',
|
|
32
43
|
port: 8013,
|
|
33
44
|
tls: false,
|
|
45
|
+
cache: 'lru',
|
|
46
|
+
maxCacheSize: DEFAULT_MAX_CACHE_SIZE,
|
|
47
|
+
maxEventStreamRetries: DEFAULT_MAX_EVENT_STREAM_RETRIES,
|
|
34
48
|
};
|
|
35
49
|
var ENV_VAR;
|
|
36
50
|
(function (ENV_VAR) {
|
|
@@ -38,10 +52,13 @@ var ENV_VAR;
|
|
|
38
52
|
ENV_VAR["FLAGD_PORT"] = "FLAGD_PORT";
|
|
39
53
|
ENV_VAR["FLAGD_TLS"] = "FLAGD_TLS";
|
|
40
54
|
ENV_VAR["FLAGD_SOCKET_PATH"] = "FLAGD_SOCKET_PATH";
|
|
55
|
+
ENV_VAR["FLAGD_CACHE"] = "FLAGD_CACHE";
|
|
56
|
+
ENV_VAR["FLAGD_MAX_CACHE_SIZE"] = "FLAGD_MAX_CACHE_SIZE";
|
|
57
|
+
ENV_VAR["FLAGD_MAX_EVENT_STREAM_RETRIES"] = "FLAGD_MAX_EVENT_STREAM_RETRIES";
|
|
41
58
|
})(ENV_VAR || (ENV_VAR = {}));
|
|
42
59
|
const getEnvVarConfig = () => {
|
|
43
60
|
var _a;
|
|
44
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
61
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
45
62
|
host: process.env[ENV_VAR.FLAGD_HOST],
|
|
46
63
|
})), (Number(process.env[ENV_VAR.FLAGD_PORT]) && {
|
|
47
64
|
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
|
|
@@ -49,6 +66,12 @@ const getEnvVarConfig = () => {
|
|
|
49
66
|
tls: ((_a = process.env[ENV_VAR.FLAGD_TLS]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true',
|
|
50
67
|
})), (process.env[ENV_VAR.FLAGD_SOCKET_PATH] && {
|
|
51
68
|
socketPath: process.env[ENV_VAR.FLAGD_SOCKET_PATH],
|
|
69
|
+
})), ((process.env[ENV_VAR.FLAGD_CACHE] === 'lru' || process.env[ENV_VAR.FLAGD_CACHE] === 'disabled') && {
|
|
70
|
+
cache: process.env[ENV_VAR.FLAGD_CACHE],
|
|
71
|
+
})), (process.env[ENV_VAR.FLAGD_MAX_CACHE_SIZE] && {
|
|
72
|
+
maxCacheSize: Number(process.env[ENV_VAR.FLAGD_MAX_CACHE_SIZE]),
|
|
73
|
+
})), (process.env[ENV_VAR.FLAGD_MAX_EVENT_STREAM_RETRIES] && {
|
|
74
|
+
maxEventStreamRetries: Number(process.env[ENV_VAR.FLAGD_MAX_EVENT_STREAM_RETRIES]),
|
|
52
75
|
})));
|
|
53
76
|
};
|
|
54
77
|
function getConfig(options = {}) {
|
|
@@ -80,2928 +103,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
80
103
|
});
|
|
81
104
|
}
|
|
82
105
|
|
|
83
|
-
/**
|
|
84
|
-
* Get the type of a JSON value.
|
|
85
|
-
* Distinguishes between array, null and object.
|
|
86
|
-
*/
|
|
87
|
-
function typeofJsonValue(value) {
|
|
88
|
-
let t = typeof value;
|
|
89
|
-
if (t == "object") {
|
|
90
|
-
if (Array.isArray(value))
|
|
91
|
-
return "array";
|
|
92
|
-
if (value === null)
|
|
93
|
-
return "null";
|
|
94
|
-
}
|
|
95
|
-
return t;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Is this a JSON object (instead of an array or null)?
|
|
99
|
-
*/
|
|
100
|
-
function isJsonObject(value) {
|
|
101
|
-
return value !== null && typeof value == "object" && !Array.isArray(value);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// lookup table from base64 character to byte
|
|
105
|
-
let encTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
|
106
|
-
// lookup table from base64 character *code* to byte because lookup by number is fast
|
|
107
|
-
let decTable = [];
|
|
108
|
-
for (let i = 0; i < encTable.length; i++)
|
|
109
|
-
decTable[encTable[i].charCodeAt(0)] = i;
|
|
110
|
-
// support base64url variants
|
|
111
|
-
decTable["-".charCodeAt(0)] = encTable.indexOf("+");
|
|
112
|
-
decTable["_".charCodeAt(0)] = encTable.indexOf("/");
|
|
113
|
-
/**
|
|
114
|
-
* Decodes a base64 string to a byte array.
|
|
115
|
-
*
|
|
116
|
-
* - ignores white-space, including line breaks and tabs
|
|
117
|
-
* - allows inner padding (can decode concatenated base64 strings)
|
|
118
|
-
* - does not require padding
|
|
119
|
-
* - understands base64url encoding:
|
|
120
|
-
* "-" instead of "+",
|
|
121
|
-
* "_" instead of "/",
|
|
122
|
-
* no padding
|
|
123
|
-
*/
|
|
124
|
-
function base64decode(base64Str) {
|
|
125
|
-
// estimate byte size, not accounting for inner padding and whitespace
|
|
126
|
-
let es = base64Str.length * 3 / 4;
|
|
127
|
-
// if (es % 3 !== 0)
|
|
128
|
-
// throw new Error('invalid base64 string');
|
|
129
|
-
if (base64Str[base64Str.length - 2] == '=')
|
|
130
|
-
es -= 2;
|
|
131
|
-
else if (base64Str[base64Str.length - 1] == '=')
|
|
132
|
-
es -= 1;
|
|
133
|
-
let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
|
|
134
|
-
groupPos = 0, // position in base64 group
|
|
135
|
-
b, // current byte
|
|
136
|
-
p = 0 // previous byte
|
|
137
|
-
;
|
|
138
|
-
for (let i = 0; i < base64Str.length; i++) {
|
|
139
|
-
b = decTable[base64Str.charCodeAt(i)];
|
|
140
|
-
if (b === undefined) {
|
|
141
|
-
// noinspection FallThroughInSwitchStatementJS
|
|
142
|
-
switch (base64Str[i]) {
|
|
143
|
-
case '=':
|
|
144
|
-
groupPos = 0; // reset state when padding found
|
|
145
|
-
case '\n':
|
|
146
|
-
case '\r':
|
|
147
|
-
case '\t':
|
|
148
|
-
case ' ':
|
|
149
|
-
continue; // skip white-space, and padding
|
|
150
|
-
default:
|
|
151
|
-
throw Error(`invalid base64 string.`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
switch (groupPos) {
|
|
155
|
-
case 0:
|
|
156
|
-
p = b;
|
|
157
|
-
groupPos = 1;
|
|
158
|
-
break;
|
|
159
|
-
case 1:
|
|
160
|
-
bytes[bytePos++] = p << 2 | (b & 48) >> 4;
|
|
161
|
-
p = b;
|
|
162
|
-
groupPos = 2;
|
|
163
|
-
break;
|
|
164
|
-
case 2:
|
|
165
|
-
bytes[bytePos++] = (p & 15) << 4 | (b & 60) >> 2;
|
|
166
|
-
p = b;
|
|
167
|
-
groupPos = 3;
|
|
168
|
-
break;
|
|
169
|
-
case 3:
|
|
170
|
-
bytes[bytePos++] = (p & 3) << 6 | b;
|
|
171
|
-
groupPos = 0;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (groupPos == 1)
|
|
176
|
-
throw Error(`invalid base64 string.`);
|
|
177
|
-
return bytes.subarray(0, bytePos);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Encodes a byte array to a base64 string.
|
|
181
|
-
* Adds padding at the end.
|
|
182
|
-
* Does not insert newlines.
|
|
183
|
-
*/
|
|
184
|
-
function base64encode(bytes) {
|
|
185
|
-
let base64 = '', groupPos = 0, // position in base64 group
|
|
186
|
-
b, // current byte
|
|
187
|
-
p = 0; // carry over from previous byte
|
|
188
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
189
|
-
b = bytes[i];
|
|
190
|
-
switch (groupPos) {
|
|
191
|
-
case 0:
|
|
192
|
-
base64 += encTable[b >> 2];
|
|
193
|
-
p = (b & 3) << 4;
|
|
194
|
-
groupPos = 1;
|
|
195
|
-
break;
|
|
196
|
-
case 1:
|
|
197
|
-
base64 += encTable[p | b >> 4];
|
|
198
|
-
p = (b & 15) << 2;
|
|
199
|
-
groupPos = 2;
|
|
200
|
-
break;
|
|
201
|
-
case 2:
|
|
202
|
-
base64 += encTable[p | b >> 6];
|
|
203
|
-
base64 += encTable[b & 63];
|
|
204
|
-
groupPos = 0;
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
// padding required?
|
|
209
|
-
if (groupPos) {
|
|
210
|
-
base64 += encTable[p];
|
|
211
|
-
base64 += '=';
|
|
212
|
-
if (groupPos == 1)
|
|
213
|
-
base64 += '=';
|
|
214
|
-
}
|
|
215
|
-
return base64;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* This handler implements the default behaviour for unknown fields.
|
|
220
|
-
* When reading data, unknown fields are stored on the message, in a
|
|
221
|
-
* symbol property.
|
|
222
|
-
* When writing data, the symbol property is queried and unknown fields
|
|
223
|
-
* are serialized into the output again.
|
|
224
|
-
*/
|
|
225
|
-
var UnknownFieldHandler;
|
|
226
|
-
(function (UnknownFieldHandler) {
|
|
227
|
-
/**
|
|
228
|
-
* The symbol used to store unknown fields for a message.
|
|
229
|
-
* The property must conform to `UnknownFieldContainer`.
|
|
230
|
-
*/
|
|
231
|
-
UnknownFieldHandler.symbol = Symbol.for("protobuf-ts/unknown");
|
|
232
|
-
/**
|
|
233
|
-
* Store an unknown field during binary read directly on the message.
|
|
234
|
-
* This method is compatible with `BinaryReadOptions.readUnknownField`.
|
|
235
|
-
*/
|
|
236
|
-
UnknownFieldHandler.onRead = (typeName, message, fieldNo, wireType, data) => {
|
|
237
|
-
let container = is(message) ? message[UnknownFieldHandler.symbol] : message[UnknownFieldHandler.symbol] = [];
|
|
238
|
-
container.push({ no: fieldNo, wireType, data });
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Write unknown fields stored for the message to the writer.
|
|
242
|
-
* This method is compatible with `BinaryWriteOptions.writeUnknownFields`.
|
|
243
|
-
*/
|
|
244
|
-
UnknownFieldHandler.onWrite = (typeName, message, writer) => {
|
|
245
|
-
for (let { no, wireType, data } of UnknownFieldHandler.list(message))
|
|
246
|
-
writer.tag(no, wireType).raw(data);
|
|
247
|
-
};
|
|
248
|
-
/**
|
|
249
|
-
* List unknown fields stored for the message.
|
|
250
|
-
* Note that there may be multiples fields with the same number.
|
|
251
|
-
*/
|
|
252
|
-
UnknownFieldHandler.list = (message, fieldNo) => {
|
|
253
|
-
if (is(message)) {
|
|
254
|
-
let all = message[UnknownFieldHandler.symbol];
|
|
255
|
-
return fieldNo ? all.filter(uf => uf.no == fieldNo) : all;
|
|
256
|
-
}
|
|
257
|
-
return [];
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Returns the last unknown field by field number.
|
|
261
|
-
*/
|
|
262
|
-
UnknownFieldHandler.last = (message, fieldNo) => UnknownFieldHandler.list(message, fieldNo).slice(-1)[0];
|
|
263
|
-
const is = (message) => message && Array.isArray(message[UnknownFieldHandler.symbol]);
|
|
264
|
-
})(UnknownFieldHandler || (UnknownFieldHandler = {}));
|
|
265
|
-
/**
|
|
266
|
-
* Protobuf binary format wire types.
|
|
267
|
-
*
|
|
268
|
-
* A wire type provides just enough information to find the length of the
|
|
269
|
-
* following value.
|
|
270
|
-
*
|
|
271
|
-
* See https://developers.google.com/protocol-buffers/docs/encoding#structure
|
|
272
|
-
*/
|
|
273
|
-
var WireType;
|
|
274
|
-
(function (WireType) {
|
|
275
|
-
/**
|
|
276
|
-
* Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
|
|
277
|
-
*/
|
|
278
|
-
WireType[WireType["Varint"] = 0] = "Varint";
|
|
279
|
-
/**
|
|
280
|
-
* Used for fixed64, sfixed64, double.
|
|
281
|
-
* Always 8 bytes with little-endian byte order.
|
|
282
|
-
*/
|
|
283
|
-
WireType[WireType["Bit64"] = 1] = "Bit64";
|
|
284
|
-
/**
|
|
285
|
-
* Used for string, bytes, embedded messages, packed repeated fields
|
|
286
|
-
*
|
|
287
|
-
* Only repeated numeric types (types which use the varint, 32-bit,
|
|
288
|
-
* or 64-bit wire types) can be packed. In proto3, such fields are
|
|
289
|
-
* packed by default.
|
|
290
|
-
*/
|
|
291
|
-
WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
|
|
292
|
-
/**
|
|
293
|
-
* Used for groups
|
|
294
|
-
* @deprecated
|
|
295
|
-
*/
|
|
296
|
-
WireType[WireType["StartGroup"] = 3] = "StartGroup";
|
|
297
|
-
/**
|
|
298
|
-
* Used for groups
|
|
299
|
-
* @deprecated
|
|
300
|
-
*/
|
|
301
|
-
WireType[WireType["EndGroup"] = 4] = "EndGroup";
|
|
302
|
-
/**
|
|
303
|
-
* Used for fixed32, sfixed32, float.
|
|
304
|
-
* Always 4 bytes with little-endian byte order.
|
|
305
|
-
*/
|
|
306
|
-
WireType[WireType["Bit32"] = 5] = "Bit32";
|
|
307
|
-
})(WireType || (WireType = {}));
|
|
308
|
-
|
|
309
|
-
// Copyright 2008 Google Inc. All rights reserved.
|
|
310
|
-
//
|
|
311
|
-
// Redistribution and use in source and binary forms, with or without
|
|
312
|
-
// modification, are permitted provided that the following conditions are
|
|
313
|
-
// met:
|
|
314
|
-
//
|
|
315
|
-
// * Redistributions of source code must retain the above copyright
|
|
316
|
-
// notice, this list of conditions and the following disclaimer.
|
|
317
|
-
// * Redistributions in binary form must reproduce the above
|
|
318
|
-
// copyright notice, this list of conditions and the following disclaimer
|
|
319
|
-
// in the documentation and/or other materials provided with the
|
|
320
|
-
// distribution.
|
|
321
|
-
// * Neither the name of Google Inc. nor the names of its
|
|
322
|
-
// contributors may be used to endorse or promote products derived from
|
|
323
|
-
// this software without specific prior written permission.
|
|
324
|
-
//
|
|
325
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
326
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
327
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
328
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
329
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
330
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
331
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
332
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
333
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
334
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
335
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
336
|
-
//
|
|
337
|
-
// Code generated by the Protocol Buffer compiler is owned by the owner
|
|
338
|
-
// of the input file used when generating it. This code is not
|
|
339
|
-
// standalone and requires a support library to be linked with it. This
|
|
340
|
-
// support library is itself covered by the above license.
|
|
341
|
-
/**
|
|
342
|
-
* Read a 64 bit varint as two JS numbers.
|
|
343
|
-
*
|
|
344
|
-
* Returns tuple:
|
|
345
|
-
* [0]: low bits
|
|
346
|
-
* [0]: high bits
|
|
347
|
-
*
|
|
348
|
-
* Copyright 2008 Google Inc. All rights reserved.
|
|
349
|
-
*
|
|
350
|
-
* See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
|
|
351
|
-
*/
|
|
352
|
-
function varint64read() {
|
|
353
|
-
let lowBits = 0;
|
|
354
|
-
let highBits = 0;
|
|
355
|
-
for (let shift = 0; shift < 28; shift += 7) {
|
|
356
|
-
let b = this.buf[this.pos++];
|
|
357
|
-
lowBits |= (b & 0x7F) << shift;
|
|
358
|
-
if ((b & 0x80) == 0) {
|
|
359
|
-
this.assertBounds();
|
|
360
|
-
return [lowBits, highBits];
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
let middleByte = this.buf[this.pos++];
|
|
364
|
-
// last four bits of the first 32 bit number
|
|
365
|
-
lowBits |= (middleByte & 0x0F) << 28;
|
|
366
|
-
// 3 upper bits are part of the next 32 bit number
|
|
367
|
-
highBits = (middleByte & 0x70) >> 4;
|
|
368
|
-
if ((middleByte & 0x80) == 0) {
|
|
369
|
-
this.assertBounds();
|
|
370
|
-
return [lowBits, highBits];
|
|
371
|
-
}
|
|
372
|
-
for (let shift = 3; shift <= 31; shift += 7) {
|
|
373
|
-
let b = this.buf[this.pos++];
|
|
374
|
-
highBits |= (b & 0x7F) << shift;
|
|
375
|
-
if ((b & 0x80) == 0) {
|
|
376
|
-
this.assertBounds();
|
|
377
|
-
return [lowBits, highBits];
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
throw new Error('invalid varint');
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Write a 64 bit varint, given as two JS numbers, to the given bytes array.
|
|
384
|
-
*
|
|
385
|
-
* Copyright 2008 Google Inc. All rights reserved.
|
|
386
|
-
*
|
|
387
|
-
* See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
|
|
388
|
-
*/
|
|
389
|
-
function varint64write(lo, hi, bytes) {
|
|
390
|
-
for (let i = 0; i < 28; i = i + 7) {
|
|
391
|
-
const shift = lo >>> i;
|
|
392
|
-
const hasNext = !((shift >>> 7) == 0 && hi == 0);
|
|
393
|
-
const byte = (hasNext ? shift | 0x80 : shift) & 0xFF;
|
|
394
|
-
bytes.push(byte);
|
|
395
|
-
if (!hasNext) {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
const splitBits = ((lo >>> 28) & 0x0F) | ((hi & 0x07) << 4);
|
|
400
|
-
const hasMoreBits = !((hi >> 3) == 0);
|
|
401
|
-
bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xFF);
|
|
402
|
-
if (!hasMoreBits) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
for (let i = 3; i < 31; i = i + 7) {
|
|
406
|
-
const shift = hi >>> i;
|
|
407
|
-
const hasNext = !((shift >>> 7) == 0);
|
|
408
|
-
const byte = (hasNext ? shift | 0x80 : shift) & 0xFF;
|
|
409
|
-
bytes.push(byte);
|
|
410
|
-
if (!hasNext) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
bytes.push((hi >>> 31) & 0x01);
|
|
415
|
-
}
|
|
416
|
-
// constants for binary math
|
|
417
|
-
const TWO_PWR_32_DBL$1 = (1 << 16) * (1 << 16);
|
|
418
|
-
/**
|
|
419
|
-
* Parse decimal string of 64 bit integer value as two JS numbers.
|
|
420
|
-
*
|
|
421
|
-
* Returns tuple:
|
|
422
|
-
* [0]: minus sign?
|
|
423
|
-
* [1]: low bits
|
|
424
|
-
* [2]: high bits
|
|
425
|
-
*
|
|
426
|
-
* Copyright 2008 Google Inc.
|
|
427
|
-
*/
|
|
428
|
-
function int64fromString(dec) {
|
|
429
|
-
// Check for minus sign.
|
|
430
|
-
let minus = dec[0] == '-';
|
|
431
|
-
if (minus)
|
|
432
|
-
dec = dec.slice(1);
|
|
433
|
-
// Work 6 decimal digits at a time, acting like we're converting base 1e6
|
|
434
|
-
// digits to binary. This is safe to do with floating point math because
|
|
435
|
-
// Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
|
|
436
|
-
const base = 1e6;
|
|
437
|
-
let lowBits = 0;
|
|
438
|
-
let highBits = 0;
|
|
439
|
-
function add1e6digit(begin, end) {
|
|
440
|
-
// Note: Number('') is 0.
|
|
441
|
-
const digit1e6 = Number(dec.slice(begin, end));
|
|
442
|
-
highBits *= base;
|
|
443
|
-
lowBits = lowBits * base + digit1e6;
|
|
444
|
-
// Carry bits from lowBits to
|
|
445
|
-
if (lowBits >= TWO_PWR_32_DBL$1) {
|
|
446
|
-
highBits = highBits + ((lowBits / TWO_PWR_32_DBL$1) | 0);
|
|
447
|
-
lowBits = lowBits % TWO_PWR_32_DBL$1;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
add1e6digit(-24, -18);
|
|
451
|
-
add1e6digit(-18, -12);
|
|
452
|
-
add1e6digit(-12, -6);
|
|
453
|
-
add1e6digit(-6);
|
|
454
|
-
return [minus, lowBits, highBits];
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Format 64 bit integer value (as two JS numbers) to decimal string.
|
|
458
|
-
*
|
|
459
|
-
* Copyright 2008 Google Inc.
|
|
460
|
-
*/
|
|
461
|
-
function int64toString(bitsLow, bitsHigh) {
|
|
462
|
-
// Skip the expensive conversion if the number is small enough to use the
|
|
463
|
-
// built-in conversions.
|
|
464
|
-
if (bitsHigh <= 0x1FFFFF) {
|
|
465
|
-
return '' + (TWO_PWR_32_DBL$1 * bitsHigh + (bitsLow >>> 0));
|
|
466
|
-
}
|
|
467
|
-
// What this code is doing is essentially converting the input number from
|
|
468
|
-
// base-2 to base-1e7, which allows us to represent the 64-bit range with
|
|
469
|
-
// only 3 (very large) digits. Those digits are then trivial to convert to
|
|
470
|
-
// a base-10 string.
|
|
471
|
-
// The magic numbers used here are -
|
|
472
|
-
// 2^24 = 16777216 = (1,6777216) in base-1e7.
|
|
473
|
-
// 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
|
|
474
|
-
// Split 32:32 representation into 16:24:24 representation so our
|
|
475
|
-
// intermediate digits don't overflow.
|
|
476
|
-
let low = bitsLow & 0xFFFFFF;
|
|
477
|
-
let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xFFFFFF;
|
|
478
|
-
let high = (bitsHigh >> 16) & 0xFFFF;
|
|
479
|
-
// Assemble our three base-1e7 digits, ignoring carries. The maximum
|
|
480
|
-
// value in a digit at this step is representable as a 48-bit integer, which
|
|
481
|
-
// can be stored in a 64-bit floating point number.
|
|
482
|
-
let digitA = low + (mid * 6777216) + (high * 6710656);
|
|
483
|
-
let digitB = mid + (high * 8147497);
|
|
484
|
-
let digitC = (high * 2);
|
|
485
|
-
// Apply carries from A to B and from B to C.
|
|
486
|
-
let base = 10000000;
|
|
487
|
-
if (digitA >= base) {
|
|
488
|
-
digitB += Math.floor(digitA / base);
|
|
489
|
-
digitA %= base;
|
|
490
|
-
}
|
|
491
|
-
if (digitB >= base) {
|
|
492
|
-
digitC += Math.floor(digitB / base);
|
|
493
|
-
digitB %= base;
|
|
494
|
-
}
|
|
495
|
-
// Convert base-1e7 digits to base-10, with optional leading zeroes.
|
|
496
|
-
function decimalFrom1e7(digit1e7, needLeadingZeros) {
|
|
497
|
-
let partial = digit1e7 ? String(digit1e7) : '';
|
|
498
|
-
if (needLeadingZeros) {
|
|
499
|
-
return '0000000'.slice(partial.length) + partial;
|
|
500
|
-
}
|
|
501
|
-
return partial;
|
|
502
|
-
}
|
|
503
|
-
return decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
|
|
504
|
-
decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
|
|
505
|
-
// If the final 1e7 digit didn't need leading zeros, we would have
|
|
506
|
-
// returned via the trivial code path at the top.
|
|
507
|
-
decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1);
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
|
|
511
|
-
*
|
|
512
|
-
* Copyright 2008 Google Inc. All rights reserved.
|
|
513
|
-
*
|
|
514
|
-
* See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
|
|
515
|
-
*/
|
|
516
|
-
function varint32write(value, bytes) {
|
|
517
|
-
if (value >= 0) {
|
|
518
|
-
// write value as varint 32
|
|
519
|
-
while (value > 0x7f) {
|
|
520
|
-
bytes.push((value & 0x7f) | 0x80);
|
|
521
|
-
value = value >>> 7;
|
|
522
|
-
}
|
|
523
|
-
bytes.push(value);
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
for (let i = 0; i < 9; i++) {
|
|
527
|
-
bytes.push(value & 127 | 128);
|
|
528
|
-
value = value >> 7;
|
|
529
|
-
}
|
|
530
|
-
bytes.push(1);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Read an unsigned 32 bit varint.
|
|
535
|
-
*
|
|
536
|
-
* See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
|
|
537
|
-
*/
|
|
538
|
-
function varint32read() {
|
|
539
|
-
let b = this.buf[this.pos++];
|
|
540
|
-
let result = b & 0x7F;
|
|
541
|
-
if ((b & 0x80) == 0) {
|
|
542
|
-
this.assertBounds();
|
|
543
|
-
return result;
|
|
544
|
-
}
|
|
545
|
-
b = this.buf[this.pos++];
|
|
546
|
-
result |= (b & 0x7F) << 7;
|
|
547
|
-
if ((b & 0x80) == 0) {
|
|
548
|
-
this.assertBounds();
|
|
549
|
-
return result;
|
|
550
|
-
}
|
|
551
|
-
b = this.buf[this.pos++];
|
|
552
|
-
result |= (b & 0x7F) << 14;
|
|
553
|
-
if ((b & 0x80) == 0) {
|
|
554
|
-
this.assertBounds();
|
|
555
|
-
return result;
|
|
556
|
-
}
|
|
557
|
-
b = this.buf[this.pos++];
|
|
558
|
-
result |= (b & 0x7F) << 21;
|
|
559
|
-
if ((b & 0x80) == 0) {
|
|
560
|
-
this.assertBounds();
|
|
561
|
-
return result;
|
|
562
|
-
}
|
|
563
|
-
// Extract only last 4 bits
|
|
564
|
-
b = this.buf[this.pos++];
|
|
565
|
-
result |= (b & 0x0F) << 28;
|
|
566
|
-
for (let readBytes = 5; ((b & 0x80) !== 0) && readBytes < 10; readBytes++)
|
|
567
|
-
b = this.buf[this.pos++];
|
|
568
|
-
if ((b & 0x80) != 0)
|
|
569
|
-
throw new Error('invalid varint');
|
|
570
|
-
this.assertBounds();
|
|
571
|
-
// Result can have 32 bits, convert it to unsigned
|
|
572
|
-
return result >>> 0;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
function detectBi() {
|
|
576
|
-
const dv = new DataView(new ArrayBuffer(8));
|
|
577
|
-
const ok = globalThis.BigInt !== undefined
|
|
578
|
-
&& typeof dv.getBigInt64 === "function"
|
|
579
|
-
&& typeof dv.getBigUint64 === "function"
|
|
580
|
-
&& typeof dv.setBigInt64 === "function"
|
|
581
|
-
&& typeof dv.setBigUint64 === "function";
|
|
582
|
-
return ok ? {
|
|
583
|
-
MIN: BigInt("-9223372036854775808"),
|
|
584
|
-
MAX: BigInt("9223372036854775807"),
|
|
585
|
-
UMIN: BigInt("0"),
|
|
586
|
-
UMAX: BigInt("18446744073709551615"),
|
|
587
|
-
C: BigInt,
|
|
588
|
-
V: dv,
|
|
589
|
-
} : undefined;
|
|
590
|
-
}
|
|
591
|
-
const BI = detectBi();
|
|
592
|
-
function assertBi(bi) {
|
|
593
|
-
if (!bi)
|
|
594
|
-
throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support");
|
|
595
|
-
}
|
|
596
|
-
// used to validate from(string) input (when bigint is unavailable)
|
|
597
|
-
const RE_DECIMAL_STR = /^-?[0-9]+$/;
|
|
598
|
-
// constants for binary math
|
|
599
|
-
const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
|
|
600
|
-
// base class for PbLong and PbULong provides shared code
|
|
601
|
-
class SharedPbLong {
|
|
602
|
-
/**
|
|
603
|
-
* Create a new instance with the given bits.
|
|
604
|
-
*/
|
|
605
|
-
constructor(lo, hi) {
|
|
606
|
-
this.lo = lo | 0;
|
|
607
|
-
this.hi = hi | 0;
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Is this instance equal to 0?
|
|
611
|
-
*/
|
|
612
|
-
isZero() {
|
|
613
|
-
return this.lo == 0 && this.hi == 0;
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Convert to a native number.
|
|
617
|
-
*/
|
|
618
|
-
toNumber() {
|
|
619
|
-
let result = this.hi * TWO_PWR_32_DBL + (this.lo >>> 0);
|
|
620
|
-
if (!Number.isSafeInteger(result))
|
|
621
|
-
throw new Error("cannot convert to safe number");
|
|
622
|
-
return result;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* 64-bit unsigned integer as two 32-bit values.
|
|
627
|
-
* Converts between `string`, `number` and `bigint` representations.
|
|
628
|
-
*/
|
|
629
|
-
class PbULong extends SharedPbLong {
|
|
630
|
-
/**
|
|
631
|
-
* Create instance from a `string`, `number` or `bigint`.
|
|
632
|
-
*/
|
|
633
|
-
static from(value) {
|
|
634
|
-
if (BI)
|
|
635
|
-
// noinspection FallThroughInSwitchStatementJS
|
|
636
|
-
switch (typeof value) {
|
|
637
|
-
case "string":
|
|
638
|
-
if (value == "0")
|
|
639
|
-
return this.ZERO;
|
|
640
|
-
if (value == "")
|
|
641
|
-
throw new Error('string is no integer');
|
|
642
|
-
value = BI.C(value);
|
|
643
|
-
case "number":
|
|
644
|
-
if (value === 0)
|
|
645
|
-
return this.ZERO;
|
|
646
|
-
value = BI.C(value);
|
|
647
|
-
case "bigint":
|
|
648
|
-
if (!value)
|
|
649
|
-
return this.ZERO;
|
|
650
|
-
if (value < BI.UMIN)
|
|
651
|
-
throw new Error('signed value for ulong');
|
|
652
|
-
if (value > BI.UMAX)
|
|
653
|
-
throw new Error('ulong too large');
|
|
654
|
-
BI.V.setBigUint64(0, value, true);
|
|
655
|
-
return new PbULong(BI.V.getInt32(0, true), BI.V.getInt32(4, true));
|
|
656
|
-
}
|
|
657
|
-
else
|
|
658
|
-
switch (typeof value) {
|
|
659
|
-
case "string":
|
|
660
|
-
if (value == "0")
|
|
661
|
-
return this.ZERO;
|
|
662
|
-
value = value.trim();
|
|
663
|
-
if (!RE_DECIMAL_STR.test(value))
|
|
664
|
-
throw new Error('string is no integer');
|
|
665
|
-
let [minus, lo, hi] = int64fromString(value);
|
|
666
|
-
if (minus)
|
|
667
|
-
throw new Error('signed value');
|
|
668
|
-
return new PbULong(lo, hi);
|
|
669
|
-
case "number":
|
|
670
|
-
if (value == 0)
|
|
671
|
-
return this.ZERO;
|
|
672
|
-
if (!Number.isSafeInteger(value))
|
|
673
|
-
throw new Error('number is no integer');
|
|
674
|
-
if (value < 0)
|
|
675
|
-
throw new Error('signed value for ulong');
|
|
676
|
-
return new PbULong(value, value / TWO_PWR_32_DBL);
|
|
677
|
-
}
|
|
678
|
-
throw new Error('unknown value ' + typeof value);
|
|
679
|
-
}
|
|
680
|
-
/**
|
|
681
|
-
* Convert to decimal string.
|
|
682
|
-
*/
|
|
683
|
-
toString() {
|
|
684
|
-
return BI ? this.toBigInt().toString() : int64toString(this.lo, this.hi);
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Convert to native bigint.
|
|
688
|
-
*/
|
|
689
|
-
toBigInt() {
|
|
690
|
-
assertBi(BI);
|
|
691
|
-
BI.V.setInt32(0, this.lo, true);
|
|
692
|
-
BI.V.setInt32(4, this.hi, true);
|
|
693
|
-
return BI.V.getBigUint64(0, true);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* ulong 0 singleton.
|
|
698
|
-
*/
|
|
699
|
-
PbULong.ZERO = new PbULong(0, 0);
|
|
700
|
-
/**
|
|
701
|
-
* 64-bit signed integer as two 32-bit values.
|
|
702
|
-
* Converts between `string`, `number` and `bigint` representations.
|
|
703
|
-
*/
|
|
704
|
-
class PbLong extends SharedPbLong {
|
|
705
|
-
/**
|
|
706
|
-
* Create instance from a `string`, `number` or `bigint`.
|
|
707
|
-
*/
|
|
708
|
-
static from(value) {
|
|
709
|
-
if (BI)
|
|
710
|
-
// noinspection FallThroughInSwitchStatementJS
|
|
711
|
-
switch (typeof value) {
|
|
712
|
-
case "string":
|
|
713
|
-
if (value == "0")
|
|
714
|
-
return this.ZERO;
|
|
715
|
-
if (value == "")
|
|
716
|
-
throw new Error('string is no integer');
|
|
717
|
-
value = BI.C(value);
|
|
718
|
-
case "number":
|
|
719
|
-
if (value === 0)
|
|
720
|
-
return this.ZERO;
|
|
721
|
-
value = BI.C(value);
|
|
722
|
-
case "bigint":
|
|
723
|
-
if (!value)
|
|
724
|
-
return this.ZERO;
|
|
725
|
-
if (value < BI.MIN)
|
|
726
|
-
throw new Error('ulong too small');
|
|
727
|
-
if (value > BI.MAX)
|
|
728
|
-
throw new Error('ulong too large');
|
|
729
|
-
BI.V.setBigInt64(0, value, true);
|
|
730
|
-
return new PbLong(BI.V.getInt32(0, true), BI.V.getInt32(4, true));
|
|
731
|
-
}
|
|
732
|
-
else
|
|
733
|
-
switch (typeof value) {
|
|
734
|
-
case "string":
|
|
735
|
-
if (value == "0")
|
|
736
|
-
return this.ZERO;
|
|
737
|
-
value = value.trim();
|
|
738
|
-
if (!RE_DECIMAL_STR.test(value))
|
|
739
|
-
throw new Error('string is no integer');
|
|
740
|
-
let [minus, lo, hi] = int64fromString(value);
|
|
741
|
-
let pbl = new PbLong(lo, hi);
|
|
742
|
-
return minus ? pbl.negate() : pbl;
|
|
743
|
-
case "number":
|
|
744
|
-
if (value == 0)
|
|
745
|
-
return this.ZERO;
|
|
746
|
-
if (!Number.isSafeInteger(value))
|
|
747
|
-
throw new Error('number is no integer');
|
|
748
|
-
return value > 0
|
|
749
|
-
? new PbLong(value, value / TWO_PWR_32_DBL)
|
|
750
|
-
: new PbLong(-value, -value / TWO_PWR_32_DBL).negate();
|
|
751
|
-
}
|
|
752
|
-
throw new Error('unknown value ' + typeof value);
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Do we have a minus sign?
|
|
756
|
-
*/
|
|
757
|
-
isNegative() {
|
|
758
|
-
return (this.hi & 0x80000000) !== 0;
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Negate two's complement.
|
|
762
|
-
* Invert all the bits and add one to the result.
|
|
763
|
-
*/
|
|
764
|
-
negate() {
|
|
765
|
-
let hi = ~this.hi, lo = this.lo;
|
|
766
|
-
if (lo)
|
|
767
|
-
lo = ~lo + 1;
|
|
768
|
-
else
|
|
769
|
-
hi += 1;
|
|
770
|
-
return new PbLong(lo, hi);
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* Convert to decimal string.
|
|
774
|
-
*/
|
|
775
|
-
toString() {
|
|
776
|
-
if (BI)
|
|
777
|
-
return this.toBigInt().toString();
|
|
778
|
-
if (this.isNegative()) {
|
|
779
|
-
let n = this.negate();
|
|
780
|
-
return '-' + int64toString(n.lo, n.hi);
|
|
781
|
-
}
|
|
782
|
-
return int64toString(this.lo, this.hi);
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Convert to native bigint.
|
|
786
|
-
*/
|
|
787
|
-
toBigInt() {
|
|
788
|
-
assertBi(BI);
|
|
789
|
-
BI.V.setInt32(0, this.lo, true);
|
|
790
|
-
BI.V.setInt32(4, this.hi, true);
|
|
791
|
-
return BI.V.getBigInt64(0, true);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* long 0 singleton.
|
|
796
|
-
*/
|
|
797
|
-
PbLong.ZERO = new PbLong(0, 0);
|
|
798
|
-
|
|
799
|
-
const defaultsRead$1 = {
|
|
800
|
-
readUnknownField: true,
|
|
801
|
-
readerFactory: bytes => new BinaryReader(bytes),
|
|
802
|
-
};
|
|
803
|
-
/**
|
|
804
|
-
* Make options for reading binary data form partial options.
|
|
805
|
-
*/
|
|
806
|
-
function binaryReadOptions(options) {
|
|
807
|
-
return options ? Object.assign(Object.assign({}, defaultsRead$1), options) : defaultsRead$1;
|
|
808
|
-
}
|
|
809
|
-
class BinaryReader {
|
|
810
|
-
constructor(buf, textDecoder) {
|
|
811
|
-
this.varint64 = varint64read; // dirty cast for `this`
|
|
812
|
-
/**
|
|
813
|
-
* Read a `uint32` field, an unsigned 32 bit varint.
|
|
814
|
-
*/
|
|
815
|
-
this.uint32 = varint32read; // dirty cast for `this` and access to protected `buf`
|
|
816
|
-
this.buf = buf;
|
|
817
|
-
this.len = buf.length;
|
|
818
|
-
this.pos = 0;
|
|
819
|
-
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
820
|
-
this.textDecoder = textDecoder !== null && textDecoder !== void 0 ? textDecoder : new TextDecoder("utf-8", {
|
|
821
|
-
fatal: true,
|
|
822
|
-
ignoreBOM: true,
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Reads a tag - field number and wire type.
|
|
827
|
-
*/
|
|
828
|
-
tag() {
|
|
829
|
-
let tag = this.uint32(), fieldNo = tag >>> 3, wireType = tag & 7;
|
|
830
|
-
if (fieldNo <= 0 || wireType < 0 || wireType > 5)
|
|
831
|
-
throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
|
|
832
|
-
return [fieldNo, wireType];
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Skip one element on the wire and return the skipped data.
|
|
836
|
-
* Supports WireType.StartGroup since v2.0.0-alpha.23.
|
|
837
|
-
*/
|
|
838
|
-
skip(wireType) {
|
|
839
|
-
let start = this.pos;
|
|
840
|
-
// noinspection FallThroughInSwitchStatementJS
|
|
841
|
-
switch (wireType) {
|
|
842
|
-
case WireType.Varint:
|
|
843
|
-
while (this.buf[this.pos++] & 0x80) {
|
|
844
|
-
// ignore
|
|
845
|
-
}
|
|
846
|
-
break;
|
|
847
|
-
case WireType.Bit64:
|
|
848
|
-
this.pos += 4;
|
|
849
|
-
case WireType.Bit32:
|
|
850
|
-
this.pos += 4;
|
|
851
|
-
break;
|
|
852
|
-
case WireType.LengthDelimited:
|
|
853
|
-
let len = this.uint32();
|
|
854
|
-
this.pos += len;
|
|
855
|
-
break;
|
|
856
|
-
case WireType.StartGroup:
|
|
857
|
-
// From descriptor.proto: Group type is deprecated, not supported in proto3.
|
|
858
|
-
// But we must still be able to parse and treat as unknown.
|
|
859
|
-
let t;
|
|
860
|
-
while ((t = this.tag()[1]) !== WireType.EndGroup) {
|
|
861
|
-
this.skip(t);
|
|
862
|
-
}
|
|
863
|
-
break;
|
|
864
|
-
default:
|
|
865
|
-
throw new Error("cant skip wire type " + wireType);
|
|
866
|
-
}
|
|
867
|
-
this.assertBounds();
|
|
868
|
-
return this.buf.subarray(start, this.pos);
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* Throws error if position in byte array is out of range.
|
|
872
|
-
*/
|
|
873
|
-
assertBounds() {
|
|
874
|
-
if (this.pos > this.len)
|
|
875
|
-
throw new RangeError("premature EOF");
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Read a `int32` field, a signed 32 bit varint.
|
|
879
|
-
*/
|
|
880
|
-
int32() {
|
|
881
|
-
return this.uint32() | 0;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
|
|
885
|
-
*/
|
|
886
|
-
sint32() {
|
|
887
|
-
let zze = this.uint32();
|
|
888
|
-
// decode zigzag
|
|
889
|
-
return (zze >>> 1) ^ -(zze & 1);
|
|
890
|
-
}
|
|
891
|
-
/**
|
|
892
|
-
* Read a `int64` field, a signed 64-bit varint.
|
|
893
|
-
*/
|
|
894
|
-
int64() {
|
|
895
|
-
return new PbLong(...this.varint64());
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* Read a `uint64` field, an unsigned 64-bit varint.
|
|
899
|
-
*/
|
|
900
|
-
uint64() {
|
|
901
|
-
return new PbULong(...this.varint64());
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
|
|
905
|
-
*/
|
|
906
|
-
sint64() {
|
|
907
|
-
let [lo, hi] = this.varint64();
|
|
908
|
-
// decode zig zag
|
|
909
|
-
let s = -(lo & 1);
|
|
910
|
-
lo = ((lo >>> 1 | (hi & 1) << 31) ^ s);
|
|
911
|
-
hi = (hi >>> 1 ^ s);
|
|
912
|
-
return new PbLong(lo, hi);
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Read a `bool` field, a variant.
|
|
916
|
-
*/
|
|
917
|
-
bool() {
|
|
918
|
-
let [lo, hi] = this.varint64();
|
|
919
|
-
return lo !== 0 || hi !== 0;
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
|
|
923
|
-
*/
|
|
924
|
-
fixed32() {
|
|
925
|
-
return this.view.getUint32((this.pos += 4) - 4, true);
|
|
926
|
-
}
|
|
927
|
-
/**
|
|
928
|
-
* Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
|
|
929
|
-
*/
|
|
930
|
-
sfixed32() {
|
|
931
|
-
return this.view.getInt32((this.pos += 4) - 4, true);
|
|
932
|
-
}
|
|
933
|
-
/**
|
|
934
|
-
* Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
|
|
935
|
-
*/
|
|
936
|
-
fixed64() {
|
|
937
|
-
return new PbULong(this.sfixed32(), this.sfixed32());
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Read a `fixed64` field, a signed, fixed-length 64-bit integer.
|
|
941
|
-
*/
|
|
942
|
-
sfixed64() {
|
|
943
|
-
return new PbLong(this.sfixed32(), this.sfixed32());
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
|
-
* Read a `float` field, 32-bit floating point number.
|
|
947
|
-
*/
|
|
948
|
-
float() {
|
|
949
|
-
return this.view.getFloat32((this.pos += 4) - 4, true);
|
|
950
|
-
}
|
|
951
|
-
/**
|
|
952
|
-
* Read a `double` field, a 64-bit floating point number.
|
|
953
|
-
*/
|
|
954
|
-
double() {
|
|
955
|
-
return this.view.getFloat64((this.pos += 8) - 8, true);
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Read a `bytes` field, length-delimited arbitrary data.
|
|
959
|
-
*/
|
|
960
|
-
bytes() {
|
|
961
|
-
let len = this.uint32();
|
|
962
|
-
let start = this.pos;
|
|
963
|
-
this.pos += len;
|
|
964
|
-
this.assertBounds();
|
|
965
|
-
return this.buf.subarray(start, start + len);
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Read a `string` field, length-delimited data converted to UTF-8 text.
|
|
969
|
-
*/
|
|
970
|
-
string() {
|
|
971
|
-
return this.textDecoder.decode(this.bytes());
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
/**
|
|
976
|
-
* assert that condition is true or throw error (with message)
|
|
977
|
-
*/
|
|
978
|
-
function assert(condition, msg) {
|
|
979
|
-
if (!condition) {
|
|
980
|
-
throw new Error(msg);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
const FLOAT32_MAX = 3.4028234663852886e+38, FLOAT32_MIN = -3.4028234663852886e+38, UINT32_MAX = 0xFFFFFFFF, INT32_MAX = 0X7FFFFFFF, INT32_MIN = -0X80000000;
|
|
984
|
-
function assertInt32(arg) {
|
|
985
|
-
if (typeof arg !== "number")
|
|
986
|
-
throw new Error('invalid int 32: ' + typeof arg);
|
|
987
|
-
if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
|
|
988
|
-
throw new Error('invalid int 32: ' + arg);
|
|
989
|
-
}
|
|
990
|
-
function assertUInt32(arg) {
|
|
991
|
-
if (typeof arg !== "number")
|
|
992
|
-
throw new Error('invalid uint 32: ' + typeof arg);
|
|
993
|
-
if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
|
|
994
|
-
throw new Error('invalid uint 32: ' + arg);
|
|
995
|
-
}
|
|
996
|
-
function assertFloat32(arg) {
|
|
997
|
-
if (typeof arg !== "number")
|
|
998
|
-
throw new Error('invalid float 32: ' + typeof arg);
|
|
999
|
-
if (!Number.isFinite(arg))
|
|
1000
|
-
return;
|
|
1001
|
-
if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
|
|
1002
|
-
throw new Error('invalid float 32: ' + arg);
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
const defaultsWrite$1 = {
|
|
1006
|
-
writeUnknownFields: true,
|
|
1007
|
-
writerFactory: () => new BinaryWriter(),
|
|
1008
|
-
};
|
|
1009
|
-
/**
|
|
1010
|
-
* Make options for writing binary data form partial options.
|
|
1011
|
-
*/
|
|
1012
|
-
function binaryWriteOptions(options) {
|
|
1013
|
-
return options ? Object.assign(Object.assign({}, defaultsWrite$1), options) : defaultsWrite$1;
|
|
1014
|
-
}
|
|
1015
|
-
class BinaryWriter {
|
|
1016
|
-
constructor(textEncoder) {
|
|
1017
|
-
/**
|
|
1018
|
-
* Previous fork states.
|
|
1019
|
-
*/
|
|
1020
|
-
this.stack = [];
|
|
1021
|
-
this.textEncoder = textEncoder !== null && textEncoder !== void 0 ? textEncoder : new TextEncoder();
|
|
1022
|
-
this.chunks = [];
|
|
1023
|
-
this.buf = [];
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* Return all bytes written and reset this writer.
|
|
1027
|
-
*/
|
|
1028
|
-
finish() {
|
|
1029
|
-
this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
|
|
1030
|
-
let len = 0;
|
|
1031
|
-
for (let i = 0; i < this.chunks.length; i++)
|
|
1032
|
-
len += this.chunks[i].length;
|
|
1033
|
-
let bytes = new Uint8Array(len);
|
|
1034
|
-
let offset = 0;
|
|
1035
|
-
for (let i = 0; i < this.chunks.length; i++) {
|
|
1036
|
-
bytes.set(this.chunks[i], offset);
|
|
1037
|
-
offset += this.chunks[i].length;
|
|
1038
|
-
}
|
|
1039
|
-
this.chunks = [];
|
|
1040
|
-
return bytes;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Start a new fork for length-delimited data like a message
|
|
1044
|
-
* or a packed repeated field.
|
|
1045
|
-
*
|
|
1046
|
-
* Must be joined later with `join()`.
|
|
1047
|
-
*/
|
|
1048
|
-
fork() {
|
|
1049
|
-
this.stack.push({ chunks: this.chunks, buf: this.buf });
|
|
1050
|
-
this.chunks = [];
|
|
1051
|
-
this.buf = [];
|
|
1052
|
-
return this;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* Join the last fork. Write its length and bytes, then
|
|
1056
|
-
* return to the previous state.
|
|
1057
|
-
*/
|
|
1058
|
-
join() {
|
|
1059
|
-
// get chunk of fork
|
|
1060
|
-
let chunk = this.finish();
|
|
1061
|
-
// restore previous state
|
|
1062
|
-
let prev = this.stack.pop();
|
|
1063
|
-
if (!prev)
|
|
1064
|
-
throw new Error('invalid state, fork stack empty');
|
|
1065
|
-
this.chunks = prev.chunks;
|
|
1066
|
-
this.buf = prev.buf;
|
|
1067
|
-
// write length of chunk as varint
|
|
1068
|
-
this.uint32(chunk.byteLength);
|
|
1069
|
-
return this.raw(chunk);
|
|
1070
|
-
}
|
|
1071
|
-
/**
|
|
1072
|
-
* Writes a tag (field number and wire type).
|
|
1073
|
-
*
|
|
1074
|
-
* Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
|
|
1075
|
-
*
|
|
1076
|
-
* Generated code should compute the tag ahead of time and call `uint32()`.
|
|
1077
|
-
*/
|
|
1078
|
-
tag(fieldNo, type) {
|
|
1079
|
-
return this.uint32((fieldNo << 3 | type) >>> 0);
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* Write a chunk of raw bytes.
|
|
1083
|
-
*/
|
|
1084
|
-
raw(chunk) {
|
|
1085
|
-
if (this.buf.length) {
|
|
1086
|
-
this.chunks.push(new Uint8Array(this.buf));
|
|
1087
|
-
this.buf = [];
|
|
1088
|
-
}
|
|
1089
|
-
this.chunks.push(chunk);
|
|
1090
|
-
return this;
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Write a `uint32` value, an unsigned 32 bit varint.
|
|
1094
|
-
*/
|
|
1095
|
-
uint32(value) {
|
|
1096
|
-
assertUInt32(value);
|
|
1097
|
-
// write value as varint 32, inlined for speed
|
|
1098
|
-
while (value > 0x7f) {
|
|
1099
|
-
this.buf.push((value & 0x7f) | 0x80);
|
|
1100
|
-
value = value >>> 7;
|
|
1101
|
-
}
|
|
1102
|
-
this.buf.push(value);
|
|
1103
|
-
return this;
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* Write a `int32` value, a signed 32 bit varint.
|
|
1107
|
-
*/
|
|
1108
|
-
int32(value) {
|
|
1109
|
-
assertInt32(value);
|
|
1110
|
-
varint32write(value, this.buf);
|
|
1111
|
-
return this;
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Write a `bool` value, a variant.
|
|
1115
|
-
*/
|
|
1116
|
-
bool(value) {
|
|
1117
|
-
this.buf.push(value ? 1 : 0);
|
|
1118
|
-
return this;
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Write a `bytes` value, length-delimited arbitrary data.
|
|
1122
|
-
*/
|
|
1123
|
-
bytes(value) {
|
|
1124
|
-
this.uint32(value.byteLength); // write length of chunk as varint
|
|
1125
|
-
return this.raw(value);
|
|
1126
|
-
}
|
|
1127
|
-
/**
|
|
1128
|
-
* Write a `string` value, length-delimited data converted to UTF-8 text.
|
|
1129
|
-
*/
|
|
1130
|
-
string(value) {
|
|
1131
|
-
let chunk = this.textEncoder.encode(value);
|
|
1132
|
-
this.uint32(chunk.byteLength); // write length of chunk as varint
|
|
1133
|
-
return this.raw(chunk);
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Write a `float` value, 32-bit floating point number.
|
|
1137
|
-
*/
|
|
1138
|
-
float(value) {
|
|
1139
|
-
assertFloat32(value);
|
|
1140
|
-
let chunk = new Uint8Array(4);
|
|
1141
|
-
new DataView(chunk.buffer).setFloat32(0, value, true);
|
|
1142
|
-
return this.raw(chunk);
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Write a `double` value, a 64-bit floating point number.
|
|
1146
|
-
*/
|
|
1147
|
-
double(value) {
|
|
1148
|
-
let chunk = new Uint8Array(8);
|
|
1149
|
-
new DataView(chunk.buffer).setFloat64(0, value, true);
|
|
1150
|
-
return this.raw(chunk);
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
|
|
1154
|
-
*/
|
|
1155
|
-
fixed32(value) {
|
|
1156
|
-
assertUInt32(value);
|
|
1157
|
-
let chunk = new Uint8Array(4);
|
|
1158
|
-
new DataView(chunk.buffer).setUint32(0, value, true);
|
|
1159
|
-
return this.raw(chunk);
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
|
|
1163
|
-
*/
|
|
1164
|
-
sfixed32(value) {
|
|
1165
|
-
assertInt32(value);
|
|
1166
|
-
let chunk = new Uint8Array(4);
|
|
1167
|
-
new DataView(chunk.buffer).setInt32(0, value, true);
|
|
1168
|
-
return this.raw(chunk);
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
|
|
1172
|
-
*/
|
|
1173
|
-
sint32(value) {
|
|
1174
|
-
assertInt32(value);
|
|
1175
|
-
// zigzag encode
|
|
1176
|
-
value = ((value << 1) ^ (value >> 31)) >>> 0;
|
|
1177
|
-
varint32write(value, this.buf);
|
|
1178
|
-
return this;
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Write a `fixed64` value, a signed, fixed-length 64-bit integer.
|
|
1182
|
-
*/
|
|
1183
|
-
sfixed64(value) {
|
|
1184
|
-
let chunk = new Uint8Array(8);
|
|
1185
|
-
let view = new DataView(chunk.buffer);
|
|
1186
|
-
let long = PbLong.from(value);
|
|
1187
|
-
view.setInt32(0, long.lo, true);
|
|
1188
|
-
view.setInt32(4, long.hi, true);
|
|
1189
|
-
return this.raw(chunk);
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
|
|
1193
|
-
*/
|
|
1194
|
-
fixed64(value) {
|
|
1195
|
-
let chunk = new Uint8Array(8);
|
|
1196
|
-
let view = new DataView(chunk.buffer);
|
|
1197
|
-
let long = PbULong.from(value);
|
|
1198
|
-
view.setInt32(0, long.lo, true);
|
|
1199
|
-
view.setInt32(4, long.hi, true);
|
|
1200
|
-
return this.raw(chunk);
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Write a `int64` value, a signed 64-bit varint.
|
|
1204
|
-
*/
|
|
1205
|
-
int64(value) {
|
|
1206
|
-
let long = PbLong.from(value);
|
|
1207
|
-
varint64write(long.lo, long.hi, this.buf);
|
|
1208
|
-
return this;
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
|
|
1212
|
-
*/
|
|
1213
|
-
sint64(value) {
|
|
1214
|
-
let long = PbLong.from(value),
|
|
1215
|
-
// zigzag encode
|
|
1216
|
-
sign = long.hi >> 31, lo = (long.lo << 1) ^ sign, hi = ((long.hi << 1) | (long.lo >>> 31)) ^ sign;
|
|
1217
|
-
varint64write(lo, hi, this.buf);
|
|
1218
|
-
return this;
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Write a `uint64` value, an unsigned 64-bit varint.
|
|
1222
|
-
*/
|
|
1223
|
-
uint64(value) {
|
|
1224
|
-
let long = PbULong.from(value);
|
|
1225
|
-
varint64write(long.lo, long.hi, this.buf);
|
|
1226
|
-
return this;
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
const defaultsWrite = {
|
|
1231
|
-
emitDefaultValues: false,
|
|
1232
|
-
enumAsInteger: false,
|
|
1233
|
-
useProtoFieldName: false,
|
|
1234
|
-
prettySpaces: 0,
|
|
1235
|
-
}, defaultsRead = {
|
|
1236
|
-
ignoreUnknownFields: false,
|
|
1237
|
-
};
|
|
1238
|
-
/**
|
|
1239
|
-
* Make options for reading JSON data from partial options.
|
|
1240
|
-
*/
|
|
1241
|
-
function jsonReadOptions(options) {
|
|
1242
|
-
return options ? Object.assign(Object.assign({}, defaultsRead), options) : defaultsRead;
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Make options for writing JSON data from partial options.
|
|
1246
|
-
*/
|
|
1247
|
-
function jsonWriteOptions(options) {
|
|
1248
|
-
return options ? Object.assign(Object.assign({}, defaultsWrite), options) : defaultsWrite;
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
/**
|
|
1252
|
-
* The symbol used as a key on message objects to store the message type.
|
|
1253
|
-
*
|
|
1254
|
-
* Note that this is an experimental feature - it is here to stay, but
|
|
1255
|
-
* implementation details may change without notice.
|
|
1256
|
-
*/
|
|
1257
|
-
const MESSAGE_TYPE = Symbol.for("protobuf-ts/message-type");
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* Converts snake_case to lowerCamelCase.
|
|
1261
|
-
*
|
|
1262
|
-
* Should behave like protoc:
|
|
1263
|
-
* https://github.com/protocolbuffers/protobuf/blob/e8ae137c96444ea313485ed1118c5e43b2099cf1/src/google/protobuf/compiler/java/java_helpers.cc#L118
|
|
1264
|
-
*/
|
|
1265
|
-
function lowerCamelCase(snakeCase) {
|
|
1266
|
-
let capNext = false;
|
|
1267
|
-
const sb = [];
|
|
1268
|
-
for (let i = 0; i < snakeCase.length; i++) {
|
|
1269
|
-
let next = snakeCase.charAt(i);
|
|
1270
|
-
if (next == '_') {
|
|
1271
|
-
capNext = true;
|
|
1272
|
-
}
|
|
1273
|
-
else if (/\d/.test(next)) {
|
|
1274
|
-
sb.push(next);
|
|
1275
|
-
capNext = true;
|
|
1276
|
-
}
|
|
1277
|
-
else if (capNext) {
|
|
1278
|
-
sb.push(next.toUpperCase());
|
|
1279
|
-
capNext = false;
|
|
1280
|
-
}
|
|
1281
|
-
else if (i == 0) {
|
|
1282
|
-
sb.push(next.toLowerCase());
|
|
1283
|
-
}
|
|
1284
|
-
else {
|
|
1285
|
-
sb.push(next);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
return sb.join('');
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
/**
|
|
1292
|
-
* Scalar value types. This is a subset of field types declared by protobuf
|
|
1293
|
-
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
1294
|
-
* are omitted, but the numerical values are identical.
|
|
1295
|
-
*/
|
|
1296
|
-
var ScalarType;
|
|
1297
|
-
(function (ScalarType) {
|
|
1298
|
-
// 0 is reserved for errors.
|
|
1299
|
-
// Order is weird for historical reasons.
|
|
1300
|
-
ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
|
|
1301
|
-
ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
|
|
1302
|
-
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
|
1303
|
-
// negative values are likely.
|
|
1304
|
-
ScalarType[ScalarType["INT64"] = 3] = "INT64";
|
|
1305
|
-
ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
|
|
1306
|
-
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
|
1307
|
-
// negative values are likely.
|
|
1308
|
-
ScalarType[ScalarType["INT32"] = 5] = "INT32";
|
|
1309
|
-
ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
|
|
1310
|
-
ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
|
|
1311
|
-
ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
|
|
1312
|
-
ScalarType[ScalarType["STRING"] = 9] = "STRING";
|
|
1313
|
-
// Tag-delimited aggregate.
|
|
1314
|
-
// Group type is deprecated and not supported in proto3. However, Proto3
|
|
1315
|
-
// implementations should still be able to parse the group wire format and
|
|
1316
|
-
// treat group fields as unknown fields.
|
|
1317
|
-
// TYPE_GROUP = 10,
|
|
1318
|
-
// TYPE_MESSAGE = 11, // Length-delimited aggregate.
|
|
1319
|
-
// New in version 2.
|
|
1320
|
-
ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
|
|
1321
|
-
ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
|
|
1322
|
-
// TYPE_ENUM = 14,
|
|
1323
|
-
ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
|
|
1324
|
-
ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
|
|
1325
|
-
ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
|
|
1326
|
-
ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
|
|
1327
|
-
})(ScalarType || (ScalarType = {}));
|
|
1328
|
-
/**
|
|
1329
|
-
* JavaScript representation of 64 bit integral types. Equivalent to the
|
|
1330
|
-
* field option "jstype".
|
|
1331
|
-
*
|
|
1332
|
-
* By default, protobuf-ts represents 64 bit types as `bigint`.
|
|
1333
|
-
*
|
|
1334
|
-
* You can change the default behaviour by enabling the plugin parameter
|
|
1335
|
-
* `long_type_string`, which will represent 64 bit types as `string`.
|
|
1336
|
-
*
|
|
1337
|
-
* Alternatively, you can change the behaviour for individual fields
|
|
1338
|
-
* with the field option "jstype":
|
|
1339
|
-
*
|
|
1340
|
-
* ```protobuf
|
|
1341
|
-
* uint64 my_field = 1 [jstype = JS_STRING];
|
|
1342
|
-
* uint64 other_field = 2 [jstype = JS_NUMBER];
|
|
1343
|
-
* ```
|
|
1344
|
-
*/
|
|
1345
|
-
var LongType;
|
|
1346
|
-
(function (LongType) {
|
|
1347
|
-
/**
|
|
1348
|
-
* Use JavaScript `bigint`.
|
|
1349
|
-
*
|
|
1350
|
-
* Field option `[jstype = JS_NORMAL]`.
|
|
1351
|
-
*/
|
|
1352
|
-
LongType[LongType["BIGINT"] = 0] = "BIGINT";
|
|
1353
|
-
/**
|
|
1354
|
-
* Use JavaScript `string`.
|
|
1355
|
-
*
|
|
1356
|
-
* Field option `[jstype = JS_STRING]`.
|
|
1357
|
-
*/
|
|
1358
|
-
LongType[LongType["STRING"] = 1] = "STRING";
|
|
1359
|
-
/**
|
|
1360
|
-
* Use JavaScript `number`.
|
|
1361
|
-
*
|
|
1362
|
-
* Large values will loose precision.
|
|
1363
|
-
*
|
|
1364
|
-
* Field option `[jstype = JS_NUMBER]`.
|
|
1365
|
-
*/
|
|
1366
|
-
LongType[LongType["NUMBER"] = 2] = "NUMBER";
|
|
1367
|
-
})(LongType || (LongType = {}));
|
|
1368
|
-
/**
|
|
1369
|
-
* Protobuf 2.1.0 introduced packed repeated fields.
|
|
1370
|
-
* Setting the field option `[packed = true]` enables packing.
|
|
1371
|
-
*
|
|
1372
|
-
* In proto3, all repeated fields are packed by default.
|
|
1373
|
-
* Setting the field option `[packed = false]` disables packing.
|
|
1374
|
-
*
|
|
1375
|
-
* Packed repeated fields are encoded with a single tag,
|
|
1376
|
-
* then a length-delimiter, then the element values.
|
|
1377
|
-
*
|
|
1378
|
-
* Unpacked repeated fields are encoded with a tag and
|
|
1379
|
-
* value for each element.
|
|
1380
|
-
*
|
|
1381
|
-
* `bytes` and `string` cannot be packed.
|
|
1382
|
-
*/
|
|
1383
|
-
var RepeatType;
|
|
1384
|
-
(function (RepeatType) {
|
|
1385
|
-
/**
|
|
1386
|
-
* The field is not repeated.
|
|
1387
|
-
*/
|
|
1388
|
-
RepeatType[RepeatType["NO"] = 0] = "NO";
|
|
1389
|
-
/**
|
|
1390
|
-
* The field is repeated and should be packed.
|
|
1391
|
-
* Invalid for `bytes` and `string`, they cannot be packed.
|
|
1392
|
-
*/
|
|
1393
|
-
RepeatType[RepeatType["PACKED"] = 1] = "PACKED";
|
|
1394
|
-
/**
|
|
1395
|
-
* The field is repeated but should not be packed.
|
|
1396
|
-
* The only valid repeat type for repeated `bytes` and `string`.
|
|
1397
|
-
*/
|
|
1398
|
-
RepeatType[RepeatType["UNPACKED"] = 2] = "UNPACKED";
|
|
1399
|
-
})(RepeatType || (RepeatType = {}));
|
|
1400
|
-
/**
|
|
1401
|
-
* Turns PartialFieldInfo into FieldInfo.
|
|
1402
|
-
*/
|
|
1403
|
-
function normalizeFieldInfo(field) {
|
|
1404
|
-
var _a, _b, _c, _d;
|
|
1405
|
-
field.localName = (_a = field.localName) !== null && _a !== void 0 ? _a : lowerCamelCase(field.name);
|
|
1406
|
-
field.jsonName = (_b = field.jsonName) !== null && _b !== void 0 ? _b : lowerCamelCase(field.name);
|
|
1407
|
-
field.repeat = (_c = field.repeat) !== null && _c !== void 0 ? _c : RepeatType.NO;
|
|
1408
|
-
field.opt = (_d = field.opt) !== null && _d !== void 0 ? _d : (field.repeat ? false : field.oneof ? false : field.kind == "message");
|
|
1409
|
-
return field;
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
/**
|
|
1413
|
-
* Is the given value a valid oneof group?
|
|
1414
|
-
*
|
|
1415
|
-
* We represent protobuf `oneof` as algebraic data types (ADT) in generated
|
|
1416
|
-
* code. But when working with messages of unknown type, the ADT does not
|
|
1417
|
-
* help us.
|
|
1418
|
-
*
|
|
1419
|
-
* This type guard checks if the given object adheres to the ADT rules, which
|
|
1420
|
-
* are as follows:
|
|
1421
|
-
*
|
|
1422
|
-
* 1) Must be an object.
|
|
1423
|
-
*
|
|
1424
|
-
* 2) Must have a "oneofKind" discriminator property.
|
|
1425
|
-
*
|
|
1426
|
-
* 3) If "oneofKind" is `undefined`, no member field is selected. The object
|
|
1427
|
-
* must not have any other properties.
|
|
1428
|
-
*
|
|
1429
|
-
* 4) If "oneofKind" is a `string`, the member field with this name is
|
|
1430
|
-
* selected.
|
|
1431
|
-
*
|
|
1432
|
-
* 5) If a member field is selected, the object must have a second property
|
|
1433
|
-
* with this name. The property must not be `undefined`.
|
|
1434
|
-
*
|
|
1435
|
-
* 6) No extra properties are allowed. The object has either one property
|
|
1436
|
-
* (no selection) or two properties (selection).
|
|
1437
|
-
*
|
|
1438
|
-
*/
|
|
1439
|
-
function isOneofGroup(any) {
|
|
1440
|
-
if (typeof any != 'object' || any === null || !any.hasOwnProperty('oneofKind')) {
|
|
1441
|
-
return false;
|
|
1442
|
-
}
|
|
1443
|
-
switch (typeof any.oneofKind) {
|
|
1444
|
-
case "string":
|
|
1445
|
-
if (any[any.oneofKind] === undefined)
|
|
1446
|
-
return false;
|
|
1447
|
-
return Object.keys(any).length == 2;
|
|
1448
|
-
case "undefined":
|
|
1449
|
-
return Object.keys(any).length == 1;
|
|
1450
|
-
default:
|
|
1451
|
-
return false;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
// noinspection JSMethodCanBeStatic
|
|
1456
|
-
class ReflectionTypeCheck {
|
|
1457
|
-
constructor(info) {
|
|
1458
|
-
var _a;
|
|
1459
|
-
this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : [];
|
|
1460
|
-
}
|
|
1461
|
-
prepare() {
|
|
1462
|
-
if (this.data)
|
|
1463
|
-
return;
|
|
1464
|
-
const req = [], known = [], oneofs = [];
|
|
1465
|
-
for (let field of this.fields) {
|
|
1466
|
-
if (field.oneof) {
|
|
1467
|
-
if (!oneofs.includes(field.oneof)) {
|
|
1468
|
-
oneofs.push(field.oneof);
|
|
1469
|
-
req.push(field.oneof);
|
|
1470
|
-
known.push(field.oneof);
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
else {
|
|
1474
|
-
known.push(field.localName);
|
|
1475
|
-
switch (field.kind) {
|
|
1476
|
-
case "scalar":
|
|
1477
|
-
case "enum":
|
|
1478
|
-
if (!field.opt || field.repeat)
|
|
1479
|
-
req.push(field.localName);
|
|
1480
|
-
break;
|
|
1481
|
-
case "message":
|
|
1482
|
-
if (field.repeat)
|
|
1483
|
-
req.push(field.localName);
|
|
1484
|
-
break;
|
|
1485
|
-
case "map":
|
|
1486
|
-
req.push(field.localName);
|
|
1487
|
-
break;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
this.data = { req, known, oneofs: Object.values(oneofs) };
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Is the argument a valid message as specified by the
|
|
1495
|
-
* reflection information?
|
|
1496
|
-
*
|
|
1497
|
-
* Checks all field types recursively. The `depth`
|
|
1498
|
-
* specifies how deep into the structure the check will be.
|
|
1499
|
-
*
|
|
1500
|
-
* With a depth of 0, only the presence of fields
|
|
1501
|
-
* is checked.
|
|
1502
|
-
*
|
|
1503
|
-
* With a depth of 1 or more, the field types are checked.
|
|
1504
|
-
*
|
|
1505
|
-
* With a depth of 2 or more, the members of map, repeated
|
|
1506
|
-
* and message fields are checked.
|
|
1507
|
-
*
|
|
1508
|
-
* Message fields will be checked recursively with depth - 1.
|
|
1509
|
-
*
|
|
1510
|
-
* The number of map entries / repeated values being checked
|
|
1511
|
-
* is < depth.
|
|
1512
|
-
*/
|
|
1513
|
-
is(message, depth, allowExcessProperties = false) {
|
|
1514
|
-
if (depth < 0)
|
|
1515
|
-
return true;
|
|
1516
|
-
if (message === null || message === undefined || typeof message != 'object')
|
|
1517
|
-
return false;
|
|
1518
|
-
this.prepare();
|
|
1519
|
-
let keys = Object.keys(message), data = this.data;
|
|
1520
|
-
// if a required field is missing in arg, this cannot be a T
|
|
1521
|
-
if (keys.length < data.req.length || data.req.some(n => !keys.includes(n)))
|
|
1522
|
-
return false;
|
|
1523
|
-
if (!allowExcessProperties) {
|
|
1524
|
-
// if the arg contains a key we dont know, this is not a literal T
|
|
1525
|
-
if (keys.some(k => !data.known.includes(k)))
|
|
1526
|
-
return false;
|
|
1527
|
-
}
|
|
1528
|
-
// "With a depth of 0, only the presence and absence of fields is checked."
|
|
1529
|
-
// "With a depth of 1 or more, the field types are checked."
|
|
1530
|
-
if (depth < 1) {
|
|
1531
|
-
return true;
|
|
1532
|
-
}
|
|
1533
|
-
// check oneof group
|
|
1534
|
-
for (const name of data.oneofs) {
|
|
1535
|
-
const group = message[name];
|
|
1536
|
-
if (!isOneofGroup(group))
|
|
1537
|
-
return false;
|
|
1538
|
-
if (group.oneofKind === undefined)
|
|
1539
|
-
continue;
|
|
1540
|
-
const field = this.fields.find(f => f.localName === group.oneofKind);
|
|
1541
|
-
if (!field)
|
|
1542
|
-
return false; // we found no field, but have a kind, something is wrong
|
|
1543
|
-
if (!this.field(group[group.oneofKind], field, allowExcessProperties, depth))
|
|
1544
|
-
return false;
|
|
1545
|
-
}
|
|
1546
|
-
// check types
|
|
1547
|
-
for (const field of this.fields) {
|
|
1548
|
-
if (field.oneof !== undefined)
|
|
1549
|
-
continue;
|
|
1550
|
-
if (!this.field(message[field.localName], field, allowExcessProperties, depth))
|
|
1551
|
-
return false;
|
|
1552
|
-
}
|
|
1553
|
-
return true;
|
|
1554
|
-
}
|
|
1555
|
-
field(arg, field, allowExcessProperties, depth) {
|
|
1556
|
-
let repeated = field.repeat;
|
|
1557
|
-
switch (field.kind) {
|
|
1558
|
-
case "scalar":
|
|
1559
|
-
if (arg === undefined)
|
|
1560
|
-
return field.opt;
|
|
1561
|
-
if (repeated)
|
|
1562
|
-
return this.scalars(arg, field.T, depth, field.L);
|
|
1563
|
-
return this.scalar(arg, field.T, field.L);
|
|
1564
|
-
case "enum":
|
|
1565
|
-
if (arg === undefined)
|
|
1566
|
-
return field.opt;
|
|
1567
|
-
if (repeated)
|
|
1568
|
-
return this.scalars(arg, ScalarType.INT32, depth);
|
|
1569
|
-
return this.scalar(arg, ScalarType.INT32);
|
|
1570
|
-
case "message":
|
|
1571
|
-
if (arg === undefined)
|
|
1572
|
-
return true;
|
|
1573
|
-
if (repeated)
|
|
1574
|
-
return this.messages(arg, field.T(), allowExcessProperties, depth);
|
|
1575
|
-
return this.message(arg, field.T(), allowExcessProperties, depth);
|
|
1576
|
-
case "map":
|
|
1577
|
-
if (typeof arg != 'object' || arg === null)
|
|
1578
|
-
return false;
|
|
1579
|
-
if (depth < 2)
|
|
1580
|
-
return true;
|
|
1581
|
-
if (!this.mapKeys(arg, field.K, depth))
|
|
1582
|
-
return false;
|
|
1583
|
-
switch (field.V.kind) {
|
|
1584
|
-
case "scalar":
|
|
1585
|
-
return this.scalars(Object.values(arg), field.V.T, depth, field.V.L);
|
|
1586
|
-
case "enum":
|
|
1587
|
-
return this.scalars(Object.values(arg), ScalarType.INT32, depth);
|
|
1588
|
-
case "message":
|
|
1589
|
-
return this.messages(Object.values(arg), field.V.T(), allowExcessProperties, depth);
|
|
1590
|
-
}
|
|
1591
|
-
break;
|
|
1592
|
-
}
|
|
1593
|
-
return true;
|
|
1594
|
-
}
|
|
1595
|
-
message(arg, type, allowExcessProperties, depth) {
|
|
1596
|
-
if (allowExcessProperties) {
|
|
1597
|
-
return type.isAssignable(arg, depth);
|
|
1598
|
-
}
|
|
1599
|
-
return type.is(arg, depth);
|
|
1600
|
-
}
|
|
1601
|
-
messages(arg, type, allowExcessProperties, depth) {
|
|
1602
|
-
if (!Array.isArray(arg))
|
|
1603
|
-
return false;
|
|
1604
|
-
if (depth < 2)
|
|
1605
|
-
return true;
|
|
1606
|
-
if (allowExcessProperties) {
|
|
1607
|
-
for (let i = 0; i < arg.length && i < depth; i++)
|
|
1608
|
-
if (!type.isAssignable(arg[i], depth - 1))
|
|
1609
|
-
return false;
|
|
1610
|
-
}
|
|
1611
|
-
else {
|
|
1612
|
-
for (let i = 0; i < arg.length && i < depth; i++)
|
|
1613
|
-
if (!type.is(arg[i], depth - 1))
|
|
1614
|
-
return false;
|
|
1615
|
-
}
|
|
1616
|
-
return true;
|
|
1617
|
-
}
|
|
1618
|
-
scalar(arg, type, longType) {
|
|
1619
|
-
let argType = typeof arg;
|
|
1620
|
-
switch (type) {
|
|
1621
|
-
case ScalarType.UINT64:
|
|
1622
|
-
case ScalarType.FIXED64:
|
|
1623
|
-
case ScalarType.INT64:
|
|
1624
|
-
case ScalarType.SFIXED64:
|
|
1625
|
-
case ScalarType.SINT64:
|
|
1626
|
-
switch (longType) {
|
|
1627
|
-
case LongType.BIGINT:
|
|
1628
|
-
return argType == "bigint";
|
|
1629
|
-
case LongType.NUMBER:
|
|
1630
|
-
return argType == "number" && !isNaN(arg);
|
|
1631
|
-
default:
|
|
1632
|
-
return argType == "string";
|
|
1633
|
-
}
|
|
1634
|
-
case ScalarType.BOOL:
|
|
1635
|
-
return argType == 'boolean';
|
|
1636
|
-
case ScalarType.STRING:
|
|
1637
|
-
return argType == 'string';
|
|
1638
|
-
case ScalarType.BYTES:
|
|
1639
|
-
return arg instanceof Uint8Array;
|
|
1640
|
-
case ScalarType.DOUBLE:
|
|
1641
|
-
case ScalarType.FLOAT:
|
|
1642
|
-
return argType == 'number' && !isNaN(arg);
|
|
1643
|
-
default:
|
|
1644
|
-
// case ScalarType.UINT32:
|
|
1645
|
-
// case ScalarType.FIXED32:
|
|
1646
|
-
// case ScalarType.INT32:
|
|
1647
|
-
// case ScalarType.SINT32:
|
|
1648
|
-
// case ScalarType.SFIXED32:
|
|
1649
|
-
return argType == 'number' && Number.isInteger(arg);
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
scalars(arg, type, depth, longType) {
|
|
1653
|
-
if (!Array.isArray(arg))
|
|
1654
|
-
return false;
|
|
1655
|
-
if (depth < 2)
|
|
1656
|
-
return true;
|
|
1657
|
-
if (Array.isArray(arg))
|
|
1658
|
-
for (let i = 0; i < arg.length && i < depth; i++)
|
|
1659
|
-
if (!this.scalar(arg[i], type, longType))
|
|
1660
|
-
return false;
|
|
1661
|
-
return true;
|
|
1662
|
-
}
|
|
1663
|
-
mapKeys(map, type, depth) {
|
|
1664
|
-
let keys = Object.keys(map);
|
|
1665
|
-
switch (type) {
|
|
1666
|
-
case ScalarType.INT32:
|
|
1667
|
-
case ScalarType.FIXED32:
|
|
1668
|
-
case ScalarType.SFIXED32:
|
|
1669
|
-
case ScalarType.SINT32:
|
|
1670
|
-
case ScalarType.UINT32:
|
|
1671
|
-
return this.scalars(keys.slice(0, depth).map(k => parseInt(k)), type, depth);
|
|
1672
|
-
case ScalarType.BOOL:
|
|
1673
|
-
return this.scalars(keys.slice(0, depth).map(k => k == 'true' ? true : k == 'false' ? false : k), type, depth);
|
|
1674
|
-
default:
|
|
1675
|
-
return this.scalars(keys, type, depth, LongType.STRING);
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
/**
|
|
1681
|
-
* Utility method to convert a PbLong or PbUlong to a JavaScript
|
|
1682
|
-
* representation during runtime.
|
|
1683
|
-
*
|
|
1684
|
-
* Works with generated field information, `undefined` is equivalent
|
|
1685
|
-
* to `STRING`.
|
|
1686
|
-
*/
|
|
1687
|
-
function reflectionLongConvert(long, type) {
|
|
1688
|
-
switch (type) {
|
|
1689
|
-
case LongType.BIGINT:
|
|
1690
|
-
return long.toBigInt();
|
|
1691
|
-
case LongType.NUMBER:
|
|
1692
|
-
return long.toNumber();
|
|
1693
|
-
default:
|
|
1694
|
-
// case undefined:
|
|
1695
|
-
// case LongType.STRING:
|
|
1696
|
-
return long.toString();
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
/**
|
|
1701
|
-
* Reads proto3 messages in canonical JSON format using reflection information.
|
|
1702
|
-
*
|
|
1703
|
-
* https://developers.google.com/protocol-buffers/docs/proto3#json
|
|
1704
|
-
*/
|
|
1705
|
-
class ReflectionJsonReader {
|
|
1706
|
-
constructor(info) {
|
|
1707
|
-
this.info = info;
|
|
1708
|
-
}
|
|
1709
|
-
prepare() {
|
|
1710
|
-
var _a;
|
|
1711
|
-
if (this.fMap === undefined) {
|
|
1712
|
-
this.fMap = {};
|
|
1713
|
-
const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : [];
|
|
1714
|
-
for (const field of fieldsInput) {
|
|
1715
|
-
this.fMap[field.name] = field;
|
|
1716
|
-
this.fMap[field.jsonName] = field;
|
|
1717
|
-
this.fMap[field.localName] = field;
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
// Cannot parse JSON <type of jsonValue> for <type name>#<fieldName>.
|
|
1722
|
-
assert(condition, fieldName, jsonValue) {
|
|
1723
|
-
if (!condition) {
|
|
1724
|
-
let what = typeofJsonValue(jsonValue);
|
|
1725
|
-
if (what == "number" || what == "boolean")
|
|
1726
|
-
what = jsonValue.toString();
|
|
1727
|
-
throw new Error(`Cannot parse JSON ${what} for ${this.info.typeName}#${fieldName}`);
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
/**
|
|
1731
|
-
* Reads a message from canonical JSON format into the target message.
|
|
1732
|
-
*
|
|
1733
|
-
* Repeated fields are appended. Map entries are added, overwriting
|
|
1734
|
-
* existing keys.
|
|
1735
|
-
*
|
|
1736
|
-
* If a message field is already present, it will be merged with the
|
|
1737
|
-
* new data.
|
|
1738
|
-
*/
|
|
1739
|
-
read(input, message, options) {
|
|
1740
|
-
this.prepare();
|
|
1741
|
-
const oneofsHandled = [];
|
|
1742
|
-
for (const [jsonKey, jsonValue] of Object.entries(input)) {
|
|
1743
|
-
const field = this.fMap[jsonKey];
|
|
1744
|
-
if (!field) {
|
|
1745
|
-
if (!options.ignoreUnknownFields)
|
|
1746
|
-
throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${jsonKey}`);
|
|
1747
|
-
continue;
|
|
1748
|
-
}
|
|
1749
|
-
const localName = field.localName;
|
|
1750
|
-
// handle oneof ADT
|
|
1751
|
-
let target; // this will be the target for the field value, whether it is member of a oneof or not
|
|
1752
|
-
if (field.oneof) {
|
|
1753
|
-
// since json objects are unordered by specification, it is not possible to take the last of multiple oneofs
|
|
1754
|
-
if (oneofsHandled.includes(field.oneof))
|
|
1755
|
-
throw new Error(`Multiple members of the oneof group "${field.oneof}" of ${this.info.typeName} are present in JSON.`);
|
|
1756
|
-
oneofsHandled.push(field.oneof);
|
|
1757
|
-
target = message[field.oneof] = {
|
|
1758
|
-
oneofKind: localName
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
else {
|
|
1762
|
-
target = message;
|
|
1763
|
-
}
|
|
1764
|
-
// we have handled oneof above. we just have read the value into `target`.
|
|
1765
|
-
if (field.kind == 'map') {
|
|
1766
|
-
if (jsonValue === null) {
|
|
1767
|
-
continue;
|
|
1768
|
-
}
|
|
1769
|
-
// check input
|
|
1770
|
-
this.assert(isJsonObject(jsonValue), field.name, jsonValue);
|
|
1771
|
-
// our target to put map entries into
|
|
1772
|
-
const fieldObj = target[localName];
|
|
1773
|
-
// read entries
|
|
1774
|
-
for (const [jsonObjKey, jsonObjValue] of Object.entries(jsonValue)) {
|
|
1775
|
-
this.assert(jsonObjValue !== null, field.name + " map value", null);
|
|
1776
|
-
// read value
|
|
1777
|
-
let val;
|
|
1778
|
-
switch (field.V.kind) {
|
|
1779
|
-
case "message":
|
|
1780
|
-
val = field.V.T().internalJsonRead(jsonObjValue, options);
|
|
1781
|
-
break;
|
|
1782
|
-
case "enum":
|
|
1783
|
-
val = this.enum(field.V.T(), jsonObjValue, field.name, options.ignoreUnknownFields);
|
|
1784
|
-
if (val === false)
|
|
1785
|
-
continue;
|
|
1786
|
-
break;
|
|
1787
|
-
case "scalar":
|
|
1788
|
-
val = this.scalar(jsonObjValue, field.V.T, field.V.L, field.name);
|
|
1789
|
-
break;
|
|
1790
|
-
}
|
|
1791
|
-
this.assert(val !== undefined, field.name + " map value", jsonObjValue);
|
|
1792
|
-
// read key
|
|
1793
|
-
let key = jsonObjKey;
|
|
1794
|
-
if (field.K == ScalarType.BOOL)
|
|
1795
|
-
key = key == "true" ? true : key == "false" ? false : key;
|
|
1796
|
-
key = this.scalar(key, field.K, LongType.STRING, field.name).toString();
|
|
1797
|
-
fieldObj[key] = val;
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
else if (field.repeat) {
|
|
1801
|
-
if (jsonValue === null)
|
|
1802
|
-
continue;
|
|
1803
|
-
// check input
|
|
1804
|
-
this.assert(Array.isArray(jsonValue), field.name, jsonValue);
|
|
1805
|
-
// our target to put array entries into
|
|
1806
|
-
const fieldArr = target[localName];
|
|
1807
|
-
// read array entries
|
|
1808
|
-
for (const jsonItem of jsonValue) {
|
|
1809
|
-
this.assert(jsonItem !== null, field.name, null);
|
|
1810
|
-
let val;
|
|
1811
|
-
switch (field.kind) {
|
|
1812
|
-
case "message":
|
|
1813
|
-
val = field.T().internalJsonRead(jsonItem, options);
|
|
1814
|
-
break;
|
|
1815
|
-
case "enum":
|
|
1816
|
-
val = this.enum(field.T(), jsonItem, field.name, options.ignoreUnknownFields);
|
|
1817
|
-
if (val === false)
|
|
1818
|
-
continue;
|
|
1819
|
-
break;
|
|
1820
|
-
case "scalar":
|
|
1821
|
-
val = this.scalar(jsonItem, field.T, field.L, field.name);
|
|
1822
|
-
break;
|
|
1823
|
-
}
|
|
1824
|
-
this.assert(val !== undefined, field.name, jsonValue);
|
|
1825
|
-
fieldArr.push(val);
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
else {
|
|
1829
|
-
switch (field.kind) {
|
|
1830
|
-
case "message":
|
|
1831
|
-
if (jsonValue === null && field.T().typeName != 'google.protobuf.Value') {
|
|
1832
|
-
this.assert(field.oneof === undefined, field.name + " (oneof member)", null);
|
|
1833
|
-
continue;
|
|
1834
|
-
}
|
|
1835
|
-
target[localName] = field.T().internalJsonRead(jsonValue, options, target[localName]);
|
|
1836
|
-
break;
|
|
1837
|
-
case "enum":
|
|
1838
|
-
let val = this.enum(field.T(), jsonValue, field.name, options.ignoreUnknownFields);
|
|
1839
|
-
if (val === false)
|
|
1840
|
-
continue;
|
|
1841
|
-
target[localName] = val;
|
|
1842
|
-
break;
|
|
1843
|
-
case "scalar":
|
|
1844
|
-
target[localName] = this.scalar(jsonValue, field.T, field.L, field.name);
|
|
1845
|
-
break;
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
/**
|
|
1851
|
-
* Returns `false` for unrecognized string representations.
|
|
1852
|
-
*
|
|
1853
|
-
* google.protobuf.NullValue accepts only JSON `null`.
|
|
1854
|
-
*/
|
|
1855
|
-
enum(type, json, fieldName, ignoreUnknownFields) {
|
|
1856
|
-
if (type[0] == 'google.protobuf.NullValue')
|
|
1857
|
-
assert(json === null, `Unable to parse field ${this.info.typeName}#${fieldName}, enum ${type[0]} only accepts null.`);
|
|
1858
|
-
if (json === null)
|
|
1859
|
-
// we require 0 to be default value for all enums
|
|
1860
|
-
return 0;
|
|
1861
|
-
switch (typeof json) {
|
|
1862
|
-
case "number":
|
|
1863
|
-
assert(Number.isInteger(json), `Unable to parse field ${this.info.typeName}#${fieldName}, enum can only be integral number, got ${json}.`);
|
|
1864
|
-
return json;
|
|
1865
|
-
case "string":
|
|
1866
|
-
let localEnumName = json;
|
|
1867
|
-
if (type[2] && json.substring(0, type[2].length) === type[2])
|
|
1868
|
-
// lookup without the shared prefix
|
|
1869
|
-
localEnumName = json.substring(type[2].length);
|
|
1870
|
-
let enumNumber = type[1][localEnumName];
|
|
1871
|
-
if (typeof enumNumber === 'undefined' && ignoreUnknownFields) {
|
|
1872
|
-
return false;
|
|
1873
|
-
}
|
|
1874
|
-
assert(typeof enumNumber == "number", `Unable to parse field ${this.info.typeName}#${fieldName}, enum ${type[0]} has no value for "${json}".`);
|
|
1875
|
-
return enumNumber;
|
|
1876
|
-
}
|
|
1877
|
-
assert(false, `Unable to parse field ${this.info.typeName}#${fieldName}, cannot parse enum value from ${typeof json}".`);
|
|
1878
|
-
}
|
|
1879
|
-
scalar(json, type, longType, fieldName) {
|
|
1880
|
-
let e;
|
|
1881
|
-
try {
|
|
1882
|
-
switch (type) {
|
|
1883
|
-
// float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
|
|
1884
|
-
// Either numbers or strings are accepted. Exponent notation is also accepted.
|
|
1885
|
-
case ScalarType.DOUBLE:
|
|
1886
|
-
case ScalarType.FLOAT:
|
|
1887
|
-
if (json === null)
|
|
1888
|
-
return .0;
|
|
1889
|
-
if (json === "NaN")
|
|
1890
|
-
return Number.NaN;
|
|
1891
|
-
if (json === "Infinity")
|
|
1892
|
-
return Number.POSITIVE_INFINITY;
|
|
1893
|
-
if (json === "-Infinity")
|
|
1894
|
-
return Number.NEGATIVE_INFINITY;
|
|
1895
|
-
if (json === "") {
|
|
1896
|
-
e = "empty string";
|
|
1897
|
-
break;
|
|
1898
|
-
}
|
|
1899
|
-
if (typeof json == "string" && json.trim().length !== json.length) {
|
|
1900
|
-
e = "extra whitespace";
|
|
1901
|
-
break;
|
|
1902
|
-
}
|
|
1903
|
-
if (typeof json != "string" && typeof json != "number") {
|
|
1904
|
-
break;
|
|
1905
|
-
}
|
|
1906
|
-
let float = Number(json);
|
|
1907
|
-
if (Number.isNaN(float)) {
|
|
1908
|
-
e = "not a number";
|
|
1909
|
-
break;
|
|
1910
|
-
}
|
|
1911
|
-
if (!Number.isFinite(float)) {
|
|
1912
|
-
// infinity and -infinity are handled by string representation above, so this is an error
|
|
1913
|
-
e = "too large or small";
|
|
1914
|
-
break;
|
|
1915
|
-
}
|
|
1916
|
-
if (type == ScalarType.FLOAT)
|
|
1917
|
-
assertFloat32(float);
|
|
1918
|
-
return float;
|
|
1919
|
-
// int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
|
|
1920
|
-
case ScalarType.INT32:
|
|
1921
|
-
case ScalarType.FIXED32:
|
|
1922
|
-
case ScalarType.SFIXED32:
|
|
1923
|
-
case ScalarType.SINT32:
|
|
1924
|
-
case ScalarType.UINT32:
|
|
1925
|
-
if (json === null)
|
|
1926
|
-
return 0;
|
|
1927
|
-
let int32;
|
|
1928
|
-
if (typeof json == "number")
|
|
1929
|
-
int32 = json;
|
|
1930
|
-
else if (json === "")
|
|
1931
|
-
e = "empty string";
|
|
1932
|
-
else if (typeof json == "string") {
|
|
1933
|
-
if (json.trim().length !== json.length)
|
|
1934
|
-
e = "extra whitespace";
|
|
1935
|
-
else
|
|
1936
|
-
int32 = Number(json);
|
|
1937
|
-
}
|
|
1938
|
-
if (int32 === undefined)
|
|
1939
|
-
break;
|
|
1940
|
-
if (type == ScalarType.UINT32)
|
|
1941
|
-
assertUInt32(int32);
|
|
1942
|
-
else
|
|
1943
|
-
assertInt32(int32);
|
|
1944
|
-
return int32;
|
|
1945
|
-
// int64, fixed64, uint64: JSON value will be a decimal string. Either numbers or strings are accepted.
|
|
1946
|
-
case ScalarType.INT64:
|
|
1947
|
-
case ScalarType.SFIXED64:
|
|
1948
|
-
case ScalarType.SINT64:
|
|
1949
|
-
if (json === null)
|
|
1950
|
-
return reflectionLongConvert(PbLong.ZERO, longType);
|
|
1951
|
-
if (typeof json != "number" && typeof json != "string")
|
|
1952
|
-
break;
|
|
1953
|
-
return reflectionLongConvert(PbLong.from(json), longType);
|
|
1954
|
-
case ScalarType.FIXED64:
|
|
1955
|
-
case ScalarType.UINT64:
|
|
1956
|
-
if (json === null)
|
|
1957
|
-
return reflectionLongConvert(PbULong.ZERO, longType);
|
|
1958
|
-
if (typeof json != "number" && typeof json != "string")
|
|
1959
|
-
break;
|
|
1960
|
-
return reflectionLongConvert(PbULong.from(json), longType);
|
|
1961
|
-
// bool:
|
|
1962
|
-
case ScalarType.BOOL:
|
|
1963
|
-
if (json === null)
|
|
1964
|
-
return false;
|
|
1965
|
-
if (typeof json !== "boolean")
|
|
1966
|
-
break;
|
|
1967
|
-
return json;
|
|
1968
|
-
// string:
|
|
1969
|
-
case ScalarType.STRING:
|
|
1970
|
-
if (json === null)
|
|
1971
|
-
return "";
|
|
1972
|
-
if (typeof json !== "string") {
|
|
1973
|
-
e = "extra whitespace";
|
|
1974
|
-
break;
|
|
1975
|
-
}
|
|
1976
|
-
try {
|
|
1977
|
-
encodeURIComponent(json);
|
|
1978
|
-
}
|
|
1979
|
-
catch (e) {
|
|
1980
|
-
e = "invalid UTF8";
|
|
1981
|
-
break;
|
|
1982
|
-
}
|
|
1983
|
-
return json;
|
|
1984
|
-
// bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
|
|
1985
|
-
// Either standard or URL-safe base64 encoding with/without paddings are accepted.
|
|
1986
|
-
case ScalarType.BYTES:
|
|
1987
|
-
if (json === null || json === "")
|
|
1988
|
-
return new Uint8Array(0);
|
|
1989
|
-
if (typeof json !== 'string')
|
|
1990
|
-
break;
|
|
1991
|
-
return base64decode(json);
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
catch (error) {
|
|
1995
|
-
e = error.message;
|
|
1996
|
-
}
|
|
1997
|
-
this.assert(false, fieldName + (e ? " - " + e : ""), json);
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
/**
|
|
2002
|
-
* Writes proto3 messages in canonical JSON format using reflection
|
|
2003
|
-
* information.
|
|
2004
|
-
*
|
|
2005
|
-
* https://developers.google.com/protocol-buffers/docs/proto3#json
|
|
2006
|
-
*/
|
|
2007
|
-
class ReflectionJsonWriter {
|
|
2008
|
-
constructor(info) {
|
|
2009
|
-
var _a;
|
|
2010
|
-
this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : [];
|
|
2011
|
-
}
|
|
2012
|
-
/**
|
|
2013
|
-
* Converts the message to a JSON object, based on the field descriptors.
|
|
2014
|
-
*/
|
|
2015
|
-
write(message, options) {
|
|
2016
|
-
const json = {}, source = message;
|
|
2017
|
-
for (const field of this.fields) {
|
|
2018
|
-
// field is not part of a oneof, simply write as is
|
|
2019
|
-
if (!field.oneof) {
|
|
2020
|
-
let jsonValue = this.field(field, source[field.localName], options);
|
|
2021
|
-
if (jsonValue !== undefined)
|
|
2022
|
-
json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue;
|
|
2023
|
-
continue;
|
|
2024
|
-
}
|
|
2025
|
-
// field is part of a oneof
|
|
2026
|
-
const group = source[field.oneof];
|
|
2027
|
-
if (group.oneofKind !== field.localName)
|
|
2028
|
-
continue; // not selected, skip
|
|
2029
|
-
const opt = field.kind == 'scalar' || field.kind == 'enum'
|
|
2030
|
-
? Object.assign(Object.assign({}, options), { emitDefaultValues: true }) : options;
|
|
2031
|
-
let jsonValue = this.field(field, group[field.localName], opt);
|
|
2032
|
-
assert(jsonValue !== undefined);
|
|
2033
|
-
json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue;
|
|
2034
|
-
}
|
|
2035
|
-
return json;
|
|
2036
|
-
}
|
|
2037
|
-
field(field, value, options) {
|
|
2038
|
-
let jsonValue = undefined;
|
|
2039
|
-
if (field.kind == 'map') {
|
|
2040
|
-
assert(typeof value == "object" && value !== null);
|
|
2041
|
-
const jsonObj = {};
|
|
2042
|
-
switch (field.V.kind) {
|
|
2043
|
-
case "scalar":
|
|
2044
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
2045
|
-
const val = this.scalar(field.V.T, entryValue, field.name, false, true);
|
|
2046
|
-
assert(val !== undefined);
|
|
2047
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
2048
|
-
}
|
|
2049
|
-
break;
|
|
2050
|
-
case "message":
|
|
2051
|
-
const messageType = field.V.T();
|
|
2052
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
2053
|
-
const val = this.message(messageType, entryValue, field.name, options);
|
|
2054
|
-
assert(val !== undefined);
|
|
2055
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
2056
|
-
}
|
|
2057
|
-
break;
|
|
2058
|
-
case "enum":
|
|
2059
|
-
const enumInfo = field.V.T();
|
|
2060
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
2061
|
-
assert(entryValue === undefined || typeof entryValue == 'number');
|
|
2062
|
-
const val = this.enum(enumInfo, entryValue, field.name, false, true, options.enumAsInteger);
|
|
2063
|
-
assert(val !== undefined);
|
|
2064
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
2065
|
-
}
|
|
2066
|
-
break;
|
|
2067
|
-
}
|
|
2068
|
-
if (options.emitDefaultValues || Object.keys(jsonObj).length > 0)
|
|
2069
|
-
jsonValue = jsonObj;
|
|
2070
|
-
}
|
|
2071
|
-
else if (field.repeat) {
|
|
2072
|
-
assert(Array.isArray(value));
|
|
2073
|
-
const jsonArr = [];
|
|
2074
|
-
switch (field.kind) {
|
|
2075
|
-
case "scalar":
|
|
2076
|
-
for (let i = 0; i < value.length; i++) {
|
|
2077
|
-
const val = this.scalar(field.T, value[i], field.name, field.opt, true);
|
|
2078
|
-
assert(val !== undefined);
|
|
2079
|
-
jsonArr.push(val);
|
|
2080
|
-
}
|
|
2081
|
-
break;
|
|
2082
|
-
case "enum":
|
|
2083
|
-
const enumInfo = field.T();
|
|
2084
|
-
for (let i = 0; i < value.length; i++) {
|
|
2085
|
-
assert(value[i] === undefined || typeof value[i] == 'number');
|
|
2086
|
-
const val = this.enum(enumInfo, value[i], field.name, field.opt, true, options.enumAsInteger);
|
|
2087
|
-
assert(val !== undefined);
|
|
2088
|
-
jsonArr.push(val);
|
|
2089
|
-
}
|
|
2090
|
-
break;
|
|
2091
|
-
case "message":
|
|
2092
|
-
const messageType = field.T();
|
|
2093
|
-
for (let i = 0; i < value.length; i++) {
|
|
2094
|
-
const val = this.message(messageType, value[i], field.name, options);
|
|
2095
|
-
assert(val !== undefined);
|
|
2096
|
-
jsonArr.push(val);
|
|
2097
|
-
}
|
|
2098
|
-
break;
|
|
2099
|
-
}
|
|
2100
|
-
// add converted array to json output
|
|
2101
|
-
if (options.emitDefaultValues || jsonArr.length > 0 || options.emitDefaultValues)
|
|
2102
|
-
jsonValue = jsonArr;
|
|
2103
|
-
}
|
|
2104
|
-
else {
|
|
2105
|
-
switch (field.kind) {
|
|
2106
|
-
case "scalar":
|
|
2107
|
-
jsonValue = this.scalar(field.T, value, field.name, field.opt, options.emitDefaultValues);
|
|
2108
|
-
break;
|
|
2109
|
-
case "enum":
|
|
2110
|
-
jsonValue = this.enum(field.T(), value, field.name, field.opt, options.emitDefaultValues, options.enumAsInteger);
|
|
2111
|
-
break;
|
|
2112
|
-
case "message":
|
|
2113
|
-
jsonValue = this.message(field.T(), value, field.name, options);
|
|
2114
|
-
break;
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
return jsonValue;
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* Returns `null` for google.protobuf.NullValue.
|
|
2121
|
-
*/
|
|
2122
|
-
enum(type, value, fieldName, optional, emitDefaultValues, enumAsInteger) {
|
|
2123
|
-
if (type[0] == 'google.protobuf.NullValue')
|
|
2124
|
-
return null;
|
|
2125
|
-
if (value === undefined) {
|
|
2126
|
-
assert(optional);
|
|
2127
|
-
return undefined;
|
|
2128
|
-
}
|
|
2129
|
-
if (value === 0 && !emitDefaultValues && !optional)
|
|
2130
|
-
// we require 0 to be default value for all enums
|
|
2131
|
-
return undefined;
|
|
2132
|
-
assert(typeof value == 'number');
|
|
2133
|
-
assert(Number.isInteger(value));
|
|
2134
|
-
if (enumAsInteger || !type[1].hasOwnProperty(value))
|
|
2135
|
-
// if we don't now the enum value, just return the number
|
|
2136
|
-
return value;
|
|
2137
|
-
if (type[2])
|
|
2138
|
-
// restore the dropped prefix
|
|
2139
|
-
return type[2] + type[1][value];
|
|
2140
|
-
return type[1][value];
|
|
2141
|
-
}
|
|
2142
|
-
message(type, value, fieldName, options) {
|
|
2143
|
-
if (value === undefined)
|
|
2144
|
-
return options.emitDefaultValues ? null : undefined;
|
|
2145
|
-
return type.internalJsonWrite(value, options);
|
|
2146
|
-
}
|
|
2147
|
-
scalar(type, value, fieldName, optional, emitDefaultValues) {
|
|
2148
|
-
if (value === undefined) {
|
|
2149
|
-
assert(optional);
|
|
2150
|
-
return undefined;
|
|
2151
|
-
}
|
|
2152
|
-
const ed = emitDefaultValues || optional;
|
|
2153
|
-
// noinspection FallThroughInSwitchStatementJS
|
|
2154
|
-
switch (type) {
|
|
2155
|
-
// int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
|
|
2156
|
-
case ScalarType.INT32:
|
|
2157
|
-
case ScalarType.SFIXED32:
|
|
2158
|
-
case ScalarType.SINT32:
|
|
2159
|
-
if (value === 0)
|
|
2160
|
-
return ed ? 0 : undefined;
|
|
2161
|
-
assertInt32(value);
|
|
2162
|
-
return value;
|
|
2163
|
-
case ScalarType.FIXED32:
|
|
2164
|
-
case ScalarType.UINT32:
|
|
2165
|
-
if (value === 0)
|
|
2166
|
-
return ed ? 0 : undefined;
|
|
2167
|
-
assertUInt32(value);
|
|
2168
|
-
return value;
|
|
2169
|
-
// float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
|
|
2170
|
-
// Either numbers or strings are accepted. Exponent notation is also accepted.
|
|
2171
|
-
case ScalarType.FLOAT:
|
|
2172
|
-
assertFloat32(value);
|
|
2173
|
-
case ScalarType.DOUBLE:
|
|
2174
|
-
if (value === 0)
|
|
2175
|
-
return ed ? 0 : undefined;
|
|
2176
|
-
assert(typeof value == 'number');
|
|
2177
|
-
if (Number.isNaN(value))
|
|
2178
|
-
return 'NaN';
|
|
2179
|
-
if (value === Number.POSITIVE_INFINITY)
|
|
2180
|
-
return 'Infinity';
|
|
2181
|
-
if (value === Number.NEGATIVE_INFINITY)
|
|
2182
|
-
return '-Infinity';
|
|
2183
|
-
return value;
|
|
2184
|
-
// string:
|
|
2185
|
-
case ScalarType.STRING:
|
|
2186
|
-
if (value === "")
|
|
2187
|
-
return ed ? '' : undefined;
|
|
2188
|
-
assert(typeof value == 'string');
|
|
2189
|
-
return value;
|
|
2190
|
-
// bool:
|
|
2191
|
-
case ScalarType.BOOL:
|
|
2192
|
-
if (value === false)
|
|
2193
|
-
return ed ? false : undefined;
|
|
2194
|
-
assert(typeof value == 'boolean');
|
|
2195
|
-
return value;
|
|
2196
|
-
// JSON value will be a decimal string. Either numbers or strings are accepted.
|
|
2197
|
-
case ScalarType.UINT64:
|
|
2198
|
-
case ScalarType.FIXED64:
|
|
2199
|
-
assert(typeof value == 'number' || typeof value == 'string' || typeof value == 'bigint');
|
|
2200
|
-
let ulong = PbULong.from(value);
|
|
2201
|
-
if (ulong.isZero() && !ed)
|
|
2202
|
-
return undefined;
|
|
2203
|
-
return ulong.toString();
|
|
2204
|
-
// JSON value will be a decimal string. Either numbers or strings are accepted.
|
|
2205
|
-
case ScalarType.INT64:
|
|
2206
|
-
case ScalarType.SFIXED64:
|
|
2207
|
-
case ScalarType.SINT64:
|
|
2208
|
-
assert(typeof value == 'number' || typeof value == 'string' || typeof value == 'bigint');
|
|
2209
|
-
let long = PbLong.from(value);
|
|
2210
|
-
if (long.isZero() && !ed)
|
|
2211
|
-
return undefined;
|
|
2212
|
-
return long.toString();
|
|
2213
|
-
// bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
|
|
2214
|
-
// Either standard or URL-safe base64 encoding with/without paddings are accepted.
|
|
2215
|
-
case ScalarType.BYTES:
|
|
2216
|
-
assert(value instanceof Uint8Array);
|
|
2217
|
-
if (!value.byteLength)
|
|
2218
|
-
return ed ? "" : undefined;
|
|
2219
|
-
return base64encode(value);
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
/**
|
|
2225
|
-
* Creates the default value for a scalar type.
|
|
2226
|
-
*/
|
|
2227
|
-
function reflectionScalarDefault(type, longType = LongType.STRING) {
|
|
2228
|
-
switch (type) {
|
|
2229
|
-
case ScalarType.BOOL:
|
|
2230
|
-
return false;
|
|
2231
|
-
case ScalarType.UINT64:
|
|
2232
|
-
case ScalarType.FIXED64:
|
|
2233
|
-
return reflectionLongConvert(PbULong.ZERO, longType);
|
|
2234
|
-
case ScalarType.INT64:
|
|
2235
|
-
case ScalarType.SFIXED64:
|
|
2236
|
-
case ScalarType.SINT64:
|
|
2237
|
-
return reflectionLongConvert(PbLong.ZERO, longType);
|
|
2238
|
-
case ScalarType.DOUBLE:
|
|
2239
|
-
case ScalarType.FLOAT:
|
|
2240
|
-
return 0.0;
|
|
2241
|
-
case ScalarType.BYTES:
|
|
2242
|
-
return new Uint8Array(0);
|
|
2243
|
-
case ScalarType.STRING:
|
|
2244
|
-
return "";
|
|
2245
|
-
default:
|
|
2246
|
-
// case ScalarType.INT32:
|
|
2247
|
-
// case ScalarType.UINT32:
|
|
2248
|
-
// case ScalarType.SINT32:
|
|
2249
|
-
// case ScalarType.FIXED32:
|
|
2250
|
-
// case ScalarType.SFIXED32:
|
|
2251
|
-
return 0;
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
/**
|
|
2256
|
-
* Reads proto3 messages in binary format using reflection information.
|
|
2257
|
-
*
|
|
2258
|
-
* https://developers.google.com/protocol-buffers/docs/encoding
|
|
2259
|
-
*/
|
|
2260
|
-
class ReflectionBinaryReader {
|
|
2261
|
-
constructor(info) {
|
|
2262
|
-
this.info = info;
|
|
2263
|
-
}
|
|
2264
|
-
prepare() {
|
|
2265
|
-
var _a;
|
|
2266
|
-
if (!this.fieldNoToField) {
|
|
2267
|
-
const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : [];
|
|
2268
|
-
this.fieldNoToField = new Map(fieldsInput.map(field => [field.no, field]));
|
|
2269
|
-
}
|
|
2270
|
-
}
|
|
2271
|
-
/**
|
|
2272
|
-
* Reads a message from binary format into the target message.
|
|
2273
|
-
*
|
|
2274
|
-
* Repeated fields are appended. Map entries are added, overwriting
|
|
2275
|
-
* existing keys.
|
|
2276
|
-
*
|
|
2277
|
-
* If a message field is already present, it will be merged with the
|
|
2278
|
-
* new data.
|
|
2279
|
-
*/
|
|
2280
|
-
read(reader, message, options, length) {
|
|
2281
|
-
this.prepare();
|
|
2282
|
-
const end = length === undefined ? reader.len : reader.pos + length;
|
|
2283
|
-
while (reader.pos < end) {
|
|
2284
|
-
// read the tag and find the field
|
|
2285
|
-
const [fieldNo, wireType] = reader.tag(), field = this.fieldNoToField.get(fieldNo);
|
|
2286
|
-
if (!field) {
|
|
2287
|
-
let u = options.readUnknownField;
|
|
2288
|
-
if (u == "throw")
|
|
2289
|
-
throw new Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.info.typeName}`);
|
|
2290
|
-
let d = reader.skip(wireType);
|
|
2291
|
-
if (u !== false)
|
|
2292
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.info.typeName, message, fieldNo, wireType, d);
|
|
2293
|
-
continue;
|
|
2294
|
-
}
|
|
2295
|
-
// target object for the field we are reading
|
|
2296
|
-
let target = message, repeated = field.repeat, localName = field.localName;
|
|
2297
|
-
// if field is member of oneof ADT, use ADT as target
|
|
2298
|
-
if (field.oneof) {
|
|
2299
|
-
target = target[field.oneof];
|
|
2300
|
-
// if other oneof member selected, set new ADT
|
|
2301
|
-
if (target.oneofKind !== localName)
|
|
2302
|
-
target = message[field.oneof] = {
|
|
2303
|
-
oneofKind: localName
|
|
2304
|
-
};
|
|
2305
|
-
}
|
|
2306
|
-
// we have handled oneof above, we just have read the value into `target[localName]`
|
|
2307
|
-
switch (field.kind) {
|
|
2308
|
-
case "scalar":
|
|
2309
|
-
case "enum":
|
|
2310
|
-
let T = field.kind == "enum" ? ScalarType.INT32 : field.T;
|
|
2311
|
-
let L = field.kind == "scalar" ? field.L : undefined;
|
|
2312
|
-
if (repeated) {
|
|
2313
|
-
let arr = target[localName]; // safe to assume presence of array, oneof cannot contain repeated values
|
|
2314
|
-
if (wireType == WireType.LengthDelimited && T != ScalarType.STRING && T != ScalarType.BYTES) {
|
|
2315
|
-
let e = reader.uint32() + reader.pos;
|
|
2316
|
-
while (reader.pos < e)
|
|
2317
|
-
arr.push(this.scalar(reader, T, L));
|
|
2318
|
-
}
|
|
2319
|
-
else
|
|
2320
|
-
arr.push(this.scalar(reader, T, L));
|
|
2321
|
-
}
|
|
2322
|
-
else
|
|
2323
|
-
target[localName] = this.scalar(reader, T, L);
|
|
2324
|
-
break;
|
|
2325
|
-
case "message":
|
|
2326
|
-
if (repeated) {
|
|
2327
|
-
let arr = target[localName]; // safe to assume presence of array, oneof cannot contain repeated values
|
|
2328
|
-
let msg = field.T().internalBinaryRead(reader, reader.uint32(), options);
|
|
2329
|
-
arr.push(msg);
|
|
2330
|
-
}
|
|
2331
|
-
else
|
|
2332
|
-
target[localName] = field.T().internalBinaryRead(reader, reader.uint32(), options, target[localName]);
|
|
2333
|
-
break;
|
|
2334
|
-
case "map":
|
|
2335
|
-
let [mapKey, mapVal] = this.mapEntry(field, reader, options);
|
|
2336
|
-
// safe to assume presence of map object, oneof cannot contain repeated values
|
|
2337
|
-
target[localName][mapKey] = mapVal;
|
|
2338
|
-
break;
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
}
|
|
2342
|
-
/**
|
|
2343
|
-
* Read a map field, expecting key field = 1, value field = 2
|
|
2344
|
-
*/
|
|
2345
|
-
mapEntry(field, reader, options) {
|
|
2346
|
-
let length = reader.uint32();
|
|
2347
|
-
let end = reader.pos + length;
|
|
2348
|
-
let key = undefined; // javascript only allows number or string for object properties
|
|
2349
|
-
let val = undefined;
|
|
2350
|
-
while (reader.pos < end) {
|
|
2351
|
-
let [fieldNo, wireType] = reader.tag();
|
|
2352
|
-
switch (fieldNo) {
|
|
2353
|
-
case 1:
|
|
2354
|
-
if (field.K == ScalarType.BOOL)
|
|
2355
|
-
key = reader.bool().toString();
|
|
2356
|
-
else
|
|
2357
|
-
// long types are read as string, number types are okay as number
|
|
2358
|
-
key = this.scalar(reader, field.K, LongType.STRING);
|
|
2359
|
-
break;
|
|
2360
|
-
case 2:
|
|
2361
|
-
switch (field.V.kind) {
|
|
2362
|
-
case "scalar":
|
|
2363
|
-
val = this.scalar(reader, field.V.T, field.V.L);
|
|
2364
|
-
break;
|
|
2365
|
-
case "enum":
|
|
2366
|
-
val = reader.int32();
|
|
2367
|
-
break;
|
|
2368
|
-
case "message":
|
|
2369
|
-
val = field.V.T().internalBinaryRead(reader, reader.uint32(), options);
|
|
2370
|
-
break;
|
|
2371
|
-
}
|
|
2372
|
-
break;
|
|
2373
|
-
default:
|
|
2374
|
-
throw new Error(`Unknown field ${fieldNo} (wire type ${wireType}) in map entry for ${this.info.typeName}#${field.name}`);
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
if (key === undefined) {
|
|
2378
|
-
let keyRaw = reflectionScalarDefault(field.K);
|
|
2379
|
-
key = field.K == ScalarType.BOOL ? keyRaw.toString() : keyRaw;
|
|
2380
|
-
}
|
|
2381
|
-
if (val === undefined)
|
|
2382
|
-
switch (field.V.kind) {
|
|
2383
|
-
case "scalar":
|
|
2384
|
-
val = reflectionScalarDefault(field.V.T, field.V.L);
|
|
2385
|
-
break;
|
|
2386
|
-
case "enum":
|
|
2387
|
-
val = 0;
|
|
2388
|
-
break;
|
|
2389
|
-
case "message":
|
|
2390
|
-
val = field.V.T().create();
|
|
2391
|
-
break;
|
|
2392
|
-
}
|
|
2393
|
-
return [key, val];
|
|
2394
|
-
}
|
|
2395
|
-
scalar(reader, type, longType) {
|
|
2396
|
-
switch (type) {
|
|
2397
|
-
case ScalarType.INT32:
|
|
2398
|
-
return reader.int32();
|
|
2399
|
-
case ScalarType.STRING:
|
|
2400
|
-
return reader.string();
|
|
2401
|
-
case ScalarType.BOOL:
|
|
2402
|
-
return reader.bool();
|
|
2403
|
-
case ScalarType.DOUBLE:
|
|
2404
|
-
return reader.double();
|
|
2405
|
-
case ScalarType.FLOAT:
|
|
2406
|
-
return reader.float();
|
|
2407
|
-
case ScalarType.INT64:
|
|
2408
|
-
return reflectionLongConvert(reader.int64(), longType);
|
|
2409
|
-
case ScalarType.UINT64:
|
|
2410
|
-
return reflectionLongConvert(reader.uint64(), longType);
|
|
2411
|
-
case ScalarType.FIXED64:
|
|
2412
|
-
return reflectionLongConvert(reader.fixed64(), longType);
|
|
2413
|
-
case ScalarType.FIXED32:
|
|
2414
|
-
return reader.fixed32();
|
|
2415
|
-
case ScalarType.BYTES:
|
|
2416
|
-
return reader.bytes();
|
|
2417
|
-
case ScalarType.UINT32:
|
|
2418
|
-
return reader.uint32();
|
|
2419
|
-
case ScalarType.SFIXED32:
|
|
2420
|
-
return reader.sfixed32();
|
|
2421
|
-
case ScalarType.SFIXED64:
|
|
2422
|
-
return reflectionLongConvert(reader.sfixed64(), longType);
|
|
2423
|
-
case ScalarType.SINT32:
|
|
2424
|
-
return reader.sint32();
|
|
2425
|
-
case ScalarType.SINT64:
|
|
2426
|
-
return reflectionLongConvert(reader.sint64(), longType);
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
/**
|
|
2432
|
-
* Writes proto3 messages in binary format using reflection information.
|
|
2433
|
-
*
|
|
2434
|
-
* https://developers.google.com/protocol-buffers/docs/encoding
|
|
2435
|
-
*/
|
|
2436
|
-
class ReflectionBinaryWriter {
|
|
2437
|
-
constructor(info) {
|
|
2438
|
-
this.info = info;
|
|
2439
|
-
}
|
|
2440
|
-
prepare() {
|
|
2441
|
-
if (!this.fields) {
|
|
2442
|
-
const fieldsInput = this.info.fields ? this.info.fields.concat() : [];
|
|
2443
|
-
this.fields = fieldsInput.sort((a, b) => a.no - b.no);
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
/**
|
|
2447
|
-
* Writes the message to binary format.
|
|
2448
|
-
*/
|
|
2449
|
-
write(message, writer, options) {
|
|
2450
|
-
this.prepare();
|
|
2451
|
-
for (const field of this.fields) {
|
|
2452
|
-
let value, // this will be our field value, whether it is member of a oneof or not
|
|
2453
|
-
emitDefault, // whether we emit the default value (only true for oneof members)
|
|
2454
|
-
repeated = field.repeat, localName = field.localName;
|
|
2455
|
-
// handle oneof ADT
|
|
2456
|
-
if (field.oneof) {
|
|
2457
|
-
const group = message[field.oneof];
|
|
2458
|
-
if (group.oneofKind !== localName)
|
|
2459
|
-
continue; // if field is not selected, skip
|
|
2460
|
-
value = group[localName];
|
|
2461
|
-
emitDefault = true;
|
|
2462
|
-
}
|
|
2463
|
-
else {
|
|
2464
|
-
value = message[localName];
|
|
2465
|
-
emitDefault = false;
|
|
2466
|
-
}
|
|
2467
|
-
// we have handled oneof above. we just have to honor `emitDefault`.
|
|
2468
|
-
switch (field.kind) {
|
|
2469
|
-
case "scalar":
|
|
2470
|
-
case "enum":
|
|
2471
|
-
let T = field.kind == "enum" ? ScalarType.INT32 : field.T;
|
|
2472
|
-
if (repeated) {
|
|
2473
|
-
assert(Array.isArray(value));
|
|
2474
|
-
if (repeated == RepeatType.PACKED)
|
|
2475
|
-
this.packed(writer, T, field.no, value);
|
|
2476
|
-
else
|
|
2477
|
-
for (const item of value)
|
|
2478
|
-
this.scalar(writer, T, field.no, item, true);
|
|
2479
|
-
}
|
|
2480
|
-
else if (value === undefined)
|
|
2481
|
-
assert(field.opt);
|
|
2482
|
-
else
|
|
2483
|
-
this.scalar(writer, T, field.no, value, emitDefault || field.opt);
|
|
2484
|
-
break;
|
|
2485
|
-
case "message":
|
|
2486
|
-
if (repeated) {
|
|
2487
|
-
assert(Array.isArray(value));
|
|
2488
|
-
for (const item of value)
|
|
2489
|
-
this.message(writer, options, field.T(), field.no, item);
|
|
2490
|
-
}
|
|
2491
|
-
else {
|
|
2492
|
-
this.message(writer, options, field.T(), field.no, value);
|
|
2493
|
-
}
|
|
2494
|
-
break;
|
|
2495
|
-
case "map":
|
|
2496
|
-
assert(typeof value == 'object' && value !== null);
|
|
2497
|
-
for (const [key, val] of Object.entries(value))
|
|
2498
|
-
this.mapEntry(writer, options, field, key, val);
|
|
2499
|
-
break;
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
let u = options.writeUnknownFields;
|
|
2503
|
-
if (u !== false)
|
|
2504
|
-
(u === true ? UnknownFieldHandler.onWrite : u)(this.info.typeName, message, writer);
|
|
2505
|
-
}
|
|
2506
|
-
mapEntry(writer, options, field, key, value) {
|
|
2507
|
-
writer.tag(field.no, WireType.LengthDelimited);
|
|
2508
|
-
writer.fork();
|
|
2509
|
-
// javascript only allows number or string for object properties
|
|
2510
|
-
// we convert from our representation to the protobuf type
|
|
2511
|
-
let keyValue = key;
|
|
2512
|
-
switch (field.K) {
|
|
2513
|
-
case ScalarType.INT32:
|
|
2514
|
-
case ScalarType.FIXED32:
|
|
2515
|
-
case ScalarType.UINT32:
|
|
2516
|
-
case ScalarType.SFIXED32:
|
|
2517
|
-
case ScalarType.SINT32:
|
|
2518
|
-
keyValue = Number.parseInt(key);
|
|
2519
|
-
break;
|
|
2520
|
-
case ScalarType.BOOL:
|
|
2521
|
-
assert(key == 'true' || key == 'false');
|
|
2522
|
-
keyValue = key == 'true';
|
|
2523
|
-
break;
|
|
2524
|
-
}
|
|
2525
|
-
// write key, expecting key field number = 1
|
|
2526
|
-
this.scalar(writer, field.K, 1, keyValue, true);
|
|
2527
|
-
// write value, expecting value field number = 2
|
|
2528
|
-
switch (field.V.kind) {
|
|
2529
|
-
case 'scalar':
|
|
2530
|
-
this.scalar(writer, field.V.T, 2, value, true);
|
|
2531
|
-
break;
|
|
2532
|
-
case 'enum':
|
|
2533
|
-
this.scalar(writer, ScalarType.INT32, 2, value, true);
|
|
2534
|
-
break;
|
|
2535
|
-
case 'message':
|
|
2536
|
-
this.message(writer, options, field.V.T(), 2, value);
|
|
2537
|
-
break;
|
|
2538
|
-
}
|
|
2539
|
-
writer.join();
|
|
2540
|
-
}
|
|
2541
|
-
message(writer, options, handler, fieldNo, value) {
|
|
2542
|
-
if (value === undefined)
|
|
2543
|
-
return;
|
|
2544
|
-
handler.internalBinaryWrite(value, writer.tag(fieldNo, WireType.LengthDelimited).fork(), options);
|
|
2545
|
-
writer.join();
|
|
2546
|
-
}
|
|
2547
|
-
/**
|
|
2548
|
-
* Write a single scalar value.
|
|
2549
|
-
*/
|
|
2550
|
-
scalar(writer, type, fieldNo, value, emitDefault) {
|
|
2551
|
-
let [wireType, method, isDefault] = this.scalarInfo(type, value);
|
|
2552
|
-
if (!isDefault || emitDefault) {
|
|
2553
|
-
writer.tag(fieldNo, wireType);
|
|
2554
|
-
writer[method](value);
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
/**
|
|
2558
|
-
* Write an array of scalar values in packed format.
|
|
2559
|
-
*/
|
|
2560
|
-
packed(writer, type, fieldNo, value) {
|
|
2561
|
-
if (!value.length)
|
|
2562
|
-
return;
|
|
2563
|
-
assert(type !== ScalarType.BYTES && type !== ScalarType.STRING);
|
|
2564
|
-
// write tag
|
|
2565
|
-
writer.tag(fieldNo, WireType.LengthDelimited);
|
|
2566
|
-
// begin length-delimited
|
|
2567
|
-
writer.fork();
|
|
2568
|
-
// write values without tags
|
|
2569
|
-
let [, method,] = this.scalarInfo(type);
|
|
2570
|
-
for (let i = 0; i < value.length; i++)
|
|
2571
|
-
writer[method](value[i]);
|
|
2572
|
-
// end length delimited
|
|
2573
|
-
writer.join();
|
|
2574
|
-
}
|
|
2575
|
-
/**
|
|
2576
|
-
* Get information for writing a scalar value.
|
|
2577
|
-
*
|
|
2578
|
-
* Returns tuple:
|
|
2579
|
-
* [0]: appropriate WireType
|
|
2580
|
-
* [1]: name of the appropriate method of IBinaryWriter
|
|
2581
|
-
* [2]: whether the given value is a default value
|
|
2582
|
-
*
|
|
2583
|
-
* If argument `value` is omitted, [2] is always false.
|
|
2584
|
-
*/
|
|
2585
|
-
scalarInfo(type, value) {
|
|
2586
|
-
let t = WireType.Varint;
|
|
2587
|
-
let m;
|
|
2588
|
-
let i = value === undefined;
|
|
2589
|
-
let d = value === 0;
|
|
2590
|
-
switch (type) {
|
|
2591
|
-
case ScalarType.INT32:
|
|
2592
|
-
m = "int32";
|
|
2593
|
-
break;
|
|
2594
|
-
case ScalarType.STRING:
|
|
2595
|
-
d = i || !value.length;
|
|
2596
|
-
t = WireType.LengthDelimited;
|
|
2597
|
-
m = "string";
|
|
2598
|
-
break;
|
|
2599
|
-
case ScalarType.BOOL:
|
|
2600
|
-
d = value === false;
|
|
2601
|
-
m = "bool";
|
|
2602
|
-
break;
|
|
2603
|
-
case ScalarType.UINT32:
|
|
2604
|
-
m = "uint32";
|
|
2605
|
-
break;
|
|
2606
|
-
case ScalarType.DOUBLE:
|
|
2607
|
-
t = WireType.Bit64;
|
|
2608
|
-
m = "double";
|
|
2609
|
-
break;
|
|
2610
|
-
case ScalarType.FLOAT:
|
|
2611
|
-
t = WireType.Bit32;
|
|
2612
|
-
m = "float";
|
|
2613
|
-
break;
|
|
2614
|
-
case ScalarType.INT64:
|
|
2615
|
-
d = i || PbLong.from(value).isZero();
|
|
2616
|
-
m = "int64";
|
|
2617
|
-
break;
|
|
2618
|
-
case ScalarType.UINT64:
|
|
2619
|
-
d = i || PbULong.from(value).isZero();
|
|
2620
|
-
m = "uint64";
|
|
2621
|
-
break;
|
|
2622
|
-
case ScalarType.FIXED64:
|
|
2623
|
-
d = i || PbULong.from(value).isZero();
|
|
2624
|
-
t = WireType.Bit64;
|
|
2625
|
-
m = "fixed64";
|
|
2626
|
-
break;
|
|
2627
|
-
case ScalarType.BYTES:
|
|
2628
|
-
d = i || !value.byteLength;
|
|
2629
|
-
t = WireType.LengthDelimited;
|
|
2630
|
-
m = "bytes";
|
|
2631
|
-
break;
|
|
2632
|
-
case ScalarType.FIXED32:
|
|
2633
|
-
t = WireType.Bit32;
|
|
2634
|
-
m = "fixed32";
|
|
2635
|
-
break;
|
|
2636
|
-
case ScalarType.SFIXED32:
|
|
2637
|
-
t = WireType.Bit32;
|
|
2638
|
-
m = "sfixed32";
|
|
2639
|
-
break;
|
|
2640
|
-
case ScalarType.SFIXED64:
|
|
2641
|
-
d = i || PbLong.from(value).isZero();
|
|
2642
|
-
t = WireType.Bit64;
|
|
2643
|
-
m = "sfixed64";
|
|
2644
|
-
break;
|
|
2645
|
-
case ScalarType.SINT32:
|
|
2646
|
-
m = "sint32";
|
|
2647
|
-
break;
|
|
2648
|
-
case ScalarType.SINT64:
|
|
2649
|
-
d = i || PbLong.from(value).isZero();
|
|
2650
|
-
m = "sint64";
|
|
2651
|
-
break;
|
|
2652
|
-
}
|
|
2653
|
-
return [t, m, i || d];
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
/**
|
|
2658
|
-
* Creates an instance of the generic message, using the field
|
|
2659
|
-
* information.
|
|
2660
|
-
*/
|
|
2661
|
-
function reflectionCreate(type) {
|
|
2662
|
-
const msg = {};
|
|
2663
|
-
Object.defineProperty(msg, MESSAGE_TYPE, { enumerable: false, value: type });
|
|
2664
|
-
for (let field of type.fields) {
|
|
2665
|
-
let name = field.localName;
|
|
2666
|
-
if (field.opt)
|
|
2667
|
-
continue;
|
|
2668
|
-
if (field.oneof)
|
|
2669
|
-
msg[field.oneof] = { oneofKind: undefined };
|
|
2670
|
-
else if (field.repeat)
|
|
2671
|
-
msg[name] = [];
|
|
2672
|
-
else
|
|
2673
|
-
switch (field.kind) {
|
|
2674
|
-
case "scalar":
|
|
2675
|
-
msg[name] = reflectionScalarDefault(field.T, field.L);
|
|
2676
|
-
break;
|
|
2677
|
-
case "enum":
|
|
2678
|
-
// we require 0 to be default value for all enums
|
|
2679
|
-
msg[name] = 0;
|
|
2680
|
-
break;
|
|
2681
|
-
case "map":
|
|
2682
|
-
msg[name] = {};
|
|
2683
|
-
break;
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
return msg;
|
|
2687
|
-
}
|
|
2688
|
-
|
|
2689
|
-
/**
|
|
2690
|
-
* Copy partial data into the target message.
|
|
2691
|
-
*
|
|
2692
|
-
* If a singular scalar or enum field is present in the source, it
|
|
2693
|
-
* replaces the field in the target.
|
|
2694
|
-
*
|
|
2695
|
-
* If a singular message field is present in the source, it is merged
|
|
2696
|
-
* with the target field by calling mergePartial() of the responsible
|
|
2697
|
-
* message type.
|
|
2698
|
-
*
|
|
2699
|
-
* If a repeated field is present in the source, its values replace
|
|
2700
|
-
* all values in the target array, removing extraneous values.
|
|
2701
|
-
* Repeated message fields are copied, not merged.
|
|
2702
|
-
*
|
|
2703
|
-
* If a map field is present in the source, entries are added to the
|
|
2704
|
-
* target map, replacing entries with the same key. Entries that only
|
|
2705
|
-
* exist in the target remain. Entries with message values are copied,
|
|
2706
|
-
* not merged.
|
|
2707
|
-
*
|
|
2708
|
-
* Note that this function differs from protobuf merge semantics,
|
|
2709
|
-
* which appends repeated fields.
|
|
2710
|
-
*/
|
|
2711
|
-
function reflectionMergePartial(info, target, source) {
|
|
2712
|
-
let fieldValue, // the field value we are working with
|
|
2713
|
-
input = source, output; // where we want our field value to go
|
|
2714
|
-
for (let field of info.fields) {
|
|
2715
|
-
let name = field.localName;
|
|
2716
|
-
if (field.oneof) {
|
|
2717
|
-
const group = input[field.oneof]; // this is the oneof`s group in the source
|
|
2718
|
-
if ((group === null || group === void 0 ? void 0 : group.oneofKind) == undefined) { // the user is free to omit
|
|
2719
|
-
continue; // we skip this field, and all other members too
|
|
2720
|
-
}
|
|
2721
|
-
fieldValue = group[name]; // our value comes from the the oneof group of the source
|
|
2722
|
-
output = target[field.oneof]; // and our output is the oneof group of the target
|
|
2723
|
-
output.oneofKind = group.oneofKind; // always update discriminator
|
|
2724
|
-
if (fieldValue == undefined) {
|
|
2725
|
-
delete output[name]; // remove any existing value
|
|
2726
|
-
continue; // skip further work on field
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
else {
|
|
2730
|
-
fieldValue = input[name]; // we are using the source directly
|
|
2731
|
-
output = target; // we want our field value to go directly into the target
|
|
2732
|
-
if (fieldValue == undefined) {
|
|
2733
|
-
continue; // skip further work on field, existing value is used as is
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
if (field.repeat)
|
|
2737
|
-
output[name].length = fieldValue.length; // resize target array to match source array
|
|
2738
|
-
// now we just work with `fieldValue` and `output` to merge the value
|
|
2739
|
-
switch (field.kind) {
|
|
2740
|
-
case "scalar":
|
|
2741
|
-
case "enum":
|
|
2742
|
-
if (field.repeat)
|
|
2743
|
-
for (let i = 0; i < fieldValue.length; i++)
|
|
2744
|
-
output[name][i] = fieldValue[i]; // not a reference type
|
|
2745
|
-
else
|
|
2746
|
-
output[name] = fieldValue; // not a reference type
|
|
2747
|
-
break;
|
|
2748
|
-
case "message":
|
|
2749
|
-
let T = field.T();
|
|
2750
|
-
if (field.repeat)
|
|
2751
|
-
for (let i = 0; i < fieldValue.length; i++)
|
|
2752
|
-
output[name][i] = T.create(fieldValue[i]);
|
|
2753
|
-
else if (output[name] === undefined)
|
|
2754
|
-
output[name] = T.create(fieldValue); // nothing to merge with
|
|
2755
|
-
else
|
|
2756
|
-
T.mergePartial(output[name], fieldValue);
|
|
2757
|
-
break;
|
|
2758
|
-
case "map":
|
|
2759
|
-
// Map and repeated fields are simply overwritten, not appended or merged
|
|
2760
|
-
switch (field.V.kind) {
|
|
2761
|
-
case "scalar":
|
|
2762
|
-
case "enum":
|
|
2763
|
-
Object.assign(output[name], fieldValue); // elements are not reference types
|
|
2764
|
-
break;
|
|
2765
|
-
case "message":
|
|
2766
|
-
let T = field.V.T();
|
|
2767
|
-
for (let k of Object.keys(fieldValue))
|
|
2768
|
-
output[name][k] = T.create(fieldValue[k]);
|
|
2769
|
-
break;
|
|
2770
|
-
}
|
|
2771
|
-
break;
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2776
|
-
/**
|
|
2777
|
-
* Determines whether two message of the same type have the same field values.
|
|
2778
|
-
* Checks for deep equality, traversing repeated fields, oneof groups, maps
|
|
2779
|
-
* and messages recursively.
|
|
2780
|
-
* Will also return true if both messages are `undefined`.
|
|
2781
|
-
*/
|
|
2782
|
-
function reflectionEquals(info, a, b) {
|
|
2783
|
-
if (a === b)
|
|
2784
|
-
return true;
|
|
2785
|
-
if (!a || !b)
|
|
2786
|
-
return false;
|
|
2787
|
-
for (let field of info.fields) {
|
|
2788
|
-
let localName = field.localName;
|
|
2789
|
-
let val_a = field.oneof ? a[field.oneof][localName] : a[localName];
|
|
2790
|
-
let val_b = field.oneof ? b[field.oneof][localName] : b[localName];
|
|
2791
|
-
switch (field.kind) {
|
|
2792
|
-
case "enum":
|
|
2793
|
-
case "scalar":
|
|
2794
|
-
let t = field.kind == "enum" ? ScalarType.INT32 : field.T;
|
|
2795
|
-
if (!(field.repeat
|
|
2796
|
-
? repeatedPrimitiveEq(t, val_a, val_b)
|
|
2797
|
-
: primitiveEq(t, val_a, val_b)))
|
|
2798
|
-
return false;
|
|
2799
|
-
break;
|
|
2800
|
-
case "map":
|
|
2801
|
-
if (!(field.V.kind == "message"
|
|
2802
|
-
? repeatedMsgEq(field.V.T(), objectValues(val_a), objectValues(val_b))
|
|
2803
|
-
: repeatedPrimitiveEq(field.V.kind == "enum" ? ScalarType.INT32 : field.V.T, objectValues(val_a), objectValues(val_b))))
|
|
2804
|
-
return false;
|
|
2805
|
-
break;
|
|
2806
|
-
case "message":
|
|
2807
|
-
let T = field.T();
|
|
2808
|
-
if (!(field.repeat
|
|
2809
|
-
? repeatedMsgEq(T, val_a, val_b)
|
|
2810
|
-
: T.equals(val_a, val_b)))
|
|
2811
|
-
return false;
|
|
2812
|
-
break;
|
|
2813
|
-
}
|
|
2814
|
-
}
|
|
2815
|
-
return true;
|
|
2816
|
-
}
|
|
2817
|
-
const objectValues = Object.values;
|
|
2818
|
-
function primitiveEq(type, a, b) {
|
|
2819
|
-
if (a === b)
|
|
2820
|
-
return true;
|
|
2821
|
-
if (type !== ScalarType.BYTES)
|
|
2822
|
-
return false;
|
|
2823
|
-
let ba = a;
|
|
2824
|
-
let bb = b;
|
|
2825
|
-
if (ba.length !== bb.length)
|
|
2826
|
-
return false;
|
|
2827
|
-
for (let i = 0; i < ba.length; i++)
|
|
2828
|
-
if (ba[i] != bb[i])
|
|
2829
|
-
return false;
|
|
2830
|
-
return true;
|
|
2831
|
-
}
|
|
2832
|
-
function repeatedPrimitiveEq(type, a, b) {
|
|
2833
|
-
if (a.length !== b.length)
|
|
2834
|
-
return false;
|
|
2835
|
-
for (let i = 0; i < a.length; i++)
|
|
2836
|
-
if (!primitiveEq(type, a[i], b[i]))
|
|
2837
|
-
return false;
|
|
2838
|
-
return true;
|
|
2839
|
-
}
|
|
2840
|
-
function repeatedMsgEq(type, a, b) {
|
|
2841
|
-
if (a.length !== b.length)
|
|
2842
|
-
return false;
|
|
2843
|
-
for (let i = 0; i < a.length; i++)
|
|
2844
|
-
if (!type.equals(a[i], b[i]))
|
|
2845
|
-
return false;
|
|
2846
|
-
return true;
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2849
|
-
/**
|
|
2850
|
-
* This standard message type provides reflection-based
|
|
2851
|
-
* operations to work with a message.
|
|
2852
|
-
*/
|
|
2853
|
-
class MessageType {
|
|
2854
|
-
constructor(name, fields, options) {
|
|
2855
|
-
this.defaultCheckDepth = 16;
|
|
2856
|
-
this.typeName = name;
|
|
2857
|
-
this.fields = fields.map(normalizeFieldInfo);
|
|
2858
|
-
this.options = options !== null && options !== void 0 ? options : {};
|
|
2859
|
-
this.refTypeCheck = new ReflectionTypeCheck(this);
|
|
2860
|
-
this.refJsonReader = new ReflectionJsonReader(this);
|
|
2861
|
-
this.refJsonWriter = new ReflectionJsonWriter(this);
|
|
2862
|
-
this.refBinReader = new ReflectionBinaryReader(this);
|
|
2863
|
-
this.refBinWriter = new ReflectionBinaryWriter(this);
|
|
2864
|
-
}
|
|
2865
|
-
create(value) {
|
|
2866
|
-
let message = reflectionCreate(this);
|
|
2867
|
-
if (value !== undefined) {
|
|
2868
|
-
reflectionMergePartial(this, message, value);
|
|
2869
|
-
}
|
|
2870
|
-
return message;
|
|
2871
|
-
}
|
|
2872
|
-
/**
|
|
2873
|
-
* Clone the message.
|
|
2874
|
-
*
|
|
2875
|
-
* Unknown fields are discarded.
|
|
2876
|
-
*/
|
|
2877
|
-
clone(message) {
|
|
2878
|
-
let copy = this.create();
|
|
2879
|
-
reflectionMergePartial(this, copy, message);
|
|
2880
|
-
return copy;
|
|
2881
|
-
}
|
|
2882
|
-
/**
|
|
2883
|
-
* Determines whether two message of the same type have the same field values.
|
|
2884
|
-
* Checks for deep equality, traversing repeated fields, oneof groups, maps
|
|
2885
|
-
* and messages recursively.
|
|
2886
|
-
* Will also return true if both messages are `undefined`.
|
|
2887
|
-
*/
|
|
2888
|
-
equals(a, b) {
|
|
2889
|
-
return reflectionEquals(this, a, b);
|
|
2890
|
-
}
|
|
2891
|
-
/**
|
|
2892
|
-
* Is the given value assignable to our message type
|
|
2893
|
-
* and contains no [excess properties](https://www.typescriptlang.org/docs/handbook/interfaces.html#excess-property-checks)?
|
|
2894
|
-
*/
|
|
2895
|
-
is(arg, depth = this.defaultCheckDepth) {
|
|
2896
|
-
return this.refTypeCheck.is(arg, depth, false);
|
|
2897
|
-
}
|
|
2898
|
-
/**
|
|
2899
|
-
* Is the given value assignable to our message type,
|
|
2900
|
-
* regardless of [excess properties](https://www.typescriptlang.org/docs/handbook/interfaces.html#excess-property-checks)?
|
|
2901
|
-
*/
|
|
2902
|
-
isAssignable(arg, depth = this.defaultCheckDepth) {
|
|
2903
|
-
return this.refTypeCheck.is(arg, depth, true);
|
|
2904
|
-
}
|
|
2905
|
-
/**
|
|
2906
|
-
* Copy partial data into the target message.
|
|
2907
|
-
*/
|
|
2908
|
-
mergePartial(target, source) {
|
|
2909
|
-
reflectionMergePartial(this, target, source);
|
|
2910
|
-
}
|
|
2911
|
-
/**
|
|
2912
|
-
* Create a new message from binary format.
|
|
2913
|
-
*/
|
|
2914
|
-
fromBinary(data, options) {
|
|
2915
|
-
let opt = binaryReadOptions(options);
|
|
2916
|
-
return this.internalBinaryRead(opt.readerFactory(data), data.byteLength, opt);
|
|
2917
|
-
}
|
|
2918
|
-
/**
|
|
2919
|
-
* Read a new message from a JSON value.
|
|
2920
|
-
*/
|
|
2921
|
-
fromJson(json, options) {
|
|
2922
|
-
return this.internalJsonRead(json, jsonReadOptions(options));
|
|
2923
|
-
}
|
|
2924
|
-
/**
|
|
2925
|
-
* Read a new message from a JSON string.
|
|
2926
|
-
* This is equivalent to `T.fromJson(JSON.parse(json))`.
|
|
2927
|
-
*/
|
|
2928
|
-
fromJsonString(json, options) {
|
|
2929
|
-
let value = JSON.parse(json);
|
|
2930
|
-
return this.fromJson(value, options);
|
|
2931
|
-
}
|
|
2932
|
-
/**
|
|
2933
|
-
* Write the message to canonical JSON value.
|
|
2934
|
-
*/
|
|
2935
|
-
toJson(message, options) {
|
|
2936
|
-
return this.internalJsonWrite(message, jsonWriteOptions(options));
|
|
2937
|
-
}
|
|
2938
|
-
/**
|
|
2939
|
-
* Convert the message to canonical JSON string.
|
|
2940
|
-
* This is equivalent to `JSON.stringify(T.toJson(t))`
|
|
2941
|
-
*/
|
|
2942
|
-
toJsonString(message, options) {
|
|
2943
|
-
var _a;
|
|
2944
|
-
let value = this.toJson(message, options);
|
|
2945
|
-
return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
|
|
2946
|
-
}
|
|
2947
|
-
/**
|
|
2948
|
-
* Write the message to binary format.
|
|
2949
|
-
*/
|
|
2950
|
-
toBinary(message, options) {
|
|
2951
|
-
let opt = binaryWriteOptions(options);
|
|
2952
|
-
return this.internalBinaryWrite(message, opt.writerFactory(), opt).finish();
|
|
2953
|
-
}
|
|
2954
|
-
/**
|
|
2955
|
-
* This is an internal method. If you just want to read a message from
|
|
2956
|
-
* JSON, use `fromJson()` or `fromJsonString()`.
|
|
2957
|
-
*
|
|
2958
|
-
* Reads JSON value and merges the fields into the target
|
|
2959
|
-
* according to protobuf rules. If the target is omitted,
|
|
2960
|
-
* a new instance is created first.
|
|
2961
|
-
*/
|
|
2962
|
-
internalJsonRead(json, options, target) {
|
|
2963
|
-
if (json !== null && typeof json == "object" && !Array.isArray(json)) {
|
|
2964
|
-
let message = target !== null && target !== void 0 ? target : this.create();
|
|
2965
|
-
this.refJsonReader.read(json, message, options);
|
|
2966
|
-
return message;
|
|
2967
|
-
}
|
|
2968
|
-
throw new Error(`Unable to parse message ${this.typeName} from JSON ${typeofJsonValue(json)}.`);
|
|
2969
|
-
}
|
|
2970
|
-
/**
|
|
2971
|
-
* This is an internal method. If you just want to write a message
|
|
2972
|
-
* to JSON, use `toJson()` or `toJsonString().
|
|
2973
|
-
*
|
|
2974
|
-
* Writes JSON value and returns it.
|
|
2975
|
-
*/
|
|
2976
|
-
internalJsonWrite(message, options) {
|
|
2977
|
-
return this.refJsonWriter.write(message, options);
|
|
2978
|
-
}
|
|
2979
|
-
/**
|
|
2980
|
-
* This is an internal method. If you just want to write a message
|
|
2981
|
-
* in binary format, use `toBinary()`.
|
|
2982
|
-
*
|
|
2983
|
-
* Serializes the message in binary format and appends it to the given
|
|
2984
|
-
* writer. Returns passed writer.
|
|
2985
|
-
*/
|
|
2986
|
-
internalBinaryWrite(message, writer, options) {
|
|
2987
|
-
this.refBinWriter.write(message, writer, options);
|
|
2988
|
-
return writer;
|
|
2989
|
-
}
|
|
2990
|
-
/**
|
|
2991
|
-
* This is an internal method. If you just want to read a message from
|
|
2992
|
-
* binary data, use `fromBinary()`.
|
|
2993
|
-
*
|
|
2994
|
-
* Reads data from binary format and merges the fields into
|
|
2995
|
-
* the target according to protobuf rules. If the target is
|
|
2996
|
-
* omitted, a new instance is created first.
|
|
2997
|
-
*/
|
|
2998
|
-
internalBinaryRead(reader, length, options, target) {
|
|
2999
|
-
let message = target !== null && target !== void 0 ? target : this.create();
|
|
3000
|
-
this.refBinReader.read(reader, message, options, length);
|
|
3001
|
-
return message;
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
3004
|
-
|
|
3005
106
|
/**
|
|
3006
107
|
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
3007
108
|
* `Value` type union.
|
|
@@ -3020,7 +121,7 @@ var NullValue;
|
|
|
3020
121
|
NullValue[NullValue["NULL_VALUE"] = 0] = "NULL_VALUE";
|
|
3021
122
|
})(NullValue || (NullValue = {}));
|
|
3022
123
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3023
|
-
class Struct$Type extends MessageType {
|
|
124
|
+
class Struct$Type extends runtime.MessageType {
|
|
3024
125
|
constructor() {
|
|
3025
126
|
super("google.protobuf.Struct", [
|
|
3026
127
|
{ no: 1, name: "fields", kind: "map", K: 9 /*ScalarType.STRING*/, V: { kind: "message", T: () => Value } }
|
|
@@ -3040,8 +141,8 @@ class Struct$Type extends MessageType {
|
|
|
3040
141
|
* Decode `Struct` from JSON object.
|
|
3041
142
|
*/
|
|
3042
143
|
internalJsonRead(json, options, target) {
|
|
3043
|
-
if (!isJsonObject(json))
|
|
3044
|
-
throw new globalThis.Error("Unable to parse message " + this.typeName + " from JSON " + typeofJsonValue(json) + ".");
|
|
144
|
+
if (!runtime.isJsonObject(json))
|
|
145
|
+
throw new globalThis.Error("Unable to parse message " + this.typeName + " from JSON " + runtime.typeofJsonValue(json) + ".");
|
|
3045
146
|
if (!target)
|
|
3046
147
|
target = this.create();
|
|
3047
148
|
for (let [k, v] of globalThis.Object.entries(json)) {
|
|
@@ -3051,9 +152,9 @@ class Struct$Type extends MessageType {
|
|
|
3051
152
|
}
|
|
3052
153
|
create(value) {
|
|
3053
154
|
const message = { fields: {} };
|
|
3054
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
155
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3055
156
|
if (value !== undefined)
|
|
3056
|
-
reflectionMergePartial(this, message, value);
|
|
157
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3057
158
|
return message;
|
|
3058
159
|
}
|
|
3059
160
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3070,7 +171,7 @@ class Struct$Type extends MessageType {
|
|
|
3070
171
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3071
172
|
let d = reader.skip(wireType);
|
|
3072
173
|
if (u !== false)
|
|
3073
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
174
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3074
175
|
}
|
|
3075
176
|
}
|
|
3076
177
|
return message;
|
|
@@ -3094,14 +195,14 @@ class Struct$Type extends MessageType {
|
|
|
3094
195
|
internalBinaryWrite(message, writer, options) {
|
|
3095
196
|
/* map<string, google.protobuf.Value> fields = 1; */
|
|
3096
197
|
for (let k of Object.keys(message.fields)) {
|
|
3097
|
-
writer.tag(1, WireType.LengthDelimited).fork().tag(1, WireType.LengthDelimited).string(k);
|
|
3098
|
-
writer.tag(2, WireType.LengthDelimited).fork();
|
|
198
|
+
writer.tag(1, runtime.WireType.LengthDelimited).fork().tag(1, runtime.WireType.LengthDelimited).string(k);
|
|
199
|
+
writer.tag(2, runtime.WireType.LengthDelimited).fork();
|
|
3099
200
|
Value.internalBinaryWrite(message.fields[k], writer, options);
|
|
3100
201
|
writer.join().join();
|
|
3101
202
|
}
|
|
3102
203
|
let u = options.writeUnknownFields;
|
|
3103
204
|
if (u !== false)
|
|
3104
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
205
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3105
206
|
return writer;
|
|
3106
207
|
}
|
|
3107
208
|
}
|
|
@@ -3110,7 +211,7 @@ class Struct$Type extends MessageType {
|
|
|
3110
211
|
*/
|
|
3111
212
|
const Struct = new Struct$Type();
|
|
3112
213
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3113
|
-
class Value$Type extends MessageType {
|
|
214
|
+
class Value$Type extends runtime.MessageType {
|
|
3114
215
|
constructor() {
|
|
3115
216
|
super("google.protobuf.Value", [
|
|
3116
217
|
{ no: 1, name: "null_value", kind: "enum", oneof: "kind", T: () => ["google.protobuf.NullValue", NullValue] },
|
|
@@ -3173,15 +274,15 @@ class Value$Type extends MessageType {
|
|
|
3173
274
|
target.kind = { oneofKind: "structValue", structValue: Struct.fromJson(json) };
|
|
3174
275
|
}
|
|
3175
276
|
break;
|
|
3176
|
-
default: throw new globalThis.Error("Unable to parse " + this.typeName + " from JSON " + typeofJsonValue(json));
|
|
277
|
+
default: throw new globalThis.Error("Unable to parse " + this.typeName + " from JSON " + runtime.typeofJsonValue(json));
|
|
3177
278
|
}
|
|
3178
279
|
return target;
|
|
3179
280
|
}
|
|
3180
281
|
create(value) {
|
|
3181
282
|
const message = { kind: { oneofKind: undefined } };
|
|
3182
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
283
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3183
284
|
if (value !== undefined)
|
|
3184
|
-
reflectionMergePartial(this, message, value);
|
|
285
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3185
286
|
return message;
|
|
3186
287
|
}
|
|
3187
288
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3231,7 +332,7 @@ class Value$Type extends MessageType {
|
|
|
3231
332
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3232
333
|
let d = reader.skip(wireType);
|
|
3233
334
|
if (u !== false)
|
|
3234
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
335
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3235
336
|
}
|
|
3236
337
|
}
|
|
3237
338
|
return message;
|
|
@@ -3239,25 +340,25 @@ class Value$Type extends MessageType {
|
|
|
3239
340
|
internalBinaryWrite(message, writer, options) {
|
|
3240
341
|
/* google.protobuf.NullValue null_value = 1; */
|
|
3241
342
|
if (message.kind.oneofKind === "nullValue")
|
|
3242
|
-
writer.tag(1, WireType.Varint).int32(message.kind.nullValue);
|
|
343
|
+
writer.tag(1, runtime.WireType.Varint).int32(message.kind.nullValue);
|
|
3243
344
|
/* double number_value = 2; */
|
|
3244
345
|
if (message.kind.oneofKind === "numberValue")
|
|
3245
|
-
writer.tag(2, WireType.Bit64).double(message.kind.numberValue);
|
|
346
|
+
writer.tag(2, runtime.WireType.Bit64).double(message.kind.numberValue);
|
|
3246
347
|
/* string string_value = 3; */
|
|
3247
348
|
if (message.kind.oneofKind === "stringValue")
|
|
3248
|
-
writer.tag(3, WireType.LengthDelimited).string(message.kind.stringValue);
|
|
349
|
+
writer.tag(3, runtime.WireType.LengthDelimited).string(message.kind.stringValue);
|
|
3249
350
|
/* bool bool_value = 4; */
|
|
3250
351
|
if (message.kind.oneofKind === "boolValue")
|
|
3251
|
-
writer.tag(4, WireType.Varint).bool(message.kind.boolValue);
|
|
352
|
+
writer.tag(4, runtime.WireType.Varint).bool(message.kind.boolValue);
|
|
3252
353
|
/* google.protobuf.Struct struct_value = 5; */
|
|
3253
354
|
if (message.kind.oneofKind === "structValue")
|
|
3254
|
-
Struct.internalBinaryWrite(message.kind.structValue, writer.tag(5, WireType.LengthDelimited).fork(), options).join();
|
|
355
|
+
Struct.internalBinaryWrite(message.kind.structValue, writer.tag(5, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3255
356
|
/* google.protobuf.ListValue list_value = 6; */
|
|
3256
357
|
if (message.kind.oneofKind === "listValue")
|
|
3257
|
-
ListValue.internalBinaryWrite(message.kind.listValue, writer.tag(6, WireType.LengthDelimited).fork(), options).join();
|
|
358
|
+
ListValue.internalBinaryWrite(message.kind.listValue, writer.tag(6, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3258
359
|
let u = options.writeUnknownFields;
|
|
3259
360
|
if (u !== false)
|
|
3260
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
361
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3261
362
|
return writer;
|
|
3262
363
|
}
|
|
3263
364
|
}
|
|
@@ -3266,7 +367,7 @@ class Value$Type extends MessageType {
|
|
|
3266
367
|
*/
|
|
3267
368
|
const Value = new Value$Type();
|
|
3268
369
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3269
|
-
class ListValue$Type extends MessageType {
|
|
370
|
+
class ListValue$Type extends runtime.MessageType {
|
|
3270
371
|
constructor() {
|
|
3271
372
|
super("google.protobuf.ListValue", [
|
|
3272
373
|
{ no: 1, name: "values", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => Value }
|
|
@@ -3283,7 +384,7 @@ class ListValue$Type extends MessageType {
|
|
|
3283
384
|
*/
|
|
3284
385
|
internalJsonRead(json, options, target) {
|
|
3285
386
|
if (!globalThis.Array.isArray(json))
|
|
3286
|
-
throw new globalThis.Error("Unable to parse " + this.typeName + " from JSON " + typeofJsonValue(json));
|
|
387
|
+
throw new globalThis.Error("Unable to parse " + this.typeName + " from JSON " + runtime.typeofJsonValue(json));
|
|
3287
388
|
if (!target)
|
|
3288
389
|
target = this.create();
|
|
3289
390
|
let values = json.map(v => Value.fromJson(v));
|
|
@@ -3292,9 +393,9 @@ class ListValue$Type extends MessageType {
|
|
|
3292
393
|
}
|
|
3293
394
|
create(value) {
|
|
3294
395
|
const message = { values: [] };
|
|
3295
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
396
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3296
397
|
if (value !== undefined)
|
|
3297
|
-
reflectionMergePartial(this, message, value);
|
|
398
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3298
399
|
return message;
|
|
3299
400
|
}
|
|
3300
401
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3311,7 +412,7 @@ class ListValue$Type extends MessageType {
|
|
|
3311
412
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3312
413
|
let d = reader.skip(wireType);
|
|
3313
414
|
if (u !== false)
|
|
3314
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
415
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3315
416
|
}
|
|
3316
417
|
}
|
|
3317
418
|
return message;
|
|
@@ -3319,10 +420,10 @@ class ListValue$Type extends MessageType {
|
|
|
3319
420
|
internalBinaryWrite(message, writer, options) {
|
|
3320
421
|
/* repeated google.protobuf.Value values = 1; */
|
|
3321
422
|
for (let i = 0; i < message.values.length; i++)
|
|
3322
|
-
Value.internalBinaryWrite(message.values[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join();
|
|
423
|
+
Value.internalBinaryWrite(message.values[i], writer.tag(1, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3323
424
|
let u = options.writeUnknownFields;
|
|
3324
425
|
if (u !== false)
|
|
3325
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
426
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3326
427
|
return writer;
|
|
3327
428
|
}
|
|
3328
429
|
}
|
|
@@ -3333,7 +434,7 @@ const ListValue = new ListValue$Type();
|
|
|
3333
434
|
|
|
3334
435
|
// @generated by protobuf-ts 2.2.2 with parameter long_type_string,generate_dependencies
|
|
3335
436
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3336
|
-
class ResolveAllRequest$Type extends MessageType {
|
|
437
|
+
class ResolveAllRequest$Type extends runtime.MessageType {
|
|
3337
438
|
constructor() {
|
|
3338
439
|
super("schema.v1.ResolveAllRequest", [
|
|
3339
440
|
{ no: 1, name: "context", kind: "message", T: () => Struct }
|
|
@@ -3341,9 +442,9 @@ class ResolveAllRequest$Type extends MessageType {
|
|
|
3341
442
|
}
|
|
3342
443
|
create(value) {
|
|
3343
444
|
const message = {};
|
|
3344
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
445
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3345
446
|
if (value !== undefined)
|
|
3346
|
-
reflectionMergePartial(this, message, value);
|
|
447
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3347
448
|
return message;
|
|
3348
449
|
}
|
|
3349
450
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3360,7 +461,7 @@ class ResolveAllRequest$Type extends MessageType {
|
|
|
3360
461
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3361
462
|
let d = reader.skip(wireType);
|
|
3362
463
|
if (u !== false)
|
|
3363
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
464
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3364
465
|
}
|
|
3365
466
|
}
|
|
3366
467
|
return message;
|
|
@@ -3368,10 +469,10 @@ class ResolveAllRequest$Type extends MessageType {
|
|
|
3368
469
|
internalBinaryWrite(message, writer, options) {
|
|
3369
470
|
/* google.protobuf.Struct context = 1; */
|
|
3370
471
|
if (message.context)
|
|
3371
|
-
Struct.internalBinaryWrite(message.context, writer.tag(1, WireType.LengthDelimited).fork(), options).join();
|
|
472
|
+
Struct.internalBinaryWrite(message.context, writer.tag(1, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3372
473
|
let u = options.writeUnknownFields;
|
|
3373
474
|
if (u !== false)
|
|
3374
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
475
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3375
476
|
return writer;
|
|
3376
477
|
}
|
|
3377
478
|
}
|
|
@@ -3380,7 +481,7 @@ class ResolveAllRequest$Type extends MessageType {
|
|
|
3380
481
|
*/
|
|
3381
482
|
const ResolveAllRequest = new ResolveAllRequest$Type();
|
|
3382
483
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3383
|
-
class ResolveAllResponse$Type extends MessageType {
|
|
484
|
+
class ResolveAllResponse$Type extends runtime.MessageType {
|
|
3384
485
|
constructor() {
|
|
3385
486
|
super("schema.v1.ResolveAllResponse", [
|
|
3386
487
|
{ no: 1, name: "flags", kind: "map", K: 9 /*ScalarType.STRING*/, V: { kind: "message", T: () => AnyFlag } }
|
|
@@ -3388,9 +489,9 @@ class ResolveAllResponse$Type extends MessageType {
|
|
|
3388
489
|
}
|
|
3389
490
|
create(value) {
|
|
3390
491
|
const message = { flags: {} };
|
|
3391
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
492
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3392
493
|
if (value !== undefined)
|
|
3393
|
-
reflectionMergePartial(this, message, value);
|
|
494
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3394
495
|
return message;
|
|
3395
496
|
}
|
|
3396
497
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3407,7 +508,7 @@ class ResolveAllResponse$Type extends MessageType {
|
|
|
3407
508
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3408
509
|
let d = reader.skip(wireType);
|
|
3409
510
|
if (u !== false)
|
|
3410
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
511
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3411
512
|
}
|
|
3412
513
|
}
|
|
3413
514
|
return message;
|
|
@@ -3431,14 +532,14 @@ class ResolveAllResponse$Type extends MessageType {
|
|
|
3431
532
|
internalBinaryWrite(message, writer, options) {
|
|
3432
533
|
/* map<string, schema.v1.AnyFlag> flags = 1; */
|
|
3433
534
|
for (let k of Object.keys(message.flags)) {
|
|
3434
|
-
writer.tag(1, WireType.LengthDelimited).fork().tag(1, WireType.LengthDelimited).string(k);
|
|
3435
|
-
writer.tag(2, WireType.LengthDelimited).fork();
|
|
535
|
+
writer.tag(1, runtime.WireType.LengthDelimited).fork().tag(1, runtime.WireType.LengthDelimited).string(k);
|
|
536
|
+
writer.tag(2, runtime.WireType.LengthDelimited).fork();
|
|
3436
537
|
AnyFlag.internalBinaryWrite(message.flags[k], writer, options);
|
|
3437
538
|
writer.join().join();
|
|
3438
539
|
}
|
|
3439
540
|
let u = options.writeUnknownFields;
|
|
3440
541
|
if (u !== false)
|
|
3441
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
542
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3442
543
|
return writer;
|
|
3443
544
|
}
|
|
3444
545
|
}
|
|
@@ -3447,7 +548,7 @@ class ResolveAllResponse$Type extends MessageType {
|
|
|
3447
548
|
*/
|
|
3448
549
|
const ResolveAllResponse = new ResolveAllResponse$Type();
|
|
3449
550
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3450
|
-
class AnyFlag$Type extends MessageType {
|
|
551
|
+
class AnyFlag$Type extends runtime.MessageType {
|
|
3451
552
|
constructor() {
|
|
3452
553
|
super("schema.v1.AnyFlag", [
|
|
3453
554
|
{ no: 1, name: "reason", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -3460,9 +561,9 @@ class AnyFlag$Type extends MessageType {
|
|
|
3460
561
|
}
|
|
3461
562
|
create(value) {
|
|
3462
563
|
const message = { reason: "", variant: "", value: { oneofKind: undefined } };
|
|
3463
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
564
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3464
565
|
if (value !== undefined)
|
|
3465
|
-
reflectionMergePartial(this, message, value);
|
|
566
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3466
567
|
return message;
|
|
3467
568
|
}
|
|
3468
569
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3506,7 +607,7 @@ class AnyFlag$Type extends MessageType {
|
|
|
3506
607
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3507
608
|
let d = reader.skip(wireType);
|
|
3508
609
|
if (u !== false)
|
|
3509
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
610
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3510
611
|
}
|
|
3511
612
|
}
|
|
3512
613
|
return message;
|
|
@@ -3514,25 +615,25 @@ class AnyFlag$Type extends MessageType {
|
|
|
3514
615
|
internalBinaryWrite(message, writer, options) {
|
|
3515
616
|
/* string reason = 1; */
|
|
3516
617
|
if (message.reason !== "")
|
|
3517
|
-
writer.tag(1, WireType.LengthDelimited).string(message.reason);
|
|
618
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.reason);
|
|
3518
619
|
/* string variant = 2; */
|
|
3519
620
|
if (message.variant !== "")
|
|
3520
|
-
writer.tag(2, WireType.LengthDelimited).string(message.variant);
|
|
621
|
+
writer.tag(2, runtime.WireType.LengthDelimited).string(message.variant);
|
|
3521
622
|
/* bool bool_value = 3; */
|
|
3522
623
|
if (message.value.oneofKind === "boolValue")
|
|
3523
|
-
writer.tag(3, WireType.Varint).bool(message.value.boolValue);
|
|
624
|
+
writer.tag(3, runtime.WireType.Varint).bool(message.value.boolValue);
|
|
3524
625
|
/* string string_value = 4; */
|
|
3525
626
|
if (message.value.oneofKind === "stringValue")
|
|
3526
|
-
writer.tag(4, WireType.LengthDelimited).string(message.value.stringValue);
|
|
627
|
+
writer.tag(4, runtime.WireType.LengthDelimited).string(message.value.stringValue);
|
|
3527
628
|
/* double double_value = 5; */
|
|
3528
629
|
if (message.value.oneofKind === "doubleValue")
|
|
3529
|
-
writer.tag(5, WireType.Bit64).double(message.value.doubleValue);
|
|
630
|
+
writer.tag(5, runtime.WireType.Bit64).double(message.value.doubleValue);
|
|
3530
631
|
/* google.protobuf.Struct object_value = 6; */
|
|
3531
632
|
if (message.value.oneofKind === "objectValue")
|
|
3532
|
-
Struct.internalBinaryWrite(message.value.objectValue, writer.tag(6, WireType.LengthDelimited).fork(), options).join();
|
|
633
|
+
Struct.internalBinaryWrite(message.value.objectValue, writer.tag(6, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3533
634
|
let u = options.writeUnknownFields;
|
|
3534
635
|
if (u !== false)
|
|
3535
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
636
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3536
637
|
return writer;
|
|
3537
638
|
}
|
|
3538
639
|
}
|
|
@@ -3541,7 +642,7 @@ class AnyFlag$Type extends MessageType {
|
|
|
3541
642
|
*/
|
|
3542
643
|
const AnyFlag = new AnyFlag$Type();
|
|
3543
644
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3544
|
-
class ResolveBooleanRequest$Type extends MessageType {
|
|
645
|
+
class ResolveBooleanRequest$Type extends runtime.MessageType {
|
|
3545
646
|
constructor() {
|
|
3546
647
|
super("schema.v1.ResolveBooleanRequest", [
|
|
3547
648
|
{ no: 1, name: "flag_key", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -3550,9 +651,9 @@ class ResolveBooleanRequest$Type extends MessageType {
|
|
|
3550
651
|
}
|
|
3551
652
|
create(value) {
|
|
3552
653
|
const message = { flagKey: "" };
|
|
3553
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
654
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3554
655
|
if (value !== undefined)
|
|
3555
|
-
reflectionMergePartial(this, message, value);
|
|
656
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3556
657
|
return message;
|
|
3557
658
|
}
|
|
3558
659
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3572,7 +673,7 @@ class ResolveBooleanRequest$Type extends MessageType {
|
|
|
3572
673
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3573
674
|
let d = reader.skip(wireType);
|
|
3574
675
|
if (u !== false)
|
|
3575
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
676
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3576
677
|
}
|
|
3577
678
|
}
|
|
3578
679
|
return message;
|
|
@@ -3580,13 +681,13 @@ class ResolveBooleanRequest$Type extends MessageType {
|
|
|
3580
681
|
internalBinaryWrite(message, writer, options) {
|
|
3581
682
|
/* string flag_key = 1; */
|
|
3582
683
|
if (message.flagKey !== "")
|
|
3583
|
-
writer.tag(1, WireType.LengthDelimited).string(message.flagKey);
|
|
684
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.flagKey);
|
|
3584
685
|
/* google.protobuf.Struct context = 2; */
|
|
3585
686
|
if (message.context)
|
|
3586
|
-
Struct.internalBinaryWrite(message.context, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
|
|
687
|
+
Struct.internalBinaryWrite(message.context, writer.tag(2, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3587
688
|
let u = options.writeUnknownFields;
|
|
3588
689
|
if (u !== false)
|
|
3589
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
690
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3590
691
|
return writer;
|
|
3591
692
|
}
|
|
3592
693
|
}
|
|
@@ -3595,7 +696,7 @@ class ResolveBooleanRequest$Type extends MessageType {
|
|
|
3595
696
|
*/
|
|
3596
697
|
const ResolveBooleanRequest = new ResolveBooleanRequest$Type();
|
|
3597
698
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3598
|
-
class ResolveBooleanResponse$Type extends MessageType {
|
|
699
|
+
class ResolveBooleanResponse$Type extends runtime.MessageType {
|
|
3599
700
|
constructor() {
|
|
3600
701
|
super("schema.v1.ResolveBooleanResponse", [
|
|
3601
702
|
{ no: 1, name: "value", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
|
|
@@ -3605,9 +706,9 @@ class ResolveBooleanResponse$Type extends MessageType {
|
|
|
3605
706
|
}
|
|
3606
707
|
create(value) {
|
|
3607
708
|
const message = { value: false, reason: "", variant: "" };
|
|
3608
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
709
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3609
710
|
if (value !== undefined)
|
|
3610
|
-
reflectionMergePartial(this, message, value);
|
|
711
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3611
712
|
return message;
|
|
3612
713
|
}
|
|
3613
714
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3630,7 +731,7 @@ class ResolveBooleanResponse$Type extends MessageType {
|
|
|
3630
731
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3631
732
|
let d = reader.skip(wireType);
|
|
3632
733
|
if (u !== false)
|
|
3633
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
734
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3634
735
|
}
|
|
3635
736
|
}
|
|
3636
737
|
return message;
|
|
@@ -3638,16 +739,16 @@ class ResolveBooleanResponse$Type extends MessageType {
|
|
|
3638
739
|
internalBinaryWrite(message, writer, options) {
|
|
3639
740
|
/* bool value = 1; */
|
|
3640
741
|
if (message.value !== false)
|
|
3641
|
-
writer.tag(1, WireType.Varint).bool(message.value);
|
|
742
|
+
writer.tag(1, runtime.WireType.Varint).bool(message.value);
|
|
3642
743
|
/* string reason = 2; */
|
|
3643
744
|
if (message.reason !== "")
|
|
3644
|
-
writer.tag(2, WireType.LengthDelimited).string(message.reason);
|
|
745
|
+
writer.tag(2, runtime.WireType.LengthDelimited).string(message.reason);
|
|
3645
746
|
/* string variant = 3; */
|
|
3646
747
|
if (message.variant !== "")
|
|
3647
|
-
writer.tag(3, WireType.LengthDelimited).string(message.variant);
|
|
748
|
+
writer.tag(3, runtime.WireType.LengthDelimited).string(message.variant);
|
|
3648
749
|
let u = options.writeUnknownFields;
|
|
3649
750
|
if (u !== false)
|
|
3650
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
751
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3651
752
|
return writer;
|
|
3652
753
|
}
|
|
3653
754
|
}
|
|
@@ -3656,7 +757,7 @@ class ResolveBooleanResponse$Type extends MessageType {
|
|
|
3656
757
|
*/
|
|
3657
758
|
const ResolveBooleanResponse = new ResolveBooleanResponse$Type();
|
|
3658
759
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3659
|
-
class ResolveStringRequest$Type extends MessageType {
|
|
760
|
+
class ResolveStringRequest$Type extends runtime.MessageType {
|
|
3660
761
|
constructor() {
|
|
3661
762
|
super("schema.v1.ResolveStringRequest", [
|
|
3662
763
|
{ no: 1, name: "flag_key", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -3665,9 +766,9 @@ class ResolveStringRequest$Type extends MessageType {
|
|
|
3665
766
|
}
|
|
3666
767
|
create(value) {
|
|
3667
768
|
const message = { flagKey: "" };
|
|
3668
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
769
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3669
770
|
if (value !== undefined)
|
|
3670
|
-
reflectionMergePartial(this, message, value);
|
|
771
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3671
772
|
return message;
|
|
3672
773
|
}
|
|
3673
774
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3687,7 +788,7 @@ class ResolveStringRequest$Type extends MessageType {
|
|
|
3687
788
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3688
789
|
let d = reader.skip(wireType);
|
|
3689
790
|
if (u !== false)
|
|
3690
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
791
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3691
792
|
}
|
|
3692
793
|
}
|
|
3693
794
|
return message;
|
|
@@ -3695,13 +796,13 @@ class ResolveStringRequest$Type extends MessageType {
|
|
|
3695
796
|
internalBinaryWrite(message, writer, options) {
|
|
3696
797
|
/* string flag_key = 1; */
|
|
3697
798
|
if (message.flagKey !== "")
|
|
3698
|
-
writer.tag(1, WireType.LengthDelimited).string(message.flagKey);
|
|
799
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.flagKey);
|
|
3699
800
|
/* google.protobuf.Struct context = 2; */
|
|
3700
801
|
if (message.context)
|
|
3701
|
-
Struct.internalBinaryWrite(message.context, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
|
|
802
|
+
Struct.internalBinaryWrite(message.context, writer.tag(2, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3702
803
|
let u = options.writeUnknownFields;
|
|
3703
804
|
if (u !== false)
|
|
3704
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
805
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3705
806
|
return writer;
|
|
3706
807
|
}
|
|
3707
808
|
}
|
|
@@ -3710,7 +811,7 @@ class ResolveStringRequest$Type extends MessageType {
|
|
|
3710
811
|
*/
|
|
3711
812
|
const ResolveStringRequest = new ResolveStringRequest$Type();
|
|
3712
813
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3713
|
-
class ResolveStringResponse$Type extends MessageType {
|
|
814
|
+
class ResolveStringResponse$Type extends runtime.MessageType {
|
|
3714
815
|
constructor() {
|
|
3715
816
|
super("schema.v1.ResolveStringResponse", [
|
|
3716
817
|
{ no: 1, name: "value", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -3720,9 +821,9 @@ class ResolveStringResponse$Type extends MessageType {
|
|
|
3720
821
|
}
|
|
3721
822
|
create(value) {
|
|
3722
823
|
const message = { value: "", reason: "", variant: "" };
|
|
3723
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
824
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3724
825
|
if (value !== undefined)
|
|
3725
|
-
reflectionMergePartial(this, message, value);
|
|
826
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3726
827
|
return message;
|
|
3727
828
|
}
|
|
3728
829
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3745,7 +846,7 @@ class ResolveStringResponse$Type extends MessageType {
|
|
|
3745
846
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3746
847
|
let d = reader.skip(wireType);
|
|
3747
848
|
if (u !== false)
|
|
3748
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
849
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3749
850
|
}
|
|
3750
851
|
}
|
|
3751
852
|
return message;
|
|
@@ -3753,16 +854,16 @@ class ResolveStringResponse$Type extends MessageType {
|
|
|
3753
854
|
internalBinaryWrite(message, writer, options) {
|
|
3754
855
|
/* string value = 1; */
|
|
3755
856
|
if (message.value !== "")
|
|
3756
|
-
writer.tag(1, WireType.LengthDelimited).string(message.value);
|
|
857
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.value);
|
|
3757
858
|
/* string reason = 2; */
|
|
3758
859
|
if (message.reason !== "")
|
|
3759
|
-
writer.tag(2, WireType.LengthDelimited).string(message.reason);
|
|
860
|
+
writer.tag(2, runtime.WireType.LengthDelimited).string(message.reason);
|
|
3760
861
|
/* string variant = 3; */
|
|
3761
862
|
if (message.variant !== "")
|
|
3762
|
-
writer.tag(3, WireType.LengthDelimited).string(message.variant);
|
|
863
|
+
writer.tag(3, runtime.WireType.LengthDelimited).string(message.variant);
|
|
3763
864
|
let u = options.writeUnknownFields;
|
|
3764
865
|
if (u !== false)
|
|
3765
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
866
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3766
867
|
return writer;
|
|
3767
868
|
}
|
|
3768
869
|
}
|
|
@@ -3771,7 +872,7 @@ class ResolveStringResponse$Type extends MessageType {
|
|
|
3771
872
|
*/
|
|
3772
873
|
const ResolveStringResponse = new ResolveStringResponse$Type();
|
|
3773
874
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3774
|
-
class ResolveFloatRequest$Type extends MessageType {
|
|
875
|
+
class ResolveFloatRequest$Type extends runtime.MessageType {
|
|
3775
876
|
constructor() {
|
|
3776
877
|
super("schema.v1.ResolveFloatRequest", [
|
|
3777
878
|
{ no: 1, name: "flag_key", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -3780,9 +881,9 @@ class ResolveFloatRequest$Type extends MessageType {
|
|
|
3780
881
|
}
|
|
3781
882
|
create(value) {
|
|
3782
883
|
const message = { flagKey: "" };
|
|
3783
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
884
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3784
885
|
if (value !== undefined)
|
|
3785
|
-
reflectionMergePartial(this, message, value);
|
|
886
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3786
887
|
return message;
|
|
3787
888
|
}
|
|
3788
889
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3802,7 +903,7 @@ class ResolveFloatRequest$Type extends MessageType {
|
|
|
3802
903
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3803
904
|
let d = reader.skip(wireType);
|
|
3804
905
|
if (u !== false)
|
|
3805
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
906
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3806
907
|
}
|
|
3807
908
|
}
|
|
3808
909
|
return message;
|
|
@@ -3810,13 +911,13 @@ class ResolveFloatRequest$Type extends MessageType {
|
|
|
3810
911
|
internalBinaryWrite(message, writer, options) {
|
|
3811
912
|
/* string flag_key = 1; */
|
|
3812
913
|
if (message.flagKey !== "")
|
|
3813
|
-
writer.tag(1, WireType.LengthDelimited).string(message.flagKey);
|
|
914
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.flagKey);
|
|
3814
915
|
/* google.protobuf.Struct context = 2; */
|
|
3815
916
|
if (message.context)
|
|
3816
|
-
Struct.internalBinaryWrite(message.context, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
|
|
917
|
+
Struct.internalBinaryWrite(message.context, writer.tag(2, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3817
918
|
let u = options.writeUnknownFields;
|
|
3818
919
|
if (u !== false)
|
|
3819
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
920
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3820
921
|
return writer;
|
|
3821
922
|
}
|
|
3822
923
|
}
|
|
@@ -3825,7 +926,7 @@ class ResolveFloatRequest$Type extends MessageType {
|
|
|
3825
926
|
*/
|
|
3826
927
|
const ResolveFloatRequest = new ResolveFloatRequest$Type();
|
|
3827
928
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3828
|
-
class ResolveFloatResponse$Type extends MessageType {
|
|
929
|
+
class ResolveFloatResponse$Type extends runtime.MessageType {
|
|
3829
930
|
constructor() {
|
|
3830
931
|
super("schema.v1.ResolveFloatResponse", [
|
|
3831
932
|
{ no: 1, name: "value", kind: "scalar", T: 1 /*ScalarType.DOUBLE*/ },
|
|
@@ -3835,9 +936,9 @@ class ResolveFloatResponse$Type extends MessageType {
|
|
|
3835
936
|
}
|
|
3836
937
|
create(value) {
|
|
3837
938
|
const message = { value: 0, reason: "", variant: "" };
|
|
3838
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
939
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3839
940
|
if (value !== undefined)
|
|
3840
|
-
reflectionMergePartial(this, message, value);
|
|
941
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3841
942
|
return message;
|
|
3842
943
|
}
|
|
3843
944
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3860,7 +961,7 @@ class ResolveFloatResponse$Type extends MessageType {
|
|
|
3860
961
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3861
962
|
let d = reader.skip(wireType);
|
|
3862
963
|
if (u !== false)
|
|
3863
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
964
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3864
965
|
}
|
|
3865
966
|
}
|
|
3866
967
|
return message;
|
|
@@ -3868,16 +969,16 @@ class ResolveFloatResponse$Type extends MessageType {
|
|
|
3868
969
|
internalBinaryWrite(message, writer, options) {
|
|
3869
970
|
/* double value = 1; */
|
|
3870
971
|
if (message.value !== 0)
|
|
3871
|
-
writer.tag(1, WireType.Bit64).double(message.value);
|
|
972
|
+
writer.tag(1, runtime.WireType.Bit64).double(message.value);
|
|
3872
973
|
/* string reason = 2; */
|
|
3873
974
|
if (message.reason !== "")
|
|
3874
|
-
writer.tag(2, WireType.LengthDelimited).string(message.reason);
|
|
975
|
+
writer.tag(2, runtime.WireType.LengthDelimited).string(message.reason);
|
|
3875
976
|
/* string variant = 3; */
|
|
3876
977
|
if (message.variant !== "")
|
|
3877
|
-
writer.tag(3, WireType.LengthDelimited).string(message.variant);
|
|
978
|
+
writer.tag(3, runtime.WireType.LengthDelimited).string(message.variant);
|
|
3878
979
|
let u = options.writeUnknownFields;
|
|
3879
980
|
if (u !== false)
|
|
3880
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
981
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3881
982
|
return writer;
|
|
3882
983
|
}
|
|
3883
984
|
}
|
|
@@ -3886,7 +987,7 @@ class ResolveFloatResponse$Type extends MessageType {
|
|
|
3886
987
|
*/
|
|
3887
988
|
const ResolveFloatResponse = new ResolveFloatResponse$Type();
|
|
3888
989
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3889
|
-
class ResolveIntRequest$Type extends MessageType {
|
|
990
|
+
class ResolveIntRequest$Type extends runtime.MessageType {
|
|
3890
991
|
constructor() {
|
|
3891
992
|
super("schema.v1.ResolveIntRequest", [
|
|
3892
993
|
{ no: 1, name: "flag_key", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -3895,9 +996,9 @@ class ResolveIntRequest$Type extends MessageType {
|
|
|
3895
996
|
}
|
|
3896
997
|
create(value) {
|
|
3897
998
|
const message = { flagKey: "" };
|
|
3898
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
999
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3899
1000
|
if (value !== undefined)
|
|
3900
|
-
reflectionMergePartial(this, message, value);
|
|
1001
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3901
1002
|
return message;
|
|
3902
1003
|
}
|
|
3903
1004
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3917,7 +1018,7 @@ class ResolveIntRequest$Type extends MessageType {
|
|
|
3917
1018
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3918
1019
|
let d = reader.skip(wireType);
|
|
3919
1020
|
if (u !== false)
|
|
3920
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
1021
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3921
1022
|
}
|
|
3922
1023
|
}
|
|
3923
1024
|
return message;
|
|
@@ -3925,13 +1026,13 @@ class ResolveIntRequest$Type extends MessageType {
|
|
|
3925
1026
|
internalBinaryWrite(message, writer, options) {
|
|
3926
1027
|
/* string flag_key = 1; */
|
|
3927
1028
|
if (message.flagKey !== "")
|
|
3928
|
-
writer.tag(1, WireType.LengthDelimited).string(message.flagKey);
|
|
1029
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.flagKey);
|
|
3929
1030
|
/* google.protobuf.Struct context = 2; */
|
|
3930
1031
|
if (message.context)
|
|
3931
|
-
Struct.internalBinaryWrite(message.context, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
|
|
1032
|
+
Struct.internalBinaryWrite(message.context, writer.tag(2, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
3932
1033
|
let u = options.writeUnknownFields;
|
|
3933
1034
|
if (u !== false)
|
|
3934
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
1035
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3935
1036
|
return writer;
|
|
3936
1037
|
}
|
|
3937
1038
|
}
|
|
@@ -3940,7 +1041,7 @@ class ResolveIntRequest$Type extends MessageType {
|
|
|
3940
1041
|
*/
|
|
3941
1042
|
const ResolveIntRequest = new ResolveIntRequest$Type();
|
|
3942
1043
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
3943
|
-
class ResolveIntResponse$Type extends MessageType {
|
|
1044
|
+
class ResolveIntResponse$Type extends runtime.MessageType {
|
|
3944
1045
|
constructor() {
|
|
3945
1046
|
super("schema.v1.ResolveIntResponse", [
|
|
3946
1047
|
{ no: 1, name: "value", kind: "scalar", T: 3 /*ScalarType.INT64*/ },
|
|
@@ -3950,9 +1051,9 @@ class ResolveIntResponse$Type extends MessageType {
|
|
|
3950
1051
|
}
|
|
3951
1052
|
create(value) {
|
|
3952
1053
|
const message = { value: "0", reason: "", variant: "" };
|
|
3953
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
1054
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
3954
1055
|
if (value !== undefined)
|
|
3955
|
-
reflectionMergePartial(this, message, value);
|
|
1056
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
3956
1057
|
return message;
|
|
3957
1058
|
}
|
|
3958
1059
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -3975,7 +1076,7 @@ class ResolveIntResponse$Type extends MessageType {
|
|
|
3975
1076
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
3976
1077
|
let d = reader.skip(wireType);
|
|
3977
1078
|
if (u !== false)
|
|
3978
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
1079
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
3979
1080
|
}
|
|
3980
1081
|
}
|
|
3981
1082
|
return message;
|
|
@@ -3983,16 +1084,16 @@ class ResolveIntResponse$Type extends MessageType {
|
|
|
3983
1084
|
internalBinaryWrite(message, writer, options) {
|
|
3984
1085
|
/* int64 value = 1; */
|
|
3985
1086
|
if (message.value !== "0")
|
|
3986
|
-
writer.tag(1, WireType.Varint).int64(message.value);
|
|
1087
|
+
writer.tag(1, runtime.WireType.Varint).int64(message.value);
|
|
3987
1088
|
/* string reason = 2; */
|
|
3988
1089
|
if (message.reason !== "")
|
|
3989
|
-
writer.tag(2, WireType.LengthDelimited).string(message.reason);
|
|
1090
|
+
writer.tag(2, runtime.WireType.LengthDelimited).string(message.reason);
|
|
3990
1091
|
/* string variant = 3; */
|
|
3991
1092
|
if (message.variant !== "")
|
|
3992
|
-
writer.tag(3, WireType.LengthDelimited).string(message.variant);
|
|
1093
|
+
writer.tag(3, runtime.WireType.LengthDelimited).string(message.variant);
|
|
3993
1094
|
let u = options.writeUnknownFields;
|
|
3994
1095
|
if (u !== false)
|
|
3995
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
1096
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
3996
1097
|
return writer;
|
|
3997
1098
|
}
|
|
3998
1099
|
}
|
|
@@ -4001,7 +1102,7 @@ class ResolveIntResponse$Type extends MessageType {
|
|
|
4001
1102
|
*/
|
|
4002
1103
|
const ResolveIntResponse = new ResolveIntResponse$Type();
|
|
4003
1104
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
4004
|
-
class ResolveObjectRequest$Type extends MessageType {
|
|
1105
|
+
class ResolveObjectRequest$Type extends runtime.MessageType {
|
|
4005
1106
|
constructor() {
|
|
4006
1107
|
super("schema.v1.ResolveObjectRequest", [
|
|
4007
1108
|
{ no: 1, name: "flag_key", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -4010,9 +1111,9 @@ class ResolveObjectRequest$Type extends MessageType {
|
|
|
4010
1111
|
}
|
|
4011
1112
|
create(value) {
|
|
4012
1113
|
const message = { flagKey: "" };
|
|
4013
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
1114
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
4014
1115
|
if (value !== undefined)
|
|
4015
|
-
reflectionMergePartial(this, message, value);
|
|
1116
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
4016
1117
|
return message;
|
|
4017
1118
|
}
|
|
4018
1119
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -4032,7 +1133,7 @@ class ResolveObjectRequest$Type extends MessageType {
|
|
|
4032
1133
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
4033
1134
|
let d = reader.skip(wireType);
|
|
4034
1135
|
if (u !== false)
|
|
4035
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
1136
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
4036
1137
|
}
|
|
4037
1138
|
}
|
|
4038
1139
|
return message;
|
|
@@ -4040,13 +1141,13 @@ class ResolveObjectRequest$Type extends MessageType {
|
|
|
4040
1141
|
internalBinaryWrite(message, writer, options) {
|
|
4041
1142
|
/* string flag_key = 1; */
|
|
4042
1143
|
if (message.flagKey !== "")
|
|
4043
|
-
writer.tag(1, WireType.LengthDelimited).string(message.flagKey);
|
|
1144
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.flagKey);
|
|
4044
1145
|
/* google.protobuf.Struct context = 2; */
|
|
4045
1146
|
if (message.context)
|
|
4046
|
-
Struct.internalBinaryWrite(message.context, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
|
|
1147
|
+
Struct.internalBinaryWrite(message.context, writer.tag(2, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
4047
1148
|
let u = options.writeUnknownFields;
|
|
4048
1149
|
if (u !== false)
|
|
4049
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
1150
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
4050
1151
|
return writer;
|
|
4051
1152
|
}
|
|
4052
1153
|
}
|
|
@@ -4055,7 +1156,7 @@ class ResolveObjectRequest$Type extends MessageType {
|
|
|
4055
1156
|
*/
|
|
4056
1157
|
const ResolveObjectRequest = new ResolveObjectRequest$Type();
|
|
4057
1158
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
4058
|
-
class ResolveObjectResponse$Type extends MessageType {
|
|
1159
|
+
class ResolveObjectResponse$Type extends runtime.MessageType {
|
|
4059
1160
|
constructor() {
|
|
4060
1161
|
super("schema.v1.ResolveObjectResponse", [
|
|
4061
1162
|
{ no: 1, name: "value", kind: "message", T: () => Struct },
|
|
@@ -4065,9 +1166,9 @@ class ResolveObjectResponse$Type extends MessageType {
|
|
|
4065
1166
|
}
|
|
4066
1167
|
create(value) {
|
|
4067
1168
|
const message = { reason: "", variant: "" };
|
|
4068
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
1169
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
4069
1170
|
if (value !== undefined)
|
|
4070
|
-
reflectionMergePartial(this, message, value);
|
|
1171
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
4071
1172
|
return message;
|
|
4072
1173
|
}
|
|
4073
1174
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -4090,7 +1191,7 @@ class ResolveObjectResponse$Type extends MessageType {
|
|
|
4090
1191
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
4091
1192
|
let d = reader.skip(wireType);
|
|
4092
1193
|
if (u !== false)
|
|
4093
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
1194
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
4094
1195
|
}
|
|
4095
1196
|
}
|
|
4096
1197
|
return message;
|
|
@@ -4098,16 +1199,16 @@ class ResolveObjectResponse$Type extends MessageType {
|
|
|
4098
1199
|
internalBinaryWrite(message, writer, options) {
|
|
4099
1200
|
/* google.protobuf.Struct value = 1; */
|
|
4100
1201
|
if (message.value)
|
|
4101
|
-
Struct.internalBinaryWrite(message.value, writer.tag(1, WireType.LengthDelimited).fork(), options).join();
|
|
1202
|
+
Struct.internalBinaryWrite(message.value, writer.tag(1, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
4102
1203
|
/* string reason = 2; */
|
|
4103
1204
|
if (message.reason !== "")
|
|
4104
|
-
writer.tag(2, WireType.LengthDelimited).string(message.reason);
|
|
1205
|
+
writer.tag(2, runtime.WireType.LengthDelimited).string(message.reason);
|
|
4105
1206
|
/* string variant = 3; */
|
|
4106
1207
|
if (message.variant !== "")
|
|
4107
|
-
writer.tag(3, WireType.LengthDelimited).string(message.variant);
|
|
1208
|
+
writer.tag(3, runtime.WireType.LengthDelimited).string(message.variant);
|
|
4108
1209
|
let u = options.writeUnknownFields;
|
|
4109
1210
|
if (u !== false)
|
|
4110
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
1211
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
4111
1212
|
return writer;
|
|
4112
1213
|
}
|
|
4113
1214
|
}
|
|
@@ -4116,7 +1217,7 @@ class ResolveObjectResponse$Type extends MessageType {
|
|
|
4116
1217
|
*/
|
|
4117
1218
|
const ResolveObjectResponse = new ResolveObjectResponse$Type();
|
|
4118
1219
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
4119
|
-
class EventStreamResponse$Type extends MessageType {
|
|
1220
|
+
class EventStreamResponse$Type extends runtime.MessageType {
|
|
4120
1221
|
constructor() {
|
|
4121
1222
|
super("schema.v1.EventStreamResponse", [
|
|
4122
1223
|
{ no: 1, name: "type", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
@@ -4125,9 +1226,9 @@ class EventStreamResponse$Type extends MessageType {
|
|
|
4125
1226
|
}
|
|
4126
1227
|
create(value) {
|
|
4127
1228
|
const message = { type: "" };
|
|
4128
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
1229
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
4129
1230
|
if (value !== undefined)
|
|
4130
|
-
reflectionMergePartial(this, message, value);
|
|
1231
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
4131
1232
|
return message;
|
|
4132
1233
|
}
|
|
4133
1234
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -4147,7 +1248,7 @@ class EventStreamResponse$Type extends MessageType {
|
|
|
4147
1248
|
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
4148
1249
|
let d = reader.skip(wireType);
|
|
4149
1250
|
if (u !== false)
|
|
4150
|
-
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
1251
|
+
(u === true ? runtime.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
4151
1252
|
}
|
|
4152
1253
|
}
|
|
4153
1254
|
return message;
|
|
@@ -4155,13 +1256,13 @@ class EventStreamResponse$Type extends MessageType {
|
|
|
4155
1256
|
internalBinaryWrite(message, writer, options) {
|
|
4156
1257
|
/* string type = 1; */
|
|
4157
1258
|
if (message.type !== "")
|
|
4158
|
-
writer.tag(1, WireType.LengthDelimited).string(message.type);
|
|
1259
|
+
writer.tag(1, runtime.WireType.LengthDelimited).string(message.type);
|
|
4159
1260
|
/* google.protobuf.Struct data = 2; */
|
|
4160
1261
|
if (message.data)
|
|
4161
|
-
Struct.internalBinaryWrite(message.data, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
|
|
1262
|
+
Struct.internalBinaryWrite(message.data, writer.tag(2, runtime.WireType.LengthDelimited).fork(), options).join();
|
|
4162
1263
|
let u = options.writeUnknownFields;
|
|
4163
1264
|
if (u !== false)
|
|
4164
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
1265
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
4165
1266
|
return writer;
|
|
4166
1267
|
}
|
|
4167
1268
|
}
|
|
@@ -4170,15 +1271,15 @@ class EventStreamResponse$Type extends MessageType {
|
|
|
4170
1271
|
*/
|
|
4171
1272
|
const EventStreamResponse = new EventStreamResponse$Type();
|
|
4172
1273
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
4173
|
-
class EventStreamRequest$Type extends MessageType {
|
|
1274
|
+
class EventStreamRequest$Type extends runtime.MessageType {
|
|
4174
1275
|
constructor() {
|
|
4175
1276
|
super("schema.v1.EventStreamRequest", []);
|
|
4176
1277
|
}
|
|
4177
1278
|
create(value) {
|
|
4178
1279
|
const message = {};
|
|
4179
|
-
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
1280
|
+
globalThis.Object.defineProperty(message, runtime.MESSAGE_TYPE, { enumerable: false, value: this });
|
|
4180
1281
|
if (value !== undefined)
|
|
4181
|
-
reflectionMergePartial(this, message, value);
|
|
1282
|
+
runtime.reflectionMergePartial(this, message, value);
|
|
4182
1283
|
return message;
|
|
4183
1284
|
}
|
|
4184
1285
|
internalBinaryRead(reader, length, options, target) {
|
|
@@ -4187,7 +1288,7 @@ class EventStreamRequest$Type extends MessageType {
|
|
|
4187
1288
|
internalBinaryWrite(message, writer, options) {
|
|
4188
1289
|
let u = options.writeUnknownFields;
|
|
4189
1290
|
if (u !== false)
|
|
4190
|
-
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
1291
|
+
(u == true ? runtime.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
4191
1292
|
return writer;
|
|
4192
1293
|
}
|
|
4193
1294
|
}
|
|
@@ -4276,13 +1377,45 @@ const Codes = {
|
|
|
4276
1377
|
InvalidArgument: 'INVALID_ARGUMENT',
|
|
4277
1378
|
NotFound: 'NOT_FOUND',
|
|
4278
1379
|
DataLoss: 'DATA_LOSS',
|
|
4279
|
-
Unavailable: 'UNAVAILABLE'
|
|
1380
|
+
Unavailable: 'UNAVAILABLE',
|
|
4280
1381
|
};
|
|
4281
1382
|
class GRPCService {
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
1383
|
+
get _cacheActive() {
|
|
1384
|
+
// the cache is "active" (able to be used) if the config enabled it, AND the gRPC stream is live
|
|
1385
|
+
return this._cacheEnabled && this._streamAlive;
|
|
1386
|
+
}
|
|
1387
|
+
constructor(config, client, logger) {
|
|
1388
|
+
var _a;
|
|
1389
|
+
this.logger = logger;
|
|
1390
|
+
this._cacheEnabled = false;
|
|
1391
|
+
this._streamAlive = false;
|
|
1392
|
+
this._streamConnectAttempt = 0;
|
|
1393
|
+
this._streamConnectBackoff = BASE_EVENT_STREAM_RETRY_BACKOFF_MS;
|
|
1394
|
+
// default to false here - reassigned in the constructor if we actaully need to connect
|
|
1395
|
+
this.streamConnection = Promise.resolve(false);
|
|
1396
|
+
this.objectParser = (struct) => {
|
|
1397
|
+
if (struct) {
|
|
1398
|
+
return Struct.toJson(struct);
|
|
1399
|
+
}
|
|
1400
|
+
return {};
|
|
1401
|
+
};
|
|
1402
|
+
this.booleanParser = (value) => {
|
|
1403
|
+
if (value) {
|
|
1404
|
+
return value;
|
|
1405
|
+
}
|
|
1406
|
+
return false;
|
|
1407
|
+
};
|
|
1408
|
+
this.stringParser = (value) => {
|
|
1409
|
+
if (value) {
|
|
1410
|
+
return value;
|
|
1411
|
+
}
|
|
1412
|
+
return '';
|
|
1413
|
+
};
|
|
1414
|
+
this.numberParser = (value) => {
|
|
1415
|
+
if (value) {
|
|
1416
|
+
return value;
|
|
1417
|
+
}
|
|
1418
|
+
return 0;
|
|
4286
1419
|
};
|
|
4287
1420
|
this.onRejected = (err) => {
|
|
4288
1421
|
// map the errors
|
|
@@ -4300,70 +1433,136 @@ class GRPCService {
|
|
|
4300
1433
|
}
|
|
4301
1434
|
};
|
|
4302
1435
|
const { host, port, tls, socketPath } = config;
|
|
4303
|
-
this.
|
|
1436
|
+
this._maxEventStreamRetries = (_a = config.maxEventStreamRetries) !== null && _a !== void 0 ? _a : DEFAULT_MAX_EVENT_STREAM_RETRIES;
|
|
1437
|
+
this._client = client
|
|
4304
1438
|
? client
|
|
4305
1439
|
: new ServiceClient(new grpcTransport.GrpcTransport({
|
|
4306
1440
|
host: socketPath ? `unix://${socketPath}` : `${host}:${port}`,
|
|
4307
|
-
channelCredentials: tls
|
|
4308
|
-
? grpc__namespace.credentials.createSsl()
|
|
4309
|
-
: grpc__namespace.credentials.createInsecure(),
|
|
1441
|
+
channelCredentials: tls ? grpc__namespace.credentials.createSsl() : grpc__namespace.credentials.createInsecure(),
|
|
4310
1442
|
}));
|
|
1443
|
+
// for now, we only need streaming if the cache is enabled (will need to be pulled out once we support events)
|
|
1444
|
+
if (config.cache === 'lru') {
|
|
1445
|
+
this._cacheEnabled = true;
|
|
1446
|
+
this._cache = new LRU__default["default"]({ maxSize: config.maxCacheSize || DEFAULT_MAX_CACHE_SIZE, sizeCalculation: () => 1 });
|
|
1447
|
+
this.streamConnection = this.connectStream();
|
|
1448
|
+
}
|
|
4311
1449
|
}
|
|
4312
1450
|
resolveBoolean(flagKey, context, logger) {
|
|
4313
1451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4314
|
-
|
|
4315
|
-
flagKey,
|
|
4316
|
-
context: this.convertContext(context, logger),
|
|
4317
|
-
}).then(this.onFulfilled, this.onRejected);
|
|
4318
|
-
return {
|
|
4319
|
-
value: response.value,
|
|
4320
|
-
reason: response.reason,
|
|
4321
|
-
variant: response.variant,
|
|
4322
|
-
};
|
|
1452
|
+
return this.resolve(this._client.resolveBoolean, flagKey, context, logger, this.booleanParser);
|
|
4323
1453
|
});
|
|
4324
1454
|
}
|
|
4325
1455
|
resolveString(flagKey, context, logger) {
|
|
4326
1456
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4327
|
-
|
|
4328
|
-
flagKey,
|
|
4329
|
-
context: this.convertContext(context, logger),
|
|
4330
|
-
}).then(this.onFulfilled, this.onRejected);
|
|
4331
|
-
return {
|
|
4332
|
-
value: response.value,
|
|
4333
|
-
reason: response.reason,
|
|
4334
|
-
variant: response.variant,
|
|
4335
|
-
};
|
|
1457
|
+
return this.resolve(this._client.resolveString, flagKey, context, logger, this.stringParser);
|
|
4336
1458
|
});
|
|
4337
1459
|
}
|
|
4338
1460
|
resolveNumber(flagKey, context, logger) {
|
|
4339
1461
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4340
|
-
|
|
4341
|
-
flagKey,
|
|
4342
|
-
context: this.convertContext(context, logger),
|
|
4343
|
-
}).then(this.onFulfilled, this.onRejected);
|
|
4344
|
-
return {
|
|
4345
|
-
value: response.value,
|
|
4346
|
-
reason: response.reason,
|
|
4347
|
-
variant: response.variant,
|
|
4348
|
-
};
|
|
1462
|
+
return this.resolve(this._client.resolveFloat, flagKey, context, logger, this.numberParser);
|
|
4349
1463
|
});
|
|
4350
1464
|
}
|
|
4351
1465
|
resolveObject(flagKey, context, logger) {
|
|
4352
1466
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
1467
|
+
return this.resolve(this._client.resolveObject, flagKey, context, logger, this.objectParser);
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
connectStream() {
|
|
1471
|
+
return new Promise((resolve, reject) => {
|
|
1472
|
+
var _a;
|
|
1473
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: connecting stream, attempt ${this._streamConnectAttempt}...`);
|
|
1474
|
+
const stream = this._client.eventStream({});
|
|
1475
|
+
stream.responses.onError(() => {
|
|
1476
|
+
this.handleError(reject);
|
|
1477
|
+
});
|
|
1478
|
+
stream.responses.onComplete(() => {
|
|
1479
|
+
this.handleComplete();
|
|
1480
|
+
});
|
|
1481
|
+
stream.responses.onMessage((message) => {
|
|
1482
|
+
if (message.type === EVENT_PROVIDER_READY) {
|
|
1483
|
+
this.handleProviderReady(resolve);
|
|
1484
|
+
}
|
|
1485
|
+
else if (message.type === EVENT_CONFIGURATION_CHANGE) {
|
|
1486
|
+
this.handleFlagsChanged(message);
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
handleProviderReady(resolve) {
|
|
1492
|
+
var _a;
|
|
1493
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`${FlagdProvider.name}: streaming connection established with flagd`);
|
|
1494
|
+
this._streamAlive = true;
|
|
1495
|
+
this._streamConnectAttempt = 0;
|
|
1496
|
+
this._streamConnectBackoff = BASE_EVENT_STREAM_RETRY_BACKOFF_MS;
|
|
1497
|
+
resolve(true);
|
|
1498
|
+
}
|
|
1499
|
+
handleFlagsChanged(message) {
|
|
1500
|
+
var _a;
|
|
1501
|
+
if (message.data) {
|
|
1502
|
+
const data = Struct.toJson(message.data);
|
|
1503
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: got message: ${JSON.stringify(data, undefined, 2)}`);
|
|
1504
|
+
if (data && typeof data === 'object' && 'flags' in data && (data === null || data === void 0 ? void 0 : data['flags'])) {
|
|
1505
|
+
const flagChangeMessage = data;
|
|
1506
|
+
// remove each changed key from cache
|
|
1507
|
+
Object.keys(flagChangeMessage.flags || []).forEach((key) => {
|
|
1508
|
+
var _a, _b;
|
|
1509
|
+
if ((_a = this._cache) === null || _a === void 0 ? void 0 : _a.delete(key)) {
|
|
1510
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug(`${FlagdProvider.name}: evicted key: ${key} from cache.`);
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
4363
1513
|
}
|
|
4364
|
-
|
|
4365
|
-
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
handleError(reject) {
|
|
1517
|
+
var _a, _b, _c;
|
|
1518
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`${FlagdProvider.name}: streaming connection error, will attempt reconnect...`);
|
|
1519
|
+
(_b = this._cache) === null || _b === void 0 ? void 0 : _b.clear();
|
|
1520
|
+
this._streamAlive = false;
|
|
1521
|
+
// if we haven't reached max attempt, reconnect after backoff
|
|
1522
|
+
if (this._streamConnectAttempt <= this._maxEventStreamRetries) {
|
|
1523
|
+
this._streamConnectAttempt++;
|
|
1524
|
+
setTimeout(() => {
|
|
1525
|
+
this._streamConnectBackoff = this._streamConnectBackoff * 2;
|
|
1526
|
+
this.connectStream();
|
|
1527
|
+
}, this._streamConnectBackoff);
|
|
1528
|
+
}
|
|
1529
|
+
else {
|
|
1530
|
+
// after max attempts, give up
|
|
1531
|
+
const errorMessage = `${FlagdProvider.name}: max stream connect attempts (${this._maxEventStreamRetries} reached)`;
|
|
1532
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.error(errorMessage);
|
|
1533
|
+
reject(new Error(errorMessage));
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
handleComplete() {
|
|
1537
|
+
var _a, _b;
|
|
1538
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`${FlagdProvider.name}: streaming connection closed gracefully`);
|
|
1539
|
+
(_b = this._cache) === null || _b === void 0 ? void 0 : _b.clear();
|
|
1540
|
+
this._streamAlive = false;
|
|
1541
|
+
}
|
|
1542
|
+
resolve(resolver, flagKey, context, logger, parser) {
|
|
1543
|
+
var _a, _b;
|
|
1544
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1545
|
+
if (this._cacheActive) {
|
|
1546
|
+
const cached = (_a = this._cache) === null || _a === void 0 ? void 0 : _a.get(flagKey);
|
|
1547
|
+
if (cached) {
|
|
1548
|
+
return Object.assign(Object.assign({}, cached), { reason: jsSdk.StandardResolutionReasons.CACHED });
|
|
1549
|
+
}
|
|
4366
1550
|
}
|
|
1551
|
+
// invoke the passed resolver method
|
|
1552
|
+
const { response } = yield resolver
|
|
1553
|
+
.call(this._client, { flagKey, context: this.convertContext(context, logger) })
|
|
1554
|
+
.then((resolved) => resolved, this.onRejected);
|
|
1555
|
+
const resolved = {
|
|
1556
|
+
// invoke the parser method if passed
|
|
1557
|
+
value: parser ? parser.call(this, response.value) : response.value,
|
|
1558
|
+
reason: response.reason,
|
|
1559
|
+
variant: response.variant,
|
|
1560
|
+
};
|
|
1561
|
+
if (this._cacheActive && response.reason === jsSdk.StandardResolutionReasons.STATIC) {
|
|
1562
|
+
// cache this static value
|
|
1563
|
+
(_b = this._cache) === null || _b === void 0 ? void 0 : _b.set(flagKey, Object.assign({}, resolved));
|
|
1564
|
+
}
|
|
1565
|
+
return resolved;
|
|
4367
1566
|
});
|
|
4368
1567
|
}
|
|
4369
1568
|
convertContext(context, logger) {
|
|
@@ -4382,7 +1581,19 @@ class GRPCService {
|
|
|
4382
1581
|
}
|
|
4383
1582
|
|
|
4384
1583
|
class FlagdProvider {
|
|
4385
|
-
|
|
1584
|
+
/**
|
|
1585
|
+
* Promise indicating the gRPC stream is connected.
|
|
1586
|
+
*
|
|
1587
|
+
* Can be used in instances where the provider being connected to the event stream is a prerequisite
|
|
1588
|
+
* to execution (e.g. testing). Not necessary for standard usage.
|
|
1589
|
+
*
|
|
1590
|
+
* @returns true if stream connected successfully, false if connection not enabled.
|
|
1591
|
+
*/
|
|
1592
|
+
get streamConnection() {
|
|
1593
|
+
return this._service.streamConnection;
|
|
1594
|
+
}
|
|
1595
|
+
constructor(options, service, logger) {
|
|
1596
|
+
this.logger = logger;
|
|
4386
1597
|
this.metadata = {
|
|
4387
1598
|
name: 'flagd Provider',
|
|
4388
1599
|
};
|
|
@@ -4391,22 +1602,26 @@ class FlagdProvider {
|
|
|
4391
1602
|
logger.error(err === null || err === void 0 ? void 0 : err.stack);
|
|
4392
1603
|
throw err;
|
|
4393
1604
|
};
|
|
4394
|
-
this._service = service ? service : new GRPCService(getConfig(options));
|
|
1605
|
+
this._service = service ? service : new GRPCService(getConfig(options), undefined, logger);
|
|
4395
1606
|
}
|
|
4396
1607
|
resolveBooleanEvaluation(flagKey, _, transformedContext, logger) {
|
|
4397
|
-
return this._service
|
|
1608
|
+
return this._service
|
|
1609
|
+
.resolveBoolean(flagKey, transformedContext, logger)
|
|
4398
1610
|
.catch((err) => this.logRejected(err, flagKey, logger));
|
|
4399
1611
|
}
|
|
4400
1612
|
resolveStringEvaluation(flagKey, _, transformedContext, logger) {
|
|
4401
|
-
return this._service
|
|
1613
|
+
return this._service
|
|
1614
|
+
.resolveString(flagKey, transformedContext, logger)
|
|
4402
1615
|
.catch((err) => this.logRejected(err, flagKey, logger));
|
|
4403
1616
|
}
|
|
4404
1617
|
resolveNumberEvaluation(flagKey, _, transformedContext, logger) {
|
|
4405
|
-
return this._service
|
|
1618
|
+
return this._service
|
|
1619
|
+
.resolveNumber(flagKey, transformedContext, logger)
|
|
4406
1620
|
.catch((err) => this.logRejected(err, flagKey, logger));
|
|
4407
1621
|
}
|
|
4408
1622
|
resolveObjectEvaluation(flagKey, _, transformedContext, logger) {
|
|
4409
|
-
return this._service
|
|
1623
|
+
return this._service
|
|
1624
|
+
.resolveObject(flagKey, transformedContext, logger)
|
|
4410
1625
|
.catch((err) => this.logRejected(err, flagKey, logger));
|
|
4411
1626
|
}
|
|
4412
1627
|
}
|