vivth 1.1.2 → 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 +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
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - class helper to created opionated regex helper;
|
|
4
|
+
* - named capture uses `es6+` feature, you might need to add polyfill to target extremely old browser;
|
|
5
|
+
* - class name refer to `Literal Expression`;
|
|
6
|
+
* - please be patient when using this class;
|
|
7
|
+
* >- destructuring is meant for extensive typehelper;
|
|
8
|
+
* >- and destructuring can lead to unhandled error here and there;
|
|
9
|
+
* >- therefore error as value is introduced to help to prevent error on runtime;
|
|
10
|
+
* @template {LitExpKeyType} KEYS
|
|
11
|
+
*/
|
|
12
|
+
export class LitExp<KEYS extends import("../types/LitExpKeyType.mjs").LitExpKeyType> {
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import("../types/LitExpKeyType.mjs").LitExpKeyType} LitExpKeyType
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @description
|
|
18
|
+
* - constructor helper;
|
|
19
|
+
* - under the hood it is an abstraction of `RegExp`, with more template literal touch;
|
|
20
|
+
* >- you can apply inline `RegExp` features on the string template literal(as constructor RegExp arg0);
|
|
21
|
+
* >>- by doing so you are opting in to make:
|
|
22
|
+
* >>>- your regex detection more robust; but
|
|
23
|
+
* >>>- `litExp_instance.make.string` to be `unusable`;
|
|
24
|
+
* >>- also mind the needs of escape for special characters;
|
|
25
|
+
* @template {LitExpKeyType} KEYS
|
|
26
|
+
* @param {KEYS} keysAndDefaultValuePair
|
|
27
|
+
* - keys and whether to override regex detection;
|
|
28
|
+
* >- example:
|
|
29
|
+
* ```js
|
|
30
|
+
* myKey: /myCustomCapture/ // all flags will be stripped;
|
|
31
|
+
* ```
|
|
32
|
+
* - default value === `false` is "[\\s\\S]*?", as in whiteSpace and nonWhiteSpace 0 to more occurence;
|
|
33
|
+
* @returns {ReturnType<typeof TrySync<(templateStringArray:TemplateStringsArray,
|
|
34
|
+
* ...values:(keyof KEYS)[]
|
|
35
|
+
* )=>LitExp<KEYS>>>}
|
|
36
|
+
* - placement of `key` will determine the named capture group will be placed in the template literal;
|
|
37
|
+
* - it is recomended to not end template literal with any of the `key`s as the regex detection might failed to detects the boundary of the end of matched string of that capture group;
|
|
38
|
+
* @example
|
|
39
|
+
* import { LitExp } from 'vivth';
|
|
40
|
+
*
|
|
41
|
+
* (()=>{
|
|
42
|
+
* const [liteal, errorPrep] = LitExp.prepare({
|
|
43
|
+
* myKey: /myCustomCapture/, // is placed on (?<myKey>myCustomCapture)
|
|
44
|
+
* // use false to place "[\\s\\S]\*?" instead;
|
|
45
|
+
* ...keyCaptureLogicPair
|
|
46
|
+
* })
|
|
47
|
+
* if (errorPrep) {
|
|
48
|
+
* console.error(error);
|
|
49
|
+
* return;
|
|
50
|
+
* }
|
|
51
|
+
* const litExp_instance = liteal`templateLiteral:${'myKey'};`
|
|
52
|
+
* // recommended to end the template literal with any string but `key`;
|
|
53
|
+
* })()
|
|
54
|
+
*/
|
|
55
|
+
static prepare: (keysAndDefaultValuePair: KEYS_1) => ReturnType<typeof TrySync<(templateStringArray: TemplateStringsArray, ...values: (keyof KEYS_1)[]) => LitExp<KEYS_1>>>;
|
|
56
|
+
/**
|
|
57
|
+
* @template {LitExpKeyType} KEYS
|
|
58
|
+
* @param {KEYS} instance_rules
|
|
59
|
+
* @param {(keyof KEYS)[]} intance_values
|
|
60
|
+
* @param {(value:keyof KEYS, regex:RegExp|false)=>ReturnType<typeof TrySync<string>>} valueHandler
|
|
61
|
+
* @param {TemplateStringsArray} strings
|
|
62
|
+
* @returns {ReturnType<typeof TrySync<string[]>>}
|
|
63
|
+
*/
|
|
64
|
+
static #processTemplate: (instance_rules: KEYS_1, intance_values: (keyof KEYS_1)[], valueHandler: (value: keyof KEYS_1, regex: RegExp | false) => ReturnType<typeof TrySync<string>>, strings: TemplateStringsArray) => ReturnType<typeof TrySync<string[]>>;
|
|
65
|
+
/**
|
|
66
|
+
* @template {LitExpKeyType} KEYS
|
|
67
|
+
* @param {RegExp|false} regex
|
|
68
|
+
* @param {keyof KEYS} value
|
|
69
|
+
* @returns {ReturnType<typeof TrySync<string>>}
|
|
70
|
+
*/
|
|
71
|
+
static #namedChapture: (value: keyof KEYS_1, regex: RegExp | false) => ReturnType<typeof TrySync<string>>;
|
|
72
|
+
/**
|
|
73
|
+
* @private
|
|
74
|
+
* @param {KEYS} keys
|
|
75
|
+
* @param {TemplateStringsArray} templateStringArray
|
|
76
|
+
* @param {...(keyof KEYS)} values
|
|
77
|
+
*/
|
|
78
|
+
private constructor();
|
|
79
|
+
/**
|
|
80
|
+
* @description
|
|
81
|
+
* - instance methods for generating things;
|
|
82
|
+
*/
|
|
83
|
+
make: {
|
|
84
|
+
/**
|
|
85
|
+
* @instance make
|
|
86
|
+
* @description
|
|
87
|
+
* - to make string based on the template literal;
|
|
88
|
+
* @param {Partial<ReturnType<LitExp<KEYS>["evaluate"]["execGroups"]>>[0]["result"]} overrides
|
|
89
|
+
* @returns {string}
|
|
90
|
+
* @example
|
|
91
|
+
* import { LitExp } from 'vivth';
|
|
92
|
+
*
|
|
93
|
+
* const [literal, errorPreparing] = LitExp.prepare({
|
|
94
|
+
* myKey: false,
|
|
95
|
+
* ...keyCaptureLogicPair
|
|
96
|
+
* })
|
|
97
|
+
*
|
|
98
|
+
* // asuming no error
|
|
99
|
+
* litExp_instance = `templateLiteral:${'myKey'};`;
|
|
100
|
+
* const [result, error] = litExp_instance.make.string({
|
|
101
|
+
* myKey: 'actualvalue',
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* console.log(result); // "templateLiteral:actualvalue;"
|
|
105
|
+
*/
|
|
106
|
+
string: (overrides: Partial<ReturnType<LitExp<KEYS>["evaluate"]["execGroups"]>>[0]["result"]) => string;
|
|
107
|
+
} & {
|
|
108
|
+
"vivth:unwrapLazy;": () => {
|
|
109
|
+
/**
|
|
110
|
+
* @instance make
|
|
111
|
+
* @description
|
|
112
|
+
* - to make string based on the template literal;
|
|
113
|
+
* @param {Partial<ReturnType<LitExp<KEYS>["evaluate"]["execGroups"]>>[0]["result"]} overrides
|
|
114
|
+
* @returns {string}
|
|
115
|
+
* @example
|
|
116
|
+
* import { LitExp } from 'vivth';
|
|
117
|
+
*
|
|
118
|
+
* const [literal, errorPreparing] = LitExp.prepare({
|
|
119
|
+
* myKey: false,
|
|
120
|
+
* ...keyCaptureLogicPair
|
|
121
|
+
* })
|
|
122
|
+
*
|
|
123
|
+
* // asuming no error
|
|
124
|
+
* litExp_instance = `templateLiteral:${'myKey'};`;
|
|
125
|
+
* const [result, error] = litExp_instance.make.string({
|
|
126
|
+
* myKey: 'actualvalue',
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* console.log(result); // "templateLiteral:actualvalue;"
|
|
130
|
+
*/
|
|
131
|
+
string: (overrides: Partial<ReturnType<LitExp<KEYS>["evaluate"]["execGroups"]>>[0]["result"]) => string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* @description
|
|
136
|
+
* - methods collections to evaluate string with `Literal Expression`;
|
|
137
|
+
*/
|
|
138
|
+
evaluate: {
|
|
139
|
+
/**
|
|
140
|
+
* @instance evaluate
|
|
141
|
+
* @description
|
|
142
|
+
* - to exec and grouped based on `key`;
|
|
143
|
+
* @param {string} string
|
|
144
|
+
* @param {Object} options
|
|
145
|
+
* @param {ConstructorParameters<typeof RegExp>[1]} options.flags
|
|
146
|
+
* @param {boolean} options.whiteSpaceSensitive
|
|
147
|
+
* - true: leave any whitespace as is to be used as regex detection;
|
|
148
|
+
* - false: convert all whitespace to `\s+`;
|
|
149
|
+
* @param {boolean} options.absoluteLeadAndFollowing
|
|
150
|
+
* - false: standard capture;
|
|
151
|
+
* - true: add `^` and `$` to capture definition:
|
|
152
|
+
* >- meaning string will have to match starting and end of line from capture definition;
|
|
153
|
+
* @returns {ReturnType<typeof TrySync<{
|
|
154
|
+
* result:{ whole:string, named: Record<keyof KEYS, string>},
|
|
155
|
+
* regexp:RegExp}>>
|
|
156
|
+
* }
|
|
157
|
+
* @example
|
|
158
|
+
* import { LitExp } from 'vivth';
|
|
159
|
+
*
|
|
160
|
+
* const [literal, errorPreparing] = LitExp.prepare({
|
|
161
|
+
* myKey: false,
|
|
162
|
+
* ...keyCaptureLogicPair
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* // asuming no eror
|
|
166
|
+
* const litExp_instance = literal`templateLiteral:${'myKey'};`
|
|
167
|
+
*
|
|
168
|
+
* const [{
|
|
169
|
+
* result:{ // asuming there's no error
|
|
170
|
+
* named: { myKey },
|
|
171
|
+
* whole,
|
|
172
|
+
* },
|
|
173
|
+
* regex, // for reference
|
|
174
|
+
* }, error] = litExp_instance.evaluate.execGroups(
|
|
175
|
+
* `templateLiteral:Something;`,
|
|
176
|
+
* { ...options }
|
|
177
|
+
* )
|
|
178
|
+
*
|
|
179
|
+
* console.log(whole); // "templateLiteral:Something;"
|
|
180
|
+
* console.log(myKey); // "Something"
|
|
181
|
+
*/
|
|
182
|
+
execGroups: (string: string, options: {
|
|
183
|
+
flags: ConstructorParameters<typeof RegExp>[1];
|
|
184
|
+
whiteSpaceSensitive: boolean;
|
|
185
|
+
absoluteLeadAndFollowing: boolean;
|
|
186
|
+
}) => ReturnType<typeof TrySync<{
|
|
187
|
+
result: {
|
|
188
|
+
whole: string;
|
|
189
|
+
named: Record<keyof KEYS, string>;
|
|
190
|
+
};
|
|
191
|
+
regexp: RegExp;
|
|
192
|
+
}>>;
|
|
193
|
+
/**
|
|
194
|
+
* @instance evaluate
|
|
195
|
+
* @description
|
|
196
|
+
* - to match all and grouped based on `key`;
|
|
197
|
+
* @param {Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[0]} string
|
|
198
|
+
* @param {Omit<Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[1], 'absoluteLeadAndFollowing'>} options
|
|
199
|
+
* @returns {ReturnType<typeof TrySync<{result:{whole:string[], named:Array<Record<keyof KEYS, string>>},
|
|
200
|
+
* regexp: RegExp}>>
|
|
201
|
+
* }
|
|
202
|
+
* @example
|
|
203
|
+
* import { LitExp, Console } from 'vivth';
|
|
204
|
+
*
|
|
205
|
+
* const [literal, errorPreparing] = LitExp.prepare({
|
|
206
|
+
* myKey: false,
|
|
207
|
+
* ...keyCaptureLogicPair
|
|
208
|
+
* })
|
|
209
|
+
*
|
|
210
|
+
* // asuming no error;
|
|
211
|
+
* litExp_instance = literal`templateLiteral:${'myKey'};`
|
|
212
|
+
*
|
|
213
|
+
* const [resultOfMatchedAllAndGrouped, error] = litExp_instance.evaluate.matchedAllAndGrouped(
|
|
214
|
+
* `templateLiteral:Something;
|
|
215
|
+
* templateLiteral:SomethingElse;`,
|
|
216
|
+
* { ...options }
|
|
217
|
+
* )
|
|
218
|
+
* (()=>{
|
|
219
|
+
* if (error) {
|
|
220
|
+
* Console.error(error);
|
|
221
|
+
* return;
|
|
222
|
+
* }
|
|
223
|
+
* const {
|
|
224
|
+
* result: {
|
|
225
|
+
* whole: [whole0, whole1],
|
|
226
|
+
* named: [
|
|
227
|
+
* { myKey: myKeyExec0, },
|
|
228
|
+
* { myKey: myKeyExec1, },
|
|
229
|
+
* ],
|
|
230
|
+
* },
|
|
231
|
+
* regexp
|
|
232
|
+
* } = resultOfMatchedAllAndGrouped;
|
|
233
|
+
*
|
|
234
|
+
* console.log(whole0); // "templateLiteral:Something;"
|
|
235
|
+
* console.log(whole1); // "templateLiteral:SomethingElse;"
|
|
236
|
+
* console.log(myKeyExec0); // "Something"
|
|
237
|
+
* console.log(myKeyExec1); // "SomethingElse"
|
|
238
|
+
* })()
|
|
239
|
+
*/
|
|
240
|
+
matchedAllAndGrouped: (string: Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[0], options: Omit<Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[1], "absoluteLeadAndFollowing">) => ReturnType<typeof TrySync<{
|
|
241
|
+
result: {
|
|
242
|
+
whole: string[];
|
|
243
|
+
named: Array<Record<keyof KEYS, string>>;
|
|
244
|
+
};
|
|
245
|
+
regexp: RegExp;
|
|
246
|
+
}>>;
|
|
247
|
+
} & {
|
|
248
|
+
"vivth:unwrapLazy;": () => {
|
|
249
|
+
/**
|
|
250
|
+
* @instance evaluate
|
|
251
|
+
* @description
|
|
252
|
+
* - to exec and grouped based on `key`;
|
|
253
|
+
* @param {string} string
|
|
254
|
+
* @param {Object} options
|
|
255
|
+
* @param {ConstructorParameters<typeof RegExp>[1]} options.flags
|
|
256
|
+
* @param {boolean} options.whiteSpaceSensitive
|
|
257
|
+
* - true: leave any whitespace as is to be used as regex detection;
|
|
258
|
+
* - false: convert all whitespace to `\s+`;
|
|
259
|
+
* @param {boolean} options.absoluteLeadAndFollowing
|
|
260
|
+
* - false: standard capture;
|
|
261
|
+
* - true: add `^` and `$` to capture definition:
|
|
262
|
+
* >- meaning string will have to match starting and end of line from capture definition;
|
|
263
|
+
* @returns {ReturnType<typeof TrySync<{
|
|
264
|
+
* result:{ whole:string, named: Record<keyof KEYS, string>},
|
|
265
|
+
* regexp:RegExp}>>
|
|
266
|
+
* }
|
|
267
|
+
* @example
|
|
268
|
+
* import { LitExp } from 'vivth';
|
|
269
|
+
*
|
|
270
|
+
* const [literal, errorPreparing] = LitExp.prepare({
|
|
271
|
+
* myKey: false,
|
|
272
|
+
* ...keyCaptureLogicPair
|
|
273
|
+
* })
|
|
274
|
+
*
|
|
275
|
+
* // asuming no eror
|
|
276
|
+
* const litExp_instance = literal`templateLiteral:${'myKey'};`
|
|
277
|
+
*
|
|
278
|
+
* const [{
|
|
279
|
+
* result:{ // asuming there's no error
|
|
280
|
+
* named: { myKey },
|
|
281
|
+
* whole,
|
|
282
|
+
* },
|
|
283
|
+
* regex, // for reference
|
|
284
|
+
* }, error] = litExp_instance.evaluate.execGroups(
|
|
285
|
+
* `templateLiteral:Something;`,
|
|
286
|
+
* { ...options }
|
|
287
|
+
* )
|
|
288
|
+
*
|
|
289
|
+
* console.log(whole); // "templateLiteral:Something;"
|
|
290
|
+
* console.log(myKey); // "Something"
|
|
291
|
+
*/
|
|
292
|
+
execGroups: (string: string, options: {
|
|
293
|
+
flags: ConstructorParameters<typeof RegExp>[1];
|
|
294
|
+
whiteSpaceSensitive: boolean;
|
|
295
|
+
absoluteLeadAndFollowing: boolean;
|
|
296
|
+
}) => ReturnType<typeof TrySync<{
|
|
297
|
+
result: {
|
|
298
|
+
whole: string;
|
|
299
|
+
named: Record<keyof KEYS, string>;
|
|
300
|
+
};
|
|
301
|
+
regexp: RegExp;
|
|
302
|
+
}>>;
|
|
303
|
+
/**
|
|
304
|
+
* @instance evaluate
|
|
305
|
+
* @description
|
|
306
|
+
* - to match all and grouped based on `key`;
|
|
307
|
+
* @param {Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[0]} string
|
|
308
|
+
* @param {Omit<Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[1], 'absoluteLeadAndFollowing'>} options
|
|
309
|
+
* @returns {ReturnType<typeof TrySync<{result:{whole:string[], named:Array<Record<keyof KEYS, string>>},
|
|
310
|
+
* regexp: RegExp}>>
|
|
311
|
+
* }
|
|
312
|
+
* @example
|
|
313
|
+
* import { LitExp, Console } from 'vivth';
|
|
314
|
+
*
|
|
315
|
+
* const [literal, errorPreparing] = LitExp.prepare({
|
|
316
|
+
* myKey: false,
|
|
317
|
+
* ...keyCaptureLogicPair
|
|
318
|
+
* })
|
|
319
|
+
*
|
|
320
|
+
* // asuming no error;
|
|
321
|
+
* litExp_instance = literal`templateLiteral:${'myKey'};`
|
|
322
|
+
*
|
|
323
|
+
* const [resultOfMatchedAllAndGrouped, error] = litExp_instance.evaluate.matchedAllAndGrouped(
|
|
324
|
+
* `templateLiteral:Something;
|
|
325
|
+
* templateLiteral:SomethingElse;`,
|
|
326
|
+
* { ...options }
|
|
327
|
+
* )
|
|
328
|
+
* (()=>{
|
|
329
|
+
* if (error) {
|
|
330
|
+
* Console.error(error);
|
|
331
|
+
* return;
|
|
332
|
+
* }
|
|
333
|
+
* const {
|
|
334
|
+
* result: {
|
|
335
|
+
* whole: [whole0, whole1],
|
|
336
|
+
* named: [
|
|
337
|
+
* { myKey: myKeyExec0, },
|
|
338
|
+
* { myKey: myKeyExec1, },
|
|
339
|
+
* ],
|
|
340
|
+
* },
|
|
341
|
+
* regexp
|
|
342
|
+
* } = resultOfMatchedAllAndGrouped;
|
|
343
|
+
*
|
|
344
|
+
* console.log(whole0); // "templateLiteral:Something;"
|
|
345
|
+
* console.log(whole1); // "templateLiteral:SomethingElse;"
|
|
346
|
+
* console.log(myKeyExec0); // "Something"
|
|
347
|
+
* console.log(myKeyExec1); // "SomethingElse"
|
|
348
|
+
* })()
|
|
349
|
+
*/
|
|
350
|
+
matchedAllAndGrouped: (string: Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[0], options: Omit<Parameters<LitExp<KEYS>["evaluate"]["execGroups"]>[1], "absoluteLeadAndFollowing">) => ReturnType<typeof TrySync<{
|
|
351
|
+
result: {
|
|
352
|
+
whole: string[];
|
|
353
|
+
named: Array<Record<keyof KEYS, string>>;
|
|
354
|
+
};
|
|
355
|
+
regexp: RegExp;
|
|
356
|
+
}>>;
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
#private;
|
|
360
|
+
}
|
|
361
|
+
import { TrySync } from '../function/TrySync.mjs';
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @description
|
|
3
3
|
* - class helpers to define pathReference;
|
|
4
4
|
* - is a singleton;
|
|
5
|
+
* - most of functionality need to access `Paths.root`, if you get warning, you can instantiate `Paths` before running anything;
|
|
5
6
|
*/
|
|
6
7
|
export class Paths {
|
|
7
8
|
/**
|
|
@@ -25,9 +26,21 @@ export class Paths {
|
|
|
25
26
|
* @example
|
|
26
27
|
* import { Paths } from 'vivth';
|
|
27
28
|
*
|
|
28
|
-
* Paths.normalize('file:\\D:\\myFile.mjs'); //
|
|
29
|
+
* Paths.normalize('file:\\D:\\myFile.mjs'); // "file://D://myFile.mjs"
|
|
29
30
|
*/
|
|
30
31
|
static normalize: (path_: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* @description
|
|
34
|
+
* - normalize path separator to forward slash `/`;
|
|
35
|
+
* - then starts with forward slash `/`;
|
|
36
|
+
* @param {string} path_
|
|
37
|
+
* @returns {`/${string}`}
|
|
38
|
+
* @example
|
|
39
|
+
* import { Paths } from 'vivth';
|
|
40
|
+
*
|
|
41
|
+
* Paths.normalizesForRoot('path\\myFile.mjs'); // "/path/myFile.mjs"
|
|
42
|
+
*/
|
|
43
|
+
static normalizesForRoot: (path_: string) => `/${string}`;
|
|
31
44
|
/**
|
|
32
45
|
* @description
|
|
33
46
|
* @param {Object} options
|
|
@@ -44,6 +57,10 @@ export class Paths {
|
|
|
44
57
|
* ```js
|
|
45
58
|
* Deno.env.get("INIT_CWD") ?? Deno.cwd()
|
|
46
59
|
* ```
|
|
60
|
+
* - pkg:
|
|
61
|
+
* ```js
|
|
62
|
+
* __dirname
|
|
63
|
+
* ```
|
|
47
64
|
* - other: you need to check your JSRuntime for the rootPath reference;
|
|
48
65
|
* @example
|
|
49
66
|
* import { Paths } from 'vivth';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - class for `Queue` handling;
|
|
4
|
-
* @template {AnyButUndefined}
|
|
4
|
+
* @template {AnyButUndefined} DEFINEDANY
|
|
5
5
|
*/
|
|
6
|
-
export class QChannel<
|
|
6
|
+
export class QChannel<DEFINEDANY extends import("../types/AnyButUndefined.mjs").AnyButUndefined> {
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {import('../types/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
|
|
9
9
|
* @typedef {import('../types/QCBReturn.mjs').QCBReturn} QCBReturn
|
|
@@ -15,6 +15,11 @@ export class QChannel<T extends import("../types/AnyButUndefined.mjs").AnyButUnd
|
|
|
15
15
|
* @param {Map<AnyButUndefined, [Promise<any>, {}]>} uniqueMap
|
|
16
16
|
* @returns {typeof QChannel}
|
|
17
17
|
* - usefull for Queue primitive on multiple library but single reference, like the Web by making the `Map` on `window` object;
|
|
18
|
+
* @example
|
|
19
|
+
* import { QChannel } from 'vivth';
|
|
20
|
+
*
|
|
21
|
+
* const myMappedQref = (window['myMappedQref'] = new Map());
|
|
22
|
+
* export const MyQClass = QChannel.makeQClass(myMappedQref);
|
|
18
23
|
*/
|
|
19
24
|
static makeQClass: (uniqueMap: Map<import("../types/AnyButUndefined.mjs").AnyButUndefined, [Promise<any>, {}]>) => typeof QChannel;
|
|
20
25
|
/**
|
|
@@ -25,9 +30,10 @@ export class QChannel<T extends import("../types/AnyButUndefined.mjs").AnyButUnd
|
|
|
25
30
|
* - ensures that each id has only one task running at a time.
|
|
26
31
|
* - calls with the same id will wait for the previous call to finish.
|
|
27
32
|
* @param {AnyButUndefined} id
|
|
33
|
+
* @param {QChannel} instance
|
|
28
34
|
* @returns {Promise<QCBReturn>} Resolves when it's safe to proceed for the given id, returning a cleanup function
|
|
29
35
|
*/
|
|
30
|
-
static #uniqueCB: (id: import("../types/AnyButUndefined.mjs").AnyButUndefined) => Promise<import("../types/QCBReturn.mjs").QCBReturn>;
|
|
36
|
+
static #uniqueCB: (id: import("../types/AnyButUndefined.mjs").AnyButUndefined, instance: QChannel<any>) => Promise<import("../types/QCBReturn.mjs").QCBReturn>;
|
|
31
37
|
/**
|
|
32
38
|
* @description
|
|
33
39
|
* - first in first out handler
|
|
@@ -48,38 +54,76 @@ export class QChannel<T extends import("../types/AnyButUndefined.mjs").AnyButUnd
|
|
|
48
54
|
* @static fifo
|
|
49
55
|
* @description
|
|
50
56
|
* - blocks execution for subsequent calls until the current one finishes.
|
|
51
|
-
* @template
|
|
52
|
-
* @param {()=>Promise<
|
|
53
|
-
* @returns {Promise<[
|
|
57
|
+
* @template RESULT
|
|
58
|
+
* @param {()=>Promise<RESULT>} asyncCallback
|
|
59
|
+
* @returns {Promise<[RESULT|undefined, Error|undefined]>}
|
|
54
60
|
* @example
|
|
55
61
|
* const [result, error] = await QChannel.fifo.callback(async () = > {
|
|
56
62
|
* // code
|
|
57
63
|
* })
|
|
58
64
|
*/
|
|
59
|
-
callback: <
|
|
65
|
+
callback: <RESULT>(asyncCallback: () => Promise<RESULT>) => Promise<[RESULT | undefined, Error | undefined]>;
|
|
60
66
|
} & {
|
|
61
|
-
"vivth:unwrapLazy;":
|
|
67
|
+
"vivth:unwrapLazy;": () => {
|
|
68
|
+
/**
|
|
69
|
+
* @static fifo
|
|
70
|
+
* @description
|
|
71
|
+
* - blocks execution for subsequent calls until the current one finishes.
|
|
72
|
+
* @returns {Promise<QCBFIFOReturn>} Resolves when it's safe to proceed, returning a cleanup function
|
|
73
|
+
* @example
|
|
74
|
+
* const { resume } = await QChannel.fifo.key();
|
|
75
|
+
* // blocks all `FIFO` called using this method and QChannel.fifoCallback;
|
|
76
|
+
* resume();
|
|
77
|
+
*/
|
|
78
|
+
key: () => Promise<import("../types/QCBFIFOReturn.mjs").QCBFIFOReturn>;
|
|
79
|
+
/**
|
|
80
|
+
* @static fifo
|
|
81
|
+
* @description
|
|
82
|
+
* - blocks execution for subsequent calls until the current one finishes.
|
|
83
|
+
* @template RESULT
|
|
84
|
+
* @param {()=>Promise<RESULT>} asyncCallback
|
|
85
|
+
* @returns {Promise<[RESULT|undefined, Error|undefined]>}
|
|
86
|
+
* @example
|
|
87
|
+
* const [result, error] = await QChannel.fifo.callback(async () = > {
|
|
88
|
+
* // code
|
|
89
|
+
* })
|
|
90
|
+
*/
|
|
91
|
+
callback: <RESULT>(asyncCallback: () => Promise<RESULT>) => Promise<[RESULT | undefined, Error | undefined]>;
|
|
92
|
+
};
|
|
62
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* @param {string} name
|
|
96
|
+
* - only used as helper for logging, and has nothing to do with runtime behaviour;
|
|
97
|
+
*/
|
|
98
|
+
constructor(name: string);
|
|
99
|
+
name: string;
|
|
100
|
+
/**
|
|
101
|
+
* @description
|
|
102
|
+
* - disable queue;
|
|
103
|
+
* - when `closed`, `isLastOnQ` will allways return `false`;
|
|
104
|
+
* @returns {void}
|
|
105
|
+
*/
|
|
106
|
+
close: () => void;
|
|
63
107
|
/**
|
|
64
108
|
* @description
|
|
65
|
-
* -
|
|
66
|
-
* -
|
|
109
|
+
* - enable queue;
|
|
110
|
+
* - when `opened`, `isLastOnQ` will evaluate whether calls are actually the last of queue;
|
|
67
111
|
* @returns {void}
|
|
68
112
|
*/
|
|
69
|
-
|
|
113
|
+
open: () => void;
|
|
70
114
|
/**
|
|
71
115
|
* @description
|
|
72
116
|
* - each `QChannelInstance` are managing it's own `queue`, and will not `await` for other `QChannelInstance`;
|
|
73
117
|
* - caveat:
|
|
74
118
|
* >- need to manually call resume();
|
|
75
119
|
* >- slightly more performant than `callback`;
|
|
76
|
-
* @param {
|
|
120
|
+
* @param {DEFINEDANY} keyID
|
|
77
121
|
* @returns {Promise<QCBReturn>}
|
|
78
122
|
* @example
|
|
79
|
-
* const q = new QChannel();
|
|
123
|
+
* const q = new QChannel('channel name');
|
|
80
124
|
* const handler = async () => {
|
|
81
125
|
* const { resume, isLastOnQ } = await q.key(keyID);
|
|
82
|
-
* // if (!isLastOnQ) { // imperative debounce if needed
|
|
126
|
+
* // if (!isLastOnQ()) { // imperative debounce if needed
|
|
83
127
|
* // resume();
|
|
84
128
|
* // return;
|
|
85
129
|
* // }
|
|
@@ -90,26 +134,29 @@ export class QChannel<T extends import("../types/AnyButUndefined.mjs").AnyButUnd
|
|
|
90
134
|
* }
|
|
91
135
|
* handler();
|
|
92
136
|
*/
|
|
93
|
-
key: (keyID:
|
|
137
|
+
key: (keyID: DEFINEDANY) => Promise<import("../types/QCBReturn.mjs").QCBReturn>;
|
|
94
138
|
/**
|
|
95
139
|
* @description
|
|
96
140
|
* - `callbackBlock` with error as value:
|
|
97
141
|
* - caveat:
|
|
98
142
|
* >- no need to manually call resume();
|
|
99
143
|
* >- slightly less performant than `callback`;
|
|
100
|
-
* @template
|
|
101
|
-
* @param {
|
|
102
|
-
* @param {(options:Omit<QCBReturn,
|
|
103
|
-
*
|
|
144
|
+
* @template RESULT
|
|
145
|
+
* @param {DEFINEDANY} keyID
|
|
146
|
+
* @param {(options:Omit<QCBReturn,
|
|
147
|
+
* "resume">) =>
|
|
148
|
+
* Promise<RESULT>} asyncCallback
|
|
149
|
+
* @returns {ReturnType<typeof TryAsync<RESULT>>}
|
|
104
150
|
* @example
|
|
105
|
-
* const q = new QChannel();
|
|
151
|
+
* const q = new QChannel('channel name');
|
|
106
152
|
* const [result, error] = await q.callback(keyID, async ({ isLastOnQ }) = > {
|
|
107
|
-
* // if (!isLastOnQ) { // imperative debounce if needed
|
|
153
|
+
* // if (!isLastOnQ()) { // imperative debounce if needed
|
|
108
154
|
* // return;
|
|
109
155
|
* // }
|
|
110
156
|
* // code
|
|
111
157
|
* })
|
|
112
158
|
*/
|
|
113
|
-
callback
|
|
159
|
+
callback<RESULT>(keyID: DEFINEDANY, asyncCallback: (options: Omit<import("../types/QCBReturn.mjs").QCBReturn, "resume">) => Promise<RESULT>): ReturnType<typeof TryAsync<RESULT>>;
|
|
114
160
|
#private;
|
|
115
161
|
}
|
|
162
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
@@ -6,19 +6,25 @@ export const safeCleanUpCBs: Set<() => Promise<void>>;
|
|
|
6
6
|
* @description
|
|
7
7
|
* - class helper for describing how to Safely Response on exit events
|
|
8
8
|
* - singleton;
|
|
9
|
-
*
|
|
9
|
+
* - most of functionality might need to access `SafeExit.instance.exiting`, if you get warning, you can instantiate `SafeExit` before running anything;
|
|
10
10
|
*/
|
|
11
|
-
export class SafeExit
|
|
11
|
+
export class SafeExit {
|
|
12
12
|
/**
|
|
13
13
|
* @description
|
|
14
14
|
* - only accessible after instantiation;
|
|
15
15
|
* @type {SafeExit}
|
|
16
16
|
*/
|
|
17
|
-
static instance: SafeExit
|
|
17
|
+
static instance: SafeExit;
|
|
18
18
|
/**
|
|
19
19
|
* @description
|
|
20
20
|
* @param {Object} options
|
|
21
|
-
* @param {
|
|
21
|
+
* @param {[string, ...string[]]} options.eventNames
|
|
22
|
+
* - eventNames are blank by default, you need to manually name them all;
|
|
23
|
+
* - 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
24
|
+
* - example:
|
|
25
|
+
* ```js
|
|
26
|
+
* ['SIGINT', 'SIGTERM']
|
|
27
|
+
* ```
|
|
22
28
|
* @param {()=>void} options.terminator
|
|
23
29
|
* - standard node/bun:
|
|
24
30
|
* ```js
|
|
@@ -38,17 +44,26 @@ export class SafeExit<eventNames extends [string, ...string[]]> {
|
|
|
38
44
|
* });
|
|
39
45
|
* };
|
|
40
46
|
* ```
|
|
47
|
+
* - example Deno:
|
|
48
|
+
* ```js
|
|
49
|
+
* (eventName) => {
|
|
50
|
+
* const sig = Deno.signal(eventName);
|
|
51
|
+
* for await (const _ of sig) {
|
|
52
|
+
* exiting.correction(true);
|
|
53
|
+
* sig.dispose();
|
|
54
|
+
* Console.log(`safe exit via "${eventName}"`);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
41
58
|
* - if your exit callback doesn't uses `process` global object you need to input on the SafeExit instantiation
|
|
42
59
|
* @example
|
|
43
60
|
* import { SafeExit, Console } from 'vivth';
|
|
44
61
|
*
|
|
45
62
|
* new SafeExit({
|
|
46
|
-
* // eventNames are blank by default, you need to manually name them all;
|
|
47
|
-
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
48
63
|
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
49
|
-
* terminator
|
|
64
|
+
* terminator : () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
50
65
|
* // optional deno example
|
|
51
|
-
* listener
|
|
66
|
+
* listener : (eventName) => {
|
|
52
67
|
* const sig = Deno.signal(eventName);
|
|
53
68
|
* for await (const _ of sig) {
|
|
54
69
|
* exiting.correction(true);
|
|
@@ -59,7 +74,7 @@ export class SafeExit<eventNames extends [string, ...string[]]> {
|
|
|
59
74
|
* });
|
|
60
75
|
*/
|
|
61
76
|
constructor({ eventNames, terminator, listener }: {
|
|
62
|
-
eventNames:
|
|
77
|
+
eventNames: [string, ...string[]];
|
|
63
78
|
terminator: () => void;
|
|
64
79
|
listener?: (eventName: string) => void;
|
|
65
80
|
});
|
|
@@ -42,9 +42,10 @@ export class Setup {
|
|
|
42
42
|
* - proxy `WorkerMainThread_instance` for Setup;
|
|
43
43
|
* @example
|
|
44
44
|
* import { Setup } from 'vivth';
|
|
45
|
+
* import { Worker } from 'node:worker_threads';
|
|
45
46
|
*
|
|
46
47
|
* Setup.workerMain({
|
|
47
|
-
* workerClass:
|
|
48
|
+
* workerClass: Worker,
|
|
48
49
|
* basePath: 'public/assets/js/workers',
|
|
49
50
|
* pathValidator: async (workerPath, root, base) => {
|
|
50
51
|
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
@@ -61,16 +62,16 @@ export class Setup {
|
|
|
61
62
|
/**
|
|
62
63
|
* @description
|
|
63
64
|
* - correct `parentPort` reference when needed;
|
|
65
|
+
* - export to create new reference to be use to create new WorkerThread instance;
|
|
64
66
|
* @example
|
|
65
67
|
* import { Setup } from 'vivth';
|
|
68
|
+
* import { parentPort } from 'node:worker_threads';
|
|
66
69
|
*
|
|
67
|
-
* Setup.workerThread({
|
|
70
|
+
* export const MyWorkerThreadRef = Setup.workerThread({parentPort});
|
|
68
71
|
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
69
72
|
* // you need to call this method;
|
|
70
73
|
*/
|
|
71
|
-
static workerThread:
|
|
72
|
-
parentPort: () => Promise<any>;
|
|
73
|
-
}) => typeof WorkerThread<Receive_, Post_>;
|
|
74
|
+
static workerThread: typeof WorkerThread.setup;
|
|
74
75
|
}
|
|
75
76
|
import { SafeExit } from './SafeExit.mjs';
|
|
76
77
|
import { Paths } from './Paths.mjs';
|