@entity-access/entity-access 1.0.547 → 1.1.1
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 +34 -43
- package/dist/compiler/QueryCompiler.d.ts +4 -4
- package/dist/compiler/QueryCompiler.d.ts.map +1 -1
- package/dist/compiler/QueryCompiler.js.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.js +3 -2
- package/dist/drivers/sql-server/SqlServerDriver.js.map +1 -1
- package/dist/model/EntityQuery.d.ts +14 -11
- package/dist/model/EntityQuery.d.ts.map +1 -1
- package/dist/model/EntityQuery.js +69 -3
- package/dist/model/EntityQuery.js.map +1 -1
- package/dist/model/EntitySource.d.ts +3 -2
- package/dist/model/EntitySource.d.ts.map +1 -1
- package/dist/model/EntitySource.js +3 -3
- package/dist/model/EntitySource.js.map +1 -1
- package/dist/model/IFilterWithParameter.d.ts +32 -17
- package/dist/model/IFilterWithParameter.d.ts.map +1 -1
- package/dist/model/changes/ChangeEntry.js +1 -1
- package/dist/model/changes/ChangeEntry.js.map +1 -1
- package/dist/query/parser/ArrowToExpression.d.ts +2 -2
- package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
- package/dist/query/parser/ArrowToExpression.js +49 -29
- package/dist/query/parser/ArrowToExpression.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/workflows/WorkflowStorage.js +20 -20
- package/dist/workflows/WorkflowStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler/QueryCompiler.ts +4 -4
- package/src/drivers/sql-server/SqlServerDriver.ts +3 -3
- package/src/model/EntityQuery.ts +88 -15
- package/src/model/EntitySource.ts +7 -5
- package/src/model/IFilterWithParameter.ts +32 -17
- package/src/model/changes/ChangeEntry.ts +1 -1
- package/src/query/parser/ArrowToExpression.ts +51 -33
- package/src/workflows/WorkflowStorage.ts +20 -20
|
@@ -18,7 +18,7 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
18
18
|
* @param target parameter target
|
|
19
19
|
* @returns Parsed expression
|
|
20
20
|
*/
|
|
21
|
-
public static transform(fx: (
|
|
21
|
+
public static transform(fx: (x: any, p: any) => any, target?: ParameterExpression, outerParameter?: ParameterExpression) {
|
|
22
22
|
const key = fx.toString();
|
|
23
23
|
const rs = new Restructure();
|
|
24
24
|
const node = rs.visit(parseExpression(key));
|
|
@@ -26,7 +26,7 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* Since expression parsed as a different parameter in nested lambda (p) =>
|
|
29
|
+
* Since expression parsed as a different parameter in nested lambda (x, p) => x..,
|
|
30
30
|
* we need to replace x with provided target to bind x with respective ParameterExpression.
|
|
31
31
|
* As ParameterExpression contains the type and model associated with the table represented by `x`.
|
|
32
32
|
* @param node parsed node
|
|
@@ -35,9 +35,6 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
35
35
|
*/
|
|
36
36
|
private static transformUncached(node: bpe.Node, target?: ParameterExpression, outerParameter?: ParameterExpression): { params: ParameterExpression[], body: Expression, target: ParameterExpression } {
|
|
37
37
|
|
|
38
|
-
if (node.type !== "ArrowFunctionExpression") {
|
|
39
|
-
throw new Error("Expecting an arrow function");
|
|
40
|
-
}
|
|
41
38
|
|
|
42
39
|
const paramSet = new Map<string, any>();
|
|
43
40
|
|
|
@@ -45,46 +42,67 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
45
42
|
|
|
46
43
|
const params = [];
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw new Error("Expecting an identifier");
|
|
51
|
-
}
|
|
52
|
-
if (!firstOuterParam && outerParameter) {
|
|
53
|
-
firstOuterParam = iterator.name;
|
|
54
|
-
paramSet.set(iterator.name, outerParameter);
|
|
55
|
-
params.push(outerParameter);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const p1 = ParameterExpression.create({ name: iterator.name });
|
|
59
|
-
paramSet.set(iterator.name, p1);
|
|
60
|
-
params.push(p1);
|
|
45
|
+
if (node.type !== "ArrowFunctionExpression") {
|
|
46
|
+
throw new Error("Expecting an arrow function");
|
|
61
47
|
}
|
|
62
48
|
|
|
63
|
-
|
|
64
|
-
paramSet.set(firstOuterParam, outerParameter);
|
|
65
|
-
}
|
|
49
|
+
let name = "____x";
|
|
66
50
|
|
|
67
51
|
let body = node.body;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const firstTarget = body.params[0];
|
|
52
|
+
let firstTarget: (bpe.Identifier | bpe.Pattern | bpe.RestElement);
|
|
53
|
+
if (body.type === "ArrowFunctionExpression") {
|
|
54
|
+
firstTarget = body.params[0];
|
|
55
|
+
if (firstTarget) {
|
|
73
56
|
|
|
74
|
-
|
|
57
|
+
if (firstTarget.type !== "Identifier") {
|
|
58
|
+
throw new Error("Expecting an identifier");
|
|
59
|
+
}
|
|
60
|
+
name = firstTarget.name;
|
|
61
|
+
}
|
|
62
|
+
for (const iterator of node.params) {
|
|
63
|
+
if (iterator.type !== "Identifier") {
|
|
64
|
+
throw new Error("Expecting an identifier");
|
|
65
|
+
}
|
|
66
|
+
if (!firstOuterParam && outerParameter) {
|
|
67
|
+
firstOuterParam = iterator.name;
|
|
68
|
+
paramSet.set(iterator.name, outerParameter);
|
|
69
|
+
params.push(outerParameter);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const p1 = ParameterExpression.create({ name: iterator.name });
|
|
73
|
+
paramSet.set(iterator.name, p1);
|
|
74
|
+
params.push(p1);
|
|
75
|
+
}
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
if (outerParameter && firstOuterParam) {
|
|
78
|
+
paramSet.set(firstOuterParam, outerParameter);
|
|
79
|
+
}
|
|
80
|
+
body = body.body;
|
|
81
|
+
} else {
|
|
82
|
+
firstTarget = node.params[0];
|
|
83
|
+
if (firstTarget) {
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
if (firstTarget.type !== "Identifier") {
|
|
86
|
+
throw new Error("Expecting an identifier");
|
|
87
|
+
}
|
|
88
|
+
name = firstTarget.name;
|
|
89
|
+
}
|
|
90
|
+
const lastParam = node.params.at(-1) as any as bpe.Identifier;
|
|
91
|
+
if (lastParam) {
|
|
92
|
+
if (outerParameter) {
|
|
93
|
+
paramSet.set(lastParam.name, outerParameter);
|
|
94
|
+
} else {
|
|
95
|
+
const p1 = ParameterExpression.create({ name: lastParam.name });
|
|
96
|
+
paramSet.set(lastParam.name, p1);
|
|
97
|
+
params.push(p1);
|
|
98
|
+
}
|
|
80
99
|
}
|
|
81
|
-
|
|
100
|
+
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
|
|
85
|
-
target ??= ParameterExpression.create({ name});
|
|
86
104
|
|
|
87
|
-
|
|
105
|
+
target ??= ParameterExpression.create({ name});
|
|
88
106
|
|
|
89
107
|
const visitor = new this(paramSet, target, name);
|
|
90
108
|
return {
|
|
@@ -43,11 +43,11 @@ export default class WorkflowStorage {
|
|
|
43
43
|
|
|
44
44
|
getPendingWorkflowCount({ taskGroup = void 0 } = { }) {
|
|
45
45
|
const db = new WorkflowDbContext(this.driver);
|
|
46
|
-
let q = db.workflows.where(void 0, (p) =>
|
|
46
|
+
let q = db.workflows.where(void 0, (x, p) => x.isWorkflow === true
|
|
47
47
|
&& x.state === "queued"
|
|
48
48
|
);
|
|
49
49
|
if (taskGroup) {
|
|
50
|
-
q = q.where({ taskGroup}, (p) =>
|
|
50
|
+
q = q.where({ taskGroup}, (x, p) => x.taskGroup === p.taskGroup);
|
|
51
51
|
}
|
|
52
52
|
return q.count();
|
|
53
53
|
}
|
|
@@ -56,13 +56,13 @@ export default class WorkflowStorage {
|
|
|
56
56
|
const now = this.clock.utcNow;
|
|
57
57
|
const db = new WorkflowDbContext(this.driver);
|
|
58
58
|
const { group, deferSeconds } = throttle;
|
|
59
|
-
const w = await db.workflows.where({ group, now }, (p) =>
|
|
59
|
+
const w = await db.workflows.where({ group, now }, (x, p) => x.throttleGroup === p.group
|
|
60
60
|
&& x.state !== "failed"
|
|
61
61
|
&& x.state !== "done"
|
|
62
62
|
&& x.isWorkflow === true
|
|
63
63
|
&& x.eta >= Sql.cast.asDateTime(p.now)
|
|
64
64
|
)
|
|
65
|
-
.orderByDescending(void 0, (p) =>
|
|
65
|
+
.orderByDescending(void 0, (x, p) => x.queued)
|
|
66
66
|
.first();
|
|
67
67
|
if (w) {
|
|
68
68
|
w.eta = DateTime.from(w.eta).addSeconds(deferSeconds);
|
|
@@ -76,9 +76,9 @@ export default class WorkflowStorage {
|
|
|
76
76
|
|
|
77
77
|
const db = new WorkflowDbContext(this.driver);
|
|
78
78
|
|
|
79
|
-
const last = await db.workflows.where(throttle, (p) =>
|
|
79
|
+
const last = await db.workflows.where(throttle, (x, p) => x.throttleGroup === p.group
|
|
80
80
|
&& x.isWorkflow === true)
|
|
81
|
-
.orderByDescending(void 0, (p) =>
|
|
81
|
+
.orderByDescending(void 0, (x, p) => x.queued)
|
|
82
82
|
.first();
|
|
83
83
|
|
|
84
84
|
if (last) {
|
|
@@ -143,12 +143,12 @@ export default class WorkflowStorage {
|
|
|
143
143
|
if (text) {
|
|
144
144
|
// save..
|
|
145
145
|
await db.workflows.statements.update({ extra: text }, { id });
|
|
146
|
-
// await db.workflows.where({ id }, (p) =>
|
|
147
|
-
// .update({ text}, (p) => (
|
|
146
|
+
// await db.workflows.where({ id }, (x, p) => x.id === p.id)
|
|
147
|
+
// .update({ text}, (x, p) => ({ extra: p.text }));
|
|
148
148
|
return text;
|
|
149
149
|
}
|
|
150
|
-
const item = await db.workflows.where({ id }, (p) =>
|
|
151
|
-
.select(void 0, (p) => (
|
|
150
|
+
const item = await db.workflows.where({ id }, (x, p) => x.id === p.id)
|
|
151
|
+
.select(void 0, (x, p) => ({ extra: x.extra}) ).first();
|
|
152
152
|
return item?.extra;
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -162,9 +162,9 @@ export default class WorkflowStorage {
|
|
|
162
162
|
|
|
163
163
|
// if parent workflows exist
|
|
164
164
|
// change eta to recent ones...
|
|
165
|
-
const hasPendingChildren = await db.workflows.where({ id }, (p) =>
|
|
165
|
+
const hasPendingChildren = await db.workflows.where({ id }, (x, p) => x.parentID === p.id && x.isWorkflow === true)
|
|
166
166
|
.limit(1000)
|
|
167
|
-
.update(void 0, (p) => (
|
|
167
|
+
.update(void 0, (x, p) => ({
|
|
168
168
|
eta: Sql.date.addMinutes(Sql.date.now(),-1)
|
|
169
169
|
}));
|
|
170
170
|
|
|
@@ -172,16 +172,16 @@ export default class WorkflowStorage {
|
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
await db.workflows.where({ id}, (p) =>
|
|
175
|
+
await db.workflows.where({ id}, (x, p) => x.parentID === p.id)
|
|
176
176
|
.limit(1000)
|
|
177
|
-
.delete({ id }, (p) =>
|
|
177
|
+
.delete({ id }, (x, p) => x.parentID === p.id);
|
|
178
178
|
|
|
179
|
-
if (await db.workflows.where({ id}, (p) =>
|
|
179
|
+
if (await db.workflows.where({ id}, (x, p) => x.parentID === p.id).some()) {
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
await db.workflows.asQuery()
|
|
184
|
-
.delete({ id}, (p) =>
|
|
184
|
+
.delete({ id}, (x, p) => x.id === p.id);
|
|
185
185
|
|
|
186
186
|
return true;
|
|
187
187
|
}
|
|
@@ -255,17 +255,17 @@ export default class WorkflowStorage {
|
|
|
255
255
|
const uuid = randomUUID();
|
|
256
256
|
|
|
257
257
|
const items = await db.workflows
|
|
258
|
-
.where({now, taskGroup}, (p) =>
|
|
258
|
+
.where({now, taskGroup}, (x, p) => x.eta <= p.now
|
|
259
259
|
&& ( x.lockedTTL === null
|
|
260
260
|
|| x.lockedTTL <= p.now
|
|
261
261
|
)
|
|
262
262
|
&& x.isWorkflow === true
|
|
263
263
|
&& x.taskGroup === p.taskGroup)
|
|
264
|
-
.orderBy({}, (p) =>
|
|
265
|
-
.thenBy({}, (p) =>
|
|
264
|
+
.orderBy({}, (x, p) => x.eta)
|
|
265
|
+
.thenBy({}, (x, p) => x.priority)
|
|
266
266
|
.limit(20)
|
|
267
267
|
.withSignal(signal)
|
|
268
|
-
.updateSelect({ uuid}, (p) => (
|
|
268
|
+
.updateSelect({ uuid}, (x, p) => ({
|
|
269
269
|
lockedTTL: Sql.date.addSeconds(Sql.date.now(), 15),
|
|
270
270
|
lockToken: p.uuid
|
|
271
271
|
}));
|