@catbee/utils 1.1.0 → 2.0.0-next.1
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/LICENSE +1 -1
- package/README.md +79 -43
- package/array/index.cjs +355 -0
- package/array/index.d.ts +317 -0
- package/array/index.mjs +327 -0
- package/async/index.cjs +484 -0
- package/async/index.d.ts +299 -0
- package/async/index.mjs +463 -0
- package/cache/index.cjs +292 -0
- package/cache/index.d.ts +179 -0
- package/cache/index.mjs +290 -0
- package/config/index.cjs +150 -0
- package/config/index.d.ts +88 -0
- package/config/index.mjs +143 -0
- package/context-store/index.cjs +267 -0
- package/context-store/index.d.ts +216 -0
- package/context-store/index.mjs +261 -0
- package/crypto/index.cjs +182 -0
- package/crypto/index.d.ts +187 -0
- package/crypto/index.mjs +166 -0
- package/date/index.cjs +340 -0
- package/date/index.d.ts +214 -0
- package/date/index.mjs +326 -0
- package/decorators/index.cjs +2051 -0
- package/decorators/index.d.ts +708 -0
- package/decorators/index.mjs +2010 -0
- package/dir/index.cjs +417 -0
- package/dir/index.d.ts +219 -0
- package/dir/index.mjs +390 -0
- package/env/index.cjs +745 -0
- package/env/index.d.ts +403 -0
- package/env/index.mjs +742 -0
- package/exception/index.cjs +362 -0
- package/exception/index.d.ts +256 -0
- package/exception/index.mjs +338 -0
- package/fs/index.cjs +287 -0
- package/fs/index.d.ts +229 -0
- package/fs/index.mjs +258 -0
- package/http-status-codes/index.cjs +96 -0
- package/http-status-codes/index.d.ts +291 -0
- package/http-status-codes/index.mjs +94 -0
- package/id/index.cjs +62 -0
- package/id/index.d.ts +61 -0
- package/id/index.mjs +56 -0
- package/index.cjs +218 -0
- package/index.d.ts +51 -0
- package/index.mjs +51 -0
- package/logger/index.cjs +334 -0
- package/logger/index.d.ts +213 -0
- package/logger/index.mjs +313 -0
- package/middleware/index.cjs +177 -0
- package/middleware/index.d.ts +127 -0
- package/middleware/index.mjs +170 -0
- package/obj/index.cjs +305 -0
- package/obj/index.d.ts +160 -0
- package/obj/index.mjs +289 -0
- package/package.json +172 -20
- package/performance/index.cjs +231 -0
- package/performance/index.d.ts +162 -0
- package/performance/index.mjs +225 -0
- package/request/index.cjs +202 -0
- package/request/index.d.ts +265 -0
- package/request/index.mjs +194 -0
- package/response/index.cjs +234 -0
- package/response/index.d.ts +342 -0
- package/response/index.mjs +222 -0
- package/server/index.cjs +1631 -0
- package/server/index.d.ts +809 -0
- package/server/index.mjs +1622 -0
- package/stream/index.cjs +151 -0
- package/stream/index.d.ts +114 -0
- package/stream/index.mjs +144 -0
- package/string/index.cjs +109 -0
- package/string/index.d.ts +126 -0
- package/string/index.mjs +95 -0
- package/type/index.cjs +129 -0
- package/type/index.d.ts +131 -0
- package/type/index.mjs +119 -0
- package/types/index.cjs +34 -0
- package/types/index.d.ts +798 -0
- package/types/index.mjs +32 -0
- package/url/index.cjs +199 -0
- package/url/index.d.ts +166 -0
- package/url/index.mjs +187 -0
- package/validation/index.cjs +259 -0
- package/validation/index.d.ts +209 -0
- package/validation/index.mjs +231 -0
- package/build/index.cjs +0 -7694
- package/build/index.d.ts +0 -5792
- package/build/index.mjs +0 -7386
|
@@ -0,0 +1,2010 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { getLogger } from '@catbee/utils/logger';
|
|
26
|
+
import { createFinalErrorResponse } from '@catbee/utils/response';
|
|
27
|
+
import { HttpStatusCodes } from '@catbee/utils/http-status-codes';
|
|
28
|
+
import { TTLCache } from '@catbee/utils/cache';
|
|
29
|
+
import { BadRequestException } from '@catbee/utils/exception';
|
|
30
|
+
import { optionalRequire } from '@catbee/utils/async';
|
|
31
|
+
import { DependencyErrors } from '@catbee/utils/server';
|
|
32
|
+
|
|
33
|
+
var __create = Object.create;
|
|
34
|
+
var __defProp = Object.defineProperty;
|
|
35
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
36
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
37
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
38
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
39
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
40
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
41
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
42
|
+
};
|
|
43
|
+
var __copyProps = (to, from, except, desc) => {
|
|
44
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
45
|
+
for (let key of __getOwnPropNames(from))
|
|
46
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
47
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
48
|
+
}
|
|
49
|
+
return to;
|
|
50
|
+
};
|
|
51
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
52
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
53
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
54
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
55
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
56
|
+
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
57
|
+
mod
|
|
58
|
+
));
|
|
59
|
+
|
|
60
|
+
// node_modules/reflect-metadata/Reflect.js
|
|
61
|
+
var require_Reflect = __commonJS({
|
|
62
|
+
"node_modules/reflect-metadata/Reflect.js"() {
|
|
63
|
+
var Reflect2;
|
|
64
|
+
(function(Reflect3) {
|
|
65
|
+
(function(factory) {
|
|
66
|
+
var root = typeof globalThis === "object" ? globalThis : typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : sloppyModeThis();
|
|
67
|
+
var exporter = makeExporter(Reflect3);
|
|
68
|
+
if (typeof root.Reflect !== "undefined") {
|
|
69
|
+
exporter = makeExporter(root.Reflect, exporter);
|
|
70
|
+
}
|
|
71
|
+
factory(exporter, root);
|
|
72
|
+
if (typeof root.Reflect === "undefined") {
|
|
73
|
+
root.Reflect = Reflect3;
|
|
74
|
+
}
|
|
75
|
+
function makeExporter(target, previous) {
|
|
76
|
+
return function(key, value) {
|
|
77
|
+
Object.defineProperty(target, key, {
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value
|
|
81
|
+
});
|
|
82
|
+
if (previous) previous(key, value);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
__name(makeExporter, "makeExporter");
|
|
86
|
+
function functionThis() {
|
|
87
|
+
try {
|
|
88
|
+
return Function("return this;")();
|
|
89
|
+
} catch (_) {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
__name(functionThis, "functionThis");
|
|
93
|
+
function indirectEvalThis() {
|
|
94
|
+
try {
|
|
95
|
+
return (0, eval)("(function() { return this; })()");
|
|
96
|
+
} catch (_) {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
__name(indirectEvalThis, "indirectEvalThis");
|
|
100
|
+
function sloppyModeThis() {
|
|
101
|
+
return functionThis() || indirectEvalThis();
|
|
102
|
+
}
|
|
103
|
+
__name(sloppyModeThis, "sloppyModeThis");
|
|
104
|
+
})(function(exporter, root) {
|
|
105
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
106
|
+
var supportsSymbol = typeof Symbol === "function";
|
|
107
|
+
var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
|
|
108
|
+
var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
|
|
109
|
+
var supportsCreate = typeof Object.create === "function";
|
|
110
|
+
var supportsProto = {
|
|
111
|
+
__proto__: []
|
|
112
|
+
} instanceof Array;
|
|
113
|
+
var downLevel = !supportsCreate && !supportsProto;
|
|
114
|
+
var HashMap = {
|
|
115
|
+
// create an object in dictionary mode (a.k.a. "slow" mode in v8)
|
|
116
|
+
create: supportsCreate ? function() {
|
|
117
|
+
return MakeDictionary(/* @__PURE__ */ Object.create(null));
|
|
118
|
+
} : supportsProto ? function() {
|
|
119
|
+
return MakeDictionary({
|
|
120
|
+
__proto__: null
|
|
121
|
+
});
|
|
122
|
+
} : function() {
|
|
123
|
+
return MakeDictionary({});
|
|
124
|
+
},
|
|
125
|
+
has: downLevel ? function(map, key) {
|
|
126
|
+
return hasOwn.call(map, key);
|
|
127
|
+
} : function(map, key) {
|
|
128
|
+
return key in map;
|
|
129
|
+
},
|
|
130
|
+
get: downLevel ? function(map, key) {
|
|
131
|
+
return hasOwn.call(map, key) ? map[key] : void 0;
|
|
132
|
+
} : function(map, key) {
|
|
133
|
+
return map[key];
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var functionPrototype = Object.getPrototypeOf(Function);
|
|
137
|
+
var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
|
|
138
|
+
var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
|
|
139
|
+
var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
|
|
140
|
+
var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : void 0;
|
|
141
|
+
var metadataRegistry = GetOrCreateMetadataRegistry();
|
|
142
|
+
var metadataProvider = CreateMetadataProvider(metadataRegistry);
|
|
143
|
+
function decorate(decorators, target, propertyKey, attributes) {
|
|
144
|
+
if (!IsUndefined(propertyKey)) {
|
|
145
|
+
if (!IsArray(decorators)) throw new TypeError();
|
|
146
|
+
if (!IsObject(target)) throw new TypeError();
|
|
147
|
+
if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes)) throw new TypeError();
|
|
148
|
+
if (IsNull(attributes)) attributes = void 0;
|
|
149
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
150
|
+
return DecorateProperty(decorators, target, propertyKey, attributes);
|
|
151
|
+
} else {
|
|
152
|
+
if (!IsArray(decorators)) throw new TypeError();
|
|
153
|
+
if (!IsConstructor(target)) throw new TypeError();
|
|
154
|
+
return DecorateConstructor(decorators, target);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
__name(decorate, "decorate");
|
|
158
|
+
exporter("decorate", decorate);
|
|
159
|
+
function metadata(metadataKey, metadataValue) {
|
|
160
|
+
function decorator(target, propertyKey) {
|
|
161
|
+
if (!IsObject(target)) throw new TypeError();
|
|
162
|
+
if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey)) throw new TypeError();
|
|
163
|
+
OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
164
|
+
}
|
|
165
|
+
__name(decorator, "decorator");
|
|
166
|
+
return decorator;
|
|
167
|
+
}
|
|
168
|
+
__name(metadata, "metadata");
|
|
169
|
+
exporter("metadata", metadata);
|
|
170
|
+
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
|
|
171
|
+
if (!IsObject(target)) throw new TypeError();
|
|
172
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
173
|
+
return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
174
|
+
}
|
|
175
|
+
__name(defineMetadata, "defineMetadata");
|
|
176
|
+
exporter("defineMetadata", defineMetadata);
|
|
177
|
+
function hasMetadata(metadataKey, target, propertyKey) {
|
|
178
|
+
if (!IsObject(target)) throw new TypeError();
|
|
179
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
180
|
+
return OrdinaryHasMetadata(metadataKey, target, propertyKey);
|
|
181
|
+
}
|
|
182
|
+
__name(hasMetadata, "hasMetadata");
|
|
183
|
+
exporter("hasMetadata", hasMetadata);
|
|
184
|
+
function hasOwnMetadata(metadataKey, target, propertyKey) {
|
|
185
|
+
if (!IsObject(target)) throw new TypeError();
|
|
186
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
187
|
+
return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
|
|
188
|
+
}
|
|
189
|
+
__name(hasOwnMetadata, "hasOwnMetadata");
|
|
190
|
+
exporter("hasOwnMetadata", hasOwnMetadata);
|
|
191
|
+
function getMetadata(metadataKey, target, propertyKey) {
|
|
192
|
+
if (!IsObject(target)) throw new TypeError();
|
|
193
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
194
|
+
return OrdinaryGetMetadata(metadataKey, target, propertyKey);
|
|
195
|
+
}
|
|
196
|
+
__name(getMetadata, "getMetadata");
|
|
197
|
+
exporter("getMetadata", getMetadata);
|
|
198
|
+
function getOwnMetadata(metadataKey, target, propertyKey) {
|
|
199
|
+
if (!IsObject(target)) throw new TypeError();
|
|
200
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
201
|
+
return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
|
|
202
|
+
}
|
|
203
|
+
__name(getOwnMetadata, "getOwnMetadata");
|
|
204
|
+
exporter("getOwnMetadata", getOwnMetadata);
|
|
205
|
+
function getMetadataKeys(target, propertyKey) {
|
|
206
|
+
if (!IsObject(target)) throw new TypeError();
|
|
207
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
208
|
+
return OrdinaryMetadataKeys(target, propertyKey);
|
|
209
|
+
}
|
|
210
|
+
__name(getMetadataKeys, "getMetadataKeys");
|
|
211
|
+
exporter("getMetadataKeys", getMetadataKeys);
|
|
212
|
+
function getOwnMetadataKeys(target, propertyKey) {
|
|
213
|
+
if (!IsObject(target)) throw new TypeError();
|
|
214
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
215
|
+
return OrdinaryOwnMetadataKeys(target, propertyKey);
|
|
216
|
+
}
|
|
217
|
+
__name(getOwnMetadataKeys, "getOwnMetadataKeys");
|
|
218
|
+
exporter("getOwnMetadataKeys", getOwnMetadataKeys);
|
|
219
|
+
function deleteMetadata(metadataKey, target, propertyKey) {
|
|
220
|
+
if (!IsObject(target)) throw new TypeError();
|
|
221
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
222
|
+
if (!IsObject(target)) throw new TypeError();
|
|
223
|
+
if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey);
|
|
224
|
+
var provider = GetMetadataProvider(
|
|
225
|
+
target,
|
|
226
|
+
propertyKey,
|
|
227
|
+
/*Create*/
|
|
228
|
+
false
|
|
229
|
+
);
|
|
230
|
+
if (IsUndefined(provider)) return false;
|
|
231
|
+
return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
|
|
232
|
+
}
|
|
233
|
+
__name(deleteMetadata, "deleteMetadata");
|
|
234
|
+
exporter("deleteMetadata", deleteMetadata);
|
|
235
|
+
function DecorateConstructor(decorators, target) {
|
|
236
|
+
for (var i = decorators.length - 1; i >= 0; --i) {
|
|
237
|
+
var decorator = decorators[i];
|
|
238
|
+
var decorated = decorator(target);
|
|
239
|
+
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
240
|
+
if (!IsConstructor(decorated)) throw new TypeError();
|
|
241
|
+
target = decorated;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return target;
|
|
245
|
+
}
|
|
246
|
+
__name(DecorateConstructor, "DecorateConstructor");
|
|
247
|
+
function DecorateProperty(decorators, target, propertyKey, descriptor) {
|
|
248
|
+
for (var i = decorators.length - 1; i >= 0; --i) {
|
|
249
|
+
var decorator = decorators[i];
|
|
250
|
+
var decorated = decorator(target, propertyKey, descriptor);
|
|
251
|
+
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
252
|
+
if (!IsObject(decorated)) throw new TypeError();
|
|
253
|
+
descriptor = decorated;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return descriptor;
|
|
257
|
+
}
|
|
258
|
+
__name(DecorateProperty, "DecorateProperty");
|
|
259
|
+
function OrdinaryHasMetadata(MetadataKey, O, P) {
|
|
260
|
+
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
261
|
+
if (hasOwn2) return true;
|
|
262
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
263
|
+
if (!IsNull(parent)) return OrdinaryHasMetadata(MetadataKey, parent, P);
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
__name(OrdinaryHasMetadata, "OrdinaryHasMetadata");
|
|
267
|
+
function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
|
|
268
|
+
var provider = GetMetadataProvider(
|
|
269
|
+
O,
|
|
270
|
+
P,
|
|
271
|
+
/*Create*/
|
|
272
|
+
false
|
|
273
|
+
);
|
|
274
|
+
if (IsUndefined(provider)) return false;
|
|
275
|
+
return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
|
|
276
|
+
}
|
|
277
|
+
__name(OrdinaryHasOwnMetadata, "OrdinaryHasOwnMetadata");
|
|
278
|
+
function OrdinaryGetMetadata(MetadataKey, O, P) {
|
|
279
|
+
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
280
|
+
if (hasOwn2) return OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
281
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
282
|
+
if (!IsNull(parent)) return OrdinaryGetMetadata(MetadataKey, parent, P);
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
__name(OrdinaryGetMetadata, "OrdinaryGetMetadata");
|
|
286
|
+
function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
|
|
287
|
+
var provider = GetMetadataProvider(
|
|
288
|
+
O,
|
|
289
|
+
P,
|
|
290
|
+
/*Create*/
|
|
291
|
+
false
|
|
292
|
+
);
|
|
293
|
+
if (IsUndefined(provider)) return;
|
|
294
|
+
return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
295
|
+
}
|
|
296
|
+
__name(OrdinaryGetOwnMetadata, "OrdinaryGetOwnMetadata");
|
|
297
|
+
function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
|
|
298
|
+
var provider = GetMetadataProvider(
|
|
299
|
+
O,
|
|
300
|
+
P,
|
|
301
|
+
/*Create*/
|
|
302
|
+
true
|
|
303
|
+
);
|
|
304
|
+
provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
|
|
305
|
+
}
|
|
306
|
+
__name(OrdinaryDefineOwnMetadata, "OrdinaryDefineOwnMetadata");
|
|
307
|
+
function OrdinaryMetadataKeys(O, P) {
|
|
308
|
+
var ownKeys = OrdinaryOwnMetadataKeys(O, P);
|
|
309
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
310
|
+
if (parent === null) return ownKeys;
|
|
311
|
+
var parentKeys = OrdinaryMetadataKeys(parent, P);
|
|
312
|
+
if (parentKeys.length <= 0) return ownKeys;
|
|
313
|
+
if (ownKeys.length <= 0) return parentKeys;
|
|
314
|
+
var set = new _Set();
|
|
315
|
+
var keys = [];
|
|
316
|
+
for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
|
|
317
|
+
var key = ownKeys_1[_i];
|
|
318
|
+
var hasKey = set.has(key);
|
|
319
|
+
if (!hasKey) {
|
|
320
|
+
set.add(key);
|
|
321
|
+
keys.push(key);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
|
|
325
|
+
var key = parentKeys_1[_a];
|
|
326
|
+
var hasKey = set.has(key);
|
|
327
|
+
if (!hasKey) {
|
|
328
|
+
set.add(key);
|
|
329
|
+
keys.push(key);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return keys;
|
|
333
|
+
}
|
|
334
|
+
__name(OrdinaryMetadataKeys, "OrdinaryMetadataKeys");
|
|
335
|
+
function OrdinaryOwnMetadataKeys(O, P) {
|
|
336
|
+
var provider = GetMetadataProvider(
|
|
337
|
+
O,
|
|
338
|
+
P,
|
|
339
|
+
/*create*/
|
|
340
|
+
false
|
|
341
|
+
);
|
|
342
|
+
if (!provider) {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
return provider.OrdinaryOwnMetadataKeys(O, P);
|
|
346
|
+
}
|
|
347
|
+
__name(OrdinaryOwnMetadataKeys, "OrdinaryOwnMetadataKeys");
|
|
348
|
+
function Type(x) {
|
|
349
|
+
if (x === null) return 1;
|
|
350
|
+
switch (typeof x) {
|
|
351
|
+
case "undefined":
|
|
352
|
+
return 0;
|
|
353
|
+
case "boolean":
|
|
354
|
+
return 2;
|
|
355
|
+
case "string":
|
|
356
|
+
return 3;
|
|
357
|
+
case "symbol":
|
|
358
|
+
return 4;
|
|
359
|
+
case "number":
|
|
360
|
+
return 5;
|
|
361
|
+
case "object":
|
|
362
|
+
return x === null ? 1 : 6;
|
|
363
|
+
default:
|
|
364
|
+
return 6;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
__name(Type, "Type");
|
|
368
|
+
function IsUndefined(x) {
|
|
369
|
+
return x === void 0;
|
|
370
|
+
}
|
|
371
|
+
__name(IsUndefined, "IsUndefined");
|
|
372
|
+
function IsNull(x) {
|
|
373
|
+
return x === null;
|
|
374
|
+
}
|
|
375
|
+
__name(IsNull, "IsNull");
|
|
376
|
+
function IsSymbol(x) {
|
|
377
|
+
return typeof x === "symbol";
|
|
378
|
+
}
|
|
379
|
+
__name(IsSymbol, "IsSymbol");
|
|
380
|
+
function IsObject(x) {
|
|
381
|
+
return typeof x === "object" ? x !== null : typeof x === "function";
|
|
382
|
+
}
|
|
383
|
+
__name(IsObject, "IsObject");
|
|
384
|
+
function ToPrimitive(input, PreferredType) {
|
|
385
|
+
switch (Type(input)) {
|
|
386
|
+
case 0:
|
|
387
|
+
return input;
|
|
388
|
+
case 1:
|
|
389
|
+
return input;
|
|
390
|
+
case 2:
|
|
391
|
+
return input;
|
|
392
|
+
case 3:
|
|
393
|
+
return input;
|
|
394
|
+
case 4:
|
|
395
|
+
return input;
|
|
396
|
+
case 5:
|
|
397
|
+
return input;
|
|
398
|
+
}
|
|
399
|
+
var hint = PreferredType === 3 ? "string" : PreferredType === 5 ? "number" : "default";
|
|
400
|
+
var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
|
|
401
|
+
if (exoticToPrim !== void 0) {
|
|
402
|
+
var result = exoticToPrim.call(input, hint);
|
|
403
|
+
if (IsObject(result)) throw new TypeError();
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
|
|
407
|
+
}
|
|
408
|
+
__name(ToPrimitive, "ToPrimitive");
|
|
409
|
+
function OrdinaryToPrimitive(O, hint) {
|
|
410
|
+
if (hint === "string") {
|
|
411
|
+
var toString_1 = O.toString;
|
|
412
|
+
if (IsCallable(toString_1)) {
|
|
413
|
+
var result = toString_1.call(O);
|
|
414
|
+
if (!IsObject(result)) return result;
|
|
415
|
+
}
|
|
416
|
+
var valueOf = O.valueOf;
|
|
417
|
+
if (IsCallable(valueOf)) {
|
|
418
|
+
var result = valueOf.call(O);
|
|
419
|
+
if (!IsObject(result)) return result;
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
var valueOf = O.valueOf;
|
|
423
|
+
if (IsCallable(valueOf)) {
|
|
424
|
+
var result = valueOf.call(O);
|
|
425
|
+
if (!IsObject(result)) return result;
|
|
426
|
+
}
|
|
427
|
+
var toString_2 = O.toString;
|
|
428
|
+
if (IsCallable(toString_2)) {
|
|
429
|
+
var result = toString_2.call(O);
|
|
430
|
+
if (!IsObject(result)) return result;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
throw new TypeError();
|
|
434
|
+
}
|
|
435
|
+
__name(OrdinaryToPrimitive, "OrdinaryToPrimitive");
|
|
436
|
+
function ToBoolean(argument) {
|
|
437
|
+
return !!argument;
|
|
438
|
+
}
|
|
439
|
+
__name(ToBoolean, "ToBoolean");
|
|
440
|
+
function ToString(argument) {
|
|
441
|
+
return "" + argument;
|
|
442
|
+
}
|
|
443
|
+
__name(ToString, "ToString");
|
|
444
|
+
function ToPropertyKey(argument) {
|
|
445
|
+
var key = ToPrimitive(
|
|
446
|
+
argument,
|
|
447
|
+
3
|
|
448
|
+
/* String */
|
|
449
|
+
);
|
|
450
|
+
if (IsSymbol(key)) return key;
|
|
451
|
+
return ToString(key);
|
|
452
|
+
}
|
|
453
|
+
__name(ToPropertyKey, "ToPropertyKey");
|
|
454
|
+
function IsArray(argument) {
|
|
455
|
+
return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
|
|
456
|
+
}
|
|
457
|
+
__name(IsArray, "IsArray");
|
|
458
|
+
function IsCallable(argument) {
|
|
459
|
+
return typeof argument === "function";
|
|
460
|
+
}
|
|
461
|
+
__name(IsCallable, "IsCallable");
|
|
462
|
+
function IsConstructor(argument) {
|
|
463
|
+
return typeof argument === "function";
|
|
464
|
+
}
|
|
465
|
+
__name(IsConstructor, "IsConstructor");
|
|
466
|
+
function IsPropertyKey(argument) {
|
|
467
|
+
switch (Type(argument)) {
|
|
468
|
+
case 3:
|
|
469
|
+
return true;
|
|
470
|
+
case 4:
|
|
471
|
+
return true;
|
|
472
|
+
default:
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
__name(IsPropertyKey, "IsPropertyKey");
|
|
477
|
+
function SameValueZero(x, y) {
|
|
478
|
+
return x === y || x !== x && y !== y;
|
|
479
|
+
}
|
|
480
|
+
__name(SameValueZero, "SameValueZero");
|
|
481
|
+
function GetMethod(V, P) {
|
|
482
|
+
var func = V[P];
|
|
483
|
+
if (func === void 0 || func === null) return void 0;
|
|
484
|
+
if (!IsCallable(func)) throw new TypeError();
|
|
485
|
+
return func;
|
|
486
|
+
}
|
|
487
|
+
__name(GetMethod, "GetMethod");
|
|
488
|
+
function GetIterator(obj) {
|
|
489
|
+
var method = GetMethod(obj, iteratorSymbol);
|
|
490
|
+
if (!IsCallable(method)) throw new TypeError();
|
|
491
|
+
var iterator = method.call(obj);
|
|
492
|
+
if (!IsObject(iterator)) throw new TypeError();
|
|
493
|
+
return iterator;
|
|
494
|
+
}
|
|
495
|
+
__name(GetIterator, "GetIterator");
|
|
496
|
+
function IteratorValue(iterResult) {
|
|
497
|
+
return iterResult.value;
|
|
498
|
+
}
|
|
499
|
+
__name(IteratorValue, "IteratorValue");
|
|
500
|
+
function IteratorStep(iterator) {
|
|
501
|
+
var result = iterator.next();
|
|
502
|
+
return result.done ? false : result;
|
|
503
|
+
}
|
|
504
|
+
__name(IteratorStep, "IteratorStep");
|
|
505
|
+
function IteratorClose(iterator) {
|
|
506
|
+
var f = iterator["return"];
|
|
507
|
+
if (f) f.call(iterator);
|
|
508
|
+
}
|
|
509
|
+
__name(IteratorClose, "IteratorClose");
|
|
510
|
+
function OrdinaryGetPrototypeOf(O) {
|
|
511
|
+
var proto = Object.getPrototypeOf(O);
|
|
512
|
+
if (typeof O !== "function" || O === functionPrototype) return proto;
|
|
513
|
+
if (proto !== functionPrototype) return proto;
|
|
514
|
+
var prototype = O.prototype;
|
|
515
|
+
var prototypeProto = prototype && Object.getPrototypeOf(prototype);
|
|
516
|
+
if (prototypeProto == null || prototypeProto === Object.prototype) return proto;
|
|
517
|
+
var constructor = prototypeProto.constructor;
|
|
518
|
+
if (typeof constructor !== "function") return proto;
|
|
519
|
+
if (constructor === O) return proto;
|
|
520
|
+
return constructor;
|
|
521
|
+
}
|
|
522
|
+
__name(OrdinaryGetPrototypeOf, "OrdinaryGetPrototypeOf");
|
|
523
|
+
function CreateMetadataRegistry() {
|
|
524
|
+
var fallback;
|
|
525
|
+
if (!IsUndefined(registrySymbol) && typeof root.Reflect !== "undefined" && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === "function") {
|
|
526
|
+
fallback = CreateFallbackProvider(root.Reflect);
|
|
527
|
+
}
|
|
528
|
+
var first;
|
|
529
|
+
var second;
|
|
530
|
+
var rest;
|
|
531
|
+
var targetProviderMap = new _WeakMap();
|
|
532
|
+
var registry = {
|
|
533
|
+
registerProvider,
|
|
534
|
+
getProvider,
|
|
535
|
+
setProvider
|
|
536
|
+
};
|
|
537
|
+
return registry;
|
|
538
|
+
function registerProvider(provider) {
|
|
539
|
+
if (!Object.isExtensible(registry)) {
|
|
540
|
+
throw new Error("Cannot add provider to a frozen registry.");
|
|
541
|
+
}
|
|
542
|
+
switch (true) {
|
|
543
|
+
case fallback === provider:
|
|
544
|
+
break;
|
|
545
|
+
case IsUndefined(first):
|
|
546
|
+
first = provider;
|
|
547
|
+
break;
|
|
548
|
+
case first === provider:
|
|
549
|
+
break;
|
|
550
|
+
case IsUndefined(second):
|
|
551
|
+
second = provider;
|
|
552
|
+
break;
|
|
553
|
+
case second === provider:
|
|
554
|
+
break;
|
|
555
|
+
default:
|
|
556
|
+
if (rest === void 0) rest = new _Set();
|
|
557
|
+
rest.add(provider);
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function getProviderNoCache(O, P) {
|
|
562
|
+
if (!IsUndefined(first)) {
|
|
563
|
+
if (first.isProviderFor(O, P)) return first;
|
|
564
|
+
if (!IsUndefined(second)) {
|
|
565
|
+
if (second.isProviderFor(O, P)) return first;
|
|
566
|
+
if (!IsUndefined(rest)) {
|
|
567
|
+
var iterator = GetIterator(rest);
|
|
568
|
+
while (true) {
|
|
569
|
+
var next = IteratorStep(iterator);
|
|
570
|
+
if (!next) {
|
|
571
|
+
return void 0;
|
|
572
|
+
}
|
|
573
|
+
var provider = IteratorValue(next);
|
|
574
|
+
if (provider.isProviderFor(O, P)) {
|
|
575
|
+
IteratorClose(iterator);
|
|
576
|
+
return provider;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
|
|
583
|
+
return fallback;
|
|
584
|
+
}
|
|
585
|
+
return void 0;
|
|
586
|
+
}
|
|
587
|
+
function getProvider(O, P) {
|
|
588
|
+
var providerMap = targetProviderMap.get(O);
|
|
589
|
+
var provider;
|
|
590
|
+
if (!IsUndefined(providerMap)) {
|
|
591
|
+
provider = providerMap.get(P);
|
|
592
|
+
}
|
|
593
|
+
if (!IsUndefined(provider)) {
|
|
594
|
+
return provider;
|
|
595
|
+
}
|
|
596
|
+
provider = getProviderNoCache(O, P);
|
|
597
|
+
if (!IsUndefined(provider)) {
|
|
598
|
+
if (IsUndefined(providerMap)) {
|
|
599
|
+
providerMap = new _Map();
|
|
600
|
+
targetProviderMap.set(O, providerMap);
|
|
601
|
+
}
|
|
602
|
+
providerMap.set(P, provider);
|
|
603
|
+
}
|
|
604
|
+
return provider;
|
|
605
|
+
}
|
|
606
|
+
function hasProvider(provider) {
|
|
607
|
+
if (IsUndefined(provider)) throw new TypeError();
|
|
608
|
+
return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
|
|
609
|
+
}
|
|
610
|
+
function setProvider(O, P, provider) {
|
|
611
|
+
if (!hasProvider(provider)) {
|
|
612
|
+
throw new Error("Metadata provider not registered.");
|
|
613
|
+
}
|
|
614
|
+
var existingProvider = getProvider(O, P);
|
|
615
|
+
if (existingProvider !== provider) {
|
|
616
|
+
if (!IsUndefined(existingProvider)) {
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
619
|
+
var providerMap = targetProviderMap.get(O);
|
|
620
|
+
if (IsUndefined(providerMap)) {
|
|
621
|
+
providerMap = new _Map();
|
|
622
|
+
targetProviderMap.set(O, providerMap);
|
|
623
|
+
}
|
|
624
|
+
providerMap.set(P, provider);
|
|
625
|
+
}
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
__name(CreateMetadataRegistry, "CreateMetadataRegistry");
|
|
630
|
+
function GetOrCreateMetadataRegistry() {
|
|
631
|
+
var metadataRegistry2;
|
|
632
|
+
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
633
|
+
metadataRegistry2 = root.Reflect[registrySymbol];
|
|
634
|
+
}
|
|
635
|
+
if (IsUndefined(metadataRegistry2)) {
|
|
636
|
+
metadataRegistry2 = CreateMetadataRegistry();
|
|
637
|
+
}
|
|
638
|
+
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
639
|
+
Object.defineProperty(root.Reflect, registrySymbol, {
|
|
640
|
+
enumerable: false,
|
|
641
|
+
configurable: false,
|
|
642
|
+
writable: false,
|
|
643
|
+
value: metadataRegistry2
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
return metadataRegistry2;
|
|
647
|
+
}
|
|
648
|
+
__name(GetOrCreateMetadataRegistry, "GetOrCreateMetadataRegistry");
|
|
649
|
+
function CreateMetadataProvider(registry) {
|
|
650
|
+
var metadata2 = new _WeakMap();
|
|
651
|
+
var provider = {
|
|
652
|
+
isProviderFor: /* @__PURE__ */ __name(function(O, P) {
|
|
653
|
+
var targetMetadata = metadata2.get(O);
|
|
654
|
+
if (IsUndefined(targetMetadata)) return false;
|
|
655
|
+
return targetMetadata.has(P);
|
|
656
|
+
}, "isProviderFor"),
|
|
657
|
+
OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata2,
|
|
658
|
+
OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata2,
|
|
659
|
+
OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata2,
|
|
660
|
+
OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys2,
|
|
661
|
+
OrdinaryDeleteMetadata
|
|
662
|
+
};
|
|
663
|
+
metadataRegistry.registerProvider(provider);
|
|
664
|
+
return provider;
|
|
665
|
+
function GetOrCreateMetadataMap(O, P, Create) {
|
|
666
|
+
var targetMetadata = metadata2.get(O);
|
|
667
|
+
var createdTargetMetadata = false;
|
|
668
|
+
if (IsUndefined(targetMetadata)) {
|
|
669
|
+
if (!Create) return void 0;
|
|
670
|
+
targetMetadata = new _Map();
|
|
671
|
+
metadata2.set(O, targetMetadata);
|
|
672
|
+
createdTargetMetadata = true;
|
|
673
|
+
}
|
|
674
|
+
var metadataMap = targetMetadata.get(P);
|
|
675
|
+
if (IsUndefined(metadataMap)) {
|
|
676
|
+
if (!Create) return void 0;
|
|
677
|
+
metadataMap = new _Map();
|
|
678
|
+
targetMetadata.set(P, metadataMap);
|
|
679
|
+
if (!registry.setProvider(O, P, provider)) {
|
|
680
|
+
targetMetadata.delete(P);
|
|
681
|
+
if (createdTargetMetadata) {
|
|
682
|
+
metadata2.delete(O);
|
|
683
|
+
}
|
|
684
|
+
throw new Error("Wrong provider for target.");
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return metadataMap;
|
|
688
|
+
}
|
|
689
|
+
function OrdinaryHasOwnMetadata2(MetadataKey, O, P) {
|
|
690
|
+
var metadataMap = GetOrCreateMetadataMap(
|
|
691
|
+
O,
|
|
692
|
+
P,
|
|
693
|
+
/*Create*/
|
|
694
|
+
false
|
|
695
|
+
);
|
|
696
|
+
if (IsUndefined(metadataMap)) return false;
|
|
697
|
+
return ToBoolean(metadataMap.has(MetadataKey));
|
|
698
|
+
}
|
|
699
|
+
function OrdinaryGetOwnMetadata2(MetadataKey, O, P) {
|
|
700
|
+
var metadataMap = GetOrCreateMetadataMap(
|
|
701
|
+
O,
|
|
702
|
+
P,
|
|
703
|
+
/*Create*/
|
|
704
|
+
false
|
|
705
|
+
);
|
|
706
|
+
if (IsUndefined(metadataMap)) return void 0;
|
|
707
|
+
return metadataMap.get(MetadataKey);
|
|
708
|
+
}
|
|
709
|
+
function OrdinaryDefineOwnMetadata2(MetadataKey, MetadataValue, O, P) {
|
|
710
|
+
var metadataMap = GetOrCreateMetadataMap(
|
|
711
|
+
O,
|
|
712
|
+
P,
|
|
713
|
+
/*Create*/
|
|
714
|
+
true
|
|
715
|
+
);
|
|
716
|
+
metadataMap.set(MetadataKey, MetadataValue);
|
|
717
|
+
}
|
|
718
|
+
function OrdinaryOwnMetadataKeys2(O, P) {
|
|
719
|
+
var keys = [];
|
|
720
|
+
var metadataMap = GetOrCreateMetadataMap(
|
|
721
|
+
O,
|
|
722
|
+
P,
|
|
723
|
+
/*Create*/
|
|
724
|
+
false
|
|
725
|
+
);
|
|
726
|
+
if (IsUndefined(metadataMap)) return keys;
|
|
727
|
+
var keysObj = metadataMap.keys();
|
|
728
|
+
var iterator = GetIterator(keysObj);
|
|
729
|
+
var k = 0;
|
|
730
|
+
while (true) {
|
|
731
|
+
var next = IteratorStep(iterator);
|
|
732
|
+
if (!next) {
|
|
733
|
+
keys.length = k;
|
|
734
|
+
return keys;
|
|
735
|
+
}
|
|
736
|
+
var nextValue = IteratorValue(next);
|
|
737
|
+
try {
|
|
738
|
+
keys[k] = nextValue;
|
|
739
|
+
} catch (e) {
|
|
740
|
+
try {
|
|
741
|
+
IteratorClose(iterator);
|
|
742
|
+
} finally {
|
|
743
|
+
throw e;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
k++;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function OrdinaryDeleteMetadata(MetadataKey, O, P) {
|
|
750
|
+
var metadataMap = GetOrCreateMetadataMap(
|
|
751
|
+
O,
|
|
752
|
+
P,
|
|
753
|
+
/*Create*/
|
|
754
|
+
false
|
|
755
|
+
);
|
|
756
|
+
if (IsUndefined(metadataMap)) return false;
|
|
757
|
+
if (!metadataMap.delete(MetadataKey)) return false;
|
|
758
|
+
if (metadataMap.size === 0) {
|
|
759
|
+
var targetMetadata = metadata2.get(O);
|
|
760
|
+
if (!IsUndefined(targetMetadata)) {
|
|
761
|
+
targetMetadata.delete(P);
|
|
762
|
+
if (targetMetadata.size === 0) {
|
|
763
|
+
metadata2.delete(targetMetadata);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
__name(CreateMetadataProvider, "CreateMetadataProvider");
|
|
771
|
+
function CreateFallbackProvider(reflect) {
|
|
772
|
+
var defineMetadata2 = reflect.defineMetadata, hasOwnMetadata2 = reflect.hasOwnMetadata, getOwnMetadata2 = reflect.getOwnMetadata, getOwnMetadataKeys2 = reflect.getOwnMetadataKeys, deleteMetadata2 = reflect.deleteMetadata;
|
|
773
|
+
var metadataOwner = new _WeakMap();
|
|
774
|
+
var provider = {
|
|
775
|
+
isProviderFor: /* @__PURE__ */ __name(function(O, P) {
|
|
776
|
+
var metadataPropertySet = metadataOwner.get(O);
|
|
777
|
+
if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) {
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
if (getOwnMetadataKeys2(O, P).length) {
|
|
781
|
+
if (IsUndefined(metadataPropertySet)) {
|
|
782
|
+
metadataPropertySet = new _Set();
|
|
783
|
+
metadataOwner.set(O, metadataPropertySet);
|
|
784
|
+
}
|
|
785
|
+
metadataPropertySet.add(P);
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
return false;
|
|
789
|
+
}, "isProviderFor"),
|
|
790
|
+
OrdinaryDefineOwnMetadata: defineMetadata2,
|
|
791
|
+
OrdinaryHasOwnMetadata: hasOwnMetadata2,
|
|
792
|
+
OrdinaryGetOwnMetadata: getOwnMetadata2,
|
|
793
|
+
OrdinaryOwnMetadataKeys: getOwnMetadataKeys2,
|
|
794
|
+
OrdinaryDeleteMetadata: deleteMetadata2
|
|
795
|
+
};
|
|
796
|
+
return provider;
|
|
797
|
+
}
|
|
798
|
+
__name(CreateFallbackProvider, "CreateFallbackProvider");
|
|
799
|
+
function GetMetadataProvider(O, P, Create) {
|
|
800
|
+
var registeredProvider = metadataRegistry.getProvider(O, P);
|
|
801
|
+
if (!IsUndefined(registeredProvider)) {
|
|
802
|
+
return registeredProvider;
|
|
803
|
+
}
|
|
804
|
+
if (Create) {
|
|
805
|
+
if (metadataRegistry.setProvider(O, P, metadataProvider)) {
|
|
806
|
+
return metadataProvider;
|
|
807
|
+
}
|
|
808
|
+
throw new Error("Illegal state.");
|
|
809
|
+
}
|
|
810
|
+
return void 0;
|
|
811
|
+
}
|
|
812
|
+
__name(GetMetadataProvider, "GetMetadataProvider");
|
|
813
|
+
function CreateMapPolyfill() {
|
|
814
|
+
var cacheSentinel = {};
|
|
815
|
+
var arraySentinel = [];
|
|
816
|
+
var MapIterator = (
|
|
817
|
+
/** @class */
|
|
818
|
+
(function() {
|
|
819
|
+
function MapIterator2(keys, values, selector) {
|
|
820
|
+
this._index = 0;
|
|
821
|
+
this._keys = keys;
|
|
822
|
+
this._values = values;
|
|
823
|
+
this._selector = selector;
|
|
824
|
+
}
|
|
825
|
+
__name(MapIterator2, "MapIterator");
|
|
826
|
+
MapIterator2.prototype["@@iterator"] = function() {
|
|
827
|
+
return this;
|
|
828
|
+
};
|
|
829
|
+
MapIterator2.prototype[iteratorSymbol] = function() {
|
|
830
|
+
return this;
|
|
831
|
+
};
|
|
832
|
+
MapIterator2.prototype.next = function() {
|
|
833
|
+
var index = this._index;
|
|
834
|
+
if (index >= 0 && index < this._keys.length) {
|
|
835
|
+
var result = this._selector(this._keys[index], this._values[index]);
|
|
836
|
+
if (index + 1 >= this._keys.length) {
|
|
837
|
+
this._index = -1;
|
|
838
|
+
this._keys = arraySentinel;
|
|
839
|
+
this._values = arraySentinel;
|
|
840
|
+
} else {
|
|
841
|
+
this._index++;
|
|
842
|
+
}
|
|
843
|
+
return {
|
|
844
|
+
value: result,
|
|
845
|
+
done: false
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
return {
|
|
849
|
+
value: void 0,
|
|
850
|
+
done: true
|
|
851
|
+
};
|
|
852
|
+
};
|
|
853
|
+
MapIterator2.prototype.throw = function(error) {
|
|
854
|
+
if (this._index >= 0) {
|
|
855
|
+
this._index = -1;
|
|
856
|
+
this._keys = arraySentinel;
|
|
857
|
+
this._values = arraySentinel;
|
|
858
|
+
}
|
|
859
|
+
throw error;
|
|
860
|
+
};
|
|
861
|
+
MapIterator2.prototype.return = function(value) {
|
|
862
|
+
if (this._index >= 0) {
|
|
863
|
+
this._index = -1;
|
|
864
|
+
this._keys = arraySentinel;
|
|
865
|
+
this._values = arraySentinel;
|
|
866
|
+
}
|
|
867
|
+
return {
|
|
868
|
+
value,
|
|
869
|
+
done: true
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
return MapIterator2;
|
|
873
|
+
})()
|
|
874
|
+
);
|
|
875
|
+
var Map1 = (
|
|
876
|
+
/** @class */
|
|
877
|
+
(function() {
|
|
878
|
+
function Map12() {
|
|
879
|
+
this._keys = [];
|
|
880
|
+
this._values = [];
|
|
881
|
+
this._cacheKey = cacheSentinel;
|
|
882
|
+
this._cacheIndex = -2;
|
|
883
|
+
}
|
|
884
|
+
__name(Map12, "Map1");
|
|
885
|
+
Object.defineProperty(Map12.prototype, "size", {
|
|
886
|
+
get: /* @__PURE__ */ __name(function() {
|
|
887
|
+
return this._keys.length;
|
|
888
|
+
}, "get"),
|
|
889
|
+
enumerable: true,
|
|
890
|
+
configurable: true
|
|
891
|
+
});
|
|
892
|
+
Map12.prototype.has = function(key) {
|
|
893
|
+
return this._find(
|
|
894
|
+
key,
|
|
895
|
+
/*insert*/
|
|
896
|
+
false
|
|
897
|
+
) >= 0;
|
|
898
|
+
};
|
|
899
|
+
Map12.prototype.get = function(key) {
|
|
900
|
+
var index = this._find(
|
|
901
|
+
key,
|
|
902
|
+
/*insert*/
|
|
903
|
+
false
|
|
904
|
+
);
|
|
905
|
+
return index >= 0 ? this._values[index] : void 0;
|
|
906
|
+
};
|
|
907
|
+
Map12.prototype.set = function(key, value) {
|
|
908
|
+
var index = this._find(
|
|
909
|
+
key,
|
|
910
|
+
/*insert*/
|
|
911
|
+
true
|
|
912
|
+
);
|
|
913
|
+
this._values[index] = value;
|
|
914
|
+
return this;
|
|
915
|
+
};
|
|
916
|
+
Map12.prototype.delete = function(key) {
|
|
917
|
+
var index = this._find(
|
|
918
|
+
key,
|
|
919
|
+
/*insert*/
|
|
920
|
+
false
|
|
921
|
+
);
|
|
922
|
+
if (index >= 0) {
|
|
923
|
+
var size = this._keys.length;
|
|
924
|
+
for (var i = index + 1; i < size; i++) {
|
|
925
|
+
this._keys[i - 1] = this._keys[i];
|
|
926
|
+
this._values[i - 1] = this._values[i];
|
|
927
|
+
}
|
|
928
|
+
this._keys.length--;
|
|
929
|
+
this._values.length--;
|
|
930
|
+
if (SameValueZero(key, this._cacheKey)) {
|
|
931
|
+
this._cacheKey = cacheSentinel;
|
|
932
|
+
this._cacheIndex = -2;
|
|
933
|
+
}
|
|
934
|
+
return true;
|
|
935
|
+
}
|
|
936
|
+
return false;
|
|
937
|
+
};
|
|
938
|
+
Map12.prototype.clear = function() {
|
|
939
|
+
this._keys.length = 0;
|
|
940
|
+
this._values.length = 0;
|
|
941
|
+
this._cacheKey = cacheSentinel;
|
|
942
|
+
this._cacheIndex = -2;
|
|
943
|
+
};
|
|
944
|
+
Map12.prototype.keys = function() {
|
|
945
|
+
return new MapIterator(this._keys, this._values, getKey);
|
|
946
|
+
};
|
|
947
|
+
Map12.prototype.values = function() {
|
|
948
|
+
return new MapIterator(this._keys, this._values, getValue);
|
|
949
|
+
};
|
|
950
|
+
Map12.prototype.entries = function() {
|
|
951
|
+
return new MapIterator(this._keys, this._values, getEntry);
|
|
952
|
+
};
|
|
953
|
+
Map12.prototype["@@iterator"] = function() {
|
|
954
|
+
return this.entries();
|
|
955
|
+
};
|
|
956
|
+
Map12.prototype[iteratorSymbol] = function() {
|
|
957
|
+
return this.entries();
|
|
958
|
+
};
|
|
959
|
+
Map12.prototype._find = function(key, insert) {
|
|
960
|
+
if (!SameValueZero(this._cacheKey, key)) {
|
|
961
|
+
this._cacheIndex = -1;
|
|
962
|
+
for (var i = 0; i < this._keys.length; i++) {
|
|
963
|
+
if (SameValueZero(this._keys[i], key)) {
|
|
964
|
+
this._cacheIndex = i;
|
|
965
|
+
break;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (this._cacheIndex < 0 && insert) {
|
|
970
|
+
this._cacheIndex = this._keys.length;
|
|
971
|
+
this._keys.push(key);
|
|
972
|
+
this._values.push(void 0);
|
|
973
|
+
}
|
|
974
|
+
return this._cacheIndex;
|
|
975
|
+
};
|
|
976
|
+
return Map12;
|
|
977
|
+
})()
|
|
978
|
+
);
|
|
979
|
+
return Map1;
|
|
980
|
+
function getKey(key, _) {
|
|
981
|
+
return key;
|
|
982
|
+
}
|
|
983
|
+
function getValue(_, value) {
|
|
984
|
+
return value;
|
|
985
|
+
}
|
|
986
|
+
function getEntry(key, value) {
|
|
987
|
+
return [
|
|
988
|
+
key,
|
|
989
|
+
value
|
|
990
|
+
];
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
__name(CreateMapPolyfill, "CreateMapPolyfill");
|
|
994
|
+
function CreateSetPolyfill() {
|
|
995
|
+
var Set1 = (
|
|
996
|
+
/** @class */
|
|
997
|
+
(function() {
|
|
998
|
+
function Set12() {
|
|
999
|
+
this._map = new _Map();
|
|
1000
|
+
}
|
|
1001
|
+
__name(Set12, "Set1");
|
|
1002
|
+
Object.defineProperty(Set12.prototype, "size", {
|
|
1003
|
+
get: /* @__PURE__ */ __name(function() {
|
|
1004
|
+
return this._map.size;
|
|
1005
|
+
}, "get"),
|
|
1006
|
+
enumerable: true,
|
|
1007
|
+
configurable: true
|
|
1008
|
+
});
|
|
1009
|
+
Set12.prototype.has = function(value) {
|
|
1010
|
+
return this._map.has(value);
|
|
1011
|
+
};
|
|
1012
|
+
Set12.prototype.add = function(value) {
|
|
1013
|
+
return this._map.set(value, value), this;
|
|
1014
|
+
};
|
|
1015
|
+
Set12.prototype.delete = function(value) {
|
|
1016
|
+
return this._map.delete(value);
|
|
1017
|
+
};
|
|
1018
|
+
Set12.prototype.clear = function() {
|
|
1019
|
+
this._map.clear();
|
|
1020
|
+
};
|
|
1021
|
+
Set12.prototype.keys = function() {
|
|
1022
|
+
return this._map.keys();
|
|
1023
|
+
};
|
|
1024
|
+
Set12.prototype.values = function() {
|
|
1025
|
+
return this._map.keys();
|
|
1026
|
+
};
|
|
1027
|
+
Set12.prototype.entries = function() {
|
|
1028
|
+
return this._map.entries();
|
|
1029
|
+
};
|
|
1030
|
+
Set12.prototype["@@iterator"] = function() {
|
|
1031
|
+
return this.keys();
|
|
1032
|
+
};
|
|
1033
|
+
Set12.prototype[iteratorSymbol] = function() {
|
|
1034
|
+
return this.keys();
|
|
1035
|
+
};
|
|
1036
|
+
return Set12;
|
|
1037
|
+
})()
|
|
1038
|
+
);
|
|
1039
|
+
return Set1;
|
|
1040
|
+
}
|
|
1041
|
+
__name(CreateSetPolyfill, "CreateSetPolyfill");
|
|
1042
|
+
function CreateWeakMapPolyfill() {
|
|
1043
|
+
var UUID_SIZE = 16;
|
|
1044
|
+
var keys = HashMap.create();
|
|
1045
|
+
var rootKey = CreateUniqueKey();
|
|
1046
|
+
return (
|
|
1047
|
+
/** @class */
|
|
1048
|
+
(function() {
|
|
1049
|
+
function WeakMap1() {
|
|
1050
|
+
this._key = CreateUniqueKey();
|
|
1051
|
+
}
|
|
1052
|
+
__name(WeakMap1, "WeakMap1");
|
|
1053
|
+
WeakMap1.prototype.has = function(target) {
|
|
1054
|
+
var table = GetOrCreateWeakMapTable(
|
|
1055
|
+
target,
|
|
1056
|
+
/*create*/
|
|
1057
|
+
false
|
|
1058
|
+
);
|
|
1059
|
+
return table !== void 0 ? HashMap.has(table, this._key) : false;
|
|
1060
|
+
};
|
|
1061
|
+
WeakMap1.prototype.get = function(target) {
|
|
1062
|
+
var table = GetOrCreateWeakMapTable(
|
|
1063
|
+
target,
|
|
1064
|
+
/*create*/
|
|
1065
|
+
false
|
|
1066
|
+
);
|
|
1067
|
+
return table !== void 0 ? HashMap.get(table, this._key) : void 0;
|
|
1068
|
+
};
|
|
1069
|
+
WeakMap1.prototype.set = function(target, value) {
|
|
1070
|
+
var table = GetOrCreateWeakMapTable(
|
|
1071
|
+
target,
|
|
1072
|
+
/*create*/
|
|
1073
|
+
true
|
|
1074
|
+
);
|
|
1075
|
+
table[this._key] = value;
|
|
1076
|
+
return this;
|
|
1077
|
+
};
|
|
1078
|
+
WeakMap1.prototype.delete = function(target) {
|
|
1079
|
+
var table = GetOrCreateWeakMapTable(
|
|
1080
|
+
target,
|
|
1081
|
+
/*create*/
|
|
1082
|
+
false
|
|
1083
|
+
);
|
|
1084
|
+
return table !== void 0 ? delete table[this._key] : false;
|
|
1085
|
+
};
|
|
1086
|
+
WeakMap1.prototype.clear = function() {
|
|
1087
|
+
this._key = CreateUniqueKey();
|
|
1088
|
+
};
|
|
1089
|
+
return WeakMap1;
|
|
1090
|
+
})()
|
|
1091
|
+
);
|
|
1092
|
+
function CreateUniqueKey() {
|
|
1093
|
+
var key;
|
|
1094
|
+
do
|
|
1095
|
+
key = "@@WeakMap@@" + CreateUUID();
|
|
1096
|
+
while (HashMap.has(keys, key));
|
|
1097
|
+
keys[key] = true;
|
|
1098
|
+
return key;
|
|
1099
|
+
}
|
|
1100
|
+
function GetOrCreateWeakMapTable(target, create) {
|
|
1101
|
+
if (!hasOwn.call(target, rootKey)) {
|
|
1102
|
+
if (!create) return void 0;
|
|
1103
|
+
Object.defineProperty(target, rootKey, {
|
|
1104
|
+
value: HashMap.create()
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
return target[rootKey];
|
|
1108
|
+
}
|
|
1109
|
+
function FillRandomBytes(buffer, size) {
|
|
1110
|
+
for (var i = 0; i < size; ++i) buffer[i] = Math.random() * 255 | 0;
|
|
1111
|
+
return buffer;
|
|
1112
|
+
}
|
|
1113
|
+
function GenRandomBytes(size) {
|
|
1114
|
+
if (typeof Uint8Array === "function") {
|
|
1115
|
+
var array = new Uint8Array(size);
|
|
1116
|
+
if (typeof crypto !== "undefined") {
|
|
1117
|
+
crypto.getRandomValues(array);
|
|
1118
|
+
} else if (typeof msCrypto !== "undefined") {
|
|
1119
|
+
msCrypto.getRandomValues(array);
|
|
1120
|
+
} else {
|
|
1121
|
+
FillRandomBytes(array, size);
|
|
1122
|
+
}
|
|
1123
|
+
return array;
|
|
1124
|
+
}
|
|
1125
|
+
return FillRandomBytes(new Array(size), size);
|
|
1126
|
+
}
|
|
1127
|
+
function CreateUUID() {
|
|
1128
|
+
var data = GenRandomBytes(UUID_SIZE);
|
|
1129
|
+
data[6] = data[6] & 79 | 64;
|
|
1130
|
+
data[8] = data[8] & 191 | 128;
|
|
1131
|
+
var result = "";
|
|
1132
|
+
for (var offset = 0; offset < UUID_SIZE; ++offset) {
|
|
1133
|
+
var byte = data[offset];
|
|
1134
|
+
if (offset === 4 || offset === 6 || offset === 8) result += "-";
|
|
1135
|
+
if (byte < 16) result += "0";
|
|
1136
|
+
result += byte.toString(16).toLowerCase();
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
__name(CreateWeakMapPolyfill, "CreateWeakMapPolyfill");
|
|
1142
|
+
function MakeDictionary(obj) {
|
|
1143
|
+
obj.__ = void 0;
|
|
1144
|
+
delete obj.__;
|
|
1145
|
+
return obj;
|
|
1146
|
+
}
|
|
1147
|
+
__name(MakeDictionary, "MakeDictionary");
|
|
1148
|
+
});
|
|
1149
|
+
})(Reflect2 || (Reflect2 = {}));
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
// src/decorators/decorators.utils.ts
|
|
1154
|
+
__toESM(require_Reflect());
|
|
1155
|
+
var ROUTES_KEY = Symbol("routes");
|
|
1156
|
+
var MIDDLEWARE_KEY = Symbol("middlewares");
|
|
1157
|
+
var PARAMS_KEY = Symbol("params");
|
|
1158
|
+
var HTTP_CODE_KEY = Symbol("httpCode");
|
|
1159
|
+
var HEADER_KEY = Symbol("headers");
|
|
1160
|
+
var BEFORE_KEY = Symbol("before");
|
|
1161
|
+
var AFTER_KEY = Symbol("after");
|
|
1162
|
+
var ROLES_KEY = Symbol("roles");
|
|
1163
|
+
var REDIRECT_KEY = Symbol("redirect");
|
|
1164
|
+
var CACHE_KEY = Symbol("cache");
|
|
1165
|
+
var RATE_LIMIT_KEY = Symbol("rateLimit");
|
|
1166
|
+
var CONTENT_TYPE_KEY = Symbol("contentType");
|
|
1167
|
+
var VERSION_KEY = Symbol("version");
|
|
1168
|
+
var TIMEOUT_KEY = Symbol("timeout");
|
|
1169
|
+
var LOG_KEY = Symbol("log");
|
|
1170
|
+
var RateLimiterCache = class RateLimiterCache2 {
|
|
1171
|
+
static {
|
|
1172
|
+
__name(this, "RateLimiterCache");
|
|
1173
|
+
}
|
|
1174
|
+
rateLimit;
|
|
1175
|
+
cache;
|
|
1176
|
+
constructor(maxSize = 100, ttlMs = 5 * 60 * 1e3) {
|
|
1177
|
+
this.cache = new TTLCache({
|
|
1178
|
+
maxSize,
|
|
1179
|
+
ttlMs
|
|
1180
|
+
});
|
|
1181
|
+
const rateLimitModule = optionalRequire("express-rate-limit");
|
|
1182
|
+
if (rateLimitModule) this.rateLimit = rateLimitModule.rateLimit;
|
|
1183
|
+
}
|
|
1184
|
+
generateKey(options) {
|
|
1185
|
+
return `${options.max}:${options.windowMs}:${options.standardHeaders}:${options.legacyHeaders}`;
|
|
1186
|
+
}
|
|
1187
|
+
get(options) {
|
|
1188
|
+
const key = this.generateKey(options);
|
|
1189
|
+
const cached = this.cache.get(key);
|
|
1190
|
+
if (cached) {
|
|
1191
|
+
return cached.limiter;
|
|
1192
|
+
}
|
|
1193
|
+
if (!this.rateLimit) {
|
|
1194
|
+
throw new Error(DependencyErrors["express-rate-limit"]);
|
|
1195
|
+
}
|
|
1196
|
+
const limiter = this.rateLimit({
|
|
1197
|
+
...options,
|
|
1198
|
+
handler: /* @__PURE__ */ __name((req, res) => {
|
|
1199
|
+
const errorResponse = createFinalErrorResponse(req, HttpStatusCodes.TOO_MANY_REQUESTS, "Too Many Requests");
|
|
1200
|
+
res.status(HttpStatusCodes.TOO_MANY_REQUESTS).json(errorResponse);
|
|
1201
|
+
}, "handler")
|
|
1202
|
+
});
|
|
1203
|
+
this.cache.set(key, {
|
|
1204
|
+
limiter,
|
|
1205
|
+
config: key
|
|
1206
|
+
});
|
|
1207
|
+
return limiter;
|
|
1208
|
+
}
|
|
1209
|
+
clear() {
|
|
1210
|
+
this.cache.clear();
|
|
1211
|
+
}
|
|
1212
|
+
get size() {
|
|
1213
|
+
return this.cache.size();
|
|
1214
|
+
}
|
|
1215
|
+
destroy() {
|
|
1216
|
+
this.cache.destroy();
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
var rateLimiterCache = new RateLimiterCache();
|
|
1220
|
+
var DIContainer = class {
|
|
1221
|
+
static {
|
|
1222
|
+
__name(this, "DIContainer");
|
|
1223
|
+
}
|
|
1224
|
+
instances = /* @__PURE__ */ new Map();
|
|
1225
|
+
constructing = /* @__PURE__ */ new Map();
|
|
1226
|
+
propertyInjections = /* @__PURE__ */ new Map();
|
|
1227
|
+
register(target) {
|
|
1228
|
+
if (!this.instances.has(target) && !this.constructing.has(target)) ;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Register a property injection to be resolved when the target class is instantiated
|
|
1232
|
+
*/
|
|
1233
|
+
registerPropertyInjection(target, propertyKey, injectClass) {
|
|
1234
|
+
const targetClass = target.constructor;
|
|
1235
|
+
if (!this.propertyInjections.has(targetClass)) {
|
|
1236
|
+
this.propertyInjections.set(targetClass, []);
|
|
1237
|
+
}
|
|
1238
|
+
this.propertyInjections.get(targetClass).push({
|
|
1239
|
+
targetClass: injectClass,
|
|
1240
|
+
propertyKey
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
get(target) {
|
|
1244
|
+
if (this.instances.has(target)) {
|
|
1245
|
+
return this.instances.get(target);
|
|
1246
|
+
}
|
|
1247
|
+
if (this.constructing.has(target)) {
|
|
1248
|
+
return this.constructing.get(target);
|
|
1249
|
+
}
|
|
1250
|
+
let proxy = {};
|
|
1251
|
+
this.constructing.set(target, proxy);
|
|
1252
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
|
|
1253
|
+
const dependencies = paramTypes.map((dep) => this.get(dep));
|
|
1254
|
+
const instance = new target(...dependencies);
|
|
1255
|
+
this.applyPropertyInjections(target, instance);
|
|
1256
|
+
Object.assign(proxy, instance);
|
|
1257
|
+
this.instances.set(target, proxy);
|
|
1258
|
+
this.constructing.delete(target);
|
|
1259
|
+
Object.setPrototypeOf(proxy, target.prototype);
|
|
1260
|
+
return proxy;
|
|
1261
|
+
}
|
|
1262
|
+
applyPropertyInjections(targetClass, instance) {
|
|
1263
|
+
const injections = this.propertyInjections.get(targetClass) || [];
|
|
1264
|
+
for (const injection of injections) {
|
|
1265
|
+
const dependency = this.get(injection.targetClass);
|
|
1266
|
+
instance[injection.propertyKey] = dependency;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
clear() {
|
|
1270
|
+
this.instances.clear();
|
|
1271
|
+
this.constructing.clear();
|
|
1272
|
+
this.propertyInjections.clear();
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
var diContainer = new DIContainer();
|
|
1276
|
+
function normalizeHeaderValue(value) {
|
|
1277
|
+
if (typeof value === "undefined") return void 0;
|
|
1278
|
+
if (typeof value === "string") return value;
|
|
1279
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
1280
|
+
return value;
|
|
1281
|
+
}
|
|
1282
|
+
return String(value);
|
|
1283
|
+
}
|
|
1284
|
+
__name(normalizeHeaderValue, "normalizeHeaderValue");
|
|
1285
|
+
function Injectable() {
|
|
1286
|
+
return (target) => {
|
|
1287
|
+
Reflect.defineMetadata("injectable", true, target);
|
|
1288
|
+
diContainer.register(target);
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
__name(Injectable, "Injectable");
|
|
1292
|
+
function Inject(targetClass) {
|
|
1293
|
+
return (target, propertyKey) => {
|
|
1294
|
+
diContainer.registerPropertyInjection(target, propertyKey, targetClass);
|
|
1295
|
+
Object.defineProperty(target, propertyKey, {
|
|
1296
|
+
configurable: true,
|
|
1297
|
+
get: /* @__PURE__ */ __name(function() {
|
|
1298
|
+
const value = Object.getOwnPropertyDescriptor(this, propertyKey)?.value;
|
|
1299
|
+
if (value !== void 0) return value;
|
|
1300
|
+
const injectedValue = diContainer.get(targetClass);
|
|
1301
|
+
Object.defineProperty(this, propertyKey, {
|
|
1302
|
+
value: injectedValue,
|
|
1303
|
+
writable: true,
|
|
1304
|
+
configurable: true
|
|
1305
|
+
});
|
|
1306
|
+
return injectedValue;
|
|
1307
|
+
}, "get"),
|
|
1308
|
+
set: /* @__PURE__ */ __name(function(value) {
|
|
1309
|
+
Object.defineProperty(this, propertyKey, {
|
|
1310
|
+
value,
|
|
1311
|
+
writable: true,
|
|
1312
|
+
configurable: true
|
|
1313
|
+
});
|
|
1314
|
+
}, "set")
|
|
1315
|
+
});
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
__name(Inject, "Inject");
|
|
1319
|
+
function inject(targetClass) {
|
|
1320
|
+
return diContainer.get(targetClass);
|
|
1321
|
+
}
|
|
1322
|
+
__name(inject, "inject");
|
|
1323
|
+
function createRouteDecorator(method) {
|
|
1324
|
+
return (path) => {
|
|
1325
|
+
return (target, propertyKey, _descriptor) => {
|
|
1326
|
+
const routes = Reflect.getMetadata(ROUTES_KEY, target.constructor) || [];
|
|
1327
|
+
routes.push({
|
|
1328
|
+
path,
|
|
1329
|
+
method,
|
|
1330
|
+
handlerName: propertyKey
|
|
1331
|
+
});
|
|
1332
|
+
Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);
|
|
1333
|
+
};
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
__name(createRouteDecorator, "createRouteDecorator");
|
|
1337
|
+
var Get = createRouteDecorator("get");
|
|
1338
|
+
var Post = createRouteDecorator("post");
|
|
1339
|
+
var Put = createRouteDecorator("put");
|
|
1340
|
+
var Patch = createRouteDecorator("patch");
|
|
1341
|
+
var Delete = createRouteDecorator("delete");
|
|
1342
|
+
var Options = createRouteDecorator("options");
|
|
1343
|
+
var Head = createRouteDecorator("head");
|
|
1344
|
+
var Trace = createRouteDecorator("trace");
|
|
1345
|
+
var Connect = createRouteDecorator("connect");
|
|
1346
|
+
function Controller(basePath) {
|
|
1347
|
+
return (target) => {
|
|
1348
|
+
Reflect.defineMetadata("basePath", basePath, target);
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
__name(Controller, "Controller");
|
|
1352
|
+
function Use(...middlewares) {
|
|
1353
|
+
return (target, propertyKey, _descriptor) => {
|
|
1354
|
+
if (propertyKey === void 0) {
|
|
1355
|
+
const existing = Reflect.getMetadata(MIDDLEWARE_KEY, target) || [];
|
|
1356
|
+
Reflect.defineMetadata(MIDDLEWARE_KEY, [
|
|
1357
|
+
...existing,
|
|
1358
|
+
...middlewares
|
|
1359
|
+
], target);
|
|
1360
|
+
} else {
|
|
1361
|
+
const existing = Reflect.getMetadata(MIDDLEWARE_KEY, target, propertyKey) || [];
|
|
1362
|
+
Reflect.defineMetadata(MIDDLEWARE_KEY, [
|
|
1363
|
+
...existing,
|
|
1364
|
+
...middlewares
|
|
1365
|
+
], target, propertyKey);
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
__name(Use, "Use");
|
|
1370
|
+
function defineParamMetadata(target, propertyKey, parameterIndex, type, key) {
|
|
1371
|
+
const params = Reflect.getMetadata(PARAMS_KEY, target, propertyKey) || [];
|
|
1372
|
+
params.push({
|
|
1373
|
+
index: parameterIndex,
|
|
1374
|
+
type,
|
|
1375
|
+
key
|
|
1376
|
+
});
|
|
1377
|
+
params.sort((a, b) => a.index - b.index);
|
|
1378
|
+
Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey);
|
|
1379
|
+
}
|
|
1380
|
+
__name(defineParamMetadata, "defineParamMetadata");
|
|
1381
|
+
function createParamDecorator(type, key) {
|
|
1382
|
+
return (paramKey) => {
|
|
1383
|
+
return (target, propertyKey, parameterIndex) => {
|
|
1384
|
+
defineParamMetadata(target, propertyKey, parameterIndex, type, paramKey ?? key);
|
|
1385
|
+
};
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
__name(createParamDecorator, "createParamDecorator");
|
|
1389
|
+
function createParamDecoratorWithoutParam(type) {
|
|
1390
|
+
return () => {
|
|
1391
|
+
return (target, propertyKey, parameterIndex) => {
|
|
1392
|
+
defineParamMetadata(target, propertyKey, parameterIndex, type, void 0);
|
|
1393
|
+
};
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
__name(createParamDecoratorWithoutParam, "createParamDecoratorWithoutParam");
|
|
1397
|
+
function createApiUrlParamDecorator(type, key) {
|
|
1398
|
+
return (paramKey, options) => {
|
|
1399
|
+
return (target, propertyKey, parameterIndex) => {
|
|
1400
|
+
const params = Reflect.getMetadata(PARAMS_KEY, target, propertyKey) || [];
|
|
1401
|
+
let paramOptions = void 0;
|
|
1402
|
+
if (typeof options === "object") {
|
|
1403
|
+
paramOptions = {};
|
|
1404
|
+
paramOptions.type = "string";
|
|
1405
|
+
paramOptions.dataType = "single";
|
|
1406
|
+
paramOptions.delimiter = ",";
|
|
1407
|
+
paramOptions.required = false;
|
|
1408
|
+
paramOptions.throwError = true;
|
|
1409
|
+
paramOptions = {
|
|
1410
|
+
...paramOptions,
|
|
1411
|
+
...options
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
params.push({
|
|
1415
|
+
index: parameterIndex,
|
|
1416
|
+
type,
|
|
1417
|
+
key: paramKey || key,
|
|
1418
|
+
options: paramOptions
|
|
1419
|
+
});
|
|
1420
|
+
params.sort((a, b) => a.index - b.index);
|
|
1421
|
+
Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey);
|
|
1422
|
+
};
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
__name(createApiUrlParamDecorator, "createApiUrlParamDecorator");
|
|
1426
|
+
var Query = createApiUrlParamDecorator("query");
|
|
1427
|
+
var Param = createApiUrlParamDecorator("param");
|
|
1428
|
+
var Body = createParamDecorator("body");
|
|
1429
|
+
var ReqLogger = createParamDecoratorWithoutParam("logger");
|
|
1430
|
+
var ReqId = createParamDecoratorWithoutParam("reqId");
|
|
1431
|
+
var ReqHeader = createParamDecorator("reqHeader");
|
|
1432
|
+
var ReqCookie = createParamDecorator("cookie");
|
|
1433
|
+
var Req = createParamDecoratorWithoutParam("req");
|
|
1434
|
+
var Res = createParamDecoratorWithoutParam("res");
|
|
1435
|
+
function HttpCode(status) {
|
|
1436
|
+
return (target, propertyKey, _descriptor) => {
|
|
1437
|
+
Reflect.defineMetadata(HTTP_CODE_KEY, status, target, propertyKey);
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
__name(HttpCode, "HttpCode");
|
|
1441
|
+
function Header(name, value) {
|
|
1442
|
+
return Headers(name, value);
|
|
1443
|
+
}
|
|
1444
|
+
__name(Header, "Header");
|
|
1445
|
+
function Headers(headers, value) {
|
|
1446
|
+
return (target, propertyKey) => {
|
|
1447
|
+
if (propertyKey === void 0) {
|
|
1448
|
+
const existing = Reflect.getMetadata(HEADER_KEY, target) || {};
|
|
1449
|
+
const newHeaders = typeof headers === "string" ? {
|
|
1450
|
+
[headers]: value
|
|
1451
|
+
} : headers;
|
|
1452
|
+
Reflect.defineMetadata(HEADER_KEY, {
|
|
1453
|
+
...existing,
|
|
1454
|
+
...newHeaders
|
|
1455
|
+
}, target);
|
|
1456
|
+
} else {
|
|
1457
|
+
const existing = Reflect.getMetadata(HEADER_KEY, target, propertyKey) || {};
|
|
1458
|
+
const newHeaders = typeof headers === "string" ? {
|
|
1459
|
+
[headers]: value
|
|
1460
|
+
} : headers;
|
|
1461
|
+
Reflect.defineMetadata(HEADER_KEY, {
|
|
1462
|
+
...existing,
|
|
1463
|
+
...newHeaders
|
|
1464
|
+
}, target, propertyKey);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
__name(Headers, "Headers");
|
|
1469
|
+
function Before(fn) {
|
|
1470
|
+
return (target, propertyKey, _descriptor) => {
|
|
1471
|
+
if (propertyKey === void 0) {
|
|
1472
|
+
const hooks = Reflect.getMetadata(BEFORE_KEY, target) || [];
|
|
1473
|
+
hooks.push(fn);
|
|
1474
|
+
Reflect.defineMetadata(BEFORE_KEY, hooks, target);
|
|
1475
|
+
} else {
|
|
1476
|
+
const hooks = Reflect.getMetadata(BEFORE_KEY, target, propertyKey) || [];
|
|
1477
|
+
hooks.push(fn);
|
|
1478
|
+
Reflect.defineMetadata(BEFORE_KEY, hooks, target, propertyKey);
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
__name(Before, "Before");
|
|
1483
|
+
function After(fn) {
|
|
1484
|
+
return (target, propertyKey, _descriptor) => {
|
|
1485
|
+
if (propertyKey === void 0) {
|
|
1486
|
+
const hooks = Reflect.getMetadata(AFTER_KEY, target) || [];
|
|
1487
|
+
hooks.push(fn);
|
|
1488
|
+
Reflect.defineMetadata(AFTER_KEY, hooks, target);
|
|
1489
|
+
} else {
|
|
1490
|
+
const hooks = Reflect.getMetadata(AFTER_KEY, target, propertyKey) || [];
|
|
1491
|
+
hooks.push(fn);
|
|
1492
|
+
Reflect.defineMetadata(AFTER_KEY, hooks, target, propertyKey);
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
__name(After, "After");
|
|
1497
|
+
function Roles(...roles) {
|
|
1498
|
+
return (target, propertyKey, _descriptor) => {
|
|
1499
|
+
if (propertyKey === void 0) {
|
|
1500
|
+
Reflect.defineMetadata(ROLES_KEY, roles, target);
|
|
1501
|
+
} else {
|
|
1502
|
+
Reflect.defineMetadata(ROLES_KEY, roles, target, propertyKey);
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
__name(Roles, "Roles");
|
|
1507
|
+
function Redirect(url, statusCode = 302) {
|
|
1508
|
+
return (target, propertyKey, descriptor) => {
|
|
1509
|
+
Reflect.defineMetadata(REDIRECT_KEY, {
|
|
1510
|
+
url,
|
|
1511
|
+
statusCode
|
|
1512
|
+
}, target, propertyKey);
|
|
1513
|
+
return descriptor;
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
__name(Redirect, "Redirect");
|
|
1517
|
+
function Cache(ttlSeconds) {
|
|
1518
|
+
return (target, propertyKey, _descriptor) => {
|
|
1519
|
+
if (propertyKey === void 0) {
|
|
1520
|
+
Reflect.defineMetadata(CACHE_KEY, {
|
|
1521
|
+
ttlSeconds
|
|
1522
|
+
}, target);
|
|
1523
|
+
} else {
|
|
1524
|
+
Reflect.defineMetadata(CACHE_KEY, {
|
|
1525
|
+
ttlSeconds
|
|
1526
|
+
}, target, propertyKey);
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
__name(Cache, "Cache");
|
|
1531
|
+
function RateLimit(options) {
|
|
1532
|
+
const opts = {
|
|
1533
|
+
standardHeaders: true,
|
|
1534
|
+
legacyHeaders: false,
|
|
1535
|
+
...options
|
|
1536
|
+
};
|
|
1537
|
+
return (target, propertyKey, _descriptor) => {
|
|
1538
|
+
if (propertyKey === void 0) {
|
|
1539
|
+
Reflect.defineMetadata(RATE_LIMIT_KEY, opts, target);
|
|
1540
|
+
} else {
|
|
1541
|
+
Reflect.defineMetadata(RATE_LIMIT_KEY, opts, target, propertyKey);
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
__name(RateLimit, "RateLimit");
|
|
1546
|
+
function ContentType(type) {
|
|
1547
|
+
return (target, propertyKey, _descriptor) => {
|
|
1548
|
+
if (propertyKey === void 0) {
|
|
1549
|
+
Reflect.defineMetadata(CONTENT_TYPE_KEY, {
|
|
1550
|
+
type
|
|
1551
|
+
}, target);
|
|
1552
|
+
} else {
|
|
1553
|
+
Reflect.defineMetadata(CONTENT_TYPE_KEY, {
|
|
1554
|
+
type
|
|
1555
|
+
}, target, propertyKey);
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
__name(ContentType, "ContentType");
|
|
1560
|
+
function Version(version, options) {
|
|
1561
|
+
const opts = {
|
|
1562
|
+
addPrefix: true,
|
|
1563
|
+
addHeader: true,
|
|
1564
|
+
headerName: "X-API-Version",
|
|
1565
|
+
...options
|
|
1566
|
+
};
|
|
1567
|
+
return (target, propertyKey, _descriptor) => {
|
|
1568
|
+
if (propertyKey === void 0) {
|
|
1569
|
+
Reflect.defineMetadata(VERSION_KEY, {
|
|
1570
|
+
version,
|
|
1571
|
+
options: opts
|
|
1572
|
+
}, target);
|
|
1573
|
+
} else {
|
|
1574
|
+
Reflect.defineMetadata(VERSION_KEY, {
|
|
1575
|
+
version,
|
|
1576
|
+
options: opts
|
|
1577
|
+
}, target, propertyKey);
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
__name(Version, "Version");
|
|
1582
|
+
function Timeout(ms) {
|
|
1583
|
+
return (target, propertyKey, _descriptor) => {
|
|
1584
|
+
if (propertyKey === void 0) {
|
|
1585
|
+
Reflect.defineMetadata(TIMEOUT_KEY, {
|
|
1586
|
+
ms
|
|
1587
|
+
}, target);
|
|
1588
|
+
} else {
|
|
1589
|
+
Reflect.defineMetadata(TIMEOUT_KEY, {
|
|
1590
|
+
ms
|
|
1591
|
+
}, target, propertyKey);
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
__name(Timeout, "Timeout");
|
|
1596
|
+
function Log(options) {
|
|
1597
|
+
return (target, propertyKey, _descriptor) => {
|
|
1598
|
+
const config = {
|
|
1599
|
+
logEntry: true,
|
|
1600
|
+
logExit: true,
|
|
1601
|
+
logBody: false,
|
|
1602
|
+
logParams: false,
|
|
1603
|
+
logResponse: false,
|
|
1604
|
+
...options
|
|
1605
|
+
};
|
|
1606
|
+
if (propertyKey === void 0) {
|
|
1607
|
+
Reflect.defineMetadata(LOG_KEY, config, target);
|
|
1608
|
+
} else {
|
|
1609
|
+
Reflect.defineMetadata(LOG_KEY, config, target, propertyKey);
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
__name(Log, "Log");
|
|
1614
|
+
function registerControllers(router, controllers) {
|
|
1615
|
+
controllers.forEach((ControllerClass) => {
|
|
1616
|
+
if (!Reflect.getMetadata("injectable", ControllerClass)) {
|
|
1617
|
+
Reflect.defineMetadata("injectable", true, ControllerClass);
|
|
1618
|
+
diContainer.register(ControllerClass);
|
|
1619
|
+
}
|
|
1620
|
+
const instance = diContainer.get(ControllerClass);
|
|
1621
|
+
let basePath = Reflect.getMetadata("basePath", ControllerClass) || "";
|
|
1622
|
+
const routes = Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];
|
|
1623
|
+
const controllerRateLimit = Reflect.getMetadata(RATE_LIMIT_KEY, ControllerClass);
|
|
1624
|
+
const controllerCache = Reflect.getMetadata(CACHE_KEY, ControllerClass);
|
|
1625
|
+
const controllerTimeout = Reflect.getMetadata(TIMEOUT_KEY, ControllerClass);
|
|
1626
|
+
const controllerVersion = Reflect.getMetadata(VERSION_KEY, ControllerClass);
|
|
1627
|
+
const controllerRoles = Reflect.getMetadata(ROLES_KEY, ControllerClass);
|
|
1628
|
+
const controllerLogConfig = Reflect.getMetadata(LOG_KEY, ControllerClass);
|
|
1629
|
+
const controllerHeaders = Reflect.getMetadata(HEADER_KEY, ControllerClass) || {};
|
|
1630
|
+
const controllerMiddlewares = Reflect.getMetadata(MIDDLEWARE_KEY, ControllerClass) || [];
|
|
1631
|
+
const controllerBeforeHooks = Reflect.getMetadata(BEFORE_KEY, ControllerClass) || [];
|
|
1632
|
+
const controllerAfterHooks = Reflect.getMetadata(AFTER_KEY, ControllerClass) || [];
|
|
1633
|
+
const controllerContentType = Reflect.getMetadata(CONTENT_TYPE_KEY, ControllerClass);
|
|
1634
|
+
if (controllerVersion?.options?.addPrefix) {
|
|
1635
|
+
basePath = `/${controllerVersion.version}${basePath || ""}`;
|
|
1636
|
+
}
|
|
1637
|
+
routes.forEach(({ path, method, handlerName }) => {
|
|
1638
|
+
const methodMiddlewares = Reflect.getMetadata(MIDDLEWARE_KEY, instance, handlerName) || [];
|
|
1639
|
+
const params = Reflect.getMetadata(PARAMS_KEY, instance, handlerName) || [];
|
|
1640
|
+
const httpCode = Reflect.getMetadata(HTTP_CODE_KEY, instance, handlerName);
|
|
1641
|
+
const methodHeaders = Reflect.getMetadata(HEADER_KEY, instance, handlerName) || {};
|
|
1642
|
+
const headers = {
|
|
1643
|
+
...controllerHeaders,
|
|
1644
|
+
...methodHeaders
|
|
1645
|
+
};
|
|
1646
|
+
const middlewares = [
|
|
1647
|
+
...controllerMiddlewares,
|
|
1648
|
+
...methodMiddlewares
|
|
1649
|
+
];
|
|
1650
|
+
const methodBeforeHooks = Reflect.getMetadata(BEFORE_KEY, instance, handlerName) || [];
|
|
1651
|
+
const methodAfterHooks = Reflect.getMetadata(AFTER_KEY, instance, handlerName) || [];
|
|
1652
|
+
const beforeHooks = [
|
|
1653
|
+
...controllerBeforeHooks,
|
|
1654
|
+
...methodBeforeHooks
|
|
1655
|
+
];
|
|
1656
|
+
const afterHooks = [
|
|
1657
|
+
...methodAfterHooks,
|
|
1658
|
+
...controllerAfterHooks
|
|
1659
|
+
];
|
|
1660
|
+
const redirect = Reflect.getMetadata(REDIRECT_KEY, instance, handlerName);
|
|
1661
|
+
const methodContentType = Reflect.getMetadata(CONTENT_TYPE_KEY, instance, handlerName);
|
|
1662
|
+
const contentType = methodContentType || controllerContentType;
|
|
1663
|
+
const roles = Reflect.getMetadata(ROLES_KEY, instance, handlerName) || controllerRoles || [];
|
|
1664
|
+
const cache = Reflect.getMetadata(CACHE_KEY, instance, handlerName) || controllerCache;
|
|
1665
|
+
const rateLimitOptions = Reflect.getMetadata(RATE_LIMIT_KEY, instance, handlerName) || controllerRateLimit;
|
|
1666
|
+
const methodVersion = Reflect.getMetadata(VERSION_KEY, instance, handlerName);
|
|
1667
|
+
const version = methodVersion || controllerVersion;
|
|
1668
|
+
const timeout = Reflect.getMetadata(TIMEOUT_KEY, instance, handlerName) || controllerTimeout;
|
|
1669
|
+
const logConfig = Reflect.getMetadata(LOG_KEY, instance, handlerName) || controllerLogConfig;
|
|
1670
|
+
let rateLimiter = null;
|
|
1671
|
+
if (rateLimitOptions) {
|
|
1672
|
+
try {
|
|
1673
|
+
rateLimiter = rateLimiterCache.get(rateLimitOptions);
|
|
1674
|
+
} catch (err) {
|
|
1675
|
+
getLogger().warn({
|
|
1676
|
+
err
|
|
1677
|
+
}, "express-rate-limit not available, skipping rate limiting for this route");
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
let finalPath = path;
|
|
1681
|
+
if (methodVersion?.options?.addPrefix && methodVersion.version !== controllerVersion?.version) {
|
|
1682
|
+
finalPath = `/${methodVersion.version}${path}`;
|
|
1683
|
+
}
|
|
1684
|
+
const handler = /* @__PURE__ */ __name(async (req, res, next) => {
|
|
1685
|
+
req["startTime"] = Date.now();
|
|
1686
|
+
let timeoutId;
|
|
1687
|
+
let timedOut = false;
|
|
1688
|
+
try {
|
|
1689
|
+
if (timeout) {
|
|
1690
|
+
timeoutId = setTimeout(() => {
|
|
1691
|
+
if (!res.headersSent && !timedOut) {
|
|
1692
|
+
timedOut = true;
|
|
1693
|
+
const errorResponse = createFinalErrorResponse(req, HttpStatusCodes.REQUEST_TIMEOUT, "Request timed out");
|
|
1694
|
+
res.status(HttpStatusCodes.REQUEST_TIMEOUT).json(errorResponse);
|
|
1695
|
+
}
|
|
1696
|
+
}, timeout.ms);
|
|
1697
|
+
}
|
|
1698
|
+
if (timedOut) return;
|
|
1699
|
+
if (rateLimiter) {
|
|
1700
|
+
await new Promise((resolve, reject) => {
|
|
1701
|
+
rateLimiter(req, res, (err) => {
|
|
1702
|
+
if (err) reject(err);
|
|
1703
|
+
else resolve();
|
|
1704
|
+
});
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
if (!res.headersSent && contentType) {
|
|
1708
|
+
res.setHeader("Content-Type", contentType.type);
|
|
1709
|
+
}
|
|
1710
|
+
if (version?.options?.addHeader && version?.options?.headerName && version?.version) {
|
|
1711
|
+
if (!res.headersSent) {
|
|
1712
|
+
res.setHeader(version.options.headerName, version.version);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
if (cache && !res.headersSent) {
|
|
1716
|
+
res.setHeader("Cache-Control", `public, max-age=${cache.ttlSeconds}`);
|
|
1717
|
+
}
|
|
1718
|
+
if (logConfig?.logEntry) {
|
|
1719
|
+
const logger = getLogger();
|
|
1720
|
+
const logData = {
|
|
1721
|
+
method: req.method,
|
|
1722
|
+
url: req.originalUrl || req.url,
|
|
1723
|
+
userAgent: req.get("User-Agent")
|
|
1724
|
+
};
|
|
1725
|
+
if (logConfig.logParams) {
|
|
1726
|
+
logData.params = req.params;
|
|
1727
|
+
logData.query = req.query;
|
|
1728
|
+
}
|
|
1729
|
+
if (logConfig.logBody) logData.body = req.body;
|
|
1730
|
+
logger.info({
|
|
1731
|
+
entry: logData
|
|
1732
|
+
}, "Route Entry:");
|
|
1733
|
+
}
|
|
1734
|
+
if (roles.length && !req?.user?.roles?.some((role) => roles.includes(role))) {
|
|
1735
|
+
const errorResponse = createFinalErrorResponse(req, HttpStatusCodes.FORBIDDEN, "Forbidden Insufficient Roles");
|
|
1736
|
+
res.status(HttpStatusCodes.FORBIDDEN).json(errorResponse);
|
|
1737
|
+
if (timeoutId) {
|
|
1738
|
+
clearTimeout(timeoutId);
|
|
1739
|
+
}
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
if (redirect?.url) {
|
|
1743
|
+
if (timeoutId) {
|
|
1744
|
+
clearTimeout(timeoutId);
|
|
1745
|
+
}
|
|
1746
|
+
return res.redirect(redirect.statusCode, redirect.url);
|
|
1747
|
+
}
|
|
1748
|
+
for (const fn of beforeHooks) await fn(req, res);
|
|
1749
|
+
const args = [];
|
|
1750
|
+
if (params.length) {
|
|
1751
|
+
params.forEach(({ index, type, key, options }) => {
|
|
1752
|
+
let rawValue;
|
|
1753
|
+
switch (type) {
|
|
1754
|
+
case "query":
|
|
1755
|
+
rawValue = key ? req.query[key] : req.query;
|
|
1756
|
+
args[index] = options ? applyParamOptions(rawValue, options, key) : rawValue;
|
|
1757
|
+
break;
|
|
1758
|
+
case "param":
|
|
1759
|
+
rawValue = key ? req.params[key] : req.params;
|
|
1760
|
+
args[index] = options ? applyParamOptions(rawValue, options, key) : rawValue;
|
|
1761
|
+
break;
|
|
1762
|
+
case "body":
|
|
1763
|
+
args[index] = key ? req.body?.[key] : req.body;
|
|
1764
|
+
break;
|
|
1765
|
+
case "req":
|
|
1766
|
+
args[index] = req;
|
|
1767
|
+
break;
|
|
1768
|
+
case "res":
|
|
1769
|
+
args[index] = res;
|
|
1770
|
+
break;
|
|
1771
|
+
case "logger":
|
|
1772
|
+
args[index] = getLogger();
|
|
1773
|
+
break;
|
|
1774
|
+
case "reqHeader":
|
|
1775
|
+
args[index] = key ? req.headers[key.toLowerCase()] : req.headers;
|
|
1776
|
+
break;
|
|
1777
|
+
case "reqId":
|
|
1778
|
+
args[index] = req.headers["x-request-id"] || req?.id || void 0;
|
|
1779
|
+
break;
|
|
1780
|
+
case "cookie":
|
|
1781
|
+
args[index] = key ? req.cookies?.[key] : req.cookies;
|
|
1782
|
+
break;
|
|
1783
|
+
}
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
const result = instance[handlerName](...args);
|
|
1787
|
+
const awaited = result instanceof Promise ? await result : result;
|
|
1788
|
+
if (timeoutId) {
|
|
1789
|
+
clearTimeout(timeoutId);
|
|
1790
|
+
}
|
|
1791
|
+
if (timedOut) return;
|
|
1792
|
+
if (redirect && awaited && typeof awaited === "object" && "url" in awaited) {
|
|
1793
|
+
const redirectUrl = awaited.url;
|
|
1794
|
+
const redirectStatus = awaited.statusCode || redirect.statusCode;
|
|
1795
|
+
return res.redirect(redirectStatus, redirectUrl);
|
|
1796
|
+
}
|
|
1797
|
+
if (!res.headersSent && typeof awaited !== "undefined") {
|
|
1798
|
+
if (httpCode) res.status(httpCode);
|
|
1799
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
1800
|
+
const normalized = normalizeHeaderValue(v);
|
|
1801
|
+
if (typeof normalized !== "undefined") {
|
|
1802
|
+
res.set(k, normalized);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
res.json(awaited);
|
|
1806
|
+
}
|
|
1807
|
+
if (logConfig?.logExit) {
|
|
1808
|
+
const logger = getLogger();
|
|
1809
|
+
const logData = {
|
|
1810
|
+
method: req.method,
|
|
1811
|
+
url: req.originalUrl || req.url,
|
|
1812
|
+
statusCode: res.statusCode,
|
|
1813
|
+
duration: `${Date.now() - req.startTime}ms`
|
|
1814
|
+
};
|
|
1815
|
+
if (logConfig.logResponse) logData.response = awaited;
|
|
1816
|
+
logger.info({
|
|
1817
|
+
exit: logData
|
|
1818
|
+
}, "Route Exit:");
|
|
1819
|
+
}
|
|
1820
|
+
for (const fn of afterHooks) await fn(req, res, awaited);
|
|
1821
|
+
} catch (err) {
|
|
1822
|
+
if (timeoutId) {
|
|
1823
|
+
clearTimeout(timeoutId);
|
|
1824
|
+
}
|
|
1825
|
+
next(err);
|
|
1826
|
+
}
|
|
1827
|
+
}, "handler");
|
|
1828
|
+
router[method](basePath + finalPath, ...middlewares, handler);
|
|
1829
|
+
});
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
__name(registerControllers, "registerControllers");
|
|
1833
|
+
function applyParamOptions(rawValue, options, key) {
|
|
1834
|
+
if (!options) return rawValue;
|
|
1835
|
+
let value = rawValue;
|
|
1836
|
+
const paramName = key ? `: ${key}` : "";
|
|
1837
|
+
if (value === void 0 || value === null || value === "") {
|
|
1838
|
+
if ("default" in options) {
|
|
1839
|
+
value = options.default;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
if (options.required && (value === void 0 || value === null || value === "")) {
|
|
1843
|
+
throw new BadRequestException(`Required parameter missing${paramName}`);
|
|
1844
|
+
}
|
|
1845
|
+
if (value !== void 0 && value !== null) {
|
|
1846
|
+
if (options.dataType === "array") {
|
|
1847
|
+
const delimiter = options.delimiter || ",";
|
|
1848
|
+
if (typeof value === "string") {
|
|
1849
|
+
value = value.split(delimiter).map((v) => v.trim());
|
|
1850
|
+
} else if (!Array.isArray(value)) {
|
|
1851
|
+
value = [
|
|
1852
|
+
value
|
|
1853
|
+
];
|
|
1854
|
+
}
|
|
1855
|
+
if (options.type === "string" && options.pattern) {
|
|
1856
|
+
const hasInvalidPattern = value.some((v) => !options.pattern.test(v));
|
|
1857
|
+
if (hasInvalidPattern) {
|
|
1858
|
+
throw new BadRequestException(`Parameter '${key}' array contains values that do not match pattern: ${options.patternName || options.pattern}`);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if (options.type === "number" && options.pattern) {
|
|
1862
|
+
const hasInvalidPattern = value.some((v) => !options.pattern.test(String(v)));
|
|
1863
|
+
if (hasInvalidPattern) {
|
|
1864
|
+
throw new BadRequestException(`Parameter '${key}' array contains values that do not match pattern: ${options.patternName || options.pattern}`);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
if (options.type === "number" && options.throwError !== false) {
|
|
1868
|
+
const hasInvalidNumber = value.some((v) => Number.isNaN(Number(v)));
|
|
1869
|
+
if (hasInvalidNumber) {
|
|
1870
|
+
throw new BadRequestException(`Type error: expected number array${paramName}`);
|
|
1871
|
+
}
|
|
1872
|
+
if (options.min !== void 0) {
|
|
1873
|
+
const hasBelowMin = value.some((v) => Number(v) < options.min);
|
|
1874
|
+
if (hasBelowMin) {
|
|
1875
|
+
throw new BadRequestException(`Validation error: number array values must be >= ${options.min}${paramName}`);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (options.max !== void 0) {
|
|
1879
|
+
const hasAboveMax = value.some((v) => Number(v) > options.max);
|
|
1880
|
+
if (hasAboveMax) {
|
|
1881
|
+
throw new BadRequestException(`Validation error: number array values must be <= ${options.max}${paramName}`);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
if (options.type === "boolean" && options.throwError !== false) {
|
|
1886
|
+
const hasInvalidBoolean = value.some((v) => !isValidBooleanInput(v));
|
|
1887
|
+
if (hasInvalidBoolean) {
|
|
1888
|
+
throw new BadRequestException(`Type error: expected boolean array${paramName}`);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
if (options.type) {
|
|
1892
|
+
value = value.map((v) => convertType(v, options.type || "string"));
|
|
1893
|
+
}
|
|
1894
|
+
} else if (options.dataType === "object") {
|
|
1895
|
+
if (typeof value === "string") {
|
|
1896
|
+
try {
|
|
1897
|
+
value = JSON.parse(value);
|
|
1898
|
+
} catch (_e) {
|
|
1899
|
+
if (options.throwError !== false) {
|
|
1900
|
+
throw new BadRequestException(`Invalid JSON object${paramName}`);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
} else if (options.type) {
|
|
1905
|
+
const originalValue = value;
|
|
1906
|
+
value = convertType(value, options.type);
|
|
1907
|
+
if (options.throwError === false) {
|
|
1908
|
+
if (options.type === "number" && typeof value === "number") {
|
|
1909
|
+
if (options.min !== void 0 && value < options.min) {
|
|
1910
|
+
value = void 0;
|
|
1911
|
+
}
|
|
1912
|
+
if (options.max !== void 0 && value > options.max) {
|
|
1913
|
+
value = void 0;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
const paramNotMatchMsg = `Parameter '${key}' does not match pattern: ${options.patternName || options.pattern}`;
|
|
1918
|
+
if (options.type === "string" && options.pattern && typeof value === "string" && !options.pattern.test(value)) {
|
|
1919
|
+
throw new BadRequestException(paramNotMatchMsg);
|
|
1920
|
+
} else if (options.type === "number" && options.pattern && typeof value === "number" && !options.pattern.test(String(value))) {
|
|
1921
|
+
throw new BadRequestException(paramNotMatchMsg);
|
|
1922
|
+
}
|
|
1923
|
+
if (options.throwError !== false) {
|
|
1924
|
+
if (options.type === "number" && typeof value === "number" && Number.isNaN(value)) {
|
|
1925
|
+
throw new BadRequestException(`Type error: expected number${paramName}`);
|
|
1926
|
+
}
|
|
1927
|
+
if (options.type === "number" && typeof value === "number") {
|
|
1928
|
+
if (options.min !== void 0 && value < options.min) {
|
|
1929
|
+
throw new BadRequestException(`Validation error: number must be >= ${options.min}${paramName}`);
|
|
1930
|
+
}
|
|
1931
|
+
if (options.max !== void 0 && value > options.max) {
|
|
1932
|
+
throw new BadRequestException(`Validation error: number must be <= ${options.max}${paramName}`);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (options.type === "boolean" && !isValidBooleanInput(originalValue)) {
|
|
1936
|
+
throw new BadRequestException(`Type error: expected boolean${paramName}`);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
if (options.transform && typeof options.transform === "function") {
|
|
1942
|
+
value = options.transform(value);
|
|
1943
|
+
}
|
|
1944
|
+
if (options.validate && typeof options.validate === "function") {
|
|
1945
|
+
if (!options.validate(value)) {
|
|
1946
|
+
if (options.throwError !== false) {
|
|
1947
|
+
throw new BadRequestException(`Parameter validation failed${paramName}`);
|
|
1948
|
+
}
|
|
1949
|
+
return void 0;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
return value;
|
|
1953
|
+
}
|
|
1954
|
+
__name(applyParamOptions, "applyParamOptions");
|
|
1955
|
+
function isValidBooleanInput(value) {
|
|
1956
|
+
if (typeof value === "boolean") return true;
|
|
1957
|
+
if (typeof value === "number") return value === 0 || value === 1;
|
|
1958
|
+
if (typeof value === "string") {
|
|
1959
|
+
const normalizedValue = value.toLowerCase().trim();
|
|
1960
|
+
return [
|
|
1961
|
+
"true",
|
|
1962
|
+
"false",
|
|
1963
|
+
"0",
|
|
1964
|
+
"1",
|
|
1965
|
+
"yes",
|
|
1966
|
+
"no"
|
|
1967
|
+
].includes(normalizedValue);
|
|
1968
|
+
}
|
|
1969
|
+
return false;
|
|
1970
|
+
}
|
|
1971
|
+
__name(isValidBooleanInput, "isValidBooleanInput");
|
|
1972
|
+
function convertType(value, type) {
|
|
1973
|
+
if (value === void 0 || value === null) {
|
|
1974
|
+
return value;
|
|
1975
|
+
}
|
|
1976
|
+
switch (type) {
|
|
1977
|
+
case "number":
|
|
1978
|
+
return Number(value);
|
|
1979
|
+
case "boolean":
|
|
1980
|
+
if (typeof value === "string") {
|
|
1981
|
+
const normalizedValue = value.toLowerCase().trim();
|
|
1982
|
+
return normalizedValue === "true" || normalizedValue === "1" || normalizedValue === "yes";
|
|
1983
|
+
}
|
|
1984
|
+
return value === true || value === 1;
|
|
1985
|
+
case "string":
|
|
1986
|
+
default:
|
|
1987
|
+
return String(value);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
__name(convertType, "convertType");
|
|
1991
|
+
/*! Bundled license information:
|
|
1992
|
+
|
|
1993
|
+
reflect-metadata/Reflect.js:
|
|
1994
|
+
(*! *****************************************************************************
|
|
1995
|
+
Copyright (C) Microsoft. All rights reserved.
|
|
1996
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
1997
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
1998
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1999
|
+
|
|
2000
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
2001
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
2002
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
2003
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
2004
|
+
|
|
2005
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
2006
|
+
and limitations under the License.
|
|
2007
|
+
***************************************************************************** *)
|
|
2008
|
+
*/
|
|
2009
|
+
|
|
2010
|
+
export { After, Before, Body, Cache, Connect, ContentType, Controller, DIContainer, Delete, Get, Head, Header, Headers, HttpCode, Inject, Injectable, Log, Options, Param, Patch, Post, Put, Query, RateLimit, Redirect, Req, ReqCookie, ReqHeader, ReqId, ReqLogger, Res, Roles, Timeout, Trace, Use, Version, createParamDecorator, createParamDecoratorWithoutParam, inject, registerControllers };
|