cogsbox-shape 0.5.188 → 0.5.189

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.
@@ -36,6 +36,7 @@ export declare class TableDB<TClient extends Record<string, unknown>, TCreate, T
36
36
  private missingDeriveDependencies;
37
37
  private fetchClientFieldsById;
38
38
  private pickDbPatchFields;
39
+ private isWritableDbColumn;
39
40
  private parseDbOnlyData;
40
41
  reconcileIds(clientData: unknown, ids: unknown): unknown;
41
42
  private reconcileFlatIds;
@@ -82,7 +82,7 @@ export class TableDB {
82
82
  }));
83
83
  const insertData = {};
84
84
  for (const key of Object.keys(dbData)) {
85
- if (!pkDbNames.has(key)) {
85
+ if (!pkDbNames.has(key) && this.isWritableDbColumn(key)) {
86
86
  insertData[key] = dbData[key];
87
87
  }
88
88
  }
@@ -200,13 +200,22 @@ export class TableDB {
200
200
  pickDbPatchFields(dbData, clientKeys) {
201
201
  const picked = {};
202
202
  for (const clientKey of clientKeys) {
203
- const dbName = this.meta.clientToDbName.get(clientKey) ?? clientKey;
203
+ const dbName = this.meta.clientToDbName.get(clientKey);
204
+ if (!dbName)
205
+ continue;
204
206
  if (dbData[dbName] !== undefined) {
205
207
  picked[dbName] = dbData[dbName];
206
208
  }
207
209
  }
208
210
  return picked;
209
211
  }
212
+ isWritableDbColumn(dbName) {
213
+ for (const field of this.meta.dbFields.values()) {
214
+ if (field.dbName === dbName)
215
+ return true;
216
+ }
217
+ return false;
218
+ }
210
219
  parseDbOnlyData(dbOnlyData, opts = { requireRequired: false }) {
211
220
  if (opts.requireRequired) {
212
221
  for (const requiredKey of this.meta.sqlOnlyRequiredClientFields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.188",
3
+ "version": "0.5.189",
4
4
  "description": "A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for relationships and serialization.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",