@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,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DBOSConfigKeyTypeError = exports.DBOSUndefinedDecoratorInputError = exports.DBOSNotAuthorizedError = exports.DBOSResponseError = exports.DuplicateWorkflowEventError = exports.DBOSDataValidationError = exports.DBOSPostgresExporterError = exports.DBOSNotRegisteredError = exports.DBOSWorkflowConflictUUIDError = exports.DBOSTopicPermissionDeniedError = exports.DBOSInitializationError = exports.DBOSWorkflowPermissionDeniedError = exports.DBOSError = exports.isClientError = void 0;
4
+ const pg_1 = require("pg");
5
+ function formatPgDatabaseError(err) {
6
+ let msg = "";
7
+ if (err.severity) {
8
+ msg = msg.concat(`severity: ${err.severity} \n`);
9
+ }
10
+ if (err.code) {
11
+ msg = msg.concat(`code: ${err.code} \n`);
12
+ }
13
+ if (err.detail) {
14
+ msg = msg.concat(`detail: ${err.detail} \n`);
15
+ }
16
+ if (err.hint) {
17
+ msg = msg.concat(`hint: ${err.hint} \n`);
18
+ }
19
+ if (err.position) {
20
+ msg = msg.concat(`position: ${err.position} \n`);
21
+ }
22
+ if (err.internalPosition) {
23
+ msg = msg.concat(`internalPosition: ${err.internalPosition} \n`);
24
+ }
25
+ if (err.internalQuery) {
26
+ msg = msg.concat(`internalQuery: ${err.internalQuery} \n`);
27
+ }
28
+ if (err.where) {
29
+ msg = msg.concat(`where: ${err.where} \n`);
30
+ }
31
+ if (err.schema) {
32
+ msg = msg.concat(`schema: ${err.schema} \n`);
33
+ }
34
+ if (err.table) {
35
+ msg = msg.concat(`table: ${err.table} \n`);
36
+ }
37
+ if (err.column) {
38
+ msg = msg.concat(`column: ${err.column} \n`);
39
+ }
40
+ if (err.dataType) {
41
+ msg = msg.concat(`dataType: ${err.dataType} \n`);
42
+ }
43
+ if (err.constraint) {
44
+ msg = msg.concat(`constraint: ${err.constraint} \n`);
45
+ }
46
+ if (err.file) {
47
+ msg = msg.concat(`file: ${err.file} \n`);
48
+ }
49
+ if (err.line) {
50
+ msg = msg.concat(`line: ${err.line} \n`);
51
+ }
52
+ return msg;
53
+ }
54
+ // Return if the error is caused by client request or by server internal.
55
+ function isClientError(dbosErrorCode) {
56
+ return (dbosErrorCode === DataValidationError) || (dbosErrorCode === WorkflowPermissionDeniedError) || (dbosErrorCode === TopicPermissionDeniedError) || (dbosErrorCode === ConflictingUUIDError) || (dbosErrorCode === NotRegisteredError);
57
+ }
58
+ exports.isClientError = isClientError;
59
+ class DBOSError extends Error {
60
+ dbosErrorCode;
61
+ // TODO: define a better coding system.
62
+ constructor(msg, dbosErrorCode = 1) {
63
+ super(msg);
64
+ this.dbosErrorCode = dbosErrorCode;
65
+ }
66
+ }
67
+ exports.DBOSError = DBOSError;
68
+ const WorkflowPermissionDeniedError = 2;
69
+ class DBOSWorkflowPermissionDeniedError extends DBOSError {
70
+ constructor(runAs, workflowName) {
71
+ const msg = `Subject ${runAs} does not have permission to run workflow ${workflowName}`;
72
+ super(msg, WorkflowPermissionDeniedError);
73
+ }
74
+ }
75
+ exports.DBOSWorkflowPermissionDeniedError = DBOSWorkflowPermissionDeniedError;
76
+ const InitializationError = 3;
77
+ class DBOSInitializationError extends DBOSError {
78
+ constructor(msg) {
79
+ super(msg, InitializationError);
80
+ }
81
+ }
82
+ exports.DBOSInitializationError = DBOSInitializationError;
83
+ const TopicPermissionDeniedError = 4;
84
+ class DBOSTopicPermissionDeniedError extends DBOSError {
85
+ constructor(destinationUUID, workflowUUID, functionID, runAs) {
86
+ const msg = `Subject ${runAs} does not have permission on destination UUID ${destinationUUID}.` + `(workflow UUID: ${workflowUUID}, function ID: ${functionID})`;
87
+ super(msg, TopicPermissionDeniedError);
88
+ }
89
+ }
90
+ exports.DBOSTopicPermissionDeniedError = DBOSTopicPermissionDeniedError;
91
+ const ConflictingUUIDError = 5;
92
+ class DBOSWorkflowConflictUUIDError extends DBOSError {
93
+ constructor(workflowUUID) {
94
+ super(`Conflicting UUID ${workflowUUID}`, ConflictingUUIDError);
95
+ }
96
+ }
97
+ exports.DBOSWorkflowConflictUUIDError = DBOSWorkflowConflictUUIDError;
98
+ const NotRegisteredError = 6;
99
+ class DBOSNotRegisteredError extends DBOSError {
100
+ constructor(name) {
101
+ const msg = `Operation (Name: ${name}) not registered`;
102
+ super(msg, NotRegisteredError);
103
+ }
104
+ }
105
+ exports.DBOSNotRegisteredError = DBOSNotRegisteredError;
106
+ const PostgresExporterError = 7;
107
+ class DBOSPostgresExporterError extends DBOSError {
108
+ constructor(err) {
109
+ let msg = `PostgresExporter error: ${err.message} \n`;
110
+ if (err instanceof pg_1.DatabaseError) {
111
+ msg = msg.concat(formatPgDatabaseError(err));
112
+ }
113
+ super(msg, PostgresExporterError);
114
+ }
115
+ }
116
+ exports.DBOSPostgresExporterError = DBOSPostgresExporterError;
117
+ const DataValidationError = 9;
118
+ class DBOSDataValidationError extends DBOSError {
119
+ constructor(msg) {
120
+ super(msg, DataValidationError);
121
+ }
122
+ }
123
+ exports.DBOSDataValidationError = DBOSDataValidationError;
124
+ const DuplicateWorkflowEvent = 10;
125
+ class DuplicateWorkflowEventError extends DBOSError {
126
+ constructor(workflowUUID, key) {
127
+ super(`Workflow ${workflowUUID} has already emitted an event with key ${key}`, DuplicateWorkflowEvent);
128
+ }
129
+ }
130
+ exports.DuplicateWorkflowEventError = DuplicateWorkflowEventError;
131
+ // This error is thrown by applications.
132
+ const ResponseError = 11;
133
+ class DBOSResponseError extends DBOSError {
134
+ status;
135
+ constructor(msg, status = 500) {
136
+ super(msg, ResponseError);
137
+ this.status = status;
138
+ }
139
+ }
140
+ exports.DBOSResponseError = DBOSResponseError;
141
+ const NotAuthorizedError = 12;
142
+ class DBOSNotAuthorizedError extends DBOSError {
143
+ status;
144
+ constructor(msg, status = 403) {
145
+ super(msg, NotAuthorizedError);
146
+ this.status = status;
147
+ }
148
+ }
149
+ exports.DBOSNotAuthorizedError = DBOSNotAuthorizedError;
150
+ const UndefinedDecoratorInputError = 13;
151
+ class DBOSUndefinedDecoratorInputError extends DBOSError {
152
+ constructor(decoratorName) {
153
+ super(`${decoratorName} received undefined input. Possible circular dependency?`, UndefinedDecoratorInputError);
154
+ }
155
+ }
156
+ exports.DBOSUndefinedDecoratorInputError = DBOSUndefinedDecoratorInputError;
157
+ const ConfigKeyTypeError = 14;
158
+ class DBOSConfigKeyTypeError extends DBOSError {
159
+ constructor(configKey, expectedType, actualType) {
160
+ super(`${configKey} should be of type ${expectedType}, but got ${actualType}`, ConfigKeyTypeError);
161
+ }
162
+ }
163
+ exports.DBOSConfigKeyTypeError = DBOSConfigKeyTypeError;
164
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":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Aa,gCAAiC,SAAQ,SAAS;IAC7D,YAAY,aAAqB;QAC/B,KAAK,CAAC,GAAG,aAAa,0DAA0D,EAAE,4BAA4B,CAAC,CAAC;IAClH,CAAC;CACF;AAJD,4EAIC;AAED,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAa,sBAAuB,SAAQ,SAAS;IACnD,YAAY,SAAiB,EAAE,YAAoB,EAAE,UAAkB;QACrE,KAAK,CAAC,GAAG,SAAS,sBAAsB,YAAY,aAAa,UAAU,EAAE,EAAE,kBAAkB,CAAC,CAAC;IACrG,CAAC;CACF;AAJD,wDAIC"}
@@ -0,0 +1,62 @@
1
+ import { MethodRegistration, MethodParameter, MethodRegistrationBase } from "../decorators";
2
+ import { DBOSExecutor } from "../dbos-executor";
3
+ import { DBOSContext, DBOSContextImpl } from "../context";
4
+ import Koa from "koa";
5
+ import { TailParameters, WorkflowHandle, WorkflowContext, WFInvokeFuncs } from "../workflow";
6
+ import { W3CTraceContextPropagator } from "@opentelemetry/core";
7
+ type WFFunc = (ctxt: WorkflowContext, ...args: any[]) => Promise<any>;
8
+ export type InvokeFuncs<T> = WFInvokeFuncs<T> & HandlerWfFuncs<T>;
9
+ type HandlerWfFuncs<T> = {
10
+ [P in keyof T as T[P] extends WFFunc ? P : never]: T[P] extends WFFunc ? (...args: TailParameters<T[P]>) => Promise<WorkflowHandle<Awaited<ReturnType<T[P]>>>> : never;
11
+ };
12
+ export interface HandlerContext extends DBOSContext {
13
+ readonly koaContext: Koa.Context;
14
+ invoke<T extends object>(targetClass: T, workflowUUID?: string): InvokeFuncs<T>;
15
+ retrieveWorkflow<R>(workflowUUID: string): WorkflowHandle<R>;
16
+ send<T extends NonNullable<any>>(destinationUUID: string, message: T, topic?: string, idempotencyKey?: string): Promise<void>;
17
+ getEvent<T extends NonNullable<any>>(workflowUUID: string, key: string, timeoutSeconds?: number): Promise<T | null>;
18
+ }
19
+ export declare class HandlerContextImpl extends DBOSContextImpl implements HandlerContext {
20
+ #private;
21
+ readonly koaContext: Koa.Context;
22
+ readonly W3CTraceContextPropagator: W3CTraceContextPropagator;
23
+ constructor(wfe: DBOSExecutor, koaContext: Koa.Context);
24
+ send<T extends NonNullable<any>>(destinationUUID: string, message: T, topic?: string, idempotencyKey?: string): Promise<void>;
25
+ getEvent<T extends NonNullable<any>>(workflowUUID: string, key: string, timeoutSeconds?: number): Promise<T | null>;
26
+ retrieveWorkflow<R>(workflowUUID: string): WorkflowHandle<R>;
27
+ /**
28
+ * Generate a proxy object for the provided class that wraps direct calls (i.e. OpClass.someMethod(param))
29
+ * to use WorkflowContext.Transaction(OpClass.someMethod, param);
30
+ */
31
+ invoke<T extends object>(object: T, workflowUUID?: string): InvokeFuncs<T>;
32
+ }
33
+ export declare enum APITypes {
34
+ GET = "GET",
35
+ POST = "POST"
36
+ }
37
+ export declare enum ArgSources {
38
+ DEFAULT = "DEFAULT",
39
+ BODY = "BODY",
40
+ QUERY = "QUERY",
41
+ URL = "URL"
42
+ }
43
+ export interface HandlerRegistrationBase extends MethodRegistrationBase {
44
+ apiType: APITypes;
45
+ apiURL: string;
46
+ args: HandlerParameter[];
47
+ }
48
+ export declare class HandlerRegistration<This, Args extends unknown[], Return> extends MethodRegistration<This, Args, Return> {
49
+ apiType: APITypes;
50
+ apiURL: string;
51
+ args: HandlerParameter[];
52
+ constructor(origFunc: (this: This, ...args: Args) => Promise<Return>);
53
+ }
54
+ export declare class HandlerParameter extends MethodParameter {
55
+ argSource: ArgSources;
56
+ constructor(idx: number, at: Function);
57
+ }
58
+ export declare function GetApi(url: string): <This, Ctx extends DBOSContext, Args extends unknown[], Return>(target: object, propertyKey: string, inDescriptor: TypedPropertyDescriptor<(this: This, ctx: Ctx, ...args: Args) => Promise<Return>>) => TypedPropertyDescriptor<(this: This, ctx: Ctx, ...args: Args) => Promise<Return>>;
59
+ export declare function PostApi(url: string): <This, Ctx extends DBOSContext, Args extends unknown[], Return>(target: object, propertyKey: string, inDescriptor: TypedPropertyDescriptor<(this: This, ctx: Ctx, ...args: Args) => Promise<Return>>) => TypedPropertyDescriptor<(this: This, ctx: Ctx, ...args: Args) => Promise<Return>>;
60
+ export declare function ArgSource(source: ArgSources): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
61
+ export {};
62
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/httpServer/handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAA8D,sBAAsB,EAA2B,MAAM,eAAe,CAAC;AACjL,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAY,cAAc,EAAE,cAAc,EAAkB,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvH,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAMhE,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;AAElE,KAAK,cAAc,CAAC,CAAC,IAAI;KACtB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAA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CAAC,MAAM,EAAE,UAAU,YACjB,MAAM,eAAe,MAAM,GAAG,MAAM,kBAAkB,MAAM,UAMtF"}
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgSource = exports.PostApi = exports.GetApi = exports.HandlerParameter = exports.HandlerRegistration = exports.ArgSources = exports.APITypes = exports.HandlerContextImpl = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const decorators_1 = require("../decorators");
6
+ const dbos_executor_1 = require("../dbos-executor");
7
+ const context_1 = require("../context");
8
+ const core_1 = require("@opentelemetry/core");
9
+ const api_1 = require("@opentelemetry/api");
10
+ class HandlerContextImpl extends context_1.DBOSContextImpl {
11
+ koaContext;
12
+ #wfe;
13
+ W3CTraceContextPropagator;
14
+ constructor(wfe, koaContext) {
15
+ // If present, retrieve the trace context from the request
16
+ const httpTracer = new core_1.W3CTraceContextPropagator();
17
+ const extractedSpanContext = api_1.trace.getSpanContext(httpTracer.extract(api_1.ROOT_CONTEXT, koaContext.request.headers, api_1.defaultTextMapGetter));
18
+ let span;
19
+ const spanAttributes = {
20
+ operationName: koaContext.url,
21
+ };
22
+ if (extractedSpanContext === undefined) {
23
+ span = wfe.tracer.startSpan(koaContext.url, spanAttributes);
24
+ }
25
+ else {
26
+ extractedSpanContext.isRemote = true;
27
+ span = wfe.tracer.startSpanWithContext(extractedSpanContext, koaContext.url, spanAttributes);
28
+ }
29
+ super(koaContext.url, span, wfe.logger);
30
+ this.koaContext = koaContext;
31
+ this.W3CTraceContextPropagator = httpTracer;
32
+ this.request = {
33
+ headers: koaContext.request.headers,
34
+ rawHeaders: koaContext.req.rawHeaders,
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
36
+ params: koaContext.params,
37
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
38
+ body: koaContext.request.body,
39
+ rawBody: koaContext.request.rawBody,
40
+ query: koaContext.request.query,
41
+ querystring: koaContext.request.querystring,
42
+ url: koaContext.request.url,
43
+ ip: koaContext.request.ip,
44
+ };
45
+ if (wfe.config.application) {
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
47
+ this.applicationConfig = wfe.config.application;
48
+ }
49
+ this.#wfe = wfe;
50
+ }
51
+ ///////////////////////
52
+ /* PUBLIC INTERFACE */
53
+ ///////////////////////
54
+ async send(destinationUUID, message, topic, idempotencyKey) {
55
+ return this.#wfe.send(destinationUUID, message, topic, idempotencyKey);
56
+ }
57
+ async getEvent(workflowUUID, key, timeoutSeconds = dbos_executor_1.DBOSExecutor.defaultNotificationTimeoutSec) {
58
+ return this.#wfe.getEvent(workflowUUID, key, timeoutSeconds);
59
+ }
60
+ retrieveWorkflow(workflowUUID) {
61
+ return this.#wfe.retrieveWorkflow(workflowUUID);
62
+ }
63
+ /**
64
+ * Generate a proxy object for the provided class that wraps direct calls (i.e. OpClass.someMethod(param))
65
+ * to use WorkflowContext.Transaction(OpClass.someMethod, param);
66
+ */
67
+ invoke(object, workflowUUID) {
68
+ const ops = (0, decorators_1.getRegisteredOperations)(object);
69
+ const proxy = {};
70
+ const params = { workflowUUID: workflowUUID, parentCtx: this };
71
+ for (const op of ops) {
72
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
73
+ proxy[op.name] = op.txnConfig
74
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
75
+ ? (...args) => this.#transaction(op.registeredFunction, params, ...args)
76
+ : op.workflowConfig
77
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
78
+ ? (...args) => this.#workflow(op.registeredFunction, params, ...args)
79
+ : op.commConfig
80
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
81
+ ? (...args) => this.#external(op.registeredFunction, params, ...args)
82
+ : undefined;
83
+ }
84
+ return proxy;
85
+ }
86
+ //////////////////////
87
+ /* PRIVATE METHODS */
88
+ /////////////////////
89
+ async #workflow(wf, params, ...args) {
90
+ return this.#wfe.workflow(wf, params, ...args);
91
+ }
92
+ async #transaction(txn, params, ...args) {
93
+ return this.#wfe.transaction(txn, params, ...args);
94
+ }
95
+ async #external(commFn, params, ...args) {
96
+ return this.#wfe.external(commFn, params, ...args);
97
+ }
98
+ }
99
+ exports.HandlerContextImpl = HandlerContextImpl;
100
+ //////////////////////////
101
+ /* REGISTRATION OBJECTS */
102
+ //////////////////////////
103
+ var APITypes;
104
+ (function (APITypes) {
105
+ APITypes["GET"] = "GET";
106
+ APITypes["POST"] = "POST";
107
+ })(APITypes || (exports.APITypes = APITypes = {}));
108
+ var ArgSources;
109
+ (function (ArgSources) {
110
+ ArgSources["DEFAULT"] = "DEFAULT";
111
+ ArgSources["BODY"] = "BODY";
112
+ ArgSources["QUERY"] = "QUERY";
113
+ ArgSources["URL"] = "URL";
114
+ })(ArgSources || (exports.ArgSources = ArgSources = {}));
115
+ class HandlerRegistration extends decorators_1.MethodRegistration {
116
+ apiType = APITypes.GET;
117
+ apiURL = "";
118
+ args = [];
119
+ constructor(origFunc) {
120
+ super(origFunc);
121
+ }
122
+ }
123
+ exports.HandlerRegistration = HandlerRegistration;
124
+ class HandlerParameter extends decorators_1.MethodParameter {
125
+ argSource = ArgSources.DEFAULT;
126
+ // eslint-disable-next-line @typescript-eslint/ban-types
127
+ constructor(idx, at) {
128
+ super(idx, at);
129
+ }
130
+ }
131
+ exports.HandlerParameter = HandlerParameter;
132
+ /////////////////////////
133
+ /* ENDPOINT DECORATORS */
134
+ /////////////////////////
135
+ function GetApi(url) {
136
+ function apidec(target, propertyKey, inDescriptor) {
137
+ const { descriptor, registration } = (0, decorators_1.registerAndWrapFunction)(target, propertyKey, inDescriptor);
138
+ const handlerRegistration = registration;
139
+ handlerRegistration.apiURL = url;
140
+ handlerRegistration.apiType = APITypes.GET;
141
+ return descriptor;
142
+ }
143
+ return apidec;
144
+ }
145
+ exports.GetApi = GetApi;
146
+ function PostApi(url) {
147
+ function apidec(target, propertyKey, inDescriptor) {
148
+ const { descriptor, registration } = (0, decorators_1.registerAndWrapFunction)(target, propertyKey, inDescriptor);
149
+ const handlerRegistration = registration;
150
+ handlerRegistration.apiURL = url;
151
+ handlerRegistration.apiType = APITypes.POST;
152
+ return descriptor;
153
+ }
154
+ return apidec;
155
+ }
156
+ exports.PostApi = PostApi;
157
+ ///////////////////////////////////
158
+ /* ENDPOINT PARAMETER DECORATORS */
159
+ ///////////////////////////////////
160
+ function ArgSource(source) {
161
+ return function (target, propertyKey, parameterIndex) {
162
+ const existingParameters = (0, decorators_1.getOrCreateMethodArgsRegistration)(target, propertyKey);
163
+ const curParam = existingParameters[parameterIndex];
164
+ curParam.argSource = source;
165
+ };
166
+ }
167
+ exports.ArgSource = ArgSource;
168
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/httpServer/handler.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,8CAAiL;AACjL,oDAAgD;AAChD,wCAA0D;AAI1D,8CAAgE;AAChE,4CAA+E;AAoB/E,MAAa,kBAAmB,SAAQ,yBAAe;IAIb;IAH/B,IAAI,CAAe;IACnB,yBAAyB,CAA4B;IAE9D,YAAY,GAAiB,EAAW,UAAuB;QAC7D,0DAA0D;QAC1D,MAAM,UAAU,GAAG,IAAI,gCAAyB,EAAE,CAAC;QACnD,MAAM,oBAAoB,GAAG,WAAK,CAAC,cAAc,CAC7C,UAAU,CAAC,OAAO,CAAC,kBAAY,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,0BAAoB,CAAC,CACrF,CAAA;QACD,IAAI,IAAU,CAAC;QACf,MAAM,cAAc,GAAG;YACrB,aAAa,EAAE,UAAU,CAAC,GAAG;SAC9B,CAAC;QACF,IAAI,oBAAoB,KAAK,SAAS,EAAE;YACtC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SAC7D;aAAM;YACL,oBAAoB,CAAC,QA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C;QAElF,MAAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAqB,CAAC;QACxE,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC;AAPD,8BAOC"}
@@ -0,0 +1,56 @@
1
+ import Koa from "koa";
2
+ import { ClassRegistration, RegistrationDefaults } from "../decorators";
3
+ import { UserDatabaseClient } from "../user_database";
4
+ import { Span } from "@opentelemetry/sdk-trace-base";
5
+ import { Logger as DBOSLogger } from "../telemetry/logs";
6
+ import { OpenAPIV3 as OpenApi3 } from 'openapi-types';
7
+ export interface MiddlewareContext {
8
+ readonly koaContext: Koa.Context;
9
+ readonly name: string;
10
+ readonly requiredRole: string[];
11
+ readonly logger: DBOSLogger;
12
+ readonly span: Span;
13
+ getConfig<T>(key: string, deflt: T | undefined): T | undefined;
14
+ query<C extends UserDatabaseClient, R, T extends unknown[]>(qry: (dbclient: C, ...args: T) => Promise<R>, ...args: T): Promise<R>;
15
+ }
16
+ /**
17
+ * Authentication middleware that executes before a request reaches a function.
18
+ * This is expected to:
19
+ * - Validate the request found in the handler context and extract auth information from the request.
20
+ * - Map the HTTP request to the user identity and roles defined in app.
21
+ * If this succeeds, return the current authenticated user and a list of roles.
22
+ * If any step fails, throw an error.
23
+ */
24
+ export type DBOSHttpAuthMiddleware = (ctx: MiddlewareContext) => Promise<DBOSHttpAuthReturn | void>;
25
+ export interface DBOSHttpAuthReturn {
26
+ authenticatedUser: string;
27
+ authenticatedRoles: string[];
28
+ }
29
+ export interface MiddlewareDefaults extends RegistrationDefaults {
30
+ koaMiddlewares?: Koa.Middleware[];
31
+ authMiddleware?: DBOSHttpAuthMiddleware;
32
+ }
33
+ export declare class MiddlewareClassRegistration<CT extends {
34
+ new (...args: unknown[]): object;
35
+ }> extends ClassRegistration<CT> implements MiddlewareDefaults {
36
+ authMiddleware?: DBOSHttpAuthMiddleware;
37
+ koaMiddlewares?: Koa.Middleware[];
38
+ constructor(ctor: CT);
39
+ }
40
+ /**
41
+ * Define an authentication function for each endpoint in this class.
42
+ */
43
+ export declare function Authentication(authMiddleware: DBOSHttpAuthMiddleware): <T extends new (...args: unknown[]) => object>(ctor: T) => void;
44
+ /**
45
+ * Define Koa middleware that is applied in order to each endpoint in this class.
46
+ */
47
+ export declare function KoaMiddleware(...koaMiddleware: Koa.Middleware[]): <T extends new (...args: unknown[]) => object>(ctor: T) => void;
48
+ type SecurityScheme = Exclude<OpenApi3.SecuritySchemeObject, OpenApi3.OAuth2SecurityScheme>;
49
+ /**
50
+ * Declare an OpenApi Security Scheme (https://spec.openapis.org/oas/v3.0.3#security-scheme-object
51
+ * for the methods of a class. Note, this decorator is only used in OpenApi generation and does not
52
+ * affect runtime behavior of the app.
53
+ */
54
+ export declare function OpenApiSecurityScheme(securityScheme: SecurityScheme): <T extends new (...args: unknown[]) => object>(_ctor: T) => void;
55
+ export {};
56
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/httpServer/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAgC,MAAM,eAAe,CAAC;AAGtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAEhC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;I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,GAAG,CAAC,UAAU,EAAE,4BAMrB,OAAO,EAAE,KAAG,MAAM,mBAK5D;AAOD,KAAK,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AAE5F;;;;GAIG;AAEH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,cAAc,4BACxB,OAAO,EAAE,KAAG,MAAM,oBAC7D"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenApiSecurityScheme = exports.KoaMiddleware = exports.Authentication = exports.MiddlewareClassRegistration = void 0;
4
+ const decorators_1 = require("../decorators");
5
+ const error_1 = require("../error");
6
+ class MiddlewareClassRegistration extends decorators_1.ClassRegistration {
7
+ authMiddleware;
8
+ koaMiddlewares;
9
+ constructor(ctor) {
10
+ super(ctor);
11
+ }
12
+ }
13
+ exports.MiddlewareClassRegistration = MiddlewareClassRegistration;
14
+ /////////////////////////////////
15
+ /* MIDDLEWARE CLASS DECORATORS */
16
+ /////////////////////////////////
17
+ /**
18
+ * Define an authentication function for each endpoint in this class.
19
+ */
20
+ function Authentication(authMiddleware) {
21
+ if (authMiddleware === undefined) {
22
+ throw new error_1.DBOSUndefinedDecoratorInputError("Authentication");
23
+ }
24
+ function clsdec(ctor) {
25
+ const clsreg = (0, decorators_1.getOrCreateClassRegistration)(ctor);
26
+ clsreg.authMiddleware = authMiddleware;
27
+ }
28
+ return clsdec;
29
+ }
30
+ exports.Authentication = Authentication;
31
+ /**
32
+ * Define Koa middleware that is applied in order to each endpoint in this class.
33
+ */
34
+ function KoaMiddleware(...koaMiddleware) {
35
+ koaMiddleware.forEach((i) => {
36
+ if (i === undefined) {
37
+ throw new error_1.DBOSUndefinedDecoratorInputError("KoaMiddleware");
38
+ }
39
+ });
40
+ function clsdec(ctor) {
41
+ const clsreg = (0, decorators_1.getOrCreateClassRegistration)(ctor);
42
+ clsreg.koaMiddlewares = koaMiddleware;
43
+ }
44
+ return clsdec;
45
+ }
46
+ exports.KoaMiddleware = KoaMiddleware;
47
+ /**
48
+ * Declare an OpenApi Security Scheme (https://spec.openapis.org/oas/v3.0.3#security-scheme-object
49
+ * for the methods of a class. Note, this decorator is only used in OpenApi generation and does not
50
+ * affect runtime behavior of the app.
51
+ */
52
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
+ function OpenApiSecurityScheme(securityScheme) {
54
+ return function (_ctor) { };
55
+ }
56
+ exports.OpenApiSecurityScheme = OpenApiSecurityScheme;
57
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/httpServer/middleware.ts"],"names":[],"mappings":";;;AACA,8CAAsG;AACtG,oCAA4D;AA2C5D,MAAa,2BAA4E,SAAQ,8BAAqB;IACpH,cAAc,CAA0B;IACxC,cAAc,CAAoB;IAElC,YAAY,IAAQ;QAClB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;CACF;AAPD,kEAOC;AAED,iCAAiC;AACjC,iCAAiC;AACjC,iCAAiC;AAEjC;;GAEG;AACH,SAAgB,cAAc,CAAC,cAAsC;IACnE,IAAI,cAAc,KAAK,SAAS,EAAE;QAChC,MAAM,IAAI,wCAAgC,CAAC,gBAAgB,CAAC,CAAC;KAC9D;IACD,SAAS,MAAM,CAAgD,IAAO;QACpE,MAAM,MAAM,GAAG,IAAA,yCAA4B,EAAC,IAAI,CAAmC,CAAC;QACpF,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AATD,wCASC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,GAAG,aAA+B;IAC9D,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,MAAM,IAAI,wCAAgC,CAAC,eAAe,CAAC,CAAC;SAC7D;IACH,CAAC,CAAC,CAAC;IACH,SAAS,MAAM,CAAgD,IAAO;QACpE,MAAM,MAAM,GAAG,IAAA,yCAA4B,EAAC,IAAI,CAAmC,CAAC;QACpF,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,sCAWC;AASD;;;;GAIG;AACH,6DAA6D;AAC7D,SAAgB,qBAAqB,CAAC,cAA8B;IAClE,OAAO,UAAyD,KAAQ,IAAI,CAAC,CAAA;AAC/E,CAAC;AAFD,sDAEC"}
@@ -0,0 +1,40 @@
1
+ /// <reference types="koa__router" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node/http" />
4
+ /// <reference types="@koa/bodyparser/dist/body-parser" />
5
+ import Koa from 'koa';
6
+ import Router from '@koa/router';
7
+ import { DBOSExecutor } from "../dbos-executor";
8
+ import { Logger } from "winston";
9
+ export declare const WorkflowUUIDHeader = "dbos-workflowuuid";
10
+ export declare const WorkflowRecoveryUrl = "/dbos-workflow-recovery";
11
+ export declare class DBOSHttpServer {
12
+ readonly dbosExec: DBOSExecutor;
13
+ readonly app: Koa;
14
+ readonly router: Router;
15
+ readonly logger: Logger;
16
+ /**
17
+ * Create a Koa app.
18
+ * @param dbosExec User pass in an DBOS workflow executor instance.
19
+ * TODO: maybe call wfe.init() somewhere in this class?
20
+ */
21
+ constructor(dbosExec: DBOSExecutor, config?: {
22
+ koa?: Koa;
23
+ router?: Router;
24
+ });
25
+ /**
26
+ * Register HTTP endpoints and attach to the app. Then start the server at the given port.
27
+ * @param port
28
+ */
29
+ listen(port: number): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
30
+ /**
31
+ * Register workflow recovery endpoint.
32
+ * Receives a list of executor IDs and returns a list of workflowUUIDs.
33
+ */
34
+ static registerRecoveryEndpoint(wfe: DBOSExecutor, router: Router): void;
35
+ /**
36
+ * Register decorated functions as HTTP endpoints.
37
+ */
38
+ static registerDecoratedEndpoints(wfe: DBOSExecutor, router: Router): void;
39
+ }
40
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/httpServer/server.ts"],"names":[],"mappings":";;;;AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,MAAM,MAAM,aAAa,CAAC;AAiBjC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKjC,eAAO,MAAM,kBAAkB,sBAAsB,CAAC;AACtD,eAAO,MAAM,mBAAmB,4BAA4B,CAAA;AAE5D,qBAAa,cAAc;IAUb,QAAQ,CAAC,QAAQ,EAAE,YAAY;IAT3C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;OAIG;gBACkB,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAE;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAuBxF;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM;IAOnB;;;OAGG;IACH,MAAM,CAAC,wBAAwB,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAmBjE;;OAEG;IACH,MAAM,CAAC,0BAA0B,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;CAsKpE"}