@mikro-orm/core 7.0.0-dev.303 → 7.0.0-dev.304
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/cache/index.d.ts +1 -1
- package/cache/index.js +0 -1
- package/errors.js +3 -13
- package/events/EventManager.js +4 -1
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/hydration/ObjectHydrator.js +5 -5
- package/logging/index.d.ts +1 -1
- package/logging/index.js +0 -1
- package/metadata/MetadataDiscovery.js +3 -3
- package/metadata/discover-entities.js +1 -1
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/naming-strategy/AbstractNamingStrategy.js +1 -1
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/package.json +1 -1
- package/platforms/Platform.js +2 -2
- package/types/index.d.ts +2 -1
- package/unit-of-work/UnitOfWork.js +1 -1
- package/utils/AbstractMigrator.js +1 -1
- package/utils/Configuration.js +1 -1
- package/utils/Cursor.js +1 -1
- package/utils/EntityComparator.js +5 -5
- package/utils/Utils.d.ts +1 -1
- package/utils/Utils.js +5 -4
- package/utils/fs-utils.js +1 -1
- package/utils/upsert-utils.js +1 -1
package/cache/index.d.ts
CHANGED
package/cache/index.js
CHANGED
package/errors.js
CHANGED
|
@@ -34,19 +34,12 @@ export class ValidationError extends Error {
|
|
|
34
34
|
return new ValidationError(`Entity ${entity.constructor.name} is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager.persist()`);
|
|
35
35
|
}
|
|
36
36
|
static notEntity(owner, prop, data) {
|
|
37
|
-
const type = Object.prototype.toString
|
|
38
|
-
.call(data)
|
|
39
|
-
.match(/\[object (\w+)]/)[1]
|
|
40
|
-
.toLowerCase();
|
|
37
|
+
const type = /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
|
|
41
38
|
return new ValidationError(`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${inspect(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`);
|
|
42
39
|
}
|
|
43
40
|
static notDiscoveredEntity(data, meta, action = 'persist') {
|
|
44
41
|
/* v8 ignore next */
|
|
45
|
-
const type = meta?.className ??
|
|
46
|
-
Object.prototype.toString
|
|
47
|
-
.call(data)
|
|
48
|
-
.match(/\[object (\w+)]/)[1]
|
|
49
|
-
.toLowerCase();
|
|
42
|
+
const type = meta?.className ?? /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
|
|
50
43
|
let err = `Trying to ${action} not discovered entity of type ${type}.`;
|
|
51
44
|
if (meta) {
|
|
52
45
|
err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
|
|
@@ -63,10 +56,7 @@ export class ValidationError extends Error {
|
|
|
63
56
|
return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
|
|
64
57
|
}
|
|
65
58
|
static invalidType(type, value, mode) {
|
|
66
|
-
const valueType = Object.prototype.toString
|
|
67
|
-
.call(value)
|
|
68
|
-
.match(/\[object (\w+)]/)[1]
|
|
69
|
-
.toLowerCase();
|
|
59
|
+
const valueType = /\[object (\w+)]/.exec(Object.prototype.toString.call(value))[1].toLowerCase();
|
|
70
60
|
if (value instanceof Date) {
|
|
71
61
|
value = value.toISOString();
|
|
72
62
|
}
|
package/events/EventManager.js
CHANGED
|
@@ -45,7 +45,10 @@ export class EventManager {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
if (event === EventType.onInit) {
|
|
48
|
-
|
|
48
|
+
for (const listener of listeners) {
|
|
49
|
+
void listener(args);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
49
52
|
}
|
|
50
53
|
return Utils.runSerial(listeners, listener => listener(args));
|
|
51
54
|
}
|
package/events/index.d.ts
CHANGED
package/events/index.js
CHANGED
|
@@ -67,7 +67,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
67
67
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
68
68
|
const tz = this.platform.getTimezone();
|
|
69
69
|
const convertorKey = path
|
|
70
|
-
.filter(k =>
|
|
70
|
+
.filter(k => !/\[idx_\d+]/.exec(k))
|
|
71
71
|
.map(k => this.safeKey(k))
|
|
72
72
|
.join('_');
|
|
73
73
|
const ret = [];
|
|
@@ -238,7 +238,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
238
238
|
};
|
|
239
239
|
const registerEmbeddedPrototype = (prop, path) => {
|
|
240
240
|
const convertorKey = path
|
|
241
|
-
.filter(k =>
|
|
241
|
+
.filter(k => !/\[idx_\d+]/.exec(k))
|
|
242
242
|
.map(k => this.safeKey(k))
|
|
243
243
|
.join('_');
|
|
244
244
|
if (prop.targetMeta?.polymorphs) {
|
|
@@ -287,7 +287,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
287
287
|
else {
|
|
288
288
|
ret.push(` const embeddedData = {`);
|
|
289
289
|
for (const childProp of Object.values(prop.embeddedProps)) {
|
|
290
|
-
const key = childProp.embedded[1]
|
|
290
|
+
const key = /^\w+$/.exec(childProp.embedded[1]) ? childProp.embedded[1] : `'${childProp.embedded[1]}'`;
|
|
291
291
|
ret.push(` ${key}: data${this.wrap(childProp.name)},`);
|
|
292
292
|
}
|
|
293
293
|
ret.push(` };`);
|
|
@@ -424,10 +424,10 @@ export class ObjectHydrator extends Hydrator {
|
|
|
424
424
|
return lines;
|
|
425
425
|
}
|
|
426
426
|
wrap(key) {
|
|
427
|
-
if (
|
|
427
|
+
if (/^\[.*]$/.exec(key)) {
|
|
428
428
|
return key;
|
|
429
429
|
}
|
|
430
|
-
return
|
|
430
|
+
return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
|
|
431
431
|
}
|
|
432
432
|
safeKey(key) {
|
|
433
433
|
return key.replace(/\W/g, '_');
|
package/logging/index.d.ts
CHANGED
package/logging/index.js
CHANGED
|
@@ -1481,13 +1481,13 @@ export class MetadataDiscovery {
|
|
|
1481
1481
|
}
|
|
1482
1482
|
initGeneratedColumn(meta, prop) {
|
|
1483
1483
|
if (!prop.generated && prop.columnTypes) {
|
|
1484
|
-
const match =
|
|
1484
|
+
const match = /(.*) generated always as (.*)/i.exec(prop.columnTypes[0]);
|
|
1485
1485
|
if (match) {
|
|
1486
1486
|
prop.columnTypes[0] = match[1];
|
|
1487
1487
|
prop.generated = match[2];
|
|
1488
1488
|
return;
|
|
1489
1489
|
}
|
|
1490
|
-
const match2 = prop.columnTypes[0]?.trim()
|
|
1490
|
+
const match2 = /^as (.*)/i.exec(prop.columnTypes[0]?.trim());
|
|
1491
1491
|
if (match2) {
|
|
1492
1492
|
prop.generated = match2[1];
|
|
1493
1493
|
}
|
|
@@ -1775,7 +1775,7 @@ export class MetadataDiscovery {
|
|
|
1775
1775
|
// it could be a runtime type from reflect-metadata
|
|
1776
1776
|
!SCALAR_TYPES.includes(prop.type) &&
|
|
1777
1777
|
// or it might be inferred via ts-morph to some generic type alias
|
|
1778
|
-
|
|
1778
|
+
!/[<>:"';{}]/.exec(prop.type)) {
|
|
1779
1779
|
const type = prop.length != null && !prop.type.endsWith(`(${prop.length})`) ? `${prop.type}(${prop.length})` : prop.type;
|
|
1780
1780
|
prop.columnTypes = [type];
|
|
1781
1781
|
}
|
|
@@ -31,7 +31,7 @@ export async function discoverEntities(paths, options) {
|
|
|
31
31
|
const found = new Map();
|
|
32
32
|
for (const filepath of files) {
|
|
33
33
|
const filename = basename(filepath);
|
|
34
|
-
if (
|
|
34
|
+
if (!/\.[cm]?[jt]s$/.exec(filename) || /\.d\.[cm]?ts/.exec(filename)) {
|
|
35
35
|
continue;
|
|
36
36
|
}
|
|
37
37
|
await getEntityClassOrSchema(filepath, found, baseDir);
|
package/metadata/index.d.ts
CHANGED
package/metadata/index.js
CHANGED
|
@@ -34,7 +34,7 @@ export class AbstractNamingStrategy {
|
|
|
34
34
|
* @inheritDoc
|
|
35
35
|
*/
|
|
36
36
|
getEntityName(tableName, schemaName) {
|
|
37
|
-
const name =
|
|
37
|
+
const name = /^[^$_\p{ID_Start}]/u.exec(tableName) ? `E_${tableName}` : tableName;
|
|
38
38
|
return this.getClassName(name.replaceAll(/[^\u200C\u200D\p{ID_Continue}]+/gu, r => r
|
|
39
39
|
.split('')
|
|
40
40
|
.map(c => `$${c.codePointAt(0)}`)
|
package/naming-strategy/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.0-dev.
|
|
3
|
+
"version": "7.0.0-dev.304",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
package/platforms/Platform.js
CHANGED
|
@@ -180,7 +180,7 @@ export class Platform {
|
|
|
180
180
|
return this.getVarcharTypeDeclarationSQL(column);
|
|
181
181
|
}
|
|
182
182
|
extractSimpleType(type) {
|
|
183
|
-
return
|
|
183
|
+
return /[^(), ]+/.exec(type.toLowerCase())[0];
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* This should be used only to compare types, it can strip some information like the length.
|
|
@@ -380,7 +380,7 @@ export class Platform {
|
|
|
380
380
|
let j = 0;
|
|
381
381
|
let pos = 0;
|
|
382
382
|
let ret = '';
|
|
383
|
-
if (sql
|
|
383
|
+
if (sql.startsWith('?')) {
|
|
384
384
|
if (sql[1] === '?') {
|
|
385
385
|
ret += this.quoteIdentifier(params[j++]);
|
|
386
386
|
pos = 2;
|
package/types/index.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ import { type IType, type TransformContext, Type } from './Type.js';
|
|
|
23
23
|
import { Uint8ArrayType } from './Uint8ArrayType.js';
|
|
24
24
|
import { UnknownType } from './UnknownType.js';
|
|
25
25
|
import { UuidType } from './UuidType.js';
|
|
26
|
-
export {
|
|
26
|
+
export type { TransformContext, IType };
|
|
27
|
+
export { Type, DateType, TimeType, DateTimeType, BigIntType, BlobType, Uint8ArrayType, ArrayType, EnumArrayType, EnumType, JsonType, IntegerType, SmallIntType, TinyIntType, MediumIntType, FloatType, DoubleType, BooleanType, DecimalType, StringType, UuidType, TextType, UnknownType, IntervalType, CharacterType, };
|
|
27
28
|
export declare const types: {
|
|
28
29
|
readonly date: typeof DateType;
|
|
29
30
|
readonly time: typeof TimeType;
|
|
@@ -255,7 +255,7 @@ export class AbstractMigrator {
|
|
|
255
255
|
}
|
|
256
256
|
getMigrationFilename(name) {
|
|
257
257
|
name = name.replace(/\.[jt]s$/, '');
|
|
258
|
-
return
|
|
258
|
+
return /^\d{14}$/.exec(name) ? this.options.fileName(name) : name;
|
|
259
259
|
}
|
|
260
260
|
prefix(options) {
|
|
261
261
|
if (typeof options === 'string' || Array.isArray(options)) {
|
package/utils/Configuration.js
CHANGED
|
@@ -310,7 +310,7 @@ export class Configuration {
|
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
catch {
|
|
313
|
-
const url =
|
|
313
|
+
const url = /:\/\/.*\/([^?]+)/.exec(this.options.clientUrl);
|
|
314
314
|
if (url) {
|
|
315
315
|
this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
316
316
|
}
|
package/utils/Cursor.js
CHANGED
|
@@ -151,7 +151,7 @@ export class Cursor {
|
|
|
151
151
|
}
|
|
152
152
|
static decode(value) {
|
|
153
153
|
return JSON.parse(Buffer.from(value, 'base64url').toString('utf8')).map((value) => {
|
|
154
|
-
if (typeof value === 'string' &&
|
|
154
|
+
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/.exec(value)) {
|
|
155
155
|
return new Date(value);
|
|
156
156
|
}
|
|
157
157
|
return value;
|
|
@@ -271,7 +271,7 @@ export class EntityComparator {
|
|
|
271
271
|
if (part.length === 1) {
|
|
272
272
|
return this.formatCompositeKeyPart(part[0]);
|
|
273
273
|
}
|
|
274
|
-
const formatted = part.map(this.formatCompositeKeyPart).join(', ');
|
|
274
|
+
const formatted = part.map(p => this.formatCompositeKeyPart(p)).join(', ');
|
|
275
275
|
return `[${formatted}]`;
|
|
276
276
|
}
|
|
277
277
|
/**
|
|
@@ -404,7 +404,7 @@ export class EntityComparator {
|
|
|
404
404
|
let tail = '';
|
|
405
405
|
return parts
|
|
406
406
|
.map(k => {
|
|
407
|
-
if (
|
|
407
|
+
if (/^\[idx_\d+]$/.exec(k)) {
|
|
408
408
|
tail += k;
|
|
409
409
|
return '';
|
|
410
410
|
}
|
|
@@ -445,7 +445,7 @@ export class EntityComparator {
|
|
|
445
445
|
getEmbeddedPropertySnapshot(meta, prop, context, level, path, dataKey, object = prop.object) {
|
|
446
446
|
const padding = ' '.repeat(level * 2);
|
|
447
447
|
const nullCond = `entity${path.map(k => this.wrap(k)).join('')} === null`;
|
|
448
|
-
let ret =
|
|
448
|
+
let ret = level === 1 ? '' : '\n';
|
|
449
449
|
if (object) {
|
|
450
450
|
ret += `${padding}if (${nullCond}) ret${dataKey} = null;\n`;
|
|
451
451
|
}
|
|
@@ -708,10 +708,10 @@ export class EntityComparator {
|
|
|
708
708
|
return this.getGenericComparator(this.wrap(prop.name), `!equals(last${this.wrap(prop.name)}, current${this.wrap(prop.name)})`);
|
|
709
709
|
}
|
|
710
710
|
wrap(key) {
|
|
711
|
-
if (
|
|
711
|
+
if (/^\[.*]$/.exec(key)) {
|
|
712
712
|
return key;
|
|
713
713
|
}
|
|
714
|
-
return
|
|
714
|
+
return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
|
|
715
715
|
}
|
|
716
716
|
safeKey(key) {
|
|
717
717
|
return key.replace(/\W/g, '_');
|
package/utils/Utils.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class Utils {
|
|
|
22
22
|
/**
|
|
23
23
|
* Removes `undefined` properties (recursively) so they are not saved as nulls
|
|
24
24
|
*/
|
|
25
|
-
static dropUndefinedProperties(o: any, value?:
|
|
25
|
+
static dropUndefinedProperties(o: any, value?: null, visited?: Set<unknown>): void;
|
|
26
26
|
/**
|
|
27
27
|
* Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.
|
|
28
28
|
* @see https://github.com/deepkit/deepkit-framework/blob/master/packages/core/src/core.ts
|
package/utils/Utils.js
CHANGED
|
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
|
|
|
123
123
|
}
|
|
124
124
|
export class Utils {
|
|
125
125
|
static PK_SEPARATOR = '~~~';
|
|
126
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.304';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|
|
@@ -543,7 +543,7 @@ export class Utils {
|
|
|
543
543
|
!!process.env?.TS_JEST || // check if ts-jest is used
|
|
544
544
|
!!process.env?.VITEST || // check if vitest is used
|
|
545
545
|
!!process.versions?.bun || // check if bun is used
|
|
546
|
-
process.argv?.slice(1).some(arg =>
|
|
546
|
+
process.argv?.slice(1).some(arg => /\.([mc]?ts|tsx)$/.exec(arg)) || // executing `.ts` file
|
|
547
547
|
process.execArgv?.some(arg => {
|
|
548
548
|
return (arg.includes('ts-node') || // check for ts-node loader
|
|
549
549
|
arg.includes('@swc-node/register') || // check for swc-node/register loader
|
|
@@ -559,7 +559,7 @@ export class Utils {
|
|
|
559
559
|
return simple;
|
|
560
560
|
}
|
|
561
561
|
const objectType = Object.prototype.toString.call(value);
|
|
562
|
-
const type =
|
|
562
|
+
const type = /^\[object (.+)]$/.exec(objectType)[1];
|
|
563
563
|
if (type === 'Uint8Array') {
|
|
564
564
|
return 'Buffer';
|
|
565
565
|
}
|
|
@@ -613,7 +613,7 @@ export class Utils {
|
|
|
613
613
|
}
|
|
614
614
|
static findDuplicates(items) {
|
|
615
615
|
return items.reduce((acc, v, i, arr) => {
|
|
616
|
-
return arr.indexOf(v) !== i && acc.
|
|
616
|
+
return arr.indexOf(v) !== i && !acc.includes(v) ? acc.concat(v) : acc;
|
|
617
617
|
}, []);
|
|
618
618
|
}
|
|
619
619
|
static removeDuplicates(items) {
|
|
@@ -677,6 +677,7 @@ export class Utils {
|
|
|
677
677
|
return compiledFunctions[key](...context.values());
|
|
678
678
|
}
|
|
679
679
|
try {
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
680
681
|
return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
|
|
681
682
|
/* v8 ignore next */
|
|
682
683
|
}
|
package/utils/fs-utils.js
CHANGED
|
@@ -150,7 +150,7 @@ export const fs = {
|
|
|
150
150
|
}
|
|
151
151
|
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
152
152
|
path = normalize(path).replace(/\\/g, '/');
|
|
153
|
-
return
|
|
153
|
+
return /^[/.]|[a-zA-Z]:/.exec(path) || path.startsWith('!') ? path : './' + path;
|
|
154
154
|
},
|
|
155
155
|
/**
|
|
156
156
|
* Determines the relative path between two paths. If either path is a `file:` URL,
|
package/utils/upsert-utils.js
CHANGED
|
@@ -101,7 +101,7 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
101
101
|
return keys.filter(key => !(key in data));
|
|
102
102
|
}
|
|
103
103
|
function getPropertyValue(obj, key) {
|
|
104
|
-
if (key.
|
|
104
|
+
if (!key.includes('.')) {
|
|
105
105
|
return obj[key];
|
|
106
106
|
}
|
|
107
107
|
const parts = key.split('.');
|