agentlang 0.0.2
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/LICENSE +83 -0
- package/README.md +120 -0
- package/bin/cli.js +4 -0
- package/out/api/http.d.ts +3 -0
- package/out/api/http.d.ts.map +1 -0
- package/out/api/http.js +290 -0
- package/out/api/http.js.map +1 -0
- package/out/cli/cli-util.d.ts +7 -0
- package/out/cli/cli-util.d.ts.map +1 -0
- package/out/cli/cli-util.js +9 -0
- package/out/cli/cli-util.js.map +1 -0
- package/out/cli/docs.d.ts +2 -0
- package/out/cli/docs.d.ts.map +1 -0
- package/out/cli/docs.js +236 -0
- package/out/cli/docs.js.map +1 -0
- package/out/cli/main.d.ts +288 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/cli/main.js +119 -0
- package/out/cli/main.js.map +1 -0
- package/out/cli/openapi-docs.yml +695 -0
- package/out/extension/main.cjs +18093 -0
- package/out/extension/main.cjs.map +7 -0
- package/out/extension/main.d.ts +4 -0
- package/out/extension/main.d.ts.map +1 -0
- package/out/extension/main.js +42 -0
- package/out/extension/main.js.map +1 -0
- package/out/language/agentlang-module.d.ts +42 -0
- package/out/language/agentlang-module.d.ts.map +1 -0
- package/out/language/agentlang-module.js +42 -0
- package/out/language/agentlang-module.js.map +1 -0
- package/out/language/agentlang-validator.d.ts +15 -0
- package/out/language/agentlang-validator.d.ts.map +1 -0
- package/out/language/agentlang-validator.js +50 -0
- package/out/language/agentlang-validator.js.map +1 -0
- package/out/language/generated/ast.d.ts +491 -0
- package/out/language/generated/ast.d.ts.map +1 -0
- package/out/language/generated/ast.js +934 -0
- package/out/language/generated/ast.js.map +1 -0
- package/out/language/generated/grammar.d.ts +7 -0
- package/out/language/generated/grammar.d.ts.map +1 -0
- package/out/language/generated/grammar.js +4475 -0
- package/out/language/generated/grammar.js.map +1 -0
- package/out/language/generated/module.d.ts +14 -0
- package/out/language/generated/module.d.ts.map +1 -0
- package/out/language/generated/module.js +21 -0
- package/out/language/generated/module.js.map +1 -0
- package/out/language/main-browser.d.ts +2 -0
- package/out/language/main-browser.d.ts.map +1 -0
- package/out/language/main-browser.js +10 -0
- package/out/language/main-browser.js.map +1 -0
- package/out/language/main.cjs +36229 -0
- package/out/language/main.cjs.map +7 -0
- package/out/language/main.d.ts +2 -0
- package/out/language/main.d.ts.map +1 -0
- package/out/language/main.js +11 -0
- package/out/language/main.js.map +1 -0
- package/out/language/parser.d.ts +9 -0
- package/out/language/parser.d.ts.map +1 -0
- package/out/language/parser.js +273 -0
- package/out/language/parser.js.map +1 -0
- package/out/language/syntax.d.ts +155 -0
- package/out/language/syntax.d.ts.map +1 -0
- package/out/language/syntax.js +527 -0
- package/out/language/syntax.js.map +1 -0
- package/out/runtime/agents/common.d.ts +2 -0
- package/out/runtime/agents/common.d.ts.map +1 -0
- package/out/runtime/agents/common.js +178 -0
- package/out/runtime/agents/common.js.map +1 -0
- package/out/runtime/agents/impl/openai.d.ts +8 -0
- package/out/runtime/agents/impl/openai.d.ts.map +1 -0
- package/out/runtime/agents/impl/openai.js +15 -0
- package/out/runtime/agents/impl/openai.js.map +1 -0
- package/out/runtime/agents/provider.d.ts +21 -0
- package/out/runtime/agents/provider.d.ts.map +1 -0
- package/out/runtime/agents/provider.js +32 -0
- package/out/runtime/agents/provider.js.map +1 -0
- package/out/runtime/agents/registry.d.ts +2 -0
- package/out/runtime/agents/registry.d.ts.map +1 -0
- package/out/runtime/agents/registry.js +10 -0
- package/out/runtime/agents/registry.js.map +1 -0
- package/out/runtime/auth/cognito.d.ts +16 -0
- package/out/runtime/auth/cognito.d.ts.map +1 -0
- package/out/runtime/auth/cognito.js +186 -0
- package/out/runtime/auth/cognito.js.map +1 -0
- package/out/runtime/auth/defs.d.ts +11 -0
- package/out/runtime/auth/defs.d.ts.map +1 -0
- package/out/runtime/auth/defs.js +24 -0
- package/out/runtime/auth/defs.js.map +1 -0
- package/out/runtime/auth/interface.d.ts +22 -0
- package/out/runtime/auth/interface.d.ts.map +1 -0
- package/out/runtime/auth/interface.js +2 -0
- package/out/runtime/auth/interface.js.map +1 -0
- package/out/runtime/defs.js +24 -0
- package/out/runtime/defs.js.map +1 -0
- package/out/runtime/interpreter.d.ts +69 -0
- package/out/runtime/interpreter.d.ts.map +1 -0
- package/out/runtime/interpreter.js +1163 -0
- package/out/runtime/interpreter.js.map +1 -0
- package/out/runtime/loader.d.ts +25 -0
- package/out/runtime/loader.d.ts.map +1 -0
- package/out/runtime/loader.js +346 -0
- package/out/runtime/loader.js.map +1 -0
- package/out/runtime/logger.d.ts +2 -0
- package/out/runtime/logger.d.ts.map +1 -0
- package/out/runtime/logger.js +44 -0
- package/out/runtime/logger.js.map +1 -0
- package/out/runtime/module.d.ts +273 -0
- package/out/runtime/module.d.ts.map +1 -0
- package/out/runtime/module.js +1786 -0
- package/out/runtime/module.js.map +1 -0
- package/out/runtime/modules/ai.d.ts +26 -0
- package/out/runtime/modules/ai.d.ts.map +1 -0
- package/out/runtime/modules/ai.js +211 -0
- package/out/runtime/modules/ai.js.map +1 -0
- package/out/runtime/modules/auth.d.ts +39 -0
- package/out/runtime/modules/auth.d.ts.map +1 -0
- package/out/runtime/modules/auth.js +359 -0
- package/out/runtime/modules/auth.js.map +1 -0
- package/out/runtime/modules/core.d.ts +2 -0
- package/out/runtime/modules/core.d.ts.map +1 -0
- package/out/runtime/modules/core.js +67 -0
- package/out/runtime/modules/core.js.map +1 -0
- package/out/runtime/relgraph.d.ts +21 -0
- package/out/runtime/relgraph.d.ts.map +1 -0
- package/out/runtime/relgraph.js +156 -0
- package/out/runtime/relgraph.js.map +1 -0
- package/out/runtime/resolvers/interface.d.ts +59 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -0
- package/out/runtime/resolvers/interface.js +111 -0
- package/out/runtime/resolvers/interface.js.map +1 -0
- package/out/runtime/resolvers/registry.d.ts +8 -0
- package/out/runtime/resolvers/registry.d.ts.map +1 -0
- package/out/runtime/resolvers/registry.js +26 -0
- package/out/runtime/resolvers/registry.js.map +1 -0
- package/out/runtime/resolvers/sqldb/database.d.ts +50 -0
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/database.js +618 -0
- package/out/runtime/resolvers/sqldb/database.js.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts +18 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.js +221 -0
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts +26 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.js +300 -0
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -0
- package/out/runtime/state.js +83 -0
- package/out/runtime/state.js.map +1 -0
- package/out/runtime/util.d.ts +43 -0
- package/out/runtime/util.d.ts.map +1 -0
- package/out/runtime/util.js +447 -0
- package/out/runtime/util.js.map +1 -0
- 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.d.ts +77 -0
- package/out/syntaxes/agentlang.monarch.d.ts.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +31 -0
- package/out/syntaxes/agentlang.monarch.js.map +1 -0
- package/out/utils/fs/index.d.ts +14 -0
- package/out/utils/fs/index.d.ts.map +1 -0
- package/out/utils/fs/index.js +26 -0
- package/out/utils/fs/index.js.map +1 -0
- package/out/utils/fs/interfaces.d.ts +105 -0
- package/out/utils/fs/interfaces.d.ts.map +1 -0
- package/out/utils/fs/interfaces.js +5 -0
- package/out/utils/fs/interfaces.js.map +1 -0
- package/out/utils/fs/lightning-fs.d.ts +116 -0
- package/out/utils/fs/lightning-fs.d.ts.map +1 -0
- package/out/utils/fs/lightning-fs.js +243 -0
- package/out/utils/fs/lightning-fs.js.map +1 -0
- package/out/utils/fs/node-fs.d.ts +93 -0
- package/out/utils/fs/node-fs.d.ts.map +1 -0
- package/out/utils/fs/node-fs.js +169 -0
- package/out/utils/fs/node-fs.js.map +1 -0
- package/out/utils/fs-utils.d.ts +153 -0
- package/out/utils/fs-utils.d.ts.map +1 -0
- package/out/utils/fs-utils.js +271 -0
- package/out/utils/fs-utils.js.map +1 -0
- package/out/utils/runtime.d.ts +36 -0
- package/out/utils/runtime.d.ts.map +1 -0
- package/out/utils/runtime.js +39 -0
- package/out/utils/runtime.js.map +1 -0
- package/package.json +155 -0
- package/src/api/http.ts +361 -0
- package/src/cli/cli-util.ts +18 -0
- package/src/cli/main.ts +146 -0
- package/src/extension/main.ts +51 -0
- package/src/language/agentlang-module.ts +75 -0
- package/src/language/agentlang-validator.ts +60 -0
- package/src/language/agentlang.langium +178 -0
- package/src/language/generated/ast.ts +1698 -0
- package/src/language/generated/grammar.ts +4477 -0
- package/src/language/generated/module.ts +25 -0
- package/src/language/main-browser.ts +19 -0
- package/src/language/main.ts +13 -0
- package/src/language/parser.ts +329 -0
- package/src/language/syntax.ts +646 -0
- package/src/runtime/agents/common.ts +177 -0
- package/src/runtime/agents/impl/openai.ts +19 -0
- package/src/runtime/agents/provider.ts +58 -0
- package/src/runtime/agents/registry.ts +9 -0
- package/src/runtime/auth/cognito.ts +225 -0
- package/src/runtime/auth/defs.ts +33 -0
- package/src/runtime/auth/interface.ts +31 -0
- package/src/runtime/defs.ts +33 -0
- package/src/runtime/interpreter.ts +1352 -0
- package/src/runtime/loader.ts +450 -0
- package/src/runtime/logger.ts +51 -0
- package/src/runtime/module.ts +2188 -0
- package/src/runtime/modules/ai.ts +257 -0
- package/src/runtime/modules/auth.ts +489 -0
- package/src/runtime/modules/core.ts +95 -0
- package/src/runtime/relgraph.ts +195 -0
- package/src/runtime/resolvers/interface.ts +160 -0
- package/src/runtime/resolvers/registry.ts +30 -0
- package/src/runtime/resolvers/sqldb/database.ts +823 -0
- package/src/runtime/resolvers/sqldb/dbutil.ts +257 -0
- package/src/runtime/resolvers/sqldb/impl.ts +471 -0
- package/src/runtime/state.ts +87 -0
- package/src/runtime/util.ts +513 -0
- package/src/setupClassic.ts +43 -0
- package/src/setupCommon.ts +33 -0
- package/src/setupExtended.ts +79 -0
- package/src/syntaxes/agentlang.monarch.ts +31 -0
- package/src/utils/fs/index.ts +28 -0
- package/src/utils/fs/interfaces.ts +118 -0
- package/src/utils/fs/lightning-fs.ts +284 -0
- package/src/utils/fs/node-fs.ts +185 -0
- package/src/utils/fs-utils.ts +304 -0
- package/src/utils/runtime.ts +43 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
import { parseHelper } from 'langium/test';
|
|
2
|
+
import { escapeQueryName } from '../runtime/util.js';
|
|
3
|
+
import { ModuleDefinition } from './generated/ast.js';
|
|
4
|
+
import { createAgentlangServices } from './agentlang-module.js';
|
|
5
|
+
import { EmptyFileSystem } from 'langium';
|
|
6
|
+
|
|
7
|
+
export class BasePattern {
|
|
8
|
+
alias: string | undefined;
|
|
9
|
+
aliases: string[] | undefined;
|
|
10
|
+
handlers: Map<string, BasePattern> | undefined;
|
|
11
|
+
|
|
12
|
+
setAlias(alias: string) {
|
|
13
|
+
this.alias = alias;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
unsetAlias() {
|
|
18
|
+
this.alias = undefined;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
addAlias(alias: string) {
|
|
23
|
+
if (this.aliases == undefined) {
|
|
24
|
+
this.aliases = [];
|
|
25
|
+
}
|
|
26
|
+
this.aliases.push(alias);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setAliases(aliases: string[]) {
|
|
30
|
+
this.aliases = aliases;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addHandler(k: 'not_found' | 'error', handler: BasePattern) {
|
|
34
|
+
if (this.handlers == undefined) {
|
|
35
|
+
this.handlers = new Map();
|
|
36
|
+
}
|
|
37
|
+
this.handlers.set(k, handler);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private aliasesAsString(): string | undefined {
|
|
41
|
+
if (this.alias) {
|
|
42
|
+
return ` as ${this.alias}`;
|
|
43
|
+
} else if (this.aliases) {
|
|
44
|
+
return ` as [${this.aliases.join(',')}]`;
|
|
45
|
+
} else {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private handlersAsString(): string | undefined {
|
|
51
|
+
if (this.handlers) {
|
|
52
|
+
let s = '{';
|
|
53
|
+
this.handlers.forEach((handler: BasePattern, k: string) => {
|
|
54
|
+
s = `${s} ${k} ${handler.toString()}\n`;
|
|
55
|
+
});
|
|
56
|
+
return s + '}';
|
|
57
|
+
} else {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
hintsAsString(): string {
|
|
62
|
+
const a = this.aliasesAsString();
|
|
63
|
+
const h = this.handlersAsString();
|
|
64
|
+
if (!a && !h) return '';
|
|
65
|
+
if (a && !h) return a;
|
|
66
|
+
if (!a && h) return h;
|
|
67
|
+
return `${a}\n${h}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
toString(): string {
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const EmptyBasePattern = new BasePattern();
|
|
76
|
+
|
|
77
|
+
export enum LiteralPatternType {
|
|
78
|
+
ID,
|
|
79
|
+
NUMBER,
|
|
80
|
+
BOOLEAN,
|
|
81
|
+
STRING,
|
|
82
|
+
REFERENCE,
|
|
83
|
+
MAP,
|
|
84
|
+
ARRAY,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class LiteralPattern extends BasePattern {
|
|
88
|
+
type: LiteralPatternType;
|
|
89
|
+
value: any;
|
|
90
|
+
|
|
91
|
+
static EmptyArray = new LiteralPattern(LiteralPatternType.ARRAY, []);
|
|
92
|
+
|
|
93
|
+
constructor(type: LiteralPatternType, value: any) {
|
|
94
|
+
super();
|
|
95
|
+
this.type = type;
|
|
96
|
+
this.value = value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static Id(value: string): LiteralPattern {
|
|
100
|
+
return new LiteralPattern(LiteralPatternType.ID, value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static Number(value: number): LiteralPattern {
|
|
104
|
+
return new LiteralPattern(LiteralPatternType.NUMBER, value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static Boolean(value: boolean): LiteralPattern {
|
|
108
|
+
return new LiteralPattern(LiteralPatternType.BOOLEAN, value);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static String(value: string): LiteralPattern {
|
|
112
|
+
return new LiteralPattern(LiteralPatternType.STRING, value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static Reference(value: string): LiteralPattern {
|
|
116
|
+
if (value.indexOf('.') < 0) {
|
|
117
|
+
throw new Error(`${value} does not look like a reference`);
|
|
118
|
+
}
|
|
119
|
+
return new LiteralPattern(LiteralPatternType.REFERENCE, value);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static Map(value: Map<string, BasePattern>): LiteralPattern {
|
|
123
|
+
return new LiteralPattern(LiteralPatternType.MAP, value);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static Array(value: Array<BasePattern>): LiteralPattern {
|
|
127
|
+
return new LiteralPattern(LiteralPatternType.ARRAY, value);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override toString(): string {
|
|
131
|
+
let s = '';
|
|
132
|
+
switch (this.type) {
|
|
133
|
+
case LiteralPatternType.ARRAY: {
|
|
134
|
+
const a = this.value as Array<BasePattern>;
|
|
135
|
+
s = `[${a
|
|
136
|
+
.map((v: BasePattern) => {
|
|
137
|
+
return v.toString();
|
|
138
|
+
})
|
|
139
|
+
.join(', ')}]`;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case LiteralPatternType.MAP: {
|
|
143
|
+
const m = this.value as Map<string, BasePattern>;
|
|
144
|
+
const arr = new Array<string>();
|
|
145
|
+
m.forEach((v: BasePattern, k: string) => {
|
|
146
|
+
arr.push(`${k}: ${v.toString()}`);
|
|
147
|
+
});
|
|
148
|
+
s = `{${arr.join(', ')}}`;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case LiteralPatternType.STRING: {
|
|
152
|
+
s = `"${this.value}"`;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
s = this.value.toString();
|
|
157
|
+
}
|
|
158
|
+
return s.concat(this.hintsAsString());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function isLiteralPattern(p: BasePattern): boolean {
|
|
163
|
+
return p instanceof LiteralPattern;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function isReferenceLiteral(p: LiteralPattern): boolean {
|
|
167
|
+
return p.type == LiteralPatternType.REFERENCE;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function referenceParts(p: LiteralPattern): string[] | undefined {
|
|
171
|
+
if (isReferenceLiteral(p)) {
|
|
172
|
+
const s: string = p.value as string;
|
|
173
|
+
return s.split('.');
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function isStringLiteral(p: LiteralPattern): boolean {
|
|
179
|
+
return p.type == LiteralPatternType.STRING;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function isNumberLiteral(p: LiteralPattern): boolean {
|
|
183
|
+
return p.type == LiteralPatternType.NUMBER;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function isBooleanLiteral(p: LiteralPattern): boolean {
|
|
187
|
+
return p.type == LiteralPatternType.BOOLEAN;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function isIdentifierLiteral(p: LiteralPattern): boolean {
|
|
191
|
+
return p.type == LiteralPatternType.ID;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function isArrayLiteral(p: LiteralPattern): boolean {
|
|
195
|
+
return p.type == LiteralPatternType.ARRAY;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function isMapLiteral(p: LiteralPattern): boolean {
|
|
199
|
+
return p.type == LiteralPatternType.MAP;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export class FunctionCallPattern extends BasePattern {
|
|
203
|
+
fnName: string;
|
|
204
|
+
arguments: BasePattern[];
|
|
205
|
+
|
|
206
|
+
constructor(fnName: string, args: BasePattern[]) {
|
|
207
|
+
super();
|
|
208
|
+
this.fnName = fnName;
|
|
209
|
+
this.arguments = args;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
override toString(): string {
|
|
213
|
+
let s = '';
|
|
214
|
+
if (this.arguments.length > 0) {
|
|
215
|
+
const args: Array<string> = [];
|
|
216
|
+
this.arguments.forEach((bp: BasePattern) => {
|
|
217
|
+
args.push(bp.toString());
|
|
218
|
+
});
|
|
219
|
+
s = `${this.fnName}(${args.join(', ')})`;
|
|
220
|
+
} else {
|
|
221
|
+
s = `${this.fnName}()`;
|
|
222
|
+
}
|
|
223
|
+
return s.concat(this.hintsAsString());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function isFunctionCallPattern(p: BasePattern): boolean {
|
|
228
|
+
return p instanceof FunctionCallPattern;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export class ExpressionPattern extends BasePattern {
|
|
232
|
+
expression: any;
|
|
233
|
+
private static services: ReturnType<typeof createAgentlangServices> =
|
|
234
|
+
createAgentlangServices(EmptyFileSystem);
|
|
235
|
+
private static doParse = parseHelper<ModuleDefinition>(this.services.Agentlang);
|
|
236
|
+
private static parse: ReturnType<typeof parseHelper<ModuleDefinition>> = (input: string) =>
|
|
237
|
+
this.doParse(input, { validation: true });
|
|
238
|
+
|
|
239
|
+
constructor(expression: any) {
|
|
240
|
+
super();
|
|
241
|
+
this.expression = expression;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static async Validated(exprString: string): Promise<ExpressionPattern> {
|
|
245
|
+
const result = await ExpressionPattern.parse(
|
|
246
|
+
`module Temp workflow Test { if (${exprString}) {} }`
|
|
247
|
+
);
|
|
248
|
+
if (result.parseResult.lexerErrors.length > 0) {
|
|
249
|
+
throw new Error(result.parseResult.lexerErrors.join('\n'));
|
|
250
|
+
}
|
|
251
|
+
if (result.parseResult.parserErrors.length > 0) {
|
|
252
|
+
throw new Error(result.parseResult.parserErrors.join('\n'));
|
|
253
|
+
}
|
|
254
|
+
return new ExpressionPattern(exprString);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
override toString(): string {
|
|
258
|
+
const s = this.expression.toString();
|
|
259
|
+
return s.concat(this.hintsAsString());
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function isExpressionPattern(p: BasePattern): boolean {
|
|
264
|
+
return p instanceof ExpressionPattern;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export class GroupExpressionPattern extends BasePattern {
|
|
268
|
+
expression: ExpressionPattern;
|
|
269
|
+
|
|
270
|
+
constructor(expr: ExpressionPattern) {
|
|
271
|
+
super();
|
|
272
|
+
this.expression = expr;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
override toString(): string {
|
|
276
|
+
return `(${this.expression.toString()})`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function isGroupExpressionPattern(p: BasePattern): boolean {
|
|
281
|
+
return p instanceof GroupExpressionPattern;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class NegExpressionPattern extends BasePattern {
|
|
285
|
+
expression: ExpressionPattern;
|
|
286
|
+
|
|
287
|
+
constructor(expr: ExpressionPattern) {
|
|
288
|
+
super();
|
|
289
|
+
this.expression = expr;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
override toString(): string {
|
|
293
|
+
return `-${this.expression.toString}`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export class NotExpressionPattern extends BasePattern {
|
|
298
|
+
expression: ExpressionPattern;
|
|
299
|
+
|
|
300
|
+
constructor(expr: ExpressionPattern) {
|
|
301
|
+
super();
|
|
302
|
+
this.expression = expr;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
override toString(): string {
|
|
306
|
+
return `not(${this.expression.toString})`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function isNegExpressionPattern(p: BasePattern): boolean {
|
|
311
|
+
return p instanceof NegExpressionPattern;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function isNotExpressionPattern(p: BasePattern): boolean {
|
|
315
|
+
return p instanceof NotExpressionPattern;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export class ReferencePattern extends BasePattern {
|
|
319
|
+
record: string;
|
|
320
|
+
member: string;
|
|
321
|
+
|
|
322
|
+
constructor(record: string, member: string) {
|
|
323
|
+
super();
|
|
324
|
+
this.record = record;
|
|
325
|
+
this.member = member;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
override toString(): string {
|
|
329
|
+
return `${this.record}.${this.member}`.concat(this.hintsAsString());
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function isReferencePattern(p: BasePattern): boolean {
|
|
334
|
+
return p instanceof ReferencePattern;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export type AttributePattern = {
|
|
338
|
+
name: string;
|
|
339
|
+
op: string | undefined;
|
|
340
|
+
value: BasePattern;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export class CrudPattern extends BasePattern {
|
|
344
|
+
recordName: string;
|
|
345
|
+
attributes: Array<AttributePattern>;
|
|
346
|
+
relationships: Map<string, CrudPattern[] | CrudPattern> | undefined;
|
|
347
|
+
isQuery: boolean = false;
|
|
348
|
+
isQueryUpdate: boolean = false;
|
|
349
|
+
isCreate: boolean = false;
|
|
350
|
+
|
|
351
|
+
constructor(recordName: string) {
|
|
352
|
+
super();
|
|
353
|
+
this.recordName = recordName;
|
|
354
|
+
this.attributes = [];
|
|
355
|
+
if (recordName.endsWith('?')) {
|
|
356
|
+
this.isQuery = true;
|
|
357
|
+
} else {
|
|
358
|
+
this.isCreate = true;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
addAttribute(n: string, p: BasePattern, op?: string) {
|
|
363
|
+
this.attributes.push({ name: n, op: op, value: p });
|
|
364
|
+
if (this.recordName.endsWith('?')) {
|
|
365
|
+
this.recordName = this.recordName.substring(0, this.recordName.length - 1);
|
|
366
|
+
}
|
|
367
|
+
this.flagType();
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
removeAttribute(n: string) {
|
|
372
|
+
const idx: number = this.attributes.findIndex((ap: AttributePattern) => {
|
|
373
|
+
return n == ap.name;
|
|
374
|
+
});
|
|
375
|
+
if (idx >= 0) {
|
|
376
|
+
this.attributes.splice(idx, 1);
|
|
377
|
+
}
|
|
378
|
+
this.flagType();
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private flagType() {
|
|
383
|
+
let hasq = false;
|
|
384
|
+
let hasc = false;
|
|
385
|
+
for (let i = 0; i < this.attributes.length; ++i) {
|
|
386
|
+
if (hasq && hasc) break;
|
|
387
|
+
const ap = this.attributes[i];
|
|
388
|
+
hasq = ap.name.endsWith('?');
|
|
389
|
+
if (!hasc) hasc = !hasq;
|
|
390
|
+
}
|
|
391
|
+
if (hasq && hasc) {
|
|
392
|
+
this.isQueryUpdate = true;
|
|
393
|
+
} else if (hasc) {
|
|
394
|
+
this.isCreate = true;
|
|
395
|
+
} else {
|
|
396
|
+
this.isQuery = hasq;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
addRelationship(n: string, p: CrudPattern[] | CrudPattern) {
|
|
401
|
+
if (this.relationships == undefined) {
|
|
402
|
+
this.relationships = new Map();
|
|
403
|
+
}
|
|
404
|
+
this.relationships.set(n, p);
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
removeRelationship(n: string) {
|
|
409
|
+
if (this.relationships) {
|
|
410
|
+
this.relationships.delete(n);
|
|
411
|
+
}
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private attributesAsString(): string {
|
|
416
|
+
const result: Array<string> = [];
|
|
417
|
+
this.attributes.forEach((ap: AttributePattern) => {
|
|
418
|
+
result.push(`${ap.name}${ap.op ? ap.op : ''} ${ap.value.toString()}`);
|
|
419
|
+
});
|
|
420
|
+
const s = result.join(', ');
|
|
421
|
+
return `{${s}}`;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
private relationshipsAsString(): string {
|
|
425
|
+
if (this.relationships != undefined) {
|
|
426
|
+
const result: Array<string> = [];
|
|
427
|
+
this.relationships.forEach((p: CrudPattern | CrudPattern[], n: string) => {
|
|
428
|
+
const ps = p instanceof Array ? `[${patternsToString(p, ',')}]` : p.toString();
|
|
429
|
+
result.push(`${n} ${ps}`);
|
|
430
|
+
});
|
|
431
|
+
return result.join(',');
|
|
432
|
+
} else {
|
|
433
|
+
return '';
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
getNormalizedRecordName(): string {
|
|
438
|
+
return escapeQueryName(this.recordName);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
override toString(): string {
|
|
442
|
+
let s = `{${this.recordName} ${this.attributesAsString()}`;
|
|
443
|
+
const rs = this.relationshipsAsString();
|
|
444
|
+
if (rs.length > 0) {
|
|
445
|
+
s = s.concat(`,${rs}`);
|
|
446
|
+
}
|
|
447
|
+
return s.concat('}', this.hintsAsString());
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function isCrudPattern(p: BasePattern): boolean {
|
|
452
|
+
return p instanceof CrudPattern;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export function isCreatePattern(p: BasePattern): boolean {
|
|
456
|
+
return isCrudPattern(p) && (p as CrudPattern).isCreate;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export function isQueryPattern(p: BasePattern): boolean {
|
|
460
|
+
return isCrudPattern(p) && (p as CrudPattern).isQuery;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export function isQueryUpdatePattern(p: BasePattern): boolean {
|
|
464
|
+
return isCrudPattern(p) && (p as CrudPattern).isQueryUpdate;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export class ForEachPattern extends BasePattern {
|
|
468
|
+
variable: string;
|
|
469
|
+
source: BasePattern;
|
|
470
|
+
body: BasePattern[];
|
|
471
|
+
|
|
472
|
+
constructor(variable?: string, source?: BasePattern) {
|
|
473
|
+
super();
|
|
474
|
+
this.variable = variable ? variable : 'X';
|
|
475
|
+
this.source = source ? source : LiteralPattern.EmptyArray;
|
|
476
|
+
this.body = [];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
addPattern(p: BasePattern): ForEachPattern {
|
|
480
|
+
this.body.push(p);
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
removePattern(index: number): ForEachPattern {
|
|
485
|
+
this.body.splice(index, 1);
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
setPatternAt(p: BasePattern, index: number): ForEachPattern {
|
|
490
|
+
this.body[index] = p;
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
removePatternAt(index: number): ForEachPattern {
|
|
495
|
+
this.body.splice(index, 1);
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
getPatternAt(index: number): BasePattern {
|
|
500
|
+
return this.body[index];
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
setVariable(s: string): ForEachPattern {
|
|
504
|
+
this.variable = s;
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
setSourcePattern(p: BasePattern): ForEachPattern {
|
|
509
|
+
this.source = p;
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
override toString(): string {
|
|
514
|
+
if (this.source == undefined || this.variable == undefined) {
|
|
515
|
+
throw new Error('`for` requires variable and source-pattern');
|
|
516
|
+
}
|
|
517
|
+
let s = `for ${this.variable} in ${this.source.toString()}`;
|
|
518
|
+
s = s.concat(`{${patternsToString(this.body)}}`);
|
|
519
|
+
return s.concat(this.hintsAsString());
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export function isForEachPattern(p: BasePattern): boolean {
|
|
524
|
+
return p instanceof ForEachPattern;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export class IfPattern extends BasePattern {
|
|
528
|
+
condition: BasePattern;
|
|
529
|
+
body: BasePattern[];
|
|
530
|
+
elseBody: BasePattern[] | undefined;
|
|
531
|
+
|
|
532
|
+
private static True = new LiteralPattern(LiteralPatternType.BOOLEAN, true);
|
|
533
|
+
|
|
534
|
+
constructor(condition?: BasePattern) {
|
|
535
|
+
super();
|
|
536
|
+
this.condition = condition ? condition : IfPattern.True;
|
|
537
|
+
this.body = [];
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
addPattern(p: BasePattern): IfPattern {
|
|
541
|
+
this.body.push(p);
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
removePattern(index: number): IfPattern {
|
|
546
|
+
this.body.splice(index, 1);
|
|
547
|
+
return this;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
setPatternAt(p: BasePattern, index: number): IfPattern {
|
|
551
|
+
this.body[index] = p;
|
|
552
|
+
return this;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
removePatternAt(index: number): IfPattern {
|
|
556
|
+
this.body.splice(index, 1);
|
|
557
|
+
return this;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
getPatternAt(index: number): BasePattern {
|
|
561
|
+
return this.body[index];
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
setConditionPattern(p: BasePattern): IfPattern {
|
|
565
|
+
this.condition = p;
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
setElse(elseBody?: BasePattern[]): IfPattern {
|
|
570
|
+
this.elseBody = elseBody ? elseBody : new Array<BasePattern>();
|
|
571
|
+
return this;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
removeElse(): IfPattern {
|
|
575
|
+
this.elseBody = undefined;
|
|
576
|
+
return this;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
override toString(): string {
|
|
580
|
+
let s = `if(${this.condition.toString()}) {`;
|
|
581
|
+
s = s.concat(patternsToString(this.body), '}');
|
|
582
|
+
if (this.elseBody) {
|
|
583
|
+
if (this.elseBody.length == 1 && this.elseBody[0] instanceof IfPattern) {
|
|
584
|
+
s = s.concat(` else ${this.elseBody[0].toString()}`);
|
|
585
|
+
} else {
|
|
586
|
+
s = s.concat(` else {${patternsToString(this.elseBody)}}`);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return s.concat(this.hintsAsString());
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export function isIfPattern(p: BasePattern): boolean {
|
|
594
|
+
return p instanceof IfPattern;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
export function newCreatePattern(recName: string): CrudPattern {
|
|
598
|
+
const cp: CrudPattern = new CrudPattern(recName);
|
|
599
|
+
cp.isCreate = true;
|
|
600
|
+
return cp;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function newQueryPattern(recName: string, forQueryUpdate: boolean = false): CrudPattern {
|
|
604
|
+
recName = recName.charAt(recName.length - 1) == '?' ? recName : recName + '?';
|
|
605
|
+
const cp: CrudPattern = new CrudPattern(recName);
|
|
606
|
+
if (forQueryUpdate) {
|
|
607
|
+
cp.isQueryUpdate = true;
|
|
608
|
+
} else {
|
|
609
|
+
cp.isQuery = true;
|
|
610
|
+
}
|
|
611
|
+
return cp;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
export function newQueryUpdatePattern(recName: string): CrudPattern {
|
|
615
|
+
return newQueryPattern(recName, true);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export class DeletePattern extends BasePattern {
|
|
619
|
+
pattern: BasePattern;
|
|
620
|
+
|
|
621
|
+
constructor(pattern: BasePattern) {
|
|
622
|
+
super();
|
|
623
|
+
this.pattern = pattern;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
override toString(): string {
|
|
627
|
+
return `delete ${this.pattern.toString()}`.concat(this.hintsAsString());
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export function isDeletePattern(p: BasePattern): boolean {
|
|
632
|
+
return p instanceof DeletePattern;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export function newDeletePattern(recName: string): DeletePattern {
|
|
636
|
+
const qp: CrudPattern = newQueryPattern(recName);
|
|
637
|
+
return new DeletePattern(qp);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function patternsToString(body: BasePattern[], sep = ';\n'): string {
|
|
641
|
+
return body
|
|
642
|
+
.map((p: BasePattern) => {
|
|
643
|
+
return p.toString();
|
|
644
|
+
})
|
|
645
|
+
.join(sep);
|
|
646
|
+
}
|