@web-ts-toolkit/access-router 0.4.0 → 0.6.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 +93 -7
- package/advanced.d.mts +38 -40
- package/advanced.d.ts +38 -40
- package/advanced.js +5 -5
- package/advanced.mjs +5 -4
- package/index.d.mts +81 -4
- package/index.d.ts +81 -4
- package/index.js +1160 -545
- package/index.mjs +990 -385
- package/llms.txt +53 -0
- package/package.json +13 -9
- package/{parsers-CsyGHYQR.d.mts → parsers-Cj4r_G4g.d.mts} +35 -17
- package/{parsers-CsyGHYQR.d.ts → parsers-Cj4r_G4g.d.ts} +35 -17
package/llms.txt
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @web-ts-toolkit/access-router
|
|
2
|
+
|
|
3
|
+
ACL-aware Express routers and in-memory data services for Mongoose-backed APIs.
|
|
4
|
+
|
|
5
|
+
## Main Patterns
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import acl from '@web-ts-toolkit/access-router';
|
|
9
|
+
|
|
10
|
+
// configure global permissions
|
|
11
|
+
acl.setGlobalOptions({ globalPermissions(req) { return []; } });
|
|
12
|
+
|
|
13
|
+
// model CRUD router from a Mongoose model name
|
|
14
|
+
const userRouter = acl.createRouter('User', { basePath: '/users' });
|
|
15
|
+
|
|
16
|
+
// in-memory data router
|
|
17
|
+
const fruitRouter = acl.createDataRouter('fruit', {
|
|
18
|
+
basePath: '/fruit',
|
|
19
|
+
idField: 'id',
|
|
20
|
+
data: [{ id: 'apple', name: 'Apple' }],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// OpenAPI + Swagger UI
|
|
24
|
+
const docsRouter = acl.createOpenApiRouter({ title: 'Example API', version: '1.0.0' });
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Validation adapters:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { fromZod, defineRequestSchema } from '@web-ts-toolkit/access-router';
|
|
31
|
+
|
|
32
|
+
const validator = fromZod(z.object({ name: z.string() }));
|
|
33
|
+
const schema = defineRequestSchema(validator);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Subpath imports:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { copyAndDepopulate } from '@web-ts-toolkit/access-router/processors';
|
|
40
|
+
import { AccessRuntime, defaultRuntime } from '@web-ts-toolkit/access-router/advanced';
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Gotchas
|
|
44
|
+
|
|
45
|
+
- peer dependencies: `express >= 5` and `mongoose >= 8`
|
|
46
|
+
- default export `acl` and named exports are both available; default is preferred for the runtime API
|
|
47
|
+
- `createRouter('User', ...)` takes a Mongoose model name string, not the model instance
|
|
48
|
+
- `createDataRouter(...)` holds data in-memory; use it for lightweight/non-persisted resources
|
|
49
|
+
|
|
50
|
+
## Pointers
|
|
51
|
+
|
|
52
|
+
- README: installation, quickstart, main exports
|
|
53
|
+
- website/docs/packages/access-router/: full documentation (routing, configuration, hooks, validation, openapi)
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-ts-toolkit/access-router",
|
|
3
|
-
"description": "
|
|
4
|
-
"
|
|
3
|
+
"description": "ACL-aware Express routers and in-memory data services for Mongoose-backed APIs",
|
|
4
|
+
"homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router",
|
|
5
|
+
"version": "0.6.0",
|
|
6
|
+
"sideEffects": false,
|
|
5
7
|
"keywords": [
|
|
6
8
|
"express",
|
|
7
9
|
"mongoose",
|
|
8
|
-
"
|
|
10
|
+
"acl",
|
|
11
|
+
"crud",
|
|
12
|
+
"openapi",
|
|
9
13
|
"access-router",
|
|
10
14
|
"router"
|
|
11
15
|
],
|
|
@@ -32,12 +36,15 @@
|
|
|
32
36
|
"default": "./processors.js"
|
|
33
37
|
}
|
|
34
38
|
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20"
|
|
41
|
+
},
|
|
35
42
|
"dependencies": {
|
|
36
|
-
"@web-ts-toolkit/express-json-router": "0.
|
|
37
|
-
"
|
|
43
|
+
"@web-ts-toolkit/express-json-router": "0.6.0",
|
|
44
|
+
"@web-ts-toolkit/utils": "0.6.0",
|
|
45
|
+
"just-diff": "^6.0.2",
|
|
38
46
|
"mongoose-schema-jsonschema": "^4.0.1",
|
|
39
47
|
"sift": "^17.1.3",
|
|
40
|
-
"@web-ts-toolkit/utils": "0.4.0",
|
|
41
48
|
"winston": "^3.19.0",
|
|
42
49
|
"zod": "^4.1.12"
|
|
43
50
|
},
|
|
@@ -49,9 +56,6 @@
|
|
|
49
56
|
"bugs": {
|
|
50
57
|
"url": "https://github.com/egose/web-ts-toolkit/issues"
|
|
51
58
|
},
|
|
52
|
-
"engines": {
|
|
53
|
-
"node": ">=20"
|
|
54
|
-
},
|
|
55
59
|
"license": "Apache-2.0",
|
|
56
60
|
"repository": {
|
|
57
61
|
"type": "git",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import mongoose from 'mongoose';
|
|
3
|
-
import { Diff } from 'deep-diff';
|
|
4
3
|
import express from 'express';
|
|
5
4
|
|
|
6
5
|
interface BooleanObject {
|
|
@@ -26,8 +25,8 @@ type Permissions = Permission;
|
|
|
26
25
|
type AccessRouterPermissions = Permission;
|
|
27
26
|
|
|
28
27
|
declare class Base<TModel = unknown> {
|
|
29
|
-
req: ModelRequest;
|
|
30
|
-
modelName: string;
|
|
28
|
+
protected req: ModelRequest;
|
|
29
|
+
protected modelName: string;
|
|
31
30
|
constructor(req: ModelRequest, modelName: string);
|
|
32
31
|
decorate<T>(doc: T, access: DecorateAccess, context: ModelHookContext): Promise<T>;
|
|
33
32
|
decorateAll<T>(docs: T[], access: DecorateAllAccess, context: ModelHookContext): Promise<T[]>;
|
|
@@ -98,19 +97,17 @@ declare class Model {
|
|
|
98
97
|
find({ filter, select, sort, populate, limit, skip, lean }: FindProps): mongoose.Query<any[], any, {}, any, "find", {}>;
|
|
99
98
|
validateSort(sort: SortType, logError?: (msg: string, ...args: unknown[]) => void): boolean;
|
|
100
99
|
findOne({ filter, select, sort, populate, lean }: FindOneProps): mongoose.Query<any, any, {}, any, "findOne", {}>;
|
|
101
|
-
findOneAndDelete(filter: any): mongoose.Query<any, any, {}, any, "findOneAndDelete", {}>;
|
|
102
100
|
exists(filter: any): mongoose.Query<any, any, {}, any, "findOne", {}>;
|
|
103
101
|
countDocuments(filter?: {}): mongoose.Query<number, any, {}, any, "countDocuments", {}>;
|
|
104
|
-
estimatedDocumentCount(): mongoose.Query<number, any, {}, any, "estimatedDocumentCount", {}>;
|
|
105
102
|
distinct(field: string, conditions?: {}): mongoose.Query<any[], any, {}, any, "distinct", {}>;
|
|
106
103
|
}
|
|
107
104
|
|
|
108
105
|
declare class Service<TModel = unknown> extends Base<TModel> {
|
|
109
|
-
model: Model;
|
|
110
|
-
options: ModelRouterOptions<TModel>;
|
|
106
|
+
protected model: Model;
|
|
107
|
+
protected options: ModelRouterOptions<TModel>;
|
|
111
108
|
defaults: Defaults<TModel>;
|
|
112
|
-
baseFields: string[];
|
|
113
|
-
baseFieldsExt: string[];
|
|
109
|
+
protected baseFields: string[];
|
|
110
|
+
protected baseFieldsExt: string[];
|
|
114
111
|
private asServiceHookContext;
|
|
115
112
|
constructor(req: ModelRequest, modelName: string);
|
|
116
113
|
findOne(filter: Filter<TModel>, args?: FindOneArgs<TModel>, options?: FindOneOptions): Promise<SingleResult<TModel> | ErrorResult>;
|
|
@@ -210,10 +207,10 @@ declare class PublicService<TModel = unknown> extends Service<TModel> {
|
|
|
210
207
|
}
|
|
211
208
|
|
|
212
209
|
declare class DataService<T> {
|
|
213
|
-
req: DataRequest;
|
|
214
|
-
dataName: string;
|
|
215
|
-
options: DataRouterOptions<T>;
|
|
216
|
-
data: T[];
|
|
210
|
+
protected req: DataRequest;
|
|
211
|
+
protected dataName: string;
|
|
212
|
+
protected options: DataRouterOptions<T>;
|
|
213
|
+
protected data: T[];
|
|
217
214
|
constructor(req: DataRequest, dataName: string);
|
|
218
215
|
findOne<TSelect extends Projection | undefined = undefined>(filter: DataFilter<T>, args?: DataFindOneArgs<T, TSelect>, options?: DataFindOneOptions): Promise<SingleResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
219
216
|
findById<TSelect extends Projection | undefined = undefined>(id: string, args?: DataFindOneArgs<T, TSelect>, options?: DataFindOneOptions): Promise<SingleResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
@@ -564,6 +561,11 @@ interface SubPopulate {
|
|
|
564
561
|
interface KeyValue {
|
|
565
562
|
[key: string]: unknown;
|
|
566
563
|
}
|
|
564
|
+
interface Change {
|
|
565
|
+
op: 'add' | 'replace' | 'remove';
|
|
566
|
+
path: Array<string | number>;
|
|
567
|
+
value?: unknown;
|
|
568
|
+
}
|
|
567
569
|
interface ModelHookContext {
|
|
568
570
|
modelName: string;
|
|
569
571
|
mongooseModel: mongoose.Model<unknown>;
|
|
@@ -576,7 +578,7 @@ interface ModelHookContext {
|
|
|
576
578
|
preparedData?: Record<string, unknown>;
|
|
577
579
|
allowedFields?: string[];
|
|
578
580
|
modifiedPaths?: string[];
|
|
579
|
-
changes?:
|
|
581
|
+
changes?: Change[];
|
|
580
582
|
docPermissions?: KeyValue;
|
|
581
583
|
resolvedQuery?: {
|
|
582
584
|
filter?: Filter;
|
|
@@ -845,7 +847,7 @@ type HookChain<TValue, TContext, TRequest extends AccessRouterRequest = AccessRo
|
|
|
845
847
|
type ValidateRule = boolean | unknown[];
|
|
846
848
|
type ValidateHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, allowedData: unknown, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<ValidateRule>;
|
|
847
849
|
type DocPermissionsHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, doc: unknown, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<Record<string, unknown>>;
|
|
848
|
-
type ChangeHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, previousValue: unknown, nextValue: unknown, changes:
|
|
850
|
+
type ChangeHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, previousValue: unknown, nextValue: unknown, changes: Change[], context: ModelHookContext) => MaybePromise<void>;
|
|
849
851
|
type DeleteHook<TValue = unknown, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: TValue, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<void>;
|
|
850
852
|
type DocumentHook<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: ModelDocument<TValue>, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<ModelDocument<TValue>>;
|
|
851
853
|
type DocumentHookChain<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = DocumentHook<TValue, TRequest> | Array<DocumentHook<TValue, TRequest>>;
|
|
@@ -886,6 +888,10 @@ type RequestSchemaResult<T = unknown> = RequestSchemaSuccess<T> | RequestSchemaF
|
|
|
886
888
|
type RequestSchemaValidator<T = unknown> = (value: unknown) => RequestSchemaResult<T> | Promise<RequestSchemaResult<T>>;
|
|
887
889
|
type RequestSchemaAdapter<T = unknown> = {
|
|
888
890
|
validate: RequestSchemaValidator<T>;
|
|
891
|
+
openapi?: Record<string, unknown>;
|
|
892
|
+
};
|
|
893
|
+
type RequestSchemaOptions = {
|
|
894
|
+
openapi?: Record<string, unknown>;
|
|
889
895
|
};
|
|
890
896
|
type StandardSchemaPathSegment = {
|
|
891
897
|
key: PropertyKey;
|
|
@@ -1403,7 +1409,19 @@ declare function parseQuery<TSchema extends z.ZodTypeAny>(schema: TSchema, value
|
|
|
1403
1409
|
declare function parseBody<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown): z.output<TSchema>;
|
|
1404
1410
|
declare function parseBodyWithSchema<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown, userSchema?: RequestSchemaLike): Promise<z.output<TSchema>>;
|
|
1405
1411
|
declare function parseNestedBodyWithSchema(schema: z.ZodTypeAny, value: unknown, nestedKey: string, userSchema?: RequestSchemaLike): Promise<Record<string, unknown>>;
|
|
1406
|
-
|
|
1412
|
+
/**
|
|
1413
|
+
* Wraps a request validator into a request schema adapter used by `access-router`.
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* const schema = defineRequestSchema(fromZod(z.object({ name: z.string() })));
|
|
1417
|
+
*/
|
|
1418
|
+
declare function defineRequestSchema<T = unknown>(validator: RequestSchemaValidator<T>, options?: RequestSchemaOptions): RequestSchemaAdapter<T>;
|
|
1419
|
+
/**
|
|
1420
|
+
* Adapts a Zod schema into a `RequestSchemaValidator` for `access-router`.
|
|
1421
|
+
*
|
|
1422
|
+
* @example
|
|
1423
|
+
* const validator = fromZod(z.object({ name: z.string() }));
|
|
1424
|
+
*/
|
|
1407
1425
|
declare function fromZod<TSchema extends z.ZodTypeAny>(schema: TSchema): RequestSchemaValidator<z.output<TSchema>>;
|
|
1408
1426
|
declare function fromStandardSchema<TSchema extends StandardSchemaV1>(schema: TSchema): RequestSchemaValidator<StandardSchemaInferOutput<TSchema>>;
|
|
1409
1427
|
declare function fromYup<TSchema extends YupSchemaLike>(schema: TSchema): RequestSchemaValidator;
|
|
@@ -1415,4 +1433,4 @@ declare function fromIoTs<TValue = unknown>(decoder: IoTsDecoderLike<TValue>): R
|
|
|
1415
1433
|
declare function fromSuperstruct<TStruct, TOutput = unknown>(struct: TStruct, validate: SuperstructValidateLike): RequestSchemaValidator<TOutput>;
|
|
1416
1434
|
declare function fromVine<TValue = unknown>(validator: VineValidatorLike<TValue>): RequestSchemaValidator<TValue>;
|
|
1417
1435
|
|
|
1418
|
-
export {
|
|
1436
|
+
export { FilterOperator as $, type AccessRouterBaseRequest as A, type BaseFilterAccess as B, type Change as C, type DataBaseFilterHook as D, type DataFindOptions as E, type DataHook as F, type DataHookContext as G, type DataIdentifierHook as H, type DataListHook as I, type DataOverrideFilterHook as J, type DataRequest as K, type DataRequestSchemas as L, type DataRouterOptions as M, type DecorateAccess as N, type DecorateAllAccess as O, type DeepFieldPath as P, type DefaultModelRouterOptions as Q, type Defaults as R, type DistinctArgs as S, type DistinctBody as T, type DocPermissionsAccess as U, type ErrorResult as V, type ExistsOptions as W, type ExtendedDataRouterOptions as X, type ExtendedDefaultModelRouterOptions as Y, type ExtendedModelRouterOptions as Z, type Filter as _, type AccessRouterFieldKey as a, type RootDataListQueryEntry as a$, type FindAccess as a0, type FindArgs as a1, type FindByIdArgs as a2, type FindByIdOptions as a3, type FindOneArgs as a4, type FindOneOptions as a5, type FindOptions as a6, type GlobalOptions as a7, type GlobalPermissionValue as a8, type GuardHook as a9, type PermissionSchema as aA, type Populate as aB, type PopulateAccess as aC, type PrepareAccess as aD, type Projection as aE, type PublicCreateArgs as aF, type PublicCreateOptions as aG, type PublicListArgs as aH, type PublicListOptions as aI, type PublicOutput as aJ, type PublicReadArgs as aK, type PublicReadOptions as aL, type PublicUpdateArgs as aM, type PublicUpdateOptions as aN, type PublicUpsertArgs as aO, type PublicUpsertOptions as aP, type ReadQueryInput as aQ, type Request as aR, type RequestSchemaAdapter as aS, type RequestSchemaFailure as aT, type RequestSchemaIssue as aU, type RequestSchemaLike as aV, type RequestSchemaOptions as aW, type RequestSchemaResult as aX, type RequestSchemaSuccess as aY, type RequestSchemaValidator as aZ, type RequestSchemas as a_, type IdentifierHook as aa, type Include as ab, type IoTsContextEntryLike as ac, type IoTsDecodeErrorLike as ad, type IoTsDecoderLike as ae, type JoiSchemaLike as af, type JoiValidationErrorDetailLike as ag, type KeyValueProjection as ah, type ListQueryInput as ai, type ListResult as aj, type MaybePromise as ak, type ModelBaseFilterHook as al, type ModelChangeHook as am, type ModelDeleteHook as an, type ModelDocPermissionsHook as ao, type ModelDocument as ap, type ModelDocumentHook as aq, type ModelHook as ar, type ModelHookContext as as, type ModelIdentifierHook as at, type ModelListHook as au, type ModelOverrideFilterHook as av, type ModelRequest as aw, type ModelRouterOptions as ax, type ModelValidateHook as ay, type PathValue as az, type AccessRouterLogger as b, type ValidateRule as b$, type RootDataOperation as b0, type RootDataReadByFilterQueryEntry as b1, type RootDataReadByIdQueryEntry as b2, type RootModelCountQueryEntry as b3, type RootModelCreateQueryEntry as b4, type RootModelDeleteQueryEntry as b5, type RootModelDistinctQueryEntry as b6, type RootModelListQueryEntry as b7, type RootModelNewQueryEntry as b8, type RootModelOperation as b9, type StandardSchemaPathSegment as bA, type StandardSchemaResult as bB, type StandardSchemaSuccess as bC, type StandardSchemaV1 as bD, StatusCodes as bE, type SubListBody as bF, type SubPopulate as bG, type SubQueryEntry as bH, type SubReadBody as bI, type SuperstructFailureLike as bJ, type SuperstructValidateLike as bK, type Task as bL, type TransformAccess as bM, type TypedFilter as bN, type UpdateByIdArgs as bO, type UpdateByIdOptions as bP, type UpdateOneArgs as bQ, type UpdateOneOptions as bR, type UpdateQueryInput as bS, type UpsertArgs as bT, type UpsertOptions as bU, type UpsertQueryInput as bV, type ValibotIssueLike as bW, type ValibotPathItemLike as bX, type ValibotSafeParseLike as bY, type ValibotSafeParseResult as bZ, type ValidateAccess as b_, type RootModelReadByFilterQueryEntry as ba, type RootModelReadByIdQueryEntry as bb, type RootModelSubBulkUpdateQueryEntry as bc, type RootModelSubCreateQueryEntry as bd, type RootModelSubDeleteQueryEntry as be, type RootModelSubListQueryEntry as bf, type RootModelSubReadQueryEntry as bg, type RootModelSubUpdateQueryEntry as bh, type RootModelUpdateQueryEntry as bi, type RootModelUpsertQueryEntry as bj, type RootOperationResult as bk, type RootQueryEntry as bl, type RootRouterOptions as bm, type RootSubOperation as bn, type RootTarget as bo, type RouteGuardAccess as bp, type SelectAccess as bq, type SelectedPopulatedPublicOutput as br, type SelectedPublicOutput as bs, type ServiceResult as bt, type SingleResult as bu, type Sort as bv, type SortOrder as bw, type StandardSchemaFailure as bx, type StandardSchemaInferOutput as by, type StandardSchemaIssue as bz, type AccessRouterRequest as c, type Validation as c0, type ValidationError as c1, type VineValidationErrorLike as c2, type VineValidationMessageLike as c3, type VineValidatorLike as c4, type YupSchemaLike as c5, type YupValidationErrorLike as c6, defineRequestSchema as c7, fromAjv as c8, fromArkType as c9, fromIoTs as ca, fromJoi as cb, fromStandardSchema as cc, fromSuperstruct as cd, fromValibot as ce, fromVine as cf, fromYup as cg, fromZod as ch, parseBody as ci, parseBodyWithSchema as cj, parseNestedBodyWithSchema as ck, parsePathParam as cl, parseQuery as cm, DataService as cn, Model as co, Service as cp, PublicService as cq, type AccessRouterPermissionMap as cr, type AccessRouterPermissions as cs, type Permissions as ct, type AccessRouterRequestExtensions as d, type AdvancedCreateBody as e, type AdvancedListBody as f, type AdvancedReadBody as g, type AdvancedReadFilterBody as h, type AdvancedUpdateBody as i, type AdvancedUpsertBody as j, type AfterPersistAccess as k, type AjvErrorObjectLike as l, type AjvValidatorLike as m, type ArkTypeErrorsLike as n, type ArkTypeLike as o, type ArkTypeProblemLike as p, Codes as q, type CountBody as r, type CreateArgs as s, type CreateOptions as t, type CreateQueryInput as u, CustomHeaders as v, type DataFilter as w, type DataFindArgs as x, type DataFindOneArgs as y, type DataFindOneOptions as z };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import mongoose from 'mongoose';
|
|
3
|
-
import { Diff } from 'deep-diff';
|
|
4
3
|
import express from 'express';
|
|
5
4
|
|
|
6
5
|
interface BooleanObject {
|
|
@@ -26,8 +25,8 @@ type Permissions = Permission;
|
|
|
26
25
|
type AccessRouterPermissions = Permission;
|
|
27
26
|
|
|
28
27
|
declare class Base<TModel = unknown> {
|
|
29
|
-
req: ModelRequest;
|
|
30
|
-
modelName: string;
|
|
28
|
+
protected req: ModelRequest;
|
|
29
|
+
protected modelName: string;
|
|
31
30
|
constructor(req: ModelRequest, modelName: string);
|
|
32
31
|
decorate<T>(doc: T, access: DecorateAccess, context: ModelHookContext): Promise<T>;
|
|
33
32
|
decorateAll<T>(docs: T[], access: DecorateAllAccess, context: ModelHookContext): Promise<T[]>;
|
|
@@ -98,19 +97,17 @@ declare class Model {
|
|
|
98
97
|
find({ filter, select, sort, populate, limit, skip, lean }: FindProps): mongoose.Query<any[], any, {}, any, "find", {}>;
|
|
99
98
|
validateSort(sort: SortType, logError?: (msg: string, ...args: unknown[]) => void): boolean;
|
|
100
99
|
findOne({ filter, select, sort, populate, lean }: FindOneProps): mongoose.Query<any, any, {}, any, "findOne", {}>;
|
|
101
|
-
findOneAndDelete(filter: any): mongoose.Query<any, any, {}, any, "findOneAndDelete", {}>;
|
|
102
100
|
exists(filter: any): mongoose.Query<any, any, {}, any, "findOne", {}>;
|
|
103
101
|
countDocuments(filter?: {}): mongoose.Query<number, any, {}, any, "countDocuments", {}>;
|
|
104
|
-
estimatedDocumentCount(): mongoose.Query<number, any, {}, any, "estimatedDocumentCount", {}>;
|
|
105
102
|
distinct(field: string, conditions?: {}): mongoose.Query<any[], any, {}, any, "distinct", {}>;
|
|
106
103
|
}
|
|
107
104
|
|
|
108
105
|
declare class Service<TModel = unknown> extends Base<TModel> {
|
|
109
|
-
model: Model;
|
|
110
|
-
options: ModelRouterOptions<TModel>;
|
|
106
|
+
protected model: Model;
|
|
107
|
+
protected options: ModelRouterOptions<TModel>;
|
|
111
108
|
defaults: Defaults<TModel>;
|
|
112
|
-
baseFields: string[];
|
|
113
|
-
baseFieldsExt: string[];
|
|
109
|
+
protected baseFields: string[];
|
|
110
|
+
protected baseFieldsExt: string[];
|
|
114
111
|
private asServiceHookContext;
|
|
115
112
|
constructor(req: ModelRequest, modelName: string);
|
|
116
113
|
findOne(filter: Filter<TModel>, args?: FindOneArgs<TModel>, options?: FindOneOptions): Promise<SingleResult<TModel> | ErrorResult>;
|
|
@@ -210,10 +207,10 @@ declare class PublicService<TModel = unknown> extends Service<TModel> {
|
|
|
210
207
|
}
|
|
211
208
|
|
|
212
209
|
declare class DataService<T> {
|
|
213
|
-
req: DataRequest;
|
|
214
|
-
dataName: string;
|
|
215
|
-
options: DataRouterOptions<T>;
|
|
216
|
-
data: T[];
|
|
210
|
+
protected req: DataRequest;
|
|
211
|
+
protected dataName: string;
|
|
212
|
+
protected options: DataRouterOptions<T>;
|
|
213
|
+
protected data: T[];
|
|
217
214
|
constructor(req: DataRequest, dataName: string);
|
|
218
215
|
findOne<TSelect extends Projection | undefined = undefined>(filter: DataFilter<T>, args?: DataFindOneArgs<T, TSelect>, options?: DataFindOneOptions): Promise<SingleResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
219
216
|
findById<TSelect extends Projection | undefined = undefined>(id: string, args?: DataFindOneArgs<T, TSelect>, options?: DataFindOneOptions): Promise<SingleResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
@@ -564,6 +561,11 @@ interface SubPopulate {
|
|
|
564
561
|
interface KeyValue {
|
|
565
562
|
[key: string]: unknown;
|
|
566
563
|
}
|
|
564
|
+
interface Change {
|
|
565
|
+
op: 'add' | 'replace' | 'remove';
|
|
566
|
+
path: Array<string | number>;
|
|
567
|
+
value?: unknown;
|
|
568
|
+
}
|
|
567
569
|
interface ModelHookContext {
|
|
568
570
|
modelName: string;
|
|
569
571
|
mongooseModel: mongoose.Model<unknown>;
|
|
@@ -576,7 +578,7 @@ interface ModelHookContext {
|
|
|
576
578
|
preparedData?: Record<string, unknown>;
|
|
577
579
|
allowedFields?: string[];
|
|
578
580
|
modifiedPaths?: string[];
|
|
579
|
-
changes?:
|
|
581
|
+
changes?: Change[];
|
|
580
582
|
docPermissions?: KeyValue;
|
|
581
583
|
resolvedQuery?: {
|
|
582
584
|
filter?: Filter;
|
|
@@ -845,7 +847,7 @@ type HookChain<TValue, TContext, TRequest extends AccessRouterRequest = AccessRo
|
|
|
845
847
|
type ValidateRule = boolean | unknown[];
|
|
846
848
|
type ValidateHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, allowedData: unknown, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<ValidateRule>;
|
|
847
849
|
type DocPermissionsHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, doc: unknown, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<Record<string, unknown>>;
|
|
848
|
-
type ChangeHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, previousValue: unknown, nextValue: unknown, changes:
|
|
850
|
+
type ChangeHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, previousValue: unknown, nextValue: unknown, changes: Change[], context: ModelHookContext) => MaybePromise<void>;
|
|
849
851
|
type DeleteHook<TValue = unknown, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: TValue, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<void>;
|
|
850
852
|
type DocumentHook<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: ModelDocument<TValue>, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<ModelDocument<TValue>>;
|
|
851
853
|
type DocumentHookChain<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = DocumentHook<TValue, TRequest> | Array<DocumentHook<TValue, TRequest>>;
|
|
@@ -886,6 +888,10 @@ type RequestSchemaResult<T = unknown> = RequestSchemaSuccess<T> | RequestSchemaF
|
|
|
886
888
|
type RequestSchemaValidator<T = unknown> = (value: unknown) => RequestSchemaResult<T> | Promise<RequestSchemaResult<T>>;
|
|
887
889
|
type RequestSchemaAdapter<T = unknown> = {
|
|
888
890
|
validate: RequestSchemaValidator<T>;
|
|
891
|
+
openapi?: Record<string, unknown>;
|
|
892
|
+
};
|
|
893
|
+
type RequestSchemaOptions = {
|
|
894
|
+
openapi?: Record<string, unknown>;
|
|
889
895
|
};
|
|
890
896
|
type StandardSchemaPathSegment = {
|
|
891
897
|
key: PropertyKey;
|
|
@@ -1403,7 +1409,19 @@ declare function parseQuery<TSchema extends z.ZodTypeAny>(schema: TSchema, value
|
|
|
1403
1409
|
declare function parseBody<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown): z.output<TSchema>;
|
|
1404
1410
|
declare function parseBodyWithSchema<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown, userSchema?: RequestSchemaLike): Promise<z.output<TSchema>>;
|
|
1405
1411
|
declare function parseNestedBodyWithSchema(schema: z.ZodTypeAny, value: unknown, nestedKey: string, userSchema?: RequestSchemaLike): Promise<Record<string, unknown>>;
|
|
1406
|
-
|
|
1412
|
+
/**
|
|
1413
|
+
* Wraps a request validator into a request schema adapter used by `access-router`.
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* const schema = defineRequestSchema(fromZod(z.object({ name: z.string() })));
|
|
1417
|
+
*/
|
|
1418
|
+
declare function defineRequestSchema<T = unknown>(validator: RequestSchemaValidator<T>, options?: RequestSchemaOptions): RequestSchemaAdapter<T>;
|
|
1419
|
+
/**
|
|
1420
|
+
* Adapts a Zod schema into a `RequestSchemaValidator` for `access-router`.
|
|
1421
|
+
*
|
|
1422
|
+
* @example
|
|
1423
|
+
* const validator = fromZod(z.object({ name: z.string() }));
|
|
1424
|
+
*/
|
|
1407
1425
|
declare function fromZod<TSchema extends z.ZodTypeAny>(schema: TSchema): RequestSchemaValidator<z.output<TSchema>>;
|
|
1408
1426
|
declare function fromStandardSchema<TSchema extends StandardSchemaV1>(schema: TSchema): RequestSchemaValidator<StandardSchemaInferOutput<TSchema>>;
|
|
1409
1427
|
declare function fromYup<TSchema extends YupSchemaLike>(schema: TSchema): RequestSchemaValidator;
|
|
@@ -1415,4 +1433,4 @@ declare function fromIoTs<TValue = unknown>(decoder: IoTsDecoderLike<TValue>): R
|
|
|
1415
1433
|
declare function fromSuperstruct<TStruct, TOutput = unknown>(struct: TStruct, validate: SuperstructValidateLike): RequestSchemaValidator<TOutput>;
|
|
1416
1434
|
declare function fromVine<TValue = unknown>(validator: VineValidatorLike<TValue>): RequestSchemaValidator<TValue>;
|
|
1417
1435
|
|
|
1418
|
-
export {
|
|
1436
|
+
export { FilterOperator as $, type AccessRouterBaseRequest as A, type BaseFilterAccess as B, type Change as C, type DataBaseFilterHook as D, type DataFindOptions as E, type DataHook as F, type DataHookContext as G, type DataIdentifierHook as H, type DataListHook as I, type DataOverrideFilterHook as J, type DataRequest as K, type DataRequestSchemas as L, type DataRouterOptions as M, type DecorateAccess as N, type DecorateAllAccess as O, type DeepFieldPath as P, type DefaultModelRouterOptions as Q, type Defaults as R, type DistinctArgs as S, type DistinctBody as T, type DocPermissionsAccess as U, type ErrorResult as V, type ExistsOptions as W, type ExtendedDataRouterOptions as X, type ExtendedDefaultModelRouterOptions as Y, type ExtendedModelRouterOptions as Z, type Filter as _, type AccessRouterFieldKey as a, type RootDataListQueryEntry as a$, type FindAccess as a0, type FindArgs as a1, type FindByIdArgs as a2, type FindByIdOptions as a3, type FindOneArgs as a4, type FindOneOptions as a5, type FindOptions as a6, type GlobalOptions as a7, type GlobalPermissionValue as a8, type GuardHook as a9, type PermissionSchema as aA, type Populate as aB, type PopulateAccess as aC, type PrepareAccess as aD, type Projection as aE, type PublicCreateArgs as aF, type PublicCreateOptions as aG, type PublicListArgs as aH, type PublicListOptions as aI, type PublicOutput as aJ, type PublicReadArgs as aK, type PublicReadOptions as aL, type PublicUpdateArgs as aM, type PublicUpdateOptions as aN, type PublicUpsertArgs as aO, type PublicUpsertOptions as aP, type ReadQueryInput as aQ, type Request as aR, type RequestSchemaAdapter as aS, type RequestSchemaFailure as aT, type RequestSchemaIssue as aU, type RequestSchemaLike as aV, type RequestSchemaOptions as aW, type RequestSchemaResult as aX, type RequestSchemaSuccess as aY, type RequestSchemaValidator as aZ, type RequestSchemas as a_, type IdentifierHook as aa, type Include as ab, type IoTsContextEntryLike as ac, type IoTsDecodeErrorLike as ad, type IoTsDecoderLike as ae, type JoiSchemaLike as af, type JoiValidationErrorDetailLike as ag, type KeyValueProjection as ah, type ListQueryInput as ai, type ListResult as aj, type MaybePromise as ak, type ModelBaseFilterHook as al, type ModelChangeHook as am, type ModelDeleteHook as an, type ModelDocPermissionsHook as ao, type ModelDocument as ap, type ModelDocumentHook as aq, type ModelHook as ar, type ModelHookContext as as, type ModelIdentifierHook as at, type ModelListHook as au, type ModelOverrideFilterHook as av, type ModelRequest as aw, type ModelRouterOptions as ax, type ModelValidateHook as ay, type PathValue as az, type AccessRouterLogger as b, type ValidateRule as b$, type RootDataOperation as b0, type RootDataReadByFilterQueryEntry as b1, type RootDataReadByIdQueryEntry as b2, type RootModelCountQueryEntry as b3, type RootModelCreateQueryEntry as b4, type RootModelDeleteQueryEntry as b5, type RootModelDistinctQueryEntry as b6, type RootModelListQueryEntry as b7, type RootModelNewQueryEntry as b8, type RootModelOperation as b9, type StandardSchemaPathSegment as bA, type StandardSchemaResult as bB, type StandardSchemaSuccess as bC, type StandardSchemaV1 as bD, StatusCodes as bE, type SubListBody as bF, type SubPopulate as bG, type SubQueryEntry as bH, type SubReadBody as bI, type SuperstructFailureLike as bJ, type SuperstructValidateLike as bK, type Task as bL, type TransformAccess as bM, type TypedFilter as bN, type UpdateByIdArgs as bO, type UpdateByIdOptions as bP, type UpdateOneArgs as bQ, type UpdateOneOptions as bR, type UpdateQueryInput as bS, type UpsertArgs as bT, type UpsertOptions as bU, type UpsertQueryInput as bV, type ValibotIssueLike as bW, type ValibotPathItemLike as bX, type ValibotSafeParseLike as bY, type ValibotSafeParseResult as bZ, type ValidateAccess as b_, type RootModelReadByFilterQueryEntry as ba, type RootModelReadByIdQueryEntry as bb, type RootModelSubBulkUpdateQueryEntry as bc, type RootModelSubCreateQueryEntry as bd, type RootModelSubDeleteQueryEntry as be, type RootModelSubListQueryEntry as bf, type RootModelSubReadQueryEntry as bg, type RootModelSubUpdateQueryEntry as bh, type RootModelUpdateQueryEntry as bi, type RootModelUpsertQueryEntry as bj, type RootOperationResult as bk, type RootQueryEntry as bl, type RootRouterOptions as bm, type RootSubOperation as bn, type RootTarget as bo, type RouteGuardAccess as bp, type SelectAccess as bq, type SelectedPopulatedPublicOutput as br, type SelectedPublicOutput as bs, type ServiceResult as bt, type SingleResult as bu, type Sort as bv, type SortOrder as bw, type StandardSchemaFailure as bx, type StandardSchemaInferOutput as by, type StandardSchemaIssue as bz, type AccessRouterRequest as c, type Validation as c0, type ValidationError as c1, type VineValidationErrorLike as c2, type VineValidationMessageLike as c3, type VineValidatorLike as c4, type YupSchemaLike as c5, type YupValidationErrorLike as c6, defineRequestSchema as c7, fromAjv as c8, fromArkType as c9, fromIoTs as ca, fromJoi as cb, fromStandardSchema as cc, fromSuperstruct as cd, fromValibot as ce, fromVine as cf, fromYup as cg, fromZod as ch, parseBody as ci, parseBodyWithSchema as cj, parseNestedBodyWithSchema as ck, parsePathParam as cl, parseQuery as cm, DataService as cn, Model as co, Service as cp, PublicService as cq, type AccessRouterPermissionMap as cr, type AccessRouterPermissions as cs, type Permissions as ct, type AccessRouterRequestExtensions as d, type AdvancedCreateBody as e, type AdvancedListBody as f, type AdvancedReadBody as g, type AdvancedReadFilterBody as h, type AdvancedUpdateBody as i, type AdvancedUpsertBody as j, type AfterPersistAccess as k, type AjvErrorObjectLike as l, type AjvValidatorLike as m, type ArkTypeErrorsLike as n, type ArkTypeLike as o, type ArkTypeProblemLike as p, Codes as q, type CountBody as r, type CreateArgs as s, type CreateOptions as t, type CreateQueryInput as u, CustomHeaders as v, type DataFilter as w, type DataFindArgs as x, type DataFindOneArgs as y, type DataFindOneOptions as z };
|