@adviser/cement 0.2.15 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { S as SysAbstraction } from './sys_abstraction-CmSCeK7b.cjs';
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.cjs';
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>;
@@ -86,17 +87,17 @@ declare enum Level {
86
87
  ERROR = "error"
87
88
  }
88
89
  type Serialized = string | number | boolean;
89
- type FnSerialized = () => Serialized;
90
+ type FnSerialized = () => Serialized | Serialized[];
90
91
  declare class LogValue {
91
92
  readonly fn: FnSerialized;
92
93
  constructor(fn: FnSerialized);
93
- value(): Serialized;
94
- toJSON(): Serialized;
94
+ value(): Serialized | Serialized[];
95
+ toJSON(): Serialized | Serialized[];
95
96
  }
96
97
  type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
97
98
  declare function removeSelfRef(): (key: unknown, val: unknown) => unknown;
98
99
  declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
99
- declare function logValue(val: Serialized | FnSerialized | LogSerializable | undefined | null): LogValue;
100
+ declare function logValue(val: Serialized | Serialized[] | FnSerialized | LogSerializable | undefined | null): LogValue;
100
101
  interface Sized {
101
102
  size: number;
102
103
  }
@@ -109,6 +110,7 @@ interface LoggerInterface<R> {
109
110
  EnableLevel(level: Level, ...modules: string[]): R;
110
111
  DisableLevel(level: Level, ...modules: string[]): R;
111
112
  SetDebug(...modules: (string | string[])[]): R;
113
+ SetExposeStack(enable?: boolean): R;
112
114
  Ref(key: string, action: {
113
115
  toString: () => string;
114
116
  } | FnSerialized): R;
@@ -147,19 +149,23 @@ interface Logger extends LoggerInterface<Logger> {
147
149
  interface LevelHandler {
148
150
  enableLevel(level: Level, ...modules: string[]): void;
149
151
  disableLevel(level: Level, ...modules: string[]): void;
152
+ setExposeStack(enable?: boolean): void;
153
+ isStackExposed: boolean;
150
154
  setDebug(...modules: (string | string[])[]): void;
151
155
  isEnabled(ilevel: unknown, module: unknown): boolean;
152
156
  }
153
157
  declare class LevelHandlerImpl implements LevelHandler {
154
158
  readonly _globalLevels: Set<Level>;
155
159
  readonly _modules: Map<string, Set<Level>>;
160
+ isStackExposed: boolean;
156
161
  enableLevel(level: Level, ...modules: string[]): void;
157
162
  disableLevel(level: Level, ...modules: string[]): void;
163
+ setExposeStack(enable?: boolean): void;
158
164
  forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void;
159
165
  setDebug(...modules: (string | string[])[]): void;
160
166
  isEnabled(ilevel: unknown, module: unknown): boolean;
161
167
  }
162
- declare class LogWriter$1 {
168
+ declare class LogWriterStream {
163
169
  readonly _out: WritableStream<Uint8Array>;
164
170
  readonly _toFlush: (() => Promise<void>)[];
165
171
  constructor(out: WritableStream<Uint8Array>);
@@ -170,7 +176,7 @@ declare class LogWriter$1 {
170
176
  }
171
177
  interface LoggerImplParams {
172
178
  readonly out?: WritableStream<Uint8Array>;
173
- readonly logWriter?: LogWriter$1;
179
+ readonly logWriter?: LogWriterStream;
174
180
  readonly sys?: SysAbstraction;
175
181
  readonly withAttributes?: LogSerializable;
176
182
  readonly levelHandler?: LevelHandler;
@@ -179,9 +185,10 @@ declare class LoggerImpl implements Logger {
179
185
  readonly _sys: SysAbstraction;
180
186
  readonly _attributes: LogSerializable;
181
187
  readonly _withAttributes: LogSerializable;
182
- readonly _logWriter: LogWriter$1;
188
+ readonly _logWriter: LogWriterStream;
183
189
  readonly _levelHandler: LevelHandler;
184
190
  constructor(params?: LoggerImplParams);
191
+ SetExposeStack(enable?: boolean): Logger;
185
192
  EnableLevel(level: Level, ...modules: string[]): Logger;
186
193
  DisableLevel(level: Level, ...modules: string[]): Logger;
187
194
  Module(key: string): Logger;
@@ -214,24 +221,46 @@ declare class LoggerImpl implements Logger {
214
221
  Msg(...args: string[]): AsError;
215
222
  }
216
223
 
217
- declare class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {
218
- readonly _bufferArr: Uint8Array[];
219
- _resolveClosed: (value?: PromiseLike<undefined>) => void;
220
- closed: Promise<undefined>;
221
- desiredSize: number | null;
222
- ready: Promise<undefined>;
224
+ declare class Future<T> {
225
+ #private;
223
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>;
224
239
  abort(reason?: any): Promise<void>;
225
240
  close(): Promise<void>;
226
241
  releaseLock(): void;
227
242
  write(chunk?: Uint8Array): Promise<void>;
228
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
+ }
229
255
  declare class LogCollector implements WritableStream<Uint8Array> {
230
256
  readonly locked: boolean;
231
- _writer?: LogWriter;
257
+ private _writer?;
258
+ private readonly _pass?;
259
+ private readonly _bufferArr;
260
+ constructor(pass?: WritableStreamDefaultWriter$1<Uint8Array>);
232
261
  abort(reason?: Uint8Array): Promise<void>;
233
262
  close(): Promise<void>;
234
- getWriter(): WritableStreamDefaultWriter<Uint8Array>;
263
+ getWriter(): WritableStreamDefaultWriter$1<Uint8Array>;
235
264
  Logs(): any[];
236
265
  }
237
266
 
@@ -241,6 +270,7 @@ interface MockLoggerReturn {
241
270
  }
242
271
  declare function MockLogger(params?: {
243
272
  readonly sys?: SysAbstraction;
273
+ readonly pass?: WritableStreamDefaultWriter<Uint8Array>;
244
274
  moduleName?: string | string[];
245
275
  readonly disableDebug?: boolean;
246
276
  }): MockLoggerReturn;
@@ -270,14 +300,6 @@ declare class None<T> extends Option<T> {
270
300
  }
271
301
  type WithoutOption<T> = T extends Option<infer U> ? U : T;
272
302
 
273
- declare class Future<T> {
274
- #private;
275
- constructor();
276
- asPromise(): Promise<T>;
277
- resolve(value: T): void;
278
- reject(reason: unknown): void;
279
- }
280
-
281
303
  interface ResolveSeqItem<T, C> {
282
304
  readonly future: Future<T>;
283
305
  readonly fn: (c: C) => Promise<T>;
@@ -403,4 +425,4 @@ interface CryptoRuntime {
403
425
  }
404
426
  declare function toCryptoRuntime(cryptoOpts?: Partial<CryptoRuntime>): CryptoRuntime;
405
427
 
406
- 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, LogWriter$1 as LogWriter, 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 };
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.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>;
@@ -86,17 +87,17 @@ declare enum Level {
86
87
  ERROR = "error"
87
88
  }
88
89
  type Serialized = string | number | boolean;
89
- type FnSerialized = () => Serialized;
90
+ type FnSerialized = () => Serialized | Serialized[];
90
91
  declare class LogValue {
91
92
  readonly fn: FnSerialized;
92
93
  constructor(fn: FnSerialized);
93
- value(): Serialized;
94
- toJSON(): Serialized;
94
+ value(): Serialized | Serialized[];
95
+ toJSON(): Serialized | Serialized[];
95
96
  }
96
97
  type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
97
98
  declare function removeSelfRef(): (key: unknown, val: unknown) => unknown;
98
99
  declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
99
- declare function logValue(val: Serialized | FnSerialized | LogSerializable | undefined | null): LogValue;
100
+ declare function logValue(val: Serialized | Serialized[] | FnSerialized | LogSerializable | undefined | null): LogValue;
100
101
  interface Sized {
101
102
  size: number;
102
103
  }
@@ -109,6 +110,7 @@ interface LoggerInterface<R> {
109
110
  EnableLevel(level: Level, ...modules: string[]): R;
110
111
  DisableLevel(level: Level, ...modules: string[]): R;
111
112
  SetDebug(...modules: (string | string[])[]): R;
113
+ SetExposeStack(enable?: boolean): R;
112
114
  Ref(key: string, action: {
113
115
  toString: () => string;
114
116
  } | FnSerialized): R;
@@ -147,19 +149,23 @@ interface Logger extends LoggerInterface<Logger> {
147
149
  interface LevelHandler {
148
150
  enableLevel(level: Level, ...modules: string[]): void;
149
151
  disableLevel(level: Level, ...modules: string[]): void;
152
+ setExposeStack(enable?: boolean): void;
153
+ isStackExposed: boolean;
150
154
  setDebug(...modules: (string | string[])[]): void;
151
155
  isEnabled(ilevel: unknown, module: unknown): boolean;
152
156
  }
153
157
  declare class LevelHandlerImpl implements LevelHandler {
154
158
  readonly _globalLevels: Set<Level>;
155
159
  readonly _modules: Map<string, Set<Level>>;
160
+ isStackExposed: boolean;
156
161
  enableLevel(level: Level, ...modules: string[]): void;
157
162
  disableLevel(level: Level, ...modules: string[]): void;
163
+ setExposeStack(enable?: boolean): void;
158
164
  forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void;
159
165
  setDebug(...modules: (string | string[])[]): void;
160
166
  isEnabled(ilevel: unknown, module: unknown): boolean;
161
167
  }
162
- declare class LogWriter$1 {
168
+ declare class LogWriterStream {
163
169
  readonly _out: WritableStream<Uint8Array>;
164
170
  readonly _toFlush: (() => Promise<void>)[];
165
171
  constructor(out: WritableStream<Uint8Array>);
@@ -170,7 +176,7 @@ declare class LogWriter$1 {
170
176
  }
171
177
  interface LoggerImplParams {
172
178
  readonly out?: WritableStream<Uint8Array>;
173
- readonly logWriter?: LogWriter$1;
179
+ readonly logWriter?: LogWriterStream;
174
180
  readonly sys?: SysAbstraction;
175
181
  readonly withAttributes?: LogSerializable;
176
182
  readonly levelHandler?: LevelHandler;
@@ -179,9 +185,10 @@ declare class LoggerImpl implements Logger {
179
185
  readonly _sys: SysAbstraction;
180
186
  readonly _attributes: LogSerializable;
181
187
  readonly _withAttributes: LogSerializable;
182
- readonly _logWriter: LogWriter$1;
188
+ readonly _logWriter: LogWriterStream;
183
189
  readonly _levelHandler: LevelHandler;
184
190
  constructor(params?: LoggerImplParams);
191
+ SetExposeStack(enable?: boolean): Logger;
185
192
  EnableLevel(level: Level, ...modules: string[]): Logger;
186
193
  DisableLevel(level: Level, ...modules: string[]): Logger;
187
194
  Module(key: string): Logger;
@@ -214,24 +221,46 @@ declare class LoggerImpl implements Logger {
214
221
  Msg(...args: string[]): AsError;
215
222
  }
216
223
 
217
- declare class LogWriter implements WritableStreamDefaultWriter<Uint8Array> {
218
- readonly _bufferArr: Uint8Array[];
219
- _resolveClosed: (value?: PromiseLike<undefined>) => void;
220
- closed: Promise<undefined>;
221
- desiredSize: number | null;
222
- ready: Promise<undefined>;
224
+ declare class Future<T> {
225
+ #private;
223
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>;
224
239
  abort(reason?: any): Promise<void>;
225
240
  close(): Promise<void>;
226
241
  releaseLock(): void;
227
242
  write(chunk?: Uint8Array): Promise<void>;
228
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
+ }
229
255
  declare class LogCollector implements WritableStream<Uint8Array> {
230
256
  readonly locked: boolean;
231
- _writer?: LogWriter;
257
+ private _writer?;
258
+ private readonly _pass?;
259
+ private readonly _bufferArr;
260
+ constructor(pass?: WritableStreamDefaultWriter$1<Uint8Array>);
232
261
  abort(reason?: Uint8Array): Promise<void>;
233
262
  close(): Promise<void>;
234
- getWriter(): WritableStreamDefaultWriter<Uint8Array>;
263
+ getWriter(): WritableStreamDefaultWriter$1<Uint8Array>;
235
264
  Logs(): any[];
236
265
  }
237
266
 
@@ -241,6 +270,7 @@ interface MockLoggerReturn {
241
270
  }
242
271
  declare function MockLogger(params?: {
243
272
  readonly sys?: SysAbstraction;
273
+ readonly pass?: WritableStreamDefaultWriter<Uint8Array>;
244
274
  moduleName?: string | string[];
245
275
  readonly disableDebug?: boolean;
246
276
  }): MockLoggerReturn;
@@ -270,14 +300,6 @@ declare class None<T> extends Option<T> {
270
300
  }
271
301
  type WithoutOption<T> = T extends Option<infer U> ? U : T;
272
302
 
273
- declare class Future<T> {
274
- #private;
275
- constructor();
276
- asPromise(): Promise<T>;
277
- resolve(value: T): void;
278
- reject(reason: unknown): void;
279
- }
280
-
281
303
  interface ResolveSeqItem<T, C> {
282
304
  readonly future: Future<T>;
283
305
  readonly fn: (c: C) => Promise<T>;
@@ -403,4 +425,4 @@ interface CryptoRuntime {
403
425
  }
404
426
  declare function toCryptoRuntime(cryptoOpts?: Partial<CryptoRuntime>): CryptoRuntime;
405
427
 
406
- 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, LogWriter$1 as LogWriter, 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 };
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,12 +299,36 @@ 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 {
305
328
  constructor() {
306
329
  this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
307
330
  this._modules = /* @__PURE__ */ new Map();
331
+ this.isStackExposed = false;
308
332
  }
309
333
  enableLevel(level, ...modules) {
310
334
  if (modules.length == 0) {
@@ -332,6 +356,9 @@ var LevelHandlerImpl = class {
332
356
  ...modules
333
357
  );
334
358
  }
359
+ setExposeStack(enable) {
360
+ this.isStackExposed = !!enable;
361
+ }
335
362
  forModules(level, fnAction, ...modules) {
336
363
  for (const m of modules.flat()) {
337
364
  if (typeof m !== "string") {
@@ -373,7 +400,7 @@ var LevelHandlerImpl = class {
373
400
  }
374
401
  };
375
402
  var levelSingleton = new LevelHandlerImpl();
376
- var LogWriter = class {
403
+ var LogWriterStream = class {
377
404
  constructor(out) {
378
405
  this._toFlush = [];
379
406
  this._flushIsRunning = false;
@@ -439,6 +466,68 @@ function toLogValue(lop) {
439
466
  }
440
467
  return lop;
441
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
+ };
442
531
  var LoggerImpl = class _LoggerImpl {
443
532
  // readonly _id: string = "logger-" + Math.random().toString(36)
444
533
  constructor(params) {
@@ -455,9 +544,20 @@ var LoggerImpl = class _LoggerImpl {
455
544
  this._logWriter = params.logWriter;
456
545
  } else {
457
546
  if (!params.out) {
458
- this._logWriter = new LogWriter(this._sys.Stdout());
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);
459
559
  } else {
460
- this._logWriter = new LogWriter(params.out);
560
+ this._logWriter = new LogWriterStream(params.out);
461
561
  }
462
562
  }
463
563
  if (!params.withAttributes) {
@@ -472,6 +572,10 @@ var LoggerImpl = class _LoggerImpl {
472
572
  this._levelHandler = levelSingleton;
473
573
  }
474
574
  }
575
+ SetExposeStack(enable) {
576
+ this._levelHandler.setExposeStack(enable);
577
+ return this;
578
+ }
475
579
  EnableLevel(level, ...modules) {
476
580
  this._levelHandler.enableLevel(level, ...modules);
477
581
  return this;
@@ -514,8 +618,12 @@ var LoggerImpl = class _LoggerImpl {
514
618
  return this;
515
619
  }
516
620
  Err(err) {
621
+ var _a;
517
622
  if (err instanceof Error) {
518
623
  this._attributes["error"] = logValue(err.message);
624
+ if (this._levelHandler.isStackExposed) {
625
+ this._attributes["stack"] = logValue((_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()));
626
+ }
519
627
  } else {
520
628
  this._attributes["error"] = logValue("" + err);
521
629
  }
@@ -647,6 +755,10 @@ var WithLoggerBuilder = class {
647
755
  Object.assign(this._li._withAttributes, this._li._attributes);
648
756
  return this._li;
649
757
  }
758
+ SetExposeStack(enable) {
759
+ this._li._levelHandler.setExposeStack(enable);
760
+ return this;
761
+ }
650
762
  EnableLevel(level, ...modules) {
651
763
  this._li._levelHandler.enableLevel(level, ...modules);
652
764
  return this;
@@ -742,37 +854,60 @@ var WithLoggerBuilder = class {
742
854
  };
743
855
 
744
856
  // src/test/log_collector.ts
745
- var LogWriter2 = class {
746
- constructor() {
747
- this._bufferArr = [];
857
+ var LogWriterCollector = class {
858
+ constructor(bufferArr) {
859
+ this._resolveClosed = new Future();
860
+ this.closed = this._resolveClosed.asPromise();
748
861
  this.desiredSize = null;
749
862
  this.ready = Promise.resolve(void 0);
750
- this._resolveClosed = () => {
751
- };
752
- this.closed = new Promise((resolve) => {
753
- this._resolveClosed = resolve;
754
- });
863
+ this._bufferArr = bufferArr;
755
864
  }
756
865
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
757
866
  abort(reason) {
758
867
  throw new Error("Method not implemented.");
759
868
  }
760
- close() {
761
- this._resolveClosed();
869
+ async close() {
870
+ await this.closed;
762
871
  return Promise.resolve(void 0);
763
872
  }
764
873
  releaseLock() {
765
874
  }
766
- write(chunk) {
875
+ async write(chunk) {
767
876
  if (chunk) {
768
877
  this._bufferArr.push(chunk);
769
878
  }
770
879
  return Promise.resolve(void 0);
771
880
  }
772
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
+ };
773
906
  var LogCollector = class {
774
- constructor() {
907
+ constructor(pass) {
775
908
  this.locked = false;
909
+ this._bufferArr = [];
910
+ this._pass = pass;
776
911
  }
777
912
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
778
913
  abort(reason) {
@@ -788,7 +923,11 @@ var LogCollector = class {
788
923
  }
789
924
  getWriter() {
790
925
  if (!this._writer) {
791
- this._writer = new LogWriter2();
926
+ const dests = [new LogWriterCollector(this._bufferArr)];
927
+ if (this._pass) {
928
+ dests.push(this._pass);
929
+ }
930
+ this._writer = new FanoutWriter(dests);
792
931
  }
793
932
  return this._writer;
794
933
  }
@@ -803,7 +942,7 @@ var LogCollector = class {
803
942
  for (const x of res) {
804
943
  yield* __yieldStar(x);
805
944
  }
806
- }(this._writer._bufferArr)
945
+ }(this._bufferArr)
807
946
  )
808
947
  );
809
948
  const splitStr = jsonNlStr.split("\n");
@@ -815,7 +954,7 @@ var LogCollector = class {
815
954
 
816
955
  // src/test/mock_logger.ts
817
956
  function MockLogger(params) {
818
- const lc = new LogCollector();
957
+ const lc = new LogCollector(params == null ? void 0 : params.pass);
819
958
  let modNames = ["MockLogger"];
820
959
  if (typeof (params == null ? void 0 : params.moduleName) === "string") {
821
960
  modNames = [params == null ? void 0 : params.moduleName];
@@ -958,29 +1097,6 @@ var None = class extends Option {
958
1097
  }
959
1098
  };
960
1099
 
961
- // src/runtime.ts
962
- function isSet(value, ref = globalThis) {
963
- const [head, ...tail] = value.split(".");
964
- if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
965
- if (tail.length <= 1) {
966
- return true;
967
- }
968
- return isSet(tail.join("."), ref[head]);
969
- }
970
- return false;
971
- }
972
- function runtimeFn() {
973
- const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
974
- const isNodeIsh = isSet("process.versions.node") && !isReactNative;
975
- const isDeno = isSet("Deno") && !isReactNative;
976
- return {
977
- isNodeIsh,
978
- isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
979
- isDeno,
980
- isReactNative
981
- };
982
- }
983
-
984
1100
  // src/crypto.ts
985
1101
  function randomBytes(size) {
986
1102
  const bytes = new Uint8Array(size);
@@ -1006,6 +1122,7 @@ export {
1006
1122
  BrowserEnvActions,
1007
1123
  BuildURI,
1008
1124
  EnvImpl,
1125
+ FanoutWriter,
1009
1126
  Future,
1010
1127
  IDMode,
1011
1128
  IsLogger,
@@ -1016,7 +1133,8 @@ export {
1016
1133
  LevelHandlerImpl,
1017
1134
  LogCollector,
1018
1135
  LogValue,
1019
- LogWriter,
1136
+ LogWriterCollector,
1137
+ LogWriterStream,
1020
1138
  LoggerImpl,
1021
1139
  MockLogger,
1022
1140
  None,