@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321
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/EntityManager.d.ts +71 -63
- package/EntityManager.js +365 -283
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -142
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +1 -2
- package/cache/FileCacheAdapter.js +19 -14
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +101 -29
- package/entity/Collection.js +473 -115
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +7 -1
- package/entity/EntityFactory.js +116 -64
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +11 -10
- package/entity/EntityLoader.js +264 -102
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +2 -6
- package/entity/Reference.js +52 -19
- package/entity/WrappedEntity.d.ts +3 -8
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +525 -311
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +20 -10
- package/errors.js +63 -31
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +24 -13
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +105 -46
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +5 -7
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +64 -9
- package/metadata/MetadataDiscovery.js +867 -354
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +72 -41
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +53 -29
- package/serialization/EntityTransformer.js +33 -21
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +4 -4
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +3 -8
- package/unit-of-work/ChangeSetComputer.js +49 -26
- package/unit-of-work/ChangeSetPersister.d.ts +13 -12
- package/unit-of-work/ChangeSetPersister.js +107 -44
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +34 -4
- package/unit-of-work/UnitOfWork.js +294 -107
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +796 -211
- package/utils/Configuration.js +160 -197
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +29 -14
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +16 -9
- package/utils/EntityComparator.js +202 -96
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -7
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +106 -401
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +34 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
|
@@ -6,7 +6,7 @@ import { isRaw } from '../utils/RawQueryFragment.js';
|
|
|
6
6
|
function isVisible(meta, propName, ignoreFields = []) {
|
|
7
7
|
const prop = meta.properties[propName];
|
|
8
8
|
const visible = prop && !prop.hidden;
|
|
9
|
-
const prefixed = prop && !prop.primary && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
9
|
+
const prefixed = prop && !prop.primary && !prop.accessor && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
10
10
|
return visible && !prefixed && !ignoreFields.includes(propName);
|
|
11
11
|
}
|
|
12
12
|
export class EntityTransformer {
|
|
@@ -27,39 +27,51 @@ export class EntityTransformer {
|
|
|
27
27
|
const root = wrapped.__serializationContext.root;
|
|
28
28
|
const meta = wrapped.__meta;
|
|
29
29
|
const ret = {};
|
|
30
|
-
const
|
|
30
|
+
const props = new Set();
|
|
31
31
|
if (meta.serializedPrimaryKey && !meta.compositePK) {
|
|
32
|
-
|
|
32
|
+
props.add(meta.serializedPrimaryKey);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
meta.primaryKeys.forEach(pk =>
|
|
35
|
+
meta.primaryKeys.forEach(pk => props.add(pk));
|
|
36
36
|
}
|
|
37
37
|
if (wrapped.isInitialized() || !wrapped.hasPrimaryKey()) {
|
|
38
|
-
|
|
38
|
+
const entityKeys = new Set(Object.keys(entity));
|
|
39
|
+
for (const prop of meta.props) {
|
|
40
|
+
if (entityKeys.has(prop.name) || (prop.getter && prop.accessor === prop.name)) {
|
|
41
|
+
props.add(prop.name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const key of entityKeys) {
|
|
45
|
+
if (!meta.properties[key]) {
|
|
46
|
+
props.add(key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
50
|
const visited = root.visited.has(entity);
|
|
41
51
|
const includePrimaryKeys = wrapped.__config.get('serialization').includePrimaryKeys;
|
|
42
52
|
if (!visited) {
|
|
43
53
|
root.visited.add(entity);
|
|
44
54
|
}
|
|
45
|
-
for (const prop of
|
|
55
|
+
for (const prop of props) {
|
|
46
56
|
const visible = raw ? meta.properties[prop] : isVisible(meta, prop, ignoreFields);
|
|
47
57
|
if (!visible) {
|
|
48
58
|
continue;
|
|
49
59
|
}
|
|
50
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop);
|
|
61
|
+
if (!raw) {
|
|
62
|
+
const partiallyLoaded = root.isPartiallyLoaded(meta.class, prop);
|
|
63
|
+
const isPrimary = includePrimaryKeys && meta.properties[prop].primary;
|
|
64
|
+
if (!partiallyLoaded && !populated && !isPrimary) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
55
67
|
}
|
|
56
|
-
const cycle = root.visit(meta.
|
|
68
|
+
const cycle = root.visit(meta.class, prop);
|
|
57
69
|
if (cycle && visited) {
|
|
58
70
|
continue;
|
|
59
71
|
}
|
|
60
72
|
const val = EntityTransformer.processProperty(prop, entity, raw, populated);
|
|
61
73
|
if (!cycle) {
|
|
62
|
-
root.leave(meta.
|
|
74
|
+
root.leave(meta.class, prop);
|
|
63
75
|
}
|
|
64
76
|
if (isRaw(val)) {
|
|
65
77
|
throw new Error(`Trying to serialize raw SQL fragment: '${val.sql}'`);
|
|
@@ -67,7 +79,7 @@ export class EntityTransformer {
|
|
|
67
79
|
if (typeof val === 'undefined') {
|
|
68
80
|
continue;
|
|
69
81
|
}
|
|
70
|
-
ret[this.propertyName(meta, prop,
|
|
82
|
+
ret[this.propertyName(meta, prop, raw)] = val;
|
|
71
83
|
}
|
|
72
84
|
if (!wrapped.isInitialized() && wrapped.hasPrimaryKey()) {
|
|
73
85
|
return ret;
|
|
@@ -76,17 +88,17 @@ export class EntityTransformer {
|
|
|
76
88
|
// decorated get methods
|
|
77
89
|
if (prop.getterName != null) {
|
|
78
90
|
const visible = !prop.hidden && entity[prop.getterName] instanceof Function;
|
|
79
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
91
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop.name);
|
|
80
92
|
if (visible) {
|
|
81
|
-
ret[this.propertyName(meta, prop.name,
|
|
93
|
+
ret[this.propertyName(meta, prop.name, raw)] = this.processProperty(prop.getterName, entity, raw, populated);
|
|
82
94
|
}
|
|
83
95
|
}
|
|
84
96
|
else {
|
|
85
97
|
// decorated getters
|
|
86
98
|
const visible = !prop.hidden && typeof entity[prop.name] !== 'undefined';
|
|
87
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
99
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop.name);
|
|
88
100
|
if (visible) {
|
|
89
|
-
ret[this.propertyName(meta, prop.name,
|
|
101
|
+
ret[this.propertyName(meta, prop.name, raw)] = this.processProperty(prop.name, entity, raw, populated);
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
}
|
|
@@ -95,15 +107,15 @@ export class EntityTransformer {
|
|
|
95
107
|
}
|
|
96
108
|
return ret;
|
|
97
109
|
}
|
|
98
|
-
static propertyName(meta, prop,
|
|
110
|
+
static propertyName(meta, prop, raw) {
|
|
99
111
|
if (raw) {
|
|
100
112
|
return prop;
|
|
101
113
|
}
|
|
102
114
|
if (meta.properties[prop].serializedName) {
|
|
103
115
|
return meta.properties[prop].serializedName;
|
|
104
116
|
}
|
|
105
|
-
if (meta.properties[prop].primary &&
|
|
106
|
-
return
|
|
117
|
+
if (meta.properties[prop].primary && meta.serializedPrimaryKey) {
|
|
118
|
+
return meta.serializedPrimaryKey;
|
|
107
119
|
}
|
|
108
120
|
return prop;
|
|
109
121
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity, EntityMetadata, PopulateOptions } from '../typings.js';
|
|
1
|
+
import type { AnyEntity, EntityMetadata, EntityName, PopulateOptions } from '../typings.js';
|
|
2
2
|
import type { Configuration } from '../utils/Configuration.js';
|
|
3
3
|
/**
|
|
4
4
|
* Helper that allows to keep track of where we are currently at when serializing complex entity graph with cycles.
|
|
@@ -10,21 +10,21 @@ export declare class SerializationContext<T extends object> {
|
|
|
10
10
|
private readonly populate;
|
|
11
11
|
private readonly fields?;
|
|
12
12
|
private readonly exclude?;
|
|
13
|
-
readonly path: [
|
|
13
|
+
readonly path: [EntityName, string][];
|
|
14
14
|
readonly visited: Set<Partial<any>>;
|
|
15
15
|
private entities;
|
|
16
16
|
constructor(config: Configuration, populate?: PopulateOptions<T>[], fields?: Set<string> | undefined, exclude?: string[] | undefined);
|
|
17
17
|
/**
|
|
18
18
|
* Returns true when there is a cycle detected.
|
|
19
19
|
*/
|
|
20
|
-
visit(entityName:
|
|
21
|
-
leave
|
|
20
|
+
visit(entityName: EntityName, prop: string): boolean;
|
|
21
|
+
leave(entityName: EntityName, prop: string): void;
|
|
22
22
|
close(): void;
|
|
23
23
|
/**
|
|
24
24
|
* When initializing new context, we need to propagate it to the whole entity graph recursively.
|
|
25
25
|
*/
|
|
26
26
|
static propagate(root: SerializationContext<any>, entity: AnyEntity, isVisible: (meta: EntityMetadata, prop: string) => boolean): void;
|
|
27
|
-
isMarkedAsPopulated(entityName:
|
|
28
|
-
isPartiallyLoaded(entityName:
|
|
27
|
+
isMarkedAsPopulated(entityName: EntityName, prop: string): boolean;
|
|
28
|
+
isPartiallyLoaded(entityName: EntityName, prop: string): boolean;
|
|
29
29
|
private register;
|
|
30
30
|
}
|
|
@@ -36,8 +36,8 @@ export class SerializationContext {
|
|
|
36
36
|
}
|
|
37
37
|
leave(entityName, prop) {
|
|
38
38
|
const last = this.path.pop();
|
|
39
|
-
/* v8 ignore next
|
|
40
|
-
if (
|
|
39
|
+
/* v8 ignore next */
|
|
40
|
+
if (last?.[0] !== entityName || last[1] !== prop) {
|
|
41
41
|
throw new Error(`Trying to leave wrong property: ${entityName}.${prop} instead of ${last?.join('.')}`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -98,13 +98,13 @@ export class SerializationContext {
|
|
|
98
98
|
}
|
|
99
99
|
let fields = [...this.fields];
|
|
100
100
|
for (const segment of this.path) {
|
|
101
|
-
/* v8 ignore next
|
|
101
|
+
/* v8 ignore next */
|
|
102
102
|
if (fields.length === 0) {
|
|
103
103
|
return true;
|
|
104
104
|
}
|
|
105
105
|
fields = fields
|
|
106
106
|
.filter(field => field.startsWith(`${segment[1]}.`) || field === '*')
|
|
107
|
-
.map(field => field === '*' ? field : field.substring(segment[1].length + 1));
|
|
107
|
+
.map(field => (field === '*' ? field : field.substring(segment[1].length + 1)));
|
|
108
108
|
}
|
|
109
109
|
return fields.some(p => p === prop || p === '*');
|
|
110
110
|
}
|
package/types/ArrayType.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type TransformContext, Type } from './Type.js';
|
|
2
2
|
import type { EntityProperty } from '../typings.js';
|
|
3
3
|
import type { Platform } from '../platforms/Platform.js';
|
|
4
4
|
export declare class ArrayType<T = string> extends Type<T[] | null, string | null> {
|
package/types/ArrayType.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Type } from './Type.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
3
2
|
import { ValidationError } from '../errors.js';
|
|
4
3
|
export class ArrayType extends Type {
|
|
5
4
|
toJsValue;
|
|
@@ -16,7 +15,7 @@ export class ArrayType extends Type {
|
|
|
16
15
|
if (Array.isArray(value)) {
|
|
17
16
|
return platform.marshallArray(value.map(i => this.toDbValue(i)));
|
|
18
17
|
}
|
|
19
|
-
/* v8 ignore next
|
|
18
|
+
/* v8 ignore next */
|
|
20
19
|
if (context?.fromQuery) {
|
|
21
20
|
return value;
|
|
22
21
|
}
|
|
@@ -26,7 +25,7 @@ export class ArrayType extends Type {
|
|
|
26
25
|
if (value == null) {
|
|
27
26
|
return value;
|
|
28
27
|
}
|
|
29
|
-
if (
|
|
28
|
+
if (typeof value === 'string') {
|
|
30
29
|
value = platform.unmarshallArray(value);
|
|
31
30
|
}
|
|
32
31
|
return value.map(i => this.toJsValue(i));
|
package/types/BigIntType.js
CHANGED
package/types/BlobType.d.ts
CHANGED
|
@@ -4,6 +4,5 @@ import type { EntityProperty } from '../typings.js';
|
|
|
4
4
|
export declare class BlobType extends Uint8ArrayType {
|
|
5
5
|
convertToJSValue(value: Buffer): Buffer | null;
|
|
6
6
|
compareAsType(): string;
|
|
7
|
-
ensureComparable(): boolean;
|
|
8
7
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
9
8
|
}
|
package/types/BlobType.js
CHANGED
package/types/BooleanType.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import type { EntityProperty } from '../typings.js';
|
|
|
4
4
|
export declare class BooleanType extends Type<boolean | null | undefined, boolean | null | undefined> {
|
|
5
5
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
6
6
|
compareAsType(): string;
|
|
7
|
+
convertToJSValue(value: boolean | null | undefined): boolean | null | undefined;
|
|
7
8
|
ensureComparable(): boolean;
|
|
8
9
|
}
|
package/types/BooleanType.js
CHANGED
package/types/DecimalType.js
CHANGED
|
@@ -8,7 +8,7 @@ export class DecimalType extends Type {
|
|
|
8
8
|
super();
|
|
9
9
|
this.mode = mode;
|
|
10
10
|
}
|
|
11
|
-
/* v8 ignore next
|
|
11
|
+
/* v8 ignore next */
|
|
12
12
|
convertToJSValue(value) {
|
|
13
13
|
if ((this.mode ?? this.prop?.runtimeType) === 'number') {
|
|
14
14
|
return +value;
|
|
@@ -19,7 +19,7 @@ export class DecimalType extends Type {
|
|
|
19
19
|
return this.format(a) === this.format(b);
|
|
20
20
|
}
|
|
21
21
|
format(val) {
|
|
22
|
-
/* v8 ignore next
|
|
22
|
+
/* v8 ignore next */
|
|
23
23
|
if (this.prop?.scale == null) {
|
|
24
24
|
return +val;
|
|
25
25
|
}
|
package/types/DoubleType.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Type } from './Type.js';
|
|
|
3
3
|
* Type that maps an SQL DOUBLE to a JS string or number.
|
|
4
4
|
*/
|
|
5
5
|
export class DoubleType extends Type {
|
|
6
|
-
/* v8 ignore next
|
|
6
|
+
/* v8 ignore next */
|
|
7
7
|
convertToJSValue(value) {
|
|
8
8
|
if (this.prop?.runtimeType === 'number') {
|
|
9
9
|
return +value;
|
package/types/EnumArrayType.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { ArrayType } from './ArrayType.js';
|
|
3
2
|
import { ValidationError } from '../errors.js';
|
|
4
3
|
function mapHydrator(items, hydrate) {
|
|
@@ -19,7 +18,7 @@ export class EnumArrayType extends ArrayType {
|
|
|
19
18
|
if (Array.isArray(value) && Array.isArray(this.items)) {
|
|
20
19
|
const invalid = value.filter(v => !this.items.includes(v));
|
|
21
20
|
if (invalid.length > 0) {
|
|
22
|
-
throw
|
|
21
|
+
throw ValidationError.invalidEnumArrayItems(this.owner, invalid);
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
return super.convertToDatabaseValue(value, platform, context);
|
package/types/JsonType.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class JsonType extends Type<unknown, string | null> {
|
|
|
5
5
|
convertToDatabaseValue(value: unknown, platform: Platform, context?: TransformContext): string | null;
|
|
6
6
|
convertToJSValueSQL(key: string, platform: Platform): string;
|
|
7
7
|
convertToDatabaseValueSQL(key: string, platform: Platform): string;
|
|
8
|
-
convertToJSValue(value: string | unknown, platform: Platform): unknown;
|
|
8
|
+
convertToJSValue(value: string | unknown, platform: Platform, context?: TransformContext): unknown;
|
|
9
9
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
10
10
|
ensureComparable<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>): boolean;
|
|
11
11
|
compareAsType(): string;
|
package/types/JsonType.js
CHANGED
|
@@ -12,8 +12,13 @@ export class JsonType extends Type {
|
|
|
12
12
|
convertToDatabaseValueSQL(key, platform) {
|
|
13
13
|
return key + platform.castColumn(this.prop);
|
|
14
14
|
}
|
|
15
|
-
convertToJSValue(value, platform) {
|
|
16
|
-
|
|
15
|
+
convertToJSValue(value, platform, context) {
|
|
16
|
+
const isJsonColumn = ['json', 'jsonb', platform.getJsonDeclarationSQL()].includes(this.prop.columnTypes[0]);
|
|
17
|
+
const isObjectEmbedded = this.prop.embedded && this.prop.object;
|
|
18
|
+
if ((platform.convertsJsonAutomatically() || isObjectEmbedded) && isJsonColumn && !context?.force) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
return platform.convertJsonToJSValue(value, context);
|
|
17
22
|
}
|
|
18
23
|
getColumnType(prop, platform) {
|
|
19
24
|
return platform.getJsonDeclarationSQL();
|
package/types/TinyIntType.js
CHANGED
package/types/Type.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { Platform } from '../platforms/Platform.js';
|
|
3
2
|
import type { Constructor, EntityMetadata, EntityProperty } from '../typings.js';
|
|
4
3
|
export interface TransformContext {
|
|
5
4
|
fromQuery?: boolean;
|
|
5
|
+
force?: boolean;
|
|
6
6
|
key?: string;
|
|
7
7
|
mode?: 'hydration' | 'query' | 'query-data' | 'discovery' | 'serialization';
|
|
8
8
|
}
|
|
@@ -23,7 +23,7 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
|
|
|
23
23
|
/**
|
|
24
24
|
* Converts a value from its database representation to its JS representation of this type.
|
|
25
25
|
*/
|
|
26
|
-
convertToJSValue(value: DBType, platform: Platform): JSType;
|
|
26
|
+
convertToJSValue(value: DBType, platform: Platform, context?: TransformContext): JSType;
|
|
27
27
|
/**
|
|
28
28
|
* Converts a value from its JS representation to its database representation of this type.
|
|
29
29
|
*/
|
|
@@ -78,6 +78,4 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
|
|
|
78
78
|
* Checks whether the argument is instance of `Type`.
|
|
79
79
|
*/
|
|
80
80
|
static isMappedType(data: any): data is Type<any>;
|
|
81
|
-
/** @ignore */
|
|
82
|
-
[inspect.custom](depth?: number): string;
|
|
83
81
|
}
|
package/types/Type.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inspect } from '
|
|
1
|
+
import { inspect } from '../logging/inspect.js';
|
|
2
2
|
export class Type {
|
|
3
3
|
static types = new Map();
|
|
4
4
|
platform;
|
|
@@ -13,7 +13,7 @@ export class Type {
|
|
|
13
13
|
/**
|
|
14
14
|
* Converts a value from its database representation to its JS representation of this type.
|
|
15
15
|
*/
|
|
16
|
-
convertToJSValue(value, platform) {
|
|
16
|
+
convertToJSValue(value, platform, context) {
|
|
17
17
|
return value;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -65,7 +65,7 @@ export class Type {
|
|
|
65
65
|
return !!data?.__mappedType;
|
|
66
66
|
}
|
|
67
67
|
/** @ignore */
|
|
68
|
-
[inspect.custom](depth = 2) {
|
|
68
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
69
69
|
const object = { ...this };
|
|
70
70
|
const hidden = ['prop', 'platform', 'meta'];
|
|
71
71
|
hidden.forEach(k => delete object[k]);
|
|
@@ -5,6 +5,5 @@ export declare class Uint8ArrayType extends Type<Uint8Array | null> {
|
|
|
5
5
|
convertToDatabaseValue(value: Uint8Array): Buffer;
|
|
6
6
|
convertToJSValue(value: Buffer): Uint8Array | null;
|
|
7
7
|
compareAsType(): string;
|
|
8
|
-
ensureComparable(): boolean;
|
|
9
8
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
10
9
|
}
|
package/types/Uint8ArrayType.js
CHANGED
|
@@ -7,7 +7,7 @@ export class Uint8ArrayType extends Type {
|
|
|
7
7
|
return Buffer.from(value);
|
|
8
8
|
}
|
|
9
9
|
convertToJSValue(value) {
|
|
10
|
-
/* v8 ignore next
|
|
10
|
+
/* v8 ignore next */
|
|
11
11
|
if (!value) {
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
@@ -22,9 +22,6 @@ export class Uint8ArrayType extends Type {
|
|
|
22
22
|
compareAsType() {
|
|
23
23
|
return 'Buffer';
|
|
24
24
|
}
|
|
25
|
-
ensureComparable() {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
25
|
getColumnType(prop, platform) {
|
|
29
26
|
return platform.getBlobDeclarationSQL();
|
|
30
27
|
}
|
package/types/UuidType.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ import type { EntityProperty } from '../typings.js';
|
|
|
4
4
|
export declare class UuidType extends Type<string | null | undefined> {
|
|
5
5
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
6
6
|
compareAsType(): string;
|
|
7
|
+
convertToDatabaseValue(value: string | null | undefined, platform: Platform): string | null;
|
|
8
|
+
convertToJSValue(value: string | null | undefined, platform: Platform): string | null | undefined;
|
|
7
9
|
ensureComparable(): boolean;
|
|
8
10
|
}
|
package/types/UuidType.js
CHANGED
|
@@ -4,9 +4,21 @@ export class UuidType extends Type {
|
|
|
4
4
|
return platform.getUuidTypeDeclarationSQL(prop);
|
|
5
5
|
}
|
|
6
6
|
compareAsType() {
|
|
7
|
-
return 'string';
|
|
7
|
+
return this.platform?.compareUuids() ?? 'string';
|
|
8
|
+
}
|
|
9
|
+
convertToDatabaseValue(value, platform) {
|
|
10
|
+
if (value == null) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
return platform.convertUuidToDatabaseValue(value);
|
|
14
|
+
}
|
|
15
|
+
convertToJSValue(value, platform) {
|
|
16
|
+
if (value == null) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
return platform.convertUuidToJSValue(value);
|
|
8
20
|
}
|
|
9
21
|
ensureComparable() {
|
|
10
|
-
return
|
|
22
|
+
return this.platform?.compareUuids() !== 'string';
|
|
11
23
|
}
|
|
12
24
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -19,11 +19,12 @@ import { StringType } from './StringType.js';
|
|
|
19
19
|
import { TextType } from './TextType.js';
|
|
20
20
|
import { TimeType } from './TimeType.js';
|
|
21
21
|
import { TinyIntType } from './TinyIntType.js';
|
|
22
|
-
import { IType, TransformContext, Type } from './Type.js';
|
|
22
|
+
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;
|