@wordrhyme/auto-crud-server 1.0.7 → 1.0.9
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 +323 -49
- package/dist/index.d.cts +76 -8
- package/dist/index.d.ts +69 -1
- package/dist/index.js +324 -50
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _trpc_server2 from "@trpc/server";
|
|
4
4
|
import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
5
5
|
import { AnyColumn, SQL } from "drizzle-orm";
|
|
6
6
|
|
|
@@ -12,13 +12,13 @@ import { AnyColumn, SQL } from "drizzle-orm";
|
|
|
12
12
|
interface Context {
|
|
13
13
|
db: PostgresJsDatabase<Record<string, never>>;
|
|
14
14
|
}
|
|
15
|
-
declare const router:
|
|
15
|
+
declare const router: _trpc_server2.TRPCRouterBuilder<{
|
|
16
16
|
ctx: Context;
|
|
17
17
|
meta: object;
|
|
18
|
-
errorShape:
|
|
18
|
+
errorShape: _trpc_server2.TRPCDefaultErrorShape;
|
|
19
19
|
transformer: true;
|
|
20
20
|
}>;
|
|
21
|
-
declare const publicProcedure:
|
|
21
|
+
declare const publicProcedure: _trpc_server2.TRPCProcedureBuilder<Context, object, object, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.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';
|
|
@@ -81,6 +81,7 @@ interface ListInput {
|
|
|
81
81
|
id: string;
|
|
82
82
|
desc: boolean;
|
|
83
83
|
}>;
|
|
84
|
+
search?: string;
|
|
84
85
|
filters?: Array<{
|
|
85
86
|
id: string;
|
|
86
87
|
value: string | string[];
|
|
@@ -116,6 +117,7 @@ interface ExportInput {
|
|
|
116
117
|
id: string;
|
|
117
118
|
desc: boolean;
|
|
118
119
|
}>;
|
|
120
|
+
search?: string;
|
|
119
121
|
filters?: Array<{
|
|
120
122
|
id: string;
|
|
121
123
|
value: string | string[];
|
|
@@ -127,6 +129,48 @@ interface ExportInput {
|
|
|
127
129
|
/** 导出数量限制,会被 clamp 到 [1, maxExportSize] */
|
|
128
130
|
limit?: number;
|
|
129
131
|
}
|
|
132
|
+
interface CrudExtensionMetadata {
|
|
133
|
+
schema?: unknown;
|
|
134
|
+
fields?: Record<string, unknown>;
|
|
135
|
+
errors?: string[];
|
|
136
|
+
}
|
|
137
|
+
interface CrudExtensionFilter {
|
|
138
|
+
id: string;
|
|
139
|
+
value: string | string[];
|
|
140
|
+
variant: string;
|
|
141
|
+
operator: string;
|
|
142
|
+
filterId?: string | undefined;
|
|
143
|
+
}
|
|
144
|
+
interface CrudExtensionsProvider {
|
|
145
|
+
getMetadata?: (input: {
|
|
146
|
+
id: string;
|
|
147
|
+
}) => Promise<CrudExtensionMetadata>;
|
|
148
|
+
saveExtraValues?: (input: {
|
|
149
|
+
id: string;
|
|
150
|
+
entityId: string;
|
|
151
|
+
rawValues: Record<string, unknown>;
|
|
152
|
+
baseValues: Record<string, unknown>;
|
|
153
|
+
extraValues: Record<string, unknown>;
|
|
154
|
+
tx?: unknown;
|
|
155
|
+
}) => Promise<void>;
|
|
156
|
+
readProjection?: (input: {
|
|
157
|
+
id: string;
|
|
158
|
+
entityIds: string[];
|
|
159
|
+
fields?: string[];
|
|
160
|
+
}) => Promise<Record<string, Record<string, unknown>>>;
|
|
161
|
+
matchEntityIds?: (input: {
|
|
162
|
+
id: string;
|
|
163
|
+
filters: CrudExtensionFilter[];
|
|
164
|
+
joinOperator?: 'and' | 'or';
|
|
165
|
+
limit?: number;
|
|
166
|
+
}) => Promise<string[]>;
|
|
167
|
+
searchEntityIds?: (input: {
|
|
168
|
+
id: string;
|
|
169
|
+
search: string;
|
|
170
|
+
limit?: number;
|
|
171
|
+
}) => Promise<string[]>;
|
|
172
|
+
}
|
|
173
|
+
type CrudExtensionsConfig<TContext = unknown> = false | CrudExtensionsProvider | ((ctx: TContext) => CrudExtensionsProvider | null | undefined);
|
|
130
174
|
/**
|
|
131
175
|
* 导出查询结果类型
|
|
132
176
|
*/
|
|
@@ -334,6 +378,7 @@ interface CrudMiddleware<TContext = unknown, TSelect = unknown, TInsert = unknow
|
|
|
334
378
|
* 按操作指定不同的 procedure,支持 default 回退
|
|
335
379
|
*/
|
|
336
380
|
interface ProcedureMap {
|
|
381
|
+
meta?: AnyProcedure;
|
|
337
382
|
list?: AnyProcedure;
|
|
338
383
|
get?: AnyProcedure;
|
|
339
384
|
create?: AnyProcedure;
|
|
@@ -414,6 +459,26 @@ type ProcedureConfig = AnyProcedure | ProcedureMap | ProcedureFactory;
|
|
|
414
459
|
interface CrudRouterConfig<TTable extends PgTable = PgTable, TContext = unknown, TSelect = unknown, TInsert = unknown, TUpdate = unknown, TListInput extends ListInput = ListInput, TGetInput extends GetInput = GetInput, TExportInput extends ExportInput = ExportInput> {
|
|
415
460
|
/** Drizzle 表定义 */
|
|
416
461
|
table: TTable;
|
|
462
|
+
/**
|
|
463
|
+
* Globally unique extension target id for this CRUD.
|
|
464
|
+
*
|
|
465
|
+
* Optional. Only consumers that enable entity extension fields need this.
|
|
466
|
+
* CRUDs without an explicit id keep the normal AutoCrud behavior and ignore
|
|
467
|
+
* field extensions.
|
|
468
|
+
*
|
|
469
|
+
* Example: "com.example.shop.stores".
|
|
470
|
+
*/
|
|
471
|
+
id?: string;
|
|
472
|
+
/**
|
|
473
|
+
* Optional dynamic field provider.
|
|
474
|
+
*
|
|
475
|
+
* - undefined: when `id` is present, `createCrudRouter` will use
|
|
476
|
+
* `ctx.crudExtensions` if the request context provides it.
|
|
477
|
+
* - false: disable dynamic fields for this CRUD even if the context has a
|
|
478
|
+
* provider.
|
|
479
|
+
* - provider/function: explicitly use this provider.
|
|
480
|
+
*/
|
|
481
|
+
extensions?: CrudExtensionsConfig<TContext>;
|
|
417
482
|
/**
|
|
418
483
|
* 主 Schema(用于 create/upsert 输入验证)
|
|
419
484
|
* - 如果不传,自动从 table 派生并排除 omitFields
|
|
@@ -597,6 +662,7 @@ interface CrudRouterConfig<TTable extends PgTable = PgTable, TContext = unknown,
|
|
|
597
662
|
middleware?: CrudMiddleware<TContext, TSelect, TInsert, TUpdate, TListInput, TGetInput, TExportInput>;
|
|
598
663
|
}
|
|
599
664
|
interface CrudProcedures {
|
|
665
|
+
meta: AnyProcedure;
|
|
600
666
|
list: AnyProcedure;
|
|
601
667
|
get: AnyProcedure;
|
|
602
668
|
create: AnyProcedure;
|
|
@@ -625,6 +691,7 @@ declare const baseListInputSchema: z.ZodObject<{
|
|
|
625
691
|
id: z.ZodString;
|
|
626
692
|
desc: z.ZodBoolean;
|
|
627
693
|
}, z.core.$strip>>>;
|
|
694
|
+
search: z.ZodOptional<z.ZodString>;
|
|
628
695
|
filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
629
696
|
id: z.ZodString;
|
|
630
697
|
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
@@ -669,6 +736,7 @@ declare const baseExportInputSchema: z.ZodObject<{
|
|
|
669
736
|
id: z.ZodString;
|
|
670
737
|
desc: z.ZodBoolean;
|
|
671
738
|
}, z.core.$strip>>>;
|
|
739
|
+
search: z.ZodOptional<z.ZodString>;
|
|
672
740
|
filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
673
741
|
id: z.ZodString;
|
|
674
742
|
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
@@ -811,12 +879,12 @@ type CrudHookEventMap<PluginId extends string, ResourceName extends string, TCre
|
|
|
811
879
|
} } & { [K in `${PluginId}.${ResourceName}.createMany`]: TCreate[] };
|
|
812
880
|
//#endregion
|
|
813
881
|
//#region src/routers/index.d.ts
|
|
814
|
-
declare const appRouter:
|
|
882
|
+
declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
|
|
815
883
|
ctx: Context;
|
|
816
884
|
meta: object;
|
|
817
|
-
errorShape:
|
|
885
|
+
errorShape: _trpc_server2.TRPCDefaultErrorShape;
|
|
818
886
|
transformer: true;
|
|
819
|
-
},
|
|
887
|
+
}, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
|
|
820
888
|
type AppRouter = typeof appRouter;
|
|
821
889
|
//#endregion
|
|
822
|
-
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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 };
|
|
890
|
+
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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
|
@@ -82,6 +82,7 @@ interface ListInput {
|
|
|
82
82
|
id: string;
|
|
83
83
|
desc: boolean;
|
|
84
84
|
}>;
|
|
85
|
+
search?: string;
|
|
85
86
|
filters?: Array<{
|
|
86
87
|
id: string;
|
|
87
88
|
value: string | string[];
|
|
@@ -117,6 +118,7 @@ interface ExportInput {
|
|
|
117
118
|
id: string;
|
|
118
119
|
desc: boolean;
|
|
119
120
|
}>;
|
|
121
|
+
search?: string;
|
|
120
122
|
filters?: Array<{
|
|
121
123
|
id: string;
|
|
122
124
|
value: string | string[];
|
|
@@ -128,6 +130,48 @@ interface ExportInput {
|
|
|
128
130
|
/** 导出数量限制,会被 clamp 到 [1, maxExportSize] */
|
|
129
131
|
limit?: number;
|
|
130
132
|
}
|
|
133
|
+
interface CrudExtensionMetadata {
|
|
134
|
+
schema?: unknown;
|
|
135
|
+
fields?: Record<string, unknown>;
|
|
136
|
+
errors?: string[];
|
|
137
|
+
}
|
|
138
|
+
interface CrudExtensionFilter {
|
|
139
|
+
id: string;
|
|
140
|
+
value: string | string[];
|
|
141
|
+
variant: string;
|
|
142
|
+
operator: string;
|
|
143
|
+
filterId?: string | undefined;
|
|
144
|
+
}
|
|
145
|
+
interface CrudExtensionsProvider {
|
|
146
|
+
getMetadata?: (input: {
|
|
147
|
+
id: string;
|
|
148
|
+
}) => Promise<CrudExtensionMetadata>;
|
|
149
|
+
saveExtraValues?: (input: {
|
|
150
|
+
id: string;
|
|
151
|
+
entityId: string;
|
|
152
|
+
rawValues: Record<string, unknown>;
|
|
153
|
+
baseValues: Record<string, unknown>;
|
|
154
|
+
extraValues: Record<string, unknown>;
|
|
155
|
+
tx?: unknown;
|
|
156
|
+
}) => Promise<void>;
|
|
157
|
+
readProjection?: (input: {
|
|
158
|
+
id: string;
|
|
159
|
+
entityIds: string[];
|
|
160
|
+
fields?: string[];
|
|
161
|
+
}) => Promise<Record<string, Record<string, unknown>>>;
|
|
162
|
+
matchEntityIds?: (input: {
|
|
163
|
+
id: string;
|
|
164
|
+
filters: CrudExtensionFilter[];
|
|
165
|
+
joinOperator?: 'and' | 'or';
|
|
166
|
+
limit?: number;
|
|
167
|
+
}) => Promise<string[]>;
|
|
168
|
+
searchEntityIds?: (input: {
|
|
169
|
+
id: string;
|
|
170
|
+
search: string;
|
|
171
|
+
limit?: number;
|
|
172
|
+
}) => Promise<string[]>;
|
|
173
|
+
}
|
|
174
|
+
type CrudExtensionsConfig<TContext = unknown> = false | CrudExtensionsProvider | ((ctx: TContext) => CrudExtensionsProvider | null | undefined);
|
|
131
175
|
/**
|
|
132
176
|
* 导出查询结果类型
|
|
133
177
|
*/
|
|
@@ -335,6 +379,7 @@ interface CrudMiddleware<TContext = unknown, TSelect = unknown, TInsert = unknow
|
|
|
335
379
|
* 按操作指定不同的 procedure,支持 default 回退
|
|
336
380
|
*/
|
|
337
381
|
interface ProcedureMap {
|
|
382
|
+
meta?: AnyProcedure;
|
|
338
383
|
list?: AnyProcedure;
|
|
339
384
|
get?: AnyProcedure;
|
|
340
385
|
create?: AnyProcedure;
|
|
@@ -415,6 +460,26 @@ type ProcedureConfig = AnyProcedure | ProcedureMap | ProcedureFactory;
|
|
|
415
460
|
interface CrudRouterConfig<TTable extends PgTable = PgTable, TContext = unknown, TSelect = unknown, TInsert = unknown, TUpdate = unknown, TListInput extends ListInput = ListInput, TGetInput extends GetInput = GetInput, TExportInput extends ExportInput = ExportInput> {
|
|
416
461
|
/** Drizzle 表定义 */
|
|
417
462
|
table: TTable;
|
|
463
|
+
/**
|
|
464
|
+
* Globally unique extension target id for this CRUD.
|
|
465
|
+
*
|
|
466
|
+
* Optional. Only consumers that enable entity extension fields need this.
|
|
467
|
+
* CRUDs without an explicit id keep the normal AutoCrud behavior and ignore
|
|
468
|
+
* field extensions.
|
|
469
|
+
*
|
|
470
|
+
* Example: "com.example.shop.stores".
|
|
471
|
+
*/
|
|
472
|
+
id?: string;
|
|
473
|
+
/**
|
|
474
|
+
* Optional dynamic field provider.
|
|
475
|
+
*
|
|
476
|
+
* - undefined: when `id` is present, `createCrudRouter` will use
|
|
477
|
+
* `ctx.crudExtensions` if the request context provides it.
|
|
478
|
+
* - false: disable dynamic fields for this CRUD even if the context has a
|
|
479
|
+
* provider.
|
|
480
|
+
* - provider/function: explicitly use this provider.
|
|
481
|
+
*/
|
|
482
|
+
extensions?: CrudExtensionsConfig<TContext>;
|
|
418
483
|
/**
|
|
419
484
|
* 主 Schema(用于 create/upsert 输入验证)
|
|
420
485
|
* - 如果不传,自动从 table 派生并排除 omitFields
|
|
@@ -598,6 +663,7 @@ interface CrudRouterConfig<TTable extends PgTable = PgTable, TContext = unknown,
|
|
|
598
663
|
middleware?: CrudMiddleware<TContext, TSelect, TInsert, TUpdate, TListInput, TGetInput, TExportInput>;
|
|
599
664
|
}
|
|
600
665
|
interface CrudProcedures {
|
|
666
|
+
meta: AnyProcedure;
|
|
601
667
|
list: AnyProcedure;
|
|
602
668
|
get: AnyProcedure;
|
|
603
669
|
create: AnyProcedure;
|
|
@@ -626,6 +692,7 @@ declare const baseListInputSchema: z.ZodObject<{
|
|
|
626
692
|
id: z.ZodString;
|
|
627
693
|
desc: z.ZodBoolean;
|
|
628
694
|
}, z.core.$strip>>>;
|
|
695
|
+
search: z.ZodOptional<z.ZodString>;
|
|
629
696
|
filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
630
697
|
id: z.ZodString;
|
|
631
698
|
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
@@ -670,6 +737,7 @@ declare const baseExportInputSchema: z.ZodObject<{
|
|
|
670
737
|
id: z.ZodString;
|
|
671
738
|
desc: z.ZodBoolean;
|
|
672
739
|
}, z.core.$strip>>>;
|
|
740
|
+
search: z.ZodOptional<z.ZodString>;
|
|
673
741
|
filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
674
742
|
id: z.ZodString;
|
|
675
743
|
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
@@ -820,4 +888,4 @@ declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
|
|
|
820
888
|
}, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
|
|
821
889
|
type AppRouter = typeof appRouter;
|
|
822
890
|
//#endregion
|
|
823
|
-
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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 };
|
|
891
|
+
export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, 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 };
|