@adviser/cement 0.0.0-jsr-t1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -0
- package/README.md +39 -0
- package/base-sys-abstraction-BkEiLHl0.d.ts +193 -0
- package/base-sys-abstraction-Qj7pkY1N.d.cts +193 -0
- package/chunk-7KFVMTOS.js +311 -0
- package/chunk-7KFVMTOS.js.map +1 -0
- package/chunk-GES3MUGV.js +92 -0
- package/chunk-GES3MUGV.js.map +1 -0
- package/chunk-Q65HLCNL.js +601 -0
- package/chunk-Q65HLCNL.js.map +1 -0
- package/chunk-WMMUXBDX.js +87 -0
- package/chunk-WMMUXBDX.js.map +1 -0
- package/index-Q3phXzYr.d.cts +75 -0
- package/index-tIGZMHTc.d.ts +75 -0
- package/index.cjs +2593 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +532 -0
- package/index.d.ts +532 -0
- package/index.js +1533 -0
- package/index.js.map +1 -0
- package/node/index.cjs +924 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +65 -0
- package/node/index.d.ts +65 -0
- package/node/index.js +398 -0
- package/node/index.js.map +1 -0
- package/package.json +81 -0
- package/src/base-sys-abstraction.test.ts +95 -0
- package/src/base-sys-abstraction.ts +242 -0
- package/src/bin2text.test.ts +59 -0
- package/src/bin2text.ts +47 -0
- package/src/crypto.test.ts +15 -0
- package/src/crypto.ts +125 -0
- package/src/file-service.ts +24 -0
- package/src/future.test.ts +32 -0
- package/src/future.ts +27 -0
- package/src/index.ts +22 -0
- package/src/jsr.json +20 -0
- package/src/log-level-impl.ts +87 -0
- package/src/log-writer-impl.ts +58 -0
- package/src/logger-impl.ts +498 -0
- package/src/logger.test.ts +1132 -0
- package/src/logger.ts +208 -0
- package/src/node/deno-file-service.ts +92 -0
- package/src/node/deno-sys-abstraction.ts +133 -0
- package/src/node/index.ts +4 -0
- package/src/node/mock-file-service.ts +45 -0
- package/src/node/node-file-service.ts +91 -0
- package/src/node/node-sys-abstraction.ts +121 -0
- package/src/option.ts +60 -0
- package/src/resolve-once.test.ts +321 -0
- package/src/resolve-once.ts +179 -0
- package/src/result.test.ts +102 -0
- package/src/result.ts +165 -0
- package/src/runtime.ts +36 -0
- package/src/sys-abstraction.ts +53 -0
- package/src/sys-env.test.ts +53 -0
- package/src/sys-env.ts +216 -0
- package/src/test/log-write-stream.ts +95 -0
- package/src/test/mock-logger.ts +40 -0
- package/src/time.ts +20 -0
- package/src/tracer.test.ts +314 -0
- package/src/tracer.ts +222 -0
- package/src/txt-en-decoder.ts +21 -0
- package/src/uri.test.ts +155 -0
- package/src/uri.ts +421 -0
- package/src/utils/console-write-stream.ts +72 -0
- package/src/utils/fanout-write-stream.ts +32 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/rebuffer.ts +75 -0
- package/src/utils/stream-map.ts +67 -0
- package/src/utils/stream2string.ts +47 -0
- package/src/utils/string2stream.ts +14 -0
- package/src/version.ts +3 -0
- package/src/web/index.ts +1 -0
- package/src/web/web-sys-abstraction.ts +80 -0
- package/ts/LICENSE +201 -0
- package/ts/README.md +39 -0
- package/ts/base-sys-abstraction.d.ts +84 -0
- package/ts/base-sys-abstraction.d.ts.map +1 -0
- package/ts/base-sys-abstraction.js +178 -0
- package/ts/base-sys-abstraction.js.map +1 -0
- package/ts/base-sys-abstraction.test.d.ts +2 -0
- package/ts/base-sys-abstraction.test.d.ts.map +1 -0
- package/ts/base-sys-abstraction.test.js +82 -0
- package/ts/base-sys-abstraction.test.js.map +1 -0
- package/ts/bin2text.d.ts +3 -0
- package/ts/bin2text.d.ts.map +1 -0
- package/ts/bin2text.js +43 -0
- package/ts/bin2text.js.map +1 -0
- package/ts/bin2text.test.d.ts +2 -0
- package/ts/bin2text.test.d.ts.map +1 -0
- package/ts/bin2text.test.js +51 -0
- package/ts/bin2text.test.js.map +1 -0
- package/ts/crypto.d.ts +76 -0
- package/ts/crypto.d.ts.map +1 -0
- package/ts/crypto.js +22 -0
- package/ts/crypto.js.map +1 -0
- package/ts/crypto.test.d.ts +2 -0
- package/ts/crypto.test.d.ts.map +1 -0
- package/ts/crypto.test.js +14 -0
- package/ts/crypto.test.js.map +1 -0
- package/ts/file-service.d.ts +17 -0
- package/ts/file-service.d.ts.map +1 -0
- package/ts/file-service.js +2 -0
- package/ts/file-service.js.map +1 -0
- package/ts/future.d.ts +8 -0
- package/ts/future.d.ts.map +1 -0
- package/ts/future.js +38 -0
- package/ts/future.js.map +1 -0
- package/ts/future.test.d.ts +2 -0
- package/ts/future.test.d.ts.map +1 -0
- package/ts/future.test.js +28 -0
- package/ts/future.test.js.map +1 -0
- package/ts/index.d.ts +23 -0
- package/ts/index.d.ts.map +1 -0
- package/ts/index.js +23 -0
- package/ts/index.js.map +1 -0
- package/ts/log-level-impl.d.ts +14 -0
- package/ts/log-level-impl.d.ts.map +1 -0
- package/ts/log-level-impl.js +72 -0
- package/ts/log-level-impl.js.map +1 -0
- package/ts/log-writer-impl.d.ts +10 -0
- package/ts/log-writer-impl.d.ts.map +1 -0
- package/ts/log-writer-impl.js +45 -0
- package/ts/log-writer-impl.js.map +1 -0
- package/ts/logger-impl.d.ts +71 -0
- package/ts/logger-impl.d.ts.map +1 -0
- package/ts/logger-impl.js +412 -0
- package/ts/logger-impl.js.map +1 -0
- package/ts/logger.d.ts +84 -0
- package/ts/logger.d.ts.map +1 -0
- package/ts/logger.js +114 -0
- package/ts/logger.js.map +1 -0
- package/ts/logger.test.d.ts +2 -0
- package/ts/logger.test.d.ts.map +1 -0
- package/ts/logger.test.js +1023 -0
- package/ts/logger.test.js.map +1 -0
- package/ts/node/deno-file-service.d.ts +17 -0
- package/ts/node/deno-file-service.d.ts.map +1 -0
- package/ts/node/deno-file-service.js +65 -0
- package/ts/node/deno-file-service.js.map +1 -0
- package/ts/node/deno-sys-abstraction.d.ts +22 -0
- package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
- package/ts/node/deno-sys-abstraction.js +101 -0
- package/ts/node/deno-sys-abstraction.js.map +1 -0
- package/ts/node/index.d.ts +5 -0
- package/ts/node/index.d.ts.map +1 -0
- package/ts/node/index.js +5 -0
- package/ts/node/index.js.map +1 -0
- package/ts/node/mock-file-service.d.ts +11 -0
- package/ts/node/mock-file-service.d.ts.map +1 -0
- package/ts/node/mock-file-service.js +34 -0
- package/ts/node/mock-file-service.js.map +1 -0
- package/ts/node/mock-file-service.test.d.ts +2 -0
- package/ts/node/mock-file-service.test.d.ts.map +1 -0
- package/ts/node/mock-file-service.test.js +31 -0
- package/ts/node/mock-file-service.test.js.map +1 -0
- package/ts/node/node-file-service.d.ts +16 -0
- package/ts/node/node-file-service.d.ts.map +1 -0
- package/ts/node/node-file-service.js +71 -0
- package/ts/node/node-file-service.js.map +1 -0
- package/ts/node/node-sys-abstraction.d.ts +22 -0
- package/ts/node/node-sys-abstraction.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.js +99 -0
- package/ts/node/node-sys-abstraction.js.map +1 -0
- package/ts/node/node-sys-abstraction.test.d.ts +2 -0
- package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.test.js +87 -0
- package/ts/node/node-sys-abstraction.test.js.map +1 -0
- package/ts/option.d.ts +25 -0
- package/ts/option.d.ts.map +1 -0
- package/ts/option.js +47 -0
- package/ts/option.js.map +1 -0
- package/ts/resolve-once.d.ts +46 -0
- package/ts/resolve-once.d.ts.map +1 -0
- package/ts/resolve-once.js +152 -0
- package/ts/resolve-once.js.map +1 -0
- package/ts/resolve-once.test.d.ts +2 -0
- package/ts/resolve-once.test.d.ts.map +1 -0
- package/ts/resolve-once.test.js +283 -0
- package/ts/resolve-once.test.js.map +1 -0
- package/ts/result.d.ts +34 -0
- package/ts/result.d.ts.map +1 -0
- package/ts/result.js +85 -0
- package/ts/result.js.map +1 -0
- package/ts/result.test.d.ts +2 -0
- package/ts/result.test.d.ts.map +1 -0
- package/ts/result.test.js +79 -0
- package/ts/result.test.js.map +1 -0
- package/ts/runtime.d.ts +8 -0
- package/ts/runtime.d.ts.map +1 -0
- package/ts/runtime.js +26 -0
- package/ts/runtime.js.map +1 -0
- package/ts/sys-abstraction.d.ts +36 -0
- package/ts/sys-abstraction.d.ts.map +1 -0
- package/ts/sys-abstraction.js +31 -0
- package/ts/sys-abstraction.js.map +1 -0
- package/ts/sys-env.d.ts +48 -0
- package/ts/sys-env.d.ts.map +1 -0
- package/ts/sys-env.js +176 -0
- package/ts/sys-env.js.map +1 -0
- package/ts/sys-env.test.d.ts +2 -0
- package/ts/sys-env.test.d.ts.map +1 -0
- package/ts/sys-env.test.js +51 -0
- package/ts/sys-env.test.js.map +1 -0
- package/ts/test/log-write-stream.d.ts +27 -0
- package/ts/test/log-write-stream.d.ts.map +1 -0
- package/ts/test/log-write-stream.js +74 -0
- package/ts/test/log-write-stream.js.map +1 -0
- package/ts/test/mock-logger.d.ts +14 -0
- package/ts/test/mock-logger.d.ts.map +1 -0
- package/ts/test/mock-logger.js +29 -0
- package/ts/test/mock-logger.js.map +1 -0
- package/ts/test/mock-logger.test.d.ts +2 -0
- package/ts/test/mock-logger.test.d.ts.map +1 -0
- package/ts/test/mock-logger.test.js +63 -0
- package/ts/test/mock-logger.test.js.map +1 -0
- package/ts/test/test-exit-handler.d.ts +2 -0
- package/ts/test/test-exit-handler.d.ts.map +1 -0
- package/ts/test/test-exit-handler.js +57 -0
- package/ts/test/test-exit-handler.js.map +1 -0
- package/ts/time.d.ts +13 -0
- package/ts/time.d.ts.map +1 -0
- package/ts/time.js +14 -0
- package/ts/time.js.map +1 -0
- package/ts/tracer.d.ts +59 -0
- package/ts/tracer.d.ts.map +1 -0
- package/ts/tracer.js +148 -0
- package/ts/tracer.js.map +1 -0
- package/ts/tracer.test.d.ts +2 -0
- package/ts/tracer.test.d.ts.map +1 -0
- package/ts/tracer.test.js +311 -0
- package/ts/tracer.test.js.map +1 -0
- package/ts/txt-en-decoder.d.ts +10 -0
- package/ts/txt-en-decoder.d.ts.map +1 -0
- package/ts/txt-en-decoder.js +15 -0
- package/ts/txt-en-decoder.js.map +1 -0
- package/ts/uri.d.ts +67 -0
- package/ts/uri.d.ts.map +1 -0
- package/ts/uri.js +283 -0
- package/ts/uri.js.map +1 -0
- package/ts/uri.test.d.ts +2 -0
- package/ts/uri.test.d.ts.map +1 -0
- package/ts/uri.test.js +119 -0
- package/ts/uri.test.js.map +1 -0
- package/ts/utils/console-write-stream.d.ts +21 -0
- package/ts/utils/console-write-stream.d.ts.map +1 -0
- package/ts/utils/console-write-stream.js +62 -0
- package/ts/utils/console-write-stream.js.map +1 -0
- package/ts/utils/fanout-write-stream.d.ts +12 -0
- package/ts/utils/fanout-write-stream.d.ts.map +1 -0
- package/ts/utils/fanout-write-stream.js +24 -0
- package/ts/utils/fanout-write-stream.js.map +1 -0
- package/ts/utils/index.d.ts +7 -0
- package/ts/utils/index.d.ts.map +1 -0
- package/ts/utils/index.js +7 -0
- package/ts/utils/index.js.map +1 -0
- package/ts/utils/rebuffer.d.ts +3 -0
- package/ts/utils/rebuffer.d.ts.map +1 -0
- package/ts/utils/rebuffer.js +60 -0
- package/ts/utils/rebuffer.js.map +1 -0
- package/ts/utils/rebuffer.test.d.ts +2 -0
- package/ts/utils/rebuffer.test.d.ts.map +1 -0
- package/ts/utils/rebuffer.test.js +77 -0
- package/ts/utils/rebuffer.test.js.map +1 -0
- package/ts/utils/stream-map.d.ts +9 -0
- package/ts/utils/stream-map.d.ts.map +1 -0
- package/ts/utils/stream-map.js +62 -0
- package/ts/utils/stream-map.js.map +1 -0
- package/ts/utils/stream-map.test.d.ts +2 -0
- package/ts/utils/stream-map.test.d.ts.map +1 -0
- package/ts/utils/stream-map.test.js +87 -0
- package/ts/utils/stream-map.test.js.map +1 -0
- package/ts/utils/stream-test-helper.d.ts +17 -0
- package/ts/utils/stream-test-helper.d.ts.map +1 -0
- package/ts/utils/stream-test-helper.js +37 -0
- package/ts/utils/stream-test-helper.js.map +1 -0
- package/ts/utils/stream2string.d.ts +3 -0
- package/ts/utils/stream2string.d.ts.map +1 -0
- package/ts/utils/stream2string.js +48 -0
- package/ts/utils/stream2string.js.map +1 -0
- package/ts/utils/stream2string.test.d.ts +2 -0
- package/ts/utils/stream2string.test.d.ts.map +1 -0
- package/ts/utils/stream2string.test.js +29 -0
- package/ts/utils/stream2string.test.js.map +1 -0
- package/ts/utils/string2stream.d.ts +4 -0
- package/ts/utils/string2stream.d.ts.map +1 -0
- package/ts/utils/string2stream.js +13 -0
- package/ts/utils/string2stream.js.map +1 -0
- package/ts/utils/string2stream.test.d.ts +2 -0
- package/ts/utils/string2stream.test.d.ts.map +1 -0
- package/ts/utils/string2stream.test.js +6 -0
- package/ts/utils/string2stream.test.js.map +1 -0
- package/ts/version.d.ts +2 -0
- package/ts/version.d.ts.map +1 -0
- package/ts/version.js +4 -0
- package/ts/version.js.map +1 -0
- package/ts/web/index.d.ts +2 -0
- package/ts/web/index.d.ts.map +1 -0
- package/ts/web/index.js +2 -0
- package/ts/web/index.js.map +1 -0
- package/ts/web/web-sys-abstraction.d.ts +4 -0
- package/ts/web/web-sys-abstraction.d.ts.map +1 -0
- package/ts/web/web-sys-abstraction.js +64 -0
- package/ts/web/web-sys-abstraction.js.map +1 -0
- package/txt-en-decoder-CZYJUju2.d.cts +11 -0
- package/txt-en-decoder-CZYJUju2.d.ts +11 -0
- package/utils/index.cjs +341 -0
- package/utils/index.cjs.map +1 -0
- package/utils/index.d.cts +2 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +32 -0
- package/utils/index.js.map +1 -0
- package/web/index.cjs +593 -0
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +6 -0
- package/web/index.d.ts +6 -0
- package/web/index.js +9 -0
- package/web/index.js.map +1 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/node/node-file-service.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":["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","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,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,aAAa;AAIb,IAAM,kBAAN,MAA6C;AAAA,EAElD,YAAY,UAAkB,QAAQ,IAAI,GAAG;AAC3C,SAAK,UAAU,KAAK,IAAI,OAAO;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,eAAe,OAAgC;AAC7C,WAAO,GAAG,SAAS,SAAS,OAAO,EAAE,UAAU,QAAQ,CAAC;AAAA,EAC1D;AAAA,EAEA,QAAQ,OAAuB;AAC7B,WAAO,KAAK,QAAQ,KAAK;AAAA,EAC3B;AAAA,EACA,SAAS,OAAuB;AAC9B,WAAO,KAAK,SAAS,KAAK;AAAA,EAC5B;AAAA,EAEA,QAAQ,OAAyB;AAC/B,WAAO,KAAK,KAAK,GAAG,KAAK;AAA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C3B,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,UAAM,UAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAa;AACjB,aAAG,UAAU,GAAG,UAAU,QAAQ,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","process","path","Deno","my"]}
|
package/package.json
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
{
|
2
|
+
"name": "@adviser/cement",
|
3
|
+
"version": "0.0.0-jsr-t1",
|
4
|
+
"description": "better try/catch/finally handling",
|
5
|
+
"main": "index.js",
|
6
|
+
"type": "module",
|
7
|
+
"exports": {
|
8
|
+
".": {
|
9
|
+
"types": "./index.d.ts",
|
10
|
+
"require": "./index.cjs",
|
11
|
+
"import": "./index.js"
|
12
|
+
},
|
13
|
+
"./web": {
|
14
|
+
"types": "./web/index.d.ts",
|
15
|
+
"require": "./web/index.cjs",
|
16
|
+
"import": "./web/index.js"
|
17
|
+
},
|
18
|
+
"./utils": {
|
19
|
+
"types": "./utils/index.d.ts",
|
20
|
+
"require": "./utils/index.cjs",
|
21
|
+
"import": "./utils/index.js"
|
22
|
+
},
|
23
|
+
"./node": {
|
24
|
+
"types": "./node/index.d.ts",
|
25
|
+
"require": "./node/index.cjs",
|
26
|
+
"import": "./node/index.js"
|
27
|
+
},
|
28
|
+
"./deno": {
|
29
|
+
"types": "./node/index.d.ts",
|
30
|
+
"require": "./node/index.cjs",
|
31
|
+
"import": "./node/index.js"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"keywords": [],
|
35
|
+
"author": "Meno Abels <meno.abels@adviser.com>",
|
36
|
+
"license": "AFL-2.0",
|
37
|
+
"bugs": {
|
38
|
+
"url": "https://github.com/mabels/cement/issues"
|
39
|
+
},
|
40
|
+
"homepage": "https://github.com/mabels/cement#readme",
|
41
|
+
"dependencies": {
|
42
|
+
"ts-essentials": "^10.0.2",
|
43
|
+
"yaml": "^2.5.1"
|
44
|
+
},
|
45
|
+
"devDependencies": {
|
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",
|
50
|
+
"esbuild-plugin-replace": "^1.4.0",
|
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",
|
58
|
+
"vite-tsconfig-paths": "^5.0.1",
|
59
|
+
"vitest": "^2.0.5",
|
60
|
+
"webdriverio": "^9.0.7"
|
61
|
+
},
|
62
|
+
"engines": {
|
63
|
+
"node": ">=16"
|
64
|
+
},
|
65
|
+
"scripts": {
|
66
|
+
"clean": "rm -rf dist node_modules",
|
67
|
+
"build": "pnpm run build:tsc; pnpm run build:js",
|
68
|
+
"build:tsc": "tsc",
|
69
|
+
"xbuild:js": "tsup",
|
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
|
+
"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",
|
73
|
+
"test:js": "vitest --run",
|
74
|
+
"pubdir": "bash ./prepare-pubdir.sh",
|
75
|
+
"presmoke": "pnpm run pubdir ; cd pubdir ; pnpm pack",
|
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
|
+
"lint": "eslint .",
|
78
|
+
"prettier": "prettier .",
|
79
|
+
"format": "prettier ."
|
80
|
+
}
|
81
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import { runtimeFn, IDMode, TimeMode, RandomMode } from "@adviser/cement";
|
2
|
+
import { DenoSysAbstraction, NodeSysAbstraction } from "@adviser/cement/node";
|
3
|
+
import { WebSysAbstraction } from "@adviser/cement/web";
|
4
|
+
|
5
|
+
const abstractions = [];
|
6
|
+
|
7
|
+
if (runtimeFn().isNodeIsh) {
|
8
|
+
abstractions.push({ name: "NodeSysAbstraction", fn: NodeSysAbstraction });
|
9
|
+
}
|
10
|
+
|
11
|
+
if (runtimeFn().isDeno) {
|
12
|
+
abstractions.push({ name: "DenoSysAbstraction", fn: DenoSysAbstraction });
|
13
|
+
}
|
14
|
+
|
15
|
+
if (runtimeFn().isBrowser) {
|
16
|
+
abstractions.push({ name: "WebSysAbstraction", fn: WebSysAbstraction });
|
17
|
+
}
|
18
|
+
|
19
|
+
for (const abstraction of abstractions) {
|
20
|
+
describe(abstraction.name, () => {
|
21
|
+
it("IdService UUID", () => {
|
22
|
+
const sys = abstraction.fn();
|
23
|
+
const id1 = sys.NextId();
|
24
|
+
const id2 = sys.NextId();
|
25
|
+
expect(id1).not.toEqual(id2);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("IdService explict UUID", () => {
|
29
|
+
const sys = abstraction.fn({ IdMode: IDMode.UUID });
|
30
|
+
const id1 = sys.NextId();
|
31
|
+
const id2 = sys.NextId();
|
32
|
+
expect(id1).not.toEqual(id2);
|
33
|
+
});
|
34
|
+
|
35
|
+
it("IdService const", () => {
|
36
|
+
const sys = abstraction.fn({ IdMode: IDMode.CONST });
|
37
|
+
const id1 = sys.NextId();
|
38
|
+
const id2 = sys.NextId();
|
39
|
+
expect(id1).toEqual(id2);
|
40
|
+
});
|
41
|
+
|
42
|
+
it("IdService set", () => {
|
43
|
+
for (let i = 0; i < 10; i++) {
|
44
|
+
const sys = abstraction.fn({ IdMode: IDMode.STEP });
|
45
|
+
const id1 = sys.NextId();
|
46
|
+
const id2 = sys.NextId();
|
47
|
+
expect(id1).toEqual("STEPId-0");
|
48
|
+
expect(id2).toEqual("STEPId-1");
|
49
|
+
}
|
50
|
+
});
|
51
|
+
|
52
|
+
it("time sleep", async () => {
|
53
|
+
const sys = abstraction.fn();
|
54
|
+
const start = sys.Time().Now();
|
55
|
+
await sys.Time().Sleep(100);
|
56
|
+
expect(sys.Time().TimeSince(start)).toBeGreaterThan(90);
|
57
|
+
});
|
58
|
+
|
59
|
+
it("time sleep const", async () => {
|
60
|
+
const sys = abstraction.fn({ TimeMode: TimeMode.REAL });
|
61
|
+
const start = new Date();
|
62
|
+
await sys.Time().Sleep(100);
|
63
|
+
const end = new Date();
|
64
|
+
expect(end.getTime() - start.getTime()).toBeGreaterThan(90);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("time sleep step", async () => {
|
68
|
+
const sys = abstraction.fn({ TimeMode: TimeMode.STEP });
|
69
|
+
const start = sys.Time().Now();
|
70
|
+
await sys.Time().Sleep(86400500);
|
71
|
+
expect(sys.Time().Now().getTime() - start.getTime()).toEqual(86401500);
|
72
|
+
});
|
73
|
+
|
74
|
+
it("const random", () => {
|
75
|
+
const sys = abstraction.fn({ RandomMode: RandomMode.CONST });
|
76
|
+
expect(sys.Random0ToValue(10)).toEqual(5);
|
77
|
+
expect(sys.Random0ToValue(10)).toEqual(5);
|
78
|
+
});
|
79
|
+
|
80
|
+
it("step random", () => {
|
81
|
+
const sys = abstraction.fn({ RandomMode: RandomMode.STEP });
|
82
|
+
expect(sys.Random0ToValue(10000)).toEqual(1);
|
83
|
+
expect(sys.Random0ToValue(10000)).toEqual(2);
|
84
|
+
});
|
85
|
+
|
86
|
+
it("random", () => {
|
87
|
+
const sys = abstraction.fn({});
|
88
|
+
for (let i = 0; i < 100; i++) {
|
89
|
+
const val = sys.Random0ToValue(10);
|
90
|
+
expect(val).toBeGreaterThanOrEqual(0);
|
91
|
+
expect(val).toBeLessThanOrEqual(10);
|
92
|
+
}
|
93
|
+
});
|
94
|
+
});
|
95
|
+
}
|
@@ -0,0 +1,242 @@
|
|
1
|
+
import { FileService } from "./file-service.js";
|
2
|
+
import { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from "./sys-abstraction.js";
|
3
|
+
import { Time } from "./time.js";
|
4
|
+
import { TxtEnDecoder } from "./txt-en-decoder.js";
|
5
|
+
|
6
|
+
export class SysTime extends Time {
|
7
|
+
Now(): Date {
|
8
|
+
return new Date();
|
9
|
+
}
|
10
|
+
Sleep(duration: number): Promise<void> {
|
11
|
+
return new Promise((resolve) => {
|
12
|
+
setTimeout(() => {
|
13
|
+
resolve();
|
14
|
+
}, duration);
|
15
|
+
});
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
export class ConstTime extends Time {
|
20
|
+
Now(): Date {
|
21
|
+
return new Date(2021, 1, 1, 0, 0, 0, 0);
|
22
|
+
}
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
24
|
+
Sleep(duration: number): Promise<void> {
|
25
|
+
return Promise.resolve();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
export class StepTime extends Time {
|
30
|
+
_step: Date;
|
31
|
+
readonly _start: Date;
|
32
|
+
constructor() {
|
33
|
+
super();
|
34
|
+
this._step = new ConstTime().Now();
|
35
|
+
this._start = this._step;
|
36
|
+
}
|
37
|
+
Now(steps = 1): Date {
|
38
|
+
// if (this._step.getTime() === 0) {
|
39
|
+
// this._step = new ConstTime().Now();
|
40
|
+
// return this._step;
|
41
|
+
// }
|
42
|
+
for (let i = 0; steps > 0 && i < steps; i++) {
|
43
|
+
this._step = new Date(this._step.getTime() + 1000);
|
44
|
+
}
|
45
|
+
if (steps < 1) {
|
46
|
+
this._step = new Date(this._start.getTime() + steps * -1000);
|
47
|
+
}
|
48
|
+
// this._step = new Date(this._step.getTime() + 1000);
|
49
|
+
return this._step;
|
50
|
+
}
|
51
|
+
Sleep(duration: number): Promise<void> {
|
52
|
+
this._step = new Date(this._step.getTime() + duration);
|
53
|
+
return Promise.resolve();
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
export function TimeFactory(timeMode: TimeMode): Time {
|
58
|
+
switch (timeMode) {
|
59
|
+
case TimeMode.REAL:
|
60
|
+
return new SysTime();
|
61
|
+
case TimeMode.CONST:
|
62
|
+
return new ConstTime();
|
63
|
+
case TimeMode.STEP:
|
64
|
+
return new StepTime();
|
65
|
+
}
|
66
|
+
return new SysTime();
|
67
|
+
}
|
68
|
+
|
69
|
+
export class RandomService {
|
70
|
+
readonly _mode: RandomMode;
|
71
|
+
_step = 0;
|
72
|
+
constructor(mode: RandomMode) {
|
73
|
+
this._mode = mode;
|
74
|
+
}
|
75
|
+
Random0ToValue(value: number): number {
|
76
|
+
switch (this._mode) {
|
77
|
+
case RandomMode.CONST:
|
78
|
+
return 0.5 * value;
|
79
|
+
case RandomMode.STEP:
|
80
|
+
this._step += 0.0001;
|
81
|
+
return this._step * value;
|
82
|
+
case RandomMode.RANDOM:
|
83
|
+
return Math.random() * value;
|
84
|
+
default:
|
85
|
+
throw new Error("Unknown RandomMode");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
export class IdService {
|
91
|
+
readonly _mode: IDMode;
|
92
|
+
_step = 0;
|
93
|
+
constructor(mode?: IDMode) {
|
94
|
+
if (!mode) {
|
95
|
+
mode = IDMode.UUID;
|
96
|
+
}
|
97
|
+
this._mode = mode;
|
98
|
+
}
|
99
|
+
NextId(): string {
|
100
|
+
switch (this._mode) {
|
101
|
+
case IDMode.UUID:
|
102
|
+
return crypto.randomUUID();
|
103
|
+
case IDMode.CONST:
|
104
|
+
return "VeryUniqueID";
|
105
|
+
case IDMode.STEP:
|
106
|
+
return `STEPId-${this._step++}`;
|
107
|
+
default:
|
108
|
+
throw new Error("Unknown IDMode");
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
export interface BaseSysAbstractionParams {
|
114
|
+
readonly TxtEnDecoder: TxtEnDecoder;
|
115
|
+
readonly FileSystem: FileService;
|
116
|
+
readonly SystemService: SystemService;
|
117
|
+
}
|
118
|
+
|
119
|
+
export interface ExitHandler {
|
120
|
+
readonly hdl: VoidFunc;
|
121
|
+
readonly id: string;
|
122
|
+
}
|
123
|
+
|
124
|
+
export interface ExitService {
|
125
|
+
injectExitHandlers(hdls: ExitHandler[]): void;
|
126
|
+
exit(code: number): void;
|
127
|
+
}
|
128
|
+
|
129
|
+
export class BaseSysAbstraction {
|
130
|
+
readonly _time: SysTime = new SysTime();
|
131
|
+
readonly _stdout: WritableStream;
|
132
|
+
readonly _stderr: WritableStream;
|
133
|
+
|
134
|
+
readonly _idService: IdService = new IdService();
|
135
|
+
readonly _randomService: RandomService = new RandomService(RandomMode.RANDOM);
|
136
|
+
readonly _fileSystem: FileService;
|
137
|
+
readonly _systemService: SystemService;
|
138
|
+
readonly _txtEnDe: TxtEnDecoder;
|
139
|
+
|
140
|
+
constructor(params: BaseSysAbstractionParams) {
|
141
|
+
this._fileSystem = params.FileSystem;
|
142
|
+
this._systemService = params.SystemService;
|
143
|
+
this._txtEnDe = params.TxtEnDecoder;
|
144
|
+
const decoder = this._txtEnDe;
|
145
|
+
this._stdout = new WritableStream({
|
146
|
+
write(chunk): Promise<void> {
|
147
|
+
return new Promise((resolve) => {
|
148
|
+
const decoded = decoder.decode(chunk);
|
149
|
+
// eslint-disable-next-line no-console
|
150
|
+
console.log(decoded.trimEnd());
|
151
|
+
resolve();
|
152
|
+
});
|
153
|
+
},
|
154
|
+
});
|
155
|
+
this._stderr = new WritableStream({
|
156
|
+
write(chunk): Promise<void> {
|
157
|
+
return new Promise((resolve) => {
|
158
|
+
const decoded = decoder.decode(chunk);
|
159
|
+
// eslint-disable-next-line no-console
|
160
|
+
console.error(decoded.trimEnd());
|
161
|
+
resolve();
|
162
|
+
});
|
163
|
+
},
|
164
|
+
});
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
export interface WrapperSysAbstractionParams {
|
169
|
+
readonly TimeMode?: TimeMode;
|
170
|
+
readonly IdMode?: IDMode;
|
171
|
+
readonly Stdout?: WritableStream<Uint8Array>;
|
172
|
+
readonly Stderr?: WritableStream<Uint8Array>;
|
173
|
+
readonly RandomMode?: RandomMode;
|
174
|
+
readonly FileSystem?: FileService;
|
175
|
+
readonly SystemService?: SystemService;
|
176
|
+
readonly TxtEnDecoder?: TxtEnDecoder;
|
177
|
+
}
|
178
|
+
|
179
|
+
export class WrapperSysAbstraction implements SysAbstraction {
|
180
|
+
readonly _time: Time;
|
181
|
+
readonly _stdout: WritableStream<Uint8Array>;
|
182
|
+
readonly _stderr: WritableStream<Uint8Array>;
|
183
|
+
readonly _idService: IdService;
|
184
|
+
readonly _randomService: RandomService;
|
185
|
+
readonly _fileSystem: FileService;
|
186
|
+
readonly _systemService: SystemService;
|
187
|
+
constructor(base: BaseSysAbstraction, params?: WrapperSysAbstractionParams) {
|
188
|
+
this._time = base._time;
|
189
|
+
this._stdout = base._stdout;
|
190
|
+
this._stderr = base._stderr;
|
191
|
+
this._idService = base._idService;
|
192
|
+
this._randomService = base._randomService;
|
193
|
+
this._fileSystem = base._fileSystem;
|
194
|
+
this._systemService = base._systemService;
|
195
|
+
if (params) {
|
196
|
+
if (params.TimeMode) {
|
197
|
+
this._time = TimeFactory(params.TimeMode);
|
198
|
+
}
|
199
|
+
if (params.Stdout) {
|
200
|
+
this._stdout = params.Stdout;
|
201
|
+
}
|
202
|
+
if (params.Stderr) {
|
203
|
+
this._stderr = params.Stderr;
|
204
|
+
}
|
205
|
+
if (params.IdMode) {
|
206
|
+
this._idService = new IdService(params.IdMode);
|
207
|
+
}
|
208
|
+
if (params.RandomMode) {
|
209
|
+
this._randomService = new RandomService(params.RandomMode);
|
210
|
+
}
|
211
|
+
if (params.FileSystem) {
|
212
|
+
this._fileSystem = params.FileSystem;
|
213
|
+
}
|
214
|
+
if (params.SystemService) {
|
215
|
+
this._systemService = params.SystemService;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
Time(): Time {
|
220
|
+
return this._time;
|
221
|
+
}
|
222
|
+
NextId(): string {
|
223
|
+
return this._idService.NextId();
|
224
|
+
}
|
225
|
+
Random0ToValue(value: number): number {
|
226
|
+
return this._randomService.Random0ToValue(value);
|
227
|
+
}
|
228
|
+
Stdout(): WritableStream {
|
229
|
+
return this._stdout;
|
230
|
+
}
|
231
|
+
Stderr(): WritableStream {
|
232
|
+
return this._stderr;
|
233
|
+
}
|
234
|
+
|
235
|
+
System(): SystemService {
|
236
|
+
return this._systemService;
|
237
|
+
}
|
238
|
+
FileSystem(): FileService {
|
239
|
+
return this._fileSystem;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
// export const BaseSysAbstraction = new BaseSysAbstractionImpl()
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { bin2string, bin2text } from "./bin2text.js";
|
2
|
+
|
3
|
+
it("bin2hex empty", () => {
|
4
|
+
expect(bin2string(new Uint8Array())).toEqual("");
|
5
|
+
});
|
6
|
+
|
7
|
+
it("bin2hex one", () => {
|
8
|
+
expect(bin2string(new Uint8Array([64]))).toBe("0000 40 @");
|
9
|
+
});
|
10
|
+
|
11
|
+
it("bin2hex 12", () => {
|
12
|
+
const collector: string[] = [];
|
13
|
+
bin2text(new Uint8Array([1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc]), (line) => {
|
14
|
+
collector.push(line);
|
15
|
+
});
|
16
|
+
expect(collector).toEqual(["0000 01 02 03 04 04 05 06 07 08 09 0a 0b 0c ............."]);
|
17
|
+
});
|
18
|
+
|
19
|
+
it("bin2hex cut", () => {
|
20
|
+
const collector: string[] = [];
|
21
|
+
bin2text(
|
22
|
+
new Uint8Array(new Array(255).fill(1).map((_, i) => i)),
|
23
|
+
(line) => {
|
24
|
+
collector.push(line);
|
25
|
+
},
|
26
|
+
52,
|
27
|
+
);
|
28
|
+
expect(collector).toEqual([
|
29
|
+
"0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",
|
30
|
+
"0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",
|
31
|
+
"0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./",
|
32
|
+
"00f0>>f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ...............",
|
33
|
+
]);
|
34
|
+
});
|
35
|
+
|
36
|
+
it("bin2hex long", () => {
|
37
|
+
const collector: string[] = [];
|
38
|
+
bin2text(new Uint8Array(new Array(256).fill(1).map((_, i) => i % 0xff)), (line) => {
|
39
|
+
collector.push(line);
|
40
|
+
});
|
41
|
+
expect(collector).toEqual([
|
42
|
+
"0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",
|
43
|
+
"0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",
|
44
|
+
"0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./",
|
45
|
+
"0030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?",
|
46
|
+
"0040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO",
|
47
|
+
"0050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_",
|
48
|
+
"0060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno",
|
49
|
+
"0070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.",
|
50
|
+
"0080 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f ................",
|
51
|
+
"0090 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f ................",
|
52
|
+
"00a0 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af ................",
|
53
|
+
"00b0 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf ................",
|
54
|
+
"00c0 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf ................",
|
55
|
+
"00d0 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df ................",
|
56
|
+
"00e0 e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef ................",
|
57
|
+
"00f0 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe 00 ................",
|
58
|
+
]);
|
59
|
+
});
|
package/src/bin2text.ts
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
export function bin2text(hex: ArrayBufferView, lineFn: (line: string) => void, size = 0): void {
|
2
|
+
const arr = new Uint8Array(hex.buffer, hex.byteOffset, hex.byteLength);
|
3
|
+
let cutted = " ";
|
4
|
+
if (size == 0) {
|
5
|
+
size = arr.length;
|
6
|
+
}
|
7
|
+
size = Math.min(size, arr.length);
|
8
|
+
const cols = 16;
|
9
|
+
for (let line = 0; line < size; line += cols) {
|
10
|
+
if (line + cols <= size || arr.length == size) {
|
11
|
+
// normal line
|
12
|
+
} else {
|
13
|
+
line = arr.length - (arr.length % cols);
|
14
|
+
size = arr.length;
|
15
|
+
cutted = ">>";
|
16
|
+
}
|
17
|
+
const l: string[] = [line.toString(16).padStart(4, "0"), cutted];
|
18
|
+
for (let col = 0; col < cols; col++) {
|
19
|
+
if (line + col < size) {
|
20
|
+
l.push(arr[line + col].toString(16).padStart(2, "0"));
|
21
|
+
} else {
|
22
|
+
l.push(" ");
|
23
|
+
}
|
24
|
+
// l.push((col > 0 && col % 4 === 3) ? " " : " ");
|
25
|
+
l.push(" ");
|
26
|
+
}
|
27
|
+
for (let col = 0; col < cols; col++) {
|
28
|
+
if (line + col < size) {
|
29
|
+
const ch = arr[line + col];
|
30
|
+
l.push(ch >= 32 && ch < 127 ? String.fromCharCode(ch) : ".");
|
31
|
+
}
|
32
|
+
}
|
33
|
+
lineFn(l.join(""));
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
export function bin2string(hex: ArrayBufferView, size = 0): string {
|
38
|
+
const collector: string[] = [];
|
39
|
+
bin2text(
|
40
|
+
hex,
|
41
|
+
(line) => {
|
42
|
+
collector.push(line);
|
43
|
+
},
|
44
|
+
size,
|
45
|
+
);
|
46
|
+
return collector.join("\n");
|
47
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { toCryptoRuntime } from "./crypto.js";
|
2
|
+
|
3
|
+
it("not extractable import -> export", async () => {
|
4
|
+
const cp = toCryptoRuntime();
|
5
|
+
const key = cp.randomBytes(32);
|
6
|
+
const x = await cp.importKey("raw", key, "AES-CBC", false, ["encrypt"]);
|
7
|
+
expect(cp.exportKey("raw", x)).rejects.toThrowError(/key is not extractable/i);
|
8
|
+
});
|
9
|
+
|
10
|
+
it("extractable import -> export", async () => {
|
11
|
+
const cp = toCryptoRuntime();
|
12
|
+
const key = cp.randomBytes(32);
|
13
|
+
const x = await cp.importKey("raw", key, "AES-CBC", true, ["encrypt"]);
|
14
|
+
expect(new Uint8Array((await cp.exportKey("raw", x)) as ArrayBuffer)).toEqual(key);
|
15
|
+
});
|