@adviser/cement 0.3.6 → 0.3.7
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-CKI4xiRR.d.ts → base-sys-abstraction-Cqb4snul.d.ts} +2 -2
- package/{base-sys-abstraction-DLnSeH4s.d.cts → base-sys-abstraction-WS7lNbFm.d.cts} +2 -2
- package/cf/index.cjs +59 -8
- package/cf/index.cjs.map +1 -1
- package/cf/index.d.cts +19 -4
- package/cf/index.d.ts +19 -4
- package/cf/index.js +5 -3
- package/cf/index.js.map +1 -1
- package/{chunk-QDDO6NOK.js → chunk-BVZ6HD34.js} +66 -7
- package/chunk-BVZ6HD34.js.map +1 -0
- package/{chunk-N5ISHPJ6.js → chunk-H5JLIMWA.js} +41 -2
- package/{chunk-N5ISHPJ6.js.map → chunk-H5JLIMWA.js.map} +1 -1
- package/{chunk-OIIUVSUX.js → chunk-K5TIGJ6I.js} +3 -3
- package/{chunk-Z7F6652G.js → chunk-LNS2K5WL.js} +4 -4
- package/{chunk-4QRZPFED.js → chunk-SCFB6I2C.js} +58 -57
- package/{chunk-4QRZPFED.js.map → chunk-SCFB6I2C.js.map} +1 -1
- package/deno/index.cjs +57 -8
- package/deno/index.cjs.map +1 -1
- package/deno/index.d.cts +3 -3
- package/deno/index.d.ts +3 -3
- package/deno/index.js +2 -2
- package/{get-params-result-Bhy5997x.d.ts → get-params-result-CXYbMEcV.d.cts} +13 -7
- package/{get-params-result-Bhy5997x.d.cts → get-params-result-CXYbMEcV.d.ts} +13 -7
- package/{index-CcNS7k5i.d.cts → index-BH1SIYUK.d.cts} +2 -2
- package/{index-DjN6Y4N2.d.ts → index-BQMIP01w.d.ts} +19 -3
- package/{index-6ofzOS0J.d.ts → index-BeXMFEyF.d.ts} +2 -2
- package/{index-TZQHtEZo.d.cts → index-C6hvxtE7.d.cts} +19 -3
- package/index.cjs +180 -14
- package/index.cjs.map +1 -1
- package/index.d.cts +27 -10
- package/index.d.ts +27 -10
- package/index.js +83 -7
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -0
- package/metafile-esm.json +1 -0
- package/node/index.cjs +139 -90
- 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 +2 -2
- package/package.json +2 -2
- package/src/cf/index.ts +1 -0
- package/src/http_header.ts +1 -1
- package/src/index.ts +5 -1
- package/src/json-en-decoder.ts +83 -0
- package/src/jsr.json +1 -1
- package/src/path-ops.ts +30 -0
- package/src/txt-en-decoder.ts +38 -9
- package/src/utils/coerce-uint8.ts +53 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/sorted-object.ts +18 -0
- package/src/utils/uint8array-equal.ts +11 -0
- package/{sys-abstraction-BRDT_TIU.d.cts → sys-abstraction-B-0XMe9V.d.cts} +2 -2
- package/{sys-abstraction-Bd0EzwO6.d.ts → sys-abstraction-CZa-VyNs.d.ts} +2 -2
- package/test/index.cjs +150 -101
- package/test/index.cjs.map +1 -1
- package/test/index.d.cts +3 -3
- package/test/index.d.ts +3 -3
- package/test/index.js +4 -4
- package/ts/src/cf/index.d.ts +1 -0
- package/ts/src/cf/index.d.ts.map +1 -1
- package/ts/src/cf/index.js +1 -0
- package/ts/src/cf/index.js.map +1 -1
- package/ts/src/http_header.d.ts +1 -1
- package/ts/src/http_header.d.ts.map +1 -1
- package/ts/src/http_header.js.map +1 -1
- package/ts/src/index.d.ts +2 -0
- package/ts/src/index.d.ts.map +1 -1
- package/ts/src/index.js +2 -0
- package/ts/src/index.js.map +1 -1
- package/ts/src/json-en-decoder.d.ts +12 -0
- package/ts/src/json-en-decoder.d.ts.map +1 -0
- package/ts/src/json-en-decoder.js +41 -0
- package/ts/src/json-en-decoder.js.map +1 -0
- package/ts/src/json-en-decoder.test.d.ts +2 -0
- package/ts/src/json-en-decoder.test.d.ts.map +1 -0
- package/ts/src/json-en-decoder.test.js +18 -0
- package/ts/src/json-en-decoder.test.js.map +1 -0
- package/ts/src/path-ops.d.ts +7 -0
- package/ts/src/path-ops.d.ts.map +1 -0
- package/ts/src/path-ops.js +33 -0
- package/ts/src/path-ops.js.map +1 -0
- package/ts/src/path-ops.test.d.ts +2 -0
- package/ts/src/path-ops.test.d.ts.map +1 -0
- package/ts/src/path-ops.test.js +23 -0
- package/ts/src/path-ops.test.js.map +1 -0
- package/ts/src/txt-en-decoder.d.ts +7 -6
- package/ts/src/txt-en-decoder.d.ts.map +1 -1
- package/ts/src/txt-en-decoder.js +30 -6
- package/ts/src/txt-en-decoder.js.map +1 -1
- package/ts/src/txt-en-decoder.test.d.ts +2 -0
- package/ts/src/txt-en-decoder.test.d.ts.map +1 -0
- package/ts/src/txt-en-decoder.test.js +60 -0
- package/ts/src/txt-en-decoder.test.js.map +1 -0
- package/ts/src/utils/coerce-uint8.d.ts +8 -0
- package/ts/src/utils/coerce-uint8.d.ts.map +1 -0
- package/ts/src/utils/coerce-uint8.js +34 -0
- package/ts/src/utils/coerce-uint8.js.map +1 -0
- package/ts/src/utils/index.d.ts +3 -0
- package/ts/src/utils/index.d.ts.map +1 -1
- package/ts/src/utils/index.js +3 -0
- package/ts/src/utils/index.js.map +1 -1
- package/ts/src/utils/sorted-objec.test.d.ts +2 -0
- package/ts/src/utils/sorted-objec.test.d.ts.map +1 -0
- package/ts/src/utils/sorted-objec.test.js +20 -0
- package/ts/src/utils/sorted-objec.test.js.map +1 -0
- package/ts/src/utils/sorted-object.d.ts +4 -0
- package/ts/src/utils/sorted-object.d.ts.map +1 -0
- package/ts/src/utils/sorted-object.js +16 -0
- package/ts/src/utils/sorted-object.js.map +1 -0
- package/ts/src/utils/uint8array-equal.d.ts +2 -0
- package/ts/src/utils/uint8array-equal.d.ts.map +1 -0
- package/ts/src/utils/uint8array-equal.js +12 -0
- package/ts/src/utils/uint8array-equal.js.map +1 -0
- package/utils/index.cjs +182 -87
- package/utils/index.cjs.map +1 -1
- package/utils/index.d.cts +2 -2
- package/utils/index.d.ts +2 -2
- package/utils/index.js +14 -2
- package/web/index.cjs +57 -8
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +3 -3
- package/web/index.d.ts +3 -3
- package/web/index.js +3 -3
- package/chunk-QDDO6NOK.js.map +0 -1
- /package/{chunk-OIIUVSUX.js.map → chunk-K5TIGJ6I.js.map} +0 -0
- /package/{chunk-Z7F6652G.js.map → chunk-LNS2K5WL.js.map} +0 -0
package/src/cf/index.ts
CHANGED
package/src/http_header.ts
CHANGED
@@ -37,7 +37,7 @@ export class HeadersImpl extends Headers {
|
|
37
37
|
export class HttpHeader {
|
38
38
|
readonly _headers: Map<string, string[]> = new Map<string, string[]>();
|
39
39
|
|
40
|
-
static from(headers?: HeadersInit |
|
40
|
+
static from(headers?: HeadersInit | Headers | HttpHeader): HttpHeader {
|
41
41
|
if (headers instanceof HttpHeader) {
|
42
42
|
return headers.Clone();
|
43
43
|
}
|
package/src/index.ts
CHANGED
@@ -19,7 +19,11 @@ export * from "./base-sys-abstraction.js";
|
|
19
19
|
export * from "./bin2text.js";
|
20
20
|
export * from "./version.js";
|
21
21
|
export * from "./http_header.js";
|
22
|
-
export *
|
22
|
+
export * from "./path-ops.js";
|
23
|
+
export * from "./json-en-decoder.js";
|
24
|
+
|
23
25
|
// ugly
|
26
|
+
export * as utils from "./utils/index.js";
|
24
27
|
import * as utils from "./utils/index.js";
|
28
|
+
|
25
29
|
export const param = utils.param;
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { exception2Result, Result } from "./result.js";
|
2
|
+
import { AsyncToEnDecoder, ToEnDecoder, TxtEnDecoder, Utf8EnDecoderSingleton } from "./txt-en-decoder.js";
|
3
|
+
|
4
|
+
export interface JSONEndeCoder {
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
6
|
+
stringify<T>(input: Result<T> | T, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
7
|
+
asyncStringify<T>(
|
8
|
+
input: Promise<Result<T> | T>,
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
|
+
replacer?: (this: any, key: string, value: any) => any,
|
11
|
+
space?: string | number,
|
12
|
+
): Promise<string>;
|
13
|
+
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
15
|
+
uint8ify<T>(input: Result<T> | T, replacer?: (this: any, key: string, value: any) => any, space?: string | number): Uint8Array;
|
16
|
+
asyncUint8ify<T>(
|
17
|
+
input: Promise<Result<T> | T>,
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
19
|
+
replacer?: (this: any, key: string, value: any) => any,
|
20
|
+
space?: string | number,
|
21
|
+
): Promise<Uint8Array>;
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
23
|
+
parse<T>(input: ToEnDecoder, reviver?: (this: any, key: string, value: any) => any): Result<T>;
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
25
|
+
asyncParse<T>(input: AsyncToEnDecoder, reviver?: (this: any, key: string, value: any) => any): Promise<Result<T>>;
|
26
|
+
}
|
27
|
+
|
28
|
+
class JSONOps implements JSONEndeCoder {
|
29
|
+
readonly txtOps: TxtEnDecoder;
|
30
|
+
constructor(txtOps: TxtEnDecoder) {
|
31
|
+
this.txtOps = txtOps;
|
32
|
+
}
|
33
|
+
async asyncStringify<T>(
|
34
|
+
input: Promise<Result<T> | T>,
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
36
|
+
replacer?: (this: any, key: string, value: any) => any,
|
37
|
+
space?: string | number,
|
38
|
+
): Promise<string> {
|
39
|
+
const resolved = await input;
|
40
|
+
return this.stringify(resolved, replacer, space);
|
41
|
+
}
|
42
|
+
async asyncUint8ify<T>(
|
43
|
+
input: Promise<Result<T> | T>,
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
45
|
+
replacer?: (this: any, key: string, value: any) => any,
|
46
|
+
space?: string | number,
|
47
|
+
): Promise<Uint8Array> {
|
48
|
+
const resolved = await input;
|
49
|
+
return this.uint8ify(resolved, replacer, space);
|
50
|
+
}
|
51
|
+
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
53
|
+
async asyncParse<T>(input: AsyncToEnDecoder, reviver?: (this: any, key: string, value: any) => any): Promise<Result<T>> {
|
54
|
+
return this.parse(await this.txtOps.asyncDecode(input), reviver);
|
55
|
+
}
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
57
|
+
stringify<T>(input: Result<T> | T, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string {
|
58
|
+
return JSON.stringify(Result.Is(input) ? input.unwrap() : input, replacer, space);
|
59
|
+
}
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
61
|
+
uint8ify<T>(input: Result<T> | T, replacer?: (this: any, key: string, value: any) => any, space?: string | number): Uint8Array {
|
62
|
+
return this.txtOps.encode(this.stringify(input, replacer, space));
|
63
|
+
}
|
64
|
+
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
66
|
+
parse<T>(input: ToEnDecoder, reviver?: (this: any, key: string, value: any) => any): Result<T> {
|
67
|
+
return exception2Result(() => JSON.parse(this.txtOps.decode(input), reviver) as T) as Result<T>;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
let jsonEnCoder: JSONEndeCoder;
|
72
|
+
export function JSONEnDecoderSingleton(txtEnde?: TxtEnDecoder): JSONEndeCoder {
|
73
|
+
let needNew = false;
|
74
|
+
if (txtEnde && txtEnde !== Utf8EnDecoderSingleton()) {
|
75
|
+
needNew = !!txtEnde;
|
76
|
+
txtEnde = txtEnde ?? Utf8EnDecoderSingleton();
|
77
|
+
}
|
78
|
+
if (needNew && txtEnde) {
|
79
|
+
return new JSONOps(txtEnde);
|
80
|
+
}
|
81
|
+
jsonEnCoder = jsonEnCoder ?? new JSONOps(Utf8EnDecoderSingleton());
|
82
|
+
return jsonEnCoder;
|
83
|
+
}
|
package/src/jsr.json
CHANGED
package/src/path-ops.ts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
export interface PathOps {
|
2
|
+
join(...args: string[]): string;
|
3
|
+
dirname(path: string): string;
|
4
|
+
basename(path: string): string;
|
5
|
+
}
|
6
|
+
|
7
|
+
class pathOpsImpl implements PathOps {
|
8
|
+
join(...paths: string[]): string {
|
9
|
+
return paths.map((i) => i.replace(/\/+$/, "")).join("/");
|
10
|
+
}
|
11
|
+
#parts(path: string): { dirname: string; basename: string } {
|
12
|
+
const splitted = path.split("/");
|
13
|
+
const last = splitted.pop();
|
14
|
+
if (splitted.length && last === "") {
|
15
|
+
return this.#parts(this.join(...splitted));
|
16
|
+
}
|
17
|
+
return {
|
18
|
+
dirname: this.join(...splitted),
|
19
|
+
basename: last ?? "",
|
20
|
+
};
|
21
|
+
}
|
22
|
+
dirname(path: string): string {
|
23
|
+
return this.#parts(path).dirname;
|
24
|
+
}
|
25
|
+
basename(path: string): string {
|
26
|
+
return this.#parts(path).basename;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
export const pathOps: PathOps = new pathOpsImpl();
|
package/src/txt-en-decoder.ts
CHANGED
@@ -1,21 +1,50 @@
|
|
1
|
+
import { Result } from "./result.js";
|
2
|
+
import { coerceIntoUint8, ToUInt8 } from "./utils/coerce-uint8.js";
|
3
|
+
|
4
|
+
export type ToEnDecoder = ToUInt8 | string | Result<string>;
|
5
|
+
export type AsyncToEnDecoder = ToEnDecoder | Blob | Promise<ToEnDecoder | Blob>;
|
6
|
+
|
1
7
|
export interface TxtEnDecoder {
|
2
|
-
encode(
|
3
|
-
decode(
|
8
|
+
encode(input: string): Uint8Array;
|
9
|
+
decode(input: ToEnDecoder): string;
|
10
|
+
asyncDecode(input: AsyncToEnDecoder): Promise<string>;
|
4
11
|
}
|
5
12
|
|
6
|
-
|
7
|
-
|
13
|
+
class Utf8EnDecoder implements TxtEnDecoder {
|
14
|
+
readonly encoder = new TextEncoder();
|
15
|
+
readonly decoder = new TextDecoder();
|
8
16
|
|
9
|
-
export class Utf8EnDecoder implements TxtEnDecoder {
|
10
17
|
encode(str: string): Uint8Array {
|
11
|
-
return encoder.encode(str);
|
18
|
+
return this.encoder.encode(str);
|
12
19
|
}
|
13
|
-
decode(data:
|
14
|
-
|
20
|
+
decode(data: ToEnDecoder): string {
|
21
|
+
if (Result.Is(data)) {
|
22
|
+
if (data.isErr()) {
|
23
|
+
throw data.Err();
|
24
|
+
}
|
25
|
+
// only for string let do coerceInto the work
|
26
|
+
const unwrapped = data.unwrap();
|
27
|
+
if (typeof unwrapped === "string") {
|
28
|
+
return this.decode(unwrapped);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
if (typeof data === "string") {
|
32
|
+
return data;
|
33
|
+
}
|
34
|
+
return this.decoder.decode(coerceIntoUint8(data as ToUInt8).Ok());
|
35
|
+
}
|
36
|
+
|
37
|
+
async asyncDecode(data: AsyncToEnDecoder): Promise<string> {
|
38
|
+
let resolved = await data;
|
39
|
+
if (resolved instanceof Blob) {
|
40
|
+
resolved = await resolved.arrayBuffer();
|
41
|
+
}
|
42
|
+
return this.decode(resolved);
|
15
43
|
}
|
16
44
|
}
|
17
45
|
|
18
|
-
|
46
|
+
let utf8EnDecoder: TxtEnDecoder;
|
19
47
|
export function Utf8EnDecoderSingleton(): TxtEnDecoder {
|
48
|
+
utf8EnDecoder = utf8EnDecoder ?? new Utf8EnDecoder();
|
20
49
|
return utf8EnDecoder;
|
21
50
|
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { Result } from "../result.js";
|
2
|
+
|
3
|
+
// Tested in txt-en-decoder.test.ts
|
4
|
+
|
5
|
+
interface GlobalBuffer {
|
6
|
+
Buffer?: {
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8
|
+
isBuffer: (obj: any) => obj is {
|
9
|
+
buffer: ArrayBufferLike;
|
10
|
+
byteOffset: number;
|
11
|
+
byteLength: number;
|
12
|
+
};
|
13
|
+
};
|
14
|
+
}
|
15
|
+
const globalBuffer = globalThis as GlobalBuffer;
|
16
|
+
|
17
|
+
export type ToUInt8Plain = Uint8Array | ArrayBuffer | ArrayBufferView;
|
18
|
+
export type ToUInt8Async = ToUInt8Plain | Blob;
|
19
|
+
export type ToUInt8 = ToUInt8Plain | Result<ToUInt8Plain>;
|
20
|
+
export type AsyncToUInt8 = ToUInt8Async | Result<ToUInt8Async> | Promise<ToUInt8Async> | Promise<Result<ToUInt8Async>>;
|
21
|
+
|
22
|
+
export function coerceIntoUint8(raw: ToUInt8): Result<Uint8Array> {
|
23
|
+
if (raw instanceof ArrayBuffer) {
|
24
|
+
return Result.Ok(new Uint8Array(raw));
|
25
|
+
}
|
26
|
+
if (ArrayBuffer.isView(raw)) {
|
27
|
+
return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
|
28
|
+
}
|
29
|
+
if (raw instanceof Blob) {
|
30
|
+
return Result.Err("Blob not supported");
|
31
|
+
}
|
32
|
+
if (globalBuffer.Buffer && globalBuffer.Buffer.isBuffer(raw)) {
|
33
|
+
return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
|
34
|
+
}
|
35
|
+
if (raw instanceof Uint8Array) {
|
36
|
+
return Result.Ok(raw);
|
37
|
+
}
|
38
|
+
if (Result.Is(raw)) {
|
39
|
+
if (raw.isErr()) {
|
40
|
+
return Result.Err(raw);
|
41
|
+
}
|
42
|
+
return coerceIntoUint8(raw.unwrap());
|
43
|
+
}
|
44
|
+
return Result.Err("Not a Uint8Array");
|
45
|
+
}
|
46
|
+
|
47
|
+
export async function asyncCoerceIntoUint8(raw: AsyncToUInt8): Promise<Result<Uint8Array>> {
|
48
|
+
let resolved = await raw;
|
49
|
+
if (resolved instanceof Blob) {
|
50
|
+
resolved = await resolved.arrayBuffer();
|
51
|
+
}
|
52
|
+
return coerceIntoUint8(resolved as ToUInt8);
|
53
|
+
}
|
package/src/utils/index.ts
CHANGED
@@ -6,3 +6,6 @@ export * from "./console-write-stream.js";
|
|
6
6
|
export * from "./fanout-write-stream.js";
|
7
7
|
export * from "./get-params-result.js";
|
8
8
|
export * from "./stripper.js";
|
9
|
+
export * from "./sorted-object.js";
|
10
|
+
export * from "./uint8array-equal.js";
|
11
|
+
export * from "./coerce-uint8.js";
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export function toSortedObjectArray<T>(set?: T): Record<string, unknown>[] {
|
2
|
+
if (!set) return [];
|
3
|
+
return toSortedArray(set).map(([k, v]) => ({ [k]: v }));
|
4
|
+
}
|
5
|
+
|
6
|
+
export function toSortedArray<T>(set?: T): [string, unknown][] {
|
7
|
+
if (!set) return [];
|
8
|
+
return Object.entries(set).sort(([a], [b]) => a.localeCompare(b));
|
9
|
+
}
|
10
|
+
|
11
|
+
export function toSortedObject<S, T extends NonNullable<S>>(set?: T): T {
|
12
|
+
if (!set) return set as T;
|
13
|
+
return Object.fromEntries(toSortedArray(set)) as T;
|
14
|
+
// return toSortedArray(set).reduce((acc, cur) => {
|
15
|
+
// acc[cur[0]] = cur[1];
|
16
|
+
// return acc
|
17
|
+
// }, {} as Record<string, unknown>) as T;
|
18
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { K as KeysParam, R as Result } from './get-params-result-
|
1
|
+
import { K as KeysParam, R as Result } from './get-params-result-CXYbMEcV.cjs';
|
2
2
|
|
3
3
|
interface NamedWritableStream {
|
4
4
|
readonly name: string;
|
@@ -106,4 +106,4 @@ interface SysAbstraction {
|
|
106
106
|
FileSystem(): FileService;
|
107
107
|
}
|
108
108
|
|
109
|
-
export { type Duration as D, type Env as E, type FileService as F, IDMode as I, type NamedWritableStream as N, type OnSetItem as O, RandomMode as R, type
|
109
|
+
export { type Duration as D, type Env as E, type FileService as F, IDMode as I, type NamedWritableStream as N, type OnSetItem as O, RandomMode as R, type SysAbstraction as S, Time as T, type VoidFunc as V, TimeMode as a, type SystemService as b, type EnvActions as c, EnvImpl as d, type EnvFactoryOpts as e, String2TimeMode as f, type EnvTuple as g, type EnvMap as h, type EnvFactoryFn as i, envFactory as j, TimeUnits as k, registerEnvAction as r };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { K as KeysParam, R as Result } from './get-params-result-
|
1
|
+
import { K as KeysParam, R as Result } from './get-params-result-CXYbMEcV.js';
|
2
2
|
|
3
3
|
interface NamedWritableStream {
|
4
4
|
readonly name: string;
|
@@ -106,4 +106,4 @@ interface SysAbstraction {
|
|
106
106
|
FileSystem(): FileService;
|
107
107
|
}
|
108
108
|
|
109
|
-
export { type Duration as D, type Env as E, type FileService as F, IDMode as I, type NamedWritableStream as N, type OnSetItem as O, RandomMode as R, type
|
109
|
+
export { type Duration as D, type Env as E, type FileService as F, IDMode as I, type NamedWritableStream as N, type OnSetItem as O, RandomMode as R, type SysAbstraction as S, Time as T, type VoidFunc as V, TimeMode as a, type SystemService as b, type EnvActions as c, EnvImpl as d, type EnvFactoryOpts as e, String2TimeMode as f, type EnvTuple as g, type EnvMap as h, type EnvFactoryFn as i, envFactory as j, TimeUnits as k, registerEnvAction as r };
|
package/test/index.cjs
CHANGED
@@ -99,19 +99,159 @@ _promise = new WeakMap();
|
|
99
99
|
_resolveFn = new WeakMap();
|
100
100
|
_rejectFn = new WeakMap();
|
101
101
|
|
102
|
+
// src/result.ts
|
103
|
+
var Result = class _Result {
|
104
|
+
static Ok(t) {
|
105
|
+
return new ResultOK(t);
|
106
|
+
}
|
107
|
+
static Err(t) {
|
108
|
+
if (typeof t === "string") {
|
109
|
+
return new ResultError(new Error(t));
|
110
|
+
}
|
111
|
+
if (_Result.Is(t)) {
|
112
|
+
if (t.is_ok()) {
|
113
|
+
return new ResultError(new Error("Result Error is Ok"));
|
114
|
+
}
|
115
|
+
return t;
|
116
|
+
}
|
117
|
+
return new ResultError(t);
|
118
|
+
}
|
119
|
+
static Is(t) {
|
120
|
+
if (!t) {
|
121
|
+
return false;
|
122
|
+
}
|
123
|
+
if (t instanceof _Result) {
|
124
|
+
return true;
|
125
|
+
}
|
126
|
+
const rt = t;
|
127
|
+
if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === "function")) {
|
128
|
+
return true;
|
129
|
+
}
|
130
|
+
return false;
|
131
|
+
}
|
132
|
+
isOk() {
|
133
|
+
return this.is_ok();
|
134
|
+
}
|
135
|
+
isErr() {
|
136
|
+
return this.is_err();
|
137
|
+
}
|
138
|
+
Ok() {
|
139
|
+
return this.unwrap();
|
140
|
+
}
|
141
|
+
Err() {
|
142
|
+
return this.unwrap_err();
|
143
|
+
}
|
144
|
+
};
|
145
|
+
var ResultOK = class extends Result {
|
146
|
+
constructor(t) {
|
147
|
+
super();
|
148
|
+
this._t = t;
|
149
|
+
}
|
150
|
+
is_ok() {
|
151
|
+
return true;
|
152
|
+
}
|
153
|
+
is_err() {
|
154
|
+
return false;
|
155
|
+
}
|
156
|
+
unwrap_err() {
|
157
|
+
throw new Error("Result is Ok");
|
158
|
+
}
|
159
|
+
unwrap() {
|
160
|
+
return this._t;
|
161
|
+
}
|
162
|
+
};
|
163
|
+
var ResultError = class extends Result {
|
164
|
+
constructor(t) {
|
165
|
+
super();
|
166
|
+
this._error = t;
|
167
|
+
}
|
168
|
+
is_ok() {
|
169
|
+
return false;
|
170
|
+
}
|
171
|
+
is_err() {
|
172
|
+
return true;
|
173
|
+
}
|
174
|
+
unwrap() {
|
175
|
+
throw new Error(`Result is Err: ${this._error}`);
|
176
|
+
}
|
177
|
+
unwrap_err() {
|
178
|
+
return this._error;
|
179
|
+
}
|
180
|
+
};
|
181
|
+
function exception2Result(fn) {
|
182
|
+
try {
|
183
|
+
const res = fn();
|
184
|
+
if (res instanceof Promise) {
|
185
|
+
return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e));
|
186
|
+
}
|
187
|
+
return Result.Ok(res);
|
188
|
+
} catch (e) {
|
189
|
+
return Result.Err(e);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
// src/utils/coerce-uint8.ts
|
194
|
+
var globalBuffer = globalThis;
|
195
|
+
function coerceIntoUint8(raw) {
|
196
|
+
if (raw instanceof ArrayBuffer) {
|
197
|
+
return Result.Ok(new Uint8Array(raw));
|
198
|
+
}
|
199
|
+
if (ArrayBuffer.isView(raw)) {
|
200
|
+
return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
|
201
|
+
}
|
202
|
+
if (raw instanceof Blob) {
|
203
|
+
return Result.Err("Blob not supported");
|
204
|
+
}
|
205
|
+
if (globalBuffer.Buffer && globalBuffer.Buffer.isBuffer(raw)) {
|
206
|
+
return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
|
207
|
+
}
|
208
|
+
if (raw instanceof Uint8Array) {
|
209
|
+
return Result.Ok(raw);
|
210
|
+
}
|
211
|
+
if (Result.Is(raw)) {
|
212
|
+
if (raw.isErr()) {
|
213
|
+
return Result.Err(raw);
|
214
|
+
}
|
215
|
+
return coerceIntoUint8(raw.unwrap());
|
216
|
+
}
|
217
|
+
return Result.Err("Not a Uint8Array");
|
218
|
+
}
|
219
|
+
|
102
220
|
// src/txt-en-decoder.ts
|
103
|
-
var encoder = new TextEncoder();
|
104
|
-
var decoder = new TextDecoder();
|
105
221
|
var Utf8EnDecoder = class {
|
222
|
+
constructor() {
|
223
|
+
this.encoder = new TextEncoder();
|
224
|
+
this.decoder = new TextDecoder();
|
225
|
+
}
|
106
226
|
encode(str) {
|
107
|
-
return encoder.encode(str);
|
227
|
+
return this.encoder.encode(str);
|
108
228
|
}
|
109
229
|
decode(data) {
|
110
|
-
|
230
|
+
if (Result.Is(data)) {
|
231
|
+
if (data.isErr()) {
|
232
|
+
throw data.Err();
|
233
|
+
}
|
234
|
+
const unwrapped = data.unwrap();
|
235
|
+
if (typeof unwrapped === "string") {
|
236
|
+
return this.decode(unwrapped);
|
237
|
+
}
|
238
|
+
}
|
239
|
+
if (typeof data === "string") {
|
240
|
+
return data;
|
241
|
+
}
|
242
|
+
return this.decoder.decode(coerceIntoUint8(data).Ok());
|
243
|
+
}
|
244
|
+
async asyncDecode(data) {
|
245
|
+
let resolved = await data;
|
246
|
+
if (resolved instanceof Blob) {
|
247
|
+
resolved = await resolved.arrayBuffer();
|
248
|
+
}
|
249
|
+
return this.decode(resolved);
|
111
250
|
}
|
112
251
|
};
|
113
|
-
var utf8EnDecoder
|
252
|
+
var utf8EnDecoder;
|
114
253
|
function Utf8EnDecoderSingleton() {
|
254
|
+
utf8EnDecoder = utf8EnDecoder != null ? utf8EnDecoder : new Utf8EnDecoder();
|
115
255
|
return utf8EnDecoder;
|
116
256
|
}
|
117
257
|
|
@@ -300,8 +440,8 @@ function logValueInternal(val, ctx) {
|
|
300
440
|
}
|
301
441
|
if (ArrayBuffer.isView(val)) {
|
302
442
|
try {
|
303
|
-
const
|
304
|
-
const asStr =
|
443
|
+
const decoder = new TextDecoder();
|
444
|
+
const asStr = decoder.decode(val);
|
305
445
|
const obj = JSON.parse(asStr);
|
306
446
|
return logValueInternal(obj, ctx);
|
307
447
|
} catch (e) {
|
@@ -624,14 +764,14 @@ var BaseSysAbstraction = class {
|
|
624
764
|
this._fileSystem = params.FileSystem;
|
625
765
|
this._systemService = params.SystemService;
|
626
766
|
this._txtEnDe = params.TxtEnDecoder;
|
627
|
-
const
|
767
|
+
const decoder = this._txtEnDe;
|
628
768
|
this._stdout = CFWriteableStream((chunk) => {
|
629
|
-
const decoded =
|
769
|
+
const decoded = decoder.decode(chunk);
|
630
770
|
console.log(decoded.trimEnd());
|
631
771
|
return Promise.resolve();
|
632
772
|
});
|
633
773
|
this._stderr = CFWriteableStream((chunk) => {
|
634
|
-
const decoded =
|
774
|
+
const decoded = decoder.decode(chunk);
|
635
775
|
console.error(decoded.trimEnd());
|
636
776
|
return Promise.resolve();
|
637
777
|
});
|
@@ -1008,97 +1148,6 @@ var CFEnvActions = class _CFEnvActions {
|
|
1008
1148
|
}
|
1009
1149
|
};
|
1010
1150
|
|
1011
|
-
// src/result.ts
|
1012
|
-
var Result = class _Result {
|
1013
|
-
static Ok(t) {
|
1014
|
-
return new ResultOK(t);
|
1015
|
-
}
|
1016
|
-
static Err(t) {
|
1017
|
-
if (typeof t === "string") {
|
1018
|
-
return new ResultError(new Error(t));
|
1019
|
-
}
|
1020
|
-
if (_Result.Is(t)) {
|
1021
|
-
if (t.is_ok()) {
|
1022
|
-
return new ResultError(new Error("Result Error is Ok"));
|
1023
|
-
}
|
1024
|
-
return t;
|
1025
|
-
}
|
1026
|
-
return new ResultError(t);
|
1027
|
-
}
|
1028
|
-
static Is(t) {
|
1029
|
-
if (!t) {
|
1030
|
-
return false;
|
1031
|
-
}
|
1032
|
-
if (t instanceof _Result) {
|
1033
|
-
return true;
|
1034
|
-
}
|
1035
|
-
const rt = t;
|
1036
|
-
if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === "function")) {
|
1037
|
-
return true;
|
1038
|
-
}
|
1039
|
-
return false;
|
1040
|
-
}
|
1041
|
-
isOk() {
|
1042
|
-
return this.is_ok();
|
1043
|
-
}
|
1044
|
-
isErr() {
|
1045
|
-
return this.is_err();
|
1046
|
-
}
|
1047
|
-
Ok() {
|
1048
|
-
return this.unwrap();
|
1049
|
-
}
|
1050
|
-
Err() {
|
1051
|
-
return this.unwrap_err();
|
1052
|
-
}
|
1053
|
-
};
|
1054
|
-
var ResultOK = class extends Result {
|
1055
|
-
constructor(t) {
|
1056
|
-
super();
|
1057
|
-
this._t = t;
|
1058
|
-
}
|
1059
|
-
is_ok() {
|
1060
|
-
return true;
|
1061
|
-
}
|
1062
|
-
is_err() {
|
1063
|
-
return false;
|
1064
|
-
}
|
1065
|
-
unwrap_err() {
|
1066
|
-
throw new Error("Result is Ok");
|
1067
|
-
}
|
1068
|
-
unwrap() {
|
1069
|
-
return this._t;
|
1070
|
-
}
|
1071
|
-
};
|
1072
|
-
var ResultError = class extends Result {
|
1073
|
-
constructor(t) {
|
1074
|
-
super();
|
1075
|
-
this._error = t;
|
1076
|
-
}
|
1077
|
-
is_ok() {
|
1078
|
-
return false;
|
1079
|
-
}
|
1080
|
-
is_err() {
|
1081
|
-
return true;
|
1082
|
-
}
|
1083
|
-
unwrap() {
|
1084
|
-
throw new Error(`Result is Err: ${this._error}`);
|
1085
|
-
}
|
1086
|
-
unwrap_err() {
|
1087
|
-
return this._error;
|
1088
|
-
}
|
1089
|
-
};
|
1090
|
-
function exception2Result(fn) {
|
1091
|
-
try {
|
1092
|
-
const res = fn();
|
1093
|
-
if (res instanceof Promise) {
|
1094
|
-
return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e));
|
1095
|
-
}
|
1096
|
-
return Result.Ok(res);
|
1097
|
-
} catch (e) {
|
1098
|
-
return Result.Err(e);
|
1099
|
-
}
|
1100
|
-
}
|
1101
|
-
|
1102
1151
|
// src/utils/get-params-result.ts
|
1103
1152
|
var _REQUIRED = class {
|
1104
1153
|
constructor() {
|