hypha-rpc 0.20.23 → 0.20.25

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.
@@ -1763,6 +1763,7 @@ __webpack_require__.r(__webpack_exports__);
1763
1763
  /* harmony export */ loadRequirementsInWebworker: () => (/* binding */ loadRequirementsInWebworker),
1764
1764
  /* harmony export */ loadRequirementsInWindow: () => (/* binding */ loadRequirementsInWindow),
1765
1765
  /* harmony export */ normalizeConfig: () => (/* binding */ normalizeConfig),
1766
+ /* harmony export */ parseServiceUrl: () => (/* binding */ parseServiceUrl),
1766
1767
  /* harmony export */ randId: () => (/* binding */ randId),
1767
1768
  /* harmony export */ toCamelCase: () => (/* binding */ toCamelCase),
1768
1769
  /* harmony export */ toSnakeCase: () => (/* binding */ toSnakeCase),
@@ -1835,6 +1836,34 @@ function convertCase(obj, caseType) {
1835
1836
  return newObj;
1836
1837
  }
1837
1838
 
1839
+ function parseServiceUrl(url) {
1840
+ // Ensure no trailing slash
1841
+ url = url.replace(/\/$/, "");
1842
+
1843
+ // Regex pattern to match the URL structure
1844
+ const pattern = new RegExp(
1845
+ "^(https?:\\/\\/[^/]+)" + // server_url (http or https followed by domain)
1846
+ "\\/([a-z0-9_-]+)" + // workspace (lowercase letters, numbers, - or _)
1847
+ "\\/services\\/" + // static part of the URL
1848
+ "(?:(?<clientId>[a-zA-Z0-9_-]+):)?" + // optional client_id
1849
+ "(?<serviceId>[a-zA-Z0-9_-]+)" + // service_id
1850
+ "(?:@(?<appId>[a-zA-Z0-9_-]+))?", // optional app_id
1851
+ );
1852
+
1853
+ const match = url.match(pattern);
1854
+ if (!match) {
1855
+ throw new Error("URL does not match the expected pattern");
1856
+ }
1857
+
1858
+ const serverUrl = match[1];
1859
+ const workspace = match[2];
1860
+ const clientId = match.groups?.clientId || "*";
1861
+ const serviceId = match.groups?.serviceId;
1862
+ const appId = match.groups?.appId || "*";
1863
+
1864
+ return { serverUrl, workspace, clientId, serviceId, appId };
1865
+ }
1866
+
1838
1867
  const dtypeToTypedArray = {
1839
1868
  int8: Int8Array,
1840
1869
  int16: Int16Array,
@@ -4467,6 +4496,7 @@ __webpack_require__.r(__webpack_exports__);
4467
4496
  /* harmony export */ RPC: () => (/* reexport safe */ _rpc_js__WEBPACK_IMPORTED_MODULE_0__.RPC),
4468
4497
  /* harmony export */ connectToServer: () => (/* binding */ connectToServer),
4469
4498
  /* harmony export */ getRTCService: () => (/* reexport safe */ _webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.getRTCService),
4499
+ /* harmony export */ getRemoteService: () => (/* binding */ getRemoteService),
4470
4500
  /* harmony export */ loadRequirements: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.loadRequirements),
4471
4501
  /* harmony export */ login: () => (/* binding */ login),
4472
4502
  /* harmony export */ registerRTCService: () => (/* reexport safe */ _webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.registerRTCService),
@@ -4985,6 +5015,7 @@ async function connectToServer(config) {
4985
5015
  },
4986
5016
  },
4987
5017
  });
5018
+
4988
5019
  wm.emit = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(rpc.emit.bind(rpc), {
4989
5020
  name: "emit",
4990
5021
  description: "Emit a message.",
@@ -4994,6 +5025,7 @@ async function connectToServer(config) {
4994
5025
  type: "object",
4995
5026
  },
4996
5027
  });
5028
+
4997
5029
  wm.on = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(rpc.on.bind(rpc), {
4998
5030
  name: "on",
4999
5031
  description: "Register a message handler.",
@@ -5006,6 +5038,33 @@ async function connectToServer(config) {
5006
5038
  type: "object",
5007
5039
  },
5008
5040
  });
5041
+
5042
+ wm.off = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(rpc.off.bind(rpc), {
5043
+ name: "off",
5044
+ description: "Remove a message handler.",
5045
+ parameters: {
5046
+ properties: {
5047
+ event: { description: "The event to remove", type: "string" },
5048
+ handler: { description: "The handler function", type: "function" },
5049
+ },
5050
+ required: ["event", "handler"],
5051
+ type: "object",
5052
+ },
5053
+ });
5054
+
5055
+ wm.once = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(rpc.once.bind(rpc), {
5056
+ name: "once",
5057
+ description: "Register a one-time message handler.",
5058
+ parameters: {
5059
+ properties: {
5060
+ event: { description: "The event to listen to", type: "string" },
5061
+ handler: { description: "The handler function", type: "function" },
5062
+ },
5063
+ required: ["event", "handler"],
5064
+ type: "object",
5065
+ },
5066
+ });
5067
+
5009
5068
  wm.getServiceSchema = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(rpc.get_service_schema, {
5010
5069
  name: "getServiceSchema",
5011
5070
  description: "Get the service schema.",
@@ -5131,6 +5190,23 @@ async function connectToServer(config) {
5131
5190
  return wm;
5132
5191
  }
5133
5192
 
5193
+ async function getRemoteService(url, config = {}) {
5194
+ const { serverUrl, workspace, clientId, serviceId, appId } =
5195
+ (0,_utils__WEBPACK_IMPORTED_MODULE_1__.parseServiceUrl)(url);
5196
+ const fullServiceId = `${workspace}/${clientId}:${serviceId}@${appId}`;
5197
+
5198
+ if (config.serverUrl) {
5199
+ if (config.serverUrl !== serverUrl) {
5200
+ throw new Error(
5201
+ "server_url in config does not match the server_url in the url",
5202
+ );
5203
+ }
5204
+ }
5205
+ config.serverUrl = serverUrl;
5206
+ const server = await connectToServer(config);
5207
+ return await server.getService(fullServiceId);
5208
+ }
5209
+
5134
5210
  class LocalWebSocket {
5135
5211
  constructor(url, client_id, workspace) {
5136
5212
  this.url = url;