@dbos-inc/dbos-sdk 3.0.23-preview → 3.0.37-preview.gfd7eaf193c
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/context.d.ts +9 -43
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +28 -113
- package/dist/src/context.js.map +1 -1
- package/dist/src/datasource.d.ts +14 -3
- package/dist/src/datasource.d.ts.map +1 -1
- package/dist/src/datasource.js +12 -11
- package/dist/src/datasource.js.map +1 -1
- package/dist/src/dbos-executor.d.ts +37 -79
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +297 -498
- 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-runtime/runtime.d.ts.map +1 -1
- package/dist/src/dbos-runtime/runtime.js +0 -9
- package/dist/src/dbos-runtime/runtime.js.map +1 -1
- package/dist/src/dbos.d.ts +9 -34
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +95 -273
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/decorators.d.ts +35 -60
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +157 -184
- package/dist/src/decorators.js.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 +1 -1
- package/dist/src/httpServer/handler.js.map +1 -1
- package/dist/src/httpServer/server.d.ts.map +1 -1
- package/dist/src/httpServer/server.js +5 -7
- package/dist/src/httpServer/server.js.map +1 -1
- package/dist/src/index.d.ts +5 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -17
- 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 +3 -2
- 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 +1 -2
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.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/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/eventreceiver.d.ts +0 -155
- package/dist/src/eventreceiver.d.ts.map +0 -1
- package/dist/src/eventreceiver.js +0 -3
- package/dist/src/eventreceiver.js.map +0 -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()
|
@@ -277,11 +244,8 @@ class DBOS {
|
|
277
244
|
dbos_executor_1.DBOSExecutor.globalInstance.logRegisteredHTTPUrls();
|
278
245
|
dbos_executor_1.DBOSExecutor.globalInstance.scheduler?.logRegisteredSchedulerEndpoints();
|
279
246
|
wfqueue_1.wfQueueRunner.logRegisteredEndpoints(dbos_executor_1.DBOSExecutor.globalInstance);
|
280
|
-
for (const evtRcvr of dbos_executor_1.DBOSExecutor.globalInstance.eventReceivers) {
|
281
|
-
evtRcvr.logRegisteredEndpoints();
|
282
|
-
}
|
283
247
|
for (const lcl of (0, decorators_1.getLifecycleListeners)()) {
|
284
|
-
lcl.logRegisteredEndpoints();
|
248
|
+
lcl.logRegisteredEndpoints?.();
|
285
249
|
}
|
286
250
|
}
|
287
251
|
/**
|
@@ -395,9 +359,9 @@ class DBOS {
|
|
395
359
|
//////
|
396
360
|
/** Get the current DBOS Logger, appropriate to the current context */
|
397
361
|
static get logger() {
|
398
|
-
const
|
399
|
-
if (
|
400
|
-
return
|
362
|
+
const lctx = (0, context_1.getCurrentContextStore)();
|
363
|
+
if (lctx?.logger)
|
364
|
+
return lctx.logger;
|
401
365
|
const executor = dbos_executor_1.DBOSExecutor.globalInstance;
|
402
366
|
if (executor)
|
403
367
|
return executor.logger;
|
@@ -411,7 +375,7 @@ class DBOS {
|
|
411
375
|
}
|
412
376
|
/** Get the current DBOS tracing span, appropriate to the current context */
|
413
377
|
static get span() {
|
414
|
-
return (0, context_1.
|
378
|
+
return (0, context_1.getCurrentContextStore)()?.span;
|
415
379
|
}
|
416
380
|
/**
|
417
381
|
* Get the current request object (such as an HTTP request)
|
@@ -419,7 +383,7 @@ class DBOS {
|
|
419
383
|
* and set it using `withTracedContext` or `runWithContext`
|
420
384
|
*/
|
421
385
|
static requestObject() {
|
422
|
-
return (0, context_1.
|
386
|
+
return (0, context_1.getCurrentContextStore)()?.request;
|
423
387
|
}
|
424
388
|
/** Get the current HTTP request (within `@DBOS.getApi` et al) */
|
425
389
|
static getRequest() {
|
@@ -445,7 +409,7 @@ class DBOS {
|
|
445
409
|
}
|
446
410
|
/** Get the current workflow ID */
|
447
411
|
static get workflowID() {
|
448
|
-
return (0, context_1.getCurrentContextStore)()?.workflowId
|
412
|
+
return (0, context_1.getCurrentContextStore)()?.workflowId;
|
449
413
|
}
|
450
414
|
/** Get the current step number, within the current workflow */
|
451
415
|
static get stepID() {
|
@@ -464,15 +428,15 @@ class DBOS {
|
|
464
428
|
}
|
465
429
|
/** Get the current authenticated user */
|
466
430
|
static get authenticatedUser() {
|
467
|
-
return (0, context_1.
|
431
|
+
return (0, context_1.getCurrentContextStore)()?.authenticatedUser ?? '';
|
468
432
|
}
|
469
433
|
/** Get the roles granted to the current authenticated user */
|
470
434
|
static get authenticatedRoles() {
|
471
|
-
return (0, context_1.
|
435
|
+
return (0, context_1.getCurrentContextStore)()?.authenticatedRoles ?? [];
|
472
436
|
}
|
473
437
|
/** Get the role assumed by the current user giving authorization to execute the current function */
|
474
438
|
static get assumedRole() {
|
475
|
-
return (0, context_1.
|
439
|
+
return (0, context_1.getCurrentContextStore)()?.assumedRole ?? '';
|
476
440
|
}
|
477
441
|
/** @returns true if called from within a transaction, false otherwise */
|
478
442
|
static isInTransaction() {
|
@@ -504,10 +468,10 @@ class DBOS {
|
|
504
468
|
// sql session (various forms)
|
505
469
|
/** @returns the current SQL client; only allowed within `@DBOS.transaction` functions */
|
506
470
|
static get sqlClient() {
|
507
|
-
|
471
|
+
const c = (0, context_1.getCurrentContextStore)()?.sqlClient;
|
472
|
+
if (!DBOS.isInTransaction() || !c)
|
508
473
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid use of `DBOS.sqlClient` outside of a `transaction`');
|
509
|
-
|
510
|
-
return ctx.client;
|
474
|
+
return c;
|
511
475
|
}
|
512
476
|
/**
|
513
477
|
* @returns the current PG SQL client;
|
@@ -583,11 +547,6 @@ class DBOS {
|
|
583
547
|
* @param defaultValue - value to return if `key` does not exist in the configuration
|
584
548
|
*/
|
585
549
|
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
550
|
if (DBOS.#executor)
|
592
551
|
return DBOS.#executor.getConfig(key, defaultValue);
|
593
552
|
return defaultValue;
|
@@ -653,8 +612,7 @@ class DBOS {
|
|
653
612
|
return DBOS.#executor.getWorkflowStatus(workflowID);
|
654
613
|
}
|
655
614
|
else if (DBOS.isInWorkflow()) {
|
656
|
-
|
657
|
-
return DBOS.#executor.getWorkflowStatus(workflowID, DBOS.workflowID, wfctx.functionIDGetIncrement());
|
615
|
+
return DBOS.#executor.getWorkflowStatus(workflowID, DBOS.workflowID, (0, context_1.functionIDGetIncrement)());
|
658
616
|
}
|
659
617
|
else {
|
660
618
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `getWorkflowStatus` inside a `transaction` or `procedure`');
|
@@ -671,7 +629,7 @@ class DBOS {
|
|
671
629
|
static async getResult(workflowID, timeoutSeconds) {
|
672
630
|
let timerFuncID = undefined;
|
673
631
|
if (DBOS.isWithinWorkflow() && timeoutSeconds !== undefined) {
|
674
|
-
timerFuncID = (0, context_1.
|
632
|
+
timerFuncID = (0, context_1.functionIDGetIncrement)();
|
675
633
|
}
|
676
634
|
return await runInternalStep(async () => {
|
677
635
|
const rres = await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.awaitWorkflowResult(workflowID, timeoutSeconds, DBOS.workflowID, timerFuncID);
|
@@ -695,7 +653,8 @@ class DBOS {
|
|
695
653
|
if (!DBOS.isInWorkflow()) {
|
696
654
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `retrieveWorkflow` inside a `transaction` or `step`');
|
697
655
|
}
|
698
|
-
|
656
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
657
|
+
return new workflow_1.RetrievedHandle(dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase, workflowID, DBOS.workflowID, functionID);
|
699
658
|
}
|
700
659
|
return DBOS.#executor.retrieveWorkflow(workflowID);
|
701
660
|
}
|
@@ -789,7 +748,11 @@ class DBOS {
|
|
789
748
|
if (DBOS.isInTransaction()) {
|
790
749
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.sleep` inside a `transaction`');
|
791
750
|
}
|
792
|
-
|
751
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
752
|
+
if (durationMS <= 0) {
|
753
|
+
return;
|
754
|
+
}
|
755
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.durableSleepms(DBOS.workflowID, functionID, durationMS);
|
793
756
|
}
|
794
757
|
await (0, utils_1.sleepms)(durationMS);
|
795
758
|
}
|
@@ -939,16 +902,7 @@ class DBOS {
|
|
939
902
|
authenticatedRoles: options.authenticatedRoles,
|
940
903
|
});
|
941
904
|
}
|
942
|
-
|
943
|
-
ctx.request = options.request || {};
|
944
|
-
ctx.authenticatedUser = options.authenticatedUser || '';
|
945
|
-
ctx.assumedRole = options.assumedRole || '';
|
946
|
-
ctx.authenticatedRoles = options.authenticatedRoles || [];
|
947
|
-
ctx.workflowUUID = options.idAssignedForNextWorkflow || '';
|
948
|
-
return (0, context_1.runWithTopContext)({
|
949
|
-
...options,
|
950
|
-
ctx,
|
951
|
-
}, callback);
|
905
|
+
return (0, context_1.runWithTopContext)(options, callback);
|
952
906
|
}
|
953
907
|
}
|
954
908
|
static startWorkflow(target, params) {
|
@@ -959,7 +913,7 @@ class DBOS {
|
|
959
913
|
const regOps = (0, decorators_1.getRegisteredOperations)(target);
|
960
914
|
const handler = {
|
961
915
|
apply(target, _thisArg, args) {
|
962
|
-
const regOp = (0, decorators_1.
|
916
|
+
const regOp = (0, decorators_1.getFunctionRegistration)(target);
|
963
917
|
if (!regOp) {
|
964
918
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
965
919
|
const name = typeof target === 'function' ? target.name : target.toString();
|
@@ -970,7 +924,7 @@ class DBOS {
|
|
970
924
|
get(target, p, receiver) {
|
971
925
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
972
926
|
const func = Reflect.get(target, p, receiver);
|
973
|
-
const regOp = (0, decorators_1.
|
927
|
+
const regOp = (0, decorators_1.getFunctionRegistration)(func) ?? regOps.find((op) => op.name === p);
|
974
928
|
if (regOp) {
|
975
929
|
return (...args) => DBOS.#invokeWorkflow(instance, regOp, args, params);
|
976
930
|
}
|
@@ -980,104 +934,6 @@ class DBOS {
|
|
980
934
|
};
|
981
935
|
return new Proxy(target, handler);
|
982
936
|
}
|
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
937
|
/**
|
1082
938
|
* Send `message` on optional `topic` to the workflow with `destinationID`
|
1083
939
|
* This can be done from inside or outside of DBOS workflow functions
|
@@ -1097,9 +953,10 @@ class DBOS {
|
|
1097
953
|
if (idempotencyKey) {
|
1098
954
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.send` with an idempotency key from within a workflow');
|
1099
955
|
}
|
1100
|
-
|
956
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
957
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.send(DBOS.workflowID, functionID, destinationID, utils_1.DBOSJSON.stringify(message), topic);
|
1101
958
|
}
|
1102
|
-
return DBOS.#executor.
|
959
|
+
return DBOS.#executor.runSendTempWF(destinationID, message, topic, idempotencyKey); // Temp WF variant
|
1103
960
|
}
|
1104
961
|
/**
|
1105
962
|
* Receive a message on optional `topic` from within a workflow.
|
@@ -1116,9 +973,11 @@ class DBOS {
|
|
1116
973
|
static async recv(topic, timeoutSeconds) {
|
1117
974
|
if (DBOS.isWithinWorkflow()) {
|
1118
975
|
if (!DBOS.isInWorkflow()) {
|
1119
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.
|
976
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.recv` inside a `step` or `transaction`');
|
1120
977
|
}
|
1121
|
-
|
978
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
979
|
+
const timeoutFunctionID = (0, context_1.functionIDGetIncrement)();
|
980
|
+
return utils_1.DBOSJSON.parse(await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.recv(DBOS.workflowID, functionID, timeoutFunctionID, topic, timeoutSeconds));
|
1122
981
|
}
|
1123
982
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `DBOS.recv` outside of a workflow'); // Only workflows can recv
|
1124
983
|
}
|
@@ -1136,7 +995,8 @@ class DBOS {
|
|
1136
995
|
if (!DBOS.isInWorkflow()) {
|
1137
996
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.setEvent` inside a `step` or `transaction`');
|
1138
997
|
}
|
1139
|
-
|
998
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
999
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.setEvent(DBOS.workflowID, functionID, key, utils_1.DBOSJSON.stringify(value));
|
1140
1000
|
}
|
1141
1001
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `DBOS.setEvent` outside of a workflow'); // Only workflows can set event
|
1142
1002
|
}
|
@@ -1157,7 +1017,14 @@ class DBOS {
|
|
1157
1017
|
if (!DBOS.isInWorkflow()) {
|
1158
1018
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.getEvent` inside a `step` or `transaction`');
|
1159
1019
|
}
|
1160
|
-
|
1020
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
1021
|
+
const timeoutFunctionID = (0, context_1.functionIDGetIncrement)();
|
1022
|
+
const params = {
|
1023
|
+
workflowID: DBOS.workflowID,
|
1024
|
+
functionID,
|
1025
|
+
timeoutFunctionID,
|
1026
|
+
};
|
1027
|
+
return utils_1.DBOSJSON.parse(await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.getEvent(workflowID, key, timeoutSeconds ?? dbos_executor_1.DBOSExecutor.defaultNotificationTimeoutSec, params));
|
1161
1028
|
}
|
1162
1029
|
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1163
1030
|
}
|
@@ -1221,46 +1088,39 @@ class DBOS {
|
|
1221
1088
|
if (!DBOS.isInWorkflow()) {
|
1222
1089
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `workflow` function from within a `step` or `transaction`');
|
1223
1090
|
}
|
1224
|
-
const
|
1225
|
-
const
|
1091
|
+
const pctx = (0, context_1.getCurrentContextStore)();
|
1092
|
+
const pwfid = pctx.workflowId;
|
1093
|
+
const funcId = (0, context_1.functionIDGetIncrement)();
|
1226
1094
|
const wfParams = {
|
1227
|
-
workflowUUID: wfId ||
|
1228
|
-
parentCtx: wfctx,
|
1095
|
+
workflowUUID: wfId || pwfid + '-' + funcId,
|
1229
1096
|
configuredInstance: instance,
|
1230
1097
|
queueName,
|
1231
1098
|
timeoutMS,
|
1232
1099
|
// Detach child deadline if a null timeout is configured
|
1233
|
-
deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined :
|
1100
|
+
deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined : pctx?.deadlineEpochMS,
|
1234
1101
|
enqueueOptions: params.enqueueOptions,
|
1235
1102
|
};
|
1236
|
-
return await invokeRegOp(wfParams,
|
1103
|
+
return await invokeRegOp(wfParams, pwfid, funcId);
|
1237
1104
|
}
|
1238
1105
|
else {
|
1239
1106
|
// Else, we setup a parent context that includes all the potential metadata the application could have set in DBOSLocalCtx
|
1240
|
-
let parentCtx = undefined;
|
1241
1107
|
if (pctx) {
|
1242
1108
|
// 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 ?? '';
|
1109
|
+
pctx.span =
|
1110
|
+
pctx.span ??
|
1111
|
+
DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'workflowCaller', {
|
1112
|
+
operationUUID: wfId,
|
1113
|
+
operationType: pctx.operationType,
|
1114
|
+
authenticatedUser: pctx.authenticatedUser,
|
1115
|
+
assumedRole: pctx.assumedRole,
|
1116
|
+
authenticatedRoles: pctx.authenticatedRoles,
|
1117
|
+
});
|
1257
1118
|
}
|
1258
1119
|
const wfParams = {
|
1259
1120
|
workflowUUID: wfId,
|
1260
1121
|
queueName,
|
1261
1122
|
enqueueOptions: params.enqueueOptions,
|
1262
1123
|
configuredInstance: instance,
|
1263
|
-
parentCtx,
|
1264
1124
|
timeoutMS,
|
1265
1125
|
};
|
1266
1126
|
return await invokeRegOp(wfParams, undefined, undefined);
|
@@ -1321,37 +1181,25 @@ class DBOS {
|
|
1321
1181
|
if (DBOS.isInStep()) {
|
1322
1182
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `transaction` function from within a `step`');
|
1323
1183
|
}
|
1324
|
-
|
1325
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, wfctx, ...rawArgs);
|
1184
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, ...rawArgs);
|
1326
1185
|
}
|
1327
1186
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1328
1187
|
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
1188
|
if (pctx) {
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1189
|
+
pctx.span =
|
1190
|
+
pctx.span ??
|
1191
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1192
|
+
operationType: pctx?.operationType,
|
1193
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1194
|
+
assumedRole: pctx?.assumedRole,
|
1195
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1196
|
+
});
|
1348
1197
|
}
|
1349
1198
|
const wfParams = {
|
1350
1199
|
configuredInstance: inst,
|
1351
|
-
parentCtx,
|
1352
1200
|
workflowUUID: wfId,
|
1353
1201
|
};
|
1354
|
-
return await DBOS.#executor.
|
1202
|
+
return await DBOS.#executor.runTransactionTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1355
1203
|
};
|
1356
1204
|
descriptor.value = invokeWrapper;
|
1357
1205
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1377,36 +1225,24 @@ class DBOS {
|
|
1377
1225
|
throw new Error('Stored procedures must be static');
|
1378
1226
|
}
|
1379
1227
|
if (DBOS.isWithinWorkflow()) {
|
1380
|
-
|
1381
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, wfctx, ...rawArgs);
|
1228
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, ...rawArgs);
|
1382
1229
|
}
|
1383
1230
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1384
1231
|
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
1232
|
if (pctx) {
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1233
|
+
pctx.span =
|
1234
|
+
pctx.span ??
|
1235
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1236
|
+
operationType: pctx?.operationType,
|
1237
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1238
|
+
assumedRole: pctx?.assumedRole,
|
1239
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1240
|
+
});
|
1404
1241
|
}
|
1405
1242
|
const wfParams = {
|
1406
|
-
parentCtx,
|
1407
1243
|
workflowUUID: wfId,
|
1408
1244
|
};
|
1409
|
-
return await DBOS.#executor.
|
1245
|
+
return await DBOS.#executor.runProcedureTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1410
1246
|
};
|
1411
1247
|
descriptor.value = invokeWrapper;
|
1412
1248
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1448,37 +1284,25 @@ class DBOS {
|
|
1448
1284
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1449
1285
|
return registration.registeredFunction.call(this, ...rawArgs);
|
1450
1286
|
}
|
1451
|
-
|
1452
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(registration.registeredFunction, undefined, undefined, inst ?? null, wfctx, ...rawArgs);
|
1287
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(registration.registeredFunction, undefined, undefined, inst ?? null, ...rawArgs);
|
1453
1288
|
}
|
1454
1289
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1455
1290
|
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
1291
|
if (pctx) {
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1292
|
+
pctx.span =
|
1293
|
+
pctx.span ??
|
1294
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1295
|
+
operationType: pctx?.operationType,
|
1296
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1297
|
+
assumedRole: pctx?.assumedRole,
|
1298
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1299
|
+
});
|
1475
1300
|
}
|
1476
1301
|
const wfParams = {
|
1477
1302
|
configuredInstance: inst,
|
1478
|
-
parentCtx,
|
1479
1303
|
workflowUUID: wfId,
|
1480
1304
|
};
|
1481
|
-
return await DBOS.#executor.
|
1305
|
+
return await DBOS.#executor.runStepTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1482
1306
|
};
|
1483
1307
|
descriptor.value = invokeWrapper;
|
1484
1308
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1512,8 +1336,7 @@ class DBOS {
|
|
1512
1336
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1513
1337
|
return func.call(this, ...rawArgs);
|
1514
1338
|
}
|
1515
|
-
|
1516
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, inst ?? null, wfctx, ...rawArgs);
|
1339
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, inst ?? null, ...rawArgs);
|
1517
1340
|
}
|
1518
1341
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1519
1342
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|
@@ -1540,8 +1363,7 @@ class DBOS {
|
|
1540
1363
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1541
1364
|
return func();
|
1542
1365
|
}
|
1543
|
-
|
1544
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, null, wfctx);
|
1366
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, null);
|
1545
1367
|
}
|
1546
1368
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1547
1369
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|