vivth 1.1.2 → 1.2.1

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 (107) hide show
  1. package/README.md +1215 -433
  2. package/README.src.md +5 -2
  3. package/bun.lock +228 -0
  4. package/index.mjs +17 -4
  5. package/package.json +6 -3
  6. package/src/bundler/CompileJS.mjs +258 -0
  7. package/src/bundler/CreateESPlugin.mjs +24 -0
  8. package/src/bundler/EsBundler.mjs +27 -13
  9. package/src/bundler/FSInline.mjs +57 -0
  10. package/src/bundler/FSInlineAnalyzer.mjs +197 -0
  11. package/src/bundler/FSInlineBundled.mjs +34 -0
  12. package/src/bundler/adds/ToBundledJSPlugin.mjs +77 -0
  13. package/src/bundler/adds/externals.mjs +8 -0
  14. package/src/bundler/adds/pluginVivthBundle.mjs +5 -0
  15. package/src/class/Console.mjs +48 -27
  16. package/src/class/Derived.mjs +55 -7
  17. package/src/class/Effect.mjs +100 -39
  18. package/src/class/EnvSignal.mjs +5 -5
  19. package/src/class/EventSignal.mjs +55 -5
  20. package/src/class/FileSafe.mjs +124 -0
  21. package/src/class/ListDerived.mjs +6 -3
  22. package/src/class/ListSignal.mjs +11 -11
  23. package/src/class/LitExp.mjs +405 -0
  24. package/src/class/Paths.mjs +27 -1
  25. package/src/class/QChannel.mjs +79 -28
  26. package/src/class/SafeExit.mjs +31 -11
  27. package/src/class/Setup.mjs +5 -2
  28. package/src/class/Signal.mjs +26 -24
  29. package/src/class/WorkerMainThread.mjs +100 -133
  30. package/src/class/WorkerMainThreadBundled.mjs +216 -0
  31. package/src/class/WorkerThread.mjs +38 -32
  32. package/src/common/Base64URL.mjs +10 -5
  33. package/src/common/Base64URLFromFile.mjs +24 -0
  34. package/src/common/keys.mjs +3 -0
  35. package/src/doc/JSautoDOC.mjs +32 -56
  36. package/src/doc/parsedFile.mjs +37 -36
  37. package/src/function/CreateImmutable.mjs +9 -9
  38. package/src/function/EventCheck.mjs +2 -2
  39. package/src/function/EventObject.mjs +5 -5
  40. package/src/function/GetRuntime.mjs +38 -0
  41. package/src/function/IsAsync.mjs +2 -2
  42. package/src/function/LazyFactory.mjs +13 -13
  43. package/src/function/Timeout.mjs +2 -2
  44. package/src/function/Try.mjs +17 -12
  45. package/src/function/TryAsync.mjs +5 -5
  46. package/src/function/TrySync.mjs +5 -5
  47. package/src/function/TsToMjs.mjs +5 -4
  48. package/src/types/LitExpKeyType.mjs +5 -0
  49. package/src/types/QCBReturn.mjs +1 -1
  50. package/src/types/Runtime.mjs +7 -0
  51. package/types/dev/fsInline.d.mts +1 -0
  52. package/types/dev/test.d.mts +1 -0
  53. package/types/dev/testWorker.d.mts +7 -0
  54. package/types/dev/testbundle.d.mts +1 -0
  55. package/types/dev/workerThreadClass.d.mts +13 -0
  56. package/types/index.d.mts +13 -4
  57. package/types/src/bundler/CompileJS.d.mts +78 -0
  58. package/types/src/bundler/CreateESPlugin.d.mts +17 -0
  59. package/types/src/bundler/EsBundler.d.mts +33 -4
  60. package/types/src/bundler/FSInline.d.mts +43 -0
  61. package/types/src/bundler/FSInlineAnalyzer.d.mts +36 -0
  62. package/types/src/bundler/FSInlineBundled.d.mts +22 -0
  63. package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +16 -0
  64. package/types/src/bundler/adds/externals.d.mts +1 -0
  65. package/types/src/bundler/adds/pluginVivthBundle.d.mts +1 -0
  66. package/types/src/class/Console.d.mts +36 -5
  67. package/types/src/class/Derived.d.mts +132 -5
  68. package/types/src/class/Effect.d.mts +106 -7
  69. package/types/src/class/EnvSignal.d.mts +8 -8
  70. package/types/src/class/EventSignal.d.mts +151 -7
  71. package/types/src/class/FileSafe.d.mts +90 -0
  72. package/types/src/class/ListDerived.d.mts +8 -5
  73. package/types/src/class/ListSignal.d.mts +123 -18
  74. package/types/src/class/LitExp.d.mts +361 -0
  75. package/types/src/class/Paths.d.mts +18 -1
  76. package/types/src/class/QChannel.d.mts +69 -22
  77. package/types/src/class/SafeExit.d.mts +24 -9
  78. package/types/src/class/Setup.d.mts +6 -5
  79. package/types/src/class/Signal.d.mts +73 -17
  80. package/types/src/class/WorkerMainThread.d.mts +39 -37
  81. package/types/src/class/WorkerMainThreadBundled.d.mts +85 -0
  82. package/types/src/class/WorkerThread.d.mts +32 -27
  83. package/types/src/common/Base64URL.d.mts +22 -1
  84. package/types/src/common/Base64URLFromFile.d.mts +16 -0
  85. package/types/src/common/keys.d.mts +1 -0
  86. package/types/src/doc/JSautoDOC.d.mts +3 -19
  87. package/types/src/doc/parsedFile.d.mts +72 -13
  88. package/types/src/function/CreateImmutable.d.mts +27 -2
  89. package/types/src/function/EventCheck.d.mts +15 -0
  90. package/types/src/function/EventObject.d.mts +17 -2
  91. package/types/src/function/GetRuntime.d.mts +2 -0
  92. package/types/src/function/IsAsync.d.mts +18 -0
  93. package/types/src/function/LazyFactory.d.mts +35 -2
  94. package/types/src/function/Timeout.d.mts +16 -0
  95. package/types/src/function/Try.d.mts +52 -1
  96. package/types/src/function/TryAsync.d.mts +22 -1
  97. package/types/src/function/TrySync.d.mts +16 -1
  98. package/types/src/function/TsToMjs.d.mts +19 -0
  99. package/types/src/types/LitExpKeyType.d.mts +1 -0
  100. package/types/src/types/QCBReturn.d.mts +1 -1
  101. package/types/src/types/Runtime.d.mts +1 -0
  102. package/dev/index.mjs +0 -28
  103. package/src/bundler/CompileMJS.mjs +0 -110
  104. package/src/function/WriteFileSafe.mjs +0 -37
  105. package/types/src/bundler/A.d.mts +0 -1
  106. package/types/src/bundler/CompileMJS.d.mts +0 -8
  107. package/types/src/function/WriteFileSafe.d.mts +0 -2
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @description
3
+ * - collection of static methods of file access with added safety to mkdir before proceeding;
4
+ */
5
+ export class FileSafe {
6
+ /**
7
+ * @description
8
+ * - method to create file safely by recursively mkdir the dirname of the outFile;
9
+ * - also returning promise of result & error as value;
10
+ * @param {Parameters<writeFile>[0]} outFile
11
+ * @param {Parameters<writeFile>[1]} content
12
+ * @param {Parameters<writeFile>[2]} [options]
13
+ * @returns {ReturnType<typeof TryAsync<void>>}
14
+ * @example
15
+ * import { join } from 'node:path';
16
+ * import { FileSafe, Paths } from 'vivth';
17
+ *
18
+ * const [, errorWrite] = await FileSafe.write(
19
+ * join(Paths.root, '/some/path.mjs'),
20
+ * `console.log("hello-world!!");`,
21
+ * { encoding: 'utf-8' }
22
+ * );
23
+ */
24
+ static write: (outFile: Parameters<typeof writeFile>[0], content: Parameters<typeof writeFile>[1], options?: Parameters<typeof writeFile>[2]) => ReturnType<typeof TryAsync<void>>;
25
+ /**
26
+ * @description
27
+ * - method to copy file/dir safely by recursively mkdir the dirname of the dest;
28
+ * - also returning promise of result & error as value;
29
+ * @param {Parameters<typeof copyFile>[0]} sourceFile
30
+ * @param {Parameters<typeof copyFile>[1]} destinationFile
31
+ * @param {Parameters<typeof copyFile>[2]} mode
32
+ * @returns {ReturnType<typeof TryAsync<void>>}
33
+ * @example
34
+ * import { join } from 'node:path';
35
+ * import { FileSafe, Paths } from 'vivth';
36
+ *
37
+ * const [, errorWrite] = await FileSafe.copy(
38
+ * join(Paths.root, '/some/path.mjs'),
39
+ * join(Paths.root, '/other/path.copy.mjs'),
40
+ * { encoding: 'utf-8' }
41
+ * );
42
+ */
43
+ static copy: (sourceFile: Parameters<typeof copyFile>[0], destinationFile: Parameters<typeof copyFile>[1], mode: Parameters<typeof copyFile>[2]) => ReturnType<typeof TryAsync<void>>;
44
+ /**
45
+ * @description
46
+ * - method to rename file/dir safely by recursively mkdir the dirname of the dest;
47
+ * - also returning promise of result & error as value;
48
+ * @param {Parameters<typeof rename>[0]} oldPath
49
+ * @param {Parameters<typeof rename>[0]} newPath
50
+ * @returns {ReturnType<typeof TryAsync<void>>}
51
+ * @example
52
+ * import { join } from 'node:path';
53
+ * import { FileSafe, Paths } from 'vivth';
54
+ *
55
+ * const [, errorRename] = await FileSafe.rename(
56
+ * join(Paths.root, 'some/path'),
57
+ * join(Paths.root, 'other/path'),
58
+ * );
59
+ */
60
+ static rename: (oldPath: Parameters<typeof rename>[0], newPath: Parameters<typeof rename>[0]) => ReturnType<typeof TryAsync<void>>;
61
+ /**
62
+ * @description
63
+ * - function to remove dir and file;
64
+ * - also returning promise of result & error as value;
65
+ * @param {Parameters<rm>[0]} path
66
+ * @param {Parameters<rm>[1]} [rmOptions]
67
+ * @returns {ReturnType<typeof TryAsync<void>>}
68
+ */
69
+ static rm: (path: Parameters<typeof rm>[0], rmOptions?: Parameters<typeof rm>[1]) => ReturnType<typeof TryAsync<void>>;
70
+ /**
71
+ * @description
72
+ * - create directory recursively;
73
+ * - also returning promise of result & error as value;
74
+ * @param {Parameters<mkdir>[0]} outDir
75
+ * - absolute path
76
+ * @returns {ReturnType<typeof TryAsync<string>>}
77
+ * @example
78
+ * import { join } from 'node:path';
79
+ * import { FileSafe, Paths } from 'vivth';
80
+ *
81
+ * const [str, errorMkDir] = await FileSafe.mkdir(join(Paths.root, '/some/path/example'));
82
+ */
83
+ static mkdir: (outDir: Parameters<typeof mkdir>[0]) => ReturnType<typeof TryAsync<string>>;
84
+ }
85
+ import { TryAsync } from '../function/TryAsync.mjs';
86
+ import { writeFile } from 'node:fs/promises';
87
+ import { copyFile } from 'node:fs/promises';
88
+ import { rename } from 'node:fs/promises';
89
+ import { rm } from 'node:fs/promises';
90
+ import { mkdir } from 'node:fs/promises';
@@ -3,16 +3,19 @@
3
3
  * - class to create `dervivedList` that satisfy `Array<Record<string, string>>`;
4
4
  * - usefull for `derivedLoops`, e.g. temporary search values;
5
5
  * - is a `Derived` instance;
6
- * @template {ListArg} LA
7
- * @extends {Derived<LA[]>}
6
+ * @template {ListArg} LISTARG
7
+ * @extends {Derived<LISTARG[]>}
8
8
  */
9
- export class ListDerived<LA extends import("../types/ListArg.mjs").ListArg> extends Derived<LA[]> {
9
+ export class ListDerived<LISTARG extends import("../types/ListArg.mjs").ListArg> extends Derived<LISTARG[]> {
10
10
  /**
11
11
  * @typedef {import('../types/ListArg.mjs').ListArg} ListArg
12
+ * @typedef {import('../common/lazie.mjs').unwrapLazy} unwrapLazy
12
13
  */
13
14
  /**
14
15
  * @description
15
- * @param {(effectInstanceOptions:Effect["options"])=>Promise<LA[]>} derivedFunction
16
+ * @param {(effectInstanceOptions:Omit<Effect["options"],
17
+ * unwrapLazy>)=>
18
+ * Promise<LISTARG[]>} derivedFunction
16
19
  * @example
17
20
  * import { ListSignal, ListDerived } from 'vivth';
18
21
  *
@@ -29,7 +32,7 @@ export class ListDerived<LA extends import("../types/ListArg.mjs").ListArg> exte
29
32
  * })
30
33
  * });
31
34
  */
32
- constructor(derivedFunction: (effectInstanceOptions: Effect["options"]) => Promise<LA[]>);
35
+ constructor(derivedFunction: (effectInstanceOptions: Omit<Effect["options"], "vivth:unwrapLazy;">) => Promise<LISTARG[]>);
33
36
  }
34
37
  import { Derived } from './Derived.mjs';
35
38
  import { Effect } from './Effect.mjs';
@@ -5,10 +5,10 @@
5
5
  /**
6
6
  * @description
7
7
  * - class to create list that satisfy `Array<Record<string, string>>`.
8
- * @template {import('../types/ListArg.mjs').ListArg} LA
9
- * @extends {Signal<LA[]>}
8
+ * @template {import('../types/ListArg.mjs').ListArg} LISTARG
9
+ * @extends {Signal<LISTARG[]>}
10
10
  */
11
- export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> extends Signal<LA[]> {
11
+ export class ListSignal<LISTARG extends import("../types/ListArg.mjs").ListArg> extends Signal<LISTARG[]> {
12
12
  /**
13
13
  * @description
14
14
  * - Checks if the input is an array whose first item (if present) is a plain object
@@ -20,7 +20,7 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
20
20
  /**
21
21
  * @description
22
22
  * - usefull for `loops`;
23
- * @param {LA[]} [value]
23
+ * @param {LISTARG[]} [value]
24
24
  * @example
25
25
  * import { ListSignal } from 'vivth';
26
26
  *
@@ -29,7 +29,7 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
29
29
  * {key1: "test2",},
30
30
  * ]);
31
31
  */
32
- constructor(value?: LA[]);
32
+ constructor(value?: LISTARG[]);
33
33
  /**
34
34
  * @description
35
35
  * - methods collection that mimics `Array` API;
@@ -41,17 +41,17 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
41
41
  * @description
42
42
  * - reference to structuredClone elements of `value`;
43
43
  * - calling doesn't notify
44
- * @type {Array<LA>}
44
+ * @returns {Array<LISTARG>}
45
45
  */
46
- readonly structuredClone: Array<LA>;
46
+ readonly structuredClone: Array<LISTARG>;
47
47
  /**
48
48
  * @instance arrayMethods
49
49
  * @description
50
50
  * - appends new elements to the end;
51
- * @param {...LA} listArg
51
+ * @param {...LISTARG} listArg
52
52
  * @returns {void}
53
53
  */
54
- push: (...listArg: LA[]) => void;
54
+ push: (...listArg: LISTARG[]) => void;
55
55
  /**
56
56
  * @instance arrayMethods
57
57
  * @description
@@ -63,10 +63,10 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
63
63
  * @instance arrayMethods
64
64
  * @description
65
65
  * - inserts new element at the start;
66
- * @param {...LA} listArg
66
+ * @param {...LISTARG} listArg
67
67
  * @returns {void}
68
68
  */
69
- unshift: (...listArg: LA[]) => void;
69
+ unshift: (...listArg: LISTARG[]) => void;
70
70
  /**
71
71
  * @instance arrayMethods
72
72
  * @description
@@ -82,11 +82,11 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
82
82
  * @instance arrayMethods
83
83
  * @description
84
84
  * - replace whole `List` data with new array.
85
- * @param {LA[]} listArgs
85
+ * @param {LISTARG[]} listArgs
86
86
  * - new array in place of the deleted array.
87
87
  * @returns {void}
88
88
  */
89
- replace: (listArgs: LA[]) => void;
89
+ replace: (listArgs: LISTARG[]) => void;
90
90
  /**
91
91
  * @instance arrayMethods
92
92
  * @description
@@ -95,11 +95,11 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
95
95
  * - The zero-based location in the data from which to start removing elements.
96
96
  * @param {number} deleteCount
97
97
  * -The number of elements to remove.
98
- * @param {...LA} listArg
98
+ * @param {...LISTARG} listArg
99
99
  * - new data in place of the deleted data.
100
100
  * @returns {void}
101
101
  */
102
- splice: (start: number, deleteCount: number, ...listArg: LA[]) => void;
102
+ splice: (start: number, deleteCount: number, ...listArg: LISTARG[]) => void;
103
103
  /**
104
104
  * @instance arrayMethods
105
105
  * @description
@@ -114,10 +114,10 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
114
114
  * @description
115
115
  * - modify `List` element at specific index;
116
116
  * @param {number} index
117
- * @param {Partial<LA>} listArg
117
+ * @param {Partial<LISTARG>} listArg
118
118
  * @returns {void}
119
119
  */
120
- modify: (index: number, listArg: Partial<LA>) => void;
120
+ modify: (index: number, listArg: Partial<LISTARG>) => void;
121
121
  /**
122
122
  * @instance arrayMethods
123
123
  * @description
@@ -141,7 +141,112 @@ export class ListSignal<LA extends import("../types/ListArg.mjs").ListArg> exten
141
141
  */
142
142
  pop: () => void;
143
143
  } & {
144
- "vivth:unwrapLazy;": string;
144
+ "vivth:unwrapLazy;": () => {
145
+ /**
146
+ * @instance arrayMethods
147
+ * @description
148
+ * - reference to structuredClone elements of `value`;
149
+ * - calling doesn't notify
150
+ * @returns {Array<LISTARG>}
151
+ */
152
+ readonly structuredClone: Array<LISTARG>;
153
+ /**
154
+ * @instance arrayMethods
155
+ * @description
156
+ * - appends new elements to the end;
157
+ * @param {...LISTARG} listArg
158
+ * @returns {void}
159
+ */
160
+ push: (...listArg: LISTARG[]) => void;
161
+ /**
162
+ * @instance arrayMethods
163
+ * @description
164
+ * - removes the first element;
165
+ * @type {()=>void}
166
+ */
167
+ shift: () => void;
168
+ /**
169
+ * @instance arrayMethods
170
+ * @description
171
+ * - inserts new element at the start;
172
+ * @param {...LISTARG} listArg
173
+ * @returns {void}
174
+ */
175
+ unshift: (...listArg: LISTARG[]) => void;
176
+ /**
177
+ * @instance arrayMethods
178
+ * @description
179
+ * - for both start and end, a negative index can be used to indicate an offset from the end of the data. For example, -2 refers to the second to last element of the data;
180
+ * @param {number} [start]
181
+ * - the beginning index of the specified portion of the data. If start is undefined, then the slice begins at index 0.
182
+ * @param {number} [end]
183
+ * - the end index of the specified portion of the data. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the data.
184
+ * @returns {void}
185
+ */
186
+ slice: (start?: number, end?: number) => void;
187
+ /**
188
+ * @instance arrayMethods
189
+ * @description
190
+ * - replace whole `List` data with new array.
191
+ * @param {LISTARG[]} listArgs
192
+ * - new array in place of the deleted array.
193
+ * @returns {void}
194
+ */
195
+ replace: (listArgs: LISTARG[]) => void;
196
+ /**
197
+ * @instance arrayMethods
198
+ * @description
199
+ * - removes elements from an data and, if necessary, inserts new elements in their place;
200
+ * @param {number} start
201
+ * - The zero-based location in the data from which to start removing elements.
202
+ * @param {number} deleteCount
203
+ * -The number of elements to remove.
204
+ * @param {...LISTARG} listArg
205
+ * - new data in place of the deleted data.
206
+ * @returns {void}
207
+ */
208
+ splice: (start: number, deleteCount: number, ...listArg: LISTARG[]) => void;
209
+ /**
210
+ * @instance arrayMethods
211
+ * @description
212
+ * - swap `List` data between two indexes;
213
+ * @param {number} indexA
214
+ * @param {number} indexB
215
+ * @returns {void}
216
+ */
217
+ swap: (indexA: number, indexB: number) => void;
218
+ /**
219
+ * @instance arrayMethods
220
+ * @description
221
+ * - modify `List` element at specific index;
222
+ * @param {number} index
223
+ * @param {Partial<LISTARG>} listArg
224
+ * @returns {void}
225
+ */
226
+ modify: (index: number, listArg: Partial<LISTARG>) => void;
227
+ /**
228
+ * @instance arrayMethods
229
+ * @description
230
+ * - remove `List` element at specific index;
231
+ * @param {number} index
232
+ * @returns {void}
233
+ */
234
+ remove: (index: number) => void;
235
+ /**
236
+ * @instance arrayMethods
237
+ * @description
238
+ * - reverses the elements in an `List` in place.
239
+ * @returns {void}
240
+ */
241
+ reverse: () => void;
242
+ /**
243
+ * @instance arrayMethods
244
+ * @description
245
+ * - removes the last element;
246
+ * @returns {void}
247
+ */
248
+ pop: () => void;
249
+ };
145
250
  };
146
251
  #private;
147
252
  }