@adviser/cement 0.2.29 → 0.2.30

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -529,4 +529,6 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
529
529
 
530
530
  declare const VERSION: string;
531
531
 
532
- 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 CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, isURL, logValue, protocols, removeSelfRef, runtimeFn, toCryptoRuntime };
532
+ declare function wrapRefcounted<T, M extends string>(t: T, method: M): T;
533
+
534
+ 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 CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, isURL, logValue, protocols, removeSelfRef, runtimeFn, toCryptoRuntime, wrapRefcounted };
package/index.d.ts CHANGED
@@ -529,4 +529,6 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
529
529
 
530
530
  declare const VERSION: string;
531
531
 
532
- 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 CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, isURL, logValue, protocols, removeSelfRef, runtimeFn, toCryptoRuntime };
532
+ declare function wrapRefcounted<T, M extends string>(t: T, method: M): T;
533
+
534
+ 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 CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, isURL, logValue, protocols, removeSelfRef, runtimeFn, toCryptoRuntime, wrapRefcounted };
package/index.js CHANGED
@@ -1468,6 +1468,26 @@ function toCryptoRuntime(cryptoOpts = {}) {
1468
1468
  var VERSION = Object.keys({
1469
1469
  __packageVersion__: "xxxx"
1470
1470
  })[0];
1471
+
1472
+ // src/refcounted.ts
1473
+ function wrapRefcounted(t, method) {
1474
+ const my = t;
1475
+ my.__refcounted = (my.__refcounted || 0) + 1;
1476
+ if (my.__refcounted === 1) {
1477
+ my.__unrefcounted = my[method];
1478
+ const mRec = my;
1479
+ mRec[method] = function() {
1480
+ this.__refcounted--;
1481
+ if (this.__refcounted === 0) {
1482
+ this.__unrefcounted();
1483
+ }
1484
+ if (this.__refcounted < 0) {
1485
+ throw new Error("already closed");
1486
+ }
1487
+ };
1488
+ }
1489
+ return t;
1490
+ }
1471
1491
  export {
1472
1492
  BaseSysAbstraction,
1473
1493
  BrowserEnvActions,
@@ -1528,6 +1548,7 @@ export {
1528
1548
  removeSelfRef,
1529
1549
  runtimeFn,
1530
1550
  toCryptoRuntime,
1531
- utils_exports as utils
1551
+ utils_exports as utils,
1552
+ wrapRefcounted
1532
1553
  };
1533
1554
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/logger-impl.ts","../../src/bin2text.ts","../../src/logger.ts","../../src/result.ts","../../src/uri.ts","../../src/runtime.ts","../../src/log-writer-impl.ts","../../src/log-level-impl.ts","../../src/test/log-write-stream.ts","../../src/test/mock-logger.ts","../../src/option.ts","../../src/tracer.ts","../../src/crypto.ts","../../src/version.ts"],"sourcesContent":["// import { v4 } from \"uuid\";\nimport YAML from \"yaml\";\nimport {\n AsError,\n FnSerialized,\n LogSerializable,\n Level,\n Logger,\n logValue,\n Serialized,\n WithLogger,\n removeSelfRef,\n Sized,\n Lengthed,\n LogValue,\n asyncLogValue,\n LevelHandler,\n LogFormatter,\n LogValueArg,\n} from \"./logger.js\";\nimport { WebSysAbstraction } from \"./web/web-sys-abstraction.js\";\nimport { SysAbstraction } from \"./sys-abstraction.js\";\nimport { Result } from \"./result.js\";\nimport { CoerceURI, URI } from \"./uri.js\";\nimport { runtimeFn } from \"./runtime.js\";\nimport { ConsoleWriterStream } from \"./utils/console-write-stream.js\";\nimport { LogWriterStream } from \"./log-writer-impl.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"./txt-en-decoder.js\";\nimport { LevelHandlerSingleton } from \"./log-level-impl.js\";\n\nfunction getLen(value: unknown): LogValue {\n if (Array.isArray(value)) {\n return logValue(() => value.length);\n } else if (typeof value === \"string\") {\n return logValue(() => value.length);\n } else if (typeof value === \"object\" && value !== null) {\n if (typeof (value as Sized).size === \"number\") {\n return logValue(() => (value as Sized).size);\n } else if (typeof (value as Lengthed).length === \"number\") {\n return logValue(() => (value as Lengthed).length);\n }\n return logValue(() => Object.keys(value).length);\n }\n return logValue(() => -1);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction hash(value: unknown): string {\n // const hasher = createHash(\"sha256\");\n // hasher.update(JSON.stringify(value, removeSelfRef()));\n // return hasher.digest(\"hex\");\n return \"not implemented\";\n}\n\nfunction toLogValue(lop: LogValue | Promise<LogValue>): LogValue | undefined {\n if (lop && typeof (lop as Promise<LogValue>).then === \"function\") {\n throw new Error(\"async logValue Not implemented\");\n }\n return lop as LogValue;\n}\n\nexport class JSONFormatter implements LogFormatter {\n private readonly _txtEnDe: TxtEnDecoder;\n private readonly _space?: number;\n constructor(txtEnde: TxtEnDecoder, space?: number) {\n this._txtEnDe = txtEnde;\n this._space = space;\n }\n format(attr: LogSerializable): Uint8Array {\n return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + \"\\n\");\n }\n}\n\nexport class YAMLFormatter implements LogFormatter {\n private readonly _txtEnDe: TxtEnDecoder;\n private readonly _space?: number;\n constructor(txtEnde: TxtEnDecoder, space?: number) {\n this._txtEnDe = txtEnde;\n this._space = space;\n }\n format(attr: LogSerializable): Uint8Array {\n return this._txtEnDe.encode(\"---\\n\" + YAML.stringify(attr, removeSelfRef(), this._space) + \"\\n\");\n }\n}\n\nexport interface LoggerImplParams {\n readonly out?: WritableStream<Uint8Array>;\n readonly logWriter?: LogWriterStream;\n readonly sys?: SysAbstraction;\n readonly withAttributes?: LogSerializable;\n readonly levelHandler?: LevelHandler;\n readonly txtEnDe?: TxtEnDecoder;\n readonly formatter?: LogFormatter;\n}\n\nexport class LoggerImpl implements Logger {\n readonly _sys: SysAbstraction;\n readonly _attributes: LogSerializable = {};\n readonly _withAttributes: LogSerializable;\n readonly _logWriter: LogWriterStream;\n readonly _levelHandler: LevelHandler;\n readonly _txtEnDe: TxtEnDecoder;\n _formatter: LogFormatter;\n // readonly _id: string = \"logger-\" + Math.random().toString(36)\n\n constructor(params?: LoggerImplParams) {\n if (!params) {\n params = {};\n }\n if (!params.sys) {\n this._sys = WebSysAbstraction();\n } else {\n this._sys = params.sys;\n }\n if (!params.txtEnDe) {\n this._txtEnDe = Utf8EnDecoderSingleton();\n } else {\n this._txtEnDe = params.txtEnDe;\n }\n if (!params.formatter) {\n this._formatter = new JSONFormatter(this._txtEnDe);\n } else {\n this._formatter = params.formatter;\n }\n\n if (params.logWriter) {\n this._logWriter = params.logWriter;\n } else {\n if (!params.out) {\n const rt = runtimeFn();\n let stream: WritableStream<Uint8Array>;\n if (rt.isBrowser) {\n stream = new ConsoleWriterStream();\n } else {\n if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {\n stream = this._sys.Stdout();\n } else {\n throw new Error(\"No output defined for runtime\");\n }\n }\n this._logWriter = new LogWriterStream(stream);\n } else {\n this._logWriter = new LogWriterStream(params.out);\n }\n }\n if (!params.withAttributes) {\n this._withAttributes = {};\n } else {\n this._withAttributes = { ...params.withAttributes };\n }\n this._attributes = { ...this._withAttributes };\n if (params.levelHandler) {\n this._levelHandler = params.levelHandler;\n } else {\n this._levelHandler = LevelHandlerSingleton();\n }\n // console.log(\"LoggerImpl\", this._id, this._attributes, this._withAttributes)\n }\n\n TxtEnDe(): TxtEnDecoder {\n return this._txtEnDe;\n }\n\n Attributes(): Record<string, unknown> {\n return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));\n // return Array.from(Object.entries(this._attributes)).reduce(\n // (acc, [key, value]) => {\n // if (value instanceof LogValue) {\n // acc[key] = value.value();\n // }\n // return acc;\n // },\n // {} as Record<string, unknown>,\n // );\n }\n\n SetExposeStack(enable?: boolean): Logger {\n this._levelHandler.setExposeStack(enable);\n return this;\n }\n\n EnableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.disableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): Logger {\n this._attributes[\"module\"] = logValue(key);\n this._withAttributes[\"module\"] = logValue(key);\n return this;\n }\n // if the string is \"*\" it will enable for all modules\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\n return this;\n }\n\n SetFormatter(formatter: LogFormatter): Logger {\n this._formatter = formatter;\n return this;\n }\n\n Timestamp(): Logger {\n this._attributes[\"ts\"] = logValue(() => this._sys.Time().Now().toISOString());\n return this;\n }\n Warn(): Logger {\n this._attributes[\"level\"] = logValue(Level.WARN);\n return this;\n }\n Log(): Logger {\n return this;\n }\n Debug(): Logger {\n this._attributes[\"level\"] = logValue(Level.DEBUG);\n return this;\n }\n Error(): Logger {\n this._attributes[\"level\"] = logValue(Level.ERROR);\n return this;\n }\n Info(): Logger {\n this._attributes[\"level\"] = logValue(Level.INFO);\n return this;\n }\n Err(err: unknown | Result<unknown> | Error): Logger {\n if (Result.Is(err)) {\n if (err.isOk()) {\n this.Result(\"noerror\", err);\n } else {\n this.Result(\"error\", err);\n }\n } else if (err instanceof Error) {\n this._attributes[\"error\"] = logValue(err.message);\n if (this._levelHandler.isStackExposed) {\n this._attributes[\"stack\"] = logValue(err.stack?.split(\"\\n\").map((s) => s.trim()));\n }\n } else {\n this._attributes[\"error\"] = logValue(\"\" + err);\n }\n return this;\n }\n WithLevel(l: Level): Logger {\n this._attributes[\"level\"] = logValue(l);\n return this;\n }\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): Logger {\n if (typeof action === \"function\") {\n this._attributes[key] = logValue(action as FnSerialized);\n } else if (typeof action.toString === \"function\") {\n this._attributes[key] = logValue(() => action.toString());\n } else {\n this._attributes[key] = logValue(\"INVALID REF\");\n }\n return this;\n }\n Bool(key: string, value: unknown): Logger {\n this._attributes[key] = logValue(!!value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): Logger {\n if (res.isOk()) {\n this._attributes[key] = logValue(res.Ok() as Serialized);\n } else {\n this.Err(res.Err());\n }\n return this;\n }\n\n Len(value: unknown, key = \"len\"): Logger {\n this._attributes[key] = getLen(value);\n return this;\n }\n\n Hash(value: unknown, key = \"hash\"): Logger {\n this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);\n return this;\n }\n\n Url(url: CoerceURI, key = \"url\"): Logger {\n this.Ref(key, () => URI.from(url).toString());\n return this;\n }\n\n Str(key: string, value?: string): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n\n Any(key: string, value?: string | number | boolean | LogSerializable): Logger {\n this._attributes[key] = logValue(value as LogValueArg);\n return this;\n }\n Dur(key: string, nsec: number): Logger {\n this._attributes[key] = logValue(`${nsec}ms`);\n // new Intl.DurationFormat(\"en\", { style: \"narrow\" }).format(nsec);\n return this;\n }\n Uint64(key: string, value: number): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Int(key: string, value: number): Logger {\n return this.Uint64(key, value);\n }\n\n async Flush(): Promise<void> {\n return new Promise((resolve) => {\n this._logWriter._flush(undefined, resolve);\n });\n }\n\n With(): WithLogger {\n // console.log(\"WithLoggerBuilder.With\", this._id, this._attributes, this._withAttributes);\n return new WithLoggerBuilder(\n new LoggerImpl({\n logWriter: this._logWriter,\n sys: this._sys,\n levelHandler: this._levelHandler,\n formatter: this._formatter,\n withAttributes: {\n module: this._attributes[\"module\"],\n ...this._withAttributes,\n },\n }),\n );\n }\n\n _resetAttributes(fn: () => () => Uint8Array): () => Uint8Array {\n const ret = fn();\n Object.keys(this._attributes).forEach((key) => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n });\n Object.assign(this._attributes, this._withAttributes);\n return ret;\n }\n\n Msg(...args: string[]): AsError {\n const fnError = this._resetAttributes(() => {\n const doWrite = this._levelHandler.isEnabled(\n toLogValue(this._attributes[\"level\"])?.value(),\n toLogValue(this._attributes[\"module\"])?.value(),\n );\n this._attributes[\"msg\"] = logValue(args.join(\" \"));\n const msg = this._attributes[\"msg\"].value();\n if (typeof msg === \"string\" && !msg.trim().length) {\n delete this._attributes[\"msg\"];\n }\n let fnRet = (): Uint8Array => this._formatter.format({ ...this._attributes });\n if (doWrite) {\n const encoded = fnRet();\n this._logWriter.write(encoded);\n fnRet = (): Uint8Array => encoded;\n }\n return fnRet;\n });\n return {\n AsError: () => new Error(this._txtEnDe.decode(fnError())),\n };\n }\n}\n\nclass WithLoggerBuilder implements WithLogger {\n readonly _li: LoggerImpl;\n constructor(li: LoggerImpl) {\n this._li = li;\n }\n\n TxtEnDe(): TxtEnDecoder {\n return this._li.TxtEnDe();\n }\n\n Logger(): Logger {\n Object.assign(this._li._withAttributes, this._li._attributes);\n return this._li;\n }\n\n Attributes(): Record<string, unknown> {\n return { ...this._li._attributes };\n }\n\n SetExposeStack(enable?: boolean): WithLogger {\n this._li._levelHandler.setExposeStack(enable);\n return this;\n }\n\n SetFormatter(fmt: LogFormatter): WithLogger {\n this._li.SetFormatter(fmt);\n return this;\n }\n\n EnableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): WithLogger {\n this._li.Module(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): WithLogger {\n this._li.SetDebug(...modules);\n return this;\n }\n\n Str(key: string, value?: string): WithLogger {\n this._li.Str(key, value);\n return this;\n }\n\n Len(value: unknown, key?: string): WithLogger {\n this._li.Len(value, key);\n return this;\n }\n\n Hash(value: unknown, key?: string): WithLogger {\n this._li.Hash(value, key);\n return this;\n }\n\n Ref(key: string, action: Serialized | FnSerialized): WithLogger {\n this._li.Ref(key, action);\n return this;\n }\n Bool(key: string, value: unknown): WithLogger {\n this._li.Bool(key, value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): WithLogger {\n this._li.Result(key, res);\n return this;\n }\n Url(url: CoerceURI, key?: string): WithLogger {\n this._li.Url(url, key);\n return this;\n }\n Int(key: string, value: number): WithLogger {\n this._li.Int(key, value);\n return this;\n }\n\n Log(): WithLogger {\n this._li.Log();\n return this;\n }\n\n WithLevel(level: Level): WithLogger {\n this._li.WithLevel(level);\n return this;\n }\n\n Error(): WithLogger {\n this._li.Error();\n return this;\n }\n Warn(): WithLogger {\n this._li.Error();\n return this;\n }\n Debug(): WithLogger {\n this._li.Debug();\n return this;\n }\n Err(err: unknown): WithLogger {\n this._li.Err(err);\n return this;\n }\n Info(): WithLogger {\n this._li.Info();\n return this;\n }\n Timestamp(): WithLogger {\n this._li.Timestamp();\n return this;\n }\n Any(key: string, value: LogSerializable): WithLogger {\n this._li.Any(key, value);\n return this;\n }\n Dur(key: string, nsec: number): WithLogger {\n this._li.Dur(key, nsec);\n return this;\n }\n Uint64(key: string, value: number): WithLogger {\n this._li.Uint64(key, value);\n return this;\n }\n}\n","export function bin2text(hex: ArrayBufferView, lineFn: (line: string) => void, size = 0): void {\n const arr = new Uint8Array(hex.buffer, hex.byteOffset, hex.byteLength);\n let cutted = \" \";\n if (size == 0) {\n size = arr.length;\n }\n size = Math.min(size, arr.length);\n const cols = 16;\n for (let line = 0; line < size; line += cols) {\n if (line + cols <= size || arr.length == size) {\n // normal line\n } else {\n line = arr.length - (arr.length % cols);\n size = arr.length;\n cutted = \">>\";\n }\n const l: string[] = [line.toString(16).padStart(4, \"0\"), cutted];\n for (let col = 0; col < cols; col++) {\n if (line + col < size) {\n l.push(arr[line + col].toString(16).padStart(2, \"0\"));\n } else {\n l.push(\" \");\n }\n // l.push((col > 0 && col % 4 === 3) ? \" \" : \" \");\n l.push(\" \");\n }\n for (let col = 0; col < cols; col++) {\n if (line + col < size) {\n const ch = arr[line + col];\n l.push(ch >= 32 && ch < 127 ? String.fromCharCode(ch) : \".\");\n }\n }\n lineFn(l.join(\"\"));\n }\n}\n\nexport function bin2string(hex: ArrayBufferView, size = 0): string {\n const collector: string[] = [];\n bin2text(\n hex,\n (line) => {\n collector.push(line);\n },\n size,\n );\n return collector.join(\"\\n\");\n}\n","import { bin2string } from \"./bin2text.js\";\nimport { Result } from \"./result.js\";\nimport { TxtEnDecoder } from \"./txt-en-decoder.js\";\nimport { CoerceURI } from \"./uri.js\";\n\nexport enum Level {\n WARN = \"warn\",\n DEBUG = \"debug\",\n INFO = \"info\",\n ERROR = \"error\",\n}\n\nexport type Serialized = string | number | boolean;\nexport type FnSerialized = () => Serialized | Serialized[];\n\nexport class LogValue {\n constructor(readonly fn: FnSerialized) {}\n value(): Serialized | Serialized[] {\n return this.fn();\n }\n toJSON(): Serialized | Serialized[] {\n return this.value();\n }\n}\n\nexport type LogSerializable = Record<string, LogValue | Promise<LogValue>>;\n\nexport function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown {\n const cache = new Set();\n return function (key: unknown, value: unknown) {\n if (typeof value === \"object\" && value !== null) {\n // Duplicate reference found, discard key\n if (cache.has(value)) return \"...\";\n cache.add(value);\n }\n return lineEnd ? value + lineEnd : value;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue> {\n // return Promise.resolve(logValue(val));\n throw new Error(\"Not implemented\");\n}\n\nexport type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;\n\nexport function logValue(val: LogValueArg, state: Set<unknown> = new Set<unknown>([Math.random()])): LogValue {\n switch (typeof val) {\n case \"function\":\n return new LogValue(val);\n case \"string\": {\n try {\n const ret = JSON.parse(val);\n if (typeof ret === \"object\" && ret !== null) {\n return logValue(ret, state);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n if (val.match(/[\\n\\r]/)) {\n const lines = val.trimEnd().split(/[\\n\\r]/);\n return new LogValue(() => lines);\n }\n }\n return new LogValue(() => val.toString());\n }\n case \"number\":\n return new LogValue(() => val);\n case \"boolean\":\n return new LogValue(() => val);\n case \"object\": {\n if (ArrayBuffer.isView(val)) {\n return logValue(bin2string(val, 512));\n }\n if (Array.isArray(val)) {\n return new LogValue(() => val.map((v) => logValue(v).value() as Serialized));\n }\n if (val === null) {\n return new LogValue(() => \"null\");\n }\n // Duplicate reference found, discard key\n if (state.has(val)) {\n return new LogValue(() => \"...\");\n }\n state.add(val);\n\n const res: Record<string, LogValue> = {};\n const typedVal = val as unknown as Record<string, LogValueArg>;\n for (const key in typedVal) {\n const element = typedVal[key];\n if (element instanceof LogValue) {\n res[key] = element;\n } else {\n res[key] = logValue(element, state);\n }\n }\n // ugly as hell cast but how declare a self-referencing type?\n return new LogValue(() => res as unknown as Serialized);\n }\n default:\n if (!val) {\n return new LogValue(() => \"--Falsy--\");\n }\n throw new Error(`Invalid type:${typeof val}`);\n }\n}\n\nexport interface Sized {\n size: number;\n}\nexport interface Lengthed {\n length: number;\n}\nexport type SizeOrLength = Sized | Lengthed;\n\nexport interface LogFormatter {\n format(attr: LogSerializable): Uint8Array;\n}\n\nexport interface LevelHandler {\n enableLevel(level: Level, ...modules: string[]): void;\n disableLevel(level: Level, ...modules: string[]): void;\n setExposeStack(enable?: boolean): void;\n isStackExposed: boolean;\n setDebug(...modules: (string | string[])[]): void;\n isEnabled(ilevel: unknown, module: unknown): boolean;\n}\n\nexport interface LoggerInterface<R> {\n TxtEnDe(): TxtEnDecoder;\n Module(key: string): R;\n // if modules is empty, set for all Levels\n EnableLevel(level: Level, ...modules: string[]): R;\n DisableLevel(level: Level, ...modules: string[]): R;\n\n Attributes(): Record<string, unknown>;\n\n SetDebug(...modules: (string | string[])[]): R;\n SetExposeStack(enable?: boolean): R;\n SetFormatter(fmt: LogFormatter): R;\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): R;\n Result<T>(key: string, res: Result<T>): R;\n // default key url\n Url(url: CoerceURI, key?: string): R;\n // len\n Len(value: unknown, key?: string): R;\n\n Hash(value: unknown, key?: string): R;\n\n Str(key: string, value?: string): R;\n Error(): R;\n Warn(): R;\n Debug(): R;\n Log(): R;\n WithLevel(level: Level): R;\n\n Err(err: unknown | Result<unknown> | Error): R; // could be Error, or something which coerces to string\n Info(): R;\n Timestamp(): R;\n Any(key: string, value: unknown): R;\n Dur(key: string, nsec: number): R;\n Uint64(key: string, value: number): R;\n Int(key: string, value: number): R;\n Bool(key: string, value: unknown): R;\n}\n\nexport function IsLogger(obj: unknown): obj is Logger {\n return (\n typeof obj === \"object\" &&\n [\n \"Module\",\n \"EnableLevel\",\n \"DisableLevel\",\n \"SetDebug\",\n \"Str\",\n \"Error\",\n \"Warn\",\n \"Debug\",\n \"Log\",\n \"WithLevel\",\n \"Err\",\n \"Info\",\n \"Timestamp\",\n \"Any\",\n \"Dur\",\n \"Uint64\",\n ]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map((fn) => typeof (obj as any)[fn] === \"function\")\n .reduce((a, b) => a && b, true)\n );\n}\n\nexport interface WithLogger extends LoggerInterface<WithLogger> {\n Logger(): Logger;\n}\n\nexport interface AsError {\n AsError(): Error;\n}\n\nexport interface Logger extends LoggerInterface<Logger> {\n With(): WithLogger;\n\n Msg(...args: string[]): AsError;\n Flush(): Promise<void>;\n}\n","export abstract class Result<T, E = Error> {\n static Ok<T = void>(t: T): Result<T, Error> {\n return new ResultOK(t);\n }\n static Err<T, E extends Error = Error>(t: E | string): Result<T, E> {\n if (typeof t === \"string\") {\n return new ResultError(new Error(t) as E);\n }\n return new ResultError(t);\n }\n static Is<T>(t: unknown): t is Result<T> {\n if (!t) {\n return false;\n }\n if (t instanceof Result) {\n return true;\n }\n const rt = t as Result<T>;\n if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === \"function\")) {\n return true;\n }\n return false;\n }\n\n isOk(): boolean {\n return this.is_ok();\n }\n isErr(): boolean {\n return this.is_err();\n }\n\n Ok(): T {\n return this.unwrap();\n }\n Err(): E {\n return this.unwrap_err();\n }\n\n abstract is_ok(): boolean;\n abstract is_err(): boolean;\n abstract unwrap(): T;\n abstract unwrap_err(): E;\n}\n\nexport class ResultOK<T> extends Result<T, Error> {\n private _t: T;\n constructor(t: T) {\n super();\n this._t = t;\n }\n is_ok(): boolean {\n return true;\n }\n is_err(): boolean {\n return false;\n }\n unwrap_err(): Error {\n throw new Error(\"Result is Ok\");\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class ResultError<T extends Error> extends Result<never, T> {\n private _error: T;\n constructor(t: T) {\n super();\n this._error = t;\n }\n is_ok(): boolean {\n return false;\n }\n is_err(): boolean {\n return true;\n }\n unwrap(): never {\n throw new Error(`Result is Err: ${this._error}`);\n }\n unwrap_err(): T {\n return this._error;\n }\n}\n\nexport type WithoutResult<T> = T extends Result<infer U> ? U : T;\n\n// type WithoutPromise<T> = T extends Promise<infer U> ? U : T;\ntype WithResult<T> = T extends Promise<infer U> ? Promise<Result<U>> : Result<T>;\n\nexport function exception2Result<FN extends () => Promise<T> | T, T>(fn: FN): WithResult<ReturnType<FN>> {\n try {\n const res = fn();\n if (res instanceof Promise) {\n return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e)) as WithResult<ReturnType<FN>>;\n }\n return Result.Ok(res) as WithResult<ReturnType<FN>>;\n } catch (e) {\n return Result.Err(e as Error) as WithResult<ReturnType<FN>>;\n }\n}\n\n/*\n\ntype FinalizedResult<T> = {\n result: T;\n scopeResult?: Result<void>;\n finally: () => Promise<void>;\n}\n\ntype exection2ResultParam<T> = {\n init: () => Promise<T>;\n inScope?: (t: T) => Promise<void>;\n cleanup: (t: T) => Promise<void>;\n\n}\n\nasync function expection2Result<T>({fn, inScope, cleanup}: exection2ResultParam<T>): Promise<Result<FinalizedResult<T>>> {\n try {\n const res = await fn();\n if (inScope) {\n try {\n await inScope?.(res)\n } catch (err) {\n return Result.Err(err as Error)\n }\n await cleanup(res)\n return Result.Ok({\n result: res,\n finally: async () => { }\n })\n }\n return Result.Ok({\n result: res ,\n finally: async () => {\n return cleanup(res)\n }\n })\n } catch (err) {\n return Result.Err(err as Error)\n }\n}\n*/\n\n// await expection2Result({\n// init: openDB,\n// inScope: (res) => {\n// res.query()\n// },\n// cleanup: async (y) => {\n// await y.close()\n// }\n// })\n// async function openDB() {\n// try {\n// const opendb = await openDB()\n// return Result.Ok({\n// openDB,\n// finally: async () => {\n// await opendb.close()\n// }})\n// } catch (err) {\n// return Result.Err(err)\n// }\n// }\n// }\n","import { exception2Result, Result } from \"./result.js\";\n\ntype NullOrUndef = null | undefined;\n\nfunction falsy2undef<T>(value: T | NullOrUndef): T | undefined {\n return value === undefined || value === null ? undefined : value;\n}\n\nfunction ensureURLWithDefaultProto(url: string | URL, defaultProtocol: string): MutableURL {\n if (!url) {\n return new MutableURL(`${defaultProtocol}//`);\n }\n if (typeof url === \"string\") {\n try {\n return new MutableURL(url);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n return new MutableURL(`${defaultProtocol}//${url}`);\n }\n } else {\n return new MutableURL(url.toString());\n }\n}\n\nexport function isURL(value: unknown): value is URL {\n return (\n value instanceof URL ||\n (!!value &&\n typeof (value as URL).searchParams === \"object\" &&\n typeof (value as URL).searchParams.sort === \"function\" &&\n typeof (value as URL).hash === \"string\")\n );\n}\n\n// due to that the System URL class is has a strange behavior\n// on different platforms, we need to implement our own URL class\nexport class MutableURL extends URL {\n private readonly _sysURL: URL;\n // private readonly _urlStr: string;\n\n private _protocol: string;\n private _pathname: string;\n private _hasHostpart: boolean;\n\n readonly hash: string;\n\n constructor(urlStr: string) {\n super(\"defect://does.not.exist\");\n const partedURL = urlStr.split(\":\");\n this._hasHostpart = protocols.has(partedURL[0]);\n let hostPartUrl = [\"http\", ...partedURL.slice(1)].join(\":\");\n if (!this._hasHostpart) {\n const pathname = hostPartUrl.replace(/http:\\/\\/[/]*/, \"\").replace(/[#?].*$/, \"\");\n hostPartUrl = hostPartUrl.replace(/http:\\/\\//, `http://localhost/${pathname}`);\n }\n try {\n this._sysURL = new URL(hostPartUrl);\n } catch (ie) {\n const e = ie as Error;\n e.message = `${e.message} for URL: ${urlStr}`;\n throw e;\n }\n this._protocol = `${partedURL[0]}:`; // this._sysURL.protocol.replace(new RegExp(\"^cement-\"), \"\");\n if (this._hasHostpart) {\n this._pathname = this._sysURL.pathname;\n } else {\n this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), \"\").replace(/[#?].*$/, \"\");\n }\n this.hash = this._sysURL.hash;\n }\n\n clone(): MutableURL {\n return new MutableURL(this.toString());\n }\n\n get host(): string {\n if (!this._hasHostpart) {\n throw new Error(\n `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(protocols.keys()))}`,\n );\n }\n return this._sysURL.host;\n }\n\n get port(): string {\n if (!this._hasHostpart) {\n throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n return this._sysURL.port;\n }\n\n set port(p: string) {\n if (!this._hasHostpart) {\n throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n this._sysURL.port = p;\n }\n\n get hostname(): string {\n if (!this._hasHostpart) {\n throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n return this._sysURL.hostname;\n }\n\n set hostname(h: string) {\n if (!this._hasHostpart) {\n throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n this._sysURL.hostname = h;\n }\n\n set pathname(p: string) {\n this._pathname = p;\n }\n\n get pathname(): string {\n return this._pathname;\n }\n\n get protocol(): string {\n return this._protocol;\n }\n\n set protocol(p: string) {\n if (!p.endsWith(\":\")) {\n p = `${p}:`;\n }\n this._protocol = p;\n }\n\n get searchParams(): URLSearchParams {\n return this._sysURL.searchParams;\n }\n\n toString(): string {\n let search = \"\";\n if (this._sysURL.searchParams.size) {\n for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {\n search += `${!search.length ? \"?\" : \"&\"}${key}=${encodeURIComponent(value)}`;\n }\n }\n let hostpart = \"\";\n if (this._hasHostpart) {\n hostpart = this._sysURL.hostname;\n if (this._sysURL.port) {\n hostpart += `:${this._sysURL.port}`;\n }\n if (!this._pathname.startsWith(\"/\")) {\n hostpart += \"/\";\n }\n }\n return `${this._protocol}//${hostpart}${this._pathname}${search}`;\n }\n}\n\nfunction from<T>(fac: (url: MutableURL) => T, strURLUri: CoerceURI | undefined, defaultProtocol: string): T {\n switch (typeof falsy2undef(strURLUri)) {\n case \"undefined\":\n return fac(new MutableURL(`${defaultProtocol}///`));\n case \"string\":\n return fac(ensureURLWithDefaultProto(strURLUri as string, defaultProtocol));\n case \"object\":\n if (BuildURI.is(strURLUri)) {\n return fac(new MutableURL(strURLUri._url.toString()));\n } else if (URI.is(strURLUri)) {\n return fac(new MutableURL(strURLUri._url.toString()));\n } else if (isURL(strURLUri)) {\n return fac(new MutableURL(strURLUri.toString()));\n }\n throw new Error(`unknown object type: ${strURLUri}`);\n default:\n throw new Error(`Invalid argument: ${typeof strURLUri}`);\n }\n}\n\nexport class BuildURI {\n _url: MutableURL; // pathname needs this\n private constructor(url: MutableURL) {\n this._url = url;\n }\n\n static is(value: unknown): value is BuildURI {\n return (\n value instanceof BuildURI ||\n (!!value && typeof (value as BuildURI).delParam === \"function\" && typeof (value as BuildURI).setParam === \"function\")\n );\n }\n static from(strURLUri?: CoerceURI, defaultProtocol = \"file:\"): BuildURI {\n return from((url) => new BuildURI(url), strURLUri, defaultProtocol);\n }\n\n port(p: string): BuildURI {\n this._url.port = p;\n return this;\n }\n\n hostname(h: string): BuildURI {\n this._url.hostname = h;\n return this;\n }\n\n // password(p: string) {\n // this._url.password = p;\n // return this;\n // }\n\n // port(p: string) {\n // this._url.port = p;\n // return this;\n // }\n\n // username(u: string) {\n // this._url.username = u;\n // return this;\n // }\n\n // search(s: string) {\n // this._url.search = s;\n // return this;\n // }\n\n protocol(p: string): BuildURI {\n this._url.protocol = p;\n // if (!p.endsWith(\":\")) {\n // p = `${p}:`;\n // }\n // const mySrc = this._url.toString();\n // const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}`), `${p}`);\n // this._url = new URL(myDst);\n return this;\n }\n\n pathname(p: string): BuildURI {\n // const myp = this.URI().pathname;\n // const mySrc = this._url.toString();\n // const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}//${myp}`), `${this._url.protocol}//${p}`);\n // this._url = new URL(myDst);\n this._url.pathname = p;\n return this;\n }\n\n // hash(h: string) {\n // this._url.hash = h;\n // return this;\n // }\n\n // host(h: string) {\n // this._url.host = h;\n // return this;\n // }\n\n delParam(key: string): BuildURI {\n this._url.searchParams.delete(key);\n return this;\n }\n\n defParam(key: string, str: string): BuildURI {\n if (!this._url.searchParams.has(key)) {\n this._url.searchParams.set(key, str);\n }\n return this;\n }\n\n setParam(key: string, str: string): BuildURI {\n this._url.searchParams.set(key, str);\n return this;\n }\n\n hasParam(key: string): boolean {\n return this._url.searchParams.has(key);\n }\n\n getParam(key: string): string | undefined {\n return falsy2undef(this._url.searchParams.get(key));\n }\n\n toString(): string {\n this._url.searchParams.sort();\n return this._url.toString();\n }\n toJSON(): string {\n return this.toString();\n }\n\n URI(): URI {\n return URI.from(this._url);\n }\n}\n\nexport type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;\n\nexport const protocols: Set<string> = new Set<string>([\"http\", \"https\", \"ws\", \"wss\"]);\n\n// non mutable URL Implementation\nexport class URI {\n static protocolHasHostpart(protocol: string): () => void {\n protocol = protocol.replace(/:$/, \"\");\n protocols.add(protocol);\n return () => {\n protocols.delete(protocol);\n };\n }\n\n // if no protocol is provided, default to file:\n static merge(into: CoerceURI, from: CoerceURI, defaultProtocol = \"file:\"): URI {\n const intoUrl = BuildURI.from(into, defaultProtocol);\n const fromUrl = URI.from(from, defaultProtocol);\n\n intoUrl.protocol(fromUrl.protocol);\n const fPath = fromUrl.pathname;\n if (!(fPath.length === 0 || fPath === \"/\" || fPath === \"./\")) {\n intoUrl.pathname(fromUrl.pathname);\n }\n for (const [key, value] of fromUrl.getParams) {\n intoUrl.setParam(key, value);\n }\n return intoUrl.URI();\n }\n\n static is(value: unknown): value is URI {\n return (\n value instanceof URI ||\n (!!value &&\n typeof (value as URI).asURL === \"function\" &&\n typeof (value as URI).getParam === \"function\" &&\n typeof (value as URI).hasParam === \"function\")\n );\n }\n\n // if no protocol is provided, default to file:\n static from(strURLUri?: CoerceURI, defaultProtocol = \"file:\"): URI {\n return from((url) => new URI(url), strURLUri, defaultProtocol);\n }\n\n static fromResult(strURLUri?: CoerceURI, defaultProtocol = \"file:\"): Result<URI> {\n return exception2Result(() => from((url) => new URI(url), strURLUri, defaultProtocol)) as Result<URI>;\n }\n\n readonly _url: MutableURL;\n private constructor(url: MutableURL) {\n this._url = url.clone();\n }\n\n build(): BuildURI {\n return BuildURI.from(this._url);\n }\n\n get hostname(): string {\n return this._url.hostname;\n }\n\n // get password(): string {\n // return this._url.password;\n // }\n\n get port(): string {\n return this._url.port;\n }\n\n get host(): string {\n return this._url.host;\n }\n\n // get username(): string {\n // return this._url.username;\n // }\n\n // get search(): string {\n // return this._url.search;\n // }\n\n get protocol(): string {\n return this._url.protocol;\n }\n\n get pathname(): string {\n return this._url.pathname;\n // return this._url\n // .toString()\n // .replace(/^.*:\\/\\//, \"\")\n // .replace(/\\?.*$/, \"\");\n }\n\n // get hash(): string {\n // return this._url.hash;\n // }\n\n // get host(): string {\n // return this._url.host;\n // }\n\n get getParams(): Iterable<[string, string]> {\n return this._url.searchParams.entries();\n }\n\n hasParam(key: string): boolean {\n return this._url.searchParams.has(key);\n }\n getParam(key: string): string | undefined {\n return falsy2undef(this._url.searchParams.get(key));\n }\n\n clone(): URI {\n return new URI(this._url);\n }\n\n asURL(): URL {\n // const url = new URL(this._url.toString());\n // url.searchParams.sort();\n return this._url.clone() as unknown as URL;\n }\n\n toString(): string {\n // this._url.searchParams.sort();\n return this._url.toString();\n }\n toJSON(): string {\n return this.toString();\n }\n}\n","export interface Runtime {\n isNodeIsh: boolean;\n isBrowser: boolean;\n isDeno: boolean;\n isReactNative: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isSet(value: string, ref: any = globalThis): boolean {\n const [head, ...tail] = value.split(\".\");\n if ([\"object\", \"function\"].includes(typeof ref) && ref && [\"object\", \"function\"].includes(typeof ref[head]) && ref[head]) {\n if (tail.length <= 1) {\n return true;\n }\n return isSet(tail.join(\".\"), ref[head]);\n }\n return false;\n}\n\nexport function runtimeFn(): Runtime {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const gt: any = globalThis;\n const isReactNative =\n isSet(\"navigator.product\") && typeof gt[\"navigator\"] === \"object\" && gt[\"navigator\"][\"product\"] === \"ReactNative\";\n let isNodeIsh = false;\n if (!isSet(\"Deno\")) {\n isNodeIsh = isSet(\"process.versions.node\") && !isReactNative;\n }\n const isDeno = isSet(\"Deno\");\n return {\n isNodeIsh,\n isBrowser: !(isNodeIsh || isDeno) && !isReactNative,\n isDeno,\n isReactNative,\n };\n}\n","export class LogWriterStream {\n readonly _out: WritableStream<Uint8Array>;\n readonly _toFlush: (() => Promise<void>)[] = [];\n\n constructor(out: WritableStream<Uint8Array>) {\n this._out = out;\n }\n\n write(encoded: Uint8Array): void {\n const my = async (): Promise<void> => {\n // const val = Math.random();\n // console.log(\">>>My:\", val)\n try {\n const writer = this._out.getWriter();\n await writer.ready;\n await writer.write(encoded);\n await writer.releaseLock();\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\"Chunk error:\", err);\n }\n // console.log(\"<<<My:\", val)\n };\n this._toFlush.push(my);\n this._flush();\n }\n\n _flushIsRunning = false;\n _flushDoneFns: (() => void)[] = [];\n _flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {\n if (done) {\n this._flushDoneFns.push(done);\n }\n\n if (this._toFlush.length == 0) {\n // console.log(\"Flush is stopped\", this._toFlush.length)\n this._flushIsRunning = false;\n this._flushDoneFns.forEach((fn) => fn());\n this._flushDoneFns = [];\n return;\n }\n\n if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {\n this._flushIsRunning = true;\n // console.log(\"Flush is started\", this._toFlush.length)\n } else if (!toFlush) {\n // console.log(\"flush queue check but is running\", this._toFlush.length)\n return;\n }\n\n // console.log(\">>>Msg:\", this._toFlush.length)\n const my = this._toFlush.shift();\n my?.().finally(() => {\n // console.log(\"<<<Msg:\", this._toFlush.length)\n this._flush(this._toFlush);\n });\n }\n}\n","import { LevelHandler, Level } from \"./logger.js\";\n\nexport class LevelHandlerImpl implements LevelHandler {\n readonly _globalLevels: Set<Level> = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);\n readonly _modules: Map<string, Set<Level>> = new Map<string, Set<Level>>();\n isStackExposed = false;\n enableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.add(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, level]));\n },\n ...modules,\n );\n }\n disableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.delete(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.delete(p);\n },\n ...modules,\n );\n }\n\n setExposeStack(enable?: boolean): void {\n this.isStackExposed = !!enable;\n }\n\n forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {\n for (const m of modules.flat()) {\n if (typeof m !== \"string\") {\n continue;\n }\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length);\n for (const p of parts) {\n fnAction(p);\n }\n }\n }\n setDebug(...modules: (string | string[])[]): void {\n this.forModules(\n Level.DEBUG,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));\n },\n ...modules,\n );\n }\n isEnabled(ilevel: unknown, module: unknown): boolean {\n const level = ilevel as Level; // what if it's not a level?\n if (typeof module === \"string\") {\n const levels = this._modules.get(module);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n const wlevel = this._modules.get(\"*\");\n if (wlevel && typeof level === \"string\") {\n if (wlevel.has(level)) {\n return true;\n }\n }\n if (typeof level !== \"string\") {\n // this is a plain log\n return true;\n }\n return this._globalLevels.has(level);\n }\n}\n\nconst levelSingleton = new LevelHandlerImpl();\n\nexport function LevelHandlerSingleton(): LevelHandler {\n return levelSingleton;\n}\n","import { FanoutWriteStream } from \"../utils/fanout-write-stream.js\";\nimport { Future } from \"../future.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\n\nexport class LogWriteStream implements WritableStreamDefaultWriter<Uint8Array> {\n private readonly _bufferArr: Uint8Array[];\n\n constructor(bufferArr: Uint8Array[]) {\n this._bufferArr = bufferArr;\n }\n\n readonly _resolveClosed: Future<undefined> = new Future<undefined>();\n readonly closed: Promise<undefined> = this._resolveClosed.asPromise();\n readonly desiredSize: number | null = null;\n readonly ready: Promise<undefined> = Promise.resolve(undefined);\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n async close(): Promise<void> {\n await this.closed;\n return Promise.resolve(undefined);\n }\n releaseLock(): void {\n // do nothing\n }\n async write(chunk?: Uint8Array): Promise<void> {\n if (chunk) {\n this._bufferArr.push(chunk);\n }\n return Promise.resolve(undefined);\n }\n}\n\nexport class LogCollector implements WritableStream<Uint8Array> {\n readonly locked: boolean = false;\n private _writer?: FanoutWriteStream;\n private readonly _pass?: WritableStreamDefaultWriter<Uint8Array>;\n private readonly _bufferArr: Uint8Array[] = [];\n private readonly _txtEnDe: TxtEnDecoder;\n\n constructor(pass?: WritableStreamDefaultWriter<Uint8Array>, txtEnDe?: TxtEnDecoder) {\n this._pass = pass;\n this._txtEnDe = txtEnDe || Utf8EnDecoderSingleton();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abort(reason?: Uint8Array): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n async close(): Promise<void> {\n if (this._writer) {\n const ret = await this._writer.close();\n this._writer = undefined;\n return ret;\n }\n return Promise.resolve(undefined);\n }\n\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (!this._writer) {\n const dests: WritableStreamDefaultWriter[] = [new LogWriteStream(this._bufferArr)];\n if (this._pass) {\n dests.push(this._pass);\n }\n this._writer = new FanoutWriteStream(dests);\n }\n return this._writer;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Logs(notJsonLine = false): any[] {\n if (!this._writer) {\n return [];\n }\n const jsonNlStr = this._txtEnDe.decode(\n new Uint8Array(\n (function* (res: Uint8Array[]): Generator<number, void, undefined> {\n for (const x of res) {\n yield* x;\n }\n })(this._bufferArr),\n ),\n );\n if (!notJsonLine) {\n const splitStr = jsonNlStr.split(\"\\n\");\n const filterStr = splitStr.filter((a) => a.length);\n const mapStr = filterStr.map((a) => JSON.parse(a));\n return mapStr;\n }\n return jsonNlStr.split(\"\\n\").filter((a) => a.length);\n }\n}\n","import { LevelHandlerImpl } from \"../log-level-impl.js\";\nimport { Logger } from \"../logger.js\";\nimport { LoggerImpl } from \"../logger-impl.js\";\nimport { SysAbstraction } from \"../sys-abstraction.js\";\nimport { LogCollector } from \"./log-write-stream.js\";\n\nexport interface MockLoggerReturn {\n readonly logger: Logger;\n readonly logCollector: LogCollector;\n}\n\nexport function MockLogger(params?: {\n readonly sys?: SysAbstraction;\n readonly pass?: WritableStreamDefaultWriter<Uint8Array>;\n moduleName?: string | string[];\n readonly disableDebug?: boolean;\n}): MockLoggerReturn {\n const lc = new LogCollector(params?.pass);\n let modNames = [\"MockLogger\"];\n if (typeof params?.moduleName === \"string\") {\n modNames = [params?.moduleName];\n } else if (Array.isArray(params?.moduleName)) {\n modNames = [...params.moduleName, ...modNames];\n }\n const logger = new LoggerImpl({\n out: lc,\n sys: params?.sys,\n levelHandler: new LevelHandlerImpl(),\n })\n .With()\n .Module(modNames[0])\n .Logger();\n if (!params?.disableDebug) {\n logger.SetDebug(...modNames);\n }\n return {\n logCollector: lc,\n logger,\n };\n}\n","export abstract class Option<T> {\n static Some<T>(t: T): Option<T> {\n return new Some(t);\n }\n\n static None<T>(): Option<T> {\n return new None();\n }\n\n static Is<T>(t: unknown): t is Option<T> {\n return t instanceof Option;\n }\n\n IsNone(): boolean {\n return this.is_none();\n }\n\n IsSome(): boolean {\n return this.is_some();\n }\n Unwrap(): T {\n return this.unwrap();\n }\n\n abstract is_none(): boolean;\n abstract is_some(): boolean;\n abstract unwrap(): T;\n}\n\nexport class Some<T> extends Option<T> {\n private _t: T;\n constructor(_t: T) {\n super();\n this._t = _t;\n }\n\n is_none(): boolean {\n return false;\n }\n is_some(): boolean {\n return true;\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class None<T> extends Option<T> {\n is_none(): boolean {\n return true;\n }\n is_some(): boolean {\n return false;\n }\n unwrap(): T {\n throw new Error(\"None.unwrap\");\n }\n}\n\nexport type WithoutOption<T> = T extends Option<infer U> ? U : T;\n","import type { MarkWritable } from \"ts-essentials\";\nimport { Time } from \"./time.js\";\nimport { Logger } from \"./logger.js\";\n\nexport type TraceCtx = {\n readonly spanId: string;\n readonly time: Time;\n readonly parent: TraceNode;\n readonly metrics: Map<string, Metric<unknown>>;\n readonly logger?: Logger;\n} & Record<string, unknown>;\n\nexport type CleanCtx = {\n readonly spanId: string;\n} & Record<string, unknown>;\n\nexport type TraceCtxParam = {\n readonly spanId: string;\n} & Partial<{\n readonly time: Time;\n readonly parent: TraceNode;\n readonly logger: Logger;\n}> &\n Record<string, unknown>;\n\nexport class Metric<T> {\n value?: T;\n readonly path: string;\n\n constructor(path: string) {\n this.path = path;\n }\n\n set(value: T): void {\n this.value = value;\n }\n\n add<R extends number | ArrayLike<T>>(value: R): void {\n if (typeof value === \"number\") {\n if (this.value === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.value = 0 as any;\n }\n (this.value as number) = ((this.value as number) + value) as number;\n } else if (Array.isArray(value)) {\n if (!Array.isArray(this.value)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.value = [] as any;\n }\n (this.value as T[]).push(...value);\n } else {\n throw new Error(\"add only support number or array\");\n }\n }\n}\n\nexport type MetricMap = Map<string, Metric<unknown>>;\n\nexport class Metrics {\n readonly tracenode: TraceNode;\n private readonly map: MetricMap;\n\n readonly spanRefs: MetricMap = new Map<string, Metric<unknown>>();\n constructor(tracenode: TraceNode) {\n this.tracenode = tracenode;\n this.map = tracenode.ctx.metrics;\n }\n\n toJSON(): Record<string, unknown> {\n const obj: Record<string, unknown> = {};\n for (const [key, value] of this.map) {\n obj[key] = value.value;\n }\n return obj;\n }\n\n get<T>(ipath: string): Metric<T> {\n const path = ipath.replace(/[/]+/g, \"/\").trim();\n if (path.startsWith(\"/\")) {\n if (path.slice(1).length === 0) {\n throw new Error(`Metrics path must contain value /:${path}`);\n }\n let metric = this.map.get(path);\n if (!metric) {\n metric = new Metric<T>(path);\n this.map.set(path, metric);\n }\n this.spanRefs.set(path, metric);\n return metric as Metric<T>;\n } else if (path.includes(\"/\")) {\n throw new Error(`Metrics path must start with /:${path}`);\n }\n const rootPath = this.tracenode.getRootPath();\n return this.get(`${rootPath}/${path}`);\n }\n}\n\nexport interface Invokaction {\n readonly result: \"success\" | \"error\";\n readonly start: number;\n readonly end: number;\n readonly metrics?: Metrics;\n}\n\nexport type TraceNodeMap = Map<string, TraceNode>;\n\nexport class TraceNode {\n readonly childs: TraceNodeMap = new Map<string, TraceNode>();\n\n readonly invokations: Invokaction[] = [];\n\n readonly spanId: string;\n readonly ctx: TraceCtx;\n readonly metrics: Metrics;\n\n static root(time: Time, logger?: Logger): TraceNode {\n return new TraceNode({\n spanId: \"root\",\n time,\n logger,\n metrics: new Map(),\n parent: undefined as unknown as TraceNode,\n });\n }\n\n constructor(ctx: TraceCtx) {\n this.spanId = ctx.spanId;\n this.ctx = ctx;\n this.metrics = new Metrics(this);\n }\n\n getRootPath(rpath: string[] = []): string {\n if (!this.ctx.parent) {\n return \"/\" + rpath.reverse().join(\"/\");\n }\n return this.ctx.parent.getRootPath(rpath.concat(this.ctx.spanId));\n }\n\n invokes(): { ctx: CleanCtx; invokations: Invokaction[] } {\n const cleanCtx = { ...this.ctx } as CleanCtx;\n delete cleanCtx.parent;\n delete cleanCtx.time;\n delete cleanCtx.logger;\n delete cleanCtx.metrics;\n const spanRefs = this.metrics.toJSON.call({ map: this.metrics.spanRefs });\n const metricsRefs = Object.keys(spanRefs).length > 0 ? { metricRefs: spanRefs } : {};\n return {\n ctx: cleanCtx as CleanCtx,\n invokations: this.invokations,\n ...metricsRefs,\n };\n }\n\n ctxWith(spanId: string, logger?: Logger): TraceCtxParam {\n const ctx = {\n ...this.ctx,\n spanId,\n };\n if (logger) {\n ctx.logger = logger;\n }\n return ctx;\n }\n\n // <V extends () => Promise<T> | T, T>(id: string, fn: V): ReturnType<V>\n span<V extends (trace: TraceNode) => Promise<T> | T, T>(inSpanId: string | TraceCtxParam, fn: V): ReturnType<V> {\n let ctx: TraceCtx;\n if (typeof inSpanId === \"string\") {\n ctx = {\n ...this.ctx,\n spanId: inSpanId,\n parent: this,\n };\n } else {\n ctx = {\n ...this.ctx,\n ...inSpanId,\n parent: this,\n };\n }\n if (ctx.logger) {\n ctx = {\n ...ctx,\n ...ctx.logger.Attributes(),\n };\n }\n const spanId = ctx.spanId;\n let spanTrace = this.childs.get(spanId);\n if (!spanTrace) {\n spanTrace = new TraceNode(ctx);\n this.childs.set(spanId.toString(), spanTrace);\n }\n const invokation: MarkWritable<MarkWritable<Invokaction, \"end\">, \"result\"> = {\n start: this.ctx.time.Now().getTime(),\n end: 0,\n result: \"success\",\n };\n spanTrace.invokations.push(invokation);\n try {\n const possiblePromise = fn(spanTrace);\n if (possiblePromise instanceof Promise) {\n return possiblePromise\n .then((v) => {\n return v;\n })\n .catch((e) => {\n invokation.result = \"error\";\n throw e;\n })\n .finally(() => {\n invokation.end = this.ctx.time.Now().getTime();\n }) as ReturnType<V>;\n }\n invokation.end = this.ctx.time.Now().getTime();\n return possiblePromise as ReturnType<V>;\n } catch (e) {\n invokation.result = \"error\";\n invokation.end = this.ctx.time.Now().getTime();\n throw e;\n }\n }\n}\n","export interface CTJsonWebKey {\n alg?: string;\n crv?: string;\n d?: string;\n dp?: string;\n dq?: string;\n e?: string;\n ext?: boolean;\n k?: string;\n key_ops?: string[];\n kty?: string;\n n?: string;\n oth?: RsaOtherPrimesInfo[];\n p?: string;\n q?: string;\n qi?: string;\n use?: string;\n x?: string;\n y?: string;\n}\n\nexport type CTKeyFormat = \"jwk\" | \"pkcs8\" | \"raw\" | \"spki\";\nexport type CTKeyUsage = \"decrypt\" | \"deriveBits\" | \"deriveKey\" | \"encrypt\" | \"sign\" | \"unwrapKey\" | \"verify\" | \"wrapKey\";\n\nexport interface CTAlgorithm {\n name: string;\n}\nexport type CTAlgorithmIdentifier = CTAlgorithm | string;\n\nexport interface CTRsaHashedImportParams extends CTAlgorithm {\n hash: CTAlgorithmIdentifier;\n}\n\nexport type CTNamedCurve = string;\nexport interface CTEcKeyImportParams extends CTAlgorithm {\n namedCurve: CTNamedCurve;\n}\n\nexport interface CTHmacImportParams extends CTAlgorithm {\n hash: CTAlgorithmIdentifier;\n length?: number;\n}\n\nexport interface CTAesKeyAlgorithm extends CTAlgorithm {\n length: number;\n}\n\nexport type CTKeyType = \"private\" | \"public\" | \"secret\";\n\nexport interface CTCryptoKey {\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/algorithm) */\n readonly algorithm: CTAlgorithm;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/extractable) */\n readonly extractable: boolean;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/type) */\n readonly type: CTKeyType;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/usages) */\n readonly usages: CTKeyUsage[];\n}\n\ninterface CTArrayBufferTypes {\n ArrayBuffer: ArrayBuffer;\n}\ntype CTArrayBufferLike = CTArrayBufferTypes[keyof CTArrayBufferTypes];\n\nexport interface CTArrayBufferView {\n /**\n * The ArrayBuffer instance referenced by the array.\n */\n buffer: CTArrayBufferLike;\n\n /**\n * The length in bytes of the array.\n */\n byteLength: number;\n\n /**\n * The offset in bytes of the array.\n */\n byteOffset: number;\n}\n\nexport type CTBufferSource = CTArrayBufferView | ArrayBuffer;\n\nexport interface CryptoRuntime {\n importKey(\n format: CTKeyFormat,\n keyData: CTJsonWebKey | CTBufferSource,\n algorithm: CTAlgorithmIdentifier | CTRsaHashedImportParams | CTEcKeyImportParams | CTHmacImportParams | CTAesKeyAlgorithm,\n extractable: boolean,\n keyUsages: CTKeyUsage[],\n ): Promise<CTCryptoKey>;\n exportKey(format: CTKeyFormat, key: CTCryptoKey): Promise<CTJsonWebKey | ArrayBuffer>;\n\n //(format: \"raw\", key: ArrayBuffer, algo: string, extractable: boolean, usages: string[]) => Promise<CryptoKey>;\n decrypt(algo: { name: string; iv: Uint8Array; tagLength: number }, key: CTCryptoKey, data: Uint8Array): Promise<ArrayBuffer>;\n encrypt(algo: { name: string; iv: Uint8Array; tagLength: number }, key: CTCryptoKey, data: Uint8Array): Promise<ArrayBuffer>;\n digestSHA256(data: Uint8Array): Promise<ArrayBuffer>;\n randomBytes(size: number): Uint8Array;\n}\n\nfunction randomBytes(size: number): Uint8Array {\n const bytes = new Uint8Array(size);\n if (size > 0) {\n crypto.getRandomValues(bytes);\n }\n return bytes;\n}\n\nfunction digestSHA256(data: Uint8Array): Promise<ArrayBuffer> {\n return Promise.resolve(crypto.subtle.digest(\"SHA-256\", data));\n}\n\nexport function toCryptoRuntime(cryptoOpts: Partial<CryptoRuntime> = {}): CryptoRuntime {\n const runtime = {\n importKey: cryptoOpts.importKey || crypto.subtle.importKey.bind(crypto.subtle),\n exportKey: cryptoOpts.exportKey || crypto.subtle.exportKey.bind(crypto.subtle),\n encrypt: cryptoOpts.encrypt || crypto.subtle.encrypt.bind(crypto.subtle),\n decrypt: cryptoOpts.decrypt || crypto.subtle.decrypt.bind(crypto.subtle),\n randomBytes: cryptoOpts.randomBytes || randomBytes,\n digestSHA256: cryptoOpts.digestSHA256 || digestSHA256,\n };\n // console.log(\"cryptoOpts\", cryptoOpts, opts)\n return runtime;\n}\n","export const VERSION = Object.keys({\n __packageVersion__: \"xxxx\",\n})[0] as string;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,UAAU;;;ACDV,SAAS,SAAS,KAAsB,QAAgC,OAAO,GAAS;AAC7F,QAAM,MAAM,IAAI,WAAW,IAAI,QAAQ,IAAI,YAAY,IAAI,UAAU;AACrE,MAAI,SAAS;AACb,MAAI,QAAQ,GAAG;AACb,WAAO,IAAI;AAAA,EACb;AACA,SAAO,KAAK,IAAI,MAAM,IAAI,MAAM;AAChC,QAAM,OAAO;AACb,WAAS,OAAO,GAAG,OAAO,MAAM,QAAQ,MAAM;AAC5C,QAAI,OAAO,QAAQ,QAAQ,IAAI,UAAU,MAAM;AAAA,IAE/C,OAAO;AACL,aAAO,IAAI,SAAU,IAAI,SAAS;AAClC,aAAO,IAAI;AACX,eAAS;AAAA,IACX;AACA,UAAM,IAAc,CAAC,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,GAAG,MAAM;AAC/D,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,UAAI,OAAO,MAAM,MAAM;AACrB,UAAE,KAAK,IAAI,OAAO,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AAAA,MACtD,OAAO;AACL,UAAE,KAAK,IAAI;AAAA,MACb;AAEA,QAAE,KAAK,GAAG;AAAA,IACZ;AACA,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,UAAI,OAAO,MAAM,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AACtB,CAAC,EAAE,CAAC;","names":["Level","from"]}
1
+ {"version":3,"sources":["../../src/logger-impl.ts","../../src/bin2text.ts","../../src/logger.ts","../../src/result.ts","../../src/uri.ts","../../src/runtime.ts","../../src/log-writer-impl.ts","../../src/log-level-impl.ts","../../src/test/log-write-stream.ts","../../src/test/mock-logger.ts","../../src/option.ts","../../src/tracer.ts","../../src/crypto.ts","../../src/version.ts","../../src/refcounted.ts"],"sourcesContent":["// import { v4 } from \"uuid\";\nimport YAML from \"yaml\";\nimport {\n AsError,\n FnSerialized,\n LogSerializable,\n Level,\n Logger,\n logValue,\n Serialized,\n WithLogger,\n removeSelfRef,\n Sized,\n Lengthed,\n LogValue,\n asyncLogValue,\n LevelHandler,\n LogFormatter,\n LogValueArg,\n} from \"./logger.js\";\nimport { WebSysAbstraction } from \"./web/web-sys-abstraction.js\";\nimport { SysAbstraction } from \"./sys-abstraction.js\";\nimport { Result } from \"./result.js\";\nimport { CoerceURI, URI } from \"./uri.js\";\nimport { runtimeFn } from \"./runtime.js\";\nimport { ConsoleWriterStream } from \"./utils/console-write-stream.js\";\nimport { LogWriterStream } from \"./log-writer-impl.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"./txt-en-decoder.js\";\nimport { LevelHandlerSingleton } from \"./log-level-impl.js\";\n\nfunction getLen(value: unknown): LogValue {\n if (Array.isArray(value)) {\n return logValue(() => value.length);\n } else if (typeof value === \"string\") {\n return logValue(() => value.length);\n } else if (typeof value === \"object\" && value !== null) {\n if (typeof (value as Sized).size === \"number\") {\n return logValue(() => (value as Sized).size);\n } else if (typeof (value as Lengthed).length === \"number\") {\n return logValue(() => (value as Lengthed).length);\n }\n return logValue(() => Object.keys(value).length);\n }\n return logValue(() => -1);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction hash(value: unknown): string {\n // const hasher = createHash(\"sha256\");\n // hasher.update(JSON.stringify(value, removeSelfRef()));\n // return hasher.digest(\"hex\");\n return \"not implemented\";\n}\n\nfunction toLogValue(lop: LogValue | Promise<LogValue>): LogValue | undefined {\n if (lop && typeof (lop as Promise<LogValue>).then === \"function\") {\n throw new Error(\"async logValue Not implemented\");\n }\n return lop as LogValue;\n}\n\nexport class JSONFormatter implements LogFormatter {\n private readonly _txtEnDe: TxtEnDecoder;\n private readonly _space?: number;\n constructor(txtEnde: TxtEnDecoder, space?: number) {\n this._txtEnDe = txtEnde;\n this._space = space;\n }\n format(attr: LogSerializable): Uint8Array {\n return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + \"\\n\");\n }\n}\n\nexport class YAMLFormatter implements LogFormatter {\n private readonly _txtEnDe: TxtEnDecoder;\n private readonly _space?: number;\n constructor(txtEnde: TxtEnDecoder, space?: number) {\n this._txtEnDe = txtEnde;\n this._space = space;\n }\n format(attr: LogSerializable): Uint8Array {\n return this._txtEnDe.encode(\"---\\n\" + YAML.stringify(attr, removeSelfRef(), this._space) + \"\\n\");\n }\n}\n\nexport interface LoggerImplParams {\n readonly out?: WritableStream<Uint8Array>;\n readonly logWriter?: LogWriterStream;\n readonly sys?: SysAbstraction;\n readonly withAttributes?: LogSerializable;\n readonly levelHandler?: LevelHandler;\n readonly txtEnDe?: TxtEnDecoder;\n readonly formatter?: LogFormatter;\n}\n\nexport class LoggerImpl implements Logger {\n readonly _sys: SysAbstraction;\n readonly _attributes: LogSerializable = {};\n readonly _withAttributes: LogSerializable;\n readonly _logWriter: LogWriterStream;\n readonly _levelHandler: LevelHandler;\n readonly _txtEnDe: TxtEnDecoder;\n _formatter: LogFormatter;\n // readonly _id: string = \"logger-\" + Math.random().toString(36)\n\n constructor(params?: LoggerImplParams) {\n if (!params) {\n params = {};\n }\n if (!params.sys) {\n this._sys = WebSysAbstraction();\n } else {\n this._sys = params.sys;\n }\n if (!params.txtEnDe) {\n this._txtEnDe = Utf8EnDecoderSingleton();\n } else {\n this._txtEnDe = params.txtEnDe;\n }\n if (!params.formatter) {\n this._formatter = new JSONFormatter(this._txtEnDe);\n } else {\n this._formatter = params.formatter;\n }\n\n if (params.logWriter) {\n this._logWriter = params.logWriter;\n } else {\n if (!params.out) {\n const rt = runtimeFn();\n let stream: WritableStream<Uint8Array>;\n if (rt.isBrowser) {\n stream = new ConsoleWriterStream();\n } else {\n if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {\n stream = this._sys.Stdout();\n } else {\n throw new Error(\"No output defined for runtime\");\n }\n }\n this._logWriter = new LogWriterStream(stream);\n } else {\n this._logWriter = new LogWriterStream(params.out);\n }\n }\n if (!params.withAttributes) {\n this._withAttributes = {};\n } else {\n this._withAttributes = { ...params.withAttributes };\n }\n this._attributes = { ...this._withAttributes };\n if (params.levelHandler) {\n this._levelHandler = params.levelHandler;\n } else {\n this._levelHandler = LevelHandlerSingleton();\n }\n // console.log(\"LoggerImpl\", this._id, this._attributes, this._withAttributes)\n }\n\n TxtEnDe(): TxtEnDecoder {\n return this._txtEnDe;\n }\n\n Attributes(): Record<string, unknown> {\n return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));\n // return Array.from(Object.entries(this._attributes)).reduce(\n // (acc, [key, value]) => {\n // if (value instanceof LogValue) {\n // acc[key] = value.value();\n // }\n // return acc;\n // },\n // {} as Record<string, unknown>,\n // );\n }\n\n SetExposeStack(enable?: boolean): Logger {\n this._levelHandler.setExposeStack(enable);\n return this;\n }\n\n EnableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): Logger {\n this._levelHandler.disableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): Logger {\n this._attributes[\"module\"] = logValue(key);\n this._withAttributes[\"module\"] = logValue(key);\n return this;\n }\n // if the string is \"*\" it will enable for all modules\n SetDebug(...modules: (string | string[])[]): Logger {\n this._levelHandler.setDebug(...modules);\n return this;\n }\n\n SetFormatter(formatter: LogFormatter): Logger {\n this._formatter = formatter;\n return this;\n }\n\n Timestamp(): Logger {\n this._attributes[\"ts\"] = logValue(() => this._sys.Time().Now().toISOString());\n return this;\n }\n Warn(): Logger {\n this._attributes[\"level\"] = logValue(Level.WARN);\n return this;\n }\n Log(): Logger {\n return this;\n }\n Debug(): Logger {\n this._attributes[\"level\"] = logValue(Level.DEBUG);\n return this;\n }\n Error(): Logger {\n this._attributes[\"level\"] = logValue(Level.ERROR);\n return this;\n }\n Info(): Logger {\n this._attributes[\"level\"] = logValue(Level.INFO);\n return this;\n }\n Err(err: unknown | Result<unknown> | Error): Logger {\n if (Result.Is(err)) {\n if (err.isOk()) {\n this.Result(\"noerror\", err);\n } else {\n this.Result(\"error\", err);\n }\n } else if (err instanceof Error) {\n this._attributes[\"error\"] = logValue(err.message);\n if (this._levelHandler.isStackExposed) {\n this._attributes[\"stack\"] = logValue(err.stack?.split(\"\\n\").map((s) => s.trim()));\n }\n } else {\n this._attributes[\"error\"] = logValue(\"\" + err);\n }\n return this;\n }\n WithLevel(l: Level): Logger {\n this._attributes[\"level\"] = logValue(l);\n return this;\n }\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): Logger {\n if (typeof action === \"function\") {\n this._attributes[key] = logValue(action as FnSerialized);\n } else if (typeof action.toString === \"function\") {\n this._attributes[key] = logValue(() => action.toString());\n } else {\n this._attributes[key] = logValue(\"INVALID REF\");\n }\n return this;\n }\n Bool(key: string, value: unknown): Logger {\n this._attributes[key] = logValue(!!value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): Logger {\n if (res.isOk()) {\n this._attributes[key] = logValue(res.Ok() as Serialized);\n } else {\n this.Err(res.Err());\n }\n return this;\n }\n\n Len(value: unknown, key = \"len\"): Logger {\n this._attributes[key] = getLen(value);\n return this;\n }\n\n Hash(value: unknown, key = \"hash\"): Logger {\n this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);\n return this;\n }\n\n Url(url: CoerceURI, key = \"url\"): Logger {\n this.Ref(key, () => URI.from(url).toString());\n return this;\n }\n\n Str(key: string, value?: string): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n\n Any(key: string, value?: string | number | boolean | LogSerializable): Logger {\n this._attributes[key] = logValue(value as LogValueArg);\n return this;\n }\n Dur(key: string, nsec: number): Logger {\n this._attributes[key] = logValue(`${nsec}ms`);\n // new Intl.DurationFormat(\"en\", { style: \"narrow\" }).format(nsec);\n return this;\n }\n Uint64(key: string, value: number): Logger {\n this._attributes[key] = logValue(value);\n return this;\n }\n Int(key: string, value: number): Logger {\n return this.Uint64(key, value);\n }\n\n async Flush(): Promise<void> {\n return new Promise((resolve) => {\n this._logWriter._flush(undefined, resolve);\n });\n }\n\n With(): WithLogger {\n // console.log(\"WithLoggerBuilder.With\", this._id, this._attributes, this._withAttributes);\n return new WithLoggerBuilder(\n new LoggerImpl({\n logWriter: this._logWriter,\n sys: this._sys,\n levelHandler: this._levelHandler,\n formatter: this._formatter,\n withAttributes: {\n module: this._attributes[\"module\"],\n ...this._withAttributes,\n },\n }),\n );\n }\n\n _resetAttributes(fn: () => () => Uint8Array): () => Uint8Array {\n const ret = fn();\n Object.keys(this._attributes).forEach((key) => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n });\n Object.assign(this._attributes, this._withAttributes);\n return ret;\n }\n\n Msg(...args: string[]): AsError {\n const fnError = this._resetAttributes(() => {\n const doWrite = this._levelHandler.isEnabled(\n toLogValue(this._attributes[\"level\"])?.value(),\n toLogValue(this._attributes[\"module\"])?.value(),\n );\n this._attributes[\"msg\"] = logValue(args.join(\" \"));\n const msg = this._attributes[\"msg\"].value();\n if (typeof msg === \"string\" && !msg.trim().length) {\n delete this._attributes[\"msg\"];\n }\n let fnRet = (): Uint8Array => this._formatter.format({ ...this._attributes });\n if (doWrite) {\n const encoded = fnRet();\n this._logWriter.write(encoded);\n fnRet = (): Uint8Array => encoded;\n }\n return fnRet;\n });\n return {\n AsError: () => new Error(this._txtEnDe.decode(fnError())),\n };\n }\n}\n\nclass WithLoggerBuilder implements WithLogger {\n readonly _li: LoggerImpl;\n constructor(li: LoggerImpl) {\n this._li = li;\n }\n\n TxtEnDe(): TxtEnDecoder {\n return this._li.TxtEnDe();\n }\n\n Logger(): Logger {\n Object.assign(this._li._withAttributes, this._li._attributes);\n return this._li;\n }\n\n Attributes(): Record<string, unknown> {\n return { ...this._li._attributes };\n }\n\n SetExposeStack(enable?: boolean): WithLogger {\n this._li._levelHandler.setExposeStack(enable);\n return this;\n }\n\n SetFormatter(fmt: LogFormatter): WithLogger {\n this._li.SetFormatter(fmt);\n return this;\n }\n\n EnableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n DisableLevel(level: Level, ...modules: string[]): WithLogger {\n this._li._levelHandler.enableLevel(level, ...modules);\n return this;\n }\n\n Module(key: string): WithLogger {\n this._li.Module(key);\n return this;\n }\n SetDebug(...modules: (string | string[])[]): WithLogger {\n this._li.SetDebug(...modules);\n return this;\n }\n\n Str(key: string, value?: string): WithLogger {\n this._li.Str(key, value);\n return this;\n }\n\n Len(value: unknown, key?: string): WithLogger {\n this._li.Len(value, key);\n return this;\n }\n\n Hash(value: unknown, key?: string): WithLogger {\n this._li.Hash(value, key);\n return this;\n }\n\n Ref(key: string, action: Serialized | FnSerialized): WithLogger {\n this._li.Ref(key, action);\n return this;\n }\n Bool(key: string, value: unknown): WithLogger {\n this._li.Bool(key, value);\n return this;\n }\n Result<T>(key: string, res: Result<T, Error>): WithLogger {\n this._li.Result(key, res);\n return this;\n }\n Url(url: CoerceURI, key?: string): WithLogger {\n this._li.Url(url, key);\n return this;\n }\n Int(key: string, value: number): WithLogger {\n this._li.Int(key, value);\n return this;\n }\n\n Log(): WithLogger {\n this._li.Log();\n return this;\n }\n\n WithLevel(level: Level): WithLogger {\n this._li.WithLevel(level);\n return this;\n }\n\n Error(): WithLogger {\n this._li.Error();\n return this;\n }\n Warn(): WithLogger {\n this._li.Error();\n return this;\n }\n Debug(): WithLogger {\n this._li.Debug();\n return this;\n }\n Err(err: unknown): WithLogger {\n this._li.Err(err);\n return this;\n }\n Info(): WithLogger {\n this._li.Info();\n return this;\n }\n Timestamp(): WithLogger {\n this._li.Timestamp();\n return this;\n }\n Any(key: string, value: LogSerializable): WithLogger {\n this._li.Any(key, value);\n return this;\n }\n Dur(key: string, nsec: number): WithLogger {\n this._li.Dur(key, nsec);\n return this;\n }\n Uint64(key: string, value: number): WithLogger {\n this._li.Uint64(key, value);\n return this;\n }\n}\n","export function bin2text(hex: ArrayBufferView, lineFn: (line: string) => void, size = 0): void {\n const arr = new Uint8Array(hex.buffer, hex.byteOffset, hex.byteLength);\n let cutted = \" \";\n if (size == 0) {\n size = arr.length;\n }\n size = Math.min(size, arr.length);\n const cols = 16;\n for (let line = 0; line < size; line += cols) {\n if (line + cols <= size || arr.length == size) {\n // normal line\n } else {\n line = arr.length - (arr.length % cols);\n size = arr.length;\n cutted = \">>\";\n }\n const l: string[] = [line.toString(16).padStart(4, \"0\"), cutted];\n for (let col = 0; col < cols; col++) {\n if (line + col < size) {\n l.push(arr[line + col].toString(16).padStart(2, \"0\"));\n } else {\n l.push(\" \");\n }\n // l.push((col > 0 && col % 4 === 3) ? \" \" : \" \");\n l.push(\" \");\n }\n for (let col = 0; col < cols; col++) {\n if (line + col < size) {\n const ch = arr[line + col];\n l.push(ch >= 32 && ch < 127 ? String.fromCharCode(ch) : \".\");\n }\n }\n lineFn(l.join(\"\"));\n }\n}\n\nexport function bin2string(hex: ArrayBufferView, size = 0): string {\n const collector: string[] = [];\n bin2text(\n hex,\n (line) => {\n collector.push(line);\n },\n size,\n );\n return collector.join(\"\\n\");\n}\n","import { bin2string } from \"./bin2text.js\";\nimport { Result } from \"./result.js\";\nimport { TxtEnDecoder } from \"./txt-en-decoder.js\";\nimport { CoerceURI } from \"./uri.js\";\n\nexport enum Level {\n WARN = \"warn\",\n DEBUG = \"debug\",\n INFO = \"info\",\n ERROR = \"error\",\n}\n\nexport type Serialized = string | number | boolean;\nexport type FnSerialized = () => Serialized | Serialized[];\n\nexport class LogValue {\n constructor(readonly fn: FnSerialized) {}\n value(): Serialized | Serialized[] {\n return this.fn();\n }\n toJSON(): Serialized | Serialized[] {\n return this.value();\n }\n}\n\nexport type LogSerializable = Record<string, LogValue | Promise<LogValue>>;\n\nexport function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown {\n const cache = new Set();\n return function (key: unknown, value: unknown) {\n if (typeof value === \"object\" && value !== null) {\n // Duplicate reference found, discard key\n if (cache.has(value)) return \"...\";\n cache.add(value);\n }\n return lineEnd ? value + lineEnd : value;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue> {\n // return Promise.resolve(logValue(val));\n throw new Error(\"Not implemented\");\n}\n\nexport type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;\n\nexport function logValue(val: LogValueArg, state: Set<unknown> = new Set<unknown>([Math.random()])): LogValue {\n switch (typeof val) {\n case \"function\":\n return new LogValue(val);\n case \"string\": {\n try {\n const ret = JSON.parse(val);\n if (typeof ret === \"object\" && ret !== null) {\n return logValue(ret, state);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n if (val.match(/[\\n\\r]/)) {\n const lines = val.trimEnd().split(/[\\n\\r]/);\n return new LogValue(() => lines);\n }\n }\n return new LogValue(() => val.toString());\n }\n case \"number\":\n return new LogValue(() => val);\n case \"boolean\":\n return new LogValue(() => val);\n case \"object\": {\n if (ArrayBuffer.isView(val)) {\n return logValue(bin2string(val, 512));\n }\n if (Array.isArray(val)) {\n return new LogValue(() => val.map((v) => logValue(v).value() as Serialized));\n }\n if (val === null) {\n return new LogValue(() => \"null\");\n }\n // Duplicate reference found, discard key\n if (state.has(val)) {\n return new LogValue(() => \"...\");\n }\n state.add(val);\n\n const res: Record<string, LogValue> = {};\n const typedVal = val as unknown as Record<string, LogValueArg>;\n for (const key in typedVal) {\n const element = typedVal[key];\n if (element instanceof LogValue) {\n res[key] = element;\n } else {\n res[key] = logValue(element, state);\n }\n }\n // ugly as hell cast but how declare a self-referencing type?\n return new LogValue(() => res as unknown as Serialized);\n }\n default:\n if (!val) {\n return new LogValue(() => \"--Falsy--\");\n }\n throw new Error(`Invalid type:${typeof val}`);\n }\n}\n\nexport interface Sized {\n size: number;\n}\nexport interface Lengthed {\n length: number;\n}\nexport type SizeOrLength = Sized | Lengthed;\n\nexport interface LogFormatter {\n format(attr: LogSerializable): Uint8Array;\n}\n\nexport interface LevelHandler {\n enableLevel(level: Level, ...modules: string[]): void;\n disableLevel(level: Level, ...modules: string[]): void;\n setExposeStack(enable?: boolean): void;\n isStackExposed: boolean;\n setDebug(...modules: (string | string[])[]): void;\n isEnabled(ilevel: unknown, module: unknown): boolean;\n}\n\nexport interface LoggerInterface<R> {\n TxtEnDe(): TxtEnDecoder;\n Module(key: string): R;\n // if modules is empty, set for all Levels\n EnableLevel(level: Level, ...modules: string[]): R;\n DisableLevel(level: Level, ...modules: string[]): R;\n\n Attributes(): Record<string, unknown>;\n\n SetDebug(...modules: (string | string[])[]): R;\n SetExposeStack(enable?: boolean): R;\n SetFormatter(fmt: LogFormatter): R;\n\n Ref(key: string, action: { toString: () => string } | FnSerialized): R;\n Result<T>(key: string, res: Result<T>): R;\n // default key url\n Url(url: CoerceURI, key?: string): R;\n // len\n Len(value: unknown, key?: string): R;\n\n Hash(value: unknown, key?: string): R;\n\n Str(key: string, value?: string): R;\n Error(): R;\n Warn(): R;\n Debug(): R;\n Log(): R;\n WithLevel(level: Level): R;\n\n Err(err: unknown | Result<unknown> | Error): R; // could be Error, or something which coerces to string\n Info(): R;\n Timestamp(): R;\n Any(key: string, value: unknown): R;\n Dur(key: string, nsec: number): R;\n Uint64(key: string, value: number): R;\n Int(key: string, value: number): R;\n Bool(key: string, value: unknown): R;\n}\n\nexport function IsLogger(obj: unknown): obj is Logger {\n return (\n typeof obj === \"object\" &&\n [\n \"Module\",\n \"EnableLevel\",\n \"DisableLevel\",\n \"SetDebug\",\n \"Str\",\n \"Error\",\n \"Warn\",\n \"Debug\",\n \"Log\",\n \"WithLevel\",\n \"Err\",\n \"Info\",\n \"Timestamp\",\n \"Any\",\n \"Dur\",\n \"Uint64\",\n ]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map((fn) => typeof (obj as any)[fn] === \"function\")\n .reduce((a, b) => a && b, true)\n );\n}\n\nexport interface WithLogger extends LoggerInterface<WithLogger> {\n Logger(): Logger;\n}\n\nexport interface AsError {\n AsError(): Error;\n}\n\nexport interface Logger extends LoggerInterface<Logger> {\n With(): WithLogger;\n\n Msg(...args: string[]): AsError;\n Flush(): Promise<void>;\n}\n","export abstract class Result<T, E = Error> {\n static Ok<T = void>(t: T): Result<T, Error> {\n return new ResultOK(t);\n }\n static Err<T, E extends Error = Error>(t: E | string): Result<T, E> {\n if (typeof t === \"string\") {\n return new ResultError(new Error(t) as E);\n }\n return new ResultError(t);\n }\n static Is<T>(t: unknown): t is Result<T> {\n if (!t) {\n return false;\n }\n if (t instanceof Result) {\n return true;\n }\n const rt = t as Result<T>;\n if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === \"function\")) {\n return true;\n }\n return false;\n }\n\n isOk(): boolean {\n return this.is_ok();\n }\n isErr(): boolean {\n return this.is_err();\n }\n\n Ok(): T {\n return this.unwrap();\n }\n Err(): E {\n return this.unwrap_err();\n }\n\n abstract is_ok(): boolean;\n abstract is_err(): boolean;\n abstract unwrap(): T;\n abstract unwrap_err(): E;\n}\n\nexport class ResultOK<T> extends Result<T, Error> {\n private _t: T;\n constructor(t: T) {\n super();\n this._t = t;\n }\n is_ok(): boolean {\n return true;\n }\n is_err(): boolean {\n return false;\n }\n unwrap_err(): Error {\n throw new Error(\"Result is Ok\");\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class ResultError<T extends Error> extends Result<never, T> {\n private _error: T;\n constructor(t: T) {\n super();\n this._error = t;\n }\n is_ok(): boolean {\n return false;\n }\n is_err(): boolean {\n return true;\n }\n unwrap(): never {\n throw new Error(`Result is Err: ${this._error}`);\n }\n unwrap_err(): T {\n return this._error;\n }\n}\n\nexport type WithoutResult<T> = T extends Result<infer U> ? U : T;\n\n// type WithoutPromise<T> = T extends Promise<infer U> ? U : T;\ntype WithResult<T> = T extends Promise<infer U> ? Promise<Result<U>> : Result<T>;\n\nexport function exception2Result<FN extends () => Promise<T> | T, T>(fn: FN): WithResult<ReturnType<FN>> {\n try {\n const res = fn();\n if (res instanceof Promise) {\n return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e)) as WithResult<ReturnType<FN>>;\n }\n return Result.Ok(res) as WithResult<ReturnType<FN>>;\n } catch (e) {\n return Result.Err(e as Error) as WithResult<ReturnType<FN>>;\n }\n}\n\n/*\n\ntype FinalizedResult<T> = {\n result: T;\n scopeResult?: Result<void>;\n finally: () => Promise<void>;\n}\n\ntype exection2ResultParam<T> = {\n init: () => Promise<T>;\n inScope?: (t: T) => Promise<void>;\n cleanup: (t: T) => Promise<void>;\n\n}\n\nasync function expection2Result<T>({fn, inScope, cleanup}: exection2ResultParam<T>): Promise<Result<FinalizedResult<T>>> {\n try {\n const res = await fn();\n if (inScope) {\n try {\n await inScope?.(res)\n } catch (err) {\n return Result.Err(err as Error)\n }\n await cleanup(res)\n return Result.Ok({\n result: res,\n finally: async () => { }\n })\n }\n return Result.Ok({\n result: res ,\n finally: async () => {\n return cleanup(res)\n }\n })\n } catch (err) {\n return Result.Err(err as Error)\n }\n}\n*/\n\n// await expection2Result({\n// init: openDB,\n// inScope: (res) => {\n// res.query()\n// },\n// cleanup: async (y) => {\n// await y.close()\n// }\n// })\n// async function openDB() {\n// try {\n// const opendb = await openDB()\n// return Result.Ok({\n// openDB,\n// finally: async () => {\n// await opendb.close()\n// }})\n// } catch (err) {\n// return Result.Err(err)\n// }\n// }\n// }\n","import { exception2Result, Result } from \"./result.js\";\n\ntype NullOrUndef = null | undefined;\n\nfunction falsy2undef<T>(value: T | NullOrUndef): T | undefined {\n return value === undefined || value === null ? undefined : value;\n}\n\nfunction ensureURLWithDefaultProto(url: string | URL, defaultProtocol: string): MutableURL {\n if (!url) {\n return new MutableURL(`${defaultProtocol}//`);\n }\n if (typeof url === \"string\") {\n try {\n return new MutableURL(url);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n return new MutableURL(`${defaultProtocol}//${url}`);\n }\n } else {\n return new MutableURL(url.toString());\n }\n}\n\nexport function isURL(value: unknown): value is URL {\n return (\n value instanceof URL ||\n (!!value &&\n typeof (value as URL).searchParams === \"object\" &&\n typeof (value as URL).searchParams.sort === \"function\" &&\n typeof (value as URL).hash === \"string\")\n );\n}\n\n// due to that the System URL class is has a strange behavior\n// on different platforms, we need to implement our own URL class\nexport class MutableURL extends URL {\n private readonly _sysURL: URL;\n // private readonly _urlStr: string;\n\n private _protocol: string;\n private _pathname: string;\n private _hasHostpart: boolean;\n\n readonly hash: string;\n\n constructor(urlStr: string) {\n super(\"defect://does.not.exist\");\n const partedURL = urlStr.split(\":\");\n this._hasHostpart = protocols.has(partedURL[0]);\n let hostPartUrl = [\"http\", ...partedURL.slice(1)].join(\":\");\n if (!this._hasHostpart) {\n const pathname = hostPartUrl.replace(/http:\\/\\/[/]*/, \"\").replace(/[#?].*$/, \"\");\n hostPartUrl = hostPartUrl.replace(/http:\\/\\//, `http://localhost/${pathname}`);\n }\n try {\n this._sysURL = new URL(hostPartUrl);\n } catch (ie) {\n const e = ie as Error;\n e.message = `${e.message} for URL: ${urlStr}`;\n throw e;\n }\n this._protocol = `${partedURL[0]}:`; // this._sysURL.protocol.replace(new RegExp(\"^cement-\"), \"\");\n if (this._hasHostpart) {\n this._pathname = this._sysURL.pathname;\n } else {\n this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), \"\").replace(/[#?].*$/, \"\");\n }\n this.hash = this._sysURL.hash;\n }\n\n clone(): MutableURL {\n return new MutableURL(this.toString());\n }\n\n get host(): string {\n if (!this._hasHostpart) {\n throw new Error(\n `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(protocols.keys()))}`,\n );\n }\n return this._sysURL.host;\n }\n\n get port(): string {\n if (!this._hasHostpart) {\n throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n return this._sysURL.port;\n }\n\n set port(p: string) {\n if (!this._hasHostpart) {\n throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n this._sysURL.port = p;\n }\n\n get hostname(): string {\n if (!this._hasHostpart) {\n throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n return this._sysURL.hostname;\n }\n\n set hostname(h: string) {\n if (!this._hasHostpart) {\n throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);\n }\n this._sysURL.hostname = h;\n }\n\n set pathname(p: string) {\n this._pathname = p;\n }\n\n get pathname(): string {\n return this._pathname;\n }\n\n get protocol(): string {\n return this._protocol;\n }\n\n set protocol(p: string) {\n if (!p.endsWith(\":\")) {\n p = `${p}:`;\n }\n this._protocol = p;\n }\n\n get searchParams(): URLSearchParams {\n return this._sysURL.searchParams;\n }\n\n toString(): string {\n let search = \"\";\n if (this._sysURL.searchParams.size) {\n for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {\n search += `${!search.length ? \"?\" : \"&\"}${key}=${encodeURIComponent(value)}`;\n }\n }\n let hostpart = \"\";\n if (this._hasHostpart) {\n hostpart = this._sysURL.hostname;\n if (this._sysURL.port) {\n hostpart += `:${this._sysURL.port}`;\n }\n if (!this._pathname.startsWith(\"/\")) {\n hostpart += \"/\";\n }\n }\n return `${this._protocol}//${hostpart}${this._pathname}${search}`;\n }\n}\n\nfunction from<T>(fac: (url: MutableURL) => T, strURLUri: CoerceURI | undefined, defaultProtocol: string): T {\n switch (typeof falsy2undef(strURLUri)) {\n case \"undefined\":\n return fac(new MutableURL(`${defaultProtocol}///`));\n case \"string\":\n return fac(ensureURLWithDefaultProto(strURLUri as string, defaultProtocol));\n case \"object\":\n if (BuildURI.is(strURLUri)) {\n return fac(new MutableURL(strURLUri._url.toString()));\n } else if (URI.is(strURLUri)) {\n return fac(new MutableURL(strURLUri._url.toString()));\n } else if (isURL(strURLUri)) {\n return fac(new MutableURL(strURLUri.toString()));\n }\n throw new Error(`unknown object type: ${strURLUri}`);\n default:\n throw new Error(`Invalid argument: ${typeof strURLUri}`);\n }\n}\n\nexport class BuildURI {\n _url: MutableURL; // pathname needs this\n private constructor(url: MutableURL) {\n this._url = url;\n }\n\n static is(value: unknown): value is BuildURI {\n return (\n value instanceof BuildURI ||\n (!!value && typeof (value as BuildURI).delParam === \"function\" && typeof (value as BuildURI).setParam === \"function\")\n );\n }\n static from(strURLUri?: CoerceURI, defaultProtocol = \"file:\"): BuildURI {\n return from((url) => new BuildURI(url), strURLUri, defaultProtocol);\n }\n\n port(p: string): BuildURI {\n this._url.port = p;\n return this;\n }\n\n hostname(h: string): BuildURI {\n this._url.hostname = h;\n return this;\n }\n\n // password(p: string) {\n // this._url.password = p;\n // return this;\n // }\n\n // port(p: string) {\n // this._url.port = p;\n // return this;\n // }\n\n // username(u: string) {\n // this._url.username = u;\n // return this;\n // }\n\n // search(s: string) {\n // this._url.search = s;\n // return this;\n // }\n\n protocol(p: string): BuildURI {\n this._url.protocol = p;\n // if (!p.endsWith(\":\")) {\n // p = `${p}:`;\n // }\n // const mySrc = this._url.toString();\n // const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}`), `${p}`);\n // this._url = new URL(myDst);\n return this;\n }\n\n pathname(p: string): BuildURI {\n // const myp = this.URI().pathname;\n // const mySrc = this._url.toString();\n // const myDst = mySrc.replace(new RegExp(`^${this._url.protocol}//${myp}`), `${this._url.protocol}//${p}`);\n // this._url = new URL(myDst);\n this._url.pathname = p;\n return this;\n }\n\n // hash(h: string) {\n // this._url.hash = h;\n // return this;\n // }\n\n // host(h: string) {\n // this._url.host = h;\n // return this;\n // }\n\n delParam(key: string): BuildURI {\n this._url.searchParams.delete(key);\n return this;\n }\n\n defParam(key: string, str: string): BuildURI {\n if (!this._url.searchParams.has(key)) {\n this._url.searchParams.set(key, str);\n }\n return this;\n }\n\n setParam(key: string, str: string): BuildURI {\n this._url.searchParams.set(key, str);\n return this;\n }\n\n hasParam(key: string): boolean {\n return this._url.searchParams.has(key);\n }\n\n getParam(key: string): string | undefined {\n return falsy2undef(this._url.searchParams.get(key));\n }\n\n toString(): string {\n this._url.searchParams.sort();\n return this._url.toString();\n }\n toJSON(): string {\n return this.toString();\n }\n\n URI(): URI {\n return URI.from(this._url);\n }\n}\n\nexport type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;\n\nexport const protocols: Set<string> = new Set<string>([\"http\", \"https\", \"ws\", \"wss\"]);\n\n// non mutable URL Implementation\nexport class URI {\n static protocolHasHostpart(protocol: string): () => void {\n protocol = protocol.replace(/:$/, \"\");\n protocols.add(protocol);\n return () => {\n protocols.delete(protocol);\n };\n }\n\n // if no protocol is provided, default to file:\n static merge(into: CoerceURI, from: CoerceURI, defaultProtocol = \"file:\"): URI {\n const intoUrl = BuildURI.from(into, defaultProtocol);\n const fromUrl = URI.from(from, defaultProtocol);\n\n intoUrl.protocol(fromUrl.protocol);\n const fPath = fromUrl.pathname;\n if (!(fPath.length === 0 || fPath === \"/\" || fPath === \"./\")) {\n intoUrl.pathname(fromUrl.pathname);\n }\n for (const [key, value] of fromUrl.getParams) {\n intoUrl.setParam(key, value);\n }\n return intoUrl.URI();\n }\n\n static is(value: unknown): value is URI {\n return (\n value instanceof URI ||\n (!!value &&\n typeof (value as URI).asURL === \"function\" &&\n typeof (value as URI).getParam === \"function\" &&\n typeof (value as URI).hasParam === \"function\")\n );\n }\n\n // if no protocol is provided, default to file:\n static from(strURLUri?: CoerceURI, defaultProtocol = \"file:\"): URI {\n return from((url) => new URI(url), strURLUri, defaultProtocol);\n }\n\n static fromResult(strURLUri?: CoerceURI, defaultProtocol = \"file:\"): Result<URI> {\n return exception2Result(() => from((url) => new URI(url), strURLUri, defaultProtocol)) as Result<URI>;\n }\n\n readonly _url: MutableURL;\n private constructor(url: MutableURL) {\n this._url = url.clone();\n }\n\n build(): BuildURI {\n return BuildURI.from(this._url);\n }\n\n get hostname(): string {\n return this._url.hostname;\n }\n\n // get password(): string {\n // return this._url.password;\n // }\n\n get port(): string {\n return this._url.port;\n }\n\n get host(): string {\n return this._url.host;\n }\n\n // get username(): string {\n // return this._url.username;\n // }\n\n // get search(): string {\n // return this._url.search;\n // }\n\n get protocol(): string {\n return this._url.protocol;\n }\n\n get pathname(): string {\n return this._url.pathname;\n // return this._url\n // .toString()\n // .replace(/^.*:\\/\\//, \"\")\n // .replace(/\\?.*$/, \"\");\n }\n\n // get hash(): string {\n // return this._url.hash;\n // }\n\n // get host(): string {\n // return this._url.host;\n // }\n\n get getParams(): Iterable<[string, string]> {\n return this._url.searchParams.entries();\n }\n\n hasParam(key: string): boolean {\n return this._url.searchParams.has(key);\n }\n getParam(key: string): string | undefined {\n return falsy2undef(this._url.searchParams.get(key));\n }\n\n clone(): URI {\n return new URI(this._url);\n }\n\n asURL(): URL {\n // const url = new URL(this._url.toString());\n // url.searchParams.sort();\n return this._url.clone() as unknown as URL;\n }\n\n toString(): string {\n // this._url.searchParams.sort();\n return this._url.toString();\n }\n toJSON(): string {\n return this.toString();\n }\n}\n","export interface Runtime {\n isNodeIsh: boolean;\n isBrowser: boolean;\n isDeno: boolean;\n isReactNative: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isSet(value: string, ref: any = globalThis): boolean {\n const [head, ...tail] = value.split(\".\");\n if ([\"object\", \"function\"].includes(typeof ref) && ref && [\"object\", \"function\"].includes(typeof ref[head]) && ref[head]) {\n if (tail.length <= 1) {\n return true;\n }\n return isSet(tail.join(\".\"), ref[head]);\n }\n return false;\n}\n\nexport function runtimeFn(): Runtime {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const gt: any = globalThis;\n const isReactNative =\n isSet(\"navigator.product\") && typeof gt[\"navigator\"] === \"object\" && gt[\"navigator\"][\"product\"] === \"ReactNative\";\n let isNodeIsh = false;\n if (!isSet(\"Deno\")) {\n isNodeIsh = isSet(\"process.versions.node\") && !isReactNative;\n }\n const isDeno = isSet(\"Deno\");\n return {\n isNodeIsh,\n isBrowser: !(isNodeIsh || isDeno) && !isReactNative,\n isDeno,\n isReactNative,\n };\n}\n","export class LogWriterStream {\n readonly _out: WritableStream<Uint8Array>;\n readonly _toFlush: (() => Promise<void>)[] = [];\n\n constructor(out: WritableStream<Uint8Array>) {\n this._out = out;\n }\n\n write(encoded: Uint8Array): void {\n const my = async (): Promise<void> => {\n // const val = Math.random();\n // console.log(\">>>My:\", val)\n try {\n const writer = this._out.getWriter();\n await writer.ready;\n await writer.write(encoded);\n await writer.releaseLock();\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\"Chunk error:\", err);\n }\n // console.log(\"<<<My:\", val)\n };\n this._toFlush.push(my);\n this._flush();\n }\n\n _flushIsRunning = false;\n _flushDoneFns: (() => void)[] = [];\n _flush(toFlush: (() => Promise<void>)[] | undefined = undefined, done?: () => void): void {\n if (done) {\n this._flushDoneFns.push(done);\n }\n\n if (this._toFlush.length == 0) {\n // console.log(\"Flush is stopped\", this._toFlush.length)\n this._flushIsRunning = false;\n this._flushDoneFns.forEach((fn) => fn());\n this._flushDoneFns = [];\n return;\n }\n\n if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {\n this._flushIsRunning = true;\n // console.log(\"Flush is started\", this._toFlush.length)\n } else if (!toFlush) {\n // console.log(\"flush queue check but is running\", this._toFlush.length)\n return;\n }\n\n // console.log(\">>>Msg:\", this._toFlush.length)\n const my = this._toFlush.shift();\n my?.().finally(() => {\n // console.log(\"<<<Msg:\", this._toFlush.length)\n this._flush(this._toFlush);\n });\n }\n}\n","import { LevelHandler, Level } from \"./logger.js\";\n\nexport class LevelHandlerImpl implements LevelHandler {\n readonly _globalLevels: Set<Level> = new Set<Level>([Level.INFO, Level.ERROR, Level.WARN]);\n readonly _modules: Map<string, Set<Level>> = new Map<string, Set<Level>>();\n isStackExposed = false;\n enableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.add(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, level]));\n },\n ...modules,\n );\n }\n disableLevel(level: Level, ...modules: string[]): void {\n if (modules.length == 0) {\n this._globalLevels.delete(level);\n return;\n }\n this.forModules(\n level,\n (p) => {\n this._modules.delete(p);\n },\n ...modules,\n );\n }\n\n setExposeStack(enable?: boolean): void {\n this.isStackExposed = !!enable;\n }\n\n forModules(level: Level, fnAction: (p: string) => void, ...modules: (string | string[])[]): void {\n for (const m of modules.flat()) {\n if (typeof m !== \"string\") {\n continue;\n }\n const parts = m\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length);\n for (const p of parts) {\n fnAction(p);\n }\n }\n }\n setDebug(...modules: (string | string[])[]): void {\n this.forModules(\n Level.DEBUG,\n (p) => {\n this._modules.set(p, new Set([...this._globalLevels, Level.DEBUG]));\n },\n ...modules,\n );\n }\n isEnabled(ilevel: unknown, module: unknown): boolean {\n const level = ilevel as Level; // what if it's not a level?\n if (typeof module === \"string\") {\n const levels = this._modules.get(module);\n if (levels && levels.has(level)) {\n return true;\n }\n }\n const wlevel = this._modules.get(\"*\");\n if (wlevel && typeof level === \"string\") {\n if (wlevel.has(level)) {\n return true;\n }\n }\n if (typeof level !== \"string\") {\n // this is a plain log\n return true;\n }\n return this._globalLevels.has(level);\n }\n}\n\nconst levelSingleton = new LevelHandlerImpl();\n\nexport function LevelHandlerSingleton(): LevelHandler {\n return levelSingleton;\n}\n","import { FanoutWriteStream } from \"../utils/fanout-write-stream.js\";\nimport { Future } from \"../future.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\n\nexport class LogWriteStream implements WritableStreamDefaultWriter<Uint8Array> {\n private readonly _bufferArr: Uint8Array[];\n\n constructor(bufferArr: Uint8Array[]) {\n this._bufferArr = bufferArr;\n }\n\n readonly _resolveClosed: Future<undefined> = new Future<undefined>();\n readonly closed: Promise<undefined> = this._resolveClosed.asPromise();\n readonly desiredSize: number | null = null;\n readonly ready: Promise<undefined> = Promise.resolve(undefined);\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n async close(): Promise<void> {\n await this.closed;\n return Promise.resolve(undefined);\n }\n releaseLock(): void {\n // do nothing\n }\n async write(chunk?: Uint8Array): Promise<void> {\n if (chunk) {\n this._bufferArr.push(chunk);\n }\n return Promise.resolve(undefined);\n }\n}\n\nexport class LogCollector implements WritableStream<Uint8Array> {\n readonly locked: boolean = false;\n private _writer?: FanoutWriteStream;\n private readonly _pass?: WritableStreamDefaultWriter<Uint8Array>;\n private readonly _bufferArr: Uint8Array[] = [];\n private readonly _txtEnDe: TxtEnDecoder;\n\n constructor(pass?: WritableStreamDefaultWriter<Uint8Array>, txtEnDe?: TxtEnDecoder) {\n this._pass = pass;\n this._txtEnDe = txtEnDe || Utf8EnDecoderSingleton();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abort(reason?: Uint8Array): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n async close(): Promise<void> {\n if (this._writer) {\n const ret = await this._writer.close();\n this._writer = undefined;\n return ret;\n }\n return Promise.resolve(undefined);\n }\n\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (!this._writer) {\n const dests: WritableStreamDefaultWriter[] = [new LogWriteStream(this._bufferArr)];\n if (this._pass) {\n dests.push(this._pass);\n }\n this._writer = new FanoutWriteStream(dests);\n }\n return this._writer;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Logs(notJsonLine = false): any[] {\n if (!this._writer) {\n return [];\n }\n const jsonNlStr = this._txtEnDe.decode(\n new Uint8Array(\n (function* (res: Uint8Array[]): Generator<number, void, undefined> {\n for (const x of res) {\n yield* x;\n }\n })(this._bufferArr),\n ),\n );\n if (!notJsonLine) {\n const splitStr = jsonNlStr.split(\"\\n\");\n const filterStr = splitStr.filter((a) => a.length);\n const mapStr = filterStr.map((a) => JSON.parse(a));\n return mapStr;\n }\n return jsonNlStr.split(\"\\n\").filter((a) => a.length);\n }\n}\n","import { LevelHandlerImpl } from \"../log-level-impl.js\";\nimport { Logger } from \"../logger.js\";\nimport { LoggerImpl } from \"../logger-impl.js\";\nimport { SysAbstraction } from \"../sys-abstraction.js\";\nimport { LogCollector } from \"./log-write-stream.js\";\n\nexport interface MockLoggerReturn {\n readonly logger: Logger;\n readonly logCollector: LogCollector;\n}\n\nexport function MockLogger(params?: {\n readonly sys?: SysAbstraction;\n readonly pass?: WritableStreamDefaultWriter<Uint8Array>;\n moduleName?: string | string[];\n readonly disableDebug?: boolean;\n}): MockLoggerReturn {\n const lc = new LogCollector(params?.pass);\n let modNames = [\"MockLogger\"];\n if (typeof params?.moduleName === \"string\") {\n modNames = [params?.moduleName];\n } else if (Array.isArray(params?.moduleName)) {\n modNames = [...params.moduleName, ...modNames];\n }\n const logger = new LoggerImpl({\n out: lc,\n sys: params?.sys,\n levelHandler: new LevelHandlerImpl(),\n })\n .With()\n .Module(modNames[0])\n .Logger();\n if (!params?.disableDebug) {\n logger.SetDebug(...modNames);\n }\n return {\n logCollector: lc,\n logger,\n };\n}\n","export abstract class Option<T> {\n static Some<T>(t: T): Option<T> {\n return new Some(t);\n }\n\n static None<T>(): Option<T> {\n return new None();\n }\n\n static Is<T>(t: unknown): t is Option<T> {\n return t instanceof Option;\n }\n\n IsNone(): boolean {\n return this.is_none();\n }\n\n IsSome(): boolean {\n return this.is_some();\n }\n Unwrap(): T {\n return this.unwrap();\n }\n\n abstract is_none(): boolean;\n abstract is_some(): boolean;\n abstract unwrap(): T;\n}\n\nexport class Some<T> extends Option<T> {\n private _t: T;\n constructor(_t: T) {\n super();\n this._t = _t;\n }\n\n is_none(): boolean {\n return false;\n }\n is_some(): boolean {\n return true;\n }\n unwrap(): T {\n return this._t;\n }\n}\n\nexport class None<T> extends Option<T> {\n is_none(): boolean {\n return true;\n }\n is_some(): boolean {\n return false;\n }\n unwrap(): T {\n throw new Error(\"None.unwrap\");\n }\n}\n\nexport type WithoutOption<T> = T extends Option<infer U> ? U : T;\n","import type { MarkWritable } from \"ts-essentials\";\nimport { Time } from \"./time.js\";\nimport { Logger } from \"./logger.js\";\n\nexport type TraceCtx = {\n readonly spanId: string;\n readonly time: Time;\n readonly parent: TraceNode;\n readonly metrics: Map<string, Metric<unknown>>;\n readonly logger?: Logger;\n} & Record<string, unknown>;\n\nexport type CleanCtx = {\n readonly spanId: string;\n} & Record<string, unknown>;\n\nexport type TraceCtxParam = {\n readonly spanId: string;\n} & Partial<{\n readonly time: Time;\n readonly parent: TraceNode;\n readonly logger: Logger;\n}> &\n Record<string, unknown>;\n\nexport class Metric<T> {\n value?: T;\n readonly path: string;\n\n constructor(path: string) {\n this.path = path;\n }\n\n set(value: T): void {\n this.value = value;\n }\n\n add<R extends number | ArrayLike<T>>(value: R): void {\n if (typeof value === \"number\") {\n if (this.value === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.value = 0 as any;\n }\n (this.value as number) = ((this.value as number) + value) as number;\n } else if (Array.isArray(value)) {\n if (!Array.isArray(this.value)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.value = [] as any;\n }\n (this.value as T[]).push(...value);\n } else {\n throw new Error(\"add only support number or array\");\n }\n }\n}\n\nexport type MetricMap = Map<string, Metric<unknown>>;\n\nexport class Metrics {\n readonly tracenode: TraceNode;\n private readonly map: MetricMap;\n\n readonly spanRefs: MetricMap = new Map<string, Metric<unknown>>();\n constructor(tracenode: TraceNode) {\n this.tracenode = tracenode;\n this.map = tracenode.ctx.metrics;\n }\n\n toJSON(): Record<string, unknown> {\n const obj: Record<string, unknown> = {};\n for (const [key, value] of this.map) {\n obj[key] = value.value;\n }\n return obj;\n }\n\n get<T>(ipath: string): Metric<T> {\n const path = ipath.replace(/[/]+/g, \"/\").trim();\n if (path.startsWith(\"/\")) {\n if (path.slice(1).length === 0) {\n throw new Error(`Metrics path must contain value /:${path}`);\n }\n let metric = this.map.get(path);\n if (!metric) {\n metric = new Metric<T>(path);\n this.map.set(path, metric);\n }\n this.spanRefs.set(path, metric);\n return metric as Metric<T>;\n } else if (path.includes(\"/\")) {\n throw new Error(`Metrics path must start with /:${path}`);\n }\n const rootPath = this.tracenode.getRootPath();\n return this.get(`${rootPath}/${path}`);\n }\n}\n\nexport interface Invokaction {\n readonly result: \"success\" | \"error\";\n readonly start: number;\n readonly end: number;\n readonly metrics?: Metrics;\n}\n\nexport type TraceNodeMap = Map<string, TraceNode>;\n\nexport class TraceNode {\n readonly childs: TraceNodeMap = new Map<string, TraceNode>();\n\n readonly invokations: Invokaction[] = [];\n\n readonly spanId: string;\n readonly ctx: TraceCtx;\n readonly metrics: Metrics;\n\n static root(time: Time, logger?: Logger): TraceNode {\n return new TraceNode({\n spanId: \"root\",\n time,\n logger,\n metrics: new Map(),\n parent: undefined as unknown as TraceNode,\n });\n }\n\n constructor(ctx: TraceCtx) {\n this.spanId = ctx.spanId;\n this.ctx = ctx;\n this.metrics = new Metrics(this);\n }\n\n getRootPath(rpath: string[] = []): string {\n if (!this.ctx.parent) {\n return \"/\" + rpath.reverse().join(\"/\");\n }\n return this.ctx.parent.getRootPath(rpath.concat(this.ctx.spanId));\n }\n\n invokes(): { ctx: CleanCtx; invokations: Invokaction[] } {\n const cleanCtx = { ...this.ctx } as CleanCtx;\n delete cleanCtx.parent;\n delete cleanCtx.time;\n delete cleanCtx.logger;\n delete cleanCtx.metrics;\n const spanRefs = this.metrics.toJSON.call({ map: this.metrics.spanRefs });\n const metricsRefs = Object.keys(spanRefs).length > 0 ? { metricRefs: spanRefs } : {};\n return {\n ctx: cleanCtx as CleanCtx,\n invokations: this.invokations,\n ...metricsRefs,\n };\n }\n\n ctxWith(spanId: string, logger?: Logger): TraceCtxParam {\n const ctx = {\n ...this.ctx,\n spanId,\n };\n if (logger) {\n ctx.logger = logger;\n }\n return ctx;\n }\n\n // <V extends () => Promise<T> | T, T>(id: string, fn: V): ReturnType<V>\n span<V extends (trace: TraceNode) => Promise<T> | T, T>(inSpanId: string | TraceCtxParam, fn: V): ReturnType<V> {\n let ctx: TraceCtx;\n if (typeof inSpanId === \"string\") {\n ctx = {\n ...this.ctx,\n spanId: inSpanId,\n parent: this,\n };\n } else {\n ctx = {\n ...this.ctx,\n ...inSpanId,\n parent: this,\n };\n }\n if (ctx.logger) {\n ctx = {\n ...ctx,\n ...ctx.logger.Attributes(),\n };\n }\n const spanId = ctx.spanId;\n let spanTrace = this.childs.get(spanId);\n if (!spanTrace) {\n spanTrace = new TraceNode(ctx);\n this.childs.set(spanId.toString(), spanTrace);\n }\n const invokation: MarkWritable<MarkWritable<Invokaction, \"end\">, \"result\"> = {\n start: this.ctx.time.Now().getTime(),\n end: 0,\n result: \"success\",\n };\n spanTrace.invokations.push(invokation);\n try {\n const possiblePromise = fn(spanTrace);\n if (possiblePromise instanceof Promise) {\n return possiblePromise\n .then((v) => {\n return v;\n })\n .catch((e) => {\n invokation.result = \"error\";\n throw e;\n })\n .finally(() => {\n invokation.end = this.ctx.time.Now().getTime();\n }) as ReturnType<V>;\n }\n invokation.end = this.ctx.time.Now().getTime();\n return possiblePromise as ReturnType<V>;\n } catch (e) {\n invokation.result = \"error\";\n invokation.end = this.ctx.time.Now().getTime();\n throw e;\n }\n }\n}\n","export interface CTJsonWebKey {\n alg?: string;\n crv?: string;\n d?: string;\n dp?: string;\n dq?: string;\n e?: string;\n ext?: boolean;\n k?: string;\n key_ops?: string[];\n kty?: string;\n n?: string;\n oth?: RsaOtherPrimesInfo[];\n p?: string;\n q?: string;\n qi?: string;\n use?: string;\n x?: string;\n y?: string;\n}\n\nexport type CTKeyFormat = \"jwk\" | \"pkcs8\" | \"raw\" | \"spki\";\nexport type CTKeyUsage = \"decrypt\" | \"deriveBits\" | \"deriveKey\" | \"encrypt\" | \"sign\" | \"unwrapKey\" | \"verify\" | \"wrapKey\";\n\nexport interface CTAlgorithm {\n name: string;\n}\nexport type CTAlgorithmIdentifier = CTAlgorithm | string;\n\nexport interface CTRsaHashedImportParams extends CTAlgorithm {\n hash: CTAlgorithmIdentifier;\n}\n\nexport type CTNamedCurve = string;\nexport interface CTEcKeyImportParams extends CTAlgorithm {\n namedCurve: CTNamedCurve;\n}\n\nexport interface CTHmacImportParams extends CTAlgorithm {\n hash: CTAlgorithmIdentifier;\n length?: number;\n}\n\nexport interface CTAesKeyAlgorithm extends CTAlgorithm {\n length: number;\n}\n\nexport type CTKeyType = \"private\" | \"public\" | \"secret\";\n\nexport interface CTCryptoKey {\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/algorithm) */\n readonly algorithm: CTAlgorithm;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/extractable) */\n readonly extractable: boolean;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/type) */\n readonly type: CTKeyType;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/usages) */\n readonly usages: CTKeyUsage[];\n}\n\ninterface CTArrayBufferTypes {\n ArrayBuffer: ArrayBuffer;\n}\ntype CTArrayBufferLike = CTArrayBufferTypes[keyof CTArrayBufferTypes];\n\nexport interface CTArrayBufferView {\n /**\n * The ArrayBuffer instance referenced by the array.\n */\n buffer: CTArrayBufferLike;\n\n /**\n * The length in bytes of the array.\n */\n byteLength: number;\n\n /**\n * The offset in bytes of the array.\n */\n byteOffset: number;\n}\n\nexport type CTBufferSource = CTArrayBufferView | ArrayBuffer;\n\nexport interface CryptoRuntime {\n importKey(\n format: CTKeyFormat,\n keyData: CTJsonWebKey | CTBufferSource,\n algorithm: CTAlgorithmIdentifier | CTRsaHashedImportParams | CTEcKeyImportParams | CTHmacImportParams | CTAesKeyAlgorithm,\n extractable: boolean,\n keyUsages: CTKeyUsage[],\n ): Promise<CTCryptoKey>;\n exportKey(format: CTKeyFormat, key: CTCryptoKey): Promise<CTJsonWebKey | ArrayBuffer>;\n\n //(format: \"raw\", key: ArrayBuffer, algo: string, extractable: boolean, usages: string[]) => Promise<CryptoKey>;\n decrypt(algo: { name: string; iv: Uint8Array; tagLength: number }, key: CTCryptoKey, data: Uint8Array): Promise<ArrayBuffer>;\n encrypt(algo: { name: string; iv: Uint8Array; tagLength: number }, key: CTCryptoKey, data: Uint8Array): Promise<ArrayBuffer>;\n digestSHA256(data: Uint8Array): Promise<ArrayBuffer>;\n randomBytes(size: number): Uint8Array;\n}\n\nfunction randomBytes(size: number): Uint8Array {\n const bytes = new Uint8Array(size);\n if (size > 0) {\n crypto.getRandomValues(bytes);\n }\n return bytes;\n}\n\nfunction digestSHA256(data: Uint8Array): Promise<ArrayBuffer> {\n return Promise.resolve(crypto.subtle.digest(\"SHA-256\", data));\n}\n\nexport function toCryptoRuntime(cryptoOpts: Partial<CryptoRuntime> = {}): CryptoRuntime {\n const runtime = {\n importKey: cryptoOpts.importKey || crypto.subtle.importKey.bind(crypto.subtle),\n exportKey: cryptoOpts.exportKey || crypto.subtle.exportKey.bind(crypto.subtle),\n encrypt: cryptoOpts.encrypt || crypto.subtle.encrypt.bind(crypto.subtle),\n decrypt: cryptoOpts.decrypt || crypto.subtle.decrypt.bind(crypto.subtle),\n randomBytes: cryptoOpts.randomBytes || randomBytes,\n digestSHA256: cryptoOpts.digestSHA256 || digestSHA256,\n };\n // console.log(\"cryptoOpts\", cryptoOpts, opts)\n return runtime;\n}\n","export const VERSION = Object.keys({\n __packageVersion__: \"xxxx\",\n})[0] as string;\n","type Refcounted<T, M extends string> = T & {\n __refcounted: number;\n __unrefcounted: () => void;\n} & Record<M, () => void>;\n\nexport function wrapRefcounted<T, M extends string>(t: T, method: M): T {\n const my = t as Refcounted<T, M>;\n my.__refcounted = (my.__refcounted || 0) + 1;\n if (my.__refcounted === 1) {\n my.__unrefcounted = my[method];\n const mRec = my as Record<string, () => void>;\n mRec[method] = function (this: Refcounted<T, M>): void {\n this.__refcounted--;\n if (this.__refcounted === 0) {\n this.__unrefcounted();\n }\n if (this.__refcounted < 0) {\n throw new Error(\"already closed\");\n }\n };\n }\n return t;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,UAAU;;;ACDV,SAAS,SAAS,KAAsB,QAAgC,OAAO,GAAS;AAC7F,QAAM,MAAM,IAAI,WAAW,IAAI,QAAQ,IAAI,YAAY,IAAI,UAAU;AACrE,MAAI,SAAS;AACb,MAAI,QAAQ,GAAG;AACb,WAAO,IAAI;AAAA,EACb;AACA,SAAO,KAAK,IAAI,MAAM,IAAI,MAAM;AAChC,QAAM,OAAO;AACb,WAAS,OAAO,GAAG,OAAO,MAAM,QAAQ,MAAM;AAC5C,QAAI,OAAO,QAAQ,QAAQ,IAAI,UAAU,MAAM;AAAA,IAE/C,OAAO;AACL,aAAO,IAAI,SAAU,IAAI,SAAS;AAClC,aAAO,IAAI;AACX,eAAS;AAAA,IACX;AACA,UAAM,IAAc,CAAC,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,GAAG,MAAM;AAC/D,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,UAAI,OAAO,MAAM,MAAM;AACrB,UAAE,KAAK,IAAI,OAAO,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AAAA,MACtD,OAAO;AACL,UAAE,KAAK,IAAI;AAAA,MACb;AAEA,QAAE,KAAK,GAAG;AAAA,IACZ;AACA,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,UAAI,OAAO,MAAM,MAAM;AACrB,cAAM,KAAK,IAAI,OAAO,GAAG;AAC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,GAAM,QAAc;AACtE,QAAM,KAAK;AACX,KAAG,gBAAgB,GAAG,gBAAgB,KAAK;AAC3C,MAAI,GAAG,iBAAiB,GAAG;AACzB,OAAG,iBAAiB,GAAG,MAAM;AAC7B,UAAM,OAAO;AACb,SAAK,MAAM,IAAI,WAAwC;AACrD,WAAK;AACL,UAAI,KAAK,iBAAiB,GAAG;AAC3B,aAAK,eAAe;AAAA,MACtB;AACA,UAAI,KAAK,eAAe,GAAG;AACzB,cAAM,IAAI,MAAM,gBAAgB;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["Level","from"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adviser/cement",
3
- "version": "0.2.29",
3
+ "version": "0.2.30",
4
4
  "description": "better try/catch/finally handling",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -44,20 +44,20 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^22.0.0",
47
- "@typescript-eslint/eslint-plugin": "^8.2.0",
48
- "@typescript-eslint/parser": "^8.3.0",
49
- "@vitest/browser": "^2.0.5",
47
+ "@typescript-eslint/eslint-plugin": "^8.7.0",
48
+ "@typescript-eslint/parser": "^8.7.0",
49
+ "@vitest/browser": "^2.1.1",
50
50
  "esbuild-plugin-replace": "^1.4.0",
51
51
  "esbuild-plugin-resolve": "^2.0.0",
52
- "eslint": "^9.8.0",
53
- "prettier": "^3.2.5",
54
- "tsup": "^8.1.0",
55
- "tsx": "^4.16.0",
56
- "typescript": "^5.5.0",
57
- "typescript-eslint": "^8.2.0",
52
+ "eslint": "^9.11.1",
53
+ "prettier": "^3.3.3",
54
+ "tsup": "^8.3.0",
55
+ "tsx": "^4.19.1",
56
+ "typescript": "^5.6.2",
57
+ "typescript-eslint": "^8.7.0",
58
58
  "vite-tsconfig-paths": "^5.0.1",
59
- "vitest": "^2.0.5",
60
- "webdriverio": "^9.0.7"
59
+ "vitest": "^2.1.1",
60
+ "webdriverio": "^9.1.0"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=16"
@@ -69,9 +69,9 @@
69
69
  "xbuild:js": "tsup",
70
70
  "build:js": "tsup --out-dir dist/pkg src/index.ts src/*/index.ts --sourcemap --format cjs,esm --dts --clean --external node:fs --external node:path",
71
71
  "test": "pnpm run test:js",
72
- "test:deno": "deno run --allow-net --allow-write --allow-run --allow-sys --allow-ffi --allow-read --allow-env ./node_modules/vitest/vitest.mjs --run --project node",
72
+ "test:deno": "deno run --quiet --allow-net --allow-write --allow-run --allow-sys --allow-ffi --allow-read --allow-env ./node_modules/vitest/vitest.mjs --run --project node",
73
73
  "test:js": "vitest --run",
74
- "pubdir": "bash ./prepare-pubdir.sh",
74
+ "pubdir": "bash -xe ./prepare-pubdir.sh",
75
75
  "presmoke": "pnpm run pubdir ; cd pubdir ; pnpm pack",
76
76
  "smoke": "cd smoke; rm -f package.json; pnpm init ; pnpm install -f ../pubdir/adviser-cement-*.tgz; npx tsx ./smoke.ts; deno run --allow-read ./smoke.ts",
77
77
  "lint": "eslint .",
package/src/index.ts CHANGED
@@ -19,4 +19,5 @@ export * from "./crypto.js";
19
19
  export * from "./base-sys-abstraction.js";
20
20
  export * from "./bin2text.js";
21
21
  export * from "./version.js";
22
+ export * from "./refcounted.js";
22
23
  export * as utils from "./utils/index.js";
package/src/jsr.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adviser/cement",
3
- "version": "0.2.29",
3
+ "version": "0.2.30",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./web": "./web/index.ts",
@@ -14,7 +14,9 @@
14
14
  "license": "AFL-2.0",
15
15
  "publish": {
16
16
  "include": [
17
- "**/*.ts"
17
+ "**/*.ts",
18
+ "README.md",
19
+ "LICENSE"
18
20
  ]
19
21
  }
20
22
  }
@@ -0,0 +1,23 @@
1
+ type Refcounted<T, M extends string> = T & {
2
+ __refcounted: number;
3
+ __unrefcounted: () => void;
4
+ } & Record<M, () => void>;
5
+
6
+ export function wrapRefcounted<T, M extends string>(t: T, method: M): T {
7
+ const my = t as Refcounted<T, M>;
8
+ my.__refcounted = (my.__refcounted || 0) + 1;
9
+ if (my.__refcounted === 1) {
10
+ my.__unrefcounted = my[method];
11
+ const mRec = my as Record<string, () => void>;
12
+ mRec[method] = function (this: Refcounted<T, M>): void {
13
+ this.__refcounted--;
14
+ if (this.__refcounted === 0) {
15
+ this.__unrefcounted();
16
+ }
17
+ if (this.__refcounted < 0) {
18
+ throw new Error("already closed");
19
+ }
20
+ };
21
+ }
22
+ return t;
23
+ }