@dbos-inc/dbos-sdk 3.0.23-preview → 3.0.27-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/authdecorators.d.ts +0 -7
- package/dist/src/authdecorators.d.ts.map +1 -1
- package/dist/src/authdecorators.js +1 -29
- package/dist/src/authdecorators.js.map +1 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js.map +1 -1
- package/dist/src/context.d.ts +10 -44
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +34 -114
- package/dist/src/context.js.map +1 -1
- package/dist/src/datasource.d.ts.map +1 -1
- package/dist/src/datasource.js +37 -17
- package/dist/src/datasource.js.map +1 -1
- package/dist/src/dbos-executor.d.ts +32 -37
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +263 -267
- package/dist/src/dbos-executor.js.map +1 -1
- package/dist/src/dbos-runtime/cli.d.ts.map +1 -1
- package/dist/src/dbos-runtime/cli.js +1 -3
- package/dist/src/dbos-runtime/cli.js.map +1 -1
- package/dist/src/dbos-runtime/debug.d.ts +1 -1
- package/dist/src/dbos-runtime/debug.d.ts.map +1 -1
- package/dist/src/dbos-runtime/debug.js +2 -3
- package/dist/src/dbos-runtime/debug.js.map +1 -1
- package/dist/src/dbos.d.ts +6 -21
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +98 -268
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/decorators.d.ts +7 -7
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +6 -30
- package/dist/src/decorators.js.map +1 -1
- package/dist/src/eventreceiver.d.ts +7 -10
- package/dist/src/eventreceiver.d.ts.map +1 -1
- package/dist/src/httpServer/handler.d.ts +1 -9
- package/dist/src/httpServer/handler.d.ts.map +1 -1
- package/dist/src/httpServer/handler.js.map +1 -1
- package/dist/src/httpServer/middleware.d.ts +2 -2
- package/dist/src/httpServer/middleware.d.ts.map +1 -1
- package/dist/src/httpServer/server.d.ts +3 -3
- package/dist/src/httpServer/server.d.ts.map +1 -1
- package/dist/src/httpServer/server.js +19 -21
- package/dist/src/httpServer/server.js.map +1 -1
- package/dist/src/index.d.ts +3 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -13
- package/dist/src/index.js.map +1 -1
- package/dist/src/paramdecorators.d.ts.map +1 -1
- package/dist/src/paramdecorators.js +0 -6
- package/dist/src/paramdecorators.js.map +1 -1
- package/dist/src/procedure.d.ts +0 -22
- package/dist/src/procedure.d.ts.map +1 -1
- package/dist/src/procedure.js +0 -16
- package/dist/src/procedure.js.map +1 -1
- package/dist/src/scheduler/scheduler.d.ts.map +1 -1
- package/dist/src/scheduler/scheduler.js.map +1 -1
- package/dist/src/step.d.ts +0 -25
- package/dist/src/step.d.ts.map +1 -1
- package/dist/src/step.js +0 -20
- package/dist/src/step.js.map +1 -1
- package/dist/src/system_database.d.ts +4 -4
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.js.map +1 -1
- package/dist/src/telemetry/logs.d.ts +4 -8
- package/dist/src/telemetry/logs.d.ts.map +1 -1
- package/dist/src/telemetry/logs.js +25 -13
- package/dist/src/telemetry/logs.js.map +1 -1
- package/dist/src/transaction.d.ts +0 -25
- package/dist/src/transaction.d.ts.map +1 -1
- package/dist/src/transaction.js +1 -15
- package/dist/src/transaction.js.map +1 -1
- package/dist/src/user_database.d.ts +2 -2
- package/dist/src/user_database.d.ts.map +1 -1
- package/dist/src/user_database.js.map +1 -1
- package/dist/src/workflow.d.ts +4 -148
- package/dist/src/workflow.d.ts.map +1 -1
- package/dist/src/workflow.js +7 -226
- 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
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InitContext = exports.DBOS = exports.runInternalStep = exports.getExecutor = void 0;
|
4
4
|
const context_1 = require("./context");
|
5
5
|
const dbos_executor_1 = require("./dbos-executor");
|
6
|
+
const workflow_1 = require("./workflow");
|
6
7
|
const logs_1 = require("./telemetry/logs");
|
7
8
|
const error_1 = require("./error");
|
8
9
|
const config_1 = require("./dbos-runtime/config");
|
@@ -31,32 +32,6 @@ function httpApiDec(verb, url) {
|
|
31
32
|
return descriptor;
|
32
33
|
};
|
33
34
|
}
|
34
|
-
// Fill in any proxy functions with error-throwing stubs
|
35
|
-
// (Goal being to give a clearer error message)
|
36
|
-
function augmentProxy(target, proxy) {
|
37
|
-
let proto = target;
|
38
|
-
while (proto && proto !== Object.prototype) {
|
39
|
-
for (const k of Reflect.ownKeys(proto)) {
|
40
|
-
if (typeof k === 'symbol')
|
41
|
-
continue;
|
42
|
-
if (k === 'constructor' || k === 'caller' || k === 'callee' || k === 'arguments')
|
43
|
-
continue; // Skip constructor
|
44
|
-
try {
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
46
|
-
if (typeof target[k] !== 'function')
|
47
|
-
continue;
|
48
|
-
if (!Object.hasOwn(proxy, k)) {
|
49
|
-
proxy[k] = (..._args) => {
|
50
|
-
throw new error_1.DBOSNotRegisteredError(k, `${k} is not a registered DBOS function`);
|
51
|
-
};
|
52
|
-
}
|
53
|
-
}
|
54
|
-
catch (e) { }
|
55
|
-
}
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
57
|
-
proto = Object.getPrototypeOf(proto);
|
58
|
-
}
|
59
|
-
}
|
60
35
|
function getExecutor() {
|
61
36
|
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
62
37
|
throw new error_1.DBOSExecutorNotInitializedError();
|
@@ -71,9 +46,7 @@ function runInternalStep(callback, funcName, childWFID) {
|
|
71
46
|
return callback();
|
72
47
|
}
|
73
48
|
else if (DBOS.isInWorkflow()) {
|
74
|
-
|
75
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.runInternalStep(callback, funcName, DBOS.workflowID, // assume DBOS.workflowID is defined because of assertCurrentWorkflowContext call above
|
76
|
-
wfctx.functionIDGetIncrement(), childWFID);
|
49
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.runInternalStep(callback, funcName, DBOS.workflowID, (0, context_1.functionIDGetIncrement)(), childWFID);
|
77
50
|
}
|
78
51
|
else {
|
79
52
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to \`${funcName}\` inside a \`transaction\` or \`procedure\``);
|
@@ -91,12 +64,7 @@ class DBOS {
|
|
91
64
|
static conductor = undefined;
|
92
65
|
static getDebugModeFromEnv() {
|
93
66
|
const debugWorkflowId = process.env.DBOS_DEBUG_WORKFLOW_ID;
|
94
|
-
|
95
|
-
return isDebugging
|
96
|
-
? process.env.DBOS_DEBUG_TIME_TRAVEL === 'true'
|
97
|
-
? dbos_executor_1.DebugMode.TIME_TRAVEL
|
98
|
-
: dbos_executor_1.DebugMode.ENABLED
|
99
|
-
: dbos_executor_1.DebugMode.DISABLED;
|
67
|
+
return debugWorkflowId !== undefined;
|
100
68
|
}
|
101
69
|
/**
|
102
70
|
* Set configuration of `DBOS` prior to `launch`
|
@@ -110,8 +78,8 @@ class DBOS {
|
|
110
78
|
}
|
111
79
|
static translateConfig() {
|
112
80
|
if (DBOS.#dbosConfig && !(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
113
|
-
const
|
114
|
-
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.translatePublicDBOSconfig)(DBOS.#dbosConfig,
|
81
|
+
const debugMode = DBOS.getDebugModeFromEnv();
|
82
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.translatePublicDBOSconfig)(DBOS.#dbosConfig, debugMode);
|
115
83
|
if (process.env.DBOS__CLOUD === 'true') {
|
116
84
|
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.overwrite_config)(DBOS.#dbosConfig, DBOS.#runtimeConfig);
|
117
85
|
}
|
@@ -174,14 +142,13 @@ class DBOS {
|
|
174
142
|
return;
|
175
143
|
}
|
176
144
|
const debugMode = options?.debugMode ?? DBOS.getDebugModeFromEnv();
|
177
|
-
const isDebugging = debugMode !== dbos_executor_1.DebugMode.DISABLED;
|
178
145
|
if (options?.conductorKey) {
|
179
146
|
// Use a generated executor ID.
|
180
147
|
utils_1.globalParams.executorID = (0, node_crypto_1.randomUUID)();
|
181
148
|
}
|
182
149
|
// Initialize the DBOS executor
|
183
150
|
if (!DBOS.#dbosConfig) {
|
184
|
-
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.parseConfigFile)({ forceConsole:
|
151
|
+
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.parseConfigFile)({ forceConsole: debugMode });
|
185
152
|
}
|
186
153
|
else if (!(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
187
154
|
DBOS.translateConfig(); // This is a defensive measure for users who'd do DBOS.config = X instead of using DBOS.setConfig()
|
@@ -281,7 +248,7 @@ class DBOS {
|
|
281
248
|
evtRcvr.logRegisteredEndpoints();
|
282
249
|
}
|
283
250
|
for (const lcl of (0, decorators_1.getLifecycleListeners)()) {
|
284
|
-
lcl.logRegisteredEndpoints();
|
251
|
+
lcl.logRegisteredEndpoints?.();
|
285
252
|
}
|
286
253
|
}
|
287
254
|
/**
|
@@ -395,9 +362,9 @@ class DBOS {
|
|
395
362
|
//////
|
396
363
|
/** Get the current DBOS Logger, appropriate to the current context */
|
397
364
|
static get logger() {
|
398
|
-
const
|
399
|
-
if (
|
400
|
-
return
|
365
|
+
const lctx = (0, context_1.getCurrentContextStore)();
|
366
|
+
if (lctx?.logger)
|
367
|
+
return lctx.logger;
|
401
368
|
const executor = dbos_executor_1.DBOSExecutor.globalInstance;
|
402
369
|
if (executor)
|
403
370
|
return executor.logger;
|
@@ -411,7 +378,7 @@ class DBOS {
|
|
411
378
|
}
|
412
379
|
/** Get the current DBOS tracing span, appropriate to the current context */
|
413
380
|
static get span() {
|
414
|
-
return (0, context_1.
|
381
|
+
return (0, context_1.getCurrentContextStore)()?.span;
|
415
382
|
}
|
416
383
|
/**
|
417
384
|
* Get the current request object (such as an HTTP request)
|
@@ -419,7 +386,7 @@ class DBOS {
|
|
419
386
|
* and set it using `withTracedContext` or `runWithContext`
|
420
387
|
*/
|
421
388
|
static requestObject() {
|
422
|
-
return (0, context_1.
|
389
|
+
return (0, context_1.getCurrentContextStore)()?.request;
|
423
390
|
}
|
424
391
|
/** Get the current HTTP request (within `@DBOS.getApi` et al) */
|
425
392
|
static getRequest() {
|
@@ -445,7 +412,7 @@ class DBOS {
|
|
445
412
|
}
|
446
413
|
/** Get the current workflow ID */
|
447
414
|
static get workflowID() {
|
448
|
-
return (0, context_1.getCurrentContextStore)()?.workflowId
|
415
|
+
return (0, context_1.getCurrentContextStore)()?.workflowId;
|
449
416
|
}
|
450
417
|
/** Get the current step number, within the current workflow */
|
451
418
|
static get stepID() {
|
@@ -464,15 +431,15 @@ class DBOS {
|
|
464
431
|
}
|
465
432
|
/** Get the current authenticated user */
|
466
433
|
static get authenticatedUser() {
|
467
|
-
return (0, context_1.
|
434
|
+
return (0, context_1.getCurrentContextStore)()?.authenticatedUser ?? '';
|
468
435
|
}
|
469
436
|
/** Get the roles granted to the current authenticated user */
|
470
437
|
static get authenticatedRoles() {
|
471
|
-
return (0, context_1.
|
438
|
+
return (0, context_1.getCurrentContextStore)()?.authenticatedRoles ?? [];
|
472
439
|
}
|
473
440
|
/** Get the role assumed by the current user giving authorization to execute the current function */
|
474
441
|
static get assumedRole() {
|
475
|
-
return (0, context_1.
|
442
|
+
return (0, context_1.getCurrentContextStore)()?.assumedRole ?? '';
|
476
443
|
}
|
477
444
|
/** @returns true if called from within a transaction, false otherwise */
|
478
445
|
static isInTransaction() {
|
@@ -504,10 +471,10 @@ class DBOS {
|
|
504
471
|
// sql session (various forms)
|
505
472
|
/** @returns the current SQL client; only allowed within `@DBOS.transaction` functions */
|
506
473
|
static get sqlClient() {
|
507
|
-
|
474
|
+
const c = (0, context_1.getCurrentContextStore)()?.sqlClient;
|
475
|
+
if (!DBOS.isInTransaction() || !c)
|
508
476
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid use of `DBOS.sqlClient` outside of a `transaction`');
|
509
|
-
|
510
|
-
return ctx.client;
|
477
|
+
return c;
|
511
478
|
}
|
512
479
|
/**
|
513
480
|
* @returns the current PG SQL client;
|
@@ -583,11 +550,6 @@ class DBOS {
|
|
583
550
|
* @param defaultValue - value to return if `key` does not exist in the configuration
|
584
551
|
*/
|
585
552
|
static getConfig(key, defaultValue) {
|
586
|
-
const ctx = (0, context_1.getCurrentDBOSContext)();
|
587
|
-
if (ctx && defaultValue)
|
588
|
-
return ctx.getConfig(key, defaultValue);
|
589
|
-
if (ctx)
|
590
|
-
return ctx.getConfig(key);
|
591
553
|
if (DBOS.#executor)
|
592
554
|
return DBOS.#executor.getConfig(key, defaultValue);
|
593
555
|
return defaultValue;
|
@@ -653,8 +615,7 @@ class DBOS {
|
|
653
615
|
return DBOS.#executor.getWorkflowStatus(workflowID);
|
654
616
|
}
|
655
617
|
else if (DBOS.isInWorkflow()) {
|
656
|
-
|
657
|
-
return DBOS.#executor.getWorkflowStatus(workflowID, DBOS.workflowID, wfctx.functionIDGetIncrement());
|
618
|
+
return DBOS.#executor.getWorkflowStatus(workflowID, DBOS.workflowID, (0, context_1.functionIDGetIncrement)());
|
658
619
|
}
|
659
620
|
else {
|
660
621
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `getWorkflowStatus` inside a `transaction` or `procedure`');
|
@@ -671,7 +632,7 @@ class DBOS {
|
|
671
632
|
static async getResult(workflowID, timeoutSeconds) {
|
672
633
|
let timerFuncID = undefined;
|
673
634
|
if (DBOS.isWithinWorkflow() && timeoutSeconds !== undefined) {
|
674
|
-
timerFuncID = (0, context_1.
|
635
|
+
timerFuncID = (0, context_1.functionIDGetIncrement)();
|
675
636
|
}
|
676
637
|
return await runInternalStep(async () => {
|
677
638
|
const rres = await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.awaitWorkflowResult(workflowID, timeoutSeconds, DBOS.workflowID, timerFuncID);
|
@@ -695,7 +656,8 @@ class DBOS {
|
|
695
656
|
if (!DBOS.isInWorkflow()) {
|
696
657
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `retrieveWorkflow` inside a `transaction` or `step`');
|
697
658
|
}
|
698
|
-
|
659
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
660
|
+
return new workflow_1.RetrievedHandle(dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase, workflowID, DBOS.workflowID, functionID);
|
699
661
|
}
|
700
662
|
return DBOS.#executor.retrieveWorkflow(workflowID);
|
701
663
|
}
|
@@ -789,7 +751,11 @@ class DBOS {
|
|
789
751
|
if (DBOS.isInTransaction()) {
|
790
752
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.sleep` inside a `transaction`');
|
791
753
|
}
|
792
|
-
|
754
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
755
|
+
if (durationMS <= 0) {
|
756
|
+
return;
|
757
|
+
}
|
758
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.durableSleepms(DBOS.workflowID, functionID, durationMS);
|
793
759
|
}
|
794
760
|
await (0, utils_1.sleepms)(durationMS);
|
795
761
|
}
|
@@ -929,9 +895,9 @@ class DBOS {
|
|
929
895
|
}
|
930
896
|
}
|
931
897
|
else {
|
932
|
-
|
933
|
-
if (!span) {
|
934
|
-
span = DBOS.#executor.tracer.startSpan('topContext', {
|
898
|
+
const span = options.span;
|
899
|
+
if (!options.span) {
|
900
|
+
options.span = DBOS.#executor.tracer.startSpan('topContext', {
|
935
901
|
operationUUID: options.idAssignedForNextWorkflow,
|
936
902
|
operationType: options.operationType,
|
937
903
|
authenticatedUser: options.authenticatedUser,
|
@@ -939,16 +905,12 @@ class DBOS {
|
|
939
905
|
authenticatedRoles: options.authenticatedRoles,
|
940
906
|
});
|
941
907
|
}
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
return (0, context_1.runWithTopContext)({
|
949
|
-
...options,
|
950
|
-
ctx,
|
951
|
-
}, callback);
|
908
|
+
try {
|
909
|
+
return await (0, context_1.runWithTopContext)(options, callback);
|
910
|
+
}
|
911
|
+
finally {
|
912
|
+
options.span = span;
|
913
|
+
}
|
952
914
|
}
|
953
915
|
}
|
954
916
|
static startWorkflow(target, params) {
|
@@ -980,104 +942,6 @@ class DBOS {
|
|
980
942
|
};
|
981
943
|
return new Proxy(target, handler);
|
982
944
|
}
|
983
|
-
static invoke(object) {
|
984
|
-
if (!DBOS.isWithinWorkflow()) {
|
985
|
-
const pctx = (0, context_1.getCurrentContextStore)();
|
986
|
-
let span = pctx?.span;
|
987
|
-
if (!span) {
|
988
|
-
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
989
|
-
operationType: pctx?.operationType,
|
990
|
-
authenticatedUser: pctx?.authenticatedUser,
|
991
|
-
assumedRole: pctx?.assumedRole,
|
992
|
-
authenticatedRoles: pctx?.authenticatedRoles,
|
993
|
-
});
|
994
|
-
}
|
995
|
-
let parentCtx = undefined;
|
996
|
-
if (pctx) {
|
997
|
-
parentCtx = pctx.ctx;
|
998
|
-
}
|
999
|
-
if (!parentCtx) {
|
1000
|
-
parentCtx = new context_1.DBOSContextImpl(pctx?.operationCaller || 'workflowCaller', span, DBOS.logger);
|
1001
|
-
parentCtx.request = pctx?.request || {};
|
1002
|
-
parentCtx.authenticatedUser = pctx?.authenticatedUser || '';
|
1003
|
-
parentCtx.assumedRole = pctx?.assumedRole || '';
|
1004
|
-
parentCtx.authenticatedRoles = pctx?.authenticatedRoles || [];
|
1005
|
-
}
|
1006
|
-
const wfParams = {
|
1007
|
-
parentCtx,
|
1008
|
-
};
|
1009
|
-
// Run the temp workflow way...
|
1010
|
-
if (typeof object === 'function') {
|
1011
|
-
const ops = (0, decorators_1.getRegisteredOperations)(object);
|
1012
|
-
const proxy = {};
|
1013
|
-
for (const op of ops) {
|
1014
|
-
proxy[op.name] = op.txnConfig
|
1015
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.transaction(op.registeredFunction, wfParams, ...args)
|
1016
|
-
: op.stepConfig
|
1017
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.external(op.registeredFunction, wfParams, ...args)
|
1018
|
-
: op.procConfig
|
1019
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.procedure(op.registeredFunction, wfParams, ...args)
|
1020
|
-
: op.workflowConfig
|
1021
|
-
? async (...args) => (await dbos_executor_1.DBOSExecutor.globalInstance.workflow(op.registeredFunction, wfParams, ...args)).getResult()
|
1022
|
-
: (..._args) => {
|
1023
|
-
throw new error_1.DBOSNotRegisteredError(op.name, `${op.name} is not a registered DBOS step, transaction, or procedure`);
|
1024
|
-
};
|
1025
|
-
}
|
1026
|
-
augmentProxy(object, proxy);
|
1027
|
-
return proxy;
|
1028
|
-
}
|
1029
|
-
else {
|
1030
|
-
const targetInst = object;
|
1031
|
-
const ops = (0, decorators_1.getRegisteredOperations)(targetInst);
|
1032
|
-
const proxy = {};
|
1033
|
-
for (const op of ops) {
|
1034
|
-
proxy[op.name] = op.txnConfig
|
1035
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.transaction(op.registeredFunction, { ...wfParams, configuredInstance: targetInst }, ...args)
|
1036
|
-
: op.stepConfig
|
1037
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.external(op.registeredFunction, { ...wfParams, configuredInstance: targetInst }, ...args)
|
1038
|
-
: op.workflowConfig
|
1039
|
-
? async (...args) => (await dbos_executor_1.DBOSExecutor.globalInstance.workflow(op.registeredFunction, { ...wfParams, configuredInstance: targetInst }, ...args)).getResult()
|
1040
|
-
: (..._args) => {
|
1041
|
-
throw new error_1.DBOSNotRegisteredError(op.name, `${op.name} is not a registered DBOS step or transaction`);
|
1042
|
-
};
|
1043
|
-
}
|
1044
|
-
augmentProxy(targetInst, proxy);
|
1045
|
-
return proxy;
|
1046
|
-
}
|
1047
|
-
}
|
1048
|
-
const wfctx = (0, context_1.assertCurrentWorkflowContext)();
|
1049
|
-
if (typeof object === 'function') {
|
1050
|
-
const ops = (0, decorators_1.getRegisteredOperations)(object);
|
1051
|
-
const proxy = {};
|
1052
|
-
for (const op of ops) {
|
1053
|
-
proxy[op.name] = op.txnConfig
|
1054
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(op.registeredFunction, null, wfctx, ...args)
|
1055
|
-
: op.stepConfig
|
1056
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(op.registeredFunction, undefined, undefined, null, wfctx, ...args)
|
1057
|
-
: op.procConfig
|
1058
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(op.registeredFunction, wfctx, ...args)
|
1059
|
-
: (..._args) => {
|
1060
|
-
throw new error_1.DBOSNotRegisteredError(op.name, `${op.name} is not a registered DBOS step, transaction, or procedure`);
|
1061
|
-
};
|
1062
|
-
}
|
1063
|
-
augmentProxy(object, proxy);
|
1064
|
-
return proxy;
|
1065
|
-
}
|
1066
|
-
else {
|
1067
|
-
const targetInst = object;
|
1068
|
-
const ops = (0, decorators_1.getRegisteredOperations)(targetInst);
|
1069
|
-
const proxy = {};
|
1070
|
-
for (const op of ops) {
|
1071
|
-
proxy[op.name] = op.txnConfig
|
1072
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(op.registeredFunction, targetInst, wfctx, ...args)
|
1073
|
-
: op.stepConfig
|
1074
|
-
? (...args) => dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(op.registeredFunction, undefined, undefined, targetInst, wfctx, ...args)
|
1075
|
-
: undefined;
|
1076
|
-
}
|
1077
|
-
augmentProxy(targetInst, proxy);
|
1078
|
-
return proxy;
|
1079
|
-
}
|
1080
|
-
}
|
1081
945
|
/**
|
1082
946
|
* Send `message` on optional `topic` to the workflow with `destinationID`
|
1083
947
|
* This can be done from inside or outside of DBOS workflow functions
|
@@ -1097,9 +961,10 @@ class DBOS {
|
|
1097
961
|
if (idempotencyKey) {
|
1098
962
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.send` with an idempotency key from within a workflow');
|
1099
963
|
}
|
1100
|
-
|
964
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
965
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.send(DBOS.workflowID, functionID, destinationID, utils_1.DBOSJSON.stringify(message), topic);
|
1101
966
|
}
|
1102
|
-
return DBOS.#executor.send(destinationID, message, topic, idempotencyKey);
|
967
|
+
return DBOS.#executor.send(destinationID, message, topic, idempotencyKey); // Temp WF variant
|
1103
968
|
}
|
1104
969
|
/**
|
1105
970
|
* Receive a message on optional `topic` from within a workflow.
|
@@ -1116,9 +981,11 @@ class DBOS {
|
|
1116
981
|
static async recv(topic, timeoutSeconds) {
|
1117
982
|
if (DBOS.isWithinWorkflow()) {
|
1118
983
|
if (!DBOS.isInWorkflow()) {
|
1119
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.
|
984
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.recv` inside a `step` or `transaction`');
|
1120
985
|
}
|
1121
|
-
|
986
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
987
|
+
const timeoutFunctionID = (0, context_1.functionIDGetIncrement)();
|
988
|
+
return utils_1.DBOSJSON.parse(await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.recv(DBOS.workflowID, functionID, timeoutFunctionID, topic, timeoutSeconds));
|
1122
989
|
}
|
1123
990
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `DBOS.recv` outside of a workflow'); // Only workflows can recv
|
1124
991
|
}
|
@@ -1136,7 +1003,8 @@ class DBOS {
|
|
1136
1003
|
if (!DBOS.isInWorkflow()) {
|
1137
1004
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.setEvent` inside a `step` or `transaction`');
|
1138
1005
|
}
|
1139
|
-
|
1006
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
1007
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.setEvent(DBOS.workflowID, functionID, key, utils_1.DBOSJSON.stringify(value));
|
1140
1008
|
}
|
1141
1009
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `DBOS.setEvent` outside of a workflow'); // Only workflows can set event
|
1142
1010
|
}
|
@@ -1157,7 +1025,14 @@ class DBOS {
|
|
1157
1025
|
if (!DBOS.isInWorkflow()) {
|
1158
1026
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.getEvent` inside a `step` or `transaction`');
|
1159
1027
|
}
|
1160
|
-
|
1028
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
1029
|
+
const timeoutFunctionID = (0, context_1.functionIDGetIncrement)();
|
1030
|
+
const params = {
|
1031
|
+
workflowID: DBOS.workflowID,
|
1032
|
+
functionID,
|
1033
|
+
timeoutFunctionID,
|
1034
|
+
};
|
1035
|
+
return utils_1.DBOSJSON.parse(await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.getEvent(workflowID, key, timeoutSeconds ?? dbos_executor_1.DBOSExecutor.defaultNotificationTimeoutSec, params));
|
1161
1036
|
}
|
1162
1037
|
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1163
1038
|
}
|
@@ -1221,46 +1096,39 @@ class DBOS {
|
|
1221
1096
|
if (!DBOS.isInWorkflow()) {
|
1222
1097
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `workflow` function from within a `step` or `transaction`');
|
1223
1098
|
}
|
1224
|
-
const
|
1225
|
-
const
|
1099
|
+
const pctx = (0, context_1.getCurrentContextStore)();
|
1100
|
+
const pwfid = pctx.workflowId;
|
1101
|
+
const funcId = (0, context_1.functionIDGetIncrement)();
|
1226
1102
|
const wfParams = {
|
1227
|
-
workflowUUID: wfId ||
|
1228
|
-
parentCtx: wfctx,
|
1103
|
+
workflowUUID: wfId || pwfid + '-' + funcId,
|
1229
1104
|
configuredInstance: instance,
|
1230
1105
|
queueName,
|
1231
1106
|
timeoutMS,
|
1232
1107
|
// Detach child deadline if a null timeout is configured
|
1233
|
-
deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined :
|
1108
|
+
deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined : pctx?.deadlineEpochMS,
|
1234
1109
|
enqueueOptions: params.enqueueOptions,
|
1235
1110
|
};
|
1236
|
-
return await invokeRegOp(wfParams,
|
1111
|
+
return await invokeRegOp(wfParams, pwfid, funcId);
|
1237
1112
|
}
|
1238
1113
|
else {
|
1239
1114
|
// Else, we setup a parent context that includes all the potential metadata the application could have set in DBOSLocalCtx
|
1240
|
-
let parentCtx = undefined;
|
1241
1115
|
if (pctx) {
|
1242
1116
|
// If pctx has no span, e.g., has not been setup through `withTracedContext`, set up a parent span for the workflow here.
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
parentCtx.request = pctx.request ?? {};
|
1253
|
-
parentCtx.authenticatedUser = pctx.authenticatedUser ?? '';
|
1254
|
-
parentCtx.assumedRole = pctx.assumedRole ?? '';
|
1255
|
-
parentCtx.authenticatedRoles = pctx.authenticatedRoles ?? [];
|
1256
|
-
parentCtx.workflowUUID = wfId ?? '';
|
1117
|
+
pctx.span =
|
1118
|
+
pctx.span ??
|
1119
|
+
DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'workflowCaller', {
|
1120
|
+
operationUUID: wfId,
|
1121
|
+
operationType: pctx.operationType,
|
1122
|
+
authenticatedUser: pctx.authenticatedUser,
|
1123
|
+
assumedRole: pctx.assumedRole,
|
1124
|
+
authenticatedRoles: pctx.authenticatedRoles,
|
1125
|
+
});
|
1257
1126
|
}
|
1258
1127
|
const wfParams = {
|
1259
1128
|
workflowUUID: wfId,
|
1260
1129
|
queueName,
|
1261
1130
|
enqueueOptions: params.enqueueOptions,
|
1262
1131
|
configuredInstance: instance,
|
1263
|
-
parentCtx,
|
1264
1132
|
timeoutMS,
|
1265
1133
|
};
|
1266
1134
|
return await invokeRegOp(wfParams, undefined, undefined);
|
@@ -1321,34 +1189,22 @@ class DBOS {
|
|
1321
1189
|
if (DBOS.isInStep()) {
|
1322
1190
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `transaction` function from within a `step`');
|
1323
1191
|
}
|
1324
|
-
|
1325
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, wfctx, ...rawArgs);
|
1192
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, ...rawArgs);
|
1326
1193
|
}
|
1327
1194
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1328
1195
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1329
|
-
let span = pctx?.span;
|
1330
|
-
if (!span) {
|
1331
|
-
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1332
|
-
operationType: pctx?.operationType,
|
1333
|
-
authenticatedUser: pctx?.authenticatedUser,
|
1334
|
-
assumedRole: pctx?.assumedRole,
|
1335
|
-
authenticatedRoles: pctx?.authenticatedRoles,
|
1336
|
-
});
|
1337
|
-
}
|
1338
|
-
let parentCtx = undefined;
|
1339
1196
|
if (pctx) {
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1197
|
+
pctx.span =
|
1198
|
+
pctx.span ??
|
1199
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1200
|
+
operationType: pctx?.operationType,
|
1201
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1202
|
+
assumedRole: pctx?.assumedRole,
|
1203
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1204
|
+
});
|
1348
1205
|
}
|
1349
1206
|
const wfParams = {
|
1350
1207
|
configuredInstance: inst,
|
1351
|
-
parentCtx,
|
1352
1208
|
workflowUUID: wfId,
|
1353
1209
|
};
|
1354
1210
|
return await DBOS.#executor.transaction(registration.registeredFunction, wfParams, ...rawArgs);
|
@@ -1377,33 +1233,21 @@ class DBOS {
|
|
1377
1233
|
throw new Error('Stored procedures must be static');
|
1378
1234
|
}
|
1379
1235
|
if (DBOS.isWithinWorkflow()) {
|
1380
|
-
|
1381
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, wfctx, ...rawArgs);
|
1236
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, ...rawArgs);
|
1382
1237
|
}
|
1383
1238
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1384
1239
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1385
|
-
let span = pctx?.span;
|
1386
|
-
if (!span) {
|
1387
|
-
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1388
|
-
operationType: pctx?.operationType,
|
1389
|
-
authenticatedUser: pctx?.authenticatedUser,
|
1390
|
-
assumedRole: pctx?.assumedRole,
|
1391
|
-
authenticatedRoles: pctx?.authenticatedRoles,
|
1392
|
-
});
|
1393
|
-
}
|
1394
|
-
let parentCtx = undefined;
|
1395
1240
|
if (pctx) {
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1241
|
+
pctx.span =
|
1242
|
+
pctx.span ??
|
1243
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1244
|
+
operationType: pctx?.operationType,
|
1245
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1246
|
+
assumedRole: pctx?.assumedRole,
|
1247
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1248
|
+
});
|
1404
1249
|
}
|
1405
1250
|
const wfParams = {
|
1406
|
-
parentCtx,
|
1407
1251
|
workflowUUID: wfId,
|
1408
1252
|
};
|
1409
1253
|
return await DBOS.#executor.procedure(registration.registeredFunction, wfParams, ...rawArgs);
|
@@ -1448,34 +1292,22 @@ class DBOS {
|
|
1448
1292
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1449
1293
|
return registration.registeredFunction.call(this, ...rawArgs);
|
1450
1294
|
}
|
1451
|
-
|
1452
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(registration.registeredFunction, undefined, undefined, inst ?? null, wfctx, ...rawArgs);
|
1295
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(registration.registeredFunction, undefined, undefined, inst ?? null, ...rawArgs);
|
1453
1296
|
}
|
1454
1297
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1455
1298
|
const pctx = (0, context_1.getCurrentContextStore)();
|
1456
|
-
let span = pctx?.span;
|
1457
|
-
if (!span) {
|
1458
|
-
span = DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1459
|
-
operationType: pctx?.operationType,
|
1460
|
-
authenticatedUser: pctx?.authenticatedUser,
|
1461
|
-
assumedRole: pctx?.assumedRole,
|
1462
|
-
authenticatedRoles: pctx?.authenticatedRoles,
|
1463
|
-
});
|
1464
|
-
}
|
1465
|
-
let parentCtx = undefined;
|
1466
1299
|
if (pctx) {
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1300
|
+
pctx.span =
|
1301
|
+
pctx.span ??
|
1302
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1303
|
+
operationType: pctx?.operationType,
|
1304
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1305
|
+
assumedRole: pctx?.assumedRole,
|
1306
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1307
|
+
});
|
1475
1308
|
}
|
1476
1309
|
const wfParams = {
|
1477
1310
|
configuredInstance: inst,
|
1478
|
-
parentCtx,
|
1479
1311
|
workflowUUID: wfId,
|
1480
1312
|
};
|
1481
1313
|
return await DBOS.#executor.external(registration.registeredFunction, wfParams, ...rawArgs);
|
@@ -1512,8 +1344,7 @@ class DBOS {
|
|
1512
1344
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1513
1345
|
return func.call(this, ...rawArgs);
|
1514
1346
|
}
|
1515
|
-
|
1516
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, inst ?? null, wfctx, ...rawArgs);
|
1347
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, inst ?? null, ...rawArgs);
|
1517
1348
|
}
|
1518
1349
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1519
1350
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|
@@ -1540,8 +1371,7 @@ class DBOS {
|
|
1540
1371
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1541
1372
|
return func();
|
1542
1373
|
}
|
1543
|
-
|
1544
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, null, wfctx);
|
1374
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, null);
|
1545
1375
|
}
|
1546
1376
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1547
1377
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|