vivth 0.11.2 → 1.0.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 +2157 -69
- package/README.src.md +35 -0
- package/bun.lock +57 -3
- package/dev/index.mjs +24 -25
- package/index.mjs +51 -29
- package/package.json +11 -7
- package/src/bundler/CompileMJS.mjs +110 -0
- package/src/bundler/EsBundler.mjs +79 -0
- package/src/class/Console.mjs +62 -0
- package/src/class/Derived.mjs +36 -25
- package/src/class/Effect.mjs +106 -0
- package/src/class/EnvSignal.mjs +88 -0
- package/src/class/EventSignal.mjs +200 -0
- package/src/class/ListDerived.mjs +39 -0
- package/src/class/ListSignal.mjs +256 -0
- package/src/class/Paths.mjs +70 -0
- package/src/class/QChannel.mjs +184 -0
- package/src/class/SafeExit.mjs +131 -0
- package/src/class/Setup.mjs +73 -0
- package/src/class/Signal.mjs +152 -54
- package/src/class/WorkerMainThread.mjs +328 -0
- package/src/class/WorkerResult.mjs +30 -0
- package/src/class/WorkerThread.mjs +151 -0
- package/src/common/Base64URL.mjs +26 -0
- package/src/common/EventNameSpace.mjs +8 -0
- package/src/common/eventObjects.mjs +5 -0
- package/src/common/lazie.mjs +3 -0
- package/src/doc/JSautoDOC.mjs +386 -0
- package/src/doc/parsedFile.mjs +537 -0
- package/src/function/CreateImmutable.mjs +64 -0
- package/src/function/EventCheck.mjs +27 -0
- package/src/function/EventObject.mjs +21 -0
- package/src/function/IsAsync.mjs +23 -0
- package/src/function/LazyFactory.mjs +71 -0
- package/src/function/Timeout.mjs +23 -0
- package/src/function/Try.mjs +64 -0
- package/src/function/TryAsync.mjs +15 -4
- package/src/function/TrySync.mjs +9 -4
- package/src/function/TsToMjs.mjs +67 -0
- package/src/function/WriteFileSafe.mjs +37 -0
- package/src/types/{AnyButUndefined.type.mjs → AnyButUndefined.mjs} +1 -0
- package/src/types/ExtnameType.mjs +6 -0
- package/src/types/IsListSignal.mjs +6 -0
- package/src/types/ListArg.mjs +6 -0
- package/src/types/MutationType.mjs +8 -0
- package/src/types/QCBFIFOReturn.mjs +6 -0
- package/src/types/QCBReturn.mjs +6 -0
- package/tsconfig.json +3 -3
- package/types/dev/index.d.mts +1 -0
- package/types/index.d.mts +34 -8
- package/types/src/bundler/A.d.mts +1 -0
- package/types/src/bundler/CompileMJS.d.mts +8 -0
- package/types/src/bundler/EsBundler.d.mts +7 -0
- package/types/src/class/Console.d.mts +40 -0
- package/types/src/class/Derived.d.mts +21 -9
- package/types/src/class/Effect.d.mts +77 -0
- package/types/src/class/EnvSignal.d.mts +47 -0
- package/types/src/class/EventSignal.d.mts +145 -0
- package/types/src/class/ListDerived.d.mts +35 -0
- package/types/src/class/ListSignal.d.mts +150 -0
- package/types/src/class/Paths.d.mts +50 -0
- package/types/src/class/QChannel.d.mts +115 -0
- package/types/src/class/SafeExit.d.mts +76 -0
- package/types/src/class/Setup.d.mts +76 -0
- package/types/src/class/Signal.d.mts +105 -26
- package/types/src/class/WorkerMainThread.d.mts +149 -0
- package/types/src/class/WorkerResult.d.mts +25 -0
- package/types/src/class/WorkerThread.d.mts +70 -0
- package/types/src/common/Base64URL.d.mts +1 -0
- package/types/src/common/EventNameSpace.d.mts +6 -0
- package/types/src/common/eventObjects.d.mts +3 -0
- package/types/src/common/lazie.d.mts +1 -0
- package/types/src/doc/JSautoDOC.d.mts +76 -0
- package/types/src/doc/parsedFile.d.mts +154 -0
- package/types/src/function/CreateImmutable.d.mts +3 -0
- package/types/src/function/EventCheck.d.mts +2 -0
- package/types/src/function/EventObject.d.mts +4 -0
- package/types/src/function/IsAsync.d.mts +1 -0
- package/types/src/function/LazyFactory.d.mts +4 -0
- package/types/src/function/Timeout.d.mts +1 -0
- package/types/src/function/Try.d.mts +1 -0
- package/types/src/function/TsToMjs.d.mts +4 -0
- package/types/src/function/WriteFileSafe.d.mts +2 -0
- package/types/src/types/{AnyButUndefined.type.d.mts → AnyButUndefined.d.mts} +3 -0
- package/types/src/types/ExtnameType.d.mts +4 -0
- package/types/src/types/IsListSignal.d.mts +4 -0
- package/types/src/types/ListArg.d.mts +4 -0
- package/types/src/types/MutationType.d.mts +5 -0
- package/types/src/types/QCBFIFOReturn.d.mts +4 -0
- package/types/src/types/QCBReturn.d.mts +7 -0
- package/src/class/$.mjs +0 -68
- package/src/class/PingFIFO.mjs +0 -78
- package/src/class/PingUnique.mjs +0 -84
- package/src/class/Q.mjs +0 -98
- package/src/class/QFIFO.mjs +0 -66
- package/src/class/QUnique.mjs +0 -75
- package/src/common.mjs +0 -16
- package/src/function/NewQBlock.mjs +0 -39
- package/types/src/class/$.d.mts +0 -40
- package/types/src/class/PingFIFO.d.mts +0 -57
- package/types/src/class/PingUnique.d.mts +0 -48
- package/types/src/class/Q.d.mts +0 -63
- package/types/src/class/QFIFO.d.mts +0 -47
- package/types/src/class/QUnique.d.mts +0 -46
- package/types/src/common.d.mts +0 -2
- package/types/src/function/NewQBlock.d.mts +0 -1
|
@@ -1,53 +1,132 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* - a class for creating signal;
|
|
4
|
-
* - can be subscribed by using [New$](#new$) or [NewDerived](#newderived);
|
|
5
|
-
* - for minimal total bundle size use `function` [NewSignal](#newSignal) instead;
|
|
2
|
+
* @type {Set<Signal>}
|
|
6
3
|
*/
|
|
4
|
+
export const setOFSignals: Set<Signal<any>>;
|
|
7
5
|
/**
|
|
6
|
+
* @description
|
|
7
|
+
* - a class for creating effect to signals;
|
|
8
8
|
* @template Value
|
|
9
9
|
*/
|
|
10
10
|
export class Signal<Value> {
|
|
11
11
|
/**
|
|
12
|
-
* @param {
|
|
13
|
-
*/
|
|
14
|
-
constructor(value: Value);
|
|
15
|
-
/**
|
|
16
|
-
* @protected
|
|
12
|
+
* @param {Set<Effect>} setOfSubscribers
|
|
17
13
|
*/
|
|
18
|
-
|
|
14
|
+
static "__#13628@#notify": (setOfSubscribers: Set<Effect>) => void;
|
|
19
15
|
/**
|
|
20
|
-
*
|
|
16
|
+
* @description
|
|
17
|
+
* @param {Value} value
|
|
18
|
+
* @example
|
|
19
|
+
* import { Signal, Effect } from 'vivth';
|
|
20
|
+
*
|
|
21
|
+
* const count = new Signal(0);
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
constructor(value: Value);
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* @description
|
|
26
|
+
* - subsrcibers reference of this instance;
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
subscribers: {
|
|
29
|
+
/**
|
|
30
|
+
* @instance subscribers
|
|
31
|
+
* @description
|
|
32
|
+
* - subscribedEffects
|
|
33
|
+
* @type {Set<Effect>}
|
|
34
|
+
*/
|
|
35
|
+
setOf: Set<Effect>;
|
|
36
|
+
/**
|
|
37
|
+
* @instance subscribers
|
|
38
|
+
* @description
|
|
39
|
+
* - manually notify on non primitive value or value that have depths;
|
|
40
|
+
* @param {(options:{signalInstance:Signal<Value>})=>Promise<void>} [callback]
|
|
41
|
+
* @returns {void}
|
|
42
|
+
* @example
|
|
43
|
+
* // for deep signal like array or object you can:
|
|
44
|
+
*
|
|
45
|
+
* const arraySignal = new Signal([1,2]);
|
|
46
|
+
* arraySignal.value.push(3);
|
|
47
|
+
* arraySignal.subscribers.notify();
|
|
48
|
+
*
|
|
49
|
+
* // OR for more complex mutation:
|
|
50
|
+
*
|
|
51
|
+
* const objectSignal = new Signal({a:'test', b:'test'});
|
|
52
|
+
* objectSignal.subscribers.notify(async ({ signalInstance }) => {
|
|
53
|
+
* signalInstance.value['c'] = 'testc';
|
|
54
|
+
* signalInstance.value['d'] = 'testd';
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
notify: (callback?: (options: {
|
|
58
|
+
signalInstance: Signal<Value>;
|
|
59
|
+
}) => Promise<void>) => void;
|
|
60
|
+
} & {
|
|
61
|
+
"vivth:unwrapLazy;": string;
|
|
62
|
+
};
|
|
28
63
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @return {void}
|
|
64
|
+
* @description
|
|
65
|
+
* - collection of remove methods
|
|
32
66
|
*/
|
|
33
|
-
remove
|
|
34
|
-
|
|
67
|
+
remove: {
|
|
68
|
+
/**
|
|
69
|
+
* @instance remove
|
|
70
|
+
* @description
|
|
71
|
+
* - remove effect subscriber to react from this instance value changes;
|
|
72
|
+
* @param {Effect} effectInstance
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
subscriber: (effectInstance: Effect) => void;
|
|
76
|
+
/**
|
|
77
|
+
* @instance remove
|
|
78
|
+
* @description
|
|
79
|
+
* - remove all effect subscribers to react from this instance value changes;
|
|
80
|
+
* @type {()=>void}
|
|
81
|
+
*/
|
|
82
|
+
allSubscribers: () => void;
|
|
83
|
+
/**
|
|
84
|
+
* @instance remove
|
|
85
|
+
* @description
|
|
86
|
+
* - remove this instance from `vivth` reactivity engine, and nullify it's own value;
|
|
87
|
+
* @type {()=>void}
|
|
88
|
+
*/
|
|
89
|
+
ref: () => void;
|
|
90
|
+
} & {
|
|
91
|
+
"vivth:unwrapLazy;": string;
|
|
92
|
+
};
|
|
35
93
|
/**
|
|
94
|
+
* @description
|
|
95
|
+
* - value before change;
|
|
36
96
|
* @type {Value}
|
|
37
97
|
*/
|
|
38
|
-
get
|
|
98
|
+
get prev(): Value;
|
|
39
99
|
/**
|
|
100
|
+
* @description
|
|
101
|
+
* - assign new value then automatically notify all subscribers;
|
|
40
102
|
* @type {Value}
|
|
103
|
+
* @example
|
|
104
|
+
* import { Signal } from 'vivth';
|
|
105
|
+
*
|
|
106
|
+
* const count = new Signal(0);
|
|
107
|
+
* count.value++;
|
|
108
|
+
* // OR
|
|
109
|
+
* count.value = 9;
|
|
41
110
|
*/
|
|
42
111
|
set value(newValue: Value);
|
|
43
112
|
/**
|
|
113
|
+
* @description
|
|
114
|
+
* - value after change;
|
|
44
115
|
* @type {Value}
|
|
116
|
+
* @example
|
|
117
|
+
* import { Signal, Effect, Derived } from 'vivth';
|
|
118
|
+
*
|
|
119
|
+
* const count = new Signal(0);
|
|
120
|
+
* count.value; // not reactive
|
|
121
|
+
*
|
|
122
|
+
* new Effect(async ({ subscribe }) =>{
|
|
123
|
+
* const countValue = subscribe(count).value; // reactive
|
|
124
|
+
* })
|
|
125
|
+
* const oneMoreThanCount = new Effect(async ({ subscribe }) =>{
|
|
126
|
+
* return subscribe(count).value + 1; // reactive
|
|
127
|
+
* })
|
|
45
128
|
*/
|
|
46
129
|
get value(): Value;
|
|
47
|
-
/**
|
|
48
|
-
* @returns {void}
|
|
49
|
-
*/
|
|
50
|
-
call$: () => void;
|
|
51
130
|
#private;
|
|
52
131
|
}
|
|
53
|
-
import {
|
|
132
|
+
import { Effect } from './Effect.mjs';
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template A
|
|
3
|
+
* @typedef {import('./WorkerResult.mjs').WorkerResult<A>} WorkerResult
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('./WorkerThread.mjs').WorkerThread} WorkerThread
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @description
|
|
10
|
+
* - class helper to create `Worker` instance;
|
|
11
|
+
* @template {WorkerThread} WT
|
|
12
|
+
*/
|
|
13
|
+
export class WorkerMainThread<WT extends WorkerThread> {
|
|
14
|
+
static "__#18619@#isRegistered": boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* - need to be called first, before any `WorkerMainThread` instantiation:
|
|
18
|
+
* @param {Object} param0
|
|
19
|
+
* @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
|
|
20
|
+
* @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
|
|
21
|
+
* ```js
|
|
22
|
+
* async(relativePath) => {
|
|
23
|
+
* // verify whether relativePath exist, then return the full path
|
|
24
|
+
* // use fetch | fs, chained with Paths.instance.root + WorkerMainThread.basePath;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
* @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
|
|
28
|
+
* - additonal realtivePath from rootPath;
|
|
29
|
+
* - default: '';
|
|
30
|
+
* @example
|
|
31
|
+
* import { WorkerMainThread } from 'vivth';
|
|
32
|
+
*
|
|
33
|
+
* WorkerMainThread.setup({
|
|
34
|
+
* workerClass: async () => await (import('worker_threads')).Worker,
|
|
35
|
+
* basePath: 'public/assets/js/workers',
|
|
36
|
+
* pathValidator: async (workerPath, root, base) => {
|
|
37
|
+
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
38
|
+
* // might also check wheter it need base or not
|
|
39
|
+
* return await res.ok;
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
static setup: ({ workerClass, pathValidator, basePath }: {
|
|
44
|
+
workerClass: (typeof WorkerMainThread)["workerClass"];
|
|
45
|
+
pathValidator: (typeof WorkerMainThread)["pathValidator"];
|
|
46
|
+
basePath?: (typeof WorkerMainThread)["basePath"];
|
|
47
|
+
}) => void;
|
|
48
|
+
/**
|
|
49
|
+
* @description
|
|
50
|
+
* - reference for `Worker` class;
|
|
51
|
+
* - edit via `setup`;
|
|
52
|
+
* @type {()=>Promise<typeof Worker|typeof import('worker_threads').Worker>}
|
|
53
|
+
*/
|
|
54
|
+
static workerClass: () => Promise<typeof Worker | typeof import("worker_threads").Worker>;
|
|
55
|
+
/**
|
|
56
|
+
* @description
|
|
57
|
+
* - reference for worker file `basePath`;
|
|
58
|
+
* - edit via `setup`;
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
static basePath: string;
|
|
62
|
+
/**
|
|
63
|
+
* @description
|
|
64
|
+
* - reference for validating path;
|
|
65
|
+
* - edit via `setup`;
|
|
66
|
+
* @type {(paths:{worker: string, root:string, base: string})=>Promise<string>}
|
|
67
|
+
*/
|
|
68
|
+
static pathValidator: (paths: {
|
|
69
|
+
worker: string;
|
|
70
|
+
root: string;
|
|
71
|
+
base: string;
|
|
72
|
+
}) => Promise<string>;
|
|
73
|
+
static "__#18619@#options": import("worker_threads").WorkerOptions & {
|
|
74
|
+
type?: "module";
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} handler
|
|
78
|
+
* @param { WorkerOptions
|
|
79
|
+
* | import('worker_threads').WorkerOptions} options
|
|
80
|
+
* @param {WorkerMainThread} worker
|
|
81
|
+
* @param {(any:any)=>void} listener
|
|
82
|
+
* @param {boolean} isInline
|
|
83
|
+
* @returns {Promise<void>}
|
|
84
|
+
*/
|
|
85
|
+
static "__#18619@#workerFilehandler": (handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<any>, listener: (any: any) => void, isInline: boolean) => Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* @type {boolean}
|
|
88
|
+
*/
|
|
89
|
+
static "__#18619@#isBrowser": boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @description
|
|
92
|
+
* - check whether js run in browser
|
|
93
|
+
* @type {boolean}
|
|
94
|
+
*/
|
|
95
|
+
static get isBrowser(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* @description
|
|
98
|
+
* - create Worker_instance;
|
|
99
|
+
* @param {string} handler
|
|
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]
|
|
108
|
+
* @example
|
|
109
|
+
* import { WorkerMainThread } from 'vivth';
|
|
110
|
+
*
|
|
111
|
+
* export const myDoubleWorker = new WorkerMainThread('./doubleWorkerThread.mjs');
|
|
112
|
+
*/
|
|
113
|
+
constructor(handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">, isInline?: boolean);
|
|
114
|
+
/**
|
|
115
|
+
* @description
|
|
116
|
+
* - terminate all signals that are used on this instance;
|
|
117
|
+
* @type {()=>void}
|
|
118
|
+
*/
|
|
119
|
+
terminate: () => void;
|
|
120
|
+
/**
|
|
121
|
+
* @description
|
|
122
|
+
* - result signal of the processed message;
|
|
123
|
+
* @type {Derived<WorkerResult<WT["Post"]>>}
|
|
124
|
+
* @example
|
|
125
|
+
* import { Effect } from 'vivth';
|
|
126
|
+
* import { myDoubleWorker } from './myDoubleWorker.mjs';
|
|
127
|
+
*
|
|
128
|
+
* const doubleReceiverSignal = myDoubleWorker.receiverSignal;
|
|
129
|
+
* new Effect(async({ subscribe }) => {
|
|
130
|
+
* const value = subscribe(doubleReceiverSignal).value;
|
|
131
|
+
* // code
|
|
132
|
+
* })
|
|
133
|
+
*/
|
|
134
|
+
receiverSignal: Derived<WorkerResult<WT["Post"]>>;
|
|
135
|
+
/**
|
|
136
|
+
* @description
|
|
137
|
+
* - callback to send message to the worker thread;
|
|
138
|
+
* @type {(event: WT["Receive"])=>void}
|
|
139
|
+
* @example
|
|
140
|
+
* import { myDoubleWorker } from './myDoubleWorker.mjs';
|
|
141
|
+
*
|
|
142
|
+
* myDoubleWorker.postMessage(90);
|
|
143
|
+
*/
|
|
144
|
+
postMessage: (event: WT["Receive"]) => void;
|
|
145
|
+
#private;
|
|
146
|
+
}
|
|
147
|
+
export type WorkerResult<A> = import("./WorkerResult.mjs").WorkerResult<A>;
|
|
148
|
+
export type WorkerThread = import("./WorkerThread.mjs").WorkerThread<any, any>;
|
|
149
|
+
import { Derived } from './Derived.mjs';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - typeHelper for `Worker` message passing;
|
|
4
|
+
* - uses error as value instead;
|
|
5
|
+
* @template POST
|
|
6
|
+
*/
|
|
7
|
+
export class WorkerResult<POST> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {POST} data
|
|
10
|
+
* @param {Error|string|undefined} error
|
|
11
|
+
*/
|
|
12
|
+
constructor(data: POST, error: Error | string | undefined);
|
|
13
|
+
/**
|
|
14
|
+
* @description
|
|
15
|
+
* - result value;
|
|
16
|
+
* @type {POST}
|
|
17
|
+
*/
|
|
18
|
+
data: POST;
|
|
19
|
+
/**
|
|
20
|
+
* @description
|
|
21
|
+
* - error value;
|
|
22
|
+
* @type {Error|string|undefined}
|
|
23
|
+
*/
|
|
24
|
+
error: Error | string | undefined;
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - class helper for `WorkerThread` creation;
|
|
4
|
+
* @template Receive
|
|
5
|
+
* @template Post
|
|
6
|
+
*/
|
|
7
|
+
export class WorkerThread<Receive, Post> {
|
|
8
|
+
/**
|
|
9
|
+
* @type {{parentPort:()=>Promise<any>}}
|
|
10
|
+
*/
|
|
11
|
+
static "__#16626@#parentPortRef": {
|
|
12
|
+
parentPort: () => Promise<any>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @description
|
|
16
|
+
* - 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;
|
|
21
|
+
* @returns {typeof WorkerThread<Receive_, Post_>}
|
|
22
|
+
* @example
|
|
23
|
+
* import { WorkerThread } from 'vivth';
|
|
24
|
+
*
|
|
25
|
+
* WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
|
|
26
|
+
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
27
|
+
* // you need to call this method;
|
|
28
|
+
*/
|
|
29
|
+
static setup: (parentPortRef: {
|
|
30
|
+
parentPort: () => Promise<any>;
|
|
31
|
+
}) => typeof WorkerThread<Receive_, Post_>;
|
|
32
|
+
/**
|
|
33
|
+
* @param {any} ev
|
|
34
|
+
*/
|
|
35
|
+
static "__#16626@#isCloseWorkerEvent": (ev: any) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @description
|
|
38
|
+
* - instantiate via created class from `setup` static method;
|
|
39
|
+
* @param {WorkerThread["handler"]} handler
|
|
40
|
+
* @example
|
|
41
|
+
* import { MyWorkerThread } from './MyWorkerThread.mjs';
|
|
42
|
+
*
|
|
43
|
+
* const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
44
|
+
* // if(!isLastOnQ) {
|
|
45
|
+
* // return null; // can be used for imperative debouncing;
|
|
46
|
+
* // }
|
|
47
|
+
* return ev = ev \* 2;
|
|
48
|
+
* });
|
|
49
|
+
*/
|
|
50
|
+
constructor(handler: (ev: any, isLastOnQ: boolean) => any);
|
|
51
|
+
/**
|
|
52
|
+
* @description
|
|
53
|
+
* - type helper;
|
|
54
|
+
* @type {(ev: Receive, isLastOnQ:boolean) => Post}
|
|
55
|
+
*/
|
|
56
|
+
handler: (ev: Receive, isLastOnQ: boolean) => Post;
|
|
57
|
+
/**
|
|
58
|
+
* @description
|
|
59
|
+
* - helper type, hold no actual value;
|
|
60
|
+
* @type {Receive}
|
|
61
|
+
*/
|
|
62
|
+
Receive: Receive;
|
|
63
|
+
/**
|
|
64
|
+
* @description
|
|
65
|
+
* - helper type, hold no actual value;
|
|
66
|
+
* @type {Post}
|
|
67
|
+
*/
|
|
68
|
+
Post: Post;
|
|
69
|
+
#private;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function Base64URL(fileString: string, mimeType: string, btoaFunction: (string: string) => string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const unwrapLazy: "vivth:unwrapLazy;";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - class for auto documenting mjs package/project, using jsdoc;
|
|
4
|
+
* - this autodocumenter uses [chokidar](https://npmjs.com/package/chokidar) under the hood;
|
|
5
|
+
* - this class also is used to generate this `README.md`;
|
|
6
|
+
* - behaviours:
|
|
7
|
+
* >1) export all named exported 'const'|'function'|'async function'|'class', alphanumeric name, started with Capital letter, same name with fileName on `options.pahts.file`;
|
|
8
|
+
* >2) declare typedef of existing typedef with alphanumeric name, started with Capital letter, same name with fileName, and have no valid export like on point <sup>1</sup> on `options.pahts.file`;
|
|
9
|
+
* >3) create `README.md` based on, `options.paths.dir` and `README.src.md`;
|
|
10
|
+
* >4) extract `"at"description` jsdoc:
|
|
11
|
+
* >>- on static/prop that have depths, all of children should have `"at"static`/`"at"instance` `nameOfImmediateParent`, same block but before `"at"description` comment line;
|
|
12
|
+
* >>- `"at"description` are treated as plain `markdown`;
|
|
13
|
+
* >>- first `"at"${string}` after `"at"description` until `"at"example` will be treated as `javascript` comment block on the `markdown`;
|
|
14
|
+
* >>- `"at"example` are treated as `javascript` block on the `markdown` file, and should be placed last on the same comment block;
|
|
15
|
+
* >>- you can always look at `vivth/src` files to check how the source, and the `README.md` and `index.mjs` is documentation/generation results;
|
|
16
|
+
*/
|
|
17
|
+
export class JSautoDOC {
|
|
18
|
+
/**
|
|
19
|
+
* @type {JSautoDOC}
|
|
20
|
+
*/
|
|
21
|
+
static "__#17292@#instance": JSautoDOC;
|
|
22
|
+
/**
|
|
23
|
+
* @description
|
|
24
|
+
* @param {Object} [options]
|
|
25
|
+
* @param {Object} [options.paths]
|
|
26
|
+
* @param {string} [options.paths.file]
|
|
27
|
+
* - entry point;
|
|
28
|
+
* @param {string} [options.paths.readMe]
|
|
29
|
+
* - readme target;
|
|
30
|
+
* @param {string} [options.paths.dir]
|
|
31
|
+
* - source directory;
|
|
32
|
+
* @param {string} [options.copyright]
|
|
33
|
+
* @param {string} [options.tableOfContentTitle]
|
|
34
|
+
* @param {import('chokidar').ChokidarOptions} [options.option]
|
|
35
|
+
* - ChokidarOptions;
|
|
36
|
+
* @example
|
|
37
|
+
* import { Console } from '../src/class/Console.mjs';
|
|
38
|
+
* import { Setup } from '../src/class/Setup.mjs';
|
|
39
|
+
* import { JSautoDOC } from '../src/doc/JSautoDOC.mjs';
|
|
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({
|
|
58
|
+
* paths: { dir: 'src', file: 'index.mjs', readMe: 'README.md' },
|
|
59
|
+
* copyright: 'this library is made and distributed under MIT license;',
|
|
60
|
+
* tableOfContentTitle: 'list of exported API and typehelpers',
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
constructor({ paths, tableOfContentTitle, copyright, option, }?: {
|
|
65
|
+
paths?: {
|
|
66
|
+
file?: string;
|
|
67
|
+
readMe?: string;
|
|
68
|
+
dir?: string;
|
|
69
|
+
};
|
|
70
|
+
copyright?: string;
|
|
71
|
+
tableOfContentTitle?: string;
|
|
72
|
+
option?: import("chokidar").ChokidarOptions;
|
|
73
|
+
});
|
|
74
|
+
#private;
|
|
75
|
+
}
|
|
76
|
+
export type Stats = import("fs").Stats;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export class parsedFile {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} exportName
|
|
4
|
+
* @returns {boolean}
|
|
5
|
+
*/
|
|
6
|
+
static "__#12@#isExportNameValid": (exportName: string) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} content
|
|
9
|
+
* @returns { RegExpExecArray[] }
|
|
10
|
+
*/
|
|
11
|
+
static getDescription: (content: string) => RegExpExecArray[];
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* instanceOrStatic:{parent:string, type:string},
|
|
15
|
+
* fullDescription:string,
|
|
16
|
+
* parsedFullDescription:{description:string, jsPreview:string},
|
|
17
|
+
* isExport:boolean,
|
|
18
|
+
* typeOfVar:string,
|
|
19
|
+
* namedVar:string,
|
|
20
|
+
* reference:string,
|
|
21
|
+
* }} refType
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} path__
|
|
25
|
+
* @param {BufferEncoding} [encoding]
|
|
26
|
+
*/
|
|
27
|
+
constructor(path__: string, encoding?: BufferEncoding);
|
|
28
|
+
documented: {
|
|
29
|
+
typedef: () => Promise<{
|
|
30
|
+
module: string;
|
|
31
|
+
readme: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* @type {Set<refType>}
|
|
35
|
+
*/
|
|
36
|
+
readme: Set<{
|
|
37
|
+
instanceOrStatic: {
|
|
38
|
+
parent: string;
|
|
39
|
+
type: string;
|
|
40
|
+
};
|
|
41
|
+
fullDescription: string;
|
|
42
|
+
parsedFullDescription: {
|
|
43
|
+
description: string;
|
|
44
|
+
jsPreview: string;
|
|
45
|
+
};
|
|
46
|
+
isExport: boolean;
|
|
47
|
+
typeOfVar: string;
|
|
48
|
+
namedVar: string;
|
|
49
|
+
reference: string;
|
|
50
|
+
}>;
|
|
51
|
+
} & {
|
|
52
|
+
"vivth:unwrapLazy;": string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* @type {undefined|{module:string, readme:string}}
|
|
56
|
+
*/
|
|
57
|
+
parsedType: undefined | {
|
|
58
|
+
module: string;
|
|
59
|
+
readme: string;
|
|
60
|
+
};
|
|
61
|
+
hasValidExportObject: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* @returns {Promise<boolean>}
|
|
64
|
+
*/
|
|
65
|
+
isFile: () => Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* @returns {Promise<boolean>}
|
|
68
|
+
*/
|
|
69
|
+
isDirectory: () => Promise<boolean>;
|
|
70
|
+
baseName: {
|
|
71
|
+
/**
|
|
72
|
+
* @type {string}
|
|
73
|
+
*/
|
|
74
|
+
readonly withExt: string;
|
|
75
|
+
/**
|
|
76
|
+
* @type {string}
|
|
77
|
+
*/
|
|
78
|
+
readonly noExt: string;
|
|
79
|
+
} & {
|
|
80
|
+
"vivth:unwrapLazy;": string;
|
|
81
|
+
};
|
|
82
|
+
path: {
|
|
83
|
+
/**
|
|
84
|
+
* @type {string}
|
|
85
|
+
*/
|
|
86
|
+
readonly relative: string;
|
|
87
|
+
/**
|
|
88
|
+
* @type {string}
|
|
89
|
+
*/
|
|
90
|
+
readonly full: string;
|
|
91
|
+
} & {
|
|
92
|
+
"vivth:unwrapLazy;": string;
|
|
93
|
+
};
|
|
94
|
+
get dirName(): {
|
|
95
|
+
/**
|
|
96
|
+
* @type {string}
|
|
97
|
+
*/
|
|
98
|
+
readonly relative: string;
|
|
99
|
+
/**
|
|
100
|
+
* @type {string}
|
|
101
|
+
*/
|
|
102
|
+
readonly full: string;
|
|
103
|
+
};
|
|
104
|
+
get ext(): {
|
|
105
|
+
/**
|
|
106
|
+
* @type {string|undefined}
|
|
107
|
+
*/
|
|
108
|
+
readonly withDot: string | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* @type {string|undefined}
|
|
111
|
+
*/
|
|
112
|
+
readonly noDot: string | undefined;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* @private
|
|
116
|
+
* @returns {Promise<Stats>}
|
|
117
|
+
*/
|
|
118
|
+
private stats;
|
|
119
|
+
get timeStamp(): {
|
|
120
|
+
/**
|
|
121
|
+
* @returns {Promise<number>}
|
|
122
|
+
*/
|
|
123
|
+
lastModified: () => Promise<number>;
|
|
124
|
+
/**
|
|
125
|
+
* @returns {Promise<number>}
|
|
126
|
+
*/
|
|
127
|
+
createdAt: () => Promise<number>;
|
|
128
|
+
};
|
|
129
|
+
content: {
|
|
130
|
+
/**
|
|
131
|
+
* @return {Promise<string|undefined>}
|
|
132
|
+
*/
|
|
133
|
+
string: () => Promise<string | undefined>;
|
|
134
|
+
parsed: () => Promise<{
|
|
135
|
+
exportName: undefined;
|
|
136
|
+
details: undefined;
|
|
137
|
+
error: {
|
|
138
|
+
fullpath: string;
|
|
139
|
+
message: string;
|
|
140
|
+
};
|
|
141
|
+
} | {
|
|
142
|
+
exportName: string | undefined;
|
|
143
|
+
details: ReturnType<(typeof parsedFile)["getDescription"]>;
|
|
144
|
+
error: undefined;
|
|
145
|
+
}>;
|
|
146
|
+
} & {
|
|
147
|
+
"vivth:unwrapLazy;": string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* @type {[Promise<any>, undefined]|[undefined, Error]}
|
|
151
|
+
*/
|
|
152
|
+
get importAsModuleJS(): [Promise<any>, undefined] | [undefined, Error];
|
|
153
|
+
#private;
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function IsAsync(functionReference: (...any: any) => (any | Promise<any>)): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function Timeout(timeMS: number): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function Try<Key extends string, ReturnType_, RecordTryType extends Record<Key, () => Promise<ReturnType_>>>(tryRecord: RecordTryType): Promise<[[keyof RecordTryType, ReturnType_], undefined] | [[undefined, undefined], Error]>;
|