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
|
@@ -25,6 +25,7 @@ export class parsedFile {
|
|
|
25
25
|
* @param {BufferEncoding} [encoding]
|
|
26
26
|
*/
|
|
27
27
|
constructor(path__: string, encoding?: BufferEncoding);
|
|
28
|
+
parse: () => Promise<void>;
|
|
28
29
|
documented: {
|
|
29
30
|
typedef: () => Promise<{
|
|
30
31
|
module: string;
|
|
@@ -49,7 +50,30 @@ export class parsedFile {
|
|
|
49
50
|
reference: string;
|
|
50
51
|
}>;
|
|
51
52
|
} & {
|
|
52
|
-
"vivth:unwrapLazy;":
|
|
53
|
+
"vivth:unwrapLazy;": () => {
|
|
54
|
+
typedef: () => Promise<{
|
|
55
|
+
module: string;
|
|
56
|
+
readme: string;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* @type {Set<refType>}
|
|
60
|
+
*/
|
|
61
|
+
readme: Set<{
|
|
62
|
+
instanceOrStatic: {
|
|
63
|
+
parent: string;
|
|
64
|
+
type: string;
|
|
65
|
+
};
|
|
66
|
+
fullDescription: string;
|
|
67
|
+
parsedFullDescription: {
|
|
68
|
+
description: string;
|
|
69
|
+
jsPreview: string;
|
|
70
|
+
};
|
|
71
|
+
isExport: boolean;
|
|
72
|
+
typeOfVar: string;
|
|
73
|
+
namedVar: string;
|
|
74
|
+
reference: string;
|
|
75
|
+
}>;
|
|
76
|
+
};
|
|
53
77
|
};
|
|
54
78
|
/**
|
|
55
79
|
* @type {undefined|{module:string, readme:string}}
|
|
@@ -69,45 +93,63 @@ export class parsedFile {
|
|
|
69
93
|
isDirectory: () => Promise<boolean>;
|
|
70
94
|
baseName: {
|
|
71
95
|
/**
|
|
72
|
-
* @
|
|
96
|
+
* @returns {string}
|
|
73
97
|
*/
|
|
74
98
|
readonly withExt: string;
|
|
75
99
|
/**
|
|
76
|
-
* @
|
|
100
|
+
* @returns {string}
|
|
77
101
|
*/
|
|
78
102
|
readonly noExt: string;
|
|
79
103
|
} & {
|
|
80
|
-
"vivth:unwrapLazy;":
|
|
104
|
+
"vivth:unwrapLazy;": () => {
|
|
105
|
+
/**
|
|
106
|
+
* @returns {string}
|
|
107
|
+
*/
|
|
108
|
+
readonly withExt: string;
|
|
109
|
+
/**
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
readonly noExt: string;
|
|
113
|
+
};
|
|
81
114
|
};
|
|
82
115
|
path: {
|
|
83
116
|
/**
|
|
84
|
-
* @
|
|
117
|
+
* @returns {string}
|
|
85
118
|
*/
|
|
86
119
|
readonly relative: string;
|
|
87
120
|
/**
|
|
88
|
-
* @
|
|
121
|
+
* @returns {string}
|
|
89
122
|
*/
|
|
90
123
|
readonly full: string;
|
|
91
124
|
} & {
|
|
92
|
-
"vivth:unwrapLazy;":
|
|
125
|
+
"vivth:unwrapLazy;": () => {
|
|
126
|
+
/**
|
|
127
|
+
* @returns {string}
|
|
128
|
+
*/
|
|
129
|
+
readonly relative: string;
|
|
130
|
+
/**
|
|
131
|
+
* @returns {string}
|
|
132
|
+
*/
|
|
133
|
+
readonly full: string;
|
|
134
|
+
};
|
|
93
135
|
};
|
|
94
136
|
get dirName(): {
|
|
95
137
|
/**
|
|
96
|
-
* @
|
|
138
|
+
* @returns {string}
|
|
97
139
|
*/
|
|
98
140
|
readonly relative: string;
|
|
99
141
|
/**
|
|
100
|
-
* @
|
|
142
|
+
* @returns {string}
|
|
101
143
|
*/
|
|
102
144
|
readonly full: string;
|
|
103
145
|
};
|
|
104
146
|
get ext(): {
|
|
105
147
|
/**
|
|
106
|
-
* @
|
|
148
|
+
* @returns {string|undefined}
|
|
107
149
|
*/
|
|
108
150
|
readonly withDot: string | undefined;
|
|
109
151
|
/**
|
|
110
|
-
* @
|
|
152
|
+
* @returns {string|undefined}
|
|
111
153
|
*/
|
|
112
154
|
readonly noDot: string | undefined;
|
|
113
155
|
};
|
|
@@ -144,10 +186,27 @@ export class parsedFile {
|
|
|
144
186
|
error: undefined;
|
|
145
187
|
}>;
|
|
146
188
|
} & {
|
|
147
|
-
"vivth:unwrapLazy;":
|
|
189
|
+
"vivth:unwrapLazy;": () => {
|
|
190
|
+
/**
|
|
191
|
+
* @return {Promise<string|undefined>}
|
|
192
|
+
*/
|
|
193
|
+
string: () => Promise<string | undefined>;
|
|
194
|
+
parsed: () => Promise<{
|
|
195
|
+
exportName: undefined;
|
|
196
|
+
details: undefined;
|
|
197
|
+
error: {
|
|
198
|
+
fullpath: string;
|
|
199
|
+
message: string;
|
|
200
|
+
};
|
|
201
|
+
} | {
|
|
202
|
+
exportName: string | undefined;
|
|
203
|
+
details: ReturnType<(typeof parsedFile)["getDescription"]>;
|
|
204
|
+
error: undefined;
|
|
205
|
+
}>;
|
|
206
|
+
};
|
|
148
207
|
};
|
|
149
208
|
/**
|
|
150
|
-
* @
|
|
209
|
+
* @returns {[Promise<any>, undefined]|[undefined, Error]}
|
|
151
210
|
*/
|
|
152
211
|
get importAsModuleJS(): [Promise<any>, undefined] | [undefined, Error];
|
|
153
212
|
#private;
|
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function for create immutable object;
|
|
4
|
+
* - usefull for binding immutable object to global for shared object:
|
|
5
|
+
* >- e.g. to window object in browser;
|
|
6
|
+
* @template {Object} PARENT
|
|
7
|
+
* @template {Object} OBJECT
|
|
8
|
+
* @param {string} keyName
|
|
9
|
+
* @param {PARENT} parent
|
|
10
|
+
* @param {(this:PARENT)=>OBJECT} object
|
|
11
|
+
* @param {Object} [options]
|
|
12
|
+
* @param {boolean} [options.lazy]
|
|
13
|
+
* @return {OBJECT}
|
|
14
|
+
* @example
|
|
15
|
+
* import { CreateImmutable } from 'vivth';
|
|
16
|
+
*
|
|
17
|
+
* const mappedObject = new Map();
|
|
18
|
+
*
|
|
19
|
+
* CreateImmutable(window, 'mySharedObject', {
|
|
20
|
+
* setMap(name_, value) => {
|
|
21
|
+
* mappedObject.set(name_, value)
|
|
22
|
+
* },
|
|
23
|
+
* getMap(name_) => mappedObject.get(name_),
|
|
24
|
+
* })
|
|
25
|
+
*/
|
|
26
|
+
export function CreateImmutable<PARENT extends unknown, OBJECT extends unknown>(parent: PARENT, keyName: string, object: (this: PARENT) => OBJECT, { lazy }?: {
|
|
2
27
|
lazy?: boolean;
|
|
3
|
-
}):
|
|
28
|
+
}): OBJECT;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - simple validation function for [EventObject](#eventobject), for multiple context, eg: `mainThread` <-> `workerThread`;
|
|
4
|
+
* @param {any} object
|
|
5
|
+
* @param {Record<typeof EventNameSpace, string>} eventObject
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
* @example
|
|
8
|
+
* import { EventCheck } from 'vivth';
|
|
9
|
+
* import { incomingMessage } from './some/where.mjs';
|
|
10
|
+
*
|
|
11
|
+
* const eventObjectPayload = EventObject('worker:exit');
|
|
12
|
+
* // assuming `incomingMessage`, also created using EventObject('worker:exit');
|
|
13
|
+
* // or manually {[EventNameSpace]:'worker:exit'};
|
|
14
|
+
* // which either will result true;
|
|
15
|
+
*/
|
|
1
16
|
export function EventCheck(object: any, eventObject: Record<typeof EventNameSpace, string>): boolean;
|
|
2
17
|
import { EventNameSpace } from '../common/EventNameSpace.mjs';
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - simple object generation function helper for [EventCheck](#eventcheck), for multiple context, eg: `mainThread` <-> `workerThread`;
|
|
4
|
+
* @template {string} NAME
|
|
5
|
+
* @param {NAME} name
|
|
6
|
+
* @returns {{[EventNameSpace]: NAME}}
|
|
7
|
+
* @example
|
|
8
|
+
* import { EventCheck } from 'vivth';
|
|
9
|
+
* import { incomingMessage } from './some/where.mjs';
|
|
10
|
+
*
|
|
11
|
+
* const eventObjectPayload = EventObject('worker:exit');
|
|
12
|
+
* // assuming `incomingMessage`, also created using EventObject('worker:exit');
|
|
13
|
+
* // or manually {[EventNameSpace]:'worker:exit'};
|
|
14
|
+
* // which either will result true;
|
|
15
|
+
*/
|
|
16
|
+
export function EventObject<NAME extends string>(name: NAME): {
|
|
17
|
+
[EventNameSpace]: NAME;
|
|
3
18
|
};
|
|
4
19
|
import { EventNameSpace } from '../common/EventNameSpace.mjs';
|
|
@@ -1 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function helper for checking whether `functionReference` is async;
|
|
4
|
+
* @param {(...any:any)=>(any|Promise<any>)} functionReference
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
* @example
|
|
7
|
+
* import { IsAsync } from 'vivth';
|
|
8
|
+
*
|
|
9
|
+
* const a = function (params) {
|
|
10
|
+
* // code
|
|
11
|
+
* }
|
|
12
|
+
* const b = async () => {
|
|
13
|
+
* // code
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* IsAsync(a); // false
|
|
17
|
+
* IsAsync(b); // true
|
|
18
|
+
*/
|
|
1
19
|
export function IsAsync(functionReference: (...any: any) => (any | Promise<any>)): boolean;
|
|
@@ -1,4 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function helper for creating lazyObject:
|
|
4
|
+
* >- usefull for lazily instantiating an object, since instance naturally have props/methods;
|
|
5
|
+
* @template FACTORY
|
|
6
|
+
* @param {() => FACTORY} factory
|
|
7
|
+
* @returns {FACTORY & {[unwrapLazy]: ()=> FACTORY}}
|
|
8
|
+
* - the unwrapLazy prop can be accessed to force instatiation/call;
|
|
9
|
+
* >- `unwrapLazy` prop name can be checked by checking the list of possible prop, from your ide;
|
|
10
|
+
* >- as of version `1.0.0`, value is `vivth:unwrapLazy;`;
|
|
11
|
+
* @example
|
|
12
|
+
* import { LazyFactory } from 'vivth';
|
|
13
|
+
*
|
|
14
|
+
* class MyClass{
|
|
15
|
+
* constructor() {
|
|
16
|
+
* this.myProp = 1; // will only available when accessed;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* export const myInstance = LazyFactory(() => {
|
|
21
|
+
* // the instance of MyClass will only be available when,
|
|
22
|
+
* // it's prop, or method is accessed/reassign;
|
|
23
|
+
* return new MyClass();
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // on other file
|
|
27
|
+
* import { myInstance } from './myInstance.mjs';
|
|
28
|
+
*
|
|
29
|
+
* const a = myInstance; // not yet initiated;
|
|
30
|
+
* const b = a.myProp // imediately initiated;
|
|
31
|
+
* // OR
|
|
32
|
+
* myInstance["vivth:unwrapLazy;"]() // forcefully call the callback;
|
|
33
|
+
*/
|
|
34
|
+
export function LazyFactory<FACTORY>(factory: () => FACTORY): FACTORY & {
|
|
35
|
+
[unwrapLazy]: () => FACTORY;
|
|
3
36
|
};
|
|
4
37
|
import { unwrapLazy } from '../common/lazie.mjs';
|
|
@@ -1 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function helper to temporarily block the code in async context;
|
|
4
|
+
* @param {number} timeMS
|
|
5
|
+
* - in miliseconds;
|
|
6
|
+
* @returns {Promise<void>}
|
|
7
|
+
* @example
|
|
8
|
+
* import { Timeout } from 'vivth';
|
|
9
|
+
*
|
|
10
|
+
* const test = async () => {
|
|
11
|
+
* // code0
|
|
12
|
+
* await Timeout(1000);
|
|
13
|
+
* // code1
|
|
14
|
+
* }
|
|
15
|
+
* test();
|
|
16
|
+
*/
|
|
1
17
|
export function Timeout(timeMS: number): Promise<void>;
|
|
@@ -1 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function for error as value for chained operations;
|
|
4
|
+
* - utility function to brute force which key is able to run;
|
|
5
|
+
* - usefull to flatten indentation for error handlings;
|
|
6
|
+
* - caveat:
|
|
7
|
+
* >- run in sequence, awaiting each key bofore running next key;
|
|
8
|
+
* @template {string} KEY
|
|
9
|
+
* @template RETURNTYPE
|
|
10
|
+
* @template {Record<
|
|
11
|
+
* KEY,
|
|
12
|
+
* (err:{prevError:undefined|Error}) => Promise<RETURNTYPE>
|
|
13
|
+
* >} RecordTryType
|
|
14
|
+
* @param {RecordTryType} tryRecord
|
|
15
|
+
* @returns {Promise<
|
|
16
|
+
* [[keyof RecordTryType, RETURNTYPE], undefined]
|
|
17
|
+
* | [[undefined, undefined], Error]
|
|
18
|
+
* >}
|
|
19
|
+
* @example
|
|
20
|
+
* import { Try } from 'vivth';
|
|
21
|
+
*
|
|
22
|
+
* const [[key, result], error] = await Try({
|
|
23
|
+
* someRuntime: async ( prevError ) => {
|
|
24
|
+
* // asuming on this one doesn't naturally throw error,
|
|
25
|
+
* // yet you need to continue to next key,
|
|
26
|
+
* // instead of returning,
|
|
27
|
+
* // you should throw new Error(something);
|
|
28
|
+
* },
|
|
29
|
+
* browser: async ( prevError ) => {
|
|
30
|
+
* return location?.origin;
|
|
31
|
+
* // if no error, stop other key function from running;
|
|
32
|
+
* // key = 'browser'
|
|
33
|
+
* // result = location?.origin;
|
|
34
|
+
* // error = undefined;
|
|
35
|
+
* // if error;
|
|
36
|
+
* // run nodeOrBun;
|
|
37
|
+
* },
|
|
38
|
+
* nodeOrBun: async ( prevError ) => {
|
|
39
|
+
* return process?.env?.INIT_CWD ?? process?.cwd();
|
|
40
|
+
* // if no error;
|
|
41
|
+
* // key = 'nodeOrBun'
|
|
42
|
+
* // result = process?.env?.INIT_CWD ?? process?.cwd();
|
|
43
|
+
* // if error;
|
|
44
|
+
* // key = undefined;
|
|
45
|
+
* // result = undefined;
|
|
46
|
+
* // error = new Error('unable to run any key');
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
*/
|
|
50
|
+
export function Try<KEY extends string, RETURNTYPE, RecordTryType extends Record<KEY, (err: {
|
|
51
|
+
prevError: undefined | Error;
|
|
52
|
+
}) => Promise<RETURNTYPE>>>(tryRecord: RecordTryType): Promise<[[keyof RecordTryType, RETURNTYPE], undefined] | [[undefined, undefined], Error]>;
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function for error as value for asynchronous operation;
|
|
4
|
+
* - usefull to flatten indentation for error handlings;
|
|
5
|
+
* @template RESULT
|
|
6
|
+
* @param {()=>Promise<RESULT>} asyncFunction_
|
|
7
|
+
* @returns {Promise<[RESULT|undefined, Error|undefined]>}
|
|
8
|
+
* @example
|
|
9
|
+
* import { TryAsync } from 'vivth';
|
|
10
|
+
*
|
|
11
|
+
* let [res, error] = await TryAsync(async () => {
|
|
12
|
+
* return await fetch('./someAPI/Path');
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* [res, error] = await TryAsync(async () => {
|
|
16
|
+
* if(!res.ok) {
|
|
17
|
+
* throw new Error(404);
|
|
18
|
+
* }
|
|
19
|
+
* return await res.json();
|
|
20
|
+
* })
|
|
21
|
+
*/
|
|
22
|
+
export function TryAsync<RESULT>(asyncFunction_: () => Promise<RESULT>): Promise<[RESULT | undefined, Error | undefined]>;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function for error as value for synchronous operation;
|
|
4
|
+
* - usefull to flatten indentation for error handlings;
|
|
5
|
+
* @template RESULT
|
|
6
|
+
* @param {()=>RESULT} function_
|
|
7
|
+
* @returns {[RESULT|undefined, Error|undefined]}
|
|
8
|
+
* @example
|
|
9
|
+
* import { readFileSync } from 'fs';
|
|
10
|
+
* import { TrySync } from './yourModule.js';
|
|
11
|
+
*
|
|
12
|
+
* const [data, error] = TrySync(() => {
|
|
13
|
+
* return readFileSync('./some/file.txt', 'utf-8');
|
|
14
|
+
* });
|
|
15
|
+
*/
|
|
16
|
+
export function TrySync<RESULT>(function_: () => RESULT): [RESULT | undefined, Error | undefined];
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - turn `.mts`||`.ts` file into `.mjs`, no bundling, just translation;
|
|
4
|
+
* - on certain circumstance where `.mjs` result needed to be typed, you need to manually add `jsdoc`;
|
|
5
|
+
* >- uses `"at"preserve` to register `jsdoc` inline;
|
|
6
|
+
* @param {string} path_
|
|
7
|
+
* - path from `Paths.root`;
|
|
8
|
+
* @param {Object} [options]
|
|
9
|
+
* @param {string} [options.overrideDir]
|
|
10
|
+
* - default: write conversion to same directory;
|
|
11
|
+
* - path are relative to project root;
|
|
12
|
+
* @param {BufferEncoding} [options.encoding]
|
|
13
|
+
* - default: `utf-8`;
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
* @example
|
|
16
|
+
* import { TsToMjs } from 'vivth';
|
|
17
|
+
*
|
|
18
|
+
* TsToMjs('./myFile.mts', { encoding: 'utf-8', overrideDir: './other/dir' });
|
|
19
|
+
*/
|
|
1
20
|
export function TsToMjs(path_: string, { overrideDir, encoding }?: {
|
|
2
21
|
overrideDir?: string;
|
|
3
22
|
encoding?: BufferEncoding;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type LitExpKeyType = Record<string, RegExp | false>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Runtime = "node" | "bun" | "deno" | "browser" | "unknown";
|
package/dev/index.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { Console } from '../src/class/Console.mjs';
|
|
4
|
-
import { Setup } from '../src/class/Setup.mjs';
|
|
5
|
-
import { JSautoDOC } from '../src/doc/JSautoDOC.mjs';
|
|
6
|
-
|
|
7
|
-
const { paths, safeExit } = Setup;
|
|
8
|
-
|
|
9
|
-
new paths({
|
|
10
|
-
root: process?.env?.INIT_CWD ?? process?.cwd(),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
new safeExit({
|
|
14
|
-
eventNames: ['SIGINT', 'SIGTERM', 'exit'],
|
|
15
|
-
terminator: () => process.exit(0),
|
|
16
|
-
listener: (eventName) => {
|
|
17
|
-
process.once(eventName, function () {
|
|
18
|
-
safeExit.instance.exiting.correction(true);
|
|
19
|
-
Console.log(`safe exit via "${eventName}"`);
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
new JSautoDOC({
|
|
25
|
-
paths: { dir: 'src', file: 'index.mjs', readMe: 'README.md' },
|
|
26
|
-
copyright: 'this library is made and distributed under MIT license;',
|
|
27
|
-
tableOfContentTitle: 'list of exported API and typehelpers',
|
|
28
|
-
});
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import { join, extname } from 'node:path';
|
|
5
|
-
|
|
6
|
-
import { Paths } from '../class/Paths.mjs';
|
|
7
|
-
import { EsBundler } from './EsBundler.mjs';
|
|
8
|
-
import { Console } from '../class/Console.mjs';
|
|
9
|
-
import { WriteFileSafe } from '../function/WriteFileSafe.mjs';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @description
|
|
13
|
-
* - function to bundle to single mjs file, including the workerThread;
|
|
14
|
-
* @param {Object} options
|
|
15
|
-
* @param {string} options.entryPoint
|
|
16
|
-
* @param {string} options.outputNoExt
|
|
17
|
-
* - no extention needed, result will always be '.mjs';
|
|
18
|
-
* @param {BufferEncoding} options.encoding
|
|
19
|
-
* @param {boolean} [options.minify]
|
|
20
|
-
* - default false;
|
|
21
|
-
* @param {boolean} [options.asBinary]
|
|
22
|
-
* - default false;
|
|
23
|
-
* @returns {Promise<ReturnType<typeof WriteFileSafe>>}
|
|
24
|
-
* @example
|
|
25
|
-
* import { Paths, CompileMJS } from 'vivth';
|
|
26
|
-
*
|
|
27
|
-
* new Paths({
|
|
28
|
-
* root: process?.env?.INIT_CWD ?? process?.cwd(),
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* CompileMJS({
|
|
32
|
-
* entryPoint: '/index.mjs',
|
|
33
|
-
* encoding: 'utf-8',
|
|
34
|
-
* outputNoExt: '/test/compiled',
|
|
35
|
-
* minify: false,
|
|
36
|
-
* asBinary: true,
|
|
37
|
-
* });
|
|
38
|
-
*/
|
|
39
|
-
export const CompileMJS = async ({
|
|
40
|
-
entryPoint,
|
|
41
|
-
encoding,
|
|
42
|
-
outputNoExt,
|
|
43
|
-
minify = false,
|
|
44
|
-
asBinary = false,
|
|
45
|
-
}) => {
|
|
46
|
-
const rootPath = Paths.root;
|
|
47
|
-
const fullpathEntry = join(rootPath, entryPoint);
|
|
48
|
-
const fulloutput = join(rootPath, `${outputNoExt}.mjs`);
|
|
49
|
-
const mainext = extname(fullpathEntry);
|
|
50
|
-
const [content, error] = await EsBundler(
|
|
51
|
-
{
|
|
52
|
-
content: await readFile(fullpathEntry, { encoding }),
|
|
53
|
-
extension: mainext,
|
|
54
|
-
asBinary: false,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
minify: false,
|
|
58
|
-
keepNames: true,
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
if (error) {
|
|
62
|
-
Console.error(error);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
let strippedComment = content.replace(/\/\*\*[\s\S]*?\*\//gm, '');
|
|
66
|
-
const workersMatched = strippedComment
|
|
67
|
-
.matchAll(
|
|
68
|
-
/new\s(WorkerMainThread\w*?)\(['"]([\s\S]*?\.worker\.[\s\S]*?)['"][\s\S]*?(?:{([\s\S]*?)}|)[\s\S]*?\)/gm
|
|
69
|
-
)
|
|
70
|
-
.toArray();
|
|
71
|
-
/**
|
|
72
|
-
* @type {Set<string>}
|
|
73
|
-
*/
|
|
74
|
-
const fileNames = new Set();
|
|
75
|
-
for (const [string, className, path_, options] of workersMatched) {
|
|
76
|
-
fileNames.add(path_);
|
|
77
|
-
const newComment = `new ${className}(vivthWorkerFilesObject["${path_}"], {${
|
|
78
|
-
options ?? ''
|
|
79
|
-
}}, true)`;
|
|
80
|
-
strippedComment = strippedComment.replace(string, newComment);
|
|
81
|
-
}
|
|
82
|
-
const vivthWorkerFilesObject = {};
|
|
83
|
-
for await (const path_ of fileNames) {
|
|
84
|
-
const workerFullPath = join(rootPath, path_);
|
|
85
|
-
const content = await readFile(workerFullPath, { encoding });
|
|
86
|
-
const [bundle, _] = await EsBundler(
|
|
87
|
-
{
|
|
88
|
-
content,
|
|
89
|
-
extension: extname(workerFullPath),
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
minify: true,
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
vivthWorkerFilesObject[path_] = bundle;
|
|
96
|
-
}
|
|
97
|
-
const [finalContent] = await EsBundler(
|
|
98
|
-
{
|
|
99
|
-
content: `const vivthWorkerFilesObject = ${JSON.stringify(
|
|
100
|
-
vivthWorkerFilesObject
|
|
101
|
-
)};\n${strippedComment}`,
|
|
102
|
-
extension: mainext,
|
|
103
|
-
asBinary,
|
|
104
|
-
},
|
|
105
|
-
{ minify }
|
|
106
|
-
);
|
|
107
|
-
return await WriteFileSafe(fulloutput, finalContent, {
|
|
108
|
-
encoding,
|
|
109
|
-
});
|
|
110
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { writeFile, mkdir } from 'node:fs/promises';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
|
|
6
|
-
import { TryAsync } from './TryAsync.mjs';
|
|
7
|
-
import { Paths } from '../class/Paths.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description
|
|
11
|
-
* - function to create file by recursively mkdir the dirname of the outFile;
|
|
12
|
-
* - also returing promise of result & error as value;
|
|
13
|
-
* @param {string} outFile
|
|
14
|
-
* @param {string} content
|
|
15
|
-
* @param {import('node:fs').WriteFileOptions} options
|
|
16
|
-
* @returns {Promise<ReturnType<typeof TryAsync<void>>>}
|
|
17
|
-
* @example
|
|
18
|
-
* import { WriteFileSafe } from 'vivth';
|
|
19
|
-
*
|
|
20
|
-
* const [_, writeError] = await TryAsync(async () => {
|
|
21
|
-
* return await WriteFileSafe(
|
|
22
|
-
* '/some/path.mjs',
|
|
23
|
-
* 'console.log("hello-world!!");',
|
|
24
|
-
* { encoding: 'utf-8' }
|
|
25
|
-
* );
|
|
26
|
-
* });
|
|
27
|
-
*/
|
|
28
|
-
export const WriteFileSafe = async (outFile, content, options) => {
|
|
29
|
-
return await TryAsync(async () => {
|
|
30
|
-
const rootPath = Paths.normalize(Paths.root);
|
|
31
|
-
if (!Paths.normalize(outFile).startsWith(rootPath)) {
|
|
32
|
-
outFile = join(rootPath, outFile);
|
|
33
|
-
}
|
|
34
|
-
await mkdir(dirname(outFile), { recursive: true });
|
|
35
|
-
return writeFile(outFile, content, options);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function A(entryPoint: string, encoding: BufferEncoding, output: string, minify?: boolean): Promise<void>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export function CompileMJS({ entryPoint, encoding, outputNoExt, minify, asBinary, }: {
|
|
2
|
-
entryPoint: string;
|
|
3
|
-
outputNoExt: string;
|
|
4
|
-
encoding: BufferEncoding;
|
|
5
|
-
minify?: boolean;
|
|
6
|
-
asBinary?: boolean;
|
|
7
|
-
}): Promise<ReturnType<typeof WriteFileSafe>>;
|
|
8
|
-
import { WriteFileSafe } from '../function/WriteFileSafe.mjs';
|