zeed 0.8.2 → 0.8.5
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/dist/chunk-5PI4S556.js +2 -0
- package/dist/chunk-5PI4S556.js.map +1 -0
- package/dist/chunk-I7COHPWN.js +2 -0
- package/dist/chunk-I7COHPWN.js.map +1 -0
- package/dist/chunk-QJ7QJLK2.js +8 -0
- package/dist/chunk-QJ7QJLK2.js.map +1 -0
- package/dist/chunk-UGK75LGZ.js +2 -0
- package/dist/chunk-UGK75LGZ.js.map +1 -0
- package/dist/chunk-UQUUBQPQ.js +7 -0
- package/dist/chunk-UQUUBQPQ.js.map +1 -0
- package/dist/index.all.cjs +12 -5031
- package/dist/index.all.cjs.map +1 -1
- package/dist/index.all.js +1 -5
- package/dist/index.all.js.map +1 -1
- package/dist/index.browser.cjs +7 -4383
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +1 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.log.cjs +1 -655
- package/dist/index.log.cjs.map +1 -1
- package/dist/index.log.js +1 -2
- package/dist/index.log.js.map +1 -1
- package/dist/index.node.cjs +12 -4479
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +1 -3
- package/dist/index.node.js.map +1 -1
- package/package.json +15 -8
- package/dist/chunk-3LN7HI45.js +0 -3077
- package/dist/chunk-3LN7HI45.js.map +0 -1
- package/dist/chunk-AM7QCF4I.js +0 -486
- package/dist/chunk-AM7QCF4I.js.map +0 -1
- package/dist/chunk-HI3XD4NV.js +0 -603
- package/dist/chunk-HI3XD4NV.js.map +0 -1
- package/dist/chunk-IFNHRAHG.js +0 -306
- package/dist/chunk-IFNHRAHG.js.map +0 -1
- package/dist/chunk-OJCXV4BY.js +0 -246
- package/dist/chunk-OJCXV4BY.js.map +0 -1
package/dist/index.node.cjs
CHANGED
|
@@ -1,4480 +1,13 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
|
|
28
|
-
// src/index.node.ts
|
|
29
|
-
var index_node_exports = {};
|
|
30
|
-
__export(index_node_exports, {
|
|
31
|
-
Channel: () => Channel,
|
|
32
|
-
CryptoEncoder: () => CryptoEncoder,
|
|
33
|
-
Currency: () => Currency,
|
|
34
|
-
DAY_MS: () => DAY_MS,
|
|
35
|
-
Day: () => Day,
|
|
36
|
-
Emitter: () => Emitter,
|
|
37
|
-
FileStorage: () => FileStorage,
|
|
38
|
-
JsonEncoder: () => JsonEncoder,
|
|
39
|
-
LocalChannel: () => LocalChannel,
|
|
40
|
-
LogLevel: () => LogLevel,
|
|
41
|
-
LogLevelAlias: () => LogLevelAlias,
|
|
42
|
-
Logger: () => Logger,
|
|
43
|
-
LoggerConsoleHandler: () => LoggerConsoleHandler,
|
|
44
|
-
LoggerContext: () => LoggerContext,
|
|
45
|
-
LoggerFileHandler: () => LoggerFileHandler,
|
|
46
|
-
LoggerMemoryHandler: () => LoggerMemoryHandler,
|
|
47
|
-
LoggerNodeHandler: () => LoggerNodeHandler,
|
|
48
|
-
MemStorage: () => MemStorage,
|
|
49
|
-
NoopEncoder: () => NoopEncoder,
|
|
50
|
-
PoolTaskIdConflictResolution: () => PoolTaskIdConflictResolution,
|
|
51
|
-
PoolTaskState: () => PoolTaskState,
|
|
52
|
-
PubSub: () => PubSub,
|
|
53
|
-
SerialQueue: () => SerialQueue,
|
|
54
|
-
Uint8ArrayToHexDump: () => Uint8ArrayToHexDump,
|
|
55
|
-
Uint8ArrayToJson: () => Uint8ArrayToJson,
|
|
56
|
-
Uint8ArrayToString: () => Uint8ArrayToString,
|
|
57
|
-
XRX: () => XRX,
|
|
58
|
-
_decodeUtf8Polyfill: () => _decodeUtf8Polyfill,
|
|
59
|
-
_encodeUtf8Polyfill: () => _encodeUtf8Polyfill,
|
|
60
|
-
arrayAvg: () => arrayAvg,
|
|
61
|
-
arrayBatches: () => arrayBatches,
|
|
62
|
-
arrayEmptyInPlace: () => arrayEmptyInPlace,
|
|
63
|
-
arrayFilterInPlace: () => arrayFilterInPlace,
|
|
64
|
-
arrayFlatten: () => arrayFlatten,
|
|
65
|
-
arrayIntersection: () => arrayIntersection,
|
|
66
|
-
arrayIsEqual: () => arrayIsEqual,
|
|
67
|
-
arrayMax: () => arrayMax,
|
|
68
|
-
arrayMin: () => arrayMin,
|
|
69
|
-
arrayMinus: () => arrayMinus,
|
|
70
|
-
arrayRandomElement: () => arrayRandomElement,
|
|
71
|
-
arrayRemoveElement: () => arrayRemoveElement,
|
|
72
|
-
arraySetElement: () => arraySetElement,
|
|
73
|
-
arrayShuffle: () => arrayShuffle,
|
|
74
|
-
arrayShuffleForce: () => arrayShuffleForce,
|
|
75
|
-
arrayShuffleInPlace: () => arrayShuffleInPlace,
|
|
76
|
-
arraySorted: () => arraySorted,
|
|
77
|
-
arraySortedNumbers: () => arraySortedNumbers,
|
|
78
|
-
arraySum: () => arraySum,
|
|
79
|
-
arraySymmetricDifference: () => arraySymmetricDifference,
|
|
80
|
-
arrayToggleInPlace: () => arrayToggleInPlace,
|
|
81
|
-
arrayUnion: () => arrayUnion,
|
|
82
|
-
arrayUnique: () => arrayUnique,
|
|
83
|
-
avg: () => avg,
|
|
84
|
-
between: () => between,
|
|
85
|
-
cloneJsonObject: () => cloneJsonObject,
|
|
86
|
-
cloneObject: () => cloneObject,
|
|
87
|
-
cmp: () => cmp,
|
|
88
|
-
colorString: () => colorString,
|
|
89
|
-
colorStringList: () => colorStringList,
|
|
90
|
-
composeOrderby: () => composeOrderby,
|
|
91
|
-
createArray: () => createArray,
|
|
92
|
-
createLocalChannelPair: () => createLocalChannelPair,
|
|
93
|
-
createPromise: () => createPromise,
|
|
94
|
-
createPromiseProxy: () => createPromiseProxy,
|
|
95
|
-
csv: () => csv,
|
|
96
|
-
currency: () => currency,
|
|
97
|
-
dateStringToDays: () => dateStringToDays,
|
|
98
|
-
day: () => day,
|
|
99
|
-
dayDay: () => dayDay,
|
|
100
|
-
dayDiff: () => dayDiff,
|
|
101
|
-
dayFromAny: () => dayFromAny,
|
|
102
|
-
dayFromDate: () => dayFromDate,
|
|
103
|
-
dayFromDateGMT: () => dayFromDateGMT,
|
|
104
|
-
dayFromParts: () => dayFromParts,
|
|
105
|
-
dayFromString: () => dayFromString,
|
|
106
|
-
dayFromTimestamp: () => dayFromTimestamp,
|
|
107
|
-
dayFromToday: () => dayFromToday,
|
|
108
|
-
dayMonth: () => dayMonth,
|
|
109
|
-
dayMonthStart: () => dayMonthStart,
|
|
110
|
-
dayOffset: () => dayOffset,
|
|
111
|
-
dayToDate: () => dayToDate,
|
|
112
|
-
dayToDateGMT: () => dayToDateGMT,
|
|
113
|
-
dayToParts: () => dayToParts,
|
|
114
|
-
dayToString: () => dayToString,
|
|
115
|
-
dayToTimestamp: () => dayToTimestamp,
|
|
116
|
-
dayYear: () => dayYear,
|
|
117
|
-
dayYearStart: () => dayYearStart,
|
|
118
|
-
debounce: () => debounce,
|
|
119
|
-
decimal: () => decimal,
|
|
120
|
-
decimalCentsPart: () => decimalCentsPart,
|
|
121
|
-
decimalFromCents: () => decimalFromCents,
|
|
122
|
-
decimalToCents: () => decimalToCents,
|
|
123
|
-
decodeBase16: () => decodeBase16,
|
|
124
|
-
decodeBase32: () => decodeBase32,
|
|
125
|
-
decodeBase58: () => decodeBase58,
|
|
126
|
-
decodeBase62: () => decodeBase62,
|
|
127
|
-
decodeBase64: () => decodeBase64,
|
|
128
|
-
decrypt: () => decrypt,
|
|
129
|
-
deepEqual: () => deepEqual,
|
|
130
|
-
deepMerge: () => deepMerge,
|
|
131
|
-
deriveKeyPbkdf2: () => deriveKeyPbkdf2,
|
|
132
|
-
detect: () => detect,
|
|
133
|
-
digest: () => digest,
|
|
134
|
-
empty: () => empty,
|
|
135
|
-
encodeBase16: () => encodeBase16,
|
|
136
|
-
encodeBase32: () => encodeBase32,
|
|
137
|
-
encodeBase58: () => encodeBase58,
|
|
138
|
-
encodeBase62: () => encodeBase62,
|
|
139
|
-
encodeBase64: () => encodeBase64,
|
|
140
|
-
encodeQuery: () => encodeQuery,
|
|
141
|
-
encrypt: () => encrypt,
|
|
142
|
-
endSortWeight: () => endSortWeight,
|
|
143
|
-
ensureFolder: () => ensureFolder,
|
|
144
|
-
ensureKey: () => ensureKey,
|
|
145
|
-
ensureKeyAsync: () => ensureKeyAsync,
|
|
146
|
-
equalBinary: () => equalBinary,
|
|
147
|
-
escapeHTML: () => escapeHTML,
|
|
148
|
-
escapeRegExp: () => escapeRegExp,
|
|
149
|
-
exists: () => exists,
|
|
150
|
-
fetchBasic: () => fetchBasic,
|
|
151
|
-
fetchJson: () => fetchJson,
|
|
152
|
-
fetchOptionsBasicAuth: () => fetchOptionsBasicAuth,
|
|
153
|
-
fetchOptionsFormURLEncoded: () => fetchOptionsFormURLEncoded,
|
|
154
|
-
fetchOptionsJson: () => fetchOptionsJson,
|
|
155
|
-
fetchText: () => fetchText,
|
|
156
|
-
fixBrokenUth8String: () => fixBrokenUth8String,
|
|
157
|
-
forEachDay: () => forEachDay,
|
|
158
|
-
forTimes: () => forTimes,
|
|
159
|
-
formatMessages: () => formatMessages,
|
|
160
|
-
formatMilliseconds: () => formatMilliseconds,
|
|
161
|
-
fromBase64: () => fromBase64,
|
|
162
|
-
fromCamelCase: () => fromCamelCase,
|
|
163
|
-
getGlobal: () => getGlobal,
|
|
164
|
-
getGlobalContext: () => getGlobalContext,
|
|
165
|
-
getGlobalEmitter: () => getGlobalEmitter,
|
|
166
|
-
getNamespaceFilterString: () => getNamespaceFilterString,
|
|
167
|
-
getNavigator: () => getNavigator,
|
|
168
|
-
getSecureRandom: () => getSecureRandom,
|
|
169
|
-
getSecureRandomIfPossible: () => getSecureRandomIfPossible,
|
|
170
|
-
getSourceLocation: () => getSourceLocation,
|
|
171
|
-
getSourceLocationByPrecedingPattern: () => getSourceLocationByPrecedingPattern,
|
|
172
|
-
getStack: () => getStack,
|
|
173
|
-
getStackLlocationList: () => getStackLlocationList,
|
|
174
|
-
getTimestamp: () => getTimestamp,
|
|
175
|
-
getWindow: () => getWindow,
|
|
176
|
-
immediate: () => immediate,
|
|
177
|
-
isArray: () => isArray,
|
|
178
|
-
isBoolean: () => isBoolean,
|
|
179
|
-
isBrowser: () => isBrowser,
|
|
180
|
-
isEven: () => isEven,
|
|
181
|
-
isHalf: () => isHalf,
|
|
182
|
-
isInteger: () => isInteger,
|
|
183
|
-
isLocalHost: () => isLocalHost,
|
|
184
|
-
isNullOrUndefined: () => isNullOrUndefined,
|
|
185
|
-
isNumber: () => isNumber,
|
|
186
|
-
isObject: () => isObject,
|
|
187
|
-
isPrime: () => isPrime,
|
|
188
|
-
isPrimeRX: () => isPrimeRX,
|
|
189
|
-
isPrimitive: () => isPrimitive,
|
|
190
|
-
isPromise: () => isPromise,
|
|
191
|
-
isRecord: () => isRecord,
|
|
192
|
-
isSafeInteger: () => isSafeInteger,
|
|
193
|
-
isString: () => isString,
|
|
194
|
-
isTimeout: () => isTimeout,
|
|
195
|
-
isUint8Array: () => isUint8Array,
|
|
196
|
-
joinToUint8Array: () => joinToUint8Array,
|
|
197
|
-
jsonStringify: () => jsonStringify,
|
|
198
|
-
jsonToUint8Array: () => jsonToUint8Array,
|
|
199
|
-
last: () => last,
|
|
200
|
-
lazyListener: () => lazyListener,
|
|
201
|
-
linkifyPlainText: () => linkifyPlainText,
|
|
202
|
-
loggerStackTraceDebug: () => loggerStackTraceDebug,
|
|
203
|
-
memoize: () => memoize,
|
|
204
|
-
messages: () => messages,
|
|
205
|
-
moveSortWeight: () => moveSortWeight,
|
|
206
|
-
parseArgs: () => parseArgs,
|
|
207
|
-
parseBasicAuth: () => parseBasicAuth,
|
|
208
|
-
parseDate: () => parseDate,
|
|
209
|
-
parseLogLevel: () => parseLogLevel,
|
|
210
|
-
parseOrderby: () => parseOrderby,
|
|
211
|
-
parseQuery: () => parseQuery,
|
|
212
|
-
pbcopy: () => pbcopy,
|
|
213
|
-
platform: () => platform,
|
|
214
|
-
promisify: () => promisify,
|
|
215
|
-
qid: () => qid,
|
|
216
|
-
randomBoolean: () => randomBoolean,
|
|
217
|
-
randomFloat: () => randomFloat,
|
|
218
|
-
randomInt: () => randomInt,
|
|
219
|
-
randomUint8Array: () => randomUint8Array,
|
|
220
|
-
readText: () => readText,
|
|
221
|
-
regExpEscape: () => regExpEscape,
|
|
222
|
-
regExpString: () => regExpString,
|
|
223
|
-
removeFolder: () => removeFolder,
|
|
224
|
-
renderMessages: () => renderMessages,
|
|
225
|
-
roundDown: () => roundDown,
|
|
226
|
-
roundHalfAwayFromZero: () => roundHalfAwayFromZero,
|
|
227
|
-
roundHalfDown: () => roundHalfDown,
|
|
228
|
-
roundHalfEven: () => roundHalfEven,
|
|
229
|
-
roundHalfOdd: () => roundHalfOdd,
|
|
230
|
-
roundHalfTowardsZero: () => roundHalfTowardsZero,
|
|
231
|
-
roundHalfUp: () => roundHalfUp,
|
|
232
|
-
roundUp: () => roundUp,
|
|
233
|
-
setupEnv: () => setupEnv,
|
|
234
|
-
size: () => size,
|
|
235
|
-
sleep: () => sleep,
|
|
236
|
-
sortedItems: () => sortedItems,
|
|
237
|
-
sortedOrderby: () => sortedOrderby,
|
|
238
|
-
startSortWeight: () => startSortWeight,
|
|
239
|
-
stringToBoolean: () => stringToBoolean,
|
|
240
|
-
stringToFloat: () => stringToFloat,
|
|
241
|
-
stringToInteger: () => stringToInteger,
|
|
242
|
-
stringToPath: () => stringToPath,
|
|
243
|
-
stringToUInt8Array: () => stringToUInt8Array,
|
|
244
|
-
suid: () => suid,
|
|
245
|
-
suidBytes: () => suidBytes,
|
|
246
|
-
suidBytesDate: () => suidBytesDate,
|
|
247
|
-
suidDate: () => suidDate,
|
|
248
|
-
sum: () => sum,
|
|
249
|
-
throttle: () => throttle,
|
|
250
|
-
timeout: () => timeout,
|
|
251
|
-
timeoutReached: () => timeoutReached,
|
|
252
|
-
timoutError: () => timoutError,
|
|
253
|
-
toBase64: () => toBase64,
|
|
254
|
-
toBase64Url: () => toBase64Url,
|
|
255
|
-
toBool: () => toBool,
|
|
256
|
-
toCamelCase: () => toCamelCase,
|
|
257
|
-
toCapitalize: () => toCapitalize,
|
|
258
|
-
toCapitalizeWords: () => toCapitalizeWords,
|
|
259
|
-
toFloat: () => toFloat,
|
|
260
|
-
toHex: () => toHex,
|
|
261
|
-
toHumanReadableFilePath: () => toHumanReadableFilePath,
|
|
262
|
-
toHumanReadableUrl: () => toHumanReadableUrl,
|
|
263
|
-
toInt: () => toInt,
|
|
264
|
-
toPath: () => toPath,
|
|
265
|
-
toString: () => toString,
|
|
266
|
-
toUint8Array: () => toUint8Array,
|
|
267
|
-
toValidFilename: () => toValidFilename,
|
|
268
|
-
today: () => today,
|
|
269
|
-
tryTimeout: () => tryTimeout,
|
|
270
|
-
uname: () => uname,
|
|
271
|
-
unescapeHTML: () => unescapeHTML,
|
|
272
|
-
useAsyncMutex: () => useAsyncMutex,
|
|
273
|
-
useBase: () => useBase,
|
|
274
|
-
useDefer: () => useDefer,
|
|
275
|
-
useDispose: () => useDispose,
|
|
276
|
-
useDisposer: () => useDisposer,
|
|
277
|
-
useEventListener: () => useEventListener,
|
|
278
|
-
useExitHandler: () => useExitHandler,
|
|
279
|
-
useInterval: () => useInterval,
|
|
280
|
-
useLevelFilter: () => useLevelFilter,
|
|
281
|
-
useMessageHub: () => useMessageHub,
|
|
282
|
-
useMutex: () => useMutex,
|
|
283
|
-
useNamespaceFilter: () => useNamespaceFilter,
|
|
284
|
-
usePool: () => usePool,
|
|
285
|
-
usePubSub: () => usePubSub,
|
|
286
|
-
useRPC: () => useRPC,
|
|
287
|
-
useTimeout: () => useTimeout,
|
|
288
|
-
uuid: () => uuid,
|
|
289
|
-
uuid32Decode: () => uuid32Decode,
|
|
290
|
-
uuid32Encode: () => uuid32Encode,
|
|
291
|
-
uuid32bit: () => uuid32bit,
|
|
292
|
-
uuidB32: () => uuidB32,
|
|
293
|
-
uuidBytes: () => uuidBytes,
|
|
294
|
-
uuidDecode: () => uuidDecode,
|
|
295
|
-
uuidEncode: () => uuidEncode,
|
|
296
|
-
uuidv4: () => uuidv4,
|
|
297
|
-
valueToBoolean: () => valueToBoolean,
|
|
298
|
-
valueToFloat: () => valueToFloat,
|
|
299
|
-
valueToInteger: () => valueToInteger,
|
|
300
|
-
valueToPath: () => valueToPath,
|
|
301
|
-
valueToString: () => valueToString,
|
|
302
|
-
waitOn: () => waitOn,
|
|
303
|
-
writeText: () => writeText
|
|
304
|
-
});
|
|
305
|
-
module.exports = __toCommonJS(index_node_exports);
|
|
306
|
-
|
|
307
|
-
// src/common/data/is.ts
|
|
308
|
-
function isObject(obj) {
|
|
309
|
-
return obj != null && typeof obj === "object";
|
|
310
|
-
}
|
|
311
|
-
__name(isObject, "isObject");
|
|
312
|
-
function isPrimitive(obj) {
|
|
313
|
-
return Object(obj) !== obj;
|
|
314
|
-
}
|
|
315
|
-
__name(isPrimitive, "isPrimitive");
|
|
316
|
-
function isArray(obj) {
|
|
317
|
-
return Array.isArray(obj);
|
|
318
|
-
}
|
|
319
|
-
__name(isArray, "isArray");
|
|
320
|
-
function isRecord(obj) {
|
|
321
|
-
return isObject(obj) && !isArray(obj);
|
|
322
|
-
}
|
|
323
|
-
__name(isRecord, "isRecord");
|
|
324
|
-
function isString(obj) {
|
|
325
|
-
return typeof obj === "string";
|
|
326
|
-
}
|
|
327
|
-
__name(isString, "isString");
|
|
328
|
-
function isNumber(obj) {
|
|
329
|
-
return typeof obj === "number";
|
|
330
|
-
}
|
|
331
|
-
__name(isNumber, "isNumber");
|
|
332
|
-
function isInteger(obj) {
|
|
333
|
-
return typeof obj === "number" && Number.isInteger(obj);
|
|
334
|
-
}
|
|
335
|
-
__name(isInteger, "isInteger");
|
|
336
|
-
function isSafeInteger(obj) {
|
|
337
|
-
return typeof obj === "number" && Number.isSafeInteger(obj);
|
|
338
|
-
}
|
|
339
|
-
__name(isSafeInteger, "isSafeInteger");
|
|
340
|
-
function isBoolean(obj) {
|
|
341
|
-
return typeof obj === "boolean";
|
|
342
|
-
}
|
|
343
|
-
__name(isBoolean, "isBoolean");
|
|
344
|
-
function isNullOrUndefined(obj) {
|
|
345
|
-
return obj == null;
|
|
346
|
-
}
|
|
347
|
-
__name(isNullOrUndefined, "isNullOrUndefined");
|
|
348
|
-
function isUint8Array(obj) {
|
|
349
|
-
return isObject(obj) && obj.constructor.name === "Uint8Array";
|
|
350
|
-
}
|
|
351
|
-
__name(isUint8Array, "isUint8Array");
|
|
352
|
-
|
|
353
|
-
// src/common/data/deep.ts
|
|
354
|
-
function deepEqual(a, b, hash = /* @__PURE__ */ new WeakSet()) {
|
|
355
|
-
if (a === b) {
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
if (hash.has(b)) {
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
361
|
-
if (!isPrimitive(b)) {
|
|
362
|
-
hash.add(b);
|
|
363
|
-
}
|
|
364
|
-
if (!(a instanceof Object) || !(b instanceof Object)) {
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
367
|
-
if (a.constructor !== b.constructor) {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
if (a.length !== b.length) {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
for (let p in a) {
|
|
374
|
-
if (!a.hasOwnProperty(p)) {
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
if (!b.hasOwnProperty(p)) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
let aa = a[p];
|
|
381
|
-
let bb = b[p];
|
|
382
|
-
if (!deepEqual(aa, bb, hash)) {
|
|
383
|
-
return false;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
for (let p in b) {
|
|
387
|
-
if (b.hasOwnProperty(p) && !a.hasOwnProperty(p)) {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return true;
|
|
392
|
-
}
|
|
393
|
-
__name(deepEqual, "deepEqual");
|
|
394
|
-
function deepMerge(target, ...sources) {
|
|
395
|
-
for (let source of sources) {
|
|
396
|
-
if (!isObject(target)) {
|
|
397
|
-
target = {};
|
|
398
|
-
}
|
|
399
|
-
if (source == null)
|
|
400
|
-
continue;
|
|
401
|
-
Object.keys(source).forEach((key) => {
|
|
402
|
-
const targetValue = target[key];
|
|
403
|
-
const sourceValue = source[key];
|
|
404
|
-
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
|
405
|
-
target[key] = targetValue.concat(sourceValue);
|
|
406
|
-
} else if (isObject(targetValue) && isObject(sourceValue)) {
|
|
407
|
-
target[key] = deepMerge(Object.assign({}, targetValue), sourceValue);
|
|
408
|
-
} else {
|
|
409
|
-
target[key] = sourceValue;
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
return target;
|
|
414
|
-
}
|
|
415
|
-
__name(deepMerge, "deepMerge");
|
|
416
|
-
|
|
417
|
-
// src/common/log-filter.ts
|
|
418
|
-
function getNamespaceFilterString(defaultNamespaceFilter2) {
|
|
419
|
-
if (defaultNamespaceFilter2 === true || defaultNamespaceFilter2 === "true" || defaultNamespaceFilter2 === "1" || typeof defaultNamespaceFilter2 === "number" && defaultNamespaceFilter2 !== 0) {
|
|
420
|
-
defaultNamespaceFilter2 = "*";
|
|
421
|
-
} else if (defaultNamespaceFilter2 === false || defaultNamespaceFilter2 === "false" || defaultNamespaceFilter2 === 0 || defaultNamespaceFilter2 === "0" || defaultNamespaceFilter2 == null || defaultNamespaceFilter2 === "null" || defaultNamespaceFilter2 === "undefined") {
|
|
422
|
-
defaultNamespaceFilter2 = "";
|
|
423
|
-
} else {
|
|
424
|
-
defaultNamespaceFilter2 = String(defaultNamespaceFilter2);
|
|
425
|
-
}
|
|
426
|
-
return defaultNamespaceFilter2;
|
|
427
|
-
}
|
|
428
|
-
__name(getNamespaceFilterString, "getNamespaceFilterString");
|
|
429
|
-
var defaultNamespaceFilter = getNamespaceFilterString(
|
|
430
|
-
typeof process !== "undefined" ? process.env.ZEED ?? process.env.DEBUG : typeof localStorage !== "undefined" ? localStorage.zeed ?? localStorage.debug : "*"
|
|
431
|
-
);
|
|
432
|
-
function useNamespaceFilter(filter = defaultNamespaceFilter) {
|
|
433
|
-
let fn;
|
|
434
|
-
let reject = [];
|
|
435
|
-
let accept = [];
|
|
436
|
-
if (!filter) {
|
|
437
|
-
fn = /* @__PURE__ */ __name(function(name) {
|
|
438
|
-
return false;
|
|
439
|
-
}, "fn");
|
|
440
|
-
} else if (filter === "*") {
|
|
441
|
-
fn = /* @__PURE__ */ __name(function(name) {
|
|
442
|
-
return true;
|
|
443
|
-
}, "fn");
|
|
444
|
-
} else {
|
|
445
|
-
let i;
|
|
446
|
-
const split = filter.split(/[\s,]+/);
|
|
447
|
-
const len = split.length;
|
|
448
|
-
for (i = 0; i < len; i++) {
|
|
449
|
-
if (!split[i]) {
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
let template = split[i].replace(/\*/g, ".*?");
|
|
453
|
-
if (template[0] === "-") {
|
|
454
|
-
reject.push(new RegExp("^" + template.substr(1) + "$"));
|
|
455
|
-
} else {
|
|
456
|
-
accept.push(new RegExp("^" + template + "$"));
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
fn = /* @__PURE__ */ __name(function(name) {
|
|
460
|
-
if (reject.length === 0 && accept.length === 0) {
|
|
461
|
-
return true;
|
|
462
|
-
}
|
|
463
|
-
let i2, len2;
|
|
464
|
-
for (i2 = 0, len2 = reject.length; i2 < len2; i2++) {
|
|
465
|
-
if (reject[i2].test(name)) {
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
for (i2 = 0, len2 = accept.length; i2 < len2; i2++) {
|
|
470
|
-
if (accept[i2].test(name)) {
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return false;
|
|
475
|
-
}, "fn");
|
|
476
|
-
}
|
|
477
|
-
fn.accept = accept;
|
|
478
|
-
fn.reject = reject;
|
|
479
|
-
fn.filter = filter;
|
|
480
|
-
return fn;
|
|
481
|
-
}
|
|
482
|
-
__name(useNamespaceFilter, "useNamespaceFilter");
|
|
483
|
-
var defaultLevelFilter = typeof process !== "undefined" ? process.env.ZEED_LEVEL ?? process.env.LEVEL ?? process.env.DEBUG_LEVEL : typeof localStorage !== "undefined" ? localStorage.zeed_level ?? localStorage.level ?? localStorage.debug_level : void 0;
|
|
484
|
-
function parseLogLevel(filter) {
|
|
485
|
-
if (filter === false)
|
|
486
|
-
return Infinity /* off */;
|
|
487
|
-
if (typeof filter === "number")
|
|
488
|
-
return filter;
|
|
489
|
-
if (typeof filter === "string") {
|
|
490
|
-
const l = LogLevelAlias[filter.toLocaleLowerCase().trim()];
|
|
491
|
-
if (l != null)
|
|
492
|
-
return l;
|
|
493
|
-
}
|
|
494
|
-
return -1 /* all */;
|
|
495
|
-
}
|
|
496
|
-
__name(parseLogLevel, "parseLogLevel");
|
|
497
|
-
function useLevelFilter(filter = defaultLevelFilter) {
|
|
498
|
-
const filterLevel = parseLogLevel(filter);
|
|
499
|
-
return (level) => level >= filterLevel;
|
|
500
|
-
}
|
|
501
|
-
__name(useLevelFilter, "useLevelFilter");
|
|
502
|
-
|
|
503
|
-
// src/common/log-base.ts
|
|
504
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
505
|
-
LogLevel2[LogLevel2["all"] = -1] = "all";
|
|
506
|
-
LogLevel2[LogLevel2["debug"] = 0] = "debug";
|
|
507
|
-
LogLevel2[LogLevel2["info"] = 1] = "info";
|
|
508
|
-
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
|
509
|
-
LogLevel2[LogLevel2["error"] = 3] = "error";
|
|
510
|
-
LogLevel2[LogLevel2["fatal"] = 4] = "fatal";
|
|
511
|
-
LogLevel2[LogLevel2["off"] = Infinity] = "off";
|
|
512
|
-
return LogLevel2;
|
|
513
|
-
})(LogLevel || {});
|
|
514
|
-
var LogLevelAlias = {
|
|
515
|
-
"*": -1 /* all */,
|
|
516
|
-
a: -1 /* all */,
|
|
517
|
-
all: -1 /* all */,
|
|
518
|
-
d: 0 /* debug */,
|
|
519
|
-
dbg: 0 /* debug */,
|
|
520
|
-
debug: 0 /* debug */,
|
|
521
|
-
i: 1 /* info */,
|
|
522
|
-
inf: 1 /* info */,
|
|
523
|
-
info: 1 /* info */,
|
|
524
|
-
w: 2 /* warn */,
|
|
525
|
-
warn: 2 /* warn */,
|
|
526
|
-
warning: 2 /* warn */,
|
|
527
|
-
e: 3 /* error */,
|
|
528
|
-
err: 3 /* error */,
|
|
529
|
-
error: 3 /* error */,
|
|
530
|
-
fatal: 4 /* fatal */,
|
|
531
|
-
off: Infinity /* off */,
|
|
532
|
-
"-": Infinity /* off */
|
|
533
|
-
};
|
|
534
|
-
function LoggerContext(prefix = "") {
|
|
535
|
-
let logHandlers = [LoggerConsoleHandler()];
|
|
536
|
-
let logAssertLevel = 2 /* warn */;
|
|
537
|
-
let logCheckNamespace = /* @__PURE__ */ __name((name) => true, "logCheckNamespace");
|
|
538
|
-
let logLock = false;
|
|
539
|
-
let logFactory = LoggerBaseFactory;
|
|
540
|
-
function LoggerBaseFactory(name = "", level) {
|
|
541
|
-
function log12(...messages2) {
|
|
542
|
-
emit({
|
|
543
|
-
name,
|
|
544
|
-
messages: messages2,
|
|
545
|
-
level: 0 /* debug */
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
__name(log12, "log");
|
|
549
|
-
log12.label = name;
|
|
550
|
-
log12.active = true;
|
|
551
|
-
log12.level = parseLogLevel(level ?? -1 /* all */);
|
|
552
|
-
log12.extend = function(prefix2) {
|
|
553
|
-
return logFactory(name ? `${name}:${prefix2}` : prefix2);
|
|
554
|
-
};
|
|
555
|
-
const emit = /* @__PURE__ */ __name((msg) => {
|
|
556
|
-
if (log12.active === true) {
|
|
557
|
-
if (msg.level >= Logger2.level && msg.level >= log12.level) {
|
|
558
|
-
if (logCheckNamespace(name)) {
|
|
559
|
-
for (let handler of logHandlers) {
|
|
560
|
-
if (handler)
|
|
561
|
-
handler(msg);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}, "emit");
|
|
567
|
-
log12.debug = function(...messages2) {
|
|
568
|
-
emit({
|
|
569
|
-
name,
|
|
570
|
-
messages: messages2,
|
|
571
|
-
level: 0 /* debug */
|
|
572
|
-
});
|
|
573
|
-
};
|
|
574
|
-
log12.info = function(...messages2) {
|
|
575
|
-
emit({
|
|
576
|
-
name,
|
|
577
|
-
messages: messages2,
|
|
578
|
-
level: 1 /* info */
|
|
579
|
-
});
|
|
580
|
-
};
|
|
581
|
-
log12.warn = function(...messages2) {
|
|
582
|
-
emit({
|
|
583
|
-
name,
|
|
584
|
-
messages: messages2,
|
|
585
|
-
level: 2 /* warn */
|
|
586
|
-
});
|
|
587
|
-
};
|
|
588
|
-
log12.error = function(...messages2) {
|
|
589
|
-
emit({
|
|
590
|
-
name,
|
|
591
|
-
messages: messages2,
|
|
592
|
-
level: 3 /* error */
|
|
593
|
-
});
|
|
594
|
-
};
|
|
595
|
-
log12.assert = function(cond, ...messages2) {
|
|
596
|
-
if (!cond) {
|
|
597
|
-
if (typeof console !== void 0) {
|
|
598
|
-
if (console.assert) {
|
|
599
|
-
console.assert(cond, ...messages2);
|
|
600
|
-
} else {
|
|
601
|
-
console.error(`Assert did fail with: ${cond}`, ...messages2);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
emit({
|
|
605
|
-
name,
|
|
606
|
-
messages: messages2 || [`Assert did fail with: ${cond}`],
|
|
607
|
-
level: logAssertLevel
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
log12.assertEqual = function(value, expected, ...args) {
|
|
612
|
-
let equal = deepEqual(value, expected);
|
|
613
|
-
if (!equal) {
|
|
614
|
-
log12.assert(
|
|
615
|
-
equal,
|
|
616
|
-
`Assert did fail. Expected ${expected} got ${value}`,
|
|
617
|
-
expected,
|
|
618
|
-
value,
|
|
619
|
-
...args
|
|
620
|
-
);
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
log12.assertNotEqual = function(value, expected, ...args) {
|
|
624
|
-
let equal = deepEqual(value, expected);
|
|
625
|
-
if (equal) {
|
|
626
|
-
log12.assert(
|
|
627
|
-
equal,
|
|
628
|
-
`Assert did fail. Expected ${expected} not to be equal with ${value}`,
|
|
629
|
-
expected,
|
|
630
|
-
value,
|
|
631
|
-
...args
|
|
632
|
-
);
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
return log12;
|
|
636
|
-
}
|
|
637
|
-
__name(LoggerBaseFactory, "LoggerBaseFactory");
|
|
638
|
-
function Logger2(name = "", level) {
|
|
639
|
-
return logFactory(name, level);
|
|
640
|
-
}
|
|
641
|
-
__name(Logger2, "Logger");
|
|
642
|
-
Logger2.registerHandler = function(handler) {
|
|
643
|
-
logHandlers.push(handler);
|
|
644
|
-
};
|
|
645
|
-
Logger2.setFilter = function(namespaces3) {
|
|
646
|
-
logCheckNamespace = useNamespaceFilter(namespaces3);
|
|
647
|
-
};
|
|
648
|
-
Logger2.setLock = (lock = true) => logLock = lock;
|
|
649
|
-
Logger2.setHandlers = function(handlers = []) {
|
|
650
|
-
if (logFactory !== LoggerBaseFactory) {
|
|
651
|
-
logFactory = LoggerBaseFactory;
|
|
652
|
-
}
|
|
653
|
-
if (logLock)
|
|
654
|
-
return;
|
|
655
|
-
logHandlers = [...handlers].filter((h) => typeof h === "function");
|
|
656
|
-
};
|
|
657
|
-
Logger2.level = -1 /* all */;
|
|
658
|
-
Logger2.setLogLevel = function(level = -1 /* all */) {
|
|
659
|
-
if (logLock)
|
|
660
|
-
return;
|
|
661
|
-
Logger2.level = level;
|
|
662
|
-
};
|
|
663
|
-
Logger2.setFactory = function(factory) {
|
|
664
|
-
if (logLock)
|
|
665
|
-
return;
|
|
666
|
-
logFactory = factory;
|
|
667
|
-
};
|
|
668
|
-
return Logger2;
|
|
669
|
-
}
|
|
670
|
-
__name(LoggerContext, "LoggerContext");
|
|
671
|
-
|
|
672
|
-
// src/common/log-console.ts
|
|
673
|
-
function LoggerConsoleHandler(opt = {}) {
|
|
674
|
-
const {
|
|
675
|
-
level = void 0,
|
|
676
|
-
filter = void 0,
|
|
677
|
-
colors: colors2 = true,
|
|
678
|
-
levelHelper = false,
|
|
679
|
-
nameBrackets = true,
|
|
680
|
-
padding = 16
|
|
681
|
-
} = opt;
|
|
682
|
-
const matchesNamespace = useNamespaceFilter(filter);
|
|
683
|
-
const matchesLevel = useLevelFilter(level);
|
|
684
|
-
return (msg) => {
|
|
685
|
-
if (!matchesLevel(msg.level))
|
|
686
|
-
return;
|
|
687
|
-
if (!matchesNamespace(msg.name))
|
|
688
|
-
return;
|
|
689
|
-
let name = msg.name ? `[${msg.name}]` : "";
|
|
690
|
-
switch (msg.level) {
|
|
691
|
-
case 1 /* info */:
|
|
692
|
-
console.info(`I|* ${name}`, ...msg.messages);
|
|
693
|
-
break;
|
|
694
|
-
case 2 /* warn */:
|
|
695
|
-
console.warn(`W|** ${name}`, ...msg.messages);
|
|
696
|
-
break;
|
|
697
|
-
case 3 /* error */:
|
|
698
|
-
console.error(`E|*** ${name}`, ...msg.messages);
|
|
699
|
-
break;
|
|
700
|
-
default:
|
|
701
|
-
console.debug(`D| ${name}`, ...msg.messages);
|
|
702
|
-
break;
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
__name(LoggerConsoleHandler, "LoggerConsoleHandler");
|
|
707
|
-
|
|
708
|
-
// src/common/global.ts
|
|
709
|
-
function _global() {
|
|
710
|
-
if (typeof self !== "undefined")
|
|
711
|
-
return self;
|
|
712
|
-
if (typeof window !== "undefined")
|
|
713
|
-
return window;
|
|
714
|
-
if (typeof global !== "undefined")
|
|
715
|
-
return global;
|
|
716
|
-
if (typeof globalThis !== "undefined")
|
|
717
|
-
return globalThis;
|
|
718
|
-
throw new Error("unable to locate global object");
|
|
719
|
-
}
|
|
720
|
-
__name(_global, "_global");
|
|
721
|
-
function getGlobalContext() {
|
|
722
|
-
let gcontext = _global();
|
|
723
|
-
if (gcontext._zeedGlobal == null) {
|
|
724
|
-
gcontext._zeedGlobal = {};
|
|
725
|
-
}
|
|
726
|
-
return gcontext._zeedGlobal;
|
|
727
|
-
}
|
|
728
|
-
__name(getGlobalContext, "getGlobalContext");
|
|
729
|
-
|
|
730
|
-
// src/common/log.ts
|
|
731
|
-
var globalLogger;
|
|
732
|
-
function getLoggerContext() {
|
|
733
|
-
let logger = LoggerContext();
|
|
734
|
-
logger.setHandlers([LoggerConsoleHandler()]);
|
|
735
|
-
return logger;
|
|
736
|
-
}
|
|
737
|
-
__name(getLoggerContext, "getLoggerContext");
|
|
738
|
-
try {
|
|
739
|
-
let _global2 = getGlobalContext();
|
|
740
|
-
if (_global2 != null) {
|
|
741
|
-
if ((_global2 == null ? void 0 : _global2.logger) == null) {
|
|
742
|
-
globalLogger = getLoggerContext();
|
|
743
|
-
_global2.logger = globalLogger;
|
|
744
|
-
} else {
|
|
745
|
-
globalLogger = _global2.logger;
|
|
746
|
-
}
|
|
747
|
-
} else {
|
|
748
|
-
globalLogger = getLoggerContext();
|
|
749
|
-
}
|
|
750
|
-
} catch (e) {
|
|
751
|
-
globalLogger = getLoggerContext();
|
|
752
|
-
}
|
|
753
|
-
var Logger = globalLogger;
|
|
754
|
-
|
|
755
|
-
// src/common/data/bin.ts
|
|
756
|
-
var log = Logger("bin");
|
|
757
|
-
function _encodeUtf8Polyfill(str) {
|
|
758
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
759
|
-
const len = encodedString.length;
|
|
760
|
-
const buf = new Uint8Array(len);
|
|
761
|
-
for (let i = 0; i < len; i++) {
|
|
762
|
-
buf[i] = encodedString.codePointAt(i) || 0;
|
|
763
|
-
}
|
|
764
|
-
return buf;
|
|
765
|
-
}
|
|
766
|
-
__name(_encodeUtf8Polyfill, "_encodeUtf8Polyfill");
|
|
767
|
-
function _decodeUtf8Polyfill(buf) {
|
|
768
|
-
let remainingLen = buf.length;
|
|
769
|
-
let encodedString = "";
|
|
770
|
-
let bufPos = 0;
|
|
771
|
-
while (remainingLen > 0) {
|
|
772
|
-
const nextLen = remainingLen < 1e4 ? remainingLen : 1e4;
|
|
773
|
-
const bytes = buf.subarray(bufPos, bufPos + nextLen);
|
|
774
|
-
bufPos += nextLen;
|
|
775
|
-
encodedString += String.fromCodePoint.apply(null, bytes);
|
|
776
|
-
remainingLen -= nextLen;
|
|
777
|
-
}
|
|
778
|
-
return decodeURIComponent(escape(encodedString));
|
|
779
|
-
}
|
|
780
|
-
__name(_decodeUtf8Polyfill, "_decodeUtf8Polyfill");
|
|
781
|
-
var _textEncoder;
|
|
782
|
-
function stringToUInt8Array(text) {
|
|
783
|
-
if (_textEncoder == null) {
|
|
784
|
-
_textEncoder = _encodeUtf8Polyfill;
|
|
785
|
-
if (typeof TextEncoder !== "undefined") {
|
|
786
|
-
const encoder = new TextEncoder();
|
|
787
|
-
_textEncoder = /* @__PURE__ */ __name((data) => encoder.encode(data), "_textEncoder");
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
return _textEncoder(text.normalize("NFC"));
|
|
791
|
-
}
|
|
792
|
-
__name(stringToUInt8Array, "stringToUInt8Array");
|
|
793
|
-
var _textDecoder;
|
|
794
|
-
function Uint8ArrayToString(bin) {
|
|
795
|
-
if (_textDecoder == null) {
|
|
796
|
-
_textDecoder = _decodeUtf8Polyfill;
|
|
797
|
-
if (typeof TextDecoder !== "undefined") {
|
|
798
|
-
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
799
|
-
_textDecoder = /* @__PURE__ */ __name((data) => decoder.decode(data), "_textDecoder");
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
return _textDecoder(bin).normalize("NFC");
|
|
803
|
-
}
|
|
804
|
-
__name(Uint8ArrayToString, "Uint8ArrayToString");
|
|
805
|
-
function toUint8Array(data) {
|
|
806
|
-
if (data instanceof ArrayBuffer)
|
|
807
|
-
return new Uint8Array(data);
|
|
808
|
-
if (typeof data === "string")
|
|
809
|
-
return stringToUInt8Array(data);
|
|
810
|
-
if (data.length)
|
|
811
|
-
return new Uint8Array(data);
|
|
812
|
-
return data;
|
|
813
|
-
}
|
|
814
|
-
__name(toUint8Array, "toUint8Array");
|
|
815
|
-
function joinToUint8Array(...args) {
|
|
816
|
-
let length = 0;
|
|
817
|
-
const bins = args.flat(1).map((d) => {
|
|
818
|
-
const b = toUint8Array(d);
|
|
819
|
-
length += b.length;
|
|
820
|
-
return b;
|
|
821
|
-
});
|
|
822
|
-
let bin = new Uint8Array(length);
|
|
823
|
-
let cursor = 0;
|
|
824
|
-
for (let b of bins) {
|
|
825
|
-
bin.set(b, cursor);
|
|
826
|
-
cursor += b.length;
|
|
827
|
-
}
|
|
828
|
-
return bin;
|
|
829
|
-
}
|
|
830
|
-
__name(joinToUint8Array, "joinToUint8Array");
|
|
831
|
-
function toHex(bin) {
|
|
832
|
-
if (typeof Buffer !== "undefined") {
|
|
833
|
-
return Buffer.from(toUint8Array(bin)).toString("hex");
|
|
834
|
-
}
|
|
835
|
-
const h = "0123456789abcdef";
|
|
836
|
-
let s = "";
|
|
837
|
-
for (const v of [...toUint8Array(bin)]) {
|
|
838
|
-
s += h[v >> 4] + h[v & 15];
|
|
839
|
-
}
|
|
840
|
-
return s;
|
|
841
|
-
}
|
|
842
|
-
__name(toHex, "toHex");
|
|
843
|
-
function toBase64(bin) {
|
|
844
|
-
const bytes = toUint8Array(bin);
|
|
845
|
-
if (typeof Buffer !== "undefined") {
|
|
846
|
-
return Buffer.from(bytes).toString("base64");
|
|
847
|
-
}
|
|
848
|
-
let s = "";
|
|
849
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
850
|
-
s += String.fromCharCode(bytes[i]);
|
|
851
|
-
}
|
|
852
|
-
return btoa(s);
|
|
853
|
-
}
|
|
854
|
-
__name(toBase64, "toBase64");
|
|
855
|
-
function toBase64Url(bin) {
|
|
856
|
-
const bytes = toUint8Array(bin);
|
|
857
|
-
if (typeof Buffer !== "undefined") {
|
|
858
|
-
return Buffer.from(bytes).toString("base64url");
|
|
859
|
-
}
|
|
860
|
-
let s = "";
|
|
861
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
862
|
-
s += String.fromCharCode(bytes[i]);
|
|
863
|
-
}
|
|
864
|
-
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_");
|
|
865
|
-
}
|
|
866
|
-
__name(toBase64Url, "toBase64Url");
|
|
867
|
-
function fromBase64(s) {
|
|
868
|
-
if (typeof Buffer !== "undefined") {
|
|
869
|
-
const buf = Buffer.from(s, "base64");
|
|
870
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
871
|
-
}
|
|
872
|
-
const a = atob(s);
|
|
873
|
-
const bytes = new Uint8Array(a.length);
|
|
874
|
-
for (let i = 0; i < a.length; i++) {
|
|
875
|
-
bytes[i] = a.charCodeAt(i);
|
|
876
|
-
}
|
|
877
|
-
return bytes;
|
|
878
|
-
}
|
|
879
|
-
__name(fromBase64, "fromBase64");
|
|
880
|
-
function equalBinary(a, b) {
|
|
881
|
-
if (a.byteLength !== b.byteLength)
|
|
882
|
-
return false;
|
|
883
|
-
const aa = toUint8Array(a);
|
|
884
|
-
const bb = toUint8Array(b);
|
|
885
|
-
for (let i = 0; i < aa.length; i++) {
|
|
886
|
-
if (aa[i] !== bb[i]) {
|
|
887
|
-
return false;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
return true;
|
|
891
|
-
}
|
|
892
|
-
__name(equalBinary, "equalBinary");
|
|
893
|
-
function jsonToUint8Array(json) {
|
|
894
|
-
try {
|
|
895
|
-
return stringToUInt8Array(JSON.stringify(json));
|
|
896
|
-
} catch (err) {
|
|
897
|
-
log.warn("jsonToUint8Array", json);
|
|
898
|
-
throw err;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
__name(jsonToUint8Array, "jsonToUint8Array");
|
|
902
|
-
function Uint8ArrayToJson(data) {
|
|
903
|
-
try {
|
|
904
|
-
return JSON.parse(Uint8ArrayToString(data));
|
|
905
|
-
} catch (err) {
|
|
906
|
-
log.warn("Uint8ArrayToJson", data);
|
|
907
|
-
throw err;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
__name(Uint8ArrayToJson, "Uint8ArrayToJson");
|
|
911
|
-
function Uint8ArrayToHexDump(buffer, blockSize) {
|
|
912
|
-
if (typeof buffer === "string") ; else if (buffer instanceof ArrayBuffer && buffer.byteLength !== void 0) {
|
|
913
|
-
buffer = String.fromCharCode.apply(
|
|
914
|
-
String,
|
|
915
|
-
[].slice.call(new Uint8Array(buffer))
|
|
916
|
-
);
|
|
917
|
-
} else if (Array.isArray(buffer)) {
|
|
918
|
-
buffer = String.fromCharCode.apply(String, buffer);
|
|
919
|
-
} else if (buffer.constructor === Uint8Array) {
|
|
920
|
-
buffer = String.fromCharCode.apply(String, [].slice.call(buffer));
|
|
921
|
-
} else {
|
|
922
|
-
return false;
|
|
923
|
-
}
|
|
924
|
-
blockSize = blockSize || 16;
|
|
925
|
-
var lines = [];
|
|
926
|
-
var hex = "0123456789ABCDEF";
|
|
927
|
-
for (var b = 0; b < buffer.length; b += blockSize) {
|
|
928
|
-
var block = buffer.slice(b, Math.min(b + blockSize, buffer.length));
|
|
929
|
-
var addr = ("0000" + b.toString(16)).slice(-4);
|
|
930
|
-
var codes = block.split("").map((ch) => {
|
|
931
|
-
var code = ch.charCodeAt(0);
|
|
932
|
-
return " " + hex[(240 & code) >> 4] + hex[15 & code];
|
|
933
|
-
}).join("");
|
|
934
|
-
codes += " ".repeat(blockSize - block.length);
|
|
935
|
-
var chars = block.replace(/[\x00-\x1F\x20]/g, ".");
|
|
936
|
-
chars += " ".repeat(blockSize - block.length);
|
|
937
|
-
lines.push(addr + " " + codes + " " + chars);
|
|
938
|
-
}
|
|
939
|
-
return lines.join("\n");
|
|
940
|
-
}
|
|
941
|
-
__name(Uint8ArrayToHexDump, "Uint8ArrayToHexDump");
|
|
942
|
-
|
|
943
|
-
// src/common/crypto.ts
|
|
944
|
-
function randomUint8Array(length = 16) {
|
|
945
|
-
let randomBytes = new Uint8Array(length);
|
|
946
|
-
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
947
|
-
crypto.getRandomValues(randomBytes);
|
|
948
|
-
} else {
|
|
949
|
-
for (let i = 0; i < length; i++) {
|
|
950
|
-
randomBytes[i] = Math.floor(Math.random() * 256);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return randomBytes;
|
|
954
|
-
}
|
|
955
|
-
__name(randomUint8Array, "randomUint8Array");
|
|
956
|
-
var DEFAULT_HASH_ALG = "SHA-256";
|
|
957
|
-
var DEFAULT_CRYPTO_ALG = "AES-GCM";
|
|
958
|
-
var DEFAULT_DERIVE_ALG = "PBKDF2";
|
|
959
|
-
async function digest(message, algorithm = DEFAULT_HASH_ALG) {
|
|
960
|
-
return toUint8Array(
|
|
961
|
-
await crypto.subtle.digest(algorithm, toUint8Array(message))
|
|
962
|
-
);
|
|
963
|
-
}
|
|
964
|
-
__name(digest, "digest");
|
|
965
|
-
async function deriveKeyPbkdf2(secret, opt = {}) {
|
|
966
|
-
const secretBuffer = toUint8Array(secret);
|
|
967
|
-
const keyMaterial = await crypto.subtle.importKey(
|
|
968
|
-
"raw",
|
|
969
|
-
secretBuffer,
|
|
970
|
-
DEFAULT_DERIVE_ALG,
|
|
971
|
-
false,
|
|
972
|
-
["deriveKey"]
|
|
973
|
-
);
|
|
974
|
-
return await crypto.subtle.deriveKey(
|
|
975
|
-
{
|
|
976
|
-
name: DEFAULT_DERIVE_ALG,
|
|
977
|
-
salt: opt.salt ? toUint8Array(opt.salt) : new Uint8Array(0),
|
|
978
|
-
iterations: opt.iterations ?? 1e5,
|
|
979
|
-
hash: DEFAULT_HASH_ALG
|
|
980
|
-
},
|
|
981
|
-
keyMaterial,
|
|
982
|
-
{
|
|
983
|
-
name: DEFAULT_CRYPTO_ALG,
|
|
984
|
-
length: 256
|
|
985
|
-
},
|
|
986
|
-
true,
|
|
987
|
-
["encrypt", "decrypt"]
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
__name(deriveKeyPbkdf2, "deriveKeyPbkdf2");
|
|
991
|
-
var MAGIC_ID = new Uint8Array([1, 1]);
|
|
992
|
-
async function encrypt(data, key) {
|
|
993
|
-
const iv = randomUint8Array(12);
|
|
994
|
-
const cipher = await crypto.subtle.encrypt(
|
|
995
|
-
{ name: DEFAULT_CRYPTO_ALG, iv },
|
|
996
|
-
key,
|
|
997
|
-
data
|
|
998
|
-
);
|
|
999
|
-
const binCypher = new Uint8Array(cipher);
|
|
1000
|
-
const bufferLength = MAGIC_ID.length + iv.length + binCypher.length;
|
|
1001
|
-
const buffer = new Uint8Array(bufferLength);
|
|
1002
|
-
let pos = 0;
|
|
1003
|
-
buffer.set(MAGIC_ID, pos);
|
|
1004
|
-
pos += MAGIC_ID.length;
|
|
1005
|
-
buffer.set(iv, pos);
|
|
1006
|
-
pos += iv.length;
|
|
1007
|
-
buffer.set(binCypher, pos);
|
|
1008
|
-
return buffer;
|
|
1009
|
-
}
|
|
1010
|
-
__name(encrypt, "encrypt");
|
|
1011
|
-
async function decrypt(data, key) {
|
|
1012
|
-
let magic = data.subarray(0, 2);
|
|
1013
|
-
if (!equalBinary(magic, MAGIC_ID)) {
|
|
1014
|
-
return Promise.reject(`Unknown magic ${magic}`);
|
|
1015
|
-
}
|
|
1016
|
-
let iv = data.subarray(2, 2 + 12);
|
|
1017
|
-
let cipher = data.subarray(2 + 12, data.length);
|
|
1018
|
-
const plain = await crypto.subtle.decrypt(
|
|
1019
|
-
{ name: DEFAULT_CRYPTO_ALG, iv },
|
|
1020
|
-
key,
|
|
1021
|
-
cipher
|
|
1022
|
-
);
|
|
1023
|
-
return new Uint8Array(plain);
|
|
1024
|
-
}
|
|
1025
|
-
__name(decrypt, "decrypt");
|
|
1026
|
-
|
|
1027
|
-
// src/common/csv.ts
|
|
1028
|
-
var separator = ",";
|
|
1029
|
-
function filterFloat(value) {
|
|
1030
|
-
if (/^([-+])?([0-9]+(\.[0-9]+)?|Infinity)$/.test(value)) {
|
|
1031
|
-
return Number(value);
|
|
1032
|
-
}
|
|
1033
|
-
return NaN;
|
|
1034
|
-
}
|
|
1035
|
-
__name(filterFloat, "filterFloat");
|
|
1036
|
-
function escape2(field) {
|
|
1037
|
-
if (field == void 0) {
|
|
1038
|
-
return "";
|
|
1039
|
-
}
|
|
1040
|
-
if (!isNaN(filterFloat(field)) && isFinite(field)) {
|
|
1041
|
-
return parseFloat(field);
|
|
1042
|
-
}
|
|
1043
|
-
return '"' + String(field).replace(/"/g, '""') + '"';
|
|
1044
|
-
}
|
|
1045
|
-
__name(escape2, "escape");
|
|
1046
|
-
function csv(data, headerRow) {
|
|
1047
|
-
let body = "";
|
|
1048
|
-
if (headerRow) {
|
|
1049
|
-
body = headerRow.join(separator) + "\r\n";
|
|
1050
|
-
}
|
|
1051
|
-
for (let i = 0; i < data.length; i++) {
|
|
1052
|
-
body += data[i].map(escape2).join(separator) + "\r\n";
|
|
1053
|
-
}
|
|
1054
|
-
return body;
|
|
1055
|
-
}
|
|
1056
|
-
__name(csv, "csv");
|
|
1057
|
-
|
|
1058
|
-
// src/common/data/math.ts
|
|
1059
|
-
function getSecureRandom() {
|
|
1060
|
-
return crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295;
|
|
1061
|
-
}
|
|
1062
|
-
__name(getSecureRandom, "getSecureRandom");
|
|
1063
|
-
function getSecureRandomIfPossible() {
|
|
1064
|
-
return typeof crypto !== "undefined" ? getSecureRandom() : Math.random();
|
|
1065
|
-
}
|
|
1066
|
-
__name(getSecureRandomIfPossible, "getSecureRandomIfPossible");
|
|
1067
|
-
function randomBoolean(bias = 0.25) {
|
|
1068
|
-
return getSecureRandomIfPossible() < bias;
|
|
1069
|
-
}
|
|
1070
|
-
__name(randomBoolean, "randomBoolean");
|
|
1071
|
-
function randomInt(max = 100, min = 0) {
|
|
1072
|
-
return min + Math.floor(getSecureRandomIfPossible() * (max - min));
|
|
1073
|
-
}
|
|
1074
|
-
__name(randomInt, "randomInt");
|
|
1075
|
-
function randomFloat(max = 100, min = 0) {
|
|
1076
|
-
return min + getSecureRandomIfPossible() * (max - min);
|
|
1077
|
-
}
|
|
1078
|
-
__name(randomFloat, "randomFloat");
|
|
1079
|
-
function between(min, value, max) {
|
|
1080
|
-
return Math.max(min, Math.min(max, value));
|
|
1081
|
-
}
|
|
1082
|
-
__name(between, "between");
|
|
1083
|
-
function sum(array) {
|
|
1084
|
-
return array.reduce((acc, value) => acc + value, 0);
|
|
1085
|
-
}
|
|
1086
|
-
__name(sum, "sum");
|
|
1087
|
-
function avg(array) {
|
|
1088
|
-
return sum(array) / array.length;
|
|
1089
|
-
}
|
|
1090
|
-
__name(avg, "avg");
|
|
1091
|
-
function isPrimeRX(value) {
|
|
1092
|
-
return !/^1?$|^(11+?)\1+$/.test("1".repeat(value));
|
|
1093
|
-
}
|
|
1094
|
-
__name(isPrimeRX, "isPrimeRX");
|
|
1095
|
-
function isPrime(value) {
|
|
1096
|
-
for (var i = 2; i < value; i++)
|
|
1097
|
-
if (value % i === 0)
|
|
1098
|
-
return false;
|
|
1099
|
-
return value > 1;
|
|
1100
|
-
}
|
|
1101
|
-
__name(isPrime, "isPrime");
|
|
1102
|
-
|
|
1103
|
-
// src/common/data/orderby.ts
|
|
1104
|
-
function parseOrderby(value = "") {
|
|
1105
|
-
let [field = "", orderby = "asc"] = value.split(" ");
|
|
1106
|
-
orderby = orderby.toLowerCase();
|
|
1107
|
-
return {
|
|
1108
|
-
field,
|
|
1109
|
-
orderby,
|
|
1110
|
-
asc: orderby !== "desc",
|
|
1111
|
-
desc: orderby === "desc"
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
__name(parseOrderby, "parseOrderby");
|
|
1115
|
-
function composeOrderby(field, asc = true) {
|
|
1116
|
-
return `${field} ${asc ? "asc" : "desc"}`;
|
|
1117
|
-
}
|
|
1118
|
-
__name(composeOrderby, "composeOrderby");
|
|
1119
|
-
function cmp(a, b, asc = true) {
|
|
1120
|
-
const aa = a || 0;
|
|
1121
|
-
const bb = b || 0;
|
|
1122
|
-
return aa > bb ? asc ? 1 : -1 : aa < bb ? asc ? -1 : 1 : 0;
|
|
1123
|
-
}
|
|
1124
|
-
__name(cmp, "cmp");
|
|
1125
|
-
function sortedOrderby(values, ...orderby) {
|
|
1126
|
-
if (orderby.length > 0) {
|
|
1127
|
-
let orderByList = orderby.map(parseOrderby);
|
|
1128
|
-
let sortValues = Array.from(values);
|
|
1129
|
-
sortValues.sort((a, b) => {
|
|
1130
|
-
for (let { field, asc } of orderByList) {
|
|
1131
|
-
const result = cmp(a[field], b[field], asc);
|
|
1132
|
-
if (result !== 0)
|
|
1133
|
-
return result;
|
|
1134
|
-
}
|
|
1135
|
-
return 0;
|
|
1136
|
-
});
|
|
1137
|
-
return sortValues;
|
|
1138
|
-
}
|
|
1139
|
-
return values;
|
|
1140
|
-
}
|
|
1141
|
-
__name(sortedOrderby, "sortedOrderby");
|
|
1142
|
-
|
|
1143
|
-
// src/common/data/array.ts
|
|
1144
|
-
function arrayUnique(x) {
|
|
1145
|
-
return x.filter((n, index) => x.indexOf(n) === index);
|
|
1146
|
-
}
|
|
1147
|
-
__name(arrayUnique, "arrayUnique");
|
|
1148
|
-
function arrayMinus(x, y) {
|
|
1149
|
-
return arrayUnique(x.filter((n) => !y.includes(n)));
|
|
1150
|
-
}
|
|
1151
|
-
__name(arrayMinus, "arrayMinus");
|
|
1152
|
-
function arrayUnion(...a) {
|
|
1153
|
-
return arrayUnique(a.reduce((acc = [], value) => acc.concat(value), []));
|
|
1154
|
-
}
|
|
1155
|
-
__name(arrayUnion, "arrayUnion");
|
|
1156
|
-
function arrayFlatten(...list) {
|
|
1157
|
-
return list.flat(Infinity);
|
|
1158
|
-
}
|
|
1159
|
-
__name(arrayFlatten, "arrayFlatten");
|
|
1160
|
-
function arrayIntersection(x, y) {
|
|
1161
|
-
return arrayUnique(x).filter((n) => y.includes(n));
|
|
1162
|
-
}
|
|
1163
|
-
__name(arrayIntersection, "arrayIntersection");
|
|
1164
|
-
function arraySymmetricDifference(x, y) {
|
|
1165
|
-
return arrayMinus(arrayUnion(x, y), arrayIntersection(x, y));
|
|
1166
|
-
}
|
|
1167
|
-
__name(arraySymmetricDifference, "arraySymmetricDifference");
|
|
1168
|
-
function arrayRemoveElement(arr, el) {
|
|
1169
|
-
if (arr && Array.isArray(arr)) {
|
|
1170
|
-
let index;
|
|
1171
|
-
while ((index = arr.indexOf(el)) !== -1) {
|
|
1172
|
-
arr.splice(index, 1);
|
|
1173
|
-
}
|
|
1174
|
-
return arr;
|
|
1175
|
-
}
|
|
1176
|
-
return [];
|
|
1177
|
-
}
|
|
1178
|
-
__name(arrayRemoveElement, "arrayRemoveElement");
|
|
1179
|
-
function arraySetElement(arr, el) {
|
|
1180
|
-
if (!arr.includes(el))
|
|
1181
|
-
arr.push(el);
|
|
1182
|
-
return arr;
|
|
1183
|
-
}
|
|
1184
|
-
__name(arraySetElement, "arraySetElement");
|
|
1185
|
-
function arrayFilterInPlace(array, fn) {
|
|
1186
|
-
array.splice(0, array.length, ...array.filter(fn));
|
|
1187
|
-
return array;
|
|
1188
|
-
}
|
|
1189
|
-
__name(arrayFilterInPlace, "arrayFilterInPlace");
|
|
1190
|
-
function arrayToggleInPlace(array, el) {
|
|
1191
|
-
const index = array.findIndex((e) => e === el);
|
|
1192
|
-
if (index >= 0)
|
|
1193
|
-
array.splice(index, 1);
|
|
1194
|
-
else
|
|
1195
|
-
array.push(el);
|
|
1196
|
-
return array;
|
|
1197
|
-
}
|
|
1198
|
-
__name(arrayToggleInPlace, "arrayToggleInPlace");
|
|
1199
|
-
function arrayEmptyInPlace(array) {
|
|
1200
|
-
array.splice(0, array.length);
|
|
1201
|
-
return array;
|
|
1202
|
-
}
|
|
1203
|
-
__name(arrayEmptyInPlace, "arrayEmptyInPlace");
|
|
1204
|
-
function arraySorted(arr, cond = cmp) {
|
|
1205
|
-
return Array.from(arr).sort(cond);
|
|
1206
|
-
}
|
|
1207
|
-
__name(arraySorted, "arraySorted");
|
|
1208
|
-
function arraySortedNumbers(arr) {
|
|
1209
|
-
return arraySorted(arr, (l, r) => l - r);
|
|
1210
|
-
}
|
|
1211
|
-
__name(arraySortedNumbers, "arraySortedNumbers");
|
|
1212
|
-
function arrayIsEqual(array1, array2) {
|
|
1213
|
-
return array1.length === array2.length && array1.every((value, index) => value === array2[index]);
|
|
1214
|
-
}
|
|
1215
|
-
__name(arrayIsEqual, "arrayIsEqual");
|
|
1216
|
-
function arrayShuffleInPlace(array) {
|
|
1217
|
-
array.sort(() => getSecureRandomIfPossible() > 0.5 ? 1 : -1);
|
|
1218
|
-
return array;
|
|
1219
|
-
}
|
|
1220
|
-
__name(arrayShuffleInPlace, "arrayShuffleInPlace");
|
|
1221
|
-
function arrayShuffle(array) {
|
|
1222
|
-
return arrayShuffleInPlace(Array.from(array));
|
|
1223
|
-
}
|
|
1224
|
-
__name(arrayShuffle, "arrayShuffle");
|
|
1225
|
-
function arrayShuffleForce(array) {
|
|
1226
|
-
while (array.length > 1) {
|
|
1227
|
-
const copy = Array.from(array);
|
|
1228
|
-
arrayShuffleInPlace(copy);
|
|
1229
|
-
if (!arrayIsEqual(array, copy))
|
|
1230
|
-
return copy;
|
|
1231
|
-
}
|
|
1232
|
-
return array;
|
|
1233
|
-
}
|
|
1234
|
-
__name(arrayShuffleForce, "arrayShuffleForce");
|
|
1235
|
-
function arrayRandomElement(array) {
|
|
1236
|
-
return array[Math.floor(getSecureRandomIfPossible() * array.length)];
|
|
1237
|
-
}
|
|
1238
|
-
__name(arrayRandomElement, "arrayRandomElement");
|
|
1239
|
-
function arrayMax(...array) {
|
|
1240
|
-
return arrayFlatten(array).reduce(
|
|
1241
|
-
(acc, value) => acc != null ? value > acc ? value : acc : value,
|
|
1242
|
-
void 0
|
|
1243
|
-
);
|
|
1244
|
-
}
|
|
1245
|
-
__name(arrayMax, "arrayMax");
|
|
1246
|
-
function arrayMin(...array) {
|
|
1247
|
-
return arrayFlatten(array).reduce(
|
|
1248
|
-
(acc, value) => acc != null ? value < acc ? value : acc : value,
|
|
1249
|
-
void 0
|
|
1250
|
-
);
|
|
1251
|
-
}
|
|
1252
|
-
__name(arrayMin, "arrayMin");
|
|
1253
|
-
function arraySum(...array) {
|
|
1254
|
-
return arrayFlatten(array).reduce((acc, value) => acc + value, 0);
|
|
1255
|
-
}
|
|
1256
|
-
__name(arraySum, "arraySum");
|
|
1257
|
-
function arrayAvg(...array) {
|
|
1258
|
-
let flatArray = arrayFlatten(array);
|
|
1259
|
-
return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length;
|
|
1260
|
-
}
|
|
1261
|
-
__name(arrayAvg, "arrayAvg");
|
|
1262
|
-
function arrayBatches(array, chunckLength) {
|
|
1263
|
-
let chunks = [];
|
|
1264
|
-
let i = 0;
|
|
1265
|
-
const n = array.length;
|
|
1266
|
-
while (i < n) {
|
|
1267
|
-
chunks.push(array.slice(i, i += chunckLength));
|
|
1268
|
-
}
|
|
1269
|
-
return chunks;
|
|
1270
|
-
}
|
|
1271
|
-
__name(arrayBatches, "arrayBatches");
|
|
1272
|
-
function createArray(size2 = 0, item) {
|
|
1273
|
-
if (size2 <= 0)
|
|
1274
|
-
return [];
|
|
1275
|
-
let arr = new Array(size2);
|
|
1276
|
-
for (let i = 0; i < size2; i++) {
|
|
1277
|
-
arr[i] = item instanceof Function ? item(i) : item;
|
|
1278
|
-
}
|
|
1279
|
-
return arr;
|
|
1280
|
-
}
|
|
1281
|
-
__name(createArray, "createArray");
|
|
1282
|
-
|
|
1283
|
-
// src/common/data/basex.ts
|
|
1284
|
-
var log2 = Logger("zeed:basex");
|
|
1285
|
-
var alphabets = {
|
|
1286
|
-
"2": "01",
|
|
1287
|
-
"8": "01234567",
|
|
1288
|
-
"11": "0123456789a",
|
|
1289
|
-
"16": "0123456789abcdef",
|
|
1290
|
-
"32": "0123456789ABCDEFGHJKMNPQRSTVWXYZ",
|
|
1291
|
-
"32-rfc": "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
1292
|
-
"32-hex": "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
1293
|
-
"32-zbase": "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
1294
|
-
"36": "0123456789abcdefghijklmnopqrstuvwxyz",
|
|
1295
|
-
"58": "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
|
|
1296
|
-
"62": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
1297
|
-
"64": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
1298
|
-
"64-url": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
1299
|
-
"66": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~",
|
|
1300
|
-
"85": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
|
|
1301
|
-
};
|
|
1302
|
-
function useBase(alphaOrBase) {
|
|
1303
|
-
let ALPHABET;
|
|
1304
|
-
if (typeof alphaOrBase === "string") {
|
|
1305
|
-
ALPHABET = alphaOrBase;
|
|
1306
|
-
} else {
|
|
1307
|
-
ALPHABET = alphabets[String(alphaOrBase)];
|
|
1308
|
-
if (ALPHABET == null)
|
|
1309
|
-
throw new Error(`Unknown base ${alphaOrBase}`);
|
|
1310
|
-
}
|
|
1311
|
-
if (ALPHABET.length >= 255)
|
|
1312
|
-
throw new TypeError("Alphabet too long");
|
|
1313
|
-
const BASE_MAP = new Uint8Array(256);
|
|
1314
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
1315
|
-
BASE_MAP[j] = 255;
|
|
1316
|
-
}
|
|
1317
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
1318
|
-
const x = ALPHABET.charAt(i);
|
|
1319
|
-
const xc = x.charCodeAt(0);
|
|
1320
|
-
if (BASE_MAP[xc] !== 255)
|
|
1321
|
-
throw new TypeError(x + " is ambiguous");
|
|
1322
|
-
BASE_MAP[xc] = i;
|
|
1323
|
-
}
|
|
1324
|
-
const BASE = ALPHABET.length;
|
|
1325
|
-
const LEADER = ALPHABET.charAt(0);
|
|
1326
|
-
const FACTOR = Math.log(BASE) / Math.log(256);
|
|
1327
|
-
const iFACTOR = Math.log(256) / Math.log(BASE);
|
|
1328
|
-
function encode(source, padToLength = -1) {
|
|
1329
|
-
let data = toUint8Array(source);
|
|
1330
|
-
if (data.byteLength === 0)
|
|
1331
|
-
return "";
|
|
1332
|
-
let length = 0;
|
|
1333
|
-
let pbegin = 0;
|
|
1334
|
-
const pend = data.byteLength;
|
|
1335
|
-
while (pbegin !== pend && data[pbegin] === 0)
|
|
1336
|
-
pbegin++;
|
|
1337
|
-
const size2 = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
1338
|
-
const dataEncoded = new Uint8Array(size2);
|
|
1339
|
-
while (pbegin !== pend) {
|
|
1340
|
-
let carry = data[pbegin];
|
|
1341
|
-
let i = 0;
|
|
1342
|
-
for (let it1 = size2 - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {
|
|
1343
|
-
carry += 256 * dataEncoded[it1] >>> 0;
|
|
1344
|
-
dataEncoded[it1] = carry % BASE >>> 0;
|
|
1345
|
-
carry = carry / BASE >>> 0;
|
|
1346
|
-
}
|
|
1347
|
-
if (carry !== 0) {
|
|
1348
|
-
log2.warn("Non-zero carry", data, padToLength, i, size2);
|
|
1349
|
-
throw new Error("Non-zero carry");
|
|
1350
|
-
}
|
|
1351
|
-
length = i;
|
|
1352
|
-
pbegin++;
|
|
1353
|
-
}
|
|
1354
|
-
let it2 = size2 - length;
|
|
1355
|
-
while (it2 !== size2 && dataEncoded[it2] === 0) {
|
|
1356
|
-
it2++;
|
|
1357
|
-
}
|
|
1358
|
-
let str = "";
|
|
1359
|
-
for (; it2 < size2; ++it2)
|
|
1360
|
-
str += ALPHABET.charAt(dataEncoded[it2]);
|
|
1361
|
-
if (padToLength > 0) {
|
|
1362
|
-
return str.padStart(padToLength, LEADER);
|
|
1363
|
-
}
|
|
1364
|
-
return str;
|
|
1365
|
-
}
|
|
1366
|
-
__name(encode, "encode");
|
|
1367
|
-
function decode(source, padToLength = -1) {
|
|
1368
|
-
if (typeof source !== "string")
|
|
1369
|
-
throw new TypeError("Expected String");
|
|
1370
|
-
if (source.length === 0)
|
|
1371
|
-
return new Uint8Array();
|
|
1372
|
-
source = source.replace(/\s+/gi, "");
|
|
1373
|
-
let psz = 0;
|
|
1374
|
-
let length = 0;
|
|
1375
|
-
while (source[psz] === LEADER) {
|
|
1376
|
-
psz++;
|
|
1377
|
-
}
|
|
1378
|
-
const size2 = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
1379
|
-
const dataDecoded = new Uint8Array(size2);
|
|
1380
|
-
while (source[psz]) {
|
|
1381
|
-
let carry = BASE_MAP[source.charCodeAt(psz)];
|
|
1382
|
-
if (carry === 255)
|
|
1383
|
-
throw new Error(`Unsupported character "${source[psz]}"`);
|
|
1384
|
-
let i = 0;
|
|
1385
|
-
for (let it3 = size2 - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {
|
|
1386
|
-
carry += BASE * dataDecoded[it3] >>> 0;
|
|
1387
|
-
dataDecoded[it3] = carry % 256 >>> 0;
|
|
1388
|
-
carry = carry / 256 >>> 0;
|
|
1389
|
-
}
|
|
1390
|
-
if (carry !== 0)
|
|
1391
|
-
throw new Error("Non-zero carry");
|
|
1392
|
-
length = i;
|
|
1393
|
-
psz++;
|
|
1394
|
-
}
|
|
1395
|
-
let it4 = size2 - length;
|
|
1396
|
-
while (it4 !== size2 && dataDecoded[it4] === 0) {
|
|
1397
|
-
it4++;
|
|
1398
|
-
}
|
|
1399
|
-
if (padToLength > 0) {
|
|
1400
|
-
return new Uint8Array([
|
|
1401
|
-
...new Uint8Array(padToLength - dataDecoded.length + it4),
|
|
1402
|
-
...dataDecoded.slice(it4)
|
|
1403
|
-
]);
|
|
1404
|
-
}
|
|
1405
|
-
return dataDecoded.slice(it4);
|
|
1406
|
-
}
|
|
1407
|
-
__name(decode, "decode");
|
|
1408
|
-
return {
|
|
1409
|
-
encode,
|
|
1410
|
-
decode
|
|
1411
|
-
};
|
|
1412
|
-
}
|
|
1413
|
-
__name(useBase, "useBase");
|
|
1414
|
-
var { encode: encodeBase16, decode: decodeBase16 } = useBase(16);
|
|
1415
|
-
var { encode: encodeBase32, decode: decodeBase32 } = useBase(32);
|
|
1416
|
-
var { encode: encodeBase58, decode: decodeBase58 } = useBase(58);
|
|
1417
|
-
var { encode: encodeBase62, decode: decodeBase62 } = useBase(62);
|
|
1418
|
-
var { encode: encodeBase64, decode: decodeBase64 } = useBase(62);
|
|
1419
|
-
|
|
1420
|
-
// src/common/data/camelcase.ts
|
|
1421
|
-
var toCamelCase = /* @__PURE__ */ __name((s) => {
|
|
1422
|
-
if (s.length > 0) {
|
|
1423
|
-
if (/^[A-Z0-9_\-\ ]*$/g.test(s)) {
|
|
1424
|
-
s = s.toLowerCase();
|
|
1425
|
-
}
|
|
1426
|
-
s = s.replace(/^[-_\ ]+/gi, "").replace(/[-_\ ]+$/gi, "").replace(/[-_\ ]+([a-z0-9])/gi, ($0, $1) => $1.toUpperCase());
|
|
1427
|
-
s = s[0].toLowerCase() + s.substring(1);
|
|
1428
|
-
}
|
|
1429
|
-
return s;
|
|
1430
|
-
}, "toCamelCase");
|
|
1431
|
-
function toCapitalize(s) {
|
|
1432
|
-
return s.charAt(0).toUpperCase() + s.toLowerCase().slice(1);
|
|
1433
|
-
}
|
|
1434
|
-
__name(toCapitalize, "toCapitalize");
|
|
1435
|
-
function toCapitalizeWords(s) {
|
|
1436
|
-
return s.replace(/\w\S*/g, toCapitalize);
|
|
1437
|
-
}
|
|
1438
|
-
__name(toCapitalizeWords, "toCapitalizeWords");
|
|
1439
|
-
function fromCamelCase(str, separator2 = "-") {
|
|
1440
|
-
separator2 = typeof separator2 === "undefined" ? "_" : separator2;
|
|
1441
|
-
return str.replace(/([a-z\d])([A-Z])/g, "$1" + separator2 + "$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1" + separator2 + "$2").toLowerCase();
|
|
1442
|
-
}
|
|
1443
|
-
__name(fromCamelCase, "fromCamelCase");
|
|
1444
|
-
|
|
1445
|
-
// src/common/data/json.ts
|
|
1446
|
-
function serializer(replacer, cycleReplacer) {
|
|
1447
|
-
var stack = [], keys = [];
|
|
1448
|
-
if (cycleReplacer == null)
|
|
1449
|
-
cycleReplacer = /* @__PURE__ */ __name(function(key, value) {
|
|
1450
|
-
if (stack[0] === value)
|
|
1451
|
-
return "[Circular ~]";
|
|
1452
|
-
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
|
1453
|
-
}, "cycleReplacer");
|
|
1454
|
-
return function(key, value) {
|
|
1455
|
-
if (stack.length > 0) {
|
|
1456
|
-
var thisPos = stack.indexOf(this);
|
|
1457
|
-
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
|
1458
|
-
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
|
1459
|
-
if (~stack.indexOf(value))
|
|
1460
|
-
value = cycleReplacer == null ? void 0 : cycleReplacer.call(this, key, value);
|
|
1461
|
-
} else
|
|
1462
|
-
stack.push(value);
|
|
1463
|
-
return replacer == null ? value : replacer.call(this, key, value);
|
|
1464
|
-
};
|
|
1465
|
-
}
|
|
1466
|
-
__name(serializer, "serializer");
|
|
1467
|
-
function jsonStringify(obj, replacer, spaces, cycleReplacer) {
|
|
1468
|
-
return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
|
|
1469
|
-
}
|
|
1470
|
-
__name(jsonStringify, "jsonStringify");
|
|
1471
|
-
|
|
1472
|
-
// src/common/data/convert.ts
|
|
1473
|
-
var TRUE_VALUES_LIST = ["1", "true", "yes", "y", "on"];
|
|
1474
|
-
function stringToBoolean(value, defaultValue = false) {
|
|
1475
|
-
if (value == null || typeof value !== "string")
|
|
1476
|
-
return defaultValue;
|
|
1477
|
-
return TRUE_VALUES_LIST.includes(String(value).trim().toLowerCase());
|
|
1478
|
-
}
|
|
1479
|
-
__name(stringToBoolean, "stringToBoolean");
|
|
1480
|
-
function stringToInteger(value, defaultValue = 0) {
|
|
1481
|
-
if (value == null || typeof value !== "string")
|
|
1482
|
-
return defaultValue;
|
|
1483
|
-
return parseInt(value.trim(), 10) ?? defaultValue;
|
|
1484
|
-
}
|
|
1485
|
-
__name(stringToInteger, "stringToInteger");
|
|
1486
|
-
function stringToFloat(value, defaultValue = 0) {
|
|
1487
|
-
if (value == null || typeof value !== "string")
|
|
1488
|
-
return defaultValue;
|
|
1489
|
-
return parseFloat(value.trim()) ?? defaultValue;
|
|
1490
|
-
}
|
|
1491
|
-
__name(stringToFloat, "stringToFloat");
|
|
1492
|
-
function valueToBoolean(value, defaultValue = false) {
|
|
1493
|
-
if (value == null)
|
|
1494
|
-
return defaultValue;
|
|
1495
|
-
if (typeof value === "boolean")
|
|
1496
|
-
return value;
|
|
1497
|
-
if (typeof value === "number")
|
|
1498
|
-
return value !== 0;
|
|
1499
|
-
return TRUE_VALUES_LIST.includes(String(value).trim().toLowerCase());
|
|
1500
|
-
}
|
|
1501
|
-
__name(valueToBoolean, "valueToBoolean");
|
|
1502
|
-
function valueToInteger(value, defaultValue = 0) {
|
|
1503
|
-
if (value == null)
|
|
1504
|
-
return defaultValue;
|
|
1505
|
-
if (typeof value === "boolean")
|
|
1506
|
-
return value ? 1 : 0;
|
|
1507
|
-
if (typeof value === "number")
|
|
1508
|
-
return Math.floor(value);
|
|
1509
|
-
return parseInt(String(value).trim(), 10) ?? defaultValue;
|
|
1510
|
-
}
|
|
1511
|
-
__name(valueToInteger, "valueToInteger");
|
|
1512
|
-
function valueToFloat(value, defaultValue = 0) {
|
|
1513
|
-
if (value == null)
|
|
1514
|
-
return defaultValue;
|
|
1515
|
-
if (typeof value === "boolean")
|
|
1516
|
-
return value ? 1 : 0;
|
|
1517
|
-
if (typeof value === "number")
|
|
1518
|
-
return Math.floor(value);
|
|
1519
|
-
return parseFloat(String(value).trim()) ?? defaultValue;
|
|
1520
|
-
}
|
|
1521
|
-
__name(valueToFloat, "valueToFloat");
|
|
1522
|
-
function valueToString(value, defaultValue = "") {
|
|
1523
|
-
if (value == null)
|
|
1524
|
-
return defaultValue;
|
|
1525
|
-
return String(value) ?? defaultValue;
|
|
1526
|
-
}
|
|
1527
|
-
__name(valueToString, "valueToString");
|
|
1528
|
-
var toFloat = valueToFloat;
|
|
1529
|
-
var toInt = valueToInteger;
|
|
1530
|
-
var toString = valueToString;
|
|
1531
|
-
var toBool = valueToBoolean;
|
|
1532
|
-
function formatMessages(messages2, opt = {}) {
|
|
1533
|
-
const { trace = true, pretty = true } = opt;
|
|
1534
|
-
return messages2.map((obj) => {
|
|
1535
|
-
if (obj && typeof obj === "object") {
|
|
1536
|
-
if (pretty && (obj instanceof Uint8Array || obj instanceof ArrayBuffer)) {
|
|
1537
|
-
return "\n" + Uint8ArrayToHexDump(obj) + "\n";
|
|
1538
|
-
}
|
|
1539
|
-
if (obj instanceof Error) {
|
|
1540
|
-
if (!trace) {
|
|
1541
|
-
return `${obj.name || "Error"}: ${obj.message}`;
|
|
1542
|
-
}
|
|
1543
|
-
return `${obj.name || "Error"}: ${obj.message}
|
|
1544
|
-
${obj.stack}`;
|
|
1545
|
-
}
|
|
1546
|
-
return pretty ? jsonStringify(obj, null, 2) : jsonStringify(obj);
|
|
1547
|
-
}
|
|
1548
|
-
return String(obj);
|
|
1549
|
-
});
|
|
1550
|
-
}
|
|
1551
|
-
__name(formatMessages, "formatMessages");
|
|
1552
|
-
function renderMessages(messages2, opt = {}) {
|
|
1553
|
-
return formatMessages(messages2, opt).join(" ");
|
|
1554
|
-
}
|
|
1555
|
-
__name(renderMessages, "renderMessages");
|
|
1556
|
-
function fixBrokenUth8String(brokenString) {
|
|
1557
|
-
try {
|
|
1558
|
-
return decodeURIComponent(escape(brokenString));
|
|
1559
|
-
} catch (e) {
|
|
1560
|
-
}
|
|
1561
|
-
return brokenString;
|
|
1562
|
-
}
|
|
1563
|
-
__name(fixBrokenUth8String, "fixBrokenUth8String");
|
|
1564
|
-
|
|
1565
|
-
// src/common/data/currency.ts
|
|
1566
|
-
var defaults = {
|
|
1567
|
-
symbol: "$",
|
|
1568
|
-
separator: ",",
|
|
1569
|
-
decimal: ".",
|
|
1570
|
-
errorOnInvalid: false,
|
|
1571
|
-
precision: 2,
|
|
1572
|
-
pattern: "!#",
|
|
1573
|
-
negativePattern: "-!#",
|
|
1574
|
-
format,
|
|
1575
|
-
fromCents: false
|
|
1576
|
-
};
|
|
1577
|
-
var round = /* @__PURE__ */ __name((v) => Math.round(v), "round");
|
|
1578
|
-
var pow = /* @__PURE__ */ __name((p) => Math.pow(10, p), "pow");
|
|
1579
|
-
var rounding = /* @__PURE__ */ __name((value, increment) => round(value / increment) * increment, "rounding");
|
|
1580
|
-
var groupRegex = /(\d)(?=(\d{3})+\b)/g;
|
|
1581
|
-
var vedicRegex = /(\d)(?=(\d\d)+\d\b)/g;
|
|
1582
|
-
function currency(value, opts = {}) {
|
|
1583
|
-
return new Currency(value, opts);
|
|
1584
|
-
}
|
|
1585
|
-
__name(currency, "currency");
|
|
1586
|
-
var _Currency = class {
|
|
1587
|
-
constructor(value, opts = {}) {
|
|
1588
|
-
let settings = Object.assign({}, defaults, opts);
|
|
1589
|
-
let precision = pow(settings.precision ?? 2);
|
|
1590
|
-
let v = parse(value, settings);
|
|
1591
|
-
this.intValue = v;
|
|
1592
|
-
this.value = v / precision;
|
|
1593
|
-
settings.increment = settings.increment || 1 / precision;
|
|
1594
|
-
if (settings.useVedic) {
|
|
1595
|
-
settings.groups = vedicRegex;
|
|
1596
|
-
} else {
|
|
1597
|
-
settings.groups = groupRegex;
|
|
1598
|
-
}
|
|
1599
|
-
this._settings = settings;
|
|
1600
|
-
this._precision = precision;
|
|
1601
|
-
}
|
|
1602
|
-
add(number) {
|
|
1603
|
-
let { intValue, _settings, _precision } = this;
|
|
1604
|
-
return currency(
|
|
1605
|
-
(intValue += parse(number, _settings)) / (_settings.fromCents ? 1 : _precision),
|
|
1606
|
-
_settings
|
|
1607
|
-
);
|
|
1608
|
-
}
|
|
1609
|
-
subtract(number) {
|
|
1610
|
-
let { intValue, _settings, _precision } = this;
|
|
1611
|
-
return currency(
|
|
1612
|
-
(intValue -= parse(number, _settings)) / (_settings.fromCents ? 1 : _precision),
|
|
1613
|
-
_settings
|
|
1614
|
-
);
|
|
1615
|
-
}
|
|
1616
|
-
multiply(number) {
|
|
1617
|
-
let { intValue, _settings, _precision } = this;
|
|
1618
|
-
return currency(
|
|
1619
|
-
(intValue *= number) / (_settings.fromCents ? 1 : pow(_precision)),
|
|
1620
|
-
_settings
|
|
1621
|
-
);
|
|
1622
|
-
}
|
|
1623
|
-
divide(number) {
|
|
1624
|
-
let { intValue, _settings } = this;
|
|
1625
|
-
return currency(intValue /= parse(number, _settings, false), _settings);
|
|
1626
|
-
}
|
|
1627
|
-
distribute(count) {
|
|
1628
|
-
let { intValue, _precision, _settings } = this, distribution = [], split = Math[intValue >= 0 ? "floor" : "ceil"](intValue / count), pennies = Math.abs(intValue - split * count), precision = _settings.fromCents ? 1 : _precision;
|
|
1629
|
-
for (; count !== 0; count--) {
|
|
1630
|
-
let item = currency(split / precision, _settings);
|
|
1631
|
-
pennies-- > 0 && (item = item[intValue >= 0 ? "add" : "subtract"](1 / precision));
|
|
1632
|
-
distribution.push(item);
|
|
1633
|
-
}
|
|
1634
|
-
return distribution;
|
|
1635
|
-
}
|
|
1636
|
-
dollars() {
|
|
1637
|
-
return ~~this.value;
|
|
1638
|
-
}
|
|
1639
|
-
cents() {
|
|
1640
|
-
let { intValue, _precision } = this;
|
|
1641
|
-
return ~~(intValue % _precision);
|
|
1642
|
-
}
|
|
1643
|
-
format(options) {
|
|
1644
|
-
let { _settings } = this;
|
|
1645
|
-
if (typeof options === "function") {
|
|
1646
|
-
return options(this, _settings);
|
|
1647
|
-
}
|
|
1648
|
-
return _settings.format(this, Object.assign({}, _settings, options));
|
|
1649
|
-
}
|
|
1650
|
-
toString() {
|
|
1651
|
-
let { intValue, _precision, _settings } = this;
|
|
1652
|
-
return rounding(intValue / _precision, _settings.increment).toFixed(
|
|
1653
|
-
_settings.precision
|
|
1654
|
-
);
|
|
1655
|
-
}
|
|
1656
|
-
toJSON() {
|
|
1657
|
-
return this.value;
|
|
1658
|
-
}
|
|
1659
|
-
static sum(...array) {
|
|
1660
|
-
return arrayFlatten(array).reduce(
|
|
1661
|
-
(acc, value) => currency(acc).add(value),
|
|
1662
|
-
this.zero
|
|
1663
|
-
);
|
|
1664
|
-
}
|
|
1665
|
-
static avg(...array) {
|
|
1666
|
-
let arr = arrayFlatten(array);
|
|
1667
|
-
return arr.reduce((acc, value) => currency(acc).add(value), this.zero).divide(arr.length);
|
|
1668
|
-
}
|
|
1669
|
-
};
|
|
1670
|
-
var Currency = _Currency;
|
|
1671
|
-
__name(Currency, "Currency");
|
|
1672
|
-
Currency.zero = new _Currency(0);
|
|
1673
|
-
Currency.one = new _Currency(1);
|
|
1674
|
-
Currency.hundred = new _Currency(100);
|
|
1675
|
-
function parse(value, opts, useRounding = true) {
|
|
1676
|
-
let v = 0, { decimal: decimal2, errorOnInvalid, precision: decimals, fromCents } = opts, precision = pow(decimals), isNumber2 = typeof value === "number";
|
|
1677
|
-
if (value instanceof Currency && fromCents) {
|
|
1678
|
-
return value.intValue;
|
|
1679
|
-
}
|
|
1680
|
-
if (isNumber2 || value instanceof Currency) {
|
|
1681
|
-
v = value instanceof Currency ? value.value : value;
|
|
1682
|
-
} else if (typeof value === "string") {
|
|
1683
|
-
let regex = new RegExp("[^-\\d" + decimal2 + "]", "g"), decimalString = new RegExp("\\" + decimal2, "g");
|
|
1684
|
-
v = value.replace(/\((.*)\)/, "-$1").replace(regex, "").replace(decimalString, ".");
|
|
1685
|
-
v = v || 0;
|
|
1686
|
-
} else {
|
|
1687
|
-
if (errorOnInvalid) {
|
|
1688
|
-
throw Error("Invalid Input");
|
|
1689
|
-
}
|
|
1690
|
-
v = 0;
|
|
1691
|
-
}
|
|
1692
|
-
if (!fromCents) {
|
|
1693
|
-
v *= precision;
|
|
1694
|
-
v = v.toFixed(4);
|
|
1695
|
-
}
|
|
1696
|
-
return useRounding ? round(v) : v;
|
|
1697
|
-
}
|
|
1698
|
-
__name(parse, "parse");
|
|
1699
|
-
function format(currency2, settings) {
|
|
1700
|
-
let { pattern: pattern2, negativePattern, symbol, separator: separator2, decimal: decimal2, groups } = settings, split = ("" + currency2).replace(/^-/, "").split("."), dollars = split[0], cents = split[1];
|
|
1701
|
-
return (currency2.value >= 0 ? pattern2 : negativePattern).replace("!", symbol).replace(
|
|
1702
|
-
"#",
|
|
1703
|
-
dollars.replace(groups, "$1" + separator2) + (cents ? decimal2 + cents : "")
|
|
1704
|
-
);
|
|
1705
|
-
}
|
|
1706
|
-
__name(format, "format");
|
|
1707
|
-
|
|
1708
|
-
// src/common/data/day.ts
|
|
1709
|
-
var DAY_MS = 864e5;
|
|
1710
|
-
function dayYear(day2) {
|
|
1711
|
-
return Math.floor(day2 / 1e4);
|
|
1712
|
-
}
|
|
1713
|
-
__name(dayYear, "dayYear");
|
|
1714
|
-
function dayMonth(day2) {
|
|
1715
|
-
return Math.floor(day2 / 100 % 100);
|
|
1716
|
-
}
|
|
1717
|
-
__name(dayMonth, "dayMonth");
|
|
1718
|
-
function dayDay(day2) {
|
|
1719
|
-
return Math.floor(day2 % 100);
|
|
1720
|
-
}
|
|
1721
|
-
__name(dayDay, "dayDay");
|
|
1722
|
-
function dayToParts(day2) {
|
|
1723
|
-
return [dayYear(day2), dayMonth(day2), dayDay(day2)];
|
|
1724
|
-
}
|
|
1725
|
-
__name(dayToParts, "dayToParts");
|
|
1726
|
-
function dayToDate(day2, gmt = false) {
|
|
1727
|
-
return gmt ? new Date(`${dayToString(day2)}T00:00:00.000Z`) : new Date(
|
|
1728
|
-
day2 / 1e4,
|
|
1729
|
-
day2 / 100 % 100 - 1,
|
|
1730
|
-
day2 % 100
|
|
1731
|
-
);
|
|
1732
|
-
}
|
|
1733
|
-
__name(dayToDate, "dayToDate");
|
|
1734
|
-
function dayFromToday() {
|
|
1735
|
-
return dayFromDate(new Date());
|
|
1736
|
-
}
|
|
1737
|
-
__name(dayFromToday, "dayFromToday");
|
|
1738
|
-
function dayFromAny(value, gmt = false) {
|
|
1739
|
-
if (typeof value === "number") {
|
|
1740
|
-
if (value < 100)
|
|
1741
|
-
return;
|
|
1742
|
-
return value;
|
|
1743
|
-
} else if (typeof value === "string") {
|
|
1744
|
-
return dayFromString(value);
|
|
1745
|
-
} else if (Array.isArray(value) && value.length === 3) {
|
|
1746
|
-
const [year, month, day2] = value;
|
|
1747
|
-
return dayFromParts(year, month, day2);
|
|
1748
|
-
} else if (value instanceof Date) {
|
|
1749
|
-
return dayFromDate(value, gmt);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
__name(dayFromAny, "dayFromAny");
|
|
1753
|
-
function dayToDateGMT(day2) {
|
|
1754
|
-
return dayToDate(day2, true);
|
|
1755
|
-
}
|
|
1756
|
-
__name(dayToDateGMT, "dayToDateGMT");
|
|
1757
|
-
function dayFromDate(date, gmt = false) {
|
|
1758
|
-
return gmt ? dayFromString(date.toISOString()) : date.getFullYear() * 1e4 + (date.getMonth() + 1) * 100 + date.getDate();
|
|
1759
|
-
}
|
|
1760
|
-
__name(dayFromDate, "dayFromDate");
|
|
1761
|
-
function dayFromDateGMT(date) {
|
|
1762
|
-
return dayFromDate(date, true);
|
|
1763
|
-
}
|
|
1764
|
-
__name(dayFromDateGMT, "dayFromDateGMT");
|
|
1765
|
-
function dayToTimestamp(day2, gmt = true) {
|
|
1766
|
-
return dayToDate(day2, gmt).getTime();
|
|
1767
|
-
}
|
|
1768
|
-
__name(dayToTimestamp, "dayToTimestamp");
|
|
1769
|
-
function dayFromTimestamp(ms, gmt = true) {
|
|
1770
|
-
return dayFromDate(new Date(ms), gmt);
|
|
1771
|
-
}
|
|
1772
|
-
__name(dayFromTimestamp, "dayFromTimestamp");
|
|
1773
|
-
function dayToString(day2, sep = "-") {
|
|
1774
|
-
let baseString = String(day2);
|
|
1775
|
-
return baseString.slice(0, 4) + sep + baseString.slice(4, 6) + sep + baseString.slice(6, 8);
|
|
1776
|
-
}
|
|
1777
|
-
__name(dayToString, "dayToString");
|
|
1778
|
-
function dayFromParts(year, month = 1, day2 = 1) {
|
|
1779
|
-
if (month < 1 || month > 12 || day2 < 1 || day2 > 31)
|
|
1780
|
-
return;
|
|
1781
|
-
return year * 1e4 + month * 100 + day2;
|
|
1782
|
-
}
|
|
1783
|
-
__name(dayFromParts, "dayFromParts");
|
|
1784
|
-
function dayFromString(value) {
|
|
1785
|
-
const string = String(value).replace(/[^0-9]/g, "").slice(0, 8);
|
|
1786
|
-
if (string.length === 8)
|
|
1787
|
-
return +string;
|
|
1788
|
-
}
|
|
1789
|
-
__name(dayFromString, "dayFromString");
|
|
1790
|
-
function dayMonthStart(day2, offset = 0) {
|
|
1791
|
-
let year = dayYear(day2);
|
|
1792
|
-
let month = dayMonth(day2);
|
|
1793
|
-
if (offset !== 0) {
|
|
1794
|
-
month += offset;
|
|
1795
|
-
year += Math.floor((month - 1) / 12);
|
|
1796
|
-
month = Math.floor((month - 1) % 12) + 1;
|
|
1797
|
-
if (month === 0)
|
|
1798
|
-
month = 12;
|
|
1799
|
-
}
|
|
1800
|
-
return dayFromParts(year, month, 1);
|
|
1801
|
-
}
|
|
1802
|
-
__name(dayMonthStart, "dayMonthStart");
|
|
1803
|
-
function dayYearStart(day2, offset = 0) {
|
|
1804
|
-
let year = dayYear(day2);
|
|
1805
|
-
return dayFromParts(year + offset, 1, 1);
|
|
1806
|
-
}
|
|
1807
|
-
__name(dayYearStart, "dayYearStart");
|
|
1808
|
-
function dayOffset(day2, offset) {
|
|
1809
|
-
return dayFromTimestamp(dayToTimestamp(day2) + offset * DAY_MS);
|
|
1810
|
-
}
|
|
1811
|
-
__name(dayOffset, "dayOffset");
|
|
1812
|
-
function dayDiff(left, right) {
|
|
1813
|
-
return Math.round((dayToTimestamp(right) - dayToTimestamp(left)) / DAY_MS);
|
|
1814
|
-
}
|
|
1815
|
-
__name(dayDiff, "dayDiff");
|
|
1816
|
-
|
|
1817
|
-
// src/common/exec/promise.ts
|
|
1818
|
-
var { warn } = Logger("zeed:promise");
|
|
1819
|
-
function createPromise() {
|
|
1820
|
-
let resolve6, reject;
|
|
1821
|
-
let promise = new Promise((_resolve, _reject) => {
|
|
1822
|
-
resolve6 = _resolve;
|
|
1823
|
-
reject = _reject;
|
|
1824
|
-
});
|
|
1825
|
-
return [promise, resolve6, reject];
|
|
1826
|
-
}
|
|
1827
|
-
__name(createPromise, "createPromise");
|
|
1828
|
-
async function sleep(milliSeconds) {
|
|
1829
|
-
return new Promise((resolve6) => setTimeout(resolve6, milliSeconds));
|
|
1830
|
-
}
|
|
1831
|
-
__name(sleep, "sleep");
|
|
1832
|
-
async function immediate() {
|
|
1833
|
-
return new Promise((resolve6) => setTimeout(resolve6, 0));
|
|
1834
|
-
}
|
|
1835
|
-
__name(immediate, "immediate");
|
|
1836
|
-
var timeoutReached = Symbol("timeout");
|
|
1837
|
-
async function timeout(promise, milliSeconds, timeoutValue = timeoutReached) {
|
|
1838
|
-
return new Promise(async (resolve6, reject) => {
|
|
1839
|
-
let done = false;
|
|
1840
|
-
const timeout2 = setTimeout(() => {
|
|
1841
|
-
done = true;
|
|
1842
|
-
resolve6(timeoutValue);
|
|
1843
|
-
}, milliSeconds);
|
|
1844
|
-
try {
|
|
1845
|
-
let result = await promise;
|
|
1846
|
-
clearTimeout(timeout2);
|
|
1847
|
-
if (!done)
|
|
1848
|
-
resolve6(result);
|
|
1849
|
-
} catch (err) {
|
|
1850
|
-
clearTimeout(timeout2);
|
|
1851
|
-
if (!done)
|
|
1852
|
-
reject(err);
|
|
1853
|
-
}
|
|
1854
|
-
});
|
|
1855
|
-
}
|
|
1856
|
-
__name(timeout, "timeout");
|
|
1857
|
-
var timoutError = new Error("Timeout reached");
|
|
1858
|
-
function isTimeout(value) {
|
|
1859
|
-
return value === timeoutReached || value === timoutError;
|
|
1860
|
-
}
|
|
1861
|
-
__name(isTimeout, "isTimeout");
|
|
1862
|
-
async function tryTimeout(promise, milliSeconds) {
|
|
1863
|
-
if (milliSeconds <= 0) {
|
|
1864
|
-
return await promise;
|
|
1865
|
-
}
|
|
1866
|
-
return new Promise(async (resolve6, reject) => {
|
|
1867
|
-
let done = false;
|
|
1868
|
-
const timeout2 = setTimeout(() => {
|
|
1869
|
-
done = true;
|
|
1870
|
-
reject(timoutError);
|
|
1871
|
-
}, milliSeconds);
|
|
1872
|
-
try {
|
|
1873
|
-
let result = await promise;
|
|
1874
|
-
clearTimeout(timeout2);
|
|
1875
|
-
if (!done)
|
|
1876
|
-
resolve6(result);
|
|
1877
|
-
} catch (err) {
|
|
1878
|
-
clearTimeout(timeout2);
|
|
1879
|
-
if (!done)
|
|
1880
|
-
reject(err);
|
|
1881
|
-
}
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
__name(tryTimeout, "tryTimeout");
|
|
1885
|
-
function waitOn(obj, event, timeoutMS = 1e3) {
|
|
1886
|
-
return new Promise((resolve6, reject) => {
|
|
1887
|
-
let fn = /* @__PURE__ */ __name((value) => {
|
|
1888
|
-
if (timer) {
|
|
1889
|
-
clearTimeout(timer);
|
|
1890
|
-
done();
|
|
1891
|
-
resolve6(value);
|
|
1892
|
-
}
|
|
1893
|
-
}, "fn");
|
|
1894
|
-
let done = /* @__PURE__ */ __name(() => {
|
|
1895
|
-
timer = null;
|
|
1896
|
-
if (obj.off) {
|
|
1897
|
-
obj.off(event, fn);
|
|
1898
|
-
} else if (obj.removeEventListener) {
|
|
1899
|
-
obj.removeEventListener(event, fn);
|
|
1900
|
-
} else {
|
|
1901
|
-
warn("No remove listener method found for", obj, event);
|
|
1902
|
-
}
|
|
1903
|
-
}, "done");
|
|
1904
|
-
let timer = setTimeout(() => {
|
|
1905
|
-
done();
|
|
1906
|
-
reject(new Error(`Did not response in time`));
|
|
1907
|
-
}, timeoutMS);
|
|
1908
|
-
if (obj.on) {
|
|
1909
|
-
obj.on(event, fn);
|
|
1910
|
-
} else if (obj.addEventListener) {
|
|
1911
|
-
obj.addEventListener(event, fn);
|
|
1912
|
-
} else {
|
|
1913
|
-
warn("No listener method found for", obj);
|
|
1914
|
-
}
|
|
1915
|
-
});
|
|
1916
|
-
}
|
|
1917
|
-
__name(waitOn, "waitOn");
|
|
1918
|
-
function isPromise(value) {
|
|
1919
|
-
return Boolean(
|
|
1920
|
-
value && (value instanceof Promise || typeof value.then === "function")
|
|
1921
|
-
);
|
|
1922
|
-
}
|
|
1923
|
-
__name(isPromise, "isPromise");
|
|
1924
|
-
function promisify(value) {
|
|
1925
|
-
return Promise.resolve(value);
|
|
1926
|
-
}
|
|
1927
|
-
__name(promisify, "promisify");
|
|
1928
|
-
|
|
1929
|
-
// src/common/data/day-legacy.ts
|
|
1930
|
-
var Day = class {
|
|
1931
|
-
get value() {
|
|
1932
|
-
return this.days;
|
|
1933
|
-
}
|
|
1934
|
-
constructor(days) {
|
|
1935
|
-
var _a2;
|
|
1936
|
-
if (typeof days === "number") {
|
|
1937
|
-
this.days = days;
|
|
1938
|
-
return;
|
|
1939
|
-
}
|
|
1940
|
-
if (days != null) {
|
|
1941
|
-
days = (_a2 = Day.from(days)) == null ? void 0 : _a2.days;
|
|
1942
|
-
}
|
|
1943
|
-
if (days == null) {
|
|
1944
|
-
const date = new Date();
|
|
1945
|
-
this.days = date.getFullYear() * 1e4 + (date.getMonth() + 1) * 100 + date.getDate();
|
|
1946
|
-
} else {
|
|
1947
|
-
this.days = days;
|
|
1948
|
-
}
|
|
1949
|
-
}
|
|
1950
|
-
static fromNumber(n) {
|
|
1951
|
-
return new Day(n);
|
|
1952
|
-
}
|
|
1953
|
-
static fromString(dateString) {
|
|
1954
|
-
return Day.from(+dateString.replace(/[^0-9]/g, "").slice(0, 8));
|
|
1955
|
-
}
|
|
1956
|
-
static fromDate(date, gmt = false) {
|
|
1957
|
-
return gmt ? Day.fromString(date.toISOString().substr(0, 10)) : Day.from(
|
|
1958
|
-
date.getFullYear() * 1e4 + (date.getMonth() + 1) * 100 + date.getDate()
|
|
1959
|
-
);
|
|
1960
|
-
}
|
|
1961
|
-
static fromDateGMT(date) {
|
|
1962
|
-
return Day.fromDate(date, true);
|
|
1963
|
-
}
|
|
1964
|
-
static from(value, gmt = false) {
|
|
1965
|
-
if (typeof value === "number") {
|
|
1966
|
-
if (value < 100)
|
|
1967
|
-
return;
|
|
1968
|
-
return new Day(value);
|
|
1969
|
-
} else if (typeof value === "string") {
|
|
1970
|
-
return Day.fromString(value);
|
|
1971
|
-
} else if (Array.isArray(value) && value.length === 3) {
|
|
1972
|
-
const [year, month = 1, day2 = 1] = value;
|
|
1973
|
-
if (month < 1 || month > 12 || day2 < 1 || day2 > 31)
|
|
1974
|
-
return;
|
|
1975
|
-
return new Day(year * 1e4 + month * 100 + day2);
|
|
1976
|
-
} else if (value instanceof Date) {
|
|
1977
|
-
return Day.fromDate(value, gmt);
|
|
1978
|
-
} else if (value instanceof Day) {
|
|
1979
|
-
return value;
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
toNumber() {
|
|
1983
|
-
return this.days;
|
|
1984
|
-
}
|
|
1985
|
-
toJson() {
|
|
1986
|
-
return this.days;
|
|
1987
|
-
}
|
|
1988
|
-
toString(sep = "-") {
|
|
1989
|
-
let baseString = String(this.days);
|
|
1990
|
-
return baseString.slice(0, 4) + sep + baseString.slice(4, 6) + sep + baseString.slice(6, 8);
|
|
1991
|
-
}
|
|
1992
|
-
toDate(gmt = false) {
|
|
1993
|
-
return gmt ? new Date(`${this.toString()}T00:00:00.000Z`) : new Date(
|
|
1994
|
-
this.days / 1e4,
|
|
1995
|
-
this.days / 100 % 100 - 1,
|
|
1996
|
-
this.days % 100
|
|
1997
|
-
);
|
|
1998
|
-
}
|
|
1999
|
-
toDateGMT() {
|
|
2000
|
-
return this.toDate(true);
|
|
2001
|
-
}
|
|
2002
|
-
get year() {
|
|
2003
|
-
return Math.floor(this.days / 1e4);
|
|
2004
|
-
}
|
|
2005
|
-
get month() {
|
|
2006
|
-
return Math.floor(this.days / 100 % 100);
|
|
2007
|
-
}
|
|
2008
|
-
get day() {
|
|
2009
|
-
return Math.floor(this.days % 100);
|
|
2010
|
-
}
|
|
2011
|
-
dayOffset(offset) {
|
|
2012
|
-
return Day.fromDateGMT(
|
|
2013
|
-
new Date(this.toDateGMT().getTime() + offset * DAY_MS)
|
|
2014
|
-
);
|
|
2015
|
-
}
|
|
2016
|
-
monthStart() {
|
|
2017
|
-
return Day.from([this.year, this.month, 1]);
|
|
2018
|
-
}
|
|
2019
|
-
yearStart() {
|
|
2020
|
-
return Day.from([this.year, 1, 1]);
|
|
2021
|
-
}
|
|
2022
|
-
monthOffset(offset) {
|
|
2023
|
-
let m = this.month + offset;
|
|
2024
|
-
let mm = Math.floor((m - 1) % 12) + 1;
|
|
2025
|
-
if (mm === 0)
|
|
2026
|
-
mm = 12;
|
|
2027
|
-
let yy = Math.floor((m - 1) / 12);
|
|
2028
|
-
return Day.from([this.year + yy, mm, this.day]);
|
|
2029
|
-
}
|
|
2030
|
-
daysUntil(otherDay) {
|
|
2031
|
-
var _a2;
|
|
2032
|
-
return Math.round(
|
|
2033
|
-
(((_a2 = new Day(otherDay)) == null ? void 0 : _a2.toDateGMT().getTime()) - this.toDateGMT().getTime()) / DAY_MS
|
|
2034
|
-
);
|
|
2035
|
-
}
|
|
2036
|
-
yesterday() {
|
|
2037
|
-
return this.dayOffset(-1);
|
|
2038
|
-
}
|
|
2039
|
-
tomorrow() {
|
|
2040
|
-
return this.dayOffset(1);
|
|
2041
|
-
}
|
|
2042
|
-
};
|
|
2043
|
-
__name(Day, "Day");
|
|
2044
|
-
async function forEachDay(from, to, handler) {
|
|
2045
|
-
let start = Day.from(from);
|
|
2046
|
-
let end = Day.from(to);
|
|
2047
|
-
while (start && end && (start == null ? void 0 : start.days) <= (end == null ? void 0 : end.days)) {
|
|
2048
|
-
let result = handler(start);
|
|
2049
|
-
if (isPromise(result)) {
|
|
2050
|
-
await result;
|
|
2051
|
-
}
|
|
2052
|
-
start = start.dayOffset(1);
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
__name(forEachDay, "forEachDay");
|
|
2056
|
-
function today() {
|
|
2057
|
-
return new Day();
|
|
2058
|
-
}
|
|
2059
|
-
__name(today, "today");
|
|
2060
|
-
function day(days) {
|
|
2061
|
-
return new Day(days);
|
|
2062
|
-
}
|
|
2063
|
-
__name(day, "day");
|
|
2064
|
-
function dateStringToDays(dateString) {
|
|
2065
|
-
return Day.fromDate(new Date(dateString)).days;
|
|
2066
|
-
}
|
|
2067
|
-
__name(dateStringToDays, "dateStringToDays");
|
|
2068
|
-
|
|
2069
|
-
// src/common/data/decimal.ts
|
|
2070
|
-
function decimal(value, decimalPlaces = 2) {
|
|
2071
|
-
return +(+value).toFixed(decimalPlaces);
|
|
2072
|
-
}
|
|
2073
|
-
__name(decimal, "decimal");
|
|
2074
|
-
function decimalFromCents(value, decimalPlaces = 2) {
|
|
2075
|
-
return +(+value / Math.pow(10, decimalPlaces)).toFixed(decimalPlaces);
|
|
2076
|
-
}
|
|
2077
|
-
__name(decimalFromCents, "decimalFromCents");
|
|
2078
|
-
function decimalToCents(value, decimalPlaces = 2) {
|
|
2079
|
-
return Math.round(+value * Math.pow(10, decimalPlaces));
|
|
2080
|
-
}
|
|
2081
|
-
__name(decimalToCents, "decimalToCents");
|
|
2082
|
-
function decimalCentsPart(value, decimalPlaces = 2) {
|
|
2083
|
-
return decimalPlaces * (decimal(value, decimalPlaces) % 1);
|
|
2084
|
-
}
|
|
2085
|
-
__name(decimalCentsPart, "decimalCentsPart");
|
|
2086
|
-
|
|
2087
|
-
// src/common/data/html.ts
|
|
2088
|
-
var escapeHTML = /* @__PURE__ */ __name((s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'").replace(/"/g, """), "escapeHTML");
|
|
2089
|
-
var unescapeHTML = /* @__PURE__ */ __name((s) => s.replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, '"').replace(/'/gi, "'").replace(/&/gi, "&"), "unescapeHTML");
|
|
2090
|
-
|
|
2091
|
-
// src/common/data/path.ts
|
|
2092
|
-
var MAX_FILENAME_LENGTH = 100;
|
|
2093
|
-
var reControlChars = /[\u0000-\u001F\u0080-\u009F]/g;
|
|
2094
|
-
var reRelativePath = /^\.+/;
|
|
2095
|
-
var reTrailingPeriods = /\.+$/;
|
|
2096
|
-
function filenameReservedRegex() {
|
|
2097
|
-
return /[<>:"/\\|?*\u0000-\u001F]/g;
|
|
2098
|
-
}
|
|
2099
|
-
__name(filenameReservedRegex, "filenameReservedRegex");
|
|
2100
|
-
function windowsReservedNameRegex() {
|
|
2101
|
-
return /^(con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
2102
|
-
}
|
|
2103
|
-
__name(windowsReservedNameRegex, "windowsReservedNameRegex");
|
|
2104
|
-
function toValidFilename(string) {
|
|
2105
|
-
if (typeof string !== "string") {
|
|
2106
|
-
throw new TypeError("Expected a string");
|
|
2107
|
-
}
|
|
2108
|
-
const replacement = "_";
|
|
2109
|
-
if (filenameReservedRegex().test(replacement) && reControlChars.test(replacement)) {
|
|
2110
|
-
throw new Error(
|
|
2111
|
-
"Replacement string cannot contain reserved filename characters"
|
|
2112
|
-
);
|
|
2113
|
-
}
|
|
2114
|
-
string = string.replace(filenameReservedRegex(), replacement).replace(reControlChars, replacement).replace(reRelativePath, replacement).replace(reTrailingPeriods, "");
|
|
2115
|
-
string = windowsReservedNameRegex().test(string) ? string + replacement : string;
|
|
2116
|
-
return string.slice(0, MAX_FILENAME_LENGTH);
|
|
2117
|
-
}
|
|
2118
|
-
__name(toValidFilename, "toValidFilename");
|
|
2119
|
-
|
|
2120
|
-
// src/common/data/regexp.ts
|
|
2121
|
-
var rxEscape = /[\\\-\[\]\/{}()*+?.^$|]/g;
|
|
2122
|
-
function escapeRegExp(value) {
|
|
2123
|
-
if (!value)
|
|
2124
|
-
return "";
|
|
2125
|
-
if (value instanceof RegExp) {
|
|
2126
|
-
return value.source;
|
|
2127
|
-
}
|
|
2128
|
-
return value.replace(rxEscape, "\\$&");
|
|
2129
|
-
}
|
|
2130
|
-
__name(escapeRegExp, "escapeRegExp");
|
|
2131
|
-
|
|
2132
|
-
// src/common/data/rounding.ts
|
|
2133
|
-
var isHalf = /* @__PURE__ */ __name((value) => Math.abs(value) % 1 === 0.5, "isHalf");
|
|
2134
|
-
var isEven = /* @__PURE__ */ __name((value) => value % 2 === 0, "isEven");
|
|
2135
|
-
var roundUp = /* @__PURE__ */ __name((value) => Math.ceil(value), "roundUp");
|
|
2136
|
-
var roundDown = /* @__PURE__ */ __name((value) => Math.floor(value), "roundDown");
|
|
2137
|
-
var roundHalfUp = /* @__PURE__ */ __name((value) => Math.round(value), "roundHalfUp");
|
|
2138
|
-
var roundHalfOdd = /* @__PURE__ */ __name((value) => {
|
|
2139
|
-
const rounded = Math.round(value);
|
|
2140
|
-
if (!isHalf(value)) {
|
|
2141
|
-
return rounded;
|
|
2142
|
-
}
|
|
2143
|
-
return isEven(rounded) ? rounded - 1 : rounded;
|
|
2144
|
-
}, "roundHalfOdd");
|
|
2145
|
-
var roundHalfAwayFromZero = /* @__PURE__ */ __name((value) => {
|
|
2146
|
-
return isHalf(value) ? Math.sign(value) * Math.ceil(Math.abs(value)) : Math.round(value);
|
|
2147
|
-
}, "roundHalfAwayFromZero");
|
|
2148
|
-
var roundHalfDown = /* @__PURE__ */ __name((value) => isHalf(value) ? Math.floor(value) : Math.round(value), "roundHalfDown");
|
|
2149
|
-
var roundHalfEven = /* @__PURE__ */ __name((value) => {
|
|
2150
|
-
const rounded = Math.round(value);
|
|
2151
|
-
if (!isHalf(value)) {
|
|
2152
|
-
return rounded;
|
|
2153
|
-
}
|
|
2154
|
-
return isEven(rounded) ? rounded : rounded - 1;
|
|
2155
|
-
}, "roundHalfEven");
|
|
2156
|
-
var roundHalfTowardsZero = /* @__PURE__ */ __name((value) => isHalf(value) ? Math.sign(value) * Math.floor(Math.abs(value)) : Math.round(value), "roundHalfTowardsZero");
|
|
2157
|
-
|
|
2158
|
-
// src/common/data/sortable.ts
|
|
2159
|
-
function startSortWeight(items) {
|
|
2160
|
-
return items.reduce((acc, item) => Math.min(acc, item.sort_weight || 0), 0) - 1 - getSecureRandomIfPossible();
|
|
2161
|
-
}
|
|
2162
|
-
__name(startSortWeight, "startSortWeight");
|
|
2163
|
-
function endSortWeight(items) {
|
|
2164
|
-
return items.reduce((acc, item) => Math.max(acc, item.sort_weight || 0), 0) + 1 + getSecureRandomIfPossible();
|
|
2165
|
-
}
|
|
2166
|
-
__name(endSortWeight, "endSortWeight");
|
|
2167
|
-
function moveSortWeight(newIndex, oldIndex, items) {
|
|
2168
|
-
let count = items.length;
|
|
2169
|
-
const moveLower = newIndex < oldIndex;
|
|
2170
|
-
if (count <= 0 || newIndex >= count - 1) {
|
|
2171
|
-
return endSortWeight(items);
|
|
2172
|
-
}
|
|
2173
|
-
if (newIndex <= 0) {
|
|
2174
|
-
return startSortWeight(items);
|
|
2175
|
-
}
|
|
2176
|
-
items = sortedItems([...items]);
|
|
2177
|
-
const step = moveLower ? -1 : 0;
|
|
2178
|
-
const lower = items[newIndex + step].sort_weight || 0;
|
|
2179
|
-
const upper = items[newIndex + step + 1].sort_weight || 0;
|
|
2180
|
-
const distance = upper - lower;
|
|
2181
|
-
if (distance === 0) {
|
|
2182
|
-
if (moveLower) {
|
|
2183
|
-
return startSortWeight(items);
|
|
2184
|
-
}
|
|
2185
|
-
return endSortWeight(items);
|
|
2186
|
-
}
|
|
2187
|
-
const middle = lower + distance / 2;
|
|
2188
|
-
const fuzzy = distance * 0.01 * (getSecureRandomIfPossible() - 0.5);
|
|
2189
|
-
return middle + fuzzy;
|
|
2190
|
-
}
|
|
2191
|
-
__name(moveSortWeight, "moveSortWeight");
|
|
2192
|
-
function sortedItems(items) {
|
|
2193
|
-
items.sort((a, b) => (a.sort_weight || 0) - (b.sort_weight || 0));
|
|
2194
|
-
return items;
|
|
2195
|
-
}
|
|
2196
|
-
__name(sortedItems, "sortedItems");
|
|
2197
|
-
|
|
2198
|
-
// src/common/data/url.ts
|
|
2199
|
-
var findURL = /((?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?)/gim;
|
|
2200
|
-
function linkifyPlainText(text) {
|
|
2201
|
-
return text.split(findURL).map((part, i) => {
|
|
2202
|
-
const escapedPart = escapeHTML(part);
|
|
2203
|
-
return i % 2 ? `<a target="_blank" href="${escapedPart}">${toHumanReadableUrl(
|
|
2204
|
-
escapedPart
|
|
2205
|
-
)}</a>` : escapedPart;
|
|
2206
|
-
}).join("");
|
|
2207
|
-
}
|
|
2208
|
-
__name(linkifyPlainText, "linkifyPlainText");
|
|
2209
|
-
function toHumanReadableUrl(url) {
|
|
2210
|
-
return url.replace(/^https?:\/\/(www\.)?/, "").replace(/\/$/, "");
|
|
2211
|
-
}
|
|
2212
|
-
__name(toHumanReadableUrl, "toHumanReadableUrl");
|
|
2213
|
-
function encodeQuery(data) {
|
|
2214
|
-
let pairs = [];
|
|
2215
|
-
for (let [key, value] of Object.entries(data)) {
|
|
2216
|
-
if (value != null) {
|
|
2217
|
-
if (!Array.isArray(value)) {
|
|
2218
|
-
value = [value];
|
|
2219
|
-
}
|
|
2220
|
-
for (let v of value) {
|
|
2221
|
-
if (v != null) {
|
|
2222
|
-
pairs.push(
|
|
2223
|
-
encodeURIComponent(key) + "=" + encodeURIComponent(String(v))
|
|
2224
|
-
);
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
return pairs.join("&");
|
|
2230
|
-
}
|
|
2231
|
-
__name(encodeQuery, "encodeQuery");
|
|
2232
|
-
function parseQuery(queryString) {
|
|
2233
|
-
let query = {};
|
|
2234
|
-
let pairs = (queryString[0] === "?" ? queryString.substr(1) : queryString).split("&");
|
|
2235
|
-
for (let i = 0; i < pairs.length; i++) {
|
|
2236
|
-
let pair = pairs[i].split("=");
|
|
2237
|
-
let key = decodeURIComponent(pair[0]);
|
|
2238
|
-
let value = decodeURIComponent(pair[1] || "");
|
|
2239
|
-
if (query[key] != null) {
|
|
2240
|
-
if (!Array.isArray(query[key])) {
|
|
2241
|
-
query[key] = [query[key]];
|
|
2242
|
-
}
|
|
2243
|
-
query[key].push(value);
|
|
2244
|
-
} else {
|
|
2245
|
-
query[key] = value;
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
return query;
|
|
2249
|
-
}
|
|
2250
|
-
__name(parseQuery, "parseQuery");
|
|
2251
|
-
|
|
2252
|
-
// src/common/data/utils.ts
|
|
2253
|
-
function ensureKey(obj, key, createFn) {
|
|
2254
|
-
let value = obj[key];
|
|
2255
|
-
if (value === void 0) {
|
|
2256
|
-
value = createFn(key, obj);
|
|
2257
|
-
obj[key] = value;
|
|
2258
|
-
}
|
|
2259
|
-
return value;
|
|
2260
|
-
}
|
|
2261
|
-
__name(ensureKey, "ensureKey");
|
|
2262
|
-
async function ensureKeyAsync(obj, key, createFn) {
|
|
2263
|
-
let value = obj[key];
|
|
2264
|
-
if (value === void 0) {
|
|
2265
|
-
value = await createFn(key, obj);
|
|
2266
|
-
obj[key] = value;
|
|
2267
|
-
}
|
|
2268
|
-
return value;
|
|
2269
|
-
}
|
|
2270
|
-
__name(ensureKeyAsync, "ensureKeyAsync");
|
|
2271
|
-
function size(obj) {
|
|
2272
|
-
if (obj != null) {
|
|
2273
|
-
if (obj.size != null) {
|
|
2274
|
-
return obj.size;
|
|
2275
|
-
}
|
|
2276
|
-
if (obj.length != null) {
|
|
2277
|
-
return obj.length;
|
|
2278
|
-
}
|
|
2279
|
-
return Object.keys(obj).length;
|
|
2280
|
-
}
|
|
2281
|
-
return 0;
|
|
2282
|
-
}
|
|
2283
|
-
__name(size, "size");
|
|
2284
|
-
function last(array) {
|
|
2285
|
-
return array != null && array.length > 0 ? array[array.length - 1] : void 0;
|
|
2286
|
-
}
|
|
2287
|
-
__name(last, "last");
|
|
2288
|
-
function empty(value) {
|
|
2289
|
-
try {
|
|
2290
|
-
if (value != null) {
|
|
2291
|
-
if (Array.isArray(value)) {
|
|
2292
|
-
return value.length <= 0;
|
|
2293
|
-
} else if (typeof value === "string") {
|
|
2294
|
-
return value.length <= 0;
|
|
2295
|
-
} else if ((value == null ? void 0 : value.size) != null) {
|
|
2296
|
-
return value.size <= 0;
|
|
2297
|
-
} else {
|
|
2298
|
-
return Object.keys(value).length <= 0;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
} catch (err) {
|
|
2302
|
-
console.warn("Failed to check if empty for", value, err);
|
|
2303
|
-
}
|
|
2304
|
-
return true;
|
|
2305
|
-
}
|
|
2306
|
-
__name(empty, "empty");
|
|
2307
|
-
function cloneObject(obj) {
|
|
2308
|
-
if (Object(obj) !== obj)
|
|
2309
|
-
return obj;
|
|
2310
|
-
return JSON.parse(JSON.stringify(obj));
|
|
2311
|
-
}
|
|
2312
|
-
__name(cloneObject, "cloneObject");
|
|
2313
|
-
function cloneJsonObject(obj) {
|
|
2314
|
-
if (Object(obj) !== obj)
|
|
2315
|
-
return obj;
|
|
2316
|
-
return JSON.parse(JSON.stringify(obj));
|
|
2317
|
-
}
|
|
2318
|
-
__name(cloneJsonObject, "cloneJsonObject");
|
|
2319
|
-
function memoize(fn) {
|
|
2320
|
-
let cache = /* @__PURE__ */ new Map();
|
|
2321
|
-
return (n) => {
|
|
2322
|
-
if (cache.has(n)) {
|
|
2323
|
-
return cache.get(n);
|
|
2324
|
-
}
|
|
2325
|
-
let result = fn(n);
|
|
2326
|
-
cache.set(n, result);
|
|
2327
|
-
return result;
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
__name(memoize, "memoize");
|
|
2331
|
-
function forTimes(count, fn) {
|
|
2332
|
-
let result = [];
|
|
2333
|
-
for (let i = 0; i < count; i++) {
|
|
2334
|
-
result.push(fn(i, count));
|
|
2335
|
-
}
|
|
2336
|
-
return result;
|
|
2337
|
-
}
|
|
2338
|
-
__name(forTimes, "forTimes");
|
|
2339
|
-
|
|
2340
|
-
// src/common/data/xrx.ts
|
|
2341
|
-
var RX_WHITESPACE = /\\\s|\s+|#[^\n]*\n?/gm;
|
|
2342
|
-
var RX_REAL_GROUPS = /\(\?P?<(\w[\w\d_]+)>|\((?!\?(:|\!|=|<=|<\!))/gm;
|
|
2343
|
-
var RX_LOOK_BEHIND = /^((?:\(\?[\w$]+\))?)\(\?<([=!])([\s\S]*?)\)/gm;
|
|
2344
|
-
var log3 = Logger("xrx");
|
|
2345
|
-
function regExpString(rx) {
|
|
2346
|
-
return typeof rx === "string" ? rx : rx.source || "";
|
|
2347
|
-
}
|
|
2348
|
-
__name(regExpString, "regExpString");
|
|
2349
|
-
function regExpEscape(str) {
|
|
2350
|
-
return str.replace(/[-\[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
2351
|
-
}
|
|
2352
|
-
__name(regExpEscape, "regExpEscape");
|
|
2353
|
-
var XRX = class {
|
|
2354
|
-
constructor(pattern2, flags) {
|
|
2355
|
-
this.namedGroups = {};
|
|
2356
|
-
this.names = [];
|
|
2357
|
-
let _flags = flags ?? "";
|
|
2358
|
-
let _rx;
|
|
2359
|
-
if (pattern2 instanceof RegExp) {
|
|
2360
|
-
if (flags == null) {
|
|
2361
|
-
_flags = pattern2.flags;
|
|
2362
|
-
}
|
|
2363
|
-
_rx = pattern2.source;
|
|
2364
|
-
} else {
|
|
2365
|
-
_rx = pattern2;
|
|
2366
|
-
}
|
|
2367
|
-
const extended = _flags && _flags.indexOf("x") !== -1;
|
|
2368
|
-
if (extended) {
|
|
2369
|
-
_flags = _flags.replace("x", "");
|
|
2370
|
-
_rx = _rx.replace(RX_WHITESPACE, (r) => {
|
|
2371
|
-
return r[0] === "\\" ? r : "";
|
|
2372
|
-
});
|
|
2373
|
-
}
|
|
2374
|
-
if (!(pattern2 instanceof RegExp)) {
|
|
2375
|
-
let index = 0;
|
|
2376
|
-
_rx = _rx.replace(RX_REAL_GROUPS, (str, name) => {
|
|
2377
|
-
index += 1;
|
|
2378
|
-
if (name) {
|
|
2379
|
-
if (name !== "index" && name !== "length" && !this.namedGroups[name]) {
|
|
2380
|
-
this.namedGroups[name] = index;
|
|
2381
|
-
} else {
|
|
2382
|
-
log3.error(`Unallowed or duplicate group name: ${name}`);
|
|
2383
|
-
}
|
|
2384
|
-
return "(";
|
|
2385
|
-
}
|
|
2386
|
-
return str;
|
|
2387
|
-
});
|
|
2388
|
-
this.names = Object.keys(this.namedGroups);
|
|
2389
|
-
}
|
|
2390
|
-
_rx = regExpString(_rx);
|
|
2391
|
-
RX_LOOK_BEHIND.lastIndex = 0;
|
|
2392
|
-
let parts = RX_LOOK_BEHIND.exec(_rx);
|
|
2393
|
-
if (parts) {
|
|
2394
|
-
this.lookBehind = {
|
|
2395
|
-
rx: new RegExp(`${parts[3]}$(?!\\s)`),
|
|
2396
|
-
expect: parts ? parts[2] === "=" : !parts
|
|
2397
|
-
};
|
|
2398
|
-
_rx = _rx.substr(parts[0].length);
|
|
2399
|
-
}
|
|
2400
|
-
this.rx = new RegExp(_rx, _flags);
|
|
2401
|
-
}
|
|
2402
|
-
get lastIndex() {
|
|
2403
|
-
return this.rx.lastIndex;
|
|
2404
|
-
}
|
|
2405
|
-
set lastIndex(index) {
|
|
2406
|
-
this.rx.lastIndex = index;
|
|
2407
|
-
}
|
|
2408
|
-
_handleMatch(m) {
|
|
2409
|
-
if (this.lookBehind) {
|
|
2410
|
-
let leftContext = m.input.slice(0, m.index);
|
|
2411
|
-
if (this.lookBehind.expect !== this.lookBehind.rx.test(leftContext)) {
|
|
2412
|
-
return null;
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
for (let name of this.names) {
|
|
2416
|
-
m[name] = m[this.namedGroups[name]];
|
|
2417
|
-
}
|
|
2418
|
-
return m;
|
|
2419
|
-
}
|
|
2420
|
-
exec(str) {
|
|
2421
|
-
let m;
|
|
2422
|
-
while (m = this.rx.exec(str)) {
|
|
2423
|
-
if (this.rx.lastIndex === m.index) {
|
|
2424
|
-
this.rx.lastIndex++;
|
|
2425
|
-
}
|
|
2426
|
-
m = this._handleMatch(m);
|
|
2427
|
-
if (m != null) {
|
|
2428
|
-
return m;
|
|
2429
|
-
}
|
|
2430
|
-
}
|
|
2431
|
-
}
|
|
2432
|
-
execAll(str) {
|
|
2433
|
-
let matches = [];
|
|
2434
|
-
let m;
|
|
2435
|
-
this.rx.lastIndex = 0;
|
|
2436
|
-
while (m = this.exec(str)) {
|
|
2437
|
-
matches.push(m);
|
|
2438
|
-
}
|
|
2439
|
-
this.rx.lastIndex = 0;
|
|
2440
|
-
return matches;
|
|
2441
|
-
}
|
|
2442
|
-
replace(str, replacement) {
|
|
2443
|
-
let fn = typeof replacement === "function" ? replacement : () => replacement;
|
|
2444
|
-
return str.replace(this.rx, (m) => {
|
|
2445
|
-
return fn(m);
|
|
2446
|
-
});
|
|
2447
|
-
}
|
|
2448
|
-
};
|
|
2449
|
-
__name(XRX, "XRX");
|
|
2450
|
-
|
|
2451
|
-
// src/common/dispose-defer.ts
|
|
2452
|
-
var log4 = Logger("dispose");
|
|
2453
|
-
async function callDisposer(disposable) {
|
|
2454
|
-
if (typeof disposable === "function") {
|
|
2455
|
-
await promisify(disposable());
|
|
2456
|
-
} else if (isPromise(disposable)) {
|
|
2457
|
-
await disposable;
|
|
2458
|
-
} else if (typeof disposable.dispose === "function") {
|
|
2459
|
-
await promisify(disposable.dispose());
|
|
2460
|
-
} else if (isPromise(disposable.dispose)) {
|
|
2461
|
-
await disposable.dispose;
|
|
2462
|
-
} else if (typeof disposable.cleanup === "function") {
|
|
2463
|
-
await promisify(disposable.cleanup());
|
|
2464
|
-
} else if (isPromise(disposable.cleanup)) {
|
|
2465
|
-
await disposable.cleanup;
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
__name(callDisposer, "callDisposer");
|
|
2469
|
-
function useDispose(config) {
|
|
2470
|
-
const { name } = typeof config === "string" ? { name: config } : config ?? {};
|
|
2471
|
-
let tracked = [];
|
|
2472
|
-
const untrack = /* @__PURE__ */ __name(async (disposable) => {
|
|
2473
|
-
if (disposable != null && tracked.includes(disposable)) {
|
|
2474
|
-
arrayFilterInPlace(tracked, (el) => el !== disposable);
|
|
2475
|
-
await callDisposer(disposable);
|
|
2476
|
-
}
|
|
2477
|
-
}, "untrack");
|
|
2478
|
-
const dispose = /* @__PURE__ */ __name(async () => {
|
|
2479
|
-
if (name)
|
|
2480
|
-
log4.debug(`dispose ${name}: ${tracked.length} entries`);
|
|
2481
|
-
while (tracked.length > 0) {
|
|
2482
|
-
await untrack(tracked[0]);
|
|
2483
|
-
}
|
|
2484
|
-
}, "dispose");
|
|
2485
|
-
const track = /* @__PURE__ */ __name((obj) => {
|
|
2486
|
-
if (obj == null)
|
|
2487
|
-
return;
|
|
2488
|
-
tracked.unshift(obj);
|
|
2489
|
-
return () => untrack(obj);
|
|
2490
|
-
}, "track");
|
|
2491
|
-
return Object.assign(dispose, {
|
|
2492
|
-
track,
|
|
2493
|
-
add: track,
|
|
2494
|
-
untrack,
|
|
2495
|
-
dispose,
|
|
2496
|
-
exec: dispose,
|
|
2497
|
-
getSize() {
|
|
2498
|
-
return tracked.length;
|
|
2499
|
-
}
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
__name(useDispose, "useDispose");
|
|
2503
|
-
var useDisposer = useDispose;
|
|
2504
|
-
function useDefer(config = {}) {
|
|
2505
|
-
const { mode = "fifo" } = config;
|
|
2506
|
-
let steps = [];
|
|
2507
|
-
const exec = /* @__PURE__ */ __name(async (expectSync = false) => {
|
|
2508
|
-
while (steps.length > 0) {
|
|
2509
|
-
let step = steps[0];
|
|
2510
|
-
arrayFilterInPlace(steps, (el) => el !== step);
|
|
2511
|
-
if (typeof step === "function") {
|
|
2512
|
-
let result = step();
|
|
2513
|
-
if (isPromise(result)) {
|
|
2514
|
-
if (expectSync)
|
|
2515
|
-
throw new Error(
|
|
2516
|
-
`Expected sync only function, but found async: ${step}`
|
|
2517
|
-
);
|
|
2518
|
-
await result;
|
|
2519
|
-
}
|
|
2520
|
-
} else if (isPromise(step)) {
|
|
2521
|
-
if (expectSync)
|
|
2522
|
-
throw new Error(
|
|
2523
|
-
`Expected sync only function, but found async: ${step}`
|
|
2524
|
-
);
|
|
2525
|
-
await step;
|
|
2526
|
-
} else {
|
|
2527
|
-
throw new Error(`Unhandled disposable: ${step}`);
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
}, "exec");
|
|
2531
|
-
const add = /* @__PURE__ */ __name((obj) => {
|
|
2532
|
-
if (mode === "lifo") {
|
|
2533
|
-
steps.unshift(obj);
|
|
2534
|
-
} else {
|
|
2535
|
-
steps.push(obj);
|
|
2536
|
-
}
|
|
2537
|
-
}, "add");
|
|
2538
|
-
return Object.assign(exec, {
|
|
2539
|
-
add,
|
|
2540
|
-
exec,
|
|
2541
|
-
getSize() {
|
|
2542
|
-
return steps.length;
|
|
2543
|
-
}
|
|
2544
|
-
});
|
|
2545
|
-
}
|
|
2546
|
-
__name(useDefer, "useDefer");
|
|
2547
|
-
function useTimeout(fn, timeout2 = 0) {
|
|
2548
|
-
let timeoutHandle = setTimeout(fn, timeout2);
|
|
2549
|
-
return () => {
|
|
2550
|
-
if (timeoutHandle) {
|
|
2551
|
-
clearTimeout(timeoutHandle);
|
|
2552
|
-
timeoutHandle = void 0;
|
|
2553
|
-
}
|
|
2554
|
-
};
|
|
2555
|
-
}
|
|
2556
|
-
__name(useTimeout, "useTimeout");
|
|
2557
|
-
function useInterval(fn, interval) {
|
|
2558
|
-
let intervalHandle = setInterval(fn, interval);
|
|
2559
|
-
return () => {
|
|
2560
|
-
if (intervalHandle) {
|
|
2561
|
-
clearInterval(intervalHandle);
|
|
2562
|
-
intervalHandle = void 0;
|
|
2563
|
-
}
|
|
2564
|
-
};
|
|
2565
|
-
}
|
|
2566
|
-
__name(useInterval, "useInterval");
|
|
2567
|
-
function useEventListener(emitter, eventName, fn, ...args) {
|
|
2568
|
-
if (emitter == null)
|
|
2569
|
-
return () => {
|
|
2570
|
-
};
|
|
2571
|
-
if (emitter.on) {
|
|
2572
|
-
emitter.on(eventName, fn, ...args);
|
|
2573
|
-
} else if (emitter.addEventListener) {
|
|
2574
|
-
emitter.addEventListener(eventName, fn, ...args);
|
|
2575
|
-
}
|
|
2576
|
-
return () => {
|
|
2577
|
-
if (emitter.off) {
|
|
2578
|
-
emitter.off(eventName, fn, ...args);
|
|
2579
|
-
} else if (emitter.removeEventListener) {
|
|
2580
|
-
emitter.removeEventListener(eventName, fn, ...args);
|
|
2581
|
-
}
|
|
2582
|
-
};
|
|
2583
|
-
}
|
|
2584
|
-
__name(useEventListener, "useEventListener");
|
|
2585
|
-
|
|
2586
|
-
// src/common/exec/mutex.ts
|
|
2587
|
-
function useMutex() {
|
|
2588
|
-
let token = true;
|
|
2589
|
-
return (fn, elseFn) => {
|
|
2590
|
-
let executed = false;
|
|
2591
|
-
if (token) {
|
|
2592
|
-
token = false;
|
|
2593
|
-
try {
|
|
2594
|
-
fn();
|
|
2595
|
-
executed = true;
|
|
2596
|
-
} finally {
|
|
2597
|
-
token = true;
|
|
2598
|
-
}
|
|
2599
|
-
} else if (elseFn !== void 0) {
|
|
2600
|
-
elseFn();
|
|
2601
|
-
}
|
|
2602
|
-
return executed;
|
|
2603
|
-
};
|
|
2604
|
-
}
|
|
2605
|
-
__name(useMutex, "useMutex");
|
|
2606
|
-
function useAsyncMutex() {
|
|
2607
|
-
let token = true;
|
|
2608
|
-
return async (fn, elseFn) => {
|
|
2609
|
-
let executed = false;
|
|
2610
|
-
if (token) {
|
|
2611
|
-
token = false;
|
|
2612
|
-
try {
|
|
2613
|
-
let result = fn();
|
|
2614
|
-
if (isPromise(result))
|
|
2615
|
-
await result;
|
|
2616
|
-
executed = true;
|
|
2617
|
-
} finally {
|
|
2618
|
-
token = true;
|
|
2619
|
-
}
|
|
2620
|
-
} else if (elseFn !== void 0) {
|
|
2621
|
-
let result = elseFn();
|
|
2622
|
-
if (isPromise(result))
|
|
2623
|
-
await result;
|
|
2624
|
-
}
|
|
2625
|
-
return executed;
|
|
2626
|
-
};
|
|
2627
|
-
}
|
|
2628
|
-
__name(useAsyncMutex, "useAsyncMutex");
|
|
2629
|
-
|
|
2630
|
-
// src/common/msg/emitter.ts
|
|
2631
|
-
var log5 = Logger("zeed:emitter");
|
|
2632
|
-
var Emitter = class {
|
|
2633
|
-
constructor() {
|
|
2634
|
-
this.subscribers = {};
|
|
2635
|
-
this.subscribersOnAny = [];
|
|
2636
|
-
this.dispose = useDispose();
|
|
2637
|
-
this.call = new Proxy({}, {
|
|
2638
|
-
get: (target, name) => (...args) => this.emit(name, ...args)
|
|
2639
|
-
});
|
|
2640
|
-
}
|
|
2641
|
-
async emit(event, ...args) {
|
|
2642
|
-
let ok = false;
|
|
2643
|
-
this.dispose.add(() => {
|
|
2644
|
-
this.subscribers = {};
|
|
2645
|
-
this.subscribersOnAny = [];
|
|
2646
|
-
});
|
|
2647
|
-
try {
|
|
2648
|
-
let subscribers = this.subscribers[event] || [];
|
|
2649
|
-
this.subscribersOnAny.forEach((fn) => fn(event, ...args));
|
|
2650
|
-
if (subscribers.length > 0) {
|
|
2651
|
-
let all = subscribers.map((fn) => {
|
|
2652
|
-
try {
|
|
2653
|
-
return promisify(fn(...args));
|
|
2654
|
-
} catch (err) {
|
|
2655
|
-
log5.warn("emit warning:", err);
|
|
2656
|
-
}
|
|
2657
|
-
});
|
|
2658
|
-
ok = true;
|
|
2659
|
-
await Promise.all(all);
|
|
2660
|
-
}
|
|
2661
|
-
} catch (err) {
|
|
2662
|
-
log5.error("emit exception", err);
|
|
2663
|
-
}
|
|
2664
|
-
return ok;
|
|
2665
|
-
}
|
|
2666
|
-
onAny(fn) {
|
|
2667
|
-
this.subscribersOnAny.push(fn);
|
|
2668
|
-
}
|
|
2669
|
-
on(event, listener) {
|
|
2670
|
-
let subscribers = this.subscribers[event] || [];
|
|
2671
|
-
subscribers.push(listener);
|
|
2672
|
-
this.subscribers[event] = subscribers;
|
|
2673
|
-
return () => {
|
|
2674
|
-
this.off(event, listener);
|
|
2675
|
-
};
|
|
2676
|
-
}
|
|
2677
|
-
onCall(handlers) {
|
|
2678
|
-
for (const [name, handler] of Object.entries(handlers)) {
|
|
2679
|
-
this.on(name, handler);
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
once(event, listener) {
|
|
2683
|
-
const onceListener = /* @__PURE__ */ __name(async (...args) => {
|
|
2684
|
-
this.off(event, onceListener);
|
|
2685
|
-
return await promisify(listener(...args));
|
|
2686
|
-
}, "onceListener");
|
|
2687
|
-
this.on(event, onceListener);
|
|
2688
|
-
return () => {
|
|
2689
|
-
this.off(event, listener);
|
|
2690
|
-
};
|
|
2691
|
-
}
|
|
2692
|
-
off(event, listener) {
|
|
2693
|
-
this.subscribers[event] = (this.subscribers[event] || []).filter(
|
|
2694
|
-
(f) => listener && f !== listener
|
|
2695
|
-
);
|
|
2696
|
-
return this;
|
|
2697
|
-
}
|
|
2698
|
-
removeAllListeners() {
|
|
2699
|
-
this.subscribers = {};
|
|
2700
|
-
return this;
|
|
2701
|
-
}
|
|
2702
|
-
};
|
|
2703
|
-
__name(Emitter, "Emitter");
|
|
2704
|
-
function getGlobalEmitter() {
|
|
2705
|
-
let emitter = getGlobalContext().emitter;
|
|
2706
|
-
if (!emitter) {
|
|
2707
|
-
emitter = new Emitter();
|
|
2708
|
-
getGlobalContext().emitter = emitter;
|
|
2709
|
-
}
|
|
2710
|
-
return emitter;
|
|
2711
|
-
}
|
|
2712
|
-
__name(getGlobalEmitter, "getGlobalEmitter");
|
|
2713
|
-
var messages = new Emitter();
|
|
2714
|
-
function lazyListener(emitter, listenerKey) {
|
|
2715
|
-
const name = Math.round(getSecureRandomIfPossible() * 100);
|
|
2716
|
-
var events = [];
|
|
2717
|
-
var lazyResolve;
|
|
2718
|
-
const incoming = /* @__PURE__ */ __name((key, obj) => {
|
|
2719
|
-
let ev = { key, obj };
|
|
2720
|
-
events.push(ev);
|
|
2721
|
-
lazyResolve && lazyResolve();
|
|
2722
|
-
}, "incoming");
|
|
2723
|
-
if (listenerKey) {
|
|
2724
|
-
if (emitter.on) {
|
|
2725
|
-
emitter.on(listenerKey, (obj) => {
|
|
2726
|
-
incoming(listenerKey, obj);
|
|
2727
|
-
});
|
|
2728
|
-
} else if (emitter.addEventListener) {
|
|
2729
|
-
emitter.addEventListener(listenerKey, (obj) => {
|
|
2730
|
-
incoming(listenerKey, obj);
|
|
2731
|
-
});
|
|
2732
|
-
} else {
|
|
2733
|
-
log5.error(name, "Cannot listen to key");
|
|
2734
|
-
}
|
|
2735
|
-
} else {
|
|
2736
|
-
if (emitter.onAny) {
|
|
2737
|
-
emitter.onAny((key, obj) => {
|
|
2738
|
-
incoming(key, obj);
|
|
2739
|
-
});
|
|
2740
|
-
} else {
|
|
2741
|
-
log5.error(name, "cannot listen to all for", emitter);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
let on = /* @__PURE__ */ __name((key, skipUnmatched = true) => {
|
|
2745
|
-
return new Promise((resolve6, reject) => {
|
|
2746
|
-
if (!key) {
|
|
2747
|
-
key = listenerKey;
|
|
2748
|
-
if (!key) {
|
|
2749
|
-
if (events.length) {
|
|
2750
|
-
key = events[0].key;
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
lazyResolve = /* @__PURE__ */ __name(() => {
|
|
2755
|
-
while (events.length > 0) {
|
|
2756
|
-
let ev = events.shift();
|
|
2757
|
-
if (ev.key === key) {
|
|
2758
|
-
lazyResolve = void 0;
|
|
2759
|
-
resolve6(ev.obj);
|
|
2760
|
-
} else {
|
|
2761
|
-
if (skipUnmatched) {
|
|
2762
|
-
log5.warn(name, `Unhandled event ${key} with value: ${ev.obj}`);
|
|
2763
|
-
continue;
|
|
2764
|
-
}
|
|
2765
|
-
reject(`Expected ${key}, but found ${ev.key} with value=${ev.obj}`);
|
|
2766
|
-
log5.error(name, `Unhandled event ${key} with value: ${ev.obj}`);
|
|
2767
|
-
}
|
|
2768
|
-
break;
|
|
2769
|
-
}
|
|
2770
|
-
}, "lazyResolve");
|
|
2771
|
-
lazyResolve();
|
|
2772
|
-
});
|
|
2773
|
-
}, "on");
|
|
2774
|
-
return on;
|
|
2775
|
-
}
|
|
2776
|
-
__name(lazyListener, "lazyListener");
|
|
2777
|
-
|
|
2778
|
-
// src/common/time.ts
|
|
2779
|
-
var getTimestamp = /* @__PURE__ */ __name(() => Date.now(), "getTimestamp");
|
|
2780
|
-
function formatMilliseconds(ms) {
|
|
2781
|
-
return ms > 999 ? (ms / 1e3).toFixed(1) + "s" : ms.toFixed(2) + "ms";
|
|
2782
|
-
}
|
|
2783
|
-
__name(formatMilliseconds, "formatMilliseconds");
|
|
2784
|
-
function parseDate(...dateCandidates) {
|
|
2785
|
-
for (let dateCandidate of dateCandidates) {
|
|
2786
|
-
if (dateCandidate instanceof Date) {
|
|
2787
|
-
return dateCandidate;
|
|
2788
|
-
}
|
|
2789
|
-
if (typeof dateCandidate === "string") {
|
|
2790
|
-
let date = null;
|
|
2791
|
-
if (dateCandidate.includes(":")) {
|
|
2792
|
-
try {
|
|
2793
|
-
date = new Date(dateCandidate);
|
|
2794
|
-
} catch (err) {
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
if (!(date instanceof Date)) {
|
|
2798
|
-
let m = /(\d\d\d\d)-(\d\d)-(\d\d)/.exec(dateCandidate);
|
|
2799
|
-
if (m) {
|
|
2800
|
-
date = new Date(+m[1], +m[2] - 1, +m[3], 12, 0);
|
|
2801
|
-
}
|
|
2802
|
-
}
|
|
2803
|
-
if (date instanceof Date) {
|
|
2804
|
-
return date;
|
|
2805
|
-
}
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
__name(parseDate, "parseDate");
|
|
2810
|
-
|
|
2811
|
-
// src/common/uuid.ts
|
|
2812
|
-
var { encode: encode62, decode: decode62 } = useBase(62);
|
|
2813
|
-
var { encode: encode32, decode: decode32 } = useBase(32);
|
|
2814
|
-
function uuidBytes() {
|
|
2815
|
-
return randomUint8Array(16);
|
|
2816
|
-
}
|
|
2817
|
-
__name(uuidBytes, "uuidBytes");
|
|
2818
|
-
var uuid32bit = /* @__PURE__ */ __name(() => new Uint32Array(randomUint8Array(4))[0], "uuid32bit");
|
|
2819
|
-
function uuid() {
|
|
2820
|
-
return encode62(uuidBytes(), 22);
|
|
2821
|
-
}
|
|
2822
|
-
__name(uuid, "uuid");
|
|
2823
|
-
function uuidEncode(bytes) {
|
|
2824
|
-
return encode62(bytes, 22);
|
|
2825
|
-
}
|
|
2826
|
-
__name(uuidEncode, "uuidEncode");
|
|
2827
|
-
function uuidDecode(uuid2) {
|
|
2828
|
-
return decode62(uuid2, 16);
|
|
2829
|
-
}
|
|
2830
|
-
__name(uuidDecode, "uuidDecode");
|
|
2831
|
-
function uuidB32() {
|
|
2832
|
-
return encode32(uuidBytes(), 26);
|
|
2833
|
-
}
|
|
2834
|
-
__name(uuidB32, "uuidB32");
|
|
2835
|
-
function uuid32Encode(bytes) {
|
|
2836
|
-
return encode32(bytes, 26);
|
|
2837
|
-
}
|
|
2838
|
-
__name(uuid32Encode, "uuid32Encode");
|
|
2839
|
-
function uuid32Decode(uuid2) {
|
|
2840
|
-
return decode32(uuid2, 16);
|
|
2841
|
-
}
|
|
2842
|
-
__name(uuid32Decode, "uuid32Decode");
|
|
2843
|
-
var _unameCounters = {};
|
|
2844
|
-
function uname(name = "id") {
|
|
2845
|
-
if (_unameCounters[name] == null) {
|
|
2846
|
-
_unameCounters[name] = 0;
|
|
2847
|
-
}
|
|
2848
|
-
return `${name}-${_unameCounters[name]++}`;
|
|
2849
|
-
}
|
|
2850
|
-
__name(uname, "uname");
|
|
2851
|
-
var _qid = 0;
|
|
2852
|
-
function qid() {
|
|
2853
|
-
return `id-${_qid++}`;
|
|
2854
|
-
}
|
|
2855
|
-
__name(qid, "qid");
|
|
2856
|
-
var pattern = "10000000-1000-4000-8000-100000000000";
|
|
2857
|
-
var uuidv4 = typeof crypto !== "undefined" && crypto.randomUUID != null ? crypto.randomUUID : () => pattern.replace(
|
|
2858
|
-
/[018]/g,
|
|
2859
|
-
(c) => (c ^ randomUint8Array(1)[0] & 15 >> c / 4).toString(16)
|
|
2860
|
-
);
|
|
2861
|
-
var ReferenceDateInMS = 16e11;
|
|
2862
|
-
function longToByteArray(long) {
|
|
2863
|
-
var byteArray = new Uint8Array([0, 0, 0, 0, 0, 0]);
|
|
2864
|
-
const bytes = byteArray.length - 1;
|
|
2865
|
-
for (var index = 0; index < byteArray.length; index++) {
|
|
2866
|
-
var byte = long & 255;
|
|
2867
|
-
byteArray[bytes - index] = byte;
|
|
2868
|
-
long = (long - byte) / 256;
|
|
2869
|
-
}
|
|
2870
|
-
return byteArray;
|
|
2871
|
-
}
|
|
2872
|
-
__name(longToByteArray, "longToByteArray");
|
|
2873
|
-
function suidBytes() {
|
|
2874
|
-
const ms = getTimestamp() - ReferenceDateInMS;
|
|
2875
|
-
return new Uint8Array([...longToByteArray(ms), ...randomUint8Array(10)]);
|
|
2876
|
-
}
|
|
2877
|
-
__name(suidBytes, "suidBytes");
|
|
2878
|
-
function suid() {
|
|
2879
|
-
return encode62(suidBytes(), 22);
|
|
2880
|
-
}
|
|
2881
|
-
__name(suid, "suid");
|
|
2882
|
-
function suidDate(id) {
|
|
2883
|
-
return suidBytesDate(decode62(id, 16));
|
|
2884
|
-
}
|
|
2885
|
-
__name(suidDate, "suidDate");
|
|
2886
|
-
function suidBytesDate(id) {
|
|
2887
|
-
return new Date(
|
|
2888
|
-
ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => {
|
|
2889
|
-
return acc * 256 + byte;
|
|
2890
|
-
}, 0)
|
|
2891
|
-
);
|
|
2892
|
-
}
|
|
2893
|
-
__name(suidBytesDate, "suidBytesDate");
|
|
2894
|
-
|
|
2895
|
-
// src/common/exec/pool.ts
|
|
2896
|
-
var PoolTaskState = /* @__PURE__ */ ((PoolTaskState2) => {
|
|
2897
|
-
PoolTaskState2[PoolTaskState2["waiting"] = 0] = "waiting";
|
|
2898
|
-
PoolTaskState2[PoolTaskState2["running"] = 1] = "running";
|
|
2899
|
-
PoolTaskState2[PoolTaskState2["finished"] = 2] = "finished";
|
|
2900
|
-
return PoolTaskState2;
|
|
2901
|
-
})(PoolTaskState || {});
|
|
2902
|
-
var PoolTaskIdConflictResolution = /* @__PURE__ */ ((PoolTaskIdConflictResolution2) => {
|
|
2903
|
-
PoolTaskIdConflictResolution2[PoolTaskIdConflictResolution2["replace"] = 0] = "replace";
|
|
2904
|
-
PoolTaskIdConflictResolution2[PoolTaskIdConflictResolution2["memoize"] = 1] = "memoize";
|
|
2905
|
-
PoolTaskIdConflictResolution2[PoolTaskIdConflictResolution2["error"] = 2] = "error";
|
|
2906
|
-
return PoolTaskIdConflictResolution2;
|
|
2907
|
-
})(PoolTaskIdConflictResolution || {});
|
|
2908
|
-
function usePool(config = {}) {
|
|
2909
|
-
const { maxParallel = 3 } = config;
|
|
2910
|
-
const events = new Emitter();
|
|
2911
|
-
let countMax = 0;
|
|
2912
|
-
let countResolved = 0;
|
|
2913
|
-
let currentParallel = 0;
|
|
2914
|
-
let priority = 0;
|
|
2915
|
-
let tasks = {};
|
|
2916
|
-
async function waitFinishAll() {
|
|
2917
|
-
if (countMax > 0) {
|
|
2918
|
-
const [promise, resolve6] = createPromise();
|
|
2919
|
-
events.once("didFinish", resolve6);
|
|
2920
|
-
return promise;
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
__name(waitFinishAll, "waitFinishAll");
|
|
2924
|
-
function didFinish() {
|
|
2925
|
-
events.emit("didFinish");
|
|
2926
|
-
countMax = 0;
|
|
2927
|
-
countResolved = 0;
|
|
2928
|
-
}
|
|
2929
|
-
__name(didFinish, "didFinish");
|
|
2930
|
-
function didUpdate() {
|
|
2931
|
-
let presentMax = 0;
|
|
2932
|
-
let presentResolved = 0;
|
|
2933
|
-
for (const { max, resolved, state } of Object.values(tasks)) {
|
|
2934
|
-
presentMax += max;
|
|
2935
|
-
presentResolved += state === 2 /* finished */ ? max : Math.min(max, resolved);
|
|
2936
|
-
}
|
|
2937
|
-
events.emit(
|
|
2938
|
-
"didUpdate",
|
|
2939
|
-
countMax,
|
|
2940
|
-
countResolved,
|
|
2941
|
-
presentMax,
|
|
2942
|
-
presentResolved
|
|
2943
|
-
);
|
|
2944
|
-
}
|
|
2945
|
-
__name(didUpdate, "didUpdate");
|
|
2946
|
-
function performNext() {
|
|
2947
|
-
didUpdate();
|
|
2948
|
-
if (countMax > 0 && countMax === countResolved)
|
|
2949
|
-
didFinish();
|
|
2950
|
-
if (currentParallel >= maxParallel)
|
|
2951
|
-
return;
|
|
2952
|
-
let waitingTasks = Object.values(tasks).filter(
|
|
2953
|
-
(t) => t.state === 0 /* waiting */
|
|
2954
|
-
);
|
|
2955
|
-
if (waitingTasks.length > 0) {
|
|
2956
|
-
let taskInfo;
|
|
2957
|
-
for (let t of waitingTasks) {
|
|
2958
|
-
if (taskInfo == null || t.priority < taskInfo.priority) {
|
|
2959
|
-
taskInfo = t;
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
if (taskInfo != null) {
|
|
2963
|
-
const id = taskInfo.id;
|
|
2964
|
-
const done = taskInfo.done;
|
|
2965
|
-
taskInfo.state = 1 /* running */;
|
|
2966
|
-
++currentParallel;
|
|
2967
|
-
events.emit("didStart", id);
|
|
2968
|
-
const taskFinished = /* @__PURE__ */ __name((result) => {
|
|
2969
|
-
if (taskInfo) {
|
|
2970
|
-
taskInfo.result = result;
|
|
2971
|
-
taskInfo.state = 2 /* finished */;
|
|
2972
|
-
taskInfo.resolved = taskInfo.max;
|
|
2973
|
-
}
|
|
2974
|
-
--currentParallel;
|
|
2975
|
-
++countResolved;
|
|
2976
|
-
performNext();
|
|
2977
|
-
}, "taskFinished");
|
|
2978
|
-
taskInfo.task(taskInfo).then((r) => {
|
|
2979
|
-
done(r);
|
|
2980
|
-
events.emit("didResolve", id, r);
|
|
2981
|
-
taskFinished(r);
|
|
2982
|
-
}).catch((err) => {
|
|
2983
|
-
done();
|
|
2984
|
-
events.emit("didReject", id, err);
|
|
2985
|
-
taskFinished();
|
|
2986
|
-
});
|
|
2987
|
-
}
|
|
2988
|
-
}
|
|
2989
|
-
}
|
|
2990
|
-
__name(performNext, "performNext");
|
|
2991
|
-
function cancel(id) {
|
|
2992
|
-
let taskInfo = tasks[id];
|
|
2993
|
-
if (taskInfo && taskInfo.state === 0 /* waiting */) {
|
|
2994
|
-
tasks[id].state = 2 /* finished */;
|
|
2995
|
-
++countResolved;
|
|
2996
|
-
events.emit("didCancel", id);
|
|
2997
|
-
didUpdate();
|
|
2998
|
-
}
|
|
2999
|
-
}
|
|
3000
|
-
__name(cancel, "cancel");
|
|
3001
|
-
function cancelAll() {
|
|
3002
|
-
Object.keys(tasks).forEach(cancel);
|
|
3003
|
-
}
|
|
3004
|
-
__name(cancelAll, "cancelAll");
|
|
3005
|
-
function enqueue(task, config2 = {}) {
|
|
3006
|
-
let done;
|
|
3007
|
-
let promise = new Promise((resolve6) => done = resolve6);
|
|
3008
|
-
let id = config2.id ?? uuid();
|
|
3009
|
-
if (tasks[id] != null) {
|
|
3010
|
-
const resolution = config2.idConflictResolution ?? 1 /* memoize */;
|
|
3011
|
-
if (resolution === 0 /* replace */) {
|
|
3012
|
-
cancel(id);
|
|
3013
|
-
} else if (resolution === 1 /* memoize */) {
|
|
3014
|
-
let runningTask = tasks[id];
|
|
3015
|
-
return {
|
|
3016
|
-
id,
|
|
3017
|
-
promise: (async () => {
|
|
3018
|
-
if (runningTask.state === 2 /* finished */) {
|
|
3019
|
-
return tasks[id].result;
|
|
3020
|
-
}
|
|
3021
|
-
})(),
|
|
3022
|
-
dispose: () => cancel(id),
|
|
3023
|
-
cancel: () => cancel(id)
|
|
3024
|
-
};
|
|
3025
|
-
} else {
|
|
3026
|
-
throw new Error(`Pool task with id=${id} already exists!`);
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
tasks[id] = {
|
|
3030
|
-
id,
|
|
3031
|
-
task,
|
|
3032
|
-
priority: ++priority,
|
|
3033
|
-
state: 0 /* waiting */,
|
|
3034
|
-
max: config2.max ?? 1,
|
|
3035
|
-
resolved: config2.resolved ?? 0,
|
|
3036
|
-
done,
|
|
3037
|
-
payload: config2.payload,
|
|
3038
|
-
setMax(max) {
|
|
3039
|
-
tasks[id].max = max;
|
|
3040
|
-
didUpdate();
|
|
3041
|
-
},
|
|
3042
|
-
setResolved(max) {
|
|
3043
|
-
tasks[id].resolved = max;
|
|
3044
|
-
didUpdate();
|
|
3045
|
-
},
|
|
3046
|
-
incResolved(inc = 1) {
|
|
3047
|
-
tasks[id].resolved += inc;
|
|
3048
|
-
didUpdate();
|
|
3049
|
-
}
|
|
3050
|
-
};
|
|
3051
|
-
++countMax;
|
|
3052
|
-
performNext();
|
|
3053
|
-
return {
|
|
3054
|
-
id,
|
|
3055
|
-
promise,
|
|
3056
|
-
dispose: () => cancel(id),
|
|
3057
|
-
cancel: () => cancel(id)
|
|
3058
|
-
};
|
|
3059
|
-
}
|
|
3060
|
-
__name(enqueue, "enqueue");
|
|
3061
|
-
return {
|
|
3062
|
-
events,
|
|
3063
|
-
cancel,
|
|
3064
|
-
cancelAll,
|
|
3065
|
-
enqueue,
|
|
3066
|
-
dispose: cancelAll,
|
|
3067
|
-
waitFinishAll
|
|
3068
|
-
};
|
|
3069
|
-
}
|
|
3070
|
-
__name(usePool, "usePool");
|
|
3071
|
-
|
|
3072
|
-
// src/common/exec/queue.ts
|
|
3073
|
-
var SerialQueue = class extends Emitter {
|
|
3074
|
-
constructor(opt = {}) {
|
|
3075
|
-
super();
|
|
3076
|
-
this.queue = [];
|
|
3077
|
-
this.waitToFinish = [];
|
|
3078
|
-
this.countMax = 0;
|
|
3079
|
-
this.countResolved = 0;
|
|
3080
|
-
this.paused = false;
|
|
3081
|
-
const { name = uname("queue"), logLevel } = opt;
|
|
3082
|
-
this.name = name;
|
|
3083
|
-
this.log = Logger(`zeed:queue:${name}`, logLevel ?? Infinity /* off */);
|
|
3084
|
-
}
|
|
3085
|
-
async performNext() {
|
|
3086
|
-
this.log(`performNext, queue.length =`, this.queue.length);
|
|
3087
|
-
if (this.currentTask != null) {
|
|
3088
|
-
this.log(`performNext => skip while another task is running`);
|
|
3089
|
-
return;
|
|
3090
|
-
}
|
|
3091
|
-
if (this.paused) {
|
|
3092
|
-
this.log(`performNext => skip while is paused`);
|
|
3093
|
-
return;
|
|
3094
|
-
}
|
|
3095
|
-
while (this.currentTask == null && !this.paused) {
|
|
3096
|
-
let info = this.queue.shift();
|
|
3097
|
-
this.log(`performNext => ${info == null ? void 0 : info.name}`);
|
|
3098
|
-
if (info == null) {
|
|
3099
|
-
break;
|
|
3100
|
-
}
|
|
3101
|
-
if (this.countResolved === 0) {
|
|
3102
|
-
this.emit("didStart", this.countMax);
|
|
3103
|
-
}
|
|
3104
|
-
const { name, task, resolve: resolve6 } = info;
|
|
3105
|
-
this.currentTask = task();
|
|
3106
|
-
let result = void 0;
|
|
3107
|
-
try {
|
|
3108
|
-
this.log.info(`start task ${name}`);
|
|
3109
|
-
result = await this.currentTask;
|
|
3110
|
-
this.log(`finished task ${name} with result =`, result);
|
|
3111
|
-
} catch (err) {
|
|
3112
|
-
this.log.warn("Error performing task", err);
|
|
3113
|
-
}
|
|
3114
|
-
resolve6(result);
|
|
3115
|
-
this.currentTask = void 0;
|
|
3116
|
-
this.countResolved += 1;
|
|
3117
|
-
this.emit("didUpdate", this.countMax, this.countResolved);
|
|
3118
|
-
}
|
|
3119
|
-
if (this.queue.length === 0) {
|
|
3120
|
-
this.emit("didFinish");
|
|
3121
|
-
this.countMax = 0;
|
|
3122
|
-
this.countResolved = 0;
|
|
3123
|
-
}
|
|
3124
|
-
while (this.waitToFinish.length > 0) {
|
|
3125
|
-
this.waitToFinish.shift()();
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
async enqueue(task, opt = {}) {
|
|
3129
|
-
const { immediate: immediate2 = false, name = uname(this.name) } = opt;
|
|
3130
|
-
if (immediate2) {
|
|
3131
|
-
this.log.info(`immediate execution ${name}`);
|
|
3132
|
-
return await task();
|
|
3133
|
-
}
|
|
3134
|
-
this.log(`enqueue ${name}`);
|
|
3135
|
-
return new Promise((resolve6) => {
|
|
3136
|
-
this.queue.push({
|
|
3137
|
-
name,
|
|
3138
|
-
task,
|
|
3139
|
-
resolve: resolve6
|
|
3140
|
-
});
|
|
3141
|
-
this.countMax += 1;
|
|
3142
|
-
this.emit("didUpdate", this.countMax, this.countResolved);
|
|
3143
|
-
this.performNext();
|
|
3144
|
-
});
|
|
3145
|
-
}
|
|
3146
|
-
async enqueueReentrant(task, opt = {}) {
|
|
3147
|
-
return this.enqueue(task, {
|
|
3148
|
-
immediate: this.currentTask != null,
|
|
3149
|
-
name: opt.name
|
|
3150
|
-
});
|
|
3151
|
-
}
|
|
3152
|
-
async cancelAll(unblock = true) {
|
|
3153
|
-
this.log(`cancelAll`);
|
|
3154
|
-
this.emit("didCancel");
|
|
3155
|
-
let resolver = this.queue.map((task) => task.resolve);
|
|
3156
|
-
this.queue = [];
|
|
3157
|
-
resolver.forEach((r) => r(void 0));
|
|
3158
|
-
await this.wait();
|
|
3159
|
-
}
|
|
3160
|
-
async pause() {
|
|
3161
|
-
this.log(`pause`);
|
|
3162
|
-
this.paused = true;
|
|
3163
|
-
await this.wait();
|
|
3164
|
-
}
|
|
3165
|
-
resume() {
|
|
3166
|
-
this.log(`resume`);
|
|
3167
|
-
this.paused = false;
|
|
3168
|
-
this.performNext();
|
|
3169
|
-
}
|
|
3170
|
-
async wait() {
|
|
3171
|
-
this.log(`wait`);
|
|
3172
|
-
if (this.currentTask == null && (this.queue.length === 0 || this.paused)) {
|
|
3173
|
-
return;
|
|
3174
|
-
}
|
|
3175
|
-
return new Promise((resolve6) => {
|
|
3176
|
-
this.waitToFinish.push(resolve6);
|
|
3177
|
-
});
|
|
3178
|
-
}
|
|
3179
|
-
get isPaused() {
|
|
3180
|
-
return this.paused;
|
|
3181
|
-
}
|
|
3182
|
-
get hasTasks() {
|
|
3183
|
-
return this.queue.length !== 0;
|
|
3184
|
-
}
|
|
3185
|
-
};
|
|
3186
|
-
__name(SerialQueue, "SerialQueue");
|
|
3187
|
-
var log6 = () => {
|
|
3188
|
-
};
|
|
3189
|
-
function throttle(callback, opt = {}) {
|
|
3190
|
-
const { delay = 100, trailing = true, leading = true } = opt;
|
|
3191
|
-
let timeoutID = 0;
|
|
3192
|
-
let checkpoint = 0;
|
|
3193
|
-
let visited = 0;
|
|
3194
|
-
let trailingExec;
|
|
3195
|
-
let debugCheckpoint = Date.now();
|
|
3196
|
-
function clearExistingTimeout() {
|
|
3197
|
-
if (timeoutID) {
|
|
3198
|
-
clearTimeout(timeoutID);
|
|
3199
|
-
timeoutID = void 0;
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
__name(clearExistingTimeout, "clearExistingTimeout");
|
|
3203
|
-
function wrapper(...args) {
|
|
3204
|
-
const now = Date.now();
|
|
3205
|
-
let self2 = this;
|
|
3206
|
-
let elapsed = now - checkpoint;
|
|
3207
|
-
function debugElapsed() {
|
|
3208
|
-
const dnow = Date.now();
|
|
3209
|
-
return `total ${(dnow - debugCheckpoint).toFixed(1)}ms - elapsed ${(dnow - checkpoint).toFixed(1)}ms - visited ${visited}x`;
|
|
3210
|
-
}
|
|
3211
|
-
__name(debugElapsed, "debugElapsed");
|
|
3212
|
-
function exec() {
|
|
3213
|
-
visited = 0;
|
|
3214
|
-
checkpoint = Date.now();
|
|
3215
|
-
callback.apply(self2, args);
|
|
3216
|
-
}
|
|
3217
|
-
__name(exec, "exec");
|
|
3218
|
-
trailingExec = exec;
|
|
3219
|
-
if (elapsed > delay || !timeoutID) {
|
|
3220
|
-
if (leading) {
|
|
3221
|
-
if (elapsed > delay) {
|
|
3222
|
-
exec();
|
|
3223
|
-
} else {
|
|
3224
|
-
++visited;
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
const timeout2 = elapsed > delay ? delay : delay - elapsed;
|
|
3228
|
-
log6(`\u23F1 start timeout with ${timeout2.toFixed(1)}ms`, debugElapsed());
|
|
3229
|
-
clearExistingTimeout();
|
|
3230
|
-
checkpoint = now;
|
|
3231
|
-
timeoutID = setTimeout(() => {
|
|
3232
|
-
timeoutID = 0;
|
|
3233
|
-
if (trailing && (!leading || visited > 0)) {
|
|
3234
|
-
trailingExec == null ? void 0 : trailingExec();
|
|
3235
|
-
}
|
|
3236
|
-
}, timeout2);
|
|
3237
|
-
} else {
|
|
3238
|
-
++visited;
|
|
3239
|
-
}
|
|
3240
|
-
}
|
|
3241
|
-
__name(wrapper, "wrapper");
|
|
3242
|
-
wrapper.cancel = clearExistingTimeout;
|
|
3243
|
-
wrapper.dispose = clearExistingTimeout;
|
|
3244
|
-
return wrapper;
|
|
3245
|
-
}
|
|
3246
|
-
__name(throttle, "throttle");
|
|
3247
|
-
function debounce(callback, opt = {}) {
|
|
3248
|
-
const { delay = 100 } = opt;
|
|
3249
|
-
let timeoutID = 0;
|
|
3250
|
-
function clearExistingTimeout() {
|
|
3251
|
-
if (timeoutID) {
|
|
3252
|
-
clearTimeout(timeoutID);
|
|
3253
|
-
timeoutID = 0;
|
|
3254
|
-
}
|
|
3255
|
-
}
|
|
3256
|
-
__name(clearExistingTimeout, "clearExistingTimeout");
|
|
3257
|
-
function wrapper(...arguments_) {
|
|
3258
|
-
let self2 = this;
|
|
3259
|
-
clearExistingTimeout();
|
|
3260
|
-
timeoutID = setTimeout(() => {
|
|
3261
|
-
timeoutID = 0;
|
|
3262
|
-
callback.apply(self2, arguments_);
|
|
3263
|
-
}, delay);
|
|
3264
|
-
}
|
|
3265
|
-
__name(wrapper, "wrapper");
|
|
3266
|
-
wrapper.cancel = clearExistingTimeout;
|
|
3267
|
-
wrapper.dispose = clearExistingTimeout;
|
|
3268
|
-
return wrapper;
|
|
3269
|
-
}
|
|
3270
|
-
__name(debounce, "debounce");
|
|
3271
|
-
|
|
3272
|
-
// src/common/localhost.ts
|
|
3273
|
-
function isLocalHost(hostname = ((_a2) => (_a2 = globalThis == null ? void 0 : globalThis.location) == null ? void 0 : _a2.hostname)() ?? "") {
|
|
3274
|
-
return ["::ffff:127.0.0.1", "localhost", "127.0.0.1", "", "::1", "::"].includes(
|
|
3275
|
-
hostname
|
|
3276
|
-
) || hostname.startsWith("192.168.") || hostname.startsWith("10.0.") || hostname.endsWith(".local");
|
|
3277
|
-
}
|
|
3278
|
-
__name(isLocalHost, "isLocalHost");
|
|
3279
|
-
|
|
3280
|
-
// src/common/log-memory.ts
|
|
3281
|
-
function LoggerMemoryHandler(opt) {
|
|
3282
|
-
let { level = void 0, filter = void 0, messages: messages2 = [] } = opt;
|
|
3283
|
-
const matchesNamespace = useNamespaceFilter(filter);
|
|
3284
|
-
const matchesLevel = useLevelFilter(level);
|
|
3285
|
-
return (msg) => {
|
|
3286
|
-
if (!matchesLevel(msg.level))
|
|
3287
|
-
return;
|
|
3288
|
-
if (!matchesNamespace(msg.name))
|
|
3289
|
-
return;
|
|
3290
|
-
messages2.push(msg);
|
|
3291
|
-
};
|
|
3292
|
-
}
|
|
3293
|
-
__name(LoggerMemoryHandler, "LoggerMemoryHandler");
|
|
3294
|
-
|
|
3295
|
-
// src/common/msg/channel.ts
|
|
3296
|
-
var Channel = class extends Emitter {
|
|
3297
|
-
constructor() {
|
|
3298
|
-
super(...arguments);
|
|
3299
|
-
this.id = uuid();
|
|
3300
|
-
}
|
|
3301
|
-
close() {
|
|
3302
|
-
this.dispose();
|
|
3303
|
-
}
|
|
3304
|
-
};
|
|
3305
|
-
__name(Channel, "Channel");
|
|
3306
|
-
var LocalChannel = class extends Channel {
|
|
3307
|
-
constructor() {
|
|
3308
|
-
super(...arguments);
|
|
3309
|
-
this.isConnected = true;
|
|
3310
|
-
}
|
|
3311
|
-
postMessage(data) {
|
|
3312
|
-
var _a2;
|
|
3313
|
-
(_a2 = this.other) == null ? void 0 : _a2.emit("message", {
|
|
3314
|
-
data,
|
|
3315
|
-
origin: "local",
|
|
3316
|
-
lastEventId: uuid()
|
|
3317
|
-
});
|
|
3318
|
-
}
|
|
3319
|
-
};
|
|
3320
|
-
__name(LocalChannel, "LocalChannel");
|
|
3321
|
-
function createLocalChannelPair() {
|
|
3322
|
-
let w1 = new LocalChannel();
|
|
3323
|
-
let w2 = new LocalChannel();
|
|
3324
|
-
w1.other = w2;
|
|
3325
|
-
w2.other = w1;
|
|
3326
|
-
return [w1, w2];
|
|
3327
|
-
}
|
|
3328
|
-
__name(createLocalChannelPair, "createLocalChannelPair");
|
|
3329
|
-
|
|
3330
|
-
// src/common/msg/encoder.ts
|
|
3331
|
-
var NoopEncoder = class {
|
|
3332
|
-
async encode(data) {
|
|
3333
|
-
return data;
|
|
3334
|
-
}
|
|
3335
|
-
async decode(data) {
|
|
3336
|
-
return data;
|
|
3337
|
-
}
|
|
3338
|
-
};
|
|
3339
|
-
__name(NoopEncoder, "NoopEncoder");
|
|
3340
|
-
var JsonEncoder = class {
|
|
3341
|
-
async encode(data) {
|
|
3342
|
-
return jsonToUint8Array(data);
|
|
3343
|
-
}
|
|
3344
|
-
async decode(data) {
|
|
3345
|
-
return Uint8ArrayToJson(data);
|
|
3346
|
-
}
|
|
3347
|
-
};
|
|
3348
|
-
__name(JsonEncoder, "JsonEncoder");
|
|
3349
|
-
var CryptoEncoder = class {
|
|
3350
|
-
constructor(key) {
|
|
3351
|
-
this.key = key;
|
|
3352
|
-
}
|
|
3353
|
-
async encode(data) {
|
|
3354
|
-
const plain = jsonToUint8Array(data);
|
|
3355
|
-
return await encrypt(plain, this.key);
|
|
3356
|
-
}
|
|
3357
|
-
async decode(data) {
|
|
3358
|
-
const plain = await decrypt(data, this.key);
|
|
3359
|
-
return Uint8ArrayToJson(plain);
|
|
3360
|
-
}
|
|
3361
|
-
};
|
|
3362
|
-
__name(CryptoEncoder, "CryptoEncoder");
|
|
3363
|
-
|
|
3364
|
-
// src/common/msg/messages.ts
|
|
3365
|
-
var createPromiseProxy = /* @__PURE__ */ __name((fn, opt, predefinedMethods = {}) => new Proxy(predefinedMethods, {
|
|
3366
|
-
get: (target, name) => {
|
|
3367
|
-
if (name in target)
|
|
3368
|
-
return target[name];
|
|
3369
|
-
return (...args) => fn(name, args, opt);
|
|
3370
|
-
}
|
|
3371
|
-
}), "createPromiseProxy");
|
|
3372
|
-
function useMessageHub(opt = {}) {
|
|
3373
|
-
let {
|
|
3374
|
-
name = uname("hub"),
|
|
3375
|
-
encoder = new JsonEncoder(),
|
|
3376
|
-
retryAfter = 1e3,
|
|
3377
|
-
ignoreUnhandled = true,
|
|
3378
|
-
logLevel = false
|
|
3379
|
-
} = opt;
|
|
3380
|
-
const log12 = Logger(name, logLevel);
|
|
3381
|
-
let handlers = {};
|
|
3382
|
-
let channel;
|
|
3383
|
-
let queue = [];
|
|
3384
|
-
let queueRetryTimer;
|
|
3385
|
-
let waitingForResponse = {};
|
|
3386
|
-
const dispose = /* @__PURE__ */ __name(() => {
|
|
3387
|
-
clearTimeout(queueRetryTimer);
|
|
3388
|
-
}, "dispose");
|
|
3389
|
-
const postNext = /* @__PURE__ */ __name(async () => {
|
|
3390
|
-
clearTimeout(queueRetryTimer);
|
|
3391
|
-
if (channel) {
|
|
3392
|
-
if (channel.isConnected) {
|
|
3393
|
-
while (queue.length) {
|
|
3394
|
-
let message = queue[0];
|
|
3395
|
-
try {
|
|
3396
|
-
channel.postMessage(await encoder.encode(message));
|
|
3397
|
-
queue.shift();
|
|
3398
|
-
} catch (err) {
|
|
3399
|
-
log12.warn("postMessage", err);
|
|
3400
|
-
break;
|
|
3401
|
-
}
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
if (queue.length > 0 && retryAfter > 0) {
|
|
3405
|
-
queueRetryTimer = setTimeout(postNext, retryAfter);
|
|
3406
|
-
}
|
|
3407
|
-
}
|
|
3408
|
-
}, "postNext");
|
|
3409
|
-
const postMessage = /* @__PURE__ */ __name(async (message) => {
|
|
3410
|
-
log12("enqueue postMessage", message);
|
|
3411
|
-
queue.push(message);
|
|
3412
|
-
await postNext();
|
|
3413
|
-
}, "postMessage");
|
|
3414
|
-
const connect = /* @__PURE__ */ __name(async (newChannel) => {
|
|
3415
|
-
channel = newChannel;
|
|
3416
|
-
channel.on("connect", postNext);
|
|
3417
|
-
channel.on("message", async (msg) => {
|
|
3418
|
-
log12("onmessage", typeof msg);
|
|
3419
|
-
const { name: name2, args, id, result, error } = await encoder.decode(msg.data);
|
|
3420
|
-
if (name2) {
|
|
3421
|
-
log12(`name ${name2} id ${id}`);
|
|
3422
|
-
try {
|
|
3423
|
-
if (handlers[name2] == null) {
|
|
3424
|
-
throw new Error(`handler for ${name2} was not found`);
|
|
3425
|
-
}
|
|
3426
|
-
let result2 = handlers[name2](...args);
|
|
3427
|
-
if (isPromise(result2))
|
|
3428
|
-
result2 = await result2;
|
|
3429
|
-
log12(`result ${result2}`);
|
|
3430
|
-
if (id) {
|
|
3431
|
-
postMessage({ id, result: result2 });
|
|
3432
|
-
}
|
|
3433
|
-
} catch (error2) {
|
|
3434
|
-
let err = error2 instanceof Error ? error2 : new Error(valueToString(error2));
|
|
3435
|
-
log12.warn("execution error", err.name);
|
|
3436
|
-
postMessage({
|
|
3437
|
-
id,
|
|
3438
|
-
error: {
|
|
3439
|
-
message: err.message,
|
|
3440
|
-
stack: err.stack,
|
|
3441
|
-
name: err.name
|
|
3442
|
-
}
|
|
3443
|
-
});
|
|
3444
|
-
}
|
|
3445
|
-
} else if (id) {
|
|
3446
|
-
log12(`response for id=${id}: result=${result}, error=${error}`);
|
|
3447
|
-
if (waitingForResponse[id] == null) {
|
|
3448
|
-
if (result === void 0) {
|
|
3449
|
-
log12(`skip response for ${id}`);
|
|
3450
|
-
} else {
|
|
3451
|
-
log12.warn(`no response hook for ${id}`);
|
|
3452
|
-
}
|
|
3453
|
-
} else {
|
|
3454
|
-
const [resolve6, reject] = waitingForResponse[id];
|
|
3455
|
-
if (resolve6 && reject) {
|
|
3456
|
-
delete waitingForResponse[id];
|
|
3457
|
-
if (error) {
|
|
3458
|
-
let err = new Error(error.message);
|
|
3459
|
-
err.stack = error.stack;
|
|
3460
|
-
err.name = error.name;
|
|
3461
|
-
log12.warn("reject", err.name);
|
|
3462
|
-
reject(err);
|
|
3463
|
-
} else {
|
|
3464
|
-
log12("resolve", result);
|
|
3465
|
-
resolve6(result);
|
|
3466
|
-
}
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
} else if (!ignoreUnhandled) {
|
|
3470
|
-
log12.warn("Unhandled message", msg);
|
|
3471
|
-
}
|
|
3472
|
-
});
|
|
3473
|
-
postNext();
|
|
3474
|
-
}, "connect");
|
|
3475
|
-
const fetchMessage = /* @__PURE__ */ __name(async (name2, args, opt2 = {}) => {
|
|
3476
|
-
const { timeout: timeout2 = 5e3 } = opt2;
|
|
3477
|
-
const id = uuid();
|
|
3478
|
-
postMessage({
|
|
3479
|
-
name: name2,
|
|
3480
|
-
args,
|
|
3481
|
-
id
|
|
3482
|
-
});
|
|
3483
|
-
return tryTimeout(
|
|
3484
|
-
new Promise(
|
|
3485
|
-
(resolve6, reject) => waitingForResponse[id] = [resolve6, reject]
|
|
3486
|
-
),
|
|
3487
|
-
timeout2
|
|
3488
|
-
);
|
|
3489
|
-
}, "fetchMessage");
|
|
3490
|
-
if (opt.channel) {
|
|
3491
|
-
connect(opt.channel);
|
|
3492
|
-
}
|
|
3493
|
-
return {
|
|
3494
|
-
dispose,
|
|
3495
|
-
connect,
|
|
3496
|
-
listen(newHandlers) {
|
|
3497
|
-
Object.assign(handlers, newHandlers);
|
|
3498
|
-
},
|
|
3499
|
-
send() {
|
|
3500
|
-
return createPromiseProxy(fetchMessage, {}, {
|
|
3501
|
-
options(perCallopt) {
|
|
3502
|
-
return createPromiseProxy(fetchMessage, { ...perCallopt });
|
|
3503
|
-
}
|
|
3504
|
-
});
|
|
3505
|
-
}
|
|
3506
|
-
};
|
|
3507
|
-
}
|
|
3508
|
-
__name(useMessageHub, "useMessageHub");
|
|
3509
|
-
|
|
3510
|
-
// src/common/msg/pubsub.ts
|
|
3511
|
-
var PubSub = class extends Emitter {
|
|
3512
|
-
constructor(opt) {
|
|
3513
|
-
super();
|
|
3514
|
-
this.publish = this.emit;
|
|
3515
|
-
this.subscribe = this.on;
|
|
3516
|
-
let { name, encoder = new JsonEncoder(), channel, debug = false } = opt;
|
|
3517
|
-
this.channel = channel;
|
|
3518
|
-
this.encoder = encoder;
|
|
3519
|
-
this.debug = debug;
|
|
3520
|
-
this.name = name ?? this.channel.id ?? uname("pubsub");
|
|
3521
|
-
this.log = Logger(`${this.shortId}`);
|
|
3522
|
-
if (this.debug) {
|
|
3523
|
-
this.channel.on("connect", () => {
|
|
3524
|
-
this.log("channel connected");
|
|
3525
|
-
});
|
|
3526
|
-
this.channel.on("disconnect", () => {
|
|
3527
|
-
this.log("channel disconnected");
|
|
3528
|
-
});
|
|
3529
|
-
}
|
|
3530
|
-
this.channel.on("message", async ({ data }) => {
|
|
3531
|
-
let info = await this.encoder.decode(data);
|
|
3532
|
-
if (this.debug)
|
|
3533
|
-
this.log(`channel message, event=${info == null ? void 0 : info.event}, info=`, info);
|
|
3534
|
-
else
|
|
3535
|
-
this.log(`channel message, event=${info == null ? void 0 : info.event}`);
|
|
3536
|
-
if (info) {
|
|
3537
|
-
const { event, args } = info;
|
|
3538
|
-
await this.emitSuper(event, ...args);
|
|
3539
|
-
}
|
|
3540
|
-
});
|
|
3541
|
-
}
|
|
3542
|
-
get shortId() {
|
|
3543
|
-
return this.name.substr(0, 6);
|
|
3544
|
-
}
|
|
3545
|
-
async emitSuper(event, ...args) {
|
|
3546
|
-
return await super.emit(event, ...args);
|
|
3547
|
-
}
|
|
3548
|
-
async emit(event, ...args) {
|
|
3549
|
-
try {
|
|
3550
|
-
if (this.debug)
|
|
3551
|
-
this.log(`emit(${String(event)})`, event);
|
|
3552
|
-
else
|
|
3553
|
-
this.log(`emit(${String(event)})`, args.length);
|
|
3554
|
-
if (!this.channel.isConnected) {
|
|
3555
|
-
this.log.warn("channel not connected");
|
|
3556
|
-
return false;
|
|
3557
|
-
}
|
|
3558
|
-
const data = await this.encoder.encode({ event, args });
|
|
3559
|
-
this.channel.postMessage(data);
|
|
3560
|
-
return true;
|
|
3561
|
-
} catch (err) {
|
|
3562
|
-
this.log.warn(`emit(${String(event)})`, err);
|
|
3563
|
-
}
|
|
3564
|
-
return false;
|
|
3565
|
-
}
|
|
3566
|
-
};
|
|
3567
|
-
__name(PubSub, "PubSub");
|
|
3568
|
-
function usePubSub(opt) {
|
|
3569
|
-
return new PubSub(opt);
|
|
3570
|
-
}
|
|
3571
|
-
__name(usePubSub, "usePubSub");
|
|
3572
|
-
|
|
3573
|
-
// src/common/msg/rpc.ts
|
|
3574
|
-
var rpcCounter = 1;
|
|
3575
|
-
var defaultSerialize = /* @__PURE__ */ __name((i) => i, "defaultSerialize");
|
|
3576
|
-
var defaultDeserialize = defaultSerialize;
|
|
3577
|
-
function useRPC(functions, options) {
|
|
3578
|
-
const {
|
|
3579
|
-
post,
|
|
3580
|
-
on,
|
|
3581
|
-
eventNames = [],
|
|
3582
|
-
serialize = defaultSerialize,
|
|
3583
|
-
deserialize = defaultDeserialize
|
|
3584
|
-
} = options;
|
|
3585
|
-
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
3586
|
-
on(async (data) => {
|
|
3587
|
-
const msg = deserialize(data);
|
|
3588
|
-
const [mode, args, id, method] = msg;
|
|
3589
|
-
if (mode === 1 /* request */ || mode === 2 /* event */) {
|
|
3590
|
-
let result, error;
|
|
3591
|
-
if (method != null) {
|
|
3592
|
-
try {
|
|
3593
|
-
result = await functions[method](...args);
|
|
3594
|
-
} catch (e) {
|
|
3595
|
-
error = String(e);
|
|
3596
|
-
}
|
|
3597
|
-
} else {
|
|
3598
|
-
error = "Method implementation missing";
|
|
3599
|
-
}
|
|
3600
|
-
if (mode === 1 /* request */ && id) {
|
|
3601
|
-
if (error) {
|
|
3602
|
-
post(serialize([4 /* reject */, error, id]));
|
|
3603
|
-
} else {
|
|
3604
|
-
post(serialize([3 /* resolve */, result, id]));
|
|
3605
|
-
}
|
|
3606
|
-
}
|
|
3607
|
-
} else if (id) {
|
|
3608
|
-
const promise = rpcPromiseMap.get(id);
|
|
3609
|
-
if (promise != null) {
|
|
3610
|
-
if (mode === 4 /* reject */)
|
|
3611
|
-
promise.reject(args);
|
|
3612
|
-
else
|
|
3613
|
-
promise.resolve(args);
|
|
3614
|
-
}
|
|
3615
|
-
rpcPromiseMap.delete(id);
|
|
3616
|
-
}
|
|
3617
|
-
});
|
|
3618
|
-
return new Proxy(
|
|
3619
|
-
{},
|
|
3620
|
-
{
|
|
3621
|
-
get(_, method) {
|
|
3622
|
-
const sendEvent = /* @__PURE__ */ __name((...args) => {
|
|
3623
|
-
post(serialize([2 /* event */, args, null, method]));
|
|
3624
|
-
}, "sendEvent");
|
|
3625
|
-
if (options.onlyEvents || eventNames.includes(method)) {
|
|
3626
|
-
sendEvent.asEvent = sendEvent;
|
|
3627
|
-
return sendEvent;
|
|
3628
|
-
}
|
|
3629
|
-
const sendCall = /* @__PURE__ */ __name((...args) => {
|
|
3630
|
-
return new Promise((resolve6, reject) => {
|
|
3631
|
-
const id = rpcCounter++;
|
|
3632
|
-
rpcPromiseMap.set(id, { resolve: resolve6, reject });
|
|
3633
|
-
post(serialize([1 /* request */, args, id, method]));
|
|
3634
|
-
});
|
|
3635
|
-
}, "sendCall");
|
|
3636
|
-
sendCall.asEvent = sendEvent;
|
|
3637
|
-
return sendCall;
|
|
3638
|
-
}
|
|
3639
|
-
}
|
|
3640
|
-
);
|
|
3641
|
-
}
|
|
3642
|
-
__name(useRPC, "useRPC");
|
|
3643
|
-
|
|
3644
|
-
// src/common/network.ts
|
|
3645
|
-
var log7 = Logger("network");
|
|
3646
|
-
var defaultOptions = {
|
|
3647
|
-
cache: "no-cache",
|
|
3648
|
-
redirect: "follow",
|
|
3649
|
-
headers: {}
|
|
3650
|
-
};
|
|
3651
|
-
function parseBasicAuth(url) {
|
|
3652
|
-
let m = /:\/\/([^@]*)@/gi.exec(url);
|
|
3653
|
-
if (m && m[1]) {
|
|
3654
|
-
let [username, password] = m[1].split(":", 2);
|
|
3655
|
-
return {
|
|
3656
|
-
url: url.replace(m[1] + "@", ""),
|
|
3657
|
-
username,
|
|
3658
|
-
password
|
|
3659
|
-
};
|
|
3660
|
-
}
|
|
3661
|
-
}
|
|
3662
|
-
__name(parseBasicAuth, "parseBasicAuth");
|
|
3663
|
-
async function fetchBasic(url, fetchOptions = {}, fetchFn = fetch) {
|
|
3664
|
-
try {
|
|
3665
|
-
if (isArray(fetchOptions)) {
|
|
3666
|
-
fetchOptions = deepMerge({}, ...arrayFlatten(fetchOptions));
|
|
3667
|
-
}
|
|
3668
|
-
let auth = parseBasicAuth(String(url));
|
|
3669
|
-
if (auth) {
|
|
3670
|
-
url = auth.url;
|
|
3671
|
-
fetchOptions = deepMerge(
|
|
3672
|
-
{},
|
|
3673
|
-
fetchOptions,
|
|
3674
|
-
fetchOptionsBasicAuth(auth.username, auth.password)
|
|
3675
|
-
);
|
|
3676
|
-
}
|
|
3677
|
-
if (fetchOptions.headers != null && !(fetchOptions.headers instanceof Headers)) {
|
|
3678
|
-
fetchOptions.headers = new Headers(fetchOptions.headers);
|
|
3679
|
-
}
|
|
3680
|
-
log7("fetch", url, fetchOptions);
|
|
3681
|
-
const response = await fetchFn(String(url), fetchOptions);
|
|
3682
|
-
if (response.status < 400) {
|
|
3683
|
-
return response;
|
|
3684
|
-
}
|
|
3685
|
-
try {
|
|
3686
|
-
log7.warn(
|
|
3687
|
-
`Fetch of ${url} with ${fetchOptions} returned status=${response.status}`
|
|
3688
|
-
);
|
|
3689
|
-
log7.warn(`Response: ${await response.text()}`);
|
|
3690
|
-
} catch (err) {
|
|
3691
|
-
log7.error("Exception:", err);
|
|
3692
|
-
}
|
|
3693
|
-
} catch (err) {
|
|
3694
|
-
log7.error("fetchBasic", err);
|
|
3695
|
-
}
|
|
3696
|
-
}
|
|
3697
|
-
__name(fetchBasic, "fetchBasic");
|
|
3698
|
-
async function fetchJson(url, fetchOptions = {}, fetchFn = fetch) {
|
|
3699
|
-
try {
|
|
3700
|
-
let res = await fetchBasic(
|
|
3701
|
-
url,
|
|
3702
|
-
[
|
|
3703
|
-
{
|
|
3704
|
-
method: "GET",
|
|
3705
|
-
headers: {
|
|
3706
|
-
Accept: "application/json"
|
|
3707
|
-
}
|
|
3708
|
-
},
|
|
3709
|
-
fetchOptions
|
|
3710
|
-
],
|
|
3711
|
-
fetchFn
|
|
3712
|
-
);
|
|
3713
|
-
if (res) {
|
|
3714
|
-
return await res.json();
|
|
3715
|
-
}
|
|
3716
|
-
} catch (err) {
|
|
3717
|
-
log7.error("fetchJSON error:", err);
|
|
3718
|
-
}
|
|
3719
|
-
}
|
|
3720
|
-
__name(fetchJson, "fetchJson");
|
|
3721
|
-
async function fetchText(url, fetchOptions = {}, fetchFn = fetch) {
|
|
3722
|
-
try {
|
|
3723
|
-
let res = await fetchBasic(
|
|
3724
|
-
url,
|
|
3725
|
-
[defaultOptions, { method: "GET" }, fetchOptions],
|
|
3726
|
-
fetchFn
|
|
3727
|
-
);
|
|
3728
|
-
if (res) {
|
|
3729
|
-
return await res.text();
|
|
3730
|
-
}
|
|
3731
|
-
} catch (err) {
|
|
3732
|
-
log7.error("fetchHTML error:", err);
|
|
3733
|
-
}
|
|
3734
|
-
}
|
|
3735
|
-
__name(fetchText, "fetchText");
|
|
3736
|
-
function fetchOptionsFormURLEncoded(data, method = "POST") {
|
|
3737
|
-
return {
|
|
3738
|
-
method,
|
|
3739
|
-
...defaultOptions,
|
|
3740
|
-
headers: {
|
|
3741
|
-
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
|
|
3742
|
-
},
|
|
3743
|
-
body: encodeQuery(data)
|
|
3744
|
-
};
|
|
3745
|
-
}
|
|
3746
|
-
__name(fetchOptionsFormURLEncoded, "fetchOptionsFormURLEncoded");
|
|
3747
|
-
function fetchOptionsJson(data, method = "POST") {
|
|
3748
|
-
return {
|
|
3749
|
-
method,
|
|
3750
|
-
...defaultOptions,
|
|
3751
|
-
headers: {
|
|
3752
|
-
"Content-Type": "application/json; charset=utf-8"
|
|
3753
|
-
},
|
|
3754
|
-
body: JSON.stringify(data)
|
|
3755
|
-
};
|
|
3756
|
-
}
|
|
3757
|
-
__name(fetchOptionsJson, "fetchOptionsJson");
|
|
3758
|
-
function fetchOptionsBasicAuth(username, password) {
|
|
3759
|
-
return {
|
|
3760
|
-
headers: {
|
|
3761
|
-
Authorization: "Basic " + toBase64(username + ":" + password)
|
|
3762
|
-
}
|
|
3763
|
-
};
|
|
3764
|
-
}
|
|
3765
|
-
__name(fetchOptionsBasicAuth, "fetchOptionsBasicAuth");
|
|
3766
|
-
|
|
3767
|
-
// src/common/platform.ts
|
|
3768
|
-
function getWindow() {
|
|
3769
|
-
if (typeof window !== "undefined")
|
|
3770
|
-
return window;
|
|
3771
|
-
}
|
|
3772
|
-
__name(getWindow, "getWindow");
|
|
3773
|
-
function getNavigator() {
|
|
3774
|
-
if (typeof navigator !== "undefined")
|
|
3775
|
-
return navigator;
|
|
3776
|
-
}
|
|
3777
|
-
__name(getNavigator, "getNavigator");
|
|
3778
|
-
function getGlobal() {
|
|
3779
|
-
return getWindow() ?? typeof WorkerGlobalScope !== "undefined" ? self : typeof global !== "undefined" ? global : Function("return this;")();
|
|
3780
|
-
}
|
|
3781
|
-
__name(getGlobal, "getGlobal");
|
|
3782
|
-
var _navigator = getNavigator();
|
|
3783
|
-
var _window = getWindow();
|
|
3784
|
-
function detect(info = {
|
|
3785
|
-
ios: false,
|
|
3786
|
-
macos: false,
|
|
3787
|
-
windows: false,
|
|
3788
|
-
beaker: false,
|
|
3789
|
-
electron: false,
|
|
3790
|
-
wkwebview: false,
|
|
3791
|
-
pwa: false,
|
|
3792
|
-
pwaInstalled: false,
|
|
3793
|
-
browser: false,
|
|
3794
|
-
node: false,
|
|
3795
|
-
worker: false,
|
|
3796
|
-
test: false,
|
|
3797
|
-
jest: false,
|
|
3798
|
-
macosNative: false,
|
|
3799
|
-
iosNative: false,
|
|
3800
|
-
appleNative: false,
|
|
3801
|
-
touch: false
|
|
3802
|
-
}) {
|
|
3803
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
3804
|
-
info.ios = ((_a2 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _a2.match(/(iPhone|iPod|iPad)/i)) != null;
|
|
3805
|
-
info.macos = !!((_b2 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _b2.startsWith("Mac"));
|
|
3806
|
-
info.windows = !!((_c = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _c.startsWith("Win"));
|
|
3807
|
-
info.beaker = (_window == null ? void 0 : _window["beaker"]) != null;
|
|
3808
|
-
info.electron = (((_e = (_d = _navigator == null ? void 0 : _navigator.userAgent) == null ? void 0 : _d.toLowerCase()) == null ? void 0 : _e.indexOf(" electron/")) || -1) > -1 && !info.beaker;
|
|
3809
|
-
info.wkwebview = ((_f = _window == null ? void 0 : _window.webkit) == null ? void 0 : _f["messageHandlers"]) != null;
|
|
3810
|
-
info.pwa = (_navigator == null ? void 0 : _navigator.serviceWorker) != null;
|
|
3811
|
-
info.pwaInstalled = (_navigator == null ? void 0 : _navigator.standalone) || ((_h = (_g = _window == null ? void 0 : _window.matchMedia) == null ? void 0 : _g.call(_window, "(display-mode: standalone)")) == null ? void 0 : _h.matches);
|
|
3812
|
-
info.node = typeof process !== "undefined" && ((_i = process == null ? void 0 : process.release) == null ? void 0 : _i.name) === "node";
|
|
3813
|
-
info.browser = !info.electron && !info.wkwebview && !info.node;
|
|
3814
|
-
info.worker = typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope;
|
|
3815
|
-
info.jest = typeof jest !== "undefined" || typeof vitest !== "undefined";
|
|
3816
|
-
info.test = info.jest;
|
|
3817
|
-
info.macosNative = info.wkwebview && info.macos;
|
|
3818
|
-
info.iosNative = info.wkwebview && info.ios;
|
|
3819
|
-
info.appleNative = info.wkwebview;
|
|
3820
|
-
info.touch = _window && "ontouchstart" in _window || ((_navigator == null ? void 0 : _navigator.maxTouchPoints) || 0) > 1 || (_navigator == null ? void 0 : _navigator.msPointerEnabled) && (_window == null ? void 0 : _window.MSGesture) || (_window == null ? void 0 : _window.DocumentTouch) && document instanceof DocumentTouch;
|
|
3821
|
-
return info;
|
|
3822
|
-
}
|
|
3823
|
-
__name(detect, "detect");
|
|
3824
|
-
var isBrowser = /* @__PURE__ */ __name(() => typeof window !== "undefined" && globalThis === window, "isBrowser");
|
|
3825
|
-
var platform = detect();
|
|
3826
|
-
function useExitHandler(handler) {
|
|
3827
|
-
if (isBrowser()) {
|
|
3828
|
-
window.addEventListener("beforeunload", handler);
|
|
3829
|
-
} else if (typeof process !== "undefined") {
|
|
3830
|
-
process.on("exit", () => handler);
|
|
3831
|
-
}
|
|
3832
|
-
}
|
|
3833
|
-
__name(useExitHandler, "useExitHandler");
|
|
3834
|
-
|
|
3835
|
-
// src/common/storage/memstorage.ts
|
|
3836
|
-
Logger("zeed:memstorage");
|
|
3837
|
-
var MemStorage = class {
|
|
3838
|
-
constructor(opt = {}) {
|
|
3839
|
-
this.store = {};
|
|
3840
|
-
}
|
|
3841
|
-
setItem(key, value) {
|
|
3842
|
-
this.store[key] = cloneObject(value);
|
|
3843
|
-
}
|
|
3844
|
-
getItem(key) {
|
|
3845
|
-
if (this.store.hasOwnProperty(key)) {
|
|
3846
|
-
return cloneObject(this.store[key]);
|
|
3847
|
-
}
|
|
3848
|
-
}
|
|
3849
|
-
removeItem(key) {
|
|
3850
|
-
delete this.store[key];
|
|
3851
|
-
}
|
|
3852
|
-
clear() {
|
|
3853
|
-
this.store = {};
|
|
3854
|
-
}
|
|
3855
|
-
allKeys() {
|
|
3856
|
-
return Object.keys(this.store);
|
|
3857
|
-
}
|
|
3858
|
-
};
|
|
3859
|
-
__name(MemStorage, "MemStorage");
|
|
3860
|
-
|
|
3861
|
-
// src/node/args.ts
|
|
3862
|
-
function parseArgs(config = {}) {
|
|
3863
|
-
const {
|
|
3864
|
-
args = process.argv.slice(1),
|
|
3865
|
-
alias = {},
|
|
3866
|
-
normalize: normalize2 = toCamelCase,
|
|
3867
|
-
booleanArgs = [],
|
|
3868
|
-
listArgs = [],
|
|
3869
|
-
numberArgs = []
|
|
3870
|
-
} = config;
|
|
3871
|
-
let nameToAlias = Object.entries(alias).reduce((map, curr) => {
|
|
3872
|
-
let [name, values] = curr;
|
|
3873
|
-
if (typeof values === "string")
|
|
3874
|
-
values = [values];
|
|
3875
|
-
for (let value of values) {
|
|
3876
|
-
map[normalize2(value)] = normalize2(name);
|
|
3877
|
-
}
|
|
3878
|
-
return map;
|
|
3879
|
-
}, {});
|
|
3880
|
-
let opts = {
|
|
3881
|
-
_: []
|
|
3882
|
-
};
|
|
3883
|
-
function setOpt(name, value) {
|
|
3884
|
-
if (opts[name] == null) {
|
|
3885
|
-
opts[name] = value;
|
|
3886
|
-
} else if (typeof opts[name] === "boolean") {
|
|
3887
|
-
opts[name] = value;
|
|
3888
|
-
} else if (Array.isArray(opts[name])) {
|
|
3889
|
-
opts[name].push(value);
|
|
3890
|
-
} else {
|
|
3891
|
-
opts[name] = [opts[name], value];
|
|
3892
|
-
}
|
|
3893
|
-
}
|
|
3894
|
-
__name(setOpt, "setOpt");
|
|
3895
|
-
let argList = [...args];
|
|
3896
|
-
let arg;
|
|
3897
|
-
while (arg = argList.shift()) {
|
|
3898
|
-
let value;
|
|
3899
|
-
if (/^--?/.test(arg)) {
|
|
3900
|
-
let key = arg.replace(/^--?/, "");
|
|
3901
|
-
if (arg.includes("=")) {
|
|
3902
|
-
let [name, valuePart] = key.split("=", 2);
|
|
3903
|
-
key = name.trim();
|
|
3904
|
-
value = valuePart.trim();
|
|
3905
|
-
}
|
|
3906
|
-
key = normalize2(key);
|
|
3907
|
-
key = nameToAlias[key] ?? key;
|
|
3908
|
-
if (booleanArgs.includes(key)) {
|
|
3909
|
-
setOpt(key, true);
|
|
3910
|
-
} else {
|
|
3911
|
-
value = value ?? argList.shift() ?? "";
|
|
3912
|
-
if (numberArgs.includes(key)) {
|
|
3913
|
-
value = Number(value ?? 0);
|
|
3914
|
-
}
|
|
3915
|
-
if (listArgs.includes(key)) {
|
|
3916
|
-
if (Array.isArray(opts[key])) {
|
|
3917
|
-
opts[key].push(value);
|
|
3918
|
-
} else {
|
|
3919
|
-
opts[key] = [value];
|
|
3920
|
-
}
|
|
3921
|
-
} else {
|
|
3922
|
-
setOpt(key, value);
|
|
3923
|
-
}
|
|
3924
|
-
}
|
|
3925
|
-
} else {
|
|
3926
|
-
opts._.push(arg);
|
|
3927
|
-
}
|
|
3928
|
-
}
|
|
3929
|
-
return opts;
|
|
3930
|
-
}
|
|
3931
|
-
__name(parseArgs, "parseArgs");
|
|
3932
|
-
|
|
3933
|
-
// src/node/clipboard.ts
|
|
3934
|
-
var import_child_process = require("child_process");
|
|
3935
|
-
function pbcopy(data) {
|
|
3936
|
-
return new Promise(async (resolve6, reject) => {
|
|
3937
|
-
const proc = (0, import_child_process.spawn)("pbcopy");
|
|
3938
|
-
proc.on("error", (err) => reject(err));
|
|
3939
|
-
proc.on("close", () => resolve6(data));
|
|
3940
|
-
proc.stdin.write(data);
|
|
3941
|
-
proc.stdin.end();
|
|
3942
|
-
});
|
|
3943
|
-
}
|
|
3944
|
-
__name(pbcopy, "pbcopy");
|
|
3945
|
-
|
|
3946
|
-
// src/node/env.ts
|
|
3947
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
3948
|
-
var import_path = require("path");
|
|
3949
|
-
var log9 = Logger("zeed:env");
|
|
3950
|
-
var NEWLINE = "\n";
|
|
3951
|
-
var RE_INI_KEY_VAL = /^\s*([\w_.-]+)\s*=\s*(.*)?\s*$/;
|
|
3952
|
-
var RE_NEWLINES = /\\n/g;
|
|
3953
|
-
var NEWLINES_MATCH = /\n|\r|\r\n/;
|
|
3954
|
-
function parse2(src, options = {}) {
|
|
3955
|
-
let obj = {};
|
|
3956
|
-
String(src).split(NEWLINES_MATCH).forEach(function(line, idx) {
|
|
3957
|
-
const keyValueArr = line.match(RE_INI_KEY_VAL);
|
|
3958
|
-
if (keyValueArr != null) {
|
|
3959
|
-
const key = keyValueArr[1];
|
|
3960
|
-
let val = keyValueArr[2] || "";
|
|
3961
|
-
const end = val.length - 1;
|
|
3962
|
-
const isDoubleQuoted = val[0] === '"' && val[end] === '"';
|
|
3963
|
-
const isSingleQuoted = val[0] === "'" && val[end] === "'";
|
|
3964
|
-
if (isSingleQuoted || isDoubleQuoted) {
|
|
3965
|
-
val = val.substring(1, end);
|
|
3966
|
-
if (isDoubleQuoted) {
|
|
3967
|
-
val = val.replace(RE_NEWLINES, NEWLINE);
|
|
3968
|
-
}
|
|
3969
|
-
} else {
|
|
3970
|
-
val = val.trim();
|
|
3971
|
-
}
|
|
3972
|
-
obj[key] = val;
|
|
3973
|
-
} else {
|
|
3974
|
-
log9.debug(
|
|
3975
|
-
`did not match key and value when parsing line ${idx + 1}: ${line}`
|
|
3976
|
-
);
|
|
3977
|
-
}
|
|
3978
|
-
});
|
|
3979
|
-
return obj;
|
|
3980
|
-
}
|
|
3981
|
-
__name(parse2, "parse");
|
|
3982
|
-
function stringToPath(value, defaultValue = ".") {
|
|
3983
|
-
return (0, import_path.resolve)(process.cwd(), value ?? defaultValue);
|
|
3984
|
-
}
|
|
3985
|
-
__name(stringToPath, "stringToPath");
|
|
3986
|
-
function valueToPath(value, defaultValue = "") {
|
|
3987
|
-
if (value == null)
|
|
3988
|
-
value = defaultValue;
|
|
3989
|
-
return stringToPath(String(value).trim(), defaultValue);
|
|
3990
|
-
}
|
|
3991
|
-
__name(valueToPath, "valueToPath");
|
|
3992
|
-
var toPath = valueToPath;
|
|
3993
|
-
function setupEnv(options = {}) {
|
|
3994
|
-
const dotenvPath = (options == null ? void 0 : options.path) ?? toPath((options == null ? void 0 : options.filename) ?? ".env");
|
|
3995
|
-
const encoding = (options == null ? void 0 : options.encoding) ?? "utf8";
|
|
3996
|
-
const debug = (options == null ? void 0 : options.debug) || false;
|
|
3997
|
-
if (debug !== true)
|
|
3998
|
-
log9.level = Infinity /* off */;
|
|
3999
|
-
try {
|
|
4000
|
-
const parsedEnv = import_fs.default.existsSync(dotenvPath) ? parse2(import_fs.default.readFileSync(dotenvPath, { encoding }), { debug }) : {};
|
|
4001
|
-
const parsedEnvLocal = import_fs.default.existsSync(dotenvPath + ".local") ? parse2(import_fs.default.readFileSync(dotenvPath + ".local", { encoding }), { debug }) : {};
|
|
4002
|
-
const parsed = Object.assign(
|
|
4003
|
-
{},
|
|
4004
|
-
parsedEnv,
|
|
4005
|
-
parsedEnvLocal
|
|
4006
|
-
);
|
|
4007
|
-
let env = (options == null ? void 0 : options.env) ?? process.env;
|
|
4008
|
-
Object.entries(parsed).forEach(([key, value]) => {
|
|
4009
|
-
if (typeof (options == null ? void 0 : options.prefix) === "string") {
|
|
4010
|
-
key = (options == null ? void 0 : options.prefix) + key;
|
|
4011
|
-
}
|
|
4012
|
-
if (!Object.prototype.hasOwnProperty.call(env, key)) {
|
|
4013
|
-
if (value != null) {
|
|
4014
|
-
log9.info(`set env.${key} = ${value}`);
|
|
4015
|
-
env[key] = value;
|
|
4016
|
-
}
|
|
4017
|
-
} else {
|
|
4018
|
-
log9.debug(`"${key}" is already defined and will not be overwritten`);
|
|
4019
|
-
}
|
|
4020
|
-
});
|
|
4021
|
-
return { parsed };
|
|
4022
|
-
} catch (e) {
|
|
4023
|
-
log9.error(e);
|
|
4024
|
-
return { error: e };
|
|
4025
|
-
}
|
|
4026
|
-
}
|
|
4027
|
-
__name(setupEnv, "setupEnv");
|
|
4028
|
-
|
|
4029
|
-
// src/node/filestorage.ts
|
|
4030
|
-
var import_fs2 = require("fs");
|
|
4031
|
-
var import_path2 = require("path");
|
|
4032
|
-
var log10 = Logger("zeed:filestorage");
|
|
4033
|
-
var FileStorage = class {
|
|
4034
|
-
constructor(opt = {}) {
|
|
4035
|
-
this.store = {};
|
|
4036
|
-
this.fileKeys = void 0;
|
|
4037
|
-
this.pretty = false;
|
|
4038
|
-
this.dirname = (0, import_path2.resolve)(process.cwd(), opt.path || ".fileStorage");
|
|
4039
|
-
this.pretty = !!opt.pretty;
|
|
4040
|
-
this.extension = opt.extension ?? ".json";
|
|
4041
|
-
if (opt.extension && !this.extension.startsWith(".")) {
|
|
4042
|
-
this.extension = "." + this.extension;
|
|
4043
|
-
}
|
|
4044
|
-
this.extensionLength = this.extension.length;
|
|
4045
|
-
this.objectToString = opt.objectToString ?? ((data) => {
|
|
4046
|
-
return this.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
4047
|
-
});
|
|
4048
|
-
this.objectFromString = opt.objectFromString ?? ((data) => {
|
|
4049
|
-
try {
|
|
4050
|
-
return JSON.parse(data);
|
|
4051
|
-
} catch (err) {
|
|
4052
|
-
log10.warn(`fileStorage parse error '${err}' in`, data);
|
|
4053
|
-
}
|
|
4054
|
-
});
|
|
4055
|
-
this.keyToFilename = opt.keyToFilename ?? toValidFilename;
|
|
4056
|
-
}
|
|
4057
|
-
setItem(key, value) {
|
|
4058
|
-
this.store[key] = cloneObject(value);
|
|
4059
|
-
try {
|
|
4060
|
-
const data = this.objectToString(value);
|
|
4061
|
-
const path = this.getPath(key);
|
|
4062
|
-
(0, import_fs2.mkdirSync)((0, import_path2.dirname)(path), { recursive: true });
|
|
4063
|
-
(0, import_fs2.writeFileSync)(path, data, "utf8");
|
|
4064
|
-
} catch (err) {
|
|
4065
|
-
log10.error("setItem error", err);
|
|
4066
|
-
}
|
|
4067
|
-
}
|
|
4068
|
-
getPath(key) {
|
|
4069
|
-
return (0, import_path2.resolve)(this.dirname, this.keyToFilename(key) + this.extension);
|
|
4070
|
-
}
|
|
4071
|
-
getBuffer(key) {
|
|
4072
|
-
const path = this.getPath(key);
|
|
4073
|
-
return Buffer.from((0, import_fs2.readFileSync)(path));
|
|
4074
|
-
}
|
|
4075
|
-
getItem(key) {
|
|
4076
|
-
let value = this.store[key];
|
|
4077
|
-
if (value === null)
|
|
4078
|
-
return;
|
|
4079
|
-
if (value != null) {
|
|
4080
|
-
return cloneObject(value);
|
|
4081
|
-
}
|
|
4082
|
-
try {
|
|
4083
|
-
const path = this.getPath(key);
|
|
4084
|
-
const data = (0, import_fs2.readFileSync)(path, "utf8");
|
|
4085
|
-
if (data != null) {
|
|
4086
|
-
const value2 = this.objectFromString(data);
|
|
4087
|
-
this.store[key] = value2;
|
|
4088
|
-
return value2;
|
|
4089
|
-
}
|
|
4090
|
-
} catch (err) {
|
|
4091
|
-
log10.warn("getItem error", err);
|
|
4092
|
-
this.store[key] = null;
|
|
4093
|
-
}
|
|
4094
|
-
}
|
|
4095
|
-
removeItem(key) {
|
|
4096
|
-
delete this.store[key];
|
|
4097
|
-
if (this.fileKeys != null) {
|
|
4098
|
-
const index = this.fileKeys.indexOf(key);
|
|
4099
|
-
if (index !== -1) {
|
|
4100
|
-
this.fileKeys.splice(index, 1);
|
|
4101
|
-
}
|
|
4102
|
-
}
|
|
4103
|
-
try {
|
|
4104
|
-
const path = this.getPath(key);
|
|
4105
|
-
(0, import_fs2.unlinkSync)(path);
|
|
4106
|
-
} catch (err) {
|
|
4107
|
-
}
|
|
4108
|
-
}
|
|
4109
|
-
clear() {
|
|
4110
|
-
this.fileKeys = [];
|
|
4111
|
-
this.store = {};
|
|
4112
|
-
(0, import_fs2.rmSync)(this.dirname, { recursive: true, force: true });
|
|
4113
|
-
}
|
|
4114
|
-
allKeys() {
|
|
4115
|
-
if (this.fileKeys == null) {
|
|
4116
|
-
try {
|
|
4117
|
-
this.fileKeys = (0, import_fs2.readdirSync)(this.dirname, { withFileTypes: true }).filter(
|
|
4118
|
-
(item) => !item.isDirectory() && item.name.endsWith(this.extension)
|
|
4119
|
-
).map((item) => item.name.slice(0, -this.extensionLength)) || [];
|
|
4120
|
-
} catch (err) {
|
|
4121
|
-
}
|
|
4122
|
-
}
|
|
4123
|
-
let keys = [...this.fileKeys || []];
|
|
4124
|
-
for (let key of Object.keys(this.store)) {
|
|
4125
|
-
if (!keys.includes(key)) {
|
|
4126
|
-
keys.push(key);
|
|
4127
|
-
}
|
|
4128
|
-
}
|
|
4129
|
-
keys.sort();
|
|
4130
|
-
return keys;
|
|
4131
|
-
}
|
|
4132
|
-
};
|
|
4133
|
-
__name(FileStorage, "FileStorage");
|
|
4134
|
-
|
|
4135
|
-
// src/node/fs.ts
|
|
4136
|
-
var import_promises = require("fs/promises");
|
|
4137
|
-
var import_node_path = require("path");
|
|
4138
|
-
function toHumanReadableFilePath(path) {
|
|
4139
|
-
const p = (0, import_node_path.normalize)(path);
|
|
4140
|
-
const h = process.env.HOME;
|
|
4141
|
-
if (h && p.startsWith(h)) {
|
|
4142
|
-
return "~" + p.slice(h.length);
|
|
4143
|
-
}
|
|
4144
|
-
return p;
|
|
4145
|
-
}
|
|
4146
|
-
__name(toHumanReadableFilePath, "toHumanReadableFilePath");
|
|
4147
|
-
async function exists(path) {
|
|
4148
|
-
try {
|
|
4149
|
-
await (0, import_promises.stat)(path);
|
|
4150
|
-
} catch (err) {
|
|
4151
|
-
return false;
|
|
4152
|
-
}
|
|
4153
|
-
return true;
|
|
4154
|
-
}
|
|
4155
|
-
__name(exists, "exists");
|
|
4156
|
-
async function ensureFolder(...parts) {
|
|
4157
|
-
const path = (0, import_node_path.join)(...parts);
|
|
4158
|
-
if (!await exists(path)) {
|
|
4159
|
-
await (0, import_promises.mkdir)(path, { recursive: true });
|
|
4160
|
-
}
|
|
4161
|
-
return path;
|
|
4162
|
-
}
|
|
4163
|
-
__name(ensureFolder, "ensureFolder");
|
|
4164
|
-
async function removeFolder(...parts) {
|
|
4165
|
-
const path = (0, import_node_path.join)(...parts);
|
|
4166
|
-
if (await exists(path)) {
|
|
4167
|
-
await (0, import_promises.rm)(path, { recursive: true });
|
|
4168
|
-
}
|
|
4169
|
-
return path;
|
|
4170
|
-
}
|
|
4171
|
-
__name(removeFolder, "removeFolder");
|
|
4172
|
-
async function readText(...parts) {
|
|
4173
|
-
const path = (0, import_node_path.join)(...parts);
|
|
4174
|
-
if (await exists(path)) {
|
|
4175
|
-
return await (0, import_promises.readFile)(path, "utf-8");
|
|
4176
|
-
}
|
|
4177
|
-
}
|
|
4178
|
-
__name(readText, "readText");
|
|
4179
|
-
async function writeText(path, content) {
|
|
4180
|
-
await (0, import_promises.writeFile)(path, content, "utf-8");
|
|
4181
|
-
}
|
|
4182
|
-
__name(writeText, "writeText");
|
|
4183
|
-
|
|
4184
|
-
// src/node/log-file.ts
|
|
4185
|
-
var import_fs3 = require("fs");
|
|
4186
|
-
var import_path4 = require("path");
|
|
4187
|
-
var namespaces = {};
|
|
4188
|
-
function LoggerFileHandler(path, opt = {}) {
|
|
4189
|
-
const { level = -1 /* all */, filter = "*" } = opt;
|
|
4190
|
-
path = (0, import_path4.resolve)(process.cwd(), path);
|
|
4191
|
-
(0, import_fs3.mkdirSync)((0, import_path4.dirname)(path), { recursive: true });
|
|
4192
|
-
var stream = (0, import_fs3.createWriteStream)(path, { flags: "a" });
|
|
4193
|
-
const matchesNamespace = useNamespaceFilter(filter);
|
|
4194
|
-
const matchesLevel = useLevelFilter(level);
|
|
4195
|
-
return (msg) => {
|
|
4196
|
-
if (!matchesLevel(msg.level))
|
|
4197
|
-
return;
|
|
4198
|
-
if (!matchesNamespace(msg.name))
|
|
4199
|
-
return;
|
|
4200
|
-
const time2 = new Date().toISOString();
|
|
4201
|
-
let name = msg.name || "";
|
|
4202
|
-
let ninfo = namespaces[name || ""];
|
|
4203
|
-
if (ninfo == null) {
|
|
4204
|
-
namespaces[name] = ninfo;
|
|
4205
|
-
}
|
|
4206
|
-
let args = [
|
|
4207
|
-
`[${name || "*"}]`,
|
|
4208
|
-
renderMessages(msg.messages, { pretty: false })
|
|
4209
|
-
];
|
|
4210
|
-
function write(...args2) {
|
|
4211
|
-
stream.write(args2.join(" ") + "\n");
|
|
4212
|
-
}
|
|
4213
|
-
__name(write, "write");
|
|
4214
|
-
switch (msg.level) {
|
|
4215
|
-
case 1 /* info */:
|
|
4216
|
-
write(time2, `I|* `, ...args);
|
|
4217
|
-
break;
|
|
4218
|
-
case 2 /* warn */:
|
|
4219
|
-
write(time2, `W|** `, ...args);
|
|
4220
|
-
break;
|
|
4221
|
-
case 3 /* error */:
|
|
4222
|
-
write(time2, `E|***`, ...args);
|
|
4223
|
-
break;
|
|
4224
|
-
default:
|
|
4225
|
-
write(time2, `D| `, ...args);
|
|
4226
|
-
break;
|
|
4227
|
-
}
|
|
4228
|
-
};
|
|
4229
|
-
}
|
|
4230
|
-
__name(LoggerFileHandler, "LoggerFileHandler");
|
|
4231
|
-
|
|
4232
|
-
// src/node/log-node.ts
|
|
4233
|
-
var import_tty = __toESM(require("tty"), 1);
|
|
4234
|
-
|
|
4235
|
-
// src/node/log-util.ts
|
|
4236
|
-
var import_path5 = require("path");
|
|
4237
|
-
function getStackLlocationList(stack) {
|
|
4238
|
-
var _a2, _b2;
|
|
4239
|
-
if (typeof stack !== "string")
|
|
4240
|
-
return [];
|
|
4241
|
-
return ((_b2 = (_a2 = stack == null ? void 0 : stack.split("\n")) == null ? void 0 : _a2.map((rawLine) => {
|
|
4242
|
-
let m = rawLine.match(
|
|
4243
|
-
/^\s+at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/
|
|
4244
|
-
);
|
|
4245
|
-
if (m) {
|
|
4246
|
-
let line = m[3] || m[2] || m[4];
|
|
4247
|
-
if (line.endsWith(")"))
|
|
4248
|
-
line = line.slice(0, -1);
|
|
4249
|
-
return line;
|
|
4250
|
-
}
|
|
4251
|
-
})) == null ? void 0 : _b2.filter((v) => v != null)) || [];
|
|
4252
|
-
}
|
|
4253
|
-
__name(getStackLlocationList, "getStackLlocationList");
|
|
4254
|
-
var cwd = (0, import_path5.resolve)(process.cwd());
|
|
4255
|
-
var _a, _b;
|
|
4256
|
-
var home = ((_a = process.env) == null ? void 0 : _a.HOME) ? (0, import_path5.resolve)((_b = process.env) == null ? void 0 : _b.HOME) : "";
|
|
4257
|
-
function pathStripCwd(path) {
|
|
4258
|
-
if (path.includes("/node_modules/")) {
|
|
4259
|
-
return "";
|
|
4260
|
-
}
|
|
4261
|
-
const fileURL = "file://";
|
|
4262
|
-
if (path.startsWith(fileURL)) {
|
|
4263
|
-
return path.substr(fileURL.length);
|
|
4264
|
-
}
|
|
4265
|
-
if (cwd && path.startsWith(cwd)) {
|
|
4266
|
-
return path.substr(cwd.length + 1);
|
|
4267
|
-
}
|
|
4268
|
-
if (home && path.startsWith(home)) {
|
|
4269
|
-
path = "~/" + path.substr(home.length + 1);
|
|
4270
|
-
}
|
|
4271
|
-
return path;
|
|
4272
|
-
}
|
|
4273
|
-
__name(pathStripCwd, "pathStripCwd");
|
|
4274
|
-
function extractFileInfo(stackLine) {
|
|
4275
|
-
let m = stackLine.match(/^\s*at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/);
|
|
4276
|
-
if (m) {
|
|
4277
|
-
let line = m[3] || m[2] || m[4];
|
|
4278
|
-
if (line.endsWith(")"))
|
|
4279
|
-
line = line.slice(0, -1);
|
|
4280
|
-
return line;
|
|
4281
|
-
}
|
|
4282
|
-
return "";
|
|
4283
|
-
}
|
|
4284
|
-
__name(extractFileInfo, "extractFileInfo");
|
|
4285
|
-
function getSourceLocation(level = 2, stripCwd = true) {
|
|
4286
|
-
var _a2;
|
|
4287
|
-
let stack = new Error().stack || "";
|
|
4288
|
-
let line = (_a2 = getStackLlocationList(stack)) == null ? void 0 : _a2[level];
|
|
4289
|
-
if (line && stripCwd) {
|
|
4290
|
-
line = pathStripCwd(line);
|
|
4291
|
-
}
|
|
4292
|
-
return line || "";
|
|
4293
|
-
}
|
|
4294
|
-
__name(getSourceLocation, "getSourceLocation");
|
|
4295
|
-
function getStack() {
|
|
4296
|
-
return new Error().stack || "";
|
|
4297
|
-
}
|
|
4298
|
-
__name(getStack, "getStack");
|
|
4299
|
-
function getSourceLocationByPrecedingPattern(patterns, stripCwd = true) {
|
|
4300
|
-
let line = "";
|
|
4301
|
-
let stack = new Error().stack || "";
|
|
4302
|
-
if (typeof stack === "string") {
|
|
4303
|
-
const lines = stack.split("\n").map((l) => l.trim());
|
|
4304
|
-
const index = lines.findIndex((l) => patterns.some((p) => l.startsWith(p)));
|
|
4305
|
-
line = lines[index + 1];
|
|
4306
|
-
if (line) {
|
|
4307
|
-
line = extractFileInfo(line);
|
|
4308
|
-
}
|
|
4309
|
-
if (line && stripCwd) {
|
|
4310
|
-
line = pathStripCwd(line);
|
|
4311
|
-
}
|
|
4312
|
-
}
|
|
4313
|
-
return line;
|
|
4314
|
-
}
|
|
4315
|
-
__name(getSourceLocationByPrecedingPattern, "getSourceLocationByPrecedingPattern");
|
|
4316
|
-
|
|
4317
|
-
// src/node/log-node.ts
|
|
4318
|
-
function shouldUseColor() {
|
|
4319
|
-
try {
|
|
4320
|
-
if (process.env.ZEED_COLOR != null) {
|
|
4321
|
-
return valueToBoolean(process.env.ZEED_COLOR, false);
|
|
4322
|
-
}
|
|
4323
|
-
return import_tty.default.isatty(process.stdout.fd);
|
|
4324
|
-
} catch (err) {
|
|
4325
|
-
}
|
|
4326
|
-
return false;
|
|
4327
|
-
}
|
|
4328
|
-
__name(shouldUseColor, "shouldUseColor");
|
|
4329
|
-
var colors = [6, 2, 3, 4, 5, 1];
|
|
4330
|
-
function selectColor(namespace) {
|
|
4331
|
-
let hash = 0;
|
|
4332
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
4333
|
-
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
4334
|
-
hash |= 0;
|
|
4335
|
-
}
|
|
4336
|
-
return colors[Math.abs(hash) % colors.length];
|
|
4337
|
-
}
|
|
4338
|
-
__name(selectColor, "selectColor");
|
|
4339
|
-
var namespaces2 = {};
|
|
4340
|
-
var time = getTimestamp();
|
|
4341
|
-
function log11(...args) {
|
|
4342
|
-
process.stdout.write(renderMessages(args) + "\n");
|
|
4343
|
-
}
|
|
4344
|
-
__name(log11, "log");
|
|
4345
|
-
var TTY_STYLE = {
|
|
4346
|
-
BOLD: "\x1B[1m",
|
|
4347
|
-
UNBOLD: "\x1B[2m",
|
|
4348
|
-
RED: "\x1B[31m",
|
|
4349
|
-
GREEN: "\x1B[32m",
|
|
4350
|
-
BLUE: "\x1B[34m",
|
|
4351
|
-
PURPLE: "\x1B[35m",
|
|
4352
|
-
GRAY: "\x1B[37m",
|
|
4353
|
-
ORANGE: "\x1B[38;5;208m",
|
|
4354
|
-
UNCOLOR: "\x1B[0m"
|
|
4355
|
-
};
|
|
4356
|
-
var colorEnd = "\x1B[0m";
|
|
4357
|
-
function colorString(value, colorCode) {
|
|
4358
|
-
const colorStart = colorCode === 8 /* ORANGE */ ? TTY_STYLE.ORANGE : "\x1B[3" + (colorCode < 8 ? colorCode : "8;5;" + colorCode) + "m";
|
|
4359
|
-
return `${colorStart}${value}${colorEnd}`;
|
|
4360
|
-
}
|
|
4361
|
-
__name(colorString, "colorString");
|
|
4362
|
-
function colorStringList(list, style, bold = true) {
|
|
4363
|
-
return list.map((value) => {
|
|
4364
|
-
if (typeof value !== "string")
|
|
4365
|
-
return value;
|
|
4366
|
-
let start = style;
|
|
4367
|
-
let end = colorEnd;
|
|
4368
|
-
if (bold) {
|
|
4369
|
-
start = `${TTY_STYLE.BOLD}${start}`;
|
|
4370
|
-
end = `${end}${TTY_STYLE.BOLD}`;
|
|
4371
|
-
}
|
|
4372
|
-
return `${start}${value}${end}`;
|
|
4373
|
-
});
|
|
4374
|
-
}
|
|
4375
|
-
__name(colorStringList, "colorStringList");
|
|
4376
|
-
var loggerStackTraceDebug = "loggerStackTraceDebug-7d38e5a9214b58d29734374cdb9521fd964d7485";
|
|
4377
|
-
function LoggerNodeHandler(opt = {}) {
|
|
4378
|
-
const {
|
|
4379
|
-
level = void 0,
|
|
4380
|
-
filter = void 0,
|
|
4381
|
-
colors: colors2 = shouldUseColor(),
|
|
4382
|
-
levelHelper = true,
|
|
4383
|
-
nameBrackets = true,
|
|
4384
|
-
padding = 0,
|
|
4385
|
-
fill = 0,
|
|
4386
|
-
stack = true
|
|
4387
|
-
} = opt;
|
|
4388
|
-
const matchesNamespace = useNamespaceFilter(filter);
|
|
4389
|
-
const matchesLevel = useLevelFilter(level);
|
|
4390
|
-
return (msg) => {
|
|
4391
|
-
var _a2;
|
|
4392
|
-
if (!matchesLevel(msg.level))
|
|
4393
|
-
return;
|
|
4394
|
-
if (!matchesNamespace(msg.name))
|
|
4395
|
-
return;
|
|
4396
|
-
const timeNow = getTimestamp();
|
|
4397
|
-
let name = msg.name || "";
|
|
4398
|
-
let ninfo = namespaces2[name || ""];
|
|
4399
|
-
if (ninfo == null) {
|
|
4400
|
-
ninfo = {
|
|
4401
|
-
color: selectColor(name)
|
|
4402
|
-
};
|
|
4403
|
-
namespaces2[name] = ninfo;
|
|
4404
|
-
}
|
|
4405
|
-
const diff = formatMilliseconds(timeNow - time);
|
|
4406
|
-
let args;
|
|
4407
|
-
let displayName = nameBrackets ? `[${name}]` : name;
|
|
4408
|
-
if (padding > 0) {
|
|
4409
|
-
displayName = displayName.padStart(padding, " ");
|
|
4410
|
-
}
|
|
4411
|
-
if (fill > 0) {
|
|
4412
|
-
displayName = displayName.padEnd(fill, " ");
|
|
4413
|
-
}
|
|
4414
|
-
if (colors2) {
|
|
4415
|
-
const c = ninfo.color;
|
|
4416
|
-
args = [colorString(displayName, c) + ` | `];
|
|
4417
|
-
if (msg.level === 2 /* warn */) {
|
|
4418
|
-
args.push(...colorStringList(msg.messages, TTY_STYLE.ORANGE));
|
|
4419
|
-
} else if (msg.level === 3 /* error */) {
|
|
4420
|
-
args.push(...colorStringList(msg.messages, TTY_STYLE.RED));
|
|
4421
|
-
} else {
|
|
4422
|
-
args.push(...msg.messages);
|
|
4423
|
-
}
|
|
4424
|
-
args.push(colorString(`+${diff}`, c));
|
|
4425
|
-
} else {
|
|
4426
|
-
args = [displayName, ...msg.messages];
|
|
4427
|
-
args.push(`+${diff}`);
|
|
4428
|
-
}
|
|
4429
|
-
if (((_a2 = msg.messages) == null ? void 0 : _a2[0]) === loggerStackTraceDebug) {
|
|
4430
|
-
console.log(getStack());
|
|
4431
|
-
}
|
|
4432
|
-
if (stack) {
|
|
4433
|
-
let line = "";
|
|
4434
|
-
if (typeof stack === "boolean") {
|
|
4435
|
-
line = getSourceLocationByPrecedingPattern(
|
|
4436
|
-
["at Function.", "at null.log (", "at log ("],
|
|
4437
|
-
true
|
|
4438
|
-
);
|
|
4439
|
-
if (!line) {
|
|
4440
|
-
line = getSourceLocation(0, true);
|
|
4441
|
-
}
|
|
4442
|
-
} else {
|
|
4443
|
-
const depth = typeof stack === "number" ? stack : 3;
|
|
4444
|
-
line = getSourceLocation(depth, true);
|
|
4445
|
-
}
|
|
4446
|
-
if (line) {
|
|
4447
|
-
args.push(colorString(`(${line})`, 7 /* GRAY */));
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
const sep = "|";
|
|
4451
|
-
const charLevel = ".";
|
|
4452
|
-
switch (msg.level) {
|
|
4453
|
-
case 1 /* info */:
|
|
4454
|
-
if (levelHelper)
|
|
4455
|
-
args[0] = `I${sep}${charLevel} ` + args[0];
|
|
4456
|
-
log11(...args);
|
|
4457
|
-
break;
|
|
4458
|
-
case 2 /* warn */:
|
|
4459
|
-
if (levelHelper)
|
|
4460
|
-
args[0] = (colors2 ? colorString(`W${sep}${charLevel}${charLevel} `, 8 /* ORANGE */) : `W${sep}${charLevel}${charLevel} `) + args[0];
|
|
4461
|
-
log11(...args);
|
|
4462
|
-
break;
|
|
4463
|
-
case 3 /* error */:
|
|
4464
|
-
if (levelHelper)
|
|
4465
|
-
args[0] = (colors2 ? colorString(
|
|
4466
|
-
`E${sep}${charLevel}${charLevel}${charLevel} `,
|
|
4467
|
-
1 /* RED */
|
|
4468
|
-
) : `E${sep}${charLevel}${charLevel}${charLevel} `) + args[0];
|
|
4469
|
-
log11(...args);
|
|
4470
|
-
break;
|
|
4471
|
-
default:
|
|
4472
|
-
if (levelHelper)
|
|
4473
|
-
args[0] = `D${sep} ` + args[0];
|
|
4474
|
-
log11(...args);
|
|
4475
|
-
break;
|
|
4476
|
-
}
|
|
4477
|
-
};
|
|
4478
|
-
}
|
|
4479
|
-
__name(LoggerNodeHandler, "LoggerNodeHandler");
|
|
1
|
+
"use strict";var Xr=Object.create;var ue=Object.defineProperty;var en=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames;var rn=Object.getPrototypeOf,nn=Object.prototype.hasOwnProperty;var o=(e,t)=>ue(e,"name",{value:t,configurable:!0});var on=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})},qt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tn(t))!nn.call(e,i)&&i!==r&&ue(e,i,{get:()=>t[i],enumerable:!(n=en(t,i))||n.enumerable});return e};var et=(e,t,r)=>(r=e!=null?Xr(rn(e)):{},qt(t||!e||!e.__esModule?ue(r,"default",{value:e,enumerable:!0}):r,e)),sn=e=>qt(ue({},"__esModule",{value:!0}),e);var Us={};on(Us,{Channel:()=>me,CryptoEncoder:()=>ze,Currency:()=>k,DAY_MS:()=>$e,Day:()=>A,Emitter:()=>M,FileStorage:()=>We,JsonEncoder:()=>z,LocalChannel:()=>ie,LogLevel:()=>N,LogLevelAlias:()=>rt,Logger:()=>L,LoggerConsoleHandler:()=>fe,LoggerContext:()=>nt,LoggerFileHandler:()=>$t,LoggerMemoryHandler:()=>es,LoggerNodeHandler:()=>zt,MemStorage:()=>qe,NoopEncoder:()=>Ve,PoolTaskIdConflictResolution:()=>Ir,PoolTaskState:()=>Rr,PubSub:()=>ye,SerialQueue:()=>Ge,Uint8ArrayToHexDump:()=>ut,Uint8ArrayToJson:()=>De,Uint8ArrayToString:()=>Zt,XRX:()=>He,_decodeUtf8Polyfill:()=>Kt,_encodeUtf8Polyfill:()=>Wt,arrayAvg:()=>Wn,arrayBatches:()=>Kn,arrayEmptyInPlace:()=>Hn,arrayFilterInPlace:()=>Ie,arrayFlatten:()=>F,arrayIntersection:()=>ir,arrayIsEqual:()=>ar,arrayMax:()=>qn,arrayMin:()=>_n,arrayMinus:()=>nr,arrayRandomElement:()=>zn,arrayRemoveElement:()=>$n,arraySetElement:()=>Bn,arrayShuffle:()=>Gn,arrayShuffleForce:()=>Vn,arrayShuffleInPlace:()=>pt,arraySorted:()=>sr,arraySortedNumbers:()=>jn,arraySum:()=>Jn,arraySymmetricDifference:()=>On,arrayToggleInPlace:()=>Nn,arrayUnion:()=>or,arrayUnique:()=>Re,avg:()=>In,between:()=>Rn,cloneJsonObject:()=>yi,cloneObject:()=>Z,cmp:()=>Me,colorString:()=>ae,colorStringList:()=>Vt,composeOrderby:()=>kn,createArray:()=>Zn,createLocalChannelPair:()=>ts,createPromise:()=>xt,createPromiseProxy:()=>Ut,csv:()=>Pn,currency:()=>H,dateStringToDays:()=>Vo,day:()=>Go,dayDay:()=>gr,dayDiff:()=>ko,dayFromAny:()=>So,dayFromDate:()=>ge,dayFromDateGMT:()=>Ro,dayFromParts:()=>Ne,dayFromString:()=>ht,dayFromTimestamp:()=>mr,dayFromToday:()=>Do,dayMonth:()=>mt,dayMonthStart:()=>Io,dayOffset:()=>Co,dayToDate:()=>yt,dayToDateGMT:()=>Mo,dayToParts:()=>Po,dayToString:()=>yr,dayToTimestamp:()=>Oe,dayYear:()=>Be,dayYearStart:()=>Uo,debounce:()=>Qi,decimal:()=>xr,decimalCentsPart:()=>_o,decimalFromCents:()=>zo,decimalToCents:()=>qo,decodeBase16:()=>eo,decodeBase32:()=>ro,decodeBase58:()=>oo,decodeBase62:()=>so,decodeBase64:()=>uo,decrypt:()=>ft,deepEqual:()=>le,deepMerge:()=>ce,deriveKeyPbkdf2:()=>vn,detect:()=>Or,digest:()=>Ln,empty:()=>mi,encodeBase16:()=>Xn,encodeBase32:()=>to,encodeBase58:()=>no,encodeBase62:()=>io,encodeBase64:()=>ao,encodeQuery:()=>Dt,encrypt:()=>ct,endSortWeight:()=>Pt,ensureFolder:()=>Ls,ensureKey:()=>fi,ensureKeyAsync:()=>pi,equalBinary:()=>at,escapeHTML:()=>Lt,escapeRegExp:()=>Qo,exists:()=>Ke,fetchBasic:()=>kt,fetchJson:()=>as,fetchOptionsBasicAuth:()=>kr,fetchOptionsFormURLEncoded:()=>ls,fetchOptionsJson:()=>cs,fetchText:()=>us,fixBrokenUth8String:()=>wo,forEachDay:()=>Ho,forTimes:()=>xi,formatMessages:()=>pr,formatMilliseconds:()=>St,fromBase64:()=>Tn,fromCamelCase:()=>co,getGlobal:()=>fs,getGlobalContext:()=>Q,getGlobalEmitter:()=>Ui,getNamespaceFilterString:()=>_t,getNavigator:()=>Fr,getSecureRandom:()=>er,getSecureRandomIfPossible:()=>R,getSourceLocation:()=>Qe,getSourceLocationByPrecedingPattern:()=>Gt,getStack:()=>jt,getStackLlocationList:()=>_r,getTimestamp:()=>re,getWindow:()=>Ft,immediate:()=>Oo,isArray:()=>Le,isBoolean:()=>dn,isBrowser:()=>$r,isEven:()=>At,isHalf:()=>ee,isInteger:()=>fn,isLocalHost:()=>Xi,isNullOrUndefined:()=>gn,isNumber:()=>cn,isObject:()=>W,isPrime:()=>Cn,isPrimeRX:()=>Un,isPrimitive:()=>tt,isPromise:()=>S,isRecord:()=>un,isSafeInteger:()=>pn,isString:()=>ln,isTimeout:()=>Bo,isUint8Array:()=>mn,joinToUint8Array:()=>xn,jsonStringify:()=>Ue,jsonToUint8Array:()=>Pe,last:()=>gi,lazyListener:()=>ki,linkifyPlainText:()=>li,loggerStackTraceDebug:()=>Qr,memoize:()=>hi,messages:()=>Ci,moveSortWeight:()=>ai,parseArgs:()=>gs,parseBasicAuth:()=>Cr,parseDate:()=>Fi,parseLogLevel:()=>ve,parseOrderby:()=>rr,parseQuery:()=>ci,pbcopy:()=>ms,platform:()=>ps,promisify:()=>j,qid:()=>zi,randomBoolean:()=>Dn,randomFloat:()=>Mn,randomInt:()=>Sn,randomUint8Array:()=>K,readText:()=>As,regExpEscape:()=>Li,regExpString:()=>Ar,removeFolder:()=>vs,renderMessages:()=>pe,roundDown:()=>ei,roundHalfAwayFromZero:()=>ni,roundHalfDown:()=>oi,roundHalfEven:()=>ii,roundHalfOdd:()=>ri,roundHalfTowardsZero:()=>si,roundHalfUp:()=>ti,roundUp:()=>Xo,setupEnv:()=>ws,size:()=>di,sleep:()=>Fo,sortedItems:()=>Tr,sortedOrderby:()=>Fn,startSortWeight:()=>Et,stringToBoolean:()=>po,stringToFloat:()=>mo,stringToInteger:()=>go,stringToPath:()=>jr,stringToUInt8Array:()=>it,suid:()=>Wi,suidBytes:()=>Sr,suidBytesDate:()=>Mr,suidDate:()=>Ki,sum:()=>tr,throttle:()=>Yi,timeout:()=>$o,timeoutReached:()=>bt,timoutError:()=>wt,toBase64:()=>st,toBase64Url:()=>wn,toBool:()=>bo,toCamelCase:()=>dt,toCapitalize:()=>ur,toCapitalizeWords:()=>lo,toFloat:()=>yo,toHex:()=>bn,toHumanReadableFilePath:()=>Ts,toHumanReadableUrl:()=>Lr,toInt:()=>ho,toPath:()=>Je,toString:()=>xo,toUint8Array:()=>D,toValidFilename:()=>vt,today:()=>jo,tryTimeout:()=>Tt,uname:()=>V,unescapeHTML:()=>Jo,useAsyncMutex:()=>Ii,useBase:()=>B,useDefer:()=>Pi,useDispose:()=>je,useDisposer:()=>Ei,useEventListener:()=>Mi,useExitHandler:()=>ds,useInterval:()=>Si,useLevelFilter:()=>$,useMessageHub:()=>rs,useMutex:()=>Ri,useNamespaceFilter:()=>C,usePool:()=>Zi,usePubSub:()=>ns,useRPC:()=>ss,useTimeout:()=>Di,uuid:()=>G,uuid32Decode:()=>Gi,uuid32Encode:()=>ji,uuid32bit:()=>$i,uuidB32:()=>Hi,uuidBytes:()=>It,uuidDecode:()=>Ni,uuidEncode:()=>Bi,uuidv4:()=>_i,valueToBoolean:()=>Ce,valueToFloat:()=>fr,valueToInteger:()=>cr,valueToPath:()=>Gr,valueToString:()=>ke,waitOn:()=>No,writeText:()=>Es});module.exports=sn(Us);function an(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;if(typeof globalThis<"u")return globalThis;throw new Error("unable to locate global object")}o(an,"_global");function Q(){let e=an();return e._zeedGlobal==null&&(e._zeedGlobal={}),e._zeedGlobal}o(Q,"getGlobalContext");function W(e){return e!=null&&typeof e=="object"}o(W,"isObject");function tt(e){return Object(e)!==e}o(tt,"isPrimitive");function Le(e){return Array.isArray(e)}o(Le,"isArray");function un(e){return W(e)&&!Le(e)}o(un,"isRecord");function ln(e){return typeof e=="string"}o(ln,"isString");function cn(e){return typeof e=="number"}o(cn,"isNumber");function fn(e){return typeof e=="number"&&Number.isInteger(e)}o(fn,"isInteger");function pn(e){return typeof e=="number"&&Number.isSafeInteger(e)}o(pn,"isSafeInteger");function dn(e){return typeof e=="boolean"}o(dn,"isBoolean");function gn(e){return e==null}o(gn,"isNullOrUndefined");function mn(e){return W(e)&&e.constructor.name==="Uint8Array"}o(mn,"isUint8Array");function le(e,t,r=new WeakSet){if(e===t||r.has(t))return!0;if(tt(t)||r.add(t),!(e instanceof Object)||!(t instanceof Object)||e.constructor!==t.constructor||e.length!==t.length)return!1;for(let n in e){if(!e.hasOwnProperty(n))continue;if(!t.hasOwnProperty(n))return!1;let i=e[n],s=t[n];if(!le(i,s,r))return!1}for(let n in t)if(t.hasOwnProperty(n)&&!e.hasOwnProperty(n))return!1;return!0}o(le,"deepEqual");function ce(e,...t){for(let r of t)W(e)||(e={}),r!=null&&Object.keys(r).forEach(n=>{let i=e[n],s=r[n];Array.isArray(i)&&Array.isArray(s)?e[n]=i.concat(s):W(i)&&W(s)?e[n]=ce(Object.assign({},i),s):e[n]=s});return e}o(ce,"deepMerge");function _t(e){return e===!0||e==="true"||e==="1"||typeof e=="number"&&e!==0?e="*":e===!1||e==="false"||e===0||e==="0"||e==null||e==="null"||e==="undefined"?e="":e=String(e),e}o(_t,"getNamespaceFilterString");var yn=_t(typeof process<"u"?process.env.ZEED??process.env.DEBUG:typeof localStorage<"u"?localStorage.zeed??localStorage.debug:"*");function C(e=yn){let t,r=[],n=[];if(!e)t=o(function(i){return!1},"fn");else if(e==="*")t=o(function(i){return!0},"fn");else{let i,s=e.split(/[\s,]+/),u=s.length;for(i=0;i<u;i++){if(!s[i])continue;let a=s[i].replace(/\*/g,".*?");a[0]==="-"?r.push(new RegExp("^"+a.substr(1)+"$")):n.push(new RegExp("^"+a+"$"))}t=o(function(a){if(r.length===0&&n.length===0)return!0;let l,c;for(l=0,c=r.length;l<c;l++)if(r[l].test(a))return!1;for(l=0,c=n.length;l<c;l++)if(n[l].test(a))return!0;return!1},"fn")}return t.accept=n,t.reject=r,t.filter=e,t}o(C,"useNamespaceFilter");var hn=typeof process<"u"?process.env.ZEED_LEVEL??process.env.LEVEL??process.env.DEBUG_LEVEL:typeof localStorage<"u"?localStorage.zeed_level??localStorage.level??localStorage.debug_level:void 0;function ve(e){if(e===!1)return 1/0;if(typeof e=="number")return e;if(typeof e=="string"){let t=rt[e.toLocaleLowerCase().trim()];if(t!=null)return t}return-1}o(ve,"parseLogLevel");function $(e=hn){let t=ve(e);return r=>r>=t}o($,"useLevelFilter");function fe(e={}){let{level:t=void 0,filter:r=void 0,colors:n=!0,levelHelper:i=!1,nameBrackets:s=!0,padding:u=16}=e,a=C(r),l=$(t);return c=>{if(!l(c.level)||!a(c.name))return;let p=c.name?`[${c.name}]`:"";switch(c.level){case 1:console.info(`I|* ${p}`,...c.messages);break;case 2:console.warn(`W|** ${p}`,...c.messages);break;case 3:console.error(`E|*** ${p}`,...c.messages);break;default:console.debug(`D| ${p}`,...c.messages);break}}}o(fe,"LoggerConsoleHandler");var N=(a=>(a[a.all=-1]="all",a[a.debug=0]="debug",a[a.info=1]="info",a[a.warn=2]="warn",a[a.error=3]="error",a[a.fatal=4]="fatal",a[a.off=1/0]="off",a))(N||{}),rt={"*":-1,a:-1,all:-1,d:0,dbg:0,debug:0,i:1,inf:1,info:1,w:2,warn:2,warning:2,e:3,err:3,error:3,fatal:4,off:1/0,"-":1/0};function nt(e=""){let t=[fe()],r=2,n=o(l=>!0,"logCheckNamespace"),i=!1,s=u;function u(l="",c){function p(...f){g({name:l,messages:f,level:0})}o(p,"log"),p.label=l,p.active=!0,p.level=ve(c??-1),p.extend=function(f){return s(l?`${l}:${f}`:f)};let g=o(f=>{if(p.active===!0&&f.level>=a.level&&f.level>=p.level&&n(l))for(let m of t)m&&m(f)},"emit");return p.debug=function(...f){g({name:l,messages:f,level:0})},p.info=function(...f){g({name:l,messages:f,level:1})},p.warn=function(...f){g({name:l,messages:f,level:2})},p.error=function(...f){g({name:l,messages:f,level:3})},p.assert=function(f,...m){f||(typeof console!==void 0&&(console.assert?console.assert(f,...m):console.error(`Assert did fail with: ${f}`,...m)),g({name:l,messages:m||[`Assert did fail with: ${f}`],level:r}))},p.assertEqual=function(f,m,...b){let y=le(f,m);y||p.assert(y,`Assert did fail. Expected ${m} got ${f}`,m,f,...b)},p.assertNotEqual=function(f,m,...b){let y=le(f,m);y&&p.assert(y,`Assert did fail. Expected ${m} not to be equal with ${f}`,m,f,...b)},p}o(u,"LoggerBaseFactory");function a(l="",c){return s(l,c)}return o(a,"Logger"),a.registerHandler=function(l){t.push(l)},a.setFilter=function(l){n=C(l)},a.setLock=(l=!0)=>i=l,a.setHandlers=function(l=[]){s!==u&&(s=u),!i&&(t=[...l].filter(c=>typeof c=="function"))},a.level=-1,a.setLogLevel=function(l=-1){i||(a.level=l)},a.setFactory=function(l){i||(s=l)},a}o(nt,"LoggerContext");var X;function ot(){let e=nt();return e.setHandlers([fe()]),e}o(ot,"getLoggerContext");try{let e=Q();e!=null?(e==null?void 0:e.logger)==null?(X=ot(),e.logger=X):X=e.logger:X=ot()}catch{X=ot()}var L=X;var Jt=L("bin");function Wt(e){let t=unescape(encodeURIComponent(e)),r=t.length,n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=t.codePointAt(i)||0;return n}o(Wt,"_encodeUtf8Polyfill");function Kt(e){let t=e.length,r="",n=0;for(;t>0;){let i=t<1e4?t:1e4,s=e.subarray(n,n+i);n+=i,r+=String.fromCodePoint.apply(null,s),t-=i}return decodeURIComponent(escape(r))}o(Kt,"_decodeUtf8Polyfill");var Ae;function it(e){if(Ae==null&&(Ae=Wt,typeof TextEncoder<"u")){let t=new TextEncoder;Ae=o(r=>t.encode(r),"_textEncoder")}return Ae(e.normalize("NFC"))}o(it,"stringToUInt8Array");var Ee;function Zt(e){if(Ee==null&&(Ee=Kt,typeof TextDecoder<"u")){let t=new TextDecoder("utf-8",{ignoreBOM:!0});Ee=o(r=>t.decode(r),"_textDecoder")}return Ee(e).normalize("NFC")}o(Zt,"Uint8ArrayToString");function D(e){return e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?it(e):e.length?new Uint8Array(e):e}o(D,"toUint8Array");function xn(...e){let t=0,r=e.flat(1).map(s=>{let u=D(s);return t+=u.length,u}),n=new Uint8Array(t),i=0;for(let s of r)n.set(s,i),i+=s.length;return n}o(xn,"joinToUint8Array");function bn(e){if(typeof Buffer<"u")return Buffer.from(D(e)).toString("hex");let t="0123456789abcdef",r="";for(let n of[...D(e)])r+=t[n>>4]+t[n&15];return r}o(bn,"toHex");function st(e){let t=D(e);if(typeof Buffer<"u")return Buffer.from(t).toString("base64");let r="";for(let n=0;n<t.byteLength;n++)r+=String.fromCharCode(t[n]);return btoa(r)}o(st,"toBase64");function wn(e){let t=D(e);if(typeof Buffer<"u")return Buffer.from(t).toString("base64url");let r="";for(let n=0;n<t.byteLength;n++)r+=String.fromCharCode(t[n]);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_")}o(wn,"toBase64Url");function Tn(e){if(typeof Buffer<"u"){let n=Buffer.from(e,"base64");return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}o(Tn,"fromBase64");function at(e,t){if(e.byteLength!==t.byteLength)return!1;let r=D(e),n=D(t);for(let i=0;i<r.length;i++)if(r[i]!==n[i])return!1;return!0}o(at,"equalBinary");function Pe(e){try{return it(JSON.stringify(e))}catch(t){throw Jt.warn("jsonToUint8Array",e),t}}o(Pe,"jsonToUint8Array");function De(e){try{return JSON.parse(Zt(e))}catch(t){throw Jt.warn("Uint8ArrayToJson",e),t}}o(De,"Uint8ArrayToJson");function ut(e,t){if(typeof e!="string")if(e instanceof ArrayBuffer&&e.byteLength!==void 0)e=String.fromCharCode.apply(String,[].slice.call(new Uint8Array(e)));else if(Array.isArray(e))e=String.fromCharCode.apply(String,e);else if(e.constructor===Uint8Array)e=String.fromCharCode.apply(String,[].slice.call(e));else return!1;t=t||16;for(var r=[],n="0123456789ABCDEF",i=0;i<e.length;i+=t){var s=e.slice(i,Math.min(i+t,e.length)),u=("0000"+i.toString(16)).slice(-4),a=s.split("").map(c=>{var p=c.charCodeAt(0);return" "+n[(240&p)>>4]+n[15&p]}).join("");a+=" ".repeat(t-s.length);var l=s.replace(/[\x00-\x1F\x20]/g,".");l+=" ".repeat(t-s.length),r.push(u+" "+a+" "+l)}return r.join(`
|
|
2
|
+
`)}o(ut,"Uint8ArrayToHexDump");function K(e=16){let t=new Uint8Array(e);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(t);else for(let r=0;r<e;r++)t[r]=Math.floor(Math.random()*256);return t}o(K,"randomUint8Array");var Qt="SHA-256",lt="AES-GCM",Yt="PBKDF2";async function Ln(e,t=Qt){return D(await crypto.subtle.digest(t,D(e)))}o(Ln,"digest");async function vn(e,t={}){let r=D(e),n=await crypto.subtle.importKey("raw",r,Yt,!1,["deriveKey"]);return await crypto.subtle.deriveKey({name:Yt,salt:t.salt?D(t.salt):new Uint8Array(0),iterations:t.iterations??1e5,hash:Qt},n,{name:lt,length:256},!0,["encrypt","decrypt"])}o(vn,"deriveKeyPbkdf2");var Se=new Uint8Array([1,1]);async function ct(e,t){let r=K(12),n=await crypto.subtle.encrypt({name:lt,iv:r},t,e),i=new Uint8Array(n),s=Se.length+r.length+i.length,u=new Uint8Array(s),a=0;return u.set(Se,a),a+=Se.length,u.set(r,a),a+=r.length,u.set(i,a),u}o(ct,"encrypt");async function ft(e,t){let r=e.subarray(0,2);if(!at(r,Se))return Promise.reject(`Unknown magic ${r}`);let n=e.subarray(2,2+12),i=e.subarray(2+12,e.length),s=await crypto.subtle.decrypt({name:lt,iv:n},t,i);return new Uint8Array(s)}o(ft,"decrypt");var Xt=",";function An(e){return/^([-+])?([0-9]+(\.[0-9]+)?|Infinity)$/.test(e)?Number(e):NaN}o(An,"filterFloat");function En(e){return e==null?"":!isNaN(An(e))&&isFinite(e)?parseFloat(e):'"'+String(e).replace(/"/g,'""')+'"'}o(En,"escape");function Pn(e,t){let r="";t&&(r=t.join(Xt)+`\r
|
|
3
|
+
`);for(let n=0;n<e.length;n++)r+=e[n].map(En).join(Xt)+`\r
|
|
4
|
+
`;return r}o(Pn,"csv");function er(){return crypto.getRandomValues(new Uint32Array(1))[0]/4294967295}o(er,"getSecureRandom");function R(){return typeof crypto<"u"?er():Math.random()}o(R,"getSecureRandomIfPossible");function Dn(e=.25){return R()<e}o(Dn,"randomBoolean");function Sn(e=100,t=0){return t+Math.floor(R()*(e-t))}o(Sn,"randomInt");function Mn(e=100,t=0){return t+R()*(e-t)}o(Mn,"randomFloat");function Rn(e,t,r){return Math.max(e,Math.min(r,t))}o(Rn,"between");function tr(e){return e.reduce((t,r)=>t+r,0)}o(tr,"sum");function In(e){return tr(e)/e.length}o(In,"avg");function Un(e){return!/^1?$|^(11+?)\1+$/.test("1".repeat(e))}o(Un,"isPrimeRX");function Cn(e){for(var t=2;t<e;t++)if(e%t===0)return!1;return e>1}o(Cn,"isPrime");function rr(e=""){let[t="",r="asc"]=e.split(" ");return r=r.toLowerCase(),{field:t,orderby:r,asc:r!=="desc",desc:r==="desc"}}o(rr,"parseOrderby");function kn(e,t=!0){return`${e} ${t?"asc":"desc"}`}o(kn,"composeOrderby");function Me(e,t,r=!0){let n=e||0,i=t||0;return n>i?r?1:-1:n<i?r?-1:1:0}o(Me,"cmp");function Fn(e,...t){if(t.length>0){let r=t.map(rr),n=Array.from(e);return n.sort((i,s)=>{for(let{field:u,asc:a}of r){let l=Me(i[u],s[u],a);if(l!==0)return l}return 0}),n}return e}o(Fn,"sortedOrderby");function Re(e){return e.filter((t,r)=>e.indexOf(t)===r)}o(Re,"arrayUnique");function nr(e,t){return Re(e.filter(r=>!t.includes(r)))}o(nr,"arrayMinus");function or(...e){return Re(e.reduce((t=[],r)=>t.concat(r),[]))}o(or,"arrayUnion");function F(...e){return e.flat(1/0)}o(F,"arrayFlatten");function ir(e,t){return Re(e).filter(r=>t.includes(r))}o(ir,"arrayIntersection");function On(e,t){return nr(or(e,t),ir(e,t))}o(On,"arraySymmetricDifference");function $n(e,t){if(e&&Array.isArray(e)){let r;for(;(r=e.indexOf(t))!==-1;)e.splice(r,1);return e}return[]}o($n,"arrayRemoveElement");function Bn(e,t){return e.includes(t)||e.push(t),e}o(Bn,"arraySetElement");function Ie(e,t){return e.splice(0,e.length,...e.filter(t)),e}o(Ie,"arrayFilterInPlace");function Nn(e,t){let r=e.findIndex(n=>n===t);return r>=0?e.splice(r,1):e.push(t),e}o(Nn,"arrayToggleInPlace");function Hn(e){return e.splice(0,e.length),e}o(Hn,"arrayEmptyInPlace");function sr(e,t=Me){return Array.from(e).sort(t)}o(sr,"arraySorted");function jn(e){return sr(e,(t,r)=>t-r)}o(jn,"arraySortedNumbers");function ar(e,t){return e.length===t.length&&e.every((r,n)=>r===t[n])}o(ar,"arrayIsEqual");function pt(e){return e.sort(()=>R()>.5?1:-1),e}o(pt,"arrayShuffleInPlace");function Gn(e){return pt(Array.from(e))}o(Gn,"arrayShuffle");function Vn(e){for(;e.length>1;){let t=Array.from(e);if(pt(t),!ar(e,t))return t}return e}o(Vn,"arrayShuffleForce");function zn(e){return e[Math.floor(R()*e.length)]}o(zn,"arrayRandomElement");function qn(...e){return F(e).reduce((t,r)=>t!=null?r>t?r:t:r,void 0)}o(qn,"arrayMax");function _n(...e){return F(e).reduce((t,r)=>t!=null?r<t?r:t:r,void 0)}o(_n,"arrayMin");function Jn(...e){return F(e).reduce((t,r)=>t+r,0)}o(Jn,"arraySum");function Wn(...e){let t=F(e);return t.reduce((r,n)=>r+n,0)/t.length}o(Wn,"arrayAvg");function Kn(e,t){let r=[],n=0,i=e.length;for(;n<i;)r.push(e.slice(n,n+=t));return r}o(Kn,"arrayBatches");function Zn(e=0,t){if(e<=0)return[];let r=new Array(e);for(let n=0;n<e;n++)r[n]=t instanceof Function?t(n):t;return r}o(Zn,"createArray");var Yn=L("zeed:basex"),Qn={2:"01",8:"01234567",11:"0123456789a",16:"0123456789abcdef",32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ","32-rfc":"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567","32-hex":"0123456789ABCDEFGHIJKLMNOPQRSTUV","32-zbase":"ybndrfg8ejkmcpqxot1uwisza345h769",36:"0123456789abcdefghijklmnopqrstuvwxyz",58:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",62:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",64:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/","64-url":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",66:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~",85:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"};function B(e){let t;if(typeof e=="string")t=e;else if(t=Qn[String(e)],t==null)throw new Error(`Unknown base ${e}`);if(t.length>=255)throw new TypeError("Alphabet too long");let r=new Uint8Array(256);for(let c=0;c<r.length;c++)r[c]=255;for(let c=0;c<t.length;c++){let p=t.charAt(c),g=p.charCodeAt(0);if(r[g]!==255)throw new TypeError(p+" is ambiguous");r[g]=c}let n=t.length,i=t.charAt(0),s=Math.log(n)/Math.log(256),u=Math.log(256)/Math.log(n);function a(c,p=-1){let g=D(c);if(g.byteLength===0)return"";let f=0,m=0,b=g.byteLength;for(;m!==b&&g[m]===0;)m++;let y=(b-m)*u+1>>>0,d=new Uint8Array(y);for(;m!==b;){let h=g[m],v=0;for(let T=y-1;(h!==0||v<f)&&T!==-1;T--,v++)h+=256*d[T]>>>0,d[T]=h%n>>>0,h=h/n>>>0;if(h!==0)throw Yn.warn("Non-zero carry",g,p,v,y),new Error("Non-zero carry");f=v,m++}let x=y-f;for(;x!==y&&d[x]===0;)x++;let w="";for(;x<y;++x)w+=t.charAt(d[x]);return p>0?w.padStart(p,i):w}o(a,"encode");function l(c,p=-1){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;c=c.replace(/\s+/gi,"");let g=0,f=0;for(;c[g]===i;)g++;let m=(c.length-g)*s+1>>>0,b=new Uint8Array(m);for(;c[g];){let d=r[c.charCodeAt(g)];if(d===255)throw new Error(`Unsupported character "${c[g]}"`);let x=0;for(let w=m-1;(d!==0||x<f)&&w!==-1;w--,x++)d+=n*b[w]>>>0,b[w]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");f=x,g++}let y=m-f;for(;y!==m&&b[y]===0;)y++;return p>0?new Uint8Array([...new Uint8Array(p-b.length+y),...b.slice(y)]):b.slice(y)}return o(l,"decode"),{encode:a,decode:l}}o(B,"useBase");var{encode:Xn,decode:eo}=B(16),{encode:to,decode:ro}=B(32),{encode:no,decode:oo}=B(58),{encode:io,decode:so}=B(62),{encode:ao,decode:uo}=B(62);var dt=o(e=>(e.length>0&&(/^[A-Z0-9_\-\ ]*$/g.test(e)&&(e=e.toLowerCase()),e=e.replace(/^[-_\ ]+/gi,"").replace(/[-_\ ]+$/gi,"").replace(/[-_\ ]+([a-z0-9])/gi,(t,r)=>r.toUpperCase()),e=e[0].toLowerCase()+e.substring(1)),e),"toCamelCase");function ur(e){return e.charAt(0).toUpperCase()+e.toLowerCase().slice(1)}o(ur,"toCapitalize");function lo(e){return e.replace(/\w\S*/g,ur)}o(lo,"toCapitalizeWords");function co(e,t="-"){return t=typeof t>"u"?"_":t,e.replace(/([a-z\d])([A-Z])/g,"$1"+t+"$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g,"$1"+t+"$2").toLowerCase()}o(co,"fromCamelCase");function fo(e,t){var r=[],n=[];return t==null&&(t=o(function(i,s){return r[0]===s?"[Circular ~]":"[Circular ~."+n.slice(0,r.indexOf(s)).join(".")+"]"},"cycleReplacer")),function(i,s){if(r.length>0){var u=r.indexOf(this);~u?r.splice(u+1):r.push(this),~u?n.splice(u,1/0,i):n.push(i),~r.indexOf(s)&&(s=t==null?void 0:t.call(this,i,s))}else r.push(s);return e==null?s:e.call(this,i,s)}}o(fo,"serializer");function Ue(e,t,r,n){return JSON.stringify(e,fo(t,n),r)}o(Ue,"jsonStringify");var lr=["1","true","yes","y","on"];function po(e,t=!1){return e==null||typeof e!="string"?t:lr.includes(String(e).trim().toLowerCase())}o(po,"stringToBoolean");function go(e,t=0){return e==null||typeof e!="string"?t:parseInt(e.trim(),10)??t}o(go,"stringToInteger");function mo(e,t=0){return e==null||typeof e!="string"?t:parseFloat(e.trim())??t}o(mo,"stringToFloat");function Ce(e,t=!1){return e==null?t:typeof e=="boolean"?e:typeof e=="number"?e!==0:lr.includes(String(e).trim().toLowerCase())}o(Ce,"valueToBoolean");function cr(e,t=0){return e==null?t:typeof e=="boolean"?e?1:0:typeof e=="number"?Math.floor(e):parseInt(String(e).trim(),10)??t}o(cr,"valueToInteger");function fr(e,t=0){return e==null?t:typeof e=="boolean"?e?1:0:typeof e=="number"?Math.floor(e):parseFloat(String(e).trim())??t}o(fr,"valueToFloat");function ke(e,t=""){return e==null?t:String(e)??t}o(ke,"valueToString");var yo=fr,ho=cr,xo=ke,bo=Ce;function pr(e,t={}){let{trace:r=!0,pretty:n=!0}=t;return e.map(i=>i&&typeof i=="object"?n&&(i instanceof Uint8Array||i instanceof ArrayBuffer)?`
|
|
5
|
+
`+ut(i)+`
|
|
6
|
+
`:i instanceof Error?r?`${i.name||"Error"}: ${i.message}
|
|
7
|
+
${i.stack}`:`${i.name||"Error"}: ${i.message}`:n?Ue(i,null,2):Ue(i):String(i))}o(pr,"formatMessages");function pe(e,t={}){return pr(e,t).join(" ")}o(pe,"renderMessages");function wo(e){try{return decodeURIComponent(escape(e))}catch{}return e}o(wo,"fixBrokenUth8String");var To={symbol:"$",separator:",",decimal:".",errorOnInvalid:!1,precision:2,pattern:"!#",negativePattern:"-!#",format:Eo,fromCents:!1},dr=o(e=>Math.round(e),"round"),gt=o(e=>Math.pow(10,e),"pow"),Lo=o((e,t)=>dr(e/t)*t,"rounding"),vo=/(\d)(?=(\d{3})+\b)/g,Ao=/(\d)(?=(\d\d)+\d\b)/g;function H(e,t={}){return new k(e,t)}o(H,"currency");var de=class{constructor(t,r={}){let n=Object.assign({},To,r),i=gt(n.precision??2),s=Fe(t,n);this.intValue=s,this.value=s/i,n.increment=n.increment||1/i,n.useVedic?n.groups=Ao:n.groups=vo,this._settings=n,this._precision=i}add(t){let{intValue:r,_settings:n,_precision:i}=this;return H((r+=Fe(t,n))/(n.fromCents?1:i),n)}subtract(t){let{intValue:r,_settings:n,_precision:i}=this;return H((r-=Fe(t,n))/(n.fromCents?1:i),n)}multiply(t){let{intValue:r,_settings:n,_precision:i}=this;return H((r*=t)/(n.fromCents?1:gt(i)),n)}divide(t){let{intValue:r,_settings:n}=this;return H(r/=Fe(t,n,!1),n)}distribute(t){let{intValue:r,_precision:n,_settings:i}=this,s=[],u=Math[r>=0?"floor":"ceil"](r/t),a=Math.abs(r-u*t),l=i.fromCents?1:n;for(;t!==0;t--){let c=H(u/l,i);a-- >0&&(c=c[r>=0?"add":"subtract"](1/l)),s.push(c)}return s}dollars(){return~~this.value}cents(){let{intValue:t,_precision:r}=this;return~~(t%r)}format(t){let{_settings:r}=this;return typeof t=="function"?t(this,r):r.format(this,Object.assign({},r,t))}toString(){let{intValue:t,_precision:r,_settings:n}=this;return Lo(t/r,n.increment).toFixed(n.precision)}toJSON(){return this.value}static sum(...t){return F(t).reduce((r,n)=>H(r).add(n),this.zero)}static avg(...t){let r=F(t);return r.reduce((n,i)=>H(n).add(i),this.zero).divide(r.length)}},k=de;o(k,"Currency"),k.zero=new de(0),k.one=new de(1),k.hundred=new de(100);function Fe(e,t,r=!0){let n=0,{decimal:i,errorOnInvalid:s,precision:u,fromCents:a}=t,l=gt(u),c=typeof e=="number";if(e instanceof k&&a)return e.intValue;if(c||e instanceof k)n=e instanceof k?e.value:e;else if(typeof e=="string"){let p=new RegExp("[^-\\d"+i+"]","g"),g=new RegExp("\\"+i,"g");n=e.replace(/\((.*)\)/,"-$1").replace(p,"").replace(g,"."),n=n||0}else{if(s)throw Error("Invalid Input");n=0}return a||(n*=l,n=n.toFixed(4)),r?dr(n):n}o(Fe,"parse");function Eo(e,t){let{pattern:r,negativePattern:n,symbol:i,separator:s,decimal:u,groups:a}=t,l=(""+e).replace(/^-/,"").split("."),c=l[0],p=l[1];return(e.value>=0?r:n).replace("!",i).replace("#",c.replace(a,"$1"+s)+(p?u+p:""))}o(Eo,"format");var $e=864e5;function Be(e){return Math.floor(e/1e4)}o(Be,"dayYear");function mt(e){return Math.floor(e/100%100)}o(mt,"dayMonth");function gr(e){return Math.floor(e%100)}o(gr,"dayDay");function Po(e){return[Be(e),mt(e),gr(e)]}o(Po,"dayToParts");function yt(e,t=!1){return t?new Date(`${yr(e)}T00:00:00.000Z`):new Date(e/1e4,e/100%100-1,e%100)}o(yt,"dayToDate");function Do(){return ge(new Date)}o(Do,"dayFromToday");function So(e,t=!1){if(typeof e=="number")return e<100?void 0:e;if(typeof e=="string")return ht(e);if(Array.isArray(e)&&e.length===3){let[r,n,i]=e;return Ne(r,n,i)}else if(e instanceof Date)return ge(e,t)}o(So,"dayFromAny");function Mo(e){return yt(e,!0)}o(Mo,"dayToDateGMT");function ge(e,t=!1){return t?ht(e.toISOString()):e.getFullYear()*1e4+(e.getMonth()+1)*100+e.getDate()}o(ge,"dayFromDate");function Ro(e){return ge(e,!0)}o(Ro,"dayFromDateGMT");function Oe(e,t=!0){return yt(e,t).getTime()}o(Oe,"dayToTimestamp");function mr(e,t=!0){return ge(new Date(e),t)}o(mr,"dayFromTimestamp");function yr(e,t="-"){let r=String(e);return r.slice(0,4)+t+r.slice(4,6)+t+r.slice(6,8)}o(yr,"dayToString");function Ne(e,t=1,r=1){if(!(t<1||t>12||r<1||r>31))return e*1e4+t*100+r}o(Ne,"dayFromParts");function ht(e){let t=String(e).replace(/[^0-9]/g,"").slice(0,8);if(t.length===8)return+t}o(ht,"dayFromString");function Io(e,t=0){let r=Be(e),n=mt(e);return t!==0&&(n+=t,r+=Math.floor((n-1)/12),n=Math.floor((n-1)%12)+1,n===0&&(n=12)),Ne(r,n,1)}o(Io,"dayMonthStart");function Uo(e,t=0){let r=Be(e);return Ne(r+t,1,1)}o(Uo,"dayYearStart");function Co(e,t){return mr(Oe(e)+t*864e5)}o(Co,"dayOffset");function ko(e,t){return Math.round((Oe(t)-Oe(e))/864e5)}o(ko,"dayDiff");var{warn:hr}=L("zeed:promise");function xt(){let e,t;return[new Promise((n,i)=>{e=n,t=i}),e,t]}o(xt,"createPromise");async function Fo(e){return new Promise(t=>setTimeout(t,e))}o(Fo,"sleep");async function Oo(){return new Promise(e=>setTimeout(e,0))}o(Oo,"immediate");var bt=Symbol("timeout");async function $o(e,t,r=bt){return new Promise(async(n,i)=>{let s=!1,u=setTimeout(()=>{s=!0,n(r)},t);try{let a=await e;clearTimeout(u),s||n(a)}catch(a){clearTimeout(u),s||i(a)}})}o($o,"timeout");var wt=new Error("Timeout reached");function Bo(e){return e===bt||e===wt}o(Bo,"isTimeout");async function Tt(e,t){return t<=0?await e:new Promise(async(r,n)=>{let i=!1,s=setTimeout(()=>{i=!0,n(wt)},t);try{let u=await e;clearTimeout(s),i||r(u)}catch(u){clearTimeout(s),i||n(u)}})}o(Tt,"tryTimeout");function No(e,t,r=1e3){return new Promise((n,i)=>{let s=o(l=>{a&&(clearTimeout(a),u(),n(l))},"fn"),u=o(()=>{a=null,e.off?e.off(t,s):e.removeEventListener?e.removeEventListener(t,s):hr("No remove listener method found for",e,t)},"done"),a=setTimeout(()=>{u(),i(new Error("Did not response in time"))},r);e.on?e.on(t,s):e.addEventListener?e.addEventListener(t,s):hr("No listener method found for",e)})}o(No,"waitOn");function S(e){return Boolean(e&&(e instanceof Promise||typeof e.then=="function"))}o(S,"isPromise");function j(e){return Promise.resolve(e)}o(j,"promisify");var A=class{get value(){return this.days}constructor(t){var r;if(typeof t=="number"){this.days=t;return}if(t!=null&&(t=(r=A.from(t))==null?void 0:r.days),t==null){let n=new Date;this.days=n.getFullYear()*1e4+(n.getMonth()+1)*100+n.getDate()}else this.days=t}static fromNumber(t){return new A(t)}static fromString(t){return A.from(+t.replace(/[^0-9]/g,"").slice(0,8))}static fromDate(t,r=!1){return r?A.fromString(t.toISOString().substr(0,10)):A.from(t.getFullYear()*1e4+(t.getMonth()+1)*100+t.getDate())}static fromDateGMT(t){return A.fromDate(t,!0)}static from(t,r=!1){if(typeof t=="number")return t<100?void 0:new A(t);if(typeof t=="string")return A.fromString(t);if(Array.isArray(t)&&t.length===3){let[n,i=1,s=1]=t;return i<1||i>12||s<1||s>31?void 0:new A(n*1e4+i*100+s)}else{if(t instanceof Date)return A.fromDate(t,r);if(t instanceof A)return t}}toNumber(){return this.days}toJson(){return this.days}toString(t="-"){let r=String(this.days);return r.slice(0,4)+t+r.slice(4,6)+t+r.slice(6,8)}toDate(t=!1){return t?new Date(`${this.toString()}T00:00:00.000Z`):new Date(this.days/1e4,this.days/100%100-1,this.days%100)}toDateGMT(){return this.toDate(!0)}get year(){return Math.floor(this.days/1e4)}get month(){return Math.floor(this.days/100%100)}get day(){return Math.floor(this.days%100)}dayOffset(t){return A.fromDateGMT(new Date(this.toDateGMT().getTime()+t*864e5))}monthStart(){return A.from([this.year,this.month,1])}yearStart(){return A.from([this.year,1,1])}monthOffset(t){let r=this.month+t,n=Math.floor((r-1)%12)+1;n===0&&(n=12);let i=Math.floor((r-1)/12);return A.from([this.year+i,n,this.day])}daysUntil(t){var r;return Math.round((((r=new A(t))==null?void 0:r.toDateGMT().getTime())-this.toDateGMT().getTime())/864e5)}yesterday(){return this.dayOffset(-1)}tomorrow(){return this.dayOffset(1)}};o(A,"Day");async function Ho(e,t,r){let n=A.from(e),i=A.from(t);for(;n&&i&&(n==null?void 0:n.days)<=(i==null?void 0:i.days);){let s=r(n);S(s)&&await s,n=n.dayOffset(1)}}o(Ho,"forEachDay");function jo(){return new A}o(jo,"today");function Go(e){return new A(e)}o(Go,"day");function Vo(e){return A.fromDate(new Date(e)).days}o(Vo,"dateStringToDays");function xr(e,t=2){return+(+e).toFixed(t)}o(xr,"decimal");function zo(e,t=2){return+(+e/Math.pow(10,t)).toFixed(t)}o(zo,"decimalFromCents");function qo(e,t=2){return Math.round(+e*Math.pow(10,t))}o(qo,"decimalToCents");function _o(e,t=2){return t*(xr(e,t)%1)}o(_o,"decimalCentsPart");var Lt=o(e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,"""),"escapeHTML"),Jo=o(e=>e.replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,'"').replace(/'/gi,"'").replace(/&/gi,"&"),"unescapeHTML");var br=/[\u0000-\u001F\u0080-\u009F]/g,Wo=/^\.+/,Ko=/\.+$/;function wr(){return/[<>:"/\\|?*\u0000-\u001F]/g}o(wr,"filenameReservedRegex");function Zo(){return/^(con|prn|aux|nul|com\d|lpt\d)$/i}o(Zo,"windowsReservedNameRegex");function vt(e){if(typeof e!="string")throw new TypeError("Expected a string");let t="_";if(wr().test(t)&&br.test(t))throw new Error("Replacement string cannot contain reserved filename characters");return e=e.replace(wr(),t).replace(br,t).replace(Wo,t).replace(Ko,""),e=Zo().test(e)?e+t:e,e.slice(0,100)}o(vt,"toValidFilename");var Yo=/[\\\-\[\]\/{}()*+?.^$|]/g;function Qo(e){return e?e instanceof RegExp?e.source:e.replace(Yo,"\\$&"):""}o(Qo,"escapeRegExp");var ee=o(e=>Math.abs(e)%1===.5,"isHalf"),At=o(e=>e%2===0,"isEven"),Xo=o(e=>Math.ceil(e),"roundUp"),ei=o(e=>Math.floor(e),"roundDown"),ti=o(e=>Math.round(e),"roundHalfUp"),ri=o(e=>{let t=Math.round(e);return ee(e)&&At(t)?t-1:t},"roundHalfOdd"),ni=o(e=>ee(e)?Math.sign(e)*Math.ceil(Math.abs(e)):Math.round(e),"roundHalfAwayFromZero"),oi=o(e=>ee(e)?Math.floor(e):Math.round(e),"roundHalfDown"),ii=o(e=>{let t=Math.round(e);return ee(e)?At(t)?t:t-1:t},"roundHalfEven"),si=o(e=>ee(e)?Math.sign(e)*Math.floor(Math.abs(e)):Math.round(e),"roundHalfTowardsZero");function Et(e){return e.reduce((t,r)=>Math.min(t,r.sort_weight||0),0)-1-R()}o(Et,"startSortWeight");function Pt(e){return e.reduce((t,r)=>Math.max(t,r.sort_weight||0),0)+1+R()}o(Pt,"endSortWeight");function ai(e,t,r){let n=r.length,i=e<t;if(n<=0||e>=n-1)return Pt(r);if(e<=0)return Et(r);r=Tr([...r]);let s=i?-1:0,u=r[e+s].sort_weight||0,l=(r[e+s+1].sort_weight||0)-u;if(l===0)return i?Et(r):Pt(r);let c=u+l/2,p=l*.01*(R()-.5);return c+p}o(ai,"moveSortWeight");function Tr(e){return e.sort((t,r)=>(t.sort_weight||0)-(r.sort_weight||0)),e}o(Tr,"sortedItems");var ui=/((?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?)/gim;function li(e){return e.split(ui).map((t,r)=>{let n=Lt(t);return r%2?`<a target="_blank" href="${n}">${Lr(n)}</a>`:n}).join("")}o(li,"linkifyPlainText");function Lr(e){return e.replace(/^https?:\/\/(www\.)?/,"").replace(/\/$/,"")}o(Lr,"toHumanReadableUrl");function Dt(e){let t=[];for(let[r,n]of Object.entries(e))if(n!=null){Array.isArray(n)||(n=[n]);for(let i of n)i!=null&&t.push(encodeURIComponent(r)+"="+encodeURIComponent(String(i)))}return t.join("&")}o(Dt,"encodeQuery");function ci(e){let t={},r=(e[0]==="?"?e.substr(1):e).split("&");for(let n=0;n<r.length;n++){let i=r[n].split("="),s=decodeURIComponent(i[0]),u=decodeURIComponent(i[1]||"");t[s]!=null?(Array.isArray(t[s])||(t[s]=[t[s]]),t[s].push(u)):t[s]=u}return t}o(ci,"parseQuery");function fi(e,t,r){let n=e[t];return n===void 0&&(n=r(t,e),e[t]=n),n}o(fi,"ensureKey");async function pi(e,t,r){let n=e[t];return n===void 0&&(n=await r(t,e),e[t]=n),n}o(pi,"ensureKeyAsync");function di(e){return e!=null?e.size!=null?e.size:e.length!=null?e.length:Object.keys(e).length:0}o(di,"size");function gi(e){return e!=null&&e.length>0?e[e.length-1]:void 0}o(gi,"last");function mi(e){try{if(e!=null)return Array.isArray(e)||typeof e=="string"?e.length<=0:(e==null?void 0:e.size)!=null?e.size<=0:Object.keys(e).length<=0}catch(t){console.warn("Failed to check if empty for",e,t)}return!0}o(mi,"empty");function Z(e){return Object(e)!==e?e:JSON.parse(JSON.stringify(e))}o(Z,"cloneObject");function yi(e){return Object(e)!==e?e:JSON.parse(JSON.stringify(e))}o(yi,"cloneJsonObject");function hi(e){let t=new Map;return r=>{if(t.has(r))return t.get(r);let n=e(r);return t.set(r,n),n}}o(hi,"memoize");function xi(e,t){let r=[];for(let n=0;n<e;n++)r.push(t(n,e));return r}o(xi,"forTimes");var bi=/\\\s|\s+|#[^\n]*\n?/gm,wi=/\(\?P?<(\w[\w\d_]+)>|\((?!\?(:|\!|=|<=|<\!))/gm,vr=/^((?:\(\?[\w$]+\))?)\(\?<([=!])([\s\S]*?)\)/gm,Ti=L("xrx");function Ar(e){return typeof e=="string"?e:e.source||""}o(Ar,"regExpString");function Li(e){return e.replace(/[-\[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}o(Li,"regExpEscape");var He=class{constructor(t,r){this.namedGroups={};this.names=[];let n=r??"",i;if(t instanceof RegExp?(r==null&&(n=t.flags),i=t.source):i=t,n&&n.indexOf("x")!==-1&&(n=n.replace("x",""),i=i.replace(bi,a=>a[0]==="\\"?a:"")),!(t instanceof RegExp)){let a=0;i=i.replace(wi,(l,c)=>(a+=1,c?(c!=="index"&&c!=="length"&&!this.namedGroups[c]?this.namedGroups[c]=a:Ti.error(`Unallowed or duplicate group name: ${c}`),"("):l)),this.names=Object.keys(this.namedGroups)}i=Ar(i),vr.lastIndex=0;let u=vr.exec(i);u&&(this.lookBehind={rx:new RegExp(`${u[3]}$(?!\\s)`),expect:u?u[2]==="=":!u},i=i.substr(u[0].length)),this.rx=new RegExp(i,n)}get lastIndex(){return this.rx.lastIndex}set lastIndex(t){this.rx.lastIndex=t}_handleMatch(t){if(this.lookBehind){let r=t.input.slice(0,t.index);if(this.lookBehind.expect!==this.lookBehind.rx.test(r))return null}for(let r of this.names)t[r]=t[this.namedGroups[r]];return t}exec(t){let r;for(;r=this.rx.exec(t);)if(this.rx.lastIndex===r.index&&this.rx.lastIndex++,r=this._handleMatch(r),r!=null)return r}execAll(t){let r=[],n;for(this.rx.lastIndex=0;n=this.exec(t);)r.push(n);return this.rx.lastIndex=0,r}replace(t,r){let n=typeof r=="function"?r:()=>r;return t.replace(this.rx,i=>n(i))}};o(He,"XRX");var vi=L("dispose");async function Ai(e){typeof e=="function"?await j(e()):S(e)?await e:typeof e.dispose=="function"?await j(e.dispose()):S(e.dispose)?await e.dispose:typeof e.cleanup=="function"?await j(e.cleanup()):S(e.cleanup)&&await e.cleanup}o(Ai,"callDisposer");function je(e){let{name:t}=typeof e=="string"?{name:e}:e??{},r=[],n=o(async u=>{u!=null&&r.includes(u)&&(Ie(r,a=>a!==u),await Ai(u))},"untrack"),i=o(async()=>{for(t&&vi.debug(`dispose ${t}: ${r.length} entries`);r.length>0;)await n(r[0])},"dispose"),s=o(u=>{if(u!=null)return r.unshift(u),()=>n(u)},"track");return Object.assign(i,{track:s,add:s,untrack:n,dispose:i,exec:i,getSize(){return r.length}})}o(je,"useDispose");var Ei=je;function Pi(e={}){let{mode:t="fifo"}=e,r=[],n=o(async(s=!1)=>{for(;r.length>0;){let u=r[0];if(Ie(r,a=>a!==u),typeof u=="function"){let a=u();if(S(a)){if(s)throw new Error(`Expected sync only function, but found async: ${u}`);await a}}else if(S(u)){if(s)throw new Error(`Expected sync only function, but found async: ${u}`);await u}else throw new Error(`Unhandled disposable: ${u}`)}},"exec");return Object.assign(n,{add:o(s=>{t==="lifo"?r.unshift(s):r.push(s)},"add"),exec:n,getSize(){return r.length}})}o(Pi,"useDefer");function Di(e,t=0){let r=setTimeout(e,t);return()=>{r&&(clearTimeout(r),r=void 0)}}o(Di,"useTimeout");function Si(e,t){let r=setInterval(e,t);return()=>{r&&(clearInterval(r),r=void 0)}}o(Si,"useInterval");function Mi(e,t,r,...n){return e==null?()=>{}:(e.on?e.on(t,r,...n):e.addEventListener&&e.addEventListener(t,r,...n),()=>{e.off?e.off(t,r,...n):e.removeEventListener&&e.removeEventListener(t,r,...n)})}o(Mi,"useEventListener");function Ri(){let e=!0;return(t,r)=>{let n=!1;if(e){e=!1;try{t(),n=!0}finally{e=!0}}else r!==void 0&&r();return n}}o(Ri,"useMutex");function Ii(){let e=!0;return async(t,r)=>{let n=!1;if(e){e=!1;try{let i=t();S(i)&&await i,n=!0}finally{e=!0}}else if(r!==void 0){let i=r();S(i)&&await i}return n}}o(Ii,"useAsyncMutex");var te=L("zeed:emitter"),M=class{constructor(){this.subscribers={};this.subscribersOnAny=[];this.dispose=je();this.call=new Proxy({},{get:(t,r)=>(...n)=>this.emit(r,...n)})}async emit(t,...r){let n=!1;this.dispose.add(()=>{this.subscribers={},this.subscribersOnAny=[]});try{let i=this.subscribers[t]||[];if(this.subscribersOnAny.forEach(s=>s(t,...r)),i.length>0){let s=i.map(u=>{try{return j(u(...r))}catch(a){te.warn("emit warning:",a)}});n=!0,await Promise.all(s)}}catch(i){te.error("emit exception",i)}return n}onAny(t){this.subscribersOnAny.push(t)}on(t,r){let n=this.subscribers[t]||[];return n.push(r),this.subscribers[t]=n,()=>{this.off(t,r)}}onCall(t){for(let[r,n]of Object.entries(t))this.on(r,n)}once(t,r){let n=o(async(...i)=>(this.off(t,n),await j(r(...i))),"onceListener");return this.on(t,n),()=>{this.off(t,r)}}off(t,r){return this.subscribers[t]=(this.subscribers[t]||[]).filter(n=>r&&n!==r),this}removeAllListeners(){return this.subscribers={},this}};o(M,"Emitter");function Ui(){let e=Q().emitter;return e||(e=new M,Q().emitter=e),e}o(Ui,"getGlobalEmitter");var Ci=new M;function ki(e,t){let r=Math.round(R()*100);var n=[],i;let s=o((a,l)=>{let c={key:a,obj:l};n.push(c),i&&i()},"incoming");return t?e.on?e.on(t,a=>{s(t,a)}):e.addEventListener?e.addEventListener(t,a=>{s(t,a)}):te.error(r,"Cannot listen to key"):e.onAny?e.onAny((a,l)=>{s(a,l)}):te.error(r,"cannot listen to all for",e),o((a,l=!0)=>new Promise((c,p)=>{a||(a=t,a||n.length&&(a=n[0].key)),i=o(()=>{for(;n.length>0;){let g=n.shift();if(g.key===a)i=void 0,c(g.obj);else{if(l){te.warn(r,`Unhandled event ${a} with value: ${g.obj}`);continue}p(`Expected ${a}, but found ${g.key} with value=${g.obj}`),te.error(r,`Unhandled event ${a} with value: ${g.obj}`)}break}},"lazyResolve"),i()}),"on")}o(ki,"lazyListener");var re=o(()=>Date.now(),"getTimestamp");function St(e){return e>999?(e/1e3).toFixed(1)+"s":e.toFixed(2)+"ms"}o(St,"formatMilliseconds");function Fi(...e){for(let t of e){if(t instanceof Date)return t;if(typeof t=="string"){let r=null;if(t.includes(":"))try{r=new Date(t)}catch{}if(!(r instanceof Date)){let n=/(\d\d\d\d)-(\d\d)-(\d\d)/.exec(t);n&&(r=new Date(+n[1],+n[2]-1,+n[3],12,0))}if(r instanceof Date)return r}}}o(Fi,"parseDate");var{encode:Rt,decode:Er}=B(62),{encode:Pr,decode:Oi}=B(32);function It(){return K(16)}o(It,"uuidBytes");var $i=o(()=>new Uint32Array(K(4))[0],"uuid32bit");function G(){return Rt(It(),22)}o(G,"uuid");function Bi(e){return Rt(e,22)}o(Bi,"uuidEncode");function Ni(e){return Er(e,16)}o(Ni,"uuidDecode");function Hi(){return Pr(It(),26)}o(Hi,"uuidB32");function ji(e){return Pr(e,26)}o(ji,"uuid32Encode");function Gi(e){return Oi(e,16)}o(Gi,"uuid32Decode");var Mt={};function V(e="id"){return Mt[e]==null&&(Mt[e]=0),`${e}-${Mt[e]++}`}o(V,"uname");var Vi=0;function zi(){return`id-${Vi++}`}o(zi,"qid");var qi="10000000-1000-4000-8000-100000000000",_i=typeof crypto<"u"&&crypto.randomUUID!=null?crypto.randomUUID:()=>qi.replace(/[018]/g,e=>(e^K(1)[0]&15>>e/4).toString(16)),Dr=16e11;function Ji(e){var t=new Uint8Array([0,0,0,0,0,0]);let r=t.length-1;for(var n=0;n<t.length;n++){var i=e&255;t[r-n]=i,e=(e-i)/256}return t}o(Ji,"longToByteArray");function Sr(){let e=re()-Dr;return new Uint8Array([...Ji(e),...K(10)])}o(Sr,"suidBytes");function Wi(){return Rt(Sr(),22)}o(Wi,"suid");function Ki(e){return Mr(Er(e,16))}o(Ki,"suidDate");function Mr(e){return new Date(Dr+e.slice(0,6).reduce((t,r)=>t*256+r,0))}o(Mr,"suidBytesDate");var Rr=(n=>(n[n.waiting=0]="waiting",n[n.running=1]="running",n[n.finished=2]="finished",n))(Rr||{}),Ir=(n=>(n[n.replace=0]="replace",n[n.memoize=1]="memoize",n[n.error=2]="error",n))(Ir||{});function Zi(e={}){let{maxParallel:t=3}=e,r=new M,n=0,i=0,s=0,u=0,a={};async function l(){if(n>0){let[y,d]=xt();return r.once("didFinish",d),y}}o(l,"waitFinishAll");function c(){r.emit("didFinish"),n=0,i=0}o(c,"didFinish");function p(){let y=0,d=0;for(let{max:x,resolved:w,state:h}of Object.values(a))y+=x,d+=h===2?x:Math.min(x,w);r.emit("didUpdate",n,i,y,d)}o(p,"didUpdate");function g(){if(p(),n>0&&n===i&&c(),s>=t)return;let y=Object.values(a).filter(d=>d.state===0);if(y.length>0){let d;for(let x of y)(d==null||x.priority<d.priority)&&(d=x);if(d!=null){let x=d.id,w=d.done;d.state=1,++s,r.emit("didStart",x);let h=o(v=>{d&&(d.result=v,d.state=2,d.resolved=d.max),--s,++i,g()},"taskFinished");d.task(d).then(v=>{w(v),r.emit("didResolve",x,v),h(v)}).catch(v=>{w(),r.emit("didReject",x,v),h()})}}}o(g,"performNext");function f(y){let d=a[y];d&&d.state===0&&(a[y].state=2,++i,r.emit("didCancel",y),p())}o(f,"cancel");function m(){Object.keys(a).forEach(f)}o(m,"cancelAll");function b(y,d={}){let x,w=new Promise(v=>x=v),h=d.id??G();if(a[h]!=null){let v=d.idConflictResolution??1;if(v===0)f(h);else if(v===1){let T=a[h];return{id:h,promise:(async()=>{if(T.state===2)return a[h].result})(),dispose:()=>f(h),cancel:()=>f(h)}}else throw new Error(`Pool task with id=${h} already exists!`)}return a[h]={id:h,task:y,priority:++u,state:0,max:d.max??1,resolved:d.resolved??0,done:x,payload:d.payload,setMax(v){a[h].max=v,p()},setResolved(v){a[h].resolved=v,p()},incResolved(v=1){a[h].resolved+=v,p()}},++n,g(),{id:h,promise:w,dispose:()=>f(h),cancel:()=>f(h)}}return o(b,"enqueue"),{events:r,cancel:f,cancelAll:m,enqueue:b,dispose:m,waitFinishAll:l}}o(Zi,"usePool");var Ge=class extends M{constructor(r={}){super();this.queue=[];this.waitToFinish=[];this.countMax=0;this.countResolved=0;this.paused=!1;let{name:n=V("queue"),logLevel:i}=r;this.name=n,this.log=L(`zeed:queue:${n}`,i??1/0)}async performNext(){if(this.log("performNext, queue.length =",this.queue.length),this.currentTask!=null){this.log("performNext => skip while another task is running");return}if(this.paused){this.log("performNext => skip while is paused");return}for(;this.currentTask==null&&!this.paused;){let r=this.queue.shift();if(this.log(`performNext => ${r==null?void 0:r.name}`),r==null)break;this.countResolved===0&&this.emit("didStart",this.countMax);let{name:n,task:i,resolve:s}=r;this.currentTask=i();let u;try{this.log.info(`start task ${n}`),u=await this.currentTask,this.log(`finished task ${n} with result =`,u)}catch(a){this.log.warn("Error performing task",a)}s(u),this.currentTask=void 0,this.countResolved+=1,this.emit("didUpdate",this.countMax,this.countResolved)}for(this.queue.length===0&&(this.emit("didFinish"),this.countMax=0,this.countResolved=0);this.waitToFinish.length>0;)this.waitToFinish.shift()()}async enqueue(r,n={}){let{immediate:i=!1,name:s=V(this.name)}=n;return i?(this.log.info(`immediate execution ${s}`),await r()):(this.log(`enqueue ${s}`),new Promise(u=>{this.queue.push({name:s,task:r,resolve:u}),this.countMax+=1,this.emit("didUpdate",this.countMax,this.countResolved),this.performNext()}))}async enqueueReentrant(r,n={}){return this.enqueue(r,{immediate:this.currentTask!=null,name:n.name})}async cancelAll(r=!0){this.log("cancelAll"),this.emit("didCancel");let n=this.queue.map(i=>i.resolve);this.queue=[],n.forEach(i=>i(void 0)),await this.wait()}async pause(){this.log("pause"),this.paused=!0,await this.wait()}resume(){this.log("resume"),this.paused=!1,this.performNext()}async wait(){if(this.log("wait"),!(this.currentTask==null&&(this.queue.length===0||this.paused)))return new Promise(r=>{this.waitToFinish.push(r)})}get isPaused(){return this.paused}get hasTasks(){return this.queue.length!==0}};o(Ge,"SerialQueue");var oe=!1,ne=oe?L("zeed:throttle"):()=>{};function Yi(e,t={}){let{delay:r=100,trailing:n=!0,leading:i=!0}=t,s=0,u=0,a=0,l,c=Date.now();function p(){s&&(clearTimeout(s),s=void 0)}o(p,"clearExistingTimeout");function g(...f){let m=Date.now(),b=this,y=m-u;function d(){let w=Date.now();return`total ${(w-c).toFixed(1)}ms - elapsed ${(w-u).toFixed(1)}ms - visited ${a}x`}o(d,"debugElapsed");function x(){a=0,u=Date.now(),e.apply(b,f)}if(o(x,"exec"),l=x,y>r||!s){oe&&ne("elapsed",d()),i&&(y>r?(oe&&ne("\u{1F680} leading",d()),x()):++a);let w=y>r?r:r-y;ne(`\u23F1 start timeout with ${w.toFixed(1)}ms`,d()),p(),u=m,s=setTimeout(()=>{oe&&ne("\u23F1 reached timeout",d()),s=0,n&&(!i||a>0)&&(oe&&ne("\u{1F680} trailing",d()),l==null||l())},w)}else++a,oe&&ne("visited",d())}return o(g,"wrapper"),g.cancel=p,g.dispose=p,g}o(Yi,"throttle");function Qi(e,t={}){let{delay:r=100}=t,n=0;function i(){n&&(clearTimeout(n),n=0)}o(i,"clearExistingTimeout");function s(...u){let a=this;i(),n=setTimeout(()=>{n=0,e.apply(a,u)},r)}return o(s,"wrapper"),s.cancel=i,s.dispose=i,s}o(Qi,"debounce");function Xi(e=(t=>(t=globalThis==null?void 0:globalThis.location)==null?void 0:t.hostname)()??""){return["::ffff:127.0.0.1","localhost","127.0.0.1","","::1","::"].includes(e)||e.startsWith("192.168.")||e.startsWith("10.0.")||e.endsWith(".local")}o(Xi,"isLocalHost");function es(e){let{level:t=void 0,filter:r=void 0,messages:n=[]}=e,i=C(r),s=$(t);return u=>{!s(u.level)||!i(u.name)||n.push(u)}}o(es,"LoggerMemoryHandler");var me=class extends M{constructor(){super(...arguments);this.id=G()}close(){this.dispose()}};o(me,"Channel");var ie=class extends me{constructor(){super(...arguments);this.isConnected=!0}postMessage(r){var n;(n=this.other)==null||n.emit("message",{data:r,origin:"local",lastEventId:G()})}};o(ie,"LocalChannel");function ts(){let e=new ie,t=new ie;return e.other=t,t.other=e,[e,t]}o(ts,"createLocalChannelPair");var Ve=class{async encode(t){return t}async decode(t){return t}};o(Ve,"NoopEncoder");var z=class{async encode(t){return Pe(t)}async decode(t){return De(t)}};o(z,"JsonEncoder");var ze=class{constructor(t){this.key=t}async encode(t){let r=Pe(t);return await ct(r,this.key)}async decode(t){let r=await ft(t,this.key);return De(r)}};o(ze,"CryptoEncoder");var Ut=o((e,t,r={})=>new Proxy(r,{get:(n,i)=>i in n?n[i]:(...s)=>e(i,s,t)}),"createPromiseProxy");function rs(e={}){let{name:t=V("hub"),encoder:r=new z,retryAfter:n=1e3,ignoreUnhandled:i=!0,logLevel:s=!1}=e,u=L(t,s),a={},l,c=[],p,g={},f=o(()=>{clearTimeout(p)},"dispose"),m=o(async()=>{if(clearTimeout(p),l){if(l.isConnected)for(;c.length;){let x=c[0];try{l.postMessage(await r.encode(x)),c.shift()}catch(w){u.warn("postMessage",w);break}}c.length>0&&n>0&&(p=setTimeout(m,n))}},"postNext"),b=o(async x=>{u("enqueue postMessage",x),c.push(x),await m()},"postMessage"),y=o(async x=>{l=x,l.on("connect",m),l.on("message",async w=>{u("onmessage",typeof w);let{name:h,args:v,id:T,result:q,error:_}=await r.decode(w.data);if(h){u(`name ${h} id ${T}`);try{if(a[h]==null)throw new Error(`handler for ${h} was not found`);let U=a[h](...v);S(U)&&(U=await U),u(`result ${U}`),T&&b({id:T,result:U})}catch(U){let J=U instanceof Error?U:new Error(ke(U));u.warn("execution error",J.name),b({id:T,error:{message:J.message,stack:J.stack,name:J.name}})}}else if(T)if(u(`response for id=${T}: result=${q}, error=${_}`),g[T]==null)q===void 0?u(`skip response for ${T}`):u.warn(`no response hook for ${T}`);else{let[U,J]=g[T];if(U&&J)if(delete g[T],_){let Te=new Error(_.message);Te.stack=_.stack,Te.name=_.name,u.warn("reject",Te.name),J(Te)}else u("resolve",q),U(q)}else i||u.warn("Unhandled message",w)}),m()},"connect"),d=o(async(x,w,h={})=>{let{timeout:v=5e3}=h,T=G();return b({name:x,args:w,id:T}),Tt(new Promise((q,_)=>g[T]=[q,_]),v)},"fetchMessage");return e.channel&&y(e.channel),{dispose:f,connect:y,listen(x){Object.assign(a,x)},send(){return Ut(d,{},{options(x){return Ut(d,{...x})}})}}}o(rs,"useMessageHub");var ye=class extends M{constructor(r){super();this.publish=this.emit;this.subscribe=this.on;let{name:n,encoder:i=new z,channel:s,debug:u=!1}=r;this.channel=s,this.encoder=i,this.debug=u,this.name=n??this.channel.id??V("pubsub"),this.log=L(`${this.shortId}`),this.debug&&(this.channel.on("connect",()=>{this.log("channel connected")}),this.channel.on("disconnect",()=>{this.log("channel disconnected")})),this.channel.on("message",async({data:a})=>{let l=await this.encoder.decode(a);if(this.debug?this.log(`channel message, event=${l==null?void 0:l.event}, info=`,l):this.log(`channel message, event=${l==null?void 0:l.event}`),l){let{event:c,args:p}=l;await this.emitSuper(c,...p)}})}get shortId(){return this.name.substr(0,6)}async emitSuper(r,...n){return await super.emit(r,...n)}async emit(r,...n){try{if(this.debug?this.log(`emit(${String(r)})`,r):this.log(`emit(${String(r)})`,n.length),!this.channel.isConnected)return this.log.warn("channel not connected"),!1;let i=await this.encoder.encode({event:r,args:n});return this.channel.postMessage(i),!0}catch(i){this.log.warn(`emit(${String(r)})`,i)}return!1}};o(ye,"PubSub");function ns(e){return new ye(e)}o(ns,"usePubSub");var os=1;var Ur=o(e=>e,"defaultSerialize"),is=Ur;function ss(e,t){let{post:r,on:n,eventNames:i=[],serialize:s=Ur,deserialize:u=is}=t,a=new Map;return n(async l=>{let c=u(l),[p,g,f,m]=c;if(p===1||p===2){let b,y;if(m!=null)try{b=await e[m](...g)}catch(d){y=String(d)}else y="Method implementation missing";p===1&&f&&r(s(y?[4,y,f]:[3,b,f]))}else if(f){let b=a.get(f);b!=null&&(p===4?b.reject(g):b.resolve(g)),a.delete(f)}}),new Proxy({},{get(l,c){let p=o((...f)=>{r(s([2,f,null,c]))},"sendEvent");if(t.onlyEvents||i.includes(c))return p.asEvent=p,p;let g=o((...f)=>new Promise((m,b)=>{let y=os++;a.set(y,{resolve:m,reject:b}),r(s([1,f,y,c]))}),"sendCall");return g.asEvent=p,g}})}o(ss,"useRPC");var Y=L("network"),Ct={cache:"no-cache",redirect:"follow",headers:{}};function Cr(e){let t=/:\/\/([^@]*)@/gi.exec(e);if(t&&t[1]){let[r,n]=t[1].split(":",2);return{url:e.replace(t[1]+"@",""),username:r,password:n}}}o(Cr,"parseBasicAuth");async function kt(e,t={},r=fetch){try{Le(t)&&(t=ce({},...F(t)));let n=Cr(String(e));n&&(e=n.url,t=ce({},t,kr(n.username,n.password))),t.headers!=null&&!(t.headers instanceof Headers)&&(t.headers=new Headers(t.headers)),Y("fetch",e,t);let i=await r(String(e),t);if(i.status<400)return i;try{Y.warn(`Fetch of ${e} with ${t} returned status=${i.status}`),Y.warn(`Response: ${await i.text()}`)}catch(s){Y.error("Exception:",s)}}catch(n){Y.error("fetchBasic",n)}}o(kt,"fetchBasic");async function as(e,t={},r=fetch){try{let n=await kt(e,[{method:"GET",headers:{Accept:"application/json"}},t],r);if(n)return await n.json()}catch(n){Y.error("fetchJSON error:",n)}}o(as,"fetchJson");async function us(e,t={},r=fetch){try{let n=await kt(e,[Ct,{method:"GET"},t],r);if(n)return await n.text()}catch(n){Y.error("fetchHTML error:",n)}}o(us,"fetchText");function ls(e,t="POST"){return{method:t,...Ct,headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:Dt(e)}}o(ls,"fetchOptionsFormURLEncoded");function cs(e,t="POST"){return{method:t,...Ct,headers:{"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify(e)}}o(cs,"fetchOptionsJson");function kr(e,t){return{headers:{Authorization:"Basic "+st(e+":"+t)}}}o(kr,"fetchOptionsBasicAuth");function Ft(){if(typeof window<"u")return window}o(Ft,"getWindow");function Fr(){if(typeof navigator<"u")return navigator}o(Fr,"getNavigator");function fs(){return Ft()??typeof WorkerGlobalScope<"u"?self:typeof global<"u"?global:Function("return this;")()}o(fs,"getGlobal");var E=Fr(),P=Ft();function Or(e={ios:!1,macos:!1,windows:!1,beaker:!1,electron:!1,wkwebview:!1,pwa:!1,pwaInstalled:!1,browser:!1,node:!1,worker:!1,test:!1,jest:!1,macosNative:!1,iosNative:!1,appleNative:!1,touch:!1}){var t,r,n,i,s,u,a,l,c;return e.ios=((t=E==null?void 0:E.platform)==null?void 0:t.match(/(iPhone|iPod|iPad)/i))!=null,e.macos=!!((r=E==null?void 0:E.platform)!=null&&r.startsWith("Mac")),e.windows=!!((n=E==null?void 0:E.platform)!=null&&n.startsWith("Win")),e.beaker=(P==null?void 0:P.beaker)!=null,e.electron=(((s=(i=E==null?void 0:E.userAgent)==null?void 0:i.toLowerCase())==null?void 0:s.indexOf(" electron/"))||-1)>-1&&!e.beaker,e.wkwebview=((u=P==null?void 0:P.webkit)==null?void 0:u.messageHandlers)!=null,e.pwa=(E==null?void 0:E.serviceWorker)!=null,e.pwaInstalled=(E==null?void 0:E.standalone)||((l=(a=P==null?void 0:P.matchMedia)==null?void 0:a.call(P,"(display-mode: standalone)"))==null?void 0:l.matches),e.node=typeof process<"u"&&((c=process==null?void 0:process.release)==null?void 0:c.name)==="node",e.browser=!e.electron&&!e.wkwebview&&!e.node,e.worker=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,e.jest=typeof jest<"u"||typeof vitest<"u",e.test=e.jest,e.macosNative=e.wkwebview&&e.macos,e.iosNative=e.wkwebview&&e.ios,e.appleNative=e.wkwebview,e.touch=P&&"ontouchstart"in P||((E==null?void 0:E.maxTouchPoints)||0)>1||(E==null?void 0:E.msPointerEnabled)&&(P==null?void 0:P.MSGesture)||(P==null?void 0:P.DocumentTouch)&&document instanceof DocumentTouch,e}o(Or,"detect");var $r=o(()=>typeof window<"u"&&globalThis===window,"isBrowser"),ps=Or();function ds(e){$r()?window.addEventListener("beforeunload",e):typeof process<"u"&&process.on("exit",()=>e)}o(ds,"useExitHandler");var Fl=L("zeed:memstorage"),qe=class{constructor(t={}){this.store={}}setItem(t,r){this.store[t]=Z(r)}getItem(t){if(this.store.hasOwnProperty(t))return Z(this.store[t])}removeItem(t){delete this.store[t]}clear(){this.store={}}allKeys(){return Object.keys(this.store)}};o(qe,"MemStorage");function gs(e={}){let{args:t=process.argv.slice(1),alias:r={},normalize:n=dt,booleanArgs:i=[],listArgs:s=[],numberArgs:u=[]}=e,a=Object.entries(r).reduce((f,m)=>{let[b,y]=m;typeof y=="string"&&(y=[y]);for(let d of y)f[n(d)]=n(b);return f},{}),l={_:[]};function c(f,m){l[f]==null||typeof l[f]=="boolean"?l[f]=m:Array.isArray(l[f])?l[f].push(m):l[f]=[l[f],m]}o(c,"setOpt");let p=[...t],g;for(;g=p.shift();){let f;if(/^--?/.test(g)){let m=g.replace(/^--?/,"");if(g.includes("=")){let[b,y]=m.split("=",2);m=b.trim(),f=y.trim()}m=n(m),m=a[m]??m,i.includes(m)?c(m,!0):(f=f??p.shift()??"",u.includes(m)&&(f=Number(f??0)),s.includes(m)?Array.isArray(l[m])?l[m].push(f):l[m]=[f]:c(m,f))}else l._.push(g)}return l}o(gs,"parseArgs");var Br=require("child_process");function ms(e){return new Promise(async(t,r)=>{let n=(0,Br.spawn)("pbcopy");n.on("error",i=>r(i)),n.on("close",()=>t(e)),n.stdin.write(e),n.stdin.end()})}o(ms,"pbcopy");var _e=et(require("crypto"),1);try{_e.default&&_e.default.webcrypto&&typeof globalThis<"u"&&typeof globalThis.crypto>"u"&&(globalThis.crypto=_e.default.webcrypto)}catch(e){console.warn("Failed to polyfill webcrypto",e)}var he=et(require("fs"),1),Hr=require("path");var xe=L("zeed:env"),ys=`
|
|
8
|
+
`,hs=/^\s*([\w_.-]+)\s*=\s*(.*)?\s*$/,xs=/\\n/g,bs=/\n|\r|\r\n/;function Nr(e,t={}){let r={};return String(e).split(bs).forEach(function(n,i){let s=n.match(hs);if(s!=null){let u=s[1],a=s[2]||"",l=a.length-1,c=a[0]==='"'&&a[l]==='"';a[0]==="'"&&a[l]==="'"||c?(a=a.substring(1,l),c&&(a=a.replace(xs,ys))):a=a.trim(),r[u]=a}else xe.debug(`did not match key and value when parsing line ${i+1}: ${n}`)}),r}o(Nr,"parse");function jr(e,t="."){return(0,Hr.resolve)(process.cwd(),e??t)}o(jr,"stringToPath");function Gr(e,t=""){return e==null&&(e=t),jr(String(e).trim(),t)}o(Gr,"valueToPath");var Je=Gr;function ws(e={}){let t=(e==null?void 0:e.path)??Je((e==null?void 0:e.filename)??".env"),r=(e==null?void 0:e.encoding)??"utf8",n=(e==null?void 0:e.debug)||!1;n!==!0&&(xe.level=1/0);try{let i=he.default.existsSync(t)?Nr(he.default.readFileSync(t,{encoding:r}),{debug:n}):{},s=he.default.existsSync(t+".local")?Nr(he.default.readFileSync(t+".local",{encoding:r}),{debug:n}):{},u=Object.assign({},i,s),a=(e==null?void 0:e.env)??process.env;return Object.entries(u).forEach(([l,c])=>{typeof(e==null?void 0:e.prefix)=="string"&&(l=(e==null?void 0:e.prefix)+l),Object.prototype.hasOwnProperty.call(a,l)?xe.debug(`"${l}" is already defined and will not be overwritten`):c!=null&&(xe.info(`set env.${l} = ${c}`),a[l]=c)}),{parsed:u}}catch(i){return xe.error(i),{error:i}}}o(ws,"setupEnv");var I=require("fs"),be=require("path");var Ot=L("zeed:filestorage"),We=class{constructor(t={}){this.store={};this.fileKeys=void 0;this.pretty=!1;this.dirname=(0,be.resolve)(process.cwd(),t.path||".fileStorage"),this.pretty=!!t.pretty,this.extension=t.extension??".json",t.extension&&!this.extension.startsWith(".")&&(this.extension="."+this.extension),this.extensionLength=this.extension.length,this.objectToString=t.objectToString??(r=>this.pretty?JSON.stringify(r,null,2):JSON.stringify(r)),this.objectFromString=t.objectFromString??(r=>{try{return JSON.parse(r)}catch(n){Ot.warn(`fileStorage parse error '${n}' in`,r)}}),this.keyToFilename=t.keyToFilename??vt}setItem(t,r){this.store[t]=Z(r);try{let n=this.objectToString(r),i=this.getPath(t);(0,I.mkdirSync)((0,be.dirname)(i),{recursive:!0}),(0,I.writeFileSync)(i,n,"utf8")}catch(n){Ot.error("setItem error",n)}}getPath(t){return(0,be.resolve)(this.dirname,this.keyToFilename(t)+this.extension)}getBuffer(t){let r=this.getPath(t);return Buffer.from((0,I.readFileSync)(r))}getItem(t){let r=this.store[t];if(r!==null){if(r!=null)return Z(r);try{let n=this.getPath(t),i=(0,I.readFileSync)(n,"utf8");if(i!=null){let s=this.objectFromString(i);return this.store[t]=s,s}}catch(n){Ot.warn("getItem error",n),this.store[t]=null}}}removeItem(t){if(delete this.store[t],this.fileKeys!=null){let r=this.fileKeys.indexOf(t);r!==-1&&this.fileKeys.splice(r,1)}try{let r=this.getPath(t);(0,I.unlinkSync)(r)}catch{}}clear(){this.fileKeys=[],this.store={},(0,I.rmSync)(this.dirname,{recursive:!0,force:!0})}allKeys(){if(this.fileKeys==null)try{this.fileKeys=(0,I.readdirSync)(this.dirname,{withFileTypes:!0}).filter(r=>!r.isDirectory()&&r.name.endsWith(this.extension)).map(r=>r.name.slice(0,-this.extensionLength))||[]}catch{}let t=[...this.fileKeys||[]];for(let r of Object.keys(this.store))t.includes(r)||t.push(r);return t.sort(),t}};o(We,"FileStorage");var O=require("fs/promises"),se=require("path");function Ts(e){let t=(0,se.normalize)(e),r=process.env.HOME;return r&&t.startsWith(r)?"~"+t.slice(r.length):t}o(Ts,"toHumanReadableFilePath");async function Ke(e){try{await(0,O.stat)(e)}catch{return!1}return!0}o(Ke,"exists");async function Ls(...e){let t=(0,se.join)(...e);return await Ke(t)||await(0,O.mkdir)(t,{recursive:!0}),t}o(Ls,"ensureFolder");async function vs(...e){let t=(0,se.join)(...e);return await Ke(t)&&await(0,O.rm)(t,{recursive:!0}),t}o(vs,"removeFolder");async function As(...e){let t=(0,se.join)(...e);if(await Ke(t))return await(0,O.readFile)(t,"utf-8")}o(As,"readText");async function Es(e,t){await(0,O.writeFile)(e,t,"utf-8")}o(Es,"writeText");var Ze=require("fs"),Ye=require("path");var Vr={};function $t(e,t={}){let{level:r=-1,filter:n="*"}=t;e=(0,Ye.resolve)(process.cwd(),e),(0,Ze.mkdirSync)((0,Ye.dirname)(e),{recursive:!0});var i=(0,Ze.createWriteStream)(e,{flags:"a"});let s=C(n),u=$(r);return a=>{if(!u(a.level)||!s(a.name))return;let l=new Date().toISOString(),c=a.name||"",p=Vr[c||""];p==null&&(Vr[c]=p);let g=[`[${c||"*"}]`,pe(a.messages,{pretty:!1})];function f(...m){i.write(m.join(" ")+`
|
|
9
|
+
`)}switch(o(f,"write"),a.level){case 1:f(l,"I|* ",...g);break;case 2:f(l,"W|** ",...g);break;case 3:f(l,"E|***",...g);break;default:f(l,"D| ",...g);break}}}o($t,"LoggerFileHandler");var Zr=et(require("tty"),1);var Ht=require("path");function _r(e){var t,r;return typeof e!="string"?[]:((r=(t=e==null?void 0:e.split(`
|
|
10
|
+
`))==null?void 0:t.map(n=>{let i=n.match(/^\s+at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/);if(i){let s=i[3]||i[2]||i[4];return s.endsWith(")")&&(s=s.slice(0,-1)),s}}))==null?void 0:r.filter(n=>n!=null))||[]}o(_r,"getStackLlocationList");var Bt=(0,Ht.resolve)(process.cwd()),zr,qr,Nt=(zr=process.env)!=null&&zr.HOME?(0,Ht.resolve)((qr=process.env)==null?void 0:qr.HOME):"";function Jr(e){if(e.includes("/node_modules/"))return"";let t="file://";return e.startsWith(t)?e.substr(t.length):Bt&&e.startsWith(Bt)?e.substr(Bt.length+1):(Nt&&e.startsWith(Nt)&&(e="~/"+e.substr(Nt.length+1)),e)}o(Jr,"pathStripCwd");function Ps(e){let t=e.match(/^\s*at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/);if(t){let r=t[3]||t[2]||t[4];return r.endsWith(")")&&(r=r.slice(0,-1)),r}return""}o(Ps,"extractFileInfo");function Qe(e=2,t=!0){var i;let r=new Error().stack||"",n=(i=_r(r))==null?void 0:i[e];return n&&t&&(n=Jr(n)),n||""}o(Qe,"getSourceLocation");function jt(){return new Error().stack||""}o(jt,"getStack");function Gt(e,t=!0){let r="",n=new Error().stack||"";if(typeof n=="string"){let i=n.split(`
|
|
11
|
+
`).map(u=>u.trim()),s=i.findIndex(u=>e.some(a=>u.startsWith(a)));r=i[s+1],r&&(r=Ps(r)),r&&t&&(r=Jr(r))}return r}o(Gt,"getSourceLocationByPrecedingPattern");function Ds(){try{return Ce(process.env.ZEED_COLOR,Zr.default.isatty(process.stdout.fd))}catch{}return!1}o(Ds,"shouldUseColor");var Ss=Ds(),Wr=[6,2,3,4,5,1];function Ms(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return Wr[Math.abs(t)%Wr.length]}o(Ms,"selectColor");var Kr={},Rs=re();function Xe(...e){process.stdout.write(pe(e)+`
|
|
12
|
+
`)}o(Xe,"log");var we={BOLD:"\x1B[1m",UNBOLD:"\x1B[2m",RED:"\x1B[31m",GREEN:"\x1B[32m",BLUE:"\x1B[34m",PURPLE:"\x1B[35m",GRAY:"\x1B[37m",ORANGE:"\x1B[38;5;208m",UNCOLOR:"\x1B[0m"};var Yr="\x1B[0m";function ae(e,t){return`${t===8?we.ORANGE:"\x1B[3"+(t<8?t:"8;5;"+t)+"m"}${e}${Yr}`}o(ae,"colorString");function Vt(e,t,r=!0){return e.map(n=>{if(typeof n!="string")return n;let i=t,s=Yr;return r&&(i=`${we.BOLD}${i}`,s=`${s}${we.BOLD}`),`${i}${n}${s}`})}o(Vt,"colorStringList");var Qr="loggerStackTraceDebug-7d38e5a9214b58d29734374cdb9521fd964d7485";function zt(e={}){let{level:t=void 0,filter:r=void 0,colors:n=Ss,levelHelper:i=!0,nameBrackets:s=!0,padding:u=0,fill:a=0,stack:l=!0}=e,c=C(r),p=$(t);return g=>{var v;if(!p(g.level)||!c(g.name))return;let f=re(),m=g.name||"",b=Kr[m||""];b==null&&(b={color:Ms(m)},Kr[m]=b);let y=St(f-Rs),d,x=s?`[${m}]`:m;if(u>0&&(x=x.padStart(u," ")),a>0&&(x=x.padEnd(a," ")),n){let T=b.color;d=[ae(x,T)+" | "],g.level===2?d.push(...Vt(g.messages,we.ORANGE)):g.level===3?d.push(...Vt(g.messages,we.RED)):d.push(...g.messages),d.push(ae(`+${y}`,T))}else d=[x,...g.messages],d.push(`+${y}`);if(((v=g.messages)==null?void 0:v[0])===Qr&&console.log(jt()),l){let T="";typeof l=="boolean"?(T=Gt(["at Function.","at null.log (","at log ("],!0),T||(T=Qe(0,!0))):T=Qe(typeof l=="number"?l:3,!0),T&&d.push(ae(`(${T})`,7))}let w="|",h=".";switch(g.level){case 1:i&&(d[0]=`I${w}${h} `+d[0]),Xe(...d);break;case 2:i&&(d[0]=(n?ae(`W${w}${h}${h} `,8):`W${w}${h}${h} `)+d[0]),Xe(...d);break;case 3:i&&(d[0]=(n?ae(`E${w}${h}${h}${h} `,1):`E${w}${h}${h}${h} `)+d[0]),Xe(...d);break;default:i&&(d[0]=`D${w} `+d[0]),Xe(...d);break}}}o(zt,"LoggerNodeHandler");function Is(){let e=[zt({padding:32,nameBrackets:!1})],t=process.env.ZEED_LOG??process.env.LOG;t&&e.unshift($t(Je(t))),L.setHandlers(e)}o(Is,"setupLogContextNode");Is();0&&(module.exports={Channel,CryptoEncoder,Currency,DAY_MS,Day,Emitter,FileStorage,JsonEncoder,LocalChannel,LogLevel,LogLevelAlias,Logger,LoggerConsoleHandler,LoggerContext,LoggerFileHandler,LoggerMemoryHandler,LoggerNodeHandler,MemStorage,NoopEncoder,PoolTaskIdConflictResolution,PoolTaskState,PubSub,SerialQueue,Uint8ArrayToHexDump,Uint8ArrayToJson,Uint8ArrayToString,XRX,_decodeUtf8Polyfill,_encodeUtf8Polyfill,arrayAvg,arrayBatches,arrayEmptyInPlace,arrayFilterInPlace,arrayFlatten,arrayIntersection,arrayIsEqual,arrayMax,arrayMin,arrayMinus,arrayRandomElement,arrayRemoveElement,arraySetElement,arrayShuffle,arrayShuffleForce,arrayShuffleInPlace,arraySorted,arraySortedNumbers,arraySum,arraySymmetricDifference,arrayToggleInPlace,arrayUnion,arrayUnique,avg,between,cloneJsonObject,cloneObject,cmp,colorString,colorStringList,composeOrderby,createArray,createLocalChannelPair,createPromise,createPromiseProxy,csv,currency,dateStringToDays,day,dayDay,dayDiff,dayFromAny,dayFromDate,dayFromDateGMT,dayFromParts,dayFromString,dayFromTimestamp,dayFromToday,dayMonth,dayMonthStart,dayOffset,dayToDate,dayToDateGMT,dayToParts,dayToString,dayToTimestamp,dayYear,dayYearStart,debounce,decimal,decimalCentsPart,decimalFromCents,decimalToCents,decodeBase16,decodeBase32,decodeBase58,decodeBase62,decodeBase64,decrypt,deepEqual,deepMerge,deriveKeyPbkdf2,detect,digest,empty,encodeBase16,encodeBase32,encodeBase58,encodeBase62,encodeBase64,encodeQuery,encrypt,endSortWeight,ensureFolder,ensureKey,ensureKeyAsync,equalBinary,escapeHTML,escapeRegExp,exists,fetchBasic,fetchJson,fetchOptionsBasicAuth,fetchOptionsFormURLEncoded,fetchOptionsJson,fetchText,fixBrokenUth8String,forEachDay,forTimes,formatMessages,formatMilliseconds,fromBase64,fromCamelCase,getGlobal,getGlobalContext,getGlobalEmitter,getNamespaceFilterString,getNavigator,getSecureRandom,getSecureRandomIfPossible,getSourceLocation,getSourceLocationByPrecedingPattern,getStack,getStackLlocationList,getTimestamp,getWindow,immediate,isArray,isBoolean,isBrowser,isEven,isHalf,isInteger,isLocalHost,isNullOrUndefined,isNumber,isObject,isPrime,isPrimeRX,isPrimitive,isPromise,isRecord,isSafeInteger,isString,isTimeout,isUint8Array,joinToUint8Array,jsonStringify,jsonToUint8Array,last,lazyListener,linkifyPlainText,loggerStackTraceDebug,memoize,messages,moveSortWeight,parseArgs,parseBasicAuth,parseDate,parseLogLevel,parseOrderby,parseQuery,pbcopy,platform,promisify,qid,randomBoolean,randomFloat,randomInt,randomUint8Array,readText,regExpEscape,regExpString,removeFolder,renderMessages,roundDown,roundHalfAwayFromZero,roundHalfDown,roundHalfEven,roundHalfOdd,roundHalfTowardsZero,roundHalfUp,roundUp,setupEnv,size,sleep,sortedItems,sortedOrderby,startSortWeight,stringToBoolean,stringToFloat,stringToInteger,stringToPath,stringToUInt8Array,suid,suidBytes,suidBytesDate,suidDate,sum,throttle,timeout,timeoutReached,timoutError,toBase64,toBase64Url,toBool,toCamelCase,toCapitalize,toCapitalizeWords,toFloat,toHex,toHumanReadableFilePath,toHumanReadableUrl,toInt,toPath,toString,toUint8Array,toValidFilename,today,tryTimeout,uname,unescapeHTML,useAsyncMutex,useBase,useDefer,useDispose,useDisposer,useEventListener,useExitHandler,useInterval,useLevelFilter,useMessageHub,useMutex,useNamespaceFilter,usePool,usePubSub,useRPC,useTimeout,uuid,uuid32Decode,uuid32Encode,uuid32bit,uuidB32,uuidBytes,uuidDecode,uuidEncode,uuidv4,valueToBoolean,valueToFloat,valueToInteger,valueToPath,valueToString,waitOn,writeText});
|
|
4480
13
|
//# sourceMappingURL=index.node.cjs.map
|