@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,94 @@
1
+ import { joinPath, typeOf } from "./documentPaths.js";
2
+ export const DEFAULT_MAX_NODES = 5e3;
3
+ export const MAX_TREE_DEPTH = 32;
4
+ export const COLLAPSE_ABOVE_NODES = 200;
5
+ export const AUTO_EXPAND_DEPTH = 2;
6
+ function entriesOf(value) {
7
+ if (Array.isArray(value)) return value.map((v, i) => [String(i), v]);
8
+ return Object.entries(value);
9
+ }
10
+ export function buildDocumentTree(doc, options = {}) {
11
+ const maxNodes = options.maxNodes ?? DEFAULT_MAX_NODES;
12
+ let total = 0;
13
+ let truncated = false;
14
+ const build = (key, value, segments, depth) => {
15
+ if (total >= maxNodes) {
16
+ truncated = true;
17
+ return void 0;
18
+ }
19
+ total++;
20
+ const type = typeOf(value);
21
+ const node = { key, path: joinPath(segments), depth, type, value, children: null };
22
+ const container = (type === "object" || type === "array") && depth < MAX_TREE_DEPTH;
23
+ const entries = container ? entriesOf(value) : [];
24
+ if (entries.length === 0) return node;
25
+ node.children = [];
26
+ for (const [childKey, child] of entries) {
27
+ const built = build(childKey, child, [...segments, childKey], depth + 1);
28
+ if (built) node.children.push(built);
29
+ }
30
+ return node;
31
+ };
32
+ const top = [];
33
+ const root = typeOf(doc) === "object" ? entriesOf(doc) : [["", doc]];
34
+ for (const [key, value] of root) {
35
+ const node = build(key, value, [key], 0);
36
+ if (node) top.push(node);
37
+ }
38
+ return { nodes: top, total, truncated };
39
+ }
40
+ export function defaultExpanded(tree) {
41
+ const open = /* @__PURE__ */ new Set();
42
+ if (tree.total > COLLAPSE_ABOVE_NODES) return open;
43
+ const walk = (nodes) => {
44
+ for (const node of nodes) {
45
+ if (node.children && node.depth < AUTO_EXPAND_DEPTH - 1) {
46
+ open.add(node.path);
47
+ walk(node.children);
48
+ }
49
+ }
50
+ };
51
+ walk(tree.nodes);
52
+ return open;
53
+ }
54
+ export function allContainerPaths(tree) {
55
+ const open = /* @__PURE__ */ new Set();
56
+ const walk = (nodes) => {
57
+ for (const node of nodes) {
58
+ if (node.children) {
59
+ open.add(node.path);
60
+ walk(node.children);
61
+ }
62
+ }
63
+ };
64
+ walk(tree.nodes);
65
+ return open;
66
+ }
67
+ export function visibleNodes(tree, expanded) {
68
+ const out = [];
69
+ const walk = (nodes) => {
70
+ for (const node of nodes) {
71
+ out.push(node);
72
+ if (node.children && expanded.has(node.path)) walk(node.children);
73
+ }
74
+ };
75
+ walk(tree.nodes);
76
+ return out;
77
+ }
78
+ export function nodeDisplay(node) {
79
+ const { value, type } = node;
80
+ if (type === "null") return { text: "null" };
81
+ if (type === "array") return { text: `[${value.length}]` };
82
+ if (type === "object") return { text: `{${Object.keys(value).length}}` };
83
+ if (type === "date") {
84
+ const raw = value instanceof Date ? value.toISOString() : value.$date;
85
+ const text = typeof raw === "string" ? raw : JSON.stringify(raw);
86
+ const parsed = typeof raw === "string" ? new Date(raw) : void 0;
87
+ return parsed && !Number.isNaN(parsed.getTime()) ? { text, title: parsed.toLocaleString() } : { text };
88
+ }
89
+ if (typeof value === "object" && value !== null) {
90
+ const inner = Object.values(value)[0];
91
+ return { text: typeof inner === "string" ? inner : JSON.stringify(inner) };
92
+ }
93
+ return { text: String(value) };
94
+ }
@@ -0,0 +1,35 @@
1
+ export type ExportFormat = 'json' | 'ndjson' | 'csv';
2
+ export declare const EXPORT_MIME_TYPES: Record<ExportFormat, string>;
3
+ /** More documents than this are not read into one browser file unless the caller raises the cap on purpose. */
4
+ export declare const DEFAULT_EXPORT_MAX_ROWS = 50000;
5
+ /**
6
+ * One document as it is written to a file: extended-JSON wrappers become plain values (`$oid` → text, `$date` → ISO text,
7
+ * `$numberInt` → number), and an integer beyond 2^53 is kept exact as a BigInt (a bare number in JSON, digits in CSV).
8
+ * A `$numberDecimal` becomes a JS number, like in the table (rounded past ~15 significant digits).
9
+ */
10
+ export declare function toExportRow(row: Record<string, unknown>): Record<string, unknown>;
11
+ /**
12
+ * Any value of a document (the whole document, a nested object, an array or a scalar) as JSON text the way an export
13
+ * writes it: wrappers become plain values and an integer beyond 2^53 stays exact as a bare number.
14
+ */
15
+ export declare function valueToJson(value: unknown, pretty?: boolean): string;
16
+ /**
17
+ * The columns of a CSV export: the keys of **all** rows in order of first appearance (a later row with a new key is not
18
+ * lost), `_id` first. Nested objects and arrays become one cell of JSON text.
19
+ */
20
+ export declare function exportColumns(rows: Record<string, unknown>[]): string[];
21
+ export interface FormatOptions {
22
+ /** `json` only: 2-space indentation instead of one document per line. */
23
+ pretty?: boolean;
24
+ /** `csv` only: the columns, in this order (default: `exportColumns`). */
25
+ columns?: string[];
26
+ }
27
+ /**
28
+ * The text of an export file for rows already passed through `toExportRow`.
29
+ * - `json`: an array, one document per line (`pretty: true`: indented);
30
+ * - `ndjson`: one compact document per line (what `mongoimport` and most tools read);
31
+ * - `csv`: a header row and one row per document, RFC 4180 quoting, `\r\n` line ends.
32
+ */
33
+ export declare function formatDocuments(rows: Record<string, unknown>[], format: ExportFormat, options?: FormatOptions): string;
34
+ /** `customers-20241231-2359.csv`: the collection name made safe for a file name, a local timestamp and the extension. */
35
+ export declare function exportFilename(collectionName: string, format: ExportFormat, now?: Date): string;
@@ -0,0 +1,54 @@
1
+ import { unwrapExtendedJson } from "../composables/useMongocampExtendedJson.js";
2
+ import { rowsToCsv } from "./exportRows.js";
3
+ export const EXPORT_MIME_TYPES = {
4
+ json: "application/json",
5
+ ndjson: "application/x-ndjson",
6
+ csv: "text/csv"
7
+ };
8
+ export const DEFAULT_EXPORT_MAX_ROWS = 5e4;
9
+ const INTEGER_TEXT = /^-?\d+$/;
10
+ function longsToBigInt(value) {
11
+ if (Array.isArray(value)) return value.map(longsToBigInt);
12
+ if (typeof value !== "object" || value === null) return value;
13
+ const entries = Object.entries(value);
14
+ const only = entries.length === 1 ? entries[0] : void 0;
15
+ if (only && only[0] === "$numberLong" && typeof only[1] === "string" && INTEGER_TEXT.test(only[1]) && !Number.isSafeInteger(Number(only[1]))) {
16
+ return BigInt(only[1]);
17
+ }
18
+ return Object.fromEntries(entries.map(([key, inner]) => [key, longsToBigInt(inner)]));
19
+ }
20
+ export function toExportRow(row) {
21
+ return unwrapExtendedJson(longsToBigInt(row));
22
+ }
23
+ function jsonText(value, space) {
24
+ const token = `\0LONG${Math.random().toString(36).slice(2)}:`;
25
+ const text = JSON.stringify(value, (_key, inner) => typeof inner === "bigint" ? `${token}${inner}` : inner, space);
26
+ return text.replaceAll(new RegExp(`"\\\\u0000${token.slice(1)}(-?\\d+)"`, "g"), "$1");
27
+ }
28
+ export function valueToJson(value, pretty = true) {
29
+ return jsonText(unwrapExtendedJson(longsToBigInt(value)), pretty ? 2 : void 0);
30
+ }
31
+ export function exportColumns(rows) {
32
+ const keys = /* @__PURE__ */ new Set();
33
+ for (const row of rows) for (const key of Object.keys(row)) keys.add(key);
34
+ return keys.has("_id") ? ["_id", ...[...keys].filter((key) => key !== "_id")] : [...keys];
35
+ }
36
+ export function formatDocuments(rows, format, options = {}) {
37
+ if (format === "ndjson") return rows.length === 0 ? "" : `${rows.map((row) => jsonText(row)).join("\n")}
38
+ `;
39
+ if (format === "csv") {
40
+ const columns = options.columns ?? exportColumns(rows);
41
+ return columns.length === 0 ? "" : rowsToCsv(rows, columns);
42
+ }
43
+ if (options.pretty) return jsonText(rows, 2);
44
+ return rows.length === 0 ? "[]\n" : `[
45
+ ${rows.map((row) => ` ${jsonText(row)}`).join(",\n")}
46
+ ]
47
+ `;
48
+ }
49
+ export function exportFilename(collectionName, format, now = /* @__PURE__ */ new Date()) {
50
+ const pad = (n) => String(n).padStart(2, "0");
51
+ const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}`;
52
+ const safe = collectionName.replace(/[^\w.-]+/g, "_") || "export";
53
+ return `${safe}-${stamp}.${format}`;
54
+ }
@@ -1,6 +1,6 @@
1
1
  function csvCell(value) {
2
2
  if (value === null || value === void 0) return "";
3
- const text = typeof value === "object" ? JSON.stringify(value) : String(value);
3
+ const text = typeof value === "object" ? JSON.stringify(value, (_key, inner) => typeof inner === "bigint" ? inner.toString() : inner) : String(value);
4
4
  return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
5
5
  }
6
6
  export function rowsToCsv(rows, keys) {
@@ -0,0 +1,27 @@
1
+ export type PreviewKind = 'image' | 'json' | 'csv' | 'text' | 'pdf' | 'other';
2
+ /** Largest file loaded for an in-page preview, per kind (bytes). Larger files only offer metadata + download. */
3
+ export declare const PREVIEW_LIMITS: Record<Exclude<PreviewKind, 'other'>, number>;
4
+ /** Characters of text shown at most (a 1 MB file is still cut so the page stays responsive). */
5
+ export declare const MAX_PREVIEW_CHARS = 200000;
6
+ /**
7
+ * What a file is, from its name first (the server stores no content type) and the blob's own type second.
8
+ * SVG is deliberately `other`: it can carry script, so it is never rendered inline.
9
+ */
10
+ export declare function previewKind(filename: string, blobType?: string): PreviewKind;
11
+ /** Whether a file of this kind and size may be loaded for preview. */
12
+ export declare function canPreview(kind: PreviewKind, length: number): boolean;
13
+ /** Pretty-prints JSON text; anything that is not valid JSON (e.g. NDJSON) comes back unchanged. */
14
+ export declare function prettyJson(text: string): string;
15
+ export declare function clipText(text: string, max?: number): {
16
+ text: string;
17
+ clipped: boolean;
18
+ };
19
+ export type MetadataParse = {
20
+ ok: true;
21
+ value: Record<string, unknown>;
22
+ } | {
23
+ ok: false;
24
+ reason: 'invalid-json' | 'not-object';
25
+ };
26
+ /** Validates the metadata editor's text: must be one JSON object (empty text = no metadata). */
27
+ export declare function parseMetadataJson(text: string): MetadataParse;
@@ -0,0 +1,50 @@
1
+ export const PREVIEW_LIMITS = {
2
+ image: 10 * 1024 * 1024,
3
+ pdf: 20 * 1024 * 1024,
4
+ json: 1024 * 1024,
5
+ csv: 1024 * 1024,
6
+ text: 1024 * 1024
7
+ };
8
+ export const MAX_PREVIEW_CHARS = 2e5;
9
+ const IMAGE_EXT = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "webp", "avif", "bmp", "ico"]);
10
+ const TEXT_EXT = /* @__PURE__ */ new Set(["txt", "md", "log", "xml", "yaml", "yml", "html", "css", "js", "ts", "ini", "toml", "sql", "sh", "conf", "properties"]);
11
+ function extensionOf(filename) {
12
+ const dot = filename.lastIndexOf(".");
13
+ return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
14
+ }
15
+ export function previewKind(filename, blobType = "") {
16
+ const ext = extensionOf(filename);
17
+ const type = blobType.split(";")[0].trim().toLowerCase();
18
+ if (ext === "svg" || type === "image/svg+xml") return "other";
19
+ if (IMAGE_EXT.has(ext) || type.startsWith("image/") && !ext) return "image";
20
+ if (ext === "pdf" || type === "application/pdf" && !ext) return "pdf";
21
+ if (ext === "json" || ext === "ndjson" || type === "application/json" && !ext) return "json";
22
+ if (ext === "csv" || ext === "tsv" || type === "text/csv" && !ext) return "csv";
23
+ if (TEXT_EXT.has(ext) || type.startsWith("text/") && !ext) return "text";
24
+ return "other";
25
+ }
26
+ export function canPreview(kind, length) {
27
+ if (kind === "other") return false;
28
+ return length <= PREVIEW_LIMITS[kind];
29
+ }
30
+ export function prettyJson(text) {
31
+ try {
32
+ return JSON.stringify(JSON.parse(text), null, 2);
33
+ } catch {
34
+ return text;
35
+ }
36
+ }
37
+ export function clipText(text, max = MAX_PREVIEW_CHARS) {
38
+ return text.length > max ? { text: text.slice(0, max), clipped: true } : { text, clipped: false };
39
+ }
40
+ export function parseMetadataJson(text) {
41
+ if (!text.trim()) return { ok: true, value: {} };
42
+ let parsed;
43
+ try {
44
+ parsed = JSON.parse(text);
45
+ } catch {
46
+ return { ok: false, reason: "invalid-json" };
47
+ }
48
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return { ok: false, reason: "not-object" };
49
+ return { ok: true, value: parsed };
50
+ }
@@ -12,6 +12,8 @@ export interface FilterCondition {
12
12
  export interface FilterGroup {
13
13
  match: 'all' | 'any';
14
14
  conditions: FilterCondition[];
15
+ /** Exclude what the combined conditions match (NOT). Written with De Morgan, see `useMongocampQuery().not`. */
16
+ negate?: boolean;
15
17
  }
16
18
  export declare const FILTER_OPERATORS_BY_TYPE: Record<FilterFieldType, FilterOperator[]>;
17
19
  export declare function operatorsFor(type: FilterFieldType): FilterOperator[];
@@ -25,7 +27,10 @@ export declare function conditionValueText(condition: FilterCondition): string;
25
27
  export declare function valueCountFor(operator: FilterOperator): 0 | 1 | 2;
26
28
  /** Lucene for one row, or `''` when the row is incomplete/invalid (so it is simply not applied). */
27
29
  export declare function buildCondition(condition: FilterCondition, type: FilterFieldType): string;
28
- /** Combines every valid row with AND (`match: 'all'`) or OR (`'any'`). `''` means "no filter". */
30
+ /**
31
+ * Combines every valid row with AND (`match: 'all'`) or OR (`'any'`), negated when `negate` is set. `''` means "no
32
+ * filter" — a negated group with no valid row is also no filter, never "match nothing".
33
+ */
29
34
  export declare function buildFilterQuery(group: FilterGroup, fieldTypes: Record<string, FilterFieldType>): string;
30
35
  /** Rows that actually contribute to the query — what a "Filters (n)" badge should show. */
31
36
  export declare function countActiveConditions(group: FilterGroup, fieldTypes: Record<string, FilterFieldType>): number;
@@ -64,8 +64,8 @@ export function buildCondition(condition, type) {
64
64
  if (type === "objectId") {
65
65
  const ids = condition.operator === "oneOf" ? splitList(value) : [value];
66
66
  if (ids.length === 0 || !ids.every(isObjectIdHex)) return "";
67
- if (condition.operator === "oneOf") return h.inClause(field, ids);
68
- return condition.operator === "notEquals" ? h.notEquals(field, value) : h.equals(field, value);
67
+ if (condition.operator === "oneOf") return h.byIds(ids);
68
+ return condition.operator === "notEquals" ? h.notEquals(field, value) : h.byId(value);
69
69
  }
70
70
  switch (condition.operator) {
71
71
  case "isEmpty":
@@ -73,9 +73,9 @@ export function buildCondition(condition, type) {
73
73
  case "isNotEmpty":
74
74
  return h.exists(field, existsType(type));
75
75
  case "isTrue":
76
- return `${escapedField}:true`;
76
+ return h.isTrue(field);
77
77
  case "isFalse":
78
- return `${escapedField}:false`;
78
+ return h.isFalse(field);
79
79
  case "gte": {
80
80
  const from = parseRangeBound(type, value);
81
81
  return from === null ? "" : h.inRange(field, from, null);
@@ -121,7 +121,8 @@ export function buildCondition(condition, type) {
121
121
  export function buildFilterQuery(group, fieldTypes) {
122
122
  const h = useMongocampQuery();
123
123
  const parts = group.conditions.map((c) => buildCondition(c, fieldTypes[c.field] ?? "string"));
124
- return group.match === "any" ? h.or(...parts) : h.and(...parts);
124
+ const combined = group.match === "any" ? h.or(...parts) : h.and(...parts);
125
+ return group.negate ? h.not(combined) : combined;
125
126
  }
126
127
  export function countActiveConditions(group, fieldTypes) {
127
128
  return group.conditions.filter((c) => buildCondition(c, fieldTypes[c.field] ?? "string") !== "").length;
@@ -0,0 +1,2 @@
1
+ /** `1.5 KB` style size; `0 B` for nothing. */
2
+ export declare function formatBytes(bytes: number): string;
@@ -0,0 +1,11 @@
1
+ export function formatBytes(bytes) {
2
+ if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
3
+ const units = ["B", "KB", "MB", "GB", "TB"];
4
+ let value = bytes;
5
+ let unit = 0;
6
+ while (value >= 1024 && unit < units.length - 1) {
7
+ value /= 1024;
8
+ unit++;
9
+ }
10
+ return `${unit === 0 ? value : value.toFixed(value >= 10 ? 0 : 1)} ${units[unit]}`;
11
+ }
@@ -0,0 +1,8 @@
1
+ export type GrantPermission = 'read' | 'write' | 'administrate';
2
+ /**
3
+ * Whether the grants allow `permission` on `collection`: `true` / `false` when they decide, `undefined` when they cannot
4
+ * — no grant list at all, or a GridFS bucket member (`<bucket>.files` / `.chunks`), whose grant name and type were not
5
+ * verified. Callers show the action on `undefined` and let the server refuse (it answers a missing grant clearly).
6
+ * Several grants for the same name add up: any one that allows it is enough.
7
+ */
8
+ export declare function permissionFromGrants(grants: unknown, collection: string, permission: GrantPermission): boolean | undefined;
@@ -0,0 +1,15 @@
1
+ import { isBucketMemberCollection } from "./collectionProtection.js";
2
+ const normalise = (value) => typeof value === "string" ? value.trim().toLowerCase() : "";
3
+ function isObject(value) {
4
+ return typeof value === "object" && value !== null;
5
+ }
6
+ function isCollectionGrant(grant) {
7
+ const type = normalise(grant.grantType);
8
+ return type === "" || type === "collection";
9
+ }
10
+ export function permissionFromGrants(grants, collection, permission) {
11
+ if (!Array.isArray(grants)) return void 0;
12
+ if (isBucketMemberCollection(collection)) return void 0;
13
+ const wanted = normalise(collection);
14
+ return grants.some((grant) => isObject(grant) && isCollectionGrant(grant) && normalise(grant.name) === wanted && grant[permission] === true);
15
+ }
@@ -1,3 +1,4 @@
1
+ import { parseJsonKeepingLongs } from "./bigIntJson.js";
1
2
  import { isIsoDateTimeString } from "./isoDate.js";
2
3
  import { isObjectIdHex } from "./objectId.js";
3
4
  export const DEFAULT_IMPORT_LIMITS = { maxRows: 1e4, maxBytes: 5 * 1024 * 1024 };
@@ -11,18 +12,27 @@ function stripBom(text) {
11
12
  function fileError(code, message) {
12
13
  return { rows: [], errors: [{ rowIndex: -1, code, message }], truncated: false };
13
14
  }
15
+ function containsUnsafeLong(value) {
16
+ if (Array.isArray(value)) return value.some(containsUnsafeLong);
17
+ if (!isPlainObject(value)) return false;
18
+ const keys = Object.keys(value);
19
+ if (keys.length === 1 && keys[0] === "$numberLong" && typeof value.$numberLong === "string" && /^-?\d+$/.test(value.$numberLong) && !Number.isSafeInteger(Number(value.$numberLong))) return true;
20
+ return Object.values(value).some(containsUnsafeLong);
21
+ }
14
22
  export function parseJsonRows(text, limits = DEFAULT_IMPORT_LIMITS) {
15
23
  if (text.length > limits.maxBytes) return fileError("file-too-large", `File is larger than ${limits.maxBytes} bytes`);
16
24
  let parsed;
17
25
  try {
18
- parsed = JSON.parse(stripBom(text));
26
+ parsed = parseJsonKeepingLongs(stripBom(text));
19
27
  } catch (e) {
20
28
  return fileError("invalid-json", `Invalid JSON: ${e instanceof Error ? e.message : String(e)}`);
21
29
  }
22
30
  if (!Array.isArray(parsed)) return fileError("not-array", "Expected a JSON array of objects");
23
31
  const report = { rows: [], errors: [], truncated: false, sourceIndexes: [] };
24
32
  parsed.forEach((item, rowIndex) => {
25
- if (isPlainObject(item)) {
33
+ if (isPlainObject(item) && containsUnsafeLong(item)) {
34
+ report.errors.push({ rowIndex, code: "unsafe-integer", message: "Integer is beyond \xB1(2^53 \u2212 1) and would lose precision; import it as text" });
35
+ } else if (isPlainObject(item)) {
26
36
  report.rows.push(item);
27
37
  report.sourceIndexes.push(rowIndex);
28
38
  } else report.errors.push({ rowIndex, code: "not-object", message: "Row is not an object" });
@@ -0,0 +1,26 @@
1
+ import type { IndexLike } from './indexForm.js';
2
+ export type IndexCopySkipReason = 'multi-field-text' | 'unsupported-key' | 'unknown-key-order' | 'custom-weights';
3
+ export type IndexCopyPlan = {
4
+ call: 'createIndex';
5
+ name: string;
6
+ keys: Record<string, 1 | -1>;
7
+ options: {
8
+ name: string;
9
+ unique?: boolean;
10
+ expireAfter?: string;
11
+ };
12
+ } | {
13
+ call: 'createTextIndex';
14
+ name: string;
15
+ field: string;
16
+ } | {
17
+ call: 'skip';
18
+ name: string;
19
+ reason: IndexCopySkipReason;
20
+ };
21
+ /** The index MongoDB creates by itself on every collection; never copied. */
22
+ export declare const DEFAULT_INDEX_NAME = "_id_";
23
+ /** What recreating `index` takes: a `createIndex` with name, `unique` and `expireAfter`, a text index, or a skip with the reason. */
24
+ export declare function planIndexCopy(index: IndexLike): IndexCopyPlan;
25
+ /** The plans for every index of a collection, without the default `_id_` index. */
26
+ export declare function planIndexCopies(indexes: IndexLike[]): IndexCopyPlan[];
@@ -0,0 +1,22 @@
1
+ import { indexKeysWithOrder } from "./indexForm.js";
2
+ export const DEFAULT_INDEX_NAME = "_id_";
3
+ export function planIndexCopy(index) {
4
+ const { keys, orderKnown } = indexKeysWithOrder(index);
5
+ if (index.text) {
6
+ const weights = Object.entries(index.weights ?? {});
7
+ if (weights.length !== 1) return { call: "skip", name: index.name, reason: "multi-field-text" };
8
+ if (weights[0][1] !== 1) return { call: "skip", name: index.name, reason: "custom-weights" };
9
+ return { call: "createTextIndex", name: index.name, field: weights[0][0] };
10
+ }
11
+ if (keys.length === 0 || keys.some((k) => k.direction !== 1 && k.direction !== -1)) return { call: "skip", name: index.name, reason: "unsupported-key" };
12
+ if (!orderKnown) return { call: "skip", name: index.name, reason: "unknown-key-order" };
13
+ const orderedKeys = {};
14
+ for (const key of keys) orderedKeys[key.field] = key.direction;
15
+ const options = { name: index.name };
16
+ if (index.unique) options.unique = true;
17
+ if (index.expire && typeof index.expireAfterSeconds === "number" && index.expireAfterSeconds >= 0) options.expireAfter = `${index.expireAfterSeconds}s`;
18
+ return { call: "createIndex", name: index.name, keys: orderedKeys, options };
19
+ }
20
+ export function planIndexCopies(indexes) {
21
+ return indexes.filter((i) => i.name !== DEFAULT_INDEX_NAME).map(planIndexCopy);
22
+ }
@@ -0,0 +1,69 @@
1
+ export interface IndexLike {
2
+ name: string;
3
+ keys?: Record<string, unknown>;
4
+ weights?: Record<string, unknown>;
5
+ text?: boolean;
6
+ unique?: boolean;
7
+ expire?: boolean;
8
+ expireAfterSeconds?: number;
9
+ }
10
+ export interface IndexKey {
11
+ field: string;
12
+ /** 1, -1, or `text` for a field of a text index. */
13
+ direction: 1 | -1 | 'text' | 'other';
14
+ }
15
+ export declare const MAX_INDEX_FIELDS = 8;
16
+ /**
17
+ * The fields of an index in index order. A text index shows its `weights` fields. For others the key order the server lists
18
+ * is not reliable, so the standard name (`a_1_b_-1`) is used when it spells out exactly these keys; else the listed order.
19
+ */
20
+ export declare function indexKeys(index: IndexLike): IndexKey[];
21
+ /**
22
+ * `indexKeys` plus whether the order is **known**: always for one key or a text index, for a compound index only when its
23
+ * standard name spells out the keys. A custom-named compound index is listed in an arbitrary order, so the order is not
24
+ * known and must not be copied onto another collection.
25
+ */
26
+ export declare function indexKeysWithOrder(index: IndexLike): {
27
+ keys: IndexKey[];
28
+ orderKnown: boolean;
29
+ };
30
+ export declare function describeKey(key: IndexKey): string;
31
+ export { formatBytes } from './formatBytes.js';
32
+ export declare function isValidExpireAfter(text: string): boolean;
33
+ export type IndexKind = 'standard' | 'unique' | 'text' | 'expiring';
34
+ export interface IndexForm {
35
+ kind: IndexKind;
36
+ /** One row per field; a text or expiring index uses the first. */
37
+ fields: Array<{
38
+ field: string;
39
+ descending: boolean;
40
+ }>;
41
+ /** Optional name (standard and unique only). */
42
+ name: string;
43
+ expireAfter: string;
44
+ }
45
+ export type IndexFormProblem = 'no-field' | 'empty-field' | 'duplicate-field' | 'too-many-fields' | 'bad-duration' | 'bad-name';
46
+ export declare function validateIndexForm(form: IndexForm): IndexFormProblem[];
47
+ export type IndexRequest = {
48
+ call: 'createIndex';
49
+ keys: Record<string, 1 | -1>;
50
+ options?: {
51
+ unique?: boolean;
52
+ name?: string;
53
+ };
54
+ } | {
55
+ call: 'createTextIndex';
56
+ field: string;
57
+ } | {
58
+ call: 'createExpiringIndex';
59
+ field: string;
60
+ duration: string;
61
+ };
62
+ /** The call a valid form stands for. Compound standard and unique indexes go through `createIndex` (verified live). */
63
+ export declare function buildIndexRequest(form: IndexForm): IndexRequest;
64
+ export type IndexErrorKind = 'duplicate-values' | 'conflict' | 'empty-keys' | 'other';
65
+ /** What a create/drop failure means, from the server's message (MongoDB error codes 11000, 85/86 and 67). */
66
+ export declare function classifyIndexError(message: string): IndexErrorKind;
67
+ /** Never used since the counter started — a hint, not proof (counters restart with the server). `_id_` is never flagged. */
68
+ export declare function isUnusedIndex(name: string, ops: number | undefined): boolean;
69
+ export declare function canDropIndex(name: string): boolean;
@@ -0,0 +1,63 @@
1
+ export const MAX_INDEX_FIELDS = 8;
2
+ export function indexKeys(index) {
3
+ return indexKeysWithOrder(index).keys;
4
+ }
5
+ export function indexKeysWithOrder(index) {
6
+ if (index.text && index.weights && Object.keys(index.weights).length > 0) {
7
+ return { keys: Object.keys(index.weights).map((field) => ({ field, direction: "text" })), orderKnown: true };
8
+ }
9
+ const entries = Object.entries(index.keys ?? {}).map(([field, value]) => ({ field, direction: value === 1 || value === -1 ? value : "other", value }));
10
+ if (entries.length <= 1) return { keys: entries.map((e) => ({ field: e.field, direction: e.direction })), orderKnown: true };
11
+ const positions = entries.map((e) => ({ e, at: index.name.indexOf(`${e.field}_${String(e.value)}`) }));
12
+ if (positions.every((p) => p.at >= 0)) {
13
+ const sorted = [...positions].sort((a, b) => a.at - b.at);
14
+ if (sorted.map((p) => `${p.e.field}_${String(p.e.value)}`).join("_") === index.name) {
15
+ return { keys: sorted.map((p) => ({ field: p.e.field, direction: p.e.direction })), orderKnown: true };
16
+ }
17
+ }
18
+ return { keys: entries.map((e) => ({ field: e.field, direction: e.direction })), orderKnown: false };
19
+ }
20
+ export function describeKey(key) {
21
+ if (key.direction === "text") return `${key.field} (text)`;
22
+ return `${key.field}: ${key.direction === 1 ? "\u2191" : key.direction === -1 ? "\u2193" : "?"}`;
23
+ }
24
+ export { formatBytes } from "./formatBytes.js";
25
+ const DURATION = /^[1-9]\d{0,8}[smhd]$/;
26
+ export function isValidExpireAfter(text) {
27
+ return DURATION.test(text.trim());
28
+ }
29
+ export function validateIndexForm(form) {
30
+ const problems = [];
31
+ const rows = form.kind === "text" || form.kind === "expiring" ? form.fields.slice(0, 1) : form.fields;
32
+ if (rows.length === 0) return ["no-field"];
33
+ const names = rows.map((r) => r.field.trim());
34
+ if (names.includes("")) problems.push("empty-field");
35
+ if (new Set(names.filter(Boolean)).size !== names.filter(Boolean).length) problems.push("duplicate-field");
36
+ if (rows.length > MAX_INDEX_FIELDS) problems.push("too-many-fields");
37
+ if (form.kind === "expiring" && !isValidExpireAfter(form.expireAfter)) problems.push("bad-duration");
38
+ if ((form.kind === "standard" || form.kind === "unique") && form.name.trim().length > 100) problems.push("bad-name");
39
+ return problems;
40
+ }
41
+ export function buildIndexRequest(form) {
42
+ const rows = form.fields.map((r) => ({ field: r.field.trim(), descending: r.descending }));
43
+ if (form.kind === "text") return { call: "createTextIndex", field: rows[0].field };
44
+ if (form.kind === "expiring") return { call: "createExpiringIndex", field: rows[0].field, duration: form.expireAfter.trim() };
45
+ const keys = {};
46
+ for (const row of rows) keys[row.field] = row.descending ? -1 : 1;
47
+ const options = {};
48
+ if (form.kind === "unique") options.unique = true;
49
+ if (form.name.trim() !== "") options.name = form.name.trim();
50
+ return Object.keys(options).length > 0 ? { call: "createIndex", keys, options } : { call: "createIndex", keys };
51
+ }
52
+ export function classifyIndexError(message) {
53
+ if (/11000|duplicate key|E11000/i.test(message)) return "duplicate-values";
54
+ if (/equivalent index already exists|IndexOptionsConflict|IndexKeySpecsConflict|already exists with a different name/i.test(message)) return "conflict";
55
+ if (/keys cannot be empty/i.test(message)) return "empty-keys";
56
+ return "other";
57
+ }
58
+ export function isUnusedIndex(name, ops) {
59
+ return name !== "_id_" && ops === 0;
60
+ }
61
+ export function canDropIndex(name) {
62
+ return name !== "_id_";
63
+ }
@@ -0,0 +1,17 @@
1
+ export type Settled<R> = {
2
+ ok: true;
3
+ value: R;
4
+ } | {
5
+ ok: false;
6
+ error: unknown;
7
+ };
8
+ export interface LimitedMapOptions {
9
+ signal?: AbortSignal;
10
+ /** Called after every finished item with how many are done so far. */
11
+ onProgress?: (done: number, total: number) => void;
12
+ }
13
+ /**
14
+ * The result of every item that was started, in input order; an item that never started (the run was aborted first) is
15
+ * `undefined`. A rejected call is `{ ok: false, error }`, never thrown.
16
+ */
17
+ export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>, options?: LimitedMapOptions): Promise<Array<Settled<R> | undefined>>;
@@ -0,0 +1,19 @@
1
+ export async function mapLimit(items, limit, fn, options = {}) {
2
+ const results = Array.from({ length: items.length });
3
+ const workers = Math.max(1, Math.min(Math.floor(limit) || 1, items.length));
4
+ let next = 0;
5
+ let done = 0;
6
+ async function worker() {
7
+ while (next < items.length && !options.signal?.aborted) {
8
+ const index = next++;
9
+ try {
10
+ results[index] = { ok: true, value: await fn(items[index], index) };
11
+ } catch (error) {
12
+ results[index] = { ok: false, error };
13
+ }
14
+ options.onProgress?.(++done, items.length);
15
+ }
16
+ }
17
+ await Promise.all(Array.from({ length: workers }, worker));
18
+ return results;
19
+ }
@@ -0,0 +1,15 @@
1
+ export type LuceneNode = {
2
+ kind: 'clause';
3
+ text: string;
4
+ } | {
5
+ kind: 'and' | 'or';
6
+ parts: LuceneNode[];
7
+ } | {
8
+ kind: 'not';
9
+ node: LuceneNode;
10
+ };
11
+ export declare class UnsupportedExpressionError extends Error {
12
+ constructor(expression: string, reason: string);
13
+ }
14
+ /** `null` for an empty expression; throws {@link UnsupportedExpressionError} for anything it cannot read. */
15
+ export declare function parseLuceneExpression(expression: string): LuceneNode | null;