@adviser/cement 0.3.19 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base-sys-abstraction-DgTynXGV.d.cts +95 -0
- package/base-sys-abstraction-h0dB3nZ5.d.ts +95 -0
- package/cf/index.cjs +232 -283
- package/cf/index.cjs.map +1 -1
- package/cf/index.d.cts +10 -8
- package/cf/index.d.ts +10 -8
- package/cf/index.js +6 -41
- package/cf/index.js.map +1 -1
- package/{chunk-GDTTUMIL.js → chunk-6F3ACVHD.js} +62 -22
- package/chunk-6F3ACVHD.js.map +1 -0
- package/{chunk-PHS255C5.js → chunk-FOALXQST.js} +1 -68
- package/chunk-FOALXQST.js.map +1 -0
- package/{chunk-23MCJYE6.js → chunk-X3IV2RYT.js} +422 -602
- package/chunk-X3IV2RYT.js.map +1 -0
- package/chunk-YKGCONBX.js +677 -0
- package/chunk-YKGCONBX.js.map +1 -0
- package/{chunk-55W4AK2Z.js → chunk-YVACAIUX.js} +5 -5
- package/deno/index.cjs +257 -241
- package/deno/index.cjs.map +1 -1
- package/deno/index.d.cts +3 -5
- package/deno/index.d.ts +3 -5
- package/deno/index.js +14 -16
- package/deno/index.js.map +1 -1
- package/{index-D1j1fPYg.d.ts → index-N0bkrgSt.d.ts} +15 -3
- package/{index-Cp1NspHH.d.cts → index-TtYD7HhB.d.cts} +15 -3
- package/index.cjs +1851 -1709
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -8
- package/index.d.ts +9 -8
- package/index.js +21 -16
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +499 -474
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +3 -5
- package/node/index.d.ts +3 -5
- package/node/index.js +14 -16
- package/node/index.js.map +1 -1
- package/package.json +6 -6
- package/src/base-sys-abstraction.ts +106 -116
- package/src/cf/cf-basic-sys-abstraction.ts +79 -0
- package/src/cf/index.ts +1 -1
- package/src/cf-test-main.ts +10 -1
- package/src/deno/deno-basic-sys-abstraction.ts +39 -0
- package/src/deno/deno-file-service.ts +1 -1
- package/src/deno/deno-sys-abstraction.ts +19 -22
- package/src/jsr.json +1 -1
- package/src/log-writer-impl.ts +6 -0
- package/src/logger-impl.ts +17 -19
- package/src/node/node-basic-sys-abstraction.ts +59 -0
- package/src/node/node-sys-abstraction.ts +19 -22
- package/src/sys-abstraction.ts +12 -6
- package/src/test/mock-logger.ts +2 -2
- package/src/txt-en-decoder.ts +3 -3
- package/src/uri.ts +71 -0
- package/src/web/index.ts +1 -1
- package/src/web/web-basic-sys-abstraction.ts +105 -0
- package/{sys-abstraction-B0x6IE7r.d.ts → sys-abstraction-CeAxxg9H.d.ts} +11 -7
- package/{sys-abstraction-BTs3Vzy4.d.cts → sys-abstraction-DDAwGTnk.d.cts} +11 -7
- package/test/index.cjs +1534 -1419
- package/test/index.cjs.map +1 -1
- package/test/index.d.cts +2 -2
- package/test/index.d.ts +2 -2
- package/test/index.js +4 -5
- package/ts/smoke/smoke.js +7 -8
- package/ts/smoke/smoke.js.map +1 -1
- package/ts/src/base-basic-sys-abstraction.test.d.ts +2 -0
- package/ts/src/base-basic-sys-abstraction.test.d.ts.map +1 -0
- package/ts/src/{base-sys-abstraction.test.js → base-basic-sys-abstraction.test.js} +9 -9
- package/ts/src/base-basic-sys-abstraction.test.js.map +1 -0
- package/ts/src/base-sys-abstraction.d.ts +33 -21
- package/ts/src/base-sys-abstraction.d.ts.map +1 -1
- package/ts/src/base-sys-abstraction.js +54 -67
- package/ts/src/base-sys-abstraction.js.map +1 -1
- package/ts/src/cf/cf-basic-sys-abstraction.d.ts +14 -0
- package/ts/src/cf/cf-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/cf/cf-basic-sys-abstraction.js +67 -0
- package/ts/src/cf/cf-basic-sys-abstraction.js.map +1 -0
- package/ts/src/cf/index.d.ts +1 -1
- package/ts/src/cf/index.d.ts.map +1 -1
- package/ts/src/cf/index.js +1 -1
- package/ts/src/cf/index.js.map +1 -1
- package/ts/src/cf-test-main.d.ts.map +1 -1
- package/ts/src/cf-test-main.js +7 -1
- package/ts/src/cf-test-main.js.map +1 -1
- package/ts/src/deno/deno-basic-sys-abstraction.d.ts +14 -0
- package/ts/src/deno/deno-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/deno/deno-basic-sys-abstraction.js +35 -0
- package/ts/src/deno/deno-basic-sys-abstraction.js.map +1 -0
- package/ts/src/deno/deno-file-service.d.ts +1 -1
- package/ts/src/deno/deno-file-service.d.ts.map +1 -1
- package/ts/src/deno/deno-sys-abstraction.d.ts +3 -6
- package/ts/src/deno/deno-sys-abstraction.d.ts.map +1 -1
- package/ts/src/deno/deno-sys-abstraction.js +13 -17
- package/ts/src/deno/deno-sys-abstraction.js.map +1 -1
- package/ts/src/log-writer-impl.d.ts +1 -0
- package/ts/src/log-writer-impl.d.ts.map +1 -1
- package/ts/src/log-writer-impl.js +1 -0
- package/ts/src/log-writer-impl.js.map +1 -1
- package/ts/src/logger-impl.d.ts +3 -3
- package/ts/src/logger-impl.d.ts.map +1 -1
- package/ts/src/logger-impl.js +3 -18
- package/ts/src/logger-impl.js.map +1 -1
- package/ts/src/logger.test.js +3 -4
- package/ts/src/logger.test.js.map +1 -1
- package/ts/src/node/node-basic-sys-abstraction.d.ts +25 -0
- package/ts/src/node/node-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/node/node-basic-sys-abstraction.js +44 -0
- package/ts/src/node/node-basic-sys-abstraction.js.map +1 -0
- package/ts/src/node/node-sys-abstraction.d.ts +3 -6
- package/ts/src/node/node-sys-abstraction.d.ts.map +1 -1
- package/ts/src/node/node-sys-abstraction.js +13 -17
- package/ts/src/node/node-sys-abstraction.js.map +1 -1
- package/ts/src/node/node-sys-abstraction.test.js +1 -1
- package/ts/src/node/node-sys-abstraction.test.js.map +1 -1
- package/ts/src/resolve-once.test.js +1 -1
- package/ts/src/sys-abstraction.d.ts +10 -6
- package/ts/src/sys-abstraction.d.ts.map +1 -1
- package/ts/src/test/mock-logger.d.ts +2 -2
- package/ts/src/test/mock-logger.d.ts.map +1 -1
- package/ts/src/test/mock-logger.js.map +1 -1
- package/ts/src/tracer.test.js +5 -8
- package/ts/src/tracer.test.js.map +1 -1
- package/ts/src/txt-en-decoder.d.ts.map +1 -1
- package/ts/src/txt-en-decoder.js +3 -3
- package/ts/src/txt-en-decoder.js.map +1 -1
- package/ts/src/uri.d.ts +12 -0
- package/ts/src/uri.d.ts.map +1 -1
- package/ts/src/uri.js +55 -0
- package/ts/src/uri.js.map +1 -1
- package/ts/src/uri.test.js +48 -0
- package/ts/src/uri.test.js.map +1 -1
- package/ts/src/web/index.d.ts +1 -1
- package/ts/src/web/index.d.ts.map +1 -1
- package/ts/src/web/index.js +1 -1
- package/ts/src/web/index.js.map +1 -1
- package/ts/src/web/web-basic-sys-abstraction.d.ts +4 -0
- package/ts/src/web/web-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/web/web-basic-sys-abstraction.js +45 -0
- package/ts/src/web/web-basic-sys-abstraction.js.map +1 -0
- package/ts/vitest.workspace.d.ts +1 -1
- package/utils/index.cjs +132 -3
- package/utils/index.cjs.map +1 -1
- package/utils/index.js +5 -5
- package/web/index.cjs +277 -281
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +4 -17
- package/web/index.d.ts +4 -17
- package/web/index.js +4 -7
- package/base-sys-abstraction-BnBZ6zd0.d.ts +0 -84
- package/base-sys-abstraction-DAZ8tx5F.d.cts +0 -84
- package/chunk-23MCJYE6.js.map +0 -1
- package/chunk-GDTTUMIL.js.map +0 -1
- package/chunk-H6MLKWIZ.js +0 -88
- package/chunk-H6MLKWIZ.js.map +0 -1
- package/chunk-LXTKPZ6M.js +0 -255
- package/chunk-LXTKPZ6M.js.map +0 -1
- package/chunk-PHS255C5.js.map +0 -1
- package/src/cf/cf-sys-abstraction.ts +0 -34
- package/src/web/web-sys-abstraction.ts +0 -80
- package/ts/src/base-sys-abstraction.test.d.ts +0 -2
- package/ts/src/base-sys-abstraction.test.d.ts.map +0 -1
- package/ts/src/base-sys-abstraction.test.js.map +0 -1
- package/ts/src/cf/cf-sys-abstraction.d.ts +0 -11
- package/ts/src/cf/cf-sys-abstraction.d.ts.map +0 -1
- package/ts/src/cf/cf-sys-abstraction.js +0 -30
- package/ts/src/cf/cf-sys-abstraction.js.map +0 -1
- package/ts/src/web/web-sys-abstraction.d.ts +0 -18
- package/ts/src/web/web-sys-abstraction.d.ts.map +0 -1
- package/ts/src/web/web-sys-abstraction.js +0 -64
- package/ts/src/web/web-sys-abstraction.js.map +0 -1
- /package/{chunk-55W4AK2Z.js.map → chunk-YVACAIUX.js.map} +0 -0
package/test/index.cjs
CHANGED
|
@@ -99,6 +99,100 @@ _promise = new WeakMap();
|
|
|
99
99
|
_resolveFn = new WeakMap();
|
|
100
100
|
_rejectFn = new WeakMap();
|
|
101
101
|
|
|
102
|
+
// src/lru-map-set.ts
|
|
103
|
+
var LRUMap = class {
|
|
104
|
+
constructor(c = {}) {
|
|
105
|
+
this._map = /* @__PURE__ */ new Map();
|
|
106
|
+
this.param = {
|
|
107
|
+
maxEntries: c.maxEntries || 100,
|
|
108
|
+
maxAge: c.maxAge || 0
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
touch(key) {
|
|
112
|
+
if (!this._map.has(key)) {
|
|
113
|
+
throw new Error(`key not found in cache: ${key}`);
|
|
114
|
+
}
|
|
115
|
+
const value = this._map.get(key);
|
|
116
|
+
this._map.delete(key);
|
|
117
|
+
this._map.set(key, value);
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
setParam(param2 = {}) {
|
|
121
|
+
if (typeof param2.maxEntries === "number") {
|
|
122
|
+
this.param.maxEntries = param2.maxEntries;
|
|
123
|
+
if (param2.maxEntries > 0 && this._map.size > param2.maxEntries) {
|
|
124
|
+
const toDelete = [];
|
|
125
|
+
let cacheSize = this._map.size;
|
|
126
|
+
for (const key of this._map.keys()) {
|
|
127
|
+
if (cacheSize > param2.maxEntries) {
|
|
128
|
+
toDelete.push(key);
|
|
129
|
+
cacheSize--;
|
|
130
|
+
} else {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const key of toDelete) {
|
|
135
|
+
this._map.delete(key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
has(key) {
|
|
141
|
+
return this._map.has(key);
|
|
142
|
+
}
|
|
143
|
+
get size() {
|
|
144
|
+
return this._map.size;
|
|
145
|
+
}
|
|
146
|
+
async getSet(key, createFN) {
|
|
147
|
+
const val = this.get(key);
|
|
148
|
+
if (val) {
|
|
149
|
+
return val;
|
|
150
|
+
} else {
|
|
151
|
+
const val2 = await createFN(key);
|
|
152
|
+
this.set(key, val2);
|
|
153
|
+
return val2;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
get(key) {
|
|
157
|
+
if (this._map.has(key)) {
|
|
158
|
+
return this.touch(key);
|
|
159
|
+
}
|
|
160
|
+
return this._map.get(key);
|
|
161
|
+
}
|
|
162
|
+
set(key, value) {
|
|
163
|
+
this._map.delete(key);
|
|
164
|
+
if (this.param.maxEntries > 0 && this._map.size >= this.param.maxEntries) {
|
|
165
|
+
this._map.delete(this._map.keys().next().value);
|
|
166
|
+
this._map.set(key, value);
|
|
167
|
+
} else {
|
|
168
|
+
this._map.set(key, value);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
delete(key) {
|
|
172
|
+
this._map.delete(key);
|
|
173
|
+
}
|
|
174
|
+
clear() {
|
|
175
|
+
this._map.clear();
|
|
176
|
+
}
|
|
177
|
+
forEach(callbackfn) {
|
|
178
|
+
this._map.forEach(callbackfn);
|
|
179
|
+
}
|
|
180
|
+
entries() {
|
|
181
|
+
return this._map.entries();
|
|
182
|
+
}
|
|
183
|
+
// *entries(): IterableIterator<[T, K]> {
|
|
184
|
+
// for (const x of this._cache.entries()) {
|
|
185
|
+
// yield x;
|
|
186
|
+
// }
|
|
187
|
+
// }
|
|
188
|
+
// getLeastRecent(): K {
|
|
189
|
+
// return Array.from(this.cache)[0];
|
|
190
|
+
// }
|
|
191
|
+
// getMostRecent(): K {
|
|
192
|
+
// return Array.from(this.cache)[this.cache.size - 1];
|
|
193
|
+
// }
|
|
194
|
+
};
|
|
195
|
+
|
|
102
196
|
// src/result.ts
|
|
103
197
|
var Result = class _Result {
|
|
104
198
|
static Ok(t) {
|
|
@@ -190,6 +284,158 @@ function exception2Result(fn) {
|
|
|
190
284
|
}
|
|
191
285
|
}
|
|
192
286
|
|
|
287
|
+
// src/resolve-once.ts
|
|
288
|
+
var ResolveOnce = class {
|
|
289
|
+
constructor(ctx) {
|
|
290
|
+
this._onceDone = false;
|
|
291
|
+
this._onceFutures = [];
|
|
292
|
+
this._onceOk = false;
|
|
293
|
+
this._isPromise = false;
|
|
294
|
+
this.ctx = ctx;
|
|
295
|
+
}
|
|
296
|
+
get ready() {
|
|
297
|
+
return this._onceDone;
|
|
298
|
+
}
|
|
299
|
+
reset() {
|
|
300
|
+
this._onceDone = false;
|
|
301
|
+
this._onceOk = false;
|
|
302
|
+
this._onceValue = void 0;
|
|
303
|
+
this._onceError = void 0;
|
|
304
|
+
if (this._inProgress) {
|
|
305
|
+
const idx = this._onceFutures.findIndex((f) => f === this._inProgress);
|
|
306
|
+
if (idx >= 0) {
|
|
307
|
+
this._onceFutures.push(...this._onceFutures.splice(2).slice(1));
|
|
308
|
+
}
|
|
309
|
+
} else {
|
|
310
|
+
this._onceFutures.length = 0;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// T extends Option<infer U> ? U : T
|
|
314
|
+
once(fn) {
|
|
315
|
+
if (this._onceDone) {
|
|
316
|
+
if (this._onceError) {
|
|
317
|
+
if (this._isPromise) {
|
|
318
|
+
return Promise.reject(this._onceError);
|
|
319
|
+
} else {
|
|
320
|
+
throw this._onceError;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (this._onceOk) {
|
|
324
|
+
if (this._isPromise) {
|
|
325
|
+
return Promise.resolve(this._onceValue);
|
|
326
|
+
} else {
|
|
327
|
+
return this._onceValue;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
throw new Error("ResolveOnce.once impossible");
|
|
331
|
+
}
|
|
332
|
+
const future = new Future();
|
|
333
|
+
this._onceFutures.push(future);
|
|
334
|
+
if (this._onceFutures.length === 1) {
|
|
335
|
+
const okFn = (value) => {
|
|
336
|
+
this._onceValue = value;
|
|
337
|
+
this._onceOk = true;
|
|
338
|
+
this._onceDone = true;
|
|
339
|
+
if (this._isPromise) {
|
|
340
|
+
this._onceFutures.forEach((f) => f.resolve(this._onceValue));
|
|
341
|
+
}
|
|
342
|
+
this._onceFutures.length = 0;
|
|
343
|
+
};
|
|
344
|
+
const catchFn = (e) => {
|
|
345
|
+
this._onceError = e;
|
|
346
|
+
this._onceOk = false;
|
|
347
|
+
this._onceValue = void 0;
|
|
348
|
+
this._onceDone = true;
|
|
349
|
+
if (this._isPromise) {
|
|
350
|
+
this._onceFutures.forEach((f) => f.reject(this._onceError));
|
|
351
|
+
}
|
|
352
|
+
this._onceFutures.length = 0;
|
|
353
|
+
};
|
|
354
|
+
this._inProgress = future;
|
|
355
|
+
try {
|
|
356
|
+
const ret = fn(this.ctx);
|
|
357
|
+
if (typeof ret.then === "function") {
|
|
358
|
+
this._isPromise = true;
|
|
359
|
+
ret.then(okFn).catch(catchFn).finally(() => {
|
|
360
|
+
this._inProgress = void 0;
|
|
361
|
+
});
|
|
362
|
+
} else {
|
|
363
|
+
okFn(ret);
|
|
364
|
+
}
|
|
365
|
+
} catch (e) {
|
|
366
|
+
catchFn(e);
|
|
367
|
+
}
|
|
368
|
+
if (!this._isPromise) {
|
|
369
|
+
this._inProgress = void 0;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (this._isPromise) {
|
|
373
|
+
return future.asPromise();
|
|
374
|
+
} else {
|
|
375
|
+
return this.once(fn);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
var Keyed = class {
|
|
380
|
+
constructor(factory, params) {
|
|
381
|
+
var _a;
|
|
382
|
+
this.factory = factory;
|
|
383
|
+
this._map = new LRUMap((_a = params == null ? void 0 : params.lru) != null ? _a : { maxEntries: -1 });
|
|
384
|
+
}
|
|
385
|
+
setParam(params) {
|
|
386
|
+
this._map.setParam(params.lru);
|
|
387
|
+
}
|
|
388
|
+
async asyncGet(key) {
|
|
389
|
+
return this.get(await key());
|
|
390
|
+
}
|
|
391
|
+
get(key) {
|
|
392
|
+
if (typeof key === "function") {
|
|
393
|
+
key = key();
|
|
394
|
+
}
|
|
395
|
+
let keyed = this._map.get(key);
|
|
396
|
+
if (!keyed) {
|
|
397
|
+
keyed = this.factory(key);
|
|
398
|
+
this._map.set(key, keyed);
|
|
399
|
+
}
|
|
400
|
+
return keyed;
|
|
401
|
+
}
|
|
402
|
+
unget(key) {
|
|
403
|
+
const keyed = this._map.get(key);
|
|
404
|
+
keyed == null ? void 0 : keyed.reset();
|
|
405
|
+
this._map.delete(key);
|
|
406
|
+
}
|
|
407
|
+
reset() {
|
|
408
|
+
this._map.forEach((keyed) => keyed.reset());
|
|
409
|
+
this._map.clear();
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var KeyedResolvOnce = class extends Keyed {
|
|
413
|
+
constructor(kp = {}) {
|
|
414
|
+
super((key) => new ResolveOnce(key), kp);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
*
|
|
418
|
+
* @returns The values of the resolved keys
|
|
419
|
+
*/
|
|
420
|
+
values() {
|
|
421
|
+
return Array.from(this._map.entries()).filter(([_, v]) => v._onceDone).map(([k, v]) => {
|
|
422
|
+
if (v._onceDone) {
|
|
423
|
+
if (v._onceError) {
|
|
424
|
+
return {
|
|
425
|
+
key: k,
|
|
426
|
+
value: Result.Err(v._onceError)
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
key: k,
|
|
431
|
+
value: Result.Ok(v._onceValue)
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
throw new Error("KeyedResolvOnce.values impossible");
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
193
439
|
// src/utils/coerce-uint8.ts
|
|
194
440
|
var globalBuffer = globalThis;
|
|
195
441
|
function coerceIntoUint8(raw) {
|
|
@@ -249,10 +495,9 @@ var TxtOps = class {
|
|
|
249
495
|
return this.decode(resolved);
|
|
250
496
|
}
|
|
251
497
|
};
|
|
252
|
-
var txtEnDecoder;
|
|
498
|
+
var txtEnDecoder = new ResolveOnce();
|
|
253
499
|
function TxtEnDecoderSingleton() {
|
|
254
|
-
|
|
255
|
-
return txtEnDecoder;
|
|
500
|
+
return txtEnDecoder.once(() => new TxtOps());
|
|
256
501
|
}
|
|
257
502
|
|
|
258
503
|
// src/test/log-write-stream.ts
|
|
@@ -642,1650 +887,1531 @@ function LevelHandlerSingleton() {
|
|
|
642
887
|
// src/logger-impl.ts
|
|
643
888
|
var import_yaml = __toESM(require("yaml"), 1);
|
|
644
889
|
|
|
645
|
-
// src/
|
|
646
|
-
var
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
890
|
+
// src/types.ts
|
|
891
|
+
var _Required = class {
|
|
892
|
+
constructor() {
|
|
893
|
+
this.type = "REQUIRED";
|
|
894
|
+
}
|
|
650
895
|
};
|
|
651
|
-
var
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
RANDOM: "random"
|
|
655
|
-
};
|
|
656
|
-
var IDMode = {
|
|
657
|
-
UUID: "uuid",
|
|
658
|
-
CONST: "const",
|
|
659
|
-
STEP: "step"
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
// src/time.ts
|
|
663
|
-
var Time = class {
|
|
664
|
-
TimeSince(start) {
|
|
665
|
-
const now = this.Now();
|
|
666
|
-
return now.getTime() - start.getTime();
|
|
896
|
+
var _Optional = class {
|
|
897
|
+
constructor() {
|
|
898
|
+
this.type = "OPTIONAL";
|
|
667
899
|
}
|
|
668
900
|
};
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
//Microsecond,
|
|
673
|
-
Minute: 60 * 1e3 * 1,
|
|
674
|
-
//Second,
|
|
675
|
-
Hour: 60 * 60 * 1e3 * 1
|
|
676
|
-
// Minute,
|
|
901
|
+
var param = {
|
|
902
|
+
REQUIRED: new _Required(),
|
|
903
|
+
OPTIONAL: new _Optional()
|
|
677
904
|
};
|
|
678
905
|
|
|
679
|
-
// src/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
906
|
+
// src/utils/get-params-result.ts
|
|
907
|
+
function getParamsResult(keys, getParam) {
|
|
908
|
+
const keyDef = keys.flat().reduce(
|
|
909
|
+
(acc, i) => {
|
|
910
|
+
if (typeof i === "string") {
|
|
911
|
+
acc.push({ key: i, def: void 0, isOptional: false });
|
|
912
|
+
} else if (typeof i === "object") {
|
|
913
|
+
acc.push(
|
|
914
|
+
...Object.keys(i).map((k) => ({
|
|
915
|
+
key: k,
|
|
916
|
+
def: typeof i[k] === "string" ? i[k] : void 0,
|
|
917
|
+
isOptional: i[k] === param.OPTIONAL
|
|
918
|
+
}))
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
return acc;
|
|
922
|
+
},
|
|
923
|
+
[]
|
|
924
|
+
);
|
|
925
|
+
const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
|
|
926
|
+
const msg = keys2.join(",");
|
|
927
|
+
return `missing parameters: ${msg}`;
|
|
928
|
+
});
|
|
929
|
+
const errors = [];
|
|
930
|
+
const result = {};
|
|
931
|
+
for (const kd of keyDef) {
|
|
932
|
+
const val = getParam.getParam(kd.key);
|
|
933
|
+
if (val === void 0) {
|
|
934
|
+
if (typeof kd.def === "string") {
|
|
935
|
+
result[kd.key] = kd.def;
|
|
936
|
+
} else {
|
|
937
|
+
if (!kd.isOptional) {
|
|
938
|
+
errors.push(kd.key);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
result[kd.key] = val;
|
|
713
943
|
}
|
|
714
|
-
return this._step;
|
|
715
944
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
return Promise.resolve();
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
function TimeFactory(timeMode) {
|
|
722
|
-
switch (timeMode) {
|
|
723
|
-
case TimeMode.REAL:
|
|
724
|
-
return new SysTime();
|
|
725
|
-
case TimeMode.CONST:
|
|
726
|
-
return new ConstTime();
|
|
727
|
-
case TimeMode.STEP:
|
|
728
|
-
return new StepTime();
|
|
945
|
+
if (errors.length) {
|
|
946
|
+
return Result.Err(msgFn(...errors));
|
|
729
947
|
}
|
|
730
|
-
return
|
|
948
|
+
return Result.Ok(result);
|
|
731
949
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
return 0.5 * value;
|
|
741
|
-
case RandomMode.STEP:
|
|
742
|
-
this._step += 1e-4;
|
|
743
|
-
return this._step * value;
|
|
744
|
-
case RandomMode.RANDOM:
|
|
745
|
-
return Math.random() * value;
|
|
746
|
-
default:
|
|
747
|
-
throw new Error("Unknown RandomMode");
|
|
748
|
-
}
|
|
749
|
-
}
|
|
950
|
+
|
|
951
|
+
// src/utils/relative-path.ts
|
|
952
|
+
var PartType = {
|
|
953
|
+
Slash: 1,
|
|
954
|
+
Root: 3,
|
|
955
|
+
Up: 4,
|
|
956
|
+
Noop: 8
|
|
957
|
+
// RootUp = 0x8 /* ../ */,
|
|
750
958
|
};
|
|
751
|
-
var
|
|
752
|
-
constructor(
|
|
753
|
-
this.
|
|
754
|
-
if (!mode) {
|
|
755
|
-
mode = IDMode.UUID;
|
|
756
|
-
}
|
|
757
|
-
this._mode = mode;
|
|
959
|
+
var Path = class {
|
|
960
|
+
constructor(parts = []) {
|
|
961
|
+
this.parts = parts;
|
|
758
962
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
963
|
+
toString() {
|
|
964
|
+
return this.parts.map((part) => {
|
|
965
|
+
if (typeof part === "string") {
|
|
966
|
+
return part;
|
|
967
|
+
} else {
|
|
968
|
+
switch (part) {
|
|
969
|
+
case PartType.Slash:
|
|
970
|
+
case PartType.Root:
|
|
971
|
+
return "/";
|
|
972
|
+
case PartType.Up:
|
|
973
|
+
return "..";
|
|
974
|
+
default:
|
|
975
|
+
return part;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}).join("");
|
|
770
979
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
980
|
+
add(part) {
|
|
981
|
+
if (this.parts.includes(PartType.Root) && part === PartType.Root) {
|
|
982
|
+
throw new Error("Cannot add absolute part to absolute path");
|
|
983
|
+
}
|
|
984
|
+
const last = this.parts[this.parts.length - 1];
|
|
985
|
+
if (last & PartType.Slash && part === PartType.Slash) {
|
|
775
986
|
return;
|
|
776
987
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
const ts = new TransformStream();
|
|
788
|
-
consumeReadableStream(ts.readable.getReader(), writeFn);
|
|
789
|
-
return ts.writable;
|
|
790
|
-
}
|
|
791
|
-
var BaseSysAbstraction = class {
|
|
792
|
-
constructor(params) {
|
|
793
|
-
this._time = new SysTime();
|
|
794
|
-
this._idService = new IdService();
|
|
795
|
-
this._randomService = new RandomService(RandomMode.RANDOM);
|
|
796
|
-
this._fileSystem = params.FileSystem;
|
|
797
|
-
this._systemService = params.SystemService;
|
|
798
|
-
this._txtEnDe = params.TxtEnDecoder;
|
|
799
|
-
const decoder = this._txtEnDe;
|
|
800
|
-
this._stdout = CFWriteableStream((chunk) => {
|
|
801
|
-
const decoded = decoder.decode(chunk);
|
|
802
|
-
console.log(decoded.trimEnd());
|
|
803
|
-
return Promise.resolve();
|
|
804
|
-
});
|
|
805
|
-
this._stderr = CFWriteableStream((chunk) => {
|
|
806
|
-
const decoded = decoder.decode(chunk);
|
|
807
|
-
console.error(decoded.trimEnd());
|
|
808
|
-
return Promise.resolve();
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
var WrapperSysAbstraction = class {
|
|
813
|
-
constructor(base, params) {
|
|
814
|
-
this._time = base._time;
|
|
815
|
-
this._stdout = base._stdout;
|
|
816
|
-
this._stderr = base._stderr;
|
|
817
|
-
this._idService = base._idService;
|
|
818
|
-
this._randomService = base._randomService;
|
|
819
|
-
this._fileSystem = base._fileSystem;
|
|
820
|
-
this._systemService = base._systemService;
|
|
821
|
-
if (params) {
|
|
822
|
-
if (params.TimeMode) {
|
|
823
|
-
this._time = TimeFactory(params.TimeMode);
|
|
824
|
-
}
|
|
825
|
-
if (params.Stdout) {
|
|
826
|
-
this._stdout = params.Stdout;
|
|
827
|
-
}
|
|
828
|
-
if (params.Stderr) {
|
|
829
|
-
this._stderr = params.Stderr;
|
|
830
|
-
}
|
|
831
|
-
if (params.IdMode) {
|
|
832
|
-
this._idService = new IdService(params.IdMode);
|
|
833
|
-
}
|
|
834
|
-
if (params.RandomMode) {
|
|
835
|
-
this._randomService = new RandomService(params.RandomMode);
|
|
836
|
-
}
|
|
837
|
-
if (params.FileSystem) {
|
|
838
|
-
this._fileSystem = params.FileSystem;
|
|
839
|
-
}
|
|
840
|
-
if (params.SystemService) {
|
|
841
|
-
this._systemService = params.SystemService;
|
|
988
|
+
switch (part) {
|
|
989
|
+
case ".":
|
|
990
|
+
this.parts.push(PartType.Noop);
|
|
991
|
+
return;
|
|
992
|
+
case "..":
|
|
993
|
+
part = PartType.Up;
|
|
994
|
+
}
|
|
995
|
+
if (last === PartType.Noop && part === PartType.Slash) {
|
|
996
|
+
if (last === PartType.Noop) {
|
|
997
|
+
this.parts.pop();
|
|
842
998
|
}
|
|
999
|
+
return;
|
|
843
1000
|
}
|
|
844
|
-
|
|
845
|
-
Time() {
|
|
846
|
-
return this._time;
|
|
847
|
-
}
|
|
848
|
-
NextId() {
|
|
849
|
-
return this._idService.NextId();
|
|
850
|
-
}
|
|
851
|
-
Random0ToValue(value) {
|
|
852
|
-
return this._randomService.Random0ToValue(value);
|
|
853
|
-
}
|
|
854
|
-
Stdout() {
|
|
855
|
-
return this._stdout;
|
|
856
|
-
}
|
|
857
|
-
Stderr() {
|
|
858
|
-
return this._stderr;
|
|
859
|
-
}
|
|
860
|
-
System() {
|
|
861
|
-
return this._systemService;
|
|
862
|
-
}
|
|
863
|
-
FileSystem() {
|
|
864
|
-
return this._fileSystem;
|
|
1001
|
+
this.parts.push(part);
|
|
865
1002
|
}
|
|
866
1003
|
};
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
this._map = /* @__PURE__ */ new Map();
|
|
872
|
-
this.param = {
|
|
873
|
-
maxEntries: c.maxEntries || 100,
|
|
874
|
-
maxAge: c.maxAge || 0
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
touch(key) {
|
|
878
|
-
if (!this._map.has(key)) {
|
|
879
|
-
throw new Error(`key not found in cache: ${key}`);
|
|
880
|
-
}
|
|
881
|
-
const value = this._map.get(key);
|
|
882
|
-
this._map.delete(key);
|
|
883
|
-
this._map.set(key, value);
|
|
884
|
-
return value;
|
|
1004
|
+
function splitPath(path) {
|
|
1005
|
+
const p = new Path();
|
|
1006
|
+
if (path === "") {
|
|
1007
|
+
return p;
|
|
885
1008
|
}
|
|
886
|
-
|
|
887
|
-
if (
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
for (const key of this._map.keys()) {
|
|
893
|
-
if (cacheSize > param2.maxEntries) {
|
|
894
|
-
toDelete.push(key);
|
|
895
|
-
cacheSize--;
|
|
896
|
-
} else {
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
for (const key of toDelete) {
|
|
901
|
-
this._map.delete(key);
|
|
902
|
-
}
|
|
1009
|
+
for (let count = 0; path.length; count++) {
|
|
1010
|
+
if (path.match(/^\/+/)) {
|
|
1011
|
+
if (count === 0) {
|
|
1012
|
+
p.add(PartType.Root);
|
|
1013
|
+
} else {
|
|
1014
|
+
p.add(PartType.Slash);
|
|
903
1015
|
}
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
has(key) {
|
|
907
|
-
return this._map.has(key);
|
|
908
|
-
}
|
|
909
|
-
get size() {
|
|
910
|
-
return this._map.size;
|
|
911
|
-
}
|
|
912
|
-
async getSet(key, createFN) {
|
|
913
|
-
const val = this.get(key);
|
|
914
|
-
if (val) {
|
|
915
|
-
return val;
|
|
1016
|
+
path = path.replace(/^\/+/, "");
|
|
916
1017
|
} else {
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
|
|
1018
|
+
const part = path.replace(/\/.*$/, "");
|
|
1019
|
+
p.add(part);
|
|
1020
|
+
path = path.replace(/^[^/]+/, "");
|
|
920
1021
|
}
|
|
921
1022
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1023
|
+
return p;
|
|
1024
|
+
}
|
|
1025
|
+
function pathJoin(...paths) {
|
|
1026
|
+
let prev = "";
|
|
1027
|
+
const res = [];
|
|
1028
|
+
for (let i = 0; i < paths.length; i++) {
|
|
1029
|
+
const path = paths[i];
|
|
1030
|
+
if (path === "") {
|
|
1031
|
+
continue;
|
|
925
1032
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
this._map.delete(this._map.keys().next().value);
|
|
932
|
-
this._map.set(key, value);
|
|
1033
|
+
if (!(prev.endsWith("/") || path.startsWith("/"))) {
|
|
1034
|
+
if (prev !== "") {
|
|
1035
|
+
res.push("/");
|
|
1036
|
+
}
|
|
1037
|
+
res.push(path);
|
|
933
1038
|
} else {
|
|
934
|
-
|
|
1039
|
+
res.push(path);
|
|
935
1040
|
}
|
|
1041
|
+
prev = path;
|
|
936
1042
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
entries() {
|
|
947
|
-
return this._map.entries();
|
|
1043
|
+
return res.join("");
|
|
1044
|
+
}
|
|
1045
|
+
function relativePath(path, relative) {
|
|
1046
|
+
const relativeParts = splitPath(relative);
|
|
1047
|
+
let result;
|
|
1048
|
+
if (relativeParts.parts[0] === PartType.Root) {
|
|
1049
|
+
result = relative;
|
|
1050
|
+
} else {
|
|
1051
|
+
result = pathJoin(path, relative);
|
|
948
1052
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1053
|
+
const unoptPath = splitPath(result);
|
|
1054
|
+
const out = [];
|
|
1055
|
+
let topUp = false;
|
|
1056
|
+
for (const part of unoptPath.parts) {
|
|
1057
|
+
switch (part) {
|
|
1058
|
+
case PartType.Root:
|
|
1059
|
+
out.push(PartType.Root);
|
|
1060
|
+
break;
|
|
1061
|
+
case PartType.Up:
|
|
1062
|
+
if (out.length && !topUp) {
|
|
1063
|
+
const last = out.length - 1;
|
|
1064
|
+
if (typeof out[last] === "string" && out[last - 1] == PartType.Root) {
|
|
1065
|
+
out.pop();
|
|
1066
|
+
} else {
|
|
1067
|
+
out.pop();
|
|
1068
|
+
out.pop();
|
|
1069
|
+
}
|
|
1070
|
+
if (out.length === 0) {
|
|
1071
|
+
topUp = !topUp ? true : topUp;
|
|
1072
|
+
out.push(PartType.Up);
|
|
1073
|
+
}
|
|
1074
|
+
} else {
|
|
1075
|
+
out.push(PartType.Up);
|
|
1076
|
+
}
|
|
1077
|
+
break;
|
|
1078
|
+
case PartType.Slash:
|
|
1079
|
+
if (!(out[out.length - 1] & PartType.Slash)) {
|
|
1080
|
+
out.push(PartType.Slash);
|
|
1081
|
+
}
|
|
1082
|
+
break;
|
|
1083
|
+
default:
|
|
1084
|
+
out.push(part);
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
return new Path(out).toString();
|
|
1089
|
+
}
|
|
961
1090
|
|
|
962
|
-
// src/
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1091
|
+
// src/utils/stripper.ts
|
|
1092
|
+
function stripper(strip, obj) {
|
|
1093
|
+
const strips = Array.isArray(strip) ? strip : [strip];
|
|
1094
|
+
const restrips = strips.map((s) => {
|
|
1095
|
+
if (typeof s === "string") {
|
|
1096
|
+
const escaped = s.replace(/[-\\[\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g, "\\$&");
|
|
1097
|
+
return new RegExp(`^${escaped}$`);
|
|
1098
|
+
}
|
|
1099
|
+
return s;
|
|
1100
|
+
});
|
|
1101
|
+
return localStripper(void 0, restrips, obj);
|
|
1102
|
+
}
|
|
1103
|
+
function localStripper(path, restrips, obj) {
|
|
1104
|
+
if (typeof obj !== "object" || obj === null) {
|
|
1105
|
+
return obj;
|
|
970
1106
|
}
|
|
971
|
-
|
|
972
|
-
return
|
|
1107
|
+
if (Array.isArray(obj)) {
|
|
1108
|
+
return obj.map((i) => localStripper(path, restrips, i));
|
|
973
1109
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
if (this._inProgress) {
|
|
980
|
-
const idx = this._onceFutures.findIndex((f) => f === this._inProgress);
|
|
981
|
-
if (idx >= 0) {
|
|
982
|
-
this._onceFutures.push(...this._onceFutures.splice(2).slice(1));
|
|
1110
|
+
const ret = { ...obj };
|
|
1111
|
+
const matcher = (key, nextPath) => {
|
|
1112
|
+
for (const re of restrips) {
|
|
1113
|
+
if (re.test(key) || re.test(nextPath)) {
|
|
1114
|
+
return true;
|
|
983
1115
|
}
|
|
984
|
-
} else {
|
|
985
|
-
this._onceFutures.length = 0;
|
|
986
1116
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
if (
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
1117
|
+
return false;
|
|
1118
|
+
};
|
|
1119
|
+
for (const key in ret) {
|
|
1120
|
+
if (Object.prototype.hasOwnProperty.call(ret, key)) {
|
|
1121
|
+
let nextPath;
|
|
1122
|
+
if (path) {
|
|
1123
|
+
nextPath = [path, key].join(".");
|
|
1124
|
+
} else {
|
|
1125
|
+
nextPath = key;
|
|
997
1126
|
}
|
|
998
|
-
if (
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
} else {
|
|
1002
|
-
return this._onceValue;
|
|
1003
|
-
}
|
|
1127
|
+
if (matcher(key, nextPath)) {
|
|
1128
|
+
delete ret[key];
|
|
1129
|
+
continue;
|
|
1004
1130
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
if (this._isPromise) {
|
|
1015
|
-
this._onceFutures.forEach((f) => f.resolve(this._onceValue));
|
|
1016
|
-
}
|
|
1017
|
-
this._onceFutures.length = 0;
|
|
1018
|
-
};
|
|
1019
|
-
const catchFn = (e) => {
|
|
1020
|
-
this._onceError = e;
|
|
1021
|
-
this._onceOk = false;
|
|
1022
|
-
this._onceValue = void 0;
|
|
1023
|
-
this._onceDone = true;
|
|
1024
|
-
if (this._isPromise) {
|
|
1025
|
-
this._onceFutures.forEach((f) => f.reject(this._onceError));
|
|
1026
|
-
}
|
|
1027
|
-
this._onceFutures.length = 0;
|
|
1028
|
-
};
|
|
1029
|
-
this._inProgress = future;
|
|
1030
|
-
try {
|
|
1031
|
-
const ret = fn(this.ctx);
|
|
1032
|
-
if (typeof ret.then === "function") {
|
|
1033
|
-
this._isPromise = true;
|
|
1034
|
-
ret.then(okFn).catch(catchFn).finally(() => {
|
|
1035
|
-
this._inProgress = void 0;
|
|
1036
|
-
});
|
|
1131
|
+
if (typeof ret[key] === "object") {
|
|
1132
|
+
if (Array.isArray(ret[key])) {
|
|
1133
|
+
ret[key] = ret[key].reduce((acc, v, i) => {
|
|
1134
|
+
const toDelete = matcher(key, `${nextPath}[${i}]`);
|
|
1135
|
+
if (!toDelete) {
|
|
1136
|
+
acc.push(localStripper(`${nextPath}[${i}]`, restrips, v));
|
|
1137
|
+
}
|
|
1138
|
+
return acc;
|
|
1139
|
+
}, []);
|
|
1037
1140
|
} else {
|
|
1038
|
-
|
|
1141
|
+
ret[key] = localStripper(nextPath, restrips, ret[key]);
|
|
1039
1142
|
}
|
|
1040
|
-
} catch (e) {
|
|
1041
|
-
catchFn(e);
|
|
1042
1143
|
}
|
|
1043
|
-
if (!this._isPromise) {
|
|
1044
|
-
this._inProgress = void 0;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
if (this._isPromise) {
|
|
1048
|
-
return future.asPromise();
|
|
1049
|
-
} else {
|
|
1050
|
-
return this.once(fn);
|
|
1051
1144
|
}
|
|
1052
1145
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1146
|
+
return ret;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// src/uri.ts
|
|
1150
|
+
function match(iref, ioth) {
|
|
1151
|
+
const mr = {
|
|
1152
|
+
score: 0,
|
|
1153
|
+
protocol: false,
|
|
1154
|
+
hostname: false,
|
|
1155
|
+
port: false,
|
|
1156
|
+
pathname: false,
|
|
1157
|
+
pathParts: [],
|
|
1158
|
+
params: {}
|
|
1159
|
+
};
|
|
1160
|
+
const ref = URI.from(iref);
|
|
1161
|
+
const oth = URI.from(ioth);
|
|
1162
|
+
if (ref.protocol === oth.protocol) {
|
|
1163
|
+
mr.score += 1;
|
|
1164
|
+
mr.protocol = true;
|
|
1065
1165
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1166
|
+
try {
|
|
1167
|
+
const refH = ref.hostname;
|
|
1168
|
+
const refP = ref.port;
|
|
1169
|
+
if (refH === oth.hostname) {
|
|
1170
|
+
mr.score += 1;
|
|
1171
|
+
mr.hostname = true;
|
|
1069
1172
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
this._map.set(key, keyed);
|
|
1173
|
+
if (refP.length && refP === oth.port) {
|
|
1174
|
+
mr.score += 1;
|
|
1175
|
+
mr.port = true;
|
|
1074
1176
|
}
|
|
1075
|
-
|
|
1076
|
-
}
|
|
1077
|
-
unget(key) {
|
|
1078
|
-
const keyed = this._map.get(key);
|
|
1079
|
-
keyed == null ? void 0 : keyed.reset();
|
|
1080
|
-
this._map.delete(key);
|
|
1081
|
-
}
|
|
1082
|
-
reset() {
|
|
1083
|
-
this._map.forEach((keyed) => keyed.reset());
|
|
1084
|
-
this._map.clear();
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
var KeyedResolvOnce = class extends Keyed {
|
|
1088
|
-
constructor(kp = {}) {
|
|
1089
|
-
super((key) => new ResolveOnce(key), kp);
|
|
1177
|
+
} catch (e) {
|
|
1090
1178
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
return {
|
|
1100
|
-
key: k,
|
|
1101
|
-
value: Result.Err(v._onceError)
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
return {
|
|
1105
|
-
key: k,
|
|
1106
|
-
value: Result.Ok(v._onceValue)
|
|
1107
|
-
};
|
|
1179
|
+
if (ref.pathname.length && ref.pathname !== "/") {
|
|
1180
|
+
const pref = ref.pathname.split("/").filter((p) => p.length);
|
|
1181
|
+
const poth = oth.pathname.split("/").filter((p) => p.length);
|
|
1182
|
+
for (let i = 0; i < pref.length && i < poth.length; i++) {
|
|
1183
|
+
if (poth[i] === pref[i]) {
|
|
1184
|
+
mr.score += 1;
|
|
1185
|
+
mr.pathname = true;
|
|
1186
|
+
mr.pathParts.push(pref[i]);
|
|
1108
1187
|
}
|
|
1109
|
-
|
|
1110
|
-
});
|
|
1188
|
+
}
|
|
1111
1189
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
const [head, ...tail] = value.split(".");
|
|
1117
|
-
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
|
1118
|
-
if (tail.length <= 1) {
|
|
1119
|
-
return true;
|
|
1190
|
+
for (const [key, value] of ref.getParams) {
|
|
1191
|
+
if (oth.getParam(key) === value) {
|
|
1192
|
+
mr.score += 1;
|
|
1193
|
+
mr.params[key] = value;
|
|
1120
1194
|
}
|
|
1121
|
-
return isSet(tail.join("."), ref[head]);
|
|
1122
1195
|
}
|
|
1123
|
-
return
|
|
1196
|
+
return mr;
|
|
1124
1197
|
}
|
|
1125
|
-
function
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
if (!isSet("Deno")) {
|
|
1133
|
-
isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
|
1134
|
-
}
|
|
1135
|
-
let isDeno = isSet("Deno");
|
|
1136
|
-
const isCFWorker = isSet("caches.default") && isSet("WebSocketPair");
|
|
1137
|
-
if (isCFWorker) {
|
|
1138
|
-
isDeno = false;
|
|
1139
|
-
isNodeIsh = false;
|
|
1140
|
-
isReactNative = false;
|
|
1198
|
+
function coerceKey(key, def) {
|
|
1199
|
+
if (typeof key === "object") {
|
|
1200
|
+
const keys = Object.keys(key);
|
|
1201
|
+
if (keys.length !== 1) {
|
|
1202
|
+
throw new Error(`Invalid key: ${JSON.stringify(key)}`);
|
|
1203
|
+
}
|
|
1204
|
+
return { key: keys[0], def: key[keys[0]] };
|
|
1141
1205
|
}
|
|
1142
|
-
return {
|
|
1143
|
-
isNodeIsh,
|
|
1144
|
-
isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
|
|
1145
|
-
isDeno,
|
|
1146
|
-
isReactNative,
|
|
1147
|
-
isCFWorker
|
|
1148
|
-
};
|
|
1206
|
+
return { key, def };
|
|
1149
1207
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
__privateAdd(this, _deno, globalThis);
|
|
1157
|
-
this.opts = opts;
|
|
1158
|
-
}
|
|
1159
|
-
static new(opts) {
|
|
1160
|
-
return once.once(() => new _DenoEnvActions(opts));
|
|
1161
|
-
}
|
|
1162
|
-
get _env() {
|
|
1163
|
-
return __privateGet(this, _deno).Deno.env;
|
|
1208
|
+
function falsy2undef(value) {
|
|
1209
|
+
return value === void 0 || value === null ? void 0 : value;
|
|
1210
|
+
}
|
|
1211
|
+
function ensureURLWithDefaultProto(url, defaultProtocol) {
|
|
1212
|
+
if (!url) {
|
|
1213
|
+
return new MutableURL(`${defaultProtocol}//`);
|
|
1164
1214
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1215
|
+
if (typeof url === "string") {
|
|
1216
|
+
try {
|
|
1217
|
+
return new MutableURL(url);
|
|
1218
|
+
} catch (e) {
|
|
1219
|
+
return new MutableURL(`${defaultProtocol}//${url}`);
|
|
1168
1220
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
active() {
|
|
1172
|
-
return runtimeFn().isDeno;
|
|
1221
|
+
} else {
|
|
1222
|
+
return new MutableURL(url.toString());
|
|
1173
1223
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1224
|
+
}
|
|
1225
|
+
function isURL(value) {
|
|
1226
|
+
return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
|
|
1227
|
+
}
|
|
1228
|
+
var MutableURL = class _MutableURL extends URL {
|
|
1229
|
+
constructor(urlStr) {
|
|
1230
|
+
super("defect://does.not.exist");
|
|
1231
|
+
const partedURL = urlStr.split(":");
|
|
1232
|
+
this._hasHostpart = hasHostPartProtocols.has(partedURL[0]);
|
|
1233
|
+
let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
|
|
1234
|
+
if (!this._hasHostpart) {
|
|
1235
|
+
const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
|
|
1236
|
+
hostPartUrl = hostPartUrl.replace(/http:\/\//, `http://localhost/${pathname}`);
|
|
1237
|
+
}
|
|
1238
|
+
try {
|
|
1239
|
+
this._sysURL = new URL(hostPartUrl);
|
|
1240
|
+
} catch (ie) {
|
|
1241
|
+
const e = ie;
|
|
1242
|
+
e.message = `${e.message} for URL: ${urlStr}`;
|
|
1243
|
+
throw e;
|
|
1244
|
+
}
|
|
1245
|
+
this._protocol = `${partedURL[0]}:`;
|
|
1246
|
+
if (this._hasHostpart) {
|
|
1247
|
+
this._pathname = this._sysURL.pathname;
|
|
1248
|
+
} else {
|
|
1249
|
+
this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
|
|
1250
|
+
}
|
|
1251
|
+
this.hash = this._sysURL.hash;
|
|
1176
1252
|
}
|
|
1177
|
-
|
|
1178
|
-
return this.
|
|
1253
|
+
clone() {
|
|
1254
|
+
return new _MutableURL(this.toString());
|
|
1179
1255
|
}
|
|
1180
|
-
|
|
1181
|
-
if (
|
|
1182
|
-
|
|
1256
|
+
get host() {
|
|
1257
|
+
if (!this._hasHostpart) {
|
|
1258
|
+
throw new Error(
|
|
1259
|
+
`you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`
|
|
1260
|
+
);
|
|
1183
1261
|
}
|
|
1262
|
+
return this._sysURL.host;
|
|
1184
1263
|
}
|
|
1185
|
-
|
|
1186
|
-
this.
|
|
1264
|
+
get port() {
|
|
1265
|
+
if (!this._hasHostpart) {
|
|
1266
|
+
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
|
|
1267
|
+
}
|
|
1268
|
+
return this._sysURL.port;
|
|
1187
1269
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
var once2 = new ResolveOnce();
|
|
1194
|
-
var _node;
|
|
1195
|
-
var _NodeEnvActions = class _NodeEnvActions {
|
|
1196
|
-
constructor(opts) {
|
|
1197
|
-
__privateAdd(this, _node, globalThis);
|
|
1198
|
-
this._env = this.active() ? __privateGet(this, _node).process.env : {};
|
|
1199
|
-
this.opts = opts;
|
|
1270
|
+
set port(p) {
|
|
1271
|
+
if (!this._hasHostpart) {
|
|
1272
|
+
throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
|
|
1273
|
+
}
|
|
1274
|
+
this._sysURL.port = p;
|
|
1200
1275
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1276
|
+
get hostname() {
|
|
1277
|
+
if (!this._hasHostpart) {
|
|
1278
|
+
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
|
|
1279
|
+
}
|
|
1280
|
+
return this._sysURL.hostname;
|
|
1203
1281
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1282
|
+
set hostname(h) {
|
|
1283
|
+
if (!this._hasHostpart) {
|
|
1284
|
+
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
|
|
1207
1285
|
}
|
|
1208
|
-
|
|
1286
|
+
this._sysURL.hostname = h;
|
|
1209
1287
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1288
|
+
set pathname(p) {
|
|
1289
|
+
this._pathname = p;
|
|
1212
1290
|
}
|
|
1213
|
-
|
|
1214
|
-
return
|
|
1291
|
+
get pathname() {
|
|
1292
|
+
return this._pathname;
|
|
1215
1293
|
}
|
|
1216
|
-
get(
|
|
1217
|
-
return this.
|
|
1294
|
+
get protocol() {
|
|
1295
|
+
return this._protocol;
|
|
1218
1296
|
}
|
|
1219
|
-
set(
|
|
1220
|
-
if (
|
|
1221
|
-
|
|
1297
|
+
set protocol(p) {
|
|
1298
|
+
if (!p.endsWith(":")) {
|
|
1299
|
+
p = `${p}:`;
|
|
1222
1300
|
}
|
|
1301
|
+
this._protocol = p;
|
|
1223
1302
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1303
|
+
get searchParams() {
|
|
1304
|
+
return this._sysURL.searchParams;
|
|
1305
|
+
}
|
|
1306
|
+
toString() {
|
|
1307
|
+
let search = "";
|
|
1308
|
+
if (this._sysURL.searchParams.size) {
|
|
1309
|
+
for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
1310
|
+
search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
let hostpart = "";
|
|
1314
|
+
if (this._hasHostpart) {
|
|
1315
|
+
hostpart = this._sysURL.hostname;
|
|
1316
|
+
if (this._sysURL.port) {
|
|
1317
|
+
hostpart += `:${this._sysURL.port}`;
|
|
1318
|
+
}
|
|
1319
|
+
if (!this._pathname.startsWith("/")) {
|
|
1320
|
+
hostpart += "/";
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
return `${this._protocol}//${hostpart}${this._pathname}${search}`;
|
|
1226
1324
|
}
|
|
1227
1325
|
};
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1326
|
+
function from(fac, strURLUri, defaultProtocol) {
|
|
1327
|
+
switch (typeof falsy2undef(strURLUri)) {
|
|
1328
|
+
case "undefined":
|
|
1329
|
+
return fac(new MutableURL(`${defaultProtocol}///`));
|
|
1330
|
+
case "string":
|
|
1331
|
+
return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
|
|
1332
|
+
case "object":
|
|
1333
|
+
if (BuildURI.is(strURLUri)) {
|
|
1334
|
+
return fac(new MutableURL(strURLUri._url.toString()));
|
|
1335
|
+
} else if (URI.is(strURLUri)) {
|
|
1336
|
+
return fac(new MutableURL(strURLUri._url.toString()));
|
|
1337
|
+
} else if (isURL(strURLUri)) {
|
|
1338
|
+
return fac(new MutableURL(strURLUri.toString()));
|
|
1339
|
+
}
|
|
1340
|
+
throw new Error(`unknown object type: ${strURLUri}`);
|
|
1341
|
+
default:
|
|
1342
|
+
throw new Error(`Invalid argument: ${typeof strURLUri}`);
|
|
1237
1343
|
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1344
|
+
}
|
|
1345
|
+
function getParamResult(key, val, msgFn = (key2) => {
|
|
1346
|
+
return `missing parameter: ${key2}`;
|
|
1347
|
+
}) {
|
|
1348
|
+
if (val === void 0) {
|
|
1349
|
+
return Result.Err(msgFn(key));
|
|
1240
1350
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1351
|
+
return Result.Ok(val);
|
|
1352
|
+
}
|
|
1353
|
+
var BuildURI = class _BuildURI {
|
|
1354
|
+
// pathname needs this
|
|
1355
|
+
constructor(url) {
|
|
1356
|
+
this._url = url;
|
|
1243
1357
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
this.env.set(key, value);
|
|
1247
|
-
}
|
|
1358
|
+
static is(value) {
|
|
1359
|
+
return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
|
|
1248
1360
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1361
|
+
static from(strURLUri, defaultProtocol = "file:") {
|
|
1362
|
+
return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
|
|
1251
1363
|
}
|
|
1252
|
-
|
|
1253
|
-
return
|
|
1364
|
+
match(other) {
|
|
1365
|
+
return match(this.URI(), URI.from(other));
|
|
1254
1366
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1367
|
+
port(p) {
|
|
1368
|
+
this._url.port = p;
|
|
1369
|
+
return this;
|
|
1257
1370
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
browser[sym] = env;
|
|
1262
|
-
return env;
|
|
1371
|
+
hostname(h) {
|
|
1372
|
+
this._url.hostname = h;
|
|
1373
|
+
return this;
|
|
1263
1374
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
this.injectOnRegister = {};
|
|
1271
|
-
this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
|
|
1375
|
+
protocol(p) {
|
|
1376
|
+
if (!p.endsWith(":")) {
|
|
1377
|
+
p = `${p}:`;
|
|
1378
|
+
}
|
|
1379
|
+
this._url.protocol = p;
|
|
1380
|
+
return this;
|
|
1272
1381
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1382
|
+
pathname(p) {
|
|
1383
|
+
this._url.pathname = p;
|
|
1384
|
+
return this;
|
|
1275
1385
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1386
|
+
// could pass a relative path or a full URL
|
|
1387
|
+
// if relative path, it will be appended to the current path
|
|
1388
|
+
resolve(p) {
|
|
1389
|
+
if (!p) {
|
|
1390
|
+
return this;
|
|
1391
|
+
}
|
|
1392
|
+
if (typeof p === "string") {
|
|
1393
|
+
if (!p.match(/^[a-zA-Z0-9]+:/)) {
|
|
1394
|
+
if (p.startsWith("/")) {
|
|
1395
|
+
this.pathname(p);
|
|
1396
|
+
return this;
|
|
1285
1397
|
}
|
|
1398
|
+
return this.appendRelative(p);
|
|
1286
1399
|
}
|
|
1287
1400
|
}
|
|
1401
|
+
this._url = new MutableURL(p.toString());
|
|
1402
|
+
return this;
|
|
1288
1403
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1404
|
+
appendRelative(p) {
|
|
1405
|
+
const appendUrl = URI.from(p);
|
|
1406
|
+
const pathname = "./" + appendUrl.pathname;
|
|
1407
|
+
const basePath = this._url.pathname;
|
|
1408
|
+
this.pathname(relativePath(basePath, pathname));
|
|
1409
|
+
for (const [key, value] of appendUrl.getParams) {
|
|
1410
|
+
this.setParam(key, value);
|
|
1411
|
+
}
|
|
1412
|
+
return this;
|
|
1291
1413
|
}
|
|
1292
|
-
|
|
1293
|
-
this.
|
|
1294
|
-
|
|
1295
|
-
env.set(key, this.injectOnRegister[key]);
|
|
1414
|
+
cleanParams() {
|
|
1415
|
+
for (const key of Array.from(this._url.searchParams.keys())) {
|
|
1416
|
+
this._url.searchParams.delete(key);
|
|
1296
1417
|
}
|
|
1297
|
-
return
|
|
1418
|
+
return this;
|
|
1298
1419
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1420
|
+
delParam(key) {
|
|
1421
|
+
this._url.searchParams.delete(key);
|
|
1422
|
+
return this;
|
|
1301
1423
|
}
|
|
1302
|
-
|
|
1303
|
-
if (
|
|
1304
|
-
this.
|
|
1424
|
+
defParam(key, str) {
|
|
1425
|
+
if (!this._url.searchParams.has(key)) {
|
|
1426
|
+
this._url.searchParams.set(key, str);
|
|
1305
1427
|
}
|
|
1428
|
+
return this;
|
|
1306
1429
|
}
|
|
1307
|
-
|
|
1308
|
-
this.
|
|
1309
|
-
|
|
1310
|
-
keys() {
|
|
1311
|
-
return Array.from(this.cfEnv.keys());
|
|
1430
|
+
setParam(key, str) {
|
|
1431
|
+
this._url.searchParams.set(key, str);
|
|
1432
|
+
return this;
|
|
1312
1433
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
// src/types.ts
|
|
1316
|
-
var _Required = class {
|
|
1317
|
-
constructor() {
|
|
1318
|
-
this.type = "REQUIRED";
|
|
1434
|
+
hasParam(key) {
|
|
1435
|
+
return this._url.searchParams.has(key);
|
|
1319
1436
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
constructor() {
|
|
1323
|
-
this.type = "OPTIONAL";
|
|
1437
|
+
get getParams() {
|
|
1438
|
+
return this._url.searchParams.entries();
|
|
1324
1439
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
// src/utils/get-params-result.ts
|
|
1332
|
-
function getParamsResult(keys, getParam) {
|
|
1333
|
-
const keyDef = keys.flat().reduce(
|
|
1334
|
-
(acc, i) => {
|
|
1335
|
-
if (typeof i === "string") {
|
|
1336
|
-
acc.push({ key: i, def: void 0, isOptional: false });
|
|
1337
|
-
} else if (typeof i === "object") {
|
|
1338
|
-
acc.push(
|
|
1339
|
-
...Object.keys(i).map((k) => ({
|
|
1340
|
-
key: k,
|
|
1341
|
-
def: typeof i[k] === "string" ? i[k] : void 0,
|
|
1342
|
-
isOptional: i[k] === param.OPTIONAL
|
|
1343
|
-
}))
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
return acc;
|
|
1347
|
-
},
|
|
1348
|
-
[]
|
|
1349
|
-
);
|
|
1350
|
-
const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
|
|
1351
|
-
const msg = keys2.join(",");
|
|
1352
|
-
return `missing parameters: ${msg}`;
|
|
1353
|
-
});
|
|
1354
|
-
const errors = [];
|
|
1355
|
-
const result = {};
|
|
1356
|
-
for (const kd of keyDef) {
|
|
1357
|
-
const val = getParam.getParam(kd.key);
|
|
1358
|
-
if (val === void 0) {
|
|
1359
|
-
if (typeof kd.def === "string") {
|
|
1360
|
-
result[kd.key] = kd.def;
|
|
1361
|
-
} else {
|
|
1362
|
-
if (!kd.isOptional) {
|
|
1363
|
-
errors.push(kd.key);
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
} else {
|
|
1367
|
-
result[kd.key] = val;
|
|
1440
|
+
getParam(key, def) {
|
|
1441
|
+
const { key: k, def: d } = coerceKey(key, def);
|
|
1442
|
+
let val = this._url.searchParams.get(k);
|
|
1443
|
+
if (!falsy2undef(val) && d) {
|
|
1444
|
+
val = d;
|
|
1368
1445
|
}
|
|
1446
|
+
return falsy2undef(val);
|
|
1369
1447
|
}
|
|
1370
|
-
|
|
1371
|
-
return
|
|
1372
|
-
}
|
|
1373
|
-
return Result.Ok(result);
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
// src/sys-env.ts
|
|
1377
|
-
var envActions = [
|
|
1378
|
-
{ id: "cf", fn: (opts) => CFEnvActions.new(opts) },
|
|
1379
|
-
{ id: "node", fn: (opts) => NodeEnvActions.new(opts) },
|
|
1380
|
-
{ id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
|
|
1381
|
-
{ id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
|
|
1382
|
-
];
|
|
1383
|
-
var _envFactories = new KeyedResolvOnce();
|
|
1384
|
-
function envFactory(opts = {}) {
|
|
1385
|
-
const found = envActions.find((fi) => fi.fn(opts).active());
|
|
1386
|
-
if (!found) {
|
|
1387
|
-
throw new Error("SysContainer:envFactory: no env available");
|
|
1448
|
+
getParamResult(key, msgFn) {
|
|
1449
|
+
return getParamResult(key, this.getParam(key), msgFn);
|
|
1388
1450
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
const ret = new EnvImpl(action, opts);
|
|
1392
|
-
action.register(ret);
|
|
1393
|
-
return ret;
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
function isIterable(obj) {
|
|
1397
|
-
if (obj == null) {
|
|
1398
|
-
return false;
|
|
1451
|
+
getParamsResult(...keys) {
|
|
1452
|
+
return getParamsResult(keys, this);
|
|
1399
1453
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
constructor(map, opts = {}) {
|
|
1404
|
-
this._onSet = [];
|
|
1405
|
-
this._map = map;
|
|
1406
|
-
this._updatePresets(opts.presetEnv);
|
|
1454
|
+
toString() {
|
|
1455
|
+
this._url.searchParams.sort();
|
|
1456
|
+
return this._url.toString();
|
|
1407
1457
|
}
|
|
1408
|
-
|
|
1409
|
-
return
|
|
1410
|
-
getParam: (k) => this.get(k)
|
|
1411
|
-
});
|
|
1458
|
+
toJSON() {
|
|
1459
|
+
return this.toString();
|
|
1412
1460
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
if (Array.isArray(key)) {
|
|
1416
|
-
if (key.length === 2) {
|
|
1417
|
-
const [k, v] = key;
|
|
1418
|
-
if (typeof k === "string" && typeof v === "string") {
|
|
1419
|
-
this.set(k, v);
|
|
1420
|
-
return;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
for (const item of key) {
|
|
1424
|
-
if (Array.isArray(item)) {
|
|
1425
|
-
if (item.length === 2) {
|
|
1426
|
-
const [k, v] = item;
|
|
1427
|
-
if (typeof k === "string" && typeof v === "string") {
|
|
1428
|
-
this.set(k, v);
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
} else {
|
|
1434
|
-
if (isIterable(key)) {
|
|
1435
|
-
for (const [k, v] of key) {
|
|
1436
|
-
if (typeof k === "string" && typeof v === "string") {
|
|
1437
|
-
this.set(k, v);
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
} else {
|
|
1441
|
-
const rKey = key;
|
|
1442
|
-
for (const k in rKey) {
|
|
1443
|
-
const v = rKey[k];
|
|
1444
|
-
if (typeof k === "string" && typeof v === "string") {
|
|
1445
|
-
this.set(k, v);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1461
|
+
asURL() {
|
|
1462
|
+
return this.URI().asURL();
|
|
1451
1463
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
return;
|
|
1455
|
-
}
|
|
1456
|
-
for (const [key, value] of presetEnv) {
|
|
1457
|
-
this._map.set(key, value);
|
|
1458
|
-
}
|
|
1464
|
+
asObj(...strips) {
|
|
1465
|
+
return this.URI().asObj(...strips);
|
|
1459
1466
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
let keys = [];
|
|
1463
|
-
if (key) {
|
|
1464
|
-
keys = [key];
|
|
1465
|
-
} else {
|
|
1466
|
-
keys = this._map.keys();
|
|
1467
|
-
}
|
|
1468
|
-
keys.filter((k) => {
|
|
1469
|
-
if (item.filter.size === 0) {
|
|
1470
|
-
return true;
|
|
1471
|
-
}
|
|
1472
|
-
if (item.filter.has(k)) {
|
|
1473
|
-
return true;
|
|
1474
|
-
}
|
|
1475
|
-
return false;
|
|
1476
|
-
}).forEach((k) => {
|
|
1477
|
-
let v;
|
|
1478
|
-
if (!key && !value) {
|
|
1479
|
-
v = this._map.get(k);
|
|
1480
|
-
} else if (key && !value) {
|
|
1481
|
-
v = void 0;
|
|
1482
|
-
} else {
|
|
1483
|
-
v = value;
|
|
1484
|
-
}
|
|
1485
|
-
item.fn(k, v);
|
|
1486
|
-
});
|
|
1487
|
-
});
|
|
1467
|
+
clone() {
|
|
1468
|
+
return _BuildURI.from(this.toString());
|
|
1488
1469
|
}
|
|
1489
|
-
|
|
1490
|
-
return this.
|
|
1470
|
+
URI() {
|
|
1471
|
+
return URI.from(this._url);
|
|
1491
1472
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1473
|
+
};
|
|
1474
|
+
var hasHostPartProtocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
|
|
1475
|
+
var URI = class _URI {
|
|
1476
|
+
static protocolHasHostpart(protocol) {
|
|
1477
|
+
protocol = protocol.replace(/:$/, "");
|
|
1478
|
+
hasHostPartProtocols.add(protocol);
|
|
1479
|
+
return () => {
|
|
1480
|
+
hasHostPartProtocols.delete(protocol);
|
|
1481
|
+
};
|
|
1497
1482
|
}
|
|
1498
|
-
|
|
1499
|
-
return this
|
|
1483
|
+
match(other) {
|
|
1484
|
+
return match(this, other);
|
|
1500
1485
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1486
|
+
// if no protocol is provided, default to file:
|
|
1487
|
+
static merge(into, from2, defaultProtocol = "file:") {
|
|
1488
|
+
const intoUrl = BuildURI.from(into, defaultProtocol);
|
|
1489
|
+
const fromUrl = _URI.from(from2, defaultProtocol);
|
|
1490
|
+
intoUrl.protocol(fromUrl.protocol);
|
|
1491
|
+
const fPath = fromUrl.pathname;
|
|
1492
|
+
if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
|
|
1493
|
+
intoUrl.pathname(fromUrl.pathname);
|
|
1504
1494
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
this._map.delete(key);
|
|
1510
|
-
this._applyOnSet(this._onSet, key);
|
|
1495
|
+
for (const [key, value] of fromUrl.getParams) {
|
|
1496
|
+
intoUrl.setParam(key, value);
|
|
1497
|
+
}
|
|
1498
|
+
return intoUrl.URI();
|
|
1511
1499
|
}
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
// src/web/web-sys-abstraction.ts
|
|
1515
|
-
var WebFileService = class {
|
|
1516
|
-
get baseDir() {
|
|
1517
|
-
throw new Error("basedir-Method not implemented.");
|
|
1500
|
+
static is(value) {
|
|
1501
|
+
return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
|
|
1518
1502
|
}
|
|
1519
|
-
//
|
|
1520
|
-
|
|
1521
|
-
|
|
1503
|
+
// if no protocol is provided, default to file:
|
|
1504
|
+
static from(strURLUri, defaultProtocol = "file:") {
|
|
1505
|
+
return from((url) => new _URI(url), strURLUri, defaultProtocol);
|
|
1522
1506
|
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
throw new Error("readFileString-Method not implemented.");
|
|
1507
|
+
static fromResult(strURLUri, defaultProtocol = "file:") {
|
|
1508
|
+
return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
|
|
1526
1509
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
throw new Error("writeFileString-Method not implemented.");
|
|
1510
|
+
constructor(url) {
|
|
1511
|
+
this._url = url.clone();
|
|
1530
1512
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
throw new Error("abs-Method not implemented.");
|
|
1513
|
+
build() {
|
|
1514
|
+
return BuildURI.from(this._url);
|
|
1534
1515
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
throw new Error("join-Method not implemented.");
|
|
1516
|
+
get hostname() {
|
|
1517
|
+
return this._url.hostname;
|
|
1538
1518
|
}
|
|
1539
|
-
//
|
|
1540
|
-
|
|
1541
|
-
|
|
1519
|
+
// get password(): string {
|
|
1520
|
+
// return this._url.password;
|
|
1521
|
+
// }
|
|
1522
|
+
get port() {
|
|
1523
|
+
return this._url.port;
|
|
1542
1524
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
throw new Error("dirname-Method not implemented.");
|
|
1525
|
+
get host() {
|
|
1526
|
+
return this._url.host;
|
|
1546
1527
|
}
|
|
1547
|
-
//
|
|
1548
|
-
|
|
1549
|
-
|
|
1528
|
+
// get username(): string {
|
|
1529
|
+
// return this._url.username;
|
|
1530
|
+
// }
|
|
1531
|
+
// get search(): string {
|
|
1532
|
+
// return this._url.search;
|
|
1533
|
+
// }
|
|
1534
|
+
get protocol() {
|
|
1535
|
+
return this._url.protocol;
|
|
1550
1536
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
throw new Error("nodeImport-Method not implemented.");
|
|
1537
|
+
get pathname() {
|
|
1538
|
+
return this._url.pathname;
|
|
1554
1539
|
}
|
|
1555
|
-
//
|
|
1556
|
-
|
|
1557
|
-
|
|
1540
|
+
// get hash(): string {
|
|
1541
|
+
// return this._url.hash;
|
|
1542
|
+
// }
|
|
1543
|
+
// get host(): string {
|
|
1544
|
+
// return this._url.host;
|
|
1545
|
+
// }
|
|
1546
|
+
get getParams() {
|
|
1547
|
+
return this._url.searchParams.entries();
|
|
1558
1548
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
Env() {
|
|
1562
|
-
return envFactory();
|
|
1549
|
+
hasParam(key) {
|
|
1550
|
+
return this._url.searchParams.has(key);
|
|
1563
1551
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1552
|
+
getParam(key, def) {
|
|
1553
|
+
const { key: k, def: d } = coerceKey(key, def);
|
|
1554
|
+
let val = this._url.searchParams.get(k);
|
|
1555
|
+
if (!falsy2undef(val) && d) {
|
|
1556
|
+
val = d;
|
|
1557
|
+
}
|
|
1558
|
+
return falsy2undef(val);
|
|
1566
1559
|
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
throw new Error("OnExit-Method not implemented.");
|
|
1560
|
+
getParamResult(key, msgFn) {
|
|
1561
|
+
return getParamResult(key, this.getParam(key), msgFn);
|
|
1570
1562
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
throw new Error("Exit-Method not implemented.");
|
|
1563
|
+
getParamsResult(...keys) {
|
|
1564
|
+
return getParamsResult(keys, this);
|
|
1574
1565
|
}
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
function WebSysAbstraction(param2) {
|
|
1578
|
-
if (!my) {
|
|
1579
|
-
my = new BaseSysAbstraction({
|
|
1580
|
-
TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton(),
|
|
1581
|
-
FileSystem: new WebFileService(),
|
|
1582
|
-
SystemService: new WebSystemService()
|
|
1583
|
-
});
|
|
1566
|
+
clone() {
|
|
1567
|
+
return new _URI(this._url);
|
|
1584
1568
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
// src/utils/relative-path.ts
|
|
1589
|
-
var PartType = {
|
|
1590
|
-
Slash: 1,
|
|
1591
|
-
Root: 3,
|
|
1592
|
-
Up: 4,
|
|
1593
|
-
Noop: 8
|
|
1594
|
-
// RootUp = 0x8 /* ../ */,
|
|
1595
|
-
};
|
|
1596
|
-
var Path = class {
|
|
1597
|
-
constructor(parts = []) {
|
|
1598
|
-
this.parts = parts;
|
|
1569
|
+
asURL() {
|
|
1570
|
+
return this._url.clone();
|
|
1599
1571
|
}
|
|
1600
1572
|
toString() {
|
|
1601
|
-
return this.
|
|
1602
|
-
if (typeof part === "string") {
|
|
1603
|
-
return part;
|
|
1604
|
-
} else {
|
|
1605
|
-
switch (part) {
|
|
1606
|
-
case PartType.Slash:
|
|
1607
|
-
case PartType.Root:
|
|
1608
|
-
return "/";
|
|
1609
|
-
case PartType.Up:
|
|
1610
|
-
return "..";
|
|
1611
|
-
default:
|
|
1612
|
-
return part;
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
}).join("");
|
|
1616
|
-
}
|
|
1617
|
-
add(part) {
|
|
1618
|
-
if (this.parts.includes(PartType.Root) && part === PartType.Root) {
|
|
1619
|
-
throw new Error("Cannot add absolute part to absolute path");
|
|
1620
|
-
}
|
|
1621
|
-
const last = this.parts[this.parts.length - 1];
|
|
1622
|
-
if (last & PartType.Slash && part === PartType.Slash) {
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
switch (part) {
|
|
1626
|
-
case ".":
|
|
1627
|
-
this.parts.push(PartType.Noop);
|
|
1628
|
-
return;
|
|
1629
|
-
case "..":
|
|
1630
|
-
part = PartType.Up;
|
|
1631
|
-
}
|
|
1632
|
-
if (last === PartType.Noop && part === PartType.Slash) {
|
|
1633
|
-
if (last === PartType.Noop) {
|
|
1634
|
-
this.parts.pop();
|
|
1635
|
-
}
|
|
1636
|
-
return;
|
|
1637
|
-
}
|
|
1638
|
-
this.parts.push(part);
|
|
1639
|
-
}
|
|
1640
|
-
};
|
|
1641
|
-
function splitPath(path) {
|
|
1642
|
-
const p = new Path();
|
|
1643
|
-
if (path === "") {
|
|
1644
|
-
return p;
|
|
1645
|
-
}
|
|
1646
|
-
for (let count = 0; path.length; count++) {
|
|
1647
|
-
if (path.match(/^\/+/)) {
|
|
1648
|
-
if (count === 0) {
|
|
1649
|
-
p.add(PartType.Root);
|
|
1650
|
-
} else {
|
|
1651
|
-
p.add(PartType.Slash);
|
|
1652
|
-
}
|
|
1653
|
-
path = path.replace(/^\/+/, "");
|
|
1654
|
-
} else {
|
|
1655
|
-
const part = path.replace(/\/.*$/, "");
|
|
1656
|
-
p.add(part);
|
|
1657
|
-
path = path.replace(/^[^/]+/, "");
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
return p;
|
|
1661
|
-
}
|
|
1662
|
-
function pathJoin(...paths) {
|
|
1663
|
-
let prev = "";
|
|
1664
|
-
const res = [];
|
|
1665
|
-
for (let i = 0; i < paths.length; i++) {
|
|
1666
|
-
const path = paths[i];
|
|
1667
|
-
if (path === "") {
|
|
1668
|
-
continue;
|
|
1669
|
-
}
|
|
1670
|
-
if (!(prev.endsWith("/") || path.startsWith("/"))) {
|
|
1671
|
-
if (prev !== "") {
|
|
1672
|
-
res.push("/");
|
|
1673
|
-
}
|
|
1674
|
-
res.push(path);
|
|
1675
|
-
} else {
|
|
1676
|
-
res.push(path);
|
|
1677
|
-
}
|
|
1678
|
-
prev = path;
|
|
1573
|
+
return this._url.toString();
|
|
1679
1574
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
function relativePath(path, relative) {
|
|
1683
|
-
const relativeParts = splitPath(relative);
|
|
1684
|
-
let result;
|
|
1685
|
-
if (relativeParts.parts[0] === PartType.Root) {
|
|
1686
|
-
result = relative;
|
|
1687
|
-
} else {
|
|
1688
|
-
result = pathJoin(path, relative);
|
|
1575
|
+
toJSON() {
|
|
1576
|
+
return this.toString();
|
|
1689
1577
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
out.pop();
|
|
1705
|
-
out.pop();
|
|
1706
|
-
}
|
|
1707
|
-
if (out.length === 0) {
|
|
1708
|
-
topUp = !topUp ? true : topUp;
|
|
1709
|
-
out.push(PartType.Up);
|
|
1710
|
-
}
|
|
1711
|
-
} else {
|
|
1712
|
-
out.push(PartType.Up);
|
|
1713
|
-
}
|
|
1714
|
-
break;
|
|
1715
|
-
case PartType.Slash:
|
|
1716
|
-
if (!(out[out.length - 1] & PartType.Slash)) {
|
|
1717
|
-
out.push(PartType.Slash);
|
|
1718
|
-
}
|
|
1719
|
-
break;
|
|
1720
|
-
default:
|
|
1721
|
-
out.push(part);
|
|
1722
|
-
break;
|
|
1578
|
+
asObj(...strips) {
|
|
1579
|
+
const pathURI = {
|
|
1580
|
+
style: "path",
|
|
1581
|
+
protocol: this.protocol,
|
|
1582
|
+
pathname: this.pathname,
|
|
1583
|
+
searchParams: Object.fromEntries(this.getParams)
|
|
1584
|
+
};
|
|
1585
|
+
if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
|
|
1586
|
+
return stripper(strips, {
|
|
1587
|
+
...pathURI,
|
|
1588
|
+
style: "host",
|
|
1589
|
+
hostname: this.hostname,
|
|
1590
|
+
port: this.port
|
|
1591
|
+
});
|
|
1723
1592
|
}
|
|
1593
|
+
return stripper(strips, pathURI);
|
|
1724
1594
|
}
|
|
1725
|
-
|
|
1726
|
-
}
|
|
1595
|
+
};
|
|
1727
1596
|
|
|
1728
|
-
// src/
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
return s;
|
|
1737
|
-
});
|
|
1738
|
-
return localStripper(void 0, restrips, obj);
|
|
1739
|
-
}
|
|
1740
|
-
function localStripper(path, restrips, obj) {
|
|
1741
|
-
if (typeof obj !== "object" || obj === null) {
|
|
1742
|
-
return obj;
|
|
1743
|
-
}
|
|
1744
|
-
if (Array.isArray(obj)) {
|
|
1745
|
-
return obj.map((i) => localStripper(path, restrips, i));
|
|
1597
|
+
// src/log-writer-impl.ts
|
|
1598
|
+
var LogWriterStream = class {
|
|
1599
|
+
constructor(out) {
|
|
1600
|
+
this._toFlush = [];
|
|
1601
|
+
this._flushIsRunning = false;
|
|
1602
|
+
this._flushDoneFns = [];
|
|
1603
|
+
this._out = out;
|
|
1604
|
+
this._id = Math.random();
|
|
1746
1605
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1606
|
+
write(encoded) {
|
|
1607
|
+
const my = async () => {
|
|
1608
|
+
try {
|
|
1609
|
+
const writer = this._out.getWriter();
|
|
1610
|
+
await writer.ready;
|
|
1611
|
+
await writer.write(encoded);
|
|
1612
|
+
writer.releaseLock();
|
|
1613
|
+
} catch (err) {
|
|
1614
|
+
console.error("Chunk error:", err);
|
|
1752
1615
|
}
|
|
1616
|
+
};
|
|
1617
|
+
this._toFlush.push(my);
|
|
1618
|
+
this._flush();
|
|
1619
|
+
}
|
|
1620
|
+
_flush(toFlush = void 0, done) {
|
|
1621
|
+
if (done) {
|
|
1622
|
+
this._flushDoneFns.push(done);
|
|
1753
1623
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
if (matcher(key, nextPath)) {
|
|
1765
|
-
delete ret[key];
|
|
1766
|
-
continue;
|
|
1767
|
-
}
|
|
1768
|
-
if (typeof ret[key] === "object") {
|
|
1769
|
-
if (Array.isArray(ret[key])) {
|
|
1770
|
-
ret[key] = ret[key].reduce((acc, v, i) => {
|
|
1771
|
-
const toDelete = matcher(key, `${nextPath}[${i}]`);
|
|
1772
|
-
if (!toDelete) {
|
|
1773
|
-
acc.push(localStripper(`${nextPath}[${i}]`, restrips, v));
|
|
1774
|
-
}
|
|
1775
|
-
return acc;
|
|
1776
|
-
}, []);
|
|
1777
|
-
} else {
|
|
1778
|
-
ret[key] = localStripper(nextPath, restrips, ret[key]);
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1624
|
+
if (this._toFlush.length == 0) {
|
|
1625
|
+
this._flushIsRunning = false;
|
|
1626
|
+
this._flushDoneFns.forEach((fn) => fn());
|
|
1627
|
+
this._flushDoneFns = [];
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
|
|
1631
|
+
this._flushIsRunning = true;
|
|
1632
|
+
} else if (!toFlush) {
|
|
1633
|
+
return;
|
|
1781
1634
|
}
|
|
1635
|
+
const my = this._toFlush.shift();
|
|
1636
|
+
my == null ? void 0 : my().catch((e) => {
|
|
1637
|
+
console.error("Flush error:", e);
|
|
1638
|
+
}).finally(() => {
|
|
1639
|
+
this._flush(this._toFlush);
|
|
1640
|
+
});
|
|
1782
1641
|
}
|
|
1783
|
-
|
|
1784
|
-
}
|
|
1642
|
+
};
|
|
1785
1643
|
|
|
1786
|
-
// src/
|
|
1787
|
-
function
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
if (
|
|
1791
|
-
|
|
1644
|
+
// src/runtime.ts
|
|
1645
|
+
function isSet(value, ref = globalThis) {
|
|
1646
|
+
const [head, ...tail] = value.split(".");
|
|
1647
|
+
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
|
1648
|
+
if (tail.length <= 1) {
|
|
1649
|
+
return true;
|
|
1792
1650
|
}
|
|
1793
|
-
return
|
|
1651
|
+
return isSet(tail.join("."), ref[head]);
|
|
1794
1652
|
}
|
|
1795
|
-
return
|
|
1796
|
-
}
|
|
1797
|
-
function falsy2undef(value) {
|
|
1798
|
-
return value === void 0 || value === null ? void 0 : value;
|
|
1653
|
+
return false;
|
|
1799
1654
|
}
|
|
1800
|
-
function
|
|
1801
|
-
|
|
1802
|
-
|
|
1655
|
+
function runtimeFn() {
|
|
1656
|
+
const gt = globalThis;
|
|
1657
|
+
let isReactNative = (
|
|
1658
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
1659
|
+
isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative"
|
|
1660
|
+
);
|
|
1661
|
+
let isNodeIsh = false;
|
|
1662
|
+
if (!isSet("Deno")) {
|
|
1663
|
+
isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
|
1803
1664
|
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
} else {
|
|
1811
|
-
return new MutableURL(url.toString());
|
|
1665
|
+
let isDeno = isSet("Deno");
|
|
1666
|
+
const isCFWorker = isSet("caches.default") && isSet("WebSocketPair");
|
|
1667
|
+
if (isCFWorker) {
|
|
1668
|
+
isDeno = false;
|
|
1669
|
+
isNodeIsh = false;
|
|
1670
|
+
isReactNative = false;
|
|
1812
1671
|
}
|
|
1672
|
+
return {
|
|
1673
|
+
isNodeIsh,
|
|
1674
|
+
isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
|
|
1675
|
+
isDeno,
|
|
1676
|
+
isReactNative,
|
|
1677
|
+
isCFWorker
|
|
1678
|
+
};
|
|
1813
1679
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
} else {
|
|
1838
|
-
this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
|
|
1839
|
-
}
|
|
1840
|
-
this.hash = this._sysURL.hash;
|
|
1680
|
+
|
|
1681
|
+
// src/sys-abstraction.ts
|
|
1682
|
+
var TimeMode = {
|
|
1683
|
+
REAL: "real",
|
|
1684
|
+
CONST: "const",
|
|
1685
|
+
STEP: "step"
|
|
1686
|
+
};
|
|
1687
|
+
var RandomMode = {
|
|
1688
|
+
CONST: "const",
|
|
1689
|
+
STEP: "step",
|
|
1690
|
+
RANDOM: "random"
|
|
1691
|
+
};
|
|
1692
|
+
var IDMode = {
|
|
1693
|
+
UUID: "uuid",
|
|
1694
|
+
CONST: "const",
|
|
1695
|
+
STEP: "step"
|
|
1696
|
+
};
|
|
1697
|
+
|
|
1698
|
+
// src/time.ts
|
|
1699
|
+
var Time = class {
|
|
1700
|
+
TimeSince(start) {
|
|
1701
|
+
const now = this.Now();
|
|
1702
|
+
return now.getTime() - start.getTime();
|
|
1841
1703
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1704
|
+
};
|
|
1705
|
+
var TimeUnits = {
|
|
1706
|
+
Microsecond: 1,
|
|
1707
|
+
Second: 1e3 * 1,
|
|
1708
|
+
//Microsecond,
|
|
1709
|
+
Minute: 60 * 1e3 * 1,
|
|
1710
|
+
//Second,
|
|
1711
|
+
Hour: 60 * 60 * 1e3 * 1
|
|
1712
|
+
// Minute,
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
// src/deno/deno-env-actions.ts
|
|
1716
|
+
var once = new ResolveOnce();
|
|
1717
|
+
var _deno;
|
|
1718
|
+
var _DenoEnvActions = class _DenoEnvActions {
|
|
1719
|
+
constructor(opts) {
|
|
1720
|
+
__privateAdd(this, _deno, globalThis);
|
|
1721
|
+
this.opts = opts;
|
|
1844
1722
|
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
throw new Error(
|
|
1848
|
-
`you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`
|
|
1849
|
-
);
|
|
1850
|
-
}
|
|
1851
|
-
return this._sysURL.host;
|
|
1723
|
+
static new(opts) {
|
|
1724
|
+
return once.once(() => new _DenoEnvActions(opts));
|
|
1852
1725
|
}
|
|
1853
|
-
get
|
|
1854
|
-
|
|
1855
|
-
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
|
|
1856
|
-
}
|
|
1857
|
-
return this._sysURL.port;
|
|
1726
|
+
get _env() {
|
|
1727
|
+
return __privateGet(this, _deno).Deno.env;
|
|
1858
1728
|
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1729
|
+
register(env) {
|
|
1730
|
+
for (const key of env.keys()) {
|
|
1731
|
+
this._env.set(key, env.get(key) || "");
|
|
1862
1732
|
}
|
|
1863
|
-
|
|
1733
|
+
return env;
|
|
1864
1734
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
|
|
1868
|
-
}
|
|
1869
|
-
return this._sysURL.hostname;
|
|
1735
|
+
active() {
|
|
1736
|
+
return runtimeFn().isDeno;
|
|
1870
1737
|
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1738
|
+
keys() {
|
|
1739
|
+
return Object.keys(this._env.toObject());
|
|
1740
|
+
}
|
|
1741
|
+
get(key) {
|
|
1742
|
+
return this._env.get(key);
|
|
1743
|
+
}
|
|
1744
|
+
set(key, value) {
|
|
1745
|
+
if (value) {
|
|
1746
|
+
this._env.set(key, value);
|
|
1874
1747
|
}
|
|
1875
|
-
this._sysURL.hostname = h;
|
|
1876
1748
|
}
|
|
1877
|
-
|
|
1878
|
-
this.
|
|
1749
|
+
delete(key) {
|
|
1750
|
+
this._env.delete(key);
|
|
1879
1751
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1752
|
+
};
|
|
1753
|
+
_deno = new WeakMap();
|
|
1754
|
+
var DenoEnvActions = _DenoEnvActions;
|
|
1755
|
+
|
|
1756
|
+
// src/node/node-env-actions.ts
|
|
1757
|
+
var once2 = new ResolveOnce();
|
|
1758
|
+
var _node;
|
|
1759
|
+
var _NodeEnvActions = class _NodeEnvActions {
|
|
1760
|
+
constructor(opts) {
|
|
1761
|
+
__privateAdd(this, _node, globalThis);
|
|
1762
|
+
this._env = this.active() ? __privateGet(this, _node).process.env : {};
|
|
1763
|
+
this.opts = opts;
|
|
1882
1764
|
}
|
|
1883
|
-
|
|
1884
|
-
return
|
|
1765
|
+
static new(opts) {
|
|
1766
|
+
return once2.once(() => new _NodeEnvActions(opts));
|
|
1885
1767
|
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1768
|
+
register(env) {
|
|
1769
|
+
for (const key of env.keys()) {
|
|
1770
|
+
this._env[key] = env.get(key) || "";
|
|
1889
1771
|
}
|
|
1890
|
-
|
|
1772
|
+
return env;
|
|
1891
1773
|
}
|
|
1892
|
-
|
|
1893
|
-
return
|
|
1774
|
+
active() {
|
|
1775
|
+
return runtimeFn().isNodeIsh;
|
|
1894
1776
|
}
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
hostpart = this._sysURL.hostname;
|
|
1905
|
-
if (this._sysURL.port) {
|
|
1906
|
-
hostpart += `:${this._sysURL.port}`;
|
|
1907
|
-
}
|
|
1908
|
-
if (!this._pathname.startsWith("/")) {
|
|
1909
|
-
hostpart += "/";
|
|
1910
|
-
}
|
|
1777
|
+
keys() {
|
|
1778
|
+
return Object.keys(this._env);
|
|
1779
|
+
}
|
|
1780
|
+
get(key) {
|
|
1781
|
+
return this._env[key];
|
|
1782
|
+
}
|
|
1783
|
+
set(key, value) {
|
|
1784
|
+
if (value) {
|
|
1785
|
+
this._env[key] = value;
|
|
1911
1786
|
}
|
|
1912
|
-
|
|
1787
|
+
}
|
|
1788
|
+
delete(key) {
|
|
1789
|
+
delete this._env[key];
|
|
1913
1790
|
}
|
|
1914
1791
|
};
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
} else if (URI.is(strURLUri)) {
|
|
1925
|
-
return fac(new MutableURL(strURLUri._url.toString()));
|
|
1926
|
-
} else if (isURL(strURLUri)) {
|
|
1927
|
-
return fac(new MutableURL(strURLUri.toString()));
|
|
1928
|
-
}
|
|
1929
|
-
throw new Error(`unknown object type: ${strURLUri}`);
|
|
1930
|
-
default:
|
|
1931
|
-
throw new Error(`Invalid argument: ${typeof strURLUri}`);
|
|
1792
|
+
_node = new WeakMap();
|
|
1793
|
+
var NodeEnvActions = _NodeEnvActions;
|
|
1794
|
+
|
|
1795
|
+
// src/web/web-env-actions.ts
|
|
1796
|
+
var once3 = new ResolveOnce();
|
|
1797
|
+
var BrowserEnvActions = class _BrowserEnvActions {
|
|
1798
|
+
constructor(opts) {
|
|
1799
|
+
this.env = /* @__PURE__ */ new Map();
|
|
1800
|
+
this.opts = opts;
|
|
1932
1801
|
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
return `missing parameter: ${key2}`;
|
|
1936
|
-
}) {
|
|
1937
|
-
if (val === void 0) {
|
|
1938
|
-
return Result.Err(msgFn(key));
|
|
1802
|
+
static new(opts) {
|
|
1803
|
+
return once3.once(() => new _BrowserEnvActions(opts));
|
|
1939
1804
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
var BuildURI = class _BuildURI {
|
|
1943
|
-
// pathname needs this
|
|
1944
|
-
constructor(url) {
|
|
1945
|
-
this._url = url;
|
|
1805
|
+
get(key) {
|
|
1806
|
+
return this.env.get(key);
|
|
1946
1807
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1808
|
+
set(key, value) {
|
|
1809
|
+
if (value) {
|
|
1810
|
+
this.env.set(key, value);
|
|
1811
|
+
}
|
|
1949
1812
|
}
|
|
1950
|
-
|
|
1951
|
-
|
|
1813
|
+
delete(key) {
|
|
1814
|
+
this.env.delete(key);
|
|
1952
1815
|
}
|
|
1953
|
-
|
|
1954
|
-
this.
|
|
1955
|
-
return this;
|
|
1816
|
+
keys() {
|
|
1817
|
+
return Array.from(this.env.keys());
|
|
1956
1818
|
}
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
return this;
|
|
1819
|
+
active() {
|
|
1820
|
+
return true;
|
|
1960
1821
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
return this;
|
|
1822
|
+
register(env) {
|
|
1823
|
+
const sym = Symbol.for(this.opts.symbol || "CP_ENV");
|
|
1824
|
+
const browser = globalThis;
|
|
1825
|
+
browser[sym] = env;
|
|
1826
|
+
return env;
|
|
1967
1827
|
}
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1830
|
+
// src/cf/cf-env-actions.ts
|
|
1831
|
+
var once4 = new ResolveOnce();
|
|
1832
|
+
var CFEnvActions = class _CFEnvActions {
|
|
1833
|
+
constructor(env) {
|
|
1834
|
+
this.injectOnRegister = {};
|
|
1835
|
+
this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
|
|
1971
1836
|
}
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
if (
|
|
1980
|
-
if (
|
|
1981
|
-
|
|
1982
|
-
|
|
1837
|
+
static new(opts) {
|
|
1838
|
+
return once4.once(() => new _CFEnvActions(opts));
|
|
1839
|
+
}
|
|
1840
|
+
static inject(o) {
|
|
1841
|
+
const env = _CFEnvActions.new({});
|
|
1842
|
+
for (const key in o) {
|
|
1843
|
+
const value = o[key];
|
|
1844
|
+
if (typeof value === "string") {
|
|
1845
|
+
if (env.env) {
|
|
1846
|
+
env.env.set(key, value);
|
|
1847
|
+
} else {
|
|
1848
|
+
env.injectOnRegister[key] = value;
|
|
1983
1849
|
}
|
|
1984
|
-
return this.appendRelative(p);
|
|
1985
1850
|
}
|
|
1986
1851
|
}
|
|
1987
|
-
this._url = new MutableURL(p.toString());
|
|
1988
|
-
return this;
|
|
1989
1852
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
this.
|
|
1995
|
-
for (const
|
|
1996
|
-
|
|
1853
|
+
active() {
|
|
1854
|
+
return runtimeFn().isCFWorker;
|
|
1855
|
+
}
|
|
1856
|
+
register(env) {
|
|
1857
|
+
this.env = env;
|
|
1858
|
+
for (const key in this.injectOnRegister) {
|
|
1859
|
+
env.set(key, this.injectOnRegister[key]);
|
|
1997
1860
|
}
|
|
1998
|
-
return
|
|
1861
|
+
return env;
|
|
1999
1862
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
1863
|
+
get(key) {
|
|
1864
|
+
return this.cfEnv.get(key);
|
|
1865
|
+
}
|
|
1866
|
+
set(key, value) {
|
|
1867
|
+
if (value) {
|
|
1868
|
+
this.cfEnv.set(key, value);
|
|
2003
1869
|
}
|
|
2004
|
-
return this;
|
|
2005
1870
|
}
|
|
2006
|
-
|
|
2007
|
-
this.
|
|
2008
|
-
|
|
1871
|
+
delete(key) {
|
|
1872
|
+
this.cfEnv.delete(key);
|
|
1873
|
+
}
|
|
1874
|
+
keys() {
|
|
1875
|
+
return Array.from(this.cfEnv.keys());
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
// src/sys-env.ts
|
|
1880
|
+
var envActions = [
|
|
1881
|
+
{ id: "cf", fn: (opts) => CFEnvActions.new(opts) },
|
|
1882
|
+
{ id: "node", fn: (opts) => NodeEnvActions.new(opts) },
|
|
1883
|
+
{ id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
|
|
1884
|
+
{ id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
|
|
1885
|
+
];
|
|
1886
|
+
var _envFactories = new KeyedResolvOnce();
|
|
1887
|
+
function envFactory(opts = {}) {
|
|
1888
|
+
const found = envActions.find((fi) => fi.fn(opts).active());
|
|
1889
|
+
if (!found) {
|
|
1890
|
+
throw new Error("SysContainer:envFactory: no env available");
|
|
1891
|
+
}
|
|
1892
|
+
return _envFactories.get(found.id).once(() => {
|
|
1893
|
+
const action = found.fn(opts);
|
|
1894
|
+
const ret = new EnvImpl(action, opts);
|
|
1895
|
+
action.register(ret);
|
|
1896
|
+
return ret;
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
function isIterable(obj) {
|
|
1900
|
+
if (obj == null) {
|
|
1901
|
+
return false;
|
|
1902
|
+
}
|
|
1903
|
+
return typeof obj[Symbol.iterator] === "function";
|
|
1904
|
+
}
|
|
1905
|
+
var EnvImpl = class {
|
|
1906
|
+
constructor(map, opts = {}) {
|
|
1907
|
+
this._onSet = [];
|
|
1908
|
+
this._map = map;
|
|
1909
|
+
this._updatePresets(opts.presetEnv);
|
|
1910
|
+
}
|
|
1911
|
+
gets(...kparams) {
|
|
1912
|
+
return getParamsResult(kparams, {
|
|
1913
|
+
getParam: (k) => this.get(k)
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
sets(...keys) {
|
|
1917
|
+
keys.forEach((key) => {
|
|
1918
|
+
if (Array.isArray(key)) {
|
|
1919
|
+
if (key.length === 2) {
|
|
1920
|
+
const [k, v] = key;
|
|
1921
|
+
if (typeof k === "string" && typeof v === "string") {
|
|
1922
|
+
this.set(k, v);
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
for (const item of key) {
|
|
1927
|
+
if (Array.isArray(item)) {
|
|
1928
|
+
if (item.length === 2) {
|
|
1929
|
+
const [k, v] = item;
|
|
1930
|
+
if (typeof k === "string" && typeof v === "string") {
|
|
1931
|
+
this.set(k, v);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
} else {
|
|
1937
|
+
if (isIterable(key)) {
|
|
1938
|
+
for (const [k, v] of key) {
|
|
1939
|
+
if (typeof k === "string" && typeof v === "string") {
|
|
1940
|
+
this.set(k, v);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
} else {
|
|
1944
|
+
const rKey = key;
|
|
1945
|
+
for (const k in rKey) {
|
|
1946
|
+
const v = rKey[k];
|
|
1947
|
+
if (typeof k === "string" && typeof v === "string") {
|
|
1948
|
+
this.set(k, v);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
2009
1954
|
}
|
|
2010
|
-
|
|
2011
|
-
if (!
|
|
2012
|
-
|
|
1955
|
+
_updatePresets(presetEnv) {
|
|
1956
|
+
if (!presetEnv) {
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
for (const [key, value] of presetEnv) {
|
|
1960
|
+
this._map.set(key, value);
|
|
2013
1961
|
}
|
|
2014
|
-
return this;
|
|
2015
1962
|
}
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
1963
|
+
_applyOnSet(onSet, key, value) {
|
|
1964
|
+
onSet.forEach((item) => {
|
|
1965
|
+
let keys = [];
|
|
1966
|
+
if (key) {
|
|
1967
|
+
keys = [key];
|
|
1968
|
+
} else {
|
|
1969
|
+
keys = this._map.keys();
|
|
1970
|
+
}
|
|
1971
|
+
keys.filter((k) => {
|
|
1972
|
+
if (item.filter.size === 0) {
|
|
1973
|
+
return true;
|
|
1974
|
+
}
|
|
1975
|
+
if (item.filter.has(k)) {
|
|
1976
|
+
return true;
|
|
1977
|
+
}
|
|
1978
|
+
return false;
|
|
1979
|
+
}).forEach((k) => {
|
|
1980
|
+
let v;
|
|
1981
|
+
if (!key && !value) {
|
|
1982
|
+
v = this._map.get(k);
|
|
1983
|
+
} else if (key && !value) {
|
|
1984
|
+
v = void 0;
|
|
1985
|
+
} else {
|
|
1986
|
+
v = value;
|
|
1987
|
+
}
|
|
1988
|
+
item.fn(k, v);
|
|
1989
|
+
});
|
|
1990
|
+
});
|
|
2019
1991
|
}
|
|
2020
|
-
|
|
2021
|
-
return this.
|
|
1992
|
+
keys() {
|
|
1993
|
+
return this._map.keys();
|
|
2022
1994
|
}
|
|
2023
|
-
|
|
2024
|
-
|
|
1995
|
+
// filter is not set all sets passed
|
|
1996
|
+
onSet(fn, ...filter) {
|
|
1997
|
+
const item = { filter: new Set(filter), fn };
|
|
1998
|
+
this._onSet.push(item);
|
|
1999
|
+
this._applyOnSet([item]);
|
|
2025
2000
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2001
|
+
get(key) {
|
|
2002
|
+
return this._map.get(key);
|
|
2003
|
+
}
|
|
2004
|
+
set(key, value) {
|
|
2005
|
+
if (!value) {
|
|
2006
|
+
return;
|
|
2031
2007
|
}
|
|
2032
|
-
|
|
2008
|
+
this._map.set(key, value);
|
|
2009
|
+
this._applyOnSet(this._onSet, key, value);
|
|
2033
2010
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2011
|
+
delete(key) {
|
|
2012
|
+
this._map.delete(key);
|
|
2013
|
+
this._applyOnSet(this._onSet, key);
|
|
2036
2014
|
}
|
|
2037
|
-
|
|
2038
|
-
|
|
2015
|
+
};
|
|
2016
|
+
|
|
2017
|
+
// src/utils/console-write-stream.ts
|
|
2018
|
+
var ConsoleWriterStreamDefaultWriter = class {
|
|
2019
|
+
constructor(stream) {
|
|
2020
|
+
this.stream = stream;
|
|
2021
|
+
this.desiredSize = null;
|
|
2022
|
+
this.decoder = new TextDecoder();
|
|
2023
|
+
this._stream = stream;
|
|
2024
|
+
this.ready = Promise.resolve(void 0);
|
|
2025
|
+
this.closed = Promise.resolve(void 0);
|
|
2039
2026
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2027
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
2028
|
+
abort(reason) {
|
|
2029
|
+
throw new Error("Method not implemented.");
|
|
2043
2030
|
}
|
|
2044
|
-
|
|
2045
|
-
return this.toString();
|
|
2031
|
+
async close() {
|
|
2046
2032
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2033
|
+
releaseLock() {
|
|
2034
|
+
this._stream.locked = false;
|
|
2035
|
+
this.ready = Promise.resolve(void 0);
|
|
2036
|
+
this.closed = Promise.resolve(void 0);
|
|
2049
2037
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2038
|
+
write(chunk) {
|
|
2039
|
+
let strObj = this.decoder.decode(chunk).trimEnd();
|
|
2040
|
+
let output = "log";
|
|
2041
|
+
try {
|
|
2042
|
+
strObj = JSON.parse(strObj);
|
|
2043
|
+
output = strObj.level;
|
|
2044
|
+
} catch (e) {
|
|
2045
|
+
}
|
|
2046
|
+
switch (output) {
|
|
2047
|
+
case "error":
|
|
2048
|
+
console.error(strObj);
|
|
2049
|
+
break;
|
|
2050
|
+
case "warn":
|
|
2051
|
+
console.warn(strObj);
|
|
2052
|
+
break;
|
|
2053
|
+
default:
|
|
2054
|
+
console.log(strObj);
|
|
2055
|
+
}
|
|
2056
|
+
return Promise.resolve();
|
|
2052
2057
|
}
|
|
2053
|
-
|
|
2054
|
-
|
|
2058
|
+
};
|
|
2059
|
+
var ConsoleWriterStream = class {
|
|
2060
|
+
constructor() {
|
|
2061
|
+
this.locked = false;
|
|
2055
2062
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2063
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
2064
|
+
abort(reason) {
|
|
2065
|
+
throw new Error("Method not implemented.");
|
|
2058
2066
|
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
var URI = class _URI {
|
|
2062
|
-
static protocolHasHostpart(protocol) {
|
|
2063
|
-
protocol = protocol.replace(/:$/, "");
|
|
2064
|
-
hasHostPartProtocols.add(protocol);
|
|
2065
|
-
return () => {
|
|
2066
|
-
hasHostPartProtocols.delete(protocol);
|
|
2067
|
-
};
|
|
2067
|
+
close() {
|
|
2068
|
+
return Promise.resolve();
|
|
2068
2069
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
const fromUrl = _URI.from(from2, defaultProtocol);
|
|
2073
|
-
intoUrl.protocol(fromUrl.protocol);
|
|
2074
|
-
const fPath = fromUrl.pathname;
|
|
2075
|
-
if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
|
|
2076
|
-
intoUrl.pathname(fromUrl.pathname);
|
|
2070
|
+
getWriter() {
|
|
2071
|
+
if (this.locked) {
|
|
2072
|
+
throw new Error("Stream is locked");
|
|
2077
2073
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2074
|
+
this.locked = true;
|
|
2075
|
+
if (!this._writer) {
|
|
2076
|
+
this._writer = new ConsoleWriterStreamDefaultWriter(this);
|
|
2080
2077
|
}
|
|
2081
|
-
return
|
|
2078
|
+
return this._writer;
|
|
2082
2079
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2080
|
+
};
|
|
2081
|
+
|
|
2082
|
+
// src/web/web-basic-sys-abstraction.ts
|
|
2083
|
+
var WebSystemService = class {
|
|
2084
|
+
constructor(ende) {
|
|
2085
|
+
this._txtEnDe = ende;
|
|
2085
2086
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
return from((url) => new _URI(url), strURLUri, defaultProtocol);
|
|
2087
|
+
Env() {
|
|
2088
|
+
return envFactory();
|
|
2089
2089
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2090
|
+
Args() {
|
|
2091
|
+
throw new Error("Args-Method not implemented.");
|
|
2092
2092
|
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2093
|
+
Stdout() {
|
|
2094
|
+
return new ConsoleWriterStream();
|
|
2095
2095
|
}
|
|
2096
|
-
|
|
2097
|
-
|
|
2096
|
+
Stderr() {
|
|
2097
|
+
const decoder = this._txtEnDe;
|
|
2098
|
+
return new WritableStream({
|
|
2099
|
+
write(chunk) {
|
|
2100
|
+
return new Promise((resolve) => {
|
|
2101
|
+
const decoded = decoder.decode(chunk);
|
|
2102
|
+
console.error(decoded.trimEnd());
|
|
2103
|
+
resolve();
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
});
|
|
2098
2107
|
}
|
|
2099
|
-
|
|
2100
|
-
|
|
2108
|
+
};
|
|
2109
|
+
var baseSysAbstraction = new ResolveOnce();
|
|
2110
|
+
function WebBasicSysAbstraction(param2) {
|
|
2111
|
+
var _a;
|
|
2112
|
+
const my = baseSysAbstraction.once(() => {
|
|
2113
|
+
return new BaseBasicSysAbstraction({
|
|
2114
|
+
TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
|
|
2115
|
+
});
|
|
2116
|
+
});
|
|
2117
|
+
return new WrapperBasicSysAbstraction(my, {
|
|
2118
|
+
basicRuntimeService: new WebSystemService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
|
|
2119
|
+
...param2
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
// src/cf/cf-basic-sys-abstraction.ts
|
|
2124
|
+
var CFRuntimeService = class {
|
|
2125
|
+
constructor(ende) {
|
|
2126
|
+
this._txtEnDe = ende;
|
|
2101
2127
|
}
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
// }
|
|
2105
|
-
get port() {
|
|
2106
|
-
return this._url.port;
|
|
2128
|
+
Env() {
|
|
2129
|
+
return envFactory();
|
|
2107
2130
|
}
|
|
2108
|
-
|
|
2109
|
-
|
|
2131
|
+
Args() {
|
|
2132
|
+
throw new Error("Args-Method not implemented.");
|
|
2110
2133
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
get protocol() {
|
|
2118
|
-
return this._url.protocol;
|
|
2134
|
+
Stdout() {
|
|
2135
|
+
return CFWriteableStream((chunk) => {
|
|
2136
|
+
const decoded = this._txtEnDe.decode(chunk);
|
|
2137
|
+
console.log(decoded.trimEnd());
|
|
2138
|
+
return Promise.resolve();
|
|
2139
|
+
});
|
|
2119
2140
|
}
|
|
2120
|
-
|
|
2121
|
-
return
|
|
2141
|
+
Stderr() {
|
|
2142
|
+
return CFWriteableStream((chunk) => {
|
|
2143
|
+
const decoded = this._txtEnDe.decode(chunk);
|
|
2144
|
+
console.error(decoded.trimEnd());
|
|
2145
|
+
return Promise.resolve();
|
|
2146
|
+
});
|
|
2122
2147
|
}
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2148
|
+
};
|
|
2149
|
+
function consumeReadableStream(reader, writeFn) {
|
|
2150
|
+
reader.read().then(({ done, value }) => {
|
|
2151
|
+
if (done) {
|
|
2152
|
+
return;
|
|
2153
|
+
}
|
|
2154
|
+
writeFn(value).then(() => {
|
|
2155
|
+
consumeReadableStream(reader, writeFn);
|
|
2156
|
+
}).catch((e) => {
|
|
2157
|
+
console.error("consumeReadableStream:writeFn", e);
|
|
2158
|
+
});
|
|
2159
|
+
}).catch((e) => {
|
|
2160
|
+
console.error("consumeReadableStream:read", e);
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function CFWriteableStream(writeFn) {
|
|
2164
|
+
const ts = new TransformStream();
|
|
2165
|
+
consumeReadableStream(ts.readable.getReader(), writeFn);
|
|
2166
|
+
return ts.writable;
|
|
2167
|
+
}
|
|
2168
|
+
var baseSysAbstraction2 = new ResolveOnce();
|
|
2169
|
+
function CFBasicSysAbstraction(param2) {
|
|
2170
|
+
var _a;
|
|
2171
|
+
const my = baseSysAbstraction2.once(() => {
|
|
2172
|
+
return new BaseBasicSysAbstraction({
|
|
2173
|
+
TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
2176
|
+
return new WrapperBasicSysAbstraction(my, {
|
|
2177
|
+
basicRuntimeService: new CFRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
|
|
2178
|
+
...param2
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
// src/deno/deno-basic-sys-abstraction.ts
|
|
2183
|
+
var DenoRuntimeService = class {
|
|
2184
|
+
constructor(ende) {
|
|
2185
|
+
this._txtEnDe = ende;
|
|
2131
2186
|
}
|
|
2132
|
-
|
|
2133
|
-
return
|
|
2187
|
+
Env() {
|
|
2188
|
+
return envFactory();
|
|
2134
2189
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
let val = this._url.searchParams.get(k);
|
|
2138
|
-
if (!falsy2undef(val) && d) {
|
|
2139
|
-
val = d;
|
|
2140
|
-
}
|
|
2141
|
-
return falsy2undef(val);
|
|
2190
|
+
Args() {
|
|
2191
|
+
return globalThis.Deno.args;
|
|
2142
2192
|
}
|
|
2143
|
-
|
|
2144
|
-
return
|
|
2193
|
+
Stdout() {
|
|
2194
|
+
return globalThis.Deno.stdout.writable;
|
|
2145
2195
|
}
|
|
2146
|
-
|
|
2147
|
-
return
|
|
2196
|
+
Stderr() {
|
|
2197
|
+
return globalThis.Deno.stderr.writable;
|
|
2148
2198
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2199
|
+
};
|
|
2200
|
+
var baseSysAbstraction3 = new ResolveOnce();
|
|
2201
|
+
function DenoBasicSysAbstraction(param2) {
|
|
2202
|
+
var _a;
|
|
2203
|
+
const my = baseSysAbstraction3.once(() => {
|
|
2204
|
+
return new BaseBasicSysAbstraction({
|
|
2205
|
+
TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
|
|
2206
|
+
});
|
|
2207
|
+
});
|
|
2208
|
+
return new WrapperBasicSysAbstraction(my, {
|
|
2209
|
+
basicRuntimeService: new DenoRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
|
|
2210
|
+
...param2
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
// src/node/node-basic-sys-abstraction.ts
|
|
2215
|
+
var NodeRuntimeService = class {
|
|
2216
|
+
constructor(ende) {
|
|
2217
|
+
this._txtEnDe = ende;
|
|
2218
|
+
this._gthis = globalThis;
|
|
2151
2219
|
}
|
|
2152
|
-
|
|
2153
|
-
return
|
|
2220
|
+
Env() {
|
|
2221
|
+
return envFactory();
|
|
2154
2222
|
}
|
|
2155
|
-
|
|
2156
|
-
return this.
|
|
2223
|
+
Args() {
|
|
2224
|
+
return this._gthis.process.argv;
|
|
2157
2225
|
}
|
|
2158
|
-
|
|
2159
|
-
return
|
|
2226
|
+
Stdout() {
|
|
2227
|
+
return new WritableStream({
|
|
2228
|
+
write: (chunk) => {
|
|
2229
|
+
this._gthis.process.stdout.write(chunk);
|
|
2230
|
+
}
|
|
2231
|
+
});
|
|
2160
2232
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
};
|
|
2168
|
-
if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
|
|
2169
|
-
return stripper(strips, {
|
|
2170
|
-
...pathURI,
|
|
2171
|
-
style: "host",
|
|
2172
|
-
hostname: this.hostname,
|
|
2173
|
-
port: this.port
|
|
2174
|
-
});
|
|
2175
|
-
}
|
|
2176
|
-
return stripper(strips, pathURI);
|
|
2233
|
+
Stderr() {
|
|
2234
|
+
return new WritableStream({
|
|
2235
|
+
write: (chunk) => {
|
|
2236
|
+
this._gthis.process.stderr.write(chunk);
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2177
2239
|
}
|
|
2178
2240
|
};
|
|
2241
|
+
var baseSysAbstraction4 = new ResolveOnce();
|
|
2242
|
+
function NodeBasicSysAbstraction(param2) {
|
|
2243
|
+
var _a;
|
|
2244
|
+
const my = baseSysAbstraction4.once(() => {
|
|
2245
|
+
return new BaseBasicSysAbstraction({
|
|
2246
|
+
TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
|
|
2247
|
+
});
|
|
2248
|
+
});
|
|
2249
|
+
return new WrapperBasicSysAbstraction(my, {
|
|
2250
|
+
basicRuntimeService: new NodeRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
|
|
2251
|
+
...param2
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2179
2254
|
|
|
2180
|
-
// src/
|
|
2181
|
-
var
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
this.desiredSize = null;
|
|
2185
|
-
this.decoder = new TextDecoder();
|
|
2186
|
-
this._stream = stream;
|
|
2187
|
-
this.ready = Promise.resolve(void 0);
|
|
2188
|
-
this.closed = Promise.resolve(void 0);
|
|
2255
|
+
// src/base-sys-abstraction.ts
|
|
2256
|
+
var SysTime = class extends Time {
|
|
2257
|
+
Now() {
|
|
2258
|
+
return /* @__PURE__ */ new Date();
|
|
2189
2259
|
}
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2260
|
+
Sleep(duration) {
|
|
2261
|
+
return new Promise((resolve) => {
|
|
2262
|
+
setTimeout(() => {
|
|
2263
|
+
resolve();
|
|
2264
|
+
}, duration);
|
|
2265
|
+
});
|
|
2193
2266
|
}
|
|
2194
|
-
|
|
2267
|
+
};
|
|
2268
|
+
var ConstTime = class extends Time {
|
|
2269
|
+
Now() {
|
|
2270
|
+
return new Date(2021, 1, 1, 0, 0, 0, 0);
|
|
2195
2271
|
}
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
this.closed = Promise.resolve(void 0);
|
|
2272
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2273
|
+
Sleep(duration) {
|
|
2274
|
+
return Promise.resolve();
|
|
2200
2275
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2276
|
+
};
|
|
2277
|
+
var StepTime = class extends Time {
|
|
2278
|
+
constructor() {
|
|
2279
|
+
super();
|
|
2280
|
+
this._step = new ConstTime().Now();
|
|
2281
|
+
this._start = this._step;
|
|
2282
|
+
}
|
|
2283
|
+
Now(steps = 1) {
|
|
2284
|
+
for (let i = 0; steps > 0 && i < steps; i++) {
|
|
2285
|
+
this._step = new Date(this._step.getTime() + 1e3);
|
|
2208
2286
|
}
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
console.error(strObj);
|
|
2212
|
-
break;
|
|
2213
|
-
case "warn":
|
|
2214
|
-
console.warn(strObj);
|
|
2215
|
-
break;
|
|
2216
|
-
default:
|
|
2217
|
-
console.log(strObj);
|
|
2287
|
+
if (steps < 1) {
|
|
2288
|
+
this._step = new Date(this._start.getTime() + steps * -1e3);
|
|
2218
2289
|
}
|
|
2290
|
+
return this._step;
|
|
2291
|
+
}
|
|
2292
|
+
Sleep(duration) {
|
|
2293
|
+
this._step = new Date(this._step.getTime() + duration);
|
|
2219
2294
|
return Promise.resolve();
|
|
2220
2295
|
}
|
|
2221
2296
|
};
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2297
|
+
function TimeFactory(timeMode) {
|
|
2298
|
+
switch (timeMode) {
|
|
2299
|
+
case TimeMode.REAL:
|
|
2300
|
+
return new SysTime();
|
|
2301
|
+
case TimeMode.CONST:
|
|
2302
|
+
return new ConstTime();
|
|
2303
|
+
case TimeMode.STEP:
|
|
2304
|
+
return new StepTime();
|
|
2225
2305
|
}
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2306
|
+
return new SysTime();
|
|
2307
|
+
}
|
|
2308
|
+
var RandomService = class {
|
|
2309
|
+
constructor(mode) {
|
|
2310
|
+
this._step = 0;
|
|
2311
|
+
this._mode = mode;
|
|
2229
2312
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2313
|
+
Random0ToValue(value) {
|
|
2314
|
+
switch (this._mode) {
|
|
2315
|
+
case RandomMode.CONST:
|
|
2316
|
+
return 0.5 * value;
|
|
2317
|
+
case RandomMode.STEP:
|
|
2318
|
+
this._step += 1e-4;
|
|
2319
|
+
return this._step * value;
|
|
2320
|
+
case RandomMode.RANDOM:
|
|
2321
|
+
return Math.random() * value;
|
|
2322
|
+
default:
|
|
2323
|
+
throw new Error("Unknown RandomMode");
|
|
2324
|
+
}
|
|
2232
2325
|
}
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2326
|
+
};
|
|
2327
|
+
var IdService = class {
|
|
2328
|
+
constructor(mode) {
|
|
2329
|
+
this._step = 0;
|
|
2330
|
+
if (!mode) {
|
|
2331
|
+
mode = IDMode.UUID;
|
|
2236
2332
|
}
|
|
2237
|
-
this.
|
|
2238
|
-
|
|
2239
|
-
|
|
2333
|
+
this._mode = mode;
|
|
2334
|
+
}
|
|
2335
|
+
NextId() {
|
|
2336
|
+
switch (this._mode) {
|
|
2337
|
+
case IDMode.UUID:
|
|
2338
|
+
return crypto.randomUUID();
|
|
2339
|
+
case IDMode.CONST:
|
|
2340
|
+
return "VeryUniqueID";
|
|
2341
|
+
case IDMode.STEP:
|
|
2342
|
+
return `STEPId-${this._step++}`;
|
|
2343
|
+
default:
|
|
2344
|
+
throw new Error("Unknown IDMode");
|
|
2240
2345
|
}
|
|
2241
|
-
return this._writer;
|
|
2242
2346
|
}
|
|
2243
2347
|
};
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
this.
|
|
2249
|
-
this.
|
|
2250
|
-
this.
|
|
2251
|
-
this._out = out;
|
|
2348
|
+
var BaseBasicSysAbstraction = class {
|
|
2349
|
+
constructor(params) {
|
|
2350
|
+
this._time = new SysTime();
|
|
2351
|
+
// system independent services
|
|
2352
|
+
this._idService = new IdService();
|
|
2353
|
+
this._randomService = new RandomService(RandomMode.RANDOM);
|
|
2354
|
+
this._txtEnDe = params.TxtEnDecoder;
|
|
2252
2355
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2356
|
+
};
|
|
2357
|
+
function BasicSysAbstractionFactory(params) {
|
|
2358
|
+
const fn = runtimeFn();
|
|
2359
|
+
switch (true) {
|
|
2360
|
+
case fn.isBrowser:
|
|
2361
|
+
return WebBasicSysAbstraction(params);
|
|
2362
|
+
case fn.isDeno:
|
|
2363
|
+
return DenoBasicSysAbstraction(params);
|
|
2364
|
+
case fn.isCFWorker:
|
|
2365
|
+
return CFBasicSysAbstraction(params);
|
|
2366
|
+
case fn.isNodeIsh:
|
|
2367
|
+
return NodeBasicSysAbstraction(params);
|
|
2368
|
+
default:
|
|
2369
|
+
throw new Error("Unknown runtime");
|
|
2266
2370
|
}
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2371
|
+
}
|
|
2372
|
+
var WrapperBasicSysAbstraction = class {
|
|
2373
|
+
constructor(base, params) {
|
|
2374
|
+
this._time = base._time;
|
|
2375
|
+
this._basicRuntimeService = params.basicRuntimeService;
|
|
2376
|
+
this._idService = base._idService;
|
|
2377
|
+
this._randomService = base._randomService;
|
|
2378
|
+
if (params.TimeMode) {
|
|
2379
|
+
this._time = TimeFactory(params.TimeMode);
|
|
2270
2380
|
}
|
|
2271
|
-
if (
|
|
2272
|
-
this.
|
|
2273
|
-
this._flushDoneFns.forEach((fn) => fn());
|
|
2274
|
-
this._flushDoneFns = [];
|
|
2275
|
-
return;
|
|
2381
|
+
if (params.IdMode) {
|
|
2382
|
+
this._idService = new IdService(params.IdMode);
|
|
2276
2383
|
}
|
|
2277
|
-
if (
|
|
2278
|
-
this.
|
|
2279
|
-
} else if (!toFlush) {
|
|
2280
|
-
return;
|
|
2384
|
+
if (params.RandomMode) {
|
|
2385
|
+
this._randomService = new RandomService(params.RandomMode);
|
|
2281
2386
|
}
|
|
2282
|
-
const my2 = this._toFlush.shift();
|
|
2283
|
-
my2 == null ? void 0 : my2().catch((e) => {
|
|
2284
|
-
console.error("Flush error:", e);
|
|
2285
|
-
}).finally(() => {
|
|
2286
|
-
this._flush(this._toFlush);
|
|
2287
|
-
});
|
|
2288
2387
|
}
|
|
2388
|
+
Time() {
|
|
2389
|
+
return this._time;
|
|
2390
|
+
}
|
|
2391
|
+
NextId() {
|
|
2392
|
+
return this._idService.NextId();
|
|
2393
|
+
}
|
|
2394
|
+
Random0ToValue(value) {
|
|
2395
|
+
return this._randomService.Random0ToValue(value);
|
|
2396
|
+
}
|
|
2397
|
+
Stdout() {
|
|
2398
|
+
return this._basicRuntimeService.Stdout();
|
|
2399
|
+
}
|
|
2400
|
+
Stderr() {
|
|
2401
|
+
return this._basicRuntimeService.Stderr();
|
|
2402
|
+
}
|
|
2403
|
+
Env() {
|
|
2404
|
+
return this._basicRuntimeService.Env();
|
|
2405
|
+
}
|
|
2406
|
+
Args() {
|
|
2407
|
+
return this._basicRuntimeService.Args();
|
|
2408
|
+
}
|
|
2409
|
+
// System(): SystemService {
|
|
2410
|
+
// return this._systemService;
|
|
2411
|
+
// }
|
|
2412
|
+
// FileSystem(): FileService {
|
|
2413
|
+
// return this._fileSystem;
|
|
2414
|
+
// }
|
|
2289
2415
|
};
|
|
2290
2416
|
|
|
2291
2417
|
// src/logger-impl.ts
|
|
@@ -2338,7 +2464,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
2338
2464
|
params = {};
|
|
2339
2465
|
}
|
|
2340
2466
|
if (!params.sys) {
|
|
2341
|
-
this._sys =
|
|
2467
|
+
this._sys = BasicSysAbstractionFactory();
|
|
2342
2468
|
} else {
|
|
2343
2469
|
this._sys = params.sys;
|
|
2344
2470
|
}
|
|
@@ -2356,18 +2482,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
2356
2482
|
this._logWriter = params.logWriter;
|
|
2357
2483
|
} else {
|
|
2358
2484
|
if (!params.out) {
|
|
2359
|
-
|
|
2360
|
-
let stream;
|
|
2361
|
-
if (rt.isBrowser) {
|
|
2362
|
-
stream = new ConsoleWriterStream();
|
|
2363
|
-
} else {
|
|
2364
|
-
if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
|
|
2365
|
-
stream = this._sys.Stdout();
|
|
2366
|
-
} else {
|
|
2367
|
-
throw new Error("No output defined for runtime");
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
this._logWriter = new LogWriterStream(stream);
|
|
2485
|
+
this._logWriter = new LogWriterStream(this._sys.Stdout());
|
|
2371
2486
|
} else {
|
|
2372
2487
|
this._logWriter = new LogWriterStream(params.out);
|
|
2373
2488
|
}
|