@wordrhyme/auto-crud-server 1.4.0 → 1.4.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.cjs +24 -16
- package/dist/index.js +24 -16
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -797,7 +797,7 @@ function resolveColumnTarget({ table, columnId, allowedColumns }) {
|
|
|
797
797
|
return getTableColumn(table, columnId);
|
|
798
798
|
}
|
|
799
799
|
const CRUD_EXTENSION_FILTER_ID = "auto-crud-extension-filter";
|
|
800
|
-
const
|
|
800
|
+
const CRUD_EXTENSION_SEARCH_IDS = Symbol("auto-crud-extension-search-ids");
|
|
801
801
|
function isObjectRecord(value) {
|
|
802
802
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
803
803
|
}
|
|
@@ -1053,11 +1053,12 @@ async function applyCrudExtensionFilters(ctx, config, table, idField, filterable
|
|
|
1053
1053
|
limit: 5e3
|
|
1054
1054
|
}));
|
|
1055
1055
|
}
|
|
1056
|
-
|
|
1056
|
+
let extensionSearchIds;
|
|
1057
|
+
if (search && !searchDisabled && provider?.searchEntityIds) extensionSearchIds = await provider.searchEntityIds({
|
|
1057
1058
|
id: target.id,
|
|
1058
1059
|
search,
|
|
1059
1060
|
limit: 5e3
|
|
1060
|
-
})
|
|
1061
|
+
});
|
|
1061
1062
|
else if (search && !searchDisabled && !buildCrudSearchCondition({
|
|
1062
1063
|
table,
|
|
1063
1064
|
search,
|
|
@@ -1067,23 +1068,38 @@ async function applyCrudExtensionFilters(ctx, config, table, idField, filterable
|
|
|
1067
1068
|
message: "CRUD search is not available"
|
|
1068
1069
|
});
|
|
1069
1070
|
const matchedSets = (await Promise.all(matchRequests)).map((matchedIds$1) => new Set(matchedIds$1));
|
|
1070
|
-
|
|
1071
|
+
const effectiveInput = extensionSearchIds === void 0 ? input : {
|
|
1071
1072
|
...input,
|
|
1073
|
+
[CRUD_EXTENSION_SEARCH_IDS]: extensionSearchIds
|
|
1074
|
+
};
|
|
1075
|
+
if (matchedSets.length === 0) return {
|
|
1076
|
+
...effectiveInput,
|
|
1072
1077
|
filters: baseFilters
|
|
1073
1078
|
};
|
|
1074
1079
|
let matchedIds = matchedSets[0] ? [...matchedSets[0]] : [];
|
|
1075
1080
|
for (const set of matchedSets.slice(1)) matchedIds = matchedIds.filter((id) => set.has(id));
|
|
1076
1081
|
return {
|
|
1077
|
-
...
|
|
1082
|
+
...effectiveInput,
|
|
1078
1083
|
filters: [...baseFilters, {
|
|
1079
1084
|
id: idField,
|
|
1080
|
-
value: matchedIds
|
|
1085
|
+
value: matchedIds,
|
|
1081
1086
|
variant: "multiSelect",
|
|
1082
1087
|
operator: "inArray",
|
|
1083
1088
|
filterId: CRUD_EXTENSION_FILTER_ID
|
|
1084
1089
|
}]
|
|
1085
1090
|
};
|
|
1086
1091
|
}
|
|
1092
|
+
function buildCrudSearchWithExtensions(table, idField, input, searchColumns) {
|
|
1093
|
+
const baseCondition = buildCrudSearchCondition({
|
|
1094
|
+
table,
|
|
1095
|
+
search: input.search,
|
|
1096
|
+
searchColumns
|
|
1097
|
+
});
|
|
1098
|
+
const extensionIds = input[CRUD_EXTENSION_SEARCH_IDS];
|
|
1099
|
+
if (extensionIds === void 0) return baseCondition;
|
|
1100
|
+
const extensionCondition = (0, drizzle_orm.inArray)(getTableColumn(table, idField), extensionIds);
|
|
1101
|
+
return baseCondition ? (0, drizzle_orm.or)(baseCondition, extensionCondition) : extensionCondition;
|
|
1102
|
+
}
|
|
1087
1103
|
function buildCrudSearchCondition({ table, search, searchColumns }) {
|
|
1088
1104
|
const term = typeof search === "string" ? search.trim() : "";
|
|
1089
1105
|
if (!term || !Array.isArray(searchColumns) || searchColumns.length === 0) return;
|
|
@@ -1287,11 +1303,7 @@ function createCrudRouter(config) {
|
|
|
1287
1303
|
});
|
|
1288
1304
|
},
|
|
1289
1305
|
resolveDateRange: ctx.resolveDateRange
|
|
1290
|
-
}) : void 0,
|
|
1291
|
-
table,
|
|
1292
|
-
search: effectiveInput.search,
|
|
1293
|
-
searchColumns
|
|
1294
|
-
})));
|
|
1306
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1295
1307
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1296
1308
|
if (where) query = query.where(where);
|
|
1297
1309
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, true);
|
|
@@ -1576,11 +1588,7 @@ function createCrudRouter(config) {
|
|
|
1576
1588
|
});
|
|
1577
1589
|
},
|
|
1578
1590
|
resolveDateRange: ctx.resolveDateRange
|
|
1579
|
-
}) : void 0,
|
|
1580
|
-
table,
|
|
1581
|
-
search: effectiveInput.search,
|
|
1582
|
-
searchColumns
|
|
1583
|
-
})));
|
|
1591
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1584
1592
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1585
1593
|
if (where) query = query.where(where);
|
|
1586
1594
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, false);
|
package/dist/index.js
CHANGED
|
@@ -766,7 +766,7 @@ function resolveColumnTarget({ table, columnId, allowedColumns }) {
|
|
|
766
766
|
return getTableColumn(table, columnId);
|
|
767
767
|
}
|
|
768
768
|
const CRUD_EXTENSION_FILTER_ID = "auto-crud-extension-filter";
|
|
769
|
-
const
|
|
769
|
+
const CRUD_EXTENSION_SEARCH_IDS = Symbol("auto-crud-extension-search-ids");
|
|
770
770
|
function isObjectRecord(value) {
|
|
771
771
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
772
772
|
}
|
|
@@ -1022,11 +1022,12 @@ async function applyCrudExtensionFilters(ctx, config, table, idField, filterable
|
|
|
1022
1022
|
limit: 5e3
|
|
1023
1023
|
}));
|
|
1024
1024
|
}
|
|
1025
|
-
|
|
1025
|
+
let extensionSearchIds;
|
|
1026
|
+
if (search && !searchDisabled && provider?.searchEntityIds) extensionSearchIds = await provider.searchEntityIds({
|
|
1026
1027
|
id: target.id,
|
|
1027
1028
|
search,
|
|
1028
1029
|
limit: 5e3
|
|
1029
|
-
})
|
|
1030
|
+
});
|
|
1030
1031
|
else if (search && !searchDisabled && !buildCrudSearchCondition({
|
|
1031
1032
|
table,
|
|
1032
1033
|
search,
|
|
@@ -1036,23 +1037,38 @@ async function applyCrudExtensionFilters(ctx, config, table, idField, filterable
|
|
|
1036
1037
|
message: "CRUD search is not available"
|
|
1037
1038
|
});
|
|
1038
1039
|
const matchedSets = (await Promise.all(matchRequests)).map((matchedIds$1) => new Set(matchedIds$1));
|
|
1039
|
-
|
|
1040
|
+
const effectiveInput = extensionSearchIds === void 0 ? input : {
|
|
1040
1041
|
...input,
|
|
1042
|
+
[CRUD_EXTENSION_SEARCH_IDS]: extensionSearchIds
|
|
1043
|
+
};
|
|
1044
|
+
if (matchedSets.length === 0) return {
|
|
1045
|
+
...effectiveInput,
|
|
1041
1046
|
filters: baseFilters
|
|
1042
1047
|
};
|
|
1043
1048
|
let matchedIds = matchedSets[0] ? [...matchedSets[0]] : [];
|
|
1044
1049
|
for (const set of matchedSets.slice(1)) matchedIds = matchedIds.filter((id) => set.has(id));
|
|
1045
1050
|
return {
|
|
1046
|
-
...
|
|
1051
|
+
...effectiveInput,
|
|
1047
1052
|
filters: [...baseFilters, {
|
|
1048
1053
|
id: idField,
|
|
1049
|
-
value: matchedIds
|
|
1054
|
+
value: matchedIds,
|
|
1050
1055
|
variant: "multiSelect",
|
|
1051
1056
|
operator: "inArray",
|
|
1052
1057
|
filterId: CRUD_EXTENSION_FILTER_ID
|
|
1053
1058
|
}]
|
|
1054
1059
|
};
|
|
1055
1060
|
}
|
|
1061
|
+
function buildCrudSearchWithExtensions(table, idField, input, searchColumns) {
|
|
1062
|
+
const baseCondition = buildCrudSearchCondition({
|
|
1063
|
+
table,
|
|
1064
|
+
search: input.search,
|
|
1065
|
+
searchColumns
|
|
1066
|
+
});
|
|
1067
|
+
const extensionIds = input[CRUD_EXTENSION_SEARCH_IDS];
|
|
1068
|
+
if (extensionIds === void 0) return baseCondition;
|
|
1069
|
+
const extensionCondition = inArray(getTableColumn(table, idField), extensionIds);
|
|
1070
|
+
return baseCondition ? or(baseCondition, extensionCondition) : extensionCondition;
|
|
1071
|
+
}
|
|
1056
1072
|
function buildCrudSearchCondition({ table, search, searchColumns }) {
|
|
1057
1073
|
const term = typeof search === "string" ? search.trim() : "";
|
|
1058
1074
|
if (!term || !Array.isArray(searchColumns) || searchColumns.length === 0) return;
|
|
@@ -1256,11 +1272,7 @@ function createCrudRouter(config) {
|
|
|
1256
1272
|
});
|
|
1257
1273
|
},
|
|
1258
1274
|
resolveDateRange: ctx.resolveDateRange
|
|
1259
|
-
}) : void 0,
|
|
1260
|
-
table,
|
|
1261
|
-
search: effectiveInput.search,
|
|
1262
|
-
searchColumns
|
|
1263
|
-
})));
|
|
1275
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1264
1276
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1265
1277
|
if (where) query = query.where(where);
|
|
1266
1278
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, true);
|
|
@@ -1545,11 +1557,7 @@ function createCrudRouter(config) {
|
|
|
1545
1557
|
});
|
|
1546
1558
|
},
|
|
1547
1559
|
resolveDateRange: ctx.resolveDateRange
|
|
1548
|
-
}) : void 0,
|
|
1549
|
-
table,
|
|
1550
|
-
search: effectiveInput.search,
|
|
1551
|
-
searchColumns
|
|
1552
|
-
})));
|
|
1560
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1553
1561
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1554
1562
|
if (where) query = query.where(where);
|
|
1555
1563
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, false);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"description": "tRPC server utilities for auto-crud - automatic CRUD routers for Drizzle ORM",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^4.0.18",
|
|
50
50
|
"zod": "^4.3.6",
|
|
51
|
-
"@internal/tsconfig": "0.1.0",
|
|
52
51
|
"@internal/eslint-config": "0.3.0",
|
|
53
|
-
"@internal/vitest-config": "0.1.0",
|
|
54
52
|
"@internal/prettier-config": "0.0.1",
|
|
55
|
-
"@internal/tsdown-config": "0.1.0"
|
|
53
|
+
"@internal/tsdown-config": "0.1.0",
|
|
54
|
+
"@internal/tsconfig": "0.1.0",
|
|
55
|
+
"@internal/vitest-config": "0.1.0"
|
|
56
56
|
},
|
|
57
57
|
"prettier": "@internal/prettier-config",
|
|
58
58
|
"scripts": {
|