@restatedev/restate-sdk 1.16.0 → 1.16.2

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.
@@ -30,6 +30,21 @@ function vm_log(level, strBytes, loggerId) {
30
30
  }, "Unexpected error thrown while trying to log: " + e?.toString());
31
31
  }
32
32
  }
33
+ /**
34
+ * Invoked by the shared core's panic hook when it hits a rust panic.
35
+ */
36
+ function fatal(message) {
37
+ try {
38
+ const stack = (/* @__PURE__ */ new Error()).stack;
39
+ require_console_logger_transport.defaultLoggerTransport({
40
+ level: require_logger_transport.RestateLogLevel.ERROR,
41
+ replaying: false,
42
+ source: require_logger_transport.LogSource.SYSTEM
43
+ }, "FATAL: the SDK shared-core panicked, terminating the process. Reason: \n" + message + (stack ? "\n\nStack:\n" + stack : ""));
44
+ const proc = globalThis.process;
45
+ if (typeof proc?.exit === "function") proc.exit(1);
46
+ } catch {}
47
+ }
33
48
  function registerLogger(loggerId, logger) {
34
49
  invocationLoggers.set(loggerId, logger);
35
50
  }
@@ -48,5 +63,6 @@ function wasmLogLevelToRestateLogLevel(level) {
48
63
 
49
64
  //#endregion
50
65
  exports.destroyLogger = destroyLogger;
66
+ exports.fatal = fatal;
51
67
  exports.registerLogger = registerLogger;
52
68
  exports.vm_log = vm_log;
@@ -5,6 +5,10 @@ import * as vm from "./vm/sdk_shared_core_wasm_bindings.js";
5
5
  * When possible, it provides an invocationId, which is used to access the registered invocationLoggers, that should contain the logger per invocation id.
6
6
  */
7
7
  export declare function vm_log(level: vm.LogLevel, strBytes: Uint8Array, loggerId?: number): void;
8
+ /**
9
+ * Invoked by the shared core's panic hook when it hits a rust panic.
10
+ */
11
+ export declare function fatal(message: string): void;
8
12
  export declare function registerLogger(loggerId: number, logger: Logger): void;
9
13
  export declare function destroyLogger(loggerId: number): void;
10
14
  //# sourceMappingURL=core_logging.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core_logging.d.ts","sourceRoot":"","sources":["../../../src/endpoint/handlers/core_logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM,uCAAuC,CAAC;AAU5D;;;GAGG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,EAAE,CAAC,QAAQ,EAClB,QAAQ,EAAE,UAAU,EACpB,QAAQ,CAAC,EAAE,MAAM,QA6BlB;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAE9D;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,QAE7C"}
1
+ {"version":3,"file":"core_logging.d.ts","sourceRoot":"","sources":["../../../src/endpoint/handlers/core_logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM,uCAAuC,CAAC;AAU5D;;;GAGG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,EAAE,CAAC,QAAQ,EAClB,QAAQ,EAAE,UAAU,EACpB,QAAQ,CAAC,EAAE,MAAM,QA6BlB;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,QAyBpC;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAE9D;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,QAE7C"}
@@ -30,6 +30,21 @@ function vm_log(level, strBytes, loggerId) {
30
30
  }, "Unexpected error thrown while trying to log: " + e?.toString());
31
31
  }
32
32
  }
33
+ /**
34
+ * Invoked by the shared core's panic hook when it hits a rust panic.
35
+ */
36
+ function fatal(message) {
37
+ try {
38
+ const stack = (/* @__PURE__ */ new Error()).stack;
39
+ defaultLoggerTransport({
40
+ level: RestateLogLevel.ERROR,
41
+ replaying: false,
42
+ source: LogSource.SYSTEM
43
+ }, "FATAL: the SDK shared-core panicked, terminating the process. Reason: \n" + message + (stack ? "\n\nStack:\n" + stack : ""));
44
+ const proc = globalThis.process;
45
+ if (typeof proc?.exit === "function") proc.exit(1);
46
+ } catch {}
47
+ }
33
48
  function registerLogger(loggerId, logger) {
34
49
  invocationLoggers.set(loggerId, logger);
35
50
  }
@@ -47,5 +62,5 @@ function wasmLogLevelToRestateLogLevel(level) {
47
62
  }
48
63
 
49
64
  //#endregion
50
- export { destroyLogger, registerLogger, vm_log };
65
+ export { destroyLogger, fatal, registerLogger, vm_log };
51
66
  //# sourceMappingURL=core_logging.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core_logging.js","names":["invocationLoggers: Map<number, Logger>"],"sources":["../../../src/endpoint/handlers/core_logging.ts"],"sourcesContent":["import { Logger } from \"../../logging/logger.js\";\nimport { LogSource, RestateLogLevel } from \"../../logging/logger_transport.js\";\nimport * as vm from \"./vm/sdk_shared_core_wasm_bindings.js\";\nimport { defaultLoggerTransport } from \"../../logging/console_logger_transport.js\";\n\n/**\n * This file contains the shared state used to install a logger that the shared-core uses for logging.\n */\n\nconst invocationLoggers: Map<number, Logger> = new Map<number, Logger>();\nconst logsTextDecoder = new TextDecoder(\"utf-8\", { fatal: false });\n\n/**\n * The shared core propagates logs to the SDK invoking this method.\n * When possible, it provides an invocationId, which is used to access the registered invocationLoggers, that should contain the logger per invocation id.\n */\nexport function vm_log(\n level: vm.LogLevel,\n strBytes: Uint8Array,\n loggerId?: number\n) {\n try {\n const logger = (loggerId && invocationLoggers.get(loggerId)) || undefined;\n const str = logsTextDecoder.decode(strBytes);\n if (logger !== undefined) {\n logger.logForLevel(wasmLogLevelToRestateLogLevel(level), str);\n } else {\n defaultLoggerTransport(\n {\n level: wasmLogLevelToRestateLogLevel(level),\n replaying: false,\n source: LogSource.JOURNAL,\n },\n str\n );\n }\n } catch (e) {\n // This function CAN'T EVER propagate an error,\n // because otherwise it will cause an awesome error in the shared core due to concurrent usage of it.\n defaultLoggerTransport(\n {\n level: RestateLogLevel.ERROR,\n replaying: false,\n source: LogSource.SYSTEM,\n },\n \"Unexpected error thrown while trying to log: \" + e?.toString()\n );\n }\n}\n\nexport function registerLogger(loggerId: number, logger: Logger) {\n invocationLoggers.set(loggerId, logger);\n}\n\nexport function destroyLogger(loggerId: number) {\n invocationLoggers.delete(loggerId);\n}\n\nfunction wasmLogLevelToRestateLogLevel(level: vm.LogLevel): RestateLogLevel {\n switch (level) {\n case vm.LogLevel.TRACE:\n return RestateLogLevel.TRACE;\n case vm.LogLevel.DEBUG:\n return RestateLogLevel.DEBUG;\n case vm.LogLevel.INFO:\n return RestateLogLevel.INFO;\n case vm.LogLevel.WARN:\n return RestateLogLevel.WARN;\n case vm.LogLevel.ERROR:\n return RestateLogLevel.ERROR;\n }\n}\n"],"mappings":";;;;;;;;AASA,MAAMA,oCAAyC,IAAI,KAAqB;AACxE,MAAM,kBAAkB,IAAI,YAAY,SAAS,EAAE,OAAO,OAAO,CAAC;;;;;AAMlE,SAAgB,OACd,OACA,UACA,UACA;AACA,KAAI;EACF,MAAM,SAAU,YAAY,kBAAkB,IAAI,SAAS,IAAK;EAChE,MAAM,MAAM,gBAAgB,OAAO,SAAS;AAC5C,MAAI,WAAW,OACb,QAAO,YAAY,8BAA8B,MAAM,EAAE,IAAI;MAE7D,wBACE;GACE,OAAO,8BAA8B,MAAM;GAC3C,WAAW;GACX,QAAQ,UAAU;GACnB,EACD,IACD;UAEI,GAAG;AAGV,yBACE;GACE,OAAO,gBAAgB;GACvB,WAAW;GACX,QAAQ,UAAU;GACnB,EACD,kDAAkD,GAAG,UAAU,CAChE;;;AAIL,SAAgB,eAAe,UAAkB,QAAgB;AAC/D,mBAAkB,IAAI,UAAU,OAAO;;AAGzC,SAAgB,cAAc,UAAkB;AAC9C,mBAAkB,OAAO,SAAS;;AAGpC,SAAS,8BAA8B,OAAqC;AAC1E,SAAQ,OAAR;EACE,cAAiB,MACf,QAAO,gBAAgB;EACzB,cAAiB,MACf,QAAO,gBAAgB;EACzB,cAAiB,KACf,QAAO,gBAAgB;EACzB,cAAiB,KACf,QAAO,gBAAgB;EACzB,cAAiB,MACf,QAAO,gBAAgB"}
1
+ {"version":3,"file":"core_logging.js","names":["invocationLoggers: Map<number, Logger>"],"sources":["../../../src/endpoint/handlers/core_logging.ts"],"sourcesContent":["import { Logger } from \"../../logging/logger.js\";\nimport { LogSource, RestateLogLevel } from \"../../logging/logger_transport.js\";\nimport * as vm from \"./vm/sdk_shared_core_wasm_bindings.js\";\nimport { defaultLoggerTransport } from \"../../logging/console_logger_transport.js\";\n\n/**\n * This file contains the shared state used to install a logger that the shared-core uses for logging.\n */\n\nconst invocationLoggers: Map<number, Logger> = new Map<number, Logger>();\nconst logsTextDecoder = new TextDecoder(\"utf-8\", { fatal: false });\n\n/**\n * The shared core propagates logs to the SDK invoking this method.\n * When possible, it provides an invocationId, which is used to access the registered invocationLoggers, that should contain the logger per invocation id.\n */\nexport function vm_log(\n level: vm.LogLevel,\n strBytes: Uint8Array,\n loggerId?: number\n) {\n try {\n const logger = (loggerId && invocationLoggers.get(loggerId)) || undefined;\n const str = logsTextDecoder.decode(strBytes);\n if (logger !== undefined) {\n logger.logForLevel(wasmLogLevelToRestateLogLevel(level), str);\n } else {\n defaultLoggerTransport(\n {\n level: wasmLogLevelToRestateLogLevel(level),\n replaying: false,\n source: LogSource.JOURNAL,\n },\n str\n );\n }\n } catch (e) {\n // This function CAN'T EVER propagate an error,\n // because otherwise it will cause an awesome error in the shared core due to concurrent usage of it.\n defaultLoggerTransport(\n {\n level: RestateLogLevel.ERROR,\n replaying: false,\n source: LogSource.SYSTEM,\n },\n \"Unexpected error thrown while trying to log: \" + e?.toString()\n );\n }\n}\n\n/**\n * Invoked by the shared core's panic hook when it hits a rust panic.\n */\nexport function fatal(message: string) {\n try {\n const stack = new Error().stack;\n defaultLoggerTransport(\n {\n level: RestateLogLevel.ERROR,\n replaying: false,\n source: LogSource.SYSTEM,\n },\n \"FATAL: the SDK shared-core panicked, terminating the process. Reason: \\n\" +\n message +\n (stack ? \"\\n\\nStack:\\n\" + stack : \"\")\n );\n\n const proc = (\n globalThis as typeof globalThis & {\n process?: { exit?: (code?: number) => never };\n }\n ).process;\n if (typeof proc?.exit === \"function\") {\n proc.exit(1);\n }\n } catch {\n // Never throw back into the panic hook (would trigger a double-panic abort).\n }\n}\n\nexport function registerLogger(loggerId: number, logger: Logger) {\n invocationLoggers.set(loggerId, logger);\n}\n\nexport function destroyLogger(loggerId: number) {\n invocationLoggers.delete(loggerId);\n}\n\nfunction wasmLogLevelToRestateLogLevel(level: vm.LogLevel): RestateLogLevel {\n switch (level) {\n case vm.LogLevel.TRACE:\n return RestateLogLevel.TRACE;\n case vm.LogLevel.DEBUG:\n return RestateLogLevel.DEBUG;\n case vm.LogLevel.INFO:\n return RestateLogLevel.INFO;\n case vm.LogLevel.WARN:\n return RestateLogLevel.WARN;\n case vm.LogLevel.ERROR:\n return RestateLogLevel.ERROR;\n }\n}\n"],"mappings":";;;;;;;;AASA,MAAMA,oCAAyC,IAAI,KAAqB;AACxE,MAAM,kBAAkB,IAAI,YAAY,SAAS,EAAE,OAAO,OAAO,CAAC;;;;;AAMlE,SAAgB,OACd,OACA,UACA,UACA;AACA,KAAI;EACF,MAAM,SAAU,YAAY,kBAAkB,IAAI,SAAS,IAAK;EAChE,MAAM,MAAM,gBAAgB,OAAO,SAAS;AAC5C,MAAI,WAAW,OACb,QAAO,YAAY,8BAA8B,MAAM,EAAE,IAAI;MAE7D,wBACE;GACE,OAAO,8BAA8B,MAAM;GAC3C,WAAW;GACX,QAAQ,UAAU;GACnB,EACD,IACD;UAEI,GAAG;AAGV,yBACE;GACE,OAAO,gBAAgB;GACvB,WAAW;GACX,QAAQ,UAAU;GACnB,EACD,kDAAkD,GAAG,UAAU,CAChE;;;;;;AAOL,SAAgB,MAAM,SAAiB;AACrC,KAAI;EACF,MAAM,yBAAQ,IAAI,OAAO,EAAC;AAC1B,yBACE;GACE,OAAO,gBAAgB;GACvB,WAAW;GACX,QAAQ,UAAU;GACnB,EACD,6EACE,WACC,QAAQ,iBAAiB,QAAQ,IACrC;EAED,MAAM,OACJ,WAGA;AACF,MAAI,OAAO,MAAM,SAAS,WACxB,MAAK,KAAK,EAAE;SAER;;AAKV,SAAgB,eAAe,UAAkB,QAAgB;AAC/D,mBAAkB,IAAI,UAAU,OAAO;;AAGzC,SAAgB,cAAc,UAAkB;AAC9C,mBAAkB,OAAO,SAAS;;AAGpC,SAAS,8BAA8B,OAAqC;AAC1E,SAAQ,OAAR;EACE,cAAiB,MACf,QAAO,gBAAgB;EACzB,cAAiB,MACf,QAAO,gBAAgB;EACzB,cAAiB,KACf,QAAO,gBAAgB;EACzB,cAAiB,KACf,QAAO,gBAAgB;EACzB,cAAiB,MACf,QAAO,gBAAgB"}