vona-module-a-orm 5.1.30 → 5.1.32

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.js CHANGED
@@ -359,8 +359,12 @@ let ServiceTransactionFiber = class ServiceTransactionFiber extends BeanBase {
359
359
  this._transactionConsistency.compensate(cb);
360
360
  }
361
361
  async doCommit() {
362
- await this._connection.commit();
363
- this._connection = undefined;
362
+ const connection = this._connection;
363
+ try {
364
+ await Promise.all([connection.executionPromise, connection.commit()]);
365
+ } finally {
366
+ this._connection = undefined;
367
+ }
364
368
  }
365
369
  async doRollback() {
366
370
  await this._connection.rollback();
@@ -539,9 +543,12 @@ let ServiceTransaction = class ServiceTransaction extends BeanBase {
539
543
  if (fiber) {
540
544
  try {
541
545
  await fiber.doCommit();
542
- } finally {
546
+ } catch (err) {
543
547
  this.transactionState.remove(this._db);
548
+ await fiber.compensatesDone();
549
+ throw err;
544
550
  }
551
+ this.transactionState.remove(this._db);
545
552
  await fiber.commitsDone();
546
553
  }
547
554
  return res;
@@ -2156,10 +2163,11 @@ ServiceCacheQuery = __decorate([Service(), BeanInfo({
2156
2163
  })], ServiceCacheQuery);
2157
2164
 
2158
2165
  const BOOLEAN_COLUMN_TYPES = ['bit', 'bool', 'boolean'];
2159
- const NUMBER_COLUMN_TYPES = ['int'];
2160
- const TIMESTAMP_COLUMN_TYPE_PREFIXES = ['timestamp'];
2161
- const FLOAT_COLUMN_TYPE_PREFIXES = ['float', 'double'];
2162
- const INTEGER_COLUMN_TYPE_PREFIXES = ['tinyint', 'smallint', 'mediumint', 'bigint', 'numeric', 'integer'];
2166
+ const INTEGER_COLUMN_TYPES = ['tinyint', 'smallint', 'mediumint', 'int', 'integer'];
2167
+ const FLOAT_COLUMN_TYPES = ['float', 'double'];
2168
+ const GENERATED_DEFAULT_PATTERN = /^(?:current_timestamp\b(?:\s*\(\s*\d*\s*\))?|current_date\b|current_time\b(?:\s*\(\s*\d*\s*\))?|now\s*\(\s*\)|nextval\s*\()/i;
2169
+ const NUMBER_LITERAL_PATTERN = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
2170
+ const QUOTED_LITERAL_PATTERN = /^'((?:''|[^'])*)'$/;
2163
2171
  let ServiceDatabaseDialectBase = class ServiceDatabaseDialectBase extends BeanBase {
2164
2172
  constructor(...args) {
2165
2173
  super(...args);
@@ -2204,9 +2212,9 @@ let ServiceDatabaseDialectBase = class ServiceDatabaseDialectBase extends BeanBa
2204
2212
  const result = {
2205
2213
  type: column.type
2206
2214
  };
2207
- result.default = this._coerceColumnValue(column.type, column.defaultValue);
2208
2215
  const columnType = column.columnType;
2209
2216
  if (columnType) result.columnType = columnType;
2217
+ result.default = this._coerceColumnValue(result, column.defaultValue);
2210
2218
  return result;
2211
2219
  }
2212
2220
  _isMysqlBooleanColumn(column) {
@@ -2274,30 +2282,101 @@ let ServiceDatabaseDialectBase = class ServiceDatabaseDialectBase extends BeanBa
2274
2282
  const items = await builder;
2275
2283
  return [items.map(item => item.id), builder];
2276
2284
  }
2277
- _coerceColumnValue(type, value) {
2285
+ _coerceColumnValue(column, value) {
2278
2286
  if (isNil(value)) return undefined;
2279
- if (BOOLEAN_COLUMN_TYPES.includes(type)) return safeBoolean(value);
2280
- if (NUMBER_COLUMN_TYPES.includes(type)) return this._safeNumber(value);
2281
- if (this._columnTypePrefixes(type, TIMESTAMP_COLUMN_TYPE_PREFIXES) && value === 'CURRENT_TIMESTAMP') {
2282
- return undefined; // new Date();
2283
- }
2284
- if (this._columnTypePrefixes(type, FLOAT_COLUMN_TYPE_PREFIXES)) {
2285
- return this._safeNumber(value);
2286
- }
2287
- if (this._columnTypePrefixes(type, INTEGER_COLUMN_TYPE_PREFIXES)) {
2288
- return this._safeNumber(value);
2287
+ if (typeof value !== 'string') {
2288
+ return this._isBooleanColumn(column) ? safeBoolean(value) : value;
2289
+ }
2290
+ const literal = this._coerceColumnLiteral(value);
2291
+ if (literal === undefined) return undefined;
2292
+ if (this._isBooleanColumn(column)) return safeBoolean(literal.value);
2293
+ if (literal.kind === 'boolean') return literal.value;
2294
+ const type = this._columnTypeName(column.type);
2295
+ if (literal.kind === 'string') return literal.value;
2296
+ if (INTEGER_COLUMN_TYPES.includes(type)) return this._safeInteger(literal.value);
2297
+ if (FLOAT_COLUMN_TYPES.includes(type)) return this._safeNumber(literal.value);
2298
+ return literal.value;
2299
+ }
2300
+ _isBooleanColumn(column) {
2301
+ return this._isMysqlBooleanColumn(column) || BOOLEAN_COLUMN_TYPES.includes(this._columnTypeName(column.type));
2302
+ }
2303
+ _columnTypeName(type) {
2304
+ return type.trim().toLowerCase().match(/^\w+/)?.[0] ?? '';
2305
+ }
2306
+ _coerceColumnLiteral(value) {
2307
+ const literal = this._unwrapColumnDefault(value);
2308
+ if (literal === '') return undefined;
2309
+ const literalLower = literal.toLowerCase();
2310
+ if (literalLower === 'null' || GENERATED_DEFAULT_PATTERN.test(literal)) return undefined;
2311
+ const quoted = literal.match(QUOTED_LITERAL_PATTERN);
2312
+ if (quoted) return {
2313
+ kind: 'string',
2314
+ value: quoted[1].replaceAll("''", "'")
2315
+ };
2316
+ if (literalLower === 'true' || literalLower === 't') return {
2317
+ kind: 'boolean',
2318
+ value: true
2319
+ };
2320
+ if (literalLower === 'false' || literalLower === 'f') return {
2321
+ kind: 'boolean',
2322
+ value: false
2323
+ };
2324
+ if (NUMBER_LITERAL_PATTERN.test(literal)) return {
2325
+ kind: 'number',
2326
+ value: literal
2327
+ };
2328
+ if (this._isExpressionColumnDefault(literal)) return undefined;
2329
+ return {
2330
+ kind: 'string',
2331
+ value: literal
2332
+ };
2333
+ }
2334
+ _unwrapColumnDefault(value) {
2335
+ let literal = value.trim();
2336
+ while (literal.startsWith('(') && literal.endsWith(')')) {
2337
+ const inner = literal.slice(1, -1).trim();
2338
+ if (!inner || !this._isColumnDefaultBalanced(inner)) break;
2339
+ literal = inner;
2340
+ }
2341
+ const castIndex = literal.indexOf('::');
2342
+ if (castIndex > 0 && this._isScalarColumnDefault(literal.slice(0, castIndex).trim())) {
2343
+ literal = literal.slice(0, castIndex).trim();
2344
+ }
2345
+ return literal;
2346
+ }
2347
+ _isScalarColumnDefault(value) {
2348
+ return value.toLowerCase() === 'null' || QUOTED_LITERAL_PATTERN.test(value) || value.toLowerCase() === 'true' || value.toLowerCase() === 'false' || NUMBER_LITERAL_PATTERN.test(value);
2349
+ }
2350
+ _isColumnDefaultBalanced(value) {
2351
+ let depth = 0;
2352
+ let quoted = false;
2353
+ for (let index = 0; index < value.length; index++) {
2354
+ const char = value[index];
2355
+ if (char === "'") {
2356
+ if (quoted && value[index + 1] === "'") {
2357
+ index++;
2358
+ } else {
2359
+ quoted = !quoted;
2360
+ }
2361
+ } else if (!quoted && char === '(') {
2362
+ depth++;
2363
+ } else if (!quoted && char === ')') {
2364
+ if (depth === 0) return false;
2365
+ depth--;
2366
+ }
2289
2367
  }
2290
- // pg: NULL::character varying
2291
- if (value.indexOf('NULL::') === 0) return undefined;
2292
- return value;
2368
+ return !quoted && depth === 0;
2293
2369
  }
2294
- // pg: nextval
2295
- _safeNumber(value) {
2370
+ _isExpressionColumnDefault(value) {
2371
+ return /[()*/+\-\s]/.test(value);
2372
+ }
2373
+ _safeInteger(value) {
2296
2374
  const num = Number(value);
2297
- return Number.isNaN(num) ? undefined : num;
2375
+ return Number.isSafeInteger(num) ? num : value;
2298
2376
  }
2299
- _columnTypePrefixes(type, prefixes) {
2300
- return prefixes.some(prefix => type.includes(prefix));
2377
+ _safeNumber(value) {
2378
+ const num = Number(value);
2379
+ return Number.isFinite(num) ? num : undefined;
2301
2380
  }
2302
2381
  };
2303
2382
  ServiceDatabaseDialectBase = __decorate([Service(), Virtual(), BeanInfo({