@adviser/cement 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/{base_sys_abstraction-BsaOQtnz.d.cts → base_sys_abstraction-B_h8JSlV.d.cts} +1 -1
- package/{base_sys_abstraction-CQ7PJOct.d.ts → base_sys_abstraction-uF0nL2K3.d.ts} +1 -1
- package/{chunk-ZYFWDQGV.js → chunk-J2IM7FHM.js} +1 -3
- package/{chunk-XBYS4FSO.js → chunk-WZMCPT2R.js} +4 -4
- package/chunk-WZMCPT2R.js.map +1 -0
- package/{chunk-CI63N5CK.js → chunk-X4Z6DNDD.js} +284 -109
- package/chunk-X4Z6DNDD.js.map +1 -0
- package/index.cjs +337 -282
- package/index.cjs.map +1 -1
- package/index.d.cts +22 -18
- package/index.d.ts +22 -18
- package/index.js +64 -177
- package/index.js.map +1 -1
- package/node/index.cjs +220 -106
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +3 -3
- package/node/index.d.ts +3 -3
- package/node/index.js +4 -4
- package/node/index.js.map +1 -1
- package/package.json +6 -5
- package/{sys_abstraction-BzkoCY1p.d.cts → sys_abstraction-C1-BRiiP.d.cts} +26 -9
- package/{sys_abstraction-BzkoCY1p.d.ts → sys_abstraction-C1-BRiiP.d.ts} +26 -9
- package/utils/index.js +1 -1
- package/web/index.cjs +220 -106
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +2 -2
- package/web/index.d.ts +2 -2
- package/web/index.js +3 -3
- package/chunk-CI63N5CK.js.map +0 -1
- package/chunk-XBYS4FSO.js.map +0 -1
- /package/{chunk-ZYFWDQGV.js.map → chunk-J2IM7FHM.js.map} +0 -0
package/node/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/node/node_file_service.ts","../../../src/node/node_sys_abstraction.ts","../../../src/node/mock_file_service.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\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): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(new TextEncoder().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) {\n out.write(chunk);\n },\n close() {\n out.close();\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base_sys_abstraction\";\nimport { NodeFileService } from \"./node_file_service\";\nimport { envImpl } from \"../sys_env\";\n\nexport class ExitServiceImpl 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 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 ExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);\n }\n\n Env() {\n return envImpl;\n }\n\n Args() {\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 FileSystem: new NodeFileService(),\n SystemService: new NodeSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { NamedWritableStream } from \"../file_service\";\nimport { NodeFileService } from \"./node_file_service\";\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) {\n fc.content = fc.content + decoder.decode(chunk);\n },\n close() {\n // do nothing\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AAGR,IAAM,kBAAN,MAA6C;AAAA,EAElD,YAAY,UAAkB,QAAQ,IAAI,GAAG;AAC3C,SAAK,UAAU,KAAK,IAAI,OAAO;AAAA,EACjC;AAAA,EAEA,WAAW,OAAuB;AAEhC,QAAI,KAAK,WAAW,KAAK,GAAG;AAC1B,aAAO;AAAA,IACT,OAAO;AACL,aAAO,OAAO,KAAK,UAAU,KAAK;AAAA,IACpC;AAAA,EACF;AAAA,EAEA,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,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AAK,IAAI;AACpB,SAAK,MAAM,KAAK,IAAI;AACpB,UAAM,UAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAO;AACX,aAAG,UAAU,GAAG,UAAU,QAAQ,OAAO,KAAK;AAAA,QAChD;AAAA,QACA,QAAQ;AAAA,QAER;AAAA,QACA,QAAQ;AACN,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
1
|
+
{"version":3,"sources":["../../../src/node/node_file_service.ts","../../../src/node/node_sys_abstraction.ts","../../../src/node/mock_file_service.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\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): Promise<void> {\n const o = await this.create(fname);\n const wr = o.stream.getWriter();\n await wr.write(new TextEncoder().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) {\n out.write(chunk);\n },\n close() {\n out.close();\n },\n abort() {\n throw new Error(\"not implemented\");\n },\n }),\n };\n }\n}\n","import { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport {\n BaseSysAbstraction,\n ExitHandler,\n ExitService,\n WrapperSysAbstraction,\n WrapperSysAbstractionParams,\n} from \"../base_sys_abstraction\";\nimport { NodeFileService } from \"./node_file_service\";\nimport { envFactory } from \"../sys_env\";\n\nexport class ExitServiceImpl 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 ExitServiceImpl();\n constructor() {\n this._exitService.injectExitHandlers(NodeSystemService._exitHandlers);\n }\n\n Env() {\n return envFactory();\n }\n\n Args() {\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 FileSystem: new NodeFileService(),\n SystemService: new NodeSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n","import { NamedWritableStream } from \"../file_service\";\nimport { NodeFileService } from \"./node_file_service\";\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) {\n fc.content = fc.content + decoder.decode(chunk);\n },\n close()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3C,IAAM,oBAAN;AA+BP,IAAI,KAAqC;AAClC,SAAS,mBAAmB,OAAqD;AACtF,MAAI,CAAC,IAAI;AACP,SAAK,IAAI,mBAAmB;AAAA,MAC1B,YAAY,IAAI,gBAAgB;AAAA,MAChC,eAAe,IAAI,kBAAkB;AAAA,IACvC,CAAC;AAAA,EACH;AACA,SAAO,IAAI,sBAAsB,IAAI,KAAK;AAC5C;;;AC7GO,IAAM,kBAAN,cAA8B,gBAAgB;AAAA,EAA9C;AAAA;AACL,SAAS,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,MAAe,OAAO,OAA6C;AACjE,QAAI,QAAQ;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,UAAM,UAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,IAAI,eAA2B;AAAA,QACrC,MAAM,OAAO;AACX,aAAG,UAAU,GAAG,UAAU,QAAQ,OAAO,KAAK;AAAA,QAChD;AAAA,QACA,QAAQ;AAAA,QAER;AAAA,QACA,QAAQ;AACN,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@adviser/cement",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.4",
|
4
4
|
"description": "better try/catch/finally handling",
|
5
5
|
"main": "index.js",
|
6
6
|
"type": "module",
|
@@ -35,14 +35,14 @@
|
|
35
35
|
"homepage": "https://github.com/mabels/cement#readme",
|
36
36
|
"devDependencies": {
|
37
37
|
"@types/node": "^20.14.9",
|
38
|
-
"@typescript-eslint/eslint-plugin": "^7.16.
|
39
|
-
"@typescript-eslint/parser": "^7.16.
|
38
|
+
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
39
|
+
"@typescript-eslint/parser": "^7.16.1",
|
40
40
|
"eslint": "^9.6.0",
|
41
41
|
"prettier": "^3.2.5",
|
42
42
|
"tsup": "^8.1.0",
|
43
43
|
"tsx": "^4.16.0",
|
44
44
|
"typescript": "^5.5.0",
|
45
|
-
"typescript-eslint": "^7.16.
|
45
|
+
"typescript-eslint": "^7.16.1",
|
46
46
|
"vitest": "^2.0.2"
|
47
47
|
},
|
48
48
|
"engines": {
|
@@ -59,6 +59,7 @@
|
|
59
59
|
"presmoke": "pnpm run pubdir ; cd pubdir ; pnpm pack",
|
60
60
|
"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",
|
61
61
|
"lint": "eslint .",
|
62
|
-
"prettier": "prettier ."
|
62
|
+
"prettier": "prettier .",
|
63
|
+
"format": "prettier ."
|
63
64
|
}
|
64
65
|
}
|
@@ -16,12 +16,26 @@ interface FileService {
|
|
16
16
|
isAbsolute(fname: string): boolean;
|
17
17
|
}
|
18
18
|
|
19
|
-
interface
|
19
|
+
interface EnvMap {
|
20
20
|
get(key: string): string | undefined;
|
21
21
|
set(key: string, value?: string): void;
|
22
|
-
|
22
|
+
delete(key: string): void;
|
23
23
|
keys(): string[];
|
24
|
-
|
24
|
+
}
|
25
|
+
interface EnvActions extends EnvMap {
|
26
|
+
active(): boolean;
|
27
|
+
register(env: Env): Env;
|
28
|
+
}
|
29
|
+
declare class BrowserEnvActions implements EnvActions {
|
30
|
+
readonly env: Map<string, string>;
|
31
|
+
readonly opts: Partial<EnvFactoryOpts>;
|
32
|
+
constructor(opts: Partial<EnvFactoryOpts>);
|
33
|
+
get(key: string): string | undefined;
|
34
|
+
set(key: string, value?: string): void;
|
35
|
+
delete(key: string): void;
|
36
|
+
keys(): string[];
|
37
|
+
active(): boolean;
|
38
|
+
register(env: Env): Env;
|
25
39
|
}
|
26
40
|
interface EnvFactoryOpts {
|
27
41
|
readonly symbol: string;
|
@@ -32,19 +46,22 @@ interface OnSetItem {
|
|
32
46
|
readonly filter: Set<string>;
|
33
47
|
readonly fn: OnSetFn;
|
34
48
|
}
|
35
|
-
interface Env extends
|
49
|
+
interface Env extends EnvMap {
|
36
50
|
onSet(fn: OnSetFn, ...filter: string[]): void;
|
37
51
|
}
|
52
|
+
declare function envFactory(opts?: Partial<Omit<EnvFactoryOpts, "action">>): Env;
|
38
53
|
declare class EnvImpl implements Env {
|
39
|
-
|
40
|
-
constructor(opts?: Partial<EnvFactoryOpts>);
|
54
|
+
readonly _map: EnvMap;
|
55
|
+
constructor(map: EnvMap, opts?: Partial<EnvFactoryOpts>);
|
56
|
+
_updatePresets(presetEnv?: Map<string, string>): void;
|
57
|
+
_applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void;
|
58
|
+
readonly _onSet: OnSetItem[];
|
41
59
|
keys(): string[];
|
42
60
|
onSet(fn: OnSetFn, ...filter: string[]): void;
|
43
61
|
get(key: string): string | undefined;
|
44
62
|
set(key: string, value?: string): void;
|
45
|
-
|
63
|
+
delete(key: string): void;
|
46
64
|
}
|
47
|
-
declare const envImpl: EnvImpl;
|
48
65
|
|
49
66
|
declare abstract class Time {
|
50
67
|
abstract Now(): Date;
|
@@ -92,4 +109,4 @@ interface SysAbstraction {
|
|
92
109
|
FileSystem(): FileService;
|
93
110
|
}
|
94
111
|
|
95
|
-
export { type Duration as D, type
|
112
|
+
export { BrowserEnvActions as B, type Duration as D, type EnvMap as E, type FileService as F, IDMode as I, type NamedWritableStream as N, type OnSetItem as O, RandomMode as R, type SysAbstraction as S, TimeMode as T, type VoidFunc as V, String2TimeMode as a, type SystemService as b, type EnvActions as c, type Env as d, envFactory as e, EnvImpl as f, Time as g, TimeUnits as h };
|
@@ -16,12 +16,26 @@ interface FileService {
|
|
16
16
|
isAbsolute(fname: string): boolean;
|
17
17
|
}
|
18
18
|
|
19
|
-
interface
|
19
|
+
interface EnvMap {
|
20
20
|
get(key: string): string | undefined;
|
21
21
|
set(key: string, value?: string): void;
|
22
|
-
|
22
|
+
delete(key: string): void;
|
23
23
|
keys(): string[];
|
24
|
-
|
24
|
+
}
|
25
|
+
interface EnvActions extends EnvMap {
|
26
|
+
active(): boolean;
|
27
|
+
register(env: Env): Env;
|
28
|
+
}
|
29
|
+
declare class BrowserEnvActions implements EnvActions {
|
30
|
+
readonly env: Map<string, string>;
|
31
|
+
readonly opts: Partial<EnvFactoryOpts>;
|
32
|
+
constructor(opts: Partial<EnvFactoryOpts>);
|
33
|
+
get(key: string): string | undefined;
|
34
|
+
set(key: string, value?: string): void;
|
35
|
+
delete(key: string): void;
|
36
|
+
keys(): string[];
|
37
|
+
active(): boolean;
|
38
|
+
register(env: Env): Env;
|
25
39
|
}
|
26
40
|
interface EnvFactoryOpts {
|
27
41
|
readonly symbol: string;
|
@@ -32,19 +46,22 @@ interface OnSetItem {
|
|
32
46
|
readonly filter: Set<string>;
|
33
47
|
readonly fn: OnSetFn;
|
34
48
|
}
|
35
|
-
interface Env extends
|
49
|
+
interface Env extends EnvMap {
|
36
50
|
onSet(fn: OnSetFn, ...filter: string[]): void;
|
37
51
|
}
|
52
|
+
declare function envFactory(opts?: Partial<Omit<EnvFactoryOpts, "action">>): Env;
|
38
53
|
declare class EnvImpl implements Env {
|
39
|
-
|
40
|
-
constructor(opts?: Partial<EnvFactoryOpts>);
|
54
|
+
readonly _map: EnvMap;
|
55
|
+
constructor(map: EnvMap, opts?: Partial<EnvFactoryOpts>);
|
56
|
+
_updatePresets(presetEnv?: Map<string, string>): void;
|
57
|
+
_applyOnSet(onSet: OnSetItem[], key?: string, value?: string): void;
|
58
|
+
readonly _onSet: OnSetItem[];
|
41
59
|
keys(): string[];
|
42
60
|
onSet(fn: OnSetFn, ...filter: string[]): void;
|
43
61
|
get(key: string): string | undefined;
|
44
62
|
set(key: string, value?: string): void;
|
45
|
-
|
63
|
+
delete(key: string): void;
|
46
64
|
}
|
47
|
-
declare const envImpl: EnvImpl;
|
48
65
|
|
49
66
|
declare abstract class Time {
|
50
67
|
abstract Now(): Date;
|
@@ -92,4 +109,4 @@ interface SysAbstraction {
|
|
92
109
|
FileSystem(): FileService;
|
93
110
|
}
|
94
111
|
|
95
|
-
export { type Duration as D, type
|
112
|
+
export { BrowserEnvActions as B, type Duration as D, type EnvMap as E, type FileService as F, IDMode as I, type NamedWritableStream as N, type OnSetItem as O, RandomMode as R, type SysAbstraction as S, TimeMode as T, type VoidFunc as V, String2TimeMode as a, type SystemService as b, type EnvActions as c, type Env as d, envFactory as e, EnvImpl as f, Time as g, TimeUnits as h };
|
package/utils/index.js
CHANGED
package/web/index.cjs
CHANGED
@@ -23,7 +23,6 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
|
|
23
23
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
24
24
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
25
25
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
26
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
27
26
|
|
28
27
|
// src/web/index.ts
|
29
28
|
var web_exports = {};
|
@@ -215,170 +214,285 @@ var WrapperSysAbstraction = class {
|
|
215
214
|
}
|
216
215
|
};
|
217
216
|
|
217
|
+
// src/future.ts
|
218
|
+
var _promise, _resolveFn, _rejectFn;
|
219
|
+
var Future = class {
|
220
|
+
constructor() {
|
221
|
+
__privateAdd(this, _promise);
|
222
|
+
__privateAdd(this, _resolveFn, () => {
|
223
|
+
throw new Error("This Promise is not working as expected.");
|
224
|
+
});
|
225
|
+
__privateAdd(this, _rejectFn, () => {
|
226
|
+
throw new Error("This Promise is not working as expected.");
|
227
|
+
});
|
228
|
+
__privateSet(this, _promise, new Promise((resolve, reject) => {
|
229
|
+
__privateSet(this, _resolveFn, resolve);
|
230
|
+
__privateSet(this, _rejectFn, reject);
|
231
|
+
}));
|
232
|
+
}
|
233
|
+
async asPromise() {
|
234
|
+
return __privateGet(this, _promise);
|
235
|
+
}
|
236
|
+
resolve(value) {
|
237
|
+
__privateGet(this, _resolveFn).call(this, value);
|
238
|
+
}
|
239
|
+
reject(reason) {
|
240
|
+
__privateGet(this, _rejectFn).call(this, reason);
|
241
|
+
}
|
242
|
+
};
|
243
|
+
_promise = new WeakMap();
|
244
|
+
_resolveFn = new WeakMap();
|
245
|
+
_rejectFn = new WeakMap();
|
246
|
+
|
247
|
+
// src/resolve-once.ts
|
248
|
+
var ResolveOnce = class {
|
249
|
+
constructor(ctx) {
|
250
|
+
this._onceDone = false;
|
251
|
+
this._onceFutures = [];
|
252
|
+
this._onceOk = false;
|
253
|
+
this._isPromise = false;
|
254
|
+
this.ctx = ctx;
|
255
|
+
}
|
256
|
+
get ready() {
|
257
|
+
return this._onceDone;
|
258
|
+
}
|
259
|
+
reset() {
|
260
|
+
this._onceDone = false;
|
261
|
+
this._onceOk = false;
|
262
|
+
this._onceValue = void 0;
|
263
|
+
this._onceError = void 0;
|
264
|
+
this._onceFutures.length = 0;
|
265
|
+
}
|
266
|
+
// T extends Option<infer U> ? U : T
|
267
|
+
once(fn) {
|
268
|
+
if (this._onceDone) {
|
269
|
+
if (this._onceError) {
|
270
|
+
if (this._isPromise) {
|
271
|
+
return Promise.reject(this._onceError);
|
272
|
+
} else {
|
273
|
+
throw this._onceError;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
if (this._onceOk) {
|
277
|
+
if (this._isPromise) {
|
278
|
+
return Promise.resolve(this._onceValue);
|
279
|
+
} else {
|
280
|
+
return this._onceValue;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
throw new Error("ResolveOnce.once impossible");
|
284
|
+
}
|
285
|
+
const future = new Future();
|
286
|
+
this._onceFutures.push(future);
|
287
|
+
if (this._onceFutures.length === 1) {
|
288
|
+
const okFn = (value) => {
|
289
|
+
this._onceValue = value;
|
290
|
+
this._onceOk = true;
|
291
|
+
this._onceDone = true;
|
292
|
+
if (this._isPromise) {
|
293
|
+
this._onceFutures.forEach((f) => f.resolve(this._onceValue));
|
294
|
+
}
|
295
|
+
this._onceFutures.length = 0;
|
296
|
+
};
|
297
|
+
const catchFn = (e) => {
|
298
|
+
this._onceError = e;
|
299
|
+
this._onceOk = false;
|
300
|
+
this._onceValue = void 0;
|
301
|
+
this._onceDone = true;
|
302
|
+
if (this._isPromise) {
|
303
|
+
this._onceFutures.forEach((f) => f.reject(this._onceError));
|
304
|
+
}
|
305
|
+
this._onceFutures.length = 0;
|
306
|
+
};
|
307
|
+
try {
|
308
|
+
const ret = fn(this.ctx);
|
309
|
+
if (typeof ret.then === "function") {
|
310
|
+
this._isPromise = true;
|
311
|
+
ret.then(okFn).catch(catchFn);
|
312
|
+
} else {
|
313
|
+
okFn(ret);
|
314
|
+
}
|
315
|
+
} catch (e) {
|
316
|
+
catchFn(e);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
if (this._isPromise) {
|
320
|
+
return future.asPromise();
|
321
|
+
} else {
|
322
|
+
return this.once(fn);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
};
|
326
|
+
|
218
327
|
// src/sys_env.ts
|
219
|
-
var _node
|
328
|
+
var _node;
|
220
329
|
var NodeEnvActions = class {
|
221
330
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
|
222
331
|
constructor(opts) {
|
223
332
|
__privateAdd(this, _node, globalThis);
|
224
|
-
|
333
|
+
this._env = this.active() ? __privateGet(this, _node).process.env : {};
|
334
|
+
}
|
335
|
+
register(env) {
|
336
|
+
return env;
|
225
337
|
}
|
226
|
-
|
338
|
+
active() {
|
227
339
|
return typeof __privateGet(this, _node) === "object" && typeof __privateGet(this, _node).process === "object" && typeof __privateGet(this, _node).process.env === "object";
|
228
340
|
}
|
229
341
|
keys() {
|
230
|
-
return Object.keys(
|
342
|
+
return Object.keys(this._env);
|
231
343
|
}
|
232
344
|
get(key) {
|
233
|
-
return
|
345
|
+
return this._env[key];
|
234
346
|
}
|
235
347
|
set(key, value) {
|
236
348
|
if (value) {
|
237
|
-
|
349
|
+
this._env[key] = value;
|
238
350
|
}
|
239
351
|
}
|
240
|
-
|
241
|
-
delete
|
352
|
+
delete(key) {
|
353
|
+
delete this._env[key];
|
242
354
|
}
|
243
355
|
};
|
244
356
|
_node = new WeakMap();
|
245
|
-
|
246
|
-
var _deno, _env2;
|
357
|
+
var _deno;
|
247
358
|
var DenoEnvActions = class {
|
248
|
-
constructor
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
|
360
|
+
constructor(opts) {
|
249
361
|
__privateAdd(this, _deno, globalThis);
|
250
|
-
__privateAdd(this, _env2);
|
251
|
-
if (env) {
|
252
|
-
__privateSet(this, _env2, env);
|
253
|
-
} else {
|
254
|
-
__privateSet(this, _env2, this.use() ? __privateGet(this, _deno).Deno.env : /* @__PURE__ */ new Map());
|
255
|
-
}
|
256
362
|
}
|
257
|
-
|
363
|
+
get _env() {
|
364
|
+
return __privateGet(this, _deno).Deno.env;
|
365
|
+
}
|
366
|
+
register(env) {
|
367
|
+
return env;
|
368
|
+
}
|
369
|
+
active() {
|
258
370
|
return typeof __privateGet(this, _deno) === "object" && typeof __privateGet(this, _deno).Deno === "object" && typeof __privateGet(this, _deno).Deno.env === "object";
|
259
371
|
}
|
260
372
|
keys() {
|
261
|
-
return Array.from(
|
373
|
+
return Array.from(this._env.keys());
|
262
374
|
}
|
263
375
|
get(key) {
|
264
|
-
return
|
376
|
+
return this._env.get(key);
|
265
377
|
}
|
266
378
|
set(key, value) {
|
267
379
|
if (value) {
|
268
|
-
|
380
|
+
this._env.set(key, value);
|
269
381
|
}
|
270
382
|
}
|
271
|
-
|
272
|
-
|
383
|
+
delete(key) {
|
384
|
+
this._env.delete(key);
|
273
385
|
}
|
274
386
|
};
|
275
387
|
_deno = new WeakMap();
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
388
|
+
var BrowserEnvActions = class {
|
389
|
+
constructor(opts) {
|
390
|
+
this.env = /* @__PURE__ */ new Map();
|
391
|
+
this.opts = opts;
|
392
|
+
}
|
393
|
+
get(key) {
|
394
|
+
return this.env.get(key);
|
395
|
+
}
|
396
|
+
set(key, value) {
|
397
|
+
if (value) {
|
398
|
+
this.env.set(key, value);
|
282
399
|
}
|
283
|
-
const map = /* @__PURE__ */ new Map();
|
284
|
-
return {
|
285
|
-
map,
|
286
|
-
finalize: (bea) => {
|
287
|
-
browser[sym] = bea;
|
288
|
-
return map;
|
289
|
-
}
|
290
|
-
};
|
291
400
|
}
|
292
|
-
|
293
|
-
|
294
|
-
super(opts, map);
|
295
|
-
this._map = finalize(this);
|
401
|
+
delete(key) {
|
402
|
+
this.env.delete(key);
|
296
403
|
}
|
297
|
-
|
404
|
+
keys() {
|
405
|
+
return Array.from(this.env.keys());
|
406
|
+
}
|
407
|
+
active() {
|
298
408
|
return true;
|
299
409
|
}
|
410
|
+
register(env) {
|
411
|
+
const sym = Symbol.for(this.opts.symbol || "CP_ENV");
|
412
|
+
const browser = globalThis;
|
413
|
+
browser[sym] = env;
|
414
|
+
return env;
|
415
|
+
}
|
300
416
|
};
|
417
|
+
var _envFactory = new ResolveOnce();
|
301
418
|
function envFactory(opts = {}) {
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
419
|
+
return _envFactory.once(() => {
|
420
|
+
const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.active());
|
421
|
+
if (!found) {
|
422
|
+
throw new Error("SysContainer:envFactory: no env available");
|
423
|
+
}
|
424
|
+
const ret = new EnvImpl(found, opts);
|
425
|
+
found.register(ret);
|
426
|
+
return ret;
|
427
|
+
});
|
307
428
|
}
|
308
|
-
var _envImpl, _EnvImpl_instances, updatePresets_fn, applyOnSet_fn, _onSet;
|
309
429
|
var EnvImpl = class {
|
310
|
-
constructor(opts = {}) {
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
430
|
+
constructor(map, opts = {}) {
|
431
|
+
this._onSet = [];
|
432
|
+
this._map = map;
|
433
|
+
this._updatePresets(opts.presetEnv);
|
434
|
+
}
|
435
|
+
_updatePresets(presetEnv) {
|
436
|
+
if (!presetEnv) {
|
437
|
+
return;
|
438
|
+
}
|
439
|
+
for (const [key, value] of presetEnv) {
|
440
|
+
this._map.set(key, value);
|
441
|
+
}
|
442
|
+
}
|
443
|
+
_applyOnSet(onSet, key, value) {
|
444
|
+
onSet.forEach((item) => {
|
445
|
+
let keys = [];
|
446
|
+
if (key) {
|
447
|
+
keys = [key];
|
448
|
+
} else {
|
449
|
+
keys = this._map.keys();
|
450
|
+
}
|
451
|
+
keys.filter((k) => {
|
452
|
+
if (item.filter.size === 0) {
|
453
|
+
return true;
|
454
|
+
}
|
455
|
+
if (item.filter.has(k)) {
|
456
|
+
return true;
|
457
|
+
}
|
458
|
+
return false;
|
459
|
+
}).forEach((k) => {
|
460
|
+
let v;
|
461
|
+
if (!key && !value) {
|
462
|
+
v = this._map.get(k);
|
463
|
+
} else if (key && !value) {
|
464
|
+
v = void 0;
|
465
|
+
} else {
|
466
|
+
v = value;
|
467
|
+
}
|
468
|
+
item.fn(k, v);
|
469
|
+
});
|
470
|
+
});
|
316
471
|
}
|
317
472
|
keys() {
|
318
|
-
return
|
473
|
+
return this._map.keys();
|
319
474
|
}
|
320
475
|
// filter is not set all sets passed
|
321
476
|
onSet(fn, ...filter) {
|
322
477
|
const item = { filter: new Set(filter), fn };
|
323
|
-
|
324
|
-
|
478
|
+
this._onSet.push(item);
|
479
|
+
this._applyOnSet([item]);
|
325
480
|
}
|
326
481
|
get(key) {
|
327
|
-
return
|
482
|
+
return this._map.get(key);
|
328
483
|
}
|
329
484
|
set(key, value) {
|
330
485
|
if (!value) {
|
331
486
|
return;
|
332
487
|
}
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
del(key) {
|
337
|
-
__privateGet(this, _envImpl).del(key);
|
338
|
-
__privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, __privateGet(this, _onSet), key);
|
488
|
+
this._map.set(key, value);
|
489
|
+
this._applyOnSet(this._onSet, key, value);
|
339
490
|
}
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
updatePresets_fn = function(presetEnv) {
|
344
|
-
if (!presetEnv) {
|
345
|
-
return;
|
346
|
-
}
|
347
|
-
for (const [key, value] of presetEnv) {
|
348
|
-
__privateGet(this, _envImpl).set(key, value);
|
491
|
+
delete(key) {
|
492
|
+
this._map.delete(key);
|
493
|
+
this._applyOnSet(this._onSet, key);
|
349
494
|
}
|
350
495
|
};
|
351
|
-
applyOnSet_fn = function(onSet, key, value) {
|
352
|
-
onSet.forEach((item) => {
|
353
|
-
let keys = [];
|
354
|
-
if (key) {
|
355
|
-
keys = [key];
|
356
|
-
} else {
|
357
|
-
keys = __privateGet(this, _envImpl).keys();
|
358
|
-
}
|
359
|
-
keys.filter((k) => {
|
360
|
-
if (item.filter.size === 0) {
|
361
|
-
return true;
|
362
|
-
}
|
363
|
-
if (item.filter.has(k)) {
|
364
|
-
return true;
|
365
|
-
}
|
366
|
-
return false;
|
367
|
-
}).forEach((k) => {
|
368
|
-
let v;
|
369
|
-
if (!key && !value) {
|
370
|
-
v = __privateGet(this, _envImpl).get(k);
|
371
|
-
} else if (key && !value) {
|
372
|
-
v = void 0;
|
373
|
-
} else {
|
374
|
-
v = value;
|
375
|
-
}
|
376
|
-
item.fn(k, v);
|
377
|
-
});
|
378
|
-
});
|
379
|
-
};
|
380
|
-
_onSet = new WeakMap();
|
381
|
-
var envImpl = new EnvImpl();
|
382
496
|
|
383
497
|
// src/web/web_sys_abstraction.ts
|
384
498
|
var WebFileService = class {
|
@@ -428,7 +542,7 @@ var WebFileService = class {
|
|
428
542
|
};
|
429
543
|
var WebSystemService = class {
|
430
544
|
Env() {
|
431
|
-
return
|
545
|
+
return envFactory();
|
432
546
|
}
|
433
547
|
Args() {
|
434
548
|
throw new Error("Args-Method not implemented.");
|