agentlang 0.0.4 → 0.0.5

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.
Files changed (43) hide show
  1. package/out/api/http.js +27 -19
  2. package/out/api/http.js.map +1 -1
  3. package/out/language/generated/ast.d.ts +20 -3
  4. package/out/language/generated/ast.d.ts.map +1 -1
  5. package/out/language/generated/ast.js +26 -1
  6. package/out/language/generated/ast.js.map +1 -1
  7. package/out/language/generated/grammar.d.ts.map +1 -1
  8. package/out/language/generated/grammar.js +208 -106
  9. package/out/language/generated/grammar.js.map +1 -1
  10. package/out/language/main.cjs +228 -107
  11. package/out/language/main.cjs.map +2 -2
  12. package/out/runtime/loader.d.ts.map +1 -1
  13. package/out/runtime/loader.js +25 -9
  14. package/out/runtime/loader.js.map +1 -1
  15. package/out/runtime/module.d.ts +1 -0
  16. package/out/runtime/module.d.ts.map +1 -1
  17. package/out/runtime/module.js +14 -0
  18. package/out/runtime/module.js.map +1 -1
  19. package/out/runtime/modules/auth.d.ts.map +1 -1
  20. package/out/runtime/modules/auth.js +13 -2
  21. package/out/runtime/modules/auth.js.map +1 -1
  22. package/out/runtime/resolvers/sqldb/database.d.ts +4 -2
  23. package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
  24. package/out/runtime/resolvers/sqldb/database.js +43 -4
  25. package/out/runtime/resolvers/sqldb/database.js.map +1 -1
  26. package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
  27. package/out/runtime/resolvers/sqldb/impl.js +7 -3
  28. package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
  29. package/out/runtime/util.d.ts +1 -0
  30. package/out/runtime/util.d.ts.map +1 -1
  31. package/out/runtime/util.js +11 -0
  32. package/out/runtime/util.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/api/http.ts +26 -17
  35. package/src/language/agentlang.langium +5 -1
  36. package/src/language/generated/ast.ts +48 -4
  37. package/src/language/generated/grammar.ts +208 -106
  38. package/src/runtime/loader.ts +23 -10
  39. package/src/runtime/module.ts +14 -0
  40. package/src/runtime/modules/auth.ts +13 -2
  41. package/src/runtime/resolvers/sqldb/database.ts +55 -4
  42. package/src/runtime/resolvers/sqldb/impl.ts +8 -7
  43. package/src/runtime/util.ts +12 -0
package/src/api/http.ts CHANGED
@@ -233,22 +233,7 @@ async function handleEntityGet(
233
233
  if (req.query.tree) {
234
234
  pattern = fetchTreePattern(makeFqName(moduleName, entityName), path);
235
235
  } else {
236
- const r = walkDownInstancePath(path);
237
- let moduleName = r[0];
238
- let entityName = r[1];
239
- const id = r[2];
240
- const parts = r[3];
241
- if (parts.length == 2 && id == undefined) {
242
- pattern = `{${moduleName}/${entityName}? {}}`;
243
- } else {
244
- moduleName = restoreFqName(moduleName);
245
- entityName = restoreFqName(entityName);
246
- if (id == undefined) {
247
- pattern = `{${moduleName}/${entityName} {${PathAttributeNameQuery}like "${path}%"}}`;
248
- } else {
249
- pattern = `{${moduleName}/${entityName} {${PathAttributeNameQuery} "${path}"}}`;
250
- }
251
- }
236
+ pattern = queryPatternFromPath(path);
252
237
  }
253
238
  parseAndEvaluateStatement(pattern, sessionInfo.userId).then(ok(res)).catch(internalError(res));
254
239
  } catch (err: any) {
@@ -257,6 +242,27 @@ async function handleEntityGet(
257
242
  }
258
243
  }
259
244
 
245
+ function queryPatternFromPath(path: string): string {
246
+ let pattern = '';
247
+ const r = walkDownInstancePath(path);
248
+ let moduleName = r[0];
249
+ let entityName = r[1];
250
+ const id = r[2];
251
+ const parts = r[3];
252
+ if (parts.length == 2 && id == undefined) {
253
+ pattern = `{${moduleName}/${entityName}? {}}`;
254
+ } else {
255
+ moduleName = restoreFqName(moduleName);
256
+ entityName = restoreFqName(entityName);
257
+ if (id == undefined) {
258
+ pattern = `{${moduleName}/${entityName} {${PathAttributeNameQuery}like "${path}%"}}`;
259
+ } else {
260
+ pattern = `{${moduleName}/${entityName} {${PathAttributeNameQuery} "${path}"}}`;
261
+ }
262
+ }
263
+ return pattern;
264
+ }
265
+
260
266
  async function handleEntityPut(
261
267
  moduleName: string,
262
268
  entityName: string,
@@ -272,6 +278,9 @@ async function handleEntityPut(
272
278
  }
273
279
  const attrs = objectAsInstanceAttributes(req.body);
274
280
  attrs.set(PathAttributeNameQuery, path);
281
+ const r = walkDownInstancePath(path);
282
+ moduleName = r[0];
283
+ entityName = r[1];
275
284
  const pattern = patternFromAttributes(moduleName, entityName, attrs);
276
285
  parseAndEvaluateStatement(pattern, sessionInfo.userId).then(ok(res)).catch(internalError(res));
277
286
  } catch (err: any) {
@@ -293,7 +302,7 @@ async function handleEntityDelete(
293
302
  res.status(401).send('Authorization required');
294
303
  return;
295
304
  }
296
- const pattern = `delete {${moduleName}/${entityName} {${PathAttributeNameQuery} "${path}"}}`;
305
+ const pattern = `delete ${queryPatternFromPath(path)}`;
297
306
  parseAndEvaluateStatement(pattern, sessionInfo.userId).then(ok(res)).catch(internalError(res));
298
307
  } catch (err: any) {
299
308
  logger.error(err);
@@ -117,7 +117,11 @@ SelectIntoEntry: alias=ID attribute=Ref;
117
117
 
118
118
  FullTextSearch: '{' name=QueryId query=Literal options=MapLiteral? '}';
119
119
 
120
- AgentDefinition: 'agent' name=(ID | STRING) (body=CrudMapBody? | '{''}');
120
+ AgentDefinition: 'agent' name=(ID | STRING) (body=AgentDefBody? | '{''}');
121
+
122
+ AgentDefBody: '{' (attributes+=AgentPropertyDef (',' attributes+=AgentPropertyDef)*)+ '}';
123
+
124
+ AgentPropertyDef: name=ID value=Literal;
121
125
 
122
126
  ResolverDefinition: 'resolver' name=(ID | STRING) '[' (paths+=STRING (',' paths+=STRING)*)+ ']'
123
127
  '{' (methods+=ResolverMethodSpec (',' methods+=ResolverMethodSpec)*)+ '}';
@@ -190,10 +190,22 @@ export function isAfterTriggerDefinition(item: unknown): item is AfterTriggerDef
190
190
  return reflection.isInstance(item, AfterTriggerDefinition);
191
191
  }
192
192
 
193
+ export interface AgentDefBody extends langium.AstNode {
194
+ readonly $container: AgentDefinition;
195
+ readonly $type: 'AgentDefBody';
196
+ attributes: Array<AgentPropertyDef>;
197
+ }
198
+
199
+ export const AgentDefBody = 'AgentDefBody';
200
+
201
+ export function isAgentDefBody(item: unknown): item is AgentDefBody {
202
+ return reflection.isInstance(item, AgentDefBody);
203
+ }
204
+
193
205
  export interface AgentDefinition extends langium.AstNode {
194
206
  readonly $container: ModuleDefinition;
195
207
  readonly $type: 'AgentDefinition';
196
- body?: CrudMapBody;
208
+ body?: AgentDefBody;
197
209
  name: string;
198
210
  }
199
211
 
@@ -203,6 +215,19 @@ export function isAgentDefinition(item: unknown): item is AgentDefinition {
203
215
  return reflection.isInstance(item, AgentDefinition);
204
216
  }
205
217
 
218
+ export interface AgentPropertyDef extends langium.AstNode {
219
+ readonly $container: AgentDefBody;
220
+ readonly $type: 'AgentPropertyDef';
221
+ name: string;
222
+ value: Literal;
223
+ }
224
+
225
+ export const AgentPropertyDef = 'AgentPropertyDef';
226
+
227
+ export function isAgentPropertyDef(item: unknown): item is AgentPropertyDef {
228
+ return reflection.isInstance(item, AgentPropertyDef);
229
+ }
230
+
206
231
  export interface AliasSpec extends langium.AstNode {
207
232
  readonly $container: RuntimeHint;
208
233
  readonly $type: 'AliasSpec';
@@ -326,7 +351,7 @@ export function isCrudMap(item: unknown): item is CrudMap {
326
351
  }
327
352
 
328
353
  export interface CrudMapBody extends langium.AstNode {
329
- readonly $container: AgentDefinition | CrudMap;
354
+ readonly $container: CrudMap;
330
355
  readonly $type: 'CrudMapBody';
331
356
  attributes: Array<SetAttribute>;
332
357
  properties: Array<PropertyDefinition>;
@@ -545,7 +570,7 @@ export function isKvPairs(item: unknown): item is KvPairs {
545
570
  }
546
571
 
547
572
  export interface Literal extends langium.AstNode {
548
- readonly $container: AttributeDefinition | BinExpr | FnCall | FullTextSearch | Group | If | KvPair | MapEntry | NegExpr | NotExpr | Pattern | SetAttribute;
573
+ readonly $container: AgentPropertyDef | AttributeDefinition | BinExpr | FnCall | FullTextSearch | Group | If | KvPair | MapEntry | NegExpr | NotExpr | Pattern | SetAttribute;
549
574
  readonly $type: 'Literal';
550
575
  array?: ArrayLiteral;
551
576
  asyncFnCall?: AsyncFnCall;
@@ -1087,7 +1112,9 @@ export function isWorkflowDefinition(item: unknown): item is WorkflowDefinition
1087
1112
  export type AgentlangAstType = {
1088
1113
  ActionEntry: ActionEntry
1089
1114
  AfterTriggerDefinition: AfterTriggerDefinition
1115
+ AgentDefBody: AgentDefBody
1090
1116
  AgentDefinition: AgentDefinition
1117
+ AgentPropertyDef: AgentPropertyDef
1091
1118
  AliasSpec: AliasSpec
1092
1119
  ArrayLiteral: ArrayLiteral
1093
1120
  AsyncFnCall: AsyncFnCall
@@ -1165,7 +1192,7 @@ export type AgentlangAstType = {
1165
1192
  export class AgentlangAstReflection extends langium.AbstractAstReflection {
1166
1193
 
1167
1194
  getAllTypes(): string[] {
1168
- return [ActionEntry, AfterTriggerDefinition, AgentDefinition, AliasSpec, ArrayLiteral, AsyncFnCall, AttributeDefinition, AttributeValueExpression, BeforeTriggerDefinition, BinExpr, CatchSpec, CompositeUniqueDefinition, CrudMap, CrudMapBody, Definition, Delete, Else, EntityActionsDefinitions, EntityDefinition, EnumSpec, EventDefinition, Expr, ExtendsClause, FnCall, ForEach, FullTextSearch, Group, Handler, If, Import, KvPair, KvPairs, Literal, MapEntry, MapKey, MapLiteral, MetaDefinition, ModuleDefinition, NegExpr, NodeDefinition, NotExpr, OneOfSpec, Pattern, PrePostTriggerDefinition, PrimExpr, PropertyDefinition, Purge, RbacAllowSpec, RbacExpressionSpec, RbacOpr, RbacRolesSpec, RbacSpecDefinition, RbacSpecEntries, RbacSpecEntry, RecordDefinition, RecordExtraDefinition, RecordSchemaDefinition, RefSpec, RelNodes, RelationshipDefinition, RelationshipPattern, ResolverDefinition, ResolverFnName, ResolverMethodName, ResolverMethodSpec, RuntimeHint, SchemaDefinition, SelectIntoEntry, SelectIntoSpec, SetAttribute, StandaloneStatement, Statement, TriggerDefinition, TriggerEntry, WorkflowDefinition];
1195
+ return [ActionEntry, AfterTriggerDefinition, AgentDefBody, AgentDefinition, AgentPropertyDef, AliasSpec, ArrayLiteral, AsyncFnCall, AttributeDefinition, AttributeValueExpression, BeforeTriggerDefinition, BinExpr, CatchSpec, CompositeUniqueDefinition, CrudMap, CrudMapBody, Definition, Delete, Else, EntityActionsDefinitions, EntityDefinition, EnumSpec, EventDefinition, Expr, ExtendsClause, FnCall, ForEach, FullTextSearch, Group, Handler, If, Import, KvPair, KvPairs, Literal, MapEntry, MapKey, MapLiteral, MetaDefinition, ModuleDefinition, NegExpr, NodeDefinition, NotExpr, OneOfSpec, Pattern, PrePostTriggerDefinition, PrimExpr, PropertyDefinition, Purge, RbacAllowSpec, RbacExpressionSpec, RbacOpr, RbacRolesSpec, RbacSpecDefinition, RbacSpecEntries, RbacSpecEntry, RecordDefinition, RecordExtraDefinition, RecordSchemaDefinition, RefSpec, RelNodes, RelationshipDefinition, RelationshipPattern, ResolverDefinition, ResolverFnName, ResolverMethodName, ResolverMethodSpec, RuntimeHint, SchemaDefinition, SelectIntoEntry, SelectIntoSpec, SetAttribute, StandaloneStatement, Statement, TriggerDefinition, TriggerEntry, WorkflowDefinition];
1169
1196
  }
1170
1197
 
1171
1198
  protected override computeIsSubtype(subtype: string, supertype: string): boolean {
@@ -1230,6 +1257,14 @@ export class AgentlangAstReflection extends langium.AbstractAstReflection {
1230
1257
  ]
1231
1258
  };
1232
1259
  }
1260
+ case AgentDefBody: {
1261
+ return {
1262
+ name: AgentDefBody,
1263
+ properties: [
1264
+ { name: 'attributes', defaultValue: [] }
1265
+ ]
1266
+ };
1267
+ }
1233
1268
  case AgentDefinition: {
1234
1269
  return {
1235
1270
  name: AgentDefinition,
@@ -1239,6 +1274,15 @@ export class AgentlangAstReflection extends langium.AbstractAstReflection {
1239
1274
  ]
1240
1275
  };
1241
1276
  }
1277
+ case AgentPropertyDef: {
1278
+ return {
1279
+ name: AgentPropertyDef,
1280
+ properties: [
1281
+ { name: 'name' },
1282
+ { name: 'value' }
1283
+ ]
1284
+ };
1285
+ }
1242
1286
  case AliasSpec: {
1243
1287
  return {
1244
1288
  name: AliasSpec,