@wordrhyme/auto-crud-server 1.4.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/README.md +20 -0
- package/dist/index.cjs +40 -20
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +40 -20
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1276,3 +1276,23 @@ MIT © [wordrhyme](https://github.com/pixpilot/shadcn-components)
|
|
|
1276
1276
|
- [tRPC](https://trpc.io/) - End-to-end typesafe APIs
|
|
1277
1277
|
- [Drizzle ORM](https://orm.drizzle.team/) - TypeScript ORM
|
|
1278
1278
|
- [Prisma](https://www.prisma.io/) - Next-generation ORM
|
|
1279
|
+
|
|
1280
|
+
## Server-side resource metadata
|
|
1281
|
+
|
|
1282
|
+
Every generated procedure includes `CrudResourceMetadata` in its tRPC metadata:
|
|
1283
|
+
|
|
1284
|
+
- `__crudResource.table`: the original Drizzle table object.
|
|
1285
|
+
- `__crudResource.idField`: the configured primary-key field (defaults to `id`).
|
|
1286
|
+
- `__crudOperation`: the generated CRUD operation. The schema `meta` endpoint uses `list`.
|
|
1287
|
+
|
|
1288
|
+
The resource binding is frozen. These two keys are reserved and override caller values; other metadata (such as permission or billing configuration) is preserved. Single procedures, procedure maps (including a custom `meta` procedure), and procedure factories are supported.
|
|
1289
|
+
|
|
1290
|
+
This metadata stays on the server; it is not added to the client-facing `meta` response. It describes the route and does not authorize requests. Applications remain responsible for permission checks and tenant isolation.
|
|
1291
|
+
|
|
1292
|
+
```ts
|
|
1293
|
+
import type { CrudResourceMetadata } from '@wordrhyme/auto-crud-server';
|
|
1294
|
+
|
|
1295
|
+
const t = initTRPC
|
|
1296
|
+
.meta<Partial<CrudResourceMetadata> & { permission?: string }>()
|
|
1297
|
+
.create();
|
|
1298
|
+
```
|
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;
|
|
@@ -1184,7 +1200,19 @@ function createCrudRouter(config) {
|
|
|
1184
1200
|
}))
|
|
1185
1201
|
});
|
|
1186
1202
|
const resolved = resolveConfig(config);
|
|
1187
|
-
const
|
|
1203
|
+
const resource = Object.freeze({
|
|
1204
|
+
table,
|
|
1205
|
+
idField
|
|
1206
|
+
});
|
|
1207
|
+
const procedureFactory = resolved.procedureFactory;
|
|
1208
|
+
resolved.procedureFactory = (operation) => procedureFactory(operation).meta({
|
|
1209
|
+
__crudResource: resource,
|
|
1210
|
+
__crudOperation: operation
|
|
1211
|
+
});
|
|
1212
|
+
const metaProcedure = resolveMetaProcedure(config.procedure, resolved.procedureFactory("list")).meta({
|
|
1213
|
+
__crudResource: resource,
|
|
1214
|
+
__crudOperation: "list"
|
|
1215
|
+
});
|
|
1188
1216
|
const softDelete = resolveSoftDelete(softDeleteOption);
|
|
1189
1217
|
const resolvedListInputSchema = config.listInputSchema ?? baseListInputSchema;
|
|
1190
1218
|
const resolvedGetInputSchema = config.getInputSchema ? zod.z.union([zod.z.string(), config.getInputSchema]) : defaultGetInputSchema;
|
|
@@ -1251,9 +1279,9 @@ function createCrudRouter(config) {
|
|
|
1251
1279
|
});
|
|
1252
1280
|
}
|
|
1253
1281
|
};
|
|
1254
|
-
const withAuthorize = async (ctx, resource, operation) => {
|
|
1255
|
-
if (!resource) return;
|
|
1256
|
-
if (!await resolved.checkAuthorize(ctx, resource, operation)) throw new __trpc_server.TRPCError({
|
|
1282
|
+
const withAuthorize = async (ctx, resource$1, operation) => {
|
|
1283
|
+
if (!resource$1) return;
|
|
1284
|
+
if (!await resolved.checkAuthorize(ctx, resource$1, operation)) throw new __trpc_server.TRPCError({
|
|
1257
1285
|
code: "FORBIDDEN",
|
|
1258
1286
|
message: `Forbidden: Cannot ${operation} this resource`
|
|
1259
1287
|
});
|
|
@@ -1287,11 +1315,7 @@ function createCrudRouter(config) {
|
|
|
1287
1315
|
});
|
|
1288
1316
|
},
|
|
1289
1317
|
resolveDateRange: ctx.resolveDateRange
|
|
1290
|
-
}) : void 0,
|
|
1291
|
-
table,
|
|
1292
|
-
search: effectiveInput.search,
|
|
1293
|
-
searchColumns
|
|
1294
|
-
})));
|
|
1318
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1295
1319
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1296
1320
|
if (where) query = query.where(where);
|
|
1297
1321
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, true);
|
|
@@ -1576,11 +1600,7 @@ function createCrudRouter(config) {
|
|
|
1576
1600
|
});
|
|
1577
1601
|
},
|
|
1578
1602
|
resolveDateRange: ctx.resolveDateRange
|
|
1579
|
-
}) : void 0,
|
|
1580
|
-
table,
|
|
1581
|
-
search: effectiveInput.search,
|
|
1582
|
-
searchColumns
|
|
1583
|
-
})));
|
|
1603
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1584
1604
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1585
1605
|
if (where) query = query.where(where);
|
|
1586
1606
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, false);
|
package/dist/index.d.cts
CHANGED
|
@@ -50,6 +50,18 @@ declare const publicProcedure: _trpc_server2.TRPCProcedureBuilder<Context, objec
|
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region src/types/config.d.ts
|
|
52
52
|
type CrudOperation = 'list' | 'get' | 'create' | 'update' | 'delete' | 'deleteMany' | 'updateMany' | 'upsert' | 'export' | 'import' | 'createMany';
|
|
53
|
+
/**
|
|
54
|
+
* Server-side metadata attached to every generated procedure.
|
|
55
|
+
* The `meta` endpoint uses the read operation `list`.
|
|
56
|
+
* Reserved keys describe the generated route; unrelated caller metadata is preserved.
|
|
57
|
+
*/
|
|
58
|
+
interface CrudResourceMetadata<TTable extends PgTable = PgTable> {
|
|
59
|
+
__crudResource: Readonly<{
|
|
60
|
+
table: TTable;
|
|
61
|
+
idField: string;
|
|
62
|
+
}>;
|
|
63
|
+
__crudOperation: CrudOperation;
|
|
64
|
+
}
|
|
53
65
|
type WriteOperation = 'create' | 'update';
|
|
54
66
|
/**
|
|
55
67
|
* 表字段键类型提取
|
|
@@ -987,4 +999,4 @@ declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
|
|
|
987
999
|
}, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
|
|
988
1000
|
type AppRouter = typeof appRouter;
|
|
989
1001
|
//#endregion
|
|
990
|
-
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudCapabilityMetadata, type CrudColumnCapability, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionValueWrite, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DateFilterRange, type DateRangeResolver, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, type ExtendedColumnFilter, type FilterOperator, type FilterVariant, type GetInput, type GetMiddlewareParams, type ImportFailedRow, type ImportInput, type ImportMiddlewareParams, type ImportResult, type ListInput, type ListMiddlewareParams, type ListResult, type ProcedureConfig, type ProcedureFactory, type ProcedureMap, type SoftDeleteConfig, type SoftDeleteOption, type UpdateManyMiddlewareParams, type UpdateMiddlewareParams, type UpsertMiddlewareParams, type WriteOperation, afterMiddleware, appRouter, baseExportInputSchema, baseGetInputSchema, baseListInputSchema, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
|
1002
|
+
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudCapabilityMetadata, type CrudColumnCapability, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionValueWrite, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudResourceMetadata, type CrudRouterConfig, type DateFilterRange, type DateRangeResolver, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, type ExtendedColumnFilter, type FilterOperator, type FilterVariant, type GetInput, type GetMiddlewareParams, type ImportFailedRow, type ImportInput, type ImportMiddlewareParams, type ImportResult, type ListInput, type ListMiddlewareParams, type ListResult, type ProcedureConfig, type ProcedureFactory, type ProcedureMap, type SoftDeleteConfig, type SoftDeleteOption, type UpdateManyMiddlewareParams, type UpdateMiddlewareParams, type UpsertMiddlewareParams, type WriteOperation, afterMiddleware, appRouter, baseExportInputSchema, baseGetInputSchema, baseListInputSchema, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,18 @@ declare const publicProcedure: _trpc_server2.TRPCProcedureBuilder<Context, objec
|
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region src/types/config.d.ts
|
|
53
53
|
type CrudOperation = 'list' | 'get' | 'create' | 'update' | 'delete' | 'deleteMany' | 'updateMany' | 'upsert' | 'export' | 'import' | 'createMany';
|
|
54
|
+
/**
|
|
55
|
+
* Server-side metadata attached to every generated procedure.
|
|
56
|
+
* The `meta` endpoint uses the read operation `list`.
|
|
57
|
+
* Reserved keys describe the generated route; unrelated caller metadata is preserved.
|
|
58
|
+
*/
|
|
59
|
+
interface CrudResourceMetadata<TTable extends PgTable = PgTable> {
|
|
60
|
+
__crudResource: Readonly<{
|
|
61
|
+
table: TTable;
|
|
62
|
+
idField: string;
|
|
63
|
+
}>;
|
|
64
|
+
__crudOperation: CrudOperation;
|
|
65
|
+
}
|
|
54
66
|
type WriteOperation = 'create' | 'update';
|
|
55
67
|
/**
|
|
56
68
|
* 表字段键类型提取
|
|
@@ -988,4 +1000,4 @@ declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
|
|
|
988
1000
|
}, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
|
|
989
1001
|
type AppRouter = typeof appRouter;
|
|
990
1002
|
//#endregion
|
|
991
|
-
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudCapabilityMetadata, type CrudColumnCapability, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionValueWrite, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DateFilterRange, type DateRangeResolver, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, type ExtendedColumnFilter, type FilterOperator, type FilterVariant, type GetInput, type GetMiddlewareParams, type ImportFailedRow, type ImportInput, type ImportMiddlewareParams, type ImportResult, type ListInput, type ListMiddlewareParams, type ListResult, type ProcedureConfig, type ProcedureFactory, type ProcedureMap, type SoftDeleteConfig, type SoftDeleteOption, type UpdateManyMiddlewareParams, type UpdateMiddlewareParams, type UpsertMiddlewareParams, type WriteOperation, afterMiddleware, appRouter, baseExportInputSchema, baseGetInputSchema, baseListInputSchema, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
|
1003
|
+
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudCapabilityMetadata, type CrudColumnCapability, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionValueWrite, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudResourceMetadata, type CrudRouterConfig, type DateFilterRange, type DateRangeResolver, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, type ExtendedColumnFilter, type FilterOperator, type FilterVariant, type GetInput, type GetMiddlewareParams, type ImportFailedRow, type ImportInput, type ImportMiddlewareParams, type ImportResult, type ListInput, type ListMiddlewareParams, type ListResult, type ProcedureConfig, type ProcedureFactory, type ProcedureMap, type SoftDeleteConfig, type SoftDeleteOption, type UpdateManyMiddlewareParams, type UpdateMiddlewareParams, type UpsertMiddlewareParams, type WriteOperation, afterMiddleware, appRouter, baseExportInputSchema, baseGetInputSchema, baseListInputSchema, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
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;
|
|
@@ -1153,7 +1169,19 @@ function createCrudRouter(config) {
|
|
|
1153
1169
|
}))
|
|
1154
1170
|
});
|
|
1155
1171
|
const resolved = resolveConfig(config);
|
|
1156
|
-
const
|
|
1172
|
+
const resource = Object.freeze({
|
|
1173
|
+
table,
|
|
1174
|
+
idField
|
|
1175
|
+
});
|
|
1176
|
+
const procedureFactory = resolved.procedureFactory;
|
|
1177
|
+
resolved.procedureFactory = (operation) => procedureFactory(operation).meta({
|
|
1178
|
+
__crudResource: resource,
|
|
1179
|
+
__crudOperation: operation
|
|
1180
|
+
});
|
|
1181
|
+
const metaProcedure = resolveMetaProcedure(config.procedure, resolved.procedureFactory("list")).meta({
|
|
1182
|
+
__crudResource: resource,
|
|
1183
|
+
__crudOperation: "list"
|
|
1184
|
+
});
|
|
1157
1185
|
const softDelete = resolveSoftDelete(softDeleteOption);
|
|
1158
1186
|
const resolvedListInputSchema = config.listInputSchema ?? baseListInputSchema;
|
|
1159
1187
|
const resolvedGetInputSchema = config.getInputSchema ? z.union([z.string(), config.getInputSchema]) : defaultGetInputSchema;
|
|
@@ -1220,9 +1248,9 @@ function createCrudRouter(config) {
|
|
|
1220
1248
|
});
|
|
1221
1249
|
}
|
|
1222
1250
|
};
|
|
1223
|
-
const withAuthorize = async (ctx, resource, operation) => {
|
|
1224
|
-
if (!resource) return;
|
|
1225
|
-
if (!await resolved.checkAuthorize(ctx, resource, operation)) throw new TRPCError({
|
|
1251
|
+
const withAuthorize = async (ctx, resource$1, operation) => {
|
|
1252
|
+
if (!resource$1) return;
|
|
1253
|
+
if (!await resolved.checkAuthorize(ctx, resource$1, operation)) throw new TRPCError({
|
|
1226
1254
|
code: "FORBIDDEN",
|
|
1227
1255
|
message: `Forbidden: Cannot ${operation} this resource`
|
|
1228
1256
|
});
|
|
@@ -1256,11 +1284,7 @@ function createCrudRouter(config) {
|
|
|
1256
1284
|
});
|
|
1257
1285
|
},
|
|
1258
1286
|
resolveDateRange: ctx.resolveDateRange
|
|
1259
|
-
}) : void 0,
|
|
1260
|
-
table,
|
|
1261
|
-
search: effectiveInput.search,
|
|
1262
|
-
searchColumns
|
|
1263
|
-
})));
|
|
1287
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1264
1288
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1265
1289
|
if (where) query = query.where(where);
|
|
1266
1290
|
const orderByExpressions = buildOrderByExpressions(effectiveInput.sort, true);
|
|
@@ -1545,11 +1569,7 @@ function createCrudRouter(config) {
|
|
|
1545
1569
|
});
|
|
1546
1570
|
},
|
|
1547
1571
|
resolveDateRange: ctx.resolveDateRange
|
|
1548
|
-
}) : void 0,
|
|
1549
|
-
table,
|
|
1550
|
-
search: effectiveInput.search,
|
|
1551
|
-
searchColumns
|
|
1552
|
-
})));
|
|
1572
|
+
}) : void 0, buildCrudSearchWithExtensions(table, idField, effectiveInput, searchColumns)));
|
|
1553
1573
|
let query = ctx.db.select().from(table).$dynamic();
|
|
1554
1574
|
if (where) query = query.where(where);
|
|
1555
1575
|
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
|
+
"version": "1.5.0",
|
|
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/
|
|
52
|
+
"@internal/tsconfig": "0.1.0",
|
|
53
|
+
"@internal/tsdown-config": "0.1.0",
|
|
54
54
|
"@internal/prettier-config": "0.0.1",
|
|
55
|
-
"@internal/
|
|
55
|
+
"@internal/vitest-config": "0.1.0"
|
|
56
56
|
},
|
|
57
57
|
"prettier": "@internal/prettier-config",
|
|
58
58
|
"scripts": {
|