@sfxcode/nuxt-ui-mongocamp 1.3.5 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +1 -1
  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.d.vue.ts +1 -0
  6. package/dist/runtime/components/MongocampAggregationBuilder.vue +331 -5
  7. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +1 -0
  8. package/dist/runtime/components/MongocampAggregationChart.d.vue.ts +6 -0
  9. package/dist/runtime/components/MongocampAggregationChart.vue +93 -0
  10. package/dist/runtime/components/MongocampAggregationChart.vue.d.ts +6 -0
  11. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +10 -0
  12. package/dist/runtime/components/MongocampAggregationStagePreview.vue +149 -0
  13. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +10 -0
  14. package/dist/runtime/components/MongocampBucketFiles.vue +230 -48
  15. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +9 -0
  16. package/dist/runtime/components/MongocampBulkDelete.vue +94 -25
  17. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +9 -0
  18. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +5 -0
  19. package/dist/runtime/components/MongocampBulkEdit.vue +41 -3
  20. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +5 -0
  21. package/dist/runtime/components/MongocampChart.d.vue.ts +29 -0
  22. package/dist/runtime/components/MongocampChart.vue +129 -0
  23. package/dist/runtime/components/MongocampChart.vue.d.ts +29 -0
  24. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +17 -0
  25. package/dist/runtime/components/MongocampCollectionCharts.vue +200 -0
  26. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +17 -0
  27. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +23 -0
  28. package/dist/runtime/components/MongocampCollectionCopy.vue +206 -0
  29. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +23 -0
  30. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +6 -0
  31. package/dist/runtime/components/MongocampCollectionData.vue +423 -138
  32. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +6 -0
  33. package/dist/runtime/components/MongocampCollectionInfos.vue +106 -238
  34. package/dist/runtime/components/MongocampCollectionRename.d.vue.ts +22 -0
  35. package/dist/runtime/components/MongocampCollectionRename.vue +116 -0
  36. package/dist/runtime/components/MongocampCollectionRename.vue.d.ts +22 -0
  37. package/dist/runtime/components/MongocampCollections.vue +93 -12
  38. package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +40 -0
  39. package/dist/runtime/components/MongocampCommandPalette.vue +135 -0
  40. package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +40 -0
  41. package/dist/runtime/components/MongocampConfirmByName.vue +2 -2
  42. package/dist/runtime/components/MongocampDashboard.d.vue.ts +3 -1
  43. package/dist/runtime/components/MongocampDashboard.vue +39 -5
  44. package/dist/runtime/components/MongocampDashboard.vue.d.ts +3 -1
  45. package/dist/runtime/components/MongocampDatabases.vue +35 -2
  46. package/dist/runtime/components/MongocampDocumentCompare.d.vue.ts +20 -0
  47. package/dist/runtime/components/MongocampDocumentCompare.vue +146 -0
  48. package/dist/runtime/components/MongocampDocumentCompare.vue.d.ts +20 -0
  49. package/dist/runtime/components/MongocampDocumentView.d.vue.ts +22 -0
  50. package/dist/runtime/components/MongocampDocumentView.vue +202 -0
  51. package/dist/runtime/components/MongocampDocumentView.vue.d.ts +22 -0
  52. package/dist/runtime/components/MongocampErrorAlert.vue +12 -4
  53. package/dist/runtime/components/MongocampExportAll.d.vue.ts +18 -0
  54. package/dist/runtime/components/MongocampExportAll.vue +191 -0
  55. package/dist/runtime/components/MongocampExportAll.vue.d.ts +18 -0
  56. package/dist/runtime/components/MongocampFilePreview.d.vue.ts +16 -0
  57. package/dist/runtime/components/MongocampFilePreview.vue +162 -0
  58. package/dist/runtime/components/MongocampFilePreview.vue.d.ts +16 -0
  59. package/dist/runtime/components/MongocampFilterBuilder.vue +11 -0
  60. package/dist/runtime/components/MongocampImport.vue +171 -13
  61. package/dist/runtime/components/MongocampIndexes.d.vue.ts +18 -0
  62. package/dist/runtime/components/MongocampIndexes.vue +496 -0
  63. package/dist/runtime/components/MongocampIndexes.vue.d.ts +18 -0
  64. package/dist/runtime/components/MongocampJobs.d.vue.ts +6 -1
  65. package/dist/runtime/components/MongocampJobs.vue +36 -5
  66. package/dist/runtime/components/MongocampJobs.vue.d.ts +6 -1
  67. package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +12 -0
  68. package/dist/runtime/components/MongocampPermissionMatrix.vue +301 -0
  69. package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +12 -0
  70. package/dist/runtime/components/MongocampQueryBar.d.vue.ts +26 -0
  71. package/dist/runtime/components/MongocampQueryBar.vue +398 -0
  72. package/dist/runtime/components/MongocampQueryBar.vue.d.ts +26 -0
  73. package/dist/runtime/components/MongocampRoleGrants.vue +18 -5
  74. package/dist/runtime/components/MongocampRoles.vue +16 -5
  75. package/dist/runtime/components/MongocampServerOverview.d.vue.ts +20 -0
  76. package/dist/runtime/components/MongocampServerOverview.vue +420 -0
  77. package/dist/runtime/components/MongocampServerOverview.vue.d.ts +20 -0
  78. package/dist/runtime/components/MongocampSettings.d.vue.ts +28 -1
  79. package/dist/runtime/components/MongocampSettings.vue +83 -10
  80. package/dist/runtime/components/MongocampSettings.vue.d.ts +28 -1
  81. package/dist/runtime/components/MongocampUsers.vue +19 -6
  82. package/dist/runtime/composables/useMongocampAdmin.d.ts +2 -1
  83. package/dist/runtime/composables/useMongocampAdmin.js +6 -1
  84. package/dist/runtime/composables/useMongocampAdminGate.d.ts +12 -0
  85. package/dist/runtime/composables/useMongocampAdminGate.js +12 -0
  86. package/dist/runtime/composables/useMongocampAggregation.d.ts +23 -1
  87. package/dist/runtime/composables/useMongocampAggregation.js +41 -26
  88. package/dist/runtime/composables/useMongocampAutoRefresh.d.ts +26 -0
  89. package/dist/runtime/composables/useMongocampAutoRefresh.js +78 -0
  90. package/dist/runtime/composables/useMongocampBucket.d.ts +13 -1
  91. package/dist/runtime/composables/useMongocampBucket.js +34 -0
  92. package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +15 -0
  93. package/dist/runtime/composables/useMongocampBulkByFilter.js +32 -0
  94. package/dist/runtime/composables/useMongocampClientApi.js +2 -1
  95. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +45 -0
  96. package/dist/runtime/composables/useMongocampCollectionCopy.js +48 -0
  97. package/dist/runtime/composables/useMongocampCollectionStats.d.ts +10 -0
  98. package/dist/runtime/composables/useMongocampCollectionStats.js +17 -0
  99. package/dist/runtime/composables/useMongocampError.d.ts +2 -1
  100. package/dist/runtime/composables/useMongocampError.js +16 -1
  101. package/dist/runtime/composables/useMongocampExportAll.d.ts +53 -0
  102. package/dist/runtime/composables/useMongocampExportAll.js +57 -0
  103. package/dist/runtime/composables/useMongocampExtendedJson.d.ts +7 -2
  104. package/dist/runtime/composables/useMongocampExtendedJson.js +44 -11
  105. package/dist/runtime/composables/useMongocampFetchAll.d.ts +25 -0
  106. package/dist/runtime/composables/useMongocampFetchAll.js +27 -0
  107. package/dist/runtime/composables/useMongocampFieldTypes.d.ts +24 -0
  108. package/dist/runtime/composables/useMongocampFieldTypes.js +44 -0
  109. package/dist/runtime/composables/useMongocampImport.d.ts +4 -0
  110. package/dist/runtime/composables/useMongocampImport.js +5 -2
  111. package/dist/runtime/composables/useMongocampIndex.d.ts +6 -1
  112. package/dist/runtime/composables/useMongocampIndex.js +7 -1
  113. package/dist/runtime/composables/useMongocampPermissions.d.ts +17 -0
  114. package/dist/runtime/composables/useMongocampPermissions.js +43 -0
  115. package/dist/runtime/composables/useMongocampPersistedState.d.ts +15 -0
  116. package/dist/runtime/composables/useMongocampPersistedState.js +21 -0
  117. package/dist/runtime/composables/useMongocampProxyApi.js +2 -1
  118. package/dist/runtime/composables/useMongocampQuery.d.ts +50 -2
  119. package/dist/runtime/composables/useMongocampQuery.js +72 -1
  120. package/dist/runtime/composables/useMongocampSavedPipelines.d.ts +25 -0
  121. package/dist/runtime/composables/useMongocampSavedPipelines.js +23 -0
  122. package/dist/runtime/composables/useMongocampSavedQueries.d.ts +37 -0
  123. package/dist/runtime/composables/useMongocampSavedQueries.js +50 -0
  124. package/dist/runtime/composables/useMongocampServerOverview.d.ts +35 -0
  125. package/dist/runtime/composables/useMongocampServerOverview.js +51 -0
  126. package/dist/runtime/composables/useMongocampSession.d.ts +2 -0
  127. package/dist/runtime/composables/useMongocampSession.js +16 -2
  128. package/dist/runtime/composables/useMongocampSystem.d.ts +7 -2
  129. package/dist/runtime/composables/useMongocampSystem.js +6 -2
  130. package/dist/runtime/locales/de.json +509 -25
  131. package/dist/runtime/locales/en.json +509 -25
  132. package/dist/runtime/plugin.js +6 -3
  133. package/dist/runtime/utils/aggregationErrors.d.ts +4 -0
  134. package/dist/runtime/utils/aggregationErrors.js +7 -0
  135. package/dist/runtime/utils/aggregationPipeline.d.ts +5 -4
  136. package/dist/runtime/utils/aggregationPipeline.js +23 -9
  137. package/dist/runtime/utils/aggregationPreview.d.ts +13 -0
  138. package/dist/runtime/utils/aggregationPreview.js +10 -0
  139. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  140. package/dist/runtime/utils/aggregationResult.js +4 -0
  141. package/dist/runtime/utils/aggregationTemplates.d.ts +34 -0
  142. package/dist/runtime/utils/aggregationTemplates.js +47 -0
  143. package/dist/runtime/utils/analyzeSamples.d.ts +1 -0
  144. package/dist/runtime/utils/analyzeSamples.js +1 -1
  145. package/dist/runtime/utils/autoRefresh.d.ts +14 -0
  146. package/dist/runtime/utils/autoRefresh.js +15 -0
  147. package/dist/runtime/utils/batchInsert.d.ts +6 -0
  148. package/dist/runtime/utils/batchInsert.js +31 -3
  149. package/dist/runtime/utils/bigIntJson.d.ts +15 -0
  150. package/dist/runtime/utils/bigIntJson.js +55 -0
  151. package/dist/runtime/utils/bsonTypes.d.ts +10 -0
  152. package/dist/runtime/utils/bsonTypes.js +42 -0
  153. package/dist/runtime/utils/bulkDelete.d.ts +9 -1
  154. package/dist/runtime/utils/bulkDelete.js +15 -3
  155. package/dist/runtime/utils/bulkEdit.d.ts +6 -0
  156. package/dist/runtime/utils/bulkEdit.js +7 -0
  157. package/dist/runtime/utils/chartData.d.ts +11 -0
  158. package/dist/runtime/utils/chartData.js +9 -0
  159. package/dist/runtime/utils/collectionChart.d.ts +36 -0
  160. package/dist/runtime/utils/collectionChart.js +73 -0
  161. package/dist/runtime/utils/collectionCopy.d.ts +24 -0
  162. package/dist/runtime/utils/collectionCopy.js +37 -0
  163. package/dist/runtime/utils/collectionStats.d.ts +31 -0
  164. package/dist/runtime/utils/collectionStats.js +42 -0
  165. package/dist/runtime/utils/commandPalette.d.ts +48 -0
  166. package/dist/runtime/utils/commandPalette.js +39 -0
  167. package/dist/runtime/utils/configRows.d.ts +7 -0
  168. package/dist/runtime/utils/configRows.js +4 -0
  169. package/dist/runtime/utils/documentCompare.d.ts +31 -0
  170. package/dist/runtime/utils/documentCompare.js +71 -0
  171. package/dist/runtime/utils/documentDiff.d.ts +19 -0
  172. package/dist/runtime/utils/documentDiff.js +71 -0
  173. package/dist/runtime/utils/documentPaths.d.ts +41 -0
  174. package/dist/runtime/utils/documentPaths.js +139 -0
  175. package/dist/runtime/utils/documentTree.d.ts +40 -0
  176. package/dist/runtime/utils/documentTree.js +102 -0
  177. package/dist/runtime/utils/exportDocuments.d.ts +33 -0
  178. package/dist/runtime/utils/exportDocuments.js +53 -0
  179. package/dist/runtime/utils/exportRows.d.ts +2 -0
  180. package/dist/runtime/utils/exportRows.js +6 -3
  181. package/dist/runtime/utils/fieldDetails.d.ts +51 -0
  182. package/dist/runtime/utils/fieldDetails.js +113 -0
  183. package/dist/runtime/utils/filePreview.d.ts +27 -0
  184. package/dist/runtime/utils/filePreview.js +50 -0
  185. package/dist/runtime/utils/filterBuilder.d.ts +6 -1
  186. package/dist/runtime/utils/filterBuilder.js +6 -5
  187. package/dist/runtime/utils/formatBytes.d.ts +2 -0
  188. package/dist/runtime/utils/formatBytes.js +11 -0
  189. package/dist/runtime/utils/grantMatching.d.ts +8 -0
  190. package/dist/runtime/utils/grantMatching.js +15 -0
  191. package/dist/runtime/utils/importRows.js +12 -2
  192. package/dist/runtime/utils/indexForm.d.ts +83 -0
  193. package/dist/runtime/utils/indexForm.js +74 -0
  194. package/dist/runtime/utils/luceneExpression.d.ts +15 -0
  195. package/dist/runtime/utils/luceneExpression.js +74 -0
  196. package/dist/runtime/utils/pagedFetch.d.ts +46 -0
  197. package/dist/runtime/utils/pagedFetch.js +58 -0
  198. package/dist/runtime/utils/paginationHeaders.d.ts +4 -0
  199. package/dist/runtime/utils/paginationHeaders.js +4 -0
  200. package/dist/runtime/utils/permissionDenied.d.ts +10 -0
  201. package/dist/runtime/utils/permissionDenied.js +23 -0
  202. package/dist/runtime/utils/permissionMatrix.d.ts +55 -0
  203. package/dist/runtime/utils/permissionMatrix.js +85 -0
  204. package/dist/runtime/utils/persistedState.d.ts +25 -0
  205. package/dist/runtime/utils/persistedState.js +47 -0
  206. package/dist/runtime/utils/queryState.d.ts +45 -0
  207. package/dist/runtime/utils/queryState.js +75 -0
  208. package/dist/runtime/utils/requestLimits.d.ts +2 -0
  209. package/dist/runtime/utils/requestLimits.js +4 -0
  210. package/dist/runtime/utils/resultChart.d.ts +32 -0
  211. package/dist/runtime/utils/resultChart.js +59 -0
  212. package/dist/runtime/utils/savedPipelines.d.ts +22 -0
  213. package/dist/runtime/utils/savedPipelines.js +46 -0
  214. package/dist/runtime/utils/savedQueries.d.ts +60 -0
  215. package/dist/runtime/utils/savedQueries.js +143 -0
  216. package/dist/runtime/utils/schemaAnalysis.d.ts +16 -0
  217. package/dist/runtime/utils/schemaAnalysis.js +57 -0
  218. package/dist/runtime/utils/serverError.d.ts +19 -0
  219. package/dist/runtime/utils/serverError.js +19 -0
  220. package/dist/runtime/utils/serverOverview.d.ts +47 -0
  221. package/dist/runtime/utils/serverOverview.js +40 -0
  222. package/dist/runtime/utils/sessionGuard.d.ts +3 -0
  223. package/dist/runtime/utils/sessionGuard.js +18 -1
  224. package/package.json +15 -14
@@ -0,0 +1,25 @@
1
+ export interface StorageLike {
2
+ getItem: (key: string) => string | null;
3
+ setItem: (key: string, value: string) => void;
4
+ removeItem: (key: string) => void;
5
+ }
6
+ export declare const PERSISTED_STATE_VERSION = 1;
7
+ /** A value larger than this (serialised) is not stored; table state is tiny, so this only stops runaway data. */
8
+ export declare const PERSISTED_STATE_MAX_BYTES = 16384;
9
+ export declare const PERSISTED_STATE_PREFIX = "nuxt-ui-mongocamp:";
10
+ export interface PersistOptions<T> {
11
+ version?: number;
12
+ /** Turns data written by an older version into the current shape; return `undefined` to drop it. */
13
+ migrate?: (data: unknown, fromVersion: number) => T | undefined;
14
+ /** Rejects data of the right version but a wrong shape (hand-edited, or written by another build). */
15
+ validate?: (data: unknown) => data is T;
16
+ /** Largest serialised size that is stored (default 16 KB). */
17
+ maxBytes?: number;
18
+ }
19
+ /** The stored value, or `undefined` when there is none, it is corrupt, of an unknown version or fails `validate`. */
20
+ export declare function readPersisted<T>(storage: StorageLike | undefined, key: string, options?: PersistOptions<T>): T | undefined;
21
+ /** Stores `data`; returns false when it was not stored (too large, storage unavailable or full). */
22
+ export declare function writePersisted(storage: StorageLike | undefined, key: string, data: unknown, version?: number, maxBytes?: number): boolean;
23
+ export declare function clearPersisted(storage: StorageLike | undefined, key: string): void;
24
+ /** `localStorage` when this runs in a browser and it is reachable, else `undefined` (never throws). */
25
+ export declare function browserStorage(): StorageLike | undefined;
@@ -0,0 +1,47 @@
1
+ export const PERSISTED_STATE_VERSION = 1;
2
+ export const PERSISTED_STATE_MAX_BYTES = 16384;
3
+ export const PERSISTED_STATE_PREFIX = "nuxt-ui-mongocamp:";
4
+ function isRecord(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6
+ }
7
+ export function readPersisted(storage, key, options = {}) {
8
+ if (!storage) return void 0;
9
+ const version = options.version ?? PERSISTED_STATE_VERSION;
10
+ try {
11
+ const text = storage.getItem(key);
12
+ if (!text) return void 0;
13
+ const envelope = JSON.parse(text);
14
+ if (!isRecord(envelope) || typeof envelope.v !== "number" || !("data" in envelope)) return void 0;
15
+ if (envelope.v === version) {
16
+ return options.validate && !options.validate(envelope.data) ? void 0 : envelope.data;
17
+ }
18
+ if (envelope.v < version && options.migrate) return options.migrate(envelope.data, envelope.v);
19
+ return void 0;
20
+ } catch {
21
+ return void 0;
22
+ }
23
+ }
24
+ export function writePersisted(storage, key, data, version = PERSISTED_STATE_VERSION, maxBytes = PERSISTED_STATE_MAX_BYTES) {
25
+ if (!storage) return false;
26
+ try {
27
+ const text = JSON.stringify({ v: version, data });
28
+ if (text.length > maxBytes) return false;
29
+ storage.setItem(key, text);
30
+ return true;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ export function clearPersisted(storage, key) {
36
+ try {
37
+ storage?.removeItem(key);
38
+ } catch {
39
+ }
40
+ }
41
+ export function browserStorage() {
42
+ try {
43
+ return typeof localStorage === "undefined" ? void 0 : localStorage;
44
+ } catch {
45
+ return void 0;
46
+ }
47
+ }
@@ -0,0 +1,45 @@
1
+ import type { FilterFieldType, FilterGroup } from './filterBuilder.js';
2
+ import type { SavedQuery } from './savedQueries.js';
3
+ export interface QueryState {
4
+ filterGroup: FilterGroup;
5
+ /** What the filter group builds (or a raw Lucene string restored without a group); '' = no filter. */
6
+ lucene: string;
7
+ /** `['name', '-age']`: a leading `-` is descending (the server's own syntax). */
8
+ sort: string[];
9
+ projection: string[];
10
+ }
11
+ export declare const MAX_SORT_ENTRIES = 5;
12
+ export declare function emptyGroup(): FilterGroup;
13
+ export declare function emptyQueryState(): QueryState;
14
+ export declare function isEmptyQuery(state: QueryState): boolean;
15
+ /** The query to keep in history / save: only what is set, so an empty one is not worth keeping. */
16
+ export declare function toSavedQuery(state: QueryState): SavedQuery;
17
+ /**
18
+ * The state a saved query stands for. A saved visual group is built again with the field types the collection has now (so
19
+ * the string always matches the group); a query saved with only a Lucene string keeps that string.
20
+ */
21
+ export declare function fromSavedQuery(query: SavedQuery, fieldTypes: Record<string, FilterFieldType>): QueryState;
22
+ export declare function parseSortEntry(entry: string): {
23
+ field: string;
24
+ desc: boolean;
25
+ };
26
+ export declare function formatSortEntry(field: string, desc: boolean): string;
27
+ /** Adds a sort on `field` (ascending), replacing an existing one on the same field; refuses beyond `MAX_SORT_ENTRIES`. */
28
+ export declare function addSort(sort: string[], field: string): string[];
29
+ export declare function toggleSortDirection(sort: string[], index: number): string[];
30
+ export declare function setSortField(sort: string[], index: number, field: string): string[];
31
+ export declare function removeSort(sort: string[], index: number): string[];
32
+ /**
33
+ * The projection after ticking or unticking `field` in a list of `all` selectable fields. An empty projection means "all",
34
+ * so the first untick starts from all of them; ticking everything again goes back to empty; the last field cannot be
35
+ * unticked (a projection of nothing is a request for only `_id`).
36
+ */
37
+ export declare function toggleProjectionField(projection: string[], field: string, all: string[]): string[];
38
+ /** Fields of the projection that exist in `all`, in `all` order — a restored query may name fields this collection lacks. */
39
+ export declare function usableProjection(projection: string[], all: string[]): string[];
40
+ /** A short one-line description for the history and saved menus; `labels` supplies the (translated) words. */
41
+ export declare function describeQuery(query: SavedQuery, labels: {
42
+ filter: string;
43
+ sort: string;
44
+ fields: string;
45
+ }, fieldTypes?: Record<string, FilterFieldType>): string;
@@ -0,0 +1,75 @@
1
+ import { buildFilterQuery, countActiveConditions } from "./filterBuilder.js";
2
+ export const MAX_SORT_ENTRIES = 5;
3
+ export function emptyGroup() {
4
+ return { match: "all", conditions: [] };
5
+ }
6
+ export function emptyQueryState() {
7
+ return { filterGroup: emptyGroup(), lucene: "", sort: [], projection: [] };
8
+ }
9
+ export function isEmptyQuery(state) {
10
+ return state.lucene === "" && state.sort.length === 0 && state.projection.length === 0;
11
+ }
12
+ export function toSavedQuery(state) {
13
+ const query = {};
14
+ if (state.filterGroup.conditions.length > 0) query.filterGroup = state.filterGroup;
15
+ if (state.lucene !== "") query.lucene = state.lucene;
16
+ if (state.sort.length > 0) query.sort = [...state.sort];
17
+ if (state.projection.length > 0) query.projection = [...state.projection];
18
+ return query;
19
+ }
20
+ export function fromSavedQuery(query, fieldTypes) {
21
+ const filterGroup = query.filterGroup ? { ...query.filterGroup, conditions: query.filterGroup.conditions.map((c) => ({ ...c })) } : emptyGroup();
22
+ const lucene = query.filterGroup ? buildFilterQuery(filterGroup, fieldTypes) : query.lucene ?? "";
23
+ return { filterGroup, lucene, sort: [...query.sort ?? []], projection: [...query.projection ?? []] };
24
+ }
25
+ export function parseSortEntry(entry) {
26
+ return entry.startsWith("-") ? { field: entry.slice(1), desc: true } : { field: entry, desc: false };
27
+ }
28
+ export function formatSortEntry(field, desc) {
29
+ return desc ? `-${field}` : field;
30
+ }
31
+ export function addSort(sort, field) {
32
+ if (sort.some((e) => parseSortEntry(e).field === field)) return sort;
33
+ return sort.length >= MAX_SORT_ENTRIES ? sort : [...sort, field];
34
+ }
35
+ export function toggleSortDirection(sort, index) {
36
+ return sort.map((entry, i) => {
37
+ if (i !== index) return entry;
38
+ const { field, desc } = parseSortEntry(entry);
39
+ return formatSortEntry(field, !desc);
40
+ });
41
+ }
42
+ export function setSortField(sort, index, field) {
43
+ if (sort.some((e, i) => i !== index && parseSortEntry(e).field === field)) return sort;
44
+ return sort.map((entry, i) => i === index ? formatSortEntry(field, parseSortEntry(entry).desc) : entry);
45
+ }
46
+ export function removeSort(sort, index) {
47
+ return sort.filter((_, i) => i !== index);
48
+ }
49
+ export function toggleProjectionField(projection, field, all) {
50
+ const current = projection.length > 0 ? projection : all;
51
+ const next = current.includes(field) ? current.filter((f) => f !== field) : [...current, field];
52
+ if (next.length === 0) return projection;
53
+ const ordered = all.filter((f) => next.includes(f));
54
+ return ordered.length === all.length ? [] : ordered;
55
+ }
56
+ export function usableProjection(projection, all) {
57
+ const known = all.filter((f) => projection.includes(f));
58
+ return known.length === all.length ? [] : known;
59
+ }
60
+ const MAX_DESCRIPTION = 60;
61
+ export function describeQuery(query, labels, fieldTypes = {}) {
62
+ const parts = [];
63
+ const filter = query.filterGroup ? buildFilterQuery(query.filterGroup, fieldTypes) || query.lucene || "" : query.lucene ?? "";
64
+ if (filter) parts.push(`${labels.filter}: ${filter.length > MAX_DESCRIPTION ? `${filter.slice(0, MAX_DESCRIPTION - 1)}\u2026` : filter}`);
65
+ else if (query.filterGroup && countActiveConditions(query.filterGroup, fieldTypes) > 0) parts.push(labels.filter);
66
+ if (query.sort?.length) {
67
+ const text = query.sort.map((e) => {
68
+ const entry = parseSortEntry(e);
69
+ return `${entry.field} ${entry.desc ? "\u2193" : "\u2191"}`;
70
+ }).join(", ");
71
+ parts.push(`${labels.sort}: ${text}`);
72
+ }
73
+ if (query.projection?.length) parts.push(`${labels.fields}: ${query.projection.length}`);
74
+ return parts.join(" \xB7 ");
75
+ }
@@ -0,0 +1,2 @@
1
+ export declare const MAX_ENCODED_FILTER_LENGTH = 1800;
2
+ export declare function isFilterTooLong(filter: string | undefined): boolean;
@@ -0,0 +1,4 @@
1
+ export const MAX_ENCODED_FILTER_LENGTH = 1800;
2
+ export function isFilterTooLong(filter) {
3
+ return filter !== void 0 && encodeURIComponent(filter).length > MAX_ENCODED_FILTER_LENGTH;
4
+ }
@@ -0,0 +1,32 @@
1
+ export declare const MAX_CHART_ROWS = 100;
2
+ export declare const MAX_SERIES = 6;
3
+ export declare const LABEL_KEY = "__label";
4
+ export type ResultChartKind = 'bar' | 'area' | 'donut';
5
+ /**
6
+ * A row's label as text: a `$bucketAuto` range `{ min, max }` becomes `min–max`, any other object (a compound `_id`)
7
+ * is flattened to `key=value` pairs, `null` is `(none)`.
8
+ */
9
+ export declare function labelText(value: unknown): string;
10
+ /** Columns that hold at least one number and may be drawn (the label column is never one). */
11
+ export declare function valueColumns(rows: Record<string, unknown>[], columns: string[], labelKey?: string): string[];
12
+ /** The column that names the rows: `_id` when present, else the first column with a non-number value. */
13
+ export declare function defaultLabelKey(rows: Record<string, unknown>[], columns: string[]): string | undefined;
14
+ /** Chart type for these labels/values: a donut for a few non-negative slices, an area for dates, else bars. */
15
+ export declare function defaultKind(labels: string[], series: number, allNonNegative: boolean): ResultChartKind;
16
+ export interface ResultChart {
17
+ kind: ResultChartKind;
18
+ labelKey: string;
19
+ valueKeys: string[];
20
+ /** One object per chart row: `{ __label, <valueKey>: number … }` */
21
+ data: Record<string, unknown>[];
22
+ /** The result had more rows than were charted */
23
+ cut: boolean;
24
+ /** Rows without a number in any chosen column are left out; how many */
25
+ skipped: number;
26
+ }
27
+ /** `null` when there is nothing to chart (no rows, no numeric column). */
28
+ export declare function buildResultChart(rows: Record<string, unknown>[], columns: string[], choice?: {
29
+ labelKey?: string;
30
+ valueKeys?: string[];
31
+ kind?: ResultChartKind;
32
+ }): ResultChart | null;
@@ -0,0 +1,59 @@
1
+ export const MAX_CHART_ROWS = 100;
2
+ export const MAX_SERIES = 6;
3
+ export const LABEL_KEY = "__label";
4
+ const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
5
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6
+ export function labelText(value) {
7
+ if (value === null || value === void 0) return "(none)";
8
+ if (isRecord(value)) {
9
+ const keys = Object.keys(value);
10
+ if (keys.length === 2 && "min" in value && "max" in value) return `${labelText(value.min)}\u2013${labelText(value.max)}`;
11
+ return keys.map((key) => `${key}=${isRecord(value[key]) ? JSON.stringify(value[key]) : labelText(value[key])}`).join(", ");
12
+ }
13
+ return Array.isArray(value) ? JSON.stringify(value) : String(value);
14
+ }
15
+ export function valueColumns(rows, columns, labelKey) {
16
+ const sample = rows.slice(0, MAX_CHART_ROWS);
17
+ return columns.filter((key) => key !== labelKey && sample.some((row) => isNumber(row[key])));
18
+ }
19
+ export function defaultLabelKey(rows, columns) {
20
+ if (columns.includes("_id")) return "_id";
21
+ const sample = rows.slice(0, MAX_CHART_ROWS);
22
+ return columns.find((key) => sample.some((row) => row[key] !== void 0 && !isNumber(row[key]))) ?? columns[0];
23
+ }
24
+ const DATE_LIKE = /^\d{4}-\d{2}(?:-\d{2})?/;
25
+ export function defaultKind(labels, series, allNonNegative) {
26
+ if (series === 1 && allNonNegative && labels.length >= 2 && labels.length <= 6) return "donut";
27
+ if (labels.length >= 3 && labels.every((label) => DATE_LIKE.test(label))) return "area";
28
+ return "bar";
29
+ }
30
+ export function buildResultChart(rows, columns, choice = {}) {
31
+ const labelKey = choice.labelKey && columns.includes(choice.labelKey) ? choice.labelKey : defaultLabelKey(rows, columns);
32
+ if (!labelKey || rows.length === 0) return null;
33
+ const available = valueColumns(rows, columns, labelKey);
34
+ const chosen = (choice.valueKeys ?? []).filter((key) => available.includes(key));
35
+ const valueKeys = (chosen.length ? chosen : available).slice(0, MAX_SERIES);
36
+ if (valueKeys.length === 0) return null;
37
+ const data = [];
38
+ let skipped = 0;
39
+ for (const row of rows.slice(0, MAX_CHART_ROWS)) {
40
+ if (!valueKeys.some((key) => isNumber(row[key]))) {
41
+ skipped++;
42
+ continue;
43
+ }
44
+ const point = { [LABEL_KEY]: labelText(row[labelKey]) };
45
+ for (const key of valueKeys) point[key] = isNumber(row[key]) ? row[key] : 0;
46
+ data.push(point);
47
+ }
48
+ if (data.length === 0) return null;
49
+ const labels = data.map((point) => point[LABEL_KEY]);
50
+ const nonNegative = data.every((point) => valueKeys.every((key) => point[key] >= 0));
51
+ return {
52
+ kind: choice.kind ?? defaultKind(labels, valueKeys.length, nonNegative),
53
+ labelKey,
54
+ valueKeys,
55
+ data,
56
+ cut: rows.length > MAX_CHART_ROWS,
57
+ skipped
58
+ };
59
+ }
@@ -0,0 +1,22 @@
1
+ import type { RequestStage } from './aggregationPipeline.js';
2
+ import { MAX_NAME_LENGTH, MAX_SAVED } from './savedQueries.js';
3
+ export interface SavedPipelineEntry {
4
+ name: string;
5
+ pipeline: RequestStage[];
6
+ }
7
+ export declare const MAX_PIPELINE_STAGES = 50;
8
+ /** Serialised size of one saved pipeline. */
9
+ export declare const MAX_PIPELINE_BYTES = 20000;
10
+ export { MAX_NAME_LENGTH, MAX_SAVED };
11
+ /** A clean copy of a request pipeline, or `undefined` when it is empty, malformed, too large or uses a denied operator. */
12
+ export declare function sanitizePipeline(value: unknown): RequestStage[] | undefined;
13
+ export type SavePipelineFailure = 'invalid-name' | 'invalid-pipeline' | 'limit';
14
+ /** Adds or replaces (name compared ignoring case) an entry; a full list still allows replacing. */
15
+ export declare function upsertPipeline(list: SavedPipelineEntry[], name: unknown, pipeline: unknown, max?: number): {
16
+ ok: true;
17
+ list: SavedPipelineEntry[];
18
+ } | {
19
+ ok: false;
20
+ reason: SavePipelineFailure;
21
+ };
22
+ export declare function sanitizePipelineList(value: unknown, max?: number): SavedPipelineEntry[];
@@ -0,0 +1,46 @@
1
+ import { findForbidden } from "./aggregationPipeline.js";
2
+ import { MAX_NAME_LENGTH, MAX_SAVED, sanitizeName } from "./savedQueries.js";
3
+ export const MAX_PIPELINE_STAGES = 50;
4
+ export const MAX_PIPELINE_BYTES = 2e4;
5
+ export { MAX_NAME_LENGTH, MAX_SAVED };
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ export function sanitizePipeline(value) {
10
+ if (!Array.isArray(value) || value.length === 0 || value.length > MAX_PIPELINE_STAGES) return void 0;
11
+ const pipeline = [];
12
+ for (const item of value) {
13
+ if (!isRecord(item) || typeof item.stage !== "string" || !item.stage.startsWith("$") || !("value" in item)) return void 0;
14
+ pipeline.push({ stage: item.stage, value: item.value });
15
+ }
16
+ let size;
17
+ try {
18
+ size = JSON.stringify(pipeline).length;
19
+ } catch {
20
+ return void 0;
21
+ }
22
+ if (size > MAX_PIPELINE_BYTES) return void 0;
23
+ return findForbidden(pipeline).length > 0 ? void 0 : pipeline;
24
+ }
25
+ export function upsertPipeline(list, name, pipeline, max = MAX_SAVED) {
26
+ const cleanName = sanitizeName(name);
27
+ if (!cleanName) return { ok: false, reason: "invalid-name" };
28
+ const clean = sanitizePipeline(pipeline);
29
+ if (!clean) return { ok: false, reason: "invalid-pipeline" };
30
+ const index = list.findIndex((e) => e.name.toLowerCase() === cleanName.toLowerCase());
31
+ if (index === -1) {
32
+ if (list.length >= max) return { ok: false, reason: "limit" };
33
+ return { ok: true, list: [...list, { name: cleanName, pipeline: clean }] };
34
+ }
35
+ return { ok: true, list: list.map((e, i) => i === index ? { name: cleanName, pipeline: clean } : e) };
36
+ }
37
+ export function sanitizePipelineList(value, max = MAX_SAVED) {
38
+ if (!Array.isArray(value)) return [];
39
+ let list = [];
40
+ for (const raw of value) {
41
+ if (!isRecord(raw)) continue;
42
+ const result = upsertPipeline(list, raw.name, raw.pipeline, max);
43
+ if (result.ok) list = result.list;
44
+ }
45
+ return list;
46
+ }
@@ -0,0 +1,60 @@
1
+ import type { FilterGroup } from './filterBuilder.js';
2
+ export interface SavedQuery {
3
+ /** The visual builder's state, so it can be restored and edited, not only the string. */
4
+ filterGroup?: FilterGroup;
5
+ /** A Lucene string (a quick search, or what the builder produced). */
6
+ lucene?: string;
7
+ sort?: string[];
8
+ projection?: string[];
9
+ }
10
+ export interface SavedQueryEntry {
11
+ name: string;
12
+ query: SavedQuery;
13
+ }
14
+ export declare const MAX_SAVED = 50;
15
+ export declare const MAX_RECENT = 20;
16
+ export declare const MAX_NAME_LENGTH = 80;
17
+ export declare const MAX_LUCENE_LENGTH = 2000;
18
+ export declare const MAX_CONDITIONS = 50;
19
+ export declare const MAX_FIELDS = 100;
20
+ export declare const MAX_FIELD_LENGTH = 200;
21
+ export declare const MAX_VALUE_LENGTH = 500;
22
+ /** Largest stored store / imported file, serialised. */
23
+ export declare const MAX_STORE_BYTES: number;
24
+ export declare const EXPORT_FORMAT = "nuxt-ui-mongocamp-saved-queries";
25
+ /**
26
+ * A clean copy of `value` holding only the known, bounded fields, or `undefined` when nothing usable is left (an empty
27
+ * query is not worth saving). Unknown keys are dropped; an invalid filter group is dropped whole.
28
+ */
29
+ export declare function sanitizeQuery(value: unknown): SavedQuery | undefined;
30
+ /** Same query ⇒ same key, whatever the key order; condition ids are ignored (they are only UI identity). */
31
+ export declare function queryKey(query: SavedQuery): string;
32
+ export declare function sanitizeName(name: unknown): string | undefined;
33
+ /** `query` first, an equal earlier one removed, at most `max` kept. */
34
+ export declare function pushRecent(list: SavedQuery[], query: SavedQuery, max?: number): SavedQuery[];
35
+ export type SaveFailure = 'invalid-name' | 'invalid-query' | 'limit';
36
+ /** Adds or replaces (name compared case-insensitively) an entry; keeps the list sorted as given, new names last. */
37
+ export declare function upsertSaved(list: SavedQueryEntry[], name: unknown, query: unknown, max?: number): {
38
+ ok: true;
39
+ list: SavedQueryEntry[];
40
+ } | {
41
+ ok: false;
42
+ reason: SaveFailure;
43
+ };
44
+ export declare function sanitizeSavedList(value: unknown, max?: number): SavedQueryEntry[];
45
+ export declare function sanitizeRecentList(value: unknown, max?: number): SavedQuery[];
46
+ export declare function serializeSaved(list: SavedQueryEntry[]): string;
47
+ export type ImportFailure = 'too-large' | 'not-json' | 'foreign-format';
48
+ /**
49
+ * Reads a file written by `serializeSaved`. Foreign, oversized or non-JSON input is refused whole; single bad entries
50
+ * are skipped and counted. Names that already exist are replaced by the imported query (upsert).
51
+ */
52
+ export declare function parseSavedImport(text: string, existing: SavedQueryEntry[], max?: number): {
53
+ ok: true;
54
+ list: SavedQueryEntry[];
55
+ imported: number;
56
+ skipped: number;
57
+ } | {
58
+ ok: false;
59
+ reason: ImportFailure;
60
+ };
@@ -0,0 +1,143 @@
1
+ export const MAX_SAVED = 50;
2
+ export const MAX_RECENT = 20;
3
+ export const MAX_NAME_LENGTH = 80;
4
+ export const MAX_LUCENE_LENGTH = 2e3;
5
+ export const MAX_CONDITIONS = 50;
6
+ export const MAX_FIELDS = 100;
7
+ export const MAX_FIELD_LENGTH = 200;
8
+ export const MAX_VALUE_LENGTH = 500;
9
+ export const MAX_STORE_BYTES = 128 * 1024;
10
+ export const EXPORT_FORMAT = "nuxt-ui-mongocamp-saved-queries";
11
+ const OPERATORS = ["contains", "equals", "notEquals", "startsWith", "endsWith", "oneOf", "gte", "lte", "between", "isTrue", "isFalse", "isEmpty", "isNotEmpty"];
12
+ function isRecord(value) {
13
+ return typeof value === "object" && value !== null && !Array.isArray(value);
14
+ }
15
+ function sanitizeStrings(value, maxItems) {
16
+ if (!Array.isArray(value)) return void 0;
17
+ const out = value.filter((v) => typeof v === "string" && v !== "" && v.length <= MAX_FIELD_LENGTH).slice(0, maxItems);
18
+ return out.length > 0 ? out : void 0;
19
+ }
20
+ function sanitizeCondition(value) {
21
+ if (!isRecord(value)) return void 0;
22
+ const { id, field, operator, value: v, value2 } = value;
23
+ if (typeof id !== "string" || id === "" || id.length > MAX_FIELD_LENGTH) return void 0;
24
+ if (typeof field !== "string" || field === "" || field.length > MAX_FIELD_LENGTH) return void 0;
25
+ if (typeof operator !== "string" || !OPERATORS.includes(operator)) return void 0;
26
+ const condition = { id, field, operator };
27
+ for (const [key, raw] of [["value", v], ["value2", value2]]) {
28
+ if (raw === void 0) continue;
29
+ if (typeof raw !== "string" || raw.length > MAX_VALUE_LENGTH) return void 0;
30
+ condition[key] = raw;
31
+ }
32
+ return condition;
33
+ }
34
+ function sanitizeGroup(value) {
35
+ if (!isRecord(value) || value.match !== "all" && value.match !== "any" || !Array.isArray(value.conditions)) return void 0;
36
+ if (value.conditions.length > MAX_CONDITIONS) return void 0;
37
+ const conditions = [];
38
+ for (const raw of value.conditions) {
39
+ const condition = sanitizeCondition(raw);
40
+ if (!condition) return void 0;
41
+ conditions.push(condition);
42
+ }
43
+ if (conditions.length === 0) return void 0;
44
+ const group = { match: value.match, conditions };
45
+ if (value.negate === true) group.negate = true;
46
+ return group;
47
+ }
48
+ export function sanitizeQuery(value) {
49
+ if (!isRecord(value)) return void 0;
50
+ const query = {};
51
+ const filterGroup = sanitizeGroup(value.filterGroup);
52
+ if (filterGroup) query.filterGroup = filterGroup;
53
+ if (typeof value.lucene === "string" && value.lucene.trim() !== "" && value.lucene.length <= MAX_LUCENE_LENGTH) query.lucene = value.lucene;
54
+ const sort = sanitizeStrings(value.sort, 10);
55
+ if (sort) query.sort = sort;
56
+ const projection = sanitizeStrings(value.projection, MAX_FIELDS);
57
+ if (projection) query.projection = projection;
58
+ return Object.keys(query).length > 0 ? query : void 0;
59
+ }
60
+ function stable(value) {
61
+ if (Array.isArray(value)) return value.map(stable);
62
+ if (isRecord(value)) return Object.fromEntries(Object.keys(value).sort().map((k) => [k, stable(value[k])]));
63
+ return value;
64
+ }
65
+ export function queryKey(query) {
66
+ const copy = stable({
67
+ ...query,
68
+ filterGroup: query.filterGroup && { ...query.filterGroup, conditions: query.filterGroup.conditions.map(({ id: _id, ...rest }) => rest) }
69
+ });
70
+ return JSON.stringify(copy);
71
+ }
72
+ export function sanitizeName(name) {
73
+ if (typeof name !== "string") return void 0;
74
+ const trimmed = name.trim();
75
+ return trimmed !== "" && trimmed.length <= MAX_NAME_LENGTH ? trimmed : void 0;
76
+ }
77
+ export function pushRecent(list, query, max = MAX_RECENT) {
78
+ const key = queryKey(query);
79
+ return [query, ...list.filter((q) => queryKey(q) !== key)].slice(0, max);
80
+ }
81
+ export function upsertSaved(list, name, query, max = MAX_SAVED) {
82
+ const cleanName = sanitizeName(name);
83
+ if (!cleanName) return { ok: false, reason: "invalid-name" };
84
+ const cleanQuery = sanitizeQuery(query);
85
+ if (!cleanQuery) return { ok: false, reason: "invalid-query" };
86
+ const index = list.findIndex((e) => e.name.toLowerCase() === cleanName.toLowerCase());
87
+ if (index === -1) {
88
+ if (list.length >= max) return { ok: false, reason: "limit" };
89
+ return { ok: true, list: [...list, { name: cleanName, query: cleanQuery }] };
90
+ }
91
+ return { ok: true, list: list.map((e, i) => i === index ? { name: cleanName, query: cleanQuery } : e) };
92
+ }
93
+ export function sanitizeSavedList(value, max = MAX_SAVED) {
94
+ if (!Array.isArray(value)) return [];
95
+ let list = [];
96
+ for (const raw of value) {
97
+ if (!isRecord(raw)) continue;
98
+ const result = upsertSaved(list, raw.name, raw.query, max);
99
+ if (result.ok) list = result.list;
100
+ }
101
+ return list;
102
+ }
103
+ export function sanitizeRecentList(value, max = MAX_RECENT) {
104
+ if (!Array.isArray(value)) return [];
105
+ const out = [];
106
+ const seen = /* @__PURE__ */ new Set();
107
+ for (const raw of value) {
108
+ const query = sanitizeQuery(raw);
109
+ if (!query || seen.has(queryKey(query))) continue;
110
+ seen.add(queryKey(query));
111
+ out.push(query);
112
+ if (out.length >= max) break;
113
+ }
114
+ return out;
115
+ }
116
+ export function serializeSaved(list) {
117
+ return JSON.stringify({ format: EXPORT_FORMAT, version: 1, queries: list }, null, 2);
118
+ }
119
+ export function parseSavedImport(text, existing, max = MAX_SAVED) {
120
+ if (text.length > MAX_STORE_BYTES) return { ok: false, reason: "too-large" };
121
+ let parsed;
122
+ try {
123
+ parsed = JSON.parse(text);
124
+ } catch {
125
+ return { ok: false, reason: "not-json" };
126
+ }
127
+ if (!isRecord(parsed) || parsed.format !== EXPORT_FORMAT || parsed.version !== 1 || !Array.isArray(parsed.queries)) {
128
+ return { ok: false, reason: "foreign-format" };
129
+ }
130
+ let list = existing;
131
+ let imported = 0;
132
+ let skipped = 0;
133
+ for (const raw of parsed.queries) {
134
+ const result = isRecord(raw) ? upsertSaved(list, raw.name, raw.query, max) : void 0;
135
+ if (result?.ok) {
136
+ list = result.list;
137
+ imported++;
138
+ } else {
139
+ skipped++;
140
+ }
141
+ }
142
+ return { ok: true, list, imported, skipped };
143
+ }
@@ -0,0 +1,16 @@
1
+ import type { SchemaAnalysis } from '@sfxcode/nuxt-mongocamp-server';
2
+ import type { SampleAnalysis, ValueKind } from './analyzeSamples.js';
3
+ /** More documents than this are never analysed in one request (≈ 20 s on the dev server); use a sample instead. */
4
+ export declare const FULL_ANALYSIS_MAX_DOCUMENTS = 200000;
5
+ /** Time to wait for an analysis of `documents` documents: a fixed allowance plus 0.4 ms each (measured: 0.11 ms), at most 2 minutes. */
6
+ export declare function analysisTimeoutMs(documents: number): number;
7
+ /** What to ask for: the server needs a positive size, and more than the collection holds is the same as all of it. */
8
+ export declare function analysisSampleSize(documents: number): number;
9
+ export declare function kindOfServerType(serverType: string): ValueKind;
10
+ /**
11
+ * Maps the server's analysis onto `SampleAnalysis`. Fields inside objects are `a.b`, fields of objects inside arrays
12
+ * `items[].sku` (the server's `[array element]` node is folded into the path, like the client-side analysis does).
13
+ * `share` is the share of analysed documents that have the field: a field's `percentageOfParent` multiplied down the
14
+ * chain, so a field inside array elements is not inflated by the number of elements. The server lists no common values.
15
+ */
16
+ export declare function statisticsFromSchemaAnalysis(analysis: SchemaAnalysis, maxFields?: number): SampleAnalysis;
@@ -0,0 +1,57 @@
1
+ import { comparePaths } from "./analyzeSamples.js";
2
+ export const FULL_ANALYSIS_MAX_DOCUMENTS = 2e5;
3
+ const BASE_TIMEOUT_MS = 15e3;
4
+ const MS_PER_DOCUMENT = 0.4;
5
+ const MAX_TIMEOUT_MS = 12e4;
6
+ export function analysisTimeoutMs(documents) {
7
+ return Math.min(MAX_TIMEOUT_MS, Math.round(BASE_TIMEOUT_MS + Math.max(0, documents) * MS_PER_DOCUMENT));
8
+ }
9
+ export function analysisSampleSize(documents) {
10
+ return Math.min(FULL_ANALYSIS_MAX_DOCUMENTS, Math.max(1, Math.floor(documents) || 1));
11
+ }
12
+ const KIND_BY_SERVER_TYPE = {
13
+ objectId: "string",
14
+ string: "string",
15
+ int: "number",
16
+ long: "number",
17
+ double: "number",
18
+ decimal: "number",
19
+ bool: "boolean",
20
+ date: "date",
21
+ object: "object",
22
+ array: "array",
23
+ null: "null"
24
+ };
25
+ const ARRAY_ELEMENT = "[array element]";
26
+ const DEFAULT_MAX_FIELDS = 200;
27
+ export function kindOfServerType(serverType) {
28
+ return KIND_BY_SERVER_TYPE[serverType] ?? "string";
29
+ }
30
+ export function statisticsFromSchemaAnalysis(analysis, maxFields = DEFAULT_MAX_FIELDS) {
31
+ const sampled = analysis.sample > 0 ? Math.min(analysis.sample, analysis.count || analysis.sample) : analysis.count;
32
+ const fields = [];
33
+ const visit = (field, parentPath, parentShare) => {
34
+ const isElement = field.name === ARRAY_ELEMENT;
35
+ const path = isElement ? `${parentPath}[]` : parentPath ? `${parentPath}.${field.name}` : field.name;
36
+ const share = parentShare * Math.min(1, Math.max(0, field.percentageOfParent));
37
+ if (!isElement) {
38
+ const present = Math.round(share * sampled);
39
+ const toDocuments = field.count > 0 ? present / field.count : 1;
40
+ const counts = /* @__PURE__ */ new Map();
41
+ for (const { fieldType, count } of field.fieldTypes ?? []) {
42
+ const kind = kindOfServerType(fieldType);
43
+ counts.set(kind, (counts.get(kind) ?? 0) + Math.round(count * toDocuments));
44
+ }
45
+ fields.push({
46
+ path,
47
+ present,
48
+ share,
49
+ types: [...counts].map(([type, count]) => ({ type, count })).sort((a, b) => b.count - a.count)
50
+ });
51
+ }
52
+ for (const sub of field.subFields ?? []) visit(sub, path, isElement ? parentShare : share);
53
+ };
54
+ for (const field of analysis.fields ?? []) visit(field, "", 1);
55
+ fields.sort((a, b) => comparePaths(a.path, b.path));
56
+ return { sampled, fields: fields.slice(0, maxFields), truncated: fields.length > maxFields };
57
+ }