@sfxcode/nuxt-ui-mongocamp 1.4.0 → 1.5.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 +1 -1
- package/dist/module.json +1 -1
- 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/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/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/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/locales/de.json +69 -71
- package/dist/runtime/locales/en.json +69 -71
- 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/package.json +8 -8
- 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
|
@@ -4,9 +4,15 @@ export interface BatchInsertFailure {
|
|
|
4
4
|
error: unknown;
|
|
5
5
|
mayBePartial: boolean;
|
|
6
6
|
}
|
|
7
|
+
export interface BatchInsertRowError {
|
|
8
|
+
index: number;
|
|
9
|
+
code?: number;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
7
12
|
export interface BatchInsertResult {
|
|
8
13
|
inserted: number;
|
|
9
14
|
failedBatches: BatchInsertFailure[];
|
|
15
|
+
rowErrors: BatchInsertRowError[];
|
|
10
16
|
skipped: number;
|
|
11
17
|
aborted: boolean;
|
|
12
18
|
}
|
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
const DEFAULT_BATCH_SIZE = 1e3;
|
|
2
2
|
const MAX_BATCH_SIZE = 1e4;
|
|
3
|
+
function rowErrorsAsFailures(rowErrors) {
|
|
4
|
+
const failures = [];
|
|
5
|
+
for (const e of [...rowErrors].sort((a, b) => a.index - b.index)) {
|
|
6
|
+
const last = failures.at(-1);
|
|
7
|
+
const lastMessage = last?.error?.message;
|
|
8
|
+
if (last && last.start + last.count === e.index && lastMessage === e.message) {
|
|
9
|
+
last.count++;
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
failures.push({ start: e.index, count: 1, error: Object.assign(new Error(e.message), { code: e.code }), mayBePartial: false });
|
|
13
|
+
}
|
|
14
|
+
return failures;
|
|
15
|
+
}
|
|
16
|
+
function readSummary(value) {
|
|
17
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
18
|
+
const { insertedCount, errors } = value;
|
|
19
|
+
if (typeof insertedCount !== "number") return void 0;
|
|
20
|
+
const list = Array.isArray(errors) ? errors : [];
|
|
21
|
+
return {
|
|
22
|
+
insertedCount,
|
|
23
|
+
errors: list.flatMap((e) => {
|
|
24
|
+
const { index, code, message } = e ?? {};
|
|
25
|
+
return typeof index === "number" ? [{ index, code: typeof code === "number" ? code : void 0, message: typeof message === "string" ? message : "" }] : [];
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
}
|
|
3
29
|
export async function runBatchInsert(rows, insert, options = {}) {
|
|
4
30
|
const batchSize = Math.min(Math.max(Math.floor(options.batchSize ?? DEFAULT_BATCH_SIZE) || DEFAULT_BATCH_SIZE, 1), MAX_BATCH_SIZE);
|
|
5
|
-
const result = { inserted: 0, failedBatches: [], skipped: 0, aborted: false };
|
|
31
|
+
const result = { inserted: 0, failedBatches: [], rowErrors: [], skipped: 0, aborted: false };
|
|
6
32
|
let done = 0;
|
|
7
33
|
for (let start = 0; start < rows.length; start += batchSize) {
|
|
8
34
|
if (options.signal?.aborted) {
|
|
@@ -12,13 +38,15 @@ export async function runBatchInsert(rows, insert, options = {}) {
|
|
|
12
38
|
}
|
|
13
39
|
const batch = rows.slice(start, start + batchSize);
|
|
14
40
|
try {
|
|
15
|
-
await insert(batch);
|
|
16
|
-
result.inserted += batch.length;
|
|
41
|
+
const summary = readSummary(await insert(batch));
|
|
42
|
+
result.inserted += summary ? summary.insertedCount : batch.length;
|
|
43
|
+
for (const e of summary?.errors ?? []) result.rowErrors.push({ index: start + e.index, code: e.code, message: e.message });
|
|
17
44
|
} catch (error) {
|
|
18
45
|
result.failedBatches.push({ start, count: batch.length, error, mayBePartial: !(options.isAtomicFailure?.(error) ?? false) });
|
|
19
46
|
}
|
|
20
47
|
done += batch.length;
|
|
21
48
|
options.onProgress?.({ done, total: rows.length });
|
|
22
49
|
}
|
|
50
|
+
if (result.rowErrors.length > 0) result.failedBatches = [...result.failedBatches, ...rowErrorsAsFailures(result.rowErrors)].sort((a, b) => a.start - b.start);
|
|
23
51
|
return result;
|
|
24
52
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BsonType = 'string' | 'int' | 'long' | 'double' | 'decimal' | 'bool' | 'date' | 'objectId' | 'null';
|
|
2
|
+
/** Dotted path of a field → the type to write it as (array elements as `tags[]`). */
|
|
3
|
+
export type TypeHints = Record<string, BsonType>;
|
|
4
|
+
export declare const BSON_TYPES: readonly BsonType[];
|
|
5
|
+
/**
|
|
6
|
+
* `value` written as `type`. A value that does not fit the type (2.5 as an int, text that is no id as an objectId, a long
|
|
7
|
+
* beyond 2^53 given as a number) is returned **unchanged** — the server then picks the type, which is what a plain value
|
|
8
|
+
* would have got anyway. Never throws.
|
|
9
|
+
*/
|
|
10
|
+
export declare function wireValue(type: BsonType, value: unknown): unknown;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const BSON_TYPES = ["string", "int", "long", "double", "decimal", "bool", "date", "objectId", "null"];
|
|
2
|
+
const INT32_MIN = -(2 ** 31);
|
|
3
|
+
const INT32_MAX = 2 ** 31 - 1;
|
|
4
|
+
const INTEGER_TEXT = /^-?\d+$/;
|
|
5
|
+
const DECIMAL_TEXT = /^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;
|
|
6
|
+
const OBJECT_ID_TEXT = /^[0-9a-f]{24}$/i;
|
|
7
|
+
const FULL_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
8
|
+
const isFullTimestamp = (value) => FULL_TIMESTAMP.test(value) && !Number.isNaN(Date.parse(value));
|
|
9
|
+
function toNumber(value) {
|
|
10
|
+
const n = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : Number.NaN;
|
|
11
|
+
return Number.isFinite(n) ? n : void 0;
|
|
12
|
+
}
|
|
13
|
+
export function wireValue(type, value) {
|
|
14
|
+
switch (type) {
|
|
15
|
+
case "int": {
|
|
16
|
+
const n = toNumber(value);
|
|
17
|
+
return n !== void 0 && Number.isInteger(n) && n >= INT32_MIN && n <= INT32_MAX ? { $numberInt: String(n) } : value;
|
|
18
|
+
}
|
|
19
|
+
case "long": {
|
|
20
|
+
if (typeof value === "string" && INTEGER_TEXT.test(value.trim())) return { $numberLong: value.trim() };
|
|
21
|
+
const n = toNumber(value);
|
|
22
|
+
return n !== void 0 && Number.isSafeInteger(n) ? { $numberLong: String(n) } : value;
|
|
23
|
+
}
|
|
24
|
+
case "double": {
|
|
25
|
+
const n = toNumber(value);
|
|
26
|
+
return n !== void 0 ? { $numberDouble: String(n) } : value;
|
|
27
|
+
}
|
|
28
|
+
case "decimal": {
|
|
29
|
+
if (typeof value === "string" && DECIMAL_TEXT.test(value.trim())) return { $numberDecimal: value.trim() };
|
|
30
|
+
const n = toNumber(value);
|
|
31
|
+
return n !== void 0 ? { $numberDecimal: String(n) } : value;
|
|
32
|
+
}
|
|
33
|
+
case "date":
|
|
34
|
+
return typeof value === "string" && isFullTimestamp(value) ? { $date: value } : value;
|
|
35
|
+
case "objectId":
|
|
36
|
+
return typeof value === "string" && OBJECT_ID_TEXT.test(value) ? { $oid: value } : value;
|
|
37
|
+
case "string":
|
|
38
|
+
return typeof value === "string" && isFullTimestamp(value) ? { $string: value } : value;
|
|
39
|
+
default:
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** More documents than this are not copied through the browser (everything is held in memory while copying). */
|
|
2
|
-
export declare const MAX_COPY_DOCUMENTS = 50000;
|
|
3
1
|
export declare const MAX_COLLECTION_NAME_LENGTH = 100;
|
|
4
2
|
export type TargetNameProblem = 'empty' | 'too-long' | 'invalid-characters' | 'protected' | 'same-as-source' | 'exists';
|
|
5
3
|
/**
|
|
@@ -9,3 +9,10 @@ export interface ConfigRow {
|
|
|
9
9
|
}
|
|
10
10
|
export declare function isSecretConfigKey(key: string): boolean;
|
|
11
11
|
export declare function buildConfigRows(configurations: unknown): ConfigRow[];
|
|
12
|
+
export declare const GRANT_STATUS_KEY = "AUTH_GRANT_DENIED_STATUS";
|
|
13
|
+
/**
|
|
14
|
+
* Whether the server still answers a missing grant with `401` (its default; `403` is planned for the next major version): a
|
|
15
|
+
* generated client clears the session on a 401, which this module works around by turning that 401 into a 403 itself. `false`
|
|
16
|
+
* when the setting is `403`, absent (an older server) or unreadable.
|
|
17
|
+
*/
|
|
18
|
+
export declare function grantStatusHint(rows: readonly ConfigRow[]): boolean;
|
|
@@ -51,3 +51,7 @@ export function buildConfigRows(configurations) {
|
|
|
51
51
|
}
|
|
52
52
|
return rows.sort((a, b) => a.key.localeCompare(b.key));
|
|
53
53
|
}
|
|
54
|
+
export const GRANT_STATUS_KEY = "AUTH_GRANT_DENIED_STATUS";
|
|
55
|
+
export function grantStatusHint(rows) {
|
|
56
|
+
return rows.find((row) => row.key === GRANT_STATUS_KEY)?.value.trim() === "401";
|
|
57
|
+
}
|
|
@@ -8,9 +8,10 @@ export function plainValue(value) {
|
|
|
8
8
|
}
|
|
9
9
|
const WRAPPED_AS_TEXT = /* @__PURE__ */ new Set(["objectId", "date", "long", "decimal"]);
|
|
10
10
|
const NUMERIC = /* @__PURE__ */ new Set(["number", "int", "long", "double", "decimal"]);
|
|
11
|
+
const EXACT_NUMERIC = /* @__PURE__ */ new Set(["int", "long", "double", "decimal"]);
|
|
11
12
|
function typesAgree(a, b) {
|
|
12
13
|
if (a === b) return true;
|
|
13
|
-
if (NUMERIC.has(a) && NUMERIC.has(b)) return
|
|
14
|
+
if (NUMERIC.has(a) && NUMERIC.has(b)) return !(EXACT_NUMERIC.has(a) && EXACT_NUMERIC.has(b));
|
|
14
15
|
return a === "string" && WRAPPED_AS_TEXT.has(b) || b === "string" && WRAPPED_AS_TEXT.has(a);
|
|
15
16
|
}
|
|
16
17
|
function leafEqual(a, b) {
|
|
@@ -10,21 +10,18 @@ export interface FlattenOptions {
|
|
|
10
10
|
maxDepth?: number;
|
|
11
11
|
/** Stops after this many entries (default 10 000); `truncated` tells. */
|
|
12
12
|
maxEntries?: number;
|
|
13
|
-
/** Type a 24-hex string as `objectId` and a full ISO timestamp as `date` (see `typeOf`). Default off. */
|
|
14
|
-
inferStrings?: boolean;
|
|
15
13
|
}
|
|
16
14
|
export interface FlattenResult {
|
|
17
15
|
entries: FlatEntry[];
|
|
18
16
|
truncated: boolean;
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
|
-
* What a value is, with extended-JSON wrappers recognised as their BSON type.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* What a value is, with extended-JSON wrappers recognised as their BSON type. Read a document with `extendedJson=canonical`
|
|
20
|
+
* (server 1.8.1) to get the types: `_id` and nested ids are `{ $oid }`, dates `{ $date }`, numbers `{ $numberInt }` /
|
|
21
|
+
* `{ $numberLong }` / `{ $numberDouble }` / `{ $numberDecimal }`, date-looking text `{ $string }`. A document read as plain
|
|
22
|
+
* JSON has no wrappers (ids and dates are strings) and is typed as what JSON says — the module no longer guesses.
|
|
24
23
|
*/
|
|
25
|
-
export declare function typeOf(value: unknown
|
|
26
|
-
inferStrings?: boolean;
|
|
27
|
-
}): PathValueType;
|
|
24
|
+
export declare function typeOf(value: unknown): PathValueType;
|
|
28
25
|
/** Splits a path at its unescaped dots; `''` is the empty path (no segments). */
|
|
29
26
|
export declare function splitPath(path: string): string[];
|
|
30
27
|
export declare function joinPath(segments: Array<string | number>): string;
|
|
@@ -10,24 +10,20 @@ const WRAPPER_TYPES = {
|
|
|
10
10
|
$numberLong: "long",
|
|
11
11
|
$numberInt: "int",
|
|
12
12
|
$numberDouble: "double",
|
|
13
|
-
$numberDecimal: "decimal"
|
|
13
|
+
$numberDecimal: "decimal",
|
|
14
|
+
// text that looks like a date, marked as text by the server in a typed read
|
|
15
|
+
$string: "string"
|
|
14
16
|
};
|
|
15
17
|
function wrapperType(value) {
|
|
16
18
|
const keys = Object.keys(value);
|
|
17
19
|
return keys.length === 1 ? WRAPPER_TYPES[keys[0]] : void 0;
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
const FULL_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
21
|
-
export function typeOf(value, options = {}) {
|
|
21
|
+
export function typeOf(value) {
|
|
22
22
|
if (value === null || value === void 0) return "null";
|
|
23
23
|
if (Array.isArray(value)) return "array";
|
|
24
24
|
if (value instanceof Date) return "date";
|
|
25
25
|
switch (typeof value) {
|
|
26
26
|
case "string":
|
|
27
|
-
if (options.inferStrings) {
|
|
28
|
-
if (OBJECT_ID_TEXT.test(value)) return "objectId";
|
|
29
|
-
if (FULL_TIMESTAMP.test(value) && !Number.isNaN(Date.parse(value))) return "date";
|
|
30
|
-
}
|
|
31
27
|
return "string";
|
|
32
28
|
case "boolean":
|
|
33
29
|
return "boolean";
|
|
@@ -68,12 +64,11 @@ export function joinPath(segments) {
|
|
|
68
64
|
export function flattenDocument(doc, options = {}) {
|
|
69
65
|
const maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
70
66
|
const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
71
|
-
const inferStrings = options.inferStrings ?? false;
|
|
72
67
|
const entries = [];
|
|
73
68
|
let truncated = false;
|
|
74
69
|
const visit = (value, segments, depth) => {
|
|
75
70
|
if (truncated) return;
|
|
76
|
-
const type = typeOf(value
|
|
71
|
+
const type = typeOf(value);
|
|
77
72
|
const container = type === "object" || type === "array";
|
|
78
73
|
const children = container ? Array.isArray(value) ? value.map((v, i) => [String(i), v]) : Object.entries(value) : [];
|
|
79
74
|
if (!container || children.length === 0 || depth >= maxDepth) {
|
|
@@ -75,13 +75,21 @@ export function visibleNodes(tree, expanded) {
|
|
|
75
75
|
walk(tree.nodes);
|
|
76
76
|
return out;
|
|
77
77
|
}
|
|
78
|
+
function canonicalDateToIso(raw) {
|
|
79
|
+
const ms = typeof raw === "object" && raw !== null ? raw.$numberLong : void 0;
|
|
80
|
+
if (typeof ms === "string" && /^-?\d+$/.test(ms)) {
|
|
81
|
+
const date = new Date(Number(ms));
|
|
82
|
+
if (!Number.isNaN(date.getTime())) return date.toISOString();
|
|
83
|
+
}
|
|
84
|
+
return raw;
|
|
85
|
+
}
|
|
78
86
|
export function nodeDisplay(node) {
|
|
79
87
|
const { value, type } = node;
|
|
80
88
|
if (type === "null") return { text: "null" };
|
|
81
89
|
if (type === "array") return { text: `[${value.length}]` };
|
|
82
90
|
if (type === "object") return { text: `{${Object.keys(value).length}}` };
|
|
83
91
|
if (type === "date") {
|
|
84
|
-
const raw = value instanceof Date ? value.toISOString() : value.$date;
|
|
92
|
+
const raw = value instanceof Date ? value.toISOString() : canonicalDateToIso(value.$date);
|
|
85
93
|
const text = typeof raw === "string" ? raw : JSON.stringify(raw);
|
|
86
94
|
const parsed = typeof raw === "string" ? new Date(raw) : void 0;
|
|
87
95
|
return parsed && !Number.isNaN(parsed.getTime()) ? { text, title: parsed.toLocaleString() } : { text };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export type ExportFormat = 'json' | 'ndjson' | 'csv';
|
|
2
2
|
export declare const EXPORT_MIME_TYPES: Record<ExportFormat, string>;
|
|
3
|
-
/** More documents than this are not read into one browser file unless the caller raises the cap on purpose. */
|
|
4
|
-
export declare const DEFAULT_EXPORT_MAX_ROWS = 50000;
|
|
5
3
|
/**
|
|
6
4
|
* One document as it is written to a file: extended-JSON wrappers become plain values (`$oid` → text, `$date` → ISO text,
|
|
7
5
|
* `$numberInt` → number), and an integer beyond 2^53 is kept exact as a BigInt (a bare number in JSON, digits in CSV).
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function rowsToCsv(rows: Record<string, unknown>[], keys: string[]): string;
|
|
2
|
+
/** Hands a Blob to the browser as a download. */
|
|
3
|
+
export declare function downloadBlob(filename: string, blob: Blob): void;
|
|
2
4
|
export declare function downloadTextFile(filename: string, content: string, mimeType: string): void;
|
|
@@ -8,11 +8,14 @@ export function rowsToCsv(rows, keys) {
|
|
|
8
8
|
for (const row of rows) lines.push(keys.map((key) => csvCell(row[key])).join(","));
|
|
9
9
|
return lines.join("\r\n");
|
|
10
10
|
}
|
|
11
|
-
export function
|
|
12
|
-
const url = URL.createObjectURL(
|
|
11
|
+
export function downloadBlob(filename, blob) {
|
|
12
|
+
const url = URL.createObjectURL(blob);
|
|
13
13
|
const link = document.createElement("a");
|
|
14
14
|
link.href = url;
|
|
15
15
|
link.download = filename;
|
|
16
16
|
link.click();
|
|
17
17
|
URL.revokeObjectURL(url);
|
|
18
18
|
}
|
|
19
|
+
export function downloadTextFile(filename, content, mimeType) {
|
|
20
|
+
downloadBlob(filename, new Blob([content], { type: `${mimeType};charset=utf-8` }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ValueKind } from './analyzeSamples.js';
|
|
2
|
+
import type { BsonType, TypeHints } from './bsonTypes.js';
|
|
3
|
+
import type { FilterFieldType } from './filterBuilder.js';
|
|
4
|
+
import type { ImportColumnType } from './importRows.js';
|
|
5
|
+
export interface FieldDetail {
|
|
6
|
+
path: string;
|
|
7
|
+
types?: Array<{
|
|
8
|
+
type: string;
|
|
9
|
+
count: number;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The value kind a `$type` name stands for: the numeric types are `number`, `bool` is `boolean`, an `objectId` is shown as
|
|
14
|
+
* text (its values are hex ids), `null` stays `null`. Anything else (`binData`, `regex`, `timestamp`, …) has no chart or
|
|
15
|
+
* filter of its own and gives `undefined`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function valueKindOfType(type: string): ValueKind | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The most frequent kind of one field, ignoring `null` and types without a kind (several `$type` names of one kind add up —
|
|
20
|
+
* `int` and `long` are both numbers). `undefined` for a field the sample did not contain or that only held nulls.
|
|
21
|
+
*/
|
|
22
|
+
export declare function dominantKindOfField(details: readonly FieldDetail[], path: string): ValueKind | undefined;
|
|
23
|
+
/** The paths a pipeline stage can name, sorted: the elements of arrays (`tags[]`) are not a path one can type. */
|
|
24
|
+
export declare function fieldPathsOf(details: readonly FieldDetail[]): string[];
|
|
25
|
+
/** What one path of a collection holds, from the server's sample. */
|
|
26
|
+
export interface FieldTypeInfo {
|
|
27
|
+
path: string;
|
|
28
|
+
/** The scalar BSON types found (never `null`), most frequent first; empty for a path that only holds objects/arrays/nulls. */
|
|
29
|
+
types: BsonType[];
|
|
30
|
+
/** The most frequent scalar type. */
|
|
31
|
+
dominant?: BsonType;
|
|
32
|
+
/** `object` / `array` when the path holds containers (a field that is only that has no `types`). */
|
|
33
|
+
container?: 'object' | 'array';
|
|
34
|
+
/** More than one kind of value (text and numbers, say). Several numeric types alone (`int` + `long`) are not "mixed". */
|
|
35
|
+
mixed: boolean;
|
|
36
|
+
/** The path of an array's element (`tags[]`): typed, but not a field one can select or filter on. */
|
|
37
|
+
element: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** The BSON type of a MongoDB `$type` name; `undefined` for object, array and the types without an editor (`binData`, `regex`, …). */
|
|
40
|
+
export declare function bsonOfType(typeName: string): BsonType | undefined;
|
|
41
|
+
/** `fields/detail` as one `FieldTypeInfo` per path, in the server's order. Never throws; a malformed entry is skipped. */
|
|
42
|
+
export declare function toFieldTypeInfos(details: readonly FieldDetail[]): FieldTypeInfo[];
|
|
43
|
+
/** The filter builder's field type of a field, or `undefined` when it has no editor (only nulls, binary data, …). */
|
|
44
|
+
export declare function filterTypeOf(info: FieldTypeInfo): FilterFieldType | undefined;
|
|
45
|
+
/** The import/bulk-edit column type of a field (`json` for containers, `string` when unknown). */
|
|
46
|
+
export declare function columnTypeOf(info: FieldTypeInfo): ImportColumnType;
|
|
47
|
+
/**
|
|
48
|
+
* Write hints for typing a value without an original document: a scalar path with exactly **one** type found. A path with
|
|
49
|
+
* several types (`int` + `long`, or text + numbers) is left unhinted so the server decides as it would for plain JSON.
|
|
50
|
+
*/
|
|
51
|
+
export declare function toTypeHints(infos: readonly FieldTypeInfo[]): TypeHints;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export function valueKindOfType(type) {
|
|
2
|
+
switch (type) {
|
|
3
|
+
case "string":
|
|
4
|
+
case "objectId":
|
|
5
|
+
return "string";
|
|
6
|
+
case "int":
|
|
7
|
+
case "long":
|
|
8
|
+
case "double":
|
|
9
|
+
case "decimal":
|
|
10
|
+
return "number";
|
|
11
|
+
case "bool":
|
|
12
|
+
return "boolean";
|
|
13
|
+
case "date":
|
|
14
|
+
return "date";
|
|
15
|
+
case "object":
|
|
16
|
+
return "object";
|
|
17
|
+
case "array":
|
|
18
|
+
return "array";
|
|
19
|
+
case "null":
|
|
20
|
+
return "null";
|
|
21
|
+
default:
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function dominantKindOfField(details, path) {
|
|
26
|
+
const counts = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const { type, count } of details.find((d) => d.path === path)?.types ?? []) {
|
|
28
|
+
const kind = valueKindOfType(type);
|
|
29
|
+
if (kind && kind !== "null") counts.set(kind, (counts.get(kind) ?? 0) + count);
|
|
30
|
+
}
|
|
31
|
+
return [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
32
|
+
}
|
|
33
|
+
export function fieldPathsOf(details) {
|
|
34
|
+
return [...new Set(details.map((d) => d.path).filter((path) => path !== "" && !path.includes("[")))].sort((a, b) => a.localeCompare(b));
|
|
35
|
+
}
|
|
36
|
+
const BSON_OF_TYPE = {
|
|
37
|
+
string: "string",
|
|
38
|
+
int: "int",
|
|
39
|
+
long: "long",
|
|
40
|
+
double: "double",
|
|
41
|
+
decimal: "decimal",
|
|
42
|
+
bool: "bool",
|
|
43
|
+
date: "date",
|
|
44
|
+
objectId: "objectId",
|
|
45
|
+
null: "null"
|
|
46
|
+
};
|
|
47
|
+
const NUMERIC = ["int", "long", "double", "decimal"];
|
|
48
|
+
const familyOf = (type) => NUMERIC.includes(type) ? "number" : type;
|
|
49
|
+
export function bsonOfType(typeName) {
|
|
50
|
+
return Object.hasOwn(BSON_OF_TYPE, typeName) ? BSON_OF_TYPE[typeName] : void 0;
|
|
51
|
+
}
|
|
52
|
+
export function toFieldTypeInfos(details) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const detail of details) {
|
|
55
|
+
if (!detail || typeof detail.path !== "string" || detail.path === "") continue;
|
|
56
|
+
const counts = /* @__PURE__ */ new Map();
|
|
57
|
+
let container;
|
|
58
|
+
for (const { type, count } of detail.types ?? []) {
|
|
59
|
+
if (type === "object" || type === "array") {
|
|
60
|
+
container ??= type;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const bson = bsonOfType(type);
|
|
64
|
+
if (bson && bson !== "null") counts.set(bson, (counts.get(bson) ?? 0) + (Number.isFinite(count) ? count : 0));
|
|
65
|
+
}
|
|
66
|
+
const types = [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([type]) => type);
|
|
67
|
+
out.push({
|
|
68
|
+
path: detail.path,
|
|
69
|
+
types,
|
|
70
|
+
dominant: types[0],
|
|
71
|
+
container,
|
|
72
|
+
mixed: new Set(types.map(familyOf)).size > 1,
|
|
73
|
+
element: detail.path.includes("[")
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
export function filterTypeOf(info) {
|
|
79
|
+
if (info.path === "_id") return "objectId";
|
|
80
|
+
if (info.dominant === void 0) return info.container;
|
|
81
|
+
switch (familyOf(info.dominant)) {
|
|
82
|
+
case "number":
|
|
83
|
+
return "number";
|
|
84
|
+
case "string":
|
|
85
|
+
return "string";
|
|
86
|
+
case "bool":
|
|
87
|
+
return "boolean";
|
|
88
|
+
case "date":
|
|
89
|
+
return "date-time";
|
|
90
|
+
case "objectId":
|
|
91
|
+
return "objectId";
|
|
92
|
+
default:
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function columnTypeOf(info) {
|
|
97
|
+
if (info.dominant === void 0) return info.container ? "json" : "string";
|
|
98
|
+
switch (familyOf(info.dominant)) {
|
|
99
|
+
case "number":
|
|
100
|
+
return "number";
|
|
101
|
+
case "bool":
|
|
102
|
+
return "boolean";
|
|
103
|
+
case "date":
|
|
104
|
+
return "date-time";
|
|
105
|
+
default:
|
|
106
|
+
return "string";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function toTypeHints(infos) {
|
|
110
|
+
const hints = {};
|
|
111
|
+
for (const info of infos) if (info.types.length === 1 && info.container === void 0) hints[info.path] = info.types[0];
|
|
112
|
+
return hints;
|
|
113
|
+
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/** An index as `GET …/index/details` lists it (the parts this module reads). */
|
|
2
|
+
export interface IndexDetailLike {
|
|
2
3
|
name: string;
|
|
3
|
-
keys?:
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
keys?: Array<{
|
|
5
|
+
field: string;
|
|
6
|
+
direction: string;
|
|
7
|
+
}>;
|
|
6
8
|
unique?: boolean;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
sparse?: boolean;
|
|
10
|
+
hidden?: boolean;
|
|
11
|
+
partialFilterExpression?: unknown;
|
|
12
|
+
collation?: unknown;
|
|
13
|
+
weights?: Record<string, unknown>;
|
|
14
|
+
defaultLanguage?: string;
|
|
15
|
+
expireAfterSeconds?: number | null;
|
|
9
16
|
}
|
|
10
17
|
export interface IndexKey {
|
|
11
18
|
field: string;
|
|
@@ -13,53 +20,60 @@ export interface IndexKey {
|
|
|
13
20
|
direction: 1 | -1 | 'text' | 'other';
|
|
14
21
|
}
|
|
15
22
|
export declare const MAX_INDEX_FIELDS = 8;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* `indexKeys` plus whether the order is **known**: always for one key or a text index, for a compound index only when its
|
|
23
|
-
* standard name spells out the keys. A custom-named compound index is listed in an arbitrary order, so the order is not
|
|
24
|
-
* known and must not be copied onto another collection.
|
|
25
|
-
*/
|
|
26
|
-
export declare function indexKeysWithOrder(index: IndexLike): {
|
|
27
|
-
keys: IndexKey[];
|
|
28
|
-
orderKnown: boolean;
|
|
29
|
-
};
|
|
23
|
+
/** The fields of an index in index order, straight from the server's ordered listing. */
|
|
24
|
+
export declare function indexKeys(index: Pick<IndexDetailLike, 'keys'>): IndexKey[];
|
|
25
|
+
/** Whether the index is a text index (any key is `text`). */
|
|
26
|
+
export declare function isTextIndex(index: Pick<IndexDetailLike, 'keys'>): boolean;
|
|
27
|
+
/** Whether the index expires documents (a TTL index). */
|
|
28
|
+
export declare function isExpiringIndex(index: Pick<IndexDetailLike, 'expireAfterSeconds'>): boolean;
|
|
30
29
|
export declare function describeKey(key: IndexKey): string;
|
|
31
30
|
export { formatBytes } from './formatBytes.js';
|
|
32
31
|
export declare function isValidExpireAfter(text: string): boolean;
|
|
33
32
|
export type IndexKind = 'standard' | 'unique' | 'text' | 'expiring';
|
|
34
33
|
export interface IndexForm {
|
|
35
34
|
kind: IndexKind;
|
|
36
|
-
/** One row per field; a text
|
|
35
|
+
/** One row per field; an expiring index uses the first, a text index all of them (the direction is ignored). */
|
|
37
36
|
fields: Array<{
|
|
38
37
|
field: string;
|
|
39
38
|
descending: boolean;
|
|
40
39
|
}>;
|
|
41
|
-
/** Optional name (
|
|
40
|
+
/** Optional name (every kind but expiring). */
|
|
42
41
|
name: string;
|
|
43
42
|
expireAfter: string;
|
|
43
|
+
/** Index only the documents that have the field (not together with a partial filter). */
|
|
44
|
+
sparse: boolean;
|
|
45
|
+
/** Created but not used by queries until unhidden. */
|
|
46
|
+
hidden: boolean;
|
|
47
|
+
/** A MongoDB filter as JSON text: only the documents it matches are indexed. Empty = none. */
|
|
48
|
+
partialFilter: string;
|
|
44
49
|
}
|
|
45
|
-
export type IndexFormProblem = 'no-field' | 'empty-field' | 'duplicate-field' | 'too-many-fields' | 'bad-duration' | 'bad-name';
|
|
50
|
+
export type IndexFormProblem = 'no-field' | 'empty-field' | 'duplicate-field' | 'too-many-fields' | 'bad-duration' | 'bad-name' | 'bad-partial-filter' | 'sparse-and-partial';
|
|
51
|
+
/** The partial filter text as an object: `undefined` for empty, `null` when it is not a JSON object. */
|
|
52
|
+
export declare function parsePartialFilter(text: string): Record<string, unknown> | null | undefined;
|
|
46
53
|
export declare function validateIndexForm(form: IndexForm): IndexFormProblem[];
|
|
54
|
+
export interface IndexCreateOptions {
|
|
55
|
+
unique?: boolean;
|
|
56
|
+
name?: string;
|
|
57
|
+
sparse?: boolean;
|
|
58
|
+
hidden?: boolean;
|
|
59
|
+
partialFilterExpression?: Record<string, unknown>;
|
|
60
|
+
}
|
|
47
61
|
export type IndexRequest = {
|
|
48
|
-
call: '
|
|
49
|
-
keys:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} | {
|
|
55
|
-
call: 'createTextIndex';
|
|
56
|
-
field: string;
|
|
62
|
+
call: 'createOrderedIndex';
|
|
63
|
+
keys: Array<{
|
|
64
|
+
field: string;
|
|
65
|
+
direction: '1' | '-1' | 'text';
|
|
66
|
+
}>;
|
|
67
|
+
options?: IndexCreateOptions;
|
|
57
68
|
} | {
|
|
58
69
|
call: 'createExpiringIndex';
|
|
59
70
|
field: string;
|
|
60
71
|
duration: string;
|
|
61
72
|
};
|
|
62
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* The call a valid form stands for. Every kind but expiring goes through the ordered create, which keeps the field order of
|
|
75
|
+
* a compound index and accepts a text index over several fields (server 1.8.1, verified live).
|
|
76
|
+
*/
|
|
63
77
|
export declare function buildIndexRequest(form: IndexForm): IndexRequest;
|
|
64
78
|
export type IndexErrorKind = 'duplicate-values' | 'conflict' | 'empty-keys' | 'other';
|
|
65
79
|
/** What a create/drop failure means, from the server's message (MongoDB error codes 11000, 85/86 and 67). */
|