@vandenberghinc/volt 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/dist/cjs/database.d.ts +41 -68
- package/backend/dist/cjs/database.js +136 -78
- package/backend/dist/cjs/endpoint.d.ts +23 -9
- package/backend/dist/cjs/endpoint.js +98 -21
- package/backend/dist/cjs/file_watcher.js +2 -2
- package/backend/dist/cjs/frontend.d.ts +0 -2
- package/backend/dist/cjs/frontend.js +9 -9
- package/backend/dist/cjs/image_endpoint.d.ts +3 -1
- package/backend/dist/cjs/image_endpoint.js +2 -1
- package/backend/dist/cjs/payments/paddle.js +10 -2
- package/backend/dist/cjs/plugins/css.d.ts +6 -5
- package/backend/dist/cjs/plugins/css.js +32 -7
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
- package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/cjs/server.d.ts +7 -13
- package/backend/dist/cjs/server.js +184 -303
- package/backend/dist/cjs/status.d.ts +1 -0
- package/backend/dist/cjs/status.js +2 -1
- package/backend/dist/cjs/stream.d.ts +5 -3
- package/backend/dist/cjs/stream.js +13 -4
- package/backend/dist/cjs/users.d.ts +1 -1
- package/backend/dist/cjs/users.js +87 -72
- package/backend/dist/cjs/utils.d.ts +17 -9
- package/backend/dist/cjs/utils.js +22 -64
- package/backend/dist/cjs/view.d.ts +2 -2
- package/backend/dist/cjs/view.js +38 -40
- package/backend/dist/cjs/volt.d.ts +3 -2
- package/backend/dist/cjs/volt.js +2 -2
- package/backend/dist/css/volt.css +5 -0
- package/backend/dist/esm/database.d.ts +41 -68
- package/backend/dist/esm/database.js +137 -79
- package/backend/dist/esm/endpoint.d.ts +23 -9
- package/backend/dist/esm/endpoint.js +99 -22
- package/backend/dist/esm/file_watcher.js +2 -2
- package/backend/dist/esm/frontend.d.ts +0 -2
- package/backend/dist/esm/frontend.js +9 -9
- package/backend/dist/esm/image_endpoint.d.ts +3 -1
- package/backend/dist/esm/image_endpoint.js +2 -1
- package/backend/dist/esm/payments/paddle.js +11 -3
- package/backend/dist/esm/plugins/css.d.ts +6 -5
- package/backend/dist/esm/plugins/css.js +32 -6
- package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm/plugins/ts/compiler.js +26 -2
- package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/esm/server.d.ts +7 -13
- package/backend/dist/esm/server.js +182 -301
- package/backend/dist/esm/status.d.ts +1 -0
- package/backend/dist/esm/status.js +1 -0
- package/backend/dist/esm/stream.d.ts +5 -3
- package/backend/dist/esm/stream.js +13 -4
- package/backend/dist/esm/users.d.ts +1 -1
- package/backend/dist/esm/users.js +87 -72
- package/backend/dist/esm/utils.d.ts +17 -9
- package/backend/dist/esm/utils.js +21 -62
- package/backend/dist/esm/view.d.ts +2 -2
- package/backend/dist/esm/view.js +38 -40
- package/backend/dist/esm/volt.d.ts +3 -2
- package/backend/dist/esm/volt.js +2 -1
- package/backend/dist/esm-dev/blacklist.js +1 -1
- package/backend/dist/esm-dev/cli.js +2 -2
- package/backend/dist/esm-dev/database.d.ts +41 -68
- package/backend/dist/esm-dev/database.js +138 -80
- package/backend/dist/esm-dev/endpoint.d.ts +23 -9
- package/backend/dist/esm-dev/endpoint.js +100 -23
- package/backend/dist/esm-dev/file_watcher.js +3 -3
- package/backend/dist/esm-dev/frontend.d.ts +0 -2
- package/backend/dist/esm-dev/frontend.js +9 -9
- package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
- package/backend/dist/esm-dev/image_endpoint.js +2 -1
- package/backend/dist/esm-dev/logger.js +1 -1
- package/backend/dist/esm-dev/payments/paddle.js +12 -4
- package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
- package/backend/dist/esm-dev/plugins/css.js +33 -7
- package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
- package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
- package/backend/dist/esm-dev/rate_limit.js +1 -1
- package/backend/dist/esm-dev/server.d.ts +7 -13
- package/backend/dist/esm-dev/server.js +184 -303
- package/backend/dist/esm-dev/status.d.ts +1 -0
- package/backend/dist/esm-dev/status.js +1 -0
- package/backend/dist/esm-dev/stream.d.ts +5 -3
- package/backend/dist/esm-dev/stream.js +13 -4
- package/backend/dist/esm-dev/users.d.ts +1 -1
- package/backend/dist/esm-dev/users.js +88 -73
- package/backend/dist/esm-dev/utils.d.ts +17 -9
- package/backend/dist/esm-dev/utils.js +22 -63
- package/backend/dist/esm-dev/view.d.ts +2 -2
- package/backend/dist/esm-dev/view.js +39 -41
- package/backend/dist/esm-dev/volt.d.ts +3 -2
- package/backend/dist/esm-dev/volt.js +2 -1
- package/backend/src/database.ts +173 -155
- package/backend/src/endpoint.ts +123 -31
- package/backend/src/file_watcher.ts +2 -2
- package/backend/src/frontend.ts +9 -8
- package/backend/src/image_endpoint.ts +4 -0
- package/backend/src/payments/paddle.ts +11 -3
- package/backend/src/plugins/css.ts +36 -8
- package/backend/src/plugins/ts/compiler.ts +37 -1
- package/backend/src/plugins/ts/preprocessing.ts +5 -3
- package/backend/src/server.ts +167 -306
- package/backend/src/status.ts +1 -0
- package/backend/src/stream.ts +28 -8
- package/backend/src/users.ts +87 -72
- package/backend/src/utils.ts +58 -25
- package/backend/src/view.ts +30 -28
- package/backend/src/{volt.js → volt.ts} +2 -1
- package/backend/tsconfig.cjs.json +3 -3
- package/backend/tsconfig.esm.json +3 -3
- package/frontend/dist/elements/base.d.ts +414 -432
- package/frontend/dist/elements/base.js +566 -329
- package/frontend/dist/elements/module.d.ts +26 -12
- package/frontend/dist/elements/module.js +69 -32
- package/frontend/dist/elements/register_element.d.ts +3 -0
- package/frontend/dist/elements/register_element.js +22 -0
- package/frontend/dist/modules/auth.d.ts +1 -0
- package/frontend/dist/modules/auth.js +6 -5
- package/frontend/dist/modules/color.d.ts +159 -0
- package/frontend/dist/modules/color.js +315 -0
- package/frontend/dist/modules/colors.d.ts +1 -26
- package/frontend/dist/modules/colors.js +417 -340
- package/frontend/dist/modules/cookies.d.ts +1 -0
- package/frontend/dist/modules/cookies.js +1 -0
- package/frontend/dist/modules/events.d.ts +1 -0
- package/frontend/dist/modules/events.js +1 -0
- package/frontend/dist/modules/google.d.ts +1 -0
- package/frontend/dist/modules/google.js +1 -0
- package/frontend/dist/modules/meta.d.ts +1 -0
- package/frontend/dist/modules/meta.js +1 -0
- package/frontend/dist/modules/mutex.d.ts +1 -2
- package/frontend/dist/modules/mutex.js +3 -4
- package/frontend/dist/modules/paddle.d.ts +1 -0
- package/frontend/dist/modules/paddle.js +14 -13
- package/frontend/dist/modules/scheme.d.ts +1 -0
- package/frontend/dist/modules/scheme.js +5 -3
- package/frontend/dist/modules/statics.d.ts +1 -0
- package/frontend/dist/modules/statics.js +1 -0
- package/frontend/dist/modules/support.d.ts +1 -0
- package/frontend/dist/modules/support.js +3 -2
- package/frontend/dist/modules/theme.d.ts +56 -0
- package/frontend/dist/{ui → modules}/theme.js +186 -75
- package/frontend/dist/modules/themes.d.ts +1 -1
- package/frontend/dist/modules/themes.js +1 -0
- package/frontend/dist/modules/user.d.ts +1 -0
- package/frontend/dist/modules/user.js +11 -10
- package/frontend/dist/modules/utils.d.ts +23 -2
- package/frontend/dist/modules/utils.js +93 -1
- package/frontend/dist/types/gradient.js +4 -0
- package/frontend/dist/ui/border_button.d.ts +0 -25
- package/frontend/dist/ui/border_button.js +50 -51
- package/frontend/dist/ui/button.d.ts +0 -21
- package/frontend/dist/ui/button.js +41 -46
- package/frontend/dist/ui/canvas.js +15 -15
- package/frontend/dist/ui/checkbox.d.ts +3 -17
- package/frontend/dist/ui/checkbox.js +36 -30
- package/frontend/dist/ui/code.d.ts +15 -82
- package/frontend/dist/ui/code.js +150 -125
- package/frontend/dist/ui/color.d.ts +0 -1
- package/frontend/dist/ui/color.js +1 -1
- package/frontend/dist/ui/context_menu.d.ts +4 -2
- package/frontend/dist/ui/context_menu.js +16 -17
- package/frontend/dist/ui/css.js +2 -0
- package/frontend/dist/ui/divider.d.ts +0 -7
- package/frontend/dist/ui/divider.js +21 -25
- package/frontend/dist/ui/dropdown.d.ts +13 -7
- package/frontend/dist/ui/dropdown.js +65 -30
- package/frontend/dist/ui/for_each.d.ts +0 -5
- package/frontend/dist/ui/for_each.js +17 -22
- package/frontend/dist/ui/form.d.ts +17 -12
- package/frontend/dist/ui/form.js +21 -18
- package/frontend/dist/ui/frame_modes.d.ts +9 -12
- package/frontend/dist/ui/frame_modes.js +8 -10
- package/frontend/dist/ui/google_map.d.ts +0 -11
- package/frontend/dist/ui/google_map.js +23 -28
- package/frontend/dist/ui/gradient.d.ts +0 -5
- package/frontend/dist/ui/gradient.js +17 -22
- package/frontend/dist/ui/image.d.ts +27 -58
- package/frontend/dist/ui/image.js +99 -93
- package/frontend/dist/ui/input.d.ts +20 -97
- package/frontend/dist/ui/input.js +192 -170
- package/frontend/dist/ui/link.d.ts +0 -18
- package/frontend/dist/ui/link.js +42 -48
- package/frontend/dist/ui/list.js +36 -37
- package/frontend/dist/ui/loader_button.d.ts +4 -19
- package/frontend/dist/ui/loader_button.js +35 -37
- package/frontend/dist/ui/loaders.d.ts +0 -8
- package/frontend/dist/ui/loaders.js +20 -25
- package/frontend/dist/ui/popup.d.ts +11 -8
- package/frontend/dist/ui/popup.js +183 -24
- package/frontend/dist/ui/pseudo.d.ts +3 -3
- package/frontend/dist/ui/pseudo.js +14 -17
- package/frontend/dist/ui/scroller.d.ts +10 -48
- package/frontend/dist/ui/scroller.js +306 -300
- package/frontend/dist/ui/slider.d.ts +9 -3
- package/frontend/dist/ui/slider.js +31 -17
- package/frontend/dist/ui/spacer.d.ts +0 -9
- package/frontend/dist/ui/spacer.js +21 -26
- package/frontend/dist/ui/span.js +13 -15
- package/frontend/dist/ui/stack.d.ts +14 -75
- package/frontend/dist/ui/stack.js +166 -169
- package/frontend/dist/ui/steps.d.ts +10 -23
- package/frontend/dist/ui/steps.js +47 -34
- package/frontend/dist/ui/style.d.ts +4 -3
- package/frontend/dist/ui/style.js +13 -18
- package/frontend/dist/ui/switch.d.ts +10 -4
- package/frontend/dist/ui/switch.js +24 -16
- package/frontend/dist/ui/table.d.ts +0 -23
- package/frontend/dist/ui/table.js +113 -119
- package/frontend/dist/ui/tabs.d.ts +3 -19
- package/frontend/dist/ui/tabs.js +35 -29
- package/frontend/dist/ui/text.d.ts +0 -8
- package/frontend/dist/ui/text.js +20 -25
- package/frontend/dist/ui/title.d.ts +0 -15
- package/frontend/dist/ui/title.js +39 -45
- package/frontend/dist/ui/ui.d.ts +0 -2
- package/frontend/dist/ui/ui.js +0 -2
- package/frontend/dist/ui/view.d.ts +3 -17
- package/frontend/dist/ui/view.js +27 -32
- package/frontend/dist/volt.d.ts +2 -1
- package/frontend/dist/volt.js +3 -1
- package/frontend/examples/dashboard/dashboard.ts +774 -0
- package/frontend/examples/theme/theme.ts +58 -0
- package/frontend/src/css/volt.css +5 -0
- package/frontend/src/elements/base.ts +767 -545
- package/frontend/src/elements/module.ts +90 -29
- package/frontend/src/elements/register_element.ts +24 -0
- package/frontend/src/modules/auth.ts +7 -6
- package/frontend/src/modules/color.ts +348 -0
- package/frontend/src/modules/colors.ts +468 -449
- package/frontend/src/modules/cookies.ts +1 -0
- package/frontend/src/modules/events.ts +1 -0
- package/frontend/src/modules/google.ts +1 -0
- package/frontend/src/modules/meta.ts +2 -1
- package/frontend/src/modules/mutex.ts +2 -4
- package/frontend/src/modules/paddle.ts +21 -20
- package/frontend/src/modules/scheme.ts +5 -4
- package/frontend/src/modules/statics.ts +2 -1
- package/frontend/src/modules/support.ts +3 -2
- package/frontend/src/modules/theme.ts +413 -0
- package/frontend/src/modules/themes.ts +2 -1
- package/frontend/src/modules/user.ts +12 -11
- package/frontend/src/modules/utils.ts +125 -2
- package/frontend/src/ui/border_button.ts +41 -37
- package/frontend/src/ui/button.ts +33 -32
- package/frontend/src/ui/canvas.ts +5 -2
- package/frontend/src/ui/checkbox.ts +21 -22
- package/frontend/src/ui/code.ts +92 -86
- package/frontend/src/ui/context_menu.ts +7 -5
- package/frontend/src/ui/css.ts +1 -1
- package/frontend/src/ui/divider.ts +15 -10
- package/frontend/src/ui/dropdown.ts +38 -21
- package/frontend/src/ui/for_each.ts +9 -8
- package/frontend/src/ui/form.ts +26 -21
- package/frontend/src/ui/frame_modes.ts +13 -17
- package/frontend/src/ui/google_map.ts +15 -13
- package/frontend/src/ui/gradient.ts +9 -8
- package/frontend/src/ui/image.ts +108 -86
- package/frontend/src/ui/input.ts +145 -144
- package/frontend/src/ui/link.ts +25 -23
- package/frontend/src/ui/list.ts +12 -6
- package/frontend/src/ui/loader_button.ts +26 -25
- package/frontend/src/ui/loaders.ts +12 -11
- package/frontend/src/ui/popup.ts +168 -14
- package/frontend/src/ui/pseudo.ts +5 -3
- package/frontend/src/ui/scroller.ts +303 -294
- package/frontend/src/ui/slider.ts +15 -10
- package/frontend/src/ui/spacer.ts +14 -11
- package/frontend/src/ui/span.ts +6 -2
- package/frontend/src/ui/stack.ts +196 -183
- package/frontend/src/ui/steps.ts +38 -22
- package/frontend/src/ui/style.ts +7 -4
- package/frontend/src/ui/switch.ts +16 -11
- package/frontend/src/ui/table.ts +42 -34
- package/frontend/src/ui/tabs.ts +20 -19
- package/frontend/src/ui/text.ts +12 -11
- package/frontend/src/ui/title.ts +22 -20
- package/frontend/src/ui/ui.ts +0 -2
- package/frontend/src/ui/view.ts +20 -19
- package/frontend/src/volt.ts +3 -1
- package/frontend/{compile.js → tools/compile.old.js} +2 -2
- package/frontend/tools/embed_scripts.js +69 -0
- package/frontend/tsconfig.json +26 -0
- package/package.json +7 -6
- package/frontend/dist/ui/theme.d.ts +0 -25
- package/frontend/exports.json +0 -1340
- package/frontend/src/modules/date.js +0 -535
- package/frontend/src/ui/color.ts +0 -117
- package/frontend/src/ui/theme.ts +0 -279
- /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
package/backend/src/database.ts
CHANGED
|
@@ -9,13 +9,23 @@
|
|
|
9
9
|
import { ChildProcess, spawn } from "child_process";
|
|
10
10
|
import { deserialize, serialize } from "bson";
|
|
11
11
|
import { Transform } from 'stream';
|
|
12
|
-
import { MongoClient, Collection as MongoCollection, ObjectId } from 'mongodb';
|
|
12
|
+
import { MongoClient, Collection as MongoCollection, ObjectId, ServerApiVersion } from 'mongodb';
|
|
13
13
|
import { logger, LogSource } from "./logger.js";
|
|
14
14
|
import { Status } from "./status.js";
|
|
15
15
|
import { vlib } from "@vinc";
|
|
16
|
+
import { resolve } from "path";
|
|
16
17
|
|
|
17
18
|
const log_source = new LogSource("Database")
|
|
18
19
|
|
|
20
|
+
interface BaseOptions {
|
|
21
|
+
options?: Record<string, any>;
|
|
22
|
+
commit_quorum?: any;
|
|
23
|
+
forced?: boolean;
|
|
24
|
+
}
|
|
25
|
+
type IndexOptions =
|
|
26
|
+
(BaseOptions & { key: string; keys?: never }) |
|
|
27
|
+
(BaseOptions & { key?: never; keys: string[] });
|
|
28
|
+
|
|
19
29
|
// ---------------------------------------------------------
|
|
20
30
|
// Collection.
|
|
21
31
|
// Path based collection, so "myfile", "mydir/myfile".
|
|
@@ -39,7 +49,7 @@ class Collection {
|
|
|
39
49
|
static constructor_scheme = {
|
|
40
50
|
name: "string",
|
|
41
51
|
uid_based: "boolean",
|
|
42
|
-
ttl: {type: "number", default: null},
|
|
52
|
+
ttl: {type: "number", default: null}, // ttl in msec
|
|
43
53
|
indexes: {
|
|
44
54
|
type: "array",
|
|
45
55
|
default: [],
|
|
@@ -48,7 +58,7 @@ class Collection {
|
|
|
48
58
|
scheme: {
|
|
49
59
|
key: {type: "string", required: (data) => data.key == null && data.keys == null },
|
|
50
60
|
keys: {
|
|
51
|
-
type: ["
|
|
61
|
+
type: ["array"],
|
|
52
62
|
required: (data) => data.key == null && data.keys == null, value_scheme: "string",
|
|
53
63
|
postprocess: (keys) => typeof keys === "string" ? [keys] : keys,
|
|
54
64
|
},
|
|
@@ -58,11 +68,6 @@ class Collection {
|
|
|
58
68
|
},
|
|
59
69
|
postprocess: (info) => {
|
|
60
70
|
if (typeof info === "string") return {keys: [info]}
|
|
61
|
-
if (typeof info === "object" && info.key) {
|
|
62
|
-
info.keys = info.key;
|
|
63
|
-
delete info.key;
|
|
64
|
-
return info;
|
|
65
|
-
}
|
|
66
71
|
return info;
|
|
67
72
|
},
|
|
68
73
|
},
|
|
@@ -74,19 +79,14 @@ class Collection {
|
|
|
74
79
|
col: MongoCollection;
|
|
75
80
|
name: string;
|
|
76
81
|
uid_based: boolean;
|
|
77
|
-
ttl: number | null;
|
|
82
|
+
ttl: number | null; // ttl in msec
|
|
78
83
|
ttl_enabled: boolean;
|
|
79
84
|
|
|
80
85
|
constructor(
|
|
81
86
|
name: string,
|
|
82
87
|
collection: MongoCollection,
|
|
83
|
-
ttl: number | null = null,
|
|
84
|
-
indexes:
|
|
85
|
-
keys: string[] | string | Record<string, any>,
|
|
86
|
-
options?: Record<string, any>,
|
|
87
|
-
commit_quorum?: any,
|
|
88
|
-
forced?: boolean
|
|
89
|
-
}> = [],
|
|
88
|
+
ttl: number | null = null, // ttl in msec
|
|
89
|
+
indexes: IndexOptions[] = [],
|
|
90
90
|
uid_based: boolean = false,
|
|
91
91
|
) {
|
|
92
92
|
|
|
@@ -120,7 +120,8 @@ class Collection {
|
|
|
120
120
|
if (this.ttl_enabled) {
|
|
121
121
|
this.col.dropIndex("_ttl_timestamp_1")
|
|
122
122
|
.catch(err => {
|
|
123
|
-
if (err.codeName !== 'IndexNotFound') {
|
|
123
|
+
if (err.codeName !== 'IndexNotFound' && err.codeName !== 'NamespaceNotFound') {
|
|
124
|
+
err.stack = new Error(err.message).stack;
|
|
124
125
|
throw err;
|
|
125
126
|
}
|
|
126
127
|
})
|
|
@@ -134,13 +135,8 @@ class Collection {
|
|
|
134
135
|
|
|
135
136
|
// Create indexes.
|
|
136
137
|
if (Array.isArray(indexes) && indexes.length > 0) {
|
|
137
|
-
for (
|
|
138
|
-
this.create_index(
|
|
139
|
-
keys: index.keys,
|
|
140
|
-
options: index.options,
|
|
141
|
-
commit_quorum: index.commit_quorum,
|
|
142
|
-
forced: index.forced,
|
|
143
|
-
})
|
|
138
|
+
for (let item of indexes) {
|
|
139
|
+
this.create_index(item)
|
|
144
140
|
}
|
|
145
141
|
}
|
|
146
142
|
}
|
|
@@ -269,31 +265,27 @@ class Collection {
|
|
|
269
265
|
@desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
|
|
270
266
|
*/
|
|
271
267
|
async create_index({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
key = undefined,
|
|
269
|
+
keys = undefined, // following the IndexOptions "key" or "keys" must be defined in typescript but not in raw js.
|
|
270
|
+
options = undefined,
|
|
271
|
+
commit_quorum = undefined,
|
|
275
272
|
forced = false
|
|
276
|
-
}: {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
commit_quorum?: any,
|
|
280
|
-
forced?: boolean
|
|
281
|
-
}): Promise<string> {
|
|
273
|
+
}: IndexOptions): Promise<string> {
|
|
274
|
+
|
|
275
|
+
// Create keys objs per input type.
|
|
282
276
|
let keys_obj: Record<string, number> = {};
|
|
283
|
-
if (
|
|
277
|
+
if (key) {
|
|
284
278
|
keys_obj = {};
|
|
285
|
-
keys_obj[
|
|
279
|
+
keys_obj[key] = 1;
|
|
286
280
|
}
|
|
287
|
-
else if (Array.isArray(keys)) {
|
|
281
|
+
else if (Array.isArray(keys) && keys.length > 0) {
|
|
288
282
|
keys_obj = {};
|
|
289
283
|
for (const key of keys) {
|
|
290
284
|
keys_obj[key] = 1;
|
|
291
285
|
}
|
|
292
286
|
}
|
|
293
|
-
else
|
|
294
|
-
|
|
295
|
-
} else {
|
|
296
|
-
keys_obj = keys;
|
|
287
|
+
else {
|
|
288
|
+
throw new Error("Define one of the following parameters: [key, keys].");
|
|
297
289
|
}
|
|
298
290
|
|
|
299
291
|
// Drop index.
|
|
@@ -875,11 +867,7 @@ class UIDCollection {
|
|
|
875
867
|
constructor(
|
|
876
868
|
name: string,
|
|
877
869
|
collection: MongoCollection,
|
|
878
|
-
indexes:
|
|
879
|
-
keys: string[] | string | Record<string, any>,
|
|
880
|
-
options?: Record<string, any>,
|
|
881
|
-
commit_quorum?: any
|
|
882
|
-
}> = [],
|
|
870
|
+
indexes: IndexOptions[] = [],
|
|
883
871
|
ttl: number | null = null,
|
|
884
872
|
) {
|
|
885
873
|
this._col = new Collection(name, collection, ttl, indexes, true);
|
|
@@ -901,16 +889,8 @@ class UIDCollection {
|
|
|
901
889
|
@name: commitQuorum
|
|
902
890
|
@desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
|
|
903
891
|
*/
|
|
904
|
-
async create_index({
|
|
905
|
-
|
|
906
|
-
options = null,
|
|
907
|
-
commit_quorum = null
|
|
908
|
-
}: {
|
|
909
|
-
keys: string[] | string | Record<string, any>,
|
|
910
|
-
options?: Record<string, any> | null,
|
|
911
|
-
commit_quorum?: any
|
|
912
|
-
}): Promise<string> {
|
|
913
|
-
return this._col.create_index({keys, options, commit_quorum});
|
|
892
|
+
async create_index(args: IndexOptions): Promise<string> {
|
|
893
|
+
return this._col.create_index(args);
|
|
914
894
|
}
|
|
915
895
|
|
|
916
896
|
/* @docs:
|
|
@@ -1353,34 +1333,26 @@ class Database {
|
|
|
1353
1333
|
preview: {type: "boolean", default: true},
|
|
1354
1334
|
preview_ip_whitelist: {type: "array", default: []},
|
|
1355
1335
|
daemon: {type: ["object", "boolean"], default: {}},
|
|
1356
|
-
_server: "object",
|
|
1336
|
+
_server: {type: ["object", "undefined"]},
|
|
1357
1337
|
}
|
|
1358
1338
|
|
|
1359
1339
|
uri: string | null;
|
|
1360
|
-
preview: boolean;
|
|
1361
|
-
preview_ip_whitelist: string[];
|
|
1340
|
+
// preview: boolean;
|
|
1341
|
+
// preview_ip_whitelist: string[];
|
|
1362
1342
|
client_opts: Record<string, any> | null;
|
|
1363
1343
|
config: Record<string, any>;
|
|
1364
|
-
source:
|
|
1344
|
+
source: vlib.Path | undefined; // Using vlib.Path type
|
|
1365
1345
|
start_args: string[];
|
|
1366
|
-
_collections:
|
|
1346
|
+
_collections: {
|
|
1367
1347
|
name: string,
|
|
1368
1348
|
ttl?: number | null,
|
|
1369
|
-
indexes?:
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
commit_quorum?: any
|
|
1373
|
-
}>,
|
|
1374
|
-
}>;
|
|
1375
|
-
_uid_collections: Array<{
|
|
1349
|
+
indexes?: string[] | IndexOptions[],
|
|
1350
|
+
}[];
|
|
1351
|
+
_uid_collections: {
|
|
1376
1352
|
name: string,
|
|
1377
1353
|
ttl?: number | null,
|
|
1378
|
-
indexes?:
|
|
1379
|
-
|
|
1380
|
-
options?: Record<string, any>,
|
|
1381
|
-
commit_quorum?: any
|
|
1382
|
-
}>,
|
|
1383
|
-
}>;
|
|
1354
|
+
indexes?: string[] | IndexOptions[],
|
|
1355
|
+
}[];
|
|
1384
1356
|
server: any;
|
|
1385
1357
|
client: MongoClient | null;
|
|
1386
1358
|
collections: Record<string, Collection | UIDCollection>;
|
|
@@ -1388,6 +1360,9 @@ class Database {
|
|
|
1388
1360
|
daemon?: any;
|
|
1389
1361
|
db?: any;
|
|
1390
1362
|
|
|
1363
|
+
// System.
|
|
1364
|
+
_listed_cols: any;
|
|
1365
|
+
|
|
1391
1366
|
constructor({
|
|
1392
1367
|
uri = null,
|
|
1393
1368
|
source = null,
|
|
@@ -1396,41 +1371,33 @@ class Database {
|
|
|
1396
1371
|
client = null,
|
|
1397
1372
|
collections = [],
|
|
1398
1373
|
uid_collections = [],
|
|
1399
|
-
preview = true,
|
|
1400
|
-
preview_ip_whitelist = [],
|
|
1374
|
+
// preview = true,
|
|
1375
|
+
// preview_ip_whitelist = [],
|
|
1401
1376
|
daemon = {},
|
|
1402
|
-
_server,
|
|
1377
|
+
_server = undefined,
|
|
1403
1378
|
}: {
|
|
1404
1379
|
uri?: string | null,
|
|
1405
1380
|
source?: string | null,
|
|
1406
1381
|
config?: Record<string, any> | null,
|
|
1407
1382
|
start_args?: string[],
|
|
1408
1383
|
client?: Record<string, any> | null,
|
|
1409
|
-
collections?:
|
|
1384
|
+
collections?: {
|
|
1410
1385
|
name: string,
|
|
1411
1386
|
ttl?: number | null,
|
|
1412
|
-
indexes?:
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
commit_quorum?: any
|
|
1416
|
-
}>,
|
|
1417
|
-
}>,
|
|
1418
|
-
uid_collections?: Array<{
|
|
1387
|
+
indexes?: string[] | IndexOptions[],
|
|
1388
|
+
}[],
|
|
1389
|
+
uid_collections?: {
|
|
1419
1390
|
name: string,
|
|
1420
1391
|
ttl?: number | null,
|
|
1421
|
-
indexes?:
|
|
1422
|
-
|
|
1423
|
-
options?: Record<string, any>,
|
|
1424
|
-
commit_quorum?: any
|
|
1425
|
-
}>,
|
|
1426
|
-
}>,
|
|
1392
|
+
indexes?: string[] | IndexOptions[],
|
|
1393
|
+
}[],
|
|
1427
1394
|
preview?: boolean,
|
|
1428
1395
|
preview_ip_whitelist?: string[],
|
|
1429
1396
|
daemon?: Record<string, any> | boolean,
|
|
1430
1397
|
_server: any,
|
|
1431
1398
|
}) {
|
|
1432
1399
|
// Checks.
|
|
1433
|
-
if (_server.is_primary && uri == null) {
|
|
1400
|
+
if (!_server || (_server.is_primary && uri == null)) {
|
|
1434
1401
|
({uri, config, start_args, config, client} = vlib.Scheme.verify({
|
|
1435
1402
|
object: arguments[0],
|
|
1436
1403
|
check_unknown: true,
|
|
@@ -1439,14 +1406,14 @@ class Database {
|
|
|
1439
1406
|
}
|
|
1440
1407
|
// Arguments.
|
|
1441
1408
|
this.uri = uri;
|
|
1442
|
-
this.preview = preview;
|
|
1443
|
-
this.preview_ip_whitelist = preview_ip_whitelist;
|
|
1409
|
+
// this.preview = preview;
|
|
1410
|
+
// this.preview_ip_whitelist = preview_ip_whitelist;
|
|
1444
1411
|
this.client_opts = client;
|
|
1445
1412
|
this.config = config || {};
|
|
1446
|
-
this.source = source != null ? new vlib.Path(source) : _server
|
|
1413
|
+
this.source = source != null ? new vlib.Path(source) : _server?.source.join(".db");
|
|
1447
1414
|
this.start_args = start_args;
|
|
1448
|
-
this._collections = collections;
|
|
1449
|
-
this._uid_collections = uid_collections;
|
|
1415
|
+
this._collections = collections ?? [];
|
|
1416
|
+
this._uid_collections = uid_collections ?? [];
|
|
1450
1417
|
this.server = _server;
|
|
1451
1418
|
|
|
1452
1419
|
// Attributes.
|
|
@@ -1454,18 +1421,21 @@ class Database {
|
|
|
1454
1421
|
this.collections = {};
|
|
1455
1422
|
|
|
1456
1423
|
// Initialize the service daemon.
|
|
1457
|
-
if (this.server
|
|
1424
|
+
if (this.server?.daemon && daemon !== false) {
|
|
1458
1425
|
const log_source = this.server.source.join(".logs");
|
|
1459
1426
|
if (!log_source.exists()) {
|
|
1460
1427
|
log_source.mkdir_sync();
|
|
1461
1428
|
}
|
|
1429
|
+
if (!this.server) {
|
|
1430
|
+
throw new Error("Parameter 'Database._server' must be defined for this behaviour.");
|
|
1431
|
+
}
|
|
1462
1432
|
this.daemon = new vlib.Daemon({
|
|
1463
1433
|
name: this.server.daemon.name + ".mongodb",
|
|
1464
1434
|
user: (daemon as Record<string, any>).user || this.server.daemon.user,
|
|
1465
1435
|
group: (daemon as Record<string, any>).group || this.server.daemon.group,
|
|
1466
1436
|
command: "mongod",
|
|
1467
1437
|
cwd: this.server.daemon.cwd,
|
|
1468
|
-
args: ["--config", this.source
|
|
1438
|
+
args: ["--config", this.source!.join("mongod.json").str(), ...this.start_args],
|
|
1469
1439
|
env: (daemon as Record<string, any>).env || this.server.daemon.env,
|
|
1470
1440
|
description: (daemon as Record<string, any>).description || `Service daemon for the mongo database of website ${this.server.domain}.`,
|
|
1471
1441
|
auto_restart: true,
|
|
@@ -1475,9 +1445,9 @@ class Database {
|
|
|
1475
1445
|
}
|
|
1476
1446
|
}
|
|
1477
1447
|
|
|
1478
|
-
|
|
1448
|
+
/* Database preview.
|
|
1479
1449
|
_initialize_db_preview(): void {
|
|
1480
|
-
|
|
1450
|
+
|
|
1481
1451
|
if (this.preview && this.server.production === false) {
|
|
1482
1452
|
this.server.endpoint(
|
|
1483
1453
|
|
|
@@ -2001,9 +1971,8 @@ class Database {
|
|
|
2001
1971
|
}
|
|
2002
1972
|
},
|
|
2003
1973
|
)
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
}
|
|
1974
|
+
}
|
|
1975
|
+
}*/
|
|
2007
1976
|
|
|
2008
1977
|
// Connect.
|
|
2009
1978
|
async connect(): Promise<void> {
|
|
@@ -2023,7 +1992,7 @@ class Database {
|
|
|
2023
1992
|
// Set default config.
|
|
2024
1993
|
if (this.config.systemLog === undefined) { this.config.systemLog = {}; }
|
|
2025
1994
|
|
|
2026
|
-
this.config.systemLog.path = this.source
|
|
1995
|
+
this.config.systemLog.path = this.source?.join("mongod.log").str()
|
|
2027
1996
|
|
|
2028
1997
|
if (this.config.systemLog.destination === undefined) {
|
|
2029
1998
|
this.config.systemLog.destination = "file";
|
|
@@ -2034,30 +2003,32 @@ class Database {
|
|
|
2034
2003
|
if (this.config.systemLog.logRotate === undefined) {
|
|
2035
2004
|
this.config.systemLog.logRotate = "reopen";
|
|
2036
2005
|
}
|
|
2037
|
-
if (this.config.systemLog.verbosity === undefined) {
|
|
2006
|
+
if (this.config.systemLog.verbosity === undefined && this.server) {
|
|
2038
2007
|
this.config.systemLog.verbosity = this.server.production ? 0 : 1;
|
|
2039
2008
|
}
|
|
2040
2009
|
|
|
2041
2010
|
if (this.config.storage === undefined) { this.config.storage = {}; }
|
|
2042
2011
|
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
db_path.
|
|
2047
|
-
|
|
2012
|
+
if (this.source) {
|
|
2013
|
+
const db_path = this.source.join("db");
|
|
2014
|
+
this.config.storage.dbPath = db_path.str()
|
|
2015
|
+
if (!db_path.exists()) {
|
|
2016
|
+
db_path.mkdir_sync();
|
|
2017
|
+
}
|
|
2048
2018
|
|
|
2049
|
-
|
|
2050
|
-
|
|
2019
|
+
if (this.config.processManagement === undefined) { this.config.processManagement = {}; }
|
|
2020
|
+
this.config.processManagement.pidFilePath = this.source.join("mongod.pid").str()
|
|
2021
|
+
}
|
|
2051
2022
|
|
|
2052
2023
|
if (this.config.net === undefined) { this.config.net = {}; }
|
|
2053
2024
|
if (this.config.net.port === undefined) { this.config.net.port = 27017; }
|
|
2054
2025
|
if (this.config.net.bindIp === undefined) { this.config.net.bindIp = "127.0.0.1"; }
|
|
2055
2026
|
|
|
2056
2027
|
// Mode 2: Start database.
|
|
2057
|
-
if (this.server
|
|
2028
|
+
if (this.server?.is_primary && this.uri == null) {
|
|
2058
2029
|
// Create the database.
|
|
2059
|
-
if (!this.source
|
|
2060
|
-
this.source
|
|
2030
|
+
if (!this.source!.exists()) {
|
|
2031
|
+
this.source!.mkdir_sync();
|
|
2061
2032
|
}
|
|
2062
2033
|
|
|
2063
2034
|
// Set the uri.
|
|
@@ -2066,7 +2037,7 @@ class Database {
|
|
|
2066
2037
|
}
|
|
2067
2038
|
|
|
2068
2039
|
// Save the config.
|
|
2069
|
-
const config_path = this.source
|
|
2040
|
+
const config_path = this.source!.join("mongod.json");
|
|
2070
2041
|
config_path.save_sync(JSON.stringify(this.config));
|
|
2071
2042
|
|
|
2072
2043
|
// Start the database.
|
|
@@ -2092,45 +2063,74 @@ class Database {
|
|
|
2092
2063
|
}
|
|
2093
2064
|
|
|
2094
2065
|
// Assign URI.
|
|
2095
|
-
else if (!this.server.is_primary && this.uri == null) {
|
|
2066
|
+
else if (this.server && !this.server.is_primary && this.uri == null) {
|
|
2096
2067
|
this.uri = `mongodb://${this.config.net.bindIp}:${this.config.net.port}/main`
|
|
2097
2068
|
}
|
|
2098
2069
|
|
|
2099
2070
|
// Initialize client.
|
|
2100
2071
|
if (this.uri) {
|
|
2101
|
-
|
|
2072
|
+
const opts = this.client_opts ?? {};
|
|
2073
|
+
opts.serverApi ??= {
|
|
2074
|
+
version: ServerApiVersion.v1,
|
|
2075
|
+
strict: true,
|
|
2076
|
+
deprecationErrors: true,
|
|
2077
|
+
};
|
|
2078
|
+
this.client = new MongoClient(this.uri, opts);
|
|
2102
2079
|
}
|
|
2103
2080
|
|
|
2104
2081
|
// Connect.
|
|
2105
2082
|
await this.connect();
|
|
2106
2083
|
|
|
2084
|
+
// Batch.
|
|
2085
|
+
const multiprocessing = true;
|
|
2086
|
+
const promises: Promise<any>[] = [];
|
|
2087
|
+
|
|
2107
2088
|
// Create collections.
|
|
2108
|
-
this._collections
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2089
|
+
for (const info of this._collections) {
|
|
2090
|
+
const promise = new Promise<void>(resolve => {
|
|
2091
|
+
if (this[info.name as keyof this] !== undefined) {
|
|
2092
|
+
throw Error(`Unable to initialize database collection "${info.name}", this attribute name is reserved for a system value.`);
|
|
2093
|
+
}
|
|
2094
|
+
if (Array.isArray(info.indexes)) {
|
|
2095
|
+
for (let index = 0; index < info.indexes.length; index++) {
|
|
2096
|
+
let item = info.indexes[index];
|
|
2097
|
+
if (typeof item === "string") {
|
|
2098
|
+
info.indexes[index] = item = { keys: [item] } as IndexOptions
|
|
2099
|
+
}
|
|
2116
2100
|
}
|
|
2117
2101
|
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2102
|
+
this.create_collection(info as any).then(data => {
|
|
2103
|
+
this[info.name] = data;
|
|
2104
|
+
resolve();
|
|
2105
|
+
})
|
|
2106
|
+
});
|
|
2107
|
+
if (multiprocessing) { promises.push(promise) }
|
|
2108
|
+
else { await promise }
|
|
2109
|
+
}
|
|
2110
|
+
for (const info of this._uid_collections) {
|
|
2111
|
+
const promise = new Promise<void>(resolve => {
|
|
2112
|
+
if (this[info.name as keyof this] !== undefined) {
|
|
2113
|
+
throw Error(`Unable to initialize database collection "${info.name}", this attribute name is reserved for a system value.`);
|
|
2114
|
+
}
|
|
2115
|
+
if (Array.isArray(info.indexes)) {
|
|
2116
|
+
for (let index = 0; index < info.indexes.length; index++) {
|
|
2117
|
+
let item = info.indexes[index];
|
|
2118
|
+
if (typeof item === "string") {
|
|
2119
|
+
info.indexes[index] = item = {
|
|
2120
|
+
key: item,
|
|
2121
|
+
} as IndexOptions
|
|
2122
|
+
}
|
|
2129
2123
|
}
|
|
2130
2124
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2125
|
+
this.create_uid_collection(info as any).then(data => {
|
|
2126
|
+
this[info.name] = data;
|
|
2127
|
+
resolve();
|
|
2128
|
+
})
|
|
2129
|
+
});
|
|
2130
|
+
if (multiprocessing) { promises.push(promise) }
|
|
2131
|
+
else { await promise }
|
|
2132
|
+
}
|
|
2133
|
+
if (multiprocessing) { await Promise.all(promises); }
|
|
2134
2134
|
}
|
|
2135
2135
|
|
|
2136
2136
|
// Close.
|
|
@@ -2143,15 +2143,11 @@ class Database {
|
|
|
2143
2143
|
* @title: Create Collection
|
|
2144
2144
|
* @description: Create a database collection.
|
|
2145
2145
|
*/
|
|
2146
|
-
create_collection(info: {
|
|
2146
|
+
async create_collection(info: {
|
|
2147
2147
|
name: string,
|
|
2148
|
-
indexes?:
|
|
2149
|
-
keys: string[] | string | Record<string, any>,
|
|
2150
|
-
options?: Record<string, any>,
|
|
2151
|
-
commit_quorum?: any
|
|
2152
|
-
}>,
|
|
2148
|
+
indexes?: IndexOptions[],
|
|
2153
2149
|
ttl?: number | null
|
|
2154
|
-
} | string): Collection {
|
|
2150
|
+
} | string): Promise<Collection> {
|
|
2155
2151
|
// Set name by single string argument.
|
|
2156
2152
|
let name: string;
|
|
2157
2153
|
let indexes: Array<any> = [];
|
|
@@ -2169,6 +2165,20 @@ class Database {
|
|
|
2169
2165
|
if (name in this.collections) {
|
|
2170
2166
|
throw Error(`Collection "${name}" is already initialized.`)
|
|
2171
2167
|
}
|
|
2168
|
+
|
|
2169
|
+
// Logs.
|
|
2170
|
+
logger.log(1, log_source, `Initializing collection "${name}".`);
|
|
2171
|
+
|
|
2172
|
+
// Check if the collection exists
|
|
2173
|
+
if (this._listed_cols == null) {
|
|
2174
|
+
this._listed_cols = await this.db.listCollections().toArray();
|
|
2175
|
+
}
|
|
2176
|
+
if (!this._listed_cols.find(x => x.name === name)) {
|
|
2177
|
+
logger.log(0, log_source, `Creating collection "${name}".`);
|
|
2178
|
+
await this.db.createCollection(name);
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
// Create collection.
|
|
2172
2182
|
const col = new Collection(
|
|
2173
2183
|
name,
|
|
2174
2184
|
this.db.collection(name),
|
|
@@ -2183,15 +2193,11 @@ class Database {
|
|
|
2183
2193
|
* @title: Create UID Based Collection
|
|
2184
2194
|
* @description: Create a UID based database collection.
|
|
2185
2195
|
*/
|
|
2186
|
-
create_uid_collection(info: {
|
|
2196
|
+
async create_uid_collection(info: {
|
|
2187
2197
|
name: string,
|
|
2188
|
-
indexes?:
|
|
2189
|
-
keys: string[] | string | Record<string, any>,
|
|
2190
|
-
options?: Record<string, any>,
|
|
2191
|
-
commit_quorum?: any
|
|
2192
|
-
}>,
|
|
2198
|
+
indexes?: IndexOptions[],
|
|
2193
2199
|
ttl?: number | null
|
|
2194
|
-
} | string): UIDCollection {
|
|
2200
|
+
} | string): Promise<UIDCollection> {
|
|
2195
2201
|
// Set name by single string argument.
|
|
2196
2202
|
let name: string;
|
|
2197
2203
|
let indexes: Array<any> = [];
|
|
@@ -2205,10 +2211,22 @@ class Database {
|
|
|
2205
2211
|
ttl = info.ttl || null;
|
|
2206
2212
|
}
|
|
2207
2213
|
|
|
2208
|
-
// Check collection.
|
|
2214
|
+
// Check duplicate collection.
|
|
2209
2215
|
if (name in this.collections) {
|
|
2210
2216
|
throw Error(`Collection "${name}" is already initialized.`)
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// Logs.
|
|
2220
|
+
logger.log(1, log_source, `Initializing uid collection "${name}".`);
|
|
2221
|
+
|
|
2222
|
+
// Check if the collection exists
|
|
2223
|
+
const collections = await this.db.listCollections({ name: name }).toArray();
|
|
2224
|
+
if (collections.length === 0) {
|
|
2225
|
+
logger.log(0, log_source, `Creating uid collection "${name}".`);
|
|
2226
|
+
await this.db.createCollection(name);
|
|
2211
2227
|
}
|
|
2228
|
+
|
|
2229
|
+
// Collection.
|
|
2212
2230
|
const col = new UIDCollection(
|
|
2213
2231
|
name,
|
|
2214
2232
|
this.db.collection(name),
|