agentlang 0.0.25 → 0.0.28
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 +3 -2
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +2 -1
- 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 +26 -9
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +28 -10
- package/out/language/main.cjs.map +2 -2
- package/out/runtime/interpreter.d.ts +3 -1
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +11 -6
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/module.d.ts +6 -0
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +90 -5
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/core.js +2 -2
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +1 -1
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +14 -8
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +2 -2
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/util.d.ts +2 -0
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +7 -0
- package/out/runtime/util.js.map +1 -1
- package/package.json +2 -1
- package/src/language/agentlang.langium +1 -1
- package/src/language/generated/ast.ts +5 -3
- package/src/language/generated/grammar.ts +26 -9
- package/src/runtime/interpreter.ts +20 -6
- package/src/runtime/module.ts +98 -5
- package/src/runtime/modules/core.ts +2 -2
- package/src/runtime/resolvers/interface.ts +17 -11
- package/src/runtime/resolvers/sqldb/impl.ts +2 -2
- package/src/runtime/util.ts +9 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as ai } from './ai.js';
|
|
2
2
|
import { default as auth } from './auth.js';
|
|
3
|
-
import { DefaultModuleName, DefaultModules } from '../util.js';
|
|
3
|
+
import { DefaultModuleName, DefaultModules, escapeSpecialChars } from '../util.js';
|
|
4
4
|
import { Instance, isInstanceOfType, makeInstance, newInstanceAttributes } from '../module.js';
|
|
5
5
|
import {
|
|
6
6
|
Environment,
|
|
@@ -103,7 +103,7 @@ async function addAudit(
|
|
|
103
103
|
`{agentlang/auditlog {
|
|
104
104
|
action "${action}",
|
|
105
105
|
resource "${resource}",
|
|
106
|
-
previous_value "${previuos_value ? JSON.stringify(previuos_value.asObject()) : ''}",
|
|
106
|
+
previous_value "${previuos_value ? escapeSpecialChars(JSON.stringify(previuos_value.asObject())) : ''}",
|
|
107
107
|
user "${user}",
|
|
108
108
|
token "${token ? token : ''}"
|
|
109
109
|
}}`,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
callPostEventOnSubscription,
|
|
2
3
|
Environment,
|
|
3
4
|
evaluate,
|
|
4
5
|
runPostCreateEvents,
|
|
@@ -206,7 +207,7 @@ export class Resolver {
|
|
|
206
207
|
case CrudType.CREATE:
|
|
207
208
|
return await runPostCreateEvents(inst, env);
|
|
208
209
|
case CrudType.UPDATE:
|
|
209
|
-
return await runPostUpdateEvents(inst, env);
|
|
210
|
+
return await runPostUpdateEvents(inst, undefined, env);
|
|
210
211
|
case CrudType.DELETE:
|
|
211
212
|
return await runPostDeleteEvents(inst, env);
|
|
212
213
|
default:
|
|
@@ -226,18 +227,23 @@ export class Resolver {
|
|
|
226
227
|
return this.onOutOfBandCrud(inst, CrudType.DELETE, env);
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
public async onSubscription(result: any): Promise<any> {
|
|
230
|
+
public async onSubscription(result: any, callPostCrudEvent: boolean = false): Promise<any> {
|
|
230
231
|
if (result != undefined) {
|
|
231
232
|
try {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
233
|
+
if (callPostCrudEvent) {
|
|
234
|
+
const inst = result as Instance;
|
|
235
|
+
return await callPostEventOnSubscription(CrudType.CREATE, inst);
|
|
236
|
+
} else {
|
|
237
|
+
const eventName = getSubscriptionEvent(this.name);
|
|
238
|
+
if (eventName) {
|
|
239
|
+
const path = splitFqName(eventName);
|
|
240
|
+
const inst = makeInstance(
|
|
241
|
+
path.getModuleName(),
|
|
242
|
+
path.getEntryName(),
|
|
243
|
+
newInstanceAttributes().set('data', result)
|
|
244
|
+
);
|
|
245
|
+
return await evaluate(inst);
|
|
246
|
+
}
|
|
241
247
|
}
|
|
242
248
|
} catch (err: any) {
|
|
243
249
|
logger.error(`Resolver ${this.name} raised error in onSubscription handler: ${err}`);
|
|
@@ -138,7 +138,7 @@ export class SqlDbResolver extends Resolver {
|
|
|
138
138
|
const queryVals: object = Object.fromEntries(
|
|
139
139
|
new Map<string, any>().set(PathAttributeName, inst.attributes.get(PathAttributeName))
|
|
140
140
|
);
|
|
141
|
-
const updateObj: object =
|
|
141
|
+
const updateObj: object = Instance.stringifyObjects(newAttrs);
|
|
142
142
|
await updateRow(
|
|
143
143
|
asTableReference(inst.moduleName, inst.name),
|
|
144
144
|
queryObj,
|
|
@@ -146,7 +146,7 @@ export class SqlDbResolver extends Resolver {
|
|
|
146
146
|
updateObj,
|
|
147
147
|
this.getDbContext(inst.getFqName())
|
|
148
148
|
);
|
|
149
|
-
return inst.mergeAttributes(newAttrs);
|
|
149
|
+
return Instance.clone(inst).mergeAttributes(newAttrs);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
static EmptyResultSet: Array<Instance> = new Array<Instance>();
|
package/src/runtime/util.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Statement,
|
|
12
12
|
} from '../language/generated/ast.js';
|
|
13
13
|
import { readFile } from '../utils/fs-utils.js';
|
|
14
|
+
import bcrypt from 'bcryptjs';
|
|
14
15
|
import path from 'node:path';
|
|
15
16
|
|
|
16
17
|
export const QuerySuffix = '?';
|
|
@@ -496,6 +497,14 @@ export function isReservedName(s: string): boolean {
|
|
|
496
497
|
return ReservedNames.has(s);
|
|
497
498
|
}
|
|
498
499
|
|
|
500
|
+
export function encryptPassword(s: string): string {
|
|
501
|
+
return bcrypt.hashSync(s, 10);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export function comparePassword(s: string, hash: string): boolean {
|
|
505
|
+
return bcrypt.compareSync(s, hash);
|
|
506
|
+
}
|
|
507
|
+
|
|
499
508
|
export function fileExtension(fileName: string): string {
|
|
500
509
|
if (isNodeEnv) {
|
|
501
510
|
return path.extname(fileName);
|