@entity-access/entity-access 1.0.548 → 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/model/EntityQuery.d.ts +11 -11
- package/dist/model/EntityQuery.d.ts.map +1 -1
- package/dist/model/EntityQuery.js +36 -0
- 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 +28 -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/model/EntityQuery.ts +50 -12
- package/src/model/EntitySource.ts +7 -5
- package/src/model/IFilterWithParameter.ts +30 -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,10 +18,10 @@ let WorkflowStorage = class WorkflowStorage {
|
|
|
18
18
|
}
|
|
19
19
|
getPendingWorkflowCount({ taskGroup = void 0 } = {}) {
|
|
20
20
|
const db = new WorkflowDbContext(this.driver);
|
|
21
|
-
let q = db.workflows.where(void 0, (p) =>
|
|
21
|
+
let q = db.workflows.where(void 0, (x, p) => x.isWorkflow === true
|
|
22
22
|
&& x.state === "queued");
|
|
23
23
|
if (taskGroup) {
|
|
24
|
-
q = q.where({ taskGroup }, (p) =>
|
|
24
|
+
q = q.where({ taskGroup }, (x, p) => x.taskGroup === p.taskGroup);
|
|
25
25
|
}
|
|
26
26
|
return q.count();
|
|
27
27
|
}
|
|
@@ -29,12 +29,12 @@ let WorkflowStorage = class WorkflowStorage {
|
|
|
29
29
|
const now = this.clock.utcNow;
|
|
30
30
|
const db = new WorkflowDbContext(this.driver);
|
|
31
31
|
const { group, deferSeconds } = throttle;
|
|
32
|
-
const w = await db.workflows.where({ group, now }, (p) =>
|
|
32
|
+
const w = await db.workflows.where({ group, now }, (x, p) => x.throttleGroup === p.group
|
|
33
33
|
&& x.state !== "failed"
|
|
34
34
|
&& x.state !== "done"
|
|
35
35
|
&& x.isWorkflow === true
|
|
36
36
|
&& x.eta >= Sql.cast.asDateTime(p.now))
|
|
37
|
-
.orderByDescending(void 0, (p) =>
|
|
37
|
+
.orderByDescending(void 0, (x, p) => x.queued)
|
|
38
38
|
.first();
|
|
39
39
|
if (w) {
|
|
40
40
|
w.eta = DateTime.from(w.eta).addSeconds(deferSeconds);
|
|
@@ -44,9 +44,9 @@ let WorkflowStorage = class WorkflowStorage {
|
|
|
44
44
|
}
|
|
45
45
|
async getNextEta(throttle) {
|
|
46
46
|
const db = new WorkflowDbContext(this.driver);
|
|
47
|
-
const last = await db.workflows.where(throttle, (p) =>
|
|
47
|
+
const last = await db.workflows.where(throttle, (x, p) => x.throttleGroup === p.group
|
|
48
48
|
&& x.isWorkflow === true)
|
|
49
|
-
.orderByDescending(void 0, (p) =>
|
|
49
|
+
.orderByDescending(void 0, (x, p) => x.queued)
|
|
50
50
|
.first();
|
|
51
51
|
if (last) {
|
|
52
52
|
if (throttle.maxPerSecond <= 0) {
|
|
@@ -105,12 +105,12 @@ let WorkflowStorage = class WorkflowStorage {
|
|
|
105
105
|
if (text) {
|
|
106
106
|
// save..
|
|
107
107
|
await db.workflows.statements.update({ extra: text }, { id });
|
|
108
|
-
// await db.workflows.where({ id }, (p) =>
|
|
109
|
-
// .update({ text}, (p) => (
|
|
108
|
+
// await db.workflows.where({ id }, (x, p) => x.id === p.id)
|
|
109
|
+
// .update({ text}, (x, p) => ({ extra: p.text }));
|
|
110
110
|
return text;
|
|
111
111
|
}
|
|
112
|
-
const item = await db.workflows.where({ id }, (p) =>
|
|
113
|
-
.select(void 0, (p) => (
|
|
112
|
+
const item = await db.workflows.where({ id }, (x, p) => x.id === p.id)
|
|
113
|
+
.select(void 0, (x, p) => ({ extra: x.extra })).first();
|
|
114
114
|
return item?.extra;
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -122,22 +122,22 @@ let WorkflowStorage = class WorkflowStorage {
|
|
|
122
122
|
const db = new WorkflowDbContext(this.driver);
|
|
123
123
|
// if parent workflows exist
|
|
124
124
|
// change eta to recent ones...
|
|
125
|
-
const hasPendingChildren = await db.workflows.where({ id }, (p) =>
|
|
125
|
+
const hasPendingChildren = await db.workflows.where({ id }, (x, p) => x.parentID === p.id && x.isWorkflow === true)
|
|
126
126
|
.limit(1000)
|
|
127
|
-
.update(void 0, (p) => (
|
|
127
|
+
.update(void 0, (x, p) => ({
|
|
128
128
|
eta: Sql.date.addMinutes(Sql.date.now(), -1)
|
|
129
129
|
}));
|
|
130
130
|
if (hasPendingChildren) {
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
|
-
await db.workflows.where({ id }, (p) =>
|
|
133
|
+
await db.workflows.where({ id }, (x, p) => x.parentID === p.id)
|
|
134
134
|
.limit(1000)
|
|
135
|
-
.delete({ id }, (p) =>
|
|
136
|
-
if (await db.workflows.where({ id }, (p) =>
|
|
135
|
+
.delete({ id }, (x, p) => x.parentID === p.id);
|
|
136
|
+
if (await db.workflows.where({ id }, (x, p) => x.parentID === p.id).some()) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
await db.workflows.asQuery()
|
|
140
|
-
.delete({ id }, (p) =>
|
|
140
|
+
.delete({ id }, (x, p) => x.id === p.id);
|
|
141
141
|
return true;
|
|
142
142
|
}
|
|
143
143
|
async save(state) {
|
|
@@ -201,16 +201,16 @@ let WorkflowStorage = class WorkflowStorage {
|
|
|
201
201
|
// const q = this.lockQuery;
|
|
202
202
|
const uuid = randomUUID();
|
|
203
203
|
const items = await db.workflows
|
|
204
|
-
.where({ now, taskGroup }, (p) =>
|
|
204
|
+
.where({ now, taskGroup }, (x, p) => x.eta <= p.now
|
|
205
205
|
&& (x.lockedTTL === null
|
|
206
206
|
|| x.lockedTTL <= p.now)
|
|
207
207
|
&& x.isWorkflow === true
|
|
208
208
|
&& x.taskGroup === p.taskGroup)
|
|
209
|
-
.orderBy({}, (p) =>
|
|
210
|
-
.thenBy({}, (p) =>
|
|
209
|
+
.orderBy({}, (x, p) => x.eta)
|
|
210
|
+
.thenBy({}, (x, p) => x.priority)
|
|
211
211
|
.limit(20)
|
|
212
212
|
.withSignal(signal)
|
|
213
|
-
.updateSelect({ uuid }, (p) => (
|
|
213
|
+
.updateSelect({ uuid }, (x, p) => ({
|
|
214
214
|
lockedTTL: Sql.date.addSeconds(Sql.date.now(), 15),
|
|
215
215
|
lockToken: p.uuid
|
|
216
216
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkflowStorage.js","sourceRoot":"","sources":["../../src/workflows/WorkflowStorage.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,MAAM,EAAE,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EA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B,CAAC;QACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBAClB,SAAS;YACb,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAQ;QACf,MAAM,EAAE,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,EAAE,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;QACrC,MAAM,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IACnG,CAAC;CAEJ,CAAA;AAjQoB,eAAe;IADnC,iBAAiB;IAMT,WAAA,MAAM,CAAA;IAEN,WAAA,MAAM,CAAA;qCADS,UAAU;QAEH,aAAa;GARvB,eAAe,CAiQnC;eAjQoB,eAAe"}
|
package/package.json
CHANGED
|
@@ -50,24 +50,24 @@ export default class QueryCompiler {
|
|
|
50
50
|
this.sqlMethodTransformer = sqlMethodTransformer;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
public transform(fx: (
|
|
53
|
+
public transform(fx: (x: any, p: any) => any, target?: ParameterExpression, outerParameter?: ParameterExpression) {
|
|
54
54
|
const key = `${fx.toString()}-${target?.id ?? '_'}-${outerParameter?.id ?? '_'}`;
|
|
55
55
|
return this.parserCache.getOrCreate(key, this, (k, self) => self.arrowToExpression.transform(fx, target, outerParameter));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
public execute<P = any, T = any>(parameters: P, fx: (
|
|
58
|
+
public execute<P = any, T = any>(parameters: P, fx: (x: T, p: P) => any, source?: EntityQuery) {
|
|
59
59
|
const { params, target , body } = this.transform(fx, source?.selectStatement.sourceParameter);
|
|
60
60
|
const exp = new this.expressionToSql(source, params[0], target, this);
|
|
61
61
|
const query = exp.visit(body);
|
|
62
62
|
return this.invoke(query, parameters);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
public compile(source: EntityQuery, fx: (p) =>
|
|
65
|
+
public compile(source: EntityQuery, fx: (x, p) => any) {
|
|
66
66
|
const { params, target , body } = this.transform(fx, source?.selectStatement.sourceParameter);
|
|
67
67
|
return { params, target, body };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public compileToSql( source: EntityQuery , fx: (p) =>
|
|
70
|
+
public compileToSql( source: EntityQuery , fx: (x, p) => any) {
|
|
71
71
|
const { params, target , body } = this.transform(fx, source?.selectStatement.sourceParameter);
|
|
72
72
|
const exp = new this.expressionToSql(source, params[0], target, this);
|
|
73
73
|
const textQuery = exp.visit(body);
|
package/src/model/EntityQuery.ts
CHANGED
|
@@ -32,7 +32,7 @@ export default class EntityQuery<T = any>
|
|
|
32
32
|
return p as EntityQuery;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
select(p: any, fx
|
|
35
|
+
select(p: any, fx?: any): any {
|
|
36
36
|
return this.map(p, fx);
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -63,7 +63,11 @@ export default class EntityQuery<T = any>
|
|
|
63
63
|
}, this.signal);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
selectView(parameters: any, fx
|
|
66
|
+
selectView(parameters: any, fx?: any): any {
|
|
67
|
+
if (fx === void 0) {
|
|
68
|
+
fx = parameters;
|
|
69
|
+
parameters = void 0;
|
|
70
|
+
}
|
|
67
71
|
const exp = this.context.driver.compiler.compile(this, fx);
|
|
68
72
|
const p1 = exp.params[0];
|
|
69
73
|
if (p1) {
|
|
@@ -131,7 +135,11 @@ export default class EntityQuery<T = any>
|
|
|
131
135
|
});
|
|
132
136
|
}
|
|
133
137
|
|
|
134
|
-
map(parameters: any, fx
|
|
138
|
+
map(parameters: any, fx?: any): any {
|
|
139
|
+
if (fx === void 0) {
|
|
140
|
+
fx = parameters;
|
|
141
|
+
parameters = void 0;
|
|
142
|
+
}
|
|
135
143
|
const q = this.extend(parameters, fx, (select, body) => {
|
|
136
144
|
const fields = [] as Expression[];
|
|
137
145
|
switch(body.type) {
|
|
@@ -159,15 +167,18 @@ export default class EntityQuery<T = any>
|
|
|
159
167
|
return new EntityQuery({ ... this, signal });
|
|
160
168
|
}
|
|
161
169
|
|
|
162
|
-
thenBy(parameters: any, fx
|
|
170
|
+
thenBy(parameters: any, fx?: any): any {
|
|
163
171
|
return this.orderBy(parameters, fx);
|
|
164
172
|
}
|
|
165
|
-
thenByDescending(parameters: any, fx
|
|
173
|
+
thenByDescending(parameters: any, fx?: any) {
|
|
166
174
|
return this.orderByDescending(parameters, fx);
|
|
167
175
|
}
|
|
168
176
|
|
|
169
|
-
where
|
|
170
|
-
|
|
177
|
+
where(parameters: any, fx?: any): any {
|
|
178
|
+
if (fx === void 0) {
|
|
179
|
+
fx = parameters;
|
|
180
|
+
parameters = void 0;
|
|
181
|
+
}
|
|
171
182
|
return this.extend(parameters, fx, (select, body) => ({
|
|
172
183
|
... select,
|
|
173
184
|
where: select.where ? Expression.logicalAnd(select.where, body): body
|
|
@@ -182,8 +193,12 @@ export default class EntityQuery<T = any>
|
|
|
182
193
|
});
|
|
183
194
|
}
|
|
184
195
|
|
|
185
|
-
union(p, fx): any {
|
|
196
|
+
union(p, fx?): any {
|
|
186
197
|
|
|
198
|
+
if (fx === void 0) {
|
|
199
|
+
fx = p;
|
|
200
|
+
p = void 0;
|
|
201
|
+
}
|
|
187
202
|
const limit = this.selectStatement.limit;
|
|
188
203
|
const offset = this.selectStatement.offset;
|
|
189
204
|
|
|
@@ -321,7 +336,11 @@ export default class EntityQuery<T = any>
|
|
|
321
336
|
});
|
|
322
337
|
}
|
|
323
338
|
|
|
324
|
-
async delete(p, f): Promise<number> {
|
|
339
|
+
async delete(p, f?): Promise<number> {
|
|
340
|
+
if (f === void 0) {
|
|
341
|
+
f = p;
|
|
342
|
+
p = void 0;
|
|
343
|
+
}
|
|
325
344
|
if (f) {
|
|
326
345
|
return this.where(p, f).delete(void 0, void 0);
|
|
327
346
|
}
|
|
@@ -367,6 +386,13 @@ export default class EntityQuery<T = any>
|
|
|
367
386
|
}
|
|
368
387
|
|
|
369
388
|
async updateSelect(p?, f?): Promise<T[]> {
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
if (f === void 0) {
|
|
392
|
+
f = p;
|
|
393
|
+
p = void 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
370
396
|
const updateStatement = this.getUpdateStatement(p, f, true);
|
|
371
397
|
|
|
372
398
|
await using scope = new AsyncDisposableScope();
|
|
@@ -404,6 +430,10 @@ export default class EntityQuery<T = any>
|
|
|
404
430
|
|
|
405
431
|
async update(p?, f?): Promise<number> {
|
|
406
432
|
|
|
433
|
+
if (f === void 0) {
|
|
434
|
+
f = p;
|
|
435
|
+
p = void 0;
|
|
436
|
+
}
|
|
407
437
|
const updateStatement = this.getUpdateStatement(p, f);
|
|
408
438
|
|
|
409
439
|
const session = this.context.logger ?? Logger.nullLogger;
|
|
@@ -419,7 +449,7 @@ export default class EntityQuery<T = any>
|
|
|
419
449
|
}
|
|
420
450
|
}
|
|
421
451
|
|
|
422
|
-
getUpdateStatement(p
|
|
452
|
+
getUpdateStatement(p, f, returnEntity = false) {
|
|
423
453
|
|
|
424
454
|
if (f) {
|
|
425
455
|
return this.extend(p, f, (select, body) => {
|
|
@@ -666,7 +696,11 @@ export default class EntityQuery<T = any>
|
|
|
666
696
|
toQuery(): { text: string; values: any[]; } {
|
|
667
697
|
return this.context.driver.compiler.compileExpression(this, this.selectStatement);
|
|
668
698
|
}
|
|
669
|
-
orderBy(parameters: any, fx
|
|
699
|
+
orderBy(parameters: any, fx?: any): any {
|
|
700
|
+
if (fx === void 0) {
|
|
701
|
+
fx = parameters;
|
|
702
|
+
parameters = void 0;
|
|
703
|
+
}
|
|
670
704
|
return this.extend(parameters, fx, (select, target) => ({
|
|
671
705
|
... select,
|
|
672
706
|
orderBy: select.orderBy
|
|
@@ -674,7 +708,11 @@ export default class EntityQuery<T = any>
|
|
|
674
708
|
: [OrderByExpression.create({ target})]
|
|
675
709
|
}));
|
|
676
710
|
}
|
|
677
|
-
orderByDescending(parameters: any, fx
|
|
711
|
+
orderByDescending(parameters: any, fx?: any): any {
|
|
712
|
+
if (fx === void 0) {
|
|
713
|
+
fx = parameters;
|
|
714
|
+
parameters = void 0;
|
|
715
|
+
}
|
|
678
716
|
const descending = true;
|
|
679
717
|
return this.extend(parameters, fx, (select, target) => ({
|
|
680
718
|
... select,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type EntityContext from "./EntityContext.js";
|
|
2
2
|
import type EntityType from "../entity-query/EntityType.js";
|
|
3
|
-
import type { IEntityQuery
|
|
3
|
+
import type { IEntityQuery } from "./IFilterWithParameter.js";
|
|
4
4
|
import { contextSymbol, modelSymbol, traceSymbol } from "../common/symbols/symbols.js";
|
|
5
5
|
import { Expression, ExpressionAs, Identifier, InsertStatement, TableLiteral } from "../query/ast/Expressions.js";
|
|
6
6
|
import { DirectSaveType } from "../drivers/base/BaseDriver.js";
|
|
@@ -358,7 +358,7 @@ export class EntitySource<T = any> {
|
|
|
358
358
|
filter.push(`x.${iterator.name} === p.${iterator.name}`);
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
-
return this.where(keys, `(p) =>
|
|
361
|
+
return this.where(keys, `(x, p) => ${filter.join(" && ")}` as any) as any;
|
|
362
362
|
// return q.first() as Promise<T>;
|
|
363
363
|
}
|
|
364
364
|
|
|
@@ -381,7 +381,7 @@ export class EntitySource<T = any> {
|
|
|
381
381
|
filter.push(`x.${fkColumn.name} === p.${relatedKeyColumn.name}`);
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
const query = `(p) =>
|
|
384
|
+
const query = `(x, p) => ${filter.join(" && ")}` as any;
|
|
385
385
|
// console.log(query);
|
|
386
386
|
|
|
387
387
|
return this.context.model.register(relatedEntity.typeClass)
|
|
@@ -444,8 +444,10 @@ export class EntitySource<T = any> {
|
|
|
444
444
|
return mode === "modify" ? events.modify(query) : events.filter(query);
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
-
public where
|
|
448
|
-
|
|
447
|
+
public where(fx: (x: T) => boolean): IEntityQuery<T>;
|
|
448
|
+
public where<P>(parameter: P, fx: (x: T, p: P) => boolean): IEntityQuery<T>;
|
|
449
|
+
public where<P>(parameter?: any, fx?: unknown) {
|
|
450
|
+
return this.asQuery().where(parameter, fx as any) as IEntityQuery<T>;
|
|
449
451
|
}
|
|
450
452
|
|
|
451
453
|
public asQuery() {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { IQueryResult } from "../drivers/base/BaseDriver.js";
|
|
2
2
|
import type { EntitySource } from "./EntitySource.js";
|
|
3
3
|
|
|
4
|
+
// export type IParamFunction<P, T, TR> = (x: T, p: P) => TR;
|
|
5
|
+
|
|
4
6
|
export type IFilterWithParameter<P = any, T = any> = (p: P) => (x: T) => boolean;
|
|
5
7
|
|
|
6
8
|
export type ILambdaExpression<P = any, T = any, TR = any> = [input: P, x: (p: P) => (s: T) => TR];
|
|
7
9
|
|
|
8
|
-
export type IFilterExpression<P = any, T = any> = [input: P,
|
|
10
|
+
export type IFilterExpression<P = any, T = any> = [input: P, fx: (x: T, p: P) => boolean];
|
|
9
11
|
|
|
10
12
|
export type IFieldsAsNumbers<T> = { [P in keyof T]: number };
|
|
11
13
|
|
|
@@ -17,8 +19,10 @@ export interface IBaseQuery<T> {
|
|
|
17
19
|
|
|
18
20
|
some(): Promise<boolean>;
|
|
19
21
|
|
|
20
|
-
select<
|
|
21
|
-
|
|
22
|
+
select<TR>(fx: (x: T) => TR): IBaseQuery<TR>;
|
|
23
|
+
select<P, TR>(parameters: P, fx: (x: T,p: P) => TR): IBaseQuery<TR>;
|
|
24
|
+
map<TR>(fx: (x: T) => TR): IBaseQuery<TR>;
|
|
25
|
+
map<P, TR>(parameters: P, fx: (x: T, p: P) => TR): IBaseQuery<TR>;
|
|
22
26
|
|
|
23
27
|
toArray(this: T extends object ? IBaseQuery<T> : never): Promise<T[]>;
|
|
24
28
|
|
|
@@ -28,37 +32,42 @@ export interface IBaseQuery<T> {
|
|
|
28
32
|
|
|
29
33
|
limit<DT>(this: DT, limit: number): DT;
|
|
30
34
|
offset<DT>(this: DT, offset: number): DT;
|
|
31
|
-
where<
|
|
35
|
+
where<DT>(this: DT, fx: (x: T) => boolean): DT;
|
|
36
|
+
where<P, DT>(this: DT, parameters: P, fx: (x: T,p: P) => boolean): DT;
|
|
37
|
+
union<DT>(this: DT, fx: (x: T) => boolean): DT;
|
|
32
38
|
union<P, DT>(this: DT, parameters: P, fx: (p: P) => (x: T) => boolean): DT;
|
|
33
|
-
selectView<
|
|
39
|
+
selectView<DT>(this: DT, fx: (x: T) => Partial<T>): DT;
|
|
40
|
+
selectView<P, DT>(this: DT, parameters: P, fx: (x: T, p: P) => Partial<T>): DT;
|
|
34
41
|
|
|
35
|
-
innerJoin<JT, DT>(this: DT, q1: IBaseQuery<JT>, fx: (
|
|
42
|
+
innerJoin<JT, DT>(this: DT, q1: IBaseQuery<JT>, fx: (x: T, p: JT) => boolean): DT;
|
|
36
43
|
|
|
37
|
-
exists<JT, DT>(this: DT, q1: IBaseQuery<JT>, fx: (
|
|
44
|
+
exists<JT, DT>(this: DT, q1: IBaseQuery<JT>, fx: (x: T, p: JT) => boolean): DT;
|
|
38
45
|
|
|
39
46
|
count(): Promise<number>;
|
|
40
47
|
count<P>(parameters: P, fx: (p: P) => (x: T) => boolean): Promise<number>;
|
|
41
48
|
|
|
42
49
|
slice<DT>(this:DT, start?: number, end?: number): DT;
|
|
43
50
|
|
|
44
|
-
sum(): Promise<number>;
|
|
45
|
-
sum<P>(parameters: P, fx: (
|
|
46
|
-
sum<P, TR>(parameters: P, fx: (p: P) => (x: T) => TR): Promise<IFieldsAsNumbers<TR>>;
|
|
51
|
+
sum(fx?: (x: T) => number): Promise<number>;
|
|
52
|
+
sum<P, TR>(parameters: P, fx: (x: T, p: P) => TR): Promise<IFieldsAsNumbers<TR>>;
|
|
47
53
|
|
|
48
54
|
|
|
49
55
|
withSignal<DT>(this:DT, signal: AbortSignal): DT;
|
|
50
56
|
|
|
51
57
|
include<TR>(fx: (x: T) => TR | TR[]): IBaseQuery<T>;
|
|
52
58
|
|
|
53
|
-
update
|
|
54
|
-
|
|
59
|
+
update(fx: (x:T) => Partial<T>): Promise<number>;
|
|
60
|
+
update<P>(parameters: P, fx: (x:T, p: P) => Partial<T>): Promise<number>;
|
|
61
|
+
updateSelect(this: T extends object ? IBaseQuery<T> : never, fx: (x:T) => Partial<T>): Promise<T[]>;
|
|
62
|
+
updateSelect<P>(this: T extends object ? IBaseQuery<T> : never, parameters: P, fx: (x:T, p: P) => Partial<T>): Promise<T[]>;
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
65
|
* Warning !! Be careful, this will delete rows from the database and neither soft delete nor any other events will be invoked.
|
|
58
66
|
* @param parameters parameters to supply
|
|
59
67
|
* @param fx filter expression
|
|
60
68
|
*/
|
|
61
|
-
delete
|
|
69
|
+
delete(fx: (x: T) => boolean): Promise<number>;
|
|
70
|
+
delete<P>(parameters: P, fx: (x: T, p: P) => boolean): Promise<number>;
|
|
62
71
|
|
|
63
72
|
trace<DT>(this: DT, tracer: (text: string) => void): DT;
|
|
64
73
|
|
|
@@ -75,12 +84,16 @@ export interface IBaseQuery<T> {
|
|
|
75
84
|
|
|
76
85
|
export interface IOrderedEntityQuery<T> extends IBaseQuery<T> {
|
|
77
86
|
|
|
78
|
-
thenBy
|
|
79
|
-
|
|
87
|
+
thenBy(fx: (x: T) => any): IOrderedEntityQuery<T>;
|
|
88
|
+
thenBy<P>(parameters: P, fx: (x: T, p: P) => any): IOrderedEntityQuery<T>;
|
|
89
|
+
thenByDescending(fx: (x: T) => any): IOrderedEntityQuery<T>;
|
|
90
|
+
thenByDescending<P>(parameters: P, fx: (x: T, p: P) => any): IOrderedEntityQuery<T>;
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
export interface IEntityQuery<T> extends IBaseQuery<T> {
|
|
83
94
|
|
|
84
|
-
orderBy
|
|
85
|
-
|
|
95
|
+
orderBy(fx: (x: T) => any): IOrderedEntityQuery<T>;
|
|
96
|
+
orderBy<P>(parameters: P, fx: (x: T, p: P) => any): IOrderedEntityQuery<T>;
|
|
97
|
+
orderByDescending(fx: (x: T) => any): IOrderedEntityQuery<T>;
|
|
98
|
+
orderByDescending<P>(parameters: P, fx: (x: T, p: P) => any): IOrderedEntityQuery<T>;
|
|
86
99
|
}
|
|
@@ -184,7 +184,7 @@ export default class ChangeEntry<T = any> implements IChanges {
|
|
|
184
184
|
filter.push(`x.${fkColumn.name} === p.${relatedKeyColumn.name}`);
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
const query = `(p) =>
|
|
187
|
+
const query = `(x, p) => ${filter.join(" && ")}` as any;
|
|
188
188
|
// console.log(query);
|
|
189
189
|
|
|
190
190
|
await context.model.register(relatedEntity.typeClass)
|
|
@@ -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 {
|