@anteros/core 0.0.9 → 0.0.11
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/database/decorator.ts +17 -13
- package/package.json +1 -1
- package/server/api.ts +5 -0
- package/types/config.d.ts +1 -0
package/database/decorator.ts
CHANGED
|
@@ -34,24 +34,24 @@ export function CheckIfArrayOfIds(action: string): any {
|
|
|
34
34
|
}
|
|
35
35
|
const originalMethod = descriptor.value;
|
|
36
36
|
descriptor.value = async function (...args: any[]) {
|
|
37
|
-
|
|
37
|
+
let collection = args[0];
|
|
38
38
|
let _ids = args[1];
|
|
39
39
|
if (!Array.isArray(_ids)) {
|
|
40
|
-
throw new AppError(`[${action}] IDs must be an array`, {
|
|
40
|
+
throw new AppError(`[${collection}] [${action}] IDs must be an array`, {
|
|
41
41
|
code: 'INVALID_ARGUMENT',
|
|
42
42
|
status: 400
|
|
43
43
|
})
|
|
44
44
|
}
|
|
45
45
|
for (let id of _ids) {
|
|
46
46
|
if (!ObjectId.isValid(id)) {
|
|
47
|
-
throw new AppError(`[${action}] IDs must be an array of valid ObjectId`, {
|
|
47
|
+
throw new AppError(`[${collection}] [${action}] IDs must be an array of valid ObjectId`, {
|
|
48
48
|
code: 'INVALID_ARGUMENT',
|
|
49
49
|
status: 400
|
|
50
50
|
})
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
if (_ids.length === 0) {
|
|
54
|
-
throw new AppError(`[${action}] IDs must be an array of at least one valid ObjectId`, {
|
|
54
|
+
throw new AppError(`[${collection}] [${action}] IDs must be an array of at least one valid ObjectId`, {
|
|
55
55
|
code: 'INVALID_ARGUMENT',
|
|
56
56
|
status: 400
|
|
57
57
|
})
|
|
@@ -69,15 +69,16 @@ export function CheckInsertData(action: string): any {
|
|
|
69
69
|
}
|
|
70
70
|
const originalMethod = descriptor.value;
|
|
71
71
|
descriptor.value = async function (...args: any[]) {
|
|
72
|
+
let collection = args[0];
|
|
72
73
|
let data = args[1];
|
|
73
74
|
if (action === 'insertOne') {
|
|
74
|
-
if (!data) throw new AppError(`[${action}] Data is required`, {
|
|
75
|
+
if (!data) throw new AppError(`[${collection}] [${action}] Data is required`, {
|
|
75
76
|
code: 'INVALID_ARGUMENT',
|
|
76
77
|
status: 400
|
|
77
78
|
})
|
|
78
79
|
}
|
|
79
80
|
if (action === 'insertMany') {
|
|
80
|
-
if (!data) throw new AppError(`[${action}] Data is required`, {
|
|
81
|
+
if (!data) throw new AppError(`[${collection}] [${action}] Data is required`, {
|
|
81
82
|
code: 'INVALID_ARGUMENT',
|
|
82
83
|
status: 400
|
|
83
84
|
})
|
|
@@ -94,9 +95,10 @@ export function CheckIfId(action: string): any {
|
|
|
94
95
|
}
|
|
95
96
|
const originalMethod = descriptor.value;
|
|
96
97
|
descriptor.value = async function (...args: any[]) {
|
|
98
|
+
let collection = args[0];
|
|
97
99
|
let _id = args[1];
|
|
98
100
|
if (!ObjectId.isValid(_id)) {
|
|
99
|
-
throw new AppError(`[${action}] ID must be a valid ObjectId`, {
|
|
101
|
+
throw new AppError(`[${collection}] [${action}] ID must be a valid ObjectId`, {
|
|
100
102
|
code: 'INVALID_ARGUMENT',
|
|
101
103
|
status: 400
|
|
102
104
|
})
|
|
@@ -115,13 +117,14 @@ export function CheckFilter(): any {
|
|
|
115
117
|
}
|
|
116
118
|
const originalMethod = descriptor.value;
|
|
117
119
|
descriptor.value = async function (...args: any[]) {
|
|
120
|
+
let collection = args[0];
|
|
118
121
|
let filter = args[1];
|
|
119
122
|
if (
|
|
120
123
|
filter === null ||
|
|
121
124
|
filter === undefined ||
|
|
122
125
|
(typeof filter === 'object' && Object.keys(filter).length === 0)
|
|
123
126
|
) {
|
|
124
|
-
throw new AppError(`[${propertyKey}] Filter is required and must not be empty`, {
|
|
127
|
+
throw new AppError(`[${collection}] [${propertyKey}] Filter is required and must not be empty`, {
|
|
125
128
|
code: 'FILTER_REQUIRED',
|
|
126
129
|
status: 400
|
|
127
130
|
})
|
|
@@ -139,26 +142,27 @@ export function CheckBulkWriteOperations(): any {
|
|
|
139
142
|
}
|
|
140
143
|
const originalMethod = descriptor.value;
|
|
141
144
|
descriptor.value = async function (...args: any[]) {
|
|
145
|
+
let collection = args[0];
|
|
142
146
|
let operations = args[1];
|
|
143
147
|
for (let operation of operations) {
|
|
144
|
-
if (!operation) throw new AppError(`[bulkWrite] Operation is required`, {
|
|
148
|
+
if (!operation) throw new AppError(`[${collection}] [bulkWrite] Operation is required`, {
|
|
145
149
|
code: 'INVALID_ARGUMENT',
|
|
146
150
|
status: 400
|
|
147
151
|
})
|
|
148
152
|
if (Object.hasOwn(operation, 'insertOne')) {
|
|
149
|
-
if (!operation.insertOne.document) throw new AppError(`[bulkWrite] Document is required`, {
|
|
153
|
+
if (!operation.insertOne.document) throw new AppError(`[${collection}] [bulkWrite] Document is required`, {
|
|
150
154
|
code: 'INVALID_ARGUMENT',
|
|
151
155
|
status: 400
|
|
152
156
|
})
|
|
153
157
|
}
|
|
154
158
|
if (Object.hasOwn(operation, 'updateOne')) {
|
|
155
|
-
if (!operation.updateOne.filter) throw new AppError(`[bulkWrite] Filter is required`, {
|
|
159
|
+
if (!operation.updateOne.filter) throw new AppError(`[${collection}] [bulkWrite] Filter is required`, {
|
|
156
160
|
code: 'INVALID_ARGUMENT',
|
|
157
161
|
status: 400
|
|
158
162
|
})
|
|
159
163
|
}
|
|
160
|
-
if (Object.hasOwn(operation, '
|
|
161
|
-
if (!operation.
|
|
164
|
+
if (Object.hasOwn(operation, 'updateMany')) {
|
|
165
|
+
if (!operation.updateMany.filter) throw new AppError(`[${collection}] [bulkWrite] Filter is required`, {
|
|
162
166
|
code: 'INVALID_ARGUMENT',
|
|
163
167
|
status: 400
|
|
164
168
|
})
|
package/package.json
CHANGED
package/server/api.ts
CHANGED
|
@@ -391,6 +391,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
391
391
|
return c.json(response);
|
|
392
392
|
|
|
393
393
|
} catch (err: any) {
|
|
394
|
+
if (cfg?.debug) console.error(err)
|
|
394
395
|
return errorResponse(c, err);
|
|
395
396
|
}
|
|
396
397
|
});
|
|
@@ -443,6 +444,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
443
444
|
throw err;
|
|
444
445
|
}
|
|
445
446
|
} catch (err: any) {
|
|
447
|
+
if (cfg?.debug) console.error(err)
|
|
446
448
|
return errorResponse(c, err);
|
|
447
449
|
}
|
|
448
450
|
});
|
|
@@ -483,6 +485,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
483
485
|
const result = await handleUpload({ collection, tenant_id, file: fileField, data });
|
|
484
486
|
return c.json(result);
|
|
485
487
|
} catch (err: any) {
|
|
488
|
+
if (cfg?.debug) console.error(err)
|
|
486
489
|
return errorResponse(c, err);
|
|
487
490
|
}
|
|
488
491
|
});
|
|
@@ -528,6 +531,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
528
531
|
c.header('Cache-Control', 'public, max-age=31536000, immutable');
|
|
529
532
|
return c.newResponse(result.stream);
|
|
530
533
|
} catch (err: any) {
|
|
534
|
+
if (cfg?.debug) console.error(err)
|
|
531
535
|
return errorResponse(c, err);
|
|
532
536
|
}
|
|
533
537
|
});
|
|
@@ -555,6 +559,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
555
559
|
await handleDelete(tenant_id, collection, fileId);
|
|
556
560
|
return c.json({ message: 'File deleted', ok: true });
|
|
557
561
|
} catch (err: any) {
|
|
562
|
+
if (cfg?.debug) console.error(err)
|
|
558
563
|
return errorResponse(c, err);
|
|
559
564
|
}
|
|
560
565
|
});
|
package/types/config.d.ts
CHANGED