@meetploy/emulator 1.17.0 → 1.17.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.
@@ -1 +1 @@
1
- export declare const STATE_RUNTIME_CODE = "\ninterface StateUpdateDoc {\n $set?: Record<string, unknown>;\n $unset?: Record<string, unknown>;\n $inc?: Record<string, number>;\n $push?: Record<string, unknown>;\n $pop?: Record<string, 1 | -1>;\n}\n\ninterface StateBinding {\n get: (key: string) => Promise<string | null>;\n set: (key: string, value: string) => Promise<void>;\n delete: (key: string) => Promise<void>;\n update: (key: string, update: StateUpdateDoc) => Promise<void>;\n}\n\nexport function initializeState(stateName: string, serviceUrl: string): StateBinding {\n return {\n async get(key: string): Promise<string | null> {\n const response = await fetch(serviceUrl + \"/state/get\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ stateName, key }),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\"State get failed: \" + errorText);\n }\n\n const result = await response.json();\n return result.value ?? null;\n },\n\n async set(key: string, value: string): Promise<void> {\n const response = await fetch(serviceUrl + \"/state/set\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ stateName, key, value }),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\"State set failed: \" + errorText);\n }\n },\n\n async delete(key: string): Promise<void> {\n const response = await fetch(serviceUrl + \"/state/delete\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ stateName, key }),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\"State delete failed: \" + errorText);\n }\n },\n\n async update(key: string, update: StateUpdateDoc): Promise<void> {\n const response = await fetch(serviceUrl + \"/state/update\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ stateName, key, update }),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\"State update failed: \" + errorText);\n }\n },\n };\n}\n";
1
+ export declare const STATE_RUNTIME_CODE = "\ninterface StateUpdateDoc {\n $set?: Record<string, unknown>;\n $unset?: Record<string, unknown>;\n $inc?: Record<string, number>;\n $push?: Record<string, unknown>;\n $pop?: Record<string, 1 | -1>;\n}\n\ninterface StateBinding {\n get: (key: string) => Promise<string | null>;\n set: (key: string, value: string) => Promise<void>;\n delete: (key: string) => Promise<void>;\n update: (key: string, update: StateUpdateDoc) => Promise<void>;\n}\n\nfunction getErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction createStateRequestError(action: string, endpoint: string, error: unknown): Error {\n const message = \"State \" + action + \" failed while calling \" + endpoint + \": \" + getErrorMessage(error);\n if (error instanceof Error) {\n return new Error(message, { cause: error });\n }\n return new Error(message);\n}\n\nasync function requestState(action: string, serviceUrl: string, payload: Record<string, unknown>): Promise<Response> {\n const endpoint = serviceUrl + \"/state/\" + action;\n let response: Response;\n\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(payload),\n });\n } catch (error) {\n throw createStateRequestError(action, endpoint, error);\n }\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n \"State \" + action + \" failed (status \" + response.status + \" \" + response.statusText + \") from \" + endpoint + \": \" + (errorText || \"empty response body\"),\n );\n }\n\n return response;\n}\n\nexport function initializeState(stateName: string, serviceUrl: string): StateBinding {\n return {\n async get(key: string): Promise<string | null> {\n const response = await requestState(\"get\", serviceUrl, { stateName, key });\n const result = await response.json();\n return result.value ?? null;\n },\n\n async set(key: string, value: string): Promise<void> {\n await requestState(\"set\", serviceUrl, { stateName, key, value });\n },\n\n async delete(key: string): Promise<void> {\n await requestState(\"delete\", serviceUrl, { stateName, key });\n },\n\n async update(key: string, update: StateUpdateDoc): Promise<void> {\n await requestState(\"update\", serviceUrl, { stateName, key, update });\n },\n };\n}\n";
@@ -14,61 +14,60 @@ interface StateBinding {
14
14
  update: (key: string, update: StateUpdateDoc) => Promise<void>;
15
15
  }
16
16
 
17
+ function getErrorMessage(error: unknown): string {
18
+ return error instanceof Error ? error.message : String(error);
19
+ }
20
+
21
+ function createStateRequestError(action: string, endpoint: string, error: unknown): Error {
22
+ const message = "State " + action + " failed while calling " + endpoint + ": " + getErrorMessage(error);
23
+ if (error instanceof Error) {
24
+ return new Error(message, { cause: error });
25
+ }
26
+ return new Error(message);
27
+ }
28
+
29
+ async function requestState(action: string, serviceUrl: string, payload: Record<string, unknown>): Promise<Response> {
30
+ const endpoint = serviceUrl + "/state/" + action;
31
+ let response: Response;
32
+
33
+ try {
34
+ response = await fetch(endpoint, {
35
+ method: "POST",
36
+ headers: { "Content-Type": "application/json" },
37
+ body: JSON.stringify(payload),
38
+ });
39
+ } catch (error) {
40
+ throw createStateRequestError(action, endpoint, error);
41
+ }
42
+
43
+ if (!response.ok) {
44
+ const errorText = await response.text();
45
+ throw new Error(
46
+ "State " + action + " failed (status " + response.status + " " + response.statusText + ") from " + endpoint + ": " + (errorText || "empty response body"),
47
+ );
48
+ }
49
+
50
+ return response;
51
+ }
52
+
17
53
  export function initializeState(stateName: string, serviceUrl: string): StateBinding {
18
54
  return {
19
55
  async get(key: string): Promise<string | null> {
20
- const response = await fetch(serviceUrl + "/state/get", {
21
- method: "POST",
22
- headers: { "Content-Type": "application/json" },
23
- body: JSON.stringify({ stateName, key }),
24
- });
25
-
26
- if (!response.ok) {
27
- const errorText = await response.text();
28
- throw new Error("State get failed: " + errorText);
29
- }
30
-
56
+ const response = await requestState("get", serviceUrl, { stateName, key });
31
57
  const result = await response.json();
32
58
  return result.value ?? null;
33
59
  },
34
60
 
35
61
  async set(key: string, value: string): Promise<void> {
36
- const response = await fetch(serviceUrl + "/state/set", {
37
- method: "POST",
38
- headers: { "Content-Type": "application/json" },
39
- body: JSON.stringify({ stateName, key, value }),
40
- });
41
-
42
- if (!response.ok) {
43
- const errorText = await response.text();
44
- throw new Error("State set failed: " + errorText);
45
- }
62
+ await requestState("set", serviceUrl, { stateName, key, value });
46
63
  },
47
64
 
48
65
  async delete(key: string): Promise<void> {
49
- const response = await fetch(serviceUrl + "/state/delete", {
50
- method: "POST",
51
- headers: { "Content-Type": "application/json" },
52
- body: JSON.stringify({ stateName, key }),
53
- });
54
-
55
- if (!response.ok) {
56
- const errorText = await response.text();
57
- throw new Error("State delete failed: " + errorText);
58
- }
66
+ await requestState("delete", serviceUrl, { stateName, key });
59
67
  },
60
68
 
61
69
  async update(key: string, update: StateUpdateDoc): Promise<void> {
62
- const response = await fetch(serviceUrl + "/state/update", {
63
- method: "POST",
64
- headers: { "Content-Type": "application/json" },
65
- body: JSON.stringify({ stateName, key, update }),
66
- });
67
-
68
- if (!response.ok) {
69
- const errorText = await response.text();
70
- throw new Error("State update failed: " + errorText);
71
- }
70
+ await requestState("update", serviceUrl, { stateName, key, update });
72
71
  },
73
72
  };
74
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"state-runtime.js","sourceRoot":"","sources":["../../src/runtime/state-runtime.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0EjC,CAAC"}
1
+ {"version":3,"file":"state-runtime.js","sourceRoot":"","sources":["../../src/runtime/state-runtime.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyEjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetploy/emulator",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",