@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
@@ -1,56 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DBOSInitializer = exports.OrmEntities = exports.configureInstance = exports.ArgName = exports.getRegistrationsForExternal = exports.associateParameterWithExternal = exports.associateMethodWithExternal = exports.associateMethodWithEventReceiver = exports.associateClassWithExternal = exports.associateClassWithEventReceiver = exports.getOrCreateClassRegistration = exports.getClassRegistrationByName = exports.getAllRegisteredClassNames = exports.getNameForClass = exports.registerAndWrapDBOSFunctionByName = exports.registerAndWrapDBOSFunction = exports.getOrCreateMethodArgsRegistration = exports.getTransactionalDataSource = exports.registerTransactionalDataSource = exports.transactionalDataSources = exports.getConfiguredInstance = exports.getRegisteredOperationsByClassname = exports.getRegisteredOperations = exports.getRegistrationForFunction = exports.registerFunctionWrapper = exports.getRegisteredMethodName = exports.getRegisteredMethodClassName = exports.ensureDBOSIsNotLaunched = exports.recordDBOSShutdown = exports.recordDBOSLaunch = exports.ClassRegistration = exports.ConfiguredInstance = exports.MethodRegistration = exports.DBOS_AUTH = exports.MethodParameter = exports.DBOSDataType = exports.insertAllMiddleware = exports.registerMiddlewareInstaller = exports.getLifecycleListeners = exports.registerLifecycleCallback = exports.DBOSLifecycleCallback = void 0;
3
+ exports.DBOSInitializer = exports.OrmEntities = exports.ArgName = exports.getRegistrationsForExternal = exports.associateParameterWithExternal = exports.associateMethodWithExternal = exports.associateClassWithExternal = exports.getTransactionalDataSource = exports.registerTransactionalDataSource = exports.transactionalDataSources = exports.getConfiguredInstance = exports.getOrCreateClassRegistration = exports.getClassRegistrationByName = exports.getAllRegisteredFunctions = exports.getAllRegisteredClassNames = exports.getNameForClass = exports.registerAndWrapDBOSFunctionByName = exports.registerAndWrapDBOSFunction = exports.getOrCreateMethodArgsRegistration = exports.getRegisteredFunctionsByClassname = exports.getRegisteredOperations = exports.getFunctionRegistrationByName = exports.getFunctionRegistration = exports.registerFunctionWrapper = exports.getRegisteredFunctionName = exports.getRegisteredFunctionClassName = exports.getRegisteredFunctionQualifiedName = exports.getRegisteredFunctionFullName = exports.insertAllMiddleware = exports.registerMiddlewareInstaller = exports.getLifecycleListeners = exports.registerLifecycleCallback = exports.ensureDBOSIsNotLaunched = exports.recordDBOSShutdown = exports.recordDBOSLaunch = exports.ClassRegistration = exports.ConfiguredInstance = exports.MethodRegistration = exports.DBOS_AUTH = exports.MethodParameter = exports.DBOSDataType = void 0;
4
4
  require("reflect-metadata");
5
5
  const error_1 = require("./error");
6
- /**
7
- * Interface for integrating into the DBOS startup/shutdown lifecycle
8
- */
9
- class DBOSLifecycleCallback {
10
- /** Called back during DBOS launch */
11
- initialize() {
12
- return Promise.resolve();
13
- }
14
- /** Called back upon shutdown (usually in tests) to close connections and free resources */
15
- destroy() {
16
- return Promise.resolve();
17
- }
18
- /** Called at launch; Implementers should emit a diagnostic list of all registrations */
19
- logRegisteredEndpoints() { }
20
- }
21
- exports.DBOSLifecycleCallback = DBOSLifecycleCallback;
22
- const lifecycleListeners = [];
23
- function registerLifecycleCallback(lcl) {
24
- if (!lifecycleListeners.includes(lcl))
25
- lifecycleListeners.push(lcl);
26
- }
27
- exports.registerLifecycleCallback = registerLifecycleCallback;
28
- function getLifecycleListeners() {
29
- return lifecycleListeners;
30
- }
31
- exports.getLifecycleListeners = getLifecycleListeners;
32
- let installedMiddleware = false;
33
- const middlewareInstallers = [];
34
- function registerMiddlewareInstaller(i) {
35
- if (installedMiddleware)
36
- throw new TypeError('Attempt to provide method middleware after insertion was performed');
37
- if (!middlewareInstallers.includes(i))
38
- middlewareInstallers.push(i);
39
- }
40
- exports.registerMiddlewareInstaller = registerMiddlewareInstaller;
41
- function insertAllMiddleware() {
42
- if (installedMiddleware)
43
- return;
44
- installedMiddleware = true;
45
- for (const [_cn, c] of classesByName) {
46
- for (const [_fn, f] of c.reg.registeredOperations) {
47
- for (const i of middlewareInstallers) {
48
- i.installMiddleware(f);
49
- }
50
- }
51
- }
52
- }
53
- exports.insertAllMiddleware = insertAllMiddleware;
54
6
  class DBOSDataType {
55
7
  dataType = 'text';
56
8
  length = -1;
@@ -238,9 +190,6 @@ class MethodParameter {
238
190
  }
239
191
  }
240
192
  exports.MethodParameter = MethodParameter;
241
- //////////////////////////////////////////
242
- /* REGISTRATION OBJECTS and read access */
243
- //////////////////////////////////////////
244
193
  exports.DBOS_AUTH = 'auth';
245
194
  class MethodRegistration {
246
195
  defaults;
@@ -253,11 +202,9 @@ class MethodRegistration {
253
202
  this.onEnter.sort((a, b) => a.seqNum - b.seqNum);
254
203
  }
255
204
  args = [];
256
- passContext = false;
257
- constructor(origFunc, isInstance, passContext) {
205
+ constructor(origFunc, isInstance) {
258
206
  this.origFunction = origFunc;
259
207
  this.isInstance = isInstance;
260
- this.passContext = passContext;
261
208
  }
262
209
  needInitialized = true;
263
210
  isInstance;
@@ -269,7 +216,6 @@ class MethodRegistration {
269
216
  stepConfig;
270
217
  procConfig;
271
218
  regLocation;
272
- eventReceiverInfo = new Map();
273
219
  externalRegInfo = new Map();
274
220
  getRegisteredInfo(reg) {
275
221
  if (!this.externalRegInfo.has(reg)) {
@@ -338,14 +284,6 @@ class MethodRegistration {
338
284
  }
339
285
  }
340
286
  exports.MethodRegistration = MethodRegistration;
341
- function registerClassInstance(inst, name) {
342
- const creg = getOrCreateClassRegistration(inst.constructor);
343
- if (creg.configuredInstances.has(name)) {
344
- throw new error_1.DBOSConflictingRegistrationError(`An instance of class '${inst.constructor.name}' with name '${name}' was already registered. Earlier registration occurred at:\n${(creg.configuredInstanceRegLocs.get(name) ?? []).join('\n')}`);
345
- }
346
- creg.configuredInstances.set(name, inst);
347
- creg.configuredInstanceRegLocs.set(name, new StackGrabber().getCleanStack(3) ?? []);
348
- }
349
287
  class ConfiguredInstance {
350
288
  name;
351
289
  constructor(name) {
@@ -372,7 +310,6 @@ class ClassRegistration {
372
310
  registeredOperations = new Map();
373
311
  configuredInstances = new Map();
374
312
  configuredInstanceRegLocs = new Map();
375
- eventReceiverInfo = new Map();
376
313
  externalRegInfo = new Map();
377
314
  getRegisteredInfo(reg) {
378
315
  if (!this.externalRegInfo.has(reg)) {
@@ -383,6 +320,8 @@ class ClassRegistration {
383
320
  constructor() { }
384
321
  }
385
322
  exports.ClassRegistration = ClassRegistration;
323
+ // #endregion
324
+ // #region Global registration structures and functions
386
325
  class StackGrabber extends Error {
387
326
  constructor() {
388
327
  super('StackGrabber');
@@ -395,6 +334,7 @@ class StackGrabber extends Error {
395
334
  .map((l) => '>>> ' + l.replace(/^\s*at\s*/, '')); // Remove the first lines
396
335
  }
397
336
  }
337
+ // Track if DBOS is launched, and if so, from where
398
338
  let dbosLaunchPoint = undefined;
399
339
  function recordDBOSLaunch() {
400
340
  dbosLaunchPoint = new StackGrabber().getCleanStack(2); // Remove one for record, one for registerAndWrap...
@@ -410,32 +350,94 @@ function ensureDBOSIsNotLaunched() {
410
350
  }
411
351
  }
412
352
  exports.ensureDBOSIsNotLaunched = ensureDBOSIsNotLaunched;
413
- // This is a bit ugly, if we got the class / instance it would help avoid this auxiliary structure
414
- const methodToRegistration = new Map();
415
- function getRegisteredMethodClassName(func) {
416
- let rv = '';
417
- if (methodToRegistration.has(func)) {
418
- rv = methodToRegistration.get(func).className;
353
+ // DBOS launch lifecycle listener
354
+ const lifecycleListeners = [];
355
+ function registerLifecycleCallback(lcl) {
356
+ if (!lifecycleListeners.includes(lcl))
357
+ lifecycleListeners.push(lcl);
358
+ }
359
+ exports.registerLifecycleCallback = registerLifecycleCallback;
360
+ function getLifecycleListeners() {
361
+ return lifecycleListeners;
362
+ }
363
+ exports.getLifecycleListeners = getLifecycleListeners;
364
+ // Middleware installers - insert middleware in registered functions prior to launch
365
+ let installedMiddleware = false;
366
+ const middlewareInstallers = [];
367
+ function registerMiddlewareInstaller(i) {
368
+ if (installedMiddleware)
369
+ throw new TypeError('Attempt to provide method middleware after insertion was performed');
370
+ if (!middlewareInstallers.includes(i))
371
+ middlewareInstallers.push(i);
372
+ }
373
+ exports.registerMiddlewareInstaller = registerMiddlewareInstaller;
374
+ function insertAllMiddleware() {
375
+ if (installedMiddleware)
376
+ return;
377
+ installedMiddleware = true;
378
+ for (const [_cn, c] of classesByName) {
379
+ for (const [_fn, f] of c.reg.registeredOperations) {
380
+ for (const i of middlewareInstallers) {
381
+ i.installMiddleware(f);
382
+ }
383
+ }
384
+ }
385
+ }
386
+ exports.insertAllMiddleware = insertAllMiddleware;
387
+ // Registration of functions, and classes
388
+ const functionToRegistration = new Map();
389
+ // Registration of instance, by constructor+name
390
+ function registerClassInstance(inst, instname) {
391
+ const creg = getOrCreateClassRegistration(inst.constructor);
392
+ if (creg.configuredInstances.has(instname)) {
393
+ throw new error_1.DBOSConflictingRegistrationError(`An instance of class '${inst.constructor.name}' with name '${instname}' was already registered. Earlier registration occurred at:\n${(creg.configuredInstanceRegLocs.get(instname) ?? []).join('\n')}`);
419
394
  }
420
- return rv;
395
+ creg.configuredInstances.set(instname, inst);
396
+ creg.configuredInstanceRegLocs.set(instname, new StackGrabber().getCleanStack(3) ?? []);
421
397
  }
422
- exports.getRegisteredMethodClassName = getRegisteredMethodClassName;
423
- function getRegisteredMethodName(func) {
424
- let rv = '';
425
- if (methodToRegistration.has(func)) {
426
- rv = methodToRegistration.get(func).name;
398
+ function getRegisteredFunctionFullName(func) {
399
+ let className = '';
400
+ let funcName = func.name ?? '';
401
+ if (functionToRegistration.has(func)) {
402
+ const fr = functionToRegistration.get(func);
403
+ className = fr.className;
404
+ funcName = fr.name;
427
405
  }
428
- return rv;
406
+ return { className, name: funcName };
407
+ }
408
+ exports.getRegisteredFunctionFullName = getRegisteredFunctionFullName;
409
+ function getRegisteredFunctionQualifiedName(func) {
410
+ const fn = getRegisteredFunctionFullName(func);
411
+ return fn.className + '.' + fn.name;
412
+ }
413
+ exports.getRegisteredFunctionQualifiedName = getRegisteredFunctionQualifiedName;
414
+ function getRegisteredFunctionClassName(func) {
415
+ return getRegisteredFunctionFullName(func).className;
429
416
  }
430
- exports.getRegisteredMethodName = getRegisteredMethodName;
417
+ exports.getRegisteredFunctionClassName = getRegisteredFunctionClassName;
418
+ function getRegisteredFunctionName(func) {
419
+ return getRegisteredFunctionFullName(func).name;
420
+ }
421
+ exports.getRegisteredFunctionName = getRegisteredFunctionName;
431
422
  function registerFunctionWrapper(func, reg) {
432
- methodToRegistration.set(func, reg);
423
+ reg.wrappedFunction = func;
424
+ functionToRegistration.set(func, reg);
433
425
  }
434
426
  exports.registerFunctionWrapper = registerFunctionWrapper;
435
- function getRegistrationForFunction(func) {
436
- return methodToRegistration.get(func);
427
+ function getFunctionRegistration(func) {
428
+ return functionToRegistration.get(func);
429
+ }
430
+ exports.getFunctionRegistration = getFunctionRegistration;
431
+ function getFunctionRegistrationByName(className, name) {
432
+ const clsreg = getClassRegistrationByName(className, false);
433
+ if (!clsreg)
434
+ return undefined;
435
+ const methReg = clsreg.registeredOperations.get(name);
436
+ if (!methReg)
437
+ return undefined;
438
+ return methReg;
437
439
  }
438
- exports.getRegistrationForFunction = getRegistrationForFunction;
440
+ exports.getFunctionRegistrationByName = getFunctionRegistrationByName;
439
441
  function getRegisteredOperations(target) {
440
442
  const registeredOperations = [];
441
443
  if (typeof target === 'function') {
@@ -456,57 +458,23 @@ function getRegisteredOperations(target) {
456
458
  return registeredOperations;
457
459
  }
458
460
  exports.getRegisteredOperations = getRegisteredOperations;
459
- function getRegisteredOperationsByClassname(target) {
461
+ function getRegisteredFunctionsByClassname(target) {
460
462
  const registeredOperations = [];
461
463
  const cls = getClassRegistrationByName(target);
462
- cls.registeredOperations?.forEach((m) => registeredOperations.push(m));
464
+ cls?.registeredOperations?.forEach((m) => registeredOperations.push(m));
463
465
  return registeredOperations;
464
466
  }
465
- exports.getRegisteredOperationsByClassname = getRegisteredOperationsByClassname;
466
- function getConfiguredInstance(clsname, cfgname) {
467
- const classReg = classesByName.get(clsname)?.reg;
468
- if (!classReg)
469
- return null;
470
- return classReg.configuredInstances.get(cfgname) ?? null;
471
- }
472
- exports.getConfiguredInstance = getConfiguredInstance;
473
- /////
474
- // Transactional data source registration
475
- /////
476
- exports.transactionalDataSources = new Map();
477
- // Register data source (user version)
478
- function registerTransactionalDataSource(name, ds) {
479
- if (exports.transactionalDataSources.has(name)) {
480
- if (exports.transactionalDataSources.get(name) !== ds) {
481
- throw new error_1.DBOSConflictingRegistrationError(`Data source with name ${name} is already registered`);
482
- }
483
- return;
484
- }
485
- ensureDBOSIsNotLaunched();
486
- exports.transactionalDataSources.set(name, ds);
487
- }
488
- exports.registerTransactionalDataSource = registerTransactionalDataSource;
489
- function getTransactionalDataSource(name) {
490
- if (exports.transactionalDataSources.has(name))
491
- return exports.transactionalDataSources.get(name);
492
- throw new error_1.DBOSNotRegisteredError(name, `Data source '${name}' is not registered`);
493
- }
494
- exports.getTransactionalDataSource = getTransactionalDataSource;
495
- ////////////////////////////////////////////////////////////////////////////////
496
- // DECORATOR REGISTRATION
497
- // These manage registration objects, creating them at decorator evaluation time
498
- // and making wrapped methods available for function registration at runtime
499
- // initialization time.
500
- ////////////////////////////////////////////////////////////////////////////////
467
+ exports.getRegisteredFunctionsByClassname = getRegisteredFunctionsByClassname;
501
468
  const methodArgsByFunction = new Map();
502
- function getOrCreateMethodArgsRegistration(target, className, funcName, func) {
469
+ function getOrCreateMethodArgsRegistration(target, funcName, origFunc) {
503
470
  let regtarget = target;
504
471
  if (regtarget && typeof regtarget !== 'function') {
505
472
  regtarget = regtarget.constructor;
506
473
  }
507
- className = className ?? (target ? getNameForClass(target) : '');
508
- const mkey = className + '|' + funcName.toString();
509
- let mParameters = methodArgsByFunction.get(mkey);
474
+ if (!origFunc) {
475
+ origFunc = Object.getOwnPropertyDescriptor(target, funcName).value;
476
+ }
477
+ let mParameters = methodArgsByFunction.get(origFunc);
510
478
  if (mParameters === undefined) {
511
479
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
512
480
  let designParamTypes = undefined;
@@ -518,8 +486,8 @@ function getOrCreateMethodArgsRegistration(target, className, funcName, func) {
518
486
  mParameters = designParamTypes.map((value, index) => new MethodParameter(index, value));
519
487
  }
520
488
  else {
521
- if (func) {
522
- const argnames = getArgNames(func);
489
+ if (origFunc) {
490
+ const argnames = getArgNames(origFunc);
523
491
  mParameters = argnames.map((_value, index) => new MethodParameter(index));
524
492
  }
525
493
  else {
@@ -529,12 +497,12 @@ function getOrCreateMethodArgsRegistration(target, className, funcName, func) {
529
497
  mParameters = argnames.map((_value, index) => new MethodParameter(index));
530
498
  }
531
499
  }
532
- methodArgsByFunction.set(mkey, mParameters);
500
+ methodArgsByFunction.set(origFunc, mParameters);
533
501
  }
534
502
  return mParameters;
535
503
  }
536
504
  exports.getOrCreateMethodArgsRegistration = getOrCreateMethodArgsRegistration;
537
- function getOrCreateMethodRegistration(target, className, propertyKey, func, passContext) {
505
+ function getOrCreateMethodRegistration(target, className, propertyKey, func) {
538
506
  let regtarget = undefined;
539
507
  let isInstance = false;
540
508
  if (target) {
@@ -558,21 +526,15 @@ function getOrCreateMethodRegistration(target, className, propertyKey, func, pas
558
526
  const classReg = getClassRegistrationByName(className, true);
559
527
  const fname = propertyKey.toString();
560
528
  if (!classReg.registeredOperations.has(fname)) {
561
- classReg.registeredOperations.set(fname, new MethodRegistration(func, isInstance, passContext));
529
+ classReg.registeredOperations.set(fname, new MethodRegistration(func, isInstance));
562
530
  }
563
531
  const methReg = classReg.registeredOperations.get(fname);
564
- // Note: We cannot tell if the method takes a context or not.
565
- // Our @Workflow, @Transaction, and @Step decorators are the only ones that would know to set passContext.
566
- // So, if passContext is indicated, add it to the registration.
567
- if (passContext && !methReg.passContext) {
568
- methReg.passContext = true;
569
- }
570
532
  if (methReg.needInitialized) {
571
533
  methReg.needInitialized = false;
572
534
  methReg.name = fname;
573
535
  methReg.className = classReg.name;
574
536
  methReg.defaults = classReg;
575
- methReg.args = getOrCreateMethodArgsRegistration(target, className, propertyKey, func);
537
+ methReg.args = getOrCreateMethodArgsRegistration(target, propertyKey, func);
576
538
  const argNames = getArgNames(func);
577
539
  methReg.args.forEach((e) => {
578
540
  if (!e.name) {
@@ -592,8 +554,8 @@ function getOrCreateMethodRegistration(target, className, propertyKey, func, pas
592
554
  value: methReg.name,
593
555
  });
594
556
  methReg.registeredFunction = wrappedMethod;
595
- methodToRegistration.set(methReg.registeredFunction, methReg);
596
- methodToRegistration.set(methReg.origFunction, methReg);
557
+ functionToRegistration.set(methReg.registeredFunction, methReg);
558
+ functionToRegistration.set(methReg.origFunction, methReg);
597
559
  }
598
560
  return methReg;
599
561
  }
@@ -602,14 +564,15 @@ function registerAndWrapDBOSFunction(target, propertyKey, descriptor) {
602
564
  if (!descriptor.value) {
603
565
  throw Error('Use of decorator when original method is undefined');
604
566
  }
605
- const registration = getOrCreateMethodRegistration(target, undefined, propertyKey, descriptor.value, false);
567
+ const registration = getOrCreateMethodRegistration(target, undefined, propertyKey, descriptor.value);
606
568
  descriptor.value = registration.wrappedFunction ?? registration.registeredFunction;
607
569
  return { descriptor, registration };
608
570
  }
609
571
  exports.registerAndWrapDBOSFunction = registerAndWrapDBOSFunction;
610
572
  function registerAndWrapDBOSFunctionByName(target, className, funcName, func) {
611
573
  ensureDBOSIsNotLaunched();
612
- const registration = getOrCreateMethodRegistration(target, className, funcName, func, false);
574
+ const freg = getFunctionRegistration(func);
575
+ const registration = freg ?? getOrCreateMethodRegistration(target, className, funcName, func);
613
576
  return { registration };
614
577
  }
615
578
  exports.registerAndWrapDBOSFunctionByName = registerAndWrapDBOSFunctionByName;
@@ -638,6 +601,18 @@ function getAllRegisteredClassNames() {
638
601
  return cnames;
639
602
  }
640
603
  exports.getAllRegisteredClassNames = getAllRegisteredClassNames;
604
+ function getAllRegisteredFunctions() {
605
+ const s = new Set();
606
+ const fregs = [];
607
+ for (const [_f, reg] of functionToRegistration) {
608
+ if (s.has(reg))
609
+ continue;
610
+ fregs.push(reg);
611
+ s.add(reg);
612
+ }
613
+ return fregs;
614
+ }
615
+ exports.getAllRegisteredFunctions = getAllRegisteredFunctions;
641
616
  function getClassRegistrationByName(name, create = false) {
642
617
  if (!classesByName.has(name) && !create) {
643
618
  throw new error_1.DBOSNotRegisteredError(name, `Class '${name}' is not registered`);
@@ -666,48 +641,42 @@ function getOrCreateClassRegistration(ctor) {
666
641
  return clsReg;
667
642
  }
668
643
  exports.getOrCreateClassRegistration = getOrCreateClassRegistration;
669
- /**
670
- * Associates a class with a `DBOSEventReceiver`, which will be calling the class's DBOS methods.
671
- * Allows class-level default values or other storage to be associated with the class, rather than
672
- * separately for each registered method.
673
- *
674
- * @param rcvr - Event receiver which will dispatch DBOS methods from the class specified by `ctor`
675
- * @param ctor - Constructor of the class that is being registered and associated with `rcvr`
676
- * @returns - Class-specific registration info cumulatively collected for `rcvr`
677
- */
678
- function associateClassWithEventReceiver(rcvr, ctor) {
679
- const clsReg = getOrCreateClassRegistration(ctor);
680
- if (!clsReg.eventReceiverInfo.has(rcvr)) {
681
- clsReg.eventReceiverInfo.set(rcvr, {});
644
+ function getConfiguredInstance(clsname, cfgname) {
645
+ const classReg = classesByName.get(clsname)?.reg;
646
+ if (!classReg)
647
+ return null;
648
+ return classReg.configuredInstances.get(cfgname) ?? null;
649
+ }
650
+ exports.getConfiguredInstance = getConfiguredInstance;
651
+ // #endregion
652
+ // #region Transactional data source registration
653
+ exports.transactionalDataSources = new Map();
654
+ // Register data source (user version)
655
+ function registerTransactionalDataSource(name, ds) {
656
+ if (exports.transactionalDataSources.has(name)) {
657
+ if (exports.transactionalDataSources.get(name) !== ds) {
658
+ throw new error_1.DBOSConflictingRegistrationError(`Data source with name ${name} is already registered`);
659
+ }
660
+ return;
682
661
  }
683
- return clsReg.eventReceiverInfo.get(rcvr);
662
+ ensureDBOSIsNotLaunched();
663
+ exports.transactionalDataSources.set(name, ds);
664
+ }
665
+ exports.registerTransactionalDataSource = registerTransactionalDataSource;
666
+ function getTransactionalDataSource(name) {
667
+ if (exports.transactionalDataSources.has(name))
668
+ return exports.transactionalDataSources.get(name);
669
+ throw new error_1.DBOSNotRegisteredError(name, `Data source '${name}' is not registered`);
684
670
  }
685
- exports.associateClassWithEventReceiver = associateClassWithEventReceiver;
671
+ exports.getTransactionalDataSource = getTransactionalDataSource;
672
+ // #endregion
673
+ // #region External (event receiver v3)
686
674
  function associateClassWithExternal(external, cls) {
687
675
  const clsn = typeof cls === 'string' ? cls : getNameForClass(cls);
688
676
  const clsreg = getClassRegistrationByName(clsn, true);
689
677
  return clsreg.getRegisteredInfo(external);
690
678
  }
691
679
  exports.associateClassWithExternal = associateClassWithExternal;
692
- /**
693
- * Associates a workflow method with a `DBOSEventReceiver` which will be in charge of calling the method
694
- * in response to received events.
695
- * This version is to be used in "Stage 2" decorators, as it applies the DBOS wrapper to the registered method.
696
- *
697
- * @param rcvr - `DBOSEventReceiver` instance that should be informed of the `target` method's registration
698
- * @param target - A DBOS method to associate with the event receiver
699
- * @param propertyKey - For Stage 2 decorator use, this is the property key used for replacing the method with its wrapper
700
- * @param inDescriptor - For Stage 2 decorator use, this is the method descriptor used for replacing the method with its wrapper
701
- * @returns The new method descriptor, registration, and event receiver info
702
- */
703
- function associateMethodWithEventReceiver(rcvr, target, propertyKey, inDescriptor) {
704
- const { descriptor, registration } = registerAndWrapDBOSFunction(target, propertyKey, inDescriptor);
705
- if (!registration.eventReceiverInfo.has(rcvr)) {
706
- registration.eventReceiverInfo.set(rcvr, {});
707
- }
708
- return { descriptor, registration, receiverInfo: registration.eventReceiverInfo.get(rcvr) };
709
- }
710
- exports.associateMethodWithEventReceiver = associateMethodWithEventReceiver;
711
680
  /*
712
681
  * Associates a DBOS function or method with an external class or object.
713
682
  * Likely, this will be invoking or intercepting the method.
@@ -721,7 +690,7 @@ function associateMethodWithExternal(external, target, className, funcName, func
721
690
  }
722
691
  exports.associateMethodWithExternal = associateMethodWithExternal;
723
692
  /*
724
- * Associates a DBOS function or method with an external class or object.
693
+ * Associates a DBOS function or method parameters with an external class or object.
725
694
  * Likely, this will be invoking or intercepting the method.
726
695
  */
727
696
  function associateParameterWithExternal(external, target, className, funcName, func, paramId) {
@@ -745,7 +714,7 @@ function associateParameterWithExternal(external, target, className, funcName, f
745
714
  }
746
715
  exports.associateParameterWithExternal = associateParameterWithExternal;
747
716
  function getRegistrationsForExternal(external, cls, funcName) {
748
- const res = [];
717
+ const res = new Array();
749
718
  if (cls) {
750
719
  const clsname = typeof cls === 'string' ? cls : getNameForClass(cls);
751
720
  const c = classesByName.get(clsname);
@@ -792,26 +761,18 @@ function getRegistrationsForExternal(external, cls, funcName) {
792
761
  }
793
762
  }
794
763
  exports.getRegistrationsForExternal = getRegistrationsForExternal;
795
- //////////////////////////
796
- /* PARAMETER DECORATORS */
797
- //////////////////////////
764
+ // #endregion
765
+ // #region Parameter decorators
798
766
  function ArgName(name) {
799
767
  return function (target, propertyKey, parameterIndex) {
800
- const existingParameters = getOrCreateMethodArgsRegistration(target, undefined, propertyKey);
768
+ const existingParameters = getOrCreateMethodArgsRegistration(target, propertyKey);
801
769
  const curParam = existingParameters[parameterIndex];
802
770
  curParam.name = name;
803
771
  };
804
772
  }
805
773
  exports.ArgName = ArgName;
806
- ///////////////////////
807
- /* CLASS DECORATORS */
808
- ///////////////////////
809
- /** @deprecated Use `new` */
810
- function configureInstance(cls, name, ...args) {
811
- const inst = new cls(name, ...args);
812
- return inst;
813
- }
814
- exports.configureInstance = configureInstance;
774
+ // #endregion
775
+ // #region Class decorators
815
776
  /**
816
777
  * @deprecated Use ORM DSs
817
778
  */
@@ -824,6 +785,8 @@ function OrmEntities(entities = []) {
824
785
  return clsdec;
825
786
  }
826
787
  exports.OrmEntities = OrmEntities;
788
+ // #endregion
789
+ // #region Method decorators
827
790
  function DBOSInitializer() {
828
791
  function decorator(target, propertyKey, inDescriptor) {
829
792
  const { descriptor, registration } = registerAndWrapDBOSFunction(target, propertyKey, inDescriptor);
@@ -833,4 +796,5 @@ function DBOSInitializer() {
833
796
  return decorator;
834
797
  }
835
798
  exports.DBOSInitializer = DBOSInitializer;
799
+ // #endregion
836
800
  //# sourceMappingURL=decorators.js.map