@forgedevstack/harbor 1.0.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -101
- package/README.md +210 -794
- package/dist/auth/apiKey.d.ts +6 -0
- package/dist/auth/apiKey.d.ts.map +1 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/jwt.d.ts +21 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/password.d.ts +6 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/rbac.d.ts +6 -0
- package/dist/auth/rbac.d.ts.map +1 -0
- package/dist/auth/signing.d.ts +5 -0
- package/dist/auth/signing.d.ts.map +1 -0
- package/dist/auth/types/apiKey.types.d.ts +9 -0
- package/dist/auth/types/apiKey.types.d.ts.map +1 -0
- package/dist/auth/types/index.d.ts +5 -0
- package/dist/auth/types/index.d.ts.map +1 -0
- package/dist/auth/types/jwt.types.d.ts +17 -0
- package/dist/auth/types/jwt.types.d.ts.map +1 -0
- package/dist/auth/types/rbac.types.d.ts +8 -0
- package/dist/auth/types/rbac.types.d.ts.map +1 -0
- package/dist/auth/types/signing.types.d.ts +8 -0
- package/dist/auth/types/signing.types.d.ts.map +1 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/manager.d.ts +24 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/stores.d.ts +28 -0
- package/dist/cache/stores.d.ts.map +1 -0
- package/dist/cache/types.d.ts +23 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cli/index.js +21 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/router.d.ts +40 -2
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/database/connection.d.ts +1 -2
- package/dist/database/connection.d.ts.map +1 -1
- package/dist/database/index.js +2 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/model.d.ts +1 -4
- package/dist/database/model.d.ts.map +1 -1
- package/dist/docker/index.js +1 -1
- package/dist/http.const-BKHG1Lsj.mjs +62 -0
- package/dist/http.const-BKHG1Lsj.mjs.map +1 -0
- package/dist/http.const-Ckcy7OFp.js +2 -0
- package/dist/http.const-Ckcy7OFp.js.map +1 -0
- package/dist/index-Ca4WpLvw.js +2 -0
- package/dist/index-Ca4WpLvw.js.map +1 -0
- package/dist/index-DIVHd6rO.mjs +1054 -0
- package/dist/index-DIVHd6rO.mjs.map +1 -0
- package/dist/index.cjs.js +16 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +676 -1691
- package/dist/index.es.js.map +1 -1
- package/dist/logger-CZn7QxCl.mjs +102 -0
- package/dist/{logger-D7aJSi62.mjs.map → logger-CZn7QxCl.mjs.map} +1 -1
- package/dist/logger-D-lfaRWQ.js +3 -0
- package/dist/{logger-DEnWXtpk.js.map → logger-D-lfaRWQ.js.map} +1 -1
- package/dist/manager-CjcKb4P9.mjs +149 -0
- package/dist/{manager-B6vqJgEn.mjs.map → manager-CjcKb4P9.mjs.map} +1 -1
- package/dist/manager-DrF1vbJg.js +4 -0
- package/dist/{manager-B1UKMjXW.js.map → manager-DrF1vbJg.js.map} +1 -1
- package/dist/middleware/health.d.ts +65 -0
- package/dist/middleware/health.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +5 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/metrics.d.ts +68 -0
- package/dist/middleware/metrics.d.ts.map +1 -0
- package/dist/middleware/rateLimit.d.ts +52 -0
- package/dist/middleware/rateLimit.d.ts.map +1 -0
- package/dist/middleware/upload.d.ts +59 -0
- package/dist/middleware/upload.d.ts.map +1 -0
- package/dist/password-BXBkKbv3.js +2 -0
- package/dist/password-BXBkKbv3.js.map +1 -0
- package/dist/password-y4m307oa.mjs +223 -0
- package/dist/password-y4m307oa.mjs.map +1 -0
- package/dist/scheduler/index.d.ts +3 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +30 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/types.d.ts +25 -0
- package/dist/scheduler/types.d.ts.map +1 -0
- package/dist/types/server.types.d.ts +7 -0
- package/dist/types/server.types.d.ts.map +1 -1
- package/dist/upload-9lCNnKK_.js +5 -0
- package/dist/upload-9lCNnKK_.js.map +1 -0
- package/dist/upload-DUjQiuq7.mjs +619 -0
- package/dist/upload-DUjQiuq7.mjs.map +1 -0
- package/dist/validation/index.js +1 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/websocket/index.d.ts +3 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +2 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/manager.d.ts +30 -0
- package/dist/websocket/manager.d.ts.map +1 -0
- package/dist/websocket/types.d.ts +27 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/package.json +58 -18
- package/templates/default/controllers/user.controller.ts +44 -64
- package/templates/default/package.json +9 -33
- package/templates/default/routes/index.ts +2 -12
- package/templates/default/routes/user.routes.ts +26 -19
- package/templates/default/server.ts +16 -35
- package/dist/logger-D7aJSi62.mjs +0 -102
- package/dist/logger-DEnWXtpk.js +0 -3
- package/dist/manager-B1UKMjXW.js +0 -4
- package/dist/manager-B6vqJgEn.mjs +0 -152
- package/dist/portal.d.ts +0 -13
- package/dist/portal.d.ts.map +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,83 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
1
|
+
import F, { Router as D } from "express";
|
|
2
|
+
import { createServer as j } from "http";
|
|
3
|
+
import { readFileSync as V, existsSync as L, writeFileSync as W } from "fs";
|
|
4
|
+
import { resolve as _ } from "path";
|
|
5
|
+
import { c as w } from "./logger-CZn7QxCl.mjs";
|
|
6
|
+
import { s as qe } from "./logger-CZn7QxCl.mjs";
|
|
7
|
+
import { validateRequest as I } from "./validation/index.js";
|
|
8
|
+
import { MongoValidator as tt, createMongoSchema as rt, createParamValidator as st, validateField as ot, validators as nt } from "./validation/index.js";
|
|
9
|
+
import { H as T, a as J } from "./http.const-BKHG1Lsj.mjs";
|
|
10
|
+
import { C as it, c as ct, b as ut } from "./http.const-BKHG1Lsj.mjs";
|
|
11
|
+
import { t as y } from "./index-DIVHd6rO.mjs";
|
|
12
|
+
import { H as lt, M as ht, Q as ft, S as pt, T as mt, e as gt, a as Tt, c as Et, d as St, b as vt, g as $t, m as Ot, r as yt, s as At } from "./index-DIVHd6rO.mjs";
|
|
13
|
+
import { R as Rt, c as Ct, e as _t, d as Pt, h as Lt, b as Ht, l as xt, k as It, n as Mt, m as Nt, r as bt, a as Ft, s as Dt, u as Ut, v as jt } from "./upload-DUjQiuq7.mjs";
|
|
14
|
+
import { WebSocketManager as kt, createWebSocketServer as Gt } from "./websocket/index.js";
|
|
15
|
+
import { Scheduler as zt, createScheduler as Qt } from "./scheduler/index.js";
|
|
16
|
+
import { CacheManager as Wt, MemoryCache as Jt, RedisCache as Yt, cache as Zt, cacheResponse as Xt, cached as qt, createCache as er } from "./cache/index.js";
|
|
17
|
+
import { J as rr, a as sr, c as or, g as nr, h as ar, j as ir, b as cr, r as ur, d as dr, v as lr } from "./password-y4m307oa.mjs";
|
|
18
|
+
import { D as fr, c as pr } from "./manager-CjcKb4P9.mjs";
|
|
19
|
+
const Y = [
|
|
16
20
|
"./harbor.config.json",
|
|
17
21
|
"./config/harbor.config.json",
|
|
18
22
|
"./.harbor/config.json"
|
|
19
|
-
],
|
|
23
|
+
], H = {
|
|
20
24
|
PORT: "HARBOR_PORT",
|
|
21
25
|
HOST: "HARBOR_HOST",
|
|
22
26
|
LOG_LEVEL: "HARBOR_LOG_LEVEL",
|
|
23
27
|
CONFIG_PATH: "HARBOR_CONFIG_PATH"
|
|
24
|
-
},
|
|
25
|
-
GET: "GET",
|
|
26
|
-
POST: "POST",
|
|
27
|
-
PUT: "PUT",
|
|
28
|
-
PATCH: "PATCH",
|
|
29
|
-
DELETE: "DELETE",
|
|
30
|
-
OPTIONS: "OPTIONS",
|
|
31
|
-
HEAD: "HEAD"
|
|
32
|
-
}, p = {
|
|
33
|
-
OK: 200,
|
|
34
|
-
CREATED: 201,
|
|
35
|
-
NO_CONTENT: 204,
|
|
36
|
-
BAD_REQUEST: 400,
|
|
37
|
-
UNAUTHORIZED: 401,
|
|
38
|
-
FORBIDDEN: 403,
|
|
39
|
-
NOT_FOUND: 404,
|
|
40
|
-
METHOD_NOT_ALLOWED: 405,
|
|
41
|
-
CONFLICT: 409,
|
|
42
|
-
UNPROCESSABLE_ENTITY: 422,
|
|
43
|
-
TOO_MANY_REQUESTS: 429,
|
|
44
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
45
|
-
BAD_GATEWAY: 502,
|
|
46
|
-
SERVICE_UNAVAILABLE: 503,
|
|
47
|
-
GATEWAY_TIMEOUT: 504
|
|
48
|
-
}, ae = {
|
|
49
|
-
200: "OK",
|
|
50
|
-
201: "Created",
|
|
51
|
-
204: "No Content",
|
|
52
|
-
400: "Bad Request",
|
|
53
|
-
401: "Unauthorized",
|
|
54
|
-
403: "Forbidden",
|
|
55
|
-
404: "Not Found",
|
|
56
|
-
405: "Method Not Allowed",
|
|
57
|
-
409: "Conflict",
|
|
58
|
-
422: "Unprocessable Entity",
|
|
59
|
-
429: "Too Many Requests",
|
|
60
|
-
500: "Internal Server Error",
|
|
61
|
-
502: "Bad Gateway",
|
|
62
|
-
503: "Service Unavailable",
|
|
63
|
-
504: "Gateway Timeout"
|
|
64
|
-
}, Je = {
|
|
65
|
-
JSON: "application/json",
|
|
66
|
-
HTML: "text/html",
|
|
67
|
-
TEXT: "text/plain",
|
|
68
|
-
FORM: "application/x-www-form-urlencoded",
|
|
69
|
-
MULTIPART: "multipart/form-data"
|
|
70
|
-
}, Ze = {
|
|
71
|
-
CONTENT_TYPE: "Content-Type",
|
|
72
|
-
AUTHORIZATION: "Authorization",
|
|
73
|
-
ACCEPT: "Accept",
|
|
74
|
-
CACHE_CONTROL: "Cache-Control",
|
|
75
|
-
X_REQUEST_ID: "X-Request-ID",
|
|
76
|
-
X_RESPONSE_TIME: "X-Response-Time"
|
|
77
|
-
}, ce = 3e3, de = "localhost", le = 3e4, ue = "10mb", D = {
|
|
28
|
+
}, Z = 3e3, X = "localhost", q = 3e4, ee = "10mb", x = {
|
|
78
29
|
server: {
|
|
79
|
-
port:
|
|
80
|
-
host:
|
|
30
|
+
port: Z,
|
|
31
|
+
host: X,
|
|
81
32
|
cors: {
|
|
82
33
|
enabled: !0,
|
|
83
34
|
origin: "*",
|
|
@@ -87,13 +38,13 @@ const ie = [
|
|
|
87
38
|
bodyParser: {
|
|
88
39
|
json: !0,
|
|
89
40
|
urlencoded: !0,
|
|
90
|
-
limit:
|
|
41
|
+
limit: ee
|
|
91
42
|
},
|
|
92
43
|
trustProxy: !1
|
|
93
44
|
},
|
|
94
45
|
routes: {
|
|
95
46
|
prefix: "",
|
|
96
|
-
timeout:
|
|
47
|
+
timeout: q,
|
|
97
48
|
defaultMiddleware: []
|
|
98
49
|
},
|
|
99
50
|
validation: {
|
|
@@ -139,440 +90,260 @@ const ie = [
|
|
|
139
90
|
format: "text",
|
|
140
91
|
output: "console"
|
|
141
92
|
}
|
|
142
|
-
},
|
|
143
|
-
function
|
|
144
|
-
const
|
|
145
|
-
if (!
|
|
146
|
-
return
|
|
93
|
+
}, te = 1e4, M = w("config");
|
|
94
|
+
function re(e) {
|
|
95
|
+
const t = se(e);
|
|
96
|
+
if (!t)
|
|
97
|
+
return M.info("No config file found, using defaults"), N(x);
|
|
147
98
|
try {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
);
|
|
152
|
-
return B.info("Config loaded", { path: e }), V(s);
|
|
153
|
-
} catch (t) {
|
|
154
|
-
return B.error("Failed to load config", t), V(D);
|
|
99
|
+
const r = V(t, "utf-8"), s = JSON.parse(r), o = U(x, s);
|
|
100
|
+
return M.info("Config loaded", { path: t }), N(o);
|
|
101
|
+
} catch (r) {
|
|
102
|
+
return M.error("Failed to load config", r), N(x);
|
|
155
103
|
}
|
|
156
104
|
}
|
|
157
|
-
function
|
|
158
|
-
return
|
|
159
|
-
D,
|
|
160
|
-
r
|
|
161
|
-
);
|
|
105
|
+
function Ie(e) {
|
|
106
|
+
return U(x, e);
|
|
162
107
|
}
|
|
163
|
-
function
|
|
164
|
-
if (r) {
|
|
165
|
-
const t = R(process.cwd(), r);
|
|
166
|
-
return I(t) ? t : null;
|
|
167
|
-
}
|
|
168
|
-
const e = process.env[x.CONFIG_PATH];
|
|
108
|
+
function se(e) {
|
|
169
109
|
if (e) {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
return t;
|
|
110
|
+
const r = _(process.cwd(), e);
|
|
111
|
+
return L(r) ? r : null;
|
|
173
112
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
113
|
+
const t = process.env[H.CONFIG_PATH];
|
|
114
|
+
if (t) {
|
|
115
|
+
const r = _(process.cwd(), t);
|
|
116
|
+
if (L(r))
|
|
117
|
+
return r;
|
|
118
|
+
}
|
|
119
|
+
for (const r of Y) {
|
|
120
|
+
const s = _(process.cwd(), r);
|
|
121
|
+
if (L(s))
|
|
122
|
+
return s;
|
|
178
123
|
}
|
|
179
124
|
return null;
|
|
180
125
|
}
|
|
181
|
-
function
|
|
182
|
-
const
|
|
183
|
-
return
|
|
126
|
+
function N(e) {
|
|
127
|
+
const t = process.env[H.PORT], r = process.env[H.HOST], s = process.env[H.LOG_LEVEL];
|
|
128
|
+
return t && (e.server.port = parseInt(t, 10)), r && (e.server.host = r), s && (e.logger.level = s), e;
|
|
184
129
|
}
|
|
185
|
-
function
|
|
186
|
-
const
|
|
187
|
-
for (const
|
|
188
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
) :
|
|
130
|
+
function U(e, t) {
|
|
131
|
+
const r = { ...e };
|
|
132
|
+
for (const s in t)
|
|
133
|
+
if (Object.prototype.hasOwnProperty.call(t, s)) {
|
|
134
|
+
const o = t[s], n = e[s];
|
|
135
|
+
o !== null && typeof o == "object" && !Array.isArray(o) && n !== null && typeof n == "object" && !Array.isArray(n) ? r[s] = U(
|
|
136
|
+
n,
|
|
137
|
+
o
|
|
138
|
+
) : o !== void 0 && (r[s] = o);
|
|
194
139
|
}
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
const ge = {
|
|
198
|
-
// Server
|
|
199
|
-
"server.starting": "Server starting...",
|
|
200
|
-
"server.started": "Server started on http://{host}:{port}",
|
|
201
|
-
"server.stopping": "Server stopping...",
|
|
202
|
-
"server.stopped": "Server stopped",
|
|
203
|
-
"server.alreadyRunning": "Server is already running",
|
|
204
|
-
"server.error": "Server error",
|
|
205
|
-
"server.gracefulShutdown": "Received {signal}, shutting down gracefully",
|
|
206
|
-
// Router
|
|
207
|
-
"router.registered": "Registered route: {method} {path}",
|
|
208
|
-
"router.missingRequired": "Route must have path, method, and handler",
|
|
209
|
-
// Validation
|
|
210
|
-
"validation.failed": "Validation failed",
|
|
211
|
-
"validation.required": "{field} is required",
|
|
212
|
-
"validation.typeMismatch": "{field} must be of type {type}",
|
|
213
|
-
"validation.minValue": "{field} must be at least {min}",
|
|
214
|
-
"validation.maxValue": "{field} must be at most {max}",
|
|
215
|
-
"validation.minLength": "{field} must be at least {min} characters",
|
|
216
|
-
"validation.maxLength": "{field} must be at most {max} characters",
|
|
217
|
-
"validation.pattern": "{field} does not match the required pattern",
|
|
218
|
-
"validation.enum": "{field} must be one of: {values}",
|
|
219
|
-
"validation.invalidObjectId": "{field} is not a valid ObjectId",
|
|
220
|
-
"validation.invalidEmail": "{field} is not a valid email address",
|
|
221
|
-
"validation.invalidUrl": "{field} is not a valid URL",
|
|
222
|
-
"validation.invalidDate": "{field} is not a valid date",
|
|
223
|
-
"validation.customFailed": "{field} failed custom validation",
|
|
224
|
-
// Errors
|
|
225
|
-
"errors.badRequest": "Bad Request",
|
|
226
|
-
"errors.unauthorized": "Unauthorized",
|
|
227
|
-
"errors.forbidden": "Forbidden",
|
|
228
|
-
"errors.notFound": "Not Found",
|
|
229
|
-
"errors.conflict": "Conflict",
|
|
230
|
-
"errors.tooManyRequests": "Too Many Requests",
|
|
231
|
-
"errors.internal": "Internal Server Error",
|
|
232
|
-
"errors.timeout": "Request timeout",
|
|
233
|
-
"errors.default": "An error occurred",
|
|
234
|
-
// Config
|
|
235
|
-
"config.notFound": "No config file found, using defaults",
|
|
236
|
-
"config.loaded": "Config loaded from {path}",
|
|
237
|
-
"config.loadFailed": "Failed to load config",
|
|
238
|
-
// Docker
|
|
239
|
-
"docker.containerStarted": "Container started: {name}",
|
|
240
|
-
"docker.containerStopped": "Container stopped: {name}",
|
|
241
|
-
"docker.containerRestarted": "Container restarted: {name}",
|
|
242
|
-
"docker.containerRemoved": "Container removed: {name}",
|
|
243
|
-
"docker.imageBuilt": "Image built: {name}:{tag}",
|
|
244
|
-
"docker.imagePushed": "Image pushed: {name}",
|
|
245
|
-
"docker.imagePulled": "Image pulled: {name}:{tag}",
|
|
246
|
-
"docker.composeUp": "Docker Compose up completed",
|
|
247
|
-
"docker.composeDown": "Docker Compose down completed",
|
|
248
|
-
"docker.commandFailed": "Docker command failed: {command}",
|
|
249
|
-
// Changelog
|
|
250
|
-
"changelog.loaded": "Changelog loaded with {count} entries",
|
|
251
|
-
"changelog.saved": "Changelog saved to {path}",
|
|
252
|
-
"changelog.released": "Released version {version}",
|
|
253
|
-
"changelog.notFound": "No changelog file found, starting fresh",
|
|
254
|
-
// Portal
|
|
255
|
-
"portal.generated": "Portal generated at {path}",
|
|
256
|
-
"portal.generating": "Generating documentation portal...",
|
|
257
|
-
// Logger
|
|
258
|
-
"logger.levelChanged": "Log level changed to {level}",
|
|
259
|
-
// HTTP Logger (Morgan-like)
|
|
260
|
-
"http.request": "{method} {url} {status} {duration}ms",
|
|
261
|
-
"http.requestStart": "Incoming request: {method} {url}",
|
|
262
|
-
"http.requestEnd": "Request completed: {method} {url} - {status} in {duration}ms",
|
|
263
|
-
// CLI
|
|
264
|
-
"cli.init.success": "Harbor project initialized!",
|
|
265
|
-
"cli.init.configExists": "harbor.config.json already exists",
|
|
266
|
-
"cli.init.created": "Created {file}",
|
|
267
|
-
"cli.docs.generating": "Generating API documentation...",
|
|
268
|
-
"cli.docs.success": "Documentation generated successfully",
|
|
269
|
-
"cli.version": "Harbor v{version}",
|
|
270
|
-
"cli.unknownCommand": "Unknown command: {command}",
|
|
271
|
-
// Database
|
|
272
|
-
"database.connected": "Connected to MongoDB at {uri}",
|
|
273
|
-
"database.disconnected": "Disconnected from MongoDB",
|
|
274
|
-
"database.connecting": "Connecting to MongoDB...",
|
|
275
|
-
"database.connectionFailed": "Failed to connect to MongoDB: {error}",
|
|
276
|
-
"database.notConnected": "Not connected to database. Call harbor.connect() first.",
|
|
277
|
-
"database.modelCreated": "Model created: {name}",
|
|
278
|
-
"database.documentSaved": "Document saved: {id}",
|
|
279
|
-
"database.documentDeleted": "Document deleted: {id}",
|
|
280
|
-
"database.validationFailed": "Validation failed: {errors}",
|
|
281
|
-
"database.queryExecuted": "Query executed: {operation} on {collection}",
|
|
282
|
-
"database.indexCreated": "Index created: {name}",
|
|
283
|
-
"database.transactionStarted": "Transaction started",
|
|
284
|
-
"database.transactionCommitted": "Transaction committed",
|
|
285
|
-
"database.transactionAborted": "Transaction aborted"
|
|
286
|
-
}, pe = {
|
|
287
|
-
// Server
|
|
288
|
-
"server.starting": "השרת מופעל...",
|
|
289
|
-
"server.started": "השרת פועל בכתובת http://{host}:{port}",
|
|
290
|
-
"server.stopping": "השרת נעצר...",
|
|
291
|
-
"server.stopped": "השרת נעצר",
|
|
292
|
-
"server.alreadyRunning": "השרת כבר פועל",
|
|
293
|
-
"server.error": "שגיאת שרת",
|
|
294
|
-
"server.gracefulShutdown": "התקבל {signal}, מכבה בצורה מסודרת",
|
|
295
|
-
// Router
|
|
296
|
-
"router.registered": "נרשם נתיב: {method} {path}",
|
|
297
|
-
"router.missingRequired": "נתיב חייב לכלול path, method ו-handler",
|
|
298
|
-
// Validation
|
|
299
|
-
"validation.failed": "האימות נכשל",
|
|
300
|
-
"validation.required": "{field} הוא שדה חובה",
|
|
301
|
-
"validation.typeMismatch": "{field} חייב להיות מסוג {type}",
|
|
302
|
-
"validation.minValue": "{field} חייב להיות לפחות {min}",
|
|
303
|
-
"validation.maxValue": "{field} חייב להיות לכל היותר {max}",
|
|
304
|
-
"validation.minLength": "{field} חייב להכיל לפחות {min} תווים",
|
|
305
|
-
"validation.maxLength": "{field} חייב להכיל לכל היותר {max} תווים",
|
|
306
|
-
"validation.pattern": "{field} לא תואם לתבנית הנדרשת",
|
|
307
|
-
"validation.enum": "{field} חייב להיות אחד מ: {values}",
|
|
308
|
-
"validation.invalidObjectId": "{field} אינו ObjectId תקין",
|
|
309
|
-
"validation.invalidEmail": "{field} אינה כתובת אימייל תקינה",
|
|
310
|
-
"validation.invalidUrl": "{field} אינו URL תקין",
|
|
311
|
-
"validation.invalidDate": "{field} אינו תאריך תקין",
|
|
312
|
-
"validation.customFailed": "{field} נכשל באימות מותאם אישית",
|
|
313
|
-
// Errors
|
|
314
|
-
"errors.badRequest": "בקשה שגויה",
|
|
315
|
-
"errors.unauthorized": "לא מורשה",
|
|
316
|
-
"errors.forbidden": "גישה נדחתה",
|
|
317
|
-
"errors.notFound": "לא נמצא",
|
|
318
|
-
"errors.conflict": "התנגשות",
|
|
319
|
-
"errors.tooManyRequests": "יותר מדי בקשות",
|
|
320
|
-
"errors.internal": "שגיאת שרת פנימית",
|
|
321
|
-
"errors.timeout": "הבקשה פגה",
|
|
322
|
-
"errors.default": "אירעה שגיאה",
|
|
323
|
-
// Config
|
|
324
|
-
"config.notFound": "קובץ הגדרות לא נמצא, משתמש בברירת מחדל",
|
|
325
|
-
"config.loaded": "הגדרות נטענו מ-{path}",
|
|
326
|
-
"config.loadFailed": "נכשל בטעינת הגדרות",
|
|
327
|
-
// Docker
|
|
328
|
-
"docker.containerStarted": "קונטיינר הופעל: {name}",
|
|
329
|
-
"docker.containerStopped": "קונטיינר נעצר: {name}",
|
|
330
|
-
"docker.containerRestarted": "קונטיינר הופעל מחדש: {name}",
|
|
331
|
-
"docker.containerRemoved": "קונטיינר הוסר: {name}",
|
|
332
|
-
"docker.imageBuilt": "תמונה נבנתה: {name}:{tag}",
|
|
333
|
-
"docker.imagePushed": "תמונה הועלתה: {name}",
|
|
334
|
-
"docker.imagePulled": "תמונה הורדה: {name}:{tag}",
|
|
335
|
-
"docker.composeUp": "Docker Compose הופעל בהצלחה",
|
|
336
|
-
"docker.composeDown": "Docker Compose נעצר בהצלחה",
|
|
337
|
-
"docker.commandFailed": "פקודת Docker נכשלה: {command}",
|
|
338
|
-
// Changelog
|
|
339
|
-
"changelog.loaded": "יומן שינויים נטען עם {count} רשומות",
|
|
340
|
-
"changelog.saved": "יומן שינויים נשמר ב-{path}",
|
|
341
|
-
"changelog.released": "שוחררה גרסה {version}",
|
|
342
|
-
"changelog.notFound": "קובץ יומן שינויים לא נמצא, מתחיל מחדש",
|
|
343
|
-
// Portal
|
|
344
|
-
"portal.generated": "פורטל נוצר ב-{path}",
|
|
345
|
-
"portal.generating": "מייצר פורטל תיעוד...",
|
|
346
|
-
// Logger
|
|
347
|
-
"logger.levelChanged": "רמת הלוג שונתה ל-{level}",
|
|
348
|
-
// HTTP Logger
|
|
349
|
-
"http.request": "{method} {url} {status} {duration}ms",
|
|
350
|
-
"http.requestStart": "בקשה נכנסת: {method} {url}",
|
|
351
|
-
"http.requestEnd": "בקשה הושלמה: {method} {url} - {status} תוך {duration}ms",
|
|
352
|
-
// CLI
|
|
353
|
-
"cli.init.success": "פרויקט Harbor אותחל בהצלחה!",
|
|
354
|
-
"cli.init.configExists": "harbor.config.json כבר קיים",
|
|
355
|
-
"cli.init.created": "נוצר {file}",
|
|
356
|
-
"cli.docs.generating": "מייצר תיעוד API...",
|
|
357
|
-
"cli.docs.success": "התיעוד נוצר בהצלחה",
|
|
358
|
-
"cli.version": "Harbor גרסה {version}",
|
|
359
|
-
"cli.unknownCommand": "פקודה לא מוכרת: {command}",
|
|
360
|
-
// Database
|
|
361
|
-
"database.connected": "מחובר ל-MongoDB ב-{uri}",
|
|
362
|
-
"database.disconnected": "נותק מ-MongoDB",
|
|
363
|
-
"database.connecting": "מתחבר ל-MongoDB...",
|
|
364
|
-
"database.connectionFailed": "החיבור ל-MongoDB נכשל: {error}",
|
|
365
|
-
"database.notConnected": "לא מחובר למסד נתונים. קרא ל-harbor.connect() קודם.",
|
|
366
|
-
"database.modelCreated": "מודל נוצר: {name}",
|
|
367
|
-
"database.documentSaved": "מסמך נשמר: {id}",
|
|
368
|
-
"database.documentDeleted": "מסמך נמחק: {id}",
|
|
369
|
-
"database.validationFailed": "האימות נכשל: {errors}",
|
|
370
|
-
"database.queryExecuted": "שאילתה בוצעה: {operation} על {collection}",
|
|
371
|
-
"database.indexCreated": "אינדקס נוצר: {name}",
|
|
372
|
-
"database.transactionStarted": "טרנזקציה התחילה",
|
|
373
|
-
"database.transactionCommitted": "טרנזקציה אושרה",
|
|
374
|
-
"database.transactionAborted": "טרנזקציה בוטלה"
|
|
375
|
-
}, E = {
|
|
376
|
-
en: ge,
|
|
377
|
-
he: pe
|
|
378
|
-
};
|
|
379
|
-
let M = "en";
|
|
380
|
-
function tt(r) {
|
|
381
|
-
if (!E[r]) {
|
|
382
|
-
console.warn(`Locale "${r}" not found, falling back to "en"`), M = "en";
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
M = r;
|
|
386
|
-
}
|
|
387
|
-
function nt() {
|
|
388
|
-
return M;
|
|
389
|
-
}
|
|
390
|
-
function rt() {
|
|
391
|
-
return Object.keys(E);
|
|
392
|
-
}
|
|
393
|
-
function C(r, e) {
|
|
394
|
-
let n = (E[M] ?? E.en)[r] ?? E.en[r] ?? r;
|
|
395
|
-
if (e)
|
|
396
|
-
for (const [s, o] of Object.entries(e))
|
|
397
|
-
n = n.replace(new RegExp(`{${s}}`, "g"), String(o ?? ""));
|
|
398
|
-
return n;
|
|
399
|
-
}
|
|
400
|
-
function st(r, e) {
|
|
401
|
-
E[r] || (E[r] = {}), Object.assign(E[r], e);
|
|
402
|
-
}
|
|
403
|
-
function ot(r, e) {
|
|
404
|
-
E[r] = e;
|
|
140
|
+
return r;
|
|
405
141
|
}
|
|
406
|
-
const
|
|
407
|
-
function
|
|
408
|
-
const
|
|
409
|
-
return
|
|
410
|
-
|
|
411
|
-
}),
|
|
142
|
+
const z = w("router");
|
|
143
|
+
function B(e, t) {
|
|
144
|
+
const r = D();
|
|
145
|
+
return e.middleware && e.middleware.forEach((s) => r.use(s)), e.routes && e.routes.forEach((s) => {
|
|
146
|
+
oe(r, s, t);
|
|
147
|
+
}), r;
|
|
412
148
|
}
|
|
413
|
-
function
|
|
414
|
-
const
|
|
415
|
-
|
|
149
|
+
function oe(e, t, r) {
|
|
150
|
+
const s = t.method.toLowerCase(), o = ne(t, r);
|
|
151
|
+
e[s](t.path, ...o), z.debug(y("router.registered", { method: t.method, path: t.path }));
|
|
416
152
|
}
|
|
417
|
-
function
|
|
418
|
-
const
|
|
419
|
-
return
|
|
420
|
-
|
|
421
|
-
}),
|
|
153
|
+
function ne(e, t) {
|
|
154
|
+
const r = [], s = e.options ?? {};
|
|
155
|
+
return s.pre && s.pre.forEach((o) => {
|
|
156
|
+
r.push(Q(o));
|
|
157
|
+
}), s.validation && r.push(ie(s.validation, t)), s.timeout && r.push(ce(s.timeout)), r.push(ae(e.handler, s)), r;
|
|
422
158
|
}
|
|
423
|
-
function
|
|
424
|
-
return async (
|
|
159
|
+
function Q(e) {
|
|
160
|
+
return async (t, r, s) => {
|
|
425
161
|
try {
|
|
426
|
-
await
|
|
427
|
-
} catch (
|
|
428
|
-
|
|
162
|
+
await e(t, r, s);
|
|
163
|
+
} catch (o) {
|
|
164
|
+
s(o);
|
|
429
165
|
}
|
|
430
166
|
};
|
|
431
167
|
}
|
|
432
|
-
function
|
|
433
|
-
return async (
|
|
168
|
+
function ae(e, t) {
|
|
169
|
+
return async (r, s, o) => {
|
|
434
170
|
try {
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
437
|
-
for (const
|
|
438
|
-
await
|
|
439
|
-
!
|
|
171
|
+
const n = await e(r, s);
|
|
172
|
+
if (t.post && t.post.length > 0)
|
|
173
|
+
for (const c of t.post)
|
|
174
|
+
await c(r, s, n);
|
|
175
|
+
!s.headersSent && n !== void 0 && s.json({
|
|
440
176
|
success: !0,
|
|
441
|
-
data:
|
|
177
|
+
data: n
|
|
442
178
|
});
|
|
443
|
-
} catch (
|
|
444
|
-
|
|
179
|
+
} catch (n) {
|
|
180
|
+
o(n);
|
|
445
181
|
}
|
|
446
182
|
};
|
|
447
183
|
}
|
|
448
|
-
function
|
|
449
|
-
return async (
|
|
184
|
+
function ie(e, t) {
|
|
185
|
+
return async (r, s, o) => {
|
|
450
186
|
try {
|
|
451
|
-
const
|
|
452
|
-
if (
|
|
453
|
-
const
|
|
454
|
-
if (!
|
|
455
|
-
|
|
187
|
+
const n = {};
|
|
188
|
+
if (e.params) {
|
|
189
|
+
const c = await I(e.params, r.params, t.validation);
|
|
190
|
+
if (!c.valid) {
|
|
191
|
+
s.status(T.BAD_REQUEST).json({
|
|
456
192
|
success: !1,
|
|
457
193
|
error: {
|
|
458
|
-
message:
|
|
459
|
-
details:
|
|
194
|
+
message: y("validation.failed"),
|
|
195
|
+
details: c.errors
|
|
460
196
|
}
|
|
461
197
|
});
|
|
462
198
|
return;
|
|
463
199
|
}
|
|
464
|
-
|
|
200
|
+
n.params = c.data;
|
|
465
201
|
}
|
|
466
|
-
if (
|
|
467
|
-
const
|
|
468
|
-
if (!
|
|
469
|
-
|
|
202
|
+
if (e.query) {
|
|
203
|
+
const c = await I(e.query, r.query, t.validation);
|
|
204
|
+
if (!c.valid) {
|
|
205
|
+
s.status(T.BAD_REQUEST).json({
|
|
470
206
|
success: !1,
|
|
471
207
|
error: {
|
|
472
|
-
message:
|
|
473
|
-
details:
|
|
208
|
+
message: y("validation.failed"),
|
|
209
|
+
details: c.errors
|
|
474
210
|
}
|
|
475
211
|
});
|
|
476
212
|
return;
|
|
477
213
|
}
|
|
478
|
-
|
|
214
|
+
n.query = c.data;
|
|
479
215
|
}
|
|
480
|
-
if (
|
|
481
|
-
const
|
|
482
|
-
if (!
|
|
483
|
-
|
|
216
|
+
if (e.body) {
|
|
217
|
+
const c = await I(e.body, r.body, t.validation);
|
|
218
|
+
if (!c.valid) {
|
|
219
|
+
s.status(T.BAD_REQUEST).json({
|
|
484
220
|
success: !1,
|
|
485
221
|
error: {
|
|
486
|
-
message:
|
|
487
|
-
details:
|
|
222
|
+
message: y("validation.failed"),
|
|
223
|
+
details: c.errors
|
|
488
224
|
}
|
|
489
225
|
});
|
|
490
226
|
return;
|
|
491
227
|
}
|
|
492
|
-
|
|
228
|
+
n.body = c.data;
|
|
493
229
|
}
|
|
494
|
-
|
|
495
|
-
} catch (
|
|
496
|
-
|
|
230
|
+
r.validated = n, o();
|
|
231
|
+
} catch (n) {
|
|
232
|
+
o(n);
|
|
497
233
|
}
|
|
498
234
|
};
|
|
499
235
|
}
|
|
500
|
-
function
|
|
501
|
-
return (
|
|
502
|
-
const
|
|
503
|
-
|
|
236
|
+
function ce(e) {
|
|
237
|
+
return (t, r, s) => {
|
|
238
|
+
const o = setTimeout(() => {
|
|
239
|
+
r.headersSent || r.status(T.GATEWAY_TIMEOUT).json({
|
|
504
240
|
success: !1,
|
|
505
241
|
error: {
|
|
506
|
-
message:
|
|
242
|
+
message: y("errors.timeout")
|
|
507
243
|
}
|
|
508
244
|
});
|
|
509
|
-
},
|
|
510
|
-
|
|
245
|
+
}, e);
|
|
246
|
+
r.on("finish", () => clearTimeout(o)), r.on("close", () => clearTimeout(o)), s();
|
|
511
247
|
};
|
|
512
248
|
}
|
|
513
|
-
function
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return
|
|
521
|
-
}
|
|
522
|
-
function dt(r, e, t) {
|
|
523
|
-
return P("PATCH", r, e, t);
|
|
249
|
+
function Me(e, t, r) {
|
|
250
|
+
const s = D();
|
|
251
|
+
r?.middleware && r.middleware.forEach((n) => s.use(n)), t.forEach((n) => {
|
|
252
|
+
const c = n.path === "/" ? "" : n.path, l = n.method.toLowerCase(), i = ue(n);
|
|
253
|
+
s[l](c, ...i), z.debug(y("router.registered", { method: n.method, path: `${e}${c}` }));
|
|
254
|
+
});
|
|
255
|
+
const o = D();
|
|
256
|
+
return o.use(e, s), o;
|
|
524
257
|
}
|
|
525
|
-
function
|
|
526
|
-
|
|
258
|
+
function ue(e) {
|
|
259
|
+
const t = [], r = e.options ?? {};
|
|
260
|
+
return r.pre && r.pre.forEach((s) => {
|
|
261
|
+
t.push(Q(s));
|
|
262
|
+
}), t.push(de(e.handler, r)), t;
|
|
527
263
|
}
|
|
528
|
-
function
|
|
529
|
-
return
|
|
264
|
+
function de(e, t) {
|
|
265
|
+
return async (r, s, o) => {
|
|
266
|
+
try {
|
|
267
|
+
const n = await e(r, s);
|
|
268
|
+
if (t.post && t.post.length > 0)
|
|
269
|
+
for (const c of t.post)
|
|
270
|
+
await c(r, s, n);
|
|
271
|
+
!s.headersSent && n !== void 0 && s.json({
|
|
272
|
+
success: !0,
|
|
273
|
+
data: n
|
|
274
|
+
});
|
|
275
|
+
} catch (n) {
|
|
276
|
+
o(n);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
530
279
|
}
|
|
531
|
-
function
|
|
280
|
+
function v(e, t, r, s) {
|
|
532
281
|
return {
|
|
533
|
-
path:
|
|
534
|
-
method:
|
|
535
|
-
handler:
|
|
536
|
-
options:
|
|
537
|
-
pre:
|
|
538
|
-
post:
|
|
539
|
-
validation:
|
|
540
|
-
timeout:
|
|
282
|
+
path: t,
|
|
283
|
+
method: e,
|
|
284
|
+
handler: r,
|
|
285
|
+
options: s ? {
|
|
286
|
+
pre: s.pre,
|
|
287
|
+
post: s.post,
|
|
288
|
+
validation: s.validation,
|
|
289
|
+
timeout: s.timeout
|
|
541
290
|
} : void 0
|
|
542
291
|
};
|
|
543
292
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
293
|
+
function Ne(e, t, r) {
|
|
294
|
+
return v("GET", e, t, r);
|
|
295
|
+
}
|
|
296
|
+
function be(e, t, r) {
|
|
297
|
+
return v("POST", e, t, r);
|
|
298
|
+
}
|
|
299
|
+
function Fe(e, t, r) {
|
|
300
|
+
return v("PUT", e, t, r);
|
|
301
|
+
}
|
|
302
|
+
function De(e, t, r) {
|
|
303
|
+
return v("PATCH", e, t, r);
|
|
304
|
+
}
|
|
305
|
+
function Ue(e, t, r) {
|
|
306
|
+
return v("DELETE", e, t, r);
|
|
307
|
+
}
|
|
308
|
+
const je = {
|
|
309
|
+
get: (e, t, r) => v("GET", e, t, r),
|
|
310
|
+
post: (e, t, r) => v("POST", e, t, r),
|
|
311
|
+
put: (e, t, r) => v("PUT", e, t, r),
|
|
312
|
+
patch: (e, t, r) => v("PATCH", e, t, r),
|
|
313
|
+
delete: (e, t, r) => v("DELETE", e, t, r),
|
|
314
|
+
options: (e, t, r) => v("OPTIONS", e, t, r),
|
|
315
|
+
head: (e, t, r) => v("HEAD", e, t, r)
|
|
316
|
+
};
|
|
317
|
+
class K {
|
|
318
|
+
_route = {};
|
|
319
|
+
_options = {};
|
|
549
320
|
static create() {
|
|
550
|
-
return new
|
|
321
|
+
return new K();
|
|
551
322
|
}
|
|
552
|
-
path(
|
|
553
|
-
return this._route.path =
|
|
323
|
+
path(t) {
|
|
324
|
+
return this._route.path = t, this;
|
|
554
325
|
}
|
|
555
|
-
method(
|
|
556
|
-
return this._route.method =
|
|
326
|
+
method(t) {
|
|
327
|
+
return this._route.method = t, this;
|
|
557
328
|
}
|
|
558
|
-
get(
|
|
559
|
-
return this.method("GET").path(
|
|
329
|
+
get(t) {
|
|
330
|
+
return this.method("GET").path(t);
|
|
560
331
|
}
|
|
561
|
-
post(
|
|
562
|
-
return this.method("POST").path(
|
|
332
|
+
post(t) {
|
|
333
|
+
return this.method("POST").path(t);
|
|
563
334
|
}
|
|
564
|
-
put(
|
|
565
|
-
return this.method("PUT").path(
|
|
335
|
+
put(t) {
|
|
336
|
+
return this.method("PUT").path(t);
|
|
566
337
|
}
|
|
567
|
-
patch(
|
|
568
|
-
return this.method("PATCH").path(
|
|
338
|
+
patch(t) {
|
|
339
|
+
return this.method("PATCH").path(t);
|
|
569
340
|
}
|
|
570
|
-
delete(
|
|
571
|
-
return this.method("DELETE").path(
|
|
341
|
+
delete(t) {
|
|
342
|
+
return this.method("DELETE").path(t);
|
|
572
343
|
}
|
|
573
|
-
handler(
|
|
574
|
-
if (this._route.handler =
|
|
575
|
-
throw new Error(
|
|
344
|
+
handler(t) {
|
|
345
|
+
if (this._route.handler = t, !this._route.path || !this._route.method || !this._route.handler)
|
|
346
|
+
throw new Error(y("router.missingRequired"));
|
|
576
347
|
return {
|
|
577
348
|
path: this._route.path,
|
|
578
349
|
method: this._route.method,
|
|
@@ -580,31 +351,30 @@ class J {
|
|
|
580
351
|
options: Object.keys(this._options).length > 0 ? this._options : void 0
|
|
581
352
|
};
|
|
582
353
|
}
|
|
583
|
-
pre(...
|
|
584
|
-
return this._options.pre = [...this._options.pre ?? [], ...
|
|
354
|
+
pre(...t) {
|
|
355
|
+
return this._options.pre = [...this._options.pre ?? [], ...t], this;
|
|
585
356
|
}
|
|
586
|
-
postFn(...
|
|
587
|
-
return this._options.post = [...this._options.post ?? [], ...
|
|
357
|
+
postFn(...t) {
|
|
358
|
+
return this._options.post = [...this._options.post ?? [], ...t], this;
|
|
588
359
|
}
|
|
589
|
-
validate(
|
|
590
|
-
return this._options.validation =
|
|
360
|
+
validate(t) {
|
|
361
|
+
return this._options.validation = t, this;
|
|
591
362
|
}
|
|
592
|
-
timeout(
|
|
593
|
-
return this._options.timeout =
|
|
363
|
+
timeout(t) {
|
|
364
|
+
return this._options.timeout = t, this;
|
|
594
365
|
}
|
|
595
|
-
rateLimit(
|
|
596
|
-
return this._options.rateLimit =
|
|
366
|
+
rateLimit(t) {
|
|
367
|
+
return this._options.rateLimit = t, this;
|
|
597
368
|
}
|
|
598
|
-
auth(
|
|
599
|
-
return this._options.auth =
|
|
369
|
+
auth(t) {
|
|
370
|
+
return this._options.auth = t, this;
|
|
600
371
|
}
|
|
601
|
-
cache(
|
|
602
|
-
return this._options.cache =
|
|
372
|
+
cache(t) {
|
|
373
|
+
return this._options.cache = t, this;
|
|
603
374
|
}
|
|
604
|
-
// Legacy .build() still works for backwards compatibility
|
|
605
375
|
build() {
|
|
606
376
|
if (!this._route.path || !this._route.method || !this._route.handler)
|
|
607
|
-
throw new Error(
|
|
377
|
+
throw new Error(y("router.missingRequired"));
|
|
608
378
|
return {
|
|
609
379
|
path: this._route.path,
|
|
610
380
|
method: this._route.method,
|
|
@@ -613,62 +383,61 @@ class J {
|
|
|
613
383
|
};
|
|
614
384
|
}
|
|
615
385
|
}
|
|
616
|
-
const
|
|
386
|
+
const le = w("error");
|
|
617
387
|
class O extends Error {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
static badRequest(t, n) {
|
|
388
|
+
statusCode;
|
|
389
|
+
code;
|
|
390
|
+
details;
|
|
391
|
+
isOperational;
|
|
392
|
+
constructor(t, r = T.INTERNAL_SERVER_ERROR, s) {
|
|
393
|
+
super(t), this.name = "HarborError", this.statusCode = r, this.code = s?.code, this.details = s?.details, this.isOperational = s?.isOperational ?? !0, Error.captureStackTrace(this, this.constructor);
|
|
394
|
+
}
|
|
395
|
+
static badRequest(t, r) {
|
|
627
396
|
return new O(
|
|
628
397
|
t ?? "Bad Request",
|
|
629
|
-
|
|
630
|
-
{ code: "BAD_REQUEST", details:
|
|
398
|
+
T.BAD_REQUEST,
|
|
399
|
+
{ code: "BAD_REQUEST", details: r }
|
|
631
400
|
);
|
|
632
401
|
}
|
|
633
402
|
static unauthorized(t) {
|
|
634
403
|
return new O(
|
|
635
404
|
t ?? "Unauthorized",
|
|
636
|
-
|
|
405
|
+
T.UNAUTHORIZED,
|
|
637
406
|
{ code: "UNAUTHORIZED" }
|
|
638
407
|
);
|
|
639
408
|
}
|
|
640
409
|
static forbidden(t) {
|
|
641
410
|
return new O(
|
|
642
411
|
t ?? "Forbidden",
|
|
643
|
-
|
|
412
|
+
T.FORBIDDEN,
|
|
644
413
|
{ code: "FORBIDDEN" }
|
|
645
414
|
);
|
|
646
415
|
}
|
|
647
416
|
static notFound(t) {
|
|
648
417
|
return new O(
|
|
649
418
|
t ?? "Not Found",
|
|
650
|
-
|
|
419
|
+
T.NOT_FOUND,
|
|
651
420
|
{ code: "NOT_FOUND" }
|
|
652
421
|
);
|
|
653
422
|
}
|
|
654
|
-
static conflict(t,
|
|
423
|
+
static conflict(t, r) {
|
|
655
424
|
return new O(
|
|
656
425
|
t ?? "Conflict",
|
|
657
|
-
|
|
658
|
-
{ code: "CONFLICT", details:
|
|
426
|
+
T.CONFLICT,
|
|
427
|
+
{ code: "CONFLICT", details: r }
|
|
659
428
|
);
|
|
660
429
|
}
|
|
661
430
|
static internal(t) {
|
|
662
431
|
return new O(
|
|
663
432
|
t ?? "Internal Server Error",
|
|
664
|
-
|
|
433
|
+
T.INTERNAL_SERVER_ERROR,
|
|
665
434
|
{ code: "INTERNAL_ERROR", isOperational: !1 }
|
|
666
435
|
);
|
|
667
436
|
}
|
|
668
437
|
static tooManyRequests(t) {
|
|
669
438
|
return new O(
|
|
670
439
|
t ?? "Too Many Requests",
|
|
671
|
-
|
|
440
|
+
T.TOO_MANY_REQUESTS,
|
|
672
441
|
{ code: "RATE_LIMIT_EXCEEDED" }
|
|
673
442
|
);
|
|
674
443
|
}
|
|
@@ -684,1103 +453,304 @@ class O extends Error {
|
|
|
684
453
|
};
|
|
685
454
|
}
|
|
686
455
|
}
|
|
687
|
-
function
|
|
688
|
-
const
|
|
689
|
-
return (
|
|
690
|
-
const
|
|
691
|
-
if (
|
|
456
|
+
function he(e) {
|
|
457
|
+
const t = e.errors;
|
|
458
|
+
return (r, s, o, n) => {
|
|
459
|
+
const c = r.statusCode ?? T.INTERNAL_SERVER_ERROR, l = fe(c, t);
|
|
460
|
+
if (l?.log !== !1 && e.logger.enabled && le.error(`${s.method} ${s.path} - ${r.message}`, r), o.headersSent)
|
|
692
461
|
return;
|
|
693
|
-
if (
|
|
694
|
-
|
|
462
|
+
if (l?.redirect) {
|
|
463
|
+
o.redirect(l.redirect);
|
|
695
464
|
return;
|
|
696
465
|
}
|
|
697
|
-
const
|
|
698
|
-
|
|
466
|
+
const i = pe(r, c, l);
|
|
467
|
+
l?.json !== !1 ? o.status(c).json(i) : o.status(c).send(i.error.message);
|
|
699
468
|
};
|
|
700
469
|
}
|
|
701
|
-
function
|
|
702
|
-
const
|
|
703
|
-
return
|
|
470
|
+
function fe(e, t) {
|
|
471
|
+
const r = e.toString();
|
|
472
|
+
return t[r] ?? t.default;
|
|
704
473
|
}
|
|
705
|
-
function
|
|
706
|
-
return
|
|
474
|
+
function pe(e, t, r) {
|
|
475
|
+
return e instanceof O ? e.toJSON() : {
|
|
707
476
|
success: !1,
|
|
708
477
|
error: {
|
|
709
|
-
message:
|
|
710
|
-
statusCode:
|
|
478
|
+
message: r?.message ?? e.message ?? J[t] ?? "An error occurred",
|
|
479
|
+
statusCode: t
|
|
711
480
|
}
|
|
712
481
|
};
|
|
713
482
|
}
|
|
714
|
-
const
|
|
715
|
-
function
|
|
716
|
-
const
|
|
717
|
-
let
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
const
|
|
721
|
-
app:
|
|
722
|
-
server:
|
|
723
|
-
config:
|
|
483
|
+
const A = w("server");
|
|
484
|
+
function Be(e = {}) {
|
|
485
|
+
const t = re(e.configPath), r = F();
|
|
486
|
+
let s = null, o = "stopped", n = null;
|
|
487
|
+
const c = [];
|
|
488
|
+
me(r, t);
|
|
489
|
+
const l = {
|
|
490
|
+
app: r,
|
|
491
|
+
server: s,
|
|
492
|
+
config: t,
|
|
724
493
|
async start() {
|
|
725
|
-
if (
|
|
726
|
-
return
|
|
727
|
-
|
|
728
|
-
const
|
|
729
|
-
return new Promise((
|
|
494
|
+
if (o === "running")
|
|
495
|
+
return A.warn("Server is already running"), l.getInfo();
|
|
496
|
+
o = "starting";
|
|
497
|
+
const i = e.port ?? t.server.port, f = e.host ?? t.server.host ?? "localhost";
|
|
498
|
+
return new Promise((p, g) => {
|
|
730
499
|
try {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
} catch (d) {
|
|
741
|
-
s = "error", b(d);
|
|
500
|
+
s = j(r), l.server = s, s.listen(i, f, () => {
|
|
501
|
+
o = "running", n = /* @__PURE__ */ new Date();
|
|
502
|
+
const a = l.getInfo();
|
|
503
|
+
A.info(`Server started on http://${f}:${i}`), e.onReady?.(a), p(a);
|
|
504
|
+
}), s.on("error", (a) => {
|
|
505
|
+
o = "error", A.error("Server error", a), e.onError?.(a), g(a);
|
|
506
|
+
}), k(l);
|
|
507
|
+
} catch (a) {
|
|
508
|
+
o = "error", g(a);
|
|
742
509
|
}
|
|
743
510
|
});
|
|
744
511
|
},
|
|
745
512
|
async stop() {
|
|
746
|
-
if (!(!
|
|
747
|
-
return
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
},
|
|
751
|
-
|
|
752
|
-
clearTimeout(
|
|
513
|
+
if (!(!s || o === "stopped"))
|
|
514
|
+
return o = "stopping", new Promise((i, f) => {
|
|
515
|
+
const p = setTimeout(() => {
|
|
516
|
+
s?.close(), i();
|
|
517
|
+
}, te);
|
|
518
|
+
s.close((g) => {
|
|
519
|
+
clearTimeout(p), g ? (A.error("Error stopping server", g), f(g)) : (o = "stopped", n = null, A.info("Server stopped"), i());
|
|
753
520
|
});
|
|
754
521
|
});
|
|
755
522
|
},
|
|
756
523
|
async restart() {
|
|
757
|
-
return await
|
|
524
|
+
return await l.stop(), l.start();
|
|
525
|
+
},
|
|
526
|
+
addRoute(i) {
|
|
527
|
+
c.push(i);
|
|
528
|
+
const f = B({ routes: [i] }, t);
|
|
529
|
+
r.use(f);
|
|
530
|
+
},
|
|
531
|
+
addRouteGroup(i) {
|
|
532
|
+
c.push(...i.routes);
|
|
533
|
+
const f = B({
|
|
534
|
+
prefix: i.prefix,
|
|
535
|
+
routes: i.routes,
|
|
536
|
+
middleware: i.middleware
|
|
537
|
+
}, t);
|
|
538
|
+
r.use(i.prefix, f);
|
|
758
539
|
},
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const g = K({ routes: [h] }, e);
|
|
762
|
-
t.use(g);
|
|
540
|
+
addMiddleware(i) {
|
|
541
|
+
r.use(i);
|
|
763
542
|
},
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
prefix: h.prefix,
|
|
768
|
-
routes: h.routes,
|
|
769
|
-
middleware: h.middleware
|
|
770
|
-
}, e);
|
|
771
|
-
t.use(h.prefix, g);
|
|
543
|
+
// Convenience methods - works like Express!
|
|
544
|
+
use(...i) {
|
|
545
|
+
r.use(...i);
|
|
772
546
|
},
|
|
773
|
-
|
|
774
|
-
|
|
547
|
+
get(i, ...f) {
|
|
548
|
+
r.get(i, ...f);
|
|
549
|
+
},
|
|
550
|
+
post(i, ...f) {
|
|
551
|
+
r.post(i, ...f);
|
|
552
|
+
},
|
|
553
|
+
put(i, ...f) {
|
|
554
|
+
r.put(i, ...f);
|
|
555
|
+
},
|
|
556
|
+
patch(i, ...f) {
|
|
557
|
+
r.patch(i, ...f);
|
|
558
|
+
},
|
|
559
|
+
delete(i, ...f) {
|
|
560
|
+
r.delete(i, ...f);
|
|
561
|
+
},
|
|
562
|
+
listen(i, f) {
|
|
563
|
+
const p = i ?? e.port ?? t.server.port, g = e.host ?? t.server.host ?? "localhost";
|
|
564
|
+
s = j(r), l.server = s, s.listen(p, g, () => {
|
|
565
|
+
o = "running", n = /* @__PURE__ */ new Date(), A.info(`Server started on http://${g}:${p}`), f?.();
|
|
566
|
+
}), k(l);
|
|
775
567
|
},
|
|
776
568
|
getInfo() {
|
|
777
|
-
const
|
|
569
|
+
const i = e.port ?? t.server.port, f = e.host ?? t.server.host ?? "localhost";
|
|
778
570
|
return {
|
|
779
|
-
port:
|
|
780
|
-
host:
|
|
781
|
-
uptime:
|
|
782
|
-
startedAt:
|
|
783
|
-
routes:
|
|
784
|
-
path:
|
|
785
|
-
method:
|
|
571
|
+
port: i,
|
|
572
|
+
host: f,
|
|
573
|
+
uptime: n ? Date.now() - n.getTime() : 0,
|
|
574
|
+
startedAt: n,
|
|
575
|
+
routes: c.map((p) => ({
|
|
576
|
+
path: p.path,
|
|
577
|
+
method: p.method,
|
|
786
578
|
middleware: []
|
|
787
579
|
})),
|
|
788
|
-
status:
|
|
580
|
+
status: o
|
|
789
581
|
};
|
|
790
582
|
}
|
|
791
583
|
};
|
|
792
|
-
return
|
|
793
|
-
|
|
794
|
-
}),
|
|
584
|
+
return e.autoStart === !0 && l.start().catch((i) => {
|
|
585
|
+
A.error("Failed to auto-start server", i);
|
|
586
|
+
}), l;
|
|
795
587
|
}
|
|
796
|
-
function
|
|
797
|
-
|
|
798
|
-
(n = e.server.bodyParser) != null && n.json && r.use(q.json({ limit: e.server.bodyParser.limit })), (s = e.server.bodyParser) != null && s.urlencoded && r.use(q.urlencoded({
|
|
588
|
+
function me(e, t) {
|
|
589
|
+
t.server.bodyParser?.json && e.use(F.json({ limit: t.server.bodyParser.limit })), t.server.bodyParser?.urlencoded && e.use(F.urlencoded({
|
|
799
590
|
extended: !0,
|
|
800
|
-
limit:
|
|
801
|
-
})),
|
|
802
|
-
const
|
|
803
|
-
|
|
591
|
+
limit: t.server.bodyParser.limit
|
|
592
|
+
})), t.server.cors?.enabled && e.use(ge(t.server.cors)), e.use(Te());
|
|
593
|
+
const r = he(t);
|
|
594
|
+
e.use(r);
|
|
804
595
|
}
|
|
805
|
-
function
|
|
806
|
-
return (
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
i && s.includes(i) && t.setHeader("Access-Control-Allow-Origin", i);
|
|
596
|
+
function ge(e) {
|
|
597
|
+
return (t, r, s) => {
|
|
598
|
+
const o = e.origin;
|
|
599
|
+
if (o === !0 || o === "*")
|
|
600
|
+
r.setHeader("Access-Control-Allow-Origin", "*");
|
|
601
|
+
else if (typeof o == "string")
|
|
602
|
+
r.setHeader("Access-Control-Allow-Origin", o);
|
|
603
|
+
else if (Array.isArray(o)) {
|
|
604
|
+
const n = t.headers.origin;
|
|
605
|
+
n && o.includes(n) && r.setHeader("Access-Control-Allow-Origin", n);
|
|
816
606
|
}
|
|
817
|
-
if (
|
|
607
|
+
if (r.setHeader(
|
|
818
608
|
"Access-Control-Allow-Methods",
|
|
819
|
-
|
|
820
|
-
),
|
|
821
|
-
|
|
609
|
+
e.methods?.join(", ") ?? "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
|
610
|
+
), e.allowedHeaders ? r.setHeader("Access-Control-Allow-Headers", e.allowedHeaders.join(", ")) : r.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"), e.credentials && r.setHeader("Access-Control-Allow-Credentials", "true"), t.method === "OPTIONS") {
|
|
611
|
+
r.status(204).end();
|
|
822
612
|
return;
|
|
823
613
|
}
|
|
824
|
-
|
|
614
|
+
s();
|
|
825
615
|
};
|
|
826
616
|
}
|
|
827
|
-
function
|
|
828
|
-
return (
|
|
829
|
-
|
|
830
|
-
|
|
617
|
+
function Te() {
|
|
618
|
+
return (e, t, r) => {
|
|
619
|
+
e.startTime = Date.now(), e.harborContext = {}, t.success = function(s, o = 200) {
|
|
620
|
+
t.status(o).json({
|
|
831
621
|
success: !0,
|
|
832
|
-
data:
|
|
622
|
+
data: s
|
|
833
623
|
});
|
|
834
|
-
},
|
|
835
|
-
|
|
624
|
+
}, t.error = function(s, o = 500, n) {
|
|
625
|
+
t.status(o).json({
|
|
836
626
|
success: !1,
|
|
837
627
|
error: {
|
|
838
|
-
message:
|
|
839
|
-
details:
|
|
628
|
+
message: s,
|
|
629
|
+
details: n
|
|
840
630
|
}
|
|
841
631
|
});
|
|
842
|
-
},
|
|
632
|
+
}, r();
|
|
843
633
|
};
|
|
844
634
|
}
|
|
845
|
-
function
|
|
846
|
-
["SIGTERM", "SIGINT"].forEach((
|
|
847
|
-
process.on(
|
|
848
|
-
|
|
635
|
+
function k(e) {
|
|
636
|
+
["SIGTERM", "SIGINT"].forEach((r) => {
|
|
637
|
+
process.on(r, async () => {
|
|
638
|
+
A.info(`Received ${r}, shutting down gracefully`), await e.stop(), process.exit(0);
|
|
849
639
|
});
|
|
850
640
|
});
|
|
851
641
|
}
|
|
852
|
-
|
|
853
|
-
constructor(e, t) {
|
|
854
|
-
c(this, "_definition");
|
|
855
|
-
c(this, "_options");
|
|
856
|
-
c(this, "_paths", /* @__PURE__ */ new Map());
|
|
857
|
-
c(this, "_virtuals", /* @__PURE__ */ new Map());
|
|
858
|
-
c(this, "_methods", /* @__PURE__ */ new Map());
|
|
859
|
-
c(this, "_statics", /* @__PURE__ */ new Map());
|
|
860
|
-
c(this, "_preHooks", /* @__PURE__ */ new Map());
|
|
861
|
-
c(this, "_postHooks", /* @__PURE__ */ new Map());
|
|
862
|
-
c(this, "_indexes", []);
|
|
863
|
-
c(this, "_plugins", []);
|
|
864
|
-
// Public accessors for methods and statics
|
|
865
|
-
c(this, "methods", {});
|
|
866
|
-
c(this, "statics", {});
|
|
867
|
-
c(this, "virtuals", {});
|
|
868
|
-
if (this._definition = e, this._options = {
|
|
869
|
-
timestamps: !1,
|
|
870
|
-
strict: !0,
|
|
871
|
-
strictQuery: !1,
|
|
872
|
-
_id: !0,
|
|
873
|
-
id: !0,
|
|
874
|
-
versionKey: "__v",
|
|
875
|
-
autoIndex: !0,
|
|
876
|
-
autoCreate: !0,
|
|
877
|
-
minimize: !0,
|
|
878
|
-
...t
|
|
879
|
-
}, this._parseDefinition(e), this._options._id && this._paths.set("_id", { type: "ObjectId", required: !1 }), this._options.timestamps) {
|
|
880
|
-
const n = typeof this._options.timestamps == "object" ? this._options.timestamps.createdAt === !1 ? null : this._options.timestamps.createdAt || "createdAt" : "createdAt", s = typeof this._options.timestamps == "object" ? this._options.timestamps.updatedAt === !1 ? null : this._options.timestamps.updatedAt || "updatedAt" : "updatedAt";
|
|
881
|
-
n && this._paths.set(n, { type: "Date", required: !1 }), s && this._paths.set(s, { type: "Date", required: !1 });
|
|
882
|
-
}
|
|
883
|
-
if (this._options.versionKey) {
|
|
884
|
-
const n = typeof this._options.versionKey == "string" ? this._options.versionKey : "__v";
|
|
885
|
-
this._paths.set(n, { type: "Number", default: 0 });
|
|
886
|
-
}
|
|
887
|
-
this.methods = new Proxy({}, {
|
|
888
|
-
set: (n, s, o) => (this._methods.set(s, o), !0),
|
|
889
|
-
get: (n, s) => this._methods.get(s)
|
|
890
|
-
}), this.statics = new Proxy({}, {
|
|
891
|
-
set: (n, s, o) => (this._statics.set(s, o), !0),
|
|
892
|
-
get: (n, s) => this._statics.get(s)
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
_parseDefinition(e, t = "") {
|
|
896
|
-
for (const [n, s] of Object.entries(e)) {
|
|
897
|
-
const o = t ? `${t}.${n}` : n;
|
|
898
|
-
if (typeof s == "string")
|
|
899
|
-
this._paths.set(o, { type: s });
|
|
900
|
-
else if (typeof s == "object" && s !== null) {
|
|
901
|
-
const i = s;
|
|
902
|
-
"type" in i ? typeof i.type == "string" ? this._paths.set(o, i) : Array.isArray(i.type) ? this._paths.set(o, { ...i, type: "Array" }) : typeof i.type == "object" && (this._paths.set(o, { type: "Object" }), this._parseDefinition(i.type, o)) : (this._paths.set(o, { type: "Object" }), this._parseDefinition(s, o));
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
// Add additional fields to schema
|
|
907
|
-
add(e, t) {
|
|
908
|
-
return this._parseDefinition(e, t), this;
|
|
909
|
-
}
|
|
910
|
-
// Get path definition
|
|
911
|
-
path(e) {
|
|
912
|
-
return this._paths.get(e);
|
|
913
|
-
}
|
|
914
|
-
// Get all paths
|
|
915
|
-
paths() {
|
|
916
|
-
return this._paths;
|
|
917
|
-
}
|
|
918
|
-
// Define virtual field
|
|
919
|
-
virtual(e) {
|
|
920
|
-
return new He(this, e);
|
|
921
|
-
}
|
|
922
|
-
// Define instance method
|
|
923
|
-
method(e, t) {
|
|
924
|
-
return this._methods.set(e, t), this;
|
|
925
|
-
}
|
|
926
|
-
// Define static method
|
|
927
|
-
static(e, t) {
|
|
928
|
-
return this._statics.set(e, t), this;
|
|
929
|
-
}
|
|
930
|
-
// Pre hook
|
|
931
|
-
pre(e, t) {
|
|
932
|
-
const n = Array.isArray(e) ? e : [e];
|
|
933
|
-
for (const s of n) {
|
|
934
|
-
const o = this._preHooks.get(s) || [];
|
|
935
|
-
o.push(t), this._preHooks.set(s, o);
|
|
936
|
-
}
|
|
937
|
-
return this;
|
|
938
|
-
}
|
|
939
|
-
// Post hook
|
|
940
|
-
post(e, t) {
|
|
941
|
-
const n = Array.isArray(e) ? e : [e];
|
|
942
|
-
for (const s of n) {
|
|
943
|
-
const o = this._postHooks.get(s) || [];
|
|
944
|
-
o.push(t), this._postHooks.set(s, o);
|
|
945
|
-
}
|
|
946
|
-
return this;
|
|
947
|
-
}
|
|
948
|
-
// Define index
|
|
949
|
-
index(e, t) {
|
|
950
|
-
return this._indexes.push({ fields: e, options: t }), this;
|
|
951
|
-
}
|
|
952
|
-
// Plugin support
|
|
953
|
-
plugin(e, t) {
|
|
954
|
-
return this._plugins.push({ fn: e, options: t }), e(this, t), this;
|
|
955
|
-
}
|
|
956
|
-
// Load class methods as schema methods
|
|
957
|
-
loadClass(e) {
|
|
958
|
-
const t = e.prototype;
|
|
959
|
-
for (const n of Object.getOwnPropertyNames(t)) {
|
|
960
|
-
if (n === "constructor") continue;
|
|
961
|
-
const s = Object.getOwnPropertyDescriptor(t, n);
|
|
962
|
-
if (s != null && s.get)
|
|
963
|
-
this._virtuals.set(n, { get: s.get });
|
|
964
|
-
else if (s != null && s.set) {
|
|
965
|
-
const o = this._virtuals.get(n) || {};
|
|
966
|
-
this._virtuals.set(n, { ...o, set: s.set });
|
|
967
|
-
} else typeof (s == null ? void 0 : s.value) == "function" && this._methods.set(n, s.value);
|
|
968
|
-
}
|
|
969
|
-
for (const n of Object.getOwnPropertyNames(e)) {
|
|
970
|
-
if (["length", "prototype", "name"].includes(n)) continue;
|
|
971
|
-
const s = e[n];
|
|
972
|
-
typeof s == "function" && this._statics.set(n, s);
|
|
973
|
-
}
|
|
974
|
-
return this;
|
|
975
|
-
}
|
|
976
|
-
// Clone schema
|
|
977
|
-
clone() {
|
|
978
|
-
const e = new Z({}, this._options);
|
|
979
|
-
return e._paths = new Map(this._paths), e._virtuals = new Map(this._virtuals), e._methods = new Map(this._methods), e._statics = new Map(this._statics), e._preHooks = new Map(this._preHooks), e._postHooks = new Map(this._postHooks), e._indexes = [...this._indexes], e;
|
|
980
|
-
}
|
|
981
|
-
// Getters
|
|
982
|
-
get options() {
|
|
983
|
-
return this._options;
|
|
984
|
-
}
|
|
985
|
-
get definition() {
|
|
986
|
-
return this._definition;
|
|
987
|
-
}
|
|
988
|
-
getMethods() {
|
|
989
|
-
return this._methods;
|
|
990
|
-
}
|
|
991
|
-
getStatics() {
|
|
992
|
-
return this._statics;
|
|
993
|
-
}
|
|
994
|
-
getVirtuals() {
|
|
995
|
-
return this._virtuals;
|
|
996
|
-
}
|
|
997
|
-
getPreHooks() {
|
|
998
|
-
return this._preHooks;
|
|
999
|
-
}
|
|
1000
|
-
getPostHooks() {
|
|
1001
|
-
return this._postHooks;
|
|
1002
|
-
}
|
|
1003
|
-
getIndexes() {
|
|
1004
|
-
return this._indexes;
|
|
1005
|
-
}
|
|
1006
|
-
// Validate document against schema
|
|
1007
|
-
async validate(e) {
|
|
1008
|
-
const t = [];
|
|
1009
|
-
for (const [n, s] of this._paths) {
|
|
1010
|
-
const o = this._getNestedValue(e, n), i = await this._validateField(n, o, s);
|
|
1011
|
-
t.push(...i);
|
|
1012
|
-
}
|
|
1013
|
-
return t.length > 0 ? { valid: !1, errors: t } : { valid: !0 };
|
|
1014
|
-
}
|
|
1015
|
-
_getNestedValue(e, t) {
|
|
1016
|
-
return t.split(".").reduce((n, s) => n == null ? void 0 : n[s], e);
|
|
1017
|
-
}
|
|
1018
|
-
async _validateField(e, t, n) {
|
|
1019
|
-
const s = [];
|
|
1020
|
-
return n.required && t == null ? (s.push({ path: e, message: `${e} is required` }), s) : t == null ? s : this._validateType(t, n.type) ? (n.type === "String" && typeof t == "string" && (n.minLength && t.length < n.minLength && s.push({ path: e, message: `${e} must be at least ${n.minLength} characters` }), n.maxLength && t.length > n.maxLength && s.push({ path: e, message: `${e} must be at most ${n.maxLength} characters` }), n.match && !n.match.test(t) && s.push({ path: e, message: `${e} does not match required pattern` }), n.enum && !n.enum.includes(t) && s.push({ path: e, message: `${e} must be one of: ${n.enum.join(", ")}` })), n.type === "Number" && typeof t == "number" && (n.min !== void 0 && t < n.min && s.push({ path: e, message: `${e} must be at least ${n.min}` }), n.max !== void 0 && t > n.max && s.push({ path: e, message: `${e} must be at most ${n.max}` })), n.validate && (await n.validate.validator(t) || s.push({ path: e, message: n.validate.message || `${e} failed validation` })), s) : (s.push({ path: e, message: `${e} must be of type ${n.type}` }), s);
|
|
1021
|
-
}
|
|
1022
|
-
_validateType(e, t) {
|
|
1023
|
-
switch (t) {
|
|
1024
|
-
case "String":
|
|
1025
|
-
return typeof e == "string";
|
|
1026
|
-
case "Number":
|
|
1027
|
-
return typeof e == "number" && !isNaN(e);
|
|
1028
|
-
case "Boolean":
|
|
1029
|
-
return typeof e == "boolean";
|
|
1030
|
-
case "Date":
|
|
1031
|
-
return e instanceof Date || typeof e == "string" && !isNaN(Date.parse(e));
|
|
1032
|
-
case "ObjectId":
|
|
1033
|
-
return typeof e == "string" && /^[0-9a-fA-F]{24}$/.test(e);
|
|
1034
|
-
case "Array":
|
|
1035
|
-
return Array.isArray(e);
|
|
1036
|
-
case "Object":
|
|
1037
|
-
case "Mixed":
|
|
1038
|
-
return typeof e == "object" && e !== null;
|
|
1039
|
-
case "Buffer":
|
|
1040
|
-
return Buffer.isBuffer(e);
|
|
1041
|
-
default:
|
|
1042
|
-
return !0;
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
// Apply transformations (lowercase, uppercase, trim)
|
|
1046
|
-
transformValue(e, t) {
|
|
1047
|
-
const n = this._paths.get(e);
|
|
1048
|
-
if (!n || typeof t != "string") return t;
|
|
1049
|
-
let s = t;
|
|
1050
|
-
return n.lowercase && (s = s.toLowerCase()), n.uppercase && (s = s.toUpperCase()), n.trim && (s = s.trim()), s;
|
|
1051
|
-
}
|
|
1052
|
-
// Get default value for a field
|
|
1053
|
-
getDefault(e) {
|
|
1054
|
-
const t = this._paths.get(e);
|
|
1055
|
-
if (!(!t || t.default === void 0))
|
|
1056
|
-
return typeof t.default == "function" ? t.default() : t.default;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
class He {
|
|
1060
|
-
constructor(e, t) {
|
|
1061
|
-
c(this, "schema");
|
|
1062
|
-
c(this, "name");
|
|
1063
|
-
this.schema = e, this.name = t;
|
|
1064
|
-
}
|
|
1065
|
-
get(e) {
|
|
1066
|
-
const t = this.schema.getVirtuals(), n = t.get(this.name) || {};
|
|
1067
|
-
return t.set(this.name, { ...n, get: e }), this;
|
|
1068
|
-
}
|
|
1069
|
-
set(e) {
|
|
1070
|
-
const t = this.schema.getVirtuals(), n = t.get(this.name) || {};
|
|
1071
|
-
return t.set(this.name, { ...n, set: e }), this;
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
class Ne extends oe {
|
|
1075
|
-
constructor() {
|
|
1076
|
-
super(...arguments);
|
|
1077
|
-
c(this, "_state", {
|
|
1078
|
-
connected: !1,
|
|
1079
|
-
readyState: 0
|
|
1080
|
-
});
|
|
1081
|
-
c(this, "_options", {});
|
|
1082
|
-
c(this, "_connectionUri", "");
|
|
1083
|
-
c(this, "_mongoClient", null);
|
|
1084
|
-
c(this, "_db", null);
|
|
1085
|
-
c(this, "_models", /* @__PURE__ */ new Map());
|
|
1086
|
-
}
|
|
1087
|
-
get readyState() {
|
|
1088
|
-
return this._state.readyState;
|
|
1089
|
-
}
|
|
1090
|
-
get host() {
|
|
1091
|
-
return this._state.host;
|
|
1092
|
-
}
|
|
1093
|
-
get port() {
|
|
1094
|
-
return this._state.port;
|
|
1095
|
-
}
|
|
1096
|
-
get name() {
|
|
1097
|
-
return this._state.name;
|
|
1098
|
-
}
|
|
1099
|
-
get db() {
|
|
1100
|
-
return this._db;
|
|
1101
|
-
}
|
|
1102
|
-
get client() {
|
|
1103
|
-
return this._mongoClient;
|
|
1104
|
-
}
|
|
1105
|
-
get models() {
|
|
1106
|
-
return this._models;
|
|
1107
|
-
}
|
|
1108
|
-
get uri() {
|
|
1109
|
-
return this._connectionUri;
|
|
1110
|
-
}
|
|
1111
|
-
async connect(t, n) {
|
|
1112
|
-
if (this._state.readyState === 1)
|
|
1113
|
-
return console.warn("[Harbor] Already connected to MongoDB"), this;
|
|
1114
|
-
this._connectionUri = t, this._options = {
|
|
1115
|
-
maxPoolSize: 10,
|
|
1116
|
-
minPoolSize: 1,
|
|
1117
|
-
serverSelectionTimeoutMS: 3e4,
|
|
1118
|
-
socketTimeoutMS: 45e3,
|
|
1119
|
-
retryWrites: !0,
|
|
1120
|
-
w: "majority",
|
|
1121
|
-
...n
|
|
1122
|
-
}, this._state.readyState = 2, this.emit("connecting");
|
|
1123
|
-
try {
|
|
1124
|
-
const { MongoClient: s } = await import("mongodb");
|
|
1125
|
-
this._mongoClient = new s(t, this._options), await this._mongoClient.connect();
|
|
1126
|
-
const o = new URL(t), i = o.pathname.slice(1) || "test";
|
|
1127
|
-
return this._db = this._mongoClient.db(i), this._state = {
|
|
1128
|
-
connected: !0,
|
|
1129
|
-
readyState: 1,
|
|
1130
|
-
host: o.hostname,
|
|
1131
|
-
port: parseInt(o.port) || 27017,
|
|
1132
|
-
name: i
|
|
1133
|
-
}, this.emit("connected"), this.emit("open"), console.log(`[Harbor] ${C("database.connected", { uri: `${o.hostname}:${o.port}/${i}` })}`), this;
|
|
1134
|
-
} catch (s) {
|
|
1135
|
-
throw this._state.readyState = 0, this.emit("error", s), s;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
async disconnect() {
|
|
1139
|
-
if (this._state.readyState === 0) {
|
|
1140
|
-
console.warn("[Harbor] Already disconnected from MongoDB");
|
|
1141
|
-
return;
|
|
1142
|
-
}
|
|
1143
|
-
this._state.readyState = 3, this.emit("disconnecting");
|
|
1144
|
-
try {
|
|
1145
|
-
this._mongoClient && await this._mongoClient.close(), this._state = {
|
|
1146
|
-
connected: !1,
|
|
1147
|
-
readyState: 0
|
|
1148
|
-
}, this._mongoClient = null, this._db = null, this.emit("disconnected"), this.emit("close"), console.log(`[Harbor] ${C("database.disconnected")}`);
|
|
1149
|
-
} catch (t) {
|
|
1150
|
-
throw this.emit("error", t), t;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
async close() {
|
|
1154
|
-
return this.disconnect();
|
|
1155
|
-
}
|
|
1156
|
-
async ping() {
|
|
1157
|
-
if (!this._db)
|
|
1158
|
-
return !1;
|
|
1159
|
-
try {
|
|
1160
|
-
return await this._db.command({ ping: 1 }), !0;
|
|
1161
|
-
} catch {
|
|
1162
|
-
return !1;
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
collection(t) {
|
|
1166
|
-
if (!this._db)
|
|
1167
|
-
throw new Error("[Harbor] Not connected to database");
|
|
1168
|
-
return this._db.collection(t);
|
|
1169
|
-
}
|
|
1170
|
-
async createCollection(t, n) {
|
|
1171
|
-
if (!this._db)
|
|
1172
|
-
throw new Error("[Harbor] Not connected to database");
|
|
1173
|
-
return this._db.createCollection(t, n);
|
|
1174
|
-
}
|
|
1175
|
-
async dropCollection(t) {
|
|
1176
|
-
if (!this._db)
|
|
1177
|
-
throw new Error("[Harbor] Not connected to database");
|
|
1178
|
-
return this._db.dropCollection(t);
|
|
1179
|
-
}
|
|
1180
|
-
async listCollections() {
|
|
1181
|
-
if (!this._db)
|
|
1182
|
-
throw new Error("[Harbor] Not connected to database");
|
|
1183
|
-
return (await this._db.listCollections().toArray()).map((n) => n.name);
|
|
1184
|
-
}
|
|
1185
|
-
async dropDatabase() {
|
|
1186
|
-
if (!this._db)
|
|
1187
|
-
throw new Error("[Harbor] Not connected to database");
|
|
1188
|
-
return this._db.dropDatabase();
|
|
1189
|
-
}
|
|
1190
|
-
// Transaction support
|
|
1191
|
-
async startSession() {
|
|
1192
|
-
if (!this._mongoClient)
|
|
1193
|
-
throw new Error("[Harbor] Not connected to database");
|
|
1194
|
-
return this._mongoClient.startSession();
|
|
1195
|
-
}
|
|
1196
|
-
async withTransaction(t, n) {
|
|
1197
|
-
const s = await this.startSession();
|
|
1198
|
-
try {
|
|
1199
|
-
let o;
|
|
1200
|
-
return await s.withTransaction(async () => {
|
|
1201
|
-
o = await t(s);
|
|
1202
|
-
}, n), o;
|
|
1203
|
-
} finally {
|
|
1204
|
-
await s.endSession();
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
// Event handlers with proper typing
|
|
1208
|
-
on(t, n) {
|
|
1209
|
-
return super.on(t, n);
|
|
1210
|
-
}
|
|
1211
|
-
once(t, n) {
|
|
1212
|
-
return super.once(t, n);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
const j = new Ne();
|
|
1216
|
-
async function mt(r, e) {
|
|
1217
|
-
return j.connect(r, e);
|
|
1218
|
-
}
|
|
1219
|
-
async function ft() {
|
|
1220
|
-
return j.disconnect();
|
|
1221
|
-
}
|
|
1222
|
-
var Y;
|
|
1223
|
-
Y = Symbol.toStringTag;
|
|
1224
|
-
class H {
|
|
1225
|
-
constructor(e, t, n, s) {
|
|
1226
|
-
c(this, "_model");
|
|
1227
|
-
c(this, "_operation");
|
|
1228
|
-
c(this, "_filter", {});
|
|
1229
|
-
c(this, "_projection", null);
|
|
1230
|
-
c(this, "_options", {});
|
|
1231
|
-
c(this, "_update", null);
|
|
1232
|
-
c(this, "_currentPath", null);
|
|
1233
|
-
c(this, Y, "Query");
|
|
1234
|
-
this._model = e, this._operation = t, this._filter = n || {}, this._update = s || null;
|
|
1235
|
-
}
|
|
1236
|
-
select(e) {
|
|
1237
|
-
if (typeof e == "string") {
|
|
1238
|
-
this._projection = {};
|
|
1239
|
-
for (const t of e.split(" "))
|
|
1240
|
-
t.startsWith("-") ? this._projection[t.slice(1)] = 0 : t && (this._projection[t] = 1);
|
|
1241
|
-
} else
|
|
1242
|
-
this._projection = e;
|
|
1243
|
-
return this;
|
|
1244
|
-
}
|
|
1245
|
-
sort(e) {
|
|
1246
|
-
if (typeof e == "string") {
|
|
1247
|
-
const t = {};
|
|
1248
|
-
for (const n of e.split(" "))
|
|
1249
|
-
n.startsWith("-") ? t[n.slice(1)] = -1 : n && (t[n] = 1);
|
|
1250
|
-
this._options.sort = t;
|
|
1251
|
-
} else
|
|
1252
|
-
this._options.sort = e;
|
|
1253
|
-
return this;
|
|
1254
|
-
}
|
|
1255
|
-
limit(e) {
|
|
1256
|
-
return this._options.limit = e, this;
|
|
1257
|
-
}
|
|
1258
|
-
skip(e) {
|
|
1259
|
-
return this._options.skip = e, this;
|
|
1260
|
-
}
|
|
1261
|
-
lean() {
|
|
1262
|
-
return this._options.lean = !0, this;
|
|
1263
|
-
}
|
|
1264
|
-
populate(e) {
|
|
1265
|
-
return this._options.populate = e, this;
|
|
1266
|
-
}
|
|
1267
|
-
where(e, t) {
|
|
1268
|
-
return this._currentPath = e, t !== void 0 && (this._filter[e] = t), this;
|
|
1269
|
-
}
|
|
1270
|
-
equals(e) {
|
|
1271
|
-
return this._currentPath && (this._filter[this._currentPath] = e), this;
|
|
1272
|
-
}
|
|
1273
|
-
gt(e) {
|
|
1274
|
-
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $gt: e }), this;
|
|
1275
|
-
}
|
|
1276
|
-
gte(e) {
|
|
1277
|
-
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $gte: e }), this;
|
|
1278
|
-
}
|
|
1279
|
-
lt(e) {
|
|
1280
|
-
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $lt: e }), this;
|
|
1281
|
-
}
|
|
1282
|
-
lte(e) {
|
|
1283
|
-
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $lte: e }), this;
|
|
1284
|
-
}
|
|
1285
|
-
in(e) {
|
|
1286
|
-
return this._currentPath && (this._filter[this._currentPath] = { $in: e }), this;
|
|
1287
|
-
}
|
|
1288
|
-
nin(e) {
|
|
1289
|
-
return this._currentPath && (this._filter[this._currentPath] = { $nin: e }), this;
|
|
1290
|
-
}
|
|
1291
|
-
ne(e) {
|
|
1292
|
-
return this._currentPath && (this._filter[this._currentPath] = { $ne: e }), this;
|
|
1293
|
-
}
|
|
1294
|
-
regex(e) {
|
|
1295
|
-
return this._currentPath && (this._filter[this._currentPath] = { $regex: e }), this;
|
|
1296
|
-
}
|
|
1297
|
-
exists(e = !0) {
|
|
1298
|
-
return this._currentPath && (this._filter[this._currentPath] = { $exists: e }), this;
|
|
1299
|
-
}
|
|
1300
|
-
or(e) {
|
|
1301
|
-
return this._filter.$or = e, this;
|
|
1302
|
-
}
|
|
1303
|
-
and(e) {
|
|
1304
|
-
return this._filter.$and = e, this;
|
|
1305
|
-
}
|
|
1306
|
-
nor(e) {
|
|
1307
|
-
return this._filter.$nor = e, this;
|
|
1308
|
-
}
|
|
1309
|
-
async exec() {
|
|
1310
|
-
const e = this._model.getCollection();
|
|
1311
|
-
switch (this._operation) {
|
|
1312
|
-
case "find": {
|
|
1313
|
-
let t = e.find(this._filter, { projection: this._projection });
|
|
1314
|
-
this._options.sort && (t = t.sort(this._options.sort)), this._options.skip && (t = t.skip(this._options.skip)), this._options.limit && (t = t.limit(this._options.limit));
|
|
1315
|
-
const n = await t.toArray();
|
|
1316
|
-
return this._options.lean ? n : n.map((s) => this._model.hydrate(s));
|
|
1317
|
-
}
|
|
1318
|
-
case "findOne": {
|
|
1319
|
-
const t = await e.findOne(this._filter, { projection: this._projection });
|
|
1320
|
-
return t ? this._options.lean ? t : this._model.hydrate(t) : null;
|
|
1321
|
-
}
|
|
1322
|
-
case "findOneAndUpdate": {
|
|
1323
|
-
const t = await e.findOneAndUpdate(
|
|
1324
|
-
this._filter,
|
|
1325
|
-
this._update,
|
|
1326
|
-
{
|
|
1327
|
-
returnDocument: this._options.new ? "after" : "before",
|
|
1328
|
-
upsert: this._options.upsert,
|
|
1329
|
-
projection: this._projection
|
|
1330
|
-
}
|
|
1331
|
-
);
|
|
1332
|
-
return t ? this._options.lean ? t : this._model.hydrate(t) : null;
|
|
1333
|
-
}
|
|
1334
|
-
case "findOneAndDelete": {
|
|
1335
|
-
const t = await e.findOneAndDelete(this._filter, {
|
|
1336
|
-
projection: this._projection
|
|
1337
|
-
});
|
|
1338
|
-
return t ? this._options.lean ? t : this._model.hydrate(t) : null;
|
|
1339
|
-
}
|
|
1340
|
-
default:
|
|
1341
|
-
throw new Error(`Unknown operation: ${this._operation}`);
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
then(e, t) {
|
|
1345
|
-
return this.exec().then(e, t);
|
|
1346
|
-
}
|
|
1347
|
-
catch(e) {
|
|
1348
|
-
return this.exec().catch(e);
|
|
1349
|
-
}
|
|
1350
|
-
finally(e) {
|
|
1351
|
-
return this.exec().finally(e);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
class Q {
|
|
1355
|
-
constructor(e, t) {
|
|
1356
|
-
c(this, "_id");
|
|
1357
|
-
c(this, "__v");
|
|
1358
|
-
c(this, "isNew", !0);
|
|
1359
|
-
c(this, "_model");
|
|
1360
|
-
c(this, "_modified", /* @__PURE__ */ new Set());
|
|
1361
|
-
/** Snapshot of document at load time for change tracking */
|
|
1362
|
-
c(this, "_original", {});
|
|
1363
|
-
var s;
|
|
1364
|
-
if (this._model = e, this._id = ((s = t == null ? void 0 : t._id) == null ? void 0 : s.toString()) || new v().toString(), t) {
|
|
1365
|
-
for (const [o, i] of Object.entries(t))
|
|
1366
|
-
o === "_id" ? this._id = (i == null ? void 0 : i.toString()) || this._id : this[o] = i;
|
|
1367
|
-
this._original = { ...t }, this.isNew = !1;
|
|
1368
|
-
}
|
|
1369
|
-
const n = e.schema;
|
|
1370
|
-
for (const [o] of n.paths())
|
|
1371
|
-
if (this[o] === void 0) {
|
|
1372
|
-
const i = n.getDefault(o);
|
|
1373
|
-
i !== void 0 && (this[o] = i);
|
|
1374
|
-
}
|
|
1375
|
-
for (const [o, i] of n.getVirtuals())
|
|
1376
|
-
Object.defineProperty(this, o, {
|
|
1377
|
-
get: i.get,
|
|
1378
|
-
set: i.set,
|
|
1379
|
-
enumerable: !0
|
|
1380
|
-
});
|
|
1381
|
-
for (const [o, i] of n.getMethods())
|
|
1382
|
-
this[o] = i.bind(this);
|
|
1383
|
-
}
|
|
1384
|
-
/** Snapshot of document at load for change tracking */
|
|
1385
|
-
get original() {
|
|
1386
|
-
return this._original;
|
|
1387
|
-
}
|
|
1388
|
-
get id() {
|
|
1389
|
-
return this._id;
|
|
1390
|
-
}
|
|
1391
|
-
isModified(e) {
|
|
1392
|
-
return e ? this._modified.has(e) : this._modified.size > 0;
|
|
1393
|
-
}
|
|
1394
|
-
markModified(e) {
|
|
1395
|
-
this._modified.add(e);
|
|
1396
|
-
}
|
|
1397
|
-
async save() {
|
|
1398
|
-
var i;
|
|
1399
|
-
const e = this._model.schema;
|
|
1400
|
-
await this._model.runPreHooks("save", this);
|
|
1401
|
-
const t = await e.validate(this.toObject());
|
|
1402
|
-
if (!t.valid) {
|
|
1403
|
-
const a = new Error(`Validation failed: ${(i = t.errors) == null ? void 0 : i.map((h) => h.message).join(", ")}`);
|
|
1404
|
-
throw a.errors = t.errors, a;
|
|
1405
|
-
}
|
|
1406
|
-
const n = /* @__PURE__ */ new Date();
|
|
1407
|
-
if (e.options.timestamps) {
|
|
1408
|
-
const a = typeof e.options.timestamps == "object" && e.options.timestamps.createdAt || "createdAt", h = typeof e.options.timestamps == "object" && e.options.timestamps.updatedAt || "updatedAt";
|
|
1409
|
-
this.isNew && a && (this[a] = n), this[h] = n;
|
|
1410
|
-
}
|
|
1411
|
-
const s = this._model.getCollection(), o = this.toObject();
|
|
1412
|
-
if (this.isNew)
|
|
1413
|
-
await s.insertOne({ _id: new v(this._id), ...o }), this.isNew = !1;
|
|
1414
|
-
else {
|
|
1415
|
-
if (e.options.versionKey) {
|
|
1416
|
-
const a = typeof e.options.versionKey == "string" ? e.options.versionKey : "__v";
|
|
1417
|
-
this[a] = (this[a] || 0) + 1;
|
|
1418
|
-
}
|
|
1419
|
-
await s.replaceOne({ _id: new v(this._id) }, o);
|
|
1420
|
-
}
|
|
1421
|
-
return this._original = { ...o }, this._modified.clear(), await this._model.runPostHooks("save", this), this;
|
|
1422
|
-
}
|
|
1423
|
-
async remove() {
|
|
1424
|
-
return await this._model.runPreHooks("remove", this), await this._model.getCollection().deleteOne({ _id: new v(this._id) }), await this._model.runPostHooks("remove", this), this;
|
|
1425
|
-
}
|
|
1426
|
-
async deleteOne() {
|
|
1427
|
-
await this._model.runPreHooks("deleteOne", this);
|
|
1428
|
-
const t = await this._model.getCollection().deleteOne({ _id: new v(this._id) });
|
|
1429
|
-
return await this._model.runPostHooks("deleteOne", this), {
|
|
1430
|
-
acknowledged: t.acknowledged,
|
|
1431
|
-
deletedCount: t.deletedCount
|
|
1432
|
-
};
|
|
1433
|
-
}
|
|
1434
|
-
async updateOne(e) {
|
|
1435
|
-
await this._model.runPreHooks("updateOne", this);
|
|
1436
|
-
const n = await this._model.getCollection().updateOne({ _id: new v(this._id) }, e);
|
|
1437
|
-
return await this._model.runPostHooks("updateOne", this), {
|
|
1438
|
-
acknowledged: n.acknowledged,
|
|
1439
|
-
modifiedCount: n.modifiedCount,
|
|
1440
|
-
matchedCount: n.matchedCount
|
|
1441
|
-
};
|
|
1442
|
-
}
|
|
1443
|
-
async populate(e) {
|
|
1444
|
-
return this;
|
|
1445
|
-
}
|
|
1446
|
-
toObject() {
|
|
1447
|
-
const e = { _id: this._id }, t = this._model.schema;
|
|
1448
|
-
for (const [n] of t.paths())
|
|
1449
|
-
n !== "_id" && this[n] !== void 0 && (e[n] = this[n]);
|
|
1450
|
-
return e;
|
|
1451
|
-
}
|
|
1452
|
-
toJSON() {
|
|
1453
|
-
return this.toObject();
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
const U = class U {
|
|
1457
|
-
constructor(e, t, n) {
|
|
1458
|
-
c(this, "_name");
|
|
1459
|
-
c(this, "_schema");
|
|
1460
|
-
c(this, "_collectionName");
|
|
1461
|
-
this._name = e, this._schema = t, this._collectionName = n || e.toLowerCase() + "s";
|
|
1462
|
-
for (const [s, o] of t.getStatics())
|
|
1463
|
-
this[s] = o.bind(this);
|
|
1464
|
-
U.models.set(e, this);
|
|
1465
|
-
}
|
|
1466
|
-
get modelName() {
|
|
1467
|
-
return this._name;
|
|
1468
|
-
}
|
|
1469
|
-
get schema() {
|
|
1470
|
-
return this._schema;
|
|
1471
|
-
}
|
|
1472
|
-
get collection() {
|
|
1473
|
-
return { name: this._collectionName };
|
|
1474
|
-
}
|
|
1475
|
-
getCollection() {
|
|
1476
|
-
if (!j.db)
|
|
1477
|
-
throw new Error("[Harbor] Not connected to database. Call harbor.connect() first.");
|
|
1478
|
-
return j.db.collection(this._collectionName);
|
|
1479
|
-
}
|
|
1480
|
-
// Create a new document instance
|
|
1481
|
-
new(e) {
|
|
1482
|
-
return new Q(this, e);
|
|
1483
|
-
}
|
|
1484
|
-
// Hydrate a plain object into a document
|
|
1485
|
-
hydrate(e) {
|
|
1486
|
-
const t = new Q(this, e);
|
|
1487
|
-
return t.isNew = !1, t;
|
|
1488
|
-
}
|
|
1489
|
-
// Query methods
|
|
1490
|
-
find(e, t, n) {
|
|
1491
|
-
const s = new H(this, "find", e);
|
|
1492
|
-
return t && s.select(t), n != null && n.sort && s.sort(n.sort), n != null && n.limit && s.limit(n.limit), n != null && n.skip && s.skip(n.skip), n != null && n.lean && s.lean(), s;
|
|
1493
|
-
}
|
|
1494
|
-
findOne(e, t, n) {
|
|
1495
|
-
const s = new H(this, "findOne", e);
|
|
1496
|
-
return t && s.select(t), n != null && n.lean && s.lean(), s;
|
|
1497
|
-
}
|
|
1498
|
-
findById(e, t, n) {
|
|
1499
|
-
return this.findOne({ _id: new v(e) }, t, n);
|
|
1500
|
-
}
|
|
1501
|
-
// Create methods
|
|
1502
|
-
async create(e) {
|
|
1503
|
-
if (Array.isArray(e)) {
|
|
1504
|
-
const n = [];
|
|
1505
|
-
for (const s of e) {
|
|
1506
|
-
const o = this.new(s);
|
|
1507
|
-
await o.save(), n.push(o);
|
|
1508
|
-
}
|
|
1509
|
-
return n;
|
|
1510
|
-
}
|
|
1511
|
-
const t = this.new(e);
|
|
1512
|
-
return await t.save(), t;
|
|
1513
|
-
}
|
|
1514
|
-
async insertMany(e, t) {
|
|
1515
|
-
const n = this.getCollection(), s = e.map((i) => ({ _id: new v(), ...i })), o = await n.insertMany(s, { ordered: (t == null ? void 0 : t.ordered) ?? !0 });
|
|
1516
|
-
return {
|
|
1517
|
-
insertedCount: o.insertedCount,
|
|
1518
|
-
insertedIds: Object.values(o.insertedIds).map((i) => i.toString())
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
// Update methods
|
|
1522
|
-
async updateOne(e, t, n) {
|
|
1523
|
-
var a;
|
|
1524
|
-
await this.runPreHooks("updateOne", null);
|
|
1525
|
-
const s = this.getCollection(), o = t.$set || t.$unset || t.$inc ? t : { $set: t }, i = await s.updateOne(e, o, { upsert: n == null ? void 0 : n.upsert });
|
|
1526
|
-
return await this.runPostHooks("updateOne", null), {
|
|
1527
|
-
acknowledged: i.acknowledged,
|
|
1528
|
-
modifiedCount: i.modifiedCount,
|
|
1529
|
-
matchedCount: i.matchedCount,
|
|
1530
|
-
upsertedCount: i.upsertedCount,
|
|
1531
|
-
upsertedId: (a = i.upsertedId) == null ? void 0 : a.toString()
|
|
1532
|
-
};
|
|
1533
|
-
}
|
|
1534
|
-
async updateMany(e, t, n) {
|
|
1535
|
-
await this.runPreHooks("updateMany", null);
|
|
1536
|
-
const s = this.getCollection(), o = t.$set || t.$unset || t.$inc ? t : { $set: t }, i = await s.updateMany(e, o, { upsert: n == null ? void 0 : n.upsert });
|
|
1537
|
-
return await this.runPostHooks("updateMany", null), {
|
|
1538
|
-
acknowledged: i.acknowledged,
|
|
1539
|
-
modifiedCount: i.modifiedCount,
|
|
1540
|
-
matchedCount: i.matchedCount
|
|
1541
|
-
};
|
|
1542
|
-
}
|
|
1543
|
-
findOneAndUpdate(e, t, n) {
|
|
1544
|
-
const s = new H(this, "findOneAndUpdate", e, t);
|
|
1545
|
-
return n != null && n.new && (s._options.new = !0), n != null && n.upsert && (s._options.upsert = !0), n != null && n.lean && s.lean(), s;
|
|
1546
|
-
}
|
|
1547
|
-
findByIdAndUpdate(e, t, n) {
|
|
1548
|
-
return this.findOneAndUpdate({ _id: new v(e) }, t, n);
|
|
1549
|
-
}
|
|
1550
|
-
async replaceOne(e, t, n) {
|
|
1551
|
-
const o = await this.getCollection().replaceOne(e, t, { upsert: n == null ? void 0 : n.upsert });
|
|
1552
|
-
return {
|
|
1553
|
-
acknowledged: o.acknowledged,
|
|
1554
|
-
modifiedCount: o.modifiedCount,
|
|
1555
|
-
matchedCount: o.matchedCount
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
// Delete methods
|
|
1559
|
-
async deleteOne(e) {
|
|
1560
|
-
await this.runPreHooks("deleteOne", null);
|
|
1561
|
-
const n = await this.getCollection().deleteOne(e);
|
|
1562
|
-
return await this.runPostHooks("deleteOne", null), {
|
|
1563
|
-
acknowledged: n.acknowledged,
|
|
1564
|
-
deletedCount: n.deletedCount
|
|
1565
|
-
};
|
|
1566
|
-
}
|
|
1567
|
-
async deleteMany(e) {
|
|
1568
|
-
await this.runPreHooks("deleteMany", null);
|
|
1569
|
-
const n = await this.getCollection().deleteMany(e);
|
|
1570
|
-
return await this.runPostHooks("deleteMany", null), {
|
|
1571
|
-
acknowledged: n.acknowledged,
|
|
1572
|
-
deletedCount: n.deletedCount
|
|
1573
|
-
};
|
|
1574
|
-
}
|
|
1575
|
-
findOneAndDelete(e, t) {
|
|
1576
|
-
const n = new H(this, "findOneAndDelete", e);
|
|
1577
|
-
return t != null && t.lean && n.lean(), n;
|
|
1578
|
-
}
|
|
1579
|
-
findByIdAndDelete(e, t) {
|
|
1580
|
-
return this.findOneAndDelete({ _id: new v(e) }, t);
|
|
1581
|
-
}
|
|
1582
|
-
// Count methods
|
|
1583
|
-
async countDocuments(e) {
|
|
1584
|
-
return this.getCollection().countDocuments(e || {});
|
|
1585
|
-
}
|
|
1586
|
-
async estimatedDocumentCount() {
|
|
1587
|
-
return this.getCollection().estimatedDocumentCount();
|
|
1588
|
-
}
|
|
1589
|
-
// Aggregate
|
|
1590
|
-
async aggregate(e, t) {
|
|
1591
|
-
return this.getCollection().aggregate(e, t).toArray();
|
|
1592
|
-
}
|
|
1593
|
-
// Distinct
|
|
1594
|
-
async distinct(e, t) {
|
|
1595
|
-
return this.getCollection().distinct(e, t || {});
|
|
1596
|
-
}
|
|
1597
|
-
// Exists
|
|
1598
|
-
async exists(e) {
|
|
1599
|
-
const t = await this.findOne(e).select({ _id: 1 }).lean();
|
|
1600
|
-
return t ? { _id: t._id.toString() } : null;
|
|
1601
|
-
}
|
|
1602
|
-
// Bulk operations
|
|
1603
|
-
async bulkWrite(e) {
|
|
1604
|
-
const n = await this.getCollection().bulkWrite(e);
|
|
1605
|
-
return {
|
|
1606
|
-
ok: n.ok,
|
|
1607
|
-
insertedCount: n.insertedCount,
|
|
1608
|
-
matchedCount: n.matchedCount,
|
|
1609
|
-
modifiedCount: n.modifiedCount,
|
|
1610
|
-
deletedCount: n.deletedCount,
|
|
1611
|
-
upsertedCount: n.upsertedCount,
|
|
1612
|
-
insertedIds: n.insertedIds || {},
|
|
1613
|
-
upsertedIds: n.upsertedIds || {}
|
|
1614
|
-
};
|
|
1615
|
-
}
|
|
1616
|
-
// Index methods
|
|
1617
|
-
async createIndex(e, t) {
|
|
1618
|
-
return this.getCollection().createIndex(e, t);
|
|
1619
|
-
}
|
|
1620
|
-
async createIndexes(e) {
|
|
1621
|
-
const t = this.getCollection(), n = e.map((s) => ({ key: s.fields, ...s.options }));
|
|
1622
|
-
return t.createIndexes(n);
|
|
1623
|
-
}
|
|
1624
|
-
async listIndexes() {
|
|
1625
|
-
return this.getCollection().listIndexes().toArray();
|
|
1626
|
-
}
|
|
1627
|
-
async dropIndex(e) {
|
|
1628
|
-
await this.getCollection().dropIndex(e);
|
|
1629
|
-
}
|
|
1630
|
-
// Populate
|
|
1631
|
-
async populate(e, t) {
|
|
1632
|
-
return e;
|
|
1633
|
-
}
|
|
1634
|
-
// Watch (change streams)
|
|
1635
|
-
watch(e, t) {
|
|
1636
|
-
return this.getCollection().watch(e, t);
|
|
1637
|
-
}
|
|
1638
|
-
// Hook execution
|
|
1639
|
-
async runPreHooks(e, t) {
|
|
1640
|
-
const n = this._schema.getPreHooks().get(e) || [];
|
|
1641
|
-
for (const s of n)
|
|
1642
|
-
await new Promise((o, i) => {
|
|
1643
|
-
try {
|
|
1644
|
-
const a = s.call(t, o);
|
|
1645
|
-
a instanceof Promise && a.then(o).catch(i);
|
|
1646
|
-
} catch (a) {
|
|
1647
|
-
i(a);
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
async runPostHooks(e, t) {
|
|
1652
|
-
const n = this._schema.getPostHooks().get(e) || [];
|
|
1653
|
-
for (const s of n)
|
|
1654
|
-
await new Promise((o, i) => {
|
|
1655
|
-
try {
|
|
1656
|
-
const a = s.call(t, o);
|
|
1657
|
-
a instanceof Promise && a.then(o).catch(i);
|
|
1658
|
-
} catch (a) {
|
|
1659
|
-
i(a);
|
|
1660
|
-
}
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
c(U, "models", /* @__PURE__ */ new Map());
|
|
1665
|
-
let L = U;
|
|
1666
|
-
function gt(r, e, t) {
|
|
1667
|
-
const n = L.models.get(r);
|
|
1668
|
-
return n || new L(r, e, t);
|
|
1669
|
-
}
|
|
1670
|
-
const pt = {
|
|
1671
|
-
ObjectId: v
|
|
1672
|
-
}, k = A("changelog"), Ie = {
|
|
642
|
+
const C = w("changelog"), Ee = {
|
|
1673
643
|
filePath: "./CHANGELOG.md",
|
|
1674
644
|
format: "markdown",
|
|
1675
645
|
includeUnreleased: !0
|
|
1676
646
|
};
|
|
1677
|
-
function
|
|
1678
|
-
const
|
|
1679
|
-
let
|
|
1680
|
-
function
|
|
1681
|
-
const
|
|
1682
|
-
if (!
|
|
1683
|
-
|
|
647
|
+
function Se(e = {}) {
|
|
648
|
+
const t = { ...Ee, ...e }, r = [];
|
|
649
|
+
let s = [];
|
|
650
|
+
function o() {
|
|
651
|
+
const a = _(process.cwd(), t.filePath);
|
|
652
|
+
if (!L(a)) {
|
|
653
|
+
C.info("No changelog file found, starting fresh");
|
|
1684
654
|
return;
|
|
1685
655
|
}
|
|
1686
656
|
try {
|
|
1687
|
-
const
|
|
1688
|
-
|
|
1689
|
-
} catch (
|
|
1690
|
-
|
|
657
|
+
const u = V(a, "utf-8");
|
|
658
|
+
n(u), C.info("Changelog loaded", { entries: r.length });
|
|
659
|
+
} catch (u) {
|
|
660
|
+
C.error("Failed to load changelog", u);
|
|
1691
661
|
}
|
|
1692
662
|
}
|
|
1693
|
-
function
|
|
1694
|
-
const
|
|
1695
|
-
for (let
|
|
1696
|
-
const m =
|
|
1697
|
-
if (m &&
|
|
1698
|
-
const
|
|
663
|
+
function n(a) {
|
|
664
|
+
const u = /## \[(\d+\.\d+\.\d+(?:-[\w.]+)?)\](?: - (\d{4}-\d{2}-\d{2}))?/g, h = a.split(u);
|
|
665
|
+
for (let d = 1; d < h.length; d += 3) {
|
|
666
|
+
const m = h[d], $ = h[d + 1], S = h[d + 2];
|
|
667
|
+
if (m && S) {
|
|
668
|
+
const R = {
|
|
1699
669
|
version: m,
|
|
1700
|
-
date:
|
|
1701
|
-
changes:
|
|
670
|
+
date: $ ? new Date($) : /* @__PURE__ */ new Date(),
|
|
671
|
+
changes: c(S)
|
|
1702
672
|
};
|
|
1703
|
-
|
|
673
|
+
r.push(R);
|
|
1704
674
|
}
|
|
1705
675
|
}
|
|
1706
676
|
}
|
|
1707
|
-
function
|
|
1708
|
-
const
|
|
677
|
+
function c(a) {
|
|
678
|
+
const u = [], h = a.split(`
|
|
1709
679
|
`);
|
|
1710
|
-
let
|
|
1711
|
-
for (const m of
|
|
1712
|
-
const
|
|
1713
|
-
if (
|
|
1714
|
-
|
|
680
|
+
let d = null;
|
|
681
|
+
for (const m of h) {
|
|
682
|
+
const $ = m.match(/^### (Added|Changed|Deprecated|Removed|Fixed|Security)/i);
|
|
683
|
+
if ($) {
|
|
684
|
+
d = $[1].toLowerCase();
|
|
1715
685
|
continue;
|
|
1716
686
|
}
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
type:
|
|
1720
|
-
description:
|
|
687
|
+
const S = m.match(/^- (.+)/);
|
|
688
|
+
S && d && u.push({
|
|
689
|
+
type: d,
|
|
690
|
+
description: S[1].trim()
|
|
1721
691
|
});
|
|
1722
692
|
}
|
|
1723
|
-
return
|
|
693
|
+
return u;
|
|
1724
694
|
}
|
|
1725
|
-
function
|
|
1726
|
-
const
|
|
1727
|
-
|
|
695
|
+
function l() {
|
|
696
|
+
const a = _(process.cwd(), t.filePath), u = i();
|
|
697
|
+
W(a, u, "utf-8"), C.info("Changelog saved", { path: a });
|
|
1728
698
|
}
|
|
1729
|
-
function
|
|
1730
|
-
let
|
|
699
|
+
function i() {
|
|
700
|
+
let a = `# Changelog
|
|
1731
701
|
|
|
1732
702
|
`;
|
|
1733
|
-
|
|
703
|
+
a += `All notable changes to this project will be documented in this file.
|
|
1734
704
|
|
|
1735
|
-
`,
|
|
1736
|
-
`,
|
|
705
|
+
`, a += `The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
706
|
+
`, a += `and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
1737
707
|
|
|
1738
|
-
`,
|
|
708
|
+
`, t.includeUnreleased && s.length > 0 && (a += `## [Unreleased]
|
|
1739
709
|
|
|
1740
|
-
`,
|
|
710
|
+
`, a += f(s), a += `
|
|
1741
711
|
`);
|
|
1742
|
-
for (const
|
|
1743
|
-
const
|
|
1744
|
-
if (
|
|
712
|
+
for (const u of r) {
|
|
713
|
+
const h = u.date.toISOString().split("T")[0];
|
|
714
|
+
if (a += `## [${u.version}] - ${h}
|
|
1745
715
|
|
|
1746
|
-
`,
|
|
1747
|
-
|
|
716
|
+
`, a += f(u.changes), u.breaking && u.breaking.length > 0) {
|
|
717
|
+
a += `### BREAKING CHANGES
|
|
1748
718
|
|
|
1749
719
|
`;
|
|
1750
|
-
for (const
|
|
1751
|
-
|
|
720
|
+
for (const d of u.breaking)
|
|
721
|
+
a += `- ${d.description}
|
|
1752
722
|
`;
|
|
1753
|
-
|
|
723
|
+
a += `
|
|
1754
724
|
`;
|
|
1755
725
|
}
|
|
1756
|
-
|
|
726
|
+
a += `
|
|
1757
727
|
`;
|
|
1758
728
|
}
|
|
1759
|
-
return
|
|
1760
|
-
}
|
|
1761
|
-
function
|
|
1762
|
-
const
|
|
1763
|
-
let
|
|
1764
|
-
const
|
|
1765
|
-
for (const m of
|
|
1766
|
-
const
|
|
1767
|
-
if (
|
|
1768
|
-
|
|
729
|
+
return a;
|
|
730
|
+
}
|
|
731
|
+
function f(a) {
|
|
732
|
+
const u = p(a);
|
|
733
|
+
let h = "";
|
|
734
|
+
const d = ["added", "changed", "deprecated", "removed", "fixed", "security"];
|
|
735
|
+
for (const m of d) {
|
|
736
|
+
const $ = u[m];
|
|
737
|
+
if ($ && $.length > 0) {
|
|
738
|
+
h += `### ${g(m)}
|
|
1769
739
|
|
|
1770
740
|
`;
|
|
1771
|
-
for (const
|
|
1772
|
-
let
|
|
1773
|
-
|
|
741
|
+
for (const S of $) {
|
|
742
|
+
let R = `- ${S.description}`;
|
|
743
|
+
S.scope && (R = `- **${S.scope}:** ${S.description}`), S.issue && (R += ` (#${S.issue})`), h += R + `
|
|
1774
744
|
`;
|
|
1775
745
|
}
|
|
1776
|
-
|
|
746
|
+
h += `
|
|
1777
747
|
`;
|
|
1778
748
|
}
|
|
1779
749
|
}
|
|
1780
|
-
return
|
|
750
|
+
return h;
|
|
1781
751
|
}
|
|
1782
|
-
function
|
|
1783
|
-
const
|
|
752
|
+
function p(a) {
|
|
753
|
+
const u = {
|
|
1784
754
|
added: [],
|
|
1785
755
|
changed: [],
|
|
1786
756
|
deprecated: [],
|
|
@@ -1788,145 +758,126 @@ function xe(r = {}) {
|
|
|
1788
758
|
fixed: [],
|
|
1789
759
|
security: []
|
|
1790
760
|
};
|
|
1791
|
-
for (const
|
|
1792
|
-
|
|
1793
|
-
return
|
|
761
|
+
for (const h of a)
|
|
762
|
+
u[h.type].push(h);
|
|
763
|
+
return u;
|
|
1794
764
|
}
|
|
1795
|
-
function
|
|
1796
|
-
return
|
|
765
|
+
function g(a) {
|
|
766
|
+
return a.charAt(0).toUpperCase() + a.slice(1);
|
|
1797
767
|
}
|
|
1798
768
|
return {
|
|
1799
|
-
load:
|
|
1800
|
-
save:
|
|
1801
|
-
addChange(
|
|
1802
|
-
|
|
1803
|
-
type:
|
|
1804
|
-
description:
|
|
1805
|
-
scope:
|
|
1806
|
-
issue:
|
|
769
|
+
load: o,
|
|
770
|
+
save: l,
|
|
771
|
+
addChange(a, u, h) {
|
|
772
|
+
s.push({
|
|
773
|
+
type: a,
|
|
774
|
+
description: u,
|
|
775
|
+
scope: h?.scope,
|
|
776
|
+
issue: h?.issue
|
|
1807
777
|
});
|
|
1808
778
|
},
|
|
1809
|
-
release(
|
|
1810
|
-
const
|
|
1811
|
-
version:
|
|
779
|
+
release(a) {
|
|
780
|
+
const u = {
|
|
781
|
+
version: a,
|
|
1812
782
|
date: /* @__PURE__ */ new Date(),
|
|
1813
|
-
changes: [...
|
|
783
|
+
changes: [...s]
|
|
1814
784
|
};
|
|
1815
|
-
return
|
|
785
|
+
return r.unshift(u), s = [], l(), C.info(`Released version ${a}`), u;
|
|
1816
786
|
},
|
|
1817
787
|
getEntries() {
|
|
1818
|
-
return [...
|
|
788
|
+
return [...r];
|
|
1819
789
|
},
|
|
1820
790
|
getUnreleased() {
|
|
1821
|
-
return [...
|
|
791
|
+
return [...s];
|
|
1822
792
|
},
|
|
1823
793
|
getLatestVersion() {
|
|
1824
|
-
|
|
1825
|
-
return ((d = t[0]) == null ? void 0 : d.version) ?? null;
|
|
794
|
+
return r[0]?.version ?? null;
|
|
1826
795
|
},
|
|
1827
|
-
getReleaseNotes(
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
const u = w(l.changes);
|
|
796
|
+
getReleaseNotes(a) {
|
|
797
|
+
const u = r.find((d) => d.version === a);
|
|
798
|
+
if (!u) return null;
|
|
799
|
+
const h = p(u.changes);
|
|
1832
800
|
return {
|
|
1833
|
-
version:
|
|
1834
|
-
date:
|
|
1835
|
-
added:
|
|
1836
|
-
changed:
|
|
1837
|
-
deprecated:
|
|
1838
|
-
removed:
|
|
1839
|
-
fixed:
|
|
1840
|
-
security:
|
|
1841
|
-
breaking:
|
|
801
|
+
version: u.version,
|
|
802
|
+
date: u.date,
|
|
803
|
+
added: h.added.map((d) => d.description),
|
|
804
|
+
changed: h.changed.map((d) => d.description),
|
|
805
|
+
deprecated: h.deprecated.map((d) => d.description),
|
|
806
|
+
removed: h.removed.map((d) => d.description),
|
|
807
|
+
fixed: h.fixed.map((d) => d.description),
|
|
808
|
+
security: h.security.map((d) => d.description),
|
|
809
|
+
breaking: u.breaking?.map((d) => d.description) ?? []
|
|
1842
810
|
};
|
|
1843
811
|
}
|
|
1844
812
|
};
|
|
1845
813
|
}
|
|
1846
|
-
class
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
}
|
|
1860
|
-
class De {
|
|
1861
|
-
constructor(e = {}) {
|
|
1862
|
-
this.options = e;
|
|
1863
|
-
}
|
|
1864
|
-
get config() {
|
|
1865
|
-
return this.options;
|
|
1866
|
-
}
|
|
1867
|
-
generate() {
|
|
1868
|
-
console.log("[Harbor] Portal generation is coming soon.");
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
function yt(r) {
|
|
1872
|
-
return new De(r);
|
|
814
|
+
class ke {
|
|
815
|
+
manager;
|
|
816
|
+
constructor(t) {
|
|
817
|
+
this.manager = Se(t);
|
|
818
|
+
}
|
|
819
|
+
load = () => this.manager.load();
|
|
820
|
+
save = () => this.manager.save();
|
|
821
|
+
addChange = (...t) => this.manager.addChange(...t);
|
|
822
|
+
release = (t) => this.manager.release(t);
|
|
823
|
+
getEntries = () => this.manager.getEntries();
|
|
824
|
+
getUnreleased = () => this.manager.getUnreleased();
|
|
825
|
+
getLatestVersion = () => this.manager.getLatestVersion();
|
|
826
|
+
getReleaseNotes = (t) => this.manager.getReleaseNotes(t);
|
|
1873
827
|
}
|
|
1874
|
-
function
|
|
1875
|
-
|
|
828
|
+
function G(e) {
|
|
829
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
1876
830
|
}
|
|
1877
|
-
function
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
o,
|
|
1887
|
-
s
|
|
1888
|
-
) : s !== void 0 && (t[n] = s);
|
|
831
|
+
function ve(e, t) {
|
|
832
|
+
const r = { ...e };
|
|
833
|
+
for (const s in t)
|
|
834
|
+
if (Object.prototype.hasOwnProperty.call(t, s)) {
|
|
835
|
+
const o = t[s], n = e[s];
|
|
836
|
+
G(o) && G(n) ? r[s] = ve(
|
|
837
|
+
n,
|
|
838
|
+
o
|
|
839
|
+
) : o !== void 0 && (r[s] = o);
|
|
1889
840
|
}
|
|
1890
|
-
return
|
|
841
|
+
return r;
|
|
1891
842
|
}
|
|
1892
|
-
function
|
|
1893
|
-
const
|
|
1894
|
-
for (const
|
|
1895
|
-
Object.prototype.hasOwnProperty.call(
|
|
1896
|
-
return
|
|
843
|
+
function Ge(e, t) {
|
|
844
|
+
const r = {};
|
|
845
|
+
for (const s of t)
|
|
846
|
+
Object.prototype.hasOwnProperty.call(e, s) && (r[s] = e[s]);
|
|
847
|
+
return r;
|
|
1897
848
|
}
|
|
1898
|
-
function
|
|
1899
|
-
const
|
|
1900
|
-
for (const
|
|
1901
|
-
delete
|
|
1902
|
-
return
|
|
849
|
+
function Ve(e, t) {
|
|
850
|
+
const r = { ...e };
|
|
851
|
+
for (const s of t)
|
|
852
|
+
delete r[s];
|
|
853
|
+
return r;
|
|
1903
854
|
}
|
|
1904
|
-
function
|
|
1905
|
-
const
|
|
1906
|
-
let
|
|
1907
|
-
for (let
|
|
1908
|
-
|
|
1909
|
-
return
|
|
855
|
+
function ze(e = 16) {
|
|
856
|
+
const t = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
857
|
+
let r = "";
|
|
858
|
+
for (let s = 0; s < e; s++)
|
|
859
|
+
r += t.charAt(Math.floor(Math.random() * t.length));
|
|
860
|
+
return r;
|
|
1910
861
|
}
|
|
1911
|
-
function
|
|
1912
|
-
if (
|
|
1913
|
-
return
|
|
1914
|
-
const
|
|
1915
|
-
switch (
|
|
862
|
+
function Qe(e, t = "ISO") {
|
|
863
|
+
if (t === "ISO")
|
|
864
|
+
return e.toISOString();
|
|
865
|
+
const r = e.getFullYear(), s = String(e.getMonth() + 1).padStart(2, "0"), o = String(e.getDate()).padStart(2, "0"), n = String(e.getHours()).padStart(2, "0"), c = String(e.getMinutes()).padStart(2, "0"), l = String(e.getSeconds()).padStart(2, "0");
|
|
866
|
+
switch (t) {
|
|
1916
867
|
case "DATE":
|
|
1917
|
-
return `${
|
|
868
|
+
return `${r}-${s}-${o}`;
|
|
1918
869
|
case "TIME":
|
|
1919
|
-
return `${
|
|
870
|
+
return `${n}:${c}:${l}`;
|
|
1920
871
|
case "DATETIME":
|
|
1921
|
-
return `${
|
|
872
|
+
return `${r}-${s}-${o} ${n}:${c}:${l}`;
|
|
1922
873
|
default:
|
|
1923
|
-
return
|
|
874
|
+
return e.toISOString();
|
|
1924
875
|
}
|
|
1925
876
|
}
|
|
1926
|
-
function
|
|
1927
|
-
return new Promise((
|
|
877
|
+
function Ke(e) {
|
|
878
|
+
return new Promise((t) => setTimeout(t, e));
|
|
1928
879
|
}
|
|
1929
|
-
const
|
|
880
|
+
const P = w("http"), E = {
|
|
1930
881
|
info: "\x1B[36m",
|
|
1931
882
|
// Cyan for 1xx
|
|
1932
883
|
success: "\x1B[32m",
|
|
@@ -1939,10 +890,10 @@ const N = A("http"), _ = {
|
|
|
1939
890
|
// Red for 5xx
|
|
1940
891
|
reset: "\x1B[0m"
|
|
1941
892
|
};
|
|
1942
|
-
function
|
|
1943
|
-
return
|
|
893
|
+
function $e(e) {
|
|
894
|
+
return e >= 500 ? E.serverError : e >= 400 ? E.clientError : e >= 300 ? E.redirect : e >= 200 ? E.success : E.info;
|
|
1944
895
|
}
|
|
1945
|
-
function
|
|
896
|
+
function b(e) {
|
|
1946
897
|
return {
|
|
1947
898
|
GET: "\x1B[32m",
|
|
1948
899
|
// Green
|
|
@@ -1958,137 +909,171 @@ function G(r) {
|
|
|
1958
909
|
// Cyan
|
|
1959
910
|
HEAD: "\x1B[36m"
|
|
1960
911
|
// Cyan
|
|
1961
|
-
}[
|
|
912
|
+
}[e] ?? "\x1B[0m";
|
|
1962
913
|
}
|
|
1963
|
-
function
|
|
1964
|
-
return
|
|
914
|
+
function Oe(e) {
|
|
915
|
+
return e === 0 ? "-" : e < 1024 ? `${e}B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)}KB` : `${(e / (1024 * 1024)).toFixed(1)}MB`;
|
|
1965
916
|
}
|
|
1966
|
-
function
|
|
1967
|
-
const
|
|
917
|
+
function ye(e, t, r) {
|
|
918
|
+
const s = Date.now() - r, o = t.statusCode, n = t.get("content-length") ?? "0";
|
|
1968
919
|
return {
|
|
1969
|
-
method:
|
|
1970
|
-
url:
|
|
1971
|
-
status:
|
|
1972
|
-
statusColor:
|
|
1973
|
-
responseTime:
|
|
1974
|
-
contentLength:
|
|
1975
|
-
remoteAddr:
|
|
920
|
+
method: e.method,
|
|
921
|
+
url: e.originalUrl || e.url,
|
|
922
|
+
status: o,
|
|
923
|
+
statusColor: $e(o),
|
|
924
|
+
responseTime: s,
|
|
925
|
+
contentLength: Oe(parseInt(n, 10) || 0),
|
|
926
|
+
remoteAddr: e.ip || e.socket.remoteAddress || "-",
|
|
1976
927
|
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1977
|
-
httpVersion: `HTTP/${
|
|
1978
|
-
userAgent:
|
|
1979
|
-
referrer:
|
|
928
|
+
httpVersion: `HTTP/${e.httpVersionMajor}.${e.httpVersionMinor}`,
|
|
929
|
+
userAgent: e.get("user-agent") ?? "-",
|
|
930
|
+
referrer: e.get("referrer") ?? "-"
|
|
1980
931
|
};
|
|
1981
932
|
}
|
|
1982
|
-
const
|
|
1983
|
-
tiny: (
|
|
1984
|
-
const
|
|
1985
|
-
return `${
|
|
933
|
+
const Ae = {
|
|
934
|
+
tiny: (e, t) => {
|
|
935
|
+
const r = t ? `${b(e.method)}${e.method}${E.reset}` : e.method, s = t ? `${e.statusColor}${e.status}${E.reset}` : String(e.status);
|
|
936
|
+
return `${r} ${e.url} ${s} ${e.responseTime}ms`;
|
|
1986
937
|
},
|
|
1987
|
-
short: (
|
|
1988
|
-
const
|
|
1989
|
-
return `${
|
|
938
|
+
short: (e, t) => {
|
|
939
|
+
const r = t ? `${b(e.method)}${e.method}${E.reset}` : e.method, s = t ? `${e.statusColor}${e.status}${E.reset}` : String(e.status);
|
|
940
|
+
return `${e.remoteAddr} ${r} ${e.url} ${s} ${e.responseTime}ms - ${e.contentLength}`;
|
|
1990
941
|
},
|
|
1991
|
-
dev: (
|
|
1992
|
-
const
|
|
1993
|
-
return `${
|
|
942
|
+
dev: (e, t) => {
|
|
943
|
+
const r = t ? `${b(e.method)}${e.method.padEnd(7)}${E.reset}` : e.method.padEnd(7), s = t ? `${e.statusColor}${e.status}${E.reset}` : String(e.status), o = e.responseTime < 100 ? `${e.responseTime}ms` : e.responseTime < 1e3 ? `\x1B[33m${e.responseTime}ms${E.reset}` : `\x1B[31m${e.responseTime}ms${E.reset}`;
|
|
944
|
+
return `${r} ${e.url} ${s} ${t ? o : `${e.responseTime}ms`} - ${e.contentLength}`;
|
|
1994
945
|
},
|
|
1995
|
-
combined: (
|
|
1996
|
-
common: (
|
|
946
|
+
combined: (e) => `${e.remoteAddr} - - [${e.date}] "${e.method} ${e.url} ${e.httpVersion}" ${e.status} ${e.contentLength} "${e.referrer}" "${e.userAgent}"`,
|
|
947
|
+
common: (e) => `${e.remoteAddr} - - [${e.date}] "${e.method} ${e.url} ${e.httpVersion}" ${e.status} ${e.contentLength}`,
|
|
1997
948
|
custom: () => ""
|
|
1998
949
|
// Handled separately
|
|
1999
950
|
};
|
|
2000
|
-
function
|
|
951
|
+
function We(e = {}) {
|
|
2001
952
|
const {
|
|
2002
|
-
format:
|
|
2003
|
-
skip:
|
|
2004
|
-
immediate:
|
|
2005
|
-
customFormat:
|
|
2006
|
-
colorize:
|
|
2007
|
-
} =
|
|
2008
|
-
return (
|
|
2009
|
-
const
|
|
2010
|
-
|
|
2011
|
-
const
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
const
|
|
2015
|
-
if (
|
|
2016
|
-
return
|
|
2017
|
-
const
|
|
953
|
+
format: t = "dev",
|
|
954
|
+
skip: r,
|
|
955
|
+
immediate: s = !1,
|
|
956
|
+
customFormat: o,
|
|
957
|
+
colorize: n = !0
|
|
958
|
+
} = e;
|
|
959
|
+
return (c, l, i) => {
|
|
960
|
+
const f = Date.now();
|
|
961
|
+
s && P.info(y("http.requestStart", { method: c.method, url: c.url }));
|
|
962
|
+
const p = l.end;
|
|
963
|
+
l.end = function(g, a, u) {
|
|
964
|
+
l.end = p;
|
|
965
|
+
const h = l.end(g, a, u);
|
|
966
|
+
if (r && r(c, l))
|
|
967
|
+
return h;
|
|
968
|
+
const d = ye(c, l, f);
|
|
2018
969
|
let m;
|
|
2019
|
-
return
|
|
2020
|
-
},
|
|
970
|
+
return t === "custom" && o ? m = o(d) : m = Ae[t](d, n), d.status >= 500 ? P.error(m) : d.status >= 400 ? P.warn(m) : P.info(m), h;
|
|
971
|
+
}, i();
|
|
2021
972
|
};
|
|
2022
973
|
}
|
|
2023
|
-
const
|
|
974
|
+
const Je = {
|
|
2024
975
|
/** Skip successful responses */
|
|
2025
|
-
successOnly: (
|
|
976
|
+
successOnly: (e, t) => t.statusCode < 400,
|
|
2026
977
|
/** Skip health check endpoints */
|
|
2027
|
-
healthChecks: (
|
|
978
|
+
healthChecks: (e) => e.url === "/health" || e.url === "/healthz" || e.url === "/ready",
|
|
2028
979
|
/** Skip static files */
|
|
2029
|
-
staticFiles: (
|
|
980
|
+
staticFiles: (e) => /\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$/i.test(e.url),
|
|
2030
981
|
/** Skip based on custom paths */
|
|
2031
|
-
paths: (
|
|
982
|
+
paths: (e) => (t) => e.some((r) => t.url.startsWith(r))
|
|
2032
983
|
};
|
|
2033
|
-
function
|
|
2034
|
-
return
|
|
984
|
+
function Ye(e) {
|
|
985
|
+
return e;
|
|
2035
986
|
}
|
|
2036
987
|
export {
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
988
|
+
it as CONTENT_TYPES,
|
|
989
|
+
Wt as CacheManager,
|
|
990
|
+
ke as ChangelogManager,
|
|
991
|
+
Ue as DELETE,
|
|
992
|
+
fr as DockerManager,
|
|
993
|
+
Ne as GET,
|
|
994
|
+
ct as HEADERS,
|
|
995
|
+
ut as HTTP_METHODS,
|
|
996
|
+
T as HTTP_STATUS,
|
|
997
|
+
lt as HarborDocument,
|
|
2046
998
|
O as HarborError,
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
rt as
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
999
|
+
rr as JWT,
|
|
1000
|
+
Jt as MemoryCache,
|
|
1001
|
+
ht as Model,
|
|
1002
|
+
tt as MongoValidator,
|
|
1003
|
+
De as PATCH,
|
|
1004
|
+
be as POST,
|
|
1005
|
+
Fe as PUT,
|
|
1006
|
+
ft as Query,
|
|
1007
|
+
Rt as RateLimitRedisStore,
|
|
1008
|
+
Yt as RedisCache,
|
|
1009
|
+
K as RouteBuilder,
|
|
1010
|
+
zt as Scheduler,
|
|
1011
|
+
pt as Schema,
|
|
1012
|
+
mt as Types,
|
|
1013
|
+
kt as WebSocketManager,
|
|
1014
|
+
gt as addTranslations,
|
|
1015
|
+
sr as apiKeyAuth,
|
|
1016
|
+
Zt as cache,
|
|
1017
|
+
Xt as cacheResponse,
|
|
1018
|
+
qt as cached,
|
|
1019
|
+
Tt as connect,
|
|
1020
|
+
Et as connection,
|
|
1021
|
+
er as createCache,
|
|
1022
|
+
Se as createChangelogManager,
|
|
1023
|
+
Ye as createCustomFormat,
|
|
1024
|
+
pr as createDockerManager,
|
|
1025
|
+
he as createErrorHandler,
|
|
1026
|
+
or as createJwt,
|
|
1027
|
+
w as createLogger,
|
|
1028
|
+
rt as createMongoSchema,
|
|
1029
|
+
st as createParamValidator,
|
|
1030
|
+
B as createRouter,
|
|
1031
|
+
Qt as createScheduler,
|
|
1032
|
+
Be as createServer,
|
|
1033
|
+
Gt as createWebSocketServer,
|
|
1034
|
+
Ct as customHealthCheck,
|
|
1035
|
+
ve as deepMerge,
|
|
1036
|
+
_t as defaultRegistry,
|
|
1037
|
+
Ie as defineConfig,
|
|
1038
|
+
St as disconnect,
|
|
1039
|
+
Pt as diskHealthCheck,
|
|
1040
|
+
Qe as formatDate,
|
|
1041
|
+
nr as generateApiKey,
|
|
1042
|
+
ze as generateId,
|
|
1043
|
+
vt as getAvailableLocales,
|
|
1044
|
+
$t as getLocale,
|
|
1045
|
+
ar as hashPassword,
|
|
1046
|
+
Lt as healthCheck,
|
|
1047
|
+
We as httpLogger,
|
|
1048
|
+
ir as jwtAuth,
|
|
1049
|
+
re as loadConfig,
|
|
1050
|
+
Ht as memoryHealthCheck,
|
|
1051
|
+
xt as metricsEndpoint,
|
|
1052
|
+
It as metricsMiddleware,
|
|
1053
|
+
Mt as mimeToExtension,
|
|
1054
|
+
Ot as model,
|
|
1055
|
+
Nt as mongoHealthCheck,
|
|
1056
|
+
Ve as omit,
|
|
1057
|
+
Ge as pick,
|
|
1058
|
+
bt as rateLimit,
|
|
1059
|
+
Ft as redisHealthCheck,
|
|
1060
|
+
yt as registerLocale,
|
|
1061
|
+
cr as requirePermission,
|
|
1062
|
+
ur as requireRole,
|
|
1063
|
+
je as route,
|
|
1064
|
+
Me as router,
|
|
1065
|
+
qe as setGlobalLogLevel,
|
|
1066
|
+
At as setLocale,
|
|
1067
|
+
Je as skipFunctions,
|
|
1068
|
+
Ke as sleep,
|
|
1069
|
+
Dt as slidingWindowRateLimit,
|
|
1070
|
+
y as t,
|
|
1071
|
+
Ut as upload,
|
|
1072
|
+
ot as validateField,
|
|
1073
|
+
jt as validateFileType,
|
|
1074
|
+
I as validateRequest,
|
|
1075
|
+
nt as validators,
|
|
1076
|
+
dr as verifyPassword,
|
|
1077
|
+
lr as verifySignature
|
|
2093
1078
|
};
|
|
2094
1079
|
//# sourceMappingURL=index.es.js.map
|