@openfeature/flagd-provider 0.13.3 → 0.14.0
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 +1 -1
- package/README.md +85 -2
- package/index.cjs.js +923 -860
- package/index.esm.js +925 -862
- package/package.json +8 -3
- package/src/lib/SyncMetadataHook.d.ts +6 -0
- package/src/lib/configuration.d.ts +64 -13
- package/src/lib/constants.d.ts +3 -0
- package/src/lib/flagd-provider.d.ts +13 -3
- package/src/lib/service/common/grpc-util.d.ts +47 -1
- package/src/lib/service/grpc/grpc-service.d.ts +17 -9
- package/src/lib/service/in-process/file/file-fetch.d.ts +2 -2
- package/src/lib/service/in-process/grpc/grpc-fetch.d.ts +11 -4
- package/src/lib/service/in-process/in-process-service.d.ts +5 -4
- package/src/lib/service/service.d.ts +2 -1
- package/src/proto/ts/flagd/evaluation/v2/evaluation.d.ts +362 -0
- package/src/proto/ts/flagd/sync/v1/sync.d.ts +24 -4
- package/src/proto/ts/sync/v1/sync_service.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -5,6 +5,7 @@ var grpcJs = require('@grpc/grpc-js');
|
|
|
5
5
|
var connectivityState = require('@grpc/grpc-js/build/src/connectivity-state');
|
|
6
6
|
var lruCache = require('lru-cache');
|
|
7
7
|
var node_util = require('node:util');
|
|
8
|
+
var node_fs = require('node:fs');
|
|
8
9
|
var flagdCore = require('@openfeature/flagd-core');
|
|
9
10
|
var fs = require('fs');
|
|
10
11
|
|
|
@@ -43,13 +44,23 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
43
44
|
const EVENT_CONFIGURATION_CHANGE = 'configuration_change';
|
|
44
45
|
const EVENT_PROVIDER_READY = 'provider_ready';
|
|
45
46
|
const DEFAULT_MAX_CACHE_SIZE = 1000;
|
|
47
|
+
const DEFAULT_RETRY_GRACE_PERIOD = 5;
|
|
48
|
+
const DEFAULT_MAX_BACKOFF_MS = 12000;
|
|
49
|
+
const FLAGD_SELECTOR_HEADER = 'flagd-selector';
|
|
46
50
|
|
|
47
51
|
const DEFAULT_CONFIG = {
|
|
52
|
+
deadlineMs: 500,
|
|
53
|
+
streamDeadlineMs: 600000,
|
|
48
54
|
host: 'localhost',
|
|
49
55
|
tls: false,
|
|
50
56
|
selector: '',
|
|
51
57
|
cache: 'lru',
|
|
52
58
|
maxCacheSize: DEFAULT_MAX_CACHE_SIZE,
|
|
59
|
+
contextEnricher: (syncContext) => syncContext !== null && syncContext !== void 0 ? syncContext : {},
|
|
60
|
+
retryBackoffMs: 1000,
|
|
61
|
+
retryBackoffMaxMs: DEFAULT_MAX_BACKOFF_MS,
|
|
62
|
+
keepAliveTime: 0,
|
|
63
|
+
retryGracePeriod: DEFAULT_RETRY_GRACE_PERIOD,
|
|
53
64
|
};
|
|
54
65
|
const DEFAULT_RPC_CONFIG = Object.assign(Object.assign({}, DEFAULT_CONFIG), { resolverType: 'rpc', port: 8013 });
|
|
55
66
|
const DEFAULT_IN_PROCESS_CONFIG = Object.assign(Object.assign({}, DEFAULT_CONFIG), { resolverType: 'in-process', port: 8015 });
|
|
@@ -57,45 +68,82 @@ var ENV_VAR;
|
|
|
57
68
|
(function (ENV_VAR) {
|
|
58
69
|
ENV_VAR["FLAGD_HOST"] = "FLAGD_HOST";
|
|
59
70
|
ENV_VAR["FLAGD_PORT"] = "FLAGD_PORT";
|
|
71
|
+
ENV_VAR["FLAGD_SYNC_PORT"] = "FLAGD_SYNC_PORT";
|
|
72
|
+
ENV_VAR["FLAGD_DEADLINE_MS"] = "FLAGD_DEADLINE_MS";
|
|
73
|
+
ENV_VAR["FLAGD_STREAM_DEADLINE_MS"] = "FLAGD_STREAM_DEADLINE_MS";
|
|
60
74
|
ENV_VAR["FLAGD_TLS"] = "FLAGD_TLS";
|
|
61
75
|
ENV_VAR["FLAGD_SOCKET_PATH"] = "FLAGD_SOCKET_PATH";
|
|
76
|
+
ENV_VAR["FLAGD_SERVER_CERT_PATH"] = "FLAGD_SERVER_CERT_PATH";
|
|
62
77
|
ENV_VAR["FLAGD_CACHE"] = "FLAGD_CACHE";
|
|
63
78
|
ENV_VAR["FLAGD_MAX_CACHE_SIZE"] = "FLAGD_MAX_CACHE_SIZE";
|
|
64
79
|
ENV_VAR["FLAGD_SOURCE_SELECTOR"] = "FLAGD_SOURCE_SELECTOR";
|
|
65
80
|
ENV_VAR["FLAGD_RESOLVER"] = "FLAGD_RESOLVER";
|
|
66
81
|
ENV_VAR["FLAGD_OFFLINE_FLAG_SOURCE_PATH"] = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
|
|
67
82
|
ENV_VAR["FLAGD_DEFAULT_AUTHORITY"] = "FLAGD_DEFAULT_AUTHORITY";
|
|
83
|
+
ENV_VAR["FLAGD_RETRY_BACKOFF_MS"] = "FLAGD_RETRY_BACKOFF_MS";
|
|
84
|
+
ENV_VAR["FLAGD_RETRY_BACKOFF_MAX_MS"] = "FLAGD_RETRY_BACKOFF_MAX_MS";
|
|
85
|
+
ENV_VAR["FLAGD_KEEP_ALIVE_TIME_MS"] = "FLAGD_KEEP_ALIVE_TIME_MS";
|
|
86
|
+
ENV_VAR["FLAGD_FATAL_STATUS_CODES"] = "FLAGD_FATAL_STATUS_CODES";
|
|
87
|
+
ENV_VAR["FLAGD_RETRY_GRACE_PERIOD"] = "FLAGD_RETRY_GRACE_PERIOD";
|
|
68
88
|
})(ENV_VAR || (ENV_VAR = {}));
|
|
69
|
-
|
|
89
|
+
function getEnvVarConfig() {
|
|
70
90
|
var _a;
|
|
71
|
-
|
|
91
|
+
let provider = undefined;
|
|
92
|
+
if (process.env[ENV_VAR.FLAGD_RESOLVER] &&
|
|
93
|
+
(process.env[ENV_VAR.FLAGD_RESOLVER].toLowerCase() === 'rpc' ||
|
|
94
|
+
process.env[ENV_VAR.FLAGD_RESOLVER].toLowerCase() === 'in-process')) {
|
|
95
|
+
provider = process.env[ENV_VAR.FLAGD_RESOLVER].toLowerCase();
|
|
96
|
+
}
|
|
97
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
72
98
|
host: process.env[ENV_VAR.FLAGD_HOST],
|
|
73
99
|
})), (Number(process.env[ENV_VAR.FLAGD_PORT]) && {
|
|
74
100
|
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
|
|
101
|
+
})), (Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]) && {
|
|
102
|
+
port: Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]),
|
|
103
|
+
})), (Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]) && {
|
|
104
|
+
deadlineMs: Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]),
|
|
105
|
+
})), (Number(process.env[ENV_VAR.FLAGD_STREAM_DEADLINE_MS]) && {
|
|
106
|
+
streamDeadlineMs: Number(process.env[ENV_VAR.FLAGD_STREAM_DEADLINE_MS]),
|
|
75
107
|
})), (process.env[ENV_VAR.FLAGD_TLS] && {
|
|
76
|
-
tls: ((_a = process.env[ENV_VAR.FLAGD_TLS]) === null || _a ===
|
|
108
|
+
tls: ((_a = process.env[ENV_VAR.FLAGD_TLS]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true',
|
|
77
109
|
})), (process.env[ENV_VAR.FLAGD_SOCKET_PATH] && {
|
|
78
110
|
socketPath: process.env[ENV_VAR.FLAGD_SOCKET_PATH],
|
|
111
|
+
})), (process.env[ENV_VAR.FLAGD_SERVER_CERT_PATH] && {
|
|
112
|
+
certPath: process.env[ENV_VAR.FLAGD_SERVER_CERT_PATH],
|
|
79
113
|
})), ((process.env[ENV_VAR.FLAGD_CACHE] === 'lru' || process.env[ENV_VAR.FLAGD_CACHE] === 'disabled') && {
|
|
80
114
|
cache: process.env[ENV_VAR.FLAGD_CACHE],
|
|
81
115
|
})), (process.env[ENV_VAR.FLAGD_MAX_CACHE_SIZE] && {
|
|
82
116
|
maxCacheSize: Number(process.env[ENV_VAR.FLAGD_MAX_CACHE_SIZE]),
|
|
83
117
|
})), (process.env[ENV_VAR.FLAGD_SOURCE_SELECTOR] && {
|
|
84
118
|
selector: process.env[ENV_VAR.FLAGD_SOURCE_SELECTOR],
|
|
85
|
-
})), (
|
|
86
|
-
resolverType:
|
|
119
|
+
})), (provider && {
|
|
120
|
+
resolverType: provider,
|
|
87
121
|
})), (process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH] && {
|
|
88
122
|
offlineFlagSourcePath: process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH],
|
|
89
123
|
})), (process.env[ENV_VAR.FLAGD_DEFAULT_AUTHORITY] && {
|
|
90
124
|
defaultAuthority: process.env[ENV_VAR.FLAGD_DEFAULT_AUTHORITY],
|
|
91
|
-
})))
|
|
92
|
-
|
|
125
|
+
})), (Number(process.env[ENV_VAR.FLAGD_RETRY_BACKOFF_MS]) && {
|
|
126
|
+
retryBackoffMs: Number(process.env[ENV_VAR.FLAGD_RETRY_BACKOFF_MS]),
|
|
127
|
+
})), (Number(process.env[ENV_VAR.FLAGD_RETRY_BACKOFF_MAX_MS]) && {
|
|
128
|
+
retryBackoffMaxMs: Number(process.env[ENV_VAR.FLAGD_RETRY_BACKOFF_MAX_MS]),
|
|
129
|
+
})), (Number(process.env[ENV_VAR.FLAGD_KEEP_ALIVE_TIME_MS]) && {
|
|
130
|
+
keepAliveTime: Number(process.env[ENV_VAR.FLAGD_KEEP_ALIVE_TIME_MS]),
|
|
131
|
+
})), (process.env[ENV_VAR.FLAGD_FATAL_STATUS_CODES] && {
|
|
132
|
+
fatalStatusCodes: process.env[ENV_VAR.FLAGD_FATAL_STATUS_CODES]
|
|
133
|
+
.split(',')
|
|
134
|
+
.map((code) => code.trim())
|
|
135
|
+
.filter((code) => code.length > 0),
|
|
136
|
+
})), (process.env[ENV_VAR.FLAGD_RETRY_GRACE_PERIOD] && {
|
|
137
|
+
retryGracePeriod: Number(process.env[ENV_VAR.FLAGD_RETRY_GRACE_PERIOD]),
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
93
140
|
function getConfig(options = {}) {
|
|
141
|
+
var _a, _b;
|
|
94
142
|
const envVarConfig = getEnvVarConfig();
|
|
95
143
|
const defaultConfig = options.resolverType == 'in-process' || envVarConfig.resolverType == 'in-process'
|
|
96
144
|
? DEFAULT_IN_PROCESS_CONFIG
|
|
97
145
|
: DEFAULT_RPC_CONFIG;
|
|
98
|
-
return Object.assign(Object.assign(Object.assign({}, defaultConfig), envVarConfig), options);
|
|
146
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, defaultConfig), envVarConfig), options), { streamDeadlineMs: (_b = (_a = options.streamDeadlineMs) !== null && _a !== void 0 ? _a : envVarConfig.streamDeadlineMs) !== null && _b !== void 0 ? _b : DEFAULT_CONFIG.streamDeadlineMs });
|
|
99
147
|
}
|
|
100
148
|
|
|
101
149
|
/**
|
|
@@ -121,10 +169,85 @@ function getConfig(options = {}) {
|
|
|
121
169
|
// WebAssembly optimizations to do native i64 multiplication and divide
|
|
122
170
|
var wasm = null;
|
|
123
171
|
try {
|
|
124
|
-
wasm = new WebAssembly.Instance(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
172
|
+
wasm = new WebAssembly.Instance(
|
|
173
|
+
new WebAssembly.Module(
|
|
174
|
+
new Uint8Array([
|
|
175
|
+
// \0asm
|
|
176
|
+
0, 97, 115, 109,
|
|
177
|
+
// version 1
|
|
178
|
+
1, 0, 0, 0,
|
|
179
|
+
|
|
180
|
+
// section "type"
|
|
181
|
+
1, 13, 2,
|
|
182
|
+
// 0, () => i32
|
|
183
|
+
96, 0, 1, 127,
|
|
184
|
+
// 1, (i32, i32, i32, i32) => i32
|
|
185
|
+
96, 4, 127, 127, 127, 127, 1, 127,
|
|
186
|
+
|
|
187
|
+
// section "function"
|
|
188
|
+
3, 7, 6,
|
|
189
|
+
// 0, type 0
|
|
190
|
+
0,
|
|
191
|
+
// 1, type 1
|
|
192
|
+
1,
|
|
193
|
+
// 2, type 1
|
|
194
|
+
1,
|
|
195
|
+
// 3, type 1
|
|
196
|
+
1,
|
|
197
|
+
// 4, type 1
|
|
198
|
+
1,
|
|
199
|
+
// 5, type 1
|
|
200
|
+
1,
|
|
201
|
+
|
|
202
|
+
// section "global"
|
|
203
|
+
6, 6, 1,
|
|
204
|
+
// 0, "high", mutable i32
|
|
205
|
+
127, 1, 65, 0, 11,
|
|
206
|
+
|
|
207
|
+
// section "export"
|
|
208
|
+
7, 50, 6,
|
|
209
|
+
// 0, "mul"
|
|
210
|
+
3, 109, 117, 108, 0, 1,
|
|
211
|
+
// 1, "div_s"
|
|
212
|
+
5, 100, 105, 118, 95, 115, 0, 2,
|
|
213
|
+
// 2, "div_u"
|
|
214
|
+
5, 100, 105, 118, 95, 117, 0, 3,
|
|
215
|
+
// 3, "rem_s"
|
|
216
|
+
5, 114, 101, 109, 95, 115, 0, 4,
|
|
217
|
+
// 4, "rem_u"
|
|
218
|
+
5, 114, 101, 109, 95, 117, 0, 5,
|
|
219
|
+
// 5, "get_high"
|
|
220
|
+
8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0,
|
|
221
|
+
|
|
222
|
+
// section "code"
|
|
223
|
+
10, 191, 1, 6,
|
|
224
|
+
// 0, "get_high"
|
|
225
|
+
4, 0, 35, 0, 11,
|
|
226
|
+
// 1, "mul"
|
|
227
|
+
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
|
228
|
+
3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
|
229
|
+
167, 11,
|
|
230
|
+
// 2, "div_s"
|
|
231
|
+
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
|
232
|
+
3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
|
233
|
+
167, 11,
|
|
234
|
+
// 3, "div_u"
|
|
235
|
+
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
|
236
|
+
3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
|
237
|
+
167, 11,
|
|
238
|
+
// 4, "rem_s"
|
|
239
|
+
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
|
240
|
+
3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
|
241
|
+
167, 11,
|
|
242
|
+
// 5, "rem_u"
|
|
243
|
+
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
|
244
|
+
3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
|
245
|
+
167, 11,
|
|
246
|
+
]),
|
|
247
|
+
),
|
|
248
|
+
{},
|
|
249
|
+
).exports;
|
|
250
|
+
} catch {
|
|
128
251
|
// no wasm support :(
|
|
129
252
|
}
|
|
130
253
|
|
|
@@ -139,7 +262,6 @@ try {
|
|
|
139
262
|
* @constructor
|
|
140
263
|
*/
|
|
141
264
|
function Long(low, high, unsigned) {
|
|
142
|
-
|
|
143
265
|
/**
|
|
144
266
|
* The low 32 bits as a signed value.
|
|
145
267
|
* @type {number}
|
|
@@ -239,25 +361,21 @@ function fromInt(value, unsigned) {
|
|
|
239
361
|
var obj, cachedObj, cache;
|
|
240
362
|
if (unsigned) {
|
|
241
363
|
value >>>= 0;
|
|
242
|
-
if (cache =
|
|
364
|
+
if ((cache = 0 <= value && value < 256)) {
|
|
243
365
|
cachedObj = UINT_CACHE[value];
|
|
244
|
-
if (cachedObj)
|
|
245
|
-
return cachedObj;
|
|
366
|
+
if (cachedObj) return cachedObj;
|
|
246
367
|
}
|
|
247
368
|
obj = fromBits(value, 0, true);
|
|
248
|
-
if (cache)
|
|
249
|
-
UINT_CACHE[value] = obj;
|
|
369
|
+
if (cache) UINT_CACHE[value] = obj;
|
|
250
370
|
return obj;
|
|
251
371
|
} else {
|
|
252
372
|
value |= 0;
|
|
253
|
-
if (cache =
|
|
373
|
+
if ((cache = -128 <= value && value < 128)) {
|
|
254
374
|
cachedObj = INT_CACHE[value];
|
|
255
|
-
if (cachedObj)
|
|
256
|
-
return cachedObj;
|
|
375
|
+
if (cachedObj) return cachedObj;
|
|
257
376
|
}
|
|
258
377
|
obj = fromBits(value, value < 0 ? -1 : 0, false);
|
|
259
|
-
if (cache)
|
|
260
|
-
INT_CACHE[value] = obj;
|
|
378
|
+
if (cache) INT_CACHE[value] = obj;
|
|
261
379
|
return obj;
|
|
262
380
|
}
|
|
263
381
|
}
|
|
@@ -278,22 +396,20 @@ Long.fromInt = fromInt;
|
|
|
278
396
|
* @inner
|
|
279
397
|
*/
|
|
280
398
|
function fromNumber(value, unsigned) {
|
|
281
|
-
if (isNaN(value))
|
|
282
|
-
return unsigned ? UZERO : ZERO;
|
|
399
|
+
if (isNaN(value)) return unsigned ? UZERO : ZERO;
|
|
283
400
|
if (unsigned) {
|
|
284
|
-
if (value < 0)
|
|
285
|
-
|
|
286
|
-
if (value >= TWO_PWR_64_DBL)
|
|
287
|
-
return MAX_UNSIGNED_VALUE;
|
|
401
|
+
if (value < 0) return UZERO;
|
|
402
|
+
if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
|
|
288
403
|
} else {
|
|
289
|
-
if (value <= -9223372036854776e3)
|
|
290
|
-
|
|
291
|
-
if (value + 1 >= TWO_PWR_63_DBL)
|
|
292
|
-
return MAX_VALUE;
|
|
404
|
+
if (value <= -9223372036854776e3) return MIN_VALUE;
|
|
405
|
+
if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
|
|
293
406
|
}
|
|
294
|
-
if (value < 0)
|
|
295
|
-
|
|
296
|
-
|
|
407
|
+
if (value < 0) return fromNumber(-value, unsigned).neg();
|
|
408
|
+
return fromBits(
|
|
409
|
+
value % TWO_PWR_32_DBL | 0,
|
|
410
|
+
(value / TWO_PWR_32_DBL) | 0,
|
|
411
|
+
unsigned,
|
|
412
|
+
);
|
|
297
413
|
}
|
|
298
414
|
|
|
299
415
|
/**
|
|
@@ -344,24 +460,26 @@ var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
|
|
|
344
460
|
* @inner
|
|
345
461
|
*/
|
|
346
462
|
function fromString(str, unsigned, radix) {
|
|
347
|
-
if (str.length === 0)
|
|
348
|
-
|
|
349
|
-
if (typeof unsigned === 'number') {
|
|
463
|
+
if (str.length === 0) throw Error("empty string");
|
|
464
|
+
if (typeof unsigned === "number") {
|
|
350
465
|
// For goog.math.long compatibility
|
|
351
466
|
radix = unsigned;
|
|
352
467
|
unsigned = false;
|
|
353
468
|
} else {
|
|
354
469
|
unsigned = !!unsigned;
|
|
355
470
|
}
|
|
356
|
-
if (
|
|
471
|
+
if (
|
|
472
|
+
str === "NaN" ||
|
|
473
|
+
str === "Infinity" ||
|
|
474
|
+
str === "+Infinity" ||
|
|
475
|
+
str === "-Infinity"
|
|
476
|
+
)
|
|
357
477
|
return unsigned ? UZERO : ZERO;
|
|
358
478
|
radix = radix || 10;
|
|
359
|
-
if (radix < 2 || 36 < radix)
|
|
360
|
-
throw RangeError('radix');
|
|
479
|
+
if (radix < 2 || 36 < radix) throw RangeError("radix");
|
|
361
480
|
|
|
362
481
|
var p;
|
|
363
|
-
if ((p = str.indexOf(
|
|
364
|
-
throw Error('interior hyphen');
|
|
482
|
+
if ((p = str.indexOf("-")) > 0) throw Error("interior hyphen");
|
|
365
483
|
else if (p === 0) {
|
|
366
484
|
return fromString(str.substring(1), unsigned, radix).neg();
|
|
367
485
|
}
|
|
@@ -404,18 +522,20 @@ Long.fromString = fromString;
|
|
|
404
522
|
* @inner
|
|
405
523
|
*/
|
|
406
524
|
function fromValue(val, unsigned) {
|
|
407
|
-
if (typeof val ===
|
|
408
|
-
|
|
409
|
-
if (typeof val === 'string')
|
|
410
|
-
return fromString(val, unsigned);
|
|
525
|
+
if (typeof val === "number") return fromNumber(val, unsigned);
|
|
526
|
+
if (typeof val === "string") return fromString(val, unsigned);
|
|
411
527
|
// Throws for non-objects, converts non-instanceof Long:
|
|
412
|
-
return fromBits(
|
|
528
|
+
return fromBits(
|
|
529
|
+
val.low,
|
|
530
|
+
val.high,
|
|
531
|
+
typeof unsigned === "boolean" ? unsigned : val.unsigned,
|
|
532
|
+
);
|
|
413
533
|
}
|
|
414
534
|
|
|
415
535
|
/**
|
|
416
536
|
* Converts the specified value to a Long using the appropriate from* function for its type.
|
|
417
537
|
* @function
|
|
418
|
-
* @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
|
|
538
|
+
* @param {!Long|number|bigint|string|!{low: number, high: number, unsigned: boolean}} val Value
|
|
419
539
|
* @param {boolean=} unsigned Whether unsigned or not, defaults to signed
|
|
420
540
|
* @returns {!Long}
|
|
421
541
|
*/
|
|
@@ -530,7 +650,7 @@ Long.NEG_ONE = NEG_ONE;
|
|
|
530
650
|
* @type {!Long}
|
|
531
651
|
* @inner
|
|
532
652
|
*/
|
|
533
|
-
var MAX_VALUE = fromBits(
|
|
653
|
+
var MAX_VALUE = fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
534
654
|
|
|
535
655
|
/**
|
|
536
656
|
* Maximum signed value.
|
|
@@ -542,7 +662,7 @@ Long.MAX_VALUE = MAX_VALUE;
|
|
|
542
662
|
* @type {!Long}
|
|
543
663
|
* @inner
|
|
544
664
|
*/
|
|
545
|
-
var MAX_UNSIGNED_VALUE = fromBits(
|
|
665
|
+
var MAX_UNSIGNED_VALUE = fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
546
666
|
|
|
547
667
|
/**
|
|
548
668
|
* Maximum unsigned value.
|
|
@@ -584,7 +704,7 @@ LongPrototype.toInt = function toInt() {
|
|
|
584
704
|
*/
|
|
585
705
|
LongPrototype.toNumber = function toNumber() {
|
|
586
706
|
if (this.unsigned)
|
|
587
|
-
return (
|
|
707
|
+
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
588
708
|
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
589
709
|
};
|
|
590
710
|
|
|
@@ -598,11 +718,10 @@ LongPrototype.toNumber = function toNumber() {
|
|
|
598
718
|
*/
|
|
599
719
|
LongPrototype.toString = function toString(radix) {
|
|
600
720
|
radix = radix || 10;
|
|
601
|
-
if (radix < 2 || 36 < radix)
|
|
602
|
-
|
|
603
|
-
if (this.
|
|
604
|
-
|
|
605
|
-
if (this.isNegative()) { // Unsigned Longs are never negative
|
|
721
|
+
if (radix < 2 || 36 < radix) throw RangeError("radix");
|
|
722
|
+
if (this.isZero()) return "0";
|
|
723
|
+
if (this.isNegative()) {
|
|
724
|
+
// Unsigned Longs are never negative
|
|
606
725
|
if (this.eq(MIN_VALUE)) {
|
|
607
726
|
// We need to change the Long value before it can be negated, so we remove
|
|
608
727
|
// the bottom-most digit in this base and then recurse to do the rest.
|
|
@@ -610,26 +729,23 @@ LongPrototype.toString = function toString(radix) {
|
|
|
610
729
|
div = this.div(radixLong),
|
|
611
730
|
rem1 = div.mul(radixLong).sub(this);
|
|
612
731
|
return div.toString(radix) + rem1.toInt().toString(radix);
|
|
613
|
-
} else
|
|
614
|
-
return '-' + this.neg().toString(radix);
|
|
732
|
+
} else return "-" + this.neg().toString(radix);
|
|
615
733
|
}
|
|
616
734
|
|
|
617
735
|
// Do several (6) digits each time through the loop, so as to
|
|
618
736
|
// minimize the calls to the very expensive emulated div.
|
|
619
737
|
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
|
|
620
738
|
rem = this;
|
|
621
|
-
var result =
|
|
739
|
+
var result = "";
|
|
622
740
|
while (true) {
|
|
623
741
|
var remDiv = rem.div(radixToPower),
|
|
624
742
|
intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
|
|
625
743
|
digits = intval.toString(radix);
|
|
626
744
|
rem = remDiv;
|
|
627
|
-
if (rem.isZero())
|
|
628
|
-
return digits + result;
|
|
745
|
+
if (rem.isZero()) return digits + result;
|
|
629
746
|
else {
|
|
630
|
-
while (digits.length < 6)
|
|
631
|
-
|
|
632
|
-
result = '' + digits + result;
|
|
747
|
+
while (digits.length < 6) digits = "0" + digits;
|
|
748
|
+
result = "" + digits + result;
|
|
633
749
|
}
|
|
634
750
|
}
|
|
635
751
|
};
|
|
@@ -676,15 +792,30 @@ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
|
|
676
792
|
* @returns {number}
|
|
677
793
|
*/
|
|
678
794
|
LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
|
679
|
-
if (this.isNegative())
|
|
795
|
+
if (this.isNegative())
|
|
796
|
+
// Unsigned Longs are never negative
|
|
680
797
|
return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
|
681
798
|
var val = this.high != 0 ? this.high : this.low;
|
|
682
|
-
for (var bit = 31; bit > 0; bit--)
|
|
683
|
-
if ((val & (1 << bit)) != 0)
|
|
684
|
-
break;
|
|
799
|
+
for (var bit = 31; bit > 0; bit--) if ((val & (1 << bit)) != 0) break;
|
|
685
800
|
return this.high != 0 ? bit + 33 : bit + 1;
|
|
686
801
|
};
|
|
687
802
|
|
|
803
|
+
/**
|
|
804
|
+
* Tests if this Long can be safely represented as a JavaScript number.
|
|
805
|
+
* @this {!Long}
|
|
806
|
+
* @returns {boolean}
|
|
807
|
+
*/
|
|
808
|
+
LongPrototype.isSafeInteger = function isSafeInteger() {
|
|
809
|
+
// 2^53-1 is the maximum safe value
|
|
810
|
+
var top11Bits = this.high >> 21;
|
|
811
|
+
// [0, 2^53-1]
|
|
812
|
+
if (!top11Bits) return true;
|
|
813
|
+
// > 2^53-1
|
|
814
|
+
if (this.unsigned) return false;
|
|
815
|
+
// [-2^53, -1] except -2^53
|
|
816
|
+
return top11Bits === -1 && !(this.low === 0 && this.high === -2097152);
|
|
817
|
+
};
|
|
818
|
+
|
|
688
819
|
/**
|
|
689
820
|
* Tests if this Long's value equals zero.
|
|
690
821
|
* @this {!Long}
|
|
@@ -739,13 +870,16 @@ LongPrototype.isEven = function isEven() {
|
|
|
739
870
|
/**
|
|
740
871
|
* Tests if this Long's value equals the specified's.
|
|
741
872
|
* @this {!Long}
|
|
742
|
-
* @param {!Long|number|string} other Other value
|
|
873
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
743
874
|
* @returns {boolean}
|
|
744
875
|
*/
|
|
745
876
|
LongPrototype.equals = function equals(other) {
|
|
746
|
-
if (!isLong(other))
|
|
747
|
-
|
|
748
|
-
|
|
877
|
+
if (!isLong(other)) other = fromValue(other);
|
|
878
|
+
if (
|
|
879
|
+
this.unsigned !== other.unsigned &&
|
|
880
|
+
this.high >>> 31 === 1 &&
|
|
881
|
+
other.high >>> 31 === 1
|
|
882
|
+
)
|
|
749
883
|
return false;
|
|
750
884
|
return this.high === other.high && this.low === other.low;
|
|
751
885
|
};
|
|
@@ -753,7 +887,7 @@ LongPrototype.equals = function equals(other) {
|
|
|
753
887
|
/**
|
|
754
888
|
* Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
|
|
755
889
|
* @function
|
|
756
|
-
* @param {!Long|number|string} other Other value
|
|
890
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
757
891
|
* @returns {boolean}
|
|
758
892
|
*/
|
|
759
893
|
LongPrototype.eq = LongPrototype.equals;
|
|
@@ -761,7 +895,7 @@ LongPrototype.eq = LongPrototype.equals;
|
|
|
761
895
|
/**
|
|
762
896
|
* Tests if this Long's value differs from the specified's.
|
|
763
897
|
* @this {!Long}
|
|
764
|
-
* @param {!Long|number|string} other Other value
|
|
898
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
765
899
|
* @returns {boolean}
|
|
766
900
|
*/
|
|
767
901
|
LongPrototype.notEquals = function notEquals(other) {
|
|
@@ -771,7 +905,7 @@ LongPrototype.notEquals = function notEquals(other) {
|
|
|
771
905
|
/**
|
|
772
906
|
* Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
|
|
773
907
|
* @function
|
|
774
|
-
* @param {!Long|number|string} other Other value
|
|
908
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
775
909
|
* @returns {boolean}
|
|
776
910
|
*/
|
|
777
911
|
LongPrototype.neq = LongPrototype.notEquals;
|
|
@@ -779,7 +913,7 @@ LongPrototype.neq = LongPrototype.notEquals;
|
|
|
779
913
|
/**
|
|
780
914
|
* Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
|
|
781
915
|
* @function
|
|
782
|
-
* @param {!Long|number|string} other Other value
|
|
916
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
783
917
|
* @returns {boolean}
|
|
784
918
|
*/
|
|
785
919
|
LongPrototype.ne = LongPrototype.notEquals;
|
|
@@ -787,7 +921,7 @@ LongPrototype.ne = LongPrototype.notEquals;
|
|
|
787
921
|
/**
|
|
788
922
|
* Tests if this Long's value is less than the specified's.
|
|
789
923
|
* @this {!Long}
|
|
790
|
-
* @param {!Long|number|string} other Other value
|
|
924
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
791
925
|
* @returns {boolean}
|
|
792
926
|
*/
|
|
793
927
|
LongPrototype.lessThan = function lessThan(other) {
|
|
@@ -797,7 +931,7 @@ LongPrototype.lessThan = function lessThan(other) {
|
|
|
797
931
|
/**
|
|
798
932
|
* Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
|
|
799
933
|
* @function
|
|
800
|
-
* @param {!Long|number|string} other Other value
|
|
934
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
801
935
|
* @returns {boolean}
|
|
802
936
|
*/
|
|
803
937
|
LongPrototype.lt = LongPrototype.lessThan;
|
|
@@ -805,7 +939,7 @@ LongPrototype.lt = LongPrototype.lessThan;
|
|
|
805
939
|
/**
|
|
806
940
|
* Tests if this Long's value is less than or equal the specified's.
|
|
807
941
|
* @this {!Long}
|
|
808
|
-
* @param {!Long|number|string} other Other value
|
|
942
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
809
943
|
* @returns {boolean}
|
|
810
944
|
*/
|
|
811
945
|
LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
|
@@ -815,7 +949,7 @@ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
|
|
815
949
|
/**
|
|
816
950
|
* Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
|
|
817
951
|
* @function
|
|
818
|
-
* @param {!Long|number|string} other Other value
|
|
952
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
819
953
|
* @returns {boolean}
|
|
820
954
|
*/
|
|
821
955
|
LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
|
@@ -823,7 +957,7 @@ LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
|
|
823
957
|
/**
|
|
824
958
|
* Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
|
|
825
959
|
* @function
|
|
826
|
-
* @param {!Long|number|string} other Other value
|
|
960
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
827
961
|
* @returns {boolean}
|
|
828
962
|
*/
|
|
829
963
|
LongPrototype.le = LongPrototype.lessThanOrEqual;
|
|
@@ -831,7 +965,7 @@ LongPrototype.le = LongPrototype.lessThanOrEqual;
|
|
|
831
965
|
/**
|
|
832
966
|
* Tests if this Long's value is greater than the specified's.
|
|
833
967
|
* @this {!Long}
|
|
834
|
-
* @param {!Long|number|string} other Other value
|
|
968
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
835
969
|
* @returns {boolean}
|
|
836
970
|
*/
|
|
837
971
|
LongPrototype.greaterThan = function greaterThan(other) {
|
|
@@ -841,7 +975,7 @@ LongPrototype.greaterThan = function greaterThan(other) {
|
|
|
841
975
|
/**
|
|
842
976
|
* Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
|
|
843
977
|
* @function
|
|
844
|
-
* @param {!Long|number|string} other Other value
|
|
978
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
845
979
|
* @returns {boolean}
|
|
846
980
|
*/
|
|
847
981
|
LongPrototype.gt = LongPrototype.greaterThan;
|
|
@@ -849,7 +983,7 @@ LongPrototype.gt = LongPrototype.greaterThan;
|
|
|
849
983
|
/**
|
|
850
984
|
* Tests if this Long's value is greater than or equal the specified's.
|
|
851
985
|
* @this {!Long}
|
|
852
|
-
* @param {!Long|number|string} other Other value
|
|
986
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
853
987
|
* @returns {boolean}
|
|
854
988
|
*/
|
|
855
989
|
LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
|
@@ -859,7 +993,7 @@ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
|
|
859
993
|
/**
|
|
860
994
|
* Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
|
|
861
995
|
* @function
|
|
862
|
-
* @param {!Long|number|string} other Other value
|
|
996
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
863
997
|
* @returns {boolean}
|
|
864
998
|
*/
|
|
865
999
|
LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
|
@@ -867,7 +1001,7 @@ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
|
|
867
1001
|
/**
|
|
868
1002
|
* Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
|
|
869
1003
|
* @function
|
|
870
|
-
* @param {!Long|number|string} other Other value
|
|
1004
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
871
1005
|
* @returns {boolean}
|
|
872
1006
|
*/
|
|
873
1007
|
LongPrototype.ge = LongPrototype.greaterThanOrEqual;
|
|
@@ -875,32 +1009,30 @@ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
|
|
|
875
1009
|
/**
|
|
876
1010
|
* Compares this Long's value with the specified's.
|
|
877
1011
|
* @this {!Long}
|
|
878
|
-
* @param {!Long|number|string} other Other value
|
|
1012
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
879
1013
|
* @returns {number} 0 if they are the same, 1 if the this is greater and -1
|
|
880
1014
|
* if the given one is greater
|
|
881
1015
|
*/
|
|
882
1016
|
LongPrototype.compare = function compare(other) {
|
|
883
|
-
if (!isLong(other))
|
|
884
|
-
|
|
885
|
-
if (this.eq(other))
|
|
886
|
-
return 0;
|
|
1017
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1018
|
+
if (this.eq(other)) return 0;
|
|
887
1019
|
var thisNeg = this.isNegative(),
|
|
888
1020
|
otherNeg = other.isNegative();
|
|
889
|
-
if (thisNeg && !otherNeg)
|
|
890
|
-
|
|
891
|
-
if (!thisNeg && otherNeg)
|
|
892
|
-
return 1;
|
|
1021
|
+
if (thisNeg && !otherNeg) return -1;
|
|
1022
|
+
if (!thisNeg && otherNeg) return 1;
|
|
893
1023
|
// At this point the sign bits are the same
|
|
894
|
-
if (!this.unsigned)
|
|
895
|
-
return this.sub(other).isNegative() ? -1 : 1;
|
|
1024
|
+
if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1;
|
|
896
1025
|
// Both are positive if at least one is unsigned
|
|
897
|
-
return
|
|
1026
|
+
return other.high >>> 0 > this.high >>> 0 ||
|
|
1027
|
+
(other.high === this.high && other.low >>> 0 > this.low >>> 0)
|
|
1028
|
+
? -1
|
|
1029
|
+
: 1;
|
|
898
1030
|
};
|
|
899
1031
|
|
|
900
1032
|
/**
|
|
901
1033
|
* Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
|
|
902
1034
|
* @function
|
|
903
|
-
* @param {!Long|number|string} other Other value
|
|
1035
|
+
* @param {!Long|number|bigint|string} other Other value
|
|
904
1036
|
* @returns {number} 0 if they are the same, 1 if the this is greater and -1
|
|
905
1037
|
* if the given one is greater
|
|
906
1038
|
*/
|
|
@@ -912,8 +1044,7 @@ LongPrototype.comp = LongPrototype.compare;
|
|
|
912
1044
|
* @returns {!Long} Negated Long
|
|
913
1045
|
*/
|
|
914
1046
|
LongPrototype.negate = function negate() {
|
|
915
|
-
if (!this.unsigned && this.eq(MIN_VALUE))
|
|
916
|
-
return MIN_VALUE;
|
|
1047
|
+
if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
|
|
917
1048
|
return this.not().add(ONE);
|
|
918
1049
|
};
|
|
919
1050
|
|
|
@@ -927,56 +1058,57 @@ LongPrototype.neg = LongPrototype.negate;
|
|
|
927
1058
|
/**
|
|
928
1059
|
* Returns the sum of this and the specified Long.
|
|
929
1060
|
* @this {!Long}
|
|
930
|
-
* @param {!Long|number|string} addend Addend
|
|
1061
|
+
* @param {!Long|number|bigint|string} addend Addend
|
|
931
1062
|
* @returns {!Long} Sum
|
|
932
1063
|
*/
|
|
933
1064
|
LongPrototype.add = function add(addend) {
|
|
934
|
-
if (!isLong(addend))
|
|
935
|
-
addend = fromValue(addend);
|
|
1065
|
+
if (!isLong(addend)) addend = fromValue(addend);
|
|
936
1066
|
|
|
937
1067
|
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
|
938
1068
|
|
|
939
1069
|
var a48 = this.high >>> 16;
|
|
940
|
-
var a32 = this.high &
|
|
1070
|
+
var a32 = this.high & 0xffff;
|
|
941
1071
|
var a16 = this.low >>> 16;
|
|
942
|
-
var a00 = this.low &
|
|
1072
|
+
var a00 = this.low & 0xffff;
|
|
943
1073
|
|
|
944
1074
|
var b48 = addend.high >>> 16;
|
|
945
|
-
var b32 = addend.high &
|
|
1075
|
+
var b32 = addend.high & 0xffff;
|
|
946
1076
|
var b16 = addend.low >>> 16;
|
|
947
|
-
var b00 = addend.low &
|
|
1077
|
+
var b00 = addend.low & 0xffff;
|
|
948
1078
|
|
|
949
|
-
var c48 = 0,
|
|
1079
|
+
var c48 = 0,
|
|
1080
|
+
c32 = 0,
|
|
1081
|
+
c16 = 0,
|
|
1082
|
+
c00 = 0;
|
|
950
1083
|
c00 += a00 + b00;
|
|
951
1084
|
c16 += c00 >>> 16;
|
|
952
|
-
c00 &=
|
|
1085
|
+
c00 &= 0xffff;
|
|
953
1086
|
c16 += a16 + b16;
|
|
954
1087
|
c32 += c16 >>> 16;
|
|
955
|
-
c16 &=
|
|
1088
|
+
c16 &= 0xffff;
|
|
956
1089
|
c32 += a32 + b32;
|
|
957
1090
|
c48 += c32 >>> 16;
|
|
958
|
-
c32 &=
|
|
1091
|
+
c32 &= 0xffff;
|
|
959
1092
|
c48 += a48 + b48;
|
|
960
|
-
c48 &=
|
|
1093
|
+
c48 &= 0xffff;
|
|
961
1094
|
return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
|
962
1095
|
};
|
|
963
1096
|
|
|
964
1097
|
/**
|
|
965
1098
|
* Returns the difference of this and the specified Long.
|
|
966
1099
|
* @this {!Long}
|
|
967
|
-
* @param {!Long|number|string} subtrahend Subtrahend
|
|
1100
|
+
* @param {!Long|number|bigint|string} subtrahend Subtrahend
|
|
968
1101
|
* @returns {!Long} Difference
|
|
969
1102
|
*/
|
|
970
1103
|
LongPrototype.subtract = function subtract(subtrahend) {
|
|
971
|
-
if (!isLong(subtrahend))
|
|
972
|
-
subtrahend = fromValue(subtrahend);
|
|
1104
|
+
if (!isLong(subtrahend)) subtrahend = fromValue(subtrahend);
|
|
973
1105
|
return this.add(subtrahend.neg());
|
|
974
1106
|
};
|
|
975
1107
|
|
|
976
1108
|
/**
|
|
977
1109
|
* Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
|
|
978
1110
|
* @function
|
|
979
|
-
* @param {!Long|number|string} subtrahend Subtrahend
|
|
1111
|
+
* @param {!Long|number|bigint|string} subtrahend Subtrahend
|
|
980
1112
|
* @returns {!Long} Difference
|
|
981
1113
|
*/
|
|
982
1114
|
LongPrototype.sub = LongPrototype.subtract;
|
|
@@ -984,38 +1116,27 @@ LongPrototype.sub = LongPrototype.subtract;
|
|
|
984
1116
|
/**
|
|
985
1117
|
* Returns the product of this and the specified Long.
|
|
986
1118
|
* @this {!Long}
|
|
987
|
-
* @param {!Long|number|string} multiplier Multiplier
|
|
1119
|
+
* @param {!Long|number|bigint|string} multiplier Multiplier
|
|
988
1120
|
* @returns {!Long} Product
|
|
989
1121
|
*/
|
|
990
1122
|
LongPrototype.multiply = function multiply(multiplier) {
|
|
991
|
-
if (this.isZero())
|
|
992
|
-
|
|
993
|
-
if (!isLong(multiplier))
|
|
994
|
-
multiplier = fromValue(multiplier);
|
|
1123
|
+
if (this.isZero()) return this;
|
|
1124
|
+
if (!isLong(multiplier)) multiplier = fromValue(multiplier);
|
|
995
1125
|
|
|
996
1126
|
// use wasm support if present
|
|
997
1127
|
if (wasm) {
|
|
998
|
-
var low = wasm["mul"](this.low,
|
|
999
|
-
this.high,
|
|
1000
|
-
multiplier.low,
|
|
1001
|
-
multiplier.high);
|
|
1128
|
+
var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
|
|
1002
1129
|
return fromBits(low, wasm["get_high"](), this.unsigned);
|
|
1003
1130
|
}
|
|
1004
1131
|
|
|
1005
|
-
if (multiplier.isZero())
|
|
1006
|
-
|
|
1007
|
-
if (
|
|
1008
|
-
return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
|
1009
|
-
if (multiplier.eq(MIN_VALUE))
|
|
1010
|
-
return this.isOdd() ? MIN_VALUE : ZERO;
|
|
1132
|
+
if (multiplier.isZero()) return this.unsigned ? UZERO : ZERO;
|
|
1133
|
+
if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
|
1134
|
+
if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
|
|
1011
1135
|
|
|
1012
1136
|
if (this.isNegative()) {
|
|
1013
|
-
if (multiplier.isNegative())
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
return this.neg().mul(multiplier).neg();
|
|
1017
|
-
} else if (multiplier.isNegative())
|
|
1018
|
-
return this.mul(multiplier.neg()).neg();
|
|
1137
|
+
if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());
|
|
1138
|
+
else return this.neg().mul(multiplier).neg();
|
|
1139
|
+
} else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg();
|
|
1019
1140
|
|
|
1020
1141
|
// If both longs are small, use float multiplication
|
|
1021
1142
|
if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
|
|
@@ -1025,43 +1146,46 @@ LongPrototype.multiply = function multiply(multiplier) {
|
|
|
1025
1146
|
// We can skip products that would overflow.
|
|
1026
1147
|
|
|
1027
1148
|
var a48 = this.high >>> 16;
|
|
1028
|
-
var a32 = this.high &
|
|
1149
|
+
var a32 = this.high & 0xffff;
|
|
1029
1150
|
var a16 = this.low >>> 16;
|
|
1030
|
-
var a00 = this.low &
|
|
1151
|
+
var a00 = this.low & 0xffff;
|
|
1031
1152
|
|
|
1032
1153
|
var b48 = multiplier.high >>> 16;
|
|
1033
|
-
var b32 = multiplier.high &
|
|
1154
|
+
var b32 = multiplier.high & 0xffff;
|
|
1034
1155
|
var b16 = multiplier.low >>> 16;
|
|
1035
|
-
var b00 = multiplier.low &
|
|
1156
|
+
var b00 = multiplier.low & 0xffff;
|
|
1036
1157
|
|
|
1037
|
-
var c48 = 0,
|
|
1158
|
+
var c48 = 0,
|
|
1159
|
+
c32 = 0,
|
|
1160
|
+
c16 = 0,
|
|
1161
|
+
c00 = 0;
|
|
1038
1162
|
c00 += a00 * b00;
|
|
1039
1163
|
c16 += c00 >>> 16;
|
|
1040
|
-
c00 &=
|
|
1164
|
+
c00 &= 0xffff;
|
|
1041
1165
|
c16 += a16 * b00;
|
|
1042
1166
|
c32 += c16 >>> 16;
|
|
1043
|
-
c16 &=
|
|
1167
|
+
c16 &= 0xffff;
|
|
1044
1168
|
c16 += a00 * b16;
|
|
1045
1169
|
c32 += c16 >>> 16;
|
|
1046
|
-
c16 &=
|
|
1170
|
+
c16 &= 0xffff;
|
|
1047
1171
|
c32 += a32 * b00;
|
|
1048
1172
|
c48 += c32 >>> 16;
|
|
1049
|
-
c32 &=
|
|
1173
|
+
c32 &= 0xffff;
|
|
1050
1174
|
c32 += a16 * b16;
|
|
1051
1175
|
c48 += c32 >>> 16;
|
|
1052
|
-
c32 &=
|
|
1176
|
+
c32 &= 0xffff;
|
|
1053
1177
|
c32 += a00 * b32;
|
|
1054
1178
|
c48 += c32 >>> 16;
|
|
1055
|
-
c32 &=
|
|
1179
|
+
c32 &= 0xffff;
|
|
1056
1180
|
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
|
1057
|
-
c48 &=
|
|
1181
|
+
c48 &= 0xffff;
|
|
1058
1182
|
return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
|
1059
1183
|
};
|
|
1060
1184
|
|
|
1061
1185
|
/**
|
|
1062
1186
|
* Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
|
|
1063
1187
|
* @function
|
|
1064
|
-
* @param {!Long|number|string} multiplier Multiplier
|
|
1188
|
+
* @param {!Long|number|bigint|string} multiplier Multiplier
|
|
1065
1189
|
* @returns {!Long} Product
|
|
1066
1190
|
*/
|
|
1067
1191
|
LongPrototype.mul = LongPrototype.multiply;
|
|
@@ -1070,23 +1194,24 @@ LongPrototype.mul = LongPrototype.multiply;
|
|
|
1070
1194
|
* Returns this Long divided by the specified. The result is signed if this Long is signed or
|
|
1071
1195
|
* unsigned if this Long is unsigned.
|
|
1072
1196
|
* @this {!Long}
|
|
1073
|
-
* @param {!Long|number|string} divisor Divisor
|
|
1197
|
+
* @param {!Long|number|bigint|string} divisor Divisor
|
|
1074
1198
|
* @returns {!Long} Quotient
|
|
1075
1199
|
*/
|
|
1076
1200
|
LongPrototype.divide = function divide(divisor) {
|
|
1077
|
-
if (!isLong(divisor))
|
|
1078
|
-
|
|
1079
|
-
if (divisor.isZero())
|
|
1080
|
-
throw Error('division by zero');
|
|
1201
|
+
if (!isLong(divisor)) divisor = fromValue(divisor);
|
|
1202
|
+
if (divisor.isZero()) throw Error("division by zero");
|
|
1081
1203
|
|
|
1082
1204
|
// use wasm support if present
|
|
1083
1205
|
if (wasm) {
|
|
1084
1206
|
// guard against signed division overflow: the largest
|
|
1085
1207
|
// negative number / -1 would be 1 larger than the largest
|
|
1086
1208
|
// positive number, due to two's complement.
|
|
1087
|
-
if (
|
|
1209
|
+
if (
|
|
1210
|
+
!this.unsigned &&
|
|
1088
1211
|
this.high === -2147483648 &&
|
|
1089
|
-
divisor.low === -1 &&
|
|
1212
|
+
divisor.low === -1 &&
|
|
1213
|
+
divisor.high === -1
|
|
1214
|
+
) {
|
|
1090
1215
|
// be consistent with non-wasm code path
|
|
1091
1216
|
return this;
|
|
1092
1217
|
}
|
|
@@ -1094,22 +1219,20 @@ LongPrototype.divide = function divide(divisor) {
|
|
|
1094
1219
|
this.low,
|
|
1095
1220
|
this.high,
|
|
1096
1221
|
divisor.low,
|
|
1097
|
-
divisor.high
|
|
1222
|
+
divisor.high,
|
|
1098
1223
|
);
|
|
1099
1224
|
return fromBits(low, wasm["get_high"](), this.unsigned);
|
|
1100
1225
|
}
|
|
1101
1226
|
|
|
1102
|
-
if (this.isZero())
|
|
1103
|
-
return this.unsigned ? UZERO : ZERO;
|
|
1227
|
+
if (this.isZero()) return this.unsigned ? UZERO : ZERO;
|
|
1104
1228
|
var approx, rem, res;
|
|
1105
1229
|
if (!this.unsigned) {
|
|
1106
1230
|
// This section is only relevant for signed longs and is derived from the
|
|
1107
1231
|
// closure library as a whole.
|
|
1108
1232
|
if (this.eq(MIN_VALUE)) {
|
|
1109
1233
|
if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
|
1110
|
-
return MIN_VALUE;
|
|
1111
|
-
else if (divisor.eq(MIN_VALUE))
|
|
1112
|
-
return ONE;
|
|
1234
|
+
return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
|
1235
|
+
else if (divisor.eq(MIN_VALUE)) return ONE;
|
|
1113
1236
|
else {
|
|
1114
1237
|
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
|
1115
1238
|
var halfThis = this.shr(1);
|
|
@@ -1122,23 +1245,19 @@ LongPrototype.divide = function divide(divisor) {
|
|
|
1122
1245
|
return res;
|
|
1123
1246
|
}
|
|
1124
1247
|
}
|
|
1125
|
-
} else if (divisor.eq(MIN_VALUE))
|
|
1126
|
-
return this.unsigned ? UZERO : ZERO;
|
|
1248
|
+
} else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
|
|
1127
1249
|
if (this.isNegative()) {
|
|
1128
|
-
if (divisor.isNegative())
|
|
1129
|
-
return this.neg().div(divisor.neg());
|
|
1250
|
+
if (divisor.isNegative()) return this.neg().div(divisor.neg());
|
|
1130
1251
|
return this.neg().div(divisor).neg();
|
|
1131
|
-
} else if (divisor.isNegative())
|
|
1132
|
-
return this.div(divisor.neg()).neg();
|
|
1252
|
+
} else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
|
|
1133
1253
|
res = ZERO;
|
|
1134
1254
|
} else {
|
|
1135
1255
|
// The algorithm below has not been made for unsigned longs. It's therefore
|
|
1136
1256
|
// required to take special care of the MSB prior to running it.
|
|
1137
|
-
if (!divisor.unsigned)
|
|
1138
|
-
|
|
1139
|
-
if (divisor.gt(this))
|
|
1140
|
-
|
|
1141
|
-
if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
|
|
1257
|
+
if (!divisor.unsigned) divisor = divisor.toUnsigned();
|
|
1258
|
+
if (divisor.gt(this)) return UZERO;
|
|
1259
|
+
if (divisor.gt(this.shru(1)))
|
|
1260
|
+
// 15 >>> 1 = 7 ; with divisor = 8 ; true
|
|
1142
1261
|
return UONE;
|
|
1143
1262
|
res = UZERO;
|
|
1144
1263
|
}
|
|
@@ -1157,8 +1276,7 @@ LongPrototype.divide = function divide(divisor) {
|
|
|
1157
1276
|
// We will tweak the approximate result by changing it in the 48-th digit or
|
|
1158
1277
|
// the smallest non-fractional digit, whichever is larger.
|
|
1159
1278
|
var log2 = Math.ceil(Math.log(approx) / Math.LN2),
|
|
1160
|
-
delta =
|
|
1161
|
-
|
|
1279
|
+
delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48),
|
|
1162
1280
|
// Decrease the approximation until it is smaller than the remainder. Note
|
|
1163
1281
|
// that if it is too large, the product overflows and is negative.
|
|
1164
1282
|
approxRes = fromNumber(approx),
|
|
@@ -1171,8 +1289,7 @@ LongPrototype.divide = function divide(divisor) {
|
|
|
1171
1289
|
|
|
1172
1290
|
// We know the answer can't be zero... and actually, zero would cause
|
|
1173
1291
|
// infinite recursion since we would make no progress.
|
|
1174
|
-
if (approxRes.isZero())
|
|
1175
|
-
approxRes = ONE;
|
|
1292
|
+
if (approxRes.isZero()) approxRes = ONE;
|
|
1176
1293
|
|
|
1177
1294
|
res = res.add(approxRes);
|
|
1178
1295
|
rem = rem.sub(approxRem);
|
|
@@ -1183,7 +1300,7 @@ LongPrototype.divide = function divide(divisor) {
|
|
|
1183
1300
|
/**
|
|
1184
1301
|
* Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
|
|
1185
1302
|
* @function
|
|
1186
|
-
* @param {!Long|number|string} divisor Divisor
|
|
1303
|
+
* @param {!Long|number|bigint|string} divisor Divisor
|
|
1187
1304
|
* @returns {!Long} Quotient
|
|
1188
1305
|
*/
|
|
1189
1306
|
LongPrototype.div = LongPrototype.divide;
|
|
@@ -1191,12 +1308,11 @@ LongPrototype.div = LongPrototype.divide;
|
|
|
1191
1308
|
/**
|
|
1192
1309
|
* Returns this Long modulo the specified.
|
|
1193
1310
|
* @this {!Long}
|
|
1194
|
-
* @param {!Long|number|string} divisor Divisor
|
|
1311
|
+
* @param {!Long|number|bigint|string} divisor Divisor
|
|
1195
1312
|
* @returns {!Long} Remainder
|
|
1196
1313
|
*/
|
|
1197
1314
|
LongPrototype.modulo = function modulo(divisor) {
|
|
1198
|
-
if (!isLong(divisor))
|
|
1199
|
-
divisor = fromValue(divisor);
|
|
1315
|
+
if (!isLong(divisor)) divisor = fromValue(divisor);
|
|
1200
1316
|
|
|
1201
1317
|
// use wasm support if present
|
|
1202
1318
|
if (wasm) {
|
|
@@ -1204,7 +1320,7 @@ LongPrototype.modulo = function modulo(divisor) {
|
|
|
1204
1320
|
this.low,
|
|
1205
1321
|
this.high,
|
|
1206
1322
|
divisor.low,
|
|
1207
|
-
divisor.high
|
|
1323
|
+
divisor.high,
|
|
1208
1324
|
);
|
|
1209
1325
|
return fromBits(low, wasm["get_high"](), this.unsigned);
|
|
1210
1326
|
}
|
|
@@ -1215,7 +1331,7 @@ LongPrototype.modulo = function modulo(divisor) {
|
|
|
1215
1331
|
/**
|
|
1216
1332
|
* Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
|
|
1217
1333
|
* @function
|
|
1218
|
-
* @param {!Long|number|string} divisor Divisor
|
|
1334
|
+
* @param {!Long|number|bigint|string} divisor Divisor
|
|
1219
1335
|
* @returns {!Long} Remainder
|
|
1220
1336
|
*/
|
|
1221
1337
|
LongPrototype.mod = LongPrototype.modulo;
|
|
@@ -1223,7 +1339,7 @@ LongPrototype.mod = LongPrototype.modulo;
|
|
|
1223
1339
|
/**
|
|
1224
1340
|
* Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
|
|
1225
1341
|
* @function
|
|
1226
|
-
* @param {!Long|number|string} divisor Divisor
|
|
1342
|
+
* @param {!Long|number|bigint|string} divisor Divisor
|
|
1227
1343
|
* @returns {!Long} Remainder
|
|
1228
1344
|
*/
|
|
1229
1345
|
LongPrototype.rem = LongPrototype.modulo;
|
|
@@ -1274,36 +1390,33 @@ LongPrototype.ctz = LongPrototype.countTrailingZeros;
|
|
|
1274
1390
|
/**
|
|
1275
1391
|
* Returns the bitwise AND of this Long and the specified.
|
|
1276
1392
|
* @this {!Long}
|
|
1277
|
-
* @param {!Long|number|string} other Other Long
|
|
1393
|
+
* @param {!Long|number|bigint|string} other Other Long
|
|
1278
1394
|
* @returns {!Long}
|
|
1279
1395
|
*/
|
|
1280
1396
|
LongPrototype.and = function and(other) {
|
|
1281
|
-
if (!isLong(other))
|
|
1282
|
-
other = fromValue(other);
|
|
1397
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1283
1398
|
return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
|
1284
1399
|
};
|
|
1285
1400
|
|
|
1286
1401
|
/**
|
|
1287
1402
|
* Returns the bitwise OR of this Long and the specified.
|
|
1288
1403
|
* @this {!Long}
|
|
1289
|
-
* @param {!Long|number|string} other Other Long
|
|
1404
|
+
* @param {!Long|number|bigint|string} other Other Long
|
|
1290
1405
|
* @returns {!Long}
|
|
1291
1406
|
*/
|
|
1292
1407
|
LongPrototype.or = function or(other) {
|
|
1293
|
-
if (!isLong(other))
|
|
1294
|
-
other = fromValue(other);
|
|
1408
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1295
1409
|
return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
|
1296
1410
|
};
|
|
1297
1411
|
|
|
1298
1412
|
/**
|
|
1299
1413
|
* Returns the bitwise XOR of this Long and the given one.
|
|
1300
1414
|
* @this {!Long}
|
|
1301
|
-
* @param {!Long|number|string} other Other Long
|
|
1415
|
+
* @param {!Long|number|bigint|string} other Other Long
|
|
1302
1416
|
* @returns {!Long}
|
|
1303
1417
|
*/
|
|
1304
1418
|
LongPrototype.xor = function xor(other) {
|
|
1305
|
-
if (!isLong(other))
|
|
1306
|
-
other = fromValue(other);
|
|
1419
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1307
1420
|
return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
|
1308
1421
|
};
|
|
1309
1422
|
|
|
@@ -1314,14 +1427,15 @@ LongPrototype.xor = function xor(other) {
|
|
|
1314
1427
|
* @returns {!Long} Shifted Long
|
|
1315
1428
|
*/
|
|
1316
1429
|
LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
|
1317
|
-
if (isLong(numBits))
|
|
1318
|
-
|
|
1319
|
-
if ((numBits &= 63) === 0)
|
|
1320
|
-
return this;
|
|
1430
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1431
|
+
if ((numBits &= 63) === 0) return this;
|
|
1321
1432
|
else if (numBits < 32)
|
|
1322
|
-
return fromBits(
|
|
1323
|
-
|
|
1324
|
-
|
|
1433
|
+
return fromBits(
|
|
1434
|
+
this.low << numBits,
|
|
1435
|
+
(this.high << numBits) | (this.low >>> (32 - numBits)),
|
|
1436
|
+
this.unsigned,
|
|
1437
|
+
);
|
|
1438
|
+
else return fromBits(0, this.low << (numBits - 32), this.unsigned);
|
|
1325
1439
|
};
|
|
1326
1440
|
|
|
1327
1441
|
/**
|
|
@@ -1339,14 +1453,20 @@ LongPrototype.shl = LongPrototype.shiftLeft;
|
|
|
1339
1453
|
* @returns {!Long} Shifted Long
|
|
1340
1454
|
*/
|
|
1341
1455
|
LongPrototype.shiftRight = function shiftRight(numBits) {
|
|
1342
|
-
if (isLong(numBits))
|
|
1343
|
-
|
|
1344
|
-
if ((numBits &= 63) === 0)
|
|
1345
|
-
return this;
|
|
1456
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1457
|
+
if ((numBits &= 63) === 0) return this;
|
|
1346
1458
|
else if (numBits < 32)
|
|
1347
|
-
return fromBits(
|
|
1459
|
+
return fromBits(
|
|
1460
|
+
(this.low >>> numBits) | (this.high << (32 - numBits)),
|
|
1461
|
+
this.high >> numBits,
|
|
1462
|
+
this.unsigned,
|
|
1463
|
+
);
|
|
1348
1464
|
else
|
|
1349
|
-
return fromBits(
|
|
1465
|
+
return fromBits(
|
|
1466
|
+
this.high >> (numBits - 32),
|
|
1467
|
+
this.high >= 0 ? 0 : -1,
|
|
1468
|
+
this.unsigned,
|
|
1469
|
+
);
|
|
1350
1470
|
};
|
|
1351
1471
|
|
|
1352
1472
|
/**
|
|
@@ -1366,7 +1486,12 @@ LongPrototype.shr = LongPrototype.shiftRight;
|
|
|
1366
1486
|
LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
|
1367
1487
|
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1368
1488
|
if ((numBits &= 63) === 0) return this;
|
|
1369
|
-
if (numBits < 32)
|
|
1489
|
+
if (numBits < 32)
|
|
1490
|
+
return fromBits(
|
|
1491
|
+
(this.low >>> numBits) | (this.high << (32 - numBits)),
|
|
1492
|
+
this.high >>> numBits,
|
|
1493
|
+
this.unsigned,
|
|
1494
|
+
);
|
|
1370
1495
|
if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
|
|
1371
1496
|
return fromBits(this.high >>> (numBits - 32), 0, this.unsigned);
|
|
1372
1497
|
};
|
|
@@ -1399,12 +1524,20 @@ LongPrototype.rotateLeft = function rotateLeft(numBits) {
|
|
|
1399
1524
|
if ((numBits &= 63) === 0) return this;
|
|
1400
1525
|
if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
|
|
1401
1526
|
if (numBits < 32) {
|
|
1402
|
-
b =
|
|
1403
|
-
return fromBits(
|
|
1527
|
+
b = 32 - numBits;
|
|
1528
|
+
return fromBits(
|
|
1529
|
+
(this.low << numBits) | (this.high >>> b),
|
|
1530
|
+
(this.high << numBits) | (this.low >>> b),
|
|
1531
|
+
this.unsigned,
|
|
1532
|
+
);
|
|
1404
1533
|
}
|
|
1405
1534
|
numBits -= 32;
|
|
1406
|
-
b =
|
|
1407
|
-
return fromBits(
|
|
1535
|
+
b = 32 - numBits;
|
|
1536
|
+
return fromBits(
|
|
1537
|
+
(this.high << numBits) | (this.low >>> b),
|
|
1538
|
+
(this.low << numBits) | (this.high >>> b),
|
|
1539
|
+
this.unsigned,
|
|
1540
|
+
);
|
|
1408
1541
|
};
|
|
1409
1542
|
/**
|
|
1410
1543
|
* Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}.
|
|
@@ -1426,12 +1559,20 @@ LongPrototype.rotateRight = function rotateRight(numBits) {
|
|
|
1426
1559
|
if ((numBits &= 63) === 0) return this;
|
|
1427
1560
|
if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
|
|
1428
1561
|
if (numBits < 32) {
|
|
1429
|
-
b =
|
|
1430
|
-
return fromBits(
|
|
1562
|
+
b = 32 - numBits;
|
|
1563
|
+
return fromBits(
|
|
1564
|
+
(this.high << b) | (this.low >>> numBits),
|
|
1565
|
+
(this.low << b) | (this.high >>> numBits),
|
|
1566
|
+
this.unsigned,
|
|
1567
|
+
);
|
|
1431
1568
|
}
|
|
1432
1569
|
numBits -= 32;
|
|
1433
|
-
b =
|
|
1434
|
-
return fromBits(
|
|
1570
|
+
b = 32 - numBits;
|
|
1571
|
+
return fromBits(
|
|
1572
|
+
(this.low << b) | (this.high >>> numBits),
|
|
1573
|
+
(this.high << b) | (this.low >>> numBits),
|
|
1574
|
+
this.unsigned,
|
|
1575
|
+
);
|
|
1435
1576
|
};
|
|
1436
1577
|
/**
|
|
1437
1578
|
* Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}.
|
|
@@ -1447,8 +1588,7 @@ LongPrototype.rotr = LongPrototype.rotateRight;
|
|
|
1447
1588
|
* @returns {!Long} Signed long
|
|
1448
1589
|
*/
|
|
1449
1590
|
LongPrototype.toSigned = function toSigned() {
|
|
1450
|
-
if (!this.unsigned)
|
|
1451
|
-
return this;
|
|
1591
|
+
if (!this.unsigned) return this;
|
|
1452
1592
|
return fromBits(this.low, this.high, false);
|
|
1453
1593
|
};
|
|
1454
1594
|
|
|
@@ -1458,8 +1598,7 @@ LongPrototype.toSigned = function toSigned() {
|
|
|
1458
1598
|
* @returns {!Long} Unsigned long
|
|
1459
1599
|
*/
|
|
1460
1600
|
LongPrototype.toUnsigned = function toUnsigned() {
|
|
1461
|
-
if (this.unsigned)
|
|
1462
|
-
return this;
|
|
1601
|
+
if (this.unsigned) return this;
|
|
1463
1602
|
return fromBits(this.low, this.high, true);
|
|
1464
1603
|
};
|
|
1465
1604
|
|
|
@@ -1483,13 +1622,13 @@ LongPrototype.toBytesLE = function toBytesLE() {
|
|
|
1483
1622
|
lo = this.low;
|
|
1484
1623
|
return [
|
|
1485
1624
|
lo & 0xff,
|
|
1486
|
-
lo >>> 8 & 0xff,
|
|
1487
|
-
lo >>> 16 & 0xff,
|
|
1625
|
+
(lo >>> 8) & 0xff,
|
|
1626
|
+
(lo >>> 16) & 0xff,
|
|
1488
1627
|
lo >>> 24,
|
|
1489
1628
|
hi & 0xff,
|
|
1490
|
-
hi >>> 8 & 0xff,
|
|
1491
|
-
hi >>> 16 & 0xff,
|
|
1492
|
-
hi >>> 24
|
|
1629
|
+
(hi >>> 8) & 0xff,
|
|
1630
|
+
(hi >>> 16) & 0xff,
|
|
1631
|
+
hi >>> 24,
|
|
1493
1632
|
];
|
|
1494
1633
|
};
|
|
1495
1634
|
|
|
@@ -1503,13 +1642,13 @@ LongPrototype.toBytesBE = function toBytesBE() {
|
|
|
1503
1642
|
lo = this.low;
|
|
1504
1643
|
return [
|
|
1505
1644
|
hi >>> 24,
|
|
1506
|
-
hi >>> 16 & 0xff,
|
|
1507
|
-
hi >>> 8 & 0xff,
|
|
1645
|
+
(hi >>> 16) & 0xff,
|
|
1646
|
+
(hi >>> 8) & 0xff,
|
|
1508
1647
|
hi & 0xff,
|
|
1509
1648
|
lo >>> 24,
|
|
1510
|
-
lo >>> 16 & 0xff,
|
|
1511
|
-
lo >>> 8 & 0xff,
|
|
1512
|
-
lo & 0xff
|
|
1649
|
+
(lo >>> 16) & 0xff,
|
|
1650
|
+
(lo >>> 8) & 0xff,
|
|
1651
|
+
lo & 0xff,
|
|
1513
1652
|
];
|
|
1514
1653
|
};
|
|
1515
1654
|
|
|
@@ -1521,7 +1660,9 @@ LongPrototype.toBytesBE = function toBytesBE() {
|
|
|
1521
1660
|
* @returns {Long} The corresponding Long value
|
|
1522
1661
|
*/
|
|
1523
1662
|
Long.fromBytes = function fromBytes(bytes, unsigned, le) {
|
|
1524
|
-
return le
|
|
1663
|
+
return le
|
|
1664
|
+
? Long.fromBytesLE(bytes, unsigned)
|
|
1665
|
+
: Long.fromBytesBE(bytes, unsigned);
|
|
1525
1666
|
};
|
|
1526
1667
|
|
|
1527
1668
|
/**
|
|
@@ -1532,15 +1673,9 @@ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
|
|
|
1532
1673
|
*/
|
|
1533
1674
|
Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
|
|
1534
1675
|
return new Long(
|
|
1535
|
-
bytes[0] |
|
|
1536
|
-
bytes[
|
|
1537
|
-
|
|
1538
|
-
bytes[3] << 24,
|
|
1539
|
-
bytes[4] |
|
|
1540
|
-
bytes[5] << 8 |
|
|
1541
|
-
bytes[6] << 16 |
|
|
1542
|
-
bytes[7] << 24,
|
|
1543
|
-
unsigned
|
|
1676
|
+
bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24),
|
|
1677
|
+
bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24),
|
|
1678
|
+
unsigned,
|
|
1544
1679
|
);
|
|
1545
1680
|
};
|
|
1546
1681
|
|
|
@@ -1552,18 +1687,45 @@ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
|
|
|
1552
1687
|
*/
|
|
1553
1688
|
Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
|
|
1554
1689
|
return new Long(
|
|
1555
|
-
bytes[4] << 24 |
|
|
1556
|
-
bytes[
|
|
1557
|
-
|
|
1558
|
-
bytes[7],
|
|
1559
|
-
bytes[0] << 24 |
|
|
1560
|
-
bytes[1] << 16 |
|
|
1561
|
-
bytes[2] << 8 |
|
|
1562
|
-
bytes[3],
|
|
1563
|
-
unsigned
|
|
1690
|
+
(bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7],
|
|
1691
|
+
(bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3],
|
|
1692
|
+
unsigned,
|
|
1564
1693
|
);
|
|
1565
1694
|
};
|
|
1566
1695
|
|
|
1696
|
+
// Support conversion to/from BigInt where available
|
|
1697
|
+
if (typeof BigInt === "function") {
|
|
1698
|
+
/**
|
|
1699
|
+
* Returns a Long representing the given big integer.
|
|
1700
|
+
* @function
|
|
1701
|
+
* @param {number} value The big integer value
|
|
1702
|
+
* @param {boolean=} unsigned Whether unsigned or not, defaults to signed
|
|
1703
|
+
* @returns {!Long} The corresponding Long value
|
|
1704
|
+
*/
|
|
1705
|
+
Long.fromBigInt = function fromBigInt(value, unsigned) {
|
|
1706
|
+
var lowBits = Number(BigInt.asIntN(32, value));
|
|
1707
|
+
var highBits = Number(BigInt.asIntN(32, value >> BigInt(32)));
|
|
1708
|
+
return fromBits(lowBits, highBits, unsigned);
|
|
1709
|
+
};
|
|
1710
|
+
|
|
1711
|
+
// Override
|
|
1712
|
+
Long.fromValue = function fromValueWithBigInt(value, unsigned) {
|
|
1713
|
+
if (typeof value === "bigint") return fromBigInt(value, unsigned);
|
|
1714
|
+
return fromValue(value, unsigned);
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1717
|
+
/**
|
|
1718
|
+
* Converts the Long to its big integer representation.
|
|
1719
|
+
* @this {!Long}
|
|
1720
|
+
* @returns {bigint}
|
|
1721
|
+
*/
|
|
1722
|
+
LongPrototype.toBigInt = function toBigInt() {
|
|
1723
|
+
var lowBigInt = BigInt(this.low >>> 0);
|
|
1724
|
+
var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high);
|
|
1725
|
+
return (highBigInt << BigInt(32)) | lowBigInt;
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1567
1729
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
1568
1730
|
|
|
1569
1731
|
function getDefaultExportFromCjs (x) {
|
|
@@ -4399,12 +4561,12 @@ const Struct = {
|
|
|
4399
4561
|
return obj;
|
|
4400
4562
|
},
|
|
4401
4563
|
create(base) {
|
|
4402
|
-
return Struct.fromPartial(base !== null && base !==
|
|
4564
|
+
return Struct.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
4403
4565
|
},
|
|
4404
4566
|
fromPartial(object) {
|
|
4405
4567
|
var _a;
|
|
4406
4568
|
const message = createBaseStruct();
|
|
4407
|
-
message.fields = Object.entries((_a = object.fields) !== null && _a !==
|
|
4569
|
+
message.fields = Object.entries((_a = object.fields) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
|
|
4408
4570
|
if (value !== undefined) {
|
|
4409
4571
|
acc[key] = value;
|
|
4410
4572
|
}
|
|
@@ -4472,7 +4634,7 @@ const Struct_FieldsEntry = {
|
|
|
4472
4634
|
return message;
|
|
4473
4635
|
},
|
|
4474
4636
|
fromJSON(object) {
|
|
4475
|
-
return { key: isSet$2(object.key) ? String(object.key) : "", value: isSet$2(object === null || object ===
|
|
4637
|
+
return { key: isSet$2(object.key) ? String(object.key) : "", value: isSet$2(object === null || object === void 0 ? void 0 : object.value) ? object.value : undefined };
|
|
4476
4638
|
},
|
|
4477
4639
|
toJSON(message) {
|
|
4478
4640
|
const obj = {};
|
|
@@ -4485,13 +4647,13 @@ const Struct_FieldsEntry = {
|
|
|
4485
4647
|
return obj;
|
|
4486
4648
|
},
|
|
4487
4649
|
create(base) {
|
|
4488
|
-
return Struct_FieldsEntry.fromPartial(base !== null && base !==
|
|
4650
|
+
return Struct_FieldsEntry.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
4489
4651
|
},
|
|
4490
4652
|
fromPartial(object) {
|
|
4491
4653
|
var _a, _b;
|
|
4492
4654
|
const message = createBaseStruct_FieldsEntry();
|
|
4493
|
-
message.key = (_a = object.key) !== null && _a !==
|
|
4494
|
-
message.value = (_b = object.value) !== null && _b !==
|
|
4655
|
+
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
|
|
4656
|
+
message.value = (_b = object.value) !== null && _b !== void 0 ? _b : undefined;
|
|
4495
4657
|
return message;
|
|
4496
4658
|
},
|
|
4497
4659
|
};
|
|
@@ -4611,17 +4773,17 @@ const Value = {
|
|
|
4611
4773
|
return obj;
|
|
4612
4774
|
},
|
|
4613
4775
|
create(base) {
|
|
4614
|
-
return Value.fromPartial(base !== null && base !==
|
|
4776
|
+
return Value.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
4615
4777
|
},
|
|
4616
4778
|
fromPartial(object) {
|
|
4617
4779
|
var _a, _b, _c, _d, _e, _f;
|
|
4618
4780
|
const message = createBaseValue();
|
|
4619
|
-
message.nullValue = (_a = object.nullValue) !== null && _a !==
|
|
4620
|
-
message.numberValue = (_b = object.numberValue) !== null && _b !==
|
|
4621
|
-
message.stringValue = (_c = object.stringValue) !== null && _c !==
|
|
4622
|
-
message.boolValue = (_d = object.boolValue) !== null && _d !==
|
|
4623
|
-
message.structValue = (_e = object.structValue) !== null && _e !==
|
|
4624
|
-
message.listValue = (_f = object.listValue) !== null && _f !==
|
|
4781
|
+
message.nullValue = (_a = object.nullValue) !== null && _a !== void 0 ? _a : undefined;
|
|
4782
|
+
message.numberValue = (_b = object.numberValue) !== null && _b !== void 0 ? _b : undefined;
|
|
4783
|
+
message.stringValue = (_c = object.stringValue) !== null && _c !== void 0 ? _c : undefined;
|
|
4784
|
+
message.boolValue = (_d = object.boolValue) !== null && _d !== void 0 ? _d : undefined;
|
|
4785
|
+
message.structValue = (_e = object.structValue) !== null && _e !== void 0 ? _e : undefined;
|
|
4786
|
+
message.listValue = (_f = object.listValue) !== null && _f !== void 0 ? _f : undefined;
|
|
4625
4787
|
return message;
|
|
4626
4788
|
},
|
|
4627
4789
|
wrap(value) {
|
|
@@ -4653,19 +4815,19 @@ const Value = {
|
|
|
4653
4815
|
if (message.stringValue !== undefined) {
|
|
4654
4816
|
return message.stringValue;
|
|
4655
4817
|
}
|
|
4656
|
-
else if ((message === null || message ===
|
|
4818
|
+
else if ((message === null || message === void 0 ? void 0 : message.numberValue) !== undefined) {
|
|
4657
4819
|
return message.numberValue;
|
|
4658
4820
|
}
|
|
4659
|
-
else if ((message === null || message ===
|
|
4821
|
+
else if ((message === null || message === void 0 ? void 0 : message.boolValue) !== undefined) {
|
|
4660
4822
|
return message.boolValue;
|
|
4661
4823
|
}
|
|
4662
|
-
else if ((message === null || message ===
|
|
4824
|
+
else if ((message === null || message === void 0 ? void 0 : message.structValue) !== undefined) {
|
|
4663
4825
|
return message.structValue;
|
|
4664
4826
|
}
|
|
4665
|
-
else if ((message === null || message ===
|
|
4827
|
+
else if ((message === null || message === void 0 ? void 0 : message.listValue) !== undefined) {
|
|
4666
4828
|
return message.listValue;
|
|
4667
4829
|
}
|
|
4668
|
-
else if ((message === null || message ===
|
|
4830
|
+
else if ((message === null || message === void 0 ? void 0 : message.nullValue) !== undefined) {
|
|
4669
4831
|
return null;
|
|
4670
4832
|
}
|
|
4671
4833
|
return undefined;
|
|
@@ -4703,32 +4865,32 @@ const ListValue = {
|
|
|
4703
4865
|
return message;
|
|
4704
4866
|
},
|
|
4705
4867
|
fromJSON(object) {
|
|
4706
|
-
return { values: Array.isArray(object === null || object ===
|
|
4868
|
+
return { values: Array.isArray(object === null || object === void 0 ? void 0 : object.values) ? [...object.values] : [] };
|
|
4707
4869
|
},
|
|
4708
4870
|
toJSON(message) {
|
|
4709
4871
|
var _a;
|
|
4710
4872
|
const obj = {};
|
|
4711
|
-
if ((_a = message.values) === null || _a ===
|
|
4873
|
+
if ((_a = message.values) === null || _a === void 0 ? void 0 : _a.length) {
|
|
4712
4874
|
obj.values = message.values;
|
|
4713
4875
|
}
|
|
4714
4876
|
return obj;
|
|
4715
4877
|
},
|
|
4716
4878
|
create(base) {
|
|
4717
|
-
return ListValue.fromPartial(base !== null && base !==
|
|
4879
|
+
return ListValue.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
4718
4880
|
},
|
|
4719
4881
|
fromPartial(object) {
|
|
4720
4882
|
var _a;
|
|
4721
4883
|
const message = createBaseListValue();
|
|
4722
|
-
message.values = ((_a = object.values) === null || _a ===
|
|
4884
|
+
message.values = ((_a = object.values) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
|
|
4723
4885
|
return message;
|
|
4724
4886
|
},
|
|
4725
4887
|
wrap(array) {
|
|
4726
4888
|
const result = createBaseListValue();
|
|
4727
|
-
result.values = array !== null && array !==
|
|
4889
|
+
result.values = array !== null && array !== void 0 ? array : [];
|
|
4728
4890
|
return result;
|
|
4729
4891
|
},
|
|
4730
4892
|
unwrap(message) {
|
|
4731
|
-
if ((message === null || message ===
|
|
4893
|
+
if ((message === null || message === void 0 ? void 0 : message.hasOwnProperty("values")) && Array.isArray(message.values)) {
|
|
4732
4894
|
return message.values;
|
|
4733
4895
|
}
|
|
4734
4896
|
else {
|
|
@@ -4744,357 +4906,6 @@ function isSet$2(value) {
|
|
|
4744
4906
|
}
|
|
4745
4907
|
|
|
4746
4908
|
/* eslint-disable */
|
|
4747
|
-
function createBaseResolveAllRequest() {
|
|
4748
|
-
return { context: undefined };
|
|
4749
|
-
}
|
|
4750
|
-
const ResolveAllRequest = {
|
|
4751
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
4752
|
-
if (message.context !== undefined) {
|
|
4753
|
-
Struct.encode(Struct.wrap(message.context), writer.uint32(10).fork()).ldelim();
|
|
4754
|
-
}
|
|
4755
|
-
return writer;
|
|
4756
|
-
},
|
|
4757
|
-
decode(input, length) {
|
|
4758
|
-
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
4759
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
4760
|
-
const message = createBaseResolveAllRequest();
|
|
4761
|
-
while (reader.pos < end) {
|
|
4762
|
-
const tag = reader.uint32();
|
|
4763
|
-
switch (tag >>> 3) {
|
|
4764
|
-
case 1:
|
|
4765
|
-
if (tag !== 10) {
|
|
4766
|
-
break;
|
|
4767
|
-
}
|
|
4768
|
-
message.context = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
4769
|
-
continue;
|
|
4770
|
-
}
|
|
4771
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
4772
|
-
break;
|
|
4773
|
-
}
|
|
4774
|
-
reader.skipType(tag & 7);
|
|
4775
|
-
}
|
|
4776
|
-
return message;
|
|
4777
|
-
},
|
|
4778
|
-
fromJSON(object) {
|
|
4779
|
-
return { context: isObject$1(object.context) ? object.context : undefined };
|
|
4780
|
-
},
|
|
4781
|
-
toJSON(message) {
|
|
4782
|
-
const obj = {};
|
|
4783
|
-
if (message.context !== undefined) {
|
|
4784
|
-
obj.context = message.context;
|
|
4785
|
-
}
|
|
4786
|
-
return obj;
|
|
4787
|
-
},
|
|
4788
|
-
create(base) {
|
|
4789
|
-
return ResolveAllRequest.fromPartial(base !== null && base !== undefined ? base : {});
|
|
4790
|
-
},
|
|
4791
|
-
fromPartial(object) {
|
|
4792
|
-
var _a;
|
|
4793
|
-
const message = createBaseResolveAllRequest();
|
|
4794
|
-
message.context = (_a = object.context) !== null && _a !== undefined ? _a : undefined;
|
|
4795
|
-
return message;
|
|
4796
|
-
},
|
|
4797
|
-
};
|
|
4798
|
-
function createBaseResolveAllResponse() {
|
|
4799
|
-
return { flags: {}, metadata: undefined };
|
|
4800
|
-
}
|
|
4801
|
-
const ResolveAllResponse = {
|
|
4802
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
4803
|
-
Object.entries(message.flags).forEach(([key, value]) => {
|
|
4804
|
-
ResolveAllResponse_FlagsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
|
|
4805
|
-
});
|
|
4806
|
-
if (message.metadata !== undefined) {
|
|
4807
|
-
Struct.encode(Struct.wrap(message.metadata), writer.uint32(18).fork()).ldelim();
|
|
4808
|
-
}
|
|
4809
|
-
return writer;
|
|
4810
|
-
},
|
|
4811
|
-
decode(input, length) {
|
|
4812
|
-
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
4813
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
4814
|
-
const message = createBaseResolveAllResponse();
|
|
4815
|
-
while (reader.pos < end) {
|
|
4816
|
-
const tag = reader.uint32();
|
|
4817
|
-
switch (tag >>> 3) {
|
|
4818
|
-
case 1:
|
|
4819
|
-
if (tag !== 10) {
|
|
4820
|
-
break;
|
|
4821
|
-
}
|
|
4822
|
-
const entry1 = ResolveAllResponse_FlagsEntry.decode(reader, reader.uint32());
|
|
4823
|
-
if (entry1.value !== undefined) {
|
|
4824
|
-
message.flags[entry1.key] = entry1.value;
|
|
4825
|
-
}
|
|
4826
|
-
continue;
|
|
4827
|
-
case 2:
|
|
4828
|
-
if (tag !== 18) {
|
|
4829
|
-
break;
|
|
4830
|
-
}
|
|
4831
|
-
message.metadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
4832
|
-
continue;
|
|
4833
|
-
}
|
|
4834
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
4835
|
-
break;
|
|
4836
|
-
}
|
|
4837
|
-
reader.skipType(tag & 7);
|
|
4838
|
-
}
|
|
4839
|
-
return message;
|
|
4840
|
-
},
|
|
4841
|
-
fromJSON(object) {
|
|
4842
|
-
return {
|
|
4843
|
-
flags: isObject$1(object.flags)
|
|
4844
|
-
? Object.entries(object.flags).reduce((acc, [key, value]) => {
|
|
4845
|
-
acc[key] = AnyFlag.fromJSON(value);
|
|
4846
|
-
return acc;
|
|
4847
|
-
}, {})
|
|
4848
|
-
: {},
|
|
4849
|
-
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
4850
|
-
};
|
|
4851
|
-
},
|
|
4852
|
-
toJSON(message) {
|
|
4853
|
-
const obj = {};
|
|
4854
|
-
if (message.flags) {
|
|
4855
|
-
const entries = Object.entries(message.flags);
|
|
4856
|
-
if (entries.length > 0) {
|
|
4857
|
-
obj.flags = {};
|
|
4858
|
-
entries.forEach(([k, v]) => {
|
|
4859
|
-
obj.flags[k] = AnyFlag.toJSON(v);
|
|
4860
|
-
});
|
|
4861
|
-
}
|
|
4862
|
-
}
|
|
4863
|
-
if (message.metadata !== undefined) {
|
|
4864
|
-
obj.metadata = message.metadata;
|
|
4865
|
-
}
|
|
4866
|
-
return obj;
|
|
4867
|
-
},
|
|
4868
|
-
create(base) {
|
|
4869
|
-
return ResolveAllResponse.fromPartial(base !== null && base !== undefined ? base : {});
|
|
4870
|
-
},
|
|
4871
|
-
fromPartial(object) {
|
|
4872
|
-
var _a, _b;
|
|
4873
|
-
const message = createBaseResolveAllResponse();
|
|
4874
|
-
message.flags = Object.entries((_a = object.flags) !== null && _a !== undefined ? _a : {}).reduce((acc, [key, value]) => {
|
|
4875
|
-
if (value !== undefined) {
|
|
4876
|
-
acc[key] = AnyFlag.fromPartial(value);
|
|
4877
|
-
}
|
|
4878
|
-
return acc;
|
|
4879
|
-
}, {});
|
|
4880
|
-
message.metadata = (_b = object.metadata) !== null && _b !== undefined ? _b : undefined;
|
|
4881
|
-
return message;
|
|
4882
|
-
},
|
|
4883
|
-
};
|
|
4884
|
-
function createBaseResolveAllResponse_FlagsEntry() {
|
|
4885
|
-
return { key: "", value: undefined };
|
|
4886
|
-
}
|
|
4887
|
-
const ResolveAllResponse_FlagsEntry = {
|
|
4888
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
4889
|
-
if (message.key !== "") {
|
|
4890
|
-
writer.uint32(10).string(message.key);
|
|
4891
|
-
}
|
|
4892
|
-
if (message.value !== undefined) {
|
|
4893
|
-
AnyFlag.encode(message.value, writer.uint32(18).fork()).ldelim();
|
|
4894
|
-
}
|
|
4895
|
-
return writer;
|
|
4896
|
-
},
|
|
4897
|
-
decode(input, length) {
|
|
4898
|
-
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
4899
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
4900
|
-
const message = createBaseResolveAllResponse_FlagsEntry();
|
|
4901
|
-
while (reader.pos < end) {
|
|
4902
|
-
const tag = reader.uint32();
|
|
4903
|
-
switch (tag >>> 3) {
|
|
4904
|
-
case 1:
|
|
4905
|
-
if (tag !== 10) {
|
|
4906
|
-
break;
|
|
4907
|
-
}
|
|
4908
|
-
message.key = reader.string();
|
|
4909
|
-
continue;
|
|
4910
|
-
case 2:
|
|
4911
|
-
if (tag !== 18) {
|
|
4912
|
-
break;
|
|
4913
|
-
}
|
|
4914
|
-
message.value = AnyFlag.decode(reader, reader.uint32());
|
|
4915
|
-
continue;
|
|
4916
|
-
}
|
|
4917
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
4918
|
-
break;
|
|
4919
|
-
}
|
|
4920
|
-
reader.skipType(tag & 7);
|
|
4921
|
-
}
|
|
4922
|
-
return message;
|
|
4923
|
-
},
|
|
4924
|
-
fromJSON(object) {
|
|
4925
|
-
return {
|
|
4926
|
-
key: isSet$1(object.key) ? String(object.key) : "",
|
|
4927
|
-
value: isSet$1(object.value) ? AnyFlag.fromJSON(object.value) : undefined,
|
|
4928
|
-
};
|
|
4929
|
-
},
|
|
4930
|
-
toJSON(message) {
|
|
4931
|
-
const obj = {};
|
|
4932
|
-
if (message.key !== "") {
|
|
4933
|
-
obj.key = message.key;
|
|
4934
|
-
}
|
|
4935
|
-
if (message.value !== undefined) {
|
|
4936
|
-
obj.value = AnyFlag.toJSON(message.value);
|
|
4937
|
-
}
|
|
4938
|
-
return obj;
|
|
4939
|
-
},
|
|
4940
|
-
create(base) {
|
|
4941
|
-
return ResolveAllResponse_FlagsEntry.fromPartial(base !== null && base !== undefined ? base : {});
|
|
4942
|
-
},
|
|
4943
|
-
fromPartial(object) {
|
|
4944
|
-
var _a;
|
|
4945
|
-
const message = createBaseResolveAllResponse_FlagsEntry();
|
|
4946
|
-
message.key = (_a = object.key) !== null && _a !== undefined ? _a : "";
|
|
4947
|
-
message.value = (object.value !== undefined && object.value !== null)
|
|
4948
|
-
? AnyFlag.fromPartial(object.value)
|
|
4949
|
-
: undefined;
|
|
4950
|
-
return message;
|
|
4951
|
-
},
|
|
4952
|
-
};
|
|
4953
|
-
function createBaseAnyFlag() {
|
|
4954
|
-
return {
|
|
4955
|
-
reason: "",
|
|
4956
|
-
variant: "",
|
|
4957
|
-
boolValue: undefined,
|
|
4958
|
-
stringValue: undefined,
|
|
4959
|
-
doubleValue: undefined,
|
|
4960
|
-
objectValue: undefined,
|
|
4961
|
-
metadata: undefined,
|
|
4962
|
-
};
|
|
4963
|
-
}
|
|
4964
|
-
const AnyFlag = {
|
|
4965
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
4966
|
-
if (message.reason !== "") {
|
|
4967
|
-
writer.uint32(10).string(message.reason);
|
|
4968
|
-
}
|
|
4969
|
-
if (message.variant !== "") {
|
|
4970
|
-
writer.uint32(18).string(message.variant);
|
|
4971
|
-
}
|
|
4972
|
-
if (message.boolValue !== undefined) {
|
|
4973
|
-
writer.uint32(24).bool(message.boolValue);
|
|
4974
|
-
}
|
|
4975
|
-
if (message.stringValue !== undefined) {
|
|
4976
|
-
writer.uint32(34).string(message.stringValue);
|
|
4977
|
-
}
|
|
4978
|
-
if (message.doubleValue !== undefined) {
|
|
4979
|
-
writer.uint32(41).double(message.doubleValue);
|
|
4980
|
-
}
|
|
4981
|
-
if (message.objectValue !== undefined) {
|
|
4982
|
-
Struct.encode(Struct.wrap(message.objectValue), writer.uint32(50).fork()).ldelim();
|
|
4983
|
-
}
|
|
4984
|
-
if (message.metadata !== undefined) {
|
|
4985
|
-
Struct.encode(Struct.wrap(message.metadata), writer.uint32(58).fork()).ldelim();
|
|
4986
|
-
}
|
|
4987
|
-
return writer;
|
|
4988
|
-
},
|
|
4989
|
-
decode(input, length) {
|
|
4990
|
-
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
4991
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
4992
|
-
const message = createBaseAnyFlag();
|
|
4993
|
-
while (reader.pos < end) {
|
|
4994
|
-
const tag = reader.uint32();
|
|
4995
|
-
switch (tag >>> 3) {
|
|
4996
|
-
case 1:
|
|
4997
|
-
if (tag !== 10) {
|
|
4998
|
-
break;
|
|
4999
|
-
}
|
|
5000
|
-
message.reason = reader.string();
|
|
5001
|
-
continue;
|
|
5002
|
-
case 2:
|
|
5003
|
-
if (tag !== 18) {
|
|
5004
|
-
break;
|
|
5005
|
-
}
|
|
5006
|
-
message.variant = reader.string();
|
|
5007
|
-
continue;
|
|
5008
|
-
case 3:
|
|
5009
|
-
if (tag !== 24) {
|
|
5010
|
-
break;
|
|
5011
|
-
}
|
|
5012
|
-
message.boolValue = reader.bool();
|
|
5013
|
-
continue;
|
|
5014
|
-
case 4:
|
|
5015
|
-
if (tag !== 34) {
|
|
5016
|
-
break;
|
|
5017
|
-
}
|
|
5018
|
-
message.stringValue = reader.string();
|
|
5019
|
-
continue;
|
|
5020
|
-
case 5:
|
|
5021
|
-
if (tag !== 41) {
|
|
5022
|
-
break;
|
|
5023
|
-
}
|
|
5024
|
-
message.doubleValue = reader.double();
|
|
5025
|
-
continue;
|
|
5026
|
-
case 6:
|
|
5027
|
-
if (tag !== 50) {
|
|
5028
|
-
break;
|
|
5029
|
-
}
|
|
5030
|
-
message.objectValue = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
5031
|
-
continue;
|
|
5032
|
-
case 7:
|
|
5033
|
-
if (tag !== 58) {
|
|
5034
|
-
break;
|
|
5035
|
-
}
|
|
5036
|
-
message.metadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
5037
|
-
continue;
|
|
5038
|
-
}
|
|
5039
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
5040
|
-
break;
|
|
5041
|
-
}
|
|
5042
|
-
reader.skipType(tag & 7);
|
|
5043
|
-
}
|
|
5044
|
-
return message;
|
|
5045
|
-
},
|
|
5046
|
-
fromJSON(object) {
|
|
5047
|
-
return {
|
|
5048
|
-
reason: isSet$1(object.reason) ? String(object.reason) : "",
|
|
5049
|
-
variant: isSet$1(object.variant) ? String(object.variant) : "",
|
|
5050
|
-
boolValue: isSet$1(object.boolValue) ? Boolean(object.boolValue) : undefined,
|
|
5051
|
-
stringValue: isSet$1(object.stringValue) ? String(object.stringValue) : undefined,
|
|
5052
|
-
doubleValue: isSet$1(object.doubleValue) ? Number(object.doubleValue) : undefined,
|
|
5053
|
-
objectValue: isObject$1(object.objectValue) ? object.objectValue : undefined,
|
|
5054
|
-
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
5055
|
-
};
|
|
5056
|
-
},
|
|
5057
|
-
toJSON(message) {
|
|
5058
|
-
const obj = {};
|
|
5059
|
-
if (message.reason !== "") {
|
|
5060
|
-
obj.reason = message.reason;
|
|
5061
|
-
}
|
|
5062
|
-
if (message.variant !== "") {
|
|
5063
|
-
obj.variant = message.variant;
|
|
5064
|
-
}
|
|
5065
|
-
if (message.boolValue !== undefined) {
|
|
5066
|
-
obj.boolValue = message.boolValue;
|
|
5067
|
-
}
|
|
5068
|
-
if (message.stringValue !== undefined) {
|
|
5069
|
-
obj.stringValue = message.stringValue;
|
|
5070
|
-
}
|
|
5071
|
-
if (message.doubleValue !== undefined) {
|
|
5072
|
-
obj.doubleValue = message.doubleValue;
|
|
5073
|
-
}
|
|
5074
|
-
if (message.objectValue !== undefined) {
|
|
5075
|
-
obj.objectValue = message.objectValue;
|
|
5076
|
-
}
|
|
5077
|
-
if (message.metadata !== undefined) {
|
|
5078
|
-
obj.metadata = message.metadata;
|
|
5079
|
-
}
|
|
5080
|
-
return obj;
|
|
5081
|
-
},
|
|
5082
|
-
create(base) {
|
|
5083
|
-
return AnyFlag.fromPartial(base !== null && base !== undefined ? base : {});
|
|
5084
|
-
},
|
|
5085
|
-
fromPartial(object) {
|
|
5086
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5087
|
-
const message = createBaseAnyFlag();
|
|
5088
|
-
message.reason = (_a = object.reason) !== null && _a !== undefined ? _a : "";
|
|
5089
|
-
message.variant = (_b = object.variant) !== null && _b !== undefined ? _b : "";
|
|
5090
|
-
message.boolValue = (_c = object.boolValue) !== null && _c !== undefined ? _c : undefined;
|
|
5091
|
-
message.stringValue = (_d = object.stringValue) !== null && _d !== undefined ? _d : undefined;
|
|
5092
|
-
message.doubleValue = (_e = object.doubleValue) !== null && _e !== undefined ? _e : undefined;
|
|
5093
|
-
message.objectValue = (_f = object.objectValue) !== null && _f !== undefined ? _f : undefined;
|
|
5094
|
-
message.metadata = (_g = object.metadata) !== null && _g !== undefined ? _g : undefined;
|
|
5095
|
-
return message;
|
|
5096
|
-
},
|
|
5097
|
-
};
|
|
5098
4909
|
function createBaseResolveBooleanRequest() {
|
|
5099
4910
|
return { flagKey: "", context: undefined };
|
|
5100
4911
|
}
|
|
@@ -5152,28 +4963,28 @@ const ResolveBooleanRequest = {
|
|
|
5152
4963
|
return obj;
|
|
5153
4964
|
},
|
|
5154
4965
|
create(base) {
|
|
5155
|
-
return ResolveBooleanRequest.fromPartial(base !== null && base !==
|
|
4966
|
+
return ResolveBooleanRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5156
4967
|
},
|
|
5157
4968
|
fromPartial(object) {
|
|
5158
4969
|
var _a, _b;
|
|
5159
4970
|
const message = createBaseResolveBooleanRequest();
|
|
5160
|
-
message.flagKey = (_a = object.flagKey) !== null && _a !==
|
|
5161
|
-
message.context = (_b = object.context) !== null && _b !==
|
|
4971
|
+
message.flagKey = (_a = object.flagKey) !== null && _a !== void 0 ? _a : "";
|
|
4972
|
+
message.context = (_b = object.context) !== null && _b !== void 0 ? _b : undefined;
|
|
5162
4973
|
return message;
|
|
5163
4974
|
},
|
|
5164
4975
|
};
|
|
5165
4976
|
function createBaseResolveBooleanResponse() {
|
|
5166
|
-
return { value:
|
|
4977
|
+
return { value: undefined, reason: "", variant: undefined, metadata: undefined };
|
|
5167
4978
|
}
|
|
5168
4979
|
const ResolveBooleanResponse = {
|
|
5169
4980
|
encode(message, writer = _m0.Writer.create()) {
|
|
5170
|
-
if (message.value
|
|
4981
|
+
if (message.value !== undefined) {
|
|
5171
4982
|
writer.uint32(8).bool(message.value);
|
|
5172
4983
|
}
|
|
5173
4984
|
if (message.reason !== "") {
|
|
5174
4985
|
writer.uint32(18).string(message.reason);
|
|
5175
4986
|
}
|
|
5176
|
-
if (message.variant !==
|
|
4987
|
+
if (message.variant !== undefined) {
|
|
5177
4988
|
writer.uint32(26).string(message.variant);
|
|
5178
4989
|
}
|
|
5179
4990
|
if (message.metadata !== undefined) {
|
|
@@ -5222,21 +5033,21 @@ const ResolveBooleanResponse = {
|
|
|
5222
5033
|
},
|
|
5223
5034
|
fromJSON(object) {
|
|
5224
5035
|
return {
|
|
5225
|
-
value: isSet$1(object.value) ? Boolean(object.value) :
|
|
5036
|
+
value: isSet$1(object.value) ? Boolean(object.value) : undefined,
|
|
5226
5037
|
reason: isSet$1(object.reason) ? String(object.reason) : "",
|
|
5227
|
-
variant: isSet$1(object.variant) ? String(object.variant) :
|
|
5038
|
+
variant: isSet$1(object.variant) ? String(object.variant) : undefined,
|
|
5228
5039
|
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
5229
5040
|
};
|
|
5230
5041
|
},
|
|
5231
5042
|
toJSON(message) {
|
|
5232
5043
|
const obj = {};
|
|
5233
|
-
if (message.value
|
|
5044
|
+
if (message.value !== undefined) {
|
|
5234
5045
|
obj.value = message.value;
|
|
5235
5046
|
}
|
|
5236
5047
|
if (message.reason !== "") {
|
|
5237
5048
|
obj.reason = message.reason;
|
|
5238
5049
|
}
|
|
5239
|
-
if (message.variant !==
|
|
5050
|
+
if (message.variant !== undefined) {
|
|
5240
5051
|
obj.variant = message.variant;
|
|
5241
5052
|
}
|
|
5242
5053
|
if (message.metadata !== undefined) {
|
|
@@ -5245,15 +5056,15 @@ const ResolveBooleanResponse = {
|
|
|
5245
5056
|
return obj;
|
|
5246
5057
|
},
|
|
5247
5058
|
create(base) {
|
|
5248
|
-
return ResolveBooleanResponse.fromPartial(base !== null && base !==
|
|
5059
|
+
return ResolveBooleanResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5249
5060
|
},
|
|
5250
5061
|
fromPartial(object) {
|
|
5251
5062
|
var _a, _b, _c, _d;
|
|
5252
5063
|
const message = createBaseResolveBooleanResponse();
|
|
5253
|
-
message.value = (_a = object.value) !== null && _a !==
|
|
5254
|
-
message.reason = (_b = object.reason) !== null && _b !==
|
|
5255
|
-
message.variant = (_c = object.variant) !== null && _c !==
|
|
5256
|
-
message.metadata = (_d = object.metadata) !== null && _d !==
|
|
5064
|
+
message.value = (_a = object.value) !== null && _a !== void 0 ? _a : undefined;
|
|
5065
|
+
message.reason = (_b = object.reason) !== null && _b !== void 0 ? _b : "";
|
|
5066
|
+
message.variant = (_c = object.variant) !== null && _c !== void 0 ? _c : undefined;
|
|
5067
|
+
message.metadata = (_d = object.metadata) !== null && _d !== void 0 ? _d : undefined;
|
|
5257
5068
|
return message;
|
|
5258
5069
|
},
|
|
5259
5070
|
};
|
|
@@ -5314,28 +5125,28 @@ const ResolveStringRequest = {
|
|
|
5314
5125
|
return obj;
|
|
5315
5126
|
},
|
|
5316
5127
|
create(base) {
|
|
5317
|
-
return ResolveStringRequest.fromPartial(base !== null && base !==
|
|
5128
|
+
return ResolveStringRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5318
5129
|
},
|
|
5319
5130
|
fromPartial(object) {
|
|
5320
5131
|
var _a, _b;
|
|
5321
5132
|
const message = createBaseResolveStringRequest();
|
|
5322
|
-
message.flagKey = (_a = object.flagKey) !== null && _a !==
|
|
5323
|
-
message.context = (_b = object.context) !== null && _b !==
|
|
5133
|
+
message.flagKey = (_a = object.flagKey) !== null && _a !== void 0 ? _a : "";
|
|
5134
|
+
message.context = (_b = object.context) !== null && _b !== void 0 ? _b : undefined;
|
|
5324
5135
|
return message;
|
|
5325
5136
|
},
|
|
5326
5137
|
};
|
|
5327
5138
|
function createBaseResolveStringResponse() {
|
|
5328
|
-
return { value:
|
|
5139
|
+
return { value: undefined, reason: "", variant: undefined, metadata: undefined };
|
|
5329
5140
|
}
|
|
5330
5141
|
const ResolveStringResponse = {
|
|
5331
5142
|
encode(message, writer = _m0.Writer.create()) {
|
|
5332
|
-
if (message.value !==
|
|
5143
|
+
if (message.value !== undefined) {
|
|
5333
5144
|
writer.uint32(10).string(message.value);
|
|
5334
5145
|
}
|
|
5335
5146
|
if (message.reason !== "") {
|
|
5336
5147
|
writer.uint32(18).string(message.reason);
|
|
5337
5148
|
}
|
|
5338
|
-
if (message.variant !==
|
|
5149
|
+
if (message.variant !== undefined) {
|
|
5339
5150
|
writer.uint32(26).string(message.variant);
|
|
5340
5151
|
}
|
|
5341
5152
|
if (message.metadata !== undefined) {
|
|
@@ -5384,21 +5195,21 @@ const ResolveStringResponse = {
|
|
|
5384
5195
|
},
|
|
5385
5196
|
fromJSON(object) {
|
|
5386
5197
|
return {
|
|
5387
|
-
value: isSet$1(object.value) ? String(object.value) :
|
|
5198
|
+
value: isSet$1(object.value) ? String(object.value) : undefined,
|
|
5388
5199
|
reason: isSet$1(object.reason) ? String(object.reason) : "",
|
|
5389
|
-
variant: isSet$1(object.variant) ? String(object.variant) :
|
|
5200
|
+
variant: isSet$1(object.variant) ? String(object.variant) : undefined,
|
|
5390
5201
|
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
5391
5202
|
};
|
|
5392
5203
|
},
|
|
5393
5204
|
toJSON(message) {
|
|
5394
5205
|
const obj = {};
|
|
5395
|
-
if (message.value !==
|
|
5206
|
+
if (message.value !== undefined) {
|
|
5396
5207
|
obj.value = message.value;
|
|
5397
5208
|
}
|
|
5398
5209
|
if (message.reason !== "") {
|
|
5399
5210
|
obj.reason = message.reason;
|
|
5400
5211
|
}
|
|
5401
|
-
if (message.variant !==
|
|
5212
|
+
if (message.variant !== undefined) {
|
|
5402
5213
|
obj.variant = message.variant;
|
|
5403
5214
|
}
|
|
5404
5215
|
if (message.metadata !== undefined) {
|
|
@@ -5407,15 +5218,15 @@ const ResolveStringResponse = {
|
|
|
5407
5218
|
return obj;
|
|
5408
5219
|
},
|
|
5409
5220
|
create(base) {
|
|
5410
|
-
return ResolveStringResponse.fromPartial(base !== null && base !==
|
|
5221
|
+
return ResolveStringResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5411
5222
|
},
|
|
5412
5223
|
fromPartial(object) {
|
|
5413
5224
|
var _a, _b, _c, _d;
|
|
5414
5225
|
const message = createBaseResolveStringResponse();
|
|
5415
|
-
message.value = (_a = object.value) !== null && _a !==
|
|
5416
|
-
message.reason = (_b = object.reason) !== null && _b !==
|
|
5417
|
-
message.variant = (_c = object.variant) !== null && _c !==
|
|
5418
|
-
message.metadata = (_d = object.metadata) !== null && _d !==
|
|
5226
|
+
message.value = (_a = object.value) !== null && _a !== void 0 ? _a : undefined;
|
|
5227
|
+
message.reason = (_b = object.reason) !== null && _b !== void 0 ? _b : "";
|
|
5228
|
+
message.variant = (_c = object.variant) !== null && _c !== void 0 ? _c : undefined;
|
|
5229
|
+
message.metadata = (_d = object.metadata) !== null && _d !== void 0 ? _d : undefined;
|
|
5419
5230
|
return message;
|
|
5420
5231
|
},
|
|
5421
5232
|
};
|
|
@@ -5476,28 +5287,28 @@ const ResolveFloatRequest = {
|
|
|
5476
5287
|
return obj;
|
|
5477
5288
|
},
|
|
5478
5289
|
create(base) {
|
|
5479
|
-
return ResolveFloatRequest.fromPartial(base !== null && base !==
|
|
5290
|
+
return ResolveFloatRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5480
5291
|
},
|
|
5481
5292
|
fromPartial(object) {
|
|
5482
5293
|
var _a, _b;
|
|
5483
5294
|
const message = createBaseResolveFloatRequest();
|
|
5484
|
-
message.flagKey = (_a = object.flagKey) !== null && _a !==
|
|
5485
|
-
message.context = (_b = object.context) !== null && _b !==
|
|
5295
|
+
message.flagKey = (_a = object.flagKey) !== null && _a !== void 0 ? _a : "";
|
|
5296
|
+
message.context = (_b = object.context) !== null && _b !== void 0 ? _b : undefined;
|
|
5486
5297
|
return message;
|
|
5487
5298
|
},
|
|
5488
5299
|
};
|
|
5489
5300
|
function createBaseResolveFloatResponse() {
|
|
5490
|
-
return { value:
|
|
5301
|
+
return { value: undefined, reason: "", variant: undefined, metadata: undefined };
|
|
5491
5302
|
}
|
|
5492
5303
|
const ResolveFloatResponse = {
|
|
5493
5304
|
encode(message, writer = _m0.Writer.create()) {
|
|
5494
|
-
if (message.value !==
|
|
5305
|
+
if (message.value !== undefined) {
|
|
5495
5306
|
writer.uint32(9).double(message.value);
|
|
5496
5307
|
}
|
|
5497
5308
|
if (message.reason !== "") {
|
|
5498
5309
|
writer.uint32(18).string(message.reason);
|
|
5499
5310
|
}
|
|
5500
|
-
if (message.variant !==
|
|
5311
|
+
if (message.variant !== undefined) {
|
|
5501
5312
|
writer.uint32(26).string(message.variant);
|
|
5502
5313
|
}
|
|
5503
5314
|
if (message.metadata !== undefined) {
|
|
@@ -5546,21 +5357,21 @@ const ResolveFloatResponse = {
|
|
|
5546
5357
|
},
|
|
5547
5358
|
fromJSON(object) {
|
|
5548
5359
|
return {
|
|
5549
|
-
value: isSet$1(object.value) ? Number(object.value) :
|
|
5360
|
+
value: isSet$1(object.value) ? Number(object.value) : undefined,
|
|
5550
5361
|
reason: isSet$1(object.reason) ? String(object.reason) : "",
|
|
5551
|
-
variant: isSet$1(object.variant) ? String(object.variant) :
|
|
5362
|
+
variant: isSet$1(object.variant) ? String(object.variant) : undefined,
|
|
5552
5363
|
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
5553
5364
|
};
|
|
5554
5365
|
},
|
|
5555
5366
|
toJSON(message) {
|
|
5556
5367
|
const obj = {};
|
|
5557
|
-
if (message.value !==
|
|
5368
|
+
if (message.value !== undefined) {
|
|
5558
5369
|
obj.value = message.value;
|
|
5559
5370
|
}
|
|
5560
5371
|
if (message.reason !== "") {
|
|
5561
5372
|
obj.reason = message.reason;
|
|
5562
5373
|
}
|
|
5563
|
-
if (message.variant !==
|
|
5374
|
+
if (message.variant !== undefined) {
|
|
5564
5375
|
obj.variant = message.variant;
|
|
5565
5376
|
}
|
|
5566
5377
|
if (message.metadata !== undefined) {
|
|
@@ -5569,15 +5380,15 @@ const ResolveFloatResponse = {
|
|
|
5569
5380
|
return obj;
|
|
5570
5381
|
},
|
|
5571
5382
|
create(base) {
|
|
5572
|
-
return ResolveFloatResponse.fromPartial(base !== null && base !==
|
|
5383
|
+
return ResolveFloatResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5573
5384
|
},
|
|
5574
5385
|
fromPartial(object) {
|
|
5575
5386
|
var _a, _b, _c, _d;
|
|
5576
5387
|
const message = createBaseResolveFloatResponse();
|
|
5577
|
-
message.value = (_a = object.value) !== null && _a !==
|
|
5578
|
-
message.reason = (_b = object.reason) !== null && _b !==
|
|
5579
|
-
message.variant = (_c = object.variant) !== null && _c !==
|
|
5580
|
-
message.metadata = (_d = object.metadata) !== null && _d !==
|
|
5388
|
+
message.value = (_a = object.value) !== null && _a !== void 0 ? _a : undefined;
|
|
5389
|
+
message.reason = (_b = object.reason) !== null && _b !== void 0 ? _b : "";
|
|
5390
|
+
message.variant = (_c = object.variant) !== null && _c !== void 0 ? _c : undefined;
|
|
5391
|
+
message.metadata = (_d = object.metadata) !== null && _d !== void 0 ? _d : undefined;
|
|
5581
5392
|
return message;
|
|
5582
5393
|
},
|
|
5583
5394
|
};
|
|
@@ -5638,28 +5449,28 @@ const ResolveIntRequest = {
|
|
|
5638
5449
|
return obj;
|
|
5639
5450
|
},
|
|
5640
5451
|
create(base) {
|
|
5641
|
-
return ResolveIntRequest.fromPartial(base !== null && base !==
|
|
5452
|
+
return ResolveIntRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5642
5453
|
},
|
|
5643
5454
|
fromPartial(object) {
|
|
5644
5455
|
var _a, _b;
|
|
5645
5456
|
const message = createBaseResolveIntRequest();
|
|
5646
|
-
message.flagKey = (_a = object.flagKey) !== null && _a !==
|
|
5647
|
-
message.context = (_b = object.context) !== null && _b !==
|
|
5457
|
+
message.flagKey = (_a = object.flagKey) !== null && _a !== void 0 ? _a : "";
|
|
5458
|
+
message.context = (_b = object.context) !== null && _b !== void 0 ? _b : undefined;
|
|
5648
5459
|
return message;
|
|
5649
5460
|
},
|
|
5650
5461
|
};
|
|
5651
5462
|
function createBaseResolveIntResponse() {
|
|
5652
|
-
return { value:
|
|
5463
|
+
return { value: undefined, reason: "", variant: undefined, metadata: undefined };
|
|
5653
5464
|
}
|
|
5654
5465
|
const ResolveIntResponse = {
|
|
5655
5466
|
encode(message, writer = _m0.Writer.create()) {
|
|
5656
|
-
if (message.value !==
|
|
5467
|
+
if (message.value !== undefined) {
|
|
5657
5468
|
writer.uint32(8).int64(message.value);
|
|
5658
5469
|
}
|
|
5659
5470
|
if (message.reason !== "") {
|
|
5660
5471
|
writer.uint32(18).string(message.reason);
|
|
5661
5472
|
}
|
|
5662
|
-
if (message.variant !==
|
|
5473
|
+
if (message.variant !== undefined) {
|
|
5663
5474
|
writer.uint32(26).string(message.variant);
|
|
5664
5475
|
}
|
|
5665
5476
|
if (message.metadata !== undefined) {
|
|
@@ -5708,21 +5519,21 @@ const ResolveIntResponse = {
|
|
|
5708
5519
|
},
|
|
5709
5520
|
fromJSON(object) {
|
|
5710
5521
|
return {
|
|
5711
|
-
value: isSet$1(object.value) ? String(object.value) :
|
|
5522
|
+
value: isSet$1(object.value) ? String(object.value) : undefined,
|
|
5712
5523
|
reason: isSet$1(object.reason) ? String(object.reason) : "",
|
|
5713
|
-
variant: isSet$1(object.variant) ? String(object.variant) :
|
|
5524
|
+
variant: isSet$1(object.variant) ? String(object.variant) : undefined,
|
|
5714
5525
|
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
5715
5526
|
};
|
|
5716
5527
|
},
|
|
5717
5528
|
toJSON(message) {
|
|
5718
5529
|
const obj = {};
|
|
5719
|
-
if (message.value !==
|
|
5530
|
+
if (message.value !== undefined) {
|
|
5720
5531
|
obj.value = message.value;
|
|
5721
5532
|
}
|
|
5722
5533
|
if (message.reason !== "") {
|
|
5723
5534
|
obj.reason = message.reason;
|
|
5724
5535
|
}
|
|
5725
|
-
if (message.variant !==
|
|
5536
|
+
if (message.variant !== undefined) {
|
|
5726
5537
|
obj.variant = message.variant;
|
|
5727
5538
|
}
|
|
5728
5539
|
if (message.metadata !== undefined) {
|
|
@@ -5731,15 +5542,15 @@ const ResolveIntResponse = {
|
|
|
5731
5542
|
return obj;
|
|
5732
5543
|
},
|
|
5733
5544
|
create(base) {
|
|
5734
|
-
return ResolveIntResponse.fromPartial(base !== null && base !==
|
|
5545
|
+
return ResolveIntResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5735
5546
|
},
|
|
5736
5547
|
fromPartial(object) {
|
|
5737
5548
|
var _a, _b, _c, _d;
|
|
5738
5549
|
const message = createBaseResolveIntResponse();
|
|
5739
|
-
message.value = (_a = object.value) !== null && _a !==
|
|
5740
|
-
message.reason = (_b = object.reason) !== null && _b !==
|
|
5741
|
-
message.variant = (_c = object.variant) !== null && _c !==
|
|
5742
|
-
message.metadata = (_d = object.metadata) !== null && _d !==
|
|
5550
|
+
message.value = (_a = object.value) !== null && _a !== void 0 ? _a : undefined;
|
|
5551
|
+
message.reason = (_b = object.reason) !== null && _b !== void 0 ? _b : "";
|
|
5552
|
+
message.variant = (_c = object.variant) !== null && _c !== void 0 ? _c : undefined;
|
|
5553
|
+
message.metadata = (_d = object.metadata) !== null && _d !== void 0 ? _d : undefined;
|
|
5743
5554
|
return message;
|
|
5744
5555
|
},
|
|
5745
5556
|
};
|
|
@@ -5800,18 +5611,18 @@ const ResolveObjectRequest = {
|
|
|
5800
5611
|
return obj;
|
|
5801
5612
|
},
|
|
5802
5613
|
create(base) {
|
|
5803
|
-
return ResolveObjectRequest.fromPartial(base !== null && base !==
|
|
5614
|
+
return ResolveObjectRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5804
5615
|
},
|
|
5805
5616
|
fromPartial(object) {
|
|
5806
5617
|
var _a, _b;
|
|
5807
5618
|
const message = createBaseResolveObjectRequest();
|
|
5808
|
-
message.flagKey = (_a = object.flagKey) !== null && _a !==
|
|
5809
|
-
message.context = (_b = object.context) !== null && _b !==
|
|
5619
|
+
message.flagKey = (_a = object.flagKey) !== null && _a !== void 0 ? _a : "";
|
|
5620
|
+
message.context = (_b = object.context) !== null && _b !== void 0 ? _b : undefined;
|
|
5810
5621
|
return message;
|
|
5811
5622
|
},
|
|
5812
5623
|
};
|
|
5813
5624
|
function createBaseResolveObjectResponse() {
|
|
5814
|
-
return { value: undefined, reason: "", variant:
|
|
5625
|
+
return { value: undefined, reason: "", variant: undefined, metadata: undefined };
|
|
5815
5626
|
}
|
|
5816
5627
|
const ResolveObjectResponse = {
|
|
5817
5628
|
encode(message, writer = _m0.Writer.create()) {
|
|
@@ -5821,7 +5632,7 @@ const ResolveObjectResponse = {
|
|
|
5821
5632
|
if (message.reason !== "") {
|
|
5822
5633
|
writer.uint32(18).string(message.reason);
|
|
5823
5634
|
}
|
|
5824
|
-
if (message.variant !==
|
|
5635
|
+
if (message.variant !== undefined) {
|
|
5825
5636
|
writer.uint32(26).string(message.variant);
|
|
5826
5637
|
}
|
|
5827
5638
|
if (message.metadata !== undefined) {
|
|
@@ -5872,7 +5683,7 @@ const ResolveObjectResponse = {
|
|
|
5872
5683
|
return {
|
|
5873
5684
|
value: isObject$1(object.value) ? object.value : undefined,
|
|
5874
5685
|
reason: isSet$1(object.reason) ? String(object.reason) : "",
|
|
5875
|
-
variant: isSet$1(object.variant) ? String(object.variant) :
|
|
5686
|
+
variant: isSet$1(object.variant) ? String(object.variant) : undefined,
|
|
5876
5687
|
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
5877
5688
|
};
|
|
5878
5689
|
},
|
|
@@ -5884,7 +5695,7 @@ const ResolveObjectResponse = {
|
|
|
5884
5695
|
if (message.reason !== "") {
|
|
5885
5696
|
obj.reason = message.reason;
|
|
5886
5697
|
}
|
|
5887
|
-
if (message.variant !==
|
|
5698
|
+
if (message.variant !== undefined) {
|
|
5888
5699
|
obj.variant = message.variant;
|
|
5889
5700
|
}
|
|
5890
5701
|
if (message.metadata !== undefined) {
|
|
@@ -5893,15 +5704,15 @@ const ResolveObjectResponse = {
|
|
|
5893
5704
|
return obj;
|
|
5894
5705
|
},
|
|
5895
5706
|
create(base) {
|
|
5896
|
-
return ResolveObjectResponse.fromPartial(base !== null && base !==
|
|
5707
|
+
return ResolveObjectResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5897
5708
|
},
|
|
5898
5709
|
fromPartial(object) {
|
|
5899
5710
|
var _a, _b, _c, _d;
|
|
5900
5711
|
const message = createBaseResolveObjectResponse();
|
|
5901
|
-
message.value = (_a = object.value) !== null && _a !==
|
|
5902
|
-
message.reason = (_b = object.reason) !== null && _b !==
|
|
5903
|
-
message.variant = (_c = object.variant) !== null && _c !==
|
|
5904
|
-
message.metadata = (_d = object.metadata) !== null && _d !==
|
|
5712
|
+
message.value = (_a = object.value) !== null && _a !== void 0 ? _a : undefined;
|
|
5713
|
+
message.reason = (_b = object.reason) !== null && _b !== void 0 ? _b : "";
|
|
5714
|
+
message.variant = (_c = object.variant) !== null && _c !== void 0 ? _c : undefined;
|
|
5715
|
+
message.metadata = (_d = object.metadata) !== null && _d !== void 0 ? _d : undefined;
|
|
5905
5716
|
return message;
|
|
5906
5717
|
},
|
|
5907
5718
|
};
|
|
@@ -5962,13 +5773,13 @@ const EventStreamResponse = {
|
|
|
5962
5773
|
return obj;
|
|
5963
5774
|
},
|
|
5964
5775
|
create(base) {
|
|
5965
|
-
return EventStreamResponse.fromPartial(base !== null && base !==
|
|
5776
|
+
return EventStreamResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
5966
5777
|
},
|
|
5967
5778
|
fromPartial(object) {
|
|
5968
5779
|
var _a, _b;
|
|
5969
5780
|
const message = createBaseEventStreamResponse();
|
|
5970
|
-
message.type = (_a = object.type) !== null && _a !==
|
|
5971
|
-
message.data = (_b = object.data) !== null && _b !==
|
|
5781
|
+
message.type = (_a = object.type) !== null && _a !== void 0 ? _a : "";
|
|
5782
|
+
message.data = (_b = object.data) !== null && _b !== void 0 ? _b : undefined;
|
|
5972
5783
|
return message;
|
|
5973
5784
|
},
|
|
5974
5785
|
};
|
|
@@ -6000,7 +5811,7 @@ const EventStreamRequest = {
|
|
|
6000
5811
|
return obj;
|
|
6001
5812
|
},
|
|
6002
5813
|
create(base) {
|
|
6003
|
-
return EventStreamRequest.fromPartial(base !== null && base !==
|
|
5814
|
+
return EventStreamRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6004
5815
|
},
|
|
6005
5816
|
fromPartial(_) {
|
|
6006
5817
|
const message = createBaseEventStreamRequest();
|
|
@@ -6008,17 +5819,8 @@ const EventStreamRequest = {
|
|
|
6008
5819
|
},
|
|
6009
5820
|
};
|
|
6010
5821
|
const ServiceService = {
|
|
6011
|
-
resolveAll: {
|
|
6012
|
-
path: "/flagd.evaluation.v1.Service/ResolveAll",
|
|
6013
|
-
requestStream: false,
|
|
6014
|
-
responseStream: false,
|
|
6015
|
-
requestSerialize: (value) => Buffer.from(ResolveAllRequest.encode(value).finish()),
|
|
6016
|
-
requestDeserialize: (value) => ResolveAllRequest.decode(value),
|
|
6017
|
-
responseSerialize: (value) => Buffer.from(ResolveAllResponse.encode(value).finish()),
|
|
6018
|
-
responseDeserialize: (value) => ResolveAllResponse.decode(value),
|
|
6019
|
-
},
|
|
6020
5822
|
resolveBoolean: {
|
|
6021
|
-
path: "/flagd.evaluation.
|
|
5823
|
+
path: "/flagd.evaluation.v2.Service/ResolveBoolean",
|
|
6022
5824
|
requestStream: false,
|
|
6023
5825
|
responseStream: false,
|
|
6024
5826
|
requestSerialize: (value) => Buffer.from(ResolveBooleanRequest.encode(value).finish()),
|
|
@@ -6027,7 +5829,7 @@ const ServiceService = {
|
|
|
6027
5829
|
responseDeserialize: (value) => ResolveBooleanResponse.decode(value),
|
|
6028
5830
|
},
|
|
6029
5831
|
resolveString: {
|
|
6030
|
-
path: "/flagd.evaluation.
|
|
5832
|
+
path: "/flagd.evaluation.v2.Service/ResolveString",
|
|
6031
5833
|
requestStream: false,
|
|
6032
5834
|
responseStream: false,
|
|
6033
5835
|
requestSerialize: (value) => Buffer.from(ResolveStringRequest.encode(value).finish()),
|
|
@@ -6036,7 +5838,7 @@ const ServiceService = {
|
|
|
6036
5838
|
responseDeserialize: (value) => ResolveStringResponse.decode(value),
|
|
6037
5839
|
},
|
|
6038
5840
|
resolveFloat: {
|
|
6039
|
-
path: "/flagd.evaluation.
|
|
5841
|
+
path: "/flagd.evaluation.v2.Service/ResolveFloat",
|
|
6040
5842
|
requestStream: false,
|
|
6041
5843
|
responseStream: false,
|
|
6042
5844
|
requestSerialize: (value) => Buffer.from(ResolveFloatRequest.encode(value).finish()),
|
|
@@ -6045,7 +5847,7 @@ const ServiceService = {
|
|
|
6045
5847
|
responseDeserialize: (value) => ResolveFloatResponse.decode(value),
|
|
6046
5848
|
},
|
|
6047
5849
|
resolveInt: {
|
|
6048
|
-
path: "/flagd.evaluation.
|
|
5850
|
+
path: "/flagd.evaluation.v2.Service/ResolveInt",
|
|
6049
5851
|
requestStream: false,
|
|
6050
5852
|
responseStream: false,
|
|
6051
5853
|
requestSerialize: (value) => Buffer.from(ResolveIntRequest.encode(value).finish()),
|
|
@@ -6054,7 +5856,7 @@ const ServiceService = {
|
|
|
6054
5856
|
responseDeserialize: (value) => ResolveIntResponse.decode(value),
|
|
6055
5857
|
},
|
|
6056
5858
|
resolveObject: {
|
|
6057
|
-
path: "/flagd.evaluation.
|
|
5859
|
+
path: "/flagd.evaluation.v2.Service/ResolveObject",
|
|
6058
5860
|
requestStream: false,
|
|
6059
5861
|
responseStream: false,
|
|
6060
5862
|
requestSerialize: (value) => Buffer.from(ResolveObjectRequest.encode(value).finish()),
|
|
@@ -6063,7 +5865,7 @@ const ServiceService = {
|
|
|
6063
5865
|
responseDeserialize: (value) => ResolveObjectResponse.decode(value),
|
|
6064
5866
|
},
|
|
6065
5867
|
eventStream: {
|
|
6066
|
-
path: "/flagd.evaluation.
|
|
5868
|
+
path: "/flagd.evaluation.v2.Service/EventStream",
|
|
6067
5869
|
requestStream: false,
|
|
6068
5870
|
responseStream: true,
|
|
6069
5871
|
requestSerialize: (value) => Buffer.from(EventStreamRequest.encode(value).finish()),
|
|
@@ -6072,7 +5874,7 @@ const ServiceService = {
|
|
|
6072
5874
|
responseDeserialize: (value) => EventStreamResponse.decode(value),
|
|
6073
5875
|
},
|
|
6074
5876
|
};
|
|
6075
|
-
const ServiceClient = grpcJs.makeGenericClientConstructor(ServiceService, "flagd.evaluation.
|
|
5877
|
+
const ServiceClient = grpcJs.makeGenericClientConstructor(ServiceService, "flagd.evaluation.v2.Service");
|
|
6076
5878
|
function longToString(long) {
|
|
6077
5879
|
return long.toString();
|
|
6078
5880
|
}
|
|
@@ -6087,6 +5889,10 @@ function isSet$1(value) {
|
|
|
6087
5889
|
return value !== null && value !== undefined;
|
|
6088
5890
|
}
|
|
6089
5891
|
|
|
5892
|
+
/**
|
|
5893
|
+
* Get the string name of a gRPC status code.
|
|
5894
|
+
*/
|
|
5895
|
+
const statusName = (code) => grpcJs.status[code];
|
|
6090
5896
|
const closeStreamIfDefined = (stream) => {
|
|
6091
5897
|
/**
|
|
6092
5898
|
* cancel() is necessary to prevent calls from hanging the process, so we need to we need to remove all the
|
|
@@ -6101,6 +5907,122 @@ const closeStreamIfDefined = (stream) => {
|
|
|
6101
5907
|
stream.destroy();
|
|
6102
5908
|
}
|
|
6103
5909
|
};
|
|
5910
|
+
/**
|
|
5911
|
+
* Creates gRPC channel credentials based on TLS and certificate path configuration.
|
|
5912
|
+
* @returns Channel credentials for gRPC connection
|
|
5913
|
+
*/
|
|
5914
|
+
const createChannelCredentials = (tls, certPath) => {
|
|
5915
|
+
if (!tls) {
|
|
5916
|
+
return grpcJs.credentials.createInsecure();
|
|
5917
|
+
}
|
|
5918
|
+
if (certPath && node_fs.existsSync(certPath)) {
|
|
5919
|
+
const rootCerts = node_fs.readFileSync(certPath);
|
|
5920
|
+
return grpcJs.credentials.createSsl(rootCerts);
|
|
5921
|
+
}
|
|
5922
|
+
return grpcJs.credentials.createSsl();
|
|
5923
|
+
};
|
|
5924
|
+
/**
|
|
5925
|
+
* Mapping of configuration options to gRPC client options.
|
|
5926
|
+
*/
|
|
5927
|
+
const CONFIG_TO_GRPC_OPTIONS = [
|
|
5928
|
+
{ configKey: 'defaultAuthority', grpcKey: 'grpc.default_authority' },
|
|
5929
|
+
{ configKey: 'keepAliveTime', grpcKey: 'grpc.keepalive_time_ms', condition: (time) => Number(time) > 0 },
|
|
5930
|
+
];
|
|
5931
|
+
/**
|
|
5932
|
+
* Builds gRPC client options from config.
|
|
5933
|
+
*/
|
|
5934
|
+
function buildClientOptions(config) {
|
|
5935
|
+
const options = {
|
|
5936
|
+
'grpc.service_config': buildRetryPolicy(['flagd.evaluation.v1.Service', 'flagd.evaluation.v2.Service', 'flagd.sync.v1.FlagSyncService'], config.retryBackoffMs, config.retryBackoffMaxMs),
|
|
5937
|
+
};
|
|
5938
|
+
for (const { configKey, grpcKey, condition } of CONFIG_TO_GRPC_OPTIONS) {
|
|
5939
|
+
const value = config[configKey];
|
|
5940
|
+
if (value !== undefined && (!condition || condition(value))) {
|
|
5941
|
+
options[grpcKey] = value;
|
|
5942
|
+
}
|
|
5943
|
+
}
|
|
5944
|
+
return options;
|
|
5945
|
+
}
|
|
5946
|
+
/**
|
|
5947
|
+
* Builds RetryPolicy for gRPC client options.
|
|
5948
|
+
* @param serviceNames Array of service names to configure retry policy for
|
|
5949
|
+
* @param retryBackoffMs Initial backoff duration in milliseconds
|
|
5950
|
+
* @param retryBackoffMaxMs Maximum backoff duration in milliseconds
|
|
5951
|
+
* @returns gRPC client options with retry policy
|
|
5952
|
+
*/
|
|
5953
|
+
const buildRetryPolicy = (serviceNames, retryBackoffMs, retryBackoffMaxMs) => {
|
|
5954
|
+
const initialBackoff = retryBackoffMs !== null && retryBackoffMs !== void 0 ? retryBackoffMs : 1000;
|
|
5955
|
+
const maxBackoff = retryBackoffMaxMs !== null && retryBackoffMaxMs !== void 0 ? retryBackoffMaxMs : 120000;
|
|
5956
|
+
const retryPolicy = {
|
|
5957
|
+
maxAttempts: 3,
|
|
5958
|
+
initialBackoff: `${Math.round(initialBackoff / 1000).toFixed(2)}s`,
|
|
5959
|
+
maxBackoff: `${Math.round(maxBackoff / 1000).toFixed(2)}s`,
|
|
5960
|
+
backoffMultiplier: 2,
|
|
5961
|
+
retryableStatusCodes: [statusName(grpcJs.status.UNAVAILABLE), statusName(grpcJs.status.UNKNOWN)],
|
|
5962
|
+
};
|
|
5963
|
+
return JSON.stringify({
|
|
5964
|
+
loadBalancingConfig: [],
|
|
5965
|
+
methodConfig: [
|
|
5966
|
+
{
|
|
5967
|
+
name: serviceNames.map((serviceName) => ({ service: serviceName })),
|
|
5968
|
+
retryPolicy,
|
|
5969
|
+
},
|
|
5970
|
+
],
|
|
5971
|
+
});
|
|
5972
|
+
};
|
|
5973
|
+
/**
|
|
5974
|
+
* Converts an array of gRPC status code strings to a Set of numeric codes.
|
|
5975
|
+
* @param fatalStatusCodes Array of status code strings.
|
|
5976
|
+
* @param logger Optional logger for warning about unknown codes
|
|
5977
|
+
* @returns Set of numeric status codes
|
|
5978
|
+
*/
|
|
5979
|
+
const createFatalStatusCodesSet = (fatalStatusCodes, logger) => {
|
|
5980
|
+
if (!(fatalStatusCodes === null || fatalStatusCodes === void 0 ? void 0 : fatalStatusCodes.length)) {
|
|
5981
|
+
return new Set();
|
|
5982
|
+
}
|
|
5983
|
+
return fatalStatusCodes.reduce((codes, codeStr) => {
|
|
5984
|
+
const numericCode = grpcJs.status[codeStr];
|
|
5985
|
+
if (typeof numericCode === 'number') {
|
|
5986
|
+
codes.add(numericCode);
|
|
5987
|
+
}
|
|
5988
|
+
else {
|
|
5989
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(`Unknown gRPC status code: "${codeStr}"`);
|
|
5990
|
+
}
|
|
5991
|
+
return codes;
|
|
5992
|
+
}, new Set());
|
|
5993
|
+
};
|
|
5994
|
+
/**
|
|
5995
|
+
* Checks if an error is a fatal gRPC status code that should not be retried.
|
|
5996
|
+
* This should only be checked on the first connection attempt.
|
|
5997
|
+
*
|
|
5998
|
+
* @param err The error to check
|
|
5999
|
+
* @param initialized Whether the connection has been successfully initialized
|
|
6000
|
+
* @param fatalStatusCodes Set of numeric status codes considered fatal
|
|
6001
|
+
* @returns True if the error is fatal and should not be retried
|
|
6002
|
+
*/
|
|
6003
|
+
const isFatalStatusCodeError = (err, initialized, fatalStatusCodes) => {
|
|
6004
|
+
if (initialized) {
|
|
6005
|
+
return false;
|
|
6006
|
+
}
|
|
6007
|
+
const serviceError = err;
|
|
6008
|
+
return (serviceError === null || serviceError === void 0 ? void 0 : serviceError.code) !== undefined && fatalStatusCodes.has(serviceError.code);
|
|
6009
|
+
};
|
|
6010
|
+
/**
|
|
6011
|
+
* Handles a fatal gRPC status code error by logging it.
|
|
6012
|
+
* Should only be called when isFatalStatusCodeError returns true.
|
|
6013
|
+
*
|
|
6014
|
+
* @param err The error to handle
|
|
6015
|
+
* @param logger Optional logger for error logging
|
|
6016
|
+
* @param disconnectCallback Callback to invoke with the error message
|
|
6017
|
+
* @param rejectConnect Optional callback to reject the connection promise
|
|
6018
|
+
*/
|
|
6019
|
+
const handleFatalStatusCodeError = (err, logger, disconnectCallback, rejectConnect) => {
|
|
6020
|
+
const serviceError = err;
|
|
6021
|
+
logger === null || logger === void 0 ? void 0 : logger.error(`Encountered fatal status code ${serviceError.code} (${serviceError.message}) on first connection, will not retry`);
|
|
6022
|
+
const errorMessage = `PROVIDER_FATAL: ${serviceError.message}`;
|
|
6023
|
+
disconnectCallback(errorMessage);
|
|
6024
|
+
rejectConnect === null || rejectConnect === void 0 ? void 0 : rejectConnect(new serverSdk.ProviderFatalError(serviceError.message));
|
|
6025
|
+
};
|
|
6104
6026
|
|
|
6105
6027
|
class GRPCService {
|
|
6106
6028
|
get _cacheActive() {
|
|
@@ -6111,9 +6033,11 @@ class GRPCService {
|
|
|
6111
6033
|
this.logger = logger;
|
|
6112
6034
|
this._cacheEnabled = false;
|
|
6113
6035
|
this._eventStream = undefined;
|
|
6036
|
+
this._initialized = false;
|
|
6037
|
+
this._errorThrottled = false;
|
|
6114
6038
|
this.onRejected = (err) => {
|
|
6115
6039
|
// map the errors
|
|
6116
|
-
switch (err === null || err ===
|
|
6040
|
+
switch (err === null || err === void 0 ? void 0 : err.code) {
|
|
6117
6041
|
case grpcJs.status.DATA_LOSS:
|
|
6118
6042
|
throw new serverSdk.ParseError(err.details);
|
|
6119
6043
|
case grpcJs.status.INVALID_ARGUMENT:
|
|
@@ -6123,95 +6047,128 @@ class GRPCService {
|
|
|
6123
6047
|
case grpcJs.status.UNAVAILABLE:
|
|
6124
6048
|
throw new serverSdk.FlagNotFoundError(err.details);
|
|
6125
6049
|
default:
|
|
6126
|
-
throw new serverSdk.GeneralError(err === null || err ===
|
|
6050
|
+
throw new serverSdk.GeneralError(err === null || err === void 0 ? void 0 : err.details);
|
|
6127
6051
|
}
|
|
6128
6052
|
};
|
|
6129
|
-
const { host, port, tls, socketPath,
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
'grpc.default_authority': defaultAuthority,
|
|
6134
|
-
};
|
|
6135
|
-
}
|
|
6053
|
+
const { host, port, tls, socketPath, certPath } = config;
|
|
6054
|
+
const clientOptions = buildClientOptions(config);
|
|
6055
|
+
const channelCredentials = createChannelCredentials(tls, certPath);
|
|
6056
|
+
this._maxBackoffMs = config.retryBackoffMaxMs || DEFAULT_MAX_BACKOFF_MS;
|
|
6136
6057
|
this._client = client
|
|
6137
6058
|
? client
|
|
6138
|
-
: new ServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`,
|
|
6059
|
+
: new ServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, channelCredentials, clientOptions);
|
|
6060
|
+
this._deadline = config.deadlineMs;
|
|
6061
|
+
this._streamDeadline = config.streamDeadlineMs;
|
|
6139
6062
|
if (config.cache === 'lru') {
|
|
6140
6063
|
this._cacheEnabled = true;
|
|
6141
6064
|
this._cache = new lruCache.LRUCache({ maxSize: config.maxCacheSize || DEFAULT_MAX_CACHE_SIZE, sizeCalculation: () => 1 });
|
|
6142
6065
|
}
|
|
6066
|
+
this._fatalStatusCodes = createFatalStatusCodesSet(config.fatalStatusCodes, logger);
|
|
6067
|
+
// create metadata with the flagd-selector header if selector is configured
|
|
6068
|
+
this._metadata = new grpcJs.Metadata();
|
|
6069
|
+
if (config.selector) {
|
|
6070
|
+
this._metadata.set(FLAGD_SELECTOR_HEADER, config.selector);
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
clearCache() {
|
|
6074
|
+
var _a;
|
|
6075
|
+
(_a = this._cache) === null || _a === void 0 ? void 0 : _a.clear();
|
|
6143
6076
|
}
|
|
6144
6077
|
connect(reconnectCallback, changedCallback, disconnectCallback) {
|
|
6145
6078
|
return new Promise((resolve, reject) => this.listen(reconnectCallback, changedCallback, disconnectCallback, resolve, reject));
|
|
6146
6079
|
}
|
|
6147
6080
|
disconnect() {
|
|
6148
|
-
return __awaiter(this,
|
|
6081
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6149
6082
|
closeStreamIfDefined(this._eventStream);
|
|
6150
6083
|
this._client.close();
|
|
6151
6084
|
});
|
|
6152
6085
|
}
|
|
6153
|
-
resolveBoolean(flagKey,
|
|
6154
|
-
return __awaiter(this,
|
|
6155
|
-
return this.resolve(this._client.resolveBoolean, flagKey, context, logger);
|
|
6086
|
+
resolveBoolean(flagKey, defaultValue, context, logger) {
|
|
6087
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6088
|
+
return this.resolve(this._client.resolveBoolean, flagKey, defaultValue, context, logger);
|
|
6156
6089
|
});
|
|
6157
6090
|
}
|
|
6158
|
-
resolveString(flagKey,
|
|
6159
|
-
return __awaiter(this,
|
|
6160
|
-
return this.resolve(this._client.resolveString, flagKey, context, logger);
|
|
6091
|
+
resolveString(flagKey, defaultValue, context, logger) {
|
|
6092
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6093
|
+
return this.resolve(this._client.resolveString, flagKey, defaultValue, context, logger);
|
|
6161
6094
|
});
|
|
6162
6095
|
}
|
|
6163
|
-
resolveNumber(flagKey,
|
|
6164
|
-
return __awaiter(this,
|
|
6165
|
-
return this.resolve(this._client.resolveFloat, flagKey, context, logger);
|
|
6096
|
+
resolveNumber(flagKey, defaultValue, context, logger) {
|
|
6097
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6098
|
+
return this.resolve(this._client.resolveFloat, flagKey, defaultValue, context, logger);
|
|
6166
6099
|
});
|
|
6167
6100
|
}
|
|
6168
|
-
resolveObject(flagKey,
|
|
6169
|
-
return __awaiter(this,
|
|
6170
|
-
return this.resolve(this._client.resolveObject, flagKey, context, logger);
|
|
6101
|
+
resolveObject(flagKey, defaultValue, context, logger) {
|
|
6102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6103
|
+
return this.resolve(this._client.resolveObject, flagKey, defaultValue, context, logger);
|
|
6171
6104
|
});
|
|
6172
6105
|
}
|
|
6173
6106
|
listen(reconnectCallback, changedCallback, disconnectCallback, resolveConnect, rejectConnect) {
|
|
6174
6107
|
var _a;
|
|
6175
|
-
(_a = this.logger) === null || _a ===
|
|
6108
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: connecting stream...`);
|
|
6176
6109
|
// close the previous stream if we're reconnecting
|
|
6177
6110
|
closeStreamIfDefined(this._eventStream);
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
if (message.type === EVENT_PROVIDER_READY) {
|
|
6186
|
-
(_a = this.logger) === null || _a === undefined ? undefined : _a.debug(`${FlagdProvider.name}: streaming connection established with flagd`);
|
|
6187
|
-
// if resolveConnect is undefined, this is a reconnection; we only want to fire the reconnect callback in that case
|
|
6188
|
-
if (resolveConnect) {
|
|
6189
|
-
resolveConnect();
|
|
6190
|
-
}
|
|
6191
|
-
else {
|
|
6192
|
-
reconnectCallback();
|
|
6111
|
+
// wait for connection to be stable
|
|
6112
|
+
this._client.waitForReady(Date.now() + this._deadline, (err) => {
|
|
6113
|
+
if (err) {
|
|
6114
|
+
// Check if error is a fatal status code on first connection only
|
|
6115
|
+
if (isFatalStatusCodeError(err, this._initialized, this._fatalStatusCodes)) {
|
|
6116
|
+
handleFatalStatusCodeError(err, this.logger, disconnectCallback, rejectConnect);
|
|
6117
|
+
return;
|
|
6193
6118
|
}
|
|
6119
|
+
rejectConnect === null || rejectConnect === void 0 ? void 0 : rejectConnect(err);
|
|
6120
|
+
this.handleError(reconnectCallback, changedCallback, disconnectCallback);
|
|
6194
6121
|
}
|
|
6195
|
-
else
|
|
6196
|
-
this.
|
|
6122
|
+
else {
|
|
6123
|
+
const streamDeadline = this._streamDeadline != 0 ? Date.now() + this._streamDeadline : undefined;
|
|
6124
|
+
const stream = this._client.eventStream({}, { deadline: streamDeadline });
|
|
6125
|
+
stream.on('error', (err) => {
|
|
6126
|
+
// In cases where we get an explicit error status, we add a delay.
|
|
6127
|
+
// This prevents tight loops when errors are returned immediately, typically by intervening proxies like Envoy.
|
|
6128
|
+
this._errorThrottled = true;
|
|
6129
|
+
// Check if error is a fatal status code on first connection only
|
|
6130
|
+
if (isFatalStatusCodeError(err, this._initialized, this._fatalStatusCodes)) {
|
|
6131
|
+
handleFatalStatusCodeError(err, this.logger, disconnectCallback, rejectConnect);
|
|
6132
|
+
return;
|
|
6133
|
+
}
|
|
6134
|
+
rejectConnect === null || rejectConnect === void 0 ? void 0 : rejectConnect(err);
|
|
6135
|
+
this.handleError(reconnectCallback, changedCallback, disconnectCallback);
|
|
6136
|
+
});
|
|
6137
|
+
stream.on('data', (message) => {
|
|
6138
|
+
var _a;
|
|
6139
|
+
if (message.type === EVENT_PROVIDER_READY) {
|
|
6140
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: streaming connection established with flagd`);
|
|
6141
|
+
this._initialized = true;
|
|
6142
|
+
// if resolveConnect is undefined, this is a reconnection; we only want to fire the reconnect callback in that case
|
|
6143
|
+
if (resolveConnect) {
|
|
6144
|
+
resolveConnect();
|
|
6145
|
+
}
|
|
6146
|
+
else {
|
|
6147
|
+
reconnectCallback();
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
else if (message.type === EVENT_CONFIGURATION_CHANGE) {
|
|
6151
|
+
this.handleFlagsChanged(message, changedCallback);
|
|
6152
|
+
}
|
|
6153
|
+
});
|
|
6154
|
+
this._eventStream = stream;
|
|
6197
6155
|
}
|
|
6198
6156
|
});
|
|
6199
|
-
this._eventStream = stream;
|
|
6200
6157
|
}
|
|
6201
6158
|
handleFlagsChanged(message, changedCallback) {
|
|
6202
6159
|
var _a;
|
|
6203
6160
|
if (message.data) {
|
|
6204
6161
|
const data = message.data;
|
|
6205
|
-
(_a = this.logger) === null || _a ===
|
|
6206
|
-
if (data && typeof data === 'object' && 'flags' in data && (data === null || data ===
|
|
6162
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: got message: ${JSON.stringify(data, undefined, 2)}`);
|
|
6163
|
+
if (data && typeof data === 'object' && 'flags' in data && (data === null || data === void 0 ? void 0 : data['flags'])) {
|
|
6207
6164
|
const flagChangeMessage = data;
|
|
6208
6165
|
const flagsChanged = Object.keys(flagChangeMessage.flags || []);
|
|
6209
6166
|
if (this._cacheEnabled) {
|
|
6210
6167
|
// remove each changed key from cache
|
|
6211
6168
|
flagsChanged.forEach((key) => {
|
|
6212
6169
|
var _a, _b;
|
|
6213
|
-
if ((_a = this._cache) === null || _a ===
|
|
6214
|
-
(_b = this.logger) === null || _b ===
|
|
6170
|
+
if ((_a = this._cache) === null || _a === void 0 ? void 0 : _a.delete(key)) {
|
|
6171
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug(`${FlagdProvider.name}: evicted key: ${key} from cache.`);
|
|
6215
6172
|
}
|
|
6216
6173
|
});
|
|
6217
6174
|
}
|
|
@@ -6220,34 +6177,38 @@ class GRPCService {
|
|
|
6220
6177
|
}
|
|
6221
6178
|
}
|
|
6222
6179
|
reconnect(reconnectCallback, changedCallback, disconnectCallback) {
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
this.listen(reconnectCallback, changedCallback, disconnectCallback);
|
|
6226
|
-
});
|
|
6180
|
+
setTimeout(() => this.listen(reconnectCallback, changedCallback, disconnectCallback), this._errorThrottled ? this._maxBackoffMs : 0);
|
|
6181
|
+
this._errorThrottled = false;
|
|
6227
6182
|
}
|
|
6228
6183
|
handleError(reconnectCallback, changedCallback, disconnectCallback) {
|
|
6229
6184
|
var _a, _b;
|
|
6230
6185
|
disconnectCallback('streaming connection error, will attempt reconnect...');
|
|
6231
|
-
(_a = this.logger) === null || _a ===
|
|
6232
|
-
(_b = this._cache) === null || _b ===
|
|
6186
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`${FlagdProvider.name}: streaming connection error, will attempt reconnect...`);
|
|
6187
|
+
(_b = this._cache) === null || _b === void 0 ? void 0 : _b.clear();
|
|
6233
6188
|
this.reconnect(reconnectCallback, changedCallback, disconnectCallback);
|
|
6234
6189
|
}
|
|
6235
|
-
resolve(promise, flagKey, context, logger) {
|
|
6236
|
-
return __awaiter(this,
|
|
6190
|
+
resolve(promise, flagKey, defaultValue, context, logger) {
|
|
6191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6237
6192
|
var _a, _b;
|
|
6238
6193
|
const resolver = node_util.promisify(promise);
|
|
6239
6194
|
if (this._cacheActive) {
|
|
6240
|
-
const cached = (_a = this._cache) === null || _a ===
|
|
6195
|
+
const cached = (_a = this._cache) === null || _a === void 0 ? void 0 : _a.get(flagKey);
|
|
6241
6196
|
if (cached) {
|
|
6242
6197
|
return Object.assign(Object.assign({}, cached), { reason: serverSdk.StandardResolutionReasons.CACHED });
|
|
6243
6198
|
}
|
|
6244
6199
|
}
|
|
6245
|
-
// invoke the passed resolver method
|
|
6200
|
+
// invoke the passed resolver method with metadata for selector support
|
|
6246
6201
|
const response = yield resolver
|
|
6247
|
-
.call(this._client, { flagKey, context })
|
|
6202
|
+
.call(this._client, { flagKey, context }, this._metadata)
|
|
6248
6203
|
.then((resolved) => resolved, this.onRejected);
|
|
6204
|
+
let value = response.value;
|
|
6205
|
+
// When no default variant is configured, the server returns an empty/zero proto
|
|
6206
|
+
// value with reason=DEFAULT. In that case, return the caller's code default value.
|
|
6207
|
+
if (response.reason === serverSdk.StandardResolutionReasons.DEFAULT && !response.variant) {
|
|
6208
|
+
value = defaultValue;
|
|
6209
|
+
}
|
|
6249
6210
|
const resolved = {
|
|
6250
|
-
value
|
|
6211
|
+
value,
|
|
6251
6212
|
reason: response.reason,
|
|
6252
6213
|
variant: response.variant,
|
|
6253
6214
|
flagMetadata: response.metadata,
|
|
@@ -6255,7 +6216,7 @@ class GRPCService {
|
|
|
6255
6216
|
logger.debug(`${FlagdProvider.name}: resolved flag with key: ${resolved.value}, variant: ${response.variant}, reason: ${response.reason}`);
|
|
6256
6217
|
if (this._cacheActive && response.reason === serverSdk.StandardResolutionReasons.STATIC) {
|
|
6257
6218
|
// cache this static value
|
|
6258
|
-
(_b = this._cache) === null || _b ===
|
|
6219
|
+
(_b = this._cache) === null || _b === void 0 ? void 0 : _b.set(flagKey, resolved);
|
|
6259
6220
|
}
|
|
6260
6221
|
return resolved;
|
|
6261
6222
|
});
|
|
@@ -6269,9 +6230,9 @@ class FileFetch {
|
|
|
6269
6230
|
this._logger = logger;
|
|
6270
6231
|
}
|
|
6271
6232
|
connect(dataFillCallback, _, changedCallback) {
|
|
6272
|
-
return __awaiter(this,
|
|
6233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6273
6234
|
var _a, _b;
|
|
6274
|
-
(_a = this._logger) === null || _a ===
|
|
6235
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug('Starting file sync connection');
|
|
6275
6236
|
try {
|
|
6276
6237
|
const output = yield fs.promises.readFile(this._filename, encoding);
|
|
6277
6238
|
// Don't emit the change event for the initial read
|
|
@@ -6296,13 +6257,13 @@ class FileFetch {
|
|
|
6296
6257
|
throw err;
|
|
6297
6258
|
}
|
|
6298
6259
|
else {
|
|
6299
|
-
switch (err === null || err ===
|
|
6260
|
+
switch (err === null || err === void 0 ? void 0 : err.code) {
|
|
6300
6261
|
case 'ENOENT':
|
|
6301
6262
|
throw new serverSdk.GeneralError(`File not found: ${this._filename}`);
|
|
6302
6263
|
case 'EACCES':
|
|
6303
6264
|
throw new serverSdk.GeneralError(`File not accessible: ${this._filename}`);
|
|
6304
6265
|
default:
|
|
6305
|
-
(_b = this._logger) === null || _b ===
|
|
6266
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug(`Error reading file: ${err}`);
|
|
6306
6267
|
throw new serverSdk.GeneralError();
|
|
6307
6268
|
}
|
|
6308
6269
|
}
|
|
@@ -6310,7 +6271,7 @@ class FileFetch {
|
|
|
6310
6271
|
});
|
|
6311
6272
|
}
|
|
6312
6273
|
disconnect() {
|
|
6313
|
-
return __awaiter(this,
|
|
6274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6314
6275
|
fs.unwatchFile(this._filename);
|
|
6315
6276
|
});
|
|
6316
6277
|
}
|
|
@@ -6374,24 +6335,27 @@ const SyncFlagsRequest = {
|
|
|
6374
6335
|
return obj;
|
|
6375
6336
|
},
|
|
6376
6337
|
create(base) {
|
|
6377
|
-
return SyncFlagsRequest.fromPartial(base !== null && base !==
|
|
6338
|
+
return SyncFlagsRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6378
6339
|
},
|
|
6379
6340
|
fromPartial(object) {
|
|
6380
6341
|
var _a, _b;
|
|
6381
6342
|
const message = createBaseSyncFlagsRequest();
|
|
6382
|
-
message.providerId = (_a = object.providerId) !== null && _a !==
|
|
6383
|
-
message.selector = (_b = object.selector) !== null && _b !==
|
|
6343
|
+
message.providerId = (_a = object.providerId) !== null && _a !== void 0 ? _a : "";
|
|
6344
|
+
message.selector = (_b = object.selector) !== null && _b !== void 0 ? _b : "";
|
|
6384
6345
|
return message;
|
|
6385
6346
|
},
|
|
6386
6347
|
};
|
|
6387
6348
|
function createBaseSyncFlagsResponse() {
|
|
6388
|
-
return { flagConfiguration: "" };
|
|
6349
|
+
return { flagConfiguration: "", syncContext: undefined };
|
|
6389
6350
|
}
|
|
6390
6351
|
const SyncFlagsResponse = {
|
|
6391
6352
|
encode(message, writer = _m0.Writer.create()) {
|
|
6392
6353
|
if (message.flagConfiguration !== "") {
|
|
6393
6354
|
writer.uint32(10).string(message.flagConfiguration);
|
|
6394
6355
|
}
|
|
6356
|
+
if (message.syncContext !== undefined) {
|
|
6357
|
+
Struct.encode(Struct.wrap(message.syncContext), writer.uint32(18).fork()).ldelim();
|
|
6358
|
+
}
|
|
6395
6359
|
return writer;
|
|
6396
6360
|
},
|
|
6397
6361
|
decode(input, length) {
|
|
@@ -6407,6 +6371,12 @@ const SyncFlagsResponse = {
|
|
|
6407
6371
|
}
|
|
6408
6372
|
message.flagConfiguration = reader.string();
|
|
6409
6373
|
continue;
|
|
6374
|
+
case 2:
|
|
6375
|
+
if (tag !== 18) {
|
|
6376
|
+
break;
|
|
6377
|
+
}
|
|
6378
|
+
message.syncContext = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
6379
|
+
continue;
|
|
6410
6380
|
}
|
|
6411
6381
|
if ((tag & 7) === 4 || tag === 0) {
|
|
6412
6382
|
break;
|
|
@@ -6416,22 +6386,29 @@ const SyncFlagsResponse = {
|
|
|
6416
6386
|
return message;
|
|
6417
6387
|
},
|
|
6418
6388
|
fromJSON(object) {
|
|
6419
|
-
return {
|
|
6389
|
+
return {
|
|
6390
|
+
flagConfiguration: isSet(object.flagConfiguration) ? String(object.flagConfiguration) : "",
|
|
6391
|
+
syncContext: isObject(object.syncContext) ? object.syncContext : undefined,
|
|
6392
|
+
};
|
|
6420
6393
|
},
|
|
6421
6394
|
toJSON(message) {
|
|
6422
6395
|
const obj = {};
|
|
6423
6396
|
if (message.flagConfiguration !== "") {
|
|
6424
6397
|
obj.flagConfiguration = message.flagConfiguration;
|
|
6425
6398
|
}
|
|
6399
|
+
if (message.syncContext !== undefined) {
|
|
6400
|
+
obj.syncContext = message.syncContext;
|
|
6401
|
+
}
|
|
6426
6402
|
return obj;
|
|
6427
6403
|
},
|
|
6428
6404
|
create(base) {
|
|
6429
|
-
return SyncFlagsResponse.fromPartial(base !== null && base !==
|
|
6405
|
+
return SyncFlagsResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6430
6406
|
},
|
|
6431
6407
|
fromPartial(object) {
|
|
6432
|
-
var _a;
|
|
6408
|
+
var _a, _b;
|
|
6433
6409
|
const message = createBaseSyncFlagsResponse();
|
|
6434
|
-
message.flagConfiguration = (_a = object.flagConfiguration) !== null && _a !==
|
|
6410
|
+
message.flagConfiguration = (_a = object.flagConfiguration) !== null && _a !== void 0 ? _a : "";
|
|
6411
|
+
message.syncContext = (_b = object.syncContext) !== null && _b !== void 0 ? _b : undefined;
|
|
6435
6412
|
return message;
|
|
6436
6413
|
},
|
|
6437
6414
|
};
|
|
@@ -6492,13 +6469,13 @@ const FetchAllFlagsRequest = {
|
|
|
6492
6469
|
return obj;
|
|
6493
6470
|
},
|
|
6494
6471
|
create(base) {
|
|
6495
|
-
return FetchAllFlagsRequest.fromPartial(base !== null && base !==
|
|
6472
|
+
return FetchAllFlagsRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6496
6473
|
},
|
|
6497
6474
|
fromPartial(object) {
|
|
6498
6475
|
var _a, _b;
|
|
6499
6476
|
const message = createBaseFetchAllFlagsRequest();
|
|
6500
|
-
message.providerId = (_a = object.providerId) !== null && _a !==
|
|
6501
|
-
message.selector = (_b = object.selector) !== null && _b !==
|
|
6477
|
+
message.providerId = (_a = object.providerId) !== null && _a !== void 0 ? _a : "";
|
|
6478
|
+
message.selector = (_b = object.selector) !== null && _b !== void 0 ? _b : "";
|
|
6502
6479
|
return message;
|
|
6503
6480
|
},
|
|
6504
6481
|
};
|
|
@@ -6544,12 +6521,12 @@ const FetchAllFlagsResponse = {
|
|
|
6544
6521
|
return obj;
|
|
6545
6522
|
},
|
|
6546
6523
|
create(base) {
|
|
6547
|
-
return FetchAllFlagsResponse.fromPartial(base !== null && base !==
|
|
6524
|
+
return FetchAllFlagsResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6548
6525
|
},
|
|
6549
6526
|
fromPartial(object) {
|
|
6550
6527
|
var _a;
|
|
6551
6528
|
const message = createBaseFetchAllFlagsResponse();
|
|
6552
|
-
message.flagConfiguration = (_a = object.flagConfiguration) !== null && _a !==
|
|
6529
|
+
message.flagConfiguration = (_a = object.flagConfiguration) !== null && _a !== void 0 ? _a : "";
|
|
6553
6530
|
return message;
|
|
6554
6531
|
},
|
|
6555
6532
|
};
|
|
@@ -6581,7 +6558,7 @@ const GetMetadataRequest = {
|
|
|
6581
6558
|
return obj;
|
|
6582
6559
|
},
|
|
6583
6560
|
create(base) {
|
|
6584
|
-
return GetMetadataRequest.fromPartial(base !== null && base !==
|
|
6561
|
+
return GetMetadataRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6585
6562
|
},
|
|
6586
6563
|
fromPartial(_) {
|
|
6587
6564
|
const message = createBaseGetMetadataRequest();
|
|
@@ -6630,12 +6607,12 @@ const GetMetadataResponse = {
|
|
|
6630
6607
|
return obj;
|
|
6631
6608
|
},
|
|
6632
6609
|
create(base) {
|
|
6633
|
-
return GetMetadataResponse.fromPartial(base !== null && base !==
|
|
6610
|
+
return GetMetadataResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6634
6611
|
},
|
|
6635
6612
|
fromPartial(object) {
|
|
6636
6613
|
var _a;
|
|
6637
6614
|
const message = createBaseGetMetadataResponse();
|
|
6638
|
-
message.metadata = (_a = object.metadata) !== null && _a !==
|
|
6615
|
+
message.metadata = (_a = object.metadata) !== null && _a !== void 0 ? _a : undefined;
|
|
6639
6616
|
return message;
|
|
6640
6617
|
},
|
|
6641
6618
|
};
|
|
@@ -6658,6 +6635,7 @@ const FlagSyncServiceService = {
|
|
|
6658
6635
|
responseSerialize: (value) => Buffer.from(FetchAllFlagsResponse.encode(value).finish()),
|
|
6659
6636
|
responseDeserialize: (value) => FetchAllFlagsResponse.decode(value),
|
|
6660
6637
|
},
|
|
6638
|
+
/** @deprecated */
|
|
6661
6639
|
getMetadata: {
|
|
6662
6640
|
path: "/flagd.sync.v1.FlagSyncService/GetMetadata",
|
|
6663
6641
|
requestStream: false,
|
|
@@ -6680,7 +6658,8 @@ function isSet(value) {
|
|
|
6680
6658
|
* Implements the gRPC sync contract to fetch flag data.
|
|
6681
6659
|
*/
|
|
6682
6660
|
class GrpcFetch {
|
|
6683
|
-
constructor(config, syncServiceClient, logger) {
|
|
6661
|
+
constructor(config, setSyncContext, syncServiceClient, logger) {
|
|
6662
|
+
this._errorThrottled = false;
|
|
6684
6663
|
/**
|
|
6685
6664
|
* Initialized will be set to true once the initial connection is successful
|
|
6686
6665
|
* and the first payload has been received. Subsequent reconnects will not
|
|
@@ -6693,63 +6672,88 @@ class GrpcFetch {
|
|
|
6693
6672
|
* false if the connection is lost.
|
|
6694
6673
|
*/
|
|
6695
6674
|
this._isConnected = false;
|
|
6696
|
-
const { host, port, tls, socketPath,
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
clientOptions = {
|
|
6700
|
-
'grpc.default_authority': defaultAuthority,
|
|
6701
|
-
};
|
|
6702
|
-
}
|
|
6675
|
+
const { host, port, tls, socketPath, certPath, selector } = config;
|
|
6676
|
+
const clientOptions = buildClientOptions(config);
|
|
6677
|
+
const channelCredentials = createChannelCredentials(tls, certPath);
|
|
6703
6678
|
this._syncClient = syncServiceClient
|
|
6704
6679
|
? syncServiceClient
|
|
6705
|
-
: new FlagSyncServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`,
|
|
6680
|
+
: new FlagSyncServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, channelCredentials, clientOptions);
|
|
6681
|
+
this._deadlineMs = config.deadlineMs;
|
|
6682
|
+
this._maxBackoffMs = config.retryBackoffMaxMs || DEFAULT_MAX_BACKOFF_MS;
|
|
6683
|
+
this._streamDeadlineMs = config.streamDeadlineMs;
|
|
6684
|
+
this._setSyncContext = setSyncContext;
|
|
6706
6685
|
this._logger = logger;
|
|
6686
|
+
// For backward compatibility during the deprecation period, we send the selector in both:
|
|
6687
|
+
// 1. The request field (deprecated, for older flagd versions)
|
|
6688
|
+
// 2. The gRPC metadata header 'flagd-selector' (new standard)
|
|
6707
6689
|
this._request = { providerId: '', selector: selector ? selector : '' };
|
|
6690
|
+
this._fatalStatusCodes = createFatalStatusCodesSet(config.fatalStatusCodes, logger);
|
|
6691
|
+
// Create metadata with the flagd-selector header
|
|
6692
|
+
this._metadata = new grpcJs.Metadata();
|
|
6693
|
+
if (selector) {
|
|
6694
|
+
this._metadata.set(FLAGD_SELECTOR_HEADER, selector);
|
|
6695
|
+
}
|
|
6708
6696
|
}
|
|
6709
6697
|
connect(dataCallback, reconnectCallback, changedCallback, disconnectCallback) {
|
|
6710
|
-
return __awaiter(this,
|
|
6698
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6711
6699
|
yield new Promise((resolve, reject) => this.listen(dataCallback, reconnectCallback, changedCallback, disconnectCallback, resolve, reject));
|
|
6712
6700
|
this._initialized = true;
|
|
6713
6701
|
});
|
|
6714
6702
|
}
|
|
6715
6703
|
disconnect() {
|
|
6716
|
-
return __awaiter(this,
|
|
6704
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6717
6705
|
var _a;
|
|
6718
|
-
(_a = this._logger) === null || _a ===
|
|
6706
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug('Disconnecting gRPC sync connection');
|
|
6719
6707
|
closeStreamIfDefined(this._syncStream);
|
|
6720
6708
|
this._syncClient.close();
|
|
6721
6709
|
});
|
|
6722
6710
|
}
|
|
6723
6711
|
listen(dataCallback, reconnectCallback, changedCallback, disconnectCallback, resolveConnect, rejectConnect) {
|
|
6724
6712
|
var _a;
|
|
6725
|
-
(_a = this._logger) === null || _a ===
|
|
6713
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug('Starting gRPC sync connection');
|
|
6726
6714
|
closeStreamIfDefined(this._syncStream);
|
|
6727
6715
|
try {
|
|
6728
|
-
|
|
6729
|
-
this.
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
try {
|
|
6733
|
-
const changes = dataCallback(data.flagConfiguration);
|
|
6734
|
-
if (this._initialized && changes.length > 0) {
|
|
6735
|
-
changedCallback(changes);
|
|
6736
|
-
}
|
|
6737
|
-
}
|
|
6738
|
-
catch (err) {
|
|
6739
|
-
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug('Error processing sync payload: ', (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'unknown error');
|
|
6740
|
-
}
|
|
6741
|
-
if (resolveConnect) {
|
|
6742
|
-
resolveConnect();
|
|
6716
|
+
// wait for connection to be stable
|
|
6717
|
+
this._syncClient.waitForReady(Date.now() + this._deadlineMs, (err) => {
|
|
6718
|
+
if (err) {
|
|
6719
|
+
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6743
6720
|
}
|
|
6744
|
-
else
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6721
|
+
else {
|
|
6722
|
+
const streamDeadline = this._streamDeadlineMs != 0 ? Date.now() + this._streamDeadlineMs : undefined;
|
|
6723
|
+
const stream = this._syncClient.syncFlags(this._request, this._metadata, { deadline: streamDeadline });
|
|
6724
|
+
stream.on('data', (data) => {
|
|
6725
|
+
var _a, _b, _c, _d;
|
|
6726
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug(`Received sync payload`);
|
|
6727
|
+
try {
|
|
6728
|
+
if (data.syncContext) {
|
|
6729
|
+
this._setSyncContext(data.syncContext);
|
|
6730
|
+
}
|
|
6731
|
+
const changes = dataCallback(data.flagConfiguration);
|
|
6732
|
+
if (this._initialized && changes.length > 0) {
|
|
6733
|
+
changedCallback(changes);
|
|
6734
|
+
}
|
|
6735
|
+
}
|
|
6736
|
+
catch (err) {
|
|
6737
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug('Error processing sync payload: ', (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'unknown error');
|
|
6738
|
+
}
|
|
6739
|
+
if (resolveConnect) {
|
|
6740
|
+
resolveConnect();
|
|
6741
|
+
}
|
|
6742
|
+
else if (!this._isConnected) {
|
|
6743
|
+
// Not the first connection and there's no active connection.
|
|
6744
|
+
(_d = this._logger) === null || _d === void 0 ? void 0 : _d.debug('Reconnected to gRPC sync');
|
|
6745
|
+
reconnectCallback();
|
|
6746
|
+
}
|
|
6747
|
+
this._isConnected = true;
|
|
6748
|
+
});
|
|
6749
|
+
stream.on('error', (err) => {
|
|
6750
|
+
// In cases where we get an explicit error status, we add a delay.
|
|
6751
|
+
// This prevents tight loops when errors are returned immediately, typically by intervening proxies like Envoy.
|
|
6752
|
+
this._errorThrottled = true;
|
|
6753
|
+
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6754
|
+
});
|
|
6755
|
+
this._syncStream = stream;
|
|
6748
6756
|
}
|
|
6749
|
-
this._isConnected = true;
|
|
6750
|
-
});
|
|
6751
|
-
this._syncStream.on('error', (err) => {
|
|
6752
|
-
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6753
6757
|
});
|
|
6754
6758
|
}
|
|
6755
6759
|
catch (err) {
|
|
@@ -6758,57 +6762,64 @@ class GrpcFetch {
|
|
|
6758
6762
|
}
|
|
6759
6763
|
handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect) {
|
|
6760
6764
|
var _a, _b, _c;
|
|
6761
|
-
|
|
6762
|
-
(
|
|
6765
|
+
// Check if error is a fatal status code on first connection only
|
|
6766
|
+
if (isFatalStatusCodeError(err, this._initialized, this._fatalStatusCodes)) {
|
|
6767
|
+
this._isConnected = false;
|
|
6768
|
+
handleFatalStatusCodeError(err, this._logger, disconnectCallback, rejectConnect);
|
|
6769
|
+
return;
|
|
6770
|
+
}
|
|
6771
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.error('Connection error, attempting to reconnect');
|
|
6772
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug(err);
|
|
6763
6773
|
this._isConnected = false;
|
|
6764
|
-
const errorMessage = (_c = err === null || err ===
|
|
6774
|
+
const errorMessage = (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'Failed to connect to syncFlags stream';
|
|
6765
6775
|
disconnectCallback(errorMessage);
|
|
6766
|
-
rejectConnect === null || rejectConnect ===
|
|
6776
|
+
rejectConnect === null || rejectConnect === void 0 ? void 0 : rejectConnect(new serverSdk.GeneralError(errorMessage));
|
|
6767
6777
|
this.reconnect(dataCallback, reconnectCallback, changedCallback, disconnectCallback);
|
|
6768
6778
|
}
|
|
6769
6779
|
reconnect(dataCallback, reconnectCallback, changedCallback, disconnectCallback) {
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
this.listen(dataCallback, reconnectCallback, changedCallback, disconnectCallback);
|
|
6773
|
-
});
|
|
6780
|
+
setTimeout(() => this.listen(dataCallback, reconnectCallback, changedCallback, disconnectCallback), this._errorThrottled ? this._maxBackoffMs : 0);
|
|
6781
|
+
this._errorThrottled = false;
|
|
6774
6782
|
}
|
|
6775
6783
|
}
|
|
6776
6784
|
|
|
6777
6785
|
class InProcessService {
|
|
6778
|
-
constructor(config, dataFetcher, logger) {
|
|
6786
|
+
constructor(config, setSyncContext, dataFetcher, logger) {
|
|
6779
6787
|
this.config = config;
|
|
6780
6788
|
this._flagdCore = new flagdCore.FlagdCore(undefined, logger);
|
|
6781
6789
|
this._dataFetcher = dataFetcher
|
|
6782
6790
|
? dataFetcher
|
|
6783
6791
|
: config.offlineFlagSourcePath
|
|
6784
6792
|
? new FileFetch(config.offlineFlagSourcePath, logger)
|
|
6785
|
-
: new GrpcFetch(config, undefined, logger);
|
|
6793
|
+
: new GrpcFetch(config, setSyncContext, undefined, logger);
|
|
6794
|
+
}
|
|
6795
|
+
clearCache() {
|
|
6796
|
+
// in-process service does not cache flags
|
|
6786
6797
|
}
|
|
6787
6798
|
connect(reconnectCallback, changedCallback, disconnectCallback) {
|
|
6788
6799
|
return this._dataFetcher.connect(this.setFlagConfiguration.bind(this), reconnectCallback, changedCallback, disconnectCallback);
|
|
6789
6800
|
}
|
|
6790
6801
|
disconnect() {
|
|
6791
|
-
return __awaiter(this,
|
|
6802
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6792
6803
|
this._dataFetcher.disconnect();
|
|
6793
6804
|
});
|
|
6794
6805
|
}
|
|
6795
6806
|
resolveBoolean(flagKey, defaultValue, context, logger) {
|
|
6796
|
-
return __awaiter(this,
|
|
6807
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6797
6808
|
return this.evaluate('boolean', flagKey, defaultValue, context, logger);
|
|
6798
6809
|
});
|
|
6799
6810
|
}
|
|
6800
6811
|
resolveNumber(flagKey, defaultValue, context, logger) {
|
|
6801
|
-
return __awaiter(this,
|
|
6812
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6802
6813
|
return this.evaluate('number', flagKey, defaultValue, context, logger);
|
|
6803
6814
|
});
|
|
6804
6815
|
}
|
|
6805
6816
|
resolveString(flagKey, defaultValue, context, logger) {
|
|
6806
|
-
return __awaiter(this,
|
|
6817
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6807
6818
|
return this.evaluate('string', flagKey, defaultValue, context, logger);
|
|
6808
6819
|
});
|
|
6809
6820
|
}
|
|
6810
6821
|
resolveObject(flagKey, defaultValue, context, logger) {
|
|
6811
|
-
return __awaiter(this,
|
|
6822
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6812
6823
|
return this.evaluate('object', flagKey, defaultValue, context, logger);
|
|
6813
6824
|
});
|
|
6814
6825
|
}
|
|
@@ -6831,6 +6842,15 @@ class InProcessService {
|
|
|
6831
6842
|
}
|
|
6832
6843
|
}
|
|
6833
6844
|
|
|
6845
|
+
class SyncMetadataHook {
|
|
6846
|
+
constructor(enrichedContext) {
|
|
6847
|
+
this.enrichedContext = enrichedContext;
|
|
6848
|
+
}
|
|
6849
|
+
before(hookContext, hookHints) {
|
|
6850
|
+
return this.enrichedContext();
|
|
6851
|
+
}
|
|
6852
|
+
}
|
|
6853
|
+
|
|
6834
6854
|
class FlagdProvider {
|
|
6835
6855
|
/**
|
|
6836
6856
|
* Construct a new flagd provider.
|
|
@@ -6840,36 +6860,58 @@ class FlagdProvider {
|
|
|
6840
6860
|
* @param service optional internal service implementation, should not be needed for production
|
|
6841
6861
|
*/
|
|
6842
6862
|
constructor(options, logger, service) {
|
|
6863
|
+
var _a;
|
|
6843
6864
|
this.logger = logger;
|
|
6844
6865
|
this.metadata = {
|
|
6845
6866
|
name: 'flagd',
|
|
6846
6867
|
};
|
|
6847
6868
|
this.runsOn = 'server';
|
|
6848
6869
|
this.events = new serverSdk.OpenFeatureEventEmitter();
|
|
6870
|
+
this.syncContext = null;
|
|
6871
|
+
this._isErrorState = false;
|
|
6849
6872
|
const config = getConfig(options);
|
|
6850
|
-
this.
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6873
|
+
this._retryGracePeriod = (_a = config.retryGracePeriod) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_GRACE_PERIOD;
|
|
6874
|
+
if (service === undefined) {
|
|
6875
|
+
if (config.resolverType === 'in-process') {
|
|
6876
|
+
this._service = new InProcessService(config, this.setSyncContext.bind(this), undefined, logger);
|
|
6877
|
+
if ((config === null || config === void 0 ? void 0 : config.offlineFlagSourcePath) === undefined) {
|
|
6878
|
+
this.hooks = [new SyncMetadataHook(() => config.contextEnricher(this.getSyncContext()))];
|
|
6879
|
+
}
|
|
6880
|
+
}
|
|
6881
|
+
else {
|
|
6882
|
+
this._service = new GRPCService(config, undefined, logger);
|
|
6883
|
+
}
|
|
6884
|
+
}
|
|
6885
|
+
else {
|
|
6886
|
+
this._service = service;
|
|
6887
|
+
}
|
|
6888
|
+
}
|
|
6889
|
+
setSyncContext(context) {
|
|
6890
|
+
this.syncContext = context;
|
|
6891
|
+
}
|
|
6892
|
+
getSyncContext() {
|
|
6893
|
+
return this.syncContext;
|
|
6855
6894
|
}
|
|
6856
6895
|
initialize() {
|
|
6857
|
-
return __awaiter(this,
|
|
6896
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6858
6897
|
var _a, _b, _c;
|
|
6859
6898
|
try {
|
|
6860
6899
|
yield this._service.connect(this.handleReconnect.bind(this), this.handleChanged.bind(this), this.handleError.bind(this));
|
|
6900
|
+
this.clearErrorTimer();
|
|
6901
|
+
this._isErrorState = false;
|
|
6861
6902
|
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${this.metadata.name}: ready`);
|
|
6862
6903
|
}
|
|
6863
6904
|
catch (err) {
|
|
6864
|
-
(_b = this.logger) === null || _b ===
|
|
6865
|
-
(_c = this.logger) === null || _c ===
|
|
6905
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error(`${this.metadata.name}: error during initialization: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
6906
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.debug(err);
|
|
6866
6907
|
throw err;
|
|
6867
6908
|
}
|
|
6868
6909
|
});
|
|
6869
6910
|
}
|
|
6870
6911
|
onClose() {
|
|
6871
6912
|
var _a;
|
|
6872
|
-
(_a = this.logger) === null || _a ===
|
|
6913
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${this.metadata.name}: shutting down`);
|
|
6914
|
+
this.clearErrorTimer();
|
|
6873
6915
|
return this._service.disconnect();
|
|
6874
6916
|
}
|
|
6875
6917
|
resolveBooleanEvaluation(flagKey, defaultValue, transformedContext, logger) {
|
|
@@ -6885,14 +6927,35 @@ class FlagdProvider {
|
|
|
6885
6927
|
return this._service.resolveObject(flagKey, defaultValue, transformedContext, logger);
|
|
6886
6928
|
}
|
|
6887
6929
|
handleReconnect() {
|
|
6930
|
+
this.clearErrorTimer();
|
|
6931
|
+
this._isErrorState = false;
|
|
6888
6932
|
this.events.emit(serverSdk.ProviderEvents.Ready);
|
|
6889
6933
|
}
|
|
6890
6934
|
handleError(message) {
|
|
6891
|
-
this.
|
|
6935
|
+
if (this._isErrorState) {
|
|
6936
|
+
return;
|
|
6937
|
+
}
|
|
6938
|
+
this._isErrorState = true;
|
|
6939
|
+
this.events.emit(serverSdk.ProviderEvents.Stale, { message });
|
|
6940
|
+
this._errorTimer = setTimeout(() => {
|
|
6941
|
+
var _a;
|
|
6942
|
+
if (this._isErrorState) {
|
|
6943
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`${this.metadata.name}: not reconnected within ${this._retryGracePeriod}s grace period, emitting ERROR`);
|
|
6944
|
+
this._service.clearCache();
|
|
6945
|
+
this.events.emit(serverSdk.ProviderEvents.Error, { message });
|
|
6946
|
+
}
|
|
6947
|
+
this._errorTimer = undefined;
|
|
6948
|
+
}, this._retryGracePeriod * 1000);
|
|
6892
6949
|
}
|
|
6893
6950
|
handleChanged(flagsChanged) {
|
|
6894
6951
|
this.events.emit(serverSdk.ProviderEvents.ConfigurationChanged, { flagsChanged });
|
|
6895
6952
|
}
|
|
6953
|
+
clearErrorTimer() {
|
|
6954
|
+
if (this._errorTimer) {
|
|
6955
|
+
clearTimeout(this._errorTimer);
|
|
6956
|
+
this._errorTimer = undefined;
|
|
6957
|
+
}
|
|
6958
|
+
}
|
|
6896
6959
|
}
|
|
6897
6960
|
|
|
6898
6961
|
exports.FlagdProvider = FlagdProvider;
|