vivth 1.1.1 → 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.
- package/.vivth-temp/README.src.md +35 -0
- package/README.md +1243 -441
- package/README.src.md +5 -2
- package/bun.lock +228 -0
- package/index.mjs +22 -9
- package/package.json +6 -3
- package/src/bundler/CompileJS.mjs +258 -0
- package/src/bundler/CreateESPlugin.mjs +24 -0
- package/src/bundler/EsBundler.mjs +27 -13
- package/src/bundler/FSInline.mjs +57 -0
- package/src/bundler/FSInlineAnalyzer.mjs +197 -0
- package/src/bundler/FSInlineBundled.mjs +34 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +77 -0
- package/src/bundler/adds/externals.mjs +8 -0
- package/src/bundler/adds/pluginVivthBundle.mjs +5 -0
- package/src/class/Console.mjs +48 -27
- package/src/class/Derived.mjs +55 -7
- package/src/class/Effect.mjs +100 -39
- package/src/class/EnvSignal.mjs +5 -5
- package/src/class/EventSignal.mjs +55 -5
- package/src/class/FileSafe.mjs +124 -0
- package/src/class/ListDerived.mjs +6 -3
- package/src/class/ListSignal.mjs +11 -11
- package/src/class/LitExp.mjs +405 -0
- package/src/class/Paths.mjs +39 -4
- package/src/class/QChannel.mjs +79 -28
- package/src/class/SafeExit.mjs +31 -11
- package/src/class/Setup.mjs +12 -7
- package/src/class/Signal.mjs +26 -24
- package/src/class/WorkerMainThread.mjs +108 -135
- package/src/class/WorkerMainThreadBundled.mjs +216 -0
- package/src/class/WorkerThread.mjs +40 -31
- package/src/common/Base64URL.mjs +10 -5
- package/src/common/Base64URLFromFile.mjs +24 -0
- package/src/common/keys.mjs +3 -0
- package/src/doc/JSautoDOC.mjs +32 -56
- package/src/doc/parsedFile.mjs +37 -36
- package/src/function/CreateImmutable.mjs +9 -9
- package/src/function/EventCheck.mjs +2 -2
- package/src/function/EventObject.mjs +5 -5
- package/src/function/GetRuntime.mjs +38 -0
- package/src/function/IsAsync.mjs +2 -2
- package/src/function/LazyFactory.mjs +13 -13
- package/src/function/Timeout.mjs +2 -2
- package/src/function/Try.mjs +17 -12
- package/src/function/TryAsync.mjs +5 -5
- package/src/function/TrySync.mjs +5 -5
- package/src/function/TsToMjs.mjs +5 -4
- package/src/types/LitExpKeyType.mjs +5 -0
- package/src/types/QCBReturn.mjs +1 -1
- package/src/types/Runtime.mjs +7 -0
- package/types/dev/fsInline.d.mts +1 -0
- package/types/dev/test.d.mts +1 -0
- package/types/dev/testWorker.d.mts +7 -0
- package/types/dev/testbundle.d.mts +1 -0
- package/types/dev/workerThreadClass.d.mts +13 -0
- package/types/index.d.mts +18 -9
- package/types/src/bundler/CompileJS.d.mts +78 -0
- package/types/src/bundler/CreateESPlugin.d.mts +17 -0
- package/types/src/bundler/EsBundler.d.mts +33 -4
- package/types/src/bundler/FSInline.d.mts +43 -0
- package/types/src/bundler/FSInlineAnalyzer.d.mts +36 -0
- package/types/src/bundler/FSInlineBundled.d.mts +22 -0
- package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +16 -0
- package/types/src/bundler/adds/externals.d.mts +1 -0
- package/types/src/bundler/adds/pluginVivthBundle.d.mts +1 -0
- package/types/src/class/Console.d.mts +36 -5
- package/types/src/class/Derived.d.mts +132 -5
- package/types/src/class/Effect.d.mts +106 -7
- package/types/src/class/EnvSignal.d.mts +8 -8
- package/types/src/class/EventSignal.d.mts +151 -7
- package/types/src/class/FileSafe.d.mts +90 -0
- package/types/src/class/ListDerived.d.mts +8 -5
- package/types/src/class/ListSignal.d.mts +123 -18
- package/types/src/class/LitExp.d.mts +361 -0
- package/types/src/class/Paths.d.mts +30 -4
- package/types/src/class/QChannel.d.mts +69 -22
- package/types/src/class/SafeExit.d.mts +24 -9
- package/types/src/class/Setup.d.mts +13 -10
- package/types/src/class/Signal.d.mts +73 -17
- package/types/src/class/WorkerMainThread.d.mts +47 -39
- package/types/src/class/WorkerMainThreadBundled.d.mts +85 -0
- package/types/src/class/WorkerThread.d.mts +34 -26
- package/types/src/common/Base64URL.d.mts +22 -1
- package/types/src/common/Base64URLFromFile.d.mts +16 -0
- package/types/src/common/keys.d.mts +1 -0
- package/types/src/doc/JSautoDOC.d.mts +3 -19
- package/types/src/doc/parsedFile.d.mts +72 -13
- package/types/src/function/CreateImmutable.d.mts +27 -2
- package/types/src/function/EventCheck.d.mts +15 -0
- package/types/src/function/EventObject.d.mts +17 -2
- package/types/src/function/GetRuntime.d.mts +2 -0
- package/types/src/function/IsAsync.d.mts +18 -0
- package/types/src/function/LazyFactory.d.mts +35 -2
- package/types/src/function/Timeout.d.mts +16 -0
- package/types/src/function/Try.d.mts +52 -1
- package/types/src/function/TryAsync.d.mts +22 -1
- package/types/src/function/TrySync.d.mts +16 -1
- package/types/src/function/TsToMjs.d.mts +19 -0
- package/types/src/types/LitExpKeyType.d.mts +1 -0
- package/types/src/types/QCBReturn.d.mts +1 -1
- package/types/src/types/Runtime.d.mts +1 -0
- package/dev/index.mjs +0 -28
- package/src/bundler/CompileMJS.mjs +0 -110
- package/src/function/WriteFileSafe.mjs +0 -37
- package/types/src/bundler/A.d.mts +0 -1
- package/types/src/bundler/CompileMJS.d.mts +0 -8
- package/types/src/function/WriteFileSafe.d.mts +0 -2
|
@@ -10,15 +10,17 @@ export class Setup {
|
|
|
10
10
|
* import { Setup, Console } from 'vivth';
|
|
11
11
|
*
|
|
12
12
|
* new Setup.safeExit({
|
|
13
|
-
* //
|
|
14
|
-
*
|
|
13
|
+
* // eventNames are blank by default, you need to manually name them all;
|
|
14
|
+
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
15
|
+
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
16
|
+
* terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
15
17
|
* // optional deno example
|
|
16
|
-
*
|
|
18
|
+
* listener = (eventName) => {
|
|
17
19
|
* const sig = Deno.signal(eventName);
|
|
18
20
|
* for await (const _ of sig) {
|
|
19
|
-
*
|
|
21
|
+
* exiting.correction(true);
|
|
20
22
|
* sig.dispose();
|
|
21
|
-
* Console.
|
|
23
|
+
* Console.log(`safe exit via "${eventName}"`);
|
|
22
24
|
* }
|
|
23
25
|
* }
|
|
24
26
|
* });
|
|
@@ -40,9 +42,10 @@ export class Setup {
|
|
|
40
42
|
* - proxy `WorkerMainThread_instance` for Setup;
|
|
41
43
|
* @example
|
|
42
44
|
* import { Setup } from 'vivth';
|
|
45
|
+
* import { Worker } from 'node:worker_threads';
|
|
43
46
|
*
|
|
44
47
|
* Setup.workerMain({
|
|
45
|
-
* workerClass:
|
|
48
|
+
* workerClass: Worker,
|
|
46
49
|
* basePath: 'public/assets/js/workers',
|
|
47
50
|
* pathValidator: async (workerPath, root, base) => {
|
|
48
51
|
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
@@ -59,16 +62,16 @@ export class Setup {
|
|
|
59
62
|
/**
|
|
60
63
|
* @description
|
|
61
64
|
* - correct `parentPort` reference when needed;
|
|
65
|
+
* - export to create new reference to be use to create new WorkerThread instance;
|
|
62
66
|
* @example
|
|
63
67
|
* import { Setup } from 'vivth';
|
|
68
|
+
* import { parentPort } from 'node:worker_threads';
|
|
64
69
|
*
|
|
65
|
-
* Setup.workerThread({
|
|
70
|
+
* export const MyWorkerThreadRef = Setup.workerThread({parentPort});
|
|
66
71
|
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
67
72
|
* // you need to call this method;
|
|
68
73
|
*/
|
|
69
|
-
static workerThread:
|
|
70
|
-
parentPort: () => Promise<any>;
|
|
71
|
-
}) => typeof WorkerThread<Receive_, Post_>;
|
|
74
|
+
static workerThread: typeof WorkerThread.setup;
|
|
72
75
|
}
|
|
73
76
|
import { SafeExit } from './SafeExit.mjs';
|
|
74
77
|
import { Paths } from './Paths.mjs';
|
|
@@ -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
|
|
8
|
+
* @template VALUE
|
|
9
9
|
*/
|
|
10
|
-
export class Signal<
|
|
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
|
-
*
|
|
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:
|
|
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<
|
|
41
|
+
* @param {(options:{signalInstance:Signal<VALUE>})=>Promise<void>} [callback]
|
|
41
42
|
* @returns {void}
|
|
42
43
|
* @example
|
|
43
|
-
*
|
|
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<
|
|
59
|
+
signalInstance: Signal<VALUE>;
|
|
59
60
|
}) => Promise<void>) => void;
|
|
60
61
|
} & {
|
|
61
|
-
"vivth:unwrapLazy;":
|
|
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;":
|
|
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
|
-
* @
|
|
152
|
+
* @returns {VALUE}
|
|
97
153
|
*/
|
|
98
|
-
get prev():
|
|
154
|
+
get prev(): VALUE;
|
|
99
155
|
/**
|
|
100
156
|
* @description
|
|
101
157
|
* - assign new value then automatically notify all subscribers;
|
|
102
|
-
* @type {
|
|
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:
|
|
167
|
+
set value(newValue: VALUE);
|
|
112
168
|
/**
|
|
113
169
|
* @description
|
|
114
170
|
* - value after change;
|
|
115
|
-
* @
|
|
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
|
|
181
|
+
* const oneMoreThanCount = new Derived(async ({ subscribe }) =>{
|
|
126
182
|
* return subscribe(count).value + 1; // reactive
|
|
127
183
|
* })
|
|
128
184
|
*/
|
|
129
|
-
get value():
|
|
185
|
+
get value(): VALUE;
|
|
130
186
|
#private;
|
|
131
187
|
}
|
|
132
188
|
import { Effect } from './Effect.mjs';
|
|
@@ -1,37 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @template
|
|
3
|
-
* @typedef {import('./WorkerResult.mjs').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
|
|
17
22
|
* - need to be called first, before any `WorkerMainThread` instantiation:
|
|
18
23
|
* @param {Object} param0
|
|
19
24
|
* @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
|
|
25
|
+
* - example:
|
|
26
|
+
* ```js
|
|
27
|
+
* import { Worker } from 'node:worker_threads';
|
|
28
|
+
* ```
|
|
20
29
|
* @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
|
|
30
|
+
* - example:
|
|
21
31
|
* ```js
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
32
|
+
* async (workerPath, root, base) => {
|
|
33
|
+
* const truePathCheck = `${root}/${base}/${workerPath}`;
|
|
34
|
+
* const res = await fetch(truePathCheck);
|
|
35
|
+
* // might also check wheter it need base or not
|
|
36
|
+
* return await res.ok;
|
|
37
|
+
* }
|
|
26
38
|
* ```
|
|
27
39
|
* @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
|
|
28
40
|
* - additonal realtivePath from rootPath;
|
|
29
41
|
* - default: '';
|
|
30
42
|
* @example
|
|
43
|
+
* import { Worker } from 'node:worker_threads';
|
|
31
44
|
* import { WorkerMainThread } from 'vivth';
|
|
32
45
|
*
|
|
33
46
|
* WorkerMainThread.setup({
|
|
34
|
-
* workerClass:
|
|
47
|
+
* workerClass: Worker,
|
|
35
48
|
* basePath: 'public/assets/js/workers',
|
|
36
49
|
* pathValidator: async (workerPath, root, base) => {
|
|
37
50
|
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
@@ -49,9 +62,9 @@ export class WorkerMainThread<WT extends WorkerThread> {
|
|
|
49
62
|
* @description
|
|
50
63
|
* - reference for `Worker` class;
|
|
51
64
|
* - edit via `setup`;
|
|
52
|
-
* @type {
|
|
65
|
+
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
53
66
|
*/
|
|
54
|
-
static workerClass:
|
|
67
|
+
static workerClass: typeof Worker | typeof import("worker_threads").Worker;
|
|
55
68
|
/**
|
|
56
69
|
* @description
|
|
57
70
|
* - reference for worker file `basePath`;
|
|
@@ -73,44 +86,38 @@ export class WorkerMainThread<WT extends WorkerThread> {
|
|
|
73
86
|
static #options: import("worker_threads").WorkerOptions & {
|
|
74
87
|
type?: "module";
|
|
75
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>;
|
|
76
102
|
/**
|
|
77
103
|
* @param {string} handler
|
|
78
104
|
* @param { WorkerOptions
|
|
79
105
|
* | import('worker_threads').WorkerOptions} options
|
|
80
106
|
* @param {WorkerMainThread} worker
|
|
81
107
|
* @param {(any:any)=>void} listener
|
|
82
|
-
* @param {boolean} isInline
|
|
83
108
|
* @returns {Promise<void>}
|
|
84
109
|
*/
|
|
85
|
-
static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void
|
|
86
|
-
/**
|
|
87
|
-
* @type {boolean}
|
|
88
|
-
*/
|
|
89
|
-
static #isBrowser: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* @description
|
|
92
|
-
* - check whether js run in browser
|
|
93
|
-
* @type {boolean}
|
|
94
|
-
*/
|
|
95
|
-
static get isBrowser(): boolean;
|
|
110
|
+
static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void) => Promise<void>;
|
|
96
111
|
/**
|
|
97
|
-
* @
|
|
98
|
-
*
|
|
99
|
-
* @param {
|
|
100
|
-
* - if `isInline` === `false`, `handler` should be:
|
|
101
|
-
* >- pointing to worker thread file; WHICH
|
|
102
|
-
* >- the path must be relative to `projectRoot`;
|
|
103
|
-
* - if `isInline` === `true`, `handler` should be
|
|
104
|
-
* >- string literal of prebundled worker thread script; OR
|
|
105
|
-
* >- manually made string literal of worker thread script;
|
|
106
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
107
|
-
* @param {boolean} [isInline]
|
|
112
|
+
* @private
|
|
113
|
+
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
114
|
+
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
|
|
108
115
|
* @example
|
|
109
116
|
* import { WorkerMainThread } from 'vivth';
|
|
110
117
|
*
|
|
111
|
-
* export const myDoubleWorker =
|
|
118
|
+
* export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
|
|
112
119
|
*/
|
|
113
|
-
constructor(
|
|
120
|
+
private constructor();
|
|
114
121
|
/**
|
|
115
122
|
* @description
|
|
116
123
|
* - terminate all signals that are used on this instance;
|
|
@@ -120,7 +127,7 @@ export class WorkerMainThread<WT extends WorkerThread> {
|
|
|
120
127
|
/**
|
|
121
128
|
* @description
|
|
122
129
|
* - result signal of the processed message;
|
|
123
|
-
* @type {Derived<WorkerResult<WT["
|
|
130
|
+
* @type {Derived<WorkerResult<WT["POST"]>>}
|
|
124
131
|
* @example
|
|
125
132
|
* import { Effect } from 'vivth';
|
|
126
133
|
* import { myDoubleWorker } from './myDoubleWorker.mjs';
|
|
@@ -131,19 +138,20 @@ export class WorkerMainThread<WT extends WorkerThread> {
|
|
|
131
138
|
* // code
|
|
132
139
|
* })
|
|
133
140
|
*/
|
|
134
|
-
receiverSignal: Derived<WorkerResult<WT["
|
|
141
|
+
receiverSignal: Derived<WorkerResult<WT["POST"]>>;
|
|
135
142
|
/**
|
|
136
143
|
* @description
|
|
137
144
|
* - callback to send message to the worker thread;
|
|
138
|
-
* @type {(event: WT["
|
|
145
|
+
* @type {(event: WT["RECEIVE"])=>void}
|
|
139
146
|
* @example
|
|
140
147
|
* import { myDoubleWorker } from './myDoubleWorker.mjs';
|
|
141
148
|
*
|
|
142
149
|
* myDoubleWorker.postMessage(90);
|
|
143
150
|
*/
|
|
144
|
-
postMessage: (event: WT["
|
|
151
|
+
postMessage: (event: WT["RECEIVE"]) => void;
|
|
145
152
|
#private;
|
|
146
153
|
}
|
|
147
|
-
export type WorkerResult<
|
|
154
|
+
export type WorkerResult<POST> = import("./WorkerResult.mjs").WorkerResult<POST>;
|
|
148
155
|
export type WorkerThread = import("./WorkerThread.mjs").WorkerThread<any, any>;
|
|
156
|
+
export type unwrapLazy = "vivth:unwrapLazy;";
|
|
149
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,34 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - class helper for `WorkerThread` creation;
|
|
4
|
-
*
|
|
5
|
-
* @template
|
|
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<
|
|
8
|
+
export class WorkerThread<RECEIVE, POST> {
|
|
8
9
|
/**
|
|
9
|
-
* @
|
|
10
|
+
* @typedef {import('../types/QCBReturn.mjs').QCBReturn} QCBReturn
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
18
|
-
* @template
|
|
19
|
-
* @param {{parentPort:()
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
19
|
+
* @template RECEIVE
|
|
20
|
+
* @template POST
|
|
21
|
+
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
22
|
+
* -example:
|
|
23
|
+
* ```js
|
|
24
|
+
* import { parentPort } from 'node:worker_threads';
|
|
25
|
+
* ```
|
|
26
|
+
* @returns {typeof WorkerThread<RECEIVE, POST>}
|
|
22
27
|
* @example
|
|
23
28
|
* import { WorkerThread } from 'vivth';
|
|
29
|
+
* import { parentPort } from 'node:worker_threads';
|
|
24
30
|
*
|
|
25
|
-
* WorkerThread.setup({ parentPort
|
|
26
|
-
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
27
|
-
* // you need to call this method;
|
|
31
|
+
* export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
28
32
|
*/
|
|
29
|
-
static setup
|
|
30
|
-
parentPort: ()
|
|
31
|
-
})
|
|
33
|
+
static setup<RECEIVE_1, POST_1>(refs: {
|
|
34
|
+
parentPort: typeof import("worker_threads")["parentPort"];
|
|
35
|
+
}): typeof WorkerThread<RECEIVE_1, POST_1>;
|
|
32
36
|
/**
|
|
33
37
|
* @param {any} ev
|
|
34
38
|
*/
|
|
@@ -41,30 +45,34 @@ export class WorkerThread<Receive, Post> {
|
|
|
41
45
|
* import { MyWorkerThread } from './MyWorkerThread.mjs';
|
|
42
46
|
*
|
|
43
47
|
* const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
44
|
-
* // if(!isLastOnQ) {
|
|
48
|
+
* // if(!isLastOnQ()) {
|
|
45
49
|
* // return null; // can be used for imperative debouncing;
|
|
46
50
|
* // }
|
|
51
|
+
* // await fetch('some/path')
|
|
52
|
+
* // if(!isLastOnQ()) {
|
|
53
|
+
* // return;
|
|
54
|
+
* // }
|
|
47
55
|
* return ev = ev \* 2;
|
|
48
56
|
* });
|
|
49
57
|
*/
|
|
50
|
-
constructor(handler: (ev: any, isLastOnQ: boolean) => any);
|
|
58
|
+
constructor(handler: (ev: any, isLastOnQ: () => boolean) => any);
|
|
51
59
|
/**
|
|
52
60
|
* @description
|
|
53
61
|
* - type helper;
|
|
54
|
-
* @type {(ev:
|
|
62
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
55
63
|
*/
|
|
56
|
-
handler: (ev:
|
|
64
|
+
handler: (ev: RECEIVE, isLastOnQ: () => boolean) => POST;
|
|
57
65
|
/**
|
|
58
66
|
* @description
|
|
59
67
|
* - helper type, hold no actual value;
|
|
60
|
-
* @type {
|
|
68
|
+
* @type {RECEIVE}
|
|
61
69
|
*/
|
|
62
|
-
|
|
70
|
+
RECEIVE: RECEIVE;
|
|
63
71
|
/**
|
|
64
72
|
* @description
|
|
65
73
|
* - helper type, hold no actual value;
|
|
66
|
-
* @type {
|
|
74
|
+
* @type {POST}
|
|
67
75
|
*/
|
|
68
|
-
|
|
76
|
+
POST: POST;
|
|
69
77
|
#private;
|
|
70
78
|
}
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
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`
|
|
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 {
|
|
39
|
+
* import { JSautoDOC } from 'vivth';
|
|
40
40
|
*
|
|
41
|
-
*
|
|
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',
|