@dbos-inc/dbos-sdk 3.0.27-preview → 3.0.35-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 (65) hide show
  1. package/dist/src/datasource.d.ts +11 -6
  2. package/dist/src/datasource.d.ts.map +1 -1
  3. package/dist/src/datasource.js +9 -6
  4. package/dist/src/datasource.js.map +1 -1
  5. package/dist/src/dbos-executor.d.ts +51 -89
  6. package/dist/src/dbos-executor.d.ts.map +1 -1
  7. package/dist/src/dbos-executor.js +61 -284
  8. package/dist/src/dbos-executor.js.map +1 -1
  9. package/dist/src/dbos-runtime/config.d.ts +6 -4
  10. package/dist/src/dbos-runtime/config.d.ts.map +1 -1
  11. package/dist/src/dbos-runtime/config.js +59 -28
  12. package/dist/src/dbos-runtime/config.js.map +1 -1
  13. package/dist/src/dbos-runtime/migrate.js +3 -3
  14. package/dist/src/dbos-runtime/migrate.js.map +1 -1
  15. package/dist/src/dbos-runtime/runtime.d.ts +1 -1
  16. package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
  17. package/dist/src/dbos-runtime/runtime.js +4 -14
  18. package/dist/src/dbos-runtime/runtime.js.map +1 -1
  19. package/dist/src/dbos.d.ts +27 -65
  20. package/dist/src/dbos.d.ts.map +1 -1
  21. package/dist/src/dbos.js +107 -122
  22. package/dist/src/dbos.js.map +1 -1
  23. package/dist/src/decorators.d.ts +51 -57
  24. package/dist/src/decorators.d.ts.map +1 -1
  25. package/dist/src/decorators.js +234 -200
  26. package/dist/src/decorators.js.map +1 -1
  27. package/dist/src/httpServer/handler.d.ts +1 -1
  28. package/dist/src/httpServer/handler.d.ts.map +1 -1
  29. package/dist/src/httpServer/handler.js +1 -1
  30. package/dist/src/httpServer/handler.js.map +1 -1
  31. package/dist/src/httpServer/middleware.d.ts +0 -1
  32. package/dist/src/httpServer/middleware.d.ts.map +1 -1
  33. package/dist/src/httpServer/middleware.js.map +1 -1
  34. package/dist/src/httpServer/server.d.ts.map +1 -1
  35. package/dist/src/httpServer/server.js +4 -6
  36. package/dist/src/httpServer/server.js.map +1 -1
  37. package/dist/src/index.d.ts +3 -5
  38. package/dist/src/index.d.ts.map +1 -1
  39. package/dist/src/index.js +7 -12
  40. package/dist/src/index.js.map +1 -1
  41. package/dist/src/paramdecorators.d.ts +6 -6
  42. package/dist/src/paramdecorators.d.ts.map +1 -1
  43. package/dist/src/paramdecorators.js.map +1 -1
  44. package/dist/src/scheduler/crontab.d.ts +3 -8
  45. package/dist/src/scheduler/crontab.d.ts.map +1 -1
  46. package/dist/src/scheduler/crontab.js +24 -23
  47. package/dist/src/scheduler/crontab.js.map +1 -1
  48. package/dist/src/scheduler/scheduler.d.ts +10 -31
  49. package/dist/src/scheduler/scheduler.d.ts.map +1 -1
  50. package/dist/src/scheduler/scheduler.js +100 -135
  51. package/dist/src/scheduler/scheduler.js.map +1 -1
  52. package/dist/src/system_database.d.ts +5 -6
  53. package/dist/src/system_database.d.ts.map +1 -1
  54. package/dist/src/system_database.js +14 -1
  55. package/dist/src/system_database.js.map +1 -1
  56. package/dist/src/utils.d.ts.map +1 -1
  57. package/dist/src/utils.js +14 -4
  58. package/dist/src/utils.js.map +1 -1
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/eslint.config.cjs +6 -1
  61. package/package.json +1 -1
  62. package/dist/src/eventreceiver.d.ts +0 -152
  63. package/dist/src/eventreceiver.d.ts.map +0 -1
  64. package/dist/src/eventreceiver.js +0 -3
  65. package/dist/src/eventreceiver.js.map +0 -1
@@ -1,40 +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 = 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.wrapDBOSFunctionAndRegister = exports.wrapDBOSFunctionAndRegisterDec = exports.wrapDBOSFunctionAndRegisterByUniqueName = exports.wrapDBOSFunctionAndRegisterByUniqueNameDec = 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
- const lifecycleListeners = [];
7
- function registerLifecycleCallback(lcl) {
8
- if (!lifecycleListeners.includes(lcl))
9
- lifecycleListeners.push(lcl);
10
- }
11
- exports.registerLifecycleCallback = registerLifecycleCallback;
12
- function getLifecycleListeners() {
13
- return lifecycleListeners;
14
- }
15
- exports.getLifecycleListeners = getLifecycleListeners;
16
- let installedMiddleware = false;
17
- const middlewareInstallers = [];
18
- function registerMiddlewareInstaller(i) {
19
- if (installedMiddleware)
20
- throw new TypeError('Attempt to provide method middleware after insertion was performed');
21
- if (!middlewareInstallers.includes(i))
22
- middlewareInstallers.push(i);
23
- }
24
- exports.registerMiddlewareInstaller = registerMiddlewareInstaller;
25
- function insertAllMiddleware() {
26
- if (installedMiddleware)
27
- return;
28
- installedMiddleware = true;
29
- for (const [_cn, c] of classesByName) {
30
- for (const [_fn, f] of c.reg.registeredOperations) {
31
- for (const i of middlewareInstallers) {
32
- i.installMiddleware(f);
33
- }
34
- }
35
- }
36
- }
37
- exports.insertAllMiddleware = insertAllMiddleware;
38
6
  class DBOSDataType {
39
7
  dataType = 'text';
40
8
  length = -1;
@@ -222,9 +190,6 @@ class MethodParameter {
222
190
  }
223
191
  }
224
192
  exports.MethodParameter = MethodParameter;
225
- //////////////////////////////////////////
226
- /* REGISTRATION OBJECTS and read access */
227
- //////////////////////////////////////////
228
193
  exports.DBOS_AUTH = 'auth';
229
194
  class MethodRegistration {
230
195
  defaults;
@@ -251,7 +216,6 @@ class MethodRegistration {
251
216
  stepConfig;
252
217
  procConfig;
253
218
  regLocation;
254
- eventReceiverInfo = new Map();
255
219
  externalRegInfo = new Map();
256
220
  getRegisteredInfo(reg) {
257
221
  if (!this.externalRegInfo.has(reg)) {
@@ -320,14 +284,6 @@ class MethodRegistration {
320
284
  }
321
285
  }
322
286
  exports.MethodRegistration = MethodRegistration;
323
- function registerClassInstance(inst, name) {
324
- const creg = getOrCreateClassRegistration(inst.constructor);
325
- if (creg.configuredInstances.has(name)) {
326
- 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')}`);
327
- }
328
- creg.configuredInstances.set(name, inst);
329
- creg.configuredInstanceRegLocs.set(name, new StackGrabber().getCleanStack(3) ?? []);
330
- }
331
287
  class ConfiguredInstance {
332
288
  name;
333
289
  constructor(name) {
@@ -351,11 +307,23 @@ class ClassRegistration {
351
307
  needsInitialized = true;
352
308
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
353
309
  ormEntities = [];
354
- registeredOperations = new Map();
310
+ registeredOperationsByName = new Map();
311
+ allRegisteredOperations = new Map();
355
312
  configuredInstances = new Map();
356
313
  configuredInstanceRegLocs = new Map();
357
- eventReceiverInfo = new Map();
358
314
  externalRegInfo = new Map();
315
+ registerOperationByName(name, reg) {
316
+ const er = this.registeredOperationsByName.get(name);
317
+ if (er && er !== reg) {
318
+ let error = `Operation (Name: ${this.name}.${name}) is already registered.`;
319
+ if (er.regLocation) {
320
+ error = error + `\nPrior registration occurred at:\n${er.regLocation.join('\n')}`;
321
+ }
322
+ throw new error_1.DBOSConflictingRegistrationError(`${error}`);
323
+ }
324
+ this.registeredOperationsByName.set(name, reg);
325
+ reg.regLocation = new StackGrabber().getCleanStack(3);
326
+ }
359
327
  getRegisteredInfo(reg) {
360
328
  if (!this.externalRegInfo.has(reg)) {
361
329
  this.externalRegInfo.set(reg, {});
@@ -365,6 +333,8 @@ class ClassRegistration {
365
333
  constructor() { }
366
334
  }
367
335
  exports.ClassRegistration = ClassRegistration;
336
+ // #endregion
337
+ // #region Global registration structures and functions
368
338
  class StackGrabber extends Error {
369
339
  constructor() {
370
340
  super('StackGrabber');
@@ -377,6 +347,7 @@ class StackGrabber extends Error {
377
347
  .map((l) => '>>> ' + l.replace(/^\s*at\s*/, '')); // Remove the first lines
378
348
  }
379
349
  }
350
+ // Track if DBOS is launched, and if so, from where
380
351
  let dbosLaunchPoint = undefined;
381
352
  function recordDBOSLaunch() {
382
353
  dbosLaunchPoint = new StackGrabber().getCleanStack(2); // Remove one for record, one for registerAndWrap...
@@ -392,38 +363,100 @@ function ensureDBOSIsNotLaunched() {
392
363
  }
393
364
  }
394
365
  exports.ensureDBOSIsNotLaunched = ensureDBOSIsNotLaunched;
395
- // This is a bit ugly, if we got the class / instance it would help avoid this auxiliary structure
396
- const methodToRegistration = new Map();
397
- function getRegisteredMethodClassName(func) {
398
- let rv = '';
399
- if (methodToRegistration.has(func)) {
400
- rv = methodToRegistration.get(func).className;
366
+ // DBOS launch lifecycle listener
367
+ const lifecycleListeners = [];
368
+ function registerLifecycleCallback(lcl) {
369
+ if (!lifecycleListeners.includes(lcl))
370
+ lifecycleListeners.push(lcl);
371
+ }
372
+ exports.registerLifecycleCallback = registerLifecycleCallback;
373
+ function getLifecycleListeners() {
374
+ return lifecycleListeners;
375
+ }
376
+ exports.getLifecycleListeners = getLifecycleListeners;
377
+ // Middleware installers - insert middleware in registered functions prior to launch
378
+ let installedMiddleware = false;
379
+ const middlewareInstallers = [];
380
+ function registerMiddlewareInstaller(i) {
381
+ if (installedMiddleware)
382
+ throw new TypeError('Attempt to provide method middleware after insertion was performed');
383
+ if (!middlewareInstallers.includes(i))
384
+ middlewareInstallers.push(i);
385
+ }
386
+ exports.registerMiddlewareInstaller = registerMiddlewareInstaller;
387
+ function insertAllMiddleware() {
388
+ if (installedMiddleware)
389
+ return;
390
+ installedMiddleware = true;
391
+ for (const [_cn, c] of classesByName) {
392
+ for (const f of c.reg.allRegisteredOperations.values()) {
393
+ for (const i of middlewareInstallers) {
394
+ i.installMiddleware(f);
395
+ }
396
+ }
397
+ }
398
+ }
399
+ exports.insertAllMiddleware = insertAllMiddleware;
400
+ // Registration of functions, and classes
401
+ const functionToRegistration = new Map();
402
+ // Registration of instance, by constructor+name
403
+ function registerClassInstance(inst, instname) {
404
+ const creg = getOrCreateClassRegistration(inst.constructor);
405
+ if (creg.configuredInstances.has(instname)) {
406
+ 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')}`);
401
407
  }
402
- return rv;
408
+ creg.configuredInstances.set(instname, inst);
409
+ creg.configuredInstanceRegLocs.set(instname, new StackGrabber().getCleanStack(3) ?? []);
403
410
  }
404
- exports.getRegisteredMethodClassName = getRegisteredMethodClassName;
405
- function getRegisteredMethodName(func) {
406
- let rv = '';
407
- if (methodToRegistration.has(func)) {
408
- rv = methodToRegistration.get(func).name;
411
+ function getRegisteredFunctionFullName(func) {
412
+ let className = '';
413
+ let funcName = func.name ?? '';
414
+ if (functionToRegistration.has(func)) {
415
+ const fr = functionToRegistration.get(func);
416
+ className = fr.className;
417
+ funcName = fr.name;
409
418
  }
410
- return rv;
419
+ return { className, name: funcName };
420
+ }
421
+ exports.getRegisteredFunctionFullName = getRegisteredFunctionFullName;
422
+ function getRegisteredFunctionQualifiedName(func) {
423
+ const fn = getRegisteredFunctionFullName(func);
424
+ return fn.className + '.' + fn.name;
411
425
  }
412
- exports.getRegisteredMethodName = getRegisteredMethodName;
426
+ exports.getRegisteredFunctionQualifiedName = getRegisteredFunctionQualifiedName;
427
+ function getRegisteredFunctionClassName(func) {
428
+ return getRegisteredFunctionFullName(func).className;
429
+ }
430
+ exports.getRegisteredFunctionClassName = getRegisteredFunctionClassName;
431
+ function getRegisteredFunctionName(func) {
432
+ return getRegisteredFunctionFullName(func).name;
433
+ }
434
+ exports.getRegisteredFunctionName = getRegisteredFunctionName;
413
435
  function registerFunctionWrapper(func, reg) {
414
- methodToRegistration.set(func, reg);
436
+ reg.wrappedFunction = func;
437
+ functionToRegistration.set(func, reg);
415
438
  }
416
439
  exports.registerFunctionWrapper = registerFunctionWrapper;
417
- function getRegistrationForFunction(func) {
418
- return methodToRegistration.get(func);
440
+ function getFunctionRegistration(func) {
441
+ return functionToRegistration.get(func);
442
+ }
443
+ exports.getFunctionRegistration = getFunctionRegistration;
444
+ function getFunctionRegistrationByName(className, name) {
445
+ const clsreg = getClassRegistrationByName(className, false);
446
+ if (!clsreg)
447
+ return undefined;
448
+ const methReg = clsreg.registeredOperationsByName.get(name);
449
+ if (!methReg)
450
+ return undefined;
451
+ return methReg;
419
452
  }
420
- exports.getRegistrationForFunction = getRegistrationForFunction;
453
+ exports.getFunctionRegistrationByName = getFunctionRegistrationByName;
421
454
  function getRegisteredOperations(target) {
422
455
  const registeredOperations = [];
423
456
  if (typeof target === 'function') {
424
457
  // Constructor case
425
458
  const classReg = classesByName.get(target.name);
426
- classReg?.reg?.registeredOperations?.forEach((m) => registeredOperations.push(m));
459
+ classReg?.reg?.allRegisteredOperations?.forEach((m) => registeredOperations.push(m));
427
460
  }
428
461
  else {
429
462
  let current = target;
@@ -438,70 +471,35 @@ function getRegisteredOperations(target) {
438
471
  return registeredOperations;
439
472
  }
440
473
  exports.getRegisteredOperations = getRegisteredOperations;
441
- function getRegisteredOperationsByClassname(target) {
474
+ function getRegisteredFunctionsByClassname(target) {
442
475
  const registeredOperations = [];
443
476
  const cls = getClassRegistrationByName(target);
444
- cls.registeredOperations?.forEach((m) => registeredOperations.push(m));
477
+ cls?.allRegisteredOperations?.forEach((m) => registeredOperations.push(m));
445
478
  return registeredOperations;
446
479
  }
447
- exports.getRegisteredOperationsByClassname = getRegisteredOperationsByClassname;
448
- function getConfiguredInstance(clsname, cfgname) {
449
- const classReg = classesByName.get(clsname)?.reg;
450
- if (!classReg)
451
- return null;
452
- return classReg.configuredInstances.get(cfgname) ?? null;
453
- }
454
- exports.getConfiguredInstance = getConfiguredInstance;
455
- /////
456
- // Transactional data source registration
457
- /////
458
- exports.transactionalDataSources = new Map();
459
- // Register data source (user version)
460
- function registerTransactionalDataSource(name, ds) {
461
- if (exports.transactionalDataSources.has(name)) {
462
- if (exports.transactionalDataSources.get(name) !== ds) {
463
- throw new error_1.DBOSConflictingRegistrationError(`Data source with name ${name} is already registered`);
464
- }
465
- return;
466
- }
467
- ensureDBOSIsNotLaunched();
468
- exports.transactionalDataSources.set(name, ds);
469
- }
470
- exports.registerTransactionalDataSource = registerTransactionalDataSource;
471
- function getTransactionalDataSource(name) {
472
- if (exports.transactionalDataSources.has(name))
473
- return exports.transactionalDataSources.get(name);
474
- throw new error_1.DBOSNotRegisteredError(name, `Data source '${name}' is not registered`);
475
- }
476
- exports.getTransactionalDataSource = getTransactionalDataSource;
477
- ////////////////////////////////////////////////////////////////////////////////
478
- // DECORATOR REGISTRATION
479
- // These manage registration objects, creating them at decorator evaluation time
480
- // and making wrapped methods available for function registration at runtime
481
- // initialization time.
482
- ////////////////////////////////////////////////////////////////////////////////
480
+ exports.getRegisteredFunctionsByClassname = getRegisteredFunctionsByClassname;
483
481
  const methodArgsByFunction = new Map();
484
- function getOrCreateMethodArgsRegistration(target, className, funcName, func) {
482
+ function getOrCreateMethodArgsRegistration(target, funcName, origFunc) {
485
483
  let regtarget = target;
486
484
  if (regtarget && typeof regtarget !== 'function') {
487
485
  regtarget = regtarget.constructor;
488
486
  }
489
- className = className ?? (target ? getNameForClass(target) : '');
490
- const mkey = className + '|' + funcName.toString();
491
- let mParameters = methodArgsByFunction.get(mkey);
487
+ if (!origFunc) {
488
+ origFunc = Object.getOwnPropertyDescriptor(target, funcName).value;
489
+ }
490
+ let mParameters = methodArgsByFunction.get(origFunc);
492
491
  if (mParameters === undefined) {
493
492
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
494
493
  let designParamTypes = undefined;
495
494
  if (target) {
496
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
497
495
  designParamTypes = Reflect.getMetadata('design:paramtypes', target, funcName);
498
496
  }
499
497
  if (designParamTypes) {
500
498
  mParameters = designParamTypes.map((value, index) => new MethodParameter(index, value));
501
499
  }
502
500
  else {
503
- if (func) {
504
- const argnames = getArgNames(func);
501
+ if (origFunc) {
502
+ const argnames = getArgNames(origFunc);
505
503
  mParameters = argnames.map((_value, index) => new MethodParameter(index));
506
504
  }
507
505
  else {
@@ -511,44 +509,28 @@ function getOrCreateMethodArgsRegistration(target, className, funcName, func) {
511
509
  mParameters = argnames.map((_value, index) => new MethodParameter(index));
512
510
  }
513
511
  }
514
- methodArgsByFunction.set(mkey, mParameters);
512
+ methodArgsByFunction.set(origFunc, mParameters);
515
513
  }
516
514
  return mParameters;
517
515
  }
518
516
  exports.getOrCreateMethodArgsRegistration = getOrCreateMethodArgsRegistration;
519
517
  function getOrCreateMethodRegistration(target, className, propertyKey, func) {
520
- let regtarget = undefined;
521
- let isInstance = false;
522
- if (target) {
523
- if (typeof target === 'function') {
524
- // Static method case
525
- regtarget = target;
526
- }
527
- else {
528
- // Instance method case
529
- regtarget = target.constructor;
530
- isInstance = true;
531
- }
532
- }
533
- if (!className) {
534
- if (regtarget)
535
- className = regtarget.name;
536
- }
537
- if (!className) {
538
- className = '';
539
- }
540
- const classReg = getClassRegistrationByName(className, true);
518
+ let classReg;
519
+ let isInstance;
520
+ ({ classReg, isInstance, className } = getOrCreateClassRegistrationByName(target, className));
541
521
  const fname = propertyKey.toString();
542
- if (!classReg.registeredOperations.has(fname)) {
543
- classReg.registeredOperations.set(fname, new MethodRegistration(func, isInstance));
522
+ const origFunc = functionToRegistration.get(func)?.origFunction ?? func;
523
+ if (!classReg.allRegisteredOperations.has(origFunc)) {
524
+ const reg = new MethodRegistration(func, isInstance);
525
+ classReg.allRegisteredOperations.set(func, reg);
544
526
  }
545
- const methReg = classReg.registeredOperations.get(fname);
527
+ const methReg = classReg.allRegisteredOperations.get(func);
546
528
  if (methReg.needInitialized) {
547
529
  methReg.needInitialized = false;
548
530
  methReg.name = fname;
549
531
  methReg.className = classReg.name;
550
532
  methReg.defaults = classReg;
551
- methReg.args = getOrCreateMethodArgsRegistration(target, className, propertyKey, func);
533
+ methReg.args = getOrCreateMethodArgsRegistration(target, propertyKey, func);
552
534
  const argNames = getArgNames(func);
553
535
  methReg.args.forEach((e) => {
554
536
  if (!e.name) {
@@ -568,27 +550,54 @@ function getOrCreateMethodRegistration(target, className, propertyKey, func) {
568
550
  value: methReg.name,
569
551
  });
570
552
  methReg.registeredFunction = wrappedMethod;
571
- methodToRegistration.set(methReg.registeredFunction, methReg);
572
- methodToRegistration.set(methReg.origFunction, methReg);
553
+ functionToRegistration.set(methReg.registeredFunction, methReg);
554
+ functionToRegistration.set(methReg.origFunction, methReg);
573
555
  }
574
556
  return methReg;
575
557
  }
576
- function registerAndWrapDBOSFunction(target, propertyKey, descriptor) {
558
+ function wrapDBOSFunctionAndRegisterByUniqueNameDec(target, propertyKey, descriptor) {
559
+ if (!descriptor.value) {
560
+ throw Error('Use of decorator when original method is undefined');
561
+ }
562
+ const registration = wrapDBOSFunctionAndRegisterByUniqueName(target, undefined, propertyKey, descriptor.value);
563
+ descriptor.value = registration.wrappedFunction ?? registration.registeredFunction;
564
+ return { descriptor, registration };
565
+ }
566
+ exports.wrapDBOSFunctionAndRegisterByUniqueNameDec = wrapDBOSFunctionAndRegisterByUniqueNameDec;
567
+ function wrapDBOSFunctionAndRegisterByUniqueName(ctorOrProto, className, propertyKey, func) {
577
568
  ensureDBOSIsNotLaunched();
569
+ const name = typeof propertyKey === 'string' ? propertyKey : propertyKey.toString();
570
+ const freg = getFunctionRegistration(func);
571
+ if (freg) {
572
+ const r = getOrCreateClassRegistrationByName(ctorOrProto, className);
573
+ r.classReg.registerOperationByName(name, freg);
574
+ return freg;
575
+ }
576
+ const registration = getOrCreateMethodRegistration(ctorOrProto, className, propertyKey, func);
577
+ const r = getOrCreateClassRegistrationByName(ctorOrProto, className);
578
+ r.classReg.registerOperationByName(name, registration);
579
+ return registration;
580
+ }
581
+ exports.wrapDBOSFunctionAndRegisterByUniqueName = wrapDBOSFunctionAndRegisterByUniqueName;
582
+ function wrapDBOSFunctionAndRegisterDec(target, propertyKey, descriptor) {
578
583
  if (!descriptor.value) {
579
584
  throw Error('Use of decorator when original method is undefined');
580
585
  }
581
- const registration = getOrCreateMethodRegistration(target, undefined, propertyKey, descriptor.value);
586
+ const registration = wrapDBOSFunctionAndRegister(target, undefined, propertyKey, descriptor.value);
582
587
  descriptor.value = registration.wrappedFunction ?? registration.registeredFunction;
583
588
  return { descriptor, registration };
584
589
  }
585
- exports.registerAndWrapDBOSFunction = registerAndWrapDBOSFunction;
586
- function registerAndWrapDBOSFunctionByName(target, className, funcName, func) {
590
+ exports.wrapDBOSFunctionAndRegisterDec = wrapDBOSFunctionAndRegisterDec;
591
+ function wrapDBOSFunctionAndRegister(ctorOrProto, className, propertyKey, func) {
587
592
  ensureDBOSIsNotLaunched();
588
- const registration = getOrCreateMethodRegistration(target, className, funcName, func);
589
- return { registration };
593
+ const freg = getFunctionRegistration(func);
594
+ if (freg) {
595
+ return freg;
596
+ }
597
+ const registration = getOrCreateMethodRegistration(ctorOrProto, className, propertyKey, func);
598
+ return registration;
590
599
  }
591
- exports.registerAndWrapDBOSFunctionByName = registerAndWrapDBOSFunctionByName;
600
+ exports.wrapDBOSFunctionAndRegister = wrapDBOSFunctionAndRegister;
592
601
  const classesByName = new Map();
593
602
  const classesByCtor = new Map();
594
603
  function getNameForClass(ctor) {
@@ -614,6 +623,18 @@ function getAllRegisteredClassNames() {
614
623
  return cnames;
615
624
  }
616
625
  exports.getAllRegisteredClassNames = getAllRegisteredClassNames;
626
+ function getAllRegisteredFunctions() {
627
+ const s = new Set();
628
+ const fregs = [];
629
+ for (const [_f, reg] of functionToRegistration) {
630
+ if (s.has(reg))
631
+ continue;
632
+ fregs.push(reg);
633
+ s.add(reg);
634
+ }
635
+ return fregs;
636
+ }
637
+ exports.getAllRegisteredFunctions = getAllRegisteredFunctions;
617
638
  function getClassRegistrationByName(name, create = false) {
618
639
  if (!classesByName.has(name) && !create) {
619
640
  throw new error_1.DBOSNotRegisteredError(name, `Class '${name}' is not registered`);
@@ -642,54 +663,72 @@ function getOrCreateClassRegistration(ctor) {
642
663
  return clsReg;
643
664
  }
644
665
  exports.getOrCreateClassRegistration = getOrCreateClassRegistration;
645
- /**
646
- * Associates a class with a `DBOSEventReceiver`, which will be calling the class's DBOS methods.
647
- * Allows class-level default values or other storage to be associated with the class, rather than
648
- * separately for each registered method.
649
- *
650
- * @param rcvr - Event receiver which will dispatch DBOS methods from the class specified by `ctor`
651
- * @param ctor - Constructor of the class that is being registered and associated with `rcvr`
652
- * @returns - Class-specific registration info cumulatively collected for `rcvr`
653
- */
654
- function associateClassWithEventReceiver(rcvr, ctor) {
655
- const clsReg = getOrCreateClassRegistration(ctor);
656
- if (!clsReg.eventReceiverInfo.has(rcvr)) {
657
- clsReg.eventReceiverInfo.set(rcvr, {});
666
+ function getOrCreateClassRegistrationByName(target, className) {
667
+ let regtarget = undefined;
668
+ let isInstance = false;
669
+ if (target) {
670
+ if (typeof target === 'function') {
671
+ // Static method case
672
+ regtarget = target;
673
+ }
674
+ else {
675
+ // Instance method case
676
+ regtarget = target.constructor;
677
+ isInstance = true;
678
+ }
679
+ }
680
+ if (!className) {
681
+ if (regtarget)
682
+ className = regtarget.name;
658
683
  }
659
- return clsReg.eventReceiverInfo.get(rcvr);
684
+ if (!className) {
685
+ className = '';
686
+ }
687
+ const classReg = getClassRegistrationByName(className, true);
688
+ return { classReg, isInstance, className };
689
+ }
690
+ function getConfiguredInstance(clsname, cfgname) {
691
+ const classReg = classesByName.get(clsname)?.reg;
692
+ if (!classReg)
693
+ return null;
694
+ return classReg.configuredInstances.get(cfgname) ?? null;
660
695
  }
661
- exports.associateClassWithEventReceiver = associateClassWithEventReceiver;
696
+ exports.getConfiguredInstance = getConfiguredInstance;
697
+ // #endregion
698
+ // #region Transactional data source registration
699
+ exports.transactionalDataSources = new Map();
700
+ // Register data source (user version)
701
+ function registerTransactionalDataSource(name, ds) {
702
+ if (exports.transactionalDataSources.has(name)) {
703
+ if (exports.transactionalDataSources.get(name) !== ds) {
704
+ throw new error_1.DBOSConflictingRegistrationError(`Data source with name ${name} is already registered`);
705
+ }
706
+ return;
707
+ }
708
+ ensureDBOSIsNotLaunched();
709
+ exports.transactionalDataSources.set(name, ds);
710
+ }
711
+ exports.registerTransactionalDataSource = registerTransactionalDataSource;
712
+ function getTransactionalDataSource(name) {
713
+ if (exports.transactionalDataSources.has(name))
714
+ return exports.transactionalDataSources.get(name);
715
+ throw new error_1.DBOSNotRegisteredError(name, `Data source '${name}' is not registered`);
716
+ }
717
+ exports.getTransactionalDataSource = getTransactionalDataSource;
718
+ // #endregion
719
+ // #region External (event receiver v3)
662
720
  function associateClassWithExternal(external, cls) {
663
721
  const clsn = typeof cls === 'string' ? cls : getNameForClass(cls);
664
722
  const clsreg = getClassRegistrationByName(clsn, true);
665
723
  return clsreg.getRegisteredInfo(external);
666
724
  }
667
725
  exports.associateClassWithExternal = associateClassWithExternal;
668
- /**
669
- * Associates a workflow method with a `DBOSEventReceiver` which will be in charge of calling the method
670
- * in response to received events.
671
- * This version is to be used in "Stage 2" decorators, as it applies the DBOS wrapper to the registered method.
672
- *
673
- * @param rcvr - `DBOSEventReceiver` instance that should be informed of the `target` method's registration
674
- * @param target - A DBOS method to associate with the event receiver
675
- * @param propertyKey - For Stage 2 decorator use, this is the property key used for replacing the method with its wrapper
676
- * @param inDescriptor - For Stage 2 decorator use, this is the method descriptor used for replacing the method with its wrapper
677
- * @returns The new method descriptor, registration, and event receiver info
678
- */
679
- function associateMethodWithEventReceiver(rcvr, target, propertyKey, inDescriptor) {
680
- const { descriptor, registration } = registerAndWrapDBOSFunction(target, propertyKey, inDescriptor);
681
- if (!registration.eventReceiverInfo.has(rcvr)) {
682
- registration.eventReceiverInfo.set(rcvr, {});
683
- }
684
- return { descriptor, registration, receiverInfo: registration.eventReceiverInfo.get(rcvr) };
685
- }
686
- exports.associateMethodWithEventReceiver = associateMethodWithEventReceiver;
687
726
  /*
688
727
  * Associates a DBOS function or method with an external class or object.
689
728
  * Likely, this will be invoking or intercepting the method.
690
729
  */
691
730
  function associateMethodWithExternal(external, target, className, funcName, func) {
692
- const { registration } = registerAndWrapDBOSFunctionByName(target, className, funcName, func);
731
+ const registration = wrapDBOSFunctionAndRegister(target, className, funcName, func);
693
732
  if (!registration.externalRegInfo.has(external)) {
694
733
  registration.externalRegInfo.set(external, {});
695
734
  }
@@ -697,14 +736,14 @@ function associateMethodWithExternal(external, target, className, funcName, func
697
736
  }
698
737
  exports.associateMethodWithExternal = associateMethodWithExternal;
699
738
  /*
700
- * Associates a DBOS function or method with an external class or object.
739
+ * Associates a DBOS function or method parameters with an external class or object.
701
740
  * Likely, this will be invoking or intercepting the method.
702
741
  */
703
742
  function associateParameterWithExternal(external, target, className, funcName, func, paramId) {
704
743
  if (!func) {
705
744
  func = Object.getOwnPropertyDescriptor(target, funcName).value;
706
745
  }
707
- const { registration } = registerAndWrapDBOSFunctionByName(target, className, funcName, func);
746
+ const registration = wrapDBOSFunctionAndRegister(target, className, funcName, func);
708
747
  let param;
709
748
  if (typeof paramId === 'number') {
710
749
  param = registration.args[paramId];
@@ -721,13 +760,13 @@ function associateParameterWithExternal(external, target, className, funcName, f
721
760
  }
722
761
  exports.associateParameterWithExternal = associateParameterWithExternal;
723
762
  function getRegistrationsForExternal(external, cls, funcName) {
724
- const res = [];
763
+ const res = new Array();
725
764
  if (cls) {
726
765
  const clsname = typeof cls === 'string' ? cls : getNameForClass(cls);
727
766
  const c = classesByName.get(clsname);
728
767
  if (c) {
729
768
  if (funcName) {
730
- const f = c.reg.registeredOperations.get(funcName);
769
+ const f = c.reg.registeredOperationsByName.get(funcName);
731
770
  if (f) {
732
771
  collectRegForFunction(f);
733
772
  }
@@ -744,7 +783,7 @@ function getRegistrationsForExternal(external, cls, funcName) {
744
783
  }
745
784
  return res;
746
785
  function collectRegForClass(c) {
747
- for (const [_fn, f] of c.reg.registeredOperations) {
786
+ for (const f of c.reg.allRegisteredOperations.values()) {
748
787
  collectRegForFunction(f);
749
788
  }
750
789
  }
@@ -768,26 +807,18 @@ function getRegistrationsForExternal(external, cls, funcName) {
768
807
  }
769
808
  }
770
809
  exports.getRegistrationsForExternal = getRegistrationsForExternal;
771
- //////////////////////////
772
- /* PARAMETER DECORATORS */
773
- //////////////////////////
810
+ // #endregion
811
+ // #region Parameter decorators
774
812
  function ArgName(name) {
775
813
  return function (target, propertyKey, parameterIndex) {
776
- const existingParameters = getOrCreateMethodArgsRegistration(target, undefined, propertyKey);
814
+ const existingParameters = getOrCreateMethodArgsRegistration(target, propertyKey);
777
815
  const curParam = existingParameters[parameterIndex];
778
816
  curParam.name = name;
779
817
  };
780
818
  }
781
819
  exports.ArgName = ArgName;
782
- ///////////////////////
783
- /* CLASS DECORATORS */
784
- ///////////////////////
785
- /** @deprecated Use `new` */
786
- function configureInstance(cls, name, ...args) {
787
- const inst = new cls(name, ...args);
788
- return inst;
789
- }
790
- exports.configureInstance = configureInstance;
820
+ // #endregion
821
+ // #region Class decorators
791
822
  /**
792
823
  * @deprecated Use ORM DSs
793
824
  */
@@ -800,13 +831,16 @@ function OrmEntities(entities = []) {
800
831
  return clsdec;
801
832
  }
802
833
  exports.OrmEntities = OrmEntities;
834
+ // #endregion
835
+ // #region Method decorators
803
836
  function DBOSInitializer() {
804
837
  function decorator(target, propertyKey, inDescriptor) {
805
- const { descriptor, registration } = registerAndWrapDBOSFunction(target, propertyKey, inDescriptor);
838
+ const { descriptor, registration } = wrapDBOSFunctionAndRegisterByUniqueNameDec(target, propertyKey, inDescriptor);
806
839
  registration.init = true;
807
840
  return descriptor;
808
841
  }
809
842
  return decorator;
810
843
  }
811
844
  exports.DBOSInitializer = DBOSInitializer;
845
+ // #endregion
812
846
  //# sourceMappingURL=decorators.js.map