@dbos-inc/dbos-sdk 3.5.44-preview.gc094fdab44 → 3.6.3-preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/schemas/user_db_schema.d.ts +15 -0
- package/dist/schemas/user_db_schema.d.ts.map +1 -0
- package/dist/schemas/user_db_schema.js +33 -0
- package/dist/schemas/user_db_schema.js.map +1 -0
- package/dist/src/client.d.ts +4 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +19 -6
- package/dist/src/client.js.map +1 -1
- package/dist/src/conductor/conductor.js +1 -1
- package/dist/src/conductor/conductor.js.map +1 -1
- package/dist/src/context.d.ts +3 -0
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js.map +1 -1
- package/dist/src/dbos-executor.d.ts +27 -2
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +787 -21
- package/dist/src/dbos-executor.js.map +1 -1
- package/dist/src/{cli → dbos-runtime}/cli.d.ts +1 -1
- package/dist/src/dbos-runtime/cli.d.ts.map +1 -0
- package/dist/src/{cli → dbos-runtime}/cli.js +12 -3
- package/dist/src/dbos-runtime/cli.js.map +1 -0
- package/dist/src/dbos-runtime/commands.d.ts.map +1 -0
- package/dist/src/dbos-runtime/commands.js.map +1 -0
- package/dist/src/{config.d.ts → dbos-runtime/config.d.ts} +6 -2
- package/dist/src/dbos-runtime/config.d.ts.map +1 -0
- package/dist/src/{config.js → dbos-runtime/config.js} +43 -9
- package/dist/src/dbos-runtime/config.js.map +1 -0
- package/dist/src/dbos-runtime/docker_pg_helper.d.ts.map +1 -0
- package/dist/src/dbos-runtime/docker_pg_helper.js.map +1 -0
- package/dist/src/dbos-runtime/migrate.d.ts +3 -0
- package/dist/src/dbos-runtime/migrate.d.ts.map +1 -0
- package/dist/src/{cli → dbos-runtime}/migrate.js +29 -1
- package/dist/src/dbos-runtime/migrate.js.map +1 -0
- package/dist/src/{workflow_management.d.ts → dbos-runtime/workflow_management.d.ts} +6 -4
- package/dist/src/dbos-runtime/workflow_management.d.ts.map +1 -0
- package/dist/src/{workflow_management.js → dbos-runtime/workflow_management.js} +26 -5
- package/dist/src/dbos-runtime/workflow_management.js.map +1 -0
- package/dist/src/dbos.d.ts +196 -2
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +407 -11
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/decorators.d.ts +38 -4
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +164 -9
- package/dist/src/decorators.js.map +1 -1
- package/dist/src/error.d.ts +8 -0
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +14 -1
- package/dist/src/error.js.map +1 -1
- package/dist/src/httpServer/handler.d.ts +13 -0
- package/dist/src/httpServer/handler.d.ts.map +1 -0
- package/dist/src/httpServer/handler.js +25 -0
- package/dist/src/httpServer/handler.js.map +1 -0
- package/dist/src/httpServer/handlerTypes.d.ts +14 -0
- package/dist/src/httpServer/handlerTypes.d.ts.map +1 -0
- package/dist/src/httpServer/handlerTypes.js +22 -0
- package/dist/src/httpServer/handlerTypes.js.map +1 -0
- package/dist/src/httpServer/middleware.d.ts +74 -0
- package/dist/src/httpServer/middleware.d.ts.map +1 -0
- package/dist/src/httpServer/middleware.js +108 -0
- package/dist/src/httpServer/middleware.js.map +1 -0
- package/dist/src/{adminserver.d.ts → httpServer/server.d.ts} +15 -6
- package/dist/src/httpServer/server.d.ts.map +1 -0
- package/dist/src/{adminserver.js → httpServer/server.js} +311 -28
- package/dist/src/httpServer/server.js.map +1 -0
- package/dist/src/index.d.ts +12 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +40 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/paramdecorators.d.ts +39 -0
- package/dist/src/paramdecorators.d.ts.map +1 -0
- package/dist/src/paramdecorators.js +365 -0
- package/dist/src/paramdecorators.js.map +1 -0
- package/dist/src/procedure.d.ts +18 -0
- package/dist/src/procedure.d.ts.map +1 -0
- package/dist/src/procedure.js +3 -0
- package/dist/src/procedure.js.map +1 -0
- package/dist/src/transaction.d.ts +19 -0
- package/dist/src/transaction.d.ts.map +1 -0
- package/dist/src/transaction.js +11 -0
- package/dist/src/transaction.js.map +1 -0
- package/dist/src/user_database.d.ts +176 -0
- package/dist/src/user_database.d.ts.map +1 -0
- package/dist/src/user_database.js +540 -0
- package/dist/src/user_database.js.map +1 -0
- package/dist/src/utils.d.ts +22 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +172 -20
- package/dist/src/utils.js.map +1 -1
- package/dist/src/wfqueue.d.ts +2 -0
- package/dist/src/wfqueue.d.ts.map +1 -1
- package/dist/src/wfqueue.js +1 -1
- package/dist/src/wfqueue.js.map +1 -1
- package/dist/src/workflow.d.ts +8 -0
- package/dist/src/workflow.d.ts.map +1 -1
- package/dist/src/workflow.js +11 -0
- package/dist/src/workflow.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -4
- package/dist/src/adminserver.d.ts.map +0 -1
- package/dist/src/adminserver.js.map +0 -1
- package/dist/src/cli/cli.d.ts.map +0 -1
- package/dist/src/cli/cli.js.map +0 -1
- package/dist/src/cli/commands.d.ts.map +0 -1
- package/dist/src/cli/commands.js.map +0 -1
- package/dist/src/cli/docker_pg_helper.d.ts.map +0 -1
- package/dist/src/cli/docker_pg_helper.js.map +0 -1
- package/dist/src/cli/migrate.d.ts +0 -3
- package/dist/src/cli/migrate.d.ts.map +0 -1
- package/dist/src/cli/migrate.js.map +0 -1
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js.map +0 -1
- package/dist/src/workflow_management.d.ts.map +0 -1
- package/dist/src/workflow_management.js.map +0 -1
- /package/dist/src/{cli → dbos-runtime}/commands.d.ts +0 -0
- /package/dist/src/{cli → dbos-runtime}/commands.js +0 -0
- /package/dist/src/{cli → dbos-runtime}/docker_pg_helper.d.ts +0 -0
- /package/dist/src/{cli → dbos-runtime}/docker_pg_helper.js +0 -0
package/dist/src/dbos.js
CHANGED
@@ -3,25 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.DBOS = exports.runInternalStep = exports.getExecutor = void 0;
|
6
|
+
exports.InitContext = exports.DBOS = exports.runInternalStep = exports.getExecutor = void 0;
|
7
7
|
const context_1 = require("./context");
|
8
8
|
const dbos_executor_1 = require("./dbos-executor");
|
9
9
|
const traces_1 = require("./telemetry/traces");
|
10
10
|
const workflow_1 = require("./workflow");
|
11
11
|
const logs_1 = require("./telemetry/logs");
|
12
12
|
const error_1 = require("./error");
|
13
|
-
const config_1 = require("./config");
|
13
|
+
const config_1 = require("./dbos-runtime/config");
|
14
14
|
const scheduler_1 = require("./scheduler/scheduler");
|
15
15
|
const decorators_1 = require("./decorators");
|
16
16
|
const utils_1 = require("./utils");
|
17
|
-
const
|
17
|
+
const server_1 = require("./httpServer/server");
|
18
|
+
const user_database_1 = require("./user_database");
|
18
19
|
const node_crypto_1 = require("node:crypto");
|
20
|
+
const _1 = require(".");
|
21
|
+
const _2 = require(".");
|
22
|
+
const handlerTypes_1 = require("./httpServer/handlerTypes");
|
19
23
|
const conductor_1 = require("./conductor/conductor");
|
20
24
|
const system_database_1 = require("./system_database");
|
21
25
|
const wfqueue_1 = require("./wfqueue");
|
22
26
|
const authdecorators_1 = require("./authdecorators");
|
23
27
|
const node_assert_1 = __importDefault(require("node:assert"));
|
24
28
|
const api_1 = require("@opentelemetry/api");
|
29
|
+
function httpApiDec(verb, url) {
|
30
|
+
return function apidec(target, propertyKey, inDescriptor) {
|
31
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterDec)(target, propertyKey, inDescriptor);
|
32
|
+
const handlerRegistration = registration;
|
33
|
+
handlerRegistration.apiURL = url;
|
34
|
+
handlerRegistration.apiType = verb;
|
35
|
+
(0, _1.requestArgValidation)(registration);
|
36
|
+
return descriptor;
|
37
|
+
};
|
38
|
+
}
|
25
39
|
function getExecutor() {
|
26
40
|
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
27
41
|
throw new error_1.DBOSExecutorNotInitializedError();
|
@@ -50,6 +64,7 @@ class DBOS {
|
|
50
64
|
// Lifecycle
|
51
65
|
///////
|
52
66
|
static adminServer = undefined;
|
67
|
+
static appServer = undefined;
|
53
68
|
static conductor = undefined;
|
54
69
|
/**
|
55
70
|
* Set configuration of `DBOS` prior to `launch`
|
@@ -59,6 +74,26 @@ class DBOS {
|
|
59
74
|
(0, node_assert_1.default)(!DBOS.isInitialized(), 'Cannot call DBOS.setConfig after DBOS.launch');
|
60
75
|
DBOS.#dbosConfig = config;
|
61
76
|
}
|
77
|
+
/**
|
78
|
+
* Use ORMEntities to set up database schema.
|
79
|
+
* Only relevant for TypeORM, and for testing purposes only, not production
|
80
|
+
* @deprecated - use data source packages such as `@dbos-inc/typeorm-datasource`
|
81
|
+
*/
|
82
|
+
static async createUserSchema() {
|
83
|
+
return dbos_executor_1.DBOSExecutor.globalInstance?.createUserSchema();
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* Use ORMEntities to drop database schema.
|
87
|
+
* Only relevant for TypeORM, and for testing purposes only, not production
|
88
|
+
* @deprecated - use data source packages such as `@dbos-inc/typeorm-datasource`
|
89
|
+
*/
|
90
|
+
static async dropUserSchema() {
|
91
|
+
return dbos_executor_1.DBOSExecutor.globalInstance?.dropUserSchema();
|
92
|
+
}
|
93
|
+
// Load files with DBOS classes (running their decorators)
|
94
|
+
static async loadClasses(dbosEntrypointFiles) {
|
95
|
+
return await dbos_executor_1.DBOSExecutor.loadClasses(dbosEntrypointFiles);
|
96
|
+
}
|
62
97
|
/**
|
63
98
|
* Check if DBOS has been `launch`ed (and not `shutdown`)
|
64
99
|
* @returns `true` if DBOS has been launched, or `false` otherwise
|
@@ -99,6 +134,7 @@ class DBOS {
|
|
99
134
|
[internalConfig, runtimeConfig] = (0, config_1.overwriteConfigForDBOSCloud)(internalConfig, runtimeConfig, configFile);
|
100
135
|
}
|
101
136
|
DBOS.#port = runtimeConfig.port;
|
137
|
+
DBOS.#userDbClient = internalConfig.userDbClient;
|
102
138
|
dbos_executor_1.DBOSExecutor.createDebouncerWorkflow();
|
103
139
|
dbos_executor_1.DBOSExecutor.createInternalQueue();
|
104
140
|
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(internalConfig, { debugMode });
|
@@ -130,9 +166,9 @@ class DBOS {
|
|
130
166
|
// Start the DBOS admin server
|
131
167
|
const logger = DBOS.logger;
|
132
168
|
if (runtimeConfig.runAdminServer) {
|
133
|
-
const adminApp =
|
169
|
+
const adminApp = server_1.DBOSHttpServer.setupAdminApp(executor);
|
134
170
|
try {
|
135
|
-
await
|
171
|
+
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(runtimeConfig.admin_port, logger);
|
136
172
|
// Wrap the listen call in a promise to properly catch errors
|
137
173
|
DBOS.adminServer = await new Promise((resolve, reject) => {
|
138
174
|
const server = adminApp.listen(runtimeConfig?.admin_port, () => {
|
@@ -159,6 +195,7 @@ class DBOS {
|
|
159
195
|
static logRegisteredEndpoints() {
|
160
196
|
if (!dbos_executor_1.DBOSExecutor.globalInstance)
|
161
197
|
return;
|
198
|
+
dbos_executor_1.DBOSExecutor.globalInstance.logRegisteredHTTPUrls();
|
162
199
|
wfqueue_1.wfQueueRunner.logRegisteredEndpoints(dbos_executor_1.DBOSExecutor.globalInstance);
|
163
200
|
for (const lcl of (0, decorators_1.getLifecycleListeners)()) {
|
164
201
|
lcl.logRegisteredEndpoints?.();
|
@@ -171,6 +208,11 @@ class DBOS {
|
|
171
208
|
* Stops workflow processing and disconnects from databases
|
172
209
|
*/
|
173
210
|
static async shutdown() {
|
211
|
+
// Stop the app server
|
212
|
+
if (DBOS.appServer) {
|
213
|
+
DBOS.appServer.close();
|
214
|
+
DBOS.appServer = undefined;
|
215
|
+
}
|
174
216
|
// Stop the admin server
|
175
217
|
if (DBOS.adminServer) {
|
176
218
|
DBOS.adminServer.close();
|
@@ -212,18 +254,60 @@ class DBOS {
|
|
212
254
|
static get #executor() {
|
213
255
|
return getExecutor();
|
214
256
|
}
|
257
|
+
/**
|
258
|
+
* Creates a node.js HTTP handler for all entrypoints registered with `@DBOS.getApi`
|
259
|
+
* and other decorators. The handler can be retrieved with `DBOS.getHTTPHandlersCallback()`.
|
260
|
+
* This method does not start listening for requests. For that, call `DBOS.launchAppHTTPServer()`.
|
261
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
262
|
+
*/
|
263
|
+
static setUpHandlerCallback() {
|
264
|
+
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
265
|
+
throw new error_1.DBOSExecutorNotInitializedError();
|
266
|
+
}
|
267
|
+
// Create the DBOS HTTP server
|
268
|
+
// This may be a no-op if there are no registered endpoints
|
269
|
+
const server = new server_1.DBOSHttpServer(dbos_executor_1.DBOSExecutor.globalInstance);
|
270
|
+
return server;
|
271
|
+
}
|
272
|
+
/**
|
273
|
+
* Creates a node.js HTTP handler for all entrypoints registered with `@DBOS.getApi`
|
274
|
+
* and other decorators. This method also starts listening for requests, on the port
|
275
|
+
* specified in the `DBOSRuntimeConfig`.
|
276
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
277
|
+
*/
|
278
|
+
static async launchAppHTTPServer() {
|
279
|
+
const server = DBOS.setUpHandlerCallback();
|
280
|
+
if (DBOS.#port) {
|
281
|
+
// This will not listen if there's no decorated endpoint
|
282
|
+
DBOS.appServer = await server.appListen(DBOS.#port);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
/**
|
286
|
+
* Retrieves the HTTP handlers callback for DBOS HTTP.
|
287
|
+
* (This is the one that handles the @DBOS.getApi, etc., methods.)
|
288
|
+
* Useful for testing purposes, or to combine the DBOS service with other
|
289
|
+
* node.js HTTP server frameworks.
|
290
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
291
|
+
*/
|
292
|
+
static getHTTPHandlersCallback() {
|
293
|
+
if (!server_1.DBOSHttpServer.instance) {
|
294
|
+
return undefined;
|
295
|
+
}
|
296
|
+
return server_1.DBOSHttpServer.instance.app.callback();
|
297
|
+
}
|
215
298
|
/** For unit testing of admin server (do not call) */
|
216
299
|
static getAdminCallback() {
|
217
|
-
if (!
|
300
|
+
if (!server_1.DBOSHttpServer.instance) {
|
218
301
|
return undefined;
|
219
302
|
}
|
220
|
-
return
|
303
|
+
return server_1.DBOSHttpServer.instance.adminApp.callback();
|
221
304
|
}
|
222
305
|
//////
|
223
306
|
// Globals
|
224
307
|
//////
|
225
308
|
static #dbosConfig;
|
226
309
|
static #port;
|
310
|
+
static #userDbClient;
|
227
311
|
//////
|
228
312
|
// Context
|
229
313
|
//////
|
@@ -266,6 +350,27 @@ class DBOS {
|
|
266
350
|
throw new error_1.DBOSError('`DBOS.request` accessed from outside of HTTP requests');
|
267
351
|
return r;
|
268
352
|
}
|
353
|
+
/**
|
354
|
+
* Get the current Koa context (within `@DBOS.getApi` et al)
|
355
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
356
|
+
*/
|
357
|
+
static getKoaContext() {
|
358
|
+
return (0, context_1.getCurrentContextStore)()?.koaContext;
|
359
|
+
}
|
360
|
+
/**
|
361
|
+
* Get the current Koa context (within `@DBOS.getApi` et al)
|
362
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
363
|
+
*/
|
364
|
+
static get koaContext() {
|
365
|
+
const r = DBOS.getKoaContext();
|
366
|
+
if (!r)
|
367
|
+
throw new error_1.DBOSError('`DBOS.koaContext` accessed from outside koa request');
|
368
|
+
return r;
|
369
|
+
}
|
370
|
+
/** Get the current application version */
|
371
|
+
static get applicationVersion() {
|
372
|
+
return utils_1.globalParams.appVersion;
|
373
|
+
}
|
269
374
|
/** Get the current workflow ID */
|
270
375
|
static get workflowID() {
|
271
376
|
return (0, context_1.getCurrentContextStore)()?.workflowId;
|
@@ -301,6 +406,10 @@ class DBOS {
|
|
301
406
|
static isInTransaction() {
|
302
407
|
return (0, context_1.getCurrentContextStore)()?.curTxFunctionId !== undefined;
|
303
408
|
}
|
409
|
+
/** @returns true if called from within a stored procedure, false otherwise */
|
410
|
+
static isInStoredProc() {
|
411
|
+
return (0, context_1.getCurrentContextStore)()?.isInStoredProc ?? false;
|
412
|
+
}
|
304
413
|
/** @returns true if called from within a step, false otherwise */
|
305
414
|
static isInStep() {
|
306
415
|
return (0, context_1.getCurrentContextStore)()?.curStepFunctionId !== undefined;
|
@@ -318,7 +427,111 @@ class DBOS {
|
|
318
427
|
* a step, transaction, or procedure, or false otherwise
|
319
428
|
*/
|
320
429
|
static isInWorkflow() {
|
321
|
-
return DBOS.isWithinWorkflow() && !DBOS.isInTransaction() && !DBOS.isInStep();
|
430
|
+
return DBOS.isWithinWorkflow() && !DBOS.isInTransaction() && !DBOS.isInStep() && !DBOS.isInStoredProc();
|
431
|
+
}
|
432
|
+
// sql session (various forms)
|
433
|
+
/**
|
434
|
+
* @returns the current SQL client; only allowed within `@DBOS.transaction` functions
|
435
|
+
* @deprecated - use data source packages such as:
|
436
|
+
* `@dbos-inc/drizzle-datasource`
|
437
|
+
* `@dbos-inc/knex-datasource`
|
438
|
+
* `@dbos-inc/node-pg-datasource`
|
439
|
+
* `@dbos-inc/postgres-datasource`
|
440
|
+
* `@dbos-inc/prisma-datasource`
|
441
|
+
* `@dbos-inc/typeorm-datasource`
|
442
|
+
*/
|
443
|
+
static get sqlClient() {
|
444
|
+
const c = (0, context_1.getCurrentContextStore)()?.sqlClient;
|
445
|
+
if (!DBOS.isInTransaction() || !c)
|
446
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid use of `DBOS.sqlClient` outside of a `transaction`');
|
447
|
+
return c;
|
448
|
+
}
|
449
|
+
/**
|
450
|
+
* @returns the current PG SQL client;
|
451
|
+
* only allowed within `@DBOS.transaction` functions when a `PGNODE` user database is in use
|
452
|
+
* @deprecated - use data source packages such as `@dbos-inc/node-pg-datasource`
|
453
|
+
*/
|
454
|
+
static get pgClient() {
|
455
|
+
if (!DBOS.isInStoredProc() && DBOS.#userDbClient !== user_database_1.UserDatabaseName.PGNODE) {
|
456
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.pgClient' but client is configured with type '${DBOS.#userDbClient}'`);
|
457
|
+
}
|
458
|
+
return DBOS.sqlClient;
|
459
|
+
}
|
460
|
+
/**
|
461
|
+
* @returns the current Knex SQL client;
|
462
|
+
* only allowed within `@DBOS.transaction` functions when a `KNEX` user database is in use
|
463
|
+
* @deprecated - use `@dbos-inc/knex-datasource` package
|
464
|
+
*/
|
465
|
+
static get knexClient() {
|
466
|
+
if (DBOS.isInStoredProc()) {
|
467
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' from within a stored procedure`);
|
468
|
+
}
|
469
|
+
if (DBOS.#userDbClient !== user_database_1.UserDatabaseName.KNEX) {
|
470
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' but client is configured with type '${DBOS.#userDbClient}'`);
|
471
|
+
}
|
472
|
+
return DBOS.sqlClient;
|
473
|
+
}
|
474
|
+
/**
|
475
|
+
* @returns the current Prisma SQL client;
|
476
|
+
* only allowed within `@DBOS.transaction` functions when a `PRISMA` user database is in use
|
477
|
+
* @deprecated - use `@dbos-inc/prisma-datasource` package
|
478
|
+
*/
|
479
|
+
static get prismaClient() {
|
480
|
+
if (DBOS.isInStoredProc()) {
|
481
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' from within a stored procedure`);
|
482
|
+
}
|
483
|
+
if (DBOS.#userDbClient !== user_database_1.UserDatabaseName.PRISMA) {
|
484
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' but client is configured with type '${DBOS.#userDbClient}'`);
|
485
|
+
}
|
486
|
+
return DBOS.sqlClient;
|
487
|
+
}
|
488
|
+
/**
|
489
|
+
* @returns the current TypeORM SQL client;
|
490
|
+
* only allowed within `@DBOS.transaction` functions when the `TYPEORM` user database is in use
|
491
|
+
* @deprecated - use `@dbos-inc/typeorm-datasource` package
|
492
|
+
*/
|
493
|
+
static get typeORMClient() {
|
494
|
+
if (DBOS.isInStoredProc()) {
|
495
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' from within a stored procedure`);
|
496
|
+
}
|
497
|
+
if (DBOS.#userDbClient !== user_database_1.UserDatabaseName.TYPEORM) {
|
498
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' but client is configured with type '${DBOS.#userDbClient}'`);
|
499
|
+
}
|
500
|
+
return DBOS.sqlClient;
|
501
|
+
}
|
502
|
+
/**
|
503
|
+
* @returns the current Drizzle SQL client;
|
504
|
+
* only allowed within `@DBOS.transaction` functions when the `DRIZZLE` user database is in use
|
505
|
+
* @deprecated - use `@dbos-inc/drizzle-datasource` package
|
506
|
+
*/
|
507
|
+
static get drizzleClient() {
|
508
|
+
if (DBOS.isInStoredProc()) {
|
509
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' from within a stored procedure`);
|
510
|
+
}
|
511
|
+
if (DBOS.#userDbClient !== user_database_1.UserDatabaseName.DRIZZLE) {
|
512
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' but client is configured with type '${DBOS.#userDbClient}'`);
|
513
|
+
}
|
514
|
+
return DBOS.sqlClient;
|
515
|
+
}
|
516
|
+
/**
|
517
|
+
* Query the current application database
|
518
|
+
* @param sql - parameterized SQL statement (string) to execute
|
519
|
+
* @param params - parameter values for `sql`
|
520
|
+
* @template T - Type for the returned records
|
521
|
+
* @returns Array of records returned by the SQL statement
|
522
|
+
* @deprecated - use data source packages such as:
|
523
|
+
* `@dbos-inc/drizzle-datasource`
|
524
|
+
* `@dbos-inc/knex-datasource`
|
525
|
+
* `@dbos-inc/node-pg-datasource`
|
526
|
+
* `@dbos-inc/postgres-datasource`
|
527
|
+
* `@dbos-inc/prisma-datasource`
|
528
|
+
* `@dbos-inc/typeorm-datasource`
|
529
|
+
*/
|
530
|
+
static async queryUserDB(sql, params) {
|
531
|
+
if (DBOS.isWithinWorkflow() && !DBOS.isInStep()) {
|
532
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `queryUserDB` inside a `workflow`, without being in a `step`');
|
533
|
+
}
|
534
|
+
return DBOS.#executor.queryUserDB(sql, params);
|
322
535
|
}
|
323
536
|
//////
|
324
537
|
// Access to system DB, for event receivers etc.
|
@@ -421,6 +634,19 @@ class DBOS {
|
|
421
634
|
}
|
422
635
|
return DBOS.#executor.retrieveWorkflow(workflowID);
|
423
636
|
}
|
637
|
+
/**
|
638
|
+
* Query the system database for all workflows matching the provided predicate
|
639
|
+
* @param input - `GetWorkflowsInput` predicate for filtering returned workflows
|
640
|
+
* @returns `GetWorkflowsOutput` listing the workflow IDs of matching workflows
|
641
|
+
* @deprecated Use `DBOS.listWorkflows` instead
|
642
|
+
*/
|
643
|
+
static async getWorkflows(input) {
|
644
|
+
(0, decorators_1.ensureDBOSIsLaunched)('getWorkflows');
|
645
|
+
return await runInternalStep(async () => {
|
646
|
+
const wfs = await DBOS.#executor.listWorkflows(input);
|
647
|
+
return { workflowUUIDs: wfs.map((wf) => wf.workflowID) };
|
648
|
+
}, 'DBOS.getWorkflows');
|
649
|
+
}
|
424
650
|
/**
|
425
651
|
* Query the system database for all workflows matching the provided predicate
|
426
652
|
* @param input - `GetWorkflowsInput` predicate for filtering returned workflows
|
@@ -610,6 +836,17 @@ class DBOS {
|
|
610
836
|
(0, decorators_1.ensureDBOSIsLaunched)('tracing');
|
611
837
|
return DBOS.#withTopContext({ operationCaller: callerName }, callback);
|
612
838
|
}
|
839
|
+
/**
|
840
|
+
* @deprecated
|
841
|
+
* Use queue named `queueName` for any workflows started within the `callback`.
|
842
|
+
* @param queueName - Name of queue upon which all workflows called or started within `callback` will be run
|
843
|
+
* @param callback - Function to run, which would call or start workflows
|
844
|
+
* @returns - Return value from `callback`
|
845
|
+
*/
|
846
|
+
static async withWorkflowQueue(queueName, callback) {
|
847
|
+
(0, decorators_1.ensureDBOSIsLaunched)('workflows');
|
848
|
+
return DBOS.#withTopContext({ queueAssignedForWorkflows: queueName }, callback);
|
849
|
+
}
|
613
850
|
/**
|
614
851
|
* Specify workflow timeout for any workflows started within the `callback`.
|
615
852
|
* @param timeoutMS - timeout length for all workflows started within `callback` will be run
|
@@ -665,7 +902,7 @@ class DBOS {
|
|
665
902
|
static startWorkflow(target, params) {
|
666
903
|
(0, decorators_1.ensureDBOSIsLaunched)('workflows');
|
667
904
|
const instance = typeof target === 'function' ? null : target;
|
668
|
-
if (instance && typeof instance !== 'function' && !(instance instanceof
|
905
|
+
if (instance && typeof instance !== 'function' && !(instance instanceof _2.ConfiguredInstance)) {
|
669
906
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `startWorkflow` on an object that is not a `ConfiguredInstance`');
|
670
907
|
}
|
671
908
|
const regOps = (0, decorators_1.getRegisteredOperations)(target);
|
@@ -931,7 +1168,7 @@ class DBOS {
|
|
931
1168
|
const queueName = params.queueName ?? ppctx?.queueAssignedForWorkflows;
|
932
1169
|
const timeoutMS = params.timeoutMS ?? ppctx?.workflowTimeoutMS;
|
933
1170
|
const instance = $this === undefined || typeof $this === 'function' ? undefined : $this;
|
934
|
-
if (instance && !(instance instanceof
|
1171
|
+
if (instance && !(instance instanceof _2.ConfiguredInstance)) {
|
935
1172
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call a `workflow` function on an object that is not a `ConfiguredInstance`');
|
936
1173
|
}
|
937
1174
|
// If this is called from within a workflow, this is a child workflow,
|
@@ -969,6 +1206,10 @@ class DBOS {
|
|
969
1206
|
const func = regOP.registeredFunction;
|
970
1207
|
return dbos_executor_1.DBOSExecutor.globalInstance.internalWorkflow(func, wfParams, workflowID, funcNum, ...args);
|
971
1208
|
}
|
1209
|
+
if (regOP.txnConfig) {
|
1210
|
+
const func = regOP.registeredFunction;
|
1211
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.startTransactionTempWF(func, wfParams, workflowID, funcNum, ...args);
|
1212
|
+
}
|
972
1213
|
if (regOP.stepConfig) {
|
973
1214
|
const func = regOP.registeredFunction;
|
974
1215
|
return dbos_executor_1.DBOSExecutor.globalInstance.startStepTempWF(func, wfParams, workflowID, funcNum, ...args);
|
@@ -995,6 +1236,95 @@ class DBOS {
|
|
995
1236
|
});
|
996
1237
|
return invoker;
|
997
1238
|
}
|
1239
|
+
/**
|
1240
|
+
* Decorator designating a method as a DBOS transaction, making SQL clients available.
|
1241
|
+
* A durable execution checkpoint will be applied to to the underlying database transaction
|
1242
|
+
* @see `DBOS.sqlClient`
|
1243
|
+
* @param config - Configuration information for the transaction, particularly its isolation mode
|
1244
|
+
* @deprecated - use data source packages such as:
|
1245
|
+
* `@dbos-inc/drizzle-datasource`
|
1246
|
+
* `@dbos-inc/knex-datasource`
|
1247
|
+
* `@dbos-inc/node-pg-datasource`
|
1248
|
+
* `@dbos-inc/postgres-datasource`
|
1249
|
+
* `@dbos-inc/prisma-datasource`
|
1250
|
+
* `@dbos-inc/typeorm-datasource`
|
1251
|
+
*/
|
1252
|
+
static transaction(config = {}) {
|
1253
|
+
function decorator(target, propertyKey, inDescriptor) {
|
1254
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1255
|
+
registration.setTxnConfig(config);
|
1256
|
+
const invokeWrapper = async function (...rawArgs) {
|
1257
|
+
(0, decorators_1.ensureDBOSIsLaunched)('transactions');
|
1258
|
+
let inst = undefined;
|
1259
|
+
if (this === undefined || typeof this === 'function') {
|
1260
|
+
// This is static
|
1261
|
+
}
|
1262
|
+
else {
|
1263
|
+
inst = this;
|
1264
|
+
if (!(inst instanceof _2.ConfiguredInstance)) {
|
1265
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call a `transaction` function on an object that is not a `ConfiguredInstance`');
|
1266
|
+
}
|
1267
|
+
}
|
1268
|
+
if (DBOS.isWithinWorkflow()) {
|
1269
|
+
if (DBOS.isInTransaction()) {
|
1270
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `transaction` function from within a `transaction`');
|
1271
|
+
}
|
1272
|
+
if (DBOS.isInStep()) {
|
1273
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `transaction` function from within a `step`');
|
1274
|
+
}
|
1275
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, ...rawArgs);
|
1276
|
+
}
|
1277
|
+
const wfId = (0, context_1.getNextWFID)(undefined);
|
1278
|
+
const wfParams = {
|
1279
|
+
configuredInstance: inst,
|
1280
|
+
workflowUUID: wfId,
|
1281
|
+
};
|
1282
|
+
return await DBOS.#executor.runTransactionTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1283
|
+
};
|
1284
|
+
descriptor.value = invokeWrapper;
|
1285
|
+
registration.wrappedFunction = invokeWrapper;
|
1286
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1287
|
+
Object.defineProperty(invokeWrapper, 'name', {
|
1288
|
+
value: registration.name,
|
1289
|
+
});
|
1290
|
+
return descriptor;
|
1291
|
+
}
|
1292
|
+
return decorator;
|
1293
|
+
}
|
1294
|
+
/**
|
1295
|
+
* Decorator designating a method as a DBOS stored procedure.
|
1296
|
+
* Within the procedure, `DBOS.sqlClient` is available for database operations.
|
1297
|
+
* A durable execution checkpoint will be applied to to the underlying database transaction
|
1298
|
+
* @param config - Configuration information for the stored procedure, particularly its execution mode
|
1299
|
+
*/
|
1300
|
+
static storedProcedure(config = {}) {
|
1301
|
+
function decorator(target, propertyKey, inDescriptor) {
|
1302
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1303
|
+
registration.setProcConfig(config);
|
1304
|
+
const invokeWrapper = async function (...rawArgs) {
|
1305
|
+
(0, decorators_1.ensureDBOSIsLaunched)('stored procedures');
|
1306
|
+
if (typeof this !== 'function') {
|
1307
|
+
throw new Error('Stored procedures must be static');
|
1308
|
+
}
|
1309
|
+
if (DBOS.isWithinWorkflow()) {
|
1310
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, ...rawArgs);
|
1311
|
+
}
|
1312
|
+
const wfId = (0, context_1.getNextWFID)(undefined);
|
1313
|
+
const wfParams = {
|
1314
|
+
workflowUUID: wfId,
|
1315
|
+
};
|
1316
|
+
return await DBOS.#executor.runProcedureTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1317
|
+
};
|
1318
|
+
descriptor.value = invokeWrapper;
|
1319
|
+
registration.wrappedFunction = invokeWrapper;
|
1320
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1321
|
+
Object.defineProperty(invokeWrapper, 'name', {
|
1322
|
+
value: registration.name,
|
1323
|
+
});
|
1324
|
+
return descriptor;
|
1325
|
+
}
|
1326
|
+
return decorator;
|
1327
|
+
}
|
998
1328
|
/**
|
999
1329
|
* Decorator designating a method as a DBOS step.
|
1000
1330
|
* A durable checkpoint will be made after the step completes
|
@@ -1015,7 +1345,7 @@ class DBOS {
|
|
1015
1345
|
}
|
1016
1346
|
else {
|
1017
1347
|
inst = this;
|
1018
|
-
if (!(inst instanceof
|
1348
|
+
if (!(inst instanceof _2.ConfiguredInstance)) {
|
1019
1349
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call a `step` function on an object that is not a `ConfiguredInstance`');
|
1020
1350
|
}
|
1021
1351
|
}
|
@@ -1107,6 +1437,51 @@ class DBOS {
|
|
1107
1437
|
}
|
1108
1438
|
return func();
|
1109
1439
|
}
|
1440
|
+
/**
|
1441
|
+
* Register serialization recipe; this is used to save/retrieve objects from the DBOS system
|
1442
|
+
* database. This includes workflow inputs, function return values, messages, and events.
|
1443
|
+
*/
|
1444
|
+
static registerSerialization(serReg) {
|
1445
|
+
if (DBOS.isInitialized()) {
|
1446
|
+
throw new TypeError(`Serializers/deserializers should not be registered after DBOS.launch()`);
|
1447
|
+
}
|
1448
|
+
(0, utils_1.registerSerializationRecipe)(serReg);
|
1449
|
+
}
|
1450
|
+
/**
|
1451
|
+
* Decorator indicating that the method is the target of HTTP GET operations for `url`
|
1452
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1453
|
+
*/
|
1454
|
+
static getApi(url) {
|
1455
|
+
return httpApiDec(handlerTypes_1.APITypes.GET, url);
|
1456
|
+
}
|
1457
|
+
/**
|
1458
|
+
* Decorator indicating that the method is the target of HTTP POST operations for `url`
|
1459
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1460
|
+
*/
|
1461
|
+
static postApi(url) {
|
1462
|
+
return httpApiDec(handlerTypes_1.APITypes.POST, url);
|
1463
|
+
}
|
1464
|
+
/**
|
1465
|
+
* Decorator indicating that the method is the target of HTTP PUT operations for `url`
|
1466
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1467
|
+
*/
|
1468
|
+
static putApi(url) {
|
1469
|
+
return httpApiDec(handlerTypes_1.APITypes.PUT, url);
|
1470
|
+
}
|
1471
|
+
/**
|
1472
|
+
* Decorator indicating that the method is the target of HTTP PATCH operations for `url`
|
1473
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1474
|
+
*/
|
1475
|
+
static patchApi(url) {
|
1476
|
+
return httpApiDec(handlerTypes_1.APITypes.PATCH, url);
|
1477
|
+
}
|
1478
|
+
/**
|
1479
|
+
* Decorator indicating that the method is the target of HTTP DELETE operations for `url`
|
1480
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1481
|
+
*/
|
1482
|
+
static deleteApi(url) {
|
1483
|
+
return httpApiDec(handlerTypes_1.APITypes.DELETE, url);
|
1484
|
+
}
|
1110
1485
|
/**
|
1111
1486
|
* Decorate a class with the default list of required roles.
|
1112
1487
|
* This class-level default can be overridden on a per-function basis with `requiredRole`.
|
@@ -1163,10 +1538,31 @@ class DBOS {
|
|
1163
1538
|
static associateFunctionWithInfo(external, func, target) {
|
1164
1539
|
return (0, decorators_1.associateMethodWithExternal)(external, target.ctorOrProto, target.className, target.name ?? func.name, func);
|
1165
1540
|
}
|
1541
|
+
/**
|
1542
|
+
* Register information to be associated with a DBOS function
|
1543
|
+
*/
|
1544
|
+
static associateParamWithInfo(external, func, target) {
|
1545
|
+
return (0, decorators_1.associateParameterWithExternal)(external, target.ctorOrProto, target.className, target.name ?? func.name, func, target.param);
|
1546
|
+
}
|
1166
1547
|
/** Get registrations */
|
1167
1548
|
static getAssociatedInfo(external, cls, funcName) {
|
1168
1549
|
return (0, decorators_1.getRegistrationsForExternal)(external, cls, funcName);
|
1169
1550
|
}
|
1170
1551
|
}
|
1171
1552
|
exports.DBOS = DBOS;
|
1553
|
+
/** @deprecated */
|
1554
|
+
class InitContext {
|
1555
|
+
createUserSchema() {
|
1556
|
+
DBOS.logger.warn('Schema synchronization is deprecated and unsafe for production use. Please use migrations instead: https://typeorm.io/migrations');
|
1557
|
+
return DBOS.createUserSchema();
|
1558
|
+
}
|
1559
|
+
dropUserSchema() {
|
1560
|
+
DBOS.logger.warn('Schema synchronization is deprecated and unsafe for production use. Please use migrations instead: https://typeorm.io/migrations');
|
1561
|
+
return DBOS.dropUserSchema();
|
1562
|
+
}
|
1563
|
+
queryUserDB(sql, ...params) {
|
1564
|
+
return DBOS.queryUserDB(sql, params);
|
1565
|
+
}
|
1566
|
+
}
|
1567
|
+
exports.InitContext = InitContext;
|
1172
1568
|
//# sourceMappingURL=dbos.js.map
|