@sfxcode/nuxt-ui-mongocamp 1.3.5 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/dist/module.d.mts +8 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +6 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +302 -3
  5. package/dist/runtime/components/MongocampAggregationChart.d.vue.ts +6 -0
  6. package/dist/runtime/components/MongocampAggregationChart.vue +93 -0
  7. package/dist/runtime/components/MongocampAggregationChart.vue.d.ts +6 -0
  8. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +9 -0
  9. package/dist/runtime/components/MongocampAggregationStagePreview.vue +148 -0
  10. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +9 -0
  11. package/dist/runtime/components/MongocampBucketFiles.vue +169 -48
  12. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +19 -0
  13. package/dist/runtime/components/MongocampBulkDelete.vue +118 -23
  14. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +19 -0
  15. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +6 -0
  16. package/dist/runtime/components/MongocampBulkEdit.vue +23 -2
  17. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +6 -0
  18. package/dist/runtime/components/MongocampChart.d.vue.ts +29 -0
  19. package/dist/runtime/components/MongocampChart.vue +129 -0
  20. package/dist/runtime/components/MongocampChart.vue.d.ts +29 -0
  21. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +15 -0
  22. package/dist/runtime/components/MongocampCollectionCharts.vue +199 -0
  23. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +15 -0
  24. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +23 -0
  25. package/dist/runtime/components/MongocampCollectionCopy.vue +445 -0
  26. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +23 -0
  27. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -0
  28. package/dist/runtime/components/MongocampCollectionData.vue +342 -137
  29. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -0
  30. package/dist/runtime/components/MongocampCollectionInfos.vue +106 -238
  31. package/dist/runtime/components/MongocampCollections.vue +62 -0
  32. package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +40 -0
  33. package/dist/runtime/components/MongocampCommandPalette.vue +135 -0
  34. package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +40 -0
  35. package/dist/runtime/components/MongocampConfirmByName.vue +2 -2
  36. package/dist/runtime/components/MongocampDashboard.d.vue.ts +3 -1
  37. package/dist/runtime/components/MongocampDashboard.vue +21 -2
  38. package/dist/runtime/components/MongocampDashboard.vue.d.ts +3 -1
  39. package/dist/runtime/components/MongocampDatabases.vue +22 -0
  40. package/dist/runtime/components/MongocampDocumentCompare.d.vue.ts +20 -0
  41. package/dist/runtime/components/MongocampDocumentCompare.vue +146 -0
  42. package/dist/runtime/components/MongocampDocumentCompare.vue.d.ts +20 -0
  43. package/dist/runtime/components/MongocampDocumentView.d.vue.ts +22 -0
  44. package/dist/runtime/components/MongocampDocumentView.vue +202 -0
  45. package/dist/runtime/components/MongocampDocumentView.vue.d.ts +22 -0
  46. package/dist/runtime/components/MongocampErrorAlert.vue +12 -4
  47. package/dist/runtime/components/MongocampExportAll.d.vue.ts +18 -0
  48. package/dist/runtime/components/MongocampExportAll.vue +204 -0
  49. package/dist/runtime/components/MongocampExportAll.vue.d.ts +18 -0
  50. package/dist/runtime/components/MongocampFilePreview.d.vue.ts +16 -0
  51. package/dist/runtime/components/MongocampFilePreview.vue +162 -0
  52. package/dist/runtime/components/MongocampFilePreview.vue.d.ts +16 -0
  53. package/dist/runtime/components/MongocampFilterBuilder.vue +11 -0
  54. package/dist/runtime/components/MongocampImport.vue +2 -10
  55. package/dist/runtime/components/MongocampIndexes.d.vue.ts +18 -0
  56. package/dist/runtime/components/MongocampIndexes.vue +455 -0
  57. package/dist/runtime/components/MongocampIndexes.vue.d.ts +18 -0
  58. package/dist/runtime/components/MongocampJobs.d.vue.ts +6 -1
  59. package/dist/runtime/components/MongocampJobs.vue +23 -3
  60. package/dist/runtime/components/MongocampJobs.vue.d.ts +6 -1
  61. package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +12 -0
  62. package/dist/runtime/components/MongocampPermissionMatrix.vue +301 -0
  63. package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +12 -0
  64. package/dist/runtime/components/MongocampQueryBar.d.vue.ts +26 -0
  65. package/dist/runtime/components/MongocampQueryBar.vue +398 -0
  66. package/dist/runtime/components/MongocampQueryBar.vue.d.ts +26 -0
  67. package/dist/runtime/components/MongocampRoleGrants.vue +2 -2
  68. package/dist/runtime/components/MongocampRoles.vue +3 -3
  69. package/dist/runtime/components/MongocampServerOverview.d.vue.ts +20 -0
  70. package/dist/runtime/components/MongocampServerOverview.vue +443 -0
  71. package/dist/runtime/components/MongocampServerOverview.vue.d.ts +20 -0
  72. package/dist/runtime/components/MongocampSettings.d.vue.ts +25 -1
  73. package/dist/runtime/components/MongocampSettings.vue +70 -9
  74. package/dist/runtime/components/MongocampSettings.vue.d.ts +25 -1
  75. package/dist/runtime/components/MongocampUsers.vue +3 -3
  76. package/dist/runtime/composables/useMongocampAdmin.d.ts +2 -1
  77. package/dist/runtime/composables/useMongocampAdmin.js +6 -1
  78. package/dist/runtime/composables/useMongocampAggregation.d.ts +12 -1
  79. package/dist/runtime/composables/useMongocampAggregation.js +33 -25
  80. package/dist/runtime/composables/useMongocampAutoRefresh.d.ts +26 -0
  81. package/dist/runtime/composables/useMongocampAutoRefresh.js +78 -0
  82. package/dist/runtime/composables/useMongocampBucket.d.ts +13 -1
  83. package/dist/runtime/composables/useMongocampBucket.js +34 -0
  84. package/dist/runtime/composables/useMongocampClientApi.js +2 -1
  85. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +85 -0
  86. package/dist/runtime/composables/useMongocampCollectionCopy.js +105 -0
  87. package/dist/runtime/composables/useMongocampCollectionStats.d.ts +10 -0
  88. package/dist/runtime/composables/useMongocampCollectionStats.js +17 -0
  89. package/dist/runtime/composables/useMongocampError.d.ts +2 -1
  90. package/dist/runtime/composables/useMongocampError.js +16 -1
  91. package/dist/runtime/composables/useMongocampExportAll.d.ts +47 -0
  92. package/dist/runtime/composables/useMongocampExportAll.js +27 -0
  93. package/dist/runtime/composables/useMongocampExtendedJson.d.ts +5 -1
  94. package/dist/runtime/composables/useMongocampExtendedJson.js +12 -6
  95. package/dist/runtime/composables/useMongocampFetchAll.d.ts +25 -0
  96. package/dist/runtime/composables/useMongocampFetchAll.js +27 -0
  97. package/dist/runtime/composables/useMongocampPermissions.d.ts +14 -0
  98. package/dist/runtime/composables/useMongocampPermissions.js +21 -0
  99. package/dist/runtime/composables/useMongocampPersistedState.d.ts +15 -0
  100. package/dist/runtime/composables/useMongocampPersistedState.js +21 -0
  101. package/dist/runtime/composables/useMongocampProxyApi.js +2 -1
  102. package/dist/runtime/composables/useMongocampQuery.d.ts +48 -0
  103. package/dist/runtime/composables/useMongocampQuery.js +72 -1
  104. package/dist/runtime/composables/useMongocampSavedPipelines.d.ts +25 -0
  105. package/dist/runtime/composables/useMongocampSavedPipelines.js +23 -0
  106. package/dist/runtime/composables/useMongocampSavedQueries.d.ts +37 -0
  107. package/dist/runtime/composables/useMongocampSavedQueries.js +50 -0
  108. package/dist/runtime/composables/useMongocampServerOverview.d.ts +42 -0
  109. package/dist/runtime/composables/useMongocampServerOverview.js +61 -0
  110. package/dist/runtime/composables/useMongocampSession.d.ts +2 -0
  111. package/dist/runtime/composables/useMongocampSession.js +16 -2
  112. package/dist/runtime/composables/useMongocampSystem.d.ts +7 -2
  113. package/dist/runtime/composables/useMongocampSystem.js +6 -2
  114. package/dist/runtime/locales/de.json +495 -9
  115. package/dist/runtime/locales/en.json +495 -9
  116. package/dist/runtime/plugin.js +6 -3
  117. package/dist/runtime/utils/aggregationPipeline.d.ts +5 -4
  118. package/dist/runtime/utils/aggregationPipeline.js +23 -9
  119. package/dist/runtime/utils/aggregationPreview.d.ts +13 -0
  120. package/dist/runtime/utils/aggregationPreview.js +10 -0
  121. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  122. package/dist/runtime/utils/aggregationResult.js +4 -0
  123. package/dist/runtime/utils/aggregationTemplates.d.ts +34 -0
  124. package/dist/runtime/utils/aggregationTemplates.js +47 -0
  125. package/dist/runtime/utils/analyzeSamples.d.ts +1 -0
  126. package/dist/runtime/utils/analyzeSamples.js +1 -1
  127. package/dist/runtime/utils/autoRefresh.d.ts +14 -0
  128. package/dist/runtime/utils/autoRefresh.js +15 -0
  129. package/dist/runtime/utils/bigIntJson.d.ts +15 -0
  130. package/dist/runtime/utils/bigIntJson.js +55 -0
  131. package/dist/runtime/utils/bulkDelete.d.ts +9 -1
  132. package/dist/runtime/utils/bulkDelete.js +15 -3
  133. package/dist/runtime/utils/bulkEdit.d.ts +6 -0
  134. package/dist/runtime/utils/bulkEdit.js +7 -0
  135. package/dist/runtime/utils/chartData.d.ts +11 -0
  136. package/dist/runtime/utils/chartData.js +9 -0
  137. package/dist/runtime/utils/collectionChart.d.ts +36 -0
  138. package/dist/runtime/utils/collectionChart.js +73 -0
  139. package/dist/runtime/utils/collectionCopy.d.ts +26 -0
  140. package/dist/runtime/utils/collectionCopy.js +38 -0
  141. package/dist/runtime/utils/collectionStats.d.ts +31 -0
  142. package/dist/runtime/utils/collectionStats.js +42 -0
  143. package/dist/runtime/utils/commandPalette.d.ts +48 -0
  144. package/dist/runtime/utils/commandPalette.js +39 -0
  145. package/dist/runtime/utils/documentCompare.d.ts +31 -0
  146. package/dist/runtime/utils/documentCompare.js +70 -0
  147. package/dist/runtime/utils/documentDiff.d.ts +19 -0
  148. package/dist/runtime/utils/documentDiff.js +71 -0
  149. package/dist/runtime/utils/documentPaths.d.ts +44 -0
  150. package/dist/runtime/utils/documentPaths.js +144 -0
  151. package/dist/runtime/utils/documentTree.d.ts +40 -0
  152. package/dist/runtime/utils/documentTree.js +94 -0
  153. package/dist/runtime/utils/exportDocuments.d.ts +35 -0
  154. package/dist/runtime/utils/exportDocuments.js +54 -0
  155. package/dist/runtime/utils/exportRows.js +1 -1
  156. package/dist/runtime/utils/filePreview.d.ts +27 -0
  157. package/dist/runtime/utils/filePreview.js +50 -0
  158. package/dist/runtime/utils/filterBuilder.d.ts +6 -1
  159. package/dist/runtime/utils/filterBuilder.js +6 -5
  160. package/dist/runtime/utils/formatBytes.d.ts +2 -0
  161. package/dist/runtime/utils/formatBytes.js +11 -0
  162. package/dist/runtime/utils/grantMatching.d.ts +8 -0
  163. package/dist/runtime/utils/grantMatching.js +15 -0
  164. package/dist/runtime/utils/importRows.js +12 -2
  165. package/dist/runtime/utils/indexCopy.d.ts +26 -0
  166. package/dist/runtime/utils/indexCopy.js +22 -0
  167. package/dist/runtime/utils/indexForm.d.ts +69 -0
  168. package/dist/runtime/utils/indexForm.js +63 -0
  169. package/dist/runtime/utils/limitedMap.d.ts +17 -0
  170. package/dist/runtime/utils/limitedMap.js +19 -0
  171. package/dist/runtime/utils/luceneExpression.d.ts +15 -0
  172. package/dist/runtime/utils/luceneExpression.js +74 -0
  173. package/dist/runtime/utils/pagedFetch.d.ts +46 -0
  174. package/dist/runtime/utils/pagedFetch.js +58 -0
  175. package/dist/runtime/utils/paginationHeaders.d.ts +4 -0
  176. package/dist/runtime/utils/paginationHeaders.js +4 -0
  177. package/dist/runtime/utils/permissionDenied.d.ts +10 -0
  178. package/dist/runtime/utils/permissionDenied.js +23 -0
  179. package/dist/runtime/utils/permissionMatrix.d.ts +55 -0
  180. package/dist/runtime/utils/permissionMatrix.js +85 -0
  181. package/dist/runtime/utils/persistedState.d.ts +25 -0
  182. package/dist/runtime/utils/persistedState.js +47 -0
  183. package/dist/runtime/utils/queryState.d.ts +45 -0
  184. package/dist/runtime/utils/queryState.js +75 -0
  185. package/dist/runtime/utils/requestLimits.d.ts +2 -0
  186. package/dist/runtime/utils/requestLimits.js +4 -0
  187. package/dist/runtime/utils/resultChart.d.ts +32 -0
  188. package/dist/runtime/utils/resultChart.js +59 -0
  189. package/dist/runtime/utils/savedPipelines.d.ts +22 -0
  190. package/dist/runtime/utils/savedPipelines.js +46 -0
  191. package/dist/runtime/utils/savedQueries.d.ts +60 -0
  192. package/dist/runtime/utils/savedQueries.js +143 -0
  193. package/dist/runtime/utils/schemaAnalysis.d.ts +16 -0
  194. package/dist/runtime/utils/schemaAnalysis.js +57 -0
  195. package/dist/runtime/utils/serverError.d.ts +19 -0
  196. package/dist/runtime/utils/serverError.js +19 -0
  197. package/dist/runtime/utils/serverOverview.d.ts +47 -0
  198. package/dist/runtime/utils/serverOverview.js +40 -0
  199. package/dist/runtime/utils/sessionGuard.d.ts +3 -0
  200. package/dist/runtime/utils/sessionGuard.js +18 -1
  201. package/package.json +12 -11
@@ -0,0 +1,74 @@
1
+ export class UnsupportedExpressionError extends Error {
2
+ constructor(expression, reason) {
3
+ super(`Cannot negate this expression (${reason}): ${expression}`);
4
+ this.name = "UnsupportedExpressionError";
5
+ }
6
+ }
7
+ const OPEN = /* @__PURE__ */ new Set(["(", "[", "{"]);
8
+ const CLOSE = /* @__PURE__ */ new Set([")", "]", "}"]);
9
+ function scan(text, visit) {
10
+ let depth = 0;
11
+ let inQuote = false;
12
+ for (let i = 0; i < text.length; i++) {
13
+ const char = text[i];
14
+ if (char === "\\") {
15
+ i++;
16
+ continue;
17
+ }
18
+ if (char === '"') {
19
+ inQuote = !inQuote;
20
+ continue;
21
+ }
22
+ if (inQuote) continue;
23
+ if (CLOSE.has(char)) depth--;
24
+ const found = visit(char, i, depth);
25
+ if (found !== void 0) return found;
26
+ if (OPEN.has(char)) depth++;
27
+ }
28
+ return void 0;
29
+ }
30
+ function matchingClose(text, start) {
31
+ const index = scan(text.slice(start), (char, i, depth) => char === ")" && depth === 0 ? i : void 0);
32
+ return index === void 0 ? -1 : start + index;
33
+ }
34
+ function splitTopLevel(text) {
35
+ const parts = [];
36
+ const operators = /* @__PURE__ */ new Set();
37
+ let last = 0;
38
+ scan(text, (char, i, depth) => {
39
+ if (char !== " " || depth !== 0) return void 0;
40
+ for (const operator of ["AND", "OR"]) {
41
+ const token = ` ${operator} `;
42
+ if (text.startsWith(token, i)) {
43
+ parts.push(text.slice(last, i));
44
+ operators.add(operator);
45
+ last = i + token.length;
46
+ return void 0;
47
+ }
48
+ }
49
+ return void 0;
50
+ });
51
+ parts.push(text.slice(last));
52
+ return { parts: parts.map((part) => part.trim()), operators };
53
+ }
54
+ export function parseLuceneExpression(expression) {
55
+ const text = expression.trim();
56
+ if (text === "" || text === "()") return null;
57
+ return parse(text, expression);
58
+ }
59
+ function parse(text, original) {
60
+ if (text.startsWith("NOT ") || text.startsWith("!")) throw new UnsupportedExpressionError(original, "NOT is not supported");
61
+ if (text.startsWith("-(") && matchingClose(text, 1) === text.length - 1) {
62
+ return { kind: "not", node: parse(text.slice(2, -1).trim(), original) };
63
+ }
64
+ if (text.startsWith("(")) {
65
+ const close = matchingClose(text, 0);
66
+ if (close === -1) throw new UnsupportedExpressionError(original, "unbalanced parentheses");
67
+ if (close === text.length - 1) return parse(text.slice(1, -1).trim(), original);
68
+ }
69
+ const { parts, operators } = splitTopLevel(text);
70
+ if (operators.size === 0) return { kind: "clause", text };
71
+ if (operators.size > 1) throw new UnsupportedExpressionError(original, "AND and OR mixed without parentheses");
72
+ if (parts.includes("")) throw new UnsupportedExpressionError(original, "empty operand");
73
+ return { kind: operators.has("AND") ? "and" : "or", parts: parts.map((part) => parse(part, original)) };
74
+ }
@@ -0,0 +1,46 @@
1
+ export declare const DEFAULT_PAGE_SIZE = 500;
2
+ /** Callers raise this on purpose; an unbounded read of a large collection is never the default. */
3
+ export declare const DEFAULT_MAX_ROWS = 10000;
4
+ export interface PageResult<T> {
5
+ rows: T[];
6
+ /** Total number of rows the server reports for the whole list, when it does (the pagination header). */
7
+ total?: number;
8
+ }
9
+ export interface FetchAllProgress {
10
+ loaded: number;
11
+ /** The server's total as of the latest page; `undefined` when it never reported one. */
12
+ total?: number;
13
+ /** How many rows will be read at most: the total, capped at `maxRows`. */
14
+ target?: number;
15
+ page: number;
16
+ }
17
+ export interface FetchAllOptions<T> {
18
+ /** Rows per request (default 500; the server accepts far more). */
19
+ pageSize?: number;
20
+ /** Stop after this many rows and report `truncated` (default 10 000). */
21
+ maxRows?: number;
22
+ onProgress?: (progress: FetchAllProgress) => void;
23
+ /** Aborting rejects with an `AbortError` — a half-read result is never returned as if it were complete. */
24
+ signal?: AbortSignal;
25
+ /** Identity of a row, to drop a row that appears twice because the list shifted while reading. */
26
+ keyOf?: (row: T) => string;
27
+ }
28
+ export interface FetchAllResult<T> {
29
+ rows: T[];
30
+ /** The server's total as of the latest page. */
31
+ total?: number;
32
+ /** More rows exist than were read: the cap was hit. */
33
+ truncated: boolean;
34
+ /** The reported total was not the same on every page — rows were added or removed during the read. */
35
+ totalChanged: boolean;
36
+ /** Rows skipped because `keyOf` had already seen them. */
37
+ duplicates: number;
38
+ pages: number;
39
+ }
40
+ /**
41
+ * Calls `fetchPage(page, pageSize)` for page 1, 2, … until everything is read, the cap is reached or `signal` aborts.
42
+ * Stops when the rows read reach the server's latest total, on an empty page, or — only when the server never reports a
43
+ * total — on a page shorter than asked for (a server may cap the page size, so a short page alone proves nothing).
44
+ * Sequential by design: the pages are cheap to compute and the page size is what makes it fast.
45
+ */
46
+ export declare function fetchAllPages<T>(fetchPage: (page: number, pageSize: number) => Promise<PageResult<T>>, options?: FetchAllOptions<T>): Promise<FetchAllResult<T>>;
@@ -0,0 +1,58 @@
1
+ export const DEFAULT_PAGE_SIZE = 500;
2
+ export const DEFAULT_MAX_ROWS = 1e4;
3
+ function abortError(signal) {
4
+ return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
5
+ }
6
+ export async function fetchAllPages(fetchPage, options = {}) {
7
+ const pageSize = Math.max(1, Math.floor(options.pageSize ?? DEFAULT_PAGE_SIZE) || DEFAULT_PAGE_SIZE);
8
+ const maxRows = Math.max(1, Math.floor(options.maxRows ?? DEFAULT_MAX_ROWS) || DEFAULT_MAX_ROWS);
9
+ const { signal, onProgress, keyOf } = options;
10
+ const rows = [];
11
+ const seen = keyOf ? /* @__PURE__ */ new Set() : void 0;
12
+ let total;
13
+ let totalChanged = false;
14
+ let duplicates = 0;
15
+ let truncated = false;
16
+ let page = 0;
17
+ for (; ; ) {
18
+ if (signal?.aborted) throw abortError(signal);
19
+ page++;
20
+ const result = await fetchPage(page, pageSize);
21
+ if (signal?.aborted) throw abortError(signal);
22
+ if (typeof result.total === "number" && Number.isFinite(result.total)) {
23
+ if (total !== void 0 && result.total !== total) totalChanged = true;
24
+ total = result.total;
25
+ }
26
+ let added = 0;
27
+ for (const row of result.rows) {
28
+ if (seen && keyOf) {
29
+ const key = keyOf(row);
30
+ if (seen.has(key)) {
31
+ duplicates++;
32
+ continue;
33
+ }
34
+ seen.add(key);
35
+ }
36
+ if (rows.length >= maxRows) {
37
+ truncated = true;
38
+ break;
39
+ }
40
+ rows.push(row);
41
+ added++;
42
+ }
43
+ onProgress?.({ loaded: rows.length, total, target: total === void 0 ? void 0 : Math.min(total, maxRows), page });
44
+ if (truncated) break;
45
+ if (rows.length >= maxRows) {
46
+ truncated = total === void 0 ? result.rows.length >= pageSize : total > rows.length + duplicates;
47
+ break;
48
+ }
49
+ if (result.rows.length === 0) break;
50
+ if (keyOf && added === 0) break;
51
+ if (total !== void 0) {
52
+ if (rows.length + duplicates >= total) break;
53
+ } else if (result.rows.length < pageSize) {
54
+ break;
55
+ }
56
+ }
57
+ return { rows, total, truncated, totalChanged, duplicates, pages: page };
58
+ }
@@ -0,0 +1,4 @@
1
+ /** A numeric response header (`x-pagination-count-rows`, …), or `undefined` when it is absent or not a number. */
2
+ export declare function headerNumber(headers: {
3
+ get: (name: string) => string | null;
4
+ } | undefined, name: string): number | undefined;
@@ -0,0 +1,4 @@
1
+ export function headerNumber(headers, name) {
2
+ const parsed = Number.parseInt(headers?.get(name) ?? "", 10);
3
+ return Number.isNaN(parsed) ? void 0 : parsed;
4
+ }
@@ -0,0 +1,10 @@
1
+ import type { Middleware } from '@sfxcode/nuxt-mongocamp-server/api';
2
+ /** `true` for the body of a 401 that names what the user may not do, `false` for a dead token or anything else. */
3
+ export declare function isPermissionDeniedBody(status: number, body: unknown): boolean;
4
+ export declare const permissionDeniedMiddleware: Middleware;
5
+ /**
6
+ * Puts the middleware first in the list the dependency's API instances share (they are all built from one
7
+ * `Configuration`, so one array). Safe to call on anything: a test double without a `middleware` array is left alone,
8
+ * and a list that already has it is not changed.
9
+ */
10
+ export declare function installPermissionDeniedMiddleware<T extends object>(apis: T): T;
@@ -0,0 +1,23 @@
1
+ const NOT_AUTHORIZED_CODE = 4011;
2
+ export function isPermissionDeniedBody(status, body) {
3
+ if (status !== 401 || typeof body !== "object" || body === null) return false;
4
+ const { code, msg } = body;
5
+ return code === NOT_AUTHORIZED_CODE && typeof msg === "string" && /^user not authorized for\b/i.test(msg.trim());
6
+ }
7
+ export const permissionDeniedMiddleware = {
8
+ post: async ({ response }) => {
9
+ if (response.status !== 401) return void 0;
10
+ try {
11
+ const text = await response.clone().text();
12
+ if (!isPermissionDeniedBody(401, JSON.parse(text))) return void 0;
13
+ return new Response(text, { status: 403, statusText: "Forbidden", headers: new Headers(response.headers) });
14
+ } catch {
15
+ return void 0;
16
+ }
17
+ }
18
+ };
19
+ export function installPermissionDeniedMiddleware(apis) {
20
+ const list = apis.adminApi?.middleware;
21
+ if (Array.isArray(list) && !list.includes(permissionDeniedMiddleware)) list.unshift(permissionDeniedMiddleware);
22
+ return apis;
23
+ }
@@ -0,0 +1,55 @@
1
+ import type { Role, UserProfile } from '@sfxcode/nuxt-mongocamp-server';
2
+ import type { GrantPermission } from './grantMatching.js';
3
+ export declare const PERMISSIONS: readonly GrantPermission[];
4
+ /** What a user may do on one collection. `undefined` = not known (the grants of a GridFS bucket's `.files` / `.chunks` were never verified). */
5
+ export interface Cell {
6
+ read: boolean | undefined;
7
+ write: boolean | undefined;
8
+ administrate: boolean | undefined;
9
+ /** An admin user: everything is allowed whatever the grants say. */
10
+ admin: boolean;
11
+ /** The roles whose grants allow at least one permission here (empty for an admin and for a user without a grant). */
12
+ via: string[];
13
+ }
14
+ export interface MatrixUser {
15
+ name: string;
16
+ admin: boolean;
17
+ roles: string[];
18
+ /** Roles the user has that the role list does not know (deleted meanwhile): their grants cannot count. */
19
+ unknownRoles: string[];
20
+ }
21
+ export interface PermissionMatrix {
22
+ users: MatrixUser[];
23
+ collections: string[];
24
+ /** `cells[userName][collection]` */
25
+ cells: Record<string, Record<string, Cell>>;
26
+ }
27
+ /**
28
+ * The matrix for `users` and `collections`. Roles are looked up by name (case-sensitive, as the server keeps them). A user's own
29
+ * `grants` field (what the server lists with the user) counts as well, so a grant that is not in any role still shows.
30
+ */
31
+ export declare function buildPermissionMatrix(users: readonly UserProfile[], roles: readonly Role[], collections: readonly string[]): PermissionMatrix;
32
+ /** The letters of a cell, `R W A` with `·` for what is missing; `?` for an unknown one; `admin` for an administrator. */
33
+ export declare function cellLetters(cell: Cell): string;
34
+ /** The short form used in the CSV: `R`, `RW`, `RWA`, `admin`, empty for nothing and `?` for unknown. */
35
+ export declare function cellCode(cell: Cell): string;
36
+ export declare function hasAnyPermission(cell: Cell): boolean;
37
+ export type QuickView = 'all' | 'users-without-roles' | 'collections-nobody-writes' | 'collections-nobody-reads';
38
+ export declare const QUICK_VIEWS: readonly QuickView[];
39
+ export interface MatrixFilter {
40
+ /** Text matched against user and collection names, ignoring case. */
41
+ text?: string;
42
+ /** Only users that have this role. */
43
+ role?: string;
44
+ view?: QuickView;
45
+ }
46
+ /** Collections no non-admin user may write (admins always can); bucket members are never listed — their grants are unknown. */
47
+ export declare function collectionsNobodyCan(matrix: PermissionMatrix, permission: GrantPermission): string[];
48
+ export declare function usersWithoutRoles(matrix: PermissionMatrix): string[];
49
+ /** The matrix narrowed to what the filter asks for; the cells are shared, nothing is copied. */
50
+ export declare function filterMatrix(matrix: PermissionMatrix, filter: MatrixFilter): PermissionMatrix;
51
+ /** Rows for `rowsToCsv`: one per user, `user`, `roles`, then one column per collection with `cellCode`. */
52
+ export declare function matrixToCsvRows(matrix: PermissionMatrix): {
53
+ keys: string[];
54
+ rows: Record<string, unknown>[];
55
+ };
@@ -0,0 +1,85 @@
1
+ import { isBucketMemberCollection } from "./collectionProtection.js";
2
+ import { permissionFromGrants } from "./grantMatching.js";
3
+ export const PERMISSIONS = ["read", "write", "administrate"];
4
+ function grantsOf(role) {
5
+ return Array.isArray(role?.collectionGrants) ? role.collectionGrants : [];
6
+ }
7
+ export function buildPermissionMatrix(users, roles, collections) {
8
+ const roleByName = new Map(roles.map((role) => [role.name, role]));
9
+ const matrixUsers = [];
10
+ const cells = {};
11
+ for (const user of users) {
12
+ const roleNames = Array.isArray(user.roles) ? user.roles : [];
13
+ const known = roleNames.filter((name) => roleByName.has(name));
14
+ const admin = user.isAdmin === true || known.some((name) => roleByName.get(name).isAdmin === true);
15
+ matrixUsers.push({ name: user.user, admin, roles: roleNames, unknownRoles: roleNames.filter((name) => !roleByName.has(name)) });
16
+ const own = Array.isArray(user.grants) ? user.grants : [];
17
+ const all = [...known.flatMap((name) => grantsOf(roleByName.get(name))), ...own];
18
+ const row = {};
19
+ for (const collection of collections) {
20
+ if (admin) {
21
+ row[collection] = { read: true, write: true, administrate: true, admin: true, via: [] };
22
+ continue;
23
+ }
24
+ const cell = {
25
+ read: permissionFromGrants(all, collection, "read"),
26
+ write: permissionFromGrants(all, collection, "write"),
27
+ administrate: permissionFromGrants(all, collection, "administrate"),
28
+ admin: false,
29
+ via: known.filter((name) => PERMISSIONS.some((p) => permissionFromGrants(grantsOf(roleByName.get(name)), collection, p) === true))
30
+ };
31
+ row[collection] = cell;
32
+ }
33
+ cells[user.user] = row;
34
+ }
35
+ return { users: matrixUsers, collections: [...collections], cells };
36
+ }
37
+ export function cellLetters(cell) {
38
+ if (cell.admin) return "admin";
39
+ const letter = (value, on) => value === void 0 ? "?" : value ? on : "\xB7";
40
+ return `${letter(cell.read, "R")}${letter(cell.write, "W")}${letter(cell.administrate, "A")}`;
41
+ }
42
+ export function cellCode(cell) {
43
+ if (cell.admin) return "admin";
44
+ if (cell.read === void 0 && cell.write === void 0 && cell.administrate === void 0) return "?";
45
+ return `${cell.read ? "R" : ""}${cell.write ? "W" : ""}${cell.administrate ? "A" : ""}`;
46
+ }
47
+ export function hasAnyPermission(cell) {
48
+ return cell.admin || PERMISSIONS.some((p) => cell[p] === true);
49
+ }
50
+ export const QUICK_VIEWS = ["all", "users-without-roles", "collections-nobody-writes", "collections-nobody-reads"];
51
+ export function collectionsNobodyCan(matrix, permission) {
52
+ const regular = matrix.users.filter((u) => !u.admin);
53
+ return matrix.collections.filter((collection) => !isBucketMemberCollection(collection) && regular.every((u) => matrix.cells[u.name][collection][permission] !== true));
54
+ }
55
+ export function usersWithoutRoles(matrix) {
56
+ return matrix.users.filter((u) => u.roles.length === 0 && !u.admin).map((u) => u.name);
57
+ }
58
+ export function filterMatrix(matrix, filter) {
59
+ const text = (filter.text ?? "").trim().toLowerCase();
60
+ let users = matrix.users;
61
+ let collections = matrix.collections;
62
+ if (filter.role) users = users.filter((u) => u.roles.includes(filter.role));
63
+ if (filter.view === "users-without-roles") {
64
+ const names = new Set(usersWithoutRoles(matrix));
65
+ users = users.filter((u) => names.has(u.name));
66
+ }
67
+ if (filter.view === "collections-nobody-writes") collections = collections.filter((c) => collectionsNobodyCan(matrix, "write").includes(c));
68
+ if (filter.view === "collections-nobody-reads") collections = collections.filter((c) => collectionsNobodyCan(matrix, "read").includes(c));
69
+ if (text) {
70
+ const userHit = users.filter((u) => u.name.toLowerCase().includes(text));
71
+ const collectionHit = collections.filter((c) => c.toLowerCase().includes(text));
72
+ if (userHit.length > 0 || collectionHit.length === 0) users = userHit;
73
+ if (collectionHit.length > 0 || userHit.length === 0) collections = collectionHit;
74
+ }
75
+ return { users, collections, cells: matrix.cells };
76
+ }
77
+ export function matrixToCsvRows(matrix) {
78
+ const keys = ["user", "roles", ...matrix.collections];
79
+ const rows = matrix.users.map((user) => {
80
+ const row = { user: user.name, roles: user.roles.join(" ") };
81
+ for (const collection of matrix.collections) row[collection] = cellCode(matrix.cells[user.name][collection]);
82
+ return row;
83
+ });
84
+ return { keys, rows };
85
+ }
@@ -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;