@entity-access/entity-access 1.0.407 → 1.0.409
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/compiler/ISqlHelpers.d.ts.map +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.d.ts.map +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js +44 -0
- 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 +44 -0
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js.map +1 -1
- package/dist/decorators/CheckConstraint.d.ts.map +1 -1
- package/dist/decorators/ForeignKey.d.ts.map +1 -1
- package/dist/decorators/Index.d.ts.map +1 -1
- package/dist/decorators/Table.d.ts.map +1 -1
- package/dist/di/di.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/model/verification/VerificationSession.d.ts +8 -1
- package/dist/model/verification/VerificationSession.d.ts.map +1 -1
- package/dist/model/verification/VerificationSession.js +51 -33
- package/dist/model/verification/VerificationSession.js.map +1 -1
- package/dist/query/Query.d.ts.map +1 -1
- package/dist/query/ast/IStringTransformer.d.ts.map +1 -1
- package/dist/sql/ISql.d.ts +20 -0
- package/dist/sql/ISql.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +46 -0
- package/src/compiler/sql-server/SqlServerSqlMethodTransformer.ts +44 -1
- package/src/model/verification/VerificationSession.ts +58 -25
- package/src/sql/ISql.ts +21 -1
|
@@ -20,18 +20,45 @@ const isKeyEmpty = (key: any, columnName: IColumn) => {
|
|
|
20
20
|
return key === null || key === "";
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
interface IVerificationSet {
|
|
24
|
+
change: ChangeEntry,
|
|
25
|
+
fields: ConditionalExpression[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* It is not good to verify all entities at once, but rather
|
|
30
|
+
* single entity as it would reduce the query to single row
|
|
31
|
+
* and avoid unnecessary joins.
|
|
32
|
+
*
|
|
33
|
+
* First failure will stop any further query evaluation.
|
|
34
|
+
*/
|
|
35
|
+
|
|
23
36
|
export default class VerificationSession {
|
|
24
37
|
|
|
25
|
-
private select: SelectStatement;
|
|
38
|
+
// private select: SelectStatement;
|
|
26
39
|
|
|
27
40
|
private field: ConditionalExpression[];
|
|
28
41
|
|
|
42
|
+
private verificationSets: IVerificationSet[];
|
|
43
|
+
|
|
44
|
+
|
|
29
45
|
constructor(private context: EntityContext) {
|
|
30
46
|
|
|
31
|
-
this.select = SelectStatement.create({});
|
|
47
|
+
// this.select = SelectStatement.create({});
|
|
48
|
+
this.verificationSets = [];
|
|
32
49
|
}
|
|
33
50
|
|
|
34
51
|
queueVerification(change: ChangeEntry, events: EntityEvents<any>) {
|
|
52
|
+
|
|
53
|
+
const vs = {
|
|
54
|
+
change,
|
|
55
|
+
fields: []
|
|
56
|
+
} as IVerificationSet;
|
|
57
|
+
|
|
58
|
+
this.verificationSets.push(vs);
|
|
59
|
+
|
|
60
|
+
this.field = vs.fields;
|
|
61
|
+
|
|
35
62
|
const { type, entity } = change;
|
|
36
63
|
if (change.status !== "inserted") {
|
|
37
64
|
// verify access to the entity
|
|
@@ -143,29 +170,35 @@ export default class VerificationSession {
|
|
|
143
170
|
}
|
|
144
171
|
|
|
145
172
|
async verifyAsync(): Promise<any> {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
[
|
|
156
|
-
]
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
|
|
174
|
+
for (const { fields } of this.verificationSets) {
|
|
175
|
+
if (!fields.length) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const select = SelectStatement.create({});
|
|
180
|
+
|
|
181
|
+
select.fields =[
|
|
182
|
+
Expression.as( fields.length === 1 ? fields[0] : Expression.templateLiteral(fields), "error")
|
|
183
|
+
];
|
|
184
|
+
select.sourceParameter = ParameterExpression.create({ name: "x"});
|
|
185
|
+
const source = ValuesStatement.create({
|
|
186
|
+
values: [
|
|
187
|
+
[NumberLiteral.one]
|
|
188
|
+
],
|
|
189
|
+
as: Expression.identifier("a"),
|
|
190
|
+
fields: [Expression.identifier("a")]
|
|
191
|
+
});
|
|
192
|
+
select.source = source;
|
|
193
|
+
const compiler = this.context.driver.compiler;
|
|
194
|
+
const query = compiler.compileExpression(null, select);
|
|
195
|
+
const logger = ServiceProvider.resolve(this.context, Logger);
|
|
196
|
+
using session = logger.newSession();
|
|
197
|
+
const { rows: [ { error }]} = await this.context.connection.executeQuery(query);
|
|
198
|
+
if (error) {
|
|
199
|
+
session.error(`Failed executing \n${query.text}\n[\n${query.values.join(",")}]\n${error?.stack ?? error}`);
|
|
200
|
+
EntityAccessError.throw(error, 412);
|
|
201
|
+
}
|
|
169
202
|
}
|
|
170
203
|
}
|
|
171
204
|
|
package/src/sql/ISql.ts
CHANGED
|
@@ -9,7 +9,27 @@ export interface ISql {
|
|
|
9
9
|
sum(a: number[]): number;
|
|
10
10
|
count(a: any[]): number;
|
|
11
11
|
avg(a: number[]): number
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
window: {
|
|
14
|
+
rowNumber: {
|
|
15
|
+
orderBy(order: number): number;
|
|
16
|
+
orderByDescending(order: number): number;
|
|
17
|
+
partitionByOrderBy(partition: any, order: number): number;
|
|
18
|
+
partitionByOrderByDescending(partition: any, order: number): number;
|
|
19
|
+
},
|
|
20
|
+
rank: {
|
|
21
|
+
orderBy(order: number): number;
|
|
22
|
+
orderByDescending(order: number): number;
|
|
23
|
+
partitionByOrderBy(partition: any, order: number): number;
|
|
24
|
+
partitionByOrderByDescending(partition: any, order: number): number;
|
|
25
|
+
}
|
|
26
|
+
denseRank: {
|
|
27
|
+
orderBy(order: number): number;
|
|
28
|
+
orderByDescending(order: number): number;
|
|
29
|
+
partitionByOrderBy(partition: any, order: number): number;
|
|
30
|
+
partitionByOrderByDescending(partition: any, order: number): number;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
13
33
|
|
|
14
34
|
cast: {
|
|
15
35
|
asNumber(a: any): number;
|