@vandenberghinc/volt 1.1.5 → 1.1.7

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 (287) hide show
  1. package/backend/dist/cjs/database.d.ts +41 -68
  2. package/backend/dist/cjs/database.js +127 -76
  3. package/backend/dist/cjs/endpoint.d.ts +23 -9
  4. package/backend/dist/cjs/endpoint.js +98 -21
  5. package/backend/dist/cjs/frontend.d.ts +0 -2
  6. package/backend/dist/cjs/frontend.js +9 -9
  7. package/backend/dist/cjs/image_endpoint.d.ts +3 -1
  8. package/backend/dist/cjs/image_endpoint.js +2 -1
  9. package/backend/dist/cjs/payments/paddle.js +10 -2
  10. package/backend/dist/cjs/plugins/css.d.ts +6 -5
  11. package/backend/dist/cjs/plugins/css.js +32 -7
  12. package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
  13. package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
  14. package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
  15. package/backend/dist/cjs/server.d.ts +7 -13
  16. package/backend/dist/cjs/server.js +184 -303
  17. package/backend/dist/cjs/status.d.ts +1 -0
  18. package/backend/dist/cjs/status.js +2 -1
  19. package/backend/dist/cjs/stream.d.ts +5 -3
  20. package/backend/dist/cjs/stream.js +13 -4
  21. package/backend/dist/cjs/users.d.ts +1 -1
  22. package/backend/dist/cjs/users.js +87 -72
  23. package/backend/dist/cjs/utils.d.ts +17 -9
  24. package/backend/dist/cjs/utils.js +22 -64
  25. package/backend/dist/cjs/view.d.ts +2 -2
  26. package/backend/dist/cjs/view.js +38 -40
  27. package/backend/dist/cjs/volt.d.ts +3 -2
  28. package/backend/dist/cjs/volt.js +2 -2
  29. package/backend/dist/css/volt.css +5 -0
  30. package/backend/dist/esm/database.d.ts +41 -68
  31. package/backend/dist/esm/database.js +127 -76
  32. package/backend/dist/esm/endpoint.d.ts +23 -9
  33. package/backend/dist/esm/endpoint.js +99 -22
  34. package/backend/dist/esm/frontend.d.ts +0 -2
  35. package/backend/dist/esm/frontend.js +9 -9
  36. package/backend/dist/esm/image_endpoint.d.ts +3 -1
  37. package/backend/dist/esm/image_endpoint.js +2 -1
  38. package/backend/dist/esm/payments/paddle.js +11 -3
  39. package/backend/dist/esm/plugins/css.d.ts +6 -5
  40. package/backend/dist/esm/plugins/css.js +32 -6
  41. package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
  42. package/backend/dist/esm/plugins/ts/compiler.js +26 -2
  43. package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
  44. package/backend/dist/esm/server.d.ts +7 -13
  45. package/backend/dist/esm/server.js +182 -301
  46. package/backend/dist/esm/status.d.ts +1 -0
  47. package/backend/dist/esm/status.js +1 -0
  48. package/backend/dist/esm/stream.d.ts +5 -3
  49. package/backend/dist/esm/stream.js +13 -4
  50. package/backend/dist/esm/users.d.ts +1 -1
  51. package/backend/dist/esm/users.js +87 -72
  52. package/backend/dist/esm/utils.d.ts +17 -9
  53. package/backend/dist/esm/utils.js +21 -62
  54. package/backend/dist/esm/view.d.ts +2 -2
  55. package/backend/dist/esm/view.js +38 -40
  56. package/backend/dist/esm/volt.d.ts +3 -2
  57. package/backend/dist/esm/volt.js +2 -1
  58. package/backend/dist/esm-dev/blacklist.js +1 -1
  59. package/backend/dist/esm-dev/cli.js +2 -2
  60. package/backend/dist/esm-dev/database.d.ts +41 -68
  61. package/backend/dist/esm-dev/database.js +128 -77
  62. package/backend/dist/esm-dev/endpoint.d.ts +23 -9
  63. package/backend/dist/esm-dev/endpoint.js +100 -23
  64. package/backend/dist/esm-dev/file_watcher.js +1 -1
  65. package/backend/dist/esm-dev/frontend.d.ts +0 -2
  66. package/backend/dist/esm-dev/frontend.js +9 -9
  67. package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
  68. package/backend/dist/esm-dev/image_endpoint.js +2 -1
  69. package/backend/dist/esm-dev/logger.js +1 -1
  70. package/backend/dist/esm-dev/payments/paddle.js +12 -4
  71. package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
  72. package/backend/dist/esm-dev/plugins/css.js +33 -7
  73. package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
  74. package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
  75. package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
  76. package/backend/dist/esm-dev/rate_limit.js +1 -1
  77. package/backend/dist/esm-dev/server.d.ts +7 -13
  78. package/backend/dist/esm-dev/server.js +184 -303
  79. package/backend/dist/esm-dev/status.d.ts +1 -0
  80. package/backend/dist/esm-dev/status.js +1 -0
  81. package/backend/dist/esm-dev/stream.d.ts +5 -3
  82. package/backend/dist/esm-dev/stream.js +13 -4
  83. package/backend/dist/esm-dev/users.d.ts +1 -1
  84. package/backend/dist/esm-dev/users.js +88 -73
  85. package/backend/dist/esm-dev/utils.d.ts +17 -9
  86. package/backend/dist/esm-dev/utils.js +22 -63
  87. package/backend/dist/esm-dev/view.d.ts +2 -2
  88. package/backend/dist/esm-dev/view.js +39 -41
  89. package/backend/dist/esm-dev/volt.d.ts +3 -2
  90. package/backend/dist/esm-dev/volt.js +2 -1
  91. package/backend/src/database.ts +163 -152
  92. package/backend/src/endpoint.ts +123 -31
  93. package/backend/src/frontend.ts +9 -8
  94. package/backend/src/image_endpoint.ts +4 -0
  95. package/backend/src/payments/paddle.ts +11 -3
  96. package/backend/src/plugins/css.ts +36 -8
  97. package/backend/src/plugins/ts/compiler.ts +37 -1
  98. package/backend/src/plugins/ts/preprocessing.ts +5 -3
  99. package/backend/src/server.ts +167 -306
  100. package/backend/src/status.ts +1 -0
  101. package/backend/src/stream.ts +28 -8
  102. package/backend/src/users.ts +87 -72
  103. package/backend/src/utils.ts +58 -25
  104. package/backend/src/view.ts +30 -28
  105. package/backend/src/{volt.js → volt.ts} +2 -1
  106. package/backend/tsconfig.cjs.json +3 -3
  107. package/backend/tsconfig.esm.json +3 -3
  108. package/frontend/dist/elements/base.d.ts +397 -415
  109. package/frontend/dist/elements/base.js +565 -328
  110. package/frontend/dist/elements/module.d.ts +26 -12
  111. package/frontend/dist/elements/module.js +69 -32
  112. package/frontend/dist/elements/register_element.d.ts +3 -0
  113. package/frontend/dist/elements/register_element.js +22 -0
  114. package/frontend/dist/modules/auth.d.ts +1 -0
  115. package/frontend/dist/modules/auth.js +6 -5
  116. package/frontend/dist/modules/color.d.ts +159 -0
  117. package/frontend/dist/modules/color.js +315 -0
  118. package/frontend/dist/modules/colors.d.ts +1 -26
  119. package/frontend/dist/modules/colors.js +417 -338
  120. package/frontend/dist/modules/cookies.d.ts +1 -0
  121. package/frontend/dist/modules/cookies.js +1 -0
  122. package/frontend/dist/modules/events.d.ts +1 -0
  123. package/frontend/dist/modules/events.js +1 -0
  124. package/frontend/dist/modules/google.d.ts +1 -0
  125. package/frontend/dist/modules/google.js +1 -0
  126. package/frontend/dist/modules/meta.d.ts +1 -0
  127. package/frontend/dist/modules/meta.js +1 -0
  128. package/frontend/dist/modules/mutex.d.ts +1 -2
  129. package/frontend/dist/modules/mutex.js +3 -4
  130. package/frontend/dist/modules/paddle.d.ts +1 -0
  131. package/frontend/dist/modules/paddle.js +14 -13
  132. package/frontend/dist/modules/scheme.d.ts +1 -0
  133. package/frontend/dist/modules/scheme.js +4 -2
  134. package/frontend/dist/modules/statics.d.ts +1 -0
  135. package/frontend/dist/modules/statics.js +1 -0
  136. package/frontend/dist/modules/support.d.ts +1 -0
  137. package/frontend/dist/modules/support.js +3 -2
  138. package/frontend/dist/modules/theme.d.ts +56 -0
  139. package/frontend/dist/{ui → modules}/theme.js +186 -75
  140. package/frontend/dist/modules/themes.d.ts +1 -1
  141. package/frontend/dist/modules/themes.js +1 -0
  142. package/frontend/dist/modules/user.d.ts +1 -0
  143. package/frontend/dist/modules/user.js +11 -10
  144. package/frontend/dist/modules/utils.d.ts +23 -2
  145. package/frontend/dist/modules/utils.js +93 -1
  146. package/frontend/dist/types/gradient.js +4 -0
  147. package/frontend/dist/ui/border_button.d.ts +0 -25
  148. package/frontend/dist/ui/border_button.js +50 -51
  149. package/frontend/dist/ui/button.d.ts +0 -21
  150. package/frontend/dist/ui/button.js +41 -46
  151. package/frontend/dist/ui/canvas.js +15 -15
  152. package/frontend/dist/ui/checkbox.d.ts +3 -17
  153. package/frontend/dist/ui/checkbox.js +36 -30
  154. package/frontend/dist/ui/code.d.ts +15 -82
  155. package/frontend/dist/ui/code.js +150 -125
  156. package/frontend/dist/ui/color.d.ts +0 -1
  157. package/frontend/dist/ui/color.js +1 -1
  158. package/frontend/dist/ui/context_menu.d.ts +4 -2
  159. package/frontend/dist/ui/context_menu.js +16 -17
  160. package/frontend/dist/ui/css.js +2 -0
  161. package/frontend/dist/ui/divider.d.ts +0 -7
  162. package/frontend/dist/ui/divider.js +21 -25
  163. package/frontend/dist/ui/dropdown.d.ts +13 -7
  164. package/frontend/dist/ui/dropdown.js +65 -30
  165. package/frontend/dist/ui/for_each.d.ts +0 -5
  166. package/frontend/dist/ui/for_each.js +17 -22
  167. package/frontend/dist/ui/form.d.ts +17 -12
  168. package/frontend/dist/ui/form.js +21 -18
  169. package/frontend/dist/ui/frame_modes.d.ts +9 -12
  170. package/frontend/dist/ui/frame_modes.js +8 -10
  171. package/frontend/dist/ui/google_map.d.ts +0 -11
  172. package/frontend/dist/ui/google_map.js +23 -28
  173. package/frontend/dist/ui/gradient.d.ts +0 -5
  174. package/frontend/dist/ui/gradient.js +17 -22
  175. package/frontend/dist/ui/image.d.ts +27 -58
  176. package/frontend/dist/ui/image.js +99 -93
  177. package/frontend/dist/ui/input.d.ts +20 -97
  178. package/frontend/dist/ui/input.js +192 -170
  179. package/frontend/dist/ui/link.d.ts +0 -18
  180. package/frontend/dist/ui/link.js +42 -48
  181. package/frontend/dist/ui/list.js +36 -37
  182. package/frontend/dist/ui/loader_button.d.ts +4 -19
  183. package/frontend/dist/ui/loader_button.js +35 -37
  184. package/frontend/dist/ui/loaders.d.ts +0 -8
  185. package/frontend/dist/ui/loaders.js +20 -25
  186. package/frontend/dist/ui/popup.d.ts +11 -8
  187. package/frontend/dist/ui/popup.js +183 -24
  188. package/frontend/dist/ui/pseudo.d.ts +3 -3
  189. package/frontend/dist/ui/pseudo.js +14 -17
  190. package/frontend/dist/ui/scroller.d.ts +10 -48
  191. package/frontend/dist/ui/scroller.js +306 -300
  192. package/frontend/dist/ui/slider.d.ts +9 -3
  193. package/frontend/dist/ui/slider.js +31 -17
  194. package/frontend/dist/ui/spacer.d.ts +0 -9
  195. package/frontend/dist/ui/spacer.js +21 -26
  196. package/frontend/dist/ui/span.js +13 -15
  197. package/frontend/dist/ui/stack.d.ts +14 -75
  198. package/frontend/dist/ui/stack.js +166 -169
  199. package/frontend/dist/ui/steps.d.ts +10 -23
  200. package/frontend/dist/ui/steps.js +47 -34
  201. package/frontend/dist/ui/style.d.ts +4 -3
  202. package/frontend/dist/ui/style.js +13 -18
  203. package/frontend/dist/ui/switch.d.ts +10 -4
  204. package/frontend/dist/ui/switch.js +24 -16
  205. package/frontend/dist/ui/table.d.ts +0 -23
  206. package/frontend/dist/ui/table.js +113 -119
  207. package/frontend/dist/ui/tabs.d.ts +3 -19
  208. package/frontend/dist/ui/tabs.js +35 -29
  209. package/frontend/dist/ui/text.d.ts +0 -8
  210. package/frontend/dist/ui/text.js +20 -25
  211. package/frontend/dist/ui/title.d.ts +0 -15
  212. package/frontend/dist/ui/title.js +39 -45
  213. package/frontend/dist/ui/ui.d.ts +0 -2
  214. package/frontend/dist/ui/ui.js +0 -2
  215. package/frontend/dist/ui/view.d.ts +3 -17
  216. package/frontend/dist/ui/view.js +27 -32
  217. package/frontend/dist/volt.d.ts +2 -1
  218. package/frontend/dist/volt.js +3 -1
  219. package/frontend/examples/dashboard/dashboard.ts +774 -0
  220. package/frontend/examples/theme/theme.ts +58 -0
  221. package/frontend/src/css/volt.css +5 -0
  222. package/frontend/src/elements/base.ts +767 -545
  223. package/frontend/src/elements/module.ts +90 -29
  224. package/frontend/src/elements/register_element.ts +24 -0
  225. package/frontend/src/modules/auth.ts +7 -6
  226. package/frontend/src/modules/color.ts +348 -0
  227. package/frontend/src/modules/colors.ts +468 -449
  228. package/frontend/src/modules/cookies.ts +1 -0
  229. package/frontend/src/modules/events.ts +1 -0
  230. package/frontend/src/modules/google.ts +1 -0
  231. package/frontend/src/modules/meta.ts +2 -1
  232. package/frontend/src/modules/mutex.ts +2 -4
  233. package/frontend/src/modules/paddle.ts +21 -20
  234. package/frontend/src/modules/scheme.ts +4 -3
  235. package/frontend/src/modules/statics.ts +2 -1
  236. package/frontend/src/modules/support.ts +3 -2
  237. package/frontend/src/modules/theme.ts +413 -0
  238. package/frontend/src/modules/themes.ts +2 -1
  239. package/frontend/src/modules/user.ts +12 -11
  240. package/frontend/src/modules/utils.ts +125 -2
  241. package/frontend/src/ui/border_button.ts +41 -37
  242. package/frontend/src/ui/button.ts +33 -32
  243. package/frontend/src/ui/canvas.ts +5 -2
  244. package/frontend/src/ui/checkbox.ts +21 -22
  245. package/frontend/src/ui/code.ts +92 -86
  246. package/frontend/src/ui/context_menu.ts +7 -5
  247. package/frontend/src/ui/css.ts +1 -1
  248. package/frontend/src/ui/divider.ts +15 -10
  249. package/frontend/src/ui/dropdown.ts +38 -21
  250. package/frontend/src/ui/for_each.ts +9 -8
  251. package/frontend/src/ui/form.ts +26 -21
  252. package/frontend/src/ui/frame_modes.ts +13 -17
  253. package/frontend/src/ui/google_map.ts +15 -13
  254. package/frontend/src/ui/gradient.ts +9 -8
  255. package/frontend/src/ui/image.ts +108 -86
  256. package/frontend/src/ui/input.ts +145 -144
  257. package/frontend/src/ui/link.ts +25 -23
  258. package/frontend/src/ui/list.ts +12 -6
  259. package/frontend/src/ui/loader_button.ts +26 -25
  260. package/frontend/src/ui/loaders.ts +12 -11
  261. package/frontend/src/ui/popup.ts +168 -14
  262. package/frontend/src/ui/pseudo.ts +5 -3
  263. package/frontend/src/ui/scroller.ts +303 -294
  264. package/frontend/src/ui/slider.ts +15 -10
  265. package/frontend/src/ui/spacer.ts +14 -11
  266. package/frontend/src/ui/span.ts +6 -2
  267. package/frontend/src/ui/stack.ts +196 -183
  268. package/frontend/src/ui/steps.ts +38 -22
  269. package/frontend/src/ui/style.ts +7 -4
  270. package/frontend/src/ui/switch.ts +16 -11
  271. package/frontend/src/ui/table.ts +42 -34
  272. package/frontend/src/ui/tabs.ts +20 -19
  273. package/frontend/src/ui/text.ts +12 -11
  274. package/frontend/src/ui/title.ts +22 -20
  275. package/frontend/src/ui/ui.ts +0 -2
  276. package/frontend/src/ui/view.ts +20 -19
  277. package/frontend/src/volt.ts +3 -1
  278. package/frontend/{compile.js → tools/compile.old.js} +2 -2
  279. package/frontend/tools/embed_scripts.js +69 -0
  280. package/frontend/tsconfig.json +26 -0
  281. package/package.json +8 -8
  282. package/frontend/dist/ui/theme.d.ts +0 -25
  283. package/frontend/exports.json +0 -1340
  284. package/frontend/src/modules/date.js +0 -535
  285. package/frontend/src/ui/color.ts +0 -117
  286. package/frontend/src/ui/theme.ts +0 -279
  287. /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
@@ -31,7 +31,7 @@ class Collection {
31
31
  static constructor_scheme = {
32
32
  name: "string",
33
33
  uid_based: "boolean",
34
- ttl: { type: "number", default: null },
34
+ ttl: { type: "number", default: null }, // ttl in msec
35
35
  indexes: {
36
36
  type: "array",
37
37
  default: [],
@@ -40,7 +40,7 @@ class Collection {
40
40
  scheme: {
41
41
  key: { type: "string", required: (data) => data.key == null && data.keys == null },
42
42
  keys: {
43
- type: ["string", "array"],
43
+ type: ["array"],
44
44
  required: (data) => data.key == null && data.keys == null, value_scheme: "string",
45
45
  postprocess: (keys) => typeof keys === "string" ? [keys] : keys,
46
46
  },
@@ -51,11 +51,6 @@ class Collection {
51
51
  postprocess: (info) => {
52
52
  if (typeof info === "string")
53
53
  return { keys: [info] };
54
- if (typeof info === "object" && info.key) {
55
- info.keys = info.key;
56
- delete info.key;
57
- return info;
58
- }
59
54
  return info;
60
55
  },
61
56
  },
@@ -65,9 +60,10 @@ class Collection {
65
60
  col;
66
61
  name;
67
62
  uid_based;
68
- ttl;
63
+ ttl; // ttl in msec
69
64
  ttl_enabled;
70
- constructor(name, collection, ttl = null, indexes = [], uid_based = false) {
65
+ constructor(name, collection, ttl = null, // ttl in msec
66
+ indexes = [], uid_based = false) {
71
67
  // Verify scheme.
72
68
  ({ indexes, ttl } = vlib.Scheme.verify({
73
69
  object: {
@@ -107,13 +103,8 @@ class Collection {
107
103
  }
108
104
  // Create indexes.
109
105
  if (Array.isArray(indexes) && indexes.length > 0) {
110
- for (const index of indexes) {
111
- this.create_index({
112
- keys: index.keys,
113
- options: index.options,
114
- commit_quorum: index.commit_quorum,
115
- forced: index.forced,
116
- });
106
+ for (let item of indexes) {
107
+ this.create_index(item);
117
108
  }
118
109
  }
119
110
  }
@@ -228,23 +219,22 @@ class Collection {
228
219
  @name: commitQuorum
229
220
  @desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
230
221
  */
231
- async create_index({ keys, options = null, commit_quorum = null, forced = false }) {
222
+ async create_index({ key = undefined, keys = undefined, // following the IndexOptions "key" or "keys" must be defined in typescript but not in raw js.
223
+ options = undefined, commit_quorum = undefined, forced = false }) {
224
+ // Create keys objs per input type.
232
225
  let keys_obj = {};
233
- if (typeof keys === "string") {
226
+ if (key) {
234
227
  keys_obj = {};
235
- keys_obj[keys] = 1;
228
+ keys_obj[key] = 1;
236
229
  }
237
- else if (Array.isArray(keys)) {
230
+ else if (Array.isArray(keys) && keys.length > 0) {
238
231
  keys_obj = {};
239
232
  for (const key of keys) {
240
233
  keys_obj[key] = 1;
241
234
  }
242
235
  }
243
- else if (keys == null || typeof keys !== "object") {
244
- vlib.Scheme.throw_invalid_type("keys", keys, ["string", "string[]", "object"], true);
245
- }
246
236
  else {
247
- keys_obj = keys;
237
+ throw new Error("Define one of the following parameters: [key, keys].");
248
238
  }
249
239
  // Drop index.
250
240
  if (forced) {
@@ -776,8 +766,8 @@ class UIDCollection {
776
766
  @name: commitQuorum
777
767
  @desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
778
768
  */
779
- async create_index({ keys, options = null, commit_quorum = null }) {
780
- return this._col.create_index({ keys, options, commit_quorum });
769
+ async create_index(args) {
770
+ return this._col.create_index(args);
781
771
  }
782
772
  /* @docs:
783
773
  * @title: Find
@@ -1165,11 +1155,11 @@ class Database {
1165
1155
  preview: { type: "boolean", default: true },
1166
1156
  preview_ip_whitelist: { type: "array", default: [] },
1167
1157
  daemon: { type: ["object", "boolean"], default: {} },
1168
- _server: "object",
1158
+ _server: { type: ["object", "undefined"] },
1169
1159
  };
1170
1160
  uri;
1171
- preview;
1172
- preview_ip_whitelist;
1161
+ // preview: boolean;
1162
+ // preview_ip_whitelist: string[];
1173
1163
  client_opts;
1174
1164
  config;
1175
1165
  source; // Using vlib.Path type
@@ -1182,9 +1172,14 @@ class Database {
1182
1172
  proc;
1183
1173
  daemon;
1184
1174
  db;
1185
- constructor({ uri = null, source = null, config = null, start_args = [], client = null, collections = [], uid_collections = [], preview = true, preview_ip_whitelist = [], daemon = {}, _server, }) {
1175
+ // System.
1176
+ _listed_cols;
1177
+ constructor({ uri = null, source = null, config = null, start_args = [], client = null, collections = [], uid_collections = [],
1178
+ // preview = true,
1179
+ // preview_ip_whitelist = [],
1180
+ daemon = {}, _server = undefined, }) {
1186
1181
  // Checks.
1187
- if (_server.is_primary && uri == null) {
1182
+ if (!_server || (_server.is_primary && uri == null)) {
1188
1183
  ({ uri, config, start_args, config, client } = vlib.Scheme.verify({
1189
1184
  object: arguments[0],
1190
1185
  check_unknown: true,
@@ -1193,24 +1188,27 @@ class Database {
1193
1188
  }
1194
1189
  // Arguments.
1195
1190
  this.uri = uri;
1196
- this.preview = preview;
1197
- this.preview_ip_whitelist = preview_ip_whitelist;
1191
+ // this.preview = preview;
1192
+ // this.preview_ip_whitelist = preview_ip_whitelist;
1198
1193
  this.client_opts = client;
1199
1194
  this.config = config || {};
1200
- this.source = source != null ? new vlib.Path(source) : _server.source.join(".db");
1195
+ this.source = source != null ? new vlib.Path(source) : _server?.source.join(".db");
1201
1196
  this.start_args = start_args;
1202
- this._collections = collections;
1203
- this._uid_collections = uid_collections;
1197
+ this._collections = collections ?? [];
1198
+ this._uid_collections = uid_collections ?? [];
1204
1199
  this.server = _server;
1205
1200
  // Attributes.
1206
1201
  this.client = null;
1207
1202
  this.collections = {};
1208
1203
  // Initialize the service daemon.
1209
- if (this.server.daemon && daemon !== false) {
1204
+ if (this.server?.daemon && daemon !== false) {
1210
1205
  const log_source = this.server.source.join(".logs");
1211
1206
  if (!log_source.exists()) {
1212
1207
  log_source.mkdir_sync();
1213
1208
  }
1209
+ if (!this.server) {
1210
+ throw new Error("Parameter 'Database._server' must be defined for this behaviour.");
1211
+ }
1214
1212
  this.daemon = new vlib.Daemon({
1215
1213
  name: this.server.daemon.name + ".mongodb",
1216
1214
  user: daemon.user || this.server.daemon.user,
@@ -1226,9 +1224,9 @@ class Database {
1226
1224
  });
1227
1225
  }
1228
1226
  }
1229
- // Database preview.
1230
- _initialize_db_preview() {
1231
- /*
1227
+ /* Database preview.
1228
+ _initialize_db_preview(): void {
1229
+
1232
1230
  if (this.preview && this.server.production === false) {
1233
1231
  this.server.endpoint(
1234
1232
 
@@ -1753,8 +1751,7 @@ class Database {
1753
1751
  },
1754
1752
  )
1755
1753
  }
1756
- */
1757
- }
1754
+ }*/
1758
1755
  // Connect.
1759
1756
  async connect() {
1760
1757
  try {
@@ -1774,7 +1771,7 @@ class Database {
1774
1771
  if (this.config.systemLog === undefined) {
1775
1772
  this.config.systemLog = {};
1776
1773
  }
1777
- this.config.systemLog.path = this.source.join("mongod.log").str();
1774
+ this.config.systemLog.path = this.source?.join("mongod.log").str();
1778
1775
  if (this.config.systemLog.destination === undefined) {
1779
1776
  this.config.systemLog.destination = "file";
1780
1777
  }
@@ -1784,21 +1781,23 @@ class Database {
1784
1781
  if (this.config.systemLog.logRotate === undefined) {
1785
1782
  this.config.systemLog.logRotate = "reopen";
1786
1783
  }
1787
- if (this.config.systemLog.verbosity === undefined) {
1784
+ if (this.config.systemLog.verbosity === undefined && this.server) {
1788
1785
  this.config.systemLog.verbosity = this.server.production ? 0 : 1;
1789
1786
  }
1790
1787
  if (this.config.storage === undefined) {
1791
1788
  this.config.storage = {};
1792
1789
  }
1793
- const db_path = this.source.join("db");
1794
- this.config.storage.dbPath = db_path.str();
1795
- if (!db_path.exists()) {
1796
- db_path.mkdir_sync();
1797
- }
1798
- if (this.config.processManagement === undefined) {
1799
- this.config.processManagement = {};
1790
+ if (this.source) {
1791
+ const db_path = this.source.join("db");
1792
+ this.config.storage.dbPath = db_path.str();
1793
+ if (!db_path.exists()) {
1794
+ db_path.mkdir_sync();
1795
+ }
1796
+ if (this.config.processManagement === undefined) {
1797
+ this.config.processManagement = {};
1798
+ }
1799
+ this.config.processManagement.pidFilePath = this.source.join("mongod.pid").str();
1800
1800
  }
1801
- this.config.processManagement.pidFilePath = this.source.join("mongod.pid").str();
1802
1801
  if (this.config.net === undefined) {
1803
1802
  this.config.net = {};
1804
1803
  }
@@ -1809,7 +1808,7 @@ class Database {
1809
1808
  this.config.net.bindIp = "127.0.0.1";
1810
1809
  }
1811
1810
  // Mode 2: Start database.
1812
- if (this.server.is_primary && this.uri == null) {
1811
+ if (this.server?.is_primary && this.uri == null) {
1813
1812
  // Create the database.
1814
1813
  if (!this.source.exists()) {
1815
1814
  this.source.mkdir_sync();
@@ -1839,7 +1838,7 @@ class Database {
1839
1838
  });
1840
1839
  }
1841
1840
  // Assign URI.
1842
- else if (!this.server.is_primary && this.uri == null) {
1841
+ else if (this.server && !this.server.is_primary && this.uri == null) {
1843
1842
  this.uri = `mongodb://${this.config.net.bindIp}:${this.config.net.port}/main`;
1844
1843
  }
1845
1844
  // Initialize client.
@@ -1854,33 +1853,65 @@ class Database {
1854
1853
  }
1855
1854
  // Connect.
1856
1855
  await this.connect();
1856
+ // Batch.
1857
+ const multiprocessing = true;
1858
+ const promises = [];
1857
1859
  // Create collections.
1858
- this._collections.forEach((info) => {
1859
- if (this[info.name] !== undefined) {
1860
- throw Error(`Unable to initialize database collection "${info.name}", this attribute name is already used.`);
1861
- }
1862
- if (Array.isArray(info.indexes)) {
1863
- for (const index of info.indexes) {
1864
- if (index != null && typeof index === "object") {
1865
- index.forced = true;
1860
+ for (const info of this._collections) {
1861
+ const promise = new Promise(resolve => {
1862
+ if (this[info.name] !== undefined) {
1863
+ throw Error(`Unable to initialize database collection "${info.name}", this attribute name is reserved for a system value.`);
1864
+ }
1865
+ if (Array.isArray(info.indexes)) {
1866
+ for (let index = 0; index < info.indexes.length; index++) {
1867
+ let item = info.indexes[index];
1868
+ if (typeof item === "string") {
1869
+ info.indexes[index] = item = { keys: [item] };
1870
+ }
1866
1871
  }
1867
1872
  }
1873
+ this.create_collection(info).then(data => {
1874
+ this[info.name] = data;
1875
+ resolve();
1876
+ });
1877
+ });
1878
+ if (multiprocessing) {
1879
+ promises.push(promise);
1868
1880
  }
1869
- this[info.name] = this.create_collection(info);
1870
- });
1871
- this._uid_collections.forEach((info) => {
1872
- if (this[info.name] !== undefined) {
1873
- throw Error(`Unable to initialize database collection "${info.name}", this attribute name is already used.`);
1881
+ else {
1882
+ await promise;
1874
1883
  }
1875
- if (Array.isArray(info.indexes)) {
1876
- for (const index of info.indexes) {
1877
- if (index != null && typeof index === "object") {
1878
- index.forced = true;
1884
+ }
1885
+ for (const info of this._uid_collections) {
1886
+ const promise = new Promise(resolve => {
1887
+ if (this[info.name] !== undefined) {
1888
+ throw Error(`Unable to initialize database collection "${info.name}", this attribute name is reserved for a system value.`);
1889
+ }
1890
+ if (Array.isArray(info.indexes)) {
1891
+ for (let index = 0; index < info.indexes.length; index++) {
1892
+ let item = info.indexes[index];
1893
+ if (typeof item === "string") {
1894
+ info.indexes[index] = item = {
1895
+ key: item,
1896
+ };
1897
+ }
1879
1898
  }
1880
1899
  }
1900
+ this.create_uid_collection(info).then(data => {
1901
+ this[info.name] = data;
1902
+ resolve();
1903
+ });
1904
+ });
1905
+ if (multiprocessing) {
1906
+ promises.push(promise);
1881
1907
  }
1882
- this[info.name] = this.create_uid_collection(info);
1883
- });
1908
+ else {
1909
+ await promise;
1910
+ }
1911
+ }
1912
+ if (multiprocessing) {
1913
+ await Promise.all(promises);
1914
+ }
1884
1915
  }
1885
1916
  // Close.
1886
1917
  async close() {
@@ -1891,7 +1922,7 @@ class Database {
1891
1922
  * @title: Create Collection
1892
1923
  * @description: Create a database collection.
1893
1924
  */
1894
- create_collection(info) {
1925
+ async create_collection(info) {
1895
1926
  // Set name by single string argument.
1896
1927
  let name;
1897
1928
  let indexes = [];
@@ -1908,6 +1939,17 @@ class Database {
1908
1939
  if (name in this.collections) {
1909
1940
  throw Error(`Collection "${name}" is already initialized.`);
1910
1941
  }
1942
+ // Logs.
1943
+ logger.log(1, log_source, `Initializing collection "${name}".`);
1944
+ // Check if the collection exists
1945
+ if (this._listed_cols == null) {
1946
+ this._listed_cols = await this.db.listCollections().toArray();
1947
+ }
1948
+ if (!this._listed_cols.find(x => x.name === name)) {
1949
+ logger.log(0, log_source, `Creating collection "${name}".`);
1950
+ await this.db.createCollection(name);
1951
+ }
1952
+ // Create collection.
1911
1953
  const col = new Collection(name, this.db.collection(name), ttl, indexes);
1912
1954
  this.collections[name] = col;
1913
1955
  return col;
@@ -1916,7 +1958,7 @@ class Database {
1916
1958
  * @title: Create UID Based Collection
1917
1959
  * @description: Create a UID based database collection.
1918
1960
  */
1919
- create_uid_collection(info) {
1961
+ async create_uid_collection(info) {
1920
1962
  // Set name by single string argument.
1921
1963
  let name;
1922
1964
  let indexes = [];
@@ -1929,10 +1971,19 @@ class Database {
1929
1971
  indexes = info.indexes || [];
1930
1972
  ttl = info.ttl || null;
1931
1973
  }
1932
- // Check collection.
1974
+ // Check duplicate collection.
1933
1975
  if (name in this.collections) {
1934
1976
  throw Error(`Collection "${name}" is already initialized.`);
1935
1977
  }
1978
+ // Logs.
1979
+ logger.log(1, log_source, `Initializing uid collection "${name}".`);
1980
+ // Check if the collection exists
1981
+ const collections = await this.db.listCollections({ name: name }).toArray();
1982
+ if (collections.length === 0) {
1983
+ logger.log(0, log_source, `Creating uid collection "${name}".`);
1984
+ await this.db.createCollection(name);
1985
+ }
1986
+ // Collection.
1936
1987
  const col = new UIDCollection(name, this.db.collection(name), indexes, ttl);
1937
1988
  this.collections[name] = col;
1938
1989
  return col;
@@ -1,18 +1,17 @@
1
1
  import { View } from './view.js';
2
2
  import { RateLimitGroup } from "./rate_limit.js";
3
3
  import { Stream, AuthStream, Params } from "./stream.js";
4
+ import type { Server } from "./server.js";
4
5
  type EndpointCallback = ((stream: Stream, params: Params) => any) | ((stream: AuthStream, params: Params) => any);
5
- export interface EndpointOptions {
6
+ interface BaseEndpointOptions {
6
7
  method?: string;
7
8
  endpoint: string | RegExp;
8
9
  authenticated?: boolean;
9
10
  rate_limit?: string | RateLimitGroup | RateLimitGroup[] | null;
10
11
  params?: Record<string, any> | null;
11
12
  callback?: EndpointCallback;
12
- view?: View | Record<string, any> | null;
13
13
  data?: any;
14
- content_type?: string;
15
- compress?: boolean;
14
+ compress?: "auto" | boolean;
16
15
  cache?: boolean | number;
17
16
  ip_whitelist?: string[] | null;
18
17
  sitemap?: boolean | null;
@@ -21,15 +20,25 @@ export interface EndpointOptions {
21
20
  _path?: string | null;
22
21
  _is_static?: boolean;
23
22
  }
23
+ interface EndpointOptionsWithView extends Omit<BaseEndpointOptions, "content_type" | "view"> {
24
+ view: View | Record<string, any>;
25
+ content_type?: string;
26
+ }
27
+ interface EndpointOptionsWithoutView extends BaseEndpointOptions {
28
+ view?: null | undefined;
29
+ content_type: string;
30
+ }
31
+ export type EndpointOptions = EndpointOptionsWithView | EndpointOptionsWithoutView;
24
32
  declare class Endpoint {
25
33
  static rate_limits: Map<string, any>;
34
+ static compressed_content_types: string[];
26
35
  method: string;
27
36
  endpoint: string | RegExp;
28
37
  authenticated: boolean;
29
38
  params: Record<string, any> | null;
30
39
  callback?: EndpointCallback;
31
40
  data: any;
32
- content_type: string;
41
+ content_type?: string;
33
42
  compress: boolean;
34
43
  cache: boolean | number;
35
44
  sitemap: boolean | null;
@@ -46,12 +55,17 @@ declare class Endpoint {
46
55
  raw_data?: any;
47
56
  content_length?: number;
48
57
  is_image_endpoint?: boolean;
49
- constructor({ method, endpoint, authenticated, rate_limit, params, callback, view, data, content_type, compress, cache, ip_whitelist, sitemap, robots, _templates, // only used in loading static files.
50
- _path, _is_static, }: EndpointOptions);
58
+ _initialized: boolean;
59
+ _server: any;
60
+ constructor({ method, endpoint, authenticated, rate_limit, params, callback, view, data, content_type, // = "text/plain",
61
+ compress, cache, ip_whitelist, sitemap, robots, _templates, // only used in loading static files.
62
+ _path, _is_static, _server, }: EndpointOptions & {
63
+ _server: Server;
64
+ });
51
65
  _load_data_by_path(server: any): this;
52
66
  _set_headers(stream: any): void;
53
67
  _refresh(server: any): Promise<void>;
54
- _initialize(server: any): Promise<void>;
55
- _serve(stream: any, status_code?: number): Promise<void>;
68
+ _dynamic_initialize(): Promise<void>;
69
+ _serve(stream: Stream, status_code?: number): Promise<void>;
56
70
  }
57
71
  export { Endpoint };
@@ -8,7 +8,7 @@ import CleanCSS from 'clean-css';
8
8
  import zlib from 'zlib';
9
9
  import { View } from './view.js';
10
10
  import { vlib } from "./vinc.js";
11
- import { Utils, FrontendError } from "./utils.js";
11
+ import { Utils, APIError } from "./utils.js";
12
12
  import { Status } from "./status.js";
13
13
  import { logger, LogSource } from "./logger.js";
14
14
  import { RateLimits } from "./rate_limit.js";
@@ -117,6 +117,57 @@ const log_source = new LogSource("Endpoint");
117
117
  class Endpoint {
118
118
  // Static attributes.
119
119
  static rate_limits = new Map();
120
+ static compressed_content_types = [
121
+ // Image formats (often already compressed)
122
+ "image/jpeg",
123
+ "image/png",
124
+ "image/gif",
125
+ "image/webp",
126
+ "image/bmp",
127
+ "image/tiff",
128
+ "image/vnd.microsoft.icon", // ICO
129
+ // Audio formats (usually compressed)
130
+ "audio/mpeg", // MP3
131
+ "audio/mp3",
132
+ "audio/ogg",
133
+ "audio/wav",
134
+ "audio/x-wav",
135
+ "audio/flac",
136
+ "audio/aac",
137
+ "audio/midi",
138
+ // Video formats (typically compressed)
139
+ "video/mp4",
140
+ "video/mpeg",
141
+ "video/ogg",
142
+ "video/webm",
143
+ "video/x-msvideo", // AVI
144
+ "video/quicktime", // MOV
145
+ // Archive / Compressed file formats
146
+ "application/zip",
147
+ "application/x-7z-compressed",
148
+ "application/x-rar-compressed",
149
+ "application/x-tar",
150
+ "application/gzip",
151
+ "application/x-gzip",
152
+ "application/x-bzip",
153
+ "application/x-bzip2",
154
+ "application/x-xz",
155
+ // Documents that are usually compressed internally
156
+ "application/pdf",
157
+ "application/vnd.ms-powerpoint",
158
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
159
+ "application/vnd.ms-excel",
160
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
161
+ "application/msword",
162
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
163
+ // Font files
164
+ "font/woff",
165
+ "font/woff2",
166
+ "application/font-sfnt",
167
+ "application/vnd.ms-fontobject",
168
+ // Other binary data
169
+ "application/octet-stream",
170
+ ];
120
171
  // Instance attributes
121
172
  method;
122
173
  endpoint;
@@ -141,8 +192,11 @@ class Endpoint {
141
192
  raw_data;
142
193
  content_length;
143
194
  is_image_endpoint;
144
- constructor({ method = "GET", endpoint = "/", authenticated = false, rate_limit = null, params = null, callback = undefined, view = null, data = null, content_type = "text/plain", compress = true, cache = true, ip_whitelist = null, sitemap = null, robots = null, _templates = {}, // only used in loading static files.
145
- _path = null, _is_static = false, }) {
195
+ _initialized = false;
196
+ _server;
197
+ constructor({ method = "GET", endpoint = "/", authenticated = false, rate_limit = null, params = null, callback = undefined, view = null, data = null, content_type, // = "text/plain",
198
+ compress = "auto", cache = true, ip_whitelist = null, sitemap = null, robots = null, _templates = {}, // only used in loading static files.
199
+ _path = null, _is_static = false, _server, }) {
146
200
  // Attributes.
147
201
  this.method = method;
148
202
  this.endpoint = endpoint;
@@ -153,7 +207,6 @@ class Endpoint {
153
207
  }
154
208
  this.data = data;
155
209
  this.content_type = content_type;
156
- this.compress = compress !== false;
157
210
  this.cache = cache;
158
211
  this.sitemap = sitemap;
159
212
  this.robots = robots;
@@ -174,6 +227,19 @@ class Endpoint {
174
227
  if (typeof this.endpoint === "string") {
175
228
  this.endpoint = Utils.clean_endpoint(this.endpoint);
176
229
  }
230
+ // Set compress.
231
+ if (compress === "auto" || typeof compress !== "boolean") {
232
+ compress = Endpoint.compressed_content_types.includes(this.content_type ?? "");
233
+ }
234
+ else if (compress === true && this.content_type != null && Endpoint.compressed_content_types.includes(this.content_type)) {
235
+ logger.warn(1, log_source, `Overriding parameter "compress", disabling compression of endpoint ${this.endpoint}.`);
236
+ compress = false;
237
+ }
238
+ this.compress = compress;
239
+ this.compress = false;
240
+ if (this.compress) {
241
+ console.log(">>> compress", { endpoint: this.endpoint, content_type: this.content_type });
242
+ }
177
243
  // Argument `view` may also be passed as an object instead of class View.
178
244
  if (view == null) {
179
245
  this.view = null;
@@ -215,6 +281,12 @@ class Endpoint {
215
281
  }
216
282
  // The endpoint parent for params verification.
217
283
  this._verify_params_parent = this.method + ":" + this.endpoint + ":";
284
+ // Initialize.
285
+ this._server = _server;
286
+ // Initialize html.
287
+ if (this.view != null) {
288
+ this.view._initialize(_server, this);
289
+ }
218
290
  }
219
291
  // Load data by path.
220
292
  _load_data_by_path(server) {
@@ -279,28 +351,33 @@ class Endpoint {
279
351
  }
280
352
  }
281
353
  // Initialize.
282
- async _initialize(server) {
354
+ async _dynamic_initialize() {
355
+ if (!this._server) {
356
+ throw new Error(`Endpoint "${this.method}:${this.endpoint}" is not initialized by the server yet.`);
357
+ }
283
358
  // Build html code of view.
284
359
  if (this.view != null) {
285
- this.view._initialize(server, this);
286
360
  await this.view._build_html();
287
361
  }
288
362
  // Compression enabled.
289
- if (server.production && this.callback == null && this.compress) {
363
+ if (this._server.production && this.callback == null && this.compress) {
290
364
  this._is_compressed = true;
291
365
  if (this.data != null) {
292
366
  this.raw_data = this.data;
293
367
  this.data = zlib.gzipSync(this.data, { level: zlib.constants.Z_BEST_COMPRESSION });
368
+ this.content_length = this.data.length;
294
369
  }
295
370
  else if (this.view != null) {
296
371
  this.view.raw_html = this.view.html;
297
372
  this.view.html = zlib.gzipSync(this.view.html, { level: zlib.constants.Z_BEST_COMPRESSION });
373
+ this.content_length = this.view.html.length;
298
374
  }
375
+ console.log(">>> Compressed - content_length:", this.content_length);
299
376
  }
300
377
  // Set cache headers.
301
- if (!server.production) {
302
- this.cache = false;
303
- }
378
+ // if (!this._server.production) {
379
+ this.cache = false; // @todo @tmp
380
+ // }
304
381
  if ((this.callback == null || this.is_image_endpoint) && (typeof this.cache === "number" || this.cache === true)) {
305
382
  if (this.cache === 1 || this.cache === true) {
306
383
  this.headers.push(["Cache-Control", "max-age=86400"]);
@@ -322,9 +399,16 @@ class Endpoint {
322
399
  if (this.content_type != null) {
323
400
  this.headers.push(["Content-Type", this.content_type]);
324
401
  }
402
+ if (this._is_compressed) {
403
+ console.log("Compressed headers:", this.headers);
404
+ }
405
+ this._initialized = true;
325
406
  }
326
407
  // Serve a client.
327
408
  async _serve(stream, status_code = 200) {
409
+ if (!this._initialized) {
410
+ await this._dynamic_initialize();
411
+ }
328
412
  try {
329
413
  // Check IP whitelist.
330
414
  if (this.ip_whitelist && !this.ip_whitelist.includes(stream.ip)) {
@@ -371,22 +455,15 @@ class Endpoint {
371
455
  }
372
456
  }
373
457
  catch (err) {
374
- if (err instanceof FrontendError) {
375
- let data = { error: err.message != null ? err.message : "Internal Server Error" };
376
- if (err.data != null && typeof err.data === "object") {
377
- Object.assign(data, err.data);
378
- }
379
- stream.send({
380
- status: err.status != null ? err.status : Status.internal_server_error,
381
- headers: { "Content-Type": "application/json" },
382
- data,
383
- });
458
+ if (err instanceof APIError) {
459
+ err.serve(stream);
384
460
  }
385
461
  else {
386
- stream.send({
462
+ stream.error({
387
463
  status: Status.internal_server_error,
388
464
  headers: { "Content-Type": "application/json" },
389
- data: { error: "Internal Server Error" },
465
+ message: "Internal Server Error",
466
+ type: "InternalServerError",
390
467
  });
391
468
  }
392
469
  logger.error(log_source, `${this.method}:${this.endpoint}: `, err); // after sending the response since this edits the error.
@@ -3,8 +3,6 @@ export declare const web_exports: {
3
3
  js: string;
4
4
  };
5
5
  export declare const Frontend: {
6
- load_globals(): Promise<string[]>;
7
- load_globals_sync(): string[];
8
6
  css: {
9
7
  adyen: string;
10
8
  volt: string;