@pulse-editor/shared-utils 0.1.1-alpha.2 → 0.1.1-alpha.4
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/dist/main.d.ts +6 -5
- package/dist/main.js +1 -1
- package/package.json +5 -3
- package/dist/cjs/imc/inter-module-communication.js +0 -1
- package/dist/cjs/imc/message-receiver.js +0 -1
- package/dist/cjs/imc/message-sender.js +0 -1
- package/dist/cjs/main.js +0 -1
- package/dist/cjs/types/constants.js +0 -1
- package/dist/cjs/types/types.js +0 -1
- package/dist/esm/imc/inter-module-communication.js +0 -1
- package/dist/esm/imc/message-receiver.js +0 -1
- package/dist/esm/imc/message-sender.js +0 -1
- package/dist/esm/main.js +0 -1
- package/dist/esm/types/constants.js +0 -1
- package/dist/esm/types/types.js +0 -1
- package/dist/imc/inter-module-communication.js +0 -1
- package/dist/imc/message-receiver.js +0 -1
- package/dist/imc/message-sender.js +0 -1
- package/dist/main.es.js +0 -1
- package/dist/types/constants.js +0 -1
- package/dist/types/types.js +0 -1
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { InterModuleCommunication } from "./imc/inter-module-communication";
|
|
2
|
+
import { MessageSender } from "./imc/message-sender";
|
|
3
|
+
import { MessageReceiver } from "./imc/message-receiver";
|
|
4
|
+
import { AccessEnum, Agent, AgentMethod, AgentTool, AgentVariable, AgentVariableType, ExtensionConfig, ExtensionTypeEnum, FetchPayload, FileViewModel, IMCMessage, IMCMessageTypeEnum, LLMConfig, NotificationTypeEnum, ReceiverHandlerMap, TextFileSelection } from "./types/types";
|
|
5
|
+
import { messageTimeout } from "./types/constants";
|
|
6
|
+
export { InterModuleCommunication, MessageSender, MessageReceiver, AccessEnum, Agent, AgentMethod, AgentTool, AgentVariable, AgentVariableType, ExtensionConfig, ExtensionTypeEnum, FetchPayload, FileViewModel, IMCMessage, IMCMessageTypeEnum, LLMConfig, NotificationTypeEnum, ReceiverHandlerMap, TextFileSelection, messageTimeout, };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e,t,s,i;!function(e){e.WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error"}(e||(e={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(t||(t={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(s||(s={})),function(e){e.public="public",e.private="private"}(i||(i={}));const n=3e5;class r{constructor(e,t,s){this.handlerMap=e,this.pendingTasks=t,this.moduleName=s}receiveMessage(t,s){if(this.moduleName===s.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${s.from}:\n ${JSON.stringify(s)}`),s.type===e.Abort){const e=s.id,t=this.pendingTasks.get(e);return void(t&&(console.log("Aborting task",e),t.controller.abort(),this.pendingTasks.delete(e)))}const i=this.handlerMap.get(s.type);if(i){const n=new AbortController,r=n.signal;this.pendingTasks.set(s.id,{controller:n});i(t,s,r).then((i=>{r.aborted||s.type!==e.Acknowledge&&this.acknowledgeSender(t,s.id,i)})).catch((i=>{const n={id:s.id,type:e.Error,payload:i.message,from:this.moduleName};t.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(s.id)}))}}acknowledgeSender(t,s,i){const n={id:s,type:e.Acknowledge,payload:i,from:this.moduleName};t.postMessage(n,"*")}}class o{constructor(e,t,s,i){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=i}async sendMessage(t,s,i){const n=(new Date).getTime().toString(),r={id:n,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(i?.aborted)return s(new Error("Request aborted"));const o=()=>{this.pendingMessages.delete(n),this.targetWindow.postMessage({id:n,type:e.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};i?.addEventListener("abort",o),this.pendingMessages.set(n,{resolve:t,reject:s}),this.targetWindow.postMessage(r,"*");const a=setTimeout((()=>{this.pendingMessages.delete(n),i?.removeEventListener("abort",o),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(n);d&&(d.resolve=e=>{clearTimeout(a),i?.removeEventListener("abort",o),t(e)},d.reject=()=>{clearTimeout(a),i?.removeEventListener("abort",o),s()})}))}}class a{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const t=new r(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=t,this.listener=e=>{if(!t)throw new Error("Receiver not initialized at module "+this.moduleName);const s=e.data,i=e.source;t.receiveMessage(i,s)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(t){this.otherWindow=t,this.otherPendingMessages=new Map;const s=new o(t,n,this.otherPendingMessages,this.moduleName);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.Acknowledge,(async(e,t)=>{const s=this.otherPendingMessages?.get(t.id);s&&(s.resolve(t.payload),this.otherPendingMessages?.delete(t.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,t,s){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,t,s)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,t)=>{this.receiverHandlerMap?.set(t,e)}))}}export{i as AccessEnum,s as ExtensionTypeEnum,e as IMCMessageTypeEnum,a as InterModuleCommunication,r as MessageReceiver,o as MessageSender,t as NotificationTypeEnum,n as messageTimeout};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulse-editor/shared-utils",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.4",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "rollup -c",
|
|
14
|
-
"lint": "eslint ."
|
|
13
|
+
"build": "npm run clean && rollup -c",
|
|
14
|
+
"lint": "eslint .",
|
|
15
|
+
"clean": "rimraf dist"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@babel/core": "^7.26.10",
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
24
25
|
"@types/node": "^22.13.1",
|
|
25
26
|
"eslint": "^9.25.0",
|
|
27
|
+
"rimraf": "^3.0.2",
|
|
26
28
|
"rollup": "^4.40.0",
|
|
27
29
|
"typescript": "^5.8.3",
|
|
28
30
|
"typescript-eslint": "^8.30.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../types/types.js"),s=require("../types/constants.js"),i=require("./message-receiver.js"),r=require("./message-sender.js");exports.InterModuleCommunication=class{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const s=new i.MessageReceiver(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=s,this.listener=e=>{if(!s)throw new Error("Receiver not initialized at module "+this.moduleName);const i=e.data,r=e.source;s.receiveMessage(r,i)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(i){this.otherWindow=i,this.otherPendingMessages=new Map;const t=new r.MessageSender(i,s.messageTimeout,this.otherPendingMessages,this.moduleName);if(this.sender=t,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.IMCMessageTypeEnum.Acknowledge,(async(e,s)=>{const i=this.otherPendingMessages?.get(s.id);i&&(i.resolve(s.payload),this.otherPendingMessages?.delete(s.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,s,i){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,s,i)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,s)=>{this.receiverHandlerMap?.set(s,e)}))}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../types/types.js");exports.MessageReceiver=class{constructor(e,s,t){this.handlerMap=e,this.pendingTasks=s,this.moduleName=t}receiveMessage(s,t){if(this.moduleName===t.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${t.from}:\n ${JSON.stringify(t)}`),t.type===e.IMCMessageTypeEnum.Abort){const e=t.id,s=this.pendingTasks.get(e);return void(s&&(console.log("Aborting task",e),s.controller.abort(),this.pendingTasks.delete(e)))}const o=this.handlerMap.get(t.type);if(o){const n=new AbortController,i=n.signal;this.pendingTasks.set(t.id,{controller:n});o(s,t,i).then((o=>{i.aborted||t.type!==e.IMCMessageTypeEnum.Acknowledge&&this.acknowledgeSender(s,t.id,o)})).catch((o=>{const n={id:t.id,type:e.IMCMessageTypeEnum.Error,payload:o.message,from:this.moduleName};s.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(t.id)}))}}acknowledgeSender(s,t,o){const n={id:t,type:e.IMCMessageTypeEnum.Acknowledge,payload:o,from:this.moduleName};s.postMessage(n,"*")}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../types/types.js");exports.MessageSender=class{constructor(e,t,s,r){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=r}async sendMessage(t,s,r){const i=(new Date).getTime().toString(),o={id:i,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(r?.aborted)return s(new Error("Request aborted"));const n=()=>{this.pendingMessages.delete(i),this.targetWindow.postMessage({id:i,type:e.IMCMessageTypeEnum.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};r?.addEventListener("abort",n),this.pendingMessages.set(i,{resolve:t,reject:s}),this.targetWindow.postMessage(o,"*");const a=setTimeout((()=>{this.pendingMessages.delete(i),r?.removeEventListener("abort",n),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(i);d&&(d.resolve=e=>{clearTimeout(a),r?.removeEventListener("abort",n),t(e)},d.reject=()=>{clearTimeout(a),r?.removeEventListener("abort",n),s()})}))}};
|
package/dist/cjs/main.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("./imc/inter-module-communication.js"),r=require("./imc/message-sender.js"),t=require("./imc/message-receiver.js"),n=require("./types/types.js"),s=require("./types/constants.js");exports.InterModuleCommunication=e.InterModuleCommunication,exports.MessageSender=r.MessageSender,exports.MessageReceiver=t.MessageReceiver,Object.defineProperty(exports,"AccessEnum",{enumerable:!0,get:function(){return n.AccessEnum}}),Object.defineProperty(exports,"ExtensionTypeEnum",{enumerable:!0,get:function(){return n.ExtensionTypeEnum}}),Object.defineProperty(exports,"IMCMessageTypeEnum",{enumerable:!0,get:function(){return n.IMCMessageTypeEnum}}),Object.defineProperty(exports,"NotificationTypeEnum",{enumerable:!0,get:function(){return n.NotificationTypeEnum}}),exports.messageTimeout=s.messageTimeout;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";exports.messageTimeout=3e5;
|
package/dist/cjs/types/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e,t,i,n;exports.IMCMessageTypeEnum=void 0,(e=exports.IMCMessageTypeEnum||(exports.IMCMessageTypeEnum={})).WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error",exports.NotificationTypeEnum=void 0,(t=exports.NotificationTypeEnum||(exports.NotificationTypeEnum={})).Success="success",t.Error="error",t.Info="info",t.Warning="warning",exports.ExtensionTypeEnum=void 0,(i=exports.ExtensionTypeEnum||(exports.ExtensionTypeEnum={})).Generic="generic",i.FileView="file-view",i.ConsoleView="console-view",exports.AccessEnum=void 0,(n=exports.AccessEnum||(exports.AccessEnum={})).public="public",n.private="private";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IMCMessageTypeEnum as e}from"../types/types.js";import{messageTimeout as s}from"../types/constants.js";import{MessageReceiver as i}from"./message-receiver.js";import{MessageSender as t}from"./message-sender.js";class r{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const s=new i(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=s,this.listener=e=>{if(!s)throw new Error("Receiver not initialized at module "+this.moduleName);const i=e.data,t=e.source;s.receiveMessage(t,i)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(i){this.otherWindow=i,this.otherPendingMessages=new Map;const r=new t(i,s,this.otherPendingMessages,this.moduleName);if(this.sender=r,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.Acknowledge,(async(e,s)=>{const i=this.otherPendingMessages?.get(s.id);i&&(i.resolve(s.payload),this.otherPendingMessages?.delete(s.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,s,i){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,s,i)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,s)=>{this.receiverHandlerMap?.set(s,e)}))}}export{r as InterModuleCommunication};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IMCMessageTypeEnum as e}from"../types/types.js";class s{constructor(e,s,o){this.handlerMap=e,this.pendingTasks=s,this.moduleName=o}receiveMessage(s,o){if(this.moduleName===o.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${o.from}:\n ${JSON.stringify(o)}`),o.type===e.Abort){const e=o.id,s=this.pendingTasks.get(e);return void(s&&(console.log("Aborting task",e),s.controller.abort(),this.pendingTasks.delete(e)))}const t=this.handlerMap.get(o.type);if(t){const n=new AbortController,i=n.signal;this.pendingTasks.set(o.id,{controller:n});t(s,o,i).then((t=>{i.aborted||o.type!==e.Acknowledge&&this.acknowledgeSender(s,o.id,t)})).catch((t=>{const n={id:o.id,type:e.Error,payload:t.message,from:this.moduleName};s.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(o.id)}))}}acknowledgeSender(s,o,t){const n={id:o,type:e.Acknowledge,payload:t,from:this.moduleName};s.postMessage(n,"*")}}export{s as MessageReceiver};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IMCMessageTypeEnum as e}from"../types/types.js";class t{constructor(e,t,s,r){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=r}async sendMessage(t,s,r){const o=(new Date).getTime().toString(),i={id:o,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(r?.aborted)return s(new Error("Request aborted"));const n=()=>{this.pendingMessages.delete(o),this.targetWindow.postMessage({id:o,type:e.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};r?.addEventListener("abort",n),this.pendingMessages.set(o,{resolve:t,reject:s}),this.targetWindow.postMessage(i,"*");const a=setTimeout((()=>{this.pendingMessages.delete(o),r?.removeEventListener("abort",n),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(o);d&&(d.resolve=e=>{clearTimeout(a),r?.removeEventListener("abort",n),t(e)},d.reject=()=>{clearTimeout(a),r?.removeEventListener("abort",n),s()})}))}}export{t as MessageSender};
|
package/dist/esm/main.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{InterModuleCommunication}from"./imc/inter-module-communication.js";export{MessageSender}from"./imc/message-sender.js";export{MessageReceiver}from"./imc/message-receiver.js";export{AccessEnum,ExtensionTypeEnum,IMCMessageTypeEnum,NotificationTypeEnum}from"./types/types.js";export{messageTimeout}from"./types/constants.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=3e5;export{e as messageTimeout};
|
package/dist/esm/types/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e,i,n,t;!function(e){e.WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error"}(e||(e={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(i||(i={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(n||(n={})),function(e){e.public="public",e.private="private"}(t||(t={}));export{t as AccessEnum,n as ExtensionTypeEnum,e as IMCMessageTypeEnum,i as NotificationTypeEnum};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IMCMessageTypeEnum as e}from"../types/types.js";import{messageTimeout as s}from"../types/constants.js";import{MessageReceiver as i}from"./message-receiver.js";import{MessageSender as t}from"./message-sender.js";class r{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const s=new i(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=s,this.listener=e=>{if(!s)throw new Error("Receiver not initialized at module "+this.moduleName);const i=e.data,t=e.source;s.receiveMessage(t,i)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(i){this.otherWindow=i,this.otherPendingMessages=new Map;const r=new t(i,s,this.otherPendingMessages,this.moduleName);if(this.sender=r,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.Acknowledge,(async(e,s)=>{const i=this.otherPendingMessages?.get(s.id);i&&(i.resolve(s.payload),this.otherPendingMessages?.delete(s.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,s,i){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,s,i)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,s)=>{this.receiverHandlerMap?.set(s,e)}))}}export{r as InterModuleCommunication};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IMCMessageTypeEnum as e}from"../types/types.js";class s{constructor(e,s,o){this.handlerMap=e,this.pendingTasks=s,this.moduleName=o}receiveMessage(s,o){if(this.moduleName===o.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${o.from}:\n ${JSON.stringify(o)}`),o.type===e.Abort){const e=o.id,s=this.pendingTasks.get(e);return void(s&&(console.log("Aborting task",e),s.controller.abort(),this.pendingTasks.delete(e)))}const t=this.handlerMap.get(o.type);if(t){const n=new AbortController,i=n.signal;this.pendingTasks.set(o.id,{controller:n});t(s,o,i).then((t=>{i.aborted||o.type!==e.Acknowledge&&this.acknowledgeSender(s,o.id,t)})).catch((t=>{const n={id:o.id,type:e.Error,payload:t.message,from:this.moduleName};s.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(o.id)}))}}acknowledgeSender(s,o,t){const n={id:o,type:e.Acknowledge,payload:t,from:this.moduleName};s.postMessage(n,"*")}}export{s as MessageReceiver};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IMCMessageTypeEnum as e}from"../types/types.js";class t{constructor(e,t,s,r){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=r}async sendMessage(t,s,r){const o=(new Date).getTime().toString(),i={id:o,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(r?.aborted)return s(new Error("Request aborted"));const n=()=>{this.pendingMessages.delete(o),this.targetWindow.postMessage({id:o,type:e.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};r?.addEventListener("abort",n),this.pendingMessages.set(o,{resolve:t,reject:s}),this.targetWindow.postMessage(i,"*");const a=setTimeout((()=>{this.pendingMessages.delete(o),r?.removeEventListener("abort",n),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(o);d&&(d.resolve=e=>{clearTimeout(a),r?.removeEventListener("abort",n),t(e)},d.reject=()=>{clearTimeout(a),r?.removeEventListener("abort",n),s()})}))}}export{t as MessageSender};
|
package/dist/main.es.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e,t,s,i;!function(e){e.WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error"}(e||(e={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(t||(t={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(s||(s={})),function(e){e.public="public",e.private="private"}(i||(i={}));const n=3e5;class r{constructor(e,t,s){this.handlerMap=e,this.pendingTasks=t,this.moduleName=s}receiveMessage(t,s){if(this.moduleName===s.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${s.from}:\n ${JSON.stringify(s)}`),s.type===e.Abort){const e=s.id,t=this.pendingTasks.get(e);return void(t&&(console.log("Aborting task",e),t.controller.abort(),this.pendingTasks.delete(e)))}const i=this.handlerMap.get(s.type);if(i){const n=new AbortController,r=n.signal;this.pendingTasks.set(s.id,{controller:n});i(t,s,r).then((i=>{r.aborted||s.type!==e.Acknowledge&&this.acknowledgeSender(t,s.id,i)})).catch((i=>{const n={id:s.id,type:e.Error,payload:i.message,from:this.moduleName};t.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(s.id)}))}}acknowledgeSender(t,s,i){const n={id:s,type:e.Acknowledge,payload:i,from:this.moduleName};t.postMessage(n,"*")}}class o{constructor(e,t,s,i){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=i}async sendMessage(t,s,i){const n=(new Date).getTime().toString(),r={id:n,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(i?.aborted)return s(new Error("Request aborted"));const o=()=>{this.pendingMessages.delete(n),this.targetWindow.postMessage({id:n,type:e.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};i?.addEventListener("abort",o),this.pendingMessages.set(n,{resolve:t,reject:s}),this.targetWindow.postMessage(r,"*");const a=setTimeout((()=>{this.pendingMessages.delete(n),i?.removeEventListener("abort",o),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(n);d&&(d.resolve=e=>{clearTimeout(a),i?.removeEventListener("abort",o),t(e)},d.reject=()=>{clearTimeout(a),i?.removeEventListener("abort",o),s()})}))}}class a{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const t=new r(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=t,this.listener=e=>{if(!t)throw new Error("Receiver not initialized at module "+this.moduleName);const s=e.data,i=e.source;t.receiveMessage(i,s)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(t){this.otherWindow=t,this.otherPendingMessages=new Map;const s=new o(t,n,this.otherPendingMessages,this.moduleName);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.Acknowledge,(async(e,t)=>{const s=this.otherPendingMessages?.get(t.id);s&&(s.resolve(t.payload),this.otherPendingMessages?.delete(t.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,t,s){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,t,s)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,t)=>{this.receiverHandlerMap?.set(t,e)}))}}export{i as AccessEnum,s as ExtensionTypeEnum,e as IMCMessageTypeEnum,a as InterModuleCommunication,r as MessageReceiver,o as MessageSender,t as NotificationTypeEnum,n as messageTimeout};
|
package/dist/types/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=3e5;export{e as messageTimeout};
|
package/dist/types/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e,i,n,t;!function(e){e.WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error"}(e||(e={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(i||(i={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(n||(n={})),function(e){e.public="public",e.private="private"}(t||(t={}));export{t as AccessEnum,n as ExtensionTypeEnum,e as IMCMessageTypeEnum,i as NotificationTypeEnum};
|