@openfeature/flagd-provider 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,4672 @@
1
+ import { StandardResolutionReasons, ErrorCode } from '@openfeature/nodejs-sdk';
2
+ import axios from 'axios';
3
+ import { GrpcTransport } from '@protobuf-ts/grpc-transport';
4
+ import * as grpc from '@grpc/grpc-js';
5
+
6
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7
+
8
+ var check = function (it) {
9
+ return it && it.Math == Math && it;
10
+ };
11
+
12
+ // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
13
+ var global$c =
14
+ // eslint-disable-next-line es-x/no-global-this -- safe
15
+ check(typeof globalThis == 'object' && globalThis) ||
16
+ check(typeof window == 'object' && window) ||
17
+ // eslint-disable-next-line no-restricted-globals -- safe
18
+ check(typeof self == 'object' && self) ||
19
+ check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
20
+ // eslint-disable-next-line no-new-func -- fallback
21
+ (function () { return this; })() || Function('return this')();
22
+
23
+ var objectGetOwnPropertyDescriptor = {};
24
+
25
+ var fails$b = function (exec) {
26
+ try {
27
+ return !!exec();
28
+ } catch (error) {
29
+ return true;
30
+ }
31
+ };
32
+
33
+ var fails$a = fails$b;
34
+
35
+ // Detect IE8's incomplete defineProperty implementation
36
+ var descriptors = !fails$a(function () {
37
+ // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing
38
+ return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
39
+ });
40
+
41
+ var fails$9 = fails$b;
42
+
43
+ var functionBindNative = !fails$9(function () {
44
+ // eslint-disable-next-line es-x/no-function-prototype-bind -- safe
45
+ var test = (function () { /* empty */ }).bind();
46
+ // eslint-disable-next-line no-prototype-builtins -- safe
47
+ return typeof test != 'function' || test.hasOwnProperty('prototype');
48
+ });
49
+
50
+ var NATIVE_BIND$1 = functionBindNative;
51
+
52
+ var call$6 = Function.prototype.call;
53
+
54
+ var functionCall = NATIVE_BIND$1 ? call$6.bind(call$6) : function () {
55
+ return call$6.apply(call$6, arguments);
56
+ };
57
+
58
+ var objectPropertyIsEnumerable = {};
59
+
60
+ var $propertyIsEnumerable = {}.propertyIsEnumerable;
61
+ // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
62
+ var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
63
+
64
+ // Nashorn ~ JDK8 bug
65
+ var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
66
+
67
+ // `Object.prototype.propertyIsEnumerable` method implementation
68
+ // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
69
+ objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
70
+ var descriptor = getOwnPropertyDescriptor$1(this, V);
71
+ return !!descriptor && descriptor.enumerable;
72
+ } : $propertyIsEnumerable;
73
+
74
+ var createPropertyDescriptor$3 = function (bitmap, value) {
75
+ return {
76
+ enumerable: !(bitmap & 1),
77
+ configurable: !(bitmap & 2),
78
+ writable: !(bitmap & 4),
79
+ value: value
80
+ };
81
+ };
82
+
83
+ var NATIVE_BIND = functionBindNative;
84
+
85
+ var FunctionPrototype$1 = Function.prototype;
86
+ var bind = FunctionPrototype$1.bind;
87
+ var call$5 = FunctionPrototype$1.call;
88
+ var uncurryThis$b = NATIVE_BIND && bind.bind(call$5, call$5);
89
+
90
+ var functionUncurryThis = NATIVE_BIND ? function (fn) {
91
+ return fn && uncurryThis$b(fn);
92
+ } : function (fn) {
93
+ return fn && function () {
94
+ return call$5.apply(fn, arguments);
95
+ };
96
+ };
97
+
98
+ var uncurryThis$a = functionUncurryThis;
99
+
100
+ var toString$1 = uncurryThis$a({}.toString);
101
+ var stringSlice = uncurryThis$a(''.slice);
102
+
103
+ var classofRaw = function (it) {
104
+ return stringSlice(toString$1(it), 8, -1);
105
+ };
106
+
107
+ var uncurryThis$9 = functionUncurryThis;
108
+ var fails$8 = fails$b;
109
+ var classof = classofRaw;
110
+
111
+ var $Object$3 = Object;
112
+ var split = uncurryThis$9(''.split);
113
+
114
+ // fallback for non-array-like ES3 and non-enumerable old V8 strings
115
+ var indexedObject = fails$8(function () {
116
+ // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
117
+ // eslint-disable-next-line no-prototype-builtins -- safe
118
+ return !$Object$3('z').propertyIsEnumerable(0);
119
+ }) ? function (it) {
120
+ return classof(it) == 'String' ? split(it, '') : $Object$3(it);
121
+ } : $Object$3;
122
+
123
+ var $TypeError$6 = TypeError;
124
+
125
+ // `RequireObjectCoercible` abstract operation
126
+ // https://tc39.es/ecma262/#sec-requireobjectcoercible
127
+ var requireObjectCoercible$2 = function (it) {
128
+ if (it == undefined) throw $TypeError$6("Can't call method on " + it);
129
+ return it;
130
+ };
131
+
132
+ // toObject with fallback for non-array-like ES3 strings
133
+ var IndexedObject$1 = indexedObject;
134
+ var requireObjectCoercible$1 = requireObjectCoercible$2;
135
+
136
+ var toIndexedObject$5 = function (it) {
137
+ return IndexedObject$1(requireObjectCoercible$1(it));
138
+ };
139
+
140
+ // `IsCallable` abstract operation
141
+ // https://tc39.es/ecma262/#sec-iscallable
142
+ var isCallable$e = function (argument) {
143
+ return typeof argument == 'function';
144
+ };
145
+
146
+ var isCallable$d = isCallable$e;
147
+
148
+ var isObject$5 = function (it) {
149
+ return typeof it == 'object' ? it !== null : isCallable$d(it);
150
+ };
151
+
152
+ var global$b = global$c;
153
+ var isCallable$c = isCallable$e;
154
+
155
+ var aFunction = function (argument) {
156
+ return isCallable$c(argument) ? argument : undefined;
157
+ };
158
+
159
+ var getBuiltIn$4 = function (namespace, method) {
160
+ return arguments.length < 2 ? aFunction(global$b[namespace]) : global$b[namespace] && global$b[namespace][method];
161
+ };
162
+
163
+ var uncurryThis$8 = functionUncurryThis;
164
+
165
+ var objectIsPrototypeOf = uncurryThis$8({}.isPrototypeOf);
166
+
167
+ var getBuiltIn$3 = getBuiltIn$4;
168
+
169
+ var engineUserAgent = getBuiltIn$3('navigator', 'userAgent') || '';
170
+
171
+ var global$a = global$c;
172
+ var userAgent = engineUserAgent;
173
+
174
+ var process = global$a.process;
175
+ var Deno = global$a.Deno;
176
+ var versions = process && process.versions || Deno && Deno.version;
177
+ var v8 = versions && versions.v8;
178
+ var match, version;
179
+
180
+ if (v8) {
181
+ match = v8.split('.');
182
+ // in old Chrome, versions of V8 isn't V8 = Chrome / 10
183
+ // but their correct versions are not interesting for us
184
+ version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
185
+ }
186
+
187
+ // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
188
+ // so check `userAgent` even if `.v8` exists, but 0
189
+ if (!version && userAgent) {
190
+ match = userAgent.match(/Edge\/(\d+)/);
191
+ if (!match || match[1] >= 74) {
192
+ match = userAgent.match(/Chrome\/(\d+)/);
193
+ if (match) version = +match[1];
194
+ }
195
+ }
196
+
197
+ var engineV8Version = version;
198
+
199
+ /* eslint-disable es-x/no-symbol -- required for testing */
200
+
201
+ var V8_VERSION = engineV8Version;
202
+ var fails$7 = fails$b;
203
+
204
+ // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- required for testing
205
+ var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$7(function () {
206
+ var symbol = Symbol();
207
+ // Chrome 38 Symbol has incorrect toString conversion
208
+ // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
209
+ return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
210
+ // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
211
+ !Symbol.sham && V8_VERSION && V8_VERSION < 41;
212
+ });
213
+
214
+ /* eslint-disable es-x/no-symbol -- required for testing */
215
+
216
+ var NATIVE_SYMBOL$1 = nativeSymbol;
217
+
218
+ var useSymbolAsUid = NATIVE_SYMBOL$1
219
+ && !Symbol.sham
220
+ && typeof Symbol.iterator == 'symbol';
221
+
222
+ var getBuiltIn$2 = getBuiltIn$4;
223
+ var isCallable$b = isCallable$e;
224
+ var isPrototypeOf = objectIsPrototypeOf;
225
+ var USE_SYMBOL_AS_UID$1 = useSymbolAsUid;
226
+
227
+ var $Object$2 = Object;
228
+
229
+ var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) {
230
+ return typeof it == 'symbol';
231
+ } : function (it) {
232
+ var $Symbol = getBuiltIn$2('Symbol');
233
+ return isCallable$b($Symbol) && isPrototypeOf($Symbol.prototype, $Object$2(it));
234
+ };
235
+
236
+ var $String$2 = String;
237
+
238
+ var tryToString$1 = function (argument) {
239
+ try {
240
+ return $String$2(argument);
241
+ } catch (error) {
242
+ return 'Object';
243
+ }
244
+ };
245
+
246
+ var isCallable$a = isCallable$e;
247
+ var tryToString = tryToString$1;
248
+
249
+ var $TypeError$5 = TypeError;
250
+
251
+ // `Assert: IsCallable(argument) is true`
252
+ var aCallable$1 = function (argument) {
253
+ if (isCallable$a(argument)) return argument;
254
+ throw $TypeError$5(tryToString(argument) + ' is not a function');
255
+ };
256
+
257
+ var aCallable = aCallable$1;
258
+
259
+ // `GetMethod` abstract operation
260
+ // https://tc39.es/ecma262/#sec-getmethod
261
+ var getMethod$1 = function (V, P) {
262
+ var func = V[P];
263
+ return func == null ? undefined : aCallable(func);
264
+ };
265
+
266
+ var call$4 = functionCall;
267
+ var isCallable$9 = isCallable$e;
268
+ var isObject$4 = isObject$5;
269
+
270
+ var $TypeError$4 = TypeError;
271
+
272
+ // `OrdinaryToPrimitive` abstract operation
273
+ // https://tc39.es/ecma262/#sec-ordinarytoprimitive
274
+ var ordinaryToPrimitive$1 = function (input, pref) {
275
+ var fn, val;
276
+ if (pref === 'string' && isCallable$9(fn = input.toString) && !isObject$4(val = call$4(fn, input))) return val;
277
+ if (isCallable$9(fn = input.valueOf) && !isObject$4(val = call$4(fn, input))) return val;
278
+ if (pref !== 'string' && isCallable$9(fn = input.toString) && !isObject$4(val = call$4(fn, input))) return val;
279
+ throw $TypeError$4("Can't convert object to primitive value");
280
+ };
281
+
282
+ var shared$3 = {exports: {}};
283
+
284
+ var global$9 = global$c;
285
+
286
+ // eslint-disable-next-line es-x/no-object-defineproperty -- safe
287
+ var defineProperty$5 = Object.defineProperty;
288
+
289
+ var defineGlobalProperty$3 = function (key, value) {
290
+ try {
291
+ defineProperty$5(global$9, key, { value: value, configurable: true, writable: true });
292
+ } catch (error) {
293
+ global$9[key] = value;
294
+ } return value;
295
+ };
296
+
297
+ var global$8 = global$c;
298
+ var defineGlobalProperty$2 = defineGlobalProperty$3;
299
+
300
+ var SHARED = '__core-js_shared__';
301
+ var store$3 = global$8[SHARED] || defineGlobalProperty$2(SHARED, {});
302
+
303
+ var sharedStore = store$3;
304
+
305
+ var store$2 = sharedStore;
306
+
307
+ (shared$3.exports = function (key, value) {
308
+ return store$2[key] || (store$2[key] = value !== undefined ? value : {});
309
+ })('versions', []).push({
310
+ version: '3.22.8',
311
+ mode: 'global',
312
+ copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)',
313
+ license: 'https://github.com/zloirock/core-js/blob/v3.22.8/LICENSE',
314
+ source: 'https://github.com/zloirock/core-js'
315
+ });
316
+
317
+ var requireObjectCoercible = requireObjectCoercible$2;
318
+
319
+ var $Object$1 = Object;
320
+
321
+ // `ToObject` abstract operation
322
+ // https://tc39.es/ecma262/#sec-toobject
323
+ var toObject$3 = function (argument) {
324
+ return $Object$1(requireObjectCoercible(argument));
325
+ };
326
+
327
+ var uncurryThis$7 = functionUncurryThis;
328
+ var toObject$2 = toObject$3;
329
+
330
+ var hasOwnProperty = uncurryThis$7({}.hasOwnProperty);
331
+
332
+ // `HasOwnProperty` abstract operation
333
+ // https://tc39.es/ecma262/#sec-hasownproperty
334
+ // eslint-disable-next-line es-x/no-object-hasown -- safe
335
+ var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
336
+ return hasOwnProperty(toObject$2(it), key);
337
+ };
338
+
339
+ var uncurryThis$6 = functionUncurryThis;
340
+
341
+ var id = 0;
342
+ var postfix = Math.random();
343
+ var toString = uncurryThis$6(1.0.toString);
344
+
345
+ var uid$2 = function (key) {
346
+ return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36);
347
+ };
348
+
349
+ var global$7 = global$c;
350
+ var shared$2 = shared$3.exports;
351
+ var hasOwn$8 = hasOwnProperty_1;
352
+ var uid$1 = uid$2;
353
+ var NATIVE_SYMBOL = nativeSymbol;
354
+ var USE_SYMBOL_AS_UID = useSymbolAsUid;
355
+
356
+ var WellKnownSymbolsStore = shared$2('wks');
357
+ var Symbol$1 = global$7.Symbol;
358
+ var symbolFor = Symbol$1 && Symbol$1['for'];
359
+ var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1;
360
+
361
+ var wellKnownSymbol$6 = function (name) {
362
+ if (!hasOwn$8(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) {
363
+ var description = 'Symbol.' + name;
364
+ if (NATIVE_SYMBOL && hasOwn$8(Symbol$1, name)) {
365
+ WellKnownSymbolsStore[name] = Symbol$1[name];
366
+ } else if (USE_SYMBOL_AS_UID && symbolFor) {
367
+ WellKnownSymbolsStore[name] = symbolFor(description);
368
+ } else {
369
+ WellKnownSymbolsStore[name] = createWellKnownSymbol(description);
370
+ }
371
+ } return WellKnownSymbolsStore[name];
372
+ };
373
+
374
+ var call$3 = functionCall;
375
+ var isObject$3 = isObject$5;
376
+ var isSymbol$1 = isSymbol$2;
377
+ var getMethod = getMethod$1;
378
+ var ordinaryToPrimitive = ordinaryToPrimitive$1;
379
+ var wellKnownSymbol$5 = wellKnownSymbol$6;
380
+
381
+ var $TypeError$3 = TypeError;
382
+ var TO_PRIMITIVE = wellKnownSymbol$5('toPrimitive');
383
+
384
+ // `ToPrimitive` abstract operation
385
+ // https://tc39.es/ecma262/#sec-toprimitive
386
+ var toPrimitive$1 = function (input, pref) {
387
+ if (!isObject$3(input) || isSymbol$1(input)) return input;
388
+ var exoticToPrim = getMethod(input, TO_PRIMITIVE);
389
+ var result;
390
+ if (exoticToPrim) {
391
+ if (pref === undefined) pref = 'default';
392
+ result = call$3(exoticToPrim, input, pref);
393
+ if (!isObject$3(result) || isSymbol$1(result)) return result;
394
+ throw $TypeError$3("Can't convert object to primitive value");
395
+ }
396
+ if (pref === undefined) pref = 'number';
397
+ return ordinaryToPrimitive(input, pref);
398
+ };
399
+
400
+ var toPrimitive = toPrimitive$1;
401
+ var isSymbol = isSymbol$2;
402
+
403
+ // `ToPropertyKey` abstract operation
404
+ // https://tc39.es/ecma262/#sec-topropertykey
405
+ var toPropertyKey$2 = function (argument) {
406
+ var key = toPrimitive(argument, 'string');
407
+ return isSymbol(key) ? key : key + '';
408
+ };
409
+
410
+ var global$6 = global$c;
411
+ var isObject$2 = isObject$5;
412
+
413
+ var document$1 = global$6.document;
414
+ // typeof document.createElement is 'object' in old IE
415
+ var EXISTS$1 = isObject$2(document$1) && isObject$2(document$1.createElement);
416
+
417
+ var documentCreateElement$2 = function (it) {
418
+ return EXISTS$1 ? document$1.createElement(it) : {};
419
+ };
420
+
421
+ var DESCRIPTORS$9 = descriptors;
422
+ var fails$6 = fails$b;
423
+ var createElement = documentCreateElement$2;
424
+
425
+ // Thanks to IE8 for its funny defineProperty
426
+ var ie8DomDefine = !DESCRIPTORS$9 && !fails$6(function () {
427
+ // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing
428
+ return Object.defineProperty(createElement('div'), 'a', {
429
+ get: function () { return 7; }
430
+ }).a != 7;
431
+ });
432
+
433
+ var DESCRIPTORS$8 = descriptors;
434
+ var call$2 = functionCall;
435
+ var propertyIsEnumerableModule$1 = objectPropertyIsEnumerable;
436
+ var createPropertyDescriptor$2 = createPropertyDescriptor$3;
437
+ var toIndexedObject$4 = toIndexedObject$5;
438
+ var toPropertyKey$1 = toPropertyKey$2;
439
+ var hasOwn$7 = hasOwnProperty_1;
440
+ var IE8_DOM_DEFINE$1 = ie8DomDefine;
441
+
442
+ // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
443
+ var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
444
+
445
+ // `Object.getOwnPropertyDescriptor` method
446
+ // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
447
+ objectGetOwnPropertyDescriptor.f = DESCRIPTORS$8 ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) {
448
+ O = toIndexedObject$4(O);
449
+ P = toPropertyKey$1(P);
450
+ if (IE8_DOM_DEFINE$1) try {
451
+ return $getOwnPropertyDescriptor$1(O, P);
452
+ } catch (error) { /* empty */ }
453
+ if (hasOwn$7(O, P)) return createPropertyDescriptor$2(!call$2(propertyIsEnumerableModule$1.f, O, P), O[P]);
454
+ };
455
+
456
+ var objectDefineProperty = {};
457
+
458
+ var DESCRIPTORS$7 = descriptors;
459
+ var fails$5 = fails$b;
460
+
461
+ // V8 ~ Chrome 36-
462
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3334
463
+ var v8PrototypeDefineBug = DESCRIPTORS$7 && fails$5(function () {
464
+ // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing
465
+ return Object.defineProperty(function () { /* empty */ }, 'prototype', {
466
+ value: 42,
467
+ writable: false
468
+ }).prototype != 42;
469
+ });
470
+
471
+ var isObject$1 = isObject$5;
472
+
473
+ var $String$1 = String;
474
+ var $TypeError$2 = TypeError;
475
+
476
+ // `Assert: Type(argument) is Object`
477
+ var anObject$5 = function (argument) {
478
+ if (isObject$1(argument)) return argument;
479
+ throw $TypeError$2($String$1(argument) + ' is not an object');
480
+ };
481
+
482
+ var DESCRIPTORS$6 = descriptors;
483
+ var IE8_DOM_DEFINE = ie8DomDefine;
484
+ var V8_PROTOTYPE_DEFINE_BUG$1 = v8PrototypeDefineBug;
485
+ var anObject$4 = anObject$5;
486
+ var toPropertyKey = toPropertyKey$2;
487
+
488
+ var $TypeError$1 = TypeError;
489
+ // eslint-disable-next-line es-x/no-object-defineproperty -- safe
490
+ var $defineProperty = Object.defineProperty;
491
+ // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
492
+ var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
493
+ var ENUMERABLE = 'enumerable';
494
+ var CONFIGURABLE$1 = 'configurable';
495
+ var WRITABLE = 'writable';
496
+
497
+ // `Object.defineProperty` method
498
+ // https://tc39.es/ecma262/#sec-object.defineproperty
499
+ objectDefineProperty.f = DESCRIPTORS$6 ? V8_PROTOTYPE_DEFINE_BUG$1 ? function defineProperty(O, P, Attributes) {
500
+ anObject$4(O);
501
+ P = toPropertyKey(P);
502
+ anObject$4(Attributes);
503
+ if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
504
+ var current = $getOwnPropertyDescriptor(O, P);
505
+ if (current && current[WRITABLE]) {
506
+ O[P] = Attributes.value;
507
+ Attributes = {
508
+ configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1],
509
+ enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
510
+ writable: false
511
+ };
512
+ }
513
+ } return $defineProperty(O, P, Attributes);
514
+ } : $defineProperty : function defineProperty(O, P, Attributes) {
515
+ anObject$4(O);
516
+ P = toPropertyKey(P);
517
+ anObject$4(Attributes);
518
+ if (IE8_DOM_DEFINE) try {
519
+ return $defineProperty(O, P, Attributes);
520
+ } catch (error) { /* empty */ }
521
+ if ('get' in Attributes || 'set' in Attributes) throw $TypeError$1('Accessors not supported');
522
+ if ('value' in Attributes) O[P] = Attributes.value;
523
+ return O;
524
+ };
525
+
526
+ var DESCRIPTORS$5 = descriptors;
527
+ var definePropertyModule$2 = objectDefineProperty;
528
+ var createPropertyDescriptor$1 = createPropertyDescriptor$3;
529
+
530
+ var createNonEnumerableProperty$5 = DESCRIPTORS$5 ? function (object, key, value) {
531
+ return definePropertyModule$2.f(object, key, createPropertyDescriptor$1(1, value));
532
+ } : function (object, key, value) {
533
+ object[key] = value;
534
+ return object;
535
+ };
536
+
537
+ var makeBuiltIn$2 = {exports: {}};
538
+
539
+ var DESCRIPTORS$4 = descriptors;
540
+ var hasOwn$6 = hasOwnProperty_1;
541
+
542
+ var FunctionPrototype = Function.prototype;
543
+ // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
544
+ var getDescriptor = DESCRIPTORS$4 && Object.getOwnPropertyDescriptor;
545
+
546
+ var EXISTS = hasOwn$6(FunctionPrototype, 'name');
547
+ // additional protection from minified / mangled / dropped function names
548
+ var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
549
+ var CONFIGURABLE = EXISTS && (!DESCRIPTORS$4 || (DESCRIPTORS$4 && getDescriptor(FunctionPrototype, 'name').configurable));
550
+
551
+ var functionName = {
552
+ EXISTS: EXISTS,
553
+ PROPER: PROPER,
554
+ CONFIGURABLE: CONFIGURABLE
555
+ };
556
+
557
+ var uncurryThis$5 = functionUncurryThis;
558
+ var isCallable$8 = isCallable$e;
559
+ var store$1 = sharedStore;
560
+
561
+ var functionToString = uncurryThis$5(Function.toString);
562
+
563
+ // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
564
+ if (!isCallable$8(store$1.inspectSource)) {
565
+ store$1.inspectSource = function (it) {
566
+ return functionToString(it);
567
+ };
568
+ }
569
+
570
+ var inspectSource$2 = store$1.inspectSource;
571
+
572
+ var global$5 = global$c;
573
+ var isCallable$7 = isCallable$e;
574
+ var inspectSource$1 = inspectSource$2;
575
+
576
+ var WeakMap$1 = global$5.WeakMap;
577
+
578
+ var nativeWeakMap = isCallable$7(WeakMap$1) && /native code/.test(inspectSource$1(WeakMap$1));
579
+
580
+ var shared$1 = shared$3.exports;
581
+ var uid = uid$2;
582
+
583
+ var keys = shared$1('keys');
584
+
585
+ var sharedKey$3 = function (key) {
586
+ return keys[key] || (keys[key] = uid(key));
587
+ };
588
+
589
+ var hiddenKeys$4 = {};
590
+
591
+ var NATIVE_WEAK_MAP = nativeWeakMap;
592
+ var global$4 = global$c;
593
+ var uncurryThis$4 = functionUncurryThis;
594
+ var isObject = isObject$5;
595
+ var createNonEnumerableProperty$4 = createNonEnumerableProperty$5;
596
+ var hasOwn$5 = hasOwnProperty_1;
597
+ var shared = sharedStore;
598
+ var sharedKey$2 = sharedKey$3;
599
+ var hiddenKeys$3 = hiddenKeys$4;
600
+
601
+ var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
602
+ var TypeError$1 = global$4.TypeError;
603
+ var WeakMap = global$4.WeakMap;
604
+ var set, get, has;
605
+
606
+ var enforce = function (it) {
607
+ return has(it) ? get(it) : set(it, {});
608
+ };
609
+
610
+ var getterFor = function (TYPE) {
611
+ return function (it) {
612
+ var state;
613
+ if (!isObject(it) || (state = get(it)).type !== TYPE) {
614
+ throw TypeError$1('Incompatible receiver, ' + TYPE + ' required');
615
+ } return state;
616
+ };
617
+ };
618
+
619
+ if (NATIVE_WEAK_MAP || shared.state) {
620
+ var store = shared.state || (shared.state = new WeakMap());
621
+ var wmget = uncurryThis$4(store.get);
622
+ var wmhas = uncurryThis$4(store.has);
623
+ var wmset = uncurryThis$4(store.set);
624
+ set = function (it, metadata) {
625
+ if (wmhas(store, it)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
626
+ metadata.facade = it;
627
+ wmset(store, it, metadata);
628
+ return metadata;
629
+ };
630
+ get = function (it) {
631
+ return wmget(store, it) || {};
632
+ };
633
+ has = function (it) {
634
+ return wmhas(store, it);
635
+ };
636
+ } else {
637
+ var STATE = sharedKey$2('state');
638
+ hiddenKeys$3[STATE] = true;
639
+ set = function (it, metadata) {
640
+ if (hasOwn$5(it, STATE)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
641
+ metadata.facade = it;
642
+ createNonEnumerableProperty$4(it, STATE, metadata);
643
+ return metadata;
644
+ };
645
+ get = function (it) {
646
+ return hasOwn$5(it, STATE) ? it[STATE] : {};
647
+ };
648
+ has = function (it) {
649
+ return hasOwn$5(it, STATE);
650
+ };
651
+ }
652
+
653
+ var internalState = {
654
+ set: set,
655
+ get: get,
656
+ has: has,
657
+ enforce: enforce,
658
+ getterFor: getterFor
659
+ };
660
+
661
+ var fails$4 = fails$b;
662
+ var isCallable$6 = isCallable$e;
663
+ var hasOwn$4 = hasOwnProperty_1;
664
+ var DESCRIPTORS$3 = descriptors;
665
+ var CONFIGURABLE_FUNCTION_NAME$1 = functionName.CONFIGURABLE;
666
+ var inspectSource = inspectSource$2;
667
+ var InternalStateModule$1 = internalState;
668
+
669
+ var enforceInternalState = InternalStateModule$1.enforce;
670
+ var getInternalState$1 = InternalStateModule$1.get;
671
+ // eslint-disable-next-line es-x/no-object-defineproperty -- safe
672
+ var defineProperty$4 = Object.defineProperty;
673
+
674
+ var CONFIGURABLE_LENGTH = DESCRIPTORS$3 && !fails$4(function () {
675
+ return defineProperty$4(function () { /* empty */ }, 'length', { value: 8 }).length !== 8;
676
+ });
677
+
678
+ var TEMPLATE = String(String).split('String');
679
+
680
+ var makeBuiltIn$1 = makeBuiltIn$2.exports = function (value, name, options) {
681
+ if (String(name).slice(0, 7) === 'Symbol(') {
682
+ name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']';
683
+ }
684
+ if (options && options.getter) name = 'get ' + name;
685
+ if (options && options.setter) name = 'set ' + name;
686
+ if (!hasOwn$4(value, 'name') || (CONFIGURABLE_FUNCTION_NAME$1 && value.name !== name)) {
687
+ defineProperty$4(value, 'name', { value: name, configurable: true });
688
+ }
689
+ if (CONFIGURABLE_LENGTH && options && hasOwn$4(options, 'arity') && value.length !== options.arity) {
690
+ defineProperty$4(value, 'length', { value: options.arity });
691
+ }
692
+ try {
693
+ if (options && hasOwn$4(options, 'constructor') && options.constructor) {
694
+ if (DESCRIPTORS$3) defineProperty$4(value, 'prototype', { writable: false });
695
+ // in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable
696
+ } else if (value.prototype) value.prototype = undefined;
697
+ } catch (error) { /* empty */ }
698
+ var state = enforceInternalState(value);
699
+ if (!hasOwn$4(state, 'source')) {
700
+ state.source = TEMPLATE.join(typeof name == 'string' ? name : '');
701
+ } return value;
702
+ };
703
+
704
+ // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
705
+ // eslint-disable-next-line no-extend-native -- required
706
+ Function.prototype.toString = makeBuiltIn$1(function toString() {
707
+ return isCallable$6(this) && getInternalState$1(this).source || inspectSource(this);
708
+ }, 'toString');
709
+
710
+ var isCallable$5 = isCallable$e;
711
+ var createNonEnumerableProperty$3 = createNonEnumerableProperty$5;
712
+ var makeBuiltIn = makeBuiltIn$2.exports;
713
+ var defineGlobalProperty$1 = defineGlobalProperty$3;
714
+
715
+ var defineBuiltIn$3 = function (O, key, value, options) {
716
+ if (!options) options = {};
717
+ var simple = options.enumerable;
718
+ var name = options.name !== undefined ? options.name : key;
719
+ if (isCallable$5(value)) makeBuiltIn(value, name, options);
720
+ if (options.global) {
721
+ if (simple) O[key] = value;
722
+ else defineGlobalProperty$1(key, value);
723
+ } else {
724
+ if (!options.unsafe) delete O[key];
725
+ else if (O[key]) simple = true;
726
+ if (simple) O[key] = value;
727
+ else createNonEnumerableProperty$3(O, key, value);
728
+ } return O;
729
+ };
730
+
731
+ var objectGetOwnPropertyNames = {};
732
+
733
+ var ceil = Math.ceil;
734
+ var floor = Math.floor;
735
+
736
+ // `Math.trunc` method
737
+ // https://tc39.es/ecma262/#sec-math.trunc
738
+ // eslint-disable-next-line es-x/no-math-trunc -- safe
739
+ var mathTrunc = Math.trunc || function trunc(x) {
740
+ var n = +x;
741
+ return (n > 0 ? floor : ceil)(n);
742
+ };
743
+
744
+ var trunc = mathTrunc;
745
+
746
+ // `ToIntegerOrInfinity` abstract operation
747
+ // https://tc39.es/ecma262/#sec-tointegerorinfinity
748
+ var toIntegerOrInfinity$2 = function (argument) {
749
+ var number = +argument;
750
+ // eslint-disable-next-line no-self-compare -- NaN check
751
+ return number !== number || number === 0 ? 0 : trunc(number);
752
+ };
753
+
754
+ var toIntegerOrInfinity$1 = toIntegerOrInfinity$2;
755
+
756
+ var max = Math.max;
757
+ var min$1 = Math.min;
758
+
759
+ // Helper for a popular repeating case of the spec:
760
+ // Let integer be ? ToInteger(index).
761
+ // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
762
+ var toAbsoluteIndex$1 = function (index, length) {
763
+ var integer = toIntegerOrInfinity$1(index);
764
+ return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
765
+ };
766
+
767
+ var toIntegerOrInfinity = toIntegerOrInfinity$2;
768
+
769
+ var min = Math.min;
770
+
771
+ // `ToLength` abstract operation
772
+ // https://tc39.es/ecma262/#sec-tolength
773
+ var toLength$1 = function (argument) {
774
+ return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
775
+ };
776
+
777
+ var toLength = toLength$1;
778
+
779
+ // `LengthOfArrayLike` abstract operation
780
+ // https://tc39.es/ecma262/#sec-lengthofarraylike
781
+ var lengthOfArrayLike$1 = function (obj) {
782
+ return toLength(obj.length);
783
+ };
784
+
785
+ var toIndexedObject$3 = toIndexedObject$5;
786
+ var toAbsoluteIndex = toAbsoluteIndex$1;
787
+ var lengthOfArrayLike = lengthOfArrayLike$1;
788
+
789
+ // `Array.prototype.{ indexOf, includes }` methods implementation
790
+ var createMethod = function (IS_INCLUDES) {
791
+ return function ($this, el, fromIndex) {
792
+ var O = toIndexedObject$3($this);
793
+ var length = lengthOfArrayLike(O);
794
+ var index = toAbsoluteIndex(fromIndex, length);
795
+ var value;
796
+ // Array#includes uses SameValueZero equality algorithm
797
+ // eslint-disable-next-line no-self-compare -- NaN check
798
+ if (IS_INCLUDES && el != el) while (length > index) {
799
+ value = O[index++];
800
+ // eslint-disable-next-line no-self-compare -- NaN check
801
+ if (value != value) return true;
802
+ // Array#indexOf ignores holes, Array#includes - not
803
+ } else for (;length > index; index++) {
804
+ if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
805
+ } return !IS_INCLUDES && -1;
806
+ };
807
+ };
808
+
809
+ var arrayIncludes = {
810
+ // `Array.prototype.includes` method
811
+ // https://tc39.es/ecma262/#sec-array.prototype.includes
812
+ includes: createMethod(true),
813
+ // `Array.prototype.indexOf` method
814
+ // https://tc39.es/ecma262/#sec-array.prototype.indexof
815
+ indexOf: createMethod(false)
816
+ };
817
+
818
+ var uncurryThis$3 = functionUncurryThis;
819
+ var hasOwn$3 = hasOwnProperty_1;
820
+ var toIndexedObject$2 = toIndexedObject$5;
821
+ var indexOf = arrayIncludes.indexOf;
822
+ var hiddenKeys$2 = hiddenKeys$4;
823
+
824
+ var push = uncurryThis$3([].push);
825
+
826
+ var objectKeysInternal = function (object, names) {
827
+ var O = toIndexedObject$2(object);
828
+ var i = 0;
829
+ var result = [];
830
+ var key;
831
+ for (key in O) !hasOwn$3(hiddenKeys$2, key) && hasOwn$3(O, key) && push(result, key);
832
+ // Don't enum bug & hidden keys
833
+ while (names.length > i) if (hasOwn$3(O, key = names[i++])) {
834
+ ~indexOf(result, key) || push(result, key);
835
+ }
836
+ return result;
837
+ };
838
+
839
+ // IE8- don't enum bug keys
840
+ var enumBugKeys$3 = [
841
+ 'constructor',
842
+ 'hasOwnProperty',
843
+ 'isPrototypeOf',
844
+ 'propertyIsEnumerable',
845
+ 'toLocaleString',
846
+ 'toString',
847
+ 'valueOf'
848
+ ];
849
+
850
+ var internalObjectKeys$1 = objectKeysInternal;
851
+ var enumBugKeys$2 = enumBugKeys$3;
852
+
853
+ var hiddenKeys$1 = enumBugKeys$2.concat('length', 'prototype');
854
+
855
+ // `Object.getOwnPropertyNames` method
856
+ // https://tc39.es/ecma262/#sec-object.getownpropertynames
857
+ // eslint-disable-next-line es-x/no-object-getownpropertynames -- safe
858
+ objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
859
+ return internalObjectKeys$1(O, hiddenKeys$1);
860
+ };
861
+
862
+ var objectGetOwnPropertySymbols = {};
863
+
864
+ // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- safe
865
+ objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
866
+
867
+ var getBuiltIn$1 = getBuiltIn$4;
868
+ var uncurryThis$2 = functionUncurryThis;
869
+ var getOwnPropertyNamesModule = objectGetOwnPropertyNames;
870
+ var getOwnPropertySymbolsModule$1 = objectGetOwnPropertySymbols;
871
+ var anObject$3 = anObject$5;
872
+
873
+ var concat$1 = uncurryThis$2([].concat);
874
+
875
+ // all object keys, includes non-enumerable and symbols
876
+ var ownKeys$1 = getBuiltIn$1('Reflect', 'ownKeys') || function ownKeys(it) {
877
+ var keys = getOwnPropertyNamesModule.f(anObject$3(it));
878
+ var getOwnPropertySymbols = getOwnPropertySymbolsModule$1.f;
879
+ return getOwnPropertySymbols ? concat$1(keys, getOwnPropertySymbols(it)) : keys;
880
+ };
881
+
882
+ var hasOwn$2 = hasOwnProperty_1;
883
+ var ownKeys = ownKeys$1;
884
+ var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor;
885
+ var definePropertyModule$1 = objectDefineProperty;
886
+
887
+ var copyConstructorProperties$1 = function (target, source, exceptions) {
888
+ var keys = ownKeys(source);
889
+ var defineProperty = definePropertyModule$1.f;
890
+ var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
891
+ for (var i = 0; i < keys.length; i++) {
892
+ var key = keys[i];
893
+ if (!hasOwn$2(target, key) && !(exceptions && hasOwn$2(exceptions, key))) {
894
+ defineProperty(target, key, getOwnPropertyDescriptor(source, key));
895
+ }
896
+ }
897
+ };
898
+
899
+ var fails$3 = fails$b;
900
+ var isCallable$4 = isCallable$e;
901
+
902
+ var replacement = /#|\.prototype\./;
903
+
904
+ var isForced$1 = function (feature, detection) {
905
+ var value = data[normalize(feature)];
906
+ return value == POLYFILL ? true
907
+ : value == NATIVE ? false
908
+ : isCallable$4(detection) ? fails$3(detection)
909
+ : !!detection;
910
+ };
911
+
912
+ var normalize = isForced$1.normalize = function (string) {
913
+ return String(string).replace(replacement, '.').toLowerCase();
914
+ };
915
+
916
+ var data = isForced$1.data = {};
917
+ var NATIVE = isForced$1.NATIVE = 'N';
918
+ var POLYFILL = isForced$1.POLYFILL = 'P';
919
+
920
+ var isForced_1 = isForced$1;
921
+
922
+ var global$3 = global$c;
923
+ var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
924
+ var createNonEnumerableProperty$2 = createNonEnumerableProperty$5;
925
+ var defineBuiltIn$2 = defineBuiltIn$3;
926
+ var defineGlobalProperty = defineGlobalProperty$3;
927
+ var copyConstructorProperties = copyConstructorProperties$1;
928
+ var isForced = isForced_1;
929
+
930
+ /*
931
+ options.target - name of the target object
932
+ options.global - target is the global object
933
+ options.stat - export as static methods of target
934
+ options.proto - export as prototype methods of target
935
+ options.real - real prototype method for the `pure` version
936
+ options.forced - export even if the native feature is available
937
+ options.bind - bind methods to the target, required for the `pure` version
938
+ options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
939
+ options.unsafe - use the simple assignment of property instead of delete + defineProperty
940
+ options.sham - add a flag to not completely full polyfills
941
+ options.enumerable - export as enumerable property
942
+ options.dontCallGetSet - prevent calling a getter on target
943
+ options.name - the .name of the function if it does not match the key
944
+ */
945
+ var _export = function (options, source) {
946
+ var TARGET = options.target;
947
+ var GLOBAL = options.global;
948
+ var STATIC = options.stat;
949
+ var FORCED, target, key, targetProperty, sourceProperty, descriptor;
950
+ if (GLOBAL) {
951
+ target = global$3;
952
+ } else if (STATIC) {
953
+ target = global$3[TARGET] || defineGlobalProperty(TARGET, {});
954
+ } else {
955
+ target = (global$3[TARGET] || {}).prototype;
956
+ }
957
+ if (target) for (key in source) {
958
+ sourceProperty = source[key];
959
+ if (options.dontCallGetSet) {
960
+ descriptor = getOwnPropertyDescriptor(target, key);
961
+ targetProperty = descriptor && descriptor.value;
962
+ } else targetProperty = target[key];
963
+ FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
964
+ // contained in target
965
+ if (!FORCED && targetProperty !== undefined) {
966
+ if (typeof sourceProperty == typeof targetProperty) continue;
967
+ copyConstructorProperties(sourceProperty, targetProperty);
968
+ }
969
+ // add a flag to not completely full polyfills
970
+ if (options.sham || (targetProperty && targetProperty.sham)) {
971
+ createNonEnumerableProperty$2(sourceProperty, 'sham', true);
972
+ }
973
+ defineBuiltIn$2(target, key, sourceProperty, options);
974
+ }
975
+ };
976
+
977
+ var internalObjectKeys = objectKeysInternal;
978
+ var enumBugKeys$1 = enumBugKeys$3;
979
+
980
+ // `Object.keys` method
981
+ // https://tc39.es/ecma262/#sec-object.keys
982
+ // eslint-disable-next-line es-x/no-object-keys -- safe
983
+ var objectKeys$2 = Object.keys || function keys(O) {
984
+ return internalObjectKeys(O, enumBugKeys$1);
985
+ };
986
+
987
+ var DESCRIPTORS$2 = descriptors;
988
+ var uncurryThis$1 = functionUncurryThis;
989
+ var call$1 = functionCall;
990
+ var fails$2 = fails$b;
991
+ var objectKeys$1 = objectKeys$2;
992
+ var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols;
993
+ var propertyIsEnumerableModule = objectPropertyIsEnumerable;
994
+ var toObject$1 = toObject$3;
995
+ var IndexedObject = indexedObject;
996
+
997
+ // eslint-disable-next-line es-x/no-object-assign -- safe
998
+ var $assign = Object.assign;
999
+ // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing
1000
+ var defineProperty$3 = Object.defineProperty;
1001
+ var concat = uncurryThis$1([].concat);
1002
+
1003
+ // `Object.assign` method
1004
+ // https://tc39.es/ecma262/#sec-object.assign
1005
+ var objectAssign = !$assign || fails$2(function () {
1006
+ // should have correct order of operations (Edge bug)
1007
+ if (DESCRIPTORS$2 && $assign({ b: 1 }, $assign(defineProperty$3({}, 'a', {
1008
+ enumerable: true,
1009
+ get: function () {
1010
+ defineProperty$3(this, 'b', {
1011
+ value: 3,
1012
+ enumerable: false
1013
+ });
1014
+ }
1015
+ }), { b: 2 })).b !== 1) return true;
1016
+ // should work with symbols and should have deterministic property order (V8 bug)
1017
+ var A = {};
1018
+ var B = {};
1019
+ // eslint-disable-next-line es-x/no-symbol -- safe
1020
+ var symbol = Symbol();
1021
+ var alphabet = 'abcdefghijklmnopqrst';
1022
+ A[symbol] = 7;
1023
+ alphabet.split('').forEach(function (chr) { B[chr] = chr; });
1024
+ return $assign({}, A)[symbol] != 7 || objectKeys$1($assign({}, B)).join('') != alphabet;
1025
+ }) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
1026
+ var T = toObject$1(target);
1027
+ var argumentsLength = arguments.length;
1028
+ var index = 1;
1029
+ var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
1030
+ var propertyIsEnumerable = propertyIsEnumerableModule.f;
1031
+ while (argumentsLength > index) {
1032
+ var S = IndexedObject(arguments[index++]);
1033
+ var keys = getOwnPropertySymbols ? concat(objectKeys$1(S), getOwnPropertySymbols(S)) : objectKeys$1(S);
1034
+ var length = keys.length;
1035
+ var j = 0;
1036
+ var key;
1037
+ while (length > j) {
1038
+ key = keys[j++];
1039
+ if (!DESCRIPTORS$2 || call$1(propertyIsEnumerable, S, key)) T[key] = S[key];
1040
+ }
1041
+ } return T;
1042
+ } : $assign;
1043
+
1044
+ var $$2 = _export;
1045
+ var assign = objectAssign;
1046
+
1047
+ // `Object.assign` method
1048
+ // https://tc39.es/ecma262/#sec-object.assign
1049
+ // eslint-disable-next-line es-x/no-object-assign -- required for testing
1050
+ $$2({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }, {
1051
+ assign: assign
1052
+ });
1053
+
1054
+ /******************************************************************************
1055
+ Copyright (c) Microsoft Corporation.
1056
+
1057
+ Permission to use, copy, modify, and/or distribute this software for any
1058
+ purpose with or without fee is hereby granted.
1059
+
1060
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1061
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1062
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1063
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1064
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1065
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1066
+ PERFORMANCE OF THIS SOFTWARE.
1067
+ ***************************************************************************** */
1068
+
1069
+ function __awaiter(thisArg, _arguments, P, generator) {
1070
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1071
+ return new (P || (P = Promise))(function (resolve, reject) {
1072
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1073
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1074
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1075
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1076
+ });
1077
+ }
1078
+
1079
+ class HTTPService{constructor(a){this.url=`${a.protocol}://${a.host}:${a.port}`;}resolveBoolean(a,b,c){return __awaiter(this,void 0,void 0,function*(){try{const d=yield axios.post(`${this.url}/flags/${encodeURIComponent(a)}/resolve/boolean`,c);return checkResponse(d,"boolean")?{value:d.data.value,reason:d.data.reason,variant:d.data.variant}:{value:b,reason:StandardResolutionReasons.ERROR,errorCode:ErrorCode.PARSE_ERROR}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:getErrorCode(a),value:b}}})}resolveNumber(a,b,c){return __awaiter(this,void 0,void 0,function*(){try{const d=yield axios.post(`${this.url}/flags/${encodeURIComponent(a)}/resolve/number`,c);return checkResponse(d,"number")?{value:d.data.value,reason:d.data.reason,variant:d.data.variant}:{value:b,reason:StandardResolutionReasons.ERROR,errorCode:ErrorCode.PARSE_ERROR}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:getErrorCode(a),value:b}}})}resolveString(a,b,c){return __awaiter(this,void 0,void 0,function*(){try{const d=yield axios.post(`${this.url}/flags/${encodeURIComponent(a)}/resolve/string`,c);return checkResponse(d,"string")?{value:d.data.value,reason:d.data.reason,variant:d.data.variant}:{value:b,reason:StandardResolutionReasons.ERROR,errorCode:ErrorCode.PARSE_ERROR}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:getErrorCode(a),value:b}}})}resolveObject(a,b,c){return __awaiter(this,void 0,void 0,function*(){try{const d=yield axios.post(`${this.url}/flags/${encodeURIComponent(a)}/resolve/object`,c);return checkResponse(d,"object")?{value:d.data.value,reason:d.data.reason,variant:d.data.variant}:{value:b,reason:StandardResolutionReasons.ERROR,errorCode:ErrorCode.PARSE_ERROR}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:getErrorCode(a),value:b}}})}}function getErrorCode(a){var b;const c=null===(b=null===a||void 0===a?void 0:a.response)||void 0===b?void 0:b.status;let d=StandardResolutionReasons.UNKNOWN;return null!=c&&(404==c?d=ErrorCode.FLAG_NOT_FOUND:400==c&&(d=ErrorCode.TYPE_MISMATCH)),d}function checkResponse(a,b){return !!(a.data&&typeof a.data.value===b&&"string"==typeof a.data.variant&&"string"==typeof a.data.reason)}
1080
+
1081
+ var objectDefineProperties = {};
1082
+
1083
+ var DESCRIPTORS$1 = descriptors;
1084
+ var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug;
1085
+ var definePropertyModule = objectDefineProperty;
1086
+ var anObject$2 = anObject$5;
1087
+ var toIndexedObject$1 = toIndexedObject$5;
1088
+ var objectKeys = objectKeys$2;
1089
+
1090
+ // `Object.defineProperties` method
1091
+ // https://tc39.es/ecma262/#sec-object.defineproperties
1092
+ // eslint-disable-next-line es-x/no-object-defineproperties -- safe
1093
+ objectDefineProperties.f = DESCRIPTORS$1 && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
1094
+ anObject$2(O);
1095
+ var props = toIndexedObject$1(Properties);
1096
+ var keys = objectKeys(Properties);
1097
+ var length = keys.length;
1098
+ var index = 0;
1099
+ var key;
1100
+ while (length > index) definePropertyModule.f(O, key = keys[index++], props[key]);
1101
+ return O;
1102
+ };
1103
+
1104
+ var getBuiltIn = getBuiltIn$4;
1105
+
1106
+ var html$1 = getBuiltIn('document', 'documentElement');
1107
+
1108
+ /* global ActiveXObject -- old IE, WSH */
1109
+
1110
+ var anObject$1 = anObject$5;
1111
+ var definePropertiesModule = objectDefineProperties;
1112
+ var enumBugKeys = enumBugKeys$3;
1113
+ var hiddenKeys = hiddenKeys$4;
1114
+ var html = html$1;
1115
+ var documentCreateElement$1 = documentCreateElement$2;
1116
+ var sharedKey$1 = sharedKey$3;
1117
+
1118
+ var GT = '>';
1119
+ var LT = '<';
1120
+ var PROTOTYPE = 'prototype';
1121
+ var SCRIPT = 'script';
1122
+ var IE_PROTO$1 = sharedKey$1('IE_PROTO');
1123
+
1124
+ var EmptyConstructor = function () { /* empty */ };
1125
+
1126
+ var scriptTag = function (content) {
1127
+ return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
1128
+ };
1129
+
1130
+ // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
1131
+ var NullProtoObjectViaActiveX = function (activeXDocument) {
1132
+ activeXDocument.write(scriptTag(''));
1133
+ activeXDocument.close();
1134
+ var temp = activeXDocument.parentWindow.Object;
1135
+ activeXDocument = null; // avoid memory leak
1136
+ return temp;
1137
+ };
1138
+
1139
+ // Create object with fake `null` prototype: use iframe Object with cleared prototype
1140
+ var NullProtoObjectViaIFrame = function () {
1141
+ // Thrash, waste and sodomy: IE GC bug
1142
+ var iframe = documentCreateElement$1('iframe');
1143
+ var JS = 'java' + SCRIPT + ':';
1144
+ var iframeDocument;
1145
+ iframe.style.display = 'none';
1146
+ html.appendChild(iframe);
1147
+ // https://github.com/zloirock/core-js/issues/475
1148
+ iframe.src = String(JS);
1149
+ iframeDocument = iframe.contentWindow.document;
1150
+ iframeDocument.open();
1151
+ iframeDocument.write(scriptTag('document.F=Object'));
1152
+ iframeDocument.close();
1153
+ return iframeDocument.F;
1154
+ };
1155
+
1156
+ // Check for document.domain and active x support
1157
+ // No need to use active x approach when document.domain is not set
1158
+ // see https://github.com/es-shims/es5-shim/issues/150
1159
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
1160
+ // avoid IE GC bug
1161
+ var activeXDocument;
1162
+ var NullProtoObject = function () {
1163
+ try {
1164
+ activeXDocument = new ActiveXObject('htmlfile');
1165
+ } catch (error) { /* ignore */ }
1166
+ NullProtoObject = typeof document != 'undefined'
1167
+ ? document.domain && activeXDocument
1168
+ ? NullProtoObjectViaActiveX(activeXDocument) // old IE
1169
+ : NullProtoObjectViaIFrame()
1170
+ : NullProtoObjectViaActiveX(activeXDocument); // WSH
1171
+ var length = enumBugKeys.length;
1172
+ while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
1173
+ return NullProtoObject();
1174
+ };
1175
+
1176
+ hiddenKeys[IE_PROTO$1] = true;
1177
+
1178
+ // `Object.create` method
1179
+ // https://tc39.es/ecma262/#sec-object.create
1180
+ // eslint-disable-next-line es-x/no-object-create -- safe
1181
+ var objectCreate = Object.create || function create(O, Properties) {
1182
+ var result;
1183
+ if (O !== null) {
1184
+ EmptyConstructor[PROTOTYPE] = anObject$1(O);
1185
+ result = new EmptyConstructor();
1186
+ EmptyConstructor[PROTOTYPE] = null;
1187
+ // add "__proto__" for Object.getPrototypeOf polyfill
1188
+ result[IE_PROTO$1] = O;
1189
+ } else result = NullProtoObject();
1190
+ return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
1191
+ };
1192
+
1193
+ var wellKnownSymbol$4 = wellKnownSymbol$6;
1194
+ var create$1 = objectCreate;
1195
+ var defineProperty$2 = objectDefineProperty.f;
1196
+
1197
+ var UNSCOPABLES = wellKnownSymbol$4('unscopables');
1198
+ var ArrayPrototype = Array.prototype;
1199
+
1200
+ // Array.prototype[@@unscopables]
1201
+ // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
1202
+ if (ArrayPrototype[UNSCOPABLES] == undefined) {
1203
+ defineProperty$2(ArrayPrototype, UNSCOPABLES, {
1204
+ configurable: true,
1205
+ value: create$1(null)
1206
+ });
1207
+ }
1208
+
1209
+ // add a key to Array.prototype[@@unscopables]
1210
+ var addToUnscopables$1 = function (key) {
1211
+ ArrayPrototype[UNSCOPABLES][key] = true;
1212
+ };
1213
+
1214
+ var iterators = {};
1215
+
1216
+ var fails$1 = fails$b;
1217
+
1218
+ var correctPrototypeGetter = !fails$1(function () {
1219
+ function F() { /* empty */ }
1220
+ F.prototype.constructor = null;
1221
+ // eslint-disable-next-line es-x/no-object-getprototypeof -- required for testing
1222
+ return Object.getPrototypeOf(new F()) !== F.prototype;
1223
+ });
1224
+
1225
+ var hasOwn$1 = hasOwnProperty_1;
1226
+ var isCallable$3 = isCallable$e;
1227
+ var toObject = toObject$3;
1228
+ var sharedKey = sharedKey$3;
1229
+ var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter;
1230
+
1231
+ var IE_PROTO = sharedKey('IE_PROTO');
1232
+ var $Object = Object;
1233
+ var ObjectPrototype = $Object.prototype;
1234
+
1235
+ // `Object.getPrototypeOf` method
1236
+ // https://tc39.es/ecma262/#sec-object.getprototypeof
1237
+ // eslint-disable-next-line es-x/no-object-getprototypeof -- safe
1238
+ var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : function (O) {
1239
+ var object = toObject(O);
1240
+ if (hasOwn$1(object, IE_PROTO)) return object[IE_PROTO];
1241
+ var constructor = object.constructor;
1242
+ if (isCallable$3(constructor) && object instanceof constructor) {
1243
+ return constructor.prototype;
1244
+ } return object instanceof $Object ? ObjectPrototype : null;
1245
+ };
1246
+
1247
+ var fails = fails$b;
1248
+ var isCallable$2 = isCallable$e;
1249
+ var getPrototypeOf$1 = objectGetPrototypeOf;
1250
+ var defineBuiltIn$1 = defineBuiltIn$3;
1251
+ var wellKnownSymbol$3 = wellKnownSymbol$6;
1252
+
1253
+ var ITERATOR$2 = wellKnownSymbol$3('iterator');
1254
+ var BUGGY_SAFARI_ITERATORS$1 = false;
1255
+
1256
+ // `%IteratorPrototype%` object
1257
+ // https://tc39.es/ecma262/#sec-%iteratorprototype%-object
1258
+ var IteratorPrototype$2, PrototypeOfArrayIteratorPrototype, arrayIterator;
1259
+
1260
+ /* eslint-disable es-x/no-array-prototype-keys -- safe */
1261
+ if ([].keys) {
1262
+ arrayIterator = [].keys();
1263
+ // Safari 8 has buggy iterators w/o `next`
1264
+ if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS$1 = true;
1265
+ else {
1266
+ PrototypeOfArrayIteratorPrototype = getPrototypeOf$1(getPrototypeOf$1(arrayIterator));
1267
+ if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype$2 = PrototypeOfArrayIteratorPrototype;
1268
+ }
1269
+ }
1270
+
1271
+ var NEW_ITERATOR_PROTOTYPE = IteratorPrototype$2 == undefined || fails(function () {
1272
+ var test = {};
1273
+ // FF44- legacy iterators case
1274
+ return IteratorPrototype$2[ITERATOR$2].call(test) !== test;
1275
+ });
1276
+
1277
+ if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype$2 = {};
1278
+
1279
+ // `%IteratorPrototype%[@@iterator]()` method
1280
+ // https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
1281
+ if (!isCallable$2(IteratorPrototype$2[ITERATOR$2])) {
1282
+ defineBuiltIn$1(IteratorPrototype$2, ITERATOR$2, function () {
1283
+ return this;
1284
+ });
1285
+ }
1286
+
1287
+ var iteratorsCore = {
1288
+ IteratorPrototype: IteratorPrototype$2,
1289
+ BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS$1
1290
+ };
1291
+
1292
+ var defineProperty$1 = objectDefineProperty.f;
1293
+ var hasOwn = hasOwnProperty_1;
1294
+ var wellKnownSymbol$2 = wellKnownSymbol$6;
1295
+
1296
+ var TO_STRING_TAG$1 = wellKnownSymbol$2('toStringTag');
1297
+
1298
+ var setToStringTag$2 = function (target, TAG, STATIC) {
1299
+ if (target && !STATIC) target = target.prototype;
1300
+ if (target && !hasOwn(target, TO_STRING_TAG$1)) {
1301
+ defineProperty$1(target, TO_STRING_TAG$1, { configurable: true, value: TAG });
1302
+ }
1303
+ };
1304
+
1305
+ var IteratorPrototype$1 = iteratorsCore.IteratorPrototype;
1306
+ var create = objectCreate;
1307
+ var createPropertyDescriptor = createPropertyDescriptor$3;
1308
+ var setToStringTag$1 = setToStringTag$2;
1309
+ var Iterators$2 = iterators;
1310
+
1311
+ var returnThis$1 = function () { return this; };
1312
+
1313
+ var createIteratorConstructor$1 = function (IteratorConstructor, NAME, next, ENUMERABLE_NEXT) {
1314
+ var TO_STRING_TAG = NAME + ' Iterator';
1315
+ IteratorConstructor.prototype = create(IteratorPrototype$1, { next: createPropertyDescriptor(+!ENUMERABLE_NEXT, next) });
1316
+ setToStringTag$1(IteratorConstructor, TO_STRING_TAG, false);
1317
+ Iterators$2[TO_STRING_TAG] = returnThis$1;
1318
+ return IteratorConstructor;
1319
+ };
1320
+
1321
+ var isCallable$1 = isCallable$e;
1322
+
1323
+ var $String = String;
1324
+ var $TypeError = TypeError;
1325
+
1326
+ var aPossiblePrototype$1 = function (argument) {
1327
+ if (typeof argument == 'object' || isCallable$1(argument)) return argument;
1328
+ throw $TypeError("Can't set " + $String(argument) + ' as a prototype');
1329
+ };
1330
+
1331
+ /* eslint-disable no-proto -- safe */
1332
+
1333
+ var uncurryThis = functionUncurryThis;
1334
+ var anObject = anObject$5;
1335
+ var aPossiblePrototype = aPossiblePrototype$1;
1336
+
1337
+ // `Object.setPrototypeOf` method
1338
+ // https://tc39.es/ecma262/#sec-object.setprototypeof
1339
+ // Works with __proto__ only. Old v8 can't work with null proto objects.
1340
+ // eslint-disable-next-line es-x/no-object-setprototypeof -- safe
1341
+ var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () {
1342
+ var CORRECT_SETTER = false;
1343
+ var test = {};
1344
+ var setter;
1345
+ try {
1346
+ // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
1347
+ setter = uncurryThis(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set);
1348
+ setter(test, []);
1349
+ CORRECT_SETTER = test instanceof Array;
1350
+ } catch (error) { /* empty */ }
1351
+ return function setPrototypeOf(O, proto) {
1352
+ anObject(O);
1353
+ aPossiblePrototype(proto);
1354
+ if (CORRECT_SETTER) setter(O, proto);
1355
+ else O.__proto__ = proto;
1356
+ return O;
1357
+ };
1358
+ }() : undefined);
1359
+
1360
+ var $$1 = _export;
1361
+ var call = functionCall;
1362
+ var FunctionName = functionName;
1363
+ var isCallable = isCallable$e;
1364
+ var createIteratorConstructor = createIteratorConstructor$1;
1365
+ var getPrototypeOf = objectGetPrototypeOf;
1366
+ var setPrototypeOf = objectSetPrototypeOf;
1367
+ var setToStringTag = setToStringTag$2;
1368
+ var createNonEnumerableProperty$1 = createNonEnumerableProperty$5;
1369
+ var defineBuiltIn = defineBuiltIn$3;
1370
+ var wellKnownSymbol$1 = wellKnownSymbol$6;
1371
+ var Iterators$1 = iterators;
1372
+ var IteratorsCore = iteratorsCore;
1373
+
1374
+ var PROPER_FUNCTION_NAME = FunctionName.PROPER;
1375
+ var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
1376
+ var IteratorPrototype = IteratorsCore.IteratorPrototype;
1377
+ var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
1378
+ var ITERATOR$1 = wellKnownSymbol$1('iterator');
1379
+ var KEYS = 'keys';
1380
+ var VALUES = 'values';
1381
+ var ENTRIES = 'entries';
1382
+
1383
+ var returnThis = function () { return this; };
1384
+
1385
+ var defineIterator$1 = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
1386
+ createIteratorConstructor(IteratorConstructor, NAME, next);
1387
+
1388
+ var getIterationMethod = function (KIND) {
1389
+ if (KIND === DEFAULT && defaultIterator) return defaultIterator;
1390
+ if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype) return IterablePrototype[KIND];
1391
+ switch (KIND) {
1392
+ case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
1393
+ case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
1394
+ case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
1395
+ } return function () { return new IteratorConstructor(this); };
1396
+ };
1397
+
1398
+ var TO_STRING_TAG = NAME + ' Iterator';
1399
+ var INCORRECT_VALUES_NAME = false;
1400
+ var IterablePrototype = Iterable.prototype;
1401
+ var nativeIterator = IterablePrototype[ITERATOR$1]
1402
+ || IterablePrototype['@@iterator']
1403
+ || DEFAULT && IterablePrototype[DEFAULT];
1404
+ var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT);
1405
+ var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
1406
+ var CurrentIteratorPrototype, methods, KEY;
1407
+
1408
+ // fix native
1409
+ if (anyNativeIterator) {
1410
+ CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable()));
1411
+ if (CurrentIteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
1412
+ if (getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) {
1413
+ if (setPrototypeOf) {
1414
+ setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype);
1415
+ } else if (!isCallable(CurrentIteratorPrototype[ITERATOR$1])) {
1416
+ defineBuiltIn(CurrentIteratorPrototype, ITERATOR$1, returnThis);
1417
+ }
1418
+ }
1419
+ // Set @@toStringTag to native iterators
1420
+ setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true);
1421
+ }
1422
+ }
1423
+
1424
+ // fix Array.prototype.{ values, @@iterator }.name in V8 / FF
1425
+ if (PROPER_FUNCTION_NAME && DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
1426
+ if (CONFIGURABLE_FUNCTION_NAME) {
1427
+ createNonEnumerableProperty$1(IterablePrototype, 'name', VALUES);
1428
+ } else {
1429
+ INCORRECT_VALUES_NAME = true;
1430
+ defaultIterator = function values() { return call(nativeIterator, this); };
1431
+ }
1432
+ }
1433
+
1434
+ // export additional methods
1435
+ if (DEFAULT) {
1436
+ methods = {
1437
+ values: getIterationMethod(VALUES),
1438
+ keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
1439
+ entries: getIterationMethod(ENTRIES)
1440
+ };
1441
+ if (FORCED) for (KEY in methods) {
1442
+ if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
1443
+ defineBuiltIn(IterablePrototype, KEY, methods[KEY]);
1444
+ }
1445
+ } else $$1({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
1446
+ }
1447
+
1448
+ // define iterator
1449
+ if (IterablePrototype[ITERATOR$1] !== defaultIterator) {
1450
+ defineBuiltIn(IterablePrototype, ITERATOR$1, defaultIterator, { name: DEFAULT });
1451
+ }
1452
+ Iterators$1[NAME] = defaultIterator;
1453
+
1454
+ return methods;
1455
+ };
1456
+
1457
+ var toIndexedObject = toIndexedObject$5;
1458
+ var addToUnscopables = addToUnscopables$1;
1459
+ var Iterators = iterators;
1460
+ var InternalStateModule = internalState;
1461
+ var defineProperty = objectDefineProperty.f;
1462
+ var defineIterator = defineIterator$1;
1463
+ var DESCRIPTORS = descriptors;
1464
+
1465
+ var ARRAY_ITERATOR = 'Array Iterator';
1466
+ var setInternalState = InternalStateModule.set;
1467
+ var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR);
1468
+
1469
+ // `Array.prototype.entries` method
1470
+ // https://tc39.es/ecma262/#sec-array.prototype.entries
1471
+ // `Array.prototype.keys` method
1472
+ // https://tc39.es/ecma262/#sec-array.prototype.keys
1473
+ // `Array.prototype.values` method
1474
+ // https://tc39.es/ecma262/#sec-array.prototype.values
1475
+ // `Array.prototype[@@iterator]` method
1476
+ // https://tc39.es/ecma262/#sec-array.prototype-@@iterator
1477
+ // `CreateArrayIterator` internal method
1478
+ // https://tc39.es/ecma262/#sec-createarrayiterator
1479
+ var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind) {
1480
+ setInternalState(this, {
1481
+ type: ARRAY_ITERATOR,
1482
+ target: toIndexedObject(iterated), // target
1483
+ index: 0, // next index
1484
+ kind: kind // kind
1485
+ });
1486
+ // `%ArrayIteratorPrototype%.next` method
1487
+ // https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
1488
+ }, function () {
1489
+ var state = getInternalState(this);
1490
+ var target = state.target;
1491
+ var kind = state.kind;
1492
+ var index = state.index++;
1493
+ if (!target || index >= target.length) {
1494
+ state.target = undefined;
1495
+ return { value: undefined, done: true };
1496
+ }
1497
+ if (kind == 'keys') return { value: index, done: false };
1498
+ if (kind == 'values') return { value: target[index], done: false };
1499
+ return { value: [index, target[index]], done: false };
1500
+ }, 'values');
1501
+
1502
+ // argumentsList[@@iterator] is %ArrayProto_values%
1503
+ // https://tc39.es/ecma262/#sec-createunmappedargumentsobject
1504
+ // https://tc39.es/ecma262/#sec-createmappedargumentsobject
1505
+ var values = Iterators.Arguments = Iterators.Array;
1506
+
1507
+ // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
1508
+ addToUnscopables('keys');
1509
+ addToUnscopables('values');
1510
+ addToUnscopables('entries');
1511
+
1512
+ // V8 ~ Chrome 45- bug
1513
+ if (DESCRIPTORS && values.name !== 'values') try {
1514
+ defineProperty(values, 'name', { value: 'values' });
1515
+ } catch (error) { /* empty */ }
1516
+
1517
+ // iterable DOM collections
1518
+ // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
1519
+ var domIterables = {
1520
+ CSSRuleList: 0,
1521
+ CSSStyleDeclaration: 0,
1522
+ CSSValueList: 0,
1523
+ ClientRectList: 0,
1524
+ DOMRectList: 0,
1525
+ DOMStringList: 0,
1526
+ DOMTokenList: 1,
1527
+ DataTransferItemList: 0,
1528
+ FileList: 0,
1529
+ HTMLAllCollection: 0,
1530
+ HTMLCollection: 0,
1531
+ HTMLFormElement: 0,
1532
+ HTMLSelectElement: 0,
1533
+ MediaList: 0,
1534
+ MimeTypeArray: 0,
1535
+ NamedNodeMap: 0,
1536
+ NodeList: 1,
1537
+ PaintRequestList: 0,
1538
+ Plugin: 0,
1539
+ PluginArray: 0,
1540
+ SVGLengthList: 0,
1541
+ SVGNumberList: 0,
1542
+ SVGPathSegList: 0,
1543
+ SVGPointList: 0,
1544
+ SVGStringList: 0,
1545
+ SVGTransformList: 0,
1546
+ SourceBufferList: 0,
1547
+ StyleSheetList: 0,
1548
+ TextTrackCueList: 0,
1549
+ TextTrackList: 0,
1550
+ TouchList: 0
1551
+ };
1552
+
1553
+ // in old WebKit versions, `element.classList` is not an instance of global `DOMTokenList`
1554
+ var documentCreateElement = documentCreateElement$2;
1555
+
1556
+ var classList = documentCreateElement('span').classList;
1557
+ var DOMTokenListPrototype$1 = classList && classList.constructor && classList.constructor.prototype;
1558
+
1559
+ var domTokenListPrototype = DOMTokenListPrototype$1 === Object.prototype ? undefined : DOMTokenListPrototype$1;
1560
+
1561
+ var global$2 = global$c;
1562
+ var DOMIterables = domIterables;
1563
+ var DOMTokenListPrototype = domTokenListPrototype;
1564
+ var ArrayIteratorMethods = es_array_iterator;
1565
+ var createNonEnumerableProperty = createNonEnumerableProperty$5;
1566
+ var wellKnownSymbol = wellKnownSymbol$6;
1567
+
1568
+ var ITERATOR = wellKnownSymbol('iterator');
1569
+ var TO_STRING_TAG = wellKnownSymbol('toStringTag');
1570
+ var ArrayValues = ArrayIteratorMethods.values;
1571
+
1572
+ var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
1573
+ if (CollectionPrototype) {
1574
+ // some Chrome versions have non-configurable methods on DOMTokenList
1575
+ if (CollectionPrototype[ITERATOR] !== ArrayValues) try {
1576
+ createNonEnumerableProperty(CollectionPrototype, ITERATOR, ArrayValues);
1577
+ } catch (error) {
1578
+ CollectionPrototype[ITERATOR] = ArrayValues;
1579
+ }
1580
+ if (!CollectionPrototype[TO_STRING_TAG]) {
1581
+ createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME);
1582
+ }
1583
+ if (DOMIterables[COLLECTION_NAME]) for (var METHOD_NAME in ArrayIteratorMethods) {
1584
+ // some Chrome versions have non-configurable methods on DOMTokenList
1585
+ if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) try {
1586
+ createNonEnumerableProperty(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME]);
1587
+ } catch (error) {
1588
+ CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME];
1589
+ }
1590
+ }
1591
+ }
1592
+ };
1593
+
1594
+ for (var COLLECTION_NAME in DOMIterables) {
1595
+ handlePrototype(global$2[COLLECTION_NAME] && global$2[COLLECTION_NAME].prototype, COLLECTION_NAME);
1596
+ }
1597
+
1598
+ handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
1599
+
1600
+ var $ = _export;
1601
+ var global$1 = global$c;
1602
+
1603
+ // `globalThis` object
1604
+ // https://tc39.es/ecma262/#sec-globalthis
1605
+ $({ global: true }, {
1606
+ globalThis: global$1
1607
+ });
1608
+
1609
+ /**
1610
+ * Get the type of a JSON value.
1611
+ * Distinguishes between array, null and object.
1612
+ */
1613
+ function typeofJsonValue(value) {
1614
+ let t = typeof value;
1615
+ if (t == "object") {
1616
+ if (Array.isArray(value))
1617
+ return "array";
1618
+ if (value === null)
1619
+ return "null";
1620
+ }
1621
+ return t;
1622
+ }
1623
+ /**
1624
+ * Is this a JSON object (instead of an array or null)?
1625
+ */
1626
+ function isJsonObject(value) {
1627
+ return value !== null && typeof value == "object" && !Array.isArray(value);
1628
+ }
1629
+
1630
+ // lookup table from base64 character to byte
1631
+ let encTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
1632
+ // lookup table from base64 character *code* to byte because lookup by number is fast
1633
+ let decTable = [];
1634
+ for (let i = 0; i < encTable.length; i++)
1635
+ decTable[encTable[i].charCodeAt(0)] = i;
1636
+ // support base64url variants
1637
+ decTable["-".charCodeAt(0)] = encTable.indexOf("+");
1638
+ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
1639
+ /**
1640
+ * Decodes a base64 string to a byte array.
1641
+ *
1642
+ * - ignores white-space, including line breaks and tabs
1643
+ * - allows inner padding (can decode concatenated base64 strings)
1644
+ * - does not require padding
1645
+ * - understands base64url encoding:
1646
+ * "-" instead of "+",
1647
+ * "_" instead of "/",
1648
+ * no padding
1649
+ */
1650
+ function base64decode(base64Str) {
1651
+ // estimate byte size, not accounting for inner padding and whitespace
1652
+ let es = base64Str.length * 3 / 4;
1653
+ // if (es % 3 !== 0)
1654
+ // throw new Error('invalid base64 string');
1655
+ if (base64Str[base64Str.length - 2] == '=')
1656
+ es -= 2;
1657
+ else if (base64Str[base64Str.length - 1] == '=')
1658
+ es -= 1;
1659
+ let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
1660
+ groupPos = 0, // position in base64 group
1661
+ b, // current byte
1662
+ p = 0 // previous byte
1663
+ ;
1664
+ for (let i = 0; i < base64Str.length; i++) {
1665
+ b = decTable[base64Str.charCodeAt(i)];
1666
+ if (b === undefined) {
1667
+ // noinspection FallThroughInSwitchStatementJS
1668
+ switch (base64Str[i]) {
1669
+ case '=':
1670
+ groupPos = 0; // reset state when padding found
1671
+ case '\n':
1672
+ case '\r':
1673
+ case '\t':
1674
+ case ' ':
1675
+ continue; // skip white-space, and padding
1676
+ default:
1677
+ throw Error(`invalid base64 string.`);
1678
+ }
1679
+ }
1680
+ switch (groupPos) {
1681
+ case 0:
1682
+ p = b;
1683
+ groupPos = 1;
1684
+ break;
1685
+ case 1:
1686
+ bytes[bytePos++] = p << 2 | (b & 48) >> 4;
1687
+ p = b;
1688
+ groupPos = 2;
1689
+ break;
1690
+ case 2:
1691
+ bytes[bytePos++] = (p & 15) << 4 | (b & 60) >> 2;
1692
+ p = b;
1693
+ groupPos = 3;
1694
+ break;
1695
+ case 3:
1696
+ bytes[bytePos++] = (p & 3) << 6 | b;
1697
+ groupPos = 0;
1698
+ break;
1699
+ }
1700
+ }
1701
+ if (groupPos == 1)
1702
+ throw Error(`invalid base64 string.`);
1703
+ return bytes.subarray(0, bytePos);
1704
+ }
1705
+ /**
1706
+ * Encodes a byte array to a base64 string.
1707
+ * Adds padding at the end.
1708
+ * Does not insert newlines.
1709
+ */
1710
+ function base64encode(bytes) {
1711
+ let base64 = '', groupPos = 0, // position in base64 group
1712
+ b, // current byte
1713
+ p = 0; // carry over from previous byte
1714
+ for (let i = 0; i < bytes.length; i++) {
1715
+ b = bytes[i];
1716
+ switch (groupPos) {
1717
+ case 0:
1718
+ base64 += encTable[b >> 2];
1719
+ p = (b & 3) << 4;
1720
+ groupPos = 1;
1721
+ break;
1722
+ case 1:
1723
+ base64 += encTable[p | b >> 4];
1724
+ p = (b & 15) << 2;
1725
+ groupPos = 2;
1726
+ break;
1727
+ case 2:
1728
+ base64 += encTable[p | b >> 6];
1729
+ base64 += encTable[b & 63];
1730
+ groupPos = 0;
1731
+ break;
1732
+ }
1733
+ }
1734
+ // padding required?
1735
+ if (groupPos) {
1736
+ base64 += encTable[p];
1737
+ base64 += '=';
1738
+ if (groupPos == 1)
1739
+ base64 += '=';
1740
+ }
1741
+ return base64;
1742
+ }
1743
+
1744
+ /**
1745
+ * This handler implements the default behaviour for unknown fields.
1746
+ * When reading data, unknown fields are stored on the message, in a
1747
+ * symbol property.
1748
+ * When writing data, the symbol property is queried and unknown fields
1749
+ * are serialized into the output again.
1750
+ */
1751
+ var UnknownFieldHandler;
1752
+ (function (UnknownFieldHandler) {
1753
+ /**
1754
+ * The symbol used to store unknown fields for a message.
1755
+ * The property must conform to `UnknownFieldContainer`.
1756
+ */
1757
+ UnknownFieldHandler.symbol = Symbol.for("protobuf-ts/unknown");
1758
+ /**
1759
+ * Store an unknown field during binary read directly on the message.
1760
+ * This method is compatible with `BinaryReadOptions.readUnknownField`.
1761
+ */
1762
+ UnknownFieldHandler.onRead = (typeName, message, fieldNo, wireType, data) => {
1763
+ let container = is(message) ? message[UnknownFieldHandler.symbol] : message[UnknownFieldHandler.symbol] = [];
1764
+ container.push({ no: fieldNo, wireType, data });
1765
+ };
1766
+ /**
1767
+ * Write unknown fields stored for the message to the writer.
1768
+ * This method is compatible with `BinaryWriteOptions.writeUnknownFields`.
1769
+ */
1770
+ UnknownFieldHandler.onWrite = (typeName, message, writer) => {
1771
+ for (let { no, wireType, data } of UnknownFieldHandler.list(message))
1772
+ writer.tag(no, wireType).raw(data);
1773
+ };
1774
+ /**
1775
+ * List unknown fields stored for the message.
1776
+ * Note that there may be multiples fields with the same number.
1777
+ */
1778
+ UnknownFieldHandler.list = (message, fieldNo) => {
1779
+ if (is(message)) {
1780
+ let all = message[UnknownFieldHandler.symbol];
1781
+ return fieldNo ? all.filter(uf => uf.no == fieldNo) : all;
1782
+ }
1783
+ return [];
1784
+ };
1785
+ /**
1786
+ * Returns the last unknown field by field number.
1787
+ */
1788
+ UnknownFieldHandler.last = (message, fieldNo) => UnknownFieldHandler.list(message, fieldNo).slice(-1)[0];
1789
+ const is = (message) => message && Array.isArray(message[UnknownFieldHandler.symbol]);
1790
+ })(UnknownFieldHandler || (UnknownFieldHandler = {}));
1791
+ /**
1792
+ * Protobuf binary format wire types.
1793
+ *
1794
+ * A wire type provides just enough information to find the length of the
1795
+ * following value.
1796
+ *
1797
+ * See https://developers.google.com/protocol-buffers/docs/encoding#structure
1798
+ */
1799
+ var WireType;
1800
+ (function (WireType) {
1801
+ /**
1802
+ * Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
1803
+ */
1804
+ WireType[WireType["Varint"] = 0] = "Varint";
1805
+ /**
1806
+ * Used for fixed64, sfixed64, double.
1807
+ * Always 8 bytes with little-endian byte order.
1808
+ */
1809
+ WireType[WireType["Bit64"] = 1] = "Bit64";
1810
+ /**
1811
+ * Used for string, bytes, embedded messages, packed repeated fields
1812
+ *
1813
+ * Only repeated numeric types (types which use the varint, 32-bit,
1814
+ * or 64-bit wire types) can be packed. In proto3, such fields are
1815
+ * packed by default.
1816
+ */
1817
+ WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
1818
+ /**
1819
+ * Used for groups
1820
+ * @deprecated
1821
+ */
1822
+ WireType[WireType["StartGroup"] = 3] = "StartGroup";
1823
+ /**
1824
+ * Used for groups
1825
+ * @deprecated
1826
+ */
1827
+ WireType[WireType["EndGroup"] = 4] = "EndGroup";
1828
+ /**
1829
+ * Used for fixed32, sfixed32, float.
1830
+ * Always 4 bytes with little-endian byte order.
1831
+ */
1832
+ WireType[WireType["Bit32"] = 5] = "Bit32";
1833
+ })(WireType || (WireType = {}));
1834
+
1835
+ // Copyright 2008 Google Inc. All rights reserved.
1836
+ //
1837
+ // Redistribution and use in source and binary forms, with or without
1838
+ // modification, are permitted provided that the following conditions are
1839
+ // met:
1840
+ //
1841
+ // * Redistributions of source code must retain the above copyright
1842
+ // notice, this list of conditions and the following disclaimer.
1843
+ // * Redistributions in binary form must reproduce the above
1844
+ // copyright notice, this list of conditions and the following disclaimer
1845
+ // in the documentation and/or other materials provided with the
1846
+ // distribution.
1847
+ // * Neither the name of Google Inc. nor the names of its
1848
+ // contributors may be used to endorse or promote products derived from
1849
+ // this software without specific prior written permission.
1850
+ //
1851
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1852
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1853
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1854
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1855
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1856
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1857
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1858
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1859
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1860
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1861
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1862
+ //
1863
+ // Code generated by the Protocol Buffer compiler is owned by the owner
1864
+ // of the input file used when generating it. This code is not
1865
+ // standalone and requires a support library to be linked with it. This
1866
+ // support library is itself covered by the above license.
1867
+ /**
1868
+ * Read a 64 bit varint as two JS numbers.
1869
+ *
1870
+ * Returns tuple:
1871
+ * [0]: low bits
1872
+ * [0]: high bits
1873
+ *
1874
+ * Copyright 2008 Google Inc. All rights reserved.
1875
+ *
1876
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
1877
+ */
1878
+ function varint64read() {
1879
+ let lowBits = 0;
1880
+ let highBits = 0;
1881
+ for (let shift = 0; shift < 28; shift += 7) {
1882
+ let b = this.buf[this.pos++];
1883
+ lowBits |= (b & 0x7F) << shift;
1884
+ if ((b & 0x80) == 0) {
1885
+ this.assertBounds();
1886
+ return [lowBits, highBits];
1887
+ }
1888
+ }
1889
+ let middleByte = this.buf[this.pos++];
1890
+ // last four bits of the first 32 bit number
1891
+ lowBits |= (middleByte & 0x0F) << 28;
1892
+ // 3 upper bits are part of the next 32 bit number
1893
+ highBits = (middleByte & 0x70) >> 4;
1894
+ if ((middleByte & 0x80) == 0) {
1895
+ this.assertBounds();
1896
+ return [lowBits, highBits];
1897
+ }
1898
+ for (let shift = 3; shift <= 31; shift += 7) {
1899
+ let b = this.buf[this.pos++];
1900
+ highBits |= (b & 0x7F) << shift;
1901
+ if ((b & 0x80) == 0) {
1902
+ this.assertBounds();
1903
+ return [lowBits, highBits];
1904
+ }
1905
+ }
1906
+ throw new Error('invalid varint');
1907
+ }
1908
+ /**
1909
+ * Write a 64 bit varint, given as two JS numbers, to the given bytes array.
1910
+ *
1911
+ * Copyright 2008 Google Inc. All rights reserved.
1912
+ *
1913
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
1914
+ */
1915
+ function varint64write(lo, hi, bytes) {
1916
+ for (let i = 0; i < 28; i = i + 7) {
1917
+ const shift = lo >>> i;
1918
+ const hasNext = !((shift >>> 7) == 0 && hi == 0);
1919
+ const byte = (hasNext ? shift | 0x80 : shift) & 0xFF;
1920
+ bytes.push(byte);
1921
+ if (!hasNext) {
1922
+ return;
1923
+ }
1924
+ }
1925
+ const splitBits = ((lo >>> 28) & 0x0F) | ((hi & 0x07) << 4);
1926
+ const hasMoreBits = !((hi >> 3) == 0);
1927
+ bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xFF);
1928
+ if (!hasMoreBits) {
1929
+ return;
1930
+ }
1931
+ for (let i = 3; i < 31; i = i + 7) {
1932
+ const shift = hi >>> i;
1933
+ const hasNext = !((shift >>> 7) == 0);
1934
+ const byte = (hasNext ? shift | 0x80 : shift) & 0xFF;
1935
+ bytes.push(byte);
1936
+ if (!hasNext) {
1937
+ return;
1938
+ }
1939
+ }
1940
+ bytes.push((hi >>> 31) & 0x01);
1941
+ }
1942
+ // constants for binary math
1943
+ const TWO_PWR_32_DBL$1 = (1 << 16) * (1 << 16);
1944
+ /**
1945
+ * Parse decimal string of 64 bit integer value as two JS numbers.
1946
+ *
1947
+ * Returns tuple:
1948
+ * [0]: minus sign?
1949
+ * [1]: low bits
1950
+ * [2]: high bits
1951
+ *
1952
+ * Copyright 2008 Google Inc.
1953
+ */
1954
+ function int64fromString(dec) {
1955
+ // Check for minus sign.
1956
+ let minus = dec[0] == '-';
1957
+ if (minus)
1958
+ dec = dec.slice(1);
1959
+ // Work 6 decimal digits at a time, acting like we're converting base 1e6
1960
+ // digits to binary. This is safe to do with floating point math because
1961
+ // Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
1962
+ const base = 1e6;
1963
+ let lowBits = 0;
1964
+ let highBits = 0;
1965
+ function add1e6digit(begin, end) {
1966
+ // Note: Number('') is 0.
1967
+ const digit1e6 = Number(dec.slice(begin, end));
1968
+ highBits *= base;
1969
+ lowBits = lowBits * base + digit1e6;
1970
+ // Carry bits from lowBits to
1971
+ if (lowBits >= TWO_PWR_32_DBL$1) {
1972
+ highBits = highBits + ((lowBits / TWO_PWR_32_DBL$1) | 0);
1973
+ lowBits = lowBits % TWO_PWR_32_DBL$1;
1974
+ }
1975
+ }
1976
+ add1e6digit(-24, -18);
1977
+ add1e6digit(-18, -12);
1978
+ add1e6digit(-12, -6);
1979
+ add1e6digit(-6);
1980
+ return [minus, lowBits, highBits];
1981
+ }
1982
+ /**
1983
+ * Format 64 bit integer value (as two JS numbers) to decimal string.
1984
+ *
1985
+ * Copyright 2008 Google Inc.
1986
+ */
1987
+ function int64toString(bitsLow, bitsHigh) {
1988
+ // Skip the expensive conversion if the number is small enough to use the
1989
+ // built-in conversions.
1990
+ if (bitsHigh <= 0x1FFFFF) {
1991
+ return '' + (TWO_PWR_32_DBL$1 * bitsHigh + bitsLow);
1992
+ }
1993
+ // What this code is doing is essentially converting the input number from
1994
+ // base-2 to base-1e7, which allows us to represent the 64-bit range with
1995
+ // only 3 (very large) digits. Those digits are then trivial to convert to
1996
+ // a base-10 string.
1997
+ // The magic numbers used here are -
1998
+ // 2^24 = 16777216 = (1,6777216) in base-1e7.
1999
+ // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
2000
+ // Split 32:32 representation into 16:24:24 representation so our
2001
+ // intermediate digits don't overflow.
2002
+ let low = bitsLow & 0xFFFFFF;
2003
+ let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xFFFFFF;
2004
+ let high = (bitsHigh >> 16) & 0xFFFF;
2005
+ // Assemble our three base-1e7 digits, ignoring carries. The maximum
2006
+ // value in a digit at this step is representable as a 48-bit integer, which
2007
+ // can be stored in a 64-bit floating point number.
2008
+ let digitA = low + (mid * 6777216) + (high * 6710656);
2009
+ let digitB = mid + (high * 8147497);
2010
+ let digitC = (high * 2);
2011
+ // Apply carries from A to B and from B to C.
2012
+ let base = 10000000;
2013
+ if (digitA >= base) {
2014
+ digitB += Math.floor(digitA / base);
2015
+ digitA %= base;
2016
+ }
2017
+ if (digitB >= base) {
2018
+ digitC += Math.floor(digitB / base);
2019
+ digitB %= base;
2020
+ }
2021
+ // Convert base-1e7 digits to base-10, with optional leading zeroes.
2022
+ function decimalFrom1e7(digit1e7, needLeadingZeros) {
2023
+ let partial = digit1e7 ? String(digit1e7) : '';
2024
+ if (needLeadingZeros) {
2025
+ return '0000000'.slice(partial.length) + partial;
2026
+ }
2027
+ return partial;
2028
+ }
2029
+ return decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
2030
+ decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
2031
+ // If the final 1e7 digit didn't need leading zeros, we would have
2032
+ // returned via the trivial code path at the top.
2033
+ decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1);
2034
+ }
2035
+ /**
2036
+ * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
2037
+ *
2038
+ * Copyright 2008 Google Inc. All rights reserved.
2039
+ *
2040
+ * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
2041
+ */
2042
+ function varint32write(value, bytes) {
2043
+ if (value >= 0) {
2044
+ // write value as varint 32
2045
+ while (value > 0x7f) {
2046
+ bytes.push((value & 0x7f) | 0x80);
2047
+ value = value >>> 7;
2048
+ }
2049
+ bytes.push(value);
2050
+ }
2051
+ else {
2052
+ for (let i = 0; i < 9; i++) {
2053
+ bytes.push(value & 127 | 128);
2054
+ value = value >> 7;
2055
+ }
2056
+ bytes.push(1);
2057
+ }
2058
+ }
2059
+ /**
2060
+ * Read an unsigned 32 bit varint.
2061
+ *
2062
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
2063
+ */
2064
+ function varint32read() {
2065
+ let b = this.buf[this.pos++];
2066
+ let result = b & 0x7F;
2067
+ if ((b & 0x80) == 0) {
2068
+ this.assertBounds();
2069
+ return result;
2070
+ }
2071
+ b = this.buf[this.pos++];
2072
+ result |= (b & 0x7F) << 7;
2073
+ if ((b & 0x80) == 0) {
2074
+ this.assertBounds();
2075
+ return result;
2076
+ }
2077
+ b = this.buf[this.pos++];
2078
+ result |= (b & 0x7F) << 14;
2079
+ if ((b & 0x80) == 0) {
2080
+ this.assertBounds();
2081
+ return result;
2082
+ }
2083
+ b = this.buf[this.pos++];
2084
+ result |= (b & 0x7F) << 21;
2085
+ if ((b & 0x80) == 0) {
2086
+ this.assertBounds();
2087
+ return result;
2088
+ }
2089
+ // Extract only last 4 bits
2090
+ b = this.buf[this.pos++];
2091
+ result |= (b & 0x0F) << 28;
2092
+ for (let readBytes = 5; ((b & 0x80) !== 0) && readBytes < 10; readBytes++)
2093
+ b = this.buf[this.pos++];
2094
+ if ((b & 0x80) != 0)
2095
+ throw new Error('invalid varint');
2096
+ this.assertBounds();
2097
+ // Result can have 32 bits, convert it to unsigned
2098
+ return result >>> 0;
2099
+ }
2100
+
2101
+ function detectBi() {
2102
+ const dv = new DataView(new ArrayBuffer(8));
2103
+ const ok = globalThis.BigInt !== undefined
2104
+ && typeof dv.getBigInt64 === "function"
2105
+ && typeof dv.getBigUint64 === "function"
2106
+ && typeof dv.setBigInt64 === "function"
2107
+ && typeof dv.setBigUint64 === "function";
2108
+ return ok ? {
2109
+ MIN: BigInt("-9223372036854775808"),
2110
+ MAX: BigInt("9223372036854775807"),
2111
+ UMIN: BigInt("0"),
2112
+ UMAX: BigInt("18446744073709551615"),
2113
+ C: BigInt,
2114
+ V: dv,
2115
+ } : undefined;
2116
+ }
2117
+ const BI = detectBi();
2118
+ function assertBi(bi) {
2119
+ if (!bi)
2120
+ throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support");
2121
+ }
2122
+ // used to validate from(string) input (when bigint is unavailable)
2123
+ const RE_DECIMAL_STR = /^-?[0-9]+$/;
2124
+ // constants for binary math
2125
+ const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
2126
+ // base class for PbLong and PbULong provides shared code
2127
+ class SharedPbLong {
2128
+ /**
2129
+ * Create a new instance with the given bits.
2130
+ */
2131
+ constructor(lo, hi) {
2132
+ this.lo = lo | 0;
2133
+ this.hi = hi | 0;
2134
+ }
2135
+ /**
2136
+ * Is this instance equal to 0?
2137
+ */
2138
+ isZero() {
2139
+ return this.lo == 0 && this.hi == 0;
2140
+ }
2141
+ /**
2142
+ * Convert to a native number.
2143
+ */
2144
+ toNumber() {
2145
+ let result = this.hi * TWO_PWR_32_DBL + (this.lo >>> 0);
2146
+ if (!Number.isSafeInteger(result))
2147
+ throw new Error("cannot convert to safe number");
2148
+ return result;
2149
+ }
2150
+ }
2151
+ /**
2152
+ * 64-bit unsigned integer as two 32-bit values.
2153
+ * Converts between `string`, `number` and `bigint` representations.
2154
+ */
2155
+ class PbULong extends SharedPbLong {
2156
+ /**
2157
+ * Create instance from a `string`, `number` or `bigint`.
2158
+ */
2159
+ static from(value) {
2160
+ if (BI)
2161
+ // noinspection FallThroughInSwitchStatementJS
2162
+ switch (typeof value) {
2163
+ case "string":
2164
+ if (value == "0")
2165
+ return this.ZERO;
2166
+ if (value == "")
2167
+ throw new Error('string is no integer');
2168
+ value = BI.C(value);
2169
+ case "number":
2170
+ if (value === 0)
2171
+ return this.ZERO;
2172
+ value = BI.C(value);
2173
+ case "bigint":
2174
+ if (!value)
2175
+ return this.ZERO;
2176
+ if (value < BI.UMIN)
2177
+ throw new Error('signed value for ulong');
2178
+ if (value > BI.UMAX)
2179
+ throw new Error('ulong too large');
2180
+ BI.V.setBigUint64(0, value, true);
2181
+ return new PbULong(BI.V.getInt32(0, true), BI.V.getInt32(4, true));
2182
+ }
2183
+ else
2184
+ switch (typeof value) {
2185
+ case "string":
2186
+ if (value == "0")
2187
+ return this.ZERO;
2188
+ value = value.trim();
2189
+ if (!RE_DECIMAL_STR.test(value))
2190
+ throw new Error('string is no integer');
2191
+ let [minus, lo, hi] = int64fromString(value);
2192
+ if (minus)
2193
+ throw new Error('signed value');
2194
+ return new PbULong(lo, hi);
2195
+ case "number":
2196
+ if (value == 0)
2197
+ return this.ZERO;
2198
+ if (!Number.isSafeInteger(value))
2199
+ throw new Error('number is no integer');
2200
+ if (value < 0)
2201
+ throw new Error('signed value for ulong');
2202
+ return new PbULong(value, value / TWO_PWR_32_DBL);
2203
+ }
2204
+ throw new Error('unknown value ' + typeof value);
2205
+ }
2206
+ /**
2207
+ * Convert to decimal string.
2208
+ */
2209
+ toString() {
2210
+ return BI ? this.toBigInt().toString() : int64toString(this.lo, this.hi);
2211
+ }
2212
+ /**
2213
+ * Convert to native bigint.
2214
+ */
2215
+ toBigInt() {
2216
+ assertBi(BI);
2217
+ BI.V.setInt32(0, this.lo, true);
2218
+ BI.V.setInt32(4, this.hi, true);
2219
+ return BI.V.getBigUint64(0, true);
2220
+ }
2221
+ }
2222
+ /**
2223
+ * ulong 0 singleton.
2224
+ */
2225
+ PbULong.ZERO = new PbULong(0, 0);
2226
+ /**
2227
+ * 64-bit signed integer as two 32-bit values.
2228
+ * Converts between `string`, `number` and `bigint` representations.
2229
+ */
2230
+ class PbLong extends SharedPbLong {
2231
+ /**
2232
+ * Create instance from a `string`, `number` or `bigint`.
2233
+ */
2234
+ static from(value) {
2235
+ if (BI)
2236
+ // noinspection FallThroughInSwitchStatementJS
2237
+ switch (typeof value) {
2238
+ case "string":
2239
+ if (value == "0")
2240
+ return this.ZERO;
2241
+ if (value == "")
2242
+ throw new Error('string is no integer');
2243
+ value = BI.C(value);
2244
+ case "number":
2245
+ if (value === 0)
2246
+ return this.ZERO;
2247
+ value = BI.C(value);
2248
+ case "bigint":
2249
+ if (!value)
2250
+ return this.ZERO;
2251
+ if (value < BI.MIN)
2252
+ throw new Error('ulong too small');
2253
+ if (value > BI.MAX)
2254
+ throw new Error('ulong too large');
2255
+ BI.V.setBigInt64(0, value, true);
2256
+ return new PbLong(BI.V.getInt32(0, true), BI.V.getInt32(4, true));
2257
+ }
2258
+ else
2259
+ switch (typeof value) {
2260
+ case "string":
2261
+ if (value == "0")
2262
+ return this.ZERO;
2263
+ value = value.trim();
2264
+ if (!RE_DECIMAL_STR.test(value))
2265
+ throw new Error('string is no integer');
2266
+ let [minus, lo, hi] = int64fromString(value);
2267
+ let pbl = new PbLong(lo, hi);
2268
+ return minus ? pbl.negate() : pbl;
2269
+ case "number":
2270
+ if (value == 0)
2271
+ return this.ZERO;
2272
+ if (!Number.isSafeInteger(value))
2273
+ throw new Error('number is no integer');
2274
+ return value > 0
2275
+ ? new PbLong(value, value / TWO_PWR_32_DBL)
2276
+ : new PbLong(-value, -value / TWO_PWR_32_DBL).negate();
2277
+ }
2278
+ throw new Error('unknown value ' + typeof value);
2279
+ }
2280
+ /**
2281
+ * Do we have a minus sign?
2282
+ */
2283
+ isNegative() {
2284
+ return (this.hi & 0x80000000) !== 0;
2285
+ }
2286
+ /**
2287
+ * Negate two's complement.
2288
+ * Invert all the bits and add one to the result.
2289
+ */
2290
+ negate() {
2291
+ let hi = ~this.hi, lo = this.lo;
2292
+ if (lo)
2293
+ lo = ~lo + 1;
2294
+ else
2295
+ hi += 1;
2296
+ return new PbLong(lo, hi);
2297
+ }
2298
+ /**
2299
+ * Convert to decimal string.
2300
+ */
2301
+ toString() {
2302
+ if (BI)
2303
+ return this.toBigInt().toString();
2304
+ if (this.isNegative()) {
2305
+ let n = this.negate();
2306
+ return '-' + int64toString(n.lo, n.hi);
2307
+ }
2308
+ return int64toString(this.lo, this.hi);
2309
+ }
2310
+ /**
2311
+ * Convert to native bigint.
2312
+ */
2313
+ toBigInt() {
2314
+ assertBi(BI);
2315
+ BI.V.setInt32(0, this.lo, true);
2316
+ BI.V.setInt32(4, this.hi, true);
2317
+ return BI.V.getBigInt64(0, true);
2318
+ }
2319
+ }
2320
+ /**
2321
+ * long 0 singleton.
2322
+ */
2323
+ PbLong.ZERO = new PbLong(0, 0);
2324
+
2325
+ const defaultsRead$1 = {
2326
+ readUnknownField: true,
2327
+ readerFactory: bytes => new BinaryReader(bytes),
2328
+ };
2329
+ /**
2330
+ * Make options for reading binary data form partial options.
2331
+ */
2332
+ function binaryReadOptions(options) {
2333
+ return options ? Object.assign(Object.assign({}, defaultsRead$1), options) : defaultsRead$1;
2334
+ }
2335
+ class BinaryReader {
2336
+ constructor(buf, textDecoder) {
2337
+ this.varint64 = varint64read; // dirty cast for `this`
2338
+ /**
2339
+ * Read a `uint32` field, an unsigned 32 bit varint.
2340
+ */
2341
+ this.uint32 = varint32read; // dirty cast for `this` and access to protected `buf`
2342
+ this.buf = buf;
2343
+ this.len = buf.length;
2344
+ this.pos = 0;
2345
+ this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
2346
+ this.textDecoder = textDecoder !== null && textDecoder !== void 0 ? textDecoder : new TextDecoder("utf-8", {
2347
+ fatal: true
2348
+ });
2349
+ }
2350
+ /**
2351
+ * Reads a tag - field number and wire type.
2352
+ */
2353
+ tag() {
2354
+ let tag = this.uint32(), fieldNo = tag >>> 3, wireType = tag & 7;
2355
+ if (fieldNo <= 0 || wireType < 0 || wireType > 5)
2356
+ throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
2357
+ return [fieldNo, wireType];
2358
+ }
2359
+ /**
2360
+ * Skip one element on the wire and return the skipped data.
2361
+ * Supports WireType.StartGroup since v2.0.0-alpha.23.
2362
+ */
2363
+ skip(wireType) {
2364
+ let start = this.pos;
2365
+ // noinspection FallThroughInSwitchStatementJS
2366
+ switch (wireType) {
2367
+ case WireType.Varint:
2368
+ while (this.buf[this.pos++] & 0x80) {
2369
+ // ignore
2370
+ }
2371
+ break;
2372
+ case WireType.Bit64:
2373
+ this.pos += 4;
2374
+ case WireType.Bit32:
2375
+ this.pos += 4;
2376
+ break;
2377
+ case WireType.LengthDelimited:
2378
+ let len = this.uint32();
2379
+ this.pos += len;
2380
+ break;
2381
+ case WireType.StartGroup:
2382
+ // From descriptor.proto: Group type is deprecated, not supported in proto3.
2383
+ // But we must still be able to parse and treat as unknown.
2384
+ let t;
2385
+ while ((t = this.tag()[1]) !== WireType.EndGroup) {
2386
+ this.skip(t);
2387
+ }
2388
+ break;
2389
+ default:
2390
+ throw new Error("cant skip wire type " + wireType);
2391
+ }
2392
+ this.assertBounds();
2393
+ return this.buf.subarray(start, this.pos);
2394
+ }
2395
+ /**
2396
+ * Throws error if position in byte array is out of range.
2397
+ */
2398
+ assertBounds() {
2399
+ if (this.pos > this.len)
2400
+ throw new RangeError("premature EOF");
2401
+ }
2402
+ /**
2403
+ * Read a `int32` field, a signed 32 bit varint.
2404
+ */
2405
+ int32() {
2406
+ return this.uint32() | 0;
2407
+ }
2408
+ /**
2409
+ * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
2410
+ */
2411
+ sint32() {
2412
+ let zze = this.uint32();
2413
+ // decode zigzag
2414
+ return (zze >>> 1) ^ -(zze & 1);
2415
+ }
2416
+ /**
2417
+ * Read a `int64` field, a signed 64-bit varint.
2418
+ */
2419
+ int64() {
2420
+ return new PbLong(...this.varint64());
2421
+ }
2422
+ /**
2423
+ * Read a `uint64` field, an unsigned 64-bit varint.
2424
+ */
2425
+ uint64() {
2426
+ return new PbULong(...this.varint64());
2427
+ }
2428
+ /**
2429
+ * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
2430
+ */
2431
+ sint64() {
2432
+ let [lo, hi] = this.varint64();
2433
+ // decode zig zag
2434
+ let s = -(lo & 1);
2435
+ lo = ((lo >>> 1 | (hi & 1) << 31) ^ s);
2436
+ hi = (hi >>> 1 ^ s);
2437
+ return new PbLong(lo, hi);
2438
+ }
2439
+ /**
2440
+ * Read a `bool` field, a variant.
2441
+ */
2442
+ bool() {
2443
+ let [lo, hi] = this.varint64();
2444
+ return lo !== 0 || hi !== 0;
2445
+ }
2446
+ /**
2447
+ * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
2448
+ */
2449
+ fixed32() {
2450
+ return this.view.getUint32((this.pos += 4) - 4, true);
2451
+ }
2452
+ /**
2453
+ * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
2454
+ */
2455
+ sfixed32() {
2456
+ return this.view.getInt32((this.pos += 4) - 4, true);
2457
+ }
2458
+ /**
2459
+ * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
2460
+ */
2461
+ fixed64() {
2462
+ return new PbULong(this.sfixed32(), this.sfixed32());
2463
+ }
2464
+ /**
2465
+ * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
2466
+ */
2467
+ sfixed64() {
2468
+ return new PbLong(this.sfixed32(), this.sfixed32());
2469
+ }
2470
+ /**
2471
+ * Read a `float` field, 32-bit floating point number.
2472
+ */
2473
+ float() {
2474
+ return this.view.getFloat32((this.pos += 4) - 4, true);
2475
+ }
2476
+ /**
2477
+ * Read a `double` field, a 64-bit floating point number.
2478
+ */
2479
+ double() {
2480
+ return this.view.getFloat64((this.pos += 8) - 8, true);
2481
+ }
2482
+ /**
2483
+ * Read a `bytes` field, length-delimited arbitrary data.
2484
+ */
2485
+ bytes() {
2486
+ let len = this.uint32();
2487
+ let start = this.pos;
2488
+ this.pos += len;
2489
+ this.assertBounds();
2490
+ return this.buf.subarray(start, start + len);
2491
+ }
2492
+ /**
2493
+ * Read a `string` field, length-delimited data converted to UTF-8 text.
2494
+ */
2495
+ string() {
2496
+ return this.textDecoder.decode(this.bytes());
2497
+ }
2498
+ }
2499
+
2500
+ /**
2501
+ * assert that condition is true or throw error (with message)
2502
+ */
2503
+ function assert(condition, msg) {
2504
+ if (!condition) {
2505
+ throw new Error(msg);
2506
+ }
2507
+ }
2508
+ /**
2509
+ * assert that value cannot exist = type `never`. throw runtime error if it does.
2510
+ */
2511
+ function assertNever(value, msg) {
2512
+ throw new Error(msg !== null && msg !== void 0 ? msg : 'Unexpected object: ' + value);
2513
+ }
2514
+ const FLOAT32_MAX = 3.4028234663852886e+38, FLOAT32_MIN = -3.4028234663852886e+38, UINT32_MAX = 0xFFFFFFFF, INT32_MAX = 0X7FFFFFFF, INT32_MIN = -0X80000000;
2515
+ function assertInt32(arg) {
2516
+ if (typeof arg !== "number")
2517
+ throw new Error('invalid int 32: ' + typeof arg);
2518
+ if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
2519
+ throw new Error('invalid int 32: ' + arg);
2520
+ }
2521
+ function assertUInt32(arg) {
2522
+ if (typeof arg !== "number")
2523
+ throw new Error('invalid uint 32: ' + typeof arg);
2524
+ if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
2525
+ throw new Error('invalid uint 32: ' + arg);
2526
+ }
2527
+ function assertFloat32(arg) {
2528
+ if (typeof arg !== "number")
2529
+ throw new Error('invalid float 32: ' + typeof arg);
2530
+ if (!Number.isFinite(arg))
2531
+ return;
2532
+ if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
2533
+ throw new Error('invalid float 32: ' + arg);
2534
+ }
2535
+
2536
+ const defaultsWrite$1 = {
2537
+ writeUnknownFields: true,
2538
+ writerFactory: () => new BinaryWriter(),
2539
+ };
2540
+ /**
2541
+ * Make options for writing binary data form partial options.
2542
+ */
2543
+ function binaryWriteOptions(options) {
2544
+ return options ? Object.assign(Object.assign({}, defaultsWrite$1), options) : defaultsWrite$1;
2545
+ }
2546
+ class BinaryWriter {
2547
+ constructor(textEncoder) {
2548
+ /**
2549
+ * Previous fork states.
2550
+ */
2551
+ this.stack = [];
2552
+ this.textEncoder = textEncoder !== null && textEncoder !== void 0 ? textEncoder : new TextEncoder();
2553
+ this.chunks = [];
2554
+ this.buf = [];
2555
+ }
2556
+ /**
2557
+ * Return all bytes written and reset this writer.
2558
+ */
2559
+ finish() {
2560
+ this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
2561
+ let len = 0;
2562
+ for (let i = 0; i < this.chunks.length; i++)
2563
+ len += this.chunks[i].length;
2564
+ let bytes = new Uint8Array(len);
2565
+ let offset = 0;
2566
+ for (let i = 0; i < this.chunks.length; i++) {
2567
+ bytes.set(this.chunks[i], offset);
2568
+ offset += this.chunks[i].length;
2569
+ }
2570
+ this.chunks = [];
2571
+ return bytes;
2572
+ }
2573
+ /**
2574
+ * Start a new fork for length-delimited data like a message
2575
+ * or a packed repeated field.
2576
+ *
2577
+ * Must be joined later with `join()`.
2578
+ */
2579
+ fork() {
2580
+ this.stack.push({ chunks: this.chunks, buf: this.buf });
2581
+ this.chunks = [];
2582
+ this.buf = [];
2583
+ return this;
2584
+ }
2585
+ /**
2586
+ * Join the last fork. Write its length and bytes, then
2587
+ * return to the previous state.
2588
+ */
2589
+ join() {
2590
+ // get chunk of fork
2591
+ let chunk = this.finish();
2592
+ // restore previous state
2593
+ let prev = this.stack.pop();
2594
+ if (!prev)
2595
+ throw new Error('invalid state, fork stack empty');
2596
+ this.chunks = prev.chunks;
2597
+ this.buf = prev.buf;
2598
+ // write length of chunk as varint
2599
+ this.uint32(chunk.byteLength);
2600
+ return this.raw(chunk);
2601
+ }
2602
+ /**
2603
+ * Writes a tag (field number and wire type).
2604
+ *
2605
+ * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
2606
+ *
2607
+ * Generated code should compute the tag ahead of time and call `uint32()`.
2608
+ */
2609
+ tag(fieldNo, type) {
2610
+ return this.uint32((fieldNo << 3 | type) >>> 0);
2611
+ }
2612
+ /**
2613
+ * Write a chunk of raw bytes.
2614
+ */
2615
+ raw(chunk) {
2616
+ if (this.buf.length) {
2617
+ this.chunks.push(new Uint8Array(this.buf));
2618
+ this.buf = [];
2619
+ }
2620
+ this.chunks.push(chunk);
2621
+ return this;
2622
+ }
2623
+ /**
2624
+ * Write a `uint32` value, an unsigned 32 bit varint.
2625
+ */
2626
+ uint32(value) {
2627
+ assertUInt32(value);
2628
+ // write value as varint 32, inlined for speed
2629
+ while (value > 0x7f) {
2630
+ this.buf.push((value & 0x7f) | 0x80);
2631
+ value = value >>> 7;
2632
+ }
2633
+ this.buf.push(value);
2634
+ return this;
2635
+ }
2636
+ /**
2637
+ * Write a `int32` value, a signed 32 bit varint.
2638
+ */
2639
+ int32(value) {
2640
+ assertInt32(value);
2641
+ varint32write(value, this.buf);
2642
+ return this;
2643
+ }
2644
+ /**
2645
+ * Write a `bool` value, a variant.
2646
+ */
2647
+ bool(value) {
2648
+ this.buf.push(value ? 1 : 0);
2649
+ return this;
2650
+ }
2651
+ /**
2652
+ * Write a `bytes` value, length-delimited arbitrary data.
2653
+ */
2654
+ bytes(value) {
2655
+ this.uint32(value.byteLength); // write length of chunk as varint
2656
+ return this.raw(value);
2657
+ }
2658
+ /**
2659
+ * Write a `string` value, length-delimited data converted to UTF-8 text.
2660
+ */
2661
+ string(value) {
2662
+ let chunk = this.textEncoder.encode(value);
2663
+ this.uint32(chunk.byteLength); // write length of chunk as varint
2664
+ return this.raw(chunk);
2665
+ }
2666
+ /**
2667
+ * Write a `float` value, 32-bit floating point number.
2668
+ */
2669
+ float(value) {
2670
+ assertFloat32(value);
2671
+ let chunk = new Uint8Array(4);
2672
+ new DataView(chunk.buffer).setFloat32(0, value, true);
2673
+ return this.raw(chunk);
2674
+ }
2675
+ /**
2676
+ * Write a `double` value, a 64-bit floating point number.
2677
+ */
2678
+ double(value) {
2679
+ let chunk = new Uint8Array(8);
2680
+ new DataView(chunk.buffer).setFloat64(0, value, true);
2681
+ return this.raw(chunk);
2682
+ }
2683
+ /**
2684
+ * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
2685
+ */
2686
+ fixed32(value) {
2687
+ assertUInt32(value);
2688
+ let chunk = new Uint8Array(4);
2689
+ new DataView(chunk.buffer).setUint32(0, value, true);
2690
+ return this.raw(chunk);
2691
+ }
2692
+ /**
2693
+ * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
2694
+ */
2695
+ sfixed32(value) {
2696
+ assertInt32(value);
2697
+ let chunk = new Uint8Array(4);
2698
+ new DataView(chunk.buffer).setInt32(0, value, true);
2699
+ return this.raw(chunk);
2700
+ }
2701
+ /**
2702
+ * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
2703
+ */
2704
+ sint32(value) {
2705
+ assertInt32(value);
2706
+ // zigzag encode
2707
+ value = ((value << 1) ^ (value >> 31)) >>> 0;
2708
+ varint32write(value, this.buf);
2709
+ return this;
2710
+ }
2711
+ /**
2712
+ * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
2713
+ */
2714
+ sfixed64(value) {
2715
+ let chunk = new Uint8Array(8);
2716
+ let view = new DataView(chunk.buffer);
2717
+ let long = PbLong.from(value);
2718
+ view.setInt32(0, long.lo, true);
2719
+ view.setInt32(4, long.hi, true);
2720
+ return this.raw(chunk);
2721
+ }
2722
+ /**
2723
+ * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
2724
+ */
2725
+ fixed64(value) {
2726
+ let chunk = new Uint8Array(8);
2727
+ let view = new DataView(chunk.buffer);
2728
+ let long = PbULong.from(value);
2729
+ view.setInt32(0, long.lo, true);
2730
+ view.setInt32(4, long.hi, true);
2731
+ return this.raw(chunk);
2732
+ }
2733
+ /**
2734
+ * Write a `int64` value, a signed 64-bit varint.
2735
+ */
2736
+ int64(value) {
2737
+ let long = PbLong.from(value);
2738
+ varint64write(long.lo, long.hi, this.buf);
2739
+ return this;
2740
+ }
2741
+ /**
2742
+ * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
2743
+ */
2744
+ sint64(value) {
2745
+ let long = PbLong.from(value),
2746
+ // zigzag encode
2747
+ sign = long.hi >> 31, lo = (long.lo << 1) ^ sign, hi = ((long.hi << 1) | (long.lo >>> 31)) ^ sign;
2748
+ varint64write(lo, hi, this.buf);
2749
+ return this;
2750
+ }
2751
+ /**
2752
+ * Write a `uint64` value, an unsigned 64-bit varint.
2753
+ */
2754
+ uint64(value) {
2755
+ let long = PbULong.from(value);
2756
+ varint64write(long.lo, long.hi, this.buf);
2757
+ return this;
2758
+ }
2759
+ }
2760
+
2761
+ const defaultsWrite = {
2762
+ emitDefaultValues: false,
2763
+ enumAsInteger: false,
2764
+ useProtoFieldName: false,
2765
+ prettySpaces: 0,
2766
+ }, defaultsRead = {
2767
+ ignoreUnknownFields: false,
2768
+ };
2769
+ /**
2770
+ * Make options for reading JSON data from partial options.
2771
+ */
2772
+ function jsonReadOptions(options) {
2773
+ return options ? Object.assign(Object.assign({}, defaultsRead), options) : defaultsRead;
2774
+ }
2775
+ /**
2776
+ * Make options for writing JSON data from partial options.
2777
+ */
2778
+ function jsonWriteOptions(options) {
2779
+ return options ? Object.assign(Object.assign({}, defaultsWrite), options) : defaultsWrite;
2780
+ }
2781
+
2782
+ /**
2783
+ * The symbol used as a key on message objects to store the message type.
2784
+ *
2785
+ * Note that this is an experimental feature - it is here to stay, but
2786
+ * implementation details may change without notice.
2787
+ */
2788
+ const MESSAGE_TYPE = Symbol.for("protobuf-ts/message-type");
2789
+
2790
+ /**
2791
+ * Converts snake_case to lowerCamelCase.
2792
+ *
2793
+ * Should behave like protoc:
2794
+ * https://github.com/protocolbuffers/protobuf/blob/e8ae137c96444ea313485ed1118c5e43b2099cf1/src/google/protobuf/compiler/java/java_helpers.cc#L118
2795
+ */
2796
+ function lowerCamelCase(snakeCase) {
2797
+ let capNext = false;
2798
+ const sb = [];
2799
+ for (let i = 0; i < snakeCase.length; i++) {
2800
+ let next = snakeCase.charAt(i);
2801
+ if (next == '_') {
2802
+ capNext = true;
2803
+ }
2804
+ else if (/\d/.test(next)) {
2805
+ sb.push(next);
2806
+ capNext = true;
2807
+ }
2808
+ else if (capNext) {
2809
+ sb.push(next.toUpperCase());
2810
+ capNext = false;
2811
+ }
2812
+ else if (i == 0) {
2813
+ sb.push(next.toLowerCase());
2814
+ }
2815
+ else {
2816
+ sb.push(next);
2817
+ }
2818
+ }
2819
+ return sb.join('');
2820
+ }
2821
+
2822
+ /**
2823
+ * Scalar value types. This is a subset of field types declared by protobuf
2824
+ * enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
2825
+ * are omitted, but the numerical values are identical.
2826
+ */
2827
+ var ScalarType;
2828
+ (function (ScalarType) {
2829
+ // 0 is reserved for errors.
2830
+ // Order is weird for historical reasons.
2831
+ ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
2832
+ ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
2833
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
2834
+ // negative values are likely.
2835
+ ScalarType[ScalarType["INT64"] = 3] = "INT64";
2836
+ ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
2837
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
2838
+ // negative values are likely.
2839
+ ScalarType[ScalarType["INT32"] = 5] = "INT32";
2840
+ ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
2841
+ ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
2842
+ ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
2843
+ ScalarType[ScalarType["STRING"] = 9] = "STRING";
2844
+ // Tag-delimited aggregate.
2845
+ // Group type is deprecated and not supported in proto3. However, Proto3
2846
+ // implementations should still be able to parse the group wire format and
2847
+ // treat group fields as unknown fields.
2848
+ // TYPE_GROUP = 10,
2849
+ // TYPE_MESSAGE = 11, // Length-delimited aggregate.
2850
+ // New in version 2.
2851
+ ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
2852
+ ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
2853
+ // TYPE_ENUM = 14,
2854
+ ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
2855
+ ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
2856
+ ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
2857
+ ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
2858
+ })(ScalarType || (ScalarType = {}));
2859
+ /**
2860
+ * JavaScript representation of 64 bit integral types. Equivalent to the
2861
+ * field option "jstype".
2862
+ *
2863
+ * By default, protobuf-ts represents 64 bit types as `bigint`.
2864
+ *
2865
+ * You can change the default behaviour by enabling the plugin parameter
2866
+ * `long_type_string`, which will represent 64 bit types as `string`.
2867
+ *
2868
+ * Alternatively, you can change the behaviour for individual fields
2869
+ * with the field option "jstype":
2870
+ *
2871
+ * ```protobuf
2872
+ * uint64 my_field = 1 [jstype = JS_STRING];
2873
+ * uint64 other_field = 2 [jstype = JS_NUMBER];
2874
+ * ```
2875
+ */
2876
+ var LongType;
2877
+ (function (LongType) {
2878
+ /**
2879
+ * Use JavaScript `bigint`.
2880
+ *
2881
+ * Field option `[jstype = JS_NORMAL]`.
2882
+ */
2883
+ LongType[LongType["BIGINT"] = 0] = "BIGINT";
2884
+ /**
2885
+ * Use JavaScript `string`.
2886
+ *
2887
+ * Field option `[jstype = JS_STRING]`.
2888
+ */
2889
+ LongType[LongType["STRING"] = 1] = "STRING";
2890
+ /**
2891
+ * Use JavaScript `number`.
2892
+ *
2893
+ * Large values will loose precision.
2894
+ *
2895
+ * Field option `[jstype = JS_NUMBER]`.
2896
+ */
2897
+ LongType[LongType["NUMBER"] = 2] = "NUMBER";
2898
+ })(LongType || (LongType = {}));
2899
+ /**
2900
+ * Protobuf 2.1.0 introduced packed repeated fields.
2901
+ * Setting the field option `[packed = true]` enables packing.
2902
+ *
2903
+ * In proto3, all repeated fields are packed by default.
2904
+ * Setting the field option `[packed = false]` disables packing.
2905
+ *
2906
+ * Packed repeated fields are encoded with a single tag,
2907
+ * then a length-delimiter, then the element values.
2908
+ *
2909
+ * Unpacked repeated fields are encoded with a tag and
2910
+ * value for each element.
2911
+ *
2912
+ * `bytes` and `string` cannot be packed.
2913
+ */
2914
+ var RepeatType;
2915
+ (function (RepeatType) {
2916
+ /**
2917
+ * The field is not repeated.
2918
+ */
2919
+ RepeatType[RepeatType["NO"] = 0] = "NO";
2920
+ /**
2921
+ * The field is repeated and should be packed.
2922
+ * Invalid for `bytes` and `string`, they cannot be packed.
2923
+ */
2924
+ RepeatType[RepeatType["PACKED"] = 1] = "PACKED";
2925
+ /**
2926
+ * The field is repeated but should not be packed.
2927
+ * The only valid repeat type for repeated `bytes` and `string`.
2928
+ */
2929
+ RepeatType[RepeatType["UNPACKED"] = 2] = "UNPACKED";
2930
+ })(RepeatType || (RepeatType = {}));
2931
+ /**
2932
+ * Turns PartialFieldInfo into FieldInfo.
2933
+ */
2934
+ function normalizeFieldInfo(field) {
2935
+ var _a, _b, _c, _d;
2936
+ field.localName = (_a = field.localName) !== null && _a !== void 0 ? _a : lowerCamelCase(field.name);
2937
+ field.jsonName = (_b = field.jsonName) !== null && _b !== void 0 ? _b : lowerCamelCase(field.name);
2938
+ field.repeat = (_c = field.repeat) !== null && _c !== void 0 ? _c : RepeatType.NO;
2939
+ field.opt = (_d = field.opt) !== null && _d !== void 0 ? _d : (field.repeat ? false : field.oneof ? false : field.kind == "message");
2940
+ return field;
2941
+ }
2942
+
2943
+ /**
2944
+ * Is the given value a valid oneof group?
2945
+ *
2946
+ * We represent protobuf `oneof` as algebraic data types (ADT) in generated
2947
+ * code. But when working with messages of unknown type, the ADT does not
2948
+ * help us.
2949
+ *
2950
+ * This type guard checks if the given object adheres to the ADT rules, which
2951
+ * are as follows:
2952
+ *
2953
+ * 1) Must be an object.
2954
+ *
2955
+ * 2) Must have a "oneofKind" discriminator property.
2956
+ *
2957
+ * 3) If "oneofKind" is `undefined`, no member field is selected. The object
2958
+ * must not have any other properties.
2959
+ *
2960
+ * 4) If "oneofKind" is a `string`, the member field with this name is
2961
+ * selected.
2962
+ *
2963
+ * 5) If a member field is selected, the object must have a second property
2964
+ * with this name. The property must not be `undefined`.
2965
+ *
2966
+ * 6) No extra properties are allowed. The object has either one property
2967
+ * (no selection) or two properties (selection).
2968
+ *
2969
+ */
2970
+ function isOneofGroup(any) {
2971
+ if (typeof any != 'object' || any === null || !any.hasOwnProperty('oneofKind')) {
2972
+ return false;
2973
+ }
2974
+ switch (typeof any.oneofKind) {
2975
+ case "string":
2976
+ if (any[any.oneofKind] === undefined)
2977
+ return false;
2978
+ return Object.keys(any).length == 2;
2979
+ case "undefined":
2980
+ return Object.keys(any).length == 1;
2981
+ default:
2982
+ return false;
2983
+ }
2984
+ }
2985
+
2986
+ // noinspection JSMethodCanBeStatic
2987
+ class ReflectionTypeCheck {
2988
+ constructor(info) {
2989
+ var _a;
2990
+ this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : [];
2991
+ }
2992
+ prepare() {
2993
+ if (this.data)
2994
+ return;
2995
+ const req = [], known = [], oneofs = [];
2996
+ for (let field of this.fields) {
2997
+ if (field.oneof) {
2998
+ if (!oneofs.includes(field.oneof)) {
2999
+ oneofs.push(field.oneof);
3000
+ req.push(field.oneof);
3001
+ known.push(field.oneof);
3002
+ }
3003
+ }
3004
+ else {
3005
+ known.push(field.localName);
3006
+ switch (field.kind) {
3007
+ case "scalar":
3008
+ case "enum":
3009
+ if (!field.opt || field.repeat)
3010
+ req.push(field.localName);
3011
+ break;
3012
+ case "message":
3013
+ if (field.repeat)
3014
+ req.push(field.localName);
3015
+ break;
3016
+ case "map":
3017
+ req.push(field.localName);
3018
+ break;
3019
+ }
3020
+ }
3021
+ }
3022
+ this.data = { req, known, oneofs: Object.values(oneofs) };
3023
+ }
3024
+ /**
3025
+ * Is the argument a valid message as specified by the
3026
+ * reflection information?
3027
+ *
3028
+ * Checks all field types recursively. The `depth`
3029
+ * specifies how deep into the structure the check will be.
3030
+ *
3031
+ * With a depth of 0, only the presence of fields
3032
+ * is checked.
3033
+ *
3034
+ * With a depth of 1 or more, the field types are checked.
3035
+ *
3036
+ * With a depth of 2 or more, the members of map, repeated
3037
+ * and message fields are checked.
3038
+ *
3039
+ * Message fields will be checked recursively with depth - 1.
3040
+ *
3041
+ * The number of map entries / repeated values being checked
3042
+ * is < depth.
3043
+ */
3044
+ is(message, depth, allowExcessProperties = false) {
3045
+ if (depth < 0)
3046
+ return true;
3047
+ if (message === null || message === undefined || typeof message != 'object')
3048
+ return false;
3049
+ this.prepare();
3050
+ let keys = Object.keys(message), data = this.data;
3051
+ // if a required field is missing in arg, this cannot be a T
3052
+ if (keys.length < data.req.length || data.req.some(n => !keys.includes(n)))
3053
+ return false;
3054
+ if (!allowExcessProperties) {
3055
+ // if the arg contains a key we dont know, this is not a literal T
3056
+ if (keys.some(k => !data.known.includes(k)))
3057
+ return false;
3058
+ }
3059
+ // "With a depth of 0, only the presence and absence of fields is checked."
3060
+ // "With a depth of 1 or more, the field types are checked."
3061
+ if (depth < 1) {
3062
+ return true;
3063
+ }
3064
+ // check oneof group
3065
+ for (const name of data.oneofs) {
3066
+ const group = message[name];
3067
+ if (!isOneofGroup(group))
3068
+ return false;
3069
+ if (group.oneofKind === undefined)
3070
+ continue;
3071
+ const field = this.fields.find(f => f.localName === group.oneofKind);
3072
+ if (!field)
3073
+ return false; // we found no field, but have a kind, something is wrong
3074
+ if (!this.field(group[group.oneofKind], field, allowExcessProperties, depth))
3075
+ return false;
3076
+ }
3077
+ // check types
3078
+ for (const field of this.fields) {
3079
+ if (field.oneof !== undefined)
3080
+ continue;
3081
+ if (!this.field(message[field.localName], field, allowExcessProperties, depth))
3082
+ return false;
3083
+ }
3084
+ return true;
3085
+ }
3086
+ field(arg, field, allowExcessProperties, depth) {
3087
+ let repeated = field.repeat;
3088
+ switch (field.kind) {
3089
+ case "scalar":
3090
+ if (arg === undefined)
3091
+ return field.opt;
3092
+ if (repeated)
3093
+ return this.scalars(arg, field.T, depth, field.L);
3094
+ return this.scalar(arg, field.T, field.L);
3095
+ case "enum":
3096
+ if (arg === undefined)
3097
+ return field.opt;
3098
+ if (repeated)
3099
+ return this.scalars(arg, ScalarType.INT32, depth);
3100
+ return this.scalar(arg, ScalarType.INT32);
3101
+ case "message":
3102
+ if (arg === undefined)
3103
+ return true;
3104
+ if (repeated)
3105
+ return this.messages(arg, field.T(), allowExcessProperties, depth);
3106
+ return this.message(arg, field.T(), allowExcessProperties, depth);
3107
+ case "map":
3108
+ if (typeof arg != 'object' || arg === null)
3109
+ return false;
3110
+ if (depth < 2)
3111
+ return true;
3112
+ if (!this.mapKeys(arg, field.K, depth))
3113
+ return false;
3114
+ switch (field.V.kind) {
3115
+ case "scalar":
3116
+ return this.scalars(Object.values(arg), field.V.T, depth, field.V.L);
3117
+ case "enum":
3118
+ return this.scalars(Object.values(arg), ScalarType.INT32, depth);
3119
+ case "message":
3120
+ return this.messages(Object.values(arg), field.V.T(), allowExcessProperties, depth);
3121
+ }
3122
+ break;
3123
+ }
3124
+ return true;
3125
+ }
3126
+ message(arg, type, allowExcessProperties, depth) {
3127
+ if (allowExcessProperties) {
3128
+ return type.isAssignable(arg, depth);
3129
+ }
3130
+ return type.is(arg, depth);
3131
+ }
3132
+ messages(arg, type, allowExcessProperties, depth) {
3133
+ if (!Array.isArray(arg))
3134
+ return false;
3135
+ if (depth < 2)
3136
+ return true;
3137
+ if (allowExcessProperties) {
3138
+ for (let i = 0; i < arg.length && i < depth; i++)
3139
+ if (!type.isAssignable(arg[i], depth - 1))
3140
+ return false;
3141
+ }
3142
+ else {
3143
+ for (let i = 0; i < arg.length && i < depth; i++)
3144
+ if (!type.is(arg[i], depth - 1))
3145
+ return false;
3146
+ }
3147
+ return true;
3148
+ }
3149
+ scalar(arg, type, longType) {
3150
+ let argType = typeof arg;
3151
+ switch (type) {
3152
+ case ScalarType.UINT64:
3153
+ case ScalarType.FIXED64:
3154
+ case ScalarType.INT64:
3155
+ case ScalarType.SFIXED64:
3156
+ case ScalarType.SINT64:
3157
+ switch (longType) {
3158
+ case LongType.BIGINT:
3159
+ return argType == "bigint";
3160
+ case LongType.NUMBER:
3161
+ return argType == "number" && !isNaN(arg);
3162
+ default:
3163
+ return argType == "string";
3164
+ }
3165
+ case ScalarType.BOOL:
3166
+ return argType == 'boolean';
3167
+ case ScalarType.STRING:
3168
+ return argType == 'string';
3169
+ case ScalarType.BYTES:
3170
+ return arg instanceof Uint8Array;
3171
+ case ScalarType.DOUBLE:
3172
+ case ScalarType.FLOAT:
3173
+ return argType == 'number' && !isNaN(arg);
3174
+ default:
3175
+ // case ScalarType.UINT32:
3176
+ // case ScalarType.FIXED32:
3177
+ // case ScalarType.INT32:
3178
+ // case ScalarType.SINT32:
3179
+ // case ScalarType.SFIXED32:
3180
+ return argType == 'number' && Number.isInteger(arg);
3181
+ }
3182
+ }
3183
+ scalars(arg, type, depth, longType) {
3184
+ if (!Array.isArray(arg))
3185
+ return false;
3186
+ if (depth < 2)
3187
+ return true;
3188
+ if (Array.isArray(arg))
3189
+ for (let i = 0; i < arg.length && i < depth; i++)
3190
+ if (!this.scalar(arg[i], type, longType))
3191
+ return false;
3192
+ return true;
3193
+ }
3194
+ mapKeys(map, type, depth) {
3195
+ let keys = Object.keys(map);
3196
+ switch (type) {
3197
+ case ScalarType.INT32:
3198
+ case ScalarType.FIXED32:
3199
+ case ScalarType.SFIXED32:
3200
+ case ScalarType.SINT32:
3201
+ case ScalarType.UINT32:
3202
+ return this.scalars(keys.slice(0, depth).map(k => parseInt(k)), type, depth);
3203
+ case ScalarType.BOOL:
3204
+ return this.scalars(keys.slice(0, depth).map(k => k == 'true' ? true : k == 'false' ? false : k), type, depth);
3205
+ default:
3206
+ return this.scalars(keys, type, depth, LongType.STRING);
3207
+ }
3208
+ }
3209
+ }
3210
+
3211
+ /**
3212
+ * Utility method to convert a PbLong or PbUlong to a JavaScript
3213
+ * representation during runtime.
3214
+ *
3215
+ * Works with generated field information, `undefined` is equivalent
3216
+ * to `STRING`.
3217
+ */
3218
+ function reflectionLongConvert(long, type) {
3219
+ switch (type) {
3220
+ case LongType.BIGINT:
3221
+ return long.toBigInt();
3222
+ case LongType.NUMBER:
3223
+ return long.toNumber();
3224
+ default:
3225
+ // case undefined:
3226
+ // case LongType.STRING:
3227
+ return long.toString();
3228
+ }
3229
+ }
3230
+
3231
+ /**
3232
+ * Reads proto3 messages in canonical JSON format using reflection information.
3233
+ *
3234
+ * https://developers.google.com/protocol-buffers/docs/proto3#json
3235
+ */
3236
+ class ReflectionJsonReader {
3237
+ constructor(info) {
3238
+ this.info = info;
3239
+ }
3240
+ prepare() {
3241
+ var _a;
3242
+ if (this.fMap === undefined) {
3243
+ this.fMap = {};
3244
+ const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : [];
3245
+ for (const field of fieldsInput) {
3246
+ this.fMap[field.name] = field;
3247
+ this.fMap[field.jsonName] = field;
3248
+ this.fMap[field.localName] = field;
3249
+ }
3250
+ }
3251
+ }
3252
+ // Cannot parse JSON <type of jsonValue> for <type name>#<fieldName>.
3253
+ assert(condition, fieldName, jsonValue) {
3254
+ if (!condition) {
3255
+ let what = typeofJsonValue(jsonValue);
3256
+ if (what == "number" || what == "boolean")
3257
+ what = jsonValue.toString();
3258
+ throw new Error(`Cannot parse JSON ${what} for ${this.info.typeName}#${fieldName}`);
3259
+ }
3260
+ }
3261
+ /**
3262
+ * Reads a message from canonical JSON format into the target message.
3263
+ *
3264
+ * Repeated fields are appended. Map entries are added, overwriting
3265
+ * existing keys.
3266
+ *
3267
+ * If a message field is already present, it will be merged with the
3268
+ * new data.
3269
+ */
3270
+ read(input, message, options) {
3271
+ this.prepare();
3272
+ const oneofsHandled = [];
3273
+ for (const [jsonKey, jsonValue] of Object.entries(input)) {
3274
+ const field = this.fMap[jsonKey];
3275
+ if (!field) {
3276
+ if (!options.ignoreUnknownFields)
3277
+ throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${jsonKey}`);
3278
+ continue;
3279
+ }
3280
+ const localName = field.localName;
3281
+ // handle oneof ADT
3282
+ let target; // this will be the target for the field value, whether it is member of a oneof or not
3283
+ if (field.oneof) {
3284
+ // since json objects are unordered by specification, it is not possible to take the last of multiple oneofs
3285
+ if (oneofsHandled.includes(field.oneof))
3286
+ throw new Error(`Multiple members of the oneof group "${field.oneof}" of ${this.info.typeName} are present in JSON.`);
3287
+ oneofsHandled.push(field.oneof);
3288
+ target = message[field.oneof] = {
3289
+ oneofKind: localName
3290
+ };
3291
+ }
3292
+ else {
3293
+ target = message;
3294
+ }
3295
+ // we have handled oneof above. we just have read the value into `target`.
3296
+ if (field.kind == 'map') {
3297
+ if (jsonValue === null) {
3298
+ continue;
3299
+ }
3300
+ // check input
3301
+ this.assert(isJsonObject(jsonValue), field.name, jsonValue);
3302
+ // our target to put map entries into
3303
+ const fieldObj = target[localName];
3304
+ // read entries
3305
+ for (const [jsonObjKey, jsonObjValue] of Object.entries(jsonValue)) {
3306
+ this.assert(jsonObjValue !== null, field.name + " map value", null);
3307
+ // read value
3308
+ let val;
3309
+ switch (field.V.kind) {
3310
+ case "message":
3311
+ val = field.V.T().internalJsonRead(jsonObjValue, options);
3312
+ break;
3313
+ case "enum":
3314
+ val = this.enum(field.V.T(), jsonObjValue, field.name, options.ignoreUnknownFields);
3315
+ if (val === false)
3316
+ continue;
3317
+ break;
3318
+ case "scalar":
3319
+ val = this.scalar(jsonObjValue, field.V.T, field.V.L, field.name);
3320
+ break;
3321
+ }
3322
+ this.assert(val !== undefined, field.name + " map value", jsonObjValue);
3323
+ // read key
3324
+ let key = jsonObjKey;
3325
+ if (field.K == ScalarType.BOOL)
3326
+ key = key == "true" ? true : key == "false" ? false : key;
3327
+ key = this.scalar(key, field.K, LongType.STRING, field.name).toString();
3328
+ fieldObj[key] = val;
3329
+ }
3330
+ }
3331
+ else if (field.repeat) {
3332
+ if (jsonValue === null)
3333
+ continue;
3334
+ // check input
3335
+ this.assert(Array.isArray(jsonValue), field.name, jsonValue);
3336
+ // our target to put array entries into
3337
+ const fieldArr = target[localName];
3338
+ // read array entries
3339
+ for (const jsonItem of jsonValue) {
3340
+ this.assert(jsonItem !== null, field.name, null);
3341
+ let val;
3342
+ switch (field.kind) {
3343
+ case "message":
3344
+ val = field.T().internalJsonRead(jsonItem, options);
3345
+ break;
3346
+ case "enum":
3347
+ val = this.enum(field.T(), jsonItem, field.name, options.ignoreUnknownFields);
3348
+ if (val === false)
3349
+ continue;
3350
+ break;
3351
+ case "scalar":
3352
+ val = this.scalar(jsonItem, field.T, field.L, field.name);
3353
+ break;
3354
+ }
3355
+ this.assert(val !== undefined, field.name, jsonValue);
3356
+ fieldArr.push(val);
3357
+ }
3358
+ }
3359
+ else {
3360
+ switch (field.kind) {
3361
+ case "message":
3362
+ if (jsonValue === null && field.T().typeName != 'google.protobuf.Value') {
3363
+ this.assert(field.oneof === undefined, field.name + " (oneof member)", null);
3364
+ continue;
3365
+ }
3366
+ target[localName] = field.T().internalJsonRead(jsonValue, options, target[localName]);
3367
+ break;
3368
+ case "enum":
3369
+ let val = this.enum(field.T(), jsonValue, field.name, options.ignoreUnknownFields);
3370
+ if (val === false)
3371
+ continue;
3372
+ target[localName] = val;
3373
+ break;
3374
+ case "scalar":
3375
+ target[localName] = this.scalar(jsonValue, field.T, field.L, field.name);
3376
+ break;
3377
+ }
3378
+ }
3379
+ }
3380
+ }
3381
+ /**
3382
+ * Returns `false` for unrecognized string representations.
3383
+ *
3384
+ * google.protobuf.NullValue accepts only JSON `null`.
3385
+ */
3386
+ enum(type, json, fieldName, ignoreUnknownFields) {
3387
+ if (type[0] == 'google.protobuf.NullValue')
3388
+ assert(json === null, `Unable to parse field ${this.info.typeName}#${fieldName}, enum ${type[0]} only accepts null.`);
3389
+ if (json === null)
3390
+ // we require 0 to be default value for all enums
3391
+ return 0;
3392
+ switch (typeof json) {
3393
+ case "number":
3394
+ assert(Number.isInteger(json), `Unable to parse field ${this.info.typeName}#${fieldName}, enum can only be integral number, got ${json}.`);
3395
+ return json;
3396
+ case "string":
3397
+ let localEnumName = json;
3398
+ if (type[2] && json.substring(0, type[2].length) === type[2])
3399
+ // lookup without the shared prefix
3400
+ localEnumName = json.substring(type[2].length);
3401
+ let enumNumber = type[1][localEnumName];
3402
+ if (typeof enumNumber === 'undefined' && ignoreUnknownFields) {
3403
+ return false;
3404
+ }
3405
+ assert(typeof enumNumber == "number", `Unable to parse field ${this.info.typeName}#${fieldName}, enum ${type[0]} has no value for "${json}".`);
3406
+ return enumNumber;
3407
+ }
3408
+ assert(false, `Unable to parse field ${this.info.typeName}#${fieldName}, cannot parse enum value from ${typeof json}".`);
3409
+ }
3410
+ scalar(json, type, longType, fieldName) {
3411
+ let e;
3412
+ try {
3413
+ switch (type) {
3414
+ // float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
3415
+ // Either numbers or strings are accepted. Exponent notation is also accepted.
3416
+ case ScalarType.DOUBLE:
3417
+ case ScalarType.FLOAT:
3418
+ if (json === null)
3419
+ return .0;
3420
+ if (json === "NaN")
3421
+ return Number.NaN;
3422
+ if (json === "Infinity")
3423
+ return Number.POSITIVE_INFINITY;
3424
+ if (json === "-Infinity")
3425
+ return Number.NEGATIVE_INFINITY;
3426
+ if (json === "") {
3427
+ e = "empty string";
3428
+ break;
3429
+ }
3430
+ if (typeof json == "string" && json.trim().length !== json.length) {
3431
+ e = "extra whitespace";
3432
+ break;
3433
+ }
3434
+ if (typeof json != "string" && typeof json != "number") {
3435
+ break;
3436
+ }
3437
+ let float = Number(json);
3438
+ if (Number.isNaN(float)) {
3439
+ e = "not a number";
3440
+ break;
3441
+ }
3442
+ if (!Number.isFinite(float)) {
3443
+ // infinity and -infinity are handled by string representation above, so this is an error
3444
+ e = "too large or small";
3445
+ break;
3446
+ }
3447
+ if (type == ScalarType.FLOAT)
3448
+ assertFloat32(float);
3449
+ return float;
3450
+ // int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
3451
+ case ScalarType.INT32:
3452
+ case ScalarType.FIXED32:
3453
+ case ScalarType.SFIXED32:
3454
+ case ScalarType.SINT32:
3455
+ case ScalarType.UINT32:
3456
+ if (json === null)
3457
+ return 0;
3458
+ let int32;
3459
+ if (typeof json == "number")
3460
+ int32 = json;
3461
+ else if (json === "")
3462
+ e = "empty string";
3463
+ else if (typeof json == "string") {
3464
+ if (json.trim().length !== json.length)
3465
+ e = "extra whitespace";
3466
+ else
3467
+ int32 = Number(json);
3468
+ }
3469
+ if (int32 === undefined)
3470
+ break;
3471
+ if (type == ScalarType.UINT32)
3472
+ assertUInt32(int32);
3473
+ else
3474
+ assertInt32(int32);
3475
+ return int32;
3476
+ // int64, fixed64, uint64: JSON value will be a decimal string. Either numbers or strings are accepted.
3477
+ case ScalarType.INT64:
3478
+ case ScalarType.SFIXED64:
3479
+ case ScalarType.SINT64:
3480
+ if (json === null)
3481
+ return reflectionLongConvert(PbLong.ZERO, longType);
3482
+ if (typeof json != "number" && typeof json != "string")
3483
+ break;
3484
+ return reflectionLongConvert(PbLong.from(json), longType);
3485
+ case ScalarType.FIXED64:
3486
+ case ScalarType.UINT64:
3487
+ if (json === null)
3488
+ return reflectionLongConvert(PbULong.ZERO, longType);
3489
+ if (typeof json != "number" && typeof json != "string")
3490
+ break;
3491
+ return reflectionLongConvert(PbULong.from(json), longType);
3492
+ // bool:
3493
+ case ScalarType.BOOL:
3494
+ if (json === null)
3495
+ return false;
3496
+ if (typeof json !== "boolean")
3497
+ break;
3498
+ return json;
3499
+ // string:
3500
+ case ScalarType.STRING:
3501
+ if (json === null)
3502
+ return "";
3503
+ if (typeof json !== "string") {
3504
+ e = "extra whitespace";
3505
+ break;
3506
+ }
3507
+ try {
3508
+ encodeURIComponent(json);
3509
+ }
3510
+ catch (e) {
3511
+ e = "invalid UTF8";
3512
+ break;
3513
+ }
3514
+ return json;
3515
+ // bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
3516
+ // Either standard or URL-safe base64 encoding with/without paddings are accepted.
3517
+ case ScalarType.BYTES:
3518
+ if (json === null || json === "")
3519
+ return new Uint8Array(0);
3520
+ if (typeof json !== 'string')
3521
+ break;
3522
+ return base64decode(json);
3523
+ }
3524
+ }
3525
+ catch (error) {
3526
+ e = error.message;
3527
+ }
3528
+ this.assert(false, fieldName + (e ? " - " + e : ""), json);
3529
+ }
3530
+ }
3531
+
3532
+ /**
3533
+ * Writes proto3 messages in canonical JSON format using reflection
3534
+ * information.
3535
+ *
3536
+ * https://developers.google.com/protocol-buffers/docs/proto3#json
3537
+ */
3538
+ class ReflectionJsonWriter {
3539
+ constructor(info) {
3540
+ var _a;
3541
+ this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : [];
3542
+ }
3543
+ /**
3544
+ * Converts the message to a JSON object, based on the field descriptors.
3545
+ */
3546
+ write(message, options) {
3547
+ const json = {}, source = message;
3548
+ for (const field of this.fields) {
3549
+ // field is not part of a oneof, simply write as is
3550
+ if (!field.oneof) {
3551
+ let jsonValue = this.field(field, source[field.localName], options);
3552
+ if (jsonValue !== undefined)
3553
+ json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue;
3554
+ continue;
3555
+ }
3556
+ // field is part of a oneof
3557
+ const group = source[field.oneof];
3558
+ if (group.oneofKind !== field.localName)
3559
+ continue; // not selected, skip
3560
+ const opt = field.kind == 'scalar' || field.kind == 'enum'
3561
+ ? Object.assign(Object.assign({}, options), { emitDefaultValues: true }) : options;
3562
+ let jsonValue = this.field(field, group[field.localName], opt);
3563
+ assert(jsonValue !== undefined);
3564
+ json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue;
3565
+ }
3566
+ return json;
3567
+ }
3568
+ field(field, value, options) {
3569
+ let jsonValue = undefined;
3570
+ if (field.kind == 'map') {
3571
+ assert(typeof value == "object" && value !== null);
3572
+ const jsonObj = {};
3573
+ switch (field.V.kind) {
3574
+ case "scalar":
3575
+ for (const [entryKey, entryValue] of Object.entries(value)) {
3576
+ const val = this.scalar(field.V.T, entryValue, field.name, false, true);
3577
+ assert(val !== undefined);
3578
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
3579
+ }
3580
+ break;
3581
+ case "message":
3582
+ const messageType = field.V.T();
3583
+ for (const [entryKey, entryValue] of Object.entries(value)) {
3584
+ const val = this.message(messageType, entryValue, field.name, options);
3585
+ assert(val !== undefined);
3586
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
3587
+ }
3588
+ break;
3589
+ case "enum":
3590
+ const enumInfo = field.V.T();
3591
+ for (const [entryKey, entryValue] of Object.entries(value)) {
3592
+ assert(entryValue === undefined || typeof entryValue == 'number');
3593
+ const val = this.enum(enumInfo, entryValue, field.name, false, true, options.enumAsInteger);
3594
+ assert(val !== undefined);
3595
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
3596
+ }
3597
+ break;
3598
+ }
3599
+ if (options.emitDefaultValues || Object.keys(jsonObj).length > 0)
3600
+ jsonValue = jsonObj;
3601
+ }
3602
+ else if (field.repeat) {
3603
+ assert(Array.isArray(value));
3604
+ const jsonArr = [];
3605
+ switch (field.kind) {
3606
+ case "scalar":
3607
+ for (let i = 0; i < value.length; i++) {
3608
+ const val = this.scalar(field.T, value[i], field.name, field.opt, true);
3609
+ assert(val !== undefined);
3610
+ jsonArr.push(val);
3611
+ }
3612
+ break;
3613
+ case "enum":
3614
+ const enumInfo = field.T();
3615
+ for (let i = 0; i < value.length; i++) {
3616
+ assert(value[i] === undefined || typeof value[i] == 'number');
3617
+ const val = this.enum(enumInfo, value[i], field.name, field.opt, true, options.enumAsInteger);
3618
+ assert(val !== undefined);
3619
+ jsonArr.push(val);
3620
+ }
3621
+ break;
3622
+ case "message":
3623
+ const messageType = field.T();
3624
+ for (let i = 0; i < value.length; i++) {
3625
+ const val = this.message(messageType, value[i], field.name, options);
3626
+ assert(val !== undefined);
3627
+ jsonArr.push(val);
3628
+ }
3629
+ break;
3630
+ }
3631
+ // add converted array to json output
3632
+ if (options.emitDefaultValues || jsonArr.length > 0 || options.emitDefaultValues)
3633
+ jsonValue = jsonArr;
3634
+ }
3635
+ else {
3636
+ switch (field.kind) {
3637
+ case "scalar":
3638
+ jsonValue = this.scalar(field.T, value, field.name, field.opt, options.emitDefaultValues);
3639
+ break;
3640
+ case "enum":
3641
+ jsonValue = this.enum(field.T(), value, field.name, field.opt, options.emitDefaultValues, options.enumAsInteger);
3642
+ break;
3643
+ case "message":
3644
+ jsonValue = this.message(field.T(), value, field.name, options);
3645
+ break;
3646
+ }
3647
+ }
3648
+ return jsonValue;
3649
+ }
3650
+ /**
3651
+ * Returns `null` for google.protobuf.NullValue.
3652
+ */
3653
+ enum(type, value, fieldName, optional, emitDefaultValues, enumAsInteger) {
3654
+ if (type[0] == 'google.protobuf.NullValue')
3655
+ return null;
3656
+ if (value === undefined) {
3657
+ assert(optional);
3658
+ return undefined;
3659
+ }
3660
+ if (value === 0 && !emitDefaultValues && !optional)
3661
+ // we require 0 to be default value for all enums
3662
+ return undefined;
3663
+ assert(typeof value == 'number');
3664
+ assert(Number.isInteger(value));
3665
+ if (enumAsInteger || !type[1].hasOwnProperty(value))
3666
+ // if we don't now the enum value, just return the number
3667
+ return value;
3668
+ if (type[2])
3669
+ // restore the dropped prefix
3670
+ return type[2] + type[1][value];
3671
+ return type[1][value];
3672
+ }
3673
+ message(type, value, fieldName, options) {
3674
+ if (value === undefined)
3675
+ return options.emitDefaultValues ? null : undefined;
3676
+ return type.internalJsonWrite(value, options);
3677
+ }
3678
+ scalar(type, value, fieldName, optional, emitDefaultValues) {
3679
+ if (value === undefined) {
3680
+ assert(optional);
3681
+ return undefined;
3682
+ }
3683
+ const ed = emitDefaultValues || optional;
3684
+ // noinspection FallThroughInSwitchStatementJS
3685
+ switch (type) {
3686
+ // int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
3687
+ case ScalarType.INT32:
3688
+ case ScalarType.SFIXED32:
3689
+ case ScalarType.SINT32:
3690
+ if (value === 0)
3691
+ return ed ? 0 : undefined;
3692
+ assertInt32(value);
3693
+ return value;
3694
+ case ScalarType.FIXED32:
3695
+ case ScalarType.UINT32:
3696
+ if (value === 0)
3697
+ return ed ? 0 : undefined;
3698
+ assertUInt32(value);
3699
+ return value;
3700
+ // float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
3701
+ // Either numbers or strings are accepted. Exponent notation is also accepted.
3702
+ case ScalarType.FLOAT:
3703
+ assertFloat32(value);
3704
+ case ScalarType.DOUBLE:
3705
+ if (value === 0)
3706
+ return ed ? 0 : undefined;
3707
+ assert(typeof value == 'number');
3708
+ if (Number.isNaN(value))
3709
+ return 'NaN';
3710
+ if (value === Number.POSITIVE_INFINITY)
3711
+ return 'Infinity';
3712
+ if (value === Number.NEGATIVE_INFINITY)
3713
+ return '-Infinity';
3714
+ return value;
3715
+ // string:
3716
+ case ScalarType.STRING:
3717
+ if (value === "")
3718
+ return ed ? '' : undefined;
3719
+ assert(typeof value == 'string');
3720
+ return value;
3721
+ // bool:
3722
+ case ScalarType.BOOL:
3723
+ if (value === false)
3724
+ return ed ? false : undefined;
3725
+ assert(typeof value == 'boolean');
3726
+ return value;
3727
+ // JSON value will be a decimal string. Either numbers or strings are accepted.
3728
+ case ScalarType.UINT64:
3729
+ case ScalarType.FIXED64:
3730
+ assert(typeof value == 'number' || typeof value == 'string' || typeof value == 'bigint');
3731
+ let ulong = PbULong.from(value);
3732
+ if (ulong.isZero() && !ed)
3733
+ return undefined;
3734
+ return ulong.toString();
3735
+ // JSON value will be a decimal string. Either numbers or strings are accepted.
3736
+ case ScalarType.INT64:
3737
+ case ScalarType.SFIXED64:
3738
+ case ScalarType.SINT64:
3739
+ assert(typeof value == 'number' || typeof value == 'string' || typeof value == 'bigint');
3740
+ let long = PbLong.from(value);
3741
+ if (long.isZero() && !ed)
3742
+ return undefined;
3743
+ return long.toString();
3744
+ // bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
3745
+ // Either standard or URL-safe base64 encoding with/without paddings are accepted.
3746
+ case ScalarType.BYTES:
3747
+ assert(value instanceof Uint8Array);
3748
+ if (!value.byteLength)
3749
+ return ed ? "" : undefined;
3750
+ return base64encode(value);
3751
+ }
3752
+ }
3753
+ }
3754
+
3755
+ /**
3756
+ * Creates the default value for a scalar type.
3757
+ */
3758
+ function reflectionScalarDefault(type, longType = LongType.STRING) {
3759
+ switch (type) {
3760
+ case ScalarType.BOOL:
3761
+ return false;
3762
+ case ScalarType.UINT64:
3763
+ case ScalarType.FIXED64:
3764
+ return reflectionLongConvert(PbULong.ZERO, longType);
3765
+ case ScalarType.INT64:
3766
+ case ScalarType.SFIXED64:
3767
+ case ScalarType.SINT64:
3768
+ return reflectionLongConvert(PbLong.ZERO, longType);
3769
+ case ScalarType.DOUBLE:
3770
+ case ScalarType.FLOAT:
3771
+ return 0.0;
3772
+ case ScalarType.BYTES:
3773
+ return new Uint8Array(0);
3774
+ case ScalarType.STRING:
3775
+ return "";
3776
+ default:
3777
+ // case ScalarType.INT32:
3778
+ // case ScalarType.UINT32:
3779
+ // case ScalarType.SINT32:
3780
+ // case ScalarType.FIXED32:
3781
+ // case ScalarType.SFIXED32:
3782
+ return 0;
3783
+ }
3784
+ }
3785
+
3786
+ /**
3787
+ * Reads proto3 messages in binary format using reflection information.
3788
+ *
3789
+ * https://developers.google.com/protocol-buffers/docs/encoding
3790
+ */
3791
+ class ReflectionBinaryReader {
3792
+ constructor(info) {
3793
+ this.info = info;
3794
+ }
3795
+ prepare() {
3796
+ var _a;
3797
+ if (!this.fieldNoToField) {
3798
+ const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : [];
3799
+ this.fieldNoToField = new Map(fieldsInput.map(field => [field.no, field]));
3800
+ }
3801
+ }
3802
+ /**
3803
+ * Reads a message from binary format into the target message.
3804
+ *
3805
+ * Repeated fields are appended. Map entries are added, overwriting
3806
+ * existing keys.
3807
+ *
3808
+ * If a message field is already present, it will be merged with the
3809
+ * new data.
3810
+ */
3811
+ read(reader, message, options, length) {
3812
+ this.prepare();
3813
+ const end = length === undefined ? reader.len : reader.pos + length;
3814
+ while (reader.pos < end) {
3815
+ // read the tag and find the field
3816
+ const [fieldNo, wireType] = reader.tag(), field = this.fieldNoToField.get(fieldNo);
3817
+ if (!field) {
3818
+ let u = options.readUnknownField;
3819
+ if (u == "throw")
3820
+ throw new Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.info.typeName}`);
3821
+ let d = reader.skip(wireType);
3822
+ if (u !== false)
3823
+ (u === true ? UnknownFieldHandler.onRead : u)(this.info.typeName, message, fieldNo, wireType, d);
3824
+ continue;
3825
+ }
3826
+ // target object for the field we are reading
3827
+ let target = message, repeated = field.repeat, localName = field.localName;
3828
+ // if field is member of oneof ADT, use ADT as target
3829
+ if (field.oneof) {
3830
+ target = target[field.oneof];
3831
+ // if other oneof member selected, set new ADT
3832
+ if (target.oneofKind !== localName)
3833
+ target = message[field.oneof] = {
3834
+ oneofKind: localName
3835
+ };
3836
+ }
3837
+ // we have handled oneof above, we just have read the value into `target[localName]`
3838
+ switch (field.kind) {
3839
+ case "scalar":
3840
+ case "enum":
3841
+ let T = field.kind == "enum" ? ScalarType.INT32 : field.T;
3842
+ let L = field.kind == "scalar" ? field.L : undefined;
3843
+ if (repeated) {
3844
+ let arr = target[localName]; // safe to assume presence of array, oneof cannot contain repeated values
3845
+ if (wireType == WireType.LengthDelimited && T != ScalarType.STRING && T != ScalarType.BYTES) {
3846
+ let e = reader.uint32() + reader.pos;
3847
+ while (reader.pos < e)
3848
+ arr.push(this.scalar(reader, T, L));
3849
+ }
3850
+ else
3851
+ arr.push(this.scalar(reader, T, L));
3852
+ }
3853
+ else
3854
+ target[localName] = this.scalar(reader, T, L);
3855
+ break;
3856
+ case "message":
3857
+ if (repeated) {
3858
+ let arr = target[localName]; // safe to assume presence of array, oneof cannot contain repeated values
3859
+ let msg = field.T().internalBinaryRead(reader, reader.uint32(), options);
3860
+ arr.push(msg);
3861
+ }
3862
+ else
3863
+ target[localName] = field.T().internalBinaryRead(reader, reader.uint32(), options, target[localName]);
3864
+ break;
3865
+ case "map":
3866
+ let [mapKey, mapVal] = this.mapEntry(field, reader, options);
3867
+ // safe to assume presence of map object, oneof cannot contain repeated values
3868
+ target[localName][mapKey] = mapVal;
3869
+ break;
3870
+ }
3871
+ }
3872
+ }
3873
+ /**
3874
+ * Read a map field, expecting key field = 1, value field = 2
3875
+ */
3876
+ mapEntry(field, reader, options) {
3877
+ let length = reader.uint32();
3878
+ let end = reader.pos + length;
3879
+ let key = undefined; // javascript only allows number or string for object properties
3880
+ let val = undefined;
3881
+ while (reader.pos < end) {
3882
+ let [fieldNo, wireType] = reader.tag();
3883
+ switch (fieldNo) {
3884
+ case 1:
3885
+ if (field.K == ScalarType.BOOL)
3886
+ key = reader.bool().toString();
3887
+ else
3888
+ // long types are read as string, number types are okay as number
3889
+ key = this.scalar(reader, field.K, LongType.STRING);
3890
+ break;
3891
+ case 2:
3892
+ switch (field.V.kind) {
3893
+ case "scalar":
3894
+ val = this.scalar(reader, field.V.T, field.V.L);
3895
+ break;
3896
+ case "enum":
3897
+ val = reader.int32();
3898
+ break;
3899
+ case "message":
3900
+ val = field.V.T().internalBinaryRead(reader, reader.uint32(), options);
3901
+ break;
3902
+ }
3903
+ break;
3904
+ default:
3905
+ throw new Error(`Unknown field ${fieldNo} (wire type ${wireType}) in map entry for ${this.info.typeName}#${field.name}`);
3906
+ }
3907
+ }
3908
+ if (key === undefined) {
3909
+ let keyRaw = reflectionScalarDefault(field.K);
3910
+ key = field.K == ScalarType.BOOL ? keyRaw.toString() : keyRaw;
3911
+ }
3912
+ if (val === undefined)
3913
+ switch (field.V.kind) {
3914
+ case "scalar":
3915
+ val = reflectionScalarDefault(field.V.T, field.V.L);
3916
+ break;
3917
+ case "enum":
3918
+ val = 0;
3919
+ break;
3920
+ case "message":
3921
+ val = field.V.T().create();
3922
+ break;
3923
+ }
3924
+ return [key, val];
3925
+ }
3926
+ scalar(reader, type, longType) {
3927
+ switch (type) {
3928
+ case ScalarType.INT32:
3929
+ return reader.int32();
3930
+ case ScalarType.STRING:
3931
+ return reader.string();
3932
+ case ScalarType.BOOL:
3933
+ return reader.bool();
3934
+ case ScalarType.DOUBLE:
3935
+ return reader.double();
3936
+ case ScalarType.FLOAT:
3937
+ return reader.float();
3938
+ case ScalarType.INT64:
3939
+ return reflectionLongConvert(reader.int64(), longType);
3940
+ case ScalarType.UINT64:
3941
+ return reflectionLongConvert(reader.uint64(), longType);
3942
+ case ScalarType.FIXED64:
3943
+ return reflectionLongConvert(reader.fixed64(), longType);
3944
+ case ScalarType.FIXED32:
3945
+ return reader.fixed32();
3946
+ case ScalarType.BYTES:
3947
+ return reader.bytes();
3948
+ case ScalarType.UINT32:
3949
+ return reader.uint32();
3950
+ case ScalarType.SFIXED32:
3951
+ return reader.sfixed32();
3952
+ case ScalarType.SFIXED64:
3953
+ return reflectionLongConvert(reader.sfixed64(), longType);
3954
+ case ScalarType.SINT32:
3955
+ return reader.sint32();
3956
+ case ScalarType.SINT64:
3957
+ return reflectionLongConvert(reader.sint64(), longType);
3958
+ }
3959
+ }
3960
+ }
3961
+
3962
+ /**
3963
+ * Writes proto3 messages in binary format using reflection information.
3964
+ *
3965
+ * https://developers.google.com/protocol-buffers/docs/encoding
3966
+ */
3967
+ class ReflectionBinaryWriter {
3968
+ constructor(info) {
3969
+ this.info = info;
3970
+ }
3971
+ prepare() {
3972
+ if (!this.fields) {
3973
+ const fieldsInput = this.info.fields ? this.info.fields.concat() : [];
3974
+ this.fields = fieldsInput.sort((a, b) => a.no - b.no);
3975
+ }
3976
+ }
3977
+ /**
3978
+ * Writes the message to binary format.
3979
+ */
3980
+ write(message, writer, options) {
3981
+ this.prepare();
3982
+ for (const field of this.fields) {
3983
+ let value, // this will be our field value, whether it is member of a oneof or not
3984
+ emitDefault, // whether we emit the default value (only true for oneof members)
3985
+ repeated = field.repeat, localName = field.localName;
3986
+ // handle oneof ADT
3987
+ if (field.oneof) {
3988
+ const group = message[field.oneof];
3989
+ if (group.oneofKind !== localName)
3990
+ continue; // if field is not selected, skip
3991
+ value = group[localName];
3992
+ emitDefault = true;
3993
+ }
3994
+ else {
3995
+ value = message[localName];
3996
+ emitDefault = false;
3997
+ }
3998
+ // we have handled oneof above. we just have to honor `emitDefault`.
3999
+ switch (field.kind) {
4000
+ case "scalar":
4001
+ case "enum":
4002
+ let T = field.kind == "enum" ? ScalarType.INT32 : field.T;
4003
+ if (repeated) {
4004
+ assert(Array.isArray(value));
4005
+ if (repeated == RepeatType.PACKED)
4006
+ this.packed(writer, T, field.no, value);
4007
+ else
4008
+ for (const item of value)
4009
+ this.scalar(writer, T, field.no, item, true);
4010
+ }
4011
+ else if (value === undefined)
4012
+ assert(field.opt);
4013
+ else
4014
+ this.scalar(writer, T, field.no, value, emitDefault || field.opt);
4015
+ break;
4016
+ case "message":
4017
+ if (repeated) {
4018
+ assert(Array.isArray(value));
4019
+ for (const item of value)
4020
+ this.message(writer, options, field.T(), field.no, item);
4021
+ }
4022
+ else {
4023
+ this.message(writer, options, field.T(), field.no, value);
4024
+ }
4025
+ break;
4026
+ case "map":
4027
+ assert(typeof value == 'object' && value !== null);
4028
+ for (const [key, val] of Object.entries(value))
4029
+ this.mapEntry(writer, options, field, key, val);
4030
+ break;
4031
+ }
4032
+ }
4033
+ let u = options.writeUnknownFields;
4034
+ if (u !== false)
4035
+ (u === true ? UnknownFieldHandler.onWrite : u)(this.info.typeName, message, writer);
4036
+ }
4037
+ mapEntry(writer, options, field, key, value) {
4038
+ writer.tag(field.no, WireType.LengthDelimited);
4039
+ writer.fork();
4040
+ // javascript only allows number or string for object properties
4041
+ // we convert from our representation to the protobuf type
4042
+ let keyValue = key;
4043
+ switch (field.K) {
4044
+ case ScalarType.INT32:
4045
+ case ScalarType.FIXED32:
4046
+ case ScalarType.UINT32:
4047
+ case ScalarType.SFIXED32:
4048
+ case ScalarType.SINT32:
4049
+ keyValue = Number.parseInt(key);
4050
+ break;
4051
+ case ScalarType.BOOL:
4052
+ assert(key == 'true' || key == 'false');
4053
+ keyValue = key == 'true';
4054
+ break;
4055
+ }
4056
+ // write key, expecting key field number = 1
4057
+ this.scalar(writer, field.K, 1, keyValue, true);
4058
+ // write value, expecting value field number = 2
4059
+ switch (field.V.kind) {
4060
+ case 'scalar':
4061
+ this.scalar(writer, field.V.T, 2, value, true);
4062
+ break;
4063
+ case 'enum':
4064
+ this.scalar(writer, ScalarType.INT32, 2, value, true);
4065
+ break;
4066
+ case 'message':
4067
+ this.message(writer, options, field.V.T(), 2, value);
4068
+ break;
4069
+ }
4070
+ writer.join();
4071
+ }
4072
+ message(writer, options, handler, fieldNo, value) {
4073
+ if (value === undefined)
4074
+ return;
4075
+ handler.internalBinaryWrite(value, writer.tag(fieldNo, WireType.LengthDelimited).fork(), options);
4076
+ writer.join();
4077
+ }
4078
+ /**
4079
+ * Write a single scalar value.
4080
+ */
4081
+ scalar(writer, type, fieldNo, value, emitDefault) {
4082
+ let [wireType, method, isDefault] = this.scalarInfo(type, value);
4083
+ if (!isDefault || emitDefault) {
4084
+ writer.tag(fieldNo, wireType);
4085
+ writer[method](value);
4086
+ }
4087
+ }
4088
+ /**
4089
+ * Write an array of scalar values in packed format.
4090
+ */
4091
+ packed(writer, type, fieldNo, value) {
4092
+ if (!value.length)
4093
+ return;
4094
+ assert(type !== ScalarType.BYTES && type !== ScalarType.STRING);
4095
+ // write tag
4096
+ writer.tag(fieldNo, WireType.LengthDelimited);
4097
+ // begin length-delimited
4098
+ writer.fork();
4099
+ // write values without tags
4100
+ let [, method,] = this.scalarInfo(type);
4101
+ for (let i = 0; i < value.length; i++)
4102
+ writer[method](value[i]);
4103
+ // end length delimited
4104
+ writer.join();
4105
+ }
4106
+ /**
4107
+ * Get information for writing a scalar value.
4108
+ *
4109
+ * Returns tuple:
4110
+ * [0]: appropriate WireType
4111
+ * [1]: name of the appropriate method of IBinaryWriter
4112
+ * [2]: whether the given value is a default value
4113
+ *
4114
+ * If argument `value` is omitted, [2] is always false.
4115
+ */
4116
+ scalarInfo(type, value) {
4117
+ let t = WireType.Varint;
4118
+ let m;
4119
+ let i = value === undefined;
4120
+ let d = value === 0;
4121
+ switch (type) {
4122
+ case ScalarType.INT32:
4123
+ m = "int32";
4124
+ break;
4125
+ case ScalarType.STRING:
4126
+ d = i || !value.length;
4127
+ t = WireType.LengthDelimited;
4128
+ m = "string";
4129
+ break;
4130
+ case ScalarType.BOOL:
4131
+ d = value === false;
4132
+ m = "bool";
4133
+ break;
4134
+ case ScalarType.UINT32:
4135
+ m = "uint32";
4136
+ break;
4137
+ case ScalarType.DOUBLE:
4138
+ t = WireType.Bit64;
4139
+ m = "double";
4140
+ break;
4141
+ case ScalarType.FLOAT:
4142
+ t = WireType.Bit32;
4143
+ m = "float";
4144
+ break;
4145
+ case ScalarType.INT64:
4146
+ d = i || PbLong.from(value).isZero();
4147
+ m = "int64";
4148
+ break;
4149
+ case ScalarType.UINT64:
4150
+ d = i || PbULong.from(value).isZero();
4151
+ m = "uint64";
4152
+ break;
4153
+ case ScalarType.FIXED64:
4154
+ d = i || PbULong.from(value).isZero();
4155
+ t = WireType.Bit64;
4156
+ m = "fixed64";
4157
+ break;
4158
+ case ScalarType.BYTES:
4159
+ d = i || !value.byteLength;
4160
+ t = WireType.LengthDelimited;
4161
+ m = "bytes";
4162
+ break;
4163
+ case ScalarType.FIXED32:
4164
+ t = WireType.Bit32;
4165
+ m = "fixed32";
4166
+ break;
4167
+ case ScalarType.SFIXED32:
4168
+ t = WireType.Bit32;
4169
+ m = "sfixed32";
4170
+ break;
4171
+ case ScalarType.SFIXED64:
4172
+ d = i || PbLong.from(value).isZero();
4173
+ t = WireType.Bit64;
4174
+ m = "sfixed64";
4175
+ break;
4176
+ case ScalarType.SINT32:
4177
+ m = "sint32";
4178
+ break;
4179
+ case ScalarType.SINT64:
4180
+ d = i || PbLong.from(value).isZero();
4181
+ m = "sint64";
4182
+ break;
4183
+ }
4184
+ return [t, m, i || d];
4185
+ }
4186
+ }
4187
+
4188
+ /**
4189
+ * Creates an instance of the generic message, using the field
4190
+ * information.
4191
+ */
4192
+ function reflectionCreate(type) {
4193
+ const msg = {};
4194
+ Object.defineProperty(msg, MESSAGE_TYPE, { enumerable: false, value: type });
4195
+ for (let field of type.fields) {
4196
+ let name = field.localName;
4197
+ if (field.opt)
4198
+ continue;
4199
+ if (field.oneof)
4200
+ msg[field.oneof] = { oneofKind: undefined };
4201
+ else if (field.repeat)
4202
+ msg[name] = [];
4203
+ else
4204
+ switch (field.kind) {
4205
+ case "scalar":
4206
+ msg[name] = reflectionScalarDefault(field.T, field.L);
4207
+ break;
4208
+ case "enum":
4209
+ // we require 0 to be default value for all enums
4210
+ msg[name] = 0;
4211
+ break;
4212
+ case "map":
4213
+ msg[name] = {};
4214
+ break;
4215
+ }
4216
+ }
4217
+ return msg;
4218
+ }
4219
+
4220
+ /**
4221
+ * Copy partial data into the target message.
4222
+ *
4223
+ * Replaces fields in the target with the fields from the
4224
+ * (partial) source.
4225
+ *
4226
+ * Omitted fields are not replaced.
4227
+ * Copies all values.
4228
+ * A default value in the source will replace a value in the target.
4229
+ *
4230
+ * Message fields are recursively merged (by calling `mergePartial()`
4231
+ * of the responsible message handler). Map and repeated fields
4232
+ * are simply overwritten, not appended or merged.
4233
+ */
4234
+ function reflectionMergePartial(info, target, source) {
4235
+ let fieldValue, // the field value we are working with
4236
+ input = source, output; // where we want our field value to go
4237
+ for (let field of info.fields) {
4238
+ let name = field.localName;
4239
+ if (field.oneof) {
4240
+ const group = input[field.oneof]; // this is the oneof`s group in the source
4241
+ if (group == undefined) { // the user is free to omit
4242
+ continue; // we skip this field, and all other members too
4243
+ }
4244
+ fieldValue = group[name]; // our value comes from the the oneof group of the source
4245
+ output = target[field.oneof]; // and our output is the oneof group of the target
4246
+ output.oneofKind = group.oneofKind; // always update discriminator
4247
+ if (fieldValue == undefined) {
4248
+ delete output[name]; // remove any existing value
4249
+ continue; // skip further work on field
4250
+ }
4251
+ }
4252
+ else {
4253
+ fieldValue = input[name]; // we are using the source directly
4254
+ output = target; // we want our field value to go directly into the target
4255
+ if (fieldValue == undefined) {
4256
+ continue; // skip further work on field, existing value is used as is
4257
+ }
4258
+ }
4259
+ // now we just work with `fieldValue` and `output` to merge the value
4260
+ switch (field.kind) {
4261
+ case "scalar":
4262
+ case "enum":
4263
+ if (field.repeat)
4264
+ output[name] = fieldValue.concat(); // elements are not reference types
4265
+ else
4266
+ output[name] = fieldValue; // not a reference type
4267
+ break;
4268
+ case "message":
4269
+ let T = field.T();
4270
+ if (field.repeat)
4271
+ for (let i = 0; i < fieldValue.length; i++)
4272
+ output[name][i] = T.create(fieldValue[i]);
4273
+ else if (output[name] === undefined)
4274
+ output[name] = T.create(fieldValue); // nothing to merge with
4275
+ else
4276
+ T.mergePartial(output[name], fieldValue);
4277
+ break;
4278
+ case "map":
4279
+ // Map and repeated fields are simply overwritten, not appended or merged
4280
+ switch (field.V.kind) {
4281
+ case "scalar":
4282
+ case "enum":
4283
+ Object.assign(output[name], fieldValue); // elements are not reference types
4284
+ break;
4285
+ case "message":
4286
+ let T = field.V.T();
4287
+ for (let k of Object.keys(fieldValue))
4288
+ output[name][k] = T.create(fieldValue[k]);
4289
+ break;
4290
+ }
4291
+ break;
4292
+ }
4293
+ }
4294
+ }
4295
+
4296
+ /**
4297
+ * Determines whether two message of the same type have the same field values.
4298
+ * Checks for deep equality, traversing repeated fields, oneof groups, maps
4299
+ * and messages recursively.
4300
+ * Will also return true if both messages are `undefined`.
4301
+ */
4302
+ function reflectionEquals(info, a, b) {
4303
+ if (a === b)
4304
+ return true;
4305
+ if (!a || !b)
4306
+ return false;
4307
+ for (let field of info.fields) {
4308
+ let localName = field.localName;
4309
+ let val_a = field.oneof ? a[field.oneof][localName] : a[localName];
4310
+ let val_b = field.oneof ? b[field.oneof][localName] : b[localName];
4311
+ switch (field.kind) {
4312
+ case "enum":
4313
+ case "scalar":
4314
+ let t = field.kind == "enum" ? ScalarType.INT32 : field.T;
4315
+ if (!(field.repeat
4316
+ ? repeatedPrimitiveEq(t, val_a, val_b)
4317
+ : primitiveEq(t, val_a, val_b)))
4318
+ return false;
4319
+ break;
4320
+ case "map":
4321
+ if (!(field.V.kind == "message"
4322
+ ? repeatedMsgEq(field.V.T(), objectValues(val_a), objectValues(val_b))
4323
+ : repeatedPrimitiveEq(field.V.kind == "enum" ? ScalarType.INT32 : field.V.T, objectValues(val_a), objectValues(val_b))))
4324
+ return false;
4325
+ break;
4326
+ case "message":
4327
+ let T = field.T();
4328
+ if (!(field.repeat
4329
+ ? repeatedMsgEq(T, val_a, val_b)
4330
+ : T.equals(val_a, val_b)))
4331
+ return false;
4332
+ break;
4333
+ }
4334
+ }
4335
+ return true;
4336
+ }
4337
+ const objectValues = Object.values;
4338
+ function primitiveEq(type, a, b) {
4339
+ if (a === b)
4340
+ return true;
4341
+ if (type !== ScalarType.BYTES)
4342
+ return false;
4343
+ let ba = a;
4344
+ let bb = b;
4345
+ if (ba.length !== bb.length)
4346
+ return false;
4347
+ for (let i = 0; i < ba.length; i++)
4348
+ if (ba[i] != bb[i])
4349
+ return false;
4350
+ return true;
4351
+ }
4352
+ function repeatedPrimitiveEq(type, a, b) {
4353
+ if (a.length !== b.length)
4354
+ return false;
4355
+ for (let i = 0; i < a.length; i++)
4356
+ if (!primitiveEq(type, a[i], b[i]))
4357
+ return false;
4358
+ return true;
4359
+ }
4360
+ function repeatedMsgEq(type, a, b) {
4361
+ if (a.length !== b.length)
4362
+ return false;
4363
+ for (let i = 0; i < a.length; i++)
4364
+ if (!type.equals(a[i], b[i]))
4365
+ return false;
4366
+ return true;
4367
+ }
4368
+
4369
+ /**
4370
+ * This standard message type provides reflection-based
4371
+ * operations to work with a message.
4372
+ */
4373
+ class MessageType {
4374
+ constructor(name, fields, options) {
4375
+ this.defaultCheckDepth = 16;
4376
+ this.typeName = name;
4377
+ this.fields = fields.map(normalizeFieldInfo);
4378
+ this.options = options !== null && options !== void 0 ? options : {};
4379
+ this.refTypeCheck = new ReflectionTypeCheck(this);
4380
+ this.refJsonReader = new ReflectionJsonReader(this);
4381
+ this.refJsonWriter = new ReflectionJsonWriter(this);
4382
+ this.refBinReader = new ReflectionBinaryReader(this);
4383
+ this.refBinWriter = new ReflectionBinaryWriter(this);
4384
+ }
4385
+ create(value) {
4386
+ let message = reflectionCreate(this);
4387
+ if (value !== undefined) {
4388
+ reflectionMergePartial(this, message, value);
4389
+ }
4390
+ return message;
4391
+ }
4392
+ /**
4393
+ * Clone the message.
4394
+ *
4395
+ * Unknown fields are discarded.
4396
+ */
4397
+ clone(message) {
4398
+ let copy = this.create();
4399
+ reflectionMergePartial(this, copy, message);
4400
+ return copy;
4401
+ }
4402
+ /**
4403
+ * Determines whether two message of the same type have the same field values.
4404
+ * Checks for deep equality, traversing repeated fields, oneof groups, maps
4405
+ * and messages recursively.
4406
+ * Will also return true if both messages are `undefined`.
4407
+ */
4408
+ equals(a, b) {
4409
+ return reflectionEquals(this, a, b);
4410
+ }
4411
+ /**
4412
+ * Is the given value assignable to our message type
4413
+ * and contains no [excess properties](https://www.typescriptlang.org/docs/handbook/interfaces.html#excess-property-checks)?
4414
+ */
4415
+ is(arg, depth = this.defaultCheckDepth) {
4416
+ return this.refTypeCheck.is(arg, depth, false);
4417
+ }
4418
+ /**
4419
+ * Is the given value assignable to our message type,
4420
+ * regardless of [excess properties](https://www.typescriptlang.org/docs/handbook/interfaces.html#excess-property-checks)?
4421
+ */
4422
+ isAssignable(arg, depth = this.defaultCheckDepth) {
4423
+ return this.refTypeCheck.is(arg, depth, true);
4424
+ }
4425
+ /**
4426
+ * Copy partial data into the target message.
4427
+ */
4428
+ mergePartial(target, source) {
4429
+ reflectionMergePartial(this, target, source);
4430
+ }
4431
+ /**
4432
+ * Create a new message from binary format.
4433
+ */
4434
+ fromBinary(data, options) {
4435
+ let opt = binaryReadOptions(options);
4436
+ return this.internalBinaryRead(opt.readerFactory(data), data.byteLength, opt);
4437
+ }
4438
+ /**
4439
+ * Read a new message from a JSON value.
4440
+ */
4441
+ fromJson(json, options) {
4442
+ return this.internalJsonRead(json, jsonReadOptions(options));
4443
+ }
4444
+ /**
4445
+ * Read a new message from a JSON string.
4446
+ * This is equivalent to `T.fromJson(JSON.parse(json))`.
4447
+ */
4448
+ fromJsonString(json, options) {
4449
+ let value = JSON.parse(json);
4450
+ return this.fromJson(value, options);
4451
+ }
4452
+ /**
4453
+ * Write the message to canonical JSON value.
4454
+ */
4455
+ toJson(message, options) {
4456
+ return this.internalJsonWrite(message, jsonWriteOptions(options));
4457
+ }
4458
+ /**
4459
+ * Convert the message to canonical JSON string.
4460
+ * This is equivalent to `JSON.stringify(T.toJson(t))`
4461
+ */
4462
+ toJsonString(message, options) {
4463
+ var _a;
4464
+ let value = this.toJson(message, options);
4465
+ return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
4466
+ }
4467
+ /**
4468
+ * Write the message to binary format.
4469
+ */
4470
+ toBinary(message, options) {
4471
+ let opt = binaryWriteOptions(options);
4472
+ return this.internalBinaryWrite(message, opt.writerFactory(), opt).finish();
4473
+ }
4474
+ /**
4475
+ * This is an internal method. If you just want to read a message from
4476
+ * JSON, use `fromJson()` or `fromJsonString()`.
4477
+ *
4478
+ * Reads JSON value and merges the fields into the target
4479
+ * according to protobuf rules. If the target is omitted,
4480
+ * a new instance is created first.
4481
+ */
4482
+ internalJsonRead(json, options, target) {
4483
+ if (json !== null && typeof json == "object" && !Array.isArray(json)) {
4484
+ let message = target !== null && target !== void 0 ? target : this.create();
4485
+ this.refJsonReader.read(json, message, options);
4486
+ return message;
4487
+ }
4488
+ throw new Error(`Unable to parse message ${this.typeName} from JSON ${typeofJsonValue(json)}.`);
4489
+ }
4490
+ /**
4491
+ * This is an internal method. If you just want to write a message
4492
+ * to JSON, use `toJson()` or `toJsonString().
4493
+ *
4494
+ * Writes JSON value and returns it.
4495
+ */
4496
+ internalJsonWrite(message, options) {
4497
+ return this.refJsonWriter.write(message, options);
4498
+ }
4499
+ /**
4500
+ * This is an internal method. If you just want to write a message
4501
+ * in binary format, use `toBinary()`.
4502
+ *
4503
+ * Serializes the message in binary format and appends it to the given
4504
+ * writer. Returns passed writer.
4505
+ */
4506
+ internalBinaryWrite(message, writer, options) {
4507
+ this.refBinWriter.write(message, writer, options);
4508
+ return writer;
4509
+ }
4510
+ /**
4511
+ * This is an internal method. If you just want to read a message from
4512
+ * binary data, use `fromBinary()`.
4513
+ *
4514
+ * Reads data from binary format and merges the fields into
4515
+ * the target according to protobuf rules. If the target is
4516
+ * omitted, a new instance is created first.
4517
+ */
4518
+ internalBinaryRead(reader, length, options, target) {
4519
+ let message = target !== null && target !== void 0 ? target : this.create();
4520
+ this.refBinReader.read(reader, message, options, length);
4521
+ return message;
4522
+ }
4523
+ }
4524
+
4525
+ /**
4526
+ * `NullValue` is a singleton enumeration to represent the null value for the
4527
+ * `Value` type union.
4528
+ *
4529
+ * The JSON representation for `NullValue` is JSON `null`.
4530
+ *
4531
+ * @generated from protobuf enum google.protobuf.NullValue
4532
+ */var NullValue;(function(a){/**
4533
+ * Null value.
4534
+ *
4535
+ * @generated from protobuf enum value: NULL_VALUE = 0;
4536
+ */a[a.NULL_VALUE=0]="NULL_VALUE";})(NullValue||(NullValue={}));// @generated message type with reflection information, may provide speed optimized methods
4537
+ class Struct$Type extends MessageType{constructor(){super("google.protobuf.Struct",[{no:1,name:"fields",kind:"map",K:9/*ScalarType.STRING*/,V:{kind:"message",T:()=>Value}}]);}/**
4538
+ * Encode `Struct` to JSON object.
4539
+ */internalJsonWrite(a){let b={};for(let[c,d]of Object.entries(a.fields))b[c]=Value.toJson(d);return b}/**
4540
+ * Decode `Struct` from JSON object.
4541
+ */internalJsonRead(a,b,c){if(!isJsonObject(a))throw new globalThis.Error("Unable to parse message "+this.typeName+" from JSON "+typeofJsonValue(a)+".");c||(c=this.create());for(let[d,e]of globalThis.Object.entries(a))c.fields[d]=Value.fromJson(e);return c}create(a){const b={fields:{}};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* map<string, google.protobuf.Value> fields */1:this.binaryReadMap1(e.fields,a,c);break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}binaryReadMap1(a,b,c){let d,e,f=b.uint32(),g=b.pos+f;for(;b.pos<g;){let[a,f]=b.tag();switch(a){case 1:d=b.string();break;case 2:e=Value.internalBinaryRead(b,b.uint32(),c);break;default:throw new globalThis.Error("unknown map entry field for field google.protobuf.Struct.fields");}}a[null!==d&&void 0!==d?d:""]=null!==e&&void 0!==e?e:Value.create();}internalBinaryWrite(a,b,c){/* map<string, google.protobuf.Value> fields = 1; */for(let d of Object.keys(a.fields))b.tag(1,WireType.LengthDelimited).fork().tag(1,WireType.LengthDelimited).string(d),b.tag(2,WireType.LengthDelimited).fork(),Value.internalBinaryWrite(a.fields[d],b,c),b.join().join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4542
+ * @generated MessageType for protobuf message google.protobuf.Struct
4543
+ */const Struct=new Struct$Type;// @generated message type with reflection information, may provide speed optimized methods
4544
+ class Value$Type extends MessageType{constructor(){super("google.protobuf.Value",[{no:1,name:"null_value",kind:"enum",oneof:"kind",T:()=>["google.protobuf.NullValue",NullValue]},{no:2,name:"number_value",kind:"scalar",oneof:"kind",T:1/*ScalarType.DOUBLE*/},{no:3,name:"string_value",kind:"scalar",oneof:"kind",T:9/*ScalarType.STRING*/},{no:4,name:"bool_value",kind:"scalar",oneof:"kind",T:8/*ScalarType.BOOL*/},{no:5,name:"struct_value",kind:"message",oneof:"kind",T:()=>Struct},{no:6,name:"list_value",kind:"message",oneof:"kind",T:()=>ListValue}]);}/**
4545
+ * Encode `Value` to JSON value.
4546
+ */internalJsonWrite(a){if(a.kind.oneofKind===void 0)throw new globalThis.Error;switch(a.kind.oneofKind){case void 0:throw new globalThis.Error;case"boolValue":return a.kind.boolValue;case"nullValue":return null;case"numberValue":return a.kind.numberValue;case"stringValue":return a.kind.stringValue;case"listValue":let b=this.fields.find(a=>6===a.no);if("message"!==(null===b||void 0===b?void 0:b.kind))throw new globalThis.Error;return b.T().toJson(a.kind.listValue);case"structValue":let c=this.fields.find(a=>5===a.no);if("message"!==(null===c||void 0===c?void 0:c.kind))throw new globalThis.Error;return c.T().toJson(a.kind.structValue);}}/**
4547
+ * Decode `Value` from JSON value.
4548
+ */internalJsonRead(a,b,c){switch(c||(c=this.create()),typeof a){case"number":c.kind={oneofKind:"numberValue",numberValue:a};break;case"string":c.kind={oneofKind:"stringValue",stringValue:a};break;case"boolean":c.kind={oneofKind:"boolValue",boolValue:a};break;case"object":if(null===a)c.kind={oneofKind:"nullValue",nullValue:NullValue.NULL_VALUE};else if(globalThis.Array.isArray(a))c.kind={oneofKind:"listValue",listValue:ListValue.fromJson(a)};else {Struct.fromJson(a);c.kind={oneofKind:"structValue",structValue:Struct.fromJson(a)};}break;default:throw new globalThis.Error("Unable to parse "+this.typeName+" from JSON "+typeofJsonValue(a));}return c}create(a){const b={kind:{oneofKind:void 0}};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* google.protobuf.NullValue null_value */1:e.kind={oneofKind:"nullValue",nullValue:a.int32()};break;case/* double number_value */2:e.kind={oneofKind:"numberValue",numberValue:a.double()};break;case/* string string_value */3:e.kind={oneofKind:"stringValue",stringValue:a.string()};break;case/* bool bool_value */4:e.kind={oneofKind:"boolValue",boolValue:a.bool()};break;case/* google.protobuf.Struct struct_value */5:e.kind={oneofKind:"structValue",structValue:Struct.internalBinaryRead(a,a.uint32(),c,e.kind.structValue)};break;case/* google.protobuf.ListValue list_value */6:e.kind={oneofKind:"listValue",listValue:ListValue.internalBinaryRead(a,a.uint32(),c,e.kind.listValue)};break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){"nullValue"===a.kind.oneofKind&&b.tag(1,WireType.Varint).int32(a.kind.nullValue),"numberValue"===a.kind.oneofKind&&b.tag(2,WireType.Bit64).double(a.kind.numberValue),"stringValue"===a.kind.oneofKind&&b.tag(3,WireType.LengthDelimited).string(a.kind.stringValue),"boolValue"===a.kind.oneofKind&&b.tag(4,WireType.Varint).bool(a.kind.boolValue),"structValue"===a.kind.oneofKind&&Struct.internalBinaryWrite(a.kind.structValue,b.tag(5,WireType.LengthDelimited).fork(),c).join(),"listValue"===a.kind.oneofKind&&ListValue.internalBinaryWrite(a.kind.listValue,b.tag(6,WireType.LengthDelimited).fork(),c).join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4549
+ * @generated MessageType for protobuf message google.protobuf.Value
4550
+ */const Value=new Value$Type;// @generated message type with reflection information, may provide speed optimized methods
4551
+ class ListValue$Type extends MessageType{constructor(){super("google.protobuf.ListValue",[{no:1,name:"values",kind:"message",repeat:1/*RepeatType.PACKED*/,T:()=>Value}]);}/**
4552
+ * Encode `ListValue` to JSON array.
4553
+ */internalJsonWrite(a){return a.values.map(a=>Value.toJson(a))}/**
4554
+ * Decode `ListValue` from JSON array.
4555
+ */internalJsonRead(a,b,c){if(!globalThis.Array.isArray(a))throw new globalThis.Error("Unable to parse "+this.typeName+" from JSON "+typeofJsonValue(a));c||(c=this.create());let d=a.map(a=>Value.fromJson(a));return c.values.push(...d),c}create(a){const b={values:[]};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* repeated google.protobuf.Value values */1:e.values.push(Value.internalBinaryRead(a,a.uint32(),c));break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){/* repeated google.protobuf.Value values = 1; */for(let d=0;d<a.values.length;d++)Value.internalBinaryWrite(a.values[d],b.tag(1,WireType.LengthDelimited).fork(),c).join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4556
+ * @generated MessageType for protobuf message google.protobuf.ListValue
4557
+ */const ListValue=new ListValue$Type;
4558
+
4559
+ /**
4560
+ * Turns PartialMethodInfo into MethodInfo.
4561
+ */
4562
+ function normalizeMethodInfo(method, service) {
4563
+ var _a, _b, _c;
4564
+ let m = method;
4565
+ m.service = service;
4566
+ m.localName = (_a = m.localName) !== null && _a !== void 0 ? _a : lowerCamelCase(m.name);
4567
+ // noinspection PointlessBooleanExpressionJS
4568
+ m.serverStreaming = !!m.serverStreaming;
4569
+ // noinspection PointlessBooleanExpressionJS
4570
+ m.clientStreaming = !!m.clientStreaming;
4571
+ m.options = (_b = m.options) !== null && _b !== void 0 ? _b : {};
4572
+ m.idempotency = (_c = m.idempotency) !== null && _c !== void 0 ? _c : undefined;
4573
+ return m;
4574
+ }
4575
+
4576
+ class ServiceType {
4577
+ constructor(typeName, methods, options) {
4578
+ this.typeName = typeName;
4579
+ this.methods = methods.map(i => normalizeMethodInfo(i, this));
4580
+ this.options = options !== null && options !== void 0 ? options : {};
4581
+ }
4582
+ }
4583
+
4584
+ /**
4585
+ * Creates a "stack" of of all interceptors specified in the given `RpcOptions`.
4586
+ * Used by generated client implementations.
4587
+ * @internal
4588
+ */
4589
+ function stackIntercept(kind, transport, method, options, input) {
4590
+ var _a, _b, _c, _d;
4591
+ if (kind == "unary") {
4592
+ let tail = (mtd, inp, opt) => transport.unary(mtd, inp, opt);
4593
+ for (const curr of ((_a = options.interceptors) !== null && _a !== void 0 ? _a : []).filter(i => i.interceptUnary).reverse()) {
4594
+ const next = tail;
4595
+ tail = (mtd, inp, opt) => curr.interceptUnary(next, mtd, inp, opt);
4596
+ }
4597
+ return tail(method, input, options);
4598
+ }
4599
+ if (kind == "serverStreaming") {
4600
+ let tail = (mtd, inp, opt) => transport.serverStreaming(mtd, inp, opt);
4601
+ for (const curr of ((_b = options.interceptors) !== null && _b !== void 0 ? _b : []).filter(i => i.interceptServerStreaming).reverse()) {
4602
+ const next = tail;
4603
+ tail = (mtd, inp, opt) => curr.interceptServerStreaming(next, mtd, inp, opt);
4604
+ }
4605
+ return tail(method, input, options);
4606
+ }
4607
+ if (kind == "clientStreaming") {
4608
+ let tail = (mtd, opt) => transport.clientStreaming(mtd, opt);
4609
+ for (const curr of ((_c = options.interceptors) !== null && _c !== void 0 ? _c : []).filter(i => i.interceptClientStreaming).reverse()) {
4610
+ const next = tail;
4611
+ tail = (mtd, opt) => curr.interceptClientStreaming(next, mtd, opt);
4612
+ }
4613
+ return tail(method, options);
4614
+ }
4615
+ if (kind == "duplex") {
4616
+ let tail = (mtd, opt) => transport.duplex(mtd, opt);
4617
+ for (const curr of ((_d = options.interceptors) !== null && _d !== void 0 ? _d : []).filter(i => i.interceptDuplex).reverse()) {
4618
+ const next = tail;
4619
+ tail = (mtd, opt) => curr.interceptDuplex(next, mtd, opt);
4620
+ }
4621
+ return tail(method, options);
4622
+ }
4623
+ assertNever(kind);
4624
+ }
4625
+
4626
+ class ErrorResponse$Type extends MessageType{constructor(){super("schema.v1.ErrorResponse",[{no:1,name:"error_code",kind:"scalar",T:9/*ScalarType.STRING*/},{no:2,name:"reason",kind:"scalar",T:9/*ScalarType.STRING*/}]);}create(a){const b={errorCode:"",reason:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* string error_code */1:e.errorCode=a.string();break;case/* string reason */2:e.reason=a.string();break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){""!==a.errorCode&&b.tag(1,WireType.LengthDelimited).string(a.errorCode),""!==a.reason&&b.tag(2,WireType.LengthDelimited).string(a.reason);let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4627
+ * @generated MessageType for protobuf message schema.v1.ErrorResponse
4628
+ */new ErrorResponse$Type;// @generated message type with reflection information, may provide speed optimized methods
4629
+ class ResolveBooleanRequest$Type extends MessageType{constructor(){super("schema.v1.ResolveBooleanRequest",[{no:1,name:"flag_key",kind:"scalar",T:9/*ScalarType.STRING*/},{no:2,name:"context",kind:"message",T:()=>Struct}]);}create(a){const b={flagKey:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* string flag_key */1:e.flagKey=a.string();break;case/* google.protobuf.Struct context */2:e.context=Struct.internalBinaryRead(a,a.uint32(),c,e.context);break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){""!==a.flagKey&&b.tag(1,WireType.LengthDelimited).string(a.flagKey),a.context&&Struct.internalBinaryWrite(a.context,b.tag(2,WireType.LengthDelimited).fork(),c).join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4630
+ * @generated MessageType for protobuf message schema.v1.ResolveBooleanRequest
4631
+ */const ResolveBooleanRequest=new ResolveBooleanRequest$Type;// @generated message type with reflection information, may provide speed optimized methods
4632
+ class ResolveBooleanResponse$Type extends MessageType{constructor(){super("schema.v1.ResolveBooleanResponse",[{no:1,name:"value",kind:"scalar",T:8/*ScalarType.BOOL*/},{no:2,name:"reason",kind:"scalar",T:9/*ScalarType.STRING*/},{no:3,name:"variant",kind:"scalar",T:9/*ScalarType.STRING*/}]);}create(a){const b={value:!1,reason:"",variant:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* bool value */1:e.value=a.bool();break;case/* string reason */2:e.reason=a.string();break;case/* string variant */3:e.variant=a.string();break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){!1!==a.value&&b.tag(1,WireType.Varint).bool(a.value),""!==a.reason&&b.tag(2,WireType.LengthDelimited).string(a.reason),""!==a.variant&&b.tag(3,WireType.LengthDelimited).string(a.variant);let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4633
+ * @generated MessageType for protobuf message schema.v1.ResolveBooleanResponse
4634
+ */const ResolveBooleanResponse=new ResolveBooleanResponse$Type;// @generated message type with reflection information, may provide speed optimized methods
4635
+ class ResolveStringRequest$Type extends MessageType{constructor(){super("schema.v1.ResolveStringRequest",[{no:1,name:"flag_key",kind:"scalar",T:9/*ScalarType.STRING*/},{no:2,name:"context",kind:"message",T:()=>Struct}]);}create(a){const b={flagKey:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* string flag_key */1:e.flagKey=a.string();break;case/* google.protobuf.Struct context */2:e.context=Struct.internalBinaryRead(a,a.uint32(),c,e.context);break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){""!==a.flagKey&&b.tag(1,WireType.LengthDelimited).string(a.flagKey),a.context&&Struct.internalBinaryWrite(a.context,b.tag(2,WireType.LengthDelimited).fork(),c).join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4636
+ * @generated MessageType for protobuf message schema.v1.ResolveStringRequest
4637
+ */const ResolveStringRequest=new ResolveStringRequest$Type;// @generated message type with reflection information, may provide speed optimized methods
4638
+ class ResolveStringResponse$Type extends MessageType{constructor(){super("schema.v1.ResolveStringResponse",[{no:1,name:"value",kind:"scalar",T:9/*ScalarType.STRING*/},{no:2,name:"reason",kind:"scalar",T:9/*ScalarType.STRING*/},{no:3,name:"variant",kind:"scalar",T:9/*ScalarType.STRING*/}]);}create(a){const b={value:"",reason:"",variant:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* string value */1:e.value=a.string();break;case/* string reason */2:e.reason=a.string();break;case/* string variant */3:e.variant=a.string();break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){""!==a.value&&b.tag(1,WireType.LengthDelimited).string(a.value),""!==a.reason&&b.tag(2,WireType.LengthDelimited).string(a.reason),""!==a.variant&&b.tag(3,WireType.LengthDelimited).string(a.variant);let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4639
+ * @generated MessageType for protobuf message schema.v1.ResolveStringResponse
4640
+ */const ResolveStringResponse=new ResolveStringResponse$Type;// @generated message type with reflection information, may provide speed optimized methods
4641
+ class ResolveNumberRequest$Type extends MessageType{constructor(){super("schema.v1.ResolveNumberRequest",[{no:1,name:"flag_key",kind:"scalar",T:9/*ScalarType.STRING*/},{no:2,name:"context",kind:"message",T:()=>Struct}]);}create(a){const b={flagKey:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* string flag_key */1:e.flagKey=a.string();break;case/* google.protobuf.Struct context */2:e.context=Struct.internalBinaryRead(a,a.uint32(),c,e.context);break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){""!==a.flagKey&&b.tag(1,WireType.LengthDelimited).string(a.flagKey),a.context&&Struct.internalBinaryWrite(a.context,b.tag(2,WireType.LengthDelimited).fork(),c).join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4642
+ * @generated MessageType for protobuf message schema.v1.ResolveNumberRequest
4643
+ */const ResolveNumberRequest=new ResolveNumberRequest$Type;// @generated message type with reflection information, may provide speed optimized methods
4644
+ class ResolveNumberResponse$Type extends MessageType{constructor(){super("schema.v1.ResolveNumberResponse",[{no:1,name:"value",kind:"scalar",T:2/*ScalarType.FLOAT*/},{no:2,name:"reason",kind:"scalar",T:9/*ScalarType.STRING*/},{no:3,name:"variant",kind:"scalar",T:9/*ScalarType.STRING*/}]);}create(a){const b={value:0,reason:"",variant:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* float value */1:e.value=a.float();break;case/* string reason */2:e.reason=a.string();break;case/* string variant */3:e.variant=a.string();break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){0!==a.value&&b.tag(1,WireType.Bit32).float(a.value),""!==a.reason&&b.tag(2,WireType.LengthDelimited).string(a.reason),""!==a.variant&&b.tag(3,WireType.LengthDelimited).string(a.variant);let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4645
+ * @generated MessageType for protobuf message schema.v1.ResolveNumberResponse
4646
+ */const ResolveNumberResponse=new ResolveNumberResponse$Type;// @generated message type with reflection information, may provide speed optimized methods
4647
+ class ResolveObjectRequest$Type extends MessageType{constructor(){super("schema.v1.ResolveObjectRequest",[{no:1,name:"flag_key",kind:"scalar",T:9/*ScalarType.STRING*/},{no:2,name:"context",kind:"message",T:()=>Struct}]);}create(a){const b={flagKey:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* string flag_key */1:e.flagKey=a.string();break;case/* google.protobuf.Struct context */2:e.context=Struct.internalBinaryRead(a,a.uint32(),c,e.context);break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){""!==a.flagKey&&b.tag(1,WireType.LengthDelimited).string(a.flagKey),a.context&&Struct.internalBinaryWrite(a.context,b.tag(2,WireType.LengthDelimited).fork(),c).join();let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4648
+ * @generated MessageType for protobuf message schema.v1.ResolveObjectRequest
4649
+ */const ResolveObjectRequest=new ResolveObjectRequest$Type;// @generated message type with reflection information, may provide speed optimized methods
4650
+ class ResolveObjectResponse$Type extends MessageType{constructor(){super("schema.v1.ResolveObjectResponse",[{no:1,name:"value",kind:"message",T:()=>Struct},{no:2,name:"reason",kind:"scalar",T:9/*ScalarType.STRING*/},{no:3,name:"variant",kind:"scalar",T:9/*ScalarType.STRING*/}]);}create(a){const b={reason:"",variant:""};return globalThis.Object.defineProperty(b,MESSAGE_TYPE,{enumerable:!1,value:this}),void 0!==a&&reflectionMergePartial(this,b,a),b}internalBinaryRead(a,b,c,d){let e=null!==d&&void 0!==d?d:this.create(),f=a.pos+b;for(;a.pos<f;){let[b,f]=a.tag();switch(b){case/* google.protobuf.Struct value */1:e.value=Struct.internalBinaryRead(a,a.uint32(),c,e.value);break;case/* string reason */2:e.reason=a.string();break;case/* string variant */3:e.variant=a.string();break;default:let g=c.readUnknownField;if("throw"===g)throw new globalThis.Error(`Unknown field ${b} (wire type ${f}) for ${this.typeName}`);let h=a.skip(f);!1!==g&&(!0===g?UnknownFieldHandler.onRead:g)(this.typeName,e,b,f,h);}}return e}internalBinaryWrite(a,b,c){a.value&&Struct.internalBinaryWrite(a.value,b.tag(1,WireType.LengthDelimited).fork(),c).join(),""!==a.reason&&b.tag(2,WireType.LengthDelimited).string(a.reason),""!==a.variant&&b.tag(3,WireType.LengthDelimited).string(a.variant);let d=c.writeUnknownFields;return !1!==d&&(!0==d?UnknownFieldHandler.onWrite:d)(this.typeName,a,b),b}}/**
4651
+ * @generated MessageType for protobuf message schema.v1.ResolveObjectResponse
4652
+ */const ResolveObjectResponse=new ResolveObjectResponse$Type;/**
4653
+ * @generated ServiceType for protobuf service schema.v1.Service
4654
+ */const Service=new ServiceType("schema.v1.Service",[{name:"ResolveBoolean",options:{"google.api.http":{post:"/flags/{flag_key}/resolve/boolean",body:"context"}},I:ResolveBooleanRequest,O:ResolveBooleanResponse},{name:"ResolveString",options:{"google.api.http":{post:"/flags/{flag_key}/resolve/string",body:"context"}},I:ResolveStringRequest,O:ResolveStringResponse},{name:"ResolveNumber",options:{"google.api.http":{post:"/flags/{flag_key}/resolve/number",body:"context"}},I:ResolveNumberRequest,O:ResolveNumberResponse},{name:"ResolveObject",options:{"google.api.http":{post:"/flags/{flag_key}/resolve/object",body:"context"}},I:ResolveObjectRequest,O:ResolveObjectResponse}]);
4655
+
4656
+ /**
4657
+ * @generated from protobuf service schema.v1.Service
4658
+ */class ServiceClient{constructor(a){this._transport=a,this.typeName=Service.typeName,this.methods=Service.methods,this.options=Service.options;}/**
4659
+ * @generated from protobuf rpc: ResolveBoolean(schema.v1.ResolveBooleanRequest) returns (schema.v1.ResolveBooleanResponse);
4660
+ */resolveBoolean(a,b){const c=this.methods[0],d=this._transport.mergeOptions(b);return stackIntercept("unary",this._transport,c,d,a)}/**
4661
+ * @generated from protobuf rpc: ResolveString(schema.v1.ResolveStringRequest) returns (schema.v1.ResolveStringResponse);
4662
+ */resolveString(a,b){const c=this.methods[1],d=this._transport.mergeOptions(b);return stackIntercept("unary",this._transport,c,d,a)}/**
4663
+ * @generated from protobuf rpc: ResolveNumber(schema.v1.ResolveNumberRequest) returns (schema.v1.ResolveNumberResponse);
4664
+ */resolveNumber(a,b){const c=this.methods[2],d=this._transport.mergeOptions(b);return stackIntercept("unary",this._transport,c,d,a)}/**
4665
+ * @generated from protobuf rpc: ResolveObject(schema.v1.ResolveObjectRequest) returns (schema.v1.ResolveObjectResponse);
4666
+ */resolveObject(a,b){const c=this.methods[3],d=this._transport.mergeOptions(b);return stackIntercept("unary",this._transport,c,d,a)}}
4667
+
4668
+ class GRPCService{constructor(a){const{host:b,port:c}=a;this.client=new ServiceClient(new GrpcTransport({host:`${b}:${c}`,channelCredentials:grpc.credentials.createInsecure()}));}resolveBoolean(a,b,c){var d;return __awaiter(this,void 0,void 0,function*(){try{const{response:b}=yield this.client.resolveBoolean({flagKey:a,context:Struct.fromJsonString(JSON.stringify(c))});return {value:b.value,reason:b.reason,variant:b.variant}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:null!==(d=null===a||void 0===a?void 0:a.code)&&void 0!==d?d:StandardResolutionReasons.UNKNOWN,value:b}}})}resolveString(a,b,c){var d;return __awaiter(this,void 0,void 0,function*(){try{const{response:b}=yield this.client.resolveString({flagKey:a,context:Struct.fromJsonString(JSON.stringify(c))});return {value:b.value,reason:b.reason,variant:b.variant}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:null!==(d=null===a||void 0===a?void 0:a.code)&&void 0!==d?d:StandardResolutionReasons.UNKNOWN,value:b}}})}resolveNumber(a,b,c){var d;return __awaiter(this,void 0,void 0,function*(){try{const{response:b}=yield this.client.resolveNumber({flagKey:a,context:Struct.fromJsonString(JSON.stringify(c))});return {value:b.value,reason:b.reason,variant:b.variant}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:null!==(d=null===a||void 0===a?void 0:a.code)&&void 0!==d?d:StandardResolutionReasons.UNKNOWN,value:b}}})}resolveObject(a,b,c){var d;return __awaiter(this,void 0,void 0,function*(){try{const{response:b}=yield this.client.resolveObject({flagKey:a,context:Struct.fromJsonString(JSON.stringify(c))});return {value:b.value,reason:b.reason,variant:b.variant}}catch(a){return {reason:StandardResolutionReasons.ERROR,errorCode:null!==(d=null===a||void 0===a?void 0:a.code)&&void 0!==d?d:StandardResolutionReasons.UNKNOWN,value:b}}})}}
4669
+
4670
+ class FlagdProvider{constructor(a){this.metadata={name:FlagdProvider.name};const{service:b,host:c,port:d,protocol:e}=Object.assign({service:"http",host:"localhost",port:8080,protocol:"http"},a);this.service="http"==b?new HTTPService({host:c,port:d,protocol:e}):new GRPCService({host:c,port:d});}resolveBooleanEvaluation(a,b,c){return this.service.resolveBoolean(a,b,c)}resolveStringEvaluation(a,b,c){return this.service.resolveString(a,b,c)}resolveNumberEvaluation(a,b,c){return this.service.resolveNumber(a,b,c)}resolveObjectEvaluation(a,b,c){return this.service.resolveObject(a,b,c)}}
4671
+
4672
+ export { FlagdProvider };