summaryrefslogtreecommitdiff
path: root/node_modules/@jet/engine/lib/actions
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet/engine/lib/actions
init commit
Diffstat (limited to 'node_modules/@jet/engine/lib/actions')
-rw-r--r--node_modules/@jet/engine/lib/actions/action-dispatcher.js64
-rw-r--r--node_modules/@jet/engine/lib/actions/index.js13
2 files changed, 77 insertions, 0 deletions
diff --git a/node_modules/@jet/engine/lib/actions/action-dispatcher.js b/node_modules/@jet/engine/lib/actions/action-dispatcher.js
new file mode 100644
index 0000000..5373f82
--- /dev/null
+++ b/node_modules/@jet/engine/lib/actions/action-dispatcher.js
@@ -0,0 +1,64 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ActionDispatcher = void 0;
+const optional_1 = require("@jet/environment/types/optional");
+class ActionDispatcher {
+ constructor(metricsPipeline) {
+ this.implementations = {};
+ this.metricsPipeline = metricsPipeline;
+ }
+ register(type, implementation) {
+ if (type in this.implementations) {
+ console.error(`An implementation is already registered for ${type}`);
+ }
+ this.implementations[type] = implementation;
+ }
+ async perform(action, metricsBehavior) {
+ if (!(action.$kind in this.implementations)) {
+ // 1. If there is no implementation registered for the type of action
+ // we were passed, we check for a chained dispatcher to forward to.
+ // If one is found, we forward this call without doing any work.
+ // If none is found, we give up.
+ if (optional_1.isSome(this.next)) {
+ return await this.next.perform(action, metricsBehavior);
+ }
+ else {
+ return "unsupported";
+ }
+ }
+ // 2. We have an implementation for the action we were given.
+ // We are responsible for processing metrics for that action.
+ this.processMetrics(action, metricsBehavior);
+ if (optional_1.isSome(this.next)) {
+ // 3a. If we have another dispatcher we are chained to, we forward to it
+ // if the implementation we have for the given action decides it cannot
+ // support performing it.
+ const outcome = await this.implementations[action.$kind](action);
+ if (outcome === "unsupported") {
+ return await this.next.perform(action, { behavior: "notProcessed" });
+ }
+ else {
+ return outcome;
+ }
+ }
+ else {
+ // 3b. We hand off control to the implementation we have for the given action type.
+ // If the implementation cannot perform the action, we give up.
+ return await this.implementations[action.$kind](action);
+ }
+ }
+ processMetrics(action, metricsBehavior) {
+ if (metricsBehavior.behavior === "notProcessed") {
+ return;
+ }
+ const actionMetrics = action.actionMetrics;
+ const context = {
+ customMetrics: actionMetrics.custom,
+ pageFields: metricsBehavior.context.pageFields,
+ };
+ action.actionMetrics.data.forEach((data) => {
+ void this.metricsPipeline.process(data, context);
+ });
+ }
+}
+exports.ActionDispatcher = ActionDispatcher;
diff --git a/node_modules/@jet/engine/lib/actions/index.js b/node_modules/@jet/engine/lib/actions/index.js
new file mode 100644
index 0000000..303d3bb
--- /dev/null
+++ b/node_modules/@jet/engine/lib/actions/index.js
@@ -0,0 +1,13 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./action-dispatcher"), exports);