vona-module-a-orm 5.0.89 → 5.0.91

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.
@@ -13,7 +13,7 @@ export default async function (options: IMetadataCustomGenerateOptions): Promise
13
13
  const tableName = __parseTableName(fileContent);
14
14
  contentColumns.push(`export type ${className}TableName = '${tableName}';`);
15
15
  contentEntityMetas.push(`export type ${className}Meta=TypeEntityMeta<${className},${className}TableName>;`);
16
- const contentRecordItem = `'${tableName}': never;`;
16
+ const contentRecordItem = `'${tableName}': ${className}Meta;`;
17
17
  if (!contentRecords.includes(contentRecordItem)) {
18
18
  contentRecords.push(contentRecordItem);
19
19
  }
package/dist/index.js CHANGED
@@ -3,12 +3,12 @@ import { BeanInfo, BeanAopMethodBase, BeanBase, deepExtend, appResource, beanFul
3
3
  import { AopMethod } from 'vona-module-a-aspect';
4
4
  import { Service, Bean, Scope } from 'vona-module-a-bean';
5
5
  import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
6
- import { isNil, catchError, safeBoolean, isClass, ensureArray, hashkey } from '@cabloy/utils';
6
+ import { isNil, catchError, safeBoolean, ensureArray, hashkey } from '@cabloy/utils';
7
7
  import knex from 'knex';
8
8
  import { BeanMutateBase } from 'vona-module-a-beanmutate';
9
9
  import { swapDeps } from '@cabloy/deps';
10
- import { prepareClassType, getTargetDecoratorRules, getTargetDecoratorRuleColumnsMap, Api, v, OrderMaxBase, OrderCoreBase, getSchemaDynamic, SymbolSchemaDynamicRefId, addSchemaDynamic, mergeFieldsOpenapiMetadata } from 'vona-module-a-openapiutils';
11
- import { ZodMetadata } from '@cabloy/zod-openapi';
10
+ import { $tableNameFromEntity, $tableDefaults, $columnsAll } from 'vona-module-a-ormutils';
11
+ import { prepareClassType, Api, v, OrderMaxBase, OrderCoreBase, getSchemaDynamic, SymbolSchemaDynamicRefId, addSchemaDynamic, mergeFieldsOpenapiMetadata } from 'vona-module-a-openapiutils';
12
12
  import z from 'zod';
13
13
  import { parseFirstWord, toLowerCaseFirstChar } from '@cabloy/word-utils';
14
14
  import { Broadcast, BeanBroadcastBase } from 'vona-module-a-broadcast';
@@ -679,7 +679,7 @@ let ServiceDatabaseClient = (_dec$l = Service(), _dec2$l = BeanInfo({
679
679
  // config: inited by bean.database.getClient
680
680
  this.clientConfig = clientConfig;
681
681
  // knex
682
- this._knex = knex(this.clientConfig);
682
+ this._knex = knex(deepExtend({}, this.clientConfig));
683
683
  }
684
684
  async __close() {
685
685
  if (this._knex) {
@@ -1148,11 +1148,11 @@ function _buildWhereColumnOpNormal(having, db, builder, column, value, op) {
1148
1148
  } else if (op === Op.notBetween) {
1149
1149
  builder[having ? 'havingNotBetween' : 'whereNotBetween'](column, value);
1150
1150
  } else if (op === Op.startsWith) {
1151
- builder[having ? 'havingLike' : 'whereLike'](column, `${value}%`);
1151
+ builder[_getOpLikeReal(having, db)](column, `${value}%`);
1152
1152
  } else if (op === Op.endsWith) {
1153
- builder[having ? 'havingLike' : 'whereLike'](column, `%${value}`);
1153
+ builder[_getOpLikeReal(having, db)](column, `%${value}`);
1154
1154
  } else if (op === Op.includes) {
1155
- builder[having ? 'havingLike' : 'whereLike'](column, `%${value}%`);
1155
+ builder[_getOpLikeReal(having, db)](column, `%${value}%`);
1156
1156
  } else if (op === Op.startsWithI) {
1157
1157
  builder[_getOpILikeReal(having, db)](column, `${value}%`);
1158
1158
  } else if (op === Op.endsWithI) {
@@ -1163,6 +1163,9 @@ function _buildWhereColumnOpNormal(having, db, builder, column, value, op) {
1163
1163
  builder[having ? 'having' : 'where'](column, '=', db.connection.ref(value));
1164
1164
  }
1165
1165
  }
1166
+ function _getOpLikeReal(having, db) {
1167
+ return db.dialect.capabilities.like ? having ? 'havingLike' : 'whereLike' : having ? 'havingILike' : 'whereILike';
1168
+ }
1166
1169
  function _getOpILikeReal(having, db) {
1167
1170
  return db.dialect.capabilities.ilike ? having ? 'havingILike' : 'whereILike' : having ? 'havingLike' : 'whereLike';
1168
1171
  }
@@ -1187,83 +1190,6 @@ function _safeColumn(column) {
1187
1190
  return column.replace(/[\\.#%'"`;,() ]/g, '');
1188
1191
  }
1189
1192
 
1190
- function $column(key) {
1191
- return key;
1192
- }
1193
- function $columns(key) {
1194
- return key;
1195
- }
1196
- function $columnsAll(classEntity, withTableName, withMeta) {
1197
- const classEntity2 = _prepareClassEntity(classEntity);
1198
- let columns = getTargetDecoratorRuleColumnsMap(classEntity2.prototype);
1199
- if (withTableName) {
1200
- const tableName = $tableName(classEntity2);
1201
- columns = {
1202
- ...columns,
1203
- $table: tableName
1204
- };
1205
- }
1206
- if (withMeta) {
1207
- const comments = $tableComments(classEntity2);
1208
- const defaults = $tableDefaults(classEntity2);
1209
- columns = {
1210
- ...columns,
1211
- $comment: comments,
1212
- $default: defaults
1213
- };
1214
- }
1215
- return columns;
1216
- }
1217
- function $tableColumns(classEntity, key) {
1218
- // tableName
1219
- const tableName = $tableName(classEntity);
1220
- return {
1221
- [tableName]: key
1222
- };
1223
- }
1224
- function $tableName(classEntity) {
1225
- const beanOptionsEntity = appResource.getBean(_prepareClassEntity(classEntity));
1226
- const entityOptions = beanOptionsEntity?.options;
1227
- return entityOptions.table;
1228
- }
1229
- function $tableComments(classEntity) {
1230
- const app = useApp();
1231
- const classEntity2 = _prepareClassEntity(classEntity);
1232
- // rules
1233
- const rules = getTargetDecoratorRules(classEntity2.prototype);
1234
- const comments = {};
1235
- for (const key in rules) {
1236
- const rule = rules[key];
1237
- const metadata = ZodMetadata.getOpenapiMetadata(rule);
1238
- const comment = metadata?.description || metadata?.title;
1239
- comments[key] = comment ? app.meta.text(comment) : '';
1240
- }
1241
- // table comment
1242
- const beanOptions = appResource.getBean(classEntity2);
1243
- if (beanOptions) {
1244
- const openapi = cast(beanOptions.options)?.openapi;
1245
- const comment = openapi?.description || openapi?.title;
1246
- cast(comments).$table = comment ? app.meta.text(comment) : '';
1247
- }
1248
- // ok
1249
- return comments;
1250
- }
1251
- function $tableDefaults(classEntity) {
1252
- const classEntity2 = _prepareClassEntity(classEntity);
1253
- // rules
1254
- const rules = getTargetDecoratorRules(classEntity2.prototype);
1255
- const defaults = {};
1256
- for (const key in rules) {
1257
- const rule = rules[key];
1258
- defaults[key] = ZodMetadata.getDefaultValue(rule);
1259
- }
1260
- // ok
1261
- return defaults;
1262
- }
1263
- function _prepareClassEntity(classEntity) {
1264
- return isClass(classEntity) ? classEntity : cast(classEntity)();
1265
- }
1266
-
1267
1193
  function _applyDecoratedDescriptor(i, e, r, n, l) {
1268
1194
  var a = {};
1269
1195
  return Object.keys(n).forEach(function (i) {
@@ -1514,7 +1440,7 @@ class BeanModelMeta extends BeanBase {
1514
1440
  _getTable(where) {
1515
1441
  const table = this[SymbolModelTable] ?? this.options.table;
1516
1442
  if (table && typeof table === 'string') return table;
1517
- const defaultTable = this.options.entity && $tableName(this.options.entity);
1443
+ const defaultTable = this.options.entity && $tableNameFromEntity(this.options.entity);
1518
1444
  if (table && typeof table === 'function') {
1519
1445
  return table(this.ctx, where, defaultTable, this);
1520
1446
  }
@@ -2789,10 +2715,13 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
2789
2715
  if (!isNil(item?.id) && !isNil(entity[relationName].id) && item?.id !== entity[relationName].id) {
2790
2716
  throw new Error(`invalid id: ${entity[relationName].id}`);
2791
2717
  }
2792
- children.push(Object.assign({}, entity[relationName], {
2793
- [key]: cast(entity).id,
2794
- id: item?.id
2795
- }));
2718
+ const dataNew = {
2719
+ [key]: cast(entity).id
2720
+ };
2721
+ if (!isNil(item?.id)) {
2722
+ dataNew.id = item.id;
2723
+ }
2724
+ children.push(Object.assign({}, entity[relationName], dataNew));
2796
2725
  }
2797
2726
  }
2798
2727
  children = await modelTarget.mutateBulk(children, methodOptionsReal);
@@ -4485,4 +4414,4 @@ const $relationMutate = {
4485
4414
  belongsToMany
4486
4415
  };
4487
4416
 
4488
- export { $Dto, $column, $columns, $columnsAll, $locale, $relation, $relationDynamic, $relationMutate, $tableColumns, $tableComments, $tableDefaults, $tableName, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, DatabaseDialect, DtoQueryBase, DtoQueryPageBase, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, EventClientNameReal, EventColumnsClear, ExtendKnex, ExtendSchemaBuilder, ExtendTableBuilder, HmrModel, Main, Model, Op, OpAggrs, OpJoint, OpJointValues, OpNormal, OpNormalValues, OpValues, QueueDoubleDelete, ScheduleSoftDeletionPrune, ScopeModuleAOrm, ServiceCacheEntity, ServiceCacheQuery, ServiceColumns, ServiceColumnsCache, ServiceDatabase, ServiceDatabaseAsyncLocalStorage, ServiceDatabaseClient, ServiceDb, ServiceEntityResolver, ServiceModelResolver, ServiceRelations, ServiceTransaction, ServiceTransactionAsyncLocalStorage, ServiceTransactionConsistency‌, ServiceTransactionFiber, ServiceTransactionState, SymbolCacheModelCacheInstances, SymbolCacheModelsClear, SymbolKeyEntity, SymbolKeyEntityMeta, SymbolKeyFieldsMore, SymbolKeyModelOptions, TransactionIsolationLevelsMap, buildWhere, clearAllCacheModelsClear, clearCacheModelCacheInstance, config, configDefault, errors, getCacheModelCacheInstances, getCacheModelsClear, getClassEntityFromClassModel, getTableOrTableAlias, getTargetColumnName, isRaw, isRef, locales, prepareClassModel, prepareColumns };
4417
+ export { $Dto, $locale, $relation, $relationDynamic, $relationMutate, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, DatabaseDialect, DtoQueryBase, DtoQueryPageBase, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, EventClientNameReal, EventColumnsClear, ExtendKnex, ExtendSchemaBuilder, ExtendTableBuilder, HmrModel, Main, Model, Op, OpAggrs, OpJoint, OpJointValues, OpNormal, OpNormalValues, OpValues, QueueDoubleDelete, ScheduleSoftDeletionPrune, ScopeModuleAOrm, ServiceCacheEntity, ServiceCacheQuery, ServiceColumns, ServiceColumnsCache, ServiceDatabase, ServiceDatabaseAsyncLocalStorage, ServiceDatabaseClient, ServiceDb, ServiceEntityResolver, ServiceModelResolver, ServiceRelations, ServiceTransaction, ServiceTransactionAsyncLocalStorage, ServiceTransactionConsistency‌, ServiceTransactionFiber, ServiceTransactionState, SymbolCacheModelCacheInstances, SymbolCacheModelsClear, SymbolKeyEntity, SymbolKeyEntityMeta, SymbolKeyFieldsMore, SymbolKeyModelOptions, TransactionIsolationLevelsMap, buildWhere, clearAllCacheModelsClear, clearCacheModelCacheInstance, config, configDefault, errors, getCacheModelCacheInstances, getCacheModelsClear, getClassEntityFromClassModel, getTableOrTableAlias, getTargetColumnName, isRaw, isRef, locales, prepareClassModel, prepareColumns };
@@ -1,4 +1,3 @@
1
- export * from './columns.ts';
2
1
  export * from './const.ts';
3
2
  export * from './databaseDialect.ts';
4
3
  export * from './dto/index.ts';
@@ -7,6 +7,7 @@ export interface IFetchIndexesResultItem {
7
7
  }
8
8
  export type TypeDatabaseDialectTableColumnsFn = () => Promise<ITableColumns>;
9
9
  export interface IDatabaseDialectCapabilities {
10
+ like: boolean;
10
11
  ilike: boolean;
11
12
  level: boolean;
12
13
  }
@@ -1,3 +1,4 @@
1
+ import type { PickString } from 'vona';
1
2
  export type TypeEntityMeta<T, N = string> = Required<{
2
3
  [key in keyof T]: key;
3
4
  }> & {
@@ -13,3 +14,5 @@ export type TypeEntityMeta<T, N = string> = Required<{
13
14
  };
14
15
  export declare const SymbolKeyFieldsMore: unique symbol;
15
16
  export type TypeSymbolKeyFieldsMore = typeof SymbolKeyFieldsMore;
17
+ export type TypeEntityStudentMetaSimple<T> = Omit<T, '$table' | '$comment' | '$default'>;
18
+ export type TypeEntityStudentMetaSimpleColumns<T> = PickString<keyof TypeEntityStudentMetaSimple<T>>;
@@ -11,7 +11,7 @@ export default async function (options) {
11
11
  const tableName = __parseTableName(fileContent);
12
12
  contentColumns.push(`export type ${className}TableName = '${tableName}';`);
13
13
  contentEntityMetas.push(`export type ${className}Meta=TypeEntityMeta<${className},${className}TableName>;`);
14
- const contentRecordItem = `'${tableName}': never;`;
14
+ const contentRecordItem = `'${tableName}': ${className}Meta;`;
15
15
  if (!contentRecords.includes(contentRecordItem)) {
16
16
  contentRecords.push(contentRecordItem);
17
17
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-orm",
3
3
  "type": "module",
4
- "version": "5.0.89",
4
+ "version": "5.0.91",
5
5
  "title": "a-orm",
6
6
  "vonaModule": {
7
7
  "capabilities": {
@@ -1,9 +0,0 @@
1
- import type { Constructable } from 'vona';
2
- import type { ITableRecord, TypeEntityMeta } from '../types/index.ts';
3
- export declare function $column<T>(key: keyof T): keyof T;
4
- export declare function $columns<T>(key?: (keyof T) | Array<keyof T> | undefined): (keyof T) | Array<keyof T> | undefined;
5
- export declare function $columnsAll<T, TableName extends boolean, Meta extends boolean>(classEntity: (() => Constructable<T>) | Constructable<T>, withTableName?: TableName, withMeta?: Meta): TableName extends true ? (Meta extends true ? TypeEntityMeta<T> : Omit<TypeEntityMeta<T>, '$comment' | '$default'>) : (Meta extends true ? Omit<TypeEntityMeta<T>, '$table'> : Omit<TypeEntityMeta<T>, '$table' | '$comment' | '$default'>);
6
- export declare function $tableColumns<T>(classEntity: (() => Constructable<T>) | Constructable<T>, key?: (keyof T) | Array<keyof T> | undefined): Record<keyof ITableRecord, (keyof T) | Array<keyof T> | undefined>;
7
- export declare function $tableName<T>(classEntity: (() => Constructable<T>) | Constructable<T>): keyof ITableRecord;
8
- export declare function $tableComments<T>(classEntity: (() => Constructable<T>) | Constructable<T>): Record<string, string>;
9
- export declare function $tableDefaults<T>(classEntity: (() => Constructable<T>) | Constructable<T>): Record<string, any>;
@@ -1,2 +0,0 @@
1
- import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
2
- export default function (options: IMetadataCustomGenerateOptions): Promise<string>;
@@ -1,2 +0,0 @@
1
- import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
2
- export default function (options: IMetadataCustomGenerateOptions): Promise<string>;
@@ -1,4 +0,0 @@
1
- import type { BeanCliBase } from '@cabloy/cli';
2
- import type { IGlobBeanFile } from '@cabloy/module-info';
3
- import type GoGoCode from 'gogocode';
4
- export declare function __parseMagics(cli: BeanCliBase, ast: GoGoCode.GoGoAST, globFile: IGlobBeanFile, entityName: string): string[];