@web-ts-toolkit/access-router 0.38.0 → 0.40.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 CHANGED
@@ -1,10 +1,173 @@
1
1
  import mongoose, { Schema } from 'mongoose';
2
2
  import { Response, NextFunction, RequestHandler, Router } from 'express';
3
- import { A as AccessRouterBaseRequest, aa as GuardHook, ay as ModelRequest, cG as AccessRuntime, N as DataRouterOptions, L as DataRequest, cH as DataService, cI as Model, az as ModelRouterOptions, cJ as Service, cK as PublicService, _ as ExtendedModelRouterOptions, cj as Validation, bu as RootRouterOptions, cL as OpenApiRouterOptions, cM as OpenApiRegistryOptions, cN as OpenApiRouteDescriptor, cO as OpenApiDocumentOptions, cP as OpenApiParameter, cQ as OpenApiSchema, cR as OpenApiResponses, a8 as GlobalOptions, R as DefaultModelRouterOptions, Z as ExtendedDefaultModelRouterOptions } from './parsers--DZcTstL.js';
4
- export { cS as AccessRouterPermissionMap, cT as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, m as AjvValidatorLike, n as ArkTypeErrorsLike, o as ArkTypeLike, a9 as GlobalPermissionValue, ad as IoTsContextEntryLike, ae as IoTsDecodeErrorLike, af as IoTsDecoderLike, ag as JoiSchemaLike, ah as JoiValidationErrorDetailLike, am as MaybePromise, an as ModelBaseFilterHook, ap as ModelDeleteHook, aq as ModelDocPermissionsHook, as as ModelDocumentHook, at as ModelHook, av as ModelIdentifierHook, aw as ModelListHook, ax as ModelOverrideFilterHook, aA as ModelValidateHook, cU as OpenApiMethod, cV as Permissions, a_ as RequestSchemaAdapter, a$ as RequestSchemaFailure, b0 as RequestSchemaIssue, b1 as RequestSchemaLike, b2 as RequestSchemaOptions, b3 as RequestSchemaResult, b4 as RequestSchemaSuccess, b5 as RequestSchemaValidator, bF as StandardSchemaFailure, bG as StandardSchemaInferOutput, bH as StandardSchemaIssue, bI as StandardSchemaPathSegment, bJ as StandardSchemaResult, bK as StandardSchemaSuccess, bL as StandardSchemaV1, c0 as SuperstructFailureLike, c1 as SuperstructValidateLike, cd as ValibotIssueLike, ce as ValibotPathItemLike, cf as ValibotSafeParseLike, cg as ValibotSafeParseResult, cl as VineValidationErrorLike, cm as VineValidationMessageLike, cn as VineValidatorLike, co as YupSchemaLike, cp as YupValidationErrorLike, cW as defaultRuntime, cq as defineRequestSchema, cr as fromAjv, cs as fromArkType, ct as fromIoTs, cu as fromJoi, cv as fromStandardSchema, cw as fromSuperstruct, cx as fromValibot, cy as fromVine, cz as fromYup, cA as fromZod } from './parsers--DZcTstL.js';
3
+ import { a8 as GlobalOptions, R as DefaultModelRouterOptions, Z as ExtendedDefaultModelRouterOptions, az as ModelRouterOptions, _ as ExtendedModelRouterOptions, N as DataRouterOptions, Y as ExtendedDataRouterOptions, A as AccessRouterBaseRequest, aa as GuardHook, ay as ModelRequest, L as DataRequest, cG as DataService, $ as Filter, aI as Projection, bD as Sort, aF as Populate, cH as Service, cI as PublicService, cj as Validation, bu as RootRouterOptions } from './parsers-PMWujHUV.js';
4
+ export { cJ as AccessRouterPermissionMap, cK as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, m as AjvValidatorLike, n as ArkTypeErrorsLike, o as ArkTypeLike, a9 as GlobalPermissionValue, ad as IoTsContextEntryLike, ae as IoTsDecodeErrorLike, af as IoTsDecoderLike, ag as JoiSchemaLike, ah as JoiValidationErrorDetailLike, am as MaybePromise, an as ModelBaseFilterHook, ap as ModelDeleteHook, aq as ModelDocPermissionsHook, as as ModelDocumentHook, at as ModelHook, av as ModelIdentifierHook, aw as ModelListHook, ax as ModelOverrideFilterHook, aA as ModelValidateHook, cL as Permissions, a_ as RequestSchemaAdapter, a$ as RequestSchemaFailure, b0 as RequestSchemaIssue, b1 as RequestSchemaLike, b2 as RequestSchemaOptions, b3 as RequestSchemaResult, b4 as RequestSchemaSuccess, b5 as RequestSchemaValidator, bF as StandardSchemaFailure, bG as StandardSchemaInferOutput, bH as StandardSchemaIssue, bI as StandardSchemaPathSegment, bJ as StandardSchemaResult, bK as StandardSchemaSuccess, bL as StandardSchemaV1, c0 as SuperstructFailureLike, c1 as SuperstructValidateLike, cd as ValibotIssueLike, ce as ValibotPathItemLike, cf as ValibotSafeParseLike, cg as ValibotSafeParseResult, cl as VineValidationErrorLike, cm as VineValidationMessageLike, cn as VineValidatorLike, co as YupSchemaLike, cp as YupValidationErrorLike, cq as defineRequestSchema, cr as fromAjv, cs as fromArkType, ct as fromIoTs, cu as fromJoi, cv as fromStandardSchema, cw as fromSuperstruct, cx as fromValibot, cy as fromVine, cz as fromYup, cA as fromZod } from './parsers-PMWujHUV.js';
5
5
  import JsonRouter from '@web-ts-toolkit/express-json-router';
6
6
  import 'zod';
7
7
 
8
+ type OpenApiMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
9
+ type OpenApiSchema = Record<string, unknown>;
10
+ type OpenApiSchemaSource = unknown;
11
+ type OpenApiParameter = {
12
+ name: string;
13
+ in: 'path' | 'query';
14
+ required?: boolean;
15
+ description?: string;
16
+ schema?: OpenApiSchema;
17
+ };
18
+ type OpenApiResponse = {
19
+ description: string;
20
+ content?: Record<string, {
21
+ schema: OpenApiSchema;
22
+ }>;
23
+ };
24
+ type OpenApiResponses = Record<string, OpenApiResponse>;
25
+ type OpenApiRouteDescriptor = {
26
+ method: OpenApiMethod;
27
+ path: string;
28
+ operationId?: string;
29
+ summary?: string;
30
+ description?: string;
31
+ tags?: string[];
32
+ acl?: string;
33
+ deprecated?: boolean;
34
+ query?: OpenApiSchemaSource;
35
+ body?: OpenApiSchemaSource;
36
+ pathParams?: Record<string, OpenApiSchemaSource>;
37
+ responses?: OpenApiResponses;
38
+ /**
39
+ * When true, replaces an existing registration with the same method/path
40
+ * even when the descriptors differ. When false (default), conflicting
41
+ * registrations throw at registration time so consumers can detect
42
+ * accidental route shadowing.
43
+ */
44
+ allowReplace?: boolean;
45
+ /**
46
+ * When true, this exact descriptor is idempotent and registering the same
47
+ * method/path with an equivalent descriptor again is silently accepted.
48
+ * Differing re-registrations still throw unless {@link allowReplace} is set.
49
+ * Additionally, an idempotent descriptor may share its operationId with
50
+ * another idempotent descriptor mounted at a different path on the same
51
+ * registry, so reserved operations (e.g. the root batch route) can be
52
+ * exposed from multiple base paths without triggering strict-mode
53
+ * duplicate-operationId rejection.
54
+ */
55
+ idempotent?: boolean;
56
+ };
57
+ type OpenApiRegistryOptions = {
58
+ /**
59
+ * Throw when the same method/path is registered twice with differing
60
+ * descriptors, instead of silently replacing. Default: true (strict).
61
+ * The {@link AccessRuntime} registry is constructed in strict mode by
62
+ * default; construct {@link OpenApiRegistry} directly with
63
+ * `rejectConflicts: false` for legacy replacement semantics.
64
+ */
65
+ rejectConflicts?: boolean;
66
+ /**
67
+ * Throw when the same operationId is registered more than once, including
68
+ * when {@link OpenApiRouteDescriptor.allowReplace} is set. Default: true.
69
+ */
70
+ rejectDuplicateOperationIds?: boolean;
71
+ };
72
+ type OpenApiDocumentOptions = {
73
+ title: string;
74
+ version: string;
75
+ description?: string;
76
+ servers?: Array<{
77
+ url: string;
78
+ description?: string;
79
+ }>;
80
+ };
81
+ type OpenApiRouterOptions = Partial<OpenApiDocumentOptions> & {
82
+ jsonPath?: string;
83
+ docsPath?: string | false;
84
+ swaggerUiCssUrl?: string;
85
+ swaggerUiBundleUrl?: string;
86
+ };
87
+
88
+ declare class AccessRuntime {
89
+ private readonly allowGlobalModelLookup;
90
+ constructor(options?: {
91
+ allowGlobalModelLookup?: boolean;
92
+ });
93
+ private readonly globalOptions;
94
+ private readonly defaultModelOptions;
95
+ private readonly modelOptions;
96
+ private readonly modelJsonSchemas;
97
+ private readonly dataOptions;
98
+ private readonly modelRefs;
99
+ private readonly modelSubs;
100
+ private readonly modelAtts;
101
+ private readonly modelInstances;
102
+ private readonly openApiRegistry;
103
+ registerModelInstance(modelName: string, model: mongoose.Model<unknown>): void;
104
+ hasModelInstance(modelName: string): boolean;
105
+ getModelInstance(modelName: string): mongoose.Model<unknown> | null;
106
+ registerOpenApiRoute(route: OpenApiRouteDescriptor): void;
107
+ /**
108
+ * Enable strict OpenAPI collision detection for the remainder of this
109
+ * runtime's lifetime. After this call, conflicting method/path
110
+ * registrations and duplicate operationIds throw {@link OpenApiCollisionError}
111
+ * instead of silently replacing. Existing already-registered routes are
112
+ * not retroactively re-validated.
113
+ */
114
+ enableOpenApiCollisionDetection(): void;
115
+ getOpenApiRoutes(): OpenApiRouteDescriptor[];
116
+ clearOpenApiRoutes(): void;
117
+ getOpenApiSpec(info: OpenApiDocumentOptions): {
118
+ openapi: string;
119
+ info: Omit<OpenApiDocumentOptions, "servers">;
120
+ servers?: OpenApiDocumentOptions["servers"];
121
+ paths: Record<string, Record<string, {
122
+ [key: `x-${string}`]: unknown;
123
+ operationId?: string;
124
+ summary?: string;
125
+ description?: string;
126
+ tags?: string[];
127
+ deprecated?: boolean;
128
+ parameters?: OpenApiParameter[];
129
+ requestBody?: {
130
+ required?: boolean;
131
+ content: Record<string, {
132
+ schema: OpenApiSchema;
133
+ }>;
134
+ };
135
+ responses: OpenApiResponses;
136
+ }>>;
137
+ };
138
+ setGlobalOptions(options: GlobalOptions): void;
139
+ setGlobalOption<K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]): void;
140
+ getGlobalOptions(): GlobalOptions;
141
+ getGlobalOption<K extends keyof GlobalOptions>(key: K, defaultValue?: GlobalOptions[K]): GlobalOptions[K];
142
+ setDefaultModelOptions(options: DefaultModelRouterOptions): void;
143
+ setDefaultModelOption<K extends keyof ExtendedDefaultModelRouterOptions>(key: K, value: ExtendedDefaultModelRouterOptions[K]): void;
144
+ getDefaultModelOptions(): DefaultModelRouterOptions<unknown>;
145
+ getDefaultModelOption<K extends keyof ExtendedDefaultModelRouterOptions>(key: K, defaultValue?: ExtendedDefaultModelRouterOptions[K]): ExtendedDefaultModelRouterOptions<unknown>[K];
146
+ private createModelOptions;
147
+ private getOrCreateModelOptions;
148
+ setModelOptions<TModel = unknown>(modelName: string, options: ModelRouterOptions<TModel>): void;
149
+ setModelOption<K extends keyof ExtendedModelRouterOptions<TModel>, TModel = unknown>(modelName: string, key: K, value: ExtendedModelRouterOptions<TModel>[K]): void;
150
+ getModelOptions<TModel = unknown>(modelName: string): ModelRouterOptions<TModel>;
151
+ getModelOption<K extends keyof ExtendedModelRouterOptions<TModel>, TModel = unknown>(modelName: string, key: K | string, defaultValue?: ExtendedModelRouterOptions<TModel>[K]): ExtendedModelRouterOptions<TModel>[K];
152
+ getExactModelOption<K extends keyof ExtendedModelRouterOptions<TModel>, TModel = unknown>(modelName: string, key: K | string): ExtendedModelRouterOptions<TModel>[K];
153
+ getModelNames(): string[];
154
+ hasModel(modelName: string): boolean;
155
+ getModelJsonSchema(modelName: string): Record<string, unknown>;
156
+ private createDataOptions;
157
+ private getOrCreateDataOptions;
158
+ setDataOptions<TData = unknown>(dataName: string, options: DataRouterOptions<TData>): void;
159
+ setDataOption<K extends keyof DataRouterOptions<TData>, TData = unknown>(dataName: string, key: K, value: DataRouterOptions<TData>[K]): void;
160
+ getDataOptions<TData = unknown>(dataName: string): DataRouterOptions<TData>;
161
+ getDataOption<K extends keyof DataRouterOptions<TData>, TData = unknown>(dataName: string, key: K | string, defaultValue?: DataRouterOptions<TData>[K]): DataRouterOptions<TData>[K];
162
+ getExactDataOption<K extends keyof ExtendedDataRouterOptions<TData>, TData = unknown>(dataName: string, key: K | string): ExtendedDataRouterOptions<TData>[K];
163
+ getDataNames(): string[];
164
+ ensureModelMeta(modelName: string): void;
165
+ getModelRef(modelName: string, refPath: string): string | null;
166
+ getModelSub(modelName: string): string[];
167
+ getModelAtt(modelName: string): string[];
168
+ }
169
+ declare const defaultRuntime: AccessRuntime;
170
+
8
171
  declare function macl(): (req: AccessRouterBaseRequest, res: Response, next: NextFunction) => Promise<void>;
9
172
  interface GuardModelConditionID {
10
173
  type: 'param' | 'query';
@@ -55,6 +218,38 @@ declare class DataRouter<TData = unknown> {
55
218
  get routes(): Router;
56
219
  }
57
220
 
221
+ interface FindProps {
222
+ filter: Filter;
223
+ select?: Projection;
224
+ sort?: Sort;
225
+ populate?: Populate[] | string;
226
+ limit?: string | number;
227
+ hardLimit?: number;
228
+ skip?: string | number;
229
+ lean?: boolean;
230
+ }
231
+ interface FindOneProps {
232
+ filter: Filter;
233
+ select?: Projection;
234
+ sort?: Sort;
235
+ populate?: Populate[] | string;
236
+ lean?: boolean;
237
+ }
238
+ declare class Model {
239
+ modelName: string;
240
+ mongooseModel: mongoose.Model<any>;
241
+ runtime: AccessRuntime | null;
242
+ constructor(modelName: string, runtime?: AccessRuntime);
243
+ new(): any;
244
+ create(data: unknown): Promise<any>;
245
+ find({ filter, select, sort, populate, limit, hardLimit, skip, lean }: FindProps): mongoose.Query<any[], any>;
246
+ findOne({ filter, select, sort, populate, lean }: FindOneProps): mongoose.Query<any, any>;
247
+ exists(filter: Filter): ReturnType<typeof Model.prototype.findOne> | null;
248
+ countDocuments(filter?: {}): mongoose.Query<number, any>;
249
+ distinct(field: string, conditions?: {}): mongoose.Query<any[], any>;
250
+ aggregate(pipeline: unknown[]): mongoose.Aggregate<any[]>;
251
+ }
252
+
58
253
  type SetTargetOption<TRouter, TOption> = {
59
254
  (option: TOption): TRouter;
60
255
  (key: string, option: unknown): TRouter;
@@ -379,4 +574,4 @@ type AccessRuntimeApi = typeof macl & Wtt;
379
574
  declare function createAccessRuntime(): AccessRuntimeApi;
380
575
  declare const acl: AccessRuntimeApi;
381
576
 
382
- export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, ExtendedDefaultModelRouterOptions, ExtendedModelRouterOptions, GlobalOptions, type GuardModelCondition, type GuardModelConditionID, ModelRouter, ModelRouterOptions, type OpLogContext, OpenApiCollisionError, OpenApiDocumentOptions, OpenApiRegistry, OpenApiRegistryOptions, OpenApiRouteDescriptor, OpenApiRouterOptions, RootRouter, RootRouterOptions, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelInstance, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, hasModelInstance, isLevelEnabled, permissionsPlugin, redactFilter, redactPayload, registerModelInstance, safeStringify, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
577
+ export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, ExtendedDefaultModelRouterOptions, ExtendedModelRouterOptions, GlobalOptions, type GuardModelCondition, type GuardModelConditionID, ModelRouter, ModelRouterOptions, type OpLogContext, OpenApiCollisionError, type OpenApiDocumentOptions, type OpenApiMethod, OpenApiRegistry, type OpenApiRegistryOptions, type OpenApiRouteDescriptor, type OpenApiRouterOptions, RootRouter, RootRouterOptions, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, defaultRuntime, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelInstance, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, hasModelInstance, isLevelEnabled, permissionsPlugin, redactFilter, redactPayload, registerModelInstance, safeStringify, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };