@sfxcode/nuxt-ui-mongocamp 1.5.8 → 2.0.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/README.md +5 -5
- package/dist/module.json +1 -1
- package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue +5 -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 -2
- package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampBucketFiles.vue +4 -6
- package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampCollectionCharts.vue +4 -2
- package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampCollectionCopy.vue +5 -3
- package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampCollectionData.vue +60 -25
- package/dist/runtime/components/MongocampCollectionInfos.vue +16 -1
- package/dist/runtime/components/MongocampDocumentView.vue +6 -1
- package/dist/runtime/components/MongocampExportAll.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampExportAll.vue +12 -0
- package/dist/runtime/components/MongocampExportAll.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampImport.vue +3 -0
- package/dist/runtime/components/MongocampIndexes.vue +7 -3
- package/dist/runtime/components/MongocampQueryBar.vue +15 -0
- package/dist/runtime/components/MongocampServerInfo.vue +1 -14
- package/dist/runtime/components/MongocampServerStatus.vue +7 -2
- package/dist/runtime/components/MongocampVersion.d.vue.ts +1 -1
- package/dist/runtime/components/MongocampVersion.vue +14 -7
- package/dist/runtime/components/MongocampVersion.vue.d.ts +1 -1
- package/dist/runtime/composables/useMongocampAdmin.js +6 -5
- package/dist/runtime/composables/useMongocampAggregation.d.ts +10 -1
- package/dist/runtime/composables/useMongocampAggregation.js +17 -5
- package/dist/runtime/composables/useMongocampBucket.d.ts +4 -0
- package/dist/runtime/composables/useMongocampBucket.js +7 -6
- package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +6 -4
- package/dist/runtime/composables/useMongocampBulkByFilter.js +11 -6
- package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +3 -1
- package/dist/runtime/composables/useMongocampCollectionCopy.js +4 -2
- package/dist/runtime/composables/useMongocampCollectionStats.js +2 -4
- package/dist/runtime/composables/useMongocampError.d.ts +1 -1
- package/dist/runtime/composables/useMongocampError.js +4 -1
- package/dist/runtime/composables/useMongocampExportAll.d.ts +10 -1
- package/dist/runtime/composables/useMongocampExportAll.js +4 -1
- package/dist/runtime/composables/useMongocampFetchAll.d.ts +11 -5
- package/dist/runtime/composables/useMongocampFetchAll.js +8 -8
- package/dist/runtime/composables/useMongocampJobs.js +3 -2
- package/dist/runtime/composables/useMongocampQuery.d.ts +26 -36
- package/dist/runtime/composables/useMongocampQuery.js +45 -48
- package/dist/runtime/composables/useMongocampSchema.js +2 -0
- package/dist/runtime/locales/de.json +12 -4
- package/dist/runtime/locales/en.json +12 -4
- package/dist/runtime/publicUtils.d.ts +1 -0
- package/dist/runtime/publicUtils.js +1 -0
- package/dist/runtime/server/handlers/mongocampProxy.d.ts +1 -1
- package/dist/runtime/server/handlers/mongocampProxy.js +12 -12
- package/dist/runtime/utils/aggregationPipeline.d.ts +2 -1
- package/dist/runtime/utils/aggregationPipeline.js +2 -3
- package/dist/runtime/utils/caseInsensitive.d.ts +10 -0
- package/dist/runtime/utils/caseInsensitive.js +8 -0
- package/dist/runtime/utils/collectionStats.d.ts +4 -1
- package/dist/runtime/utils/collectionStats.js +2 -2
- package/dist/runtime/utils/configRows.d.ts +3 -3
- package/dist/runtime/utils/cursorPaging.d.ts +16 -0
- package/dist/runtime/utils/cursorPaging.js +17 -0
- package/dist/runtime/utils/documentCompare.js +2 -3
- package/dist/runtime/utils/documentPaths.d.ts +5 -5
- package/dist/runtime/utils/documentPaths.js +9 -2
- package/dist/runtime/utils/documentTree.js +3 -0
- package/dist/runtime/utils/fileFilter.d.ts +7 -0
- package/dist/runtime/utils/fileFilter.js +11 -0
- package/dist/runtime/utils/filterBuilder.d.ts +1 -1
- package/dist/runtime/utils/filterBuilder.js +5 -11
- package/dist/runtime/utils/filterSuggestions.js +1 -1
- package/dist/runtime/utils/indexForm.d.ts +7 -0
- package/dist/runtime/utils/indexForm.js +9 -0
- package/dist/runtime/utils/pagedFetch.d.ts +13 -0
- package/dist/runtime/utils/pagedFetch.js +44 -0
- package/dist/runtime/utils/queryState.d.ts +5 -0
- package/dist/runtime/utils/queryState.js +3 -2
- package/dist/runtime/utils/relaxedValues.d.ts +17 -0
- package/dist/runtime/utils/relaxedValues.js +51 -0
- package/dist/runtime/utils/requestLimits.d.ts +1 -1
- package/dist/runtime/utils/requestLimits.js +1 -1
- package/dist/runtime/utils/savedQueries.d.ts +2 -0
- package/dist/runtime/utils/savedQueries.js +1 -0
- package/dist/runtime/utils/schemaAnalysis.d.ts +4 -4
- package/dist/runtime/utils/schemaAnalysis.js +2 -2
- package/dist/runtime/utils/sensitiveFields.d.ts +20 -0
- package/dist/runtime/utils/sensitiveFields.js +63 -0
- package/dist/runtime/utils/serverError.d.ts +7 -0
- package/dist/runtime/utils/serverError.js +11 -0
- package/dist/runtime/utils/serverStatus.d.ts +2 -2
- package/package.json +12 -6
- package/dist/runtime/utils/luceneExpression.d.ts +0 -15
- package/dist/runtime/utils/luceneExpression.js +0 -74
|
@@ -503,11 +503,14 @@ const limitsText = computed(() => ({ maxRows: DEFAULT_IMPORT_LIMITS.maxRows, max
|
|
|
503
503
|
class="flex flex-col gap-3"
|
|
504
504
|
data-test="ndjson-result"
|
|
505
505
|
>
|
|
506
|
+
<!-- server 2.0 imports all or nothing: an aborted import removes what earlier batches stored -->
|
|
506
507
|
<UAlert
|
|
507
508
|
v-if="serverError"
|
|
508
509
|
color="error"
|
|
509
510
|
:variant="ui.alert.variant"
|
|
510
511
|
icon="i-lucide-circle-alert"
|
|
512
|
+
data-test="ndjson-aborted"
|
|
513
|
+
:title="t('nuxtUiMongocamp.import.ndjsonAborted')"
|
|
511
514
|
:description="serverError"
|
|
512
515
|
/>
|
|
513
516
|
<template v-else-if="serverResult">
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
buildIndexRequest,
|
|
9
9
|
canDropIndex,
|
|
10
10
|
classifyIndexError,
|
|
11
|
+
collationLocale,
|
|
11
12
|
describeKey,
|
|
12
13
|
formatBytes,
|
|
13
14
|
indexKeys,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
isTextIndex,
|
|
16
17
|
isUnusedIndex,
|
|
17
18
|
MAX_INDEX_FIELDS,
|
|
19
|
+
partialFilterText,
|
|
18
20
|
validateIndexForm
|
|
19
21
|
} from "../utils/indexForm";
|
|
20
22
|
import { shortenLabel } from "../utils/chartData";
|
|
@@ -74,7 +76,9 @@ const rows = computed(
|
|
|
74
76
|
sparse: idx.sparse,
|
|
75
77
|
hidden: idx.hidden,
|
|
76
78
|
partial: idx.partialFilterExpression != null,
|
|
79
|
+
partialFilter: partialFilterText(idx.partialFilterExpression),
|
|
77
80
|
collation: idx.collation != null,
|
|
81
|
+
collationLocale: collationLocale(idx.collation),
|
|
78
82
|
language: idx.defaultLanguage ?? void 0,
|
|
79
83
|
expireAfterSeconds: isExpiringIndex(idx) ? idx.expireAfterSeconds : void 0,
|
|
80
84
|
size: storage.value?.indexSizes[idx.name],
|
|
@@ -107,11 +111,11 @@ const columns = computed(() => [
|
|
|
107
111
|
if (row.original.text) flags.push({ label: "text", color: "info" });
|
|
108
112
|
if (row.original.expireAfterSeconds !== void 0) flags.push({ label: `expire ${row.original.expireAfterSeconds}s`, color: "secondary" });
|
|
109
113
|
if (row.original.sparse) flags.push({ label: "sparse", color: "secondary" });
|
|
110
|
-
if (row.original.partial) flags.push({ label: "partial", color: "secondary" });
|
|
114
|
+
if (row.original.partial) flags.push({ label: "partial", color: "secondary", title: row.original.partialFilter });
|
|
111
115
|
if (row.original.hidden) flags.push({ label: "hidden", color: "warning" });
|
|
112
|
-
if (row.original.collation) flags.push({ label: "collation", color: "secondary" });
|
|
116
|
+
if (row.original.collation) flags.push({ label: row.original.collationLocale ? `collation ${row.original.collationLocale}` : "collation", color: "secondary" });
|
|
113
117
|
if (row.original.text && row.original.language) flags.push({ label: row.original.language, color: "info" });
|
|
114
|
-
const badges = flags.map((flag) => h(UBadge, { label: flag.label, color: flag.color, variant: ui.value.badge.variant, size: "sm" }));
|
|
118
|
+
const badges = flags.map((flag) => h(UBadge, { label: flag.label, color: flag.color, variant: ui.value.badge.variant, size: "sm", title: flag.title, ...flag.title ? { "data-partial-filter": flag.title } : {} }));
|
|
115
119
|
if (badges.length === 0) badges.push(h(UBadge, { label: t("nuxtUiMongocamp.collectionInfos.typeStandard"), color: "neutral", variant: ui.value.badge.variant, size: "sm" }));
|
|
116
120
|
return h("div", { class: "flex flex-wrap gap-1" }, badges);
|
|
117
121
|
}
|
|
@@ -44,6 +44,9 @@ function commit(next, options = {}) {
|
|
|
44
44
|
emit("apply", next);
|
|
45
45
|
if (options.remember !== false && !isEmptyQuery(next)) record(toSavedQuery(next));
|
|
46
46
|
}
|
|
47
|
+
function toggleMatchCase() {
|
|
48
|
+
commit({ ...model.value, matchCase: !model.value.matchCase }, { remember: false });
|
|
49
|
+
}
|
|
47
50
|
function onBuilderApply(lucene) {
|
|
48
51
|
commit({ ...model.value, filterGroup: cloneGroup(draft.value), lucene });
|
|
49
52
|
}
|
|
@@ -134,6 +137,18 @@ function saveCurrent() {
|
|
|
134
137
|
/>
|
|
135
138
|
</UChip>
|
|
136
139
|
|
|
140
|
+
<UButton
|
|
141
|
+
icon="i-lucide-case-sensitive"
|
|
142
|
+
color="neutral"
|
|
143
|
+
:variant="model.matchCase ? 'subtle' : 'ghost'"
|
|
144
|
+
:size="ui.controlSize"
|
|
145
|
+
:aria-pressed="model.matchCase"
|
|
146
|
+
:aria-label="t('nuxtUiMongocamp.queryBar.matchCase')"
|
|
147
|
+
:title="t('nuxtUiMongocamp.queryBar.matchCaseHint')"
|
|
148
|
+
data-test="match-case"
|
|
149
|
+
@click="toggleMatchCase"
|
|
150
|
+
/>
|
|
151
|
+
|
|
137
152
|
<UPopover>
|
|
138
153
|
<UChip
|
|
139
154
|
:text="model.sort.length"
|
|
@@ -23,10 +23,6 @@ const stats = ref(null);
|
|
|
23
23
|
const capabilities = ref(null);
|
|
24
24
|
const loading = ref(false);
|
|
25
25
|
const failed = ref({ info: false, stats: false, capabilities: false });
|
|
26
|
-
const olderServer = ref(false);
|
|
27
|
-
function statusOf(error) {
|
|
28
|
-
return error?.response?.status;
|
|
29
|
-
}
|
|
30
26
|
async function load() {
|
|
31
27
|
const [info, loadedStats, loadedCapabilities] = await Promise.allSettled([
|
|
32
28
|
getServerInfo(),
|
|
@@ -36,12 +32,10 @@ async function load() {
|
|
|
36
32
|
mongoDbVersion.value = info.status === "fulfilled" ? info.value.mongoDbVersion || null : mongoDbVersion.value;
|
|
37
33
|
stats.value = loadedStats.status === "fulfilled" ? loadedStats.value : stats.value;
|
|
38
34
|
capabilities.value = loadedCapabilities.status === "fulfilled" ? loadedCapabilities.value : capabilities.value;
|
|
39
|
-
const missing = loadedCapabilities.status === "rejected" && [404, 405].includes(statusOf(loadedCapabilities.reason) ?? 0);
|
|
40
|
-
olderServer.value = missing;
|
|
41
35
|
failed.value = {
|
|
42
36
|
info: info.status === "rejected",
|
|
43
37
|
stats: loadedStats.status === "rejected",
|
|
44
|
-
capabilities: loadedCapabilities.status === "rejected"
|
|
38
|
+
capabilities: loadedCapabilities.status === "rejected"
|
|
45
39
|
};
|
|
46
40
|
if ([info, loadedStats, loadedCapabilities].every((r) => r.status === "rejected")) throw info.reason;
|
|
47
41
|
}
|
|
@@ -270,13 +264,6 @@ defineExpose({ refresh });
|
|
|
270
264
|
</div>
|
|
271
265
|
</UCard>
|
|
272
266
|
|
|
273
|
-
<UAlert
|
|
274
|
-
v-if="olderServer && !hideCapabilities"
|
|
275
|
-
color="neutral"
|
|
276
|
-
:variant="ui.alert.variant"
|
|
277
|
-
data-testid="older-server"
|
|
278
|
-
:description="t('nuxtUiMongocamp.serverInfo.olderServer')"
|
|
279
|
-
/>
|
|
280
267
|
<UCard v-if="!hideCapabilities && capabilities">
|
|
281
268
|
<template #header>
|
|
282
269
|
<span class="font-semibold">{{ t("nuxtUiMongocamp.serverInfo.capabilitiesHeading") }}</span>
|
|
@@ -12,7 +12,7 @@ const props = defineProps({
|
|
|
12
12
|
const { t } = useI18n();
|
|
13
13
|
const paths = useMongocampPaths();
|
|
14
14
|
const { $mongocampVersion } = useNuxtApp();
|
|
15
|
-
const { getStats, getServerInfo } = useMongocampSystem();
|
|
15
|
+
const { getStats, getServerInfo, getCapabilities } = useMongocampSystem();
|
|
16
16
|
const { canSeeAdmin } = useMongocampRoles();
|
|
17
17
|
const { blocked } = useMongocampAdminGate();
|
|
18
18
|
const state = useMongocampStorage();
|
|
@@ -24,9 +24,14 @@ const uptimeSeconds = ref();
|
|
|
24
24
|
const outcome = ref({ info: "skipped", stats: "skipped" });
|
|
25
25
|
const canAskInfo = computed(() => isProxyMode || !!state.value?.profile);
|
|
26
26
|
const canAskStats = computed(() => canAskInfo.value && !blocked.value);
|
|
27
|
+
async function databaseInfo() {
|
|
28
|
+
if (!blocked.value) return getServerInfo();
|
|
29
|
+
const major = (await getCapabilities()).mongoDbMajor;
|
|
30
|
+
return { mongoDbVersion: major ? String(major) : void 0 };
|
|
31
|
+
}
|
|
27
32
|
async function refresh() {
|
|
28
33
|
const [info, stats] = await Promise.allSettled([
|
|
29
|
-
canAskInfo.value ?
|
|
34
|
+
canAskInfo.value ? databaseInfo() : Promise.reject(new Error("skipped")),
|
|
30
35
|
canAskStats.value ? getStats() : Promise.reject(new Error("skipped"))
|
|
31
36
|
]);
|
|
32
37
|
mongoDbVersion.value = info.status === "fulfilled" ? info.value.mongoDbVersion || void 0 : void 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
|
-
/** Hide the MongoDB version badge (it is also hidden while the server cannot tell, e.g. before login
|
|
2
|
+
/** Hide the MongoDB version badge (it is also hidden while the server cannot tell, e.g. before login). */
|
|
3
3
|
hideDatabase?: boolean;
|
|
4
4
|
};
|
|
5
5
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
@@ -9,22 +9,29 @@ const props = defineProps({
|
|
|
9
9
|
const { t } = useI18n();
|
|
10
10
|
const ui = useMongocampUi();
|
|
11
11
|
const { $mongocampVersion } = useNuxtApp();
|
|
12
|
-
const { getServerInfo } = useMongocampSystem();
|
|
12
|
+
const { getServerInfo, getCapabilities } = useMongocampSystem();
|
|
13
13
|
const state = useMongocampStorage();
|
|
14
14
|
const isProxyMode = useMongocampProxyMode();
|
|
15
15
|
const version = computed(() => $mongocampVersion.value);
|
|
16
16
|
const mongoDbVersion = ref(null);
|
|
17
17
|
const canAsk = computed(() => !props.hideDatabase && (isProxyMode || !!state.value?.profile));
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
async function loadDatabaseVersion() {
|
|
19
|
+
if (isProxyMode || state.value?.profile?.isAdmin === true) {
|
|
20
|
+
try {
|
|
21
|
+
const full = (await getServerInfo()).mongoDbVersion;
|
|
22
|
+
if (full) return full;
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
try {
|
|
24
|
-
|
|
27
|
+
const major = (await getCapabilities()).mongoDbMajor;
|
|
28
|
+
return major ? String(major) : null;
|
|
25
29
|
} catch {
|
|
26
|
-
|
|
30
|
+
return null;
|
|
27
31
|
}
|
|
32
|
+
}
|
|
33
|
+
watch(canAsk, async (ask) => {
|
|
34
|
+
mongoDbVersion.value = ask ? await loadDatabaseVersion() : null;
|
|
28
35
|
}, { immediate: true });
|
|
29
36
|
</script>
|
|
30
37
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
|
-
/** Hide the MongoDB version badge (it is also hidden while the server cannot tell, e.g. before login
|
|
2
|
+
/** Hide the MongoDB version badge (it is also hidden while the server cannot tell, e.g. before login). */
|
|
3
3
|
hideDatabase?: boolean;
|
|
4
4
|
};
|
|
5
5
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
2
|
import { analysisSampleSize, analysisTimeoutMs } from "../utils/schemaAnalysis.js";
|
|
3
|
+
import { ignoringNotFound } from "../utils/serverError.js";
|
|
3
4
|
const REQUEST_TIMEOUT_MS = 15e3;
|
|
4
5
|
function withTimeout() {
|
|
5
6
|
return { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) };
|
|
@@ -20,7 +21,7 @@ export default () => {
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
async function deleteUser(userId) {
|
|
23
|
-
return adminApi.deleteUser({ userId });
|
|
24
|
+
return await ignoringNotFound(() => adminApi.deleteUser({ userId })) ?? { value: true };
|
|
24
25
|
}
|
|
25
26
|
async function updateUserRoles(userId, roles) {
|
|
26
27
|
return adminApi.updateRolesForUser({ userId, requestBody: roles });
|
|
@@ -47,20 +48,20 @@ export default () => {
|
|
|
47
48
|
return adminApi.updateRole({ roleName, updateRoleRequest: { isAdmin, collectionGrants } });
|
|
48
49
|
}
|
|
49
50
|
async function deleteRole(roleName) {
|
|
50
|
-
return adminApi.deleteRole({ roleName });
|
|
51
|
+
return await ignoringNotFound(() => adminApi.deleteRole({ roleName })) ?? { value: true };
|
|
51
52
|
}
|
|
52
53
|
async function clearCollection(collectionName) {
|
|
53
|
-
return collectionApi.clearCollection({ collectionName }, withTimeout());
|
|
54
|
+
return await ignoringNotFound(() => collectionApi.clearCollection({ collectionName }, withTimeout())) ?? { value: true };
|
|
54
55
|
}
|
|
55
56
|
async function deleteCollection(collectionName) {
|
|
56
|
-
return collectionApi.deleteCollection({ collectionName }, withTimeout());
|
|
57
|
+
return await ignoringNotFound(() => collectionApi.deleteCollection({ collectionName }, withTimeout())) ?? { value: true };
|
|
57
58
|
}
|
|
58
59
|
async function getJsonSchema(collectionName) {
|
|
59
60
|
return collectionApi.getJsonSchema({ collectionName }, withTimeout());
|
|
60
61
|
}
|
|
61
62
|
async function getSchemaAnalysis(collectionName, documents, depth = 3) {
|
|
62
63
|
const sampleSize = analysisSampleSize(documents);
|
|
63
|
-
return collectionApi.getSchemaAnalysis({ collectionName, sampleSize,
|
|
64
|
+
return collectionApi.getSchemaAnalysis({ collectionName, sampleSize, depth }, { signal: AbortSignal.timeout(analysisTimeoutMs(sampleSize)) });
|
|
64
65
|
}
|
|
65
66
|
async function getUser(userId) {
|
|
66
67
|
return adminApi.getUser({ userId }, withTimeout());
|
|
@@ -8,7 +8,9 @@ export interface AggregationOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* Lets the pipeline use `$collStats` / `$indexStats` (storage and index-usage numbers) — and nothing else from the
|
|
10
10
|
* deny-list. Their results carry the database server's address, so `host` and `ns` are removed from every row.
|
|
11
|
-
*
|
|
11
|
+
* The aggregation builder never sets it.
|
|
12
|
+
* @deprecated A stock MongoCamp 2.0 server refuses both stages (`AGGREGATION_STAGES_DENIED`); index usage comes from
|
|
13
|
+
* `useMongocampCollectionStats().getIndexUsage` (`GET …/index/stats`), storage numbers from `getStorage`.
|
|
12
14
|
*/
|
|
13
15
|
allowStatsStages?: boolean;
|
|
14
16
|
/**
|
|
@@ -17,6 +19,13 @@ export interface AggregationOptions {
|
|
|
17
19
|
* with a `FilterTooLongError` instead of becoming an opaque network failure.
|
|
18
20
|
*/
|
|
19
21
|
filter?: string;
|
|
22
|
+
/** Match the wildcards of `filter` without regard to case (server 2.0 matches them case-sensitively otherwise). */
|
|
23
|
+
filterCaseInsensitive?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Skip the count (`count=none`, server 2.0) when only the rows are needed: the server does less work, and `total` is then
|
|
26
|
+
* the number of rows returned, `pages` 1.
|
|
27
|
+
*/
|
|
28
|
+
skipCount?: boolean;
|
|
20
29
|
/** Aborting rejects the call (an `AbortError`); the 30 s timeout still applies. */
|
|
21
30
|
signal?: AbortSignal;
|
|
22
31
|
}
|
|
@@ -2,6 +2,7 @@ import { useMongocampClientApi, useI18n } from "#imports";
|
|
|
2
2
|
import { useMongocampError } from "./useMongocampError.js";
|
|
3
3
|
import { findForbidden, STATS_OPERATORS } from "../utils/aggregationPipeline.js";
|
|
4
4
|
import { FilterTooLongError, ForbiddenPipelineError } from "../utils/aggregationErrors.js";
|
|
5
|
+
import { sensitiveFieldReferences, sensitiveFieldsOf, sensitiveFieldsOfPipeline, withoutFieldsDeep } from "../utils/sensitiveFields.js";
|
|
5
6
|
import { fieldPathsOf } from "../utils/fieldDetails.js";
|
|
6
7
|
import { isFilterTooLong, MAX_ENCODED_FILTER_LENGTH } from "../utils/requestLimits.js";
|
|
7
8
|
import { stripServerFields } from "../utils/aggregationResult.js";
|
|
@@ -31,6 +32,11 @@ export function useMongocampAggregation() {
|
|
|
31
32
|
async function runAggregation(collectionName, pipeline, paging = {}, options = {}) {
|
|
32
33
|
const findings = findForbidden(pipeline, options.allowStatsStages ? STATS_OPERATORS : []);
|
|
33
34
|
if (findings.length > 0) throw new ForbiddenPipelineError(findings);
|
|
35
|
+
const hiddenFields = sensitiveFieldsOfPipeline(collectionName, pipeline);
|
|
36
|
+
const hiddenUses = sensitiveFieldReferences(pipeline, hiddenFields);
|
|
37
|
+
if (hiddenUses.length > 0) {
|
|
38
|
+
throw new ForbiddenPipelineError(hiddenUses.map((use) => ({ stageIndex: use.stageIndex, operator: use.reference, path: use.reference, sensitive: true })));
|
|
39
|
+
}
|
|
34
40
|
if (isFilterTooLong(options.filter)) throw new FilterTooLongError(MAX_ENCODED_FILTER_LENGTH);
|
|
35
41
|
const page = paging.page ?? 1;
|
|
36
42
|
const response = await collectionApi.aggregateRaw({
|
|
@@ -39,10 +45,13 @@ export function useMongocampAggregation() {
|
|
|
39
45
|
mongoAggregateRequest: { pipeline, allowDiskUse: false },
|
|
40
46
|
rowsPerPage: paging.rowsPerPage,
|
|
41
47
|
page,
|
|
42
|
-
filter: options.filter?.trim() ? options.filter : void 0
|
|
48
|
+
filter: options.filter?.trim() ? options.filter : void 0,
|
|
49
|
+
filterCaseInsensitive: options.filter?.trim() ? options.filterCaseInsensitive : void 0,
|
|
50
|
+
count: options.skipCount ? "none" : void 0,
|
|
51
|
+
extendedJson: "relaxed"
|
|
43
52
|
}, requestInit(AGGREGATE_TIMEOUT_MS, options.signal));
|
|
44
53
|
const value = await readJsonKeepingLongs(response);
|
|
45
|
-
const unwrapped = Array.isArray(value) ? value.filter(isPlainObject).map((row) => unwrapExtendedJson(row)) : [];
|
|
54
|
+
const unwrapped = (Array.isArray(value) ? value.filter(isPlainObject).map((row) => unwrapExtendedJson(row)) : []).map((row) => withoutFieldsDeep(row, hiddenFields));
|
|
46
55
|
const rows = options.allowStatsStages ? stripServerFields(unwrapped) : unwrapped;
|
|
47
56
|
const headers = response.raw?.headers;
|
|
48
57
|
return {
|
|
@@ -59,6 +68,7 @@ export function useMongocampAggregation() {
|
|
|
59
68
|
return fieldPathsOf(await listFieldDetails(collectionName));
|
|
60
69
|
}
|
|
61
70
|
async function listDistinct(collectionName, field, limit = DEFAULT_DISTINCT_LIMIT) {
|
|
71
|
+
if (sensitiveFieldsOf(collectionName).includes(field)) return { values: [], total: 0, truncated: false };
|
|
62
72
|
const response = await collectionApi.distinctRaw({ collectionName, field, rowsPerPage: limit, page: 1 }, withTimeout(REQUEST_TIMEOUT_MS));
|
|
63
73
|
const value = unwrapExtendedJson(await readJsonKeepingLongs(response));
|
|
64
74
|
const values = (Array.isArray(value) ? value : []).filter((v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean");
|
|
@@ -67,12 +77,14 @@ export function useMongocampAggregation() {
|
|
|
67
77
|
}
|
|
68
78
|
async function sampleDocuments(collectionName, size = DEFAULT_SAMPLE_SIZE) {
|
|
69
79
|
const clamped = Math.min(Math.max(Math.floor(size) || DEFAULT_SAMPLE_SIZE, 1), MAX_SAMPLE_SIZE);
|
|
70
|
-
return runAggregation(collectionName, [{ stage: "$sample", value: { size: clamped } }], { page: 1, rowsPerPage: clamped });
|
|
80
|
+
return runAggregation(collectionName, [{ stage: "$sample", value: { size: clamped } }], { page: 1, rowsPerPage: clamped }, { skipCount: true });
|
|
71
81
|
}
|
|
72
82
|
async function describeAggregationError(error) {
|
|
73
83
|
if (error instanceof FilterTooLongError) return { kind: "other", message: t("nuxtUiMongocamp.aggregation.errors.filterTooLong", { max: error.max }) };
|
|
74
84
|
if (error instanceof ForbiddenPipelineError) {
|
|
75
|
-
|
|
85
|
+
const first = error.findings[0];
|
|
86
|
+
if (first?.sensitive) return { kind: "forbidden", message: t("nuxtUiMongocamp.aggregation.errors.sensitiveField", { field: first.operator }) };
|
|
87
|
+
return { kind: "forbidden", message: t("nuxtUiMongocamp.aggregation.errors.forbidden", { operator: first?.operator ?? "" }) };
|
|
76
88
|
}
|
|
77
89
|
const server = await readServerError(error);
|
|
78
90
|
if (server.code === OPERATOR_NOT_ALLOWED_CODE) {
|
|
@@ -86,7 +98,7 @@ export function useMongocampAggregation() {
|
|
|
86
98
|
return { kind: server.kind ?? "other", message: server.message };
|
|
87
99
|
}
|
|
88
100
|
const described = describeError(error);
|
|
89
|
-
const kind = described.kind === "forbidden" ? "forbidden-access" : described.kind === "notAllowed" || described.kind === "invalid" ? "other" : described.kind;
|
|
101
|
+
const kind = described.kind === "forbidden" ? "forbidden-access" : described.kind === "notAllowed" || described.kind === "invalid" || described.kind === "notFound" ? "other" : described.kind;
|
|
90
102
|
return { kind, message: described.message };
|
|
91
103
|
}
|
|
92
104
|
return { runAggregation, listDistinct, listFieldNames, listFieldDetails, sampleDocuments, describeAggregationError };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { BucketInformation, FileInformation } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
2
|
export interface ListFilesOptions {
|
|
3
|
+
/**
|
|
4
|
+
* A MongoDB query as JSON text (`{"filename":{"$regex":"png","$options":"i"}}`, see `filenameFilter`) — **not Lucene**: the
|
|
5
|
+
* file list ignores a Lucene string and returns every file.
|
|
6
|
+
*/
|
|
3
7
|
filter?: string;
|
|
4
8
|
sort?: string;
|
|
5
9
|
projection?: string;
|
|
@@ -2,6 +2,7 @@ import { ref } from "vue";
|
|
|
2
2
|
import { useI18n, useMongocampClientApi, useToast } from "#imports";
|
|
3
3
|
import { BUCKET_COLLECTION_SUFFIX } from "../utils/collectionProtection.js";
|
|
4
4
|
import { isFilterTooLong, MAX_ENCODED_FILTER_LENGTH } from "../utils/requestLimits.js";
|
|
5
|
+
import { ignoringNotFound } from "../utils/serverError.js";
|
|
5
6
|
function unwrapId(value) {
|
|
6
7
|
if (typeof value === "string") return value;
|
|
7
8
|
if (typeof value === "object" && value !== null && "$oid" in value) {
|
|
@@ -110,9 +111,9 @@ export function useMongocampBucket() {
|
|
|
110
111
|
async function deleteFile(bucketName, fileId) {
|
|
111
112
|
fileActionInFlight.value.add(fileId);
|
|
112
113
|
try {
|
|
113
|
-
const result = await fileApi.deleteFile({ bucketName, fileId });
|
|
114
|
+
const result = await ignoringNotFound(() => fileApi.deleteFile({ bucketName, fileId }));
|
|
114
115
|
toast.add({ title: t("nuxtUiMongocamp.bucket.deletedTitle"), description: t("nuxtUiMongocamp.bucket.deletedDescription"), color: "success" });
|
|
115
|
-
return result.wasAcknowledged;
|
|
116
|
+
return result ? result.wasAcknowledged : true;
|
|
116
117
|
} catch (e) {
|
|
117
118
|
toast.add({ title: t("nuxtUiMongocamp.bucket.deleteFailedTitle"), description: e instanceof Error ? e.message : t("nuxtUiMongocamp.bucket.deleteFailedFallback"), color: "error" });
|
|
118
119
|
return false;
|
|
@@ -146,9 +147,9 @@ export function useMongocampBucket() {
|
|
|
146
147
|
async function clearBucket(bucketName) {
|
|
147
148
|
bucketActionInFlight.value.add(bucketName);
|
|
148
149
|
try {
|
|
149
|
-
const result = await bucketApi.clearBucket({ bucketName });
|
|
150
|
+
const result = await ignoringNotFound(() => bucketApi.clearBucket({ bucketName }));
|
|
150
151
|
toast.add({ title: t("nuxtUiMongocamp.bucket.bucketClearedTitle"), description: t("nuxtUiMongocamp.bucket.bucketClearedDescription", { bucketName }), color: "success" });
|
|
151
|
-
return result.value;
|
|
152
|
+
return result ? result.value : true;
|
|
152
153
|
} catch (e) {
|
|
153
154
|
toast.add({ title: t("nuxtUiMongocamp.bucket.clearFailedTitle"), description: e instanceof Error ? e.message : t("nuxtUiMongocamp.bucket.clearFailedFallback", { bucketName }), color: "error" });
|
|
154
155
|
return false;
|
|
@@ -159,9 +160,9 @@ export function useMongocampBucket() {
|
|
|
159
160
|
async function deleteBucket(bucketName) {
|
|
160
161
|
bucketActionInFlight.value.add(bucketName);
|
|
161
162
|
try {
|
|
162
|
-
const result = await bucketApi.deleteBucket({ bucketName });
|
|
163
|
+
const result = await ignoringNotFound(() => bucketApi.deleteBucket({ bucketName }));
|
|
163
164
|
toast.add({ title: t("nuxtUiMongocamp.bucket.bucketDeletedTitle"), description: t("nuxtUiMongocamp.bucket.bucketDeletedDescription", { bucketName }), color: "success" });
|
|
164
|
-
return result.value;
|
|
165
|
+
return result ? result.value : true;
|
|
165
166
|
} catch (e) {
|
|
166
167
|
toast.add({ title: t("nuxtUiMongocamp.bucket.deleteFailedTitle"), description: e instanceof Error ? e.message : t("nuxtUiMongocamp.bucket.deleteFailedBucketFallback", { bucketName }), color: "error" });
|
|
167
168
|
return false;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FilterCallOptions } from '../utils/caseInsensitive.js';
|
|
1
2
|
export interface BulkUpdateByFilterResult {
|
|
2
3
|
matched: number;
|
|
3
4
|
modified: number;
|
|
@@ -6,10 +7,11 @@ export interface BulkUpdateByFilterResult {
|
|
|
6
7
|
* Count, delete and update by the **Lucene filter** of the list — one request each (server 1.7.0): no ids are collected,
|
|
7
8
|
* so there is no cap, no id snapshot and nothing to chunk. An empty filter would touch the whole collection, which the
|
|
8
9
|
* server only does with `matchAll=true`; it is sent exactly when the filter is empty, so the caller's own confirmation
|
|
9
|
-
* (the typed collection name) is what guards that case.
|
|
10
|
+
* (the typed collection name) is what guards that case. The last argument is an `AbortSignal` or
|
|
11
|
+
* `{ signal, filterCaseInsensitive }` (server 2.0: wildcards match case-sensitively unless that flag is set). A filter the server cannot parse is answered 400 (nothing changes).
|
|
10
12
|
*/
|
|
11
13
|
export declare function useMongocampBulkByFilter(): {
|
|
12
|
-
countDocuments: (collectionName: string, filter?: string,
|
|
13
|
-
deleteByFilter: (collectionName: string, filter?: string,
|
|
14
|
-
updateByFilter: (collectionName: string, filter: string | undefined, document: Record<string, unknown>,
|
|
14
|
+
countDocuments: (collectionName: string, filter?: string, options?: AbortSignal | FilterCallOptions) => Promise<number>;
|
|
15
|
+
deleteByFilter: (collectionName: string, filter?: string, options?: AbortSignal | FilterCallOptions) => Promise<number>;
|
|
16
|
+
updateByFilter: (collectionName: string, filter: string | undefined, document: Record<string, unknown>, options?: AbortSignal | FilterCallOptions) => Promise<BulkUpdateByFilterResult>;
|
|
15
17
|
};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
|
+
import { filterCallOptions } from "../utils/caseInsensitive.js";
|
|
2
3
|
export function useMongocampBulkByFilter() {
|
|
3
4
|
const { documentApi } = useMongocampClientApi();
|
|
4
5
|
const clean = (filter) => filter && filter.trim() !== "" ? filter : void 0;
|
|
5
|
-
async function countDocuments(collectionName, filter,
|
|
6
|
-
const
|
|
6
|
+
async function countDocuments(collectionName, filter, options) {
|
|
7
|
+
const { signal, filterCaseInsensitive } = filterCallOptions(options);
|
|
8
|
+
const response = await documentApi.countDocuments({ collectionName, filter: clean(filter), filterCaseInsensitive }, signal ? { signal } : void 0);
|
|
7
9
|
return response.count;
|
|
8
10
|
}
|
|
9
|
-
async function deleteByFilter(collectionName, filter,
|
|
11
|
+
async function deleteByFilter(collectionName, filter, options) {
|
|
12
|
+
const { signal, filterCaseInsensitive } = filterCallOptions(options);
|
|
10
13
|
const lucene = clean(filter);
|
|
11
14
|
const response = await documentApi.deleteMany(
|
|
12
|
-
{ collectionName, requestBody: {}, filter: lucene, matchAll: lucene === void 0 ? true : void 0 },
|
|
15
|
+
{ collectionName, requestBody: {}, filter: lucene, matchAll: lucene === void 0 ? true : void 0, filterCaseInsensitive },
|
|
13
16
|
signal ? { signal } : void 0
|
|
14
17
|
);
|
|
15
18
|
return response.deletedCount;
|
|
16
19
|
}
|
|
17
|
-
async function updateByFilter(collectionName, filter, document,
|
|
20
|
+
async function updateByFilter(collectionName, filter, document, options) {
|
|
21
|
+
const { signal, filterCaseInsensitive } = filterCallOptions(options);
|
|
18
22
|
const lucene = clean(filter);
|
|
19
23
|
const response = await documentApi.updateMany(
|
|
20
24
|
{
|
|
@@ -22,7 +26,8 @@ export function useMongocampBulkByFilter() {
|
|
|
22
26
|
// the generated type says string values only; the server takes any JSON value
|
|
23
27
|
updateRequest: { filter: {}, document },
|
|
24
28
|
filter: lucene,
|
|
25
|
-
matchAll: lucene === void 0 ? true : void 0
|
|
29
|
+
matchAll: lucene === void 0 ? true : void 0,
|
|
30
|
+
filterCaseInsensitive
|
|
26
31
|
},
|
|
27
32
|
signal ? { signal } : void 0
|
|
28
33
|
);
|
|
@@ -3,6 +3,8 @@ export interface CopyOptions {
|
|
|
3
3
|
target: string;
|
|
4
4
|
/** Lucene filter: copy only the documents that match. */
|
|
5
5
|
filter?: string;
|
|
6
|
+
/** Match the wildcards of `filter` without regard to case (server 2.0 matches them case-sensitively otherwise). */
|
|
7
|
+
filterCaseInsensitive?: boolean;
|
|
6
8
|
/** Create the same indexes on the new collection (the server reproduces them from the real index specifications). */
|
|
7
9
|
withIndexes?: boolean;
|
|
8
10
|
signal?: AbortSignal;
|
|
@@ -41,5 +43,5 @@ export declare function useMongocampCollectionCopy(): {
|
|
|
41
43
|
backupCollection: (options: BackupOptions) => Promise<CopyResult>;
|
|
42
44
|
renameCollection: (source: string, target: string, signal?: AbortSignal) => Promise<RenameResult>;
|
|
43
45
|
listCollectionNames: () => Promise<string[]>;
|
|
44
|
-
countDocuments: (collectionName: string, filter?: string,
|
|
46
|
+
countDocuments: (collectionName: string, filter?: string, options?: AbortSignal | import("../utils/caseInsensitive.js").FilterCallOptions) => Promise<number>;
|
|
45
47
|
};
|
|
@@ -11,11 +11,13 @@ export function useMongocampCollectionCopy() {
|
|
|
11
11
|
return await collectionApi.listCollections();
|
|
12
12
|
}
|
|
13
13
|
async function copyCollection(options) {
|
|
14
|
-
const { source, target, filter, withIndexes, signal } = options;
|
|
14
|
+
const { source, target, filter, filterCaseInsensitive, withIndexes, signal } = options;
|
|
15
|
+
const lucene = filter?.trim() ? filter : void 0;
|
|
15
16
|
try {
|
|
16
17
|
const response = await collectionApi.copyCollection({
|
|
17
18
|
collectionName: source,
|
|
18
|
-
copyRequest: { target, filter:
|
|
19
|
+
copyRequest: { target, filter: lucene, withIndexes: withIndexes ?? false },
|
|
20
|
+
filterCaseInsensitive: lucene ? filterCaseInsensitive : void 0
|
|
19
21
|
}, signal ? { signal } : void 0);
|
|
20
22
|
return { target: response.name, count: response.count, indexes: response.indexes };
|
|
21
23
|
} catch (error) {
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
2
|
import { mapIndexUsage, mapStorage } from "../utils/collectionStats.js";
|
|
3
|
-
import { useMongocampAggregation } from "./useMongocampAggregation.js";
|
|
4
3
|
const REQUEST_TIMEOUT_MS = 15e3;
|
|
5
4
|
export function useMongocampCollectionStats() {
|
|
6
|
-
const { collectionApi } = useMongocampClientApi();
|
|
7
|
-
const { runAggregation } = useMongocampAggregation();
|
|
5
|
+
const { collectionApi, indexApi } = useMongocampClientApi();
|
|
8
6
|
async function getStorage(collection) {
|
|
9
7
|
const status = await collectionApi.getCollectionInformation({ collectionName: collection }, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
10
8
|
return mapStorage(status);
|
|
11
9
|
}
|
|
12
10
|
async function getIndexUsage(collection) {
|
|
13
|
-
const
|
|
11
|
+
const rows = await indexApi.indexStats({ collectionName: collection }, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
14
12
|
return mapIndexUsage(rows);
|
|
15
13
|
}
|
|
16
14
|
return { getStorage, getIndexUsage };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type MongocampErrorKind = 'network' | 'unauthorized' | 'forbidden' | 'notAllowed' | 'invalid' | 'other';
|
|
1
|
+
export type MongocampErrorKind = 'network' | 'unauthorized' | 'forbidden' | 'notAllowed' | 'invalid' | 'notFound' | 'other';
|
|
2
2
|
export interface DescribedError {
|
|
3
3
|
kind: MongocampErrorKind;
|
|
4
4
|
message: string;
|
|
@@ -14,6 +14,9 @@ export function useMongocampError() {
|
|
|
14
14
|
if (status === 403) {
|
|
15
15
|
return { kind: "forbidden", message: t("nuxtUiMongocamp.errors.forbidden") };
|
|
16
16
|
}
|
|
17
|
+
if (status === 404) {
|
|
18
|
+
return { kind: "notFound", message: t("nuxtUiMongocamp.errors.notFound") };
|
|
19
|
+
}
|
|
17
20
|
const message = error instanceof Error && error.message ? error.message : t(fallbackKey ?? "nuxtUiMongocamp.errors.generic");
|
|
18
21
|
return { kind: "other", message };
|
|
19
22
|
}
|
|
@@ -27,7 +30,7 @@ export function useMongocampError() {
|
|
|
27
30
|
}
|
|
28
31
|
if (base.kind === "forbidden") return base;
|
|
29
32
|
if (server.message && server.status !== void 0 && server.status >= 400) {
|
|
30
|
-
return { kind: server.status === 400 ? "invalid" : "other", message: server.message };
|
|
33
|
+
return { kind: server.status === 400 ? "invalid" : server.status === 404 ? "notFound" : "other", message: server.message };
|
|
31
34
|
}
|
|
32
35
|
return base;
|
|
33
36
|
}
|
|
@@ -4,6 +4,8 @@ export interface ExportCollectionOptions {
|
|
|
4
4
|
format: ExportFormat;
|
|
5
5
|
/** Lucene filter: export only the documents that match (the current filter of a table). It travels in the URL: over ~1 800 encoded characters it throws `FilterTooLongError`. */
|
|
6
6
|
filter?: string;
|
|
7
|
+
/** Match the wildcards of `filter` without regard to case (server 2.0 matches them case-sensitively otherwise). */
|
|
8
|
+
filterCaseInsensitive?: boolean;
|
|
7
9
|
sort?: string[];
|
|
8
10
|
/** Limit the fields; for a CSV they are also its columns, in this order (default: the fields of the first 1 000 documents). */
|
|
9
11
|
projection?: string[];
|
|
@@ -11,6 +13,12 @@ export interface ExportCollectionOptions {
|
|
|
11
13
|
columns?: string[];
|
|
12
14
|
/** Stop after this many documents (`limit`); default: all. */
|
|
13
15
|
maxRows?: number;
|
|
16
|
+
/**
|
|
17
|
+
* JSON/NDJSON only: `relaxed` (default) is readable and keeps ids, dates, big integers, decimals and date-like text, but a
|
|
18
|
+
* re-import stores every whole number as Int64; `canonical` wraps every number too, so a re-import keeps Int32/Int64/Double
|
|
19
|
+
* exactly (larger files). Ignored for CSV, which stays plain.
|
|
20
|
+
*/
|
|
21
|
+
extendedJson?: 'relaxed' | 'canonical';
|
|
14
22
|
/** How many documents the caller expects (the count of the filter): a file with fewer is reported as `incomplete`. */
|
|
15
23
|
expected?: number;
|
|
16
24
|
/** After every chunk of the stream. */
|
|
@@ -45,7 +53,8 @@ export interface ExportResult {
|
|
|
45
53
|
/**
|
|
46
54
|
* Exports a whole collection, or every document matching a filter, as JSON, NDJSON or CSV — not just the rows on screen.
|
|
47
55
|
* The server streams the file (`GET …/documents/export`, server 1.8.1): there is no document cap and the browser never parses
|
|
48
|
-
* a document.
|
|
56
|
+
* a document. JSON and NDJSON files are relaxed Extended JSON (`{ "$oid" }`, `{ "$date" }`, `{ "$numberLong" }`, …), so they go
|
|
57
|
+
* back in through the importer with every type; CSV stays plain text (an integer beyond 2^53 keeps every digit).
|
|
49
58
|
* The file ends up in a `Blob` (the browser may keep it on disk) and is handed to the browser as a download.
|
|
50
59
|
*/
|
|
51
60
|
export declare function useMongocampExportAll(): {
|
|
@@ -26,9 +26,12 @@ export function useMongocampExportAll() {
|
|
|
26
26
|
collectionName: collection,
|
|
27
27
|
format,
|
|
28
28
|
filter: options.filter?.trim() ? options.filter : void 0,
|
|
29
|
+
filterCaseInsensitive: options.filter?.trim() ? options.filterCaseInsensitive : void 0,
|
|
29
30
|
sort: options.sort?.length ? options.sort : void 0,
|
|
30
31
|
projection,
|
|
31
|
-
limit: options.maxRows
|
|
32
|
+
limit: options.maxRows,
|
|
33
|
+
// CSV is plain unless a format is asked for; the JSON formats keep their types
|
|
34
|
+
extendedJson: format === "csv" ? void 0 : options.extendedJson ?? "relaxed"
|
|
32
35
|
}, options.signal ? { signal: options.signal } : void 0);
|
|
33
36
|
const mimeType = EXPORT_MIME_TYPES[format];
|
|
34
37
|
const { stream, state } = countingStream(options.onProgress);
|
|
@@ -2,22 +2,28 @@ import type { FetchAllOptions, FetchAllResult } from '../utils/pagedFetch.js';
|
|
|
2
2
|
export interface FetchAllDocumentsOptions<T> extends FetchAllOptions<T> {
|
|
3
3
|
/** Lucene filter, as for the document list. */
|
|
4
4
|
filter?: string;
|
|
5
|
+
/** Match the wildcards of `filter` without regard to case (server 2.0 matches them case-sensitively otherwise). */
|
|
6
|
+
filterCaseInsensitive?: boolean;
|
|
5
7
|
/** Sort keys as the document list takes them (`['name', '-age']`). Without one the server's natural order is used. */
|
|
6
8
|
sort?: string[];
|
|
7
9
|
/** Fields to return; `['_id']` is the cheap way to collect ids. */
|
|
8
10
|
projection?: string[];
|
|
9
11
|
}
|
|
10
12
|
export interface FetchAllFilesOptions<T> extends FetchAllOptions<T> {
|
|
13
|
+
/** A MongoDB query as JSON text (not Lucene — the file list ignores Lucene), e.g. from `filenameFilter`. */
|
|
11
14
|
filter?: string;
|
|
12
15
|
sort?: string;
|
|
13
16
|
projection?: string;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
|
-
* Reads every document of a collection (or of a Lucene filter) page by page
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* Reads every document of a collection (or of a Lucene filter) page by page, following the server's cursor
|
|
20
|
+
* (`fetchAllByCursor`, server 2.0): every page costs the same, and documents added or removed while reading do not make the
|
|
21
|
+
* others missing or repeated (verified: 25 000 documents read during concurrent inserts, none lost or doubled). The
|
|
22
|
+
* rows are relaxed Extended JSON, as the server sends them — `_id` `{ $oid }`, dates `{ $date }`, integers beyond 2^53
|
|
23
|
+
* `{ $numberLong }`, decimals, date-looking text `{ $string }` (`idOf` / `unwrapExtendedJson` give plain values) — and the
|
|
24
|
+
* total comes from the first page's pagination header (later pages skip the count).
|
|
25
|
+
* Capped at 10 000 rows by default (`maxRows` raises it); see `utils/pagedFetch.ts` for stopping, progress and abort.
|
|
26
|
+
* Every page has its own 60 s timeout.
|
|
21
27
|
*/
|
|
22
28
|
export declare function useMongocampFetchAll(): {
|
|
23
29
|
fetchAllDocuments: <T = Record<string, unknown>>(collectionName: string, options?: FetchAllDocumentsOptions<T>) => Promise<FetchAllResult<T>>;
|