|
1 | | -import { enumerate, invariant, isPlainObject } from '@zenstackhq/common-helpers'; |
| 1 | +import { enumerate, invariant, isPlainObject, lowerCaseFirst } from '@zenstackhq/common-helpers'; |
2 | 2 | import type { AliasableExpression, Expression, ExpressionBuilder, ExpressionWrapper, SqlBool, ValueNode } from 'kysely'; |
3 | 3 | import { expressionBuilder, sql, type SelectQueryBuilder } from 'kysely'; |
4 | 4 | import { match, P } from 'ts-pattern'; |
@@ -1160,12 +1160,12 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> { |
1160 | 1160 | return (omit as any)[field]; |
1161 | 1161 | } |
1162 | 1162 |
|
1163 | | - if ( |
1164 | | - this.options.omit?.[model] && |
1165 | | - typeof this.options.omit[model] === 'object' && |
1166 | | - typeof (this.options.omit[model] as any)[field] === 'boolean' |
1167 | | - ) { |
1168 | | - return (this.options.omit[model] as any)[field]; |
| 1163 | + // client-level: check both uncapitalized (current) and original (backward compat) model name |
| 1164 | + const uncapModel = lowerCaseFirst(model); |
| 1165 | + const omitConfig = (this.options.omit as Record<string, any> | undefined)?.[uncapModel] ?? |
| 1166 | + (this.options.omit as Record<string, any> | undefined)?.[model]; |
| 1167 | + if (omitConfig && typeof omitConfig === 'object' && typeof omitConfig[field] === 'boolean') { |
| 1168 | + return omitConfig[field]; |
1169 | 1169 | } |
1170 | 1170 |
|
1171 | 1171 | // schema-level |
@@ -1355,7 +1355,9 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> { |
1355 | 1355 | let computer: Function | undefined; |
1356 | 1356 | if ('computedFields' in this.options) { |
1357 | 1357 | const computedFields = this.options.computedFields as Record<string, any>; |
1358 | | - computer = computedFields?.[fieldDef.originModel ?? model]?.[field]; |
| 1358 | + // check both uncapitalized (current) and original (backward compat) model name |
| 1359 | + const computedModel = fieldDef.originModel ?? model; |
| 1360 | + computer = computedFields?.[lowerCaseFirst(computedModel)]?.[field] ?? computedFields?.[computedModel]?.[field]; |
1359 | 1361 | } |
1360 | 1362 | if (!computer) { |
1361 | 1363 | throw createConfigError(`Computed field "${field}" implementation not provided for model "${model}"`); |
|
0 commit comments