@wordrhyme/auto-crud-server 1.4.1 → 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 +16 -4
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +16 -4
- package/package.json +3 -3
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
|
@@ -1200,7 +1200,19 @@ function createCrudRouter(config) {
|
|
|
1200
1200
|
}))
|
|
1201
1201
|
});
|
|
1202
1202
|
const resolved = resolveConfig(config);
|
|
1203
|
-
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
|
+
});
|
|
1204
1216
|
const softDelete = resolveSoftDelete(softDeleteOption);
|
|
1205
1217
|
const resolvedListInputSchema = config.listInputSchema ?? baseListInputSchema;
|
|
1206
1218
|
const resolvedGetInputSchema = config.getInputSchema ? zod.z.union([zod.z.string(), config.getInputSchema]) : defaultGetInputSchema;
|
|
@@ -1267,9 +1279,9 @@ function createCrudRouter(config) {
|
|
|
1267
1279
|
});
|
|
1268
1280
|
}
|
|
1269
1281
|
};
|
|
1270
|
-
const withAuthorize = async (ctx, resource, operation) => {
|
|
1271
|
-
if (!resource) return;
|
|
1272
|
-
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({
|
|
1273
1285
|
code: "FORBIDDEN",
|
|
1274
1286
|
message: `Forbidden: Cannot ${operation} this resource`
|
|
1275
1287
|
});
|
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
|
@@ -1169,7 +1169,19 @@ function createCrudRouter(config) {
|
|
|
1169
1169
|
}))
|
|
1170
1170
|
});
|
|
1171
1171
|
const resolved = resolveConfig(config);
|
|
1172
|
-
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
|
+
});
|
|
1173
1185
|
const softDelete = resolveSoftDelete(softDeleteOption);
|
|
1174
1186
|
const resolvedListInputSchema = config.listInputSchema ?? baseListInputSchema;
|
|
1175
1187
|
const resolvedGetInputSchema = config.getInputSchema ? z.union([z.string(), config.getInputSchema]) : defaultGetInputSchema;
|
|
@@ -1236,9 +1248,9 @@ function createCrudRouter(config) {
|
|
|
1236
1248
|
});
|
|
1237
1249
|
}
|
|
1238
1250
|
};
|
|
1239
|
-
const withAuthorize = async (ctx, resource, operation) => {
|
|
1240
|
-
if (!resource) return;
|
|
1241
|
-
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({
|
|
1242
1254
|
code: "FORBIDDEN",
|
|
1243
1255
|
message: `Forbidden: Cannot ${operation} this resource`
|
|
1244
1256
|
});
|
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",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"vitest": "^4.0.18",
|
|
50
50
|
"zod": "^4.3.6",
|
|
51
51
|
"@internal/eslint-config": "0.3.0",
|
|
52
|
-
"@internal/prettier-config": "0.0.1",
|
|
53
|
-
"@internal/tsdown-config": "0.1.0",
|
|
54
52
|
"@internal/tsconfig": "0.1.0",
|
|
53
|
+
"@internal/tsdown-config": "0.1.0",
|
|
54
|
+
"@internal/prettier-config": "0.0.1",
|
|
55
55
|
"@internal/vitest-config": "0.1.0"
|
|
56
56
|
},
|
|
57
57
|
"prettier": "@internal/prettier-config",
|