@adviser/cement 0.2.36 → 0.2.38

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/node/index.ts","../../../src/node/node-file-service.ts","../../../src/txt-en-decoder.ts","../../../src/time.ts","../../../src/base-sys-abstraction.ts","../../../src/future.ts","../../../src/resolve-once.ts","../../../src/sys-env.ts","../../../src/node/node-sys-abstraction.ts","../../../src/node/deno-sys-abstraction.ts","../../../src/node/deno-file-service.ts","../../../src/node/mock-file-service.ts"],"sourcesContent":["export * from \"./node-file-service.js\";\nexport * from \"./node-sys-abstraction.js\";\nexport * from \"./deno-sys-abstraction.js\";\nexport * from \"./mock-file-service.js\";\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport process from \"node:process\";\nimport { FileService, NamedWritableStream } from \"../file-service.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\n\nexport class NodeFileService implements FileService {\n readonly baseDir: string;\n constructor(baseDir: string = process.cwd()) {\n this.baseDir = this.abs(baseDir);\n }\n\n // nodeImport(fname: string): string {\n // // console.log('nodeImport:'+ fname);\n // if (path.isAbsolute(fname)) {\n // return fname;\n // } else {\n // return \"./\" + path.normalize(fname);\n // }\n // }\n\n readFileString(fname: string): Promise<string> {\n return fs.promises.readFile(fname, { encoding: \"utf-8\" });\n }\n\n dirname(fname: string): string {\n return path.dirname(fname);\n }\n basename(fname: string): string {\n return path.basename(fname);\n }\n\n join(...paths: string[]): string {\n return path.join(...paths);\n }\n\n relative(from: string, to?: string): string {\n if (to === undefined) {\n to = from;\n from = process.cwd();\n }\n const ret = path.relative(from, to);\n // console.log('relative:'+ from + \" -> \" + to + \"= \" + ret);\n return ret;\n }\n\n abs(fname: string): string {\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n const cwd = process.cwd();\n return path.resolve(cwd, fname);\n }\n }\n\n isAbsolute(fname: string): boolean {\n return path.isAbsolute(fname);\n }\n\n async writeFileString(fname: string, content: string, ende: TxtEnDecoder = Utf8EnDecoderSingleton()): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(ende.encode(content));\n await wr.close();\n }\n\n async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!path.isAbsolute(fname)) {\n oName = this.abs(fname);\n }\n\n const base = path.dirname(oName);\n await fs.promises.mkdir(base, { recursive: true });\n const out = fs.createWriteStream(oName);\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk): void {\n out.write(chunk);\n },\n close(): void {\n out.close();\n },\n abort(): void {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n","export interface TxtEnDecoder {\n encode(str: string): Uint8Array;\n decode(data: Uint8Array): string;\n}\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\nexport class Utf8EnDecoder implements TxtEnDecoder {\n encode(str: string): Uint8Array {\n return encoder.encode(str);\n }\n decode(data: Uint8Array): string {\n return decoder.decode(data);\n }\n}\n\nconst utf8EnDecoder = new Utf8EnDecoder();\nexport function Utf8EnDecoderSingleton(): TxtEnDecoder {\n return utf8EnDecoder;\n}\n","export abstract class Time {\n abstract Now(add?: number): Date;\n abstract Sleep(duration: Duration): Promise<void>;\n TimeSince(start: Date): Duration {\n const now = this.Now();\n return now.getTime() - start.getTime();\n }\n}\n\nexport type Duration = number;\n\nexport enum TimeUnits {\n Microsecond = 1,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Second = 1000 * Microsecond,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Minute = 60 * Second,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Hour = 60 * Minute,\n}\n","import { FileService } from \"./file-service.js\";\nimport { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from \"./sys-abstraction.js\";\nimport { Time } from \"./time.js\";\nimport { TxtEnDecoder } from \"./txt-en-decoder.js\";\n\nexport class SysTime extends Time {\n Now(): Date {\n return new Date();\n }\n Sleep(duration: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve();\n }, duration);\n });\n }\n}\n\nexport class ConstTime extends Time {\n Now(): Date {\n return new Date(2021, 1, 1, 0, 0, 0, 0);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Sleep(duration: number): Promise<void> {\n return Promise.resolve();\n }\n}\n\nexport class StepTime extends Time {\n _step: Date;\n readonly _start: Date;\n constructor() {\n super();\n this._step = new ConstTime().Now();\n this._start = this._step;\n }\n Now(steps = 1): Date {\n // if (this._step.getTime() === 0) {\n // this._step = new ConstTime().Now();\n // return this._step;\n // }\n for (let i = 0; steps > 0 && i < steps; i++) {\n this._step = new Date(this._step.getTime() + 1000);\n }\n if (steps < 1) {\n this._step = new Date(this._start.getTime() + steps * -1000);\n }\n // this._step = new Date(this._step.getTime() + 1000);\n return this._step;\n }\n Sleep(duration: number): Promise<void> {\n this._step = new Date(this._step.getTime() + duration);\n return Promise.resolve();\n }\n}\n\nexport function TimeFactory(timeMode: TimeMode): Time {\n switch (timeMode) {\n case TimeMode.REAL:\n return new SysTime();\n case TimeMode.CONST:\n return new ConstTime();\n case TimeMode.STEP:\n return new StepTime();\n }\n return new SysTime();\n}\n\nexport class RandomService {\n readonly _mode: RandomMode;\n _step = 0;\n constructor(mode: RandomMode) {\n this._mode = mode;\n }\n Random0ToValue(value: number): number {\n switch (this._mode) {\n case RandomMode.CONST:\n return 0.5 * value;\n case RandomMode.STEP:\n this._step += 0.0001;\n return this._step * value;\n case RandomMode.RANDOM:\n return Math.random() * value;\n default:\n throw new Error(\"Unknown RandomMode\");\n }\n }\n}\n\nexport class IdService {\n readonly _mode: IDMode;\n _step = 0;\n constructor(mode?: IDMode) {\n if (!mode) {\n mode = IDMode.UUID;\n }\n this._mode = mode;\n }\n NextId(): string {\n switch (this._mode) {\n case IDMode.UUID:\n return crypto.randomUUID();\n case IDMode.CONST:\n return \"VeryUniqueID\";\n case IDMode.STEP:\n return `STEPId-${this._step++}`;\n default:\n throw new Error(\"Unknown IDMode\");\n }\n }\n}\n\nexport interface BaseSysAbstractionParams {\n readonly TxtEnDecoder: TxtEnDecoder;\n readonly FileSystem: FileService;\n readonly SystemService: SystemService;\n}\n\nexport interface ExitHandler {\n readonly hdl: VoidFunc;\n readonly id: string;\n}\n\nexport interface ExitService {\n injectExitHandlers(hdls: ExitHandler[]): void;\n exit(code: number): void;\n}\n\nexport class BaseSysAbstraction {\n readonly _time: SysTime = new SysTime();\n readonly _stdout: WritableStream;\n readonly _stderr: WritableStream;\n\n readonly _idService: IdService = new IdService();\n readonly _randomService: RandomService = new RandomService(RandomMode.RANDOM);\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n readonly _txtEnDe: TxtEnDecoder;\n\n constructor(params: BaseSysAbstractionParams) {\n this._fileSystem = params.FileSystem;\n this._systemService = params.SystemService;\n this._txtEnDe = params.TxtEnDecoder;\n const decoder = this._txtEnDe;\n this._stdout = new WritableStream({\n write(chunk): Promise<void> {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n // eslint-disable-next-line no-console\n console.log(decoded.trimEnd());\n resolve();\n });\n },\n });\n this._stderr = new WritableStream({\n write(chunk): Promise<void> {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n // eslint-disable-next-line no-console\n console.error(decoded.trimEnd());\n resolve();\n });\n },\n });\n }\n}\n\nexport interface WrapperSysAbstractionParams {\n readonly TimeMode?: TimeMode;\n readonly IdMode?: IDMode;\n readonly Stdout?: WritableStream<Uint8Array>;\n readonly Stderr?: WritableStream<Uint8Array>;\n readonly RandomMode?: RandomMode;\n readonly FileSystem?: FileService;\n readonly SystemService?: SystemService;\n readonly TxtEnDecoder?: TxtEnDecoder;\n}\n\nexport class WrapperSysAbstraction implements SysAbstraction {\n readonly _time: Time;\n readonly _stdout: WritableStream<Uint8Array>;\n readonly _stderr: WritableStream<Uint8Array>;\n readonly _idService: IdService;\n readonly _randomService: RandomService;\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n constructor(base: BaseSysAbstraction, params?: WrapperSysAbstractionParams) {\n this._time = base._time;\n this._stdout = base._stdout;\n this._stderr = base._stderr;\n this._idService = base._idService;\n this._randomService = base._randomService;\n this._fileSystem = base._fileSystem;\n this._systemService = base._systemService;\n if (params) {\n if (params.TimeMode) {\n this._time = TimeFactory(params.TimeMode);\n }\n if (params.Stdout) {\n this._stdout = params.Stdout;\n }\n if (params.Stderr) {\n this._stderr = params.Stderr;\n }\n if (params.IdMode) {\n this._idService = new IdService(params.IdMode);\n }\n if (params.RandomMode) {\n this._randomService = new RandomService(params.RandomMode);\n }\n if (params.FileSystem) {\n this._fileSystem = params.FileSystem;\n }\n if (params.SystemService) {\n this._systemService = params.SystemService;\n }\n }\n }\n Time(): Time {\n return this._time;\n }\n NextId(): string {\n return this._idService.NextId();\n }\n Random0ToValue(value: number): number {\n return this._randomService.Random0ToValue(value);\n }\n Stdout(): WritableStream {\n return this._stdout;\n }\n Stderr(): WritableStream {\n return this._stderr;\n }\n\n System(): SystemService {\n return this._systemService;\n }\n FileSystem(): FileService {\n return this._fileSystem;\n }\n}\n// export const BaseSysAbstraction = new BaseSysAbstractionImpl()\n","export class Future<T> {\n readonly #promise: Promise<T>;\n #resolveFn: (value: T) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n #rejectFn: (reason: unknown) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n\n constructor() {\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolveFn = resolve;\n this.#rejectFn = reject;\n });\n }\n\n async asPromise(): Promise<T> {\n return this.#promise;\n }\n\n resolve(value: T): void {\n this.#resolveFn(value);\n }\n reject(reason: unknown): void {\n this.#rejectFn(reason);\n }\n}\n","import { Future } from \"./future.js\";\n\ninterface ResolveSeqItem<T, C> {\n readonly future: Future<T>;\n readonly fn: (c: C) => Promise<T>;\n readonly id?: number;\n}\n\nexport class ResolveSeq<T, C = void> {\n readonly ctx: C;\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n reset(): void {\n /* noop */\n }\n async _step(item?: ResolveSeqItem<T, C> | undefined): Promise<void> {\n if (!item) {\n // done\n return;\n }\n item\n .fn(this.ctx)\n .then((value) => item.future.resolve(value))\n .catch((e) => item.future.reject(e as Error))\n .finally(() => {\n this._seqFutures.shift();\n this._step(this._seqFutures[0]);\n });\n }\n readonly _seqFutures: ResolveSeqItem<T, C>[] = [];\n async add(fn: (c: C) => Promise<T>, id?: number): Promise<T> {\n const future = new Future<T>();\n this._seqFutures.push({ future, fn, id });\n if (this._seqFutures.length === 1) {\n this._step(this._seqFutures[0]);\n }\n return future.asPromise();\n }\n}\n\nexport class ResolveOnce<T, CTX = void> {\n _onceDone = false;\n readonly _onceFutures: Future<T>[] = [];\n _onceOk = false;\n _onceValue?: T;\n _onceError?: Error;\n _isPromise = false;\n\n readonly ctx: CTX;\n\n constructor(ctx?: CTX) {\n this.ctx = ctx as CTX;\n }\n\n get ready(): boolean {\n return this._onceDone;\n }\n\n reset(): void {\n this._onceDone = false;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceError = undefined;\n this._onceFutures.length = 0;\n }\n\n // T extends Option<infer U> ? U : T\n once<R>(fn: (c: CTX) => R): R {\n if (this._onceDone) {\n if (this._onceError) {\n if (this._isPromise) {\n return Promise.reject(this._onceError) as unknown as R;\n } else {\n throw this._onceError;\n }\n }\n if (this._onceOk) {\n if (this._isPromise) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return Promise.resolve(this._onceValue!) as unknown as R;\n } else {\n return this._onceValue as unknown as R;\n }\n }\n throw new Error(\"ResolveOnce.once impossible\");\n }\n const future = new Future<T>();\n this._onceFutures.push(future);\n if (this._onceFutures.length === 1) {\n const okFn = (value: T): void => {\n this._onceValue = value;\n this._onceOk = true;\n this._onceDone = true;\n if (this._isPromise) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.resolve(this._onceValue!));\n }\n this._onceFutures.length = 0;\n };\n const catchFn = (e: Error): void => {\n this._onceError = e as Error;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceDone = true;\n if (this._isPromise) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.reject(this._onceError!));\n }\n this._onceFutures.length = 0;\n };\n try {\n const ret = fn(this.ctx);\n if (typeof (ret as Promise<T>).then === \"function\") {\n this._isPromise = true;\n (ret as Promise<T>).then(okFn).catch(catchFn);\n } else {\n okFn(ret as unknown as T);\n }\n } catch (e) {\n catchFn(e as Error);\n }\n }\n if (this._isPromise) {\n return future.asPromise() as unknown as R;\n } else {\n // abit funky but i don't want to impl the return just once\n return this.once(fn);\n }\n }\n}\n\nexport class Keyed<T extends { reset: () => void }, K = string> {\n private readonly _map = new Map<K, T>();\n\n readonly factory: (key: K) => T;\n constructor(factory: (key: K) => T) {\n this.factory = factory;\n }\n\n async asyncGet(key: () => Promise<K>): Promise<T> {\n return this.get(await key());\n }\n\n get(key: K | (() => K)): T {\n if (typeof key === \"function\") {\n key = (key as () => K)();\n }\n let keyed = this._map.get(key);\n if (!keyed) {\n keyed = this.factory(key);\n this._map.set(key, keyed);\n }\n return keyed;\n }\n\n unget(key: K): void {\n const keyed = this._map.get(key);\n keyed?.reset();\n this._map.delete(key);\n }\n\n reset(): void {\n this._map.forEach((keyed) => keyed.reset());\n this._map.clear();\n }\n}\n\nexport class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {\n constructor() {\n super((key) => new ResolveOnce<T, K>(key));\n }\n}\n\nexport class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {\n constructor() {\n super((key) => new ResolveSeq<T, K>(key));\n }\n}\n","import { ResolveOnce } from \"./resolve-once.js\";\n\nexport interface EnvMap {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n delete(key: string): void;\n keys(): string[];\n}\nexport interface EnvActions extends EnvMap {\n active(): boolean;\n register(env: Env): Env;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n\n register(env: Env): Env {\n return env;\n }\n\n active(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly _env = this.active() ? this.#node.process.env : {};\n keys(): string[] {\n return Object.keys(this._env);\n }\n get(key: string): string | undefined {\n return this._env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this._env[key] = value;\n }\n }\n delete(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n get _env(): Map<string, string> {\n return this.#deno.Deno.env;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n\n register(env: Env): Env {\n return env;\n }\n active(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this._env.keys());\n }\n get(key: string): string | undefined {\n return this._env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this._env.set(key, value);\n }\n }\n delete(key: string): void {\n this._env.delete(key);\n }\n}\n\nexport class BrowserEnvActions implements EnvActions {\n readonly env: Map<string, string> = new Map<string, string>();\n readonly opts: Partial<EnvFactoryOpts>;\n constructor(opts: Partial<EnvFactoryOpts>) {\n this.opts = opts;\n }\n\n get(key: string): string | undefined {\n return this.env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.env.set(key, value);\n }\n }\n delete(key: string): void {\n this.env.delete(key);\n }\n keys(): string[] {\n return Array.from(this.env.keys());\n }\n active(): boolean {\n return true; // that should work on every runtime\n }\n\n register(env: Env): Env {\n const sym = Symbol.for(this.opts.symbol || \"CP_ENV\");\n const browser = globalThis as unknown as Record<symbol, Env>;\n browser[sym] = env;\n return env;\n }\n}\n\nexport interface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends EnvMap {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nconst _envFactory = new ResolveOnce<Env>();\nexport function envFactory(opts: Partial<EnvFactoryOpts> = {}): Env {\n return _envFactory.once(() => {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.active());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n const ret = new EnvImpl(found, opts);\n found.register(ret);\n return ret;\n });\n}\n\nexport class EnvImpl implements Env {\n readonly _map: EnvMap;\n constructor(map: EnvMap, opts: Partial<EnvFactoryOpts> = {}) {\n this._map = map;\n this._updatePresets(opts.presetEnv);\n }\n _updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this._map.set(key, value);\n }\n }\n _applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this._map.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this._map.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly _onSet: OnSetItem[] = [];\n keys(): string[] {\n return this._map.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this._onSet.push(item);\n this._applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this._map.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this._map.set(key, value);\n this._applyOnSet(this._onSet, key, value);\n }\n delete(key: string): void {\n this._map.delete(key);\n this._applyOnSet(this._onSet, key);\n }\n}\n\n// export const envImpl = new EnvImpl();\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys-abstraction.js\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base-sys-abstraction.js\";\nimport { NodeFileService } from \"./node-file-service.js\";\nimport { Env, envFactory } from \"../sys-env.js\";\nimport { Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\nimport process from \"node:process\";\n\nexport class NodeExitServiceImpl implements ExitService {\n constructor() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"unhandledRejection\", (reason: string, p: Promise<unknown>) => {\n this.exit(19);\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"uncaughtException\", (error: Error) => {\n this.exit(18);\n });\n process.on(\"close\", () => {\n this.exit(0);\n });\n process.on(\"exit\", () => {\n this.exit(0);\n });\n process.on(\"SIGQUIT\", () => {\n this.exit(3);\n });\n process.on(\"SIGINT\", () => {\n this.exit(2);\n });\n process.on(\"SIGTERM\", () => {\n this.exit(9);\n });\n }\n _exitHandlers: ExitHandler[] = [];\n injectExitHandlers(hdls: ExitHandler[]): void {\n // console.log(\"ExitService: injecting exit handlers\", hdls)\n this._exitHandlers = hdls;\n }\n invoked = false;\n readonly _handleExit = async (): Promise<void> => {\n if (this.invoked) {\n // console.error(\"ExitService: already invoked\");\n return;\n }\n this.invoked = true;\n for (const h of this._exitHandlers) {\n try {\n // console.log(`ExitService: calling handler ${h.id}`)\n const ret = h.hdl();\n // console.log(`ExitService: called handler ${h.id}`, ret)\n if (typeof (ret as Promise<void>).then === \"function\") {\n await ret;\n }\n } finally {\n // ignore\n }\n }\n };\n\n exit(code: number): void {\n // console.log(\"ExitService: exit called\", code)\n this._handleExit()\n .then(() => {\n process.exit(code);\n })\n .catch((err) => {\n // eslint-disable-next-line no-console\n console.error(\"ExitService: failed to handle exit\", err);\n process.exit(code);\n });\n }\n}\n\nexport class NodeSystemService implements SystemService {\n static readonly _exitHandlers: ExitHandler[] = [];\n readonly _exitService: ExitService = new NodeExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);\n }\n\n Env(): Env {\n return envFactory();\n }\n\n Args(): string[] {\n return process.argv;\n }\n\n OnExit(hdl: VoidFunc): VoidFunc {\n const id = crypto.randomUUID();\n NodeSystemService._exitHandlers.push({ hdl, id });\n return () => {\n const idx = NodeSystemService._exitHandlers.findIndex((h) => h.id === id);\n if (idx >= 0) {\n NodeSystemService._exitHandlers.splice(idx, 1);\n }\n };\n }\n\n Exit(code: number): void {\n this._exitService.exit(code);\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function NodeSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n TxtEnDecoder: param?.TxtEnDecoder || Utf8EnDecoderSingleton(),\n FileSystem: new NodeFileService(),\n SystemService: new NodeSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys-abstraction.js\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base-sys-abstraction.js\";\nimport { Env, envFactory } from \"../sys-env.js\";\nimport { Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\nimport * as process from \"node:process\";\nimport { DenoFileService } from \"./deno-file-service.js\";\n\nconst Deno = (globalThis as unknown as { Deno: unknown }).Deno as {\n addSignalListener(sig: string, hdl: () => void): void;\n exit(code?: number): void;\n};\n\nexport class DenoExitServiceImpl implements ExitService {\n constructor() {\n globalThis.addEventListener(\"unhandledrejection\", (e) => {\n e.preventDefault();\n this.exit(19);\n });\n globalThis.addEventListener(\"error\", () => {\n this.exit(19);\n });\n globalThis.addEventListener(\"uncaughtException\", () => {\n this.exit(19);\n });\n\n // process.on(\"close\", () => {\n // this.exit(0);\n // });\n globalThis.addEventListener(\"unload\", () => {\n this.exit(0);\n // console.log('goodbye!');\n });\n\n // process.on(\"exit\", () => {\n // });\n Deno.addSignalListener(\"SIGQUIT\", () => {\n this.exit(3);\n });\n Deno.addSignalListener(\"SIGINT\", () => {\n this.exit(2);\n });\n Deno.addSignalListener(\"SIGTERM\", () => {\n this.exit(9);\n });\n }\n _exitHandlers: ExitHandler[] = [];\n injectExitHandlers(hdls: ExitHandler[]): void {\n // console.log(\"ExitService: injecting exit handlers\", hdls)\n this._exitHandlers = hdls;\n }\n invoked = false;\n readonly _handleExit = async (): Promise<void> => {\n if (this.invoked) {\n // console.error(\"ExitService: already invoked\");\n return;\n }\n this.invoked = true;\n for (const h of this._exitHandlers) {\n try {\n // console.log(`ExitService: calling handler ${h.id}`)\n const ret = h.hdl();\n // console.log(`ExitService: called handler ${h.id}`, ret)\n if (typeof (ret as Promise<void>).then === \"function\") {\n await ret;\n }\n } finally {\n // ignore\n }\n }\n };\n\n exit(code: number): void {\n // console.log(\"ExitService: exit called\", code)\n this._handleExit()\n .then(() => {\n Deno.exit(code);\n })\n .catch((err) => {\n // eslint-disable-next-line no-console\n console.error(\"ExitService: failed to handle exit\", err);\n Deno.exit(code);\n });\n }\n}\n\nexport class DenoSystemService implements SystemService {\n static readonly _exitHandlers: ExitHandler[] = [];\n readonly _exitService: ExitService = new DenoExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(DenoSystemService._exitHandlers);\n }\n\n Env(): Env {\n return envFactory();\n }\n\n Args(): string[] {\n return process.argv;\n }\n\n OnExit(hdl: VoidFunc): VoidFunc {\n const id = crypto.randomUUID();\n DenoSystemService._exitHandlers.push({ hdl, id });\n return () => {\n const idx = DenoSystemService._exitHandlers.findIndex((h) => h.id === id);\n if (idx >= 0) {\n DenoSystemService._exitHandlers.splice(idx, 1);\n }\n };\n }\n\n Exit(code: number): void {\n this._exitService.exit(code);\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function DenoSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n TxtEnDecoder: param?.TxtEnDecoder || Utf8EnDecoderSingleton(),\n FileSystem: new DenoFileService(),\n SystemService: new DenoSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { FileService, NamedWritableStream } from \"../file-service.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\nimport * as path from \"node:path\";\n\nconst Deno = (globalThis as unknown as { Deno: unknown }).Deno as {\n cwd(): string;\n readFile(fname: string): Promise<Uint8Array>;\n mkdir(base: string, options: { recursive: boolean }): Promise<void>;\n open(fname: string, options: { write: boolean; create: boolean; truncate: boolean }): Promise<WritableStream>;\n};\n\nexport class DenoFileService implements FileService {\n readonly baseDir: string;\n readonly txtEnde: TxtEnDecoder;\n constructor(baseDir: string = Deno.cwd(), txtEnde: TxtEnDecoder = Utf8EnDecoderSingleton()) {\n this.baseDir = this.abs(baseDir);\n this.txtEnde = txtEnde;\n }\n\n // nodeImport(fname: string): string {\n // // console.log('nodeImport:'+ fname);\n // if (path.isAbsolute(fname)) {\n // return fname;\n // } else {\n // return \"./\" + path.normalize(fname);\n // }\n // }\n\n async readFileString(fname: string): Promise<string> {\n return this.txtEnde.decode(await Deno.readFile(fname));\n }\n\n dirname(fname: string): string {\n return path.dirname(fname);\n }\n basename(fname: string): string {\n return path.basename(fname);\n }\n\n join(...paths: string[]): string {\n return path.join(...paths);\n }\n\n relative(from: string, to?: string): string {\n if (to === undefined) {\n to = from;\n from = Deno.cwd();\n }\n const ret = path.relative(from, to);\n // console.log('relative:'+ from + \" -> \" + to + \"= \" + ret);\n return ret;\n }\n\n abs(fname: string): string {\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n const cwd = Deno.cwd();\n return path.resolve(cwd, fname);\n }\n }\n\n isAbsolute(fname: string): boolean {\n return path.isAbsolute(fname);\n }\n\n async writeFileString(fname: string, content: string, ende = Utf8EnDecoderSingleton()): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(ende.encode(content));\n await wr.close();\n }\n\n async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!path.isAbsolute(fname)) {\n oName = this.abs(fname);\n }\n\n const base = path.dirname(oName);\n await Deno.mkdir(base, { recursive: true });\n const out = await Deno.open(oName, {\n write: true,\n create: true,\n truncate: true,\n });\n return {\n name: oName,\n stream: out,\n };\n }\n}\n","import { NamedWritableStream } from \"../file-service.js\";\nimport { NodeFileService } from \"./node-file-service.js\";\n\nexport interface FileCollector {\n readonly name: string;\n content: string;\n}\n\nexport class MockFileService extends NodeFileService {\n readonly files = {} as Record<string, FileCollector>;\n\n // override abs(fname: string): string {\n // return this.join(\"/mock/\", fname);\n // }\n\n override async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!this.isAbsolute(fname)) {\n oName = await this.abs(fname);\n }\n\n const fc = {\n name: oName,\n content: \"\",\n };\n this.files[oName] = fc;\n this.files[fname] = fc;\n const decoder = new TextDecoder();\n\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk): void {\n fc.content = fc.content + decoder.decode(chunk);\n },\n close(): void {\n // do nothing\n },\n abort(): void {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAiB;AACjB,qBAAe;AACf,0B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ACT,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AACA,SAAK,MAAM,KAAK,IAAI;AACpB,SAAK,MAAM,KAAK,IAAI;AACpB,UAAMC,WAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAa;AACjB,aAAG,UAAU,GAAG,UAAUA,SAAQ,OAAO,KAAK;AAAA,QAChD;AAAA,QACA,QAAc;AAAA,QAEd;AAAA,QACA,QAAc;AACZ,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["process","fs","path","resolve","decoder","resolve","import_node_process","process","process","path","Deno","my","decoder"]}
1
+ {"version":3,"sources":["../../../src/node/index.ts","../../../src/node/node-file-service.ts","../../../src/txt-en-decoder.ts","../../../src/time.ts","../../../src/base-sys-abstraction.ts","../../../src/future.ts","../../../src/resolve-once.ts","../../../src/sys-env.ts","../../../src/node/node-sys-abstraction.ts","../../../src/node/deno-sys-abstraction.ts","../../../src/node/deno-file-service.ts","../../../src/node/mock-file-service.ts"],"sourcesContent":["export * from \"./node-file-service.js\";\nexport * from \"./node-sys-abstraction.js\";\nexport * from \"./deno-sys-abstraction.js\";\nexport * from \"./mock-file-service.js\";\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport process from \"node:process\";\nimport { FileService, NamedWritableStream } from \"../file-service.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\n\nexport class NodeFileService implements FileService {\n readonly baseDir: string;\n constructor(baseDir: string = process.cwd()) {\n this.baseDir = this.abs(baseDir);\n }\n\n // nodeImport(fname: string): string {\n // // console.log('nodeImport:'+ fname);\n // if (path.isAbsolute(fname)) {\n // return fname;\n // } else {\n // return \"./\" + path.normalize(fname);\n // }\n // }\n\n readFileString(fname: string): Promise<string> {\n return fs.promises.readFile(fname, { encoding: \"utf-8\" });\n }\n\n dirname(fname: string): string {\n return path.dirname(fname);\n }\n basename(fname: string): string {\n return path.basename(fname);\n }\n\n join(...paths: string[]): string {\n return path.join(...paths);\n }\n\n relative(from: string, to?: string): string {\n if (to === undefined) {\n to = from;\n from = process.cwd();\n }\n const ret = path.relative(from, to);\n // console.log('relative:'+ from + \" -> \" + to + \"= \" + ret);\n return ret;\n }\n\n abs(fname: string): string {\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n const cwd = process.cwd();\n return path.resolve(cwd, fname);\n }\n }\n\n isAbsolute(fname: string): boolean {\n return path.isAbsolute(fname);\n }\n\n async writeFileString(fname: string, content: string, ende: TxtEnDecoder = Utf8EnDecoderSingleton()): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(ende.encode(content));\n await wr.close();\n }\n\n async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!path.isAbsolute(fname)) {\n oName = this.abs(fname);\n }\n\n const base = path.dirname(oName);\n await fs.promises.mkdir(base, { recursive: true });\n const out = fs.createWriteStream(oName);\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk): void {\n out.write(chunk);\n },\n close(): void {\n out.close();\n },\n abort(): void {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n","export interface TxtEnDecoder {\n encode(str: string): Uint8Array;\n decode(data: Uint8Array): string;\n}\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\nexport class Utf8EnDecoder implements TxtEnDecoder {\n encode(str: string): Uint8Array {\n return encoder.encode(str);\n }\n decode(data: Uint8Array): string {\n return decoder.decode(data);\n }\n}\n\nconst utf8EnDecoder = new Utf8EnDecoder();\nexport function Utf8EnDecoderSingleton(): TxtEnDecoder {\n return utf8EnDecoder;\n}\n","export abstract class Time {\n abstract Now(add?: number): Date;\n abstract Sleep(duration: Duration): Promise<void>;\n TimeSince(start: Date): Duration {\n const now = this.Now();\n return now.getTime() - start.getTime();\n }\n}\n\nexport type Duration = number;\n\nexport enum TimeUnits {\n Microsecond = 1,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Second = 1000 * Microsecond,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Minute = 60 * Second,\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Hour = 60 * Minute,\n}\n","import { FileService } from \"./file-service.js\";\nimport { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from \"./sys-abstraction.js\";\nimport { Time } from \"./time.js\";\nimport { TxtEnDecoder } from \"./txt-en-decoder.js\";\n\nexport class SysTime extends Time {\n Now(): Date {\n return new Date();\n }\n Sleep(duration: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve();\n }, duration);\n });\n }\n}\n\nexport class ConstTime extends Time {\n Now(): Date {\n return new Date(2021, 1, 1, 0, 0, 0, 0);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Sleep(duration: number): Promise<void> {\n return Promise.resolve();\n }\n}\n\nexport class StepTime extends Time {\n _step: Date;\n readonly _start: Date;\n constructor() {\n super();\n this._step = new ConstTime().Now();\n this._start = this._step;\n }\n Now(steps = 1): Date {\n // if (this._step.getTime() === 0) {\n // this._step = new ConstTime().Now();\n // return this._step;\n // }\n for (let i = 0; steps > 0 && i < steps; i++) {\n this._step = new Date(this._step.getTime() + 1000);\n }\n if (steps < 1) {\n this._step = new Date(this._start.getTime() + steps * -1000);\n }\n // this._step = new Date(this._step.getTime() + 1000);\n return this._step;\n }\n Sleep(duration: number): Promise<void> {\n this._step = new Date(this._step.getTime() + duration);\n return Promise.resolve();\n }\n}\n\nexport function TimeFactory(timeMode: TimeMode): Time {\n switch (timeMode) {\n case TimeMode.REAL:\n return new SysTime();\n case TimeMode.CONST:\n return new ConstTime();\n case TimeMode.STEP:\n return new StepTime();\n }\n return new SysTime();\n}\n\nexport class RandomService {\n readonly _mode: RandomMode;\n _step = 0;\n constructor(mode: RandomMode) {\n this._mode = mode;\n }\n Random0ToValue(value: number): number {\n switch (this._mode) {\n case RandomMode.CONST:\n return 0.5 * value;\n case RandomMode.STEP:\n this._step += 0.0001;\n return this._step * value;\n case RandomMode.RANDOM:\n return Math.random() * value;\n default:\n throw new Error(\"Unknown RandomMode\");\n }\n }\n}\n\nexport class IdService {\n readonly _mode: IDMode;\n _step = 0;\n constructor(mode?: IDMode) {\n if (!mode) {\n mode = IDMode.UUID;\n }\n this._mode = mode;\n }\n NextId(): string {\n switch (this._mode) {\n case IDMode.UUID:\n return crypto.randomUUID();\n case IDMode.CONST:\n return \"VeryUniqueID\";\n case IDMode.STEP:\n return `STEPId-${this._step++}`;\n default:\n throw new Error(\"Unknown IDMode\");\n }\n }\n}\n\nexport interface BaseSysAbstractionParams {\n readonly TxtEnDecoder: TxtEnDecoder;\n readonly FileSystem: FileService;\n readonly SystemService: SystemService;\n}\n\nexport interface ExitHandler {\n readonly hdl: VoidFunc;\n readonly id: string;\n}\n\nexport interface ExitService {\n injectExitHandlers(hdls: ExitHandler[]): void;\n exit(code: number): void;\n}\n\n// some black magic to make it work with CF workers\nfunction consumeReadableStream(\n reader: ReadableStreamDefaultReader<Uint8Array>,\n writeFn: (chunk: Uint8Array) => Promise<void>,\n): void {\n reader\n .read()\n .then(({ done, value }) => {\n if (done) {\n return;\n }\n writeFn(value)\n .then(() => {\n consumeReadableStream(reader, writeFn);\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\"consumeReadableStream:writeFn\", e);\n });\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\"consumeReadableStream:read\", e);\n });\n}\n\nfunction CFWriteableStream(writeFn: (chunk: Uint8Array) => Promise<void>): WritableStream {\n const ts = new TransformStream();\n consumeReadableStream(ts.readable.getReader(), writeFn);\n return ts.writable;\n}\n\nexport class BaseSysAbstraction {\n readonly _time: SysTime = new SysTime();\n readonly _stdout: WritableStream;\n readonly _stderr: WritableStream;\n\n readonly _idService: IdService = new IdService();\n readonly _randomService: RandomService = new RandomService(RandomMode.RANDOM);\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n readonly _txtEnDe: TxtEnDecoder;\n\n constructor(params: BaseSysAbstractionParams) {\n this._fileSystem = params.FileSystem;\n this._systemService = params.SystemService;\n this._txtEnDe = params.TxtEnDecoder;\n const decoder = this._txtEnDe;\n this._stdout = CFWriteableStream(async (chunk) => {\n const decoded = decoder.decode(chunk);\n // eslint-disable-next-line no-console\n console.log(decoded.trimEnd());\n });\n this._stderr = CFWriteableStream(async (chunk) => {\n const decoded = decoder.decode(chunk);\n // eslint-disable-next-line no-console\n console.error(decoded.trimEnd());\n });\n /* this is not CF worker compatible\n this._stdout = new WritableStream({\n write(chunk): Promise<void> {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n // eslint-disable-next-line no-console\n console.log(decoded.trimEnd());\n resolve();\n });\n },\n });\n this._stderr = new WritableStream({\n write(chunk): Promise<void> {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n // eslint-disable-next-line no-console\n console.error(decoded.trimEnd());\n resolve();\n });\n },\n });\n */\n }\n}\n\nexport interface WrapperSysAbstractionParams {\n readonly TimeMode?: TimeMode;\n readonly IdMode?: IDMode;\n readonly Stdout?: WritableStream<Uint8Array>;\n readonly Stderr?: WritableStream<Uint8Array>;\n readonly RandomMode?: RandomMode;\n readonly FileSystem?: FileService;\n readonly SystemService?: SystemService;\n readonly TxtEnDecoder?: TxtEnDecoder;\n}\n\nexport class WrapperSysAbstraction implements SysAbstraction {\n readonly _time: Time;\n readonly _stdout: WritableStream<Uint8Array>;\n readonly _stderr: WritableStream<Uint8Array>;\n readonly _idService: IdService;\n readonly _randomService: RandomService;\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n constructor(base: BaseSysAbstraction, params?: WrapperSysAbstractionParams) {\n this._time = base._time;\n this._stdout = base._stdout;\n this._stderr = base._stderr;\n this._idService = base._idService;\n this._randomService = base._randomService;\n this._fileSystem = base._fileSystem;\n this._systemService = base._systemService;\n if (params) {\n if (params.TimeMode) {\n this._time = TimeFactory(params.TimeMode);\n }\n if (params.Stdout) {\n this._stdout = params.Stdout;\n }\n if (params.Stderr) {\n this._stderr = params.Stderr;\n }\n if (params.IdMode) {\n this._idService = new IdService(params.IdMode);\n }\n if (params.RandomMode) {\n this._randomService = new RandomService(params.RandomMode);\n }\n if (params.FileSystem) {\n this._fileSystem = params.FileSystem;\n }\n if (params.SystemService) {\n this._systemService = params.SystemService;\n }\n }\n }\n Time(): Time {\n return this._time;\n }\n NextId(): string {\n return this._idService.NextId();\n }\n Random0ToValue(value: number): number {\n return this._randomService.Random0ToValue(value);\n }\n Stdout(): WritableStream {\n return this._stdout;\n }\n Stderr(): WritableStream {\n return this._stderr;\n }\n\n System(): SystemService {\n return this._systemService;\n }\n FileSystem(): FileService {\n return this._fileSystem;\n }\n}\n// export const BaseSysAbstraction = new BaseSysAbstractionImpl()\n","export class Future<T> {\n readonly #promise: Promise<T>;\n #resolveFn: (value: T) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n #rejectFn: (reason: unknown) => void = () => {\n throw new Error(\"This Promise is not working as expected.\");\n };\n\n constructor() {\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolveFn = resolve;\n this.#rejectFn = reject;\n });\n }\n\n async asPromise(): Promise<T> {\n return this.#promise;\n }\n\n resolve(value: T): void {\n this.#resolveFn(value);\n }\n reject(reason: unknown): void {\n this.#rejectFn(reason);\n }\n}\n","import { Future } from \"./future.js\";\n\ninterface ResolveSeqItem<T, C> {\n readonly future: Future<T>;\n readonly fn: (c: C) => Promise<T>;\n readonly id?: number;\n}\n\nexport class ResolveSeq<T, C = void> {\n readonly ctx: C;\n constructor(ctx?: C) {\n this.ctx = ctx as C;\n }\n reset(): void {\n /* noop */\n }\n async _step(item?: ResolveSeqItem<T, C> | undefined): Promise<void> {\n if (!item) {\n // done\n return;\n }\n item\n .fn(this.ctx)\n .then((value) => item.future.resolve(value))\n .catch((e) => item.future.reject(e as Error))\n .finally(() => {\n this._seqFutures.shift();\n this._step(this._seqFutures[0]);\n });\n }\n readonly _seqFutures: ResolveSeqItem<T, C>[] = [];\n async add(fn: (c: C) => Promise<T>, id?: number): Promise<T> {\n const future = new Future<T>();\n this._seqFutures.push({ future, fn, id });\n if (this._seqFutures.length === 1) {\n this._step(this._seqFutures[0]);\n }\n return future.asPromise();\n }\n}\n\nexport class ResolveOnce<T, CTX = void> {\n _onceDone = false;\n readonly _onceFutures: Future<T>[] = [];\n _onceOk = false;\n _onceValue?: T;\n _onceError?: Error;\n _isPromise = false;\n\n readonly ctx: CTX;\n\n constructor(ctx?: CTX) {\n this.ctx = ctx as CTX;\n }\n\n get ready(): boolean {\n return this._onceDone;\n }\n\n reset(): void {\n this._onceDone = false;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceError = undefined;\n this._onceFutures.length = 0;\n }\n\n // T extends Option<infer U> ? U : T\n once<R>(fn: (c: CTX) => R): R {\n if (this._onceDone) {\n if (this._onceError) {\n if (this._isPromise) {\n return Promise.reject(this._onceError) as unknown as R;\n } else {\n throw this._onceError;\n }\n }\n if (this._onceOk) {\n if (this._isPromise) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return Promise.resolve(this._onceValue!) as unknown as R;\n } else {\n return this._onceValue as unknown as R;\n }\n }\n throw new Error(\"ResolveOnce.once impossible\");\n }\n const future = new Future<T>();\n this._onceFutures.push(future);\n if (this._onceFutures.length === 1) {\n const okFn = (value: T): void => {\n this._onceValue = value;\n this._onceOk = true;\n this._onceDone = true;\n if (this._isPromise) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.resolve(this._onceValue!));\n }\n this._onceFutures.length = 0;\n };\n const catchFn = (e: Error): void => {\n this._onceError = e as Error;\n this._onceOk = false;\n this._onceValue = undefined;\n this._onceDone = true;\n if (this._isPromise) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._onceFutures.forEach((f) => f.reject(this._onceError!));\n }\n this._onceFutures.length = 0;\n };\n try {\n const ret = fn(this.ctx);\n if (typeof (ret as Promise<T>).then === \"function\") {\n this._isPromise = true;\n (ret as Promise<T>).then(okFn).catch(catchFn);\n } else {\n okFn(ret as unknown as T);\n }\n } catch (e) {\n catchFn(e as Error);\n }\n }\n if (this._isPromise) {\n return future.asPromise() as unknown as R;\n } else {\n // abit funky but i don't want to impl the return just once\n return this.once(fn);\n }\n }\n}\n\nexport class Keyed<T extends { reset: () => void }, K = string> {\n private readonly _map = new Map<K, T>();\n\n readonly factory: (key: K) => T;\n constructor(factory: (key: K) => T) {\n this.factory = factory;\n }\n\n async asyncGet(key: () => Promise<K>): Promise<T> {\n return this.get(await key());\n }\n\n get(key: K | (() => K)): T {\n if (typeof key === \"function\") {\n key = (key as () => K)();\n }\n let keyed = this._map.get(key);\n if (!keyed) {\n keyed = this.factory(key);\n this._map.set(key, keyed);\n }\n return keyed;\n }\n\n unget(key: K): void {\n const keyed = this._map.get(key);\n keyed?.reset();\n this._map.delete(key);\n }\n\n reset(): void {\n this._map.forEach((keyed) => keyed.reset());\n this._map.clear();\n }\n}\n\nexport class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K> {\n constructor() {\n super((key) => new ResolveOnce<T, K>(key));\n }\n}\n\nexport class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {\n constructor() {\n super((key) => new ResolveSeq<T, K>(key));\n }\n}\n","import { ResolveOnce } from \"./resolve-once.js\";\n\nexport interface EnvMap {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n delete(key: string): void;\n keys(): string[];\n}\nexport interface EnvActions extends EnvMap {\n active(): boolean;\n register(env: Env): Env;\n}\n\nclass NodeEnvActions implements EnvActions {\n readonly #node = globalThis as unknown as { process: { env: Record<string, string> } };\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n\n register(env: Env): Env {\n return env;\n }\n\n active(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly _env = this.active() ? this.#node.process.env : {};\n keys(): string[] {\n return Object.keys(this._env);\n }\n get(key: string): string | undefined {\n return this._env[key];\n }\n set(key: string, value?: string): void {\n if (value) {\n this._env[key] = value;\n }\n }\n delete(key: string): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._env[key];\n }\n}\n\nclass DenoEnvActions implements EnvActions {\n readonly #deno = globalThis as unknown as { Deno: { env: Map<string, string> } };\n\n get _env(): Map<string, string> {\n return this.#deno.Deno.env;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars\n constructor(opts: Partial<EnvFactoryOpts>) {\n // do nothing\n }\n\n register(env: Env): Env {\n return env;\n }\n active(): boolean {\n return typeof this.#deno === \"object\" && typeof this.#deno.Deno === \"object\" && typeof this.#deno.Deno.env === \"object\";\n }\n keys(): string[] {\n return Array.from(this._env.keys());\n }\n get(key: string): string | undefined {\n return this._env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this._env.set(key, value);\n }\n }\n delete(key: string): void {\n this._env.delete(key);\n }\n}\n\nexport class BrowserEnvActions implements EnvActions {\n readonly env: Map<string, string> = new Map<string, string>();\n readonly opts: Partial<EnvFactoryOpts>;\n constructor(opts: Partial<EnvFactoryOpts>) {\n this.opts = opts;\n }\n\n get(key: string): string | undefined {\n return this.env.get(key);\n }\n set(key: string, value?: string): void {\n if (value) {\n this.env.set(key, value);\n }\n }\n delete(key: string): void {\n this.env.delete(key);\n }\n keys(): string[] {\n return Array.from(this.env.keys());\n }\n active(): boolean {\n return true; // that should work on every runtime\n }\n\n register(env: Env): Env {\n const sym = Symbol.for(this.opts.symbol || \"CP_ENV\");\n const browser = globalThis as unknown as Record<symbol, Env>;\n browser[sym] = env;\n return env;\n }\n}\n\nexport interface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\ntype OnSetFn = (key: string, value?: string) => void;\nexport interface OnSetItem {\n readonly filter: Set<string>;\n readonly fn: OnSetFn;\n}\n\nexport interface Env extends EnvMap {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nconst _envFactory = new ResolveOnce<Env>();\nexport function envFactory(opts: Partial<EnvFactoryOpts> = {}): Env {\n return _envFactory.once(() => {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.active());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n const ret = new EnvImpl(found, opts);\n found.register(ret);\n return ret;\n });\n}\n\nexport class EnvImpl implements Env {\n readonly _map: EnvMap;\n constructor(map: EnvMap, opts: Partial<EnvFactoryOpts> = {}) {\n this._map = map;\n this._updatePresets(opts.presetEnv);\n }\n _updatePresets(presetEnv?: Map<string, string>): void {\n if (!presetEnv) {\n return;\n }\n for (const [key, value] of presetEnv) {\n this._map.set(key, value);\n }\n }\n _applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void {\n onSet.forEach((item) => {\n let keys: string[] = [];\n if (key) {\n keys = [key];\n } else {\n keys = this._map.keys();\n }\n keys\n .filter((k) => {\n if (item.filter.size === 0) {\n return true;\n }\n if (item.filter.has(k)) {\n return true;\n }\n return false;\n })\n .forEach((k) => {\n let v;\n if (!key && !value) {\n // init\n v = this._map.get(k);\n } else if (key && !value) {\n // del\n v = undefined;\n } else {\n // set\n v = value;\n }\n item.fn(k, v);\n });\n });\n }\n readonly _onSet: OnSetItem[] = [];\n keys(): string[] {\n return this._map.keys();\n }\n // filter is not set all sets passed\n onSet(fn: OnSetFn, ...filter: string[]): void {\n const item: OnSetItem = { filter: new Set(filter), fn };\n this._onSet.push(item);\n this._applyOnSet([item]);\n }\n get(key: string): string | undefined {\n return this._map.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this._map.set(key, value);\n this._applyOnSet(this._onSet, key, value);\n }\n delete(key: string): void {\n this._map.delete(key);\n this._applyOnSet(this._onSet, key);\n }\n}\n\n// export const envImpl = new EnvImpl();\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys-abstraction.js\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base-sys-abstraction.js\";\nimport { NodeFileService } from \"./node-file-service.js\";\nimport { Env, envFactory } from \"../sys-env.js\";\nimport { Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\nimport process from \"node:process\";\n\nexport class NodeExitServiceImpl implements ExitService {\n constructor() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"unhandledRejection\", (reason: string, p: Promise<unknown>) => {\n this.exit(19);\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n process.on(\"uncaughtException\", (error: Error) => {\n this.exit(18);\n });\n process.on(\"close\", () => {\n this.exit(0);\n });\n process.on(\"exit\", () => {\n this.exit(0);\n });\n process.on(\"SIGQUIT\", () => {\n this.exit(3);\n });\n process.on(\"SIGINT\", () => {\n this.exit(2);\n });\n process.on(\"SIGTERM\", () => {\n this.exit(9);\n });\n }\n _exitHandlers: ExitHandler[] = [];\n injectExitHandlers(hdls: ExitHandler[]): void {\n // console.log(\"ExitService: injecting exit handlers\", hdls)\n this._exitHandlers = hdls;\n }\n invoked = false;\n readonly _handleExit = async (): Promise<void> => {\n if (this.invoked) {\n // console.error(\"ExitService: already invoked\");\n return;\n }\n this.invoked = true;\n for (const h of this._exitHandlers) {\n try {\n // console.log(`ExitService: calling handler ${h.id}`)\n const ret = h.hdl();\n // console.log(`ExitService: called handler ${h.id}`, ret)\n if (typeof (ret as Promise<void>).then === \"function\") {\n await ret;\n }\n } finally {\n // ignore\n }\n }\n };\n\n exit(code: number): void {\n // console.log(\"ExitService: exit called\", code)\n this._handleExit()\n .then(() => {\n process.exit(code);\n })\n .catch((err) => {\n // eslint-disable-next-line no-console\n console.error(\"ExitService: failed to handle exit\", err);\n process.exit(code);\n });\n }\n}\n\nexport class NodeSystemService implements SystemService {\n static readonly _exitHandlers: ExitHandler[] = [];\n readonly _exitService: ExitService = new NodeExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);\n }\n\n Env(): Env {\n return envFactory();\n }\n\n Args(): string[] {\n return process.argv;\n }\n\n OnExit(hdl: VoidFunc): VoidFunc {\n const id = crypto.randomUUID();\n NodeSystemService._exitHandlers.push({ hdl, id });\n return () => {\n const idx = NodeSystemService._exitHandlers.findIndex((h) => h.id === id);\n if (idx >= 0) {\n NodeSystemService._exitHandlers.splice(idx, 1);\n }\n };\n }\n\n Exit(code: number): void {\n this._exitService.exit(code);\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function NodeSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n TxtEnDecoder: param?.TxtEnDecoder || Utf8EnDecoderSingleton(),\n FileSystem: new NodeFileService(),\n SystemService: new NodeSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys-abstraction.js\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base-sys-abstraction.js\";\nimport { Env, envFactory } from \"../sys-env.js\";\nimport { Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\nimport * as process from \"node:process\";\nimport { DenoFileService } from \"./deno-file-service.js\";\n\nconst Deno = (globalThis as unknown as { Deno: unknown }).Deno as {\n addSignalListener(sig: string, hdl: () => void): void;\n exit(code?: number): void;\n};\n\nexport class DenoExitServiceImpl implements ExitService {\n constructor() {\n globalThis.addEventListener(\"unhandledrejection\", (e) => {\n e.preventDefault();\n this.exit(19);\n });\n globalThis.addEventListener(\"error\", () => {\n this.exit(19);\n });\n globalThis.addEventListener(\"uncaughtException\", () => {\n this.exit(19);\n });\n\n // process.on(\"close\", () => {\n // this.exit(0);\n // });\n globalThis.addEventListener(\"unload\", () => {\n this.exit(0);\n // console.log('goodbye!');\n });\n\n // process.on(\"exit\", () => {\n // });\n Deno.addSignalListener(\"SIGQUIT\", () => {\n this.exit(3);\n });\n Deno.addSignalListener(\"SIGINT\", () => {\n this.exit(2);\n });\n Deno.addSignalListener(\"SIGTERM\", () => {\n this.exit(9);\n });\n }\n _exitHandlers: ExitHandler[] = [];\n injectExitHandlers(hdls: ExitHandler[]): void {\n // console.log(\"ExitService: injecting exit handlers\", hdls)\n this._exitHandlers = hdls;\n }\n invoked = false;\n readonly _handleExit = async (): Promise<void> => {\n if (this.invoked) {\n // console.error(\"ExitService: already invoked\");\n return;\n }\n this.invoked = true;\n for (const h of this._exitHandlers) {\n try {\n // console.log(`ExitService: calling handler ${h.id}`)\n const ret = h.hdl();\n // console.log(`ExitService: called handler ${h.id}`, ret)\n if (typeof (ret as Promise<void>).then === \"function\") {\n await ret;\n }\n } finally {\n // ignore\n }\n }\n };\n\n exit(code: number): void {\n // console.log(\"ExitService: exit called\", code)\n this._handleExit()\n .then(() => {\n Deno.exit(code);\n })\n .catch((err) => {\n // eslint-disable-next-line no-console\n console.error(\"ExitService: failed to handle exit\", err);\n Deno.exit(code);\n });\n }\n}\n\nexport class DenoSystemService implements SystemService {\n static readonly _exitHandlers: ExitHandler[] = [];\n readonly _exitService: ExitService = new DenoExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(DenoSystemService._exitHandlers);\n }\n\n Env(): Env {\n return envFactory();\n }\n\n Args(): string[] {\n return process.argv;\n }\n\n OnExit(hdl: VoidFunc): VoidFunc {\n const id = crypto.randomUUID();\n DenoSystemService._exitHandlers.push({ hdl, id });\n return () => {\n const idx = DenoSystemService._exitHandlers.findIndex((h) => h.id === id);\n if (idx >= 0) {\n DenoSystemService._exitHandlers.splice(idx, 1);\n }\n };\n }\n\n Exit(code: number): void {\n this._exitService.exit(code);\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function DenoSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n TxtEnDecoder: param?.TxtEnDecoder || Utf8EnDecoderSingleton(),\n FileSystem: new DenoFileService(),\n SystemService: new DenoSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { FileService, NamedWritableStream } from \"../file-service.js\";\nimport { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\nimport * as path from \"node:path\";\n\nconst Deno = (globalThis as unknown as { Deno: unknown }).Deno as {\n cwd(): string;\n readFile(fname: string): Promise<Uint8Array>;\n mkdir(base: string, options: { recursive: boolean }): Promise<void>;\n open(fname: string, options: { write: boolean; create: boolean; truncate: boolean }): Promise<WritableStream>;\n};\n\nexport class DenoFileService implements FileService {\n readonly baseDir: string;\n readonly txtEnde: TxtEnDecoder;\n constructor(baseDir: string = Deno.cwd(), txtEnde: TxtEnDecoder = Utf8EnDecoderSingleton()) {\n this.baseDir = this.abs(baseDir);\n this.txtEnde = txtEnde;\n }\n\n // nodeImport(fname: string): string {\n // // console.log('nodeImport:'+ fname);\n // if (path.isAbsolute(fname)) {\n // return fname;\n // } else {\n // return \"./\" + path.normalize(fname);\n // }\n // }\n\n async readFileString(fname: string): Promise<string> {\n return this.txtEnde.decode(await Deno.readFile(fname));\n }\n\n dirname(fname: string): string {\n return path.dirname(fname);\n }\n basename(fname: string): string {\n return path.basename(fname);\n }\n\n join(...paths: string[]): string {\n return path.join(...paths);\n }\n\n relative(from: string, to?: string): string {\n if (to === undefined) {\n to = from;\n from = Deno.cwd();\n }\n const ret = path.relative(from, to);\n // console.log('relative:'+ from + \" -> \" + to + \"= \" + ret);\n return ret;\n }\n\n abs(fname: string): string {\n if (path.isAbsolute(fname)) {\n return fname;\n } else {\n const cwd = Deno.cwd();\n return path.resolve(cwd, fname);\n }\n }\n\n isAbsolute(fname: string): boolean {\n return path.isAbsolute(fname);\n }\n\n async writeFileString(fname: string, content: string, ende = Utf8EnDecoderSingleton()): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(ende.encode(content));\n await wr.close();\n }\n\n async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!path.isAbsolute(fname)) {\n oName = this.abs(fname);\n }\n\n const base = path.dirname(oName);\n await Deno.mkdir(base, { recursive: true });\n const out = await Deno.open(oName, {\n write: true,\n create: true,\n truncate: true,\n });\n return {\n name: oName,\n stream: out,\n };\n }\n}\n","import { NamedWritableStream } from \"../file-service.js\";\nimport { NodeFileService } from \"./node-file-service.js\";\n\nexport interface FileCollector {\n readonly name: string;\n content: string;\n}\n\nexport class MockFileService extends NodeFileService {\n readonly files = {} as Record<string, FileCollector>;\n\n // override abs(fname: string): string {\n // return this.join(\"/mock/\", fname);\n // }\n\n override async create(fname: string): Promise<NamedWritableStream> {\n let oName = fname;\n if (!this.isAbsolute(fname)) {\n oName = await this.abs(fname);\n }\n\n const fc = {\n name: oName,\n content: \"\",\n };\n this.files[oName] = fc;\n this.files[fname] = fc;\n const decoder = new TextDecoder();\n\n return {\n name: oName,\n stream: new WritableStream<Uint8Array>({\n write(chunk): void {\n fc.content = fc.content + decoder.decode(chunk);\n },\n close(): void {\n // do nothing\n },\n abort(): void {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAiB;AACjB,qBAAe;AACf,0BAAoB;;;ACGpB,IAAM,UAAU,IAAI,YAAY;AAChC,IAAM,UAAU,IAAI,YAAY;AAEzB,IAAM,gBAAN,MAA4C;AAAA,EACjD,OAAO,KAAyB;AAC9B,WAAO,QAAQ,OAAO,GAAG;AAAA,EAC3B;A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Q;AACZ,QAAI,CAAC,KAAK,WAAW,KAAK,GAAG;AAC3B,cAAQ,MAAM,KAAK,IAAI,KAAK;AAAA,IAC9B;AAEA,UAAM,KAAK;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AACA,SAAK,MAAM,KAAK,IAAI;AACpB,SAAK,MAAM,KAAK,IAAI;AACpB,UAAMC,WAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAa;AACjB,aAAG,UAAU,GAAG,UAAUA,SAAQ,OAAO,KAAK;AAAA,QAChD;AAAA,QACA,QAAc;AAAA,QAEd;AAAA,QACA,QAAc;AACZ,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["process","fs","path","resolve","decoder","resolve","import_node_process","process","process","path","Deno","my","decoder"]}
package/node/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  BaseSysAbstraction,
3
3
  WrapperSysAbstraction,
4
4
  envFactory
5
- } from "../chunk-Q65HLCNL.js";
5
+ } from "../chunk-F5W6VELE.js";
6
6
  import {
7
7
  Utf8EnDecoderSingleton
8
8
  } from "../chunk-GES3MUGV.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adviser/cement",
3
- "version": "0.2.36",
3
+ "version": "0.2.38",
4
4
  "description": "better try/catch/finally handling",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -49,7 +49,7 @@
49
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.11.1",
52
+ "eslint": "9.14.0",
53
53
  "prettier": "^3.3.3",
54
54
  "tsup": "^8.3.0",
55
55
  "tsx": "^4.19.1",
@@ -126,6 +126,38 @@ export interface ExitService {
126
126
  exit(code: number): void;
127
127
  }
128
128
 
129
+ // some black magic to make it work with CF workers
130
+ function consumeReadableStream(
131
+ reader: ReadableStreamDefaultReader<Uint8Array>,
132
+ writeFn: (chunk: Uint8Array) => Promise<void>,
133
+ ): void {
134
+ reader
135
+ .read()
136
+ .then(({ done, value }) => {
137
+ if (done) {
138
+ return;
139
+ }
140
+ writeFn(value)
141
+ .then(() => {
142
+ consumeReadableStream(reader, writeFn);
143
+ })
144
+ .catch((e) => {
145
+ // eslint-disable-next-line no-console
146
+ console.error("consumeReadableStream:writeFn", e);
147
+ });
148
+ })
149
+ .catch((e) => {
150
+ // eslint-disable-next-line no-console
151
+ console.error("consumeReadableStream:read", e);
152
+ });
153
+ }
154
+
155
+ function CFWriteableStream(writeFn: (chunk: Uint8Array) => Promise<void>): WritableStream {
156
+ const ts = new TransformStream();
157
+ consumeReadableStream(ts.readable.getReader(), writeFn);
158
+ return ts.writable;
159
+ }
160
+
129
161
  export class BaseSysAbstraction {
130
162
  readonly _time: SysTime = new SysTime();
131
163
  readonly _stdout: WritableStream;
@@ -142,6 +174,17 @@ export class BaseSysAbstraction {
142
174
  this._systemService = params.SystemService;
143
175
  this._txtEnDe = params.TxtEnDecoder;
144
176
  const decoder = this._txtEnDe;
177
+ this._stdout = CFWriteableStream(async (chunk) => {
178
+ const decoded = decoder.decode(chunk);
179
+ // eslint-disable-next-line no-console
180
+ console.log(decoded.trimEnd());
181
+ });
182
+ this._stderr = CFWriteableStream(async (chunk) => {
183
+ const decoded = decoder.decode(chunk);
184
+ // eslint-disable-next-line no-console
185
+ console.error(decoded.trimEnd());
186
+ });
187
+ /* this is not CF worker compatible
145
188
  this._stdout = new WritableStream({
146
189
  write(chunk): Promise<void> {
147
190
  return new Promise((resolve) => {
@@ -162,6 +205,7 @@ export class BaseSysAbstraction {
162
205
  });
163
206
  },
164
207
  });
208
+ */
165
209
  }
166
210
  }
167
211
 
package/src/jsr.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adviser/cement",
3
- "version": "0.2.36",
3
+ "version": "0.2.38",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./web": "./web/index.ts",
@@ -9,7 +9,7 @@ export class LogWriterStream {
9
9
  write(encoded: Uint8Array): void {
10
10
  const my = async (): Promise<void> => {
11
11
  // const val = Math.random();
12
- // console.log(">>>My:", val)
12
+ // console.log(">>>My:", encoded)
13
13
  try {
14
14
  const writer = this._out.getWriter();
15
15
  await writer.ready;
@@ -17,6 +17,7 @@ import {
17
17
  LevelHandler,
18
18
  LogFormatter,
19
19
  LogValueArg,
20
+ HttpType,
20
21
  } from "./logger.js";
21
22
  import { WebSysAbstraction } from "./web/web-sys-abstraction.js";
22
23
  import { SysAbstraction } from "./sys-abstraction.js";
@@ -271,19 +272,33 @@ export class LoggerImpl implements Logger {
271
272
  return this;
272
273
  }
273
274
 
274
- Http(res: Response | Result<Response>, req?: Request, key?: string): Logger {
275
- if (Result.Is(res)) {
276
- if (res.isErr()) {
277
- this.Err(res.Err());
278
- return this;
279
- }
280
- res = res.Ok();
275
+ Http(...mix: (HttpType | string)[]): Logger {
276
+ const key: string | undefined = mix.find((x) => typeof x === "string");
277
+ mix = mix.filter((x) => typeof x !== "string");
278
+ const resErrors = mix.filter((x) => Result.Is(x) && x.isErr()) as Result<unknown, Error>[];
279
+ if (resErrors.length) {
280
+ this.Err(resErrors.map((x) => x.Err().message).join("\n"));
281
+ return this;
282
+ }
283
+ const req = mix
284
+ .map((reqOrResult) => (Result.Is(reqOrResult) ? reqOrResult.Ok() : reqOrResult))
285
+ .find((req) => typeof (req as Response).status !== "number") as Request | undefined;
286
+ const res = mix
287
+ .map((resOrResult) => (Result.Is(resOrResult) ? resOrResult.Ok() : resOrResult))
288
+ .find((res) => typeof (res as Response).status === "number") as Response | undefined;
289
+ let reqAndOrres: { res: Response; req: Request } | Response | Request | undefined;
290
+ if (res && req) {
291
+ reqAndOrres = { res, req };
292
+ } else if (!res && !req) {
293
+ reqAndOrres = undefined;
294
+ } else if (res) {
295
+ reqAndOrres = res;
296
+ } else if (req) {
297
+ reqAndOrres = req;
281
298
  }
282
- let reqRes: Response | { res: Response; req: Request } = res;
283
- if (req) {
284
- reqRes = { res, req };
299
+ if (reqAndOrres) {
300
+ this.Any(key || "Http", reqAndOrres as unknown as LogSerializable);
285
301
  }
286
- this.Any(key || "Http", reqRes as unknown as LogSerializable);
287
302
  return this;
288
303
  }
289
304
  Pair(x: Record<string, unknown>): Logger {
@@ -464,8 +479,8 @@ class WithLoggerBuilder implements WithLogger {
464
479
  return this;
465
480
  }
466
481
 
467
- Http(res: Response | Result<Response>, req?: Request, key?: string): WithLogger {
468
- this._li.Http(res, req, key);
482
+ Http(...mix: (HttpType | string)[]): WithLogger {
483
+ this._li.Http(...mix);
469
484
  return this;
470
485
  }
471
486
  Pair(x: Record<string, unknown>): WithLogger {
package/src/logger.ts CHANGED
@@ -78,7 +78,16 @@ export function logValue(val: LogValueArg, state: Set<unknown> = new Set<unknown
78
78
  return new LogValue(() => "null");
79
79
  }
80
80
  if (ArrayBuffer.isView(val)) {
81
- return logValue(bin2string(val, 512));
81
+ try {
82
+ // should be injected
83
+ const decoder = new TextDecoder();
84
+ const asStr = decoder.decode(val);
85
+ const obj = JSON.parse(asStr);
86
+ return logValue(obj, state);
87
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
88
+ } catch (e) {
89
+ return logValue(bin2string(val, 512));
90
+ }
82
91
  }
83
92
  if (Array.isArray(val)) {
84
93
  return new LogValue(() => (val as Serialized[]).map((v) => logValue(v).value() as Serialized));
@@ -153,6 +162,8 @@ export interface LevelHandler {
153
162
  isEnabled(ilevel: unknown, module: unknown): boolean;
154
163
  }
155
164
 
165
+ export type HttpType = Response | Result<Response> | Request | Result<Request>;
166
+
156
167
  export interface LoggerInterface<R> {
157
168
  TxtEnDe(): TxtEnDecoder;
158
169
  Module(key: string): R;
@@ -181,7 +192,10 @@ export interface LoggerInterface<R> {
181
192
  Bool<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
182
193
  Any<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
183
194
 
184
- Http(res: Response | Result<Response>, req?: Request, key?: string): R;
195
+ // first string is the key
196
+ // first response is Response
197
+ // first request is Request
198
+ Http(...mix: (HttpType | string)[]): R;
185
199
  Pair(x: Record<string, unknown>): R;
186
200
 
187
201
  Error(): R;
package/src/uri.ts CHANGED
@@ -5,6 +5,23 @@ type NullOrUndef = null | undefined;
5
5
 
6
6
  type OneKey<K extends string, V = string> = Record<K, V>;
7
7
 
8
+ export type MsgFn = (...keys: string[]) => string;
9
+ /*
10
+ if KeyParam is a Object
11
+ if the right side is a string, it is the default value
12
+ if the right side is a !string, it is required
13
+ */
14
+ export type KeysParam = (string | MsgFn | Record<string, unknown>)[];
15
+
16
+ // type ReturnType<T extends (...args: KeysParam) => unknown> = T extends (...args: KeysParam) => infer R ? R : unknown;
17
+
18
+ // function fetchData<T extends (...args: any[]) => Promise<any>>(fn: T): ReturnType<T> {
19
+ // return fn();
20
+ // }
21
+ // type ReturnObject<T extends KeysParam> = {
22
+ // [K in keyof T]: string;
23
+ // };
24
+
8
25
  export interface URIInterface<R extends URIInterface<R>> {
9
26
  // readonly hostname: string;
10
27
  // readonly port: string;
@@ -16,7 +33,7 @@ export interface URIInterface<R extends URIInterface<R>> {
16
33
  hasParam(key: string): boolean;
17
34
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
18
35
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
19
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
36
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
20
37
  clone(): R;
21
38
  asURL(): URL;
22
39
  toString(): string;
@@ -237,11 +254,8 @@ function getParamResult(
237
254
  return Result.Ok(val);
238
255
  }
239
256
 
240
- type msgFn = (...keys: string[]) => string;
241
- type keysParam = (string | msgFn | Record<string, string>)[];
242
-
243
257
  function getParamsResult(
244
- keys: keysParam,
258
+ keys: KeysParam,
245
259
  getParam: { getParam: (key: string) => string | undefined },
246
260
  ): Result<Record<string, string>> {
247
261
  const keyDef = keys.flat().reduce(
@@ -249,7 +263,7 @@ function getParamsResult(
249
263
  if (typeof i === "string") {
250
264
  acc.push({ key: i });
251
265
  } else if (typeof i === "object") {
252
- acc.push(...Object.keys(i).map((k) => ({ key: k, def: i[k] })));
266
+ acc.push(...Object.keys(i).map((k) => ({ key: k, def: typeof i[k] === "string" ? i[k] : undefined })));
253
267
  }
254
268
  return acc;
255
269
  },
@@ -267,7 +281,7 @@ function getParamsResult(
267
281
  for (const kd of keyDef) {
268
282
  const val = getParam.getParam(kd.key);
269
283
  if (val === undefined) {
270
- if (kd.def) {
284
+ if (typeof kd.def === "string") {
271
285
  result[kd.key] = kd.def;
272
286
  } else {
273
287
  errors.push(kd.key);
@@ -424,7 +438,7 @@ export class BuildURI implements URIInterface<BuildURI> {
424
438
  return getParamResult(key, this.getParam(key), msgFn);
425
439
  }
426
440
 
427
- getParamsResult(...keys: keysParam): Result<Record<string, string>> {
441
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>> {
428
442
  return getParamsResult(keys, this);
429
443
  }
430
444
 
@@ -576,7 +590,7 @@ export class URI implements URIInterface<URI> {
576
590
  return getParamResult(key, this.getParam(key), msgFn);
577
591
  }
578
592
 
579
- getParamsResult(...keys: keysParam): Result<Record<string, string>> {
593
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>> {
580
594
  return getParamsResult(keys, this);
581
595
  }
582
596
 
@@ -1 +1 @@
1
- {"version":3,"file":"base-sys-abstraction.d.ts","sourceRoot":"","sources":["../../src/base-sys-abstraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE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 .read()
97
+ .then(({ done, value }) => {
98
+ if (done) {
99
+ return;
100
+ }
101
+ writeFn(value)
102
+ .then(() => {
103
+ consumeReadableStream(reader, writeFn);
104
+ })
105
+ .catch((e) => {
106
+ console.error("consumeReadableStream:writeFn", e);
107
+ });
108
+ })
109
+ .catch((e) => {
110
+ console.error("consumeReadableStream:read", e);
111
+ });
112
+ }
113
+ function CFWriteableStream(writeFn) {
114
+ const ts = new TransformStream();
115
+ consumeReadableStream(ts.readable.getReader(), writeFn);
116
+ return ts.writable;
117
+ }
94
118
  export class BaseSysAbstraction {
95
119
  constructor(params) {
96
120
  this._time = new SysTime();
@@ -100,23 +124,13 @@ export class BaseSysAbstraction {
100
124
  this._systemService = params.SystemService;
101
125
  this._txtEnDe = params.TxtEnDecoder;
102
126
  const decoder = this._txtEnDe;
103
- this._stdout = new WritableStream({
104
- write(chunk) {
105
- return new Promise((resolve) => {
106
- const decoded = decoder.decode(chunk);
107
- console.log(decoded.trimEnd());
108
- resolve();
109
- });
110
- },
127
+ this._stdout = CFWriteableStream(async (chunk) => {
128
+ const decoded = decoder.decode(chunk);
129
+ console.log(decoded.trimEnd());
111
130
  });
112
- this._stderr = new WritableStream({
113
- write(chunk) {
114
- return new Promise((resolve) => {
115
- const decoded = decoder.decode(chunk);
116
- console.error(decoded.trimEnd());
117
- resolve();
118
- });
119
- },
131
+ this._stderr = CFWriteableStream(async (chunk) => {
132
+ const decoded = decoder.decode(chunk);
133
+ console.error(decoded.trimEnd());
120
134
  });
121
135
  }
122
136
  }