@wordrhyme/auto-crud-server 1.0.3 → 1.0.4
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.cts +95 -8
- package/dist/index.d.ts +88 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _trpc_server0 from "@trpc/server";
|
|
3
3
|
import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
4
4
|
import { SQL } from "drizzle-orm";
|
|
5
5
|
import { z } from "zod";
|
|
@@ -12,13 +12,13 @@ import { z } from "zod";
|
|
|
12
12
|
interface Context {
|
|
13
13
|
db: PostgresJsDatabase<Record<string, never>>;
|
|
14
14
|
}
|
|
15
|
-
declare const router:
|
|
15
|
+
declare const router: _trpc_server0.TRPCRouterBuilder<{
|
|
16
16
|
ctx: Context;
|
|
17
17
|
meta: object;
|
|
18
|
-
errorShape:
|
|
18
|
+
errorShape: _trpc_server0.TRPCDefaultErrorShape;
|
|
19
19
|
transformer: true;
|
|
20
20
|
}>;
|
|
21
|
-
declare const publicProcedure:
|
|
21
|
+
declare const publicProcedure: _trpc_server0.TRPCProcedureBuilder<Context, object, object, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, false>;
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/types/config.d.ts
|
|
24
24
|
type CrudOperation = "list" | "get" | "create" | "update" | "delete" | "deleteMany" | "updateMany" | "upsert" | "export" | "import" | "createMany";
|
|
@@ -611,13 +611,100 @@ type AnyMiddlewareParams<TContext> = {
|
|
|
611
611
|
*/
|
|
612
612
|
declare function composeMiddleware<TContext, TResult>(...middlewares: Array<(params: AnyMiddlewareParams<TContext>) => Promise<any>>): (params: AnyMiddlewareParams<TContext>) => Promise<TResult>;
|
|
613
613
|
//#endregion
|
|
614
|
+
//#region src/types/hook-types.d.ts
|
|
615
|
+
/**
|
|
616
|
+
* Hook 系统类型工具
|
|
617
|
+
*
|
|
618
|
+
* 提供 CrudHookEventMap 类型——从 Zod Schema / Drizzle Table 推导出
|
|
619
|
+
* auto-crud 相关的所有 Hook 事件类型。
|
|
620
|
+
*
|
|
621
|
+
* 下游插件通过 module augmentation 合并到全局 HookEventMap:
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```typescript
|
|
625
|
+
* import type { CrudHookEventMap } from "@wordrhyme/auto-crud-server";
|
|
626
|
+
* import type { z } from "zod";
|
|
627
|
+
* import type { InferSelectModel } from "drizzle-orm";
|
|
628
|
+
*
|
|
629
|
+
* declare module "@wordrhyme/plugin" {
|
|
630
|
+
* interface HookEventMap extends CrudHookEventMap<
|
|
631
|
+
* "crm",
|
|
632
|
+
* "customers",
|
|
633
|
+
* z.infer<typeof createCustomerSchema>,
|
|
634
|
+
* z.infer<typeof updateCustomerSchema>,
|
|
635
|
+
* InferSelectModel<typeof customerTable>
|
|
636
|
+
* > {}
|
|
637
|
+
* }
|
|
638
|
+
*
|
|
639
|
+
* // 使用效果:
|
|
640
|
+
* // ctx.hooks.emit('crm.customers. ← IDE 自动补全所有 hook 名和 payload
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
/**
|
|
644
|
+
* 从 CRUD Schema 类型自动推导 Hook 事件映射
|
|
645
|
+
*
|
|
646
|
+
* 生成两类 hook:
|
|
647
|
+
* 1. 生命周期 hook(beforeCreate / afterCreate 等)— 由 tRPC middleware 自动 emit
|
|
648
|
+
* 2. Procedure hook(create / update / list 等)— 供 emit 自动映射 tRPC 路由使用
|
|
649
|
+
*
|
|
650
|
+
* @typeParam PluginId - 插件标识(如 'crm', 'shop')
|
|
651
|
+
* @typeParam ResourceName - 资源名称(如 'customers', 'products')
|
|
652
|
+
* @typeParam TCreate - 创建输入类型(z.infer<typeof createSchema>)
|
|
653
|
+
* @typeParam TUpdate - 更新输入类型(z.infer<typeof updateSchema>)
|
|
654
|
+
* @typeParam TSelect - 查询返回类型(InferSelectModel<typeof table>)
|
|
655
|
+
*/
|
|
656
|
+
type CrudHookEventMap<PluginId extends string, ResourceName extends string, TCreate, TUpdate, TSelect> = { [K in `${PluginId}.${ResourceName}.beforeCreate`]: TCreate } & { [K in `${PluginId}.${ResourceName}.afterCreate`]: TSelect } & { [K in `${PluginId}.${ResourceName}.beforeUpdate`]: {
|
|
657
|
+
id: string;
|
|
658
|
+
data: TUpdate;
|
|
659
|
+
} } & { [K in `${PluginId}.${ResourceName}.afterUpdate`]: TSelect } & { [K in `${PluginId}.${ResourceName}.beforeDelete`]: {
|
|
660
|
+
id: string;
|
|
661
|
+
} } & { [K in `${PluginId}.${ResourceName}.afterDelete`]: TSelect } & { [K in `${PluginId}.${ResourceName}.create`]: TCreate } & { [K in `${PluginId}.${ResourceName}.update`]: {
|
|
662
|
+
id: string;
|
|
663
|
+
data: TUpdate;
|
|
664
|
+
} } & { [K in `${PluginId}.${ResourceName}.delete`]: string } & { [K in `${PluginId}.${ResourceName}.deleteMany`]: string[] } & { [K in `${PluginId}.${ResourceName}.updateMany`]: {
|
|
665
|
+
ids: string[];
|
|
666
|
+
data: TUpdate;
|
|
667
|
+
} } & { [K in `${PluginId}.${ResourceName}.upsert`]: TCreate } & { [K in `${PluginId}.${ResourceName}.get`]: string } & { [K in `${PluginId}.${ResourceName}.list`]: {
|
|
668
|
+
page: number;
|
|
669
|
+
perPage: number;
|
|
670
|
+
sort?: Array<{
|
|
671
|
+
id: string;
|
|
672
|
+
desc: boolean;
|
|
673
|
+
}>;
|
|
674
|
+
filters?: Array<{
|
|
675
|
+
id: string;
|
|
676
|
+
value: string | string[];
|
|
677
|
+
variant: string;
|
|
678
|
+
operator: string;
|
|
679
|
+
filterId: string;
|
|
680
|
+
}>;
|
|
681
|
+
joinOperator: "and" | "or";
|
|
682
|
+
} } & { [K in `${PluginId}.${ResourceName}.export`]: {
|
|
683
|
+
sort?: Array<{
|
|
684
|
+
id: string;
|
|
685
|
+
desc: boolean;
|
|
686
|
+
}>;
|
|
687
|
+
filters?: Array<{
|
|
688
|
+
id: string;
|
|
689
|
+
value: string | string[];
|
|
690
|
+
variant: string;
|
|
691
|
+
operator: string;
|
|
692
|
+
filterId: string;
|
|
693
|
+
}>;
|
|
694
|
+
joinOperator?: "and" | "or";
|
|
695
|
+
limit?: number;
|
|
696
|
+
} } & { [K in `${PluginId}.${ResourceName}.import`]: {
|
|
697
|
+
rows: unknown[];
|
|
698
|
+
onConflict?: "skip" | "upsert" | "error";
|
|
699
|
+
} } & { [K in `${PluginId}.${ResourceName}.createMany`]: TCreate[] };
|
|
700
|
+
//#endregion
|
|
614
701
|
//#region src/routers/index.d.ts
|
|
615
|
-
declare const appRouter:
|
|
702
|
+
declare const appRouter: _trpc_server0.TRPCBuiltRouter<{
|
|
616
703
|
ctx: Context;
|
|
617
704
|
meta: object;
|
|
618
|
-
errorShape:
|
|
705
|
+
errorShape: _trpc_server0.TRPCDefaultErrorShape;
|
|
619
706
|
transformer: true;
|
|
620
|
-
},
|
|
707
|
+
}, _trpc_server0.TRPCDecorateCreateRouterOptions<{}>>;
|
|
621
708
|
type AppRouter = typeof appRouter;
|
|
622
709
|
//#endregion
|
|
623
|
-
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
|
710
|
+
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
package/dist/index.d.ts
CHANGED
|
@@ -612,6 +612,93 @@ type AnyMiddlewareParams<TContext> = {
|
|
|
612
612
|
*/
|
|
613
613
|
declare function composeMiddleware<TContext, TResult>(...middlewares: Array<(params: AnyMiddlewareParams<TContext>) => Promise<any>>): (params: AnyMiddlewareParams<TContext>) => Promise<TResult>;
|
|
614
614
|
//#endregion
|
|
615
|
+
//#region src/types/hook-types.d.ts
|
|
616
|
+
/**
|
|
617
|
+
* Hook 系统类型工具
|
|
618
|
+
*
|
|
619
|
+
* 提供 CrudHookEventMap 类型——从 Zod Schema / Drizzle Table 推导出
|
|
620
|
+
* auto-crud 相关的所有 Hook 事件类型。
|
|
621
|
+
*
|
|
622
|
+
* 下游插件通过 module augmentation 合并到全局 HookEventMap:
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* import type { CrudHookEventMap } from "@wordrhyme/auto-crud-server";
|
|
627
|
+
* import type { z } from "zod";
|
|
628
|
+
* import type { InferSelectModel } from "drizzle-orm";
|
|
629
|
+
*
|
|
630
|
+
* declare module "@wordrhyme/plugin" {
|
|
631
|
+
* interface HookEventMap extends CrudHookEventMap<
|
|
632
|
+
* "crm",
|
|
633
|
+
* "customers",
|
|
634
|
+
* z.infer<typeof createCustomerSchema>,
|
|
635
|
+
* z.infer<typeof updateCustomerSchema>,
|
|
636
|
+
* InferSelectModel<typeof customerTable>
|
|
637
|
+
* > {}
|
|
638
|
+
* }
|
|
639
|
+
*
|
|
640
|
+
* // 使用效果:
|
|
641
|
+
* // ctx.hooks.emit('crm.customers. ← IDE 自动补全所有 hook 名和 payload
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
/**
|
|
645
|
+
* 从 CRUD Schema 类型自动推导 Hook 事件映射
|
|
646
|
+
*
|
|
647
|
+
* 生成两类 hook:
|
|
648
|
+
* 1. 生命周期 hook(beforeCreate / afterCreate 等)— 由 tRPC middleware 自动 emit
|
|
649
|
+
* 2. Procedure hook(create / update / list 等)— 供 emit 自动映射 tRPC 路由使用
|
|
650
|
+
*
|
|
651
|
+
* @typeParam PluginId - 插件标识(如 'crm', 'shop')
|
|
652
|
+
* @typeParam ResourceName - 资源名称(如 'customers', 'products')
|
|
653
|
+
* @typeParam TCreate - 创建输入类型(z.infer<typeof createSchema>)
|
|
654
|
+
* @typeParam TUpdate - 更新输入类型(z.infer<typeof updateSchema>)
|
|
655
|
+
* @typeParam TSelect - 查询返回类型(InferSelectModel<typeof table>)
|
|
656
|
+
*/
|
|
657
|
+
type CrudHookEventMap<PluginId extends string, ResourceName extends string, TCreate, TUpdate, TSelect> = { [K in `${PluginId}.${ResourceName}.beforeCreate`]: TCreate } & { [K in `${PluginId}.${ResourceName}.afterCreate`]: TSelect } & { [K in `${PluginId}.${ResourceName}.beforeUpdate`]: {
|
|
658
|
+
id: string;
|
|
659
|
+
data: TUpdate;
|
|
660
|
+
} } & { [K in `${PluginId}.${ResourceName}.afterUpdate`]: TSelect } & { [K in `${PluginId}.${ResourceName}.beforeDelete`]: {
|
|
661
|
+
id: string;
|
|
662
|
+
} } & { [K in `${PluginId}.${ResourceName}.afterDelete`]: TSelect } & { [K in `${PluginId}.${ResourceName}.create`]: TCreate } & { [K in `${PluginId}.${ResourceName}.update`]: {
|
|
663
|
+
id: string;
|
|
664
|
+
data: TUpdate;
|
|
665
|
+
} } & { [K in `${PluginId}.${ResourceName}.delete`]: string } & { [K in `${PluginId}.${ResourceName}.deleteMany`]: string[] } & { [K in `${PluginId}.${ResourceName}.updateMany`]: {
|
|
666
|
+
ids: string[];
|
|
667
|
+
data: TUpdate;
|
|
668
|
+
} } & { [K in `${PluginId}.${ResourceName}.upsert`]: TCreate } & { [K in `${PluginId}.${ResourceName}.get`]: string } & { [K in `${PluginId}.${ResourceName}.list`]: {
|
|
669
|
+
page: number;
|
|
670
|
+
perPage: number;
|
|
671
|
+
sort?: Array<{
|
|
672
|
+
id: string;
|
|
673
|
+
desc: boolean;
|
|
674
|
+
}>;
|
|
675
|
+
filters?: Array<{
|
|
676
|
+
id: string;
|
|
677
|
+
value: string | string[];
|
|
678
|
+
variant: string;
|
|
679
|
+
operator: string;
|
|
680
|
+
filterId: string;
|
|
681
|
+
}>;
|
|
682
|
+
joinOperator: "and" | "or";
|
|
683
|
+
} } & { [K in `${PluginId}.${ResourceName}.export`]: {
|
|
684
|
+
sort?: Array<{
|
|
685
|
+
id: string;
|
|
686
|
+
desc: boolean;
|
|
687
|
+
}>;
|
|
688
|
+
filters?: Array<{
|
|
689
|
+
id: string;
|
|
690
|
+
value: string | string[];
|
|
691
|
+
variant: string;
|
|
692
|
+
operator: string;
|
|
693
|
+
filterId: string;
|
|
694
|
+
}>;
|
|
695
|
+
joinOperator?: "and" | "or";
|
|
696
|
+
limit?: number;
|
|
697
|
+
} } & { [K in `${PluginId}.${ResourceName}.import`]: {
|
|
698
|
+
rows: unknown[];
|
|
699
|
+
onConflict?: "skip" | "upsert" | "error";
|
|
700
|
+
} } & { [K in `${PluginId}.${ResourceName}.createMany`]: TCreate[] };
|
|
701
|
+
//#endregion
|
|
615
702
|
//#region src/routers/index.d.ts
|
|
616
703
|
declare const appRouter: _trpc_server0.TRPCBuiltRouter<{
|
|
617
704
|
ctx: Context;
|
|
@@ -621,4 +708,4 @@ declare const appRouter: _trpc_server0.TRPCBuiltRouter<{
|
|
|
621
708
|
}, _trpc_server0.TRPCDecorateCreateRouterOptions<{}>>;
|
|
622
709
|
type AppRouter = typeof appRouter;
|
|
623
710
|
//#endregion
|
|
624
|
-
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
|
711
|
+
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"description": "tRPC server utilities for auto-crud - automatic CRUD routers for Drizzle ORM",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"vitest": "^4.0.18",
|
|
49
49
|
"zod": "^4.1.13",
|
|
50
50
|
"@internal/eslint-config": "0.3.0",
|
|
51
|
-
"@internal/prettier-config": "0.0.1",
|
|
52
51
|
"@internal/tsconfig": "0.1.0",
|
|
53
52
|
"@internal/tsdown-config": "0.1.0",
|
|
53
|
+
"@internal/prettier-config": "0.0.1",
|
|
54
54
|
"@internal/vitest-config": "0.1.0"
|
|
55
55
|
},
|
|
56
56
|
"prettier": "@internal/prettier-config",
|