@wordrhyme/auto-crud-server 2.0.0 → 2.0.2

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 CHANGED
@@ -1270,15 +1270,15 @@ DATABASE_URL = 'postgresql://user:password@localhost:5432/dbname';
1270
1270
 
1271
1271
  ## 📄 许可证
1272
1272
 
1273
- MIT © [wordrhyme](https://github.com/pixpilot/shadcn-components)
1273
+ MIT © [wordrhyme](https://github.com/denvey/wordrhyme-components)
1274
1274
 
1275
1275
  ---
1276
1276
 
1277
1277
  ## 🔗 相关链接
1278
1278
 
1279
- - [GitHub](https://github.com/pixpilot/shadcn-components)
1280
- - [文档](https://github.com/pixpilot/shadcn-components/tree/main/packages/auto-crud-server)
1281
- - [@wordrhyme/auto-crud](https://github.com/pixpilot/shadcn-components/tree/main/packages/auto-crud) - 前端组件库
1279
+ - [GitHub](https://github.com/denvey/wordrhyme-components)
1280
+ - [文档](https://github.com/denvey/wordrhyme-components/tree/main/packages/auto-crud-server)
1281
+ - [@wordrhyme/auto-crud](https://github.com/denvey/wordrhyme-components/tree/main/packages/auto-crud) - 前端组件库
1282
1282
  - [Changelog](./CHANGELOG.md)
1283
1283
 
1284
1284
  ---
package/dist/index.cjs CHANGED
@@ -872,9 +872,15 @@ function splitCrudExtensionWriteInput(inputData, tableColumnNames) {
872
872
  baseValues: {},
873
873
  extraValues: null
874
874
  };
875
+ const rawValues = { ...inputData };
876
+ delete rawValues.__crudExtensionProjection;
877
+ if (isObjectRecord(rawValues.ext)) {
878
+ rawValues.ext = { ...rawValues.ext };
879
+ delete rawValues.ext.__crudExtensionProjection;
880
+ }
875
881
  const baseValues = {};
876
882
  const extraValues = {};
877
- for (const [key, value] of Object.entries(inputData)) {
883
+ for (const [key, value] of Object.entries(rawValues)) {
878
884
  if (key === "ext") {
879
885
  if (isObjectRecord(value)) Object.assign(extraValues, value);
880
886
  continue;
@@ -884,7 +890,7 @@ function splitCrudExtensionWriteInput(inputData, tableColumnNames) {
884
890
  }
885
891
  return {
886
892
  data: baseValues,
887
- rawValues: inputData,
893
+ rawValues,
888
894
  baseValues,
889
895
  extraValues: Object.keys(extraValues).length > 0 ? extraValues : null
890
896
  };
@@ -1019,6 +1025,10 @@ async function enrichCrudRows(ctx, config, idField, rows) {
1019
1025
  if (!projected || Object.keys(projected).length === 0) return row;
1020
1026
  return {
1021
1027
  ...row,
1028
+ __crudExtensionProjection: Object.fromEntries(Object.entries(projected).flatMap(([field, value]) => isObjectRecord(value) && (value.type === "ref" || typeof value.type !== "string" && "refId" in value) ? [[field, {
1029
+ refId: readProjectionValue(value) ?? null,
1030
+ display: typeof value.display === "string" ? value.display : null
1031
+ }]] : [])),
1022
1032
  ...Object.fromEntries(Object.entries(projected).map(([field, value]) => [field, readProjectionValue(value)]))
1023
1033
  };
1024
1034
  });
package/dist/index.d.cts CHANGED
@@ -231,7 +231,10 @@ interface CrudExtensionsProvider {
231
231
  * Otherwise list/get/export return a defined refId (including null), then
232
232
  * value when present. Providers should put editable values in value, including
233
233
  * ID arrays for multi-reference fields. display is a legacy fallback only when
234
- * no raw value exists; consumers resolve labels through their data sources.
234
+ * no raw value exists. Envelopes with type "ref" or a legacy untyped refId
235
+ * also expose the resolved raw ID and display in
236
+ * __crudExtensionProjection on each row, allowing consumers to show the
237
+ * existing reference label without requiring access to the target's search API.
235
238
  */
236
239
  readProjection?: (input: {
237
240
  id: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as _trpc_server2 from "@trpc/server";
1
+ import * as _trpc_server0 from "@trpc/server";
2
2
  import { AnyColumn, SQL, Table } from "drizzle-orm";
3
3
  import { z } from "zod";
4
4
  import superjson from "superjson";
@@ -41,13 +41,13 @@ interface Context {
41
41
  db: PostgresJsDatabase<Record<string, never>>;
42
42
  resolveDateRange?: DateRangeResolver;
43
43
  }
44
- declare const router: _trpc_server2.TRPCRouterBuilder<{
44
+ declare const router: _trpc_server0.TRPCRouterBuilder<{
45
45
  ctx: Context;
46
46
  meta: object;
47
- errorShape: _trpc_server2.TRPCDefaultErrorShape;
47
+ errorShape: _trpc_server0.TRPCDefaultErrorShape;
48
48
  transformer: true;
49
49
  }>;
50
- declare const publicProcedure: _trpc_server2.TRPCProcedureBuilder<Context, object, object, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, false>;
50
+ declare const publicProcedure: _trpc_server0.TRPCProcedureBuilder<Context, object, object, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, false>;
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';
@@ -232,7 +232,10 @@ interface CrudExtensionsProvider {
232
232
  * Otherwise list/get/export return a defined refId (including null), then
233
233
  * value when present. Providers should put editable values in value, including
234
234
  * ID arrays for multi-reference fields. display is a legacy fallback only when
235
- * no raw value exists; consumers resolve labels through their data sources.
235
+ * no raw value exists. Envelopes with type "ref" or a legacy untyped refId
236
+ * also expose the resolved raw ID and display in
237
+ * __crudExtensionProjection on each row, allowing consumers to show the
238
+ * existing reference label without requiring access to the target's search API.
236
239
  */
237
240
  readProjection?: (input: {
238
241
  id: string;
@@ -1019,12 +1022,12 @@ type CrudHookEventMap<PluginId extends string, ResourceName extends string, TCre
1019
1022
  } } & { [K in `${PluginId}.${ResourceName}.createMany`]: TCreate[] };
1020
1023
  //#endregion
1021
1024
  //#region src/routers/index.d.ts
1022
- declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
1025
+ declare const appRouter: _trpc_server0.TRPCBuiltRouter<{
1023
1026
  ctx: Context;
1024
1027
  meta: object;
1025
- errorShape: _trpc_server2.TRPCDefaultErrorShape;
1028
+ errorShape: _trpc_server0.TRPCDefaultErrorShape;
1026
1029
  transformer: true;
1027
- }, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
1030
+ }, _trpc_server0.TRPCDecorateCreateRouterOptions<{}>>;
1028
1031
  type AppRouter = typeof appRouter;
1029
1032
  //#endregion
1030
1033
  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
@@ -841,9 +841,15 @@ function splitCrudExtensionWriteInput(inputData, tableColumnNames) {
841
841
  baseValues: {},
842
842
  extraValues: null
843
843
  };
844
+ const rawValues = { ...inputData };
845
+ delete rawValues.__crudExtensionProjection;
846
+ if (isObjectRecord(rawValues.ext)) {
847
+ rawValues.ext = { ...rawValues.ext };
848
+ delete rawValues.ext.__crudExtensionProjection;
849
+ }
844
850
  const baseValues = {};
845
851
  const extraValues = {};
846
- for (const [key, value] of Object.entries(inputData)) {
852
+ for (const [key, value] of Object.entries(rawValues)) {
847
853
  if (key === "ext") {
848
854
  if (isObjectRecord(value)) Object.assign(extraValues, value);
849
855
  continue;
@@ -853,7 +859,7 @@ function splitCrudExtensionWriteInput(inputData, tableColumnNames) {
853
859
  }
854
860
  return {
855
861
  data: baseValues,
856
- rawValues: inputData,
862
+ rawValues,
857
863
  baseValues,
858
864
  extraValues: Object.keys(extraValues).length > 0 ? extraValues : null
859
865
  };
@@ -988,6 +994,10 @@ async function enrichCrudRows(ctx, config, idField, rows) {
988
994
  if (!projected || Object.keys(projected).length === 0) return row;
989
995
  return {
990
996
  ...row,
997
+ __crudExtensionProjection: Object.fromEntries(Object.entries(projected).flatMap(([field, value]) => isObjectRecord(value) && (value.type === "ref" || typeof value.type !== "string" && "refId" in value) ? [[field, {
998
+ refId: readProjectionValue(value) ?? null,
999
+ display: typeof value.display === "string" ? value.display : null
1000
+ }]] : [])),
991
1001
  ...Object.fromEntries(Object.entries(projected).map(([field, value]) => [field, readProjectionValue(value)]))
992
1002
  };
993
1003
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wordrhyme/auto-crud-server",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "description": "tRPC server utilities for auto-crud - automatic CRUD routers for Drizzle ORM",
6
6
  "author": "wordrhyme",
7
7
  "license": "MIT",
@@ -48,10 +48,10 @@
48
48
  "typescript": "^5.9.3",
49
49
  "vitest": "^4.0.18",
50
50
  "zod": "^4.3.6",
51
+ "@internal/eslint-config": "0.3.0",
51
52
  "@internal/prettier-config": "0.0.1",
52
53
  "@internal/tsconfig": "0.1.0",
53
54
  "@internal/tsdown-config": "0.1.0",
54
- "@internal/eslint-config": "0.3.0",
55
55
  "@internal/vitest-config": "0.1.0"
56
56
  },
57
57
  "prettier": "@internal/prettier-config",