@sfxcode/nuxt-ui-mongocamp 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/module.d.mts +12 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +18 -5
- package/dist/runtime/components/MongocampAggregationBuilder.vue +2 -2
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +5 -3
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +5 -3
- package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -1
- package/dist/runtime/components/MongocampCollectionData.vue +69 -5
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -1
- package/dist/runtime/components/MongocampCollectionInfos.vue +104 -8
- package/dist/runtime/components/MongocampCollections.d.vue.ts +8 -1
- package/dist/runtime/components/MongocampCollections.vue +84 -72
- package/dist/runtime/components/MongocampCollections.vue.d.ts +8 -1
- package/dist/runtime/components/MongocampConfirmByName.d.vue.ts +23 -0
- package/dist/runtime/components/MongocampConfirmByName.vue +92 -0
- package/dist/runtime/components/MongocampConfirmByName.vue.d.ts +23 -0
- package/dist/runtime/components/MongocampDashboard.d.vue.ts +5 -3
- package/dist/runtime/components/MongocampDashboard.vue.d.ts +5 -3
- package/dist/runtime/components/MongocampEmptyState.d.vue.ts +5 -3
- package/dist/runtime/components/MongocampEmptyState.vue.d.ts +5 -3
- package/dist/runtime/components/MongocampErrorAlert.vue +28 -5
- package/dist/runtime/components/MongocampGrantList.d.vue.ts +7 -0
- package/dist/runtime/components/MongocampGrantList.vue +38 -0
- package/dist/runtime/components/MongocampGrantList.vue.d.ts +7 -0
- package/dist/runtime/components/MongocampRoles.vue +45 -0
- package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
- package/dist/runtime/components/MongocampSettings.vue +179 -0
- package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
- package/dist/runtime/components/MongocampUsers.vue +183 -3
- package/dist/runtime/composables/useMongocampAdmin.d.ts +10 -4
- package/dist/runtime/composables/useMongocampAdmin.js +37 -1
- package/dist/runtime/composables/useMongocampAggregation.js +9 -30
- package/dist/runtime/composables/useMongocampBucket.js +1 -1
- package/dist/runtime/composables/useMongocampIndex.d.ts +1 -0
- package/dist/runtime/composables/useMongocampIndex.js +8 -1
- package/dist/runtime/composables/useMongocampQuery.d.ts +2 -2
- package/dist/runtime/composables/useMongocampRoles.d.ts +1 -0
- package/dist/runtime/composables/useMongocampRoles.js +3 -2
- package/dist/runtime/composables/useMongocampSession.d.ts +8 -0
- package/dist/runtime/composables/useMongocampSession.js +45 -0
- package/dist/runtime/composables/useMongocampSystem.d.ts +15 -3
- package/dist/runtime/composables/useMongocampSystem.js +19 -2
- package/dist/runtime/locales/de.json +61 -2
- package/dist/runtime/locales/en.json +61 -2
- package/dist/runtime/plugin.js +19 -0
- package/dist/runtime/utils/aggregationErrors.d.ts +1 -1
- package/dist/runtime/utils/aggregationErrors.js +0 -1
- package/dist/runtime/utils/collectionProtection.d.ts +3 -0
- package/dist/runtime/utils/collectionProtection.js +7 -0
- package/dist/runtime/utils/configRows.d.ts +11 -0
- package/dist/runtime/utils/configRows.js +53 -0
- package/dist/runtime/utils/failureKind.d.ts +3 -0
- package/dist/runtime/utils/failureKind.js +11 -0
- package/dist/runtime/utils/filterBuilder.d.ts +1 -1
- package/dist/runtime/utils/filterBuilder.js +8 -0
- package/dist/runtime/utils/jwtExpiry.d.ts +3 -0
- package/dist/runtime/utils/jwtExpiry.js +31 -0
- package/dist/runtime/utils/serverProbe.d.ts +10 -0
- package/dist/runtime/utils/serverProbe.js +25 -0
- package/dist/runtime/utils/sessionGuard.d.ts +10 -0
- package/dist/runtime/utils/sessionGuard.js +10 -0
- package/dist/runtime/utils/throttled.d.ts +6 -0
- package/dist/runtime/utils/throttled.js +16 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ The `mongocamp` key is forwarded to `@sfxcode/nuxt-mongocamp-server`. Set `MONGO
|
|
|
52
52
|
|
|
53
53
|
## Components
|
|
54
54
|
|
|
55
|
-
All components are auto-imported. The sections below cover the main ones; the [component reference](https://sfxcode.github.io/nuxt-ui-mongocamp/components/) lists every component, including `MongocampDashboard` (admin landing page), `MongocampJobs`, `MongocampAccount`, `MongocampDatabases`, `MongocampBucketFiles`, and the building blocks `MongocampFilterBuilder`, `MongocampBulkDelete`, `MongocampBulkEdit`, `MongocampImport`, `MongocampAggregationBuilder`, `MongocampErrorAlert` and `MongocampEmptyState`.
|
|
55
|
+
All components are auto-imported. The sections below cover the main ones; the [component reference](https://sfxcode.github.io/nuxt-ui-mongocamp/components/) lists every component, including `MongocampDashboard` (admin landing page), `MongocampJobs`, `MongocampAccount`, `MongocampDatabases`, `MongocampBucketFiles`, and the building blocks `MongocampFilterBuilder`, `MongocampBulkDelete`, `MongocampBulkEdit`, `MongocampImport`, `MongocampAggregationBuilder`, `MongocampConfirmByName`, `MongocampErrorAlert` and `MongocampEmptyState`.
|
|
56
56
|
|
|
57
57
|
### `<MongocampLogin />`
|
|
58
58
|
|
package/dist/module.d.mts
CHANGED
|
@@ -18,6 +18,18 @@ interface ModuleOptions {
|
|
|
18
18
|
* by the middleware itself, so it can never cause a redirect loop.
|
|
19
19
|
*/
|
|
20
20
|
logoutPath?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Opt-in dead-session guard: a route middleware that clears a session whose token says it has
|
|
23
|
+
* expired (the JWT `exp`, never verified) and sends the user to `loginPath` when the route they
|
|
24
|
+
* asked for needs a login. An unreadable token is never treated as expired. No effect in
|
|
25
|
+
* server proxy mode (there is no login).
|
|
26
|
+
*/
|
|
27
|
+
sessionGuard?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Path the session guard navigates to after clearing an expired session — e.g. '/login'. Always
|
|
30
|
+
* treated as allowed by the middleware itself, so it can never cause a redirect loop.
|
|
31
|
+
*/
|
|
32
|
+
loginPath?: string;
|
|
21
33
|
/**
|
|
22
34
|
* Roles with management access
|
|
23
35
|
*/
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,6 +2,21 @@ import { createResolver, defineNuxtModule, addPlugin, addComponentsDir, addImpor
|
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
4
|
|
|
5
|
+
function optionWarnings(options) {
|
|
6
|
+
const warnings = [];
|
|
7
|
+
if (options.useServerProxy && options.useGlobalAuthMiddleware) {
|
|
8
|
+
warnings.push(
|
|
9
|
+
"[nuxt-ui-mongocamp] `useServerProxy` and `useGlobalAuthMiddleware` are both enabled. Server proxy mode has no login/session, so `isLoggedIn`/`isAdmin`/`isManager` can never become true \u2014 every route matched by `securedRouteParts`, `managementRouteParts`, or `adminRouteParts` will be permanently unreachable."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
if (options.useServerProxy && options.sessionGuard) {
|
|
13
|
+
warnings.push(
|
|
14
|
+
"[nuxt-ui-mongocamp] `sessionGuard` has no effect together with `useServerProxy`: server proxy mode has no login, token or session to guard."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return warnings;
|
|
18
|
+
}
|
|
19
|
+
|
|
5
20
|
const { resolve } = createResolver(import.meta.url);
|
|
6
21
|
const runtimeDir = resolve("./runtime");
|
|
7
22
|
const module$1 = defineNuxtModule({
|
|
@@ -18,6 +33,8 @@ const module$1 = defineNuxtModule({
|
|
|
18
33
|
notAllowedPath: "/",
|
|
19
34
|
logoutRedirectPath: "/",
|
|
20
35
|
logoutPath: "/logout",
|
|
36
|
+
sessionGuard: false,
|
|
37
|
+
loginPath: "/",
|
|
21
38
|
managerRoles: [],
|
|
22
39
|
securedRouteParts: [],
|
|
23
40
|
managementRouteParts: [],
|
|
@@ -65,11 +82,7 @@ const module$1 = defineNuxtModule({
|
|
|
65
82
|
]
|
|
66
83
|
});
|
|
67
84
|
});
|
|
68
|
-
|
|
69
|
-
consola.warn(
|
|
70
|
-
"[nuxt-ui-mongocamp] `useServerProxy` and `useGlobalAuthMiddleware` are both enabled. Server proxy mode has no login/session, so `isLoggedIn`/`isAdmin`/`isManager` can never become true \u2014 every route matched by `securedRouteParts`, `managementRouteParts`, or `adminRouteParts` will be permanently unreachable."
|
|
71
|
-
);
|
|
72
|
-
}
|
|
85
|
+
for (const warning of optionWarnings(options)) consola.warn(warning);
|
|
73
86
|
addPlugin(resolve(runtimeDir, "plugin"));
|
|
74
87
|
addComponentsDir({ path: resolve(runtimeDir, "components") });
|
|
75
88
|
addImportsDir(resolve(runtimeDir, "composables"));
|
|
@@ -314,7 +314,7 @@ const exportMenuItems = computed(() => [
|
|
|
314
314
|
|
|
315
315
|
<UAlert
|
|
316
316
|
v-if="runError"
|
|
317
|
-
color="error"
|
|
317
|
+
:color="runError.kind === 'retryable' ? 'warning' : 'error'"
|
|
318
318
|
variant="subtle"
|
|
319
319
|
icon="i-lucide-circle-alert"
|
|
320
320
|
:title="t('nuxtUiMongocamp.aggregation.runFailedTitle')"
|
|
@@ -332,7 +332,7 @@ const exportMenuItems = computed(() => [
|
|
|
332
332
|
<UButton
|
|
333
333
|
v-else-if="runError.kind !== 'forbidden'"
|
|
334
334
|
:label="t('nuxtUiMongocamp.common.retry')"
|
|
335
|
-
color="error"
|
|
335
|
+
:color="runError.kind === 'retryable' ? 'warning' : 'error'"
|
|
336
336
|
variant="subtle"
|
|
337
337
|
icon="i-lucide-refresh-cw"
|
|
338
338
|
@click="execute(page)"
|
|
@@ -3,10 +3,12 @@ type __VLS_Props = {
|
|
|
3
3
|
deleting?: boolean;
|
|
4
4
|
error?: string;
|
|
5
5
|
};
|
|
6
|
-
declare
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
declare const __VLS_template: () => {
|
|
7
|
+
__VLS_Slots: {
|
|
8
|
+
actions?: (props: {}) => any;
|
|
9
|
+
};
|
|
9
10
|
};
|
|
11
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
10
12
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
11
13
|
open: () => any;
|
|
12
14
|
clear: () => any;
|
|
@@ -3,10 +3,12 @@ type __VLS_Props = {
|
|
|
3
3
|
deleting?: boolean;
|
|
4
4
|
error?: string;
|
|
5
5
|
};
|
|
6
|
-
declare
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
declare const __VLS_template: () => {
|
|
7
|
+
__VLS_Slots: {
|
|
8
|
+
actions?: (props: {}) => any;
|
|
9
|
+
};
|
|
9
10
|
};
|
|
11
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
10
12
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
11
13
|
open: () => any;
|
|
12
14
|
clear: () => any;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
2
|
collectionName: string;
|
|
3
|
+
infoPath?: string;
|
|
3
4
|
};
|
|
4
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
6
|
+
infoPath: string;
|
|
7
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
8
|
declare const _default: typeof __VLS_export;
|
|
6
9
|
export default _default;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, h, ref, resolveComponent, watch } from "vue";
|
|
3
|
-
import { useI18n, useMongocampClientApi, useMongocampError, useMongocampSchema } from "#imports";
|
|
3
|
+
import { useI18n, useMongocampClientApi, useMongocampError, useMongocampRoles, useMongocampSchema, useToast } from "#imports";
|
|
4
4
|
import useMongocampCollection from "../composables/useMongocampCollection";
|
|
5
5
|
import { useMongocampBucket } from "../composables/useMongocampBucket";
|
|
6
|
+
import { useMongocampIndex } from "../composables/useMongocampIndex";
|
|
6
7
|
import { unwrapExtendedJson, wrapExtendedJson } from "../composables/useMongocampExtendedJson";
|
|
7
8
|
import { isIsoDateTimeString } from "../utils/isoDate";
|
|
9
|
+
import { parseServerError } from "../utils/aggregationErrors";
|
|
8
10
|
import { downloadTextFile, rowsToCsv } from "../utils/exportRows";
|
|
9
11
|
import { runBulkDelete } from "../utils/bulkDelete";
|
|
10
12
|
import { BulkMatchShortfall, BulkUnaddressableId, buildIdFilter, isEditableField, runBulkUpdate } from "../utils/bulkEdit";
|
|
@@ -23,7 +25,8 @@ import useMongocampDocument from "../composables/useMongocampDocument";
|
|
|
23
25
|
import { useMongocampQuery } from "../composables/useMongocampQuery";
|
|
24
26
|
import { useMongocampAggregation } from "../composables/useMongocampAggregation";
|
|
25
27
|
const props = defineProps({
|
|
26
|
-
collectionName: { type: String, required: true }
|
|
28
|
+
collectionName: { type: String, required: true },
|
|
29
|
+
infoPath: { type: String, required: false, default: "/secured/admin/collections" }
|
|
27
30
|
});
|
|
28
31
|
const { t } = useI18n();
|
|
29
32
|
const { documentApi } = useMongocampClientApi();
|
|
@@ -33,6 +36,9 @@ const { ensureMetaData } = useMongocampDocument();
|
|
|
33
36
|
const { and, like, or } = useMongocampQuery();
|
|
34
37
|
const { schemaFromSamples } = useMongocampSchema();
|
|
35
38
|
const { listDistinct } = useMongocampAggregation();
|
|
39
|
+
const { createIndexForField } = useMongocampIndex();
|
|
40
|
+
const { isManager } = useMongocampRoles();
|
|
41
|
+
const toast = useToast();
|
|
36
42
|
const fileInputRef = ref(null);
|
|
37
43
|
function openFilePicker() {
|
|
38
44
|
fileInputRef.value?.click();
|
|
@@ -47,6 +53,7 @@ async function handleFileSelected(event) {
|
|
|
47
53
|
}
|
|
48
54
|
const UButton = resolveComponent("UButton");
|
|
49
55
|
const UTooltip = resolveComponent("UTooltip");
|
|
56
|
+
const UDropdownMenu = resolveComponent("UDropdownMenu");
|
|
50
57
|
const UCheckbox = resolveComponent("UCheckbox");
|
|
51
58
|
function withTooltip(text, node) {
|
|
52
59
|
return h(UTooltip, { text }, { default: () => node });
|
|
@@ -198,6 +205,63 @@ function sortHeader(column, label) {
|
|
|
198
205
|
onClick: () => column.toggleSorting(isSorted === "asc")
|
|
199
206
|
});
|
|
200
207
|
}
|
|
208
|
+
const indexing = ref(/* @__PURE__ */ new Set());
|
|
209
|
+
function canIndexField(key) {
|
|
210
|
+
return isManager.value && !isBucketCollection(props.collectionName) && key !== "_id" && key !== "metaData";
|
|
211
|
+
}
|
|
212
|
+
async function indexFailureMessage(error) {
|
|
213
|
+
try {
|
|
214
|
+
const body = await error?.response?.clone().json();
|
|
215
|
+
if (typeof body?.msg === "string" && body.msg) {
|
|
216
|
+
const message = parseServerError(body.msg).message;
|
|
217
|
+
if (message) return message;
|
|
218
|
+
}
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
return describeError(error).message;
|
|
222
|
+
}
|
|
223
|
+
async function indexField(key, ascending) {
|
|
224
|
+
if (indexing.value.has(key)) return;
|
|
225
|
+
indexing.value = new Set(indexing.value).add(key);
|
|
226
|
+
try {
|
|
227
|
+
const created = await createIndexForField(props.collectionName, key, ascending);
|
|
228
|
+
toast.add({
|
|
229
|
+
title: t("nuxtUiMongocamp.collectionData.indexCreatedTitle"),
|
|
230
|
+
description: t("nuxtUiMongocamp.collectionData.indexCreatedDescription", { name: created.name, collection: props.collectionName }),
|
|
231
|
+
color: "success",
|
|
232
|
+
actions: [{ label: t("nuxtUiMongocamp.collectionData.viewIndexes"), to: `${props.infoPath}/${props.collectionName}` }]
|
|
233
|
+
});
|
|
234
|
+
} catch (e) {
|
|
235
|
+
toast.add({ title: t("nuxtUiMongocamp.collectionData.indexFailedTitle", { field: key }), description: await indexFailureMessage(e), color: "error" });
|
|
236
|
+
} finally {
|
|
237
|
+
const next = new Set(indexing.value);
|
|
238
|
+
next.delete(key);
|
|
239
|
+
indexing.value = next;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function columnHeader(column, key) {
|
|
243
|
+
const sort = sortHeader(column, key);
|
|
244
|
+
if (!canIndexField(key)) return sort;
|
|
245
|
+
const label = t("nuxtUiMongocamp.collectionData.indexFieldTooltip", { field: key });
|
|
246
|
+
return h("div", { class: "flex items-center gap-1" }, [
|
|
247
|
+
sort,
|
|
248
|
+
h(UDropdownMenu, {
|
|
249
|
+
items: [[
|
|
250
|
+
{ label: t("nuxtUiMongocamp.collectionData.indexAscending"), icon: "i-lucide-arrow-up-narrow-wide", onSelect: () => indexField(key, true) },
|
|
251
|
+
{ label: t("nuxtUiMongocamp.collectionData.indexDescending"), icon: "i-lucide-arrow-down-wide-narrow", onSelect: () => indexField(key, false) }
|
|
252
|
+
]]
|
|
253
|
+
}, {
|
|
254
|
+
default: () => h(UButton, {
|
|
255
|
+
"icon": "i-lucide-list-tree",
|
|
256
|
+
"color": "neutral",
|
|
257
|
+
"variant": "ghost",
|
|
258
|
+
"size": "xs",
|
|
259
|
+
"aria-label": label,
|
|
260
|
+
"loading": indexing.value.has(key)
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
201
265
|
const columns = ref([]);
|
|
202
266
|
const documents = ref([]);
|
|
203
267
|
const loading = ref(false);
|
|
@@ -388,7 +452,7 @@ async function handleBulkDelete() {
|
|
|
388
452
|
}
|
|
389
453
|
}
|
|
390
454
|
const editableFields = computed(
|
|
391
|
-
() => filterFields.value.filter((f) => f.key !== "metaData" && isEditableField(f.key)).
|
|
455
|
+
() => filterFields.value.filter((f) => f.key !== "metaData" && isEditableField(f.key)).flatMap((f) => f.type === "objectId" ? [] : [{ key: f.key, type: f.type === "array" || f.type === "object" ? "json" : f.type }])
|
|
392
456
|
);
|
|
393
457
|
function bulkEditFailureReason(error) {
|
|
394
458
|
if (error instanceof BulkMatchShortfall) return t("nuxtUiMongocamp.bulk.editShortfall", { matched: error.matched, expected: error.expected });
|
|
@@ -446,13 +510,13 @@ async function fetchDocuments() {
|
|
|
446
510
|
];
|
|
447
511
|
columns.value = orderedKeys.map((key, index) => ({
|
|
448
512
|
accessorKey: key,
|
|
449
|
-
header: ({ column }) =>
|
|
513
|
+
header: ({ column }) => columnHeader(column, key),
|
|
450
514
|
cell: makeCell(key, "string"),
|
|
451
515
|
// keep the first column (usually _id) pinned so rows stay identifiable when the table scrolls sideways
|
|
452
516
|
...index === 0 ? { meta: { class: { th: "sticky left-0 z-10 bg-default", td: "sticky left-0 z-10 bg-default" } } } : {}
|
|
453
517
|
}));
|
|
454
518
|
filterableColumns.value = orderedKeys.filter((k) => k !== "_id" && k !== "metaData" && typeof firstRow[k] === "string");
|
|
455
|
-
filterFields.value = schemaFromSamples(rows).
|
|
519
|
+
filterFields.value = schemaFromSamples(rows).map((c) => ({ key: c.columnKey, type: c.columnKey === "_id" ? "objectId" : toFilterFieldType(c.columnType) })).filter((f) => operatorsFor(f.type).length > 0);
|
|
456
520
|
if (!isBucketCollection(props.collectionName)) {
|
|
457
521
|
columns.value.unshift(createSelectColumn(UCheckbox, { selectAll: t("nuxtUiMongocamp.bulk.selectAll"), selectRow: t("nuxtUiMongocamp.bulk.selectRow") }));
|
|
458
522
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
2
|
collectionName: string;
|
|
3
|
+
infoPath?: string;
|
|
3
4
|
};
|
|
4
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
6
|
+
infoPath: string;
|
|
7
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
8
|
declare const _default: typeof __VLS_export;
|
|
6
9
|
export default _default;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { computed, h, reactive, ref, resolveComponent, watch } from "vue";
|
|
3
3
|
import { useI18n, useMongocampClientApi, useMongocampIndex, useMongocampSchema, useToast } from "#imports";
|
|
4
4
|
import { useMongocampAggregation } from "../composables/useMongocampAggregation";
|
|
5
|
+
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
5
6
|
import { analyzeSamples } from "../utils/analyzeSamples";
|
|
7
|
+
import { downloadTextFile } from "../utils/exportRows";
|
|
6
8
|
const props = defineProps({
|
|
7
9
|
collectionName: { type: String, required: true },
|
|
8
10
|
sampleSize: { type: Number, required: false, default: 500 }
|
|
@@ -12,6 +14,7 @@ const { collectionApi, documentApi } = useMongocampClientApi();
|
|
|
12
14
|
const { schemaFromSamples, schemaToTsInterface } = useMongocampSchema();
|
|
13
15
|
const { listIndexes, createIndex, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex } = useMongocampIndex();
|
|
14
16
|
const { sampleDocuments, describeAggregationError } = useMongocampAggregation();
|
|
17
|
+
const { getJsonSchema } = useMongocampAdmin();
|
|
15
18
|
const UBadge = resolveComponent("UBadge");
|
|
16
19
|
const UIcon = resolveComponent("UIcon");
|
|
17
20
|
const UButton = resolveComponent("UButton");
|
|
@@ -67,6 +70,44 @@ async function copySchemaAsTs() {
|
|
|
67
70
|
await navigator.clipboard.writeText(tsInterface.value);
|
|
68
71
|
toast.add({ title: t("nuxtUiMongocamp.collectionInfos.copiedTitle"), description: t("nuxtUiMongocamp.collectionInfos.copiedDescription"), color: "success" });
|
|
69
72
|
}
|
|
73
|
+
const isSchemaOpen = ref(false);
|
|
74
|
+
const schemaJson = ref("");
|
|
75
|
+
const schemaLoading = ref(false);
|
|
76
|
+
const schemaError = ref(null);
|
|
77
|
+
let schemaRun = 0;
|
|
78
|
+
async function loadJsonSchema() {
|
|
79
|
+
const run = ++schemaRun;
|
|
80
|
+
schemaLoading.value = true;
|
|
81
|
+
schemaError.value = null;
|
|
82
|
+
try {
|
|
83
|
+
const schema = await getJsonSchema(props.collectionName);
|
|
84
|
+
if (run !== schemaRun) return;
|
|
85
|
+
schemaJson.value = JSON.stringify(schema, null, 2);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (run !== schemaRun) return;
|
|
88
|
+
schemaError.value = e;
|
|
89
|
+
} finally {
|
|
90
|
+
if (run === schemaRun) schemaLoading.value = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function openJsonSchema() {
|
|
94
|
+
isSchemaOpen.value = true;
|
|
95
|
+
if (!schemaJson.value) loadJsonSchema();
|
|
96
|
+
}
|
|
97
|
+
async function copyJsonSchema() {
|
|
98
|
+
await navigator.clipboard.writeText(schemaJson.value);
|
|
99
|
+
toast.add({ title: t("nuxtUiMongocamp.collectionInfos.copiedTitle"), description: t("nuxtUiMongocamp.collectionInfos.schemaCopiedDescription"), color: "success" });
|
|
100
|
+
}
|
|
101
|
+
function downloadJsonSchema() {
|
|
102
|
+
downloadTextFile(`${props.collectionName}.schema.json`, schemaJson.value, "application/json");
|
|
103
|
+
}
|
|
104
|
+
watch(() => props.collectionName, () => {
|
|
105
|
+
schemaRun++;
|
|
106
|
+
schemaJson.value = "";
|
|
107
|
+
schemaError.value = null;
|
|
108
|
+
schemaLoading.value = false;
|
|
109
|
+
isSchemaOpen.value = false;
|
|
110
|
+
});
|
|
70
111
|
const schemaTableColumns = computed(() => [
|
|
71
112
|
{
|
|
72
113
|
accessorKey: "field",
|
|
@@ -403,14 +444,24 @@ const indexTableColumns = computed(() => [
|
|
|
403
444
|
size="sm"
|
|
404
445
|
/>
|
|
405
446
|
</div>
|
|
406
|
-
<
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
447
|
+
<div class="flex items-center gap-1">
|
|
448
|
+
<UButton
|
|
449
|
+
icon="i-lucide-file-json"
|
|
450
|
+
:label="t('nuxtUiMongocamp.collectionInfos.jsonSchema')"
|
|
451
|
+
color="neutral"
|
|
452
|
+
variant="ghost"
|
|
453
|
+
size="sm"
|
|
454
|
+
@click="openJsonSchema"
|
|
455
|
+
/>
|
|
456
|
+
<UButton
|
|
457
|
+
icon="i-lucide-copy"
|
|
458
|
+
:label="t('nuxtUiMongocamp.collectionInfos.copyAsTs')"
|
|
459
|
+
color="neutral"
|
|
460
|
+
variant="ghost"
|
|
461
|
+
size="sm"
|
|
462
|
+
@click="copySchemaAsTs"
|
|
463
|
+
/>
|
|
464
|
+
</div>
|
|
414
465
|
</div>
|
|
415
466
|
</template>
|
|
416
467
|
<UTable
|
|
@@ -558,5 +609,50 @@ const indexTableColumns = computed(() => [
|
|
|
558
609
|
/>
|
|
559
610
|
</template>
|
|
560
611
|
</UModal>
|
|
612
|
+
|
|
613
|
+
<UModal
|
|
614
|
+
v-model:open="isSchemaOpen"
|
|
615
|
+
:title="t('nuxtUiMongocamp.collectionInfos.jsonSchemaTitle', { name: collectionName })"
|
|
616
|
+
:ui="{ content: 'sm:max-w-3xl', footer: 'justify-end' }"
|
|
617
|
+
>
|
|
618
|
+
<template #body>
|
|
619
|
+
<MongocampErrorAlert
|
|
620
|
+
:error="schemaError"
|
|
621
|
+
:title="t('nuxtUiMongocamp.collectionInfos.jsonSchemaFailedTitle')"
|
|
622
|
+
@retry="loadJsonSchema"
|
|
623
|
+
/>
|
|
624
|
+
<div
|
|
625
|
+
v-if="schemaLoading"
|
|
626
|
+
class="flex justify-center py-8"
|
|
627
|
+
>
|
|
628
|
+
<UIcon
|
|
629
|
+
name="i-lucide-loader-circle"
|
|
630
|
+
class="size-6 animate-spin text-dimmed"
|
|
631
|
+
/>
|
|
632
|
+
</div>
|
|
633
|
+
<pre
|
|
634
|
+
v-else-if="schemaJson"
|
|
635
|
+
class="max-h-[60vh] overflow-auto rounded-md bg-elevated p-3 text-xs"
|
|
636
|
+
tabindex="0"
|
|
637
|
+
:aria-label="t('nuxtUiMongocamp.collectionInfos.jsonSchema')"
|
|
638
|
+
>{{ schemaJson }}</pre>
|
|
639
|
+
</template>
|
|
640
|
+
<template #footer>
|
|
641
|
+
<UButton
|
|
642
|
+
icon="i-lucide-copy"
|
|
643
|
+
:label="t('nuxtUiMongocamp.common.copy')"
|
|
644
|
+
color="neutral"
|
|
645
|
+
variant="ghost"
|
|
646
|
+
:disabled="!schemaJson"
|
|
647
|
+
@click="copyJsonSchema"
|
|
648
|
+
/>
|
|
649
|
+
<UButton
|
|
650
|
+
icon="i-lucide-download"
|
|
651
|
+
:label="t('nuxtUiMongocamp.collectionInfos.downloadSchema')"
|
|
652
|
+
:disabled="!schemaJson"
|
|
653
|
+
@click="downloadJsonSchema"
|
|
654
|
+
/>
|
|
655
|
+
</template>
|
|
656
|
+
</UModal>
|
|
561
657
|
</div>
|
|
562
658
|
</template>
|
|
@@ -2,7 +2,14 @@ type __VLS_Props = {
|
|
|
2
2
|
infoPath?: string;
|
|
3
3
|
dataPath?: string;
|
|
4
4
|
bucketFilesPath?: string;
|
|
5
|
+
canManage?: boolean;
|
|
5
6
|
};
|
|
6
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
8
|
+
changed: () => any;
|
|
9
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
10
|
+
onChanged?: (() => any) | undefined;
|
|
11
|
+
}>, {
|
|
12
|
+
canManage: boolean;
|
|
13
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
14
|
declare const _default: typeof __VLS_export;
|
|
8
15
|
export default _default;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, h, ref, resolveComponent } from "vue";
|
|
3
|
-
import { useI18n, useMongocampClientApi, useMongocampBucket } from "#imports";
|
|
3
|
+
import { useI18n, useMongocampClientApi, useMongocampBucket, useMongocampRoles, useToast } from "#imports";
|
|
4
|
+
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
5
|
+
import { isProtectedCollection } from "../utils/collectionProtection";
|
|
4
6
|
const props = defineProps({
|
|
5
7
|
infoPath: { type: String, required: false },
|
|
6
8
|
dataPath: { type: String, required: false },
|
|
7
|
-
bucketFilesPath: { type: String, required: false }
|
|
9
|
+
bucketFilesPath: { type: String, required: false },
|
|
10
|
+
canManage: { type: Boolean, required: false, default: true }
|
|
8
11
|
});
|
|
12
|
+
const emit = defineEmits(["changed"]);
|
|
9
13
|
const { t } = useI18n();
|
|
10
14
|
const { collectionApi } = useMongocampClientApi();
|
|
11
15
|
const { isBucketCollection, bucketNameFor, bucketActionInFlight, clearBucket, deleteBucket } = useMongocampBucket();
|
|
16
|
+
const { clearCollection, deleteCollection } = useMongocampAdmin();
|
|
17
|
+
const { isAdmin } = useMongocampRoles();
|
|
18
|
+
const toast = useToast();
|
|
19
|
+
const canClearOrDrop = computed(() => props.canManage && isAdmin.value);
|
|
12
20
|
const collections = ref([]);
|
|
13
21
|
const loading = ref(false);
|
|
14
22
|
const loadError = ref(null);
|
|
@@ -44,29 +52,49 @@ function withTooltip(text, node) {
|
|
|
44
52
|
}
|
|
45
53
|
const globalFilter = ref("");
|
|
46
54
|
const sorting = ref([]);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const pending = ref(null);
|
|
56
|
+
const isConfirmOpen = ref(false);
|
|
57
|
+
function askToConfirm(kind, name) {
|
|
58
|
+
pending.value = { kind, name };
|
|
59
|
+
isConfirmOpen.value = true;
|
|
52
60
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const confirmTexts = computed(() => {
|
|
62
|
+
const name = pending.value?.name ?? "";
|
|
63
|
+
switch (pending.value?.kind) {
|
|
64
|
+
case "clear":
|
|
65
|
+
return { title: t("nuxtUiMongocamp.collections.clearTitle"), description: t("nuxtUiMongocamp.collections.confirmClear", { name }), label: t("nuxtUiMongocamp.collections.clearTitle"), color: "warning", icon: "i-lucide-eraser" };
|
|
66
|
+
case "drop":
|
|
67
|
+
return { title: t("nuxtUiMongocamp.collections.dropTitle"), description: t("nuxtUiMongocamp.collections.confirmDrop", { name }), label: t("nuxtUiMongocamp.collections.dropTitle"), color: "error", icon: "i-lucide-trash-2" };
|
|
68
|
+
case "clearBucket":
|
|
69
|
+
return { title: t("nuxtUiMongocamp.collections.clearBucketTitle"), description: t("nuxtUiMongocamp.collections.confirmClearBucket", { bucketName: name }), label: t("nuxtUiMongocamp.collections.clearBucketTitle"), color: "warning", icon: "i-lucide-eraser" };
|
|
70
|
+
default:
|
|
71
|
+
return { title: t("nuxtUiMongocamp.collections.deleteBucketTitle"), description: t("nuxtUiMongocamp.collections.confirmDeleteBucket", { bucketName: name }), label: t("nuxtUiMongocamp.collections.deleteBucketTitle"), color: "error", icon: "i-lucide-trash-2" };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
async function runBucketAction(action, bucketName) {
|
|
75
|
+
if (!await action(bucketName)) throw new Error(t("nuxtUiMongocamp.collections.bucketActionFailed", { bucketName }));
|
|
64
76
|
}
|
|
65
|
-
async function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
async function runPending() {
|
|
78
|
+
const action = pending.value;
|
|
79
|
+
if (!action) return;
|
|
80
|
+
switch (action.kind) {
|
|
81
|
+
case "clear":
|
|
82
|
+
await clearCollection(action.name);
|
|
83
|
+
toast.add({ title: t("nuxtUiMongocamp.collections.clearedTitle"), description: t("nuxtUiMongocamp.collections.clearedDescription", { name: action.name }), color: "success" });
|
|
84
|
+
break;
|
|
85
|
+
case "drop":
|
|
86
|
+
await deleteCollection(action.name);
|
|
87
|
+
toast.add({ title: t("nuxtUiMongocamp.collections.droppedTitle"), description: t("nuxtUiMongocamp.collections.droppedDescription", { name: action.name }), color: "success" });
|
|
88
|
+
break;
|
|
89
|
+
case "clearBucket":
|
|
90
|
+
await runBucketAction(clearBucket, action.name);
|
|
91
|
+
break;
|
|
92
|
+
case "deleteBucket":
|
|
93
|
+
await runBucketAction(deleteBucket, action.name);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
await fetchCollections();
|
|
97
|
+
emit("changed");
|
|
70
98
|
}
|
|
71
99
|
function sortHeader(column, label) {
|
|
72
100
|
const isSorted = column.getIsSorted();
|
|
@@ -140,7 +168,7 @@ const columns = computed(() => [
|
|
|
140
168
|
"size": "sm",
|
|
141
169
|
"aria-label": t("nuxtUiMongocamp.collections.clearBucketTooltip"),
|
|
142
170
|
"loading": bucketActionInFlight.value.has(bucketName),
|
|
143
|
-
"onClick": () =>
|
|
171
|
+
"onClick": () => askToConfirm("clearBucket", bucketName)
|
|
144
172
|
})),
|
|
145
173
|
withTooltip(t("nuxtUiMongocamp.collections.deleteBucketTooltip"), h(UButton, {
|
|
146
174
|
"icon": "i-lucide-trash-2",
|
|
@@ -149,7 +177,27 @@ const columns = computed(() => [
|
|
|
149
177
|
"size": "sm",
|
|
150
178
|
"aria-label": t("nuxtUiMongocamp.collections.deleteBucketTooltip"),
|
|
151
179
|
"loading": bucketActionInFlight.value.has(bucketName),
|
|
152
|
-
"onClick": () =>
|
|
180
|
+
"onClick": () => askToConfirm("deleteBucket", bucketName)
|
|
181
|
+
}))
|
|
182
|
+
);
|
|
183
|
+
} else if (canClearOrDrop.value && !isProtectedCollection(row.original.name)) {
|
|
184
|
+
const name = row.original.name;
|
|
185
|
+
buttons.push(
|
|
186
|
+
withTooltip(t("nuxtUiMongocamp.collections.clearTooltip"), h(UButton, {
|
|
187
|
+
"icon": "i-lucide-eraser",
|
|
188
|
+
"color": "warning",
|
|
189
|
+
"variant": "ghost",
|
|
190
|
+
"size": "sm",
|
|
191
|
+
"aria-label": t("nuxtUiMongocamp.collections.clearTooltip"),
|
|
192
|
+
"onClick": () => askToConfirm("clear", name)
|
|
193
|
+
})),
|
|
194
|
+
withTooltip(t("nuxtUiMongocamp.collections.dropTooltip"), h(UButton, {
|
|
195
|
+
"icon": "i-lucide-trash-2",
|
|
196
|
+
"color": "error",
|
|
197
|
+
"variant": "ghost",
|
|
198
|
+
"size": "sm",
|
|
199
|
+
"aria-label": t("nuxtUiMongocamp.collections.dropTooltip"),
|
|
200
|
+
"onClick": () => askToConfirm("drop", name)
|
|
153
201
|
}))
|
|
154
202
|
);
|
|
155
203
|
}
|
|
@@ -204,52 +252,16 @@ fetchCollections();
|
|
|
204
252
|
</template>
|
|
205
253
|
</UTable>
|
|
206
254
|
|
|
207
|
-
<
|
|
208
|
-
v-
|
|
209
|
-
:
|
|
210
|
-
:
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
color="neutral"
|
|
219
|
-
variant="ghost"
|
|
220
|
-
@click="isClearBucketModalOpen = false"
|
|
221
|
-
/>
|
|
222
|
-
<UButton
|
|
223
|
-
:label="t('nuxtUiMongocamp.collections.clearBucketTitle')"
|
|
224
|
-
color="warning"
|
|
225
|
-
icon="i-lucide-eraser"
|
|
226
|
-
@click="handleClearBucket"
|
|
227
|
-
/>
|
|
228
|
-
</template>
|
|
229
|
-
</UModal>
|
|
230
|
-
|
|
231
|
-
<UModal
|
|
232
|
-
v-model:open="isDeleteBucketModalOpen"
|
|
233
|
-
:title="t('nuxtUiMongocamp.collections.deleteBucketTitle')"
|
|
234
|
-
:ui="{ footer: 'justify-end' }"
|
|
235
|
-
>
|
|
236
|
-
<template #body>
|
|
237
|
-
<p>{{ t("nuxtUiMongocamp.collections.confirmDeleteBucket", { bucketName: bucketToDelete }) }}</p>
|
|
238
|
-
</template>
|
|
239
|
-
<template #footer>
|
|
240
|
-
<UButton
|
|
241
|
-
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
242
|
-
color="neutral"
|
|
243
|
-
variant="ghost"
|
|
244
|
-
@click="isDeleteBucketModalOpen = false"
|
|
245
|
-
/>
|
|
246
|
-
<UButton
|
|
247
|
-
:label="t('nuxtUiMongocamp.collections.deleteBucketTitle')"
|
|
248
|
-
color="error"
|
|
249
|
-
icon="i-lucide-trash-2"
|
|
250
|
-
@click="handleDeleteBucket"
|
|
251
|
-
/>
|
|
252
|
-
</template>
|
|
253
|
-
</UModal>
|
|
255
|
+
<MongocampConfirmByName
|
|
256
|
+
v-if="pending"
|
|
257
|
+
v-model:open="isConfirmOpen"
|
|
258
|
+
:name="pending.name"
|
|
259
|
+
:title="confirmTexts.title"
|
|
260
|
+
:description="confirmTexts.description"
|
|
261
|
+
:confirm-label="confirmTexts.label"
|
|
262
|
+
:confirm-color="confirmTexts.color"
|
|
263
|
+
:confirm-icon="confirmTexts.icon"
|
|
264
|
+
:on-confirm="runPending"
|
|
265
|
+
/>
|
|
254
266
|
</div>
|
|
255
267
|
</template>
|