@mikro-orm/core 7.0.2-dev.12 → 7.0.2-dev.14
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 +4 -0
- package/EntityManager.js +4 -0
- package/MikroORM.d.ts +2 -0
- package/MikroORM.js +2 -0
- package/cache/CacheAdapter.d.ts +2 -0
- package/cache/GeneratedCacheAdapter.d.ts +1 -0
- package/cache/GeneratedCacheAdapter.js +1 -0
- package/cache/MemoryCacheAdapter.d.ts +1 -0
- package/cache/MemoryCacheAdapter.js +1 -0
- package/cache/NullCacheAdapter.d.ts +1 -0
- package/cache/NullCacheAdapter.js +1 -0
- package/connections/Connection.d.ts +13 -0
- package/connections/Connection.js +9 -0
- package/drivers/DatabaseDriver.d.ts +12 -0
- package/drivers/DatabaseDriver.js +12 -0
- package/drivers/IDatabaseDriver.d.ts +44 -0
- package/drivers/IDatabaseDriver.js +1 -0
- package/entity/BaseEntity.d.ts +11 -0
- package/entity/BaseEntity.js +11 -0
- package/entity/Collection.d.ts +26 -0
- package/entity/Collection.js +15 -0
- package/entity/EntityAssigner.d.ts +3 -0
- package/entity/EntityAssigner.js +2 -0
- package/entity/EntityFactory.d.ts +16 -0
- package/entity/EntityFactory.js +6 -0
- package/entity/EntityLoader.d.ts +19 -0
- package/entity/EntityLoader.js +2 -0
- package/entity/EntityRepository.d.ts +2 -0
- package/entity/EntityRepository.js +2 -0
- package/entity/Reference.d.ts +20 -0
- package/entity/Reference.js +16 -0
- package/entity/WrappedEntity.d.ts +20 -0
- package/entity/WrappedEntity.js +21 -1
- package/entity/defineEntity.d.ts +10 -0
- package/entity/defineEntity.js +1 -0
- package/enums.d.ts +132 -0
- package/enums.js +132 -0
- package/errors.d.ts +6 -0
- package/errors.js +6 -0
- package/events/EventManager.d.ts +5 -0
- package/events/EventManager.js +5 -0
- package/events/EventSubscriber.d.ts +4 -0
- package/events/TransactionEventBroadcaster.d.ts +2 -0
- package/events/TransactionEventBroadcaster.js +2 -0
- package/hydration/Hydrator.d.ts +2 -0
- package/hydration/Hydrator.js +2 -0
- package/hydration/ObjectHydrator.d.ts +1 -0
- package/hydration/ObjectHydrator.js +1 -0
- package/logging/DefaultLogger.d.ts +3 -0
- package/logging/DefaultLogger.js +3 -0
- package/logging/Logger.d.ts +5 -0
- package/metadata/EntitySchema.d.ts +22 -0
- package/metadata/EntitySchema.js +20 -0
- package/metadata/MetadataDiscovery.d.ts +4 -0
- package/metadata/MetadataDiscovery.js +4 -0
- package/metadata/MetadataProvider.d.ts +8 -0
- package/metadata/MetadataProvider.js +8 -0
- package/metadata/MetadataStorage.d.ts +14 -0
- package/metadata/MetadataStorage.js +13 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +1 -0
- package/naming-strategy/AbstractNamingStrategy.js +1 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -0
- package/naming-strategy/MongoNamingStrategy.js +1 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +1 -0
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -0
- package/platforms/ExceptionConverter.js +1 -0
- package/platforms/Platform.d.ts +65 -0
- package/platforms/Platform.js +65 -0
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +2 -0
- package/serialization/EntityTransformer.d.ts +2 -0
- package/serialization/EntityTransformer.js +2 -0
- package/serialization/SerializationContext.d.ts +5 -0
- package/serialization/SerializationContext.js +5 -0
- package/types/ArrayType.d.ts +1 -0
- package/types/ArrayType.js +1 -0
- package/types/BlobType.d.ts +1 -0
- package/types/BlobType.js +1 -0
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +1 -0
- package/types/CharacterType.d.ts +1 -0
- package/types/CharacterType.js +1 -0
- package/types/DateTimeType.d.ts +1 -0
- package/types/DateTimeType.js +1 -0
- package/types/DateType.d.ts +1 -0
- package/types/DateType.js +1 -0
- package/types/EnumArrayType.d.ts +1 -0
- package/types/EnumArrayType.js +1 -0
- package/types/EnumType.d.ts +1 -0
- package/types/EnumType.js +1 -0
- package/types/FloatType.d.ts +1 -0
- package/types/FloatType.js +1 -0
- package/types/IntegerType.d.ts +1 -0
- package/types/IntegerType.js +1 -0
- package/types/IntervalType.d.ts +1 -0
- package/types/IntervalType.js +1 -0
- package/types/JsonType.d.ts +1 -0
- package/types/JsonType.js +1 -0
- package/types/MediumIntType.d.ts +1 -0
- package/types/MediumIntType.js +1 -0
- package/types/SmallIntType.d.ts +1 -0
- package/types/SmallIntType.js +1 -0
- package/types/StringType.d.ts +1 -0
- package/types/StringType.js +1 -0
- package/types/TextType.d.ts +1 -0
- package/types/TextType.js +1 -0
- package/types/TimeType.d.ts +1 -0
- package/types/TimeType.js +1 -0
- package/types/TinyIntType.d.ts +1 -0
- package/types/TinyIntType.js +1 -0
- package/types/Type.d.ts +3 -0
- package/types/Type.js +1 -0
- package/types/Uint8ArrayType.d.ts +1 -0
- package/types/Uint8ArrayType.js +1 -0
- package/types/UnknownType.d.ts +1 -0
- package/types/UnknownType.js +1 -0
- package/types/UuidType.d.ts +1 -0
- package/types/UuidType.js +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.js +2 -0
- package/typings.d.ts +177 -0
- package/typings.js +11 -0
- package/unit-of-work/ChangeSet.d.ts +4 -0
- package/unit-of-work/ChangeSet.js +4 -0
- package/unit-of-work/ChangeSetComputer.d.ts +2 -0
- package/unit-of-work/ChangeSetComputer.js +2 -0
- package/unit-of-work/ChangeSetPersister.d.ts +4 -0
- package/unit-of-work/ChangeSetPersister.js +4 -0
- package/unit-of-work/IdentityMap.d.ts +7 -0
- package/unit-of-work/IdentityMap.js +7 -0
- package/unit-of-work/UnitOfWork.d.ts +15 -0
- package/unit-of-work/UnitOfWork.js +15 -0
- package/utils/Configuration.d.ts +8 -0
- package/utils/Configuration.js +8 -0
- package/utils/EntityComparator.d.ts +2 -0
- package/utils/EntityComparator.js +2 -0
- package/utils/NullHighlighter.d.ts +1 -0
- package/utils/NullHighlighter.js +1 -0
- package/utils/RawQueryFragment.d.ts +10 -0
- package/utils/RawQueryFragment.js +9 -0
- package/utils/RequestContext.d.ts +1 -0
- package/utils/TransactionContext.d.ts +1 -0
- package/utils/TransactionContext.js +1 -0
- package/utils/Utils.d.ts +6 -0
- package/utils/Utils.js +7 -1
package/typings.js
CHANGED
|
@@ -5,14 +5,25 @@ import { helper } from './entity/wrap.js';
|
|
|
5
5
|
import { Utils } from './utils/Utils.js';
|
|
6
6
|
import { EntityComparator } from './utils/EntityComparator.js';
|
|
7
7
|
import { BaseEntity } from './entity/BaseEntity.js';
|
|
8
|
+
/** Symbol used to declare a custom repository type on an entity class (e.g., `[EntityRepositoryType]?: BookRepository`). */
|
|
8
9
|
export const EntityRepositoryType = Symbol('EntityRepositoryType');
|
|
10
|
+
/** Symbol used to declare the primary key property name(s) on an entity (e.g., `[PrimaryKeyProp]?: 'id'`). */
|
|
9
11
|
export const PrimaryKeyProp = Symbol('PrimaryKeyProp');
|
|
12
|
+
/** Symbol used to declare which properties are optional in `em.create()` (e.g., `[OptionalProps]?: 'createdAt'`). */
|
|
10
13
|
export const OptionalProps = Symbol('OptionalProps');
|
|
14
|
+
/** Symbol used to declare which relation properties should be eagerly loaded (e.g., `[EagerProps]?: 'author'`). */
|
|
11
15
|
export const EagerProps = Symbol('EagerProps');
|
|
16
|
+
/** Symbol used to declare which properties are hidden from serialization (e.g., `[HiddenProps]?: 'password'`). */
|
|
12
17
|
export const HiddenProps = Symbol('HiddenProps');
|
|
18
|
+
/** Symbol used to declare type-level configuration on an entity (e.g., `[Config]?: DefineConfig<{ forceObject: true }>`). */
|
|
13
19
|
export const Config = Symbol('Config');
|
|
20
|
+
/** Symbol used to declare the entity name as a string literal type (used by `defineEntity`). */
|
|
14
21
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
15
22
|
export const EntityName = Symbol('EntityName');
|
|
23
|
+
/**
|
|
24
|
+
* Runtime metadata for an entity, holding its properties, relations, indexes, hooks, and more.
|
|
25
|
+
* Created during metadata discovery and used throughout the ORM lifecycle.
|
|
26
|
+
*/
|
|
16
27
|
export class EntityMetadata {
|
|
17
28
|
static counter = 0;
|
|
18
29
|
_id = 1000 * EntityMetadata.counter++; // keep the id >= 1000 to allow computing cache keys by simple addition
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EntityData, EntityMetadata, EntityDictionary, Primary } from '../typings.js';
|
|
2
|
+
/** Represents a pending change (create, update, or delete) for a single entity. */
|
|
2
3
|
export declare class ChangeSet<T extends object> {
|
|
3
4
|
entity: T;
|
|
4
5
|
type: ChangeSetType;
|
|
@@ -7,7 +8,9 @@ export declare class ChangeSet<T extends object> {
|
|
|
7
8
|
private primaryKey?;
|
|
8
9
|
private serializedPrimaryKey?;
|
|
9
10
|
constructor(entity: T, type: ChangeSetType, payload: EntityDictionary<T>, meta: EntityMetadata<T>);
|
|
11
|
+
/** Returns the primary key of the entity, optionally as an object for composite keys. */
|
|
10
12
|
getPrimaryKey(object?: boolean): Primary<T> | null;
|
|
13
|
+
/** Returns the serialized (string) form of the primary key. */
|
|
11
14
|
getSerializedPrimaryKey(): string | null;
|
|
12
15
|
}
|
|
13
16
|
export interface ChangeSet<T> {
|
|
@@ -22,6 +25,7 @@ export interface ChangeSet<T> {
|
|
|
22
25
|
/** For TPT: changesets for parent tables, ordered from immediate parent to root */
|
|
23
26
|
tptChangeSets?: ChangeSet<T>[];
|
|
24
27
|
}
|
|
28
|
+
/** Enumeration of change set operation types. */
|
|
25
29
|
export declare enum ChangeSetType {
|
|
26
30
|
CREATE = "create",
|
|
27
31
|
UPDATE = "update",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { helper } from '../entity/wrap.js';
|
|
2
2
|
import { Utils } from '../utils/Utils.js';
|
|
3
3
|
import { inspect } from '../logging/inspect.js';
|
|
4
|
+
/** Represents a pending change (create, update, or delete) for a single entity. */
|
|
4
5
|
export class ChangeSet {
|
|
5
6
|
entity;
|
|
6
7
|
type;
|
|
@@ -17,6 +18,7 @@ export class ChangeSet {
|
|
|
17
18
|
this.rootMeta = meta.root;
|
|
18
19
|
this.schema = helper(entity).__schema ?? meta.root.schema;
|
|
19
20
|
}
|
|
21
|
+
/** Returns the primary key of the entity, optionally as an object for composite keys. */
|
|
20
22
|
getPrimaryKey(object = false) {
|
|
21
23
|
if (!this.originalEntity) {
|
|
22
24
|
this.primaryKey ??= helper(this.entity).getPrimaryKey(true);
|
|
@@ -40,6 +42,7 @@ export class ChangeSet {
|
|
|
40
42
|
}
|
|
41
43
|
return this.primaryKey ?? null;
|
|
42
44
|
}
|
|
45
|
+
/** Returns the serialized (string) form of the primary key. */
|
|
43
46
|
getSerializedPrimaryKey() {
|
|
44
47
|
this.serializedPrimaryKey ??= helper(this.entity).getSerializedPrimaryKey();
|
|
45
48
|
return this.serializedPrimaryKey;
|
|
@@ -55,6 +58,7 @@ export class ChangeSet {
|
|
|
55
58
|
return ret === '[Object]' ? `[${name}]` : name + ' ' + ret;
|
|
56
59
|
}
|
|
57
60
|
}
|
|
61
|
+
/** Enumeration of change set operation types. */
|
|
58
62
|
export var ChangeSetType;
|
|
59
63
|
(function (ChangeSetType) {
|
|
60
64
|
ChangeSetType["CREATE"] = "create";
|
|
@@ -2,9 +2,11 @@ import type { AnyEntity } from '../typings.js';
|
|
|
2
2
|
import { ChangeSet } from './ChangeSet.js';
|
|
3
3
|
import { type Collection } from '../entity/Collection.js';
|
|
4
4
|
import type { EntityManager } from '../EntityManager.js';
|
|
5
|
+
/** @internal Computes change sets by comparing entity state against original snapshots. */
|
|
5
6
|
export declare class ChangeSetComputer {
|
|
6
7
|
#private;
|
|
7
8
|
constructor(em: EntityManager, collectionUpdates: Set<Collection<AnyEntity>>);
|
|
9
|
+
/** Computes a change set for the given entity by diffing against its original state. */
|
|
8
10
|
computeChangeSet<T extends object>(entity: T): ChangeSet<T> | null;
|
|
9
11
|
/**
|
|
10
12
|
* Traverses entity graph and executes `onCreate` and `onUpdate` methods, assigning the values to given properties.
|
|
@@ -6,6 +6,7 @@ import { validateEntity } from '../entity/validators.js';
|
|
|
6
6
|
import { Reference } from '../entity/Reference.js';
|
|
7
7
|
import { PolymorphicRef } from '../entity/PolymorphicRef.js';
|
|
8
8
|
import { ReferenceKind } from '../enums.js';
|
|
9
|
+
/** @internal Computes change sets by comparing entity state against original snapshots. */
|
|
9
10
|
export class ChangeSetComputer {
|
|
10
11
|
#comparator;
|
|
11
12
|
#metadata;
|
|
@@ -21,6 +22,7 @@ export class ChangeSetComputer {
|
|
|
21
22
|
this.#platform = this.#em.getPlatform();
|
|
22
23
|
this.#comparator = this.#config.getComparator(this.#metadata);
|
|
23
24
|
}
|
|
25
|
+
/** Computes a change set for the given entity by diffing against its original state. */
|
|
24
26
|
computeChangeSet(entity) {
|
|
25
27
|
const meta = this.#metadata.get(entity.constructor);
|
|
26
28
|
if (meta.readonly) {
|
|
@@ -2,11 +2,15 @@ import type { Dictionary, EntityDictionary, EntityMetadata } from '../typings.js
|
|
|
2
2
|
import { type ChangeSet } from './ChangeSet.js';
|
|
3
3
|
import type { DriverMethodOptions } from '../drivers/IDatabaseDriver.js';
|
|
4
4
|
import type { EntityManager } from '../EntityManager.js';
|
|
5
|
+
/** @internal Executes change sets against the database, handling inserts, updates, and deletes. */
|
|
5
6
|
export declare class ChangeSetPersister {
|
|
6
7
|
#private;
|
|
7
8
|
constructor(em: EntityManager);
|
|
9
|
+
/** Executes all pending INSERT change sets, using batch inserts when possible. */
|
|
8
10
|
executeInserts<T extends object>(changeSets: ChangeSet<T>[], options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
11
|
+
/** Executes all pending UPDATE change sets, using batch updates when possible. */
|
|
9
12
|
executeUpdates<T extends object>(changeSets: ChangeSet<T>[], batched: boolean, options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
13
|
+
/** Executes all pending DELETE change sets in batches. */
|
|
10
14
|
executeDeletes<T extends object>(changeSets: ChangeSet<T>[], options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
11
15
|
private runForEachSchema;
|
|
12
16
|
private validateRequired;
|
|
@@ -6,6 +6,7 @@ import { isRaw } from '../utils/RawQueryFragment.js';
|
|
|
6
6
|
import { Utils } from '../utils/Utils.js';
|
|
7
7
|
import { OptimisticLockError, ValidationError } from '../errors.js';
|
|
8
8
|
import { ReferenceKind } from '../enums.js';
|
|
9
|
+
/** @internal Executes change sets against the database, handling inserts, updates, and deletes. */
|
|
9
10
|
export class ChangeSetPersister {
|
|
10
11
|
#platform;
|
|
11
12
|
#comparator;
|
|
@@ -27,6 +28,7 @@ export class ChangeSetPersister {
|
|
|
27
28
|
this.#comparator = this.#config.getComparator(this.#metadata);
|
|
28
29
|
this.#usesReturningStatement = this.#platform.usesReturningStatement() || this.#platform.usesOutputStatement();
|
|
29
30
|
}
|
|
31
|
+
/** Executes all pending INSERT change sets, using batch inserts when possible. */
|
|
30
32
|
async executeInserts(changeSets, options, withSchema) {
|
|
31
33
|
if (!withSchema) {
|
|
32
34
|
return this.runForEachSchema(changeSets, 'executeInserts', options);
|
|
@@ -40,6 +42,7 @@ export class ChangeSetPersister {
|
|
|
40
42
|
await this.persistNewEntity(meta, changeSet, options);
|
|
41
43
|
}
|
|
42
44
|
}
|
|
45
|
+
/** Executes all pending UPDATE change sets, using batch updates when possible. */
|
|
43
46
|
async executeUpdates(changeSets, batched, options, withSchema) {
|
|
44
47
|
if (!withSchema) {
|
|
45
48
|
return this.runForEachSchema(changeSets, 'executeUpdates', options, batched);
|
|
@@ -59,6 +62,7 @@ export class ChangeSetPersister {
|
|
|
59
62
|
await this.persistManagedEntity(changeSet, options);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
65
|
+
/** Executes all pending DELETE change sets in batches. */
|
|
62
66
|
async executeDeletes(changeSets, options, withSchema) {
|
|
63
67
|
if (!withSchema) {
|
|
64
68
|
return this.runForEachSchema(changeSets, 'executeDeletes', options);
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import type { AnyEntity, EntityMetadata } from '../typings.js';
|
|
2
|
+
/** @internal Stores managed entity instances keyed by their primary key hash, ensuring each row is loaded once. */
|
|
2
3
|
export declare class IdentityMap {
|
|
3
4
|
#private;
|
|
4
5
|
constructor(defaultSchema?: string);
|
|
6
|
+
/** Stores an entity in the identity map under its primary key hash. */
|
|
5
7
|
store<T>(item: T): void;
|
|
6
8
|
/**
|
|
7
9
|
* Stores an entity under an alternate key (non-PK property).
|
|
8
10
|
* This allows looking up entities by unique properties that are not the primary key.
|
|
9
11
|
*/
|
|
10
12
|
storeByKey<T>(item: T, key: string, value: string, schema?: string): void;
|
|
13
|
+
/** Removes an entity and its alternate key entries from the identity map. */
|
|
11
14
|
delete<T>(item: T): void;
|
|
15
|
+
/** Retrieves an entity by its hash key from the identity map. */
|
|
12
16
|
getByHash<T>(meta: EntityMetadata<T>, hash: string): T | undefined;
|
|
17
|
+
/** Returns (or creates) the per-entity-class store within the identity map. */
|
|
13
18
|
getStore<T>(meta: EntityMetadata<T>): Map<string, T>;
|
|
14
19
|
clear(): void;
|
|
20
|
+
/** Returns all entities currently in the identity map. */
|
|
15
21
|
values(): AnyEntity[];
|
|
16
22
|
[Symbol.iterator](): IterableIterator<AnyEntity>;
|
|
23
|
+
/** Returns all hash keys currently in the identity map. */
|
|
17
24
|
keys(): string[];
|
|
18
25
|
/**
|
|
19
26
|
* For back compatibility only.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @internal Stores managed entity instances keyed by their primary key hash, ensuring each row is loaded once. */
|
|
1
2
|
export class IdentityMap {
|
|
2
3
|
#defaultSchema;
|
|
3
4
|
#registry = new Map();
|
|
@@ -6,6 +7,7 @@ export class IdentityMap {
|
|
|
6
7
|
constructor(defaultSchema) {
|
|
7
8
|
this.#defaultSchema = defaultSchema;
|
|
8
9
|
}
|
|
10
|
+
/** Stores an entity in the identity map under its primary key hash. */
|
|
9
11
|
store(item) {
|
|
10
12
|
this.getStore(item.__meta.root).set(this.getPkHash(item), item);
|
|
11
13
|
}
|
|
@@ -24,6 +26,7 @@ export class IdentityMap {
|
|
|
24
26
|
}
|
|
25
27
|
keys.add(hash);
|
|
26
28
|
}
|
|
29
|
+
/** Removes an entity and its alternate key entries from the identity map. */
|
|
27
30
|
delete(item) {
|
|
28
31
|
const meta = item.__meta.root;
|
|
29
32
|
const store = this.getStore(meta);
|
|
@@ -37,10 +40,12 @@ export class IdentityMap {
|
|
|
37
40
|
this.#alternateKeys.delete(item);
|
|
38
41
|
}
|
|
39
42
|
}
|
|
43
|
+
/** Retrieves an entity by its hash key from the identity map. */
|
|
40
44
|
getByHash(meta, hash) {
|
|
41
45
|
const store = this.getStore(meta);
|
|
42
46
|
return store.has(hash) ? store.get(hash) : undefined;
|
|
43
47
|
}
|
|
48
|
+
/** Returns (or creates) the per-entity-class store within the identity map. */
|
|
44
49
|
getStore(meta) {
|
|
45
50
|
const store = this.#registry.get(meta.class);
|
|
46
51
|
if (store) {
|
|
@@ -53,6 +58,7 @@ export class IdentityMap {
|
|
|
53
58
|
clear() {
|
|
54
59
|
this.#registry.clear();
|
|
55
60
|
}
|
|
61
|
+
/** Returns all entities currently in the identity map. */
|
|
56
62
|
values() {
|
|
57
63
|
const ret = [];
|
|
58
64
|
for (const store of this.#registry.values()) {
|
|
@@ -67,6 +73,7 @@ export class IdentityMap {
|
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
}
|
|
76
|
+
/** Returns all hash keys currently in the identity map. */
|
|
70
77
|
keys() {
|
|
71
78
|
const ret = [];
|
|
72
79
|
for (const [cls, store] of this.#registry) {
|
|
@@ -6,9 +6,11 @@ import { ChangeSetPersister } from './ChangeSetPersister.js';
|
|
|
6
6
|
import type { EntityManager } from '../EntityManager.js';
|
|
7
7
|
import { IdentityMap } from './IdentityMap.js';
|
|
8
8
|
import type { LockOptions } from '../drivers/IDatabaseDriver.js';
|
|
9
|
+
/** Implements the Unit of Work pattern: tracks entity changes, computes change sets, and flushes them to the database. */
|
|
9
10
|
export declare class UnitOfWork {
|
|
10
11
|
#private;
|
|
11
12
|
constructor(em: EntityManager);
|
|
13
|
+
/** Merges an entity into the identity map, taking a snapshot of its current state. */
|
|
12
14
|
merge<T extends object>(entity: T, visited?: Set<AnyEntity>): void;
|
|
13
15
|
/**
|
|
14
16
|
* Entity data can wary in its shape, e.g. we might get a deep relation graph with joined strategy, but for diffing,
|
|
@@ -45,6 +47,7 @@ export declare class UnitOfWork {
|
|
|
45
47
|
* If false (default), the value is assumed to be in JS format already.
|
|
46
48
|
*/
|
|
47
49
|
storeByKey<T extends object>(entity: T, key: string, value: unknown, schema?: string, convertCustomTypes?: boolean): void;
|
|
50
|
+
/** Attempts to extract a primary key from the where condition and look up the entity in the identity map. */
|
|
48
51
|
tryGetById<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, schema?: string, strict?: boolean): T | null;
|
|
49
52
|
/**
|
|
50
53
|
* Returns map of all managed entities.
|
|
@@ -54,10 +57,15 @@ export declare class UnitOfWork {
|
|
|
54
57
|
* Returns stored snapshot of entity state that is used for change set computation.
|
|
55
58
|
*/
|
|
56
59
|
getOriginalEntityData<T extends object>(entity: T): EntityData<T> | undefined;
|
|
60
|
+
/** Returns the set of entities scheduled for persistence. */
|
|
57
61
|
getPersistStack(): Set<AnyEntity>;
|
|
62
|
+
/** Returns the set of entities scheduled for removal. */
|
|
58
63
|
getRemoveStack(): Set<AnyEntity>;
|
|
64
|
+
/** Returns all computed change sets for the current flush. */
|
|
59
65
|
getChangeSets(): ChangeSet<AnyEntity>[];
|
|
66
|
+
/** Returns all M:N collections that need synchronization. */
|
|
60
67
|
getCollectionUpdates(): Collection<AnyEntity>[];
|
|
68
|
+
/** Returns extra updates needed for relations that could not be resolved in the initial pass. */
|
|
61
69
|
getExtraUpdates(): Set<[
|
|
62
70
|
AnyEntity,
|
|
63
71
|
string | string[],
|
|
@@ -65,17 +73,24 @@ export declare class UnitOfWork {
|
|
|
65
73
|
ChangeSet<any> | undefined,
|
|
66
74
|
ChangeSetType
|
|
67
75
|
]>;
|
|
76
|
+
/** Checks whether an auto-flush is needed before querying the given entity type. */
|
|
68
77
|
shouldAutoFlush<T extends object>(meta: EntityMetadata<T>): boolean;
|
|
78
|
+
/** Clears the queue of entity types that triggered auto-flush detection. */
|
|
69
79
|
clearActionsQueue(): void;
|
|
80
|
+
/** Computes and registers a change set for the given entity. */
|
|
70
81
|
computeChangeSet<T extends object>(entity: T, type?: ChangeSetType): void;
|
|
82
|
+
/** Recomputes and merges the change set for an already-tracked entity. */
|
|
71
83
|
recomputeSingleChangeSet<T extends object>(entity: T): void;
|
|
84
|
+
/** Marks an entity for persistence, cascading to related entities. */
|
|
72
85
|
persist<T extends object>(entity: T, visited?: Set<AnyEntity>, options?: {
|
|
73
86
|
checkRemoveStack?: boolean;
|
|
74
87
|
cascade?: boolean;
|
|
75
88
|
}): void;
|
|
89
|
+
/** Marks an entity for removal, cascading to related entities. */
|
|
76
90
|
remove<T extends object>(entity: T, visited?: Set<AnyEntity>, options?: {
|
|
77
91
|
cascade?: boolean;
|
|
78
92
|
}): void;
|
|
93
|
+
/** Flushes all pending changes to the database within a transaction. */
|
|
79
94
|
commit(): Promise<void>;
|
|
80
95
|
private doCommit;
|
|
81
96
|
lock<T extends object>(entity: T, options: LockOptions): Promise<void>;
|
|
@@ -15,6 +15,7 @@ import { IdentityMap } from './IdentityMap.js';
|
|
|
15
15
|
import { createAsyncContext } from '../utils/AsyncContext.js';
|
|
16
16
|
// to deal with validation for flush inside flush hooks and `Promise.all`
|
|
17
17
|
const insideFlush = createAsyncContext();
|
|
18
|
+
/** Implements the Unit of Work pattern: tracks entity changes, computes change sets, and flushes them to the database. */
|
|
18
19
|
export class UnitOfWork {
|
|
19
20
|
/** map of references to managed entities */
|
|
20
21
|
#identityMap;
|
|
@@ -45,6 +46,7 @@ export class UnitOfWork {
|
|
|
45
46
|
this.#changeSetComputer = new ChangeSetComputer(this.#em, this.#collectionUpdates);
|
|
46
47
|
this.#changeSetPersister = new ChangeSetPersister(this.#em);
|
|
47
48
|
}
|
|
49
|
+
/** Merges an entity into the identity map, taking a snapshot of its current state. */
|
|
48
50
|
merge(entity, visited) {
|
|
49
51
|
const wrapped = helper(entity);
|
|
50
52
|
wrapped.__em = this.#em;
|
|
@@ -217,6 +219,7 @@ export class UnitOfWork {
|
|
|
217
219
|
entity[key] = value;
|
|
218
220
|
this.#identityMap.storeByKey(entity, key, '' + value, schema);
|
|
219
221
|
}
|
|
222
|
+
/** Attempts to extract a primary key from the where condition and look up the entity in the identity map. */
|
|
220
223
|
tryGetById(entityName, where, schema, strict = true) {
|
|
221
224
|
const pk = Utils.extractPK(where, this.#metadata.find(entityName), strict);
|
|
222
225
|
if (!pk) {
|
|
@@ -236,21 +239,27 @@ export class UnitOfWork {
|
|
|
236
239
|
getOriginalEntityData(entity) {
|
|
237
240
|
return helper(entity).__originalEntityData;
|
|
238
241
|
}
|
|
242
|
+
/** Returns the set of entities scheduled for persistence. */
|
|
239
243
|
getPersistStack() {
|
|
240
244
|
return this.#persistStack;
|
|
241
245
|
}
|
|
246
|
+
/** Returns the set of entities scheduled for removal. */
|
|
242
247
|
getRemoveStack() {
|
|
243
248
|
return this.#removeStack;
|
|
244
249
|
}
|
|
250
|
+
/** Returns all computed change sets for the current flush. */
|
|
245
251
|
getChangeSets() {
|
|
246
252
|
return [...this.#changeSets.values()];
|
|
247
253
|
}
|
|
254
|
+
/** Returns all M:N collections that need synchronization. */
|
|
248
255
|
getCollectionUpdates() {
|
|
249
256
|
return [...this.#collectionUpdates];
|
|
250
257
|
}
|
|
258
|
+
/** Returns extra updates needed for relations that could not be resolved in the initial pass. */
|
|
251
259
|
getExtraUpdates() {
|
|
252
260
|
return this.#extraUpdates;
|
|
253
261
|
}
|
|
262
|
+
/** Checks whether an auto-flush is needed before querying the given entity type. */
|
|
254
263
|
shouldAutoFlush(meta) {
|
|
255
264
|
if (insideFlush.getStore()) {
|
|
256
265
|
return false;
|
|
@@ -263,9 +272,11 @@ export class UnitOfWork {
|
|
|
263
272
|
}
|
|
264
273
|
return false;
|
|
265
274
|
}
|
|
275
|
+
/** Clears the queue of entity types that triggered auto-flush detection. */
|
|
266
276
|
clearActionsQueue() {
|
|
267
277
|
this.#queuedActions.clear();
|
|
268
278
|
}
|
|
279
|
+
/** Computes and registers a change set for the given entity. */
|
|
269
280
|
computeChangeSet(entity, type) {
|
|
270
281
|
const wrapped = helper(entity);
|
|
271
282
|
if (type === ChangeSetType.DELETE || type === ChangeSetType.DELETE_EARLY) {
|
|
@@ -285,6 +296,7 @@ export class UnitOfWork {
|
|
|
285
296
|
this.#persistStack.delete(entity);
|
|
286
297
|
wrapped.__originalEntityData = this.#comparator.prepareEntity(entity);
|
|
287
298
|
}
|
|
299
|
+
/** Recomputes and merges the change set for an already-tracked entity. */
|
|
288
300
|
recomputeSingleChangeSet(entity) {
|
|
289
301
|
const changeSet = this.#changeSets.get(entity);
|
|
290
302
|
if (!changeSet) {
|
|
@@ -296,6 +308,7 @@ export class UnitOfWork {
|
|
|
296
308
|
helper(entity).__originalEntityData = this.#comparator.prepareEntity(entity);
|
|
297
309
|
}
|
|
298
310
|
}
|
|
311
|
+
/** Marks an entity for persistence, cascading to related entities. */
|
|
299
312
|
persist(entity, visited, options = {}) {
|
|
300
313
|
EntityHelper.ensurePropagation(entity);
|
|
301
314
|
if (options.checkRemoveStack && this.#removeStack.has(entity)) {
|
|
@@ -312,6 +325,7 @@ export class UnitOfWork {
|
|
|
312
325
|
this.cascade(entity, Cascade.PERSIST, visited, options);
|
|
313
326
|
}
|
|
314
327
|
}
|
|
328
|
+
/** Marks an entity for removal, cascading to related entities. */
|
|
315
329
|
remove(entity, visited, options = {}) {
|
|
316
330
|
// allow removing not managed entities if they are not part of the persist stack
|
|
317
331
|
if (helper(entity).__managed || !this.#persistStack.has(entity)) {
|
|
@@ -342,6 +356,7 @@ export class UnitOfWork {
|
|
|
342
356
|
this.cascade(entity, Cascade.REMOVE, visited);
|
|
343
357
|
}
|
|
344
358
|
}
|
|
359
|
+
/** Flushes all pending changes to the database within a transaction. */
|
|
345
360
|
async commit() {
|
|
346
361
|
if (this.#working) {
|
|
347
362
|
if (insideFlush.getStore()) {
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -15,14 +15,17 @@ import { DataloaderType, FlushMode, LoadStrategy, PopulateHint, type EmbeddedPre
|
|
|
15
15
|
import { EntityComparator } from './EntityComparator.js';
|
|
16
16
|
import type { Type } from '../types/Type.js';
|
|
17
17
|
import type { MikroORM } from '../MikroORM.js';
|
|
18
|
+
/** Holds and validates all ORM configuration options, providing access to drivers, loggers, cache adapters, and other services. */
|
|
18
19
|
export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>> {
|
|
19
20
|
#private;
|
|
20
21
|
constructor(options: Partial<Options>, validate?: boolean);
|
|
22
|
+
/** Returns the database platform instance. */
|
|
21
23
|
getPlatform(): ReturnType<D['getPlatform']>;
|
|
22
24
|
/**
|
|
23
25
|
* Gets specific configuration option. Falls back to specified `defaultValue` if provided.
|
|
24
26
|
*/
|
|
25
27
|
get<T extends keyof Options<D, EM>, U extends Options<D, EM>[T]>(key: T, defaultValue?: U): U;
|
|
28
|
+
/** Returns all configuration options. */
|
|
26
29
|
getAll(): Options<D, EM>;
|
|
27
30
|
/**
|
|
28
31
|
* Overrides specified configuration value.
|
|
@@ -41,13 +44,17 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
41
44
|
* Falls back to the main logger if no custom slow query logger factory is configured.
|
|
42
45
|
*/
|
|
43
46
|
getSlowQueryLogger(): Logger;
|
|
47
|
+
/** Returns the configured dataloader type, normalizing boolean values. */
|
|
44
48
|
getDataloaderType(): DataloaderType;
|
|
49
|
+
/** Returns the configured schema name, optionally skipping the platform's default schema. */
|
|
45
50
|
getSchema(skipDefaultSchema?: boolean): string | undefined;
|
|
46
51
|
/**
|
|
47
52
|
* Gets current database driver instance.
|
|
48
53
|
*/
|
|
49
54
|
getDriver(): D;
|
|
55
|
+
/** Registers a lazily-initialized extension by name. */
|
|
50
56
|
registerExtension(name: string, cb: () => unknown): void;
|
|
57
|
+
/** Returns a previously registered extension by name, initializing it on first access. */
|
|
51
58
|
getExtension<T>(name: string): T | undefined;
|
|
52
59
|
/**
|
|
53
60
|
* Gets instance of NamingStrategy. (cached)
|
|
@@ -83,6 +90,7 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
83
90
|
getCachedService<T extends {
|
|
84
91
|
new (...args: any[]): InstanceType<T>;
|
|
85
92
|
}>(cls: T, ...args: ConstructorParameters<T>): InstanceType<T>;
|
|
93
|
+
/** Clears the cached service instances, forcing re-creation on next access. */
|
|
86
94
|
resetServiceCache(): void;
|
|
87
95
|
private init;
|
|
88
96
|
private sync;
|
package/utils/Configuration.js
CHANGED
|
@@ -127,6 +127,7 @@ const DEFAULTS = {
|
|
|
127
127
|
preferReadReplicas: true,
|
|
128
128
|
dynamicImportProvider: /* v8 ignore next */ (id) => import(id),
|
|
129
129
|
};
|
|
130
|
+
/** Holds and validates all ORM configuration options, providing access to drivers, loggers, cache adapters, and other services. */
|
|
130
131
|
export class Configuration {
|
|
131
132
|
#options;
|
|
132
133
|
#logger;
|
|
@@ -162,6 +163,7 @@ export class Configuration {
|
|
|
162
163
|
this.init(validate);
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
/** Returns the database platform instance. */
|
|
165
167
|
getPlatform() {
|
|
166
168
|
return this.#platform;
|
|
167
169
|
}
|
|
@@ -174,6 +176,7 @@ export class Configuration {
|
|
|
174
176
|
}
|
|
175
177
|
return defaultValue;
|
|
176
178
|
}
|
|
179
|
+
/** Returns all configuration options. */
|
|
177
180
|
getAll() {
|
|
178
181
|
return this.#options;
|
|
179
182
|
}
|
|
@@ -210,12 +213,14 @@ export class Configuration {
|
|
|
210
213
|
}) ?? this.#logger;
|
|
211
214
|
return this.#slowQueryLogger;
|
|
212
215
|
}
|
|
216
|
+
/** Returns the configured dataloader type, normalizing boolean values. */
|
|
213
217
|
getDataloaderType() {
|
|
214
218
|
if (typeof this.#options.dataloader === 'boolean') {
|
|
215
219
|
return this.#options.dataloader ? DataloaderType.ALL : DataloaderType.NONE;
|
|
216
220
|
}
|
|
217
221
|
return this.#options.dataloader;
|
|
218
222
|
}
|
|
223
|
+
/** Returns the configured schema name, optionally skipping the platform's default schema. */
|
|
219
224
|
getSchema(skipDefaultSchema = false) {
|
|
220
225
|
if (skipDefaultSchema && this.#options.schema === this.#platform.getDefaultSchemaName()) {
|
|
221
226
|
return undefined;
|
|
@@ -228,9 +233,11 @@ export class Configuration {
|
|
|
228
233
|
getDriver() {
|
|
229
234
|
return this.#driver;
|
|
230
235
|
}
|
|
236
|
+
/** Registers a lazily-initialized extension by name. */
|
|
231
237
|
registerExtension(name, cb) {
|
|
232
238
|
this.#extensions.set(name, cb);
|
|
233
239
|
}
|
|
240
|
+
/** Returns a previously registered extension by name, initializing it on first access. */
|
|
234
241
|
getExtension(name) {
|
|
235
242
|
if (this.#cache.has(name)) {
|
|
236
243
|
return this.#cache.get(name);
|
|
@@ -303,6 +310,7 @@ export class Configuration {
|
|
|
303
310
|
}
|
|
304
311
|
return this.#cache.get(cls.name);
|
|
305
312
|
}
|
|
313
|
+
/** Clears the cached service instances, forcing re-creation on next access. */
|
|
306
314
|
resetServiceCache() {
|
|
307
315
|
this.#cache.clear();
|
|
308
316
|
}
|
|
@@ -9,6 +9,7 @@ type SnapshotGenerator<T> = (entity: T) => EntityData<T>;
|
|
|
9
9
|
type PkGetter<T> = (entity: T) => Primary<T>;
|
|
10
10
|
type PkSerializer<T> = (entity: T) => string;
|
|
11
11
|
type CompositeKeyPart = string | CompositeKeyPart[];
|
|
12
|
+
/** @internal Generates and caches JIT-compiled functions for comparing, snapshotting, and mapping entity data. */
|
|
12
13
|
export declare class EntityComparator {
|
|
13
14
|
#private;
|
|
14
15
|
constructor(metadata: IMetadataStorage, platform: Platform, config?: Configuration);
|
|
@@ -18,6 +19,7 @@ export declare class EntityComparator {
|
|
|
18
19
|
diffEntities<T extends object>(entityName: EntityName<T>, a: EntityData<T>, b: EntityData<T>, options?: {
|
|
19
20
|
includeInverseSides?: boolean;
|
|
20
21
|
}): EntityData<T>;
|
|
22
|
+
/** Returns true if two entity snapshots are identical (no differences). */
|
|
21
23
|
matching<T extends object>(entityName: EntityName<T>, a: EntityData<T>, b: EntityData<T>): boolean;
|
|
22
24
|
/**
|
|
23
25
|
* Removes ORM specific code from entities and prepares it for serializing. Used before change set computation.
|
|
@@ -5,6 +5,7 @@ import { JsonType } from '../types/JsonType.js';
|
|
|
5
5
|
import { Raw } from './RawQueryFragment.js';
|
|
6
6
|
import { EntityIdentifier } from '../entity/EntityIdentifier.js';
|
|
7
7
|
import { PolymorphicRef } from '../entity/PolymorphicRef.js';
|
|
8
|
+
/** @internal Generates and caches JIT-compiled functions for comparing, snapshotting, and mapping entity data. */
|
|
8
9
|
export class EntityComparator {
|
|
9
10
|
#comparators = new Map();
|
|
10
11
|
#mappers = new Map();
|
|
@@ -28,6 +29,7 @@ export class EntityComparator {
|
|
|
28
29
|
const comparator = this.getEntityComparator(entityName);
|
|
29
30
|
return Utils.callCompiledFunction(comparator, a, b, options);
|
|
30
31
|
}
|
|
32
|
+
/** Returns true if two entity snapshots are identical (no differences). */
|
|
31
33
|
matching(entityName, a, b) {
|
|
32
34
|
const diff = this.diffEntities(entityName, a, b);
|
|
33
35
|
return Utils.getObjectKeysSize(diff) === 0;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Highlighter } from '../typings.js';
|
|
2
|
+
/** No-op highlighter that returns SQL text unchanged. Used as the default when no syntax highlighting is configured. */
|
|
2
3
|
export declare class NullHighlighter implements Highlighter {
|
|
3
4
|
highlight(text: string): string;
|
|
4
5
|
}
|
package/utils/NullHighlighter.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AnyString, Dictionary, EntityKey } from '../typings.js';
|
|
2
2
|
declare const rawFragmentSymbolBrand: unique symbol;
|
|
3
|
+
/** Branded symbol type used as a unique key for tracking raw SQL fragments in object properties. */
|
|
3
4
|
export type RawQueryFragmentSymbol = symbol & {
|
|
4
5
|
readonly [rawFragmentSymbolBrand]: true;
|
|
5
6
|
};
|
|
7
|
+
/** Represents a raw SQL fragment with optional parameters, usable as both a value and an object key via Symbol coercion. */
|
|
6
8
|
export declare class RawQueryFragment<Alias extends string = string> {
|
|
7
9
|
#private;
|
|
8
10
|
readonly sql: string;
|
|
@@ -10,18 +12,25 @@ export declare class RawQueryFragment<Alias extends string = string> {
|
|
|
10
12
|
/** @internal Type-level only - used to track the alias for type inference */
|
|
11
13
|
private readonly __alias?;
|
|
12
14
|
constructor(sql: string, params?: unknown[]);
|
|
15
|
+
/** Returns a unique symbol key for this fragment, creating and caching it on first access. */
|
|
13
16
|
get key(): RawQueryFragmentSymbol;
|
|
17
|
+
/** Creates a new fragment with an alias appended via `as ??`. */
|
|
14
18
|
as<A extends string>(alias: A): RawQueryFragment<A>;
|
|
15
19
|
[Symbol.toPrimitive](hint: 'string'): RawQueryFragmentSymbol;
|
|
16
20
|
get [Symbol.toStringTag](): string;
|
|
17
21
|
toJSON(): string;
|
|
18
22
|
clone(): this;
|
|
23
|
+
/** Checks whether the given value is a symbol that maps to a known raw query fragment. */
|
|
19
24
|
static isKnownFragmentSymbol(key: unknown): key is RawQueryFragmentSymbol;
|
|
25
|
+
/** Checks whether an object has any symbol keys that are known raw query fragments. */
|
|
20
26
|
static hasObjectFragments(object: unknown): boolean;
|
|
27
|
+
/** Checks whether the given value is a RawQueryFragment instance or a known fragment symbol. */
|
|
21
28
|
static isKnownFragment(key: unknown): key is RawQueryFragment | symbol;
|
|
29
|
+
/** Retrieves the RawQueryFragment associated with the given key (instance or symbol). */
|
|
22
30
|
static getKnownFragment(key: unknown): RawQueryFragment | undefined;
|
|
23
31
|
}
|
|
24
32
|
export { RawQueryFragment as Raw };
|
|
33
|
+
/** Checks whether the given value is a `RawQueryFragment` instance. */
|
|
25
34
|
export declare function isRaw(value: unknown): value is RawQueryFragment;
|
|
26
35
|
/** @internal */
|
|
27
36
|
export declare const ALIAS_REPLACEMENT = "[::alias::]";
|
|
@@ -107,6 +116,7 @@ export declare namespace sql {
|
|
|
107
116
|
var lower: <R = RawQueryFragment<string> & symbol, T extends object = any>(key: string | ((alias: string) => string)) => R;
|
|
108
117
|
var upper: <R = RawQueryFragment<string> & symbol, T extends object = any>(key: string | ((alias: string) => string)) => R;
|
|
109
118
|
}
|
|
119
|
+
/** Creates a raw SQL function expression wrapping the given key (e.g., `lower(name)`). */
|
|
110
120
|
export declare function createSqlFunction<R = RawQueryFragment & symbol, T extends object = any>(func: string, key: string | ((alias: string) => string)): R;
|
|
111
121
|
/**
|
|
112
122
|
* Tag function providing quoting of db identifiers (table name, columns names, index names, ...).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Utils } from './Utils.js';
|
|
2
|
+
/** Represents a raw SQL fragment with optional parameters, usable as both a value and an object key via Symbol coercion. */
|
|
2
3
|
export class RawQueryFragment {
|
|
3
4
|
sql;
|
|
4
5
|
params;
|
|
@@ -8,6 +9,7 @@ export class RawQueryFragment {
|
|
|
8
9
|
this.sql = sql;
|
|
9
10
|
this.params = params;
|
|
10
11
|
}
|
|
12
|
+
/** Returns a unique symbol key for this fragment, creating and caching it on first access. */
|
|
11
13
|
get key() {
|
|
12
14
|
if (!this.#key) {
|
|
13
15
|
this.#key = Symbol(this.toJSON());
|
|
@@ -15,6 +17,7 @@ export class RawQueryFragment {
|
|
|
15
17
|
}
|
|
16
18
|
return this.#key;
|
|
17
19
|
}
|
|
20
|
+
/** Creates a new fragment with an alias appended via `as ??`. */
|
|
18
21
|
as(alias) {
|
|
19
22
|
return new RawQueryFragment(`${this.sql} as ??`, [...this.params, alias]);
|
|
20
23
|
}
|
|
@@ -35,19 +38,23 @@ export class RawQueryFragment {
|
|
|
35
38
|
clone() {
|
|
36
39
|
return this;
|
|
37
40
|
}
|
|
41
|
+
/** Checks whether the given value is a symbol that maps to a known raw query fragment. */
|
|
38
42
|
static isKnownFragmentSymbol(key) {
|
|
39
43
|
return typeof key === 'symbol' && this.#rawQueryReferences.has(key);
|
|
40
44
|
}
|
|
45
|
+
/** Checks whether an object has any symbol keys that are known raw query fragments. */
|
|
41
46
|
static hasObjectFragments(object) {
|
|
42
47
|
return (Utils.isPlainObject(object) &&
|
|
43
48
|
Object.getOwnPropertySymbols(object).some(symbol => this.isKnownFragmentSymbol(symbol)));
|
|
44
49
|
}
|
|
50
|
+
/** Checks whether the given value is a RawQueryFragment instance or a known fragment symbol. */
|
|
45
51
|
static isKnownFragment(key) {
|
|
46
52
|
if (key instanceof RawQueryFragment) {
|
|
47
53
|
return true;
|
|
48
54
|
}
|
|
49
55
|
return this.isKnownFragmentSymbol(key);
|
|
50
56
|
}
|
|
57
|
+
/** Retrieves the RawQueryFragment associated with the given key (instance or symbol). */
|
|
51
58
|
static getKnownFragment(key) {
|
|
52
59
|
if (key instanceof RawQueryFragment) {
|
|
53
60
|
return key;
|
|
@@ -70,6 +77,7 @@ export { RawQueryFragment as Raw };
|
|
|
70
77
|
Object.defineProperties(RawQueryFragment.prototype, {
|
|
71
78
|
__raw: { value: true, enumerable: false },
|
|
72
79
|
});
|
|
80
|
+
/** Checks whether the given value is a `RawQueryFragment` instance. */
|
|
73
81
|
export function isRaw(value) {
|
|
74
82
|
return typeof value === 'object' && value !== null && '__raw' in value;
|
|
75
83
|
}
|
|
@@ -178,6 +186,7 @@ export function raw(sql, params) {
|
|
|
178
186
|
export function sql(sql, ...values) {
|
|
179
187
|
return raw(sql.join('?'), values);
|
|
180
188
|
}
|
|
189
|
+
/** Creates a raw SQL function expression wrapping the given key (e.g., `lower(name)`). */
|
|
181
190
|
export function createSqlFunction(func, key) {
|
|
182
191
|
if (typeof key === 'string') {
|
|
183
192
|
return raw(`${func}(${key})`);
|
|
@@ -35,6 +35,7 @@ export declare class RequestContext {
|
|
|
35
35
|
static getEntityManager(name?: string): EntityManager | undefined;
|
|
36
36
|
private static createContext;
|
|
37
37
|
}
|
|
38
|
+
/** Options for creating a new RequestContext, allowing schema and logger overrides. */
|
|
38
39
|
export interface CreateContextOptions {
|
|
39
40
|
schema?: string;
|
|
40
41
|
loggerContext?: LoggingOptions;
|