@web-ts-toolkit/access-router 0.2.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/index.d.ts ADDED
@@ -0,0 +1,1589 @@
1
+ import express, { Response, NextFunction, Router } from 'express';
2
+ import mongoose, { Document } from 'mongoose';
3
+ import { Diff } from 'deep-diff';
4
+ import { z } from 'zod';
5
+ import JsonRouter from '@web-ts-toolkit/express-json-router';
6
+
7
+ interface BooleanObject {
8
+ [key: string]: boolean;
9
+ }
10
+ declare class Permission {
11
+ $_permissions: BooleanObject;
12
+ $_permissionKeys: string[];
13
+ constructor(permissions: BooleanObject);
14
+ prop(permission: string): boolean;
15
+ has(permission: string): boolean;
16
+ hasAny(permissions: string[]): boolean;
17
+ hasAll(permissions: string[]): boolean;
18
+ any(permissions: string[]): boolean;
19
+ all(permissions: string[]): boolean;
20
+ }
21
+
22
+ interface Permissions extends Permission {
23
+ [key: string]: any;
24
+ }
25
+
26
+ declare class Base {
27
+ req: Request;
28
+ modelName: string;
29
+ constructor(req: Request, modelName: string);
30
+ decorate<T>(doc: T, access: DecorateAccess, context: MiddlewareContext): Promise<T>;
31
+ decorateAll<T>(docs: T[], access: DecorateAllAccess, context: MiddlewareContext): Promise<T[]>;
32
+ genAllowedFields(doc: unknown, access: SelectAccess, baseFields?: string[]): Promise<string[]>;
33
+ genDocPermissions(doc: unknown, access: DocPermissionsAccess, context: MiddlewareContext): Promise<Record<string, unknown>>;
34
+ genFilter(access?: BaseFilterAccess, filter?: any): Promise<Filter>;
35
+ getIdentifier(): string | null;
36
+ genIDFilter(id: string): Promise<Filter>;
37
+ genPopulate(access?: SelectAccess, populate?: Populate | Populate[] | string | null): Promise<Populate[]>;
38
+ genSelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
39
+ genQuerySelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
40
+ addEmptyPermissions<T>(doc: T): T;
41
+ addDocPermissions<T>(doc: T, access: DocPermissionsAccess, context: MiddlewareContext): Promise<T>;
42
+ addFieldPermissions<T extends {
43
+ _id?: unknown;
44
+ }>(doc: T, access: DocPermissionsAccess, context: MiddlewareContext): Promise<T>;
45
+ pickAllowedFields<T>(doc: T, access: SelectAccess, baseFields?: string[]): Promise<T>;
46
+ trimOutputFields<T>(doc: T, access: SelectAccess, baseFields?: string[]): Promise<T>;
47
+ prepare<T>(allowedData: T, access: PrepareAccess, context: MiddlewareContext): Promise<T>;
48
+ runTasks<T extends object>(docObject: T, tasks: Task | Task[]): T;
49
+ transform<T>(doc: T, access: TransformAccess, context: MiddlewareContext): Promise<T>;
50
+ finalize<T>(doc: T, access: FinalizeAccess, context: MiddlewareContext): Promise<T>;
51
+ changes(doc: Record<string, unknown>, context: MiddlewareContext): Promise<void>;
52
+ validate(allowedData: unknown, access: ValidateAccess, context: MiddlewareContext): Promise<boolean | unknown[]>;
53
+ checkIfModelPermissionExists(accesses: DocPermissionsAccess[]): boolean;
54
+ protected validateClientFilter(filter: Filter | null | undefined): string[];
55
+ protected processInclude(include: Include | Include[]): {
56
+ includes: Include[];
57
+ includeLocalFields: any[];
58
+ includePaths: any[];
59
+ };
60
+ protected includeDocs(docs: any, include: Include | Include[]): Promise<any>;
61
+ private includeDocsList;
62
+ private includeDocsCount;
63
+ protected parseClientData(filter: any): Promise<unknown>;
64
+ private handleSubQuery;
65
+ private handleDate;
66
+ }
67
+
68
+ interface FindProps {
69
+ filter: Filter;
70
+ select?: Projection;
71
+ sort?: Sort;
72
+ populate?: Populate[] | string;
73
+ limit?: string | number;
74
+ skip?: string | number;
75
+ lean?: boolean;
76
+ }
77
+ interface FindOneProps {
78
+ filter: Filter;
79
+ select?: Projection;
80
+ sort?: Sort;
81
+ populate?: Populate[] | string;
82
+ lean?: boolean;
83
+ }
84
+ type SortValue = 1 | -1 | 'asc' | 'ascending' | 'desc' | 'descending';
85
+ type SortType = string | [string, SortValue][] | {
86
+ [key: string]: SortValue;
87
+ } | Map<string, SortValue> | null | undefined;
88
+ declare class Model {
89
+ modelName: string;
90
+ model: mongoose.Model<any>;
91
+ constructor(modelName: string);
92
+ new(): any;
93
+ create(data: any): Promise<any>;
94
+ find({ filter, select, sort, populate, limit, skip, lean }: FindProps): mongoose.Query<any[], any, {}, any, "find", {}>;
95
+ validateSort(sort: SortType, logError?: (msg: string, ...args: unknown[]) => void): boolean;
96
+ findOne({ filter, select, sort, populate, lean }: FindOneProps): mongoose.Query<any, any, {}, any, "findOne", {}>;
97
+ findOneAndDelete(filter: any): mongoose.Query<any, any, {}, any, "findOneAndDelete", {}>;
98
+ exists(filter: any): mongoose.Query<any, any, {}, any, "findOne", {}>;
99
+ countDocuments(filter?: {}): mongoose.Query<number, any, {}, any, "countDocuments", {}>;
100
+ estimatedDocumentCount(): mongoose.Query<number, any, {}, any, "estimatedDocumentCount", {}>;
101
+ distinct(field: string, conditions?: {}): mongoose.Query<any[], any, {}, any, "distinct", {}>;
102
+ }
103
+
104
+ declare class Service extends Base {
105
+ model: Model;
106
+ options: ModelRouterOptions;
107
+ defaults: Defaults;
108
+ baseFields: string[];
109
+ baseFieldsExt: string[];
110
+ constructor(req: Request, modelName: string);
111
+ findOne(filter: Filter, args?: FindOneArgs, options?: FindOneOptions): Promise<SingleResult | ErrorResult>;
112
+ findById(id: string, args?: FindByIdArgs, options?: FindByIdOptions): Promise<SingleResult | ErrorResult>;
113
+ find(filter: Filter, args?: FindArgs, options?: FindOptions, decorate?: Function): Promise<ListResult | ErrorResult>;
114
+ create(data: any, args?: CreateArgs, options?: CreateOptions, decorate?: Function): Promise<ListResult | ErrorResult>;
115
+ new(): Promise<SingleResult>;
116
+ updateOne(filter: Filter, data: any, args?: UpdateOneArgs, options?: UpdateOneOptions, decorate?: Function): Promise<SingleResult | ErrorResult>;
117
+ updateById(id: string, data: any, { populate, overrides }?: UpdateByIdArgs, { skim, includePermissions, populateAccess, }?: UpdateByIdOptions, decorate?: Function): Promise<SingleResult | ErrorResult>;
118
+ upsert(filter: Filter, data: any, args?: UpsertArgs, options?: UpsertOptions, decorate?: Function): Promise<ServiceResult>;
119
+ delete(id: string): Promise<SingleResult | ErrorResult>;
120
+ exists(filter: Filter, options: ExistsOptions & {
121
+ includeId: true;
122
+ }): Promise<SingleResult | ErrorResult>;
123
+ exists(filter: Filter, options?: ExistsOptions): Promise<SingleResult<boolean> | ErrorResult>;
124
+ distinct(field: string, args?: DistinctArgs): Promise<ListResult | ErrorResult>;
125
+ count(filter: any, access?: BaseFilterAccess): Promise<SingleResult<number> | ErrorResult>;
126
+ getDocPermissions(doc: any): unknown;
127
+ private getFieldPermissionAccess;
128
+ private getAccessibleIdSet;
129
+ listSub(id: any, sub: any, options?: {
130
+ filter: Filter;
131
+ fields: string[];
132
+ }): Promise<ListResult | ErrorResult>;
133
+ readSub(id: any, sub: any, subId: any, options?: {
134
+ fields: string[];
135
+ populate: SubPopulate | SubPopulate[];
136
+ }): Promise<SingleResult | ErrorResult>;
137
+ updateSub(id: any, sub: any, subId: any, data: any): Promise<SingleResult | ErrorResult>;
138
+ bulkUpdateSub(id: any, sub: any, data: any): Promise<ListResult | ErrorResult>;
139
+ createSub(id: any, sub: any, data: any, options?: {
140
+ addFirst: boolean;
141
+ }): Promise<ListResult | ErrorResult>;
142
+ deleteSub(id: any, sub: any, subId: any): Promise<SingleResult | ErrorResult>;
143
+ getParentDoc(id: any, sub: any, args?: {
144
+ populate?: SubPopulate | SubPopulate[];
145
+ }, options?: {
146
+ access?: BaseFilterAccess;
147
+ lean?: boolean;
148
+ }): Promise<any>;
149
+ }
150
+
151
+ declare class PublicService extends Service {
152
+ _list(filter: Filter, args?: PublicListArgs, options?: PublicListOptions): Promise<ListResult | ErrorResult>;
153
+ _create(data: any, args?: PublicCreateArgs, options?: PublicCreateOptions): Promise<ListResult | ErrorResult>;
154
+ _new(): Promise<SingleResult>;
155
+ _read(id: string, args?: PublicReadArgs, options?: PublicReadOptions): Promise<SingleResult | ErrorResult>;
156
+ _readFilter(filter: Filter, args?: PublicReadArgs & {
157
+ sort?: Sort;
158
+ }, options?: PublicReadOptions): Promise<SingleResult | ErrorResult>;
159
+ _update(id: string, data: any, args?: PublicUpdateArgs, options?: PublicUpdateOptions): Promise<SingleResult | ErrorResult>;
160
+ _delete(id: string): Promise<SingleResult | ErrorResult>;
161
+ _distinct(field: string, options?: DistinctArgs): Promise<ListResult | ErrorResult>;
162
+ _count(filter: any, access?: BaseFilterAccess): Promise<SingleResult<number> | ErrorResult>;
163
+ }
164
+
165
+ declare class DataService<T> {
166
+ req: Request;
167
+ dataName: string;
168
+ options: DataRouterOptions;
169
+ data: T[];
170
+ constructor(req: Request, dataName: string);
171
+ findOne(filter: DataFilter, args?: DataFindOneArgs, options?: DataFindOneOptions): Promise<SingleResult<T> | ErrorResult>;
172
+ findById(id: string, args?: DataFindOneArgs, options?: DataFindOneOptions): Promise<SingleResult<T> | ErrorResult>;
173
+ find(filter: DataFilter, args?: DataFindArgs, options?: DataFindOptions): Promise<ListResult<T> | ErrorResult>;
174
+ decorate<TDoc>(doc: TDoc, access: DecorateAccess, context?: DataMiddlewareContext): Promise<TDoc>;
175
+ decorateAll<TDoc>(docs: TDoc[], access: DecorateAllAccess): Promise<TDoc[]>;
176
+ genAllowedFields(doc: unknown, access: SelectAccess, baseFields?: string[]): Promise<string[]>;
177
+ genFilter(access?: BaseFilterAccess, filter?: any): Promise<Filter>;
178
+ genIDFilter(id: string): Promise<Filter>;
179
+ genSelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
180
+ genQuerySelect(access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: string[]): Promise<string[]>;
181
+ pickAllowedFields<TDoc>(doc: TDoc, access: SelectAccess, baseFields?: string[]): Promise<TDoc>;
182
+ trimOutputFields<TDoc>(doc: TDoc, access: SelectAccess, baseFields?: string[]): Promise<TDoc>;
183
+ }
184
+
185
+ declare class Core {
186
+ private req;
187
+ private caches;
188
+ constructor(req: Request);
189
+ getIdentifier(modelName: string): string;
190
+ genIDFilter(modelName: string, id: string): Promise<any>;
191
+ genFilter(modelName: string, access?: BaseFilterAccess, _filter?: Filter): Promise<Filter>;
192
+ private removePrefix;
193
+ genAllowedFields(modelName: string, doc: unknown, access: SelectAccess, baseFields?: any[]): Promise<string[]>;
194
+ pickAllowedFields<T>(modelName: string, doc: T, access: SelectAccess, baseFields?: any[]): Promise<T>;
195
+ genSelect(modelName: string, access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: any[]): Promise<string[]>;
196
+ genPopulate(modelName: string, access?: SelectAccess | BaseFilterAccess, _populate?: Populate | Populate[] | string | null): Promise<(string | Populate)[]>;
197
+ validate(modelName: string, allowedData: unknown, access: ValidateAccess, context: MiddlewareContext): Promise<boolean | unknown[]>;
198
+ prepare<T>(modelName: string, allowedData: T, access: PrepareAccess, context: MiddlewareContext): Promise<T>;
199
+ transform<T>(modelName: string, doc: T, access: TransformAccess, context: MiddlewareContext): Promise<T>;
200
+ finalize<T>(modelName: string, doc: T, access: FinalizeAccess, context: MiddlewareContext): Promise<T>;
201
+ changes(modelName: string, doc: Record<string, unknown>, context: MiddlewareContext): Promise<void>;
202
+ genDocPermissions(modelName: string, doc: unknown, access: DocPermissionsAccess, context: MiddlewareContext): Promise<{}>;
203
+ addEmptyPermissions<T>(modelName: string, doc: T): T;
204
+ addDocPermissions<T>(modelName: string, doc: T, access: DocPermissionsAccess, context: MiddlewareContext): Promise<T>;
205
+ addFieldPermissions<T extends {
206
+ _id?: unknown;
207
+ }>(modelName: string, doc: T, access: DocPermissionsAccess, context: MiddlewareContext): Promise<T>;
208
+ decorate<T>(modelName: string, doc: T, access: DecorateAccess, context: MiddlewareContext): Promise<T>;
209
+ decorateAll<T>(modelName: string, docs: T[], access: DecorateAllAccess, context: MiddlewareContext): Promise<T[]>;
210
+ runTasks<T extends object>(modelName: string, docObject: T, task: Task | Task[]): T;
211
+ getPermissions(): Permission;
212
+ setPermissions(): Promise<void>;
213
+ canActivate(routeGuard: Validation): Promise<any>;
214
+ isAllowed(modelName: string, access: RouteGuardAccess | string): Promise<any>;
215
+ getService(modelName: string): Service;
216
+ getPublicService(modelName: string): PublicService;
217
+ service(modelName: string): PublicService;
218
+ svc(modelName: string): PublicService;
219
+ private getGlobalPermissions;
220
+ }
221
+
222
+ declare class DataCore {
223
+ private req;
224
+ private caches;
225
+ constructor(req: Request);
226
+ genIDFilter(dataName: string, id: string): Promise<any>;
227
+ genFilter(dataName: string, access?: BaseFilterAccess, _filter?: Filter): Promise<Filter>;
228
+ genAllowedFields(dataName: string, _doc: unknown, access: SelectAccess, baseFields?: any[]): Promise<string[]>;
229
+ pickAllowedFields<TDoc>(dataName: string, doc: TDoc, access: SelectAccess, baseFields?: any[]): Promise<TDoc>;
230
+ genSelect(dataName: string, access: SelectAccess, targetFields?: Projection, skipChecks?: boolean, subPaths?: any[]): Promise<string[]>;
231
+ decorate<TDoc>(dataName: string, doc: TDoc, access: DecorateAccess, context?: DataMiddlewareContext): Promise<TDoc>;
232
+ decorateAll<TDoc>(dataName: string, docs: TDoc[], access: DecorateAllAccess): Promise<TDoc[]>;
233
+ getPermissions(): Permission;
234
+ setPermissions(): Promise<void>;
235
+ canActivate(routeGuard: Validation): Promise<any>;
236
+ isAllowed(dataName: string, access: RouteGuardAccess | string): Promise<any>;
237
+ getService(dataName: string): DataService<unknown>;
238
+ service(dataName: string): DataService<unknown>;
239
+ svc(dataName: string): DataService<unknown>;
240
+ private getGlobalPermissions;
241
+ }
242
+
243
+ declare enum StatusCodes {
244
+ OK = 200,
245
+ Created = 201,
246
+ BadRequest = 400,
247
+ Unauthorized = 401,
248
+ Forbidden = 403,
249
+ NotFound = 404,
250
+ UnprocessableContent = 422
251
+ }
252
+ declare enum Codes {
253
+ Success = "success",
254
+ Created = "created",
255
+ BadRequest = "bad_request",
256
+ Unauthorized = "unauthorized",
257
+ Forbidden = "forbidden",
258
+ NotFound = "not_found"
259
+ }
260
+ declare enum CustomHeaders {
261
+ TotalCount = "wtt-total-count",
262
+ ReturnedCount = "wtt-returned-count",
263
+ Page = "wtt-page",
264
+ PageSize = "wtt-page-size",
265
+ TotalPages = "wtt-total-pages",
266
+ HasNextPage = "wtt-has-next-page",
267
+ HasPreviousPage = "wtt-has-previous-page"
268
+ }
269
+ declare enum FilterOperator {
270
+ SubQuery = 0,
271
+ Date = 1
272
+ }
273
+
274
+ type Validation = boolean | string | string[] | Function;
275
+ interface KeyValueProjection {
276
+ [key: string]: 1 | -1;
277
+ }
278
+ type Projection = string[] | string | KeyValueProjection;
279
+ type SortOrder = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
280
+ type Sort = string | {
281
+ [key: string]: SortOrder;
282
+ } | [string, SortOrder][] | undefined | null;
283
+ type Filter = false | Record<string, unknown>;
284
+ interface Include {
285
+ model: string;
286
+ op: 'list' | 'read' | 'count';
287
+ path: string;
288
+ filter?: Filter;
289
+ localField: string;
290
+ foreignField: string;
291
+ args?: unknown;
292
+ options?: unknown;
293
+ }
294
+ type FindAccess = 'list' | 'read';
295
+ type PopulateAccess = 'list' | 'read';
296
+ interface Populate {
297
+ path: string;
298
+ select?: Projection;
299
+ match?: unknown;
300
+ access?: PopulateAccess;
301
+ }
302
+ interface SubPopulate {
303
+ path: string;
304
+ select?: Projection;
305
+ }
306
+ interface keyValue {
307
+ [key: string]: unknown;
308
+ }
309
+ interface MiddlewareContext {
310
+ modelName: string;
311
+ model: mongoose.Model<unknown>;
312
+ originalDocObject?: Record<string, unknown>;
313
+ finalDocObject?: Record<string, unknown>;
314
+ diff?(doc: Document): void;
315
+ currentDoc?: keyValue;
316
+ originalData?: Record<string, unknown>;
317
+ preparedData?: Record<string, unknown>;
318
+ modifiedPaths?: string[];
319
+ changes?: Diff<unknown>[];
320
+ docPermissions?: keyValue;
321
+ fieldPermissionAccess?: {
322
+ readIds?: Set<string>;
323
+ updateIds?: Set<string>;
324
+ };
325
+ }
326
+ interface DataMiddlewareContext {
327
+ }
328
+ interface RootQueryEntry {
329
+ model: string;
330
+ op: string;
331
+ id?: string;
332
+ field?: string;
333
+ filter?: Filter;
334
+ data?: unknown;
335
+ args?: unknown;
336
+ options?: unknown;
337
+ order?: number;
338
+ }
339
+ interface SubQueryEntry extends RootQueryEntry {
340
+ sqOptions?: {
341
+ path?: string;
342
+ compact?: boolean;
343
+ };
344
+ }
345
+ interface Task {
346
+ type: string;
347
+ args: unknown;
348
+ options: Record<string, unknown>;
349
+ }
350
+ interface Request extends express.Request {
351
+ query: Record<'skip' | 'limit' | 'page' | 'page_size' | 'try_list' | 'skim' | 'include_permissions' | 'include_count' | 'include_extra_headers' | 'returning_all', string>;
352
+ macl: Core;
353
+ dacl: DataCore;
354
+ }
355
+ interface ErrorResult<TError = unknown, TQuery = unknown> {
356
+ success: false;
357
+ code: Codes.BadRequest | Codes.Unauthorized | Codes.Forbidden | Codes.NotFound;
358
+ errors?: TError[];
359
+ query?: TQuery;
360
+ }
361
+ interface SingleResult<T = unknown, TInput = unknown, TQuery = unknown> {
362
+ success: true;
363
+ kind: 'single';
364
+ code: Codes.Success | Codes.Created;
365
+ data: T;
366
+ input?: TInput;
367
+ query?: TQuery;
368
+ context?: MiddlewareContext;
369
+ }
370
+ interface ListResult<T = unknown, TInput = unknown, TQuery = unknown> {
371
+ success: true;
372
+ kind: 'list';
373
+ code: Codes.Success | Codes.Created;
374
+ data: T[];
375
+ count: number;
376
+ totalCount?: number | null;
377
+ input?: TInput;
378
+ query?: TQuery;
379
+ contexts?: MiddlewareContext[];
380
+ }
381
+ type ServiceResult<T = unknown, TError = unknown, TInput = unknown, TQuery = unknown> = SingleResult<T, TInput, TQuery> | ListResult<T, TInput, TQuery> | ErrorResult<TError, TQuery>;
382
+
383
+ interface PublicCreateArgs {
384
+ select?: Projection;
385
+ populate?: Populate[] | string;
386
+ tasks?: Task | Task[];
387
+ }
388
+ interface CreateArgs extends Omit<PublicCreateArgs, 'select' | 'tasks'> {
389
+ }
390
+ interface PublicCreateOptions {
391
+ skim?: boolean;
392
+ includePermissions?: boolean;
393
+ populateAccess?: PopulateAccess;
394
+ }
395
+ interface CreateOptions extends PublicCreateOptions {
396
+ }
397
+
398
+ interface PublicUpdateArgs {
399
+ select?: Projection;
400
+ populate?: Populate[] | string;
401
+ tasks?: Task | Task[];
402
+ }
403
+ interface UpdateOneArgs extends Omit<PublicUpdateArgs, 'select' | 'tasks'> {
404
+ overrides?: {
405
+ filter?: Filter;
406
+ populate?: Populate[] | string;
407
+ };
408
+ }
409
+ interface UpdateByIdArgs extends Omit<UpdateOneArgs, 'overrides'> {
410
+ overrides?: {
411
+ populate?: Populate[] | string;
412
+ idFilter?: Filter;
413
+ };
414
+ }
415
+ interface UpsertArgs extends UpdateOneArgs {
416
+ }
417
+ interface PublicUpdateOptions {
418
+ skim?: boolean;
419
+ returningAll?: boolean;
420
+ includePermissions?: boolean;
421
+ populateAccess?: PopulateAccess;
422
+ }
423
+ interface UpdateOneOptions extends Omit<PublicUpdateOptions, 'returningAll'> {
424
+ }
425
+ interface UpdateByIdOptions extends UpdateOneOptions {
426
+ }
427
+ interface UpsertOptions extends UpdateOneOptions {
428
+ }
429
+
430
+ interface PublicListArgs {
431
+ select?: Projection;
432
+ populate?: Populate[] | string;
433
+ include?: Include | Include[];
434
+ sort?: Sort;
435
+ skip?: string | number;
436
+ limit?: string | number;
437
+ page?: string | number;
438
+ pageSize?: string | number;
439
+ tasks?: Task | Task[];
440
+ }
441
+ interface PublicListOptions {
442
+ skim?: boolean;
443
+ includePermissions?: boolean;
444
+ includeCount?: boolean;
445
+ populateAccess?: PopulateAccess;
446
+ lean?: boolean;
447
+ }
448
+
449
+ interface PublicReadArgs {
450
+ select?: Projection;
451
+ populate?: Populate[] | string;
452
+ include?: Include | Include[];
453
+ tasks?: Task | Task[];
454
+ }
455
+ interface PublicReadOptions {
456
+ skim?: boolean;
457
+ populateAccess?: PopulateAccess;
458
+ lean?: boolean;
459
+ includePermissions?: boolean;
460
+ tryList?: boolean;
461
+ }
462
+
463
+ interface FindArgs {
464
+ select?: Projection;
465
+ populate?: Populate[] | string;
466
+ include?: Include | Include[];
467
+ sort?: Sort;
468
+ skip?: string | number;
469
+ limit?: string | number;
470
+ page?: string | number;
471
+ pageSize?: string | number;
472
+ overrides?: {
473
+ filter?: Filter;
474
+ select?: Projection;
475
+ populate?: Populate[] | string;
476
+ };
477
+ }
478
+ interface FindOptions {
479
+ skim?: boolean;
480
+ includePermissions?: boolean;
481
+ includeCount?: boolean;
482
+ populateAccess?: PopulateAccess;
483
+ lean?: boolean;
484
+ }
485
+ interface FindOneArgs {
486
+ select?: Projection;
487
+ sort?: Sort;
488
+ populate?: Populate[] | string;
489
+ include?: Include | Include[];
490
+ overrides?: {
491
+ filter?: Filter;
492
+ select?: Projection;
493
+ populate?: Populate[] | string;
494
+ };
495
+ }
496
+ interface FindOneOptions {
497
+ access?: FindAccess;
498
+ populateAccess?: PopulateAccess;
499
+ skim?: boolean;
500
+ lean?: boolean;
501
+ includePermissions?: boolean;
502
+ }
503
+ interface FindByIdArgs {
504
+ select?: Projection;
505
+ populate?: Populate[] | string;
506
+ include?: Include | Include[];
507
+ overrides?: {
508
+ select?: Projection;
509
+ populate?: Populate[] | string;
510
+ idFilter?: Filter;
511
+ };
512
+ }
513
+ interface FindByIdOptions extends FindOneOptions {
514
+ }
515
+
516
+ interface ExistsOptions {
517
+ access?: BaseFilterAccess;
518
+ includeId?: boolean;
519
+ }
520
+
521
+ interface DefaultFindOneArgs extends Omit<FindOneArgs, 'overrides'> {
522
+ }
523
+ interface DefaultFindByIdArgs extends Omit<FindByIdArgs, 'overrides'> {
524
+ }
525
+ interface DefaultFindArgs extends Omit<FindArgs, 'overrides'> {
526
+ }
527
+ type MaybePromise<T> = T | Promise<T>;
528
+ type RequestZodSchema = z.ZodTypeAny;
529
+ type GlobalPermissionValue = Record<string, boolean> | string[] | string | null | undefined;
530
+ type BaseFilterHook = (this: express.Request, permissions: Permissions) => MaybePromise<Filter | true | null | undefined>;
531
+ type OverrideFilterHook = (this: express.Request, filter: Filter, permissions: Permissions) => MaybePromise<Filter>;
532
+ type MiddlewareHook<TValue, TContext> = (this: express.Request, value: TValue, permissions: Permissions, context: TContext) => MaybePromise<TValue>;
533
+ type MiddlewareChain<TValue, TContext> = MiddlewareHook<TValue, TContext> | Array<MiddlewareHook<TValue, TContext>>;
534
+ type ValidateRule = boolean | unknown[];
535
+ type ValidateHook = (this: express.Request, allowedData: unknown, permissions: Permissions, context: MiddlewareContext) => MaybePromise<ValidateRule>;
536
+ type DocPermissionsHook = (this: express.Request, doc: unknown, permissions: Permissions, context: MiddlewareContext) => MaybePromise<Record<string, unknown>>;
537
+ type ChangeHook = (this: express.Request, previousValue: unknown, nextValue: unknown, changes: Diff<unknown>[], context: MiddlewareContext) => MaybePromise<void>;
538
+ type ModelMiddleware = MiddlewareChain<unknown, MiddlewareContext>;
539
+ type ModelListMiddleware = MiddlewareChain<unknown[], MiddlewareContext>;
540
+ type DataMiddleware = MiddlewareChain<unknown, DataMiddlewareContext>;
541
+ type DataListMiddleware = MiddlewareChain<unknown[], DataMiddlewareContext>;
542
+ type SubRouteGuardOptions = Record<string, Validation | Record<string, Validation>>;
543
+ interface RequestSchemas {
544
+ create?: RequestZodSchema;
545
+ update?: RequestZodSchema;
546
+ upsert?: RequestZodSchema;
547
+ count?: RequestZodSchema;
548
+ distinct?: RequestZodSchema;
549
+ advancedList?: RequestZodSchema;
550
+ advancedReadFilter?: RequestZodSchema;
551
+ advancedRead?: RequestZodSchema;
552
+ advancedCreate?: RequestZodSchema;
553
+ advancedCreateData?: RequestZodSchema;
554
+ advancedUpdate?: RequestZodSchema;
555
+ advancedUpdateData?: RequestZodSchema;
556
+ advancedUpsert?: RequestZodSchema;
557
+ advancedUpsertData?: RequestZodSchema;
558
+ subList?: RequestZodSchema;
559
+ subRead?: RequestZodSchema;
560
+ subCreate?: RequestZodSchema;
561
+ subUpdate?: RequestZodSchema;
562
+ subBulkUpdate?: RequestZodSchema;
563
+ }
564
+ interface DataRequestSchemas {
565
+ advancedList?: RequestZodSchema;
566
+ advancedReadFilter?: RequestZodSchema;
567
+ advancedRead?: RequestZodSchema;
568
+ }
569
+ interface Defaults {
570
+ findOneArgs?: DefaultFindOneArgs;
571
+ findOneOptions?: FindOneOptions;
572
+ findByIdArgs?: DefaultFindByIdArgs;
573
+ findByIdOptions?: FindByIdOptions;
574
+ findArgs?: DefaultFindArgs;
575
+ findOptions?: FindOptions;
576
+ createArgs?: CreateArgs;
577
+ createOptions?: CreateOptions;
578
+ updateOneArgs?: UpdateOneArgs;
579
+ updateOneOptions?: UpdateOneOptions;
580
+ upsertOptions?: UpsertOptions;
581
+ updateByIdArgs?: UpdateByIdArgs;
582
+ upsertArgs?: UpsertArgs;
583
+ updateByIdOptions?: UpdateByIdOptions;
584
+ existsOptions?: ExistsOptions;
585
+ publicListArgs?: PublicListArgs;
586
+ publicListOptions?: PublicListOptions;
587
+ publicCreateArgs?: PublicCreateArgs;
588
+ publicCreateOptions?: PublicCreateOptions;
589
+ publicReadArgs?: PublicReadArgs;
590
+ publicReadOptions?: PublicReadOptions;
591
+ publicUpdateArgs?: PublicUpdateArgs;
592
+ publicUpdateOptions?: PublicUpdateOptions;
593
+ }
594
+ interface AccessRouterLogger {
595
+ debug?: (...args: unknown[]) => unknown;
596
+ info?: (...args: unknown[]) => unknown;
597
+ warn?: (...args: unknown[]) => unknown;
598
+ error?: (...args: unknown[]) => unknown;
599
+ }
600
+ interface GlobalOptions {
601
+ requestPermissionField?: string;
602
+ globalPermissions?: (this: express.Request, req: express.Request) => MaybePromise<GlobalPermissionValue>;
603
+ logger?: AccessRouterLogger;
604
+ }
605
+ interface RootRouterOptions {
606
+ basePath: string;
607
+ routeGuard?: Validation;
608
+ }
609
+ interface Access {
610
+ list?: Validation;
611
+ create?: Validation;
612
+ read?: Validation;
613
+ update?: Validation;
614
+ delete?: Validation;
615
+ distinct?: Validation;
616
+ count?: Validation;
617
+ sub?: Validation | SubRouteGuardOptions;
618
+ }
619
+ interface PermissionSchema {
620
+ [key: string]: Access;
621
+ }
622
+ interface DocPermissions {
623
+ list?: Function;
624
+ create?: Function;
625
+ read?: Function;
626
+ update?: Function;
627
+ }
628
+ interface DefaultModelRouterOptions {
629
+ listHardLimit?: number;
630
+ documentPermissionField?: string;
631
+ idParam?: string;
632
+ identifier?: string | Function;
633
+ parentPath?: string;
634
+ queryPath?: string;
635
+ mutationPath?: string;
636
+ routeGuard?: Validation | Access;
637
+ modelPermissionPrefix?: string;
638
+ }
639
+ interface ExtendedDefaultModelRouterOptions extends DefaultModelRouterOptions {
640
+ 'routeGuard.default'?: Validation;
641
+ 'routeGuard.new'?: Validation;
642
+ 'routeGuard.list'?: Validation;
643
+ 'routeGuard.read'?: Validation;
644
+ 'routeGuard.update'?: Validation;
645
+ 'routeGuard.delete'?: Validation;
646
+ 'routeGuard.create'?: Validation;
647
+ 'routeGuard.distinct'?: Validation;
648
+ 'routeGuard.count'?: Validation;
649
+ 'routeGuard.subs'?: SubRouteGuardOptions;
650
+ }
651
+ interface ModelRouterOptions extends DefaultModelRouterOptions {
652
+ modelName?: string;
653
+ basePath?: string;
654
+ permissionSchema?: PermissionSchema;
655
+ _permissionSchemaKeys?: string[];
656
+ _globalPermissionKeys?: Record<string, string[]>;
657
+ _modelPermissionKeys?: Record<string, string[]>;
658
+ mandatoryFields?: string[];
659
+ docPermissions?: DocPermissions | DocPermissionsHook;
660
+ baseFilter?: BaseFilterHook | Record<string, BaseFilterHook>;
661
+ overrideFilter?: OverrideFilterHook | Record<string, OverrideFilterHook>;
662
+ decorate?: ModelMiddleware | Record<string, ModelMiddleware>;
663
+ decorateAll?: ModelListMiddleware | Record<string, ModelListMiddleware>;
664
+ validate?: ValidateRule | ValidateHook | Record<string, ValidateRule | ValidateHook>;
665
+ prepare?: ModelMiddleware | Record<string, ModelMiddleware>;
666
+ transform?: ModelMiddleware | Record<string, ModelMiddleware>;
667
+ finalize?: ModelMiddleware | Record<string, ModelMiddleware>;
668
+ change?: Record<string, ChangeHook>;
669
+ requestSchemas?: RequestSchemas;
670
+ defaults?: Defaults;
671
+ }
672
+ interface DataRouterOptions {
673
+ data?: unknown[];
674
+ listHardLimit?: number;
675
+ idParam?: string;
676
+ identifier?: string | Function;
677
+ parentPath?: string;
678
+ queryPath?: string;
679
+ routeGuard?: Validation | Access;
680
+ dataName?: string;
681
+ basePath?: string;
682
+ permissionSchema?: PermissionSchema;
683
+ baseFilter?: BaseFilterHook | Record<string, BaseFilterHook>;
684
+ overrideFilter?: OverrideFilterHook | Record<string, OverrideFilterHook>;
685
+ decorate?: DataMiddleware | Record<string, DataMiddleware>;
686
+ decorateAll?: DataListMiddleware | Record<string, DataListMiddleware>;
687
+ requestSchemas?: DataRequestSchemas;
688
+ }
689
+ interface ExtendedModelRouterOptions extends ModelRouterOptions, ExtendedDefaultModelRouterOptions {
690
+ 'mandatoryFields.default'?: string[];
691
+ 'mandatoryFields.list'?: string[];
692
+ 'mandatoryFields.create'?: string[];
693
+ 'mandatoryFields.read'?: string[];
694
+ 'mandatoryFields.update'?: string[];
695
+ 'docPermissions.default'?: DocPermissionsHook;
696
+ 'docPermissions.list'?: DocPermissionsHook;
697
+ 'docPermissions.create'?: DocPermissionsHook;
698
+ 'docPermissions.read'?: DocPermissionsHook;
699
+ 'docPermissions.update'?: DocPermissionsHook;
700
+ 'baseFilter.default'?: BaseFilterHook;
701
+ 'baseFilter.list'?: BaseFilterHook;
702
+ 'baseFilter.read'?: BaseFilterHook;
703
+ 'baseFilter.update'?: BaseFilterHook;
704
+ 'baseFilter.delete'?: BaseFilterHook;
705
+ 'overrideFilter.default'?: OverrideFilterHook;
706
+ 'overrideFilter.list'?: OverrideFilterHook;
707
+ 'overrideFilter.read'?: OverrideFilterHook;
708
+ 'overrideFilter.update'?: OverrideFilterHook;
709
+ 'overrideFilter.delete'?: OverrideFilterHook;
710
+ 'decorate.default'?: ModelMiddleware;
711
+ 'decorate.list'?: ModelMiddleware;
712
+ 'decorate.create'?: ModelMiddleware;
713
+ 'decorate.read'?: ModelMiddleware;
714
+ 'decorate.update'?: ModelMiddleware;
715
+ 'decorateAll.default'?: ModelListMiddleware;
716
+ 'decorateAll.list'?: ModelListMiddleware;
717
+ 'validate.default'?: ValidateRule | ValidateHook;
718
+ 'validate.create'?: ValidateRule | ValidateHook;
719
+ 'validate.update'?: ValidateRule | ValidateHook;
720
+ 'prepare.default'?: ModelMiddleware;
721
+ 'prepare.create'?: ModelMiddleware;
722
+ 'prepare.update'?: ModelMiddleware;
723
+ 'transform.default'?: ModelMiddleware;
724
+ 'transform.update'?: ModelMiddleware;
725
+ 'finalize.default'?: ModelMiddleware;
726
+ 'finalize.create'?: ModelMiddleware;
727
+ 'finalize.update'?: ModelMiddleware;
728
+ 'requestSchemas.create'?: RequestZodSchema;
729
+ 'requestSchemas.update'?: RequestZodSchema;
730
+ 'requestSchemas.upsert'?: RequestZodSchema;
731
+ 'requestSchemas.count'?: RequestZodSchema;
732
+ 'requestSchemas.distinct'?: RequestZodSchema;
733
+ 'requestSchemas.advancedList'?: RequestZodSchema;
734
+ 'requestSchemas.advancedReadFilter'?: RequestZodSchema;
735
+ 'requestSchemas.advancedRead'?: RequestZodSchema;
736
+ 'requestSchemas.advancedCreate.default'?: RequestZodSchema;
737
+ 'requestSchemas.advancedCreate.data'?: RequestZodSchema;
738
+ 'requestSchemas.advancedUpdate'?: RequestZodSchema;
739
+ 'requestSchemas.advancedUpdate.default'?: RequestZodSchema;
740
+ 'requestSchemas.advancedUpdate.data'?: RequestZodSchema;
741
+ 'requestSchemas.advancedUpsert.default'?: RequestZodSchema;
742
+ 'requestSchemas.advancedUpsert.data'?: RequestZodSchema;
743
+ 'requestSchemas.subList'?: RequestZodSchema;
744
+ 'requestSchemas.subRead'?: RequestZodSchema;
745
+ 'requestSchemas.subCreate'?: RequestZodSchema;
746
+ 'requestSchemas.subUpdate'?: RequestZodSchema;
747
+ 'requestSchemas.subBulkUpdate'?: RequestZodSchema;
748
+ 'defaults.findOneArgs'?: DefaultFindOneArgs;
749
+ 'defaults.findOneOptions'?: FindOneOptions;
750
+ 'defaults.findByIdArgs'?: DefaultFindByIdArgs;
751
+ 'defaults.findByIdOptions'?: FindByIdOptions;
752
+ 'defaults.findArgs'?: DefaultFindArgs;
753
+ 'defaults.findOptions'?: FindOptions;
754
+ 'defaults.createArgs'?: CreateArgs;
755
+ 'defaults.createOptions'?: CreateOptions;
756
+ 'defaults.updateOneArgs'?: UpdateOneArgs;
757
+ 'defaults.updateOneOptions'?: UpdateOneOptions;
758
+ 'defaults.updateByIdArgs'?: UpdateByIdArgs;
759
+ 'defaults.updateByIdOptions'?: UpdateByIdOptions;
760
+ 'defaults.existsOptions'?: ExistsOptions;
761
+ 'defaults.publicListArgs'?: PublicListArgs;
762
+ 'defaults.publicListOptions'?: PublicListOptions;
763
+ 'defaults.publicCreateArgs'?: PublicCreateArgs;
764
+ 'defaults.publicCreateOptions'?: PublicCreateOptions;
765
+ 'defaults.publicReadArgs'?: PublicReadArgs;
766
+ 'defaults.publicReadOptions'?: PublicReadOptions;
767
+ 'defaults.publicUpdateArgs'?: PublicUpdateArgs;
768
+ 'defaults.publicUpdateOptions'?: PublicUpdateOptions;
769
+ }
770
+ interface ExtendedDataRouterOptions extends DataRouterOptions {
771
+ 'requestSchemas.advancedList'?: RequestZodSchema;
772
+ 'requestSchemas.advancedReadFilter'?: RequestZodSchema;
773
+ 'requestSchemas.advancedRead'?: RequestZodSchema;
774
+ }
775
+ type SelectAccess = 'list' | 'create' | 'read' | 'update' | string;
776
+ type RouteGuardAccess = 'new' | 'list' | 'read' | 'update' | 'delete' | 'create' | 'distinct' | 'count' | 'subs' | string;
777
+ type DocPermissionsAccess = 'list' | 'create' | 'read' | 'update' | string;
778
+ type BaseFilterAccess = 'list' | 'read' | 'update' | 'delete' | string;
779
+ type DecorateAccess = 'list' | 'create' | 'read' | 'update' | string;
780
+ type DecorateAllAccess = 'list' | string;
781
+ type ValidateAccess = 'create' | 'update' | string;
782
+ type PrepareAccess = 'create' | 'update' | string;
783
+ type TransformAccess = 'update' | string;
784
+ type FinalizeAccess = 'create' | 'update' | string;
785
+
786
+ interface DistinctArgs {
787
+ filter?: Filter;
788
+ }
789
+
790
+ type DataFilter = Filter;
791
+ interface DataFindOneArgs {
792
+ select?: Projection;
793
+ }
794
+ interface DataFindOneOptions {
795
+ access?: FindAccess;
796
+ }
797
+ interface DataFindArgs {
798
+ select?: Projection;
799
+ sort?: string;
800
+ skip?: string | number;
801
+ limit?: string | number;
802
+ page?: string | number;
803
+ pageSize?: string | number;
804
+ }
805
+ interface DataFindOptions {
806
+ }
807
+
808
+ declare function macl(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
809
+ interface GuardModelConditionID {
810
+ type: string;
811
+ key: string;
812
+ }
813
+ interface GuardModelCondition {
814
+ modelName: string;
815
+ id: string | GuardModelConditionID;
816
+ condition: string | string[];
817
+ }
818
+ declare function guard(condition: string): any;
819
+ declare function guard(conditions: string[]): any;
820
+ declare function guard(conditionFunc: Function): any;
821
+ declare function guard(modelCondition: GuardModelCondition): any;
822
+
823
+ type SetTargetOption$1 = {
824
+ (option: unknown): ModelRouter;
825
+ (key: string, option: unknown): ModelRouter;
826
+ };
827
+ declare class ModelRouter {
828
+ readonly modelName: string;
829
+ readonly router: JsonRouter;
830
+ readonly model: Model;
831
+ readonly options: ModelRouterOptions;
832
+ readonly fullBasePath: string;
833
+ constructor(modelName: string, initialOptions: ModelRouterOptions);
834
+ private getRequestSchema;
835
+ private assertAllowed;
836
+ private setCollectionRoutes;
837
+ private setDocumentRoutes;
838
+ private setSubDocumentRoutes;
839
+ private logEndpoints;
840
+ set<K extends keyof ExtendedModelRouterOptions>(keyOrOptions: K | ModelRouterOptions, value?: unknown): this;
841
+ setOption<K extends keyof ExtendedModelRouterOptions>(key: K, option: ExtendedModelRouterOptions[K]): this;
842
+ setOptions(options: ModelRouterOptions): this;
843
+ /**
844
+ * The maximum limit of the number of documents returned from the `list` operation.
845
+ */
846
+ listHardLimit: SetTargetOption$1;
847
+ /**
848
+ * The object schema to define the access control policy for each model field.
849
+ */
850
+ permissionSchema: SetTargetOption$1;
851
+ /**
852
+ * The object field to store the document permissions.
853
+ */
854
+ documentPermissionField: SetTargetOption$1;
855
+ /**
856
+ * The essential model fields involved in generating document permissions.
857
+ */
858
+ mandatoryFields: SetTargetOption$1;
859
+ /**
860
+ * The function called in the process of generating document permissions.
861
+ */
862
+ docPermissions: SetTargetOption$1;
863
+ /**
864
+ * The access control policy for CRUDL endpoints.
865
+ * @operation `create`, `list`, `read`, `update`, `delete`
866
+ */
867
+ routeGuard: SetTargetOption$1;
868
+ /**
869
+ * The base filter definitions applied in every query transaction.
870
+ * @operation `list`, `read`, `update`, `delete`
871
+ */
872
+ baseFilter: SetTargetOption$1;
873
+ /**
874
+ * The override filter definitions applied in every query transaction.
875
+ * @operation `list`, `read`, `update`, `delete`
876
+ */
877
+ overrideFilter: SetTargetOption$1;
878
+ /**
879
+ * Middleware
880
+ *
881
+ * The function called before a new/update document data is processed in `prepare` hooks. This method is used to validate `write data` and throw an error if not valid.
882
+ * @operation `create`, `update`
883
+ */
884
+ validate: SetTargetOption$1;
885
+ /**
886
+ * Middleware
887
+ *
888
+ * The function called before a new document is created or an existing document is updated. This method is used to process raw data passed into the API endpoints.
889
+ * @operation `create`, `update`
890
+ */
891
+ prepare: SetTargetOption$1;
892
+ /**
893
+ * Middleware
894
+ *
895
+ * The function called before an updated document is saved.
896
+ * @operation `update`
897
+ */
898
+ transform: SetTargetOption$1;
899
+ /**
900
+ * Middleware
901
+ *
902
+ * The function called after a new document is created or an updated document is saved.
903
+ * @operation `create`, `update`
904
+ */
905
+ finalize: SetTargetOption$1;
906
+ /**
907
+ * Middleware
908
+ *
909
+ * The function called after a updated document finalized
910
+ * @operation `update`
911
+ */
912
+ change: SetTargetOption$1;
913
+ /**
914
+ * Middleware
915
+ *
916
+ * The function called before response data is sent. This method is used to process raw data to apply custom logic before sending the result.
917
+ * @operation `list`, `read`, `create`, `update`
918
+ */
919
+ decorate: SetTargetOption$1;
920
+ /**
921
+ * Middleware
922
+ *
923
+ * The function are called before response data is sent and after `decorate` middleware runs. This method is used to process and filter multiple document objects before sending the result.
924
+ * @operation `list`
925
+ */
926
+ decorateAll: SetTargetOption$1;
927
+ /**
928
+ * The document selector definition with the `id` param.
929
+ * @option `string` | `Function`
930
+ * @operation `read`, `update`, `delete`
931
+ */
932
+ identifier: SetTargetOption$1;
933
+ /**
934
+ * The default values used when missing in the operations.
935
+ */
936
+ defaults: SetTargetOption$1;
937
+ get routes(): Router;
938
+ }
939
+
940
+ declare class RootRouter {
941
+ router: JsonRouter;
942
+ basename: string;
943
+ routeGuard: Validation;
944
+ constructor(options?: RootRouterOptions);
945
+ private processResult;
946
+ private processOp;
947
+ private groupItemsByOrder;
948
+ private assertAllowed;
949
+ private setRoutes;
950
+ get routes(): Router;
951
+ }
952
+
953
+ type SetTargetOption = {
954
+ (option: unknown): DataRouter;
955
+ (key: string, option: unknown): DataRouter;
956
+ };
957
+ declare class DataRouter {
958
+ readonly dataName: string;
959
+ readonly router: JsonRouter;
960
+ readonly options: DataRouterOptions;
961
+ readonly fullBasePath: string;
962
+ constructor(dataName: string, initialOptions: DataRouterOptions);
963
+ private getRequestSchema;
964
+ private assertAllowed;
965
+ private setCollectionRoutes;
966
+ private setDocumentRoutes;
967
+ set<K extends keyof DataRouterOptions>(keyOrOptions: K | DataRouterOptions, value?: unknown): this;
968
+ setOption<K extends keyof DataRouterOptions>(key: K, option: DataRouterOptions[K]): this;
969
+ setOptions(options: DataRouterOptions): this;
970
+ data: SetTargetOption;
971
+ listHardLimit: SetTargetOption;
972
+ permissionSchema: SetTargetOption;
973
+ routeGuard: SetTargetOption;
974
+ baseFilter: SetTargetOption;
975
+ overrideFilter: SetTargetOption;
976
+ decorate: SetTargetOption;
977
+ decorateAll: SetTargetOption;
978
+ identifier: SetTargetOption;
979
+ get routes(): Router;
980
+ }
981
+
982
+ declare const setGlobalOptions: (options: GlobalOptions) => void;
983
+ declare const setGlobalOption: <K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]) => void;
984
+ declare const getGlobalOptions: () => GlobalOptions;
985
+ declare const getGlobalOption: <K extends keyof GlobalOptions>(key: K, defaultValue?: GlobalOptions[K]) => GlobalOptions[K];
986
+
987
+ declare const setModelOptions: (modelName: string, options: ModelRouterOptions) => void;
988
+ declare const setModelOption: <K extends keyof ExtendedModelRouterOptions>(modelName: string, key: K, value: ExtendedModelRouterOptions[K]) => void;
989
+ declare const getModelOptions: (modelName: string) => ModelRouterOptions;
990
+ declare const getModelOption: <K extends keyof ExtendedModelRouterOptions>(modelName: string, key: K | string, defaultValue?: ExtendedModelRouterOptions[K]) => ExtendedModelRouterOptions[K];
991
+ declare const getModelNames: () => string[];
992
+ declare const getModelJsonSchema: (modelName: string) => Record<string, unknown>;
993
+
994
+ declare const setDefaultModelOptions: (options: DefaultModelRouterOptions) => void;
995
+ declare const setDefaultModelOption: <K extends keyof ExtendedDefaultModelRouterOptions>(key: K, value: ExtendedDefaultModelRouterOptions[K]) => void;
996
+ declare const getDefaultModelOptions: () => DefaultModelRouterOptions;
997
+ declare const getDefaultModelOption: <K extends keyof ExtendedDefaultModelRouterOptions>(key: K, defaultValue?: ExtendedDefaultModelRouterOptions[K]) => ExtendedDefaultModelRouterOptions[K];
998
+
999
+ interface Options {
1000
+ virtualPermissionField?: string;
1001
+ modelName: string;
1002
+ }
1003
+ declare function permissionsPlugin(schema: any, options: Options): void;
1004
+
1005
+ declare const MIDDLEWARE: unique symbol;
1006
+ declare const DATA_MIDDLEWARE: unique symbol;
1007
+ declare const CORE: unique symbol;
1008
+ declare const PERMISSIONS: unique symbol;
1009
+ declare const PERMISSION_KEYS: unique symbol;
1010
+
1011
+ type ListQueryInput = {
1012
+ skip?: string;
1013
+ limit?: string;
1014
+ page?: string;
1015
+ page_size?: string;
1016
+ skim?: 'true' | 'false';
1017
+ include_permissions?: 'true' | 'false';
1018
+ include_count?: 'true' | 'false';
1019
+ include_extra_headers?: 'true' | 'false';
1020
+ };
1021
+ type CreateQueryInput = {
1022
+ include_permissions?: 'true' | 'false';
1023
+ };
1024
+ type ReadQueryInput = {
1025
+ include_permissions?: 'true' | 'false';
1026
+ try_list?: 'true' | 'false';
1027
+ };
1028
+ type UpdateQueryInput = {
1029
+ returning_all?: 'true' | 'false';
1030
+ };
1031
+ type UpsertQueryInput = {
1032
+ returning_all?: 'true' | 'false';
1033
+ include_permissions?: 'true' | 'false';
1034
+ };
1035
+ type AdvancedListBody = {
1036
+ query?: Filter | unknown[];
1037
+ filter?: Filter | unknown[];
1038
+ select?: Projection;
1039
+ sort?: Sort;
1040
+ populate?: Populate[] | string;
1041
+ include?: Include | Include[];
1042
+ tasks?: Task | Task[];
1043
+ skip?: string | number;
1044
+ limit?: string | number;
1045
+ page?: string | number;
1046
+ pageSize?: string | number;
1047
+ options?: {
1048
+ skim?: boolean;
1049
+ includePermissions?: boolean;
1050
+ includeCount?: boolean;
1051
+ includeExtraHeaders?: boolean;
1052
+ populateAccess?: unknown;
1053
+ };
1054
+ };
1055
+ type CountBody = {
1056
+ query?: Filter | unknown[];
1057
+ filter?: Filter | unknown[];
1058
+ access?: unknown;
1059
+ };
1060
+ type AdvancedReadFilterBody = {
1061
+ filter?: Filter | unknown[];
1062
+ select?: Projection;
1063
+ sort?: Sort;
1064
+ populate?: Populate[] | string;
1065
+ include?: Include | Include[];
1066
+ tasks?: Task | Task[];
1067
+ options?: {
1068
+ skim?: boolean;
1069
+ includePermissions?: boolean;
1070
+ tryList?: boolean;
1071
+ populateAccess?: unknown;
1072
+ };
1073
+ };
1074
+ type AdvancedReadBody = {
1075
+ select?: Projection;
1076
+ populate?: Populate[] | string;
1077
+ include?: Include | Include[];
1078
+ tasks?: Task | Task[];
1079
+ options?: {
1080
+ skim?: boolean;
1081
+ includePermissions?: boolean;
1082
+ tryList?: boolean;
1083
+ populateAccess?: unknown;
1084
+ };
1085
+ };
1086
+ type AdvancedCreateBody = {
1087
+ data: unknown;
1088
+ select?: Projection;
1089
+ populate?: Populate[] | string;
1090
+ tasks?: Task | Task[];
1091
+ options?: {
1092
+ includePermissions?: boolean;
1093
+ populateAccess?: unknown;
1094
+ };
1095
+ };
1096
+ type AdvancedUpdateBody = {
1097
+ data: unknown;
1098
+ select?: Projection;
1099
+ populate?: Populate[] | string;
1100
+ tasks?: Task | Task[];
1101
+ options?: {
1102
+ returningAll?: boolean;
1103
+ includePermissions?: boolean;
1104
+ populateAccess?: unknown;
1105
+ };
1106
+ };
1107
+ type AdvancedUpsertBody = {
1108
+ data: Record<string, unknown>;
1109
+ select?: Projection;
1110
+ populate?: Populate[] | string;
1111
+ tasks?: Task | Task[];
1112
+ options?: {
1113
+ returningAll?: boolean;
1114
+ includePermissions?: boolean;
1115
+ populateAccess?: unknown;
1116
+ };
1117
+ };
1118
+ type DistinctBody = {
1119
+ query?: Filter | unknown[];
1120
+ filter?: Filter | unknown[];
1121
+ };
1122
+ type SubListBody = {
1123
+ filter?: Filter;
1124
+ fields?: string[];
1125
+ };
1126
+ type SubReadBody = {
1127
+ fields?: string[];
1128
+ populate?: SubPopulate | SubPopulate[] | string | string[];
1129
+ };
1130
+ declare const rootQuerySchema: z.ZodArray<z.ZodObject<{
1131
+ model: z.ZodString;
1132
+ op: z.ZodString;
1133
+ id: z.ZodOptional<z.ZodString>;
1134
+ field: z.ZodOptional<z.ZodString>;
1135
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1136
+ data: z.ZodOptional<z.ZodUnknown>;
1137
+ args: z.ZodOptional<z.ZodUnknown>;
1138
+ options: z.ZodOptional<z.ZodUnknown>;
1139
+ order: z.ZodOptional<z.ZodNumber>;
1140
+ }, z.core.$loose>>;
1141
+ declare const listBodySchema: z.ZodObject<{
1142
+ query: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1143
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1144
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1145
+ sort: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<-1>, z.ZodLiteral<1>, z.ZodLiteral<"asc">, z.ZodLiteral<"ascending">, z.ZodLiteral<"desc">, z.ZodLiteral<"descending">]>>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<-1>, z.ZodLiteral<1>, z.ZodLiteral<"asc">, z.ZodLiteral<"ascending">, z.ZodLiteral<"desc">, z.ZodLiteral<"descending">]>], null>>, z.ZodNull]>>;
1146
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1147
+ path: z.ZodString;
1148
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1149
+ match: z.ZodOptional<z.ZodUnknown>;
1150
+ access: z.ZodOptional<z.ZodEnum<{
1151
+ read: "read";
1152
+ list: "list";
1153
+ }>>;
1154
+ }, z.core.$loose>]>>, z.ZodObject<{
1155
+ path: z.ZodString;
1156
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1157
+ match: z.ZodOptional<z.ZodUnknown>;
1158
+ access: z.ZodOptional<z.ZodEnum<{
1159
+ read: "read";
1160
+ list: "list";
1161
+ }>>;
1162
+ }, z.core.$loose>]>>;
1163
+ include: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1164
+ model: z.ZodString;
1165
+ op: z.ZodEnum<{
1166
+ read: "read";
1167
+ list: "list";
1168
+ count: "count";
1169
+ }>;
1170
+ path: z.ZodString;
1171
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1172
+ localField: z.ZodString;
1173
+ foreignField: z.ZodString;
1174
+ args: z.ZodOptional<z.ZodUnknown>;
1175
+ options: z.ZodOptional<z.ZodUnknown>;
1176
+ }, z.core.$loose>, z.ZodArray<z.ZodObject<{
1177
+ model: z.ZodString;
1178
+ op: z.ZodEnum<{
1179
+ read: "read";
1180
+ list: "list";
1181
+ count: "count";
1182
+ }>;
1183
+ path: z.ZodString;
1184
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1185
+ localField: z.ZodString;
1186
+ foreignField: z.ZodString;
1187
+ args: z.ZodOptional<z.ZodUnknown>;
1188
+ options: z.ZodOptional<z.ZodUnknown>;
1189
+ }, z.core.$loose>>]>>;
1190
+ tasks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1191
+ type: z.ZodString;
1192
+ args: z.ZodUnknown;
1193
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1194
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
1195
+ type: z.ZodString;
1196
+ args: z.ZodUnknown;
1197
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1198
+ }, z.core.$strip>>]>>;
1199
+ skip: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1200
+ limit: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1201
+ page: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1202
+ pageSize: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1203
+ options: z.ZodOptional<z.ZodObject<{
1204
+ skim: z.ZodOptional<z.ZodBoolean>;
1205
+ includePermissions: z.ZodOptional<z.ZodBoolean>;
1206
+ includeCount: z.ZodOptional<z.ZodBoolean>;
1207
+ includeExtraHeaders: z.ZodOptional<z.ZodBoolean>;
1208
+ populateAccess: z.ZodOptional<z.ZodUnknown>;
1209
+ }, z.core.$loose>>;
1210
+ }, z.core.$loose>;
1211
+ declare const dataListBodySchema: z.ZodObject<{
1212
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1213
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1214
+ sort: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<-1>, z.ZodLiteral<1>, z.ZodLiteral<"asc">, z.ZodLiteral<"ascending">, z.ZodLiteral<"desc">, z.ZodLiteral<"descending">]>>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<-1>, z.ZodLiteral<1>, z.ZodLiteral<"asc">, z.ZodLiteral<"ascending">, z.ZodLiteral<"desc">, z.ZodLiteral<"descending">]>], null>>, z.ZodNull]>>;
1215
+ skip: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1216
+ limit: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1217
+ page: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1218
+ pageSize: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1219
+ options: z.ZodOptional<z.ZodObject<{
1220
+ includeCount: z.ZodOptional<z.ZodBoolean>;
1221
+ includeExtraHeaders: z.ZodOptional<z.ZodBoolean>;
1222
+ }, z.core.$loose>>;
1223
+ }, z.core.$loose>;
1224
+ declare const countBodySchema: z.ZodObject<{
1225
+ query: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1226
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1227
+ access: z.ZodOptional<z.ZodUnknown>;
1228
+ }, z.core.$loose>;
1229
+ declare const readFilterBodySchema: z.ZodObject<{
1230
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1231
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1232
+ sort: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<-1>, z.ZodLiteral<1>, z.ZodLiteral<"asc">, z.ZodLiteral<"ascending">, z.ZodLiteral<"desc">, z.ZodLiteral<"descending">]>>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<-1>, z.ZodLiteral<1>, z.ZodLiteral<"asc">, z.ZodLiteral<"ascending">, z.ZodLiteral<"desc">, z.ZodLiteral<"descending">]>], null>>, z.ZodNull]>>;
1233
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1234
+ path: z.ZodString;
1235
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1236
+ match: z.ZodOptional<z.ZodUnknown>;
1237
+ access: z.ZodOptional<z.ZodEnum<{
1238
+ read: "read";
1239
+ list: "list";
1240
+ }>>;
1241
+ }, z.core.$loose>]>>, z.ZodObject<{
1242
+ path: z.ZodString;
1243
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1244
+ match: z.ZodOptional<z.ZodUnknown>;
1245
+ access: z.ZodOptional<z.ZodEnum<{
1246
+ read: "read";
1247
+ list: "list";
1248
+ }>>;
1249
+ }, z.core.$loose>]>>;
1250
+ include: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1251
+ model: z.ZodString;
1252
+ op: z.ZodEnum<{
1253
+ read: "read";
1254
+ list: "list";
1255
+ count: "count";
1256
+ }>;
1257
+ path: z.ZodString;
1258
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1259
+ localField: z.ZodString;
1260
+ foreignField: z.ZodString;
1261
+ args: z.ZodOptional<z.ZodUnknown>;
1262
+ options: z.ZodOptional<z.ZodUnknown>;
1263
+ }, z.core.$loose>, z.ZodArray<z.ZodObject<{
1264
+ model: z.ZodString;
1265
+ op: z.ZodEnum<{
1266
+ read: "read";
1267
+ list: "list";
1268
+ count: "count";
1269
+ }>;
1270
+ path: z.ZodString;
1271
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1272
+ localField: z.ZodString;
1273
+ foreignField: z.ZodString;
1274
+ args: z.ZodOptional<z.ZodUnknown>;
1275
+ options: z.ZodOptional<z.ZodUnknown>;
1276
+ }, z.core.$loose>>]>>;
1277
+ tasks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1278
+ type: z.ZodString;
1279
+ args: z.ZodUnknown;
1280
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1281
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
1282
+ type: z.ZodString;
1283
+ args: z.ZodUnknown;
1284
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1285
+ }, z.core.$strip>>]>>;
1286
+ options: z.ZodOptional<z.ZodObject<{
1287
+ skim: z.ZodOptional<z.ZodBoolean>;
1288
+ includePermissions: z.ZodOptional<z.ZodBoolean>;
1289
+ tryList: z.ZodOptional<z.ZodBoolean>;
1290
+ populateAccess: z.ZodOptional<z.ZodUnknown>;
1291
+ }, z.core.$loose>>;
1292
+ }, z.core.$loose>;
1293
+ declare const dataReadFilterBodySchema: z.ZodObject<{
1294
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1295
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1296
+ options: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
1297
+ }, z.core.$loose>;
1298
+ declare const readByIdBodySchema: z.ZodObject<{
1299
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1300
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1301
+ path: z.ZodString;
1302
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1303
+ match: z.ZodOptional<z.ZodUnknown>;
1304
+ access: z.ZodOptional<z.ZodEnum<{
1305
+ read: "read";
1306
+ list: "list";
1307
+ }>>;
1308
+ }, z.core.$loose>]>>, z.ZodObject<{
1309
+ path: z.ZodString;
1310
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1311
+ match: z.ZodOptional<z.ZodUnknown>;
1312
+ access: z.ZodOptional<z.ZodEnum<{
1313
+ read: "read";
1314
+ list: "list";
1315
+ }>>;
1316
+ }, z.core.$loose>]>>;
1317
+ include: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1318
+ model: z.ZodString;
1319
+ op: z.ZodEnum<{
1320
+ read: "read";
1321
+ list: "list";
1322
+ count: "count";
1323
+ }>;
1324
+ path: z.ZodString;
1325
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1326
+ localField: z.ZodString;
1327
+ foreignField: z.ZodString;
1328
+ args: z.ZodOptional<z.ZodUnknown>;
1329
+ options: z.ZodOptional<z.ZodUnknown>;
1330
+ }, z.core.$loose>, z.ZodArray<z.ZodObject<{
1331
+ model: z.ZodString;
1332
+ op: z.ZodEnum<{
1333
+ read: "read";
1334
+ list: "list";
1335
+ count: "count";
1336
+ }>;
1337
+ path: z.ZodString;
1338
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1339
+ localField: z.ZodString;
1340
+ foreignField: z.ZodString;
1341
+ args: z.ZodOptional<z.ZodUnknown>;
1342
+ options: z.ZodOptional<z.ZodUnknown>;
1343
+ }, z.core.$loose>>]>>;
1344
+ tasks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1345
+ type: z.ZodString;
1346
+ args: z.ZodUnknown;
1347
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1348
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
1349
+ type: z.ZodString;
1350
+ args: z.ZodUnknown;
1351
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1352
+ }, z.core.$strip>>]>>;
1353
+ options: z.ZodOptional<z.ZodObject<{
1354
+ skim: z.ZodOptional<z.ZodBoolean>;
1355
+ includePermissions: z.ZodOptional<z.ZodBoolean>;
1356
+ tryList: z.ZodOptional<z.ZodBoolean>;
1357
+ populateAccess: z.ZodOptional<z.ZodUnknown>;
1358
+ }, z.core.$loose>>;
1359
+ }, z.core.$loose>;
1360
+ declare const dataReadByIdBodySchema: z.ZodObject<{
1361
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1362
+ options: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
1363
+ }, z.core.$loose>;
1364
+ declare const advancedCreateBodySchema: z.ZodObject<{
1365
+ data: z.ZodUnknown;
1366
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1367
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1368
+ path: z.ZodString;
1369
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1370
+ match: z.ZodOptional<z.ZodUnknown>;
1371
+ access: z.ZodOptional<z.ZodEnum<{
1372
+ read: "read";
1373
+ list: "list";
1374
+ }>>;
1375
+ }, z.core.$loose>]>>, z.ZodObject<{
1376
+ path: z.ZodString;
1377
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1378
+ match: z.ZodOptional<z.ZodUnknown>;
1379
+ access: z.ZodOptional<z.ZodEnum<{
1380
+ read: "read";
1381
+ list: "list";
1382
+ }>>;
1383
+ }, z.core.$loose>]>>;
1384
+ tasks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1385
+ type: z.ZodString;
1386
+ args: z.ZodUnknown;
1387
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1388
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
1389
+ type: z.ZodString;
1390
+ args: z.ZodUnknown;
1391
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1392
+ }, z.core.$strip>>]>>;
1393
+ options: z.ZodOptional<z.ZodObject<{
1394
+ includePermissions: z.ZodOptional<z.ZodBoolean>;
1395
+ populateAccess: z.ZodOptional<z.ZodUnknown>;
1396
+ }, z.core.$loose>>;
1397
+ }, z.core.$loose>;
1398
+ declare const createBodySchema: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>]>;
1399
+ declare const updateBodySchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1400
+ declare const advancedUpdateBodySchema: z.ZodObject<{
1401
+ data: z.ZodUnknown;
1402
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1403
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1404
+ path: z.ZodString;
1405
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1406
+ match: z.ZodOptional<z.ZodUnknown>;
1407
+ access: z.ZodOptional<z.ZodEnum<{
1408
+ read: "read";
1409
+ list: "list";
1410
+ }>>;
1411
+ }, z.core.$loose>]>>, z.ZodObject<{
1412
+ path: z.ZodString;
1413
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1414
+ match: z.ZodOptional<z.ZodUnknown>;
1415
+ access: z.ZodOptional<z.ZodEnum<{
1416
+ read: "read";
1417
+ list: "list";
1418
+ }>>;
1419
+ }, z.core.$loose>]>>;
1420
+ tasks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1421
+ type: z.ZodString;
1422
+ args: z.ZodUnknown;
1423
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1424
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
1425
+ type: z.ZodString;
1426
+ args: z.ZodUnknown;
1427
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1428
+ }, z.core.$strip>>]>>;
1429
+ options: z.ZodOptional<z.ZodObject<{
1430
+ returningAll: z.ZodOptional<z.ZodBoolean>;
1431
+ includePermissions: z.ZodOptional<z.ZodBoolean>;
1432
+ populateAccess: z.ZodOptional<z.ZodUnknown>;
1433
+ }, z.core.$loose>>;
1434
+ }, z.core.$loose>;
1435
+ declare const upsertBodySchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1436
+ declare const advancedUpsertBodySchema: z.ZodObject<{
1437
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1438
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1439
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1440
+ path: z.ZodString;
1441
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1442
+ match: z.ZodOptional<z.ZodUnknown>;
1443
+ access: z.ZodOptional<z.ZodEnum<{
1444
+ read: "read";
1445
+ list: "list";
1446
+ }>>;
1447
+ }, z.core.$loose>]>>, z.ZodObject<{
1448
+ path: z.ZodString;
1449
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1450
+ match: z.ZodOptional<z.ZodUnknown>;
1451
+ access: z.ZodOptional<z.ZodEnum<{
1452
+ read: "read";
1453
+ list: "list";
1454
+ }>>;
1455
+ }, z.core.$loose>]>>;
1456
+ tasks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1457
+ type: z.ZodString;
1458
+ args: z.ZodUnknown;
1459
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1460
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
1461
+ type: z.ZodString;
1462
+ args: z.ZodUnknown;
1463
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1464
+ }, z.core.$strip>>]>>;
1465
+ options: z.ZodOptional<z.ZodObject<{
1466
+ returningAll: z.ZodOptional<z.ZodBoolean>;
1467
+ includePermissions: z.ZodOptional<z.ZodBoolean>;
1468
+ populateAccess: z.ZodOptional<z.ZodUnknown>;
1469
+ }, z.core.$loose>>;
1470
+ }, z.core.$loose>;
1471
+ declare const distinctBodySchema: z.ZodObject<{
1472
+ query: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1473
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>>;
1474
+ }, z.core.$loose>;
1475
+ declare const subListBodySchema: z.ZodObject<{
1476
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1477
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
1478
+ }, z.core.$loose>;
1479
+ declare const subMutationBodySchema: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>]>;
1480
+ declare const subReadBodySchema: z.ZodObject<{
1481
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
1482
+ populate: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
1483
+ path: z.ZodString;
1484
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1485
+ }, z.core.$loose>]>>, z.ZodObject<{
1486
+ path: z.ZodString;
1487
+ select: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<-1>]>>]>>;
1488
+ }, z.core.$loose>]>>;
1489
+ }, z.core.$loose>;
1490
+ declare function parsePathParam(value: string | string[] | undefined, parameter: string): string;
1491
+ declare function parseQuery<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown): z.output<TSchema>;
1492
+ declare function parseBody<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown): z.output<TSchema>;
1493
+ declare function parseBodyWithSchema<TSchema extends z.ZodTypeAny>(schema: TSchema, value: unknown, userSchema?: z.ZodTypeAny): z.output<TSchema>;
1494
+ declare function parseNestedBodyWithSchema(schema: z.ZodTypeAny, value: unknown, nestedKey: string, userSchema?: z.ZodTypeAny): Record<string, unknown>;
1495
+ declare const requestSchemas: {
1496
+ listQuery: z.ZodObject<{
1497
+ skip: z.ZodOptional<z.ZodString>;
1498
+ limit: z.ZodOptional<z.ZodString>;
1499
+ page: z.ZodOptional<z.ZodString>;
1500
+ page_size: z.ZodOptional<z.ZodString>;
1501
+ skim: z.ZodOptional<z.ZodEnum<{
1502
+ true: "true";
1503
+ false: "false";
1504
+ }>>;
1505
+ include_permissions: z.ZodOptional<z.ZodEnum<{
1506
+ true: "true";
1507
+ false: "false";
1508
+ }>>;
1509
+ include_count: z.ZodOptional<z.ZodEnum<{
1510
+ true: "true";
1511
+ false: "false";
1512
+ }>>;
1513
+ include_extra_headers: z.ZodOptional<z.ZodEnum<{
1514
+ true: "true";
1515
+ false: "false";
1516
+ }>>;
1517
+ }, z.core.$loose>;
1518
+ createQuery: z.ZodObject<{
1519
+ include_permissions: z.ZodOptional<z.ZodEnum<{
1520
+ true: "true";
1521
+ false: "false";
1522
+ }>>;
1523
+ }, z.core.$loose>;
1524
+ readQuery: z.ZodObject<{
1525
+ include_permissions: z.ZodOptional<z.ZodEnum<{
1526
+ true: "true";
1527
+ false: "false";
1528
+ }>>;
1529
+ try_list: z.ZodOptional<z.ZodEnum<{
1530
+ true: "true";
1531
+ false: "false";
1532
+ }>>;
1533
+ }, z.core.$loose>;
1534
+ updateQuery: z.ZodObject<{
1535
+ returning_all: z.ZodOptional<z.ZodEnum<{
1536
+ true: "true";
1537
+ false: "false";
1538
+ }>>;
1539
+ }, z.core.$loose>;
1540
+ upsertQuery: z.ZodObject<{
1541
+ returning_all: z.ZodOptional<z.ZodEnum<{
1542
+ true: "true";
1543
+ false: "false";
1544
+ }>>;
1545
+ include_permissions: z.ZodOptional<z.ZodEnum<{
1546
+ true: "true";
1547
+ false: "false";
1548
+ }>>;
1549
+ }, z.core.$loose>;
1550
+ };
1551
+
1552
+ type CreateRouter = {
1553
+ (modelName: string, options: ModelRouterOptions): ModelRouter;
1554
+ (options: RootRouterOptions): RootRouter;
1555
+ };
1556
+ type CreateDataRouter = {
1557
+ (dataName: string, options: DataRouterOptions): DataRouter;
1558
+ };
1559
+ type WttSet = {
1560
+ <K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]): void;
1561
+ (options: {
1562
+ [K in keyof GlobalOptions]: GlobalOptions[K];
1563
+ }): void;
1564
+ };
1565
+ interface Wtt {
1566
+ createRouter: CreateRouter;
1567
+ createDataRouter: CreateDataRouter;
1568
+ set: WttSet;
1569
+ setGlobalOptions: typeof setGlobalOptions;
1570
+ setGlobalOption: typeof setGlobalOption;
1571
+ getGlobalOptions: typeof getGlobalOptions;
1572
+ getGlobalOption: typeof getGlobalOption;
1573
+ setModelOptions: typeof setModelOptions;
1574
+ setModelOption: typeof setModelOption;
1575
+ getModelOptions: typeof getModelOptions;
1576
+ getModelOption: typeof getModelOption;
1577
+ getModelNames: typeof getModelNames;
1578
+ getModelJsonSchema: typeof getModelJsonSchema;
1579
+ setDefaultModelOptions: typeof setDefaultModelOptions;
1580
+ setDefaultModelOption: typeof setDefaultModelOption;
1581
+ getDefaultModelOptions: typeof getDefaultModelOptions;
1582
+ getDefaultModelOption: typeof getDefaultModelOption;
1583
+ RootRouter: typeof RootRouter;
1584
+ ModelRouter: typeof ModelRouter;
1585
+ DataRouter: typeof DataRouter;
1586
+ }
1587
+ declare const wtt: typeof macl & Wtt;
1588
+
1589
+ export { type AccessRouterLogger, type AdvancedCreateBody, type AdvancedListBody, type AdvancedReadBody, type AdvancedReadFilterBody, type AdvancedUpdateBody, type AdvancedUpsertBody, type BaseFilterAccess, CORE, Codes, type CountBody, type CreateArgs, type CreateOptions, type CreateQueryInput, CustomHeaders, DATA_MIDDLEWARE, type DataFilter, type DataFindArgs, type DataFindOneArgs, type DataFindOneOptions, type DataFindOptions, type DataMiddlewareContext, type DataRequestSchemas, type DataRouterOptions, type DecorateAccess, type DecorateAllAccess, type DefaultModelRouterOptions, type Defaults, type DistinctArgs, type DistinctBody, type DocPermissionsAccess, type ErrorResult, type ExistsOptions, type ExtendedDataRouterOptions, type ExtendedDefaultModelRouterOptions, type ExtendedModelRouterOptions, type Filter, FilterOperator, type FinalizeAccess, type FindAccess, type FindArgs, type FindByIdArgs, type FindByIdOptions, type FindOneArgs, type FindOneOptions, type FindOptions, type GlobalOptions, type Include, type KeyValueProjection, type ListQueryInput, type ListResult, MIDDLEWARE, type MiddlewareContext, ModelRouter, type ModelRouterOptions, PERMISSIONS, PERMISSION_KEYS, type Permissions, type Populate, type PopulateAccess, type PrepareAccess, type Projection, type PublicCreateArgs, type PublicCreateOptions, type PublicListArgs, type PublicListOptions, type PublicReadArgs, type PublicReadOptions, type PublicUpdateArgs, type PublicUpdateOptions, type ReadQueryInput, type Request, type RequestSchemas, type RootQueryEntry, RootRouter, type RootRouterOptions, type RouteGuardAccess, type SelectAccess, type ServiceResult, type SingleResult, type Sort, type SortOrder, StatusCodes, type SubListBody, type SubPopulate, type SubQueryEntry, type SubReadBody, type Task, type TransformAccess, type UpdateByIdArgs, type UpdateByIdOptions, type UpdateOneArgs, type UpdateOneOptions, type UpdateQueryInput, type UpsertArgs, type UpsertOptions, type UpsertQueryInput, type ValidateAccess, type Validation, advancedCreateBodySchema, advancedUpdateBodySchema, advancedUpsertBodySchema, countBodySchema, createBodySchema, dataListBodySchema, dataReadByIdBodySchema, dataReadFilterBodySchema, wtt as default, distinctBodySchema, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, listBodySchema, parseBody, parseBodyWithSchema, parseNestedBodyWithSchema, parsePathParam, parseQuery, permissionsPlugin, readByIdBodySchema, readFilterBodySchema, requestSchemas, rootQuerySchema, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions, subListBodySchema, subMutationBodySchema, subReadBodySchema, updateBodySchema, upsertBodySchema };