@adviser/cement 0.1.26 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import { V as VoidFunc, T as TimeMode, I as IDMode, R as RandomMode, F as FileService, b as SystemService } from './sys_abstraction-CjljYIkv.cjs';
1
+ import { V as VoidFunc, T as TimeMode, I as IDMode, R as RandomMode, F as FileService, b as SystemService } from './sys_abstraction-BzkoCY1p.cjs';
2
2
 
3
3
  interface ExitHandler {
4
4
  readonly hdl: VoidFunc;
@@ -1,4 +1,4 @@
1
- import { V as VoidFunc, T as TimeMode, I as IDMode, R as RandomMode, F as FileService, b as SystemService } from './sys_abstraction-CjljYIkv.js';
1
+ import { V as VoidFunc, T as TimeMode, I as IDMode, R as RandomMode, F as FileService, b as SystemService } from './sys_abstraction-BzkoCY1p.js';
2
2
 
3
3
  interface ExitHandler {
4
4
  readonly hdl: VoidFunc;
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  BaseSysAbstraction,
3
- WrapperSysAbstraction
4
- } from "./chunk-PZTL4UNG.js";
3
+ WrapperSysAbstraction,
4
+ envImpl
5
+ } from "./chunk-RSXHMWBX.js";
5
6
 
6
7
  // src/web/web_sys_abstraction.ts
7
8
  var WebFileService = class {
@@ -51,7 +52,7 @@ var WebFileService = class {
51
52
  };
52
53
  var WebSystemService = class {
53
54
  Env() {
54
- throw new Error("Env-Method not implemented.");
55
+ return envImpl;
55
56
  }
56
57
  Args() {
57
58
  throw new Error("Args-Method not implemented.");
@@ -79,4 +80,4 @@ function WebSysAbstraction(param) {
79
80
  export {
80
81
  WebSysAbstraction
81
82
  };
82
- //# sourceMappingURL=chunk-MWAFFTM4.js.map
83
+ //# sourceMappingURL=chunk-GX6QZCII.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/web_sys_abstraction.ts"],"sourcesContent":["import { BaseSysAbstraction, WrapperSysAbstraction, WrapperSysAbstractionParams } from \"../base_sys_abstraction\";\nimport { FileService, NamedWritableStream } from \"../file_service\";\nimport { SysAbstraction, SystemService, VoidFunc } from \"../sys_abstraction\";\nimport { envImpl } from \"../sys_env\";\n\nclass WebFileService implements FileService {\n get baseDir(): string {\n throw new Error(\"basedir-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n create(fname: string): Promise<NamedWritableStream> {\n throw new Error(\"create-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n readFileString(fname: string): Promise<string> {\n throw new Error(\"readFileString-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n writeFileString(fname: string, content: string): Promise<void> {\n throw new Error(\"writeFileString-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abs(fname: string): string {\n throw new Error(\"abs-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n join(...paths: string[]): string {\n throw new Error(\"join-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n relative(from: string, to?: string | undefined): string {\n throw new Error(\"relative-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dirname(fname: string): string {\n throw new Error(\"dirname-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n basename(fname: string): string {\n throw new Error(\"basename-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n nodeImport(fname: string): string {\n throw new Error(\"nodeImport-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isAbsolute(fname: string): boolean {\n throw new Error(\"isAbsolute-Method not implemented.\");\n }\n}\n\nclass WebSystemService implements SystemService {\n Env() {\n return envImpl;\n }\n Args(): string[] {\n throw new Error(\"Args-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n OnExit(hdl: VoidFunc): VoidFunc {\n throw new Error(\"OnExit-Method not implemented.\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Exit(code: number): void {\n throw new Error(\"Exit-Method not implemented.\");\n }\n}\n\nlet my: BaseSysAbstraction | undefined = undefined;\nexport function WebSysAbstraction(param?: WrapperSysAbstractionParams): SysAbstraction {\n if (!my) {\n my = new BaseSysAbstraction({\n FileSystem: new WebFileService(),\n SystemService: new WebSystemService(),\n });\n }\n return new WrapperSysAbstraction(my, param);\n}\n"],"mappings":";;;;;;;AAKA,IAAM,iBAAN,MAA4C;AAAA,EAC1C,IAAI,UAAkB;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAAA;AAAA,EAEA,OAAO,OAA6C;AAClD,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAAA;AAAA,EAEA,eAAe,OAAgC;AAC7C,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AAAA;AAAA,EAEA,gBAAgB,OAAe,SAAgC;AAC7D,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AAAA;AAAA,EAEA,IAAI,OAAuB;AACzB,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAAA;AAAA,EAEA,QAAQ,OAAyB;AAC/B,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAAA;AAAA,EAEA,SAAS,MAAc,IAAiC;AACtD,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAAA;AAAA,EAEA,QAAQ,OAAuB;AAC7B,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAAA;AAAA,EAEA,SAAS,OAAuB;AAC9B,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAAA;AAAA,EAEA,WAAW,OAAuB;AAChC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAAA;AAAA,EAEA,WAAW,OAAwB;AACjC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACF;AAEA,IAAM,mBAAN,MAAgD;AAAA,EAC9C,MAAM;AACJ,WAAO;AAAA,EACT;AAAA,EACA,OAAiB;AACf,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAAA;AAAA,EAEA,OAAO,KAAyB;AAC9B,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAAA;AAAA,EAEA,KAAK,MAAoB;AACvB,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACF;AAEA,IAAI,KAAqC;AAClC,SAAS,kBAAkB,OAAqD;AACrF,MAAI,CAAC,IAAI;AACP,SAAK,IAAI,mBAAmB;AAAA,MAC1B,YAAY,IAAI,eAAe;AAAA,MAC/B,eAAe,IAAI,iBAAiB;AAAA,IACtC,CAAC;AAAA,EACH;AACA,SAAO,IAAI,sBAAsB,IAAI,KAAK;AAC5C;","names":[]}
@@ -1,3 +1,10 @@
1
+ import {
2
+ __privateAdd,
3
+ __privateGet,
4
+ __privateMethod,
5
+ __privateSet
6
+ } from "./chunk-ZYFWDQGV.js";
7
+
1
8
  // src/sys_abstraction.ts
2
9
  var TimeMode = /* @__PURE__ */ ((TimeMode2) => {
3
10
  TimeMode2["REAL"] = "real";
@@ -45,6 +52,163 @@ var TimeUnits = /* @__PURE__ */ ((TimeUnits2) => {
45
52
  return TimeUnits2;
46
53
  })(TimeUnits || {});
47
54
 
55
+ // src/sys_env.ts
56
+ var _node, _env;
57
+ var NodeEnvActions = class {
58
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
59
+ constructor(opts) {
60
+ __privateAdd(this, _node, globalThis);
61
+ __privateAdd(this, _env, this.use() ? process.env : {});
62
+ }
63
+ use() {
64
+ return typeof __privateGet(this, _node) === "object" && typeof __privateGet(this, _node).process === "object" && typeof __privateGet(this, _node).process.env === "object";
65
+ }
66
+ keys() {
67
+ return Object.keys(__privateGet(this, _env));
68
+ }
69
+ get(key) {
70
+ return __privateGet(this, _env)[key];
71
+ }
72
+ set(key, value) {
73
+ if (value) {
74
+ __privateGet(this, _env)[key] = value;
75
+ }
76
+ }
77
+ del(key) {
78
+ delete __privateGet(this, _env)[key];
79
+ }
80
+ };
81
+ _node = new WeakMap();
82
+ _env = new WeakMap();
83
+ var _deno, _env2;
84
+ var DenoEnvActions = class {
85
+ constructor(opts, env) {
86
+ __privateAdd(this, _deno, globalThis);
87
+ __privateAdd(this, _env2);
88
+ if (env) {
89
+ __privateSet(this, _env2, env);
90
+ } else {
91
+ __privateSet(this, _env2, this.use() ? __privateGet(this, _deno).Deno.env : /* @__PURE__ */ new Map());
92
+ }
93
+ }
94
+ use() {
95
+ return typeof __privateGet(this, _deno) === "object" && typeof __privateGet(this, _deno).Deno === "object" && typeof __privateGet(this, _deno).Deno.env === "object";
96
+ }
97
+ keys() {
98
+ return Array.from(__privateGet(this, _env2).keys());
99
+ }
100
+ get(key) {
101
+ return __privateGet(this, _env2).get(key);
102
+ }
103
+ set(key, value) {
104
+ if (value) {
105
+ __privateGet(this, _env2).set(key, value);
106
+ }
107
+ }
108
+ del(key) {
109
+ __privateGet(this, _env2).delete(key);
110
+ }
111
+ };
112
+ _deno = new WeakMap();
113
+ _env2 = new WeakMap();
114
+ var BrowserEnvActions = class _BrowserEnvActions extends DenoEnvActions {
115
+ static getEnv(sym) {
116
+ const browser = globalThis;
117
+ if (typeof browser === "object" && typeof browser[sym] === "object") {
118
+ return browser[sym];
119
+ }
120
+ browser[sym] = /* @__PURE__ */ new Map();
121
+ return browser[sym];
122
+ }
123
+ constructor(opts) {
124
+ super(opts, _BrowserEnvActions.getEnv(Symbol.for(opts.symbol || "CP_ENV")));
125
+ }
126
+ use() {
127
+ return true;
128
+ }
129
+ };
130
+ function envFactory(opts = {}) {
131
+ const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());
132
+ if (!found) {
133
+ throw new Error("SysContainer:envFactory: no env available");
134
+ }
135
+ return found;
136
+ }
137
+ var _envImpl, _EnvImpl_instances, updatePresets_fn, applyOnSet_fn, _onSet;
138
+ var EnvImpl = class {
139
+ constructor(opts = {}) {
140
+ __privateAdd(this, _EnvImpl_instances);
141
+ __privateAdd(this, _envImpl);
142
+ __privateAdd(this, _onSet, []);
143
+ __privateSet(this, _envImpl, envFactory(opts));
144
+ __privateMethod(this, _EnvImpl_instances, updatePresets_fn).call(this, opts.presetEnv);
145
+ }
146
+ keys() {
147
+ return __privateGet(this, _envImpl).keys();
148
+ }
149
+ // filter is not set all sets passed
150
+ onSet(fn, ...filter) {
151
+ const item = { filter: new Set(filter), fn };
152
+ __privateGet(this, _onSet).push(item);
153
+ __privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, [item]);
154
+ }
155
+ get(key) {
156
+ return __privateGet(this, _envImpl).get(key);
157
+ }
158
+ set(key, value) {
159
+ if (!value) {
160
+ return;
161
+ }
162
+ __privateGet(this, _envImpl).set(key, value);
163
+ __privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, __privateGet(this, _onSet), key, value);
164
+ }
165
+ del(key) {
166
+ __privateGet(this, _envImpl).del(key);
167
+ __privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, __privateGet(this, _onSet), key);
168
+ }
169
+ };
170
+ _envImpl = new WeakMap();
171
+ _EnvImpl_instances = new WeakSet();
172
+ updatePresets_fn = function(presetEnv) {
173
+ if (!presetEnv) {
174
+ return;
175
+ }
176
+ for (const [key, value] of presetEnv) {
177
+ __privateGet(this, _envImpl).set(key, value);
178
+ }
179
+ };
180
+ applyOnSet_fn = function(onSet, key, value) {
181
+ onSet.forEach((item) => {
182
+ let keys = [];
183
+ if (key) {
184
+ keys = [key];
185
+ } else {
186
+ keys = __privateGet(this, _envImpl).keys();
187
+ }
188
+ keys.filter((k) => {
189
+ if (item.filter.size === 0) {
190
+ return true;
191
+ }
192
+ if (item.filter.has(k)) {
193
+ return true;
194
+ }
195
+ return false;
196
+ }).forEach((k) => {
197
+ let v;
198
+ if (!key && !value) {
199
+ v = __privateGet(this, _envImpl).get(k);
200
+ } else if (key && !value) {
201
+ v = void 0;
202
+ } else {
203
+ v = value;
204
+ }
205
+ item.fn(k, v);
206
+ });
207
+ });
208
+ };
209
+ _onSet = new WeakMap();
210
+ var envImpl = new EnvImpl();
211
+
48
212
  // src/base_sys_abstraction.ts
49
213
  var SysTime = class extends Time {
50
214
  Now() {
@@ -228,6 +392,8 @@ export {
228
392
  Time,
229
393
  TimeUnits,
230
394
  BaseSysAbstraction,
231
- WrapperSysAbstraction
395
+ WrapperSysAbstraction,
396
+ EnvImpl,
397
+ envImpl
232
398
  };
233
- //# sourceMappingURL=chunk-PZTL4UNG.js.map
399
+ //# sourceMappingURL=chunk-RSXHMWBX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sys_abstraction.ts","../../src/time.ts","../../src/sys_env.ts","../../src/base_sys_abstraction.ts"],"sourcesContent":["import { FileService } from \"./file_service\";\nimport { Env } from \"./sys_env\";\nimport { Time } from \"./time\";\n\nexport enum TimeMode {\n REAL = \"real\",\n CONST = \"const\",\n STEP = \"step\",\n}\n\nexport enum RandomMode {\n CONST = \"const\",\n STEP = \"step\",\n RANDOM = \"random\",\n}\n\nexport enum IDMode {\n UUID = \"uuid\",\n CONST = \"const\",\n STEP = \"step\",\n}\n\nexport function String2TimeMode(s?: string): TimeMode {\n switch (s?.toLowerCase()) {\n case \"real\":\n return TimeMode.REAL;\n case \"const\":\n return TimeMode.CONST;\n case \"step\":\n return TimeMode.STEP;\n default:\n return TimeMode.REAL;\n }\n}\n\nexport type VoidFunc = () => void | Promise<void>;\n\nexport interface SystemService {\n Env(): Env;\n Args(): string[];\n OnExit(hdl: VoidFunc): VoidFunc;\n Exit(code: number): void;\n}\n\nexport interface SysAbstraction {\n Time(): Time;\n Stdout(): WritableStream<Uint8Array>;\n Stderr(): WritableStream<Uint8Array>;\n NextId(): string;\n Random0ToValue(value: number): number;\n System(): SystemService;\n FileSystem(): FileService;\n}\n","export abstract class Time {\n abstract Now(): 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","export interface EnvActions {\n get(key: string): string | undefined;\n set(key: string, value?: string): void;\n del(key: string): void;\n keys(): string[];\n use(): boolean;\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 use(): boolean {\n return typeof this.#node === \"object\" && typeof this.#node.process === \"object\" && typeof this.#node.process.env === \"object\";\n }\n readonly #env = this.use() ? 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 del(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 readonly #env: Map<string, string>;\n constructor(opts: Partial<EnvFactoryOpts>, env?: Map<string, string>) {\n if (env) {\n this.#env = env;\n } else {\n this.#env = this.use() ? this.#deno.Deno.env : new Map();\n }\n }\n use(): 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 del(key: string): void {\n this.#env.delete(key);\n }\n}\n\nclass BrowserEnvActions extends DenoEnvActions {\n static getEnv(sym: symbol) {\n const browser = globalThis as unknown as Record<symbol, Map<string, string>>;\n if (typeof browser === \"object\" && typeof browser[sym] === \"object\") {\n return browser[sym];\n }\n browser[sym] = new Map();\n return browser[sym];\n }\n\n constructor(opts: Partial<EnvFactoryOpts>) {\n // not perfect the globalThis will be polluted\n // also in the case it is not need.\n // better we have a lazy init\n super(opts, BrowserEnvActions.getEnv(Symbol.for(opts.symbol || \"CP_ENV\")));\n }\n use(): boolean {\n return true;\n }\n}\n\ninterface EnvFactoryOpts {\n readonly symbol: string; // default \"CP_ENV\" used by BrowserEnvActions\n readonly presetEnv: Map<string, string>;\n}\n\nfunction envFactory(opts: Partial<EnvFactoryOpts> = {}): EnvActions {\n const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());\n if (!found) {\n throw new Error(\"SysContainer:envFactory: no env available\");\n }\n return found;\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 Omit<EnvActions, \"use\"> {\n onSet(fn: OnSetFn, ...filter: string[]): void;\n}\n\nexport class EnvImpl implements Env {\n readonly #envImpl: EnvActions;\n constructor(opts: Partial<EnvFactoryOpts> = {}) {\n this.#envImpl = envFactory(opts);\n // do nothing\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.#envImpl.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.#envImpl.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.#envImpl.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.#envImpl.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.#envImpl.get(key);\n }\n set(key: string, value?: string): void {\n if (!value) {\n return;\n }\n this.#envImpl.set(key, value);\n this.#applyOnSet(this.#onSet, key, value);\n }\n del(key: string): void {\n this.#envImpl.del(key);\n this.#applyOnSet(this.#onSet, key);\n }\n}\n\nexport const envImpl = new EnvImpl();\n","import { FileService } from \"./file_service\";\nimport { TimeMode, RandomMode, IDMode, SystemService, VoidFunc, SysAbstraction } from \"./sys_abstraction\";\nimport { Time } from \"./time\";\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 constructor() {\n super();\n this._step = new ConstTime().Now();\n }\n Now() {\n if (this._step.getTime() === 0) {\n this._step = new ConstTime().Now();\n return this._step;\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 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\nconst decoder = new TextDecoder();\nexport class BaseSysAbstraction {\n readonly _time = new SysTime();\n readonly _stdout = new WritableStream({\n write(chunk) {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n console.log(decoded.trimEnd());\n resolve();\n });\n },\n });\n readonly _stderr = new WritableStream({\n write(chunk) {\n return new Promise((resolve) => {\n const decoded = decoder.decode(chunk);\n console.error(decoded.trimEnd());\n resolve();\n });\n },\n });\n\n readonly _idService = new IdService();\n readonly _randomService = new RandomService(RandomMode.RANDOM);\n readonly _fileSystem: FileService;\n readonly _systemService: SystemService;\n\n constructor(params: BaseSysAbstractionParams) {\n this._fileSystem = params.FileSystem;\n this._systemService = params.SystemService;\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}\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"],"mappings":";;;;;;;;AAIO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAML,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AAML,IAAK,S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OAAO,YAAY;AACrB,aAAK,iBAAiB,IAAI,cAAc,OAAO,UAAU;AAAA,MAC3D;AACA,UAAI,OAAO,YAAY;AACrB,aAAK,cAAc,OAAO;AAAA,MAC5B;AACA,UAAI,OAAO,eAAe;AACxB,aAAK,iBAAiB,OAAO;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAa;AACX,WAAO,KAAK;AAAA,EACd;AAAA,EACA,SAAiB;AACf,WAAO,KAAK,WAAW,OAAO;AAAA,EAChC;AAAA,EACA,eAAe,OAAuB;AACpC,WAAO,KAAK,eAAe,eAAe,KAAK;AAAA,EACjD;AAAA,EACA,SAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,SAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAAwB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,aAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;","names":["TimeMode","RandomMode","IDMode","TimeUnits","_env"]}
@@ -22,6 +22,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
22
22
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
23
23
  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);
24
24
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
25
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
25
26
  var __await = function(promise, isYieldStar) {
26
27
  this[0] = promise;
27
28
  this[1] = isYieldStar;
@@ -60,6 +61,7 @@ export {
60
61
  __privateGet,
61
62
  __privateAdd,
62
63
  __privateSet,
64
+ __privateMethod,
63
65
  __yieldStar
64
66
  };
65
- //# sourceMappingURL=chunk-J2IM7FHM.js.map
67
+ //# sourceMappingURL=chunk-ZYFWDQGV.js.map
package/index.cjs CHANGED
@@ -38,6 +38,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
38
38
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
39
39
  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);
40
40
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
41
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
41
42
  var __await = function(promise, isYieldStar) {
42
43
  this[0] = promise;
43
44
  this[1] = isYieldStar;
@@ -74,6 +75,7 @@ var __yieldStar = (value) => {
74
75
  // src/index.ts
75
76
  var src_exports = {};
76
77
  __export(src_exports, {
78
+ EnvImpl: () => EnvImpl,
77
79
  Future: () => Future,
78
80
  IDMode: () => IDMode,
79
81
  IsLogger: () => IsLogger,
@@ -98,7 +100,8 @@ __export(src_exports, {
98
100
  String2TimeMode: () => String2TimeMode,
99
101
  Time: () => Time,
100
102
  TimeMode: () => TimeMode,
101
- TimeUnits: () => TimeUnits
103
+ TimeUnits: () => TimeUnits,
104
+ envImpl: () => envImpl
102
105
  });
103
106
  module.exports = __toCommonJS(src_exports);
104
107
 
@@ -353,6 +356,163 @@ var WrapperSysAbstraction = class {
353
356
  }
354
357
  };
355
358
 
359
+ // src/sys_env.ts
360
+ var _node, _env;
361
+ var NodeEnvActions = class {
362
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
363
+ constructor(opts) {
364
+ __privateAdd(this, _node, globalThis);
365
+ __privateAdd(this, _env, this.use() ? process.env : {});
366
+ }
367
+ use() {
368
+ return typeof __privateGet(this, _node) === "object" && typeof __privateGet(this, _node).process === "object" && typeof __privateGet(this, _node).process.env === "object";
369
+ }
370
+ keys() {
371
+ return Object.keys(__privateGet(this, _env));
372
+ }
373
+ get(key) {
374
+ return __privateGet(this, _env)[key];
375
+ }
376
+ set(key, value) {
377
+ if (value) {
378
+ __privateGet(this, _env)[key] = value;
379
+ }
380
+ }
381
+ del(key) {
382
+ delete __privateGet(this, _env)[key];
383
+ }
384
+ };
385
+ _node = new WeakMap();
386
+ _env = new WeakMap();
387
+ var _deno, _env2;
388
+ var DenoEnvActions = class {
389
+ constructor(opts, env) {
390
+ __privateAdd(this, _deno, globalThis);
391
+ __privateAdd(this, _env2);
392
+ if (env) {
393
+ __privateSet(this, _env2, env);
394
+ } else {
395
+ __privateSet(this, _env2, this.use() ? __privateGet(this, _deno).Deno.env : /* @__PURE__ */ new Map());
396
+ }
397
+ }
398
+ use() {
399
+ return typeof __privateGet(this, _deno) === "object" && typeof __privateGet(this, _deno).Deno === "object" && typeof __privateGet(this, _deno).Deno.env === "object";
400
+ }
401
+ keys() {
402
+ return Array.from(__privateGet(this, _env2).keys());
403
+ }
404
+ get(key) {
405
+ return __privateGet(this, _env2).get(key);
406
+ }
407
+ set(key, value) {
408
+ if (value) {
409
+ __privateGet(this, _env2).set(key, value);
410
+ }
411
+ }
412
+ del(key) {
413
+ __privateGet(this, _env2).delete(key);
414
+ }
415
+ };
416
+ _deno = new WeakMap();
417
+ _env2 = new WeakMap();
418
+ var BrowserEnvActions = class _BrowserEnvActions extends DenoEnvActions {
419
+ static getEnv(sym) {
420
+ const browser = globalThis;
421
+ if (typeof browser === "object" && typeof browser[sym] === "object") {
422
+ return browser[sym];
423
+ }
424
+ browser[sym] = /* @__PURE__ */ new Map();
425
+ return browser[sym];
426
+ }
427
+ constructor(opts) {
428
+ super(opts, _BrowserEnvActions.getEnv(Symbol.for(opts.symbol || "CP_ENV")));
429
+ }
430
+ use() {
431
+ return true;
432
+ }
433
+ };
434
+ function envFactory(opts = {}) {
435
+ const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.use());
436
+ if (!found) {
437
+ throw new Error("SysContainer:envFactory: no env available");
438
+ }
439
+ return found;
440
+ }
441
+ var _envImpl, _EnvImpl_instances, updatePresets_fn, applyOnSet_fn, _onSet;
442
+ var EnvImpl = class {
443
+ constructor(opts = {}) {
444
+ __privateAdd(this, _EnvImpl_instances);
445
+ __privateAdd(this, _envImpl);
446
+ __privateAdd(this, _onSet, []);
447
+ __privateSet(this, _envImpl, envFactory(opts));
448
+ __privateMethod(this, _EnvImpl_instances, updatePresets_fn).call(this, opts.presetEnv);
449
+ }
450
+ keys() {
451
+ return __privateGet(this, _envImpl).keys();
452
+ }
453
+ // filter is not set all sets passed
454
+ onSet(fn, ...filter) {
455
+ const item = { filter: new Set(filter), fn };
456
+ __privateGet(this, _onSet).push(item);
457
+ __privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, [item]);
458
+ }
459
+ get(key) {
460
+ return __privateGet(this, _envImpl).get(key);
461
+ }
462
+ set(key, value) {
463
+ if (!value) {
464
+ return;
465
+ }
466
+ __privateGet(this, _envImpl).set(key, value);
467
+ __privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, __privateGet(this, _onSet), key, value);
468
+ }
469
+ del(key) {
470
+ __privateGet(this, _envImpl).del(key);
471
+ __privateMethod(this, _EnvImpl_instances, applyOnSet_fn).call(this, __privateGet(this, _onSet), key);
472
+ }
473
+ };
474
+ _envImpl = new WeakMap();
475
+ _EnvImpl_instances = new WeakSet();
476
+ updatePresets_fn = function(presetEnv) {
477
+ if (!presetEnv) {
478
+ return;
479
+ }
480
+ for (const [key, value] of presetEnv) {
481
+ __privateGet(this, _envImpl).set(key, value);
482
+ }
483
+ };
484
+ applyOnSet_fn = function(onSet, key, value) {
485
+ onSet.forEach((item) => {
486
+ let keys = [];
487
+ if (key) {
488
+ keys = [key];
489
+ } else {
490
+ keys = __privateGet(this, _envImpl).keys();
491
+ }
492
+ keys.filter((k) => {
493
+ if (item.filter.size === 0) {
494
+ return true;
495
+ }
496
+ if (item.filter.has(k)) {
497
+ return true;
498
+ }
499
+ return false;
500
+ }).forEach((k) => {
501
+ let v;
502
+ if (!key && !value) {
503
+ v = __privateGet(this, _envImpl).get(k);
504
+ } else if (key && !value) {
505
+ v = void 0;
506
+ } else {
507
+ v = value;
508
+ }
509
+ item.fn(k, v);
510
+ });
511
+ });
512
+ };
513
+ _onSet = new WeakMap();
514
+ var envImpl = new EnvImpl();
515
+
356
516
  // src/web/web_sys_abstraction.ts
357
517
  var WebFileService = class {
358
518
  get baseDir() {
@@ -401,7 +561,7 @@ var WebFileService = class {
401
561
  };
402
562
  var WebSystemService = class {
403
563
  Env() {
404
- throw new Error("Env-Method not implemented.");
564
+ return envImpl;
405
565
  }
406
566
  Args() {
407
567
  throw new Error("Args-Method not implemented.");
@@ -1213,6 +1373,7 @@ var KeyedResolvSeq = class extends Keyed {
1213
1373
  };
1214
1374
  // Annotate the CommonJS export names for ESM import in node:
1215
1375
  0 && (module.exports = {
1376
+ EnvImpl,
1216
1377
  Future,
1217
1378
  IDMode,
1218
1379
  IsLogger,
@@ -1237,6 +1398,7 @@ var KeyedResolvSeq = class extends Keyed {
1237
1398
  String2TimeMode,
1238
1399
  Time,
1239
1400
  TimeMode,
1240
- TimeUnits
1401
+ TimeUnits,
1402
+ envImpl
1241
1403
  });
1242
1404
  //# sourceMappingURL=index.cjs.map