@decaf-ts/core 0.7.2 → 0.7.3
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/README.md +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/lib/esm/identity/decorators.d.ts +3 -4
- package/lib/esm/identity/decorators.js +4 -10
- package/lib/esm/identity/decorators.js.map +1 -1
- package/lib/esm/identity/index.d.ts +0 -1
- package/lib/esm/identity/index.js +0 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/interfaces/ContextuallyLogged.d.ts +8 -0
- package/lib/esm/interfaces/ContextuallyLogged.js +2 -0
- package/lib/esm/interfaces/ContextuallyLogged.js.map +1 -0
- package/lib/esm/interfaces/ErrorParser.d.ts +2 -2
- package/lib/esm/interfaces/Executor.d.ts +1 -1
- package/lib/esm/interfaces/Observable.d.ts +8 -8
- package/lib/esm/interfaces/Observer.d.ts +2 -2
- package/lib/esm/interfaces/RawExecutor.d.ts +1 -1
- package/lib/esm/model/BaseModel.d.ts +2 -2
- package/lib/esm/model/BaseModel.js +2 -2
- package/lib/esm/model/construction.d.ts +9 -8
- package/lib/esm/model/construction.js +2 -2
- package/lib/esm/model/construction.js.map +1 -1
- package/lib/esm/model/decorators.d.ts +4 -3
- package/lib/esm/model/decorators.js +2 -2
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/overrides/Metadata.d.ts +1 -8
- package/lib/esm/overrides/Model.d.ts +75 -0
- package/lib/esm/overrides/Model.js +2 -0
- package/lib/esm/overrides/Model.js.map +1 -0
- package/lib/esm/overrides/index.d.ts +2 -0
- package/lib/esm/overrides/index.js +2 -0
- package/lib/esm/overrides/index.js.map +1 -1
- package/lib/esm/overrides/injectables.d.ts +10 -0
- package/lib/esm/overrides/injectables.js +2 -0
- package/lib/esm/overrides/injectables.js.map +1 -0
- package/lib/esm/overrides/overrides.js +45 -3
- package/lib/esm/overrides/overrides.js.map +1 -1
- package/lib/esm/persistence/Adapter.d.ts +52 -51
- package/lib/esm/persistence/Adapter.js +76 -61
- package/lib/esm/persistence/Adapter.js.map +1 -1
- package/lib/esm/persistence/Dispatch.d.ts +7 -6
- package/lib/esm/persistence/Dispatch.js +25 -18
- package/lib/esm/persistence/Dispatch.js.map +1 -1
- package/lib/esm/persistence/ObserverHandler.d.ts +7 -6
- package/lib/esm/persistence/ObserverHandler.js +5 -4
- package/lib/esm/persistence/ObserverHandler.js.map +1 -1
- package/lib/esm/persistence/Sequence.d.ts +10 -17
- package/lib/esm/persistence/Sequence.js +10 -15
- package/lib/esm/persistence/Sequence.js.map +1 -1
- package/lib/esm/persistence/constants.d.ts +1 -0
- package/lib/esm/persistence/constants.js +1 -0
- package/lib/esm/persistence/constants.js.map +1 -1
- package/lib/esm/persistence/migrations.d.ts +8 -8
- package/lib/esm/persistence/migrations.js +8 -9
- package/lib/esm/persistence/migrations.js.map +1 -1
- package/lib/esm/persistence/types.d.ts +38 -20
- package/lib/esm/query/Paginator.d.ts +6 -5
- package/lib/esm/query/Paginator.js +4 -4
- package/lib/esm/query/Paginator.js.map +1 -1
- package/lib/esm/query/Statement.d.ts +9 -8
- package/lib/esm/query/Statement.js +23 -10
- package/lib/esm/query/Statement.js.map +1 -1
- package/lib/esm/ram/RamAdapter.d.ts +21 -21
- package/lib/esm/ram/RamAdapter.js +36 -23
- package/lib/esm/ram/RamAdapter.js.map +1 -1
- package/lib/esm/ram/RamPaginator.d.ts +2 -1
- package/lib/esm/ram/RamPaginator.js +5 -3
- package/lib/esm/ram/RamPaginator.js.map +1 -1
- package/lib/esm/ram/RamSequence.d.ts +4 -11
- package/lib/esm/ram/RamSequence.js +20 -24
- package/lib/esm/ram/RamSequence.js.map +1 -1
- package/lib/esm/ram/RamStatement.d.ts +7 -7
- package/lib/esm/ram/RamStatement.js.map +1 -1
- package/lib/esm/ram/handlers.d.ts +3 -4
- package/lib/esm/ram/handlers.js.map +1 -1
- package/lib/esm/ram/index.d.ts +0 -1
- package/lib/esm/ram/index.js +0 -1
- package/lib/esm/ram/index.js.map +1 -1
- package/lib/esm/ram/types.d.ts +4 -12
- package/lib/esm/repository/Repository.d.ts +31 -95
- package/lib/esm/repository/Repository.js +106 -201
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/decorators.js +3 -2
- package/lib/esm/repository/decorators.js.map +1 -1
- package/lib/esm/repository/utils.d.ts +1 -1
- package/lib/esm/repository/utils.js +2 -3
- package/lib/esm/repository/utils.js.map +1 -1
- package/lib/esm/utils/ContextualLoggedClass.d.ts +16 -0
- package/lib/esm/utils/ContextualLoggedClass.js +29 -0
- package/lib/esm/utils/ContextualLoggedClass.js.map +1 -0
- package/lib/esm/utils/Services.d.ts +28 -0
- package/lib/esm/utils/Services.js +88 -0
- package/lib/esm/utils/Services.js.map +1 -0
- package/lib/esm/utils/decorators.d.ts +1 -9
- package/lib/esm/utils/decorators.js +26 -15
- package/lib/esm/utils/decorators.js.map +1 -1
- package/lib/esm/utils/index.d.ts +2 -1
- package/lib/esm/utils/index.js +2 -1
- package/lib/esm/utils/index.js.map +1 -1
- package/lib/identity/decorators.cjs +3 -9
- package/lib/identity/decorators.d.ts +3 -4
- package/lib/identity/decorators.js.map +1 -1
- package/lib/identity/index.cjs +0 -1
- package/lib/identity/index.d.ts +0 -1
- package/lib/identity/index.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/interfaces/ContextuallyLogged.cjs +3 -0
- package/lib/interfaces/ContextuallyLogged.d.ts +8 -0
- package/lib/interfaces/ContextuallyLogged.js.map +1 -0
- package/lib/interfaces/ErrorParser.d.ts +2 -2
- package/lib/interfaces/Executor.d.ts +1 -1
- package/lib/interfaces/Observable.d.ts +8 -8
- package/lib/interfaces/Observer.d.ts +2 -2
- package/lib/interfaces/RawExecutor.d.ts +1 -1
- package/lib/model/BaseModel.cjs +2 -2
- package/lib/model/BaseModel.d.ts +2 -2
- package/lib/model/construction.cjs +2 -2
- package/lib/model/construction.d.ts +9 -8
- package/lib/model/construction.js.map +1 -1
- package/lib/model/decorators.cjs +1 -1
- package/lib/model/decorators.d.ts +4 -3
- package/lib/model/decorators.js.map +1 -1
- package/lib/overrides/Metadata.d.ts +1 -8
- package/lib/overrides/Model.cjs +4 -0
- package/lib/overrides/Model.d.ts +75 -0
- package/lib/overrides/Model.js.map +1 -0
- package/lib/overrides/index.cjs +2 -0
- package/lib/overrides/index.d.ts +2 -0
- package/lib/overrides/index.js.map +1 -1
- package/lib/overrides/injectables.cjs +4 -0
- package/lib/overrides/injectables.d.ts +10 -0
- package/lib/overrides/injectables.js.map +1 -0
- package/lib/overrides/overrides.cjs +43 -1
- package/lib/overrides/overrides.js.map +1 -1
- package/lib/persistence/Adapter.cjs +81 -66
- package/lib/persistence/Adapter.d.ts +52 -51
- package/lib/persistence/Adapter.js.map +1 -1
- package/lib/persistence/Dispatch.cjs +25 -18
- package/lib/persistence/Dispatch.d.ts +7 -6
- package/lib/persistence/Dispatch.js.map +1 -1
- package/lib/persistence/ObserverHandler.cjs +5 -4
- package/lib/persistence/ObserverHandler.d.ts +7 -6
- package/lib/persistence/ObserverHandler.js.map +1 -1
- package/lib/persistence/Sequence.cjs +10 -15
- package/lib/persistence/Sequence.d.ts +10 -17
- package/lib/persistence/Sequence.js.map +1 -1
- package/lib/persistence/constants.cjs +1 -0
- package/lib/persistence/constants.d.ts +1 -0
- package/lib/persistence/constants.js.map +1 -1
- package/lib/persistence/migrations.cjs +7 -8
- package/lib/persistence/migrations.d.ts +8 -8
- package/lib/persistence/migrations.js.map +1 -1
- package/lib/persistence/types.d.ts +38 -20
- package/lib/query/Paginator.cjs +4 -4
- package/lib/query/Paginator.d.ts +6 -5
- package/lib/query/Paginator.js.map +1 -1
- package/lib/query/Statement.cjs +34 -21
- package/lib/query/Statement.d.ts +9 -8
- package/lib/query/Statement.js.map +1 -1
- package/lib/ram/RamAdapter.cjs +35 -22
- package/lib/ram/RamAdapter.d.ts +21 -21
- package/lib/ram/RamAdapter.js.map +1 -1
- package/lib/ram/RamPaginator.cjs +5 -3
- package/lib/ram/RamPaginator.d.ts +2 -1
- package/lib/ram/RamPaginator.js.map +1 -1
- package/lib/ram/RamSequence.cjs +19 -23
- package/lib/ram/RamSequence.d.ts +4 -11
- package/lib/ram/RamSequence.js.map +1 -1
- package/lib/ram/RamStatement.d.ts +7 -7
- package/lib/ram/RamStatement.js.map +1 -1
- package/lib/ram/handlers.d.ts +3 -4
- package/lib/ram/handlers.js.map +1 -1
- package/lib/ram/index.cjs +0 -1
- package/lib/ram/index.d.ts +0 -1
- package/lib/ram/index.js.map +1 -1
- package/lib/ram/types.d.ts +4 -12
- package/lib/repository/Repository.cjs +107 -202
- package/lib/repository/Repository.d.ts +31 -95
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/decorators.cjs +1 -0
- package/lib/repository/decorators.js.map +1 -1
- package/lib/repository/utils.cjs +2 -3
- package/lib/repository/utils.d.ts +1 -1
- package/lib/repository/utils.js.map +1 -1
- package/lib/utils/ContextualLoggedClass.cjs +33 -0
- package/lib/utils/ContextualLoggedClass.d.ts +16 -0
- package/lib/utils/ContextualLoggedClass.js.map +1 -0
- package/lib/utils/Services.cjs +93 -0
- package/lib/utils/Services.d.ts +28 -0
- package/lib/utils/Services.js.map +1 -0
- package/lib/utils/decorators.cjs +27 -16
- package/lib/utils/decorators.d.ts +1 -9
- package/lib/utils/decorators.js.map +1 -1
- package/lib/utils/index.cjs +2 -1
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/esm/identity/utils.d.ts +0 -24
- package/lib/esm/identity/utils.js +0 -44
- package/lib/esm/identity/utils.js.map +0 -1
- package/lib/esm/ram/RamContext.d.ts +0 -28
- package/lib/esm/ram/RamContext.js +0 -30
- package/lib/esm/ram/RamContext.js.map +0 -1
- package/lib/identity/utils.cjs +0 -49
- package/lib/identity/utils.d.ts +0 -24
- package/lib/identity/utils.js.map +0 -1
- package/lib/ram/RamContext.cjs +0 -34
- package/lib/ram/RamContext.d.ts +0 -28
- package/lib/ram/RamContext.js.map +0 -1
package/lib/ram/handlers.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { Repo } from "../repository";
|
|
3
2
|
import { RelationsMetadata } from "../model";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { RamRepository } from "./types";
|
|
4
|
+
import { RamContext } from "./types";
|
|
6
5
|
/**
|
|
7
6
|
* @description Sets the created by field on a model during RAM create/update operations
|
|
8
7
|
* @summary Automatically populates a model field with the UUID from the context during create or update operations.
|
|
@@ -22,4 +21,4 @@ import { Context } from "@decaf-ts/db-decorators";
|
|
|
22
21
|
* @memberOf module:core
|
|
23
22
|
* @category Ram
|
|
24
23
|
*/
|
|
25
|
-
export declare function createdByOnRamCreateUpdate<M extends Model, R extends
|
|
24
|
+
export declare function createdByOnRamCreateUpdate<M extends Model, R extends RamRepository<M>>(this: R, context: RamContext, data: RelationsMetadata, key: keyof M, model: M): Promise<void>;
|
package/lib/ram/handlers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/ram/handlers.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/ram/handlers.ts"],"names":[],"mappings":";;AAyBA,gEAgBC;AAtCD,4DAAkD;AAGlD;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,0BAA0B,CAK9C,OAAmB,EACnB,IAAuB,EACvB,GAAY,EACZ,KAAQ;IAER,MAAM,IAAI,GAAW,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,IAAI;QACP,MAAM,IAAI,8BAAgB,CACxB,mDAAmD,CACpD,CAAC;IACJ,KAAK,CAAC,GAAG,CAAC,GAAG,IAAkB,CAAC;AAClC,CAAC"}
|
package/lib/ram/index.cjs
CHANGED
|
@@ -20,7 +20,6 @@ RamAdapter_1.RamAdapter.decoration();
|
|
|
20
20
|
__exportStar(require("./model/index.cjs"), exports);
|
|
21
21
|
__exportStar(require("./constants.cjs"), exports);
|
|
22
22
|
__exportStar(require("./handlers.cjs"), exports);
|
|
23
|
-
__exportStar(require("./RamContext.cjs"), exports);
|
|
24
23
|
__exportStar(require("./RamPaginator.cjs"), exports);
|
|
25
24
|
__exportStar(require("./RamStatement.cjs"), exports);
|
|
26
25
|
__exportStar(require("./RamSequence.cjs"), exports);
|
package/lib/ram/index.d.ts
CHANGED
package/lib/ram/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ram/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,8CAA8C;AAC9C,uBAAU,CAAC,UAAU,EAAE,CAAC;AAExB,oDAAwB;AACxB,kDAA4B;AAC5B,iDAA2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ram/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,8CAA8C;AAC9C,uBAAU,CAAC,UAAU,EAAE,CAAC;AAExB,oDAAwB;AACxB,kDAA4B;AAC5B,iDAA2B;AAC3B,qDAA+B;AAC/B,qDAA+B;AAC/B,oDAA8B;AAC9B,8CAAwB;AACxB,0BAA0B;AAC1B,mDAA6B"}
|
package/lib/ram/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { Repository } from "../repository";
|
|
3
3
|
import { Context, RepositoryFlags } from "@decaf-ts/db-decorators";
|
|
4
|
-
import { RamAdapter } from "./RamAdapter";
|
|
5
4
|
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
+
import { Adapter } from "../persistence";
|
|
6
6
|
/**
|
|
7
7
|
* @description In-memory storage structure for the RAM adapter
|
|
8
8
|
* @summary A nested Map structure that stores all entities by their table name and primary key.
|
|
@@ -28,7 +28,7 @@ export type RamStorage = Map<string, Map<string | number, any>>;
|
|
|
28
28
|
* @memberOf module:core
|
|
29
29
|
* @category Ram
|
|
30
30
|
*/
|
|
31
|
-
export type RawRamQuery<M extends Model> = {
|
|
31
|
+
export type RawRamQuery<M extends Model = any> = {
|
|
32
32
|
select: undefined | (keyof M)[];
|
|
33
33
|
from: Constructor<M>;
|
|
34
34
|
where: (el: M) => boolean;
|
|
@@ -48,16 +48,8 @@ export type RawRamQuery<M extends Model> = {
|
|
|
48
48
|
export interface RamFlags extends RepositoryFlags {
|
|
49
49
|
UUID: string;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @summary A specialized repository type for working with models in the RAM adapter.
|
|
54
|
-
* It combines the model type with RAM-specific query, adapter, flags, and context types.
|
|
55
|
-
* @template M - The model type managed by the repository
|
|
56
|
-
* @typedef {Repository<M, RawRamQuery<any>, RamAdapter, RamFlags, Context<RamFlags>>} RamRepository
|
|
57
|
-
* @memberOf module:core
|
|
58
|
-
* @category Ram
|
|
59
|
-
*/
|
|
60
|
-
export type RamRepository<M extends Model<true | false>> = Repository<M, RawRamQuery<any>, RamAdapter, RamFlags, Context<RamFlags>>;
|
|
51
|
+
export type RamRepository<M extends Model<boolean>> = Repository<M, Adapter<RamConfig, RamStorage, RawRamQuery<any>, RamContext>>;
|
|
52
|
+
export type RamContext = Context<RamFlags>;
|
|
61
53
|
export type RamConfig = {
|
|
62
54
|
user: string;
|
|
63
55
|
};
|
|
@@ -17,9 +17,8 @@ const constants_1 = require("./../persistence/constants.cjs");
|
|
|
17
17
|
const constants_2 = require("./constants.cjs");
|
|
18
18
|
const Sequence_1 = require("./../persistence/Sequence.cjs");
|
|
19
19
|
const Condition_1 = require("./../query/Condition.cjs");
|
|
20
|
-
const utils_1 = require("./../identity/utils.cjs");
|
|
21
20
|
const ObserverHandler_1 = require("./../persistence/ObserverHandler.cjs");
|
|
22
|
-
const
|
|
21
|
+
const logging_1 = require("@decaf-ts/logging");
|
|
23
22
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
24
23
|
/**
|
|
25
24
|
* @description Core repository implementation for database operations on models on a table by table way.
|
|
@@ -105,13 +104,14 @@ class Repository extends db_decorators_1.Repository {
|
|
|
105
104
|
*/
|
|
106
105
|
get tableName() {
|
|
107
106
|
if (!this._tableName)
|
|
108
|
-
this._tableName =
|
|
107
|
+
this._tableName = decorator_validation_1.Model.tableName(this.class);
|
|
109
108
|
return this._tableName;
|
|
110
109
|
}
|
|
111
110
|
/**
|
|
112
111
|
* @description Primary key properties for this repository's model.
|
|
113
112
|
* @summary Gets the sequence options containing primary key information.
|
|
114
113
|
* @return {SequenceOptions} The primary key properties.
|
|
114
|
+
* @deprecated for Model.sequenceFor(class)
|
|
115
115
|
*/
|
|
116
116
|
get pkProps() {
|
|
117
117
|
return super.pkProps;
|
|
@@ -125,17 +125,6 @@ class Repository extends db_decorators_1.Repository {
|
|
|
125
125
|
if (clazz) {
|
|
126
126
|
Repository.register(clazz, this, this.adapter.alias);
|
|
127
127
|
if (adapter) {
|
|
128
|
-
// const flavour = Metadata.flavourOf(clazz);
|
|
129
|
-
// if (
|
|
130
|
-
// flavour &&
|
|
131
|
-
// flavour !== DefaultFlavour &&
|
|
132
|
-
// flavour !== adapter.flavour
|
|
133
|
-
// ) {
|
|
134
|
-
// this.log.warn(
|
|
135
|
-
// `Incompatible flavours detected between adapter (${adapter.flavour}) and model (${flavour})`
|
|
136
|
-
// );
|
|
137
|
-
// // throw new InternalError("Incompatible flavours");
|
|
138
|
-
// }
|
|
139
128
|
const flavour = decoration_1.Metadata.get(clazz, decoration_1.DecorationKeys.FLAVOUR);
|
|
140
129
|
if (flavour === decoration_1.DefaultFlavour) {
|
|
141
130
|
(0, decoration_1.uses)(adapter.flavour)(clazz);
|
|
@@ -147,6 +136,9 @@ class Repository extends db_decorators_1.Repository {
|
|
|
147
136
|
(0, db_decorators_1.wrapMethodWithContext)(this, this[name + "Prefix"], m, this[name + "Suffix"]);
|
|
148
137
|
});
|
|
149
138
|
}
|
|
139
|
+
logCtx(args, method) {
|
|
140
|
+
return Adapter_1.Adapter.logCtx(args, method);
|
|
141
|
+
}
|
|
150
142
|
/**
|
|
151
143
|
* @description Creates a proxy with overridden repository flags.
|
|
152
144
|
* @summary Returns a proxy of this repository with the specified flags overridden.
|
|
@@ -154,9 +146,6 @@ class Repository extends db_decorators_1.Repository {
|
|
|
154
146
|
* @return {Repository} A proxy of this repository with overridden flags.
|
|
155
147
|
*/
|
|
156
148
|
override(flags) {
|
|
157
|
-
this.log
|
|
158
|
-
.for(this.override)
|
|
159
|
-
.debug(`Overriding repository flags with ${JSON.stringify(flags)}`);
|
|
160
149
|
return new Proxy(this, {
|
|
161
150
|
get: (target, p, receiver) => {
|
|
162
151
|
const result = Reflect.get(target, p, receiver);
|
|
@@ -208,11 +197,16 @@ class Repository extends db_decorators_1.Repository {
|
|
|
208
197
|
*/
|
|
209
198
|
async createPrefix(model, ...args) {
|
|
210
199
|
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.CREATE, this.class, args, this.adapter, this._overrides || {});
|
|
200
|
+
const shouldRunHandlers = contextArgs.context.get("ignoreHandlers") !== false;
|
|
201
|
+
const shouldValidate = !contextArgs.context.get("ignoreValidation");
|
|
211
202
|
model = new this.class(model);
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
203
|
+
if (shouldRunHandlers)
|
|
204
|
+
await (0, db_decorators_1.enforceDBDecorators)(this, contextArgs.context, model, db_decorators_1.OperationKeys.CREATE, db_decorators_1.OperationKeys.ON);
|
|
205
|
+
if (shouldValidate) {
|
|
206
|
+
const errors = await Promise.resolve(model.hasErrors(...(contextArgs.context.get("ignoredValidationProperties") || [])));
|
|
207
|
+
if (errors)
|
|
208
|
+
throw new db_decorators_1.ValidationError(errors.toString());
|
|
209
|
+
}
|
|
216
210
|
return [model, ...contextArgs.args];
|
|
217
211
|
}
|
|
218
212
|
/**
|
|
@@ -223,13 +217,12 @@ class Repository extends db_decorators_1.Repository {
|
|
|
223
217
|
* @return {Promise<M>} The created model with updated properties.
|
|
224
218
|
*/
|
|
225
219
|
async create(model, ...args) {
|
|
220
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.create);
|
|
221
|
+
log.debug(`Creating new ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)}`);
|
|
226
222
|
// eslint-disable-next-line prefer-const
|
|
227
|
-
let { record, id, transient } = this.adapter.prepare(model,
|
|
228
|
-
record = await this.adapter.create(this.
|
|
229
|
-
|
|
230
|
-
if (args.length)
|
|
231
|
-
c = args[args.length - 1];
|
|
232
|
-
return this.adapter.revert(record, this.class, this.pk, id, c && c.get("rebuildWithTransient") ? transient : undefined);
|
|
223
|
+
let { record, id, transient } = this.adapter.prepare(model, ctx);
|
|
224
|
+
record = await this.adapter.create(this.class, id, record, ...ctxArgs);
|
|
225
|
+
return this.adapter.revert(record, this.class, id, transient, ctx);
|
|
233
226
|
}
|
|
234
227
|
/**
|
|
235
228
|
* @description Post-creation hook.
|
|
@@ -251,11 +244,13 @@ class Repository extends db_decorators_1.Repository {
|
|
|
251
244
|
async createAll(models, ...args) {
|
|
252
245
|
if (!models.length)
|
|
253
246
|
return models;
|
|
254
|
-
const
|
|
247
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.createAll);
|
|
248
|
+
log.debug(`Creating ${models.length} new ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)}`);
|
|
249
|
+
const prepared = models.map((m) => this.adapter.prepare(m, ctx));
|
|
255
250
|
const ids = prepared.map((p) => p.id);
|
|
256
251
|
let records = prepared.map((p) => p.record);
|
|
257
|
-
records = await this.adapter.createAll(this.
|
|
258
|
-
return records.map((r, i) => this.adapter.revert(r, this.class,
|
|
252
|
+
records = await this.adapter.createAll(this.class, ids, records, ...ctxArgs);
|
|
253
|
+
return records.map((r, i) => this.adapter.revert(r, this.class, ids[i], ctx.get("rebuildWithTransient") ? prepared[i].transient : undefined, ctx));
|
|
259
254
|
}
|
|
260
255
|
/**
|
|
261
256
|
* @description Prepares multiple models for creation.
|
|
@@ -267,14 +262,16 @@ class Repository extends db_decorators_1.Repository {
|
|
|
267
262
|
*/
|
|
268
263
|
async createAllPrefix(models, ...args) {
|
|
269
264
|
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.CREATE, this.class, args, this.adapter, this._overrides || {});
|
|
265
|
+
const shouldRunHandlers = contextArgs.context.get("ignoreHandlers") !== false;
|
|
266
|
+
const shouldValidate = !contextArgs.context.get("ignoreValidation");
|
|
270
267
|
if (!models.length)
|
|
271
268
|
return [models, ...contextArgs.args];
|
|
272
|
-
const opts =
|
|
269
|
+
const opts = decorator_validation_1.Model.sequenceFor(models[0]);
|
|
273
270
|
let ids = [];
|
|
274
271
|
if (opts.type) {
|
|
275
272
|
if (!opts.name)
|
|
276
273
|
opts.name = Sequence_1.Sequence.pk(models[0]);
|
|
277
|
-
ids = await (await this.adapter.Sequence(opts)).range(models.length);
|
|
274
|
+
ids = await (await this.adapter.Sequence(opts)).range(models.length, ...contextArgs.args);
|
|
278
275
|
}
|
|
279
276
|
else {
|
|
280
277
|
ids = models.map((m, i) => {
|
|
@@ -292,21 +289,17 @@ class Repository extends db_decorators_1.Repository {
|
|
|
292
289
|
? ids[i]
|
|
293
290
|
: `${m[this.pk]}`.toString());
|
|
294
291
|
}
|
|
295
|
-
|
|
292
|
+
if (shouldRunHandlers)
|
|
293
|
+
await (0, db_decorators_1.enforceDBDecorators)(this, contextArgs.context, m, db_decorators_1.OperationKeys.CREATE, db_decorators_1.OperationKeys.ON);
|
|
296
294
|
return m;
|
|
297
295
|
}));
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
: ` - ${i}: ${e.toString()}`;
|
|
306
|
-
return accum;
|
|
307
|
-
}, undefined);
|
|
308
|
-
if (errorMessages)
|
|
309
|
-
throw new db_decorators_1.ValidationError(errorMessages);
|
|
296
|
+
if (shouldValidate) {
|
|
297
|
+
const ignoredProps = contextArgs.context.get("ignoredValidationProperties") || [];
|
|
298
|
+
const errors = await Promise.all(models.map((m) => Promise.resolve(m.hasErrors(...ignoredProps))));
|
|
299
|
+
const errorMessages = (0, db_decorators_1.reduceErrorsToPrint)(errors);
|
|
300
|
+
if (errorMessages)
|
|
301
|
+
throw new db_decorators_1.ValidationError(errorMessages);
|
|
302
|
+
}
|
|
310
303
|
return [models, ...contextArgs.args];
|
|
311
304
|
}
|
|
312
305
|
/**
|
|
@@ -326,13 +319,15 @@ class Repository extends db_decorators_1.Repository {
|
|
|
326
319
|
/**
|
|
327
320
|
* @description Reads a model from the database by ID.
|
|
328
321
|
* @summary Retrieves a model instance from the database using its primary key.
|
|
329
|
-
* @param {
|
|
322
|
+
* @param {PrimaryKeyType} id - The primary key of the model to read.
|
|
330
323
|
* @param {...any[]} args - Additional arguments.
|
|
331
324
|
* @return {Promise<M>} The retrieved model instance.
|
|
332
325
|
*/
|
|
333
326
|
async read(id, ...args) {
|
|
334
|
-
const
|
|
335
|
-
|
|
327
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.read);
|
|
328
|
+
log.debug(`reading ${this.class.name} from table ${decorator_validation_1.Model.tableName(this.class)} with pk ${this.pk}`);
|
|
329
|
+
const m = await this.adapter.read(this.class, id, ...ctxArgs);
|
|
330
|
+
return this.adapter.revert(m, this.class, id, undefined, ctx);
|
|
336
331
|
}
|
|
337
332
|
/**
|
|
338
333
|
* @description Prepares for reading multiple models by IDs.
|
|
@@ -358,8 +353,10 @@ class Repository extends db_decorators_1.Repository {
|
|
|
358
353
|
* @return {Promise<M[]>} The retrieved model instances.
|
|
359
354
|
*/
|
|
360
355
|
async readAll(keys, ...args) {
|
|
361
|
-
const
|
|
362
|
-
|
|
356
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.readAll);
|
|
357
|
+
log.debug(`reading ${keys.length} ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)}`);
|
|
358
|
+
const records = await this.adapter.readAll(this.class, keys, ...ctxArgs);
|
|
359
|
+
return records.map((r, i) => this.adapter.revert(r, this.class, keys[i], undefined, ctx));
|
|
363
360
|
}
|
|
364
361
|
/**
|
|
365
362
|
* @description Updates a model in the database.
|
|
@@ -369,10 +366,12 @@ class Repository extends db_decorators_1.Repository {
|
|
|
369
366
|
* @return {Promise<M>} The updated model with refreshed properties.
|
|
370
367
|
*/
|
|
371
368
|
async update(model, ...args) {
|
|
369
|
+
const { ctxArgs, log, ctx } = this.logCtx(args, this.update);
|
|
372
370
|
// eslint-disable-next-line prefer-const
|
|
373
|
-
let { record, id, transient } = this.adapter.prepare(model,
|
|
374
|
-
|
|
375
|
-
|
|
371
|
+
let { record, id, transient } = this.adapter.prepare(model, ctx);
|
|
372
|
+
log.debug(`updating ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)} with id ${id}`);
|
|
373
|
+
record = await this.adapter.update(this.class, id, record, ...ctxArgs);
|
|
374
|
+
return this.adapter.revert(record, this.class, id, transient, ctx);
|
|
376
375
|
}
|
|
377
376
|
/**
|
|
378
377
|
* @description Prepares a model for update.
|
|
@@ -385,18 +384,19 @@ class Repository extends db_decorators_1.Repository {
|
|
|
385
384
|
*/
|
|
386
385
|
async updatePrefix(model, ...args) {
|
|
387
386
|
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.UPDATE, this.class, args, this.adapter, this._overrides || {});
|
|
387
|
+
const shouldRunHandlers = contextArgs.context.get("ignoreHandlers") !== false;
|
|
388
|
+
const shouldValidate = !contextArgs.context.get("ignoreValidation");
|
|
388
389
|
const pk = model[this.pk];
|
|
389
390
|
if (!pk)
|
|
390
391
|
throw new db_decorators_1.InternalError(`No value for the Id is defined under the property ${this.pk}`);
|
|
391
392
|
const oldModel = await this.read(pk, ...contextArgs.args);
|
|
392
|
-
model =
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
Repository.setMetadata(model, Repository.getMetadata(oldModel));
|
|
393
|
+
model = decorator_validation_1.Model.merge(oldModel, model, this.class);
|
|
394
|
+
if (shouldRunHandlers)
|
|
395
|
+
await (0, db_decorators_1.enforceDBDecorators)(this, contextArgs.context, model, db_decorators_1.OperationKeys.UPDATE, db_decorators_1.OperationKeys.ON, oldModel);
|
|
396
|
+
if (shouldValidate) {
|
|
397
|
+
const errors = await Promise.resolve(model.hasErrors(oldModel, ...decorator_validation_1.Model.relations(this.class), ...(contextArgs.context.get("ignoredValidationProperties") || [])));
|
|
398
|
+
if (errors)
|
|
399
|
+
throw new db_decorators_1.ValidationError(errors.toString());
|
|
400
400
|
}
|
|
401
401
|
return [model, ...contextArgs.args];
|
|
402
402
|
}
|
|
@@ -408,9 +408,11 @@ class Repository extends db_decorators_1.Repository {
|
|
|
408
408
|
* @return {Promise<M[]>} The updated models with refreshed properties.
|
|
409
409
|
*/
|
|
410
410
|
async updateAll(models, ...args) {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.updateAll);
|
|
412
|
+
log.debug(`Updating ${models.length} new ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)}`);
|
|
413
|
+
const records = models.map((m) => this.adapter.prepare(m, ctx));
|
|
414
|
+
const updated = await this.adapter.updateAll(this.class, records.map((r) => r.id), records.map((r) => r.record), ...ctxArgs);
|
|
415
|
+
return updated.map((u, i) => this.adapter.revert(u, this.class, records[i].id, ctx.get("rebuildWithTransient") ? records[i].transient : undefined, ctx));
|
|
414
416
|
}
|
|
415
417
|
/**
|
|
416
418
|
* @description Prepares multiple models for update.
|
|
@@ -423,6 +425,8 @@ class Repository extends db_decorators_1.Repository {
|
|
|
423
425
|
*/
|
|
424
426
|
async updateAllPrefix(models, ...args) {
|
|
425
427
|
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.UPDATE, this.class, args, this.adapter, this._overrides || {});
|
|
428
|
+
const shouldRunHandlers = contextArgs.context.get("ignoreHandlers") !== false;
|
|
429
|
+
const shouldValidate = !contextArgs.context.get("ignoreValidation");
|
|
426
430
|
const ids = models.map((m) => {
|
|
427
431
|
const id = m[this.pk];
|
|
428
432
|
if (!id)
|
|
@@ -431,32 +435,18 @@ class Repository extends db_decorators_1.Repository {
|
|
|
431
435
|
});
|
|
432
436
|
const oldModels = await this.readAll(ids, ...contextArgs.args);
|
|
433
437
|
models = models.map((m, i) => {
|
|
434
|
-
m =
|
|
435
|
-
if (Repository.getMetadata(oldModels[i])) {
|
|
436
|
-
if (!Repository.getMetadata(m))
|
|
437
|
-
Repository.setMetadata(m, Repository.getMetadata(oldModels[i]));
|
|
438
|
-
}
|
|
438
|
+
m = decorator_validation_1.Model.merge(oldModels[i], m, this.class);
|
|
439
439
|
return m;
|
|
440
440
|
});
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return accum;
|
|
451
|
-
}, undefined);
|
|
452
|
-
if (errorMessages)
|
|
453
|
-
throw new db_decorators_1.ValidationError(errorMessages);
|
|
454
|
-
models.forEach((m, i) => {
|
|
455
|
-
if (Repository.getMetadata(oldModels[i])) {
|
|
456
|
-
if (!Repository.getMetadata(m))
|
|
457
|
-
Repository.setMetadata(m, Repository.getMetadata(oldModels[i]));
|
|
458
|
-
}
|
|
459
|
-
});
|
|
441
|
+
if (shouldRunHandlers)
|
|
442
|
+
await Promise.all(models.map((m, i) => (0, db_decorators_1.enforceDBDecorators)(this, contextArgs.context, m, db_decorators_1.OperationKeys.UPDATE, db_decorators_1.OperationKeys.ON, oldModels[i])));
|
|
443
|
+
if (shouldValidate) {
|
|
444
|
+
const ignoredProps = contextArgs.context.get("ignoredValidationProperties") || [];
|
|
445
|
+
const errors = await Promise.all(models.map((m, i) => Promise.resolve(m.hasErrors(oldModels[i], m, ...ignoredProps))));
|
|
446
|
+
const errorMessages = (0, db_decorators_1.reduceErrorsToPrint)(errors);
|
|
447
|
+
if (errorMessages)
|
|
448
|
+
throw new db_decorators_1.ValidationError(errorMessages);
|
|
449
|
+
}
|
|
460
450
|
return [models, ...contextArgs.args];
|
|
461
451
|
}
|
|
462
452
|
/**
|
|
@@ -480,8 +470,10 @@ class Repository extends db_decorators_1.Repository {
|
|
|
480
470
|
* @return {Promise<M>} The deleted model instance.
|
|
481
471
|
*/
|
|
482
472
|
async delete(id, ...args) {
|
|
483
|
-
const
|
|
484
|
-
|
|
473
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.delete);
|
|
474
|
+
log.debug(`deleting new ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)} with pk ${id}`);
|
|
475
|
+
const m = await this.adapter.delete(this.class, id, ...ctxArgs);
|
|
476
|
+
return this.adapter.revert(m, this.class, id, undefined, ctx);
|
|
485
477
|
}
|
|
486
478
|
/**
|
|
487
479
|
* @description Prepares for deleting multiple models by IDs.
|
|
@@ -506,8 +498,10 @@ class Repository extends db_decorators_1.Repository {
|
|
|
506
498
|
* @return {Promise<M[]>} The deleted model instances.
|
|
507
499
|
*/
|
|
508
500
|
async deleteAll(keys, ...args) {
|
|
509
|
-
const
|
|
510
|
-
|
|
501
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.create);
|
|
502
|
+
log.debug(`deleting ${keys.length} ${this.class.name} in table ${decorator_validation_1.Model.tableName(this.class)}`);
|
|
503
|
+
const results = await this.adapter.deleteAll(this.class, keys, ...ctxArgs);
|
|
504
|
+
return results.map((r, i) => this.adapter.revert(r, this.class, keys[i], undefined, ctx));
|
|
511
505
|
}
|
|
512
506
|
/**
|
|
513
507
|
* @description Implementation of the select method.
|
|
@@ -559,8 +553,18 @@ class Repository extends db_decorators_1.Repository {
|
|
|
559
553
|
writable: false,
|
|
560
554
|
});
|
|
561
555
|
const log = this.log.for(this.observe);
|
|
562
|
-
const tableName =
|
|
563
|
-
this.adapter.observe(this, (table
|
|
556
|
+
const tableName = decorator_validation_1.Model.tableName(this.class);
|
|
557
|
+
this.adapter.observe(this, (table,
|
|
558
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
559
|
+
event,
|
|
560
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
561
|
+
id,
|
|
562
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
563
|
+
...args) => {
|
|
564
|
+
if (typeof table === "string")
|
|
565
|
+
return table === tableName;
|
|
566
|
+
return decoration_1.Metadata.constr(table) === decoration_1.Metadata.constr(this.class);
|
|
567
|
+
});
|
|
564
568
|
log.verbose(`now observing ${this.adapter} filtering on table === ${tableName}`);
|
|
565
569
|
this.observerHandler.observe(observer, filter);
|
|
566
570
|
log.verbose(`Registered new observer ${observer.toString()}`);
|
|
@@ -599,12 +603,11 @@ class Repository extends db_decorators_1.Repository {
|
|
|
599
603
|
async updateObservers(table, event, id, ...args) {
|
|
600
604
|
if (!this.observerHandler)
|
|
601
605
|
throw new db_decorators_1.InternalError("ObserverHandler not initialized. Did you register any observables?");
|
|
602
|
-
this.
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
: Sequence_1.Sequence.parseValue(this.pkProps?.type, id), ...args);
|
|
606
|
+
const { log, ctxArgs } = this.logCtx(args, this.updateObservers);
|
|
607
|
+
log.verbose(`Updating ${this.observerHandler.count()} observers for ${this}`);
|
|
608
|
+
await this.observerHandler.updateObservers(table, event, Array.isArray(id)
|
|
609
|
+
? id.map((i) => Sequence_1.Sequence.parseValue(decorator_validation_1.Model.sequenceFor(this.class).type, i))
|
|
610
|
+
: Sequence_1.Sequence.parseValue(decorator_validation_1.Model.sequenceFor(this.class).type, id), ...ctxArgs);
|
|
608
611
|
}
|
|
609
612
|
/**
|
|
610
613
|
* @description Alias for updateObservers.
|
|
@@ -663,7 +666,7 @@ class Repository extends db_decorators_1.Repository {
|
|
|
663
666
|
* @throws {InternalError} If no repository is registered for the model.
|
|
664
667
|
*/
|
|
665
668
|
static get(model, alias) {
|
|
666
|
-
const name =
|
|
669
|
+
const name = decorator_validation_1.Model.tableName(model);
|
|
667
670
|
let registryName = name;
|
|
668
671
|
if (alias) {
|
|
669
672
|
registryName = [name, alias].join(db_decorators_1.DefaultSeparator);
|
|
@@ -684,7 +687,7 @@ class Repository extends db_decorators_1.Repository {
|
|
|
684
687
|
* @throws {InternalError} If a repository is already registered for the model.
|
|
685
688
|
*/
|
|
686
689
|
static register(model, repo, alias) {
|
|
687
|
-
let name =
|
|
690
|
+
let name = decorator_validation_1.Model.tableName(model);
|
|
688
691
|
if (alias) {
|
|
689
692
|
name = [name, alias].join(db_decorators_1.DefaultSeparator);
|
|
690
693
|
}
|
|
@@ -694,114 +697,16 @@ class Repository extends db_decorators_1.Repository {
|
|
|
694
697
|
}
|
|
695
698
|
this._cache[name] = repo;
|
|
696
699
|
}
|
|
697
|
-
/**
|
|
698
|
-
* @description Sets metadata on a model instance.
|
|
699
|
-
* @summary Attaches metadata to a model instance using a non-enumerable property.
|
|
700
|
-
* @template M - The model type that extends Model.
|
|
701
|
-
* @param {M} model - The model instance.
|
|
702
|
-
* @param {any} metadata - The metadata to attach to the model.
|
|
703
|
-
*/
|
|
704
|
-
static setMetadata(model, metadata) {
|
|
705
|
-
Object.defineProperty(model, constants_1.PersistenceKeys.METADATA, {
|
|
706
|
-
enumerable: false,
|
|
707
|
-
configurable: true,
|
|
708
|
-
writable: false,
|
|
709
|
-
value: metadata,
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* @description Gets metadata from a model instance.
|
|
714
|
-
* @summary Retrieves previously attached metadata from a model instance.
|
|
715
|
-
* @template M - The model type that extends Model.
|
|
716
|
-
* @param {M} model - The model instance.
|
|
717
|
-
* @return {any} The metadata or undefined if not found.
|
|
718
|
-
*/
|
|
719
|
-
static getMetadata(model) {
|
|
720
|
-
const descriptor = Object.getOwnPropertyDescriptor(model, constants_1.PersistenceKeys.METADATA);
|
|
721
|
-
return descriptor ? descriptor.value : undefined;
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* @description Removes metadata from a model instance.
|
|
725
|
-
* @summary Deletes the metadata property from a model instance.
|
|
726
|
-
* @template M - The model type that extends Model.
|
|
727
|
-
* @param {M} model - The model instance.
|
|
728
|
-
*/
|
|
729
|
-
static removeMetadata(model) {
|
|
730
|
-
const descriptor = Object.getOwnPropertyDescriptor(model, constants_1.PersistenceKeys.METADATA);
|
|
731
|
-
if (descriptor)
|
|
732
|
-
delete model[constants_1.PersistenceKeys.METADATA];
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* @description Gets sequence options for a model's primary key.
|
|
736
|
-
* @summary Retrieves the sequence configuration for a model's primary key from metadata.
|
|
737
|
-
* @template M - The model type that extends Model.
|
|
738
|
-
* @param {M} model - The model instance.
|
|
739
|
-
* @return {SequenceOptions} The sequence options for the model's primary key.
|
|
740
|
-
* @throws {InternalError} If no sequence options are defined for the model.
|
|
741
|
-
*/
|
|
742
|
-
static getSequenceOptions(model) {
|
|
743
|
-
const pkName = decorator_validation_1.Model.pk(model.constructor);
|
|
744
|
-
const key = decoration_1.Metadata.key(db_decorators_1.DBKeys.ID, pkName);
|
|
745
|
-
const metadata = decoration_1.Metadata.get(model.constructor, key);
|
|
746
|
-
if (!metadata)
|
|
747
|
-
throw new db_decorators_1.InternalError("No sequence options defined for model. did you use the @pk decorator?");
|
|
748
|
-
return metadata;
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* @description Gets all indexes defined on a model.
|
|
752
|
-
* @summary Retrieves all index metadata from a model's property decorators.
|
|
753
|
-
* @template M - The model type that extends Model.
|
|
754
|
-
* @param {M | Constructor<M>} model - The model instance or constructor.
|
|
755
|
-
* @return {Record<string, Record<string, IndexMetadata>>} A nested record of property names to index metadata.
|
|
756
|
-
*/
|
|
757
|
-
static indexes(model) {
|
|
758
|
-
const indexDecorators = decoration_1.Metadata.get(model instanceof decorator_validation_1.Model ? model.constructor : model, constants_1.PersistenceKeys.INDEX);
|
|
759
|
-
return Object.keys(indexDecorators || {}).reduce((acum, t) => {
|
|
760
|
-
acum[t] = { [constants_1.PersistenceKeys.INDEX]: indexDecorators[t] };
|
|
761
|
-
return acum;
|
|
762
|
-
}, {});
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* @description Gets all relation properties defined on a model.
|
|
766
|
-
* @summary Retrieves the names of all properties marked as relations in the model hierarchy.
|
|
767
|
-
* @template M - The model type that extends Model.
|
|
768
|
-
* @param {M | Constructor<M>} model - The model instance or constructor.
|
|
769
|
-
* @return {string[]} An array of property names that are relations.
|
|
770
|
-
*/
|
|
771
|
-
static relations(model) {
|
|
772
|
-
return (decoration_1.Metadata.relations(model instanceof decorator_validation_1.Model ? model.constructor : model) || []);
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* @description Gets the table name for a model.
|
|
776
|
-
* @summary Retrieves the database table name associated with a model.
|
|
777
|
-
* @template M - The model type that extends Model.
|
|
778
|
-
* @param {M | Constructor<M>} model - The model instance or constructor.
|
|
779
|
-
* @return {string} The table name for the model.
|
|
780
|
-
*/
|
|
781
|
-
static table(model) {
|
|
782
|
-
return (0, utils_1.getTableName)(model);
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* @description Gets the column name for a model attribute.
|
|
786
|
-
* @summary Retrieves the database column name for a model property.
|
|
787
|
-
* @template M - The model type that extends Model.
|
|
788
|
-
* @param {M} model - The model instance.
|
|
789
|
-
* @param {string} attribute - The attribute/property name.
|
|
790
|
-
* @return {string} The column name for the attribute.
|
|
791
|
-
*/
|
|
792
|
-
static column(model, attribute) {
|
|
793
|
-
return (0, utils_1.getColumnName)(model, attribute);
|
|
794
|
-
}
|
|
795
700
|
}
|
|
796
701
|
exports.Repository = Repository;
|
|
797
702
|
__decorate([
|
|
798
|
-
(0,
|
|
703
|
+
(0, logging_1.final)(),
|
|
799
704
|
__metadata("design:type", Function),
|
|
800
705
|
__metadata("design:paramtypes", [Object, Function]),
|
|
801
706
|
__metadata("design:returntype", void 0)
|
|
802
707
|
], Repository.prototype, "observe", null);
|
|
803
708
|
__decorate([
|
|
804
|
-
(0,
|
|
709
|
+
(0, logging_1.final)(),
|
|
805
710
|
__metadata("design:type", Function),
|
|
806
711
|
__metadata("design:paramtypes", [Object]),
|
|
807
712
|
__metadata("design:returntype", void 0)
|