@mikro-orm/core 7.0.0-dev.23 → 7.0.0-dev.230
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 +91 -59
- package/EntityManager.js +303 -251
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -143
- package/README.md +2 -0
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +17 -8
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +0 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +21 -12
- package/drivers/DatabaseDriver.d.ts +25 -16
- package/drivers/DatabaseDriver.js +118 -35
- package/drivers/IDatabaseDriver.d.ts +42 -19
- package/entity/BaseEntity.d.ts +61 -2
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +101 -29
- package/entity/Collection.js +436 -104
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +26 -18
- package/entity/EntityFactory.d.ts +7 -1
- package/entity/EntityFactory.js +83 -54
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +48 -15
- package/entity/EntityLoader.d.ts +7 -6
- package/entity/EntityLoader.js +215 -89
- package/entity/EntityRepository.d.ts +27 -7
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +1 -5
- package/entity/Reference.js +21 -12
- package/entity/WrappedEntity.d.ts +0 -5
- package/entity/WrappedEntity.js +2 -7
- package/entity/defineEntity.d.ts +380 -310
- package/entity/defineEntity.js +124 -273
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.js +1 -1
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/enums.d.ts +8 -6
- package/enums.js +2 -1
- package/errors.d.ts +20 -10
- package/errors.js +55 -23
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +87 -35
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +1 -0
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/index.d.ts +1 -0
- package/logging/index.js +1 -0
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +92 -33
- package/metadata/MetadataDiscovery.d.ts +64 -9
- package/metadata/MetadataDiscovery.js +778 -325
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +46 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +70 -37
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +196 -41
- 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 +1 -1
- package/metadata/types.d.ts +526 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +20 -2
- 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/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -11
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +7 -14
- package/platforms/Platform.js +20 -43
- package/serialization/EntitySerializer.d.ts +5 -0
- package/serialization/EntitySerializer.js +47 -27
- package/serialization/EntityTransformer.js +28 -18
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +3 -3
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.d.ts +8 -6
- 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.d.ts +6 -4
- 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/index.d.ts +1 -1
- package/typings.d.ts +381 -171
- package/typings.js +97 -44
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +4 -5
- package/unit-of-work/ChangeSetComputer.d.ts +1 -3
- package/unit-of-work/ChangeSetComputer.js +35 -14
- package/unit-of-work/ChangeSetPersister.d.ts +7 -3
- package/unit-of-work/ChangeSetPersister.js +83 -25
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +27 -3
- package/unit-of-work/UnitOfWork.js +258 -92
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +28 -17
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +795 -209
- package/utils/Configuration.js +150 -192
- package/utils/ConfigurationLoader.d.ts +1 -54
- package/utils/ConfigurationLoader.js +1 -352
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +24 -11
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +29 -12
- package/utils/EntityComparator.d.ts +16 -9
- package/utils/EntityComparator.js +158 -58
- package/utils/QueryHelper.d.ts +18 -6
- package/utils/QueryHelper.js +76 -23
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +35 -71
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +28 -4
- package/utils/Utils.d.ts +14 -127
- package/utils/Utils.js +85 -397
- package/utils/clone.js +8 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +97 -0
- package/utils/fs-utils.d.ts +33 -0
- package/utils/fs-utils.js +192 -0
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -1
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +46 -3
- 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
|
@@ -15,8 +15,8 @@ function isVisible(meta, propName, options) {
|
|
|
15
15
|
if (options.exclude?.find(item => item === propName)) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
|
-
const visible = prop && !prop.hidden;
|
|
19
|
-
const prefixed = prop && !prop.primary && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
18
|
+
const visible = prop && !(prop.hidden && !options.includeHidden);
|
|
19
|
+
const prefixed = prop && !prop.primary && !prop.accessor && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
20
20
|
return visible && !prefixed;
|
|
21
21
|
}
|
|
22
22
|
function isPopulated(propName, options) {
|
|
@@ -41,23 +41,41 @@ export class EntitySerializer {
|
|
|
41
41
|
}
|
|
42
42
|
const root = wrapped.__serializationContext.root;
|
|
43
43
|
const ret = {};
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const props = new Set();
|
|
45
|
+
if (meta.serializedPrimaryKey && !meta.compositePK) {
|
|
46
|
+
props.add(meta.serializedPrimaryKey);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
meta.primaryKeys.forEach(pk => props.add(pk));
|
|
50
|
+
}
|
|
51
|
+
if (wrapped.isInitialized() || !wrapped.hasPrimaryKey()) {
|
|
52
|
+
const entityKeys = new Set(Object.keys(entity));
|
|
53
|
+
for (const prop of meta.props) {
|
|
54
|
+
if (entityKeys.has(prop.name) || (prop.getter && prop.accessor === prop.name)) {
|
|
55
|
+
props.add(prop.name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const key of entityKeys) {
|
|
59
|
+
if (!meta.properties[key]) {
|
|
60
|
+
props.add(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
46
64
|
const visited = root.visited.has(entity);
|
|
47
65
|
if (!visited) {
|
|
48
66
|
root.visited.add(entity);
|
|
49
67
|
}
|
|
50
|
-
for (const prop of
|
|
68
|
+
for (const prop of props) {
|
|
51
69
|
if (!isVisible(meta, prop, options)) {
|
|
52
70
|
continue;
|
|
53
71
|
}
|
|
54
|
-
const cycle = root.visit(meta.
|
|
72
|
+
const cycle = root.visit(meta.class, prop);
|
|
55
73
|
if (cycle && visited) {
|
|
56
74
|
continue;
|
|
57
75
|
}
|
|
58
76
|
const val = this.processProperty(prop, entity, options);
|
|
59
77
|
if (!cycle) {
|
|
60
|
-
root.leave(meta.
|
|
78
|
+
root.leave(meta.class, prop);
|
|
61
79
|
}
|
|
62
80
|
if (options.skipNull && Utils.isPlainObject(val)) {
|
|
63
81
|
Utils.dropUndefinedProperties(val, null);
|
|
@@ -67,7 +85,7 @@ export class EntitySerializer {
|
|
|
67
85
|
}
|
|
68
86
|
const visible = typeof val !== 'undefined' && !(val === null && options.skipNull);
|
|
69
87
|
if (visible) {
|
|
70
|
-
ret[this.propertyName(meta, prop
|
|
88
|
+
ret[this.propertyName(meta, prop)] = val;
|
|
71
89
|
}
|
|
72
90
|
}
|
|
73
91
|
if (contextCreated) {
|
|
@@ -81,26 +99,26 @@ export class EntitySerializer {
|
|
|
81
99
|
if (prop.getterName != null) {
|
|
82
100
|
const visible = entity[prop.getterName] instanceof Function && isVisible(meta, prop.name, options);
|
|
83
101
|
if (visible) {
|
|
84
|
-
ret[this.propertyName(meta, prop.name
|
|
102
|
+
ret[this.propertyName(meta, prop.name)] = this.processProperty(prop.getterName, entity, options);
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
else {
|
|
88
106
|
// decorated getters
|
|
89
107
|
const visible = typeof entity[prop.name] !== 'undefined' && isVisible(meta, prop.name, options);
|
|
90
108
|
if (visible) {
|
|
91
|
-
ret[this.propertyName(meta, prop.name
|
|
109
|
+
ret[this.propertyName(meta, prop.name)] = this.processProperty(prop.name, entity, options);
|
|
92
110
|
}
|
|
93
111
|
}
|
|
94
112
|
}
|
|
95
113
|
return ret;
|
|
96
114
|
}
|
|
97
|
-
static propertyName(meta, prop
|
|
98
|
-
/* v8 ignore next
|
|
115
|
+
static propertyName(meta, prop) {
|
|
116
|
+
/* v8 ignore next */
|
|
99
117
|
if (meta.properties[prop]?.serializedName) {
|
|
100
118
|
return meta.properties[prop].serializedName;
|
|
101
119
|
}
|
|
102
|
-
if (meta.properties[prop]?.primary &&
|
|
103
|
-
return
|
|
120
|
+
if (meta.properties[prop]?.primary && meta.serializedPrimaryKey) {
|
|
121
|
+
return meta.serializedPrimaryKey;
|
|
104
122
|
}
|
|
105
123
|
return prop;
|
|
106
124
|
}
|
|
@@ -119,7 +137,7 @@ export class EntitySerializer {
|
|
|
119
137
|
}
|
|
120
138
|
return returnValue;
|
|
121
139
|
}
|
|
122
|
-
/* v8 ignore next
|
|
140
|
+
/* v8 ignore next */
|
|
123
141
|
if (!options.ignoreSerializers && serializer) {
|
|
124
142
|
return serializer(value);
|
|
125
143
|
}
|
|
@@ -132,7 +150,7 @@ export class EntitySerializer {
|
|
|
132
150
|
if (Utils.isScalarReference(value)) {
|
|
133
151
|
return value.unwrap();
|
|
134
152
|
}
|
|
135
|
-
/* v8 ignore next
|
|
153
|
+
/* v8 ignore next */
|
|
136
154
|
if (property?.kind === ReferenceKind.EMBEDDED) {
|
|
137
155
|
if (Array.isArray(value)) {
|
|
138
156
|
return value.map(item => helper(item).toJSON());
|
|
@@ -141,12 +159,20 @@ export class EntitySerializer {
|
|
|
141
159
|
return helper(value).toJSON();
|
|
142
160
|
}
|
|
143
161
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return customType.toJSON(value, wrapped.__platform);
|
|
162
|
+
if (property.customType) {
|
|
163
|
+
return this.processCustomType(value, property, wrapped.__platform, options.convertCustomTypes);
|
|
147
164
|
}
|
|
148
165
|
return wrapped.__platform.normalizePrimaryKey(value);
|
|
149
166
|
}
|
|
167
|
+
static processCustomType(value, prop, platform, convertCustomTypes) {
|
|
168
|
+
if (!prop.customType) {
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
if (convertCustomTypes) {
|
|
172
|
+
return prop.customType.convertToDatabaseValue(value, platform, { mode: 'serialization' });
|
|
173
|
+
}
|
|
174
|
+
return prop.customType.toJSON(value, platform);
|
|
175
|
+
}
|
|
150
176
|
static extractChildOptions(options, prop) {
|
|
151
177
|
return {
|
|
152
178
|
...options,
|
|
@@ -165,10 +191,7 @@ export class EntitySerializer {
|
|
|
165
191
|
if (expand) {
|
|
166
192
|
return this.serialize(child, childOptions);
|
|
167
193
|
}
|
|
168
|
-
|
|
169
|
-
if (prop.customType) {
|
|
170
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
171
|
-
}
|
|
194
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
172
195
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
173
196
|
return Utils.primaryKeyToObject(meta, pk, visible);
|
|
174
197
|
}
|
|
@@ -192,10 +215,7 @@ export class EntitySerializer {
|
|
|
192
215
|
if (populated || !wrapped.__managed) {
|
|
193
216
|
return this.serialize(item, this.extractChildOptions(options, prop.name));
|
|
194
217
|
}
|
|
195
|
-
|
|
196
|
-
if (prop.customType) {
|
|
197
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
198
|
-
}
|
|
218
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
199
219
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
200
220
|
return Utils.primaryKeyToObject(wrapped.__meta, pk);
|
|
201
221
|
}
|
|
@@ -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,49 @@ 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
|
-
const partiallyLoaded = root.isPartiallyLoaded(meta.
|
|
60
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop);
|
|
61
|
+
const partiallyLoaded = root.isPartiallyLoaded(meta.class, prop);
|
|
52
62
|
const isPrimary = includePrimaryKeys && meta.properties[prop].primary;
|
|
53
63
|
if (!partiallyLoaded && !populated && !isPrimary) {
|
|
54
64
|
continue;
|
|
55
65
|
}
|
|
56
|
-
const cycle = root.visit(meta.
|
|
66
|
+
const cycle = root.visit(meta.class, prop);
|
|
57
67
|
if (cycle && visited) {
|
|
58
68
|
continue;
|
|
59
69
|
}
|
|
60
70
|
const val = EntityTransformer.processProperty(prop, entity, raw, populated);
|
|
61
71
|
if (!cycle) {
|
|
62
|
-
root.leave(meta.
|
|
72
|
+
root.leave(meta.class, prop);
|
|
63
73
|
}
|
|
64
74
|
if (isRaw(val)) {
|
|
65
75
|
throw new Error(`Trying to serialize raw SQL fragment: '${val.sql}'`);
|
|
@@ -67,7 +77,7 @@ export class EntityTransformer {
|
|
|
67
77
|
if (typeof val === 'undefined') {
|
|
68
78
|
continue;
|
|
69
79
|
}
|
|
70
|
-
ret[this.propertyName(meta, prop,
|
|
80
|
+
ret[this.propertyName(meta, prop, raw)] = val;
|
|
71
81
|
}
|
|
72
82
|
if (!wrapped.isInitialized() && wrapped.hasPrimaryKey()) {
|
|
73
83
|
return ret;
|
|
@@ -76,17 +86,17 @@ export class EntityTransformer {
|
|
|
76
86
|
// decorated get methods
|
|
77
87
|
if (prop.getterName != null) {
|
|
78
88
|
const visible = !prop.hidden && entity[prop.getterName] instanceof Function;
|
|
79
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
89
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop.name);
|
|
80
90
|
if (visible) {
|
|
81
|
-
ret[this.propertyName(meta, prop.name,
|
|
91
|
+
ret[this.propertyName(meta, prop.name, raw)] = this.processProperty(prop.getterName, entity, raw, populated);
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
else {
|
|
85
95
|
// decorated getters
|
|
86
96
|
const visible = !prop.hidden && typeof entity[prop.name] !== 'undefined';
|
|
87
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
97
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop.name);
|
|
88
98
|
if (visible) {
|
|
89
|
-
ret[this.propertyName(meta, prop.name,
|
|
99
|
+
ret[this.propertyName(meta, prop.name, raw)] = this.processProperty(prop.name, entity, raw, populated);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
}
|
|
@@ -95,15 +105,15 @@ export class EntityTransformer {
|
|
|
95
105
|
}
|
|
96
106
|
return ret;
|
|
97
107
|
}
|
|
98
|
-
static propertyName(meta, prop,
|
|
108
|
+
static propertyName(meta, prop, raw) {
|
|
99
109
|
if (raw) {
|
|
100
110
|
return prop;
|
|
101
111
|
}
|
|
102
112
|
if (meta.properties[prop].serializedName) {
|
|
103
113
|
return meta.properties[prop].serializedName;
|
|
104
114
|
}
|
|
105
|
-
if (meta.properties[prop].primary &&
|
|
106
|
-
return
|
|
115
|
+
if (meta.properties[prop].primary && meta.serializedPrimaryKey) {
|
|
116
|
+
return meta.serializedPrimaryKey;
|
|
107
117
|
}
|
|
108
118
|
return prop;
|
|
109
119
|
}
|
|
@@ -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,7 +98,7 @@ 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
|
}
|
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.d.ts
CHANGED
|
@@ -5,13 +5,15 @@ import type { EntityProperty } from '../typings.js';
|
|
|
5
5
|
* This type will automatically convert string values returned from the database to native JS bigints (default)
|
|
6
6
|
* or numbers (safe only for values up to `Number.MAX_SAFE_INTEGER`), or strings, depending on the `mode`.
|
|
7
7
|
*/
|
|
8
|
-
export declare class BigIntType extends
|
|
9
|
-
mode?:
|
|
10
|
-
constructor(mode?:
|
|
11
|
-
convertToDatabaseValue(value:
|
|
12
|
-
convertToJSValue(value: string | bigint | null | undefined):
|
|
13
|
-
toJSON(value:
|
|
8
|
+
export declare class BigIntType<Mode extends 'bigint' | 'number' | 'string' = 'bigint'> extends Type<JSTypeByMode<Mode> | null | undefined, string | null | undefined> {
|
|
9
|
+
mode?: Mode | undefined;
|
|
10
|
+
constructor(mode?: Mode | undefined);
|
|
11
|
+
convertToDatabaseValue(value: JSTypeByMode<Mode> | null | undefined): string | null | undefined;
|
|
12
|
+
convertToJSValue(value: string | bigint | null | undefined): JSTypeByMode<Mode> | null | undefined;
|
|
13
|
+
toJSON(value: JSTypeByMode<Mode> | null | undefined): JSTypeByMode<Mode> | null | undefined;
|
|
14
14
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
15
15
|
compareAsType(): string;
|
|
16
16
|
compareValues(a: string, b: string): boolean;
|
|
17
17
|
}
|
|
18
|
+
type JSTypeByMode<Mode extends 'bigint' | 'number' | 'string'> = Mode extends 'bigint' ? bigint : Mode extends 'number' ? number : string;
|
|
19
|
+
export {};
|
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.d.ts
CHANGED
|
@@ -4,12 +4,14 @@ import type { EntityProperty } from '../typings.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Type that maps an SQL DECIMAL to a JS string or number.
|
|
6
6
|
*/
|
|
7
|
-
export declare class DecimalType extends
|
|
8
|
-
mode?:
|
|
9
|
-
constructor(mode?:
|
|
10
|
-
convertToJSValue(value: string):
|
|
7
|
+
export declare class DecimalType<Mode extends 'number' | 'string' = 'string'> extends Type<JSTypeByMode<Mode>, string> {
|
|
8
|
+
mode?: Mode | undefined;
|
|
9
|
+
constructor(mode?: Mode | undefined);
|
|
10
|
+
convertToJSValue(value: string): JSTypeByMode<Mode>;
|
|
11
11
|
compareValues(a: string, b: string): boolean;
|
|
12
12
|
private format;
|
|
13
13
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
14
14
|
compareAsType(): string;
|
|
15
15
|
}
|
|
16
|
+
type JSTypeByMode<Mode extends 'number' | 'string'> = Mode extends 'number' ? number : string;
|
|
17
|
+
export {};
|
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/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ 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';
|