@sfxcode/nuxt-ui-mongocamp 1.3.5 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/dist/module.d.mts +8 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +6 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +302 -3
  5. package/dist/runtime/components/MongocampAggregationChart.d.vue.ts +6 -0
  6. package/dist/runtime/components/MongocampAggregationChart.vue +93 -0
  7. package/dist/runtime/components/MongocampAggregationChart.vue.d.ts +6 -0
  8. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +9 -0
  9. package/dist/runtime/components/MongocampAggregationStagePreview.vue +148 -0
  10. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +9 -0
  11. package/dist/runtime/components/MongocampBucketFiles.vue +169 -48
  12. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +19 -0
  13. package/dist/runtime/components/MongocampBulkDelete.vue +118 -23
  14. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +19 -0
  15. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +6 -0
  16. package/dist/runtime/components/MongocampBulkEdit.vue +23 -2
  17. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +6 -0
  18. package/dist/runtime/components/MongocampChart.d.vue.ts +29 -0
  19. package/dist/runtime/components/MongocampChart.vue +129 -0
  20. package/dist/runtime/components/MongocampChart.vue.d.ts +29 -0
  21. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +15 -0
  22. package/dist/runtime/components/MongocampCollectionCharts.vue +199 -0
  23. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +15 -0
  24. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +23 -0
  25. package/dist/runtime/components/MongocampCollectionCopy.vue +445 -0
  26. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +23 -0
  27. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -0
  28. package/dist/runtime/components/MongocampCollectionData.vue +342 -137
  29. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -0
  30. package/dist/runtime/components/MongocampCollectionInfos.vue +106 -238
  31. package/dist/runtime/components/MongocampCollections.vue +62 -0
  32. package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +40 -0
  33. package/dist/runtime/components/MongocampCommandPalette.vue +135 -0
  34. package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +40 -0
  35. package/dist/runtime/components/MongocampConfirmByName.vue +2 -2
  36. package/dist/runtime/components/MongocampDashboard.d.vue.ts +3 -1
  37. package/dist/runtime/components/MongocampDashboard.vue +21 -2
  38. package/dist/runtime/components/MongocampDashboard.vue.d.ts +3 -1
  39. package/dist/runtime/components/MongocampDatabases.vue +22 -0
  40. package/dist/runtime/components/MongocampDocumentCompare.d.vue.ts +20 -0
  41. package/dist/runtime/components/MongocampDocumentCompare.vue +146 -0
  42. package/dist/runtime/components/MongocampDocumentCompare.vue.d.ts +20 -0
  43. package/dist/runtime/components/MongocampDocumentView.d.vue.ts +22 -0
  44. package/dist/runtime/components/MongocampDocumentView.vue +202 -0
  45. package/dist/runtime/components/MongocampDocumentView.vue.d.ts +22 -0
  46. package/dist/runtime/components/MongocampErrorAlert.vue +12 -4
  47. package/dist/runtime/components/MongocampExportAll.d.vue.ts +18 -0
  48. package/dist/runtime/components/MongocampExportAll.vue +204 -0
  49. package/dist/runtime/components/MongocampExportAll.vue.d.ts +18 -0
  50. package/dist/runtime/components/MongocampFilePreview.d.vue.ts +16 -0
  51. package/dist/runtime/components/MongocampFilePreview.vue +162 -0
  52. package/dist/runtime/components/MongocampFilePreview.vue.d.ts +16 -0
  53. package/dist/runtime/components/MongocampFilterBuilder.vue +11 -0
  54. package/dist/runtime/components/MongocampImport.vue +2 -10
  55. package/dist/runtime/components/MongocampIndexes.d.vue.ts +18 -0
  56. package/dist/runtime/components/MongocampIndexes.vue +455 -0
  57. package/dist/runtime/components/MongocampIndexes.vue.d.ts +18 -0
  58. package/dist/runtime/components/MongocampJobs.d.vue.ts +6 -1
  59. package/dist/runtime/components/MongocampJobs.vue +23 -3
  60. package/dist/runtime/components/MongocampJobs.vue.d.ts +6 -1
  61. package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +12 -0
  62. package/dist/runtime/components/MongocampPermissionMatrix.vue +301 -0
  63. package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +12 -0
  64. package/dist/runtime/components/MongocampQueryBar.d.vue.ts +26 -0
  65. package/dist/runtime/components/MongocampQueryBar.vue +398 -0
  66. package/dist/runtime/components/MongocampQueryBar.vue.d.ts +26 -0
  67. package/dist/runtime/components/MongocampRoleGrants.vue +2 -2
  68. package/dist/runtime/components/MongocampRoles.vue +3 -3
  69. package/dist/runtime/components/MongocampServerOverview.d.vue.ts +20 -0
  70. package/dist/runtime/components/MongocampServerOverview.vue +443 -0
  71. package/dist/runtime/components/MongocampServerOverview.vue.d.ts +20 -0
  72. package/dist/runtime/components/MongocampSettings.d.vue.ts +25 -1
  73. package/dist/runtime/components/MongocampSettings.vue +70 -9
  74. package/dist/runtime/components/MongocampSettings.vue.d.ts +25 -1
  75. package/dist/runtime/components/MongocampUsers.vue +3 -3
  76. package/dist/runtime/composables/useMongocampAdmin.d.ts +2 -1
  77. package/dist/runtime/composables/useMongocampAdmin.js +6 -1
  78. package/dist/runtime/composables/useMongocampAggregation.d.ts +12 -1
  79. package/dist/runtime/composables/useMongocampAggregation.js +33 -25
  80. package/dist/runtime/composables/useMongocampAutoRefresh.d.ts +26 -0
  81. package/dist/runtime/composables/useMongocampAutoRefresh.js +78 -0
  82. package/dist/runtime/composables/useMongocampBucket.d.ts +13 -1
  83. package/dist/runtime/composables/useMongocampBucket.js +34 -0
  84. package/dist/runtime/composables/useMongocampClientApi.js +2 -1
  85. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +85 -0
  86. package/dist/runtime/composables/useMongocampCollectionCopy.js +105 -0
  87. package/dist/runtime/composables/useMongocampCollectionStats.d.ts +10 -0
  88. package/dist/runtime/composables/useMongocampCollectionStats.js +17 -0
  89. package/dist/runtime/composables/useMongocampError.d.ts +2 -1
  90. package/dist/runtime/composables/useMongocampError.js +16 -1
  91. package/dist/runtime/composables/useMongocampExportAll.d.ts +47 -0
  92. package/dist/runtime/composables/useMongocampExportAll.js +27 -0
  93. package/dist/runtime/composables/useMongocampExtendedJson.d.ts +5 -1
  94. package/dist/runtime/composables/useMongocampExtendedJson.js +12 -6
  95. package/dist/runtime/composables/useMongocampFetchAll.d.ts +25 -0
  96. package/dist/runtime/composables/useMongocampFetchAll.js +27 -0
  97. package/dist/runtime/composables/useMongocampPermissions.d.ts +14 -0
  98. package/dist/runtime/composables/useMongocampPermissions.js +21 -0
  99. package/dist/runtime/composables/useMongocampPersistedState.d.ts +15 -0
  100. package/dist/runtime/composables/useMongocampPersistedState.js +21 -0
  101. package/dist/runtime/composables/useMongocampProxyApi.js +2 -1
  102. package/dist/runtime/composables/useMongocampQuery.d.ts +48 -0
  103. package/dist/runtime/composables/useMongocampQuery.js +72 -1
  104. package/dist/runtime/composables/useMongocampSavedPipelines.d.ts +25 -0
  105. package/dist/runtime/composables/useMongocampSavedPipelines.js +23 -0
  106. package/dist/runtime/composables/useMongocampSavedQueries.d.ts +37 -0
  107. package/dist/runtime/composables/useMongocampSavedQueries.js +50 -0
  108. package/dist/runtime/composables/useMongocampServerOverview.d.ts +42 -0
  109. package/dist/runtime/composables/useMongocampServerOverview.js +61 -0
  110. package/dist/runtime/composables/useMongocampSession.d.ts +2 -0
  111. package/dist/runtime/composables/useMongocampSession.js +16 -2
  112. package/dist/runtime/composables/useMongocampSystem.d.ts +7 -2
  113. package/dist/runtime/composables/useMongocampSystem.js +6 -2
  114. package/dist/runtime/locales/de.json +495 -9
  115. package/dist/runtime/locales/en.json +495 -9
  116. package/dist/runtime/plugin.js +6 -3
  117. package/dist/runtime/utils/aggregationPipeline.d.ts +5 -4
  118. package/dist/runtime/utils/aggregationPipeline.js +23 -9
  119. package/dist/runtime/utils/aggregationPreview.d.ts +13 -0
  120. package/dist/runtime/utils/aggregationPreview.js +10 -0
  121. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  122. package/dist/runtime/utils/aggregationResult.js +4 -0
  123. package/dist/runtime/utils/aggregationTemplates.d.ts +34 -0
  124. package/dist/runtime/utils/aggregationTemplates.js +47 -0
  125. package/dist/runtime/utils/analyzeSamples.d.ts +1 -0
  126. package/dist/runtime/utils/analyzeSamples.js +1 -1
  127. package/dist/runtime/utils/autoRefresh.d.ts +14 -0
  128. package/dist/runtime/utils/autoRefresh.js +15 -0
  129. package/dist/runtime/utils/bigIntJson.d.ts +15 -0
  130. package/dist/runtime/utils/bigIntJson.js +55 -0
  131. package/dist/runtime/utils/bulkDelete.d.ts +9 -1
  132. package/dist/runtime/utils/bulkDelete.js +15 -3
  133. package/dist/runtime/utils/bulkEdit.d.ts +6 -0
  134. package/dist/runtime/utils/bulkEdit.js +7 -0
  135. package/dist/runtime/utils/chartData.d.ts +11 -0
  136. package/dist/runtime/utils/chartData.js +9 -0
  137. package/dist/runtime/utils/collectionChart.d.ts +36 -0
  138. package/dist/runtime/utils/collectionChart.js +73 -0
  139. package/dist/runtime/utils/collectionCopy.d.ts +26 -0
  140. package/dist/runtime/utils/collectionCopy.js +38 -0
  141. package/dist/runtime/utils/collectionStats.d.ts +31 -0
  142. package/dist/runtime/utils/collectionStats.js +42 -0
  143. package/dist/runtime/utils/commandPalette.d.ts +48 -0
  144. package/dist/runtime/utils/commandPalette.js +39 -0
  145. package/dist/runtime/utils/documentCompare.d.ts +31 -0
  146. package/dist/runtime/utils/documentCompare.js +70 -0
  147. package/dist/runtime/utils/documentDiff.d.ts +19 -0
  148. package/dist/runtime/utils/documentDiff.js +71 -0
  149. package/dist/runtime/utils/documentPaths.d.ts +44 -0
  150. package/dist/runtime/utils/documentPaths.js +144 -0
  151. package/dist/runtime/utils/documentTree.d.ts +40 -0
  152. package/dist/runtime/utils/documentTree.js +94 -0
  153. package/dist/runtime/utils/exportDocuments.d.ts +35 -0
  154. package/dist/runtime/utils/exportDocuments.js +54 -0
  155. package/dist/runtime/utils/exportRows.js +1 -1
  156. package/dist/runtime/utils/filePreview.d.ts +27 -0
  157. package/dist/runtime/utils/filePreview.js +50 -0
  158. package/dist/runtime/utils/filterBuilder.d.ts +6 -1
  159. package/dist/runtime/utils/filterBuilder.js +6 -5
  160. package/dist/runtime/utils/formatBytes.d.ts +2 -0
  161. package/dist/runtime/utils/formatBytes.js +11 -0
  162. package/dist/runtime/utils/grantMatching.d.ts +8 -0
  163. package/dist/runtime/utils/grantMatching.js +15 -0
  164. package/dist/runtime/utils/importRows.js +12 -2
  165. package/dist/runtime/utils/indexCopy.d.ts +26 -0
  166. package/dist/runtime/utils/indexCopy.js +22 -0
  167. package/dist/runtime/utils/indexForm.d.ts +69 -0
  168. package/dist/runtime/utils/indexForm.js +63 -0
  169. package/dist/runtime/utils/limitedMap.d.ts +17 -0
  170. package/dist/runtime/utils/limitedMap.js +19 -0
  171. package/dist/runtime/utils/luceneExpression.d.ts +15 -0
  172. package/dist/runtime/utils/luceneExpression.js +74 -0
  173. package/dist/runtime/utils/pagedFetch.d.ts +46 -0
  174. package/dist/runtime/utils/pagedFetch.js +58 -0
  175. package/dist/runtime/utils/paginationHeaders.d.ts +4 -0
  176. package/dist/runtime/utils/paginationHeaders.js +4 -0
  177. package/dist/runtime/utils/permissionDenied.d.ts +10 -0
  178. package/dist/runtime/utils/permissionDenied.js +23 -0
  179. package/dist/runtime/utils/permissionMatrix.d.ts +55 -0
  180. package/dist/runtime/utils/permissionMatrix.js +85 -0
  181. package/dist/runtime/utils/persistedState.d.ts +25 -0
  182. package/dist/runtime/utils/persistedState.js +47 -0
  183. package/dist/runtime/utils/queryState.d.ts +45 -0
  184. package/dist/runtime/utils/queryState.js +75 -0
  185. package/dist/runtime/utils/requestLimits.d.ts +2 -0
  186. package/dist/runtime/utils/requestLimits.js +4 -0
  187. package/dist/runtime/utils/resultChart.d.ts +32 -0
  188. package/dist/runtime/utils/resultChart.js +59 -0
  189. package/dist/runtime/utils/savedPipelines.d.ts +22 -0
  190. package/dist/runtime/utils/savedPipelines.js +46 -0
  191. package/dist/runtime/utils/savedQueries.d.ts +60 -0
  192. package/dist/runtime/utils/savedQueries.js +143 -0
  193. package/dist/runtime/utils/schemaAnalysis.d.ts +16 -0
  194. package/dist/runtime/utils/schemaAnalysis.js +57 -0
  195. package/dist/runtime/utils/serverError.d.ts +19 -0
  196. package/dist/runtime/utils/serverError.js +19 -0
  197. package/dist/runtime/utils/serverOverview.d.ts +47 -0
  198. package/dist/runtime/utils/serverOverview.js +40 -0
  199. package/dist/runtime/utils/sessionGuard.d.ts +3 -0
  200. package/dist/runtime/utils/sessionGuard.js +18 -1
  201. package/package.json +12 -11
@@ -0,0 +1,38 @@
1
+ import { isProtectedCollection } from "./collectionProtection.js";
2
+ export const MAX_COPY_DOCUMENTS = 5e4;
3
+ export const MAX_COLLECTION_NAME_LENGTH = 100;
4
+ const ALLOWED_NAME = /^\w[\w.-]*$/;
5
+ export function validateTargetName(name, source, existing) {
6
+ const target = name.trim();
7
+ if (target === "") return "empty";
8
+ if (target.length > MAX_COLLECTION_NAME_LENGTH) return "too-long";
9
+ if (!ALLOWED_NAME.test(target)) return "invalid-characters";
10
+ if (isProtectedCollection(target) || target.startsWith("system.")) return "protected";
11
+ if (target.toLowerCase() === source.toLowerCase()) return "same-as-source";
12
+ if (existing.some((e) => e.toLowerCase() === target.toLowerCase())) return "exists";
13
+ return void 0;
14
+ }
15
+ export function canCopyCollection(name) {
16
+ return !isProtectedCollection(name) && !name.startsWith("system.");
17
+ }
18
+ const pad = (n, width = 2) => String(n).padStart(width, "0");
19
+ export function backupStamp(now) {
20
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
21
+ }
22
+ export function backupName(source, existing, now = /* @__PURE__ */ new Date()) {
23
+ const taken = new Set(existing.map((e) => e.toLowerCase()));
24
+ const cleaned = source.replace(/[^\w.-]/g, "_").replace(/^[.-]+/, "") || "collection";
25
+ const stamp = backupStamp(now);
26
+ for (let attempt = 1; ; attempt++) {
27
+ const suffix = `_backup_${stamp}${attempt > 1 ? `_${attempt}` : ""}`;
28
+ const name = `${cleaned.slice(0, MAX_COLLECTION_NAME_LENGTH - suffix.length)}${suffix}`;
29
+ if (!taken.has(name.toLowerCase())) return name;
30
+ }
31
+ }
32
+ export class CollectionNotCopyableError extends Error {
33
+ constructor(collection) {
34
+ super(`Collection "${collection}" cannot be copied`);
35
+ this.collection = collection;
36
+ this.name = "CollectionNotCopyableError";
37
+ }
38
+ }
@@ -0,0 +1,31 @@
1
+ import type { CollectionStatus } from '@sfxcode/nuxt-mongocamp-server';
2
+ export interface CollectionStorage {
3
+ collectionType: string;
4
+ /** Number of documents. */
5
+ count: number;
6
+ /** Uncompressed size of the documents, in bytes. */
7
+ size: number;
8
+ /** Size on disk (compressed), in bytes. */
9
+ storageSize: number;
10
+ avgObjSize: number;
11
+ indexCount: number;
12
+ /** Bytes per index name. */
13
+ indexSizes: Record<string, number>;
14
+ totalIndexSize: number;
15
+ }
16
+ export interface IndexUsage {
17
+ name: string;
18
+ /** The indexed fields, e.g. `{ name: 1 }`. */
19
+ key: Record<string, unknown>;
20
+ /** Operations that used the index since `since` (counted per server start). */
21
+ ops: number;
22
+ /** ISO time the counter started; `null` when the server did not say. */
23
+ since: string | null;
24
+ /** No operation has used it since `since` — a candidate to drop (never the `_id_` index). */
25
+ unused: boolean;
26
+ }
27
+ /** A non-negative finite number, else 0 (a missing or malformed number is not worth failing a card for). */
28
+ export declare function toCount(value: unknown): number;
29
+ export declare function mapStorage(status: Partial<CollectionStatus>): CollectionStorage;
30
+ /** Rows of a `$indexStats` aggregation (already unwrapped, `host`/`ns` stripped) as typed usage; rows without a name are skipped. */
31
+ export declare function mapIndexUsage(rows: Array<Record<string, unknown>>): IndexUsage[];
@@ -0,0 +1,42 @@
1
+ export function toCount(value) {
2
+ const n = typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
3
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : 0;
4
+ }
5
+ export function mapStorage(status) {
6
+ const indexSizes = {};
7
+ for (const [name, size] of Object.entries(status.indexSizes ?? {})) indexSizes[name] = toCount(size);
8
+ return {
9
+ collectionType: typeof status.collectionType === "string" ? status.collectionType : "",
10
+ count: toCount(status.count),
11
+ size: toCount(status.size),
12
+ storageSize: toCount(status.storageSize),
13
+ avgObjSize: toCount(status.avgObjSize),
14
+ indexCount: toCount(status.nindexes),
15
+ indexSizes,
16
+ totalIndexSize: toCount(status.totalIndexSize)
17
+ };
18
+ }
19
+ function isRecord(value) {
20
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21
+ }
22
+ function isoOrNull(value) {
23
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.toISOString();
24
+ if (typeof value === "string" && !Number.isNaN(Date.parse(value))) return value;
25
+ return null;
26
+ }
27
+ export function mapIndexUsage(rows) {
28
+ const out = [];
29
+ for (const row of rows) {
30
+ if (typeof row.name !== "string" || row.name === "") continue;
31
+ const accesses = isRecord(row.accesses) ? row.accesses : {};
32
+ const ops = toCount(accesses.ops);
33
+ out.push({
34
+ name: row.name,
35
+ key: isRecord(row.key) ? row.key : {},
36
+ ops,
37
+ since: isoOrNull(accesses.since),
38
+ unused: ops === 0
39
+ });
40
+ }
41
+ return out;
42
+ }
@@ -0,0 +1,48 @@
1
+ export type PaletteKind = 'collection' | 'bucket' | 'user' | 'role' | 'job' | 'action';
2
+ export interface PaletteEntry {
3
+ /** Unique, e.g. `collection:orders` */
4
+ id: string;
5
+ kind: PaletteKind;
6
+ label: string;
7
+ description?: string;
8
+ icon: string;
9
+ /** Route to open; absent for actions without a page */
10
+ to?: string;
11
+ /** Set for actions that are not navigation (`refresh`, `logout`) */
12
+ action?: 'refresh' | 'logout';
13
+ }
14
+ export interface PalettePaths {
15
+ /** `<collectionPath>/<name>/data` */
16
+ collectionPath: string;
17
+ /** `<bucketPath>/<bucket>` */
18
+ bucketPath: string;
19
+ usersPath: string;
20
+ /** `<rolePath>/<name>` (the grants page) */
21
+ rolePath: string;
22
+ jobsPath: string;
23
+ settingsPath: string;
24
+ accountPath: string;
25
+ }
26
+ export interface PaletteData {
27
+ collections?: string[];
28
+ users?: string[];
29
+ roles?: string[];
30
+ jobs?: {
31
+ name: string;
32
+ group: string;
33
+ }[];
34
+ }
35
+ /** A cache entry is reusable while younger than the TTL; a clock that went backwards counts as stale. */
36
+ export declare function isFresh(loadedAt: number | undefined, now: number, ttlMs: number): boolean;
37
+ /**
38
+ * Everything the palette can jump to. `canRead` hides collections the user may not read (UI-level, fail-open);
39
+ * `mc_*` collections and GridFS halves never appear as collections — a `<name>.files` becomes a bucket entry.
40
+ */
41
+ export declare function buildEntries(data: PaletteData, paths: PalettePaths, options?: {
42
+ canRead?: (collection: string) => boolean;
43
+ }): PaletteEntry[];
44
+ /** The fixed actions; settings is for administrators only. */
45
+ export declare function buildActions(paths: PalettePaths, options: {
46
+ isAdmin: boolean;
47
+ canLogout?: boolean;
48
+ }): PaletteEntry[];
@@ -0,0 +1,39 @@
1
+ import { isBucketMemberCollection } from "./collectionProtection.js";
2
+ const join = (base, ...parts) => [base.replace(/\/+$/, ""), ...parts.map(encodeURIComponent)].join("/");
3
+ export function isFresh(loadedAt, now, ttlMs) {
4
+ return loadedAt !== void 0 && now >= loadedAt && now - loadedAt < ttlMs;
5
+ }
6
+ export function buildEntries(data, paths, options = {}) {
7
+ const canRead = options.canRead ?? (() => true);
8
+ const entries = [];
9
+ for (const name of data.collections ?? []) {
10
+ if (name.startsWith("mc_")) continue;
11
+ if (name.endsWith(".files")) {
12
+ if (!canRead(name)) continue;
13
+ const bucket = name.slice(0, -".files".length);
14
+ entries.push({ id: `bucket:${bucket}`, kind: "bucket", label: bucket, icon: "i-lucide-folder-archive", to: join(paths.bucketPath, bucket) });
15
+ continue;
16
+ }
17
+ if (isBucketMemberCollection(name) || !canRead(name)) continue;
18
+ entries.push({ id: `collection:${name}`, kind: "collection", label: name, icon: "i-lucide-database", to: join(paths.collectionPath, name, "data") });
19
+ }
20
+ for (const user of data.users ?? []) {
21
+ entries.push({ id: `user:${user}`, kind: "user", label: user, icon: "i-lucide-user", to: paths.usersPath });
22
+ }
23
+ for (const role of data.roles ?? []) {
24
+ entries.push({ id: `role:${role}`, kind: "role", label: role, icon: "i-lucide-shield", to: join(paths.rolePath, role) });
25
+ }
26
+ for (const job of data.jobs ?? []) {
27
+ entries.push({ id: `job:${job.group}/${job.name}`, kind: "job", label: job.name, description: job.group, icon: "i-lucide-clock", to: paths.jobsPath });
28
+ }
29
+ return entries;
30
+ }
31
+ export function buildActions(paths, options) {
32
+ const actions = [
33
+ { id: "action:account", kind: "action", label: "account", icon: "i-lucide-user-cog", to: paths.accountPath }
34
+ ];
35
+ if (options.isAdmin) actions.push({ id: "action:settings", kind: "action", label: "settings", icon: "i-lucide-settings", to: paths.settingsPath });
36
+ actions.push({ id: "action:refresh", kind: "action", label: "refresh", icon: "i-lucide-refresh-cw", action: "refresh" });
37
+ if (options.canLogout ?? true) actions.push({ id: "action:logout", kind: "action", label: "logout", icon: "i-lucide-log-out", action: "logout" });
38
+ return actions;
39
+ }
@@ -0,0 +1,31 @@
1
+ import type { PathValueType } from './documentPaths.js';
2
+ export type CompareStatus = 'same' | 'changed' | 'added' | 'removed';
3
+ export interface CompareRow {
4
+ path: string;
5
+ status: CompareStatus;
6
+ /** Plain (unwrapped) values; absent on the side that lacks the path */
7
+ left?: unknown;
8
+ right?: unknown;
9
+ leftType?: PathValueType;
10
+ rightType?: PathValueType;
11
+ /** Same text on both sides but a different BSON type (`1` vs `"1"`, long vs int) */
12
+ typeDiffers?: boolean;
13
+ }
14
+ export interface CompareResult {
15
+ rows: CompareRow[];
16
+ counts: Record<CompareStatus, number>;
17
+ /** One of the documents was larger than the path limit */
18
+ truncated: boolean;
19
+ }
20
+ /** A leaf as a plain value: wrappers unwrapped, Date → ISO text, BigInt → digits. */
21
+ export declare function plainValue(value: unknown): unknown;
22
+ /**
23
+ * Path-level comparison of two documents. Both are flattened (arrays by index, an extended-JSON wrapper is one leaf),
24
+ * so `{ $oid }`/`{ $date }`/`{ $numberLong }` compare as the plain values the table shows. Rows follow the left
25
+ * document's order, paths only the right one has come after. A key's order inside an object is not a difference.
26
+ */
27
+ export declare function compareDocuments(left: unknown, right: unknown, options?: {
28
+ maxEntries?: number;
29
+ }): CompareResult;
30
+ /** Short text of a leaf for a table cell. */
31
+ export declare function compareText(value: unknown): string;
@@ -0,0 +1,70 @@
1
+ import { unwrapExtendedJson } from "../composables/useMongocampExtendedJson.js";
2
+ import { flattenDocument } from "./documentPaths.js";
3
+ const FULL_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
4
+ export function plainValue(value) {
5
+ if (value instanceof Date) return value.toISOString();
6
+ if (typeof value === "bigint") return value.toString();
7
+ return unwrapExtendedJson(value);
8
+ }
9
+ const WRAPPED_AS_TEXT = /* @__PURE__ */ new Set(["objectId", "date", "long", "decimal"]);
10
+ const NUMERIC = /* @__PURE__ */ new Set(["number", "int", "long", "double", "decimal"]);
11
+ function typesAgree(a, b) {
12
+ if (a === b) return true;
13
+ if (NUMERIC.has(a) && NUMERIC.has(b)) return true;
14
+ return a === "string" && WRAPPED_AS_TEXT.has(b) || b === "string" && WRAPPED_AS_TEXT.has(a);
15
+ }
16
+ function leafEqual(a, b) {
17
+ if (a === b) return true;
18
+ if (typeof a === "string" && typeof b === "string") {
19
+ return FULL_TIMESTAMP.test(a) && FULL_TIMESTAMP.test(b) && Date.parse(a) === Date.parse(b);
20
+ }
21
+ if (Array.isArray(a) && Array.isArray(b)) return a.length === 0 && b.length === 0;
22
+ if (typeof a === "object" && typeof b === "object" && a && b && !Array.isArray(a) && !Array.isArray(b)) {
23
+ return Object.keys(a).length === 0 && Object.keys(b).length === 0;
24
+ }
25
+ return false;
26
+ }
27
+ function withoutEmptyRoot(result) {
28
+ return { ...result, entries: result.entries.filter((e) => e.path !== "" || e.type !== "object" && e.type !== "array") };
29
+ }
30
+ export function compareDocuments(left, right, options = {}) {
31
+ const a = withoutEmptyRoot(flattenDocument(left, { maxEntries: options.maxEntries }));
32
+ const b = withoutEmptyRoot(flattenDocument(right, { maxEntries: options.maxEntries }));
33
+ const rightByPath = new Map(b.entries.map((e) => [e.path, e]));
34
+ const seen = /* @__PURE__ */ new Set();
35
+ const rows = [];
36
+ for (const entry of a.entries) {
37
+ seen.add(entry.path);
38
+ const other = rightByPath.get(entry.path);
39
+ const l = plainValue(entry.value);
40
+ if (!other) {
41
+ rows.push({ path: entry.path, status: "removed", left: l, leftType: entry.type });
42
+ continue;
43
+ }
44
+ const r = plainValue(other.value);
45
+ const equal = leafEqual(l, r);
46
+ const typeDiffers = !typesAgree(entry.type, other.type) && String(l) === String(r);
47
+ rows.push({
48
+ path: entry.path,
49
+ status: equal && !typeDiffers ? "same" : "changed",
50
+ left: l,
51
+ right: r,
52
+ leftType: entry.type,
53
+ rightType: other.type,
54
+ typeDiffers
55
+ });
56
+ }
57
+ for (const entry of b.entries) {
58
+ if (seen.has(entry.path)) continue;
59
+ rows.push({ path: entry.path, status: "added", right: plainValue(entry.value), rightType: entry.type });
60
+ }
61
+ const counts = { same: 0, changed: 0, added: 0, removed: 0 };
62
+ for (const row of rows) counts[row.status]++;
63
+ return { rows, counts, truncated: a.truncated || b.truncated };
64
+ }
65
+ export function compareText(value) {
66
+ if (value === null) return "null";
67
+ if (typeof value === "string") return value;
68
+ if (typeof value === "object") return JSON.stringify(value);
69
+ return String(value);
70
+ }
@@ -0,0 +1,19 @@
1
+ export interface DocumentChanges {
2
+ /** dotted path → new value (already in the wire shape the caller built, e.g. `{ $date }` wrappers kept) */
3
+ set: Record<string, unknown>;
4
+ /** dotted paths to remove */
5
+ unset: string[];
6
+ }
7
+ /**
8
+ * The minimal changes that turn `original` into `edited` (both whole documents, `_id` ignored): changed leaves as
9
+ * dotted keys, whole values for arrays and anything that is not a plain object on both sides, removed fields as
10
+ * unsets. Returns `null` when the change cannot be expressed as a partial update (a top-level field name that
11
+ * contains a dot or starts with `$`) — the caller then falls back to a full replace.
12
+ */
13
+ export declare function diffDocument(original: Record<string, unknown>, edited: Record<string, unknown>): DocumentChanges | null;
14
+ export declare function hasChanges(changes: DocumentChanges): boolean;
15
+ /**
16
+ * The request body for `updateDocumentPartial`. Plain fields and `$unset` may be mixed (verified). Never returns
17
+ * an empty body — the server answers an empty partial update with a 500 — so callers check `hasChanges` first.
18
+ */
19
+ export declare function buildPartialBody(changes: DocumentChanges): Record<string, unknown>;
@@ -0,0 +1,71 @@
1
+ import { unwrapExtendedJson } from "../composables/useMongocampExtendedJson.js";
2
+ function isPlainObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
4
+ }
5
+ function isWrapper(value) {
6
+ const keys = Object.keys(value);
7
+ return keys.length === 1 && keys[0].startsWith("$");
8
+ }
9
+ function isUnsafeKey(key) {
10
+ return key === "" || key.includes(".") || key.startsWith("$");
11
+ }
12
+ function normalize(value) {
13
+ if (value instanceof Date) return value.toISOString();
14
+ return unwrapExtendedJson(value);
15
+ }
16
+ const FULL_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
17
+ function sameInstant(a, b) {
18
+ return FULL_TIMESTAMP.test(a) && FULL_TIMESTAMP.test(b) && Date.parse(a) === Date.parse(b);
19
+ }
20
+ function deepEqual(a, b) {
21
+ if (a === b) return true;
22
+ if (typeof a === "string" && typeof b === "string") return sameInstant(a, b);
23
+ if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, i) => deepEqual(item, b[i]));
24
+ if (isPlainObject(a) && isPlainObject(b)) {
25
+ const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
26
+ return [...keys].every((key) => deepEqual(a[key], b[key]));
27
+ }
28
+ return false;
29
+ }
30
+ function canDescend(original, edited) {
31
+ if (!isPlainObject(original) || !isPlainObject(edited)) return false;
32
+ if (isWrapper(original) || isWrapper(edited)) return false;
33
+ return ![...Object.keys(original), ...Object.keys(edited)].some(isUnsafeKey);
34
+ }
35
+ function walk(original, edited, prefix, changes) {
36
+ for (const key of /* @__PURE__ */ new Set([...Object.keys(original), ...Object.keys(edited)])) {
37
+ if (prefix === "" && key === "_id") continue;
38
+ if (isUnsafeKey(key)) return false;
39
+ const path = prefix + key;
40
+ const hadIt = key in original;
41
+ const next = edited[key];
42
+ if (next === void 0) {
43
+ if (hadIt) changes.unset.push(path);
44
+ continue;
45
+ }
46
+ if (!hadIt) {
47
+ changes.set[path] = next;
48
+ continue;
49
+ }
50
+ const before = original[key];
51
+ if (deepEqual(normalize(before), normalize(next))) continue;
52
+ if (canDescend(before, next)) {
53
+ if (!walk(before, next, `${path}.`, changes)) return false;
54
+ continue;
55
+ }
56
+ changes.set[path] = next;
57
+ }
58
+ return true;
59
+ }
60
+ export function diffDocument(original, edited) {
61
+ const changes = { set: {}, unset: [] };
62
+ return walk(original, edited, "", changes) ? changes : null;
63
+ }
64
+ export function hasChanges(changes) {
65
+ return Object.keys(changes.set).length > 0 || changes.unset.length > 0;
66
+ }
67
+ export function buildPartialBody(changes) {
68
+ const body = { ...changes.set };
69
+ if (changes.unset.length > 0) body.$unset = Object.fromEntries(changes.unset.map((path) => [path, ""]));
70
+ return body;
71
+ }
@@ -0,0 +1,44 @@
1
+ export type PathValueType = 'null' | 'string' | 'boolean' | 'number' | 'int' | 'long' | 'double' | 'decimal' | 'objectId' | 'date' | 'array' | 'object';
2
+ export interface FlatEntry {
3
+ path: string;
4
+ type: PathValueType;
5
+ /** The leaf as stored: a wrapper stays one value (`{ $oid }` is not descended into); empty arrays/objects are leaves. */
6
+ value: unknown;
7
+ }
8
+ export interface FlattenOptions {
9
+ /** Deeper structures are returned as one `object`/`array` leaf (default 32). */
10
+ maxDepth?: number;
11
+ /** Stops after this many entries (default 10 000); `truncated` tells. */
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
+ }
16
+ export interface FlattenResult {
17
+ entries: FlatEntry[];
18
+ truncated: boolean;
19
+ }
20
+ /**
21
+ * What a value is, with extended-JSON wrappers recognised as their BSON type. A document the module has already read
22
+ * has no wrappers left (`_id` and dates are plain strings, a long a digit string), so `inferStrings` types a 24-hex
23
+ * string as `objectId` and a full ISO timestamp as `date` — a guess: an ordinary text of that shape is typed the same.
24
+ */
25
+ export declare function typeOf(value: unknown, options?: {
26
+ inferStrings?: boolean;
27
+ }): PathValueType;
28
+ /** Splits a path at its unescaped dots; `''` is the empty path (no segments). */
29
+ export declare function splitPath(path: string): string[];
30
+ export declare function joinPath(segments: Array<string | number>): string;
31
+ /**
32
+ * Every leaf of `doc` as `{ path, type, value }`, depth-first in key order. Arrays are walked by index, a wrapper is one
33
+ * leaf, an empty array/object is a leaf. The document is never changed.
34
+ */
35
+ export declare function flattenDocument(doc: unknown, options?: FlattenOptions): FlattenResult;
36
+ /** The value at `path`, or `undefined` when any part of it is missing. Never reads inherited properties. */
37
+ export declare function getPath(doc: unknown, path: string): unknown;
38
+ export declare function hasPath(doc: unknown, path: string): boolean;
39
+ /**
40
+ * A copy of `doc` with `value` at `path`; only the objects/arrays along the path are copied, the rest is shared. Missing
41
+ * intermediate objects are created, an array may be appended to at index `length`. Throws for a path through
42
+ * `__proto__`/`constructor`/`prototype`, a non-index segment in an array or an index beyond its end.
43
+ */
44
+ export declare function setPath<T extends Record<string, unknown>>(doc: T, path: string, value: unknown): T;
@@ -0,0 +1,144 @@
1
+ const DEFAULT_MAX_DEPTH = 32;
2
+ const DEFAULT_MAX_ENTRIES = 1e4;
3
+ const FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
4
+ function isPlainObject(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
6
+ }
7
+ const WRAPPER_TYPES = {
8
+ $oid: "objectId",
9
+ $date: "date",
10
+ $numberLong: "long",
11
+ $numberInt: "int",
12
+ $numberDouble: "double",
13
+ $numberDecimal: "decimal"
14
+ };
15
+ function wrapperType(value) {
16
+ const keys = Object.keys(value);
17
+ return keys.length === 1 ? WRAPPER_TYPES[keys[0]] : void 0;
18
+ }
19
+ const OBJECT_ID_TEXT = /^[0-9a-f]{24}$/i;
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 = {}) {
22
+ if (value === null || value === void 0) return "null";
23
+ if (Array.isArray(value)) return "array";
24
+ if (value instanceof Date) return "date";
25
+ switch (typeof value) {
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
+ return "string";
32
+ case "boolean":
33
+ return "boolean";
34
+ case "number":
35
+ return "number";
36
+ case "bigint":
37
+ return "long";
38
+ case "object":
39
+ return wrapperType(value) ?? "object";
40
+ default:
41
+ return "string";
42
+ }
43
+ }
44
+ function escapeSegment(key) {
45
+ return key.replace(/[\\.]/g, (m) => `\\${m}`);
46
+ }
47
+ export function splitPath(path) {
48
+ if (path === "") return [];
49
+ const segments = [];
50
+ let current = "";
51
+ for (let i = 0; i < path.length; i++) {
52
+ const char = path[i];
53
+ if (char === "\\" && i + 1 < path.length) {
54
+ current += path[++i];
55
+ } else if (char === ".") {
56
+ segments.push(current);
57
+ current = "";
58
+ } else {
59
+ current += char;
60
+ }
61
+ }
62
+ segments.push(current);
63
+ return segments;
64
+ }
65
+ export function joinPath(segments) {
66
+ return segments.map((s) => escapeSegment(String(s))).join(".");
67
+ }
68
+ export function flattenDocument(doc, options = {}) {
69
+ const maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;
70
+ const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
71
+ const inferStrings = options.inferStrings ?? false;
72
+ const entries = [];
73
+ let truncated = false;
74
+ const visit = (value, segments, depth) => {
75
+ if (truncated) return;
76
+ const type = typeOf(value, { inferStrings });
77
+ const container = type === "object" || type === "array";
78
+ const children = container ? Array.isArray(value) ? value.map((v, i) => [String(i), v]) : Object.entries(value) : [];
79
+ if (!container || children.length === 0 || depth >= maxDepth) {
80
+ if (entries.length >= maxEntries) {
81
+ truncated = true;
82
+ return;
83
+ }
84
+ entries.push({ path: joinPath(segments), type, value });
85
+ return;
86
+ }
87
+ for (const [key, child] of children) {
88
+ visit(child, [...segments, key], depth + 1);
89
+ if (truncated) return;
90
+ }
91
+ };
92
+ visit(doc, [], 0);
93
+ return { entries, truncated };
94
+ }
95
+ function childOf(container, segment) {
96
+ if (Array.isArray(container)) {
97
+ if (!/^(?:0|[1-9]\d*)$/.test(segment)) return { found: false };
98
+ const index = Number(segment);
99
+ return index < container.length ? { found: true, value: container[index] } : { found: false };
100
+ }
101
+ if (isPlainObject(container) && Object.hasOwn(container, segment) && !FORBIDDEN_SEGMENTS.has(segment)) {
102
+ return { found: true, value: container[segment] };
103
+ }
104
+ return { found: false };
105
+ }
106
+ export function getPath(doc, path) {
107
+ let current = doc;
108
+ for (const segment of splitPath(path)) {
109
+ const next = childOf(current, segment);
110
+ if (!next.found) return void 0;
111
+ current = next.value;
112
+ }
113
+ return current;
114
+ }
115
+ export function hasPath(doc, path) {
116
+ let current = doc;
117
+ for (const segment of splitPath(path)) {
118
+ const next = childOf(current, segment);
119
+ if (!next.found) return false;
120
+ current = next.value;
121
+ }
122
+ return true;
123
+ }
124
+ function setIn(container, segments, value) {
125
+ const [segment, ...rest] = segments;
126
+ if (segment === void 0) return value;
127
+ if (FORBIDDEN_SEGMENTS.has(segment)) throw new TypeError(`Refusing to set a path through "${segment}"`);
128
+ if (Array.isArray(container)) {
129
+ if (!/^(?:0|[1-9]\d*)$/.test(segment)) throw new TypeError(`"${segment}" is not an array index`);
130
+ const index = Number(segment);
131
+ if (index > container.length) throw new RangeError(`Index ${index} is beyond the end of an array of ${container.length}`);
132
+ const copy = [...container];
133
+ copy[index] = setIn(index < container.length ? container[index] : void 0, rest, value);
134
+ return copy;
135
+ }
136
+ const base = isPlainObject(container) ? container : {};
137
+ const own = Object.hasOwn(base, segment) ? base[segment] : void 0;
138
+ return { ...base, [segment]: setIn(own, rest, value) };
139
+ }
140
+ export function setPath(doc, path, value) {
141
+ const segments = splitPath(path);
142
+ if (segments.length === 0) throw new TypeError("A path is needed");
143
+ return setIn(doc, segments, value);
144
+ }
@@ -0,0 +1,40 @@
1
+ import type { PathValueType } from './documentPaths.js';
2
+ export interface TreeNode {
3
+ /** The key (an array index for an array element). */
4
+ key: string;
5
+ /** Dotted path, as `getPath` reads it. */
6
+ path: string;
7
+ depth: number;
8
+ type: PathValueType;
9
+ value: unknown;
10
+ /** `null` for a leaf (a scalar, a wrapper, or an empty container shown as `[]` / `{}`). */
11
+ children: TreeNode[] | null;
12
+ }
13
+ export interface DocumentTree {
14
+ nodes: TreeNode[];
15
+ /** Nodes built (leaves and containers). */
16
+ total: number;
17
+ /** The document was larger than `maxNodes`; the rest is not in the tree. */
18
+ truncated: boolean;
19
+ }
20
+ export declare const DEFAULT_MAX_NODES = 5000;
21
+ export declare const MAX_TREE_DEPTH = 32;
22
+ /** More nodes than this start fully collapsed; fewer open the first two levels. */
23
+ export declare const COLLAPSE_ABOVE_NODES = 200;
24
+ export declare const AUTO_EXPAND_DEPTH = 2;
25
+ export declare function buildDocumentTree(doc: unknown, options?: {
26
+ maxNodes?: number;
27
+ }): DocumentTree;
28
+ /** Paths of the containers that start open: depth 0 and 1 for a small document, none for a large one. */
29
+ export declare function defaultExpanded(tree: DocumentTree): Set<string>;
30
+ export declare function allContainerPaths(tree: DocumentTree): Set<string>;
31
+ /** The nodes to draw, in order: a node's children follow it only while its path is in `expanded`. */
32
+ export declare function visibleNodes(tree: DocumentTree, expanded: ReadonlySet<string>): TreeNode[];
33
+ /**
34
+ * The text for a node. A wrapper shows its content (`{ $oid }` → the id, `{ $numberLong }` → every digit), a container
35
+ * its size (`[3]`, `{2}`), an empty one `[]` / `{}`. `title` is a longer form where there is one (a date, localised).
36
+ */
37
+ export declare function nodeDisplay(node: TreeNode): {
38
+ text: string;
39
+ title?: string;
40
+ };