@catbee/utils 0.0.1 → 0.0.2
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/README.md +303 -107
- package/build/esm/config.d.ts +12 -0
- package/build/esm/config.js +12 -0
- package/build/esm/config.js.map +1 -1
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/types/api-response.d.ts +82 -0
- package/build/esm/types/api-response.js.map +1 -1
- package/build/esm/utils/array.utils.d.ts +64 -1
- package/build/esm/utils/array.utils.js +139 -2
- package/build/esm/utils/array.utils.js.map +1 -1
- package/build/esm/utils/async.utils.d.ts +60 -1
- package/build/esm/utils/async.utils.js +160 -2
- package/build/esm/utils/async.utils.js.map +1 -1
- package/build/esm/utils/cache.utils.d.ts +67 -4
- package/build/esm/utils/cache.utils.js +210 -28
- package/build/esm/utils/cache.utils.js.map +1 -1
- package/build/esm/utils/context-store.utils.d.ts +101 -0
- package/build/esm/utils/context-store.utils.js +182 -0
- package/build/esm/utils/context-store.utils.js.map +1 -1
- package/build/esm/utils/crypto.utils.d.ts +110 -8
- package/build/esm/utils/crypto.utils.js +298 -15
- package/build/esm/utils/crypto.utils.js.map +1 -1
- package/build/esm/utils/decorators.utils.d.ts +40 -0
- package/build/esm/utils/decorators.utils.js +312 -0
- package/build/esm/utils/decorators.utils.js.map +1 -0
- package/build/esm/utils/dir.utils.d.ts +121 -0
- package/build/esm/utils/dir.utils.js +577 -0
- package/build/esm/utils/dir.utils.js.map +1 -1
- package/build/esm/utils/env.utils.d.ts +83 -0
- package/build/esm/utils/env.utils.js +233 -0
- package/build/esm/utils/env.utils.js.map +1 -1
- package/build/esm/utils/exception.utils.d.ts +116 -0
- package/build/esm/utils/exception.utils.js +322 -0
- package/build/esm/utils/exception.utils.js.map +1 -1
- package/build/esm/utils/fs.utils.d.ts +132 -0
- package/build/esm/utils/fs.utils.js +421 -0
- package/build/esm/utils/fs.utils.js.map +1 -1
- package/build/esm/utils/http-status-codes.d.ts +87 -178
- package/build/esm/utils/http-status-codes.js +92 -178
- package/build/esm/utils/http-status-codes.js.map +1 -1
- package/build/esm/utils/id.utils.d.ts +11 -10
- package/build/esm/utils/id.utils.js +29 -20
- package/build/esm/utils/id.utils.js.map +1 -1
- package/build/esm/utils/logger.utils.d.ts +24 -0
- package/build/esm/utils/logger.utils.js +54 -0
- package/build/esm/utils/logger.utils.js.map +1 -1
- package/build/esm/utils/middleware.utils.d.ts +72 -0
- package/build/esm/utils/middleware.utils.js +158 -0
- package/build/esm/utils/middleware.utils.js.map +1 -0
- package/build/esm/utils/obj.utils.d.ts +65 -3
- package/build/esm/utils/obj.utils.js +205 -6
- package/build/esm/utils/obj.utils.js.map +1 -1
- package/build/esm/utils/response.utils.d.ts +101 -0
- package/build/esm/utils/response.utils.js +153 -0
- package/build/esm/utils/response.utils.js.map +1 -1
- package/build/esm/utils/string.utils.d.ts +61 -5
- package/build/esm/utils/string.utils.js +101 -11
- package/build/esm/utils/string.utils.js.map +1 -1
- package/build/esm/utils/url.utils.d.ts +117 -0
- package/build/esm/utils/url.utils.js +287 -0
- package/build/esm/utils/url.utils.js.map +1 -1
- package/build/esm/utils/validate.utils.d.ts +110 -0
- package/build/esm/utils/validate.utils.js +186 -0
- package/build/esm/utils/validate.utils.js.map +1 -1
- package/build/esnext/config.d.ts +12 -0
- package/build/esnext/config.js +12 -0
- package/build/esnext/config.js.map +1 -1
- package/build/esnext/index.d.ts +1 -0
- package/build/esnext/index.js +1 -0
- package/build/esnext/index.js.map +1 -1
- package/build/esnext/types/api-response.d.ts +82 -0
- package/build/esnext/types/api-response.js.map +1 -1
- package/build/esnext/utils/array.utils.d.ts +64 -1
- package/build/esnext/utils/array.utils.js +129 -2
- package/build/esnext/utils/array.utils.js.map +1 -1
- package/build/esnext/utils/async.utils.d.ts +60 -1
- package/build/esnext/utils/async.utils.js +117 -1
- package/build/esnext/utils/async.utils.js.map +1 -1
- package/build/esnext/utils/cache.utils.d.ts +67 -4
- package/build/esnext/utils/cache.utils.js +137 -9
- package/build/esnext/utils/cache.utils.js.map +1 -1
- package/build/esnext/utils/context-store.utils.d.ts +101 -0
- package/build/esnext/utils/context-store.utils.js +168 -0
- package/build/esnext/utils/context-store.utils.js.map +1 -1
- package/build/esnext/utils/crypto.utils.d.ts +110 -8
- package/build/esnext/utils/crypto.utils.js +205 -15
- package/build/esnext/utils/crypto.utils.js.map +1 -1
- package/build/esnext/utils/decorators.utils.d.ts +40 -0
- package/build/esnext/utils/decorators.utils.js +155 -0
- package/build/esnext/utils/decorators.utils.js.map +1 -0
- package/build/esnext/utils/dir.utils.d.ts +121 -0
- package/build/esnext/utils/dir.utils.js +306 -0
- package/build/esnext/utils/dir.utils.js.map +1 -1
- package/build/esnext/utils/env.utils.d.ts +83 -0
- package/build/esnext/utils/env.utils.js +185 -0
- package/build/esnext/utils/env.utils.js.map +1 -1
- package/build/esnext/utils/exception.utils.d.ts +116 -0
- package/build/esnext/utils/exception.utils.js +213 -0
- package/build/esnext/utils/exception.utils.js.map +1 -1
- package/build/esnext/utils/fs.utils.d.ts +132 -0
- package/build/esnext/utils/fs.utils.js +268 -0
- package/build/esnext/utils/fs.utils.js.map +1 -1
- package/build/esnext/utils/http-status-codes.d.ts +87 -178
- package/build/esnext/utils/http-status-codes.js +92 -178
- package/build/esnext/utils/http-status-codes.js.map +1 -1
- package/build/esnext/utils/id.utils.d.ts +11 -10
- package/build/esnext/utils/id.utils.js +27 -19
- package/build/esnext/utils/id.utils.js.map +1 -1
- package/build/esnext/utils/logger.utils.d.ts +24 -0
- package/build/esnext/utils/logger.utils.js +42 -0
- package/build/esnext/utils/logger.utils.js.map +1 -1
- package/build/esnext/utils/middleware.utils.d.ts +72 -0
- package/build/esnext/utils/middleware.utils.js +157 -0
- package/build/esnext/utils/middleware.utils.js.map +1 -0
- package/build/esnext/utils/obj.utils.d.ts +65 -3
- package/build/esnext/utils/obj.utils.js +167 -3
- package/build/esnext/utils/obj.utils.js.map +1 -1
- package/build/esnext/utils/response.utils.d.ts +101 -0
- package/build/esnext/utils/response.utils.js +138 -0
- package/build/esnext/utils/response.utils.js.map +1 -1
- package/build/esnext/utils/string.utils.d.ts +61 -5
- package/build/esnext/utils/string.utils.js +110 -14
- package/build/esnext/utils/string.utils.js.map +1 -1
- package/build/esnext/utils/url.utils.d.ts +117 -0
- package/build/esnext/utils/url.utils.js +248 -0
- package/build/esnext/utils/url.utils.js.map +1 -1
- package/build/esnext/utils/validate.utils.d.ts +110 -0
- package/build/esnext/utils/validate.utils.js +184 -0
- package/build/esnext/utils/validate.utils.js.map +1 -1
- package/build/src/config.d.ts +12 -0
- package/build/src/config.js +12 -0
- package/build/src/config.js.map +1 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/types/api-response.d.ts +82 -0
- package/build/src/types/api-response.js.map +1 -1
- package/build/src/utils/array.utils.d.ts +64 -1
- package/build/src/utils/array.utils.js +137 -4
- package/build/src/utils/array.utils.js.map +1 -1
- package/build/src/utils/async.utils.d.ts +60 -1
- package/build/src/utils/async.utils.js +124 -4
- package/build/src/utils/async.utils.js.map +1 -1
- package/build/src/utils/cache.utils.d.ts +67 -4
- package/build/src/utils/cache.utils.js +137 -9
- package/build/src/utils/cache.utils.js.map +1 -1
- package/build/src/utils/context-store.utils.d.ts +101 -0
- package/build/src/utils/context-store.utils.js +171 -1
- package/build/src/utils/context-store.utils.js.map +1 -1
- package/build/src/utils/crypto.utils.d.ts +110 -8
- package/build/src/utils/crypto.utils.js +224 -27
- package/build/src/utils/crypto.utils.js.map +1 -1
- package/build/src/utils/decorators.utils.d.ts +40 -0
- package/build/src/utils/decorators.utils.js +165 -0
- package/build/src/utils/decorators.utils.js.map +1 -0
- package/build/src/utils/dir.utils.d.ts +121 -0
- package/build/src/utils/dir.utils.js +316 -0
- package/build/src/utils/dir.utils.js.map +1 -1
- package/build/src/utils/env.utils.d.ts +83 -0
- package/build/src/utils/env.utils.js +186 -1
- package/build/src/utils/env.utils.js.map +1 -1
- package/build/src/utils/exception.utils.d.ts +116 -0
- package/build/src/utils/exception.utils.js +226 -1
- package/build/src/utils/exception.utils.js.map +1 -1
- package/build/src/utils/fs.utils.d.ts +132 -0
- package/build/src/utils/fs.utils.js +282 -0
- package/build/src/utils/fs.utils.js.map +1 -1
- package/build/src/utils/http-status-codes.d.ts +87 -178
- package/build/src/utils/http-status-codes.js +92 -178
- package/build/src/utils/http-status-codes.js.map +1 -1
- package/build/src/utils/id.utils.d.ts +11 -10
- package/build/src/utils/id.utils.js +27 -19
- package/build/src/utils/id.utils.js.map +1 -1
- package/build/src/utils/logger.utils.d.ts +24 -0
- package/build/src/utils/logger.utils.js +45 -0
- package/build/src/utils/logger.utils.js.map +1 -1
- package/build/src/utils/middleware.utils.d.ts +72 -0
- package/build/src/utils/middleware.utils.js +163 -0
- package/build/src/utils/middleware.utils.js.map +1 -0
- package/build/src/utils/obj.utils.d.ts +65 -3
- package/build/src/utils/obj.utils.js +177 -7
- package/build/src/utils/obj.utils.js.map +1 -1
- package/build/src/utils/response.utils.d.ts +101 -0
- package/build/src/utils/response.utils.js +146 -1
- package/build/src/utils/response.utils.js.map +1 -1
- package/build/src/utils/string.utils.d.ts +61 -5
- package/build/src/utils/string.utils.js +122 -20
- package/build/src/utils/string.utils.js.map +1 -1
- package/build/src/utils/url.utils.d.ts +117 -0
- package/build/src/utils/url.utils.js +257 -0
- package/build/src/utils/url.utils.js.map +1 -1
- package/build/src/utils/validate.utils.d.ts +110 -0
- package/build/src/utils/validate.utils.js +198 -0
- package/build/src/utils/validate.utils.js.map +1 -1
- package/package.json +20 -12
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
63
|
+
var __values = (this && this.__values) || function(o) {
|
|
64
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
65
|
+
if (m) return m.call(o);
|
|
66
|
+
if (o && typeof o.length === "number") return {
|
|
67
|
+
next: function () {
|
|
68
|
+
if (o && i >= o.length) o = void 0;
|
|
69
|
+
return { value: o && o[i++], done: !o };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
|
+
};
|
|
74
|
+
import "reflect-metadata";
|
|
75
|
+
// --- End sample Express interfaces ---
|
|
76
|
+
var ROUTES_KEY = Symbol("routes");
|
|
77
|
+
var MIDDLEWARE_KEY = Symbol("middlewares");
|
|
78
|
+
var PARAMS_KEY = Symbol("params");
|
|
79
|
+
// ---- Route Decorators ----
|
|
80
|
+
function createRouteDecorator(method) {
|
|
81
|
+
return function (path) {
|
|
82
|
+
return function (target, propertyKey, descriptor) {
|
|
83
|
+
var routes = Reflect.getMetadata(ROUTES_KEY, target.constructor) || [];
|
|
84
|
+
routes.push({
|
|
85
|
+
path: path,
|
|
86
|
+
method: method,
|
|
87
|
+
handlerName: propertyKey,
|
|
88
|
+
});
|
|
89
|
+
Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export var Get = createRouteDecorator("get");
|
|
94
|
+
export var Post = createRouteDecorator("post");
|
|
95
|
+
export var Put = createRouteDecorator("put");
|
|
96
|
+
export var Patch = createRouteDecorator("patch");
|
|
97
|
+
export var Delete = createRouteDecorator("delete");
|
|
98
|
+
export var Options = createRouteDecorator("options");
|
|
99
|
+
export var Head = createRouteDecorator("head");
|
|
100
|
+
export var Trace = createRouteDecorator("trace");
|
|
101
|
+
export var Connect = createRouteDecorator("connect");
|
|
102
|
+
// ---- Controller Decorator ----
|
|
103
|
+
export function Controller(basePath) {
|
|
104
|
+
return function (target) {
|
|
105
|
+
Reflect.defineMetadata("basePath", basePath, target);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// ---- Middleware Decorator ----
|
|
109
|
+
export function Use() {
|
|
110
|
+
var middlewares = [];
|
|
111
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
112
|
+
middlewares[_i] = arguments[_i];
|
|
113
|
+
}
|
|
114
|
+
return function (target, propertyKey, descriptor) {
|
|
115
|
+
var existing = Reflect.getMetadata(MIDDLEWARE_KEY, target, propertyKey) || [];
|
|
116
|
+
Reflect.defineMetadata(MIDDLEWARE_KEY, __spreadArray(__spreadArray([], __read(existing), false), __read(middlewares), false), target, propertyKey);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// ---- Parameter Decorators ----
|
|
120
|
+
function createParamDecorator(type, key) {
|
|
121
|
+
return function (paramKey) {
|
|
122
|
+
return function (target, propertyKey, parameterIndex) {
|
|
123
|
+
var params = Reflect.getMetadata(PARAMS_KEY, target, propertyKey) || [];
|
|
124
|
+
// Ensure parameters are ordered by index
|
|
125
|
+
params.push({ index: parameterIndex, type: type, key: paramKey || key });
|
|
126
|
+
params.sort(function (a, b) { return a.index - b.index; });
|
|
127
|
+
Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey);
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export var Query = createParamDecorator("query");
|
|
132
|
+
export var Param = createParamDecorator("param");
|
|
133
|
+
export var Body = createParamDecorator("body");
|
|
134
|
+
export var Req = createParamDecorator("req");
|
|
135
|
+
export var Res = createParamDecorator("res");
|
|
136
|
+
// Custom HTTP status code decorator
|
|
137
|
+
var HTTP_CODE_KEY = Symbol("httpCode");
|
|
138
|
+
export function HttpCode(status) {
|
|
139
|
+
return function (target, propertyKey, descriptor) {
|
|
140
|
+
Reflect.defineMetadata(HTTP_CODE_KEY, status, target, propertyKey);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Custom header decorator
|
|
144
|
+
var HEADER_KEY = Symbol("headers");
|
|
145
|
+
export function Header(name, value) {
|
|
146
|
+
return function (target, propertyKey, descriptor) {
|
|
147
|
+
var headers = Reflect.getMetadata(HEADER_KEY, target, propertyKey) || {};
|
|
148
|
+
headers[name] = value;
|
|
149
|
+
Reflect.defineMetadata(HEADER_KEY, headers, target, propertyKey);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// Before/After hooks (not Express middleware, but can be used for logging, etc.)
|
|
153
|
+
var BEFORE_KEY = Symbol("before");
|
|
154
|
+
var AFTER_KEY = Symbol("after");
|
|
155
|
+
export function Before(fn) {
|
|
156
|
+
return function (target, propertyKey, descriptor) {
|
|
157
|
+
var hooks = Reflect.getMetadata(BEFORE_KEY, target, propertyKey) || [];
|
|
158
|
+
hooks.push(fn);
|
|
159
|
+
Reflect.defineMetadata(BEFORE_KEY, hooks, target, propertyKey);
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export function After(fn) {
|
|
163
|
+
return function (target, propertyKey, descriptor) {
|
|
164
|
+
var hooks = Reflect.getMetadata(AFTER_KEY, target, propertyKey) || [];
|
|
165
|
+
hooks.push(fn);
|
|
166
|
+
Reflect.defineMetadata(AFTER_KEY, hooks, target, propertyKey);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// ---- Register Controllers ----
|
|
170
|
+
export function registerControllers(router, controllers) {
|
|
171
|
+
var _this = this;
|
|
172
|
+
controllers.forEach(function (ControllerClass) {
|
|
173
|
+
var instance = new ControllerClass();
|
|
174
|
+
var basePath = Reflect.getMetadata("basePath", ControllerClass) || "";
|
|
175
|
+
var routes = Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];
|
|
176
|
+
routes.forEach(function (_a) {
|
|
177
|
+
var _b;
|
|
178
|
+
var path = _a.path, method = _a.method, handlerName = _a.handlerName;
|
|
179
|
+
var middlewares = Reflect.getMetadata(MIDDLEWARE_KEY, instance, handlerName) || [];
|
|
180
|
+
var params = Reflect.getMetadata(PARAMS_KEY, instance, handlerName) || [];
|
|
181
|
+
var httpCode = Reflect.getMetadata(HTTP_CODE_KEY, instance, handlerName);
|
|
182
|
+
var headers = Reflect.getMetadata(HEADER_KEY, instance, handlerName) || {};
|
|
183
|
+
var beforeHooks = Reflect.getMetadata(BEFORE_KEY, instance, handlerName) || [];
|
|
184
|
+
var afterHooks = Reflect.getMetadata(AFTER_KEY, instance, handlerName) || [];
|
|
185
|
+
var handler = function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
186
|
+
var beforeHooks_1, beforeHooks_1_1, fn, e_1_1, args_1, result, awaited, _a, _b, _c, _d, k, v, afterHooks_1, afterHooks_1_1, fn, e_2_1, err_1;
|
|
187
|
+
var e_1, _e, _f, e_3, _g, e_2, _h;
|
|
188
|
+
var _j, _k;
|
|
189
|
+
return __generator(this, function (_l) {
|
|
190
|
+
switch (_l.label) {
|
|
191
|
+
case 0:
|
|
192
|
+
_l.trys.push([0, 20, , 21]);
|
|
193
|
+
_l.label = 1;
|
|
194
|
+
case 1:
|
|
195
|
+
_l.trys.push([1, 6, 7, 8]);
|
|
196
|
+
beforeHooks_1 = __values(beforeHooks), beforeHooks_1_1 = beforeHooks_1.next();
|
|
197
|
+
_l.label = 2;
|
|
198
|
+
case 2:
|
|
199
|
+
if (!!beforeHooks_1_1.done) return [3 /*break*/, 5];
|
|
200
|
+
fn = beforeHooks_1_1.value;
|
|
201
|
+
return [4 /*yield*/, fn(req, res)];
|
|
202
|
+
case 3:
|
|
203
|
+
_l.sent();
|
|
204
|
+
_l.label = 4;
|
|
205
|
+
case 4:
|
|
206
|
+
beforeHooks_1_1 = beforeHooks_1.next();
|
|
207
|
+
return [3 /*break*/, 2];
|
|
208
|
+
case 5: return [3 /*break*/, 8];
|
|
209
|
+
case 6:
|
|
210
|
+
e_1_1 = _l.sent();
|
|
211
|
+
e_1 = { error: e_1_1 };
|
|
212
|
+
return [3 /*break*/, 8];
|
|
213
|
+
case 7:
|
|
214
|
+
try {
|
|
215
|
+
if (beforeHooks_1_1 && !beforeHooks_1_1.done && (_e = beforeHooks_1.return)) _e.call(beforeHooks_1);
|
|
216
|
+
}
|
|
217
|
+
finally { if (e_1) throw e_1.error; }
|
|
218
|
+
return [7 /*endfinally*/];
|
|
219
|
+
case 8:
|
|
220
|
+
args_1 = [];
|
|
221
|
+
if (params.length) {
|
|
222
|
+
params.forEach(function (_a) {
|
|
223
|
+
var _b;
|
|
224
|
+
var index = _a.index, type = _a.type, key = _a.key;
|
|
225
|
+
switch (type) {
|
|
226
|
+
case "query":
|
|
227
|
+
args_1[index] = key ? req.query[key] : req.query;
|
|
228
|
+
break;
|
|
229
|
+
case "param":
|
|
230
|
+
args_1[index] = key ? req.params[key] : req.params;
|
|
231
|
+
break;
|
|
232
|
+
case "body":
|
|
233
|
+
args_1[index] = key ? (_b = req.body) === null || _b === void 0 ? void 0 : _b[key] : req.body;
|
|
234
|
+
break;
|
|
235
|
+
case "req":
|
|
236
|
+
args_1[index] = req;
|
|
237
|
+
break;
|
|
238
|
+
case "res":
|
|
239
|
+
args_1[index] = res;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
result = (_f = instance)[handlerName].apply(_f, __spreadArray([], __read(args_1), false));
|
|
245
|
+
if (!(result instanceof Promise)) return [3 /*break*/, 10];
|
|
246
|
+
return [4 /*yield*/, result];
|
|
247
|
+
case 9:
|
|
248
|
+
_a = _l.sent();
|
|
249
|
+
return [3 /*break*/, 11];
|
|
250
|
+
case 10:
|
|
251
|
+
_a = result;
|
|
252
|
+
_l.label = 11;
|
|
253
|
+
case 11:
|
|
254
|
+
awaited = _a;
|
|
255
|
+
if (!res.headersSent && typeof awaited !== "undefined") {
|
|
256
|
+
if (httpCode)
|
|
257
|
+
(_j = res.status) === null || _j === void 0 ? void 0 : _j.call(res, httpCode);
|
|
258
|
+
try {
|
|
259
|
+
for (_b = __values(Object.entries(headers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
260
|
+
_d = __read(_c.value, 2), k = _d[0], v = _d[1];
|
|
261
|
+
(_k = res.set) === null || _k === void 0 ? void 0 : _k.call(res, k, v);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
265
|
+
finally {
|
|
266
|
+
try {
|
|
267
|
+
if (_c && !_c.done && (_g = _b.return)) _g.call(_b);
|
|
268
|
+
}
|
|
269
|
+
finally { if (e_3) throw e_3.error; }
|
|
270
|
+
}
|
|
271
|
+
res.json(awaited);
|
|
272
|
+
}
|
|
273
|
+
_l.label = 12;
|
|
274
|
+
case 12:
|
|
275
|
+
_l.trys.push([12, 17, 18, 19]);
|
|
276
|
+
afterHooks_1 = __values(afterHooks), afterHooks_1_1 = afterHooks_1.next();
|
|
277
|
+
_l.label = 13;
|
|
278
|
+
case 13:
|
|
279
|
+
if (!!afterHooks_1_1.done) return [3 /*break*/, 16];
|
|
280
|
+
fn = afterHooks_1_1.value;
|
|
281
|
+
return [4 /*yield*/, fn(req, res, awaited)];
|
|
282
|
+
case 14:
|
|
283
|
+
_l.sent();
|
|
284
|
+
_l.label = 15;
|
|
285
|
+
case 15:
|
|
286
|
+
afterHooks_1_1 = afterHooks_1.next();
|
|
287
|
+
return [3 /*break*/, 13];
|
|
288
|
+
case 16: return [3 /*break*/, 19];
|
|
289
|
+
case 17:
|
|
290
|
+
e_2_1 = _l.sent();
|
|
291
|
+
e_2 = { error: e_2_1 };
|
|
292
|
+
return [3 /*break*/, 19];
|
|
293
|
+
case 18:
|
|
294
|
+
try {
|
|
295
|
+
if (afterHooks_1_1 && !afterHooks_1_1.done && (_h = afterHooks_1.return)) _h.call(afterHooks_1);
|
|
296
|
+
}
|
|
297
|
+
finally { if (e_2) throw e_2.error; }
|
|
298
|
+
return [7 /*endfinally*/];
|
|
299
|
+
case 19: return [3 /*break*/, 21];
|
|
300
|
+
case 20:
|
|
301
|
+
err_1 = _l.sent();
|
|
302
|
+
next(err_1);
|
|
303
|
+
return [3 /*break*/, 21];
|
|
304
|
+
case 21: return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); };
|
|
308
|
+
(_b = router)[method].apply(_b, __spreadArray(__spreadArray([basePath + path], __read(middlewares), false), [handler], false));
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=decorators.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.utils.js","sourceRoot":"","sources":["../../../src/utils/decorators.utils.ts"],"names":[],"mappings":"AAAA,sDAAsD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtD,OAAO,kBAAkB,CAAC;AAuB1B,wCAAwC;AAExC,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpC,IAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAC7C,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAyBpC,6BAA6B;AAC7B,SAAS,oBAAoB,CAAC,MAAkB;IAC9C,OAAO,UAAC,IAAY;QAClB,OAAO,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;YACrC,IAAM,MAAM,GACV,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAC5D,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,MAAA;gBACJ,MAAM,QAAA;gBACN,WAAW,EAAE,WAAqB;aACnC,CAAC,CAAC;YACH,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACjE,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,IAAM,GAAG,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAC/C,MAAM,CAAC,IAAM,IAAI,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,CAAC,IAAM,GAAG,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAC/C,MAAM,CAAC,IAAM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AC,CAAA;wCAAjC,KAAA,mBAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;wCAA8B,MAAA,GAAG,CAAC,GAAG,oDAAG,CAAC,EAAE,CAAC,CAAC,CAAC;qCAAA;;;;;;;;;gCAC9D,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;4BACpB,CAAC;;;;4BACgB,eAAA,SAAA,UAAU,CAAA;;;;4BAAhB,EAAE;4BAAgB,qBAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAA;;4BAA3B,SAA2B,CAAC;;;;;;;;;;;;;;;;;;;4BAEzD,IAAI,CAAC,KAAG,CAAC,CAAC;;;;;iBAEb,CAAC;YAEF,CAAA,KAAC,MAAc,CAAA,CAAC,MAAM,CAAC,wCAAC,QAAQ,GAAG,IAAI,UAAK,WAAW,YAAE,OAAO,WAAE;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport \"reflect-metadata\";\n\n// --- Sample Express interfaces for type safety ---\nexport interface Request {\n query: any;\n params: any;\n body?: any;\n [key: string]: any;\n}\nexport interface Response {\n json: (body: any) => void;\n headersSent: boolean;\n [key: string]: any;\n}\nexport type NextFunction = (err?: any) => void;\nexport type RequestHandler = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => any;\nexport interface Router {\n [method: string]: (path: string, ...handlers: RequestHandler[]) => void;\n}\n// --- End sample Express interfaces ---\n\nconst ROUTES_KEY = Symbol(\"routes\");\nconst MIDDLEWARE_KEY = Symbol(\"middlewares\");\nconst PARAMS_KEY = Symbol(\"params\");\n\nexport type HttpMethod =\n | \"get\"\n | \"post\"\n | \"put\"\n | \"patch\"\n | \"delete\"\n | \"options\"\n | \"head\"\n | \"trace\"\n | \"connect\";\n\ninterface RouteDefinition {\n path: string;\n method: HttpMethod;\n handlerName: string;\n}\n\ninterface ParamDefinition {\n index: number;\n type: \"query\" | \"param\" | \"body\" | \"req\" | \"res\";\n key?: string;\n}\n\n// ---- Route Decorators ----\nfunction createRouteDecorator(method: HttpMethod) {\n return (path: string): MethodDecorator => {\n return (target, propertyKey, descriptor) => {\n const routes: RouteDefinition[] =\n Reflect.getMetadata(ROUTES_KEY, target.constructor) || [];\n routes.push({\n path,\n method,\n handlerName: propertyKey as string,\n });\n Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);\n };\n };\n}\n\nexport const Get = createRouteDecorator(\"get\");\nexport const Post = createRouteDecorator(\"post\");\nexport const Put = createRouteDecorator(\"put\");\nexport const Patch = createRouteDecorator(\"patch\");\nexport const Delete = createRouteDecorator(\"delete\");\nexport const Options = createRouteDecorator(\"options\");\nexport const Head = createRouteDecorator(\"head\");\nexport const Trace = createRouteDecorator(\"trace\");\nexport const Connect = createRouteDecorator(\"connect\");\n\n// ---- Controller Decorator ----\nexport function Controller(basePath: string): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(\"basePath\", basePath, target);\n };\n}\n\n// ---- Middleware Decorator ----\nexport function Use(...middlewares: RequestHandler[]): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const existing: RequestHandler[] =\n Reflect.getMetadata(MIDDLEWARE_KEY, target, propertyKey as string) || [];\n Reflect.defineMetadata(\n MIDDLEWARE_KEY,\n [...existing, ...middlewares],\n target,\n propertyKey as string,\n );\n };\n}\n\n// ---- Parameter Decorators ----\nfunction createParamDecorator(type: ParamDefinition[\"type\"], key?: string) {\n return (paramKey?: string): ParameterDecorator => {\n return (target, propertyKey, parameterIndex) => {\n const params: ParamDefinition[] =\n Reflect.getMetadata(PARAMS_KEY, target, propertyKey as string) || [];\n // Ensure parameters are ordered by index\n params.push({ index: parameterIndex, type, key: paramKey || key });\n params.sort((a, b) => a.index - b.index);\n Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey as string);\n };\n };\n}\n\nexport const Query = createParamDecorator(\"query\");\nexport const Param = createParamDecorator(\"param\");\nexport const Body = createParamDecorator(\"body\");\nexport const Req = createParamDecorator(\"req\");\nexport const Res = createParamDecorator(\"res\");\n\n// Custom HTTP status code decorator\nconst HTTP_CODE_KEY = Symbol(\"httpCode\");\nexport function HttpCode(status: number): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n Reflect.defineMetadata(\n HTTP_CODE_KEY,\n status,\n target,\n propertyKey as string,\n );\n };\n}\n\n// Custom header decorator\nconst HEADER_KEY = Symbol(\"headers\");\nexport function Header(name: string, value: string): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const headers: Record<string, string> =\n Reflect.getMetadata(HEADER_KEY, target, propertyKey as string) || {};\n headers[name] = value;\n Reflect.defineMetadata(HEADER_KEY, headers, target, propertyKey as string);\n };\n}\n\n// Before/After hooks (not Express middleware, but can be used for logging, etc.)\nconst BEFORE_KEY = Symbol(\"before\");\nconst AFTER_KEY = Symbol(\"after\");\nexport function Before(fn: Function): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const hooks: Function[] =\n Reflect.getMetadata(BEFORE_KEY, target, propertyKey as string) || [];\n hooks.push(fn);\n Reflect.defineMetadata(BEFORE_KEY, hooks, target, propertyKey as string);\n };\n}\nexport function After(fn: Function): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const hooks: Function[] =\n Reflect.getMetadata(AFTER_KEY, target, propertyKey as string) || [];\n hooks.push(fn);\n Reflect.defineMetadata(AFTER_KEY, hooks, target, propertyKey as string);\n };\n}\n\n// ---- Register Controllers ----\nexport function registerControllers(router: Router, controllers: any[]) {\n controllers.forEach((ControllerClass) => {\n const instance = new ControllerClass();\n const basePath: string =\n Reflect.getMetadata(\"basePath\", ControllerClass) || \"\";\n const routes: RouteDefinition[] =\n Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];\n\n routes.forEach(({ path, method, handlerName }) => {\n const middlewares: RequestHandler[] =\n Reflect.getMetadata(MIDDLEWARE_KEY, instance, handlerName) || [];\n const params: ParamDefinition[] =\n Reflect.getMetadata(PARAMS_KEY, instance, handlerName) || [];\n\n const httpCode: number | undefined = Reflect.getMetadata(\n HTTP_CODE_KEY,\n instance,\n handlerName,\n );\n const headers: Record<string, string> =\n Reflect.getMetadata(HEADER_KEY, instance, handlerName) || {};\n const beforeHooks: Function[] =\n Reflect.getMetadata(BEFORE_KEY, instance, handlerName) || [];\n const afterHooks: Function[] =\n Reflect.getMetadata(AFTER_KEY, instance, handlerName) || [];\n\n const handler: RequestHandler = async (req, res, next) => {\n try {\n for (const fn of beforeHooks) await fn(req, res);\n const args: any[] = [];\n if (params.length) {\n params.forEach(({ index, type, key }) => {\n switch (type) {\n case \"query\":\n args[index] = key ? req.query[key] : req.query;\n break;\n case \"param\":\n args[index] = key ? req.params[key] : req.params;\n break;\n case \"body\":\n args[index] = key ? req.body?.[key] : req.body;\n break;\n case \"req\":\n args[index] = req;\n break;\n case \"res\":\n args[index] = res;\n break;\n }\n });\n }\n const result = (instance as any)[handlerName](...args);\n // Support both sync and async handlers\n const awaited = result instanceof Promise ? await result : result;\n if (!res.headersSent && typeof awaited !== \"undefined\") {\n if (httpCode) res.status?.(httpCode);\n for (const [k, v] of Object.entries(headers)) res.set?.(k, v);\n res.json(awaited);\n }\n for (const fn of afterHooks) await fn(req, res, awaited);\n } catch (err) {\n next(err);\n }\n };\n\n (router as any)[method](basePath + path, ...middlewares, handler);\n });\n });\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "fs";
|
|
1
2
|
/**
|
|
2
3
|
* Ensures that a directory exists, creating parent directories if needed (like `mkdir -p`).
|
|
3
4
|
*
|
|
@@ -72,4 +73,124 @@ export declare function getDirSize(dirPath: string): Promise<number>;
|
|
|
72
73
|
* @returns {() => void} A function to stop watching the directory.
|
|
73
74
|
*/
|
|
74
75
|
export declare function watchDir(dirPath: string, callback: (eventType: "rename" | "change", filename: string | null) => void): () => void;
|
|
76
|
+
/**
|
|
77
|
+
* Finds files matching a glob pattern.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} pattern - Glob pattern to match files.
|
|
80
|
+
* @param {object} [options] - Options for glob pattern matching.
|
|
81
|
+
* @param {string} [options.cwd] - Current working directory for relative patterns.
|
|
82
|
+
* @param {boolean} [options.dot=false] - Include dotfiles in matches.
|
|
83
|
+
* @param {boolean} [options.nodir=true] - Only match files, not directories.
|
|
84
|
+
* @returns {Promise<string[]>} Array of matched file paths.
|
|
85
|
+
* @throws {Error} If pattern matching fails.
|
|
86
|
+
*/
|
|
87
|
+
export declare function findFilesByPattern(pattern: string, options?: {
|
|
88
|
+
cwd?: string;
|
|
89
|
+
dot?: boolean;
|
|
90
|
+
nodir?: boolean;
|
|
91
|
+
}): Promise<string[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Gets all subdirectories in a directory.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} dirPath - The directory to search in.
|
|
96
|
+
* @param {boolean} [recursive=false] - Whether to include subdirectories recursively.
|
|
97
|
+
* @returns {Promise<string[]>} Array of absolute subdirectory paths.
|
|
98
|
+
* @throws {Error} If directory cannot be read.
|
|
99
|
+
*/
|
|
100
|
+
export declare function getSubdirectories(dirPath: string, recursive?: boolean): Promise<string[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Ensures a directory exists and is empty.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} dirPath - Path to the directory.
|
|
105
|
+
* @returns {Promise<void>} Resolves when the directory exists and is empty.
|
|
106
|
+
* @throws {Error} If directory cannot be created or emptied.
|
|
107
|
+
*/
|
|
108
|
+
export declare function ensureEmptyDir(dirPath: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Creates a temporary directory with optional auto-cleanup.
|
|
111
|
+
*
|
|
112
|
+
* @param {object} [options] - Options for the temporary directory.
|
|
113
|
+
* @param {string} [options.prefix='tmp-'] - Prefix for the directory name.
|
|
114
|
+
* @param {string} [options.parentDir=os.tmpdir()] - Parent directory.
|
|
115
|
+
* @param {boolean} [options.cleanup=false] - Whether to register cleanup on process exit.
|
|
116
|
+
* @returns {Promise<{ path: string, cleanup: () => Promise<void> }>} Object with directory path and cleanup function.
|
|
117
|
+
* @throws {Error} If directory cannot be created.
|
|
118
|
+
*/
|
|
119
|
+
export declare function createTempDir(options?: {
|
|
120
|
+
prefix?: string;
|
|
121
|
+
parentDir?: string;
|
|
122
|
+
cleanup?: boolean;
|
|
123
|
+
}): Promise<{
|
|
124
|
+
path: string;
|
|
125
|
+
cleanup: () => Promise<void>;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Finds the newest file in a directory.
|
|
129
|
+
*
|
|
130
|
+
* @param {string} dirPath - Directory to search.
|
|
131
|
+
* @param {boolean} [recursive=false] - Whether to search subdirectories.
|
|
132
|
+
* @returns {Promise<string | null>} Path to the newest file or null if no files.
|
|
133
|
+
* @throws {Error} If directory cannot be read.
|
|
134
|
+
*/
|
|
135
|
+
export declare function findNewestFile(dirPath: string, recursive?: boolean): Promise<string | null>;
|
|
136
|
+
/**
|
|
137
|
+
* Finds the oldest file in a directory.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} dirPath - Directory to search.
|
|
140
|
+
* @param {boolean} [recursive=false] - Whether to search subdirectories.
|
|
141
|
+
* @returns {Promise<string | null>} Path to the oldest file or null if no files.
|
|
142
|
+
* @throws {Error} If directory cannot be read.
|
|
143
|
+
*/
|
|
144
|
+
export declare function findOldestFile(dirPath: string, recursive?: boolean): Promise<string | null>;
|
|
145
|
+
/**
|
|
146
|
+
* Finds files or directories in a directory matching a predicate function.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} dirPath - Directory to search.
|
|
149
|
+
* @param {(path: string, stat: fs.Stats) => boolean | Promise<boolean>} predicate - Function to test each path.
|
|
150
|
+
* @param {boolean} [recursive=false] - Whether to search subdirectories.
|
|
151
|
+
* @returns {Promise<string[]>} Array of matching paths.
|
|
152
|
+
* @throws {Error} If directory cannot be read.
|
|
153
|
+
*/
|
|
154
|
+
export declare function findInDir(dirPath: string, predicate: (path: string, stat: fs.Stats) => boolean | Promise<boolean>, recursive?: boolean): Promise<string[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Watches a directory recursively for file changes.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} dirPath - Base directory path to watch.
|
|
159
|
+
* @param {(eventType: "rename" | "change", filename: string) => void} callback - Callback for each change event.
|
|
160
|
+
* @param {boolean} [includeSubdirs=true] - Whether to watch subdirectories.
|
|
161
|
+
* @returns {Promise<() => void>} A function to stop watching the directory.
|
|
162
|
+
* @throws {Error} If directory cannot be watched.
|
|
163
|
+
*/
|
|
164
|
+
export declare function watchDirRecursive(dirPath: string, callback: (eventType: "rename" | "change", filename: string) => void, includeSubdirs?: boolean): Promise<() => void>;
|
|
165
|
+
/**
|
|
166
|
+
* Gets detailed directory statistics including file count, directory count, and size.
|
|
167
|
+
*
|
|
168
|
+
* @param {string} dirPath - Path to the directory.
|
|
169
|
+
* @returns {Promise<{ fileCount: number, dirCount: number, totalSize: number }>} Directory statistics.
|
|
170
|
+
* @throws {Error} If directory cannot be read.
|
|
171
|
+
*/
|
|
172
|
+
export declare function getDirStats(dirPath: string): Promise<{
|
|
173
|
+
fileCount: number;
|
|
174
|
+
dirCount: number;
|
|
175
|
+
totalSize: number;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Walks through a directory hierarchy, calling a visitor function for each entry.
|
|
179
|
+
*
|
|
180
|
+
* @param {string} dirPath - Starting directory path.
|
|
181
|
+
* @param {object} options - Options for walking the directory.
|
|
182
|
+
* @param {(entry: { path: string, name: string, isDirectory: boolean, stats: fs.Stats }) => boolean | void | Promise<boolean | void>} options.visitorFn -
|
|
183
|
+
* Function called for each file/directory. Return false to skip a directory.
|
|
184
|
+
* @param {'pre' | 'post'} [options.traversalOrder='pre'] - Whether to visit directories before or after their contents.
|
|
185
|
+
* @throws {Error} If directory cannot be read.
|
|
186
|
+
*/
|
|
187
|
+
export declare function walkDir(dirPath: string, options: {
|
|
188
|
+
visitorFn: (entry: {
|
|
189
|
+
path: string;
|
|
190
|
+
name: string;
|
|
191
|
+
isDirectory: boolean;
|
|
192
|
+
stats: fs.Stats;
|
|
193
|
+
}) => boolean | void | Promise<boolean | void>;
|
|
194
|
+
traversalOrder?: "pre" | "post";
|
|
195
|
+
}): Promise<void>;
|
|
75
196
|
//# sourceMappingURL=dir.utils.d.ts.map
|