@vandenberghinc/volt 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.
Files changed (451) hide show
  1. package/.vrepo +28 -0
  2. package/.vscode/tasks.json +87 -0
  3. package/README.md +67 -0
  4. package/backend/dist/cjs/blacklist.d.ts +10 -0
  5. package/backend/dist/cjs/blacklist.js +53 -0
  6. package/backend/dist/cjs/cli.d.ts +2 -0
  7. package/backend/dist/cjs/cli.js +263 -0
  8. package/backend/dist/cjs/database.d.ts +364 -0
  9. package/backend/dist/cjs/database.js +1962 -0
  10. package/backend/dist/cjs/endpoint.d.ts +57 -0
  11. package/backend/dist/cjs/endpoint.js +425 -0
  12. package/backend/dist/cjs/file_watcher.d.ts +44 -0
  13. package/backend/dist/cjs/file_watcher.js +348 -0
  14. package/backend/dist/cjs/frontend.d.ts +13 -0
  15. package/backend/dist/cjs/frontend.js +30 -0
  16. package/backend/dist/cjs/image_endpoint.d.ts +24 -0
  17. package/backend/dist/cjs/image_endpoint.js +210 -0
  18. package/backend/dist/cjs/logger.d.ts +5 -0
  19. package/backend/dist/cjs/logger.js +16 -0
  20. package/backend/dist/cjs/meta.d.ts +50 -0
  21. package/backend/dist/cjs/meta.js +153 -0
  22. package/backend/dist/cjs/mutex.d.ts +24 -0
  23. package/backend/dist/cjs/mutex.js +52 -0
  24. package/backend/dist/cjs/package.json +1 -0
  25. package/backend/dist/cjs/payments/paddle.d.ts +161 -0
  26. package/backend/dist/cjs/payments/paddle.js +2301 -0
  27. package/backend/dist/cjs/plugins/browser.d.ts +36 -0
  28. package/backend/dist/cjs/plugins/browser.js +183 -0
  29. package/backend/dist/cjs/plugins/communication.d.ts +70 -0
  30. package/backend/dist/cjs/plugins/communication.js +177 -0
  31. package/backend/dist/cjs/plugins/css.d.ts +10 -0
  32. package/backend/dist/cjs/plugins/css.js +71 -0
  33. package/backend/dist/cjs/plugins/mail.d.ts +277 -0
  34. package/backend/dist/cjs/plugins/mail.js +1419 -0
  35. package/backend/dist/cjs/plugins/pdf.d.ts +757 -0
  36. package/backend/dist/cjs/plugins/pdf.js +1694 -0
  37. package/backend/dist/cjs/plugins/thread_monitor.d.ts +18 -0
  38. package/backend/dist/cjs/plugins/thread_monitor.js +127 -0
  39. package/backend/dist/cjs/plugins/ts/compiler.d.ts +132 -0
  40. package/backend/dist/cjs/plugins/ts/compiler.js +944 -0
  41. package/backend/dist/cjs/plugins/ts/preprocessing.d.ts +14 -0
  42. package/backend/dist/cjs/plugins/ts/preprocessing.js +762 -0
  43. package/backend/dist/cjs/rate_limit.d.ts +65 -0
  44. package/backend/dist/cjs/rate_limit.js +463 -0
  45. package/backend/dist/cjs/request.deprc.d.ts +48 -0
  46. package/backend/dist/cjs/request.deprc.js +572 -0
  47. package/backend/dist/cjs/response.deprc.d.ts +55 -0
  48. package/backend/dist/cjs/response.deprc.js +275 -0
  49. package/backend/dist/cjs/server.d.ts +311 -0
  50. package/backend/dist/cjs/server.js +3475 -0
  51. package/backend/dist/cjs/splash_screen.d.ts +35 -0
  52. package/backend/dist/cjs/splash_screen.js +152 -0
  53. package/backend/dist/cjs/status.d.ts +60 -0
  54. package/backend/dist/cjs/status.js +199 -0
  55. package/backend/dist/cjs/stream.d.ts +75 -0
  56. package/backend/dist/cjs/stream.js +954 -0
  57. package/backend/dist/cjs/users.d.ts +111 -0
  58. package/backend/dist/cjs/users.js +1945 -0
  59. package/backend/dist/cjs/utils.d.ts +27 -0
  60. package/backend/dist/cjs/utils.js +329 -0
  61. package/backend/dist/cjs/view.d.ts +52 -0
  62. package/backend/dist/cjs/view.js +568 -0
  63. package/backend/dist/cjs/vinc.d.ts +2 -0
  64. package/backend/dist/cjs/vinc.dev.d.ts +2 -0
  65. package/backend/dist/cjs/vinc.dev.js +42 -0
  66. package/backend/dist/cjs/vinc.js +42 -0
  67. package/backend/dist/cjs/volt.d.ts +15 -0
  68. package/backend/dist/cjs/volt.js +64 -0
  69. package/backend/dist/css/adyen.css +92 -0
  70. package/backend/dist/css/volt.css +65 -0
  71. package/backend/dist/esm/blacklist.d.ts +10 -0
  72. package/backend/dist/esm/blacklist.js +49 -0
  73. package/backend/dist/esm/cli.d.ts +2 -0
  74. package/backend/dist/esm/cli.js +228 -0
  75. package/backend/dist/esm/database.d.ts +364 -0
  76. package/backend/dist/esm/database.js +1957 -0
  77. package/backend/dist/esm/endpoint.d.ts +57 -0
  78. package/backend/dist/esm/endpoint.js +421 -0
  79. package/backend/dist/esm/file_watcher.d.ts +44 -0
  80. package/backend/dist/esm/file_watcher.js +313 -0
  81. package/backend/dist/esm/frontend.d.ts +13 -0
  82. package/backend/dist/esm/frontend.js +27 -0
  83. package/backend/dist/esm/image_endpoint.d.ts +24 -0
  84. package/backend/dist/esm/image_endpoint.js +206 -0
  85. package/backend/dist/esm/logger.d.ts +5 -0
  86. package/backend/dist/esm/logger.js +13 -0
  87. package/backend/dist/esm/meta.d.ts +50 -0
  88. package/backend/dist/esm/meta.js +149 -0
  89. package/backend/dist/esm/mutex.d.ts +24 -0
  90. package/backend/dist/esm/mutex.js +48 -0
  91. package/backend/dist/esm/payments/paddle.d.ts +161 -0
  92. package/backend/dist/esm/payments/paddle.js +2261 -0
  93. package/backend/dist/esm/plugins/browser.d.ts +36 -0
  94. package/backend/dist/esm/plugins/browser.js +176 -0
  95. package/backend/dist/esm/plugins/communication.d.ts +70 -0
  96. package/backend/dist/esm/plugins/communication.js +169 -0
  97. package/backend/dist/esm/plugins/css.d.ts +10 -0
  98. package/backend/dist/esm/plugins/css.js +64 -0
  99. package/backend/dist/esm/plugins/mail.d.ts +277 -0
  100. package/backend/dist/esm/plugins/mail.js +1403 -0
  101. package/backend/dist/esm/plugins/pdf.d.ts +757 -0
  102. package/backend/dist/esm/plugins/pdf.js +1694 -0
  103. package/backend/dist/esm/plugins/thread_monitor.d.ts +18 -0
  104. package/backend/dist/esm/plugins/thread_monitor.js +120 -0
  105. package/backend/dist/esm/plugins/ts/compiler.d.ts +132 -0
  106. package/backend/dist/esm/plugins/ts/compiler.js +907 -0
  107. package/backend/dist/esm/plugins/ts/preprocessing.d.ts +14 -0
  108. package/backend/dist/esm/plugins/ts/preprocessing.js +724 -0
  109. package/backend/dist/esm/rate_limit.d.ts +65 -0
  110. package/backend/dist/esm/rate_limit.js +425 -0
  111. package/backend/dist/esm/request.deprc.d.ts +48 -0
  112. package/backend/dist/esm/request.deprc.js +572 -0
  113. package/backend/dist/esm/response.deprc.d.ts +55 -0
  114. package/backend/dist/esm/response.deprc.js +275 -0
  115. package/backend/dist/esm/server.d.ts +311 -0
  116. package/backend/dist/esm/server.js +3435 -0
  117. package/backend/dist/esm/splash_screen.d.ts +35 -0
  118. package/backend/dist/esm/splash_screen.js +148 -0
  119. package/backend/dist/esm/status.d.ts +60 -0
  120. package/backend/dist/esm/status.js +196 -0
  121. package/backend/dist/esm/stream.d.ts +75 -0
  122. package/backend/dist/esm/stream.js +947 -0
  123. package/backend/dist/esm/users.d.ts +111 -0
  124. package/backend/dist/esm/users.js +1908 -0
  125. package/backend/dist/esm/utils.d.ts +27 -0
  126. package/backend/dist/esm/utils.js +324 -0
  127. package/backend/dist/esm/view.d.ts +52 -0
  128. package/backend/dist/esm/view.js +561 -0
  129. package/backend/dist/esm/vinc.d.ts +2 -0
  130. package/backend/dist/esm/vinc.dev.d.ts +2 -0
  131. package/backend/dist/esm/vinc.dev.js +6 -0
  132. package/backend/dist/esm/vinc.js +6 -0
  133. package/backend/dist/esm/volt.d.ts +15 -0
  134. package/backend/dist/esm/volt.js +23 -0
  135. package/backend/dist/esm-dev/blacklist.d.ts +10 -0
  136. package/backend/dist/esm-dev/blacklist.js +49 -0
  137. package/backend/dist/esm-dev/cli.d.ts +2 -0
  138. package/backend/dist/esm-dev/cli.js +228 -0
  139. package/backend/dist/esm-dev/database.d.ts +364 -0
  140. package/backend/dist/esm-dev/database.js +1957 -0
  141. package/backend/dist/esm-dev/endpoint.d.ts +57 -0
  142. package/backend/dist/esm-dev/endpoint.js +421 -0
  143. package/backend/dist/esm-dev/file_watcher.d.ts +44 -0
  144. package/backend/dist/esm-dev/file_watcher.js +313 -0
  145. package/backend/dist/esm-dev/frontend.d.ts +13 -0
  146. package/backend/dist/esm-dev/frontend.js +27 -0
  147. package/backend/dist/esm-dev/image_endpoint.d.ts +24 -0
  148. package/backend/dist/esm-dev/image_endpoint.js +206 -0
  149. package/backend/dist/esm-dev/logger.d.ts +5 -0
  150. package/backend/dist/esm-dev/logger.js +13 -0
  151. package/backend/dist/esm-dev/meta.d.ts +50 -0
  152. package/backend/dist/esm-dev/meta.js +149 -0
  153. package/backend/dist/esm-dev/mutex.d.ts +24 -0
  154. package/backend/dist/esm-dev/mutex.js +48 -0
  155. package/backend/dist/esm-dev/payments/paddle.d.ts +161 -0
  156. package/backend/dist/esm-dev/payments/paddle.js +2261 -0
  157. package/backend/dist/esm-dev/plugins/browser.d.ts +36 -0
  158. package/backend/dist/esm-dev/plugins/browser.js +176 -0
  159. package/backend/dist/esm-dev/plugins/communication.d.ts +70 -0
  160. package/backend/dist/esm-dev/plugins/communication.js +169 -0
  161. package/backend/dist/esm-dev/plugins/css.d.ts +10 -0
  162. package/backend/dist/esm-dev/plugins/css.js +64 -0
  163. package/backend/dist/esm-dev/plugins/mail.d.ts +277 -0
  164. package/backend/dist/esm-dev/plugins/mail.js +1403 -0
  165. package/backend/dist/esm-dev/plugins/pdf.d.ts +757 -0
  166. package/backend/dist/esm-dev/plugins/pdf.js +1694 -0
  167. package/backend/dist/esm-dev/plugins/thread_monitor.d.ts +18 -0
  168. package/backend/dist/esm-dev/plugins/thread_monitor.js +120 -0
  169. package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +132 -0
  170. package/backend/dist/esm-dev/plugins/ts/compiler.js +907 -0
  171. package/backend/dist/esm-dev/plugins/ts/preprocessing.d.ts +14 -0
  172. package/backend/dist/esm-dev/plugins/ts/preprocessing.js +724 -0
  173. package/backend/dist/esm-dev/rate_limit.d.ts +65 -0
  174. package/backend/dist/esm-dev/rate_limit.js +425 -0
  175. package/backend/dist/esm-dev/request.deprc.d.ts +48 -0
  176. package/backend/dist/esm-dev/request.deprc.js +572 -0
  177. package/backend/dist/esm-dev/response.deprc.d.ts +55 -0
  178. package/backend/dist/esm-dev/response.deprc.js +275 -0
  179. package/backend/dist/esm-dev/server.d.ts +311 -0
  180. package/backend/dist/esm-dev/server.js +3435 -0
  181. package/backend/dist/esm-dev/splash_screen.d.ts +35 -0
  182. package/backend/dist/esm-dev/splash_screen.js +148 -0
  183. package/backend/dist/esm-dev/status.d.ts +60 -0
  184. package/backend/dist/esm-dev/status.js +196 -0
  185. package/backend/dist/esm-dev/stream.d.ts +75 -0
  186. package/backend/dist/esm-dev/stream.js +947 -0
  187. package/backend/dist/esm-dev/users.d.ts +111 -0
  188. package/backend/dist/esm-dev/users.js +1908 -0
  189. package/backend/dist/esm-dev/utils.d.ts +27 -0
  190. package/backend/dist/esm-dev/utils.js +324 -0
  191. package/backend/dist/esm-dev/view.d.ts +52 -0
  192. package/backend/dist/esm-dev/view.js +561 -0
  193. package/backend/dist/esm-dev/vinc.d.ts +2 -0
  194. package/backend/dist/esm-dev/vinc.dev.d.ts +2 -0
  195. package/backend/dist/esm-dev/vinc.dev.js +6 -0
  196. package/backend/dist/esm-dev/vinc.js +6 -0
  197. package/backend/dist/esm-dev/volt.d.ts +15 -0
  198. package/backend/dist/esm-dev/volt.js +23 -0
  199. package/backend/src/blacklist.ts +69 -0
  200. package/backend/src/cli.js +245 -0
  201. package/backend/src/database.ts +2241 -0
  202. package/backend/src/endpoint.ts +494 -0
  203. package/backend/src/file_watcher.ts +359 -0
  204. package/backend/src/frontend.ts +35 -0
  205. package/backend/src/globals.d.ts +8 -0
  206. package/backend/src/image_endpoint.ts +258 -0
  207. package/backend/src/logger.ts +18 -0
  208. package/backend/src/meta.ts +202 -0
  209. package/backend/src/mutex.ts +51 -0
  210. package/backend/src/payments/paddle.ts +2659 -0
  211. package/backend/src/plugins/browser.ts +188 -0
  212. package/backend/src/plugins/communication.ts +204 -0
  213. package/backend/src/plugins/css.ts +84 -0
  214. package/backend/src/plugins/fonts/Menlo-Bold.ttf +0 -0
  215. package/backend/src/plugins/fonts/Menlo-Regular.ttf +0 -0
  216. package/backend/src/plugins/mail.ts +1720 -0
  217. package/backend/src/plugins/pdf.js +1932 -0
  218. package/backend/src/plugins/thread_monitor.ts +164 -0
  219. package/backend/src/plugins/ts/compiler.ts +1242 -0
  220. package/backend/src/plugins/ts/preprocessing.ts +812 -0
  221. package/backend/src/rate_limit.ts +503 -0
  222. package/backend/src/request.deprc.js +626 -0
  223. package/backend/src/response.deprc.js +354 -0
  224. package/backend/src/server.ts +4149 -0
  225. package/backend/src/splash_screen.ts +192 -0
  226. package/backend/src/status.ts +199 -0
  227. package/backend/src/stream.ts +1070 -0
  228. package/backend/src/users.ts +2077 -0
  229. package/backend/src/utils.ts +359 -0
  230. package/backend/src/view.ts +655 -0
  231. package/backend/src/vinc.dev.js +6 -0
  232. package/backend/src/vinc.ts +6 -0
  233. package/backend/src/volt.js +25 -0
  234. package/backend/tsconfig.cjs.json +29 -0
  235. package/backend/tsconfig.esm.dev.json +34 -0
  236. package/backend/tsconfig.esm.json +30 -0
  237. package/backend/tsconfig.json +2 -0
  238. package/frontend/compile.js +436 -0
  239. package/frontend/dist/elements/base.d.ts +9891 -0
  240. package/frontend/dist/elements/base.js +8818 -0
  241. package/frontend/dist/elements/module.d.ts +16 -0
  242. package/frontend/dist/elements/module.js +178 -0
  243. package/frontend/dist/modules/array.d.ts +37 -0
  244. package/frontend/dist/modules/array.js +284 -0
  245. package/frontend/dist/modules/auth.d.ts +45 -0
  246. package/frontend/dist/modules/auth.js +138 -0
  247. package/frontend/dist/modules/colors.d.ts +26 -0
  248. package/frontend/dist/modules/colors.js +340 -0
  249. package/frontend/dist/modules/compression.d.ts +6 -0
  250. package/frontend/dist/modules/compression.js +999 -0
  251. package/frontend/dist/modules/cookies.d.ts +17 -0
  252. package/frontend/dist/modules/cookies.js +166 -0
  253. package/frontend/dist/modules/date.d.ts +142 -0
  254. package/frontend/dist/modules/date.js +493 -0
  255. package/frontend/dist/modules/events.d.ts +7 -0
  256. package/frontend/dist/modules/events.js +90 -0
  257. package/frontend/dist/modules/google.d.ts +10 -0
  258. package/frontend/dist/modules/google.js +53 -0
  259. package/frontend/dist/modules/meta.d.ts +9 -0
  260. package/frontend/dist/modules/meta.js +45 -0
  261. package/frontend/dist/modules/mutex.d.ts +8 -0
  262. package/frontend/dist/modules/mutex.js +52 -0
  263. package/frontend/dist/modules/number.d.ts +12 -0
  264. package/frontend/dist/modules/number.js +8 -0
  265. package/frontend/dist/modules/object.d.ts +50 -0
  266. package/frontend/dist/modules/object.js +147 -0
  267. package/frontend/dist/modules/paddle.d.ts +1403 -0
  268. package/frontend/dist/modules/paddle.js +2641 -0
  269. package/frontend/dist/modules/scheme.d.ts +207 -0
  270. package/frontend/dist/modules/scheme.js +649 -0
  271. package/frontend/dist/modules/settings.d.ts +3 -0
  272. package/frontend/dist/modules/settings.js +4 -0
  273. package/frontend/dist/modules/statics.d.ts +4 -0
  274. package/frontend/dist/modules/statics.js +45 -0
  275. package/frontend/dist/modules/string.d.ts +163 -0
  276. package/frontend/dist/modules/string.js +291 -0
  277. package/frontend/dist/modules/support.d.ts +18 -0
  278. package/frontend/dist/modules/support.js +102 -0
  279. package/frontend/dist/modules/themes.d.ts +8 -0
  280. package/frontend/dist/modules/themes.js +17 -0
  281. package/frontend/dist/modules/user.d.ts +58 -0
  282. package/frontend/dist/modules/user.js +279 -0
  283. package/frontend/dist/modules/utils.d.ts +58 -0
  284. package/frontend/dist/modules/utils.js +1159 -0
  285. package/frontend/dist/types/gradient.d.ts +12 -0
  286. package/frontend/dist/types/gradient.js +79 -0
  287. package/frontend/dist/ui/border_button.d.ts +177 -0
  288. package/frontend/dist/ui/border_button.js +235 -0
  289. package/frontend/dist/ui/button.d.ts +42 -0
  290. package/frontend/dist/ui/button.js +114 -0
  291. package/frontend/dist/ui/canvas.d.ts +56 -0
  292. package/frontend/dist/ui/canvas.js +411 -0
  293. package/frontend/dist/ui/checkbox.d.ts +72 -0
  294. package/frontend/dist/ui/checkbox.js +277 -0
  295. package/frontend/dist/ui/code.d.ts +232 -0
  296. package/frontend/dist/ui/code.js +977 -0
  297. package/frontend/dist/ui/color.d.ts +1 -0
  298. package/frontend/dist/ui/color.js +110 -0
  299. package/frontend/dist/ui/context_menu.d.ts +30 -0
  300. package/frontend/dist/ui/context_menu.js +211 -0
  301. package/frontend/dist/ui/css.d.ts +10 -0
  302. package/frontend/dist/ui/css.js +44 -0
  303. package/frontend/dist/ui/divider.d.ts +18 -0
  304. package/frontend/dist/ui/divider.js +82 -0
  305. package/frontend/dist/ui/dropdown.d.ts +115 -0
  306. package/frontend/dist/ui/dropdown.js +446 -0
  307. package/frontend/dist/ui/for_each.d.ts +38 -0
  308. package/frontend/dist/ui/for_each.js +97 -0
  309. package/frontend/dist/ui/form.d.ts +25 -0
  310. package/frontend/dist/ui/form.js +227 -0
  311. package/frontend/dist/ui/frame_modes.d.ts +28 -0
  312. package/frontend/dist/ui/frame_modes.js +116 -0
  313. package/frontend/dist/ui/google_map.d.ts +31 -0
  314. package/frontend/dist/ui/google_map.js +111 -0
  315. package/frontend/dist/ui/gradient.d.ts +24 -0
  316. package/frontend/dist/ui/gradient.js +115 -0
  317. package/frontend/dist/ui/image.d.ts +138 -0
  318. package/frontend/dist/ui/image.js +570 -0
  319. package/frontend/dist/ui/input.d.ts +316 -0
  320. package/frontend/dist/ui/input.js +1187 -0
  321. package/frontend/dist/ui/link.d.ts +39 -0
  322. package/frontend/dist/ui/link.js +146 -0
  323. package/frontend/dist/ui/list.d.ts +33 -0
  324. package/frontend/dist/ui/list.js +161 -0
  325. package/frontend/dist/ui/loader_button.d.ts +108 -0
  326. package/frontend/dist/ui/loader_button.js +207 -0
  327. package/frontend/dist/ui/loaders.d.ts +60 -0
  328. package/frontend/dist/ui/loaders.js +150 -0
  329. package/frontend/dist/ui/popup.d.ts +84 -0
  330. package/frontend/dist/ui/popup.js +331 -0
  331. package/frontend/dist/ui/pseudo.d.ts +16 -0
  332. package/frontend/dist/ui/pseudo.js +81 -0
  333. package/frontend/dist/ui/scroller.d.ts +131 -0
  334. package/frontend/dist/ui/scroller.js +1251 -0
  335. package/frontend/dist/ui/slider.d.ts +35 -0
  336. package/frontend/dist/ui/slider.js +203 -0
  337. package/frontend/dist/ui/spacer.d.ts +20 -0
  338. package/frontend/dist/ui/spacer.js +83 -0
  339. package/frontend/dist/ui/span.d.ts +11 -0
  340. package/frontend/dist/ui/span.js +75 -0
  341. package/frontend/dist/ui/stack.d.ts +123 -0
  342. package/frontend/dist/ui/stack.js +344 -0
  343. package/frontend/dist/ui/steps.d.ts +72 -0
  344. package/frontend/dist/ui/steps.js +306 -0
  345. package/frontend/dist/ui/style.d.ts +12 -0
  346. package/frontend/dist/ui/style.js +78 -0
  347. package/frontend/dist/ui/switch.d.ts +44 -0
  348. package/frontend/dist/ui/switch.js +280 -0
  349. package/frontend/dist/ui/table.d.ts +118 -0
  350. package/frontend/dist/ui/table.js +411 -0
  351. package/frontend/dist/ui/tabs.d.ts +85 -0
  352. package/frontend/dist/ui/tabs.js +392 -0
  353. package/frontend/dist/ui/text.d.ts +19 -0
  354. package/frontend/dist/ui/text.js +88 -0
  355. package/frontend/dist/ui/theme.d.ts +25 -0
  356. package/frontend/dist/ui/theme.js +237 -0
  357. package/frontend/dist/ui/title.d.ts +36 -0
  358. package/frontend/dist/ui/title.js +127 -0
  359. package/frontend/dist/ui/ui.d.ts +38 -0
  360. package/frontend/dist/ui/ui.js +41 -0
  361. package/frontend/dist/ui/view.d.ts +25 -0
  362. package/frontend/dist/ui/view.js +93 -0
  363. package/frontend/dist/volt.d.ts +22 -0
  364. package/frontend/dist/volt.js +27 -0
  365. package/frontend/exports.json +1340 -0
  366. package/frontend/src/css/adyen.css +92 -0
  367. package/frontend/src/css/volt.css +65 -0
  368. package/frontend/src/elements/base.ts +16790 -0
  369. package/frontend/src/elements/module.ts +184 -0
  370. package/frontend/src/elements/types.d.ts +155 -0
  371. package/frontend/src/modules/array.ts +366 -0
  372. package/frontend/src/modules/auth.ts +188 -0
  373. package/frontend/src/modules/colors.ts +449 -0
  374. package/frontend/src/modules/compression.ts +67 -0
  375. package/frontend/src/modules/cookies.ts +182 -0
  376. package/frontend/src/modules/date.js +535 -0
  377. package/frontend/src/modules/date.ts +583 -0
  378. package/frontend/src/modules/events.ts +96 -0
  379. package/frontend/src/modules/google.ts +60 -0
  380. package/frontend/src/modules/meta.ts +59 -0
  381. package/frontend/src/modules/mutex.ts +59 -0
  382. package/frontend/src/modules/number.ts +20 -0
  383. package/frontend/src/modules/object.ts +212 -0
  384. package/frontend/src/modules/paddle.ts +2990 -0
  385. package/frontend/src/modules/scheme.ts +740 -0
  386. package/frontend/src/modules/settings.ts +5 -0
  387. package/frontend/src/modules/statics.ts +47 -0
  388. package/frontend/src/modules/string.ts +500 -0
  389. package/frontend/src/modules/support.ts +118 -0
  390. package/frontend/src/modules/themes.ts +24 -0
  391. package/frontend/src/modules/user.ts +321 -0
  392. package/frontend/src/modules/utils.ts +1260 -0
  393. package/frontend/src/static/admin/admin.png +0 -0
  394. package/frontend/src/static/admin/password.webp +0 -0
  395. package/frontend/src/static/icons/copy.webp +0 -0
  396. package/frontend/src/static/payments/arrow.long.webp +0 -0
  397. package/frontend/src/static/payments/arrow.long2.webp +0 -0
  398. package/frontend/src/static/payments/cancelled.webp +0 -0
  399. package/frontend/src/static/payments/check.sign.webp +0 -0
  400. package/frontend/src/static/payments/check.webp +0 -0
  401. package/frontend/src/static/payments/close.webp +0 -0
  402. package/frontend/src/static/payments/error.webp +0 -0
  403. package/frontend/src/static/payments/exclamation.webp +0 -0
  404. package/frontend/src/static/payments/minus.webp +0 -0
  405. package/frontend/src/static/payments/party.webp +0 -0
  406. package/frontend/src/static/payments/plus.webp +0 -0
  407. package/frontend/src/static/payments/shopping_cart.webp +0 -0
  408. package/frontend/src/static/payments/trash.webp +0 -0
  409. package/frontend/src/types/global.d.ts +4 -0
  410. package/frontend/src/types/gradient.ts +87 -0
  411. package/frontend/src/ui/any_element.d.ts +5 -0
  412. package/frontend/src/ui/border_button.ts +320 -0
  413. package/frontend/src/ui/button.ts +62 -0
  414. package/frontend/src/ui/canvas.ts +431 -0
  415. package/frontend/src/ui/checkbox.ts +284 -0
  416. package/frontend/src/ui/code.ts +1049 -0
  417. package/frontend/src/ui/color.ts +117 -0
  418. package/frontend/src/ui/context_menu.ts +194 -0
  419. package/frontend/src/ui/css.ts +57 -0
  420. package/frontend/src/ui/divider.ts +28 -0
  421. package/frontend/src/ui/dropdown.ts +503 -0
  422. package/frontend/src/ui/for_each.ts +71 -0
  423. package/frontend/src/ui/form.ts +208 -0
  424. package/frontend/src/ui/frame_modes.ts +140 -0
  425. package/frontend/src/ui/google_map.ts +70 -0
  426. package/frontend/src/ui/gradient.ts +73 -0
  427. package/frontend/src/ui/image.ts +587 -0
  428. package/frontend/src/ui/input.ts +1284 -0
  429. package/frontend/src/ui/link.ts +77 -0
  430. package/frontend/src/ui/list.ts +88 -0
  431. package/frontend/src/ui/loader_button.ts +192 -0
  432. package/frontend/src/ui/loaders.ts +126 -0
  433. package/frontend/src/ui/popup.ts +370 -0
  434. package/frontend/src/ui/pseudo.ts +33 -0
  435. package/frontend/src/ui/scroller.ts +1324 -0
  436. package/frontend/src/ui/slider.ts +215 -0
  437. package/frontend/src/ui/spacer.ts +29 -0
  438. package/frontend/src/ui/span.ts +23 -0
  439. package/frontend/src/ui/stack.ts +238 -0
  440. package/frontend/src/ui/steps.ts +334 -0
  441. package/frontend/src/ui/style.ts +26 -0
  442. package/frontend/src/ui/switch.ts +286 -0
  443. package/frontend/src/ui/table.ts +323 -0
  444. package/frontend/src/ui/tabs.ts +441 -0
  445. package/frontend/src/ui/text.ts +38 -0
  446. package/frontend/src/ui/theme.ts +279 -0
  447. package/frontend/src/ui/title.ts +64 -0
  448. package/frontend/src/ui/ui.ts +47 -0
  449. package/frontend/src/ui/view.ts +44 -0
  450. package/frontend/src/volt.ts +31 -0
  451. package/package.json +58 -0
@@ -0,0 +1,1070 @@
1
+ /*
2
+ * Author: Daan van den Bergh
3
+ * Copyright: © 2022 - 2024 Daan van den Bergh.
4
+ */
5
+
6
+ // ---------------------------------------------------------
7
+ // Imports.
8
+
9
+ import zlib from 'zlib';
10
+ import { vlib } from "@vinc";
11
+ import { IncomingMessage, ServerResponse } from 'http';
12
+ import { ServerHttp2Stream, Http2Stream, IncomingHttpHeaders, Http2ServerRequest, Http2ServerResponse } from 'http2';
13
+
14
+ // ---------------------------------------------------------
15
+ // Types.
16
+
17
+ export type Params = any
18
+ export type Parameters = Params;
19
+
20
+ // ---------------------------------------------------------
21
+ // Request object.
22
+
23
+ /* @docs
24
+ @nav: Backend
25
+ @chapter: Stream
26
+ @title: HTTP1/2 Stream
27
+ @description:
28
+ The http2 stream wrapper object.
29
+ @attribute:
30
+ @name: headers
31
+ @desc: The request headers.
32
+ */
33
+
34
+ export class Stream {
35
+ private s?: ServerHttp2Stream;
36
+ public headers: IncomingHttpHeaders | IncomingMessage['headers'];
37
+ private req?: IncomingMessage | Http2ServerRequest;
38
+ private res?: ServerResponse | Http2ServerResponse;
39
+ public http2: boolean;
40
+ public http1: boolean;
41
+ private _ip: string;
42
+ private _port: number;
43
+ private _method: string;
44
+ private _params: Record<string, any> | undefined;
45
+ private _is_query_params: boolean;
46
+ private _endpoint: string | undefined;
47
+ private _query_string: string | undefined;
48
+ private _cookies: Record<string, any> | undefined;
49
+ private _uid: string | null;
50
+ public status_code: number | null;
51
+ public finished: boolean;
52
+ private res_cookies: string[];
53
+ private res_headers: Record<string, any> | [string, any][];
54
+ public body: string;
55
+ private promise: Promise<void> | undefined;
56
+
57
+ constructor(
58
+ stream?: ServerHttp2Stream,
59
+ headers?: IncomingHttpHeaders | IncomingMessage['headers'],
60
+ req?: IncomingMessage | Http2ServerRequest,
61
+ res?: ServerResponse | Http2ServerResponse,
62
+ ) {
63
+
64
+ // Parameters.
65
+ this.s = stream;
66
+ this.headers = (headers ?? {}) as IncomingHttpHeaders | IncomingMessage['headers'];
67
+ this.req = req;
68
+ this.res = res;
69
+ this.http2 = req == null;
70
+ this.http1 = req != null;
71
+
72
+ // HTTP1.
73
+ if (this.http1) {
74
+ this.headers = this.req!.headers;
75
+ }
76
+
77
+ // Request attributes.
78
+ this._ip = this.http2 ? (this.s as Http2Stream).session!.socket!.remoteAddress! : this.req!.socket!.remoteAddress!;
79
+ this._port = this.http2 ? (this.s as Http2Stream).session!.socket!.remotePort! : this.req!.socket!.remotePort!;
80
+ this._method = this.http2 ? this.headers[':method'] as string : this.req!.method!;
81
+ this._params = undefined;
82
+ this._is_query_params = false;
83
+ this._endpoint = undefined;
84
+ this._query_string = undefined;
85
+ this._cookies = undefined;
86
+ this._uid = null;
87
+
88
+ // Response attributes
89
+ this.status_code = null;
90
+ this.finished = false;
91
+ this.res_cookies = [];
92
+ this.res_headers = this.http1 ? [] : {};
93
+
94
+ // Read body.
95
+ this.body = "";
96
+ this.promise = undefined;
97
+ this._recv_body();
98
+ }
99
+
100
+ // Receve the body.
101
+ private _recv_body() {
102
+ this.promise = new Promise<void>((resolve, reject) => {
103
+
104
+ // Buffers.
105
+ const buffs: Buffer[] = [];
106
+
107
+ // Get decompress stream.
108
+ let decompress_stream: zlib.Gunzip | zlib.Inflate | undefined;
109
+ const content_encoding = this.headers['content-encoding'];
110
+ if (content_encoding === 'gzip') {
111
+ decompress_stream = zlib.createGunzip();
112
+ } else if (content_encoding === 'deflate') {
113
+ decompress_stream = zlib.createInflate();
114
+ }
115
+ const cleanup = () => {
116
+ if (decompress_stream) {
117
+ decompress_stream.close();
118
+ }
119
+ };
120
+
121
+ // HTTP2.
122
+ if (this.http2) {
123
+ let stream: any = this.s;
124
+
125
+ // If decompression is needed, pipe the stream through the decompression stream
126
+ if (decompress_stream) {
127
+ stream = (this.s as Http2Stream).pipe(decompress_stream);
128
+ // decompress_stream.on('error', (e) => { cleanup(); reject(e); });
129
+ }
130
+
131
+ // On error.
132
+ stream.on('error', (e) => { cleanup(); reject(e); });
133
+
134
+ // Receive data.
135
+ stream.on('data', (chunk: Buffer) => {
136
+ buffs.push(chunk);
137
+ });
138
+ stream.on('end', () => {
139
+ this.body = Buffer.concat(buffs).toString();
140
+ cleanup();
141
+ resolve();
142
+ });
143
+ }
144
+
145
+ // HTTP1.
146
+ else {
147
+ let stream: any = this.req!;
148
+
149
+ // Decompress data.
150
+ if (decompress_stream) {
151
+ this.req!.pipe(decompress_stream)
152
+ stream = decompress_stream;
153
+ }
154
+
155
+ // On error.
156
+ stream.on('error', (e) => { cleanup(); reject(e); });
157
+
158
+ // Receive data.
159
+ stream.on("data", (data: Buffer) => {
160
+ buffs.push(data);
161
+ })
162
+ stream.on("end", () => {
163
+ this.body = Buffer.concat(buffs).toString();
164
+ cleanup();
165
+ resolve();
166
+ })
167
+ }
168
+ })
169
+ }
170
+
171
+ // Parse endpoint.
172
+ private _parse_endoint() {
173
+ if (this._endpoint !== undefined) { return }
174
+ this._endpoint = this.http2 ? this.headers[":path"] as string : this.req!.url!;
175
+ let index;
176
+ if ((index = this._endpoint.indexOf("?")) !== -1) {
177
+ this._query_string = this._endpoint.substr(index + 1);
178
+ this._endpoint = this._endpoint.substr(0, index);
179
+ }
180
+ this._endpoint = this._endpoint.replace(/\/\//g, "/");
181
+ if (this._endpoint.length > 1 && this._endpoint.charAt(this._endpoint.length - 1) === "/") {
182
+ this._endpoint = this._endpoint.substr(0, this._endpoint.length - 1);
183
+ }
184
+ }
185
+
186
+ // Parse the parameters.
187
+ public _parse_params() {
188
+
189
+ // Parse query string.
190
+ this._parse_endoint();
191
+
192
+ // Already parsed.
193
+ if (this._params !== undefined) {return}
194
+
195
+ // Initialize.
196
+ this._params = {};
197
+
198
+ // By query string.
199
+ if (this._query_string !== undefined) {
200
+
201
+ // As encoded json.
202
+ if (this._query_string.charAt(0) === "{") {
203
+ try {
204
+ this._params = JSON.parse(decodeURIComponent(this._query_string));
205
+ } catch(err) {
206
+ throw Error(`Invalid json request query: ${err}.`)
207
+ }
208
+ }
209
+
210
+ // As query string.
211
+ else {
212
+
213
+ // Assign.
214
+ this._is_query_params = true;
215
+
216
+ // Variables.
217
+ let is_key = true, key = "", value = "";
218
+ const number_regex = /^-?\d+(\.\d+)?$/;
219
+
220
+ // Callback.
221
+ const add_value = () => {
222
+ let output_value: any;
223
+ switch (value) {
224
+ case "true": case "True":
225
+ output_value = true;
226
+ break;
227
+ case "false": case "False":
228
+ output_value = false;
229
+ break;
230
+ case "null": case "None": case "undefined":
231
+ output_value = null;
232
+ break;
233
+ default:
234
+ output_value = decodeURIComponent(value.replaceAll("+", " "))
235
+ if (number_regex.test(output_value)) {
236
+ if (output_value.indexOf(".") !== -1) {
237
+ output_value = parseFloat(output_value);
238
+ } else {
239
+ output_value = parseInt(output_value);
240
+ }
241
+ }
242
+ break;
243
+ }
244
+ this._params![decodeURIComponent(key.replaceAll("+", " "))] = output_value;
245
+ key = "";
246
+ value = "";
247
+ is_key = true;
248
+ };
249
+
250
+ // Iterate
251
+ for (let i = 0; i < this._query_string.length; i++) {
252
+ const c = this._query_string.charAt(i);
253
+ if (is_key && c === "=") {
254
+ is_key = false;
255
+ continue;
256
+ } else if (is_key === false && c === "&") {
257
+ add_value();
258
+ continue;
259
+ }
260
+ if (is_key) {
261
+ key += c;
262
+ } else {
263
+ value += c;
264
+ }
265
+ }
266
+ if (key.length > 0) {
267
+ add_value();
268
+ }
269
+ }
270
+ }
271
+
272
+ // By body.
273
+ else if (this.body.trim().charAt(0) === "{") {
274
+ try {
275
+ this._params = JSON.parse(this.body);
276
+ } catch(err) {
277
+ throw Error(`Invalid json request body: ${err}.`)
278
+ }
279
+ }
280
+
281
+ // Handler.
282
+ return this._params;
283
+ }
284
+
285
+ // Parse cookies.
286
+ private _parse_cookies() {
287
+
288
+ // Reset cookies.
289
+ this._cookies = {};
290
+
291
+ // Vars.
292
+ const cookie_str = this.http2 ? this.headers["cookie"] : this.req!.headers.cookie;
293
+ if (cookie_str === undefined) { return null; }
294
+ let key = "";
295
+ let value = "";
296
+ let cookie: Record<string, any> = {};
297
+ let cookie_length = 0;
298
+ let cookie_key: string | null = null;
299
+ let is_value = false;
300
+ let is_str: string | null = null;
301
+
302
+ // Append to cookie.
303
+ const append_to_cookie = () => {
304
+ if (key.length > 0) {
305
+ if (cookie_length === 0) {
306
+ cookie.value = value;
307
+ } else {
308
+ cookie[key] = value;
309
+ }
310
+ ++cookie_length;
311
+ }
312
+ key = "";
313
+ value = "";
314
+ is_value = false;
315
+ is_str = null;
316
+ }
317
+
318
+ // Append cookie.
319
+ const append_cookie = () => {
320
+ if (cookie_key != null) {
321
+ this._cookies![cookie_key] = cookie;
322
+ cookie_key = null;
323
+ cookie = {};
324
+ cookie_length = 0;
325
+ }
326
+ }
327
+
328
+ // Iterate.
329
+ for (let x = 0; x < cookie_str.length; x++) {
330
+ const c = cookie_str.charAt(x);
331
+
332
+ // Add char to value.
333
+ if (is_value) {
334
+
335
+ // End of cookie string.
336
+ if (is_str === c) {
337
+ value = value.substr(1, value.length - 1);
338
+ append_to_cookie();
339
+ }
340
+
341
+ // Cookie seperator.
342
+ else if (is_str == null && c === " ") {
343
+ append_to_cookie();
344
+ }
345
+
346
+ // End of cookie.
347
+ else if (is_str == null && c === ";") {
348
+ append_to_cookie();
349
+ append_cookie();
350
+
351
+ }
352
+
353
+ // Append to value.
354
+ else {
355
+ value += c;
356
+ if (value.length === 1 && (c === "\"" || c === "'")) {
357
+ is_str = c;
358
+ }
359
+ }
360
+ }
361
+
362
+ // Skip whitespace in keys.
363
+ else if (c == " " || c == "\t") {
364
+ continue;
365
+ }
366
+
367
+ // End of cookie key.
368
+ else if (c == "=") {
369
+ if (cookie_key == null) {
370
+ cookie_key = key;
371
+ }
372
+ is_value = true;
373
+ }
374
+
375
+ // Add char to key.
376
+ else {
377
+ key += c;
378
+ }
379
+ }
380
+ append_to_cookie();
381
+ append_cookie();
382
+ }
383
+
384
+ // ---------------------------------------------------------
385
+ // Functions.
386
+
387
+ // Wait till the request body is fully received.
388
+ async join(): Promise<void> {
389
+ await this.promise;
390
+ }
391
+
392
+ // Get the requests ip.
393
+ /* @docs:
394
+ * @title: IP
395
+ * @description: Get the request's ip.
396
+ * @property: true
397
+ * @usage:
398
+ * ...
399
+ * const ip = stream.ip;
400
+ */
401
+ get ip(): string {
402
+ return this._ip;
403
+ }
404
+
405
+ // Get the requests port.
406
+ /* @docs:
407
+ * @title: Port
408
+ * @description: Get the request's port.
409
+ * @property: true
410
+ * @usage:
411
+ * ...
412
+ * const port = stream.port;
413
+ */
414
+ get port(): number {
415
+ return this._port;
416
+ }
417
+
418
+ // Get the method.
419
+ /* @docs:
420
+ * @title: Method
421
+ * @description: Get the request method.
422
+ * @property: true
423
+ * @usage:
424
+ * ...
425
+ * const method = stream.method;
426
+ */
427
+ get method(): string {
428
+ return this._method;
429
+ }
430
+
431
+ // Get the endpoint.
432
+ /* @docs:
433
+ * @title: Endpoint
434
+ * @description: Get the request's endpoint. This will not include the query string.
435
+ * @property: true
436
+ * @type: string
437
+ * @usage:
438
+ * ...
439
+ * const endpoint = stream.endpoint;
440
+ */
441
+ get endpoint(): string {
442
+ if (this._endpoint !== undefined) {
443
+ return this._endpoint;
444
+ }
445
+ this._parse_endoint();
446
+ return this._endpoint as unknown as string;
447
+ }
448
+
449
+ // Get the params.
450
+ /* @docs:
451
+ * @title: Parameters
452
+ * @description: Get the request's query or body params.
453
+ * property: true
454
+ * @type: object
455
+ * @usage:
456
+ * ...
457
+ * const params = stream.params;
458
+ */
459
+ get params(): Record<string, any> {
460
+ if (this._params !== undefined) {
461
+ return this._params;
462
+ }
463
+ this._parse_params();
464
+ return this._params as unknown as Record<string, any>;
465
+ }
466
+
467
+ // Get a param by name and optionally by type.
468
+ /* @docs:
469
+ * @title: Parameter
470
+ * @description: Get a single query or body parameter with an optional type cast.
471
+ * @warning: Throws an error when the parameter does not exist or when the type is different from the specified type(s), unless parameter `def` is defined.
472
+ * @param:
473
+ * @name: name
474
+ * @desc: The name of the parameter.
475
+ * @type: string
476
+ * @param:
477
+ * @name: type
478
+ * @desc: The type cast of the parameters, valid types are `[null, "boolean", "number", "string", "array", "object"]`.
479
+ * @type: string
480
+ * @param:
481
+ * @name: def
482
+ * @desc:
483
+ * The default value to return when the parameter does not exist.
484
+ *
485
+ * If the parameter is not defined and `def` is `undefined` then this function will throw an error.
486
+ * When `def` is `undefined` errors will be thrown, when `def` is `null` and the parameter is undefined then `null` will be returned as the default value.
487
+ *
488
+ * Errors will always be thrown when the incorrect type has been sent by the user.
489
+ * @type: any
490
+ * @usage:
491
+ * ...
492
+ * const param = stream.param("myparameter", "number", 10);
493
+ */
494
+ param<T = any>(name: string, type: string | string[] | null = null, def: any = undefined): T {
495
+
496
+ // Parse params.
497
+ this._parse_params();
498
+
499
+ // Get value.
500
+ let value = this._params![name];
501
+
502
+ // Check type.
503
+ if (type != null) {
504
+
505
+ // Vars.
506
+ let is_type_array = Array.isArray(type);
507
+
508
+ // Wrapper funcs.
509
+ const type_str = () => {
510
+ let str = "";
511
+ if (type != null) {
512
+ str += " type "
513
+ if (is_type_array) {
514
+ let i = 0, one_but_last_i = (type as any).length - 2;
515
+ (type as any).forEach((item, i) => {
516
+ str += `"${item}"`;
517
+ if (i < one_but_last_i) {
518
+ str += ", ";
519
+ } else if (i === one_but_last_i) {
520
+ str += " or ";
521
+ }
522
+ })
523
+ } else {
524
+ str += `"${type}"`;
525
+ }
526
+ }
527
+ return str;
528
+ }
529
+ const type_eq_or_includes = (match: string) => {
530
+ if (is_type_array) {
531
+ return (type as any).includes(match);
532
+ }
533
+ return match === type;
534
+ }
535
+
536
+ // Check undefined.
537
+ if (value == null || value === "") {
538
+ if (def !== undefined) {
539
+ return def;
540
+ }
541
+ throw Error(`Define parameter "${name}"${type_str()}.`)
542
+ }
543
+
544
+ // Cast the value to another type when a query string was used.
545
+ if (this._is_query_params && type_eq_or_includes("string") === false) {
546
+ if (is_type_array === false) {
547
+ type = [type as string];
548
+ }
549
+ const success = (type as any).some((type) => {
550
+
551
+ // Convert to string.
552
+ if (type === "string") {
553
+ return true;
554
+ }
555
+
556
+ // Convert to null.
557
+ if (type === "null" && value === "null") {
558
+ value = null;
559
+ return true;
560
+ }
561
+
562
+ // Convert to boolean.
563
+ const is_boolean = type === "boolean";
564
+ if (is_boolean && value === "true") {
565
+ value = true;
566
+ return true;
567
+ }
568
+ if (is_boolean && value === "false") {
569
+ value = false;
570
+ return true;
571
+ }
572
+
573
+ // Convert to array.
574
+ if (type === "array") {
575
+ value = (value as string).split(",");
576
+ return true;
577
+ }
578
+
579
+ // Convert to object.
580
+ if (type === "object") {
581
+ const split: string[] = (value as string).split(",");
582
+ value = {};
583
+ split.forEach((item) => {
584
+ const pair = item.split(":");
585
+ (value as Record<string, any>)[pair[0]] = pair[1];
586
+ })
587
+ return true;
588
+ }
589
+
590
+ // Convert to numeric.
591
+ if (type === "number" && /^-?\d+(\.\d+)?$/.test(value)) {
592
+ value = parseFloat(value);
593
+ return true;
594
+ }
595
+ })
596
+ if (!success) {
597
+ throw Error(`Parameter "${name}" should be of${type_str()}.`)
598
+ }
599
+
600
+ }
601
+
602
+ // Check the type when no query params are defined since JSON.parse already parsed the types.
603
+ else if (!this._is_query_params) {
604
+ const value_type = typeof value;
605
+ if (!is_type_array) {
606
+ type = [type as string];
607
+ }
608
+ const success = (type as any).some((type) => {
609
+ const l_is_array = type === "array";
610
+ const l_is_null = type === "null";
611
+
612
+ // Same type.
613
+ if (!l_is_array && !l_is_null && type === value_type) {
614
+ return true;
615
+ }
616
+
617
+ // Check to null.
618
+ if (l_is_null && value == null) {
619
+ return true;
620
+ }
621
+
622
+ // Convert to array.
623
+ if (l_is_array && Array.isArray(value)) {
624
+ return true;
625
+ }
626
+ })
627
+ if (!success) {
628
+ throw Error(`Parameter "${name}" should be of${type_str()}.`)
629
+ }
630
+ }
631
+ }
632
+
633
+ // Check undefined.
634
+ else if (value == null || value === "") {
635
+ if (def !== undefined) {
636
+ return def;
637
+ }
638
+ throw Error(`Define parameter "${name}".`)
639
+ }
640
+
641
+ // Return value.
642
+ return value;
643
+ }
644
+
645
+ // Get the request cookies.
646
+ /* @docs:
647
+ * @title: Cookies
648
+ * @description: Get the request's cookies
649
+ * property: true
650
+ * @type: object
651
+ * @usage:
652
+ * ...
653
+ * const cookies = stream.cookies;
654
+ */
655
+ get cookies(): Record<string, any> {
656
+ if (this._cookies !== undefined) {
657
+ return this._cookies;
658
+ }
659
+ this._parse_cookies();
660
+ return this._cookies as unknown as Record<string, any>;
661
+ }
662
+
663
+ // Check if the stream is closed
664
+ /* @docs:
665
+ * @title: Closed
666
+ * @description: Check if the stream is closed.
667
+ * @property: true
668
+ * @usage:
669
+ * ...
670
+ * const ip = stream.closed;
671
+ */
672
+ get closed(): boolean {
673
+ if (!this.http2) { throw new Error("This function is only supported for http2 streams."); }
674
+ return this.s!.closed;
675
+ }
676
+
677
+ // Check if the stream is destroyed
678
+ /* @docs:
679
+ * @title: Destroyed
680
+ * @description: Check if the stream is destroyed.
681
+ * @property: true
682
+ * @usage:
683
+ * ...
684
+ * const ip = stream.destroyed;
685
+ */
686
+ get destroyed(): boolean {
687
+ if (this.http2) {
688
+ return this.s!.destroyed;
689
+ } else {
690
+ return this.req!.destroyed;
691
+ }
692
+ }
693
+
694
+ // ---------------------------------------------------------
695
+ // Functions.
696
+
697
+ // Get the authenticated uid.
698
+ /* @docs:
699
+ * @title: UID
700
+ * @description: Get the authenticated uid, is `null` when the request was not authenticated.
701
+ * @property: true
702
+ * @type: string
703
+ * @usage:
704
+ * ...
705
+ * const uid = stream.uid;
706
+ */
707
+ get uid(): string | null {
708
+ return this._uid;
709
+ }
710
+ set uid(value: string | null) {
711
+ this._uid = value;
712
+ }
713
+
714
+ // Send a response.
715
+ /* @docs:
716
+ * @title: Send
717
+ * @description: Send a response
718
+ * @parameter:
719
+ * @name: status
720
+ * @description: The response status.
721
+ * @type: number
722
+ * @parameter:
723
+ * @name: headers
724
+ * @description: The response headers.
725
+ * @type: object
726
+ * @parameter:
727
+ * @name: body
728
+ * @description: The response body.
729
+ * @type: any
730
+ * @parameter:
731
+ * @name: data
732
+ * @description: The response data.
733
+ * @type: undefined, string
734
+ * @deprecated: true
735
+ * @parameter:
736
+ * @name: compress
737
+ * @description: A boolean indicating if the response data should be compressed.
738
+ * @type: boolean
739
+ * @usage:
740
+ * ...
741
+ * stream.send({status: 200, data: "Hello World!"});
742
+ */
743
+ send({status = 200, headers = {}, body = null, data = null, compress = false}: {
744
+ status?: number,
745
+ headers?: Record<string, any>,
746
+ body?: any,
747
+ data?: any,
748
+ compress?: boolean
749
+ } = {}): this {
750
+
751
+ // Copy body.
752
+ if (data != null) {
753
+ body = data;
754
+ }
755
+
756
+ // Assign sent status code.
757
+ this.status_code = status;
758
+
759
+ // HTTP2.
760
+ if (this.http2) {
761
+ const stream = this.s as ServerHttp2Stream;
762
+
763
+ // Headers.
764
+ this.res_headers[":status"] = status;
765
+ this.set_headers(headers);
766
+ if (this.res_cookies.length > 0) {
767
+ this.res_headers["set-cookie"] = this.res_cookies;
768
+ }
769
+ if (compress) {
770
+ this.res_headers["Content-Encoding"] = "gzip";
771
+ this.res_headers["Vary"] = "Accept-Encoding";
772
+ }
773
+
774
+ // Is json.
775
+ if (body != null && typeof body === 'object' && Buffer.isBuffer(body) === false && (body instanceof Uint8Array) === false) {
776
+ this.res_headers["Content-Type"] = "application/json";
777
+ body = JSON.stringify(body);
778
+ }
779
+
780
+ // Respond.
781
+ stream.respond(this.res_headers as any)
782
+
783
+ // Compress.
784
+ if (compress) {
785
+ body = zlib.gzipSync(body, {level: zlib.constants.Z_BEST_COMPRESSION});
786
+ }
787
+
788
+ // End.
789
+ if (body != null) {
790
+ stream.end(Buffer.from(body));
791
+ // stream.end(body); // do not use toString() here or it will cause issues with writing binary data.
792
+ } else {
793
+ stream.end();
794
+ }
795
+ }
796
+
797
+ // HTTP1.
798
+ else {
799
+ const req = this.req as IncomingMessage;
800
+ const res = this.res as ServerResponse;
801
+
802
+ // Set status code.
803
+ res.statusCode = status;
804
+
805
+ // Set headers.
806
+ for (let i = 0; i < this.res_headers.length; i++) {
807
+ res.setHeader(this.res_headers[i][0], this.res_headers[i][1]);
808
+ }
809
+ Object.keys(headers).forEach((key) => {
810
+ res.setHeader(key, headers[key]);
811
+ });
812
+
813
+ // Set cookies.
814
+ if (this.cookies.length > 0) {
815
+ res.setHeader('Set-Cookie', this.res_cookies);
816
+ }
817
+
818
+ // Convert data.
819
+ if (body != null && typeof body === 'object' && Buffer.isBuffer(body) === false && (body instanceof Uint8Array) === false) {
820
+ res.setHeader("Content-Type", "application/json");
821
+ body = JSON.stringify(body);
822
+ }
823
+
824
+ // @todo compress.
825
+ if (compress) {
826
+ res.setHeader("Content-Encoding", "gzip");
827
+ res.setHeader("Vary", "Accept-Encoding");
828
+ body = zlib.gzipSync(body, {level: zlib.constants.Z_BEST_COMPRESSION});
829
+ }
830
+
831
+ // Set data.
832
+ if (body != null) {
833
+ res.end(body); // do not use toString() here or it will cause issues with writing binary data.
834
+ }
835
+
836
+ // End.
837
+ else {
838
+ res.end();
839
+ }
840
+ }
841
+
842
+ // Set as finished.
843
+ this.finished = true;
844
+
845
+ return this;
846
+ }
847
+
848
+ // Send a successs response.
849
+ /* @docs:
850
+ * @title: Send Successs
851
+ * @description: Send a response
852
+ * @parameter:
853
+ * @name: status
854
+ * @description: The response status.
855
+ * @type: number
856
+ * @parameter:
857
+ * @name: headers
858
+ * @description: The response headers.
859
+ * @type: object
860
+ * @parameter:
861
+ * @name: body
862
+ * @description: The response data.
863
+ * @type: any
864
+ * @parameter:
865
+ * @name: data
866
+ * @description: The response data.
867
+ * @type: undefined, string
868
+ * @deprecated: true
869
+ * @parameter:
870
+ * @name: compress
871
+ * @description: A boolean indicating if the response data should be compressed.
872
+ * @type: boolean
873
+ * @usage:
874
+ * ...
875
+ * stream.success({data: "Hello World!"});
876
+ */
877
+ success({status = 200, headers = {}, body = null, data = null, compress = false}: {
878
+ status?: number,
879
+ headers?: Record<string, any>,
880
+ body?: any,
881
+ data?: any,
882
+ compress?: boolean
883
+ } = {}): this {
884
+ return this.send({status: status, headers: headers, body: body ?? data, compress: compress});
885
+ }
886
+
887
+ // Send an error response.
888
+ /* @docs:
889
+ * @title: Send Error
890
+ * @description: Send an error response
891
+ * @parameter:
892
+ * @name: status
893
+ * @description: The response status.
894
+ * @type: number
895
+ * @parameter:
896
+ * @name: headers
897
+ * @description: The response headers.
898
+ * @type: object
899
+ * @parameter:
900
+ * @name: body
901
+ * @description: The response data.
902
+ * @type: any
903
+ * @parameter:
904
+ * @name: data
905
+ * @description: The response data.
906
+ * @type: undefined, string
907
+ * @deprecated: true
908
+ * @parameter:
909
+ * @name: compress
910
+ * @description: A boolean indicating if the response data should be compressed.
911
+ * @type: boolean
912
+ * @usage:
913
+ * ...
914
+ * stream.error({data: "Some error occured"});
915
+ */
916
+ error({status = 500, headers = {}, body = null, data = null, compress = false}: {
917
+ status?: number,
918
+ headers?: Record<string, any>,
919
+ body?: any,
920
+ data?: any,
921
+ compress?: boolean
922
+ } = {}): this {
923
+ return this.send({status: status, headers: headers, body: body ?? data, compress: compress});
924
+ }
925
+
926
+ // Set headers.
927
+ /* @docs:
928
+ * @title: Set header
929
+ * @description: Add a new header to the response data.
930
+ * @parameter:
931
+ * @name: name
932
+ * @description: The header name.
933
+ * @type: string
934
+ * @parameter:
935
+ * @name: value
936
+ * @description: The header value.
937
+ * @type: string
938
+ * @usage:
939
+ * ...
940
+ * stream.set_header("Connection", "close");
941
+ */
942
+ set_header(name: string, value: any): this {
943
+ if (this.http2) {
944
+ this.res_headers[name] = value;
945
+ } else {
946
+ this.res_headers.append([name, value]);
947
+ }
948
+ return this;
949
+ }
950
+
951
+ // Set headers.
952
+ /* @docs:
953
+ * @title: Set headers
954
+ * @description: Add new headers to the response data.
955
+ * @parameter:
956
+ * @name: headers
957
+ * @description: The new response headers.
958
+ * @type: object
959
+ * @usage:
960
+ * ...
961
+ * stream.set_headers({"Connection": "close"});
962
+ */
963
+ set_headers(headers: Record<string, any> = {}): this {
964
+ if (headers == null) { return this; }
965
+ if (this.http2) {
966
+ Object.keys(headers).forEach((key) => {
967
+ this.res_headers[key] = headers[key];
968
+ });
969
+ } else {
970
+ Object.keys(headers).forEach((key) => {
971
+ this.res_headers.append([key, headers[key]]);
972
+ });
973
+ }
974
+ return this;
975
+ }
976
+
977
+ // Remove header.
978
+ /* @docs:
979
+ * @title: Remove headers
980
+ * @description: Remove header names from the response data.
981
+ * @parameter:
982
+ * @name: ...names
983
+ * @description: The header names to remove.
984
+ * @type: ...string
985
+ * @usage:
986
+ * ...
987
+ * stream.remove_header("Connection", "User-Agent");
988
+ * @funcs: 2
989
+ */
990
+ remove_header(...names: string[]): this {
991
+ if (this.http1) {
992
+ const headers: [string, string][] = [];
993
+ for (let i = 0; i < this.res_headers.length; i++) {
994
+ if (!names.includes(this.res_headers[i][0])) {
995
+ headers.push(this.res_headers[i]);
996
+ }
997
+ }
998
+ this.res_headers = headers;
999
+ } else {
1000
+ for (let i = 0; i < names.length; i++) {
1001
+ delete this.res_headers[names[i]]
1002
+ }
1003
+ }
1004
+ return this;
1005
+ }
1006
+ remove_headers(...names: string[]): this {
1007
+ return this.remove_header(...names);
1008
+ }
1009
+
1010
+ // Set a cookie.
1011
+ /* @docs:
1012
+ * @title: Set cookie.
1013
+ * @description: Set a cookie that will be sent with the response.
1014
+ * @warning: Will only be added to the response when the user uses `send()`, `success()` or `error()`.
1015
+ * @parameter:
1016
+ * @name: cookie
1017
+ * @description: The cookie string.
1018
+ * @type: string
1019
+ * @usage:
1020
+ * ...
1021
+ * stream.set_cookie("MyCookie=Hello World;");
1022
+ */
1023
+ set_cookie(cookie: string): this {
1024
+ cookie = cookie.trim();
1025
+ const name_end = cookie.indexOf("=");
1026
+ if (name_end !== -1) {
1027
+ const name = cookie.substr(0, name_end);
1028
+ for (let i = 0; i < this.res_cookies.length; i++) {
1029
+ if (this.res_cookies[i].eq_first(name)) {
1030
+ this.res_cookies[i] = cookie;
1031
+ return this;
1032
+ }
1033
+ }
1034
+ }
1035
+ this.res_cookies.push(cookie);
1036
+ return this;
1037
+ }
1038
+
1039
+ // Set cookies.
1040
+ /* @docs:
1041
+ * @title: Set Cookies
1042
+ * @description: Set a cookie that will be sent with the response.
1043
+ * @warning: Will only be added to the response when the user uses `send()`, `success()` or `error()`.
1044
+ * @parameter:
1045
+ * @name: cookies
1046
+ * @description: The cookie strings.
1047
+ * @type: ...string
1048
+ * @usage:
1049
+ * ...
1050
+ * stream.set_cookies("MyCookie1=Hello World;", "MyCookie2=Hello Universe;");
1051
+ */
1052
+ set_cookies(...cookies: string[]): this {
1053
+ for (let i = 0; i < cookies.length; i++) {
1054
+ this.set_cookie(cookies[i]);
1055
+ }
1056
+ return this;
1057
+ }
1058
+ }
1059
+
1060
+
1061
+ // A stream that passed the `authenticated: true` attribute of an Enpdoint.
1062
+ export type AuthStream = Stream & {
1063
+ // private _uid: string;
1064
+ get uid(): string;
1065
+ }
1066
+
1067
+ // ---------------------------------------------------------
1068
+ // Exports.
1069
+
1070
+ export default Stream;