vivth 0.11.1 → 1.0.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.
Files changed (107) hide show
  1. package/.vivth/dist/init.mjs +24 -0
  2. package/README.md +2157 -69
  3. package/README.src.md +35 -0
  4. package/bun.lock +57 -3
  5. package/dev/index.mjs +24 -25
  6. package/index.mjs +51 -29
  7. package/package.json +11 -7
  8. package/src/bundler/CompileMJS.mjs +110 -0
  9. package/src/bundler/EsBundler.mjs +79 -0
  10. package/src/class/Console.mjs +62 -0
  11. package/src/class/Derived.mjs +37 -21
  12. package/src/class/Effect.mjs +106 -0
  13. package/src/class/EnvSignal.mjs +88 -0
  14. package/src/class/EventSignal.mjs +200 -0
  15. package/src/class/ListDerived.mjs +39 -0
  16. package/src/class/ListSignal.mjs +256 -0
  17. package/src/class/Paths.mjs +70 -0
  18. package/src/class/QChannel.mjs +184 -0
  19. package/src/class/SafeExit.mjs +131 -0
  20. package/src/class/Setup.mjs +73 -0
  21. package/src/class/Signal.mjs +152 -54
  22. package/src/class/WorkerMainThread.mjs +328 -0
  23. package/src/class/WorkerResult.mjs +30 -0
  24. package/src/class/WorkerThread.mjs +151 -0
  25. package/src/common/Base64URL.mjs +26 -0
  26. package/src/common/EventNameSpace.mjs +8 -0
  27. package/src/common/eventObjects.mjs +5 -0
  28. package/src/common/lazie.mjs +3 -0
  29. package/src/doc/JSautoDOC.mjs +386 -0
  30. package/src/doc/parsedFile.mjs +537 -0
  31. package/src/function/CreateImmutable.mjs +64 -0
  32. package/src/function/EventCheck.mjs +27 -0
  33. package/src/function/EventObject.mjs +21 -0
  34. package/src/function/IsAsync.mjs +23 -0
  35. package/src/function/LazyFactory.mjs +71 -0
  36. package/src/function/Timeout.mjs +23 -0
  37. package/src/function/Try.mjs +64 -0
  38. package/src/function/TryAsync.mjs +15 -4
  39. package/src/function/TrySync.mjs +9 -4
  40. package/src/function/TsToMjs.mjs +67 -0
  41. package/src/function/WriteFileSafe.mjs +37 -0
  42. package/src/types/{AnyButUndefined.type.mjs → AnyButUndefined.mjs} +1 -0
  43. package/src/types/ExtnameType.mjs +6 -0
  44. package/src/types/IsListSignal.mjs +6 -0
  45. package/src/types/ListArg.mjs +6 -0
  46. package/src/types/MutationType.mjs +8 -0
  47. package/src/types/QCBFIFOReturn.mjs +6 -0
  48. package/src/types/QCBReturn.mjs +6 -0
  49. package/tsconfig.json +3 -3
  50. package/types/dev/index.d.mts +1 -0
  51. package/types/index.d.mts +34 -8
  52. package/types/src/bundler/A.d.mts +1 -0
  53. package/types/src/bundler/CompileMJS.d.mts +8 -0
  54. package/types/src/bundler/EsBundler.d.mts +7 -0
  55. package/types/src/class/Console.d.mts +40 -0
  56. package/types/src/class/Derived.d.mts +21 -7
  57. package/types/src/class/Effect.d.mts +77 -0
  58. package/types/src/class/EnvSignal.d.mts +47 -0
  59. package/types/src/class/EventSignal.d.mts +145 -0
  60. package/types/src/class/ListDerived.d.mts +35 -0
  61. package/types/src/class/ListSignal.d.mts +150 -0
  62. package/types/src/class/Paths.d.mts +50 -0
  63. package/types/src/class/QChannel.d.mts +115 -0
  64. package/types/src/class/SafeExit.d.mts +76 -0
  65. package/types/src/class/Setup.d.mts +76 -0
  66. package/types/src/class/Signal.d.mts +105 -26
  67. package/types/src/class/WorkerMainThread.d.mts +149 -0
  68. package/types/src/class/WorkerResult.d.mts +25 -0
  69. package/types/src/class/WorkerThread.d.mts +70 -0
  70. package/types/src/common/Base64URL.d.mts +1 -0
  71. package/types/src/common/EventNameSpace.d.mts +6 -0
  72. package/types/src/common/eventObjects.d.mts +3 -0
  73. package/types/src/common/lazie.d.mts +1 -0
  74. package/types/src/doc/JSautoDOC.d.mts +76 -0
  75. package/types/src/doc/parsedFile.d.mts +154 -0
  76. package/types/src/function/CreateImmutable.d.mts +3 -0
  77. package/types/src/function/EventCheck.d.mts +2 -0
  78. package/types/src/function/EventObject.d.mts +4 -0
  79. package/types/src/function/IsAsync.d.mts +1 -0
  80. package/types/src/function/LazyFactory.d.mts +4 -0
  81. package/types/src/function/Timeout.d.mts +1 -0
  82. package/types/src/function/Try.d.mts +1 -0
  83. package/types/src/function/TsToMjs.d.mts +4 -0
  84. package/types/src/function/WriteFileSafe.d.mts +2 -0
  85. package/types/src/types/{AnyButUndefined.type.d.mts → AnyButUndefined.d.mts} +3 -0
  86. package/types/src/types/ExtnameType.d.mts +4 -0
  87. package/types/src/types/IsListSignal.d.mts +4 -0
  88. package/types/src/types/ListArg.d.mts +4 -0
  89. package/types/src/types/MutationType.d.mts +5 -0
  90. package/types/src/types/QCBFIFOReturn.d.mts +4 -0
  91. package/types/src/types/QCBReturn.d.mts +7 -0
  92. package/src/class/$.mjs +0 -68
  93. package/src/class/PingFIFO.mjs +0 -78
  94. package/src/class/PingUnique.mjs +0 -84
  95. package/src/class/Q.mjs +0 -98
  96. package/src/class/QFIFO.mjs +0 -66
  97. package/src/class/QUnique.mjs +0 -75
  98. package/src/common.mjs +0 -16
  99. package/src/function/NewQBlock.mjs +0 -39
  100. package/types/src/class/$.d.mts +0 -38
  101. package/types/src/class/PingFIFO.d.mts +0 -57
  102. package/types/src/class/PingUnique.d.mts +0 -48
  103. package/types/src/class/Q.d.mts +0 -63
  104. package/types/src/class/QFIFO.d.mts +0 -47
  105. package/types/src/class/QUnique.d.mts +0 -46
  106. package/types/src/common.d.mts +0 -2
  107. package/types/src/function/NewQBlock.d.mts +0 -1
package/README.src.md ADDED
@@ -0,0 +1,35 @@
1
+ ## HOW TO INSTALL
2
+
3
+ - example uses `npm`, you can allways use your own favourite package manager;
4
+
5
+ ```shell
6
+ npm i vivth
7
+ ```
8
+
9
+ ## vivth
10
+
11
+ - `vivth` are intended to be a collections of usefull `primitives`, and not to be directly used as
12
+ underlying framework;
13
+ - completely `JSruntime` agnostic:
14
+ > - instead of `vivth` trying to guess, all runtime specific API should be provided by dev;
15
+ - contains helpers to help you write data driven javascript program, including:
16
+ > - collections of extremely ⚡ performant `signal` classes;
17
+ > > - `vivth` deliberately take away `auto-subscription`:
18
+ > > > - and introducing more imperative way of subsrciption yet still simple enough, which in
19
+ > > > turn, it completely removes total code blocking on previously needed auto subsrciption
20
+ > > > process on first run;
21
+ > > > - and also make previously unthinkable dynamic subscription on conditionals that runs
22
+ > > > outside first run, now completely possible;
23
+ > - collections of `queue-helper` classes;
24
+ > - fully typed `worker-threads` abstraction;
25
+ > - ` error as value` function helper;
26
+ > - opionated `autoDocumentation`;
27
+ > - opionated `bundler`;
28
+
29
+ ## versions:
30
+
31
+ - `1.0.0:b`:
32
+ > - beta release;
33
+ > - checking edge cases;
34
+ > - stable API, the exposed API access are highly unlikely to changes, only the underlying code
35
+ > might changes for improving performance;
package/bun.lock CHANGED
@@ -3,18 +3,70 @@
3
3
  "workspaces": {
4
4
  "": {
5
5
  "name": "vivth",
6
+ "dependencies": {
7
+ "chokidar": "^4.0.3",
8
+ "esbuild": "^0.25.9",
9
+ },
6
10
  "devDependencies": {
7
- "@html_first/js_lib_template": "link:@html_first/js_lib_template",
8
11
  "@html_first/simple_queue": "^1.3.1",
9
12
  "@types/bun": "latest",
10
- "chokidar": "^4.0.3",
11
13
  "concurrently": "^9.1.2",
12
14
  "typescript": "^5.8.3",
13
15
  },
14
16
  },
15
17
  },
16
18
  "packages": {
17
- "@html_first/js_lib_template": ["@html_first/js_lib_template@link:@html_first/js_lib_template", {}],
19
+ "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.9", "", { "os": "aix", "cpu": "ppc64" }, "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA=="],
20
+
21
+ "@esbuild/android-arm": ["@esbuild/android-arm@0.25.9", "", { "os": "android", "cpu": "arm" }, "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ=="],
22
+
23
+ "@esbuild/android-arm64": ["@esbuild/android-arm64@0.25.9", "", { "os": "android", "cpu": "arm64" }, "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg=="],
24
+
25
+ "@esbuild/android-x64": ["@esbuild/android-x64@0.25.9", "", { "os": "android", "cpu": "x64" }, "sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw=="],
26
+
27
+ "@esbuild/darwin-arm64": ["@esbuild/darwin-arm64@0.25.9", "", { "os": "darwin", "cpu": "arm64" }, "sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg=="],
28
+
29
+ "@esbuild/darwin-x64": ["@esbuild/darwin-x64@0.25.9", "", { "os": "darwin", "cpu": "x64" }, "sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ=="],
30
+
31
+ "@esbuild/freebsd-arm64": ["@esbuild/freebsd-arm64@0.25.9", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q=="],
32
+
33
+ "@esbuild/freebsd-x64": ["@esbuild/freebsd-x64@0.25.9", "", { "os": "freebsd", "cpu": "x64" }, "sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg=="],
34
+
35
+ "@esbuild/linux-arm": ["@esbuild/linux-arm@0.25.9", "", { "os": "linux", "cpu": "arm" }, "sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw=="],
36
+
37
+ "@esbuild/linux-arm64": ["@esbuild/linux-arm64@0.25.9", "", { "os": "linux", "cpu": "arm64" }, "sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw=="],
38
+
39
+ "@esbuild/linux-ia32": ["@esbuild/linux-ia32@0.25.9", "", { "os": "linux", "cpu": "ia32" }, "sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A=="],
40
+
41
+ "@esbuild/linux-loong64": ["@esbuild/linux-loong64@0.25.9", "", { "os": "linux", "cpu": "none" }, "sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ=="],
42
+
43
+ "@esbuild/linux-mips64el": ["@esbuild/linux-mips64el@0.25.9", "", { "os": "linux", "cpu": "none" }, "sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA=="],
44
+
45
+ "@esbuild/linux-ppc64": ["@esbuild/linux-ppc64@0.25.9", "", { "os": "linux", "cpu": "ppc64" }, "sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w=="],
46
+
47
+ "@esbuild/linux-riscv64": ["@esbuild/linux-riscv64@0.25.9", "", { "os": "linux", "cpu": "none" }, "sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg=="],
48
+
49
+ "@esbuild/linux-s390x": ["@esbuild/linux-s390x@0.25.9", "", { "os": "linux", "cpu": "s390x" }, "sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA=="],
50
+
51
+ "@esbuild/linux-x64": ["@esbuild/linux-x64@0.25.9", "", { "os": "linux", "cpu": "x64" }, "sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg=="],
52
+
53
+ "@esbuild/netbsd-arm64": ["@esbuild/netbsd-arm64@0.25.9", "", { "os": "none", "cpu": "arm64" }, "sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q=="],
54
+
55
+ "@esbuild/netbsd-x64": ["@esbuild/netbsd-x64@0.25.9", "", { "os": "none", "cpu": "x64" }, "sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g=="],
56
+
57
+ "@esbuild/openbsd-arm64": ["@esbuild/openbsd-arm64@0.25.9", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ=="],
58
+
59
+ "@esbuild/openbsd-x64": ["@esbuild/openbsd-x64@0.25.9", "", { "os": "openbsd", "cpu": "x64" }, "sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA=="],
60
+
61
+ "@esbuild/openharmony-arm64": ["@esbuild/openharmony-arm64@0.25.9", "", { "os": "none", "cpu": "arm64" }, "sha512-4Xd0xNiMVXKh6Fa7HEJQbrpP3m3DDn43jKxMjxLLRjWnRsfxjORYJlXPO4JNcXtOyfajXorRKY9NkOpTHptErg=="],
62
+
63
+ "@esbuild/sunos-x64": ["@esbuild/sunos-x64@0.25.9", "", { "os": "sunos", "cpu": "x64" }, "sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw=="],
64
+
65
+ "@esbuild/win32-arm64": ["@esbuild/win32-arm64@0.25.9", "", { "os": "win32", "cpu": "arm64" }, "sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ=="],
66
+
67
+ "@esbuild/win32-ia32": ["@esbuild/win32-ia32@0.25.9", "", { "os": "win32", "cpu": "ia32" }, "sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww=="],
68
+
69
+ "@esbuild/win32-x64": ["@esbuild/win32-x64@0.25.9", "", { "os": "win32", "cpu": "x64" }, "sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ=="],
18
70
 
19
71
  "@html_first/simple_queue": ["@html_first/simple_queue@1.3.1", "", {}, "sha512-YidSXC9aTa0iQAxOA9NIAQWtKp/PU6IwLU+tvlDV62FAy2vwa3/SdpvaMFkBS+3/3t0qOKQ8mZYesDWdhY9Yig=="],
20
72
 
@@ -44,6 +96,8 @@
44
96
 
45
97
  "emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
46
98
 
99
+ "esbuild": ["esbuild@0.25.9", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.9", "@esbuild/android-arm": "0.25.9", "@esbuild/android-arm64": "0.25.9", "@esbuild/android-x64": "0.25.9", "@esbuild/darwin-arm64": "0.25.9", "@esbuild/darwin-x64": "0.25.9", "@esbuild/freebsd-arm64": "0.25.9", "@esbuild/freebsd-x64": "0.25.9", "@esbuild/linux-arm": "0.25.9", "@esbuild/linux-arm64": "0.25.9", "@esbuild/linux-ia32": "0.25.9", "@esbuild/linux-loong64": "0.25.9", "@esbuild/linux-mips64el": "0.25.9", "@esbuild/linux-ppc64": "0.25.9", "@esbuild/linux-riscv64": "0.25.9", "@esbuild/linux-s390x": "0.25.9", "@esbuild/linux-x64": "0.25.9", "@esbuild/netbsd-arm64": "0.25.9", "@esbuild/netbsd-x64": "0.25.9", "@esbuild/openbsd-arm64": "0.25.9", "@esbuild/openbsd-x64": "0.25.9", "@esbuild/openharmony-arm64": "0.25.9", "@esbuild/sunos-x64": "0.25.9", "@esbuild/win32-arm64": "0.25.9", "@esbuild/win32-ia32": "0.25.9", "@esbuild/win32-x64": "0.25.9" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g=="],
100
+
47
101
  "escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="],
48
102
 
49
103
  "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="],
package/dev/index.mjs CHANGED
@@ -1,28 +1,27 @@
1
1
  // @ts-check
2
2
 
3
- import { __JSDev } from '@html_first/js_lib_template';
3
+ import { Console } from '../src/class/Console.mjs';
4
+ import { Setup } from '../src/class/Setup.mjs';
5
+ import { JSautoDOC } from '../src/doc/JSautoDOC.mjs';
4
6
 
5
- new __JSDev({
6
- filePath: './index.mjs',
7
- folderPath: './src',
8
- readMePath: './README.md',
9
- copyright: ['developed and published under MIT license,'],
10
- description: [
11
- '## HOW TO INSTALL',
12
- '```shell',
13
- 'npm i vivth',
14
- '```',
15
- '```shell',
16
- 'bun i vivth',
17
- '```',
18
- '',
19
- '## vivth',
20
- '- contains helpers to help you write autosubscriber pattern javascript program, including:',
21
- '>- collections of signal based functions and classes;',
22
- '>- collections of queue helper functions and classes;',
23
- '',
24
- '- `vivth` technically can run in any `js runtime`, since it uses non platform specific api;',
25
- '- it is written specifically to be used as a primitives for javascript library or runtime, so there are no complex abstraction is, nor will be, added in `vivth` it self;',
26
- '',
27
- ],
28
- }).run();
7
+ const { paths, safeExit } = Setup;
8
+
9
+ new paths({
10
+ root: process?.env?.INIT_CWD ?? process?.cwd(),
11
+ });
12
+
13
+ new safeExit({
14
+ exitEventNames: ['SIGINT', 'SIGTERM', 'exit'],
15
+ exitCallbackListeners: (eventName) => {
16
+ process.once(eventName, function () {
17
+ safeExit.instance.exiting.correction(true);
18
+ Console.log(`safe exit via "${eventName}"`);
19
+ });
20
+ },
21
+ });
22
+
23
+ new JSautoDOC({
24
+ paths: { dir: 'src', file: 'index.mjs', readMe: 'README.md' },
25
+ copyright: 'this library is made and distributed under MIT license;',
26
+ tableOfContentTitle: 'list of exported API and typehelpers',
27
+ });
package/index.mjs CHANGED
@@ -1,38 +1,60 @@
1
1
  // @ts-check
2
+
2
3
  /**
3
- * generated using:
4
- * @see {@link https://www.npmjs.com/package/@html_first/js_lib_template | @html_first/js_lib_template}
4
+ * automatically generated by `vivth.MJSautoDOC`
5
5
  * @copyright
6
- * developed and published under MIT license,
7
- * @description
8
- * ## HOW TO INSTALL
9
- * ```shell
10
- * npm i vivth
11
- * ```
12
- * ```shell
13
- * bun i vivth
14
- * ```
15
- *
16
- * ## vivth
17
- * - contains helpers to help you write autosubscriber pattern javascript program, including:
18
- * >- collections of signal based functions and classes;
19
- * >- collections of queue helper functions and classes;
20
- *
21
- * - `vivth` technically can run in any `js runtime`, since it uses non platform specific api;
22
- * - it is written specifically to be used as a primitives for javascript library or runtime, so there are no complex abstraction is, nor will be, added in `vivth` it self;
23
- *
6
+ * this library is made and distributed under MIT license;
24
7
  */
25
- export { $ } from './src/class/$.mjs';
8
+
9
+ export { CompileMJS } from './src/bundler/CompileMJS.mjs';
10
+ export { EsBundler } from './src/bundler/EsBundler.mjs';
11
+ export { Console } from './src/class/Console.mjs';
26
12
  export { Derived } from './src/class/Derived.mjs';
27
- export { PingFIFO } from './src/class/PingFIFO.mjs';
28
- export { PingUnique } from './src/class/PingUnique.mjs';
29
- export { Q } from './src/class/Q.mjs';
30
- export { QFIFO } from './src/class/QFIFO.mjs';
31
- export { QUnique } from './src/class/QUnique.mjs';
13
+ export { Effect } from './src/class/Effect.mjs';
14
+ export { EnvSignal } from './src/class/EnvSignal.mjs';
15
+ export { EventSignal } from './src/class/EventSignal.mjs';
16
+ export { ListDerived } from './src/class/ListDerived.mjs';
17
+ export { ListSignal } from './src/class/ListSignal.mjs';
18
+ export { Paths } from './src/class/Paths.mjs';
19
+ export { QChannel } from './src/class/QChannel.mjs';
20
+ export { SafeExit } from './src/class/SafeExit.mjs';
21
+ export { Setup } from './src/class/Setup.mjs';
32
22
  export { Signal } from './src/class/Signal.mjs';
33
- export { NewQBlock } from './src/function/NewQBlock.mjs';
23
+ export { WorkerMainThread } from './src/class/WorkerMainThread.mjs';
24
+ export { WorkerResult } from './src/class/WorkerResult.mjs';
25
+ export { WorkerThread } from './src/class/WorkerThread.mjs';
26
+ export { Base64URL } from './src/common/Base64URL.mjs';
27
+ export { EventNameSpace } from './src/common/EventNameSpace.mjs';
28
+ export { JSautoDOC } from './src/doc/JSautoDOC.mjs';
29
+ export { CreateImmutable } from './src/function/CreateImmutable.mjs';
30
+ export { EventCheck } from './src/function/EventCheck.mjs';
31
+ export { EventObject } from './src/function/EventObject.mjs';
32
+ export { IsAsync } from './src/function/IsAsync.mjs';
33
+ export { LazyFactory } from './src/function/LazyFactory.mjs';
34
+ export { Timeout } from './src/function/Timeout.mjs';
35
+ export { Try } from './src/function/Try.mjs';
34
36
  export { TryAsync } from './src/function/TryAsync.mjs';
35
37
  export { TrySync } from './src/function/TrySync.mjs';
36
- /**
37
- * @typedef {{}|null|number|string|boolean|symbol|bigint|function} AnyButUndefined
38
+ export { TsToMjs } from './src/function/TsToMjs.mjs';
39
+ export { WriteFileSafe } from './src/function/WriteFileSafe.mjs';
40
+ /**
41
+ * @typedef {import('./src/types/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
42
+ */
43
+ /**
44
+ * @typedef {import('./src/types/ExtnameType.mjs').ExtnameType} ExtnameType
45
+ */
46
+ /**
47
+ * @typedef {import('./src/types/IsListSignal.mjs').IsListSignal} IsListSignal
48
+ */
49
+ /**
50
+ * @typedef {import('./src/types/ListArg.mjs').ListArg} ListArg
51
+ */
52
+ /**
53
+ * @typedef {import('./src/types/MutationType.mjs').MutationType} MutationType
54
+ */
55
+ /**
56
+ * @typedef {import('./src/types/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
57
+ */
58
+ /**
59
+ * @typedef {import('./src/types/QCBReturn.mjs').QCBReturn} QCBReturn
38
60
  */
package/package.json CHANGED
@@ -1,20 +1,19 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "0.11.1",
3
+ "version": "1.0.0",
4
4
  "description": "extremely simple signal as library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
7
- "scripts": {
8
- "dev": "concurrently 'bun --watch ./dev/index.mjs' 'bun tsc --watch'"
9
- },
10
7
  "devDependencies": {
11
- "@html_first/js_lib_template": "link:@html_first/js_lib_template",
12
8
  "typescript": "^5.8.3",
13
9
  "@html_first/simple_queue": "^1.3.1",
14
10
  "concurrently": "^9.1.2",
15
- "chokidar": "^4.0.3",
16
11
  "@types/bun": "latest"
17
12
  },
13
+ "dependencies": {
14
+ "chokidar": "^4.0.3",
15
+ "esbuild": "^0.25.9"
16
+ },
18
17
  "peerDependencies": {},
19
18
  "repository": {
20
19
  "type": "git",
@@ -22,7 +21,8 @@
22
21
  },
23
22
  "keywords": [
24
23
  "simple",
25
- "signal"
24
+ "signal",
25
+ "data driven"
26
26
  ],
27
27
  "author": "hakim_jazuli",
28
28
  "license": "MIT",
@@ -30,5 +30,9 @@
30
30
  "url": "https://github.com/hakimjazuli/vivth/issues"
31
31
  },
32
32
  "homepage": "https://github.com/hakimjazuli/vivth#readme",
33
+ "scripts": {
34
+ "dev": "concurrently 'bun --watch ./dev/index.mjs'",
35
+ "typed": "bun tsc --watch"
36
+ },
33
37
  "sideEffects": false
34
38
  }
@@ -0,0 +1,110 @@
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
+ };
@@ -0,0 +1,79 @@
1
+ // @ts-check
2
+
3
+ import { build } from 'esbuild';
4
+
5
+ import { Console } from '../class/Console.mjs';
6
+ import { Paths } from '../class/Paths.mjs';
7
+ import { TryAsync } from '../function/TryAsync.mjs';
8
+
9
+ /**
10
+ * @description
11
+ * - opinionated bundler for extension below using esbuild;
12
+ * - bundles all imports into a single output string;
13
+ * @param {Object} options
14
+ * @param {string} options.content
15
+ * - the code can also uses composites from the result from multiple readFiles;
16
+ * - the import statements on the content should use absolute path from project root, prefixed with forward slash;
17
+ * @param {string} options.extension
18
+ * @param {boolean} [options.asBinary]
19
+ * @param {Omit<Parameters<build>[0], 'entryPoints'|'bundle'|'write'|'format'|'sourcemap'|'external'|'stdin'>} [esbuildOptions]
20
+ * @returns {Promise<ReturnType<typeof TryAsync<string>>>}
21
+ * @example
22
+ * import { EsBundler } from 'vivth';
23
+ *
24
+ * const bundledString = EsBundler(,
25
+ * {
26
+ * content: ``,
27
+ * extension: '.mts',
28
+ * ...options
29
+ * },
30
+ * {
31
+ * ...esbuildOptions,
32
+ * });
33
+ */
34
+ export const EsBundler = async ({ content, extension, asBinary = false }, esbuildOptions = {}) => {
35
+ return await TryAsync(async () => {
36
+ /** @type {Parameters<build>[0]['stdin']['loader']} */
37
+ let loader;
38
+ switch (extension) {
39
+ case '.mts':
40
+ case '.ts':
41
+ loader = 'ts';
42
+ break;
43
+ case '.mjs':
44
+ loader = 'js';
45
+ break;
46
+ default:
47
+ const error = {
48
+ extension,
49
+ message: 'Invalid extension passed to EsBundler',
50
+ acceptedextensions: ['.mts', '.ts', '.mjs'],
51
+ };
52
+ Console.error(error);
53
+ throw new Error(JSON.stringify(error));
54
+ }
55
+ const result = await build({
56
+ target: 'esnext',
57
+ platform: 'node',
58
+ ...esbuildOptions,
59
+ stdin: {
60
+ contents: content,
61
+ loader,
62
+ resolveDir: Paths.root,
63
+ },
64
+ format: 'esm',
65
+ bundle: true,
66
+ write: false,
67
+ sourcemap: false,
68
+ external: [],
69
+ banner: {
70
+ js: asBinary ? '#!/usr/bin/env node' : '',
71
+ },
72
+ });
73
+ if (result.warnings?.length) {
74
+ Console.warn(result.warnings.map((w) => w.text).join('\n'));
75
+ }
76
+ const resString = result.outputFiles?.[0]?.text;
77
+ return resString ?? '';
78
+ });
79
+ };
@@ -0,0 +1,62 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @description
5
+ * - class with static methods to print to standard console with added style;
6
+ */
7
+ export class Console {
8
+ /**
9
+ * @param {string} prefix
10
+ * @param {'log'|'info'|'error'|'warn'} mode
11
+ * - Console method to use
12
+ * @param {any} data
13
+ * @param {string} color
14
+ * @param {string} bgcolor
15
+ * @returns {void}
16
+ */
17
+ static #call = (prefix, mode, data, color, bgcolor) => {
18
+ /** @type {unknown} */
19
+ const fn = console[mode];
20
+ if (typeof fn !== 'function') {
21
+ return;
22
+ }
23
+ fn.call(
24
+ console,
25
+ `%c${prefix} ${mode.toUpperCase()}:`,
26
+ `color:${color};background:${bgcolor};padding:2px 6px;border-radius:4px;`,
27
+ data
28
+ );
29
+ };
30
+ /**
31
+ * @description
32
+ * @param {any} data
33
+ * @returns {void}
34
+ */
35
+ static log = (data) => {
36
+ Console.#call('🟢', 'log', data, 'white', '#2e7d32');
37
+ };
38
+ /**
39
+ * @description
40
+ * @param {any} data
41
+ * @returns {void}
42
+ */
43
+ static info = (data) => {
44
+ Console.#call('🔵', 'info', data, 'white', '#1565c0');
45
+ };
46
+ /**
47
+ * @description
48
+ * @param {any} data
49
+ * @returns {void}
50
+ */
51
+ static warn = (data) => {
52
+ Console.#call('🟠', 'warn', data, 'black', '#ffb300');
53
+ };
54
+ /**
55
+ * @description
56
+ * @param {any} data
57
+ * @returns {void}
58
+ */
59
+ static error = (data) => {
60
+ Console.#call('🔴', 'error', data, 'white', '#c62828');
61
+ };
62
+ }
@@ -1,48 +1,64 @@
1
1
  // @ts-check
2
2
 
3
3
  import { Signal } from './Signal.mjs';
4
- import { $ } from './$.mjs';
5
- import { isAsync } from '../common.mjs';
4
+ import { Effect } from './Effect.mjs';
5
+ import { Console } from './Console.mjs';
6
6
 
7
7
  /**
8
8
  * @description
9
- * - a class for creating signal which its value are derived from other signal (`Derived` and `Signal` alike);
10
- * - can be subscribed by using [New$](#new$);
11
- * - for minimal total bundle size use `function` [NewDerived](#newderived) instead;
12
- */
13
- /**
9
+ * - a class for creating derived version of [Signal](#signal);
14
10
  * @template V
15
11
  * @extends Signal<V>
16
12
  */
17
13
  export class Derived extends Signal {
18
14
  /**
19
- * @param {()=>V} derivedFunction
15
+ * @description
16
+ * - Derived used [Signal](#signal) and [Effect](#effect) under the hood;
17
+ * @param {(effectInstanceOptions:Effect["options"])=>Promise<V>} derivedFunction
18
+ * @example
19
+ * import { Signal, Derived } from 'vivth';
20
+ *
21
+ * const count = new Signal(0);
22
+ * const double = new Derived(async({
23
+ * subscribe,
24
+ * // : registrar callback for this derived instance, immediately return the signal instance
25
+ * }) => {
26
+ * return subscribe(count).value + count.value;
27
+ * // double listen to count changes, by returning the value, double.value also changes
28
+ * // notice the count.value are accessed double, but it's all safe,
29
+ * // since the wrapped one is the only one that are recorded as notifier.
30
+ * });
31
+ *
32
+ * count.value++;
20
33
  */
21
34
  constructor(derivedFunction) {
22
- // @ts-expect-error
23
- super(0);
24
- const real = isAsync(derivedFunction)
25
- ? async () => {
26
- super.value = await derivedFunction();
27
- }
28
- : () => {
29
- super.value = derivedFunction();
30
- };
31
- new $(real);
35
+ super(undefined);
36
+ new Effect(async (options) => {
37
+ super.value = await derivedFunction(options);
38
+ });
32
39
  }
33
40
  /**
41
+ * @description
42
+ * - the most recent value of the instance
43
+ * - can be turn into reactive with Effect or Derived instantiation;
34
44
  * @type {V}
35
45
  */
36
46
  get value() {
37
47
  return super.value;
38
48
  }
39
49
  /**
50
+ * @description
51
+ * - Derived instance value cannot be manually assigned;
52
+ * - it's value should always be determined by it's own `derivedFunction`;
40
53
  * @private
54
+ * @type {V}
41
55
  */
42
- set value(_) {
43
- console.warn({
56
+ set value(newValue) {
57
+ Console.warn({
58
+ newValue,
59
+ currentValue: super.value,
44
60
  derivedInstance: this,
45
- warning: 'NewDerived.value cannot be manually assigned',
61
+ warning: 'derivedInstance.value cannot be manually assigned',
46
62
  });
47
63
  }
48
64
  }