@sfxcode/nuxt-ui-mongocamp 1.5.8 → 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.
- package/README.md +5 -5
- package/dist/module.json +1 -1
- package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue +5 -2
- package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampAggregationStagePreview.vue +4 -2
- package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampBucketFiles.vue +4 -6
- package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampCollectionCharts.vue +4 -2
- package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampCollectionCopy.vue +5 -3
- package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampCollectionData.vue +60 -25
- package/dist/runtime/components/MongocampCollectionInfos.vue +16 -1
- package/dist/runtime/components/MongocampDocumentView.vue +6 -1
- package/dist/runtime/components/MongocampExportAll.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampExportAll.vue +12 -0
- package/dist/runtime/components/MongocampExportAll.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampImport.vue +3 -0
- package/dist/runtime/components/MongocampIndexes.vue +7 -3
- package/dist/runtime/components/MongocampQueryBar.vue +15 -0
- package/dist/runtime/components/MongocampServerInfo.vue +1 -14
- package/dist/runtime/components/MongocampServerStatus.vue +7 -2
- package/dist/runtime/components/MongocampVersion.d.vue.ts +1 -1
- package/dist/runtime/components/MongocampVersion.vue +14 -7
- package/dist/runtime/components/MongocampVersion.vue.d.ts +1 -1
- package/dist/runtime/composables/useMongocampAdmin.js +6 -5
- package/dist/runtime/composables/useMongocampAggregation.d.ts +10 -1
- package/dist/runtime/composables/useMongocampAggregation.js +17 -5
- package/dist/runtime/composables/useMongocampBucket.d.ts +4 -0
- package/dist/runtime/composables/useMongocampBucket.js +7 -6
- package/dist/runtime/composables/useMongocampBulkByFilter.d.ts +6 -4
- package/dist/runtime/composables/useMongocampBulkByFilter.js +11 -6
- package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +3 -1
- package/dist/runtime/composables/useMongocampCollectionCopy.js +4 -2
- package/dist/runtime/composables/useMongocampCollectionStats.js +2 -4
- package/dist/runtime/composables/useMongocampError.d.ts +1 -1
- package/dist/runtime/composables/useMongocampError.js +4 -1
- package/dist/runtime/composables/useMongocampExportAll.d.ts +10 -1
- package/dist/runtime/composables/useMongocampExportAll.js +4 -1
- package/dist/runtime/composables/useMongocampFetchAll.d.ts +11 -5
- package/dist/runtime/composables/useMongocampFetchAll.js +8 -8
- package/dist/runtime/composables/useMongocampJobs.js +3 -2
- package/dist/runtime/composables/useMongocampQuery.d.ts +26 -36
- package/dist/runtime/composables/useMongocampQuery.js +45 -48
- package/dist/runtime/composables/useMongocampSchema.js +2 -0
- package/dist/runtime/locales/de.json +12 -4
- package/dist/runtime/locales/en.json +12 -4
- package/dist/runtime/publicUtils.d.ts +1 -0
- package/dist/runtime/publicUtils.js +1 -0
- package/dist/runtime/server/handlers/mongocampProxy.d.ts +1 -1
- package/dist/runtime/server/handlers/mongocampProxy.js +12 -12
- package/dist/runtime/utils/aggregationPipeline.d.ts +2 -1
- package/dist/runtime/utils/aggregationPipeline.js +2 -3
- package/dist/runtime/utils/caseInsensitive.d.ts +10 -0
- package/dist/runtime/utils/caseInsensitive.js +8 -0
- package/dist/runtime/utils/collectionStats.d.ts +4 -1
- package/dist/runtime/utils/collectionStats.js +2 -2
- package/dist/runtime/utils/configRows.d.ts +3 -3
- package/dist/runtime/utils/cursorPaging.d.ts +16 -0
- package/dist/runtime/utils/cursorPaging.js +17 -0
- package/dist/runtime/utils/documentCompare.js +2 -3
- package/dist/runtime/utils/documentPaths.d.ts +5 -5
- package/dist/runtime/utils/documentPaths.js +9 -2
- package/dist/runtime/utils/documentTree.js +3 -0
- package/dist/runtime/utils/fileFilter.d.ts +7 -0
- package/dist/runtime/utils/fileFilter.js +11 -0
- package/dist/runtime/utils/filterBuilder.d.ts +1 -1
- package/dist/runtime/utils/filterBuilder.js +5 -11
- package/dist/runtime/utils/filterSuggestions.js +1 -1
- package/dist/runtime/utils/indexForm.d.ts +7 -0
- package/dist/runtime/utils/indexForm.js +9 -0
- package/dist/runtime/utils/pagedFetch.d.ts +13 -0
- package/dist/runtime/utils/pagedFetch.js +44 -0
- package/dist/runtime/utils/queryState.d.ts +5 -0
- package/dist/runtime/utils/queryState.js +3 -2
- package/dist/runtime/utils/relaxedValues.d.ts +17 -0
- package/dist/runtime/utils/relaxedValues.js +51 -0
- package/dist/runtime/utils/requestLimits.d.ts +1 -1
- package/dist/runtime/utils/requestLimits.js +1 -1
- package/dist/runtime/utils/savedQueries.d.ts +2 -0
- package/dist/runtime/utils/savedQueries.js +1 -0
- package/dist/runtime/utils/schemaAnalysis.d.ts +4 -4
- package/dist/runtime/utils/schemaAnalysis.js +2 -2
- package/dist/runtime/utils/sensitiveFields.d.ts +20 -0
- package/dist/runtime/utils/sensitiveFields.js +63 -0
- package/dist/runtime/utils/serverError.d.ts +7 -0
- package/dist/runtime/utils/serverError.js +11 -0
- package/dist/runtime/utils/serverStatus.d.ts +2 -2
- package/package.json +12 -6
- package/dist/runtime/utils/luceneExpression.d.ts +0 -15
- package/dist/runtime/utils/luceneExpression.js +0 -74
|
@@ -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
|
|
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.
|
|
20
|
-
*
|
|
21
|
-
* `{ $
|
|
22
|
-
*
|
|
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
|
|
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)
|
|
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
|
|
66
|
+
return h.notExists(field);
|
|
73
67
|
case "isNotEmpty":
|
|
74
|
-
return h.exists(field
|
|
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 =
|
|
1
|
+
export declare const MAX_ENCODED_FILTER_LENGTH = 6000;
|
|
2
2
|
export declare function isFilterTooLong(filter: string | undefined): boolean;
|
|
@@ -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) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { SchemaAnalysis } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
2
|
import type { SampleAnalysis, ValueKind } from './analyzeSamples.js';
|
|
3
|
-
/** More documents than this are never analysed in one request
|
|
4
|
-
export declare const FULL_ANALYSIS_MAX_DOCUMENTS =
|
|
5
|
-
/** Time to wait for an analysis of `documents` documents: a fixed allowance plus 0.
|
|
3
|
+
/** More documents than this are never analysed in one request; use a sample instead. */
|
|
4
|
+
export declare const FULL_ANALYSIS_MAX_DOCUMENTS = 1000000;
|
|
5
|
+
/** Time to wait for an analysis of `documents` documents: a fixed allowance plus 0.05 ms each (measured: 0.012 ms), at most 2 minutes. */
|
|
6
6
|
export declare function analysisTimeoutMs(documents: number): number;
|
|
7
|
-
/** What to ask for: the
|
|
7
|
+
/** What to ask for: the count (every document; more than the collection holds is the same), capped, never 0. */
|
|
8
8
|
export declare function analysisSampleSize(documents: number): number;
|
|
9
9
|
export declare function kindOfServerType(serverType: string): ValueKind;
|
|
10
10
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { comparePaths } from "./analyzeSamples.js";
|
|
2
|
-
export const FULL_ANALYSIS_MAX_DOCUMENTS =
|
|
2
|
+
export const FULL_ANALYSIS_MAX_DOCUMENTS = 1e6;
|
|
3
3
|
const BASE_TIMEOUT_MS = 15e3;
|
|
4
|
-
const MS_PER_DOCUMENT = 0.
|
|
4
|
+
const MS_PER_DOCUMENT = 0.05;
|
|
5
5
|
const MAX_TIMEOUT_MS = 12e4;
|
|
6
6
|
export function analysisTimeoutMs(documents) {
|
|
7
7
|
return Math.min(MAX_TIMEOUT_MS, Math.round(BASE_TIMEOUT_MS + Math.max(0, documents) * MS_PER_DOCUMENT));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The top-level fields of `collection` that are never shown; `[]` for ordinary collections. */
|
|
2
|
+
export declare function sensitiveFieldsOf(collection: string): readonly string[];
|
|
3
|
+
/** A copy of `row` without the sensitive fields of `collection` (the row itself when there are none). */
|
|
4
|
+
export declare function withoutSensitiveFields<T extends Record<string, unknown>>(row: T, collection: string): T;
|
|
5
|
+
interface PipelineStageLike {
|
|
6
|
+
stage: string;
|
|
7
|
+
value: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** The hidden fields a pipeline over `collection` can reach (its own collection and every collection it joins). */
|
|
10
|
+
export declare function sensitiveFieldsOfPipeline(collection: string, pipeline: readonly PipelineStageLike[]): string[];
|
|
11
|
+
export interface SensitiveFieldUse {
|
|
12
|
+
stageIndex: number;
|
|
13
|
+
/** The path as written, e.g. `$password` or `$u.apiKey`. */
|
|
14
|
+
reference: string;
|
|
15
|
+
}
|
|
16
|
+
/** Every string `'$…'` (a field path, not a `'$$variable'`) whose last segment is one of `fields`. */
|
|
17
|
+
export declare function sensitiveFieldReferences(pipeline: readonly PipelineStageLike[], fields: readonly string[]): SensitiveFieldUse[];
|
|
18
|
+
/** A copy of `value` without any key named in `fields`, at any depth. */
|
|
19
|
+
export declare function withoutFieldsDeep<T>(value: T, fields: readonly string[]): T;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const SENSITIVE_FIELDS = {
|
|
2
|
+
mc_users: ["password", "apiKey"]
|
|
3
|
+
};
|
|
4
|
+
export function sensitiveFieldsOf(collection) {
|
|
5
|
+
return Object.hasOwn(SENSITIVE_FIELDS, collection) ? SENSITIVE_FIELDS[collection] : [];
|
|
6
|
+
}
|
|
7
|
+
export function withoutSensitiveFields(row, collection) {
|
|
8
|
+
const hidden = sensitiveFieldsOf(collection);
|
|
9
|
+
if (hidden.length === 0 || !hidden.some((field) => Object.hasOwn(row, field))) return row;
|
|
10
|
+
return Object.fromEntries(Object.entries(row).filter(([key]) => !hidden.includes(key)));
|
|
11
|
+
}
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function joinedCollections(value, into, depth = 0) {
|
|
16
|
+
if (depth > 32) return;
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
for (const entry of value) joinedCollections(entry, into, depth + 1);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!isRecord(value)) return;
|
|
22
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
23
|
+
if (key === "from" && typeof entry === "string") into.add(entry);
|
|
24
|
+
if (key === "$unionWith") {
|
|
25
|
+
if (typeof entry === "string") into.add(entry);
|
|
26
|
+
else if (isRecord(entry) && typeof entry.coll === "string") into.add(entry.coll);
|
|
27
|
+
}
|
|
28
|
+
joinedCollections(entry, into, depth + 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function sensitiveFieldsOfPipeline(collection, pipeline) {
|
|
32
|
+
const read = /* @__PURE__ */ new Set([collection]);
|
|
33
|
+
for (const stage of pipeline) {
|
|
34
|
+
if (stage.stage === "$unionWith" || stage.stage === "unionWith") joinedCollections({ $unionWith: stage.value }, read);
|
|
35
|
+
joinedCollections(stage.value, read);
|
|
36
|
+
}
|
|
37
|
+
return [...new Set([...read].flatMap((name) => [...sensitiveFieldsOf(name)]))];
|
|
38
|
+
}
|
|
39
|
+
export function sensitiveFieldReferences(pipeline, fields) {
|
|
40
|
+
if (fields.length === 0) return [];
|
|
41
|
+
const found = [];
|
|
42
|
+
const visit = (value, stageIndex, depth) => {
|
|
43
|
+
if (depth > 32 || found.length >= 20) return;
|
|
44
|
+
if (typeof value === "string") {
|
|
45
|
+
if (value.startsWith("$") && !value.startsWith("$$") && fields.includes(value.slice(1).split(".").pop())) found.push({ stageIndex, reference: value });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) value.forEach((entry) => visit(entry, stageIndex, depth + 1));
|
|
49
|
+
else if (isRecord(value)) Object.values(value).forEach((entry) => visit(entry, stageIndex, depth + 1));
|
|
50
|
+
};
|
|
51
|
+
pipeline.forEach((stage, index) => visit(stage.value, index, 0));
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
export function withoutFieldsDeep(value, fields) {
|
|
55
|
+
if (fields.length === 0) return value;
|
|
56
|
+
const strip = (entry, depth) => {
|
|
57
|
+
if (depth > 64) return entry;
|
|
58
|
+
if (Array.isArray(entry)) return entry.map((item) => strip(item, depth + 1));
|
|
59
|
+
if (!isRecord(entry)) return entry;
|
|
60
|
+
return Object.fromEntries(Object.entries(entry).filter(([key]) => !fields.includes(key)).map(([key, inner]) => [key, strip(inner, depth + 1)]));
|
|
61
|
+
};
|
|
62
|
+
return strip(value, 0);
|
|
63
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export declare const OPERATOR_NOT_ALLOWED_CODE = 4031;
|
|
2
|
+
/** The request was answered 404: what it asked for does not exist (any more). */
|
|
3
|
+
export declare function isNotFound(error: unknown): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Runs a delete-like request for which "it is already gone" is success: a 404 resolves with `undefined` instead of
|
|
6
|
+
* rejecting (server 2.0 answers 404 where 1.x answered `200 false` / a count of 0). Any other failure still rejects.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ignoringNotFound<T>(run: () => Promise<T>): Promise<T | undefined>;
|
|
2
9
|
export interface ServerError {
|
|
3
10
|
/** HTTP status of the response, when there was one. */
|
|
4
11
|
status?: number;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { parseServerError } from "./aggregationErrors.js";
|
|
2
2
|
export const OPERATOR_NOT_ALLOWED_CODE = 4031;
|
|
3
|
+
export function isNotFound(error) {
|
|
4
|
+
return error?.response?.status === 404;
|
|
5
|
+
}
|
|
6
|
+
export async function ignoringNotFound(run) {
|
|
7
|
+
try {
|
|
8
|
+
return await run();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (isNotFound(error)) return void 0;
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
3
14
|
export async function readServerError(error) {
|
|
4
15
|
const response = error?.response;
|
|
5
16
|
const status = typeof response?.status === "number" ? response.status : void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type ServerHealth = 'ok' | 'partial' | 'down';
|
|
2
2
|
/**
|
|
3
|
-
* What one request did: it answered (`ok`), the server answered with an error (`refused` — no right
|
|
4
|
-
*
|
|
3
|
+
* What one request did: it answered (`ok`), the server answered with an error (`refused` — e.g. no right: `/system/stats` is
|
|
4
|
+
* for administrators), nothing came back (`failed`), or it was not sent (`skipped` — not signed in, not allowed).
|
|
5
5
|
*/
|
|
6
6
|
export type Outcome = 'ok' | 'refused' | 'failed' | 'skipped';
|
|
7
7
|
/** An error that carries an HTTP response proves the server is there; anything else (network, timeout) does not. */
|