@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.
Files changed (127) hide show
  1. package/{base-sys-abstraction-CKI4xiRR.d.ts → base-sys-abstraction-Cqb4snul.d.ts} +2 -2
  2. package/{base-sys-abstraction-DLnSeH4s.d.cts → base-sys-abstraction-WS7lNbFm.d.cts} +2 -2
  3. package/cf/index.cjs +59 -8
  4. package/cf/index.cjs.map +1 -1
  5. package/cf/index.d.cts +19 -4
  6. package/cf/index.d.ts +19 -4
  7. package/cf/index.js +5 -3
  8. package/cf/index.js.map +1 -1
  9. package/{chunk-QDDO6NOK.js → chunk-BVZ6HD34.js} +66 -7
  10. package/chunk-BVZ6HD34.js.map +1 -0
  11. package/{chunk-N5ISHPJ6.js → chunk-H5JLIMWA.js} +41 -2
  12. package/{chunk-N5ISHPJ6.js.map → chunk-H5JLIMWA.js.map} +1 -1
  13. package/{chunk-OIIUVSUX.js → chunk-K5TIGJ6I.js} +3 -3
  14. package/{chunk-Z7F6652G.js → chunk-LNS2K5WL.js} +4 -4
  15. package/{chunk-4QRZPFED.js → chunk-SCFB6I2C.js} +58 -57
  16. package/{chunk-4QRZPFED.js.map → chunk-SCFB6I2C.js.map} +1 -1
  17. package/deno/index.cjs +57 -8
  18. package/deno/index.cjs.map +1 -1
  19. package/deno/index.d.cts +3 -3
  20. package/deno/index.d.ts +3 -3
  21. package/deno/index.js +2 -2
  22. package/{get-params-result-Bhy5997x.d.ts → get-params-result-CXYbMEcV.d.cts} +13 -7
  23. package/{get-params-result-Bhy5997x.d.cts → get-params-result-CXYbMEcV.d.ts} +13 -7
  24. package/{index-CcNS7k5i.d.cts → index-BH1SIYUK.d.cts} +2 -2
  25. package/{index-DjN6Y4N2.d.ts → index-BQMIP01w.d.ts} +19 -3
  26. package/{index-6ofzOS0J.d.ts → index-BeXMFEyF.d.ts} +2 -2
  27. package/{index-TZQHtEZo.d.cts → index-C6hvxtE7.d.cts} +19 -3
  28. package/index.cjs +180 -14
  29. package/index.cjs.map +1 -1
  30. package/index.d.cts +27 -10
  31. package/index.d.ts +27 -10
  32. package/index.js +83 -7
  33. package/index.js.map +1 -1
  34. package/metafile-cjs.json +1 -0
  35. package/metafile-esm.json +1 -0
  36. package/node/index.cjs +139 -90
  37. package/node/index.cjs.map +1 -1
  38. package/node/index.d.cts +3 -3
  39. package/node/index.d.ts +3 -3
  40. package/node/index.js +2 -2
  41. package/package.json +2 -2
  42. package/src/cf/index.ts +1 -0
  43. package/src/http_header.ts +1 -1
  44. package/src/index.ts +5 -1
  45. package/src/json-en-decoder.ts +83 -0
  46. package/src/jsr.json +1 -1
  47. package/src/path-ops.ts +30 -0
  48. package/src/txt-en-decoder.ts +38 -9
  49. package/src/utils/coerce-uint8.ts +53 -0
  50. package/src/utils/index.ts +3 -0
  51. package/src/utils/sorted-object.ts +18 -0
  52. package/src/utils/uint8array-equal.ts +11 -0
  53. package/{sys-abstraction-BRDT_TIU.d.cts → sys-abstraction-B-0XMe9V.d.cts} +2 -2
  54. package/{sys-abstraction-Bd0EzwO6.d.ts → sys-abstraction-CZa-VyNs.d.ts} +2 -2
  55. package/test/index.cjs +150 -101
  56. package/test/index.cjs.map +1 -1
  57. package/test/index.d.cts +3 -3
  58. package/test/index.d.ts +3 -3
  59. package/test/index.js +4 -4
  60. package/ts/src/cf/index.d.ts +1 -0
  61. package/ts/src/cf/index.d.ts.map +1 -1
  62. package/ts/src/cf/index.js +1 -0
  63. package/ts/src/cf/index.js.map +1 -1
  64. package/ts/src/http_header.d.ts +1 -1
  65. package/ts/src/http_header.d.ts.map +1 -1
  66. package/ts/src/http_header.js.map +1 -1
  67. package/ts/src/index.d.ts +2 -0
  68. package/ts/src/index.d.ts.map +1 -1
  69. package/ts/src/index.js +2 -0
  70. package/ts/src/index.js.map +1 -1
  71. package/ts/src/json-en-decoder.d.ts +12 -0
  72. package/ts/src/json-en-decoder.d.ts.map +1 -0
  73. package/ts/src/json-en-decoder.js +41 -0
  74. package/ts/src/json-en-decoder.js.map +1 -0
  75. package/ts/src/json-en-decoder.test.d.ts +2 -0
  76. package/ts/src/json-en-decoder.test.d.ts.map +1 -0
  77. package/ts/src/json-en-decoder.test.js +18 -0
  78. package/ts/src/json-en-decoder.test.js.map +1 -0
  79. package/ts/src/path-ops.d.ts +7 -0
  80. package/ts/src/path-ops.d.ts.map +1 -0
  81. package/ts/src/path-ops.js +33 -0
  82. package/ts/src/path-ops.js.map +1 -0
  83. package/ts/src/path-ops.test.d.ts +2 -0
  84. package/ts/src/path-ops.test.d.ts.map +1 -0
  85. package/ts/src/path-ops.test.js +23 -0
  86. package/ts/src/path-ops.test.js.map +1 -0
  87. package/ts/src/txt-en-decoder.d.ts +7 -6
  88. package/ts/src/txt-en-decoder.d.ts.map +1 -1
  89. package/ts/src/txt-en-decoder.js +30 -6
  90. package/ts/src/txt-en-decoder.js.map +1 -1
  91. package/ts/src/txt-en-decoder.test.d.ts +2 -0
  92. package/ts/src/txt-en-decoder.test.d.ts.map +1 -0
  93. package/ts/src/txt-en-decoder.test.js +60 -0
  94. package/ts/src/txt-en-decoder.test.js.map +1 -0
  95. package/ts/src/utils/coerce-uint8.d.ts +8 -0
  96. package/ts/src/utils/coerce-uint8.d.ts.map +1 -0
  97. package/ts/src/utils/coerce-uint8.js +34 -0
  98. package/ts/src/utils/coerce-uint8.js.map +1 -0
  99. package/ts/src/utils/index.d.ts +3 -0
  100. package/ts/src/utils/index.d.ts.map +1 -1
  101. package/ts/src/utils/index.js +3 -0
  102. package/ts/src/utils/index.js.map +1 -1
  103. package/ts/src/utils/sorted-objec.test.d.ts +2 -0
  104. package/ts/src/utils/sorted-objec.test.d.ts.map +1 -0
  105. package/ts/src/utils/sorted-objec.test.js +20 -0
  106. package/ts/src/utils/sorted-objec.test.js.map +1 -0
  107. package/ts/src/utils/sorted-object.d.ts +4 -0
  108. package/ts/src/utils/sorted-object.d.ts.map +1 -0
  109. package/ts/src/utils/sorted-object.js +16 -0
  110. package/ts/src/utils/sorted-object.js.map +1 -0
  111. package/ts/src/utils/uint8array-equal.d.ts +2 -0
  112. package/ts/src/utils/uint8array-equal.d.ts.map +1 -0
  113. package/ts/src/utils/uint8array-equal.js +12 -0
  114. package/ts/src/utils/uint8array-equal.js.map +1 -0
  115. package/utils/index.cjs +182 -87
  116. package/utils/index.cjs.map +1 -1
  117. package/utils/index.d.cts +2 -2
  118. package/utils/index.d.ts +2 -2
  119. package/utils/index.js +14 -2
  120. package/web/index.cjs +57 -8
  121. package/web/index.cjs.map +1 -1
  122. package/web/index.d.cts +3 -3
  123. package/web/index.d.ts +3 -3
  124. package/web/index.js +3 -3
  125. package/chunk-QDDO6NOK.js.map +0 -1
  126. /package/{chunk-OIIUVSUX.js.map → chunk-K5TIGJ6I.js.map} +0 -0
  127. /package/{chunk-Z7F6652G.js.map → chunk-LNS2K5WL.js.map} +0 -0
package/src/cf/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./cf-sys-abstraction.js";
2
+ export * from "./cf-env-actions.js";
@@ -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 | NodeJS.Dict<string | string[]> | Headers | HttpHeader): HttpHeader {
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 * as utils from "./utils/index.js";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adviser/cement",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./web": "./web/index.ts",
@@ -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();
@@ -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(str: string): Uint8Array;
3
- decode(data: Uint8Array): string;
8
+ encode(input: string): Uint8Array;
9
+ decode(input: ToEnDecoder): string;
10
+ asyncDecode(input: AsyncToEnDecoder): Promise<string>;
4
11
  }
5
12
 
6
- const encoder = new TextEncoder();
7
- const decoder = new TextDecoder();
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: Uint8Array): string {
14
- return decoder.decode(data);
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
- const utf8EnDecoder = new Utf8EnDecoder();
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
+ }
@@ -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
+ }
@@ -0,0 +1,11 @@
1
+ export function UInt8ArrayEqual(a: Uint8Array, b: Uint8Array): boolean {
2
+ if (a.length !== b.length) {
3
+ return false;
4
+ }
5
+ for (let i = 0; i < a.length; i++) {
6
+ if (a[i] !== b[i]) {
7
+ return false;
8
+ }
9
+ }
10
+ return true;
11
+ }
@@ -1,4 +1,4 @@
1
- import { K as KeysParam, R as Result } from './get-params-result-Bhy5997x.cjs';
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 SystemService as S, Time as T, type VoidFunc as V, type SysAbstraction as a, TimeMode as b, String2TimeMode as c, type EnvTuple as d, type EnvMap as e, type EnvActions as f, type EnvFactoryOpts as g, type EnvFactoryFn as h, envFactory as i, EnvImpl as j, TimeUnits as k, registerEnvAction as r };
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-Bhy5997x.js';
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 SystemService as S, Time as T, type VoidFunc as V, type SysAbstraction as a, TimeMode as b, String2TimeMode as c, type EnvTuple as d, type EnvMap as e, type EnvActions as f, type EnvFactoryOpts as g, type EnvFactoryFn as h, envFactory as i, EnvImpl as j, TimeUnits as k, registerEnvAction as r };
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
- return decoder.decode(data);
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 = new 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 decoder2 = new TextDecoder();
304
- const asStr = decoder2.decode(val);
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 decoder2 = this._txtEnDe;
767
+ const decoder = this._txtEnDe;
628
768
  this._stdout = CFWriteableStream((chunk) => {
629
- const decoded = decoder2.decode(chunk);
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 = decoder2.decode(chunk);
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() {