@adviser/cement 0.2.16 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +147 -43
- package/index.cjs.map +1 -1
- package/index.d.cts +36 -20
- package/index.d.ts +36 -20
- package/index.js +144 -42
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { S as SysAbstraction } from './sys_abstraction-CmSCeK7b.js';
|
2
2
|
export { B as BrowserEnvActions, D as Duration, e as Env, c as EnvActions, d as EnvFactoryOpts, g as EnvImpl, E as EnvMap, F as FileService, I as IDMode, N as NamedWritableStream, O as OnSetItem, R as RandomMode, a as String2TimeMode, b as SystemService, h as Time, T as TimeMode, i as TimeUnits, V as VoidFunc, f as envFactory } from './sys_abstraction-CmSCeK7b.js';
|
3
|
+
import { WritableStreamDefaultWriter as WritableStreamDefaultWriter$1 } from 'stream/web';
|
3
4
|
|
4
5
|
declare abstract class Result<T, E = Error> {
|
5
6
|
static Ok<T>(t: T): Result<T, Error>;
|
@@ -164,7 +165,7 @@ declare class LevelHandlerImpl implements LevelHandler {
|
|
164
165
|
setDebug(...modules: (string | string[])[]): void;
|
165
166
|
isEnabled(ilevel: unknown, module: unknown): boolean;
|
166
167
|
}
|
167
|
-
declare class
|
168
|
+
declare class LogWriterStream {
|
168
169
|
readonly _out: WritableStream<Uint8Array>;
|
169
170
|
readonly _toFlush: (() => Promise<void>)[];
|
170
171
|
constructor(out: WritableStream<Uint8Array>);
|
@@ -175,7 +176,7 @@ declare class LogWriter$1 {
|
|
175
176
|
}
|
176
177
|
interface LoggerImplParams {
|
177
178
|
readonly out?: WritableStream<Uint8Array>;
|
178
|
-
readonly logWriter?:
|
179
|
+
readonly logWriter?: LogWriterStream;
|
179
180
|
readonly sys?: SysAbstraction;
|
180
181
|
readonly withAttributes?: LogSerializable;
|
181
182
|
readonly levelHandler?: LevelHandler;
|
@@ -184,7 +185,7 @@ declare class LoggerImpl implements Logger {
|
|
184
185
|
readonly _sys: SysAbstraction;
|
185
186
|
readonly _attributes: LogSerializable;
|
186
187
|
readonly _withAttributes: LogSerializable;
|
187
|
-
readonly _logWriter:
|
188
|
+
readonly _logWriter: LogWriterStream;
|
188
189
|
readonly _levelHandler: LevelHandler;
|
189
190
|
constructor(params?: LoggerImplParams);
|
190
191
|
SetExposeStack(enable?: boolean): Logger;
|
@@ -220,24 +221,46 @@ declare class LoggerImpl implements Logger {
|
|
220
221
|
Msg(...args: string[]): AsError;
|
221
222
|
}
|
222
223
|
|
223
|
-
declare class
|
224
|
-
|
225
|
-
_resolveClosed: (value?: PromiseLike<undefined>) => void;
|
226
|
-
closed: Promise<undefined>;
|
227
|
-
desiredSize: number | null;
|
228
|
-
ready: Promise<undefined>;
|
224
|
+
declare class Future<T> {
|
225
|
+
#private;
|
229
226
|
constructor();
|
227
|
+
asPromise(): Promise<T>;
|
228
|
+
resolve(value: T): void;
|
229
|
+
reject(reason: unknown): void;
|
230
|
+
}
|
231
|
+
|
232
|
+
declare class LogWriterCollector implements WritableStreamDefaultWriter$1<Uint8Array> {
|
233
|
+
private readonly _bufferArr;
|
234
|
+
constructor(bufferArr: Uint8Array[]);
|
235
|
+
readonly _resolveClosed: Future<undefined>;
|
236
|
+
readonly closed: Promise<undefined>;
|
237
|
+
readonly desiredSize: number | null;
|
238
|
+
readonly ready: Promise<undefined>;
|
230
239
|
abort(reason?: any): Promise<void>;
|
231
240
|
close(): Promise<void>;
|
232
241
|
releaseLock(): void;
|
233
242
|
write(chunk?: Uint8Array): Promise<void>;
|
234
243
|
}
|
244
|
+
declare class FanoutWriter implements WritableStreamDefaultWriter$1<Uint8Array> {
|
245
|
+
readonly _writers: WritableStreamDefaultWriter$1<Uint8Array>[];
|
246
|
+
readonly ready: Promise<undefined>;
|
247
|
+
readonly closed: Promise<undefined>;
|
248
|
+
readonly desiredSize: number | null;
|
249
|
+
constructor(writers: WritableStreamDefaultWriter$1<Uint8Array>[]);
|
250
|
+
abort(reason?: any): Promise<void>;
|
251
|
+
close(): Promise<void>;
|
252
|
+
releaseLock(): void;
|
253
|
+
write(chunk?: Uint8Array | undefined): Promise<void>;
|
254
|
+
}
|
235
255
|
declare class LogCollector implements WritableStream<Uint8Array> {
|
236
256
|
readonly locked: boolean;
|
237
|
-
_writer
|
257
|
+
private _writer?;
|
258
|
+
private readonly _pass?;
|
259
|
+
private readonly _bufferArr;
|
260
|
+
constructor(pass?: WritableStreamDefaultWriter$1<Uint8Array>);
|
238
261
|
abort(reason?: Uint8Array): Promise<void>;
|
239
262
|
close(): Promise<void>;
|
240
|
-
getWriter(): WritableStreamDefaultWriter<Uint8Array>;
|
263
|
+
getWriter(): WritableStreamDefaultWriter$1<Uint8Array>;
|
241
264
|
Logs(): any[];
|
242
265
|
}
|
243
266
|
|
@@ -247,6 +270,7 @@ interface MockLoggerReturn {
|
|
247
270
|
}
|
248
271
|
declare function MockLogger(params?: {
|
249
272
|
readonly sys?: SysAbstraction;
|
273
|
+
readonly pass?: WritableStreamDefaultWriter<Uint8Array>;
|
250
274
|
moduleName?: string | string[];
|
251
275
|
readonly disableDebug?: boolean;
|
252
276
|
}): MockLoggerReturn;
|
@@ -276,14 +300,6 @@ declare class None<T> extends Option<T> {
|
|
276
300
|
}
|
277
301
|
type WithoutOption<T> = T extends Option<infer U> ? U : T;
|
278
302
|
|
279
|
-
declare class Future<T> {
|
280
|
-
#private;
|
281
|
-
constructor();
|
282
|
-
asPromise(): Promise<T>;
|
283
|
-
resolve(value: T): void;
|
284
|
-
reject(reason: unknown): void;
|
285
|
-
}
|
286
|
-
|
287
303
|
interface ResolveSeqItem<T, C> {
|
288
304
|
readonly future: Future<T>;
|
289
305
|
readonly fn: (c: C) => Promise<T>;
|
@@ -409,4 +425,4 @@ interface CryptoRuntime {
|
|
409
425
|
}
|
410
426
|
declare function toCryptoRuntime(cryptoOpts?: Partial<CryptoRuntime>): CryptoRuntime;
|
411
427
|
|
412
|
-
export { type AsError, BuildURI, type CTAesKeyAlgorithm, type CTAlgorithm, type CTAlgorithmIdentifier, type CTArrayBufferView, type CTBufferSource, type CTCryptoKey, type CTEcKeyImportParams, type CTHmacImportParams, type CTJsonWebKey, type CTKeyFormat, type CTKeyType, type CTKeyUsage, type CTNamedCurve, type CTRsaHashedImportParams, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, IsLogger, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LogCollector, type LogSerializable, LogValue,
|
428
|
+
export { type AsError, BuildURI, type CTAesKeyAlgorithm, type CTAlgorithm, type CTAlgorithmIdentifier, type CTArrayBufferView, type CTBufferSource, type CTCryptoKey, type CTEcKeyImportParams, type CTHmacImportParams, type CTJsonWebKey, type CTKeyFormat, type CTKeyType, type CTKeyUsage, type CTNamedCurve, type CTRsaHashedImportParams, type CoerceURI, type CryptoRuntime, FanoutWriter, type FnSerialized, Future, IsLogger, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LogCollector, type LogSerializable, LogValue, LogWriterCollector, LogWriterStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, MockLogger, type MockLoggerReturn, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, URI, type WithLogger, type WithoutOption, type WithoutResult, asyncLogValue, isURL, logValue, removeSelfRef, runtimeFn, toCryptoRuntime };
|
package/index.js
CHANGED
@@ -299,6 +299,29 @@ var URI = class _URI {
|
|
299
299
|
}
|
300
300
|
};
|
301
301
|
|
302
|
+
// src/runtime.ts
|
303
|
+
function isSet(value, ref = globalThis) {
|
304
|
+
const [head, ...tail] = value.split(".");
|
305
|
+
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
306
|
+
if (tail.length <= 1) {
|
307
|
+
return true;
|
308
|
+
}
|
309
|
+
return isSet(tail.join("."), ref[head]);
|
310
|
+
}
|
311
|
+
return false;
|
312
|
+
}
|
313
|
+
function runtimeFn() {
|
314
|
+
const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
|
315
|
+
const isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
316
|
+
const isDeno = isSet("Deno") && !isReactNative;
|
317
|
+
return {
|
318
|
+
isNodeIsh,
|
319
|
+
isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
|
320
|
+
isDeno,
|
321
|
+
isReactNative
|
322
|
+
};
|
323
|
+
}
|
324
|
+
|
302
325
|
// src/logger_impl.ts
|
303
326
|
var encoder = new TextEncoder();
|
304
327
|
var LevelHandlerImpl = class {
|
@@ -377,7 +400,7 @@ var LevelHandlerImpl = class {
|
|
377
400
|
}
|
378
401
|
};
|
379
402
|
var levelSingleton = new LevelHandlerImpl();
|
380
|
-
var
|
403
|
+
var LogWriterStream = class {
|
381
404
|
constructor(out) {
|
382
405
|
this._toFlush = [];
|
383
406
|
this._flushIsRunning = false;
|
@@ -443,6 +466,68 @@ function toLogValue(lop) {
|
|
443
466
|
}
|
444
467
|
return lop;
|
445
468
|
}
|
469
|
+
var ConsoleWriterStreamDefaultWriter = class {
|
470
|
+
constructor(stream) {
|
471
|
+
this.stream = stream;
|
472
|
+
this.desiredSize = null;
|
473
|
+
this.decoder = new TextDecoder();
|
474
|
+
this._stream = stream;
|
475
|
+
this.ready = Promise.resolve(void 0);
|
476
|
+
this.closed = Promise.resolve(void 0);
|
477
|
+
}
|
478
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
479
|
+
abort(reason) {
|
480
|
+
throw new Error("Method not implemented.");
|
481
|
+
}
|
482
|
+
async close() {
|
483
|
+
}
|
484
|
+
releaseLock() {
|
485
|
+
this._stream.locked = false;
|
486
|
+
this.ready = Promise.resolve(void 0);
|
487
|
+
this.closed = Promise.resolve(void 0);
|
488
|
+
}
|
489
|
+
async write(chunk) {
|
490
|
+
const str = this.decoder.decode(chunk).trimEnd();
|
491
|
+
let output = "log";
|
492
|
+
try {
|
493
|
+
const decode = JSON.parse(str);
|
494
|
+
output = decode.level;
|
495
|
+
} catch (e) {
|
496
|
+
}
|
497
|
+
switch (output) {
|
498
|
+
case "error":
|
499
|
+
console.error(str);
|
500
|
+
break;
|
501
|
+
case "warn":
|
502
|
+
console.warn(str);
|
503
|
+
break;
|
504
|
+
default:
|
505
|
+
console.log(str);
|
506
|
+
}
|
507
|
+
}
|
508
|
+
};
|
509
|
+
var ConsoleWriterStream = class {
|
510
|
+
constructor() {
|
511
|
+
this.locked = false;
|
512
|
+
}
|
513
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
514
|
+
abort(reason) {
|
515
|
+
throw new Error("Method not implemented.");
|
516
|
+
}
|
517
|
+
async close() {
|
518
|
+
return;
|
519
|
+
}
|
520
|
+
getWriter() {
|
521
|
+
if (this.locked) {
|
522
|
+
throw new Error("Stream is locked");
|
523
|
+
}
|
524
|
+
this.locked = true;
|
525
|
+
if (!this._writer) {
|
526
|
+
this._writer = new ConsoleWriterStreamDefaultWriter(this);
|
527
|
+
}
|
528
|
+
return this._writer;
|
529
|
+
}
|
530
|
+
};
|
446
531
|
var LoggerImpl = class _LoggerImpl {
|
447
532
|
// readonly _id: string = "logger-" + Math.random().toString(36)
|
448
533
|
constructor(params) {
|
@@ -459,9 +544,20 @@ var LoggerImpl = class _LoggerImpl {
|
|
459
544
|
this._logWriter = params.logWriter;
|
460
545
|
} else {
|
461
546
|
if (!params.out) {
|
462
|
-
|
547
|
+
const rt = runtimeFn();
|
548
|
+
let stream;
|
549
|
+
if (rt.isBrowser) {
|
550
|
+
stream = new ConsoleWriterStream();
|
551
|
+
} else {
|
552
|
+
if (rt.isNodeIsh || rt.isReactNative) {
|
553
|
+
stream = this._sys.Stdout();
|
554
|
+
} else {
|
555
|
+
throw new Error("No output defined for runtime");
|
556
|
+
}
|
557
|
+
}
|
558
|
+
this._logWriter = new LogWriterStream(stream);
|
463
559
|
} else {
|
464
|
-
this._logWriter = new
|
560
|
+
this._logWriter = new LogWriterStream(params.out);
|
465
561
|
}
|
466
562
|
}
|
467
563
|
if (!params.withAttributes) {
|
@@ -758,37 +854,60 @@ var WithLoggerBuilder = class {
|
|
758
854
|
};
|
759
855
|
|
760
856
|
// src/test/log_collector.ts
|
761
|
-
var
|
762
|
-
constructor() {
|
763
|
-
this.
|
857
|
+
var LogWriterCollector = class {
|
858
|
+
constructor(bufferArr) {
|
859
|
+
this._resolveClosed = new Future();
|
860
|
+
this.closed = this._resolveClosed.asPromise();
|
764
861
|
this.desiredSize = null;
|
765
862
|
this.ready = Promise.resolve(void 0);
|
766
|
-
this.
|
767
|
-
};
|
768
|
-
this.closed = new Promise((resolve) => {
|
769
|
-
this._resolveClosed = resolve;
|
770
|
-
});
|
863
|
+
this._bufferArr = bufferArr;
|
771
864
|
}
|
772
865
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
773
866
|
abort(reason) {
|
774
867
|
throw new Error("Method not implemented.");
|
775
868
|
}
|
776
|
-
close() {
|
777
|
-
this.
|
869
|
+
async close() {
|
870
|
+
await this.closed;
|
778
871
|
return Promise.resolve(void 0);
|
779
872
|
}
|
780
873
|
releaseLock() {
|
781
874
|
}
|
782
|
-
write(chunk) {
|
875
|
+
async write(chunk) {
|
783
876
|
if (chunk) {
|
784
877
|
this._bufferArr.push(chunk);
|
785
878
|
}
|
786
879
|
return Promise.resolve(void 0);
|
787
880
|
}
|
788
881
|
};
|
882
|
+
var FanoutWriter = class {
|
883
|
+
constructor(writers) {
|
884
|
+
this.desiredSize = null;
|
885
|
+
this._writers = writers;
|
886
|
+
this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => void 0);
|
887
|
+
this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => void 0);
|
888
|
+
}
|
889
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
890
|
+
abort(reason) {
|
891
|
+
return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {
|
892
|
+
});
|
893
|
+
}
|
894
|
+
close() {
|
895
|
+
return Promise.all(this._writers.map((w) => w.close())).then(() => {
|
896
|
+
});
|
897
|
+
}
|
898
|
+
releaseLock() {
|
899
|
+
this._writers.map((w) => w.releaseLock());
|
900
|
+
}
|
901
|
+
write(chunk) {
|
902
|
+
return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {
|
903
|
+
});
|
904
|
+
}
|
905
|
+
};
|
789
906
|
var LogCollector = class {
|
790
|
-
constructor() {
|
907
|
+
constructor(pass) {
|
791
908
|
this.locked = false;
|
909
|
+
this._bufferArr = [];
|
910
|
+
this._pass = pass;
|
792
911
|
}
|
793
912
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
794
913
|
abort(reason) {
|
@@ -804,7 +923,11 @@ var LogCollector = class {
|
|
804
923
|
}
|
805
924
|
getWriter() {
|
806
925
|
if (!this._writer) {
|
807
|
-
|
926
|
+
const dests = [new LogWriterCollector(this._bufferArr)];
|
927
|
+
if (this._pass) {
|
928
|
+
dests.push(this._pass);
|
929
|
+
}
|
930
|
+
this._writer = new FanoutWriter(dests);
|
808
931
|
}
|
809
932
|
return this._writer;
|
810
933
|
}
|
@@ -819,7 +942,7 @@ var LogCollector = class {
|
|
819
942
|
for (const x of res) {
|
820
943
|
yield* __yieldStar(x);
|
821
944
|
}
|
822
|
-
}(this.
|
945
|
+
}(this._bufferArr)
|
823
946
|
)
|
824
947
|
);
|
825
948
|
const splitStr = jsonNlStr.split("\n");
|
@@ -831,7 +954,7 @@ var LogCollector = class {
|
|
831
954
|
|
832
955
|
// src/test/mock_logger.ts
|
833
956
|
function MockLogger(params) {
|
834
|
-
const lc = new LogCollector();
|
957
|
+
const lc = new LogCollector(params == null ? void 0 : params.pass);
|
835
958
|
let modNames = ["MockLogger"];
|
836
959
|
if (typeof (params == null ? void 0 : params.moduleName) === "string") {
|
837
960
|
modNames = [params == null ? void 0 : params.moduleName];
|
@@ -974,29 +1097,6 @@ var None = class extends Option {
|
|
974
1097
|
}
|
975
1098
|
};
|
976
1099
|
|
977
|
-
// src/runtime.ts
|
978
|
-
function isSet(value, ref = globalThis) {
|
979
|
-
const [head, ...tail] = value.split(".");
|
980
|
-
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
981
|
-
if (tail.length <= 1) {
|
982
|
-
return true;
|
983
|
-
}
|
984
|
-
return isSet(tail.join("."), ref[head]);
|
985
|
-
}
|
986
|
-
return false;
|
987
|
-
}
|
988
|
-
function runtimeFn() {
|
989
|
-
const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
|
990
|
-
const isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
991
|
-
const isDeno = isSet("Deno") && !isReactNative;
|
992
|
-
return {
|
993
|
-
isNodeIsh,
|
994
|
-
isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
|
995
|
-
isDeno,
|
996
|
-
isReactNative
|
997
|
-
};
|
998
|
-
}
|
999
|
-
|
1000
1100
|
// src/crypto.ts
|
1001
1101
|
function randomBytes(size) {
|
1002
1102
|
const bytes = new Uint8Array(size);
|
@@ -1022,6 +1122,7 @@ export {
|
|
1022
1122
|
BrowserEnvActions,
|
1023
1123
|
BuildURI,
|
1024
1124
|
EnvImpl,
|
1125
|
+
FanoutWriter,
|
1025
1126
|
Future,
|
1026
1127
|
IDMode,
|
1027
1128
|
IsLogger,
|
@@ -1032,7 +1133,8 @@ export {
|
|
1032
1133
|
LevelHandlerImpl,
|
1033
1134
|
LogCollector,
|
1034
1135
|
LogValue,
|
1035
|
-
|
1136
|
+
LogWriterCollector,
|
1137
|
+
LogWriterStream,
|
1036
1138
|
LoggerImpl,
|
1037
1139
|
MockLogger,
|
1038
1140
|
None,
|