@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,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultLogger = void 0;
|
|
4
|
+
const colors_1 = require("./colors");
|
|
5
|
+
class DefaultLogger {
|
|
6
|
+
options;
|
|
7
|
+
debugMode;
|
|
8
|
+
writer;
|
|
9
|
+
usesReplicas;
|
|
10
|
+
highlighter;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.debugMode = this.options.debugMode ?? false;
|
|
14
|
+
this.writer = this.options.writer;
|
|
15
|
+
this.usesReplicas = this.options.usesReplicas;
|
|
16
|
+
this.highlighter = this.options.highlighter;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
log(namespace, message, context) {
|
|
22
|
+
if (!this.isEnabled(namespace, context)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// clean up the whitespace
|
|
26
|
+
message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
|
|
27
|
+
// use red for error levels
|
|
28
|
+
if (context?.level === 'error') {
|
|
29
|
+
message = colors_1.colors.red(message);
|
|
30
|
+
}
|
|
31
|
+
// use yellow for warning levels
|
|
32
|
+
if (context?.level === 'warning') {
|
|
33
|
+
message = colors_1.colors.yellow(message);
|
|
34
|
+
}
|
|
35
|
+
const label = context?.label
|
|
36
|
+
? colors_1.colors.cyan(`(${context.label}) `)
|
|
37
|
+
: '';
|
|
38
|
+
this.writer(colors_1.colors.grey(`[${namespace}] `) + label + message);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
error(namespace, message, context) {
|
|
44
|
+
this.log(namespace, message, { ...context, level: 'error' });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
49
|
+
warn(namespace, message, context) {
|
|
50
|
+
this.log(namespace, message, { ...context, level: 'warning' });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
55
|
+
setDebugMode(debugMode) {
|
|
56
|
+
this.debugMode = debugMode;
|
|
57
|
+
}
|
|
58
|
+
isEnabled(namespace, context) {
|
|
59
|
+
if (context?.enabled !== undefined) {
|
|
60
|
+
return context.enabled;
|
|
61
|
+
}
|
|
62
|
+
const debugMode = context?.debugMode ?? this.debugMode;
|
|
63
|
+
return !!debugMode && (!Array.isArray(debugMode) || debugMode.includes(namespace));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @inheritDoc
|
|
67
|
+
*/
|
|
68
|
+
logQuery(context) {
|
|
69
|
+
if (!this.isEnabled('query', context)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
/* istanbul ignore next */
|
|
73
|
+
let msg = this.highlighter?.highlight(context.query) ?? context.query;
|
|
74
|
+
if (context.took != null) {
|
|
75
|
+
const meta = [`took ${context.took} ms`];
|
|
76
|
+
if (context.results != null) {
|
|
77
|
+
meta.push(`${context.results} result${context.results === 0 || context.results > 1 ? 's' : ''}`);
|
|
78
|
+
}
|
|
79
|
+
if (context.affected != null) {
|
|
80
|
+
meta.push(`${context.affected} row${context.affected === 0 || context.affected > 1 ? 's' : ''} affected`);
|
|
81
|
+
}
|
|
82
|
+
msg += colors_1.colors.grey(` [${meta.join(', ')}]`);
|
|
83
|
+
}
|
|
84
|
+
if (this.usesReplicas && context.connection) {
|
|
85
|
+
msg += colors_1.colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
|
|
86
|
+
}
|
|
87
|
+
return this.log('query', msg, context);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.DefaultLogger = DefaultLogger;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Dictionary, Highlighter } from '../typings';
|
|
2
|
+
export interface Logger {
|
|
3
|
+
/**
|
|
4
|
+
* Logs a message inside given namespace.
|
|
5
|
+
*/
|
|
6
|
+
log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
|
|
7
|
+
/**
|
|
8
|
+
* Logs error message inside given namespace.
|
|
9
|
+
*/
|
|
10
|
+
error(namespace: LoggerNamespace, message: string, context?: LogContext): void;
|
|
11
|
+
/**
|
|
12
|
+
* Logs warning message inside given namespace.
|
|
13
|
+
*/
|
|
14
|
+
warn(namespace: LoggerNamespace, message: string, context?: LogContext): void;
|
|
15
|
+
/**
|
|
16
|
+
* Logs a message inside given namespace.
|
|
17
|
+
*/
|
|
18
|
+
logQuery(context: LogContext): void;
|
|
19
|
+
/**
|
|
20
|
+
* Sets active namespaces. Pass `true` to enable all logging.
|
|
21
|
+
*/
|
|
22
|
+
setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
|
|
23
|
+
isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
|
|
24
|
+
}
|
|
25
|
+
export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info';
|
|
26
|
+
export interface LogContext extends Dictionary {
|
|
27
|
+
query?: string;
|
|
28
|
+
label?: string;
|
|
29
|
+
params?: unknown[];
|
|
30
|
+
took?: number;
|
|
31
|
+
results?: number;
|
|
32
|
+
affected?: number;
|
|
33
|
+
level?: 'info' | 'warning' | 'error';
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
debugMode?: LoggerNamespace[];
|
|
36
|
+
connection?: {
|
|
37
|
+
type?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface LoggerOptions {
|
|
42
|
+
writer: (message: string) => void;
|
|
43
|
+
debugMode?: boolean | LoggerNamespace[];
|
|
44
|
+
highlighter?: Highlighter;
|
|
45
|
+
usesReplicas?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Logger options to modify format output and overrides, including a label and additional properties that can be accessed by custom loggers.
|
|
49
|
+
*
|
|
50
|
+
* Differs from {@apilink LoggerOptions} in terms of how they are used; this type is primarily a public type meant to be used within methods like `em.find()`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* await em.findOne(User, 1, { logger: { label: 'user middleware' } };
|
|
54
|
+
* // [query] (user middleware) select * from user where id = 1;
|
|
55
|
+
*/
|
|
56
|
+
export type LoggingOptions = Pick<LogContext, 'label' | 'enabled' | 'debugMode'>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LogContext, LoggerNamespace } from './Logger';
|
|
2
|
+
import { DefaultLogger } from './DefaultLogger';
|
|
3
|
+
/**
|
|
4
|
+
* A basic logger that provides fully formatted output without color
|
|
5
|
+
*/
|
|
6
|
+
export declare class SimpleLogger extends DefaultLogger {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritDoc
|
|
9
|
+
*/
|
|
10
|
+
log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
logQuery(context: {
|
|
15
|
+
query: string;
|
|
16
|
+
} & LogContext): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleLogger = void 0;
|
|
4
|
+
const DefaultLogger_1 = require("./DefaultLogger");
|
|
5
|
+
/**
|
|
6
|
+
* A basic logger that provides fully formatted output without color
|
|
7
|
+
*/
|
|
8
|
+
class SimpleLogger extends DefaultLogger_1.DefaultLogger {
|
|
9
|
+
/**
|
|
10
|
+
* @inheritDoc
|
|
11
|
+
*/
|
|
12
|
+
log(namespace, message, context) {
|
|
13
|
+
if (!this.isEnabled(namespace, context)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// clean up the whitespace
|
|
17
|
+
message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
|
|
18
|
+
const label = context?.label ? `(${context.label}) ` : '';
|
|
19
|
+
this.writer(`[${namespace}] ${label}${message}`);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
logQuery(context) {
|
|
25
|
+
if (!this.isEnabled('query', context)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return this.log('query', context.query, context);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.SimpleLogger = SimpleLogger;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export declare const colors: {
|
|
3
|
+
red: (text: string) => string;
|
|
4
|
+
green: (text: string) => string;
|
|
5
|
+
yellow: (text: string) => string;
|
|
6
|
+
grey: (text: string) => string;
|
|
7
|
+
cyan: (text: string) => string;
|
|
8
|
+
enabled: () => boolean | "" | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.colors = void 0;
|
|
5
|
+
const bool = (v) => v && ['true', 't', '1'].includes(v.toLowerCase());
|
|
6
|
+
const boolIfDefined = (v) => v != null ? bool(v) : true;
|
|
7
|
+
const enabled = () => !bool(process.env.NO_COLOR)
|
|
8
|
+
&& !bool(process.env.MIKRO_ORM_NO_COLOR)
|
|
9
|
+
&& boolIfDefined(process.env.FORCE_COLOR)
|
|
10
|
+
&& boolIfDefined(process.env.MIKRO_ORM_COLORS);
|
|
11
|
+
const wrap = (fn) => (text) => enabled() ? fn(text) : text;
|
|
12
|
+
/** @internal */
|
|
13
|
+
exports.colors = {
|
|
14
|
+
red: wrap((text) => `\x1B[31m${text}\x1B[39m`),
|
|
15
|
+
green: wrap((text) => `\x1B[32m${text}\x1B[39m`),
|
|
16
|
+
yellow: wrap((text) => `\x1B[33m${text}\x1B[39m`),
|
|
17
|
+
grey: wrap((text) => `\x1B[90m${text}\x1B[39m`),
|
|
18
|
+
cyan: wrap((text) => `\x1B[36m${text}\x1B[39m`),
|
|
19
|
+
enabled,
|
|
20
|
+
};
|
package/logging/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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("./colors"), exports);
|
|
18
|
+
__exportStar(require("./Logger"), exports);
|
|
19
|
+
__exportStar(require("./DefaultLogger"), exports);
|
|
20
|
+
__exportStar(require("./SimpleLogger"), exports);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EntityMetadata, type AnyEntity, type EntityKey, type Constructor, type DeepPartial, type EntityName, type EntityProperty, type CleanKeys, type ExpandProperty, type IsNever, type EntityClass } from '../typings';
|
|
2
|
+
import type { EmbeddedOptions, EnumOptions, IndexOptions, ManyToManyOptions, ManyToOneOptions, OneToManyOptions, OneToOneOptions, PrimaryKeyOptions, PropertyOptions, SerializedPrimaryKeyOptions, UniqueOptions } from '../decorators';
|
|
3
|
+
import { ReferenceKind } from '../enums';
|
|
4
|
+
import { Type } from '../types';
|
|
5
|
+
type TypeType = string | NumberConstructor | StringConstructor | BooleanConstructor | DateConstructor | ArrayConstructor | Constructor<Type<any>> | Type<any>;
|
|
6
|
+
type TypeDef<Target> = {
|
|
7
|
+
type: TypeType;
|
|
8
|
+
} | {
|
|
9
|
+
entity: string | (() => string | EntityName<Target>);
|
|
10
|
+
};
|
|
11
|
+
export type EntitySchemaProperty<Target, Owner> = ({
|
|
12
|
+
kind: ReferenceKind.MANY_TO_ONE | 'm:1';
|
|
13
|
+
} & TypeDef<Target> & ManyToOneOptions<Owner, Target>) | ({
|
|
14
|
+
kind: ReferenceKind.ONE_TO_ONE | '1:1';
|
|
15
|
+
} & TypeDef<Target> & OneToOneOptions<Owner, Target>) | ({
|
|
16
|
+
kind: ReferenceKind.ONE_TO_MANY | '1:m';
|
|
17
|
+
} & TypeDef<Target> & OneToManyOptions<Owner, Target>) | ({
|
|
18
|
+
kind: ReferenceKind.MANY_TO_MANY | 'm:n';
|
|
19
|
+
} & TypeDef<Target> & ManyToManyOptions<Owner, Target>) | ({
|
|
20
|
+
kind: ReferenceKind.EMBEDDED | 'embedded';
|
|
21
|
+
} & TypeDef<Target> & EmbeddedOptions & PropertyOptions<Owner>) | ({
|
|
22
|
+
enum: true;
|
|
23
|
+
} & EnumOptions<Owner>) | (TypeDef<Target> & PropertyOptions<Owner>);
|
|
24
|
+
type OmitBaseProps<Entity, Base> = IsNever<Base> extends true ? Entity : Omit<Entity, keyof Base>;
|
|
25
|
+
export type EntitySchemaMetadata<Entity, Base = never> = Omit<Partial<EntityMetadata<Entity>>, 'name' | 'properties' | 'extends'> & ({
|
|
26
|
+
name: string;
|
|
27
|
+
} | {
|
|
28
|
+
class: EntityClass<Entity>;
|
|
29
|
+
name?: string;
|
|
30
|
+
}) & {
|
|
31
|
+
extends?: string | EntitySchema<Base>;
|
|
32
|
+
} & {
|
|
33
|
+
properties?: {
|
|
34
|
+
[Key in keyof OmitBaseProps<Entity, Base> as CleanKeys<OmitBaseProps<Entity, Base>, Key>]-?: EntitySchemaProperty<ExpandProperty<NonNullable<Entity[Key]>>, Entity>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare class EntitySchema<Entity = any, Base = never> {
|
|
38
|
+
/**
|
|
39
|
+
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
40
|
+
* so we can use the class in `entities` option just like the EntitySchema instance.
|
|
41
|
+
*/
|
|
42
|
+
static REGISTRY: Map<Partial<any>, EntitySchema<any, never>>;
|
|
43
|
+
private readonly _meta;
|
|
44
|
+
private internal;
|
|
45
|
+
private initialized;
|
|
46
|
+
constructor(meta: EntitySchemaMetadata<Entity, Base>);
|
|
47
|
+
static fromMetadata<T = AnyEntity, U = never>(meta: EntityMetadata<T> | DeepPartial<EntityMetadata<T>>): EntitySchema<T, U>;
|
|
48
|
+
addProperty(name: EntityKey<Entity>, type?: TypeType, options?: PropertyOptions<Entity> | EntityProperty<Entity>): void;
|
|
49
|
+
addEnum(name: EntityKey<Entity>, type?: TypeType, options?: EnumOptions<Entity>): void;
|
|
50
|
+
addVersion(name: EntityKey<Entity>, type: TypeType, options?: PropertyOptions<Entity>): void;
|
|
51
|
+
addPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: PrimaryKeyOptions<Entity>): void;
|
|
52
|
+
addSerializedPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: SerializedPrimaryKeyOptions<Entity>): void;
|
|
53
|
+
addEmbedded<Target = AnyEntity>(name: EntityKey<Entity>, options: EmbeddedOptions): void;
|
|
54
|
+
addManyToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToOneOptions<Entity, Target>): void;
|
|
55
|
+
addManyToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToManyOptions<Entity, Target>): void;
|
|
56
|
+
addOneToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToManyOptions<Entity, Target>): void;
|
|
57
|
+
addOneToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToOneOptions<Entity, Target>): void;
|
|
58
|
+
addIndex(options: IndexOptions<Entity>): void;
|
|
59
|
+
addUnique(options: UniqueOptions<Entity>): void;
|
|
60
|
+
setCustomRepository(repository: () => Constructor): void;
|
|
61
|
+
setExtends(base: string | EntitySchema): void;
|
|
62
|
+
setClass(proto: EntityClass<Entity>): void;
|
|
63
|
+
get meta(): EntityMetadata<Entity>;
|
|
64
|
+
get name(): EntityName<Entity>;
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
init(): this;
|
|
69
|
+
private initProperties;
|
|
70
|
+
private initPrimaryKeys;
|
|
71
|
+
private normalizeType;
|
|
72
|
+
private createProperty;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntitySchema = void 0;
|
|
4
|
+
const typings_1 = require("../typings");
|
|
5
|
+
const BaseEntity_1 = require("../entity/BaseEntity");
|
|
6
|
+
const enums_1 = require("../enums");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const EnumArrayType_1 = require("../types/EnumArrayType");
|
|
10
|
+
class EntitySchema {
|
|
11
|
+
/**
|
|
12
|
+
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
13
|
+
* so we can use the class in `entities` option just like the EntitySchema instance.
|
|
14
|
+
*/
|
|
15
|
+
static REGISTRY = new Map();
|
|
16
|
+
_meta = new typings_1.EntityMetadata();
|
|
17
|
+
internal = false;
|
|
18
|
+
initialized = false;
|
|
19
|
+
constructor(meta) {
|
|
20
|
+
meta.name = meta.class ? meta.class.name : meta.name;
|
|
21
|
+
if (meta.name) {
|
|
22
|
+
meta.abstract ??= false;
|
|
23
|
+
}
|
|
24
|
+
if (meta.class && !meta.internal) {
|
|
25
|
+
EntitySchema.REGISTRY.set(meta.class, this);
|
|
26
|
+
}
|
|
27
|
+
if (meta.tableName || meta.collection) {
|
|
28
|
+
utils_1.Utils.renameKey(meta, 'tableName', 'collection');
|
|
29
|
+
meta.tableName = meta.collection;
|
|
30
|
+
}
|
|
31
|
+
Object.assign(this._meta, { className: meta.name }, meta);
|
|
32
|
+
this._meta.root ??= this._meta;
|
|
33
|
+
}
|
|
34
|
+
static fromMetadata(meta) {
|
|
35
|
+
const schema = new EntitySchema({ ...meta, internal: true });
|
|
36
|
+
schema.internal = true;
|
|
37
|
+
return schema;
|
|
38
|
+
}
|
|
39
|
+
addProperty(name, type, options = {}) {
|
|
40
|
+
const rename = (data, from, to) => {
|
|
41
|
+
if (from in options && !(to in options)) {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
options[to] = [options[from]];
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
delete options[from];
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (name !== options.name) {
|
|
49
|
+
utils_1.Utils.renameKey(options, 'name', 'fieldName');
|
|
50
|
+
}
|
|
51
|
+
rename(options, 'fieldName', 'fieldNames');
|
|
52
|
+
rename(options, 'ref', 'ref');
|
|
53
|
+
rename(options, 'joinColumn', 'joinColumns');
|
|
54
|
+
rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
|
|
55
|
+
rename(options, 'referenceColumnName', 'referencedColumnNames');
|
|
56
|
+
rename(options, 'columnType', 'columnTypes');
|
|
57
|
+
const prop = { name, kind: enums_1.ReferenceKind.SCALAR, ...options, type: this.normalizeType(options, type) };
|
|
58
|
+
if (type && types_1.Type.isMappedType(type.prototype)) {
|
|
59
|
+
prop.type = type;
|
|
60
|
+
}
|
|
61
|
+
if (utils_1.Utils.isString(prop.formula)) {
|
|
62
|
+
const formula = prop.formula; // tmp var is needed here
|
|
63
|
+
prop.formula = () => formula;
|
|
64
|
+
}
|
|
65
|
+
if (prop.formula) {
|
|
66
|
+
prop.persist ??= false;
|
|
67
|
+
}
|
|
68
|
+
this._meta.properties[name] = prop;
|
|
69
|
+
}
|
|
70
|
+
addEnum(name, type, options = {}) {
|
|
71
|
+
if (options.items instanceof Function) {
|
|
72
|
+
options.items = utils_1.Utils.extractEnumValues(options.items());
|
|
73
|
+
}
|
|
74
|
+
// enum arrays are simple numeric/string arrays, the constraint is enforced in the custom type only
|
|
75
|
+
if (options.array && !options.type) {
|
|
76
|
+
options.type = new EnumArrayType_1.EnumArrayType(`${this._meta.className}.${name}`, options.items);
|
|
77
|
+
options.enum = false;
|
|
78
|
+
}
|
|
79
|
+
const prop = { enum: true, ...options };
|
|
80
|
+
if (prop.array) {
|
|
81
|
+
prop.enum = false;
|
|
82
|
+
}
|
|
83
|
+
// force string labels on native enums
|
|
84
|
+
if (prop.nativeEnumName && Array.isArray(prop.items)) {
|
|
85
|
+
prop.items = prop.items.map(val => '' + val);
|
|
86
|
+
}
|
|
87
|
+
this.addProperty(name, this.internal ? type : type || 'enum', prop);
|
|
88
|
+
}
|
|
89
|
+
addVersion(name, type, options = {}) {
|
|
90
|
+
this.addProperty(name, type, { version: true, ...options });
|
|
91
|
+
}
|
|
92
|
+
addPrimaryKey(name, type, options = {}) {
|
|
93
|
+
this.addProperty(name, type, { primary: true, ...options });
|
|
94
|
+
}
|
|
95
|
+
addSerializedPrimaryKey(name, type, options = {}) {
|
|
96
|
+
this._meta.serializedPrimaryKey = name;
|
|
97
|
+
this.addProperty(name, type, options);
|
|
98
|
+
}
|
|
99
|
+
addEmbedded(name, options) {
|
|
100
|
+
utils_1.Utils.defaultValue(options, 'prefix', true);
|
|
101
|
+
if (options.array) {
|
|
102
|
+
options.object = true; // force object mode for arrays
|
|
103
|
+
}
|
|
104
|
+
this._meta.properties[name] = {
|
|
105
|
+
name,
|
|
106
|
+
type: this.normalizeType(options),
|
|
107
|
+
kind: enums_1.ReferenceKind.EMBEDDED,
|
|
108
|
+
...options,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
addManyToOne(name, type, options) {
|
|
112
|
+
const prop = this.createProperty(enums_1.ReferenceKind.MANY_TO_ONE, options);
|
|
113
|
+
prop.owner = true;
|
|
114
|
+
if (prop.joinColumns && !prop.fieldNames) {
|
|
115
|
+
prop.fieldNames = prop.joinColumns;
|
|
116
|
+
}
|
|
117
|
+
if (prop.fieldNames && !prop.joinColumns) {
|
|
118
|
+
prop.joinColumns = prop.fieldNames;
|
|
119
|
+
}
|
|
120
|
+
this.addProperty(name, type, prop);
|
|
121
|
+
}
|
|
122
|
+
addManyToMany(name, type, options) {
|
|
123
|
+
options.fixedOrder = options.fixedOrder || !!options.fixedOrderColumn;
|
|
124
|
+
if (!options.owner && !options.mappedBy) {
|
|
125
|
+
options.owner = true;
|
|
126
|
+
}
|
|
127
|
+
if (options.owner) {
|
|
128
|
+
utils_1.Utils.renameKey(options, 'mappedBy', 'inversedBy');
|
|
129
|
+
}
|
|
130
|
+
const prop = this.createProperty(enums_1.ReferenceKind.MANY_TO_MANY, options);
|
|
131
|
+
this.addProperty(name, type, prop);
|
|
132
|
+
}
|
|
133
|
+
addOneToMany(name, type, options) {
|
|
134
|
+
const prop = this.createProperty(enums_1.ReferenceKind.ONE_TO_MANY, options);
|
|
135
|
+
this.addProperty(name, type, prop);
|
|
136
|
+
}
|
|
137
|
+
addOneToOne(name, type, options) {
|
|
138
|
+
const prop = this.createProperty(enums_1.ReferenceKind.ONE_TO_ONE, options);
|
|
139
|
+
utils_1.Utils.defaultValue(prop, 'owner', !!prop.inversedBy || !prop.mappedBy);
|
|
140
|
+
utils_1.Utils.defaultValue(prop, 'unique', prop.owner);
|
|
141
|
+
if (prop.owner && options.mappedBy) {
|
|
142
|
+
utils_1.Utils.renameKey(prop, 'mappedBy', 'inversedBy');
|
|
143
|
+
}
|
|
144
|
+
if (prop.joinColumns && !prop.fieldNames) {
|
|
145
|
+
prop.fieldNames = prop.joinColumns;
|
|
146
|
+
}
|
|
147
|
+
if (prop.fieldNames && !prop.joinColumns) {
|
|
148
|
+
prop.joinColumns = prop.fieldNames;
|
|
149
|
+
}
|
|
150
|
+
this.addProperty(name, type, prop);
|
|
151
|
+
}
|
|
152
|
+
addIndex(options) {
|
|
153
|
+
this._meta.indexes.push(options);
|
|
154
|
+
}
|
|
155
|
+
addUnique(options) {
|
|
156
|
+
this._meta.uniques.push(options);
|
|
157
|
+
}
|
|
158
|
+
setCustomRepository(repository) {
|
|
159
|
+
this._meta.repository = repository;
|
|
160
|
+
}
|
|
161
|
+
setExtends(base) {
|
|
162
|
+
this._meta.extends = base;
|
|
163
|
+
}
|
|
164
|
+
setClass(proto) {
|
|
165
|
+
this._meta.class = proto;
|
|
166
|
+
this._meta.prototype = proto.prototype;
|
|
167
|
+
this._meta.className = proto.name;
|
|
168
|
+
const tokens = utils_1.Utils.tokenize(proto);
|
|
169
|
+
this._meta.constructorParams = utils_1.Utils.getParamNames(tokens, 'constructor');
|
|
170
|
+
this._meta.toJsonParams = utils_1.Utils.getParamNames(tokens, 'toJSON').filter(p => p !== '...args');
|
|
171
|
+
if (!this.internal) {
|
|
172
|
+
EntitySchema.REGISTRY.set(proto, this);
|
|
173
|
+
}
|
|
174
|
+
if (Object.getPrototypeOf(proto) !== BaseEntity_1.BaseEntity) {
|
|
175
|
+
this._meta.extends = this._meta.extends || Object.getPrototypeOf(proto).name || undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
get meta() {
|
|
179
|
+
return this._meta;
|
|
180
|
+
}
|
|
181
|
+
get name() {
|
|
182
|
+
return this._meta.className;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
init() {
|
|
188
|
+
if (this.initialized) {
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
if (!this._meta.class) {
|
|
192
|
+
const name = this.name;
|
|
193
|
+
this._meta.class = ({ [name]: class {
|
|
194
|
+
} })[name];
|
|
195
|
+
}
|
|
196
|
+
this.setClass(this._meta.class);
|
|
197
|
+
if (this._meta.abstract && !this._meta.discriminatorColumn) {
|
|
198
|
+
delete this._meta.name;
|
|
199
|
+
}
|
|
200
|
+
const tableName = this._meta.collection ?? this._meta.tableName;
|
|
201
|
+
if (tableName?.includes('.') && !this._meta.schema) {
|
|
202
|
+
this._meta.schema = tableName.substring(0, tableName.indexOf('.'));
|
|
203
|
+
this._meta.collection = tableName.substring(tableName.indexOf('.') + 1);
|
|
204
|
+
}
|
|
205
|
+
this.initProperties();
|
|
206
|
+
this.initPrimaryKeys();
|
|
207
|
+
this._meta.props = Object.values(this._meta.properties);
|
|
208
|
+
this._meta.relations = this._meta.props.filter(prop => typeof prop.kind !== 'undefined' && prop.kind !== enums_1.ReferenceKind.SCALAR && prop.kind !== enums_1.ReferenceKind.EMBEDDED);
|
|
209
|
+
this.initialized = true;
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
initProperties() {
|
|
213
|
+
utils_1.Utils.entries(this._meta.properties).forEach(([name, options]) => {
|
|
214
|
+
if (types_1.Type.isMappedType(options.type)) {
|
|
215
|
+
options.type ??= options.type.constructor.name;
|
|
216
|
+
}
|
|
217
|
+
switch (options.kind) {
|
|
218
|
+
case enums_1.ReferenceKind.ONE_TO_ONE:
|
|
219
|
+
this.addOneToOne(name, options.type, options);
|
|
220
|
+
break;
|
|
221
|
+
case enums_1.ReferenceKind.ONE_TO_MANY:
|
|
222
|
+
this.addOneToMany(name, options.type, options);
|
|
223
|
+
break;
|
|
224
|
+
case enums_1.ReferenceKind.MANY_TO_ONE:
|
|
225
|
+
this.addManyToOne(name, options.type, options);
|
|
226
|
+
break;
|
|
227
|
+
case enums_1.ReferenceKind.MANY_TO_MANY:
|
|
228
|
+
this.addManyToMany(name, options.type, options);
|
|
229
|
+
break;
|
|
230
|
+
case enums_1.ReferenceKind.EMBEDDED:
|
|
231
|
+
this.addEmbedded(name, options);
|
|
232
|
+
break;
|
|
233
|
+
default:
|
|
234
|
+
if (options.enum) {
|
|
235
|
+
this.addEnum(name, options.type, options);
|
|
236
|
+
}
|
|
237
|
+
else if (options.primary) {
|
|
238
|
+
this.addPrimaryKey(name, options.type, options);
|
|
239
|
+
}
|
|
240
|
+
else if (options.serializedPrimaryKey) {
|
|
241
|
+
this.addSerializedPrimaryKey(name, options.type, options);
|
|
242
|
+
}
|
|
243
|
+
else if (options.version) {
|
|
244
|
+
this.addVersion(name, options.type, options);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
this.addProperty(name, options.type, options);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
initPrimaryKeys() {
|
|
253
|
+
const pks = Object.values(this._meta.properties).filter(prop => prop.primary);
|
|
254
|
+
if (pks.length > 0) {
|
|
255
|
+
this._meta.primaryKeys = pks.map(prop => prop.name);
|
|
256
|
+
this._meta.compositePK = pks.length > 1;
|
|
257
|
+
this._meta.simplePK = !this._meta.compositePK && pks[0].kind === enums_1.ReferenceKind.SCALAR && !pks[0].customType;
|
|
258
|
+
}
|
|
259
|
+
if (pks.length === 1 && ['number', 'bigint'].includes(pks[0].type)) {
|
|
260
|
+
pks[0].autoincrement ??= true;
|
|
261
|
+
}
|
|
262
|
+
const serializedPrimaryKey = Object.values(this._meta.properties).find(prop => prop.serializedPrimaryKey);
|
|
263
|
+
if (serializedPrimaryKey) {
|
|
264
|
+
this._meta.serializedPrimaryKey = serializedPrimaryKey.name;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
normalizeType(options, type) {
|
|
268
|
+
if ('entity' in options) {
|
|
269
|
+
if (utils_1.Utils.isString(options.entity)) {
|
|
270
|
+
type = options.type = options.entity;
|
|
271
|
+
}
|
|
272
|
+
else if (options.entity) {
|
|
273
|
+
const tmp = options.entity();
|
|
274
|
+
type = options.type = Array.isArray(tmp) ? tmp.map(t => utils_1.Utils.className(t)).sort().join(' | ') : utils_1.Utils.className(tmp);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (type instanceof Function) {
|
|
278
|
+
type = type.name;
|
|
279
|
+
}
|
|
280
|
+
if (['String', 'Number', 'Boolean', 'Array'].includes(type)) {
|
|
281
|
+
type = type.toLowerCase();
|
|
282
|
+
}
|
|
283
|
+
return type;
|
|
284
|
+
}
|
|
285
|
+
createProperty(kind, options) {
|
|
286
|
+
return {
|
|
287
|
+
kind,
|
|
288
|
+
cascade: [enums_1.Cascade.PERSIST],
|
|
289
|
+
...options,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.EntitySchema = EntitySchema;
|