@sfxcode/nuxt-ui-mongocamp 1.5.7 → 2.0.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 (130) hide show
  1. package/README.md +5 -5
  2. package/dist/module.d.mts +17 -0
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +4 -0
  5. package/dist/runtime/components/MongocampAccount.vue +12 -14
  6. package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +1 -0
  7. package/dist/runtime/components/MongocampAggregationBuilder.vue +32 -45
  8. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +1 -0
  9. package/dist/runtime/components/MongocampAggregationChart.vue +7 -5
  10. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +1 -0
  11. package/dist/runtime/components/MongocampAggregationStagePreview.vue +5 -3
  12. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +1 -0
  13. package/dist/runtime/components/MongocampBucketFiles.vue +29 -40
  14. package/dist/runtime/components/MongocampBulkDelete.vue +8 -9
  15. package/dist/runtime/components/MongocampBulkEdit.vue +5 -4
  16. package/dist/runtime/components/MongocampChart.vue +1 -1
  17. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +1 -0
  18. package/dist/runtime/components/MongocampCollectionCharts.vue +10 -7
  19. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +1 -0
  20. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +1 -0
  21. package/dist/runtime/components/MongocampCollectionCopy.vue +11 -9
  22. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +1 -0
  23. package/dist/runtime/components/MongocampCollectionData.vue +97 -87
  24. package/dist/runtime/components/MongocampCollectionInfos.vue +34 -24
  25. package/dist/runtime/components/MongocampCollectionRename.vue +5 -4
  26. package/dist/runtime/components/MongocampCollections.vue +24 -33
  27. package/dist/runtime/components/MongocampCommandPalette.vue +3 -1
  28. package/dist/runtime/components/MongocampConfirmByName.vue +5 -4
  29. package/dist/runtime/components/MongocampDashboard.vue +5 -3
  30. package/dist/runtime/components/MongocampDatabases.vue +14 -8
  31. package/dist/runtime/components/MongocampDocumentCompare.vue +6 -4
  32. package/dist/runtime/components/MongocampDocumentView.vue +12 -9
  33. package/dist/runtime/components/MongocampEmptyState.vue +4 -1
  34. package/dist/runtime/components/MongocampErrorAlert.vue +8 -7
  35. package/dist/runtime/components/MongocampExportAll.d.vue.ts +1 -0
  36. package/dist/runtime/components/MongocampExportAll.vue +19 -7
  37. package/dist/runtime/components/MongocampExportAll.vue.d.ts +1 -0
  38. package/dist/runtime/components/MongocampFilePreview.vue +7 -6
  39. package/dist/runtime/components/MongocampFilterBuilder.vue +12 -16
  40. package/dist/runtime/components/MongocampGrantList.vue +6 -2
  41. package/dist/runtime/components/MongocampImport.vue +32 -28
  42. package/dist/runtime/components/MongocampIndexes.vue +21 -19
  43. package/dist/runtime/components/MongocampJobs.vue +20 -20
  44. package/dist/runtime/components/MongocampLogin.vue +2 -1
  45. package/dist/runtime/components/MongocampPermissionMatrix.vue +14 -11
  46. package/dist/runtime/components/MongocampQueryBar.vue +33 -32
  47. package/dist/runtime/components/MongocampRoleGrants.vue +21 -17
  48. package/dist/runtime/components/MongocampRoles.vue +28 -32
  49. package/dist/runtime/components/MongocampServerInfo.vue +17 -25
  50. package/dist/runtime/components/MongocampServerOverview.vue +16 -12
  51. package/dist/runtime/components/MongocampServerStatus.vue +9 -3
  52. package/dist/runtime/components/MongocampSettings.vue +15 -11
  53. package/dist/runtime/components/MongocampUserAccess.vue +11 -6
  54. package/dist/runtime/components/MongocampUsers.vue +32 -35
  55. package/dist/runtime/components/MongocampVersion.d.vue.ts +1 -1
  56. package/dist/runtime/components/MongocampVersion.vue +20 -11
  57. package/dist/runtime/components/MongocampVersion.vue.d.ts +1 -1
  58. package/dist/runtime/composables/useMongocampAdmin.js +6 -5
  59. package/dist/runtime/composables/useMongocampAggregation.d.ts +10 -1
  60. package/dist/runtime/composables/useMongocampAggregation.js +17 -5
  61. package/dist/runtime/composables/useMongocampBucket.d.ts +4 -0
  62. package/dist/runtime/composables/useMongocampBucket.js +7 -6
  63. package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +6 -4
  64. package/dist/runtime/composables/useMongocampBulkByFilter.js +11 -6
  65. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +3 -1
  66. package/dist/runtime/composables/useMongocampCollectionCopy.js +4 -2
  67. package/dist/runtime/composables/useMongocampCollectionStats.js +2 -4
  68. package/dist/runtime/composables/useMongocampError.d.ts +1 -1
  69. package/dist/runtime/composables/useMongocampError.js +4 -1
  70. package/dist/runtime/composables/useMongocampExportAll.d.ts +10 -1
  71. package/dist/runtime/composables/useMongocampExportAll.js +4 -1
  72. package/dist/runtime/composables/useMongocampFetchAll.d.ts +11 -5
  73. package/dist/runtime/composables/useMongocampFetchAll.js +8 -8
  74. package/dist/runtime/composables/useMongocampJobs.js +3 -2
  75. package/dist/runtime/composables/useMongocampQuery.d.ts +26 -36
  76. package/dist/runtime/composables/useMongocampQuery.js +45 -48
  77. package/dist/runtime/composables/useMongocampSchema.js +2 -0
  78. package/dist/runtime/composables/useMongocampUi.d.ts +8 -0
  79. package/dist/runtime/composables/useMongocampUi.js +7 -0
  80. package/dist/runtime/locales/de.json +12 -4
  81. package/dist/runtime/locales/en.json +12 -4
  82. package/dist/runtime/plugin.js +8 -0
  83. package/dist/runtime/publicUtils.d.ts +1 -0
  84. package/dist/runtime/publicUtils.js +1 -0
  85. package/dist/runtime/server/handlers/mongocampProxy.d.ts +1 -1
  86. package/dist/runtime/server/handlers/mongocampProxy.js +12 -12
  87. package/dist/runtime/utils/aggregationPipeline.d.ts +2 -1
  88. package/dist/runtime/utils/aggregationPipeline.js +2 -3
  89. package/dist/runtime/utils/caseInsensitive.d.ts +10 -0
  90. package/dist/runtime/utils/caseInsensitive.js +8 -0
  91. package/dist/runtime/utils/collectionStats.d.ts +4 -1
  92. package/dist/runtime/utils/collectionStats.js +2 -2
  93. package/dist/runtime/utils/compactSession.d.ts +13 -0
  94. package/dist/runtime/utils/compactSession.js +12 -0
  95. package/dist/runtime/utils/configRows.d.ts +3 -3
  96. package/dist/runtime/utils/cursorPaging.d.ts +16 -0
  97. package/dist/runtime/utils/cursorPaging.js +17 -0
  98. package/dist/runtime/utils/documentCompare.js +2 -3
  99. package/dist/runtime/utils/documentPaths.d.ts +5 -5
  100. package/dist/runtime/utils/documentPaths.js +9 -2
  101. package/dist/runtime/utils/documentTree.js +3 -0
  102. package/dist/runtime/utils/fileFilter.d.ts +7 -0
  103. package/dist/runtime/utils/fileFilter.js +11 -0
  104. package/dist/runtime/utils/filterBuilder.d.ts +1 -1
  105. package/dist/runtime/utils/filterBuilder.js +5 -11
  106. package/dist/runtime/utils/filterSuggestions.js +1 -1
  107. package/dist/runtime/utils/indexForm.d.ts +7 -0
  108. package/dist/runtime/utils/indexForm.js +9 -0
  109. package/dist/runtime/utils/pagedFetch.d.ts +13 -0
  110. package/dist/runtime/utils/pagedFetch.js +44 -0
  111. package/dist/runtime/utils/queryState.d.ts +5 -0
  112. package/dist/runtime/utils/queryState.js +3 -2
  113. package/dist/runtime/utils/relaxedValues.d.ts +17 -0
  114. package/dist/runtime/utils/relaxedValues.js +51 -0
  115. package/dist/runtime/utils/requestLimits.d.ts +1 -1
  116. package/dist/runtime/utils/requestLimits.js +1 -1
  117. package/dist/runtime/utils/savedQueries.d.ts +2 -0
  118. package/dist/runtime/utils/savedQueries.js +1 -0
  119. package/dist/runtime/utils/schemaAnalysis.d.ts +4 -4
  120. package/dist/runtime/utils/schemaAnalysis.js +2 -2
  121. package/dist/runtime/utils/sensitiveFields.d.ts +20 -0
  122. package/dist/runtime/utils/sensitiveFields.js +63 -0
  123. package/dist/runtime/utils/serverError.d.ts +7 -0
  124. package/dist/runtime/utils/serverError.js +11 -0
  125. package/dist/runtime/utils/serverStatus.d.ts +2 -2
  126. package/dist/runtime/utils/uiTheme.d.ts +65 -0
  127. package/dist/runtime/utils/uiTheme.js +47 -0
  128. package/package.json +22 -16
  129. package/dist/runtime/utils/luceneExpression.d.ts +0 -15
  130. package/dist/runtime/utils/luceneExpression.js +0 -74
@@ -3,3 +3,4 @@ export { connectionUsage, formatCount, formatUptime } from "./utils/serverInfo.j
3
3
  export { groupCollectionNames } from "./utils/collectionNames.js";
4
4
  export { bucketNameOf, isBucketMemberCollection, isProtectedCollection } from "./utils/collectionProtection.js";
5
5
  export { isNetworkFailure } from "./utils/connection.js";
6
+ export { idOf } from "./utils/relaxedValues.js";
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
1
+ declare const _default: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<import("h3").HTTPResponse>>;
2
2
  export default _default;
@@ -1,14 +1,16 @@
1
- import { createError, defineEventHandler, getRequestURL, proxyRequest } from "h3";
2
- import { useNitroApp, useRuntimeConfig } from "nitropack/runtime";
1
+ import { createError, defineHandler, getRequestURL, proxyRequest } from "h3";
2
+ import { useNitroApp } from "nitro/app";
3
+ import { useRuntimeConfig } from "nitro/runtime-config";
3
4
  import { consola } from "consola";
4
5
  let warnedMissingAuthorizeHook = false;
5
6
  function hasAuthorizeHookRegistered(hooks) {
7
+ if (!hooks) return false;
6
8
  const bag = hooks._hooks;
7
9
  if (!bag) return true;
8
10
  return (bag["mongocamp-proxy:authorize"]?.length ?? 0) > 0;
9
11
  }
10
- export default defineEventHandler(async (event) => {
11
- const config = useRuntimeConfig(event);
12
+ export default defineHandler(async (event) => {
13
+ const config = useRuntimeConfig();
12
14
  const options = config.public.nuxtUiMongocampOptions;
13
15
  if (!options?.useServerProxy) {
14
16
  throw createError({ statusCode: 404, statusMessage: "Not Found" });
@@ -20,7 +22,7 @@ export default defineEventHandler(async (event) => {
20
22
  "[nuxt-ui-mongocamp] `useServerProxy` is enabled but no `mongocamp-proxy:authorize` hook is registered. The proxy route is unguarded: any caller who can reach it gets the full power of the configured MongoCamp api key. Register a guard from your own `server/plugins/*.ts` \u2014 see docs/guide/server-proxy-auth.md."
21
23
  );
22
24
  }
23
- await nitroHooks.callHook("mongocamp-proxy:authorize", event);
25
+ await nitroHooks?.callHook("mongocamp-proxy:authorize", event);
24
26
  const serverProxyPath = (options.serverProxyPath ?? "/api/_mongocamp").replace(/\/+$/, "");
25
27
  const mongocampUrl = config.public.mongocamp?.url;
26
28
  const apiKey = config.mongocampApiKey ?? "";
@@ -34,12 +36,10 @@ export default defineEventHandler(async (event) => {
34
36
  const subPath = requestUrl.pathname.slice(serverProxyPath.length);
35
37
  const target = `${mongocampUrl}${subPath}${requestUrl.search}`;
36
38
  return proxyRequest(event, target, {
37
- headers: {
38
- "X-AUTH-APIKEY": apiKey,
39
- // Neutralize any Authorization header the caller sent — auth against MongoCamp in
40
- // proxy mode must only ever come from the server-side api key above, never from
41
- // whatever a caller (legitimate or not) put on their own request.
42
- "Authorization": ""
43
- }
39
+ // Drop any Authorization header (and the app's cookies) the caller sent — auth against
40
+ // MongoCamp in proxy mode must only ever come from the server-side api key below, never
41
+ // from whatever a caller (legitimate or not) put on their own request.
42
+ filterHeaders: ["authorization", "cookie"],
43
+ headers: { "X-AUTH-APIKEY": apiKey }
44
44
  });
45
45
  });
@@ -1,4 +1,4 @@
1
- export declare const FORBIDDEN_OPERATORS: readonly ["$out", "$merge", "$function", "$accumulator", "$where", "$lookup", "$unionWith", "$graphLookup", "$collStats", "$indexStats"];
1
+ export declare const FORBIDDEN_OPERATORS: readonly ["$out", "$merge", "$function", "$accumulator", "$where", "$currentOp", "$listSessions", "$collStats", "$indexStats"];
2
2
  export declare const STATS_OPERATORS: readonly ["$collStats", "$indexStats"];
3
3
  export declare const VISUAL_STAGE_TYPES: readonly ["$match", "$group", "$sort", "$project", "$limit", "$unwind", "$addFields", "$count", "$bucketAuto"];
4
4
  export type AggregationStageType = typeof VISUAL_STAGE_TYPES[number];
@@ -15,6 +15,7 @@ export interface ForbiddenUse {
15
15
  stageIndex: number;
16
16
  operator: string;
17
17
  path: string;
18
+ sensitive?: boolean;
18
19
  }
19
20
  export type PipelineErrorCode = 'too-large' | 'invalid-json' | 'not-array' | 'too-many-stages' | 'stage-shape' | 'forbidden-operator' | 'too-deep';
20
21
  export interface PipelineError {
@@ -4,9 +4,8 @@ export const FORBIDDEN_OPERATORS = [
4
4
  "$function",
5
5
  "$accumulator",
6
6
  "$where",
7
- "$lookup",
8
- "$unionWith",
9
- "$graphLookup",
7
+ "$currentOp",
8
+ "$listSessions",
10
9
  "$collStats",
11
10
  "$indexStats"
12
11
  ];
@@ -0,0 +1,10 @@
1
+ /** `true` when the server should match the wildcards of `filter` without regard to case; `undefined` = send nothing. */
2
+ export declare function caseInsensitiveFlag(filter: string | undefined, matchCase?: boolean): true | undefined;
3
+ /** The options a filtered request takes besides the filter itself. */
4
+ export interface FilterCallOptions {
5
+ signal?: AbortSignal;
6
+ /** Match the filter's wildcards without regard to case (see `caseInsensitiveFlag`). */
7
+ filterCaseInsensitive?: boolean;
8
+ }
9
+ /** Accepts the old positional `AbortSignal` as well as the options object. */
10
+ export declare function filterCallOptions(value: AbortSignal | FilterCallOptions | undefined): FilterCallOptions;
@@ -0,0 +1,8 @@
1
+ const UNESCAPED_WILDCARD = /(?:^|[^\\])[*?]/;
2
+ export function caseInsensitiveFlag(filter, matchCase = false) {
3
+ return !matchCase && filter !== void 0 && UNESCAPED_WILDCARD.test(filter) ? true : void 0;
4
+ }
5
+ export function filterCallOptions(value) {
6
+ if (value === void 0) return {};
7
+ return typeof AbortSignal !== "undefined" && value instanceof AbortSignal ? { signal: value } : value;
8
+ }
@@ -27,5 +27,8 @@ export interface IndexUsage {
27
27
  /** A non-negative finite number, else 0 (a missing or malformed number is not worth failing a card for). */
28
28
  export declare function toCount(value: unknown): number;
29
29
  export declare function mapStorage(status: Partial<CollectionStatus>): CollectionStorage;
30
- /** Rows of a `$indexStats` aggregation (already unwrapped, `host`/`ns` stripped) as typed usage; rows without a name are skipped. */
30
+ /**
31
+ * Index usage as typed rows: from `GET …/index/stats` (`{ name, key, ops, since }`, server 2.0) or from raw `$indexStats`
32
+ * rows (`accesses.ops` / `accesses.since`); rows without a name are skipped.
33
+ */
31
34
  export declare function mapIndexUsage(rows: Array<Record<string, unknown>>): IndexUsage[];
@@ -29,12 +29,12 @@ export function mapIndexUsage(rows) {
29
29
  for (const row of rows) {
30
30
  if (typeof row.name !== "string" || row.name === "") continue;
31
31
  const accesses = isRecord(row.accesses) ? row.accesses : {};
32
- const ops = toCount(accesses.ops);
32
+ const ops = toCount(row.ops ?? accesses.ops);
33
33
  out.push({
34
34
  name: row.name,
35
35
  key: isRecord(row.key) ? row.key : {},
36
36
  ops,
37
- since: isoOrNull(accesses.since),
37
+ since: isoOrNull(row.since ?? accesses.since),
38
38
  unused: ops === 0
39
39
  });
40
40
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Module option `compactSession`: what of the user profile goes into the session cookie. `@sfxcode/nuxt-mongocamp-server`
3
+ * stores the whole `userProfile` of a login or token refresh — grants and the API key included — so a user with many
4
+ * grants pushes the cookie past the browser's ~4 KB limit and the login silently fails. The module itself never reads
5
+ * grants from the session (`useMongocampPermissions` asks the server), so the cookie only needs who the user is.
6
+ */
7
+ export interface CompactProfile {
8
+ user: string;
9
+ isAdmin: boolean;
10
+ roles?: string[];
11
+ }
12
+ /** The compact profile, or `undefined` when the stored one is already compact (or missing) and nothing needs writing. */
13
+ export declare function compactProfile(profile: unknown): CompactProfile | undefined;
@@ -0,0 +1,12 @@
1
+ const KEPT = /* @__PURE__ */ new Set(["user", "isAdmin", "roles"]);
2
+ export function compactProfile(profile) {
3
+ if (!profile || typeof profile !== "object") return void 0;
4
+ const p = profile;
5
+ if (Object.keys(p).every((key) => KEPT.has(key))) return void 0;
6
+ const roles = Array.isArray(p.roles) ? p.roles.filter((r) => typeof r === "string") : void 0;
7
+ return {
8
+ user: typeof p.user === "string" ? p.user : "",
9
+ isAdmin: p.isAdmin === true,
10
+ ...roles ? { roles } : {}
11
+ };
12
+ }
@@ -11,8 +11,8 @@ export declare function isSecretConfigKey(key: string): boolean;
11
11
  export declare function buildConfigRows(configurations: unknown): ConfigRow[];
12
12
  export declare const GRANT_STATUS_KEY = "AUTH_GRANT_DENIED_STATUS";
13
13
  /**
14
- * Whether the server still answers a missing grant with `401` (its default; `403` is planned for the next major version): a
15
- * generated client clears the session on a 401, which this module works around by turning that 401 into a 403 itself. `false`
16
- * when the setting is `403`, absent (an older server) or unreadable.
14
+ * Whether the server answers a missing grant with `401` (the default of server 2.0, `AUTH_GRANT_DENIED_STATUS`): a generated
15
+ * client clears the session on a 401, which this module works around by turning that 401 into a 403 itself. `false` when the
16
+ * setting is `403`, absent or unreadable.
17
17
  */
18
18
  export declare function grantStatusHint(rows: readonly ConfigRow[]): boolean;
@@ -0,0 +1,16 @@
1
+ /** The sort the server uses for a cursor, also for page numbers: the given keys, then `_id` unless it is already there. */
2
+ export declare function stableSort(sort: readonly string[] | undefined): string[];
3
+ /** The cursors of the pages reached by stepping forward, for one list (`key`: filter, sort, fields, page size, …). */
4
+ export interface CursorMemory {
5
+ key: string;
6
+ /** page number → the `after` that loads it; page 1 is always `''`. */
7
+ cursors: Record<number, string>;
8
+ }
9
+ export declare function emptyCursorMemory(): CursorMemory;
10
+ /** The `after` that loads `page` of the list `key`, or `undefined` when only its page number can load it. */
11
+ export declare function cursorFor(memory: CursorMemory, key: string, page: number): string | undefined;
12
+ /**
13
+ * The memory after `page` of the list `key` was loaded and answered with `next` (absent on the last page). Another list
14
+ * starts afresh; a missing `next` forgets what lay beyond.
15
+ */
16
+ export declare function rememberNext(memory: CursorMemory, key: string, page: number, next: string | undefined): CursorMemory;
@@ -0,0 +1,17 @@
1
+ export function stableSort(sort) {
2
+ const keys = [...sort ?? []];
3
+ return keys.some((key) => key === "_id" || key === "-_id") ? keys : [...keys, "_id"];
4
+ }
5
+ export function emptyCursorMemory() {
6
+ return { key: "", cursors: {} };
7
+ }
8
+ export function cursorFor(memory, key, page) {
9
+ if (page === 1) return "";
10
+ return memory.key === key ? memory.cursors[page] : void 0;
11
+ }
12
+ export function rememberNext(memory, key, page, next) {
13
+ const kept = memory.key === key ? Object.entries(memory.cursors).filter(([p]) => Number(p) !== page + 1) : [];
14
+ const cursors = Object.fromEntries(kept);
15
+ if (next) cursors[page + 1] = next;
16
+ return { key, cursors };
17
+ }
@@ -6,13 +6,12 @@ export function plainValue(value) {
6
6
  if (typeof value === "bigint") return value.toString();
7
7
  return unwrapExtendedJson(value);
8
8
  }
9
- const WRAPPED_AS_TEXT = /* @__PURE__ */ new Set(["objectId", "date", "long", "decimal"]);
10
9
  const NUMERIC = /* @__PURE__ */ new Set(["number", "int", "long", "double", "decimal"]);
11
10
  const EXACT_NUMERIC = /* @__PURE__ */ new Set(["int", "long", "double", "decimal"]);
12
11
  function typesAgree(a, b) {
13
12
  if (a === b) return true;
14
13
  if (NUMERIC.has(a) && NUMERIC.has(b)) return !(EXACT_NUMERIC.has(a) && EXACT_NUMERIC.has(b));
15
- return a === "string" && WRAPPED_AS_TEXT.has(b) || b === "string" && WRAPPED_AS_TEXT.has(a);
14
+ return false;
16
15
  }
17
16
  function leafEqual(a, b) {
18
17
  if (a === b) return true;
@@ -44,7 +43,7 @@ export function compareDocuments(left, right, options = {}) {
44
43
  }
45
44
  const r = plainValue(other.value);
46
45
  const equal = leafEqual(l, r);
47
- const typeDiffers = !typesAgree(entry.type, other.type) && String(l) === String(r);
46
+ const typeDiffers = !typesAgree(entry.type, other.type) && (equal || String(l) === String(r));
48
47
  rows.push({
49
48
  path: entry.path,
50
49
  status: equal && !typeDiffers ? "same" : "changed",
@@ -1,4 +1,4 @@
1
- export type PathValueType = 'null' | 'string' | 'boolean' | 'number' | 'int' | 'long' | 'double' | 'decimal' | 'objectId' | 'date' | 'array' | 'object';
1
+ export type PathValueType = 'null' | 'string' | 'boolean' | 'number' | 'int' | 'long' | 'double' | 'decimal' | 'objectId' | 'date' | 'array' | 'object' | 'binary' | 'regex' | 'timestamp' | 'minKey' | 'maxKey';
2
2
  export interface FlatEntry {
3
3
  path: string;
4
4
  type: PathValueType;
@@ -16,10 +16,10 @@ export interface FlattenResult {
16
16
  truncated: boolean;
17
17
  }
18
18
  /**
19
- * What a value is, with extended-JSON wrappers recognised as their BSON type. Read a document with `extendedJson=canonical`
20
- * (server 1.8.1) to get the types: `_id` and nested ids are `{ $oid }`, dates `{ $date }`, numbers `{ $numberInt }` /
21
- * `{ $numberLong }` / `{ $numberDouble }` / `{ $numberDecimal }`, date-looking text `{ $string }`. A document read as plain
22
- * JSON has no wrappers (ids and dates are strings) and is typed as what JSON says — the module no longer guesses.
19
+ * What a value is, with extended-JSON wrappers recognised as their BSON type. The server's default (relaxed) read wraps ids
20
+ * `{ $oid }`, dates `{ $date }`, integers beyond 2^53 `{ $numberLong }`, decimals `{ $numberDecimal }`, date-looking text
21
+ * `{ $string }`, binary/regex/timestamp/min-max keys; other numbers are plain (`number`). A canonical read
22
+ * (`extendedJson=canonical`) also wraps every number, so int, long and double can be told apart.
23
23
  */
24
24
  export declare function typeOf(value: unknown): PathValueType;
25
25
  /** Splits a path at its unescaped dots; `''` is the empty path (no segments). */
@@ -11,8 +11,15 @@ const WRAPPER_TYPES = {
11
11
  $numberInt: "int",
12
12
  $numberDouble: "double",
13
13
  $numberDecimal: "decimal",
14
- // text that looks like a date, marked as text by the server in a typed read
15
- $string: "string"
14
+ // text that looks like a date, marked as text by the server
15
+ $string: "string",
16
+ // wrappers without a plain JavaScript value: one leaf each
17
+ $binary: "binary",
18
+ $uuid: "binary",
19
+ $regularExpression: "regex",
20
+ $timestamp: "timestamp",
21
+ $minKey: "minKey",
22
+ $maxKey: "maxKey"
16
23
  };
17
24
  function wrapperType(value) {
18
25
  const keys = Object.keys(value);
@@ -1,4 +1,5 @@
1
1
  import { joinPath, typeOf } from "./documentPaths.js";
2
+ import { leafWrapperText } from "./relaxedValues.js";
2
3
  export const DEFAULT_MAX_NODES = 5e3;
3
4
  export const MAX_TREE_DEPTH = 32;
4
5
  export const COLLAPSE_ABOVE_NODES = 200;
@@ -95,6 +96,8 @@ export function nodeDisplay(node) {
95
96
  return parsed && !Number.isNaN(parsed.getTime()) ? { text, title: parsed.toLocaleString() } : { text };
96
97
  }
97
98
  if (typeof value === "object" && value !== null) {
99
+ const leaf = leafWrapperText(value);
100
+ if (leaf !== void 0) return { text: leaf };
98
101
  const inner = Object.values(value)[0];
99
102
  return { text: typeof inner === "string" ? inner : JSON.stringify(inner) };
100
103
  }
@@ -0,0 +1,7 @@
1
+ /** The text as a regular expression that matches it literally. */
2
+ export declare function escapeRegex(text: string): string;
3
+ /**
4
+ * The `filter` for files whose name contains `term` (case-insensitive unless `matchCase`), as the JSON text the list
5
+ * route takes: `{"filename":{"$regex":"…","$options":"i"}}`. `undefined` for a blank term = no filter.
6
+ */
7
+ export declare function filenameFilter(term: string, matchCase?: boolean): string | undefined;
@@ -0,0 +1,11 @@
1
+ const REGEX_SPECIAL = /[.*+?^${}()|[\]\\]/g;
2
+ export function escapeRegex(text) {
3
+ return text.replace(REGEX_SPECIAL, "\\$&");
4
+ }
5
+ export function filenameFilter(term, matchCase = false) {
6
+ const trimmed = term.trim();
7
+ if (trimmed === "") return void 0;
8
+ const condition = { $regex: escapeRegex(trimmed) };
9
+ if (!matchCase) condition.$options = "i";
10
+ return JSON.stringify({ filename: condition });
11
+ }
@@ -12,7 +12,7 @@ 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`. */
15
+ /** Exclude what the combined conditions match (NOT): `-( … )`, see `useMongocampQuery().not`. */
16
16
  negate?: boolean;
17
17
  }
18
18
  export declare const FILTER_OPERATORS_BY_TYPE: Record<FilterFieldType, FilterOperator[]>;
@@ -6,10 +6,10 @@ export const FILTER_OPERATORS_BY_TYPE = {
6
6
  "string": ["contains", "equals", "notEquals", "startsWith", "endsWith", "oneOf", "isEmpty", "isNotEmpty"],
7
7
  "number": ["equals", "notEquals", "gte", "lte", "between", "oneOf", "isEmpty", "isNotEmpty"],
8
8
  "date-time": ["gte", "lte", "between", "isEmpty", "isNotEmpty"],
9
- "boolean": ["isTrue", "isFalse"],
9
+ "boolean": ["isTrue", "isFalse", "isEmpty", "isNotEmpty"],
10
10
  "objectId": ["equals", "notEquals", "oneOf"],
11
- "array": [],
12
- "object": []
11
+ "array": ["isEmpty", "isNotEmpty"],
12
+ "object": ["isEmpty", "isNotEmpty"]
13
13
  };
14
14
  export function operatorsFor(type) {
15
15
  return Object.hasOwn(FILTER_OPERATORS_BY_TYPE, type) ? FILTER_OPERATORS_BY_TYPE[type] : FILTER_OPERATORS_BY_TYPE.string;
@@ -45,12 +45,6 @@ function parseRangeBound(type, raw) {
45
45
  if (type === "date-time") return isIsoDateTimeString(raw) ? raw : null;
46
46
  return null;
47
47
  }
48
- function existsType(type) {
49
- if (type === "string") return "text";
50
- if (type === "number") return "number";
51
- if (type === "date-time") return "date";
52
- return void 0;
53
- }
54
48
  function splitList(raw) {
55
49
  return raw.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
56
50
  }
@@ -69,9 +63,9 @@ export function buildCondition(condition, type) {
69
63
  }
70
64
  switch (condition.operator) {
71
65
  case "isEmpty":
72
- return h.notExists(field, existsType(type));
66
+ return h.notExists(field);
73
67
  case "isNotEmpty":
74
- return h.exists(field, existsType(type));
68
+ return h.exists(field);
75
69
  case "isTrue":
76
70
  return h.isTrue(field);
77
71
  case "isFalse":
@@ -1,5 +1,5 @@
1
1
  const SUGGESTION_OPERATORS = ["equals", "notEquals", "oneOf"];
2
- const UNFILTERABLE = /[:*?()\\]/;
2
+ const UNFILTERABLE = /\*/;
3
3
  export function isSuggestable(value, operator) {
4
4
  if (value.trim() === "" || UNFILTERABLE.test(value)) return false;
5
5
  return operator !== "oneOf" || !value.includes(",");
@@ -77,6 +77,13 @@ export type IndexRequest = {
77
77
  export declare function buildIndexRequest(form: IndexForm): IndexRequest;
78
78
  export type IndexErrorKind = 'duplicate-values' | 'conflict' | 'empty-keys' | 'other';
79
79
  /** What a create/drop failure means, from the server's message (MongoDB error codes 11000, 85/86 and 67). */
80
+ /**
81
+ * The partial filter of an index as compact JSON for a tooltip (`{"n":{"$gt":0}}`); `undefined` when there is none or when it
82
+ * is not a readable object (the `{ "underlying": null }` form of older servers).
83
+ */
84
+ export declare function partialFilterText(value: unknown): string | undefined;
85
+ /** The locale of an index collation (`de`), or `undefined`. */
86
+ export declare function collationLocale(value: unknown): string | undefined;
80
87
  export declare function classifyIndexError(message: string): IndexErrorKind;
81
88
  /** Never used since the counter started — a hint, not proof (counters restart with the server). `_id_` is never flagged. */
82
89
  export declare function isUnusedIndex(name: string, ops: number | undefined): boolean;
@@ -60,6 +60,15 @@ export function buildIndexRequest(form) {
60
60
  if (partial) options.partialFilterExpression = partial;
61
61
  return Object.keys(options).length > 0 ? { call: "createOrderedIndex", keys, options } : { call: "createOrderedIndex", keys };
62
62
  }
63
+ export function partialFilterText(value) {
64
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
65
+ const text = JSON.stringify(value);
66
+ return text === "{}" || text.includes('"underlying"') ? void 0 : text;
67
+ }
68
+ export function collationLocale(value) {
69
+ const locale = value?.locale;
70
+ return typeof locale === "string" && locale !== "" ? locale : void 0;
71
+ }
63
72
  export function classifyIndexError(message) {
64
73
  if (/11000|duplicate key|E11000/i.test(message)) return "duplicate-values";
65
74
  if (/equivalent index already exists|IndexOptionsConflict|IndexKeySpecsConflict|already exists with a different name/i.test(message)) return "conflict";
@@ -44,3 +44,16 @@ export interface FetchAllResult<T> {
44
44
  * Sequential by design: the pages are cheap to compute and the page size is what makes it fast.
45
45
  */
46
46
  export declare function fetchAllPages<T>(fetchPage: (page: number, pageSize: number) => Promise<PageResult<T>>, options?: FetchAllOptions<T>): Promise<FetchAllResult<T>>;
47
+ export interface CursorPageResult<T> {
48
+ rows: T[];
49
+ /** The cursor of the next page (`x-pagination-next`); absent on the last page. */
50
+ next?: string;
51
+ /** The total, when the page reports one (the first page asks for it, the others skip the count). */
52
+ total?: number;
53
+ }
54
+ /**
55
+ * Calls `fetchPage(after, pageSize, first)` with `after = ''` and then each page's `next` until a page has no `next`, the cap
56
+ * is reached or `signal` aborts. `first` is true only for the first call, so the caller can ask for the count once (progress)
57
+ * and skip it afterwards. Same options and result as `fetchAllPages`; `totalChanged` is always false here.
58
+ */
59
+ export declare function fetchAllByCursor<T>(fetchPage: (after: string, pageSize: number, first: boolean) => Promise<CursorPageResult<T>>, options?: FetchAllOptions<T>): Promise<FetchAllResult<T>>;
@@ -56,3 +56,47 @@ export async function fetchAllPages(fetchPage, options = {}) {
56
56
  }
57
57
  return { rows, total, truncated, totalChanged, duplicates, pages: page };
58
58
  }
59
+ export async function fetchAllByCursor(fetchPage, options = {}) {
60
+ const pageSize = Math.max(1, Math.floor(options.pageSize ?? DEFAULT_PAGE_SIZE) || DEFAULT_PAGE_SIZE);
61
+ const maxRows = Math.max(1, Math.floor(options.maxRows ?? DEFAULT_MAX_ROWS) || DEFAULT_MAX_ROWS);
62
+ const { signal, onProgress, keyOf } = options;
63
+ const rows = [];
64
+ const seen = keyOf ? /* @__PURE__ */ new Set() : void 0;
65
+ let total;
66
+ let duplicates = 0;
67
+ let truncated = false;
68
+ let page = 0;
69
+ let after = "";
70
+ for (; ; ) {
71
+ if (signal?.aborted) throw abortError(signal);
72
+ page++;
73
+ const result = await fetchPage(after, pageSize, page === 1);
74
+ if (signal?.aborted) throw abortError(signal);
75
+ if (typeof result.total === "number" && Number.isFinite(result.total)) total = result.total;
76
+ for (const row of result.rows) {
77
+ if (seen && keyOf) {
78
+ const key = keyOf(row);
79
+ if (seen.has(key)) {
80
+ duplicates++;
81
+ continue;
82
+ }
83
+ seen.add(key);
84
+ }
85
+ if (rows.length >= maxRows) {
86
+ truncated = true;
87
+ break;
88
+ }
89
+ rows.push(row);
90
+ }
91
+ onProgress?.({ loaded: rows.length, total, target: total === void 0 ? void 0 : Math.min(total, maxRows), page });
92
+ if (truncated) break;
93
+ const next = result.next;
94
+ if (rows.length >= maxRows) {
95
+ truncated = Boolean(next);
96
+ break;
97
+ }
98
+ if (!next || next === after || result.rows.length === 0) break;
99
+ after = next;
100
+ }
101
+ return { rows, total, truncated, totalChanged: false, duplicates, pages: page };
102
+ }
@@ -7,6 +7,11 @@ export interface QueryState {
7
7
  /** `['name', '-age']`: a leading `-` is descending (the server's own syntax). */
8
8
  sort: string[];
9
9
  projection: string[];
10
+ /**
11
+ * Match the case of wildcard terms (`name:Ali*`): fast, a prefix can use an index. Off (the default) sends
12
+ * `filterCaseInsensitive=true` with every wildcard filter, so `ali` also finds `Alice` (server 2.0).
13
+ */
14
+ matchCase: boolean;
10
15
  }
11
16
  export declare const MAX_SORT_ENTRIES = 5;
12
17
  export declare function emptyGroup(): FilterGroup;
@@ -4,7 +4,7 @@ export function emptyGroup() {
4
4
  return { match: "all", conditions: [] };
5
5
  }
6
6
  export function emptyQueryState() {
7
- return { filterGroup: emptyGroup(), lucene: "", sort: [], projection: [] };
7
+ return { filterGroup: emptyGroup(), lucene: "", sort: [], projection: [], matchCase: false };
8
8
  }
9
9
  export function isEmptyQuery(state) {
10
10
  return state.lucene === "" && state.sort.length === 0 && state.projection.length === 0;
@@ -15,12 +15,13 @@ export function toSavedQuery(state) {
15
15
  if (state.lucene !== "") query.lucene = state.lucene;
16
16
  if (state.sort.length > 0) query.sort = [...state.sort];
17
17
  if (state.projection.length > 0) query.projection = [...state.projection];
18
+ if (state.matchCase && (query.filterGroup || query.lucene)) query.matchCase = true;
18
19
  return query;
19
20
  }
20
21
  export function fromSavedQuery(query, fieldTypes) {
21
22
  const filterGroup = query.filterGroup ? { ...query.filterGroup, conditions: query.filterGroup.conditions.map((c) => ({ ...c })) } : emptyGroup();
22
23
  const lucene = query.filterGroup ? buildFilterQuery(filterGroup, fieldTypes) : query.lucene ?? "";
23
- return { filterGroup, lucene, sort: [...query.sort ?? []], projection: [...query.projection ?? []] };
24
+ return { filterGroup, lucene, sort: [...query.sort ?? []], projection: [...query.projection ?? []], matchCase: query.matchCase === true };
24
25
  }
25
26
  export function parseSortEntry(entry) {
26
27
  return entry.startsWith("-") ? { field: entry.slice(1), desc: true } : { field: entry, desc: false };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A document id as text: the hex of `{ $oid }`, the value of `{ $numberLong }` / `{ $numberInt }` / `{ $string }`, a plain
3
+ * string or number as it is. `undefined` for anything else (an object id, a binary id). Mirrors `documentId` of
4
+ * `@sfxcode/nuxt-mongocamp-server`, without needing `bson`.
5
+ */
6
+ export declare function idOf(value: unknown): string | undefined;
7
+ /** `true` for `{ $string: '…' }`, the server's marker for text that would otherwise be read as a date. */
8
+ export declare function isStringWrapper(value: unknown): value is {
9
+ $string: string;
10
+ };
11
+ /** `true` for a plain string or a `{ $string }` wrapper — a field that holds text. */
12
+ export declare function isTextValue(value: unknown): boolean;
13
+ /**
14
+ * A short text for the wrappers that have no plain JavaScript value: `Binary(00, 12 bytes)`, `/a.c/i`,
15
+ * `Timestamp(1700000000, 1)`, `MinKey`, `MaxKey`; also the text of `{ $string }`. `undefined` for anything else.
16
+ */
17
+ export declare function leafWrapperText(value: unknown): string | undefined;
@@ -0,0 +1,51 @@
1
+ function isRecord(value) {
2
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3
+ }
4
+ function onlyKey(value) {
5
+ const keys = Object.keys(value);
6
+ return keys.length === 1 ? keys[0] : void 0;
7
+ }
8
+ const ID_WRAPPERS = /* @__PURE__ */ new Set(["$oid", "$numberLong", "$numberInt", "$string"]);
9
+ export function idOf(value) {
10
+ if (typeof value === "string") return value;
11
+ if (typeof value === "number" && Number.isFinite(value)) return String(value);
12
+ if (isRecord(value)) {
13
+ const key = onlyKey(value);
14
+ const inner = key && ID_WRAPPERS.has(key) ? value[key] : void 0;
15
+ if (typeof inner === "string" || typeof inner === "number") return String(inner);
16
+ }
17
+ return void 0;
18
+ }
19
+ export function isStringWrapper(value) {
20
+ return isRecord(value) && onlyKey(value) === "$string" && typeof value.$string === "string";
21
+ }
22
+ export function isTextValue(value) {
23
+ return typeof value === "string" || isStringWrapper(value);
24
+ }
25
+ export function leafWrapperText(value) {
26
+ if (!isRecord(value)) return void 0;
27
+ const key = onlyKey(value);
28
+ const inner = key ? value[key] : void 0;
29
+ switch (key) {
30
+ case "$string":
31
+ return typeof inner === "string" ? inner : void 0;
32
+ case "$binary": {
33
+ if (!isRecord(inner)) return void 0;
34
+ const base64 = typeof inner.base64 === "string" ? inner.base64 : "";
35
+ const bytes = Math.floor(base64.replace(/=+$/, "").length * 3 / 4);
36
+ return `Binary(${String(inner.subType ?? "00")}, ${bytes} bytes)`;
37
+ }
38
+ case "$uuid":
39
+ return typeof inner === "string" ? `UUID(${inner})` : void 0;
40
+ case "$regularExpression":
41
+ return isRecord(inner) ? `/${String(inner.pattern ?? "")}/${String(inner.options ?? "")}` : void 0;
42
+ case "$timestamp":
43
+ return isRecord(inner) ? `Timestamp(${String(inner.t ?? "")}, ${String(inner.i ?? "")})` : void 0;
44
+ case "$minKey":
45
+ return "MinKey";
46
+ case "$maxKey":
47
+ return "MaxKey";
48
+ default:
49
+ return void 0;
50
+ }
51
+ }
@@ -1,2 +1,2 @@
1
- export declare const MAX_ENCODED_FILTER_LENGTH = 1800;
1
+ export declare const MAX_ENCODED_FILTER_LENGTH = 6000;
2
2
  export declare function isFilterTooLong(filter: string | undefined): boolean;
@@ -1,4 +1,4 @@
1
- export const MAX_ENCODED_FILTER_LENGTH = 1800;
1
+ export const MAX_ENCODED_FILTER_LENGTH = 6e3;
2
2
  export function isFilterTooLong(filter) {
3
3
  return filter !== void 0 && encodeURIComponent(filter).length > MAX_ENCODED_FILTER_LENGTH;
4
4
  }
@@ -6,6 +6,8 @@ export interface SavedQuery {
6
6
  lucene?: string;
7
7
  sort?: string[];
8
8
  projection?: string[];
9
+ /** The filter's wildcards match case exactly (see `QueryState.matchCase`); absent = case-insensitive. */
10
+ matchCase?: true;
9
11
  }
10
12
  export interface SavedQueryEntry {
11
13
  name: string;
@@ -55,6 +55,7 @@ export function sanitizeQuery(value) {
55
55
  if (sort) query.sort = sort;
56
56
  const projection = sanitizeStrings(value.projection, MAX_FIELDS);
57
57
  if (projection) query.projection = projection;
58
+ if (Object.keys(query).length > 0 && value.matchCase === true) query.matchCase = true;
58
59
  return Object.keys(query).length > 0 ? query : void 0;
59
60
  }
60
61
  function stable(value) {