@sfxcode/mongocamp-server-core 2.5.0 → 2.6.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/dist/index.d.mts +110 -4
- package/dist/index.mjs +493 -50
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -40,6 +40,7 @@ declare const ConfigKeys: {
|
|
|
40
40
|
readonly WatchQueueMax: "WATCH_QUEUE_MAX";
|
|
41
41
|
readonly ServerHeaderEnabled: "SERVER_HEADER_ENABLED";
|
|
42
42
|
readonly ErrorsExposeInternal: "ERRORS_EXPOSE_INTERNAL";
|
|
43
|
+
readonly UsersReadHideApiKey: "USERS_READ_HIDE_API_KEY";
|
|
43
44
|
readonly ExportCsvEscapeFormulas: "EXPORT_CSV_ESCAPE_FORMULAS";
|
|
44
45
|
readonly FilterTimeZone: "FILTER_TIME_ZONE";
|
|
45
46
|
readonly MigrationDropScalaLeftovers: "MIGRATION_DROP_SCALA_LEFTOVERS";
|
|
@@ -154,6 +155,8 @@ declare class MongocampDatabase {
|
|
|
154
155
|
db(name?: string): Db;
|
|
155
156
|
/** Name of an internal collection, with the `AUTH_PREFIX` (`mc_users`, `mc_roles`, `mc_token_cache`, ...). */
|
|
156
157
|
internalCollectionName(name: string): string;
|
|
158
|
+
/** `USERS_READ_HIDE_API_KEY` (2.6.0): the document routes leave out `apiKey` of the users collection too. */
|
|
159
|
+
get hidesUserApiKeys(): boolean;
|
|
157
160
|
close(): Promise<void>;
|
|
158
161
|
}
|
|
159
162
|
|
|
@@ -178,13 +181,18 @@ declare class MongocampError extends Error {
|
|
|
178
181
|
readonly additionalInfo: string;
|
|
179
182
|
readonly issues?: ValidationIssue[] | undefined;
|
|
180
183
|
readonly current?: Record<string, unknown> | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* 2.6.0: the stored document of a version conflict with the values of the driver (without secrets), so the answer can use the Extended
|
|
186
|
+
* JSON mode of the request (`currentIn`); `current` is relaxed.
|
|
187
|
+
*/
|
|
188
|
+
storedDocument?: Record<string, unknown>;
|
|
181
189
|
constructor(message: string, status: number, code?: number, additionalInfo?: string, issues?: ValidationIssue[] | undefined, current?: Record<string, unknown> | undefined);
|
|
182
190
|
get description(): ErrorDescription;
|
|
183
191
|
static badRequest(message: string, code?: number): MongocampError;
|
|
184
192
|
/** 400 for documents that are not valid, with the fields in `issues` (a schema, a before-hook). */
|
|
185
193
|
static validation(issues: ValidationIssue[], message?: string, code?: number): MongocampError;
|
|
186
194
|
/** 409 for a write based on an outdated version, with the stored document (as Extended JSON) for the client to show or merge. */
|
|
187
|
-
static versionConflict(current: Record<string, unknown>): MongocampError;
|
|
195
|
+
static versionConflict(current: Record<string, unknown>, storedDocument?: Record<string, unknown>): MongocampError;
|
|
188
196
|
/** 403 and not 401: a client such as the UI clears its session on 401, but the session is fine, only this request is refused. */
|
|
189
197
|
static forbidden(message: string, code?: number): MongocampError;
|
|
190
198
|
static unauthorized(message?: string, code?: number): MongocampError;
|
|
@@ -196,6 +204,11 @@ type ErrorLogger = (error: unknown, status: number) => void;
|
|
|
196
204
|
interface ErrorResponseOptions {
|
|
197
205
|
/** The message of an unexpected error in the answer (`ERRORS_EXPOSE_INTERNAL`, for development); by default only the log has it. */
|
|
198
206
|
exposeInternal?: boolean | undefined;
|
|
207
|
+
/**
|
|
208
|
+
* 2.6.0: the `current` document of a version conflict in the Extended JSON mode of the request (query parameter `extendedJson`);
|
|
209
|
+
* relaxed without.
|
|
210
|
+
*/
|
|
211
|
+
currentIn?: ((document: Record<string, unknown>) => Record<string, unknown>) | undefined;
|
|
199
212
|
}
|
|
200
213
|
/** The message of an unexpected error (2.5.0): its text stays in the log, the client gets the request id (header `x-request-id`). */
|
|
201
214
|
declare const InternalErrorMessage = "internal server error, the log of the server has the details (x-request-id)";
|
|
@@ -666,6 +679,8 @@ interface ResolvedIndex {
|
|
|
666
679
|
fingerprint: string;
|
|
667
680
|
/** Declared, or added for a behaviour. */
|
|
668
681
|
origin: 'declaration' | 'owner';
|
|
682
|
+
/** The partial filter was added by soft delete (2.6.0: told in the declaration answer). */
|
|
683
|
+
softDeleteFilter?: boolean;
|
|
669
684
|
}
|
|
670
685
|
/**
|
|
671
686
|
* The indexes of a declaration: the declared ones and the ones of its behaviours (an index on the owner field; with soft delete, unique
|
|
@@ -683,9 +698,13 @@ declare function resolveIndexes(declarations: readonly IndexDeclaration[] | unde
|
|
|
683
698
|
* 'billing.accountId': 'crm:accounts', // a nested field, a collection of another database
|
|
684
699
|
* }
|
|
685
700
|
*/
|
|
686
|
-
/**
|
|
701
|
+
/**
|
|
702
|
+
* The target collection (`name` or `database:name`), or an object with it. `many` (2.6.0) says that the field holds an array of ids when
|
|
703
|
+
* the schema cannot tell (no schema of the field, a loose object); a schema that tells otherwise is an error.
|
|
704
|
+
*/
|
|
687
705
|
type RefDeclaration = string | {
|
|
688
706
|
readonly collection: string;
|
|
707
|
+
readonly many?: boolean;
|
|
689
708
|
};
|
|
690
709
|
interface ResolvedRef {
|
|
691
710
|
/** The field path of the reference. */
|
|
@@ -825,6 +844,13 @@ interface DeclaredCollection {
|
|
|
825
844
|
/** What the start did with the validator of MongoDB (`collections()` feature). */
|
|
826
845
|
sync?: ValidatorSyncResult;
|
|
827
846
|
}
|
|
847
|
+
/** A reference of a declared collection to another one (2.6.0, `referencedBy` of the declaration answer). */
|
|
848
|
+
interface ReferenceTo {
|
|
849
|
+
collection: string;
|
|
850
|
+
database: string;
|
|
851
|
+
field: string;
|
|
852
|
+
many: boolean;
|
|
853
|
+
}
|
|
828
854
|
/** The declarations of a server by database and collection; `context.collections`. */
|
|
829
855
|
declare class CollectionRegistry {
|
|
830
856
|
private readonly entries;
|
|
@@ -833,6 +859,13 @@ declare class CollectionRegistry {
|
|
|
833
859
|
find(databaseName: string, name: string): DeclaredCollection | undefined;
|
|
834
860
|
/** The declaration of a collection as the routes name it (`orders`, `otherdb:orders`). */
|
|
835
861
|
resolve(context: Pick<MongocampContext, 'database'>, collection: string): DeclaredCollection | undefined;
|
|
862
|
+
/** The fields of the declared refs of a collection (2.6.0: a Lucene term with an id matches their `ObjectId`); empty without a declaration. */
|
|
863
|
+
refFields(context: Pick<MongocampContext, 'database'>, collection: string): string[];
|
|
864
|
+
/**
|
|
865
|
+
* The references of the declared collections to a declaration (2.6.0, `referencedBy` of its answer), from the registry (no database
|
|
866
|
+
* read). `collection` is the name as the routes take it (`database:name` when the declaration names its database).
|
|
867
|
+
*/
|
|
868
|
+
referencesTo(context: Pick<MongocampContext, 'database'>, target: DeclaredCollection): ReferenceTo[];
|
|
836
869
|
get size(): number;
|
|
837
870
|
all(): DeclaredCollection[];
|
|
838
871
|
/** Adds declarations, all or none (a collection that is declared twice is an error); the returned function removes them. */
|
|
@@ -871,6 +904,26 @@ interface components {
|
|
|
871
904
|
CapabilityLimits: {
|
|
872
905
|
/** Format: int64 */
|
|
873
906
|
importMaxBytes: number;
|
|
907
|
+
/**
|
|
908
|
+
* Format: int64
|
|
909
|
+
* @description BODY_MAX_BYTES (2.6.0); 0 is no limit.
|
|
910
|
+
*/
|
|
911
|
+
bodyMaxBytes: number;
|
|
912
|
+
/**
|
|
913
|
+
* Format: int64
|
|
914
|
+
* @description PAGING_MAX_ROWS (2.6.0); 0 is no limit.
|
|
915
|
+
*/
|
|
916
|
+
pagingMaxRows: number;
|
|
917
|
+
/**
|
|
918
|
+
* Format: int64
|
|
919
|
+
* @description EXPORT_MAX_DOCUMENTS (2.6.0); 0 is no limit.
|
|
920
|
+
*/
|
|
921
|
+
exportMaxDocuments: number;
|
|
922
|
+
/**
|
|
923
|
+
* Format: int64
|
|
924
|
+
* @description GRIDFS_UPLOAD_MAX_BYTES (2.6.0); 0 is no limit.
|
|
925
|
+
*/
|
|
926
|
+
gridfsUploadMaxBytes: number;
|
|
874
927
|
/** Format: int32 */
|
|
875
928
|
grantDeniedStatus: number;
|
|
876
929
|
};
|
|
@@ -1398,14 +1451,44 @@ interface components {
|
|
|
1398
1451
|
[key: string]: unknown;
|
|
1399
1452
|
};
|
|
1400
1453
|
unique: boolean;
|
|
1454
|
+
/** @description 2.6.0 */
|
|
1455
|
+
sparse: boolean;
|
|
1456
|
+
/**
|
|
1457
|
+
* @description Declared, or added for a behaviour (owner = the index on the owner field), 2.6.0.
|
|
1458
|
+
* @enum {string}
|
|
1459
|
+
*/
|
|
1460
|
+
origin: "declaration" | "owner";
|
|
1461
|
+
/** @description The partial filter as relaxed Extended JSON (2.6.0), as index details show it. */
|
|
1462
|
+
partialFilterExpression?: {
|
|
1463
|
+
[key: string]: unknown;
|
|
1464
|
+
};
|
|
1465
|
+
/**
|
|
1466
|
+
* @description softDelete when the soft delete behaviour added the partial filter to a unique index (2.6.0).
|
|
1467
|
+
* @enum {string}
|
|
1468
|
+
*/
|
|
1469
|
+
partialFilterFrom?: "softDelete";
|
|
1470
|
+
/**
|
|
1471
|
+
* Format: int64
|
|
1472
|
+
* @description 2.6.0
|
|
1473
|
+
*/
|
|
1474
|
+
expireAfterSeconds?: number;
|
|
1401
1475
|
}[];
|
|
1402
1476
|
/** @description The references of the declaration (2.4.0), the fields a read can expand (query parameter expand). */
|
|
1403
1477
|
refs: {
|
|
1404
1478
|
field: string;
|
|
1405
1479
|
/** @description The target collection (name or database:name). */
|
|
1406
1480
|
collection: string;
|
|
1407
|
-
/** @description Whether the field holds an array of ids (from the schema);
|
|
1408
|
-
many
|
|
1481
|
+
/** @description Whether the field holds an array of ids (from the schema or the declaration); false when neither tells (2.6.0, before it was missing then). */
|
|
1482
|
+
many: boolean;
|
|
1483
|
+
}[];
|
|
1484
|
+
/** @description The references of the declared collections to this collection (2.6.0), from the declarations of the server; empty when none. */
|
|
1485
|
+
referencedBy: {
|
|
1486
|
+
/** @description The referencing collection as the routes name it (name or database:name). */
|
|
1487
|
+
collection: string;
|
|
1488
|
+
database: string;
|
|
1489
|
+
/** @description The field of the referencing collection that holds the id. */
|
|
1490
|
+
field: string;
|
|
1491
|
+
many: boolean;
|
|
1409
1492
|
}[];
|
|
1410
1493
|
timestamps?: {
|
|
1411
1494
|
createdAt: string;
|
|
@@ -1791,6 +1874,12 @@ declare class ConfigPersistence {
|
|
|
1791
1874
|
private persistentDefinitions;
|
|
1792
1875
|
/** Registers the missing keys with their defaults (`registerConfig`) and reads the stored values; the refresh starts if wanted. */
|
|
1793
1876
|
initialize(refreshMillis?: number | false): Promise<void>;
|
|
1877
|
+
/**
|
|
1878
|
+
* 2.6.0: a database created before 2.2.0 stored the old default 401 of `AUTH_GRANT_DENIED_STATUS` at its first start, and kept answering
|
|
1879
|
+
* 401 for a missing grant. A stored 401 that no update set (no `changedAt`, written since 2.6.0) becomes the default 403 once; an
|
|
1880
|
+
* administrator who wants 401 patches it again (then it is marked and stays).
|
|
1881
|
+
*/
|
|
1882
|
+
private upgradeLegacyDefaults;
|
|
1794
1883
|
/** Reads the stored values; at startup also the keys that need a restart, later only the ones that are active at once. */
|
|
1795
1884
|
refresh(startup: boolean): Promise<void>;
|
|
1796
1885
|
/** A configuration as answered by the API: the stored one, the one of the env, or a non persistent one. */
|
|
@@ -1803,6 +1892,11 @@ declare class ConfigPersistence {
|
|
|
1803
1892
|
* in this instance, the other instances read it with their next refresh.
|
|
1804
1893
|
*/
|
|
1805
1894
|
update(key: string, value: unknown): Promise<boolean>;
|
|
1895
|
+
/**
|
|
1896
|
+
* 2.6.0: the default again (`DELETE /system/configurations/{key}`), at once in this instance for a key that needs no restart. The
|
|
1897
|
+
* reasons it is not possible are answered by the route (unknown, not persistent, set by the environment, a generated default).
|
|
1898
|
+
*/
|
|
1899
|
+
reset(key: string): Promise<boolean>;
|
|
1806
1900
|
close(): void;
|
|
1807
1901
|
}
|
|
1808
1902
|
|
|
@@ -2410,6 +2504,12 @@ declare const ErrorCodes: {
|
|
|
2410
2504
|
readonly changeStreamsUnsupported: 5011;
|
|
2411
2505
|
readonly unauthorizedUser: 4011;
|
|
2412
2506
|
readonly unauthorizedUserForOtherUser: 4012;
|
|
2507
|
+
/** 413 (2.6.0): the body is greater than `BODY_MAX_BYTES`. */
|
|
2508
|
+
readonly bodyTooLarge: 4131;
|
|
2509
|
+
/** 413 (2.6.0): the uploaded file is greater than `GRIDFS_UPLOAD_MAX_BYTES`. */
|
|
2510
|
+
readonly uploadTooLarge: 4132;
|
|
2511
|
+
/** 413 (2.6.0): the import is greater than `IMPORT_MAX_BYTES`. */
|
|
2512
|
+
readonly importTooLarge: 4133;
|
|
2413
2513
|
readonly forbiddenStage: 4031;
|
|
2414
2514
|
readonly forbiddenCollectionInStage: 4032;
|
|
2415
2515
|
readonly jobAlreadyAdded: 4121;
|
|
@@ -2617,6 +2717,10 @@ declare class LuceneQueryError extends Error {
|
|
|
2617
2717
|
* - ranges are `$gte`/`$gt`/`$lte`/`$lt`, `[* TO *]`, `field:*` and `_exists_:field` are `$exists`
|
|
2618
2718
|
*
|
|
2619
2719
|
* With `searchWithValueAndString` a value that converts (e.g. the number `123`) is also searched as the text (`"123"`).
|
|
2720
|
+
*
|
|
2721
|
+
* 2.6.0: a term with 24 hex characters on a field of `idFields` (the declared refs of the collection) matches the `ObjectId` and the text
|
|
2722
|
+
* (`$in` / `$nin`), so `customerId:<hex>` finds the orders of a customer; an array ref matches when one element is the id. Only declared
|
|
2723
|
+
* refs: a 24-hex text on any other field stays a plain term (no other filter changes its results).
|
|
2620
2724
|
*/
|
|
2621
2725
|
type Filter = Record<string, unknown>;
|
|
2622
2726
|
interface ConvertOptions {
|
|
@@ -2625,6 +2729,8 @@ interface ConvertOptions {
|
|
|
2625
2729
|
caseInsensitive?: boolean;
|
|
2626
2730
|
/** The time zone of dates without offset (`FILTER_TIME_ZONE`), UTC by default. */
|
|
2627
2731
|
timeZone?: string;
|
|
2732
|
+
/** Fields whose 24-hex terms also match the `ObjectId` (2.6.0: the declared refs of the collection). */
|
|
2733
|
+
idFields?: Iterable<string>;
|
|
2628
2734
|
}
|
|
2629
2735
|
declare function luceneQueryToFilter(query: LuceneQuery, options?: ConvertOptions): Filter;
|
|
2630
2736
|
|
package/dist/index.mjs
CHANGED
|
@@ -148,6 +148,12 @@ const ErrorCodes = {
|
|
|
148
148
|
changeStreamsUnsupported: 5011,
|
|
149
149
|
unauthorizedUser: 4011,
|
|
150
150
|
unauthorizedUserForOtherUser: 4012,
|
|
151
|
+
/** 413 (2.6.0): the body is greater than `BODY_MAX_BYTES`. */
|
|
152
|
+
bodyTooLarge: 4131,
|
|
153
|
+
/** 413 (2.6.0): the uploaded file is greater than `GRIDFS_UPLOAD_MAX_BYTES`. */
|
|
154
|
+
uploadTooLarge: 4132,
|
|
155
|
+
/** 413 (2.6.0): the import is greater than `IMPORT_MAX_BYTES`. */
|
|
156
|
+
importTooLarge: 4133,
|
|
151
157
|
forbiddenStage: 4031,
|
|
152
158
|
forbiddenCollectionInStage: 4032,
|
|
153
159
|
jobAlreadyAdded: 4121,
|
|
@@ -424,6 +430,11 @@ class MongocampError extends Error {
|
|
|
424
430
|
this.current = current;
|
|
425
431
|
this.name = "MongocampError";
|
|
426
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* 2.6.0: the stored document of a version conflict with the values of the driver (without secrets), so the answer can use the Extended
|
|
435
|
+
* JSON mode of the request (`currentIn`); `current` is relaxed.
|
|
436
|
+
*/
|
|
437
|
+
storedDocument;
|
|
427
438
|
get description() {
|
|
428
439
|
const description = { code: this.code, msg: this.message, additionalInfo: this.additionalInfo };
|
|
429
440
|
if (this.issues !== void 0) {
|
|
@@ -442,8 +453,12 @@ class MongocampError extends Error {
|
|
|
442
453
|
return new MongocampError(message, 400, code, "", issues);
|
|
443
454
|
}
|
|
444
455
|
/** 409 for a write based on an outdated version, with the stored document (as Extended JSON) for the client to show or merge. */
|
|
445
|
-
static versionConflict(current) {
|
|
446
|
-
|
|
456
|
+
static versionConflict(current, storedDocument) {
|
|
457
|
+
const error = new MongocampError("the document was changed in the meantime: read it again (current) and repeat the change", 409, ErrorCodes.versionConflict, "", void 0, current);
|
|
458
|
+
if (storedDocument !== void 0) {
|
|
459
|
+
error.storedDocument = storedDocument;
|
|
460
|
+
}
|
|
461
|
+
return error;
|
|
447
462
|
}
|
|
448
463
|
/** 403 and not 401: a client such as the UI clears its session on 401, but the session is fine, only this request is refused. */
|
|
449
464
|
static forbidden(message, code = -1) {
|
|
@@ -483,7 +498,11 @@ const InternalErrorMessage = "internal server error, the log of the server has t
|
|
|
483
498
|
function toErrorResponse(error, log = defaultLogger, options = {}) {
|
|
484
499
|
const cause = error instanceof HTTPError && error.cause instanceof Error ? error.cause : error;
|
|
485
500
|
if (cause instanceof MongocampError) {
|
|
486
|
-
|
|
501
|
+
const description = cause.description;
|
|
502
|
+
if (cause.storedDocument !== void 0 && options.currentIn !== void 0) {
|
|
503
|
+
description.current = options.currentIn(cause.storedDocument);
|
|
504
|
+
}
|
|
505
|
+
return errorResponse(cause.status, description);
|
|
487
506
|
}
|
|
488
507
|
const databaseError = findDatabaseError(cause);
|
|
489
508
|
if (databaseError) {
|
|
@@ -900,6 +919,7 @@ const ConfigKeys = {
|
|
|
900
919
|
// new in 2.5.0: what the answers of the server show (the `server` header, the messages of unexpected errors) and csv formula escaping
|
|
901
920
|
ServerHeaderEnabled: "SERVER_HEADER_ENABLED",
|
|
902
921
|
ErrorsExposeInternal: "ERRORS_EXPOSE_INTERNAL",
|
|
922
|
+
UsersReadHideApiKey: "USERS_READ_HIDE_API_KEY",
|
|
903
923
|
ExportCsvEscapeFormulas: "EXPORT_CSV_ESCAPE_FORMULAS",
|
|
904
924
|
// new in 2.0.0: the time zone of dates without offset in Lucene filters
|
|
905
925
|
FilterTimeZone: "FILTER_TIME_ZONE",
|
|
@@ -982,6 +1002,8 @@ const configDefinitions = [
|
|
|
982
1002
|
define(K.WatchQueueMax, "Long", 1e3),
|
|
983
1003
|
define(K.ServerHeaderEnabled, "Boolean", true),
|
|
984
1004
|
define(K.ErrorsExposeInternal, "Boolean", false),
|
|
1005
|
+
// 2.6.0: the document routes leave out apiKey of the users collection too (default true in 3.0)
|
|
1006
|
+
define(K.UsersReadHideApiKey, "Boolean", false),
|
|
985
1007
|
define(K.ExportCsvEscapeFormulas, "Boolean", false),
|
|
986
1008
|
define(K.FilterTimeZone, "String", "UTC"),
|
|
987
1009
|
define(K.MigrationDropScalaLeftovers, "Boolean", false, nonPersistent),
|
|
@@ -992,7 +1014,7 @@ const configDefinitions = [
|
|
|
992
1014
|
define(K.FileHandler, "String", "gridfs", restart),
|
|
993
1015
|
define(K.FileCacheAge, "String", "7776000"),
|
|
994
1016
|
define(K.CorsHeadersAllowed, "List[String]", ["Authorization", "Content-Type", "X-Requested-With", "X-AUTH-APIKEY"]),
|
|
995
|
-
define(K.CorsHeadersExposed, "List[String]", ["Content-Type", "x-pagination-rows-per-page", "x-pagination-current-page", "x-pagination-count-rows", "x-pagination-count-pages", "x-pagination-next", "x-request-id"]),
|
|
1017
|
+
define(K.CorsHeadersExposed, "List[String]", ["Content-Type", "x-pagination-rows-per-page", "x-pagination-current-page", "x-pagination-count-rows", "x-pagination-count-pages", "x-pagination-next", "x-request-id", "x-export-max-documents"]),
|
|
996
1018
|
define(K.CorsOriginsAllowed, "List[String]", ["http://localhost:8080"]),
|
|
997
1019
|
define(K.DocsSwagger, "Boolean", false, restart),
|
|
998
1020
|
define(K.DocsOpenApi, "Boolean", true, restart),
|
|
@@ -1035,6 +1057,9 @@ function longQuery(params, name) {
|
|
|
1035
1057
|
}
|
|
1036
1058
|
return value;
|
|
1037
1059
|
}
|
|
1060
|
+
function limitPaging(paging, maxRows) {
|
|
1061
|
+
return maxRows > 0 && (paging.rowsPerPage ?? 0) > maxRows ? { ...paging, rowsPerPage: maxRows } : paging;
|
|
1062
|
+
}
|
|
1038
1063
|
function readPaging(params) {
|
|
1039
1064
|
const paging = { rowsPerPage: longQuery(params, "rowsPerPage"), page: longQuery(params, "page") };
|
|
1040
1065
|
if (params.has("after")) {
|
|
@@ -2000,6 +2025,7 @@ class ConfigPersistence {
|
|
|
2000
2025
|
};
|
|
2001
2026
|
await this.collection.updateOne({ key: definition.key }, { $setOnInsert: document }, { upsert: true });
|
|
2002
2027
|
}
|
|
2028
|
+
await this.upgradeLegacyDefaults();
|
|
2003
2029
|
await this.refresh(true);
|
|
2004
2030
|
if (refreshMillis !== false) {
|
|
2005
2031
|
this.timer = setInterval(() => {
|
|
@@ -2008,6 +2034,14 @@ class ConfigPersistence {
|
|
|
2008
2034
|
this.timer.unref?.();
|
|
2009
2035
|
}
|
|
2010
2036
|
}
|
|
2037
|
+
/**
|
|
2038
|
+
* 2.6.0: a database created before 2.2.0 stored the old default 401 of `AUTH_GRANT_DENIED_STATUS` at its first start, and kept answering
|
|
2039
|
+
* 401 for a missing grant. A stored 401 that no update set (no `changedAt`, written since 2.6.0) becomes the default 403 once; an
|
|
2040
|
+
* administrator who wants 401 patches it again (then it is marked and stays).
|
|
2041
|
+
*/
|
|
2042
|
+
async upgradeLegacyDefaults() {
|
|
2043
|
+
await this.collection.updateOne({ key: "AUTH_GRANT_DENIED_STATUS", value: 401, changedAt: { $exists: false } }, { $set: { value: 403 } });
|
|
2044
|
+
}
|
|
2011
2045
|
/** Reads the stored values; at startup also the keys that need a restart, later only the ones that are active at once. */
|
|
2012
2046
|
async refresh(startup) {
|
|
2013
2047
|
const documents = await this.collection.find({}).toArray();
|
|
@@ -2067,7 +2101,7 @@ class ConfigPersistence {
|
|
|
2067
2101
|
}
|
|
2068
2102
|
const internal = valueForUpdate(definition, value);
|
|
2069
2103
|
const stored = toStored(definition.type, internal);
|
|
2070
|
-
const before = await this.collection.findOneAndUpdate({ key }, { $set: { value: stored } });
|
|
2104
|
+
const before = await this.collection.findOneAndUpdate({ key }, { $set: { value: stored, changedAt: /* @__PURE__ */ new Date() } });
|
|
2071
2105
|
if (!before) {
|
|
2072
2106
|
return false;
|
|
2073
2107
|
}
|
|
@@ -2077,6 +2111,24 @@ class ConfigPersistence {
|
|
|
2077
2111
|
}
|
|
2078
2112
|
return true;
|
|
2079
2113
|
}
|
|
2114
|
+
/**
|
|
2115
|
+
* 2.6.0: the default again (`DELETE /system/configurations/{key}`), at once in this instance for a key that needs no restart. The
|
|
2116
|
+
* reasons it is not possible are answered by the route (unknown, not persistent, set by the environment, a generated default).
|
|
2117
|
+
*/
|
|
2118
|
+
async reset(key) {
|
|
2119
|
+
const definition = this.config.definition(key);
|
|
2120
|
+
if (!definition?.persistent || this.config.overrideOf(key) === "env" || typeof definition.defaultValue === "function") {
|
|
2121
|
+
return false;
|
|
2122
|
+
}
|
|
2123
|
+
const internal = definition.defaultValue;
|
|
2124
|
+
const stored = toStored(definition.type, internal);
|
|
2125
|
+
const before = await this.collection.findOneAndUpdate({ key }, { $set: { value: stored, comment: "" }, $unset: { changedAt: "" } }, { upsert: true });
|
|
2126
|
+
this.events?.publish("config:update", { key, newValue: SecretKeys.has(key) ? SecretMask : stored, oldValue: SecretKeys.has(key) ? SecretMask : before?.value ?? null, callingMethod: "resetConfig" });
|
|
2127
|
+
if (!definition.needsRestartForActivation) {
|
|
2128
|
+
this.config.applyPersisted(key, internal);
|
|
2129
|
+
}
|
|
2130
|
+
return true;
|
|
2131
|
+
}
|
|
2080
2132
|
close() {
|
|
2081
2133
|
if (this.timer) {
|
|
2082
2134
|
clearInterval(this.timer);
|
|
@@ -2120,6 +2172,10 @@ class MongocampDatabase {
|
|
|
2120
2172
|
internalCollectionName(name) {
|
|
2121
2173
|
return `${this.config.string(ConfigKeys.AuthPrefix)}${name}`;
|
|
2122
2174
|
}
|
|
2175
|
+
/** `USERS_READ_HIDE_API_KEY` (2.6.0): the document routes leave out `apiKey` of the users collection too. */
|
|
2176
|
+
get hidesUserApiKeys() {
|
|
2177
|
+
return this.config.boolean(ConfigKeys.UsersReadHideApiKey);
|
|
2178
|
+
}
|
|
2123
2179
|
async close() {
|
|
2124
2180
|
if (this.ownsClient) {
|
|
2125
2181
|
await this.client.close();
|
|
@@ -3027,6 +3083,7 @@ function resolveIndexes(declarations, behaviours) {
|
|
|
3027
3083
|
}
|
|
3028
3084
|
if (indexOptions.unique === true && behaviours.softDelete !== void 0 && indexOptions.partialFilterExpression === void 0) {
|
|
3029
3085
|
indexOptions.partialFilterExpression = { [behaviours.softDelete.field]: null };
|
|
3086
|
+
return { ...resolved(key, indexOptions, options.name, "declaration"), softDeleteFilter: true };
|
|
3030
3087
|
}
|
|
3031
3088
|
return resolved(key, indexOptions, options.name, "declaration");
|
|
3032
3089
|
});
|
|
@@ -3201,7 +3258,16 @@ function resolveRefs(refs, behaviours, jsonSchema) {
|
|
|
3201
3258
|
if (throughArray) {
|
|
3202
3259
|
throw new Error(`refs: ${field} goes through an array, only the last part of a reference may be an array`);
|
|
3203
3260
|
}
|
|
3204
|
-
|
|
3261
|
+
const declaredMany = typeof declaration === "object" && declaration !== null ? declaration.many : void 0;
|
|
3262
|
+
if (declaredMany !== void 0 && typeof declaredMany !== "boolean") {
|
|
3263
|
+
throw new Error(`refs: many of ${field} must be a boolean`);
|
|
3264
|
+
}
|
|
3265
|
+
const schemaMany = node !== void 0 ? isArrayNode(node) : void 0;
|
|
3266
|
+
if (declaredMany !== void 0 && schemaMany !== void 0 && declaredMany !== schemaMany) {
|
|
3267
|
+
throw new Error(`refs: ${field} is declared with many: ${declaredMany}, but the schema says ${schemaMany ? "an array" : "no array"}`);
|
|
3268
|
+
}
|
|
3269
|
+
const many = schemaMany ?? declaredMany;
|
|
3270
|
+
return { field, collection, ...many !== void 0 ? { many } : {} };
|
|
3205
3271
|
});
|
|
3206
3272
|
}
|
|
3207
3273
|
|
|
@@ -4004,11 +4070,15 @@ function idToString(id) {
|
|
|
4004
4070
|
}
|
|
4005
4071
|
|
|
4006
4072
|
const SecretUserFields = ["password"];
|
|
4073
|
+
const SecretUserFieldsWithApiKey = ["password", "apiKey"];
|
|
4007
4074
|
function secretFieldsOf(database, collection) {
|
|
4008
4075
|
const name = parseCollectionName(collection);
|
|
4009
4076
|
const defaultDatabase = database.db().databaseName;
|
|
4010
4077
|
const inDefault = name.database === void 0 || name.database === defaultDatabase;
|
|
4011
|
-
|
|
4078
|
+
if (!inDefault || name.name !== database.internalCollectionName("users")) {
|
|
4079
|
+
return [];
|
|
4080
|
+
}
|
|
4081
|
+
return database.hidesUserApiKeys ? SecretUserFieldsWithApiKey : SecretUserFields;
|
|
4012
4082
|
}
|
|
4013
4083
|
function withoutSecrets(document, fields) {
|
|
4014
4084
|
if (fields.length === 0 || !fields.some((field) => field in document)) {
|
|
@@ -4101,7 +4171,8 @@ function registerVersioned(context, own) {
|
|
|
4101
4171
|
const conflictCheck = (collection, filter) => async () => {
|
|
4102
4172
|
const stored = await collectionOf(context.database, collection).findOne(filter);
|
|
4103
4173
|
if (stored !== null) {
|
|
4104
|
-
|
|
4174
|
+
const secrets = secretFieldsOf(context.database, collection);
|
|
4175
|
+
throw MongocampError.versionConflict(withoutSecrets(documentToJson(stored), secrets), withoutSecrets(stored, secrets));
|
|
4105
4176
|
}
|
|
4106
4177
|
};
|
|
4107
4178
|
const removers = [
|
|
@@ -4391,6 +4462,22 @@ class CollectionRegistry {
|
|
|
4391
4462
|
const name = parseCollectionName(collection);
|
|
4392
4463
|
return this.find(databaseOf(context.database, name).databaseName, name.name);
|
|
4393
4464
|
}
|
|
4465
|
+
/** The fields of the declared refs of a collection (2.6.0: a Lucene term with an id matches their `ObjectId`); empty without a declaration. */
|
|
4466
|
+
refFields(context, collection) {
|
|
4467
|
+
return this.resolve(context, collection)?.refs.map((ref) => ref.field) ?? [];
|
|
4468
|
+
}
|
|
4469
|
+
/**
|
|
4470
|
+
* The references of the declared collections to a declaration (2.6.0, `referencedBy` of its answer), from the registry (no database
|
|
4471
|
+
* read). `collection` is the name as the routes take it (`database:name` when the declaration names its database).
|
|
4472
|
+
*/
|
|
4473
|
+
referencesTo(context, target) {
|
|
4474
|
+
return this.all().flatMap((entry) => entry.refs.filter((ref) => this.resolve(context, ref.collection) === target).map((ref) => ({
|
|
4475
|
+
collection: entry.definition.database !== void 0 ? `${entry.definition.database}${CollectionSeparator}${entry.definition.name}` : entry.definition.name,
|
|
4476
|
+
database: entry.databaseName,
|
|
4477
|
+
field: ref.field,
|
|
4478
|
+
many: ref.many ?? false
|
|
4479
|
+
})));
|
|
4480
|
+
}
|
|
4394
4481
|
get size() {
|
|
4395
4482
|
return this.entries.size;
|
|
4396
4483
|
}
|
|
@@ -4724,7 +4811,7 @@ async function readLines(collection, body, maxBytes, state, beforeBatch) {
|
|
|
4724
4811
|
}
|
|
4725
4812
|
bytes += value.byteLength;
|
|
4726
4813
|
if (bytes > maxBytes) {
|
|
4727
|
-
throw new MongocampError("the body of the request is greater than IMPORT_MAX_BYTES", 413);
|
|
4814
|
+
throw new MongocampError("the body of the request is greater than IMPORT_MAX_BYTES", 413, ErrorCodes.importTooLarge);
|
|
4728
4815
|
}
|
|
4729
4816
|
pending += decoder.decode(value, { stream: true });
|
|
4730
4817
|
let newline = pending.indexOf("\n");
|
|
@@ -5137,8 +5224,7 @@ class DocumentService {
|
|
|
5137
5224
|
/** The filter with the read scope of the caller. */
|
|
5138
5225
|
/** The paging of a read with `rowsPerPage` at most `PAGING_MAX_ROWS` (2.5.0, 0: no limit); the page headers show the rows used. */
|
|
5139
5226
|
limited(paging) {
|
|
5140
|
-
|
|
5141
|
-
return max > 0 && (paging.rowsPerPage ?? 0) > max ? { ...paging, rowsPerPage: max } : paging;
|
|
5227
|
+
return limitPaging(paging, this.context.config.number(ConfigKeys.PagingMaxRows));
|
|
5142
5228
|
}
|
|
5143
5229
|
/** Refuses filters, projections and updates of the caller with an operator of `FILTER_OPERATORS_DENIED` (2.5.0). */
|
|
5144
5230
|
checkOperators(...values) {
|
|
@@ -5806,8 +5892,9 @@ function parseDate(text, timeZone = "UTC") {
|
|
|
5806
5892
|
return (FullIsoDate.test(text) ? parseJodaIso(text, timeZone) : void 0) ?? parseSimplePatterns(text, timeZone);
|
|
5807
5893
|
}
|
|
5808
5894
|
|
|
5895
|
+
const ObjectIdHex = /^[0-9a-f]{24}$/i;
|
|
5809
5896
|
function luceneQueryToFilter(query, options = {}) {
|
|
5810
|
-
const settings = { both: options.searchWithValueAndString ?? false, caseInsensitive: options.caseInsensitive ?? false, timeZone: options.timeZone ?? "UTC" };
|
|
5897
|
+
const settings = { both: options.searchWithValueAndString ?? false, caseInsensitive: options.caseInsensitive ?? false, timeZone: options.timeZone ?? "UTC", idFields: new Set(options.idFields ?? []) };
|
|
5811
5898
|
return searchMap(query, false, settings);
|
|
5812
5899
|
}
|
|
5813
5900
|
function searchMap(query, negated, settings) {
|
|
@@ -5913,6 +6000,10 @@ function appendTerm(negated, result, field, termText, settings, quoted = false)
|
|
|
5913
6000
|
}
|
|
5914
6001
|
const both = settings.both || quoted;
|
|
5915
6002
|
const text = termText.includes("*") ? unescape(termText) : termText;
|
|
6003
|
+
if (settings.idFields.has(field) && ObjectIdHex.test(text)) {
|
|
6004
|
+
result[field] = { [negated ? "$nin" : "$in"]: [new ObjectId(text), text] };
|
|
6005
|
+
return;
|
|
6006
|
+
}
|
|
5916
6007
|
const value = convertTermValue(text, settings.timeZone);
|
|
5917
6008
|
const operator = negated ? "$ne" : "$eq";
|
|
5918
6009
|
if (!both || value === text) {
|
|
@@ -6584,7 +6675,7 @@ function createServerCollection(context, name, options) {
|
|
|
6584
6675
|
if (filter === void 0) {
|
|
6585
6676
|
return {};
|
|
6586
6677
|
}
|
|
6587
|
-
return typeof filter === "string" ? filterParameter(filter, { timeZone: context.config.string(ConfigKeys.FilterTimeZone) }) : filter;
|
|
6678
|
+
return typeof filter === "string" ? filterParameter(filter, { timeZone: context.config.string(ConfigKeys.FilterTimeZone), idFields: context.collections.refFields(context, name) }) : filter;
|
|
6588
6679
|
};
|
|
6589
6680
|
const plain = (document) => plainNumbers(document);
|
|
6590
6681
|
const decodedConflict = async (write) => {
|
|
@@ -6785,7 +6876,7 @@ const operations = [
|
|
|
6785
6876
|
["GET", "/auth/authenticated", "isAuthenticated", "Auth", "Check Authentication"],
|
|
6786
6877
|
["GET", "/admin/users", "listUsers", "Admin", "List Users"],
|
|
6787
6878
|
["PUT", "/admin/users", "addUser", "Admin", "Add User"],
|
|
6788
|
-
["PATCH", "/admin/users/:userId/apikey", "
|
|
6879
|
+
["PATCH", "/admin/users/:userId/apikey", "generateNewApiKeyForUser", "Admin", "Update ApiKey"],
|
|
6789
6880
|
["PATCH", "/admin/users/:userId/password", "updatePasswordForUser", "Admin", "Update Password"],
|
|
6790
6881
|
["PATCH", "/admin/users/:userId/roles", "updateRolesForUser", "Admin", "Update User Roles"],
|
|
6791
6882
|
["GET", "/admin/users/:userId", "getUser", "Admin", "UserProfile for userId"],
|
|
@@ -6795,6 +6886,7 @@ const operations = [
|
|
|
6795
6886
|
["GET", "/admin/roles/:roleName", "getRole", "Admin", "Get Role"],
|
|
6796
6887
|
["DELETE", "/admin/roles/:roleName", "deleteRole", "Admin", "Delete Role"],
|
|
6797
6888
|
["PATCH", "/admin/roles/:roleName", "updateRole", "Admin", "Update Role"],
|
|
6889
|
+
["POST", "/mongodb/buckets/:bucketName/files/search", "searchFiles", "File", "Search Files in Bucket"],
|
|
6798
6890
|
["GET", "/mongodb/buckets/:bucketName/files", "listFiles", "File", "Files in Bucket"],
|
|
6799
6891
|
["PUT", "/mongodb/buckets/:bucketName/files", "insertFile", "File", "Insert File"],
|
|
6800
6892
|
["POST", "/mongodb/buckets/:bucketName/files", "findFiles", "File", "Files in Bucket"],
|
|
@@ -6827,6 +6919,7 @@ const operations = [
|
|
|
6827
6919
|
["GET", "/system/configurations", "listConfigurations", "Application", "List Configurations"],
|
|
6828
6920
|
["GET", "/system/configurations/:configurationKey", "getConfig", "Application", "Configuration for configurationKey"],
|
|
6829
6921
|
["PATCH", "/system/configurations/:configurationKey", "updateConfiguration", "Application", "Update Configuration"],
|
|
6922
|
+
["DELETE", "/system/configurations/:configurationKey", "resetConfiguration", "Application", "Reset Configuration"],
|
|
6830
6923
|
["DELETE", "/system", "shutdown", "Application", "Shutdown MongoCamp"],
|
|
6831
6924
|
["GET", "/mongodb/databases", "ListDatabases", "Database", "List of Databases"],
|
|
6832
6925
|
["GET", "/mongodb/databases/infos", "databaseInfos", "Database", "List of Database Infos"],
|
|
@@ -6996,7 +7089,7 @@ function optionalInteger$1(body, field) {
|
|
|
6996
7089
|
function isStringList(value) {
|
|
6997
7090
|
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
6998
7091
|
}
|
|
6999
|
-
function stringList(value, field) {
|
|
7092
|
+
function stringList$1(value, field) {
|
|
7000
7093
|
if (!isStringList(value)) {
|
|
7001
7094
|
fail(field);
|
|
7002
7095
|
}
|
|
@@ -7026,7 +7119,7 @@ function readUserInformation(body) {
|
|
|
7026
7119
|
userId: requiredString(object, "userId"),
|
|
7027
7120
|
password: requiredString(object, "password"),
|
|
7028
7121
|
apiKey: optionalString(object, "apiKey") ?? null,
|
|
7029
|
-
roles: object.roles === void 0 || object.roles === null ? [] : stringList(object.roles, "roles")
|
|
7122
|
+
roles: object.roles === void 0 || object.roles === null ? [] : stringList$1(object.roles, "roles")
|
|
7030
7123
|
};
|
|
7031
7124
|
}
|
|
7032
7125
|
function readGrant(value, index) {
|
|
@@ -7055,7 +7148,7 @@ function readUpdateRole(body) {
|
|
|
7055
7148
|
};
|
|
7056
7149
|
}
|
|
7057
7150
|
function readRoleNames(body) {
|
|
7058
|
-
return stringList(body, "body");
|
|
7151
|
+
return stringList$1(body, "body");
|
|
7059
7152
|
}
|
|
7060
7153
|
|
|
7061
7154
|
function pathParam(event, name) {
|
|
@@ -7090,15 +7183,15 @@ function booleanQuery(params, name, defaultValue) {
|
|
|
7090
7183
|
}
|
|
7091
7184
|
return normalized === "true";
|
|
7092
7185
|
}
|
|
7093
|
-
function filterOptions(params, config) {
|
|
7186
|
+
function filterOptions(params, config, idFields = []) {
|
|
7094
7187
|
const timeZone = config.string(ConfigKeys.FilterTimeZone);
|
|
7095
7188
|
if (!isTimeZone(timeZone)) {
|
|
7096
7189
|
throw new MongocampError(`${ConfigKeys.FilterTimeZone} is no time zone: ${timeZone}`, 500);
|
|
7097
7190
|
}
|
|
7098
|
-
return { caseInsensitive: booleanQuery(params, "filterCaseInsensitive", false), timeZone };
|
|
7191
|
+
return { caseInsensitive: booleanQuery(params, "filterCaseInsensitive", false), timeZone, idFields };
|
|
7099
7192
|
}
|
|
7100
7193
|
function tooLarge() {
|
|
7101
|
-
return new MongocampError("the body of the request is greater than BODY_MAX_BYTES", 413);
|
|
7194
|
+
return new MongocampError("the body of the request is greater than BODY_MAX_BYTES", 413, ErrorCodes.bodyTooLarge);
|
|
7102
7195
|
}
|
|
7103
7196
|
async function readText(event) {
|
|
7104
7197
|
const max = event.context.mongocampBodyMaxBytes ?? 0;
|
|
@@ -7278,7 +7371,7 @@ function registerAggregationRoutes(app, context) {
|
|
|
7278
7371
|
if (queryFilter !== null && queryFilter.trim() !== "" && request.filter !== void 0 && request.filter.trim() !== "") {
|
|
7279
7372
|
throw MongocampError.badRequest("send the filter in the query or in the body, not in both", ErrorCodes.ambiguousFilter);
|
|
7280
7373
|
}
|
|
7281
|
-
const matchFilter = request.filter !== void 0 ? bodyFilter(request.filter, filterOptions(params, config)) : filterParameter(queryFilter, filterOptions(params, config));
|
|
7374
|
+
const matchFilter = request.filter !== void 0 ? bodyFilter(request.filter, filterOptions(params, config, context.collections.refFields(context, collection))) : filterParameter(queryFilter, filterOptions(params, config, context.collections.refFields(context, collection)));
|
|
7282
7375
|
checkPipeline(user, collection, request.pipeline, config.list(ConfigKeys.AggregationStagesDenied));
|
|
7283
7376
|
const prefix = [];
|
|
7284
7377
|
if (Object.keys(matchFilter).length > 0) {
|
|
@@ -7490,7 +7583,7 @@ async function uploadFile(bucket, request, fileNameOverride, maxBytes = 0) {
|
|
|
7490
7583
|
await uploaded;
|
|
7491
7584
|
if (truncated) {
|
|
7492
7585
|
await deleteFile(bucket, id);
|
|
7493
|
-
throw new MongocampError("the file is greater than GRIDFS_UPLOAD_MAX_BYTES", 413);
|
|
7586
|
+
throw new MongocampError("the file is greater than GRIDFS_UPLOAD_MAX_BYTES", 413, ErrorCodes.uploadTooLarge);
|
|
7494
7587
|
}
|
|
7495
7588
|
if (!metadataWithUpload && metadataText !== void 0) {
|
|
7496
7589
|
await filesCollection(bucket).updateOne({ _id: id }, { $set: { metadata: uploadMetadata(metadataText) } });
|
|
@@ -7540,6 +7633,16 @@ function mapField$1(body, field) {
|
|
|
7540
7633
|
}
|
|
7541
7634
|
return decodeAny(value);
|
|
7542
7635
|
}
|
|
7636
|
+
function stringList(body, field) {
|
|
7637
|
+
const value = body[field];
|
|
7638
|
+
if (value === void 0 || value === null) {
|
|
7639
|
+
return [];
|
|
7640
|
+
}
|
|
7641
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
7642
|
+
throw MongocampError.decodeFailure("body", `field ${field}`);
|
|
7643
|
+
}
|
|
7644
|
+
return value;
|
|
7645
|
+
}
|
|
7543
7646
|
function registerBucketRoutes(app, context) {
|
|
7544
7647
|
const { auth, database, config, events } = context;
|
|
7545
7648
|
const base = "/mongodb/buckets/:bucketName";
|
|
@@ -7587,7 +7690,7 @@ function registerBucketRoutes(app, context) {
|
|
|
7587
7690
|
const filesResponse = (page) => jsonResponse(page.items, { headers: paginationHeaders(page.info) });
|
|
7588
7691
|
const files = (bucket, request, params) => {
|
|
7589
7692
|
checkDeniedFilterOperators([request.filter, request.projection], config.list(ConfigKeys.FilterOperatorsDenied));
|
|
7590
|
-
return findFiles(bucket, request, readPaging(params), readCountMode(params));
|
|
7693
|
+
return findFiles(bucket, request, limitPaging(readPaging(params), config.number(ConfigKeys.PagingMaxRows)), readCountMode(params));
|
|
7591
7694
|
};
|
|
7592
7695
|
app.get(`${base}/files`, async (event) => {
|
|
7593
7696
|
const { bucket } = await authorized(event, "read");
|
|
@@ -7602,6 +7705,17 @@ function registerBucketRoutes(app, context) {
|
|
|
7602
7705
|
const params = queryParams(event);
|
|
7603
7706
|
return filesResponse(await files(bucket, request, params));
|
|
7604
7707
|
});
|
|
7708
|
+
app.post(`${base}/files/search`, async (event) => {
|
|
7709
|
+
const { bucket } = await authorized(event, "read");
|
|
7710
|
+
const params = queryParams(event);
|
|
7711
|
+
const body = asObject(await readJson(event));
|
|
7712
|
+
const request = {
|
|
7713
|
+
filter: bodyFilter(optionalString(body, "filter"), filterOptions(params, config)),
|
|
7714
|
+
sort: sortFromList(stringList(body, "sort")),
|
|
7715
|
+
projection: projectionFromList(stringList(body, "projection"))
|
|
7716
|
+
};
|
|
7717
|
+
return filesResponse(await files(bucket, request, params));
|
|
7718
|
+
});
|
|
7605
7719
|
app.put(`${base}/files`, async (event) => {
|
|
7606
7720
|
const { bucket, name, user } = await authorized(event, "write");
|
|
7607
7721
|
const id = await uploadFile(bucket, event.req, queryParams(event).get("fileName") ?? void 0, context.config.number(ConfigKeys.GridfsUploadMaxBytes));
|
|
@@ -8585,7 +8699,7 @@ function registerCollectionRoutes(app, context) {
|
|
|
8585
8699
|
if (!await existsIn(source)) {
|
|
8586
8700
|
throw new MongocampError(`the collection ${fullName(source)} does not exist`, 404, ErrorCodes.invalidCollectionName);
|
|
8587
8701
|
}
|
|
8588
|
-
const filter = bodyFilter(request.filter, filterOptions(queryParams(event), config));
|
|
8702
|
+
const filter = bodyFilter(request.filter, filterOptions(queryParams(event), config, context.collections.refFields(context, collection)));
|
|
8589
8703
|
const targetExists = await checkTarget(user, target, request.dropTarget);
|
|
8590
8704
|
const result = await copyCollection(database, source, target, filter, request.withIndexes, targetExists, systemPrefix());
|
|
8591
8705
|
context.events.publish("collection:copy", { user: user.user, collectionName: fullName(source), newCollectionName: fullName(target) });
|
|
@@ -9265,7 +9379,7 @@ paths:
|
|
|
9265
9379
|
- Admin
|
|
9266
9380
|
summary: Update ApiKey
|
|
9267
9381
|
description: Generate a new API key for the user
|
|
9268
|
-
operationId:
|
|
9382
|
+
operationId: generateNewApiKeyForUser
|
|
9269
9383
|
parameters:
|
|
9270
9384
|
- name: userId
|
|
9271
9385
|
in: path
|
|
@@ -9862,6 +9976,152 @@ paths:
|
|
|
9862
9976
|
- httpAuth: []
|
|
9863
9977
|
- httpAuth1: []
|
|
9864
9978
|
- apiKeyAuth: []
|
|
9979
|
+
/mongodb/buckets/{bucketName}/files/search:
|
|
9980
|
+
post:
|
|
9981
|
+
tags:
|
|
9982
|
+
- File
|
|
9983
|
+
summary: Search Files in Bucket
|
|
9984
|
+
description: 'The files of the bucket with a Lucene filter (2.6.0), like the search of documents: filter, sort and projection in the request body (no URL limit), fields of the files collection (filename, length, uploadDate, metadata.*). The operators of FILTER_OPERATORS_DENIED are refused; PAGING_MAX_ROWS applies.'
|
|
9985
|
+
operationId: searchFiles
|
|
9986
|
+
parameters:
|
|
9987
|
+
- name: bucketName
|
|
9988
|
+
in: path
|
|
9989
|
+
description: The name of your MongoDb Collection
|
|
9990
|
+
required: true
|
|
9991
|
+
schema:
|
|
9992
|
+
type: string
|
|
9993
|
+
- name: rowsPerPage
|
|
9994
|
+
in: query
|
|
9995
|
+
description: Count elements per page
|
|
9996
|
+
required: false
|
|
9997
|
+
schema:
|
|
9998
|
+
type: integer
|
|
9999
|
+
format: int64
|
|
10000
|
+
example: 100
|
|
10001
|
+
- name: page
|
|
10002
|
+
in: query
|
|
10003
|
+
description: Requested page of the ResultSets
|
|
10004
|
+
required: false
|
|
10005
|
+
schema:
|
|
10006
|
+
type: integer
|
|
10007
|
+
format: int64
|
|
10008
|
+
example: 1
|
|
10009
|
+
- name: count
|
|
10010
|
+
in: query
|
|
10011
|
+
description: 'How the result is counted: exact (default) or none (no count headers, no count query)'
|
|
10012
|
+
required: false
|
|
10013
|
+
schema:
|
|
10014
|
+
type: string
|
|
10015
|
+
enum:
|
|
10016
|
+
- exact
|
|
10017
|
+
- none
|
|
10018
|
+
default: exact
|
|
10019
|
+
example: exact
|
|
10020
|
+
- name: after
|
|
10021
|
+
in: query
|
|
10022
|
+
description: 'Cursor paging: the x-pagination-next value of the previous page, empty for the first page. The sort always ends
|
|
10023
|
+
with _id; cannot be combined with page'
|
|
10024
|
+
required: false
|
|
10025
|
+
schema:
|
|
10026
|
+
type: string
|
|
10027
|
+
example: ''
|
|
10028
|
+
- name: filterCaseInsensitive
|
|
10029
|
+
in: query
|
|
10030
|
+
description: 'true: wildcards and prefixes of the Lucene filter ignore the case.'
|
|
10031
|
+
required: false
|
|
10032
|
+
schema:
|
|
10033
|
+
type: boolean
|
|
10034
|
+
default: false
|
|
10035
|
+
requestBody:
|
|
10036
|
+
content:
|
|
10037
|
+
application/json:
|
|
10038
|
+
schema:
|
|
10039
|
+
$ref: '#/components/schemas/SearchRequest'
|
|
10040
|
+
example:
|
|
10041
|
+
filter: filename:report* AND metadata.year:2024
|
|
10042
|
+
sort:
|
|
10043
|
+
- -uploadDate
|
|
10044
|
+
required: true
|
|
10045
|
+
responses:
|
|
10046
|
+
'200':
|
|
10047
|
+
description: ''
|
|
10048
|
+
headers:
|
|
10049
|
+
x-pagination-count-rows:
|
|
10050
|
+
description: count all elements
|
|
10051
|
+
required: false
|
|
10052
|
+
schema:
|
|
10053
|
+
type: integer
|
|
10054
|
+
format: int64
|
|
10055
|
+
example: 200
|
|
10056
|
+
x-pagination-rows-per-page:
|
|
10057
|
+
description: Count elements per page
|
|
10058
|
+
required: true
|
|
10059
|
+
schema:
|
|
10060
|
+
type: integer
|
|
10061
|
+
format: int64
|
|
10062
|
+
example: 20
|
|
10063
|
+
x-pagination-current-page:
|
|
10064
|
+
description: Current page
|
|
10065
|
+
required: true
|
|
10066
|
+
schema:
|
|
10067
|
+
type: integer
|
|
10068
|
+
format: int64
|
|
10069
|
+
example: 1
|
|
10070
|
+
x-pagination-count-pages:
|
|
10071
|
+
description: Count pages
|
|
10072
|
+
required: false
|
|
10073
|
+
schema:
|
|
10074
|
+
type: integer
|
|
10075
|
+
format: int64
|
|
10076
|
+
example: 10
|
|
10077
|
+
x-pagination-next:
|
|
10078
|
+
description: 'Cursor of the next page (only with the parameter after, missing on the last page)'
|
|
10079
|
+
required: false
|
|
10080
|
+
schema:
|
|
10081
|
+
type: string
|
|
10082
|
+
content:
|
|
10083
|
+
application/json:
|
|
10084
|
+
schema:
|
|
10085
|
+
type: array
|
|
10086
|
+
items:
|
|
10087
|
+
$ref: '#/components/schemas/FileInformation'
|
|
10088
|
+
'400':
|
|
10089
|
+
description: 'Invalid value for: query parameter rowsPerPage, Invalid value
|
|
10090
|
+
for: query parameter page'
|
|
10091
|
+
content:
|
|
10092
|
+
text/plain:
|
|
10093
|
+
schema:
|
|
10094
|
+
type: string
|
|
10095
|
+
default:
|
|
10096
|
+
description: ''
|
|
10097
|
+
headers:
|
|
10098
|
+
x-error-code:
|
|
10099
|
+
description: Error Code
|
|
10100
|
+
required: true
|
|
10101
|
+
schema:
|
|
10102
|
+
type: integer
|
|
10103
|
+
format: int32
|
|
10104
|
+
example: 100
|
|
10105
|
+
x-error-message:
|
|
10106
|
+
description: Message of the MongoCampException
|
|
10107
|
+
required: true
|
|
10108
|
+
schema:
|
|
10109
|
+
type: string
|
|
10110
|
+
example: Error Message
|
|
10111
|
+
x-error-additional-info:
|
|
10112
|
+
description: Additional information for the MongoCampException
|
|
10113
|
+
required: true
|
|
10114
|
+
schema:
|
|
10115
|
+
type: string
|
|
10116
|
+
example: Additional Error Info
|
|
10117
|
+
content:
|
|
10118
|
+
application/json:
|
|
10119
|
+
schema:
|
|
10120
|
+
$ref: '#/components/schemas/ErrorDescription'
|
|
10121
|
+
security:
|
|
10122
|
+
- httpAuth: []
|
|
10123
|
+
- httpAuth1: []
|
|
10124
|
+
- apiKeyAuth: []
|
|
9865
10125
|
/mongodb/buckets/{bucketName}/files:
|
|
9866
10126
|
get:
|
|
9867
10127
|
tags:
|
|
@@ -12201,6 +12461,62 @@ paths:
|
|
|
12201
12461
|
- httpAuth: []
|
|
12202
12462
|
- httpAuth1: []
|
|
12203
12463
|
- apiKeyAuth: []
|
|
12464
|
+
delete:
|
|
12465
|
+
tags:
|
|
12466
|
+
- Application
|
|
12467
|
+
summary: Reset Configuration
|
|
12468
|
+
description: 'Reset the Configuration to its default value (2.6.0), at once for a key that needs no restart. 404 for an unknown key, 400 for a key that is read at the start only, set by the environment or has a generated default (AUTH_SECRET).'
|
|
12469
|
+
operationId: resetConfiguration
|
|
12470
|
+
parameters:
|
|
12471
|
+
- name: configurationKey
|
|
12472
|
+
in: path
|
|
12473
|
+
description: configurationKey to reset
|
|
12474
|
+
required: true
|
|
12475
|
+
schema:
|
|
12476
|
+
type: string
|
|
12477
|
+
responses:
|
|
12478
|
+
'200':
|
|
12479
|
+
description: ''
|
|
12480
|
+
content:
|
|
12481
|
+
application/json:
|
|
12482
|
+
schema:
|
|
12483
|
+
$ref: '#/components/schemas/JsonValue_Boolean'
|
|
12484
|
+
'400':
|
|
12485
|
+
description: 'Invalid value for: path parameter configurationKey'
|
|
12486
|
+
content:
|
|
12487
|
+
text/plain:
|
|
12488
|
+
schema:
|
|
12489
|
+
type: string
|
|
12490
|
+
default:
|
|
12491
|
+
description: ''
|
|
12492
|
+
headers:
|
|
12493
|
+
x-error-code:
|
|
12494
|
+
description: Error Code
|
|
12495
|
+
required: true
|
|
12496
|
+
schema:
|
|
12497
|
+
type: integer
|
|
12498
|
+
format: int32
|
|
12499
|
+
example: 100
|
|
12500
|
+
x-error-message:
|
|
12501
|
+
description: Message of the MongoCampException
|
|
12502
|
+
required: true
|
|
12503
|
+
schema:
|
|
12504
|
+
type: string
|
|
12505
|
+
example: Error Message
|
|
12506
|
+
x-error-additional-info:
|
|
12507
|
+
description: Additional information for the MongoCampException
|
|
12508
|
+
required: true
|
|
12509
|
+
schema:
|
|
12510
|
+
type: string
|
|
12511
|
+
example: Additional Error Info
|
|
12512
|
+
content:
|
|
12513
|
+
application/json:
|
|
12514
|
+
schema:
|
|
12515
|
+
$ref: '#/components/schemas/ErrorDescription'
|
|
12516
|
+
security:
|
|
12517
|
+
- httpAuth: []
|
|
12518
|
+
- httpAuth1: []
|
|
12519
|
+
- apiKeyAuth: []
|
|
12204
12520
|
/system:
|
|
12205
12521
|
delete:
|
|
12206
12522
|
tags:
|
|
@@ -15779,11 +16095,31 @@ components:
|
|
|
15779
16095
|
type: object
|
|
15780
16096
|
required:
|
|
15781
16097
|
- importMaxBytes
|
|
16098
|
+
- bodyMaxBytes
|
|
16099
|
+
- pagingMaxRows
|
|
16100
|
+
- exportMaxDocuments
|
|
16101
|
+
- gridfsUploadMaxBytes
|
|
15782
16102
|
- grantDeniedStatus
|
|
15783
16103
|
properties:
|
|
15784
16104
|
importMaxBytes:
|
|
15785
16105
|
type: integer
|
|
15786
16106
|
format: int64
|
|
16107
|
+
bodyMaxBytes:
|
|
16108
|
+
description: BODY_MAX_BYTES (2.6.0); 0 is no limit.
|
|
16109
|
+
type: integer
|
|
16110
|
+
format: int64
|
|
16111
|
+
pagingMaxRows:
|
|
16112
|
+
description: PAGING_MAX_ROWS (2.6.0); 0 is no limit.
|
|
16113
|
+
type: integer
|
|
16114
|
+
format: int64
|
|
16115
|
+
exportMaxDocuments:
|
|
16116
|
+
description: EXPORT_MAX_DOCUMENTS (2.6.0); 0 is no limit.
|
|
16117
|
+
type: integer
|
|
16118
|
+
format: int64
|
|
16119
|
+
gridfsUploadMaxBytes:
|
|
16120
|
+
description: GRIDFS_UPLOAD_MAX_BYTES (2.6.0); 0 is no limit.
|
|
16121
|
+
type: integer
|
|
16122
|
+
format: int64
|
|
15787
16123
|
grantDeniedStatus:
|
|
15788
16124
|
type: integer
|
|
15789
16125
|
format: int32
|
|
@@ -16813,6 +17149,7 @@ components:
|
|
|
16813
17149
|
- protectedFields
|
|
16814
17150
|
- indexes
|
|
16815
17151
|
- refs
|
|
17152
|
+
- referencedBy
|
|
16816
17153
|
properties:
|
|
16817
17154
|
name:
|
|
16818
17155
|
type: string
|
|
@@ -16842,6 +17179,8 @@ components:
|
|
|
16842
17179
|
- name
|
|
16843
17180
|
- key
|
|
16844
17181
|
- unique
|
|
17182
|
+
- sparse
|
|
17183
|
+
- origin
|
|
16845
17184
|
properties:
|
|
16846
17185
|
name:
|
|
16847
17186
|
type: string
|
|
@@ -16850,6 +17189,28 @@ components:
|
|
|
16850
17189
|
additionalProperties: true
|
|
16851
17190
|
unique:
|
|
16852
17191
|
type: boolean
|
|
17192
|
+
sparse:
|
|
17193
|
+
description: 2.6.0
|
|
17194
|
+
type: boolean
|
|
17195
|
+
origin:
|
|
17196
|
+
description: 'Declared, or added for a behaviour (owner = the index on the owner field), 2.6.0.'
|
|
17197
|
+
type: string
|
|
17198
|
+
enum:
|
|
17199
|
+
- declaration
|
|
17200
|
+
- owner
|
|
17201
|
+
partialFilterExpression:
|
|
17202
|
+
description: The partial filter as relaxed Extended JSON (2.6.0), as index details show it.
|
|
17203
|
+
type: object
|
|
17204
|
+
additionalProperties: true
|
|
17205
|
+
partialFilterFrom:
|
|
17206
|
+
description: softDelete when the soft delete behaviour added the partial filter to a unique index (2.6.0).
|
|
17207
|
+
type: string
|
|
17208
|
+
enum:
|
|
17209
|
+
- softDelete
|
|
17210
|
+
expireAfterSeconds:
|
|
17211
|
+
description: 2.6.0
|
|
17212
|
+
type: integer
|
|
17213
|
+
format: int64
|
|
16853
17214
|
refs:
|
|
16854
17215
|
description: The references of the declaration (2.4.0), the fields a read can expand (query parameter expand).
|
|
16855
17216
|
type: array
|
|
@@ -16858,6 +17219,7 @@ components:
|
|
|
16858
17219
|
required:
|
|
16859
17220
|
- field
|
|
16860
17221
|
- collection
|
|
17222
|
+
- many
|
|
16861
17223
|
properties:
|
|
16862
17224
|
field:
|
|
16863
17225
|
type: string
|
|
@@ -16865,7 +17227,28 @@ components:
|
|
|
16865
17227
|
description: The target collection (name or database:name).
|
|
16866
17228
|
type: string
|
|
16867
17229
|
many:
|
|
16868
|
-
description: Whether the field holds an array of ids (from the schema);
|
|
17230
|
+
description: Whether the field holds an array of ids (from the schema or the declaration); false when neither tells (2.6.0, before it was missing then).
|
|
17231
|
+
type: boolean
|
|
17232
|
+
referencedBy:
|
|
17233
|
+
description: The references of the declared collections to this collection (2.6.0), from the declarations of the server; empty when none.
|
|
17234
|
+
type: array
|
|
17235
|
+
items:
|
|
17236
|
+
type: object
|
|
17237
|
+
required:
|
|
17238
|
+
- collection
|
|
17239
|
+
- database
|
|
17240
|
+
- field
|
|
17241
|
+
- many
|
|
17242
|
+
properties:
|
|
17243
|
+
collection:
|
|
17244
|
+
description: The referencing collection as the routes name it (name or database:name).
|
|
17245
|
+
type: string
|
|
17246
|
+
database:
|
|
17247
|
+
type: string
|
|
17248
|
+
field:
|
|
17249
|
+
description: The field of the referencing collection that holds the id.
|
|
17250
|
+
type: string
|
|
17251
|
+
many:
|
|
16869
17252
|
type: boolean
|
|
16870
17253
|
timestamps:
|
|
16871
17254
|
type: object
|
|
@@ -17238,7 +17621,7 @@ function registerDocsRoutes(app, context) {
|
|
|
17238
17621
|
}
|
|
17239
17622
|
}
|
|
17240
17623
|
|
|
17241
|
-
function declarationInfo(declared) {
|
|
17624
|
+
function declarationInfo(declared, referencedBy = []) {
|
|
17242
17625
|
const { behaviours } = declared;
|
|
17243
17626
|
return {
|
|
17244
17627
|
name: declared.definition.name,
|
|
@@ -17246,8 +17629,20 @@ function declarationInfo(declared) {
|
|
|
17246
17629
|
validation: declared.validation,
|
|
17247
17630
|
systemFields: systemFields(behaviours).map((entry) => entry.path),
|
|
17248
17631
|
protectedFields: [...behaviours.protectedFields],
|
|
17249
|
-
|
|
17250
|
-
|
|
17632
|
+
// 2.6.0: the options as index details show them, and where the index comes from
|
|
17633
|
+
indexes: declared.indexes.map((index) => ({
|
|
17634
|
+
name: index.name,
|
|
17635
|
+
key: { ...index.key },
|
|
17636
|
+
unique: index.options.unique === true,
|
|
17637
|
+
sparse: index.options.sparse === true,
|
|
17638
|
+
origin: index.origin,
|
|
17639
|
+
...index.options.partialFilterExpression !== void 0 ? { partialFilterExpression: documentToJson(index.options.partialFilterExpression, "relaxed") } : {},
|
|
17640
|
+
...index.softDeleteFilter === true ? { partialFilterFrom: "softDelete" } : {},
|
|
17641
|
+
...typeof index.options.expireAfterSeconds === "number" ? { expireAfterSeconds: index.options.expireAfterSeconds } : {}
|
|
17642
|
+
})),
|
|
17643
|
+
// 2.6.0: many is always given (false when neither the schema nor the declaration says an array), and the references to this collection
|
|
17644
|
+
refs: declared.refs.map((ref) => ({ ...ref, many: ref.many ?? false })),
|
|
17645
|
+
referencedBy: referencedBy.map((reference) => ({ ...reference })),
|
|
17251
17646
|
...behaviours.timestamps !== void 0 ? { timestamps: { ...behaviours.timestamps } } : {},
|
|
17252
17647
|
...behaviours.owner !== void 0 ? { owner: { field: behaviours.owner.field, read: typeof behaviours.owner.read === "function" ? "custom" : behaviours.owner.read } } : {},
|
|
17253
17648
|
...behaviours.softDelete !== void 0 ? { softDelete: { ...behaviours.softDelete } } : {},
|
|
@@ -17347,12 +17742,12 @@ async function* converted(cursor, mode, secrets = [], expand) {
|
|
|
17347
17742
|
yield* flush();
|
|
17348
17743
|
}
|
|
17349
17744
|
}
|
|
17350
|
-
function endMarker(format, count) {
|
|
17745
|
+
function endMarker(format, count, capped = false) {
|
|
17351
17746
|
if (format === "ndjson") {
|
|
17352
|
-
return `${stringifyJson({ $end: true, count })}
|
|
17747
|
+
return `${stringifyJson(capped ? { $end: true, count, capped: true } : { $end: true, count })}
|
|
17353
17748
|
`;
|
|
17354
17749
|
}
|
|
17355
|
-
return format === "csv" ? `# end ${count}\r
|
|
17750
|
+
return format === "csv" ? `# end ${count}${capped ? " capped" : ""}\r
|
|
17356
17751
|
` : "";
|
|
17357
17752
|
}
|
|
17358
17753
|
function errorMarker(format, error) {
|
|
@@ -17364,11 +17759,23 @@ function errorMarker(format, error) {
|
|
|
17364
17759
|
return format === "csv" ? `# error ${message.replaceAll(/[\r\n]+/g, " ")}\r
|
|
17365
17760
|
` : "";
|
|
17366
17761
|
}
|
|
17762
|
+
async function* upTo(cursor, cap, onCapped) {
|
|
17763
|
+
let count = 0;
|
|
17764
|
+
for await (const document of cursor) {
|
|
17765
|
+
if (cap !== void 0 && count >= cap) {
|
|
17766
|
+
onCapped();
|
|
17767
|
+
return;
|
|
17768
|
+
}
|
|
17769
|
+
count++;
|
|
17770
|
+
yield document;
|
|
17771
|
+
}
|
|
17772
|
+
}
|
|
17367
17773
|
function exportStream(cursor, format, columns, options = {}) {
|
|
17368
17774
|
const encoder = new TextEncoder();
|
|
17369
17775
|
let count = 0;
|
|
17776
|
+
let capped = false;
|
|
17370
17777
|
async function* counted() {
|
|
17371
|
-
for await (const document of converted(cursor, options.mode, options.secrets, options.expand)) {
|
|
17778
|
+
for await (const document of converted(upTo(cursor, options.cap, () => capped = true), options.mode, options.secrets, options.expand)) {
|
|
17372
17779
|
count++;
|
|
17373
17780
|
yield document;
|
|
17374
17781
|
}
|
|
@@ -17380,7 +17787,7 @@ function exportStream(cursor, format, columns, options = {}) {
|
|
|
17380
17787
|
const { value, done } = await pieces.next();
|
|
17381
17788
|
if (done) {
|
|
17382
17789
|
if (options.trailer) {
|
|
17383
|
-
const marker = endMarker(format, count);
|
|
17790
|
+
const marker = endMarker(format, count, capped);
|
|
17384
17791
|
if (marker) {
|
|
17385
17792
|
controller.enqueue(encoder.encode(marker));
|
|
17386
17793
|
}
|
|
@@ -17466,12 +17873,13 @@ function registerDocumentRoutes(app, context) {
|
|
|
17466
17873
|
const pageOf = (collection, result, mode) => pageResponse({ items: result.documents.map((document) => documentToJson(document, mode)), info: result.info }, secretFieldsOf(database, collection));
|
|
17467
17874
|
const base = "/mongodb/collections/:collectionName/documents";
|
|
17468
17875
|
const collectionParam = (event) => pathParam(event, "collectionName");
|
|
17876
|
+
const refFields = (collection) => context.collections.refFields(context, collection);
|
|
17469
17877
|
app.get(base, async (event) => {
|
|
17470
17878
|
const collection = collectionParam(event);
|
|
17471
17879
|
const user = await auth.requireCollection(event.req, collection, "read");
|
|
17472
17880
|
const params = queryParams(event);
|
|
17473
17881
|
const request = {
|
|
17474
|
-
filter: convertFields(filterParameter(params.get("filter"), filterOptions(params, config))),
|
|
17882
|
+
filter: convertFields(filterParameter(params.get("filter"), filterOptions(params, config, refFields(collection)))),
|
|
17475
17883
|
sort: sortFromList(params.getAll("sort")),
|
|
17476
17884
|
projection: projectionFromList(params.getAll("projection"))
|
|
17477
17885
|
};
|
|
@@ -17482,7 +17890,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17482
17890
|
const collection = collectionParam(event);
|
|
17483
17891
|
const user = await auth.requireCollection(event.req, collection, "read");
|
|
17484
17892
|
const params = queryParams(event);
|
|
17485
|
-
const filter = convertFields(filterParameter(params.get("filter"), filterOptions(params, config)));
|
|
17893
|
+
const filter = convertFields(filterParameter(params.get("filter"), filterOptions(params, config, refFields(collection))));
|
|
17486
17894
|
return jsonResponse({ count: await service.count(user, collection, filter, withDeletedOf(params, user, collection)) });
|
|
17487
17895
|
});
|
|
17488
17896
|
app.post(`${base}/count`, async (event) => {
|
|
@@ -17490,7 +17898,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17490
17898
|
const user = await auth.requireCollection(event.req, collection, "read");
|
|
17491
17899
|
const params = queryParams(event);
|
|
17492
17900
|
const body = asObject(await readJson(event));
|
|
17493
|
-
const filter = convertFields(bodyFilter(optionalString(body, "filter"), filterOptions(params, config)));
|
|
17901
|
+
const filter = convertFields(bodyFilter(optionalString(body, "filter"), filterOptions(params, config, refFields(collection))));
|
|
17494
17902
|
return jsonResponse({ count: await service.count(user, collection, filter, withDeletedOf(params, user, collection)) });
|
|
17495
17903
|
});
|
|
17496
17904
|
app.post(`${base}/search`, async (event) => {
|
|
@@ -17500,7 +17908,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17500
17908
|
const mode = extendedJsonMode(params);
|
|
17501
17909
|
const body = asObject(await readJson(event));
|
|
17502
17910
|
const request = {
|
|
17503
|
-
filter: convertFields(bodyFilter(optionalString(body, "filter"), filterOptions(params, config))),
|
|
17911
|
+
filter: convertFields(bodyFilter(optionalString(body, "filter"), filterOptions(params, config, refFields(collection)))),
|
|
17504
17912
|
sort: sortFromList(stringListField(body, "sort")),
|
|
17505
17913
|
projection: projectionFromList(stringListField(body, "projection"))
|
|
17506
17914
|
};
|
|
@@ -17568,11 +17976,13 @@ function registerDocumentRoutes(app, context) {
|
|
|
17568
17976
|
}
|
|
17569
17977
|
const scoped = await service.exportFilter(user, collection, convertFields(request.filter), withDeletedOf(params, user, collection));
|
|
17570
17978
|
const maxDocuments = config.number(ConfigKeys.ExportMaxDocuments);
|
|
17979
|
+
const cap = maxDocuments > 0 && (request.limit === void 0 || request.limit > maxDocuments) ? maxDocuments : void 0;
|
|
17571
17980
|
const query = {
|
|
17572
17981
|
filter: scoped.filter,
|
|
17573
17982
|
sort: sortFromList(request.sort),
|
|
17574
17983
|
projection: projectionFromList(request.projection),
|
|
17575
|
-
|
|
17984
|
+
// 2.6.0: one more than the cap, so the end marker can tell that the cap cut the export
|
|
17985
|
+
limit: cap !== void 0 ? cap + 1 : request.limit
|
|
17576
17986
|
};
|
|
17577
17987
|
const target = collectionOf(database, collection);
|
|
17578
17988
|
const secrets = secretFieldsOf(database, collection);
|
|
@@ -17586,10 +17996,12 @@ function registerDocumentRoutes(app, context) {
|
|
|
17586
17996
|
}
|
|
17587
17997
|
const trailer = booleanQuery(params, "trailer", false);
|
|
17588
17998
|
const expand = refs.length > 0 ? (documents) => service.expand(user, documents, refs) : void 0;
|
|
17589
|
-
return new Response(exportStream(exportCursor(target, query), format, columns, { mode, secrets, trailer, expand, escapeFormulas: config.boolean(ConfigKeys.ExportCsvEscapeFormulas) }), {
|
|
17999
|
+
return new Response(exportStream(exportCursor(target, query), format, columns, { mode, secrets, trailer, expand, escapeFormulas: config.boolean(ConfigKeys.ExportCsvEscapeFormulas), cap }), {
|
|
17590
18000
|
headers: {
|
|
17591
18001
|
"content-type": "text/plain; charset=UTF-8",
|
|
17592
|
-
"content-disposition": `attachment; filename="${exportFileName(collection, format)}"
|
|
18002
|
+
"content-disposition": `attachment; filename="${exportFileName(collection, format)}"`,
|
|
18003
|
+
// 2.6.0: the cap before the body (a json array has no end marker)
|
|
18004
|
+
...maxDocuments > 0 ? { "x-export-max-documents": String(maxDocuments) } : {}
|
|
17593
18005
|
}
|
|
17594
18006
|
});
|
|
17595
18007
|
};
|
|
@@ -17597,7 +18009,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17597
18009
|
const collection = collectionParam(event);
|
|
17598
18010
|
const user = await auth.requireCollection(event.req, collection, "read");
|
|
17599
18011
|
const params = queryParams(event);
|
|
17600
|
-
const filter = filterParameter(params.get("filter"), filterOptions(params, config));
|
|
18012
|
+
const filter = filterParameter(params.get("filter"), filterOptions(params, config, refFields(collection)));
|
|
17601
18013
|
return exportResponse(user, collection, params, { filter, sort: params.getAll("sort"), projection: params.getAll("projection"), limit: intQuery(params, "limit"), expand: expandOf(params) });
|
|
17602
18014
|
});
|
|
17603
18015
|
app.post(`${base}/export`, async (event) => {
|
|
@@ -17606,7 +18018,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17606
18018
|
const params = queryParams(event);
|
|
17607
18019
|
const body = asObject(await readJson(event));
|
|
17608
18020
|
return exportResponse(user, collection, params, {
|
|
17609
|
-
filter: bodyFilter(optionalString(body, "filter"), filterOptions(params, config)),
|
|
18021
|
+
filter: bodyFilter(optionalString(body, "filter"), filterOptions(params, config, refFields(collection))),
|
|
17610
18022
|
sort: stringListField(body, "sort"),
|
|
17611
18023
|
projection: stringListField(body, "projection"),
|
|
17612
18024
|
limit: optionalInteger$1(body, "limit"),
|
|
@@ -17619,7 +18031,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17619
18031
|
const maxBytes = context.config.number(ConfigKeys.ImportMaxBytes);
|
|
17620
18032
|
const length = Number(event.req.headers.get("content-length") ?? Number.NaN);
|
|
17621
18033
|
if (Number.isFinite(length) && length > maxBytes) {
|
|
17622
|
-
throw new MongocampError("the body of the request is greater than IMPORT_MAX_BYTES", 413);
|
|
18034
|
+
throw new MongocampError("the body of the request is greater than IMPORT_MAX_BYTES", 413, ErrorCodes.importTooLarge);
|
|
17623
18035
|
}
|
|
17624
18036
|
const state = await service.import(user, collection, event.req.body, maxBytes);
|
|
17625
18037
|
return jsonResponse(state.response);
|
|
@@ -17643,7 +18055,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17643
18055
|
const body = asObject(await readJson(event));
|
|
17644
18056
|
const document = mapField(body, "document", true);
|
|
17645
18057
|
const params = queryParams(event);
|
|
17646
|
-
const filter = manyFilter(params, mapField(body, "filter"), filterOptions(params, config));
|
|
18058
|
+
const filter = manyFilter(params, mapField(body, "filter"), filterOptions(params, config, refFields(collection)));
|
|
17647
18059
|
return jsonResponse(await service.updateMany(user, collection, filter, convertToOperationMap(convertFields(document))));
|
|
17648
18060
|
});
|
|
17649
18061
|
app.delete(`${base}/many/delete`, async (event) => {
|
|
@@ -17652,7 +18064,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17652
18064
|
const body = await readOptionalJson(event);
|
|
17653
18065
|
const bodyMap = body === void 0 ? {} : decodeAnyObject(body);
|
|
17654
18066
|
const params = queryParams(event);
|
|
17655
|
-
return jsonResponse(await service.removeMany(user, collection, manyFilter(params, bodyMap, filterOptions(params, config))));
|
|
18067
|
+
return jsonResponse(await service.removeMany(user, collection, manyFilter(params, bodyMap, filterOptions(params, config, refFields(collection)))));
|
|
17656
18068
|
});
|
|
17657
18069
|
app.post(`${base}/:documentId/restore`, async (event) => {
|
|
17658
18070
|
const collection = collectionParam(event);
|
|
@@ -17666,7 +18078,7 @@ function registerDocumentRoutes(app, context) {
|
|
|
17666
18078
|
if (declared === void 0) {
|
|
17667
18079
|
throw MongocampError.notFound(`the collection ${collection} is not declared`);
|
|
17668
18080
|
}
|
|
17669
|
-
return jsonResponse(declarationInfo(declared));
|
|
18081
|
+
return jsonResponse(declarationInfo(declared, context.collections.referencesTo(context, declared)));
|
|
17670
18082
|
});
|
|
17671
18083
|
const auditedOf = (collection) => {
|
|
17672
18084
|
const declared = context.collections.resolve(context, collection);
|
|
@@ -18565,7 +18977,7 @@ function registerWatchRoutes(app, context) {
|
|
|
18565
18977
|
}
|
|
18566
18978
|
const params = queryParams(event);
|
|
18567
18979
|
const refs = context.documents.refs(collection, params.getAll("expand").flatMap((value) => value.split(",")));
|
|
18568
|
-
const scope = await readScope(context, user, collection, convertFields(filterParameter(params.get("filter"), filterOptions(params, config))), "watch");
|
|
18980
|
+
const scope = await readScope(context, user, collection, convertFields(filterParameter(params.get("filter"), filterOptions(params, config, context.collections.refFields(context, collection)))), "watch");
|
|
18569
18981
|
const target = collectionOf(database, collection);
|
|
18570
18982
|
const secrets = secretFieldsOf(database, collection);
|
|
18571
18983
|
const lastEventId = event.req.headers.get("last-event-id")?.trim() ?? "";
|
|
@@ -18770,6 +19182,11 @@ async function systemStats(admin) {
|
|
|
18770
19182
|
function capabilityLimits(config) {
|
|
18771
19183
|
return {
|
|
18772
19184
|
importMaxBytes: config.number(ConfigKeys.ImportMaxBytes),
|
|
19185
|
+
// 2.6.0: the limits of 2.5 for every user, 0 is no limit
|
|
19186
|
+
bodyMaxBytes: config.number(ConfigKeys.BodyMaxBytes),
|
|
19187
|
+
pagingMaxRows: config.number(ConfigKeys.PagingMaxRows),
|
|
19188
|
+
exportMaxDocuments: config.number(ConfigKeys.ExportMaxDocuments),
|
|
19189
|
+
gridfsUploadMaxBytes: config.number(ConfigKeys.GridfsUploadMaxBytes),
|
|
18773
19190
|
grantDeniedStatus: config.number(ConfigKeys.AuthGrantDeniedStatus) === 401 ? 401 : 403
|
|
18774
19191
|
};
|
|
18775
19192
|
}
|
|
@@ -18838,6 +19255,24 @@ function registerConfigurationRoutes(app, context) {
|
|
|
18838
19255
|
const updated = await configurations.update(key, decodeAny(body.value));
|
|
18839
19256
|
return jsonResponse({ value: updated });
|
|
18840
19257
|
});
|
|
19258
|
+
app.delete("/system/configurations/:configurationKey", async (event) => {
|
|
19259
|
+
await auth.requireAdmin(event.req);
|
|
19260
|
+
const key = pathParam(event, "configurationKey");
|
|
19261
|
+
const definition = config.definition(key);
|
|
19262
|
+
if (!definition) {
|
|
19263
|
+
throw MongocampError.notFound("configuration not found");
|
|
19264
|
+
}
|
|
19265
|
+
if (!definition.persistent) {
|
|
19266
|
+
throw MongocampError.badRequest(`${key} cannot be changed at runtime, it is read at the start only`);
|
|
19267
|
+
}
|
|
19268
|
+
if (config.overrideOf(key) === "env") {
|
|
19269
|
+
throw MongocampError.badRequest(`${key} is set by the environment and cannot be changed`);
|
|
19270
|
+
}
|
|
19271
|
+
if (typeof definition.defaultValue === "function") {
|
|
19272
|
+
throw MongocampError.badRequest(`${key} has a generated default and cannot be reset`);
|
|
19273
|
+
}
|
|
19274
|
+
return jsonResponse({ value: await configurations.reset(key) });
|
|
19275
|
+
});
|
|
18841
19276
|
app.delete("/system", async (event) => {
|
|
18842
19277
|
await auth.requireAdmin(event.req);
|
|
18843
19278
|
const shutdown = context.shutdown;
|
|
@@ -18894,11 +19329,19 @@ const routeGroups = [
|
|
|
18894
19329
|
registerIndexRoutes,
|
|
18895
19330
|
registerBucketRoutes
|
|
18896
19331
|
];
|
|
19332
|
+
function errorOptions(config, url) {
|
|
19333
|
+
let mode = DefaultExtendedJsonMode;
|
|
19334
|
+
try {
|
|
19335
|
+
mode = parseExtendedJsonMode(url.searchParams.get("extendedJson")) ?? DefaultExtendedJsonMode;
|
|
19336
|
+
} catch {
|
|
19337
|
+
}
|
|
19338
|
+
return { exposeInternal: config.boolean(ConfigKeys.ErrorsExposeInternal), currentIn: (document) => documentToJson(document, mode) };
|
|
19339
|
+
}
|
|
18897
19340
|
function createApp(context) {
|
|
18898
19341
|
const app = new H3({
|
|
18899
19342
|
// errors are answered and logged (5xx) by toErrorResponse
|
|
18900
19343
|
silent: true,
|
|
18901
|
-
onError: (error) => toErrorResponse(error, errorLogger(context.logger),
|
|
19344
|
+
onError: (error, event) => toErrorResponse(error, errorLogger(context.logger), errorOptions(context.config, event.url))
|
|
18902
19345
|
});
|
|
18903
19346
|
app.use((event) => {
|
|
18904
19347
|
event.context.mongocampBodyMaxBytes = context.config.number(ConfigKeys.BodyMaxBytes);
|
|
@@ -19009,7 +19452,7 @@ async function createMongocampServer(options = {}) {
|
|
|
19009
19452
|
try {
|
|
19010
19453
|
response = await app.fetch(request);
|
|
19011
19454
|
} catch (error) {
|
|
19012
|
-
response = toErrorResponse(error, errorLogger(logger),
|
|
19455
|
+
response = toErrorResponse(error, errorLogger(logger), errorOptions(config, new URL(request.url)));
|
|
19013
19456
|
}
|
|
19014
19457
|
requestEvents.completed(start, response);
|
|
19015
19458
|
if (fetchOptions.log) {
|