@sfxcode/mongocamp-server-core 2.4.0 → 2.5.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 +137 -117
- package/dist/index.mjs +362 -174
- package/package.json +8 -2
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,7 @@ declare const ConfigKeys: {
|
|
|
23
23
|
readonly ServerInterface: "SERVER_INTERFACE";
|
|
24
24
|
readonly ServerPort: "SERVER_PORT";
|
|
25
25
|
readonly AggregationStagesDenied: "AGGREGATION_STAGES_DENIED";
|
|
26
|
+
readonly FilterOperatorsDenied: "FILTER_OPERATORS_DENIED";
|
|
26
27
|
readonly AuthHandler: "AUTH_HANDLER";
|
|
27
28
|
readonly AuthSecret: "AUTH_SECRET";
|
|
28
29
|
readonly AuthApiKeyLength: "AUTH_APIKEYLENGTH";
|
|
@@ -32,6 +33,14 @@ declare const ConfigKeys: {
|
|
|
32
33
|
readonly AuthGrantDeniedStatus: "AUTH_GRANT_DENIED_STATUS";
|
|
33
34
|
readonly ImportMaxBytes: "IMPORT_MAX_BYTES";
|
|
34
35
|
readonly WatchMaxStreams: "WATCH_MAX_STREAMS";
|
|
36
|
+
readonly BodyMaxBytes: "BODY_MAX_BYTES";
|
|
37
|
+
readonly PagingMaxRows: "PAGING_MAX_ROWS";
|
|
38
|
+
readonly ExportMaxDocuments: "EXPORT_MAX_DOCUMENTS";
|
|
39
|
+
readonly GridfsUploadMaxBytes: "GRIDFS_UPLOAD_MAX_BYTES";
|
|
40
|
+
readonly WatchQueueMax: "WATCH_QUEUE_MAX";
|
|
41
|
+
readonly ServerHeaderEnabled: "SERVER_HEADER_ENABLED";
|
|
42
|
+
readonly ErrorsExposeInternal: "ERRORS_EXPOSE_INTERNAL";
|
|
43
|
+
readonly ExportCsvEscapeFormulas: "EXPORT_CSV_ESCAPE_FORMULAS";
|
|
35
44
|
readonly FilterTimeZone: "FILTER_TIME_ZONE";
|
|
36
45
|
readonly MigrationDropScalaLeftovers: "MIGRATION_DROP_SCALA_LEFTOVERS";
|
|
37
46
|
readonly JobsEnabled: "JOBS_ENABLED";
|
|
@@ -81,9 +90,9 @@ declare class ConfigurationError extends Error {
|
|
|
81
90
|
type ConfigEnv = Record<string, string | undefined>;
|
|
82
91
|
interface ConfigSources {
|
|
83
92
|
/** Environment variables, `process.env` when omitted. */
|
|
84
|
-
env?: ConfigEnv;
|
|
93
|
+
env?: ConfigEnv | undefined;
|
|
85
94
|
/** Programmatic values (e.g. from Nuxt runtimeConfig). Strings are parsed like env values, other values are taken as they are. */
|
|
86
|
-
values?: Partial<Record<ConfigKey, unknown
|
|
95
|
+
values?: Partial<Record<ConfigKey, unknown>> | undefined;
|
|
87
96
|
}
|
|
88
97
|
/**
|
|
89
98
|
* In-memory view of all configurations. Precedence: definition default < programmatic values < env.
|
|
@@ -184,11 +193,18 @@ declare class MongocampError extends Error {
|
|
|
184
193
|
static decodeFailure(what: string, additionalInfo?: string): MongocampError;
|
|
185
194
|
}
|
|
186
195
|
type ErrorLogger = (error: unknown, status: number) => void;
|
|
196
|
+
interface ErrorResponseOptions {
|
|
197
|
+
/** The message of an unexpected error in the answer (`ERRORS_EXPOSE_INTERNAL`, for development); by default only the log has it. */
|
|
198
|
+
exposeInternal?: boolean | undefined;
|
|
199
|
+
}
|
|
200
|
+
/** The message of an unexpected error (2.5.0): its text stays in the log, the client gets the request id (header `x-request-id`). */
|
|
201
|
+
declare const InternalErrorMessage = "internal server error, the log of the server has the details (x-request-id)";
|
|
187
202
|
/**
|
|
188
203
|
* Maps anything thrown in a handler to the error response of the Scala server (`MongoCampExceptionHandler`): a `MongocampError` as it is,
|
|
189
|
-
* a database error with the status for its code and a message without internal names, everything else as 500 with code -1
|
|
204
|
+
* a database error with the status for its code and a message without internal names, everything else as 500 with code -1 and a generic
|
|
205
|
+
* message (2.5.0; before, the message of the error, which can name internals).
|
|
190
206
|
*/
|
|
191
|
-
declare function toErrorResponse(error: unknown, log?: ErrorLogger): Response;
|
|
207
|
+
declare function toErrorResponse(error: unknown, log?: ErrorLogger, options?: ErrorResponseOptions): Response;
|
|
192
208
|
|
|
193
209
|
/** Pagination of list routes (`PagingFunctions.scala`, `MongoPaginatedFilter.scala`): 1-based pages, 100 rows per page by default. */
|
|
194
210
|
declare const DefaultRowsPerPage = 100;
|
|
@@ -201,9 +217,9 @@ declare const PaginationHeaders: {
|
|
|
201
217
|
};
|
|
202
218
|
/** `after` switches to cursor paging (`http/cursor.ts`): the token of the previous page, or empty for the first page. */
|
|
203
219
|
interface Paging {
|
|
204
|
-
rowsPerPage?: number;
|
|
205
|
-
page?: number;
|
|
206
|
-
after?: string;
|
|
220
|
+
rowsPerPage?: number | undefined;
|
|
221
|
+
page?: number | undefined;
|
|
222
|
+
after?: string | undefined;
|
|
207
223
|
}
|
|
208
224
|
/** Query parameter `count`: `exact` (default) counts the matching documents, `none` skips the count and its headers. */
|
|
209
225
|
type CountMode = 'exact' | 'none';
|
|
@@ -388,7 +404,6 @@ interface LoginResult {
|
|
|
388
404
|
expirationDate: string;
|
|
389
405
|
}
|
|
390
406
|
declare class AuthService {
|
|
391
|
-
private readonly database;
|
|
392
407
|
private readonly config;
|
|
393
408
|
private readonly version;
|
|
394
409
|
readonly holder: AuthHolder;
|
|
@@ -776,7 +791,7 @@ interface MongocampCollectionDefinition<S extends StandardSchemaV1 = StandardSch
|
|
|
776
791
|
/** Default `warn`. */
|
|
777
792
|
validation?: ValidationMode;
|
|
778
793
|
/** A `$jsonSchema` validator for MongoDB that replaces the one converted from the schema (for schemas without JSON Schema form). */
|
|
779
|
-
validator?: Document$2;
|
|
794
|
+
validator?: Document$2 | undefined;
|
|
780
795
|
/** Indexes (2.4.0): `'status'`, `'-createdAt'`, `['a', '-b']` or `{ fields, unique, ... }`; synced at the start (own indexes only). */
|
|
781
796
|
indexes?: readonly IndexDeclaration[];
|
|
782
797
|
/** References (2.4.0): field → target collection (`'customers'`, `'db:customers'`), for `expand` on reads. */
|
|
@@ -1962,16 +1977,16 @@ declare function combineScopes(filter: Document$2, scopes: readonly Document$2[]
|
|
|
1962
1977
|
declare function readScope(context: Pick<MongocampContext, 'interceptors' | 'database'>, user: AuthorizedUser, collection: string, filter: Document$2, operation: ReadOperation, options?: ScopeOptions): Promise<Document$2>;
|
|
1963
1978
|
interface ScopeOptions {
|
|
1964
1979
|
/** Soft-deleted documents too (an administrator's `withDeleted=true`, checked by the route). */
|
|
1965
|
-
withDeleted?: boolean;
|
|
1980
|
+
withDeleted?: boolean | undefined;
|
|
1966
1981
|
}
|
|
1967
1982
|
/** `withDeleted=true` of a read route (2.3.0): soft-deleted documents too, for the administrators of the collection only (403 otherwise). */
|
|
1968
1983
|
declare function withDeletedOf(params: URLSearchParams, user: AuthorizedUser, collection: string): ScopeOptions;
|
|
1969
1984
|
|
|
1970
1985
|
interface ReadOptions extends ScopeOptions {
|
|
1971
1986
|
/** The kind of request for the hooks of `document:beforeRead` (default by operation). */
|
|
1972
|
-
operation?: ReadOperation;
|
|
1987
|
+
operation?: ReadOperation | undefined;
|
|
1973
1988
|
/** References to expand (2.4.0): declared ref fields of the collection, at most `MaxExpands`. */
|
|
1974
|
-
expand?: readonly string[];
|
|
1989
|
+
expand?: readonly string[] | undefined;
|
|
1975
1990
|
}
|
|
1976
1991
|
interface PageResult {
|
|
1977
1992
|
documents: Document$2[];
|
|
@@ -1985,6 +2000,10 @@ declare class DocumentService {
|
|
|
1985
2000
|
/** The grant of the caller; `withDeleted` only for the administrators of the collection. */
|
|
1986
2001
|
private require;
|
|
1987
2002
|
/** The filter with the read scope of the caller. */
|
|
2003
|
+
/** The paging of a read with `rowsPerPage` at most `PAGING_MAX_ROWS` (2.5.0, 0: no limit); the page headers show the rows used. */
|
|
2004
|
+
private limited;
|
|
2005
|
+
/** Refuses filters, projections and updates of the caller with an operator of `FILTER_OPERATORS_DENIED` (2.5.0). */
|
|
2006
|
+
private checkOperators;
|
|
1988
2007
|
scope(user: AuthorizedUser, collection: string, filter: Document$2, operation: ReadOperation, options?: ScopeOptions): Promise<Document$2>;
|
|
1989
2008
|
/**
|
|
1990
2009
|
* The declared references of `fields` (2.4.0); 400 for a name that is no reference of the collection and for more than `MaxExpands`.
|
|
@@ -2200,11 +2219,11 @@ interface MongocampContext {
|
|
|
2200
2219
|
collections: CollectionRegistry;
|
|
2201
2220
|
jobs: JobScheduler;
|
|
2202
2221
|
/** The metrics, with `METRICS_ENABLED` only. */
|
|
2203
|
-
metrics?: MongocampMetrics;
|
|
2222
|
+
metrics?: MongocampMetrics | undefined;
|
|
2204
2223
|
/** The answer of `buildInfo`, kept for an hour. */
|
|
2205
2224
|
systemInfo: InfoCache<SystemInfo>;
|
|
2206
2225
|
/** Stops the process (`DELETE /system`); not set when the server is embedded in an application. */
|
|
2207
|
-
shutdown?: (force: boolean) => void | Promise<void
|
|
2226
|
+
shutdown?: ((force: boolean) => void | Promise<void>) | undefined;
|
|
2208
2227
|
}
|
|
2209
2228
|
|
|
2210
2229
|
/**
|
|
@@ -2245,8 +2264,9 @@ interface ServerPage<T> {
|
|
|
2245
2264
|
countPages?: number;
|
|
2246
2265
|
}
|
|
2247
2266
|
/** A document that was read (with `_id`), or its id. */
|
|
2267
|
+
/** An id, or a document that was read (its `_id`; the schema type of a declared collection has an optional `_id`). */
|
|
2248
2268
|
type ServerDocumentIdentity = string | number | ObjectId | {
|
|
2249
|
-
_id
|
|
2269
|
+
_id?: unknown;
|
|
2250
2270
|
};
|
|
2251
2271
|
interface ServerCollection<T, I = T> {
|
|
2252
2272
|
readonly name: string;
|
|
@@ -2363,25 +2383,6 @@ interface MongocampServer {
|
|
|
2363
2383
|
/** Creates and connects a MongoCamp server. */
|
|
2364
2384
|
declare function createMongocampServer(options?: MongocampServerOptions): Promise<MongocampServer>;
|
|
2365
2385
|
|
|
2366
|
-
/** The fields of the server in the wide event of a request (key `mongocamp`). */
|
|
2367
|
-
interface MongocampRequestFields {
|
|
2368
|
-
requestId: string;
|
|
2369
|
-
/** The operationId of the OpenAPI spec (`listDocuments`), `NOT_SET` for an unknown route. */
|
|
2370
|
-
operation: string;
|
|
2371
|
-
controller: string;
|
|
2372
|
-
/** The user the request was authenticated as; missing for public routes and invalid credentials. */
|
|
2373
|
-
user?: string;
|
|
2374
|
-
database?: string;
|
|
2375
|
-
collection?: string;
|
|
2376
|
-
bucket?: string;
|
|
2377
|
-
/** All matching rows of a paged list (`x-pagination-count-rows`). */
|
|
2378
|
-
rows?: number;
|
|
2379
|
-
/** `x-error-code` and `x-error-message` of an error response. */
|
|
2380
|
-
errorCode?: string;
|
|
2381
|
-
errorMessage?: string;
|
|
2382
|
-
}
|
|
2383
|
-
declare function requestFields(request: Request, response: Response, fields: HttpRequestFields, user: string | undefined): MongocampRequestFields;
|
|
2384
|
-
|
|
2385
2386
|
/** Error codes of the API (`mongocamp-library/.../exception/ErrorCodes.scala`), sent in `ErrorDescription.code` and `x-error-code`. */
|
|
2386
2387
|
declare const ErrorCodes: {
|
|
2387
2388
|
/** A request that could not be decoded (body, query or header with an invalid value). */
|
|
@@ -2417,6 +2418,106 @@ declare const ErrorCodes: {
|
|
|
2417
2418
|
readonly jobClassNotFound: 4042;
|
|
2418
2419
|
};
|
|
2419
2420
|
|
|
2421
|
+
/**
|
|
2422
|
+
* The behaviour `audit` (2.3.0): every write to the collection leaves a record with the operation, the user, the time and the document
|
|
2423
|
+
* before and after, in `<AUTH_PREFIX>audit` of the default database, kept for `retentionDays` (a TTL index on `expiresAt`).
|
|
2424
|
+
*
|
|
2425
|
+
* Built on the events, so it is best effort like them: written after the request is answered, a failure is logged and does not fail the
|
|
2426
|
+
* write. A write of many documents records up to `MaxOldValues` documents and one summary record with the count. An import records the
|
|
2427
|
+
* ids of the documents only.
|
|
2428
|
+
*/
|
|
2429
|
+
type AuditOperation = 'insert' | 'replace' | 'update' | 'delete' | 'softDelete' | 'restore';
|
|
2430
|
+
interface AuditRecord {
|
|
2431
|
+
collection: string;
|
|
2432
|
+
database: string;
|
|
2433
|
+
/** The `_id` of the document; absent on a summary record. */
|
|
2434
|
+
documentId?: unknown;
|
|
2435
|
+
operation: AuditOperation;
|
|
2436
|
+
user: string;
|
|
2437
|
+
at: Date;
|
|
2438
|
+
before?: Document$2;
|
|
2439
|
+
after?: Document$2;
|
|
2440
|
+
/** A summary of a write of many documents: the number of documents and how many of them have a record. */
|
|
2441
|
+
summary?: {
|
|
2442
|
+
count: number;
|
|
2443
|
+
recorded: number;
|
|
2444
|
+
};
|
|
2445
|
+
/** When MongoDB deletes the record (TTL). */
|
|
2446
|
+
expiresAt: Date;
|
|
2447
|
+
}
|
|
2448
|
+
declare const AuditCollection = "audit";
|
|
2449
|
+
/** The audit records of the server: `<AUTH_PREFIX>audit` in the default database. */
|
|
2450
|
+
declare function auditCollectionOf<T extends Document$2 = AuditRecord>(context: Pick<MongocampContext, 'database'>): Collection<T>;
|
|
2451
|
+
/** The records of one write. */
|
|
2452
|
+
declare function auditRecords(input: {
|
|
2453
|
+
declared: DeclaredCollection;
|
|
2454
|
+
operation: AuditOperation;
|
|
2455
|
+
user: string;
|
|
2456
|
+
at: Date;
|
|
2457
|
+
documents: Array<{
|
|
2458
|
+
before?: Document$2 | undefined;
|
|
2459
|
+
after?: Document$2 | undefined;
|
|
2460
|
+
}>;
|
|
2461
|
+
count?: number;
|
|
2462
|
+
}): AuditRecord[];
|
|
2463
|
+
/** Creates the indexes of the audit records (history per document, TTL); idempotent. */
|
|
2464
|
+
declare function ensureAuditIndexes(context: Pick<MongocampContext, 'database' | 'logger'>): Promise<void>;
|
|
2465
|
+
|
|
2466
|
+
/**
|
|
2467
|
+
* The events of the server as hooks of a Nitro app (or any `hookable` instance): `mongocamp:document:update`, ... and `mongocamp:ready` with
|
|
2468
|
+
* the server once it is started. The before-hooks of the writes (`mongocamp:document:beforeInsert`, ...) are awaited and may change the
|
|
2469
|
+
* payload in place or refuse the write by throwing (see `WriteInterceptors`). An extension of an application is then a plain Nitro plugin:
|
|
2470
|
+
*
|
|
2471
|
+
* export default definePlugin((nitroApp) => {
|
|
2472
|
+
* nitroApp.hooks.hook('mongocamp:ready', server => server.use(metrics()))
|
|
2473
|
+
* nitroApp.hooks.hook('mongocamp:document:delete', event => audit(event))
|
|
2474
|
+
* nitroApp.hooks.hook('mongocamp:document:beforeInsert', ({ documents, user }) => documents.forEach(d => d.createdBy = user.userId))
|
|
2475
|
+
* })
|
|
2476
|
+
*/
|
|
2477
|
+
type MongocampHooks = {
|
|
2478
|
+
'mongocamp:ready': (server: MongocampServer) => void | Promise<void>;
|
|
2479
|
+
} & {
|
|
2480
|
+
[N in EventName as `mongocamp:${N}`]: (event: MongocampEvent<N>) => void | Promise<void>;
|
|
2481
|
+
} & {
|
|
2482
|
+
[N in InterceptorName as `mongocamp:${N}`]: (payload: WriteInterceptorPayloads[N]) => void | Promise<void>;
|
|
2483
|
+
};
|
|
2484
|
+
/** The part of `hookable` (Nitro's `nitroApp.hooks`) the bridge needs. */
|
|
2485
|
+
interface HookSystem {
|
|
2486
|
+
callHook(name: string, ...args: unknown[]): unknown;
|
|
2487
|
+
}
|
|
2488
|
+
declare const HookPrefix = "mongocamp:";
|
|
2489
|
+
/** Calls `mongocamp:<event>` for every event of the server that has a hook listener; the returned function stops it. */
|
|
2490
|
+
declare function forwardEventsToHooks(server: Pick<MongocampServer, 'events'>, hooks: HookSystem): () => void;
|
|
2491
|
+
/**
|
|
2492
|
+
* Runs `mongocamp:document:beforeInsert`, ... of the hook system as interceptors of the writes (awaited, an error refuses the write); only
|
|
2493
|
+
* hooks with a listener cost anything. The returned function stops it.
|
|
2494
|
+
*/
|
|
2495
|
+
declare function forwardInterceptorsToHooks(server: Pick<MongocampServer, 'interceptors'>, hooks: HookSystem): () => void;
|
|
2496
|
+
/**
|
|
2497
|
+
* Connects a started server with the hooks of its host: forwards the events and the interceptors, and calls `mongocamp:ready` (awaited, so
|
|
2498
|
+
* features that the plugins switch on are active before the first request is answered).
|
|
2499
|
+
*/
|
|
2500
|
+
declare function connectHooks(server: MongocampServer, hooks: HookSystem): Promise<() => void>;
|
|
2501
|
+
|
|
2502
|
+
/** The fields of the server in the wide event of a request (key `mongocamp`). */
|
|
2503
|
+
interface MongocampRequestFields {
|
|
2504
|
+
requestId: string;
|
|
2505
|
+
/** The operationId of the OpenAPI spec (`listDocuments`), `NOT_SET` for an unknown route. */
|
|
2506
|
+
operation: string;
|
|
2507
|
+
controller: string;
|
|
2508
|
+
/** The user the request was authenticated as; missing for public routes and invalid credentials. */
|
|
2509
|
+
user?: string;
|
|
2510
|
+
database?: string;
|
|
2511
|
+
collection?: string;
|
|
2512
|
+
bucket?: string;
|
|
2513
|
+
/** All matching rows of a paged list (`x-pagination-count-rows`). */
|
|
2514
|
+
rows?: number;
|
|
2515
|
+
/** `x-error-code` and `x-error-message` of an error response. */
|
|
2516
|
+
errorCode?: string;
|
|
2517
|
+
errorMessage?: string;
|
|
2518
|
+
}
|
|
2519
|
+
declare function requestFields(request: Request, response: Response, fields: HttpRequestFields, user: string | undefined): MongocampRequestFields;
|
|
2520
|
+
|
|
2420
2521
|
/** The key of the wrapper `{"$string": "..."}`: a text that looks like a date stays a text (`CirceSchema.TextMarker`). */
|
|
2421
2522
|
declare const TextMarker = "$string";
|
|
2422
2523
|
/**
|
|
@@ -2664,51 +2765,6 @@ type Owner = NonNullable<ResolvedBehaviours['owner']>;
|
|
|
2664
2765
|
/** The condition of the documents of a user. */
|
|
2665
2766
|
declare function ownedBy(owner: Owner, userId: string): Document$2;
|
|
2666
2767
|
|
|
2667
|
-
/**
|
|
2668
|
-
* The behaviour `audit` (2.3.0): every write to the collection leaves a record with the operation, the user, the time and the document
|
|
2669
|
-
* before and after, in `<AUTH_PREFIX>audit` of the default database, kept for `retentionDays` (a TTL index on `expiresAt`).
|
|
2670
|
-
*
|
|
2671
|
-
* Built on the events, so it is best effort like them: written after the request is answered, a failure is logged and does not fail the
|
|
2672
|
-
* write. A write of many documents records up to `MaxOldValues` documents and one summary record with the count. An import records the
|
|
2673
|
-
* ids of the documents only.
|
|
2674
|
-
*/
|
|
2675
|
-
type AuditOperation = 'insert' | 'replace' | 'update' | 'delete' | 'softDelete' | 'restore';
|
|
2676
|
-
interface AuditRecord {
|
|
2677
|
-
collection: string;
|
|
2678
|
-
database: string;
|
|
2679
|
-
/** The `_id` of the document; absent on a summary record. */
|
|
2680
|
-
documentId?: unknown;
|
|
2681
|
-
operation: AuditOperation;
|
|
2682
|
-
user: string;
|
|
2683
|
-
at: Date;
|
|
2684
|
-
before?: Document$2;
|
|
2685
|
-
after?: Document$2;
|
|
2686
|
-
/** A summary of a write of many documents: the number of documents and how many of them have a record. */
|
|
2687
|
-
summary?: {
|
|
2688
|
-
count: number;
|
|
2689
|
-
recorded: number;
|
|
2690
|
-
};
|
|
2691
|
-
/** When MongoDB deletes the record (TTL). */
|
|
2692
|
-
expiresAt: Date;
|
|
2693
|
-
}
|
|
2694
|
-
declare const AuditCollection = "audit";
|
|
2695
|
-
/** The audit records of the server: `<AUTH_PREFIX>audit` in the default database. */
|
|
2696
|
-
declare function auditCollectionOf(context: Pick<MongocampContext, 'database'>): Collection<AuditRecord>;
|
|
2697
|
-
/** The records of one write. */
|
|
2698
|
-
declare function auditRecords(input: {
|
|
2699
|
-
declared: DeclaredCollection;
|
|
2700
|
-
operation: AuditOperation;
|
|
2701
|
-
user: string;
|
|
2702
|
-
at: Date;
|
|
2703
|
-
documents: Array<{
|
|
2704
|
-
before?: Document$2;
|
|
2705
|
-
after?: Document$2;
|
|
2706
|
-
}>;
|
|
2707
|
-
count?: number;
|
|
2708
|
-
}): AuditRecord[];
|
|
2709
|
-
/** Creates the indexes of the audit records (history per document, TTL); idempotent. */
|
|
2710
|
-
declare function ensureAuditIndexes(context: Pick<MongocampContext, 'database' | 'logger'>): Promise<void>;
|
|
2711
|
-
|
|
2712
2768
|
/**
|
|
2713
2769
|
* The behaviour `versioned` (2.3.0): a replace or partial update that sends the version of the document it is based on only succeeds when
|
|
2714
2770
|
* the document still has that version; otherwise it answers 409 with the stored document (`current`) instead of overwriting the change of
|
|
@@ -2751,41 +2807,5 @@ declare function stampReplace(document: Document$2, timestamps: Timestamps, stam
|
|
|
2751
2807
|
/** An update with the change fields set (`$set` with dot paths, so the creation fields next to them stay). */
|
|
2752
2808
|
declare function stampUpdate(update: Document$2, timestamps: Timestamps, stamp: WriteStamp): Document$2;
|
|
2753
2809
|
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
* the server once it is started. The before-hooks of the writes (`mongocamp:document:beforeInsert`, ...) are awaited and may change the
|
|
2757
|
-
* payload in place or refuse the write by throwing (see `WriteInterceptors`). An extension of an application is then a plain Nitro plugin:
|
|
2758
|
-
*
|
|
2759
|
-
* export default definePlugin((nitroApp) => {
|
|
2760
|
-
* nitroApp.hooks.hook('mongocamp:ready', server => server.use(metrics()))
|
|
2761
|
-
* nitroApp.hooks.hook('mongocamp:document:delete', event => audit(event))
|
|
2762
|
-
* nitroApp.hooks.hook('mongocamp:document:beforeInsert', ({ documents, user }) => documents.forEach(d => d.createdBy = user.userId))
|
|
2763
|
-
* })
|
|
2764
|
-
*/
|
|
2765
|
-
type MongocampHooks = {
|
|
2766
|
-
'mongocamp:ready': (server: MongocampServer) => void | Promise<void>;
|
|
2767
|
-
} & {
|
|
2768
|
-
[N in EventName as `mongocamp:${N}`]: (event: MongocampEvent<N>) => void | Promise<void>;
|
|
2769
|
-
} & {
|
|
2770
|
-
[N in InterceptorName as `mongocamp:${N}`]: (payload: WriteInterceptorPayloads[N]) => void | Promise<void>;
|
|
2771
|
-
};
|
|
2772
|
-
/** The part of `hookable` (Nitro's `nitroApp.hooks`) the bridge needs. */
|
|
2773
|
-
interface HookSystem {
|
|
2774
|
-
callHook(name: string, ...args: unknown[]): unknown;
|
|
2775
|
-
}
|
|
2776
|
-
declare const HookPrefix = "mongocamp:";
|
|
2777
|
-
/** Calls `mongocamp:<event>` for every event of the server that has a hook listener; the returned function stops it. */
|
|
2778
|
-
declare function forwardEventsToHooks(server: Pick<MongocampServer, 'events'>, hooks: HookSystem): () => void;
|
|
2779
|
-
/**
|
|
2780
|
-
* Runs `mongocamp:document:beforeInsert`, ... of the hook system as interceptors of the writes (awaited, an error refuses the write); only
|
|
2781
|
-
* hooks with a listener cost anything. The returned function stops it.
|
|
2782
|
-
*/
|
|
2783
|
-
declare function forwardInterceptorsToHooks(server: Pick<MongocampServer, 'interceptors'>, hooks: HookSystem): () => void;
|
|
2784
|
-
/**
|
|
2785
|
-
* Connects a started server with the hooks of its host: forwards the events and the interceptors, and calls `mongocamp:ready` (awaited, so
|
|
2786
|
-
* features that the plugins switch on are active before the first request is answered).
|
|
2787
|
-
*/
|
|
2788
|
-
declare function connectHooks(server: MongocampServer, hooks: HookSystem): Promise<() => void>;
|
|
2789
|
-
|
|
2790
|
-
export { AuditCollection, AuthorizedUser, BehaviourDefaults, CleanUpTokenJob, CleanUpTokenJobClass, CollectionRegistry, ConfigKeys, ConfigStore, ConfigurationError, DefaultRowsPerPage, DefaultValidationMode, DocumentService, ErrorCodes, EventBus, FilterDefaultField, HookPrefix, 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, versionInDocument, versionInUpdate, withDeletedOf, withIncrement, withSystemFields, withVersion };
|
|
2791
|
-
export type { AuditOperation, AuditOptions, AuditRecord, BehaviourFlags, ConfigDefinition, ConfigKey, ConfigType, ConversionResult, ConvertOptions, DeclaredCollection, ErrorDescription, 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, TimestampsOptions, UserInformation, ValidationMode, ValidatorSyncAction, ValidatorSyncResult, VersionInfo, VersionedOptions, WriteInterceptor, WriteInterceptorPayloads, WriteStamp };
|
|
2810
|
+
export { 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 };
|
|
2811
|
+
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 };
|