@dbos-inc/dbos-sdk 0.7.18-preview

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dbos-config.schema.json +121 -0
  4. package/dbos-test-config.yaml +16 -0
  5. package/dist/schemas/system_db_schema.d.ts +34 -0
  6. package/dist/schemas/system_db_schema.d.ts.map +1 -0
  7. package/dist/schemas/system_db_schema.js +75 -0
  8. package/dist/schemas/system_db_schema.js.map +1 -0
  9. package/dist/schemas/user_db_schema.d.ts +11 -0
  10. package/dist/schemas/user_db_schema.d.ts.map +1 -0
  11. package/dist/schemas/user_db_schema.js +16 -0
  12. package/dist/schemas/user_db_schema.js.map +1 -0
  13. package/dist/src/cloud-cli/applications/configure.d.ts +2 -0
  14. package/dist/src/cloud-cli/applications/configure.d.ts.map +1 -0
  15. package/dist/src/cloud-cli/applications/configure.js +57 -0
  16. package/dist/src/cloud-cli/applications/configure.js.map +1 -0
  17. package/dist/src/cloud-cli/applications/delete-app.d.ts +2 -0
  18. package/dist/src/cloud-cli/applications/delete-app.d.ts.map +1 -0
  19. package/dist/src/cloud-cli/applications/delete-app.js +36 -0
  20. package/dist/src/cloud-cli/applications/delete-app.js.map +1 -0
  21. package/dist/src/cloud-cli/applications/deploy-app-code.d.ts +2 -0
  22. package/dist/src/cloud-cli/applications/deploy-app-code.d.ts.map +1 -0
  23. package/dist/src/cloud-cli/applications/deploy-app-code.js +64 -0
  24. package/dist/src/cloud-cli/applications/deploy-app-code.js.map +1 -0
  25. package/dist/src/cloud-cli/applications/get-app-logs.d.ts +2 -0
  26. package/dist/src/cloud-cli/applications/get-app-logs.d.ts.map +1 -0
  27. package/dist/src/cloud-cli/applications/get-app-logs.js +37 -0
  28. package/dist/src/cloud-cli/applications/get-app-logs.js.map +1 -0
  29. package/dist/src/cloud-cli/applications/index.d.ts +8 -0
  30. package/dist/src/cloud-cli/applications/index.d.ts.map +1 -0
  31. package/dist/src/cloud-cli/applications/index.js +18 -0
  32. package/dist/src/cloud-cli/applications/index.js.map +1 -0
  33. package/dist/src/cloud-cli/applications/list-apps.d.ts +2 -0
  34. package/dist/src/cloud-cli/applications/list-apps.d.ts.map +1 -0
  35. package/dist/src/cloud-cli/applications/list-apps.js +45 -0
  36. package/dist/src/cloud-cli/applications/list-apps.js.map +1 -0
  37. package/dist/src/cloud-cli/applications/register-app.d.ts +2 -0
  38. package/dist/src/cloud-cli/applications/register-app.d.ts.map +1 -0
  39. package/dist/src/cloud-cli/applications/register-app.js +41 -0
  40. package/dist/src/cloud-cli/applications/register-app.js.map +1 -0
  41. package/dist/src/cloud-cli/applications/types.d.ts +7 -0
  42. package/dist/src/cloud-cli/applications/types.d.ts.map +1 -0
  43. package/dist/src/cloud-cli/applications/types.js +3 -0
  44. package/dist/src/cloud-cli/applications/types.js.map +1 -0
  45. package/dist/src/cloud-cli/applications/update-app.d.ts +2 -0
  46. package/dist/src/cloud-cli/applications/update-app.d.ts.map +1 -0
  47. package/dist/src/cloud-cli/applications/update-app.js +42 -0
  48. package/dist/src/cloud-cli/applications/update-app.js.map +1 -0
  49. package/dist/src/cloud-cli/cli.d.ts +3 -0
  50. package/dist/src/cloud-cli/cli.d.ts.map +1 -0
  51. package/dist/src/cloud-cli/cli.js +148 -0
  52. package/dist/src/cloud-cli/cli.js.map +1 -0
  53. package/dist/src/cloud-cli/login.d.ts +7 -0
  54. package/dist/src/cloud-cli/login.d.ts.map +1 -0
  55. package/dist/src/cloud-cli/login.js +40 -0
  56. package/dist/src/cloud-cli/login.js.map +1 -0
  57. package/dist/src/cloud-cli/register.d.ts +2 -0
  58. package/dist/src/cloud-cli/register.d.ts.map +1 -0
  59. package/dist/src/cloud-cli/register.js +35 -0
  60. package/dist/src/cloud-cli/register.js.map +1 -0
  61. package/dist/src/cloud-cli/userdb.d.ts +4 -0
  62. package/dist/src/cloud-cli/userdb.d.ts.map +1 -0
  63. package/dist/src/cloud-cli/userdb.js +149 -0
  64. package/dist/src/cloud-cli/userdb.js.map +1 -0
  65. package/dist/src/cloud-cli/utils.d.ts +3 -0
  66. package/dist/src/cloud-cli/utils.d.ts.map +1 -0
  67. package/dist/src/cloud-cli/utils.js +17 -0
  68. package/dist/src/cloud-cli/utils.js.map +1 -0
  69. package/dist/src/communicator.d.ts +24 -0
  70. package/dist/src/communicator.d.ts.map +1 -0
  71. package/dist/src/communicator.js +26 -0
  72. package/dist/src/communicator.js.map +1 -0
  73. package/dist/src/context.d.ts +60 -0
  74. package/dist/src/context.d.ts.map +1 -0
  75. package/dist/src/context.js +94 -0
  76. package/dist/src/context.js.map +1 -0
  77. package/dist/src/data_validation.d.ts +3 -0
  78. package/dist/src/data_validation.d.ts.map +1 -0
  79. package/dist/src/data_validation.js +168 -0
  80. package/dist/src/data_validation.js.map +1 -0
  81. package/dist/src/dbos-executor.d.ts +79 -0
  82. package/dist/src/dbos-executor.d.ts.map +1 -0
  83. package/dist/src/dbos-executor.js +408 -0
  84. package/dist/src/dbos-executor.js.map +1 -0
  85. package/dist/src/dbos-runtime/TypeParser.d.ts +33 -0
  86. package/dist/src/dbos-runtime/TypeParser.d.ts.map +1 -0
  87. package/dist/src/dbos-runtime/TypeParser.js +104 -0
  88. package/dist/src/dbos-runtime/TypeParser.js.map +1 -0
  89. package/dist/src/dbos-runtime/applicationVersion.d.ts +3 -0
  90. package/dist/src/dbos-runtime/applicationVersion.d.ts.map +1 -0
  91. package/dist/src/dbos-runtime/applicationVersion.js +13 -0
  92. package/dist/src/dbos-runtime/applicationVersion.js.map +1 -0
  93. package/dist/src/dbos-runtime/cli.d.ts +8 -0
  94. package/dist/src/dbos-runtime/cli.d.ts.map +1 -0
  95. package/dist/src/dbos-runtime/cli.js +52 -0
  96. package/dist/src/dbos-runtime/cli.js.map +1 -0
  97. package/dist/src/dbos-runtime/config.d.ts +28 -0
  98. package/dist/src/dbos-runtime/config.d.ts.map +1 -0
  99. package/dist/src/dbos-runtime/config.js +111 -0
  100. package/dist/src/dbos-runtime/config.js.map +1 -0
  101. package/dist/src/dbos-runtime/init.d.ts +7 -0
  102. package/dist/src/dbos-runtime/init.d.ts.map +1 -0
  103. package/dist/src/dbos-runtime/init.js +51 -0
  104. package/dist/src/dbos-runtime/init.js.map +1 -0
  105. package/dist/src/dbos-runtime/openApi.d.ts +35 -0
  106. package/dist/src/dbos-runtime/openApi.d.ts.map +1 -0
  107. package/dist/src/dbos-runtime/openApi.js +595 -0
  108. package/dist/src/dbos-runtime/openApi.js.map +1 -0
  109. package/dist/src/dbos-runtime/runtime.d.ts +28 -0
  110. package/dist/src/dbos-runtime/runtime.d.ts.map +1 -0
  111. package/dist/src/dbos-runtime/runtime.js +96 -0
  112. package/dist/src/dbos-runtime/runtime.js.map +1 -0
  113. package/dist/src/dbos-runtime/tsDiagUtil.d.ts +16 -0
  114. package/dist/src/dbos-runtime/tsDiagUtil.d.ts.map +1 -0
  115. package/dist/src/dbos-runtime/tsDiagUtil.js +72 -0
  116. package/dist/src/dbos-runtime/tsDiagUtil.js.map +1 -0
  117. package/dist/src/decorators.d.ts +118 -0
  118. package/dist/src/decorators.d.ts.map +1 -0
  119. package/dist/src/decorators.js +467 -0
  120. package/dist/src/decorators.js.map +1 -0
  121. package/dist/src/error.d.ts +44 -0
  122. package/dist/src/error.d.ts.map +1 -0
  123. package/dist/src/error.js +164 -0
  124. package/dist/src/error.js.map +1 -0
  125. package/dist/src/httpServer/handler.d.ts +62 -0
  126. package/dist/src/httpServer/handler.d.ts.map +1 -0
  127. package/dist/src/httpServer/handler.js +168 -0
  128. package/dist/src/httpServer/handler.js.map +1 -0
  129. package/dist/src/httpServer/middleware.d.ts +56 -0
  130. package/dist/src/httpServer/middleware.d.ts.map +1 -0
  131. package/dist/src/httpServer/middleware.js +57 -0
  132. package/dist/src/httpServer/middleware.js.map +1 -0
  133. package/dist/src/httpServer/server.d.ts +40 -0
  134. package/dist/src/httpServer/server.d.ts.map +1 -0
  135. package/dist/src/httpServer/server.js +231 -0
  136. package/dist/src/httpServer/server.js.map +1 -0
  137. package/dist/src/index.d.ts +12 -0
  138. package/dist/src/index.d.ts.map +1 -0
  139. package/dist/src/index.js +75 -0
  140. package/dist/src/index.js.map +1 -0
  141. package/dist/src/provenance/provenance_daemon.d.ts +34 -0
  142. package/dist/src/provenance/provenance_daemon.d.ts.map +1 -0
  143. package/dist/src/provenance/provenance_daemon.js +86 -0
  144. package/dist/src/provenance/provenance_daemon.js.map +1 -0
  145. package/dist/src/system_database.d.ts +69 -0
  146. package/dist/src/system_database.d.ts.map +1 -0
  147. package/dist/src/system_database.js +384 -0
  148. package/dist/src/system_database.js.map +1 -0
  149. package/dist/src/telemetry/collector.d.ts +17 -0
  150. package/dist/src/telemetry/collector.d.ts.map +1 -0
  151. package/dist/src/telemetry/collector.js +77 -0
  152. package/dist/src/telemetry/collector.js.map +1 -0
  153. package/dist/src/telemetry/exporters.d.ts +29 -0
  154. package/dist/src/telemetry/exporters.d.ts.map +1 -0
  155. package/dist/src/telemetry/exporters.js +186 -0
  156. package/dist/src/telemetry/exporters.js.map +1 -0
  157. package/dist/src/telemetry/index.d.ts +7 -0
  158. package/dist/src/telemetry/index.d.ts.map +1 -0
  159. package/dist/src/telemetry/index.js +3 -0
  160. package/dist/src/telemetry/index.js.map +1 -0
  161. package/dist/src/telemetry/logs.d.ts +25 -0
  162. package/dist/src/telemetry/logs.d.ts.map +1 -0
  163. package/dist/src/telemetry/logs.js +91 -0
  164. package/dist/src/telemetry/logs.js.map +1 -0
  165. package/dist/src/telemetry/signals.d.ts +30 -0
  166. package/dist/src/telemetry/signals.d.ts.map +1 -0
  167. package/dist/src/telemetry/signals.js +11 -0
  168. package/dist/src/telemetry/signals.js.map +1 -0
  169. package/dist/src/telemetry/traces.d.ts +17 -0
  170. package/dist/src/telemetry/traces.d.ts.map +1 -0
  171. package/dist/src/telemetry/traces.js +76 -0
  172. package/dist/src/telemetry/traces.js.map +1 -0
  173. package/dist/src/testing/testing_runtime.d.ts +76 -0
  174. package/dist/src/testing/testing_runtime.d.ts.map +1 -0
  175. package/dist/src/testing/testing_runtime.js +147 -0
  176. package/dist/src/testing/testing_runtime.js.map +1 -0
  177. package/dist/src/transaction.d.ts +28 -0
  178. package/dist/src/transaction.d.ts.map +1 -0
  179. package/dist/src/transaction.js +27 -0
  180. package/dist/src/transaction.js.map +1 -0
  181. package/dist/src/user_database.d.ts +132 -0
  182. package/dist/src/user_database.d.ts.map +1 -0
  183. package/dist/src/user_database.js +324 -0
  184. package/dist/src/user_database.js.map +1 -0
  185. package/dist/src/utils.d.ts +6 -0
  186. package/dist/src/utils.d.ts.map +1 -0
  187. package/dist/src/utils.js +35 -0
  188. package/dist/src/utils.js.map +1 -0
  189. package/dist/src/workflow.d.ts +179 -0
  190. package/dist/src/workflow.d.ts.map +1 -0
  191. package/dist/src/workflow.js +446 -0
  192. package/dist/src/workflow.js.map +1 -0
  193. package/examples/hello/README.md +41 -0
  194. package/examples/hello/dbos-config.yaml +15 -0
  195. package/examples/hello/jest.config.js +8 -0
  196. package/examples/hello/knexfile.ts +23 -0
  197. package/examples/hello/migrations/create_dbos_hello_tables.ts +12 -0
  198. package/examples/hello/package.json +21 -0
  199. package/examples/hello/src/operations.test.ts +38 -0
  200. package/examples/hello/src/operations.ts +21 -0
  201. package/examples/hello/start_postgres_docker.sh +23 -0
  202. package/examples/hello/tsconfig.json +24 -0
  203. package/package.json +78 -0
@@ -0,0 +1,384 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PostgresSystemDatabase = exports.DBOSExecutorIDHeader = void 0;
5
+ const serialize_error_1 = require("serialize-error");
6
+ const dbos_executor_1 = require("./dbos-executor");
7
+ const pg_1 = require("pg");
8
+ const error_1 = require("./error");
9
+ const workflow_1 = require("./workflow");
10
+ const system_db_schema_1 = require("../schemas/system_db_schema");
11
+ const utils_1 = require("./utils");
12
+ exports.DBOSExecutorIDHeader = "dbos-executor-id";
13
+ class PostgresSystemDatabase {
14
+ pgPoolConfig;
15
+ systemDatabaseName;
16
+ logger;
17
+ pool;
18
+ notificationsClient = null;
19
+ notificationsMap = {};
20
+ workflowEventsMap = {};
21
+ workflowStatusBuffer = new Map();
22
+ constructor(pgPoolConfig, systemDatabaseName, logger) {
23
+ this.pgPoolConfig = pgPoolConfig;
24
+ this.systemDatabaseName = systemDatabaseName;
25
+ this.logger = logger;
26
+ const poolConfig = { ...pgPoolConfig };
27
+ poolConfig.database = systemDatabaseName;
28
+ this.pool = new pg_1.Pool(poolConfig);
29
+ }
30
+ async init() {
31
+ const pgSystemClient = new pg_1.Client(this.pgPoolConfig);
32
+ await pgSystemClient.connect();
33
+ // Create the system database and load tables.
34
+ const dbExists = await pgSystemClient.query(`SELECT FROM pg_database WHERE datname = '${this.systemDatabaseName}'`);
35
+ if (dbExists.rows.length === 0) {
36
+ // Create the DBOS system database.
37
+ await pgSystemClient.query(`CREATE DATABASE "${this.systemDatabaseName}"`);
38
+ // Load the DBOS system schemas.
39
+ await this.pool.query(system_db_schema_1.systemDBSchema);
40
+ }
41
+ await this.listenForNotifications();
42
+ await pgSystemClient.end();
43
+ }
44
+ async destroy() {
45
+ if (this.notificationsClient) {
46
+ this.notificationsClient.removeAllListeners();
47
+ this.notificationsClient.release();
48
+ }
49
+ await this.pool.end();
50
+ }
51
+ async checkWorkflowOutput(workflowUUID) {
52
+ const { rows } = await this.pool.query("SELECT status, output, error FROM workflow_status WHERE workflow_uuid=$1", [workflowUUID]);
53
+ if (rows.length === 0 || rows[0].status === workflow_1.StatusString.PENDING) {
54
+ return dbos_executor_1.dbosNull;
55
+ }
56
+ else if (rows[0].status === workflow_1.StatusString.ERROR) {
57
+ throw (0, serialize_error_1.deserializeError)(JSON.parse(rows[0].error));
58
+ }
59
+ else {
60
+ return JSON.parse(rows[0].output);
61
+ }
62
+ }
63
+ async initWorkflowStatus(workflowUUID, name, authenticatedUser, assumedRole, authenticatedRoles, request, args) {
64
+ let executorID = "local";
65
+ if (request && request.headers && request.headers[exports.DBOSExecutorIDHeader]) {
66
+ executorID = request.headers[exports.DBOSExecutorIDHeader];
67
+ }
68
+ await this.pool.query(`INSERT INTO workflow_status (workflow_uuid, status, name, authenticated_user, assumed_role, authenticated_roles, request, output, executor_id) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (workflow_uuid) DO NOTHING`, [workflowUUID, workflow_1.StatusString.PENDING, name, authenticatedUser, assumedRole, JSON.stringify(authenticatedRoles), JSON.stringify(request), null, executorID]);
69
+ const { rows } = await this.pool.query(`INSERT INTO workflow_inputs (workflow_uuid, inputs) VALUES($1, $2) ON CONFLICT (workflow_uuid) DO UPDATE SET workflow_uuid = excluded.workflow_uuid RETURNING inputs`, [workflowUUID, JSON.stringify(args)]);
70
+ return JSON.parse(rows[0].inputs);
71
+ }
72
+ bufferWorkflowOutput(workflowUUID, output) {
73
+ this.workflowStatusBuffer.set(workflowUUID, output);
74
+ }
75
+ /**
76
+ * Flush the workflow output buffer to the database.
77
+ */
78
+ async flushWorkflowStatusBuffer() {
79
+ const localBuffer = new Map(this.workflowStatusBuffer);
80
+ this.workflowStatusBuffer.clear();
81
+ try {
82
+ const client = await this.pool.connect();
83
+ await client.query("BEGIN");
84
+ for (const [workflowUUID, output] of localBuffer) {
85
+ await client.query(`INSERT INTO workflow_status (workflow_uuid, status, output) VALUES($1, $2, $3) ON CONFLICT (workflow_uuid)
86
+ DO UPDATE SET status=EXCLUDED.status, output=EXCLUDED.output;`, [workflowUUID, workflow_1.StatusString.SUCCESS, JSON.stringify(output)]);
87
+ }
88
+ await client.query("COMMIT");
89
+ client.release();
90
+ }
91
+ catch (error) {
92
+ this.logger.error("Error flushing workflow buffer", error);
93
+ // If there is a failure in flushing the buffer, return items to the global buffer for retrying later.
94
+ for (const [workflowUUID, output] of localBuffer) {
95
+ if (!this.workflowStatusBuffer.has(workflowUUID)) {
96
+ this.workflowStatusBuffer.set(workflowUUID, output);
97
+ }
98
+ }
99
+ }
100
+ return Array.from(localBuffer.keys());
101
+ }
102
+ async recordWorkflowError(workflowUUID, error) {
103
+ const serialErr = JSON.stringify((0, serialize_error_1.serializeError)(error));
104
+ await this.pool.query(`INSERT INTO workflow_status (workflow_uuid, status, error) VALUES($1, $2, $3) ON CONFLICT (workflow_uuid)
105
+ DO UPDATE SET status=EXCLUDED.status, error=EXCLUDED.error;`, [workflowUUID, workflow_1.StatusString.ERROR, serialErr]);
106
+ }
107
+ async getPendingWorkflows(executorID) {
108
+ const { rows } = await this.pool.query(`SELECT workflow_uuid FROM workflow_status WHERE status=$1 AND executor_id=$2`, [workflow_1.StatusString.PENDING, executorID]);
109
+ return rows.map(i => i.workflow_uuid);
110
+ }
111
+ async getWorkflowInputs(workflowUUID) {
112
+ const { rows } = await this.pool.query(`SELECT inputs FROM workflow_inputs WHERE workflow_uuid=$1`, [workflowUUID]);
113
+ if (rows.length === 0) {
114
+ return null;
115
+ }
116
+ return JSON.parse(rows[0].inputs);
117
+ }
118
+ async checkOperationOutput(workflowUUID, functionID) {
119
+ const { rows } = await this.pool.query("SELECT output, error FROM operation_outputs WHERE workflow_uuid=$1 AND function_id=$2", [workflowUUID, functionID]);
120
+ if (rows.length === 0) {
121
+ return dbos_executor_1.dbosNull;
122
+ }
123
+ else if (JSON.parse(rows[0].error) !== null) {
124
+ throw (0, serialize_error_1.deserializeError)(JSON.parse(rows[0].error));
125
+ }
126
+ else {
127
+ return JSON.parse(rows[0].output);
128
+ }
129
+ }
130
+ async recordOperationOutput(workflowUUID, functionID, output) {
131
+ const serialOutput = JSON.stringify(output);
132
+ try {
133
+ await this.pool.query("INSERT INTO operation_outputs (workflow_uuid, function_id, output) VALUES ($1, $2, $3);", [workflowUUID, functionID, serialOutput]);
134
+ }
135
+ catch (error) {
136
+ const err = error;
137
+ if (err.code === "40001" || err.code === "23505") {
138
+ // Serialization and primary key conflict (Postgres).
139
+ throw new error_1.DBOSWorkflowConflictUUIDError(workflowUUID);
140
+ }
141
+ else {
142
+ throw err;
143
+ }
144
+ }
145
+ }
146
+ async recordOperationError(workflowUUID, functionID, error) {
147
+ const serialErr = JSON.stringify((0, serialize_error_1.serializeError)(error));
148
+ try {
149
+ await this.pool.query("INSERT INTO operation_outputs (workflow_uuid, function_id, error) VALUES ($1, $2, $3);", [workflowUUID, functionID, serialErr]);
150
+ }
151
+ catch (error) {
152
+ const err = error;
153
+ if (err.code === "40001" || err.code === "23505") {
154
+ // Serialization and primary key conflict (Postgres).
155
+ throw new error_1.DBOSWorkflowConflictUUIDError(workflowUUID);
156
+ }
157
+ else {
158
+ throw err;
159
+ }
160
+ }
161
+ }
162
+ /**
163
+ * Guard the operation, throwing an error if a conflicting execution is detected.
164
+ */
165
+ async recordNotificationOutput(client, workflowUUID, functionID, output) {
166
+ try {
167
+ await client.query("INSERT INTO operation_outputs (workflow_uuid, function_id, output) VALUES ($1, $2, $3);", [workflowUUID, functionID, JSON.stringify(output)]);
168
+ }
169
+ catch (error) {
170
+ await client.query("ROLLBACK");
171
+ client.release();
172
+ const err = error;
173
+ if (err.code === "40001" || err.code === "23505") {
174
+ // Serialization and primary key conflict (Postgres).
175
+ throw new error_1.DBOSWorkflowConflictUUIDError(workflowUUID);
176
+ }
177
+ else {
178
+ throw err;
179
+ }
180
+ }
181
+ }
182
+ nullTopic = "__null__topic__";
183
+ async send(workflowUUID, functionID, destinationUUID, message, topic) {
184
+ topic = topic ?? this.nullTopic;
185
+ const client = await this.pool.connect();
186
+ await client.query("BEGIN ISOLATION LEVEL READ COMMITTED");
187
+ const { rows } = await client.query("SELECT output FROM operation_outputs WHERE workflow_uuid=$1 AND function_id=$2", [workflowUUID, functionID]);
188
+ if (rows.length > 0) {
189
+ await client.query("ROLLBACK");
190
+ client.release();
191
+ return;
192
+ }
193
+ await client.query(`INSERT INTO notifications (destination_uuid, topic, message) VALUES ($1, $2, $3);`, [destinationUUID, topic, JSON.stringify(message)]);
194
+ await this.recordNotificationOutput(client, workflowUUID, functionID, undefined);
195
+ await client.query("COMMIT");
196
+ client.release();
197
+ }
198
+ async recv(workflowUUID, functionID, topic, timeoutSeconds = dbos_executor_1.DBOSExecutor.defaultNotificationTimeoutSec) {
199
+ topic = topic ?? this.nullTopic;
200
+ // First, check for previous executions.
201
+ const checkRows = (await this.pool.query("SELECT output FROM operation_outputs WHERE workflow_uuid=$1 AND function_id=$2", [workflowUUID, functionID])).rows;
202
+ if (checkRows.length > 0) {
203
+ return JSON.parse(checkRows[0].output);
204
+ }
205
+ // Then, register the key with the global notifications listener.
206
+ let resolveNotification;
207
+ const messagePromise = new Promise((resolve) => {
208
+ resolveNotification = resolve;
209
+ });
210
+ const payload = `${workflowUUID}::${topic}`;
211
+ this.notificationsMap[payload] = resolveNotification; // The resolver assignment in the Promise definition runs synchronously.
212
+ let timer;
213
+ const timeoutPromise = new Promise((resolve) => {
214
+ timer = setTimeout(() => {
215
+ resolve();
216
+ }, timeoutSeconds * 1000);
217
+ });
218
+ const received = Promise.race([messagePromise, timeoutPromise]);
219
+ // Check if the key is already in the DB, then wait for the notification if it isn't.
220
+ const initRecvRows = (await this.pool.query("SELECT topic FROM notifications WHERE destination_uuid=$1 AND topic=$2;", [workflowUUID, topic])).rows;
221
+ if (initRecvRows.length === 0) {
222
+ await received;
223
+ }
224
+ clearTimeout(timer);
225
+ // Transactionally consume and return the message if it's in the DB, otherwise return null.
226
+ const client = await this.pool.connect();
227
+ await client.query(`BEGIN ISOLATION LEVEL READ COMMITTED`);
228
+ const finalRecvRows = (await client.query(`WITH oldest_entry AS (
229
+ SELECT destination_uuid, topic, message, created_at_epoch_ms
230
+ FROM notifications
231
+ WHERE destination_uuid = $1
232
+ AND topic = $2
233
+ ORDER BY created_at_epoch_ms ASC
234
+ LIMIT 1
235
+ )
236
+
237
+ DELETE FROM notifications
238
+ USING oldest_entry
239
+ WHERE notifications.destination_uuid = oldest_entry.destination_uuid
240
+ AND notifications.topic = oldest_entry.topic
241
+ AND notifications.created_at_epoch_ms = oldest_entry.created_at_epoch_ms
242
+ RETURNING notifications.*;`, [workflowUUID, topic])).rows;
243
+ let message = null;
244
+ if (finalRecvRows.length > 0) {
245
+ message = JSON.parse(finalRecvRows[0].message);
246
+ }
247
+ await this.recordNotificationOutput(client, workflowUUID, functionID, message);
248
+ await client.query(`COMMIT`);
249
+ client.release();
250
+ return message;
251
+ }
252
+ async setEvent(workflowUUID, functionID, key, message) {
253
+ const client = await this.pool.connect();
254
+ await client.query("BEGIN ISOLATION LEVEL READ COMMITTED");
255
+ let { rows } = await client.query("SELECT output FROM operation_outputs WHERE workflow_uuid=$1 AND function_id=$2", [workflowUUID, functionID]);
256
+ if (rows.length > 0) {
257
+ await client.query("ROLLBACK");
258
+ client.release();
259
+ return;
260
+ }
261
+ ({ rows } = await client.query(`INSERT INTO workflow_events (workflow_uuid, key, value) VALUES ($1, $2, $3) ON CONFLICT (workflow_uuid, key) DO NOTHING RETURNING workflow_uuid;`, [workflowUUID, key, JSON.stringify(message)]));
262
+ if (rows.length === 0) {
263
+ await client.query("ROLLBACK");
264
+ client.release();
265
+ throw new error_1.DuplicateWorkflowEventError(workflowUUID, key);
266
+ }
267
+ await this.recordNotificationOutput(client, workflowUUID, functionID, undefined);
268
+ await client.query("COMMIT");
269
+ client.release();
270
+ }
271
+ async getEvent(workflowUUID, key, timeoutSeconds, callerUUID, functionID) {
272
+ // Check if the operation has been done before for OAOO (only do this inside a workflow).
273
+ if (callerUUID !== undefined && functionID !== undefined) {
274
+ const { rows } = await this.pool.query("SELECT output FROM operation_outputs WHERE workflow_uuid=$1 AND function_id=$2", [callerUUID, functionID]);
275
+ if (rows.length > 0) {
276
+ return JSON.parse(rows[0].output);
277
+ }
278
+ }
279
+ // Register the key with the global notifications listener.
280
+ let resolveNotification;
281
+ const valuePromise = new Promise((resolve) => {
282
+ resolveNotification = resolve;
283
+ });
284
+ this.workflowEventsMap[`${workflowUUID}::${key}`] = resolveNotification; // The resolver assignment in the Promise definition runs synchronously.
285
+ let timer;
286
+ const timeoutPromise = new Promise((resolve) => {
287
+ timer = setTimeout(() => {
288
+ resolve();
289
+ }, timeoutSeconds * 1000);
290
+ });
291
+ const received = Promise.race([valuePromise, timeoutPromise]);
292
+ // Check if the key is already in the DB, then wait for the notification if it isn't.
293
+ const initRecvRows = (await this.pool.query("SELECT key, value FROM workflow_events WHERE workflow_uuid=$1 AND key=$2;", [workflowUUID, key])).rows;
294
+ if (initRecvRows.length === 0) {
295
+ await received;
296
+ }
297
+ clearTimeout(timer);
298
+ // Return the value if it's in the DB, otherwise return null.
299
+ let value = null;
300
+ if (initRecvRows.length > 0) {
301
+ value = JSON.parse(initRecvRows[0].value);
302
+ }
303
+ else {
304
+ // Read it again from the database.
305
+ const finalRecvRows = (await this.pool.query("SELECT value FROM workflow_events WHERE workflow_uuid=$1 AND key=$2;", [workflowUUID, key])).rows;
306
+ if (finalRecvRows.length > 0) {
307
+ value = JSON.parse(finalRecvRows[0].value);
308
+ }
309
+ }
310
+ // Record the output if it is inside a workflow.
311
+ if (callerUUID !== undefined && functionID !== undefined) {
312
+ await this.recordOperationOutput(callerUUID, functionID, value);
313
+ }
314
+ return value;
315
+ }
316
+ async getWorkflowStatus(workflowUUID, callerUUID, functionID) {
317
+ // Check if the operation has been done before for OAOO (only do this inside a workflow).
318
+ if (callerUUID !== undefined && functionID !== undefined) {
319
+ const { rows } = await this.pool.query("SELECT output FROM operation_outputs WHERE workflow_uuid=$1 AND function_id=$2", [callerUUID, functionID]);
320
+ if (rows.length > 0) {
321
+ return JSON.parse(rows[0].output);
322
+ }
323
+ }
324
+ const { rows } = await this.pool.query("SELECT status, name, authenticated_user, assumed_role, authenticated_roles, request FROM workflow_status WHERE workflow_uuid=$1", [workflowUUID]);
325
+ let value = null;
326
+ if (rows.length > 0) {
327
+ value = {
328
+ status: rows[0].status,
329
+ workflowName: rows[0].name,
330
+ authenticatedUser: rows[0].authenticated_user,
331
+ assumedRole: rows[0].assumed_role,
332
+ authenticatedRoles: JSON.parse(rows[0].authenticated_roles),
333
+ request: JSON.parse(rows[0].request),
334
+ };
335
+ }
336
+ // Record the output if it is inside a workflow.
337
+ if (callerUUID !== undefined && functionID !== undefined) {
338
+ await this.recordOperationOutput(callerUUID, functionID, value);
339
+ }
340
+ return value;
341
+ }
342
+ async getWorkflowResult(workflowUUID) {
343
+ const pollingIntervalMs = 1000;
344
+ // eslint-disable-next-line no-constant-condition
345
+ while (true) {
346
+ const { rows } = await this.pool.query("SELECT status, output, error FROM workflow_status WHERE workflow_uuid=$1", [workflowUUID]);
347
+ if (rows.length > 0) {
348
+ const status = rows[0].status;
349
+ if (status === workflow_1.StatusString.SUCCESS) {
350
+ return JSON.parse(rows[0].output);
351
+ }
352
+ else if (status === workflow_1.StatusString.ERROR) {
353
+ throw (0, serialize_error_1.deserializeError)(JSON.parse(rows[0].error));
354
+ }
355
+ }
356
+ await (0, utils_1.sleep)(pollingIntervalMs);
357
+ }
358
+ }
359
+ /* BACKGROUND PROCESSES */
360
+ /**
361
+ * A background process that listens for notifications from Postgres then signals the appropriate
362
+ * workflow listener by resolving its promise.
363
+ */
364
+ async listenForNotifications() {
365
+ this.notificationsClient = await this.pool.connect();
366
+ await this.notificationsClient.query("LISTEN dbos_notifications_channel;");
367
+ await this.notificationsClient.query("LISTEN dbos_workflow_events_channel;");
368
+ const handler = (msg) => {
369
+ if (msg.channel === 'dbos_notifications_channel') {
370
+ if (msg.payload && msg.payload in this.notificationsMap) {
371
+ this.notificationsMap[msg.payload]();
372
+ }
373
+ }
374
+ else {
375
+ if (msg.payload && msg.payload in this.workflowEventsMap) {
376
+ this.workflowEventsMap[msg.payload]();
377
+ }
378
+ }
379
+ };
380
+ this.notificationsClient.on("notification", handler);
381
+ }
382
+ }
383
+ exports.PostgresSystemDatabase = PostgresSystemDatabase;
384
+ //# sourceMappingURL=system_database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system_database.js","sourceRoot":"","sources":["../../src/system_database.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAEvD,qDAAmE;AACnE,mDAAmE;AACnE,2BAAuF;AACvF,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,CAAC,iBAAiB,EAAE;oBACxD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;iBACvC;aACF;QACH,CAAC,CAAC;QACF,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;CACF;AA1ZD,wDA0ZC"}
@@ -0,0 +1,17 @@
1
+ import { MethodRegistrationBase } from "../decorators";
2
+ import { ITelemetryExporter } from "./exporters";
3
+ import { DBOSSignal } from "./signals";
4
+ export declare class TelemetryCollector {
5
+ readonly exporters: ITelemetryExporter<any, any>[];
6
+ private readonly signals;
7
+ private readonly signalBufferID;
8
+ private readonly processAndExportSignalsIntervalMs;
9
+ private readonly processAndExportSignalsMaxBatchSize;
10
+ constructor(exporters: ITelemetryExporter<any, any>[]);
11
+ init(registeredOperations?: Array<MethodRegistrationBase>): Promise<void>;
12
+ destroy(): Promise<void>;
13
+ push(signal: DBOSSignal): void;
14
+ private pop;
15
+ processAndExportSignals(): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=collector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../../src/telemetry/collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAmBvC,qBAAa,kBAAkB;IAQjB,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;IAN9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,iCAAiC,CAAQ;IAC1D,OAAO,CAAC,QAAQ,CAAC,mCAAmC,CAAM;gBAGrC,SAAS,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;IAMxD,IAAI,CAAC,oBAAoB,GAAE,KAAK,CAAC,sBAAsB,CAAM;IAQ7D,OAAO;IAUb,IAAI,CAAC,MAAM,EAAE,UAAU;IAIvB,OAAO,CAAC,GAAG;IAIL,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB/C"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TelemetryCollector = void 0;
4
+ class SignalsQueue {
5
+ data = [];
6
+ push(signal) {
7
+ this.data.push(signal);
8
+ }
9
+ pop() {
10
+ return this.data.shift();
11
+ }
12
+ size() {
13
+ return this.data.length;
14
+ }
15
+ }
16
+ // TODO: Handle temporary workflows properly.
17
+ class TelemetryCollector {
18
+ exporters;
19
+ // Signals buffer management
20
+ signals = new SignalsQueue();
21
+ signalBufferID;
22
+ processAndExportSignalsIntervalMs = 1000;
23
+ processAndExportSignalsMaxBatchSize = 10;
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ constructor(exporters) {
26
+ this.exporters = exporters;
27
+ this.signalBufferID = setInterval(() => {
28
+ void this.processAndExportSignals();
29
+ }, this.processAndExportSignalsIntervalMs);
30
+ }
31
+ async init(registeredOperations = []) {
32
+ for (const exporter of this.exporters) {
33
+ if (exporter.init) {
34
+ await exporter.init(registeredOperations);
35
+ }
36
+ }
37
+ }
38
+ async destroy() {
39
+ clearInterval(this.signalBufferID);
40
+ await this.processAndExportSignals();
41
+ for (const exporter of this.exporters) {
42
+ if (exporter.destroy) {
43
+ await exporter.destroy();
44
+ }
45
+ }
46
+ }
47
+ push(signal) {
48
+ this.signals.push(signal);
49
+ }
50
+ pop() {
51
+ return this.signals.pop();
52
+ }
53
+ async processAndExportSignals() {
54
+ const batch = [];
55
+ while (this.signals.size() > 0 && batch.length < this.processAndExportSignalsMaxBatchSize) {
56
+ const signal = this.pop();
57
+ if (!signal) {
58
+ break;
59
+ }
60
+ batch.push(signal);
61
+ }
62
+ if (batch.length > 0) {
63
+ const exports = [];
64
+ for (const exporter of this.exporters) {
65
+ exports.push(exporter.export(batch));
66
+ }
67
+ try {
68
+ await Promise.all(exports);
69
+ }
70
+ catch (e) {
71
+ console.error(e.message);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ exports.TelemetryCollector = TelemetryCollector;
77
+ //# sourceMappingURL=collector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.js","sourceRoot":"","sources":["../../../src/telemetry/collector.ts"],"names":[],"mappings":";;;AAIA,MAAM,YAAY;IAChB,IAAI,GAAiB,EAAE,CAAC;IAExB,IAAI,CAAC,MAAkB;QACrB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1B,CAAC;CACF;AAED,6CAA6C;AAC7C,MAAa,kBAAkB;IAQR;IAPrB,4BAA4B;IACX,OAAO,GAAiB,IAAI,YAAY,EAAE,CAAC;IAC3C,cAAc,CAAiB;IAC/B,iCAAiC,GAAG,IAAI,CAAC;IACzC,mCAAmC,GAAG,EAAE,CAAC;IAE1D,8DAA8D;IAC9D,YAAqB,SAAyC;QAAzC,cAAS,GAAT,SAAS,CAAgC;QAC5D,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,GAAG,EAAE;YACrC,KAAK,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACtC,CAAC,EAAE,IAAI,CAAC,iCAAiC,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,uBAAsD,EAAE;QACjE,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;YACrC,IAAI,QAAQ,CAAC,IAAI,EAAE;gBACjB,MAAM,QAAQ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ACrC;SACF;IACH,CAAC;CACF;AA7DD,gDA6DC"}
@@ -0,0 +1,29 @@
1
+ import { Client, QueryConfig, QueryArrayResult, PoolConfig } from "pg";
2
+ import { DBOSDataType, MethodRegistrationBase } from "./../decorators";
3
+ import { DBOSSignal, ProvenanceSignal, TelemetrySignal } from "./signals";
4
+ export interface ITelemetryExporter<T, U> {
5
+ export(signal: DBOSSignal[]): Promise<T>;
6
+ process?(signal: DBOSSignal[]): U;
7
+ init?(registeredOperations?: ReadonlyArray<MethodRegistrationBase>): Promise<void>;
8
+ destroy?(): Promise<void>;
9
+ }
10
+ export declare const JAEGER_EXPORTER = "JaegerExporter";
11
+ export declare class JaegerExporter implements ITelemetryExporter<void, undefined> {
12
+ private readonly exporter;
13
+ constructor(endpoint?: string);
14
+ export(rawSignals: DBOSSignal[]): Promise<void>;
15
+ }
16
+ export declare const POSTGRES_EXPORTER = "PostgresExporter";
17
+ export declare class PostgresExporter implements ITelemetryExporter<QueryArrayResult[], QueryConfig[]> {
18
+ private readonly poolConfig;
19
+ readonly observabilityDBName: string;
20
+ readonly pgClient: Client;
21
+ constructor(poolConfig: PoolConfig, observabilityDBName?: string);
22
+ static getPGDataType(t: DBOSDataType): string;
23
+ init(registeredOperations?: ReadonlyArray<MethodRegistrationBase>): Promise<void>;
24
+ destroy(): Promise<void>;
25
+ process(signals: TelemetrySignal[]): QueryConfig[];
26
+ processProvenance(signals: ProvenanceSignal[]): QueryConfig;
27
+ export(signals: DBOSSignal[]): Promise<QueryArrayResult[]>;
28
+ }
29
+ //# sourceMappingURL=exporters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporters.d.ts","sourceRoot":"","sources":["../../../src/telemetry/exporters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEvE,OAAO,EAAY,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEj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