vivth 1.4.3 → 1.4.5
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 +43 -6
- package/index.mjs +1 -0
- package/package.json +1 -1
- package/src/class/LitExp.mjs +1 -1
- package/src/class/WorkerMainThread.mjs +8 -7
- package/src/class/WorkerMainThreadBundled.mjs +8 -7
- package/src/class/WorkerThread.mjs +5 -4
- package/src/function/TemplateLiteral.mjs +67 -0
- package/types/index.d.mts +1 -0
- package/types/src/class/WorkerMainThread.d.mts +7 -7
- package/types/src/class/WorkerMainThreadBundled.d.mts +7 -7
- package/types/src/class/WorkerThread.d.mts +7 -6
- package/types/src/function/TemplateLiteral.d.mts +22 -0
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ npm i vivth
|
|
|
92
92
|
- [GetRuntime](#getruntime)
|
|
93
93
|
- [IsAsync](#isasync)
|
|
94
94
|
- [LazyFactory](#lazyfactory)
|
|
95
|
+
- [TemplateLiteral](#templateliteral)
|
|
95
96
|
- [Timeout](#timeout)
|
|
96
97
|
- [Tries](#tries)
|
|
97
98
|
- [TryAsync](#tryasync)
|
|
@@ -2547,7 +2548,7 @@ WorkerMainThread.setup({
|
|
|
2547
2548
|
|
|
2548
2549
|
```js
|
|
2549
2550
|
/**
|
|
2550
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
2551
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
2551
2552
|
*/
|
|
2552
2553
|
```
|
|
2553
2554
|
|
|
@@ -2569,7 +2570,7 @@ WorkerMainThread.setup({
|
|
|
2569
2570
|
```js
|
|
2570
2571
|
/**
|
|
2571
2572
|
* @param {string} handler
|
|
2572
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
2573
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
2573
2574
|
* @returns {WorkerMainThread<WT>}
|
|
2574
2575
|
*/
|
|
2575
2576
|
```
|
|
@@ -2694,7 +2695,7 @@ myDoubleWorker.postMessage(90);
|
|
|
2694
2695
|
/**
|
|
2695
2696
|
* @template RECEIVE
|
|
2696
2697
|
* @template POST
|
|
2697
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
2698
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
2698
2699
|
* -example:
|
|
2699
2700
|
* ```js
|
|
2700
2701
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -2727,7 +2728,7 @@ export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
|
2727
2728
|
```js
|
|
2728
2729
|
import { MyWorkerThread } from "./MyWorkerThread.mjs";
|
|
2729
2730
|
|
|
2730
|
-
const
|
|
2731
|
+
const handler = async (ev, isLastOnQ) => {
|
|
2731
2732
|
// if(!isLastOnQ()) {
|
|
2732
2733
|
// return null; // can be used for imperative debouncing;
|
|
2733
2734
|
// }
|
|
@@ -2736,7 +2737,8 @@ const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
|
2736
2737
|
// return;
|
|
2737
2738
|
// }
|
|
2738
2739
|
return (ev = ev * 2);
|
|
2739
|
-
}
|
|
2740
|
+
};
|
|
2741
|
+
new MyWorkerThread(handler);
|
|
2740
2742
|
```
|
|
2741
2743
|
|
|
2742
2744
|
#### reference:`WorkerThread_instance.handler`
|
|
@@ -2745,7 +2747,7 @@ const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
|
2745
2747
|
|
|
2746
2748
|
```js
|
|
2747
2749
|
/**
|
|
2748
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
2750
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
2749
2751
|
*/
|
|
2750
2752
|
```
|
|
2751
2753
|
|
|
@@ -3272,6 +3274,41 @@ myInstance["vivth:unwrapLazy;"](); // forcefully call factory generator;
|
|
|
3272
3274
|
|
|
3273
3275
|
\*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
|
|
3274
3276
|
|
|
3277
|
+
<h2 id="templateliteral">TemplateLiteral</h2>
|
|
3278
|
+
|
|
3279
|
+
#### reference:`TemplateLiteral`
|
|
3280
|
+
|
|
3281
|
+
- function helper to create template literal with VALUEhandler to handle each values;
|
|
3282
|
+
|
|
3283
|
+
```js
|
|
3284
|
+
/**
|
|
3285
|
+
* @template {(input:any)=>string|Promise<string>} VALUEHANDLER
|
|
3286
|
+
* @param {VALUEHANDLER} valueHandler
|
|
3287
|
+
* @param {(result:string)=>string} [postProcess]
|
|
3288
|
+
* @returns {(strings:TemplateStringsArray,
|
|
3289
|
+
* ...values:(Parameters<VALUEHANDLER>[0])[])=>
|
|
3290
|
+
* ReturnType<VALUEHANDLER>}
|
|
3291
|
+
*/
|
|
3292
|
+
```
|
|
3293
|
+
|
|
3294
|
+
- <i>example</i>:
|
|
3295
|
+
|
|
3296
|
+
```js
|
|
3297
|
+
import { TemplateLiteral } form 'vivth';
|
|
3298
|
+
|
|
3299
|
+
export const html = TemplateLiteral(
|
|
3300
|
+
(val) => val,
|
|
3301
|
+
// optional
|
|
3302
|
+
(res) => return window.body.innerHTML = res
|
|
3303
|
+
);
|
|
3304
|
+
|
|
3305
|
+
html`<div>${`<button>innerButton</button>`}</div>`;
|
|
3306
|
+
// this will set innerHTML of body to '<div><button>innerButton</button></div>'
|
|
3307
|
+
|
|
3308
|
+
```
|
|
3309
|
+
|
|
3310
|
+
\*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
|
|
3311
|
+
|
|
3275
3312
|
<h2 id="timeout">Timeout</h2>
|
|
3276
3313
|
|
|
3277
3314
|
#### reference:`Timeout`
|
package/index.mjs
CHANGED
|
@@ -45,6 +45,7 @@ export { GetNamedImportAlias } from './src/function/GetNamedImportAlias.mjs';
|
|
|
45
45
|
export { GetRuntime } from './src/function/GetRuntime.mjs';
|
|
46
46
|
export { IsAsync } from './src/function/IsAsync.mjs';
|
|
47
47
|
export { LazyFactory } from './src/function/LazyFactory.mjs';
|
|
48
|
+
export { TemplateLiteral } from './src/function/TemplateLiteral.mjs';
|
|
48
49
|
export { Timeout } from './src/function/Timeout.mjs';
|
|
49
50
|
export { Tries } from './src/function/Tries.mjs';
|
|
50
51
|
export { TryAsync } from './src/function/TryAsync.mjs';
|
package/package.json
CHANGED
package/src/class/LitExp.mjs
CHANGED
|
@@ -132,7 +132,7 @@ export class LitExp {
|
|
|
132
132
|
throw new Error('string undefined');
|
|
133
133
|
}
|
|
134
134
|
if (i + 1 == stringsLength && string === '') {
|
|
135
|
-
result.push('(?:\\s
|
|
135
|
+
result.push('(?:\\s+?|;|,|$|\/\/)');
|
|
136
136
|
} else {
|
|
137
137
|
result.push(LitExp.escape(string));
|
|
138
138
|
}
|
|
@@ -88,7 +88,7 @@ export class WorkerMainThread {
|
|
|
88
88
|
* @description
|
|
89
89
|
* - reference for `Worker` class;
|
|
90
90
|
* - edit via `setup`;
|
|
91
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
91
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
92
92
|
*/
|
|
93
93
|
static workerClass;
|
|
94
94
|
/**
|
|
@@ -98,15 +98,16 @@ export class WorkerMainThread {
|
|
|
98
98
|
* @type {(paths:{worker: string, root:string})=>Promise<string>}
|
|
99
99
|
*/
|
|
100
100
|
static pathValidator;
|
|
101
|
-
static #options =
|
|
102
|
-
type: 'module'
|
|
103
|
-
|
|
101
|
+
static #options =
|
|
102
|
+
/** @type {import('node:worker_threads').WorkerOptions & { type?: 'module' }} */ ({
|
|
103
|
+
type: 'module',
|
|
104
|
+
});
|
|
104
105
|
/**
|
|
105
106
|
* @template {WorkerThread<any, any>} WT
|
|
106
107
|
* @description
|
|
107
108
|
* - create Worker_instance;
|
|
108
109
|
* @param {string} handler
|
|
109
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
110
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
110
111
|
* @returns {WorkerMainThread<WT>}
|
|
111
112
|
* @example
|
|
112
113
|
* import { WorkerMainThread } from 'vivth';
|
|
@@ -144,7 +145,7 @@ export class WorkerMainThread {
|
|
|
144
145
|
* @template {WorkerThread<any, any>} WT
|
|
145
146
|
* @param {string} handler
|
|
146
147
|
* @param { WorkerOptions
|
|
147
|
-
* | import('worker_threads').WorkerOptions} options
|
|
148
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
148
149
|
* @param {WorkerMainThread<WT>} worker
|
|
149
150
|
* @param {(any:any)=>void} listener
|
|
150
151
|
* @returns {Promise<void>}
|
|
@@ -246,7 +247,7 @@ export class WorkerMainThread {
|
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
248
249
|
* lazyly generated because node version need to await
|
|
249
|
-
* @type {Signal<Worker | import('worker_threads').Worker>}
|
|
250
|
+
* @type {Signal<Worker | import('node:worker_threads').Worker>}
|
|
250
251
|
*/
|
|
251
252
|
// @ts-expect-error
|
|
252
253
|
#worker = new Signal(undefined);
|
|
@@ -51,20 +51,21 @@ export class WorkerMainThread {
|
|
|
51
51
|
WorkerMainThread.pathValidator = pathValidator;
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
54
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
55
55
|
*/
|
|
56
56
|
static workerClass;
|
|
57
57
|
/**
|
|
58
58
|
* @type {(paths:{worker: string, root:string})=>Promise<string>}
|
|
59
59
|
*/
|
|
60
60
|
static pathValidator;
|
|
61
|
-
static #options =
|
|
62
|
-
type: 'module'
|
|
63
|
-
|
|
61
|
+
static #options =
|
|
62
|
+
/** @type {import('node:worker_threads').WorkerOptions & { type?: 'module' }} */ ({
|
|
63
|
+
type: 'module',
|
|
64
|
+
});
|
|
64
65
|
/**
|
|
65
66
|
* @template {WorkerThread<any, any>} WT
|
|
66
67
|
* @param {string} handler
|
|
67
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
68
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
68
69
|
* @returns {WorkerMainThread<WT>}
|
|
69
70
|
*/
|
|
70
71
|
static newVivthWorker(handler, options = {}) {
|
|
@@ -93,7 +94,7 @@ export class WorkerMainThread {
|
|
|
93
94
|
* @template {WorkerThread<any, any>} WT
|
|
94
95
|
* @param {string} handler
|
|
95
96
|
* @param { WorkerOptions
|
|
96
|
-
* | import('worker_threads').WorkerOptions} options
|
|
97
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
97
98
|
* @param {WorkerMainThread<WT>} worker
|
|
98
99
|
* @param {(any:any)=>void} listener
|
|
99
100
|
* @returns {Promise<void>}
|
|
@@ -179,7 +180,7 @@ export class WorkerMainThread {
|
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
182
|
* lazyly generated because node version need to await
|
|
182
|
-
* @type {Signal<Worker | import('worker_threads').Worker>}
|
|
183
|
+
* @type {Signal<Worker | import('node:worker_threads').Worker>}
|
|
183
184
|
*/
|
|
184
185
|
// @ts-expect-error
|
|
185
186
|
#worker = new Signal(undefined);
|
|
@@ -28,7 +28,7 @@ export class WorkerThread {
|
|
|
28
28
|
* - need to be called and exported as new `WorkerThread` class reference;
|
|
29
29
|
* @template RECEIVE
|
|
30
30
|
* @template POST
|
|
31
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
31
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
32
32
|
* -example:
|
|
33
33
|
* ```js
|
|
34
34
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -61,7 +61,7 @@ export class WorkerThread {
|
|
|
61
61
|
* @example
|
|
62
62
|
* import { MyWorkerThread } from './MyWorkerThread.mjs';
|
|
63
63
|
*
|
|
64
|
-
* const
|
|
64
|
+
* const handler = async (ev, isLastOnQ) => {
|
|
65
65
|
* // if(!isLastOnQ()) {
|
|
66
66
|
* // return null; // can be used for imperative debouncing;
|
|
67
67
|
* // }
|
|
@@ -70,7 +70,8 @@ export class WorkerThread {
|
|
|
70
70
|
* // return;
|
|
71
71
|
* // }
|
|
72
72
|
* return ev = ev \* 2;
|
|
73
|
-
* }
|
|
73
|
+
* }
|
|
74
|
+
* new MyWorkerThread(handler);
|
|
74
75
|
*/
|
|
75
76
|
constructor(handler) {
|
|
76
77
|
this.handler = handler;
|
|
@@ -154,7 +155,7 @@ export class WorkerThread {
|
|
|
154
155
|
/**
|
|
155
156
|
* @description
|
|
156
157
|
* - type helper;
|
|
157
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
158
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
158
159
|
*/
|
|
159
160
|
handler;
|
|
160
161
|
/**
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { IsAsync } from './IsAsync.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* - function helper to create template literal with VALUEhandler to handle each values;
|
|
8
|
+
* @template {(input:any)=>string|Promise<string>} VALUEHANDLER
|
|
9
|
+
* @param {VALUEHANDLER} valueHandler
|
|
10
|
+
* @param {(result:string)=>string} [postProcess]
|
|
11
|
+
* @returns {(strings:TemplateStringsArray,
|
|
12
|
+
* ...values:(Parameters<VALUEHANDLER>[0])[])=>
|
|
13
|
+
* ReturnType<VALUEHANDLER>}
|
|
14
|
+
* @example
|
|
15
|
+
* import { TemplateLiteral } form 'vivth';
|
|
16
|
+
*
|
|
17
|
+
* export const html = TemplateLiteral(
|
|
18
|
+
* (val) => val,
|
|
19
|
+
* // optional
|
|
20
|
+
* (res) => return window.body.innerHTML = res
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* html`<div>${`<button>innerButton</button>`}</div>`;
|
|
24
|
+
* // this will set innerHTML of body to '<div><button>innerButton</button></div>'
|
|
25
|
+
*/
|
|
26
|
+
export function TemplateLiteral(valueHandler, postProcess = undefined) {
|
|
27
|
+
if (IsAsync(valueHandler)) {
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
return async (strings, ...values) => {
|
|
30
|
+
const result = [];
|
|
31
|
+
for (let i = 0; i < strings.length; i++) {
|
|
32
|
+
result.push(strings[i]);
|
|
33
|
+
if (i < values.length) {
|
|
34
|
+
const value = values[i];
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
result.push(await valueHandler(value));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const resTrue = result.join('');
|
|
42
|
+
if (!postProcess) {
|
|
43
|
+
return resTrue;
|
|
44
|
+
}
|
|
45
|
+
return postProcess(resTrue);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
return (strings, ...values) => {
|
|
50
|
+
const result = [];
|
|
51
|
+
for (let i = 0; i < strings.length; i++) {
|
|
52
|
+
result.push(strings[i]);
|
|
53
|
+
if (i < values.length) {
|
|
54
|
+
const value = values[i];
|
|
55
|
+
if (value === undefined) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
result.push(valueHandler(value));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const resTrue = result.join('');
|
|
62
|
+
if (!postProcess) {
|
|
63
|
+
return resTrue;
|
|
64
|
+
}
|
|
65
|
+
return postProcess(resTrue);
|
|
66
|
+
};
|
|
67
|
+
}
|
package/types/index.d.mts
CHANGED
|
@@ -37,6 +37,7 @@ export { GetNamedImportAlias } from "./src/function/GetNamedImportAlias.mjs";
|
|
|
37
37
|
export { GetRuntime } from "./src/function/GetRuntime.mjs";
|
|
38
38
|
export { IsAsync } from "./src/function/IsAsync.mjs";
|
|
39
39
|
export { LazyFactory } from "./src/function/LazyFactory.mjs";
|
|
40
|
+
export { TemplateLiteral } from "./src/function/TemplateLiteral.mjs";
|
|
40
41
|
export { Timeout } from "./src/function/Timeout.mjs";
|
|
41
42
|
export { Tries } from "./src/function/Tries.mjs";
|
|
42
43
|
export { TryAsync } from "./src/function/TryAsync.mjs";
|
|
@@ -66,9 +66,9 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
66
66
|
* @description
|
|
67
67
|
* - reference for `Worker` class;
|
|
68
68
|
* - edit via `setup`;
|
|
69
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
69
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
70
70
|
*/
|
|
71
|
-
static workerClass: typeof Worker | typeof import("worker_threads").Worker;
|
|
71
|
+
static workerClass: typeof Worker | typeof import("node:worker_threads").Worker;
|
|
72
72
|
/**
|
|
73
73
|
* @description
|
|
74
74
|
* - reference for validating path;
|
|
@@ -79,7 +79,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
79
79
|
worker: string;
|
|
80
80
|
root: string;
|
|
81
81
|
}) => Promise<string>;
|
|
82
|
-
static "__#private@#options": import("worker_threads").WorkerOptions & {
|
|
82
|
+
static "__#private@#options": import("node:worker_threads").WorkerOptions & {
|
|
83
83
|
type?: "module";
|
|
84
84
|
};
|
|
85
85
|
/**
|
|
@@ -87,24 +87,24 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
87
87
|
* @description
|
|
88
88
|
* - create Worker_instance;
|
|
89
89
|
* @param {string} handler
|
|
90
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
90
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
91
91
|
* @returns {WorkerMainThread<WT>}
|
|
92
92
|
* @example
|
|
93
93
|
* import { WorkerMainThread } from 'vivth';
|
|
94
94
|
*
|
|
95
95
|
* export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
|
|
96
96
|
*/
|
|
97
|
-
static newVivthWorker<WT_1 extends WorkerThread<any, any>>(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("node:worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
|
|
98
98
|
/**
|
|
99
99
|
* @template {WorkerThread<any, any>} WT
|
|
100
100
|
* @param {string} handler
|
|
101
101
|
* @param { WorkerOptions
|
|
102
|
-
* | import('worker_threads').WorkerOptions} options
|
|
102
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
103
103
|
* @param {WorkerMainThread<WT>} worker
|
|
104
104
|
* @param {(any:any)=>void} listener
|
|
105
105
|
* @returns {Promise<void>}
|
|
106
106
|
*/
|
|
107
|
-
static "__#private@#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>;
|
|
107
|
+
static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("node:worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
|
|
108
108
|
/**
|
|
109
109
|
* @private
|
|
110
110
|
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
@@ -28,9 +28,9 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
28
28
|
pathValidator: (typeof WorkerMainThread)["pathValidator"];
|
|
29
29
|
}) => void;
|
|
30
30
|
/**
|
|
31
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
31
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
32
32
|
*/
|
|
33
|
-
static workerClass: typeof Worker | typeof import("worker_threads").Worker;
|
|
33
|
+
static workerClass: typeof Worker | typeof import("node:worker_threads").Worker;
|
|
34
34
|
/**
|
|
35
35
|
* @type {(paths:{worker: string, root:string})=>Promise<string>}
|
|
36
36
|
*/
|
|
@@ -38,26 +38,26 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
38
38
|
worker: string;
|
|
39
39
|
root: string;
|
|
40
40
|
}) => Promise<string>;
|
|
41
|
-
static "__#private@#options": import("worker_threads").WorkerOptions & {
|
|
41
|
+
static "__#private@#options": import("node:worker_threads").WorkerOptions & {
|
|
42
42
|
type?: "module";
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* @template {WorkerThread<any, any>} WT
|
|
46
46
|
* @param {string} handler
|
|
47
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
47
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
48
48
|
* @returns {WorkerMainThread<WT>}
|
|
49
49
|
*/
|
|
50
|
-
static newVivthWorker<WT_1 extends WorkerThread<any, any>>(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("node:worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
|
|
51
51
|
/**
|
|
52
52
|
* @template {WorkerThread<any, any>} WT
|
|
53
53
|
* @param {string} handler
|
|
54
54
|
* @param { WorkerOptions
|
|
55
|
-
* | import('worker_threads').WorkerOptions} options
|
|
55
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
56
56
|
* @param {WorkerMainThread<WT>} worker
|
|
57
57
|
* @param {(any:any)=>void} listener
|
|
58
58
|
* @returns {Promise<void>}
|
|
59
59
|
*/
|
|
60
|
-
static "__#private@#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>;
|
|
60
|
+
static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("node:worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
|
|
61
61
|
/**
|
|
62
62
|
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
63
63
|
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
|
|
@@ -18,7 +18,7 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
18
18
|
* - need to be called and exported as new `WorkerThread` class reference;
|
|
19
19
|
* @template RECEIVE
|
|
20
20
|
* @template POST
|
|
21
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
21
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
22
22
|
* -example:
|
|
23
23
|
* ```js
|
|
24
24
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -31,7 +31,7 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
31
31
|
* export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
32
32
|
*/
|
|
33
33
|
static setup<RECEIVE_1, POST_1>(refs: {
|
|
34
|
-
parentPort: typeof import("worker_threads")["parentPort"];
|
|
34
|
+
parentPort: typeof import("node:worker_threads")["parentPort"];
|
|
35
35
|
}): typeof WorkerThread<RECEIVE_1, POST_1>;
|
|
36
36
|
/**
|
|
37
37
|
* @param {any} ev
|
|
@@ -44,7 +44,7 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
44
44
|
* @example
|
|
45
45
|
* import { MyWorkerThread } from './MyWorkerThread.mjs';
|
|
46
46
|
*
|
|
47
|
-
* const
|
|
47
|
+
* const handler = async (ev, isLastOnQ) => {
|
|
48
48
|
* // if(!isLastOnQ()) {
|
|
49
49
|
* // return null; // can be used for imperative debouncing;
|
|
50
50
|
* // }
|
|
@@ -53,15 +53,16 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
53
53
|
* // return;
|
|
54
54
|
* // }
|
|
55
55
|
* return ev = ev \* 2;
|
|
56
|
-
* }
|
|
56
|
+
* }
|
|
57
|
+
* new MyWorkerThread(handler);
|
|
57
58
|
*/
|
|
58
59
|
constructor(handler: WorkerThread<RECEIVE, POST>["handler"]);
|
|
59
60
|
/**
|
|
60
61
|
* @description
|
|
61
62
|
* - type helper;
|
|
62
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
63
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
63
64
|
*/
|
|
64
|
-
handler: (ev: RECEIVE, isLastOnQ: () => boolean) => POST
|
|
65
|
+
handler: (ev: RECEIVE, isLastOnQ: () => boolean) => Promise<POST>;
|
|
65
66
|
/**
|
|
66
67
|
* @description
|
|
67
68
|
* - helper type, hold no actual value;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function helper to create template literal with VALUEhandler to handle each values;
|
|
4
|
+
* @template {(input:any)=>string|Promise<string>} VALUEHANDLER
|
|
5
|
+
* @param {VALUEHANDLER} valueHandler
|
|
6
|
+
* @param {(result:string)=>string} [postProcess]
|
|
7
|
+
* @returns {(strings:TemplateStringsArray,
|
|
8
|
+
* ...values:(Parameters<VALUEHANDLER>[0])[])=>
|
|
9
|
+
* ReturnType<VALUEHANDLER>}
|
|
10
|
+
* @example
|
|
11
|
+
* import { TemplateLiteral } form 'vivth';
|
|
12
|
+
*
|
|
13
|
+
* export const html = TemplateLiteral(
|
|
14
|
+
* (val) => val,
|
|
15
|
+
* // optional
|
|
16
|
+
* (res) => return window.body.innerHTML = res
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* html`<div>${`<button>innerButton</button>`}</div>`;
|
|
20
|
+
* // this will set innerHTML of body to '<div><button>innerButton</button></div>'
|
|
21
|
+
*/
|
|
22
|
+
export function TemplateLiteral<VALUEHANDLER extends (input: any) => string | Promise<string>>(valueHandler: VALUEHANDLER, postProcess?: (result: string) => string): (strings: TemplateStringsArray, ...values: (Parameters<VALUEHANDLER>[0])[]) => ReturnType<VALUEHANDLER>;
|