@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.
Files changed (88) 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/client.d.ts.map +1 -1
  6. package/dist/src/client.js.map +1 -1
  7. package/dist/src/context.d.ts +10 -44
  8. package/dist/src/context.d.ts.map +1 -1
  9. package/dist/src/context.js +34 -114
  10. package/dist/src/context.js.map +1 -1
  11. package/dist/src/datasource.d.ts +14 -3
  12. package/dist/src/datasource.d.ts.map +1 -1
  13. package/dist/src/datasource.js +41 -18
  14. package/dist/src/datasource.js.map +1 -1
  15. package/dist/src/dbos-executor.d.ts +43 -84
  16. package/dist/src/dbos-executor.d.ts.map +1 -1
  17. package/dist/src/dbos-executor.js +313 -500
  18. package/dist/src/dbos-executor.js.map +1 -1
  19. package/dist/src/dbos-runtime/cli.d.ts.map +1 -1
  20. package/dist/src/dbos-runtime/cli.js +1 -3
  21. package/dist/src/dbos-runtime/cli.js.map +1 -1
  22. package/dist/src/dbos-runtime/debug.d.ts +1 -1
  23. package/dist/src/dbos-runtime/debug.d.ts.map +1 -1
  24. package/dist/src/dbos-runtime/debug.js +2 -3
  25. package/dist/src/dbos-runtime/debug.js.map +1 -1
  26. package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
  27. package/dist/src/dbos-runtime/runtime.js +0 -9
  28. package/dist/src/dbos-runtime/runtime.js.map +1 -1
  29. package/dist/src/dbos.d.ts +11 -42
  30. package/dist/src/dbos.d.ts.map +1 -1
  31. package/dist/src/dbos.js +103 -284
  32. package/dist/src/dbos.js.map +1 -1
  33. package/dist/src/decorators.d.ts +33 -60
  34. package/dist/src/decorators.d.ts.map +1 -1
  35. package/dist/src/decorators.js +154 -190
  36. package/dist/src/decorators.js.map +1 -1
  37. package/dist/src/httpServer/handler.d.ts +1 -9
  38. package/dist/src/httpServer/handler.d.ts.map +1 -1
  39. package/dist/src/httpServer/handler.js +1 -1
  40. package/dist/src/httpServer/handler.js.map +1 -1
  41. package/dist/src/httpServer/middleware.d.ts +2 -2
  42. package/dist/src/httpServer/middleware.d.ts.map +1 -1
  43. package/dist/src/httpServer/server.d.ts +3 -3
  44. package/dist/src/httpServer/server.d.ts.map +1 -1
  45. package/dist/src/httpServer/server.js +23 -24
  46. package/dist/src/httpServer/server.js.map +1 -1
  47. package/dist/src/index.d.ts +5 -8
  48. package/dist/src/index.d.ts.map +1 -1
  49. package/dist/src/index.js +7 -17
  50. package/dist/src/index.js.map +1 -1
  51. package/dist/src/paramdecorators.d.ts.map +1 -1
  52. package/dist/src/paramdecorators.js +0 -6
  53. package/dist/src/paramdecorators.js.map +1 -1
  54. package/dist/src/procedure.d.ts +0 -22
  55. package/dist/src/procedure.d.ts.map +1 -1
  56. package/dist/src/procedure.js +0 -16
  57. package/dist/src/procedure.js.map +1 -1
  58. package/dist/src/scheduler/scheduler.d.ts.map +1 -1
  59. package/dist/src/scheduler/scheduler.js +3 -2
  60. package/dist/src/scheduler/scheduler.js.map +1 -1
  61. package/dist/src/step.d.ts +0 -25
  62. package/dist/src/step.d.ts.map +1 -1
  63. package/dist/src/step.js +0 -20
  64. package/dist/src/step.js.map +1 -1
  65. package/dist/src/system_database.d.ts +9 -10
  66. package/dist/src/system_database.d.ts.map +1 -1
  67. package/dist/src/system_database.js.map +1 -1
  68. package/dist/src/telemetry/logs.d.ts +4 -8
  69. package/dist/src/telemetry/logs.d.ts.map +1 -1
  70. package/dist/src/telemetry/logs.js +25 -13
  71. package/dist/src/telemetry/logs.js.map +1 -1
  72. package/dist/src/transaction.d.ts +0 -25
  73. package/dist/src/transaction.d.ts.map +1 -1
  74. package/dist/src/transaction.js +1 -15
  75. package/dist/src/transaction.js.map +1 -1
  76. package/dist/src/user_database.d.ts +2 -2
  77. package/dist/src/user_database.d.ts.map +1 -1
  78. package/dist/src/user_database.js.map +1 -1
  79. package/dist/src/workflow.d.ts +4 -148
  80. package/dist/src/workflow.d.ts.map +1 -1
  81. package/dist/src/workflow.js +7 -226
  82. package/dist/src/workflow.js.map +1 -1
  83. package/dist/tsconfig.tsbuildinfo +1 -1
  84. package/package.json +1 -1
  85. package/dist/src/eventreceiver.d.ts +0 -155
  86. package/dist/src/eventreceiver.d.ts.map +0 -1
  87. package/dist/src/eventreceiver.js +0 -3
  88. 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
  }
@@ -929,9 +892,9 @@ class DBOS {
929
892
  }
930
893
  }
931
894
  else {
932
- let span = options.span;
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
- 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
+ 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.getRegistrationForFunction)(target);
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.getRegistrationForFunction)(func) ?? regOps.find((op) => op.name === p);
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
- return (0, context_1.getCurrentDBOSContext)().send(destinationID, message, topic);
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.send(destinationID, message, topic, idempotencyKey);
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.setEvent` inside a `step` or `transaction`');
981
+ throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to `DBOS.recv` inside a `step` or `transaction`');
1120
982
  }
1121
- return (0, context_1.getCurrentDBOSContext)().recv(topic, timeoutSeconds);
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
- return (0, context_1.getCurrentDBOSContext)().setEvent(key, value);
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
- return (0, context_1.getCurrentDBOSContext)().getEvent(workflowID, key, timeoutSeconds);
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 wfctx = (0, context_1.assertCurrentWorkflowContext)();
1225
- const funcId = wfctx.functionIDGetIncrement();
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 || wfctx.workflowUUID + '-' + funcId,
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 : wfctx.deadlineEpochMS,
1105
+ deadlineEpochMS: params.timeoutMS === null || pctx?.workflowTimeoutMS === null ? undefined : pctx?.deadlineEpochMS,
1234
1106
  enqueueOptions: params.enqueueOptions,
1235
1107
  };
1236
- return await invokeRegOp(wfParams, wfctx.workflowUUID, funcId);
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
- 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 ?? '';
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- 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 || [];
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.transaction(registration.registeredFunction, wfParams, ...rawArgs);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- 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 || [];
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.procedure(registration.registeredFunction, wfParams, ...rawArgs);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- 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 || [];
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.external(registration.registeredFunction, wfParams, ...rawArgs);
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
- const wfctx = (0, context_1.assertCurrentWorkflowContext)();
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
  */