@dbos-inc/dbos-sdk 2.10.3-preview → 2.10.11-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/dist/src/context.d.ts +13 -11
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js.map +1 -1
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +28 -23
- package/dist/src/dbos-executor.js.map +1 -1
- package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
- package/dist/src/dbos-runtime/runtime.js +1 -2
- package/dist/src/dbos-runtime/runtime.js.map +1 -1
- package/dist/src/dbos.d.ts +5 -11
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +161 -162
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/error.d.ts +2 -14
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +12 -97
- package/dist/src/error.js.map +1 -1
- package/dist/src/httpServer/middleware.d.ts.map +1 -1
- package/dist/src/httpServer/middleware.js +8 -9
- package/dist/src/httpServer/middleware.js.map +1 -1
- package/dist/src/httpServer/server.d.ts.map +1 -1
- package/dist/src/httpServer/server.js +1 -2
- package/dist/src/httpServer/server.js.map +1 -1
- package/dist/src/system_database.d.ts +1 -1
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.js +3 -3
- package/dist/src/system_database.js.map +1 -1
- package/dist/src/testing/testing_runtime.d.ts.map +1 -1
- package/dist/src/testing/testing_runtime.js +1 -2
- package/dist/src/testing/testing_runtime.js.map +1 -1
- package/dist/src/wfqueue.d.ts +3 -2
- package/dist/src/wfqueue.d.ts.map +1 -1
- package/dist/src/wfqueue.js.map +1 -1
- package/dist/src/workflow.d.ts +4 -4
- package/dist/src/workflow.d.ts.map +1 -1
- package/dist/src/workflow.js +1 -1
- package/dist/src/workflow.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/dbos.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.InitContext = exports.DBOS = void 0;
|
3
|
+
exports.InitContext = exports.DBOS = exports.runAsWorkflowStep = exports.getExecutor = void 0;
|
4
4
|
const context_1 = require("./context");
|
5
5
|
const dbos_executor_1 = require("./dbos-executor");
|
6
6
|
const logs_1 = require("./telemetry/logs");
|
@@ -54,6 +54,30 @@ function augmentProxy(target, proxy) {
|
|
54
54
|
proto = Object.getPrototypeOf(proto);
|
55
55
|
}
|
56
56
|
}
|
57
|
+
function getExecutor() {
|
58
|
+
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
59
|
+
throw new error_1.DBOSExecutorNotInitializedError();
|
60
|
+
}
|
61
|
+
return dbos_executor_1.DBOSExecutor.globalInstance;
|
62
|
+
}
|
63
|
+
exports.getExecutor = getExecutor;
|
64
|
+
function runAsWorkflowStep(callback, funcName, childWFID) {
|
65
|
+
if (DBOS.isWithinWorkflow()) {
|
66
|
+
if (DBOS.isInStep()) {
|
67
|
+
// OK to use directly
|
68
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
69
|
+
}
|
70
|
+
else if (DBOS.isInWorkflow()) {
|
71
|
+
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
72
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, DBOS.workflowID, wfctx.functionIDGetIncrement(), childWFID);
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to \`${funcName}\` inside a \`transaction\` or \`procedure\``);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
79
|
+
}
|
80
|
+
exports.runAsWorkflowStep = runAsWorkflowStep;
|
57
81
|
class DBOS {
|
58
82
|
///////
|
59
83
|
// Lifecycle
|
@@ -76,16 +100,16 @@ class DBOS {
|
|
76
100
|
* @param runtimeConfig - configuration of runtime access to DBOS
|
77
101
|
*/
|
78
102
|
static setConfig(config, runtimeConfig) {
|
79
|
-
DBOS
|
80
|
-
DBOS
|
103
|
+
DBOS.#dbosConfig = config;
|
104
|
+
DBOS.#runtimeConfig = runtimeConfig;
|
81
105
|
DBOS.translateConfig();
|
82
106
|
}
|
83
107
|
static translateConfig() {
|
84
|
-
if (DBOS
|
108
|
+
if (DBOS.#dbosConfig && !(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
85
109
|
const isDebugging = DBOS.getDebugModeFromEnv() !== dbos_executor_1.DebugMode.DISABLED;
|
86
|
-
[DBOS
|
110
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.translatePublicDBOSconfig)(DBOS.#dbosConfig, isDebugging);
|
87
111
|
if (process.env.DBOS__CLOUD === 'true') {
|
88
|
-
[DBOS
|
112
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.overwrite_config)(DBOS.#dbosConfig, DBOS.#runtimeConfig);
|
89
113
|
}
|
90
114
|
}
|
91
115
|
}
|
@@ -94,7 +118,7 @@ class DBOS {
|
|
94
118
|
* Use `setConfig`
|
95
119
|
*/
|
96
120
|
static setAppConfig(key, newValue) {
|
97
|
-
const conf = DBOS
|
121
|
+
const conf = DBOS.#dbosConfig?.application;
|
98
122
|
if (!conf)
|
99
123
|
throw new error_1.DBOSExecutorNotInitializedError();
|
100
124
|
(0, lodash_1.set)(conf, key, newValue);
|
@@ -104,11 +128,11 @@ class DBOS {
|
|
104
128
|
* USE IN TESTS ONLY - ALL WORKFLOWS, QUEUES, ETC. WILL BE LOST.
|
105
129
|
*/
|
106
130
|
static async dropSystemDB() {
|
107
|
-
if (!DBOS
|
108
|
-
DBOS
|
131
|
+
if (!DBOS.#dbosConfig) {
|
132
|
+
DBOS.#dbosConfig = (0, config_1.parseConfigFile)()[0];
|
109
133
|
}
|
110
134
|
DBOS.translateConfig();
|
111
|
-
return system_database_1.PostgresSystemDatabase.dropSystemDB(DBOS
|
135
|
+
return system_database_1.PostgresSystemDatabase.dropSystemDB(DBOS.#dbosConfig);
|
112
136
|
}
|
113
137
|
/**
|
114
138
|
* Use ORMEntities to set up database schema.
|
@@ -151,21 +175,20 @@ class DBOS {
|
|
151
175
|
utils_1.globalParams.executorID = (0, node_crypto_1.randomUUID)();
|
152
176
|
}
|
153
177
|
// Initialize the DBOS executor
|
154
|
-
if (!DBOS
|
155
|
-
[DBOS
|
178
|
+
if (!DBOS.#dbosConfig) {
|
179
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.parseConfigFile)({ forceConsole: isDebugging });
|
156
180
|
}
|
157
|
-
else if (!(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS
|
181
|
+
else if (!(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
158
182
|
DBOS.translateConfig(); // This is a defensive measure for users who'd do DBOS.config = X instead of using DBOS.setConfig()
|
159
183
|
}
|
160
|
-
if (!DBOS
|
184
|
+
if (!DBOS.#dbosConfig) {
|
161
185
|
throw new error_1.DBOSError('DBOS configuration not set');
|
162
186
|
}
|
163
187
|
dbos_executor_1.DBOSExecutor.createInternalQueue();
|
164
|
-
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(DBOS
|
188
|
+
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(DBOS.#dbosConfig, {
|
165
189
|
debugMode,
|
166
190
|
});
|
167
191
|
const executor = dbos_executor_1.DBOSExecutor.globalInstance;
|
168
|
-
DBOS.globalLogger = executor.logger;
|
169
192
|
await executor.init();
|
170
193
|
const debugWorkflowId = process.env.DBOS_DEBUG_WORKFLOW_ID;
|
171
194
|
if (debugWorkflowId) {
|
@@ -188,14 +211,14 @@ class DBOS {
|
|
188
211
|
}
|
189
212
|
// Start the DBOS admin server
|
190
213
|
const logger = DBOS.logger;
|
191
|
-
if (DBOS
|
214
|
+
if (DBOS.#runtimeConfig && DBOS.#runtimeConfig.runAdminServer) {
|
192
215
|
const adminApp = server_1.DBOSHttpServer.setupAdminApp(executor);
|
193
216
|
try {
|
194
|
-
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(DBOS
|
217
|
+
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(DBOS.#runtimeConfig.admin_port, logger);
|
195
218
|
// Wrap the listen call in a promise to properly catch errors
|
196
219
|
DBOS.adminServer = await new Promise((resolve, reject) => {
|
197
|
-
const server = adminApp.listen(DBOS
|
198
|
-
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${DBOS
|
220
|
+
const server = adminApp.listen(DBOS.#runtimeConfig?.admin_port, () => {
|
221
|
+
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${DBOS.#runtimeConfig?.admin_port}`);
|
199
222
|
resolve(server);
|
200
223
|
});
|
201
224
|
server.on('error', (err) => {
|
@@ -204,7 +227,7 @@ class DBOS {
|
|
204
227
|
});
|
205
228
|
}
|
206
229
|
catch (e) {
|
207
|
-
logger.warn(`Unable to start DBOS admin server on port ${DBOS
|
230
|
+
logger.warn(`Unable to start DBOS admin server on port ${DBOS.#runtimeConfig.admin_port}`);
|
208
231
|
}
|
209
232
|
}
|
210
233
|
if (options?.koaApp) {
|
@@ -296,14 +319,9 @@ class DBOS {
|
|
296
319
|
static async initEventReceivers() {
|
297
320
|
return dbos_executor_1.DBOSExecutor.globalInstance?.initEventReceivers();
|
298
321
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
static get executor() {
|
303
|
-
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
304
|
-
throw new error_1.DBOSExecutorNotInitializedError();
|
305
|
-
}
|
306
|
-
return dbos_executor_1.DBOSExecutor.globalInstance;
|
322
|
+
// Global DBOS executor instance
|
323
|
+
static get #executor() {
|
324
|
+
return getExecutor();
|
307
325
|
}
|
308
326
|
/**
|
309
327
|
* Creates a node.js HTTP handler for all entrypoints registered with `@DBOS.getApi`
|
@@ -326,9 +344,9 @@ class DBOS {
|
|
326
344
|
*/
|
327
345
|
static async launchAppHTTPServer() {
|
328
346
|
const server = DBOS.setUpHandlerCallback();
|
329
|
-
if (DBOS
|
347
|
+
if (DBOS.#runtimeConfig) {
|
330
348
|
// This will not listen if there's no decorated endpoint
|
331
|
-
DBOS.appServer = await server.appListen(DBOS
|
349
|
+
DBOS.appServer = await server.appListen(DBOS.#runtimeConfig.port);
|
332
350
|
}
|
333
351
|
}
|
334
352
|
/**
|
@@ -353,10 +371,12 @@ class DBOS {
|
|
353
371
|
//////
|
354
372
|
// Globals
|
355
373
|
//////
|
356
|
-
static
|
357
|
-
static
|
358
|
-
static
|
359
|
-
static
|
374
|
+
static #dbosConfig;
|
375
|
+
static #runtimeConfig = undefined;
|
376
|
+
static #invokeWrappers = new Map();
|
377
|
+
static get dbosConfig() {
|
378
|
+
return DBOS.#dbosConfig;
|
379
|
+
}
|
360
380
|
//////
|
361
381
|
// Context
|
362
382
|
//////
|
@@ -477,8 +497,8 @@ class DBOS {
|
|
477
497
|
*/
|
478
498
|
static get pgClient() {
|
479
499
|
const client = DBOS.sqlClient;
|
480
|
-
if (!DBOS.isInStoredProc() && DBOS
|
481
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.pgClient' but client is configured with type '${DBOS
|
500
|
+
if (!DBOS.isInStoredProc() && DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.PGNODE) {
|
501
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.pgClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
482
502
|
}
|
483
503
|
return client;
|
484
504
|
}
|
@@ -490,8 +510,8 @@ class DBOS {
|
|
490
510
|
if (DBOS.isInStoredProc()) {
|
491
511
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' from within a stored procedure`);
|
492
512
|
}
|
493
|
-
if (DBOS
|
494
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' but client is configured with type '${DBOS
|
513
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.KNEX) {
|
514
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.knexClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
495
515
|
}
|
496
516
|
const client = DBOS.sqlClient;
|
497
517
|
return client;
|
@@ -504,8 +524,8 @@ class DBOS {
|
|
504
524
|
if (DBOS.isInStoredProc()) {
|
505
525
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' from within a stored procedure`);
|
506
526
|
}
|
507
|
-
if (DBOS
|
508
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' but client is configured with type '${DBOS
|
527
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.PRISMA) {
|
528
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.prismaClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
509
529
|
}
|
510
530
|
const client = DBOS.sqlClient;
|
511
531
|
return client;
|
@@ -518,8 +538,8 @@ class DBOS {
|
|
518
538
|
if (DBOS.isInStoredProc()) {
|
519
539
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' from within a stored procedure`);
|
520
540
|
}
|
521
|
-
if (DBOS
|
522
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' but client is configured with type '${DBOS
|
541
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.TYPEORM) {
|
542
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.typeORMClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
523
543
|
}
|
524
544
|
const client = DBOS.sqlClient;
|
525
545
|
return client;
|
@@ -532,8 +552,8 @@ class DBOS {
|
|
532
552
|
if (DBOS.isInStoredProc()) {
|
533
553
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' from within a stored procedure`);
|
534
554
|
}
|
535
|
-
if (DBOS
|
536
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' but client is configured with type '${DBOS
|
555
|
+
if (DBOS.#dbosConfig?.userDbclient !== user_database_1.UserDatabaseName.DRIZZLE) {
|
556
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError(`Requested 'DBOS.drizzleClient' but client is configured with type '${DBOS.#dbosConfig?.userDbclient}'`);
|
537
557
|
}
|
538
558
|
const client = DBOS.sqlClient;
|
539
559
|
return client;
|
@@ -550,8 +570,8 @@ class DBOS {
|
|
550
570
|
return ctx.getConfig(key, defaultValue);
|
551
571
|
if (ctx)
|
552
572
|
return ctx.getConfig(key);
|
553
|
-
if (DBOS
|
554
|
-
return DBOS
|
573
|
+
if (DBOS.#executor)
|
574
|
+
return DBOS.#executor.getConfig(key, defaultValue);
|
555
575
|
return defaultValue;
|
556
576
|
}
|
557
577
|
/**
|
@@ -565,7 +585,7 @@ class DBOS {
|
|
565
585
|
if (DBOS.isWithinWorkflow() && !DBOS.isInStep()) {
|
566
586
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `queryUserDB` inside a `workflow`, without being in a `step`');
|
567
587
|
}
|
568
|
-
return DBOS
|
588
|
+
return DBOS.#executor.queryUserDB(sql, params);
|
569
589
|
}
|
570
590
|
//////
|
571
591
|
// Access to system DB, for event receivers etc.
|
@@ -586,7 +606,7 @@ class DBOS {
|
|
586
606
|
* @returns The latest system database state for the specified service+workflow+item
|
587
607
|
*/
|
588
608
|
static async getEventDispatchState(svc, wfn, key) {
|
589
|
-
return await DBOS
|
609
|
+
return await DBOS.#executor.getEventDispatchState(svc, wfn, key);
|
590
610
|
}
|
591
611
|
/**
|
592
612
|
* Set a state item into the system database, which provides a key/value store interface for event dispatchers.
|
@@ -598,26 +618,13 @@ class DBOS {
|
|
598
618
|
* @returns The upsert returns the current record, which may be useful if it is more recent than the `state` provided.
|
599
619
|
*/
|
600
620
|
static async upsertEventDispatchState(state) {
|
601
|
-
return await DBOS
|
621
|
+
return await DBOS.#executor.upsertEventDispatchState(state);
|
602
622
|
}
|
603
623
|
//////
|
604
624
|
// Workflow and other operations
|
605
625
|
//////
|
606
|
-
static runAsWorkflowStep(callback, funcName
|
607
|
-
|
608
|
-
if (DBOS.isInStep()) {
|
609
|
-
// OK to use directly
|
610
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
611
|
-
}
|
612
|
-
else if (DBOS.isInWorkflow()) {
|
613
|
-
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
614
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, DBOS.workflowID, wfctx.functionIDGetIncrement(), childWFID);
|
615
|
-
}
|
616
|
-
else {
|
617
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to \`${funcName}\` inside a \`transaction\` or \`procedure\``);
|
618
|
-
}
|
619
|
-
}
|
620
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runAsStep(callback, funcName, undefined, undefined, childWFID);
|
626
|
+
static #runAsWorkflowStep(callback, funcName) {
|
627
|
+
return runAsWorkflowStep(callback, funcName);
|
621
628
|
}
|
622
629
|
/**
|
623
630
|
* Get the workflow status given a workflow ID
|
@@ -628,17 +635,17 @@ class DBOS {
|
|
628
635
|
if (DBOS.isWithinWorkflow()) {
|
629
636
|
if (DBOS.isInStep()) {
|
630
637
|
// OK to use directly
|
631
|
-
return DBOS
|
638
|
+
return DBOS.#executor.getWorkflowStatus(workflowID);
|
632
639
|
}
|
633
640
|
else if (DBOS.isInWorkflow()) {
|
634
641
|
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
635
|
-
return DBOS
|
642
|
+
return DBOS.#executor.getWorkflowStatus(workflowID, DBOS.workflowID, wfctx.functionIDGetIncrement());
|
636
643
|
}
|
637
644
|
else {
|
638
645
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `getWorkflowStatus` inside a `transaction` or `procedure`');
|
639
646
|
}
|
640
647
|
}
|
641
|
-
return DBOS
|
648
|
+
return DBOS.#executor.getWorkflowStatus(workflowID);
|
642
649
|
}
|
643
650
|
/**
|
644
651
|
* Get the workflow result, given a workflow ID
|
@@ -651,12 +658,13 @@ class DBOS {
|
|
651
658
|
if (DBOS.isWithinWorkflow() && timeoutSeconds !== undefined) {
|
652
659
|
timerFuncID = (0, context_1.assertCurrentWorkflowContext)().functionIDGetIncrement();
|
653
660
|
}
|
654
|
-
return await
|
661
|
+
return await runAsWorkflowStep(async () => {
|
655
662
|
const rres = await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.awaitWorkflowResult(workflowID, timeoutSeconds, DBOS.workflowID, timerFuncID);
|
656
663
|
if (!rres)
|
657
664
|
return null;
|
658
|
-
if (rres?.cancelled)
|
659
|
-
throw new error_1.
|
665
|
+
if (rres?.cancelled) {
|
666
|
+
throw new error_1.DBOSAwaitedWorkflowCancelledError(workflowID);
|
667
|
+
}
|
660
668
|
return dbos_executor_1.DBOSExecutor.reviveResultOrError(rres);
|
661
669
|
}, 'DBOS.getResult', workflowID);
|
662
670
|
}
|
@@ -674,7 +682,7 @@ class DBOS {
|
|
674
682
|
}
|
675
683
|
return (0, context_1.getCurrentDBOSContext)().retrieveWorkflow(workflowID);
|
676
684
|
}
|
677
|
-
return DBOS
|
685
|
+
return DBOS.#executor.retrieveWorkflow(workflowID);
|
678
686
|
}
|
679
687
|
/**
|
680
688
|
* Query the system database for all workflows matching the provided predicate
|
@@ -683,8 +691,8 @@ class DBOS {
|
|
683
691
|
* @deprecated Use `DBOS.listWorkflows` instead
|
684
692
|
*/
|
685
693
|
static async getWorkflows(input) {
|
686
|
-
return await DBOS
|
687
|
-
const wfs = await DBOS
|
694
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
695
|
+
const wfs = await DBOS.#executor.listWorkflows(input);
|
688
696
|
return { workflowUUIDs: wfs.map((wf) => wf.workflowID) };
|
689
697
|
}, 'DBOS.getWorkflows');
|
690
698
|
}
|
@@ -694,8 +702,8 @@ class DBOS {
|
|
694
702
|
* @returns `WorkflowStatus` array containing details of the matching workflows
|
695
703
|
*/
|
696
704
|
static async listWorkflows(input) {
|
697
|
-
return await DBOS
|
698
|
-
return await DBOS
|
705
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
706
|
+
return await DBOS.#executor.listWorkflows(input);
|
699
707
|
}, 'DBOS.listWorkflows');
|
700
708
|
}
|
701
709
|
/**
|
@@ -704,8 +712,8 @@ class DBOS {
|
|
704
712
|
* @returns `WorkflowStatus` array containing details of the matching workflows
|
705
713
|
*/
|
706
714
|
static async listQueuedWorkflows(input) {
|
707
|
-
return await DBOS
|
708
|
-
return await DBOS
|
715
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
716
|
+
return await DBOS.#executor.listQueuedWorkflows(input);
|
709
717
|
}, 'DBOS.listQueuedWorkflows');
|
710
718
|
}
|
711
719
|
/**
|
@@ -714,8 +722,8 @@ class DBOS {
|
|
714
722
|
* @returns `StepInfo` array listing the executed steps of the workflow. If the workflow is not found, `undefined` is returned.
|
715
723
|
*/
|
716
724
|
static async listWorkflowSteps(workflowID) {
|
717
|
-
return await DBOS
|
718
|
-
return await DBOS
|
725
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
726
|
+
return await DBOS.#executor.listWorkflowSteps(workflowID);
|
719
727
|
}, 'DBOS.listWorkflowSteps');
|
720
728
|
}
|
721
729
|
/**
|
@@ -725,8 +733,8 @@ class DBOS {
|
|
725
733
|
* @param workflowID - ID of the workflow
|
726
734
|
*/
|
727
735
|
static async cancelWorkflow(workflowID) {
|
728
|
-
return await DBOS
|
729
|
-
return await DBOS
|
736
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
737
|
+
return await DBOS.#executor.cancelWorkflow(workflowID);
|
730
738
|
}, 'DBOS.cancelWorkflow');
|
731
739
|
}
|
732
740
|
/**
|
@@ -734,8 +742,8 @@ class DBOS {
|
|
734
742
|
* @param workflowID - ID of the workflow
|
735
743
|
*/
|
736
744
|
static async resumeWorkflow(workflowID) {
|
737
|
-
await DBOS
|
738
|
-
return await DBOS
|
745
|
+
await DBOS.#runAsWorkflowStep(async () => {
|
746
|
+
return await DBOS.#executor.resumeWorkflow(workflowID);
|
739
747
|
}, 'DBOS.resumeWorkflow');
|
740
748
|
return this.retrieveWorkflow(workflowID);
|
741
749
|
}
|
@@ -748,8 +756,8 @@ class DBOS {
|
|
748
756
|
* @throws DBOSInvalidStepIDError if the `startStep` is greater than the maximum step ID of the workflow
|
749
757
|
*/
|
750
758
|
static async forkWorkflow(workflowID, startStep, options) {
|
751
|
-
const forkedID = await DBOS
|
752
|
-
return await DBOS
|
759
|
+
const forkedID = await DBOS.#runAsWorkflowStep(async () => {
|
760
|
+
return await DBOS.#executor.forkWorkflow(workflowID, startStep, options);
|
753
761
|
}, 'DBOS.forkWorkflow');
|
754
762
|
return this.retrieveWorkflow(forkedID);
|
755
763
|
}
|
@@ -758,8 +766,8 @@ class DBOS {
|
|
758
766
|
* @param input - Filter predicate, containing the queue name and other criteria
|
759
767
|
*/
|
760
768
|
static async getWorkflowQueue(input) {
|
761
|
-
return await DBOS
|
762
|
-
return await DBOS
|
769
|
+
return await DBOS.#runAsWorkflowStep(async () => {
|
770
|
+
return await DBOS.#executor.getWorkflowQueue(input);
|
763
771
|
}, 'DBOS.getWorkflowQueue');
|
764
772
|
}
|
765
773
|
/**
|
@@ -795,20 +803,7 @@ class DBOS {
|
|
795
803
|
* @returns - Return value from `callback`
|
796
804
|
*/
|
797
805
|
static async withNextWorkflowID(workflowID, callback) {
|
798
|
-
|
799
|
-
if (pctx) {
|
800
|
-
const pcwfid = pctx.idAssignedForNextWorkflow;
|
801
|
-
try {
|
802
|
-
pctx.idAssignedForNextWorkflow = workflowID;
|
803
|
-
return callback();
|
804
|
-
}
|
805
|
-
finally {
|
806
|
-
pctx.idAssignedForNextWorkflow = pcwfid;
|
807
|
-
}
|
808
|
-
}
|
809
|
-
else {
|
810
|
-
return (0, context_1.runWithTopContext)({ idAssignedForNextWorkflow: workflowID }, callback);
|
811
|
-
}
|
806
|
+
return DBOS.#withTopContext({ idAssignedForNextWorkflow: workflowID }, callback);
|
812
807
|
}
|
813
808
|
/**
|
814
809
|
* Use the provided `callerName`, `span`, and `request` as context for any
|
@@ -820,16 +815,11 @@ class DBOS {
|
|
820
815
|
* @returns - Return value from `callback`
|
821
816
|
*/
|
822
817
|
static async withTracedContext(callerName, span, request, callback) {
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
return callback();
|
829
|
-
}
|
830
|
-
else {
|
831
|
-
return (0, context_1.runWithTopContext)({ span, request }, callback);
|
832
|
-
}
|
818
|
+
return DBOS.#withTopContext({
|
819
|
+
operationCaller: callerName,
|
820
|
+
span,
|
821
|
+
request,
|
822
|
+
}, callback);
|
833
823
|
}
|
834
824
|
/**
|
835
825
|
* Use the provided `authedUser` and `authedRoles` as the authenticated user for
|
@@ -841,15 +831,10 @@ class DBOS {
|
|
841
831
|
* @returns - Return value from `callback`
|
842
832
|
*/
|
843
833
|
static async withAuthedContext(authedUser, authedRoles, callback) {
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
return callback();
|
849
|
-
}
|
850
|
-
else {
|
851
|
-
return (0, context_1.runWithTopContext)({ authenticatedUser: authedUser, authenticatedRoles: authedRoles }, callback);
|
852
|
-
}
|
834
|
+
return DBOS.#withTopContext({
|
835
|
+
authenticatedUser: authedUser,
|
836
|
+
authenticatedRoles: authedRoles,
|
837
|
+
}, callback);
|
853
838
|
}
|
854
839
|
/**
|
855
840
|
* This generic setter helps users calling DBOS operation to pass a name,
|
@@ -859,14 +844,7 @@ class DBOS {
|
|
859
844
|
* @returns - Return value from `callback`
|
860
845
|
*/
|
861
846
|
static async withNamedContext(callerName, callback) {
|
862
|
-
|
863
|
-
if (pctx) {
|
864
|
-
pctx.operationCaller = callerName;
|
865
|
-
return callback();
|
866
|
-
}
|
867
|
-
else {
|
868
|
-
return (0, context_1.runWithTopContext)({ operationCaller: callerName }, callback);
|
869
|
-
}
|
847
|
+
return DBOS.#withTopContext({ operationCaller: callerName }, callback);
|
870
848
|
}
|
871
849
|
/**
|
872
850
|
* @deprecated
|
@@ -876,20 +854,7 @@ class DBOS {
|
|
876
854
|
* @returns - Return value from `callback`
|
877
855
|
*/
|
878
856
|
static async withWorkflowQueue(queueName, callback) {
|
879
|
-
|
880
|
-
if (pctx) {
|
881
|
-
const originalQueueName = pctx.queueAssignedForWorkflows;
|
882
|
-
try {
|
883
|
-
pctx.queueAssignedForWorkflows = queueName;
|
884
|
-
return callback();
|
885
|
-
}
|
886
|
-
finally {
|
887
|
-
pctx.queueAssignedForWorkflows = originalQueueName;
|
888
|
-
}
|
889
|
-
}
|
890
|
-
else {
|
891
|
-
return (0, context_1.runWithTopContext)({ queueAssignedForWorkflows: queueName }, callback);
|
892
|
-
}
|
857
|
+
return DBOS.#withTopContext({ queueAssignedForWorkflows: queueName }, callback);
|
893
858
|
}
|
894
859
|
/**
|
895
860
|
* Specify workflow timeout for any workflows started within the `callback`.
|
@@ -898,19 +863,44 @@ class DBOS {
|
|
898
863
|
* @returns - Return value from `callback`
|
899
864
|
*/
|
900
865
|
static async withWorkflowTimeout(timeoutMS, callback) {
|
866
|
+
return DBOS.#withTopContext({ workflowTimeoutMS: timeoutMS }, callback);
|
867
|
+
}
|
868
|
+
/**
|
869
|
+
* Run a workflow with the option to set any of the contextual items
|
870
|
+
*
|
871
|
+
* @param options - Overrides for options
|
872
|
+
* @param callback - Function to run, which would call or start workflows
|
873
|
+
* @returns - Return value from `callback`
|
874
|
+
*/
|
875
|
+
static async #withTopContext(options, callback) {
|
901
876
|
const pctx = (0, context_1.getCurrentContextStore)();
|
902
877
|
if (pctx) {
|
903
|
-
|
878
|
+
// Save existing values and overwrite with new; hard to do cleanly but is actually type correct
|
879
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
880
|
+
const existing = {};
|
881
|
+
for (const k of Object.keys(options)) {
|
882
|
+
if (Object.hasOwn(pctx, k))
|
883
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
884
|
+
existing[k] = options[k];
|
885
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
886
|
+
pctx[k] = options[k];
|
887
|
+
}
|
904
888
|
try {
|
905
|
-
|
906
|
-
return callback();
|
889
|
+
return await callback();
|
907
890
|
}
|
908
891
|
finally {
|
909
|
-
|
892
|
+
for (const k of Object.keys(options)) {
|
893
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
894
|
+
if (Object.hasOwn(existing, k))
|
895
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
896
|
+
pctx[k] = existing[k];
|
897
|
+
else
|
898
|
+
delete pctx[k];
|
899
|
+
}
|
910
900
|
}
|
911
901
|
}
|
912
902
|
else {
|
913
|
-
return (0, context_1.runWithTopContext)(
|
903
|
+
return (0, context_1.runWithTopContext)(options, callback);
|
914
904
|
}
|
915
905
|
}
|
916
906
|
static startWorkflow(target, params) {
|
@@ -944,6 +934,11 @@ class DBOS {
|
|
944
934
|
deadlineEpochMS: wfctx.deadlineEpochMS,
|
945
935
|
enqueueOptions: inParams?.enqueueOptions,
|
946
936
|
};
|
937
|
+
// Detach child deadline if a null timeout is configured
|
938
|
+
// We must check the inParams but also pctx (if the workflow was called withWorkflowTimeout)
|
939
|
+
if (inParams?.timeoutMS === null || pctx?.workflowTimeoutMS === null) {
|
940
|
+
wfParams.deadlineEpochMS = undefined;
|
941
|
+
}
|
947
942
|
for (const op of ops) {
|
948
943
|
if (op.workflowConfig) {
|
949
944
|
proxy[op.name] = (...args) => dbos_executor_1.DBOSExecutor.globalInstance.internalWorkflow(op.registeredFunction, wfParams, wfctx.workflowUUID, funcId, ...args);
|
@@ -973,7 +968,7 @@ class DBOS {
|
|
973
968
|
// If pctx has no span, e.g., has not been setup through `withTracedContext`, set up a parent span for the workflow here.
|
974
969
|
let span = pctx.span;
|
975
970
|
if (!span) {
|
976
|
-
span = DBOS
|
971
|
+
span = DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'startWorkflow', {
|
977
972
|
operationUUID: wfId,
|
978
973
|
operationType: pctx.operationType,
|
979
974
|
authenticatedUser: pctx.authenticatedUser,
|
@@ -998,7 +993,7 @@ class DBOS {
|
|
998
993
|
};
|
999
994
|
for (const op of ops) {
|
1000
995
|
if (op.workflowConfig) {
|
1001
|
-
proxy[op.name] = (...args) => DBOS
|
996
|
+
proxy[op.name] = (...args) => DBOS.#executor.workflow(op.registeredFunction, wfParams, ...args);
|
1002
997
|
}
|
1003
998
|
else if (op.txnConfig) {
|
1004
999
|
const txn = op.registeredFunction;
|
@@ -1022,7 +1017,7 @@ class DBOS {
|
|
1022
1017
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1023
1018
|
let span = pctx?.span;
|
1024
1019
|
if (!span) {
|
1025
|
-
span = DBOS
|
1020
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1026
1021
|
operationType: pctx?.operationType,
|
1027
1022
|
authenticatedUser: pctx?.authenticatedUser,
|
1028
1023
|
assumedRole: pctx?.assumedRole,
|
@@ -1136,7 +1131,7 @@ class DBOS {
|
|
1136
1131
|
}
|
1137
1132
|
return (0, context_1.getCurrentDBOSContext)().send(destinationID, message, topic);
|
1138
1133
|
}
|
1139
|
-
return DBOS
|
1134
|
+
return DBOS.#executor.send(destinationID, message, topic, idempotencyKey);
|
1140
1135
|
}
|
1141
1136
|
/**
|
1142
1137
|
* Receive a message on optional `topic` from within a workflow.
|
@@ -1196,7 +1191,7 @@ class DBOS {
|
|
1196
1191
|
}
|
1197
1192
|
return (0, context_1.getCurrentDBOSContext)().getEvent(workflowID, key, timeoutSeconds);
|
1198
1193
|
}
|
1199
|
-
return DBOS
|
1194
|
+
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1200
1195
|
}
|
1201
1196
|
//////
|
1202
1197
|
// Decorators
|
@@ -1254,6 +1249,10 @@ class DBOS {
|
|
1254
1249
|
timeoutMS: pctx?.workflowTimeoutMS,
|
1255
1250
|
deadlineEpochMS: wfctx.deadlineEpochMS,
|
1256
1251
|
};
|
1252
|
+
// Detach child deadline if a null timeout is configured
|
1253
|
+
if (pctx?.workflowTimeoutMS === null) {
|
1254
|
+
params.deadlineEpochMS = undefined;
|
1255
|
+
}
|
1257
1256
|
const cwfh = await dbos_executor_1.DBOSExecutor.globalInstance.internalWorkflow(registration.registeredFunction, params, wfctx.workflowUUID, funcId, ...rawArgs);
|
1258
1257
|
return await cwfh.getResult();
|
1259
1258
|
}
|
@@ -1263,7 +1262,7 @@ class DBOS {
|
|
1263
1262
|
// If pctx has no span, e.g., has not been setup through `withTracedContext`, set up a parent span for the workflow here.
|
1264
1263
|
let span = pctx.span;
|
1265
1264
|
if (!span) {
|
1266
|
-
span = DBOS
|
1265
|
+
span = DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'workflowCaller', {
|
1267
1266
|
operationUUID: wfId,
|
1268
1267
|
operationType: pctx.operationType,
|
1269
1268
|
authenticatedUser: pctx.authenticatedUser,
|
@@ -1285,7 +1284,7 @@ class DBOS {
|
|
1285
1284
|
parentCtx,
|
1286
1285
|
timeoutMS: pctx?.workflowTimeoutMS,
|
1287
1286
|
};
|
1288
|
-
const handle = await DBOS
|
1287
|
+
const handle = await DBOS.#executor.workflow(registration.registeredFunction, wfParams, ...rawArgs);
|
1289
1288
|
return await handle.getResult();
|
1290
1289
|
};
|
1291
1290
|
descriptor.value = invokeWrapper;
|
@@ -1295,7 +1294,7 @@ class DBOS {
|
|
1295
1294
|
});
|
1296
1295
|
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1297
1296
|
// TODO CTX this should not be in here already, or if it is we need to do something different...
|
1298
|
-
DBOS
|
1297
|
+
DBOS.#invokeWrappers.set(invokeWrapper, registration.registeredFunction);
|
1299
1298
|
return descriptor;
|
1300
1299
|
}
|
1301
1300
|
return decorator;
|
@@ -1335,7 +1334,7 @@ class DBOS {
|
|
1335
1334
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1336
1335
|
let span = pctx?.span;
|
1337
1336
|
if (!span) {
|
1338
|
-
span = DBOS
|
1337
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1339
1338
|
operationType: pctx?.operationType,
|
1340
1339
|
authenticatedUser: pctx?.authenticatedUser,
|
1341
1340
|
assumedRole: pctx?.assumedRole,
|
@@ -1358,7 +1357,7 @@ class DBOS {
|
|
1358
1357
|
parentCtx,
|
1359
1358
|
workflowUUID: wfId,
|
1360
1359
|
};
|
1361
|
-
return await DBOS
|
1360
|
+
return await DBOS.#executor.transaction(registration.registeredFunction, wfParams, ...rawArgs);
|
1362
1361
|
};
|
1363
1362
|
descriptor.value = invokeWrapper;
|
1364
1363
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1391,7 +1390,7 @@ class DBOS {
|
|
1391
1390
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1392
1391
|
let span = pctx?.span;
|
1393
1392
|
if (!span) {
|
1394
|
-
span = DBOS
|
1393
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1395
1394
|
operationType: pctx?.operationType,
|
1396
1395
|
authenticatedUser: pctx?.authenticatedUser,
|
1397
1396
|
assumedRole: pctx?.assumedRole,
|
@@ -1413,7 +1412,7 @@ class DBOS {
|
|
1413
1412
|
parentCtx,
|
1414
1413
|
workflowUUID: wfId,
|
1415
1414
|
};
|
1416
|
-
return await DBOS
|
1415
|
+
return await DBOS.#executor.procedure(registration.registeredFunction, wfParams, ...rawArgs);
|
1417
1416
|
};
|
1418
1417
|
descriptor.value = invokeWrapper;
|
1419
1418
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1462,7 +1461,7 @@ class DBOS {
|
|
1462
1461
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1463
1462
|
let span = pctx?.span;
|
1464
1463
|
if (!span) {
|
1465
|
-
span = DBOS
|
1464
|
+
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1466
1465
|
operationType: pctx?.operationType,
|
1467
1466
|
authenticatedUser: pctx?.authenticatedUser,
|
1468
1467
|
assumedRole: pctx?.assumedRole,
|
@@ -1485,7 +1484,7 @@ class DBOS {
|
|
1485
1484
|
parentCtx,
|
1486
1485
|
workflowUUID: wfId,
|
1487
1486
|
};
|
1488
|
-
return await DBOS
|
1487
|
+
return await DBOS.#executor.external(registration.registeredFunction, wfParams, ...rawArgs);
|
1489
1488
|
};
|
1490
1489
|
descriptor.value = invokeWrapper;
|
1491
1490
|
registration.wrappedFunction = invokeWrapper;
|