@spinajs/orm 2.0.180 → 2.0.182
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/lib/cjs/builders.d.ts +643 -643
- package/lib/cjs/builders.js +1602 -1602
- package/lib/cjs/builders.js.map +1 -1
- package/lib/cjs/converters.d.ts +34 -34
- package/lib/cjs/converters.js +104 -104
- package/lib/cjs/decorators.d.ts +152 -152
- package/lib/cjs/decorators.js +449 -449
- package/lib/cjs/dehydrators.d.ts +10 -10
- package/lib/cjs/dehydrators.js +47 -47
- package/lib/cjs/driver.d.ts +82 -82
- package/lib/cjs/driver.js +102 -102
- package/lib/cjs/driver.js.map +1 -1
- package/lib/cjs/enums.d.ts +116 -116
- package/lib/cjs/enums.js +126 -126
- package/lib/cjs/enums.js.map +1 -1
- package/lib/cjs/exceptions.d.ts +6 -6
- package/lib/cjs/exceptions.js +10 -10
- package/lib/cjs/hydrators.d.ts +19 -19
- package/lib/cjs/hydrators.js +132 -132
- package/lib/cjs/hydrators.js.map +1 -1
- package/lib/cjs/index.d.ts +17 -17
- package/lib/cjs/index.js +33 -33
- package/lib/cjs/interfaces.d.ts +921 -919
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +279 -279
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/middlewares.d.ts +62 -62
- package/lib/cjs/middlewares.js +258 -258
- package/lib/cjs/model.d.ts +288 -284
- package/lib/cjs/model.d.ts.map +1 -1
- package/lib/cjs/model.js +826 -810
- package/lib/cjs/model.js.map +1 -1
- package/lib/cjs/orm.d.ts +61 -61
- package/lib/cjs/orm.js +333 -333
- package/lib/cjs/orm.js.map +1 -1
- package/lib/cjs/relation-objects.d.ts +108 -108
- package/lib/cjs/relation-objects.js +221 -221
- package/lib/cjs/relations.d.ts +61 -61
- package/lib/cjs/relations.js +194 -194
- package/lib/cjs/relations.js.map +1 -1
- package/lib/cjs/statements.d.ts +143 -143
- package/lib/cjs/statements.js +309 -309
- package/lib/cjs/statements.js.map +1 -1
- package/lib/cjs/types.d.ts +32 -32
- package/lib/cjs/types.js +2 -2
- package/lib/cjs/wrappers.d.ts +5 -5
- package/lib/cjs/wrappers.js +12 -12
- package/lib/mjs/builders.d.ts +643 -643
- package/lib/mjs/builders.js +1594 -1594
- package/lib/mjs/builders.js.map +1 -1
- package/lib/mjs/converters.d.ts +34 -34
- package/lib/mjs/converters.js +96 -96
- package/lib/mjs/decorators.d.ts +152 -152
- package/lib/mjs/decorators.js +422 -422
- package/lib/mjs/dehydrators.d.ts +10 -10
- package/lib/mjs/dehydrators.js +41 -41
- package/lib/mjs/driver.d.ts +82 -82
- package/lib/mjs/driver.js +98 -98
- package/lib/mjs/driver.js.map +1 -1
- package/lib/mjs/enums.d.ts +116 -116
- package/lib/mjs/enums.js +123 -123
- package/lib/mjs/enums.js.map +1 -1
- package/lib/mjs/exceptions.d.ts +6 -6
- package/lib/mjs/exceptions.js +6 -6
- package/lib/mjs/hydrators.d.ts +19 -19
- package/lib/mjs/hydrators.js +128 -128
- package/lib/mjs/hydrators.js.map +1 -1
- package/lib/mjs/index.d.ts +17 -17
- package/lib/mjs/index.js +17 -17
- package/lib/mjs/interfaces.d.ts +921 -919
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +267 -267
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/middlewares.d.ts +62 -62
- package/lib/mjs/middlewares.js +249 -249
- package/lib/mjs/model.d.ts +288 -284
- package/lib/mjs/model.d.ts.map +1 -1
- package/lib/mjs/model.js +816 -800
- package/lib/mjs/model.js.map +1 -1
- package/lib/mjs/orm.d.ts +61 -61
- package/lib/mjs/orm.js +326 -326
- package/lib/mjs/orm.js.map +1 -1
- package/lib/mjs/relation-objects.d.ts +108 -108
- package/lib/mjs/relation-objects.js +211 -211
- package/lib/mjs/relations.d.ts +61 -61
- package/lib/mjs/relations.js +191 -191
- package/lib/mjs/relations.js.map +1 -1
- package/lib/mjs/statements.d.ts +143 -143
- package/lib/mjs/statements.js +301 -301
- package/lib/mjs/statements.js.map +1 -1
- package/lib/mjs/types.d.ts +32 -32
- package/lib/mjs/types.js +1 -1
- package/lib/mjs/wrappers.d.ts +5 -5
- package/lib/mjs/wrappers.js +9 -9
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;AAQA,OAAO,EAAE,WAAW,EAAe,SAAS,EAAc,MAAM,aAAa,CAAC;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI3D,MAAM,CAAN,IAAY,YAOX;AAPD,WAAY,YAAY;IACtB,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,6DAAW,CAAA;AACb,CAAC,EAPW,YAAY,
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;AAQA,OAAO,EAAE,WAAW,EAAe,SAAS,EAAc,MAAM,aAAa,CAAC;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI3D,MAAM,CAAN,IAAY,YAOX;AAPD,WAAY,YAAY;IACtB,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,6DAAW,CAAA;AACb,CAAC,EAPW,YAAY,KAAZ,YAAY,QAOvB;AAED,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,6DAAG,CAAA;IACH,mEAAM,CAAA;IACN,mEAAM,CAAA;AACR,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B;AAaD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AAW,EAAE,QAAa,EAAE,QAAa;QACrD,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAAc;CAAI;AAE9D;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;CAAI;AAGlD,IAAe,kBAAkB,GAAjC,MAAe,kBAAkB;CAEvC,CAAA;AAFqB,kBAAkB;IADvC,SAAS,EAAE;GACU,kBAAkB,CAEvC;;AAMD;;GAEG;AACH,MAAM,OAAgB,UAAU;CAAI;AASpC,MAAM,OAAgB,mBAAmB;CAExC;AAED,MAAM,OAAgB,oBAAoB;CAEzC"}
|
package/lib/mjs/middlewares.d.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { IRelationDescriptor, IModelDescriptor, IBuilderMiddleware, ISelectQueryBuilder } from './interfaces.js';
|
|
2
|
-
import { ModelBase } from './model.js';
|
|
3
|
-
import { BelongsToRelation } from './relations.js';
|
|
4
|
-
export declare class HasManyRelationMiddleware implements IBuilderMiddleware {
|
|
5
|
-
protected _relationQuery: ISelectQueryBuilder;
|
|
6
|
-
protected _description: IRelationDescriptor;
|
|
7
|
-
protected _path: string;
|
|
8
|
-
constructor(_relationQuery: ISelectQueryBuilder, _description: IRelationDescriptor, _path: string);
|
|
9
|
-
afterQuery(data: any[]): any[];
|
|
10
|
-
modelCreation(_: any): ModelBase;
|
|
11
|
-
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
12
|
-
}
|
|
13
|
-
export declare class BelongsToRelationRecursiveMiddleware implements IBuilderMiddleware {
|
|
14
|
-
protected _relationQuery: ISelectQueryBuilder;
|
|
15
|
-
protected _description: IRelationDescriptor;
|
|
16
|
-
protected _targetModelDescriptor: IModelDescriptor;
|
|
17
|
-
constructor(_relationQuery: ISelectQueryBuilder, _description: IRelationDescriptor, _targetModelDescriptor: IModelDescriptor);
|
|
18
|
-
afterQuery(data: any[]): any[];
|
|
19
|
-
modelCreation(_: any): ModelBase;
|
|
20
|
-
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
21
|
-
}
|
|
22
|
-
export declare class HasManyToManyRelationMiddleware implements IBuilderMiddleware {
|
|
23
|
-
protected _relationQuery: ISelectQueryBuilder;
|
|
24
|
-
protected _description: IRelationDescriptor;
|
|
25
|
-
protected _targetModelDescriptor: IModelDescriptor;
|
|
26
|
-
constructor(_relationQuery: ISelectQueryBuilder, _description: IRelationDescriptor, _targetModelDescriptor: IModelDescriptor);
|
|
27
|
-
afterQuery(data: any[]): any[];
|
|
28
|
-
modelCreation(_: any): ModelBase;
|
|
29
|
-
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
30
|
-
private pickProps;
|
|
31
|
-
}
|
|
32
|
-
export declare class BelongsToPopulateDataMiddleware implements IBuilderMiddleware {
|
|
33
|
-
protected _description: IRelationDescriptor;
|
|
34
|
-
protected relation: BelongsToRelation;
|
|
35
|
-
constructor(_description: IRelationDescriptor, relation: BelongsToRelation);
|
|
36
|
-
afterQuery(data: any[]): any[];
|
|
37
|
-
modelCreation(_: any): ModelBase<unknown>;
|
|
38
|
-
afterHydration(data: ModelBase<unknown>[]): Promise<void | any[]>;
|
|
39
|
-
}
|
|
40
|
-
export declare class BelongsToRelationResultTransformMiddleware implements IBuilderMiddleware {
|
|
41
|
-
afterQuery(data: any[]): any[];
|
|
42
|
-
modelCreation(_: any): ModelBase;
|
|
43
|
-
afterHydration(_data: Array<ModelBase>): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Dynamically sets a deeply nested value in an object.
|
|
46
|
-
* Optionally "bores" a path to it if its undefined.
|
|
47
|
-
*
|
|
48
|
-
* @param obj - The object which contains the value you want to change/set.
|
|
49
|
-
* @param path - The array representation of path to the value you want to change/set.
|
|
50
|
-
* @param value - The value you want to set it to.
|
|
51
|
-
* @param setrecursively - If true, will set value of non-existing path as well.
|
|
52
|
-
*/
|
|
53
|
-
protected setDeep(obj: any, path: any[], value: any, setrecursively?: boolean): void;
|
|
54
|
-
protected keyTransform(key: string): string[];
|
|
55
|
-
}
|
|
56
|
-
export declare class DiscriminationMapMiddleware implements IBuilderMiddleware {
|
|
57
|
-
protected _description: IModelDescriptor;
|
|
58
|
-
constructor(_description: IModelDescriptor);
|
|
59
|
-
afterQuery(data: any[]): any[];
|
|
60
|
-
modelCreation(data: any): ModelBase;
|
|
61
|
-
afterHydration(_data: ModelBase[]): Promise<void>;
|
|
62
|
-
}
|
|
1
|
+
import { IRelationDescriptor, IModelDescriptor, IBuilderMiddleware, ISelectQueryBuilder } from './interfaces.js';
|
|
2
|
+
import { ModelBase } from './model.js';
|
|
3
|
+
import { BelongsToRelation } from './relations.js';
|
|
4
|
+
export declare class HasManyRelationMiddleware implements IBuilderMiddleware {
|
|
5
|
+
protected _relationQuery: ISelectQueryBuilder;
|
|
6
|
+
protected _description: IRelationDescriptor;
|
|
7
|
+
protected _path: string;
|
|
8
|
+
constructor(_relationQuery: ISelectQueryBuilder, _description: IRelationDescriptor, _path: string);
|
|
9
|
+
afterQuery(data: any[]): any[];
|
|
10
|
+
modelCreation(_: any): ModelBase;
|
|
11
|
+
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
12
|
+
}
|
|
13
|
+
export declare class BelongsToRelationRecursiveMiddleware implements IBuilderMiddleware {
|
|
14
|
+
protected _relationQuery: ISelectQueryBuilder;
|
|
15
|
+
protected _description: IRelationDescriptor;
|
|
16
|
+
protected _targetModelDescriptor: IModelDescriptor;
|
|
17
|
+
constructor(_relationQuery: ISelectQueryBuilder, _description: IRelationDescriptor, _targetModelDescriptor: IModelDescriptor);
|
|
18
|
+
afterQuery(data: any[]): any[];
|
|
19
|
+
modelCreation(_: any): ModelBase;
|
|
20
|
+
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
21
|
+
}
|
|
22
|
+
export declare class HasManyToManyRelationMiddleware implements IBuilderMiddleware {
|
|
23
|
+
protected _relationQuery: ISelectQueryBuilder;
|
|
24
|
+
protected _description: IRelationDescriptor;
|
|
25
|
+
protected _targetModelDescriptor: IModelDescriptor;
|
|
26
|
+
constructor(_relationQuery: ISelectQueryBuilder, _description: IRelationDescriptor, _targetModelDescriptor: IModelDescriptor);
|
|
27
|
+
afterQuery(data: any[]): any[];
|
|
28
|
+
modelCreation(_: any): ModelBase;
|
|
29
|
+
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
30
|
+
private pickProps;
|
|
31
|
+
}
|
|
32
|
+
export declare class BelongsToPopulateDataMiddleware implements IBuilderMiddleware {
|
|
33
|
+
protected _description: IRelationDescriptor;
|
|
34
|
+
protected relation: BelongsToRelation;
|
|
35
|
+
constructor(_description: IRelationDescriptor, relation: BelongsToRelation);
|
|
36
|
+
afterQuery(data: any[]): any[];
|
|
37
|
+
modelCreation(_: any): ModelBase<unknown>;
|
|
38
|
+
afterHydration(data: ModelBase<unknown>[]): Promise<void | any[]>;
|
|
39
|
+
}
|
|
40
|
+
export declare class BelongsToRelationResultTransformMiddleware implements IBuilderMiddleware {
|
|
41
|
+
afterQuery(data: any[]): any[];
|
|
42
|
+
modelCreation(_: any): ModelBase;
|
|
43
|
+
afterHydration(_data: Array<ModelBase>): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Dynamically sets a deeply nested value in an object.
|
|
46
|
+
* Optionally "bores" a path to it if its undefined.
|
|
47
|
+
*
|
|
48
|
+
* @param obj - The object which contains the value you want to change/set.
|
|
49
|
+
* @param path - The array representation of path to the value you want to change/set.
|
|
50
|
+
* @param value - The value you want to set it to.
|
|
51
|
+
* @param setrecursively - If true, will set value of non-existing path as well.
|
|
52
|
+
*/
|
|
53
|
+
protected setDeep(obj: any, path: any[], value: any, setrecursively?: boolean): void;
|
|
54
|
+
protected keyTransform(key: string): string[];
|
|
55
|
+
}
|
|
56
|
+
export declare class DiscriminationMapMiddleware implements IBuilderMiddleware {
|
|
57
|
+
protected _description: IModelDescriptor;
|
|
58
|
+
constructor(_description: IModelDescriptor);
|
|
59
|
+
afterQuery(data: any[]): any[];
|
|
60
|
+
modelCreation(data: any): ModelBase;
|
|
61
|
+
afterHydration(_data: ModelBase[]): Promise<void>;
|
|
62
|
+
}
|
|
63
63
|
//# sourceMappingURL=middlewares.d.ts.map
|
package/lib/mjs/middlewares.js
CHANGED
|
@@ -1,250 +1,250 @@
|
|
|
1
|
-
/* eslint-disable prettier/prettier */
|
|
2
|
-
import { RelationType } from './interfaces.js';
|
|
3
|
-
import { ManyToManyRelationList, OneToManyRelationList } from './relation-objects.js';
|
|
4
|
-
export class HasManyRelationMiddleware {
|
|
5
|
-
constructor(_relationQuery, _description, _path) {
|
|
6
|
-
this._relationQuery = _relationQuery;
|
|
7
|
-
this._description = _description;
|
|
8
|
-
this._path = _path;
|
|
9
|
-
}
|
|
10
|
-
afterQuery(data) {
|
|
11
|
-
return data;
|
|
12
|
-
}
|
|
13
|
-
modelCreation(_) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
async afterHydration(data) {
|
|
17
|
-
const self = this;
|
|
18
|
-
const pks = data.map((d) => {
|
|
19
|
-
return d[this._description.PrimaryKey];
|
|
20
|
-
});
|
|
21
|
-
const hydrateMiddleware = {
|
|
22
|
-
afterQuery(data) {
|
|
23
|
-
return data;
|
|
24
|
-
},
|
|
25
|
-
modelCreation() {
|
|
26
|
-
return null;
|
|
27
|
-
},
|
|
28
|
-
async afterHydration(relationData) {
|
|
29
|
-
relationData.forEach((d) => (d.__relationKey__ = self._description.Name));
|
|
30
|
-
data.forEach((d) => {
|
|
31
|
-
const relData = relationData.filter((rd) => {
|
|
32
|
-
return d[self._description.PrimaryKey] === rd[self._description.ForeignKey];
|
|
33
|
-
});
|
|
34
|
-
d[self._description.Name] = new OneToManyRelationList(d, self._description.TargetModel, self._description, relData);
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
if (pks.length !== 0) {
|
|
39
|
-
this._relationQuery.whereIn(this._description.ForeignKey, pks);
|
|
40
|
-
this._relationQuery.middleware(hydrateMiddleware);
|
|
41
|
-
return await this._relationQuery;
|
|
42
|
-
}
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export class BelongsToRelationRecursiveMiddleware {
|
|
47
|
-
constructor(_relationQuery, _description, _targetModelDescriptor) {
|
|
48
|
-
this._relationQuery = _relationQuery;
|
|
49
|
-
this._description = _description;
|
|
50
|
-
this._targetModelDescriptor = _targetModelDescriptor;
|
|
51
|
-
}
|
|
52
|
-
afterQuery(data) {
|
|
53
|
-
return data;
|
|
54
|
-
}
|
|
55
|
-
modelCreation(_) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
async afterHydration(data) {
|
|
59
|
-
const self = this;
|
|
60
|
-
const pks = data.map((d) => d[this._description.PrimaryKey]);
|
|
61
|
-
const fKey = this._description.ForeignKey;
|
|
62
|
-
const key = this._description.PrimaryKey;
|
|
63
|
-
const name = this._description.Name;
|
|
64
|
-
const hydrateMiddleware = {
|
|
65
|
-
afterQuery(data) {
|
|
66
|
-
return data;
|
|
67
|
-
},
|
|
68
|
-
modelCreation(_) {
|
|
69
|
-
return null;
|
|
70
|
-
},
|
|
71
|
-
async afterHydration(relationData) {
|
|
72
|
-
relationData.forEach((d) => (d.__relationKey__ = self._description.Name));
|
|
73
|
-
function buildRelationTree(_d, parent) {
|
|
74
|
-
const branch = [];
|
|
75
|
-
_d.forEach((d) => {
|
|
76
|
-
if (d[fKey] === parent) {
|
|
77
|
-
const children = buildRelationTree(_d, d[key]);
|
|
78
|
-
if (children) {
|
|
79
|
-
// TODO:
|
|
80
|
-
// implement RecursiveRelation list to allow for
|
|
81
|
-
// manipulation of the recursive data
|
|
82
|
-
d[name] = new OneToManyRelationList(d, d.Model, {
|
|
83
|
-
Name: name,
|
|
84
|
-
Type: RelationType.Many,
|
|
85
|
-
TargetModelType: d.Model,
|
|
86
|
-
TargetModel: d.Model,
|
|
87
|
-
SourceModel: d.Model,
|
|
88
|
-
ForeignKey: fKey,
|
|
89
|
-
PrimaryKey: key,
|
|
90
|
-
Recursive: false,
|
|
91
|
-
}, children);
|
|
92
|
-
}
|
|
93
|
-
branch.push(d);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return branch;
|
|
97
|
-
}
|
|
98
|
-
const result = buildRelationTree(relationData, null);
|
|
99
|
-
data.forEach((d) => {
|
|
100
|
-
d[name] = result.find((r) => r[key] === d[key])[name];
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
this._relationQuery.whereIn(this._description.PrimaryKey, pks);
|
|
105
|
-
this._relationQuery.middleware(new DiscriminationMapMiddleware(this._targetModelDescriptor));
|
|
106
|
-
this._relationQuery.middleware(hydrateMiddleware);
|
|
107
|
-
return await this._relationQuery;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export class HasManyToManyRelationMiddleware {
|
|
111
|
-
constructor(_relationQuery, _description, _targetModelDescriptor) {
|
|
112
|
-
this._relationQuery = _relationQuery;
|
|
113
|
-
this._description = _description;
|
|
114
|
-
this._targetModelDescriptor = _targetModelDescriptor;
|
|
115
|
-
}
|
|
116
|
-
afterQuery(data) {
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
modelCreation(_) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
async afterHydration(data) {
|
|
123
|
-
const self = this;
|
|
124
|
-
const pks = data.map((d) => d[this._description.PrimaryKey]);
|
|
125
|
-
const hydrateMiddleware = {
|
|
126
|
-
afterQuery(data) {
|
|
127
|
-
return data.map((d) => Object.assign({}, d[self._description.Name], { JunctionModel: self.pickProps(d, [self._description.Name]) }));
|
|
128
|
-
},
|
|
129
|
-
modelCreation(_) {
|
|
130
|
-
return null;
|
|
131
|
-
},
|
|
132
|
-
async afterHydration(relationData) {
|
|
133
|
-
relationData.forEach((d) => (d.__relationKey__ = self._description.Name));
|
|
134
|
-
data.forEach((d) => {
|
|
135
|
-
const relData = relationData.filter((rd) => rd.JunctionModel[self._description.ForeignKey] === d[self._description.PrimaryKey]);
|
|
136
|
-
d[self._description.Name] = new ManyToManyRelationList(d, self._description.TargetModel, self._description, relData);
|
|
137
|
-
});
|
|
138
|
-
relationData.forEach((d) => delete d.JunctionModel);
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
if (pks.length !== 0) {
|
|
142
|
-
this._relationQuery.whereIn(this._description.ForeignKey, pks);
|
|
143
|
-
this._relationQuery.middleware(new BelongsToRelationResultTransformMiddleware());
|
|
144
|
-
this._relationQuery.middleware(new DiscriminationMapMiddleware(this._targetModelDescriptor));
|
|
145
|
-
this._relationQuery.middleware(hydrateMiddleware);
|
|
146
|
-
return await this._relationQuery;
|
|
147
|
-
}
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
pickProps(source, except) {
|
|
151
|
-
const obj = {};
|
|
152
|
-
for (const p in source) {
|
|
153
|
-
if (except.indexOf(p) === -1) {
|
|
154
|
-
obj[p] = source[p];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return obj;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
export class BelongsToPopulateDataMiddleware {
|
|
161
|
-
constructor(_description, relation) {
|
|
162
|
-
this._description = _description;
|
|
163
|
-
this.relation = relation;
|
|
164
|
-
}
|
|
165
|
-
afterQuery(data) {
|
|
166
|
-
return data;
|
|
167
|
-
}
|
|
168
|
-
modelCreation(_) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
afterHydration(data) {
|
|
172
|
-
const relData = data.map((d) => d[this._description.Name].Value).filter((x) => x !== null && x !== undefined);
|
|
173
|
-
const middlewares = this.relation._relationQuery.Relations
|
|
174
|
-
.map((x) => {
|
|
175
|
-
return x._query._middlewares;
|
|
176
|
-
})
|
|
177
|
-
.reduce((prev, current) => {
|
|
178
|
-
return prev.concat(current);
|
|
179
|
-
}, []);
|
|
180
|
-
return Promise.all(middlewares.map((x) => {
|
|
181
|
-
return x.afterHydration(relData);
|
|
182
|
-
}));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
export class BelongsToRelationResultTransformMiddleware {
|
|
186
|
-
afterQuery(data) {
|
|
187
|
-
return data.map((d) => {
|
|
188
|
-
const transformedData = Object.assign(d);
|
|
189
|
-
for (const key in transformedData) {
|
|
190
|
-
if (key.startsWith('$')) {
|
|
191
|
-
this.setDeep(transformedData, this.keyTransform(key), d[key]);
|
|
192
|
-
delete transformedData[key];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return transformedData;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
modelCreation(_) {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
// tslint:disable-next-line: no-empty
|
|
202
|
-
async afterHydration(_data) { }
|
|
203
|
-
/**
|
|
204
|
-
* Dynamically sets a deeply nested value in an object.
|
|
205
|
-
* Optionally "bores" a path to it if its undefined.
|
|
206
|
-
*
|
|
207
|
-
* @param obj - The object which contains the value you want to change/set.
|
|
208
|
-
* @param path - The array representation of path to the value you want to change/set.
|
|
209
|
-
* @param value - The value you want to set it to.
|
|
210
|
-
* @param setrecursively - If true, will set value of non-existing path as well.
|
|
211
|
-
*/
|
|
212
|
-
setDeep(obj, path, value, setrecursively = true) {
|
|
213
|
-
path.reduce((a, b, level) => {
|
|
214
|
-
if (setrecursively && typeof a[b] === 'undefined' && level !== path.length - 1) {
|
|
215
|
-
a[b] = {};
|
|
216
|
-
return a[b];
|
|
217
|
-
}
|
|
218
|
-
if (level === path.length - 1) {
|
|
219
|
-
a[b] = value;
|
|
220
|
-
return value;
|
|
221
|
-
}
|
|
222
|
-
return a[b];
|
|
223
|
-
}, obj);
|
|
224
|
-
}
|
|
225
|
-
keyTransform(key) {
|
|
226
|
-
return key.replace(/\$+/g, '').split('.');
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
export class DiscriminationMapMiddleware {
|
|
230
|
-
constructor(_description) {
|
|
231
|
-
this._description = _description;
|
|
232
|
-
}
|
|
233
|
-
afterQuery(data) {
|
|
234
|
-
return data;
|
|
235
|
-
}
|
|
236
|
-
modelCreation(data) {
|
|
237
|
-
if (this._description.DiscriminationMap && this._description.DiscriminationMap.Field) {
|
|
238
|
-
const distValue = data[this._description.DiscriminationMap.Field];
|
|
239
|
-
if (distValue && this._description.DiscriminationMap.Models.has(distValue)) {
|
|
240
|
-
const result = new (this._description.DiscriminationMap.Models.get(distValue))();
|
|
241
|
-
result.hydrate(data);
|
|
242
|
-
return result;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
// tslint:disable-next-line: no-empty
|
|
248
|
-
async afterHydration(_data) { }
|
|
249
|
-
}
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
import { RelationType } from './interfaces.js';
|
|
3
|
+
import { ManyToManyRelationList, OneToManyRelationList } from './relation-objects.js';
|
|
4
|
+
export class HasManyRelationMiddleware {
|
|
5
|
+
constructor(_relationQuery, _description, _path) {
|
|
6
|
+
this._relationQuery = _relationQuery;
|
|
7
|
+
this._description = _description;
|
|
8
|
+
this._path = _path;
|
|
9
|
+
}
|
|
10
|
+
afterQuery(data) {
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
modelCreation(_) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
async afterHydration(data) {
|
|
17
|
+
const self = this;
|
|
18
|
+
const pks = data.map((d) => {
|
|
19
|
+
return d[this._description.PrimaryKey];
|
|
20
|
+
});
|
|
21
|
+
const hydrateMiddleware = {
|
|
22
|
+
afterQuery(data) {
|
|
23
|
+
return data;
|
|
24
|
+
},
|
|
25
|
+
modelCreation() {
|
|
26
|
+
return null;
|
|
27
|
+
},
|
|
28
|
+
async afterHydration(relationData) {
|
|
29
|
+
relationData.forEach((d) => (d.__relationKey__ = self._description.Name));
|
|
30
|
+
data.forEach((d) => {
|
|
31
|
+
const relData = relationData.filter((rd) => {
|
|
32
|
+
return d[self._description.PrimaryKey] === rd[self._description.ForeignKey];
|
|
33
|
+
});
|
|
34
|
+
d[self._description.Name] = new OneToManyRelationList(d, self._description.TargetModel, self._description, relData);
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
if (pks.length !== 0) {
|
|
39
|
+
this._relationQuery.whereIn(this._description.ForeignKey, pks);
|
|
40
|
+
this._relationQuery.middleware(hydrateMiddleware);
|
|
41
|
+
return await this._relationQuery;
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class BelongsToRelationRecursiveMiddleware {
|
|
47
|
+
constructor(_relationQuery, _description, _targetModelDescriptor) {
|
|
48
|
+
this._relationQuery = _relationQuery;
|
|
49
|
+
this._description = _description;
|
|
50
|
+
this._targetModelDescriptor = _targetModelDescriptor;
|
|
51
|
+
}
|
|
52
|
+
afterQuery(data) {
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
modelCreation(_) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
async afterHydration(data) {
|
|
59
|
+
const self = this;
|
|
60
|
+
const pks = data.map((d) => d[this._description.PrimaryKey]);
|
|
61
|
+
const fKey = this._description.ForeignKey;
|
|
62
|
+
const key = this._description.PrimaryKey;
|
|
63
|
+
const name = this._description.Name;
|
|
64
|
+
const hydrateMiddleware = {
|
|
65
|
+
afterQuery(data) {
|
|
66
|
+
return data;
|
|
67
|
+
},
|
|
68
|
+
modelCreation(_) {
|
|
69
|
+
return null;
|
|
70
|
+
},
|
|
71
|
+
async afterHydration(relationData) {
|
|
72
|
+
relationData.forEach((d) => (d.__relationKey__ = self._description.Name));
|
|
73
|
+
function buildRelationTree(_d, parent) {
|
|
74
|
+
const branch = [];
|
|
75
|
+
_d.forEach((d) => {
|
|
76
|
+
if (d[fKey] === parent) {
|
|
77
|
+
const children = buildRelationTree(_d, d[key]);
|
|
78
|
+
if (children) {
|
|
79
|
+
// TODO:
|
|
80
|
+
// implement RecursiveRelation list to allow for
|
|
81
|
+
// manipulation of the recursive data
|
|
82
|
+
d[name] = new OneToManyRelationList(d, d.Model, {
|
|
83
|
+
Name: name,
|
|
84
|
+
Type: RelationType.Many,
|
|
85
|
+
TargetModelType: d.Model,
|
|
86
|
+
TargetModel: d.Model,
|
|
87
|
+
SourceModel: d.Model,
|
|
88
|
+
ForeignKey: fKey,
|
|
89
|
+
PrimaryKey: key,
|
|
90
|
+
Recursive: false,
|
|
91
|
+
}, children);
|
|
92
|
+
}
|
|
93
|
+
branch.push(d);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return branch;
|
|
97
|
+
}
|
|
98
|
+
const result = buildRelationTree(relationData, null);
|
|
99
|
+
data.forEach((d) => {
|
|
100
|
+
d[name] = result.find((r) => r[key] === d[key])[name];
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
this._relationQuery.whereIn(this._description.PrimaryKey, pks);
|
|
105
|
+
this._relationQuery.middleware(new DiscriminationMapMiddleware(this._targetModelDescriptor));
|
|
106
|
+
this._relationQuery.middleware(hydrateMiddleware);
|
|
107
|
+
return await this._relationQuery;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class HasManyToManyRelationMiddleware {
|
|
111
|
+
constructor(_relationQuery, _description, _targetModelDescriptor) {
|
|
112
|
+
this._relationQuery = _relationQuery;
|
|
113
|
+
this._description = _description;
|
|
114
|
+
this._targetModelDescriptor = _targetModelDescriptor;
|
|
115
|
+
}
|
|
116
|
+
afterQuery(data) {
|
|
117
|
+
return data;
|
|
118
|
+
}
|
|
119
|
+
modelCreation(_) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
async afterHydration(data) {
|
|
123
|
+
const self = this;
|
|
124
|
+
const pks = data.map((d) => d[this._description.PrimaryKey]);
|
|
125
|
+
const hydrateMiddleware = {
|
|
126
|
+
afterQuery(data) {
|
|
127
|
+
return data.map((d) => Object.assign({}, d[self._description.Name], { JunctionModel: self.pickProps(d, [self._description.Name]) }));
|
|
128
|
+
},
|
|
129
|
+
modelCreation(_) {
|
|
130
|
+
return null;
|
|
131
|
+
},
|
|
132
|
+
async afterHydration(relationData) {
|
|
133
|
+
relationData.forEach((d) => (d.__relationKey__ = self._description.Name));
|
|
134
|
+
data.forEach((d) => {
|
|
135
|
+
const relData = relationData.filter((rd) => rd.JunctionModel[self._description.ForeignKey] === d[self._description.PrimaryKey]);
|
|
136
|
+
d[self._description.Name] = new ManyToManyRelationList(d, self._description.TargetModel, self._description, relData);
|
|
137
|
+
});
|
|
138
|
+
relationData.forEach((d) => delete d.JunctionModel);
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
if (pks.length !== 0) {
|
|
142
|
+
this._relationQuery.whereIn(this._description.ForeignKey, pks);
|
|
143
|
+
this._relationQuery.middleware(new BelongsToRelationResultTransformMiddleware());
|
|
144
|
+
this._relationQuery.middleware(new DiscriminationMapMiddleware(this._targetModelDescriptor));
|
|
145
|
+
this._relationQuery.middleware(hydrateMiddleware);
|
|
146
|
+
return await this._relationQuery;
|
|
147
|
+
}
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
pickProps(source, except) {
|
|
151
|
+
const obj = {};
|
|
152
|
+
for (const p in source) {
|
|
153
|
+
if (except.indexOf(p) === -1) {
|
|
154
|
+
obj[p] = source[p];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return obj;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export class BelongsToPopulateDataMiddleware {
|
|
161
|
+
constructor(_description, relation) {
|
|
162
|
+
this._description = _description;
|
|
163
|
+
this.relation = relation;
|
|
164
|
+
}
|
|
165
|
+
afterQuery(data) {
|
|
166
|
+
return data;
|
|
167
|
+
}
|
|
168
|
+
modelCreation(_) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
afterHydration(data) {
|
|
172
|
+
const relData = data.map((d) => d[this._description.Name].Value).filter((x) => x !== null && x !== undefined);
|
|
173
|
+
const middlewares = this.relation._relationQuery.Relations
|
|
174
|
+
.map((x) => {
|
|
175
|
+
return x._query._middlewares;
|
|
176
|
+
})
|
|
177
|
+
.reduce((prev, current) => {
|
|
178
|
+
return prev.concat(current);
|
|
179
|
+
}, []);
|
|
180
|
+
return Promise.all(middlewares.map((x) => {
|
|
181
|
+
return x.afterHydration(relData);
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export class BelongsToRelationResultTransformMiddleware {
|
|
186
|
+
afterQuery(data) {
|
|
187
|
+
return data.map((d) => {
|
|
188
|
+
const transformedData = Object.assign(d);
|
|
189
|
+
for (const key in transformedData) {
|
|
190
|
+
if (key.startsWith('$')) {
|
|
191
|
+
this.setDeep(transformedData, this.keyTransform(key), d[key]);
|
|
192
|
+
delete transformedData[key];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return transformedData;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
modelCreation(_) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
// tslint:disable-next-line: no-empty
|
|
202
|
+
async afterHydration(_data) { }
|
|
203
|
+
/**
|
|
204
|
+
* Dynamically sets a deeply nested value in an object.
|
|
205
|
+
* Optionally "bores" a path to it if its undefined.
|
|
206
|
+
*
|
|
207
|
+
* @param obj - The object which contains the value you want to change/set.
|
|
208
|
+
* @param path - The array representation of path to the value you want to change/set.
|
|
209
|
+
* @param value - The value you want to set it to.
|
|
210
|
+
* @param setrecursively - If true, will set value of non-existing path as well.
|
|
211
|
+
*/
|
|
212
|
+
setDeep(obj, path, value, setrecursively = true) {
|
|
213
|
+
path.reduce((a, b, level) => {
|
|
214
|
+
if (setrecursively && typeof a[b] === 'undefined' && level !== path.length - 1) {
|
|
215
|
+
a[b] = {};
|
|
216
|
+
return a[b];
|
|
217
|
+
}
|
|
218
|
+
if (level === path.length - 1) {
|
|
219
|
+
a[b] = value;
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
return a[b];
|
|
223
|
+
}, obj);
|
|
224
|
+
}
|
|
225
|
+
keyTransform(key) {
|
|
226
|
+
return key.replace(/\$+/g, '').split('.');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
export class DiscriminationMapMiddleware {
|
|
230
|
+
constructor(_description) {
|
|
231
|
+
this._description = _description;
|
|
232
|
+
}
|
|
233
|
+
afterQuery(data) {
|
|
234
|
+
return data;
|
|
235
|
+
}
|
|
236
|
+
modelCreation(data) {
|
|
237
|
+
if (this._description.DiscriminationMap && this._description.DiscriminationMap.Field) {
|
|
238
|
+
const distValue = data[this._description.DiscriminationMap.Field];
|
|
239
|
+
if (distValue && this._description.DiscriminationMap.Models.has(distValue)) {
|
|
240
|
+
const result = new (this._description.DiscriminationMap.Models.get(distValue))();
|
|
241
|
+
result.hydrate(data);
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
// tslint:disable-next-line: no-empty
|
|
248
|
+
async afterHydration(_data) { }
|
|
249
|
+
}
|
|
250
250
|
//# sourceMappingURL=middlewares.js.map
|