@abaplint/runtime 2.11.0 → 2.11.1

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.
@@ -0,0 +1,12 @@
1
+ import { ABAPObject } from "./types";
2
+ export type ABAPEventReference = {
3
+ EVENT_NAME: string;
4
+ EVENT_CLASS: string;
5
+ };
6
+ type HandlerMethod = (parameters?: any) => Promise<void>;
7
+ export declare class ABAPEventing {
8
+ private readonly registrations;
9
+ setHandler(event: ABAPEventReference, methods: HandlerMethod[], forObject: ABAPObject | "ALL", activation: boolean): any;
10
+ raiseEvent(event: ABAPEventReference, me: ABAPObject, _parameters?: object): Promise<void>;
11
+ }
12
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ABAPEventing = void 0;
4
+ class ABAPEventing {
5
+ registrations = {};
6
+ setHandler(event, methods, forObject, activation) {
7
+ if (activation === false) {
8
+ throw new Error("ABAPEventing.setHandler: deactivation not supported, todo");
9
+ }
10
+ else if (methods.length === 0) {
11
+ throw new Error("ABAPEventing.setHandler: no methods provided");
12
+ }
13
+ if (!this.registrations[event.EVENT_CLASS]) {
14
+ this.registrations[event.EVENT_CLASS] = {};
15
+ }
16
+ if (!this.registrations[event.EVENT_CLASS][event.EVENT_NAME]) {
17
+ this.registrations[event.EVENT_CLASS][event.EVENT_NAME] = [];
18
+ }
19
+ const ref = forObject === "ALL" ? "ALL" : new WeakRef(forObject);
20
+ const handlers = this.registrations[event.EVENT_CLASS][event.EVENT_NAME];
21
+ // todo: tackle duplicates
22
+ handlers.push({
23
+ handlers: methods,
24
+ forObject: ref,
25
+ });
26
+ }
27
+ // todo: cleanup of dead WeakRefs
28
+ async raiseEvent(event, me, _parameters) {
29
+ const handlers = this.registrations[event.EVENT_CLASS]?.[event.EVENT_NAME];
30
+ if (handlers === undefined) {
31
+ return;
32
+ }
33
+ for (const handler of handlers) {
34
+ if (handler.forObject === "ALL") {
35
+ for (const method of handler.handlers) {
36
+ await method(_parameters);
37
+ }
38
+ }
39
+ else if (handler.forObject.deref() === me) {
40
+ for (const method of handler.handlers) {
41
+ await method(_parameters);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ exports.ABAPEventing = ABAPEventing;
48
+ //# sourceMappingURL=abap_eventing.js.map
@@ -17,6 +17,7 @@ import { buildDbTableName } from "./prefix";
17
17
  import { IntegerFactory } from "./integer_factory";
18
18
  import { dynamicCallLookup } from "./dynamic_call_lookup";
19
19
  import { CharacterFactory } from "./character_factory";
20
+ import { ABAPEventing } from "./abap_eventing";
20
21
  export { RFC, types, DB, MemoryConsole };
21
22
  export type RuntimeDatabaseOptions = {
22
23
  schemaPrefix?: string;
@@ -71,6 +72,7 @@ export declare class ABAP {
71
72
  buildDbTableName: typeof buildDbTableName;
72
73
  ClassicError: typeof ClassicError;
73
74
  dynamicCallLookup: typeof dynamicCallLookup;
75
+ eventing: ABAPEventing;
74
76
  IntegerFactory: typeof IntegerFactory;
75
77
  CharacterFactory: typeof CharacterFactory;
76
78
  readonly context: Context;
@@ -24,6 +24,7 @@ const prefix_1 = require("./prefix");
24
24
  const integer_factory_1 = require("./integer_factory");
25
25
  const dynamic_call_lookup_1 = require("./dynamic_call_lookup");
26
26
  const character_factory_1 = require("./character_factory");
27
+ const abap_eventing_1 = require("./abap_eventing");
27
28
  class ABAP {
28
29
  // global objects
29
30
  Classes = {};
@@ -51,6 +52,7 @@ class ABAP {
51
52
  buildDbTableName = prefix_1.buildDbTableName;
52
53
  ClassicError = classic_error_1.ClassicError;
53
54
  dynamicCallLookup = dynamic_call_lookup_1.dynamicCallLookup;
55
+ eventing = new abap_eventing_1.ABAPEventing();
54
56
  IntegerFactory = integer_factory_1.IntegerFactory;
55
57
  CharacterFactory = character_factory_1.CharacterFactory;
56
58
  context;
@@ -1 +1,3 @@
1
- export declare function raiseEvent(): void;
1
+ import { ABAPEventReference } from "../abap_eventing";
2
+ import { ABAPObject } from "../types";
3
+ export declare function raiseEvent(eventReference: ABAPEventReference, me: ABAPObject, parameters?: object): Promise<void>;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.raiseEvent = raiseEvent;
4
- function raiseEvent() {
5
- // todo
6
- return;
4
+ async function raiseEvent(eventReference, me, parameters) {
5
+ await abap.eventing.raiseEvent(eventReference, me, parameters);
7
6
  }
8
7
  //# sourceMappingURL=raise_event.js.map
@@ -1,3 +1,4 @@
1
+ import { ABAPEventReference } from "../abap_eventing";
1
2
  import { ABAPObject, FieldSymbol } from "../types";
2
3
  import { ICharacter } from "../types/_character";
3
- export declare function setHandler(_methods: any[], _f: ABAPObject | FieldSymbol, _activation: ICharacter): void;
4
+ export declare function setHandler(eventReference: ABAPEventReference, methods: any[], forObject: ABAPObject | FieldSymbol, activation?: ICharacter): void;
@@ -1,8 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setHandler = setHandler;
4
- function setHandler(_methods, _f, _activation) {
5
- // todo
6
- return;
4
+ const types_1 = require("../types");
5
+ function setHandler(eventReference, methods, forObject, activation) {
6
+ if (forObject instanceof types_1.FieldSymbol) {
7
+ const pointer = forObject.getPointer();
8
+ if (pointer === undefined) {
9
+ throw new Error("CX_SY_ SOMETHING TODO");
10
+ }
11
+ return setHandler(eventReference, methods, pointer, activation);
12
+ }
13
+ else if (forObject instanceof types_1.ABAPObject && forObject.get() === undefined) {
14
+ throw new Error("SET_HANDLER_FOR_NULL");
15
+ }
16
+ const act = activation === undefined ? true : activation.get() === "X";
17
+ abap.eventing.setHandler(eventReference, methods, forObject, act);
7
18
  }
8
19
  //# sourceMappingURL=set_handler.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.11.0",
3
+ "version": "2.11.1",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",