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.
- package/README.md +1215 -433
- package/README.src.md +5 -2
- package/bun.lock +228 -0
- package/index.mjs +17 -4
- 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 +27 -1
- package/src/class/QChannel.mjs +79 -28
- package/src/class/SafeExit.mjs +31 -11
- package/src/class/Setup.mjs +5 -2
- package/src/class/Signal.mjs +26 -24
- package/src/class/WorkerMainThread.mjs +100 -133
- package/src/class/WorkerMainThreadBundled.mjs +216 -0
- package/src/class/WorkerThread.mjs +38 -32
- 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 +13 -4
- 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 +18 -1
- 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 +6 -5
- package/types/src/class/Signal.d.mts +73 -17
- package/types/src/class/WorkerMainThread.d.mts +39 -37
- package/types/src/class/WorkerMainThreadBundled.d.mts +85 -0
- package/types/src/class/WorkerThread.d.mts +32 -27
- 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
|
@@ -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,16 +1,21 @@
|
|
|
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
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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:
|
|
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 {
|
|
65
|
+
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
59
66
|
*/
|
|
60
|
-
static workerClass:
|
|
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
|
|
110
|
+
static #workerFilehandler: (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void) => Promise<void>;
|
|
92
111
|
/**
|
|
93
|
-
* @
|
|
94
|
-
|
|
95
|
-
|
|
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 =
|
|
118
|
+
* export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
|
|
118
119
|
*/
|
|
119
|
-
constructor(
|
|
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["
|
|
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["
|
|
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["
|
|
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["
|
|
151
|
+
postMessage: (event: WT["RECEIVE"]) => void;
|
|
151
152
|
#private;
|
|
152
153
|
}
|
|
153
|
-
export type WorkerResult<
|
|
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
|
-
*
|
|
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
|
-
* -
|
|
19
|
+
* @template RECEIVE
|
|
20
|
+
* @template POST
|
|
21
|
+
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
22
|
+
* -example:
|
|
21
23
|
* ```js
|
|
22
|
-
*
|
|
24
|
+
* import { parentPort } from 'node:worker_threads';
|
|
23
25
|
* ```
|
|
24
|
-
* @returns {typeof WorkerThread<
|
|
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
|
|
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
|
|
33
|
-
parentPort: ()
|
|
34
|
-
})
|
|
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:
|
|
62
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
58
63
|
*/
|
|
59
|
-
handler: (ev:
|
|
64
|
+
handler: (ev: RECEIVE, isLastOnQ: () => boolean) => POST;
|
|
60
65
|
/**
|
|
61
66
|
* @description
|
|
62
67
|
* - helper type, hold no actual value;
|
|
63
|
-
* @type {
|
|
68
|
+
* @type {RECEIVE}
|
|
64
69
|
*/
|
|
65
|
-
|
|
70
|
+
RECEIVE: RECEIVE;
|
|
66
71
|
/**
|
|
67
72
|
* @description
|
|
68
73
|
* - helper type, hold no actual value;
|
|
69
|
-
* @type {
|
|
74
|
+
* @type {POST}
|
|
70
75
|
*/
|
|
71
|
-
|
|
76
|
+
POST: POST;
|
|
72
77
|
#private;
|
|
73
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',
|