unconventional 2.4.0 → 3.1.1
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/dist/core/base.model.js +1 -0
- package/dist/utils/db.utils.js +14 -4
- package/package.json +4 -5
package/dist/core/base.model.js
CHANGED
package/dist/utils/db.utils.js
CHANGED
|
@@ -177,11 +177,21 @@ function getOrder(model, sort) {
|
|
|
177
177
|
return [{ field: model.idField, direction: unconventional_pg_queries_1.SqlDirection.Asc }];
|
|
178
178
|
const propSummary = model.schema.props;
|
|
179
179
|
const orders = [];
|
|
180
|
-
sort.split(
|
|
181
|
-
let [field, direction] = item.split(
|
|
182
|
-
let jsonPath = [];
|
|
180
|
+
sort.split(/,(?![^()]*\))/).forEach((item) => {
|
|
181
|
+
let [field, direction] = item.trim().split(/\s+(?![^()]*\))/);
|
|
183
182
|
direction ||= unconventional_pg_queries_1.SqlDirection.Asc;
|
|
183
|
+
const coalesce = field.match(/^COALESCE\(([^()]+)\)$/i)?.[1].split(',').map(column => column.trim());
|
|
184
|
+
if (coalesce) {
|
|
185
|
+
field = coalesce.shift() ?? '';
|
|
186
|
+
if (!coalesce.length)
|
|
187
|
+
throw api_error_1.APIError.errInvalidQueryParameter(`COALESCE requires a fallback field`);
|
|
188
|
+
coalesce.forEach(column => {
|
|
189
|
+
if (!propSummary[column])
|
|
190
|
+
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid orderBy field: '${column}'`);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
184
193
|
// Handle JSON path
|
|
194
|
+
let jsonPath = [];
|
|
185
195
|
if (field.includes('.')) {
|
|
186
196
|
jsonPath = field.split('.');
|
|
187
197
|
field = jsonPath.shift();
|
|
@@ -190,7 +200,7 @@ function getOrder(model, sort) {
|
|
|
190
200
|
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid orderBy field: '${field}'`);
|
|
191
201
|
if (!db_types_1.ValidSortDirections.includes(direction.toUpperCase()))
|
|
192
202
|
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid orderBy direction: '${direction}'`);
|
|
193
|
-
orders.push({ field, jsonPath, direction: direction.toUpperCase() });
|
|
203
|
+
orders.push({ field, jsonPath, direction: direction.toUpperCase(), ...(coalesce ? { coalesce } : {}) });
|
|
194
204
|
});
|
|
195
205
|
return orders;
|
|
196
206
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unconventional",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A complete server built on Cloudflare Workers
|
|
3
|
+
"version": "3.1.1",
|
|
4
|
+
"description": "A complete server built on Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
7
|
-
"pages",
|
|
8
7
|
"functions",
|
|
9
8
|
"workers",
|
|
10
9
|
"edge",
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
47
|
"hono": "^4",
|
|
49
|
-
"unconventional-pg-queries": "^
|
|
48
|
+
"unconventional-pg-queries": "^3.1.1"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@cloudflare/workers-types": "^4.20231121.0",
|
|
@@ -56,6 +55,6 @@
|
|
|
56
55
|
"hono": "^4",
|
|
57
56
|
"tsx": "^4.20.6",
|
|
58
57
|
"typescript": "^5.3.3",
|
|
59
|
-
"unconventional-pg-queries": "^
|
|
58
|
+
"unconventional-pg-queries": "^3.1.1"
|
|
60
59
|
}
|
|
61
60
|
}
|