@dbos-inc/dbos-sdk 0.8.45-preview.g56ba028de5 → 0.8.48-preview

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. package/dist/packages/dbos-cloud/applications/delete-app.d.ts.map +1 -1
  2. package/dist/packages/dbos-cloud/applications/delete-app.js +1 -2
  3. package/dist/packages/dbos-cloud/applications/delete-app.js.map +1 -1
  4. package/dist/packages/dbos-cloud/applications/deploy-app-code.d.ts.map +1 -1
  5. package/dist/packages/dbos-cloud/applications/deploy-app-code.js +5 -7
  6. package/dist/packages/dbos-cloud/applications/deploy-app-code.js.map +1 -1
  7. package/dist/packages/dbos-cloud/applications/get-app-logs.d.ts.map +1 -1
  8. package/dist/packages/dbos-cloud/applications/get-app-logs.js +1 -2
  9. package/dist/packages/dbos-cloud/applications/get-app-logs.js.map +1 -1
  10. package/dist/packages/dbos-cloud/applications/list-apps.d.ts.map +1 -1
  11. package/dist/packages/dbos-cloud/applications/list-apps.js +1 -2
  12. package/dist/packages/dbos-cloud/applications/list-apps.js.map +1 -1
  13. package/dist/packages/dbos-cloud/applications/register-app.d.ts.map +1 -1
  14. package/dist/packages/dbos-cloud/applications/register-app.js +1 -2
  15. package/dist/packages/dbos-cloud/applications/register-app.js.map +1 -1
  16. package/dist/packages/dbos-cloud/applications/update-app.d.ts.map +1 -1
  17. package/dist/packages/dbos-cloud/applications/update-app.js +1 -2
  18. package/dist/packages/dbos-cloud/applications/update-app.js.map +1 -1
  19. package/dist/packages/dbos-cloud/cli.js +0 -12
  20. package/dist/packages/dbos-cloud/cli.js.map +1 -1
  21. package/dist/packages/dbos-cloud/cloudutils.d.ts +7 -0
  22. package/dist/packages/dbos-cloud/cloudutils.d.ts.map +1 -1
  23. package/dist/packages/dbos-cloud/cloudutils.js +44 -3
  24. package/dist/packages/dbos-cloud/cloudutils.js.map +1 -1
  25. package/dist/packages/dbos-cloud/login.d.ts.map +1 -1
  26. package/dist/packages/dbos-cloud/login.js +3 -4
  27. package/dist/packages/dbos-cloud/login.js.map +1 -1
  28. package/dist/packages/dbos-cloud/register.d.ts.map +1 -1
  29. package/dist/packages/dbos-cloud/register.js +1 -2
  30. package/dist/packages/dbos-cloud/register.js.map +1 -1
  31. package/dist/packages/dbos-cloud/userdb.d.ts +0 -2
  32. package/dist/packages/dbos-cloud/userdb.d.ts.map +1 -1
  33. package/dist/packages/dbos-cloud/userdb.js +4 -177
  34. package/dist/packages/dbos-cloud/userdb.js.map +1 -1
  35. package/dist/src/context.d.ts +1 -0
  36. package/dist/src/context.d.ts.map +1 -1
  37. package/dist/src/dbos-executor.d.ts +0 -1
  38. package/dist/src/dbos-executor.d.ts.map +1 -1
  39. package/dist/src/dbos-executor.js +4 -8
  40. package/dist/src/dbos-executor.js.map +1 -1
  41. package/dist/src/dbos-runtime/cli.d.ts.map +1 -1
  42. package/dist/src/dbos-runtime/cli.js +15 -2
  43. package/dist/src/dbos-runtime/cli.js.map +1 -1
  44. package/dist/src/dbos-runtime/migrate.d.ts +3 -0
  45. package/dist/src/dbos-runtime/migrate.d.ts.map +1 -0
  46. package/dist/src/dbos-runtime/migrate.js +175 -0
  47. package/dist/src/dbos-runtime/migrate.js.map +1 -0
  48. package/dist/src/dbos-runtime/runtime.d.ts +7 -9
  49. package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
  50. package/dist/src/dbos-runtime/runtime.js +35 -21
  51. package/dist/src/dbos-runtime/runtime.js.map +1 -1
  52. package/dist/src/httpServer/handler.d.ts.map +1 -1
  53. package/dist/src/httpServer/handler.js +3 -2
  54. package/dist/src/httpServer/handler.js.map +1 -1
  55. package/dist/src/httpServer/server.d.ts +10 -7
  56. package/dist/src/httpServer/server.d.ts.map +1 -1
  57. package/dist/src/httpServer/server.js +23 -29
  58. package/dist/src/httpServer/server.js.map +1 -1
  59. package/dist/src/index.d.ts +0 -1
  60. package/dist/src/index.d.ts.map +1 -1
  61. package/dist/src/index.js +1 -3
  62. package/dist/src/index.js.map +1 -1
  63. package/dist/src/system_database.d.ts +2 -0
  64. package/dist/src/system_database.d.ts.map +1 -1
  65. package/dist/src/system_database.js +31 -16
  66. package/dist/src/system_database.js.map +1 -1
  67. package/dist/src/telemetry/collector.d.ts.map +1 -1
  68. package/dist/src/telemetry/collector.js +1 -0
  69. package/dist/src/telemetry/collector.js.map +1 -1
  70. package/dist/src/telemetry/exporters.d.ts +2 -0
  71. package/dist/src/telemetry/exporters.d.ts.map +1 -1
  72. package/dist/src/telemetry/exporters.js +4 -0
  73. package/dist/src/telemetry/exporters.js.map +1 -1
  74. package/dist/src/telemetry/logs.d.ts.map +1 -1
  75. package/dist/src/telemetry/logs.js +15 -33
  76. package/dist/src/telemetry/logs.js.map +1 -1
  77. package/dist/src/telemetry/traces.js +2 -2
  78. package/dist/src/telemetry/traces.js.map +1 -1
  79. package/dist/src/testing/testing_runtime.d.ts +4 -1
  80. package/dist/src/testing/testing_runtime.d.ts.map +1 -1
  81. package/dist/src/testing/testing_runtime.js +6 -0
  82. package/dist/src/testing/testing_runtime.js.map +1 -1
  83. package/dist/src/utils.d.ts +1 -1
  84. package/dist/src/utils.d.ts.map +1 -1
  85. package/dist/src/utils.js +20 -4
  86. package/dist/src/utils.js.map +1 -1
  87. package/dist/tsconfig.build.tsbuildinfo +1 -1
  88. package/examples/hello/start_postgres_docker.sh +1 -1
  89. package/migrations/20240123182943_schema.js +8 -0
  90. package/migrations/20240123183021_tables.js +48 -0
  91. package/migrations/20240123183025_indexes.js +14 -0
  92. package/migrations/20240123183030_triggers.js +39 -0
  93. package/migrations/20240124015239_status_timestamp.js +22 -0
  94. package/package.json +1 -1
  95. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/delete-app.d.ts.map +1 -1
  96. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/delete-app.js +1 -2
  97. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/delete-app.js.map +1 -1
  98. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/deploy-app-code.d.ts.map +1 -1
  99. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/deploy-app-code.js +5 -7
  100. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/deploy-app-code.js.map +1 -1
  101. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/get-app-logs.d.ts.map +1 -1
  102. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/get-app-logs.js +1 -2
  103. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/get-app-logs.js.map +1 -1
  104. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/list-apps.d.ts.map +1 -1
  105. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/list-apps.js +1 -2
  106. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/list-apps.js.map +1 -1
  107. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/register-app.d.ts.map +1 -1
  108. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/register-app.js +1 -2
  109. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/register-app.js.map +1 -1
  110. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/update-app.d.ts.map +1 -1
  111. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/update-app.js +1 -2
  112. package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/update-app.js.map +1 -1
  113. package/packages/dbos-cloud/dist/packages/dbos-cloud/cli.js +0 -12
  114. package/packages/dbos-cloud/dist/packages/dbos-cloud/cli.js.map +1 -1
  115. package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.d.ts +7 -0
  116. package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.d.ts.map +1 -1
  117. package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.js +44 -3
  118. package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.js.map +1 -1
  119. package/packages/dbos-cloud/dist/packages/dbos-cloud/login.d.ts.map +1 -1
  120. package/packages/dbos-cloud/dist/packages/dbos-cloud/login.js +3 -4
  121. package/packages/dbos-cloud/dist/packages/dbos-cloud/login.js.map +1 -1
  122. package/packages/dbos-cloud/dist/packages/dbos-cloud/register.d.ts.map +1 -1
  123. package/packages/dbos-cloud/dist/packages/dbos-cloud/register.js +1 -2
  124. package/packages/dbos-cloud/dist/packages/dbos-cloud/register.js.map +1 -1
  125. package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.d.ts +0 -2
  126. package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.d.ts.map +1 -1
  127. package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.js +4 -177
  128. package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.js.map +1 -1
  129. package/packages/dbos-cloud/dist/src/utils.d.ts +1 -1
  130. package/packages/dbos-cloud/dist/src/utils.d.ts.map +1 -1
  131. package/packages/dbos-cloud/dist/src/utils.js +20 -4
  132. package/packages/dbos-cloud/dist/src/utils.js.map +1 -1
  133. package/packages/dbos-cloud/package.json +1 -1
  134. package/packages/dbos-openapi/package.json +1 -1
  135. package/packages/dbos-cloud/dist/schemas/system_db_schema.d.ts +0 -34
  136. package/packages/dbos-cloud/dist/schemas/system_db_schema.d.ts.map +0 -1
  137. package/packages/dbos-cloud/dist/schemas/system_db_schema.js +0 -77
  138. package/packages/dbos-cloud/dist/schemas/system_db_schema.js.map +0 -1
  139. package/packages/dbos-cloud/dist/schemas/user_db_schema.d.ts +0 -11
  140. package/packages/dbos-cloud/dist/schemas/user_db_schema.d.ts.map +0 -1
  141. package/packages/dbos-cloud/dist/schemas/user_db_schema.js +0 -16
  142. package/packages/dbos-cloud/dist/schemas/user_db_schema.js.map +0 -1
  143. package/packages/dbos-cloud/dist/src/communicator.d.ts +0 -25
  144. package/packages/dbos-cloud/dist/src/communicator.d.ts.map +0 -1
  145. package/packages/dbos-cloud/dist/src/communicator.js +0 -26
  146. package/packages/dbos-cloud/dist/src/communicator.js.map +0 -1
  147. package/packages/dbos-cloud/dist/src/context.d.ts +0 -64
  148. package/packages/dbos-cloud/dist/src/context.d.ts.map +0 -1
  149. package/packages/dbos-cloud/dist/src/context.js +0 -96
  150. package/packages/dbos-cloud/dist/src/context.js.map +0 -1
  151. package/packages/dbos-cloud/dist/src/data_validation.d.ts +0 -3
  152. package/packages/dbos-cloud/dist/src/data_validation.d.ts.map +0 -1
  153. package/packages/dbos-cloud/dist/src/data_validation.js +0 -168
  154. package/packages/dbos-cloud/dist/src/data_validation.js.map +0 -1
  155. package/packages/dbos-cloud/dist/src/dbos-executor.d.ts +0 -102
  156. package/packages/dbos-cloud/dist/src/dbos-executor.d.ts.map +0 -1
  157. package/packages/dbos-cloud/dist/src/dbos-executor.js +0 -631
  158. package/packages/dbos-cloud/dist/src/dbos-executor.js.map +0 -1
  159. package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.d.ts +0 -3
  160. package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.d.ts.map +0 -1
  161. package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.js +0 -13
  162. package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.js.map +0 -1
  163. package/packages/dbos-cloud/dist/src/dbos-runtime/cli.d.ts +0 -8
  164. package/packages/dbos-cloud/dist/src/dbos-runtime/cli.d.ts.map +0 -1
  165. package/packages/dbos-cloud/dist/src/dbos-runtime/cli.js +0 -47
  166. package/packages/dbos-cloud/dist/src/dbos-runtime/cli.js.map +0 -1
  167. package/packages/dbos-cloud/dist/src/dbos-runtime/config.d.ts +0 -29
  168. package/packages/dbos-cloud/dist/src/dbos-runtime/config.d.ts.map +0 -1
  169. package/packages/dbos-cloud/dist/src/dbos-runtime/config.js +0 -111
  170. package/packages/dbos-cloud/dist/src/dbos-runtime/config.js.map +0 -1
  171. package/packages/dbos-cloud/dist/src/dbos-runtime/debug.d.ts +0 -4
  172. package/packages/dbos-cloud/dist/src/dbos-runtime/debug.d.ts.map +0 -1
  173. package/packages/dbos-cloud/dist/src/dbos-runtime/debug.js +0 -21
  174. package/packages/dbos-cloud/dist/src/dbos-runtime/debug.js.map +0 -1
  175. package/packages/dbos-cloud/dist/src/dbos-runtime/init.d.ts +0 -7
  176. package/packages/dbos-cloud/dist/src/dbos-runtime/init.d.ts.map +0 -1
  177. package/packages/dbos-cloud/dist/src/dbos-runtime/init.js +0 -51
  178. package/packages/dbos-cloud/dist/src/dbos-runtime/init.js.map +0 -1
  179. package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.d.ts +0 -28
  180. package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.d.ts.map +0 -1
  181. package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.js +0 -95
  182. package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.js.map +0 -1
  183. package/packages/dbos-cloud/dist/src/debugger/debug_workflow.d.ts +0 -38
  184. package/packages/dbos-cloud/dist/src/debugger/debug_workflow.d.ts.map +0 -1
  185. package/packages/dbos-cloud/dist/src/debugger/debug_workflow.js +0 -211
  186. package/packages/dbos-cloud/dist/src/debugger/debug_workflow.js.map +0 -1
  187. package/packages/dbos-cloud/dist/src/decorators.d.ts +0 -118
  188. package/packages/dbos-cloud/dist/src/decorators.d.ts.map +0 -1
  189. package/packages/dbos-cloud/dist/src/decorators.js +0 -467
  190. package/packages/dbos-cloud/dist/src/decorators.js.map +0 -1
  191. package/packages/dbos-cloud/dist/src/error.d.ts +0 -47
  192. package/packages/dbos-cloud/dist/src/error.d.ts.map +0 -1
  193. package/packages/dbos-cloud/dist/src/error.js +0 -171
  194. package/packages/dbos-cloud/dist/src/error.js.map +0 -1
  195. package/packages/dbos-cloud/dist/src/httpServer/handler.d.ts +0 -54
  196. package/packages/dbos-cloud/dist/src/httpServer/handler.d.ts.map +0 -1
  197. package/packages/dbos-cloud/dist/src/httpServer/handler.js +0 -175
  198. package/packages/dbos-cloud/dist/src/httpServer/handler.js.map +0 -1
  199. package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.d.ts +0 -11
  200. package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.d.ts.map +0 -1
  201. package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.js +0 -19
  202. package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.js.map +0 -1
  203. package/packages/dbos-cloud/dist/src/httpServer/middleware.d.ts +0 -56
  204. package/packages/dbos-cloud/dist/src/httpServer/middleware.d.ts.map +0 -1
  205. package/packages/dbos-cloud/dist/src/httpServer/middleware.js +0 -57
  206. package/packages/dbos-cloud/dist/src/httpServer/middleware.js.map +0 -1
  207. package/packages/dbos-cloud/dist/src/httpServer/server.d.ts +0 -45
  208. package/packages/dbos-cloud/dist/src/httpServer/server.d.ts.map +0 -1
  209. package/packages/dbos-cloud/dist/src/httpServer/server.js +0 -253
  210. package/packages/dbos-cloud/dist/src/httpServer/server.js.map +0 -1
  211. package/packages/dbos-cloud/dist/src/system_database.d.ts +0 -89
  212. package/packages/dbos-cloud/dist/src/system_database.d.ts.map +0 -1
  213. package/packages/dbos-cloud/dist/src/system_database.js +0 -447
  214. package/packages/dbos-cloud/dist/src/system_database.js.map +0 -1
  215. package/packages/dbos-cloud/dist/src/telemetry/collector.d.ts +0 -16
  216. package/packages/dbos-cloud/dist/src/telemetry/collector.d.ts.map +0 -1
  217. package/packages/dbos-cloud/dist/src/telemetry/collector.js +0 -65
  218. package/packages/dbos-cloud/dist/src/telemetry/collector.js.map +0 -1
  219. package/packages/dbos-cloud/dist/src/telemetry/exporters.d.ts +0 -15
  220. package/packages/dbos-cloud/dist/src/telemetry/exporters.d.ts.map +0 -1
  221. package/packages/dbos-cloud/dist/src/telemetry/exporters.js +0 -59
  222. package/packages/dbos-cloud/dist/src/telemetry/exporters.js.map +0 -1
  223. package/packages/dbos-cloud/dist/src/telemetry/index.d.ts +0 -11
  224. package/packages/dbos-cloud/dist/src/telemetry/index.d.ts.map +0 -1
  225. package/packages/dbos-cloud/dist/src/telemetry/index.js +0 -19
  226. package/packages/dbos-cloud/dist/src/telemetry/index.js.map +0 -1
  227. package/packages/dbos-cloud/dist/src/telemetry/logs.d.ts +0 -47
  228. package/packages/dbos-cloud/dist/src/telemetry/logs.d.ts.map +0 -1
  229. package/packages/dbos-cloud/dist/src/telemetry/logs.js +0 -195
  230. package/packages/dbos-cloud/dist/src/telemetry/logs.js.map +0 -1
  231. package/packages/dbos-cloud/dist/src/telemetry/traces.d.ts +0 -14
  232. package/packages/dbos-cloud/dist/src/telemetry/traces.d.ts.map +0 -1
  233. package/packages/dbos-cloud/dist/src/telemetry/traces.js +0 -52
  234. package/packages/dbos-cloud/dist/src/telemetry/traces.js.map +0 -1
  235. package/packages/dbos-cloud/dist/src/transaction.d.ts +0 -29
  236. package/packages/dbos-cloud/dist/src/transaction.d.ts.map +0 -1
  237. package/packages/dbos-cloud/dist/src/transaction.js +0 -27
  238. package/packages/dbos-cloud/dist/src/transaction.js.map +0 -1
  239. package/packages/dbos-cloud/dist/src/user_database.d.ts +0 -132
  240. package/packages/dbos-cloud/dist/src/user_database.d.ts.map +0 -1
  241. package/packages/dbos-cloud/dist/src/user_database.js +0 -332
  242. package/packages/dbos-cloud/dist/src/user_database.js.map +0 -1
  243. package/packages/dbos-cloud/dist/src/workflow.d.ts +0 -195
  244. package/packages/dbos-cloud/dist/src/workflow.d.ts.map +0 -1
  245. package/packages/dbos-cloud/dist/src/workflow.js +0 -498
  246. package/packages/dbos-cloud/dist/src/workflow.js.map +0 -1
@@ -1,253 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DBOSHttpServer = exports.HealthUrl = exports.WorkflowRecoveryUrl = exports.WorkflowUUIDHeader = void 0;
7
- const koa_1 = __importDefault(require("koa"));
8
- const router_1 = __importDefault(require("@koa/router"));
9
- const bodyparser_1 = require("@koa/bodyparser");
10
- const cors_1 = __importDefault(require("@koa/cors"));
11
- const handler_1 = require("./handler");
12
- const handlerTypes_1 = require("./handlerTypes");
13
- const error_1 = require("../error");
14
- const api_1 = require("@opentelemetry/api");
15
- exports.WorkflowUUIDHeader = "dbos-workflowuuid";
16
- exports.WorkflowRecoveryUrl = "/dbos-workflow-recovery";
17
- exports.HealthUrl = "/dbos-healthz";
18
- class DBOSHttpServer {
19
- dbosExec;
20
- app;
21
- router;
22
- logger;
23
- /**
24
- * Create a Koa app.
25
- * @param dbosExec User pass in an DBOS workflow executor instance.
26
- * TODO: maybe call dbosExec.init() somewhere in this class?
27
- */
28
- constructor(dbosExec, config = {}) {
29
- this.dbosExec = dbosExec;
30
- if (!config.router) {
31
- config.router = new router_1.default();
32
- }
33
- this.router = config.router;
34
- this.logger = dbosExec.logger;
35
- if (!config.koa) {
36
- config.koa = new koa_1.default();
37
- // Note: we definitely need bodyParser.
38
- // For cors(), it doesn't work if we use it in a router, and thus we have to use it in app.
39
- config.koa.use((0, bodyparser_1.bodyParser)());
40
- config.koa.use((0, cors_1.default)());
41
- }
42
- this.app = config.koa;
43
- // Register HTTP endpoints.
44
- DBOSHttpServer.registerHealthEndpoint(this.dbosExec, this.router);
45
- DBOSHttpServer.registerRecoveryEndpoint(this.dbosExec, this.router);
46
- DBOSHttpServer.registerDecoratedEndpoints(this.dbosExec, this.router);
47
- this.app.use(this.router.routes()).use(this.router.allowedMethods());
48
- }
49
- /**
50
- * Register HTTP endpoints and attach to the app. Then start the server at the given port.
51
- * @param port
52
- */
53
- listen(port) {
54
- // Start the HTTP server.
55
- return this.app.listen(port, () => {
56
- this.logger.info(`DBOS Server is running at http://localhost:${port}`);
57
- });
58
- }
59
- /**
60
- * Health check endpoint.
61
- */
62
- static registerHealthEndpoint(dbosExec, router) {
63
- // Handler function that parses request for recovery.
64
- const healthHandler = async (koaCtxt, koaNext) => {
65
- koaCtxt.body = "healthy";
66
- await koaNext();
67
- };
68
- router.get(exports.HealthUrl, healthHandler);
69
- dbosExec.logger.debug(`DBOS Server Registered Healthz POST ${exports.HealthUrl}`);
70
- }
71
- /**
72
- * Register workflow recovery endpoint.
73
- * Receives a list of executor IDs and returns a list of workflowUUIDs.
74
- */
75
- static registerRecoveryEndpoint(dbosExec, router) {
76
- // Handler function that parses request for recovery.
77
- const recoveryHandler = async (koaCtxt, koaNext) => {
78
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
79
- const executorIDs = koaCtxt.request.body;
80
- dbosExec.logger.info("Recovering workflows for executors: " + executorIDs.toString());
81
- const recoverHandles = await dbosExec.recoverPendingWorkflows(executorIDs);
82
- // Return a list of workflowUUIDs being recovered.
83
- koaCtxt.body = await Promise.allSettled(recoverHandles.map((i) => i.getWorkflowUUID())).then((results) => results.filter((i) => i.status === "fulfilled").map((i) => i.value));
84
- await koaNext();
85
- };
86
- router.post(exports.WorkflowRecoveryUrl, recoveryHandler);
87
- dbosExec.logger.debug(`DBOS Server Registered Recovery POST ${exports.WorkflowRecoveryUrl}`);
88
- }
89
- /**
90
- * Register decorated functions as HTTP endpoints.
91
- */
92
- static registerDecoratedEndpoints(dbosExec, router) {
93
- // Register user declared endpoints, wrap around the endpoint with request parsing and response.
94
- dbosExec.registeredOperations.forEach((registeredOperation) => {
95
- const ro = registeredOperation;
96
- if (ro.apiURL) {
97
- // Ignore URL with "/dbos-workflow-recovery" prefix.
98
- if (ro.apiURL.startsWith(exports.WorkflowRecoveryUrl)) {
99
- dbosExec.logger.error(`Invalid URL: ${ro.apiURL} -- should not start with ${exports.WorkflowRecoveryUrl}!`);
100
- return;
101
- }
102
- // Ignore URL with "/dbos-healthz" prefix.
103
- if (ro.apiURL.startsWith(exports.HealthUrl)) {
104
- dbosExec.logger.error(`Invalid URL: ${ro.apiURL} -- should not start with ${exports.HealthUrl}!`);
105
- return;
106
- }
107
- // Check if we need to apply any Koa middleware.
108
- const defaults = ro.defaults;
109
- if (defaults?.koaMiddlewares) {
110
- defaults.koaMiddlewares.forEach((koaMiddleware) => {
111
- dbosExec.logger.debug(`DBOS Server applying middleware ${koaMiddleware.name} to ${ro.apiURL}`);
112
- router.use(ro.apiURL, koaMiddleware);
113
- });
114
- }
115
- // Wrapper function that parses request and send response.
116
- const wrappedHandler = async (koaCtxt, koaNext) => {
117
- const oc = new handler_1.HandlerContextImpl(dbosExec, koaCtxt);
118
- try {
119
- // Check for auth first
120
- if (defaults?.authMiddleware) {
121
- const res = await defaults.authMiddleware({
122
- name: ro.name,
123
- requiredRole: ro.getRequiredRoles(),
124
- koaContext: koaCtxt,
125
- logger: oc.logger,
126
- span: oc.span,
127
- getConfig: (key, def) => {
128
- return oc.getConfig(key, def);
129
- },
130
- query: (query, ...args) => {
131
- return dbosExec.userDatabase.queryFunction(query, ...args);
132
- },
133
- });
134
- if (res) {
135
- oc.authenticatedUser = res.authenticatedUser;
136
- oc.authenticatedRoles = res.authenticatedRoles;
137
- }
138
- }
139
- // Parse the arguments.
140
- const args = [];
141
- ro.args.forEach((marg, idx) => {
142
- marg.argSource = marg.argSource ?? handlerTypes_1.ArgSources.DEFAULT; // Assign a default value.
143
- if (idx === 0) {
144
- return; // Do not parse the context.
145
- }
146
- let foundArg = undefined;
147
- if ((ro.apiType === handlerTypes_1.APITypes.GET && marg.argSource === handlerTypes_1.ArgSources.DEFAULT) || marg.argSource === handlerTypes_1.ArgSources.QUERY) {
148
- foundArg = koaCtxt.request.query[marg.name];
149
- if (foundArg) {
150
- args.push(foundArg);
151
- }
152
- }
153
- else if ((ro.apiType === handlerTypes_1.APITypes.POST && marg.argSource === handlerTypes_1.ArgSources.DEFAULT) || marg.argSource === handlerTypes_1.ArgSources.BODY) {
154
- if (!koaCtxt.request.body) {
155
- throw new error_1.DBOSDataValidationError(`Argument ${marg.name} requires a method body.`);
156
- }
157
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
158
- foundArg = koaCtxt.request.body[marg.name];
159
- if (foundArg) {
160
- args.push(foundArg);
161
- }
162
- }
163
- // Try to parse the argument from the URL if nothing found.
164
- if (!foundArg) {
165
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
166
- args.push(koaCtxt.params[marg.name]);
167
- }
168
- //console.log(`found arg ${marg.name} ${idx} ${args[idx-1]}`);
169
- });
170
- // Extract workflow UUID from headers (if any).
171
- // We pass in the specified workflow UUID to workflows and transactions, but doesn't restrict how handlers use it.
172
- const headerWorkflowUUID = koaCtxt.get(exports.WorkflowUUIDHeader);
173
- // Finally, invoke the transaction/workflow/plain function and properly set HTTP response.
174
- // If functions return successfully and hasn't set the body, we set the body to the function return value. The status code will be automatically set to 200 or 204 (if the body is null/undefined).
175
- // In case of an exception:
176
- // - If a client-side error is thrown, we return 400.
177
- // - If an error contains a `status` field, we return the specified status code.
178
- // - Otherwise, we return 500.
179
- const wfParams = { parentCtx: oc, workflowUUID: headerWorkflowUUID };
180
- if (ro.txnConfig) {
181
- koaCtxt.body = await dbosExec.transaction(ro.registeredFunction, wfParams, ...args);
182
- }
183
- else if (ro.workflowConfig) {
184
- koaCtxt.body = await (await dbosExec.workflow(ro.registeredFunction, wfParams, ...args)).getResult();
185
- }
186
- else if (ro.commConfig) {
187
- koaCtxt.body = await dbosExec.external(ro.registeredFunction, wfParams, ...args);
188
- }
189
- else {
190
- // Directly invoke the handler code.
191
- const retValue = await ro.invoke(undefined, [oc, ...args]);
192
- // Set the body to the return value unless the body is already set by the handler.
193
- if (koaCtxt.body === undefined) {
194
- koaCtxt.body = retValue;
195
- }
196
- }
197
- oc.span.setStatus({ code: api_1.SpanStatusCode.OK });
198
- }
199
- catch (e) {
200
- if (e instanceof Error) {
201
- oc.logger.error(e);
202
- oc.span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e.message });
203
- let st = e?.status || 500;
204
- const dbosErrorCode = e?.dbosErrorCode;
205
- if (dbosErrorCode && (0, error_1.isClientError)(dbosErrorCode)) {
206
- st = 400; // Set to 400: client-side error.
207
- }
208
- koaCtxt.status = st;
209
- koaCtxt.message = e.message;
210
- koaCtxt.body = {
211
- status: st,
212
- message: e.message,
213
- details: e,
214
- };
215
- }
216
- else {
217
- // FIXME we should have a standard, user friendly message for errors that are not instances of Error.
218
- // using stringify() will not produce a pretty output, because our format function uses stringify() too.
219
- oc.logger.error(JSON.stringify(e));
220
- oc.span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: JSON.stringify(e) });
221
- koaCtxt.body = e;
222
- koaCtxt.status = 500;
223
- }
224
- }
225
- finally {
226
- oc.W3CTraceContextPropagator.inject(api_1.trace.setSpanContext(api_1.ROOT_CONTEXT, oc.span.spanContext()), {
227
- context: koaCtxt,
228
- }, {
229
- set: (carrier, key, value) => {
230
- carrier.context.set(key, value);
231
- },
232
- });
233
- dbosExec.tracer.endSpan(oc.span);
234
- // Add requestID to response headers.
235
- koaCtxt.set(handler_1.RequestIDHeader, oc.request.requestID);
236
- await koaNext();
237
- }
238
- };
239
- // Actually register the endpoint.
240
- if (ro.apiType === handlerTypes_1.APITypes.GET) {
241
- router.get(ro.apiURL, wrappedHandler);
242
- dbosExec.logger.debug(`DBOS Server Registered GET ${ro.apiURL}`);
243
- }
244
- else if (ro.apiType === handlerTypes_1.APITypes.POST) {
245
- router.post(ro.apiURL, wrappedHandler);
246
- dbosExec.logger.debug(`DBOS Server Registered POST ${ro.apiURL}`);
247
- }
248
- }
249
- });
250
- }
251
- }
252
- exports.DBOSHttpServer = DBOSHttpServer;
253
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../../src/httpServer/server.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,yDAAiC;AACjC,gDAA6C;AAC7C,qDAA6B;AAC7B,uCAImB;AACnB,iDAAsD;AAGtD,oCAKkB;AAIlB,4CAAyE;AAG5D,QAAA,kBAAkB,GAAG,mBAAmB,CAAC;AACzC,QAAA,mBAAmB,GAAG,yBAAyB,CAAA;AAC/C,QAAA,SAAS,GAAG,eAAe,CAAA;AAExC,MAAa,cAAc;IAUJ;IATZ,GAAG,CAAM;IACT,MAAM,CAAS;IACf,MAAM,CAAS;IAExB;;;;OAIG;IACH,YAAqB,QAAsB,EAAE,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, PoolClient, PoolConfig } from "pg";
3
- import { WorkflowStatus } from "./workflow";
4
- import { HTTPRequest } from "./context";
5
- import { GlobalLogger as Logger } from "./telemetry/logs";
6
- export interface SystemDatabase {
7
- init(): Promise<void>;
8
- destroy(): Promise<void>;
9
- checkWorkflowOutput<R>(workflowUUID: string): Promise<DBOSNull | R>;
10
- initWorkflowStatus<T extends any[]>(bufferedStatus: WorkflowStatusInternal, args: T): Promise<T>;
11
- bufferWorkflowOutput(workflowUUID: string, status: WorkflowStatusInternal): void;
12
- flushWorkflowStatusBuffer(): Promise<void>;
13
- recordWorkflowError(workflowUUID: string, status: WorkflowStatusInternal): Promise<void>;
14
- getPendingWorkflows(executorID: string): Promise<Array<string>>;
15
- bufferWorkflowInputs<T extends any[]>(workflowUUID: string, args: T): void;
16
- getWorkflowInputs<T extends any[]>(workflowUUID: string): Promise<T | null>;
17
- flushWorkflowInputsBuffer(): Promise<void>;
18
- checkOperationOutput<R>(workflowUUID: string, functionID: number): Promise<DBOSNull | R>;
19
- recordOperationOutput<R>(workflowUUID: string, functionID: number, output: R): Promise<void>;
20
- recordOperationError(workflowUUID: string, functionID: number, error: Error): Promise<void>;
21
- getWorkflowStatus(workflowUUID: string, callerUUID?: string, functionID?: number): Promise<WorkflowStatus | null>;
22
- getWorkflowResult<R>(workflowUUID: string): Promise<R>;
23
- send<T extends NonNullable<any>>(workflowUUID: string, functionID: number, destinationUUID: string, message: T, topic?: string): Promise<void>;
24
- recv<T extends NonNullable<any>>(workflowUUID: string, functionID: number, topic?: string, timeoutSeconds?: number): Promise<T | null>;
25
- setEvent<T extends NonNullable<any>>(workflowUUID: string, functionID: number, key: string, value: T): Promise<void>;
26
- getEvent<T extends NonNullable<any>>(workflowUUID: string, key: string, timeoutSeconds: number, callerUUID?: string, functionID?: number): Promise<T | null>;
27
- }
28
- export interface WorkflowStatusInternal {
29
- workflowUUID: string;
30
- status: string;
31
- name: string;
32
- authenticatedUser: string;
33
- output: unknown;
34
- error: string;
35
- assumedRole: string;
36
- authenticatedRoles: string[];
37
- request: HTTPRequest;
38
- executorID: string;
39
- }
40
- export interface ExistenceCheck {
41
- exists: boolean;
42
- }
43
- export declare class PostgresSystemDatabase implements SystemDatabase {
44
- readonly pgPoolConfig: PoolConfig;
45
- readonly systemDatabaseName: string;
46
- readonly logger: Logger;
47
- readonly pool: Pool;
48
- notificationsClient: PoolClient | null;
49
- readonly notificationsMap: Record<string, () => void>;
50
- readonly workflowEventsMap: Record<string, () => void>;
51
- readonly workflowStatusBuffer: Map<string, WorkflowStatusInternal>;
52
- readonly workflowInputsBuffer: Map<string, any[]>;
53
- readonly flushBatchSize = 100;
54
- constructor(pgPoolConfig: PoolConfig, systemDatabaseName: string, logger: Logger);
55
- init(): Promise<void>;
56
- destroy(): Promise<void>;
57
- checkWorkflowOutput<R>(workflowUUID: string): Promise<DBOSNull | R>;
58
- initWorkflowStatus<T extends any[]>(initStatus: WorkflowStatusInternal, args: T): Promise<T>;
59
- bufferWorkflowOutput(workflowUUID: string, status: WorkflowStatusInternal): void;
60
- /**
61
- * Flush the workflow output buffer to the database.
62
- */
63
- flushWorkflowStatusBuffer(): Promise<void>;
64
- recordWorkflowError(workflowUUID: string, status: WorkflowStatusInternal): Promise<void>;
65
- getPendingWorkflows(executorID: string): Promise<Array<string>>;
66
- bufferWorkflowInputs<T extends any[]>(workflowUUID: string, args: T): void;
67
- flushWorkflowInputsBuffer(): Promise<void>;
68
- getWorkflowInputs<T extends any[]>(workflowUUID: string): Promise<T | null>;
69
- checkOperationOutput<R>(workflowUUID: string, functionID: number): Promise<DBOSNull | R>;
70
- recordOperationOutput<R>(workflowUUID: string, functionID: number, output: R): Promise<void>;
71
- recordOperationError(workflowUUID: string, functionID: number, error: Error): Promise<void>;
72
- /**
73
- * Guard the operation, throwing an error if a conflicting execution is detected.
74
- */
75
- recordNotificationOutput<R>(client: PoolClient, workflowUUID: string, functionID: number, output: R): Promise<void>;
76
- readonly nullTopic = "__null__topic__";
77
- send<T extends NonNullable<any>>(workflowUUID: string, functionID: number, destinationUUID: string, message: T, topic?: string): Promise<void>;
78
- recv<T extends NonNullable<any>>(workflowUUID: string, functionID: number, topic?: string, timeoutSeconds?: number): Promise<T | null>;
79
- setEvent<T extends NonNullable<any>>(workflowUUID: string, functionID: number, key: string, message: T): Promise<void>;
80
- getEvent<T extends NonNullable<any>>(workflowUUID: string, key: string, timeoutSeconds: number, callerUUID?: string, functionID?: number): Promise<T | null>;
81
- getWorkflowStatus(workflowUUID: string, callerUUID?: string, functionID?: number): Promise<WorkflowStatus | null>;
82
- getWorkflowResult<R>(workflowUUID: string): Promise<R>;
83
- /**
84
- * A background process that listens for notifications from Postgres then signals the appropriate
85
- * workflow listener by resolving its promise.
86
- */
87
- listenForNotifications(): Promise<void>;
88
- }
89
- //# sourceMappingURL=system_database.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system_database.d.ts","sourceRoot":"","sources":["../../../../src/system_database.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAiB,IAAI,EAAE,UAAU,EAAgB,UAAU,EAAU,MAAM,IAAI,CAAC;AAEvF,OAAO,EAAgB,cAAc,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,mBAAmB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IACpE,kBAAkB,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,cAAc,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CA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