@web-ts-toolkit/access-router-deco 0.5.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.js ADDED
@@ -0,0 +1,524 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ AfterDelete: () => AfterDelete,
33
+ AfterPersist: () => AfterPersist,
34
+ BaseFilter: () => BaseFilter,
35
+ BeforeDelete: () => BeforeDelete,
36
+ Context: () => Context,
37
+ Decorate: () => Decorate,
38
+ DecorateAll: () => DecorateAll,
39
+ DocPermissions: () => DocPermissions,
40
+ Document: () => Document,
41
+ EgoseFactory: () => EgoseFactory,
42
+ EgoseFactoryStatic: () => EgoseFactoryStatic,
43
+ GlobalPermissions: () => GlobalPermissions,
44
+ Identifier: () => Identifier,
45
+ Module: () => Module,
46
+ Option: () => Option,
47
+ OverrideFilter: () => OverrideFilter,
48
+ Permissions: () => Permissions,
49
+ Prepare: () => Prepare,
50
+ Request: () => Request,
51
+ RouteGuard: () => RouteGuard,
52
+ Router: () => Router2,
53
+ RouterOptions: () => RouterOptions,
54
+ Transform: () => Transform,
55
+ Validate: () => Validate
56
+ });
57
+ module.exports = __toCommonJS(index_exports);
58
+
59
+ // src/factory.ts
60
+ var import_express = __toESM(require("express"));
61
+ var import_access_router = __toESM(require("@web-ts-toolkit/access-router"));
62
+
63
+ // src/constants.ts
64
+ var MODULE_ROUTERS = "routers";
65
+ var MODULE_ROUTER_OPTIONS = "routerOptions";
66
+ var MODULE_OPTIONS = "options";
67
+ var ROOT_ROUTER_WATERMARK = "__root_router__";
68
+ var ROUTER_WATERMARK = "__router__";
69
+ var DEFAULT_MODEL_ROUTER_OPTIONS_WATERMARK = "__default_model_router_options__";
70
+ var MODEL_ROUTER_OPTIONS_WATERMARK = "__model_router_options__";
71
+ var ROUTER_MODEL = "__router_model__";
72
+ var ROUTER_OPTIONS = "__router_options__";
73
+ var ARGS_METADATA = "__args_metadata__";
74
+ var OPTIONS_METADATA = "__opts_metadata__";
75
+ var GLOBAL_PERMISSIONS_WATERMARK = "__global_permissions__";
76
+ var DOC_PERMISSIONS_WATERMARK = "__doc_permissions__";
77
+ var ROUTE_GUARD_WATERMARK = "__route_guard__";
78
+ var BASE_FILTER_WATERMARK = "__base_filter__";
79
+ var VALIDATE_WATERMARK = "__validate__";
80
+ var PREPARE_WATERMARK = "__prepare__";
81
+ var TRANSFORM_WATERMARK = "__transform__";
82
+ var DECORATE_WATERMARK = "__decorate__";
83
+ var DECORATE_ALL_WATERMARK = "__decorate_all__";
84
+ var IDENTIFIER_WATERMARK = "__identifier__";
85
+ var OVERRIDE_FILTER_WATERMARK = "__override_filter__";
86
+ var AFTER_PERSIST_WATERMARK = "__after_persist__";
87
+ var BEFORE_DELETE_WATERMARK = "__before_delete__";
88
+ var AFTER_DELETE_WATERMARK = "__after_delete__";
89
+ var GLOBAL_PERMISSIONS_ARGS = [0 /* REQUEST */];
90
+ var DOC_PERMISSIONS_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
91
+ var ROUTE_GUARD_ARGS = [3 /* PERMISSIONS */];
92
+ var BASE_FILTER_ARGS = [3 /* PERMISSIONS */];
93
+ var VALIDATE_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
94
+ var PREPARE_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
95
+ var TRANSFORM_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
96
+ var DECORATE_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
97
+ var DECORATE_ALL_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
98
+ var OVERRIDE_FILTER_ARGS = [3 /* PERMISSIONS */];
99
+ var AFTER_PERSIST_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
100
+ var BEFORE_DELETE_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
101
+ var AFTER_DELETE_ARGS = [1 /* DOCUMENT */, 3 /* PERMISSIONS */, 2 /* CONTEXT */];
102
+ var IDENTIFIER_ARGS = [];
103
+ var ARGS = {
104
+ globalPermissions: GLOBAL_PERMISSIONS_ARGS,
105
+ docPermissions: DOC_PERMISSIONS_ARGS,
106
+ routeGuard: ROUTE_GUARD_ARGS,
107
+ baseFilter: BASE_FILTER_ARGS,
108
+ overrideFilter: OVERRIDE_FILTER_ARGS,
109
+ validate: VALIDATE_ARGS,
110
+ prepare: PREPARE_ARGS,
111
+ transform: TRANSFORM_ARGS,
112
+ afterPersist: AFTER_PERSIST_ARGS,
113
+ decorate: DECORATE_ARGS,
114
+ decorateAll: DECORATE_ALL_ARGS,
115
+ beforeDelete: BEFORE_DELETE_ARGS,
116
+ afterDelete: AFTER_DELETE_ARGS,
117
+ identifier: IDENTIFIER_ARGS
118
+ };
119
+
120
+ // src/metadata.ts
121
+ var isConstructor = (prop) => prop === "constructor";
122
+ var isFunction = (value) => typeof value === "function";
123
+ var getMetadata = (obj, key) => {
124
+ return Reflect.getMetadata(key, obj) ?? null;
125
+ };
126
+ var getMetadataKeysStartWith = (obj, startKey) => {
127
+ return Reflect.getMetadataKeys(obj).filter((key) => key.startsWith(startKey));
128
+ };
129
+ var getMethodDescriptor = (obj, method) => {
130
+ let current = obj;
131
+ do {
132
+ const descriptor = Reflect.getOwnPropertyDescriptor(current, method);
133
+ if (descriptor) return descriptor;
134
+ } while ((current = Reflect.getPrototypeOf(current)) && current !== Object.prototype);
135
+ return void 0;
136
+ };
137
+ var getMethodMetadata = (obj, method, key) => {
138
+ const descriptor = getMethodDescriptor(obj, method);
139
+ return descriptor ? getMetadata(descriptor.value, key) : null;
140
+ };
141
+ var getMethodMetadataKeysStartWith = (obj, method, startKey) => {
142
+ const descriptor = getMethodDescriptor(obj, method);
143
+ return descriptor ? getMetadataKeysStartWith(descriptor.value, startKey) : [];
144
+ };
145
+ function* getAllMethodNames(obj) {
146
+ const seen = /* @__PURE__ */ new Set();
147
+ let current = obj;
148
+ const isMethod = (prop) => {
149
+ if (seen.has(prop)) return false;
150
+ const descriptor = Object.getOwnPropertyDescriptor(current, prop);
151
+ if (descriptor?.set || descriptor?.get) return false;
152
+ return !isConstructor(prop) && isFunction(current[prop]);
153
+ };
154
+ do {
155
+ for (const name of Object.getOwnPropertyNames(current).filter(isMethod)) {
156
+ seen.add(name);
157
+ yield name;
158
+ }
159
+ } while ((current = Reflect.getPrototypeOf(current)) && current !== Object.prototype);
160
+ }
161
+ var isRootRouter = (obj) => !!getMetadata(obj, ROOT_ROUTER_WATERMARK);
162
+ var isModelRouter = (obj) => !!getMetadata(obj, ROUTER_WATERMARK);
163
+ var isDefaultModelRouterOptions = (obj) => !!getMetadata(obj, DEFAULT_MODEL_ROUTER_OPTIONS_WATERMARK);
164
+ var isModelRouterOptions = (obj) => !!getMetadata(obj, MODEL_ROUTER_OPTIONS_WATERMARK);
165
+ var isGlobalPermissionsMethod = (obj, method) => !!getMethodMetadata(obj, method, GLOBAL_PERMISSIONS_WATERMARK);
166
+ var isDocPermissionsMethod = (obj, method) => !!getMethodMetadata(obj, method, DOC_PERMISSIONS_WATERMARK);
167
+ var isBaseFilterMethod = (obj, method) => !!getMethodMetadata(obj, method, BASE_FILTER_WATERMARK);
168
+ var isOverrideFilterMethod = (obj, method) => !!getMethodMetadata(obj, method, OVERRIDE_FILTER_WATERMARK);
169
+ var isValidateMethod = (obj, method) => !!getMethodMetadata(obj, method, VALIDATE_WATERMARK);
170
+ var isPrepareMethod = (obj, method) => !!getMethodMetadata(obj, method, PREPARE_WATERMARK);
171
+ var isTransformMethod = (obj, method) => !!getMethodMetadata(obj, method, TRANSFORM_WATERMARK);
172
+ var isAfterPersistMethod = (obj, method) => !!getMethodMetadata(obj, method, AFTER_PERSIST_WATERMARK);
173
+ var isDecorateMethod = (obj, method) => !!getMethodMetadata(obj, method, DECORATE_WATERMARK);
174
+ var isDecorateAllMethod = (obj, method) => !!getMethodMetadata(obj, method, DECORATE_ALL_WATERMARK);
175
+ var isRouteGuardMethod = (obj, method) => !!getMethodMetadata(obj, method, ROUTE_GUARD_WATERMARK);
176
+ var isIdentifierMethod = (obj, method) => !!getMethodMetadata(obj, method, IDENTIFIER_WATERMARK);
177
+ var isBeforeDeleteMethod = (obj, method) => !!getMethodMetadata(obj, method, BEFORE_DELETE_WATERMARK);
178
+ var isAfterDeleteMethod = (obj, method) => !!getMethodMetadata(obj, method, AFTER_DELETE_WATERMARK);
179
+
180
+ // src/factory.ts
181
+ var toArray = (value) => Array.isArray(value) ? value : [value];
182
+ var compact = (arr) => arr.filter((x) => x != null);
183
+ var HOOK_CONFIG = [
184
+ { check: isDocPermissionsMethod, optionKey: "docPermissions", aclKey: "docPermissions", array: false },
185
+ { check: isBaseFilterMethod, optionKey: "baseFilter", aclKey: "baseFilter", array: false },
186
+ { check: isOverrideFilterMethod, optionKey: "overrideFilter", aclKey: "overrideFilter", array: false },
187
+ { check: isValidateMethod, optionKey: "validate", aclKey: "validate", array: true },
188
+ { check: isPrepareMethod, optionKey: "prepare", aclKey: "prepare", array: true },
189
+ { check: isTransformMethod, optionKey: "transform", aclKey: "transform", array: true },
190
+ { check: isAfterPersistMethod, optionKey: "afterPersist", aclKey: "afterPersist", array: true },
191
+ { check: isDecorateMethod, optionKey: "decorate", aclKey: "decorate", array: true },
192
+ { check: isDecorateAllMethod, optionKey: "decorateAll", aclKey: "decorateAll", array: true },
193
+ { check: isRouteGuardMethod, optionKey: "routeGuard", aclKey: "operationAccess", array: false },
194
+ { check: isIdentifierMethod, optionKey: "identifier", aclKey: "resolveIdFilter", array: false },
195
+ { check: isBeforeDeleteMethod, optionKey: "beforeDelete", aclKey: "beforeDelete", array: false },
196
+ { check: isAfterDeleteMethod, optionKey: "afterDelete", aclKey: "afterDelete", array: false }
197
+ ];
198
+ var EgoseFactoryStatic = class _EgoseFactoryStatic {
199
+ static create() {
200
+ return new _EgoseFactoryStatic();
201
+ }
202
+ constructor() {
203
+ }
204
+ bootstrap(module2, expressApp) {
205
+ this._expressApp = expressApp;
206
+ const routers = getMetadata(module2, MODULE_ROUTERS) || [];
207
+ const routerOptions = getMetadata(module2, MODULE_ROUTER_OPTIONS) || [];
208
+ const globalOptions = getMetadata(module2, MODULE_OPTIONS) || {};
209
+ import_access_router.default.setGlobalOptions(globalOptions);
210
+ this.bootstrapEgose(module2);
211
+ const expressRouter = import_express.default.Router();
212
+ const basePath = globalOptions.basePath || "/";
213
+ for (let x = 0; x < routers.length; x++) {
214
+ const router = routers[x];
215
+ if (isRootRouter(router)) this.bootstrapRootRouter(router, expressRouter);
216
+ else if (isModelRouter(router)) this.bootstrapModelRouter(router, expressRouter);
217
+ }
218
+ for (let x = 0; x < routerOptions.length; x++) {
219
+ const routerOption = routerOptions[x];
220
+ if (isDefaultModelRouterOptions(routerOption)) this.setDefaultModelRouterOptions(routerOption);
221
+ else if (isModelRouterOptions(routerOption)) this.setModelRouterOptions(routerOption);
222
+ }
223
+ this._expressApp.use(basePath, expressRouter);
224
+ if (globalOptions.handleErrors) {
225
+ this._expressApp.use((req, res, next) => {
226
+ next(new Error("Not Found"));
227
+ });
228
+ this._expressApp.use((err, req, res, next) => {
229
+ res.status(err.status || 500);
230
+ res.json({ message: err.message, error: err });
231
+ });
232
+ }
233
+ }
234
+ bootstrapEgose(module2) {
235
+ const moduleInstance = new module2();
236
+ this.registerPropertyOptions(moduleInstance, (key, val) => import_access_router.default.setGlobalOption(key, val));
237
+ const methodNames = new Set(getAllMethodNames(module2.prototype));
238
+ for (const methodName of methodNames) {
239
+ if (isGlobalPermissionsMethod(moduleInstance, methodName)) {
240
+ this.registerMethodHookGlobal(moduleInstance, methodName, "globalPermissions", "globalPermissions", false);
241
+ }
242
+ }
243
+ this._expressApp.use((0, import_access_router.default)());
244
+ }
245
+ bootstrapRootRouter(router, expressRouter) {
246
+ const options = getMetadata(router, ROUTER_OPTIONS);
247
+ const rootRouter = import_access_router.default.createRouter(options);
248
+ expressRouter.use(rootRouter.routes);
249
+ }
250
+ bootstrapModelRouter(DecoRouter, expressRouter) {
251
+ const modelName = getMetadata(DecoRouter, ROUTER_MODEL);
252
+ const options = getMetadata(DecoRouter, ROUTER_OPTIONS);
253
+ const modelRouter = import_access_router.default.createRouter(modelName, options);
254
+ const instance = new DecoRouter();
255
+ this.registerPropertyOptions(instance, (key, val) => import_access_router.default.setModelOption(modelName, key, val));
256
+ this.registerMethodOptions(
257
+ instance,
258
+ DecoRouter.prototype,
259
+ (key, val) => import_access_router.default.setModelOption(modelName, key, val),
260
+ (key) => import_access_router.default.getModelOption(modelName, key)
261
+ );
262
+ expressRouter.use(modelRouter.routes);
263
+ }
264
+ setDefaultModelRouterOptions(DecoRouterOptions) {
265
+ const options = getMetadata(DecoRouterOptions, ROUTER_OPTIONS);
266
+ import_access_router.default.setDefaultModelOptions(options);
267
+ const instance = new DecoRouterOptions();
268
+ this.registerPropertyOptions(instance, (key, val) => import_access_router.default.setDefaultModelOption(key, val));
269
+ this.registerMethodOptions(
270
+ instance,
271
+ DecoRouterOptions.prototype,
272
+ (key, val) => import_access_router.default.setDefaultModelOption(key, val),
273
+ (key) => import_access_router.default.getDefaultModelOption(key),
274
+ [{ check: isRouteGuardMethod, optionKey: "routeGuard", aclKey: "operationAccess", array: false }]
275
+ );
276
+ }
277
+ setModelRouterOptions(DecoRouterOptions) {
278
+ const modelName = getMetadata(DecoRouterOptions, ROUTER_MODEL);
279
+ const options = getMetadata(DecoRouterOptions, ROUTER_OPTIONS);
280
+ import_access_router.default.setModelOptions(modelName, options);
281
+ const instance = new DecoRouterOptions();
282
+ this.registerPropertyOptions(instance, (key, val) => import_access_router.default.setModelOption(modelName, key, val));
283
+ this.registerMethodOptions(
284
+ instance,
285
+ DecoRouterOptions.prototype,
286
+ (key, val) => import_access_router.default.setModelOption(modelName, key, val),
287
+ (key) => import_access_router.default.getModelOption(modelName, key)
288
+ );
289
+ }
290
+ registerPropertyOptions(instance, setOption) {
291
+ const optionProps = getMetadata(instance, OPTIONS_METADATA) || [];
292
+ for (let x = 0; x < optionProps.length; x++) {
293
+ const optionProp = optionProps[x];
294
+ const value = instance[optionProp.propertyKey];
295
+ setOption(optionProp.optionKey, value);
296
+ }
297
+ }
298
+ registerMethodOptions(instance, prototype, setOption, getOption, filter) {
299
+ const methodNames = new Set(getAllMethodNames(prototype));
300
+ const hooks = filter || HOOK_CONFIG;
301
+ for (const methodName of methodNames) {
302
+ for (const hook of hooks) {
303
+ if (hook.check(instance, methodName)) {
304
+ this.registerMethodHookOnAcl(
305
+ instance,
306
+ methodName,
307
+ hook.optionKey,
308
+ hook.aclKey,
309
+ hook.array,
310
+ setOption,
311
+ getOption
312
+ );
313
+ break;
314
+ }
315
+ }
316
+ }
317
+ }
318
+ registerMethodHookGlobal(routerOrOptions, methodName, optionKey, aclKey, arrayType) {
319
+ const fn = this.wrapMethod(routerOrOptions, methodName, optionKey);
320
+ if (!fn) return;
321
+ if (arrayType) {
322
+ const curr = toArray(compact([import_access_router.default.getGlobalOption(aclKey)]));
323
+ import_access_router.default.setGlobalOption(aclKey, [...curr, fn]);
324
+ } else {
325
+ import_access_router.default.setGlobalOption(aclKey, fn);
326
+ }
327
+ }
328
+ registerMethodHookOnAcl(routerOrOptions, methodName, optionKey, aclKey, arrayType, setOption, getOption) {
329
+ const keys = getMethodMetadataKeysStartWith(routerOrOptions, methodName, optionKey);
330
+ for (let x = 0; x < keys.length; x++) {
331
+ const key = keys[x];
332
+ const val = getMethodMetadata(routerOrOptions, methodName, key);
333
+ if (val !== true) continue;
334
+ const fn = this.wrapMethod(routerOrOptions, methodName, optionKey);
335
+ if (!fn) continue;
336
+ const aclOptionKey = optionKey === aclKey ? key : key.replace(optionKey, aclKey);
337
+ if (arrayType) {
338
+ const curr = toArray(compact([getOption(aclOptionKey)]));
339
+ setOption(aclOptionKey, [...curr, fn]);
340
+ } else {
341
+ setOption(aclOptionKey, fn);
342
+ }
343
+ }
344
+ }
345
+ wrapMethod(target, methodName, optionKey) {
346
+ const dtor = getMethodDescriptor(target, methodName);
347
+ if (!dtor || typeof dtor.value !== "function") return null;
348
+ const arglist = ARGS[optionKey] || [];
349
+ const metalist = Reflect.getMetadata(ARGS_METADATA, target.constructor, methodName) || [];
350
+ return function(...args) {
351
+ const ordered = metalist.slice().sort((a, b) => a.index - b.index).map((meta) => {
352
+ if (meta.type === 0 /* REQUEST */) return this;
353
+ const index = arglist.findIndex((v) => v === meta.type);
354
+ return args[index];
355
+ });
356
+ return dtor.value.call(target, ...ordered);
357
+ };
358
+ }
359
+ };
360
+ var EgoseFactory = EgoseFactoryStatic.create();
361
+
362
+ // src/decorators/method.decorators.ts
363
+ var import_reflect_metadata = require("reflect-metadata");
364
+ var setMethodMetadata = (watermark, parentOptionKey, optionKey) => {
365
+ return (target, key, descriptor) => {
366
+ Reflect.defineMetadata(watermark, true, descriptor.value);
367
+ const compositeKey = optionKey ? `${parentOptionKey}.${optionKey}` : parentOptionKey;
368
+ Reflect.defineMetadata(compositeKey, true, descriptor.value);
369
+ return descriptor;
370
+ };
371
+ };
372
+ function GlobalPermissions() {
373
+ return setMethodMetadata(GLOBAL_PERMISSIONS_WATERMARK, "globalPermissions");
374
+ }
375
+ function DocPermissions(optionKey) {
376
+ return setMethodMetadata(DOC_PERMISSIONS_WATERMARK, "docPermissions", optionKey);
377
+ }
378
+ function BaseFilter(optionKey) {
379
+ return setMethodMetadata(BASE_FILTER_WATERMARK, "baseFilter", optionKey);
380
+ }
381
+ function OverrideFilter(optionKey) {
382
+ return setMethodMetadata(OVERRIDE_FILTER_WATERMARK, "overrideFilter", optionKey);
383
+ }
384
+ function Validate(optionKey) {
385
+ return setMethodMetadata(VALIDATE_WATERMARK, "validate", optionKey);
386
+ }
387
+ function Prepare(optionKey) {
388
+ return setMethodMetadata(PREPARE_WATERMARK, "prepare", optionKey);
389
+ }
390
+ function Transform(optionKey) {
391
+ return setMethodMetadata(TRANSFORM_WATERMARK, "transform", optionKey);
392
+ }
393
+ function AfterPersist(optionKey) {
394
+ return setMethodMetadata(AFTER_PERSIST_WATERMARK, "afterPersist", optionKey);
395
+ }
396
+ function Decorate(optionKey) {
397
+ return setMethodMetadata(DECORATE_WATERMARK, "decorate", optionKey);
398
+ }
399
+ function DecorateAll(optionKey) {
400
+ return setMethodMetadata(DECORATE_ALL_WATERMARK, "decorateAll", optionKey);
401
+ }
402
+ function RouteGuard(optionKey) {
403
+ return setMethodMetadata(ROUTE_GUARD_WATERMARK, "routeGuard", optionKey);
404
+ }
405
+ function Identifier() {
406
+ return setMethodMetadata(IDENTIFIER_WATERMARK, "identifier");
407
+ }
408
+ function BeforeDelete() {
409
+ return setMethodMetadata(BEFORE_DELETE_WATERMARK, "beforeDelete");
410
+ }
411
+ function AfterDelete() {
412
+ return setMethodMetadata(AFTER_DELETE_WATERMARK, "afterDelete");
413
+ }
414
+
415
+ // src/decorators/property.decorators.ts
416
+ var import_reflect_metadata2 = require("reflect-metadata");
417
+ function Option(optionKey) {
418
+ return (target, propertyKey) => {
419
+ const opts = Reflect.getMetadata(OPTIONS_METADATA, target) || [];
420
+ Reflect.defineMetadata(OPTIONS_METADATA, opts.concat({ optionKey: optionKey || propertyKey, propertyKey }), target);
421
+ };
422
+ }
423
+
424
+ // src/decorators/parameter.decorators.ts
425
+ var import_reflect_metadata3 = require("reflect-metadata");
426
+ var mergeHookParams = (target, key, index, type) => {
427
+ const args = Reflect.getMetadata(ARGS_METADATA, target.constructor, key) || [];
428
+ Reflect.defineMetadata(ARGS_METADATA, args.concat({ index, type }), target.constructor, key);
429
+ };
430
+ function Request() {
431
+ return (target, key, index) => mergeHookParams(target, key, index, 0 /* REQUEST */);
432
+ }
433
+ function Document() {
434
+ return (target, key, index) => mergeHookParams(target, key, index, 1 /* DOCUMENT */);
435
+ }
436
+ function Permissions() {
437
+ return (target, key, index) => mergeHookParams(target, key, index, 3 /* PERMISSIONS */);
438
+ }
439
+ function Context() {
440
+ return (target, key, index) => mergeHookParams(target, key, index, 2 /* CONTEXT */);
441
+ }
442
+
443
+ // src/decorators/class.decorators.ts
444
+ var import_reflect_metadata4 = require("reflect-metadata");
445
+ function Module(metadata) {
446
+ return (target) => {
447
+ for (const property in metadata) {
448
+ if (Object.prototype.hasOwnProperty.call(metadata, property)) {
449
+ Reflect.defineMetadata(property, metadata[property], target);
450
+ }
451
+ }
452
+ };
453
+ }
454
+ function createRootRouter(options) {
455
+ return (target) => {
456
+ Reflect.defineMetadata(ROOT_ROUTER_WATERMARK, true, target);
457
+ Reflect.defineMetadata(ROUTER_OPTIONS, options || {}, target);
458
+ };
459
+ }
460
+ function createModelRouter(modelName, options) {
461
+ return (target) => {
462
+ Reflect.defineMetadata(ROUTER_WATERMARK, true, target);
463
+ Reflect.defineMetadata(ROUTER_MODEL, modelName, target);
464
+ Reflect.defineMetadata(ROUTER_OPTIONS, options || {}, target);
465
+ };
466
+ }
467
+ var Router2 = function Router3(modelNameOrOptions, options) {
468
+ if (typeof modelNameOrOptions === "string") {
469
+ return createModelRouter(modelNameOrOptions, options);
470
+ }
471
+ if (modelNameOrOptions !== null && typeof modelNameOrOptions === "object") {
472
+ return createRootRouter(modelNameOrOptions);
473
+ }
474
+ throw new TypeError("Router() expects a model name string or a RootRouterOptions object");
475
+ };
476
+ function createDefaultModelRouterOptions(options) {
477
+ return (target) => {
478
+ Reflect.defineMetadata(DEFAULT_MODEL_ROUTER_OPTIONS_WATERMARK, true, target);
479
+ Reflect.defineMetadata(ROUTER_OPTIONS, options || {}, target);
480
+ };
481
+ }
482
+ function createModelRouterOptions(modelName, options) {
483
+ return (target) => {
484
+ Reflect.defineMetadata(MODEL_ROUTER_OPTIONS_WATERMARK, true, target);
485
+ Reflect.defineMetadata(ROUTER_MODEL, modelName, target);
486
+ Reflect.defineMetadata(ROUTER_OPTIONS, options || {}, target);
487
+ };
488
+ }
489
+ var RouterOptions = function RouterOptions2(modelNameOrOptions, options) {
490
+ if (typeof modelNameOrOptions === "string") {
491
+ return createModelRouterOptions(modelNameOrOptions, options);
492
+ }
493
+ if (modelNameOrOptions !== null && typeof modelNameOrOptions === "object") {
494
+ return createDefaultModelRouterOptions(modelNameOrOptions);
495
+ }
496
+ throw new TypeError("RouterOptions() expects a model name string or a DefaultModelRouterOptions object");
497
+ };
498
+ // Annotate the CommonJS export names for ESM import in node:
499
+ 0 && (module.exports = {
500
+ AfterDelete,
501
+ AfterPersist,
502
+ BaseFilter,
503
+ BeforeDelete,
504
+ Context,
505
+ Decorate,
506
+ DecorateAll,
507
+ DocPermissions,
508
+ Document,
509
+ EgoseFactory,
510
+ EgoseFactoryStatic,
511
+ GlobalPermissions,
512
+ Identifier,
513
+ Module,
514
+ Option,
515
+ OverrideFilter,
516
+ Permissions,
517
+ Prepare,
518
+ Request,
519
+ RouteGuard,
520
+ Router,
521
+ RouterOptions,
522
+ Transform,
523
+ Validate
524
+ });