@entity-access/entity-access 1.0.304 → 1.0.306
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/common/CustomEvent.d.ts +0 -1
- package/dist/common/CustomEvent.d.ts.map +1 -1
- package/dist/common/Logger.d.ts +1 -1
- package/dist/common/cache/TimedCache.d.ts.map +1 -1
- package/dist/common/cloner.d.ts.map +1 -1
- package/dist/common/sleep.d.ts +0 -1
- package/dist/common/sleep.d.ts.map +1 -1
- package/dist/compiler/ISqlHelpers.d.ts +2 -0
- package/dist/compiler/ISqlHelpers.d.ts.map +1 -1
- package/dist/compiler/ISqlHelpers.js +26 -0
- package/dist/compiler/ISqlHelpers.js.map +1 -1
- package/dist/compiler/QueryCompiler.js +1 -1
- package/dist/compiler/QueryCompiler.js.map +1 -1
- package/dist/compiler/RawQuery.d.ts +0 -1
- package/dist/compiler/RawQuery.d.ts.map +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.d.ts +1 -2
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.d.ts.map +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js +16 -14
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js.map +1 -1
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.d.ts +1 -2
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.d.ts.map +1 -1
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js +16 -14
- package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js.map +1 -1
- package/dist/decorators/CheckConstraint.d.ts.map +1 -1
- package/dist/decorators/Index.d.ts.map +1 -1
- package/dist/di/di.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts +0 -2
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts +0 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.js +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.js.map +1 -1
- package/dist/entity-query/EntityType.d.ts +4 -4
- package/dist/model/EntityContext.d.ts +0 -1
- package/dist/model/EntityContext.d.ts.map +1 -1
- package/dist/model/EntityModel.d.ts.map +1 -1
- package/dist/model/EntityQuery.d.ts +0 -1
- package/dist/model/EntityQuery.d.ts.map +1 -1
- package/dist/model/EntitySource.d.ts.map +1 -1
- package/dist/model/IFilterWithParameter.d.ts +0 -1
- package/dist/model/IFilterWithParameter.d.ts.map +1 -1
- package/dist/query/Query.d.ts.map +1 -1
- package/dist/query/ast/DebugStringVisitor.d.ts +2 -1
- package/dist/query/ast/DebugStringVisitor.d.ts.map +1 -1
- package/dist/query/ast/DebugStringVisitor.js +3 -0
- package/dist/query/ast/DebugStringVisitor.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +7 -3
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/query/ast/Expressions.d.ts.map +1 -1
- package/dist/query/ast/IStringTransformer.d.ts +2 -2
- package/dist/query/ast/IStringTransformer.d.ts.map +1 -1
- package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
- package/dist/query/parser/ArrowToExpression.js +31 -17
- package/dist/query/parser/ArrowToExpression.js.map +1 -1
- package/dist/tests/db-tests/tests/select-items-sum.d.ts.map +1 -1
- package/dist/tests/db-tests/tests/select-items-sum.js +4 -5
- package/dist/tests/db-tests/tests/select-items-sum.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/workflows/Waiter.d.ts +0 -1
- package/dist/workflows/Waiter.d.ts.map +1 -1
- package/dist/workflows/WorkflowContext.d.ts +0 -1
- package/dist/workflows/WorkflowContext.d.ts.map +1 -1
- package/dist/workflows/WorkflowRegistry.d.ts.map +1 -1
- package/dist/workflows/WorkflowStorage.d.ts +0 -1
- package/dist/workflows/WorkflowStorage.d.ts.map +1 -1
- package/dist/workflows/WorkflowStorage.js +3 -3
- package/dist/workflows/WorkflowStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler/ISqlHelpers.ts +33 -0
- package/src/compiler/QueryCompiler.ts +1 -1
- package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +17 -15
- package/src/compiler/sql-server/SqlServerSqlMethodTransformer.ts +17 -15
- package/src/drivers/sql-server/SqlServerQueryCompiler.ts +1 -1
- package/src/query/ast/DebugStringVisitor.ts +5 -1
- package/src/query/ast/ExpressionToSql.ts +8 -3
- package/src/query/ast/IStringTransformer.ts +1 -1
- package/src/query/parser/ArrowToExpression.ts +32 -17
- package/src/tests/db-tests/tests/select-items-sum.ts +4 -5
- package/src/workflows/WorkflowStorage.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { joinAny, joinMap, prepareAny } from "../../query/ast/IStringTransformer.js";
|
|
2
2
|
import { NotSupportedError } from "../../query/parser/NotSupportedError.js";
|
|
3
3
|
import Sql from "../../sql/Sql.js";
|
|
4
|
-
import { ISqlHelpers } from "../ISqlHelpers.js";
|
|
4
|
+
import { ISqlHelpers, flattenMethods } from "../ISqlHelpers.js";
|
|
5
5
|
import type QueryCompiler from "../QueryCompiler.js";
|
|
6
6
|
|
|
7
7
|
const onlyAlphaNumeric = (x: string) => x.replace(/\W/g, "");
|
|
@@ -204,18 +204,20 @@ export const PostgreSqlHelper: ISqlHelpers = {
|
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
export
|
|
207
|
+
export const PostgreSqlMethodTransformer = flattenMethods(PostgreSqlHelper);
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
209
|
+
// export default function PostgreSqlMethodTransformer(compiler: QueryCompiler, method: string, args: any[]): string {
|
|
210
|
+
|
|
211
|
+
// let start = PostgreSqlHelper;
|
|
212
|
+
// for (const iterator of callee) {
|
|
213
|
+
// start = start[iterator];
|
|
214
|
+
// if (!start) {
|
|
215
|
+
// return;
|
|
216
|
+
// }
|
|
217
|
+
// }
|
|
218
|
+
// if (!start) {
|
|
219
|
+
// return;
|
|
220
|
+
// }
|
|
221
|
+
// // eslint-disable-next-line @typescript-eslint/ban-types
|
|
222
|
+
// return (start as unknown as Function).apply(compiler, args);
|
|
223
|
+
// }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { joinAny, joinMap, prepareAny } from "../../query/ast/IStringTransformer.js";
|
|
3
3
|
import Sql from "../../sql/Sql.js";
|
|
4
|
-
import { ISqlHelpers } from "../ISqlHelpers.js";
|
|
4
|
+
import { ISqlHelpers, flattenMethods } from "../ISqlHelpers.js";
|
|
5
5
|
import type QueryCompiler from "../QueryCompiler.js";
|
|
6
6
|
|
|
7
7
|
export const SqlServerSqlHelper: ISqlHelpers = {
|
|
@@ -207,18 +207,20 @@ export const SqlServerSqlHelper: ISqlHelpers = {
|
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
-
export
|
|
210
|
+
export const SqlServerSqlMethodTransformer = flattenMethods(SqlServerSqlHelper);
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
212
|
+
// export default function SqlServerSqlMethodTransformer(compiler: QueryCompiler, method: string, args: any[]): string {
|
|
213
|
+
|
|
214
|
+
// let start = SqlServerSqlHelper;
|
|
215
|
+
// for (const iterator of callee) {
|
|
216
|
+
// start = start[iterator];
|
|
217
|
+
// if (!start) {
|
|
218
|
+
// return;
|
|
219
|
+
// }
|
|
220
|
+
// }
|
|
221
|
+
// if (!start) {
|
|
222
|
+
// return;
|
|
223
|
+
// }
|
|
224
|
+
// // eslint-disable-next-line @typescript-eslint/ban-types
|
|
225
|
+
// return (start as unknown as Function).apply(compiler, args);
|
|
226
|
+
// }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NamingConventions } from "../../compiler/NamingConventions.js";
|
|
2
2
|
import QueryCompiler from "../../compiler/QueryCompiler.js";
|
|
3
|
-
import SqlServerSqlMethodTransformer from "../../compiler/sql-server/SqlServerSqlMethodTransformer.js";
|
|
3
|
+
import { SqlServerSqlMethodTransformer } from "../../compiler/sql-server/SqlServerSqlMethodTransformer.js";
|
|
4
4
|
import ArrowToExpression from "../../query/parser/ArrowToExpression.js";
|
|
5
5
|
import ExpressionToSqlServer from "./ExpressionToSqlServer.js";
|
|
6
6
|
import { SqlServerLiteral } from "./SqlServerLiteral.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayExpression, ArrowFunctionExpression, BigIntLiteral, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, DeleteStatement, ExistsExpression, Expression, ExpressionAs, Identifier, InsertStatement, JoinExpression, MemberExpression, NewObjectExpression, NotExits, NullExpression, NumberLiteral, OrderByExpression, ParameterExpression, ReturnUpdated, SelectStatement, StringLiteral, TableLiteral, TemplateElement, TemplateLiteral, UnionAllStatement, UpdateStatement, ValuesStatement } from "./Expressions.js";
|
|
1
|
+
import { ArrayExpression, ArrowFunctionExpression, BigIntLiteral, BinaryExpression, BooleanLiteral, BracketExpression, CallExpression, CoalesceExpression, ConditionalExpression, Constant, DeleteStatement, ExistsExpression, Expression, ExpressionAs, Identifier, InsertStatement, JoinExpression, MemberExpression, NewObjectExpression, NotExits, NullExpression, NumberLiteral, OrderByExpression, ParameterExpression, ReturnUpdated, SelectStatement, StringLiteral, TableLiteral, TemplateElement, TemplateLiteral, UnionAllStatement, UpdateStatement, ValuesStatement } from "./Expressions.js";
|
|
2
2
|
import Visitor from "./Visitor.js";
|
|
3
3
|
|
|
4
4
|
const isBinary = (type) => /^(BinaryExpression|CoalesceExpression)$/.test(type);
|
|
@@ -58,6 +58,10 @@ export default class DebugStringVisitor extends Visitor<string> {
|
|
|
58
58
|
return `"Constant:${e.value}"`;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
visitBracketExpression(e: BracketExpression): string {
|
|
62
|
+
return `(${this.visit(e.target)})`;
|
|
63
|
+
}
|
|
64
|
+
|
|
61
65
|
visitExpressionAs(e: ExpressionAs): string {
|
|
62
66
|
return `${this.visit(e.expression)} as ${this.visit(e.alias)}`;
|
|
63
67
|
}
|
|
@@ -243,7 +243,7 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
243
243
|
if (lastMethod.isCollectionMethod) {
|
|
244
244
|
return this.visit({ ... select, where, fields: [
|
|
245
245
|
CallExpression.create({
|
|
246
|
-
callee: Expression.
|
|
246
|
+
callee: Expression.identifier("Sql.coll." + lastMethod.member),
|
|
247
247
|
arguments: [body.body]
|
|
248
248
|
})
|
|
249
249
|
] } as SelectStatement);
|
|
@@ -259,9 +259,11 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
const identifierValue = identifier?.value;
|
|
263
|
+
|
|
264
|
+
if (identifierValue?.startsWith("Sql")) {
|
|
263
265
|
const argList = e.arguments?.map((x) => this.visit(x)) ?? [];
|
|
264
|
-
const transformedCallee = this.compiler.sqlMethodTransformer(this.compiler,
|
|
266
|
+
const transformedCallee = this.compiler.sqlMethodTransformer(this.compiler, identifierValue, argList.map((al) => al.flat(2)) as any[]);
|
|
265
267
|
if (transformedCallee) {
|
|
266
268
|
return prepare `${transformedCallee}`;
|
|
267
269
|
}
|
|
@@ -891,6 +893,9 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
891
893
|
throw new EntityAccessError("Invalid call expression");
|
|
892
894
|
}
|
|
893
895
|
x = me.target;
|
|
896
|
+
if (x.type === "MemberExpression") {
|
|
897
|
+
x = this.resolveExpression(x) ?? x;
|
|
898
|
+
}
|
|
894
899
|
chain.splice(0, 0, { member: (me.property as Identifier).value, args: ce.arguments });
|
|
895
900
|
continue;
|
|
896
901
|
}
|
|
@@ -5,7 +5,7 @@ export type ITextQuery = ITextQueryFragment[];
|
|
|
5
5
|
|
|
6
6
|
export type IStringTransformer = (s: string) => string;
|
|
7
7
|
|
|
8
|
-
export type ISqlMethodTransformer = (compiler: QueryCompiler,
|
|
8
|
+
export type ISqlMethodTransformer = (compiler: QueryCompiler, method: string, args: string[]) => string;
|
|
9
9
|
|
|
10
10
|
export class QueryParameter {
|
|
11
11
|
|
|
@@ -240,34 +240,49 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
240
240
|
return ce;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
let callee = ce.callee as MemberExpression;
|
|
244
|
+
const name = [];
|
|
245
|
+
while(callee) {
|
|
246
|
+
name.splice(0, 0, (callee.property as Identifier)?.value);
|
|
247
|
+
const target = callee.target;
|
|
248
|
+
switch(target.type) {
|
|
249
|
+
case "MemberExpression":
|
|
250
|
+
callee = target as MemberExpression;
|
|
251
|
+
continue;
|
|
252
|
+
case "Identifier":
|
|
253
|
+
name.splice(0, 0, (target as Identifier).value);
|
|
254
|
+
callee = null;
|
|
255
|
+
break;
|
|
256
|
+
default:
|
|
257
|
+
return ce;
|
|
258
|
+
}
|
|
246
259
|
}
|
|
247
260
|
|
|
248
|
-
|
|
249
|
-
if (mapCallee?.type !== "MemberExpression") {
|
|
261
|
+
if (name[0] !== "Sql") {
|
|
250
262
|
return ce;
|
|
251
263
|
}
|
|
252
264
|
|
|
253
|
-
const
|
|
254
|
-
const method = (me.property as Identifier).value;
|
|
265
|
+
const method = name[2];
|
|
255
266
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
267
|
+
const reWrittenCe = CallExpression.create({
|
|
268
|
+
callee: Expression.identifier(name.join(".")),
|
|
269
|
+
arguments: ce.arguments
|
|
270
|
+
});
|
|
259
271
|
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
|
|
273
|
+
if (name[1] !== "coll") {
|
|
274
|
+
// rewrite...
|
|
275
|
+
return reWrittenCe;
|
|
262
276
|
}
|
|
263
277
|
|
|
264
|
-
const
|
|
265
|
-
if(
|
|
266
|
-
return
|
|
278
|
+
const firstArg = ce.arguments[0] as CallExpression;
|
|
279
|
+
if (firstArg?.type !== "CallExpression") {
|
|
280
|
+
return reWrittenCe;
|
|
267
281
|
}
|
|
268
282
|
|
|
269
|
-
|
|
270
|
-
|
|
283
|
+
const mapCallee = firstArg.callee as MemberExpression;
|
|
284
|
+
if (mapCallee?.type !== "MemberExpression") {
|
|
285
|
+
return reWrittenCe;
|
|
271
286
|
}
|
|
272
287
|
|
|
273
288
|
const left = CallExpression.create({
|
|
@@ -31,13 +31,12 @@ export default async function(this: TestConfig) {
|
|
|
31
31
|
|
|
32
32
|
// assert.notEqual(null, report);
|
|
33
33
|
|
|
34
|
-
await context.orders.asQuery()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// await context.orders.asQuery()
|
|
35
|
+
// .update(void 0, (p) => (x) => ({
|
|
36
|
+
// total: Sql.coll.sum(x.orderItems.map((o) => o.amount ))
|
|
37
|
+
// }));
|
|
38
38
|
|
|
39
39
|
report = await context.users.all()
|
|
40
|
-
.where({}, (p) => (x) => x.orders.some((oi) => oi.customerID > 0))
|
|
41
40
|
.map({}, (p) => (x) => ({
|
|
42
41
|
total: Sql.coll.sum(x.orders
|
|
43
42
|
.filter((o) => o.status === "pending")
|
|
@@ -274,9 +274,9 @@ export default class WorkflowStorage {
|
|
|
274
274
|
Expression.assign(
|
|
275
275
|
Expression.identifier(lockTTLField),
|
|
276
276
|
CallExpression.create({
|
|
277
|
-
callee: Expression.
|
|
277
|
+
callee: Expression.identifier("Sql.date.addMinutes"),
|
|
278
278
|
arguments: [CallExpression.create({
|
|
279
|
-
callee: Expression.
|
|
279
|
+
callee: Expression.identifier("Sql.date.now")
|
|
280
280
|
}),
|
|
281
281
|
NumberLiteral.create({ value: 15 })
|
|
282
282
|
]
|
|
@@ -294,7 +294,7 @@ export default class WorkflowStorage {
|
|
|
294
294
|
Expression.lessOrEqual(
|
|
295
295
|
Expression.identifier(lockTTLField),
|
|
296
296
|
CallExpression.create({
|
|
297
|
-
callee: Expression.
|
|
297
|
+
callee: Expression.identifier("Sql.date.now")
|
|
298
298
|
})
|
|
299
299
|
)
|
|
300
300
|
))
|