@sfxcode/nuxt-ui-mongocamp 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +1 -1
  2. package/dist/module.json +2 -2
  3. package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +1 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +29 -2
  5. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +1 -0
  6. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +1 -0
  7. package/dist/runtime/components/MongocampAggregationStagePreview.vue +4 -3
  8. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +1 -0
  9. package/dist/runtime/components/MongocampBucketFiles.vue +61 -0
  10. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +2 -12
  11. package/dist/runtime/components/MongocampBulkDelete.vue +14 -40
  12. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +2 -12
  13. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +5 -6
  14. package/dist/runtime/components/MongocampBulkEdit.vue +43 -26
  15. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +5 -6
  16. package/dist/runtime/components/MongocampChart.vue +1 -4
  17. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +2 -0
  18. package/dist/runtime/components/MongocampCollectionCharts.vue +9 -8
  19. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +2 -0
  20. package/dist/runtime/components/MongocampCollectionCopy.vue +19 -258
  21. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +2 -0
  22. package/dist/runtime/components/MongocampCollectionData.vue +206 -126
  23. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +2 -0
  24. package/dist/runtime/components/MongocampCollectionRename.d.vue.ts +22 -0
  25. package/dist/runtime/components/MongocampCollectionRename.vue +116 -0
  26. package/dist/runtime/components/MongocampCollectionRename.vue.d.ts +22 -0
  27. package/dist/runtime/components/MongocampCollections.vue +31 -12
  28. package/dist/runtime/components/MongocampCommandPalette.vue +2 -2
  29. package/dist/runtime/components/MongocampDashboard.vue +19 -4
  30. package/dist/runtime/components/MongocampDatabases.vue +13 -2
  31. package/dist/runtime/components/MongocampExportAll.vue +13 -26
  32. package/dist/runtime/components/MongocampImport.vue +169 -3
  33. package/dist/runtime/components/MongocampIndexes.vue +54 -13
  34. package/dist/runtime/components/MongocampJobs.vue +14 -3
  35. package/dist/runtime/components/MongocampRoleGrants.vue +16 -3
  36. package/dist/runtime/components/MongocampRoles.vue +13 -2
  37. package/dist/runtime/components/MongocampServerInfo.d.vue.ts +24 -0
  38. package/dist/runtime/components/MongocampServerInfo.vue +331 -0
  39. package/dist/runtime/components/MongocampServerInfo.vue.d.ts +24 -0
  40. package/dist/runtime/components/MongocampServerOverview.vue +16 -39
  41. package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
  42. package/dist/runtime/components/MongocampSettings.vue +14 -2
  43. package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
  44. package/dist/runtime/components/MongocampUsers.vue +16 -3
  45. package/dist/runtime/components/MongocampVersion.d.vue.ts +7 -1
  46. package/dist/runtime/components/MongocampVersion.vue +49 -19
  47. package/dist/runtime/components/MongocampVersion.vue.d.ts +7 -1
  48. package/dist/runtime/composables/useMongocampAdminGate.d.ts +12 -0
  49. package/dist/runtime/composables/useMongocampAdminGate.js +12 -0
  50. package/dist/runtime/composables/useMongocampAggregation.d.ts +11 -0
  51. package/dist/runtime/composables/useMongocampAggregation.js +12 -5
  52. package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +15 -0
  53. package/dist/runtime/composables/useMongocampBulkByFilter.js +32 -0
  54. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +25 -65
  55. package/dist/runtime/composables/useMongocampCollectionCopy.js +27 -84
  56. package/dist/runtime/composables/useMongocampExportAll.d.ts +27 -21
  57. package/dist/runtime/composables/useMongocampExportAll.js +51 -21
  58. package/dist/runtime/composables/useMongocampExtendedJson.d.ts +2 -1
  59. package/dist/runtime/composables/useMongocampExtendedJson.js +32 -5
  60. package/dist/runtime/composables/useMongocampFetchAll.js +1 -1
  61. package/dist/runtime/composables/useMongocampFieldTypes.d.ts +24 -0
  62. package/dist/runtime/composables/useMongocampFieldTypes.js +44 -0
  63. package/dist/runtime/composables/useMongocampImport.d.ts +4 -0
  64. package/dist/runtime/composables/useMongocampImport.js +5 -2
  65. package/dist/runtime/composables/useMongocampIndex.d.ts +6 -1
  66. package/dist/runtime/composables/useMongocampIndex.js +7 -1
  67. package/dist/runtime/composables/useMongocampPermissions.d.ts +8 -5
  68. package/dist/runtime/composables/useMongocampPermissions.js +24 -2
  69. package/dist/runtime/composables/useMongocampQuery.d.ts +3 -3
  70. package/dist/runtime/composables/useMongocampServerOverview.d.ts +4 -11
  71. package/dist/runtime/composables/useMongocampServerOverview.js +12 -22
  72. package/dist/runtime/composables/useMongocampSystem.d.ts +10 -1
  73. package/dist/runtime/composables/useMongocampSystem.js +11 -1
  74. package/dist/runtime/locales/de.json +104 -71
  75. package/dist/runtime/locales/en.json +104 -71
  76. package/dist/runtime/plugin.d.ts +2 -2
  77. package/dist/runtime/utils/aggregationErrors.d.ts +4 -0
  78. package/dist/runtime/utils/aggregationErrors.js +7 -0
  79. package/dist/runtime/utils/batchInsert.d.ts +6 -0
  80. package/dist/runtime/utils/batchInsert.js +31 -3
  81. package/dist/runtime/utils/bsonTypes.d.ts +10 -0
  82. package/dist/runtime/utils/bsonTypes.js +42 -0
  83. package/dist/runtime/utils/collectionCopy.d.ts +0 -2
  84. package/dist/runtime/utils/collectionCopy.js +0 -1
  85. package/dist/runtime/utils/configRows.d.ts +7 -0
  86. package/dist/runtime/utils/configRows.js +4 -0
  87. package/dist/runtime/utils/documentCompare.js +2 -1
  88. package/dist/runtime/utils/documentPaths.d.ts +5 -8
  89. package/dist/runtime/utils/documentPaths.js +5 -10
  90. package/dist/runtime/utils/documentTree.js +9 -1
  91. package/dist/runtime/utils/exportDocuments.d.ts +0 -2
  92. package/dist/runtime/utils/exportDocuments.js +0 -1
  93. package/dist/runtime/utils/exportRows.d.ts +2 -0
  94. package/dist/runtime/utils/exportRows.js +5 -2
  95. package/dist/runtime/utils/fieldDetails.d.ts +51 -0
  96. package/dist/runtime/utils/fieldDetails.js +113 -0
  97. package/dist/runtime/utils/indexForm.d.ts +47 -33
  98. package/dist/runtime/utils/indexForm.js +32 -21
  99. package/dist/runtime/utils/serverInfo.d.ts +8 -0
  100. package/dist/runtime/utils/serverInfo.js +21 -0
  101. package/package.json +11 -11
  102. package/dist/runtime/utils/indexCopy.d.ts +0 -26
  103. package/dist/runtime/utils/indexCopy.js +0 -22
  104. package/dist/runtime/utils/limitedMap.d.ts +0 -17
  105. package/dist/runtime/utils/limitedMap.js +0 -19
@@ -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).
@@ -5,7 +5,6 @@ export const EXPORT_MIME_TYPES = {
5
5
  ndjson: "application/x-ndjson",
6
6
  csv: "text/csv"
7
7
  };
8
- export const DEFAULT_EXPORT_MAX_ROWS = 5e4;
9
8
  const INTEGER_TEXT = /^-?\d+$/;
10
9
  function longsToBigInt(value) {
11
10
  if (Array.isArray(value)) return value.map(longsToBigInt);
@@ -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 downloadTextFile(filename, content, mimeType) {
12
- const url = URL.createObjectURL(new Blob([content], { type: `${mimeType};charset=utf-8` }));
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
- export interface IndexLike {
1
+ /** An index as `GET …/index/details` lists it (the parts this module reads). */
2
+ export interface IndexDetailLike {
2
3
  name: string;
3
- keys?: Record<string, unknown>;
4
- weights?: Record<string, unknown>;
5
- text?: boolean;
4
+ keys?: Array<{
5
+ field: string;
6
+ direction: string;
7
+ }>;
6
8
  unique?: boolean;
7
- expire?: boolean;
8
- expireAfterSeconds?: number;
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
- * The fields of an index in index order. A text index shows its `weights` fields. For others the key order the server lists
18
- * is not reliable, so the standard name (`a_1_b_-1`) is used when it spells out exactly these keys; else the listed order.
19
- */
20
- export declare function indexKeys(index: IndexLike): IndexKey[];
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 or expiring index uses the first. */
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 (standard and unique only). */
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: 'createIndex';
49
- keys: Record<string, 1 | -1>;
50
- options?: {
51
- unique?: boolean;
52
- name?: string;
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
- /** The call a valid form stands for. Compound standard and unique indexes go through `createIndex` (verified live). */
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). */
@@ -1,21 +1,15 @@
1
1
  export const MAX_INDEX_FIELDS = 8;
2
2
  export function indexKeys(index) {
3
- return indexKeysWithOrder(index).keys;
3
+ return (index.keys ?? []).map(({ field, direction }) => ({
4
+ field,
5
+ direction: direction === "1" ? 1 : direction === "-1" ? -1 : direction === "text" ? "text" : "other"
6
+ }));
4
7
  }
5
- export function indexKeysWithOrder(index) {
6
- if (index.text && index.weights && Object.keys(index.weights).length > 0) {
7
- return { keys: Object.keys(index.weights).map((field) => ({ field, direction: "text" })), orderKnown: true };
8
- }
9
- const entries = Object.entries(index.keys ?? {}).map(([field, value]) => ({ field, direction: value === 1 || value === -1 ? value : "other", value }));
10
- if (entries.length <= 1) return { keys: entries.map((e) => ({ field: e.field, direction: e.direction })), orderKnown: true };
11
- const positions = entries.map((e) => ({ e, at: index.name.indexOf(`${e.field}_${String(e.value)}`) }));
12
- if (positions.every((p) => p.at >= 0)) {
13
- const sorted = [...positions].sort((a, b) => a.at - b.at);
14
- if (sorted.map((p) => `${p.e.field}_${String(p.e.value)}`).join("_") === index.name) {
15
- return { keys: sorted.map((p) => ({ field: p.e.field, direction: p.e.direction })), orderKnown: true };
16
- }
17
- }
18
- return { keys: entries.map((e) => ({ field: e.field, direction: e.direction })), orderKnown: false };
8
+ export function isTextIndex(index) {
9
+ return indexKeys(index).some((key) => key.direction === "text");
10
+ }
11
+ export function isExpiringIndex(index) {
12
+ return typeof index.expireAfterSeconds === "number";
19
13
  }
20
14
  export function describeKey(key) {
21
15
  if (key.direction === "text") return `${key.field} (text)`;
@@ -26,28 +20,45 @@ const DURATION = /^[1-9]\d{0,8}[smhd]$/;
26
20
  export function isValidExpireAfter(text) {
27
21
  return DURATION.test(text.trim());
28
22
  }
23
+ export function parsePartialFilter(text) {
24
+ if (text.trim() === "") return void 0;
25
+ try {
26
+ const value = JSON.parse(text);
27
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length > 0 ? value : null;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+ const takesOptions = (kind) => kind !== "expiring";
29
33
  export function validateIndexForm(form) {
30
34
  const problems = [];
31
- const rows = form.kind === "text" || form.kind === "expiring" ? form.fields.slice(0, 1) : form.fields;
35
+ const rows = form.kind === "expiring" ? form.fields.slice(0, 1) : form.fields;
32
36
  if (rows.length === 0) return ["no-field"];
33
37
  const names = rows.map((r) => r.field.trim());
34
38
  if (names.includes("")) problems.push("empty-field");
35
39
  if (new Set(names.filter(Boolean)).size !== names.filter(Boolean).length) problems.push("duplicate-field");
36
40
  if (rows.length > MAX_INDEX_FIELDS) problems.push("too-many-fields");
37
41
  if (form.kind === "expiring" && !isValidExpireAfter(form.expireAfter)) problems.push("bad-duration");
38
- if ((form.kind === "standard" || form.kind === "unique") && form.name.trim().length > 100) problems.push("bad-name");
42
+ if (takesOptions(form.kind) && form.name.trim().length > 100) problems.push("bad-name");
43
+ if (takesOptions(form.kind)) {
44
+ const partial = parsePartialFilter(form.partialFilter);
45
+ if (partial === null) problems.push("bad-partial-filter");
46
+ else if (partial !== void 0 && form.sparse) problems.push("sparse-and-partial");
47
+ }
39
48
  return problems;
40
49
  }
41
50
  export function buildIndexRequest(form) {
42
51
  const rows = form.fields.map((r) => ({ field: r.field.trim(), descending: r.descending }));
43
- if (form.kind === "text") return { call: "createTextIndex", field: rows[0].field };
44
52
  if (form.kind === "expiring") return { call: "createExpiringIndex", field: rows[0].field, duration: form.expireAfter.trim() };
45
- const keys = {};
46
- for (const row of rows) keys[row.field] = row.descending ? -1 : 1;
53
+ const keys = rows.map((row) => ({ field: row.field, direction: form.kind === "text" ? "text" : row.descending ? "-1" : "1" }));
47
54
  const options = {};
48
55
  if (form.kind === "unique") options.unique = true;
49
56
  if (form.name.trim() !== "") options.name = form.name.trim();
50
- return Object.keys(options).length > 0 ? { call: "createIndex", keys, options } : { call: "createIndex", keys };
57
+ if (form.sparse) options.sparse = true;
58
+ if (form.hidden) options.hidden = true;
59
+ const partial = parsePartialFilter(form.partialFilter);
60
+ if (partial) options.partialFilterExpression = partial;
61
+ return Object.keys(options).length > 0 ? { call: "createOrderedIndex", keys, options } : { call: "createOrderedIndex", keys };
51
62
  }
52
63
  export function classifyIndexError(message) {
53
64
  if (/11000|duplicate key|E11000/i.test(message)) return "duplicate-values";
@@ -0,0 +1,8 @@
1
+ /** `3d 4h`, `5h 12m`, `7m 3s`, `42s` — the two biggest non-zero units; `-` for nothing/unknown. */
2
+ export declare function formatUptime(seconds: number | null | undefined): string;
3
+ /** Thousands separators without a locale dependency (the counters run into the millions). */
4
+ export declare function formatCount(value: number | null | undefined): string;
5
+ /** Share of connections in use, 0–100 (`current` against `current + available`); `null` if nothing is known. */
6
+ export declare function connectionUsage(current: number | null | undefined, available: number | null | undefined): number | null;
7
+ export declare const OP_COUNTER_KEYS: readonly ["insert", "query", "update", "delete", "getmore", "command"];
8
+ export type OpCounterKey = typeof OP_COUNTER_KEYS[number];
@@ -0,0 +1,21 @@
1
+ export function formatUptime(seconds) {
2
+ if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return "-";
3
+ const total = Math.floor(seconds);
4
+ const days = Math.floor(total / 86400);
5
+ const hours = Math.floor(total % 86400 / 3600);
6
+ const minutes = Math.floor(total % 3600 / 60);
7
+ const secs = total % 60;
8
+ const parts = [[days, "d"], [hours, "h"], [minutes, "m"], [secs, "s"]];
9
+ const shown = parts.filter(([value]) => value > 0).slice(0, 2).map(([value, unit]) => `${value}${unit}`);
10
+ return shown.length ? shown.join(" ") : "0s";
11
+ }
12
+ export function formatCount(value) {
13
+ if (value == null || !Number.isFinite(value)) return "-";
14
+ return Math.trunc(value).toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
15
+ }
16
+ export function connectionUsage(current, available) {
17
+ if (current == null || available == null) return null;
18
+ const total = current + available;
19
+ return total > 0 ? Math.round(current / total * 100) : null;
20
+ }
21
+ export const OP_COUNTER_KEYS = ["insert", "query", "update", "delete", "getmore", "command"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-ui-mongocamp",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
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 --minor --release && npm publish && git push --follow-tags",
47
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --patch --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,27 +55,27 @@
55
55
  "docs:preview": "vitepress preview docs"
56
56
  },
57
57
  "dependencies": {
58
- "@formkit/nuxt": "^2.2.1",
58
+ "@formkit/nuxt": "^2.5.0",
59
59
  "@internationalized/date": "^3.12.4",
60
60
  "@nuxt/ui": "^4.12.0",
61
61
  "@nuxtjs/i18n": "^10.6.0",
62
- "@sfxcode/nuxt-mongocamp-server": "^1.6.3",
62
+ "@sfxcode/nuxt-mongocamp-server": "^1.9.1",
63
63
  "@sfxcode/nuxt-ui-formkit": "^1.4.2",
64
- "@tanstack/charts": "^1.3.0",
64
+ "@tanstack/charts": "^1.5.0",
65
65
  "consola": "^3.4.2",
66
66
  "defu": "^6.1.7",
67
- "minimatch": "^11.0.4",
68
- "unocss-nuxt-ui": "^1.2.2"
67
+ "minimatch": "^11.0.8",
68
+ "unocss-nuxt-ui": "^1.3.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@iconify-json/lucide": "^1.2.151",
71
+ "@iconify-json/lucide": "^1.2.154",
72
72
  "@nuxt/devtools": "^4.1.0",
73
73
  "@nuxt/eslint-config": "^1.17.0",
74
74
  "@nuxt/kit": "^4.6.4",
75
- "@nuxt/module-builder": "^1.0.3",
75
+ "@nuxt/module-builder": "^1.0.4",
76
76
  "@nuxt/schema": "^4.6.4",
77
- "@nuxt/test-utils": "^4.3.4",
78
- "@playwright/test": "^1.64.1",
77
+ "@nuxt/test-utils": "^4.4.0",
78
+ "@playwright/test": "^1.65.0",
79
79
  "@types/node": "latest",
80
80
  "@unhead/vue": "^3.4.3",
81
81
  "@vue/test-utils": "^2.5.1",
@@ -1,26 +0,0 @@
1
- import type { IndexLike } from './indexForm.js';
2
- export type IndexCopySkipReason = 'multi-field-text' | 'unsupported-key' | 'unknown-key-order' | 'custom-weights';
3
- export type IndexCopyPlan = {
4
- call: 'createIndex';
5
- name: string;
6
- keys: Record<string, 1 | -1>;
7
- options: {
8
- name: string;
9
- unique?: boolean;
10
- expireAfter?: string;
11
- };
12
- } | {
13
- call: 'createTextIndex';
14
- name: string;
15
- field: string;
16
- } | {
17
- call: 'skip';
18
- name: string;
19
- reason: IndexCopySkipReason;
20
- };
21
- /** The index MongoDB creates by itself on every collection; never copied. */
22
- export declare const DEFAULT_INDEX_NAME = "_id_";
23
- /** What recreating `index` takes: a `createIndex` with name, `unique` and `expireAfter`, a text index, or a skip with the reason. */
24
- export declare function planIndexCopy(index: IndexLike): IndexCopyPlan;
25
- /** The plans for every index of a collection, without the default `_id_` index. */
26
- export declare function planIndexCopies(indexes: IndexLike[]): IndexCopyPlan[];
@@ -1,22 +0,0 @@
1
- import { indexKeysWithOrder } from "./indexForm.js";
2
- export const DEFAULT_INDEX_NAME = "_id_";
3
- export function planIndexCopy(index) {
4
- const { keys, orderKnown } = indexKeysWithOrder(index);
5
- if (index.text) {
6
- const weights = Object.entries(index.weights ?? {});
7
- if (weights.length !== 1) return { call: "skip", name: index.name, reason: "multi-field-text" };
8
- if (weights[0][1] !== 1) return { call: "skip", name: index.name, reason: "custom-weights" };
9
- return { call: "createTextIndex", name: index.name, field: weights[0][0] };
10
- }
11
- if (keys.length === 0 || keys.some((k) => k.direction !== 1 && k.direction !== -1)) return { call: "skip", name: index.name, reason: "unsupported-key" };
12
- if (!orderKnown) return { call: "skip", name: index.name, reason: "unknown-key-order" };
13
- const orderedKeys = {};
14
- for (const key of keys) orderedKeys[key.field] = key.direction;
15
- const options = { name: index.name };
16
- if (index.unique) options.unique = true;
17
- if (index.expire && typeof index.expireAfterSeconds === "number" && index.expireAfterSeconds >= 0) options.expireAfter = `${index.expireAfterSeconds}s`;
18
- return { call: "createIndex", name: index.name, keys: orderedKeys, options };
19
- }
20
- export function planIndexCopies(indexes) {
21
- return indexes.filter((i) => i.name !== DEFAULT_INDEX_NAME).map(planIndexCopy);
22
- }
@@ -1,17 +0,0 @@
1
- export type Settled<R> = {
2
- ok: true;
3
- value: R;
4
- } | {
5
- ok: false;
6
- error: unknown;
7
- };
8
- export interface LimitedMapOptions {
9
- signal?: AbortSignal;
10
- /** Called after every finished item with how many are done so far. */
11
- onProgress?: (done: number, total: number) => void;
12
- }
13
- /**
14
- * The result of every item that was started, in input order; an item that never started (the run was aborted first) is
15
- * `undefined`. A rejected call is `{ ok: false, error }`, never thrown.
16
- */
17
- export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>, options?: LimitedMapOptions): Promise<Array<Settled<R> | undefined>>;
@@ -1,19 +0,0 @@
1
- export async function mapLimit(items, limit, fn, options = {}) {
2
- const results = Array.from({ length: items.length });
3
- const workers = Math.max(1, Math.min(Math.floor(limit) || 1, items.length));
4
- let next = 0;
5
- let done = 0;
6
- async function worker() {
7
- while (next < items.length && !options.signal?.aborted) {
8
- const index = next++;
9
- try {
10
- results[index] = { ok: true, value: await fn(items[index], index) };
11
- } catch (error) {
12
- results[index] = { ok: false, error };
13
- }
14
- options.onProgress?.(++done, items.length);
15
- }
16
- }
17
- await Promise.all(Array.from({ length: workers }, worker));
18
- return results;
19
- }