@entity-access/entity-access 1.0.9 → 1.0.11
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 +13 -8
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.d.ts.map +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js +54 -2
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js.map +1 -1
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.d.ts.map +1 -1
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js +54 -2
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js.map +1 -1
- package/dist/decorators/IColumn.d.ts +4 -0
- package/dist/decorators/IColumn.d.ts.map +1 -1
- package/dist/decorators/Relate.d.ts +8 -0
- package/dist/decorators/Relate.d.ts.map +1 -0
- package/dist/decorators/Relate.js +18 -0
- package/dist/decorators/Relate.js.map +1 -0
- package/dist/di/di.js +1 -1
- package/dist/di/di.js.map +1 -1
- package/dist/sql/ISql.d.ts +29 -0
- package/dist/sql/ISql.d.ts.map +1 -1
- package/dist/tests/model/ShoppingContext.d.ts.map +1 -1
- package/dist/tests/model/ShoppingContext.js +25 -33
- package/dist/tests/model/ShoppingContext.js.map +1 -1
- package/dist/tests/security/tests/place-order.js +5 -5
- package/dist/tests/security/tests/place-order.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +56 -2
- package/src/compiler/sql-server/SqlServerSqlMethodTransformer.ts +59 -3
- package/src/decorators/IColumn.ts +5 -0
- package/src/decorators/Relate.ts +37 -0
- package/src/di/di.ts +1 -1
- package/src/sql/ISql.ts +31 -0
- package/src/tests/model/ShoppingContext.ts +25 -33
- package/src/tests/security/tests/place-order.ts +5 -5
package/src/sql/ISql.ts
CHANGED
|
@@ -14,13 +14,44 @@ export interface ISql {
|
|
|
14
14
|
|
|
15
15
|
text: {
|
|
16
16
|
concat(... fragments: string[]): string;
|
|
17
|
+
/**
|
|
18
|
+
* Concat with separator
|
|
19
|
+
* @param separator separator used to join
|
|
20
|
+
* @param fragments text fragments
|
|
21
|
+
*/
|
|
22
|
+
concatWS(separator: string, ... fragments: string[]): string;
|
|
23
|
+
difference(left: string, right: string): number;
|
|
17
24
|
like(text: string, test: string): boolean;
|
|
18
25
|
iLike(text: string, test: string): boolean;
|
|
19
26
|
left(text: string, length: number): string;
|
|
20
27
|
right(text: string, length: number): string;
|
|
21
28
|
startsWith(text: string, test: string): boolean;
|
|
22
29
|
endsWith(text: string, test: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* This will return index of given search, and it will
|
|
32
|
+
* return -1 if test value is not found. If underlying provider
|
|
33
|
+
* supports 1 as starting index, 1 will be subtracted from given result.
|
|
34
|
+
* @param text string to be searched in
|
|
35
|
+
* @param test string to search
|
|
36
|
+
*/
|
|
23
37
|
indexOf(text: string, test: string): number;
|
|
38
|
+
normalize(text: string, kind?: string): string;
|
|
39
|
+
collate(text: string, collation: string): string;
|
|
40
|
+
lower(text: string): string;
|
|
41
|
+
upper(text: string): string;
|
|
42
|
+
trim(text: string): string;
|
|
43
|
+
|
|
44
|
+
reverse(text: string): string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create substring from the given string. Please note that the index you specify should be
|
|
48
|
+
* zero based, and based on underlying provider, index will be incremented by one if provider
|
|
49
|
+
* supports 1 as starting index.
|
|
50
|
+
* @param text text
|
|
51
|
+
* @param start start index, zero based, one will be added to support underlying database positioning
|
|
52
|
+
* @param length length
|
|
53
|
+
*/
|
|
54
|
+
substring(text: string, start: number, length?: number): string;
|
|
24
55
|
},
|
|
25
56
|
|
|
26
57
|
date: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EntityContext from "../../model/EntityContext.js";
|
|
2
2
|
import Column from "../../decorators/Column.js";
|
|
3
|
-
import
|
|
3
|
+
import Relate from "../../decorators/Relate.js";
|
|
4
4
|
import Table from "../../decorators/Table.js";
|
|
5
5
|
|
|
6
6
|
export const statusPublished = "published";
|
|
@@ -73,10 +73,9 @@ export class Product {
|
|
|
73
73
|
|
|
74
74
|
public categories: ProductCategory[];
|
|
75
75
|
|
|
76
|
-
@
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
relatedProperty: (user) => user.ownedProducts
|
|
76
|
+
@Relate(User, {
|
|
77
|
+
foreignKey: (product) => product.ownerID,
|
|
78
|
+
inverseProperty: (user) => user.ownedProducts
|
|
80
79
|
})
|
|
81
80
|
public owner: User;
|
|
82
81
|
|
|
@@ -95,17 +94,15 @@ export class ProductCategory {
|
|
|
95
94
|
@Column({ dataType: "Char", length: 200})
|
|
96
95
|
public categoryID: string;
|
|
97
96
|
|
|
98
|
-
@
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
relatedProperty: (c) => c.categories
|
|
97
|
+
@Relate(Product, {
|
|
98
|
+
foreignKey: (pc) => pc.productID,
|
|
99
|
+
inverseProperty: (c) => c.categories
|
|
102
100
|
})
|
|
103
101
|
public product: Product;
|
|
104
102
|
|
|
105
|
-
@
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
relatedProperty: (c) => c.productCategories
|
|
103
|
+
@Relate(Category, {
|
|
104
|
+
foreignKey: (pc) => pc.categoryID,
|
|
105
|
+
inverseProperty: (c) => c.productCategories
|
|
109
106
|
})
|
|
110
107
|
public category: Category;
|
|
111
108
|
}
|
|
@@ -131,10 +128,9 @@ export class ProductPrice {
|
|
|
131
128
|
@Column({})
|
|
132
129
|
public productID: number;
|
|
133
130
|
|
|
134
|
-
@
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
relatedProperty: (product) => product.prices
|
|
131
|
+
@Relate(Product, {
|
|
132
|
+
foreignKey: (productPrice) => productPrice.productID,
|
|
133
|
+
inverseProperty: (product) => product.prices
|
|
138
134
|
})
|
|
139
135
|
public product: Product;
|
|
140
136
|
|
|
@@ -155,10 +151,9 @@ export class Order {
|
|
|
155
151
|
|
|
156
152
|
public orderItems: OrderItem[];
|
|
157
153
|
|
|
158
|
-
@
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
relatedProperty: (user) => user.orders
|
|
154
|
+
@Relate(User, {
|
|
155
|
+
foreignKey: (order) => order.customerID,
|
|
156
|
+
inverseProperty: (user) => user.orders
|
|
162
157
|
})
|
|
163
158
|
public customer: User;
|
|
164
159
|
|
|
@@ -182,25 +177,22 @@ export class OrderItem {
|
|
|
182
177
|
@Column()
|
|
183
178
|
public amount: number;
|
|
184
179
|
|
|
185
|
-
@
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
relatedProperty: (order) => order.orderItems
|
|
180
|
+
@Relate(Order, {
|
|
181
|
+
foreignKey: (orderItem) => orderItem.orderID,
|
|
182
|
+
inverseProperty: (order) => order.orderItems
|
|
189
183
|
})
|
|
190
184
|
public order: Order;
|
|
191
185
|
|
|
192
|
-
@
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
relatedProperty:(product) => product.orderItems
|
|
186
|
+
@Relate(Product, {
|
|
187
|
+
foreignKey: (orderItem) => orderItem.productID,
|
|
188
|
+
inverseProperty:(product) => product.orderItems
|
|
196
189
|
})
|
|
197
190
|
public product: Product;
|
|
198
191
|
|
|
199
192
|
|
|
200
|
-
@
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
relatedProperty: (productPrice) => productPrice.orderItems
|
|
193
|
+
@Relate(ProductPrice, {
|
|
194
|
+
foreignKey: (orderItem) => orderItem.priceID,
|
|
195
|
+
inverseProperty: (productPrice) => productPrice.orderItems
|
|
204
196
|
})
|
|
205
197
|
public productPrice: ProductPrice;
|
|
206
198
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import Logger from "../../../common/Logger.js";
|
|
3
|
-
import { ServiceProvider } from "../../../di/di.js";
|
|
3
|
+
import { ServiceCollection, ServiceProvider } from "../../../di/di.js";
|
|
4
4
|
import { BaseDriver } from "../../../drivers/base/BaseDriver.js";
|
|
5
5
|
import ContextEvents from "../../../model/events/ContextEvents.js";
|
|
6
6
|
import { TestConfig } from "../../TestConfig.js";
|
|
@@ -31,10 +31,10 @@ async function getNewOrders(this: TestConfig) {
|
|
|
31
31
|
try {
|
|
32
32
|
const user = new UserInfo();
|
|
33
33
|
user.userID = 2;
|
|
34
|
-
|
|
34
|
+
ServiceCollection.register("Singleton", Logger, () => Logger.instance);
|
|
35
35
|
scope.add(BaseDriver, this.driver);
|
|
36
36
|
scope.add(UserInfo, user);
|
|
37
|
-
|
|
37
|
+
ServiceCollection.register("Singleton", ContextEvents, () => new ShoppingContextEvents());
|
|
38
38
|
const context = scope.create(ShoppingContext);
|
|
39
39
|
context.verifyFilters = true;
|
|
40
40
|
|
|
@@ -53,10 +53,10 @@ async function addNewOrder(this: TestConfig, customer: User, userID?) {
|
|
|
53
53
|
try {
|
|
54
54
|
const user = new UserInfo();
|
|
55
55
|
user.userID = userID ?? customer.userID;
|
|
56
|
-
|
|
56
|
+
ServiceCollection.register("Singleton", Logger, () => Logger.instance);
|
|
57
57
|
scope.add(BaseDriver, this.driver);
|
|
58
58
|
scope.add(UserInfo, user);
|
|
59
|
-
|
|
59
|
+
ServiceCollection.register("Singleton", ContextEvents, () => new ShoppingContextEvents());
|
|
60
60
|
const context = scope.create(ShoppingContext);
|
|
61
61
|
context.verifyFilters = true;
|
|
62
62
|
|