@yandjin-mikro-orm/core 6.1.4-rc-sti-changes-1
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 +553 -0
- package/EntityManager.js +1736 -0
- package/LICENSE +21 -0
- package/MikroORM.d.ts +102 -0
- package/MikroORM.js +258 -0
- package/README.md +383 -0
- package/cache/CacheAdapter.d.ts +40 -0
- package/cache/CacheAdapter.js +2 -0
- package/cache/FileCacheAdapter.d.ts +31 -0
- package/cache/FileCacheAdapter.js +90 -0
- package/cache/GeneratedCacheAdapter.d.ts +25 -0
- package/cache/GeneratedCacheAdapter.js +38 -0
- package/cache/MemoryCacheAdapter.d.ts +24 -0
- package/cache/MemoryCacheAdapter.js +44 -0
- package/cache/NullCacheAdapter.d.ts +19 -0
- package/cache/NullCacheAdapter.js +30 -0
- package/cache/index.d.ts +5 -0
- package/cache/index.js +21 -0
- package/connections/Connection.d.ts +85 -0
- package/connections/Connection.js +128 -0
- package/connections/index.d.ts +1 -0
- package/connections/index.js +17 -0
- package/decorators/Check.d.ts +3 -0
- package/decorators/Check.js +17 -0
- package/decorators/CreateRequestContext.d.ts +2 -0
- package/decorators/CreateRequestContext.js +31 -0
- package/decorators/Embeddable.d.ts +8 -0
- package/decorators/Embeddable.js +15 -0
- package/decorators/Embedded.d.ts +13 -0
- package/decorators/Embedded.js +21 -0
- package/decorators/EnsureRequestContext.d.ts +2 -0
- package/decorators/EnsureRequestContext.js +26 -0
- package/decorators/Entity.d.ts +18 -0
- package/decorators/Entity.js +17 -0
- package/decorators/Enum.d.ts +9 -0
- package/decorators/Enum.js +20 -0
- package/decorators/Filter.d.ts +2 -0
- package/decorators/Filter.js +12 -0
- package/decorators/Formula.d.ts +5 -0
- package/decorators/Formula.js +19 -0
- package/decorators/Indexed.d.ts +12 -0
- package/decorators/Indexed.js +25 -0
- package/decorators/ManyToMany.d.ts +21 -0
- package/decorators/ManyToMany.js +17 -0
- package/decorators/ManyToOne.d.ts +15 -0
- package/decorators/ManyToOne.js +17 -0
- package/decorators/OneToMany.d.ts +18 -0
- package/decorators/OneToMany.js +21 -0
- package/decorators/OneToOne.d.ts +12 -0
- package/decorators/OneToOne.js +11 -0
- package/decorators/PrimaryKey.d.ts +8 -0
- package/decorators/PrimaryKey.js +24 -0
- package/decorators/Property.d.ts +218 -0
- package/decorators/Property.js +35 -0
- package/decorators/Subscriber.d.ts +1 -0
- package/decorators/Subscriber.js +2 -0
- package/decorators/hooks.d.ts +16 -0
- package/decorators/hooks.js +60 -0
- package/decorators/index.d.ts +17 -0
- package/decorators/index.js +36 -0
- package/drivers/DatabaseDriver.d.ts +72 -0
- package/drivers/DatabaseDriver.js +358 -0
- package/drivers/IDatabaseDriver.d.ts +193 -0
- package/drivers/IDatabaseDriver.js +4 -0
- package/drivers/index.d.ts +2 -0
- package/drivers/index.js +18 -0
- package/entity/ArrayCollection.d.ts +113 -0
- package/entity/ArrayCollection.js +386 -0
- package/entity/BaseEntity.d.ts +22 -0
- package/entity/BaseEntity.js +47 -0
- package/entity/Collection.d.ts +104 -0
- package/entity/Collection.js +373 -0
- package/entity/EntityAssigner.d.ts +28 -0
- package/entity/EntityAssigner.js +226 -0
- package/entity/EntityFactory.d.ts +41 -0
- package/entity/EntityFactory.js +302 -0
- package/entity/EntityHelper.d.ts +29 -0
- package/entity/EntityHelper.js +250 -0
- package/entity/EntityIdentifier.d.ts +10 -0
- package/entity/EntityIdentifier.js +19 -0
- package/entity/EntityLoader.d.ts +65 -0
- package/entity/EntityLoader.js +579 -0
- package/entity/EntityRepository.d.ts +161 -0
- package/entity/EntityRepository.js +207 -0
- package/entity/EntityValidator.d.ts +19 -0
- package/entity/EntityValidator.js +152 -0
- package/entity/Reference.d.ts +89 -0
- package/entity/Reference.js +242 -0
- package/entity/WrappedEntity.d.ts +67 -0
- package/entity/WrappedEntity.js +146 -0
- package/entity/index.d.ts +13 -0
- package/entity/index.js +29 -0
- package/entity/wrap.d.ts +15 -0
- package/entity/wrap.js +26 -0
- package/enums.d.ts +160 -0
- package/enums.js +169 -0
- package/errors.d.ts +65 -0
- package/errors.js +222 -0
- package/events/EventManager.d.ts +17 -0
- package/events/EventManager.js +77 -0
- package/events/EventSubscriber.d.ts +39 -0
- package/events/EventSubscriber.js +2 -0
- package/events/TransactionEventBroadcaster.d.ts +11 -0
- package/events/TransactionEventBroadcaster.js +17 -0
- package/events/index.d.ts +3 -0
- package/events/index.js +19 -0
- package/exceptions.d.ts +104 -0
- package/exceptions.js +130 -0
- package/hydration/Hydrator.d.ts +23 -0
- package/hydration/Hydrator.js +51 -0
- package/hydration/ObjectHydrator.d.ts +24 -0
- package/hydration/ObjectHydrator.js +332 -0
- package/hydration/index.d.ts +2 -0
- package/hydration/index.js +18 -0
- package/index.d.ts +25 -0
- package/index.js +50 -0
- package/index.mjs +192 -0
- package/logging/DefaultLogger.d.ts +32 -0
- package/logging/DefaultLogger.js +90 -0
- package/logging/Logger.d.ts +56 -0
- package/logging/Logger.js +2 -0
- package/logging/SimpleLogger.d.ts +17 -0
- package/logging/SimpleLogger.js +31 -0
- package/logging/colors.d.ts +9 -0
- package/logging/colors.js +20 -0
- package/logging/index.d.ts +4 -0
- package/logging/index.js +20 -0
- package/metadata/EntitySchema.d.ts +74 -0
- package/metadata/EntitySchema.js +293 -0
- package/metadata/MetadataDiscovery.d.ts +71 -0
- package/metadata/MetadataDiscovery.js +1244 -0
- package/metadata/MetadataProvider.d.ts +11 -0
- package/metadata/MetadataProvider.js +23 -0
- package/metadata/MetadataStorage.d.ts +22 -0
- package/metadata/MetadataStorage.js +87 -0
- package/metadata/MetadataValidator.d.ts +24 -0
- package/metadata/MetadataValidator.js +213 -0
- package/metadata/ReflectMetadataProvider.d.ts +8 -0
- package/metadata/ReflectMetadataProvider.js +48 -0
- package/metadata/index.d.ts +6 -0
- package/metadata/index.js +22 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
- package/naming-strategy/AbstractNamingStrategy.js +48 -0
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
- package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
- package/naming-strategy/MongoNamingStrategy.js +25 -0
- package/naming-strategy/NamingStrategy.d.ts +52 -0
- package/naming-strategy/NamingStrategy.js +2 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
- package/naming-strategy/index.d.ts +5 -0
- package/naming-strategy/index.js +21 -0
- package/package.json +70 -0
- package/platforms/ExceptionConverter.d.ts +5 -0
- package/platforms/ExceptionConverter.js +11 -0
- package/platforms/Platform.d.ts +201 -0
- package/platforms/Platform.js +452 -0
- package/platforms/index.d.ts +2 -0
- package/platforms/index.js +18 -0
- package/serialization/EntitySerializer.d.ts +34 -0
- package/serialization/EntitySerializer.js +206 -0
- package/serialization/EntityTransformer.d.ts +8 -0
- package/serialization/EntityTransformer.js +192 -0
- package/serialization/SerializationContext.d.ts +30 -0
- package/serialization/SerializationContext.js +111 -0
- package/serialization/index.d.ts +3 -0
- package/serialization/index.js +19 -0
- package/types/ArrayType.d.ts +13 -0
- package/types/ArrayType.js +47 -0
- package/types/BigIntType.d.ts +16 -0
- package/types/BigIntType.js +45 -0
- package/types/BlobType.d.ts +10 -0
- package/types/BlobType.js +27 -0
- package/types/BooleanType.d.ts +8 -0
- package/types/BooleanType.js +16 -0
- package/types/DateTimeType.d.ts +8 -0
- package/types/DateTimeType.js +16 -0
- package/types/DateType.d.ts +8 -0
- package/types/DateType.js +16 -0
- package/types/DecimalType.d.ts +11 -0
- package/types/DecimalType.js +22 -0
- package/types/DoubleType.d.ts +11 -0
- package/types/DoubleType.js +22 -0
- package/types/EnumArrayType.d.ts +9 -0
- package/types/EnumArrayType.js +32 -0
- package/types/EnumType.d.ts +8 -0
- package/types/EnumType.js +16 -0
- package/types/FloatType.d.ts +8 -0
- package/types/FloatType.js +16 -0
- package/types/IntegerType.d.ts +8 -0
- package/types/IntegerType.js +16 -0
- package/types/IntervalType.d.ts +8 -0
- package/types/IntervalType.js +16 -0
- package/types/JsonType.d.ts +13 -0
- package/types/JsonType.js +34 -0
- package/types/MediumIntType.d.ts +6 -0
- package/types/MediumIntType.js +10 -0
- package/types/SmallIntType.d.ts +8 -0
- package/types/SmallIntType.js +16 -0
- package/types/StringType.d.ts +8 -0
- package/types/StringType.js +16 -0
- package/types/TextType.d.ts +8 -0
- package/types/TextType.js +16 -0
- package/types/TimeType.d.ts +9 -0
- package/types/TimeType.js +23 -0
- package/types/TinyIntType.d.ts +8 -0
- package/types/TinyIntType.js +16 -0
- package/types/Type.d.ts +64 -0
- package/types/Type.js +84 -0
- package/types/Uint8ArrayType.d.ts +11 -0
- package/types/Uint8ArrayType.js +37 -0
- package/types/UnknownType.d.ts +7 -0
- package/types/UnknownType.js +13 -0
- package/types/UuidType.d.ts +7 -0
- package/types/UuidType.js +13 -0
- package/types/index.d.ts +75 -0
- package/types/index.js +77 -0
- package/typings.d.ts +767 -0
- package/typings.js +198 -0
- package/unit-of-work/ChangeSet.d.ts +34 -0
- package/unit-of-work/ChangeSet.js +62 -0
- package/unit-of-work/ChangeSetComputer.d.ts +26 -0
- package/unit-of-work/ChangeSetComputer.js +153 -0
- package/unit-of-work/ChangeSetPersister.d.ts +50 -0
- package/unit-of-work/ChangeSetPersister.js +361 -0
- package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
- package/unit-of-work/CommitOrderCalculator.js +113 -0
- package/unit-of-work/IdentityMap.d.ts +17 -0
- package/unit-of-work/IdentityMap.js +84 -0
- package/unit-of-work/UnitOfWork.d.ts +124 -0
- package/unit-of-work/UnitOfWork.js +1013 -0
- package/unit-of-work/index.d.ts +6 -0
- package/unit-of-work/index.js +22 -0
- package/utils/AbstractSchemaGenerator.d.ts +38 -0
- package/utils/AbstractSchemaGenerator.js +101 -0
- package/utils/Configuration.d.ts +390 -0
- package/utils/Configuration.js +357 -0
- package/utils/ConfigurationLoader.d.ts +29 -0
- package/utils/ConfigurationLoader.js +282 -0
- package/utils/Cursor.d.ts +77 -0
- package/utils/Cursor.js +169 -0
- package/utils/DataloaderUtils.d.ts +43 -0
- package/utils/DataloaderUtils.js +194 -0
- package/utils/EntityComparator.d.ts +73 -0
- package/utils/EntityComparator.js +568 -0
- package/utils/NullHighlighter.d.ts +4 -0
- package/utils/NullHighlighter.js +9 -0
- package/utils/QueryHelper.d.ts +28 -0
- package/utils/QueryHelper.js +228 -0
- package/utils/RawQueryFragment.d.ts +96 -0
- package/utils/RawQueryFragment.js +188 -0
- package/utils/RequestContext.d.ts +34 -0
- package/utils/RequestContext.js +54 -0
- package/utils/TransactionContext.d.ts +19 -0
- package/utils/TransactionContext.js +34 -0
- package/utils/Utils.d.ts +274 -0
- package/utils/Utils.js +1073 -0
- package/utils/clone.d.ts +6 -0
- package/utils/clone.js +127 -0
- package/utils/index.d.ts +13 -0
- package/utils/index.js +29 -0
- package/utils/upsert-utils.d.ts +6 -0
- package/utils/upsert-utils.js +33 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Platform = exports.JsonProperty = void 0;
|
|
4
|
+
const clone_1 = require("../utils/clone");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
const naming_strategy_1 = require("../naming-strategy");
|
|
7
|
+
const ExceptionConverter_1 = require("./ExceptionConverter");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const Utils_1 = require("../utils/Utils");
|
|
10
|
+
const enums_1 = require("../enums");
|
|
11
|
+
exports.JsonProperty = Symbol('JsonProperty');
|
|
12
|
+
class Platform {
|
|
13
|
+
exceptionConverter = new ExceptionConverter_1.ExceptionConverter();
|
|
14
|
+
config;
|
|
15
|
+
namingStrategy;
|
|
16
|
+
timezone;
|
|
17
|
+
usesPivotTable() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
supportsTransactions() {
|
|
21
|
+
return !this.config.get('disableTransactions');
|
|
22
|
+
}
|
|
23
|
+
usesImplicitTransactions() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
getNamingStrategy() {
|
|
27
|
+
return naming_strategy_1.UnderscoreNamingStrategy;
|
|
28
|
+
}
|
|
29
|
+
usesReturningStatement() {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
usesCascadeStatement() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/** for postgres native enums */
|
|
36
|
+
supportsNativeEnums() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
getSchemaHelper() {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
indexForeignKeys() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
allowsMultiInsert() {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether or not the driver supports retuning list of created PKs back when multi-inserting
|
|
50
|
+
*/
|
|
51
|
+
usesBatchInserts() {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether or not the driver supports updating many records at once
|
|
56
|
+
*/
|
|
57
|
+
usesBatchUpdates() {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
usesDefaultKeyword() {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Normalizes primary key wrapper to scalar value (e.g. mongodb's ObjectId to string)
|
|
65
|
+
*/
|
|
66
|
+
normalizePrimaryKey(data) {
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Converts scalar primary key representation to native driver wrapper (e.g. string to mongodb's ObjectId)
|
|
71
|
+
*/
|
|
72
|
+
denormalizePrimaryKey(data) {
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Used when serializing via toObject and toJSON methods, allows to use different PK field name (like `id` instead of `_id`)
|
|
77
|
+
*/
|
|
78
|
+
getSerializedPrimaryKeyField(field) {
|
|
79
|
+
return field;
|
|
80
|
+
}
|
|
81
|
+
usesDifferentSerializedPrimaryKey() {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns the SQL specific for the platform to get the current timestamp
|
|
86
|
+
*/
|
|
87
|
+
getCurrentTimestampSQL(length) {
|
|
88
|
+
return 'current_timestamp' + (length ? `(${length})` : '');
|
|
89
|
+
}
|
|
90
|
+
getDateTimeTypeDeclarationSQL(column = { length: 0 }) {
|
|
91
|
+
return 'datetime' + (column.length ? `(${column.length})` : '');
|
|
92
|
+
}
|
|
93
|
+
getDefaultDateTimeLength() {
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
getDateTypeDeclarationSQL(length) {
|
|
97
|
+
return 'date' + (length ? `(${length})` : '');
|
|
98
|
+
}
|
|
99
|
+
getTimeTypeDeclarationSQL(length) {
|
|
100
|
+
return 'time' + (length ? `(${length})` : '');
|
|
101
|
+
}
|
|
102
|
+
getRegExpOperator(val, flags) {
|
|
103
|
+
return 'regexp';
|
|
104
|
+
}
|
|
105
|
+
getRegExpValue(val) {
|
|
106
|
+
if (val.flags.includes('i')) {
|
|
107
|
+
return { $re: `(?i)${val.source}` };
|
|
108
|
+
}
|
|
109
|
+
return { $re: val.source };
|
|
110
|
+
}
|
|
111
|
+
isAllowedTopLevelOperator(operator) {
|
|
112
|
+
return operator === '$not';
|
|
113
|
+
}
|
|
114
|
+
quoteVersionValue(value, prop) {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
getDefaultVersionLength() {
|
|
118
|
+
return 3;
|
|
119
|
+
}
|
|
120
|
+
allowsComparingTuples() {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
allowsUniqueBatchUpdates() {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
isBigIntProperty(prop) {
|
|
127
|
+
return prop.columnTypes && prop.columnTypes[0] === 'bigint';
|
|
128
|
+
}
|
|
129
|
+
isRaw(value) {
|
|
130
|
+
return typeof value === 'object' && value !== null && '__raw' in value;
|
|
131
|
+
}
|
|
132
|
+
getDefaultSchemaName() {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
getBooleanTypeDeclarationSQL() {
|
|
136
|
+
return 'boolean';
|
|
137
|
+
}
|
|
138
|
+
getIntegerTypeDeclarationSQL(column) {
|
|
139
|
+
return 'int';
|
|
140
|
+
}
|
|
141
|
+
getSmallIntTypeDeclarationSQL(column) {
|
|
142
|
+
return 'smallint';
|
|
143
|
+
}
|
|
144
|
+
getMediumIntTypeDeclarationSQL(column) {
|
|
145
|
+
return 'mediumint';
|
|
146
|
+
}
|
|
147
|
+
getTinyIntTypeDeclarationSQL(column) {
|
|
148
|
+
return 'tinyint';
|
|
149
|
+
}
|
|
150
|
+
getBigIntTypeDeclarationSQL(column) {
|
|
151
|
+
return 'bigint';
|
|
152
|
+
}
|
|
153
|
+
getVarcharTypeDeclarationSQL(column) {
|
|
154
|
+
return `varchar(${column.length ?? 255})`;
|
|
155
|
+
}
|
|
156
|
+
getIntervalTypeDeclarationSQL(column) {
|
|
157
|
+
return 'interval' + (column.length ? `(${column.length})` : '');
|
|
158
|
+
}
|
|
159
|
+
getTextTypeDeclarationSQL(_column) {
|
|
160
|
+
return `text`;
|
|
161
|
+
}
|
|
162
|
+
getEnumTypeDeclarationSQL(column) {
|
|
163
|
+
if (column.items?.every(item => Utils_1.Utils.isString(item))) {
|
|
164
|
+
return `enum('${column.items.join("','")}')`;
|
|
165
|
+
}
|
|
166
|
+
return this.getTinyIntTypeDeclarationSQL(column);
|
|
167
|
+
}
|
|
168
|
+
getFloatDeclarationSQL() {
|
|
169
|
+
return 'float';
|
|
170
|
+
}
|
|
171
|
+
getDoubleDeclarationSQL() {
|
|
172
|
+
return 'double';
|
|
173
|
+
}
|
|
174
|
+
getDecimalTypeDeclarationSQL(column) {
|
|
175
|
+
const precision = column.precision ?? 10;
|
|
176
|
+
const scale = column.scale ?? 0;
|
|
177
|
+
return `numeric(${precision},${scale})`;
|
|
178
|
+
}
|
|
179
|
+
getUuidTypeDeclarationSQL(column) {
|
|
180
|
+
column.length ??= 36;
|
|
181
|
+
return this.getVarcharTypeDeclarationSQL(column);
|
|
182
|
+
}
|
|
183
|
+
extractSimpleType(type) {
|
|
184
|
+
return type.toLowerCase().match(/[^(), ]+/)[0];
|
|
185
|
+
}
|
|
186
|
+
getMappedType(type) {
|
|
187
|
+
const mappedType = this.config.get('discovery').getMappedType?.(type, this);
|
|
188
|
+
return mappedType ?? this.getDefaultMappedType(type);
|
|
189
|
+
}
|
|
190
|
+
getDefaultMappedType(type) {
|
|
191
|
+
if (type.endsWith('[]')) {
|
|
192
|
+
return types_1.Type.getType(types_1.ArrayType);
|
|
193
|
+
}
|
|
194
|
+
switch (this.extractSimpleType(type)) {
|
|
195
|
+
case 'string':
|
|
196
|
+
case 'varchar': return types_1.Type.getType(types_1.StringType);
|
|
197
|
+
case 'interval': return types_1.Type.getType(types_1.IntervalType);
|
|
198
|
+
case 'text': return types_1.Type.getType(types_1.TextType);
|
|
199
|
+
case 'number': return types_1.Type.getType(types_1.IntegerType);
|
|
200
|
+
case 'bigint': return types_1.Type.getType(types_1.BigIntType);
|
|
201
|
+
case 'smallint': return types_1.Type.getType(types_1.SmallIntType);
|
|
202
|
+
case 'tinyint': return types_1.Type.getType(types_1.TinyIntType);
|
|
203
|
+
case 'mediumint': return types_1.Type.getType(types_1.MediumIntType);
|
|
204
|
+
case 'float': return types_1.Type.getType(types_1.FloatType);
|
|
205
|
+
case 'double': return types_1.Type.getType(types_1.DoubleType);
|
|
206
|
+
case 'integer': return types_1.Type.getType(types_1.IntegerType);
|
|
207
|
+
case 'decimal':
|
|
208
|
+
case 'numeric': return types_1.Type.getType(types_1.DecimalType);
|
|
209
|
+
case 'boolean': return types_1.Type.getType(types_1.BooleanType);
|
|
210
|
+
case 'blob':
|
|
211
|
+
case 'buffer': return types_1.Type.getType(types_1.BlobType);
|
|
212
|
+
case 'uint8array': return types_1.Type.getType(types_1.Uint8ArrayType);
|
|
213
|
+
case 'uuid': return types_1.Type.getType(types_1.UuidType);
|
|
214
|
+
case 'date': return types_1.Type.getType(types_1.DateType);
|
|
215
|
+
case 'datetime': return types_1.Type.getType(types_1.DateTimeType);
|
|
216
|
+
case 'timestamp': return types_1.Type.getType(types_1.DateTimeType);
|
|
217
|
+
case 'time': return types_1.Type.getType(types_1.TimeType);
|
|
218
|
+
case 'object':
|
|
219
|
+
case 'json': return types_1.Type.getType(types_1.JsonType);
|
|
220
|
+
case 'enum': return types_1.Type.getType(types_1.EnumType);
|
|
221
|
+
default: return types_1.Type.getType(types_1.UnknownType);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
supportsMultipleStatements() {
|
|
225
|
+
return this.config.get('multipleStatements');
|
|
226
|
+
}
|
|
227
|
+
getArrayDeclarationSQL() {
|
|
228
|
+
return 'text';
|
|
229
|
+
}
|
|
230
|
+
marshallArray(values) {
|
|
231
|
+
return values.join(',');
|
|
232
|
+
}
|
|
233
|
+
unmarshallArray(value) {
|
|
234
|
+
if (value === '') {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
return value.split(',');
|
|
238
|
+
}
|
|
239
|
+
getBlobDeclarationSQL() {
|
|
240
|
+
return 'blob';
|
|
241
|
+
}
|
|
242
|
+
getJsonDeclarationSQL() {
|
|
243
|
+
return 'json';
|
|
244
|
+
}
|
|
245
|
+
getSearchJsonPropertySQL(path, type, aliased) {
|
|
246
|
+
return path;
|
|
247
|
+
}
|
|
248
|
+
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
249
|
+
return path.join('.');
|
|
250
|
+
}
|
|
251
|
+
/* istanbul ignore next */
|
|
252
|
+
getJsonIndexDefinition(index) {
|
|
253
|
+
return index.columnNames;
|
|
254
|
+
}
|
|
255
|
+
getFullTextWhereClause(prop) {
|
|
256
|
+
throw new Error('Full text searching is not supported by this driver.');
|
|
257
|
+
}
|
|
258
|
+
supportsCreatingFullTextIndex() {
|
|
259
|
+
throw new Error('Full text searching is not supported by this driver.');
|
|
260
|
+
}
|
|
261
|
+
getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
|
|
262
|
+
throw new Error('Full text searching is not supported by this driver.');
|
|
263
|
+
}
|
|
264
|
+
convertsJsonAutomatically() {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
convertJsonToDatabaseValue(value, context) {
|
|
268
|
+
return JSON.stringify(value);
|
|
269
|
+
}
|
|
270
|
+
convertJsonToJSValue(value) {
|
|
271
|
+
return (0, Utils_1.parseJsonSafe)(value);
|
|
272
|
+
}
|
|
273
|
+
convertIntervalToJSValue(value) {
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
convertIntervalToDatabaseValue(value) {
|
|
277
|
+
return value;
|
|
278
|
+
}
|
|
279
|
+
parseDate(value) {
|
|
280
|
+
return new Date(value);
|
|
281
|
+
}
|
|
282
|
+
getRepositoryClass() {
|
|
283
|
+
return entity_1.EntityRepository;
|
|
284
|
+
}
|
|
285
|
+
getDefaultCharset() {
|
|
286
|
+
return 'utf8';
|
|
287
|
+
}
|
|
288
|
+
getExceptionConverter() {
|
|
289
|
+
return this.exceptionConverter;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Allows to register extensions of the driver automatically (e.g. `SchemaGenerator` extension in SQL drivers).
|
|
293
|
+
*/
|
|
294
|
+
lookupExtensions(orm) {
|
|
295
|
+
// no extensions by default
|
|
296
|
+
}
|
|
297
|
+
/* istanbul ignore next: kept for type inference only */
|
|
298
|
+
getSchemaGenerator(driver, em) {
|
|
299
|
+
throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
|
|
300
|
+
}
|
|
301
|
+
processDateProperty(value) {
|
|
302
|
+
return value;
|
|
303
|
+
}
|
|
304
|
+
quoteIdentifier(id, quote = '`') {
|
|
305
|
+
return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
|
|
306
|
+
}
|
|
307
|
+
quoteValue(value) {
|
|
308
|
+
return value;
|
|
309
|
+
}
|
|
310
|
+
formatQuery(sql, params) {
|
|
311
|
+
if (params.length === 0) {
|
|
312
|
+
return sql;
|
|
313
|
+
}
|
|
314
|
+
// fast string replace without regexps
|
|
315
|
+
let j = 0;
|
|
316
|
+
let pos = 0;
|
|
317
|
+
let ret = '';
|
|
318
|
+
if (sql[0] === '?') {
|
|
319
|
+
if (sql[1] === '?') {
|
|
320
|
+
ret += this.quoteIdentifier(params[j++]);
|
|
321
|
+
pos = 2;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
ret += this.quoteValue(params[j++]);
|
|
325
|
+
pos = 1;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
while (pos < sql.length) {
|
|
329
|
+
const idx = sql.indexOf('?', pos + 1);
|
|
330
|
+
if (idx === -1) {
|
|
331
|
+
ret += sql.substring(pos, sql.length);
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
if (sql.substring(idx - 1, idx + 1) === '\\?') {
|
|
335
|
+
ret += sql.substring(pos, idx - 1) + '?';
|
|
336
|
+
pos = idx + 1;
|
|
337
|
+
}
|
|
338
|
+
else if (sql.substring(idx, idx + 2) === '??') {
|
|
339
|
+
ret += sql.substring(pos, idx) + this.quoteIdentifier(params[j++]);
|
|
340
|
+
pos = idx + 2;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
ret += sql.substring(pos, idx) + this.quoteValue(params[j++]);
|
|
344
|
+
pos = idx + 1;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return ret;
|
|
348
|
+
}
|
|
349
|
+
cloneEmbeddable(data) {
|
|
350
|
+
const copy = (0, clone_1.clone)(data);
|
|
351
|
+
// tag the copy so we know it should be stringified when quoting (so we know how to treat JSON arrays)
|
|
352
|
+
Object.defineProperty(copy, exports.JsonProperty, { enumerable: false, value: true });
|
|
353
|
+
return copy;
|
|
354
|
+
}
|
|
355
|
+
setConfig(config) {
|
|
356
|
+
this.config = config;
|
|
357
|
+
this.namingStrategy = config.getNamingStrategy();
|
|
358
|
+
if (this.config.get('forceUtcTimezone')) {
|
|
359
|
+
this.timezone = 'Z';
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
this.timezone = this.config.get('timezone');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
getConfig() {
|
|
366
|
+
return this.config;
|
|
367
|
+
}
|
|
368
|
+
getTimezone() {
|
|
369
|
+
return this.timezone;
|
|
370
|
+
}
|
|
371
|
+
isNumericColumn(mappedType) {
|
|
372
|
+
return [types_1.IntegerType, types_1.SmallIntType, types_1.BigIntType].some(t => mappedType instanceof t);
|
|
373
|
+
}
|
|
374
|
+
supportsUnsigned() {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Returns the default name of index for the given columns
|
|
379
|
+
*/
|
|
380
|
+
getIndexName(tableName, columns, type) {
|
|
381
|
+
return this.namingStrategy.indexName(tableName, columns, type);
|
|
382
|
+
}
|
|
383
|
+
/* istanbul ignore next */
|
|
384
|
+
getDefaultPrimaryName(tableName, columns) {
|
|
385
|
+
return this.namingStrategy.indexName(tableName, columns, 'primary');
|
|
386
|
+
}
|
|
387
|
+
supportsCustomPrimaryKeyNames() {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
isPopulated(key, populate) {
|
|
391
|
+
return populate === true || (populate !== false && populate.some(p => p.field === key || p.all));
|
|
392
|
+
}
|
|
393
|
+
shouldHaveColumn(prop, populate, exclude, includeFormulas = true) {
|
|
394
|
+
if (exclude?.includes(prop.name)) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
if (exclude?.find(k => k.startsWith(`${prop.name}.`) && !this.isPopulated(prop.name, populate))) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
if (prop.formula) {
|
|
401
|
+
return includeFormulas && (!prop.lazy || this.isPopulated(prop.name, populate));
|
|
402
|
+
}
|
|
403
|
+
if (prop.persist === false) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
if (prop.lazy && (populate === false || (populate !== true && !populate.some(p => p.field === prop.name)))) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
if ([enums_1.ReferenceKind.SCALAR, enums_1.ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
if (prop.kind === enums_1.ReferenceKind.EMBEDDED) {
|
|
413
|
+
return !!prop.object;
|
|
414
|
+
}
|
|
415
|
+
return prop.kind === enums_1.ReferenceKind.ONE_TO_ONE && prop.owner;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Currently not supported due to how knex does complex sqlite diffing (always based on current schema)
|
|
419
|
+
*/
|
|
420
|
+
supportsDownMigrations() {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
validateMetadata(meta) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Generates a custom order by statement given a set of in order values, eg.
|
|
428
|
+
* ORDER BY (CASE WHEN priority = 'low' THEN 1 WHEN priority = 'medium' THEN 2 ELSE NULL END)
|
|
429
|
+
*/
|
|
430
|
+
generateCustomOrder(escapedColumn, values) {
|
|
431
|
+
throw new Error('Not supported');
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* @internal
|
|
435
|
+
*/
|
|
436
|
+
castColumn(prop) {
|
|
437
|
+
return '';
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* @internal
|
|
441
|
+
*/
|
|
442
|
+
castJsonValue(prop) {
|
|
443
|
+
return '';
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* @internal
|
|
447
|
+
*/
|
|
448
|
+
clone() {
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
exports.Platform = Platform;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Platform"), exports);
|
|
18
|
+
__exportStar(require("./ExceptionConverter"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ArrayElement, AutoPath, CleanTypeConfig, EntityDTO, FromEntityType, Loaded, TypeConfig, UnboxArray } from '../typings';
|
|
2
|
+
export declare class EntitySerializer {
|
|
3
|
+
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>): EntityDTO<Loaded<T, P>>;
|
|
4
|
+
private static propertyName;
|
|
5
|
+
private static processProperty;
|
|
6
|
+
private static extractChildOptions;
|
|
7
|
+
private static processEntity;
|
|
8
|
+
private static processCollection;
|
|
9
|
+
}
|
|
10
|
+
export interface SerializeOptions<T, P extends string = never, E extends string = never> {
|
|
11
|
+
/** Specify which relation should be serialized as populated and which as a FK. */
|
|
12
|
+
populate?: readonly AutoPath<T, P, '*'>[];
|
|
13
|
+
/** Specify which properties should be omitted. */
|
|
14
|
+
exclude?: readonly AutoPath<T, E>[];
|
|
15
|
+
/** Enforce unpopulated references to be returned as objects, e.g. `{ author: { id: 1 } }` instead of `{ author: 1 }`. */
|
|
16
|
+
forceObject?: boolean;
|
|
17
|
+
/** Ignore custom property serializers. */
|
|
18
|
+
ignoreSerializers?: boolean;
|
|
19
|
+
/** Skip properties with `null` value. */
|
|
20
|
+
skipNull?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Converts entity instance to POJO, converting the `Collection`s to arrays and unwrapping the `Reference` wrapper, while respecting the serialization options.
|
|
24
|
+
* This method accepts either a single entity or an array of entities, and returns the corresponding POJO or an array of POJO.
|
|
25
|
+
* To serialize a single entity, you can also use `wrap(entity).serialize()` which handles a single entity only.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const dtos = serialize([user1, user, ...], { exclude: ['id', 'email'], forceObject: true });
|
|
29
|
+
* const [dto2, dto3] = serialize([user2, user3], { exclude: ['id', 'email'], forceObject: true });
|
|
30
|
+
* const dto1 = serialize(user, { exclude: ['id', 'email'], forceObject: true });
|
|
31
|
+
* const dto2 = wrap(user).serialize({ exclude: ['id', 'email'], forceObject: true });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ? EntityDTO<Loaded<ArrayElement<Naked>, Populate>, CleanTypeConfig<Config>>[] : EntityDTO<Loaded<Naked, Populate>, CleanTypeConfig<Config>>;
|