@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.
Files changed (123) hide show
  1. package/CHANGELOG.md +82 -101
  2. package/README.md +210 -794
  3. package/dist/auth/apiKey.d.ts +6 -0
  4. package/dist/auth/apiKey.d.ts.map +1 -0
  5. package/dist/auth/index.d.ts +7 -0
  6. package/dist/auth/index.d.ts.map +1 -0
  7. package/dist/auth/index.js +2 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/auth/jwt.d.ts +21 -0
  10. package/dist/auth/jwt.d.ts.map +1 -0
  11. package/dist/auth/password.d.ts +6 -0
  12. package/dist/auth/password.d.ts.map +1 -0
  13. package/dist/auth/rbac.d.ts +6 -0
  14. package/dist/auth/rbac.d.ts.map +1 -0
  15. package/dist/auth/signing.d.ts +5 -0
  16. package/dist/auth/signing.d.ts.map +1 -0
  17. package/dist/auth/types/apiKey.types.d.ts +9 -0
  18. package/dist/auth/types/apiKey.types.d.ts.map +1 -0
  19. package/dist/auth/types/index.d.ts +5 -0
  20. package/dist/auth/types/index.d.ts.map +1 -0
  21. package/dist/auth/types/jwt.types.d.ts +17 -0
  22. package/dist/auth/types/jwt.types.d.ts.map +1 -0
  23. package/dist/auth/types/rbac.types.d.ts +8 -0
  24. package/dist/auth/types/rbac.types.d.ts.map +1 -0
  25. package/dist/auth/types/signing.types.d.ts +8 -0
  26. package/dist/auth/types/signing.types.d.ts.map +1 -0
  27. package/dist/cache/index.d.ts +4 -0
  28. package/dist/cache/index.d.ts.map +1 -0
  29. package/dist/cache/index.js +2 -0
  30. package/dist/cache/index.js.map +1 -0
  31. package/dist/cache/manager.d.ts +24 -0
  32. package/dist/cache/manager.d.ts.map +1 -0
  33. package/dist/cache/stores.d.ts +28 -0
  34. package/dist/cache/stores.d.ts.map +1 -0
  35. package/dist/cache/types.d.ts +23 -0
  36. package/dist/cache/types.d.ts.map +1 -0
  37. package/dist/cli/index.js +21 -22
  38. package/dist/cli/index.js.map +1 -1
  39. package/dist/core/config.d.ts.map +1 -1
  40. package/dist/core/router.d.ts +40 -2
  41. package/dist/core/router.d.ts.map +1 -1
  42. package/dist/core/server.d.ts.map +1 -1
  43. package/dist/database/connection.d.ts +1 -2
  44. package/dist/database/connection.d.ts.map +1 -1
  45. package/dist/database/index.js +2 -0
  46. package/dist/database/index.js.map +1 -0
  47. package/dist/database/model.d.ts +1 -4
  48. package/dist/database/model.d.ts.map +1 -1
  49. package/dist/docker/index.js +1 -1
  50. package/dist/http.const-BKHG1Lsj.mjs +62 -0
  51. package/dist/http.const-BKHG1Lsj.mjs.map +1 -0
  52. package/dist/http.const-Ckcy7OFp.js +2 -0
  53. package/dist/http.const-Ckcy7OFp.js.map +1 -0
  54. package/dist/index-Ca4WpLvw.js +2 -0
  55. package/dist/index-Ca4WpLvw.js.map +1 -0
  56. package/dist/index-DIVHd6rO.mjs +1054 -0
  57. package/dist/index-DIVHd6rO.mjs.map +1 -0
  58. package/dist/index.cjs.js +16 -16
  59. package/dist/index.cjs.js.map +1 -1
  60. package/dist/index.d.ts +11 -2
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.es.js +676 -1691
  63. package/dist/index.es.js.map +1 -1
  64. package/dist/logger-CZn7QxCl.mjs +102 -0
  65. package/dist/{logger-D7aJSi62.mjs.map → logger-CZn7QxCl.mjs.map} +1 -1
  66. package/dist/logger-D-lfaRWQ.js +3 -0
  67. package/dist/{logger-DEnWXtpk.js.map → logger-D-lfaRWQ.js.map} +1 -1
  68. package/dist/manager-CjcKb4P9.mjs +149 -0
  69. package/dist/{manager-B6vqJgEn.mjs.map → manager-CjcKb4P9.mjs.map} +1 -1
  70. package/dist/manager-DrF1vbJg.js +4 -0
  71. package/dist/{manager-B1UKMjXW.js.map → manager-DrF1vbJg.js.map} +1 -1
  72. package/dist/middleware/health.d.ts +65 -0
  73. package/dist/middleware/health.d.ts.map +1 -0
  74. package/dist/middleware/index.d.ts +5 -0
  75. package/dist/middleware/index.d.ts.map +1 -0
  76. package/dist/middleware/index.js +2 -0
  77. package/dist/middleware/index.js.map +1 -0
  78. package/dist/middleware/metrics.d.ts +68 -0
  79. package/dist/middleware/metrics.d.ts.map +1 -0
  80. package/dist/middleware/rateLimit.d.ts +52 -0
  81. package/dist/middleware/rateLimit.d.ts.map +1 -0
  82. package/dist/middleware/upload.d.ts +59 -0
  83. package/dist/middleware/upload.d.ts.map +1 -0
  84. package/dist/password-BXBkKbv3.js +2 -0
  85. package/dist/password-BXBkKbv3.js.map +1 -0
  86. package/dist/password-y4m307oa.mjs +223 -0
  87. package/dist/password-y4m307oa.mjs.map +1 -0
  88. package/dist/scheduler/index.d.ts +3 -0
  89. package/dist/scheduler/index.d.ts.map +1 -0
  90. package/dist/scheduler/index.js +2 -0
  91. package/dist/scheduler/index.js.map +1 -0
  92. package/dist/scheduler/scheduler.d.ts +30 -0
  93. package/dist/scheduler/scheduler.d.ts.map +1 -0
  94. package/dist/scheduler/types.d.ts +25 -0
  95. package/dist/scheduler/types.d.ts.map +1 -0
  96. package/dist/types/server.types.d.ts +7 -0
  97. package/dist/types/server.types.d.ts.map +1 -1
  98. package/dist/upload-9lCNnKK_.js +5 -0
  99. package/dist/upload-9lCNnKK_.js.map +1 -0
  100. package/dist/upload-DUjQiuq7.mjs +619 -0
  101. package/dist/upload-DUjQiuq7.mjs.map +1 -0
  102. package/dist/validation/index.js +1 -1
  103. package/dist/validation/index.js.map +1 -1
  104. package/dist/websocket/index.d.ts +3 -0
  105. package/dist/websocket/index.d.ts.map +1 -0
  106. package/dist/websocket/index.js +2 -0
  107. package/dist/websocket/index.js.map +1 -0
  108. package/dist/websocket/manager.d.ts +30 -0
  109. package/dist/websocket/manager.d.ts.map +1 -0
  110. package/dist/websocket/types.d.ts +27 -0
  111. package/dist/websocket/types.d.ts.map +1 -0
  112. package/package.json +58 -18
  113. package/templates/default/controllers/user.controller.ts +44 -64
  114. package/templates/default/package.json +9 -33
  115. package/templates/default/routes/index.ts +2 -12
  116. package/templates/default/routes/user.routes.ts +26 -19
  117. package/templates/default/server.ts +16 -35
  118. package/dist/logger-D7aJSi62.mjs +0 -102
  119. package/dist/logger-DEnWXtpk.js +0 -3
  120. package/dist/manager-B1UKMjXW.js +0 -4
  121. package/dist/manager-B6vqJgEn.mjs +0 -152
  122. package/dist/portal.d.ts +0 -13
  123. package/dist/portal.d.ts.map +0 -1
package/dist/index.es.js CHANGED
@@ -1,83 +1,34 @@
1
- var ee = Object.defineProperty;
2
- var te = (r, e, t) => e in r ? ee(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var c = (r, e, t) => te(r, typeof e != "symbol" ? e + "" : e, t);
4
- import q, { Router as ne } from "express";
5
- import { createServer as re } from "http";
6
- import { readFileSync as X, existsSync as I, writeFileSync as se } from "fs";
7
- import { resolve as R } from "path";
8
- import { c as A } from "./logger-D7aJSi62.mjs";
9
- import { s as kt } from "./logger-D7aJSi62.mjs";
10
- import { validateRequest as F } from "./validation/index.js";
11
- import { MongoValidator as Ht, createMongoSchema as Nt, createParamValidator as It, validateField as xt, validators as Dt } from "./validation/index.js";
12
- import { EventEmitter as oe } from "events";
13
- import { ObjectId as v } from "mongodb";
14
- import { D as jt, c as Lt } from "./manager-B6vqJgEn.mjs";
15
- const ie = [
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
- ], x = {
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
- }, Xe = {
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: ce,
80
- host: de,
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: ue
41
+ limit: ee
91
42
  },
92
43
  trustProxy: !1
93
44
  },
94
45
  routes: {
95
46
  prefix: "",
96
- timeout: le,
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
- }, he = 1e4, B = A("config");
143
- function me(r) {
144
- const e = fe(r);
145
- if (!e)
146
- return B.info("No config file found, using defaults"), V(D);
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 t = X(e, "utf-8"), n = JSON.parse(t), s = z(
149
- D,
150
- n
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 et(r) {
158
- return z(
159
- D,
160
- r
161
- );
105
+ function Ie(e) {
106
+ return U(x, e);
162
107
  }
163
- function fe(r) {
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 t = R(process.cwd(), e);
171
- if (I(t))
172
- return t;
110
+ const r = _(process.cwd(), e);
111
+ return L(r) ? r : null;
173
112
  }
174
- for (const t of ie) {
175
- const n = R(process.cwd(), t);
176
- if (I(n))
177
- return n;
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 V(r) {
182
- const e = process.env[x.PORT], t = process.env[x.HOST], n = process.env[x.LOG_LEVEL];
183
- return e && (r.server.port = parseInt(e, 10)), t && (r.server.host = t), n && (r.logger.level = n), r;
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 z(r, e) {
186
- const t = { ...r };
187
- for (const n in e)
188
- if (Object.prototype.hasOwnProperty.call(e, n)) {
189
- const s = e[n], o = r[n];
190
- s !== null && typeof s == "object" && !Array.isArray(s) && o !== null && typeof o == "object" && !Array.isArray(o) ? t[n] = z(
191
- o,
192
- s
193
- ) : s !== void 0 && (t[n] = s);
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 t;
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 _e = A("router");
407
- function K(r, e) {
408
- const t = ne();
409
- return r.middleware && r.middleware.forEach((n) => t.use(n)), r.routes && r.routes.forEach((n) => {
410
- ye(t, n, e);
411
- }), t;
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 ye(r, e, t) {
414
- const n = e.method.toLowerCase(), s = we(e, t);
415
- r[n](e.path, ...s), _e.debug(C("router.registered", { method: e.method, path: e.path }));
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 we(r, e) {
418
- const t = [], n = r.options ?? {};
419
- return n.pre && n.pre.forEach((s) => {
420
- t.push(ve(s));
421
- }), n.validation && t.push(Ce(n.validation, e)), n.timeout && t.push(Te(n.timeout)), t.push(be(r.handler, n)), t;
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 ve(r) {
424
- return async (e, t, n) => {
159
+ function Q(e) {
160
+ return async (t, r, s) => {
425
161
  try {
426
- await r(e, t, n);
427
- } catch (s) {
428
- n(s);
162
+ await e(t, r, s);
163
+ } catch (o) {
164
+ s(o);
429
165
  }
430
166
  };
431
167
  }
432
- function be(r, e) {
433
- return async (t, n, s) => {
168
+ function ae(e, t) {
169
+ return async (r, s, o) => {
434
170
  try {
435
- const o = await r(t, n);
436
- if (e.post && e.post.length > 0)
437
- for (const i of e.post)
438
- await i(t, n, o);
439
- !n.headersSent && o !== void 0 && n.json({
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: o
177
+ data: n
442
178
  });
443
- } catch (o) {
444
- s(o);
179
+ } catch (n) {
180
+ o(n);
445
181
  }
446
182
  };
447
183
  }
448
- function Ce(r, e) {
449
- return async (t, n, s) => {
184
+ function ie(e, t) {
185
+ return async (r, s, o) => {
450
186
  try {
451
- const o = {};
452
- if (r.params) {
453
- const i = await F(r.params, t.params, e.validation);
454
- if (!i.valid) {
455
- n.status(p.BAD_REQUEST).json({
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: C("validation.failed"),
459
- details: i.errors
194
+ message: y("validation.failed"),
195
+ details: c.errors
460
196
  }
461
197
  });
462
198
  return;
463
199
  }
464
- o.params = i.data;
200
+ n.params = c.data;
465
201
  }
466
- if (r.query) {
467
- const i = await F(r.query, t.query, e.validation);
468
- if (!i.valid) {
469
- n.status(p.BAD_REQUEST).json({
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: C("validation.failed"),
473
- details: i.errors
208
+ message: y("validation.failed"),
209
+ details: c.errors
474
210
  }
475
211
  });
476
212
  return;
477
213
  }
478
- o.query = i.data;
214
+ n.query = c.data;
479
215
  }
480
- if (r.body) {
481
- const i = await F(r.body, t.body, e.validation);
482
- if (!i.valid) {
483
- n.status(p.BAD_REQUEST).json({
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: C("validation.failed"),
487
- details: i.errors
222
+ message: y("validation.failed"),
223
+ details: c.errors
488
224
  }
489
225
  });
490
226
  return;
491
227
  }
492
- o.body = i.data;
228
+ n.body = c.data;
493
229
  }
494
- t.validated = o, s();
495
- } catch (o) {
496
- s(o);
230
+ r.validated = n, o();
231
+ } catch (n) {
232
+ o(n);
497
233
  }
498
234
  };
499
235
  }
500
- function Te(r) {
501
- return (e, t, n) => {
502
- const s = setTimeout(() => {
503
- t.headersSent || t.status(p.GATEWAY_TIMEOUT).json({
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: C("errors.timeout")
242
+ message: y("errors.timeout")
507
243
  }
508
244
  });
509
- }, r);
510
- t.on("finish", () => clearTimeout(s)), t.on("close", () => clearTimeout(s)), n();
245
+ }, e);
246
+ r.on("finish", () => clearTimeout(o)), r.on("close", () => clearTimeout(o)), s();
511
247
  };
512
248
  }
513
- function it(r, e, t) {
514
- return P("GET", r, e, t);
515
- }
516
- function at(r, e, t) {
517
- return P("POST", r, e, t);
518
- }
519
- function ct(r, e, t) {
520
- return P("PUT", r, e, t);
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 lt(r, e, t) {
526
- return P("DELETE", r, e, t);
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 ut(r, e, t, n) {
529
- return P(r, e, t, n);
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 P(r, e, t, n) {
280
+ function v(e, t, r, s) {
532
281
  return {
533
- path: e,
534
- method: r,
535
- handler: t,
536
- options: n ? {
537
- pre: n.pre,
538
- post: n.post,
539
- validation: n.validation,
540
- timeout: n.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
- class J {
545
- constructor() {
546
- c(this, "_route", {});
547
- c(this, "_options", {});
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 J();
321
+ return new K();
551
322
  }
552
- path(e) {
553
- return this._route.path = e, this;
323
+ path(t) {
324
+ return this._route.path = t, this;
554
325
  }
555
- method(e) {
556
- return this._route.method = e, this;
326
+ method(t) {
327
+ return this._route.method = t, this;
557
328
  }
558
- get(e) {
559
- return this.method("GET").path(e);
329
+ get(t) {
330
+ return this.method("GET").path(t);
560
331
  }
561
- post(e) {
562
- return this.method("POST").path(e);
332
+ post(t) {
333
+ return this.method("POST").path(t);
563
334
  }
564
- put(e) {
565
- return this.method("PUT").path(e);
335
+ put(t) {
336
+ return this.method("PUT").path(t);
566
337
  }
567
- patch(e) {
568
- return this.method("PATCH").path(e);
338
+ patch(t) {
339
+ return this.method("PATCH").path(t);
569
340
  }
570
- delete(e) {
571
- return this.method("DELETE").path(e);
341
+ delete(t) {
342
+ return this.method("DELETE").path(t);
572
343
  }
573
- handler(e) {
574
- if (this._route.handler = e, !this._route.path || !this._route.method || !this._route.handler)
575
- throw new Error(C("router.missingRequired"));
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(...e) {
584
- return this._options.pre = [...this._options.pre ?? [], ...e], this;
354
+ pre(...t) {
355
+ return this._options.pre = [...this._options.pre ?? [], ...t], this;
585
356
  }
586
- postFn(...e) {
587
- return this._options.post = [...this._options.post ?? [], ...e], this;
357
+ postFn(...t) {
358
+ return this._options.post = [...this._options.post ?? [], ...t], this;
588
359
  }
589
- validate(e) {
590
- return this._options.validation = e, this;
360
+ validate(t) {
361
+ return this._options.validation = t, this;
591
362
  }
592
- timeout(e) {
593
- return this._options.timeout = e, this;
363
+ timeout(t) {
364
+ return this._options.timeout = t, this;
594
365
  }
595
- rateLimit(e) {
596
- return this._options.rateLimit = e, this;
366
+ rateLimit(t) {
367
+ return this._options.rateLimit = t, this;
597
368
  }
598
- auth(e) {
599
- return this._options.auth = e, this;
369
+ auth(t) {
370
+ return this._options.auth = t, this;
600
371
  }
601
- cache(e) {
602
- return this._options.cache = e, this;
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(C("router.missingRequired"));
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 Oe = A("error");
386
+ const le = w("error");
617
387
  class O extends Error {
618
- constructor(t, n = p.INTERNAL_SERVER_ERROR, s) {
619
- super(t);
620
- c(this, "statusCode");
621
- c(this, "code");
622
- c(this, "details");
623
- c(this, "isOperational");
624
- this.name = "HarborError", this.statusCode = n, this.code = s == null ? void 0 : s.code, this.details = s == null ? void 0 : s.details, this.isOperational = (s == null ? void 0 : s.isOperational) ?? !0, Error.captureStackTrace(this, this.constructor);
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
- p.BAD_REQUEST,
630
- { code: "BAD_REQUEST", details: n }
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
- p.UNAUTHORIZED,
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
- p.FORBIDDEN,
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
- p.NOT_FOUND,
419
+ T.NOT_FOUND,
651
420
  { code: "NOT_FOUND" }
652
421
  );
653
422
  }
654
- static conflict(t, n) {
423
+ static conflict(t, r) {
655
424
  return new O(
656
425
  t ?? "Conflict",
657
- p.CONFLICT,
658
- { code: "CONFLICT", details: n }
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
- p.INTERNAL_SERVER_ERROR,
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
- p.TOO_MANY_REQUESTS,
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 Ee(r) {
688
- const e = r.errors;
689
- return (t, n, s, o) => {
690
- const i = t.statusCode ?? p.INTERNAL_SERVER_ERROR, a = Se(i, e);
691
- if ((a == null ? void 0 : a.log) !== !1 && r.logger.enabled && Oe.error(`${n.method} ${n.path} - ${t.message}`, t), s.headersSent)
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 (a != null && a.redirect) {
694
- s.redirect(a.redirect);
462
+ if (l?.redirect) {
463
+ o.redirect(l.redirect);
695
464
  return;
696
465
  }
697
- const h = Ae(t, i, a);
698
- (a == null ? void 0 : a.json) !== !1 ? s.status(i).json(h) : s.status(i).send(h.error.message);
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 Se(r, e) {
702
- const t = r.toString();
703
- return e[t] ?? e.default;
470
+ function fe(e, t) {
471
+ const r = e.toString();
472
+ return t[r] ?? t.default;
704
473
  }
705
- function Ae(r, e, t) {
706
- return r instanceof O ? r.toJSON() : {
474
+ function pe(e, t, r) {
475
+ return e instanceof O ? e.toJSON() : {
707
476
  success: !1,
708
477
  error: {
709
- message: (t == null ? void 0 : t.message) ?? r.message ?? ae[e] ?? "An error occurred",
710
- statusCode: e
478
+ message: r?.message ?? e.message ?? J[t] ?? "An error occurred",
479
+ statusCode: t
711
480
  }
712
481
  };
713
482
  }
714
- const S = A("server");
715
- function ht(r = {}) {
716
- const e = me(r.configPath), t = q();
717
- let n = null, s = "stopped", o = null;
718
- const i = [];
719
- Pe(t, e);
720
- const a = {
721
- app: t,
722
- server: n,
723
- config: e,
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 (s === "running")
726
- return S.warn("Server is already running"), a.getInfo();
727
- s = "starting";
728
- const h = r.port ?? e.server.port, g = r.host ?? e.server.host ?? "localhost";
729
- return new Promise((w, b) => {
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
- n = re(t), a.server = n, n.listen(h, g, () => {
732
- var l;
733
- s = "running", o = /* @__PURE__ */ new Date();
734
- const d = a.getInfo();
735
- S.info(`Server started on http://${g}:${h}`), (l = r.onReady) == null || l.call(r, d), w(d);
736
- }), n.on("error", (d) => {
737
- var l;
738
- s = "error", S.error("Server error", d), (l = r.onError) == null || l.call(r, d), b(d);
739
- }), Re(a);
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 (!(!n || s === "stopped"))
747
- return s = "stopping", new Promise((h, g) => {
748
- const w = setTimeout(() => {
749
- n == null || n.close(), h();
750
- }, he);
751
- n.close((b) => {
752
- clearTimeout(w), b ? (S.error("Error stopping server", b), g(b)) : (s = "stopped", o = null, S.info("Server stopped"), h());
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 a.stop(), a.start();
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
- addRoute(h) {
760
- i.push(h);
761
- const g = K({ routes: [h] }, e);
762
- t.use(g);
540
+ addMiddleware(i) {
541
+ r.use(i);
763
542
  },
764
- addRouteGroup(h) {
765
- i.push(...h.routes);
766
- const g = K({
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
- addMiddleware(h) {
774
- t.use(h);
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 h = r.port ?? e.server.port, g = r.host ?? e.server.host ?? "localhost";
569
+ const i = e.port ?? t.server.port, f = e.host ?? t.server.host ?? "localhost";
778
570
  return {
779
- port: h,
780
- host: g,
781
- uptime: o ? Date.now() - o.getTime() : 0,
782
- startedAt: o,
783
- routes: i.map((w) => ({
784
- path: w.path,
785
- method: w.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: s
580
+ status: o
789
581
  };
790
582
  }
791
583
  };
792
- return r.autoStart !== !1 && a.start().catch((h) => {
793
- S.error("Failed to auto-start server", h);
794
- }), a;
584
+ return e.autoStart === !0 && l.start().catch((i) => {
585
+ A.error("Failed to auto-start server", i);
586
+ }), l;
795
587
  }
796
- function Pe(r, e) {
797
- var n, s, o;
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: e.server.bodyParser.limit
801
- })), (o = e.server.cors) != null && o.enabled && r.use($e(e.server.cors)), r.use(ke());
802
- const t = Ee(e);
803
- r.use(t);
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 $e(r) {
806
- return (e, t, n) => {
807
- var o;
808
- const s = r.origin;
809
- if (s === !0 || s === "*")
810
- t.setHeader("Access-Control-Allow-Origin", "*");
811
- else if (typeof s == "string")
812
- t.setHeader("Access-Control-Allow-Origin", s);
813
- else if (Array.isArray(s)) {
814
- const i = e.headers.origin;
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 (t.setHeader(
607
+ if (r.setHeader(
818
608
  "Access-Control-Allow-Methods",
819
- ((o = r.methods) == null ? void 0 : o.join(", ")) ?? "GET,POST,PUT,PATCH,DELETE,OPTIONS"
820
- ), r.allowedHeaders ? t.setHeader("Access-Control-Allow-Headers", r.allowedHeaders.join(", ")) : t.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"), r.credentials && t.setHeader("Access-Control-Allow-Credentials", "true"), e.method === "OPTIONS") {
821
- t.status(204).end();
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
- n();
614
+ s();
825
615
  };
826
616
  }
827
- function ke() {
828
- return (r, e, t) => {
829
- r.startTime = Date.now(), r.harborContext = {}, e.success = function(n, s = 200) {
830
- e.status(s).json({
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: n
622
+ data: s
833
623
  });
834
- }, e.error = function(n, s = 500, o) {
835
- e.status(s).json({
624
+ }, t.error = function(s, o = 500, n) {
625
+ t.status(o).json({
836
626
  success: !1,
837
627
  error: {
838
- message: n,
839
- details: o
628
+ message: s,
629
+ details: n
840
630
  }
841
631
  });
842
- }, t();
632
+ }, r();
843
633
  };
844
634
  }
845
- function Re(r) {
846
- ["SIGTERM", "SIGINT"].forEach((t) => {
847
- process.on(t, async () => {
848
- S.info(`Received ${t}, shutting down gracefully`), await r.stop(), process.exit(0);
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
- class Z {
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 xe(r = {}) {
1678
- const e = { ...Ie, ...r }, t = [];
1679
- let n = [];
1680
- function s() {
1681
- const d = R(process.cwd(), e.filePath);
1682
- if (!I(d)) {
1683
- k.info("No changelog file found, starting fresh");
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 l = X(d, "utf-8");
1688
- o(l), k.info("Changelog loaded", { entries: t.length });
1689
- } catch (l) {
1690
- k.error("Failed to load changelog", l);
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 o(d) {
1694
- const l = /## \[(\d+\.\d+\.\d+(?:-[\w.]+)?)\](?: - (\d{4}-\d{2}-\d{2}))?/g, u = d.split(l);
1695
- for (let f = 1; f < u.length; f += 3) {
1696
- const m = u[f], T = u[f + 1], y = u[f + 2];
1697
- if (m && y) {
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: T ? new Date(T) : /* @__PURE__ */ new Date(),
1701
- changes: i(y)
670
+ date: $ ? new Date($) : /* @__PURE__ */ new Date(),
671
+ changes: c(S)
1702
672
  };
1703
- t.push($);
673
+ r.push(R);
1704
674
  }
1705
675
  }
1706
676
  }
1707
- function i(d) {
1708
- const l = [], u = d.split(`
677
+ function c(a) {
678
+ const u = [], h = a.split(`
1709
679
  `);
1710
- let f = null;
1711
- for (const m of u) {
1712
- const T = m.match(/^### (Added|Changed|Deprecated|Removed|Fixed|Security)/i);
1713
- if (T) {
1714
- f = T[1].toLowerCase();
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 y = m.match(/^- (.+)/);
1718
- y && f && l.push({
1719
- type: f,
1720
- description: y[1].trim()
687
+ const S = m.match(/^- (.+)/);
688
+ S && d && u.push({
689
+ type: d,
690
+ description: S[1].trim()
1721
691
  });
1722
692
  }
1723
- return l;
693
+ return u;
1724
694
  }
1725
- function a() {
1726
- const d = R(process.cwd(), e.filePath), l = h();
1727
- se(d, l, "utf-8"), k.info("Changelog saved", { path: d });
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 h() {
1730
- let d = `# Changelog
699
+ function i() {
700
+ let a = `# Changelog
1731
701
 
1732
702
  `;
1733
- d += `All notable changes to this project will be documented in this file.
703
+ a += `All notable changes to this project will be documented in this file.
1734
704
 
1735
- `, d += `The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1736
- `, d += `and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
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
- `, e.includeUnreleased && n.length > 0 && (d += `## [Unreleased]
708
+ `, t.includeUnreleased && s.length > 0 && (a += `## [Unreleased]
1739
709
 
1740
- `, d += g(n), d += `
710
+ `, a += f(s), a += `
1741
711
  `);
1742
- for (const l of t) {
1743
- const u = l.date.toISOString().split("T")[0];
1744
- if (d += `## [${l.version}] - ${u}
712
+ for (const u of r) {
713
+ const h = u.date.toISOString().split("T")[0];
714
+ if (a += `## [${u.version}] - ${h}
1745
715
 
1746
- `, d += g(l.changes), l.breaking && l.breaking.length > 0) {
1747
- d += `### BREAKING CHANGES
716
+ `, a += f(u.changes), u.breaking && u.breaking.length > 0) {
717
+ a += `### BREAKING CHANGES
1748
718
 
1749
719
  `;
1750
- for (const f of l.breaking)
1751
- d += `- ${f.description}
720
+ for (const d of u.breaking)
721
+ a += `- ${d.description}
1752
722
  `;
1753
- d += `
723
+ a += `
1754
724
  `;
1755
725
  }
1756
- d += `
726
+ a += `
1757
727
  `;
1758
728
  }
1759
- return d;
1760
- }
1761
- function g(d) {
1762
- const l = w(d);
1763
- let u = "";
1764
- const f = ["added", "changed", "deprecated", "removed", "fixed", "security"];
1765
- for (const m of f) {
1766
- const T = l[m];
1767
- if (T && T.length > 0) {
1768
- u += `### ${b(m)}
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 y of T) {
1772
- let $ = `- ${y.description}`;
1773
- y.scope && ($ = `- **${y.scope}:** ${y.description}`), y.issue && ($ += ` (#${y.issue})`), u += $ + `
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
- u += `
746
+ h += `
1777
747
  `;
1778
748
  }
1779
749
  }
1780
- return u;
750
+ return h;
1781
751
  }
1782
- function w(d) {
1783
- const l = {
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 u of d)
1792
- l[u.type].push(u);
1793
- return l;
761
+ for (const h of a)
762
+ u[h.type].push(h);
763
+ return u;
1794
764
  }
1795
- function b(d) {
1796
- return d.charAt(0).toUpperCase() + d.slice(1);
765
+ function g(a) {
766
+ return a.charAt(0).toUpperCase() + a.slice(1);
1797
767
  }
1798
768
  return {
1799
- load: s,
1800
- save: a,
1801
- addChange(d, l, u) {
1802
- n.push({
1803
- type: d,
1804
- description: l,
1805
- scope: u == null ? void 0 : u.scope,
1806
- issue: u == null ? void 0 : u.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(d) {
1810
- const l = {
1811
- version: d,
779
+ release(a) {
780
+ const u = {
781
+ version: a,
1812
782
  date: /* @__PURE__ */ new Date(),
1813
- changes: [...n]
783
+ changes: [...s]
1814
784
  };
1815
- return t.unshift(l), n = [], a(), k.info(`Released version ${d}`), l;
785
+ return r.unshift(u), s = [], l(), C.info(`Released version ${a}`), u;
1816
786
  },
1817
787
  getEntries() {
1818
- return [...t];
788
+ return [...r];
1819
789
  },
1820
790
  getUnreleased() {
1821
- return [...n];
791
+ return [...s];
1822
792
  },
1823
793
  getLatestVersion() {
1824
- var d;
1825
- return ((d = t[0]) == null ? void 0 : d.version) ?? null;
794
+ return r[0]?.version ?? null;
1826
795
  },
1827
- getReleaseNotes(d) {
1828
- var f;
1829
- const l = t.find((m) => m.version === d);
1830
- if (!l) return null;
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: l.version,
1834
- date: l.date,
1835
- added: u.added.map((m) => m.description),
1836
- changed: u.changed.map((m) => m.description),
1837
- deprecated: u.deprecated.map((m) => m.description),
1838
- removed: u.removed.map((m) => m.description),
1839
- fixed: u.fixed.map((m) => m.description),
1840
- security: u.security.map((m) => m.description),
1841
- breaking: ((f = l.breaking) == null ? void 0 : f.map((m) => m.description)) ?? []
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 _t {
1847
- constructor(e) {
1848
- c(this, "manager");
1849
- c(this, "load", () => this.manager.load());
1850
- c(this, "save", () => this.manager.save());
1851
- c(this, "addChange", (...e) => this.manager.addChange(...e));
1852
- c(this, "release", (e) => this.manager.release(e));
1853
- c(this, "getEntries", () => this.manager.getEntries());
1854
- c(this, "getUnreleased", () => this.manager.getUnreleased());
1855
- c(this, "getLatestVersion", () => this.manager.getLatestVersion());
1856
- c(this, "getReleaseNotes", (e) => this.manager.getReleaseNotes(e));
1857
- this.manager = xe(e);
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 wt() {
1875
- console.log("[Harbor] API documentation generation is coming soon.");
828
+ function G(e) {
829
+ return typeof e == "object" && e !== null && !Array.isArray(e);
1876
830
  }
1877
- function W(r) {
1878
- return typeof r == "object" && r !== null && !Array.isArray(r);
1879
- }
1880
- function Me(r, e) {
1881
- const t = { ...r };
1882
- for (const n in e)
1883
- if (Object.prototype.hasOwnProperty.call(e, n)) {
1884
- const s = e[n], o = r[n];
1885
- W(s) && W(o) ? t[n] = Me(
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 t;
841
+ return r;
1891
842
  }
1892
- function vt(r, e) {
1893
- const t = {};
1894
- for (const n of e)
1895
- Object.prototype.hasOwnProperty.call(r, n) && (t[n] = r[n]);
1896
- return t;
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 bt(r, e) {
1899
- const t = { ...r };
1900
- for (const n of e)
1901
- delete t[n];
1902
- return t;
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 Ct(r = 16) {
1905
- const e = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1906
- let t = "";
1907
- for (let n = 0; n < r; n++)
1908
- t += e.charAt(Math.floor(Math.random() * e.length));
1909
- return t;
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 Tt(r, e = "ISO") {
1912
- if (e === "ISO")
1913
- return r.toISOString();
1914
- const t = r.getFullYear(), n = String(r.getMonth() + 1).padStart(2, "0"), s = String(r.getDate()).padStart(2, "0"), o = String(r.getHours()).padStart(2, "0"), i = String(r.getMinutes()).padStart(2, "0"), a = String(r.getSeconds()).padStart(2, "0");
1915
- switch (e) {
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 `${t}-${n}-${s}`;
868
+ return `${r}-${s}-${o}`;
1918
869
  case "TIME":
1919
- return `${o}:${i}:${a}`;
870
+ return `${n}:${c}:${l}`;
1920
871
  case "DATETIME":
1921
- return `${t}-${n}-${s} ${o}:${i}:${a}`;
872
+ return `${r}-${s}-${o} ${n}:${c}:${l}`;
1922
873
  default:
1923
- return r.toISOString();
874
+ return e.toISOString();
1924
875
  }
1925
876
  }
1926
- function Ot(r) {
1927
- return new Promise((e) => setTimeout(e, r));
877
+ function Ke(e) {
878
+ return new Promise((t) => setTimeout(t, e));
1928
879
  }
1929
- const N = A("http"), _ = {
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 je(r) {
1943
- return r >= 500 ? _.serverError : r >= 400 ? _.clientError : r >= 300 ? _.redirect : r >= 200 ? _.success : _.info;
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 G(r) {
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
- }[r] ?? "\x1B[0m";
912
+ }[e] ?? "\x1B[0m";
1962
913
  }
1963
- function Le(r) {
1964
- return r === 0 ? "-" : r < 1024 ? `${r}B` : r < 1024 * 1024 ? `${(r / 1024).toFixed(1)}KB` : `${(r / (1024 * 1024)).toFixed(1)}MB`;
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 Ue(r, e, t) {
1967
- const n = Date.now() - t, s = e.statusCode, o = e.get("content-length") ?? "0";
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: r.method,
1970
- url: r.originalUrl || r.url,
1971
- status: s,
1972
- statusColor: je(s),
1973
- responseTime: n,
1974
- contentLength: Le(parseInt(o, 10) || 0),
1975
- remoteAddr: r.ip || r.socket.remoteAddress || "-",
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/${r.httpVersionMajor}.${r.httpVersionMinor}`,
1978
- userAgent: r.get("user-agent") ?? "-",
1979
- referrer: r.get("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 Fe = {
1983
- tiny: (r, e) => {
1984
- const t = e ? `${G(r.method)}${r.method}${_.reset}` : r.method, n = e ? `${r.statusColor}${r.status}${_.reset}` : String(r.status);
1985
- return `${t} ${r.url} ${n} ${r.responseTime}ms`;
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: (r, e) => {
1988
- const t = e ? `${G(r.method)}${r.method}${_.reset}` : r.method, n = e ? `${r.statusColor}${r.status}${_.reset}` : String(r.status);
1989
- return `${r.remoteAddr} ${t} ${r.url} ${n} ${r.responseTime}ms - ${r.contentLength}`;
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: (r, e) => {
1992
- const t = e ? `${G(r.method)}${r.method.padEnd(7)}${_.reset}` : r.method.padEnd(7), n = e ? `${r.statusColor}${r.status}${_.reset}` : String(r.status), s = r.responseTime < 100 ? `${r.responseTime}ms` : r.responseTime < 1e3 ? `\x1B[33m${r.responseTime}ms${_.reset}` : `\x1B[31m${r.responseTime}ms${_.reset}`;
1993
- return `${t} ${r.url} ${n} ${e ? s : `${r.responseTime}ms`} - ${r.contentLength}`;
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: (r) => `${r.remoteAddr} - - [${r.date}] "${r.method} ${r.url} ${r.httpVersion}" ${r.status} ${r.contentLength} "${r.referrer}" "${r.userAgent}"`,
1996
- common: (r) => `${r.remoteAddr} - - [${r.date}] "${r.method} ${r.url} ${r.httpVersion}" ${r.status} ${r.contentLength}`,
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 Et(r = {}) {
951
+ function We(e = {}) {
2001
952
  const {
2002
- format: e = "dev",
2003
- skip: t,
2004
- immediate: n = !1,
2005
- customFormat: s,
2006
- colorize: o = !0
2007
- } = r;
2008
- return (i, a, h) => {
2009
- const g = Date.now();
2010
- n && N.info(C("http.requestStart", { method: i.method, url: i.url }));
2011
- const w = a.end;
2012
- a.end = function(b, d, l) {
2013
- a.end = w;
2014
- const u = a.end(b, d, l);
2015
- if (t && t(i, a))
2016
- return u;
2017
- const f = Ue(i, a, g);
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 e === "custom" && s ? m = s(f) : m = Fe[e](f, o), f.status >= 500 ? N.error(m) : f.status >= 400 ? N.warn(m) : N.info(m), u;
2020
- }, h();
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 St = {
974
+ const Je = {
2024
975
  /** Skip successful responses */
2025
- successOnly: (r, e) => e.statusCode < 400,
976
+ successOnly: (e, t) => t.statusCode < 400,
2026
977
  /** Skip health check endpoints */
2027
- healthChecks: (r) => r.url === "/health" || r.url === "/healthz" || r.url === "/ready",
978
+ healthChecks: (e) => e.url === "/health" || e.url === "/healthz" || e.url === "/ready",
2028
979
  /** Skip static files */
2029
- staticFiles: (r) => /\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$/i.test(r.url),
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: (r) => (e) => r.some((t) => e.url.startsWith(t))
982
+ paths: (e) => (t) => e.some((r) => t.url.startsWith(r))
2032
983
  };
2033
- function At(r) {
2034
- return r;
984
+ function Ye(e) {
985
+ return e;
2035
986
  }
2036
987
  export {
2037
- Je as CONTENT_TYPES,
2038
- _t as ChangelogManager,
2039
- lt as DELETE,
2040
- jt as DockerManager,
2041
- it as GET,
2042
- Ze as HEADERS,
2043
- Xe as HTTP_METHODS,
2044
- p as HTTP_STATUS,
2045
- Q as HarborDocument,
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
- L as Model,
2048
- Ht as MongoValidator,
2049
- dt as PATCH,
2050
- at as POST,
2051
- ct as PUT,
2052
- De as PortalGenerator,
2053
- H as Query,
2054
- J as RouteBuilder,
2055
- Z as Schema,
2056
- pt as Types,
2057
- st as addTranslations,
2058
- mt as connect,
2059
- j as connection,
2060
- xe as createChangelogManager,
2061
- At as createCustomFormat,
2062
- Lt as createDockerManager,
2063
- Ee as createErrorHandler,
2064
- A as createLogger,
2065
- Nt as createMongoSchema,
2066
- It as createParamValidator,
2067
- yt as createPortal,
2068
- K as createRouter,
2069
- ht as createServer,
2070
- Me as deepMerge,
2071
- et as defineConfig,
2072
- ft as disconnect,
2073
- Tt as formatDate,
2074
- wt as generateDocs,
2075
- Ct as generateId,
2076
- rt as getAvailableLocales,
2077
- nt as getLocale,
2078
- Et as httpLogger,
2079
- me as loadConfig,
2080
- gt as model,
2081
- bt as omit,
2082
- vt as pick,
2083
- ot as registerLocale,
2084
- ut as route,
2085
- kt as setGlobalLogLevel,
2086
- tt as setLocale,
2087
- St as skipFunctions,
2088
- Ot as sleep,
2089
- C as t,
2090
- xt as validateField,
2091
- F as validateRequest,
2092
- Dt as validators
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