@web-ts-toolkit/access-router 0.47.1 → 0.49.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 +529 -1
- package/advanced.d.mts +110 -13
- package/advanced.d.ts +110 -13
- package/advanced.js +422 -20
- package/advanced.mjs +424 -21
- package/index.d.mts +134 -45
- package/index.d.ts +134 -45
- package/index.js +8837 -4773
- package/index.mjs +8786 -4712
- package/llms.txt +138 -2
- package/package.json +3 -3
- package/{parsers-BidvJUu7.d.mts → parsers-DhUuvj9B.d.mts} +941 -55
- package/{parsers-BidvJUu7.d.ts → parsers-DhUuvj9B.d.ts} +941 -55
package/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Schema } from 'mongoose';
|
|
2
2
|
import { Response, NextFunction, RequestHandler, Router } from 'express';
|
|
3
|
-
import { A as AccessRouterBaseRequest,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AccessRouterBaseRequest, aj as GuardHook, aI as ModelRequest, d8 as AccessRuntime, V as DataRouterOptions, T as DataRequest, d9 as DataService, a4 as ExtendedDataRouterOptions, a8 as Filter, b2 as Projection, c0 as Sort, a$ as Populate, aJ as ModelRouterOptions, da as Service, db as PublicService, aS as ModelVirtualRecordAccess, aO as ModelVirtualDescriptor, aQ as ModelVirtualGetter, aR as ModelVirtualLeaf, a6 as ExtendedModelRouterOptions, cL as Validation, bQ as RootRouterOptions, dc as OpenApiRouterOptions, dd as OpenApiRegistryOptions, de as OpenApiRouteDescriptor, df as OpenApiDocumentOptions, dg as OpenApiParameter, dh as OpenApiSchema, di as OpenApiResponses, ah as GlobalOptions, Z as DefaultModelRouterOptions, a5 as ExtendedDefaultModelRouterOptions } from './parsers-DhUuvj9B.mjs';
|
|
4
|
+
export { dj as AccessRouterPermissionMap, dk as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, n as AjvValidatorLike, o as ArkTypeErrorsLike, p as ArkTypeLike, a7 as FieldOperationAccess, ai as GlobalPermissionValue, am as IoTsContextEntryLike, an as IoTsDecodeErrorLike, ao as IoTsDecoderLike, ap as JoiSchemaLike, aq as JoiValidationErrorDetailLike, aw as MaybePromise, ax as ModelBaseFilterHook, az as ModelDeleteHook, aA as ModelDocPermissionsHook, aC as ModelDocumentHook, aD as ModelHook, aF as ModelIdentifierHook, aG as ModelListHook, aH as ModelOverrideFilterHook, aK as ModelValidateHook, aL as ModelVirtualAccess, aM as ModelVirtualAccessRecord, aN as ModelVirtualContext, aP as ModelVirtualDoc, aT as ModelVirtuals, dl as OpenApiMethod, aU as OperationAccess, aX as PairedRouteAccess, a_ as PermissionSchema, dm as Permissions, bk as RequestSchemaAdapter, bl as RequestSchemaFailure, bm as RequestSchemaIssue, bn as RequestSchemaLike, bo as RequestSchemaOptions, bp as RequestSchemaResult, bq as RequestSchemaSuccess, br as RequestSchemaValidator, bT as RouteBaseAccess, bU as RouteGuardAccess, bV as RouteVariant, bW as RouteVariantAccess, c2 as StandardSchemaFailure, c3 as StandardSchemaInferOutput, c4 as StandardSchemaIssue, c5 as StandardSchemaPathSegment, c6 as StandardSchemaResult, c7 as StandardSchemaSuccess, c8 as StandardSchemaV1, cb as SubOperationAccess, cf as SubRouteGuardOptions, cr as SuperstructFailureLike, cs as SuperstructValidateLike, cF as ValibotIssueLike, cG as ValibotPathItemLike, cH as ValibotSafeParseLike, cI as ValibotSafeParseResult, cN as VineValidationErrorLike, cO as VineValidationMessageLike, cP as VineValidatorLike, cQ as VirtualSubModel, cR as WithVirtuals, cS as YupSchemaLike, cT as YupValidationErrorLike, dn as defaultRuntime, cU as defineRequestSchema, cV as fromAjv, cW as fromArkType, cX as fromIoTs, cY as fromJoi, cZ as fromStandardSchema, c_ as fromSuperstruct, c$ as fromValibot, d0 as fromVine, d1 as fromYup, d2 as fromZod } from './parsers-DhUuvj9B.mjs';
|
|
5
5
|
import JsonRouter from '@web-ts-toolkit/express-json-router';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
@@ -28,6 +28,7 @@ declare class DataRouter<TData = unknown> {
|
|
|
28
28
|
readonly runtime: AccessRuntime;
|
|
29
29
|
readonly dataName: string;
|
|
30
30
|
readonly router: JsonRouter;
|
|
31
|
+
/** Frozen construction-time snapshot. Read current policy with runtime.getDataOptions(dataName). */
|
|
31
32
|
readonly options: DataRouterOptions<TData>;
|
|
32
33
|
readonly fullBasePath: string;
|
|
33
34
|
constructor(dataName: string, initialOptions: DataRouterOptions<TData>, runtime?: AccessRuntime);
|
|
@@ -37,13 +38,28 @@ declare class DataRouter<TData = unknown> {
|
|
|
37
38
|
private registerOpenApiRoute;
|
|
38
39
|
private setCollectionRoutes;
|
|
39
40
|
private setDocumentRoutes;
|
|
40
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Update live behavior with a typed key/path or an options object. Dotted paths
|
|
43
|
+
* such as `operationAccess.basicRead` update one key; object assignment replaces
|
|
44
|
+
* supplied top-level values shallowly. The construction-time options snapshot stays fixed.
|
|
45
|
+
*/
|
|
46
|
+
set<K extends keyof ExtendedDataRouterOptions<TData>>(key: K, value: ExtendedDataRouterOptions<TData>[K]): this;
|
|
41
47
|
set(options: DataRouterOptions<TData>): this;
|
|
42
|
-
|
|
48
|
+
/** Set one live option/path; `setOption('operationAccess.basicRead', undefined)` restores inheritance. */
|
|
49
|
+
setOption<K extends keyof ExtendedDataRouterOptions<TData>>(key: K, option: ExtendedDataRouterOptions<TData>[K]): this;
|
|
50
|
+
/** Shallowly replace supplied top-level options; an operationAccess object replaces that entire rule object. */
|
|
43
51
|
setOptions(options: DataRouterOptions<TData>): this;
|
|
44
52
|
data: SetTargetOption$1<DataRouter<TData>, DataRouterOptions<TData>['data']>;
|
|
45
53
|
listHardLimit: SetTargetOption$1<DataRouter<TData>, DataRouterOptions<TData>['listHardLimit']>;
|
|
54
|
+
/** Base-operation field grants; basic/advanced route guards belong to operationAccess. */
|
|
46
55
|
permissionSchema: SetTargetOption$1<DataRouter<TData>, DataRouterOptions<TData>['permissionSchema']>;
|
|
56
|
+
/**
|
|
57
|
+
* Live list/read guards plus basicList/advancedList/basicRead/advancedRead.
|
|
58
|
+
* `operationAccess('basicRead', false)` updates one key and denies GET /:id
|
|
59
|
+
* (and HEAD) with HTTP 401; registered POST reads still inherit `read`.
|
|
60
|
+
* `operationAccess({ list: true, read: true })` replaces the whole rule object,
|
|
61
|
+
* not a deep merge. Use setOption with undefined to restore variant inheritance.
|
|
62
|
+
*/
|
|
47
63
|
operationAccess: SetTargetOption$1<DataRouter<TData>, DataRouterOptions<TData>['operationAccess']>;
|
|
48
64
|
baseFilter: SetTargetOption$1<DataRouter<TData>, DataRouterOptions<TData>['baseFilter']>;
|
|
49
65
|
/**
|
|
@@ -98,150 +114,223 @@ type SetTargetOption<TRouter, TOption> = {
|
|
|
98
114
|
(option: TOption): TRouter;
|
|
99
115
|
(key: string, option: unknown): TRouter;
|
|
100
116
|
};
|
|
101
|
-
declare class ModelRouter<TModel = unknown
|
|
117
|
+
declare class ModelRouter<TModel = unknown, TVirtuals extends object = Record<never, never>> {
|
|
102
118
|
readonly runtime: AccessRuntime;
|
|
103
119
|
readonly modelName: string;
|
|
104
120
|
readonly router: JsonRouter;
|
|
105
121
|
readonly model: Model;
|
|
106
|
-
|
|
122
|
+
/** Frozen construction-time snapshot. Read current policy with runtime.getModelOptions(modelName). */
|
|
123
|
+
readonly options: ModelRouterOptions<TModel, TVirtuals>;
|
|
107
124
|
readonly fullBasePath: string;
|
|
108
|
-
constructor(modelName: string, initialOptions: ModelRouterOptions<TModel>, runtime?: AccessRuntime);
|
|
109
|
-
static fromModel<TModel
|
|
125
|
+
constructor(modelName: string, initialOptions: ModelRouterOptions<TModel, TVirtuals>, runtime?: AccessRuntime);
|
|
126
|
+
static fromModel<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, initialOptions: ModelRouterOptions<TModel, TVirtuals>, runtime?: AccessRuntime): ModelRouter<TModel, TVirtuals>;
|
|
110
127
|
private getRequestSchema;
|
|
111
|
-
getService(req: ModelRequest): Service<TModel>;
|
|
112
|
-
getPublicService(req: ModelRequest): PublicService<TModel>;
|
|
128
|
+
getService(req: ModelRequest): Service<TModel, TVirtuals>;
|
|
129
|
+
getPublicService(req: ModelRequest): PublicService<TModel, TVirtuals>;
|
|
113
130
|
private assertAllowed;
|
|
114
131
|
private registerOpenApiRoute;
|
|
115
132
|
private setCollectionRoutes;
|
|
116
133
|
private setDocumentRoutes;
|
|
117
134
|
private setSubDocumentRoutes;
|
|
118
135
|
private logEndpoints;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Update live behavior with a typed key/path or an options object. Dotted paths
|
|
138
|
+
* such as `operationAccess.basicRead` update one key; object assignment replaces
|
|
139
|
+
* supplied top-level values shallowly. The construction-time options snapshot stays fixed.
|
|
140
|
+
*/
|
|
141
|
+
set<K extends Extract<keyof TVirtuals, string> & string, A extends ModelVirtualRecordAccess>(key: `virtuals.${K}.${A}`, value: ModelVirtualDescriptor<TModel, K extends keyof TVirtuals ? TVirtuals[K] : unknown> | ModelVirtualGetter<TModel, K extends keyof TVirtuals ? TVirtuals[K] : unknown>): this;
|
|
142
|
+
set<K extends Extract<keyof TVirtuals, string> & string>(key: `virtuals.${K}`, value: ModelVirtualLeaf<TModel, K extends keyof TVirtuals ? TVirtuals[K] : unknown>): this;
|
|
143
|
+
set<K extends keyof ExtendedModelRouterOptions<TModel, TVirtuals>>(key: K, value: ExtendedModelRouterOptions<TModel, TVirtuals>[K]): this;
|
|
144
|
+
set(options: ModelRouterOptions<TModel, TVirtuals>): this;
|
|
145
|
+
/** Set one live option/path; `setOption('operationAccess.basicRead', undefined)` restores inheritance. */
|
|
146
|
+
setOption<K extends keyof ExtendedModelRouterOptions<TModel, TVirtuals>>(key: K, option: ExtendedModelRouterOptions<TModel, TVirtuals>[K]): this;
|
|
147
|
+
/** Shallowly replace supplied top-level options; an operationAccess object replaces that entire rule object. */
|
|
148
|
+
setOptions(options: ModelRouterOptions<TModel, TVirtuals>): this;
|
|
123
149
|
/**
|
|
124
150
|
* The maximum limit of the number of documents returned from the `list` operation.
|
|
125
151
|
*/
|
|
126
|
-
listHardLimit: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['listHardLimit']>;
|
|
152
|
+
listHardLimit: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['listHardLimit']>;
|
|
127
153
|
/**
|
|
128
154
|
* The object schema to define the access control policy for each model field.
|
|
155
|
+
* Virtual permission keys (`fullAddress`, etc.) are typed via `TVirtuals`.
|
|
156
|
+
* Basic/advanced route guards belong to operationAccess, not field-rule objects.
|
|
157
|
+
*/
|
|
158
|
+
permissionSchema: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['permissionSchema']>;
|
|
159
|
+
/**
|
|
160
|
+
* Package-level computed fields (VIRT-01, VIRT-00A D1-D8).
|
|
161
|
+
* Mutable post-construction (not a build-time key). Supports
|
|
162
|
+
* `virtuals({...})`, `virtuals(name, descriptor)`, and dotted
|
|
163
|
+
* `set('virtuals.<name>.<access>', descriptor)` forms. Exact →
|
|
164
|
+
* `.default` → bare resolution applies; inapplicable registered names stay
|
|
165
|
+
* virtual. Configuration is validated before commit against the receiving
|
|
166
|
+
* Mongoose schema + child scopes, protected permission-field overlaps,
|
|
167
|
+
* `_id`/reserved paths, and dotted names; rejected mutations preserve the
|
|
168
|
+
* previous valid configuration.
|
|
169
|
+
*
|
|
170
|
+
* Reachable from the root (`@web-ts-toolkit/access-router`) and the
|
|
171
|
+
* existing `./advanced` interface barrel; no new subpaths. Selected
|
|
172
|
+
* virtual outputs are optional (`Partial`) because authorization, absent
|
|
173
|
+
* dependencies, `undefined`, and fail-closed errors can omit them.
|
|
174
|
+
*
|
|
175
|
+
* @example Shortest typed happy-path (persisted model lacks `fullAddress`):
|
|
176
|
+
* ```ts
|
|
177
|
+
* import acl from '@web-ts-toolkit/access-router';
|
|
178
|
+
* interface User { name: string; address: string; }
|
|
179
|
+
* interface UserVirtuals { fullAddress: string; }
|
|
180
|
+
* const router = acl.createRouter<User, UserVirtuals>('User', {
|
|
181
|
+
* permissionSchema: {
|
|
182
|
+
* name: { read: true },
|
|
183
|
+
* address: { read: 'canViewAddress' },
|
|
184
|
+
* fullAddress: { read: 'canViewAddress' },
|
|
185
|
+
* },
|
|
186
|
+
* virtuals: {
|
|
187
|
+
* fullAddress: {
|
|
188
|
+
* dependsOn: ['address'],
|
|
189
|
+
* read: async function (doc) {
|
|
190
|
+
* if (doc.address === undefined) return undefined;
|
|
191
|
+
* return `addr:${doc.address}`;
|
|
192
|
+
* },
|
|
193
|
+
* },
|
|
194
|
+
* },
|
|
195
|
+
* });
|
|
196
|
+
* router.virtuals({
|
|
197
|
+
* fullAddress: {
|
|
198
|
+
* dependsOn: ['address'],
|
|
199
|
+
* read: async function (doc) {
|
|
200
|
+
* if (doc.address === undefined) return undefined;
|
|
201
|
+
* return `addr:${doc.address}`;
|
|
202
|
+
* },
|
|
203
|
+
* },
|
|
204
|
+
* });
|
|
205
|
+
* router.set('virtuals.fullAddress.read', {
|
|
206
|
+
* get: async function (doc) {
|
|
207
|
+
* if (doc.address === undefined) return undefined;
|
|
208
|
+
* return `addr:${doc.address}`;
|
|
209
|
+
* },
|
|
210
|
+
* dependsOn: ['address'],
|
|
211
|
+
* });
|
|
212
|
+
* void router;
|
|
213
|
+
* ```
|
|
129
214
|
*/
|
|
130
|
-
|
|
215
|
+
virtuals: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['virtuals']>;
|
|
131
216
|
/**
|
|
132
217
|
* The object field to store the document permissions.
|
|
133
218
|
*/
|
|
134
|
-
documentPermissionField: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['documentPermissionField']>;
|
|
219
|
+
documentPermissionField: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['documentPermissionField']>;
|
|
135
220
|
/**
|
|
136
221
|
* The model fields always selected for ACL and response shaping.
|
|
137
222
|
*/
|
|
138
|
-
alwaysSelectFields: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['alwaysSelectFields']>;
|
|
223
|
+
alwaysSelectFields: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['alwaysSelectFields']>;
|
|
139
224
|
/**
|
|
140
225
|
* The function called in the process of generating document permissions.
|
|
141
226
|
*/
|
|
142
|
-
docPermissions: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['docPermissions']>;
|
|
227
|
+
docPermissions: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['docPermissions']>;
|
|
143
228
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
229
|
+
* Configure live base and basic/advanced route guards. Only undefined inherits;
|
|
230
|
+
* selected false denies with HTTP 401 without removing routes or OpenAPI entries.
|
|
231
|
+
* `operationAccess('basicRead', false)` updates one key, and
|
|
232
|
+
* `operationAccess('subs.comments.basicRead', false)` updates a field-specific key.
|
|
233
|
+
* `operationAccess({ list: true, read: true })` replaces the whole rule object,
|
|
234
|
+
* not a deep merge. Use setOption with undefined to restore variant inheritance.
|
|
146
235
|
*/
|
|
147
|
-
operationAccess: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['operationAccess']>;
|
|
236
|
+
operationAccess: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['operationAccess']>;
|
|
148
237
|
/**
|
|
149
238
|
* The base filter definitions applied in every query transaction.
|
|
150
239
|
* @operation `list`, `read`, `update`, `delete`
|
|
151
240
|
*/
|
|
152
|
-
baseFilter: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['baseFilter']>;
|
|
241
|
+
baseFilter: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['baseFilter']>;
|
|
153
242
|
/**
|
|
154
243
|
* Trusted filter replacements applied before base-filter composition.
|
|
155
244
|
* They may replace ordinary filters, but cannot replace an existing `false` denial.
|
|
156
245
|
* Returning `false` denies the transaction.
|
|
157
246
|
* @operation `list`, `read`, `update`, `delete`
|
|
158
247
|
*/
|
|
159
|
-
overrideFilter: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['overrideFilter']>;
|
|
248
|
+
overrideFilter: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['overrideFilter']>;
|
|
160
249
|
/**
|
|
161
250
|
* Hook
|
|
162
251
|
*
|
|
163
252
|
* The function called before a new/update document data is processed in `prepare` hooks. This method is used to validate `write data` and throw an error if not valid.
|
|
164
253
|
* @operation `create`, `update`
|
|
165
254
|
*/
|
|
166
|
-
validate: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['validate']>;
|
|
255
|
+
validate: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['validate']>;
|
|
167
256
|
/**
|
|
168
257
|
* Hook
|
|
169
258
|
*
|
|
170
259
|
* The function called before a new document is created or an existing document is updated. This method is used to process raw data passed into the API endpoints.
|
|
171
260
|
* @operation `create`, `update`
|
|
172
261
|
*/
|
|
173
|
-
prepare: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['prepare']>;
|
|
262
|
+
prepare: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['prepare']>;
|
|
174
263
|
/**
|
|
175
264
|
* Hook
|
|
176
265
|
*
|
|
177
266
|
* The function called before an updated document is saved.
|
|
178
267
|
* @operation `update`
|
|
179
268
|
*/
|
|
180
|
-
transform: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['transform']>;
|
|
269
|
+
transform: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['transform']>;
|
|
181
270
|
/**
|
|
182
271
|
* Hook
|
|
183
272
|
*
|
|
184
273
|
* The function called after a new document is created or an updated document is saved.
|
|
185
274
|
* @operation `create`, `update`
|
|
186
275
|
*/
|
|
187
|
-
afterPersist: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['afterPersist']>;
|
|
276
|
+
afterPersist: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['afterPersist']>;
|
|
188
277
|
/**
|
|
189
278
|
* Hook
|
|
190
279
|
*
|
|
191
280
|
* The function called after an updated document changes have been finalized.
|
|
192
281
|
* @operation `update`
|
|
193
282
|
*/
|
|
194
|
-
onChange: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['onChange']>;
|
|
283
|
+
onChange: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['onChange']>;
|
|
195
284
|
/**
|
|
196
285
|
* Hook
|
|
197
286
|
*
|
|
198
287
|
* The function called before a document is deleted.
|
|
199
288
|
* @operation `delete`
|
|
200
289
|
*/
|
|
201
|
-
beforeDelete: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['beforeDelete']>;
|
|
290
|
+
beforeDelete: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['beforeDelete']>;
|
|
202
291
|
/**
|
|
203
292
|
* Hook
|
|
204
293
|
*
|
|
205
294
|
* The function called after a document is deleted.
|
|
206
295
|
* @operation `delete`
|
|
207
296
|
*/
|
|
208
|
-
afterDelete: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['afterDelete']>;
|
|
297
|
+
afterDelete: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['afterDelete']>;
|
|
209
298
|
/**
|
|
210
299
|
* Hook
|
|
211
300
|
*
|
|
212
301
|
* The function called before response data is sent. This method is used to process raw data to apply custom logic before sending the result.
|
|
213
302
|
* @operation `list`, `read`, `create`, `update`
|
|
214
303
|
*/
|
|
215
|
-
decorate: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['decorate']>;
|
|
304
|
+
decorate: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['decorate']>;
|
|
216
305
|
/**
|
|
217
306
|
* Hook
|
|
218
307
|
*
|
|
219
308
|
* The functions are called before response data is sent and after `decorate` hooks run. This method is used to process and filter multiple document objects before sending the result.
|
|
220
309
|
* @operation `list`
|
|
221
310
|
*/
|
|
222
|
-
decorateAll: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['decorateAll']>;
|
|
311
|
+
decorateAll: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['decorateAll']>;
|
|
223
312
|
/**
|
|
224
313
|
* The field matched against the `id` route param.
|
|
225
314
|
* @operation `read`, `update`, `delete`
|
|
226
315
|
*/
|
|
227
|
-
idField: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['idField']>;
|
|
316
|
+
idField: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['idField']>;
|
|
228
317
|
/**
|
|
229
318
|
* The function used to resolve the `id` route param into a document filter.
|
|
230
319
|
* @operation `read`, `update`, `delete`
|
|
231
320
|
*/
|
|
232
|
-
resolveIdFilter: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['resolveIdFilter']>;
|
|
321
|
+
resolveIdFilter: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['resolveIdFilter']>;
|
|
233
322
|
/**
|
|
234
323
|
* The route segment used for advanced query endpoints.
|
|
235
324
|
*/
|
|
236
|
-
queryRouteSegment: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['queryRouteSegment']>;
|
|
325
|
+
queryRouteSegment: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['queryRouteSegment']>;
|
|
237
326
|
/**
|
|
238
327
|
* The route segment used for advanced mutation endpoints.
|
|
239
328
|
*/
|
|
240
|
-
mutationRouteSegment: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['mutationRouteSegment']>;
|
|
329
|
+
mutationRouteSegment: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['mutationRouteSegment']>;
|
|
241
330
|
/**
|
|
242
331
|
* The default values used when missing in the operations.
|
|
243
332
|
*/
|
|
244
|
-
defaults: SetTargetOption<ModelRouter<TModel>, ModelRouterOptions<TModel>['defaults']>;
|
|
333
|
+
defaults: SetTargetOption<ModelRouter<TModel, TVirtuals>, ModelRouterOptions<TModel, TVirtuals>['defaults']>;
|
|
245
334
|
get routes(): Router;
|
|
246
335
|
}
|
|
247
336
|
|
|
@@ -338,10 +427,10 @@ declare const setGlobalOption: <K extends keyof GlobalOptions>(key: K, value: Gl
|
|
|
338
427
|
declare const getGlobalOptions: () => GlobalOptions;
|
|
339
428
|
declare const getGlobalOption: <K extends keyof GlobalOptions>(key: K, defaultValue?: GlobalOptions[K]) => GlobalOptions[K];
|
|
340
429
|
|
|
341
|
-
declare const setModelOptions: <TModel = unknown
|
|
342
|
-
declare const setModelOption: <K extends keyof ExtendedModelRouterOptions<TModel>, TModel = unknown
|
|
343
|
-
declare const getModelOptions: <TModel = unknown
|
|
344
|
-
declare const getModelOption: <K extends keyof ExtendedModelRouterOptions<TModel>, TModel = unknown
|
|
430
|
+
declare const setModelOptions: <TModel = unknown, TVirtuals extends object = Record<never, never>>(modelName: string, options: ModelRouterOptions<TModel, TVirtuals>) => void;
|
|
431
|
+
declare const setModelOption: <K extends keyof ExtendedModelRouterOptions<TModel, TVirtuals>, TModel = unknown, TVirtuals extends object = Record<never, never>>(modelName: string, key: K, value: ExtendedModelRouterOptions<TModel, TVirtuals>[K]) => void;
|
|
432
|
+
declare const getModelOptions: <TModel = unknown, TVirtuals extends object = Record<never, never>>(modelName: string) => ModelRouterOptions<TModel, TVirtuals>;
|
|
433
|
+
declare const getModelOption: <K extends keyof ExtendedModelRouterOptions<TModel, TVirtuals>, TModel = unknown, TVirtuals extends object = Record<never, never>>(modelName: string, key: K | string, defaultValue?: ExtendedModelRouterOptions<TModel, TVirtuals>[K]) => ExtendedModelRouterOptions<TModel, TVirtuals>[K];
|
|
345
434
|
declare const getModelNames: () => string[];
|
|
346
435
|
declare const getModelJsonSchema: (modelName: string) => Record<string, unknown>;
|
|
347
436
|
declare const registerModelInstance: <TModel>(modelName: string, model: mongoose.Model<TModel>) => void;
|
|
@@ -382,8 +471,8 @@ interface OpLogContext {
|
|
|
382
471
|
}
|
|
383
472
|
|
|
384
473
|
type CreateRouter = {
|
|
385
|
-
<TModel
|
|
386
|
-
<TModel
|
|
474
|
+
<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
475
|
+
<TModel, TVirtuals extends object = Record<never, never>>(modelName: string, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
387
476
|
(options: RootRouterOptions): RootRouter;
|
|
388
477
|
};
|
|
389
478
|
type CreateDataRouter = {
|
|
@@ -428,4 +517,4 @@ type AccessRuntimeApi = typeof macl & Wtt;
|
|
|
428
517
|
declare function createAccessRuntime(): AccessRuntimeApi;
|
|
429
518
|
declare const acl: AccessRuntimeApi;
|
|
430
519
|
|
|
431
|
-
export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, ExtendedDefaultModelRouterOptions, ExtendedModelRouterOptions, GlobalOptions, GuardHook, type GuardModelCondition, type GuardModelConditionID, ModelRouter, ModelRouterOptions, type OpLogContext, OpenApiCollisionError, OpenApiDocumentOptions, OpenApiRegistry, OpenApiRegistryOptions, OpenApiRouteDescriptor, OpenApiRouterOptions, RootRouter, RootRouterOptions, Validation, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelInstance, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, hasModelInstance, isLevelEnabled, permissionsPlugin, redactFilter, redactPayload, registerModelInstance, safeStringify, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
|
|
520
|
+
export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, DefaultModelRouterOptions, ExtendedDataRouterOptions, ExtendedDefaultModelRouterOptions, ExtendedModelRouterOptions, GlobalOptions, GuardHook, type GuardModelCondition, type GuardModelConditionID, ModelRouter, ModelRouterOptions, ModelVirtualDescriptor, ModelVirtualGetter, ModelVirtualLeaf, ModelVirtualRecordAccess, type OpLogContext, OpenApiCollisionError, OpenApiDocumentOptions, OpenApiRegistry, OpenApiRegistryOptions, OpenApiRouteDescriptor, OpenApiRouterOptions, RootRouter, RootRouterOptions, Validation, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelInstance, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, hasModelInstance, isLevelEnabled, permissionsPlugin, redactFilter, redactPayload, registerModelInstance, safeStringify, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
|