agentlang 0.0.28 → 0.0.29
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/language/generated/ast.d.ts +17 -20
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +17 -21
- 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 +217 -184
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +225 -200
- package/out/language/main.cjs.map +2 -2
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +4 -1
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.js +1 -1
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/logger.js +1 -2
- package/out/runtime/logger.js.map +1 -1
- package/out/runtime/module.d.ts +5 -4
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +42 -37
- package/out/runtime/module.js.map +1 -1
- package/out/syntaxes/agentlang.monarch.js +1 -1
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/package.json +1 -1
- package/src/language/agentlang.langium +5 -3
- package/src/language/generated/ast.ts +32 -40
- package/src/language/generated/grammar.ts +217 -184
- package/src/runtime/interpreter.ts +4 -1
- package/src/runtime/loader.ts +1 -1
- package/src/runtime/logger.ts +1 -3
- package/src/runtime/module.ts +58 -37
- package/src/syntaxes/agentlang.monarch.ts +1 -1
|
@@ -1740,8 +1740,11 @@ async function runPrePostEvents(
|
|
|
1740
1740
|
}
|
|
1741
1741
|
};
|
|
1742
1742
|
if (trigInfo.async) {
|
|
1743
|
-
|
|
1743
|
+
const newEnv = new Environment('async.prepost.env');
|
|
1744
|
+
newEnv.bind('this', inst);
|
|
1745
|
+
evaluate(eventInst, callback, newEnv).catch(catchHandler);
|
|
1744
1746
|
} else {
|
|
1747
|
+
env.bind('this', inst);
|
|
1745
1748
|
await evaluate(eventInst, callback, env).catch(catchHandler);
|
|
1746
1749
|
}
|
|
1747
1750
|
}
|
package/src/runtime/loader.ts
CHANGED
|
@@ -413,7 +413,7 @@ export function addRelationshipFromDef(
|
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
export function addWorkflowFromDef(def: WorkflowDefinition, moduleName: string): Workflow {
|
|
416
|
-
return addWorkflow(def.name, moduleName, def.statements, def.
|
|
416
|
+
return addWorkflow(def.name || '', moduleName, def.statements, def.header);
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
const StandaloneStatements = new Map<string, Statement[]>();
|
package/src/runtime/logger.ts
CHANGED
|
@@ -25,8 +25,6 @@ if (isNodeEnv) {
|
|
|
25
25
|
maxFiles: '7d',
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
const consoleTransport = new winston.transports.Console();
|
|
29
|
-
|
|
30
28
|
logger = winston.createLogger({
|
|
31
29
|
format: winston.format.combine(
|
|
32
30
|
winston.format.timestamp(),
|
|
@@ -34,7 +32,7 @@ if (isNodeEnv) {
|
|
|
34
32
|
return `[${timestamp}] ${level}: ${message}`;
|
|
35
33
|
})
|
|
36
34
|
),
|
|
37
|
-
transports: [fileTransport
|
|
35
|
+
transports: [fileTransport],
|
|
38
36
|
});
|
|
39
37
|
} else {
|
|
40
38
|
function mkLogger(tag: string): Function {
|
package/src/runtime/module.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
RbacSpecEntry,
|
|
20
20
|
RbacSpecEntries,
|
|
21
21
|
RbacOpr,
|
|
22
|
-
|
|
22
|
+
WorkflowHeader,
|
|
23
23
|
} from '../language/generated/ast.js';
|
|
24
24
|
import {
|
|
25
25
|
Path,
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
} from './util.js';
|
|
46
46
|
import { parseStatement } from '../language/parser.js';
|
|
47
47
|
import { ActiveSessionInfo, AdminSession } from './auth/defs.js';
|
|
48
|
-
import { FetchModuleFn, PathAttributeName
|
|
48
|
+
import { FetchModuleFn, PathAttributeName } from './defs.js';
|
|
49
49
|
import { logger } from './logger.js';
|
|
50
50
|
|
|
51
51
|
export class ModuleEntry {
|
|
@@ -1157,10 +1157,17 @@ export class Relationship extends Record {
|
|
|
1157
1157
|
|
|
1158
1158
|
export class Workflow extends ModuleEntry {
|
|
1159
1159
|
statements: Statement[];
|
|
1160
|
+
generatedName: boolean;
|
|
1160
1161
|
|
|
1161
|
-
constructor(
|
|
1162
|
+
constructor(
|
|
1163
|
+
name: string,
|
|
1164
|
+
patterns: Statement[],
|
|
1165
|
+
moduleName: string,
|
|
1166
|
+
generatedName: boolean = false
|
|
1167
|
+
) {
|
|
1162
1168
|
super(name, moduleName);
|
|
1163
1169
|
this.statements = patterns;
|
|
1170
|
+
this.generatedName = generatedName;
|
|
1164
1171
|
}
|
|
1165
1172
|
|
|
1166
1173
|
async addStatement(stmtCode: string): Promise<Workflow> {
|
|
@@ -1278,7 +1285,8 @@ export class Workflow extends ModuleEntry {
|
|
|
1278
1285
|
}
|
|
1279
1286
|
|
|
1280
1287
|
override toString() {
|
|
1281
|
-
|
|
1288
|
+
const n = this.generatedName ? untangleWorkflowName(this.name) : this.name;
|
|
1289
|
+
let s: string = `workflow ${normalizeWorkflowName(n)} {\n`;
|
|
1282
1290
|
const ss = this.statementsToStringsHelper(this.statements);
|
|
1283
1291
|
s = s.concat(joinStatements(ss));
|
|
1284
1292
|
return s.concat('\n}');
|
|
@@ -1887,8 +1895,11 @@ export function addWorkflow(
|
|
|
1887
1895
|
name: string,
|
|
1888
1896
|
moduleName = activeModule,
|
|
1889
1897
|
statements?: Statement[],
|
|
1890
|
-
|
|
1898
|
+
hdr?: WorkflowHeader
|
|
1891
1899
|
): Workflow {
|
|
1900
|
+
if (hdr) {
|
|
1901
|
+
name = prePostWorkflowName(hdr.tag, hdr.prefix, hdr.name, moduleName);
|
|
1902
|
+
}
|
|
1892
1903
|
const module: Module = fetchModule(moduleName);
|
|
1893
1904
|
if (module.hasEntry(name)) {
|
|
1894
1905
|
const entry: ModuleEntry = module.getEntry(name);
|
|
@@ -1900,39 +1911,48 @@ export function addWorkflow(
|
|
|
1900
1911
|
event.addMeta(SystemDefinedEvent, 'true');
|
|
1901
1912
|
}
|
|
1902
1913
|
if (!statements) statements = new Array<Statement>();
|
|
1903
|
-
if (
|
|
1914
|
+
if (hdr) {
|
|
1904
1915
|
const eventFqName = makeFqName(moduleName, name);
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1916
|
+
const entityDef = getEntityDef(hdr.name, moduleName);
|
|
1917
|
+
if (hdr.tag == '@after') {
|
|
1918
|
+
entityDef?.addAfterTrigger({
|
|
1919
|
+
on: hdr.prefix,
|
|
1920
|
+
event: eventFqName,
|
|
1921
|
+
async: false,
|
|
1922
|
+
});
|
|
1923
|
+
} else {
|
|
1924
|
+
entityDef?.addBeforeTrigger({
|
|
1925
|
+
on: hdr.prefix,
|
|
1926
|
+
event: eventFqName,
|
|
1927
|
+
async: false,
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return module.addEntry(
|
|
1932
|
+
new Workflow(asWorkflowName(name), statements, moduleName, hdr ? true : false)
|
|
1933
|
+
) as Workflow;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
function prePostWorkflowName(
|
|
1937
|
+
tag: '@after' | '@before',
|
|
1938
|
+
opr: 'create' | 'update' | 'delete',
|
|
1939
|
+
entityName: string,
|
|
1940
|
+
moduleName?: string
|
|
1941
|
+
): string {
|
|
1942
|
+
const parts = splitFqName(entityName);
|
|
1943
|
+
const mname = parts.hasModule() ? parts.getModuleName() : moduleName;
|
|
1944
|
+
if (!mname) {
|
|
1945
|
+
throw new Error(`Cannot infer module name for ${entityName}`);
|
|
1930
1946
|
}
|
|
1931
|
-
return
|
|
1947
|
+
return `${tag.substring(1)}_${opr}_${mname}_${parts.getEntryName()}`;
|
|
1932
1948
|
}
|
|
1933
1949
|
|
|
1934
|
-
function
|
|
1935
|
-
const
|
|
1950
|
+
function untangleWorkflowName(name: string): string {
|
|
1951
|
+
const parts = name.split('_');
|
|
1952
|
+
return `@${parts[0]} ${parts[1]}:${parts[2]}/${parts[3]}`;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
function getEntityDef(entityName: string, moduleName: string): Entity | undefined {
|
|
1936
1956
|
const parts = splitFqName(entityName);
|
|
1937
1957
|
const mname = parts.hasModule() ? parts.getModuleName() : moduleName;
|
|
1938
1958
|
return getEntity(parts.getEntryName(), mname);
|
|
@@ -1949,12 +1969,13 @@ export function getWorkflow(eventInstance: Instance): Workflow {
|
|
|
1949
1969
|
return EmptyWorkflow;
|
|
1950
1970
|
}
|
|
1951
1971
|
|
|
1952
|
-
export function getEntity(name: string, moduleName: string): Entity {
|
|
1972
|
+
export function getEntity(name: string, moduleName: string): Entity | undefined {
|
|
1953
1973
|
const fr: FetchModuleByEntryNameResult = fetchModuleByEntryName(name, moduleName);
|
|
1954
1974
|
if (fr.module.isEntity(fr.entryName)) {
|
|
1955
1975
|
return fr.module.getEntry(fr.entryName) as Entity;
|
|
1956
1976
|
}
|
|
1957
|
-
|
|
1977
|
+
logger.error(`Entity ${fr.entryName} not found in module ${fr.moduleName}`);
|
|
1978
|
+
return undefined;
|
|
1958
1979
|
}
|
|
1959
1980
|
|
|
1960
1981
|
function isEntryOfType(t: RecordType, fqName: string): boolean {
|
|
@@ -2782,7 +2803,7 @@ export function getEntityRbacRules(entityFqName: string): RbacSpecification[] |
|
|
|
2782
2803
|
const m = isModule(mn) && fetchModule(mn);
|
|
2783
2804
|
if (m && m.isEntity(en)) {
|
|
2784
2805
|
const entity = getEntity(en, mn);
|
|
2785
|
-
return entity
|
|
2806
|
+
return entity?.getRbacSpecifications()?.filter((spec: RbacSpecification) => {
|
|
2786
2807
|
return spec.expression != undefined;
|
|
2787
2808
|
});
|
|
2788
2809
|
}
|
|
@@ -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','@into','@meta','@oneof','@rbac','@ref','@
|
|
4
|
+
'@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@into','@meta','@oneof','@rbac','@ref','@then','@upsert','@with_unique','agent','allow','and','await','between','contains','create','delete','else','entity','error','event','extends','false','for','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','subscribe','true','update','upsert','where','workflow'
|
|
5
5
|
],
|
|
6
6
|
operators: [
|
|
7
7
|
'!=','*','+',',','-','.','/',':',';','<','<=','<>','=','>','>=','?','@'
|