@adviser/cement 0.3.19 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base-sys-abstraction-DgTynXGV.d.cts +95 -0
- package/base-sys-abstraction-h0dB3nZ5.d.ts +95 -0
- package/cf/index.cjs +232 -283
- package/cf/index.cjs.map +1 -1
- package/cf/index.d.cts +10 -8
- package/cf/index.d.ts +10 -8
- package/cf/index.js +6 -41
- package/cf/index.js.map +1 -1
- package/{chunk-GDTTUMIL.js → chunk-6F3ACVHD.js} +62 -22
- package/chunk-6F3ACVHD.js.map +1 -0
- package/{chunk-PHS255C5.js → chunk-FOALXQST.js} +1 -68
- package/chunk-FOALXQST.js.map +1 -0
- package/{chunk-23MCJYE6.js → chunk-X3IV2RYT.js} +422 -602
- package/chunk-X3IV2RYT.js.map +1 -0
- package/chunk-YKGCONBX.js +677 -0
- package/chunk-YKGCONBX.js.map +1 -0
- package/{chunk-55W4AK2Z.js → chunk-YVACAIUX.js} +5 -5
- package/deno/index.cjs +257 -241
- package/deno/index.cjs.map +1 -1
- package/deno/index.d.cts +3 -5
- package/deno/index.d.ts +3 -5
- package/deno/index.js +14 -16
- package/deno/index.js.map +1 -1
- package/{index-D1j1fPYg.d.ts → index-N0bkrgSt.d.ts} +15 -3
- package/{index-Cp1NspHH.d.cts → index-TtYD7HhB.d.cts} +15 -3
- package/index.cjs +1851 -1709
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -8
- package/index.d.ts +9 -8
- package/index.js +21 -16
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +499 -474
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +3 -5
- package/node/index.d.ts +3 -5
- package/node/index.js +14 -16
- package/node/index.js.map +1 -1
- package/package.json +6 -6
- package/src/base-sys-abstraction.ts +106 -116
- package/src/cf/cf-basic-sys-abstraction.ts +79 -0
- package/src/cf/index.ts +1 -1
- package/src/cf-test-main.ts +10 -1
- package/src/deno/deno-basic-sys-abstraction.ts +39 -0
- package/src/deno/deno-file-service.ts +1 -1
- package/src/deno/deno-sys-abstraction.ts +19 -22
- package/src/jsr.json +1 -1
- package/src/log-writer-impl.ts +6 -0
- package/src/logger-impl.ts +17 -19
- package/src/node/node-basic-sys-abstraction.ts +59 -0
- package/src/node/node-sys-abstraction.ts +19 -22
- package/src/sys-abstraction.ts +12 -6
- package/src/test/mock-logger.ts +2 -2
- package/src/txt-en-decoder.ts +3 -3
- package/src/uri.ts +71 -0
- package/src/web/index.ts +1 -1
- package/src/web/web-basic-sys-abstraction.ts +105 -0
- package/{sys-abstraction-B0x6IE7r.d.ts → sys-abstraction-CeAxxg9H.d.ts} +11 -7
- package/{sys-abstraction-BTs3Vzy4.d.cts → sys-abstraction-DDAwGTnk.d.cts} +11 -7
- package/test/index.cjs +1534 -1419
- package/test/index.cjs.map +1 -1
- package/test/index.d.cts +2 -2
- package/test/index.d.ts +2 -2
- package/test/index.js +4 -5
- package/ts/smoke/smoke.js +7 -8
- package/ts/smoke/smoke.js.map +1 -1
- package/ts/src/base-basic-sys-abstraction.test.d.ts +2 -0
- package/ts/src/base-basic-sys-abstraction.test.d.ts.map +1 -0
- package/ts/src/{base-sys-abstraction.test.js → base-basic-sys-abstraction.test.js} +9 -9
- package/ts/src/base-basic-sys-abstraction.test.js.map +1 -0
- package/ts/src/base-sys-abstraction.d.ts +33 -21
- package/ts/src/base-sys-abstraction.d.ts.map +1 -1
- package/ts/src/base-sys-abstraction.js +54 -67
- package/ts/src/base-sys-abstraction.js.map +1 -1
- package/ts/src/cf/cf-basic-sys-abstraction.d.ts +14 -0
- package/ts/src/cf/cf-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/cf/cf-basic-sys-abstraction.js +67 -0
- package/ts/src/cf/cf-basic-sys-abstraction.js.map +1 -0
- package/ts/src/cf/index.d.ts +1 -1
- package/ts/src/cf/index.d.ts.map +1 -1
- package/ts/src/cf/index.js +1 -1
- package/ts/src/cf/index.js.map +1 -1
- package/ts/src/cf-test-main.d.ts.map +1 -1
- package/ts/src/cf-test-main.js +7 -1
- package/ts/src/cf-test-main.js.map +1 -1
- package/ts/src/deno/deno-basic-sys-abstraction.d.ts +14 -0
- package/ts/src/deno/deno-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/deno/deno-basic-sys-abstraction.js +35 -0
- package/ts/src/deno/deno-basic-sys-abstraction.js.map +1 -0
- package/ts/src/deno/deno-file-service.d.ts +1 -1
- package/ts/src/deno/deno-file-service.d.ts.map +1 -1
- package/ts/src/deno/deno-sys-abstraction.d.ts +3 -6
- package/ts/src/deno/deno-sys-abstraction.d.ts.map +1 -1
- package/ts/src/deno/deno-sys-abstraction.js +13 -17
- package/ts/src/deno/deno-sys-abstraction.js.map +1 -1
- package/ts/src/log-writer-impl.d.ts +1 -0
- package/ts/src/log-writer-impl.d.ts.map +1 -1
- package/ts/src/log-writer-impl.js +1 -0
- package/ts/src/log-writer-impl.js.map +1 -1
- package/ts/src/logger-impl.d.ts +3 -3
- package/ts/src/logger-impl.d.ts.map +1 -1
- package/ts/src/logger-impl.js +3 -18
- package/ts/src/logger-impl.js.map +1 -1
- package/ts/src/logger.test.js +3 -4
- package/ts/src/logger.test.js.map +1 -1
- package/ts/src/node/node-basic-sys-abstraction.d.ts +25 -0
- package/ts/src/node/node-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/node/node-basic-sys-abstraction.js +44 -0
- package/ts/src/node/node-basic-sys-abstraction.js.map +1 -0
- package/ts/src/node/node-sys-abstraction.d.ts +3 -6
- package/ts/src/node/node-sys-abstraction.d.ts.map +1 -1
- package/ts/src/node/node-sys-abstraction.js +13 -17
- package/ts/src/node/node-sys-abstraction.js.map +1 -1
- package/ts/src/node/node-sys-abstraction.test.js +1 -1
- package/ts/src/node/node-sys-abstraction.test.js.map +1 -1
- package/ts/src/resolve-once.test.js +1 -1
- package/ts/src/sys-abstraction.d.ts +10 -6
- package/ts/src/sys-abstraction.d.ts.map +1 -1
- package/ts/src/test/mock-logger.d.ts +2 -2
- package/ts/src/test/mock-logger.d.ts.map +1 -1
- package/ts/src/test/mock-logger.js.map +1 -1
- package/ts/src/tracer.test.js +5 -8
- package/ts/src/tracer.test.js.map +1 -1
- package/ts/src/txt-en-decoder.d.ts.map +1 -1
- package/ts/src/txt-en-decoder.js +3 -3
- package/ts/src/txt-en-decoder.js.map +1 -1
- package/ts/src/uri.d.ts +12 -0
- package/ts/src/uri.d.ts.map +1 -1
- package/ts/src/uri.js +55 -0
- package/ts/src/uri.js.map +1 -1
- package/ts/src/uri.test.js +48 -0
- package/ts/src/uri.test.js.map +1 -1
- package/ts/src/web/index.d.ts +1 -1
- package/ts/src/web/index.d.ts.map +1 -1
- package/ts/src/web/index.js +1 -1
- package/ts/src/web/index.js.map +1 -1
- package/ts/src/web/web-basic-sys-abstraction.d.ts +4 -0
- package/ts/src/web/web-basic-sys-abstraction.d.ts.map +1 -0
- package/ts/src/web/web-basic-sys-abstraction.js +45 -0
- package/ts/src/web/web-basic-sys-abstraction.js.map +1 -0
- package/ts/vitest.workspace.d.ts +1 -1
- package/utils/index.cjs +132 -3
- package/utils/index.cjs.map +1 -1
- package/utils/index.js +5 -5
- package/web/index.cjs +277 -281
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +4 -17
- package/web/index.d.ts +4 -17
- package/web/index.js +4 -7
- package/base-sys-abstraction-BnBZ6zd0.d.ts +0 -84
- package/base-sys-abstraction-DAZ8tx5F.d.cts +0 -84
- package/chunk-23MCJYE6.js.map +0 -1
- package/chunk-GDTTUMIL.js.map +0 -1
- package/chunk-H6MLKWIZ.js +0 -88
- package/chunk-H6MLKWIZ.js.map +0 -1
- package/chunk-LXTKPZ6M.js +0 -255
- package/chunk-LXTKPZ6M.js.map +0 -1
- package/chunk-PHS255C5.js.map +0 -1
- package/src/cf/cf-sys-abstraction.ts +0 -34
- package/src/web/web-sys-abstraction.ts +0 -80
- package/ts/src/base-sys-abstraction.test.d.ts +0 -2
- package/ts/src/base-sys-abstraction.test.d.ts.map +0 -1
- package/ts/src/base-sys-abstraction.test.js.map +0 -1
- package/ts/src/cf/cf-sys-abstraction.d.ts +0 -11
- package/ts/src/cf/cf-sys-abstraction.d.ts.map +0 -1
- package/ts/src/cf/cf-sys-abstraction.js +0 -30
- package/ts/src/cf/cf-sys-abstraction.js.map +0 -1
- package/ts/src/web/web-sys-abstraction.d.ts +0 -18
- package/ts/src/web/web-sys-abstraction.d.ts.map +0 -1
- package/ts/src/web/web-sys-abstraction.js +0 -64
- package/ts/src/web/web-sys-abstraction.js.map +0 -1
- /package/{chunk-55W4AK2Z.js.map → chunk-YVACAIUX.js.map} +0 -0
@@ -1,7 +1,21 @@
|
|
1
1
|
import { FileService } from "./file-service.js";
|
2
|
-
import {
|
2
|
+
import { runtimeFn } from "./runtime.js";
|
3
|
+
import {
|
4
|
+
TimeMode,
|
5
|
+
RandomMode,
|
6
|
+
IDMode,
|
7
|
+
SystemService,
|
8
|
+
VoidFunc,
|
9
|
+
BasicSysAbstraction,
|
10
|
+
BasicRuntimeService,
|
11
|
+
} from "./sys-abstraction.js";
|
3
12
|
import { Time } from "./time.js";
|
4
13
|
import { TxtEnDecoder } from "./txt-en-decoder.js";
|
14
|
+
import { WebBasicSysAbstraction } from "./web/web-basic-sys-abstraction.js";
|
15
|
+
import { Env } from "./sys-env.js";
|
16
|
+
import { CFBasicSysAbstraction } from "./cf/cf-basic-sys-abstraction.js";
|
17
|
+
import { DenoBasicSysAbstraction } from "./deno/deno-basic-sys-abstraction.js";
|
18
|
+
import { NodeBasicSysAbstraction } from "./node/node-basic-sys-abstraction.js";
|
5
19
|
|
6
20
|
export class SysTime extends Time {
|
7
21
|
Now(): Date {
|
@@ -110,8 +124,11 @@ export class IdService {
|
|
110
124
|
}
|
111
125
|
}
|
112
126
|
|
113
|
-
export interface
|
127
|
+
export interface BaseBasicSysAbstractionParams {
|
114
128
|
readonly TxtEnDecoder: TxtEnDecoder;
|
129
|
+
}
|
130
|
+
|
131
|
+
export interface BaseSysAbstractionParams extends BaseBasicSysAbstractionParams {
|
115
132
|
readonly FileSystem: FileService;
|
116
133
|
readonly SystemService: SystemService;
|
117
134
|
}
|
@@ -127,141 +144,84 @@ export interface ExitService {
|
|
127
144
|
}
|
128
145
|
|
129
146
|
// some black magic to make it work with CF workers
|
130
|
-
function consumeReadableStream(
|
131
|
-
reader: ReadableStreamDefaultReader<Uint8Array>,
|
132
|
-
writeFn: (chunk: Uint8Array) => Promise<void>,
|
133
|
-
): void {
|
134
|
-
reader
|
135
|
-
.read()
|
136
|
-
.then(({ done, value }) => {
|
137
|
-
if (done) {
|
138
|
-
return;
|
139
|
-
}
|
140
|
-
writeFn(value)
|
141
|
-
.then(() => {
|
142
|
-
consumeReadableStream(reader, writeFn);
|
143
|
-
})
|
144
|
-
.catch((e) => {
|
145
|
-
// eslint-disable-next-line no-console
|
146
|
-
console.error("consumeReadableStream:writeFn", e);
|
147
|
-
});
|
148
|
-
})
|
149
|
-
.catch((e) => {
|
150
|
-
// eslint-disable-next-line no-console
|
151
|
-
console.error("consumeReadableStream:read", e);
|
152
|
-
});
|
153
|
-
}
|
154
|
-
|
155
|
-
function CFWriteableStream(writeFn: (chunk: Uint8Array) => Promise<void>): WritableStream<Uint8Array> {
|
156
|
-
const ts = new TransformStream<Uint8Array, Uint8Array>();
|
157
|
-
consumeReadableStream(ts.readable.getReader(), writeFn);
|
158
|
-
return ts.writable;
|
159
|
-
}
|
160
147
|
|
161
|
-
export class
|
148
|
+
export class BaseBasicSysAbstraction {
|
162
149
|
readonly _time: SysTime = new SysTime();
|
163
|
-
readonly _stdout: WritableStream<Uint8Array>;
|
164
|
-
readonly _stderr: WritableStream<Uint8Array>;
|
165
150
|
|
151
|
+
// system independent services
|
166
152
|
readonly _idService: IdService = new IdService();
|
167
153
|
readonly _randomService: RandomService = new RandomService(RandomMode.RANDOM);
|
154
|
+
readonly _txtEnDe: TxtEnDecoder;
|
155
|
+
|
156
|
+
constructor(params: BaseBasicSysAbstractionParams) {
|
157
|
+
this._txtEnDe = params.TxtEnDecoder;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
export class BaseSysAbstraction extends BaseBasicSysAbstraction {
|
162
|
+
// system related services
|
168
163
|
readonly _fileSystem: FileService;
|
169
164
|
readonly _systemService: SystemService;
|
170
|
-
readonly _txtEnDe: TxtEnDecoder;
|
171
165
|
|
172
166
|
constructor(params: BaseSysAbstractionParams) {
|
167
|
+
super(params);
|
173
168
|
this._fileSystem = params.FileSystem;
|
174
169
|
this._systemService = params.SystemService;
|
175
|
-
this._txtEnDe = params.TxtEnDecoder;
|
176
|
-
const decoder = this._txtEnDe;
|
177
|
-
this._stdout = CFWriteableStream((chunk) => {
|
178
|
-
const decoded = decoder.decode(chunk);
|
179
|
-
// eslint-disable-next-line no-console
|
180
|
-
console.log(decoded.trimEnd());
|
181
|
-
return Promise.resolve();
|
182
|
-
});
|
183
|
-
this._stderr = CFWriteableStream((chunk) => {
|
184
|
-
const decoded = decoder.decode(chunk);
|
185
|
-
// eslint-disable-next-line no-console
|
186
|
-
console.error(decoded.trimEnd());
|
187
|
-
return Promise.resolve();
|
188
|
-
});
|
189
|
-
/* this is not CF worker compatible
|
190
|
-
this._stdout = new WritableStream({
|
191
|
-
write(chunk): Promise<void> {
|
192
|
-
return new Promise((resolve) => {
|
193
|
-
const decoded = decoder.decode(chunk);
|
194
|
-
// eslint-disable-next-line no-console
|
195
|
-
console.log(decoded.trimEnd());
|
196
|
-
resolve();
|
197
|
-
});
|
198
|
-
},
|
199
|
-
});
|
200
|
-
this._stderr = new WritableStream({
|
201
|
-
write(chunk): Promise<void> {
|
202
|
-
return new Promise((resolve) => {
|
203
|
-
const decoded = decoder.decode(chunk);
|
204
|
-
// eslint-disable-next-line no-console
|
205
|
-
console.error(decoded.trimEnd());
|
206
|
-
resolve();
|
207
|
-
});
|
208
|
-
},
|
209
|
-
});
|
210
|
-
*/
|
211
170
|
}
|
212
171
|
}
|
213
172
|
|
214
|
-
export interface
|
215
|
-
readonly TimeMode
|
216
|
-
readonly IdMode
|
217
|
-
readonly
|
218
|
-
readonly
|
219
|
-
readonly
|
220
|
-
readonly
|
221
|
-
readonly
|
222
|
-
|
173
|
+
export interface BasicSysAbstractionParams {
|
174
|
+
readonly TimeMode: TimeMode;
|
175
|
+
readonly IdMode: IDMode;
|
176
|
+
readonly RandomMode: RandomMode;
|
177
|
+
// readonly FileSystem: FileService;
|
178
|
+
// readonly SystemService: SystemService;
|
179
|
+
readonly TxtEnDecoder: TxtEnDecoder;
|
180
|
+
// readonly BasicRuntimeService: BasicSysAbstraction;
|
181
|
+
}
|
182
|
+
|
183
|
+
export type WrapperBasicSysAbstractionParams = Partial<BasicRuntimeService & BasicSysAbstractionParams>;
|
184
|
+
|
185
|
+
export function BasicSysAbstractionFactory(params?: WrapperBasicSysAbstractionParams): BasicSysAbstraction {
|
186
|
+
const fn = runtimeFn();
|
187
|
+
switch (true) {
|
188
|
+
case fn.isBrowser:
|
189
|
+
return WebBasicSysAbstraction(params);
|
190
|
+
case fn.isDeno:
|
191
|
+
return DenoBasicSysAbstraction(params);
|
192
|
+
case fn.isCFWorker:
|
193
|
+
return CFBasicSysAbstraction(params);
|
194
|
+
case fn.isNodeIsh:
|
195
|
+
return NodeBasicSysAbstraction(params);
|
196
|
+
default:
|
197
|
+
throw new Error("Unknown runtime");
|
198
|
+
}
|
223
199
|
}
|
224
200
|
|
225
|
-
export class
|
201
|
+
export class WrapperBasicSysAbstraction implements BasicSysAbstraction {
|
226
202
|
readonly _time: Time;
|
227
|
-
readonly _stdout: WritableStream<Uint8Array>;
|
228
|
-
readonly _stderr: WritableStream<Uint8Array>;
|
229
203
|
readonly _idService: IdService;
|
230
204
|
readonly _randomService: RandomService;
|
231
|
-
readonly
|
232
|
-
|
233
|
-
|
205
|
+
readonly _basicRuntimeService: BasicRuntimeService;
|
206
|
+
constructor(
|
207
|
+
base: BaseBasicSysAbstraction,
|
208
|
+
params: Partial<BasicSysAbstractionParams> & { basicRuntimeService: BasicRuntimeService },
|
209
|
+
) {
|
234
210
|
this._time = base._time;
|
235
|
-
this.
|
236
|
-
this._stderr = base._stderr;
|
211
|
+
this._basicRuntimeService = params.basicRuntimeService;
|
237
212
|
this._idService = base._idService;
|
238
213
|
this._randomService = base._randomService;
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
}
|
248
|
-
if (params.Stderr) {
|
249
|
-
this._stderr = params.Stderr;
|
250
|
-
}
|
251
|
-
if (params.IdMode) {
|
252
|
-
this._idService = new IdService(params.IdMode);
|
253
|
-
}
|
254
|
-
if (params.RandomMode) {
|
255
|
-
this._randomService = new RandomService(params.RandomMode);
|
256
|
-
}
|
257
|
-
if (params.FileSystem) {
|
258
|
-
this._fileSystem = params.FileSystem;
|
259
|
-
}
|
260
|
-
if (params.SystemService) {
|
261
|
-
this._systemService = params.SystemService;
|
262
|
-
}
|
214
|
+
if (params.TimeMode) {
|
215
|
+
this._time = TimeFactory(params.TimeMode);
|
216
|
+
}
|
217
|
+
if (params.IdMode) {
|
218
|
+
this._idService = new IdService(params.IdMode);
|
219
|
+
}
|
220
|
+
if (params.RandomMode) {
|
221
|
+
this._randomService = new RandomService(params.RandomMode);
|
263
222
|
}
|
264
223
|
}
|
224
|
+
|
265
225
|
Time(): Time {
|
266
226
|
return this._time;
|
267
227
|
}
|
@@ -272,10 +232,41 @@ export class WrapperSysAbstraction implements SysAbstraction {
|
|
272
232
|
return this._randomService.Random0ToValue(value);
|
273
233
|
}
|
274
234
|
Stdout(): WritableStream {
|
275
|
-
return this.
|
235
|
+
return this._basicRuntimeService.Stdout();
|
276
236
|
}
|
277
237
|
Stderr(): WritableStream {
|
278
|
-
return this.
|
238
|
+
return this._basicRuntimeService.Stderr();
|
239
|
+
}
|
240
|
+
Env(): Env {
|
241
|
+
return this._basicRuntimeService.Env();
|
242
|
+
}
|
243
|
+
Args(): string[] {
|
244
|
+
return this._basicRuntimeService.Args();
|
245
|
+
}
|
246
|
+
|
247
|
+
// System(): SystemService {
|
248
|
+
// return this._systemService;
|
249
|
+
// }
|
250
|
+
// FileSystem(): FileService {
|
251
|
+
// return this._fileSystem;
|
252
|
+
// }
|
253
|
+
}
|
254
|
+
// export const BaseSysAbstraction = new BaseSysAbstractionImpl()
|
255
|
+
|
256
|
+
export class WrapperRuntimeSysAbstraction extends WrapperBasicSysAbstraction {
|
257
|
+
readonly _systemService: SystemService;
|
258
|
+
readonly _fileSystem: FileService;
|
259
|
+
constructor(
|
260
|
+
base: BaseSysAbstraction,
|
261
|
+
params: Partial<BaseBasicSysAbstraction> & {
|
262
|
+
systemService?: SystemService;
|
263
|
+
fileSystem?: FileService;
|
264
|
+
basicRuntimeService: BasicRuntimeService;
|
265
|
+
},
|
266
|
+
) {
|
267
|
+
super(base, params);
|
268
|
+
this._systemService = params.systemService ?? base._systemService;
|
269
|
+
this._fileSystem = params.fileSystem ?? base._fileSystem;
|
279
270
|
}
|
280
271
|
|
281
272
|
System(): SystemService {
|
@@ -285,4 +276,3 @@ export class WrapperSysAbstraction implements SysAbstraction {
|
|
285
276
|
return this._fileSystem;
|
286
277
|
}
|
287
278
|
}
|
288
|
-
// export const BaseSysAbstraction = new BaseSysAbstractionImpl()
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { BaseBasicSysAbstraction, WrapperBasicSysAbstraction, WrapperBasicSysAbstractionParams } from "../base-sys-abstraction.js";
|
2
|
+
import { ResolveOnce } from "../resolve-once.js";
|
3
|
+
import { BasicRuntimeService, BasicSysAbstraction } from "../sys-abstraction.js";
|
4
|
+
import { Env, envFactory } from "../sys-env.js";
|
5
|
+
import { TxtEnDecoder, TxtEnDecoderSingleton } from "../txt-en-decoder.js";
|
6
|
+
|
7
|
+
export class CFRuntimeService implements BasicRuntimeService {
|
8
|
+
readonly _txtEnDe: TxtEnDecoder;
|
9
|
+
constructor(ende: TxtEnDecoder) {
|
10
|
+
this._txtEnDe = ende;
|
11
|
+
}
|
12
|
+
Env(): Env {
|
13
|
+
return envFactory();
|
14
|
+
}
|
15
|
+
Args(): string[] {
|
16
|
+
throw new Error("Args-Method not implemented.");
|
17
|
+
}
|
18
|
+
|
19
|
+
Stdout(): WritableStream<Uint8Array> {
|
20
|
+
return CFWriteableStream((chunk) => {
|
21
|
+
const decoded = this._txtEnDe.decode(chunk);
|
22
|
+
// eslint-disable-next-line no-console
|
23
|
+
console.log(decoded.trimEnd());
|
24
|
+
return Promise.resolve();
|
25
|
+
});
|
26
|
+
}
|
27
|
+
Stderr(): WritableStream<Uint8Array> {
|
28
|
+
return CFWriteableStream((chunk) => {
|
29
|
+
const decoded = this._txtEnDe.decode(chunk);
|
30
|
+
// eslint-disable-next-line no-console
|
31
|
+
console.error(decoded.trimEnd());
|
32
|
+
return Promise.resolve();
|
33
|
+
});
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
function consumeReadableStream(
|
38
|
+
reader: ReadableStreamDefaultReader<Uint8Array>,
|
39
|
+
writeFn: (chunk: Uint8Array) => Promise<void>,
|
40
|
+
): void {
|
41
|
+
reader
|
42
|
+
.read()
|
43
|
+
.then(({ done, value }) => {
|
44
|
+
if (done) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
writeFn(value)
|
48
|
+
.then(() => {
|
49
|
+
consumeReadableStream(reader, writeFn);
|
50
|
+
})
|
51
|
+
.catch((e) => {
|
52
|
+
// eslint-disable-next-line no-console
|
53
|
+
console.error("consumeReadableStream:writeFn", e);
|
54
|
+
});
|
55
|
+
})
|
56
|
+
.catch((e) => {
|
57
|
+
// eslint-disable-next-line no-console
|
58
|
+
console.error("consumeReadableStream:read", e);
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
function CFWriteableStream(writeFn: (chunk: Uint8Array) => Promise<void>): WritableStream<Uint8Array> {
|
63
|
+
const ts = new TransformStream<Uint8Array, Uint8Array>();
|
64
|
+
consumeReadableStream(ts.readable.getReader(), writeFn);
|
65
|
+
return ts.writable;
|
66
|
+
}
|
67
|
+
|
68
|
+
const baseSysAbstraction = new ResolveOnce<BaseBasicSysAbstraction>();
|
69
|
+
export function CFBasicSysAbstraction(param?: WrapperBasicSysAbstractionParams): BasicSysAbstraction {
|
70
|
+
const my = baseSysAbstraction.once(() => {
|
71
|
+
return new BaseBasicSysAbstraction({
|
72
|
+
TxtEnDecoder: param?.TxtEnDecoder || TxtEnDecoderSingleton(),
|
73
|
+
});
|
74
|
+
});
|
75
|
+
return new WrapperBasicSysAbstraction(my, {
|
76
|
+
basicRuntimeService: new CFRuntimeService(param?.TxtEnDecoder ?? my._txtEnDe),
|
77
|
+
...param,
|
78
|
+
});
|
79
|
+
}
|
package/src/cf/index.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./cf-sys-abstraction.js";
|
1
|
+
export * from "./cf-basic-sys-abstraction.js";
|
2
2
|
export * from "./cf-env-actions.js";
|
package/src/cf-test-main.ts
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
+
import { LoggerImpl } from "@adviser/cement";
|
2
|
+
|
1
3
|
export default {
|
2
4
|
fetch(): Response {
|
3
|
-
|
5
|
+
// console.log(">>>>enter");
|
6
|
+
const logger = new LoggerImpl();
|
7
|
+
for (let i = 0; i < 10; i++) {
|
8
|
+
logger.Error().Any({ i }).Msg("Hello Logger World!");
|
9
|
+
}
|
10
|
+
const ret = new Response("Hello World!");
|
11
|
+
// console.log(">>>>exit");
|
12
|
+
return ret;
|
4
13
|
},
|
5
14
|
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { BaseBasicSysAbstraction, WrapperBasicSysAbstraction, WrapperBasicSysAbstractionParams } from "../base-sys-abstraction.js";
|
2
|
+
import { ResolveOnce } from "../resolve-once.js";
|
3
|
+
import { BasicRuntimeService, BasicSysAbstraction } from "../sys-abstraction.js";
|
4
|
+
import { Env, envFactory } from "../sys-env.js";
|
5
|
+
import { TxtEnDecoder, TxtEnDecoderSingleton } from "../txt-en-decoder.js";
|
6
|
+
|
7
|
+
export class DenoRuntimeService implements BasicRuntimeService {
|
8
|
+
readonly _txtEnDe: TxtEnDecoder;
|
9
|
+
constructor(ende: TxtEnDecoder) {
|
10
|
+
this._txtEnDe = ende;
|
11
|
+
}
|
12
|
+
Env(): Env {
|
13
|
+
return envFactory();
|
14
|
+
}
|
15
|
+
|
16
|
+
Args(): string[] {
|
17
|
+
return globalThis.Deno.args;
|
18
|
+
}
|
19
|
+
|
20
|
+
Stdout(): WritableStream<Uint8Array> {
|
21
|
+
return globalThis.Deno.stdout.writable;
|
22
|
+
}
|
23
|
+
Stderr(): WritableStream<Uint8Array> {
|
24
|
+
return globalThis.Deno.stderr.writable;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
const baseSysAbstraction = new ResolveOnce<BaseBasicSysAbstraction>();
|
29
|
+
export function DenoBasicSysAbstraction(param?: WrapperBasicSysAbstractionParams): BasicSysAbstraction {
|
30
|
+
const my = baseSysAbstraction.once(() => {
|
31
|
+
return new BaseBasicSysAbstraction({
|
32
|
+
TxtEnDecoder: param?.TxtEnDecoder || TxtEnDecoderSingleton(),
|
33
|
+
});
|
34
|
+
});
|
35
|
+
return new WrapperBasicSysAbstraction(my, {
|
36
|
+
basicRuntimeService: new DenoRuntimeService(param?.TxtEnDecoder ?? my._txtEnDe),
|
37
|
+
...param,
|
38
|
+
});
|
39
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as path from "node:path";
|
2
|
-
import { FileService, NamedWritableStream } from "../file-service.js";
|
2
|
+
import type { FileService, NamedWritableStream } from "../file-service.js";
|
3
3
|
import { TxtEnDecoder, TxtEnDecoderSingleton } from "../txt-en-decoder.js";
|
4
4
|
|
5
5
|
const Deno = (globalThis as unknown as { Deno: unknown }).Deno as {
|
@@ -2,12 +2,13 @@ import {
|
|
2
2
|
ExitService,
|
3
3
|
ExitHandler,
|
4
4
|
BaseSysAbstraction,
|
5
|
-
|
6
|
-
|
5
|
+
WrapperBasicSysAbstractionParams,
|
6
|
+
WrapperRuntimeSysAbstraction,
|
7
7
|
} from "../base-sys-abstraction.js";
|
8
|
-
import {
|
9
|
-
import {
|
8
|
+
import { ResolveOnce } from "../resolve-once.js";
|
9
|
+
import { RuntimeSysAbstraction, SystemService, VoidFunc } from "../sys-abstraction.js";
|
10
10
|
import { TxtEnDecoderSingleton } from "../txt-en-decoder.js";
|
11
|
+
import { DenoBasicSysAbstraction } from "./deno-basic-sys-abstraction.js";
|
11
12
|
// import * as process from "node:process";
|
12
13
|
import { DenoFileService } from "./deno-file-service.js";
|
13
14
|
|
@@ -97,14 +98,6 @@ export class DenoSystemService implements SystemService {
|
|
97
98
|
this._exitService.injectExitHandlers(DenoSystemService._exitHandlers);
|
98
99
|
}
|
99
100
|
|
100
|
-
Env(): Env {
|
101
|
-
return envFactory();
|
102
|
-
}
|
103
|
-
|
104
|
-
Args(): string[] {
|
105
|
-
return Deno.args;
|
106
|
-
}
|
107
|
-
|
108
101
|
OnExit(hdl: VoidFunc): VoidFunc {
|
109
102
|
const id = crypto.randomUUID();
|
110
103
|
DenoSystemService._exitHandlers.push({ hdl, id });
|
@@ -121,14 +114,18 @@ export class DenoSystemService implements SystemService {
|
|
121
114
|
}
|
122
115
|
}
|
123
116
|
|
124
|
-
|
125
|
-
export function DenoSysAbstraction(param?:
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
117
|
+
const baseSysAbstraction = new ResolveOnce<BaseSysAbstraction>();
|
118
|
+
export function DenoSysAbstraction(param?: WrapperBasicSysAbstractionParams): RuntimeSysAbstraction {
|
119
|
+
const my = baseSysAbstraction.once(
|
120
|
+
() =>
|
121
|
+
new BaseSysAbstraction({
|
122
|
+
TxtEnDecoder: param?.TxtEnDecoder || TxtEnDecoderSingleton(),
|
123
|
+
FileSystem: new DenoFileService(),
|
124
|
+
SystemService: new DenoSystemService(),
|
125
|
+
}),
|
126
|
+
);
|
127
|
+
return new WrapperRuntimeSysAbstraction(my, {
|
128
|
+
basicRuntimeService: DenoBasicSysAbstraction(param),
|
129
|
+
...param,
|
130
|
+
});
|
134
131
|
}
|
package/src/jsr.json
CHANGED
package/src/log-writer-impl.ts
CHANGED
@@ -2,8 +2,12 @@ export class LogWriterStream {
|
|
2
2
|
readonly _out: WritableStream<Uint8Array>;
|
3
3
|
readonly _toFlush: (() => Promise<void>)[] = [];
|
4
4
|
|
5
|
+
readonly _id: number;
|
6
|
+
|
5
7
|
constructor(out: WritableStream<Uint8Array>) {
|
6
8
|
this._out = out;
|
9
|
+
this._id = Math.random();
|
10
|
+
// console.log(">>>My:constructor:", this._id);
|
7
11
|
}
|
8
12
|
|
9
13
|
write(encoded: Uint8Array): void {
|
@@ -11,10 +15,12 @@ export class LogWriterStream {
|
|
11
15
|
// const val = Math.random();
|
12
16
|
// console.log(">>>My:", encoded)
|
13
17
|
try {
|
18
|
+
// console.log(">>>My:getWriter:get:", this._id);
|
14
19
|
const writer = this._out.getWriter();
|
15
20
|
await writer.ready;
|
16
21
|
await writer.write(encoded);
|
17
22
|
writer.releaseLock();
|
23
|
+
// console.log(">>>My:getWriter:release", this._id);
|
18
24
|
} catch (err) {
|
19
25
|
// eslint-disable-next-line no-console
|
20
26
|
console.error("Chunk error:", err);
|
package/src/logger-impl.ts
CHANGED
@@ -19,15 +19,13 @@ import {
|
|
19
19
|
HttpType,
|
20
20
|
LogValueState,
|
21
21
|
} from "./logger.js";
|
22
|
-
import {
|
23
|
-
import { SysAbstraction } from "./sys-abstraction.js";
|
22
|
+
import { BasicSysAbstraction } from "./sys-abstraction.js";
|
24
23
|
import { Result } from "./result.js";
|
25
24
|
import { CoerceURI, URI } from "./uri.js";
|
26
|
-
import { runtimeFn } from "./runtime.js";
|
27
|
-
import { ConsoleWriterStream } from "./utils/console-write-stream.js";
|
28
25
|
import { LogWriterStream } from "./log-writer-impl.js";
|
29
26
|
import { TxtEnDecoder, TxtEnDecoderSingleton } from "./txt-en-decoder.js";
|
30
27
|
import { LevelHandlerSingleton } from "./log-level-impl.js";
|
28
|
+
import { BasicSysAbstractionFactory } from "./base-sys-abstraction.js";
|
31
29
|
|
32
30
|
function getLen(value: unknown, lvs: LogValueState): LogValue {
|
33
31
|
if (Array.isArray(value)) {
|
@@ -93,7 +91,7 @@ export class YAMLFormatter implements LogFormatter {
|
|
93
91
|
export interface LoggerImplParams {
|
94
92
|
readonly out?: WritableStream<Uint8Array>;
|
95
93
|
readonly logWriter?: LogWriterStream;
|
96
|
-
readonly sys?:
|
94
|
+
readonly sys?: BasicSysAbstraction;
|
97
95
|
readonly withAttributes?: LogSerializable;
|
98
96
|
readonly levelHandler?: LevelHandler;
|
99
97
|
readonly txtEnDe?: TxtEnDecoder;
|
@@ -107,7 +105,7 @@ function toLogValueCtx(lvh: LevelHandler): LogValueState {
|
|
107
105
|
}
|
108
106
|
|
109
107
|
export class LoggerImpl implements Logger {
|
110
|
-
readonly _sys:
|
108
|
+
readonly _sys: BasicSysAbstraction;
|
111
109
|
readonly _attributes: LogSerializable = {};
|
112
110
|
readonly _withAttributes: LogSerializable;
|
113
111
|
readonly _logWriter: LogWriterStream;
|
@@ -121,7 +119,7 @@ export class LoggerImpl implements Logger {
|
|
121
119
|
params = {};
|
122
120
|
}
|
123
121
|
if (!params.sys) {
|
124
|
-
this._sys =
|
122
|
+
this._sys = BasicSysAbstractionFactory();
|
125
123
|
} else {
|
126
124
|
this._sys = params.sys;
|
127
125
|
}
|
@@ -140,18 +138,18 @@ export class LoggerImpl implements Logger {
|
|
140
138
|
this._logWriter = params.logWriter;
|
141
139
|
} else {
|
142
140
|
if (!params.out) {
|
143
|
-
const rt = runtimeFn();
|
144
|
-
let stream: WritableStream<Uint8Array>;
|
145
|
-
if (rt.isBrowser) {
|
146
|
-
|
147
|
-
} else {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
}
|
154
|
-
this._logWriter = new LogWriterStream(
|
141
|
+
// const rt = runtimeFn();
|
142
|
+
// let stream: WritableStream<Uint8Array>;
|
143
|
+
// if (rt.isBrowser) {
|
144
|
+
// stream = new ConsoleWriterStream();
|
145
|
+
// } else {
|
146
|
+
// if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
|
147
|
+
// stream = this._sys.Stdout();
|
148
|
+
// } else {
|
149
|
+
// throw new Error("No output defined for runtime");
|
150
|
+
// }
|
151
|
+
// }
|
152
|
+
this._logWriter = new LogWriterStream(this._sys.Stdout());
|
155
153
|
} else {
|
156
154
|
this._logWriter = new LogWriterStream(params.out);
|
157
155
|
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { BaseBasicSysAbstraction, WrapperBasicSysAbstraction, WrapperBasicSysAbstractionParams } from "../base-sys-abstraction.js";
|
2
|
+
import { ResolveOnce } from "../resolve-once.js";
|
3
|
+
import { BasicRuntimeService, BasicSysAbstraction } from "../sys-abstraction.js";
|
4
|
+
import { Env, envFactory } from "../sys-env.js";
|
5
|
+
import { TxtEnDecoder, TxtEnDecoderSingleton } from "../txt-en-decoder.js";
|
6
|
+
|
7
|
+
export class NodeRuntimeService implements BasicRuntimeService {
|
8
|
+
readonly _txtEnDe: TxtEnDecoder;
|
9
|
+
readonly _gthis: {
|
10
|
+
process: {
|
11
|
+
argv: string[];
|
12
|
+
stdout: {
|
13
|
+
write(chunk: Uint8Array): void;
|
14
|
+
};
|
15
|
+
stderr: {
|
16
|
+
write(chunk: Uint8Array): void;
|
17
|
+
};
|
18
|
+
};
|
19
|
+
};
|
20
|
+
constructor(ende: TxtEnDecoder) {
|
21
|
+
this._txtEnDe = ende;
|
22
|
+
this._gthis = globalThis as unknown as NodeRuntimeService["_gthis"];
|
23
|
+
}
|
24
|
+
Env(): Env {
|
25
|
+
return envFactory();
|
26
|
+
}
|
27
|
+
|
28
|
+
Args(): string[] {
|
29
|
+
return this._gthis.process.argv;
|
30
|
+
}
|
31
|
+
|
32
|
+
Stdout(): WritableStream<Uint8Array> {
|
33
|
+
return new WritableStream({
|
34
|
+
write: (chunk: Uint8Array): void => {
|
35
|
+
this._gthis.process.stdout.write(chunk);
|
36
|
+
},
|
37
|
+
});
|
38
|
+
}
|
39
|
+
Stderr(): WritableStream<Uint8Array> {
|
40
|
+
return new WritableStream<Uint8Array>({
|
41
|
+
write: (chunk: Uint8Array): void => {
|
42
|
+
this._gthis.process.stderr.write(chunk);
|
43
|
+
},
|
44
|
+
});
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
const baseSysAbstraction = new ResolveOnce<BaseBasicSysAbstraction>();
|
49
|
+
export function NodeBasicSysAbstraction(param?: WrapperBasicSysAbstractionParams): BasicSysAbstraction {
|
50
|
+
const my = baseSysAbstraction.once(() => {
|
51
|
+
return new BaseBasicSysAbstraction({
|
52
|
+
TxtEnDecoder: param?.TxtEnDecoder || TxtEnDecoderSingleton(),
|
53
|
+
});
|
54
|
+
});
|
55
|
+
return new WrapperBasicSysAbstraction(my, {
|
56
|
+
basicRuntimeService: new NodeRuntimeService(param?.TxtEnDecoder ?? my._txtEnDe),
|
57
|
+
...param,
|
58
|
+
});
|
59
|
+
}
|