@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.
Files changed (264) hide show
  1. package/EntityManager.d.ts +553 -0
  2. package/EntityManager.js +1736 -0
  3. package/LICENSE +21 -0
  4. package/MikroORM.d.ts +102 -0
  5. package/MikroORM.js +258 -0
  6. package/README.md +383 -0
  7. package/cache/CacheAdapter.d.ts +40 -0
  8. package/cache/CacheAdapter.js +2 -0
  9. package/cache/FileCacheAdapter.d.ts +31 -0
  10. package/cache/FileCacheAdapter.js +90 -0
  11. package/cache/GeneratedCacheAdapter.d.ts +25 -0
  12. package/cache/GeneratedCacheAdapter.js +38 -0
  13. package/cache/MemoryCacheAdapter.d.ts +24 -0
  14. package/cache/MemoryCacheAdapter.js +44 -0
  15. package/cache/NullCacheAdapter.d.ts +19 -0
  16. package/cache/NullCacheAdapter.js +30 -0
  17. package/cache/index.d.ts +5 -0
  18. package/cache/index.js +21 -0
  19. package/connections/Connection.d.ts +85 -0
  20. package/connections/Connection.js +128 -0
  21. package/connections/index.d.ts +1 -0
  22. package/connections/index.js +17 -0
  23. package/decorators/Check.d.ts +3 -0
  24. package/decorators/Check.js +17 -0
  25. package/decorators/CreateRequestContext.d.ts +2 -0
  26. package/decorators/CreateRequestContext.js +31 -0
  27. package/decorators/Embeddable.d.ts +8 -0
  28. package/decorators/Embeddable.js +15 -0
  29. package/decorators/Embedded.d.ts +13 -0
  30. package/decorators/Embedded.js +21 -0
  31. package/decorators/EnsureRequestContext.d.ts +2 -0
  32. package/decorators/EnsureRequestContext.js +26 -0
  33. package/decorators/Entity.d.ts +18 -0
  34. package/decorators/Entity.js +17 -0
  35. package/decorators/Enum.d.ts +9 -0
  36. package/decorators/Enum.js +20 -0
  37. package/decorators/Filter.d.ts +2 -0
  38. package/decorators/Filter.js +12 -0
  39. package/decorators/Formula.d.ts +5 -0
  40. package/decorators/Formula.js +19 -0
  41. package/decorators/Indexed.d.ts +12 -0
  42. package/decorators/Indexed.js +25 -0
  43. package/decorators/ManyToMany.d.ts +21 -0
  44. package/decorators/ManyToMany.js +17 -0
  45. package/decorators/ManyToOne.d.ts +15 -0
  46. package/decorators/ManyToOne.js +17 -0
  47. package/decorators/OneToMany.d.ts +18 -0
  48. package/decorators/OneToMany.js +21 -0
  49. package/decorators/OneToOne.d.ts +12 -0
  50. package/decorators/OneToOne.js +11 -0
  51. package/decorators/PrimaryKey.d.ts +8 -0
  52. package/decorators/PrimaryKey.js +24 -0
  53. package/decorators/Property.d.ts +218 -0
  54. package/decorators/Property.js +35 -0
  55. package/decorators/Subscriber.d.ts +1 -0
  56. package/decorators/Subscriber.js +2 -0
  57. package/decorators/hooks.d.ts +16 -0
  58. package/decorators/hooks.js +60 -0
  59. package/decorators/index.d.ts +17 -0
  60. package/decorators/index.js +36 -0
  61. package/drivers/DatabaseDriver.d.ts +72 -0
  62. package/drivers/DatabaseDriver.js +358 -0
  63. package/drivers/IDatabaseDriver.d.ts +193 -0
  64. package/drivers/IDatabaseDriver.js +4 -0
  65. package/drivers/index.d.ts +2 -0
  66. package/drivers/index.js +18 -0
  67. package/entity/ArrayCollection.d.ts +113 -0
  68. package/entity/ArrayCollection.js +386 -0
  69. package/entity/BaseEntity.d.ts +22 -0
  70. package/entity/BaseEntity.js +47 -0
  71. package/entity/Collection.d.ts +104 -0
  72. package/entity/Collection.js +373 -0
  73. package/entity/EntityAssigner.d.ts +28 -0
  74. package/entity/EntityAssigner.js +226 -0
  75. package/entity/EntityFactory.d.ts +41 -0
  76. package/entity/EntityFactory.js +302 -0
  77. package/entity/EntityHelper.d.ts +29 -0
  78. package/entity/EntityHelper.js +250 -0
  79. package/entity/EntityIdentifier.d.ts +10 -0
  80. package/entity/EntityIdentifier.js +19 -0
  81. package/entity/EntityLoader.d.ts +65 -0
  82. package/entity/EntityLoader.js +579 -0
  83. package/entity/EntityRepository.d.ts +161 -0
  84. package/entity/EntityRepository.js +207 -0
  85. package/entity/EntityValidator.d.ts +19 -0
  86. package/entity/EntityValidator.js +152 -0
  87. package/entity/Reference.d.ts +89 -0
  88. package/entity/Reference.js +242 -0
  89. package/entity/WrappedEntity.d.ts +67 -0
  90. package/entity/WrappedEntity.js +146 -0
  91. package/entity/index.d.ts +13 -0
  92. package/entity/index.js +29 -0
  93. package/entity/wrap.d.ts +15 -0
  94. package/entity/wrap.js +26 -0
  95. package/enums.d.ts +160 -0
  96. package/enums.js +169 -0
  97. package/errors.d.ts +65 -0
  98. package/errors.js +222 -0
  99. package/events/EventManager.d.ts +17 -0
  100. package/events/EventManager.js +77 -0
  101. package/events/EventSubscriber.d.ts +39 -0
  102. package/events/EventSubscriber.js +2 -0
  103. package/events/TransactionEventBroadcaster.d.ts +11 -0
  104. package/events/TransactionEventBroadcaster.js +17 -0
  105. package/events/index.d.ts +3 -0
  106. package/events/index.js +19 -0
  107. package/exceptions.d.ts +104 -0
  108. package/exceptions.js +130 -0
  109. package/hydration/Hydrator.d.ts +23 -0
  110. package/hydration/Hydrator.js +51 -0
  111. package/hydration/ObjectHydrator.d.ts +24 -0
  112. package/hydration/ObjectHydrator.js +332 -0
  113. package/hydration/index.d.ts +2 -0
  114. package/hydration/index.js +18 -0
  115. package/index.d.ts +25 -0
  116. package/index.js +50 -0
  117. package/index.mjs +192 -0
  118. package/logging/DefaultLogger.d.ts +32 -0
  119. package/logging/DefaultLogger.js +90 -0
  120. package/logging/Logger.d.ts +56 -0
  121. package/logging/Logger.js +2 -0
  122. package/logging/SimpleLogger.d.ts +17 -0
  123. package/logging/SimpleLogger.js +31 -0
  124. package/logging/colors.d.ts +9 -0
  125. package/logging/colors.js +20 -0
  126. package/logging/index.d.ts +4 -0
  127. package/logging/index.js +20 -0
  128. package/metadata/EntitySchema.d.ts +74 -0
  129. package/metadata/EntitySchema.js +293 -0
  130. package/metadata/MetadataDiscovery.d.ts +71 -0
  131. package/metadata/MetadataDiscovery.js +1244 -0
  132. package/metadata/MetadataProvider.d.ts +11 -0
  133. package/metadata/MetadataProvider.js +23 -0
  134. package/metadata/MetadataStorage.d.ts +22 -0
  135. package/metadata/MetadataStorage.js +87 -0
  136. package/metadata/MetadataValidator.d.ts +24 -0
  137. package/metadata/MetadataValidator.js +213 -0
  138. package/metadata/ReflectMetadataProvider.d.ts +8 -0
  139. package/metadata/ReflectMetadataProvider.js +48 -0
  140. package/metadata/index.d.ts +6 -0
  141. package/metadata/index.js +22 -0
  142. package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
  143. package/naming-strategy/AbstractNamingStrategy.js +48 -0
  144. package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
  145. package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
  146. package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
  147. package/naming-strategy/MongoNamingStrategy.js +25 -0
  148. package/naming-strategy/NamingStrategy.d.ts +52 -0
  149. package/naming-strategy/NamingStrategy.js +2 -0
  150. package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
  151. package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
  152. package/naming-strategy/index.d.ts +5 -0
  153. package/naming-strategy/index.js +21 -0
  154. package/package.json +70 -0
  155. package/platforms/ExceptionConverter.d.ts +5 -0
  156. package/platforms/ExceptionConverter.js +11 -0
  157. package/platforms/Platform.d.ts +201 -0
  158. package/platforms/Platform.js +452 -0
  159. package/platforms/index.d.ts +2 -0
  160. package/platforms/index.js +18 -0
  161. package/serialization/EntitySerializer.d.ts +34 -0
  162. package/serialization/EntitySerializer.js +206 -0
  163. package/serialization/EntityTransformer.d.ts +8 -0
  164. package/serialization/EntityTransformer.js +192 -0
  165. package/serialization/SerializationContext.d.ts +30 -0
  166. package/serialization/SerializationContext.js +111 -0
  167. package/serialization/index.d.ts +3 -0
  168. package/serialization/index.js +19 -0
  169. package/types/ArrayType.d.ts +13 -0
  170. package/types/ArrayType.js +47 -0
  171. package/types/BigIntType.d.ts +16 -0
  172. package/types/BigIntType.js +45 -0
  173. package/types/BlobType.d.ts +10 -0
  174. package/types/BlobType.js +27 -0
  175. package/types/BooleanType.d.ts +8 -0
  176. package/types/BooleanType.js +16 -0
  177. package/types/DateTimeType.d.ts +8 -0
  178. package/types/DateTimeType.js +16 -0
  179. package/types/DateType.d.ts +8 -0
  180. package/types/DateType.js +16 -0
  181. package/types/DecimalType.d.ts +11 -0
  182. package/types/DecimalType.js +22 -0
  183. package/types/DoubleType.d.ts +11 -0
  184. package/types/DoubleType.js +22 -0
  185. package/types/EnumArrayType.d.ts +9 -0
  186. package/types/EnumArrayType.js +32 -0
  187. package/types/EnumType.d.ts +8 -0
  188. package/types/EnumType.js +16 -0
  189. package/types/FloatType.d.ts +8 -0
  190. package/types/FloatType.js +16 -0
  191. package/types/IntegerType.d.ts +8 -0
  192. package/types/IntegerType.js +16 -0
  193. package/types/IntervalType.d.ts +8 -0
  194. package/types/IntervalType.js +16 -0
  195. package/types/JsonType.d.ts +13 -0
  196. package/types/JsonType.js +34 -0
  197. package/types/MediumIntType.d.ts +6 -0
  198. package/types/MediumIntType.js +10 -0
  199. package/types/SmallIntType.d.ts +8 -0
  200. package/types/SmallIntType.js +16 -0
  201. package/types/StringType.d.ts +8 -0
  202. package/types/StringType.js +16 -0
  203. package/types/TextType.d.ts +8 -0
  204. package/types/TextType.js +16 -0
  205. package/types/TimeType.d.ts +9 -0
  206. package/types/TimeType.js +23 -0
  207. package/types/TinyIntType.d.ts +8 -0
  208. package/types/TinyIntType.js +16 -0
  209. package/types/Type.d.ts +64 -0
  210. package/types/Type.js +84 -0
  211. package/types/Uint8ArrayType.d.ts +11 -0
  212. package/types/Uint8ArrayType.js +37 -0
  213. package/types/UnknownType.d.ts +7 -0
  214. package/types/UnknownType.js +13 -0
  215. package/types/UuidType.d.ts +7 -0
  216. package/types/UuidType.js +13 -0
  217. package/types/index.d.ts +75 -0
  218. package/types/index.js +77 -0
  219. package/typings.d.ts +767 -0
  220. package/typings.js +198 -0
  221. package/unit-of-work/ChangeSet.d.ts +34 -0
  222. package/unit-of-work/ChangeSet.js +62 -0
  223. package/unit-of-work/ChangeSetComputer.d.ts +26 -0
  224. package/unit-of-work/ChangeSetComputer.js +153 -0
  225. package/unit-of-work/ChangeSetPersister.d.ts +50 -0
  226. package/unit-of-work/ChangeSetPersister.js +361 -0
  227. package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
  228. package/unit-of-work/CommitOrderCalculator.js +113 -0
  229. package/unit-of-work/IdentityMap.d.ts +17 -0
  230. package/unit-of-work/IdentityMap.js +84 -0
  231. package/unit-of-work/UnitOfWork.d.ts +124 -0
  232. package/unit-of-work/UnitOfWork.js +1013 -0
  233. package/unit-of-work/index.d.ts +6 -0
  234. package/unit-of-work/index.js +22 -0
  235. package/utils/AbstractSchemaGenerator.d.ts +38 -0
  236. package/utils/AbstractSchemaGenerator.js +101 -0
  237. package/utils/Configuration.d.ts +390 -0
  238. package/utils/Configuration.js +357 -0
  239. package/utils/ConfigurationLoader.d.ts +29 -0
  240. package/utils/ConfigurationLoader.js +282 -0
  241. package/utils/Cursor.d.ts +77 -0
  242. package/utils/Cursor.js +169 -0
  243. package/utils/DataloaderUtils.d.ts +43 -0
  244. package/utils/DataloaderUtils.js +194 -0
  245. package/utils/EntityComparator.d.ts +73 -0
  246. package/utils/EntityComparator.js +568 -0
  247. package/utils/NullHighlighter.d.ts +4 -0
  248. package/utils/NullHighlighter.js +9 -0
  249. package/utils/QueryHelper.d.ts +28 -0
  250. package/utils/QueryHelper.js +228 -0
  251. package/utils/RawQueryFragment.d.ts +96 -0
  252. package/utils/RawQueryFragment.js +188 -0
  253. package/utils/RequestContext.d.ts +34 -0
  254. package/utils/RequestContext.js +54 -0
  255. package/utils/TransactionContext.d.ts +19 -0
  256. package/utils/TransactionContext.js +34 -0
  257. package/utils/Utils.d.ts +274 -0
  258. package/utils/Utils.js +1073 -0
  259. package/utils/clone.d.ts +6 -0
  260. package/utils/clone.js +127 -0
  261. package/utils/index.d.ts +13 -0
  262. package/utils/index.js +29 -0
  263. package/utils/upsert-utils.d.ts +6 -0
  264. 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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
+ };
@@ -0,0 +1,4 @@
1
+ export * from './colors';
2
+ export * from './Logger';
3
+ export * from './DefaultLogger';
4
+ export * from './SimpleLogger';
@@ -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;