@sfxcode/mongocamp-server-core 2.7.1 → 2.8.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 +78 -13
- package/dist/index.mjs +216 -72
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -295,12 +295,19 @@ declare class AuthorizedUser {
|
|
|
295
295
|
* behaviours (owner, timestamps, versioned, audit), the read scopes and the events see this user.
|
|
296
296
|
*/
|
|
297
297
|
readonly actingFor?: AuthorizedUser;
|
|
298
|
-
|
|
298
|
+
/**
|
|
299
|
+
* The request asks to keep the change fields it sends (2.8.0, header `X-MONGOCAMP-KEEP-TIMESTAMPS`); only for administrators, and only
|
|
300
|
+
* on collections whose `timestamps` allow it (`preserveOnUpdate`).
|
|
301
|
+
*/
|
|
302
|
+
readonly keepTimestamps: boolean;
|
|
303
|
+
constructor(user: UserInformation, roles: Role[], actingFor?: AuthorizedUser, keepTimestamps?: boolean);
|
|
299
304
|
get userId(): string;
|
|
300
305
|
/** The user the request acts for: the one of `X-AUTH-ACT-AS`, else the logged in user itself. */
|
|
301
306
|
get acting(): AuthorizedUser;
|
|
302
307
|
/** This user acting for another one (2.7.0). */
|
|
303
308
|
actingAs(other: AuthorizedUser): AuthorizedUser;
|
|
309
|
+
/** This user asking to keep the sent change fields (2.8.0); has no effect for a user who is no administrator. */
|
|
310
|
+
keepingTimestamps(): AuthorizedUser;
|
|
304
311
|
/** Collection grants, and the bucket meta grants as grants for the `.files` collection of the bucket. */
|
|
305
312
|
get collectionGrants(): Grant[];
|
|
306
313
|
get bucketGrants(): Grant[];
|
|
@@ -431,6 +438,8 @@ interface LoginResult {
|
|
|
431
438
|
* rights stay the administrator's. Refused (403) for every caller that is no administrator, 401 for a user that does not exist.
|
|
432
439
|
*/
|
|
433
440
|
declare const ActAsHeader = "X-AUTH-ACT-AS";
|
|
441
|
+
/** 2.8.0: an administrator's write keeps the `updatedAt` / `updatedBy` it sends where `timestamps.preserveOnUpdate` allows it. */
|
|
442
|
+
declare const KeepTimestampsHeader = "X-MONGOCAMP-KEEP-TIMESTAMPS";
|
|
434
443
|
declare class AuthService {
|
|
435
444
|
private readonly config;
|
|
436
445
|
private readonly version;
|
|
@@ -516,6 +525,12 @@ interface TimestampsOptions {
|
|
|
516
525
|
* Default false.
|
|
517
526
|
*/
|
|
518
527
|
preserveOnInsert?: boolean;
|
|
528
|
+
/**
|
|
529
|
+
* An update or replace by an administrator — also one acting for a user — keeps the `updatedAt` / `updatedBy` it sends (2.8.0; scripts
|
|
530
|
+
* that mark their writes or keep the change time of a document); missing ones are written as usual. With `versioned` in mode
|
|
531
|
+
* `timestamp` a sent `updatedAt` is also the expected version, so such a write is checked and does not advance the version. Default false.
|
|
532
|
+
*/
|
|
533
|
+
preserveOnUpdate?: boolean;
|
|
519
534
|
}
|
|
520
535
|
/** The documents a user may read when the read rule is a function: a filter combined with every read (it can only narrow). */
|
|
521
536
|
type ReadScope = (context: {
|
|
@@ -570,6 +585,7 @@ interface ResolvedBehaviours {
|
|
|
570
585
|
createdBy?: string;
|
|
571
586
|
updatedBy?: string;
|
|
572
587
|
preserveOnInsert?: boolean;
|
|
588
|
+
preserveOnUpdate?: boolean;
|
|
573
589
|
};
|
|
574
590
|
owner?: {
|
|
575
591
|
field: string;
|
|
@@ -1073,6 +1089,11 @@ interface components {
|
|
|
1073
1089
|
count: number;
|
|
1074
1090
|
/** Format: int32 */
|
|
1075
1091
|
indexes: number;
|
|
1092
|
+
/**
|
|
1093
|
+
* Format: int32
|
|
1094
|
+
* @description 2.8.0: own indexes of a declaration (mongocamp_idx_*) that were not copied, because the target is not declared (no index sync would manage them there)
|
|
1095
|
+
*/
|
|
1096
|
+
skippedIndexes?: number;
|
|
1076
1097
|
};
|
|
1077
1098
|
/** CountResponse */
|
|
1078
1099
|
CountResponse: {
|
|
@@ -1343,6 +1364,15 @@ interface components {
|
|
|
1343
1364
|
configType: string;
|
|
1344
1365
|
comment: string;
|
|
1345
1366
|
needsRestartForActivation: boolean;
|
|
1367
|
+
/**
|
|
1368
|
+
* @description 2.8.0: where the active value comes from — env, an option of the server, an administrator's update (patched), a value stored without update (stored, e.g. the default an older server wrote at the first start), or the default
|
|
1369
|
+
* @enum {string}
|
|
1370
|
+
*/
|
|
1371
|
+
source?: "env" | "option" | "patched" | "stored" | "default";
|
|
1372
|
+
/** @description 2.8.0: the current default in the form of value; left out for a generated default (AUTH_SECRET) */
|
|
1373
|
+
defaultValue?: unknown;
|
|
1374
|
+
/** @description 2.8.0: value is the current default */
|
|
1375
|
+
isDefault?: boolean;
|
|
1346
1376
|
};
|
|
1347
1377
|
/** MongoFindRequest */
|
|
1348
1378
|
MongoFindRequest: {
|
|
@@ -1659,6 +1689,13 @@ interface components {
|
|
|
1659
1689
|
version: string;
|
|
1660
1690
|
/** Format: date-time */
|
|
1661
1691
|
builtAt: string;
|
|
1692
|
+
/** @description 2.8.0: the package of the server core that runs (name and version of the application above may differ) */
|
|
1693
|
+
core?: components["schemas"]["CoreVersion"];
|
|
1694
|
+
};
|
|
1695
|
+
/** CoreVersion */
|
|
1696
|
+
CoreVersion: {
|
|
1697
|
+
name: string;
|
|
1698
|
+
version: string;
|
|
1662
1699
|
};
|
|
1663
1700
|
};
|
|
1664
1701
|
responses: never;
|
|
@@ -1887,32 +1924,45 @@ declare class EventBus {
|
|
|
1887
1924
|
* Differences to the Scala server: an env (or programmatic) value wins without being written into the collection (the Scala server
|
|
1888
1925
|
* replaced the document with comment "updated by env"), and an update is checked against the type of the configuration.
|
|
1889
1926
|
*/
|
|
1927
|
+
/**
|
|
1928
|
+
* 2.8.0: where the active value of a configuration comes from — the env, an option of `createMongocampServer`, an administrator's
|
|
1929
|
+
* update (`changedAt`), a value stored without update (written as the default by a first start, possibly by an older server), or the
|
|
1930
|
+
* default (nothing stored, or not persistent).
|
|
1931
|
+
*/
|
|
1932
|
+
type ConfigurationSource = 'env' | 'option' | 'patched' | 'stored' | 'default';
|
|
1890
1933
|
interface MongoCampConfiguration {
|
|
1891
1934
|
key: string;
|
|
1892
1935
|
value: unknown;
|
|
1893
1936
|
configType: string;
|
|
1894
1937
|
comment: string;
|
|
1895
1938
|
needsRestartForActivation: boolean;
|
|
1939
|
+
/** 2.8.0 */
|
|
1940
|
+
source: ConfigurationSource;
|
|
1941
|
+
/** 2.8.0: the current default in the form of `value`; left out for a generated default (`AUTH_SECRET`). */
|
|
1942
|
+
defaultValue?: unknown;
|
|
1943
|
+
/** 2.8.0: `value` is the current default (always true for a generated default that nobody changed). */
|
|
1944
|
+
isDefault: boolean;
|
|
1896
1945
|
}
|
|
1897
1946
|
declare class ConfigPersistence {
|
|
1898
1947
|
private readonly database;
|
|
1899
1948
|
private readonly config;
|
|
1900
1949
|
private readonly events?;
|
|
1950
|
+
private readonly logger?;
|
|
1901
1951
|
private timer;
|
|
1902
|
-
constructor(database: MongocampDatabase, config: ConfigStore, events?: EventBus | undefined);
|
|
1952
|
+
constructor(database: MongocampDatabase, config: ConfigStore, events?: EventBus | undefined, logger?: MongocampLogger | undefined);
|
|
1903
1953
|
get collection(): Collection;
|
|
1904
1954
|
private persistentDefinitions;
|
|
1905
1955
|
/** Registers the missing keys with their defaults (`registerConfig`) and reads the stored values; the refresh starts if wanted. */
|
|
1906
1956
|
initialize(refreshMillis?: number | false): Promise<void>;
|
|
1957
|
+
/** Replaces the stored old defaults of `LegacyDefaults` that nobody set (no `changedAt`, written since 2.6.0) by the current ones. */
|
|
1958
|
+
private upgradeLegacyDefaults;
|
|
1907
1959
|
/**
|
|
1908
|
-
* 2.
|
|
1909
|
-
*
|
|
1910
|
-
* administrator who wants 401 patches it again (then it is marked and stays).
|
|
1911
|
-
*
|
|
1912
|
-
* 2.7.1: the same for an old default of `CORS_HEADERS_EXPOSED` (see `LegacyCorsHeadersExposed`). Without `x-pagination-next` a browser
|
|
1913
|
-
* cannot read the cursor, and a cursor read (nuxt-ui-mongocamp `fetchAllDocuments`) ends after the first page without saying so.
|
|
1960
|
+
* 2.8.0: the keys whose stored value nobody set (no `changedAt`) and that differ from the current default — written as the default by
|
|
1961
|
+
* an older server at the first start, or set before 2.6.0. An env or option override hides the stored value, so it is not listed.
|
|
1914
1962
|
*/
|
|
1915
|
-
|
|
1963
|
+
unmarkedNonDefaults(): Promise<string[]>;
|
|
1964
|
+
/** 2.8.0: one warning at the start, keys only (values can be secret). */
|
|
1965
|
+
private warnUnmarkedNonDefaults;
|
|
1916
1966
|
/** Reads the stored values; at startup also the keys that need a restart, later only the ones that are active at once. */
|
|
1917
1967
|
refresh(startup: boolean): Promise<void>;
|
|
1918
1968
|
/** A configuration as answered by the API: the stored one, the one of the env, or a non persistent one. */
|
|
@@ -1960,6 +2010,11 @@ interface InterceptorBase {
|
|
|
1960
2010
|
* ones of the user it acts for.
|
|
1961
2011
|
*/
|
|
1962
2012
|
actedBy?: UserInformation;
|
|
2013
|
+
/**
|
|
2014
|
+
* An administrator asked to keep the `updatedAt` / `updatedBy` it sends (2.8.0, header `X-MONGOCAMP-KEEP-TIMESTAMPS`, or the option
|
|
2015
|
+
* `keepTimestamps` of a server collection); honoured where `timestamps.preserveOnUpdate` is set.
|
|
2016
|
+
*/
|
|
2017
|
+
keepTimestamps?: true;
|
|
1963
2018
|
}
|
|
1964
2019
|
interface WriteInterceptorPayloads {
|
|
1965
2020
|
/** Documents to insert: one for `PUT …/documents`, all of the request for `insertMany`, one batch for an import. */
|
|
@@ -2373,6 +2428,11 @@ interface MongocampContext {
|
|
|
2373
2428
|
type ServerCollectionUser = string | AuthorizedUser | Request | 'system';
|
|
2374
2429
|
interface ServerCollectionOptions {
|
|
2375
2430
|
user: ServerCollectionUser;
|
|
2431
|
+
/**
|
|
2432
|
+
* Updates and replaces keep the `updatedAt` / `updatedBy` they send (2.8.0), where the collection's `timestamps.preserveOnUpdate`
|
|
2433
|
+
* allows it and the user is an administrator (or `'system'`). Like the header `X-MONGOCAMP-KEEP-TIMESTAMPS` of the API.
|
|
2434
|
+
*/
|
|
2435
|
+
keepTimestamps?: boolean;
|
|
2376
2436
|
}
|
|
2377
2437
|
interface ServerFindOptions {
|
|
2378
2438
|
/** A MongoDB filter, or a Lucene filter as text (`status:open AND qty:[1 TO 5]`). */
|
|
@@ -2515,6 +2575,11 @@ interface MongocampServer {
|
|
|
2515
2575
|
/** Creates and connects a MongoCamp server. */
|
|
2516
2576
|
declare function createMongocampServer(options?: MongocampServerOptions): Promise<MongocampServer>;
|
|
2517
2577
|
|
|
2578
|
+
declare const CoreVersion: {
|
|
2579
|
+
readonly name: "@sfxcode/mongocamp-server-core";
|
|
2580
|
+
readonly version: "2.8.0";
|
|
2581
|
+
};
|
|
2582
|
+
|
|
2518
2583
|
/** Error codes of the API (`mongocamp-library/.../exception/ErrorCodes.scala`), sent in `ErrorDescription.code` and `x-error-code`. */
|
|
2519
2584
|
declare const ErrorCodes: {
|
|
2520
2585
|
/** A request that could not be decoded (body, query or header with an invalid value). */
|
|
@@ -2874,7 +2939,7 @@ declare function stripDocument(document: Document$2, paths: readonly string[]):
|
|
|
2874
2939
|
* An update without the guarded paths: keys at or below a guarded path are removed; a `$set` of an object on a parent of a field of a
|
|
2875
2940
|
* behaviour is set field by field, without the guarded fields; other operators on such a parent are removed.
|
|
2876
2941
|
*/
|
|
2877
|
-
declare function stripUpdate(update: Document$2, guarded: readonly string[], system: readonly string[]): Document$2;
|
|
2942
|
+
declare function stripUpdate(update: Document$2, guarded: readonly string[], system: readonly string[], setOnly?: readonly string[]): Document$2;
|
|
2878
2943
|
|
|
2879
2944
|
/**
|
|
2880
2945
|
* The behaviour `softDelete` (2.3.0): a delete sets the deleted mark (`deletedAt`) instead of removing the document, every read hides
|
|
@@ -2947,9 +3012,9 @@ declare function stampInsert(document: Document$2, timestamps: Timestamps, stamp
|
|
|
2947
3012
|
* Sets the change fields of a replacing document; the creation fields stay as stored (put back by the guard), a document without them
|
|
2948
3013
|
* (stored before the behaviour was switched on) gets the values of this write.
|
|
2949
3014
|
*/
|
|
2950
|
-
declare function stampReplace(document: Document$2, timestamps: Timestamps, stamp: WriteStamp): void;
|
|
3015
|
+
declare function stampReplace(document: Document$2, timestamps: Timestamps, stamp: WriteStamp, keepSent?: boolean): void;
|
|
2951
3016
|
/** An update with the change fields set (`$set` with dot paths, so the creation fields next to them stay). */
|
|
2952
|
-
declare function stampUpdate(update: Document$2, timestamps: Timestamps, stamp: WriteStamp): Document$2;
|
|
3017
|
+
declare function stampUpdate(update: Document$2, timestamps: Timestamps, stamp: WriteStamp, keepSent?: boolean): Document$2;
|
|
2953
3018
|
|
|
2954
|
-
export { ActAsHeader, AuditCollection, AuthService, AuthorizedUser, BehaviourDefaults, CleanUpTokenJob, CleanUpTokenJobClass, CollectionRegistry, ConfigKeys, ConfigPersistence, ConfigStore, ConfigurationError, DefaultRowsPerPage, DefaultValidationMode, DocumentService, ErrorCodes, EventBus, FilterDefaultField, HookPrefix, InfoCache, InternalErrorMessage, JobScheduler, LuceneQueryError, MaxExpands, MongocampDatabase, MongocampError, MongocampMetrics, OwnIndexPrefix, PaginationHeaders, SyncValidationLevel, SystemUser, TextMarker, WriteInterceptors, auditCollectionOf, auditRecords, bsonMarkerOptions, collections, combineScopes, configDefinitions, connectHooks, consoleLogger, convertFields, convertIdValue, createMongocampServer, createServerCollection, decodeAny, defineMongocampCollection, documentToJson, ensureAuditIndexes, filterParameter, forwardEventsToHooks, forwardInterceptorsToHooks, guardedPaths, luceneQueryToFilter, luceneToFilter, metrics, notDeleted, ownedBy, parseExtendedJsonMode, parseJson, parseLuceneQuery, pathIdFilter, purgeIndexName, readScope, refsOf, requestFields, requestLogging, resolveBehaviours, resolveIndexes, resolveRefs, restoreUpdate, sameValidator, stampInsert, stampReplace, stampUpdate, stringifyJson, stripDocument, stripUpdate, syncIndexes, syncPurgeIndex, syncValidator, systemFields, toErrorResponse, toMongoJsonSchema, validatorOf, versionInDocument, versionInUpdate, withDeletedOf, withIncrement, withSystemFields, withVersion };
|
|
3019
|
+
export { ActAsHeader, AuditCollection, AuthService, AuthorizedUser, BehaviourDefaults, CleanUpTokenJob, CleanUpTokenJobClass, CollectionRegistry, ConfigKeys, ConfigPersistence, ConfigStore, ConfigurationError, CoreVersion, DefaultRowsPerPage, DefaultValidationMode, DocumentService, ErrorCodes, EventBus, FilterDefaultField, HookPrefix, InfoCache, InternalErrorMessage, JobScheduler, KeepTimestampsHeader, LuceneQueryError, MaxExpands, MongocampDatabase, MongocampError, MongocampMetrics, OwnIndexPrefix, PaginationHeaders, SyncValidationLevel, SystemUser, TextMarker, WriteInterceptors, auditCollectionOf, auditRecords, bsonMarkerOptions, collections, combineScopes, configDefinitions, connectHooks, consoleLogger, convertFields, convertIdValue, createMongocampServer, createServerCollection, decodeAny, defineMongocampCollection, documentToJson, ensureAuditIndexes, filterParameter, forwardEventsToHooks, forwardInterceptorsToHooks, guardedPaths, luceneQueryToFilter, luceneToFilter, metrics, notDeleted, ownedBy, parseExtendedJsonMode, parseJson, parseLuceneQuery, pathIdFilter, purgeIndexName, readScope, refsOf, requestFields, requestLogging, resolveBehaviours, resolveIndexes, resolveRefs, restoreUpdate, sameValidator, stampInsert, stampReplace, stampUpdate, stringifyJson, stripDocument, stripUpdate, syncIndexes, syncPurgeIndex, syncValidator, systemFields, toErrorResponse, toMongoJsonSchema, validatorOf, versionInDocument, versionInUpdate, withDeletedOf, withIncrement, withSystemFields, withVersion };
|
|
2955
3020
|
export type { AuditOperation, AuditOptions, AuditRecord, BehaviourFlags, ConfigDefinition, ConfigKey, ConfigType, ConversionResult, ConvertOptions, DeclaredCollection, ErrorDescription, ErrorResponseOptions, EventListener, EventName, EventTarget, ExpandedDocument, ExtendedJsonMode, FetchOptions, Grant, HookSystem, IndexDeclaration, IndexDirection, IndexOptions, IndexSyncResult, InferDocument, InferDocumentInput, InferRefs, InterceptorBase, InterceptorName, InterceptorStage, InterceptorTarget, JobConfig, JobHandler, JobInformation, JobRun, LuceneQuery, MongocampCollectionDefinition, MongocampContext, MongocampEvent, MongocampEvents, MongocampFeature, MongocampHooks, MongocampLogger, MongocampRequestFields, MongocampServer, MongocampServerOptions, OwnerOptions, PaginationInfo, Paging, ReadOperation, ReadScope, RefDeclaration, RefTargets, RequestLog, ResolvedBehaviours, ResolvedIndex, ResolvedRef, Role, ScopeOptions, ServerCollection, ServerCollectionOptions, ServerCollectionUser, ServerDocumentIdentity, ServerFindOptions, ServerPage, SoftDeleteOptions, SystemFields, SystemInfo, TimestampsOptions, UserInformation, ValidationIssue, ValidationMode, ValidatorSyncAction, ValidatorSyncResult, VersionInfo, VersionedOptions, WriteInterceptor, WriteInterceptorPayloads, WriteStamp };
|
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,7 @@ function mergeGrants(roles) {
|
|
|
37
37
|
return [...merged.values()].sort((a, b) => a.name.localeCompare(b.name) || a.grantType.localeCompare(b.grantType));
|
|
38
38
|
}
|
|
39
39
|
class AuthorizedUser {
|
|
40
|
-
constructor(user, roles, actingFor) {
|
|
40
|
+
constructor(user, roles, actingFor, keepTimestamps = false) {
|
|
41
41
|
this.user = user;
|
|
42
42
|
this.roles = roles;
|
|
43
43
|
this.grants = mergeGrants(roles);
|
|
@@ -45,6 +45,7 @@ class AuthorizedUser {
|
|
|
45
45
|
if (actingFor !== void 0) {
|
|
46
46
|
this.actingFor = actingFor;
|
|
47
47
|
}
|
|
48
|
+
this.keepTimestamps = keepTimestamps;
|
|
48
49
|
}
|
|
49
50
|
grants;
|
|
50
51
|
isAdmin;
|
|
@@ -53,6 +54,11 @@ class AuthorizedUser {
|
|
|
53
54
|
* behaviours (owner, timestamps, versioned, audit), the read scopes and the events see this user.
|
|
54
55
|
*/
|
|
55
56
|
actingFor;
|
|
57
|
+
/**
|
|
58
|
+
* The request asks to keep the change fields it sends (2.8.0, header `X-MONGOCAMP-KEEP-TIMESTAMPS`); only for administrators, and only
|
|
59
|
+
* on collections whose `timestamps` allow it (`preserveOnUpdate`).
|
|
60
|
+
*/
|
|
61
|
+
keepTimestamps;
|
|
56
62
|
get userId() {
|
|
57
63
|
return this.user.userId;
|
|
58
64
|
}
|
|
@@ -62,7 +68,11 @@ class AuthorizedUser {
|
|
|
62
68
|
}
|
|
63
69
|
/** This user acting for another one (2.7.0). */
|
|
64
70
|
actingAs(other) {
|
|
65
|
-
return new AuthorizedUser(this.user, this.roles, other);
|
|
71
|
+
return new AuthorizedUser(this.user, this.roles, other, this.keepTimestamps);
|
|
72
|
+
}
|
|
73
|
+
/** This user asking to keep the sent change fields (2.8.0); has no effect for a user who is no administrator. */
|
|
74
|
+
keepingTimestamps() {
|
|
75
|
+
return new AuthorizedUser(this.user, this.roles, this.actingFor, this.isAdmin);
|
|
66
76
|
}
|
|
67
77
|
/** Collection grants, and the bucket meta grants as grants for the `.files` collection of the bucket. */
|
|
68
78
|
get collectionGrants() {
|
|
@@ -108,7 +118,7 @@ function actingUser(user) {
|
|
|
108
118
|
return user.actingFor === void 0 ? { user: user.user } : { user: user.actingFor.user, actedBy: user.user };
|
|
109
119
|
}
|
|
110
120
|
function actingIdentity(user) {
|
|
111
|
-
return { ...actingUser(user), isAdmin: user.acting.isAdmin };
|
|
121
|
+
return { ...actingUser(user), isAdmin: user.acting.isAdmin, ...user.keepTimestamps ? { keepTimestamps: true } : {} };
|
|
112
122
|
}
|
|
113
123
|
function toUserProfile(user, roles) {
|
|
114
124
|
return {
|
|
@@ -1598,6 +1608,7 @@ class TokenCache {
|
|
|
1598
1608
|
|
|
1599
1609
|
const ApiKeyHeader = "X-AUTH-APIKEY";
|
|
1600
1610
|
const ActAsHeader = "X-AUTH-ACT-AS";
|
|
1611
|
+
const KeepTimestampsHeader = "X-MONGOCAMP-KEEP-TIMESTAMPS";
|
|
1601
1612
|
function readCredentials(request) {
|
|
1602
1613
|
const credentials = {};
|
|
1603
1614
|
const authorization = request.headers.get("authorization")?.trim();
|
|
@@ -1691,7 +1702,9 @@ class AuthService {
|
|
|
1691
1702
|
async authenticate(request) {
|
|
1692
1703
|
const user = await this.authenticateUser(readCredentials(request));
|
|
1693
1704
|
this.requestUsers.set(request, user.userId);
|
|
1694
|
-
const
|
|
1705
|
+
const roles = await this.holder.findRoles(user.roles);
|
|
1706
|
+
const keep = request.headers.get(KeepTimestampsHeader)?.trim().toLowerCase() === "true";
|
|
1707
|
+
const authorized = keep ? new AuthorizedUser(user, roles).keepingTimestamps() : new AuthorizedUser(user, roles);
|
|
1695
1708
|
const actAs = request.headers.get(ActAsHeader)?.trim();
|
|
1696
1709
|
if (actAs === void 0 || actAs === "") {
|
|
1697
1710
|
return authorized;
|
|
@@ -1973,6 +1986,19 @@ const LegacyCorsHeadersExposed = [
|
|
|
1973
1986
|
["Content-Type", "x-pagination-rows-per-page", "x-pagination-current-page", "x-pagination-count-rows", "x-pagination-count-pages", "x-request-id"],
|
|
1974
1987
|
["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"]
|
|
1975
1988
|
];
|
|
1989
|
+
const LegacyAggregationStagesDenied = [
|
|
1990
|
+
["$function", "$accumulator", "$where", "$out", "$merge", "$currentOp", "$listSessions"]
|
|
1991
|
+
];
|
|
1992
|
+
const LegacyDefaults = [
|
|
1993
|
+
// a database created before 2.2.0 kept answering 401 for a missing grant
|
|
1994
|
+
{ key: ConfigKeys.AuthGrantDeniedStatus, since: "2.6.0", values: [401] },
|
|
1995
|
+
// without x-pagination-next a browser cannot read the cursor, and a cursor read ends after the first page without saying so
|
|
1996
|
+
{ key: ConfigKeys.CorsHeadersExposed, since: "2.7.1", values: LegacyCorsHeadersExposed },
|
|
1997
|
+
// the Scala server allowed $collStats and $indexStats
|
|
1998
|
+
{ key: ConfigKeys.AggregationStagesDenied, since: "2.7.2", values: LegacyAggregationStagesDenied },
|
|
1999
|
+
// the Scala server served the API reference by default
|
|
2000
|
+
{ key: ConfigKeys.DocsSwagger, since: "2.7.2", values: [true] }
|
|
2001
|
+
];
|
|
1976
2002
|
const RefreshIntervalMillis = 6e4;
|
|
1977
2003
|
function plainNumber(value) {
|
|
1978
2004
|
if (typeof value === "number") {
|
|
@@ -2035,10 +2061,11 @@ function valueForUpdate(definition, value) {
|
|
|
2035
2061
|
return converted;
|
|
2036
2062
|
}
|
|
2037
2063
|
class ConfigPersistence {
|
|
2038
|
-
constructor(database, config, events) {
|
|
2064
|
+
constructor(database, config, events, logger) {
|
|
2039
2065
|
this.database = database;
|
|
2040
2066
|
this.config = config;
|
|
2041
2067
|
this.events = events;
|
|
2068
|
+
this.logger = logger;
|
|
2042
2069
|
}
|
|
2043
2070
|
timer;
|
|
2044
2071
|
get collection() {
|
|
@@ -2062,6 +2089,7 @@ class ConfigPersistence {
|
|
|
2062
2089
|
await this.collection.updateOne({ key: definition.key }, { $setOnInsert: document }, { upsert: true });
|
|
2063
2090
|
}
|
|
2064
2091
|
await this.upgradeLegacyDefaults();
|
|
2092
|
+
await this.warnUnmarkedNonDefaults();
|
|
2065
2093
|
await this.refresh(true);
|
|
2066
2094
|
if (refreshMillis !== false) {
|
|
2067
2095
|
this.timer = setInterval(() => {
|
|
@@ -2070,24 +2098,36 @@ class ConfigPersistence {
|
|
|
2070
2098
|
this.timer.unref?.();
|
|
2071
2099
|
}
|
|
2072
2100
|
}
|
|
2073
|
-
/**
|
|
2074
|
-
* 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
|
|
2075
|
-
* 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
|
|
2076
|
-
* administrator who wants 401 patches it again (then it is marked and stays).
|
|
2077
|
-
*
|
|
2078
|
-
* 2.7.1: the same for an old default of `CORS_HEADERS_EXPOSED` (see `LegacyCorsHeadersExposed`). Without `x-pagination-next` a browser
|
|
2079
|
-
* cannot read the cursor, and a cursor read (nuxt-ui-mongocamp `fetchAllDocuments`) ends after the first page without saying so.
|
|
2080
|
-
*/
|
|
2101
|
+
/** Replaces the stored old defaults of `LegacyDefaults` that nobody set (no `changedAt`, written since 2.6.0) by the current ones. */
|
|
2081
2102
|
async upgradeLegacyDefaults() {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2103
|
+
for (const { key, values } of LegacyDefaults) {
|
|
2104
|
+
const definition = this.config.definition(key);
|
|
2105
|
+
if (!definition) {
|
|
2106
|
+
continue;
|
|
2107
|
+
}
|
|
2085
2108
|
await this.collection.updateOne(
|
|
2086
|
-
{ key
|
|
2087
|
-
{ $set: { value: toStored(
|
|
2109
|
+
{ key, value: { $in: values }, changedAt: { $exists: false } },
|
|
2110
|
+
{ $set: { value: toStored(definition.type, defaultOf(definition)) } }
|
|
2088
2111
|
);
|
|
2089
2112
|
}
|
|
2090
2113
|
}
|
|
2114
|
+
/**
|
|
2115
|
+
* 2.8.0: the keys whose stored value nobody set (no `changedAt`) and that differ from the current default — written as the default by
|
|
2116
|
+
* an older server at the first start, or set before 2.6.0. An env or option override hides the stored value, so it is not listed.
|
|
2117
|
+
*/
|
|
2118
|
+
async unmarkedNonDefaults() {
|
|
2119
|
+
return (await this.list()).filter((entry) => entry.source === "stored" && !entry.isDefault).map((entry) => entry.key);
|
|
2120
|
+
}
|
|
2121
|
+
/** 2.8.0: one warning at the start, keys only (values can be secret). */
|
|
2122
|
+
async warnUnmarkedNonDefaults() {
|
|
2123
|
+
if (!this.logger) {
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
const keys = await this.unmarkedNonDefaults();
|
|
2127
|
+
if (keys.length > 0) {
|
|
2128
|
+
this.logger.warn(`[mongocamp] stored configurations that nobody changed differ from the current default (an old default or a value set before 2.6.0): ${keys.join(", ")}. Check GET /system/configurations (isDefault: false), reset with DELETE /system/configurations/{key} or patch to keep.`);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2091
2131
|
/** Reads the stored values; at startup also the keys that need a restart, later only the ones that are active at once. */
|
|
2092
2132
|
async refresh(startup) {
|
|
2093
2133
|
const documents = await this.collection.find({}).toArray();
|
|
@@ -2112,15 +2152,23 @@ class ConfigPersistence {
|
|
|
2112
2152
|
const converted = fromStored(definition.type, stored.value);
|
|
2113
2153
|
value = converted === void 0 ? stored.value ?? null : toStored(definition.type, converted);
|
|
2114
2154
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2155
|
+
const source = override === "env" ? "env" : override === "programmatic" ? "option" : !definition.persistent || !stored ? "default" : stored.changedAt !== void 0 ? "patched" : "stored";
|
|
2156
|
+
const generated = typeof definition.defaultValue === "function";
|
|
2157
|
+
let defaultValue = generated ? void 0 : toStored(definition.type, definition.defaultValue);
|
|
2158
|
+
const isDefault = generated ? source === "stored" || source === "default" : sameStoredValue(value, defaultValue);
|
|
2159
|
+
if (SecretKeys.has(definition.key)) {
|
|
2160
|
+
value = masked(value);
|
|
2161
|
+
defaultValue = masked(defaultValue);
|
|
2117
2162
|
}
|
|
2118
2163
|
return {
|
|
2119
2164
|
key: definition.key,
|
|
2120
2165
|
value,
|
|
2121
2166
|
configType: definition.type,
|
|
2122
2167
|
comment: override === "env" ? EnvComment : String(stored?.comment ?? ""),
|
|
2123
|
-
needsRestartForActivation: definition.needsRestartForActivation
|
|
2168
|
+
needsRestartForActivation: definition.needsRestartForActivation,
|
|
2169
|
+
source,
|
|
2170
|
+
...generated ? {} : { defaultValue },
|
|
2171
|
+
isDefault
|
|
2124
2172
|
};
|
|
2125
2173
|
}
|
|
2126
2174
|
/** All configurations sorted by key (`getAllRegisteredConfigurations`). */
|
|
@@ -2182,6 +2230,20 @@ class ConfigPersistence {
|
|
|
2182
2230
|
}
|
|
2183
2231
|
}
|
|
2184
2232
|
}
|
|
2233
|
+
function masked(value) {
|
|
2234
|
+
return value !== null && value !== void 0 && value !== "" ? SecretMask : value;
|
|
2235
|
+
}
|
|
2236
|
+
function sameStoredValue(a, b) {
|
|
2237
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2238
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((entry, index) => sameStoredValue(entry, b[index]));
|
|
2239
|
+
}
|
|
2240
|
+
const numberA = plainNumber(a);
|
|
2241
|
+
const numberB = plainNumber(b);
|
|
2242
|
+
if (numberA !== void 0 || numberB !== void 0) {
|
|
2243
|
+
return numberA === numberB;
|
|
2244
|
+
}
|
|
2245
|
+
return (a ?? null) === (b ?? null);
|
|
2246
|
+
}
|
|
2185
2247
|
function defaultOf(definition) {
|
|
2186
2248
|
return typeof definition.defaultValue === "function" ? definition.defaultValue() : definition.defaultValue;
|
|
2187
2249
|
}
|
|
@@ -2863,7 +2925,7 @@ const BehaviourDefaults = {
|
|
|
2863
2925
|
auditRetentionDays: 365
|
|
2864
2926
|
};
|
|
2865
2927
|
const optionKeys = {
|
|
2866
|
-
timestamps: ["createdAt", "updatedAt", "createdBy", "updatedBy", "preserveOnInsert"],
|
|
2928
|
+
timestamps: ["createdAt", "updatedAt", "createdBy", "updatedBy", "preserveOnInsert", "preserveOnUpdate"],
|
|
2867
2929
|
owner: ["field", "read", "adminBypass", "preserveOnInsert"],
|
|
2868
2930
|
softDelete: ["field", "purgeAfterDays"],
|
|
2869
2931
|
versioned: ["mode", "field", "required"],
|
|
@@ -2920,12 +2982,14 @@ function resolveBehaviours(flags) {
|
|
|
2920
2982
|
...timestamps.createdBy !== void 0 ? { createdBy: field(timestamps.createdBy, BehaviourDefaults.createdBy, "timestamps.createdBy") } : {},
|
|
2921
2983
|
...timestamps.updatedBy !== void 0 ? { updatedBy: field(timestamps.updatedBy, BehaviourDefaults.updatedBy, "timestamps.updatedBy") } : {}
|
|
2922
2984
|
};
|
|
2923
|
-
|
|
2924
|
-
if (
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2985
|
+
for (const flag of ["preserveOnInsert", "preserveOnUpdate"]) {
|
|
2986
|
+
if (timestamps[flag] !== void 0) {
|
|
2987
|
+
if (typeof timestamps[flag] !== "boolean") {
|
|
2988
|
+
throw new TypeError(`timestamps.${flag} must be true or false`);
|
|
2989
|
+
}
|
|
2990
|
+
if (timestamps[flag]) {
|
|
2991
|
+
resolved.timestamps[flag] = true;
|
|
2992
|
+
}
|
|
2929
2993
|
}
|
|
2930
2994
|
}
|
|
2931
2995
|
}
|
|
@@ -3005,6 +3069,12 @@ function byAdministrator(event) {
|
|
|
3005
3069
|
function preservesOnInsert(timestamps, event) {
|
|
3006
3070
|
return timestamps?.preserveOnInsert === true && byAdministrator(event);
|
|
3007
3071
|
}
|
|
3072
|
+
function preservesOnUpdate(timestamps, event) {
|
|
3073
|
+
return timestamps?.preserveOnUpdate === true && event.keepTimestamps === true && byAdministrator(event);
|
|
3074
|
+
}
|
|
3075
|
+
function changePaths(timestamps) {
|
|
3076
|
+
return [timestamps.updatedAt, timestamps.updatedBy].filter((path) => path !== void 0);
|
|
3077
|
+
}
|
|
3008
3078
|
function preservesOwnerOnInsert(owner, event) {
|
|
3009
3079
|
return owner?.preserveOnInsert === true && byAdministrator(event);
|
|
3010
3080
|
}
|
|
@@ -3658,7 +3728,7 @@ function flatten(value, prefix) {
|
|
|
3658
3728
|
return isPlainObject(entry) && Object.keys(entry).length > 0 ? flatten(entry, path) : [[path, entry]];
|
|
3659
3729
|
});
|
|
3660
3730
|
}
|
|
3661
|
-
function stripUpdate(update, guarded, system) {
|
|
3731
|
+
function stripUpdate(update, guarded, system, setOnly = []) {
|
|
3662
3732
|
const result = {};
|
|
3663
3733
|
for (const [operator, fields] of Object.entries(update)) {
|
|
3664
3734
|
if (!operator.startsWith("$") || !isPlainObject(fields)) {
|
|
@@ -3667,7 +3737,7 @@ function stripUpdate(update, guarded, system) {
|
|
|
3667
3737
|
}
|
|
3668
3738
|
const kept = {};
|
|
3669
3739
|
for (const [path, value] of Object.entries(fields)) {
|
|
3670
|
-
if (guarded.some((entry) => isAtOrBelow(path, entry))) {
|
|
3740
|
+
if (guarded.some((entry) => isAtOrBelow(path, entry)) || operator !== "$set" && setOnly.some((entry) => isAtOrBelow(path, entry))) {
|
|
3671
3741
|
continue;
|
|
3672
3742
|
}
|
|
3673
3743
|
const parentOfSystem = system.some((entry) => entry.startsWith(`${path}.`));
|
|
@@ -3717,7 +3787,9 @@ function registerGuard(context, own) {
|
|
|
3717
3787
|
return;
|
|
3718
3788
|
}
|
|
3719
3789
|
const stored = await collectionOf(context.database, event.collectionName).findOne(event.filter, { projection: Object.fromEntries(guard.all.map((path) => [path, 1])) });
|
|
3720
|
-
const
|
|
3790
|
+
const { timestamps } = guard.declared.behaviours;
|
|
3791
|
+
const kept = timestamps !== void 0 && preservesOnUpdate(timestamps, event) ? changePaths(timestamps).filter((path) => getPath(event.document, path) !== void 0) : [];
|
|
3792
|
+
const document = stripDocument(event.document, guard.all.filter((path) => !kept.includes(path)));
|
|
3721
3793
|
for (const path of guard.protected) {
|
|
3722
3794
|
const value = stored === null ? void 0 : getPath(stored, path);
|
|
3723
3795
|
if (value !== void 0) {
|
|
@@ -3725,7 +3797,7 @@ function registerGuard(context, own) {
|
|
|
3725
3797
|
}
|
|
3726
3798
|
}
|
|
3727
3799
|
if (stored !== null) {
|
|
3728
|
-
preservedSystemValues.set(event, guard.system.map((path) => [path, getPath(stored, path)]).filter(([, value]) => value !== void 0));
|
|
3800
|
+
preservedSystemValues.set(event, guard.system.filter((path) => !kept.includes(path)).map((path) => [path, getPath(stored, path)]).filter(([, value]) => value !== void 0));
|
|
3729
3801
|
}
|
|
3730
3802
|
event.document = document;
|
|
3731
3803
|
}, { stage: "guard" }),
|
|
@@ -3739,7 +3811,9 @@ function registerGuard(context, own) {
|
|
|
3739
3811
|
context.interceptors.on("document:beforeUpdate", (event) => {
|
|
3740
3812
|
const guard = guardedFor(event.collectionName);
|
|
3741
3813
|
if (guard !== void 0) {
|
|
3742
|
-
|
|
3814
|
+
const { timestamps } = guard.declared.behaviours;
|
|
3815
|
+
const kept = timestamps !== void 0 && preservesOnUpdate(timestamps, event) ? changePaths(timestamps) : [];
|
|
3816
|
+
event.update = stripUpdate(event.update, guard.all.filter((path) => !kept.includes(path)), guard.system, kept);
|
|
3743
3817
|
}
|
|
3744
3818
|
}, { stage: "guard" })
|
|
3745
3819
|
];
|
|
@@ -3898,22 +3972,26 @@ function stampInsert(document, timestamps, stamp, keepSent = false) {
|
|
|
3898
3972
|
write(timestamps.updatedBy, stamp.userId);
|
|
3899
3973
|
}
|
|
3900
3974
|
}
|
|
3901
|
-
function stampReplace(document, timestamps, stamp) {
|
|
3975
|
+
function stampReplace(document, timestamps, stamp, keepSent = false) {
|
|
3902
3976
|
if (getPath(document, timestamps.createdAt) === void 0) {
|
|
3903
3977
|
setPath(document, timestamps.createdAt, stamp.now);
|
|
3904
3978
|
}
|
|
3905
3979
|
if (timestamps.createdBy !== void 0 && getPath(document, timestamps.createdBy) === void 0) {
|
|
3906
3980
|
setPath(document, timestamps.createdBy, stamp.userId);
|
|
3907
3981
|
}
|
|
3908
|
-
|
|
3909
|
-
|
|
3982
|
+
if (!keepSent || getPath(document, timestamps.updatedAt) === void 0) {
|
|
3983
|
+
setPath(document, timestamps.updatedAt, stamp.now);
|
|
3984
|
+
}
|
|
3985
|
+
if (timestamps.updatedBy !== void 0 && (!keepSent || getPath(document, timestamps.updatedBy) === void 0)) {
|
|
3910
3986
|
setPath(document, timestamps.updatedBy, stamp.userId);
|
|
3911
3987
|
}
|
|
3912
3988
|
}
|
|
3913
|
-
function stampUpdate(update, timestamps, stamp) {
|
|
3989
|
+
function stampUpdate(update, timestamps, stamp, keepSent = false) {
|
|
3914
3990
|
const set = isPlainObject(update.$set) ? { ...update.$set } : {};
|
|
3915
|
-
set[timestamps.updatedAt]
|
|
3916
|
-
|
|
3991
|
+
if (!keepSent || set[timestamps.updatedAt] === void 0) {
|
|
3992
|
+
set[timestamps.updatedAt] = stamp.now;
|
|
3993
|
+
}
|
|
3994
|
+
if (timestamps.updatedBy !== void 0 && (!keepSent || set[timestamps.updatedBy] === void 0)) {
|
|
3917
3995
|
set[timestamps.updatedBy] = stamp.userId;
|
|
3918
3996
|
}
|
|
3919
3997
|
return { ...update, $set: set };
|
|
@@ -3938,13 +4016,13 @@ function registerTimestamps(context, own, clock = () => /* @__PURE__ */ new Date
|
|
|
3938
4016
|
context.interceptors.on("document:beforeReplace", (event) => {
|
|
3939
4017
|
const timestamps = timestampsFor(event.collectionName);
|
|
3940
4018
|
if (timestamps !== void 0) {
|
|
3941
|
-
stampReplace(event.document, timestamps, stampOf(event.user));
|
|
4019
|
+
stampReplace(event.document, timestamps, stampOf(event.user), preservesOnUpdate(timestamps, event));
|
|
3942
4020
|
}
|
|
3943
4021
|
}, { stage: "system" }),
|
|
3944
4022
|
context.interceptors.on("document:beforeUpdate", (event) => {
|
|
3945
4023
|
const timestamps = timestampsFor(event.collectionName);
|
|
3946
4024
|
if (timestamps !== void 0) {
|
|
3947
|
-
event.update = stampUpdate(event.update, timestamps, stampOf(event.user));
|
|
4025
|
+
event.update = stampUpdate(event.update, timestamps, stampOf(event.user), preservesOnUpdate(timestamps, event));
|
|
3948
4026
|
}
|
|
3949
4027
|
}, { stage: "system" })
|
|
3950
4028
|
];
|
|
@@ -6742,24 +6820,25 @@ function createServerCollection(context, name, options) {
|
|
|
6742
6820
|
const service = context.documents;
|
|
6743
6821
|
let resolved;
|
|
6744
6822
|
const user = () => {
|
|
6745
|
-
resolved ??= (
|
|
6746
|
-
const given = options.user;
|
|
6747
|
-
if (given === "system") {
|
|
6748
|
-
return SystemUser;
|
|
6749
|
-
}
|
|
6750
|
-
if (given instanceof AuthorizedUser) {
|
|
6751
|
-
return given;
|
|
6752
|
-
}
|
|
6753
|
-
if (given instanceof Request) {
|
|
6754
|
-
return context.auth.authenticate(given);
|
|
6755
|
-
}
|
|
6756
|
-
if (typeof given === "string" && given !== "") {
|
|
6757
|
-
return context.auth.authorizedUser(given);
|
|
6758
|
-
}
|
|
6759
|
-
throw MongocampError.unauthorized("the server collection needs a user (an id, a request or 'system')");
|
|
6760
|
-
})();
|
|
6823
|
+
resolved ??= resolveUser().then((authorized) => options.keepTimestamps === true ? authorized.keepingTimestamps() : authorized);
|
|
6761
6824
|
return resolved;
|
|
6762
6825
|
};
|
|
6826
|
+
const resolveUser = async () => {
|
|
6827
|
+
const given = options.user;
|
|
6828
|
+
if (given === "system") {
|
|
6829
|
+
return SystemUser;
|
|
6830
|
+
}
|
|
6831
|
+
if (given instanceof AuthorizedUser) {
|
|
6832
|
+
return given;
|
|
6833
|
+
}
|
|
6834
|
+
if (given instanceof Request) {
|
|
6835
|
+
return context.auth.authenticate(given);
|
|
6836
|
+
}
|
|
6837
|
+
if (typeof given === "string" && given !== "") {
|
|
6838
|
+
return context.auth.authorizedUser(given);
|
|
6839
|
+
}
|
|
6840
|
+
throw MongocampError.unauthorized("the server collection needs a user (an id, a request or 'system')");
|
|
6841
|
+
};
|
|
6763
6842
|
const filterOf = (filter) => {
|
|
6764
6843
|
if (filter === void 0) {
|
|
6765
6844
|
return {};
|
|
@@ -7859,8 +7938,9 @@ function registerBucketRoutes(app, context) {
|
|
|
7859
7938
|
});
|
|
7860
7939
|
}
|
|
7861
7940
|
|
|
7862
|
-
async function copyIndexes(source, target) {
|
|
7863
|
-
const
|
|
7941
|
+
async function copyIndexes(source, target, withOwnIndexes) {
|
|
7942
|
+
const all = (await source.listIndexes().toArray()).filter((index) => index.name !== "_id_");
|
|
7943
|
+
const indexes = withOwnIndexes ? all : all.filter((index) => !String(index.name).startsWith(OwnIndexPrefix));
|
|
7864
7944
|
if (indexes.length > 0) {
|
|
7865
7945
|
const specifications = indexes.map((index) => {
|
|
7866
7946
|
const { v: _version, ns: _namespace, ...specification } = index;
|
|
@@ -7868,9 +7948,9 @@ async function copyIndexes(source, target) {
|
|
|
7868
7948
|
});
|
|
7869
7949
|
await target.db.command({ createIndexes: target.collectionName, indexes: specifications });
|
|
7870
7950
|
}
|
|
7871
|
-
return indexes.length;
|
|
7951
|
+
return { indexes: indexes.length, skippedIndexes: all.length - indexes.length };
|
|
7872
7952
|
}
|
|
7873
|
-
async function copyCollection(database, source, target, filter, withIndexes, replaceTarget, temporaryPrefix) {
|
|
7953
|
+
async function copyCollection(database, source, target, filter, withIndexes, replaceTarget, temporaryPrefix, targetDeclared = false) {
|
|
7874
7954
|
const db = databaseOf(database, source);
|
|
7875
7955
|
const temporaryName = `${temporaryPrefix}copy_${randomUUID().replaceAll("-", "")}`;
|
|
7876
7956
|
try {
|
|
@@ -7880,9 +7960,9 @@ async function copyCollection(database, source, target, filter, withIndexes, rep
|
|
|
7880
7960
|
if (!(await collectionNames(db)).includes(temporaryName)) {
|
|
7881
7961
|
await db.createCollection(temporaryName);
|
|
7882
7962
|
}
|
|
7883
|
-
const
|
|
7963
|
+
const copied = withIndexes ? await copyIndexes(db.collection(source.name), db.collection(temporaryName), targetDeclared) : { indexes: 0, skippedIndexes: 0 };
|
|
7884
7964
|
await db.collection(temporaryName).rename(target.name, { dropTarget: replaceTarget });
|
|
7885
|
-
return { count: await db.collection(target.name).countDocuments(),
|
|
7965
|
+
return { count: await db.collection(target.name).countDocuments(), ...copied };
|
|
7886
7966
|
} finally {
|
|
7887
7967
|
if ((await collectionNames(db)).includes(temporaryName)) {
|
|
7888
7968
|
await db.collection(temporaryName).drop();
|
|
@@ -7890,7 +7970,7 @@ async function copyCollection(database, source, target, filter, withIndexes, rep
|
|
|
7890
7970
|
}
|
|
7891
7971
|
}
|
|
7892
7972
|
function copyResponse(target, result) {
|
|
7893
|
-
return { name: fullName(target), count: result.count, indexes: result.indexes };
|
|
7973
|
+
return { name: fullName(target), count: result.count, indexes: result.indexes, skippedIndexes: result.skippedIndexes };
|
|
7894
7974
|
}
|
|
7895
7975
|
|
|
7896
7976
|
const ValidationLevels = ["off", "moderate", "strict"];
|
|
@@ -8804,7 +8884,8 @@ function registerCollectionRoutes(app, context) {
|
|
|
8804
8884
|
}
|
|
8805
8885
|
const filter = bodyFilter(request.filter, filterOptions(queryParams(event), config, context.collections.refFields(context, collection)));
|
|
8806
8886
|
const targetExists = await checkTarget(user, target, request.dropTarget);
|
|
8807
|
-
const
|
|
8887
|
+
const targetDeclared = context.collections.resolve(context, fullName(target)) !== void 0;
|
|
8888
|
+
const result = await copyCollection(database, source, target, filter, request.withIndexes, targetExists, systemPrefix(), targetDeclared);
|
|
8808
8889
|
context.events.publish("collection:copy", { user: user.user, collectionName: fullName(source), newCollectionName: fullName(target) });
|
|
8809
8890
|
return jsonResponse(copyResponse(target, result));
|
|
8810
8891
|
});
|
|
@@ -14479,6 +14560,17 @@ paths:
|
|
|
14479
14560
|
required: true
|
|
14480
14561
|
schema:
|
|
14481
14562
|
type: string
|
|
14563
|
+
- name: extendedJson
|
|
14564
|
+
in: query
|
|
14565
|
+
description: '2.8.0 in the spec (read since 2.6.0): the mode of the document current of a version conflict (409, code 4092):
|
|
14566
|
+
relaxed (default) or canonical Extended JSON, or plain.'
|
|
14567
|
+
required: false
|
|
14568
|
+
schema:
|
|
14569
|
+
type: string
|
|
14570
|
+
enum:
|
|
14571
|
+
- relaxed
|
|
14572
|
+
- canonical
|
|
14573
|
+
- plain
|
|
14482
14574
|
requestBody:
|
|
14483
14575
|
content:
|
|
14484
14576
|
application/json:
|
|
@@ -14548,6 +14640,17 @@ paths:
|
|
|
14548
14640
|
required: true
|
|
14549
14641
|
schema:
|
|
14550
14642
|
type: string
|
|
14643
|
+
- name: extendedJson
|
|
14644
|
+
in: query
|
|
14645
|
+
description: '2.8.0 in the spec (read since 2.6.0): the mode of the document current of a version conflict (409, code 4092):
|
|
14646
|
+
relaxed (default) or canonical Extended JSON, or plain.'
|
|
14647
|
+
required: false
|
|
14648
|
+
schema:
|
|
14649
|
+
type: string
|
|
14650
|
+
enum:
|
|
14651
|
+
- relaxed
|
|
14652
|
+
- canonical
|
|
14653
|
+
- plain
|
|
14551
14654
|
requestBody:
|
|
14552
14655
|
content:
|
|
14553
14656
|
application/json:
|
|
@@ -16454,6 +16557,11 @@ components:
|
|
|
16454
16557
|
indexes:
|
|
16455
16558
|
type: integer
|
|
16456
16559
|
format: int32
|
|
16560
|
+
skippedIndexes:
|
|
16561
|
+
description: '2.8.0: own indexes of a declaration (mongocamp_idx_*) that were not copied, because the target is not
|
|
16562
|
+
declared (no index sync would manage them there)'
|
|
16563
|
+
type: integer
|
|
16564
|
+
format: int32
|
|
16457
16565
|
CountResponse:
|
|
16458
16566
|
title: CountResponse
|
|
16459
16567
|
type: object
|
|
@@ -17009,6 +17117,22 @@ components:
|
|
|
17009
17117
|
type: string
|
|
17010
17118
|
needsRestartForActivation:
|
|
17011
17119
|
type: boolean
|
|
17120
|
+
source:
|
|
17121
|
+
description: '2.8.0: where the active value comes from \u2014 env, an option of the server, an administrator''s
|
|
17122
|
+
update (patched), a value stored without update (stored, e.g. the default an older server wrote at the first
|
|
17123
|
+
start), or the default'
|
|
17124
|
+
type: string
|
|
17125
|
+
enum:
|
|
17126
|
+
- env
|
|
17127
|
+
- option
|
|
17128
|
+
- patched
|
|
17129
|
+
- stored
|
|
17130
|
+
- default
|
|
17131
|
+
defaultValue:
|
|
17132
|
+
description: '2.8.0: the current default in the form of value; left out for a generated default (AUTH_SECRET)'
|
|
17133
|
+
isDefault:
|
|
17134
|
+
description: '2.8.0: value is the current default'
|
|
17135
|
+
type: boolean
|
|
17012
17136
|
MongoFindRequest:
|
|
17013
17137
|
title: MongoFindRequest
|
|
17014
17138
|
type: object
|
|
@@ -17668,6 +17792,20 @@ components:
|
|
|
17668
17792
|
builtAt:
|
|
17669
17793
|
type: string
|
|
17670
17794
|
format: date-time
|
|
17795
|
+
core:
|
|
17796
|
+
description: '2.8.0: the package of the server core that runs (name and version of the application above may differ)'
|
|
17797
|
+
$ref: '#/components/schemas/CoreVersion'
|
|
17798
|
+
CoreVersion:
|
|
17799
|
+
title: CoreVersion
|
|
17800
|
+
type: object
|
|
17801
|
+
required:
|
|
17802
|
+
- name
|
|
17803
|
+
- version
|
|
17804
|
+
properties:
|
|
17805
|
+
name:
|
|
17806
|
+
type: string
|
|
17807
|
+
version:
|
|
17808
|
+
type: string
|
|
17671
17809
|
securitySchemes:
|
|
17672
17810
|
apiKeyAuth:
|
|
17673
17811
|
type: apiKey
|
|
@@ -18547,14 +18685,17 @@ function registerIndexRoutes(app, context) {
|
|
|
18547
18685
|
const collection = await administrated(event);
|
|
18548
18686
|
return jsonResponse((await collection.listIndexes().toArray()).map(indexInfo));
|
|
18549
18687
|
});
|
|
18550
|
-
|
|
18688
|
+
const existingIndex = async (event) => {
|
|
18551
18689
|
const collection = await administrated(event);
|
|
18552
18690
|
const name = pathParam(event, "indexName");
|
|
18553
18691
|
const index = (await collection.listIndexes().toArray()).find((entry) => entry.name === name);
|
|
18554
18692
|
if (!index) {
|
|
18555
18693
|
throw MongocampError.notFound(`index not found with name [${name}]`, 27);
|
|
18556
18694
|
}
|
|
18557
|
-
return
|
|
18695
|
+
return { collection, name, index };
|
|
18696
|
+
};
|
|
18697
|
+
app.get(`${base}/:indexName`, async (event) => {
|
|
18698
|
+
return jsonResponse(mongoIndex((await existingIndex(event)).index));
|
|
18558
18699
|
});
|
|
18559
18700
|
app.put(base, async (event) => {
|
|
18560
18701
|
const collection = await administrated(event);
|
|
@@ -18588,8 +18729,8 @@ function registerIndexRoutes(app, context) {
|
|
|
18588
18729
|
return created(await collection.createIndex({ [pathParam(event, "fieldName")]: "text" }, options));
|
|
18589
18730
|
});
|
|
18590
18731
|
app.delete(`${base}/:indexName`, async (event) => {
|
|
18591
|
-
const collection = await
|
|
18592
|
-
await collection.dropIndex(
|
|
18732
|
+
const { collection, name } = await existingIndex(event);
|
|
18733
|
+
await collection.dropIndex(name);
|
|
18593
18734
|
return jsonResponse({ dropped: true });
|
|
18594
18735
|
});
|
|
18595
18736
|
}
|
|
@@ -19021,11 +19162,14 @@ function metrics() {
|
|
|
19021
19162
|
};
|
|
19022
19163
|
}
|
|
19023
19164
|
|
|
19165
|
+
const CoreVersion = { name: "@sfxcode/mongocamp-server-core", version: "2.8.0" };
|
|
19166
|
+
|
|
19024
19167
|
function registerInformationRoutes(app, context) {
|
|
19025
19168
|
app.get("/version", () => jsonResponse({
|
|
19026
19169
|
name: context.version.name,
|
|
19027
19170
|
version: context.version.version,
|
|
19028
|
-
builtAt: instantString(context.version.builtAt)
|
|
19171
|
+
builtAt: instantString(context.version.builtAt),
|
|
19172
|
+
core: { name: CoreVersion.name, version: CoreVersion.version }
|
|
19029
19173
|
}));
|
|
19030
19174
|
}
|
|
19031
19175
|
|
|
@@ -19475,7 +19619,7 @@ async function createMongocampServer(options = {}) {
|
|
|
19475
19619
|
for (const [name, interceptor] of Object.entries(options.intercept ?? {})) {
|
|
19476
19620
|
interceptors.on(name, interceptor);
|
|
19477
19621
|
}
|
|
19478
|
-
const configurations = new ConfigPersistence(database, config, events);
|
|
19622
|
+
const configurations = new ConfigPersistence(database, config, events, logger);
|
|
19479
19623
|
const auth = new AuthService(database, config, version);
|
|
19480
19624
|
const jobOptions = typeof options.jobs === "object" ? options.jobs : { enabled: options.jobs ?? true };
|
|
19481
19625
|
const handlers = new Map([
|
|
@@ -19610,4 +19754,4 @@ async function connectHooks(server, hooks) {
|
|
|
19610
19754
|
};
|
|
19611
19755
|
}
|
|
19612
19756
|
|
|
19613
|
-
export { ActAsHeader, AuditCollection, AuthorizedUser, BehaviourDefaults, CleanUpTokenJob, CleanUpTokenJobClass, CollectionRegistry, ConfigKeys, ConfigStore, ConfigurationError, DefaultRowsPerPage, DefaultValidationMode, DocumentService, ErrorCodes, EventBus, FilterDefaultField, HookPrefix, InternalErrorMessage, JobScheduler, LuceneQueryError, MaxExpands, MongocampError, OwnIndexPrefix, PaginationHeaders, SyncValidationLevel, SystemUser, TextMarker, WriteInterceptors, auditCollectionOf, auditRecords, bsonMarkerOptions, collections, combineScopes, configDefinitions, connectHooks, consoleLogger, convertFields, convertIdValue, createMongocampServer, createServerCollection, decodeAny, defineMongocampCollection, documentToJson, ensureAuditIndexes, filterParameter, forwardEventsToHooks, forwardInterceptorsToHooks, guardedPaths, luceneQueryToFilter, luceneToFilter, metrics, notDeleted, ownedBy, parseExtendedJsonMode, parseJson, parseLuceneQuery, pathIdFilter, purgeIndexName, readScope, refsOf, requestFields, requestLogging, resolveBehaviours, resolveIndexes, resolveRefs, restoreUpdate, sameValidator, stampInsert, stampReplace, stampUpdate, stringifyJson, stripDocument, stripUpdate, syncIndexes, syncPurgeIndex, syncValidator, systemFields, toErrorResponse, toMongoJsonSchema, validatorOf$1 as validatorOf, versionInDocument, versionInUpdate, withDeletedOf, withIncrement, withSystemFields, withVersion };
|
|
19757
|
+
export { ActAsHeader, AuditCollection, AuthorizedUser, BehaviourDefaults, CleanUpTokenJob, CleanUpTokenJobClass, CollectionRegistry, ConfigKeys, ConfigStore, ConfigurationError, CoreVersion, DefaultRowsPerPage, DefaultValidationMode, DocumentService, ErrorCodes, EventBus, FilterDefaultField, HookPrefix, InternalErrorMessage, JobScheduler, KeepTimestampsHeader, LuceneQueryError, MaxExpands, MongocampError, OwnIndexPrefix, PaginationHeaders, SyncValidationLevel, SystemUser, TextMarker, WriteInterceptors, auditCollectionOf, auditRecords, bsonMarkerOptions, collections, combineScopes, configDefinitions, connectHooks, consoleLogger, convertFields, convertIdValue, createMongocampServer, createServerCollection, decodeAny, defineMongocampCollection, documentToJson, ensureAuditIndexes, filterParameter, forwardEventsToHooks, forwardInterceptorsToHooks, guardedPaths, luceneQueryToFilter, luceneToFilter, metrics, notDeleted, ownedBy, parseExtendedJsonMode, parseJson, parseLuceneQuery, pathIdFilter, purgeIndexName, readScope, refsOf, requestFields, requestLogging, resolveBehaviours, resolveIndexes, resolveRefs, restoreUpdate, sameValidator, stampInsert, stampReplace, stampUpdate, stringifyJson, stripDocument, stripUpdate, syncIndexes, syncPurgeIndex, syncValidator, systemFields, toErrorResponse, toMongoJsonSchema, validatorOf$1 as validatorOf, versionInDocument, versionInUpdate, withDeletedOf, withIncrement, withSystemFields, withVersion };
|