vivth 1.1.2 → 1.2.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 (108) hide show
  1. package/.vivth-temp/README.src.md +35 -0
  2. package/README.md +1215 -433
  3. package/README.src.md +5 -2
  4. package/bun.lock +228 -0
  5. package/index.mjs +17 -4
  6. package/package.json +6 -3
  7. package/src/bundler/CompileJS.mjs +258 -0
  8. package/src/bundler/CreateESPlugin.mjs +24 -0
  9. package/src/bundler/EsBundler.mjs +27 -13
  10. package/src/bundler/FSInline.mjs +57 -0
  11. package/src/bundler/FSInlineAnalyzer.mjs +197 -0
  12. package/src/bundler/FSInlineBundled.mjs +34 -0
  13. package/src/bundler/adds/ToBundledJSPlugin.mjs +77 -0
  14. package/src/bundler/adds/externals.mjs +8 -0
  15. package/src/bundler/adds/pluginVivthBundle.mjs +5 -0
  16. package/src/class/Console.mjs +48 -27
  17. package/src/class/Derived.mjs +55 -7
  18. package/src/class/Effect.mjs +100 -39
  19. package/src/class/EnvSignal.mjs +5 -5
  20. package/src/class/EventSignal.mjs +55 -5
  21. package/src/class/FileSafe.mjs +124 -0
  22. package/src/class/ListDerived.mjs +6 -3
  23. package/src/class/ListSignal.mjs +11 -11
  24. package/src/class/LitExp.mjs +405 -0
  25. package/src/class/Paths.mjs +27 -1
  26. package/src/class/QChannel.mjs +79 -28
  27. package/src/class/SafeExit.mjs +31 -11
  28. package/src/class/Setup.mjs +5 -2
  29. package/src/class/Signal.mjs +26 -24
  30. package/src/class/WorkerMainThread.mjs +100 -133
  31. package/src/class/WorkerMainThreadBundled.mjs +216 -0
  32. package/src/class/WorkerThread.mjs +38 -32
  33. package/src/common/Base64URL.mjs +10 -5
  34. package/src/common/Base64URLFromFile.mjs +24 -0
  35. package/src/common/keys.mjs +3 -0
  36. package/src/doc/JSautoDOC.mjs +32 -56
  37. package/src/doc/parsedFile.mjs +37 -36
  38. package/src/function/CreateImmutable.mjs +9 -9
  39. package/src/function/EventCheck.mjs +2 -2
  40. package/src/function/EventObject.mjs +5 -5
  41. package/src/function/GetRuntime.mjs +38 -0
  42. package/src/function/IsAsync.mjs +2 -2
  43. package/src/function/LazyFactory.mjs +13 -13
  44. package/src/function/Timeout.mjs +2 -2
  45. package/src/function/Try.mjs +17 -12
  46. package/src/function/TryAsync.mjs +5 -5
  47. package/src/function/TrySync.mjs +5 -5
  48. package/src/function/TsToMjs.mjs +5 -4
  49. package/src/types/LitExpKeyType.mjs +5 -0
  50. package/src/types/QCBReturn.mjs +1 -1
  51. package/src/types/Runtime.mjs +7 -0
  52. package/types/dev/fsInline.d.mts +1 -0
  53. package/types/dev/test.d.mts +1 -0
  54. package/types/dev/testWorker.d.mts +7 -0
  55. package/types/dev/testbundle.d.mts +1 -0
  56. package/types/dev/workerThreadClass.d.mts +13 -0
  57. package/types/index.d.mts +13 -4
  58. package/types/src/bundler/CompileJS.d.mts +78 -0
  59. package/types/src/bundler/CreateESPlugin.d.mts +17 -0
  60. package/types/src/bundler/EsBundler.d.mts +33 -4
  61. package/types/src/bundler/FSInline.d.mts +43 -0
  62. package/types/src/bundler/FSInlineAnalyzer.d.mts +36 -0
  63. package/types/src/bundler/FSInlineBundled.d.mts +22 -0
  64. package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +16 -0
  65. package/types/src/bundler/adds/externals.d.mts +1 -0
  66. package/types/src/bundler/adds/pluginVivthBundle.d.mts +1 -0
  67. package/types/src/class/Console.d.mts +36 -5
  68. package/types/src/class/Derived.d.mts +132 -5
  69. package/types/src/class/Effect.d.mts +106 -7
  70. package/types/src/class/EnvSignal.d.mts +8 -8
  71. package/types/src/class/EventSignal.d.mts +151 -7
  72. package/types/src/class/FileSafe.d.mts +90 -0
  73. package/types/src/class/ListDerived.d.mts +8 -5
  74. package/types/src/class/ListSignal.d.mts +123 -18
  75. package/types/src/class/LitExp.d.mts +361 -0
  76. package/types/src/class/Paths.d.mts +18 -1
  77. package/types/src/class/QChannel.d.mts +69 -22
  78. package/types/src/class/SafeExit.d.mts +24 -9
  79. package/types/src/class/Setup.d.mts +6 -5
  80. package/types/src/class/Signal.d.mts +73 -17
  81. package/types/src/class/WorkerMainThread.d.mts +39 -37
  82. package/types/src/class/WorkerMainThreadBundled.d.mts +85 -0
  83. package/types/src/class/WorkerThread.d.mts +32 -27
  84. package/types/src/common/Base64URL.d.mts +22 -1
  85. package/types/src/common/Base64URLFromFile.d.mts +16 -0
  86. package/types/src/common/keys.d.mts +1 -0
  87. package/types/src/doc/JSautoDOC.d.mts +3 -19
  88. package/types/src/doc/parsedFile.d.mts +72 -13
  89. package/types/src/function/CreateImmutable.d.mts +27 -2
  90. package/types/src/function/EventCheck.d.mts +15 -0
  91. package/types/src/function/EventObject.d.mts +17 -2
  92. package/types/src/function/GetRuntime.d.mts +2 -0
  93. package/types/src/function/IsAsync.d.mts +18 -0
  94. package/types/src/function/LazyFactory.d.mts +35 -2
  95. package/types/src/function/Timeout.d.mts +16 -0
  96. package/types/src/function/Try.d.mts +52 -1
  97. package/types/src/function/TryAsync.d.mts +22 -1
  98. package/types/src/function/TrySync.d.mts +16 -1
  99. package/types/src/function/TsToMjs.d.mts +19 -0
  100. package/types/src/types/LitExpKeyType.d.mts +1 -0
  101. package/types/src/types/QCBReturn.d.mts +1 -1
  102. package/types/src/types/Runtime.d.mts +1 -0
  103. package/dev/index.mjs +0 -28
  104. package/src/bundler/CompileMJS.mjs +0 -110
  105. package/src/function/WriteFileSafe.mjs +0 -37
  106. package/types/src/bundler/A.d.mts +0 -1
  107. package/types/src/bundler/CompileMJS.d.mts +0 -8
  108. package/types/src/function/WriteFileSafe.d.mts +0 -2
@@ -5,22 +5,23 @@ export const setOFSignals: Set<Signal<any>>;
5
5
  /**
6
6
  * @description
7
7
  * - a class for creating effect to signals;
8
- * @template Value
8
+ * @template VALUE
9
9
  */
10
- export class Signal<Value> {
10
+ export class Signal<VALUE> {
11
11
  /**
12
12
  * @param {Set<Effect>} setOfSubscribers
13
13
  */
14
14
  static #notify: (setOfSubscribers: Set<Effect>) => void;
15
15
  /**
16
16
  * @description
17
- * @param {Value} value
17
+ * - create a `Signal`;
18
+ * @param {VALUE} value
18
19
  * @example
19
20
  * import { Signal, Effect } from 'vivth';
20
21
  *
21
22
  * const count = new Signal(0);
22
23
  */
23
- constructor(value: Value);
24
+ constructor(value: VALUE);
24
25
  /**
25
26
  * @description
26
27
  * - subsrcibers reference of this instance;
@@ -37,17 +38,17 @@ export class Signal<Value> {
37
38
  * @instance subscribers
38
39
  * @description
39
40
  * - manually notify on non primitive value or value that have depths;
40
- * @param {(options:{signalInstance:Signal<Value>})=>Promise<void>} [callback]
41
+ * @param {(options:{signalInstance:Signal<VALUE>})=>Promise<void>} [callback]
41
42
  * @returns {void}
42
43
  * @example
43
- * // for deep signal like array or object you can:
44
+ * import { Signal } from 'vivth';
44
45
  *
46
+ * // for deep signal like array or object you can:
45
47
  * const arraySignal = new Signal([1,2]);
46
48
  * arraySignal.value.push(3);
47
49
  * arraySignal.subscribers.notify();
48
50
  *
49
51
  * // OR for more complex mutation:
50
- *
51
52
  * const objectSignal = new Signal({a:'test', b:'test'});
52
53
  * objectSignal.subscribers.notify(async ({ signalInstance }) => {
53
54
  * signalInstance.value['c'] = 'testc';
@@ -55,10 +56,42 @@ export class Signal<Value> {
55
56
  * });
56
57
  */
57
58
  notify: (callback?: (options: {
58
- signalInstance: Signal<Value>;
59
+ signalInstance: Signal<VALUE>;
59
60
  }) => Promise<void>) => void;
60
61
  } & {
61
- "vivth:unwrapLazy;": string;
62
+ "vivth:unwrapLazy;": () => {
63
+ /**
64
+ * @instance subscribers
65
+ * @description
66
+ * - subscribedEffects
67
+ * @type {Set<Effect>}
68
+ */
69
+ setOf: Set<Effect>;
70
+ /**
71
+ * @instance subscribers
72
+ * @description
73
+ * - manually notify on non primitive value or value that have depths;
74
+ * @param {(options:{signalInstance:Signal<VALUE>})=>Promise<void>} [callback]
75
+ * @returns {void}
76
+ * @example
77
+ * import { Signal } from 'vivth';
78
+ *
79
+ * // for deep signal like array or object you can:
80
+ * const arraySignal = new Signal([1,2]);
81
+ * arraySignal.value.push(3);
82
+ * arraySignal.subscribers.notify();
83
+ *
84
+ * // OR for more complex mutation:
85
+ * const objectSignal = new Signal({a:'test', b:'test'});
86
+ * objectSignal.subscribers.notify(async ({ signalInstance }) => {
87
+ * signalInstance.value['c'] = 'testc';
88
+ * signalInstance.value['d'] = 'testd';
89
+ * });
90
+ */
91
+ notify: (callback?: (options: {
92
+ signalInstance: Signal<VALUE>;
93
+ }) => Promise<void>) => void;
94
+ };
62
95
  };
63
96
  /**
64
97
  * @description
@@ -88,18 +121,41 @@ export class Signal<Value> {
88
121
  */
89
122
  ref: () => void;
90
123
  } & {
91
- "vivth:unwrapLazy;": string;
124
+ "vivth:unwrapLazy;": () => {
125
+ /**
126
+ * @instance remove
127
+ * @description
128
+ * - remove effect subscriber to react from this instance value changes;
129
+ * @param {Effect} effectInstance
130
+ * @returns {void}
131
+ */
132
+ subscriber: (effectInstance: Effect) => void;
133
+ /**
134
+ * @instance remove
135
+ * @description
136
+ * - remove all effect subscribers to react from this instance value changes;
137
+ * @type {()=>void}
138
+ */
139
+ allSubscribers: () => void;
140
+ /**
141
+ * @instance remove
142
+ * @description
143
+ * - remove this instance from `vivth` reactivity engine, and nullify it's own value;
144
+ * @type {()=>void}
145
+ */
146
+ ref: () => void;
147
+ };
92
148
  };
93
149
  /**
94
150
  * @description
95
151
  * - value before change;
96
- * @type {Value}
152
+ * @returns {VALUE}
97
153
  */
98
- get prev(): Value;
154
+ get prev(): VALUE;
99
155
  /**
100
156
  * @description
101
157
  * - assign new value then automatically notify all subscribers;
102
- * @type {Value}
158
+ * @type {VALUE}
103
159
  * @example
104
160
  * import { Signal } from 'vivth';
105
161
  *
@@ -108,11 +164,11 @@ export class Signal<Value> {
108
164
  * // OR
109
165
  * count.value = 9;
110
166
  */
111
- set value(newValue: Value);
167
+ set value(newValue: VALUE);
112
168
  /**
113
169
  * @description
114
170
  * - value after change;
115
- * @type {Value}
171
+ * @returns {VALUE}
116
172
  * @example
117
173
  * import { Signal, Effect, Derived } from 'vivth';
118
174
  *
@@ -122,11 +178,11 @@ export class Signal<Value> {
122
178
  * new Effect(async ({ subscribe }) =>{
123
179
  * const countValue = subscribe(count).value; // reactive
124
180
  * })
125
- * const oneMoreThanCount = new Effect(async ({ subscribe }) =>{
181
+ * const oneMoreThanCount = new Derived(async ({ subscribe }) =>{
126
182
  * return subscribe(count).value + 1; // reactive
127
183
  * })
128
184
  */
129
- get value(): Value;
185
+ get value(): VALUE;
130
186
  #private;
131
187
  }
132
188
  import { Effect } from './Effect.mjs';
@@ -1,16 +1,21 @@
1
1
  /**
2
- * @template A
3
- * @typedef {import('./WorkerResult.mjs').WorkerResult<A>} WorkerResult
2
+ * @template POST
3
+ * @typedef {import('./WorkerResult.mjs').WorkerResult<POST>} WorkerResult
4
4
  */
5
5
  /**
6
6
  * @typedef {import('./WorkerThread.mjs').WorkerThread} WorkerThread
7
+ * @typedef {import('../common/lazie.mjs').unwrapLazy} unwrapLazy
7
8
  */
8
9
  /**
9
10
  * @description
10
11
  * - class helper to create `Worker` instance;
12
+ * - before any `Worker` functionaily to be used, you need to setup it with `WorkerThread.setup` and `WorkerMainThread.setup` before runing anytyhing;
11
13
  * @template {WorkerThread} WT
12
14
  */
13
15
  export class WorkerMainThread<WT extends WorkerThread> {
16
+ /**
17
+ * @type {boolean}
18
+ */
14
19
  static #isRegistered: boolean;
15
20
  /**
16
21
  * @description
@@ -19,13 +24,14 @@ export class WorkerMainThread<WT extends WorkerThread> {
19
24
  * @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
20
25
  * - example:
21
26
  * ```js
22
- * async () => await (import('worker_threads')).Worker
27
+ * import { Worker } from 'node:worker_threads';
23
28
  * ```
24
29
  * @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
25
30
  * - example:
26
31
  * ```js
27
32
  * async (workerPath, root, base) => {
28
- * const res = await fetch(`${root}/${base}/${workerPath}`);
33
+ * const truePathCheck = `${root}/${base}/${workerPath}`;
34
+ * const res = await fetch(truePathCheck);
29
35
  * // might also check wheter it need base or not
30
36
  * return await res.ok;
31
37
  * }
@@ -34,10 +40,11 @@ export class WorkerMainThread<WT extends WorkerThread> {
34
40
  * - additonal realtivePath from rootPath;
35
41
  * - default: '';
36
42
  * @example
43
+ * import { Worker } from 'node:worker_threads';
37
44
  * import { WorkerMainThread } from 'vivth';
38
45
  *
39
46
  * WorkerMainThread.setup({
40
- * workerClass: async () => await (import('worker_threads')).Worker,
47
+ * workerClass: Worker,
41
48
  * basePath: 'public/assets/js/workers',
42
49
  * pathValidator: async (workerPath, root, base) => {
43
50
  * const res = await fetch(`${root}/${base}/${workerPath}`);
@@ -55,9 +62,9 @@ export class WorkerMainThread<WT extends WorkerThread> {
55
62
  * @description
56
63
  * - reference for `Worker` class;
57
64
  * - edit via `setup`;
58
- * @type {()=>Promise<typeof Worker|typeof import('worker_threads').Worker>}
65
+ * @type {typeof Worker|typeof import('worker_threads').Worker}
59
66
  */
60
- static workerClass: () => Promise<typeof Worker | typeof import("worker_threads").Worker>;
67
+ static workerClass: typeof Worker | typeof import("worker_threads").Worker;
61
68
  /**
62
69
  * @description
63
70
  * - reference for worker file `basePath`;
@@ -79,44 +86,38 @@ export class WorkerMainThread<WT extends WorkerThread> {
79
86
  static #options: import("worker_threads").WorkerOptions & {
80
87
  type?: "module";
81
88
  };
89
+ /**
90
+ * @template {WorkerThread} WT
91
+ * @description
92
+ * - create Worker_instance;
93
+ * @param {string} handler
94
+ * @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
95
+ * @returns {WorkerMainThread<WT>}
96
+ * @example
97
+ * import { WorkerMainThread } from 'vivth';
98
+ *
99
+ * export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
100
+ */
101
+ static newVivthWorker: (handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">) => WorkerMainThread<WT_1>;
82
102
  /**
83
103
  * @param {string} handler
84
104
  * @param { WorkerOptions
85
105
  * | import('worker_threads').WorkerOptions} options
86
106
  * @param {WorkerMainThread} worker
87
107
  * @param {(any:any)=>void} listener
88
- * @param {boolean} isInline
89
108
  * @returns {Promise<void>}
90
109
  */
91
- static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void, isInline: boolean) => Promise<void>;
110
+ static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void) => Promise<void>;
92
111
  /**
93
- * @type {boolean}
94
- */
95
- static #isBrowser: boolean;
96
- /**
97
- * @description
98
- * - check whether js run in browser
99
- * @type {boolean}
100
- */
101
- static get isBrowser(): boolean;
102
- /**
103
- * @description
104
- * - create Worker_instance;
105
- * @param {string} handler
106
- * - if `isInline` === `false`, `handler` should be:
107
- * >- pointing to worker thread file; WHICH
108
- * >- the path must be relative to `projectRoot`;
109
- * - if `isInline` === `true`, `handler` should be
110
- * >- string literal of prebundled worker thread script; OR
111
- * >- manually made string literal of worker thread script;
112
- * @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
113
- * @param {boolean} [isInline]
112
+ * @private
113
+ * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
114
+ * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
114
115
  * @example
115
116
  * import { WorkerMainThread } from 'vivth';
116
117
  *
117
- * export const myDoubleWorker = new WorkerMainThread('./doubleWorkerThread.mjs');
118
+ * export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
118
119
  */
119
- constructor(handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">, isInline?: boolean);
120
+ private constructor();
120
121
  /**
121
122
  * @description
122
123
  * - terminate all signals that are used on this instance;
@@ -126,7 +127,7 @@ export class WorkerMainThread<WT extends WorkerThread> {
126
127
  /**
127
128
  * @description
128
129
  * - result signal of the processed message;
129
- * @type {Derived<WorkerResult<WT["Post"]>>}
130
+ * @type {Derived<WorkerResult<WT["POST"]>>}
130
131
  * @example
131
132
  * import { Effect } from 'vivth';
132
133
  * import { myDoubleWorker } from './myDoubleWorker.mjs';
@@ -137,19 +138,20 @@ export class WorkerMainThread<WT extends WorkerThread> {
137
138
  * // code
138
139
  * })
139
140
  */
140
- receiverSignal: Derived<WorkerResult<WT["Post"]>>;
141
+ receiverSignal: Derived<WorkerResult<WT["POST"]>>;
141
142
  /**
142
143
  * @description
143
144
  * - callback to send message to the worker thread;
144
- * @type {(event: WT["Receive"])=>void}
145
+ * @type {(event: WT["RECEIVE"])=>void}
145
146
  * @example
146
147
  * import { myDoubleWorker } from './myDoubleWorker.mjs';
147
148
  *
148
149
  * myDoubleWorker.postMessage(90);
149
150
  */
150
- postMessage: (event: WT["Receive"]) => void;
151
+ postMessage: (event: WT["RECEIVE"]) => void;
151
152
  #private;
152
153
  }
153
- export type WorkerResult<A> = import("./WorkerResult.mjs").WorkerResult<A>;
154
+ export type WorkerResult<POST> = import("./WorkerResult.mjs").WorkerResult<POST>;
154
155
  export type WorkerThread = import("./WorkerThread.mjs").WorkerThread<any, any>;
156
+ export type unwrapLazy = "vivth:unwrapLazy;";
155
157
  import { Derived } from './Derived.mjs';
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @template POST
3
+ * @typedef {import('./WorkerResult.mjs').WorkerResult<POST>} WorkerResult
4
+ */
5
+ /**
6
+ * @typedef {import('./WorkerThread.mjs').WorkerThread} WorkerThread
7
+ * @typedef {import('../common/lazie.mjs').unwrapLazy} unwrapLazy
8
+ */
9
+ /**
10
+ * @template {WorkerThread} WT
11
+ */
12
+ export class WorkerMainThread<WT extends WorkerThread> {
13
+ /**
14
+ * @type {boolean}
15
+ */
16
+ static #isRegistered: boolean;
17
+ /**
18
+ * @param {Object} param0
19
+ * @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
20
+ * @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
21
+ * @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
22
+ */
23
+ static setup: ({ workerClass, pathValidator, basePath }: {
24
+ workerClass: (typeof WorkerMainThread)["workerClass"];
25
+ pathValidator: (typeof WorkerMainThread)["pathValidator"];
26
+ basePath?: (typeof WorkerMainThread)["basePath"];
27
+ }) => void;
28
+ /**
29
+ * @type {typeof Worker|typeof import('worker_threads').Worker}
30
+ */
31
+ static workerClass: typeof Worker | typeof import("worker_threads").Worker;
32
+ /**
33
+ * @type {string}
34
+ */
35
+ static basePath: string;
36
+ /**
37
+ * @type {(paths:{worker: string, root:string, base: string})=>Promise<string>}
38
+ */
39
+ static pathValidator: (paths: {
40
+ worker: string;
41
+ root: string;
42
+ base: string;
43
+ }) => Promise<string>;
44
+ static #options: import("worker_threads").WorkerOptions & {
45
+ type?: "module";
46
+ };
47
+ /**
48
+ * @template {WorkerThread} WT
49
+ * @param {string} handler
50
+ * @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
51
+ * @returns {WorkerMainThread<WT>}
52
+ */
53
+ static newVivthWorker: (handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">) => WorkerMainThread<WT_1>;
54
+ /**
55
+ * @param {string} handler
56
+ * @param { WorkerOptions
57
+ * | import('worker_threads').WorkerOptions} options
58
+ * @param {WorkerMainThread} worker
59
+ * @param {(any:any)=>void} listener
60
+ * @returns {Promise<void>}
61
+ */
62
+ static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void) => Promise<void>;
63
+ /**
64
+ * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
65
+ * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
66
+ */
67
+ constructor(handler: Parameters<(typeof WorkerMainThread<WT>)["newVivthWorker"]>[0], options?: Parameters<(typeof WorkerMainThread<WT>)["newVivthWorker"]>[1]);
68
+ /**
69
+ * @type {()=>void}
70
+ */
71
+ terminate: () => void;
72
+ /**
73
+ * @type {Derived<WorkerResult<WT["POST"]>>}
74
+ */
75
+ receiverSignal: Derived<WorkerResult<WT["POST"]>>;
76
+ /**
77
+ * @type {(event: WT["RECEIVE"])=>void}
78
+ */
79
+ postMessage: (event: WT["RECEIVE"]) => void;
80
+ #private;
81
+ }
82
+ export type WorkerResult<POST> = import("./WorkerResult.mjs").WorkerResult<POST>;
83
+ export type WorkerThread = import("./WorkerThread.mjs").WorkerThread<any, any>;
84
+ export type unwrapLazy = "vivth:unwrapLazy;";
85
+ import { Derived } from './Derived.mjs';
@@ -1,37 +1,38 @@
1
1
  /**
2
2
  * @description
3
3
  * - class helper for `WorkerThread` creation;
4
- * @template Receive
5
- * @template Post
4
+ * - before any `Worker` functionaily to be used, you need to setup it with `WorkerThread.setup` and `WorkerMainThread.setup` before runing anytyhing;
5
+ * @template RECEIVE
6
+ * @template POST
6
7
  */
7
- export class WorkerThread<Receive, Post> {
8
+ export class WorkerThread<RECEIVE, POST> {
8
9
  /**
9
- * @type {{parentPort:()=>Promise<any>}}
10
+ * @typedef {import('../types/QCBReturn.mjs').QCBReturn} QCBReturn
10
11
  */
11
- static #parentPortRef: {
12
- parentPort: () => Promise<any>;
13
- };
12
+ /**
13
+ * @type {Parameters<typeof WorkerThread["setup"]>[0]}
14
+ */
15
+ static #refs: Parameters<(typeof WorkerThread)["setup"]>[0];
14
16
  /**
15
17
  * @description
16
18
  * - need to be called and exported as new `WorkerThread` class reference;
17
- * @template Receive_
18
- * @template Post_
19
- * @param {{parentPort:()=>Promise<any>}} parentPortRef
20
- * - correct parentPort reference, example:
19
+ * @template RECEIVE
20
+ * @template POST
21
+ * @param {{parentPort:import('worker_threads')["parentPort"]}} refs
22
+ * -example:
21
23
  * ```js
22
- * async () => (await import('node:worker_threads')).parentPort
24
+ * import { parentPort } from 'node:worker_threads';
23
25
  * ```
24
- * @returns {typeof WorkerThread<Receive_, Post_>}
26
+ * @returns {typeof WorkerThread<RECEIVE, POST>}
25
27
  * @example
26
28
  * import { WorkerThread } from 'vivth';
29
+ * import { parentPort } from 'node:worker_threads';
27
30
  *
28
- * WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
29
- * // that is the default value, if your parentPort/equivalent API is not that;
30
- * // you need to call this method;
31
+ * export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
31
32
  */
32
- static setup: (parentPortRef: {
33
- parentPort: () => Promise<any>;
34
- }) => typeof WorkerThread<Receive_, Post_>;
33
+ static setup<RECEIVE_1, POST_1>(refs: {
34
+ parentPort: typeof import("worker_threads")["parentPort"];
35
+ }): typeof WorkerThread<RECEIVE_1, POST_1>;
35
36
  /**
36
37
  * @param {any} ev
37
38
  */
@@ -44,30 +45,34 @@ export class WorkerThread<Receive, Post> {
44
45
  * import { MyWorkerThread } from './MyWorkerThread.mjs';
45
46
  *
46
47
  * const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
47
- * // if(!isLastOnQ) {
48
+ * // if(!isLastOnQ()) {
48
49
  * // return null; // can be used for imperative debouncing;
49
50
  * // }
51
+ * // await fetch('some/path')
52
+ * // if(!isLastOnQ()) {
53
+ * // return;
54
+ * // }
50
55
  * return ev = ev \* 2;
51
56
  * });
52
57
  */
53
- constructor(handler: (ev: any, isLastOnQ: boolean) => any);
58
+ constructor(handler: (ev: any, isLastOnQ: () => boolean) => any);
54
59
  /**
55
60
  * @description
56
61
  * - type helper;
57
- * @type {(ev: Receive, isLastOnQ:boolean) => Post}
62
+ * @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
58
63
  */
59
- handler: (ev: Receive, isLastOnQ: boolean) => Post;
64
+ handler: (ev: RECEIVE, isLastOnQ: () => boolean) => POST;
60
65
  /**
61
66
  * @description
62
67
  * - helper type, hold no actual value;
63
- * @type {Receive}
68
+ * @type {RECEIVE}
64
69
  */
65
- Receive: Receive;
70
+ RECEIVE: RECEIVE;
66
71
  /**
67
72
  * @description
68
73
  * - helper type, hold no actual value;
69
- * @type {Post}
74
+ * @type {POST}
70
75
  */
71
- Post: Post;
76
+ POST: POST;
72
77
  #private;
73
78
  }
@@ -1 +1,22 @@
1
- export function Base64URL(fileString: string, mimeType: string, btoaFunction: (string: string) => string): string;
1
+ /**
2
+ * @description
3
+ * - create inline base64 url;
4
+ * - usage:
5
+ * >- can be extremely usefull to display file on desktop app webview, without exposing http server;
6
+ * @param {string} fileString
7
+ * @param {string} mimeType
8
+ * @param {(string:string)=>string} btoaFunction
9
+ * - check your js runtime `btoa`;
10
+ * - node compatible:
11
+ * ```js
12
+ * (str, prevBufferEncoding) =>
13
+ * Buffer.from(str, prevBufferEncoding).toString('base64')
14
+ * ```
15
+ * @returns {Base64URLString}
16
+ * @example
17
+ * import { Base64URL } from 'vivth'
18
+ * import fileString from './fileString.mjs';
19
+ *
20
+ * Base64URL(fileString, 'application/javascript', btoa);
21
+ */
22
+ export function Base64URL(fileString: string, mimeType: string, btoaFunction: (string: string) => string): Base64URLString;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description
3
+ * - create inline base64 url;
4
+ * - usage:
5
+ * >- can be extremely usefull to display file on desktop app webview, without exposing http server;
6
+ * >- when using `FSInline`, use [Base64URL](#base64url) instead;
7
+ * @param {string} filePath
8
+ * @returns {Promise<Base64URLString>}
9
+ * @example
10
+ * import { join } from 'node:path'
11
+ *
12
+ * import { Base64URLFromFile, Paths } from 'vivth'
13
+ *
14
+ * await Base64URLFromFile(join(Paths.root, '/path/to/file'));
15
+ */
16
+ export function Base64URLFromFile(filePath: string): Promise<Base64URLString>;
@@ -0,0 +1 @@
1
+ export const keys_vivthGenereteDir: ".vivth";
@@ -14,7 +14,7 @@
14
14
  * >>- `"at"description` are treated as plain `markdown`;
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
- * >>- you can always look at `vivth/src` files to check how the source, and the `README.md` and `index.mjs` is documentation/generation results;
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
18
  */
19
19
  export class JSautoDOC {
20
20
  /**
@@ -36,25 +36,9 @@ export class JSautoDOC {
36
36
  * @param {import('chokidar').ChokidarOptions} [options.option]
37
37
  * - ChokidarOptions;
38
38
  * @example
39
- * import { Console, Setup, JSautoDOC } from 'vivth';
39
+ * import { JSautoDOC } from 'vivth';
40
40
  *
41
- * const { paths, safeExit } = Setup;
42
- *
43
- * new paths({
44
- * root: process?.env?.INIT_CWD ?? process?.cwd(),
45
- * });
46
- *
47
- * new safeExit({
48
- * exitEventNames: ['SIGINT', 'SIGTERM', 'exit'],
49
- * exitCallbackListeners: (eventName) => {
50
- * process.once(eventName, function () {
51
- * safeExit.instance.exiting.correction(true);
52
- * Console.log(`safe exit via "${eventName}"`);
53
- * });
54
- * },
55
- * });
56
- *
57
- * new JSautoDOC({
41
+ * new JSautoDOC({
58
42
  * paths: { dir: 'src', file: 'index.mjs', readMe: 'README.md' },
59
43
  * copyright: 'this library is made and distributed under MIT license;',
60
44
  * tableOfContentTitle: 'list of exported API and typehelpers',