@forgedevstack/harbor 1.0.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -101
- package/README.md +210 -794
- package/dist/auth/apiKey.d.ts +6 -0
- package/dist/auth/apiKey.d.ts.map +1 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/jwt.d.ts +21 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/password.d.ts +6 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/rbac.d.ts +6 -0
- package/dist/auth/rbac.d.ts.map +1 -0
- package/dist/auth/signing.d.ts +5 -0
- package/dist/auth/signing.d.ts.map +1 -0
- package/dist/auth/types/apiKey.types.d.ts +9 -0
- package/dist/auth/types/apiKey.types.d.ts.map +1 -0
- package/dist/auth/types/index.d.ts +5 -0
- package/dist/auth/types/index.d.ts.map +1 -0
- package/dist/auth/types/jwt.types.d.ts +17 -0
- package/dist/auth/types/jwt.types.d.ts.map +1 -0
- package/dist/auth/types/rbac.types.d.ts +8 -0
- package/dist/auth/types/rbac.types.d.ts.map +1 -0
- package/dist/auth/types/signing.types.d.ts +8 -0
- package/dist/auth/types/signing.types.d.ts.map +1 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/manager.d.ts +24 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/stores.d.ts +28 -0
- package/dist/cache/stores.d.ts.map +1 -0
- package/dist/cache/types.d.ts +23 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cli/index.js +21 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/router.d.ts +40 -2
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/database/connection.d.ts +1 -2
- package/dist/database/connection.d.ts.map +1 -1
- package/dist/database/index.js +2 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/model.d.ts +1 -4
- package/dist/database/model.d.ts.map +1 -1
- package/dist/docker/index.js +1 -1
- package/dist/http.const-BKHG1Lsj.mjs +62 -0
- package/dist/http.const-BKHG1Lsj.mjs.map +1 -0
- package/dist/http.const-Ckcy7OFp.js +2 -0
- package/dist/http.const-Ckcy7OFp.js.map +1 -0
- package/dist/index-Ca4WpLvw.js +2 -0
- package/dist/index-Ca4WpLvw.js.map +1 -0
- package/dist/index-DIVHd6rO.mjs +1054 -0
- package/dist/index-DIVHd6rO.mjs.map +1 -0
- package/dist/index.cjs.js +16 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +676 -1691
- package/dist/index.es.js.map +1 -1
- package/dist/logger-CZn7QxCl.mjs +102 -0
- package/dist/{logger-D7aJSi62.mjs.map → logger-CZn7QxCl.mjs.map} +1 -1
- package/dist/logger-D-lfaRWQ.js +3 -0
- package/dist/{logger-DEnWXtpk.js.map → logger-D-lfaRWQ.js.map} +1 -1
- package/dist/manager-CjcKb4P9.mjs +149 -0
- package/dist/{manager-B6vqJgEn.mjs.map → manager-CjcKb4P9.mjs.map} +1 -1
- package/dist/manager-DrF1vbJg.js +4 -0
- package/dist/{manager-B1UKMjXW.js.map → manager-DrF1vbJg.js.map} +1 -1
- package/dist/middleware/health.d.ts +65 -0
- package/dist/middleware/health.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +5 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/metrics.d.ts +68 -0
- package/dist/middleware/metrics.d.ts.map +1 -0
- package/dist/middleware/rateLimit.d.ts +52 -0
- package/dist/middleware/rateLimit.d.ts.map +1 -0
- package/dist/middleware/upload.d.ts +59 -0
- package/dist/middleware/upload.d.ts.map +1 -0
- package/dist/password-BXBkKbv3.js +2 -0
- package/dist/password-BXBkKbv3.js.map +1 -0
- package/dist/password-y4m307oa.mjs +223 -0
- package/dist/password-y4m307oa.mjs.map +1 -0
- package/dist/scheduler/index.d.ts +3 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +30 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/types.d.ts +25 -0
- package/dist/scheduler/types.d.ts.map +1 -0
- package/dist/types/server.types.d.ts +7 -0
- package/dist/types/server.types.d.ts.map +1 -1
- package/dist/upload-9lCNnKK_.js +5 -0
- package/dist/upload-9lCNnKK_.js.map +1 -0
- package/dist/upload-DUjQiuq7.mjs +619 -0
- package/dist/upload-DUjQiuq7.mjs.map +1 -0
- package/dist/validation/index.js +1 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/websocket/index.d.ts +3 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +2 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/manager.d.ts +30 -0
- package/dist/websocket/manager.d.ts.map +1 -0
- package/dist/websocket/types.d.ts +27 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/package.json +58 -18
- package/templates/default/controllers/user.controller.ts +44 -64
- package/templates/default/package.json +9 -33
- package/templates/default/routes/index.ts +2 -12
- package/templates/default/routes/user.routes.ts +26 -19
- package/templates/default/server.ts +16 -35
- package/dist/logger-D7aJSi62.mjs +0 -102
- package/dist/logger-DEnWXtpk.js +0 -3
- package/dist/manager-B1UKMjXW.js +0 -4
- package/dist/manager-B6vqJgEn.mjs +0 -152
- package/dist/portal.d.ts +0 -13
- package/dist/portal.d.ts.map +0 -1
|
@@ -0,0 +1,1054 @@
|
|
|
1
|
+
import { EventEmitter as g } from "events";
|
|
2
|
+
import { ObjectId as c } from "mongodb";
|
|
3
|
+
const y = {
|
|
4
|
+
// Server
|
|
5
|
+
"server.starting": "Server starting...",
|
|
6
|
+
"server.started": "Server started on http://{host}:{port}",
|
|
7
|
+
"server.stopping": "Server stopping...",
|
|
8
|
+
"server.stopped": "Server stopped",
|
|
9
|
+
"server.alreadyRunning": "Server is already running",
|
|
10
|
+
"server.error": "Server error",
|
|
11
|
+
"server.gracefulShutdown": "Received {signal}, shutting down gracefully",
|
|
12
|
+
// Router
|
|
13
|
+
"router.registered": "Registered route: {method} {path}",
|
|
14
|
+
"router.missingRequired": "Route must have path, method, and handler",
|
|
15
|
+
// Validation
|
|
16
|
+
"validation.failed": "Validation failed",
|
|
17
|
+
"validation.required": "{field} is required",
|
|
18
|
+
"validation.typeMismatch": "{field} must be of type {type}",
|
|
19
|
+
"validation.minValue": "{field} must be at least {min}",
|
|
20
|
+
"validation.maxValue": "{field} must be at most {max}",
|
|
21
|
+
"validation.minLength": "{field} must be at least {min} characters",
|
|
22
|
+
"validation.maxLength": "{field} must be at most {max} characters",
|
|
23
|
+
"validation.pattern": "{field} does not match the required pattern",
|
|
24
|
+
"validation.enum": "{field} must be one of: {values}",
|
|
25
|
+
"validation.invalidObjectId": "{field} is not a valid ObjectId",
|
|
26
|
+
"validation.invalidEmail": "{field} is not a valid email address",
|
|
27
|
+
"validation.invalidUrl": "{field} is not a valid URL",
|
|
28
|
+
"validation.invalidDate": "{field} is not a valid date",
|
|
29
|
+
"validation.customFailed": "{field} failed custom validation",
|
|
30
|
+
// Errors
|
|
31
|
+
"errors.badRequest": "Bad Request",
|
|
32
|
+
"errors.unauthorized": "Unauthorized",
|
|
33
|
+
"errors.forbidden": "Forbidden",
|
|
34
|
+
"errors.notFound": "Not Found",
|
|
35
|
+
"errors.conflict": "Conflict",
|
|
36
|
+
"errors.tooManyRequests": "Too Many Requests",
|
|
37
|
+
"errors.internal": "Internal Server Error",
|
|
38
|
+
"errors.timeout": "Request timeout",
|
|
39
|
+
"errors.default": "An error occurred",
|
|
40
|
+
// Config
|
|
41
|
+
"config.notFound": "No config file found, using defaults",
|
|
42
|
+
"config.loaded": "Config loaded from {path}",
|
|
43
|
+
"config.loadFailed": "Failed to load config",
|
|
44
|
+
// Docker
|
|
45
|
+
"docker.containerStarted": "Container started: {name}",
|
|
46
|
+
"docker.containerStopped": "Container stopped: {name}",
|
|
47
|
+
"docker.containerRestarted": "Container restarted: {name}",
|
|
48
|
+
"docker.containerRemoved": "Container removed: {name}",
|
|
49
|
+
"docker.imageBuilt": "Image built: {name}:{tag}",
|
|
50
|
+
"docker.imagePushed": "Image pushed: {name}",
|
|
51
|
+
"docker.imagePulled": "Image pulled: {name}:{tag}",
|
|
52
|
+
"docker.composeUp": "Docker Compose up completed",
|
|
53
|
+
"docker.composeDown": "Docker Compose down completed",
|
|
54
|
+
"docker.commandFailed": "Docker command failed: {command}",
|
|
55
|
+
// Changelog
|
|
56
|
+
"changelog.loaded": "Changelog loaded with {count} entries",
|
|
57
|
+
"changelog.saved": "Changelog saved to {path}",
|
|
58
|
+
"changelog.released": "Released version {version}",
|
|
59
|
+
"changelog.notFound": "No changelog file found, starting fresh",
|
|
60
|
+
// Portal
|
|
61
|
+
"portal.generated": "Portal generated at {path}",
|
|
62
|
+
"portal.generating": "Generating documentation portal...",
|
|
63
|
+
// Logger
|
|
64
|
+
"logger.levelChanged": "Log level changed to {level}",
|
|
65
|
+
// HTTP Logger (Morgan-like)
|
|
66
|
+
"http.request": "{method} {url} {status} {duration}ms",
|
|
67
|
+
"http.requestStart": "Incoming request: {method} {url}",
|
|
68
|
+
"http.requestEnd": "Request completed: {method} {url} - {status} in {duration}ms",
|
|
69
|
+
// CLI
|
|
70
|
+
"cli.init.success": "Harbor project initialized!",
|
|
71
|
+
"cli.init.configExists": "harbor.config.json already exists",
|
|
72
|
+
"cli.init.created": "Created {file}",
|
|
73
|
+
"cli.docs.generating": "Generating API documentation...",
|
|
74
|
+
"cli.docs.success": "Documentation generated successfully",
|
|
75
|
+
"cli.version": "Harbor v{version}",
|
|
76
|
+
"cli.unknownCommand": "Unknown command: {command}",
|
|
77
|
+
// Database
|
|
78
|
+
"database.connected": "Connected to MongoDB at {uri}",
|
|
79
|
+
"database.disconnected": "Disconnected from MongoDB",
|
|
80
|
+
"database.connecting": "Connecting to MongoDB...",
|
|
81
|
+
"database.connectionFailed": "Failed to connect to MongoDB: {error}",
|
|
82
|
+
"database.notConnected": "Not connected to database. Call harbor.connect() first.",
|
|
83
|
+
"database.modelCreated": "Model created: {name}",
|
|
84
|
+
"database.documentSaved": "Document saved: {id}",
|
|
85
|
+
"database.documentDeleted": "Document deleted: {id}",
|
|
86
|
+
"database.validationFailed": "Validation failed: {errors}",
|
|
87
|
+
"database.queryExecuted": "Query executed: {operation} on {collection}",
|
|
88
|
+
"database.indexCreated": "Index created: {name}",
|
|
89
|
+
"database.transactionStarted": "Transaction started",
|
|
90
|
+
"database.transactionCommitted": "Transaction committed",
|
|
91
|
+
"database.transactionAborted": "Transaction aborted"
|
|
92
|
+
}, w = {
|
|
93
|
+
// Server
|
|
94
|
+
"server.starting": "השרת מופעל...",
|
|
95
|
+
"server.started": "השרת פועל בכתובת http://{host}:{port}",
|
|
96
|
+
"server.stopping": "השרת נעצר...",
|
|
97
|
+
"server.stopped": "השרת נעצר",
|
|
98
|
+
"server.alreadyRunning": "השרת כבר פועל",
|
|
99
|
+
"server.error": "שגיאת שרת",
|
|
100
|
+
"server.gracefulShutdown": "התקבל {signal}, מכבה בצורה מסודרת",
|
|
101
|
+
// Router
|
|
102
|
+
"router.registered": "נרשם נתיב: {method} {path}",
|
|
103
|
+
"router.missingRequired": "נתיב חייב לכלול path, method ו-handler",
|
|
104
|
+
// Validation
|
|
105
|
+
"validation.failed": "האימות נכשל",
|
|
106
|
+
"validation.required": "{field} הוא שדה חובה",
|
|
107
|
+
"validation.typeMismatch": "{field} חייב להיות מסוג {type}",
|
|
108
|
+
"validation.minValue": "{field} חייב להיות לפחות {min}",
|
|
109
|
+
"validation.maxValue": "{field} חייב להיות לכל היותר {max}",
|
|
110
|
+
"validation.minLength": "{field} חייב להכיל לפחות {min} תווים",
|
|
111
|
+
"validation.maxLength": "{field} חייב להכיל לכל היותר {max} תווים",
|
|
112
|
+
"validation.pattern": "{field} לא תואם לתבנית הנדרשת",
|
|
113
|
+
"validation.enum": "{field} חייב להיות אחד מ: {values}",
|
|
114
|
+
"validation.invalidObjectId": "{field} אינו ObjectId תקין",
|
|
115
|
+
"validation.invalidEmail": "{field} אינה כתובת אימייל תקינה",
|
|
116
|
+
"validation.invalidUrl": "{field} אינו URL תקין",
|
|
117
|
+
"validation.invalidDate": "{field} אינו תאריך תקין",
|
|
118
|
+
"validation.customFailed": "{field} נכשל באימות מותאם אישית",
|
|
119
|
+
// Errors
|
|
120
|
+
"errors.badRequest": "בקשה שגויה",
|
|
121
|
+
"errors.unauthorized": "לא מורשה",
|
|
122
|
+
"errors.forbidden": "גישה נדחתה",
|
|
123
|
+
"errors.notFound": "לא נמצא",
|
|
124
|
+
"errors.conflict": "התנגשות",
|
|
125
|
+
"errors.tooManyRequests": "יותר מדי בקשות",
|
|
126
|
+
"errors.internal": "שגיאת שרת פנימית",
|
|
127
|
+
"errors.timeout": "הבקשה פגה",
|
|
128
|
+
"errors.default": "אירעה שגיאה",
|
|
129
|
+
// Config
|
|
130
|
+
"config.notFound": "קובץ הגדרות לא נמצא, משתמש בברירת מחדל",
|
|
131
|
+
"config.loaded": "הגדרות נטענו מ-{path}",
|
|
132
|
+
"config.loadFailed": "נכשל בטעינת הגדרות",
|
|
133
|
+
// Docker
|
|
134
|
+
"docker.containerStarted": "קונטיינר הופעל: {name}",
|
|
135
|
+
"docker.containerStopped": "קונטיינר נעצר: {name}",
|
|
136
|
+
"docker.containerRestarted": "קונטיינר הופעל מחדש: {name}",
|
|
137
|
+
"docker.containerRemoved": "קונטיינר הוסר: {name}",
|
|
138
|
+
"docker.imageBuilt": "תמונה נבנתה: {name}:{tag}",
|
|
139
|
+
"docker.imagePushed": "תמונה הועלתה: {name}",
|
|
140
|
+
"docker.imagePulled": "תמונה הורדה: {name}:{tag}",
|
|
141
|
+
"docker.composeUp": "Docker Compose הופעל בהצלחה",
|
|
142
|
+
"docker.composeDown": "Docker Compose נעצר בהצלחה",
|
|
143
|
+
"docker.commandFailed": "פקודת Docker נכשלה: {command}",
|
|
144
|
+
// Changelog
|
|
145
|
+
"changelog.loaded": "יומן שינויים נטען עם {count} רשומות",
|
|
146
|
+
"changelog.saved": "יומן שינויים נשמר ב-{path}",
|
|
147
|
+
"changelog.released": "שוחררה גרסה {version}",
|
|
148
|
+
"changelog.notFound": "קובץ יומן שינויים לא נמצא, מתחיל מחדש",
|
|
149
|
+
// Portal
|
|
150
|
+
"portal.generated": "פורטל נוצר ב-{path}",
|
|
151
|
+
"portal.generating": "מייצר פורטל תיעוד...",
|
|
152
|
+
// Logger
|
|
153
|
+
"logger.levelChanged": "רמת הלוג שונתה ל-{level}",
|
|
154
|
+
// HTTP Logger
|
|
155
|
+
"http.request": "{method} {url} {status} {duration}ms",
|
|
156
|
+
"http.requestStart": "בקשה נכנסת: {method} {url}",
|
|
157
|
+
"http.requestEnd": "בקשה הושלמה: {method} {url} - {status} תוך {duration}ms",
|
|
158
|
+
// CLI
|
|
159
|
+
"cli.init.success": "פרויקט Harbor אותחל בהצלחה!",
|
|
160
|
+
"cli.init.configExists": "harbor.config.json כבר קיים",
|
|
161
|
+
"cli.init.created": "נוצר {file}",
|
|
162
|
+
"cli.docs.generating": "מייצר תיעוד API...",
|
|
163
|
+
"cli.docs.success": "התיעוד נוצר בהצלחה",
|
|
164
|
+
"cli.version": "Harbor גרסה {version}",
|
|
165
|
+
"cli.unknownCommand": "פקודה לא מוכרת: {command}",
|
|
166
|
+
// Database
|
|
167
|
+
"database.connected": "מחובר ל-MongoDB ב-{uri}",
|
|
168
|
+
"database.disconnected": "נותק מ-MongoDB",
|
|
169
|
+
"database.connecting": "מתחבר ל-MongoDB...",
|
|
170
|
+
"database.connectionFailed": "החיבור ל-MongoDB נכשל: {error}",
|
|
171
|
+
"database.notConnected": "לא מחובר למסד נתונים. קרא ל-harbor.connect() קודם.",
|
|
172
|
+
"database.modelCreated": "מודל נוצר: {name}",
|
|
173
|
+
"database.documentSaved": "מסמך נשמר: {id}",
|
|
174
|
+
"database.documentDeleted": "מסמך נמחק: {id}",
|
|
175
|
+
"database.validationFailed": "האימות נכשל: {errors}",
|
|
176
|
+
"database.queryExecuted": "שאילתה בוצעה: {operation} על {collection}",
|
|
177
|
+
"database.indexCreated": "אינדקס נוצר: {name}",
|
|
178
|
+
"database.transactionStarted": "טרנזקציה התחילה",
|
|
179
|
+
"database.transactionCommitted": "טרנזקציה אושרה",
|
|
180
|
+
"database.transactionAborted": "טרנזקציה בוטלה"
|
|
181
|
+
}, d = {
|
|
182
|
+
en: y,
|
|
183
|
+
he: w
|
|
184
|
+
};
|
|
185
|
+
let m = "en";
|
|
186
|
+
function A(r) {
|
|
187
|
+
if (!d[r]) {
|
|
188
|
+
console.warn(`Locale "${r}" not found, falling back to "en"`), m = "en";
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
m = r;
|
|
192
|
+
}
|
|
193
|
+
function H() {
|
|
194
|
+
return m;
|
|
195
|
+
}
|
|
196
|
+
function j() {
|
|
197
|
+
return Object.keys(d);
|
|
198
|
+
}
|
|
199
|
+
function f(r, t) {
|
|
200
|
+
let n = (d[m] ?? d.en)[r] ?? d.en[r] ?? r;
|
|
201
|
+
if (t)
|
|
202
|
+
for (const [i, s] of Object.entries(t))
|
|
203
|
+
n = n.replace(new RegExp(`{${i}}`, "g"), String(s ?? ""));
|
|
204
|
+
return n;
|
|
205
|
+
}
|
|
206
|
+
function M(r, t) {
|
|
207
|
+
d[r] || (d[r] = {}), Object.assign(d[r], t);
|
|
208
|
+
}
|
|
209
|
+
function $(r, t) {
|
|
210
|
+
d[r] = t;
|
|
211
|
+
}
|
|
212
|
+
class p {
|
|
213
|
+
_definition;
|
|
214
|
+
_options;
|
|
215
|
+
_paths = /* @__PURE__ */ new Map();
|
|
216
|
+
_virtuals = /* @__PURE__ */ new Map();
|
|
217
|
+
_methods = /* @__PURE__ */ new Map();
|
|
218
|
+
_statics = /* @__PURE__ */ new Map();
|
|
219
|
+
_preHooks = /* @__PURE__ */ new Map();
|
|
220
|
+
_postHooks = /* @__PURE__ */ new Map();
|
|
221
|
+
_indexes = [];
|
|
222
|
+
_plugins = [];
|
|
223
|
+
// Public accessors for methods and statics
|
|
224
|
+
methods = {};
|
|
225
|
+
statics = {};
|
|
226
|
+
virtuals = {};
|
|
227
|
+
constructor(t, e) {
|
|
228
|
+
if (this._definition = t, this._options = {
|
|
229
|
+
timestamps: !1,
|
|
230
|
+
strict: !0,
|
|
231
|
+
strictQuery: !1,
|
|
232
|
+
_id: !0,
|
|
233
|
+
id: !0,
|
|
234
|
+
versionKey: "__v",
|
|
235
|
+
autoIndex: !0,
|
|
236
|
+
autoCreate: !0,
|
|
237
|
+
minimize: !0,
|
|
238
|
+
...e
|
|
239
|
+
}, this._parseDefinition(t), this._options._id && this._paths.set("_id", { type: "ObjectId", required: !1 }), this._options.timestamps) {
|
|
240
|
+
const n = typeof this._options.timestamps == "object" ? this._options.timestamps.createdAt === !1 ? null : this._options.timestamps.createdAt || "createdAt" : "createdAt", i = typeof this._options.timestamps == "object" ? this._options.timestamps.updatedAt === !1 ? null : this._options.timestamps.updatedAt || "updatedAt" : "updatedAt";
|
|
241
|
+
n && this._paths.set(n, { type: "Date", required: !1 }), i && this._paths.set(i, { type: "Date", required: !1 });
|
|
242
|
+
}
|
|
243
|
+
if (this._options.versionKey) {
|
|
244
|
+
const n = typeof this._options.versionKey == "string" ? this._options.versionKey : "__v";
|
|
245
|
+
this._paths.set(n, { type: "Number", default: 0 });
|
|
246
|
+
}
|
|
247
|
+
this.methods = new Proxy({}, {
|
|
248
|
+
set: (n, i, s) => (this._methods.set(i, s), !0),
|
|
249
|
+
get: (n, i) => this._methods.get(i)
|
|
250
|
+
}), this.statics = new Proxy({}, {
|
|
251
|
+
set: (n, i, s) => (this._statics.set(i, s), !0),
|
|
252
|
+
get: (n, i) => this._statics.get(i)
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
_parseDefinition(t, e = "") {
|
|
256
|
+
for (const [n, i] of Object.entries(t)) {
|
|
257
|
+
const s = e ? `${e}.${n}` : n;
|
|
258
|
+
if (typeof i == "string")
|
|
259
|
+
this._paths.set(s, { type: i });
|
|
260
|
+
else if (typeof i == "object" && i !== null) {
|
|
261
|
+
const o = i;
|
|
262
|
+
"type" in o ? typeof o.type == "string" ? this._paths.set(s, o) : Array.isArray(o.type) ? this._paths.set(s, { ...o, type: "Array" }) : typeof o.type == "object" && (this._paths.set(s, { type: "Object" }), this._parseDefinition(o.type, s)) : (this._paths.set(s, { type: "Object" }), this._parseDefinition(i, s));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Add additional fields to schema
|
|
267
|
+
add(t, e) {
|
|
268
|
+
return this._parseDefinition(t, e), this;
|
|
269
|
+
}
|
|
270
|
+
// Get path definition
|
|
271
|
+
path(t) {
|
|
272
|
+
return this._paths.get(t);
|
|
273
|
+
}
|
|
274
|
+
// Get all paths
|
|
275
|
+
paths() {
|
|
276
|
+
return this._paths;
|
|
277
|
+
}
|
|
278
|
+
// Define virtual field
|
|
279
|
+
virtual(t) {
|
|
280
|
+
return new b(this, t);
|
|
281
|
+
}
|
|
282
|
+
// Define instance method
|
|
283
|
+
method(t, e) {
|
|
284
|
+
return this._methods.set(t, e), this;
|
|
285
|
+
}
|
|
286
|
+
// Define static method
|
|
287
|
+
static(t, e) {
|
|
288
|
+
return this._statics.set(t, e), this;
|
|
289
|
+
}
|
|
290
|
+
// Pre hook
|
|
291
|
+
pre(t, e) {
|
|
292
|
+
const n = Array.isArray(t) ? t : [t];
|
|
293
|
+
for (const i of n) {
|
|
294
|
+
const s = this._preHooks.get(i) || [];
|
|
295
|
+
s.push(e), this._preHooks.set(i, s);
|
|
296
|
+
}
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
// Post hook
|
|
300
|
+
post(t, e) {
|
|
301
|
+
const n = Array.isArray(t) ? t : [t];
|
|
302
|
+
for (const i of n) {
|
|
303
|
+
const s = this._postHooks.get(i) || [];
|
|
304
|
+
s.push(e), this._postHooks.set(i, s);
|
|
305
|
+
}
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
// Define index
|
|
309
|
+
index(t, e) {
|
|
310
|
+
return this._indexes.push({ fields: t, options: e }), this;
|
|
311
|
+
}
|
|
312
|
+
// Plugin support
|
|
313
|
+
plugin(t, e) {
|
|
314
|
+
return this._plugins.push({ fn: t, options: e }), t(this, e), this;
|
|
315
|
+
}
|
|
316
|
+
// Load class methods as schema methods
|
|
317
|
+
loadClass(t) {
|
|
318
|
+
const e = t.prototype;
|
|
319
|
+
for (const n of Object.getOwnPropertyNames(e)) {
|
|
320
|
+
if (n === "constructor") continue;
|
|
321
|
+
const i = Object.getOwnPropertyDescriptor(e, n);
|
|
322
|
+
if (i?.get)
|
|
323
|
+
this._virtuals.set(n, { get: i.get });
|
|
324
|
+
else if (i?.set) {
|
|
325
|
+
const s = this._virtuals.get(n) || {};
|
|
326
|
+
this._virtuals.set(n, { ...s, set: i.set });
|
|
327
|
+
} else typeof i?.value == "function" && this._methods.set(n, i.value);
|
|
328
|
+
}
|
|
329
|
+
for (const n of Object.getOwnPropertyNames(t)) {
|
|
330
|
+
if (["length", "prototype", "name"].includes(n)) continue;
|
|
331
|
+
const i = t[n];
|
|
332
|
+
typeof i == "function" && this._statics.set(n, i);
|
|
333
|
+
}
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
// Clone schema
|
|
337
|
+
clone() {
|
|
338
|
+
const t = new p({}, this._options);
|
|
339
|
+
return t._paths = new Map(this._paths), t._virtuals = new Map(this._virtuals), t._methods = new Map(this._methods), t._statics = new Map(this._statics), t._preHooks = new Map(this._preHooks), t._postHooks = new Map(this._postHooks), t._indexes = [...this._indexes], t;
|
|
340
|
+
}
|
|
341
|
+
// Getters
|
|
342
|
+
get options() {
|
|
343
|
+
return this._options;
|
|
344
|
+
}
|
|
345
|
+
get definition() {
|
|
346
|
+
return this._definition;
|
|
347
|
+
}
|
|
348
|
+
getMethods() {
|
|
349
|
+
return this._methods;
|
|
350
|
+
}
|
|
351
|
+
getStatics() {
|
|
352
|
+
return this._statics;
|
|
353
|
+
}
|
|
354
|
+
getVirtuals() {
|
|
355
|
+
return this._virtuals;
|
|
356
|
+
}
|
|
357
|
+
getPreHooks() {
|
|
358
|
+
return this._preHooks;
|
|
359
|
+
}
|
|
360
|
+
getPostHooks() {
|
|
361
|
+
return this._postHooks;
|
|
362
|
+
}
|
|
363
|
+
getIndexes() {
|
|
364
|
+
return this._indexes;
|
|
365
|
+
}
|
|
366
|
+
// Validate document against schema
|
|
367
|
+
async validate(t) {
|
|
368
|
+
const e = [];
|
|
369
|
+
for (const [n, i] of this._paths) {
|
|
370
|
+
const s = this._getNestedValue(t, n), o = await this._validateField(n, s, i);
|
|
371
|
+
e.push(...o);
|
|
372
|
+
}
|
|
373
|
+
return e.length > 0 ? { valid: !1, errors: e } : { valid: !0 };
|
|
374
|
+
}
|
|
375
|
+
_getNestedValue(t, e) {
|
|
376
|
+
return e.split(".").reduce((n, i) => n?.[i], t);
|
|
377
|
+
}
|
|
378
|
+
async _validateField(t, e, n) {
|
|
379
|
+
const i = [];
|
|
380
|
+
return n.required && e == null ? (i.push({ path: t, message: `${t} is required` }), i) : e == null ? i : this._validateType(e, n.type) ? (n.type === "String" && typeof e == "string" && (n.minLength && e.length < n.minLength && i.push({ path: t, message: `${t} must be at least ${n.minLength} characters` }), n.maxLength && e.length > n.maxLength && i.push({ path: t, message: `${t} must be at most ${n.maxLength} characters` }), n.match && !n.match.test(e) && i.push({ path: t, message: `${t} does not match required pattern` }), n.enum && !n.enum.includes(e) && i.push({ path: t, message: `${t} must be one of: ${n.enum.join(", ")}` })), n.type === "Number" && typeof e == "number" && (n.min !== void 0 && e < n.min && i.push({ path: t, message: `${t} must be at least ${n.min}` }), n.max !== void 0 && e > n.max && i.push({ path: t, message: `${t} must be at most ${n.max}` })), n.validate && (await n.validate.validator(e) || i.push({ path: t, message: n.validate.message || `${t} failed validation` })), i) : (i.push({ path: t, message: `${t} must be of type ${n.type}` }), i);
|
|
381
|
+
}
|
|
382
|
+
_validateType(t, e) {
|
|
383
|
+
switch (e) {
|
|
384
|
+
case "String":
|
|
385
|
+
return typeof t == "string";
|
|
386
|
+
case "Number":
|
|
387
|
+
return typeof t == "number" && !isNaN(t);
|
|
388
|
+
case "Boolean":
|
|
389
|
+
return typeof t == "boolean";
|
|
390
|
+
case "Date":
|
|
391
|
+
return t instanceof Date || typeof t == "string" && !isNaN(Date.parse(t));
|
|
392
|
+
case "ObjectId":
|
|
393
|
+
return typeof t == "string" && /^[0-9a-fA-F]{24}$/.test(t);
|
|
394
|
+
case "Array":
|
|
395
|
+
return Array.isArray(t);
|
|
396
|
+
case "Object":
|
|
397
|
+
case "Mixed":
|
|
398
|
+
return typeof t == "object" && t !== null;
|
|
399
|
+
case "Buffer":
|
|
400
|
+
return Buffer.isBuffer(t);
|
|
401
|
+
default:
|
|
402
|
+
return !0;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// Apply transformations (lowercase, uppercase, trim)
|
|
406
|
+
transformValue(t, e) {
|
|
407
|
+
const n = this._paths.get(t);
|
|
408
|
+
if (!n || typeof e != "string") return e;
|
|
409
|
+
let i = e;
|
|
410
|
+
return n.lowercase && (i = i.toLowerCase()), n.uppercase && (i = i.toUpperCase()), n.trim && (i = i.trim()), i;
|
|
411
|
+
}
|
|
412
|
+
// Get default value for a field
|
|
413
|
+
getDefault(t) {
|
|
414
|
+
const e = this._paths.get(t);
|
|
415
|
+
if (!(!e || e.default === void 0))
|
|
416
|
+
return typeof e.default == "function" ? e.default() : e.default;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
class b {
|
|
420
|
+
schema;
|
|
421
|
+
name;
|
|
422
|
+
constructor(t, e) {
|
|
423
|
+
this.schema = t, this.name = e;
|
|
424
|
+
}
|
|
425
|
+
get(t) {
|
|
426
|
+
const e = this.schema.getVirtuals(), n = e.get(this.name) || {};
|
|
427
|
+
return e.set(this.name, { ...n, get: t }), this;
|
|
428
|
+
}
|
|
429
|
+
set(t) {
|
|
430
|
+
const e = this.schema.getVirtuals(), n = e.get(this.name) || {};
|
|
431
|
+
return e.set(this.name, { ...n, set: t }), this;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
class v extends g {
|
|
435
|
+
_state = {
|
|
436
|
+
connected: !1,
|
|
437
|
+
readyState: 0
|
|
438
|
+
};
|
|
439
|
+
// @ts-ignore - Reserved for future use
|
|
440
|
+
_uri = "";
|
|
441
|
+
_options = {};
|
|
442
|
+
_mongoClient = null;
|
|
443
|
+
_db = null;
|
|
444
|
+
_models = /* @__PURE__ */ new Map();
|
|
445
|
+
get readyState() {
|
|
446
|
+
return this._state.readyState;
|
|
447
|
+
}
|
|
448
|
+
get host() {
|
|
449
|
+
return this._state.host;
|
|
450
|
+
}
|
|
451
|
+
get port() {
|
|
452
|
+
return this._state.port;
|
|
453
|
+
}
|
|
454
|
+
get name() {
|
|
455
|
+
return this._state.name;
|
|
456
|
+
}
|
|
457
|
+
get db() {
|
|
458
|
+
return this._db;
|
|
459
|
+
}
|
|
460
|
+
get client() {
|
|
461
|
+
return this._mongoClient;
|
|
462
|
+
}
|
|
463
|
+
get models() {
|
|
464
|
+
return this._models;
|
|
465
|
+
}
|
|
466
|
+
async connect(t, e) {
|
|
467
|
+
if (this._state.readyState === 1)
|
|
468
|
+
return console.warn("[Harbor] Already connected to MongoDB"), this;
|
|
469
|
+
this._uri = t, this._options = {
|
|
470
|
+
maxPoolSize: 10,
|
|
471
|
+
minPoolSize: 1,
|
|
472
|
+
serverSelectionTimeoutMS: 3e4,
|
|
473
|
+
socketTimeoutMS: 45e3,
|
|
474
|
+
retryWrites: !0,
|
|
475
|
+
w: "majority",
|
|
476
|
+
...e
|
|
477
|
+
}, this._state.readyState = 2, this.emit("connecting");
|
|
478
|
+
try {
|
|
479
|
+
const { MongoClient: n } = await import("mongodb");
|
|
480
|
+
this._mongoClient = new n(t, this._options), await this._mongoClient.connect();
|
|
481
|
+
const i = new URL(t), s = i.pathname.slice(1) || "test";
|
|
482
|
+
return this._db = this._mongoClient.db(s), this._state = {
|
|
483
|
+
connected: !0,
|
|
484
|
+
readyState: 1,
|
|
485
|
+
host: i.hostname,
|
|
486
|
+
port: parseInt(i.port) || 27017,
|
|
487
|
+
name: s
|
|
488
|
+
}, this.emit("connected"), this.emit("open"), console.log(`[Harbor] ${f("database.connected", { uri: `${i.hostname}:${i.port}/${s}` })}`), this;
|
|
489
|
+
} catch (n) {
|
|
490
|
+
throw this._state.readyState = 0, this.emit("error", n), n;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async disconnect() {
|
|
494
|
+
if (this._state.readyState === 0) {
|
|
495
|
+
console.warn("[Harbor] Already disconnected from MongoDB");
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
this._state.readyState = 3, this.emit("disconnecting");
|
|
499
|
+
try {
|
|
500
|
+
this._mongoClient && await this._mongoClient.close(), this._state = {
|
|
501
|
+
connected: !1,
|
|
502
|
+
readyState: 0
|
|
503
|
+
}, this._mongoClient = null, this._db = null, this.emit("disconnected"), this.emit("close"), console.log(`[Harbor] ${f("database.disconnected")}`);
|
|
504
|
+
} catch (t) {
|
|
505
|
+
throw this.emit("error", t), t;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async close() {
|
|
509
|
+
return this.disconnect();
|
|
510
|
+
}
|
|
511
|
+
async ping() {
|
|
512
|
+
if (!this._db)
|
|
513
|
+
return !1;
|
|
514
|
+
try {
|
|
515
|
+
return await this._db.command({ ping: 1 }), !0;
|
|
516
|
+
} catch {
|
|
517
|
+
return !1;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
collection(t) {
|
|
521
|
+
if (!this._db)
|
|
522
|
+
throw new Error("[Harbor] Not connected to database");
|
|
523
|
+
return this._db.collection(t);
|
|
524
|
+
}
|
|
525
|
+
async createCollection(t, e) {
|
|
526
|
+
if (!this._db)
|
|
527
|
+
throw new Error("[Harbor] Not connected to database");
|
|
528
|
+
return this._db.createCollection(t, e);
|
|
529
|
+
}
|
|
530
|
+
async dropCollection(t) {
|
|
531
|
+
if (!this._db)
|
|
532
|
+
throw new Error("[Harbor] Not connected to database");
|
|
533
|
+
return this._db.dropCollection(t);
|
|
534
|
+
}
|
|
535
|
+
async listCollections() {
|
|
536
|
+
if (!this._db)
|
|
537
|
+
throw new Error("[Harbor] Not connected to database");
|
|
538
|
+
return (await this._db.listCollections().toArray()).map((e) => e.name);
|
|
539
|
+
}
|
|
540
|
+
async dropDatabase() {
|
|
541
|
+
if (!this._db)
|
|
542
|
+
throw new Error("[Harbor] Not connected to database");
|
|
543
|
+
return this._db.dropDatabase();
|
|
544
|
+
}
|
|
545
|
+
// Transaction support
|
|
546
|
+
async startSession() {
|
|
547
|
+
if (!this._mongoClient)
|
|
548
|
+
throw new Error("[Harbor] Not connected to database");
|
|
549
|
+
return this._mongoClient.startSession();
|
|
550
|
+
}
|
|
551
|
+
async withTransaction(t, e) {
|
|
552
|
+
const n = await this.startSession();
|
|
553
|
+
try {
|
|
554
|
+
let i;
|
|
555
|
+
return await n.withTransaction(async () => {
|
|
556
|
+
i = await t(n);
|
|
557
|
+
}, e), i;
|
|
558
|
+
} finally {
|
|
559
|
+
await n.endSession();
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
// Event handlers with proper typing
|
|
563
|
+
on(t, e) {
|
|
564
|
+
return super.on(t, e);
|
|
565
|
+
}
|
|
566
|
+
once(t, e) {
|
|
567
|
+
return super.once(t, e);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const h = new v();
|
|
571
|
+
async function C(r, t) {
|
|
572
|
+
return h.connect(r, t);
|
|
573
|
+
}
|
|
574
|
+
async function k() {
|
|
575
|
+
return h.disconnect();
|
|
576
|
+
}
|
|
577
|
+
class u {
|
|
578
|
+
_model;
|
|
579
|
+
_operation;
|
|
580
|
+
_filter = {};
|
|
581
|
+
_projection = null;
|
|
582
|
+
_options = {};
|
|
583
|
+
_update = null;
|
|
584
|
+
_currentPath = null;
|
|
585
|
+
constructor(t, e, n, i) {
|
|
586
|
+
this._model = t, this._operation = e, this._filter = n || {}, this._update = i || null;
|
|
587
|
+
}
|
|
588
|
+
select(t) {
|
|
589
|
+
if (typeof t == "string") {
|
|
590
|
+
this._projection = {};
|
|
591
|
+
for (const e of t.split(" "))
|
|
592
|
+
e.startsWith("-") ? this._projection[e.slice(1)] = 0 : e && (this._projection[e] = 1);
|
|
593
|
+
} else
|
|
594
|
+
this._projection = t;
|
|
595
|
+
return this;
|
|
596
|
+
}
|
|
597
|
+
sort(t) {
|
|
598
|
+
if (typeof t == "string") {
|
|
599
|
+
const e = {};
|
|
600
|
+
for (const n of t.split(" "))
|
|
601
|
+
n.startsWith("-") ? e[n.slice(1)] = -1 : n && (e[n] = 1);
|
|
602
|
+
this._options.sort = e;
|
|
603
|
+
} else
|
|
604
|
+
this._options.sort = t;
|
|
605
|
+
return this;
|
|
606
|
+
}
|
|
607
|
+
limit(t) {
|
|
608
|
+
return this._options.limit = t, this;
|
|
609
|
+
}
|
|
610
|
+
skip(t) {
|
|
611
|
+
return this._options.skip = t, this;
|
|
612
|
+
}
|
|
613
|
+
lean() {
|
|
614
|
+
return this._options.lean = !0, this;
|
|
615
|
+
}
|
|
616
|
+
populate(t) {
|
|
617
|
+
return this._options.populate = t, this;
|
|
618
|
+
}
|
|
619
|
+
where(t, e) {
|
|
620
|
+
return this._currentPath = t, e !== void 0 && (this._filter[t] = e), this;
|
|
621
|
+
}
|
|
622
|
+
equals(t) {
|
|
623
|
+
return this._currentPath && (this._filter[this._currentPath] = t), this;
|
|
624
|
+
}
|
|
625
|
+
gt(t) {
|
|
626
|
+
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $gt: t }), this;
|
|
627
|
+
}
|
|
628
|
+
gte(t) {
|
|
629
|
+
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $gte: t }), this;
|
|
630
|
+
}
|
|
631
|
+
lt(t) {
|
|
632
|
+
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $lt: t }), this;
|
|
633
|
+
}
|
|
634
|
+
lte(t) {
|
|
635
|
+
return this._currentPath && (this._filter[this._currentPath] = { ...this._filter[this._currentPath], $lte: t }), this;
|
|
636
|
+
}
|
|
637
|
+
in(t) {
|
|
638
|
+
return this._currentPath && (this._filter[this._currentPath] = { $in: t }), this;
|
|
639
|
+
}
|
|
640
|
+
nin(t) {
|
|
641
|
+
return this._currentPath && (this._filter[this._currentPath] = { $nin: t }), this;
|
|
642
|
+
}
|
|
643
|
+
ne(t) {
|
|
644
|
+
return this._currentPath && (this._filter[this._currentPath] = { $ne: t }), this;
|
|
645
|
+
}
|
|
646
|
+
regex(t) {
|
|
647
|
+
return this._currentPath && (this._filter[this._currentPath] = { $regex: t }), this;
|
|
648
|
+
}
|
|
649
|
+
exists(t = !0) {
|
|
650
|
+
return this._currentPath && (this._filter[this._currentPath] = { $exists: t }), this;
|
|
651
|
+
}
|
|
652
|
+
or(t) {
|
|
653
|
+
return this._filter.$or = t, this;
|
|
654
|
+
}
|
|
655
|
+
and(t) {
|
|
656
|
+
return this._filter.$and = t, this;
|
|
657
|
+
}
|
|
658
|
+
nor(t) {
|
|
659
|
+
return this._filter.$nor = t, this;
|
|
660
|
+
}
|
|
661
|
+
async exec() {
|
|
662
|
+
const t = this._model.getCollection();
|
|
663
|
+
switch (this._operation) {
|
|
664
|
+
case "find": {
|
|
665
|
+
let e = t.find(this._filter, { projection: this._projection });
|
|
666
|
+
this._options.sort && (e = e.sort(this._options.sort)), this._options.skip && (e = e.skip(this._options.skip)), this._options.limit && (e = e.limit(this._options.limit));
|
|
667
|
+
const n = await e.toArray();
|
|
668
|
+
return this._options.lean ? n : n.map((i) => this._model.hydrate(i));
|
|
669
|
+
}
|
|
670
|
+
case "findOne": {
|
|
671
|
+
const e = await t.findOne(this._filter, { projection: this._projection });
|
|
672
|
+
return e ? this._options.lean ? e : this._model.hydrate(e) : null;
|
|
673
|
+
}
|
|
674
|
+
case "findOneAndUpdate": {
|
|
675
|
+
const e = await t.findOneAndUpdate(
|
|
676
|
+
this._filter,
|
|
677
|
+
this._update,
|
|
678
|
+
{
|
|
679
|
+
returnDocument: this._options.new ? "after" : "before",
|
|
680
|
+
upsert: this._options.upsert,
|
|
681
|
+
projection: this._projection
|
|
682
|
+
}
|
|
683
|
+
);
|
|
684
|
+
return e ? this._options.lean ? e : this._model.hydrate(e) : null;
|
|
685
|
+
}
|
|
686
|
+
case "findOneAndDelete": {
|
|
687
|
+
const e = await t.findOneAndDelete(this._filter, {
|
|
688
|
+
projection: this._projection
|
|
689
|
+
});
|
|
690
|
+
return e ? this._options.lean ? e : this._model.hydrate(e) : null;
|
|
691
|
+
}
|
|
692
|
+
default:
|
|
693
|
+
throw new Error(`Unknown operation: ${this._operation}`);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
then(t, e) {
|
|
697
|
+
return this.exec().then(t, e);
|
|
698
|
+
}
|
|
699
|
+
catch(t) {
|
|
700
|
+
return this.exec().catch(t);
|
|
701
|
+
}
|
|
702
|
+
finally(t) {
|
|
703
|
+
return this.exec().finally(t);
|
|
704
|
+
}
|
|
705
|
+
[Symbol.toStringTag] = "Query";
|
|
706
|
+
}
|
|
707
|
+
class _ {
|
|
708
|
+
_id;
|
|
709
|
+
__v;
|
|
710
|
+
isNew = !0;
|
|
711
|
+
_model;
|
|
712
|
+
// @ts-ignore - Reserved for tracking changes
|
|
713
|
+
_original = {};
|
|
714
|
+
_modified = /* @__PURE__ */ new Set();
|
|
715
|
+
constructor(t, e) {
|
|
716
|
+
if (this._model = t, this._id = e?._id?.toString() || new c().toString(), e) {
|
|
717
|
+
for (const [i, s] of Object.entries(e))
|
|
718
|
+
i === "_id" ? this._id = s?.toString() || this._id : this[i] = s;
|
|
719
|
+
this._original = { ...e }, this.isNew = !1;
|
|
720
|
+
}
|
|
721
|
+
const n = t.schema;
|
|
722
|
+
for (const [i] of n.paths())
|
|
723
|
+
if (this[i] === void 0) {
|
|
724
|
+
const s = n.getDefault(i);
|
|
725
|
+
s !== void 0 && (this[i] = s);
|
|
726
|
+
}
|
|
727
|
+
for (const [i, s] of n.getVirtuals())
|
|
728
|
+
Object.defineProperty(this, i, {
|
|
729
|
+
get: s.get,
|
|
730
|
+
set: s.set,
|
|
731
|
+
enumerable: !0
|
|
732
|
+
});
|
|
733
|
+
for (const [i, s] of n.getMethods())
|
|
734
|
+
this[i] = s.bind(this);
|
|
735
|
+
}
|
|
736
|
+
get id() {
|
|
737
|
+
return this._id;
|
|
738
|
+
}
|
|
739
|
+
isModified(t) {
|
|
740
|
+
return t ? this._modified.has(t) : this._modified.size > 0;
|
|
741
|
+
}
|
|
742
|
+
markModified(t) {
|
|
743
|
+
this._modified.add(t);
|
|
744
|
+
}
|
|
745
|
+
async save() {
|
|
746
|
+
const t = this._model.schema;
|
|
747
|
+
await this._model.runPreHooks("save", this);
|
|
748
|
+
const e = await t.validate(this.toObject());
|
|
749
|
+
if (!e.valid) {
|
|
750
|
+
const o = new Error(`Validation failed: ${e.errors?.map((a) => a.message).join(", ")}`);
|
|
751
|
+
throw o.errors = e.errors, o;
|
|
752
|
+
}
|
|
753
|
+
const n = /* @__PURE__ */ new Date();
|
|
754
|
+
if (t.options.timestamps) {
|
|
755
|
+
const o = typeof t.options.timestamps == "object" && t.options.timestamps.createdAt || "createdAt", a = typeof t.options.timestamps == "object" && t.options.timestamps.updatedAt || "updatedAt";
|
|
756
|
+
this.isNew && o && (this[o] = n), this[a] = n;
|
|
757
|
+
}
|
|
758
|
+
const i = this._model.getCollection(), s = this.toObject();
|
|
759
|
+
if (this.isNew)
|
|
760
|
+
await i.insertOne({ _id: new c(this._id), ...s }), this.isNew = !1;
|
|
761
|
+
else {
|
|
762
|
+
if (t.options.versionKey) {
|
|
763
|
+
const o = typeof t.options.versionKey == "string" ? t.options.versionKey : "__v";
|
|
764
|
+
this[o] = (this[o] || 0) + 1;
|
|
765
|
+
}
|
|
766
|
+
await i.replaceOne({ _id: new c(this._id) }, s);
|
|
767
|
+
}
|
|
768
|
+
return this._original = { ...s }, this._modified.clear(), await this._model.runPostHooks("save", this), this;
|
|
769
|
+
}
|
|
770
|
+
async remove() {
|
|
771
|
+
return await this._model.runPreHooks("remove", this), await this._model.getCollection().deleteOne({ _id: new c(this._id) }), await this._model.runPostHooks("remove", this), this;
|
|
772
|
+
}
|
|
773
|
+
async deleteOne() {
|
|
774
|
+
await this._model.runPreHooks("deleteOne", this);
|
|
775
|
+
const e = await this._model.getCollection().deleteOne({ _id: new c(this._id) });
|
|
776
|
+
return await this._model.runPostHooks("deleteOne", this), {
|
|
777
|
+
acknowledged: e.acknowledged,
|
|
778
|
+
deletedCount: e.deletedCount
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
async updateOne(t) {
|
|
782
|
+
await this._model.runPreHooks("updateOne", this);
|
|
783
|
+
const n = await this._model.getCollection().updateOne({ _id: new c(this._id) }, t);
|
|
784
|
+
return await this._model.runPostHooks("updateOne", this), {
|
|
785
|
+
acknowledged: n.acknowledged,
|
|
786
|
+
modifiedCount: n.modifiedCount,
|
|
787
|
+
matchedCount: n.matchedCount
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
async populate(t) {
|
|
791
|
+
return this;
|
|
792
|
+
}
|
|
793
|
+
toObject() {
|
|
794
|
+
const t = { _id: this._id }, e = this._model.schema;
|
|
795
|
+
for (const [n] of e.paths())
|
|
796
|
+
n !== "_id" && this[n] !== void 0 && (t[n] = this[n]);
|
|
797
|
+
return t;
|
|
798
|
+
}
|
|
799
|
+
toJSON() {
|
|
800
|
+
return this.toObject();
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
class l {
|
|
804
|
+
_name;
|
|
805
|
+
_schema;
|
|
806
|
+
_collectionName;
|
|
807
|
+
static models = /* @__PURE__ */ new Map();
|
|
808
|
+
constructor(t, e, n) {
|
|
809
|
+
this._name = t, this._schema = e, this._collectionName = n || t.toLowerCase() + "s";
|
|
810
|
+
for (const [i, s] of e.getStatics())
|
|
811
|
+
this[i] = s.bind(this);
|
|
812
|
+
l.models.set(t, this);
|
|
813
|
+
}
|
|
814
|
+
get modelName() {
|
|
815
|
+
return this._name;
|
|
816
|
+
}
|
|
817
|
+
get schema() {
|
|
818
|
+
return this._schema;
|
|
819
|
+
}
|
|
820
|
+
get collection() {
|
|
821
|
+
return { name: this._collectionName };
|
|
822
|
+
}
|
|
823
|
+
getCollection() {
|
|
824
|
+
if (!h.db)
|
|
825
|
+
throw new Error("[Harbor] Not connected to database. Call harbor.connect() first.");
|
|
826
|
+
return h.db.collection(this._collectionName);
|
|
827
|
+
}
|
|
828
|
+
// Create a new document instance
|
|
829
|
+
new(t) {
|
|
830
|
+
return new _(this, t);
|
|
831
|
+
}
|
|
832
|
+
// Hydrate a plain object into a document
|
|
833
|
+
hydrate(t) {
|
|
834
|
+
const e = new _(this, t);
|
|
835
|
+
return e.isNew = !1, e;
|
|
836
|
+
}
|
|
837
|
+
// Query methods
|
|
838
|
+
find(t, e, n) {
|
|
839
|
+
const i = new u(this, "find", t);
|
|
840
|
+
return e && i.select(e), n?.sort && i.sort(n.sort), n?.limit && i.limit(n.limit), n?.skip && i.skip(n.skip), n?.lean && i.lean(), i;
|
|
841
|
+
}
|
|
842
|
+
findOne(t, e, n) {
|
|
843
|
+
const i = new u(this, "findOne", t);
|
|
844
|
+
return e && i.select(e), n?.lean && i.lean(), i;
|
|
845
|
+
}
|
|
846
|
+
findById(t, e, n) {
|
|
847
|
+
return this.findOne({ _id: new c(t) }, e, n);
|
|
848
|
+
}
|
|
849
|
+
// Create methods
|
|
850
|
+
async create(t) {
|
|
851
|
+
if (Array.isArray(t)) {
|
|
852
|
+
const n = [];
|
|
853
|
+
for (const i of t) {
|
|
854
|
+
const s = this.new(i);
|
|
855
|
+
await s.save(), n.push(s);
|
|
856
|
+
}
|
|
857
|
+
return n;
|
|
858
|
+
}
|
|
859
|
+
const e = this.new(t);
|
|
860
|
+
return await e.save(), e;
|
|
861
|
+
}
|
|
862
|
+
async insertMany(t, e) {
|
|
863
|
+
const n = this.getCollection(), i = t.map((o) => ({ _id: new c(), ...o })), s = await n.insertMany(i, { ordered: e?.ordered ?? !0 });
|
|
864
|
+
return {
|
|
865
|
+
insertedCount: s.insertedCount,
|
|
866
|
+
insertedIds: Object.values(s.insertedIds).map((o) => o.toString())
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
// Update methods
|
|
870
|
+
async updateOne(t, e, n) {
|
|
871
|
+
await this.runPreHooks("updateOne", null);
|
|
872
|
+
const i = this.getCollection(), s = e.$set || e.$unset || e.$inc ? e : { $set: e }, o = await i.updateOne(t, s, { upsert: n?.upsert });
|
|
873
|
+
return await this.runPostHooks("updateOne", null), {
|
|
874
|
+
acknowledged: o.acknowledged,
|
|
875
|
+
modifiedCount: o.modifiedCount,
|
|
876
|
+
matchedCount: o.matchedCount,
|
|
877
|
+
upsertedCount: o.upsertedCount,
|
|
878
|
+
upsertedId: o.upsertedId?.toString()
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
async updateMany(t, e, n) {
|
|
882
|
+
await this.runPreHooks("updateMany", null);
|
|
883
|
+
const i = this.getCollection(), s = e.$set || e.$unset || e.$inc ? e : { $set: e }, o = await i.updateMany(t, s, { upsert: n?.upsert });
|
|
884
|
+
return await this.runPostHooks("updateMany", null), {
|
|
885
|
+
acknowledged: o.acknowledged,
|
|
886
|
+
modifiedCount: o.modifiedCount,
|
|
887
|
+
matchedCount: o.matchedCount
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
findOneAndUpdate(t, e, n) {
|
|
891
|
+
const i = new u(this, "findOneAndUpdate", t, e);
|
|
892
|
+
return n?.new && (i._options.new = !0), n?.upsert && (i._options.upsert = !0), n?.lean && i.lean(), i;
|
|
893
|
+
}
|
|
894
|
+
findByIdAndUpdate(t, e, n) {
|
|
895
|
+
return this.findOneAndUpdate({ _id: new c(t) }, e, n);
|
|
896
|
+
}
|
|
897
|
+
async replaceOne(t, e, n) {
|
|
898
|
+
const s = await this.getCollection().replaceOne(t, e, { upsert: n?.upsert });
|
|
899
|
+
return {
|
|
900
|
+
acknowledged: s.acknowledged,
|
|
901
|
+
modifiedCount: s.modifiedCount,
|
|
902
|
+
matchedCount: s.matchedCount
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
// Delete methods
|
|
906
|
+
async deleteOne(t) {
|
|
907
|
+
await this.runPreHooks("deleteOne", null);
|
|
908
|
+
const n = await this.getCollection().deleteOne(t);
|
|
909
|
+
return await this.runPostHooks("deleteOne", null), {
|
|
910
|
+
acknowledged: n.acknowledged,
|
|
911
|
+
deletedCount: n.deletedCount
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
async deleteMany(t) {
|
|
915
|
+
await this.runPreHooks("deleteMany", null);
|
|
916
|
+
const n = await this.getCollection().deleteMany(t);
|
|
917
|
+
return await this.runPostHooks("deleteMany", null), {
|
|
918
|
+
acknowledged: n.acknowledged,
|
|
919
|
+
deletedCount: n.deletedCount
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
findOneAndDelete(t, e) {
|
|
923
|
+
const n = new u(this, "findOneAndDelete", t);
|
|
924
|
+
return e?.lean && n.lean(), n;
|
|
925
|
+
}
|
|
926
|
+
findByIdAndDelete(t, e) {
|
|
927
|
+
return this.findOneAndDelete({ _id: new c(t) }, e);
|
|
928
|
+
}
|
|
929
|
+
// Count methods
|
|
930
|
+
async countDocuments(t) {
|
|
931
|
+
return this.getCollection().countDocuments(t || {});
|
|
932
|
+
}
|
|
933
|
+
async estimatedDocumentCount() {
|
|
934
|
+
return this.getCollection().estimatedDocumentCount();
|
|
935
|
+
}
|
|
936
|
+
// Aggregate
|
|
937
|
+
async aggregate(t, e) {
|
|
938
|
+
return this.getCollection().aggregate(t, e).toArray();
|
|
939
|
+
}
|
|
940
|
+
// Distinct
|
|
941
|
+
async distinct(t, e) {
|
|
942
|
+
return this.getCollection().distinct(t, e || {});
|
|
943
|
+
}
|
|
944
|
+
// Exists
|
|
945
|
+
async exists(t) {
|
|
946
|
+
const e = await this.findOne(t).select({ _id: 1 }).lean();
|
|
947
|
+
return e ? { _id: e._id.toString() } : null;
|
|
948
|
+
}
|
|
949
|
+
// Bulk operations
|
|
950
|
+
async bulkWrite(t) {
|
|
951
|
+
const n = await this.getCollection().bulkWrite(t);
|
|
952
|
+
return {
|
|
953
|
+
ok: n.ok,
|
|
954
|
+
insertedCount: n.insertedCount,
|
|
955
|
+
matchedCount: n.matchedCount,
|
|
956
|
+
modifiedCount: n.modifiedCount,
|
|
957
|
+
deletedCount: n.deletedCount,
|
|
958
|
+
upsertedCount: n.upsertedCount,
|
|
959
|
+
insertedIds: n.insertedIds || {},
|
|
960
|
+
upsertedIds: n.upsertedIds || {}
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
// Index methods
|
|
964
|
+
async createIndex(t, e) {
|
|
965
|
+
return this.getCollection().createIndex(t, e);
|
|
966
|
+
}
|
|
967
|
+
async createIndexes(t) {
|
|
968
|
+
const e = this.getCollection(), n = t.map((i) => ({ key: i.fields, ...i.options }));
|
|
969
|
+
return e.createIndexes(n);
|
|
970
|
+
}
|
|
971
|
+
async listIndexes() {
|
|
972
|
+
return this.getCollection().listIndexes().toArray();
|
|
973
|
+
}
|
|
974
|
+
async dropIndex(t) {
|
|
975
|
+
await this.getCollection().dropIndex(t);
|
|
976
|
+
}
|
|
977
|
+
// Populate
|
|
978
|
+
async populate(t, e) {
|
|
979
|
+
return t;
|
|
980
|
+
}
|
|
981
|
+
// Watch (change streams)
|
|
982
|
+
watch(t, e) {
|
|
983
|
+
return this.getCollection().watch(t, e);
|
|
984
|
+
}
|
|
985
|
+
// Hook execution
|
|
986
|
+
async runPreHooks(t, e) {
|
|
987
|
+
const n = this._schema.getPreHooks().get(t) || [];
|
|
988
|
+
for (const i of n)
|
|
989
|
+
await new Promise((s, o) => {
|
|
990
|
+
try {
|
|
991
|
+
const a = i.call(e, s);
|
|
992
|
+
a instanceof Promise && a.then(s).catch(o);
|
|
993
|
+
} catch (a) {
|
|
994
|
+
o(a);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
async runPostHooks(t, e) {
|
|
999
|
+
const n = this._schema.getPostHooks().get(t) || [];
|
|
1000
|
+
for (const i of n)
|
|
1001
|
+
await new Promise((s, o) => {
|
|
1002
|
+
try {
|
|
1003
|
+
const a = i.call(e, s);
|
|
1004
|
+
a instanceof Promise && a.then(s).catch(o);
|
|
1005
|
+
} catch (a) {
|
|
1006
|
+
o(a);
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function O(r, t, e) {
|
|
1012
|
+
const n = l.models.get(r);
|
|
1013
|
+
return n || new l(r, t, e);
|
|
1014
|
+
}
|
|
1015
|
+
const P = {
|
|
1016
|
+
ObjectId: c
|
|
1017
|
+
}, I = {
|
|
1018
|
+
// Connection
|
|
1019
|
+
connection: h,
|
|
1020
|
+
connect: C,
|
|
1021
|
+
disconnect: k,
|
|
1022
|
+
// Schema & Model
|
|
1023
|
+
Schema: p,
|
|
1024
|
+
Model: l,
|
|
1025
|
+
model: O,
|
|
1026
|
+
// Types
|
|
1027
|
+
Types: P,
|
|
1028
|
+
// Convenience methods
|
|
1029
|
+
get models() {
|
|
1030
|
+
return Object.fromEntries(l.models);
|
|
1031
|
+
},
|
|
1032
|
+
// Version
|
|
1033
|
+
version: "1.0.0"
|
|
1034
|
+
};
|
|
1035
|
+
export {
|
|
1036
|
+
_ as H,
|
|
1037
|
+
l as M,
|
|
1038
|
+
u as Q,
|
|
1039
|
+
p as S,
|
|
1040
|
+
P as T,
|
|
1041
|
+
C as a,
|
|
1042
|
+
j as b,
|
|
1043
|
+
h as c,
|
|
1044
|
+
k as d,
|
|
1045
|
+
M as e,
|
|
1046
|
+
v as f,
|
|
1047
|
+
H as g,
|
|
1048
|
+
I as h,
|
|
1049
|
+
O as m,
|
|
1050
|
+
$ as r,
|
|
1051
|
+
A as s,
|
|
1052
|
+
f as t
|
|
1053
|
+
};
|
|
1054
|
+
//# sourceMappingURL=index-DIVHd6rO.mjs.map
|