@wordrhyme/auto-crud-server 2.0.0 → 2.0.1

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 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
@@ -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;
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.1",
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/prettier-config": "0.0.1",
52
- "@internal/tsconfig": "0.1.0",
53
- "@internal/tsdown-config": "0.1.0",
54
51
  "@internal/eslint-config": "0.3.0",
55
- "@internal/vitest-config": "0.1.0"
52
+ "@internal/tsconfig": "0.1.0",
53
+ "@internal/prettier-config": "0.0.1",
54
+ "@internal/vitest-config": "0.1.0",
55
+ "@internal/tsdown-config": "0.1.0"
56
56
  },
57
57
  "prettier": "@internal/prettier-config",
58
58
  "scripts": {