vivth 1.2.3 → 1.3.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.
Files changed (71) hide show
  1. package/README.md +608 -586
  2. package/README.src.md +5 -1
  3. package/bun.lock +6 -0
  4. package/index.mjs +10 -6
  5. package/package.json +3 -1
  6. package/src/bundler/CompileJS.mjs +11 -8
  7. package/src/bundler/EsBundler.mjs +4 -2
  8. package/src/bundler/FSInline.mjs +3 -0
  9. package/src/bundler/FSInlineAnalyzer.mjs +31 -7
  10. package/src/bundler/FSInlineBundled.mjs +5 -1
  11. package/src/bundler/adds/ToBundledJSPlugin.mjs +3 -4
  12. package/src/class/Console.mjs +12 -4
  13. package/src/class/Derived.mjs +5 -1
  14. package/src/class/Effect.mjs +6 -6
  15. package/src/class/EnvSignal.mjs +1 -8
  16. package/src/class/EventSignal.mjs +8 -7
  17. package/src/class/FileSafe.mjs +1 -1
  18. package/src/class/ListSignal.mjs +18 -10
  19. package/src/class/LitExp.mjs +241 -204
  20. package/src/class/Paths.mjs +10 -8
  21. package/src/class/QChannel.mjs +14 -7
  22. package/src/class/SafeExit.mjs +16 -7
  23. package/src/class/Signal.mjs +8 -7
  24. package/src/class/WorkerMainThread.mjs +45 -24
  25. package/src/class/WorkerMainThreadBundled.mjs +42 -24
  26. package/src/class/WorkerThread.mjs +21 -7
  27. package/src/common/Base64URL.mjs +2 -2
  28. package/src/common/Base64URLFromFile.mjs +1 -1
  29. package/src/doc/JSautoDOC.mjs +99 -62
  30. package/src/doc/correctBeforeParse.mjs +139 -0
  31. package/src/doc/parsedFile.mjs +127 -76
  32. package/src/function/CreateImmutable.mjs +12 -7
  33. package/src/function/GetRuntime.mjs +8 -3
  34. package/src/function/LazyFactory.mjs +10 -4
  35. package/src/function/Try.mjs +4 -1
  36. package/src/function/TryAsync.mjs +2 -1
  37. package/src/function/TrySync.mjs +3 -1
  38. package/src/function/TsToMjs.mjs +7 -4
  39. package/src/types/AnyButUndefined.mjs +1 -0
  40. package/src/types/LitExpResultType.mjs +7 -0
  41. package/src/types/Runtime.mjs +1 -1
  42. package/tsconfig.json +27 -5
  43. package/types/dev/workerThreadClass.d.mts +1 -1
  44. package/types/index.d.mts +7 -6
  45. package/types/src/bundler/CompileJS.d.mts +14 -9
  46. package/types/src/bundler/EsBundler.d.mts +1 -1
  47. package/types/src/class/Derived.d.mts +4 -64
  48. package/types/src/class/Effect.d.mts +8 -8
  49. package/types/src/class/EnvSignal.d.mts +0 -1
  50. package/types/src/class/EventSignal.d.mts +5 -5
  51. package/types/src/class/FileSafe.d.mts +2 -2
  52. package/types/src/class/ListSignal.d.mts +1 -1
  53. package/types/src/class/LitExp.d.mts +49 -53
  54. package/types/src/class/Paths.d.mts +4 -4
  55. package/types/src/class/QChannel.d.mts +1 -1
  56. package/types/src/class/SafeExit.d.mts +3 -3
  57. package/types/src/class/Signal.d.mts +3 -3
  58. package/types/src/class/WorkerMainThread.d.mts +13 -8
  59. package/types/src/class/WorkerMainThreadBundled.d.mts +13 -8
  60. package/types/src/class/WorkerThread.d.mts +4 -4
  61. package/types/src/common/Base64URL.d.mts +2 -2
  62. package/types/src/common/Base64URLFromFile.d.mts +2 -2
  63. package/types/src/doc/JSautoDOC.d.mts +33 -12
  64. package/types/src/doc/correctBeforeParse.d.mts +2 -0
  65. package/types/src/doc/parsedFile.d.mts +7 -10
  66. package/types/src/function/CreateImmutable.d.mts +2 -2
  67. package/types/src/function/Try.d.mts +2 -2
  68. package/types/src/function/TryAsync.d.mts +2 -2
  69. package/types/src/function/TrySync.d.mts +3 -2
  70. package/types/src/function/TsToMjs.d.mts +2 -2
  71. package/types/src/types/LitExpResultType.d.mts +7 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @type {Set<Signal>}
2
+ * @type {Set<Signal<any>>}
3
3
  */
4
4
  export const setOFSignals: Set<Signal<any>>;
5
5
  /**
@@ -149,9 +149,9 @@ export class Signal<VALUE> {
149
149
  /**
150
150
  * @description
151
151
  * - value before change;
152
- * @returns {VALUE}
152
+ * @returns {VALUE|undefined}
153
153
  */
154
- get prev(): VALUE;
154
+ get prev(): VALUE | undefined;
155
155
  /**
156
156
  * @description
157
157
  * - assign new value then automatically notify all subscribers;
@@ -3,16 +3,20 @@
3
3
  * @typedef {import('./WorkerResult.mjs').WorkerResult<POST>} WorkerResult
4
4
  */
5
5
  /**
6
- * @typedef {import('./WorkerThread.mjs').WorkerThread} WorkerThread
6
+ * @template RECEIVE
7
+ * @template POST
8
+ * @typedef {import('./WorkerThread.mjs').WorkerThread<RECEIVE, POST>} WorkerThread
9
+ */
10
+ /**
7
11
  * @typedef {import('../common/lazie.mjs').unwrapLazy} unwrapLazy
8
12
  */
9
13
  /**
10
14
  * @description
11
15
  * - class helper to create `Worker` instance;
12
16
  * - before any `Worker` functionaily to be used, you need to setup it with `WorkerThread.setup` and `WorkerMainThread.setup` before runing anytyhing;
13
- * @template {WorkerThread} WT
17
+ * @template {WorkerThread<any, any>} WT
14
18
  */
15
- export class WorkerMainThread<WT extends WorkerThread> {
19
+ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
16
20
  /**
17
21
  * @type {boolean}
18
22
  */
@@ -79,7 +83,7 @@ export class WorkerMainThread<WT extends WorkerThread> {
79
83
  type?: "module";
80
84
  };
81
85
  /**
82
- * @template {WorkerThread} WT
86
+ * @template {WorkerThread<any, any>} WT
83
87
  * @description
84
88
  * - create Worker_instance;
85
89
  * @param {string} handler
@@ -90,16 +94,17 @@ export class WorkerMainThread<WT extends WorkerThread> {
90
94
  *
91
95
  * export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
92
96
  */
93
- static newVivthWorker: (handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">) => WorkerMainThread<WT_1>;
97
+ static newVivthWorker<WT_1 extends WorkerThread<any, any>>(handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
94
98
  /**
99
+ * @template {WorkerThread<any, any>} WT
95
100
  * @param {string} handler
96
101
  * @param { WorkerOptions
97
102
  * | import('worker_threads').WorkerOptions} options
98
- * @param {WorkerMainThread} worker
103
+ * @param {WorkerMainThread<WT>} worker
99
104
  * @param {(any:any)=>void} listener
100
105
  * @returns {Promise<void>}
101
106
  */
102
- static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void) => Promise<void>;
107
+ static #workerFilehandler<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
103
108
  /**
104
109
  * @private
105
110
  * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
@@ -144,6 +149,6 @@ export class WorkerMainThread<WT extends WorkerThread> {
144
149
  #private;
145
150
  }
146
151
  export type WorkerResult<POST> = import("./WorkerResult.mjs").WorkerResult<POST>;
147
- export type WorkerThread = import("./WorkerThread.mjs").WorkerThread<any, any>;
152
+ export type WorkerThread<RECEIVE, POST> = import("./WorkerThread.mjs").WorkerThread<RECEIVE, POST>;
148
153
  export type unwrapLazy = "vivth:unwrapLazy;";
149
154
  import { Derived } from './Derived.mjs';
@@ -3,13 +3,17 @@
3
3
  * @typedef {import('./WorkerResult.mjs').WorkerResult<POST>} WorkerResult
4
4
  */
5
5
  /**
6
- * @typedef {import('./WorkerThread.mjs').WorkerThread} WorkerThread
6
+ * @template RECEIVE
7
+ * @template POST
8
+ * @typedef {import('./WorkerThread.mjs').WorkerThread<RECEIVE, POST>} WorkerThread
9
+ */
10
+ /**
7
11
  * @typedef {import('../common/lazie.mjs').unwrapLazy} unwrapLazy
8
12
  */
9
13
  /**
10
- * @template {WorkerThread} WT
14
+ * @template {WorkerThread<any, any>} WT
11
15
  */
12
- export class WorkerMainThread<WT extends WorkerThread> {
16
+ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
13
17
  /**
14
18
  * @type {boolean}
15
19
  */
@@ -38,21 +42,22 @@ export class WorkerMainThread<WT extends WorkerThread> {
38
42
  type?: "module";
39
43
  };
40
44
  /**
41
- * @template {WorkerThread} WT
45
+ * @template {WorkerThread<any, any>} WT
42
46
  * @param {string} handler
43
47
  * @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
44
48
  * @returns {WorkerMainThread<WT>}
45
49
  */
46
- static newVivthWorker: (handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">) => WorkerMainThread<WT_1>;
50
+ static newVivthWorker<WT_1 extends WorkerThread<any, any>>(handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
47
51
  /**
52
+ * @template {WorkerThread<any, any>} WT
48
53
  * @param {string} handler
49
54
  * @param { WorkerOptions
50
55
  * | import('worker_threads').WorkerOptions} options
51
- * @param {WorkerMainThread} worker
56
+ * @param {WorkerMainThread<WT>} worker
52
57
  * @param {(any:any)=>void} listener
53
58
  * @returns {Promise<void>}
54
59
  */
55
- static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void) => Promise<void>;
60
+ static #workerFilehandler<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
56
61
  /**
57
62
  * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
58
63
  * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
@@ -73,6 +78,6 @@ export class WorkerMainThread<WT extends WorkerThread> {
73
78
  #private;
74
79
  }
75
80
  export type WorkerResult<POST> = import("./WorkerResult.mjs").WorkerResult<POST>;
76
- export type WorkerThread = import("./WorkerThread.mjs").WorkerThread<any, any>;
81
+ export type WorkerThread<RECEIVE, POST> = import("./WorkerThread.mjs").WorkerThread<RECEIVE, POST>;
77
82
  export type unwrapLazy = "vivth:unwrapLazy;";
78
83
  import { Derived } from './Derived.mjs';
@@ -10,9 +10,9 @@ export class WorkerThread<RECEIVE, POST> {
10
10
  * @typedef {import('../types/QCBReturn.mjs').QCBReturn} QCBReturn
11
11
  */
12
12
  /**
13
- * @type {Parameters<typeof WorkerThread["setup"]>[0]}
13
+ * @type {Parameters<typeof WorkerThread["setup"]>[0]|undefined}
14
14
  */
15
- static #refs: Parameters<(typeof WorkerThread)["setup"]>[0];
15
+ static #refs: Parameters<(typeof WorkerThread)["setup"]>[0] | undefined;
16
16
  /**
17
17
  * @description
18
18
  * - need to be called and exported as new `WorkerThread` class reference;
@@ -40,7 +40,7 @@ export class WorkerThread<RECEIVE, POST> {
40
40
  /**
41
41
  * @description
42
42
  * - instantiate via created class from `setup` static method;
43
- * @param {WorkerThread["handler"]} handler
43
+ * @param {WorkerThread<RECEIVE, POST>["handler"]} handler
44
44
  * @example
45
45
  * import { MyWorkerThread } from './MyWorkerThread.mjs';
46
46
  *
@@ -55,7 +55,7 @@ export class WorkerThread<RECEIVE, POST> {
55
55
  * return ev = ev \* 2;
56
56
  * });
57
57
  */
58
- constructor(handler: (ev: any, isLastOnQ: () => boolean) => any);
58
+ constructor(handler: WorkerThread<RECEIVE, POST>["handler"]);
59
59
  /**
60
60
  * @description
61
61
  * - type helper;
@@ -12,11 +12,11 @@
12
12
  * (str, prevBufferEncoding) =>
13
13
  * Buffer.from(str, prevBufferEncoding).toString('base64')
14
14
  * ```
15
- * @returns {Base64URLString}
15
+ * @returns {string}
16
16
  * @example
17
17
  * import { Base64URL } from 'vivth'
18
18
  * import fileString from './fileString.mjs';
19
19
  *
20
20
  * Base64URL(fileString, 'application/javascript', btoa);
21
21
  */
22
- export function Base64URL(fileString: string, mimeType: string, btoaFunction: (string: string) => string): Base64URLString;
22
+ export function Base64URL(fileString: string, mimeType: string, btoaFunction: (string: string) => string): string;
@@ -5,7 +5,7 @@
5
5
  * >- can be extremely usefull to display file on desktop app webview, without exposing http server;
6
6
  * >- when using `FSInline`, use [Base64URL](#base64url) instead;
7
7
  * @param {string} filePath
8
- * @returns {Promise<Base64URLString>}
8
+ * @returns {Promise<string>}
9
9
  * @example
10
10
  * import { join } from 'node:path'
11
11
  *
@@ -13,4 +13,4 @@
13
13
  *
14
14
  * await Base64URLFromFile(join(Paths.root, '/path/to/file'));
15
15
  */
16
- export function Base64URLFromFile(filePath: string): Promise<Base64URLString>;
16
+ export function Base64URLFromFile(filePath: string): Promise<string>;
@@ -15,21 +15,24 @@
15
15
  * >>- first `"at"${string}` after `"at"description` until `"at"example` will be treated as `javascript` comment block on the `markdown`;
16
16
  * >>- `"at"example` are treated as `javascript` block on the `markdown` file, and should be placed last on the same comment block;
17
17
  * >>- you can always look at `vivth/src` files to check how the source, and the `README.md` and `index.mjs` documentation/generation results;
18
+ * >6) this types of arrow functions will be converted to regullar function, for concise type emition:
19
+ * >>- validly exported function;
20
+ * >>- static/instance method(s) with generic template;
18
21
  */
19
22
  export class JSautoDOC {
20
23
  /**
21
- * @type {JSautoDOC}
24
+ * @type {JSautoDOC|undefined}
22
25
  */
23
- static #instance: JSautoDOC;
26
+ static #instance: JSautoDOC | undefined;
24
27
  /**
25
28
  * @description
26
29
  * @param {Object} [options]
27
30
  * @param {Object} [options.paths]
28
- * @param {string} [options.paths.file]
31
+ * @param {string} options.paths.file
29
32
  * - entry point;
30
- * @param {string} [options.paths.readMe]
33
+ * @param {string} options.paths.readMe
31
34
  * - readme target;
32
- * @param {string} [options.paths.dir]
35
+ * @param {string} options.paths.dir
33
36
  * - source directory;
34
37
  * @param {string} [options.copyright]
35
38
  * @param {string} [options.tableOfContentTitle]
@@ -47,13 +50,31 @@ export class JSautoDOC {
47
50
  */
48
51
  constructor({ paths, tableOfContentTitle, copyright, option, }?: {
49
52
  paths?: {
50
- file?: string;
51
- readMe?: string;
52
- dir?: string;
53
- };
54
- copyright?: string;
55
- tableOfContentTitle?: string;
56
- option?: import("chokidar").ChokidarOptions;
53
+ file: string;
54
+ readMe: string;
55
+ dir: string;
56
+ } | undefined;
57
+ copyright?: string | undefined;
58
+ tableOfContentTitle?: string | undefined;
59
+ option?: Partial<{
60
+ persistent: boolean;
61
+ ignoreInitial: boolean;
62
+ followSymlinks: boolean;
63
+ cwd?: string;
64
+ usePolling: boolean;
65
+ interval: number;
66
+ binaryInterval: number;
67
+ alwaysStat?: boolean;
68
+ depth?: number;
69
+ ignorePermissionErrors: boolean;
70
+ atomic: boolean | number;
71
+ } & {
72
+ ignored: import("chokidar").Matcher | import("chokidar").Matcher[];
73
+ awaitWriteFinish: boolean | Partial<{
74
+ stabilityThreshold: number;
75
+ pollInterval: number;
76
+ }>;
77
+ }> | undefined;
57
78
  });
58
79
  #private;
59
80
  }
@@ -0,0 +1,2 @@
1
+ export function correctBeforeParse(path: string, encoding?: BufferEncoding): Promise<RetType>;
2
+ export type RetType = "shouldProceedNextCheck" | "waitForRewrite" | "doNotProcess";
@@ -22,15 +22,16 @@ export class parsedFile {
22
22
  */
23
23
  /**
24
24
  * @param {string} path__
25
+ * @param {import('fs').Stats} _stats
25
26
  * @param {BufferEncoding} [encoding]
26
27
  */
27
- constructor(path__: string, encoding?: BufferEncoding);
28
+ constructor(path__: string, _stats: import("fs").Stats, encoding?: BufferEncoding);
28
29
  parse: () => Promise<void>;
29
30
  documented: {
30
31
  typedef: () => Promise<{
31
32
  module: string;
32
33
  readme: string;
33
- }>;
34
+ } | undefined>;
34
35
  /**
35
36
  * @type {Set<refType>}
36
37
  */
@@ -54,7 +55,7 @@ export class parsedFile {
54
55
  typedef: () => Promise<{
55
56
  module: string;
56
57
  readme: string;
57
- }>;
58
+ } | undefined>;
58
59
  /**
59
60
  * @type {Set<refType>}
60
61
  */
@@ -153,11 +154,6 @@ export class parsedFile {
153
154
  */
154
155
  readonly noDot: string | undefined;
155
156
  };
156
- /**
157
- * @private
158
- * @returns {Promise<Stats>}
159
- */
160
- private stats;
161
157
  get timeStamp(): {
162
158
  /**
163
159
  * @returns {Promise<number>}
@@ -206,8 +202,9 @@ export class parsedFile {
206
202
  };
207
203
  };
208
204
  /**
209
- * @returns {[Promise<any>, undefined]|[undefined, Error]}
205
+ * @returns {ReturnType<typeof TryAsync<any>>}
210
206
  */
211
- get importAsModuleJS(): [Promise<any>, undefined] | [undefined, Error];
207
+ importAsModuleJS: () => ReturnType<typeof TryAsync<any>>;
212
208
  #private;
213
209
  }
210
+ import { TryAsync } from '../function/TryAsync.mjs';
@@ -23,6 +23,6 @@
23
23
  * getMap(name_) => mappedObject.get(name_),
24
24
  * })
25
25
  */
26
- export function CreateImmutable<PARENT extends unknown, OBJECT extends unknown>(parent: PARENT, keyName: string, object: (this: PARENT) => OBJECT, { lazy }?: {
27
- lazy?: boolean;
26
+ export function CreateImmutable<PARENT extends Object, OBJECT extends Object>(parent: PARENT, keyName: string, object: (this: PARENT) => OBJECT, { lazy }?: {
27
+ lazy?: boolean | undefined;
28
28
  }): OBJECT;
@@ -14,7 +14,7 @@
14
14
  * @param {RecordTryType} tryRecord
15
15
  * @returns {Promise<
16
16
  * [[keyof RecordTryType, RETURNTYPE], undefined]
17
- * | [[undefined, undefined], Error]
17
+ * | [[undefined, undefined], Error|undefined]
18
18
  * >}
19
19
  * @example
20
20
  * import { Try } from 'vivth';
@@ -49,4 +49,4 @@
49
49
  */
50
50
  export function Try<KEY extends string, RETURNTYPE, RecordTryType extends Record<KEY, (err: {
51
51
  prevError: undefined | Error;
52
- }) => Promise<RETURNTYPE>>>(tryRecord: RecordTryType): Promise<[[keyof RecordTryType, RETURNTYPE], undefined] | [[undefined, undefined], Error]>;
52
+ }) => Promise<RETURNTYPE>>>(tryRecord: RecordTryType): Promise<[[keyof RecordTryType, RETURNTYPE], undefined] | [[undefined, undefined], Error | undefined]>;
@@ -4,7 +4,7 @@
4
4
  * - usefull to flatten indentation for error handlings;
5
5
  * @template RESULT
6
6
  * @param {()=>Promise<RESULT>} asyncFunction_
7
- * @returns {Promise<[RESULT|undefined, Error|undefined]>}
7
+ * @returns {Promise<[RESULT,undefined]|[undefined,Error]>}
8
8
  * @example
9
9
  * import { TryAsync } from 'vivth';
10
10
  *
@@ -19,4 +19,4 @@
19
19
  * return await res.json();
20
20
  * })
21
21
  */
22
- export function TryAsync<RESULT>(asyncFunction_: () => Promise<RESULT>): Promise<[RESULT | undefined, Error | undefined]>;
22
+ export function TryAsync<RESULT>(asyncFunction_: () => Promise<RESULT>): Promise<[RESULT, undefined] | [undefined, Error]>;
@@ -4,7 +4,8 @@
4
4
  * - usefull to flatten indentation for error handlings;
5
5
  * @template RESULT
6
6
  * @param {()=>RESULT} function_
7
- * @returns {[RESULT|undefined, Error|undefined]}
7
+ * @returns {[RESULT,undefined]|
8
+ * [undefined,Error]}
8
9
  * @example
9
10
  * import { readFileSync } from 'fs';
10
11
  * import { TrySync } from './yourModule.js';
@@ -13,4 +14,4 @@
13
14
  * return readFileSync('./some/file.txt', 'utf-8');
14
15
  * });
15
16
  */
16
- export function TrySync<RESULT>(function_: () => RESULT): [RESULT | undefined, Error | undefined];
17
+ export function TrySync<RESULT>(function_: () => RESULT): [RESULT, undefined] | [undefined, Error];
@@ -18,6 +18,6 @@
18
18
  * TsToMjs('./myFile.mts', { encoding: 'utf-8', overrideDir: './other/dir' });
19
19
  */
20
20
  export function TsToMjs(path_: string, { overrideDir, encoding }?: {
21
- overrideDir?: string;
22
- encoding?: BufferEncoding;
21
+ overrideDir?: string | undefined;
22
+ encoding?: BufferEncoding | undefined;
23
23
  }): Promise<void>;
@@ -0,0 +1,7 @@
1
+ export type LitExpResultType<KEYS extends import("./LitExpKeyType.mjs").LitExpKeyType> = {
2
+ result: {
3
+ whole: string[];
4
+ named: Array<Record<keyof KEYS, string>>;
5
+ };
6
+ regexp: RegExp;
7
+ };