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