@restura/core 0.1.3 → 0.2.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/index.d.mts +63 -46
- package/dist/index.d.ts +63 -46
- package/dist/index.js +39 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -572,7 +572,15 @@ var ResponseValidator = class _ResponseValidator {
|
|
|
572
572
|
return { validator: map, isArray: route.type === "ARRAY" };
|
|
573
573
|
}
|
|
574
574
|
getFieldResponseType(field, tableName) {
|
|
575
|
-
if (field.
|
|
575
|
+
if (field.type) {
|
|
576
|
+
if (_ResponseValidator.validatorIsValidString(field.type)) {
|
|
577
|
+
return { validator: field.type };
|
|
578
|
+
}
|
|
579
|
+
if (field.type.includes("|")) {
|
|
580
|
+
return { validator: this.parseValidationEnum(field.type) };
|
|
581
|
+
}
|
|
582
|
+
return { validator: "object" };
|
|
583
|
+
} else if (field.selector) {
|
|
576
584
|
return this.getTypeFromTable(field.selector, tableName);
|
|
577
585
|
} else if (field.subquery) {
|
|
578
586
|
const table = this.database.find((t) => t.name == tableName);
|
|
@@ -798,7 +806,9 @@ var ApiTree = class _ApiTree {
|
|
|
798
806
|
}
|
|
799
807
|
getNameAndType(p, routeBaseTable, joins) {
|
|
800
808
|
let responseType = "any", isNullable = false, array = false;
|
|
801
|
-
if (p.
|
|
809
|
+
if (p.type) {
|
|
810
|
+
responseType = p.type;
|
|
811
|
+
} else if (p.selector) {
|
|
802
812
|
({ responseType, isNullable } = this.getTypeFromTable(p.selector, p.name));
|
|
803
813
|
const selectorKey = p.selector.split(".")[0];
|
|
804
814
|
if (selectorKey !== routeBaseTable) {
|
|
@@ -1048,7 +1058,22 @@ var groupBySchema = z3.object({
|
|
|
1048
1058
|
var whereDataSchema = z3.object({
|
|
1049
1059
|
tableName: z3.string().optional(),
|
|
1050
1060
|
columnName: z3.string().optional(),
|
|
1051
|
-
operator: z3.enum([
|
|
1061
|
+
operator: z3.enum([
|
|
1062
|
+
"=",
|
|
1063
|
+
"<",
|
|
1064
|
+
">",
|
|
1065
|
+
"<=",
|
|
1066
|
+
">=",
|
|
1067
|
+
"!=",
|
|
1068
|
+
"LIKE",
|
|
1069
|
+
"NOT LIKE",
|
|
1070
|
+
"IN",
|
|
1071
|
+
"NOT IN",
|
|
1072
|
+
"STARTS WITH",
|
|
1073
|
+
"ENDS WITH",
|
|
1074
|
+
"IS",
|
|
1075
|
+
"IS NOT"
|
|
1076
|
+
]).optional(),
|
|
1052
1077
|
value: z3.string().or(z3.number()).optional(),
|
|
1053
1078
|
custom: z3.string().optional(),
|
|
1054
1079
|
conjunction: z3.enum(["AND", "OR"]).optional()
|
|
@@ -1082,7 +1107,8 @@ var responseDataSchema = z3.object({
|
|
|
1082
1107
|
// Explicit type for the lazy schema
|
|
1083
1108
|
groupBy: groupBySchema.optional(),
|
|
1084
1109
|
orderBy: orderBySchema.optional()
|
|
1085
|
-
}).optional()
|
|
1110
|
+
}).optional(),
|
|
1111
|
+
type: z3.string().optional()
|
|
1086
1112
|
}).strict();
|
|
1087
1113
|
var routeDataBaseSchema = z3.object({
|
|
1088
1114
|
method: z3.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
|
|
@@ -1733,6 +1759,7 @@ var SqlEngine = class {
|
|
|
1733
1759
|
return tableSchema;
|
|
1734
1760
|
}
|
|
1735
1761
|
doesRoleHavePermissionToColumn(role, schema, item, joins) {
|
|
1762
|
+
if (item.type) return true;
|
|
1736
1763
|
if (item.selector) {
|
|
1737
1764
|
let tableName = item.selector.split(".")[0];
|
|
1738
1765
|
const columnName = item.selector.split(".")[1];
|
|
@@ -2215,7 +2242,7 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
2215
2242
|
item.name
|
|
2216
2243
|
)}`;
|
|
2217
2244
|
}
|
|
2218
|
-
return `${escapeColumnName(item.selector)} AS ${escapeColumnName(item.name)}`;
|
|
2245
|
+
return `${item.type ? item.selector : escapeColumnName(item.selector)} AS ${escapeColumnName(item.name)}`;
|
|
2219
2246
|
}).join(",\n ")}
|
|
2220
2247
|
`;
|
|
2221
2248
|
sqlStatement += `FROM "${routeData.table}"
|
|
@@ -2369,16 +2396,19 @@ DELETE FROM "${routeData.table}" ${joinStatement} ${whereClause}`;
|
|
|
2369
2396
|
`Invalid where clause in route ${routeData.name}, missing required fields if not custom`
|
|
2370
2397
|
);
|
|
2371
2398
|
let operator = item.operator;
|
|
2399
|
+
let value = item.value;
|
|
2372
2400
|
if (operator === "LIKE") {
|
|
2373
|
-
|
|
2401
|
+
value = `'%${value}%'`;
|
|
2402
|
+
} else if (operator === "NOT LIKE") {
|
|
2403
|
+
value = `'%${value}%'`;
|
|
2374
2404
|
} else if (operator === "STARTS WITH") {
|
|
2375
2405
|
operator = "LIKE";
|
|
2376
|
-
|
|
2406
|
+
value = `'${value}%'`;
|
|
2377
2407
|
} else if (operator === "ENDS WITH") {
|
|
2378
2408
|
operator = "LIKE";
|
|
2379
|
-
|
|
2409
|
+
value = `'%${value}'`;
|
|
2380
2410
|
}
|
|
2381
|
-
const replacedValue = this.replaceParamKeywords(
|
|
2411
|
+
const replacedValue = this.replaceParamKeywords(value, routeData, req, sqlParams);
|
|
2382
2412
|
whereClause += ` ${item.conjunction || ""} "${item.tableName}"."${item.columnName}" ${operator.replace("LIKE", "ILIKE")} ${["IN", "NOT IN"].includes(operator) ? `(${replacedValue})` : replacedValue}
|
|
2383
2413
|
`;
|
|
2384
2414
|
});
|