@entity-access/entity-access 1.0.122 → 1.0.125
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/dist/decorators/Column.d.ts +6 -1
- package/dist/decorators/Column.d.ts.map +1 -1
- package/dist/decorators/Column.js +7 -0
- package/dist/decorators/Column.js.map +1 -1
- package/dist/decorators/IColumn.d.ts +3 -1
- package/dist/decorators/IColumn.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.js +1 -1
- package/dist/drivers/base/BaseDriver.js.map +1 -1
- package/dist/eternity/EternityContext.d.ts +1 -1
- package/dist/eternity/EternityContext.d.ts.map +1 -1
- package/dist/eternity/EternityContext.js.map +1 -1
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +9 -0
- package/dist/migrations/Migrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js +13 -3
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +14 -2
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
- package/dist/model/EntitySource.d.ts +1 -1
- package/dist/model/EntitySource.js.map +1 -1
- package/dist/model/changes/ChangeEntry.js +3 -3
- package/dist/model/changes/ChangeEntry.js.map +1 -1
- package/dist/model/changes/ChangeSet.d.ts +2 -2
- package/dist/model/changes/ChangeSet.d.ts.map +1 -1
- package/dist/model/changes/ChangeSet.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +1 -1
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/tests/model/ShoppingContext.d.ts +3 -0
- package/dist/tests/model/ShoppingContext.d.ts.map +1 -1
- package/dist/tests/model/ShoppingContext.js +15 -7
- package/dist/tests/model/ShoppingContext.js.map +1 -1
- package/dist/tests/model/UseFile.js +1 -1
- package/dist/tests/model/UseFile.js.map +1 -1
- package/dist/tests/security/events/ProductEvents.d.ts +2 -0
- package/dist/tests/security/events/ProductEvents.d.ts.map +1 -1
- package/dist/tests/security/events/ProductEvents.js +4 -0
- package/dist/tests/security/events/ProductEvents.js.map +1 -1
- package/dist/tests/security/tests/test-events.d.ts +3 -0
- package/dist/tests/security/tests/test-events.d.ts.map +1 -0
- package/dist/tests/security/tests/test-events.js +35 -0
- package/dist/tests/security/tests/test-events.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/decorators/Column.ts +13 -3
- package/src/decorators/IColumn.ts +5 -1
- package/src/drivers/base/BaseDriver.ts +1 -1
- package/src/eternity/EternityContext.ts +1 -1
- package/src/migrations/Migrations.ts +11 -0
- package/src/migrations/postgres/PostgresAutomaticMigrations.ts +17 -3
- package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +16 -2
- package/src/model/EntitySource.ts +1 -1
- package/src/model/changes/ChangeEntry.ts +3 -3
- package/src/model/changes/ChangeSet.ts +2 -2
- package/src/query/ast/ExpressionToSql.ts +1 -1
- package/src/tests/model/ShoppingContext.ts +15 -7
- package/src/tests/model/UseFile.ts +1 -1
- package/src/tests/security/events/ProductEvents.ts +6 -0
- package/src/tests/security/tests/test-events.ts +43 -0
|
@@ -5,6 +5,7 @@ import Table from "../../decorators/Table.js";
|
|
|
5
5
|
import Index from "../../decorators/Index.js";
|
|
6
6
|
import DateTime from "../../types/DateTime.js";
|
|
7
7
|
import { UserFile } from "./UseFile.js";
|
|
8
|
+
import Sql from "../../sql/Sql.js";
|
|
8
9
|
|
|
9
10
|
export const statusPublished = "published";
|
|
10
11
|
|
|
@@ -41,7 +42,7 @@ export class ShoppingContext extends EntityContext {
|
|
|
41
42
|
})
|
|
42
43
|
export class User {
|
|
43
44
|
|
|
44
|
-
@Column({ key: true ,
|
|
45
|
+
@Column({ key: true , generated: "identity", dataType: "BigInt" })
|
|
45
46
|
public userID: number;
|
|
46
47
|
|
|
47
48
|
@Column({})
|
|
@@ -80,6 +81,10 @@ export class Category {
|
|
|
80
81
|
@Column({ length: 200 })
|
|
81
82
|
public name: string;
|
|
82
83
|
|
|
84
|
+
|
|
85
|
+
@Column({ computed: (x) => Sql.text.lower(x.name)})
|
|
86
|
+
public lowerName: string;
|
|
87
|
+
|
|
83
88
|
@Column({ dataType: "Char", length: 200, nullable: true })
|
|
84
89
|
@RelateTo(Category, {
|
|
85
90
|
property: (c) => c.parent,
|
|
@@ -118,7 +123,7 @@ export class UserProfile {
|
|
|
118
123
|
@Table("ProfilePhotos")
|
|
119
124
|
export class ProfilePhoto {
|
|
120
125
|
|
|
121
|
-
@Column({ key: true, dataType: "BigInt",
|
|
126
|
+
@Column({ key: true, dataType: "BigInt", generated: "identity" })
|
|
122
127
|
public photoID: number;
|
|
123
128
|
|
|
124
129
|
@Column ({ dataType: "BigInt"})
|
|
@@ -162,7 +167,7 @@ export class UserCategory {
|
|
|
162
167
|
@Table("Products")
|
|
163
168
|
export class Product {
|
|
164
169
|
|
|
165
|
-
@Column({ key: true,
|
|
170
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt" })
|
|
166
171
|
public productID: number;
|
|
167
172
|
|
|
168
173
|
@Column()
|
|
@@ -183,13 +188,16 @@ export class Product {
|
|
|
183
188
|
public categories: ProductCategory[];
|
|
184
189
|
public owner: User;
|
|
185
190
|
|
|
191
|
+
public updated: string[];
|
|
192
|
+
public nameUpdated: boolean;
|
|
193
|
+
|
|
186
194
|
}
|
|
187
195
|
|
|
188
196
|
|
|
189
197
|
@Table("ProductCategories")
|
|
190
198
|
export class ProductCategory {
|
|
191
199
|
|
|
192
|
-
@Column({ key: true, dataType: "BigInt",
|
|
200
|
+
@Column({ key: true, dataType: "BigInt", generated: "identity" })
|
|
193
201
|
public productCategoryID: number;
|
|
194
202
|
|
|
195
203
|
@Column({ dataType: "BigInt" })
|
|
@@ -214,7 +222,7 @@ export class ProductCategory {
|
|
|
214
222
|
@Table("ProductPrices")
|
|
215
223
|
export class ProductPrice {
|
|
216
224
|
|
|
217
|
-
@Column({ key: true,
|
|
225
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt"})
|
|
218
226
|
public priceID: number;
|
|
219
227
|
|
|
220
228
|
@Column()
|
|
@@ -248,7 +256,7 @@ export class ProductPrice {
|
|
|
248
256
|
})
|
|
249
257
|
export class Order {
|
|
250
258
|
|
|
251
|
-
@Column({ key: true,
|
|
259
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt"})
|
|
252
260
|
public orderID: number;
|
|
253
261
|
|
|
254
262
|
@Column()
|
|
@@ -273,7 +281,7 @@ export class Order {
|
|
|
273
281
|
@Table("OrderItems")
|
|
274
282
|
export class OrderItem {
|
|
275
283
|
|
|
276
|
-
@Column({ key: true,
|
|
284
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt"})
|
|
277
285
|
public orderItemID: number;
|
|
278
286
|
|
|
279
287
|
@Column()
|
|
@@ -6,7 +6,7 @@ import { User } from "./ShoppingContext.js";
|
|
|
6
6
|
@Table("UserFiles")
|
|
7
7
|
export class UserFile {
|
|
8
8
|
|
|
9
|
-
@Column({ dataType: "BigInt", key: true,
|
|
9
|
+
@Column({ dataType: "BigInt", key: true, generated: "identity" })
|
|
10
10
|
public fileID: number;
|
|
11
11
|
|
|
12
12
|
@Column({ dataType: "BigInt"})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EntityAccessError from "../../../common/EntityAccessError.js";
|
|
2
2
|
import Inject from "../../../di/di.js";
|
|
3
3
|
import { IEntityQuery } from "../../../model/IFilterWithParameter.js";
|
|
4
|
+
import ChangeEntry from "../../../model/changes/ChangeEntry.js";
|
|
4
5
|
import EntityEvents from "../../../model/events/EntityEvents.js";
|
|
5
6
|
import { Product, ProductCategory, ProductPrice } from "../../model/ShoppingContext.js";
|
|
6
7
|
import { UserInfo } from "./UserInfo.js";
|
|
@@ -34,6 +35,11 @@ export class ProductEvents extends EntityEvents<Product> {
|
|
|
34
35
|
return query.where({ userID }, (p) => (x) => x.ownerID === p.userID);
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
afterUpdate(entity: Product, entry: ChangeEntry<Product>): void | Promise<void> {
|
|
39
|
+
entity.updated = Array.from(entry.updated.keys()).map((x) => x.name);
|
|
40
|
+
entity.nameUpdated = entry.isUpdated("name");
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
export class ProductCategoryEvents extends EntityEvents<ProductCategory> {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import Logger from "../../../common/Logger.js";
|
|
3
|
+
import { ServiceCollection, ServiceProvider } from "../../../di/di.js";
|
|
4
|
+
import { BaseDriver } from "../../../drivers/base/BaseDriver.js";
|
|
5
|
+
import ContextEvents from "../../../model/events/ContextEvents.js";
|
|
6
|
+
import { TestConfig } from "../../TestConfig.js";
|
|
7
|
+
import { ShoppingContext } from "../../model/ShoppingContext.js";
|
|
8
|
+
import { createContext } from "../../model/createContext.js";
|
|
9
|
+
import { ShoppingContextEvents } from "../ShoppingContextEvents.js";
|
|
10
|
+
import { UserInfo } from "../events/UserInfo.js";
|
|
11
|
+
|
|
12
|
+
export default async function (this: TestConfig) {
|
|
13
|
+
|
|
14
|
+
await createContext(this.driver);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const global = new ServiceProvider();
|
|
18
|
+
global.add(BaseDriver, this.driver);
|
|
19
|
+
const scope = global.createScope();
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
|
|
23
|
+
const userID = 1;
|
|
24
|
+
const user = new UserInfo();
|
|
25
|
+
user.userID = userID;
|
|
26
|
+
scope.add(Logger, Logger.instance);
|
|
27
|
+
scope.add(BaseDriver, this.driver);
|
|
28
|
+
scope.add(UserInfo, user);
|
|
29
|
+
scope.add(ContextEvents, new ShoppingContextEvents());
|
|
30
|
+
const context = scope.create(ShoppingContext);
|
|
31
|
+
|
|
32
|
+
const first = await context.products.all().first();
|
|
33
|
+
first.name = "First Product";
|
|
34
|
+
const fe = context.changeSet.getEntry(first);
|
|
35
|
+
await context.saveChanges();
|
|
36
|
+
|
|
37
|
+
assert.equal(true, first.nameUpdated);
|
|
38
|
+
assert.equal(false, fe.isUpdated("name"));
|
|
39
|
+
} finally {
|
|
40
|
+
scope.dispose();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|