@sfxcode/mongocamp-server-core 2.7.2 → 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 -6
- package/dist/index.mjs +195 -59
- 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,25 +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>;
|
|
1907
1957
|
/** Replaces the stored old defaults of `LegacyDefaults` that nobody set (no `changedAt`, written since 2.6.0) by the current ones. */
|
|
1908
1958
|
private upgradeLegacyDefaults;
|
|
1959
|
+
/**
|
|
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.
|
|
1962
|
+
*/
|
|
1963
|
+
unmarkedNonDefaults(): Promise<string[]>;
|
|
1964
|
+
/** 2.8.0: one warning at the start, keys only (values can be secret). */
|
|
1965
|
+
private warnUnmarkedNonDefaults;
|
|
1909
1966
|
/** Reads the stored values; at startup also the keys that need a restart, later only the ones that are active at once. */
|
|
1910
1967
|
refresh(startup: boolean): Promise<void>;
|
|
1911
1968
|
/** A configuration as answered by the API: the stored one, the one of the env, or a non persistent one. */
|
|
@@ -1953,6 +2010,11 @@ interface InterceptorBase {
|
|
|
1953
2010
|
* ones of the user it acts for.
|
|
1954
2011
|
*/
|
|
1955
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;
|
|
1956
2018
|
}
|
|
1957
2019
|
interface WriteInterceptorPayloads {
|
|
1958
2020
|
/** Documents to insert: one for `PUT …/documents`, all of the request for `insertMany`, one batch for an import. */
|
|
@@ -2366,6 +2428,11 @@ interface MongocampContext {
|
|
|
2366
2428
|
type ServerCollectionUser = string | AuthorizedUser | Request | 'system';
|
|
2367
2429
|
interface ServerCollectionOptions {
|
|
2368
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;
|
|
2369
2436
|
}
|
|
2370
2437
|
interface ServerFindOptions {
|
|
2371
2438
|
/** A MongoDB filter, or a Lucene filter as text (`status:open AND qty:[1 TO 5]`). */
|
|
@@ -2508,6 +2575,11 @@ interface MongocampServer {
|
|
|
2508
2575
|
/** Creates and connects a MongoCamp server. */
|
|
2509
2576
|
declare function createMongocampServer(options?: MongocampServerOptions): Promise<MongocampServer>;
|
|
2510
2577
|
|
|
2578
|
+
declare const CoreVersion: {
|
|
2579
|
+
readonly name: "@sfxcode/mongocamp-server-core";
|
|
2580
|
+
readonly version: "2.8.0";
|
|
2581
|
+
};
|
|
2582
|
+
|
|
2511
2583
|
/** Error codes of the API (`mongocamp-library/.../exception/ErrorCodes.scala`), sent in `ErrorDescription.code` and `x-error-code`. */
|
|
2512
2584
|
declare const ErrorCodes: {
|
|
2513
2585
|
/** A request that could not be decoded (body, query or header with an invalid value). */
|
|
@@ -2867,7 +2939,7 @@ declare function stripDocument(document: Document$2, paths: readonly string[]):
|
|
|
2867
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
|
|
2868
2940
|
* behaviour is set field by field, without the guarded fields; other operators on such a parent are removed.
|
|
2869
2941
|
*/
|
|
2870
|
-
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;
|
|
2871
2943
|
|
|
2872
2944
|
/**
|
|
2873
2945
|
* The behaviour `softDelete` (2.3.0): a delete sets the deleted mark (`deletedAt`) instead of removing the document, every read hides
|
|
@@ -2940,9 +3012,9 @@ declare function stampInsert(document: Document$2, timestamps: Timestamps, stamp
|
|
|
2940
3012
|
* Sets the change fields of a replacing document; the creation fields stay as stored (put back by the guard), a document without them
|
|
2941
3013
|
* (stored before the behaviour was switched on) gets the values of this write.
|
|
2942
3014
|
*/
|
|
2943
|
-
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;
|
|
2944
3016
|
/** An update with the change fields set (`$set` with dot paths, so the creation fields next to them stay). */
|
|
2945
|
-
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;
|
|
2946
3018
|
|
|
2947
|
-
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 };
|
|
2948
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;
|
|
@@ -2048,10 +2061,11 @@ function valueForUpdate(definition, value) {
|
|
|
2048
2061
|
return converted;
|
|
2049
2062
|
}
|
|
2050
2063
|
class ConfigPersistence {
|
|
2051
|
-
constructor(database, config, events) {
|
|
2064
|
+
constructor(database, config, events, logger) {
|
|
2052
2065
|
this.database = database;
|
|
2053
2066
|
this.config = config;
|
|
2054
2067
|
this.events = events;
|
|
2068
|
+
this.logger = logger;
|
|
2055
2069
|
}
|
|
2056
2070
|
timer;
|
|
2057
2071
|
get collection() {
|
|
@@ -2075,6 +2089,7 @@ class ConfigPersistence {
|
|
|
2075
2089
|
await this.collection.updateOne({ key: definition.key }, { $setOnInsert: document }, { upsert: true });
|
|
2076
2090
|
}
|
|
2077
2091
|
await this.upgradeLegacyDefaults();
|
|
2092
|
+
await this.warnUnmarkedNonDefaults();
|
|
2078
2093
|
await this.refresh(true);
|
|
2079
2094
|
if (refreshMillis !== false) {
|
|
2080
2095
|
this.timer = setInterval(() => {
|
|
@@ -2096,6 +2111,23 @@ class ConfigPersistence {
|
|
|
2096
2111
|
);
|
|
2097
2112
|
}
|
|
2098
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
|
+
}
|
|
2099
2131
|
/** Reads the stored values; at startup also the keys that need a restart, later only the ones that are active at once. */
|
|
2100
2132
|
async refresh(startup) {
|
|
2101
2133
|
const documents = await this.collection.find({}).toArray();
|
|
@@ -2120,15 +2152,23 @@ class ConfigPersistence {
|
|
|
2120
2152
|
const converted = fromStored(definition.type, stored.value);
|
|
2121
2153
|
value = converted === void 0 ? stored.value ?? null : toStored(definition.type, converted);
|
|
2122
2154
|
}
|
|
2123
|
-
|
|
2124
|
-
|
|
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);
|
|
2125
2162
|
}
|
|
2126
2163
|
return {
|
|
2127
2164
|
key: definition.key,
|
|
2128
2165
|
value,
|
|
2129
2166
|
configType: definition.type,
|
|
2130
2167
|
comment: override === "env" ? EnvComment : String(stored?.comment ?? ""),
|
|
2131
|
-
needsRestartForActivation: definition.needsRestartForActivation
|
|
2168
|
+
needsRestartForActivation: definition.needsRestartForActivation,
|
|
2169
|
+
source,
|
|
2170
|
+
...generated ? {} : { defaultValue },
|
|
2171
|
+
isDefault
|
|
2132
2172
|
};
|
|
2133
2173
|
}
|
|
2134
2174
|
/** All configurations sorted by key (`getAllRegisteredConfigurations`). */
|
|
@@ -2190,6 +2230,20 @@ class ConfigPersistence {
|
|
|
2190
2230
|
}
|
|
2191
2231
|
}
|
|
2192
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
|
+
}
|
|
2193
2247
|
function defaultOf(definition) {
|
|
2194
2248
|
return typeof definition.defaultValue === "function" ? definition.defaultValue() : definition.defaultValue;
|
|
2195
2249
|
}
|
|
@@ -2871,7 +2925,7 @@ const BehaviourDefaults = {
|
|
|
2871
2925
|
auditRetentionDays: 365
|
|
2872
2926
|
};
|
|
2873
2927
|
const optionKeys = {
|
|
2874
|
-
timestamps: ["createdAt", "updatedAt", "createdBy", "updatedBy", "preserveOnInsert"],
|
|
2928
|
+
timestamps: ["createdAt", "updatedAt", "createdBy", "updatedBy", "preserveOnInsert", "preserveOnUpdate"],
|
|
2875
2929
|
owner: ["field", "read", "adminBypass", "preserveOnInsert"],
|
|
2876
2930
|
softDelete: ["field", "purgeAfterDays"],
|
|
2877
2931
|
versioned: ["mode", "field", "required"],
|
|
@@ -2928,12 +2982,14 @@ function resolveBehaviours(flags) {
|
|
|
2928
2982
|
...timestamps.createdBy !== void 0 ? { createdBy: field(timestamps.createdBy, BehaviourDefaults.createdBy, "timestamps.createdBy") } : {},
|
|
2929
2983
|
...timestamps.updatedBy !== void 0 ? { updatedBy: field(timestamps.updatedBy, BehaviourDefaults.updatedBy, "timestamps.updatedBy") } : {}
|
|
2930
2984
|
};
|
|
2931
|
-
|
|
2932
|
-
if (
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
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
|
+
}
|
|
2937
2993
|
}
|
|
2938
2994
|
}
|
|
2939
2995
|
}
|
|
@@ -3013,6 +3069,12 @@ function byAdministrator(event) {
|
|
|
3013
3069
|
function preservesOnInsert(timestamps, event) {
|
|
3014
3070
|
return timestamps?.preserveOnInsert === true && byAdministrator(event);
|
|
3015
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
|
+
}
|
|
3016
3078
|
function preservesOwnerOnInsert(owner, event) {
|
|
3017
3079
|
return owner?.preserveOnInsert === true && byAdministrator(event);
|
|
3018
3080
|
}
|
|
@@ -3666,7 +3728,7 @@ function flatten(value, prefix) {
|
|
|
3666
3728
|
return isPlainObject(entry) && Object.keys(entry).length > 0 ? flatten(entry, path) : [[path, entry]];
|
|
3667
3729
|
});
|
|
3668
3730
|
}
|
|
3669
|
-
function stripUpdate(update, guarded, system) {
|
|
3731
|
+
function stripUpdate(update, guarded, system, setOnly = []) {
|
|
3670
3732
|
const result = {};
|
|
3671
3733
|
for (const [operator, fields] of Object.entries(update)) {
|
|
3672
3734
|
if (!operator.startsWith("$") || !isPlainObject(fields)) {
|
|
@@ -3675,7 +3737,7 @@ function stripUpdate(update, guarded, system) {
|
|
|
3675
3737
|
}
|
|
3676
3738
|
const kept = {};
|
|
3677
3739
|
for (const [path, value] of Object.entries(fields)) {
|
|
3678
|
-
if (guarded.some((entry) => isAtOrBelow(path, entry))) {
|
|
3740
|
+
if (guarded.some((entry) => isAtOrBelow(path, entry)) || operator !== "$set" && setOnly.some((entry) => isAtOrBelow(path, entry))) {
|
|
3679
3741
|
continue;
|
|
3680
3742
|
}
|
|
3681
3743
|
const parentOfSystem = system.some((entry) => entry.startsWith(`${path}.`));
|
|
@@ -3725,7 +3787,9 @@ function registerGuard(context, own) {
|
|
|
3725
3787
|
return;
|
|
3726
3788
|
}
|
|
3727
3789
|
const stored = await collectionOf(context.database, event.collectionName).findOne(event.filter, { projection: Object.fromEntries(guard.all.map((path) => [path, 1])) });
|
|
3728
|
-
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)));
|
|
3729
3793
|
for (const path of guard.protected) {
|
|
3730
3794
|
const value = stored === null ? void 0 : getPath(stored, path);
|
|
3731
3795
|
if (value !== void 0) {
|
|
@@ -3733,7 +3797,7 @@ function registerGuard(context, own) {
|
|
|
3733
3797
|
}
|
|
3734
3798
|
}
|
|
3735
3799
|
if (stored !== null) {
|
|
3736
|
-
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));
|
|
3737
3801
|
}
|
|
3738
3802
|
event.document = document;
|
|
3739
3803
|
}, { stage: "guard" }),
|
|
@@ -3747,7 +3811,9 @@ function registerGuard(context, own) {
|
|
|
3747
3811
|
context.interceptors.on("document:beforeUpdate", (event) => {
|
|
3748
3812
|
const guard = guardedFor(event.collectionName);
|
|
3749
3813
|
if (guard !== void 0) {
|
|
3750
|
-
|
|
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);
|
|
3751
3817
|
}
|
|
3752
3818
|
}, { stage: "guard" })
|
|
3753
3819
|
];
|
|
@@ -3906,22 +3972,26 @@ function stampInsert(document, timestamps, stamp, keepSent = false) {
|
|
|
3906
3972
|
write(timestamps.updatedBy, stamp.userId);
|
|
3907
3973
|
}
|
|
3908
3974
|
}
|
|
3909
|
-
function stampReplace(document, timestamps, stamp) {
|
|
3975
|
+
function stampReplace(document, timestamps, stamp, keepSent = false) {
|
|
3910
3976
|
if (getPath(document, timestamps.createdAt) === void 0) {
|
|
3911
3977
|
setPath(document, timestamps.createdAt, stamp.now);
|
|
3912
3978
|
}
|
|
3913
3979
|
if (timestamps.createdBy !== void 0 && getPath(document, timestamps.createdBy) === void 0) {
|
|
3914
3980
|
setPath(document, timestamps.createdBy, stamp.userId);
|
|
3915
3981
|
}
|
|
3916
|
-
|
|
3917
|
-
|
|
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)) {
|
|
3918
3986
|
setPath(document, timestamps.updatedBy, stamp.userId);
|
|
3919
3987
|
}
|
|
3920
3988
|
}
|
|
3921
|
-
function stampUpdate(update, timestamps, stamp) {
|
|
3989
|
+
function stampUpdate(update, timestamps, stamp, keepSent = false) {
|
|
3922
3990
|
const set = isPlainObject(update.$set) ? { ...update.$set } : {};
|
|
3923
|
-
set[timestamps.updatedAt]
|
|
3924
|
-
|
|
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)) {
|
|
3925
3995
|
set[timestamps.updatedBy] = stamp.userId;
|
|
3926
3996
|
}
|
|
3927
3997
|
return { ...update, $set: set };
|
|
@@ -3946,13 +4016,13 @@ function registerTimestamps(context, own, clock = () => /* @__PURE__ */ new Date
|
|
|
3946
4016
|
context.interceptors.on("document:beforeReplace", (event) => {
|
|
3947
4017
|
const timestamps = timestampsFor(event.collectionName);
|
|
3948
4018
|
if (timestamps !== void 0) {
|
|
3949
|
-
stampReplace(event.document, timestamps, stampOf(event.user));
|
|
4019
|
+
stampReplace(event.document, timestamps, stampOf(event.user), preservesOnUpdate(timestamps, event));
|
|
3950
4020
|
}
|
|
3951
4021
|
}, { stage: "system" }),
|
|
3952
4022
|
context.interceptors.on("document:beforeUpdate", (event) => {
|
|
3953
4023
|
const timestamps = timestampsFor(event.collectionName);
|
|
3954
4024
|
if (timestamps !== void 0) {
|
|
3955
|
-
event.update = stampUpdate(event.update, timestamps, stampOf(event.user));
|
|
4025
|
+
event.update = stampUpdate(event.update, timestamps, stampOf(event.user), preservesOnUpdate(timestamps, event));
|
|
3956
4026
|
}
|
|
3957
4027
|
}, { stage: "system" })
|
|
3958
4028
|
];
|
|
@@ -6750,24 +6820,25 @@ function createServerCollection(context, name, options) {
|
|
|
6750
6820
|
const service = context.documents;
|
|
6751
6821
|
let resolved;
|
|
6752
6822
|
const user = () => {
|
|
6753
|
-
resolved ??= (
|
|
6754
|
-
const given = options.user;
|
|
6755
|
-
if (given === "system") {
|
|
6756
|
-
return SystemUser;
|
|
6757
|
-
}
|
|
6758
|
-
if (given instanceof AuthorizedUser) {
|
|
6759
|
-
return given;
|
|
6760
|
-
}
|
|
6761
|
-
if (given instanceof Request) {
|
|
6762
|
-
return context.auth.authenticate(given);
|
|
6763
|
-
}
|
|
6764
|
-
if (typeof given === "string" && given !== "") {
|
|
6765
|
-
return context.auth.authorizedUser(given);
|
|
6766
|
-
}
|
|
6767
|
-
throw MongocampError.unauthorized("the server collection needs a user (an id, a request or 'system')");
|
|
6768
|
-
})();
|
|
6823
|
+
resolved ??= resolveUser().then((authorized) => options.keepTimestamps === true ? authorized.keepingTimestamps() : authorized);
|
|
6769
6824
|
return resolved;
|
|
6770
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
|
+
};
|
|
6771
6842
|
const filterOf = (filter) => {
|
|
6772
6843
|
if (filter === void 0) {
|
|
6773
6844
|
return {};
|
|
@@ -7867,8 +7938,9 @@ function registerBucketRoutes(app, context) {
|
|
|
7867
7938
|
});
|
|
7868
7939
|
}
|
|
7869
7940
|
|
|
7870
|
-
async function copyIndexes(source, target) {
|
|
7871
|
-
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));
|
|
7872
7944
|
if (indexes.length > 0) {
|
|
7873
7945
|
const specifications = indexes.map((index) => {
|
|
7874
7946
|
const { v: _version, ns: _namespace, ...specification } = index;
|
|
@@ -7876,9 +7948,9 @@ async function copyIndexes(source, target) {
|
|
|
7876
7948
|
});
|
|
7877
7949
|
await target.db.command({ createIndexes: target.collectionName, indexes: specifications });
|
|
7878
7950
|
}
|
|
7879
|
-
return indexes.length;
|
|
7951
|
+
return { indexes: indexes.length, skippedIndexes: all.length - indexes.length };
|
|
7880
7952
|
}
|
|
7881
|
-
async function copyCollection(database, source, target, filter, withIndexes, replaceTarget, temporaryPrefix) {
|
|
7953
|
+
async function copyCollection(database, source, target, filter, withIndexes, replaceTarget, temporaryPrefix, targetDeclared = false) {
|
|
7882
7954
|
const db = databaseOf(database, source);
|
|
7883
7955
|
const temporaryName = `${temporaryPrefix}copy_${randomUUID().replaceAll("-", "")}`;
|
|
7884
7956
|
try {
|
|
@@ -7888,9 +7960,9 @@ async function copyCollection(database, source, target, filter, withIndexes, rep
|
|
|
7888
7960
|
if (!(await collectionNames(db)).includes(temporaryName)) {
|
|
7889
7961
|
await db.createCollection(temporaryName);
|
|
7890
7962
|
}
|
|
7891
|
-
const
|
|
7963
|
+
const copied = withIndexes ? await copyIndexes(db.collection(source.name), db.collection(temporaryName), targetDeclared) : { indexes: 0, skippedIndexes: 0 };
|
|
7892
7964
|
await db.collection(temporaryName).rename(target.name, { dropTarget: replaceTarget });
|
|
7893
|
-
return { count: await db.collection(target.name).countDocuments(),
|
|
7965
|
+
return { count: await db.collection(target.name).countDocuments(), ...copied };
|
|
7894
7966
|
} finally {
|
|
7895
7967
|
if ((await collectionNames(db)).includes(temporaryName)) {
|
|
7896
7968
|
await db.collection(temporaryName).drop();
|
|
@@ -7898,7 +7970,7 @@ async function copyCollection(database, source, target, filter, withIndexes, rep
|
|
|
7898
7970
|
}
|
|
7899
7971
|
}
|
|
7900
7972
|
function copyResponse(target, result) {
|
|
7901
|
-
return { name: fullName(target), count: result.count, indexes: result.indexes };
|
|
7973
|
+
return { name: fullName(target), count: result.count, indexes: result.indexes, skippedIndexes: result.skippedIndexes };
|
|
7902
7974
|
}
|
|
7903
7975
|
|
|
7904
7976
|
const ValidationLevels = ["off", "moderate", "strict"];
|
|
@@ -8812,7 +8884,8 @@ function registerCollectionRoutes(app, context) {
|
|
|
8812
8884
|
}
|
|
8813
8885
|
const filter = bodyFilter(request.filter, filterOptions(queryParams(event), config, context.collections.refFields(context, collection)));
|
|
8814
8886
|
const targetExists = await checkTarget(user, target, request.dropTarget);
|
|
8815
|
-
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);
|
|
8816
8889
|
context.events.publish("collection:copy", { user: user.user, collectionName: fullName(source), newCollectionName: fullName(target) });
|
|
8817
8890
|
return jsonResponse(copyResponse(target, result));
|
|
8818
8891
|
});
|
|
@@ -14487,6 +14560,17 @@ paths:
|
|
|
14487
14560
|
required: true
|
|
14488
14561
|
schema:
|
|
14489
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
|
|
14490
14574
|
requestBody:
|
|
14491
14575
|
content:
|
|
14492
14576
|
application/json:
|
|
@@ -14556,6 +14640,17 @@ paths:
|
|
|
14556
14640
|
required: true
|
|
14557
14641
|
schema:
|
|
14558
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
|
|
14559
14654
|
requestBody:
|
|
14560
14655
|
content:
|
|
14561
14656
|
application/json:
|
|
@@ -16462,6 +16557,11 @@ components:
|
|
|
16462
16557
|
indexes:
|
|
16463
16558
|
type: integer
|
|
16464
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
|
|
16465
16565
|
CountResponse:
|
|
16466
16566
|
title: CountResponse
|
|
16467
16567
|
type: object
|
|
@@ -17017,6 +17117,22 @@ components:
|
|
|
17017
17117
|
type: string
|
|
17018
17118
|
needsRestartForActivation:
|
|
17019
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
|
|
17020
17136
|
MongoFindRequest:
|
|
17021
17137
|
title: MongoFindRequest
|
|
17022
17138
|
type: object
|
|
@@ -17676,6 +17792,20 @@ components:
|
|
|
17676
17792
|
builtAt:
|
|
17677
17793
|
type: string
|
|
17678
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
|
|
17679
17809
|
securitySchemes:
|
|
17680
17810
|
apiKeyAuth:
|
|
17681
17811
|
type: apiKey
|
|
@@ -18555,14 +18685,17 @@ function registerIndexRoutes(app, context) {
|
|
|
18555
18685
|
const collection = await administrated(event);
|
|
18556
18686
|
return jsonResponse((await collection.listIndexes().toArray()).map(indexInfo));
|
|
18557
18687
|
});
|
|
18558
|
-
|
|
18688
|
+
const existingIndex = async (event) => {
|
|
18559
18689
|
const collection = await administrated(event);
|
|
18560
18690
|
const name = pathParam(event, "indexName");
|
|
18561
18691
|
const index = (await collection.listIndexes().toArray()).find((entry) => entry.name === name);
|
|
18562
18692
|
if (!index) {
|
|
18563
18693
|
throw MongocampError.notFound(`index not found with name [${name}]`, 27);
|
|
18564
18694
|
}
|
|
18565
|
-
return
|
|
18695
|
+
return { collection, name, index };
|
|
18696
|
+
};
|
|
18697
|
+
app.get(`${base}/:indexName`, async (event) => {
|
|
18698
|
+
return jsonResponse(mongoIndex((await existingIndex(event)).index));
|
|
18566
18699
|
});
|
|
18567
18700
|
app.put(base, async (event) => {
|
|
18568
18701
|
const collection = await administrated(event);
|
|
@@ -18596,8 +18729,8 @@ function registerIndexRoutes(app, context) {
|
|
|
18596
18729
|
return created(await collection.createIndex({ [pathParam(event, "fieldName")]: "text" }, options));
|
|
18597
18730
|
});
|
|
18598
18731
|
app.delete(`${base}/:indexName`, async (event) => {
|
|
18599
|
-
const collection = await
|
|
18600
|
-
await collection.dropIndex(
|
|
18732
|
+
const { collection, name } = await existingIndex(event);
|
|
18733
|
+
await collection.dropIndex(name);
|
|
18601
18734
|
return jsonResponse({ dropped: true });
|
|
18602
18735
|
});
|
|
18603
18736
|
}
|
|
@@ -19029,11 +19162,14 @@ function metrics() {
|
|
|
19029
19162
|
};
|
|
19030
19163
|
}
|
|
19031
19164
|
|
|
19165
|
+
const CoreVersion = { name: "@sfxcode/mongocamp-server-core", version: "2.8.0" };
|
|
19166
|
+
|
|
19032
19167
|
function registerInformationRoutes(app, context) {
|
|
19033
19168
|
app.get("/version", () => jsonResponse({
|
|
19034
19169
|
name: context.version.name,
|
|
19035
19170
|
version: context.version.version,
|
|
19036
|
-
builtAt: instantString(context.version.builtAt)
|
|
19171
|
+
builtAt: instantString(context.version.builtAt),
|
|
19172
|
+
core: { name: CoreVersion.name, version: CoreVersion.version }
|
|
19037
19173
|
}));
|
|
19038
19174
|
}
|
|
19039
19175
|
|
|
@@ -19483,7 +19619,7 @@ async function createMongocampServer(options = {}) {
|
|
|
19483
19619
|
for (const [name, interceptor] of Object.entries(options.intercept ?? {})) {
|
|
19484
19620
|
interceptors.on(name, interceptor);
|
|
19485
19621
|
}
|
|
19486
|
-
const configurations = new ConfigPersistence(database, config, events);
|
|
19622
|
+
const configurations = new ConfigPersistence(database, config, events, logger);
|
|
19487
19623
|
const auth = new AuthService(database, config, version);
|
|
19488
19624
|
const jobOptions = typeof options.jobs === "object" ? options.jobs : { enabled: options.jobs ?? true };
|
|
19489
19625
|
const handlers = new Map([
|
|
@@ -19618,4 +19754,4 @@ async function connectHooks(server, hooks) {
|
|
|
19618
19754
|
};
|
|
19619
19755
|
}
|
|
19620
19756
|
|
|
19621
|
-
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 };
|