@dbos-inc/dbos-sdk 3.0.23-preview → 3.0.29-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 +14 -3
- package/dist/src/datasource.d.ts.map +1 -1
- package/dist/src/datasource.js +41 -18
- package/dist/src/datasource.js.map +1 -1
- package/dist/src/dbos-executor.d.ts +43 -84
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +313 -500
- 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 +11 -42
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +103 -284
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/decorators.d.ts +33 -60
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +154 -190
- 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/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 +23 -24
- 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 +9 -10
- 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/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
|
}
|
@@ -929,9 +892,9 @@ class DBOS {
|
|
929
892
|
}
|
930
893
|
}
|
931
894
|
else {
|
932
|
-
|
933
|
-
if (!span) {
|
934
|
-
span = DBOS.#executor.tracer.startSpan('topContext', {
|
895
|
+
const span = options.span;
|
896
|
+
if (!options.span) {
|
897
|
+
options.span = DBOS.#executor.tracer.startSpan('topContext', {
|
935
898
|
operationUUID: options.idAssignedForNextWorkflow,
|
936
899
|
operationType: options.operationType,
|
937
900
|
authenticatedUser: options.authenticatedUser,
|
@@ -939,16 +902,12 @@ class DBOS {
|
|
939
902
|
authenticatedRoles: options.authenticatedRoles,
|
940
903
|
});
|
941
904
|
}
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
return (0, context_1.runWithTopContext)({
|
949
|
-
...options,
|
950
|
-
ctx,
|
951
|
-
}, callback);
|
905
|
+
try {
|
906
|
+
return await (0, context_1.runWithTopContext)(options, callback);
|
907
|
+
}
|
908
|
+
finally {
|
909
|
+
options.span = span;
|
910
|
+
}
|
952
911
|
}
|
953
912
|
}
|
954
913
|
static startWorkflow(target, params) {
|
@@ -959,7 +918,7 @@ class DBOS {
|
|
959
918
|
const regOps = (0, decorators_1.getRegisteredOperations)(target);
|
960
919
|
const handler = {
|
961
920
|
apply(target, _thisArg, args) {
|
962
|
-
const regOp = (0, decorators_1.
|
921
|
+
const regOp = (0, decorators_1.getFunctionRegistration)(target);
|
963
922
|
if (!regOp) {
|
964
923
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
965
924
|
const name = typeof target === 'function' ? target.name : target.toString();
|
@@ -970,7 +929,7 @@ class DBOS {
|
|
970
929
|
get(target, p, receiver) {
|
971
930
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
972
931
|
const func = Reflect.get(target, p, receiver);
|
973
|
-
const regOp = (0, decorators_1.
|
932
|
+
const regOp = (0, decorators_1.getFunctionRegistration)(func) ?? regOps.find((op) => op.name === p);
|
974
933
|
if (regOp) {
|
975
934
|
return (...args) => DBOS.#invokeWorkflow(instance, regOp, args, params);
|
976
935
|
}
|
@@ -980,104 +939,6 @@ class DBOS {
|
|
980
939
|
};
|
981
940
|
return new Proxy(target, handler);
|
982
941
|
}
|
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
942
|
/**
|
1082
943
|
* Send `message` on optional `topic` to the workflow with `destinationID`
|
1083
944
|
* This can be done from inside or outside of DBOS workflow functions
|
@@ -1097,9 +958,10 @@ class DBOS {
|
|
1097
958
|
if (idempotencyKey) {
|
1098
959
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.send` with an idempotency key from within a workflow');
|
1099
960
|
}
|
1100
|
-
|
961
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
962
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.send(DBOS.workflowID, functionID, destinationID, utils_1.DBOSJSON.stringify(message), topic);
|
1101
963
|
}
|
1102
|
-
return DBOS.#executor.
|
964
|
+
return DBOS.#executor.runSendTempWF(destinationID, message, topic, idempotencyKey); // Temp WF variant
|
1103
965
|
}
|
1104
966
|
/**
|
1105
967
|
* Receive a message on optional `topic` from within a workflow.
|
@@ -1116,9 +978,11 @@ class DBOS {
|
|
1116
978
|
static async recv(topic, timeoutSeconds) {
|
1117
979
|
if (DBOS.isWithinWorkflow()) {
|
1118
980
|
if (!DBOS.isInWorkflow()) {
|
1119
|
-
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.
|
981
|
+
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.recv` inside a `step` or `transaction`');
|
1120
982
|
}
|
1121
|
-
|
983
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
984
|
+
const timeoutFunctionID = (0, context_1.functionIDGetIncrement)();
|
985
|
+
return utils_1.DBOSJSON.parse(await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.recv(DBOS.workflowID, functionID, timeoutFunctionID, topic, timeoutSeconds));
|
1122
986
|
}
|
1123
987
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `DBOS.recv` outside of a workflow'); // Only workflows can recv
|
1124
988
|
}
|
@@ -1136,7 +1000,8 @@ class DBOS {
|
|
1136
1000
|
if (!DBOS.isInWorkflow()) {
|
1137
1001
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.setEvent` inside a `step` or `transaction`');
|
1138
1002
|
}
|
1139
|
-
|
1003
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
1004
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.setEvent(DBOS.workflowID, functionID, key, utils_1.DBOSJSON.stringify(value));
|
1140
1005
|
}
|
1141
1006
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Attempt to call `DBOS.setEvent` outside of a workflow'); // Only workflows can set event
|
1142
1007
|
}
|
@@ -1157,7 +1022,14 @@ class DBOS {
|
|
1157
1022
|
if (!DBOS.isInWorkflow()) {
|
1158
1023
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.getEvent` inside a `step` or `transaction`');
|
1159
1024
|
}
|
1160
|
-
|
1025
|
+
const functionID = (0, context_1.functionIDGetIncrement)();
|
1026
|
+
const timeoutFunctionID = (0, context_1.functionIDGetIncrement)();
|
1027
|
+
const params = {
|
1028
|
+
workflowID: DBOS.workflowID,
|
1029
|
+
functionID,
|
1030
|
+
timeoutFunctionID,
|
1031
|
+
};
|
1032
|
+
return utils_1.DBOSJSON.parse(await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.getEvent(workflowID, key, timeoutSeconds ?? dbos_executor_1.DBOSExecutor.defaultNotificationTimeoutSec, params));
|
1161
1033
|
}
|
1162
1034
|
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1163
1035
|
}
|
@@ -1221,46 +1093,39 @@ class DBOS {
|
|
1221
1093
|
if (!DBOS.isInWorkflow()) {
|
1222
1094
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `workflow` function from within a `step` or `transaction`');
|
1223
1095
|
}
|
1224
|
-
const
|
1225
|
-
const
|
1096
|
+
const pctx = (0, context_1.getCurrentContextStore)();
|
1097
|
+
const pwfid = pctx.workflowId;
|
1098
|
+
const funcId = (0, context_1.functionIDGetIncrement)();
|
1226
1099
|
const wfParams = {
|
1227
|
-
workflowUUID: wfId ||
|
1228
|
-
parentCtx: wfctx,
|
1100
|
+
workflowUUID: wfId || pwfid + '-' + funcId,
|
1229
1101
|
configuredInstance: instance,
|
1230
1102
|
queueName,
|
1231
1103
|
timeoutMS,
|
1232
1104
|
// Detach child deadline if a null timeout is configured
|
1233
|
-
deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined :
|
1105
|
+
deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined : pctx?.deadlineEpochMS,
|
1234
1106
|
enqueueOptions: params.enqueueOptions,
|
1235
1107
|
};
|
1236
|
-
return await invokeRegOp(wfParams,
|
1108
|
+
return await invokeRegOp(wfParams, pwfid, funcId);
|
1237
1109
|
}
|
1238
1110
|
else {
|
1239
1111
|
// Else, we setup a parent context that includes all the potential metadata the application could have set in DBOSLocalCtx
|
1240
|
-
let parentCtx = undefined;
|
1241
1112
|
if (pctx) {
|
1242
1113
|
// 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 ?? '';
|
1114
|
+
pctx.span =
|
1115
|
+
pctx.span ??
|
1116
|
+
DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'workflowCaller', {
|
1117
|
+
operationUUID: wfId,
|
1118
|
+
operationType: pctx.operationType,
|
1119
|
+
authenticatedUser: pctx.authenticatedUser,
|
1120
|
+
assumedRole: pctx.assumedRole,
|
1121
|
+
authenticatedRoles: pctx.authenticatedRoles,
|
1122
|
+
});
|
1257
1123
|
}
|
1258
1124
|
const wfParams = {
|
1259
1125
|
workflowUUID: wfId,
|
1260
1126
|
queueName,
|
1261
1127
|
enqueueOptions: params.enqueueOptions,
|
1262
1128
|
configuredInstance: instance,
|
1263
|
-
parentCtx,
|
1264
1129
|
timeoutMS,
|
1265
1130
|
};
|
1266
1131
|
return await invokeRegOp(wfParams, undefined, undefined);
|
@@ -1321,37 +1186,25 @@ class DBOS {
|
|
1321
1186
|
if (DBOS.isInStep()) {
|
1322
1187
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `transaction` function from within a `step`');
|
1323
1188
|
}
|
1324
|
-
|
1325
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, wfctx, ...rawArgs);
|
1189
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callTransactionFunction(registration.registeredFunction, inst ?? null, ...rawArgs);
|
1326
1190
|
}
|
1327
1191
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1328
1192
|
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
1193
|
if (pctx) {
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1194
|
+
pctx.span =
|
1195
|
+
pctx.span ??
|
1196
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1197
|
+
operationType: pctx?.operationType,
|
1198
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1199
|
+
assumedRole: pctx?.assumedRole,
|
1200
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1201
|
+
});
|
1348
1202
|
}
|
1349
1203
|
const wfParams = {
|
1350
1204
|
configuredInstance: inst,
|
1351
|
-
parentCtx,
|
1352
1205
|
workflowUUID: wfId,
|
1353
1206
|
};
|
1354
|
-
return await DBOS.#executor.
|
1207
|
+
return await DBOS.#executor.runTransactionTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1355
1208
|
};
|
1356
1209
|
descriptor.value = invokeWrapper;
|
1357
1210
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1377,36 +1230,24 @@ class DBOS {
|
|
1377
1230
|
throw new Error('Stored procedures must be static');
|
1378
1231
|
}
|
1379
1232
|
if (DBOS.isWithinWorkflow()) {
|
1380
|
-
|
1381
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, wfctx, ...rawArgs);
|
1233
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callProcedureFunction(registration.registeredFunction, ...rawArgs);
|
1382
1234
|
}
|
1383
1235
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1384
1236
|
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
1237
|
if (pctx) {
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1238
|
+
pctx.span =
|
1239
|
+
pctx.span ??
|
1240
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1241
|
+
operationType: pctx?.operationType,
|
1242
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1243
|
+
assumedRole: pctx?.assumedRole,
|
1244
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1245
|
+
});
|
1404
1246
|
}
|
1405
1247
|
const wfParams = {
|
1406
|
-
parentCtx,
|
1407
1248
|
workflowUUID: wfId,
|
1408
1249
|
};
|
1409
|
-
return await DBOS.#executor.
|
1250
|
+
return await DBOS.#executor.runProcedureTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1410
1251
|
};
|
1411
1252
|
descriptor.value = invokeWrapper;
|
1412
1253
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1448,37 +1289,25 @@ class DBOS {
|
|
1448
1289
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1449
1290
|
return registration.registeredFunction.call(this, ...rawArgs);
|
1450
1291
|
}
|
1451
|
-
|
1452
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(registration.registeredFunction, undefined, undefined, inst ?? null, wfctx, ...rawArgs);
|
1292
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(registration.registeredFunction, undefined, undefined, inst ?? null, ...rawArgs);
|
1453
1293
|
}
|
1454
1294
|
const wfId = (0, context_1.getNextWFID)(undefined);
|
1455
1295
|
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
1296
|
if (pctx) {
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1297
|
+
pctx.span =
|
1298
|
+
pctx.span ??
|
1299
|
+
DBOS.#executor.tracer.startSpan(pctx?.operationCaller || 'transactionCaller', {
|
1300
|
+
operationType: pctx?.operationType,
|
1301
|
+
authenticatedUser: pctx?.authenticatedUser,
|
1302
|
+
assumedRole: pctx?.assumedRole,
|
1303
|
+
authenticatedRoles: pctx?.authenticatedRoles,
|
1304
|
+
});
|
1475
1305
|
}
|
1476
1306
|
const wfParams = {
|
1477
1307
|
configuredInstance: inst,
|
1478
|
-
parentCtx,
|
1479
1308
|
workflowUUID: wfId,
|
1480
1309
|
};
|
1481
|
-
return await DBOS.#executor.
|
1310
|
+
return await DBOS.#executor.runStepTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1482
1311
|
};
|
1483
1312
|
descriptor.value = invokeWrapper;
|
1484
1313
|
registration.wrappedFunction = invokeWrapper;
|
@@ -1512,8 +1341,7 @@ class DBOS {
|
|
1512
1341
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1513
1342
|
return func.call(this, ...rawArgs);
|
1514
1343
|
}
|
1515
|
-
|
1516
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, inst ?? null, wfctx, ...rawArgs);
|
1344
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, inst ?? null, ...rawArgs);
|
1517
1345
|
}
|
1518
1346
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1519
1347
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|
@@ -1540,8 +1368,7 @@ class DBOS {
|
|
1540
1368
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1541
1369
|
return func();
|
1542
1370
|
}
|
1543
|
-
|
1544
|
-
return dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, null, wfctx);
|
1371
|
+
return dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(func, name, config, null);
|
1545
1372
|
}
|
1546
1373
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1547
1374
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|
@@ -1600,14 +1427,6 @@ class DBOS {
|
|
1600
1427
|
/////
|
1601
1428
|
// Registration, etc
|
1602
1429
|
/////
|
1603
|
-
/**
|
1604
|
-
* Construct and register an object.
|
1605
|
-
* Calling this is not necessary; calling the constructor of any `ConfiguredInstance` subclass is sufficient
|
1606
|
-
* @deprecated Use `new` directly
|
1607
|
-
*/
|
1608
|
-
static configureInstance(cls, name, ...args) {
|
1609
|
-
return (0, decorators_1.configureInstance)(cls, name, ...args);
|
1610
|
-
}
|
1611
1430
|
/**
|
1612
1431
|
* Register a lifecycle listener
|
1613
1432
|
*/
|