@mikro-orm/core 7.0.0-dev.7 → 7.0.0-dev.71
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 +85 -42
- package/EntityManager.js +282 -194
- package/MikroORM.d.ts +11 -29
- package/MikroORM.js +33 -127
- package/README.md +3 -2
- package/cache/FileCacheAdapter.js +1 -2
- package/connections/Connection.d.ts +11 -7
- package/connections/Connection.js +16 -14
- package/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +13 -4
- package/drivers/IDatabaseDriver.d.ts +27 -5
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +98 -30
- package/entity/Collection.js +432 -93
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +9 -1
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +63 -40
- package/entity/EntityHelper.js +26 -9
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +69 -36
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/EntityValidator.js +4 -4
- package/entity/Reference.d.ts +9 -7
- package/entity/Reference.js +32 -5
- package/entity/WrappedEntity.d.ts +0 -2
- package/entity/WrappedEntity.js +1 -5
- package/entity/defineEntity.d.ts +549 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +2 -1
- package/entity/index.js +2 -1
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +15 -3
- package/enums.d.ts +20 -5
- package/enums.js +13 -0
- package/errors.d.ts +6 -1
- package/errors.js +14 -4
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +35 -24
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +9 -13
- package/metadata/EntitySchema.js +44 -26
- package/metadata/MetadataDiscovery.d.ts +6 -7
- package/metadata/MetadataDiscovery.js +161 -162
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +15 -0
- package/metadata/MetadataStorage.d.ts +0 -4
- package/metadata/MetadataStorage.js +6 -10
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +4 -13
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +39 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +1 -1
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
- package/naming-strategy/AbstractNamingStrategy.js +7 -1
- package/naming-strategy/NamingStrategy.d.ts +11 -1
- package/package.json +11 -10
- package/platforms/Platform.d.ts +6 -10
- package/platforms/Platform.js +6 -22
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +29 -11
- package/serialization/EntityTransformer.js +22 -12
- package/serialization/SerializationContext.js +14 -11
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +1 -2
- package/types/BigIntType.d.ts +8 -6
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +1 -1
- package/types/DoubleType.js +1 -1
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +0 -3
- package/types/index.d.ts +1 -1
- package/typings.d.ts +112 -77
- package/typings.js +32 -32
- package/unit-of-work/ChangeSetComputer.js +8 -3
- package/unit-of-work/ChangeSetPersister.d.ts +4 -2
- package/unit-of-work/ChangeSetPersister.js +37 -16
- package/unit-of-work/UnitOfWork.d.ts +8 -1
- package/unit-of-work/UnitOfWork.js +111 -54
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +10 -8
- package/utils/Configuration.d.ts +200 -191
- package/utils/Configuration.js +141 -152
- package/utils/ConfigurationLoader.d.ts +3 -44
- package/utils/ConfigurationLoader.js +26 -239
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +3 -0
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +53 -7
- package/utils/EntityComparator.d.ts +8 -4
- package/utils/EntityComparator.js +107 -60
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +69 -8
- package/utils/RawQueryFragment.d.ts +36 -4
- package/utils/RawQueryFragment.js +34 -13
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +17 -84
- package/utils/Utils.js +132 -252
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/upsert-utils.d.ts +7 -2
- package/utils/upsert-utils.js +52 -1
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -402
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/utils/upsert-utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isRaw } from '../utils/RawQueryFragment.js';
|
|
2
|
+
import { Utils } from './Utils.js';
|
|
1
3
|
function expandEmbeddedProperties(prop, key) {
|
|
2
4
|
if (prop.object) {
|
|
3
5
|
return [prop.name];
|
|
@@ -71,7 +73,15 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
71
73
|
if (!meta) {
|
|
72
74
|
return '*';
|
|
73
75
|
}
|
|
74
|
-
const keys = meta.comparableProps.filter(p =>
|
|
76
|
+
const keys = meta.comparableProps.filter(p => {
|
|
77
|
+
if (p.lazy || p.embeddable) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (p.autoincrement) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return Array.isArray(uniqueFields) && !uniqueFields.includes(p.name);
|
|
84
|
+
}).map(p => p.name);
|
|
75
85
|
if (meta.versionProperty) {
|
|
76
86
|
keys.push(meta.versionProperty);
|
|
77
87
|
}
|
|
@@ -88,3 +98,44 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
88
98
|
}
|
|
89
99
|
return keys.filter(key => !(key in data));
|
|
90
100
|
}
|
|
101
|
+
function getPropertyValue(obj, key) {
|
|
102
|
+
if (key.indexOf('.') === -1) {
|
|
103
|
+
return obj[key];
|
|
104
|
+
}
|
|
105
|
+
const parts = key.split('.');
|
|
106
|
+
let curr = obj;
|
|
107
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
108
|
+
curr[parts[i]] ??= {};
|
|
109
|
+
curr = curr[parts[i]];
|
|
110
|
+
}
|
|
111
|
+
return curr[parts[parts.length - 1]];
|
|
112
|
+
}
|
|
113
|
+
/** @internal */
|
|
114
|
+
export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
115
|
+
const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
|
|
116
|
+
const propIndex = !isRaw(unique) && unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
|
|
117
|
+
if (onConflictFields || where == null) {
|
|
118
|
+
if (propIndex !== false && propIndex >= 0) {
|
|
119
|
+
let key = unique[propIndex];
|
|
120
|
+
if (key.includes('.')) {
|
|
121
|
+
const prop = meta.properties[key.substring(0, key.indexOf('.'))];
|
|
122
|
+
if (prop) {
|
|
123
|
+
key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
where = { [key]: getPropertyValue(data, unique[propIndex]) };
|
|
127
|
+
}
|
|
128
|
+
else if (meta.uniques.length > 0) {
|
|
129
|
+
for (const u of meta.uniques) {
|
|
130
|
+
if (Utils.asArray(u.properties).every(p => data[p] != null)) {
|
|
131
|
+
where = Utils.asArray(u.properties).reduce((o, key) => {
|
|
132
|
+
o[key] = data[key];
|
|
133
|
+
return o;
|
|
134
|
+
}, {});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { where, propIndex };
|
|
141
|
+
}
|
package/decorators/Check.d.ts
DELETED
package/decorators/Check.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
3
|
-
export function Check(options) {
|
|
4
|
-
return function (target, propertyName) {
|
|
5
|
-
const meta = MetadataStorage.getMetadataFromDecorator((propertyName ? target.constructor : target));
|
|
6
|
-
options.property ??= propertyName;
|
|
7
|
-
meta.checks.push(options);
|
|
8
|
-
if (!propertyName) {
|
|
9
|
-
return target;
|
|
10
|
-
}
|
|
11
|
-
return Utils.propertyDecoratorReturnValue();
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ContextProvider } from '../typings.js';
|
|
2
|
-
export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
|
|
3
|
-
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RequestContext } from '../utils/RequestContext.js';
|
|
2
|
-
import { resolveContextProvider } from '../utils/resolveContextProvider.js';
|
|
3
|
-
import { TransactionContext } from '../utils/TransactionContext.js';
|
|
4
|
-
export function CreateRequestContext(context, respectExistingContext = false) {
|
|
5
|
-
return function (target, propertyKey, descriptor) {
|
|
6
|
-
const originalMethod = descriptor.value;
|
|
7
|
-
const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
|
|
8
|
-
if (originalMethod.constructor.name !== 'AsyncFunction') {
|
|
9
|
-
throw new Error(`@${name}() should be use with async functions`);
|
|
10
|
-
}
|
|
11
|
-
descriptor.value = async function (...args) {
|
|
12
|
-
const em = await resolveContextProvider(this, context);
|
|
13
|
-
if (!em) {
|
|
14
|
-
throw new Error(`@${name}() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@${name}(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
15
|
-
}
|
|
16
|
-
// reuse existing context if available for given respect `contextName`
|
|
17
|
-
if (respectExistingContext && RequestContext.getEntityManager(em.name)) {
|
|
18
|
-
return originalMethod.apply(this, args);
|
|
19
|
-
}
|
|
20
|
-
// Otherwise, the outer tx context would be preferred.
|
|
21
|
-
const txContext = TransactionContext.currentTransactionContext();
|
|
22
|
-
const provider = txContext ? TransactionContext : RequestContext;
|
|
23
|
-
return txContext
|
|
24
|
-
? provider.create(em.fork({ useContext: true }), () => originalMethod.apply(this, args))
|
|
25
|
-
: provider.create(em, () => originalMethod.apply(this, args));
|
|
26
|
-
};
|
|
27
|
-
return descriptor;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export function EnsureRequestContext(context) {
|
|
31
|
-
return CreateRequestContext(context, true);
|
|
32
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AnyString, Dictionary, EntityClass } from '../typings.js';
|
|
2
|
-
export declare function Embeddable<T>(options?: EmbeddableOptions<T>): (target: T) => T;
|
|
3
|
-
export interface EmbeddableOptions<T> {
|
|
4
|
-
discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
|
|
5
|
-
discriminatorMap?: Dictionary<string>;
|
|
6
|
-
discriminatorValue?: number | string;
|
|
7
|
-
abstract?: boolean;
|
|
8
|
-
}
|
package/decorators/Embeddable.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
export function Embeddable(options = {}) {
|
|
3
|
-
return function (target) {
|
|
4
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target);
|
|
5
|
-
meta.class = target;
|
|
6
|
-
meta.name = meta.class.name;
|
|
7
|
-
meta.embeddable = true;
|
|
8
|
-
Object.assign(meta, options);
|
|
9
|
-
return target;
|
|
10
|
-
};
|
|
11
|
-
}
|
package/decorators/Embedded.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AnyEntity } from '../typings.js';
|
|
2
|
-
export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
|
|
3
|
-
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|
|
4
|
-
export type EmbeddedPrefixMode = 'absolute' | 'relative';
|
|
5
|
-
export interface EmbeddedOptions {
|
|
6
|
-
entity?: string | (() => AnyEntity | AnyEntity[]);
|
|
7
|
-
type?: string;
|
|
8
|
-
prefix?: string | boolean;
|
|
9
|
-
prefixMode?: EmbeddedPrefixMode;
|
|
10
|
-
nullable?: boolean;
|
|
11
|
-
object?: boolean;
|
|
12
|
-
array?: boolean;
|
|
13
|
-
hidden?: boolean;
|
|
14
|
-
serializer?: (value: any) => any;
|
|
15
|
-
serializedName?: string;
|
|
16
|
-
groups?: string[];
|
|
17
|
-
persist?: boolean;
|
|
18
|
-
}
|
package/decorators/Embedded.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MetadataValidator } from '../metadata/MetadataValidator.js';
|
|
2
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
3
|
-
import { Utils } from '../utils/Utils.js';
|
|
4
|
-
import { ReferenceKind } from '../enums.js';
|
|
5
|
-
export function Embedded(type = {}, options = {}) {
|
|
6
|
-
return function (target, propertyName) {
|
|
7
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
8
|
-
MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.EMBEDDED);
|
|
9
|
-
options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
|
|
10
|
-
Utils.defaultValue(options, 'prefix', true);
|
|
11
|
-
meta.properties[propertyName] = {
|
|
12
|
-
name: propertyName,
|
|
13
|
-
kind: ReferenceKind.EMBEDDED,
|
|
14
|
-
...options,
|
|
15
|
-
};
|
|
16
|
-
return Utils.propertyDecoratorReturnValue();
|
|
17
|
-
};
|
|
18
|
-
}
|
package/decorators/Entity.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AnyString, Constructor, Dictionary, EntityClass, ObjectQuery } from '../typings.js';
|
|
2
|
-
import type { FindOptions } from '../drivers/IDatabaseDriver.js';
|
|
3
|
-
export declare function Entity<T extends EntityClass<unknown>>(options?: EntityOptions<T>): (target: T) => void;
|
|
4
|
-
export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
|
|
5
|
-
tableName?: string;
|
|
6
|
-
schema?: string;
|
|
7
|
-
collection?: string;
|
|
8
|
-
discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
|
|
9
|
-
discriminatorMap?: Dictionary<string>;
|
|
10
|
-
discriminatorValue?: number | string;
|
|
11
|
-
forceConstructor?: boolean;
|
|
12
|
-
comment?: string;
|
|
13
|
-
abstract?: boolean;
|
|
14
|
-
readonly?: boolean;
|
|
15
|
-
virtual?: boolean;
|
|
16
|
-
expression?: string | ((em: any, where: ObjectQuery<E>, options: FindOptions<E, any, any, any>) => object);
|
|
17
|
-
repository?: () => Constructor;
|
|
18
|
-
};
|
package/decorators/Entity.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
3
|
-
export function Entity(options = {}) {
|
|
4
|
-
return function (target) {
|
|
5
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target);
|
|
6
|
-
Utils.mergeConfig(meta, options);
|
|
7
|
-
meta.class = target;
|
|
8
|
-
if (!options.abstract || meta.discriminatorColumn) {
|
|
9
|
-
meta.name = target.name;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
}
|
package/decorators/Enum.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PropertyOptions } from './Property.js';
|
|
2
|
-
import type { AnyEntity, Dictionary } from '../typings.js';
|
|
3
|
-
export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: T, propertyName: string) => any;
|
|
4
|
-
export interface EnumOptions<T> extends PropertyOptions<T> {
|
|
5
|
-
items?: (number | string)[] | (() => Dictionary);
|
|
6
|
-
array?: boolean;
|
|
7
|
-
/** for postgres, by default it uses text column with check constraint */
|
|
8
|
-
nativeEnumName?: string;
|
|
9
|
-
}
|
package/decorators/Enum.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { ReferenceKind } from '../enums.js';
|
|
3
|
-
import { Utils } from '../utils/Utils.js';
|
|
4
|
-
export function Enum(options = {}) {
|
|
5
|
-
return function (target, propertyName) {
|
|
6
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
7
|
-
options = options instanceof Function ? { items: options } : options;
|
|
8
|
-
meta.properties[propertyName] = {
|
|
9
|
-
name: propertyName,
|
|
10
|
-
kind: ReferenceKind.SCALAR,
|
|
11
|
-
enum: true,
|
|
12
|
-
...options,
|
|
13
|
-
};
|
|
14
|
-
return Utils.propertyDecoratorReturnValue();
|
|
15
|
-
};
|
|
16
|
-
}
|
package/decorators/Filter.d.ts
DELETED
package/decorators/Filter.js
DELETED
package/decorators/Formula.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { PropertyOptions } from './Property.js';
|
|
2
|
-
export declare function Formula<T extends object>(formula: string | ((alias: string) => string), options?: FormulaOptions<T>): (target: T, propertyName: string) => any;
|
|
3
|
-
export interface FormulaOptions<T> extends PropertyOptions<T> {
|
|
4
|
-
}
|
package/decorators/Formula.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { ReferenceKind } from '../enums.js';
|
|
3
|
-
import { Utils } from '../utils/Utils.js';
|
|
4
|
-
export function Formula(formula, options = {}) {
|
|
5
|
-
return function (target, propertyName) {
|
|
6
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
7
|
-
meta.properties[propertyName] = {
|
|
8
|
-
name: propertyName,
|
|
9
|
-
kind: ReferenceKind.SCALAR,
|
|
10
|
-
formula,
|
|
11
|
-
...options,
|
|
12
|
-
};
|
|
13
|
-
return Utils.propertyDecoratorReturnValue();
|
|
14
|
-
};
|
|
15
|
-
}
|
package/decorators/Indexed.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { EntityClass, Dictionary, AutoPath } from '../typings.js';
|
|
2
|
-
import type { DeferMode } from '../enums.js';
|
|
3
|
-
export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (target: T, propertyName?: (T extends EntityClass<unknown> ? undefined : keyof T) | undefined) => any;
|
|
4
|
-
export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (target: T, propertyName?: (T extends EntityClass<unknown> ? undefined : keyof T) | undefined) => any;
|
|
5
|
-
type MaybeArray<T> = T | T[];
|
|
6
|
-
type Properties<T, H extends string> = MaybeArray<AutoPath<T, H>>;
|
|
7
|
-
interface BaseOptions<T, H extends string> {
|
|
8
|
-
name?: string;
|
|
9
|
-
properties?: (T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>);
|
|
10
|
-
options?: Dictionary;
|
|
11
|
-
expression?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface UniqueOptions<T, H extends string = string> extends BaseOptions<T, H> {
|
|
14
|
-
deferMode?: DeferMode | `${DeferMode}`;
|
|
15
|
-
}
|
|
16
|
-
export interface IndexOptions<T, H extends string = string> extends BaseOptions<T, H> {
|
|
17
|
-
type?: string;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
package/decorators/Indexed.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
3
|
-
function createDecorator(options, unique) {
|
|
4
|
-
return function (target, propertyName) {
|
|
5
|
-
const meta = MetadataStorage.getMetadataFromDecorator(propertyName ? target.constructor : target);
|
|
6
|
-
options.properties ??= propertyName;
|
|
7
|
-
const key = unique ? 'uniques' : 'indexes';
|
|
8
|
-
meta[key].push(options);
|
|
9
|
-
if (!propertyName) {
|
|
10
|
-
return target;
|
|
11
|
-
}
|
|
12
|
-
return Utils.propertyDecoratorReturnValue();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function Index(options = {}) {
|
|
16
|
-
return createDecorator(options, false);
|
|
17
|
-
}
|
|
18
|
-
export function Unique(options = {}) {
|
|
19
|
-
return createDecorator(options, true);
|
|
20
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { ReferenceOptions } from './Property.js';
|
|
2
|
-
import type { EntityName, FilterQuery, AnyString } from '../typings.js';
|
|
3
|
-
import { type QueryOrderMap } from '../enums.js';
|
|
4
|
-
export declare function ManyToMany<Target extends object, Owner extends object>(entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>), mappedBy?: (string & keyof Target) | ((e: Target) => any), options?: Partial<ManyToManyOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
|
|
5
|
-
export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
|
|
6
|
-
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
7
|
-
owner?: boolean;
|
|
8
|
-
/** Point to the inverse side property name. */
|
|
9
|
-
inversedBy?: (string & keyof Target) | ((e: Target) => any);
|
|
10
|
-
/** Point to the owning side property name. */
|
|
11
|
-
mappedBy?: (string & keyof Target) | ((e: Target) => any);
|
|
12
|
-
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
13
|
-
where?: FilterQuery<Target>;
|
|
14
|
-
/** Set default ordering. */
|
|
15
|
-
orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
|
|
16
|
-
/** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
|
|
17
|
-
fixedOrder?: boolean;
|
|
18
|
-
/** Override default order column name (`id`) for fixed ordering. */
|
|
19
|
-
fixedOrderColumn?: string;
|
|
20
|
-
/** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
|
|
21
|
-
pivotTable?: string;
|
|
22
|
-
/** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
|
|
23
|
-
pivotEntity?: string | (() => EntityName<any>);
|
|
24
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
25
|
-
joinColumn?: string;
|
|
26
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
27
|
-
joinColumns?: string[];
|
|
28
|
-
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
29
|
-
inverseJoinColumn?: string;
|
|
30
|
-
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
31
|
-
inverseJoinColumns?: string[];
|
|
32
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
33
|
-
referenceColumnName?: string;
|
|
34
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
35
|
-
referencedColumnNames?: string[];
|
|
36
|
-
/** What to do when the target entity gets deleted. */
|
|
37
|
-
deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
38
|
-
/** What to do when the reference to the target entity gets updated. */
|
|
39
|
-
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
40
|
-
}
|
package/decorators/ManyToMany.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { MetadataValidator } from '../metadata/MetadataValidator.js';
|
|
3
|
-
import { Utils } from '../utils/Utils.js';
|
|
4
|
-
import { ReferenceKind } from '../enums.js';
|
|
5
|
-
export function ManyToMany(entity, mappedBy, options = {}) {
|
|
6
|
-
return function (target, propertyName) {
|
|
7
|
-
options = Utils.processDecoratorParameters({ entity, mappedBy, options });
|
|
8
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
9
|
-
MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_MANY);
|
|
10
|
-
const property = { name: propertyName, kind: ReferenceKind.MANY_TO_MANY };
|
|
11
|
-
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
12
|
-
return Utils.propertyDecoratorReturnValue();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ReferenceOptions } from './Property.js';
|
|
2
|
-
import { type DeferMode } from '../enums.js';
|
|
3
|
-
import type { AnyString, EntityName } from '../typings.js';
|
|
4
|
-
export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), options?: Partial<ManyToOneOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
|
|
5
|
-
export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
|
|
6
|
-
/** Point to the inverse side property name. */
|
|
7
|
-
inversedBy?: (string & keyof Target) | ((e: Target) => any);
|
|
8
|
-
/** Wrap the entity in {@apilink Reference} wrapper. */
|
|
9
|
-
ref?: boolean;
|
|
10
|
-
/** Use this relation as a primary key. */
|
|
11
|
-
primary?: boolean;
|
|
12
|
-
/** Map this relation to the primary key value instead of an entity. */
|
|
13
|
-
mapToPk?: boolean;
|
|
14
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
15
|
-
joinColumn?: string;
|
|
16
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
17
|
-
joinColumns?: string[];
|
|
18
|
-
/** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
|
|
19
|
-
ownColumns?: string[];
|
|
20
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
21
|
-
referenceColumnName?: string;
|
|
22
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
23
|
-
referencedColumnNames?: string[];
|
|
24
|
-
/** What to do when the target entity gets deleted. */
|
|
25
|
-
deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
26
|
-
/** What to do when the reference to the target entity gets updated. */
|
|
27
|
-
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
28
|
-
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
29
|
-
deferMode?: DeferMode | `${DeferMode}`;
|
|
30
|
-
}
|
package/decorators/ManyToOne.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { MetadataValidator } from '../metadata/MetadataValidator.js';
|
|
3
|
-
import { Utils } from '../utils/Utils.js';
|
|
4
|
-
import { ReferenceKind } from '../enums.js';
|
|
5
|
-
export function ManyToOne(entity = {}, options = {}) {
|
|
6
|
-
return function (target, propertyName) {
|
|
7
|
-
options = Utils.processDecoratorParameters({ entity, options });
|
|
8
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
9
|
-
MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_ONE);
|
|
10
|
-
const property = { name: propertyName, kind: ReferenceKind.MANY_TO_ONE };
|
|
11
|
-
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
12
|
-
return Utils.propertyDecoratorReturnValue();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ReferenceOptions } from './Property.js';
|
|
2
|
-
import { ReferenceKind, type QueryOrderMap } from '../enums.js';
|
|
3
|
-
import type { EntityName, FilterQuery } from '../typings.js';
|
|
4
|
-
export declare function createOneToDecorator<Target, Owner>(entity: OneToManyOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any) | undefined, options: Partial<OneToManyOptions<Owner, Target>>, kind: ReferenceKind): (target: Owner, propertyName: string) => any;
|
|
5
|
-
export declare function OneToMany<Target, Owner>(entity: string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
|
|
6
|
-
export declare function OneToMany<Target, Owner>(options: OneToManyOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
|
7
|
-
export interface OneToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
|
|
8
|
-
/** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
|
|
9
|
-
orphanRemoval?: boolean;
|
|
10
|
-
/** Set default ordering. */
|
|
11
|
-
orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
|
|
12
|
-
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
13
|
-
where?: FilterQuery<Target>;
|
|
14
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
15
|
-
joinColumn?: string;
|
|
16
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
17
|
-
joinColumns?: string[];
|
|
18
|
-
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
19
|
-
inverseJoinColumn?: string;
|
|
20
|
-
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
21
|
-
inverseJoinColumns?: string[];
|
|
22
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
23
|
-
referenceColumnName?: string;
|
|
24
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
25
|
-
referencedColumnNames?: string[];
|
|
26
|
-
/** Point to the owning side property name. */
|
|
27
|
-
mappedBy: (string & keyof Target) | ((e: Target) => any);
|
|
28
|
-
}
|
package/decorators/OneToMany.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { MetadataValidator } from '../metadata/MetadataValidator.js';
|
|
3
|
-
import { Utils } from '../utils/Utils.js';
|
|
4
|
-
import { ReferenceKind } from '../enums.js';
|
|
5
|
-
export function createOneToDecorator(entity, mappedBy, options, kind) {
|
|
6
|
-
return function (target, propertyName) {
|
|
7
|
-
options = Utils.processDecoratorParameters({ entity, mappedBy, options });
|
|
8
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
9
|
-
MetadataValidator.validateSingleDecorator(meta, propertyName, kind);
|
|
10
|
-
const property = { name: propertyName, kind };
|
|
11
|
-
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
12
|
-
return Utils.propertyDecoratorReturnValue();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function OneToMany(entity, mappedBy, options = {}) {
|
|
16
|
-
return createOneToDecorator(entity, mappedBy, options, ReferenceKind.ONE_TO_MANY);
|
|
17
|
-
}
|
package/decorators/OneToOne.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type DeferMode } from '../enums.js';
|
|
2
|
-
import { type OneToManyOptions } from './OneToMany.js';
|
|
3
|
-
import type { AnyString, EntityName } from '../typings.js';
|
|
4
|
-
export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: Owner, propertyName: string) => any;
|
|
5
|
-
export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>> {
|
|
6
|
-
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
7
|
-
owner?: boolean;
|
|
8
|
-
/** Point to the inverse side property name. */
|
|
9
|
-
inversedBy?: (string & keyof Target) | ((e: Target) => any);
|
|
10
|
-
/** Wrap the entity in {@apilink Reference} wrapper. */
|
|
11
|
-
ref?: boolean;
|
|
12
|
-
/** Use this relation as a primary key. */
|
|
13
|
-
primary?: boolean;
|
|
14
|
-
/** Map this relation to the primary key value instead of an entity. */
|
|
15
|
-
mapToPk?: boolean;
|
|
16
|
-
/** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
|
|
17
|
-
ownColumns?: string[];
|
|
18
|
-
/** What to do when the target entity gets deleted. */
|
|
19
|
-
deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
20
|
-
/** What to do when the reference to the target entity gets updated. */
|
|
21
|
-
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
22
|
-
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
23
|
-
deferMode?: DeferMode | `${DeferMode}`;
|
|
24
|
-
}
|
package/decorators/OneToOne.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ReferenceKind } from '../enums.js';
|
|
2
|
-
import { createOneToDecorator } from './OneToMany.js';
|
|
3
|
-
export function OneToOne(entity, mappedByOrOptions, options = {}) {
|
|
4
|
-
const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
|
|
5
|
-
options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
|
|
6
|
-
return createOneToDecorator(entity, mappedBy, options, ReferenceKind.ONE_TO_ONE);
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PropertyOptions } from './Property.js';
|
|
2
|
-
export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
|
|
3
|
-
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
|
|
4
|
-
export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
|
|
5
|
-
}
|
|
6
|
-
export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
|
|
7
|
-
type?: any;
|
|
8
|
-
}
|
package/decorators/PrimaryKey.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
-
import { MetadataValidator } from '../metadata/MetadataValidator.js';
|
|
3
|
-
import { ReferenceKind } from '../enums.js';
|
|
4
|
-
import { Utils } from '../utils/Utils.js';
|
|
5
|
-
function createDecorator(options, serialized) {
|
|
6
|
-
return function (target, propertyName) {
|
|
7
|
-
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
8
|
-
MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.SCALAR);
|
|
9
|
-
const k = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
10
|
-
options[k] = true;
|
|
11
|
-
meta.properties[propertyName] = { name: propertyName, kind: ReferenceKind.SCALAR, ...options };
|
|
12
|
-
return Utils.propertyDecoratorReturnValue();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function PrimaryKey(options = {}) {
|
|
16
|
-
return createDecorator(options, false);
|
|
17
|
-
}
|
|
18
|
-
export function SerializedPrimaryKey(options = {}) {
|
|
19
|
-
return createDecorator(options, true);
|
|
20
|
-
}
|