@sfxcode/nuxt-ui-mongocamp 1.3.4 → 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 (212) hide show
  1. package/README.md +4 -0
  2. package/dist/module.d.mts +8 -0
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +6 -0
  5. package/dist/runtime/components/MongocampAggregationBuilder.vue +302 -3
  6. package/dist/runtime/components/MongocampAggregationChart.d.vue.ts +6 -0
  7. package/dist/runtime/components/MongocampAggregationChart.vue +93 -0
  8. package/dist/runtime/components/MongocampAggregationChart.vue.d.ts +6 -0
  9. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +9 -0
  10. package/dist/runtime/components/MongocampAggregationStagePreview.vue +148 -0
  11. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +9 -0
  12. package/dist/runtime/components/MongocampBucketFiles.vue +169 -48
  13. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +19 -0
  14. package/dist/runtime/components/MongocampBulkDelete.vue +118 -23
  15. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +19 -0
  16. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +6 -0
  17. package/dist/runtime/components/MongocampBulkEdit.vue +23 -2
  18. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +6 -0
  19. package/dist/runtime/components/MongocampChart.d.vue.ts +29 -0
  20. package/dist/runtime/components/MongocampChart.vue +129 -0
  21. package/dist/runtime/components/MongocampChart.vue.d.ts +29 -0
  22. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +15 -0
  23. package/dist/runtime/components/MongocampCollectionCharts.vue +199 -0
  24. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +15 -0
  25. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +23 -0
  26. package/dist/runtime/components/MongocampCollectionCopy.vue +445 -0
  27. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +23 -0
  28. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -0
  29. package/dist/runtime/components/MongocampCollectionData.vue +343 -146
  30. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -0
  31. package/dist/runtime/components/MongocampCollectionInfos.vue +106 -238
  32. package/dist/runtime/components/MongocampCollections.vue +62 -0
  33. package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +40 -0
  34. package/dist/runtime/components/MongocampCommandPalette.vue +135 -0
  35. package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +40 -0
  36. package/dist/runtime/components/MongocampConfirmByName.vue +2 -2
  37. package/dist/runtime/components/MongocampDashboard.d.vue.ts +3 -1
  38. package/dist/runtime/components/MongocampDashboard.vue +21 -2
  39. package/dist/runtime/components/MongocampDashboard.vue.d.ts +3 -1
  40. package/dist/runtime/components/MongocampDatabases.vue +22 -0
  41. package/dist/runtime/components/MongocampDocumentCompare.d.vue.ts +20 -0
  42. package/dist/runtime/components/MongocampDocumentCompare.vue +146 -0
  43. package/dist/runtime/components/MongocampDocumentCompare.vue.d.ts +20 -0
  44. package/dist/runtime/components/MongocampDocumentView.d.vue.ts +22 -0
  45. package/dist/runtime/components/MongocampDocumentView.vue +202 -0
  46. package/dist/runtime/components/MongocampDocumentView.vue.d.ts +22 -0
  47. package/dist/runtime/components/MongocampErrorAlert.vue +12 -16
  48. package/dist/runtime/components/MongocampExportAll.d.vue.ts +18 -0
  49. package/dist/runtime/components/MongocampExportAll.vue +204 -0
  50. package/dist/runtime/components/MongocampExportAll.vue.d.ts +18 -0
  51. package/dist/runtime/components/MongocampFilePreview.d.vue.ts +16 -0
  52. package/dist/runtime/components/MongocampFilePreview.vue +162 -0
  53. package/dist/runtime/components/MongocampFilePreview.vue.d.ts +16 -0
  54. package/dist/runtime/components/MongocampFilterBuilder.vue +11 -0
  55. package/dist/runtime/components/MongocampImport.vue +2 -10
  56. package/dist/runtime/components/MongocampIndexes.d.vue.ts +18 -0
  57. package/dist/runtime/components/MongocampIndexes.vue +455 -0
  58. package/dist/runtime/components/MongocampIndexes.vue.d.ts +18 -0
  59. package/dist/runtime/components/MongocampJobs.d.vue.ts +6 -1
  60. package/dist/runtime/components/MongocampJobs.vue +24 -4
  61. package/dist/runtime/components/MongocampJobs.vue.d.ts +6 -1
  62. package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +12 -0
  63. package/dist/runtime/components/MongocampPermissionMatrix.vue +301 -0
  64. package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +12 -0
  65. package/dist/runtime/components/MongocampQueryBar.d.vue.ts +26 -0
  66. package/dist/runtime/components/MongocampQueryBar.vue +398 -0
  67. package/dist/runtime/components/MongocampQueryBar.vue.d.ts +26 -0
  68. package/dist/runtime/components/MongocampRoleGrants.vue +2 -2
  69. package/dist/runtime/components/MongocampRoles.vue +3 -3
  70. package/dist/runtime/components/MongocampServerOverview.d.vue.ts +20 -0
  71. package/dist/runtime/components/MongocampServerOverview.vue +443 -0
  72. package/dist/runtime/components/MongocampServerOverview.vue.d.ts +20 -0
  73. package/dist/runtime/components/MongocampSettings.d.vue.ts +25 -1
  74. package/dist/runtime/components/MongocampSettings.vue +70 -9
  75. package/dist/runtime/components/MongocampSettings.vue.d.ts +25 -1
  76. package/dist/runtime/components/MongocampUsers.vue +3 -3
  77. package/dist/runtime/composables/useMongocampAdmin.d.ts +2 -1
  78. package/dist/runtime/composables/useMongocampAdmin.js +7 -15
  79. package/dist/runtime/composables/useMongocampAggregation.d.ts +12 -1
  80. package/dist/runtime/composables/useMongocampAggregation.js +33 -25
  81. package/dist/runtime/composables/useMongocampAutoRefresh.d.ts +26 -0
  82. package/dist/runtime/composables/useMongocampAutoRefresh.js +78 -0
  83. package/dist/runtime/composables/useMongocampBucket.d.ts +13 -1
  84. package/dist/runtime/composables/useMongocampBucket.js +34 -0
  85. package/dist/runtime/composables/useMongocampClientApi.d.ts +1 -1
  86. package/dist/runtime/composables/useMongocampClientApi.js +2 -1
  87. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +85 -0
  88. package/dist/runtime/composables/useMongocampCollectionCopy.js +105 -0
  89. package/dist/runtime/composables/useMongocampCollectionStats.d.ts +10 -0
  90. package/dist/runtime/composables/useMongocampCollectionStats.js +17 -0
  91. package/dist/runtime/composables/useMongocampError.d.ts +2 -1
  92. package/dist/runtime/composables/useMongocampError.js +16 -1
  93. package/dist/runtime/composables/useMongocampExportAll.d.ts +47 -0
  94. package/dist/runtime/composables/useMongocampExportAll.js +27 -0
  95. package/dist/runtime/composables/useMongocampExtendedJson.d.ts +5 -1
  96. package/dist/runtime/composables/useMongocampExtendedJson.js +12 -6
  97. package/dist/runtime/composables/useMongocampFetchAll.d.ts +25 -0
  98. package/dist/runtime/composables/useMongocampFetchAll.js +27 -0
  99. package/dist/runtime/composables/useMongocampPermissions.d.ts +14 -0
  100. package/dist/runtime/composables/useMongocampPermissions.js +21 -0
  101. package/dist/runtime/composables/useMongocampPersistedState.d.ts +15 -0
  102. package/dist/runtime/composables/useMongocampPersistedState.js +21 -0
  103. package/dist/runtime/composables/useMongocampProxyApi.d.ts +1 -1
  104. package/dist/runtime/composables/useMongocampProxyApi.js +2 -1
  105. package/dist/runtime/composables/useMongocampQuery.d.ts +50 -2
  106. package/dist/runtime/composables/useMongocampQuery.js +72 -1
  107. package/dist/runtime/composables/useMongocampSavedPipelines.d.ts +25 -0
  108. package/dist/runtime/composables/useMongocampSavedPipelines.js +23 -0
  109. package/dist/runtime/composables/useMongocampSavedQueries.d.ts +37 -0
  110. package/dist/runtime/composables/useMongocampSavedQueries.js +50 -0
  111. package/dist/runtime/composables/useMongocampServerOverview.d.ts +42 -0
  112. package/dist/runtime/composables/useMongocampServerOverview.js +61 -0
  113. package/dist/runtime/composables/useMongocampSession.d.ts +3 -2
  114. package/dist/runtime/composables/useMongocampSession.js +14 -22
  115. package/dist/runtime/composables/useMongocampSystem.d.ts +7 -2
  116. package/dist/runtime/composables/useMongocampSystem.js +6 -2
  117. package/dist/runtime/locales/de.json +495 -10
  118. package/dist/runtime/locales/en.json +495 -10
  119. package/dist/runtime/plugin.js +8 -5
  120. package/dist/runtime/utils/aggregationPipeline.d.ts +5 -4
  121. package/dist/runtime/utils/aggregationPipeline.js +23 -9
  122. package/dist/runtime/utils/aggregationPreview.d.ts +13 -0
  123. package/dist/runtime/utils/aggregationPreview.js +10 -0
  124. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  125. package/dist/runtime/utils/aggregationResult.js +4 -0
  126. package/dist/runtime/utils/aggregationTemplates.d.ts +34 -0
  127. package/dist/runtime/utils/aggregationTemplates.js +47 -0
  128. package/dist/runtime/utils/analyzeSamples.d.ts +1 -0
  129. package/dist/runtime/utils/analyzeSamples.js +1 -1
  130. package/dist/runtime/utils/autoRefresh.d.ts +14 -0
  131. package/dist/runtime/utils/autoRefresh.js +15 -0
  132. package/dist/runtime/utils/bigIntJson.d.ts +15 -0
  133. package/dist/runtime/utils/bigIntJson.js +55 -0
  134. package/dist/runtime/utils/bulkDelete.d.ts +9 -1
  135. package/dist/runtime/utils/bulkDelete.js +15 -3
  136. package/dist/runtime/utils/bulkEdit.d.ts +6 -0
  137. package/dist/runtime/utils/bulkEdit.js +7 -0
  138. package/dist/runtime/utils/chartData.d.ts +11 -0
  139. package/dist/runtime/utils/chartData.js +9 -0
  140. package/dist/runtime/utils/collectionChart.d.ts +36 -0
  141. package/dist/runtime/utils/collectionChart.js +73 -0
  142. package/dist/runtime/utils/collectionCopy.d.ts +26 -0
  143. package/dist/runtime/utils/collectionCopy.js +38 -0
  144. package/dist/runtime/utils/collectionStats.d.ts +31 -0
  145. package/dist/runtime/utils/collectionStats.js +42 -0
  146. package/dist/runtime/utils/commandPalette.d.ts +48 -0
  147. package/dist/runtime/utils/commandPalette.js +39 -0
  148. package/dist/runtime/utils/createProxyMongocampApis.d.ts +2 -2
  149. package/dist/runtime/utils/createProxyMongocampApis.js +2 -2
  150. package/dist/runtime/utils/documentCompare.d.ts +31 -0
  151. package/dist/runtime/utils/documentCompare.js +70 -0
  152. package/dist/runtime/utils/documentDiff.d.ts +19 -0
  153. package/dist/runtime/utils/documentDiff.js +71 -0
  154. package/dist/runtime/utils/documentPaths.d.ts +44 -0
  155. package/dist/runtime/utils/documentPaths.js +144 -0
  156. package/dist/runtime/utils/documentTree.d.ts +40 -0
  157. package/dist/runtime/utils/documentTree.js +94 -0
  158. package/dist/runtime/utils/exportDocuments.d.ts +35 -0
  159. package/dist/runtime/utils/exportDocuments.js +54 -0
  160. package/dist/runtime/utils/exportRows.js +1 -1
  161. package/dist/runtime/utils/filePreview.d.ts +27 -0
  162. package/dist/runtime/utils/filePreview.js +50 -0
  163. package/dist/runtime/utils/filterBuilder.d.ts +6 -1
  164. package/dist/runtime/utils/filterBuilder.js +6 -5
  165. package/dist/runtime/utils/formatBytes.d.ts +2 -0
  166. package/dist/runtime/utils/formatBytes.js +11 -0
  167. package/dist/runtime/utils/grantMatching.d.ts +8 -0
  168. package/dist/runtime/utils/grantMatching.js +15 -0
  169. package/dist/runtime/utils/importRows.js +12 -2
  170. package/dist/runtime/utils/indexCopy.d.ts +26 -0
  171. package/dist/runtime/utils/indexCopy.js +22 -0
  172. package/dist/runtime/utils/indexForm.d.ts +69 -0
  173. package/dist/runtime/utils/indexForm.js +63 -0
  174. package/dist/runtime/utils/limitedMap.d.ts +17 -0
  175. package/dist/runtime/utils/limitedMap.js +19 -0
  176. package/dist/runtime/utils/luceneExpression.d.ts +15 -0
  177. package/dist/runtime/utils/luceneExpression.js +74 -0
  178. package/dist/runtime/utils/pagedFetch.d.ts +46 -0
  179. package/dist/runtime/utils/pagedFetch.js +58 -0
  180. package/dist/runtime/utils/paginationHeaders.d.ts +4 -0
  181. package/dist/runtime/utils/paginationHeaders.js +4 -0
  182. package/dist/runtime/utils/permissionDenied.d.ts +10 -0
  183. package/dist/runtime/utils/permissionDenied.js +23 -0
  184. package/dist/runtime/utils/permissionMatrix.d.ts +55 -0
  185. package/dist/runtime/utils/permissionMatrix.js +85 -0
  186. package/dist/runtime/utils/persistedState.d.ts +25 -0
  187. package/dist/runtime/utils/persistedState.js +47 -0
  188. package/dist/runtime/utils/queryState.d.ts +45 -0
  189. package/dist/runtime/utils/queryState.js +75 -0
  190. package/dist/runtime/utils/requestLimits.d.ts +2 -0
  191. package/dist/runtime/utils/requestLimits.js +4 -0
  192. package/dist/runtime/utils/resultChart.d.ts +32 -0
  193. package/dist/runtime/utils/resultChart.js +59 -0
  194. package/dist/runtime/utils/savedPipelines.d.ts +22 -0
  195. package/dist/runtime/utils/savedPipelines.js +46 -0
  196. package/dist/runtime/utils/savedQueries.d.ts +60 -0
  197. package/dist/runtime/utils/savedQueries.js +143 -0
  198. package/dist/runtime/utils/schemaAnalysis.d.ts +16 -0
  199. package/dist/runtime/utils/schemaAnalysis.js +57 -0
  200. package/dist/runtime/utils/serverError.d.ts +19 -0
  201. package/dist/runtime/utils/serverError.js +19 -0
  202. package/dist/runtime/utils/serverOverview.d.ts +47 -0
  203. package/dist/runtime/utils/serverOverview.js +40 -0
  204. package/dist/runtime/utils/sessionGuard.d.ts +3 -0
  205. package/dist/runtime/utils/sessionGuard.js +18 -1
  206. package/package.json +13 -12
  207. package/dist/runtime/utils/failureKind.d.ts +0 -3
  208. package/dist/runtime/utils/failureKind.js +0 -11
  209. package/dist/runtime/utils/serverProbe.d.ts +0 -10
  210. package/dist/runtime/utils/serverProbe.js +0 -25
  211. package/dist/runtime/utils/throttled.d.ts +0 -6
  212. package/dist/runtime/utils/throttled.js +0 -16
@@ -1,5 +1,6 @@
1
- export declare const FORBIDDEN_OPERATORS: readonly ["$out", "$merge", "$function", "$accumulator", "$where", "$lookup", "$unionWith", "$graphLookup"];
2
- export declare const VISUAL_STAGE_TYPES: readonly ["$match", "$group", "$sort", "$project", "$limit"];
1
+ export declare const FORBIDDEN_OPERATORS: readonly ["$out", "$merge", "$function", "$accumulator", "$where", "$lookup", "$unionWith", "$graphLookup", "$collStats", "$indexStats"];
2
+ export declare const STATS_OPERATORS: readonly ["$collStats", "$indexStats"];
3
+ export declare const VISUAL_STAGE_TYPES: readonly ["$match", "$group", "$sort", "$project", "$limit", "$unwind", "$addFields", "$count", "$bucketAuto"];
3
4
  export type AggregationStageType = typeof VISUAL_STAGE_TYPES[number];
4
5
  export interface AggregationStage {
5
6
  id: string;
@@ -29,12 +30,12 @@ export type ParsedPipeline = {
29
30
  ok: false;
30
31
  error: PipelineError;
31
32
  };
32
- export type StageIssueCode = 'not-object' | 'invalid-limit' | 'invalid-sort' | 'group-needs-id';
33
+ export type StageIssueCode = 'not-object' | 'invalid-limit' | 'invalid-sort' | 'group-needs-id' | 'invalid-unwind' | 'invalid-count' | 'bucket-needs-fields';
33
34
  export interface StageIssue {
34
35
  stageIndex: number;
35
36
  code: StageIssueCode;
36
37
  }
37
- export declare function findForbidden(pipeline: RequestStage[]): ForbiddenUse[];
38
+ export declare function findForbidden(pipeline: RequestStage[], allowed?: readonly string[]): ForbiddenUse[];
38
39
  export declare function buildPipeline(stages: AggregationStage[]): RequestStage[];
39
40
  export declare function validateStages(stages: AggregationStage[]): StageIssue[];
40
41
  export declare function parsePipeline(text: string): ParsedPipeline;
@@ -6,9 +6,12 @@ export const FORBIDDEN_OPERATORS = [
6
6
  "$where",
7
7
  "$lookup",
8
8
  "$unionWith",
9
- "$graphLookup"
9
+ "$graphLookup",
10
+ "$collStats",
11
+ "$indexStats"
10
12
  ];
11
- export const VISUAL_STAGE_TYPES = ["$match", "$group", "$sort", "$project", "$limit"];
13
+ export const STATS_OPERATORS = ["$collStats", "$indexStats"];
14
+ export const VISUAL_STAGE_TYPES = ["$match", "$group", "$sort", "$project", "$limit", "$unwind", "$addFields", "$count", "$bucketAuto"];
12
15
  const MAX_TEXT_LENGTH = 2e5;
13
16
  const MAX_STAGES = 50;
14
17
  const MAX_DEPTH = 64;
@@ -17,28 +20,29 @@ const FORBIDDEN = new Set(FORBIDDEN_OPERATORS);
17
20
  function isPlainObject(value) {
18
21
  return typeof value === "object" && value !== null && !Array.isArray(value);
19
22
  }
20
- function scan(value, path, depth, stageIndex, found) {
23
+ function scan(value, path, depth, stageIndex, found, forbidden) {
21
24
  if (found.length >= MAX_FINDINGS) return;
22
25
  if (depth > MAX_DEPTH) {
23
26
  found.push({ stageIndex, operator: "too-deep", path });
24
27
  return;
25
28
  }
26
29
  if (Array.isArray(value)) {
27
- value.forEach((item, i) => scan(item, `${path}[${i}]`, depth + 1, stageIndex, found));
30
+ value.forEach((item, i) => scan(item, `${path}[${i}]`, depth + 1, stageIndex, found, forbidden));
28
31
  return;
29
32
  }
30
33
  if (!isPlainObject(value)) return;
31
34
  for (const [key, inner] of Object.entries(value)) {
32
35
  const keyPath = `${path}.${key}`;
33
- if (FORBIDDEN.has(key)) found.push({ stageIndex, operator: key, path: keyPath });
34
- scan(inner, keyPath, depth + 1, stageIndex, found);
36
+ if (forbidden.has(key)) found.push({ stageIndex, operator: key, path: keyPath });
37
+ scan(inner, keyPath, depth + 1, stageIndex, found, forbidden);
35
38
  }
36
39
  }
37
- export function findForbidden(pipeline) {
40
+ export function findForbidden(pipeline, allowed = []) {
41
+ const forbidden = allowed.length > 0 ? new Set([...FORBIDDEN].filter((operator) => !allowed.includes(operator))) : FORBIDDEN;
38
42
  const found = [];
39
43
  pipeline.forEach((stage, stageIndex) => {
40
- if (FORBIDDEN.has(stage.stage)) found.push({ stageIndex, operator: stage.stage, path: stage.stage });
41
- scan(stage.value, stage.stage, 0, stageIndex, found);
44
+ if (forbidden.has(stage.stage)) found.push({ stageIndex, operator: stage.stage, path: stage.stage });
45
+ scan(stage.value, stage.stage, 0, stageIndex, found, forbidden);
42
46
  });
43
47
  return found;
44
48
  }
@@ -66,12 +70,22 @@ export function validateStages(stages) {
66
70
  if (typeof value !== "number" || !Number.isInteger(value) || value < 1) issues.push({ stageIndex, code: "invalid-limit" });
67
71
  return;
68
72
  }
73
+ if (type === "$unwind") {
74
+ const path = typeof value === "string" ? value : isPlainObject(value) ? value.path : void 0;
75
+ if (typeof path !== "string" || !path.startsWith("$") || path.length < 2) issues.push({ stageIndex, code: "invalid-unwind" });
76
+ return;
77
+ }
78
+ if (type === "$count") {
79
+ if (typeof value !== "string" || value.startsWith("$") || value.includes(".")) issues.push({ stageIndex, code: "invalid-count" });
80
+ return;
81
+ }
69
82
  if (!isPlainObject(value)) {
70
83
  issues.push({ stageIndex, code: "not-object" });
71
84
  return;
72
85
  }
73
86
  if (type === "$group" && !("_id" in value)) issues.push({ stageIndex, code: "group-needs-id" });
74
87
  if (type === "$sort" && !Object.values(value).every((direction) => direction === 1 || direction === -1)) issues.push({ stageIndex, code: "invalid-sort" });
88
+ if (type === "$bucketAuto" && (!("groupBy" in value) || typeof value.buckets !== "number" || !Number.isInteger(value.buckets) || value.buckets < 1)) issues.push({ stageIndex, code: "bucket-needs-fields" });
75
89
  });
76
90
  return issues;
77
91
  }
@@ -0,0 +1,13 @@
1
+ import type { AggregationStage, RequestStage } from './aggregationPipeline.js';
2
+ /** Documents shown under a stage. */
3
+ export declare const PREVIEW_LIMIT = 5;
4
+ /** Wait after the last keystroke before a preview is run again. */
5
+ export declare const PREVIEW_DEBOUNCE_MS = 500;
6
+ /**
7
+ * The request pipeline for the preview after stage `upTo` (0-based): every stage up to it, with stages that have nothing in
8
+ * them yet left out (as when running), then a `$limit` so the server never builds more than a few documents. A stage that
9
+ * is itself a `$limit` is kept as it is — the appended one only ever makes the result shorter.
10
+ */
11
+ export declare function previewPipeline(stages: AggregationStage[], upTo: number, limit?: number): RequestStage[];
12
+ /** A stable text for a pipeline, to tell whether a preview is out of date. */
13
+ export declare function pipelineKey(pipeline: RequestStage[]): string;
@@ -0,0 +1,10 @@
1
+ import { buildPipeline } from "./aggregationPipeline.js";
2
+ export const PREVIEW_LIMIT = 5;
3
+ export const PREVIEW_DEBOUNCE_MS = 500;
4
+ export function previewPipeline(stages, upTo, limit = PREVIEW_LIMIT) {
5
+ const prefix = buildPipeline(stages.slice(0, upTo + 1));
6
+ return [...prefix, { stage: "$limit", value: Math.max(1, Math.floor(limit)) }];
7
+ }
8
+ export function pipelineKey(pipeline) {
9
+ return JSON.stringify(pipeline);
10
+ }
@@ -3,3 +3,8 @@ export declare function formatCell(value: unknown): {
3
3
  text: string;
4
4
  full: string;
5
5
  };
6
+ /**
7
+ * Drops the server-only keys from the top level of every row. Meant for the results of a stats stage — a user document
8
+ * may legitimately have a `host` field, so this is not applied to ordinary aggregation results.
9
+ */
10
+ export declare function stripServerFields(rows: Record<string, unknown>[]): Record<string, unknown>[];
@@ -15,3 +15,7 @@ export function formatCell(value) {
15
15
  const full = value === void 0 ? "" : typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
16
16
  return { text: full.length > MAX_CELL_LENGTH ? `${full.slice(0, MAX_CELL_LENGTH - 1)}\u2026` : full, full };
17
17
  }
18
+ const SERVER_ONLY_KEYS = ["host", "ns"];
19
+ export function stripServerFields(rows) {
20
+ return rows.map((row) => Object.fromEntries(Object.entries(row).filter(([key]) => !SERVER_ONLY_KEYS.includes(key))));
21
+ }
@@ -0,0 +1,34 @@
1
+ import type { AggregationStageType } from './aggregationPipeline.js';
2
+ export type TemplateKey = 'count-by-field' | 'top-values' | 'date-histogram' | 'sum-avg-by-group';
3
+ export interface TemplateStage {
4
+ type: AggregationStageType;
5
+ value: unknown;
6
+ }
7
+ export type DateUnit = 'year' | 'month' | 'day';
8
+ export interface TemplateInput {
9
+ field: string;
10
+ /** `sum-avg-by-group`: the numeric field to add up and average. */
11
+ valueField?: string;
12
+ /** `top-values`: how many values to keep (default 10). */
13
+ top?: number;
14
+ /** `date-histogram`: the bucket size (default month). */
15
+ unit?: DateUnit;
16
+ }
17
+ export interface TemplateInfo {
18
+ key: TemplateKey;
19
+ /** Which inputs it needs besides `field`. */
20
+ needsValueField: boolean;
21
+ needsTop: boolean;
22
+ needsUnit: boolean;
23
+ }
24
+ export declare const TEMPLATES: readonly TemplateInfo[];
25
+ export declare const DEFAULT_TOP = 10;
26
+ export declare const MAX_TOP = 1000;
27
+ export declare const DATE_FORMATS: Record<DateUnit, string>;
28
+ /** A field name that can be written as `$name` in a pipeline: not empty, no `$`, no NUL, no leading/trailing/double dot. */
29
+ export declare function isTemplateField(field: string): boolean;
30
+ export type TemplateProblem = 'field' | 'value-field' | 'top';
31
+ /** What is wrong with the input of a template, or `undefined`. */
32
+ export declare function validateTemplateInput(key: TemplateKey, input: TemplateInput): TemplateProblem | undefined;
33
+ /** The stages of a template. Throws for invalid input — check `validateTemplateInput` first. */
34
+ export declare function templateStages(key: TemplateKey, input: TemplateInput): TemplateStage[];
@@ -0,0 +1,47 @@
1
+ export const TEMPLATES = [
2
+ { key: "count-by-field", needsValueField: false, needsTop: false, needsUnit: false },
3
+ { key: "top-values", needsValueField: false, needsTop: true, needsUnit: false },
4
+ { key: "date-histogram", needsValueField: false, needsTop: false, needsUnit: true },
5
+ { key: "sum-avg-by-group", needsValueField: true, needsTop: false, needsUnit: false }
6
+ ];
7
+ export const DEFAULT_TOP = 10;
8
+ export const MAX_TOP = 1e3;
9
+ export const DATE_FORMATS = { year: "%Y", month: "%Y-%m", day: "%Y-%m-%d" };
10
+ export function isTemplateField(field) {
11
+ return field.trim() !== "" && !field.includes("$") && !field.includes("\0") && !/^\.|\.$|\.\./.test(field.trim());
12
+ }
13
+ export function validateTemplateInput(key, input) {
14
+ if (!isTemplateField(input.field)) return "field";
15
+ const info = TEMPLATES.find((t) => t.key === key);
16
+ if (info.needsValueField && !isTemplateField(input.valueField ?? "")) return "value-field";
17
+ if (info.needsTop && input.top !== void 0 && (!Number.isInteger(input.top) || input.top < 1 || input.top > MAX_TOP)) return "top";
18
+ return void 0;
19
+ }
20
+ export function templateStages(key, input) {
21
+ const problem = validateTemplateInput(key, input);
22
+ if (problem) throw new Error(`Invalid template input: ${problem}`);
23
+ const field = `$${input.field.trim()}`;
24
+ switch (key) {
25
+ case "count-by-field":
26
+ return [
27
+ { type: "$group", value: { _id: field, count: { $sum: 1 } } },
28
+ { type: "$sort", value: { count: -1 } }
29
+ ];
30
+ case "top-values":
31
+ return [
32
+ { type: "$group", value: { _id: field, count: { $sum: 1 } } },
33
+ { type: "$sort", value: { count: -1 } },
34
+ { type: "$limit", value: input.top ?? DEFAULT_TOP }
35
+ ];
36
+ case "date-histogram":
37
+ return [
38
+ { type: "$group", value: { _id: { $dateToString: { format: DATE_FORMATS[input.unit ?? "month"], date: field } }, count: { $sum: 1 } } },
39
+ { type: "$sort", value: { _id: 1 } }
40
+ ];
41
+ case "sum-avg-by-group":
42
+ return [
43
+ { type: "$group", value: { _id: field, total: { $sum: `$${input.valueField.trim()}` }, avg: { $avg: `$${input.valueField.trim()}` }, count: { $sum: 1 } } },
44
+ { type: "$sort", value: { _id: 1 } }
45
+ ];
46
+ }
47
+ }
@@ -24,4 +24,5 @@ export interface AnalyzeOptions {
24
24
  maxDistinctForTop?: number;
25
25
  }
26
26
  export declare function kindOf(value: unknown): ValueKind;
27
+ export declare function comparePaths(a: string, b: string): number;
27
28
  export declare function analyzeSamples(rows: unknown[], options?: AnalyzeOptions): SampleAnalysis;
@@ -15,7 +15,7 @@ export function kindOf(value) {
15
15
  function shorten(text) {
16
16
  return text.length > MAX_VALUE_LENGTH ? `${text.slice(0, MAX_VALUE_LENGTH - 1)}\u2026` : text;
17
17
  }
18
- function comparePaths(a, b) {
18
+ export function comparePaths(a, b) {
19
19
  if (a === "_id") return b === "_id" ? 0 : -1;
20
20
  if (b === "_id") return 1;
21
21
  const left = a.split(".");
@@ -0,0 +1,14 @@
1
+ /** A refresh interval below this is raised to it: a live view must not hammer the server. */
2
+ export declare const MIN_REFRESH_INTERVAL_MS = 1000;
3
+ export declare const DEFAULT_BACKOFF_FACTOR = 2;
4
+ /** Default ceiling of the delay after repeated failures. */
5
+ export declare const DEFAULT_BACKOFF_MAX_MS: number;
6
+ export interface BackoffOptions {
7
+ /** Delay multiplier per consecutive failure (default 2). */
8
+ factor?: number;
9
+ /** The delay never grows beyond this (default 5 minutes, never below the interval). */
10
+ maxMs?: number;
11
+ }
12
+ export declare function clampInterval(intervalMs: number): number;
13
+ /** The wait before the next load: the interval, multiplied per consecutive failure up to the ceiling. */
14
+ export declare function nextDelay(intervalMs: number, failures: number, backoff?: BackoffOptions | false): number;
@@ -0,0 +1,15 @@
1
+ export const MIN_REFRESH_INTERVAL_MS = 1e3;
2
+ export const DEFAULT_BACKOFF_FACTOR = 2;
3
+ export const DEFAULT_BACKOFF_MAX_MS = 5 * 60 * 1e3;
4
+ export function clampInterval(intervalMs) {
5
+ return Number.isFinite(intervalMs) ? Math.max(MIN_REFRESH_INTERVAL_MS, Math.floor(intervalMs)) : MIN_REFRESH_INTERVAL_MS;
6
+ }
7
+ export function nextDelay(intervalMs, failures, backoff = {}) {
8
+ const base = clampInterval(intervalMs);
9
+ if (backoff === false || failures <= 0) return base;
10
+ const factor = Number.isFinite(backoff.factor) && backoff.factor > 1 ? backoff.factor : DEFAULT_BACKOFF_FACTOR;
11
+ const max = Math.max(base, backoff.maxMs ?? DEFAULT_BACKOFF_MAX_MS);
12
+ let delay = base;
13
+ for (let i = 0; i < failures && delay < max; i++) delay = Math.min(max, delay * factor);
14
+ return delay;
15
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `JSON.parse` that does not round integers a JS number cannot hold: every such integer literal outside a string
3
+ * becomes `{ "$numberLong": "<digits>" }`. Decimals, exponents, safe integers and everything inside strings are
4
+ * untouched. Throws like `JSON.parse` for invalid JSON.
5
+ */
6
+ export declare function parseJsonKeepingLongs(text: string): unknown;
7
+ /**
8
+ * The parsed body of an API response with large integers kept exact. Reads the text of a clone of the raw response, so
9
+ * the generated client's own `value()` still works; falls back to `value()` when there is no readable raw response
10
+ * (or the text is not JSON), which is also what a test double without a body gets.
11
+ */
12
+ export declare function readJsonKeepingLongs<T = unknown>(response: {
13
+ raw?: Response;
14
+ value: () => Promise<unknown>;
15
+ }): Promise<T>;
@@ -0,0 +1,55 @@
1
+ const MIN_UNSAFE_DIGITS = 16;
2
+ function isDigit(char) {
3
+ return char !== void 0 && char >= "0" && char <= "9";
4
+ }
5
+ export function parseJsonKeepingLongs(text) {
6
+ let result = "";
7
+ let copiedUpTo = 0;
8
+ let inString = false;
9
+ let i = 0;
10
+ while (i < text.length) {
11
+ const char = text[i];
12
+ if (inString) {
13
+ i += char === "\\" ? 2 : 1;
14
+ if (char === '"') inString = false;
15
+ continue;
16
+ }
17
+ if (char === '"') {
18
+ inString = true;
19
+ i++;
20
+ continue;
21
+ }
22
+ if (char !== "-" && !isDigit(char)) {
23
+ i++;
24
+ continue;
25
+ }
26
+ const start = i;
27
+ let end = char === "-" ? i + 1 : i;
28
+ const digitsStart = end;
29
+ while (isDigit(text[end])) end++;
30
+ const integerEnd = end;
31
+ if (text[end] === "." || text[end] === "e" || text[end] === "E") {
32
+ end++;
33
+ while (end < text.length && (isDigit(text[end]) || text[end] === "+" || text[end] === "-" || text[end] === "." || text[end] === "e" || text[end] === "E")) end++;
34
+ i = end;
35
+ continue;
36
+ }
37
+ const token = text.slice(start, integerEnd);
38
+ if (integerEnd - digitsStart >= MIN_UNSAFE_DIGITS && !Number.isSafeInteger(Number(token))) {
39
+ result += `${text.slice(copiedUpTo, start)}{"$numberLong":"${token}"}`;
40
+ copiedUpTo = integerEnd;
41
+ }
42
+ i = integerEnd;
43
+ }
44
+ return JSON.parse(result + text.slice(copiedUpTo));
45
+ }
46
+ export async function readJsonKeepingLongs(response) {
47
+ const raw = response.raw;
48
+ if (raw && typeof raw.clone === "function") {
49
+ try {
50
+ return parseJsonKeepingLongs(await raw.clone().text());
51
+ } catch {
52
+ }
53
+ }
54
+ return await response.value();
55
+ }
@@ -4,10 +4,18 @@ export interface BulkDeleteResult<T> {
4
4
  item: T;
5
5
  error: unknown;
6
6
  }[];
7
+ /** Only present after an abort: items that were never tried, so they are known to be untouched. */
8
+ notAttempted?: T[];
9
+ }
10
+ export interface BulkRunOptions {
11
+ /** Aborting stops before the next request; what already ran stays done and is reported. */
12
+ signal?: AbortSignal;
13
+ /** Called after every chunk / item with how many items have been dealt with so far. */
14
+ onProgress?: (done: number, total: number) => void;
7
15
  }
8
16
  export interface BulkRemoveMany<T> {
9
17
  run: (items: T[]) => Promise<number | undefined>;
10
18
  canHandle?: (item: T) => boolean;
11
19
  chunkSize?: number;
12
20
  }
13
- export declare function runBulkDelete<T>(items: T[], remove: (item: T) => Promise<unknown>, concurrency?: number, removeMany?: BulkRemoveMany<T>): Promise<BulkDeleteResult<T>>;
21
+ export declare function runBulkDelete<T>(items: T[], remove: (item: T) => Promise<unknown>, concurrency?: number, removeMany?: BulkRemoveMany<T>, options?: BulkRunOptions): Promise<BulkDeleteResult<T>>;
@@ -1,6 +1,12 @@
1
1
  const DEFAULT_CHUNK_SIZE = 100;
2
- export async function runBulkDelete(items, remove, concurrency = 5, removeMany) {
2
+ export async function runBulkDelete(items, remove, concurrency = 5, removeMany, options = {}) {
3
3
  const outcomes = Array.from({ length: items.length });
4
+ const { signal, onProgress } = options;
5
+ let done = 0;
6
+ const advance = (count) => {
7
+ done += count;
8
+ onProgress?.(done, items.length);
9
+ };
4
10
  const individually = [];
5
11
  if (removeMany) {
6
12
  const chunkSize = Math.max(1, Math.floor(removeMany.chunkSize ?? DEFAULT_CHUNK_SIZE) || DEFAULT_CHUNK_SIZE);
@@ -10,11 +16,13 @@ export async function runBulkDelete(items, remove, concurrency = 5, removeMany)
10
16
  else individually.push(index);
11
17
  });
12
18
  for (let start = 0; start < batched.length; start += chunkSize) {
19
+ if (signal?.aborted) break;
13
20
  const indexes = batched.slice(start, start + chunkSize);
14
21
  try {
15
22
  const deletedCount = await removeMany.run(indexes.map((i) => items[i]));
16
23
  if (typeof deletedCount === "number" && deletedCount >= indexes.length) {
17
24
  for (const i of indexes) outcomes[i] = { ok: true };
25
+ advance(indexes.length);
18
26
  continue;
19
27
  }
20
28
  } catch {
@@ -26,7 +34,7 @@ export async function runBulkDelete(items, remove, concurrency = 5, removeMany)
26
34
  }
27
35
  let next = 0;
28
36
  async function worker() {
29
- while (next < individually.length) {
37
+ while (next < individually.length && !signal?.aborted) {
30
38
  const index = individually[next++];
31
39
  try {
32
40
  await remove(items[index]);
@@ -34,14 +42,18 @@ export async function runBulkDelete(items, remove, concurrency = 5, removeMany)
34
42
  } catch (error) {
35
43
  outcomes[index] = { ok: false, error };
36
44
  }
45
+ advance(1);
37
46
  }
38
47
  }
39
48
  await Promise.all(Array.from({ length: Math.min(concurrency, individually.length) }, worker));
40
49
  const result = { deleted: [], failed: [] };
50
+ const notAttempted = [];
41
51
  items.forEach((item, index) => {
42
52
  const outcome = outcomes[index];
43
- if (outcome.ok) result.deleted.push(item);
53
+ if (!outcome) notAttempted.push(item);
54
+ else if (outcome.ok) result.deleted.push(item);
44
55
  else result.failed.push({ item, error: outcome.error });
45
56
  });
57
+ if (notAttempted.length > 0) result.notAttempted = notAttempted;
46
58
  return result;
47
59
  }
@@ -14,9 +14,15 @@ export interface BulkUpdateFailure {
14
14
  export interface BulkUpdateResult {
15
15
  updated: string[];
16
16
  failed: BulkUpdateFailure[];
17
+ /** Only present after an abort: ids that were never tried, so they are known to be untouched. */
18
+ notAttempted?: string[];
17
19
  }
18
20
  export interface BulkUpdateOptions {
19
21
  chunkSize?: number;
22
+ /** Aborting stops before the next chunk; what already ran stays done and is reported. */
23
+ signal?: AbortSignal;
24
+ /** Called after every chunk with how many ids have been dealt with so far. */
25
+ onProgress?: (done: number, total: number) => void;
20
26
  }
21
27
  export declare function isEditableField(field: string): boolean;
22
28
  export declare function buildIdFilter(ids: string[]): {
@@ -29,7 +29,12 @@ export async function runBulkUpdate(ids, updateMany, options = {}) {
29
29
  const result = { updated: [], failed: [] };
30
30
  const addressable = ids.filter((id) => isObjectIdHex(id));
31
31
  const others = ids.filter((id) => !isObjectIdHex(id));
32
+ let done = 0;
32
33
  for (let start = 0; start < addressable.length; start += chunkSize) {
34
+ if (options.signal?.aborted) {
35
+ result.notAttempted = addressable.slice(start);
36
+ break;
37
+ }
33
38
  const chunk = addressable.slice(start, start + chunkSize);
34
39
  try {
35
40
  const response = await updateMany(chunk);
@@ -39,6 +44,8 @@ export async function runBulkUpdate(ids, updateMany, options = {}) {
39
44
  } catch (error) {
40
45
  result.failed.push({ ids: chunk, error });
41
46
  }
47
+ done += chunk.length;
48
+ options.onProgress?.(done, ids.length);
42
49
  }
43
50
  for (const id of others) result.failed.push({ ids: [id], error: new BulkUnaddressableId(id) });
44
51
  return result;
@@ -0,0 +1,11 @@
1
+ export interface LabelledValue {
2
+ label: string;
3
+ value: number;
4
+ }
5
+ /** Shortens a label for an axis (`very-long-name` → `very-long-na…`); the full text stays in the data table. */
6
+ export declare function shortenLabel(label: string, max?: number): string;
7
+ /**
8
+ * The `n` biggest items plus one summed "other" item for the rest (only when something is left over).
9
+ * Keeps the input order of the top items by value, biggest first.
10
+ */
11
+ export declare function topNWithOther(items: LabelledValue[], n: number, otherLabel: string): LabelledValue[];
@@ -0,0 +1,9 @@
1
+ export function shortenLabel(label, max = 24) {
2
+ return label.length > max ? `${label.slice(0, Math.max(1, max - 1))}\u2026` : label;
3
+ }
4
+ export function topNWithOther(items, n, otherLabel) {
5
+ const sorted = [...items].sort((a, b) => b.value - a.value);
6
+ if (sorted.length <= n) return sorted;
7
+ const rest = sorted.slice(n).reduce((sum, item) => sum + item.value, 0);
8
+ return [...sorted.slice(0, n), { label: otherLabel, value: rest }];
9
+ }
@@ -0,0 +1,36 @@
1
+ import type { RequestStage } from './aggregationPipeline.js';
2
+ import type { DateUnit } from './aggregationTemplates.js';
3
+ import type { SampleAnalysis, ValueKind } from './analyzeSamples.js';
4
+ export type ChartKind = 'values' | 'dates' | 'numbers';
5
+ export interface ChartPoint {
6
+ label: string;
7
+ count: number;
8
+ }
9
+ export declare const DEFAULT_TOP = 10;
10
+ export declare const DEFAULT_BUCKETS = 10;
11
+ /** Periods of a date histogram that are drawn; more are cut (the first ones are kept) and the chart says so. */
12
+ export declare const MAX_PERIODS = 100;
13
+ /** Up to this many bars a date histogram is a bar chart, beyond it an area chart reads better. */
14
+ export declare const MAX_BAR_PERIODS = 36;
15
+ /** The chart a field of this (dominant) value kind gets, or `undefined` when none makes sense (objects, arrays, only nulls). */
16
+ export declare function chartKindFor(kind: ValueKind | undefined): ChartKind | undefined;
17
+ /** The most frequent value kind of a field in a sample analysis, ignoring `null`; `undefined` for an unknown field. */
18
+ export declare function dominantKind(analysis: SampleAnalysis, field: string): ValueKind | undefined;
19
+ export interface ChartRequest {
20
+ pipeline: RequestStage[];
21
+ /** How many rows the single page holds. */
22
+ rowsPerPage: number;
23
+ }
24
+ export interface ChartOptions {
25
+ top?: number;
26
+ buckets?: number;
27
+ unit?: DateUnit;
28
+ }
29
+ /** The request for a chart, or `undefined` when the field name cannot be used in a pipeline. */
30
+ export declare function chartRequest(kind: ChartKind, field: string, options?: ChartOptions): ChartRequest | undefined;
31
+ /** Rows of the aggregation as chart points. `noneLabel` names the group of documents without a value. */
32
+ export declare function rowsToPoints(kind: ChartKind, rows: Record<string, unknown>[], noneLabel: string): ChartPoint[];
33
+ /** Which UChart type draws it. */
34
+ export declare function chartTypeFor(kind: ChartKind, points: number): 'bar' | 'area';
35
+ /** The highest point (the first one on a tie), for the text description of a chart. */
36
+ export declare function highestPoint(points: ChartPoint[]): ChartPoint | undefined;
@@ -0,0 +1,73 @@
1
+ import { DATE_FORMATS, isTemplateField } from "./aggregationTemplates.js";
2
+ export const DEFAULT_TOP = 10;
3
+ export const DEFAULT_BUCKETS = 10;
4
+ export const MAX_PERIODS = 100;
5
+ export const MAX_BAR_PERIODS = 36;
6
+ export function chartKindFor(kind) {
7
+ switch (kind) {
8
+ case "string":
9
+ case "boolean":
10
+ return "values";
11
+ case "date":
12
+ return "dates";
13
+ case "number":
14
+ return "numbers";
15
+ default:
16
+ return void 0;
17
+ }
18
+ }
19
+ export function dominantKind(analysis, field) {
20
+ const stat = analysis.fields.find((f) => f.path === field);
21
+ return stat?.types.find((t) => t.type !== "null")?.type;
22
+ }
23
+ export function chartRequest(kind, field, options = {}) {
24
+ if (!isTemplateField(field)) return void 0;
25
+ const name = field.trim();
26
+ const path = `$${name}`;
27
+ if (kind === "values") {
28
+ return {
29
+ pipeline: [{ stage: "$group", value: { _id: path, count: { $sum: 1 } } }, { stage: "$sort", value: { count: -1, _id: 1 } }],
30
+ rowsPerPage: options.top ?? DEFAULT_TOP
31
+ };
32
+ }
33
+ if (kind === "dates") {
34
+ return {
35
+ pipeline: [
36
+ { stage: "$match", value: { [name]: { $type: "date" } } },
37
+ { stage: "$group", value: { _id: { $dateToString: { format: DATE_FORMATS[options.unit ?? "month"], date: path } }, count: { $sum: 1 } } },
38
+ { stage: "$sort", value: { _id: 1 } }
39
+ ],
40
+ rowsPerPage: MAX_PERIODS
41
+ };
42
+ }
43
+ return {
44
+ pipeline: [
45
+ { stage: "$match", value: { [name]: { $type: "number" } } },
46
+ { stage: "$bucketAuto", value: { groupBy: path, buckets: options.buckets ?? DEFAULT_BUCKETS } }
47
+ ],
48
+ rowsPerPage: options.buckets ?? DEFAULT_BUCKETS
49
+ };
50
+ }
51
+ function text(value) {
52
+ return typeof value === "string" ? value : JSON.stringify(value);
53
+ }
54
+ function countOf(row) {
55
+ const n = Number(row.count);
56
+ return Number.isFinite(n) ? n : 0;
57
+ }
58
+ export function rowsToPoints(kind, rows, noneLabel) {
59
+ return rows.map((row) => {
60
+ const id = row._id;
61
+ if (kind === "numbers") {
62
+ const range = typeof id === "object" && id !== null ? id : {};
63
+ return { label: `${text(range.min)}\u2013${text(range.max)}`, count: countOf(row) };
64
+ }
65
+ return { label: id === null || id === void 0 ? noneLabel : text(id), count: countOf(row) };
66
+ });
67
+ }
68
+ export function chartTypeFor(kind, points) {
69
+ return kind === "dates" && points > MAX_BAR_PERIODS ? "area" : "bar";
70
+ }
71
+ export function highestPoint(points) {
72
+ return points.reduce((best, p) => !best || p.count > best.count ? p : best, void 0);
73
+ }
@@ -0,0 +1,26 @@
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
+ export declare const MAX_COLLECTION_NAME_LENGTH = 100;
4
+ export type TargetNameProblem = 'empty' | 'too-long' | 'invalid-characters' | 'protected' | 'same-as-source' | 'exists';
5
+ /**
6
+ * What is wrong with a name for the new collection, or `undefined` when it is fine. `existing` is every collection the
7
+ * server lists; a name equal to one of them ignoring case counts as existing (grants match case-insensitively, so two
8
+ * names that differ only in case would be confusing even though MongoDB keeps them apart).
9
+ */
10
+ export declare function validateTargetName(name: string, source: string, existing: readonly string[]): TargetNameProblem | undefined;
11
+ /** A collection that may be copied: not MongoCamp's own, not a GridFS half (those need their other half). */
12
+ export declare function canCopyCollection(name: string): boolean;
13
+ /** `20261104_153045` — local date and time, sortable, safe in a collection name. */
14
+ export declare function backupStamp(now: Date): string;
15
+ /**
16
+ * The name of a quick backup of `source`: `<source>_backup_<yyyymmdd>_<hhmmss>`. Characters a new name may not contain are
17
+ * replaced by `_`, the source part is shortened to stay within the length limit, and when the name already exists (two
18
+ * backups in the same second, or one made earlier) `_2`, `_3`, … is appended. The result always passes `validateTargetName`
19
+ * for an ordinary source; for a source that cannot be copied (`canCopyCollection`) there is no backup name.
20
+ */
21
+ export declare function backupName(source: string, existing: readonly string[], now?: Date): string;
22
+ /** Thrown for a source that cannot be copied at all (MongoCamp's own collections, GridFS halves, `system.*`). */
23
+ export declare class CollectionNotCopyableError extends Error {
24
+ collection: string;
25
+ constructor(collection: string);
26
+ }