@sfxcode/nuxt-ui-mongocamp 1.3.5 → 1.4.0
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/dist/module.d.mts +8 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +6 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue +302 -3
- package/dist/runtime/components/MongocampAggregationChart.d.vue.ts +6 -0
- package/dist/runtime/components/MongocampAggregationChart.vue +93 -0
- package/dist/runtime/components/MongocampAggregationChart.vue.d.ts +6 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +9 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.vue +148 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +9 -0
- package/dist/runtime/components/MongocampBucketFiles.vue +169 -48
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +19 -0
- package/dist/runtime/components/MongocampBulkDelete.vue +118 -23
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +19 -0
- package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +6 -0
- package/dist/runtime/components/MongocampBulkEdit.vue +23 -2
- package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +6 -0
- package/dist/runtime/components/MongocampChart.d.vue.ts +29 -0
- package/dist/runtime/components/MongocampChart.vue +129 -0
- package/dist/runtime/components/MongocampChart.vue.d.ts +29 -0
- package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +15 -0
- package/dist/runtime/components/MongocampCollectionCharts.vue +199 -0
- package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +15 -0
- package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +23 -0
- package/dist/runtime/components/MongocampCollectionCopy.vue +445 -0
- package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +23 -0
- package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -0
- package/dist/runtime/components/MongocampCollectionData.vue +342 -137
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -0
- package/dist/runtime/components/MongocampCollectionInfos.vue +106 -238
- package/dist/runtime/components/MongocampCollections.vue +62 -0
- package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +40 -0
- package/dist/runtime/components/MongocampCommandPalette.vue +135 -0
- package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +40 -0
- package/dist/runtime/components/MongocampConfirmByName.vue +2 -2
- package/dist/runtime/components/MongocampDashboard.d.vue.ts +3 -1
- package/dist/runtime/components/MongocampDashboard.vue +21 -2
- package/dist/runtime/components/MongocampDashboard.vue.d.ts +3 -1
- package/dist/runtime/components/MongocampDatabases.vue +22 -0
- package/dist/runtime/components/MongocampDocumentCompare.d.vue.ts +20 -0
- package/dist/runtime/components/MongocampDocumentCompare.vue +146 -0
- package/dist/runtime/components/MongocampDocumentCompare.vue.d.ts +20 -0
- package/dist/runtime/components/MongocampDocumentView.d.vue.ts +22 -0
- package/dist/runtime/components/MongocampDocumentView.vue +202 -0
- package/dist/runtime/components/MongocampDocumentView.vue.d.ts +22 -0
- package/dist/runtime/components/MongocampErrorAlert.vue +12 -4
- package/dist/runtime/components/MongocampExportAll.d.vue.ts +18 -0
- package/dist/runtime/components/MongocampExportAll.vue +204 -0
- package/dist/runtime/components/MongocampExportAll.vue.d.ts +18 -0
- package/dist/runtime/components/MongocampFilePreview.d.vue.ts +16 -0
- package/dist/runtime/components/MongocampFilePreview.vue +162 -0
- package/dist/runtime/components/MongocampFilePreview.vue.d.ts +16 -0
- package/dist/runtime/components/MongocampFilterBuilder.vue +11 -0
- package/dist/runtime/components/MongocampImport.vue +2 -10
- package/dist/runtime/components/MongocampIndexes.d.vue.ts +18 -0
- package/dist/runtime/components/MongocampIndexes.vue +455 -0
- package/dist/runtime/components/MongocampIndexes.vue.d.ts +18 -0
- package/dist/runtime/components/MongocampJobs.d.vue.ts +6 -1
- package/dist/runtime/components/MongocampJobs.vue +23 -3
- package/dist/runtime/components/MongocampJobs.vue.d.ts +6 -1
- package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +12 -0
- package/dist/runtime/components/MongocampPermissionMatrix.vue +301 -0
- package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +12 -0
- package/dist/runtime/components/MongocampQueryBar.d.vue.ts +26 -0
- package/dist/runtime/components/MongocampQueryBar.vue +398 -0
- package/dist/runtime/components/MongocampQueryBar.vue.d.ts +26 -0
- package/dist/runtime/components/MongocampRoleGrants.vue +2 -2
- package/dist/runtime/components/MongocampRoles.vue +3 -3
- package/dist/runtime/components/MongocampServerOverview.d.vue.ts +20 -0
- package/dist/runtime/components/MongocampServerOverview.vue +443 -0
- package/dist/runtime/components/MongocampServerOverview.vue.d.ts +20 -0
- package/dist/runtime/components/MongocampSettings.d.vue.ts +25 -1
- package/dist/runtime/components/MongocampSettings.vue +70 -9
- package/dist/runtime/components/MongocampSettings.vue.d.ts +25 -1
- package/dist/runtime/components/MongocampUsers.vue +3 -3
- package/dist/runtime/composables/useMongocampAdmin.d.ts +2 -1
- package/dist/runtime/composables/useMongocampAdmin.js +6 -1
- package/dist/runtime/composables/useMongocampAggregation.d.ts +12 -1
- package/dist/runtime/composables/useMongocampAggregation.js +33 -25
- package/dist/runtime/composables/useMongocampAutoRefresh.d.ts +26 -0
- package/dist/runtime/composables/useMongocampAutoRefresh.js +78 -0
- package/dist/runtime/composables/useMongocampBucket.d.ts +13 -1
- package/dist/runtime/composables/useMongocampBucket.js +34 -0
- package/dist/runtime/composables/useMongocampClientApi.js +2 -1
- package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +85 -0
- package/dist/runtime/composables/useMongocampCollectionCopy.js +105 -0
- package/dist/runtime/composables/useMongocampCollectionStats.d.ts +10 -0
- package/dist/runtime/composables/useMongocampCollectionStats.js +17 -0
- package/dist/runtime/composables/useMongocampError.d.ts +2 -1
- package/dist/runtime/composables/useMongocampError.js +16 -1
- package/dist/runtime/composables/useMongocampExportAll.d.ts +47 -0
- package/dist/runtime/composables/useMongocampExportAll.js +27 -0
- package/dist/runtime/composables/useMongocampExtendedJson.d.ts +5 -1
- package/dist/runtime/composables/useMongocampExtendedJson.js +12 -6
- package/dist/runtime/composables/useMongocampFetchAll.d.ts +25 -0
- package/dist/runtime/composables/useMongocampFetchAll.js +27 -0
- package/dist/runtime/composables/useMongocampPermissions.d.ts +14 -0
- package/dist/runtime/composables/useMongocampPermissions.js +21 -0
- package/dist/runtime/composables/useMongocampPersistedState.d.ts +15 -0
- package/dist/runtime/composables/useMongocampPersistedState.js +21 -0
- package/dist/runtime/composables/useMongocampProxyApi.js +2 -1
- package/dist/runtime/composables/useMongocampQuery.d.ts +48 -0
- package/dist/runtime/composables/useMongocampQuery.js +72 -1
- package/dist/runtime/composables/useMongocampSavedPipelines.d.ts +25 -0
- package/dist/runtime/composables/useMongocampSavedPipelines.js +23 -0
- package/dist/runtime/composables/useMongocampSavedQueries.d.ts +37 -0
- package/dist/runtime/composables/useMongocampSavedQueries.js +50 -0
- package/dist/runtime/composables/useMongocampServerOverview.d.ts +42 -0
- package/dist/runtime/composables/useMongocampServerOverview.js +61 -0
- package/dist/runtime/composables/useMongocampSession.d.ts +2 -0
- package/dist/runtime/composables/useMongocampSession.js +16 -2
- package/dist/runtime/composables/useMongocampSystem.d.ts +7 -2
- package/dist/runtime/composables/useMongocampSystem.js +6 -2
- package/dist/runtime/locales/de.json +495 -9
- package/dist/runtime/locales/en.json +495 -9
- package/dist/runtime/plugin.js +6 -3
- package/dist/runtime/utils/aggregationPipeline.d.ts +5 -4
- package/dist/runtime/utils/aggregationPipeline.js +23 -9
- package/dist/runtime/utils/aggregationPreview.d.ts +13 -0
- package/dist/runtime/utils/aggregationPreview.js +10 -0
- package/dist/runtime/utils/aggregationResult.d.ts +5 -0
- package/dist/runtime/utils/aggregationResult.js +4 -0
- package/dist/runtime/utils/aggregationTemplates.d.ts +34 -0
- package/dist/runtime/utils/aggregationTemplates.js +47 -0
- package/dist/runtime/utils/analyzeSamples.d.ts +1 -0
- package/dist/runtime/utils/analyzeSamples.js +1 -1
- package/dist/runtime/utils/autoRefresh.d.ts +14 -0
- package/dist/runtime/utils/autoRefresh.js +15 -0
- package/dist/runtime/utils/bigIntJson.d.ts +15 -0
- package/dist/runtime/utils/bigIntJson.js +55 -0
- package/dist/runtime/utils/bulkDelete.d.ts +9 -1
- package/dist/runtime/utils/bulkDelete.js +15 -3
- package/dist/runtime/utils/bulkEdit.d.ts +6 -0
- package/dist/runtime/utils/bulkEdit.js +7 -0
- package/dist/runtime/utils/chartData.d.ts +11 -0
- package/dist/runtime/utils/chartData.js +9 -0
- package/dist/runtime/utils/collectionChart.d.ts +36 -0
- package/dist/runtime/utils/collectionChart.js +73 -0
- package/dist/runtime/utils/collectionCopy.d.ts +26 -0
- package/dist/runtime/utils/collectionCopy.js +38 -0
- package/dist/runtime/utils/collectionStats.d.ts +31 -0
- package/dist/runtime/utils/collectionStats.js +42 -0
- package/dist/runtime/utils/commandPalette.d.ts +48 -0
- package/dist/runtime/utils/commandPalette.js +39 -0
- package/dist/runtime/utils/documentCompare.d.ts +31 -0
- package/dist/runtime/utils/documentCompare.js +70 -0
- package/dist/runtime/utils/documentDiff.d.ts +19 -0
- package/dist/runtime/utils/documentDiff.js +71 -0
- package/dist/runtime/utils/documentPaths.d.ts +44 -0
- package/dist/runtime/utils/documentPaths.js +144 -0
- package/dist/runtime/utils/documentTree.d.ts +40 -0
- package/dist/runtime/utils/documentTree.js +94 -0
- package/dist/runtime/utils/exportDocuments.d.ts +35 -0
- package/dist/runtime/utils/exportDocuments.js +54 -0
- package/dist/runtime/utils/exportRows.js +1 -1
- package/dist/runtime/utils/filePreview.d.ts +27 -0
- package/dist/runtime/utils/filePreview.js +50 -0
- package/dist/runtime/utils/filterBuilder.d.ts +6 -1
- package/dist/runtime/utils/filterBuilder.js +6 -5
- package/dist/runtime/utils/formatBytes.d.ts +2 -0
- package/dist/runtime/utils/formatBytes.js +11 -0
- package/dist/runtime/utils/grantMatching.d.ts +8 -0
- package/dist/runtime/utils/grantMatching.js +15 -0
- package/dist/runtime/utils/importRows.js +12 -2
- package/dist/runtime/utils/indexCopy.d.ts +26 -0
- package/dist/runtime/utils/indexCopy.js +22 -0
- package/dist/runtime/utils/indexForm.d.ts +69 -0
- package/dist/runtime/utils/indexForm.js +63 -0
- package/dist/runtime/utils/limitedMap.d.ts +17 -0
- package/dist/runtime/utils/limitedMap.js +19 -0
- package/dist/runtime/utils/luceneExpression.d.ts +15 -0
- package/dist/runtime/utils/luceneExpression.js +74 -0
- package/dist/runtime/utils/pagedFetch.d.ts +46 -0
- package/dist/runtime/utils/pagedFetch.js +58 -0
- package/dist/runtime/utils/paginationHeaders.d.ts +4 -0
- package/dist/runtime/utils/paginationHeaders.js +4 -0
- package/dist/runtime/utils/permissionDenied.d.ts +10 -0
- package/dist/runtime/utils/permissionDenied.js +23 -0
- package/dist/runtime/utils/permissionMatrix.d.ts +55 -0
- package/dist/runtime/utils/permissionMatrix.js +85 -0
- package/dist/runtime/utils/persistedState.d.ts +25 -0
- package/dist/runtime/utils/persistedState.js +47 -0
- package/dist/runtime/utils/queryState.d.ts +45 -0
- package/dist/runtime/utils/queryState.js +75 -0
- package/dist/runtime/utils/requestLimits.d.ts +2 -0
- package/dist/runtime/utils/requestLimits.js +4 -0
- package/dist/runtime/utils/resultChart.d.ts +32 -0
- package/dist/runtime/utils/resultChart.js +59 -0
- package/dist/runtime/utils/savedPipelines.d.ts +22 -0
- package/dist/runtime/utils/savedPipelines.js +46 -0
- package/dist/runtime/utils/savedQueries.d.ts +60 -0
- package/dist/runtime/utils/savedQueries.js +143 -0
- package/dist/runtime/utils/schemaAnalysis.d.ts +16 -0
- package/dist/runtime/utils/schemaAnalysis.js +57 -0
- package/dist/runtime/utils/serverError.d.ts +19 -0
- package/dist/runtime/utils/serverError.js +19 -0
- package/dist/runtime/utils/serverOverview.d.ts +47 -0
- package/dist/runtime/utils/serverOverview.js +40 -0
- package/dist/runtime/utils/sessionGuard.d.ts +3 -0
- package/dist/runtime/utils/sessionGuard.js +18 -1
- package/package.json +12 -11
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const MAX_CHART_ROWS = 100;
|
|
2
|
+
export const MAX_SERIES = 6;
|
|
3
|
+
export const LABEL_KEY = "__label";
|
|
4
|
+
const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
5
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
export function labelText(value) {
|
|
7
|
+
if (value === null || value === void 0) return "(none)";
|
|
8
|
+
if (isRecord(value)) {
|
|
9
|
+
const keys = Object.keys(value);
|
|
10
|
+
if (keys.length === 2 && "min" in value && "max" in value) return `${labelText(value.min)}\u2013${labelText(value.max)}`;
|
|
11
|
+
return keys.map((key) => `${key}=${isRecord(value[key]) ? JSON.stringify(value[key]) : labelText(value[key])}`).join(", ");
|
|
12
|
+
}
|
|
13
|
+
return Array.isArray(value) ? JSON.stringify(value) : String(value);
|
|
14
|
+
}
|
|
15
|
+
export function valueColumns(rows, columns, labelKey) {
|
|
16
|
+
const sample = rows.slice(0, MAX_CHART_ROWS);
|
|
17
|
+
return columns.filter((key) => key !== labelKey && sample.some((row) => isNumber(row[key])));
|
|
18
|
+
}
|
|
19
|
+
export function defaultLabelKey(rows, columns) {
|
|
20
|
+
if (columns.includes("_id")) return "_id";
|
|
21
|
+
const sample = rows.slice(0, MAX_CHART_ROWS);
|
|
22
|
+
return columns.find((key) => sample.some((row) => row[key] !== void 0 && !isNumber(row[key]))) ?? columns[0];
|
|
23
|
+
}
|
|
24
|
+
const DATE_LIKE = /^\d{4}-\d{2}(?:-\d{2})?/;
|
|
25
|
+
export function defaultKind(labels, series, allNonNegative) {
|
|
26
|
+
if (series === 1 && allNonNegative && labels.length >= 2 && labels.length <= 6) return "donut";
|
|
27
|
+
if (labels.length >= 3 && labels.every((label) => DATE_LIKE.test(label))) return "area";
|
|
28
|
+
return "bar";
|
|
29
|
+
}
|
|
30
|
+
export function buildResultChart(rows, columns, choice = {}) {
|
|
31
|
+
const labelKey = choice.labelKey && columns.includes(choice.labelKey) ? choice.labelKey : defaultLabelKey(rows, columns);
|
|
32
|
+
if (!labelKey || rows.length === 0) return null;
|
|
33
|
+
const available = valueColumns(rows, columns, labelKey);
|
|
34
|
+
const chosen = (choice.valueKeys ?? []).filter((key) => available.includes(key));
|
|
35
|
+
const valueKeys = (chosen.length ? chosen : available).slice(0, MAX_SERIES);
|
|
36
|
+
if (valueKeys.length === 0) return null;
|
|
37
|
+
const data = [];
|
|
38
|
+
let skipped = 0;
|
|
39
|
+
for (const row of rows.slice(0, MAX_CHART_ROWS)) {
|
|
40
|
+
if (!valueKeys.some((key) => isNumber(row[key]))) {
|
|
41
|
+
skipped++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const point = { [LABEL_KEY]: labelText(row[labelKey]) };
|
|
45
|
+
for (const key of valueKeys) point[key] = isNumber(row[key]) ? row[key] : 0;
|
|
46
|
+
data.push(point);
|
|
47
|
+
}
|
|
48
|
+
if (data.length === 0) return null;
|
|
49
|
+
const labels = data.map((point) => point[LABEL_KEY]);
|
|
50
|
+
const nonNegative = data.every((point) => valueKeys.every((key) => point[key] >= 0));
|
|
51
|
+
return {
|
|
52
|
+
kind: choice.kind ?? defaultKind(labels, valueKeys.length, nonNegative),
|
|
53
|
+
labelKey,
|
|
54
|
+
valueKeys,
|
|
55
|
+
data,
|
|
56
|
+
cut: rows.length > MAX_CHART_ROWS,
|
|
57
|
+
skipped
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RequestStage } from './aggregationPipeline.js';
|
|
2
|
+
import { MAX_NAME_LENGTH, MAX_SAVED } from './savedQueries.js';
|
|
3
|
+
export interface SavedPipelineEntry {
|
|
4
|
+
name: string;
|
|
5
|
+
pipeline: RequestStage[];
|
|
6
|
+
}
|
|
7
|
+
export declare const MAX_PIPELINE_STAGES = 50;
|
|
8
|
+
/** Serialised size of one saved pipeline. */
|
|
9
|
+
export declare const MAX_PIPELINE_BYTES = 20000;
|
|
10
|
+
export { MAX_NAME_LENGTH, MAX_SAVED };
|
|
11
|
+
/** A clean copy of a request pipeline, or `undefined` when it is empty, malformed, too large or uses a denied operator. */
|
|
12
|
+
export declare function sanitizePipeline(value: unknown): RequestStage[] | undefined;
|
|
13
|
+
export type SavePipelineFailure = 'invalid-name' | 'invalid-pipeline' | 'limit';
|
|
14
|
+
/** Adds or replaces (name compared ignoring case) an entry; a full list still allows replacing. */
|
|
15
|
+
export declare function upsertPipeline(list: SavedPipelineEntry[], name: unknown, pipeline: unknown, max?: number): {
|
|
16
|
+
ok: true;
|
|
17
|
+
list: SavedPipelineEntry[];
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
reason: SavePipelineFailure;
|
|
21
|
+
};
|
|
22
|
+
export declare function sanitizePipelineList(value: unknown, max?: number): SavedPipelineEntry[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { findForbidden } from "./aggregationPipeline.js";
|
|
2
|
+
import { MAX_NAME_LENGTH, MAX_SAVED, sanitizeName } from "./savedQueries.js";
|
|
3
|
+
export const MAX_PIPELINE_STAGES = 50;
|
|
4
|
+
export const MAX_PIPELINE_BYTES = 2e4;
|
|
5
|
+
export { MAX_NAME_LENGTH, MAX_SAVED };
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
export function sanitizePipeline(value) {
|
|
10
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > MAX_PIPELINE_STAGES) return void 0;
|
|
11
|
+
const pipeline = [];
|
|
12
|
+
for (const item of value) {
|
|
13
|
+
if (!isRecord(item) || typeof item.stage !== "string" || !item.stage.startsWith("$") || !("value" in item)) return void 0;
|
|
14
|
+
pipeline.push({ stage: item.stage, value: item.value });
|
|
15
|
+
}
|
|
16
|
+
let size;
|
|
17
|
+
try {
|
|
18
|
+
size = JSON.stringify(pipeline).length;
|
|
19
|
+
} catch {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
if (size > MAX_PIPELINE_BYTES) return void 0;
|
|
23
|
+
return findForbidden(pipeline).length > 0 ? void 0 : pipeline;
|
|
24
|
+
}
|
|
25
|
+
export function upsertPipeline(list, name, pipeline, max = MAX_SAVED) {
|
|
26
|
+
const cleanName = sanitizeName(name);
|
|
27
|
+
if (!cleanName) return { ok: false, reason: "invalid-name" };
|
|
28
|
+
const clean = sanitizePipeline(pipeline);
|
|
29
|
+
if (!clean) return { ok: false, reason: "invalid-pipeline" };
|
|
30
|
+
const index = list.findIndex((e) => e.name.toLowerCase() === cleanName.toLowerCase());
|
|
31
|
+
if (index === -1) {
|
|
32
|
+
if (list.length >= max) return { ok: false, reason: "limit" };
|
|
33
|
+
return { ok: true, list: [...list, { name: cleanName, pipeline: clean }] };
|
|
34
|
+
}
|
|
35
|
+
return { ok: true, list: list.map((e, i) => i === index ? { name: cleanName, pipeline: clean } : e) };
|
|
36
|
+
}
|
|
37
|
+
export function sanitizePipelineList(value, max = MAX_SAVED) {
|
|
38
|
+
if (!Array.isArray(value)) return [];
|
|
39
|
+
let list = [];
|
|
40
|
+
for (const raw of value) {
|
|
41
|
+
if (!isRecord(raw)) continue;
|
|
42
|
+
const result = upsertPipeline(list, raw.name, raw.pipeline, max);
|
|
43
|
+
if (result.ok) list = result.list;
|
|
44
|
+
}
|
|
45
|
+
return list;
|
|
46
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { FilterGroup } from './filterBuilder.js';
|
|
2
|
+
export interface SavedQuery {
|
|
3
|
+
/** The visual builder's state, so it can be restored and edited, not only the string. */
|
|
4
|
+
filterGroup?: FilterGroup;
|
|
5
|
+
/** A Lucene string (a quick search, or what the builder produced). */
|
|
6
|
+
lucene?: string;
|
|
7
|
+
sort?: string[];
|
|
8
|
+
projection?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface SavedQueryEntry {
|
|
11
|
+
name: string;
|
|
12
|
+
query: SavedQuery;
|
|
13
|
+
}
|
|
14
|
+
export declare const MAX_SAVED = 50;
|
|
15
|
+
export declare const MAX_RECENT = 20;
|
|
16
|
+
export declare const MAX_NAME_LENGTH = 80;
|
|
17
|
+
export declare const MAX_LUCENE_LENGTH = 2000;
|
|
18
|
+
export declare const MAX_CONDITIONS = 50;
|
|
19
|
+
export declare const MAX_FIELDS = 100;
|
|
20
|
+
export declare const MAX_FIELD_LENGTH = 200;
|
|
21
|
+
export declare const MAX_VALUE_LENGTH = 500;
|
|
22
|
+
/** Largest stored store / imported file, serialised. */
|
|
23
|
+
export declare const MAX_STORE_BYTES: number;
|
|
24
|
+
export declare const EXPORT_FORMAT = "nuxt-ui-mongocamp-saved-queries";
|
|
25
|
+
/**
|
|
26
|
+
* A clean copy of `value` holding only the known, bounded fields, or `undefined` when nothing usable is left (an empty
|
|
27
|
+
* query is not worth saving). Unknown keys are dropped; an invalid filter group is dropped whole.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitizeQuery(value: unknown): SavedQuery | undefined;
|
|
30
|
+
/** Same query ⇒ same key, whatever the key order; condition ids are ignored (they are only UI identity). */
|
|
31
|
+
export declare function queryKey(query: SavedQuery): string;
|
|
32
|
+
export declare function sanitizeName(name: unknown): string | undefined;
|
|
33
|
+
/** `query` first, an equal earlier one removed, at most `max` kept. */
|
|
34
|
+
export declare function pushRecent(list: SavedQuery[], query: SavedQuery, max?: number): SavedQuery[];
|
|
35
|
+
export type SaveFailure = 'invalid-name' | 'invalid-query' | 'limit';
|
|
36
|
+
/** Adds or replaces (name compared case-insensitively) an entry; keeps the list sorted as given, new names last. */
|
|
37
|
+
export declare function upsertSaved(list: SavedQueryEntry[], name: unknown, query: unknown, max?: number): {
|
|
38
|
+
ok: true;
|
|
39
|
+
list: SavedQueryEntry[];
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
reason: SaveFailure;
|
|
43
|
+
};
|
|
44
|
+
export declare function sanitizeSavedList(value: unknown, max?: number): SavedQueryEntry[];
|
|
45
|
+
export declare function sanitizeRecentList(value: unknown, max?: number): SavedQuery[];
|
|
46
|
+
export declare function serializeSaved(list: SavedQueryEntry[]): string;
|
|
47
|
+
export type ImportFailure = 'too-large' | 'not-json' | 'foreign-format';
|
|
48
|
+
/**
|
|
49
|
+
* Reads a file written by `serializeSaved`. Foreign, oversized or non-JSON input is refused whole; single bad entries
|
|
50
|
+
* are skipped and counted. Names that already exist are replaced by the imported query (upsert).
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseSavedImport(text: string, existing: SavedQueryEntry[], max?: number): {
|
|
53
|
+
ok: true;
|
|
54
|
+
list: SavedQueryEntry[];
|
|
55
|
+
imported: number;
|
|
56
|
+
skipped: number;
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
reason: ImportFailure;
|
|
60
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export const MAX_SAVED = 50;
|
|
2
|
+
export const MAX_RECENT = 20;
|
|
3
|
+
export const MAX_NAME_LENGTH = 80;
|
|
4
|
+
export const MAX_LUCENE_LENGTH = 2e3;
|
|
5
|
+
export const MAX_CONDITIONS = 50;
|
|
6
|
+
export const MAX_FIELDS = 100;
|
|
7
|
+
export const MAX_FIELD_LENGTH = 200;
|
|
8
|
+
export const MAX_VALUE_LENGTH = 500;
|
|
9
|
+
export const MAX_STORE_BYTES = 128 * 1024;
|
|
10
|
+
export const EXPORT_FORMAT = "nuxt-ui-mongocamp-saved-queries";
|
|
11
|
+
const OPERATORS = ["contains", "equals", "notEquals", "startsWith", "endsWith", "oneOf", "gte", "lte", "between", "isTrue", "isFalse", "isEmpty", "isNotEmpty"];
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function sanitizeStrings(value, maxItems) {
|
|
16
|
+
if (!Array.isArray(value)) return void 0;
|
|
17
|
+
const out = value.filter((v) => typeof v === "string" && v !== "" && v.length <= MAX_FIELD_LENGTH).slice(0, maxItems);
|
|
18
|
+
return out.length > 0 ? out : void 0;
|
|
19
|
+
}
|
|
20
|
+
function sanitizeCondition(value) {
|
|
21
|
+
if (!isRecord(value)) return void 0;
|
|
22
|
+
const { id, field, operator, value: v, value2 } = value;
|
|
23
|
+
if (typeof id !== "string" || id === "" || id.length > MAX_FIELD_LENGTH) return void 0;
|
|
24
|
+
if (typeof field !== "string" || field === "" || field.length > MAX_FIELD_LENGTH) return void 0;
|
|
25
|
+
if (typeof operator !== "string" || !OPERATORS.includes(operator)) return void 0;
|
|
26
|
+
const condition = { id, field, operator };
|
|
27
|
+
for (const [key, raw] of [["value", v], ["value2", value2]]) {
|
|
28
|
+
if (raw === void 0) continue;
|
|
29
|
+
if (typeof raw !== "string" || raw.length > MAX_VALUE_LENGTH) return void 0;
|
|
30
|
+
condition[key] = raw;
|
|
31
|
+
}
|
|
32
|
+
return condition;
|
|
33
|
+
}
|
|
34
|
+
function sanitizeGroup(value) {
|
|
35
|
+
if (!isRecord(value) || value.match !== "all" && value.match !== "any" || !Array.isArray(value.conditions)) return void 0;
|
|
36
|
+
if (value.conditions.length > MAX_CONDITIONS) return void 0;
|
|
37
|
+
const conditions = [];
|
|
38
|
+
for (const raw of value.conditions) {
|
|
39
|
+
const condition = sanitizeCondition(raw);
|
|
40
|
+
if (!condition) return void 0;
|
|
41
|
+
conditions.push(condition);
|
|
42
|
+
}
|
|
43
|
+
if (conditions.length === 0) return void 0;
|
|
44
|
+
const group = { match: value.match, conditions };
|
|
45
|
+
if (value.negate === true) group.negate = true;
|
|
46
|
+
return group;
|
|
47
|
+
}
|
|
48
|
+
export function sanitizeQuery(value) {
|
|
49
|
+
if (!isRecord(value)) return void 0;
|
|
50
|
+
const query = {};
|
|
51
|
+
const filterGroup = sanitizeGroup(value.filterGroup);
|
|
52
|
+
if (filterGroup) query.filterGroup = filterGroup;
|
|
53
|
+
if (typeof value.lucene === "string" && value.lucene.trim() !== "" && value.lucene.length <= MAX_LUCENE_LENGTH) query.lucene = value.lucene;
|
|
54
|
+
const sort = sanitizeStrings(value.sort, 10);
|
|
55
|
+
if (sort) query.sort = sort;
|
|
56
|
+
const projection = sanitizeStrings(value.projection, MAX_FIELDS);
|
|
57
|
+
if (projection) query.projection = projection;
|
|
58
|
+
return Object.keys(query).length > 0 ? query : void 0;
|
|
59
|
+
}
|
|
60
|
+
function stable(value) {
|
|
61
|
+
if (Array.isArray(value)) return value.map(stable);
|
|
62
|
+
if (isRecord(value)) return Object.fromEntries(Object.keys(value).sort().map((k) => [k, stable(value[k])]));
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
export function queryKey(query) {
|
|
66
|
+
const copy = stable({
|
|
67
|
+
...query,
|
|
68
|
+
filterGroup: query.filterGroup && { ...query.filterGroup, conditions: query.filterGroup.conditions.map(({ id: _id, ...rest }) => rest) }
|
|
69
|
+
});
|
|
70
|
+
return JSON.stringify(copy);
|
|
71
|
+
}
|
|
72
|
+
export function sanitizeName(name) {
|
|
73
|
+
if (typeof name !== "string") return void 0;
|
|
74
|
+
const trimmed = name.trim();
|
|
75
|
+
return trimmed !== "" && trimmed.length <= MAX_NAME_LENGTH ? trimmed : void 0;
|
|
76
|
+
}
|
|
77
|
+
export function pushRecent(list, query, max = MAX_RECENT) {
|
|
78
|
+
const key = queryKey(query);
|
|
79
|
+
return [query, ...list.filter((q) => queryKey(q) !== key)].slice(0, max);
|
|
80
|
+
}
|
|
81
|
+
export function upsertSaved(list, name, query, max = MAX_SAVED) {
|
|
82
|
+
const cleanName = sanitizeName(name);
|
|
83
|
+
if (!cleanName) return { ok: false, reason: "invalid-name" };
|
|
84
|
+
const cleanQuery = sanitizeQuery(query);
|
|
85
|
+
if (!cleanQuery) return { ok: false, reason: "invalid-query" };
|
|
86
|
+
const index = list.findIndex((e) => e.name.toLowerCase() === cleanName.toLowerCase());
|
|
87
|
+
if (index === -1) {
|
|
88
|
+
if (list.length >= max) return { ok: false, reason: "limit" };
|
|
89
|
+
return { ok: true, list: [...list, { name: cleanName, query: cleanQuery }] };
|
|
90
|
+
}
|
|
91
|
+
return { ok: true, list: list.map((e, i) => i === index ? { name: cleanName, query: cleanQuery } : e) };
|
|
92
|
+
}
|
|
93
|
+
export function sanitizeSavedList(value, max = MAX_SAVED) {
|
|
94
|
+
if (!Array.isArray(value)) return [];
|
|
95
|
+
let list = [];
|
|
96
|
+
for (const raw of value) {
|
|
97
|
+
if (!isRecord(raw)) continue;
|
|
98
|
+
const result = upsertSaved(list, raw.name, raw.query, max);
|
|
99
|
+
if (result.ok) list = result.list;
|
|
100
|
+
}
|
|
101
|
+
return list;
|
|
102
|
+
}
|
|
103
|
+
export function sanitizeRecentList(value, max = MAX_RECENT) {
|
|
104
|
+
if (!Array.isArray(value)) return [];
|
|
105
|
+
const out = [];
|
|
106
|
+
const seen = /* @__PURE__ */ new Set();
|
|
107
|
+
for (const raw of value) {
|
|
108
|
+
const query = sanitizeQuery(raw);
|
|
109
|
+
if (!query || seen.has(queryKey(query))) continue;
|
|
110
|
+
seen.add(queryKey(query));
|
|
111
|
+
out.push(query);
|
|
112
|
+
if (out.length >= max) break;
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
export function serializeSaved(list) {
|
|
117
|
+
return JSON.stringify({ format: EXPORT_FORMAT, version: 1, queries: list }, null, 2);
|
|
118
|
+
}
|
|
119
|
+
export function parseSavedImport(text, existing, max = MAX_SAVED) {
|
|
120
|
+
if (text.length > MAX_STORE_BYTES) return { ok: false, reason: "too-large" };
|
|
121
|
+
let parsed;
|
|
122
|
+
try {
|
|
123
|
+
parsed = JSON.parse(text);
|
|
124
|
+
} catch {
|
|
125
|
+
return { ok: false, reason: "not-json" };
|
|
126
|
+
}
|
|
127
|
+
if (!isRecord(parsed) || parsed.format !== EXPORT_FORMAT || parsed.version !== 1 || !Array.isArray(parsed.queries)) {
|
|
128
|
+
return { ok: false, reason: "foreign-format" };
|
|
129
|
+
}
|
|
130
|
+
let list = existing;
|
|
131
|
+
let imported = 0;
|
|
132
|
+
let skipped = 0;
|
|
133
|
+
for (const raw of parsed.queries) {
|
|
134
|
+
const result = isRecord(raw) ? upsertSaved(list, raw.name, raw.query, max) : void 0;
|
|
135
|
+
if (result?.ok) {
|
|
136
|
+
list = result.list;
|
|
137
|
+
imported++;
|
|
138
|
+
} else {
|
|
139
|
+
skipped++;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { ok: true, list, imported, skipped };
|
|
143
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SchemaAnalysis } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
|
+
import type { SampleAnalysis, ValueKind } from './analyzeSamples.js';
|
|
3
|
+
/** More documents than this are never analysed in one request (≈ 20 s on the dev server); use a sample instead. */
|
|
4
|
+
export declare const FULL_ANALYSIS_MAX_DOCUMENTS = 200000;
|
|
5
|
+
/** Time to wait for an analysis of `documents` documents: a fixed allowance plus 0.4 ms each (measured: 0.11 ms), at most 2 minutes. */
|
|
6
|
+
export declare function analysisTimeoutMs(documents: number): number;
|
|
7
|
+
/** What to ask for: the server needs a positive size, and more than the collection holds is the same as all of it. */
|
|
8
|
+
export declare function analysisSampleSize(documents: number): number;
|
|
9
|
+
export declare function kindOfServerType(serverType: string): ValueKind;
|
|
10
|
+
/**
|
|
11
|
+
* Maps the server's analysis onto `SampleAnalysis`. Fields inside objects are `a.b`, fields of objects inside arrays
|
|
12
|
+
* `items[].sku` (the server's `[array element]` node is folded into the path, like the client-side analysis does).
|
|
13
|
+
* `share` is the share of analysed documents that have the field: a field's `percentageOfParent` multiplied down the
|
|
14
|
+
* chain, so a field inside array elements is not inflated by the number of elements. The server lists no common values.
|
|
15
|
+
*/
|
|
16
|
+
export declare function statisticsFromSchemaAnalysis(analysis: SchemaAnalysis, maxFields?: number): SampleAnalysis;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { comparePaths } from "./analyzeSamples.js";
|
|
2
|
+
export const FULL_ANALYSIS_MAX_DOCUMENTS = 2e5;
|
|
3
|
+
const BASE_TIMEOUT_MS = 15e3;
|
|
4
|
+
const MS_PER_DOCUMENT = 0.4;
|
|
5
|
+
const MAX_TIMEOUT_MS = 12e4;
|
|
6
|
+
export function analysisTimeoutMs(documents) {
|
|
7
|
+
return Math.min(MAX_TIMEOUT_MS, Math.round(BASE_TIMEOUT_MS + Math.max(0, documents) * MS_PER_DOCUMENT));
|
|
8
|
+
}
|
|
9
|
+
export function analysisSampleSize(documents) {
|
|
10
|
+
return Math.min(FULL_ANALYSIS_MAX_DOCUMENTS, Math.max(1, Math.floor(documents) || 1));
|
|
11
|
+
}
|
|
12
|
+
const KIND_BY_SERVER_TYPE = {
|
|
13
|
+
objectId: "string",
|
|
14
|
+
string: "string",
|
|
15
|
+
int: "number",
|
|
16
|
+
long: "number",
|
|
17
|
+
double: "number",
|
|
18
|
+
decimal: "number",
|
|
19
|
+
bool: "boolean",
|
|
20
|
+
date: "date",
|
|
21
|
+
object: "object",
|
|
22
|
+
array: "array",
|
|
23
|
+
null: "null"
|
|
24
|
+
};
|
|
25
|
+
const ARRAY_ELEMENT = "[array element]";
|
|
26
|
+
const DEFAULT_MAX_FIELDS = 200;
|
|
27
|
+
export function kindOfServerType(serverType) {
|
|
28
|
+
return KIND_BY_SERVER_TYPE[serverType] ?? "string";
|
|
29
|
+
}
|
|
30
|
+
export function statisticsFromSchemaAnalysis(analysis, maxFields = DEFAULT_MAX_FIELDS) {
|
|
31
|
+
const sampled = analysis.sample > 0 ? Math.min(analysis.sample, analysis.count || analysis.sample) : analysis.count;
|
|
32
|
+
const fields = [];
|
|
33
|
+
const visit = (field, parentPath, parentShare) => {
|
|
34
|
+
const isElement = field.name === ARRAY_ELEMENT;
|
|
35
|
+
const path = isElement ? `${parentPath}[]` : parentPath ? `${parentPath}.${field.name}` : field.name;
|
|
36
|
+
const share = parentShare * Math.min(1, Math.max(0, field.percentageOfParent));
|
|
37
|
+
if (!isElement) {
|
|
38
|
+
const present = Math.round(share * sampled);
|
|
39
|
+
const toDocuments = field.count > 0 ? present / field.count : 1;
|
|
40
|
+
const counts = /* @__PURE__ */ new Map();
|
|
41
|
+
for (const { fieldType, count } of field.fieldTypes ?? []) {
|
|
42
|
+
const kind = kindOfServerType(fieldType);
|
|
43
|
+
counts.set(kind, (counts.get(kind) ?? 0) + Math.round(count * toDocuments));
|
|
44
|
+
}
|
|
45
|
+
fields.push({
|
|
46
|
+
path,
|
|
47
|
+
present,
|
|
48
|
+
share,
|
|
49
|
+
types: [...counts].map(([type, count]) => ({ type, count })).sort((a, b) => b.count - a.count)
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
for (const sub of field.subFields ?? []) visit(sub, path, isElement ? parentShare : share);
|
|
53
|
+
};
|
|
54
|
+
for (const field of analysis.fields ?? []) visit(field, "", 1);
|
|
55
|
+
fields.sort((a, b) => comparePaths(a.path, b.path));
|
|
56
|
+
return { sampled, fields: fields.slice(0, maxFields), truncated: fields.length > maxFields };
|
|
57
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const OPERATOR_NOT_ALLOWED_CODE = 4031;
|
|
2
|
+
export interface ServerError {
|
|
3
|
+
/** HTTP status of the response, when there was one. */
|
|
4
|
+
status?: number;
|
|
5
|
+
/** The server's own error code from the body. */
|
|
6
|
+
code?: number;
|
|
7
|
+
/** The server's message with every database address removed (`parseServerError`); `undefined` when there is none. */
|
|
8
|
+
message?: string;
|
|
9
|
+
/** `mongo` when the message is MongoDB's own text for a failed command. */
|
|
10
|
+
kind?: 'mongo' | 'other';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads what the server said about a failed request from the error the generated client threw. The client only
|
|
14
|
+
* keeps the `Response`, so the body is read from a clone, best-effort: anything unreadable (no response, a network
|
|
15
|
+
* failure, a non-JSON body such as a proxy's 503) just yields what is known. Never throws.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readServerError(error: unknown): Promise<ServerError>;
|
|
18
|
+
/** `$function` out of "the operator $function is not allowed in an aggregation" (code 4031). */
|
|
19
|
+
export declare function notAllowedOperator(message: string | undefined): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseServerError } from "./aggregationErrors.js";
|
|
2
|
+
export const OPERATOR_NOT_ALLOWED_CODE = 4031;
|
|
3
|
+
export async function readServerError(error) {
|
|
4
|
+
const response = error?.response;
|
|
5
|
+
const status = typeof response?.status === "number" ? response.status : void 0;
|
|
6
|
+
if (!response || typeof response.clone !== "function") return { status };
|
|
7
|
+
try {
|
|
8
|
+
const body = await response.clone().json();
|
|
9
|
+
const code = typeof body?.code === "number" ? body.code : void 0;
|
|
10
|
+
if (typeof body?.msg !== "string" || !body.msg) return { status, code };
|
|
11
|
+
const info = parseServerError(body.msg);
|
|
12
|
+
return { status, code, message: info.message || void 0, kind: info.kind };
|
|
13
|
+
} catch {
|
|
14
|
+
return { status };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function notAllowedOperator(message) {
|
|
18
|
+
return /operator (\$[A-Za-z]+) is not allowed/.exec(message ?? "")?.[1];
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DatabaseInfo, JobInformation } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
|
+
export interface CollectionStat {
|
|
3
|
+
name: string;
|
|
4
|
+
count: number;
|
|
5
|
+
/** Uncompressed size of the documents, bytes. */
|
|
6
|
+
size: number;
|
|
7
|
+
/** Size on disk, bytes. */
|
|
8
|
+
storageSize: number;
|
|
9
|
+
avgObjSize: number;
|
|
10
|
+
indexCount: number;
|
|
11
|
+
totalIndexSize: number;
|
|
12
|
+
}
|
|
13
|
+
export type RankBy = 'storageSize' | 'count' | 'avgObjSize' | 'totalIndexSize';
|
|
14
|
+
export declare const RANK_METRICS: readonly RankBy[];
|
|
15
|
+
/** Metrics that are byte sizes (the others are plain counts). */
|
|
16
|
+
export declare const BYTE_METRICS: ReadonlySet<RankBy>;
|
|
17
|
+
/** The `n` collections with the highest value of `by`, highest first (ties by name); collections with nothing in them are left out. */
|
|
18
|
+
export declare function rankCollections(stats: readonly CollectionStat[], by: RankBy, n: number): CollectionStat[];
|
|
19
|
+
export interface OverviewTotals {
|
|
20
|
+
databases: number;
|
|
21
|
+
/** Sum of the databases' size on disk, bytes (0 when they could not be read). */
|
|
22
|
+
diskBytes: number;
|
|
23
|
+
collections: number;
|
|
24
|
+
documents: number;
|
|
25
|
+
/** Sum of the collections' size on disk, bytes. */
|
|
26
|
+
storageBytes: number;
|
|
27
|
+
indexBytes: number;
|
|
28
|
+
indexes: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function overviewTotals(stats: readonly CollectionStat[], databases: readonly DatabaseInfo[] | null): OverviewTotals;
|
|
31
|
+
export interface ShareSlice {
|
|
32
|
+
/** The collection name, or `null` for the slice that sums up all the others. */
|
|
33
|
+
name: string | null;
|
|
34
|
+
value: number;
|
|
35
|
+
}
|
|
36
|
+
/** The `top` biggest collections by `by` and one slice for everything else (a donut stays readable with 6 slices). */
|
|
37
|
+
export declare function shareSlices(stats: readonly CollectionStat[], by: RankBy, top?: number): ShareSlice[];
|
|
38
|
+
export interface UpcomingJob {
|
|
39
|
+
group: string;
|
|
40
|
+
name: string;
|
|
41
|
+
cronExpression: string;
|
|
42
|
+
next: Date;
|
|
43
|
+
}
|
|
44
|
+
/** The next `n` scheduled runs, soonest first; a job without a (valid) next fire time is not scheduled and is left out. */
|
|
45
|
+
export declare function nextJobs(jobs: readonly JobInformation[], n: number): UpcomingJob[];
|
|
46
|
+
/** A collection's statistics from the server's collection information; missing or malformed numbers count as 0. */
|
|
47
|
+
export declare function toCollectionStat(name: string, info: Partial<Record<'count' | 'size' | 'storageSize' | 'avgObjSize' | 'nindexes' | 'totalIndexSize', unknown>>): CollectionStat;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const RANK_METRICS = ["storageSize", "count", "avgObjSize", "totalIndexSize"];
|
|
2
|
+
export const BYTE_METRICS = /* @__PURE__ */ new Set(["storageSize", "avgObjSize", "totalIndexSize"]);
|
|
3
|
+
export function rankCollections(stats, by, n) {
|
|
4
|
+
return stats.filter((s) => s[by] > 0).sort((a, b) => b[by] - a[by] || a.name.localeCompare(b.name)).slice(0, Math.max(0, Math.floor(n)));
|
|
5
|
+
}
|
|
6
|
+
export function overviewTotals(stats, databases) {
|
|
7
|
+
const sum = (pick) => stats.reduce((total, s) => total + pick(s), 0);
|
|
8
|
+
return {
|
|
9
|
+
databases: databases?.length ?? 0,
|
|
10
|
+
diskBytes: databases?.reduce((total, d) => total + (Number.isFinite(d.sizeOnDisk) ? d.sizeOnDisk : 0), 0) ?? 0,
|
|
11
|
+
collections: stats.length,
|
|
12
|
+
documents: sum((s) => s.count),
|
|
13
|
+
storageBytes: sum((s) => s.storageSize),
|
|
14
|
+
indexBytes: sum((s) => s.totalIndexSize),
|
|
15
|
+
indexes: sum((s) => s.indexCount)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function shareSlices(stats, by, top = 5) {
|
|
19
|
+
const ranked = rankCollections(stats, by, stats.length);
|
|
20
|
+
const slices = ranked.slice(0, top).map((s) => ({ name: s.name, value: s[by] }));
|
|
21
|
+
const rest = ranked.slice(top).reduce((total, s) => total + s[by], 0);
|
|
22
|
+
if (rest > 0) slices.push({ name: null, value: rest });
|
|
23
|
+
return slices;
|
|
24
|
+
}
|
|
25
|
+
function toDate(value) {
|
|
26
|
+
const date = value instanceof Date ? value : typeof value === "string" || typeof value === "number" ? new Date(value) : void 0;
|
|
27
|
+
return date && !Number.isNaN(date.getTime()) ? date : void 0;
|
|
28
|
+
}
|
|
29
|
+
export function nextJobs(jobs, n) {
|
|
30
|
+
const upcoming = [];
|
|
31
|
+
for (const job of jobs) {
|
|
32
|
+
const next = toDate(job.nextScheduledFireTime);
|
|
33
|
+
if (next) upcoming.push({ group: job.group, name: job.name, cronExpression: job.cronExpression, next });
|
|
34
|
+
}
|
|
35
|
+
return upcoming.sort((a, b) => a.next.getTime() - b.next.getTime() || `${a.group}/${a.name}`.localeCompare(`${b.group}/${b.name}`)).slice(0, Math.max(0, Math.floor(n)));
|
|
36
|
+
}
|
|
37
|
+
export function toCollectionStat(name, info) {
|
|
38
|
+
const n = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
39
|
+
return { name, count: n(info.count), size: n(info.size), storageSize: n(info.storageSize), avgObjSize: n(info.avgObjSize), indexCount: n(info.nindexes), totalIndexSize: n(info.totalIndexSize) };
|
|
40
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { TokenExpiryState } from './jwtExpiry.js';
|
|
2
|
+
export type VerifyResult = 'valid' | 'invalid' | 'unknown';
|
|
2
3
|
interface SessionGuardDeps {
|
|
3
4
|
path: string;
|
|
4
5
|
loginPath: string;
|
|
5
6
|
checkExpiry: () => TokenExpiryState;
|
|
6
7
|
invalidate: () => Promise<void>;
|
|
8
|
+
verify?: () => Promise<VerifyResult>;
|
|
7
9
|
isAllowed: (path: string) => boolean;
|
|
8
10
|
}
|
|
9
11
|
export declare function runSessionGuard(deps: SessionGuardDeps): Promise<'continue' | 'redirect'>;
|
|
12
|
+
export declare function createVerifyCache(ttlMs: number, now?: () => number): (key: string, run: () => Promise<VerifyResult>) => Promise<VerifyResult>;
|
|
10
13
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export async function runSessionGuard(deps) {
|
|
2
|
-
|
|
2
|
+
const expiry = deps.checkExpiry();
|
|
3
|
+
if (expiry !== "expired" && !(expiry === "valid" && deps.verify && await isRejectedByServer(deps.verify))) return "continue";
|
|
3
4
|
try {
|
|
4
5
|
await deps.invalidate();
|
|
5
6
|
} catch {
|
|
@@ -8,3 +9,19 @@ export async function runSessionGuard(deps) {
|
|
|
8
9
|
if (deps.path === deps.loginPath) return "continue";
|
|
9
10
|
return deps.isAllowed(deps.path) ? "continue" : "redirect";
|
|
10
11
|
}
|
|
12
|
+
async function isRejectedByServer(verify) {
|
|
13
|
+
try {
|
|
14
|
+
return await verify() === "invalid";
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function createVerifyCache(ttlMs, now = Date.now) {
|
|
20
|
+
let last = null;
|
|
21
|
+
return async function cached(key, run) {
|
|
22
|
+
if (last && last.key === key && now() - last.at < ttlMs) return "valid";
|
|
23
|
+
const result = await run();
|
|
24
|
+
last = result === "valid" ? { key, at: now() } : null;
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sfxcode/nuxt-ui-mongocamp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A Nuxt module that wraps @sfxcode/nuxt-mongocamp-server with ready-made UI components, composables, and a runtime plugin",
|
|
5
5
|
"repository": "sfxcode/nuxt-ui-mongocamp",
|
|
6
6
|
"homepage": "https://sfxcode.github.io/nuxt-ui-mongocamp/",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dev": "npm run dev:prepare && nuxt dev playground",
|
|
45
45
|
"dev:build": "nuxt build playground",
|
|
46
46
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
|
|
47
|
-
"release": "npm run lint && npm run test && npm run prepack && changelogen --
|
|
47
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --minor --release && npm publish && git push --follow-tags",
|
|
48
48
|
"lint": "eslint .",
|
|
49
49
|
"test": "vitest run --project unit --project components",
|
|
50
50
|
"test:watch": "vitest watch",
|
|
@@ -55,24 +55,25 @@
|
|
|
55
55
|
"docs:preview": "vitepress preview docs"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@formkit/nuxt": "^2.1
|
|
58
|
+
"@formkit/nuxt": "^2.2.1",
|
|
59
59
|
"@internationalized/date": "^3.12.4",
|
|
60
60
|
"@nuxt/ui": "^4.12.0",
|
|
61
61
|
"@nuxtjs/i18n": "^10.6.0",
|
|
62
62
|
"@sfxcode/nuxt-mongocamp-server": "^1.6.3",
|
|
63
|
-
"@sfxcode/nuxt-ui-formkit": "^1.4.
|
|
63
|
+
"@sfxcode/nuxt-ui-formkit": "^1.4.2",
|
|
64
|
+
"@tanstack/charts": "^1.3.0",
|
|
64
65
|
"consola": "^3.4.2",
|
|
65
66
|
"defu": "^6.1.7",
|
|
66
|
-
"minimatch": "^11.0.
|
|
67
|
+
"minimatch": "^11.0.4",
|
|
67
68
|
"unocss-nuxt-ui": "^1.2.2"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@iconify-json/lucide": "^1.2.
|
|
71
|
-
"@nuxt/devtools": "^4.
|
|
71
|
+
"@iconify-json/lucide": "^1.2.151",
|
|
72
|
+
"@nuxt/devtools": "^4.1.0",
|
|
72
73
|
"@nuxt/eslint-config": "^1.17.0",
|
|
73
|
-
"@nuxt/kit": "^4.6.
|
|
74
|
+
"@nuxt/kit": "^4.6.4",
|
|
74
75
|
"@nuxt/module-builder": "^1.0.3",
|
|
75
|
-
"@nuxt/schema": "^4.6.
|
|
76
|
+
"@nuxt/schema": "^4.6.4",
|
|
76
77
|
"@nuxt/test-utils": "^4.3.4",
|
|
77
78
|
"@playwright/test": "^1.64.1",
|
|
78
79
|
"@types/node": "latest",
|
|
@@ -81,10 +82,10 @@
|
|
|
81
82
|
"changelogen": "^0.6.2",
|
|
82
83
|
"eslint": "^10.14.0",
|
|
83
84
|
"happy-dom": "^21.0.4",
|
|
84
|
-
"nuxt": "^4.6.
|
|
85
|
+
"nuxt": "^4.6.4",
|
|
85
86
|
"typescript": "~6.0.3",
|
|
86
87
|
"vitepress": "2.0.0-alpha.18",
|
|
87
|
-
"vitest": "^5.0
|
|
88
|
+
"vitest": "^5.1.0",
|
|
88
89
|
"vue-tsc": "^3.3.14"
|
|
89
90
|
},
|
|
90
91
|
"packageManager": "pnpm@11.21.0+sha512.521705bce689924eac72f5a3587122f362689ef6571e55ba80076fd637c11132ecffada26fad4ea79c485bfddbfd3d5a2a5b05805a77e893de71ec8a6cca3bb1"
|