@sfxcode/nuxt-ui-mongocamp 1.4.0 → 1.5.1
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.json +2 -2
- package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue +29 -2
- package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.vue +4 -3
- package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampBucketFiles.vue +61 -0
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +2 -12
- package/dist/runtime/components/MongocampBulkDelete.vue +14 -40
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +2 -12
- package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +5 -6
- package/dist/runtime/components/MongocampBulkEdit.vue +43 -26
- package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +5 -6
- package/dist/runtime/components/MongocampChart.vue +1 -4
- package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +2 -0
- package/dist/runtime/components/MongocampCollectionCharts.vue +9 -8
- package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +2 -0
- package/dist/runtime/components/MongocampCollectionCopy.vue +19 -258
- package/dist/runtime/components/MongocampCollectionData.d.vue.ts +2 -0
- package/dist/runtime/components/MongocampCollectionData.vue +206 -126
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +2 -0
- package/dist/runtime/components/MongocampCollectionRename.d.vue.ts +22 -0
- package/dist/runtime/components/MongocampCollectionRename.vue +116 -0
- package/dist/runtime/components/MongocampCollectionRename.vue.d.ts +22 -0
- package/dist/runtime/components/MongocampCollections.vue +31 -12
- package/dist/runtime/components/MongocampCommandPalette.vue +2 -2
- package/dist/runtime/components/MongocampDashboard.vue +19 -4
- package/dist/runtime/components/MongocampDatabases.vue +13 -2
- package/dist/runtime/components/MongocampExportAll.vue +13 -26
- package/dist/runtime/components/MongocampImport.vue +169 -3
- package/dist/runtime/components/MongocampIndexes.vue +54 -13
- package/dist/runtime/components/MongocampJobs.vue +14 -3
- package/dist/runtime/components/MongocampRoleGrants.vue +16 -3
- package/dist/runtime/components/MongocampRoles.vue +13 -2
- package/dist/runtime/components/MongocampServerInfo.d.vue.ts +24 -0
- package/dist/runtime/components/MongocampServerInfo.vue +331 -0
- package/dist/runtime/components/MongocampServerInfo.vue.d.ts +24 -0
- package/dist/runtime/components/MongocampServerOverview.vue +16 -39
- package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
- package/dist/runtime/components/MongocampSettings.vue +14 -2
- package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
- package/dist/runtime/components/MongocampUsers.vue +16 -3
- package/dist/runtime/components/MongocampVersion.d.vue.ts +7 -1
- package/dist/runtime/components/MongocampVersion.vue +49 -19
- package/dist/runtime/components/MongocampVersion.vue.d.ts +7 -1
- package/dist/runtime/composables/useMongocampAdminGate.d.ts +12 -0
- package/dist/runtime/composables/useMongocampAdminGate.js +12 -0
- package/dist/runtime/composables/useMongocampAggregation.d.ts +11 -0
- package/dist/runtime/composables/useMongocampAggregation.js +12 -5
- package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +15 -0
- package/dist/runtime/composables/useMongocampBulkByFilter.js +32 -0
- package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +25 -65
- package/dist/runtime/composables/useMongocampCollectionCopy.js +27 -84
- package/dist/runtime/composables/useMongocampExportAll.d.ts +27 -21
- package/dist/runtime/composables/useMongocampExportAll.js +51 -21
- package/dist/runtime/composables/useMongocampExtendedJson.d.ts +2 -1
- package/dist/runtime/composables/useMongocampExtendedJson.js +32 -5
- package/dist/runtime/composables/useMongocampFetchAll.js +1 -1
- package/dist/runtime/composables/useMongocampFieldTypes.d.ts +24 -0
- package/dist/runtime/composables/useMongocampFieldTypes.js +44 -0
- package/dist/runtime/composables/useMongocampImport.d.ts +4 -0
- package/dist/runtime/composables/useMongocampImport.js +5 -2
- package/dist/runtime/composables/useMongocampIndex.d.ts +6 -1
- package/dist/runtime/composables/useMongocampIndex.js +7 -1
- package/dist/runtime/composables/useMongocampPermissions.d.ts +8 -5
- package/dist/runtime/composables/useMongocampPermissions.js +24 -2
- package/dist/runtime/composables/useMongocampQuery.d.ts +3 -3
- package/dist/runtime/composables/useMongocampServerOverview.d.ts +4 -11
- package/dist/runtime/composables/useMongocampServerOverview.js +12 -22
- package/dist/runtime/composables/useMongocampSystem.d.ts +10 -1
- package/dist/runtime/composables/useMongocampSystem.js +11 -1
- package/dist/runtime/locales/de.json +104 -71
- package/dist/runtime/locales/en.json +104 -71
- package/dist/runtime/plugin.d.ts +2 -2
- package/dist/runtime/utils/aggregationErrors.d.ts +4 -0
- package/dist/runtime/utils/aggregationErrors.js +7 -0
- package/dist/runtime/utils/batchInsert.d.ts +6 -0
- package/dist/runtime/utils/batchInsert.js +31 -3
- package/dist/runtime/utils/bsonTypes.d.ts +10 -0
- package/dist/runtime/utils/bsonTypes.js +42 -0
- package/dist/runtime/utils/collectionCopy.d.ts +0 -2
- package/dist/runtime/utils/collectionCopy.js +0 -1
- package/dist/runtime/utils/configRows.d.ts +7 -0
- package/dist/runtime/utils/configRows.js +4 -0
- package/dist/runtime/utils/documentCompare.js +2 -1
- package/dist/runtime/utils/documentPaths.d.ts +5 -8
- package/dist/runtime/utils/documentPaths.js +5 -10
- package/dist/runtime/utils/documentTree.js +9 -1
- package/dist/runtime/utils/exportDocuments.d.ts +0 -2
- package/dist/runtime/utils/exportDocuments.js +0 -1
- package/dist/runtime/utils/exportRows.d.ts +2 -0
- package/dist/runtime/utils/exportRows.js +5 -2
- package/dist/runtime/utils/fieldDetails.d.ts +51 -0
- package/dist/runtime/utils/fieldDetails.js +113 -0
- package/dist/runtime/utils/indexForm.d.ts +47 -33
- package/dist/runtime/utils/indexForm.js +32 -21
- package/dist/runtime/utils/serverInfo.d.ts +8 -0
- package/dist/runtime/utils/serverInfo.js +21 -0
- package/package.json +11 -11
- package/dist/runtime/utils/indexCopy.d.ts +0 -26
- package/dist/runtime/utils/indexCopy.js +0 -22
- package/dist/runtime/utils/limitedMap.d.ts +0 -17
- package/dist/runtime/utils/limitedMap.js +0 -19
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isIsoDateTimeString } from "../utils/isoDate.js";
|
|
2
|
+
import { wireValue } from "../utils/bsonTypes.js";
|
|
2
3
|
function isPlainObject(value) {
|
|
3
4
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
5
|
}
|
|
@@ -26,6 +27,7 @@ export function unwrapExtendedJson(value, options = {}) {
|
|
|
26
27
|
if (Array.isArray(value)) return value.map((item) => unwrapExtendedJson(item, options));
|
|
27
28
|
if (!isPlainObject(value)) return value;
|
|
28
29
|
if (typeof value.$oid === "string") return value.$oid;
|
|
30
|
+
if (typeof value.$string === "string" && Object.keys(value).length === 1) return value.$string;
|
|
29
31
|
if ("$date" in value) return unwrapDateTime(value);
|
|
30
32
|
const number = unwrapNumber(value, options.exactLongs ?? true);
|
|
31
33
|
if (number !== void 0) return number;
|
|
@@ -33,10 +35,35 @@ export function unwrapExtendedJson(value, options = {}) {
|
|
|
33
35
|
for (const [key, v] of Object.entries(value)) result[key] = unwrapExtendedJson(v, options);
|
|
34
36
|
return result;
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
const INT32_MIN = -(2 ** 31);
|
|
39
|
+
const INT32_MAX = 2 ** 31 - 1;
|
|
40
|
+
function rewrapNumber(value, original) {
|
|
41
|
+
if (!Number.isFinite(value)) return value;
|
|
42
|
+
if ("$numberInt" in original && Number.isInteger(value) && value >= INT32_MIN && value <= INT32_MAX) return { $numberInt: String(value) };
|
|
43
|
+
if ("$numberLong" in original && Number.isSafeInteger(value)) return { $numberLong: String(value) };
|
|
44
|
+
if ("$numberDouble" in original) return { $numberDouble: String(value) };
|
|
45
|
+
if ("$numberDecimal" in original) return { $numberDecimal: String(value) };
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
function isWrapper(value) {
|
|
49
|
+
if (!isPlainObject(value)) return false;
|
|
50
|
+
const keys = Object.keys(value);
|
|
51
|
+
return keys.length === 1 && keys[0].startsWith("$");
|
|
52
|
+
}
|
|
53
|
+
const joinKey = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
54
|
+
function rewrapValue(value, originalValue, path, hints) {
|
|
55
|
+
const hint = hints?.[path];
|
|
56
|
+
if (hint !== void 0 && !isWrapper(originalValue) && value !== null && typeof value !== "object") return wireValue(hint, value);
|
|
37
57
|
if (typeof value === "string" && INTEGER_TEXT.test(value) && isPlainObject(originalValue) && typeof originalValue.$numberLong === "string") {
|
|
38
58
|
return { $numberLong: value };
|
|
39
59
|
}
|
|
60
|
+
if (typeof value === "number" && isPlainObject(originalValue)) {
|
|
61
|
+
const wrapped = rewrapNumber(value, originalValue);
|
|
62
|
+
if (wrapped !== value) return wrapped;
|
|
63
|
+
}
|
|
64
|
+
if (typeof value === "string" && isPlainObject(originalValue) && typeof originalValue.$string === "string") {
|
|
65
|
+
return { $string: value };
|
|
66
|
+
}
|
|
40
67
|
if (typeof value === "string" && isIsoDateTimeString(value)) {
|
|
41
68
|
return { $date: value };
|
|
42
69
|
}
|
|
@@ -45,20 +72,20 @@ function rewrapValue(value, originalValue) {
|
|
|
45
72
|
}
|
|
46
73
|
if (Array.isArray(value)) {
|
|
47
74
|
const originalArray = Array.isArray(originalValue) ? originalValue : [];
|
|
48
|
-
return value.map((item, index) => rewrapValue(item, originalArray[index]));
|
|
75
|
+
return value.map((item, index) => rewrapValue(item, originalArray[index], `${path}[]`, hints));
|
|
49
76
|
}
|
|
50
77
|
if (isPlainObject(value)) {
|
|
51
78
|
const originalObject = isPlainObject(originalValue) ? originalValue : void 0;
|
|
52
79
|
const nested = {};
|
|
53
|
-
for (const [key, v] of Object.entries(value)) nested[key] = rewrapValue(v, originalObject?.[key]);
|
|
80
|
+
for (const [key, v] of Object.entries(value)) nested[key] = rewrapValue(v, originalObject?.[key], joinKey(path, key), hints);
|
|
54
81
|
return nested;
|
|
55
82
|
}
|
|
56
83
|
return value;
|
|
57
84
|
}
|
|
58
|
-
export function wrapExtendedJson(formData, originalDoc) {
|
|
85
|
+
export function wrapExtendedJson(formData, originalDoc, hints) {
|
|
59
86
|
const result = originalDoc ? { ...originalDoc } : {};
|
|
60
87
|
for (const [key, value] of Object.entries(formData)) {
|
|
61
|
-
result[key] = rewrapValue(value, originalDoc?.[key]);
|
|
88
|
+
result[key] = rewrapValue(value, originalDoc?.[key], key, hints);
|
|
62
89
|
}
|
|
63
90
|
delete result._id;
|
|
64
91
|
return result;
|
|
@@ -12,7 +12,7 @@ export function useMongocampFetchAll() {
|
|
|
12
12
|
async function fetchAllDocuments(collectionName, options = {}) {
|
|
13
13
|
const { filter, sort, projection, ...paging } = options;
|
|
14
14
|
return fetchAllPages(async (page, pageSize) => {
|
|
15
|
-
const response = await documentApi.
|
|
15
|
+
const response = await documentApi.searchDocumentsRaw({ collectionName, searchRequest: { filter, sort, projection }, page, rowsPerPage: pageSize }, requestInit(options.signal));
|
|
16
16
|
return { rows: await readJsonKeepingLongs(response), total: headerNumber(response.raw?.headers, "x-pagination-count-rows") };
|
|
17
17
|
}, paging);
|
|
18
18
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FieldTypeInfo } from '../utils/fieldDetails.js';
|
|
2
|
+
import type { TypeHints } from '../utils/bsonTypes.js';
|
|
3
|
+
import type { FilterFieldType } from '../utils/filterBuilder.js';
|
|
4
|
+
export type FieldTypesStatus = 'idle' | 'loading' | 'ready' | 'failed';
|
|
5
|
+
/**
|
|
6
|
+
* The fields of a collection with the types of their values, from the server's own sample (`GET …/fields/detail`, server
|
|
7
|
+
* 1.8.1) — one request per collection, shared by every component that asks (a `useState` cache), instead of guessing from the
|
|
8
|
+
* rows of the page on screen. Components call `load()` (also after a reload that may have changed the data: `load(true)`) and
|
|
9
|
+
* read `fields` / `typeOf` / `filterFields` / `hints`; while nothing is loaded, or when the request failed, they are empty and
|
|
10
|
+
* the caller keeps its own fallback. Never throws.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useMongocampFieldTypes(collection: string | (() => string)): {
|
|
13
|
+
load: (force?: boolean) => Promise<void>;
|
|
14
|
+
invalidate: (target?: string) => void;
|
|
15
|
+
status: () => FieldTypesStatus;
|
|
16
|
+
fields: () => FieldTypeInfo[];
|
|
17
|
+
selectable: () => FieldTypeInfo[];
|
|
18
|
+
typeOf: (path: string) => FieldTypeInfo | undefined;
|
|
19
|
+
filterFields: () => {
|
|
20
|
+
key: string;
|
|
21
|
+
type: FilterFieldType;
|
|
22
|
+
}[];
|
|
23
|
+
hints: () => TypeHints;
|
|
24
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useMongocampClientApi, useState } from "#imports";
|
|
2
|
+
import { filterTypeOf, toFieldTypeInfos, toTypeHints } from "../utils/fieldDetails.js";
|
|
3
|
+
const REQUEST_TIMEOUT_MS = 15e3;
|
|
4
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
5
|
+
export function useMongocampFieldTypes(collection) {
|
|
6
|
+
const { collectionApi } = useMongocampClientApi();
|
|
7
|
+
const cache = useState("mongocamp-field-types", () => ({}));
|
|
8
|
+
const name = () => typeof collection === "function" ? collection() : collection;
|
|
9
|
+
const entry = () => cache.value[name()] ?? { status: "idle", fields: [] };
|
|
10
|
+
async function load(force = false) {
|
|
11
|
+
const key = name();
|
|
12
|
+
if (!key) return;
|
|
13
|
+
if (!force && (cache.value[key]?.status === "ready" || inFlight.has(key))) return inFlight.get(key);
|
|
14
|
+
const run = (async () => {
|
|
15
|
+
cache.value = { ...cache.value, [key]: { status: "loading", fields: cache.value[key]?.fields ?? [] } };
|
|
16
|
+
try {
|
|
17
|
+
const details = await collectionApi.getFieldDetails({ collectionName: key }, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
18
|
+
cache.value = { ...cache.value, [key]: { status: "ready", fields: toFieldTypeInfos(details) } };
|
|
19
|
+
} catch {
|
|
20
|
+
cache.value = { ...cache.value, [key]: { status: "failed", fields: [] } };
|
|
21
|
+
} finally {
|
|
22
|
+
inFlight.delete(key);
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
inFlight.set(key, run);
|
|
26
|
+
return run;
|
|
27
|
+
}
|
|
28
|
+
function invalidate(target = name()) {
|
|
29
|
+
const { [target]: _dropped, ...rest } = cache.value;
|
|
30
|
+
cache.value = rest;
|
|
31
|
+
}
|
|
32
|
+
const status = () => entry().status;
|
|
33
|
+
const fields = () => entry().fields;
|
|
34
|
+
const selectable = () => entry().fields.filter((f) => !f.element);
|
|
35
|
+
const typeOf = (path) => entry().fields.find((f) => f.path === path);
|
|
36
|
+
function filterFields() {
|
|
37
|
+
return selectable().flatMap((f) => {
|
|
38
|
+
const type = filterTypeOf(f);
|
|
39
|
+
return type ? [{ key: f.path, type }] : [];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const hints = () => toTypeHints(entry().fields);
|
|
43
|
+
return { load, invalidate, status, fields, selectable, typeOf, filterFields, hints };
|
|
44
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BatchInsertResult } from '../utils/batchInsert.js';
|
|
2
|
+
import type { ImportResponse } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
3
|
export type { BatchInsertResult } from '../utils/batchInsert.js';
|
|
3
4
|
export interface ImportRowsOptions {
|
|
4
5
|
batchSize?: number;
|
|
@@ -11,4 +12,7 @@ export interface ImportRowsOptions {
|
|
|
11
12
|
}
|
|
12
13
|
export declare function useMongocampImport(): {
|
|
13
14
|
importRows: (collectionName: string, rows: Record<string, unknown>[], options?: ImportRowsOptions) => Promise<BatchInsertResult>;
|
|
15
|
+
importNdjson: (collectionName: string, file: Blob, options?: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}) => Promise<ImportResponse>;
|
|
14
18
|
};
|
|
@@ -16,10 +16,13 @@ export function useMongocampImport() {
|
|
|
16
16
|
(batch) => {
|
|
17
17
|
const timeout = AbortSignal.timeout(BATCH_TIMEOUT_MS);
|
|
18
18
|
const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
|
|
19
|
-
return documentApi.insertMany({ collectionName, requestBody: batch }, { signal });
|
|
19
|
+
return documentApi.insertMany({ collectionName, requestBody: batch, ordered: false }, { signal });
|
|
20
20
|
},
|
|
21
21
|
{ batchSize: options.batchSize, signal: options.signal, onProgress: options.onProgress, isAtomicFailure: isRejectedBeforeWrite }
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
async function importNdjson(collectionName, file, options = {}) {
|
|
25
|
+
return documentApi.importDocuments({ collectionName, body: file }, options.signal ? { signal: options.signal } : void 0);
|
|
26
|
+
}
|
|
27
|
+
return { importRows, importNdjson };
|
|
25
28
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { IndexCreateResponse, IndexDropResponse, IndexOptionsRequest, MongoIndex } from '@sfxcode/nuxt-mongocamp-server';
|
|
1
|
+
import type { IndexCreateResponse, IndexDropResponse, IndexInfo, IndexOptionsRequest, MongoIndex } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
2
|
export declare function useMongocampIndex(): {
|
|
3
3
|
listIndexes: (collectionName: string) => Promise<MongoIndex[]>;
|
|
4
|
+
listIndexDetails: (collectionName: string) => Promise<IndexInfo[]>;
|
|
4
5
|
createIndex: (collectionName: string, keys: Record<string, number>, options?: IndexOptionsRequest) => Promise<IndexCreateResponse>;
|
|
6
|
+
createOrderedIndex: (collectionName: string, orderedKeys: Array<{
|
|
7
|
+
field: string;
|
|
8
|
+
direction: string;
|
|
9
|
+
}>, options?: IndexOptionsRequest) => Promise<IndexCreateResponse>;
|
|
5
10
|
createIndexForField: (collectionName: string, fieldName: string, sortAscending?: boolean) => Promise<IndexCreateResponse>;
|
|
6
11
|
createUniqueIndex: (collectionName: string, fieldName: string, sortAscending?: boolean) => Promise<IndexCreateResponse>;
|
|
7
12
|
createTextIndex: (collectionName: string, fieldName: string) => Promise<IndexCreateResponse>;
|
|
@@ -8,9 +8,15 @@ export function useMongocampIndex() {
|
|
|
8
8
|
async function listIndexes(collectionName) {
|
|
9
9
|
return indexApi.listIndices({ collectionName });
|
|
10
10
|
}
|
|
11
|
+
async function listIndexDetails(collectionName) {
|
|
12
|
+
return indexApi.indexDetails({ collectionName }, withTimeout());
|
|
13
|
+
}
|
|
11
14
|
async function createIndex(collectionName, keys, options) {
|
|
12
15
|
return indexApi.createIndex({ collectionName, indexCreateRequest: { keys, indexOptionsRequest: options } });
|
|
13
16
|
}
|
|
17
|
+
async function createOrderedIndex(collectionName, orderedKeys, options) {
|
|
18
|
+
return indexApi.createIndex({ collectionName, indexCreateRequest: { orderedKeys, indexOptionsRequest: options } });
|
|
19
|
+
}
|
|
14
20
|
async function createIndexForField(collectionName, fieldName, sortAscending = true) {
|
|
15
21
|
return indexApi.createIndexForField({ collectionName, fieldName, sortAscending }, withTimeout());
|
|
16
22
|
}
|
|
@@ -26,5 +32,5 @@ export function useMongocampIndex() {
|
|
|
26
32
|
async function deleteIndex(collectionName, indexName) {
|
|
27
33
|
return indexApi.deleteIndex({ collectionName, indexName });
|
|
28
34
|
}
|
|
29
|
-
return { listIndexes, createIndex, createIndexForField, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex };
|
|
35
|
+
return { listIndexes, listIndexDetails, createIndex, createOrderedIndex, createIndexForField, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex };
|
|
30
36
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What the signed-in user may do with a collection
|
|
3
|
-
*
|
|
2
|
+
* What the signed-in user may do with a collection — so a component can hide an action the server would refuse instead of
|
|
3
|
+
* letting the click fail. **UI-level only**: the server stays the authority.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* `load()` asks the server (`GET /auth/permissions`, server 1.7.0), which resolves roles, grants and the signed-in
|
|
6
|
+
* user's rights itself — and also works in server proxy mode, where there is no profile. `canRead` / `canWrite` /
|
|
7
|
+
* `canAdminister` stay synchronous: they answer from what was loaded, and until then from the grants of the session profile
|
|
8
|
+
* (admin, proxy mode, a profile without a grant list and GridFS bucket members answer "yes" — fail-open). A failing
|
|
9
|
+
* `load()` changes nothing. Administrators are never asked: everything is allowed.
|
|
8
10
|
*/
|
|
9
11
|
export declare function useMongocampPermissions(): {
|
|
10
12
|
canRead: (collectionName: string) => boolean;
|
|
11
13
|
canWrite: (collectionName: string) => boolean;
|
|
12
14
|
canAdminister: (collectionName: string) => boolean;
|
|
13
15
|
readableCollections: (collectionNames: string[]) => string[];
|
|
16
|
+
load: (collectionName?: string) => Promise<void>;
|
|
14
17
|
};
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#app";
|
|
2
|
-
import { useMongocampStorage } from "#imports";
|
|
2
|
+
import { useMongocampClientApi, useMongocampStorage, useState } from "#imports";
|
|
3
3
|
import { permissionFromGrants } from "../utils/grantMatching.js";
|
|
4
|
+
const REQUEST_TIMEOUT_MS = 15e3;
|
|
4
5
|
export function useMongocampPermissions() {
|
|
5
6
|
const config = useRuntimeConfig();
|
|
6
7
|
const state = useMongocampStorage();
|
|
8
|
+
const cache = useState("mongocamp-permissions", () => ({ user: "", byName: {} }));
|
|
7
9
|
const isProxyMode = config.public.nuxtUiMongocampOptions?.useServerProxy ?? false;
|
|
10
|
+
const currentUser = () => state.value?.profile?.user ?? "";
|
|
11
|
+
const key = (name) => name.trim().toLowerCase();
|
|
12
|
+
function fromServer(collectionName) {
|
|
13
|
+
if (cache.value.user !== currentUser()) return void 0;
|
|
14
|
+
return cache.value.byName[key(collectionName)];
|
|
15
|
+
}
|
|
8
16
|
function allowed(collectionName, permission) {
|
|
17
|
+
const answered = fromServer(collectionName);
|
|
18
|
+
if (answered) return answered[permission];
|
|
9
19
|
if (isProxyMode) return true;
|
|
10
20
|
const profile = state.value?.profile;
|
|
11
21
|
if (!profile || profile.isAdmin) return true;
|
|
@@ -17,5 +27,17 @@ export function useMongocampPermissions() {
|
|
|
17
27
|
function readableCollections(collectionNames) {
|
|
18
28
|
return collectionNames.filter(canRead);
|
|
19
29
|
}
|
|
20
|
-
|
|
30
|
+
async function load(collectionName) {
|
|
31
|
+
if (state.value?.profile?.isAdmin) return;
|
|
32
|
+
try {
|
|
33
|
+
const { authApi } = useMongocampClientApi();
|
|
34
|
+
const rows = await authApi.userPermissions(collectionName ? { collection: collectionName } : {}, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
35
|
+
const user = currentUser();
|
|
36
|
+
const byName = cache.value.user === user ? { ...cache.value.byName } : {};
|
|
37
|
+
for (const row of rows) byName[key(row.name)] = { read: row.read, write: row.write, administrate: row.administrate };
|
|
38
|
+
cache.value = { user, byName };
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { canRead, canWrite, canAdminister, readableCollections, load };
|
|
21
43
|
}
|
|
@@ -10,7 +10,7 @@ export interface MongocampQueryHelper {
|
|
|
10
10
|
* Matches documents where the field has a value. Without `type` this ORs a text wildcard with a
|
|
11
11
|
* full-range number and a full-range date clause, so it works for any of those types.
|
|
12
12
|
*
|
|
13
|
-
* MongoCamp (
|
|
13
|
+
* MongoCamp (last verified on 1.6.3, not re-checked on 1.8) does not understand `_exists_:field` (it matches nothing), and `field:*` only matches text,
|
|
14
14
|
* which is why this is not just a wildcard.
|
|
15
15
|
*/
|
|
16
16
|
exists: (fieldName: string, type?: ExistsFieldType) => string;
|
|
@@ -36,7 +36,7 @@ export interface MongocampQueryHelper {
|
|
|
36
36
|
/**
|
|
37
37
|
* `field:[from TO to]` — inclusive range.
|
|
38
38
|
*
|
|
39
|
-
* Pass `null` (or `'*'`) for an open end. MongoCamp (
|
|
39
|
+
* Pass `null` (or `'*'`) for an open end. MongoCamp (last verified on 1.6.3, not re-checked on 1.8) rejects `[x TO *]`, so the open end is replaced by
|
|
40
40
|
* the far bound of the other bound's type: the 64-bit integer limits for numbers, year 0001 / 9999 for
|
|
41
41
|
* dates. Both ends open means "has a value" and returns `exists(field)`. An open end next to a *text*
|
|
42
42
|
* bound can't be expressed and still becomes `*`, which the server rejects.
|
|
@@ -139,7 +139,7 @@ export interface MongocampQueryHelper {
|
|
|
139
139
|
notOnDay: (fieldName: string, day: string) => string;
|
|
140
140
|
/**
|
|
141
141
|
* The negation of any expression these helpers produced, written so the server evaluates it correctly.
|
|
142
|
-
* MongoCamp (
|
|
142
|
+
* MongoCamp (last verified on 1.6.3, not re-checked on 1.8) evaluates `-(A AND B)` as `-A AND -B`, so a negated `AND` group is rewritten with
|
|
143
143
|
* De Morgan's law as `((-A) OR (-B))` — each negated clause in its own parentheses, which the server needs — and a
|
|
144
144
|
* negated `OR` group as `((-A) AND (-B))`, recursively. A single clause becomes `-clause` (and `-clause` becomes
|
|
145
145
|
* `clause`). Returns `''` for an empty expression. Throws `UnsupportedExpressionError` for text it cannot read
|
|
@@ -5,15 +5,8 @@ export type { CollectionStat } from '../utils/serverOverview.js';
|
|
|
5
5
|
export interface ServerOverviewOptions {
|
|
6
6
|
/** Read at most this many collections (default 200); the rest is counted in `skipped`. */
|
|
7
7
|
maxCollections?: number;
|
|
8
|
-
/** Collection requests in flight at once (default 6). */
|
|
9
|
-
concurrency?: number;
|
|
10
8
|
/** Aborting rejects with an `AbortError`. */
|
|
11
9
|
signal?: AbortSignal;
|
|
12
|
-
/** After every collection that was read. */
|
|
13
|
-
onProgress?: (progress: {
|
|
14
|
-
done: number;
|
|
15
|
-
total: number;
|
|
16
|
-
}) => void;
|
|
17
10
|
}
|
|
18
11
|
export interface ServerOverview {
|
|
19
12
|
/** `null` when the databases could not be read (see `errors.databases`). */
|
|
@@ -24,7 +17,7 @@ export interface ServerOverview {
|
|
|
24
17
|
collectionCount: number;
|
|
25
18
|
/** Collections not read because of `maxCollections`. */
|
|
26
19
|
skipped: number;
|
|
27
|
-
/** Collections
|
|
20
|
+
/** Collections the server listed but could not read the numbers of (`available: false`). */
|
|
28
21
|
failed: string[];
|
|
29
22
|
cluster: ServerCluster | null;
|
|
30
23
|
jobs: JobInformation[] | null;
|
|
@@ -33,9 +26,9 @@ export interface ServerOverview {
|
|
|
33
26
|
}
|
|
34
27
|
/**
|
|
35
28
|
* What an admin wants to see first: the databases, the size of every collection, the cluster and the scheduled jobs. The
|
|
36
|
-
* parts are independent — one that fails is reported in `errors` and leaves the others intact.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
29
|
+
* parts are independent — one that fails is reported in `errors` and leaves the others intact. The numbers of **all**
|
|
30
|
+
* collections come in one request (`GET /mongodb/collections/info`, server 1.7.0); `maxCollections` only limits how many of
|
|
31
|
+
* them are kept. Aborting rejects with an `AbortError`.
|
|
39
32
|
*/
|
|
40
33
|
export declare function useMongocampServerOverview(): {
|
|
41
34
|
loadOverview: (options?: ServerOverviewOptions) => Promise<ServerOverview>;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
|
-
import { mapLimit } from "../utils/limitedMap.js";
|
|
3
2
|
import { toCollectionStat } from "../utils/serverOverview.js";
|
|
4
3
|
import { useMongocampJobs } from "./useMongocampJobs.js";
|
|
5
4
|
import { useMongocampSystem } from "./useMongocampSystem.js";
|
|
6
5
|
const REQUEST_TIMEOUT_MS = 15e3;
|
|
7
6
|
const DEFAULT_MAX_COLLECTIONS = 200;
|
|
8
|
-
const DEFAULT_CONCURRENCY = 6;
|
|
9
7
|
function abortError() {
|
|
10
8
|
return new DOMException("The operation was aborted.", "AbortError");
|
|
11
9
|
}
|
|
@@ -18,7 +16,9 @@ export function useMongocampServerOverview() {
|
|
|
18
16
|
if (signal?.aborted) throw abortError();
|
|
19
17
|
const maxCollections = Math.max(0, Math.floor(options.maxCollections ?? DEFAULT_MAX_COLLECTIONS));
|
|
20
18
|
const errors = {};
|
|
21
|
-
const
|
|
19
|
+
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
|
|
20
|
+
const init = { signal: signal ? AbortSignal.any([signal, timeout]) : timeout };
|
|
21
|
+
const [databases, summaries, cluster, jobs] = await Promise.allSettled([getDatabaseInfos(), collectionApi.listCollectionInformation({}, init), getCluster(), listJobs()]);
|
|
22
22
|
if (signal?.aborted) throw abortError();
|
|
23
23
|
const result = {
|
|
24
24
|
databases: databases.status === "fulfilled" ? databases.value : null,
|
|
@@ -33,28 +33,18 @@ export function useMongocampServerOverview() {
|
|
|
33
33
|
if (databases.status === "rejected") errors.databases = databases.reason;
|
|
34
34
|
if (cluster.status === "rejected") errors.cluster = cluster.reason;
|
|
35
35
|
if (jobs.status === "rejected") errors.jobs = jobs.reason;
|
|
36
|
-
if (
|
|
37
|
-
errors.collections =
|
|
36
|
+
if (summaries.status === "rejected") {
|
|
37
|
+
errors.collections = summaries.reason;
|
|
38
38
|
return result;
|
|
39
39
|
}
|
|
40
|
-
const own =
|
|
40
|
+
const own = summaries.value.filter((summary) => !summary.name.startsWith("mc_"));
|
|
41
41
|
result.collectionCount = own.length;
|
|
42
|
-
const
|
|
43
|
-
result.skipped = own.length -
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return toCollectionStat(name, await collectionApi.getCollectionInformation({ collectionName: name }, init));
|
|
49
|
-
}, { signal, onProgress: (done, total) => options.onProgress?.({ done, total }) });
|
|
50
|
-
if (signal?.aborted) throw abortError();
|
|
51
|
-
settled.forEach((outcome, index) => {
|
|
52
|
-
if (outcome?.ok) result.collections.push(outcome.value);
|
|
53
|
-
else {
|
|
54
|
-
result.failed.push(toRead[index]);
|
|
55
|
-
if (outcome && errors.collections === void 0) errors.collections = outcome.error;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
42
|
+
const kept = own.slice(0, maxCollections);
|
|
43
|
+
result.skipped = own.length - kept.length;
|
|
44
|
+
for (const summary of kept) {
|
|
45
|
+
if (summary.available === false) result.failed.push(summary.name);
|
|
46
|
+
else result.collections.push(toCollectionStat(summary.name, summary));
|
|
47
|
+
}
|
|
58
48
|
return result;
|
|
59
49
|
}
|
|
60
50
|
return { loadOverview };
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import type { ClusterMemberInformation, DatabaseInfo } from '@sfxcode/nuxt-mongocamp-server';
|
|
1
|
+
import type { Capabilities, ClusterMemberInformation, DatabaseInfo, SystemStats } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
2
|
import type { ConfigRow } from '../utils/configRows.js';
|
|
3
3
|
export interface ServerCluster {
|
|
4
4
|
coordinator: ClusterMemberInformation;
|
|
5
5
|
members: ClusterMemberInformation[];
|
|
6
6
|
}
|
|
7
|
+
export interface ServerInfo {
|
|
8
|
+
/** Version of the MongoDB server the MongoCamp server is connected to, e.g. `9.0.4`. */
|
|
9
|
+
mongoDbVersion: string;
|
|
10
|
+
/** The same version as numbers (`[9, 0, 4, 0]`), empty if the server sent none. */
|
|
11
|
+
mongoDbVersionArray: number[];
|
|
12
|
+
}
|
|
7
13
|
export interface ServerPlugins {
|
|
8
14
|
routesPlugins: string[];
|
|
9
15
|
filePlugins: string[];
|
|
@@ -19,6 +25,9 @@ export interface ServerPlugins {
|
|
|
19
25
|
*/
|
|
20
26
|
export declare function useMongocampSystem(): {
|
|
21
27
|
getCluster: () => Promise<ServerCluster>;
|
|
28
|
+
getServerInfo: () => Promise<ServerInfo>;
|
|
29
|
+
getStats: () => Promise<SystemStats>;
|
|
30
|
+
getCapabilities: () => Promise<Capabilities>;
|
|
22
31
|
listDatabases: () => Promise<string[]>;
|
|
23
32
|
getDatabaseInfos: () => Promise<DatabaseInfo[]>;
|
|
24
33
|
getDatabaseInfo: (databaseName: string) => Promise<DatabaseInfo>;
|
|
@@ -38,5 +38,15 @@ export function useMongocampSystem() {
|
|
|
38
38
|
const cluster = await systemApi.viewCluster(withTimeout());
|
|
39
39
|
return { coordinator: cluster.coordinator, members: cluster.members?.length ? cluster.members : [cluster.coordinator] };
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
async function getServerInfo() {
|
|
42
|
+
const info = await systemApi.systemInfo(withTimeout());
|
|
43
|
+
return { mongoDbVersion: info.mongoDbVersion, mongoDbVersionArray: info.mongoDbVersionArray ?? [] };
|
|
44
|
+
}
|
|
45
|
+
async function getStats() {
|
|
46
|
+
return systemApi.systemStats(withTimeout());
|
|
47
|
+
}
|
|
48
|
+
async function getCapabilities() {
|
|
49
|
+
return systemApi.systemCapabilities(withTimeout());
|
|
50
|
+
}
|
|
51
|
+
return { getCluster, getServerInfo, getStats, getCapabilities, listDatabases, getDatabaseInfos, getDatabaseInfo, listCollectionsByDatabase, getSettings, listConfigurations, getConfig };
|
|
42
52
|
}
|