@dbos-inc/dbos-sdk 0.8.45-preview → 0.8.46-preview
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/packages/dbos-cloud/applications/delete-app.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/applications/delete-app.js +1 -2
- package/dist/packages/dbos-cloud/applications/delete-app.js.map +1 -1
- package/dist/packages/dbos-cloud/applications/deploy-app-code.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/applications/deploy-app-code.js +5 -7
- package/dist/packages/dbos-cloud/applications/deploy-app-code.js.map +1 -1
- package/dist/packages/dbos-cloud/applications/get-app-logs.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/applications/get-app-logs.js +1 -2
- package/dist/packages/dbos-cloud/applications/get-app-logs.js.map +1 -1
- package/dist/packages/dbos-cloud/applications/list-apps.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/applications/list-apps.js +1 -2
- package/dist/packages/dbos-cloud/applications/list-apps.js.map +1 -1
- package/dist/packages/dbos-cloud/applications/register-app.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/applications/register-app.js +1 -2
- package/dist/packages/dbos-cloud/applications/register-app.js.map +1 -1
- package/dist/packages/dbos-cloud/applications/update-app.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/applications/update-app.js +1 -2
- package/dist/packages/dbos-cloud/applications/update-app.js.map +1 -1
- package/dist/packages/dbos-cloud/cloudutils.d.ts +7 -0
- package/dist/packages/dbos-cloud/cloudutils.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/cloudutils.js +44 -3
- package/dist/packages/dbos-cloud/cloudutils.js.map +1 -1
- package/dist/packages/dbos-cloud/login.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/login.js +3 -4
- package/dist/packages/dbos-cloud/login.js.map +1 -1
- package/dist/packages/dbos-cloud/register.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/register.js +1 -2
- package/dist/packages/dbos-cloud/register.js.map +1 -1
- package/dist/packages/dbos-cloud/userdb.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/userdb.js +3 -4
- package/dist/packages/dbos-cloud/userdb.js.map +1 -1
- package/dist/src/context.d.ts +1 -0
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/httpServer/server.d.ts +2 -1
- package/dist/src/httpServer/server.d.ts.map +1 -1
- package/dist/src/testing/testing_runtime.d.ts +2 -1
- package/dist/src/testing/testing_runtime.d.ts.map +1 -1
- package/dist/src/utils.d.ts +0 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -12
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/delete-app.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/delete-app.js +1 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/delete-app.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/deploy-app-code.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/deploy-app-code.js +5 -7
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/deploy-app-code.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/get-app-logs.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/get-app-logs.js +1 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/get-app-logs.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/list-apps.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/list-apps.js +1 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/list-apps.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/register-app.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/register-app.js +1 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/register-app.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/update-app.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/update-app.js +1 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/applications/update-app.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.d.ts +7 -0
- package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.js +44 -3
- package/packages/dbos-cloud/dist/packages/dbos-cloud/cloudutils.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/login.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/login.js +3 -4
- package/packages/dbos-cloud/dist/packages/dbos-cloud/login.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/register.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/register.js +1 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/register.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.js +3 -4
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.js.map +1 -1
- package/packages/dbos-cloud/dist/src/utils.d.ts +0 -1
- package/packages/dbos-cloud/dist/src/utils.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/src/utils.js +3 -12
- package/packages/dbos-cloud/dist/src/utils.js.map +1 -1
- package/packages/dbos-cloud/package.json +1 -1
- package/packages/dbos-openapi/package.json +1 -1
- package/packages/dbos-cloud/dist/schemas/system_db_schema.d.ts +0 -34
- package/packages/dbos-cloud/dist/schemas/system_db_schema.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/schemas/system_db_schema.js +0 -77
- package/packages/dbos-cloud/dist/schemas/system_db_schema.js.map +0 -1
- package/packages/dbos-cloud/dist/schemas/user_db_schema.d.ts +0 -11
- package/packages/dbos-cloud/dist/schemas/user_db_schema.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/schemas/user_db_schema.js +0 -16
- package/packages/dbos-cloud/dist/schemas/user_db_schema.js.map +0 -1
- package/packages/dbos-cloud/dist/src/communicator.d.ts +0 -25
- package/packages/dbos-cloud/dist/src/communicator.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/communicator.js +0 -26
- package/packages/dbos-cloud/dist/src/communicator.js.map +0 -1
- package/packages/dbos-cloud/dist/src/context.d.ts +0 -64
- package/packages/dbos-cloud/dist/src/context.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/context.js +0 -96
- package/packages/dbos-cloud/dist/src/context.js.map +0 -1
- package/packages/dbos-cloud/dist/src/data_validation.d.ts +0 -3
- package/packages/dbos-cloud/dist/src/data_validation.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/data_validation.js +0 -168
- package/packages/dbos-cloud/dist/src/data_validation.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-executor.d.ts +0 -102
- package/packages/dbos-cloud/dist/src/dbos-executor.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-executor.js +0 -631
- package/packages/dbos-cloud/dist/src/dbos-executor.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.d.ts +0 -3
- package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.js +0 -13
- package/packages/dbos-cloud/dist/src/dbos-runtime/applicationVersion.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.d.ts +0 -8
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.js +0 -61
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/config.d.ts +0 -29
- package/packages/dbos-cloud/dist/src/dbos-runtime/config.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/config.js +0 -111
- package/packages/dbos-cloud/dist/src/dbos-runtime/config.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/debug.d.ts +0 -4
- package/packages/dbos-cloud/dist/src/dbos-runtime/debug.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/debug.js +0 -21
- package/packages/dbos-cloud/dist/src/dbos-runtime/debug.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/init.d.ts +0 -7
- package/packages/dbos-cloud/dist/src/dbos-runtime/init.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/init.js +0 -51
- package/packages/dbos-cloud/dist/src/dbos-runtime/init.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.d.ts +0 -3
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.js +0 -175
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.js.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.d.ts +0 -28
- package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.js +0 -95
- package/packages/dbos-cloud/dist/src/dbos-runtime/runtime.js.map +0 -1
- package/packages/dbos-cloud/dist/src/debugger/debug_workflow.d.ts +0 -38
- package/packages/dbos-cloud/dist/src/debugger/debug_workflow.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/debugger/debug_workflow.js +0 -211
- package/packages/dbos-cloud/dist/src/debugger/debug_workflow.js.map +0 -1
- package/packages/dbos-cloud/dist/src/decorators.d.ts +0 -118
- package/packages/dbos-cloud/dist/src/decorators.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/decorators.js +0 -467
- package/packages/dbos-cloud/dist/src/decorators.js.map +0 -1
- package/packages/dbos-cloud/dist/src/error.d.ts +0 -47
- package/packages/dbos-cloud/dist/src/error.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/error.js +0 -171
- package/packages/dbos-cloud/dist/src/error.js.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/handler.d.ts +0 -54
- package/packages/dbos-cloud/dist/src/httpServer/handler.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/handler.js +0 -175
- package/packages/dbos-cloud/dist/src/httpServer/handler.js.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.d.ts +0 -11
- package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.js +0 -19
- package/packages/dbos-cloud/dist/src/httpServer/handlerTypes.js.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/middleware.d.ts +0 -56
- package/packages/dbos-cloud/dist/src/httpServer/middleware.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/middleware.js +0 -57
- package/packages/dbos-cloud/dist/src/httpServer/middleware.js.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/server.d.ts +0 -45
- package/packages/dbos-cloud/dist/src/httpServer/server.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/httpServer/server.js +0 -253
- package/packages/dbos-cloud/dist/src/httpServer/server.js.map +0 -1
- package/packages/dbos-cloud/dist/src/system_database.d.ts +0 -91
- package/packages/dbos-cloud/dist/src/system_database.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/system_database.js +0 -462
- package/packages/dbos-cloud/dist/src/system_database.js.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/collector.d.ts +0 -16
- package/packages/dbos-cloud/dist/src/telemetry/collector.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/collector.js +0 -65
- package/packages/dbos-cloud/dist/src/telemetry/collector.js.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/exporters.d.ts +0 -15
- package/packages/dbos-cloud/dist/src/telemetry/exporters.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/exporters.js +0 -59
- package/packages/dbos-cloud/dist/src/telemetry/exporters.js.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/index.d.ts +0 -11
- package/packages/dbos-cloud/dist/src/telemetry/index.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/index.js +0 -19
- package/packages/dbos-cloud/dist/src/telemetry/index.js.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/logs.d.ts +0 -47
- package/packages/dbos-cloud/dist/src/telemetry/logs.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/logs.js +0 -195
- package/packages/dbos-cloud/dist/src/telemetry/logs.js.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/traces.d.ts +0 -14
- package/packages/dbos-cloud/dist/src/telemetry/traces.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/telemetry/traces.js +0 -52
- package/packages/dbos-cloud/dist/src/telemetry/traces.js.map +0 -1
- package/packages/dbos-cloud/dist/src/transaction.d.ts +0 -29
- package/packages/dbos-cloud/dist/src/transaction.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/transaction.js +0 -27
- package/packages/dbos-cloud/dist/src/transaction.js.map +0 -1
- package/packages/dbos-cloud/dist/src/user_database.d.ts +0 -132
- package/packages/dbos-cloud/dist/src/user_database.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/user_database.js +0 -332
- package/packages/dbos-cloud/dist/src/user_database.js.map +0 -1
- package/packages/dbos-cloud/dist/src/workflow.d.ts +0 -195
- package/packages/dbos-cloud/dist/src/workflow.d.ts.map +0 -1
- package/packages/dbos-cloud/dist/src/workflow.js +0 -498
- 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,SAAyC,EAAE;QAAnE,aAAQ,GAAR,QAAQ,CAAc;QACzC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,CAAC,MAAM,GAAG,IAAI,gBAAM,EAAE,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE9B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAChB,MAAM,CAAC,GAAG,GAAG,IAAI,aAAG,EAAE,CAAC;YAEvB,uCAAuC;YACvC,2FAA2F;YAC3F,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,uBAAU,GAAE,CAAC,CAAC;YAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,G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BACH,CAAC,CAAC;gBAEF,kCAAkC;gBAClC,IAAI,EAAE,CAAC,OAAO,KAAK,uBAAQ,CAAC,GAAG,EAAE,CAAC;oBAChC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;oBACtC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;gBACnE,CAAC;qBAAM,IAAI,EAAE,CAAC,OAAO,KAAK,uBAAQ,CAAC,IAAI,EAAE,CAAC;oBACxC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;oBACvC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;gBACpE,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnQD,wCAmQC"}
|
@@ -1,91 +0,0 @@
|
|
1
|
-
import { DBOSNull } from "./dbos-executor";
|
2
|
-
import { Pool, 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 function migrateSystemDatabase(systemPoolConfig: PoolConfig): Promise<void>;
|
44
|
-
export declare class PostgresSystemDatabase implements SystemDatabase {
|
45
|
-
readonly pgPoolConfig: PoolConfig;
|
46
|
-
readonly systemDatabaseName: string;
|
47
|
-
readonly logger: Logger;
|
48
|
-
readonly pool: Pool;
|
49
|
-
readonly systemPoolConfig: PoolConfig;
|
50
|
-
notificationsClient: PoolClient | null;
|
51
|
-
readonly notificationsMap: Record<string, () => void>;
|
52
|
-
readonly workflowEventsMap: Record<string, () => void>;
|
53
|
-
readonly workflowStatusBuffer: Map<string, WorkflowStatusInternal>;
|
54
|
-
readonly workflowInputsBuffer: Map<string, any[]>;
|
55
|
-
readonly flushBatchSize = 100;
|
56
|
-
constructor(pgPoolConfig: PoolConfig, systemDatabaseName: string, logger: Logger);
|
57
|
-
init(): Promise<void>;
|
58
|
-
destroy(): Promise<void>;
|
59
|
-
checkWorkflowOutput<R>(workflowUUID: string): Promise<DBOSNull | R>;
|
60
|
-
initWorkflowStatus<T extends any[]>(initStatus: WorkflowStatusInternal, args: T): Promise<T>;
|
61
|
-
bufferWorkflowOutput(workflowUUID: string, status: WorkflowStatusInternal): void;
|
62
|
-
/**
|
63
|
-
* Flush the workflow output buffer to the database.
|
64
|
-
*/
|
65
|
-
flushWorkflowStatusBuffer(): Promise<void>;
|
66
|
-
recordWorkflowError(workflowUUID: string, status: WorkflowStatusInternal): Promise<void>;
|
67
|
-
getPendingWorkflows(executorID: string): Promise<Array<string>>;
|
68
|
-
bufferWorkflowInputs<T extends any[]>(workflowUUID: string, args: T): void;
|
69
|
-
flushWorkflowInputsBuffer(): Promise<void>;
|
70
|
-
getWorkflowInputs<T extends any[]>(workflowUUID: string): Promise<T | null>;
|
71
|
-
checkOperationOutput<R>(workflowUUID: string, functionID: number): Promise<DBOSNull | R>;
|
72
|
-
recordOperationOutput<R>(workflowUUID: string, functionID: number, output: R): Promise<void>;
|
73
|
-
recordOperationError(workflowUUID: string, functionID: number, error: Error): Promise<void>;
|
74
|
-
/**
|
75
|
-
* Guard the operation, throwing an error if a conflicting execution is detected.
|
76
|
-
*/
|
77
|
-
recordNotificationOutput<R>(client: PoolClient, workflowUUID: string, functionID: number, output: R): Promise<void>;
|
78
|
-
readonly nullTopic = "__null__topic__";
|
79
|
-
send<T extends NonNullable<any>>(workflowUUID: string, functionID: number, destinationUUID: string, message: T, topic?: string): Promise<void>;
|
80
|
-
recv<T extends NonNullable<any>>(workflowUUID: string, functionID: number, topic?: string, timeoutSeconds?: number): Promise<T | null>;
|
81
|
-
setEvent<T extends NonNullable<any>>(workflowUUID: string, functionID: number, key: string, message: T): Promise<void>;
|
82
|
-
getEvent<T extends NonNullable<any>>(workflowUUID: string, key: string, timeoutSeconds: number, callerUUID?: string, functionID?: number): Promise<T | null>;
|
83
|
-
getWorkflowStatus(workflowUUID: string, callerUUID?: string, functionID?: number): Promise<WorkflowStatus | null>;
|
84
|
-
getWorkflowResult<R>(workflowUUID: string): Promise<R>;
|
85
|
-
/**
|
86
|
-
* A background process that listens for notifications from Postgres then signals the appropriate
|
87
|
-
* workflow listener by resolving its promise.
|
88
|
-
*/
|
89
|
-
listenForNotifications(): Promise<void>;
|
90
|
-
}
|
91
|
-
//# 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;AAI1D,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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