vivth 1.1.1 → 1.1.2

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 CHANGED
@@ -68,12 +68,12 @@ npm i vivth
68
68
  - [TsToMjs](#tstomjs)
69
69
  - [WriteFileSafe](#writefilesafe)
70
70
  - [AnyButUndefined](#anybutundefined)
71
- - [QCBReturn](#qcbreturn)
72
- - [QCBFIFOReturn](#qcbfiforeturn)
73
- - [MutationType](#mutationtype)
74
- - [ListArg](#listarg)
75
- - [IsListSignal](#islistsignal)
76
71
  - [ExtnameType](#extnametype)
72
+ - [IsListSignal](#islistsignal)
73
+ - [ListArg](#listarg)
74
+ - [MutationType](#mutationtype)
75
+ - [QCBFIFOReturn](#qcbfiforeturn)
76
+ - [QCBReturn](#qcbreturn)
77
77
 
78
78
  <h2 id="compilemjs">CompileMJS</h2>
79
79
 
@@ -846,9 +846,18 @@ npm i vivth
846
846
  /**
847
847
  * @param {Object} options
848
848
  * @param {string} options.root
849
- * - browser: location.origin
850
- * - node/bun compatible: process?.env?.INIT_CWD ?? process?.cwd();
851
- * - deno: Deno.env.get("INIT_CWD") ?? Deno.cwd(); need for `deno run --allow-env --allow-read your_script.ts`
849
+ * - browser:
850
+ * ```js
851
+ * location.origin
852
+ * ```
853
+ * - node/bun compatible:
854
+ * ```js
855
+ * process?.env?.INIT_CWD ?? process?.cwd()
856
+ * ```
857
+ * - deno: need for `deno run --allow-env --allow-read your_script.ts`:
858
+ * ```js
859
+ * Deno.env.get("INIT_CWD") ?? Deno.cwd()
860
+ * ```
852
861
  * - other: you need to check your JSRuntime for the rootPath reference;
853
862
  */
854
863
  ```
@@ -1142,15 +1151,17 @@ npm i vivth
1142
1151
  import { Setup, Console } from 'vivth';
1143
1152
 
1144
1153
  new Setup.safeExit({
1145
- // exitEventNames are blank by default, you need to manually name them all;
1146
- exitEventNames: ['SIGINT', 'SIGTERM', ...otherExitEventNames],
1154
+ // eventNames are blank by default, you need to manually name them all;
1155
+ // 'exit' will be omited, as it might cause async callbacks failed to execute;
1156
+ eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
1157
+ terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
1147
1158
  // optional deno example
1148
- exitCallbackListeners = (eventName) => {
1159
+ listener = (eventName) => {
1149
1160
  const sig = Deno.signal(eventName);
1150
1161
  for await (const _ of sig) {
1151
- SafeExit.instance.exiting.correction(true);
1162
+ exiting.correction(true);
1152
1163
  sig.dispose();
1153
- Console.info(`safe exit via "${eventName}"`);
1164
+ Console.log(`safe exit via "${eventName}"`);
1154
1165
  }
1155
1166
  }
1156
1167
  });
@@ -1199,7 +1210,7 @@ npm i vivth
1199
1210
  ```js
1200
1211
  import { Setup } from 'vivth';
1201
1212
 
1202
- Setup.workerThread({ parentPort: async () => await import('node:worker_threads') });
1213
+ Setup.workerThread({ parentPort: async () => (await import('node:worker_threads')).parentPort });
1203
1214
  // that is the default value, if your parentPort/equivalent API is not that;
1204
1215
  // you need to call this method;
1205
1216
 
@@ -1380,12 +1391,18 @@ npm i vivth
1380
1391
  /**
1381
1392
  * @param {Object} param0
1382
1393
  * @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
1394
+ * - example:
1395
+ * ```js
1396
+ * async () => await (import('worker_threads')).Worker
1397
+ * ```
1383
1398
  * @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
1399
+ * - example:
1384
1400
  * ```js
1385
- * async(relativePath) => {
1386
- * // verify whether relativePath exist, then return the full path
1387
- * // use fetch | fs, chained with Paths.instance.root + WorkerMainThread.basePath;
1388
- * }
1401
+ * async (workerPath, root, base) => {
1402
+ * const res = await fetch(`${root}/${base}/${workerPath}`);
1403
+ * // might also check wheter it need base or not
1404
+ * return await res.ok;
1405
+ * }
1389
1406
  * ```
1390
1407
  * @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
1391
1408
  * - additonal realtivePath from rootPath;
@@ -1573,7 +1590,10 @@ npm i vivth
1573
1590
  * @template Receive_
1574
1591
  * @template Post_
1575
1592
  * @param {{parentPort:()=>Promise<any>}} parentPortRef
1576
- * - correct parentPort reference;
1593
+ * - correct parentPort reference, example:
1594
+ * ```js
1595
+ * async () => (await import('node:worker_threads')).parentPort
1596
+ * ```
1577
1597
  * @returns {typeof WorkerThread<Receive_, Post_>}
1578
1598
  */
1579
1599
  ```
@@ -1581,7 +1601,7 @@ npm i vivth
1581
1601
  ```js
1582
1602
  import { WorkerThread } from 'vivth';
1583
1603
 
1584
- WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
1604
+ WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
1585
1605
  // that is the default value, if your parentPort/equivalent API is not that;
1586
1606
  // you need to call this method;
1587
1607
 
@@ -2134,76 +2154,76 @@ npm i vivth
2134
2154
  ```
2135
2155
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2136
2156
 
2137
- <h2 id="qcbreturn">QCBReturn</h2>
2157
+ <h2 id="extnametype">ExtnameType</h2>
2138
2158
 
2139
2159
  - jsdoc types:
2140
2160
 
2141
2161
  ```js
2142
2162
  /**
2143
- * - return type of Q callback;
2144
- * @typedef {{resume:()=>void, isLastOnQ:boolean}} QCBReturn
2163
+ * - jsRuntime extention naming convention;
2164
+ * @typedef {`.${string}`} ExtnameType
2145
2165
  */
2146
2166
  ```
2147
2167
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2148
2168
 
2149
- <h2 id="qcbfiforeturn">QCBFIFOReturn</h2>
2169
+ <h2 id="islistsignal">IsListSignal</h2>
2150
2170
 
2151
2171
  - jsdoc types:
2152
2172
 
2153
2173
  ```js
2154
2174
  /**
2155
- * - return type of Q callback fifo;
2156
- * @typedef {Omit<import("./src/types/QCBReturn.mjs").QCBReturn, "isLastOnQ">} QCBFIFOReturn
2175
+ * - `EnvSignal.get` argument whether signal need to be a list or not;
2176
+ * @typedef {boolean} IsListSignal
2157
2177
  */
2158
2178
  ```
2159
2179
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2160
2180
 
2161
- <h2 id="mutationtype">MutationType</h2>
2181
+ <h2 id="listarg">ListArg</h2>
2162
2182
 
2163
2183
  - jsdoc types:
2164
2184
 
2165
2185
  ```js
2166
2186
  /**
2167
- * - `ListSignal` mutation type;
2168
- * @typedef {'push'|'unshift'|'splice'|'swap'|'modify'|'shift'|'remove'} MutationType
2169
- * - instance method: serves as helper to mutate, and notify for `effects`;
2170
- * > - `slice` uses `splice` in the background, you don't need to manually reindex when using it;
2187
+ * - ListSignal argument type;
2188
+ * @typedef {Record<string, string>} ListArg
2171
2189
  */
2172
2190
  ```
2173
2191
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2174
2192
 
2175
- <h2 id="listarg">ListArg</h2>
2193
+ <h2 id="mutationtype">MutationType</h2>
2176
2194
 
2177
2195
  - jsdoc types:
2178
2196
 
2179
2197
  ```js
2180
2198
  /**
2181
- * - ListSignal argument type;
2182
- * @typedef {Record<string, string>} ListArg
2199
+ * - `ListSignal` mutation type;
2200
+ * @typedef {'push'|'unshift'|'splice'|'swap'|'modify'|'shift'|'remove'} MutationType
2201
+ * - instance method: serves as helper to mutate, and notify for `effects`;
2202
+ * > - `slice` uses `splice` in the background, you don't need to manually reindex when using it;
2183
2203
  */
2184
2204
  ```
2185
2205
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2186
2206
 
2187
- <h2 id="islistsignal">IsListSignal</h2>
2207
+ <h2 id="qcbfiforeturn">QCBFIFOReturn</h2>
2188
2208
 
2189
2209
  - jsdoc types:
2190
2210
 
2191
2211
  ```js
2192
2212
  /**
2193
- * - `EnvSignal.get` argument whether signal need to be a list or not;
2194
- * @typedef {boolean} IsListSignal
2213
+ * - return type of Q callback fifo;
2214
+ * @typedef {Omit<import("./src/types/QCBReturn.mjs").QCBReturn, "isLastOnQ">} QCBFIFOReturn
2195
2215
  */
2196
2216
  ```
2197
2217
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2198
2218
 
2199
- <h2 id="extnametype">ExtnameType</h2>
2219
+ <h2 id="qcbreturn">QCBReturn</h2>
2200
2220
 
2201
2221
  - jsdoc types:
2202
2222
 
2203
2223
  ```js
2204
2224
  /**
2205
- * - jsRuntime extention naming convention;
2206
- * @typedef {`.${string}`} ExtnameType
2225
+ * - return type of Q callback;
2226
+ * @typedef {{resume:()=>void, isLastOnQ:boolean}} QCBReturn
2207
2227
  */
2208
2228
  ```
2209
2229
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
package/index.mjs CHANGED
@@ -41,20 +41,20 @@ export { WriteFileSafe } from './src/function/WriteFileSafe.mjs';
41
41
  * @typedef {import('./src/types/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
42
42
  */
43
43
  /**
44
- * @typedef {import('./src/types/QCBReturn.mjs').QCBReturn} QCBReturn
44
+ * @typedef {import('./src/types/ExtnameType.mjs').ExtnameType} ExtnameType
45
45
  */
46
46
  /**
47
- * @typedef {import('./src/types/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
47
+ * @typedef {import('./src/types/IsListSignal.mjs').IsListSignal} IsListSignal
48
48
  */
49
49
  /**
50
- * @typedef {import('./src/types/MutationType.mjs').MutationType} MutationType
50
+ * @typedef {import('./src/types/ListArg.mjs').ListArg} ListArg
51
51
  */
52
52
  /**
53
- * @typedef {import('./src/types/ListArg.mjs').ListArg} ListArg
53
+ * @typedef {import('./src/types/MutationType.mjs').MutationType} MutationType
54
54
  */
55
55
  /**
56
- * @typedef {import('./src/types/IsListSignal.mjs').IsListSignal} IsListSignal
56
+ * @typedef {import('./src/types/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
57
57
  */
58
58
  /**
59
- * @typedef {import('./src/types/ExtnameType.mjs').ExtnameType} ExtnameType
59
+ * @typedef {import('./src/types/QCBReturn.mjs').QCBReturn} QCBReturn
60
60
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "extremely simple signal as library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
@@ -16,9 +16,18 @@ export class Paths {
16
16
  * @description
17
17
  * @param {Object} options
18
18
  * @param {string} options.root
19
- * - browser: location.origin
20
- * - node/bun compatible: process?.env?.INIT_CWD ?? process?.cwd();
21
- * - deno: Deno.env.get("INIT_CWD") ?? Deno.cwd(); need for `deno run --allow-env --allow-read your_script.ts`
19
+ * - browser:
20
+ * ```js
21
+ * location.origin
22
+ * ```
23
+ * - node/bun compatible:
24
+ * ```js
25
+ * process?.env?.INIT_CWD ?? process?.cwd()
26
+ * ```
27
+ * - deno: need for `deno run --allow-env --allow-read your_script.ts`:
28
+ * ```js
29
+ * Deno.env.get("INIT_CWD") ?? Deno.cwd()
30
+ * ```
22
31
  * - other: you need to check your JSRuntime for the rootPath reference;
23
32
  * @example
24
33
  * import { Paths } from 'vivth';
@@ -17,15 +17,17 @@ export class Setup {
17
17
  * import { Setup, Console } from 'vivth';
18
18
  *
19
19
  * new Setup.safeExit({
20
- * // exitEventNames are blank by default, you need to manually name them all;
21
- * exitEventNames: ['SIGINT', 'SIGTERM', ...otherExitEventNames],
20
+ * // eventNames are blank by default, you need to manually name them all;
21
+ * // 'exit' will be omited, as it might cause async callbacks failed to execute;
22
+ * eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
23
+ * terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
22
24
  * // optional deno example
23
- * exitCallbackListeners = (eventName) => {
25
+ * listener = (eventName) => {
24
26
  * const sig = Deno.signal(eventName);
25
27
  * for await (const _ of sig) {
26
- * SafeExit.instance.exiting.correction(true);
28
+ * exiting.correction(true);
27
29
  * sig.dispose();
28
- * Console.info(`safe exit via "${eventName}"`);
30
+ * Console.log(`safe exit via "${eventName}"`);
29
31
  * }
30
32
  * }
31
33
  * });
@@ -65,7 +67,7 @@ export class Setup {
65
67
  * @example
66
68
  * import { Setup } from 'vivth';
67
69
  *
68
- * Setup.workerThread({ parentPort: async () => await import('node:worker_threads') });
70
+ * Setup.workerThread({ parentPort: async () => (await import('node:worker_threads')).parentPort });
69
71
  * // that is the default value, if your parentPort/equivalent API is not that;
70
72
  * // you need to call this method;
71
73
  */
@@ -31,12 +31,18 @@ export class WorkerMainThread {
31
31
  * - need to be called first, before any `WorkerMainThread` instantiation:
32
32
  * @param {Object} param0
33
33
  * @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
34
+ * - example:
35
+ * ```js
36
+ * async () => await (import('worker_threads')).Worker
37
+ * ```
34
38
  * @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
39
+ * - example:
35
40
  * ```js
36
- * async(relativePath) => {
37
- * // verify whether relativePath exist, then return the full path
38
- * // use fetch | fs, chained with Paths.instance.root + WorkerMainThread.basePath;
39
- * }
41
+ * async (workerPath, root, base) => {
42
+ * const res = await fetch(`${root}/${base}/${workerPath}`);
43
+ * // might also check wheter it need base or not
44
+ * return await res.ok;
45
+ * }
40
46
  * ```
41
47
  * @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
42
48
  * - additonal realtivePath from rootPath;
@@ -28,12 +28,15 @@ export class WorkerThread {
28
28
  * @template Receive_
29
29
  * @template Post_
30
30
  * @param {{parentPort:()=>Promise<any>}} parentPortRef
31
- * - correct parentPort reference;
31
+ * - correct parentPort reference, example:
32
+ * ```js
33
+ * async () => (await import('node:worker_threads')).parentPort
34
+ * ```
32
35
  * @returns {typeof WorkerThread<Receive_, Post_>}
33
36
  * @example
34
37
  * import { WorkerThread } from 'vivth';
35
38
  *
36
- * WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
39
+ * WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
37
40
  * // that is the default value, if your parentPort/equivalent API is not that;
38
41
  * // you need to call this method;
39
42
  */
package/types/index.d.mts CHANGED
@@ -30,9 +30,9 @@ export { TrySync } from "./src/function/TrySync.mjs";
30
30
  export { TsToMjs } from "./src/function/TsToMjs.mjs";
31
31
  export { WriteFileSafe } from "./src/function/WriteFileSafe.mjs";
32
32
  export type AnyButUndefined = import("./src/types/AnyButUndefined.mjs").AnyButUndefined;
33
- export type QCBReturn = import("./src/types/QCBReturn.mjs").QCBReturn;
34
- export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
35
- export type MutationType = import("./src/types/MutationType.mjs").MutationType;
36
- export type ListArg = import("./src/types/ListArg.mjs").ListArg;
37
- export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
38
33
  export type ExtnameType = import("./src/types/ExtnameType.mjs").ExtnameType;
34
+ export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
35
+ export type ListArg = import("./src/types/ListArg.mjs").ListArg;
36
+ export type MutationType = import("./src/types/MutationType.mjs").MutationType;
37
+ export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
38
+ export type QCBReturn = import("./src/types/QCBReturn.mjs").QCBReturn;
@@ -32,9 +32,18 @@ export class Paths {
32
32
  * @description
33
33
  * @param {Object} options
34
34
  * @param {string} options.root
35
- * - browser: location.origin
36
- * - node/bun compatible: process?.env?.INIT_CWD ?? process?.cwd();
37
- * - deno: Deno.env.get("INIT_CWD") ?? Deno.cwd(); need for `deno run --allow-env --allow-read your_script.ts`
35
+ * - browser:
36
+ * ```js
37
+ * location.origin
38
+ * ```
39
+ * - node/bun compatible:
40
+ * ```js
41
+ * process?.env?.INIT_CWD ?? process?.cwd()
42
+ * ```
43
+ * - deno: need for `deno run --allow-env --allow-read your_script.ts`:
44
+ * ```js
45
+ * Deno.env.get("INIT_CWD") ?? Deno.cwd()
46
+ * ```
38
47
  * - other: you need to check your JSRuntime for the rootPath reference;
39
48
  * @example
40
49
  * import { Paths } from 'vivth';
@@ -10,15 +10,17 @@ export class Setup {
10
10
  * import { Setup, Console } from 'vivth';
11
11
  *
12
12
  * new Setup.safeExit({
13
- * // exitEventNames are blank by default, you need to manually name them all;
14
- * exitEventNames: ['SIGINT', 'SIGTERM', ...otherExitEventNames],
13
+ * // eventNames are blank by default, you need to manually name them all;
14
+ * // 'exit' will be omited, as it might cause async callbacks failed to execute;
15
+ * eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
16
+ * terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
15
17
  * // optional deno example
16
- * exitCallbackListeners = (eventName) => {
18
+ * listener = (eventName) => {
17
19
  * const sig = Deno.signal(eventName);
18
20
  * for await (const _ of sig) {
19
- * SafeExit.instance.exiting.correction(true);
21
+ * exiting.correction(true);
20
22
  * sig.dispose();
21
- * Console.info(`safe exit via "${eventName}"`);
23
+ * Console.log(`safe exit via "${eventName}"`);
22
24
  * }
23
25
  * }
24
26
  * });
@@ -62,7 +64,7 @@ export class Setup {
62
64
  * @example
63
65
  * import { Setup } from 'vivth';
64
66
  *
65
- * Setup.workerThread({ parentPort: async () => await import('node:worker_threads') });
67
+ * Setup.workerThread({ parentPort: async () => (await import('node:worker_threads')).parentPort });
66
68
  * // that is the default value, if your parentPort/equivalent API is not that;
67
69
  * // you need to call this method;
68
70
  */
@@ -17,12 +17,18 @@ export class WorkerMainThread<WT extends WorkerThread> {
17
17
  * - need to be called first, before any `WorkerMainThread` instantiation:
18
18
  * @param {Object} param0
19
19
  * @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
20
+ * - example:
21
+ * ```js
22
+ * async () => await (import('worker_threads')).Worker
23
+ * ```
20
24
  * @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
25
+ * - example:
21
26
  * ```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
- * }
27
+ * async (workerPath, root, base) => {
28
+ * const res = await fetch(`${root}/${base}/${workerPath}`);
29
+ * // might also check wheter it need base or not
30
+ * return await res.ok;
31
+ * }
26
32
  * ```
27
33
  * @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
28
34
  * - additonal realtivePath from rootPath;
@@ -17,12 +17,15 @@ export class WorkerThread<Receive, Post> {
17
17
  * @template Receive_
18
18
  * @template Post_
19
19
  * @param {{parentPort:()=>Promise<any>}} parentPortRef
20
- * - correct parentPort reference;
20
+ * - correct parentPort reference, example:
21
+ * ```js
22
+ * async () => (await import('node:worker_threads')).parentPort
23
+ * ```
21
24
  * @returns {typeof WorkerThread<Receive_, Post_>}
22
25
  * @example
23
26
  * import { WorkerThread } from 'vivth';
24
27
  *
25
- * WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
28
+ * WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
26
29
  * // that is the default value, if your parentPort/equivalent API is not that;
27
30
  * // you need to call this method;
28
31
  */