@rapidrest/service-core 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -123
- package/dist/lib/Server.js +19 -7
- package/dist/lib/Server.js.map +1 -1
- package/dist/lib/auth/AuthMiddleware.js +32 -3
- package/dist/lib/auth/AuthMiddleware.js.map +1 -1
- package/dist/lib/database/MongoSchemaSync.js +187 -1
- package/dist/lib/database/MongoSchemaSync.js.map +1 -1
- package/dist/lib/database/TypeOrmSupport.js +85 -0
- package/dist/lib/database/TypeOrmSupport.js.map +1 -1
- package/dist/lib/decorators/RouteDecorators.js.map +1 -1
- package/dist/lib/http/WebSocketDrain.js +67 -0
- package/dist/lib/http/WebSocketDrain.js.map +1 -0
- package/dist/lib/http/bun/BunRouter.js +4 -0
- package/dist/lib/http/bun/BunRouter.js.map +1 -1
- package/dist/lib/http/bun/BunWebSocket.js +33 -0
- package/dist/lib/http/bun/BunWebSocket.js.map +1 -1
- package/dist/lib/http/index.js +1 -1
- package/dist/lib/http/index.js.map +1 -1
- package/dist/lib/http/uWS/Adapters.js +153 -70
- package/dist/lib/http/uWS/Adapters.js.map +1 -1
- package/dist/lib/http/uWS/Router.js +10 -6
- package/dist/lib/http/uWS/Router.js.map +1 -1
- package/dist/lib/http/uWS/WebSocket.js +33 -0
- package/dist/lib/http/uWS/WebSocket.js.map +1 -1
- package/dist/lib/models/ModelUtils.js +89 -42
- package/dist/lib/models/ModelUtils.js.map +1 -1
- package/dist/lib/models/RepoUtils.js +105 -57
- package/dist/lib/models/RepoUtils.js.map +1 -1
- package/dist/lib/routes/RouteUtils.js +52 -1
- package/dist/lib/routes/RouteUtils.js.map +1 -1
- package/dist/types/auth/AuthMiddleware.d.ts +19 -1
- package/dist/types/database/MongoSchemaSync.d.ts +52 -1
- package/dist/types/database/TypeOrmSupport.d.ts +15 -0
- package/dist/types/decorators/RouteDecorators.d.ts +24 -0
- package/dist/types/http/IWebSocketShim.d.ts +24 -0
- package/dist/types/http/WebSocketDrain.d.ts +27 -0
- package/dist/types/http/bun/BunWebSocket.d.ts +15 -0
- package/dist/types/http/index.d.ts +1 -1
- package/dist/types/http/uWS/Adapters.d.ts +37 -15
- package/dist/types/http/uWS/WebSocket.d.ts +13 -0
- package/dist/types/models/ModelUtils.d.ts +36 -16
- package/dist/types/models/RepoUtils.d.ts +12 -0
- package/dist/types/routes/RouteUtils.d.ts +11 -0
- package/package.json +1 -1
|
@@ -71,6 +71,14 @@ export declare class ModelUtils {
|
|
|
71
71
|
private static scopedPropertyCache;
|
|
72
72
|
/** Sequence used to give every `Raw()` SQL expression's named parameter a unique name within one query. */
|
|
73
73
|
private static rawParamSeq;
|
|
74
|
+
/**
|
|
75
|
+
* Returns whether `modelClass` keeps every version of a record as its own row/document (`@TrackChanges`).
|
|
76
|
+
*
|
|
77
|
+
* This is the one rule used everywhere: a model is tracked when its `trackChanges` value is truthy, so `-1`
|
|
78
|
+
* (every version) and any positive count are tracked, and `@TrackChanges(0)` is not (it behaves like a model
|
|
79
|
+
* without the decorator).
|
|
80
|
+
*/
|
|
81
|
+
static isTrackChanges(modelClass: any): boolean;
|
|
74
82
|
/**
|
|
75
83
|
* Marks `value` as a literal search value for `buildSearchQuery()` (and so `RepoUtils.find/count/truncate`),
|
|
76
84
|
* so it is compared exactly as given instead of being parsed as `op(value)` syntax. Use this whenever a query
|
|
@@ -185,9 +193,13 @@ export declare class ModelUtils {
|
|
|
185
193
|
* callers that expose a record by id to an API client (e.g. `findOne`, `exists`) should pass false so a
|
|
186
194
|
* soft-deleted record doesn't remain fully readable/resurrectable, the same way `buildSearchQuery` already
|
|
187
195
|
* excludes deleted records by default for list-style queries.
|
|
196
|
+
* @param latestOnly Set to true to match only the current version of a `@TrackChanges` record when no `version` is
|
|
197
|
+
* given, so a lookup by an identifier value an older version used to hold (before a rename) finds nothing. Has no
|
|
198
|
+
* effect for a model that isn't tracked, or when `version` is given. Defaults to false (every stored version
|
|
199
|
+
* matches), which is what a delete or a count of stored versions needs.
|
|
188
200
|
* @returns An object that can be passed to a TypeORM `find` function.
|
|
189
201
|
*/
|
|
190
|
-
static buildIdSearchQuery<T extends {}>(repo: Repository<T> | MongoRepository<T> | undefined, modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
202
|
+
static buildIdSearchQuery<T extends {}>(repo: Repository<T> | MongoRepository<T> | undefined, modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean, latestOnly?: boolean): any;
|
|
191
203
|
/**
|
|
192
204
|
* Builds a TypeORM compatible query object for use in `find` functions for retrieving objects matching the
|
|
193
205
|
* specified unique identifier.
|
|
@@ -195,9 +207,11 @@ export declare class ModelUtils {
|
|
|
195
207
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
196
208
|
* @param id The unique identifier to search for.
|
|
197
209
|
* @param version The version number of the document to search for.
|
|
210
|
+
* @param includeDeleted Set to false to exclude soft-deleted `RecoverableBaseEntity` records from matching.
|
|
211
|
+
* @param latestOnly See `buildIdSearchQuery()`.
|
|
198
212
|
* @returns An object that can be passed to a TypeORM `find` function.
|
|
199
213
|
*/
|
|
200
|
-
static buildIdSearchQuerySQL(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
214
|
+
static buildIdSearchQuerySQL(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean, latestOnly?: boolean): any;
|
|
201
215
|
/**
|
|
202
216
|
* Builds a MongoDB compatible query object for use in `find` functions for retrieving objects matching the
|
|
203
217
|
* specified unique identifier.
|
|
@@ -206,9 +220,10 @@ export declare class ModelUtils {
|
|
|
206
220
|
* @param id The unique identifier to search for.
|
|
207
221
|
* @param version The version number of the document to search for.
|
|
208
222
|
* @param includeDeleted Set to true to also match soft-deleted `RecoverableBaseEntity` records.
|
|
223
|
+
* @param latestOnly See `buildIdSearchQuery()`.
|
|
209
224
|
* @returns An object that can be passed to a MongoDB `find` function.
|
|
210
225
|
*/
|
|
211
|
-
static buildIdSearchQueryMongo(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
226
|
+
static buildIdSearchQueryMongo(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean, latestOnly?: boolean): any;
|
|
212
227
|
/**
|
|
213
228
|
* Resolves a raw, single-value operand (already unwrapped from any `op(...)` syntax) to a properly-typed
|
|
214
229
|
* native value: `me` is substituted for the requesting user's uid, and the result is otherwise coerced
|
|
@@ -302,16 +317,11 @@ export declare class ModelUtils {
|
|
|
302
317
|
* @param param
|
|
303
318
|
*/
|
|
304
319
|
private static getQueryParamValueMongo;
|
|
305
|
-
/**
|
|
306
|
-
* Extracts the `$match` stage from either shape `buildSearchQueryMongo` can return (a pipeline array or a
|
|
307
|
-
* flattened `{$match, $sort}` object).
|
|
308
|
-
*/
|
|
320
|
+
/** Extracts the `$match` from the flattened `{ $match, $sort }` object `buildSearchQueryMongo` returns. */
|
|
309
321
|
private static extractMatch;
|
|
310
322
|
/**
|
|
311
|
-
*
|
|
312
|
-
* `
|
|
313
|
-
* object depending on how many stages it produced (existing callers, e.g. `RepoUtils`, already branch on
|
|
314
|
-
* `Array.isArray()` to handle both) - use this instead at any new call site that wants one consistent shape.
|
|
323
|
+
* Converts the flattened `{ $match, $sort }` object `buildSearchQueryMongo` returns to a pipeline array
|
|
324
|
+
* (`[{ $match }, { $sort }]`, each stage only when present). A pipeline array is returned as is.
|
|
315
325
|
*/
|
|
316
326
|
static toFindQuery(pipelineOrObject: any): any[];
|
|
317
327
|
/**
|
|
@@ -434,11 +444,10 @@ export declare class ModelUtils {
|
|
|
434
444
|
* before delegating here), this function applies no soft-delete filtering of its own - a caller invoking it
|
|
435
445
|
* directly, bypassing `buildSearchQuery`, will not get that default exclusion.
|
|
436
446
|
*
|
|
437
|
-
* Does NOT bound `limit`/`page` into the returned
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
* NOTE: The result of this function is only compatible with the `aggregate()` function.
|
|
447
|
+
* Does NOT bound `limit`/`page` into the returned query (see `resolvePagination`). Always returns a flattened
|
|
448
|
+
* `{ $match, $sort? }` object, never an aggregation pipeline: pass `$match` to `find()`/`count()` and `$sort` as
|
|
449
|
+
* the sort option. For a `@TrackChanges` model the `$match` is restricted to `latest: true` rows unless the query
|
|
450
|
+
* filters on `version`.
|
|
442
451
|
*
|
|
443
452
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
444
453
|
* @param {any} query The search query parameters to include.
|
|
@@ -448,6 +457,17 @@ export declare class ModelUtils {
|
|
|
448
457
|
* @returns {object} The MongoDB compatible query object.
|
|
449
458
|
*/
|
|
450
459
|
static buildSearchQueryMongo(modelClass: any, query?: any, exactMatch?: boolean, user?: any, depth?: number): any;
|
|
460
|
+
/**
|
|
461
|
+
* Returns whether `query` filters on `version` itself, the one way a search on a `@TrackChanges` model sees
|
|
462
|
+
* past a record's current version.
|
|
463
|
+
*/
|
|
464
|
+
private static filtersOnVersion;
|
|
465
|
+
/**
|
|
466
|
+
* Restricts every OR branch of a MongoDB search on a tracked model to the current versions (`latest: true`),
|
|
467
|
+
* unless the query filters on `version`. A client-supplied `latest` is overwritten (or, with a `version` filter,
|
|
468
|
+
* removed): it is never a way to choose which rows match.
|
|
469
|
+
*/
|
|
470
|
+
private static applyLatestFilterMongo;
|
|
451
471
|
/**
|
|
452
472
|
* Compiles a single `PredicateNode` leaf to a MongoDB filter fragment (`{field: ...}`).
|
|
453
473
|
*/
|
|
@@ -346,6 +346,18 @@ export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
|
346
346
|
searchIdQuery(id: string, version?: number | string, includeDeleted?: boolean): any;
|
|
347
347
|
truncate(query: any, options: RepoFindOptions): Promise<void>;
|
|
348
348
|
update(obj: Partial<T>, existing: T, options?: RepoUpdateOptions<T>): Promise<T>;
|
|
349
|
+
/**
|
|
350
|
+
* Clears the `latest` marker from every version of the record `uid` older than `version`, the version just
|
|
351
|
+
* written. Always called after the new version was inserted, never before, so a crash in between leaves the record
|
|
352
|
+
* with two current versions (the next update fixes that) and never with none. Runs in the caller's transaction
|
|
353
|
+
* where there is one.
|
|
354
|
+
*/
|
|
355
|
+
private demoteOlderVersions;
|
|
356
|
+
/**
|
|
357
|
+
* Makes the newest stored version of the record `uid` its current one. Called after a version was purged, which
|
|
358
|
+
* may have been the current one.
|
|
359
|
+
*/
|
|
360
|
+
private promoteNewestVersion;
|
|
349
361
|
/**
|
|
350
362
|
* Maps an error thrown by one of `update()`'s writes: a duplicate key on the record's identity (`_id`/primary key
|
|
351
363
|
* or `(uid, version)`) is a lost optimistic-lock race (409 `INVALID_OBJECT_VERSION`), and a duplicate value of any
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HttpRequest, RequestHandler } from "../http/types.js";
|
|
2
|
+
import { type WebSocketAuthOptions } from "../auth/AuthMiddleware.js";
|
|
2
3
|
import { RateLimiter } from "../RateLimiter.js";
|
|
3
4
|
import { ElevationWindow, RateLimitOptions, WebSocketRouteOptions } from "../decorators/RouteDecorators.js";
|
|
4
5
|
/**
|
|
@@ -66,6 +67,16 @@ export declare class RouteUtils {
|
|
|
66
67
|
* @throws Error naming the route when an option is invalid.
|
|
67
68
|
*/
|
|
68
69
|
static resolveWebSocketOptions(options: WebSocketRouteOptions | undefined, routeName: string): WebSocketRouteOptions | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Validates the authentication options of a `@WebSocket()` route (`loginFallback`, `authCloseCode`,
|
|
72
|
+
* `authCloseReason`) and returns them for `AuthMiddleware.authWebSocket()`. A field that is `undefined` is left
|
|
73
|
+
* out and keeps its default, so a route without them behaves exactly as before.
|
|
74
|
+
*
|
|
75
|
+
* @param options The options declared on the route, if any.
|
|
76
|
+
* @param routeName A description of the route, used in the error message.
|
|
77
|
+
* @throws Error naming the route when an option is invalid.
|
|
78
|
+
*/
|
|
79
|
+
static resolveWebSocketAuthOptions(options: WebSocketRouteOptions | undefined, routeName: string): WebSocketAuthOptions | undefined;
|
|
69
80
|
/**
|
|
70
81
|
* Returns a canonical form of a request path for use in rate limit identifiers. The router percent-decodes
|
|
71
82
|
* `:param` values, so `/clients/%61bc` and `/clients/abc` reach the same handler. Keying on the raw path would
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rapidrest/service-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Provides all core functionality for RapidREST based backend services.",
|
|
5
5
|
"repository": "https://github.com/rapidrest/service-core.git",
|
|
6
6
|
"author": "RapidREST <rapidrests@gmail.com>",
|