@sfxcode/nuxt-ui-mongocamp 1.5.8 → 2.1.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 (104) hide show
  1. package/README.md +5 -5
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +1 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +5 -2
  5. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +1 -0
  6. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +1 -0
  7. package/dist/runtime/components/MongocampAggregationStagePreview.vue +4 -2
  8. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +1 -0
  9. package/dist/runtime/components/MongocampBucketFiles.vue +4 -6
  10. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +1 -0
  11. package/dist/runtime/components/MongocampCollectionCharts.vue +4 -2
  12. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +1 -0
  13. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +1 -0
  14. package/dist/runtime/components/MongocampCollectionCopy.vue +5 -3
  15. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +1 -0
  16. package/dist/runtime/components/MongocampCollectionData.vue +63 -36
  17. package/dist/runtime/components/MongocampCollectionInfos.vue +16 -1
  18. package/dist/runtime/components/MongocampDocumentView.vue +6 -1
  19. package/dist/runtime/components/MongocampExportAll.d.vue.ts +1 -0
  20. package/dist/runtime/components/MongocampExportAll.vue +12 -0
  21. package/dist/runtime/components/MongocampExportAll.vue.d.ts +1 -0
  22. package/dist/runtime/components/MongocampImport.vue +3 -0
  23. package/dist/runtime/components/MongocampIndexes.vue +7 -3
  24. package/dist/runtime/components/MongocampQueryBar.vue +15 -0
  25. package/dist/runtime/components/MongocampServerInfo.vue +1 -14
  26. package/dist/runtime/components/MongocampServerStatus.vue +7 -2
  27. package/dist/runtime/components/MongocampSettings.d.vue.ts +0 -3
  28. package/dist/runtime/components/MongocampSettings.vue +2 -48
  29. package/dist/runtime/components/MongocampSettings.vue.d.ts +0 -3
  30. package/dist/runtime/components/MongocampVersion.d.vue.ts +1 -1
  31. package/dist/runtime/components/MongocampVersion.vue +14 -7
  32. package/dist/runtime/components/MongocampVersion.vue.d.ts +1 -1
  33. package/dist/runtime/composables/useMongocampAdmin.js +6 -5
  34. package/dist/runtime/composables/useMongocampAggregation.d.ts +11 -3
  35. package/dist/runtime/composables/useMongocampAggregation.js +19 -10
  36. package/dist/runtime/composables/useMongocampBucket.d.ts +4 -0
  37. package/dist/runtime/composables/useMongocampBucket.js +7 -6
  38. package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +6 -4
  39. package/dist/runtime/composables/useMongocampBulkByFilter.js +11 -6
  40. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +3 -1
  41. package/dist/runtime/composables/useMongocampCollectionCopy.js +4 -2
  42. package/dist/runtime/composables/useMongocampCollectionStats.js +2 -4
  43. package/dist/runtime/composables/useMongocampError.d.ts +1 -1
  44. package/dist/runtime/composables/useMongocampError.js +4 -1
  45. package/dist/runtime/composables/useMongocampExportAll.d.ts +17 -7
  46. package/dist/runtime/composables/useMongocampExportAll.js +19 -20
  47. package/dist/runtime/composables/useMongocampFetchAll.d.ts +11 -5
  48. package/dist/runtime/composables/useMongocampFetchAll.js +8 -8
  49. package/dist/runtime/composables/useMongocampJobs.js +3 -2
  50. package/dist/runtime/composables/useMongocampQuery.d.ts +26 -36
  51. package/dist/runtime/composables/useMongocampQuery.js +42 -49
  52. package/dist/runtime/composables/useMongocampSchema.js +2 -0
  53. package/dist/runtime/composables/useMongocampSystem.d.ts +3 -9
  54. package/dist/runtime/composables/useMongocampSystem.js +1 -9
  55. package/dist/runtime/locales/de.json +13 -12
  56. package/dist/runtime/locales/en.json +13 -12
  57. package/dist/runtime/publicUtils.d.ts +1 -0
  58. package/dist/runtime/publicUtils.js +1 -0
  59. package/dist/runtime/server/handlers/mongocampProxy.d.ts +1 -1
  60. package/dist/runtime/server/handlers/mongocampProxy.js +12 -12
  61. package/dist/runtime/utils/aggregationErrors.d.ts +0 -4
  62. package/dist/runtime/utils/aggregationErrors.js +0 -7
  63. package/dist/runtime/utils/aggregationPipeline.d.ts +2 -1
  64. package/dist/runtime/utils/aggregationPipeline.js +2 -3
  65. package/dist/runtime/utils/caseInsensitive.d.ts +10 -0
  66. package/dist/runtime/utils/caseInsensitive.js +8 -0
  67. package/dist/runtime/utils/collectionStats.d.ts +4 -1
  68. package/dist/runtime/utils/collectionStats.js +2 -2
  69. package/dist/runtime/utils/configRows.d.ts +3 -3
  70. package/dist/runtime/utils/cursorPaging.d.ts +16 -0
  71. package/dist/runtime/utils/cursorPaging.js +17 -0
  72. package/dist/runtime/utils/documentCompare.js +2 -3
  73. package/dist/runtime/utils/documentPaths.d.ts +5 -5
  74. package/dist/runtime/utils/documentPaths.js +9 -2
  75. package/dist/runtime/utils/documentTree.js +3 -0
  76. package/dist/runtime/utils/exportTrailer.d.ts +10 -0
  77. package/dist/runtime/utils/exportTrailer.js +28 -0
  78. package/dist/runtime/utils/fileFilter.d.ts +7 -0
  79. package/dist/runtime/utils/fileFilter.js +11 -0
  80. package/dist/runtime/utils/filterBuilder.d.ts +1 -1
  81. package/dist/runtime/utils/filterBuilder.js +12 -12
  82. package/dist/runtime/utils/filterSuggestions.js +1 -1
  83. package/dist/runtime/utils/indexForm.d.ts +7 -0
  84. package/dist/runtime/utils/indexForm.js +9 -0
  85. package/dist/runtime/utils/pagedFetch.d.ts +13 -0
  86. package/dist/runtime/utils/pagedFetch.js +44 -0
  87. package/dist/runtime/utils/queryState.d.ts +5 -0
  88. package/dist/runtime/utils/queryState.js +3 -2
  89. package/dist/runtime/utils/relaxedValues.d.ts +17 -0
  90. package/dist/runtime/utils/relaxedValues.js +51 -0
  91. package/dist/runtime/utils/requestLimits.d.ts +1 -1
  92. package/dist/runtime/utils/requestLimits.js +1 -1
  93. package/dist/runtime/utils/savedQueries.d.ts +2 -0
  94. package/dist/runtime/utils/savedQueries.js +1 -0
  95. package/dist/runtime/utils/schemaAnalysis.d.ts +4 -4
  96. package/dist/runtime/utils/schemaAnalysis.js +2 -2
  97. package/dist/runtime/utils/sensitiveFields.d.ts +20 -0
  98. package/dist/runtime/utils/sensitiveFields.js +63 -0
  99. package/dist/runtime/utils/serverError.d.ts +7 -0
  100. package/dist/runtime/utils/serverError.js +11 -0
  101. package/dist/runtime/utils/serverStatus.d.ts +2 -2
  102. package/package.json +12 -6
  103. package/dist/runtime/utils/luceneExpression.d.ts +0 -15
  104. package/dist/runtime/utils/luceneExpression.js +0 -74
@@ -1,16 +1,14 @@
1
1
  import { useMongocampClientApi } from "#imports";
2
2
  import { mapIndexUsage, mapStorage } from "../utils/collectionStats.js";
3
- import { useMongocampAggregation } from "./useMongocampAggregation.js";
4
3
  const REQUEST_TIMEOUT_MS = 15e3;
5
4
  export function useMongocampCollectionStats() {
6
- const { collectionApi } = useMongocampClientApi();
7
- const { runAggregation } = useMongocampAggregation();
5
+ const { collectionApi, indexApi } = useMongocampClientApi();
8
6
  async function getStorage(collection) {
9
7
  const status = await collectionApi.getCollectionInformation({ collectionName: collection }, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
10
8
  return mapStorage(status);
11
9
  }
12
10
  async function getIndexUsage(collection) {
13
- const { rows } = await runAggregation(collection, [{ stage: "$indexStats", value: {} }], { rowsPerPage: 1e3 }, { allowStatsStages: true });
11
+ const rows = await indexApi.indexStats({ collectionName: collection }, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
14
12
  return mapIndexUsage(rows);
15
13
  }
16
14
  return { getStorage, getIndexUsage };
@@ -1,4 +1,4 @@
1
- export type MongocampErrorKind = 'network' | 'unauthorized' | 'forbidden' | 'notAllowed' | 'invalid' | 'other';
1
+ export type MongocampErrorKind = 'network' | 'unauthorized' | 'forbidden' | 'notAllowed' | 'invalid' | 'notFound' | 'other';
2
2
  export interface DescribedError {
3
3
  kind: MongocampErrorKind;
4
4
  message: string;
@@ -14,6 +14,9 @@ export function useMongocampError() {
14
14
  if (status === 403) {
15
15
  return { kind: "forbidden", message: t("nuxtUiMongocamp.errors.forbidden") };
16
16
  }
17
+ if (status === 404) {
18
+ return { kind: "notFound", message: t("nuxtUiMongocamp.errors.notFound") };
19
+ }
17
20
  const message = error instanceof Error && error.message ? error.message : t(fallbackKey ?? "nuxtUiMongocamp.errors.generic");
18
21
  return { kind: "other", message };
19
22
  }
@@ -27,7 +30,7 @@ export function useMongocampError() {
27
30
  }
28
31
  if (base.kind === "forbidden") return base;
29
32
  if (server.message && server.status !== void 0 && server.status >= 400) {
30
- return { kind: server.status === 400 ? "invalid" : "other", message: server.message };
33
+ return { kind: server.status === 400 ? "invalid" : server.status === 404 ? "notFound" : "other", message: server.message };
31
34
  }
32
35
  return base;
33
36
  }
@@ -2,8 +2,10 @@ import type { ExportFormat } from '../utils/exportDocuments.js';
2
2
  export interface ExportCollectionOptions {
3
3
  collection: string;
4
4
  format: ExportFormat;
5
- /** Lucene filter: export only the documents that match (the current filter of a table). It travels in the URL: over ~1 800 encoded characters it throws `FilterTooLongError`. */
5
+ /** Lucene filter: export only the documents that match (the current filter of a table). Sent in the request body (server 2.2), so any length. */
6
6
  filter?: string;
7
+ /** Match the wildcards of `filter` without regard to case (server 2.0 matches them case-sensitively otherwise). */
8
+ filterCaseInsensitive?: boolean;
7
9
  sort?: string[];
8
10
  /** Limit the fields; for a CSV they are also its columns, in this order (default: the fields of the first 1 000 documents). */
9
11
  projection?: string[];
@@ -11,7 +13,13 @@ export interface ExportCollectionOptions {
11
13
  columns?: string[];
12
14
  /** Stop after this many documents (`limit`); default: all. */
13
15
  maxRows?: number;
14
- /** How many documents the caller expects (the count of the filter): a file with fewer is reported as `incomplete`. */
16
+ /**
17
+ * JSON/NDJSON only: `relaxed` (default) is readable and keeps ids, dates, big integers, decimals and date-like text, but a
18
+ * re-import stores every whole number as Int64; `canonical` wraps every number too, so a re-import keeps Int32/Int64/Double
19
+ * exactly (larger files). Ignored for CSV, which stays plain.
20
+ */
21
+ extendedJson?: 'relaxed' | 'canonical';
22
+ /** How many documents the caller expects (the count of the filter): the document count of a complete JSON file (NDJSON and CSV report their own). */
15
23
  expected?: number;
16
24
  /** After every chunk of the stream. */
17
25
  onProgress?: (progress: ExportProgress) => void;
@@ -34,18 +42,20 @@ export interface ExportResult {
34
42
  mimeType: string;
35
43
  format: ExportFormat;
36
44
  bytes: number;
37
- /** Documents in the file: exact for NDJSON (one per line); for JSON and CSV the expected count when the file is complete. */
45
+ /** Documents in the file: exact for NDJSON and CSV (the server's end marker); for JSON the expected count when the file is complete. */
38
46
  documents?: number;
39
47
  /**
40
- * The file is certainly **cut short**: the server ends a stream that fails midway with a normal `200`, so the file is checked
41
- * — JSON must end with `]`, NDJSON and CSV must hold at least the expected number of documents. Tell the user.
48
+ * The file is **cut short**: the server ends a stream that fails midway with a normal `200`, so the file is checked — JSON
49
+ * must end with `]`, NDJSON and CSV must end with the server's end marker (`trailer=true`, server 2.2; the marker itself is
50
+ * removed from the file). Tell the user.
42
51
  */
43
52
  incomplete: boolean;
44
53
  }
45
54
  /**
46
55
  * Exports a whole collection, or every document matching a filter, as JSON, NDJSON or CSV — not just the rows on screen.
47
- * The server streams the file (`GET …/documents/export`, server 1.8.1): there is no document cap and the browser never parses
48
- * a document. Values are written as plain JSON, so an integer beyond 2^53 keeps every digit as the text the server wrote.
56
+ * The server streams the file (`POST …/documents/export`, server 2.2: filter, sort, projection and limit in the body): there is no document cap and the browser never parses
57
+ * a document. JSON and NDJSON files are relaxed Extended JSON (`{ "$oid" }`, `{ "$date" }`, `{ "$numberLong" }`, …), so they go
58
+ * back in through the importer with every type; CSV stays plain text (an integer beyond 2^53 keeps every digit).
49
59
  * The file ends up in a `Blob` (the browser may keep it on disk) and is handed to the browser as a download.
50
60
  */
51
61
  export declare function useMongocampExportAll(): {
@@ -1,8 +1,7 @@
1
1
  import { useMongocampClientApi } from "#imports";
2
2
  import { downloadBlob } from "../utils/exportRows.js";
3
3
  import { EXPORT_MIME_TYPES, exportFilename } from "../utils/exportDocuments.js";
4
- import { FilterTooLongError } from "../utils/aggregationErrors.js";
5
- import { isFilterTooLong, MAX_ENCODED_FILTER_LENGTH } from "../utils/requestLimits.js";
4
+ import { readExportTrailer } from "../utils/exportTrailer.js";
6
5
  function countingStream(onProgress) {
7
6
  const state = { bytes: 0, newlines: 0, last: 0 };
8
7
  const stream = new TransformStream({
@@ -20,35 +19,35 @@ export function useMongocampExportAll() {
20
19
  const { documentApi } = useMongocampClientApi();
21
20
  async function exportCollection(options) {
22
21
  const { collection, format, download = true } = options;
23
- if (isFilterTooLong(options.filter)) throw new FilterTooLongError(MAX_ENCODED_FILTER_LENGTH);
24
22
  const projection = options.projection?.length ? options.projection : options.columns?.length ? options.columns : void 0;
25
- const response = await documentApi.exportDocumentsRaw({
23
+ const filter = options.filter?.trim() ? options.filter : void 0;
24
+ const response = await documentApi.exportDocumentsByBodyRaw({
26
25
  collectionName: collection,
26
+ exportRequest: { filter, sort: options.sort?.length ? options.sort : void 0, projection, limit: options.maxRows },
27
27
  format,
28
- filter: options.filter?.trim() ? options.filter : void 0,
29
- sort: options.sort?.length ? options.sort : void 0,
30
- projection,
31
- limit: options.maxRows
28
+ filterCaseInsensitive: filter ? options.filterCaseInsensitive : void 0,
29
+ // CSV is plain unless a format is asked for; the JSON formats keep their types
30
+ extendedJson: format === "csv" ? void 0 : options.extendedJson ?? "relaxed",
31
+ // an end (or error) marker as the last line, so a cut-off file can be told from a complete one; JSON has its `]`
32
+ trailer: format === "json" ? void 0 : true
32
33
  }, options.signal ? { signal: options.signal } : void 0);
33
34
  const mimeType = EXPORT_MIME_TYPES[format];
34
- const { stream, state } = countingStream(options.onProgress);
35
+ const { stream } = countingStream(options.onProgress);
35
36
  const body = response.raw.body;
36
- const blob = body ? await new Response(body.pipeThrough(stream), { headers: { "content-type": mimeType } }).blob() : await response.raw.blob();
37
- const bytes = body ? state.bytes : blob.size;
38
- const lines = body ? state.newlines + (state.last !== 10 && state.bytes > 0 ? 1 : 0) : 0;
39
- const wanted = options.expected === void 0 ? void 0 : Math.min(options.expected, options.maxRows ?? Infinity);
37
+ const received = body ? await new Response(body.pipeThrough(stream), { headers: { "content-type": mimeType } }).blob() : await response.raw.blob();
38
+ let blob = received;
40
39
  let incomplete;
41
40
  let documents;
42
41
  if (format === "json") {
43
- incomplete = !(await blob.slice(Math.max(0, bytes - 8)).text()).trimEnd().endsWith("]");
44
- if (!incomplete) documents = wanted;
45
- } else if (format === "ndjson") {
46
- documents = lines;
47
- incomplete = wanted !== void 0 && lines < wanted;
42
+ incomplete = !(await blob.slice(Math.max(0, blob.size - 8)).text()).trimEnd().endsWith("]");
43
+ if (!incomplete) documents = options.expected === void 0 ? void 0 : Math.min(options.expected, options.maxRows ?? Infinity);
48
44
  } else {
49
- incomplete = wanted !== void 0 && lines - 1 < wanted;
50
- if (!incomplete) documents = wanted;
45
+ const trailer = await readExportTrailer(received, format);
46
+ blob = trailer.marker ? received.slice(0, trailer.cut, mimeType) : received;
47
+ incomplete = trailer.count === void 0;
48
+ documents = trailer.count;
51
49
  }
50
+ const bytes = blob.size;
52
51
  const filename = options.filename ?? exportFilename(collection, format);
53
52
  if (download) downloadBlob(filename, blob);
54
53
  return { blob, filename, mimeType, format, bytes, documents, incomplete };
@@ -2,22 +2,28 @@ import type { FetchAllOptions, FetchAllResult } from '../utils/pagedFetch.js';
2
2
  export interface FetchAllDocumentsOptions<T> extends FetchAllOptions<T> {
3
3
  /** Lucene filter, as for the document list. */
4
4
  filter?: string;
5
+ /** Match the wildcards of `filter` without regard to case (server 2.0 matches them case-sensitively otherwise). */
6
+ filterCaseInsensitive?: boolean;
5
7
  /** Sort keys as the document list takes them (`['name', '-age']`). Without one the server's natural order is used. */
6
8
  sort?: string[];
7
9
  /** Fields to return; `['_id']` is the cheap way to collect ids. */
8
10
  projection?: string[];
9
11
  }
10
12
  export interface FetchAllFilesOptions<T> extends FetchAllOptions<T> {
13
+ /** A MongoDB query as JSON text (not Lucene — the file list ignores Lucene), e.g. from `filenameFilter`. */
11
14
  filter?: string;
12
15
  sort?: string;
13
16
  projection?: string;
14
17
  }
15
18
  /**
16
- * Reads every document of a collection (or of a Lucene filter) page by page: `fetchAllPages` over the document list. The
17
- * rows are what the list returns — read from the response text, so integers beyond 2^53 are `{ $numberLong }` wrappers
18
- * (run them through `unwrapExtendedJson` for display) — and the total comes from the pagination header.
19
- * Capped at 10 000 rows by default (`maxRows` raises it); see `utils/pagedFetch.ts` for stopping, progress, abort and
20
- * the effect of documents changing during the read. Every page has its own 60 s timeout.
19
+ * Reads every document of a collection (or of a Lucene filter) page by page, following the server's cursor
20
+ * (`fetchAllByCursor`, server 2.0): every page costs the same, and documents added or removed while reading do not make the
21
+ * others missing or repeated (verified: 25 000 documents read during concurrent inserts, none lost or doubled). The
22
+ * rows are relaxed Extended JSON, as the server sends them — `_id` `{ $oid }`, dates `{ $date }`, integers beyond 2^53
23
+ * `{ $numberLong }`, decimals, date-looking text `{ $string }` (`idOf` / `unwrapExtendedJson` give plain values) — and the
24
+ * total comes from the first page's pagination header (later pages skip the count).
25
+ * Capped at 10 000 rows by default (`maxRows` raises it); see `utils/pagedFetch.ts` for stopping, progress and abort.
26
+ * Every page has its own 60 s timeout.
21
27
  */
22
28
  export declare function useMongocampFetchAll(): {
23
29
  fetchAllDocuments: <T = Record<string, unknown>>(collectionName: string, options?: FetchAllDocumentsOptions<T>) => Promise<FetchAllResult<T>>;
@@ -1,6 +1,6 @@
1
1
  import { useMongocampClientApi } from "#imports";
2
2
  import { readJsonKeepingLongs } from "../utils/bigIntJson.js";
3
- import { fetchAllPages } from "../utils/pagedFetch.js";
3
+ import { fetchAllByCursor } from "../utils/pagedFetch.js";
4
4
  import { headerNumber } from "../utils/paginationHeaders.js";
5
5
  const PAGE_TIMEOUT_MS = 6e4;
6
6
  function requestInit(signal) {
@@ -10,17 +10,17 @@ function requestInit(signal) {
10
10
  export function useMongocampFetchAll() {
11
11
  const { documentApi, fileApi } = useMongocampClientApi();
12
12
  async function fetchAllDocuments(collectionName, options = {}) {
13
- const { filter, sort, projection, ...paging } = options;
14
- return fetchAllPages(async (page, pageSize) => {
15
- const response = await documentApi.searchDocumentsRaw({ collectionName, searchRequest: { filter, sort, projection }, page, rowsPerPage: pageSize }, requestInit(options.signal));
16
- return { rows: await readJsonKeepingLongs(response), total: headerNumber(response.raw?.headers, "x-pagination-count-rows") };
13
+ const { filter, filterCaseInsensitive, sort, projection, ...paging } = options;
14
+ return fetchAllByCursor(async (after, pageSize, first) => {
15
+ const response = await documentApi.searchDocumentsRaw({ collectionName, searchRequest: { filter, sort, projection }, after, count: first ? "exact" : "none", rowsPerPage: pageSize, extendedJson: "relaxed", filterCaseInsensitive }, requestInit(options.signal));
16
+ return { rows: await readJsonKeepingLongs(response), next: response.raw?.headers.get("x-pagination-next") || void 0, total: headerNumber(response.raw?.headers, "x-pagination-count-rows") };
17
17
  }, paging);
18
18
  }
19
19
  async function fetchAllFiles(bucketName, options = {}) {
20
20
  const { filter, sort, projection, ...paging } = options;
21
- return fetchAllPages(async (page, pageSize) => {
22
- const response = await fileApi.listFilesRaw({ bucketName, filter, sort, projection, page, rowsPerPage: pageSize }, requestInit(options.signal));
23
- return { rows: await readJsonKeepingLongs(response), total: headerNumber(response.raw?.headers, "x-pagination-count-rows") };
21
+ return fetchAllByCursor(async (after, pageSize, first) => {
22
+ const response = await fileApi.listFilesRaw({ bucketName, filter, sort, projection, after, count: first ? "exact" : "none", rowsPerPage: pageSize }, requestInit(options.signal));
23
+ return { rows: await readJsonKeepingLongs(response), next: response.raw?.headers.get("x-pagination-next") || void 0, total: headerNumber(response.raw?.headers, "x-pagination-count-rows") };
24
24
  }, paging);
25
25
  }
26
26
  return { fetchAllDocuments, fetchAllFiles };
@@ -1,4 +1,5 @@
1
1
  import { useMongocampClientApi } from "#imports";
2
+ import { ignoringNotFound } from "../utils/serverError.js";
2
3
  export function useMongocampJobs() {
3
4
  const { jobApi } = useMongocampClientApi();
4
5
  async function listJobs() {
@@ -18,8 +19,8 @@ export function useMongocampJobs() {
18
19
  return result.value;
19
20
  }
20
21
  async function deleteJob(jobGroup, jobName) {
21
- const result = await jobApi.deleteJob({ jobGroup, jobName });
22
- return result.value;
22
+ const result = await ignoringNotFound(() => jobApi.deleteJob({ jobGroup, jobName }));
23
+ return result ? result.value : true;
23
24
  }
24
25
  return { listJobs, listPossibleJobs, registerJob, updateJob, executeJob, deleteJob };
25
26
  }
@@ -1,23 +1,18 @@
1
1
  /** Scalar value accepted by all query helpers. `null` and `undefined` produce an empty (no-op) expression. */
2
2
  export type QueryValue = string | number | boolean | null | undefined;
3
3
  /**
4
- * What kind of values a field holds, when you know it. It only selects a shorter query for
5
- * `exists`/`notExists`: `text` → `field:*`, `number` and `date` → a closed range over every possible value.
4
+ * What kind of values a field holds. Server 2.0 tests existence the same way for every type, so this no longer changes the
5
+ * query; it is still accepted so existing calls keep compiling.
6
+ * @deprecated not needed with MongoCamp 2.0
6
7
  */
7
8
  export type ExistsFieldType = 'text' | 'number' | 'date';
8
9
  export interface MongocampQueryHelper {
9
10
  /**
10
- * Matches documents where the field has a value. Without `type` this ORs a text wildcard with a
11
- * full-range number and a full-range date clause, so it works for any of those types.
12
- *
13
- * MongoCamp (last verified on 1.6.3, not re-checked on 1.8) does not understand `_exists_:field` (it matches nothing), and `field:*` only matches text,
14
- * which is why this is not just a wildcard.
11
+ * `_exists_:field` — the field is present, whatever its type (text, number, date, boolean, array, object). Like
12
+ * MongoDB's `$exists`, a field holding `null`, `''` or `[]` exists too. `type` is ignored (kept for older calls).
15
13
  */
16
14
  exists: (fieldName: string, type?: ExistsFieldType) => string;
17
- /**
18
- * Matches documents where the field is absent: every `exists` clause negated and ANDed (negating the
19
- * whole group is silently ignored by the server).
20
- */
15
+ /** `-_exists_:field` — the field is absent. */
21
16
  notExists: (fieldName: string, type?: ExistsFieldType) => string;
22
17
  /** Alias for `notExists`. */
23
18
  isEmpty: (fieldName: string, type?: ExistsFieldType) => string;
@@ -36,14 +31,11 @@ export interface MongocampQueryHelper {
36
31
  /**
37
32
  * `field:[from TO to]` — inclusive range.
38
33
  *
39
- * Pass `null` (or `'*'`) for an open end. MongoCamp (last verified on 1.6.3, not re-checked on 1.8) rejects `[x TO *]`, so the open end is replaced by
40
- * the far bound of the other bound's type: the 64-bit integer limits for numbers, year 0001 / 9999 for
41
- * dates. Both ends open means "has a value" and returns `exists(field)`. An open end next to a *text*
42
- * bound can't be expressed and still becomes `*`, which the server rejects.
34
+ * Pass `null` (or `'*'`) for an open end (`[x TO *]`); both ends open is `exists(field)`.
43
35
  *
44
- * A date without a time is widened to the whole UTC day (`T00:00:00Z` as lower, `T23:59:59.999Z` as
45
- * upper bound) — the server matches nothing for a bare date. Characters that would break out of the
46
- * range (brackets, quotes, whitespace…) in a bound are escaped.
36
+ * A date without a time is midnight UTC for the server; as the inclusive **upper** bound the server (2.2) covers that whole
37
+ * day — "up to 2024-06-15" includes the 15th. Characters that would break out of the range (brackets, quotes,
38
+ * whitespace…) in a bound are escaped.
47
39
  */
48
40
  inRange: (fieldName: string, from: QueryValue, to: QueryValue) => string;
49
41
  /**
@@ -105,14 +97,19 @@ export interface MongocampQueryHelper {
105
97
  /**
106
98
  * `_id:"<hex>"` — the document with this id. The id must be a 24-character hex ObjectId (any case); anything else
107
99
  * **throws** a `TypeError` instead of returning `''`, because "no filter" would match every document. (A wildcard on
108
- * `_id` matches nothing on the server, so there is no `like` for ids.)
100
+ * `_id` matches nothing on the server, so there is no `like` for ids.) Takes the id as text or as a relaxed read returns
101
+ * it, `{ $oid }`.
109
102
  */
110
- byId: (id: string) => string;
103
+ byId: (id: string | {
104
+ $oid: string;
105
+ }) => string;
111
106
  /**
112
107
  * `_id:("a" OR "b")` — any of these documents. Every id must be a 24-character hex ObjectId or it throws, like `byId`.
113
108
  * An empty array returns `''` (no clause), as `inClause` does.
114
109
  */
115
- byIds: (ids: string[]) => string;
110
+ byIds: (ids: Array<string | {
111
+ $oid: string;
112
+ }>) => string;
116
113
  /** `field:true` — a boolean field that is true. A document without the field does not match. */
117
114
  isTrue: (fieldName: string) => string;
118
115
  /** `field:false` — a boolean field that is false. A document without the field does not match. */
@@ -123,32 +120,25 @@ export interface MongocampQueryHelper {
123
120
  */
124
121
  arrayContains: (fieldName: string, value: QueryValue) => string;
125
122
  /**
126
- * The field is an array with at least one element (an empty array and a missing field do not match). Written like
127
- * `exists` — a text wildcard ORed with a full number and a full date range — because `field:*` alone only finds
128
- * arrays of *text* (verified: `nums:*` matched no array of numbers). Pass `type` when you know the element type for the
129
- * shorter clause. Arrays of booleans and of objects are not covered (nothing matches them).
123
+ * `field.0:*` — the field is an array with at least one element, of any type (an empty array and a missing field do
124
+ * not match). `type` is ignored (kept for older calls).
130
125
  */
131
126
  hasItems: (fieldName: string, type?: ExistsFieldType) => string;
132
127
  /**
133
- * The whole UTC day `YYYY-MM-DD`: `field:[YYYY-MM-DDT00:00:00Z TO YYYY-MM-DDT23:59:59.999Z]`. The server matches nothing
134
- * for a bare one-day range, so the bounds are widened to the full day. Throws a `TypeError` for anything that is not a
135
- * real calendar date.
128
+ * The whole UTC day `YYYY-MM-DD`: `field:[YYYY-MM-DD TO YYYY-MM-DD]` (the server, 2.2, lets a bare inclusive upper date
129
+ * cover its whole day). Throws a `TypeError` for anything that is not a real calendar date.
136
130
  */
137
131
  onDay: (fieldName: string, day: string) => string;
138
132
  /** `-field:[the whole UTC day]` — everything except that day (documents without the field included). */
139
133
  notOnDay: (fieldName: string, day: string) => string;
140
134
  /**
141
- * The negation of any expression these helpers produced, written so the server evaluates it correctly.
142
- * MongoCamp (last verified on 1.6.3, not re-checked on 1.8) evaluates `-(A AND B)` as `-A AND -B`, so a negated `AND` group is rewritten with
143
- * De Morgan's law as `((-A) OR (-B))` — each negated clause in its own parentheses, which the server needs — and a
144
- * negated `OR` group as `((-A) AND (-B))`, recursively. A single clause becomes `-clause` (and `-clause` becomes
145
- * `clause`). Returns `''` for an empty expression. Throws `UnsupportedExpressionError` for text it cannot read
146
- * (`NOT …`, `AND`/`OR` mixed without parentheses) rather than guessing.
135
+ * The negation of any expression: `-(expression)` — server 2.0 follows Lucene, so `-(A AND B)` is "not both". A single
136
+ * clause becomes `-clause` and `-clause` becomes `clause`. Returns `''` for an empty expression.
147
137
  */
148
138
  not: (queryPart: string | null | undefined) => string;
149
- /** The negation of "all of these": `notAnd(a, b)` = `not(and(a, b))` = `((-a) OR (-b))`. Empty parts are ignored. */
139
+ /** The negation of "all of these": `notAnd(a, b)` = `-(a AND b)`. Empty parts are ignored. */
150
140
  notAnd: (...queryParts: (string | null | undefined)[]) => string;
151
- /** The negation of "any of these": `notOr(a, b)` = `not(or(a, b))` = `((-a) AND (-b))`. Empty parts are ignored. */
141
+ /** The negation of "any of these": `notOr(a, b)` = `-(a OR b)`. Empty parts are ignored. */
152
142
  notOr: (...queryParts: (string | null | undefined)[]) => string;
153
143
  }
154
144
  export declare function useMongocampQuery(): MongocampQueryHelper;
@@ -1,17 +1,8 @@
1
1
  import { escapeFieldName } from "../utils/escapeFieldName.js";
2
- import { isIsoDateTimeString } from "../utils/isoDate.js";
3
2
  import { isObjectIdHex } from "../utils/objectId.js";
4
- import { parseLuceneExpression } from "../utils/luceneExpression.js";
5
3
  import { useMongocampQueryBuilder } from "./useMongocampQueryBuilder.js";
6
- const NUMBER_BOUNDS = { from: "-9223372036854775808", to: "9223372036854775807" };
7
- const DATE_BOUNDS = { from: "0001-01-01T00:00:00Z", to: "9999-12-31T23:59:59.999Z" };
8
- const PLAIN_NUMBER_REGEX = /^-?(?:\d+(?:\.\d+)?|\.\d+)$/;
4
+ import { idOf } from "../utils/relaxedValues.js";
9
5
  const DATE_ONLY_REGEX = /^\d{4}-\d{2}-\d{2}$/;
10
- function boundKind(value) {
11
- if (PLAIN_NUMBER_REGEX.test(value)) return "number";
12
- if (isIsoDateTimeString(value)) return "date";
13
- return "other";
14
- }
15
6
  function boundText(value) {
16
7
  if (value == null) return null;
17
8
  const text = value.toString().trim();
@@ -20,33 +11,45 @@ function boundText(value) {
20
11
  function escapeBound(value) {
21
12
  return value.replace(/[\s[\]{}()"\\^~!&|]/g, "\\$&");
22
13
  }
23
- function widenDate(value, edge) {
24
- return DATE_ONLY_REGEX.test(value) ? `${value}${edge === "from" ? "T00:00:00Z" : "T23:59:59.999Z"}` : value;
14
+ function isSingleTerm(text) {
15
+ if (text.startsWith("(") || text.startsWith("-(")) return false;
16
+ let quoted = false;
17
+ let depth = 0;
18
+ for (let i = 0; i < text.length; i++) {
19
+ const char = text[i];
20
+ if (char === "\\") i++;
21
+ else if (char === '"') quoted = !quoted;
22
+ else if (quoted) continue;
23
+ else if (char === "[" || char === "{" || char === "(") depth++;
24
+ else if (char === "]" || char === "}" || char === ")") depth--;
25
+ else if (depth === 0 && /\s/.test(char)) return false;
26
+ }
27
+ return true;
25
28
  }
26
- function farBound(kind, edge) {
27
- if (kind === "number") return NUMBER_BOUNDS[edge];
28
- if (kind === "date") return DATE_BOUNDS[edge];
29
- return "*";
29
+ function isWrappedGroup(text) {
30
+ if (!text.startsWith("(") || !text.endsWith(")")) return false;
31
+ let quoted = false;
32
+ let depth = 0;
33
+ for (let i = 0; i < text.length; i++) {
34
+ const char = text[i];
35
+ if (char === "\\") i++;
36
+ else if (char === '"') quoted = !quoted;
37
+ else if (quoted) continue;
38
+ else if (char === "(") depth++;
39
+ else if (char === ")" && --depth === 0 && i < text.length - 1) return false;
40
+ }
41
+ return depth === 0;
30
42
  }
31
43
  export function useMongocampQuery() {
32
44
  const { q } = useMongocampQueryBuilder();
33
45
  function fieldTerm(fieldName, value) {
34
46
  return q.field(escapeFieldName(fieldName), value);
35
47
  }
36
- function existsClauses(fieldName, type) {
37
- const clauses = [];
38
- if (!type || type === "text") clauses.push(fieldTerm(fieldName, "*"));
39
- if (!type || type === "number") clauses.push(fieldTerm(fieldName, q.range(NUMBER_BOUNDS.from, NUMBER_BOUNDS.to)));
40
- if (!type || type === "date") clauses.push(fieldTerm(fieldName, q.range(DATE_BOUNDS.from, DATE_BOUNDS.to)));
41
- return clauses;
42
- }
43
- function exists(fieldName, type) {
44
- const clauses = existsClauses(fieldName, type);
45
- return clauses.length === 1 ? clauses[0] : `(${clauses.join(" OR ")})`;
48
+ function exists(fieldName, _type) {
49
+ return q.field("_exists_", escapeFieldName(fieldName));
46
50
  }
47
51
  function notExists(fieldName, type) {
48
- const clauses = existsClauses(fieldName, type).map((clause) => `-${clause}`);
49
- return clauses.length === 1 ? clauses[0] : and(...clauses);
52
+ return `-${exists(fieldName, type)}`;
50
53
  }
51
54
  function isEmpty(fieldName, type) {
52
55
  return notExists(fieldName, type);
@@ -66,9 +69,8 @@ export function useMongocampQuery() {
66
69
  const lower = boundText(from);
67
70
  const upper = boundText(to);
68
71
  if (lower === null && upper === null) return exists(fieldName);
69
- const kind = boundKind(lower ?? upper);
70
- const fromStr = lower === null ? farBound(kind, "from") : escapeBound(boundKind(lower) === "date" ? widenDate(lower, "from") : lower);
71
- const toStr = upper === null ? farBound(kind, "to") : escapeBound(boundKind(upper) === "date" ? widenDate(upper, "to") : upper);
72
+ const fromStr = lower === null ? "*" : escapeBound(lower);
73
+ const toStr = upper === null ? "*" : escapeBound(upper);
72
74
  return fieldTerm(fieldName, q.range(fromStr, toStr));
73
75
  }
74
76
  function notInRange(fieldName, from, to) {
@@ -134,10 +136,10 @@ export function useMongocampQuery() {
134
136
  return id;
135
137
  }
136
138
  function byId(id) {
137
- return equals("_id", requireObjectId(id, "byId"));
139
+ return equals("_id", requireObjectId(idOf(id) ?? id, "byId"));
138
140
  }
139
141
  function byIds(ids) {
140
- return inClause("_id", ids.map((id) => requireObjectId(id, "byIds")));
142
+ return inClause("_id", ids.map((id) => requireObjectId(idOf(id) ?? id, "byIds")));
141
143
  }
142
144
  function isTrue(fieldName) {
143
145
  return fieldTerm(fieldName, "true");
@@ -149,8 +151,8 @@ export function useMongocampQuery() {
149
151
  if (value == null || value.toString().length === 0) return "";
150
152
  return inClause(fieldName, [value]);
151
153
  }
152
- function hasItems(fieldName, type) {
153
- return exists(fieldName, type);
154
+ function hasItems(fieldName, _type) {
155
+ return q.field(`${escapeFieldName(fieldName)}.0`, "*");
154
156
  }
155
157
  function requireDay(day, helper) {
156
158
  const parsed = DATE_ONLY_REGEX.test(day) ? /* @__PURE__ */ new Date(`${day}T00:00:00Z`) : null;
@@ -165,21 +167,12 @@ export function useMongocampQuery() {
165
167
  function notOnDay(fieldName, day) {
166
168
  return `-${onDay(fieldName, requireDay(day, "notOnDay"))}`;
167
169
  }
168
- function render(node) {
169
- if (node.kind === "clause") return node.text;
170
- if (node.kind === "not") return negate(node.node);
171
- const parts = node.parts.map(render);
172
- return node.kind === "and" ? and(...parts) : or(...parts);
173
- }
174
- function negate(node) {
175
- if (node.kind === "clause") return node.text.startsWith("-") ? node.text.slice(1) : `-${node.text}`;
176
- if (node.kind === "not") return render(node.node);
177
- const negated = node.parts.map(negate);
178
- return node.kind === "and" ? or(...negated) : and(...negated);
179
- }
180
170
  function not(queryPart) {
181
- const node = parseLuceneExpression(queryPart ?? "");
182
- return node === null ? "" : negate(node);
171
+ const text = (queryPart ?? "").trim();
172
+ if (text === "" || text === "()") return "";
173
+ if (isSingleTerm(text)) return text.startsWith("-") ? text.slice(1) : `-${text}`;
174
+ if (text.startsWith("-") && isWrappedGroup(text.slice(1))) return text.slice(1);
175
+ return isWrappedGroup(text) ? `-${text}` : `-(${text})`;
183
176
  }
184
177
  function notAnd(...queryParts) {
185
178
  return not(and(...queryParts));
@@ -1,3 +1,4 @@
1
+ import { isTextValue, leafWrapperText } from "../utils/relaxedValues.js";
1
2
  const DATE_TIME_STRING_REGEX = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
2
3
  function isDateTimeString(value) {
3
4
  return DATE_TIME_STRING_REGEX.test(value);
@@ -12,6 +13,7 @@ function detectValueType(value) {
12
13
  if (typeof value === "string") return isDateTimeString(value) ? "date-time" : "string";
13
14
  if (Array.isArray(value)) return "array";
14
15
  if (isPlainObject(value)) {
16
+ if (isTextValue(value) || leafWrapperText(value) !== void 0) return "string";
15
17
  if ("$date" in value) return "date-time";
16
18
  if ("$oid" in value) return "string";
17
19
  if ("$numberInt" in value || "$numberLong" in value || "$numberDouble" in value || "$numberDecimal" in value) return "number";
@@ -10,18 +10,13 @@ export interface ServerInfo {
10
10
  /** The same version as numbers (`[9, 0, 4, 0]`), empty if the server sent none. */
11
11
  mongoDbVersionArray: number[];
12
12
  }
13
- export interface ServerPlugins {
14
- routesPlugins: string[];
15
- filePlugins: string[];
16
- ignoredPlugins: string[];
17
- }
18
13
  /**
19
14
  * Read-only wrapper for databaseApi, applicationApi and the cluster view of systemApi. Deliberately read-only —
20
15
  * deleteDatabase, shutdown and updateConfiguration are out of scope (cross-cutting, highly
21
16
  * destructive) and not exposed. The server's settings and configuration payloads contain real secrets
22
- * (auth secret, database credentials and host), so the settings methods never hand them out:
23
- * `getSettings` returns the plugin lists only, and the configuration methods return rows that are
24
- * already masked (see utils/configRows.ts).
17
+ * (auth secret, database credentials and host), so the settings methods never hand them out: the
18
+ * configuration methods return rows that are already masked (see utils/configRows.ts). `GET /system/settings`
19
+ * is not used at all — since server 2.2 it holds nothing but that configuration map, secrets included.
25
20
  */
26
21
  export declare function useMongocampSystem(): {
27
22
  getCluster: () => Promise<ServerCluster>;
@@ -32,7 +27,6 @@ export declare function useMongocampSystem(): {
32
27
  getDatabaseInfos: () => Promise<DatabaseInfo[]>;
33
28
  getDatabaseInfo: (databaseName: string) => Promise<DatabaseInfo>;
34
29
  listCollectionsByDatabase: (databaseName: string) => Promise<string[]>;
35
- getSettings: () => Promise<ServerPlugins>;
36
30
  listConfigurations: () => Promise<ConfigRow[]>;
37
31
  getConfig: (configurationKey: string) => Promise<ConfigRow>;
38
32
  };
@@ -18,14 +18,6 @@ export function useMongocampSystem() {
18
18
  async function listCollectionsByDatabase(databaseName) {
19
19
  return databaseApi.listCollectionsByDatabase({ databaseName }, withTimeout());
20
20
  }
21
- async function getSettings() {
22
- const settings = await applicationApi.settings(withTimeout());
23
- return {
24
- routesPlugins: settings.routesPlugins ?? [],
25
- filePlugins: settings.filePlugins ?? [],
26
- ignoredPlugins: settings.ignoredPlugins ?? []
27
- };
28
- }
29
21
  async function listConfigurations() {
30
22
  return buildConfigRows(await applicationApi.listConfigurations(withTimeout()));
31
23
  }
@@ -48,5 +40,5 @@ export function useMongocampSystem() {
48
40
  async function getCapabilities() {
49
41
  return systemApi.systemCapabilities(withTimeout());
50
42
  }
51
- return { getCluster, getServerInfo, getStats, getCapabilities, listDatabases, getDatabaseInfos, getDatabaseInfo, listCollectionsByDatabase, getSettings, listConfigurations, getConfig };
43
+ return { getCluster, getServerInfo, getStats, getCapabilities, listDatabases, getDatabaseInfos, getDatabaseInfo, listCollectionsByDatabase, listConfigurations, getConfig };
52
44
  }