@web-ts-toolkit/access-router 0.29.0 → 0.31.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/advanced.d.mts +1433 -4
- package/advanced.d.ts +1433 -4
- package/index.d.mts +1157 -14
- package/index.d.ts +1157 -14
- package/index.js +111 -108
- package/index.mjs +15 -9
- package/package.json +3 -3
- package/parsers-Cj4r_G4g.d.mts +0 -1436
- package/parsers-Cj4r_G4g.d.ts +0 -1436
package/index.d.mts
CHANGED
|
@@ -1,9 +1,231 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
|
-
import { Response, NextFunction,
|
|
3
|
-
import { a7 as GlobalOptions, Q as DefaultModelRouterOptions, Y as ExtendedDefaultModelRouterOptions, ax as ModelRouterOptions, Z as ExtendedModelRouterOptions, M as DataRouterOptions, X as ExtendedDataRouterOptions, A as AccessRouterBaseRequest, a9 as GuardHook, aw as ModelRequest, K as DataRequest, cn as DataService, co as Model, cp as Service, cq as PublicService, c0 as Validation, bm as RootRouterOptions } from './parsers-Cj4r_G4g.mjs';
|
|
4
|
-
export { cr as AccessRouterPermissionMap, cs as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, m as AjvValidatorLike, n as ArkTypeErrorsLike, o as ArkTypeLike, ac as IoTsContextEntryLike, ad as IoTsDecodeErrorLike, ae as IoTsDecoderLike, af as JoiSchemaLike, ag as JoiValidationErrorDetailLike, ct as Permissions, aS as RequestSchemaAdapter, aT as RequestSchemaFailure, aU as RequestSchemaIssue, aV as RequestSchemaLike, aW as RequestSchemaOptions, aX as RequestSchemaResult, aY as RequestSchemaSuccess, aZ as RequestSchemaValidator, bx as StandardSchemaFailure, by as StandardSchemaInferOutput, bz as StandardSchemaIssue, bA as StandardSchemaPathSegment, bB as StandardSchemaResult, bC as StandardSchemaSuccess, bD as StandardSchemaV1, bJ as SuperstructFailureLike, bK as SuperstructValidateLike, bW as ValibotIssueLike, bX as ValibotPathItemLike, bY as ValibotSafeParseLike, bZ as ValibotSafeParseResult, c2 as VineValidationErrorLike, c3 as VineValidationMessageLike, c4 as VineValidatorLike, c5 as YupSchemaLike, c6 as YupValidationErrorLike, c7 as defineRequestSchema, c8 as fromAjv, c9 as fromArkType, ca as fromIoTs, cb as fromJoi, cc as fromStandardSchema, cd as fromSuperstruct, ce as fromValibot, cf as fromVine, cg as fromYup, ch as fromZod } from './parsers-Cj4r_G4g.mjs';
|
|
2
|
+
import express, { Router, Response, NextFunction, RequestHandler } from 'express';
|
|
5
3
|
import JsonRouter from '@web-ts-toolkit/express-json-router';
|
|
6
|
-
import 'zod';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
interface BooleanObject {
|
|
7
|
+
[key: string]: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface AccessRouterPermissionMap {
|
|
10
|
+
}
|
|
11
|
+
type AccessRouterPermissionKey = Extract<keyof AccessRouterPermissionMap, string>;
|
|
12
|
+
type PermissionName = AccessRouterPermissionKey | (string & {});
|
|
13
|
+
declare class Permission {
|
|
14
|
+
private readonly permissions;
|
|
15
|
+
private readonly permissionKeys;
|
|
16
|
+
constructor(permissions: BooleanObject);
|
|
17
|
+
get keys(): readonly string[];
|
|
18
|
+
private normalizePermissionArgs;
|
|
19
|
+
hasKey(permission: PermissionName): boolean;
|
|
20
|
+
has(permission: PermissionName): boolean;
|
|
21
|
+
hasAny(permissionOrPermissions: PermissionName | readonly PermissionName[], ...permissions: PermissionName[]): boolean;
|
|
22
|
+
hasAll(permissionOrPermissions: PermissionName | readonly PermissionName[], ...permissions: PermissionName[]): boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type Permissions = Permission;
|
|
26
|
+
type AccessRouterPermissions = Permission;
|
|
27
|
+
|
|
28
|
+
declare class Base<TModel = unknown> {
|
|
29
|
+
protected req: ModelRequest;
|
|
30
|
+
protected modelName: string;
|
|
31
|
+
constructor(req: ModelRequest, modelName: string);
|
|
32
|
+
decorate<T>(doc: T, access: DecorateAccess, context: ModelHookContext): Promise<T>;
|
|
33
|
+
decorateAll<T>(docs: T[], access: DecorateAllAccess, context: ModelHookContext): Promise<T[]>;
|
|
34
|
+
genAllowedFields(doc: unknown, access: SelectAccess, baseFields?: string[]): Promise<string[]>;
|
|
35
|
+
genDocPermissions(doc: unknown, access: DocPermissionsAccess, context: ModelHookContext): Promise<Record<string, unknown>>;
|
|
36
|
+
genFilter(access?: BaseFilterAccess, filter?: Filter<TModel>): Promise<Filter<TModel>>;
|
|
37
|
+
getIdentifier(): string | null;
|
|
38
|
+
genIDFilter(id: string): Promise<Filter<TModel>>;
|
|
39
|
+
genPopulate(access?: SelectAccess, populate?: Populate | Populate[] | string | null): Promise<Populate[]>;
|
|
40
|
+
genSelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
|
|
41
|
+
genQuerySelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
|
|
42
|
+
addEmptyPermissions<T>(doc: T): T;
|
|
43
|
+
addDocPermissions<T>(doc: T, access: DocPermissionsAccess, context: ModelHookContext): Promise<T>;
|
|
44
|
+
addFieldPermissions<T extends {
|
|
45
|
+
_id?: unknown;
|
|
46
|
+
}>(doc: T, access: DocPermissionsAccess, context: ModelHookContext): Promise<T>;
|
|
47
|
+
pickAllowedFields<T>(doc: T, access: SelectAccess, baseFields?: string[]): Promise<T>;
|
|
48
|
+
trimOutputFields<T>(doc: T, access: SelectAccess, baseFields?: string[]): Promise<T>;
|
|
49
|
+
prepare<T>(allowedData: T, access: PrepareAccess, context: ModelHookContext): Promise<T>;
|
|
50
|
+
runTasks<T extends object>(docObject: T, tasks: Task | Task[]): T;
|
|
51
|
+
transform<T>(doc: T, access: TransformAccess, context: ModelHookContext): Promise<T>;
|
|
52
|
+
afterPersist<T>(doc: T, access: AfterPersistAccess, context: ModelHookContext): Promise<T>;
|
|
53
|
+
changes(doc: Record<string, unknown>, context: ModelHookContext): Promise<void>;
|
|
54
|
+
beforeDelete<T>(doc: T, context: ModelHookContext): Promise<void>;
|
|
55
|
+
afterDelete<T>(doc: T, context: ModelHookContext): Promise<void>;
|
|
56
|
+
validate(allowedData: unknown, access: ValidateAccess, context: ModelHookContext): Promise<boolean | unknown[]>;
|
|
57
|
+
checkIfModelPermissionExists(accesses: DocPermissionsAccess[]): boolean;
|
|
58
|
+
protected validateClientFilter(filter: Filter | null | undefined): string[];
|
|
59
|
+
protected processInclude(include: Include | Include[]): {
|
|
60
|
+
includes: Include[];
|
|
61
|
+
includeLocalFields: string[];
|
|
62
|
+
includePaths: string[];
|
|
63
|
+
};
|
|
64
|
+
protected includeDocs(docs: any, include: Include | Include[]): Promise<any>;
|
|
65
|
+
private includeDocsList;
|
|
66
|
+
private includeDocsCount;
|
|
67
|
+
protected parseClientData<TValue>(filter: TValue): Promise<TValue>;
|
|
68
|
+
private handleSubQuery;
|
|
69
|
+
private handleDate;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface FindProps {
|
|
73
|
+
filter: Filter;
|
|
74
|
+
select?: Projection;
|
|
75
|
+
sort?: Sort;
|
|
76
|
+
populate?: Populate[] | string;
|
|
77
|
+
limit?: string | number;
|
|
78
|
+
skip?: string | number;
|
|
79
|
+
lean?: boolean;
|
|
80
|
+
}
|
|
81
|
+
interface FindOneProps {
|
|
82
|
+
filter: Filter;
|
|
83
|
+
select?: Projection;
|
|
84
|
+
sort?: Sort;
|
|
85
|
+
populate?: Populate[] | string;
|
|
86
|
+
lean?: boolean;
|
|
87
|
+
}
|
|
88
|
+
type SortValue = 1 | -1 | 'asc' | 'ascending' | 'desc' | 'descending';
|
|
89
|
+
type SortType = string | [string, SortValue][] | {
|
|
90
|
+
[key: string]: SortValue;
|
|
91
|
+
} | Map<string, SortValue> | null | undefined;
|
|
92
|
+
declare class Model {
|
|
93
|
+
modelName: string;
|
|
94
|
+
model: mongoose.Model<any>;
|
|
95
|
+
constructor(modelName: string);
|
|
96
|
+
new(): any;
|
|
97
|
+
create(data: any): Promise<any>;
|
|
98
|
+
find({ filter, select, sort, populate, limit, skip, lean }: FindProps): mongoose.Query<any[], any, {}, any, "find", {}>;
|
|
99
|
+
validateSort(sort: SortType, logError?: (msg: string, ...args: unknown[]) => void): boolean;
|
|
100
|
+
findOne({ filter, select, sort, populate, lean }: FindOneProps): mongoose.Query<any, any, {}, any, "findOne", {}>;
|
|
101
|
+
exists(filter: any): mongoose.Query<any, any, {}, any, "findOne", {}>;
|
|
102
|
+
countDocuments(filter?: {}): mongoose.Query<number, any, {}, any, "countDocuments", {}>;
|
|
103
|
+
distinct(field: string, conditions?: {}): mongoose.Query<any[], any, {}, any, "distinct", {}>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare class Service<TModel = unknown> extends Base<TModel> {
|
|
107
|
+
protected model: Model;
|
|
108
|
+
protected options: ModelRouterOptions<TModel>;
|
|
109
|
+
defaults: Defaults<TModel>;
|
|
110
|
+
protected baseFields: string[];
|
|
111
|
+
protected baseFieldsExt: string[];
|
|
112
|
+
private asServiceHookContext;
|
|
113
|
+
constructor(req: ModelRequest, modelName: string);
|
|
114
|
+
findOne(filter: Filter<TModel>, args?: FindOneArgs<TModel>, options?: FindOneOptions): Promise<SingleResult<TModel> | ErrorResult>;
|
|
115
|
+
findById(id: string, args?: FindByIdArgs<TModel>, options?: FindByIdOptions): Promise<SingleResult<TModel> | ErrorResult>;
|
|
116
|
+
find(filter: Filter<TModel>, args?: FindArgs<TModel>, options?: FindOptions, decorate?: Function): Promise<ListResult<TModel> | ErrorResult>;
|
|
117
|
+
create(data: any, args?: CreateArgs, options?: CreateOptions, decorate?: Function): Promise<ListResult<TModel> | ErrorResult>;
|
|
118
|
+
new(): Promise<SingleResult<TModel>>;
|
|
119
|
+
updateOne(filter: Filter<TModel>, data: any, args?: UpdateOneArgs<TModel>, options?: UpdateOneOptions, decorate?: Function): Promise<SingleResult<TModel> | ErrorResult>;
|
|
120
|
+
updateById(id: string, data: any, args?: UpdateByIdArgs<TModel>, options?: UpdateByIdOptions, decorate?: Function): Promise<SingleResult<TModel> | ErrorResult>;
|
|
121
|
+
upsert(filter: Filter<TModel>, data: any, args?: UpsertArgs<TModel>, options?: UpsertOptions, decorate?: Function): Promise<ServiceResult<TModel>>;
|
|
122
|
+
delete(id: string): Promise<SingleResult<unknown> | ErrorResult>;
|
|
123
|
+
exists(filter: Filter<TModel>, options: ExistsOptions & {
|
|
124
|
+
includeId: true;
|
|
125
|
+
}): Promise<SingleResult<unknown> | ErrorResult>;
|
|
126
|
+
exists(filter: Filter<TModel>, options?: ExistsOptions): Promise<SingleResult<boolean> | ErrorResult>;
|
|
127
|
+
distinct(field: string, args?: DistinctArgs<TModel>): Promise<ListResult<unknown> | ErrorResult>;
|
|
128
|
+
count(filter: Filter<TModel>, access?: BaseFilterAccess): Promise<SingleResult<number> | ErrorResult>;
|
|
129
|
+
getDocPermissions(doc: unknown): Record<string, unknown>;
|
|
130
|
+
private resolveFindOneArgs;
|
|
131
|
+
private resolveFindOneOptions;
|
|
132
|
+
private resolveFindByIdArgs;
|
|
133
|
+
private resolveFindByIdOptions;
|
|
134
|
+
private resolveFindArgs;
|
|
135
|
+
private resolveFindOptions;
|
|
136
|
+
private resolveCreateArgs;
|
|
137
|
+
private resolveCreateOptions;
|
|
138
|
+
private resolveUpdateOneArgs;
|
|
139
|
+
private resolveUpdateOneOptions;
|
|
140
|
+
private resolveUpdateByIdArgs;
|
|
141
|
+
private resolveUpdateByIdOptions;
|
|
142
|
+
private resolveUpsertArgs;
|
|
143
|
+
private resolveUpsertOptions;
|
|
144
|
+
private resolveExistsOptions;
|
|
145
|
+
private getFieldPermissionAccess;
|
|
146
|
+
private getAccessibleIdSet;
|
|
147
|
+
listSub(id: any, sub: any, options?: {
|
|
148
|
+
filter: Filter;
|
|
149
|
+
select: string[];
|
|
150
|
+
}): Promise<ListResult | ErrorResult>;
|
|
151
|
+
readSub(id: any, sub: any, subId: any, options?: {
|
|
152
|
+
select: string[];
|
|
153
|
+
populate: SubPopulate | SubPopulate[];
|
|
154
|
+
}): Promise<SingleResult | ErrorResult>;
|
|
155
|
+
updateSub(id: any, sub: any, subId: any, data: any): Promise<SingleResult | ErrorResult>;
|
|
156
|
+
bulkUpdateSub(id: any, sub: any, data: any): Promise<ListResult | ErrorResult>;
|
|
157
|
+
createSub(id: any, sub: any, data: any, options?: {
|
|
158
|
+
addFirst: boolean;
|
|
159
|
+
}): Promise<ListResult | ErrorResult>;
|
|
160
|
+
deleteSub(id: any, sub: any, subId: any): Promise<SingleResult | ErrorResult>;
|
|
161
|
+
getParentDoc(id: any, sub: any, args?: {
|
|
162
|
+
populate?: SubPopulate | SubPopulate[];
|
|
163
|
+
}, options?: {
|
|
164
|
+
access?: BaseFilterAccess;
|
|
165
|
+
lean?: boolean;
|
|
166
|
+
}): Promise<any>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
declare class PublicService<TModel = unknown> extends Service<TModel> {
|
|
170
|
+
_list<TSelect extends Projection | undefined = undefined, TPopulate extends Populate[] | string | undefined = undefined>(filter: Filter<TModel>, args?: Omit<PublicListArgs, 'select' | 'populate'> & {
|
|
171
|
+
select?: TSelect;
|
|
172
|
+
populate?: TPopulate;
|
|
173
|
+
}, options?: PublicListOptions): Promise<ListResult<SelectedPopulatedPublicOutput<TModel, TSelect, TPopulate>> | ErrorResult>;
|
|
174
|
+
_create<TSelect extends Projection | undefined = undefined, TPopulate extends Populate[] | string | undefined = undefined>(data: any, args?: Omit<PublicCreateArgs, 'select' | 'populate'> & {
|
|
175
|
+
select?: TSelect;
|
|
176
|
+
populate?: TPopulate;
|
|
177
|
+
}, options?: PublicCreateOptions): Promise<ListResult<SelectedPopulatedPublicOutput<TModel, TSelect, TPopulate>> | ErrorResult>;
|
|
178
|
+
_new(): Promise<SingleResult<PublicOutput<TModel>>>;
|
|
179
|
+
_read<TSelect extends Projection | undefined = undefined, TPopulate extends Populate[] | string | undefined = undefined>(id: string, args?: Omit<PublicReadArgs, 'select' | 'populate'> & {
|
|
180
|
+
select?: TSelect;
|
|
181
|
+
populate?: TPopulate;
|
|
182
|
+
}, options?: PublicReadOptions): Promise<SingleResult<SelectedPopulatedPublicOutput<TModel, TSelect, TPopulate>> | ErrorResult>;
|
|
183
|
+
_readFilter<TSelect extends Projection | undefined = undefined, TPopulate extends Populate[] | string | undefined = undefined>(filter: Filter<TModel>, args?: Omit<PublicReadArgs, 'select' | 'populate'> & {
|
|
184
|
+
select?: TSelect;
|
|
185
|
+
populate?: TPopulate;
|
|
186
|
+
sort?: Sort;
|
|
187
|
+
}, options?: PublicReadOptions): Promise<SingleResult<SelectedPopulatedPublicOutput<TModel, TSelect, TPopulate>> | ErrorResult>;
|
|
188
|
+
_update<TSelect extends Projection | undefined = undefined, TPopulate extends Populate[] | string | undefined = undefined>(id: string, data: any, args?: Omit<PublicUpdateArgs, 'select' | 'populate'> & {
|
|
189
|
+
select?: TSelect;
|
|
190
|
+
populate?: TPopulate;
|
|
191
|
+
}, options?: PublicUpdateOptions): Promise<SingleResult<SelectedPopulatedPublicOutput<TModel, TSelect, TPopulate>> | ErrorResult>;
|
|
192
|
+
_upsert<TSelect extends Projection | undefined = undefined, TPopulate extends Populate[] | string | undefined = undefined>(data: Record<string, unknown>, args?: Omit<PublicUpsertArgs, 'select' | 'populate'> & {
|
|
193
|
+
select?: TSelect;
|
|
194
|
+
populate?: TPopulate;
|
|
195
|
+
}, options?: PublicUpsertOptions): Promise<ServiceResult<SelectedPopulatedPublicOutput<TModel, TSelect, TPopulate>> | ErrorResult>;
|
|
196
|
+
_delete(id: string): Promise<SingleResult<unknown> | ErrorResult>;
|
|
197
|
+
_distinct(field: string, options?: DistinctArgs<TModel>): Promise<ListResult<unknown> | ErrorResult>;
|
|
198
|
+
_count(filter: Filter<TModel>, access?: BaseFilterAccess): Promise<SingleResult<number> | ErrorResult>;
|
|
199
|
+
private resolvePublicListArgs;
|
|
200
|
+
private resolvePublicListOptions;
|
|
201
|
+
private resolvePublicCreateArgs;
|
|
202
|
+
private resolvePublicCreateOptions;
|
|
203
|
+
private resolvePublicReadArgs;
|
|
204
|
+
private resolvePublicReadFilterArgs;
|
|
205
|
+
private resolvePublicReadOptions;
|
|
206
|
+
private resolvePublicUpdateArgs;
|
|
207
|
+
private resolvePublicUpdateOptions;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare class DataService<T> {
|
|
211
|
+
protected req: DataRequest;
|
|
212
|
+
protected dataName: string;
|
|
213
|
+
protected options: DataRouterOptions<T>;
|
|
214
|
+
protected data: T[];
|
|
215
|
+
constructor(req: DataRequest, dataName: string);
|
|
216
|
+
findOne<TSelect extends Projection | undefined = undefined>(filter: DataFilter<T>, args?: DataFindOneArgs<T, TSelect>, options?: DataFindOneOptions): Promise<SingleResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
217
|
+
findById<TSelect extends Projection | undefined = undefined>(id: string, args?: DataFindOneArgs<T, TSelect>, options?: DataFindOneOptions): Promise<SingleResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
218
|
+
find<TSelect extends Projection | undefined = undefined>(filter: DataFilter<T>, args?: DataFindArgs<T, TSelect>, options?: DataFindOptions): Promise<ListResult<SelectedPublicOutput<T, TSelect>> | ErrorResult>;
|
|
219
|
+
decorate<TDoc>(doc: TDoc, access: DecorateAccess, context?: DataHookContext): Promise<TDoc>;
|
|
220
|
+
decorateAll<TDoc>(docs: TDoc[], access: DecorateAllAccess, context?: DataHookContext): Promise<TDoc[]>;
|
|
221
|
+
genAllowedFields(doc: unknown, access: SelectAccess, baseFields?: string[]): Promise<string[]>;
|
|
222
|
+
genFilter(access?: BaseFilterAccess, filter?: DataFilter<T>): Promise<DataFilter<T>>;
|
|
223
|
+
genIDFilter(id: string): Promise<DataFilter<T>>;
|
|
224
|
+
genSelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
|
|
225
|
+
genQuerySelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
|
|
226
|
+
pickAllowedFields<TDoc>(doc: TDoc, access: SelectAccess, baseFields?: string[]): Promise<TDoc>;
|
|
227
|
+
trimOutputFields<TDoc>(doc: TDoc, access: SelectAccess, baseFields?: string[]): Promise<TDoc>;
|
|
228
|
+
}
|
|
7
229
|
|
|
8
230
|
type OpenApiMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
9
231
|
type OpenApiSchema = Record<string, unknown>;
|
|
@@ -52,6 +274,8 @@ type OpenApiRouterOptions = Partial<OpenApiDocumentOptions> & {
|
|
|
52
274
|
swaggerUiBundleUrl?: string;
|
|
53
275
|
};
|
|
54
276
|
|
|
277
|
+
declare function createOpenApiRouter(runtime: AccessRuntime, options?: OpenApiRouterOptions): Router;
|
|
278
|
+
|
|
55
279
|
declare class AccessRuntime {
|
|
56
280
|
private readonly globalOptions;
|
|
57
281
|
private readonly defaultModelOptions;
|
|
@@ -112,14 +336,911 @@ declare class AccessRuntime {
|
|
|
112
336
|
getExactDataOption<K extends keyof ExtendedDataRouterOptions<TData>, TData = unknown>(dataName: string, key: K | string): ExtendedDataRouterOptions<TData>[K];
|
|
113
337
|
getDataNames(): string[];
|
|
114
338
|
ensureModelMeta(modelName: string): void;
|
|
115
|
-
getModelRef(modelName: string, refPath: string):
|
|
339
|
+
getModelRef(modelName: string, refPath: string): string | null;
|
|
116
340
|
getModelSub(modelName: string): string[];
|
|
117
|
-
getModelAtt(modelName: string):
|
|
341
|
+
getModelAtt(modelName: string): string[];
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
type InternalModelHookContext = ModelHookContext & {
|
|
345
|
+
fieldPermissionAccess?: {
|
|
346
|
+
readIds?: Set<string>;
|
|
347
|
+
updateIds?: Set<string>;
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
declare class Core {
|
|
351
|
+
private req;
|
|
352
|
+
private caches;
|
|
353
|
+
constructor(req: AccessRouterBaseRequest);
|
|
354
|
+
getIdentifier(modelName: string): string;
|
|
355
|
+
genIDFilter<TModel = unknown>(modelName: string, id: string): Promise<Filter<TModel>>;
|
|
356
|
+
genFilter<TModel = unknown>(modelName: string, access?: BaseFilterAccess, _filter?: Filter<TModel>): Promise<Filter<TModel>>;
|
|
357
|
+
private removePrefix;
|
|
358
|
+
genAllowedFields(modelName: string, doc: unknown, access: SelectAccess, baseFields?: any[]): Promise<string[]>;
|
|
359
|
+
pickAllowedFields<T>(modelName: string, doc: T, access: SelectAccess, baseFields?: any[]): Promise<T>;
|
|
360
|
+
genSelect(modelName: string, access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: any[]): Promise<string[]>;
|
|
361
|
+
genPopulate(modelName: string, access?: SelectAccess | BaseFilterAccess, _populate?: Populate | Populate[] | string | null): Promise<(string | Populate)[]>;
|
|
362
|
+
validate(modelName: string, allowedData: unknown, access: ValidateAccess, context: ModelHookContext): Promise<boolean | unknown[]>;
|
|
363
|
+
prepare<T>(modelName: string, allowedData: T, access: PrepareAccess, context: ModelHookContext): Promise<T>;
|
|
364
|
+
transform<T>(modelName: string, doc: T, access: TransformAccess, context: ModelHookContext): Promise<T>;
|
|
365
|
+
afterPersist<T>(modelName: string, doc: T, access: AfterPersistAccess, context: ModelHookContext): Promise<T>;
|
|
366
|
+
changes(modelName: string, doc: Record<string, unknown>, context: ModelHookContext): Promise<void>;
|
|
367
|
+
beforeDelete<T>(modelName: string, doc: T, context: ModelHookContext): Promise<void>;
|
|
368
|
+
afterDelete<T>(modelName: string, doc: T, context: ModelHookContext): Promise<void>;
|
|
369
|
+
genDocPermissions(modelName: string, doc: unknown, access: DocPermissionsAccess, context: ModelHookContext): Promise<{}>;
|
|
370
|
+
addEmptyPermissions<T>(modelName: string, doc: T): T;
|
|
371
|
+
addDocPermissions<T>(modelName: string, doc: T, access: DocPermissionsAccess, context: ModelHookContext): Promise<T>;
|
|
372
|
+
addFieldPermissions<T extends {
|
|
373
|
+
_id?: unknown;
|
|
374
|
+
}>(modelName: string, doc: T, access: DocPermissionsAccess, context: InternalModelHookContext): Promise<T>;
|
|
375
|
+
decorate<T>(modelName: string, doc: T, access: DecorateAccess, context: ModelHookContext): Promise<T>;
|
|
376
|
+
decorateAll<T>(modelName: string, docs: T[], access: DecorateAllAccess, context: ModelHookContext): Promise<T[]>;
|
|
377
|
+
runTasks<T extends object>(modelName: string, docObject: T, task: Task | Task[]): T;
|
|
378
|
+
getPermissions(): Permission;
|
|
379
|
+
setPermissions(): Promise<void>;
|
|
380
|
+
canActivate(routeGuard: Validation): Promise<boolean>;
|
|
381
|
+
isAllowed(modelName: string, access: RouteGuardAccess | string): Promise<boolean>;
|
|
382
|
+
getService<TModel = unknown>(modelName: string): Service<TModel>;
|
|
383
|
+
getPublicService<TModel = unknown>(modelName: string): PublicService<TModel>;
|
|
384
|
+
service<TModel = unknown>(modelName: string): PublicService<TModel>;
|
|
385
|
+
svc<TModel = unknown>(modelName: string): PublicService<TModel>;
|
|
386
|
+
private getGlobalPermissions;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
declare class DataCore {
|
|
390
|
+
private req;
|
|
391
|
+
private caches;
|
|
392
|
+
constructor(req: AccessRouterBaseRequest);
|
|
393
|
+
genIDFilter<TData = unknown>(dataName: string, id: string): Promise<Filter<TData>>;
|
|
394
|
+
genFilter<TData = unknown>(dataName: string, access?: BaseFilterAccess, _filter?: Filter<TData>): Promise<Filter<TData>>;
|
|
395
|
+
genAllowedFields(dataName: string, _doc: unknown, access: SelectAccess, baseFields?: any[]): Promise<string[]>;
|
|
396
|
+
pickAllowedFields<TDoc>(dataName: string, doc: TDoc, access: SelectAccess, baseFields?: any[]): Promise<TDoc>;
|
|
397
|
+
genSelect(dataName: string, access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: any[]): Promise<string[]>;
|
|
398
|
+
decorate<TDoc>(dataName: string, doc: TDoc, access: DecorateAccess, context?: DataHookContext): Promise<TDoc>;
|
|
399
|
+
decorateAll<TDoc>(dataName: string, docs: TDoc[], access: DecorateAllAccess, context?: DataHookContext): Promise<TDoc[]>;
|
|
400
|
+
getPermissions(): Permission;
|
|
401
|
+
setPermissions(): Promise<void>;
|
|
402
|
+
canActivate(routeGuard: Validation): Promise<boolean>;
|
|
403
|
+
isAllowed(dataName: string, access: RouteGuardAccess | string): Promise<boolean>;
|
|
404
|
+
getService<TData = unknown>(dataName: string): DataService<TData>;
|
|
405
|
+
service<TData = unknown>(dataName: string): DataService<TData>;
|
|
406
|
+
svc<TData = unknown>(dataName: string): DataService<TData>;
|
|
407
|
+
private getGlobalPermissions;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
declare enum Codes {
|
|
411
|
+
Success = "success",
|
|
412
|
+
Created = "created",
|
|
413
|
+
BadRequest = "bad_request",
|
|
414
|
+
Unauthorized = "unauthorized",
|
|
415
|
+
Forbidden = "forbidden",
|
|
416
|
+
NotFound = "not_found"
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
interface AccessRouterRequestExtensions {
|
|
420
|
+
macl?: Core;
|
|
421
|
+
dacl?: DataCore;
|
|
422
|
+
}
|
|
423
|
+
type AccessRouterRequest = express.Request & AccessRouterRequestExtensions;
|
|
424
|
+
|
|
425
|
+
type GuardHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, permissions: AccessRouterPermissions) => boolean | Promise<boolean>;
|
|
426
|
+
type Validation = boolean | string | string[] | GuardHook;
|
|
427
|
+
type SelectAccess = 'list' | 'create' | 'read' | 'update' | string;
|
|
428
|
+
type RouteGuardAccess = 'new' | 'list' | 'read' | 'update' | 'upsert' | 'delete' | 'create' | 'distinct' | 'count' | 'subs' | string;
|
|
429
|
+
type DocPermissionsAccess = 'list' | 'create' | 'read' | 'update' | string;
|
|
430
|
+
type BaseFilterAccess = 'list' | 'read' | 'update' | 'delete' | string;
|
|
431
|
+
type DecorateAccess = 'list' | 'create' | 'read' | 'update' | string;
|
|
432
|
+
type DecorateAllAccess = 'list' | string;
|
|
433
|
+
type ValidateAccess = 'create' | 'update' | string;
|
|
434
|
+
type PrepareAccess = 'create' | 'update' | string;
|
|
435
|
+
type TransformAccess = 'update' | string;
|
|
436
|
+
type AfterPersistAccess = 'create' | 'update' | string;
|
|
437
|
+
|
|
438
|
+
interface PublicCreateArgs {
|
|
439
|
+
select?: Projection;
|
|
440
|
+
populate?: Populate[] | string;
|
|
441
|
+
tasks?: Task | Task[];
|
|
442
|
+
}
|
|
443
|
+
interface CreateArgs extends Omit<PublicCreateArgs, 'select' | 'tasks'> {
|
|
444
|
+
}
|
|
445
|
+
interface PublicCreateOptions {
|
|
446
|
+
skim?: boolean;
|
|
447
|
+
includePermissions?: boolean;
|
|
448
|
+
populateAccess?: PopulateAccess;
|
|
449
|
+
}
|
|
450
|
+
interface CreateOptions extends PublicCreateOptions {
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
interface PublicListArgs {
|
|
454
|
+
select?: Projection;
|
|
455
|
+
populate?: Populate[] | string;
|
|
456
|
+
include?: Include | Include[];
|
|
457
|
+
sort?: Sort;
|
|
458
|
+
skip?: string | number;
|
|
459
|
+
limit?: string | number;
|
|
460
|
+
page?: string | number;
|
|
461
|
+
pageSize?: string | number;
|
|
462
|
+
tasks?: Task | Task[];
|
|
463
|
+
}
|
|
464
|
+
interface PublicListOptions {
|
|
465
|
+
skim?: boolean;
|
|
466
|
+
includePermissions?: boolean;
|
|
467
|
+
includeCount?: boolean;
|
|
468
|
+
populateAccess?: PopulateAccess;
|
|
469
|
+
lean?: boolean;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
interface PublicReadArgs {
|
|
473
|
+
select?: Projection;
|
|
474
|
+
populate?: Populate[] | string;
|
|
475
|
+
include?: Include | Include[];
|
|
476
|
+
tasks?: Task | Task[];
|
|
477
|
+
}
|
|
478
|
+
interface PublicReadOptions {
|
|
479
|
+
skim?: boolean;
|
|
480
|
+
populateAccess?: PopulateAccess;
|
|
481
|
+
lean?: boolean;
|
|
482
|
+
includePermissions?: boolean;
|
|
483
|
+
tryList?: boolean;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
interface PublicUpdateArgs {
|
|
487
|
+
select?: Projection;
|
|
488
|
+
populate?: Populate[] | string;
|
|
489
|
+
tasks?: Task | Task[];
|
|
490
|
+
}
|
|
491
|
+
interface PublicUpsertArgs extends PublicUpdateArgs {
|
|
492
|
+
}
|
|
493
|
+
interface UpdateOneArgs<T = unknown> extends Omit<PublicUpdateArgs, 'select' | 'tasks'> {
|
|
494
|
+
overrides?: {
|
|
495
|
+
filter?: Filter<T>;
|
|
496
|
+
populate?: Populate[] | string;
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
interface UpdateByIdArgs<T = unknown> extends Omit<UpdateOneArgs<T>, 'overrides'> {
|
|
500
|
+
overrides?: {
|
|
501
|
+
populate?: Populate[] | string;
|
|
502
|
+
idFilter?: Filter<T>;
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
interface UpsertArgs<T = unknown> extends UpdateOneArgs<T> {
|
|
506
|
+
}
|
|
507
|
+
interface PublicUpdateOptions {
|
|
508
|
+
skim?: boolean;
|
|
509
|
+
returningAll?: boolean;
|
|
510
|
+
includePermissions?: boolean;
|
|
511
|
+
populateAccess?: PopulateAccess;
|
|
512
|
+
}
|
|
513
|
+
interface PublicUpsertOptions extends PublicUpdateOptions {
|
|
514
|
+
}
|
|
515
|
+
interface UpdateOneOptions extends Omit<PublicUpdateOptions, 'returningAll'> {
|
|
516
|
+
}
|
|
517
|
+
interface UpdateByIdOptions extends UpdateOneOptions {
|
|
518
|
+
}
|
|
519
|
+
interface UpsertOptions extends UpdateOneOptions {
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
type DataFilter<T = unknown> = Filter<T>;
|
|
523
|
+
interface DataFindOneArgs<T = unknown, TSelect extends Projection | undefined = Projection | undefined> {
|
|
524
|
+
select?: TSelect;
|
|
525
|
+
}
|
|
526
|
+
interface DataFindOneOptions {
|
|
527
|
+
access?: FindAccess;
|
|
528
|
+
}
|
|
529
|
+
interface DataFindArgs<T = unknown, TSelect extends Projection | undefined = Projection | undefined> {
|
|
530
|
+
select?: TSelect;
|
|
531
|
+
sort?: string;
|
|
532
|
+
skip?: string | number;
|
|
533
|
+
limit?: string | number;
|
|
534
|
+
page?: string | number;
|
|
535
|
+
pageSize?: string | number;
|
|
536
|
+
}
|
|
537
|
+
interface DataFindOptions {
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
interface KeyValueProjection {
|
|
541
|
+
[key: string]: 1 | -1;
|
|
542
|
+
}
|
|
543
|
+
type Projection = string[] | string | KeyValueProjection;
|
|
544
|
+
type SortOrder = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
|
|
545
|
+
type Sort = string | {
|
|
546
|
+
[key: string]: SortOrder;
|
|
547
|
+
} | [string, SortOrder][] | undefined | null;
|
|
548
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
549
|
+
type NonTraversable = Primitive | Date | RegExp | Function;
|
|
550
|
+
type PrevDepth = [never, 0, 1, 2, 3, 4, 5];
|
|
551
|
+
type IsUnknown<T> = unknown extends T ? ([keyof T] extends [never] ? true : false) : false;
|
|
552
|
+
type Descend<T> = T extends readonly (infer U)[] ? U : T;
|
|
553
|
+
type ArrayValue<T> = T extends readonly (infer U)[] ? U : T;
|
|
554
|
+
type ComparableValue = string | number | bigint | Date;
|
|
555
|
+
type WithDefaultId<T> = T extends object ? T & {
|
|
556
|
+
_id?: unknown;
|
|
557
|
+
} : {
|
|
558
|
+
_id?: unknown;
|
|
559
|
+
};
|
|
560
|
+
type PublicOutput<T> = T extends object ? T & Record<string, unknown> : Record<string, unknown>;
|
|
561
|
+
type ModelDocument<TModel = unknown> = mongoose.Document & TModel;
|
|
562
|
+
type TrimLeft<S extends string> = S extends ` ${infer Rest}` ? TrimLeft<Rest> : S;
|
|
563
|
+
type TrimRight<S extends string> = S extends `${infer Rest} ` ? TrimRight<Rest> : S;
|
|
564
|
+
type Trim<S extends string> = TrimLeft<TrimRight<S>>;
|
|
565
|
+
type SplitProjectionString<S extends string> = S extends `${infer Head} ${infer Tail}` ? SplitProjectionString<Head> | SplitProjectionString<Tail> : Trim<S>;
|
|
566
|
+
type ProjectionTokens<TProjection> = TProjection extends readonly string[] ? TProjection[number] : TProjection extends string ? SplitProjectionString<TProjection> : TProjection extends KeyValueProjection ? {
|
|
567
|
+
[K in Extract<keyof TProjection, string>]: TProjection[K] extends 1 ? K : never;
|
|
568
|
+
}[Extract<keyof TProjection, string>] : never;
|
|
569
|
+
type PositiveProjectionPaths<TProjection> = ProjectionTokens<TProjection> extends infer TToken ? TToken extends string ? TToken extends '' ? never : TToken extends `-${string}` ? never : TToken : never : never;
|
|
570
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer I) => void ? I : never;
|
|
571
|
+
type Simplify<T> = {
|
|
572
|
+
[K in keyof T]: T[K];
|
|
573
|
+
} & {};
|
|
574
|
+
type DeepPickSingle<T, TPath extends string> = TPath extends `${infer Head}.${infer Tail}` ? Head extends keyof WithDefaultId<T> ? Head extends string ? {
|
|
575
|
+
[K in Head]: WithDefaultId<T>[K] extends readonly (infer U)[] ? Array<Simplify<DeepPickSingle<U, Tail>>> : WithDefaultId<T>[K] extends object ? Simplify<DeepPickSingle<WithDefaultId<T>[K], Tail>> : WithDefaultId<T>[K];
|
|
576
|
+
} : {} : {} : TPath extends keyof WithDefaultId<T> ? Pick<WithDefaultId<T>, TPath> : {};
|
|
577
|
+
type DeepPick<T, TPaths extends string> = Simplify<UnionToIntersection<DeepPickSingle<T, TPaths>>>;
|
|
578
|
+
type SelectedPublicOutput<T, TProjection> = string extends PositiveProjectionPaths<TProjection> ? PublicOutput<T> : [PositiveProjectionPaths<TProjection>] extends [never] ? PublicOutput<T> : DeepPick<T, Extract<PositiveProjectionPaths<TProjection>, string>>;
|
|
579
|
+
type PopulateInput = Populate | string;
|
|
580
|
+
type PopulateInputs<TPopulate> = TPopulate extends readonly (infer U)[] ? U : TPopulate;
|
|
581
|
+
type PopulatePath<TPopulateEntry> = TPopulateEntry extends string ? TPopulateEntry : TPopulateEntry extends {
|
|
582
|
+
path: infer TPath extends string;
|
|
583
|
+
} ? TPath : never;
|
|
584
|
+
type PopulateSelect<TPopulateEntry> = TPopulateEntry extends {
|
|
585
|
+
select?: infer TSelect;
|
|
586
|
+
} ? TSelect : undefined;
|
|
587
|
+
type PopulateLeafValue<TValue, TPopulateEntry> = TValue extends readonly (infer U)[] ? Array<SelectedPublicOutput<U, PopulateSelect<TPopulateEntry>>> : SelectedPublicOutput<TValue, PopulateSelect<TPopulateEntry>>;
|
|
588
|
+
type PopulateEntryShape<T, TPath extends string, TValue> = TPath extends `${infer Head}.${infer Tail}` ? Head extends keyof WithDefaultId<T> ? Head extends string ? {
|
|
589
|
+
[K in Head]: WithDefaultId<T>[K] extends readonly (infer U)[] ? Array<Simplify<PopulateEntryShape<U, Tail, TValue>>> : Simplify<PopulateEntryShape<WithDefaultId<T>[K], Tail, TValue>>;
|
|
590
|
+
} : {} : {} : TPath extends keyof WithDefaultId<T> ? Pick<{
|
|
591
|
+
[K in TPath]: TValue;
|
|
592
|
+
}, TPath> : {};
|
|
593
|
+
type PopulateOutputShape<T, TPopulateEntry> = PopulatePath<TPopulateEntry> extends infer TPath extends string ? PopulateEntryShape<T, TPath, PopulateLeafValue<PathValue<WithDefaultId<T>, TPath>, TPopulateEntry>> : {};
|
|
594
|
+
type PopulateOutput<T, TPopulate> = string extends PopulatePath<PopulateInputs<TPopulate>> ? {} : [PopulatePath<PopulateInputs<TPopulate>>] extends [never] ? {} : Simplify<UnionToIntersection<PopulateOutputShape<T, Extract<PopulateInputs<TPopulate>, PopulateInput>>>>;
|
|
595
|
+
type SelectedPopulatedPublicOutput<T, TProjection, TPopulate> = Simplify<SelectedPublicOutput<T, TProjection> & PopulateOutput<T, TPopulate>>;
|
|
596
|
+
type DeepFieldPath<T, Depth extends number = 4> = [Depth] extends [never] ? never : Descend<T> extends NonTraversable ? never : {
|
|
597
|
+
[K in Extract<keyof Descend<T>, string>]: K | (Descend<T>[K] extends NonTraversable ? never : Descend<T>[K] extends readonly (infer U)[] ? U extends NonTraversable ? never : `${K}.${DeepFieldPath<U, PrevDepth[Depth]>}` : Descend<T>[K] extends object ? `${K}.${DeepFieldPath<Descend<T>[K], PrevDepth[Depth]>}` : never);
|
|
598
|
+
}[Extract<keyof Descend<T>, string>];
|
|
599
|
+
type PathValue<T, TPath extends string> = TPath extends `${infer Head}.${infer Tail}` ? Head extends Extract<keyof Descend<T>, string> ? PathValue<Descend<Descend<T>[Head]>, Tail> : unknown : TPath extends Extract<keyof Descend<T>, string> ? Descend<T>[TPath] : unknown;
|
|
600
|
+
type FieldFilterOperators<T> = {
|
|
601
|
+
$eq?: T;
|
|
602
|
+
$ne?: T;
|
|
603
|
+
$in?: Array<ArrayValue<T>>;
|
|
604
|
+
$nin?: Array<ArrayValue<T>>;
|
|
605
|
+
$exists?: boolean;
|
|
606
|
+
$gt?: ArrayValue<T> extends ComparableValue ? ArrayValue<T> : never;
|
|
607
|
+
$gte?: ArrayValue<T> extends ComparableValue ? ArrayValue<T> : never;
|
|
608
|
+
$lt?: ArrayValue<T> extends ComparableValue ? ArrayValue<T> : never;
|
|
609
|
+
$lte?: ArrayValue<T> extends ComparableValue ? ArrayValue<T> : never;
|
|
610
|
+
$regex?: ArrayValue<T> extends string ? string | RegExp : never;
|
|
611
|
+
$all?: T extends readonly unknown[] ? Array<ArrayValue<T>> : never;
|
|
612
|
+
$size?: T extends readonly unknown[] ? number : never;
|
|
613
|
+
$elemMatch?: ArrayValue<T> extends object ? TypedFilter<ArrayValue<T>> : never;
|
|
614
|
+
$$sq?: unknown;
|
|
615
|
+
$$date?: unknown;
|
|
616
|
+
[key: `$${string}`]: unknown;
|
|
617
|
+
};
|
|
618
|
+
type FieldFilterValue<T> = T | FieldFilterOperators<NonNullable<T>>;
|
|
619
|
+
type LooseFilter = false | Record<string, unknown>;
|
|
620
|
+
type TypedFilterObject<T> = {
|
|
621
|
+
[K in DeepFieldPath<T>]?: FieldFilterValue<PathValue<T, K>>;
|
|
622
|
+
} & {
|
|
623
|
+
_id?: FieldFilterValue<unknown>;
|
|
624
|
+
$and?: TypedFilter<T>[];
|
|
625
|
+
$or?: TypedFilter<T>[];
|
|
626
|
+
$nor?: TypedFilter<T>[];
|
|
627
|
+
[key: `$${string}`]: unknown;
|
|
628
|
+
};
|
|
629
|
+
type TypedFilter<T> = false | TypedFilterObject<WithDefaultId<T>>;
|
|
630
|
+
type Filter<T = unknown> = IsUnknown<T> extends true ? LooseFilter : TypedFilter<T>;
|
|
631
|
+
interface Include {
|
|
632
|
+
model: string;
|
|
633
|
+
op: 'list' | 'read' | 'count';
|
|
634
|
+
path: string;
|
|
635
|
+
filter?: Filter;
|
|
636
|
+
localField: string;
|
|
637
|
+
foreignField: string;
|
|
638
|
+
args?: unknown;
|
|
639
|
+
options?: unknown;
|
|
640
|
+
}
|
|
641
|
+
type FindAccess = 'list' | 'read';
|
|
642
|
+
type PopulateAccess = 'list' | 'read';
|
|
643
|
+
interface Populate {
|
|
644
|
+
path: string;
|
|
645
|
+
select?: Projection;
|
|
646
|
+
match?: unknown;
|
|
647
|
+
access?: PopulateAccess;
|
|
648
|
+
}
|
|
649
|
+
interface SubPopulate {
|
|
650
|
+
path: string;
|
|
651
|
+
select?: Projection;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
interface KeyValue {
|
|
655
|
+
[key: string]: unknown;
|
|
656
|
+
}
|
|
657
|
+
interface Change {
|
|
658
|
+
op: 'add' | 'replace' | 'remove';
|
|
659
|
+
path: Array<string | number>;
|
|
660
|
+
value?: unknown;
|
|
661
|
+
}
|
|
662
|
+
interface ModelHookContext {
|
|
663
|
+
modelName: string;
|
|
664
|
+
mongooseModel: mongoose.Model<unknown>;
|
|
665
|
+
operation?: string;
|
|
666
|
+
originalDocumentSnapshot?: Record<string, unknown>;
|
|
667
|
+
finalDocumentSnapshot?: Record<string, unknown>;
|
|
668
|
+
currentDocument?: ModelDocument;
|
|
669
|
+
originalData?: Record<string, unknown>;
|
|
670
|
+
allowedData?: Record<string, unknown>;
|
|
671
|
+
preparedData?: Record<string, unknown>;
|
|
672
|
+
allowedFields?: string[];
|
|
673
|
+
modifiedPaths?: string[];
|
|
674
|
+
changes?: Change[];
|
|
675
|
+
docPermissions?: KeyValue;
|
|
676
|
+
resolvedQuery?: {
|
|
677
|
+
filter?: Filter;
|
|
678
|
+
select?: string[];
|
|
679
|
+
populate?: Populate[] | string;
|
|
680
|
+
sort?: Sort;
|
|
681
|
+
skip?: number;
|
|
682
|
+
limit?: number;
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
interface DataHookContext {
|
|
686
|
+
dataName?: string;
|
|
687
|
+
operation?: string;
|
|
688
|
+
resolvedQuery?: {
|
|
689
|
+
filter?: Filter;
|
|
690
|
+
select?: string[];
|
|
691
|
+
sort?: Sort;
|
|
692
|
+
skip?: number;
|
|
693
|
+
limit?: number;
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
interface Task {
|
|
697
|
+
type: string;
|
|
698
|
+
args: unknown;
|
|
699
|
+
options: Record<string, unknown>;
|
|
700
|
+
}
|
|
701
|
+
interface AccessRouterBaseRequest extends AccessRouterRequest {
|
|
702
|
+
query: Record<'skip' | 'limit' | 'page' | 'page_size' | 'try_list' | 'skim' | 'include_permissions' | 'include_count' | 'include_extra_headers' | 'returning_all', string>;
|
|
703
|
+
}
|
|
704
|
+
interface ModelRequest extends AccessRouterBaseRequest {
|
|
705
|
+
macl: Core;
|
|
706
|
+
}
|
|
707
|
+
interface DataRequest extends AccessRouterBaseRequest {
|
|
708
|
+
dacl: DataCore;
|
|
709
|
+
}
|
|
710
|
+
interface ErrorResult<TError = unknown, TQuery = unknown> {
|
|
711
|
+
success: false;
|
|
712
|
+
code: Codes.BadRequest | Codes.Unauthorized | Codes.Forbidden | Codes.NotFound;
|
|
713
|
+
errors?: TError[];
|
|
714
|
+
query?: TQuery;
|
|
715
|
+
}
|
|
716
|
+
interface SingleResult<T = unknown, TInput = unknown, TQuery = unknown> {
|
|
717
|
+
success: true;
|
|
718
|
+
kind: 'single';
|
|
719
|
+
code: Codes.Success | Codes.Created;
|
|
720
|
+
data: T;
|
|
721
|
+
input?: TInput;
|
|
722
|
+
query?: TQuery;
|
|
723
|
+
context?: ModelHookContext;
|
|
724
|
+
}
|
|
725
|
+
interface ListResult<T = unknown, TInput = unknown, TQuery = unknown> {
|
|
726
|
+
success: true;
|
|
727
|
+
kind: 'list';
|
|
728
|
+
code: Codes.Success | Codes.Created;
|
|
729
|
+
data: T[];
|
|
730
|
+
count: number;
|
|
731
|
+
totalCount?: number | null;
|
|
732
|
+
input?: TInput;
|
|
733
|
+
query?: TQuery;
|
|
734
|
+
contexts?: ModelHookContext[];
|
|
735
|
+
}
|
|
736
|
+
type ServiceResult<T = unknown, TError = unknown, TInput = unknown, TQuery = unknown> = SingleResult<T, TInput, TQuery> | ListResult<T, TInput, TQuery> | ErrorResult<TError, TQuery>;
|
|
737
|
+
|
|
738
|
+
interface FindArgs<T = unknown> {
|
|
739
|
+
select?: Projection;
|
|
740
|
+
populate?: Populate[] | string;
|
|
741
|
+
include?: Include | Include[];
|
|
742
|
+
sort?: Sort;
|
|
743
|
+
skip?: string | number;
|
|
744
|
+
limit?: string | number;
|
|
745
|
+
page?: string | number;
|
|
746
|
+
pageSize?: string | number;
|
|
747
|
+
overrides?: {
|
|
748
|
+
filter?: Filter<T>;
|
|
749
|
+
select?: Projection;
|
|
750
|
+
populate?: Populate[] | string;
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
interface FindOptions {
|
|
754
|
+
skim?: boolean;
|
|
755
|
+
includePermissions?: boolean;
|
|
756
|
+
includeCount?: boolean;
|
|
757
|
+
populateAccess?: PopulateAccess;
|
|
758
|
+
lean?: boolean;
|
|
759
|
+
}
|
|
760
|
+
interface FindOneArgs<T = unknown> {
|
|
761
|
+
select?: Projection;
|
|
762
|
+
sort?: Sort;
|
|
763
|
+
populate?: Populate[] | string;
|
|
764
|
+
include?: Include | Include[];
|
|
765
|
+
overrides?: {
|
|
766
|
+
filter?: Filter<T>;
|
|
767
|
+
select?: Projection;
|
|
768
|
+
populate?: Populate[] | string;
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
interface FindOneOptions {
|
|
772
|
+
access?: FindAccess;
|
|
773
|
+
populateAccess?: PopulateAccess;
|
|
774
|
+
skim?: boolean;
|
|
775
|
+
lean?: boolean;
|
|
776
|
+
includePermissions?: boolean;
|
|
777
|
+
}
|
|
778
|
+
interface FindByIdArgs<T = unknown> {
|
|
779
|
+
select?: Projection;
|
|
780
|
+
populate?: Populate[] | string;
|
|
781
|
+
include?: Include | Include[];
|
|
782
|
+
overrides?: {
|
|
783
|
+
select?: Projection;
|
|
784
|
+
populate?: Populate[] | string;
|
|
785
|
+
idFilter?: Filter<T>;
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
interface FindByIdOptions extends FindOneOptions {
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
interface ExistsOptions {
|
|
792
|
+
access?: BaseFilterAccess;
|
|
793
|
+
includeId?: boolean;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
797
|
+
type AccessRouterFieldKey<T> = [Extract<keyof T, string>] extends [never] ? string : Extract<keyof T, string>;
|
|
798
|
+
type IdentifierHook<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, id: string) => MaybePromise<Filter<TValue>>;
|
|
799
|
+
type GlobalPermissionValue = Record<string, boolean> | string[] | string | null | undefined;
|
|
800
|
+
type BaseFilterHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, permissions: AccessRouterPermissions) => MaybePromise<Filter | true | null | undefined>;
|
|
801
|
+
type OverrideFilterHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, filter: Filter, permissions: AccessRouterPermissions) => MaybePromise<Filter>;
|
|
802
|
+
type Hook<TValue, TContext, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: TValue, permissions: AccessRouterPermissions, context: TContext) => MaybePromise<TValue>;
|
|
803
|
+
type HookChain<TValue, TContext, TRequest extends AccessRouterRequest = AccessRouterRequest> = Hook<TValue, TContext, TRequest> | Array<Hook<TValue, TContext, TRequest>>;
|
|
804
|
+
type ValidateRule = boolean | unknown[];
|
|
805
|
+
type ValidateHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, allowedData: unknown, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<ValidateRule>;
|
|
806
|
+
type DocPermissionsHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, doc: unknown, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<Record<string, unknown>>;
|
|
807
|
+
type ChangeHook<TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, previousValue: unknown, nextValue: unknown, changes: Change[], context: ModelHookContext) => MaybePromise<void>;
|
|
808
|
+
type DeleteHook<TValue = unknown, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: TValue, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<void>;
|
|
809
|
+
type DocumentHook<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = (this: TRequest, value: ModelDocument<TValue>, permissions: AccessRouterPermissions, context: ModelHookContext) => MaybePromise<ModelDocument<TValue>>;
|
|
810
|
+
type DocumentHookChain<TValue, TRequest extends AccessRouterRequest = AccessRouterRequest> = DocumentHook<TValue, TRequest> | Array<DocumentHook<TValue, TRequest>>;
|
|
811
|
+
type ModelBaseFilterHook = BaseFilterHook<ModelRequest>;
|
|
812
|
+
type DataBaseFilterHook = BaseFilterHook<DataRequest>;
|
|
813
|
+
type ModelOverrideFilterHook = OverrideFilterHook<ModelRequest>;
|
|
814
|
+
type DataOverrideFilterHook = OverrideFilterHook<DataRequest>;
|
|
815
|
+
type ModelIdentifierHook<TValue = unknown> = IdentifierHook<TValue, ModelRequest>;
|
|
816
|
+
type DataIdentifierHook<TValue = unknown> = IdentifierHook<TValue, DataRequest>;
|
|
817
|
+
type ModelValidateHook = ValidateHook<ModelRequest>;
|
|
818
|
+
type ModelDocPermissionsHook = DocPermissionsHook<ModelRequest>;
|
|
819
|
+
type ModelChangeHook = ChangeHook<ModelRequest>;
|
|
820
|
+
type ModelDocumentHook<TValue = unknown> = DocumentHookChain<TValue, ModelRequest>;
|
|
821
|
+
type ModelDeleteHook<TValue = unknown> = DeleteHook<ModelDocument<TValue>, ModelRequest>;
|
|
822
|
+
type ModelHook<TValue = unknown> = HookChain<TValue, ModelHookContext, ModelRequest>;
|
|
823
|
+
type ModelListHook<TValue = unknown> = HookChain<TValue[], ModelHookContext, ModelRequest>;
|
|
824
|
+
type DataHook<TValue = unknown> = HookChain<TValue, DataHookContext, DataRequest>;
|
|
825
|
+
type DataListHook<TValue = unknown> = HookChain<TValue[], DataHookContext, DataRequest>;
|
|
826
|
+
|
|
827
|
+
type RequestSchemaIssue = {
|
|
828
|
+
message: string;
|
|
829
|
+
path?: Array<string | number>;
|
|
830
|
+
};
|
|
831
|
+
type RequestSchemaSuccess<T = unknown> = {
|
|
832
|
+
success: true;
|
|
833
|
+
data: T;
|
|
834
|
+
};
|
|
835
|
+
type RequestSchemaFailure = {
|
|
836
|
+
success: false;
|
|
837
|
+
issues: RequestSchemaIssue[];
|
|
838
|
+
};
|
|
839
|
+
type RequestSchemaResult<T = unknown> = RequestSchemaSuccess<T> | RequestSchemaFailure;
|
|
840
|
+
type RequestSchemaValidator<T = unknown> = (value: unknown) => RequestSchemaResult<T> | Promise<RequestSchemaResult<T>>;
|
|
841
|
+
type RequestSchemaAdapter<T = unknown> = {
|
|
842
|
+
validate: RequestSchemaValidator<T>;
|
|
843
|
+
openapi?: Record<string, unknown>;
|
|
844
|
+
};
|
|
845
|
+
type RequestSchemaOptions = {
|
|
846
|
+
openapi?: Record<string, unknown>;
|
|
847
|
+
};
|
|
848
|
+
type StandardSchemaPathSegment = {
|
|
849
|
+
key: PropertyKey;
|
|
850
|
+
};
|
|
851
|
+
type StandardSchemaIssue = {
|
|
852
|
+
message: string;
|
|
853
|
+
path?: ReadonlyArray<PropertyKey | StandardSchemaPathSegment>;
|
|
854
|
+
};
|
|
855
|
+
type StandardSchemaSuccess<T = unknown> = {
|
|
856
|
+
value: T;
|
|
857
|
+
issues?: undefined;
|
|
858
|
+
};
|
|
859
|
+
type StandardSchemaFailure = {
|
|
860
|
+
issues: ReadonlyArray<StandardSchemaIssue>;
|
|
861
|
+
};
|
|
862
|
+
type StandardSchemaResult<T = unknown> = StandardSchemaSuccess<T> | StandardSchemaFailure;
|
|
863
|
+
type StandardSchemaV1<Input = unknown, Output = Input> = {
|
|
864
|
+
readonly '~standard': {
|
|
865
|
+
readonly version: 1;
|
|
866
|
+
readonly vendor: string;
|
|
867
|
+
readonly validate: (value: unknown, options?: {
|
|
868
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
869
|
+
}) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
870
|
+
readonly types?: {
|
|
871
|
+
readonly input: Input;
|
|
872
|
+
readonly output: Output;
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
};
|
|
876
|
+
type StandardSchemaInferOutput<TSchema extends StandardSchemaV1> = NonNullable<TSchema['~standard']['types']>['output'];
|
|
877
|
+
type RequestSchemaLike<T = unknown> = RequestSchemaValidator<T> | RequestSchemaAdapter<T> | StandardSchemaV1;
|
|
878
|
+
type YupValidationErrorLike = {
|
|
879
|
+
message: string;
|
|
880
|
+
path?: string;
|
|
881
|
+
inner?: ReadonlyArray<YupValidationErrorLike>;
|
|
882
|
+
};
|
|
883
|
+
type YupSchemaLike<T = unknown> = {
|
|
884
|
+
validate: (value: unknown, options?: {
|
|
885
|
+
abortEarly?: boolean;
|
|
886
|
+
stripUnknown?: boolean;
|
|
887
|
+
}) => Promise<T> | T;
|
|
888
|
+
};
|
|
889
|
+
type JoiValidationErrorDetailLike = {
|
|
890
|
+
message: string;
|
|
891
|
+
path?: ReadonlyArray<string | number>;
|
|
892
|
+
};
|
|
893
|
+
type JoiSchemaLike<T = unknown> = {
|
|
894
|
+
validate: (value: unknown, options?: {
|
|
895
|
+
abortEarly?: boolean;
|
|
896
|
+
stripUnknown?: boolean;
|
|
897
|
+
}) => {
|
|
898
|
+
value: T;
|
|
899
|
+
error?: {
|
|
900
|
+
details?: ReadonlyArray<JoiValidationErrorDetailLike>;
|
|
901
|
+
};
|
|
902
|
+
} | Promise<{
|
|
903
|
+
value: T;
|
|
904
|
+
error?: {
|
|
905
|
+
details?: ReadonlyArray<JoiValidationErrorDetailLike>;
|
|
906
|
+
};
|
|
907
|
+
}>;
|
|
908
|
+
};
|
|
909
|
+
type AjvErrorObjectLike = {
|
|
910
|
+
message?: string;
|
|
911
|
+
instancePath?: string;
|
|
912
|
+
schemaPath?: string;
|
|
913
|
+
params?: {
|
|
914
|
+
missingProperty?: string;
|
|
915
|
+
};
|
|
916
|
+
};
|
|
917
|
+
type AjvValidatorLike<T = unknown> = {
|
|
918
|
+
(value: unknown): boolean | Promise<boolean>;
|
|
919
|
+
errors?: ReadonlyArray<AjvErrorObjectLike> | null;
|
|
920
|
+
};
|
|
921
|
+
type ValibotPathItemLike = {
|
|
922
|
+
key?: unknown;
|
|
923
|
+
};
|
|
924
|
+
type ValibotIssueLike = {
|
|
925
|
+
message: string;
|
|
926
|
+
path?: ReadonlyArray<ValibotPathItemLike>;
|
|
927
|
+
};
|
|
928
|
+
type ValibotSafeParseResult<T = unknown> = {
|
|
929
|
+
success: true;
|
|
930
|
+
output: T;
|
|
931
|
+
issues?: undefined;
|
|
932
|
+
} | {
|
|
933
|
+
success: false;
|
|
934
|
+
output?: undefined;
|
|
935
|
+
issues: ReadonlyArray<ValibotIssueLike>;
|
|
936
|
+
};
|
|
937
|
+
type ValibotSafeParseLike = <TSchema, TOutput = unknown>(schema: TSchema, value: unknown, config?: {
|
|
938
|
+
abortEarly?: boolean;
|
|
939
|
+
}) => ValibotSafeParseResult<TOutput> | Promise<ValibotSafeParseResult<TOutput>>;
|
|
940
|
+
type ArkTypeProblemLike = {
|
|
941
|
+
path?: ReadonlyArray<string | number>;
|
|
942
|
+
message?: string;
|
|
943
|
+
problem?: string;
|
|
944
|
+
};
|
|
945
|
+
type ArkTypeErrorsLike = ReadonlyArray<ArkTypeProblemLike> & {
|
|
946
|
+
summary?: string;
|
|
947
|
+
};
|
|
948
|
+
type ArkTypeLike<T = unknown> = {
|
|
949
|
+
(value: unknown): T | ArkTypeErrorsLike;
|
|
950
|
+
errors?: unknown;
|
|
951
|
+
};
|
|
952
|
+
type IoTsContextEntryLike = {
|
|
953
|
+
key: string;
|
|
954
|
+
};
|
|
955
|
+
type IoTsDecodeErrorLike = {
|
|
956
|
+
message?: string;
|
|
957
|
+
context: ReadonlyArray<IoTsContextEntryLike>;
|
|
958
|
+
};
|
|
959
|
+
type IoTsDecoderLike<T = unknown> = {
|
|
960
|
+
decode: (value: unknown) => {
|
|
961
|
+
_tag: 'Left';
|
|
962
|
+
left: ReadonlyArray<IoTsDecodeErrorLike>;
|
|
963
|
+
} | {
|
|
964
|
+
_tag: 'Right';
|
|
965
|
+
right: T;
|
|
966
|
+
};
|
|
967
|
+
};
|
|
968
|
+
type SuperstructFailureLike = {
|
|
969
|
+
message?: string;
|
|
970
|
+
path?: ReadonlyArray<string | number>;
|
|
971
|
+
key?: string | number;
|
|
972
|
+
branch?: ReadonlyArray<unknown>;
|
|
973
|
+
failures?: () => ReadonlyArray<SuperstructFailureLike>;
|
|
974
|
+
};
|
|
975
|
+
type SuperstructValidateLike = <TStruct, TOutput = unknown>(value: unknown, struct: TStruct) => readonly [failure: SuperstructFailureLike, value: undefined] | readonly [failure: undefined, value: TOutput] | Promise<readonly [failure: SuperstructFailureLike, value: undefined] | readonly [failure: undefined, value: TOutput]>;
|
|
976
|
+
type VineValidationMessageLike = {
|
|
977
|
+
field: string;
|
|
978
|
+
message: string;
|
|
979
|
+
index?: number;
|
|
980
|
+
};
|
|
981
|
+
type VineValidationErrorLike = {
|
|
982
|
+
messages: ReadonlyArray<VineValidationMessageLike>;
|
|
983
|
+
};
|
|
984
|
+
type VineValidatorLike<T = unknown> = {
|
|
985
|
+
validate: (value: unknown) => Promise<T> | T;
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
interface DefaultFindOneArgs<TModel = unknown> extends Omit<FindOneArgs<TModel>, 'overrides'> {
|
|
989
|
+
}
|
|
990
|
+
interface DefaultFindByIdArgs<TModel = unknown> extends Omit<FindByIdArgs<TModel>, 'overrides'> {
|
|
991
|
+
}
|
|
992
|
+
interface DefaultFindArgs<TModel = unknown> extends Omit<FindArgs<TModel>, 'overrides'> {
|
|
993
|
+
}
|
|
994
|
+
type RequestSchema = RequestSchemaLike;
|
|
995
|
+
type NestedRequestSchema = {
|
|
996
|
+
default?: RequestSchema;
|
|
997
|
+
data?: RequestSchema;
|
|
998
|
+
};
|
|
999
|
+
type SubRouteGuardOptions = Record<string, Validation | Record<string, Validation>>;
|
|
1000
|
+
interface RequestSchemas {
|
|
1001
|
+
create?: RequestSchema;
|
|
1002
|
+
update?: RequestSchema;
|
|
1003
|
+
upsert?: RequestSchema;
|
|
1004
|
+
count?: RequestSchema;
|
|
1005
|
+
distinct?: RequestSchema;
|
|
1006
|
+
advancedList?: RequestSchema;
|
|
1007
|
+
advancedReadFilter?: RequestSchema;
|
|
1008
|
+
advancedRead?: RequestSchema;
|
|
1009
|
+
advancedCreate?: RequestSchema | NestedRequestSchema;
|
|
1010
|
+
advancedCreateData?: RequestSchema;
|
|
1011
|
+
advancedUpdate?: RequestSchema | NestedRequestSchema;
|
|
1012
|
+
advancedUpdateData?: RequestSchema;
|
|
1013
|
+
advancedUpsert?: RequestSchema | NestedRequestSchema;
|
|
1014
|
+
advancedUpsertData?: RequestSchema;
|
|
1015
|
+
subList?: RequestSchema;
|
|
1016
|
+
subRead?: RequestSchema;
|
|
1017
|
+
subCreate?: RequestSchema;
|
|
1018
|
+
subUpdate?: RequestSchema;
|
|
1019
|
+
subBulkUpdate?: RequestSchema;
|
|
1020
|
+
}
|
|
1021
|
+
interface DataRequestSchemas {
|
|
1022
|
+
advancedList?: RequestSchema;
|
|
1023
|
+
advancedReadFilter?: RequestSchema;
|
|
1024
|
+
advancedRead?: RequestSchema;
|
|
1025
|
+
}
|
|
1026
|
+
interface Defaults<TModel = unknown> {
|
|
1027
|
+
findOneArgs?: DefaultFindOneArgs<TModel>;
|
|
1028
|
+
findOneOptions?: FindOneOptions;
|
|
1029
|
+
findByIdArgs?: DefaultFindByIdArgs<TModel>;
|
|
1030
|
+
findByIdOptions?: FindByIdOptions;
|
|
1031
|
+
findArgs?: DefaultFindArgs<TModel>;
|
|
1032
|
+
findOptions?: FindOptions;
|
|
1033
|
+
createArgs?: CreateArgs;
|
|
1034
|
+
createOptions?: CreateOptions;
|
|
1035
|
+
updateOneArgs?: UpdateOneArgs<TModel>;
|
|
1036
|
+
updateOneOptions?: UpdateOneOptions;
|
|
1037
|
+
upsertOptions?: UpsertOptions;
|
|
1038
|
+
updateByIdArgs?: UpdateByIdArgs<TModel>;
|
|
1039
|
+
upsertArgs?: UpsertArgs<TModel>;
|
|
1040
|
+
updateByIdOptions?: UpdateByIdOptions;
|
|
1041
|
+
existsOptions?: ExistsOptions;
|
|
1042
|
+
publicListArgs?: PublicListArgs;
|
|
1043
|
+
publicListOptions?: PublicListOptions;
|
|
1044
|
+
publicCreateArgs?: PublicCreateArgs;
|
|
1045
|
+
publicCreateOptions?: PublicCreateOptions;
|
|
1046
|
+
publicReadArgs?: PublicReadArgs;
|
|
1047
|
+
publicReadOptions?: PublicReadOptions;
|
|
1048
|
+
publicUpdateArgs?: PublicUpdateArgs;
|
|
1049
|
+
publicUpdateOptions?: PublicUpdateOptions;
|
|
1050
|
+
}
|
|
1051
|
+
interface AccessRouterLogger {
|
|
1052
|
+
debug?: (...args: unknown[]) => unknown;
|
|
1053
|
+
info?: (...args: unknown[]) => unknown;
|
|
1054
|
+
warn?: (...args: unknown[]) => unknown;
|
|
1055
|
+
error?: (...args: unknown[]) => unknown;
|
|
1056
|
+
}
|
|
1057
|
+
interface GlobalOptions {
|
|
1058
|
+
requestPermissionField?: string;
|
|
1059
|
+
globalPermissions?: (this: AccessRouterRequest, req: AccessRouterRequest) => MaybePromise<GlobalPermissionValue>;
|
|
1060
|
+
logger?: AccessRouterLogger;
|
|
1061
|
+
}
|
|
1062
|
+
interface RootRouterOptions {
|
|
1063
|
+
basePath: string;
|
|
1064
|
+
operationAccess?: Validation;
|
|
1065
|
+
}
|
|
1066
|
+
interface OperationAccess {
|
|
1067
|
+
new?: Validation;
|
|
1068
|
+
list?: Validation;
|
|
1069
|
+
create?: Validation;
|
|
1070
|
+
read?: Validation;
|
|
1071
|
+
update?: Validation;
|
|
1072
|
+
upsert?: Validation;
|
|
1073
|
+
delete?: Validation;
|
|
1074
|
+
distinct?: Validation;
|
|
1075
|
+
count?: Validation;
|
|
1076
|
+
subs?: Validation | SubRouteGuardOptions;
|
|
1077
|
+
}
|
|
1078
|
+
type PermissionRule = Validation | OperationAccess;
|
|
1079
|
+
type PermissionSchema<TField extends string = string> = Partial<Record<TField, PermissionRule>>;
|
|
1080
|
+
interface DocPermissions {
|
|
1081
|
+
list?: ModelDocPermissionsHook;
|
|
1082
|
+
create?: ModelDocPermissionsHook;
|
|
1083
|
+
read?: ModelDocPermissionsHook;
|
|
1084
|
+
update?: ModelDocPermissionsHook;
|
|
1085
|
+
}
|
|
1086
|
+
interface DefaultModelRouterOptions<TModel = unknown> {
|
|
1087
|
+
listHardLimit?: number;
|
|
1088
|
+
documentPermissionField?: string;
|
|
1089
|
+
idParam?: string;
|
|
1090
|
+
idField?: string;
|
|
1091
|
+
resolveIdFilter?: ModelIdentifierHook<TModel>;
|
|
1092
|
+
parentPath?: string;
|
|
1093
|
+
queryRouteSegment?: string;
|
|
1094
|
+
mutationRouteSegment?: string;
|
|
1095
|
+
operationAccess?: Validation | OperationAccess;
|
|
1096
|
+
modelPermissionPrefix?: string;
|
|
1097
|
+
}
|
|
1098
|
+
interface ExtendedDefaultModelRouterOptions<TModel = unknown> extends DefaultModelRouterOptions<TModel> {
|
|
1099
|
+
'operationAccess.default'?: Validation;
|
|
1100
|
+
'operationAccess.new'?: Validation;
|
|
1101
|
+
'operationAccess.list'?: Validation;
|
|
1102
|
+
'operationAccess.read'?: Validation;
|
|
1103
|
+
'operationAccess.update'?: Validation;
|
|
1104
|
+
'operationAccess.delete'?: Validation;
|
|
1105
|
+
'operationAccess.create'?: Validation;
|
|
1106
|
+
'operationAccess.distinct'?: Validation;
|
|
1107
|
+
'operationAccess.count'?: Validation;
|
|
1108
|
+
'operationAccess.subs'?: SubRouteGuardOptions;
|
|
1109
|
+
}
|
|
1110
|
+
interface ModelRouterOptions<TModel = unknown> extends DefaultModelRouterOptions<TModel> {
|
|
1111
|
+
modelName?: string;
|
|
1112
|
+
basePath?: string;
|
|
1113
|
+
permissionSchema?: PermissionSchema<AccessRouterFieldKey<TModel>>;
|
|
1114
|
+
alwaysSelectFields?: string[];
|
|
1115
|
+
docPermissions?: DocPermissions | ModelDocPermissionsHook;
|
|
1116
|
+
baseFilter?: ModelBaseFilterHook | Record<string, ModelBaseFilterHook>;
|
|
1117
|
+
overrideFilter?: ModelOverrideFilterHook | Record<string, ModelOverrideFilterHook>;
|
|
1118
|
+
decorate?: ModelHook<TModel> | Record<string, ModelHook<TModel>>;
|
|
1119
|
+
decorateAll?: ModelListHook<TModel> | Record<string, ModelListHook<TModel>>;
|
|
1120
|
+
validate?: ValidateRule | ModelValidateHook | Record<string, ValidateRule | ModelValidateHook>;
|
|
1121
|
+
prepare?: ModelHook<TModel> | Record<string, ModelHook<TModel>>;
|
|
1122
|
+
transform?: ModelDocumentHook<TModel> | Record<string, ModelDocumentHook<TModel>>;
|
|
1123
|
+
afterPersist?: ModelDocumentHook<TModel> | Record<string, ModelDocumentHook<TModel>>;
|
|
1124
|
+
onChange?: Record<string, ModelChangeHook>;
|
|
1125
|
+
beforeDelete?: ModelDeleteHook<TModel>;
|
|
1126
|
+
afterDelete?: ModelDeleteHook<TModel>;
|
|
1127
|
+
requestSchemas?: RequestSchemas;
|
|
1128
|
+
defaults?: Defaults<TModel>;
|
|
1129
|
+
}
|
|
1130
|
+
interface DataRouterOptions<TData = unknown> {
|
|
1131
|
+
data?: TData[];
|
|
1132
|
+
listHardLimit?: number;
|
|
1133
|
+
idParam?: string;
|
|
1134
|
+
idField?: string;
|
|
1135
|
+
resolveIdFilter?: DataIdentifierHook<TData>;
|
|
1136
|
+
parentPath?: string;
|
|
1137
|
+
queryRouteSegment?: string;
|
|
1138
|
+
operationAccess?: Validation | OperationAccess;
|
|
1139
|
+
dataName?: string;
|
|
1140
|
+
basePath?: string;
|
|
1141
|
+
permissionSchema?: PermissionSchema<AccessRouterFieldKey<TData>>;
|
|
1142
|
+
baseFilter?: DataBaseFilterHook | Record<string, DataBaseFilterHook>;
|
|
1143
|
+
overrideFilter?: DataOverrideFilterHook | Record<string, DataOverrideFilterHook>;
|
|
1144
|
+
decorate?: DataHook<TData> | Record<string, DataHook<TData>>;
|
|
1145
|
+
decorateAll?: DataListHook<TData> | Record<string, DataListHook<TData>>;
|
|
1146
|
+
requestSchemas?: DataRequestSchemas;
|
|
1147
|
+
}
|
|
1148
|
+
interface ExtendedModelRouterOptions<TModel = unknown> extends ModelRouterOptions<TModel>, ExtendedDefaultModelRouterOptions<TModel> {
|
|
1149
|
+
'alwaysSelectFields.default'?: string[];
|
|
1150
|
+
'alwaysSelectFields.list'?: string[];
|
|
1151
|
+
'alwaysSelectFields.create'?: string[];
|
|
1152
|
+
'alwaysSelectFields.read'?: string[];
|
|
1153
|
+
'alwaysSelectFields.update'?: string[];
|
|
1154
|
+
'docPermissions.default'?: ModelDocPermissionsHook;
|
|
1155
|
+
'docPermissions.list'?: ModelDocPermissionsHook;
|
|
1156
|
+
'docPermissions.create'?: ModelDocPermissionsHook;
|
|
1157
|
+
'docPermissions.read'?: ModelDocPermissionsHook;
|
|
1158
|
+
'docPermissions.update'?: ModelDocPermissionsHook;
|
|
1159
|
+
'baseFilter.default'?: ModelBaseFilterHook;
|
|
1160
|
+
'baseFilter.list'?: ModelBaseFilterHook;
|
|
1161
|
+
'baseFilter.read'?: ModelBaseFilterHook;
|
|
1162
|
+
'baseFilter.update'?: ModelBaseFilterHook;
|
|
1163
|
+
'baseFilter.delete'?: ModelBaseFilterHook;
|
|
1164
|
+
'overrideFilter.default'?: ModelOverrideFilterHook;
|
|
1165
|
+
'overrideFilter.list'?: ModelOverrideFilterHook;
|
|
1166
|
+
'overrideFilter.read'?: ModelOverrideFilterHook;
|
|
1167
|
+
'overrideFilter.update'?: ModelOverrideFilterHook;
|
|
1168
|
+
'overrideFilter.delete'?: ModelOverrideFilterHook;
|
|
1169
|
+
'decorate.default'?: ModelHook;
|
|
1170
|
+
'decorate.list'?: ModelHook;
|
|
1171
|
+
'decorate.create'?: ModelHook;
|
|
1172
|
+
'decorate.read'?: ModelHook;
|
|
1173
|
+
'decorate.update'?: ModelHook;
|
|
1174
|
+
'decorateAll.default'?: ModelListHook;
|
|
1175
|
+
'decorateAll.list'?: ModelListHook;
|
|
1176
|
+
'validate.default'?: ValidateRule | ModelValidateHook;
|
|
1177
|
+
'validate.create'?: ValidateRule | ModelValidateHook;
|
|
1178
|
+
'validate.update'?: ValidateRule | ModelValidateHook;
|
|
1179
|
+
'prepare.default'?: ModelHook;
|
|
1180
|
+
'prepare.create'?: ModelHook;
|
|
1181
|
+
'prepare.update'?: ModelHook;
|
|
1182
|
+
'transform.default'?: ModelDocumentHook;
|
|
1183
|
+
'transform.update'?: ModelDocumentHook;
|
|
1184
|
+
'afterPersist.default'?: ModelDocumentHook;
|
|
1185
|
+
'afterPersist.create'?: ModelDocumentHook;
|
|
1186
|
+
'afterPersist.update'?: ModelDocumentHook;
|
|
1187
|
+
onChange?: Record<string, ModelChangeHook>;
|
|
1188
|
+
'requestSchemas.create'?: RequestSchema;
|
|
1189
|
+
'requestSchemas.update'?: RequestSchema;
|
|
1190
|
+
'requestSchemas.upsert'?: RequestSchema;
|
|
1191
|
+
'requestSchemas.count'?: RequestSchema;
|
|
1192
|
+
'requestSchemas.distinct'?: RequestSchema;
|
|
1193
|
+
'requestSchemas.advancedList'?: RequestSchema;
|
|
1194
|
+
'requestSchemas.advancedReadFilter'?: RequestSchema;
|
|
1195
|
+
'requestSchemas.advancedRead'?: RequestSchema;
|
|
1196
|
+
'requestSchemas.advancedCreate.default'?: RequestSchema;
|
|
1197
|
+
'requestSchemas.advancedCreate.data'?: RequestSchema;
|
|
1198
|
+
'requestSchemas.advancedUpdate'?: RequestSchema;
|
|
1199
|
+
'requestSchemas.advancedUpdate.default'?: RequestSchema;
|
|
1200
|
+
'requestSchemas.advancedUpdate.data'?: RequestSchema;
|
|
1201
|
+
'requestSchemas.advancedUpsert.default'?: RequestSchema;
|
|
1202
|
+
'requestSchemas.advancedUpsert.data'?: RequestSchema;
|
|
1203
|
+
'requestSchemas.subList'?: RequestSchema;
|
|
1204
|
+
'requestSchemas.subRead'?: RequestSchema;
|
|
1205
|
+
'requestSchemas.subCreate'?: RequestSchema;
|
|
1206
|
+
'requestSchemas.subUpdate'?: RequestSchema;
|
|
1207
|
+
'requestSchemas.subBulkUpdate'?: RequestSchema;
|
|
1208
|
+
'defaults.findOneArgs'?: DefaultFindOneArgs<TModel>;
|
|
1209
|
+
'defaults.findOneOptions'?: FindOneOptions;
|
|
1210
|
+
'defaults.findByIdArgs'?: DefaultFindByIdArgs<TModel>;
|
|
1211
|
+
'defaults.findByIdOptions'?: FindByIdOptions;
|
|
1212
|
+
'defaults.findArgs'?: DefaultFindArgs<TModel>;
|
|
1213
|
+
'defaults.findOptions'?: FindOptions;
|
|
1214
|
+
'defaults.createArgs'?: CreateArgs;
|
|
1215
|
+
'defaults.createOptions'?: CreateOptions;
|
|
1216
|
+
'defaults.updateOneArgs'?: UpdateOneArgs<TModel>;
|
|
1217
|
+
'defaults.updateOneOptions'?: UpdateOneOptions;
|
|
1218
|
+
'defaults.updateByIdArgs'?: UpdateByIdArgs<TModel>;
|
|
1219
|
+
'defaults.updateByIdOptions'?: UpdateByIdOptions;
|
|
1220
|
+
'defaults.upsertArgs'?: UpsertArgs<TModel>;
|
|
1221
|
+
'defaults.existsOptions'?: ExistsOptions;
|
|
1222
|
+
'defaults.publicListArgs'?: PublicListArgs;
|
|
1223
|
+
'defaults.publicListOptions'?: PublicListOptions;
|
|
1224
|
+
'defaults.publicCreateArgs'?: PublicCreateArgs;
|
|
1225
|
+
'defaults.publicCreateOptions'?: PublicCreateOptions;
|
|
1226
|
+
'defaults.publicReadArgs'?: PublicReadArgs;
|
|
1227
|
+
'defaults.publicReadOptions'?: PublicReadOptions;
|
|
1228
|
+
'defaults.publicUpdateArgs'?: PublicUpdateArgs;
|
|
1229
|
+
'defaults.publicUpdateOptions'?: PublicUpdateOptions;
|
|
1230
|
+
}
|
|
1231
|
+
interface ExtendedDataRouterOptions<TData = unknown> extends DataRouterOptions<TData> {
|
|
1232
|
+
'requestSchemas.advancedList'?: RequestSchema;
|
|
1233
|
+
'requestSchemas.advancedReadFilter'?: RequestSchema;
|
|
1234
|
+
'requestSchemas.advancedRead'?: RequestSchema;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
interface DistinctArgs<T = unknown> {
|
|
1238
|
+
filter?: Filter<T>;
|
|
118
1239
|
}
|
|
119
1240
|
|
|
120
1241
|
declare function macl(): (req: AccessRouterBaseRequest, res: Response, next: NextFunction) => Promise<void>;
|
|
121
1242
|
interface GuardModelConditionID {
|
|
122
|
-
type:
|
|
1243
|
+
type: 'param' | 'query';
|
|
123
1244
|
key: string;
|
|
124
1245
|
}
|
|
125
1246
|
interface GuardModelCondition {
|
|
@@ -127,10 +1248,10 @@ interface GuardModelCondition {
|
|
|
127
1248
|
id: string | GuardModelConditionID;
|
|
128
1249
|
condition: string | string[];
|
|
129
1250
|
}
|
|
130
|
-
declare function guard(condition: string):
|
|
131
|
-
declare function guard(conditions: string[]):
|
|
132
|
-
declare function guard(conditionFunc: GuardHook<ModelRequest>):
|
|
133
|
-
declare function guard(modelCondition: GuardModelCondition):
|
|
1251
|
+
declare function guard(condition: string): RequestHandler;
|
|
1252
|
+
declare function guard(conditions: string[]): RequestHandler;
|
|
1253
|
+
declare function guard(conditionFunc: GuardHook<ModelRequest>): RequestHandler;
|
|
1254
|
+
declare function guard(modelCondition: GuardModelCondition): RequestHandler;
|
|
134
1255
|
|
|
135
1256
|
type SetTargetOption$1<TRouter, TOption> = {
|
|
136
1257
|
(option: TOption): TRouter;
|
|
@@ -334,8 +1455,6 @@ declare class RootRouter {
|
|
|
334
1455
|
get routes(): Router;
|
|
335
1456
|
}
|
|
336
1457
|
|
|
337
|
-
declare function createOpenApiRouter(runtime: AccessRuntime, options?: OpenApiRouterOptions): Router;
|
|
338
|
-
|
|
339
1458
|
type AccessRouterInstance = ModelRouter<any> | DataRouter<any> | RootRouter;
|
|
340
1459
|
type CombinedRouteInput = Router | AccessRouterInstance;
|
|
341
1460
|
declare function combineRoutes(...inputs: CombinedRouteInput[]): Router;
|
|
@@ -357,6 +1476,30 @@ declare const setDefaultModelOption: <K extends keyof ExtendedDefaultModelRouter
|
|
|
357
1476
|
declare const getDefaultModelOptions: () => DefaultModelRouterOptions<unknown>;
|
|
358
1477
|
declare const getDefaultModelOption: <K extends keyof ExtendedDefaultModelRouterOptions>(key: K, defaultValue?: ExtendedDefaultModelRouterOptions[K]) => ExtendedDefaultModelRouterOptions<unknown>[K];
|
|
359
1478
|
|
|
1479
|
+
/**
|
|
1480
|
+
* Wraps a request validator into a request schema adapter used by `access-router`.
|
|
1481
|
+
*
|
|
1482
|
+
* @example
|
|
1483
|
+
* const schema = defineRequestSchema(fromZod(z.object({ name: z.string() })));
|
|
1484
|
+
*/
|
|
1485
|
+
declare function defineRequestSchema<T = unknown>(validator: RequestSchemaValidator<T>, options?: RequestSchemaOptions): RequestSchemaAdapter<T>;
|
|
1486
|
+
/**
|
|
1487
|
+
* Adapts a Zod schema into a `RequestSchemaValidator` for `access-router`.
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* const validator = fromZod(z.object({ name: z.string() }));
|
|
1491
|
+
*/
|
|
1492
|
+
declare function fromZod<TSchema extends z.ZodTypeAny>(schema: TSchema): RequestSchemaValidator<z.output<TSchema>>;
|
|
1493
|
+
declare function fromStandardSchema<TSchema extends StandardSchemaV1>(schema: TSchema): RequestSchemaValidator<StandardSchemaInferOutput<TSchema>>;
|
|
1494
|
+
declare function fromYup<TSchema extends YupSchemaLike>(schema: TSchema): RequestSchemaValidator;
|
|
1495
|
+
declare function fromJoi<TSchema extends JoiSchemaLike>(schema: TSchema): RequestSchemaValidator;
|
|
1496
|
+
declare function fromAjv<TValue = unknown>(validator: AjvValidatorLike<TValue>): RequestSchemaValidator<TValue>;
|
|
1497
|
+
declare function fromValibot<TSchema, TOutput = unknown>(schema: TSchema, safeParse: ValibotSafeParseLike): RequestSchemaValidator<TOutput>;
|
|
1498
|
+
declare function fromArkType<TValue = unknown>(type: ArkTypeLike<TValue>): RequestSchemaValidator<TValue>;
|
|
1499
|
+
declare function fromIoTs<TValue = unknown>(decoder: IoTsDecoderLike<TValue>): RequestSchemaValidator<TValue>;
|
|
1500
|
+
declare function fromSuperstruct<TStruct, TOutput = unknown>(struct: TStruct, validate: SuperstructValidateLike): RequestSchemaValidator<TOutput>;
|
|
1501
|
+
declare function fromVine<TValue = unknown>(validator: VineValidatorLike<TValue>): RequestSchemaValidator<TValue>;
|
|
1502
|
+
|
|
360
1503
|
interface Options {
|
|
361
1504
|
virtualPermissionField?: string;
|
|
362
1505
|
modelName: string;
|
|
@@ -407,4 +1550,4 @@ type AccessRuntimeApi = typeof macl & Wtt;
|
|
|
407
1550
|
declare function createAccessRuntime(): AccessRuntimeApi;
|
|
408
1551
|
declare const acl: AccessRuntimeApi;
|
|
409
1552
|
|
|
410
|
-
export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, GlobalOptions, ModelRouter, ModelRouterOptions, type OpenApiDocumentOptions, type OpenApiMethod, type OpenApiRouteDescriptor, type OpenApiRouterOptions, RootRouter, RootRouterOptions, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, permissionsPlugin, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
|
|
1553
|
+
export { type AccessRouterPermissionMap, type AccessRouterPermissions, type AccessRouterRequest, type AccessRouterRequestExtensions, AccessRuntime, type AccessRuntimeApi, type AjvErrorObjectLike, type AjvValidatorLike, type ArkTypeErrorsLike, type ArkTypeLike, type CombinedRouteInput, DataRouter, type DataRouterOptions, type GlobalOptions, type IoTsContextEntryLike, type IoTsDecodeErrorLike, type IoTsDecoderLike, type JoiSchemaLike, type JoiValidationErrorDetailLike, ModelRouter, type ModelRouterOptions, type OpenApiDocumentOptions, type OpenApiMethod, type OpenApiRouteDescriptor, type OpenApiRouterOptions, type Permissions, type RequestSchemaAdapter, type RequestSchemaFailure, type RequestSchemaIssue, type RequestSchemaLike, type RequestSchemaOptions, type RequestSchemaResult, type RequestSchemaSuccess, type RequestSchemaValidator, RootRouter, type RootRouterOptions, type StandardSchemaFailure, type StandardSchemaInferOutput, type StandardSchemaIssue, type StandardSchemaPathSegment, type StandardSchemaResult, type StandardSchemaSuccess, type StandardSchemaV1, type SuperstructFailureLike, type SuperstructValidateLike, type ValibotIssueLike, type ValibotPathItemLike, type ValibotSafeParseLike, type ValibotSafeParseResult, type VineValidationErrorLike, type VineValidationMessageLike, type VineValidatorLike, type YupSchemaLike, type YupValidationErrorLike, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, defineRequestSchema, fromAjv, fromArkType, fromIoTs, fromJoi, fromStandardSchema, fromSuperstruct, fromValibot, fromVine, fromYup, fromZod, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, permissionsPlugin, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
|