@dbos-inc/dbos-sdk 3.0.20-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.
Files changed (83) hide show
  1. package/dist/src/authdecorators.d.ts +0 -7
  2. package/dist/src/authdecorators.d.ts.map +1 -1
  3. package/dist/src/authdecorators.js +1 -29
  4. package/dist/src/authdecorators.js.map +1 -1
  5. package/dist/src/conductor/conductor.d.ts.map +1 -1
  6. package/dist/src/conductor/conductor.js +3 -0
  7. package/dist/src/conductor/conductor.js.map +1 -1
  8. package/dist/src/conductor/protocol.d.ts +3 -0
  9. package/dist/src/conductor/protocol.d.ts.map +1 -1
  10. package/dist/src/conductor/protocol.js.map +1 -1
  11. package/dist/src/context.d.ts +9 -43
  12. package/dist/src/context.d.ts.map +1 -1
  13. package/dist/src/context.js +28 -113
  14. package/dist/src/context.js.map +1 -1
  15. package/dist/src/datasource.d.ts +14 -3
  16. package/dist/src/datasource.d.ts.map +1 -1
  17. package/dist/src/datasource.js +12 -11
  18. package/dist/src/datasource.js.map +1 -1
  19. package/dist/src/dbos-executor.d.ts +37 -79
  20. package/dist/src/dbos-executor.d.ts.map +1 -1
  21. package/dist/src/dbos-executor.js +297 -498
  22. package/dist/src/dbos-executor.js.map +1 -1
  23. package/dist/src/dbos-runtime/cli.d.ts.map +1 -1
  24. package/dist/src/dbos-runtime/cli.js +1 -3
  25. package/dist/src/dbos-runtime/cli.js.map +1 -1
  26. package/dist/src/dbos-runtime/debug.d.ts +1 -1
  27. package/dist/src/dbos-runtime/debug.d.ts.map +1 -1
  28. package/dist/src/dbos-runtime/debug.js +2 -3
  29. package/dist/src/dbos-runtime/debug.js.map +1 -1
  30. package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
  31. package/dist/src/dbos-runtime/runtime.js +0 -9
  32. package/dist/src/dbos-runtime/runtime.js.map +1 -1
  33. package/dist/src/dbos.d.ts +9 -34
  34. package/dist/src/dbos.d.ts.map +1 -1
  35. package/dist/src/dbos.js +95 -273
  36. package/dist/src/dbos.js.map +1 -1
  37. package/dist/src/decorators.d.ts +35 -60
  38. package/dist/src/decorators.d.ts.map +1 -1
  39. package/dist/src/decorators.js +157 -184
  40. package/dist/src/decorators.js.map +1 -1
  41. package/dist/src/httpServer/handler.d.ts +1 -9
  42. package/dist/src/httpServer/handler.d.ts.map +1 -1
  43. package/dist/src/httpServer/handler.js +1 -1
  44. package/dist/src/httpServer/handler.js.map +1 -1
  45. package/dist/src/httpServer/server.d.ts.map +1 -1
  46. package/dist/src/httpServer/server.js +8 -7
  47. package/dist/src/httpServer/server.js.map +1 -1
  48. package/dist/src/index.d.ts +5 -8
  49. package/dist/src/index.d.ts.map +1 -1
  50. package/dist/src/index.js +7 -17
  51. package/dist/src/index.js.map +1 -1
  52. package/dist/src/paramdecorators.d.ts.map +1 -1
  53. package/dist/src/paramdecorators.js +0 -6
  54. package/dist/src/paramdecorators.js.map +1 -1
  55. package/dist/src/procedure.d.ts +0 -22
  56. package/dist/src/procedure.d.ts.map +1 -1
  57. package/dist/src/procedure.js +0 -16
  58. package/dist/src/procedure.js.map +1 -1
  59. package/dist/src/scheduler/scheduler.d.ts.map +1 -1
  60. package/dist/src/scheduler/scheduler.js +3 -2
  61. package/dist/src/scheduler/scheduler.js.map +1 -1
  62. package/dist/src/step.d.ts +0 -25
  63. package/dist/src/step.d.ts.map +1 -1
  64. package/dist/src/step.js +0 -20
  65. package/dist/src/step.js.map +1 -1
  66. package/dist/src/system_database.d.ts +2 -3
  67. package/dist/src/system_database.d.ts.map +1 -1
  68. package/dist/src/system_database.js +56 -3
  69. package/dist/src/system_database.js.map +1 -1
  70. package/dist/src/transaction.d.ts +0 -25
  71. package/dist/src/transaction.d.ts.map +1 -1
  72. package/dist/src/transaction.js +1 -15
  73. package/dist/src/transaction.js.map +1 -1
  74. package/dist/src/workflow.d.ts +7 -148
  75. package/dist/src/workflow.d.ts.map +1 -1
  76. package/dist/src/workflow.js +7 -226
  77. package/dist/src/workflow.js.map +1 -1
  78. package/dist/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +2 -2
  80. package/dist/src/eventreceiver.d.ts +0 -155
  81. package/dist/src/eventreceiver.d.ts.map +0 -1
  82. package/dist/src/eventreceiver.js +0 -3
  83. 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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- const isDebugging = debugWorkflowId !== undefined;
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 isDebugging = DBOS.getDebugModeFromEnv() !== dbos_executor_1.DebugMode.DISABLED;
114
- [DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.translatePublicDBOSconfig)(DBOS.#dbosConfig, isDebugging);
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: isDebugging });
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 ctx = (0, context_1.getCurrentDBOSContext)();
399
- if (ctx)
400
- return ctx.logger;
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.getCurrentDBOSContext)()?.span ?? (0, context_1.getCurrentContextStore)()?.span;
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.getCurrentDBOSContext)()?.request ?? (0, context_1.getCurrentContextStore)()?.request;
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 ?? (0, context_1.getCurrentDBOSContext)()?.workflowUUID;
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.getCurrentDBOSContext)()?.authenticatedUser ?? (0, context_1.getCurrentContextStore)()?.authenticatedUser ?? '';
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.getCurrentDBOSContext)()?.authenticatedRoles ?? (0, context_1.getCurrentContextStore)()?.authenticatedRoles ?? [];
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.getCurrentDBOSContext)()?.assumedRole ?? (0, context_1.getCurrentContextStore)()?.assumedRole ?? '';
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
- if (!DBOS.isInTransaction())
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
- const ctx = (0, context_1.assertCurrentDBOSContext)();
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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.assertCurrentWorkflowContext)().functionIDGetIncrement();
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
- return (0, context_1.getCurrentDBOSContext)().retrieveWorkflow(workflowID);
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
- return (0, context_1.getCurrentDBOSContext)().sleepms(durationMS);
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
- const ctx = new context_1.DBOSContextImpl(options.operationCaller || 'topContext', span, DBOS.logger);
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.getRegistrationForFunction)(target);
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.getRegistrationForFunction)(func) ?? regOps.find((op) => op.name === p);
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
- return (0, context_1.getCurrentDBOSContext)().send(destinationID, message, topic);
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.send(destinationID, message, topic, idempotencyKey);
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.setEvent` inside a `step` or `transaction`');
976
+ throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.recv` inside a `step` or `transaction`');
1120
977
  }
1121
- return (0, context_1.getCurrentDBOSContext)().recv(topic, timeoutSeconds);
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
- return (0, context_1.getCurrentDBOSContext)().setEvent(key, value);
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
- return (0, context_1.getCurrentDBOSContext)().getEvent(workflowID, key, timeoutSeconds);
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 wfctx = (0, context_1.assertCurrentWorkflowContext)();
1225
- const funcId = wfctx.functionIDGetIncrement();
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 || wfctx.workflowUUID + '-' + funcId,
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 : wfctx.deadlineEpochMS,
1100
+ deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined : pctx?.deadlineEpochMS,
1234
1101
  enqueueOptions: params.enqueueOptions,
1235
1102
  };
1236
- return await invokeRegOp(wfParams, wfctx.workflowUUID, funcId);
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
- const span = pctx.span ??
1244
- DBOS.#executor.tracer.startSpan(pctx.operationCaller || 'workflowCaller', {
1245
- operationUUID: wfId,
1246
- operationType: pctx.operationType,
1247
- authenticatedUser: pctx.authenticatedUser,
1248
- assumedRole: pctx.assumedRole,
1249
- authenticatedRoles: pctx.authenticatedRoles,
1250
- });
1251
- parentCtx = new context_1.DBOSContextImpl(pctx.operationCaller || 'workflowCaller', span, DBOS.logger);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- parentCtx = pctx.ctx;
1341
- }
1342
- if (!parentCtx) {
1343
- parentCtx = new context_1.DBOSContextImpl(pctx?.operationCaller || 'workflowCaller', span, DBOS.logger);
1344
- parentCtx.request = pctx?.request || {};
1345
- parentCtx.authenticatedUser = pctx?.authenticatedUser || '';
1346
- parentCtx.assumedRole = pctx?.assumedRole || '';
1347
- parentCtx.authenticatedRoles = pctx?.authenticatedRoles || [];
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.transaction(registration.registeredFunction, wfParams, ...rawArgs);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- parentCtx = pctx.ctx;
1397
- }
1398
- if (!parentCtx) {
1399
- parentCtx = new context_1.DBOSContextImpl(pctx?.operationCaller || 'workflowCaller', span, DBOS.logger);
1400
- parentCtx.request = pctx?.request || {};
1401
- parentCtx.authenticatedUser = pctx?.authenticatedUser || '';
1402
- parentCtx.assumedRole = pctx?.assumedRole || '';
1403
- parentCtx.authenticatedRoles = pctx?.authenticatedRoles || [];
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.procedure(registration.registeredFunction, wfParams, ...rawArgs);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- parentCtx = pctx.ctx;
1468
- }
1469
- if (!parentCtx) {
1470
- parentCtx = new context_1.DBOSContextImpl(pctx?.operationCaller || 'workflowCaller', span, DBOS.logger);
1471
- parentCtx.request = pctx?.request || {};
1472
- parentCtx.authenticatedUser = pctx?.authenticatedUser || '';
1473
- parentCtx.assumedRole = pctx?.assumedRole || '';
1474
- parentCtx.authenticatedRoles = pctx?.authenticatedRoles || [];
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.external(registration.registeredFunction, wfParams, ...rawArgs);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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.`);