agentlang 0.7.9 → 0.7.11
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/out/api/http.d.ts.map +1 -1
- package/out/api/http.js +8 -1
- package/out/api/http.js.map +1 -1
- package/out/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +33 -2
- package/out/cli/main.js.map +1 -1
- package/out/extension/main.cjs +250 -250
- package/out/extension/main.cjs.map +2 -2
- package/out/language/agentlang-validator.d.ts +1 -2
- package/out/language/agentlang-validator.d.ts.map +1 -1
- package/out/language/agentlang-validator.js +0 -39
- package/out/language/agentlang-validator.js.map +1 -1
- package/out/language/generated/ast.d.ts +62 -11
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +75 -3
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.d.ts.map +1 -1
- package/out/language/generated/grammar.js +758 -239
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +1370 -824
- package/out/language/main.cjs.map +4 -4
- package/out/language/parser.d.ts +1 -0
- package/out/language/parser.d.ts.map +1 -1
- package/out/language/parser.js +44 -7
- package/out/language/parser.js.map +1 -1
- package/out/language/syntax.d.ts +1 -1
- package/out/language/syntax.d.ts.map +1 -1
- package/out/language/syntax.js +22 -13
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/api.d.ts +2 -0
- package/out/runtime/api.d.ts.map +1 -1
- package/out/runtime/api.js +5 -0
- package/out/runtime/api.js.map +1 -1
- package/out/runtime/auth/cognito.d.ts.map +1 -1
- package/out/runtime/auth/cognito.js +4 -4
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/defs.d.ts +5 -0
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +16 -0
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/exec-graph.js +1 -1
- package/out/runtime/exec-graph.js.map +1 -1
- package/out/runtime/interpreter.d.ts +6 -1
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +144 -112
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.d.ts +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +74 -27
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts +41 -11
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +238 -50
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +13 -6
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/auth.d.ts +2 -1
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +93 -3
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/modules/core.d.ts +7 -5
- package/out/runtime/modules/core.d.ts.map +1 -1
- package/out/runtime/modules/core.js +93 -16
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/monitor.d.ts.map +1 -1
- package/out/runtime/monitor.js +1 -0
- package/out/runtime/monitor.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +6 -1
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +2 -2
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.d.ts +19 -2
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +107 -21
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/dbutil.d.ts +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/dbutil.js +25 -3
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts +3 -2
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +80 -6
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/state.d.ts +58 -0
- package/out/runtime/state.d.ts.map +1 -1
- package/out/runtime/state.js +12 -0
- package/out/runtime/state.js.map +1 -1
- package/out/runtime/util.d.ts +1 -1
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +27 -13
- package/out/runtime/util.js.map +1 -1
- package/out/setupClassic.d.ts +98 -0
- package/out/setupClassic.d.ts.map +1 -0
- package/out/setupClassic.js +38 -0
- package/out/setupClassic.js.map +1 -0
- package/out/setupCommon.d.ts +2 -0
- package/out/setupCommon.d.ts.map +1 -0
- package/out/setupCommon.js +33 -0
- package/out/setupCommon.js.map +1 -0
- package/out/setupExtended.d.ts +40 -0
- package/out/setupExtended.d.ts.map +1 -0
- package/out/setupExtended.js +67 -0
- package/out/setupExtended.js.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +1 -1
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/package.json +187 -185
- package/src/api/http.ts +8 -0
- package/src/cli/main.ts +38 -2
- package/src/language/agentlang-validator.ts +1 -51
- package/src/language/agentlang.langium +17 -4
- package/src/language/generated/ast.ts +147 -13
- package/src/language/generated/grammar.ts +758 -239
- package/src/language/parser.ts +43 -8
- package/src/language/syntax.ts +25 -12
- package/src/runtime/api.ts +8 -0
- package/src/runtime/defs.ts +8 -0
- package/src/runtime/interpreter.ts +104 -76
- package/src/runtime/loader.ts +75 -25
- package/src/runtime/module.ts +194 -32
- package/src/runtime/modules/ai.ts +10 -4
- package/src/runtime/modules/auth.ts +1 -0
- package/src/runtime/modules/core.ts +99 -23
- package/src/runtime/monitor.ts +1 -0
- package/src/runtime/resolvers/interface.ts +9 -2
- package/src/runtime/resolvers/sqldb/database.ts +68 -17
- package/src/runtime/resolvers/sqldb/dbutil.ts +28 -6
- package/src/runtime/resolvers/sqldb/impl.ts +86 -14
- package/src/runtime/state.ts +14 -0
- package/src/runtime/util.ts +25 -12
- package/src/syntaxes/agentlang.monarch.ts +1 -1
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
} from '../../defs.js';
|
|
42
42
|
import { saveMigration } from '../../modules/core.js';
|
|
43
43
|
import { getAppSpec } from '../../loader.js';
|
|
44
|
+
import { WhereClause } from '../interface.js';
|
|
44
45
|
|
|
45
46
|
export let defaultDataSource: DataSource | undefined;
|
|
46
47
|
|
|
@@ -880,17 +881,30 @@ function objectToRawWhereClause(queryObj: object, queryVals: any, tableName?: st
|
|
|
880
881
|
}
|
|
881
882
|
}
|
|
882
883
|
|
|
884
|
+
export type QuerySpec = {
|
|
885
|
+
queryObj: object | undefined;
|
|
886
|
+
queryVals: object | undefined;
|
|
887
|
+
aggregates: Map<string, string> | undefined;
|
|
888
|
+
groupBy: string[] | undefined;
|
|
889
|
+
orderBy: string[] | undefined;
|
|
890
|
+
orderByDesc: 'DESC' | 'ASC';
|
|
891
|
+
joinClauses: JoinClause[] | undefined;
|
|
892
|
+
intoSpec: Map<string, string> | undefined;
|
|
893
|
+
whereClauses: WhereClause[] | undefined;
|
|
894
|
+
distinct: boolean;
|
|
895
|
+
};
|
|
896
|
+
|
|
883
897
|
export async function getMany(
|
|
884
898
|
tableName: string,
|
|
885
|
-
|
|
886
|
-
queryVals: object | undefined,
|
|
887
|
-
distinct: boolean,
|
|
899
|
+
querySpec: QuerySpec,
|
|
888
900
|
ctx: DbContext
|
|
889
901
|
): Promise<any> {
|
|
890
902
|
const alias: string = tableName.toLowerCase();
|
|
891
903
|
const queryStr: string = withNotDeletedClause(
|
|
892
904
|
alias,
|
|
893
|
-
queryObj !== undefined
|
|
905
|
+
querySpec.queryObj !== undefined
|
|
906
|
+
? objectToWhereClause(querySpec.queryObj, querySpec.queryVals, alias)
|
|
907
|
+
: ''
|
|
894
908
|
);
|
|
895
909
|
let ownersJoinCond: string[] | undefined;
|
|
896
910
|
let ot: string = '';
|
|
@@ -927,30 +941,54 @@ export async function getMany(
|
|
|
927
941
|
const qb: SelectQueryBuilder<any> = getDatasourceForTransaction(ctx.txnId)
|
|
928
942
|
.getRepository(tableName)
|
|
929
943
|
.createQueryBuilder();
|
|
944
|
+
const hasAggregates = querySpec.aggregates !== undefined;
|
|
945
|
+
if (hasAggregates) {
|
|
946
|
+
qb.select([]);
|
|
947
|
+
querySpec.aggregates?.forEach((f: string, n: string) => {
|
|
948
|
+
qb.addSelect(f, n);
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
if (querySpec.groupBy !== undefined) {
|
|
952
|
+
querySpec.groupBy.forEach((gb: string) => {
|
|
953
|
+
qb.addGroupBy(gb);
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
if (querySpec.orderBy !== undefined) {
|
|
957
|
+
querySpec.orderBy.forEach((ob: string) => {
|
|
958
|
+
qb.addOrderBy(ob, querySpec.orderByDesc);
|
|
959
|
+
});
|
|
960
|
+
}
|
|
930
961
|
if (ownersJoinCond) {
|
|
931
962
|
qb.innerJoin(ot, otAlias, ownersJoinCond.join(' AND '));
|
|
932
963
|
}
|
|
933
|
-
if (distinct) {
|
|
964
|
+
if (querySpec.distinct) {
|
|
934
965
|
qb.distinct(true);
|
|
935
966
|
}
|
|
936
|
-
qb.where(queryStr, queryVals);
|
|
937
|
-
return await qb.
|
|
967
|
+
qb.where(queryStr, querySpec.queryVals);
|
|
968
|
+
if (hasAggregates) return await qb.getRawMany();
|
|
969
|
+
else return await qb.getMany();
|
|
938
970
|
}
|
|
939
971
|
|
|
940
972
|
export async function getManyByJoin(
|
|
941
973
|
tableName: string,
|
|
942
|
-
|
|
943
|
-
queryVals: object | undefined,
|
|
944
|
-
joinClauses: JoinClause[],
|
|
945
|
-
intoSpec: Map<string, string>,
|
|
946
|
-
distinct: boolean,
|
|
974
|
+
querySpec: QuerySpec,
|
|
947
975
|
ctx: DbContext
|
|
948
976
|
): Promise<any> {
|
|
949
977
|
const alias: string = tableName.toLowerCase();
|
|
950
|
-
|
|
978
|
+
let queryStr: string = withNotDeletedClause(
|
|
951
979
|
alias,
|
|
952
|
-
queryObj !== undefined
|
|
980
|
+
querySpec.queryObj !== undefined
|
|
981
|
+
? objectToRawWhereClause(querySpec.queryObj, querySpec.queryVals, alias)
|
|
982
|
+
: ''
|
|
953
983
|
);
|
|
984
|
+
if (querySpec.whereClauses) {
|
|
985
|
+
const qs = new Array<string>();
|
|
986
|
+
querySpec.whereClauses.forEach((wc: WhereClause) => {
|
|
987
|
+
const v = isString(wc.qval) ? `'${wc.qval}'` : wc.qval;
|
|
988
|
+
qs.push(`${wc.attrName} ${wc.op} ${v}`);
|
|
989
|
+
});
|
|
990
|
+
queryStr = `${queryStr} AND ${qs.join(' AND ')}`;
|
|
991
|
+
}
|
|
954
992
|
let ot: string = '';
|
|
955
993
|
let otAlias: string = '';
|
|
956
994
|
if (!ctx.isPermitted()) {
|
|
@@ -961,7 +999,7 @@ export async function getManyByJoin(
|
|
|
961
999
|
if (!hasGlobalPerms) {
|
|
962
1000
|
ot = ownersTable(tableName);
|
|
963
1001
|
otAlias = ot.toLowerCase();
|
|
964
|
-
joinClauses
|
|
1002
|
+
querySpec.joinClauses?.push({
|
|
965
1003
|
tableName: otAlias,
|
|
966
1004
|
joinOn: [
|
|
967
1005
|
makeJoinOn(`${otAlias}.path`, `${alias}.${PathAttributeName}`),
|
|
@@ -972,7 +1010,7 @@ export async function getManyByJoin(
|
|
|
972
1010
|
}
|
|
973
1011
|
}
|
|
974
1012
|
const joinSql = new Array<string>();
|
|
975
|
-
joinClauses
|
|
1013
|
+
querySpec.joinClauses?.forEach((jc: JoinClause) => {
|
|
976
1014
|
const joinType = jc.joinType ? jc.joinType : 'inner join';
|
|
977
1015
|
joinSql.push(
|
|
978
1016
|
`${joinType} ${jc.tableName} as ${jc.tableName} on ${joinOnAsSql(jc.joinOn)} AND ${jc.tableName}.${DeletedFlagAttributeName} = false`
|
|
@@ -984,7 +1022,20 @@ export async function getManyByJoin(
|
|
|
984
1022
|
}
|
|
985
1023
|
}
|
|
986
1024
|
});
|
|
987
|
-
|
|
1025
|
+
if (querySpec.intoSpec === undefined) {
|
|
1026
|
+
throw new Error('SELECT-INTO pattern is missing');
|
|
1027
|
+
}
|
|
1028
|
+
const intos = intoSpecToSql(querySpec.intoSpec);
|
|
1029
|
+
const aggrs =
|
|
1030
|
+
querySpec.aggregates !== undefined ? intoSpecToSql(querySpec.aggregates) : undefined;
|
|
1031
|
+
const cols = aggrs ? `${intos}, ${aggrs}` : intos;
|
|
1032
|
+
let sql = `SELECT ${querySpec.distinct ? 'DISTINCT' : ''} ${cols} FROM ${tableName} ${joinSql.join('\n')} WHERE ${queryStr}`;
|
|
1033
|
+
if (querySpec.groupBy !== undefined) {
|
|
1034
|
+
sql = `${sql} GROUP BY ${querySpec.groupBy.join(', ')}`;
|
|
1035
|
+
}
|
|
1036
|
+
if (querySpec.orderBy !== undefined) {
|
|
1037
|
+
sql = `${sql} ORDER BY ${querySpec.orderBy.join(', ')} ${querySpec.orderByDesc}`;
|
|
1038
|
+
}
|
|
988
1039
|
logger.debug(`Join Query: ${sql}`);
|
|
989
1040
|
const qb = getDatasourceForTransaction(ctx.txnId).getRepository(tableName).manager;
|
|
990
1041
|
return await qb.query(sql);
|
|
@@ -28,8 +28,13 @@ import {
|
|
|
28
28
|
Module,
|
|
29
29
|
} from '../../module.js';
|
|
30
30
|
import { buildGraph } from '../../relgraph.js';
|
|
31
|
-
import { makeFqName } from '../../util.js';
|
|
32
|
-
import {
|
|
31
|
+
import { makeFqName, splitFqName, splitRefs } from '../../util.js';
|
|
32
|
+
import {
|
|
33
|
+
DeletedFlagAttributeName,
|
|
34
|
+
FkSpec,
|
|
35
|
+
ParentAttributeName,
|
|
36
|
+
PathAttributeName,
|
|
37
|
+
} from '../../defs.js';
|
|
33
38
|
|
|
34
39
|
export const DefaultVectorDimension = 1536;
|
|
35
40
|
|
|
@@ -50,6 +55,22 @@ export function asTableReference(moduleName: string, ref: string): string {
|
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
export function asColumnReference(n: string, tableName: string, entityName: string, entityFqName: string, moduleName: string, quoted: boolean = false): string {
|
|
59
|
+
const refs = splitRefs(n);
|
|
60
|
+
const rlen = refs.length
|
|
61
|
+
if (rlen == 1 || refs[0] == entityName || refs[0] == entityFqName) {
|
|
62
|
+
const r = rlen == 1 ? refs[0] : refs[1]
|
|
63
|
+
return quoted ? `"${tableName}"."${r}"` : `${tableName}.${r}`;
|
|
64
|
+
} else {
|
|
65
|
+
const p = splitFqName(refs[0]);
|
|
66
|
+
if (p.length == 2) {
|
|
67
|
+
return quoted ? `"${asTableReference(p[0], p[1])}"."${refs[1]}"` : `${asTableReference(p[0], p[1])}.${refs[1]}`;
|
|
68
|
+
} else {
|
|
69
|
+
return quoted ? `"${asTableReference(moduleName, p[0])}"."${refs[1]}"` : `${asTableReference(moduleName, p[0])}.${refs[1]}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
53
74
|
export function modulesAsDbSchema(): TableSchema[] {
|
|
54
75
|
const result: TableSchema[] = new Array<TableSchema>();
|
|
55
76
|
getModuleNames().forEach((n: string) => {
|
|
@@ -96,11 +117,11 @@ export function modulesAsOrmSchema(): OrmSchema {
|
|
|
96
117
|
}
|
|
97
118
|
});
|
|
98
119
|
entities.forEach((r: Record) => {
|
|
99
|
-
const fks = r.getFkAttributeSpecs()
|
|
120
|
+
const fks = r.getFkAttributeSpecs();
|
|
100
121
|
if (fks.length > 0) {
|
|
101
|
-
fkSpecs.push(...fks)
|
|
122
|
+
fkSpecs.push(...fks);
|
|
102
123
|
}
|
|
103
|
-
})
|
|
124
|
+
});
|
|
104
125
|
});
|
|
105
126
|
return { entities: ents, vectorEntities: vects, fkSpecs };
|
|
106
127
|
}
|
|
@@ -291,7 +312,8 @@ export function asSqlType(type: string): ColumnType {
|
|
|
291
312
|
t == 'url' ||
|
|
292
313
|
t == 'map' ||
|
|
293
314
|
t == 'any' ||
|
|
294
|
-
t == 'path'
|
|
315
|
+
t == 'path' ||
|
|
316
|
+
t == 'password'
|
|
295
317
|
)
|
|
296
318
|
return 'varchar';
|
|
297
319
|
else if (t == 'int') return 'integer';
|
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
splitFqName,
|
|
23
23
|
splitRefs,
|
|
24
24
|
} from '../../util.js';
|
|
25
|
-
import { JoinInfo, Resolver } from '../interface.js';
|
|
26
|
-
import { asTableReference } from './dbutil.js';
|
|
25
|
+
import { JoinInfo, Resolver, WhereClause } from '../interface.js';
|
|
26
|
+
import { asColumnReference, asTableReference } from './dbutil.js';
|
|
27
27
|
import {
|
|
28
28
|
getMany,
|
|
29
29
|
insertRow,
|
|
@@ -43,8 +43,9 @@ import {
|
|
|
43
43
|
JoinOn,
|
|
44
44
|
makeJoinOn,
|
|
45
45
|
getManyByJoin,
|
|
46
|
+
QuerySpec,
|
|
46
47
|
} from './database.js';
|
|
47
|
-
import { Environment } from '../../interpreter.js';
|
|
48
|
+
import { AggregateFunctionCall, Environment } from '../../interpreter.js';
|
|
48
49
|
import { OpenAIEmbeddings } from '@langchain/openai';
|
|
49
50
|
import { Embeddings } from '@langchain/core/embeddings';
|
|
50
51
|
import { DeletedFlagAttributeName, ParentAttributeName, PathAttributeName } from '../../defs.js';
|
|
@@ -164,6 +165,26 @@ export class SqlDbResolver extends Resolver {
|
|
|
164
165
|
return Instance.clone(inst).mergeAttributes(newAttrs);
|
|
165
166
|
}
|
|
166
167
|
|
|
168
|
+
private static normalizedAggregates(
|
|
169
|
+
inst: Instance,
|
|
170
|
+
tableName: string
|
|
171
|
+
): Map<string, string> | undefined {
|
|
172
|
+
if (inst.aggregates !== undefined) {
|
|
173
|
+
const entn = inst.name;
|
|
174
|
+
const entfqn = inst.getFqName();
|
|
175
|
+
const mn = inst.moduleName;
|
|
176
|
+
const result = new Map<string, string>();
|
|
177
|
+
inst.aggregates.forEach((f: AggregateFunctionCall, n: string) => {
|
|
178
|
+
const args = f.args.map((v: string) => {
|
|
179
|
+
return asColumnReference(v, tableName, entn, entfqn, mn, true);
|
|
180
|
+
});
|
|
181
|
+
result.set(n, `${f.name}(${args.join(', ')})`);
|
|
182
|
+
});
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
167
188
|
static EmptyResultSet: Array<Instance> = new Array<Instance>();
|
|
168
189
|
|
|
169
190
|
public override async queryInstances(
|
|
@@ -178,7 +199,32 @@ export class SqlDbResolver extends Resolver {
|
|
|
178
199
|
const ctx = this.getDbContext(fqName);
|
|
179
200
|
const qattrs: any = queryAll ? undefined : inst.queryAttributesAsObject();
|
|
180
201
|
const qvals: any = queryAll ? undefined : inst.queryAttributeValuesAsObject();
|
|
181
|
-
const
|
|
202
|
+
const groupBy = inst.groupBy
|
|
203
|
+
? inst.groupBy.map((gb: string) => {
|
|
204
|
+
return asColumnReference(gb, tableName, inst.name, fqName, inst.moduleName, true);
|
|
205
|
+
})
|
|
206
|
+
: undefined;
|
|
207
|
+
const orderBy = inst.orderBy
|
|
208
|
+
? inst.orderBy.map((ob: string) => {
|
|
209
|
+
return asColumnReference(ob, tableName, inst.name, fqName, inst.moduleName, true);
|
|
210
|
+
})
|
|
211
|
+
: undefined;
|
|
212
|
+
const orderByDesc = inst.orderByDesc ? 'DESC' : 'ASC';
|
|
213
|
+
const aggregates = SqlDbResolver.normalizedAggregates(inst, tableName);
|
|
214
|
+
const qspec: QuerySpec = {
|
|
215
|
+
queryObj: qattrs,
|
|
216
|
+
queryVals: qvals,
|
|
217
|
+
distinct,
|
|
218
|
+
groupBy,
|
|
219
|
+
orderBy,
|
|
220
|
+
orderByDesc,
|
|
221
|
+
aggregates,
|
|
222
|
+
joinClauses: undefined,
|
|
223
|
+
intoSpec: undefined,
|
|
224
|
+
whereClauses: undefined,
|
|
225
|
+
};
|
|
226
|
+
const readOnlyAttrs = inst.record.getWriteOnlyAttributes();
|
|
227
|
+
const rslt: any = await getMany(tableName, qspec, ctx);
|
|
182
228
|
if (rslt instanceof Array) {
|
|
183
229
|
result = new Array<Instance>();
|
|
184
230
|
rslt.forEach((r: object) => {
|
|
@@ -187,6 +233,9 @@ export class SqlDbResolver extends Resolver {
|
|
|
187
233
|
new Map(Object.entries(r))
|
|
188
234
|
);
|
|
189
235
|
attrs.delete(DeletedFlagAttributeName);
|
|
236
|
+
readOnlyAttrs?.forEach((n: string) => {
|
|
237
|
+
attrs.delete(n);
|
|
238
|
+
});
|
|
190
239
|
result.push(Instance.newWithAttributes(inst, attrs));
|
|
191
240
|
});
|
|
192
241
|
}
|
|
@@ -266,12 +315,15 @@ export class SqlDbResolver extends Resolver {
|
|
|
266
315
|
joinInfo: JoinInfo[],
|
|
267
316
|
intoSpec: Map<string, string>,
|
|
268
317
|
distinct: boolean = false,
|
|
269
|
-
rawJoinSpec?: JoinSpec
|
|
318
|
+
rawJoinSpec?: JoinSpec[],
|
|
319
|
+
whereClauses?: WhereClause[]
|
|
270
320
|
): Promise<any> {
|
|
271
321
|
const tableName = asTableReference(inst.moduleName, inst.name);
|
|
272
322
|
const joinClauses: JoinClause[] = [];
|
|
273
323
|
if (rawJoinSpec) {
|
|
274
|
-
|
|
324
|
+
rawJoinSpec.forEach((rjs: JoinSpec) => {
|
|
325
|
+
this.processRawJoinSpec(tableName, inst, rjs, joinClauses);
|
|
326
|
+
});
|
|
275
327
|
} else {
|
|
276
328
|
this.processJoinInfo(tableName, inst, joinInfo, joinClauses);
|
|
277
329
|
}
|
|
@@ -280,15 +332,35 @@ export class SqlDbResolver extends Resolver {
|
|
|
280
332
|
const mn = p.hasModule() ? p.getModuleName() : inst.moduleName;
|
|
281
333
|
intoSpec.set(k, asTableReference(mn, p.getEntryName()));
|
|
282
334
|
});
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
inst.
|
|
286
|
-
|
|
335
|
+
const fqName = inst.getFqName();
|
|
336
|
+
const groupBy = inst.groupBy
|
|
337
|
+
? inst.groupBy.map((gb: string) => {
|
|
338
|
+
return asColumnReference(gb, tableName, inst.name, fqName, inst.moduleName, true);
|
|
339
|
+
})
|
|
340
|
+
: undefined;
|
|
341
|
+
const orderBy = inst.orderBy
|
|
342
|
+
? inst.orderBy.map((ob: string) => {
|
|
343
|
+
return asColumnReference(ob, tableName, inst.name, fqName, inst.moduleName, true);
|
|
344
|
+
})
|
|
345
|
+
: undefined;
|
|
346
|
+
const orderByDesc = inst.orderByDesc ? 'DESC' : 'ASC';
|
|
347
|
+
const aggregates = SqlDbResolver.normalizedAggregates(inst, tableName);
|
|
348
|
+
whereClauses?.forEach((wc: WhereClause) => {
|
|
349
|
+
wc.attrName = asColumnReference(wc.attrName, tableName, inst.name, fqName, inst.moduleName);
|
|
350
|
+
});
|
|
351
|
+
const qspec: QuerySpec = {
|
|
352
|
+
queryObj: inst.queryAttributesAsObject(),
|
|
353
|
+
queryVals: inst.queryAttributeValuesAsObject(),
|
|
354
|
+
distinct,
|
|
355
|
+
groupBy,
|
|
356
|
+
orderBy,
|
|
357
|
+
orderByDesc,
|
|
358
|
+
aggregates,
|
|
287
359
|
joinClauses,
|
|
360
|
+
whereClauses,
|
|
288
361
|
intoSpec,
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
);
|
|
362
|
+
};
|
|
363
|
+
const rslt: any = await getManyByJoin(tableName, qspec, this.getDbContext(inst.getFqName()));
|
|
292
364
|
return rslt;
|
|
293
365
|
}
|
|
294
366
|
|
|
@@ -536,7 +608,7 @@ function maybeNormalizeAttributeNames(
|
|
|
536
608
|
ks.forEach((k: string) => {
|
|
537
609
|
const v = attrs.get(k);
|
|
538
610
|
attrs.delete(k);
|
|
539
|
-
attrs.set(k.substring(n + 1), v);
|
|
611
|
+
attrs.set(k.substring(n + 1) || k, v);
|
|
540
612
|
});
|
|
541
613
|
}
|
|
542
614
|
return attrs;
|
package/src/runtime/state.ts
CHANGED
|
@@ -116,6 +116,20 @@ export const ConfigSchema = z.object({
|
|
|
116
116
|
level: z.enum(['error', 'warn', 'info', 'debug']).default('info'),
|
|
117
117
|
})
|
|
118
118
|
.optional(),
|
|
119
|
+
retry: z
|
|
120
|
+
.array(
|
|
121
|
+
z.object({
|
|
122
|
+
name: z.string(),
|
|
123
|
+
attempts: z.number(),
|
|
124
|
+
backoff: z.object({
|
|
125
|
+
strategy: z.enum(['linear', 'exponential', 'constant']),
|
|
126
|
+
delay: z.number(),
|
|
127
|
+
magnitude: z.enum(['seconds', 'milliSeconds', 'minutes']),
|
|
128
|
+
factor: z.number(),
|
|
129
|
+
}),
|
|
130
|
+
})
|
|
131
|
+
)
|
|
132
|
+
.optional(),
|
|
119
133
|
});
|
|
120
134
|
|
|
121
135
|
export type Config = z.infer<typeof ConfigSchema>;
|
package/src/runtime/util.ts
CHANGED
|
@@ -621,16 +621,18 @@ export function generateLoggerCallId() {
|
|
|
621
621
|
const JS_PREFIX = '#js';
|
|
622
622
|
|
|
623
623
|
export function preprocessRawConfig(rawConfig: any): any {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
624
|
+
if (rawConfig) {
|
|
625
|
+
const keys = Object.keys(rawConfig);
|
|
626
|
+
keys.forEach((k: any) => {
|
|
627
|
+
const v = rawConfig[k];
|
|
628
|
+
if (isString(v) && v.startsWith(JS_PREFIX)) {
|
|
629
|
+
const s = v.substring(3).trim();
|
|
630
|
+
rawConfig[k] = eval(s);
|
|
631
|
+
} else if (typeof v == 'object') {
|
|
632
|
+
preprocessRawConfig(v);
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
}
|
|
634
636
|
return rawConfig;
|
|
635
637
|
}
|
|
636
638
|
|
|
@@ -644,11 +646,22 @@ export function setScecretReader(f: ReadSecret) {
|
|
|
644
646
|
globalThis.readSecret = f;
|
|
645
647
|
}
|
|
646
648
|
|
|
647
|
-
export function objectAsString(obj: any) {
|
|
649
|
+
export function objectAsString(obj: any, keyAsString: boolean = false) {
|
|
648
650
|
const entries = new Array<string>();
|
|
649
651
|
Object.entries(obj).forEach(([k, v]) => {
|
|
650
652
|
const vv = typeof v === 'string' ? `"${v}"` : v;
|
|
651
|
-
|
|
653
|
+
let fv = vv;
|
|
654
|
+
if (fv instanceof Array) {
|
|
655
|
+
fv = fv.map((v: any) => {
|
|
656
|
+
return objectAsString(v, true);
|
|
657
|
+
});
|
|
658
|
+
} else if (fv instanceof Object) {
|
|
659
|
+
fv = objectAsString(fv, true);
|
|
660
|
+
}
|
|
661
|
+
if (keyAsString) {
|
|
662
|
+
k = `"${k}"`;
|
|
663
|
+
}
|
|
664
|
+
entries.push(`${k}: ${fv}`);
|
|
652
665
|
});
|
|
653
666
|
return `{${entries.join(', ')}}`;
|
|
654
667
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Monarch syntax highlighting for the agentlang language.
|
|
2
2
|
export default {
|
|
3
3
|
keywords: [
|
|
4
|
-
'@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@full_join','@inner_join','@into','@join','@left_join','@meta','@oneof','@public','@rbac','@ref','@right_join','@then','@upsert','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','throw','true','update','upsert','where','workflow'
|
|
4
|
+
'@actions','@after','@as','@asc','@async','@before','@catch','@desc','@distinct','@enum','@expr','@from','@full_join','@groupBy','@inner_join','@into','@join','@left_join','@meta','@oneof','@orderBy','@public','@rbac','@ref','@right_join','@then','@upsert','@where','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','throw','true','update','upsert','where','workflow'
|
|
5
5
|
],
|
|
6
6
|
operators: [
|
|
7
7
|
'!=','*','+',',','-','-->','.','/',':',';','<','<=','<>','=','==','>','>=','?','@'
|