@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.
- package/dist/src/datasource.d.ts +11 -6
- package/dist/src/datasource.d.ts.map +1 -1
- package/dist/src/datasource.js +9 -6
- package/dist/src/datasource.js.map +1 -1
- package/dist/src/dbos-executor.d.ts +51 -89
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +61 -284
- package/dist/src/dbos-executor.js.map +1 -1
- package/dist/src/dbos-runtime/config.d.ts +6 -4
- package/dist/src/dbos-runtime/config.d.ts.map +1 -1
- package/dist/src/dbos-runtime/config.js +59 -28
- package/dist/src/dbos-runtime/config.js.map +1 -1
- package/dist/src/dbos-runtime/migrate.js +3 -3
- package/dist/src/dbos-runtime/migrate.js.map +1 -1
- package/dist/src/dbos-runtime/runtime.d.ts +1 -1
- package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
- package/dist/src/dbos-runtime/runtime.js +4 -14
- package/dist/src/dbos-runtime/runtime.js.map +1 -1
- package/dist/src/dbos.d.ts +27 -65
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +107 -122
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/decorators.d.ts +51 -57
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +234 -200
- package/dist/src/decorators.js.map +1 -1
- package/dist/src/httpServer/handler.d.ts +1 -1
- package/dist/src/httpServer/handler.d.ts.map +1 -1
- package/dist/src/httpServer/handler.js +1 -1
- package/dist/src/httpServer/handler.js.map +1 -1
- package/dist/src/httpServer/middleware.d.ts +0 -1
- package/dist/src/httpServer/middleware.d.ts.map +1 -1
- package/dist/src/httpServer/middleware.js.map +1 -1
- package/dist/src/httpServer/server.d.ts.map +1 -1
- package/dist/src/httpServer/server.js +4 -6
- package/dist/src/httpServer/server.js.map +1 -1
- package/dist/src/index.d.ts +3 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/paramdecorators.d.ts +6 -6
- package/dist/src/paramdecorators.d.ts.map +1 -1
- package/dist/src/paramdecorators.js.map +1 -1
- package/dist/src/scheduler/crontab.d.ts +3 -8
- package/dist/src/scheduler/crontab.d.ts.map +1 -1
- package/dist/src/scheduler/crontab.js +24 -23
- package/dist/src/scheduler/crontab.js.map +1 -1
- package/dist/src/scheduler/scheduler.d.ts +10 -31
- package/dist/src/scheduler/scheduler.d.ts.map +1 -1
- package/dist/src/scheduler/scheduler.js +100 -135
- package/dist/src/scheduler/scheduler.js.map +1 -1
- package/dist/src/system_database.d.ts +5 -6
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.js +14 -1
- package/dist/src/system_database.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +14 -4
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.cjs +6 -1
- package/package.json +1 -1
- package/dist/src/eventreceiver.d.ts +0 -152
- package/dist/src/eventreceiver.d.ts.map +0 -1
- package/dist/src/eventreceiver.js +0 -3
- package/dist/src/eventreceiver.js.map +0 -1
package/dist/src/dbos.js
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.InitContext = exports.DBOS = exports.runInternalStep = exports.getExecutor = void 0;
|
4
7
|
const context_1 = require("./context");
|
@@ -8,6 +11,7 @@ const logs_1 = require("./telemetry/logs");
|
|
8
11
|
const error_1 = require("./error");
|
9
12
|
const config_1 = require("./dbos-runtime/config");
|
10
13
|
const runtime_1 = require("./dbos-runtime/runtime");
|
14
|
+
const scheduler_1 = require("./scheduler/scheduler");
|
11
15
|
const decorators_1 = require("./decorators");
|
12
16
|
const utils_1 = require("./utils");
|
13
17
|
const server_1 = require("./httpServer/server");
|
@@ -17,14 +21,13 @@ const node_crypto_1 = require("node:crypto");
|
|
17
21
|
const _1 = require(".");
|
18
22
|
const _2 = require(".");
|
19
23
|
const handlerTypes_1 = require("./httpServer/handlerTypes");
|
20
|
-
const lodash_1 = require("lodash");
|
21
24
|
const conductor_1 = require("./conductor/conductor");
|
22
|
-
const system_database_1 = require("./system_database");
|
23
25
|
const wfqueue_1 = require("./wfqueue");
|
24
26
|
const authdecorators_1 = require("./authdecorators");
|
27
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
25
28
|
function httpApiDec(verb, url) {
|
26
29
|
return function apidec(target, propertyKey, inDescriptor) {
|
27
|
-
const { descriptor, registration } = (0, decorators_1.
|
30
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterDec)(target, propertyKey, inDescriptor);
|
28
31
|
const handlerRegistration = registration;
|
29
32
|
handlerRegistration.apiURL = url;
|
30
33
|
handlerRegistration.apiType = verb;
|
@@ -62,49 +65,13 @@ class DBOS {
|
|
62
65
|
static adminServer = undefined;
|
63
66
|
static appServer = undefined;
|
64
67
|
static conductor = undefined;
|
65
|
-
static getDebugModeFromEnv() {
|
66
|
-
const debugWorkflowId = process.env.DBOS_DEBUG_WORKFLOW_ID;
|
67
|
-
return debugWorkflowId !== undefined;
|
68
|
-
}
|
69
68
|
/**
|
70
69
|
* Set configuration of `DBOS` prior to `launch`
|
71
70
|
* @param config - configuration of services needed by DBOS
|
72
|
-
* @param runtimeConfig - configuration of runtime access to DBOS
|
73
71
|
*/
|
74
|
-
static setConfig(config
|
72
|
+
static setConfig(config) {
|
73
|
+
(0, node_assert_1.default)(!DBOS.isInitialized(), 'Cannot call DBOS.setConfig after DBOS.launch');
|
75
74
|
DBOS.#dbosConfig = config;
|
76
|
-
DBOS.#runtimeConfig = runtimeConfig;
|
77
|
-
DBOS.translateConfig();
|
78
|
-
}
|
79
|
-
static translateConfig() {
|
80
|
-
if (DBOS.#dbosConfig && !(0, dbos_executor_1.isDeprecatedDBOSConfig)(DBOS.#dbosConfig)) {
|
81
|
-
const debugMode = DBOS.getDebugModeFromEnv();
|
82
|
-
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.translatePublicDBOSconfig)(DBOS.#dbosConfig, debugMode);
|
83
|
-
if (process.env.DBOS__CLOUD === 'true') {
|
84
|
-
[DBOS.#dbosConfig, DBOS.#runtimeConfig] = (0, config_1.overwrite_config)(DBOS.#dbosConfig, DBOS.#runtimeConfig);
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* @deprecated For unit testing purposes only
|
90
|
-
* Use `setConfig`
|
91
|
-
*/
|
92
|
-
static setAppConfig(key, newValue) {
|
93
|
-
const conf = DBOS.#dbosConfig?.application;
|
94
|
-
if (!conf)
|
95
|
-
throw new error_1.DBOSExecutorNotInitializedError();
|
96
|
-
(0, lodash_1.set)(conf, key, newValue);
|
97
|
-
}
|
98
|
-
/**
|
99
|
-
* Drop DBOS system database.
|
100
|
-
* USE IN TESTS ONLY - ALL WORKFLOWS, QUEUES, ETC. WILL BE LOST.
|
101
|
-
*/
|
102
|
-
static async dropSystemDB() {
|
103
|
-
if (!DBOS.#dbosConfig) {
|
104
|
-
DBOS.#dbosConfig = (0, config_1.parseConfigFile)()[0];
|
105
|
-
}
|
106
|
-
DBOS.translateConfig();
|
107
|
-
return system_database_1.PostgresSystemDatabase.dropSystemDB(DBOS.#dbosConfig);
|
108
75
|
}
|
109
76
|
/**
|
110
77
|
* Use ORMEntities to set up database schema.
|
@@ -141,25 +108,55 @@ class DBOS {
|
|
141
108
|
if (DBOS.isInitialized()) {
|
142
109
|
return;
|
143
110
|
}
|
144
|
-
const debugMode = options?.debugMode ?? DBOS.getDebugModeFromEnv();
|
145
111
|
if (options?.conductorKey) {
|
146
112
|
// Use a generated executor ID.
|
147
113
|
utils_1.globalParams.executorID = (0, node_crypto_1.randomUUID)();
|
148
114
|
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
115
|
+
const debugMode = options?.debugMode ?? process.env.DBOS_DEBUG_WORKFLOW_ID !== undefined;
|
116
|
+
const configFile = (0, config_1.readConfigFile)();
|
117
|
+
const $dbosConfig = DBOS.#dbosConfig;
|
118
|
+
let [internalConfig, runtimeConfig] = $dbosConfig
|
119
|
+
? (0, config_1.translatePublicDBOSconfig)(
|
120
|
+
// copy config settings to ensure no unexpected fields are passed thru
|
121
|
+
{
|
122
|
+
adminPort: $dbosConfig.adminPort,
|
123
|
+
name: $dbosConfig.name,
|
124
|
+
databaseUrl: $dbosConfig.databaseUrl,
|
125
|
+
userDbclient: $dbosConfig.userDbclient,
|
126
|
+
userDbPoolSize: $dbosConfig.userDbPoolSize,
|
127
|
+
sysDbName: $dbosConfig.sysDbName,
|
128
|
+
sysDbPoolSize: $dbosConfig.sysDbPoolSize,
|
129
|
+
logLevel: $dbosConfig.logLevel,
|
130
|
+
addContextMetadata: $dbosConfig.addContextMetadata,
|
131
|
+
runAdminServer: $dbosConfig.runAdminServer,
|
132
|
+
otlpTracesEndpoints: [...($dbosConfig.otlpTracesEndpoints ?? [])],
|
133
|
+
otlpLogsEndpoints: [...($dbosConfig.otlpLogsEndpoints ?? [])],
|
134
|
+
}, debugMode)
|
135
|
+
: (0, config_1.processConfigFile)(configFile, { forceConsole: debugMode });
|
136
|
+
if (process.env.DBOS__CLOUD === 'true') {
|
137
|
+
[internalConfig, runtimeConfig] = (0, config_1.overwrite_config)(internalConfig, runtimeConfig, configFile);
|
138
|
+
}
|
139
|
+
DBOS.#port = runtimeConfig.port;
|
140
|
+
DBOS.#poolConfig = internalConfig.poolConfig;
|
141
|
+
DBOS.#dbosConfig = {
|
142
|
+
name: internalConfig.name,
|
143
|
+
databaseUrl: internalConfig.databaseUrl,
|
144
|
+
userDbclient: internalConfig.userDbclient,
|
145
|
+
userDbPoolSize: DBOS.#dbosConfig?.userDbPoolSize,
|
146
|
+
sysDbName: internalConfig.system_database,
|
147
|
+
sysDbPoolSize: internalConfig.sysDbPoolSize,
|
148
|
+
logLevel: internalConfig.telemetry.logs?.logLevel,
|
149
|
+
addContextMetadata: internalConfig.telemetry.logs?.addContextMetadata,
|
150
|
+
otlpTracesEndpoints: [...(internalConfig.telemetry.OTLPExporter?.tracesEndpoint ?? [])],
|
151
|
+
otlpLogsEndpoints: [...(internalConfig.telemetry.OTLPExporter?.logsEndpoint ?? [])],
|
152
|
+
adminPort: runtimeConfig.admin_port,
|
153
|
+
runAdminServer: runtimeConfig.runAdminServer,
|
154
|
+
};
|
155
|
+
if (utils_1.globalParams.appName === '' && DBOS.#dbosConfig.name) {
|
156
|
+
utils_1.globalParams.appName = DBOS.#dbosConfig.name;
|
158
157
|
}
|
159
158
|
dbos_executor_1.DBOSExecutor.createInternalQueue();
|
160
|
-
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(
|
161
|
-
debugMode,
|
162
|
-
});
|
159
|
+
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(internalConfig, { debugMode });
|
163
160
|
const executor = dbos_executor_1.DBOSExecutor.globalInstance;
|
164
161
|
await executor.init();
|
165
162
|
const debugWorkflowId = process.env.DBOS_DEBUG_WORKFLOW_ID;
|
@@ -186,14 +183,14 @@ class DBOS {
|
|
186
183
|
}
|
187
184
|
// Start the DBOS admin server
|
188
185
|
const logger = DBOS.logger;
|
189
|
-
if (
|
186
|
+
if (runtimeConfig.runAdminServer) {
|
190
187
|
const adminApp = server_1.DBOSHttpServer.setupAdminApp(executor);
|
191
188
|
try {
|
192
|
-
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(
|
189
|
+
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(runtimeConfig.admin_port, logger);
|
193
190
|
// Wrap the listen call in a promise to properly catch errors
|
194
191
|
DBOS.adminServer = await new Promise((resolve, reject) => {
|
195
|
-
const server = adminApp.listen(
|
196
|
-
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${
|
192
|
+
const server = adminApp.listen(runtimeConfig?.admin_port, () => {
|
193
|
+
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${runtimeConfig?.admin_port}`);
|
197
194
|
resolve(server);
|
198
195
|
});
|
199
196
|
server.on('error', (err) => {
|
@@ -202,7 +199,7 @@ class DBOS {
|
|
202
199
|
});
|
203
200
|
}
|
204
201
|
catch (e) {
|
205
|
-
logger.warn(`Unable to start DBOS admin server on port ${
|
202
|
+
logger.warn(`Unable to start DBOS admin server on port ${runtimeConfig.admin_port}`);
|
206
203
|
}
|
207
204
|
}
|
208
205
|
if (options?.koaApp) {
|
@@ -242,11 +239,7 @@ class DBOS {
|
|
242
239
|
if (!dbos_executor_1.DBOSExecutor.globalInstance)
|
243
240
|
return;
|
244
241
|
dbos_executor_1.DBOSExecutor.globalInstance.logRegisteredHTTPUrls();
|
245
|
-
dbos_executor_1.DBOSExecutor.globalInstance.scheduler?.logRegisteredSchedulerEndpoints();
|
246
242
|
wfqueue_1.wfQueueRunner.logRegisteredEndpoints(dbos_executor_1.DBOSExecutor.globalInstance);
|
247
|
-
for (const evtRcvr of dbos_executor_1.DBOSExecutor.globalInstance.eventReceivers) {
|
248
|
-
evtRcvr.logRegisteredEndpoints();
|
249
|
-
}
|
250
243
|
for (const lcl of (0, decorators_1.getLifecycleListeners)()) {
|
251
244
|
lcl.logRegisteredEndpoints?.();
|
252
245
|
}
|
@@ -325,9 +318,9 @@ class DBOS {
|
|
325
318
|
*/
|
326
319
|
static async launchAppHTTPServer() {
|
327
320
|
const server = DBOS.setUpHandlerCallback();
|
328
|
-
if (DBOS.#
|
321
|
+
if (DBOS.#port) {
|
329
322
|
// This will not listen if there's no decorated endpoint
|
330
|
-
DBOS.appServer = await server.appListen(DBOS.#
|
323
|
+
DBOS.appServer = await server.appListen(DBOS.#port);
|
331
324
|
}
|
332
325
|
}
|
333
326
|
/**
|
@@ -353,9 +346,10 @@ class DBOS {
|
|
353
346
|
// Globals
|
354
347
|
//////
|
355
348
|
static #dbosConfig;
|
356
|
-
static #
|
349
|
+
static #poolConfig;
|
350
|
+
static #port;
|
357
351
|
static get dbosConfig() {
|
358
|
-
return DBOS.#dbosConfig;
|
352
|
+
return { ...DBOS.#dbosConfig, poolConfig: DBOS.#poolConfig };
|
359
353
|
}
|
360
354
|
//////
|
361
355
|
// Context
|
@@ -543,17 +537,6 @@ class DBOS {
|
|
543
537
|
const client = DBOS.sqlClient;
|
544
538
|
return client;
|
545
539
|
}
|
546
|
-
/**
|
547
|
-
* Gets configuration information from the `application` section
|
548
|
-
* of `DBOSConfig`
|
549
|
-
* @param key - name of configuration item
|
550
|
-
* @param defaultValue - value to return if `key` does not exist in the configuration
|
551
|
-
*/
|
552
|
-
static getConfig(key, defaultValue) {
|
553
|
-
if (DBOS.#executor)
|
554
|
-
return DBOS.#executor.getConfig(key, defaultValue);
|
555
|
-
return defaultValue;
|
556
|
-
}
|
557
540
|
/**
|
558
541
|
* Query the current application database
|
559
542
|
* @param sql - parameterized SQL statement (string) to execute
|
@@ -921,7 +904,7 @@ class DBOS {
|
|
921
904
|
const regOps = (0, decorators_1.getRegisteredOperations)(target);
|
922
905
|
const handler = {
|
923
906
|
apply(target, _thisArg, args) {
|
924
|
-
const regOp = (0, decorators_1.
|
907
|
+
const regOp = (0, decorators_1.getFunctionRegistration)(target);
|
925
908
|
if (!regOp) {
|
926
909
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
927
910
|
const name = typeof target === 'function' ? target.name : target.toString();
|
@@ -932,7 +915,7 @@ class DBOS {
|
|
932
915
|
get(target, p, receiver) {
|
933
916
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
934
917
|
const func = Reflect.get(target, p, receiver);
|
935
|
-
const regOp = (0, decorators_1.
|
918
|
+
const regOp = (0, decorators_1.getFunctionRegistration)(func) ?? regOps.find((op) => op.name === p);
|
936
919
|
if (regOp) {
|
937
920
|
return (...args) => DBOS.#invokeWorkflow(instance, regOp, args, params);
|
938
921
|
}
|
@@ -964,7 +947,7 @@ class DBOS {
|
|
964
947
|
const functionID = (0, context_1.functionIDGetIncrement)();
|
965
948
|
return await dbos_executor_1.DBOSExecutor.globalInstance.systemDatabase.send(DBOS.workflowID, functionID, destinationID, utils_1.DBOSJSON.stringify(message), topic);
|
966
949
|
}
|
967
|
-
return DBOS.#executor.
|
950
|
+
return DBOS.#executor.runSendTempWF(destinationID, message, topic, idempotencyKey); // Temp WF variant
|
968
951
|
}
|
969
952
|
/**
|
970
953
|
* Receive a message on optional `topic` from within a workflow.
|
@@ -1036,21 +1019,33 @@ class DBOS {
|
|
1036
1019
|
}
|
1037
1020
|
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1038
1021
|
}
|
1022
|
+
/**
|
1023
|
+
* registers a workflow method or function with an invocation schedule
|
1024
|
+
* @param func - The workflow method or function to register with an invocation schedule
|
1025
|
+
* @param options - Configuration information for the scheduled workflow
|
1026
|
+
*/
|
1027
|
+
static registerScheduled(func, config) {
|
1028
|
+
scheduler_1.ScheduledReceiver.registerScheduled(func, config);
|
1029
|
+
}
|
1039
1030
|
//////
|
1040
1031
|
// Decorators
|
1041
1032
|
//////
|
1042
1033
|
/**
|
1043
1034
|
* Decorator associating a class static method with an invocation schedule
|
1044
|
-
* @param
|
1045
|
-
*/
|
1046
|
-
static scheduled(
|
1047
|
-
function
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1035
|
+
* @param config - The schedule, consisting of a crontab and policy for "make-up work"
|
1036
|
+
*/
|
1037
|
+
static scheduled(config) {
|
1038
|
+
function methodDecorator(target, propertyKey, descriptor) {
|
1039
|
+
if (descriptor.value) {
|
1040
|
+
DBOS.registerScheduled(descriptor.value, {
|
1041
|
+
...config,
|
1042
|
+
ctorOrProto: target,
|
1043
|
+
name: String(propertyKey),
|
1044
|
+
});
|
1045
|
+
}
|
1051
1046
|
return descriptor;
|
1052
1047
|
}
|
1053
|
-
return
|
1048
|
+
return methodDecorator;
|
1054
1049
|
}
|
1055
1050
|
/**
|
1056
1051
|
* Decorator designating a method as a DBOS workflow
|
@@ -1060,10 +1055,11 @@ class DBOS {
|
|
1060
1055
|
*/
|
1061
1056
|
static workflow(config = {}) {
|
1062
1057
|
function decorator(target, propertyKey, inDescriptor) {
|
1063
|
-
const { descriptor, registration } = (0, decorators_1.
|
1058
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1064
1059
|
const invoker = DBOS.#getWorkflowInvoker(registration, config);
|
1065
1060
|
descriptor.value = invoker;
|
1066
1061
|
registration.wrappedFunction = invoker;
|
1062
|
+
(0, decorators_1.registerFunctionWrapper)(invoker, registration);
|
1067
1063
|
return descriptor;
|
1068
1064
|
}
|
1069
1065
|
return decorator;
|
@@ -1077,9 +1073,9 @@ class DBOS {
|
|
1077
1073
|
* @param name - The name of the registered workflow
|
1078
1074
|
* @param options - Configuration information for the registered workflow
|
1079
1075
|
*/
|
1080
|
-
static registerWorkflow(func,
|
1081
|
-
const
|
1082
|
-
return DBOS.#getWorkflowInvoker(registration,
|
1076
|
+
static registerWorkflow(func, config) {
|
1077
|
+
const registration = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueName)(config?.ctorOrProto, config?.className, config?.name ?? func.name, func);
|
1078
|
+
return DBOS.#getWorkflowInvoker(registration, config);
|
1083
1079
|
}
|
1084
1080
|
static async #invokeWorkflow($this, regOP, args, params = {}) {
|
1085
1081
|
const wfId = (0, context_1.getNextWFID)(params.workflowID);
|
@@ -1169,7 +1165,7 @@ class DBOS {
|
|
1169
1165
|
*/
|
1170
1166
|
static transaction(config = {}) {
|
1171
1167
|
function decorator(target, propertyKey, inDescriptor) {
|
1172
|
-
const { descriptor, registration } = (0, decorators_1.
|
1168
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1173
1169
|
registration.setTxnConfig(config);
|
1174
1170
|
const invokeWrapper = async function (...rawArgs) {
|
1175
1171
|
let inst = undefined;
|
@@ -1207,10 +1203,11 @@ class DBOS {
|
|
1207
1203
|
configuredInstance: inst,
|
1208
1204
|
workflowUUID: wfId,
|
1209
1205
|
};
|
1210
|
-
return await DBOS.#executor.
|
1206
|
+
return await DBOS.#executor.runTransactionTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1211
1207
|
};
|
1212
1208
|
descriptor.value = invokeWrapper;
|
1213
1209
|
registration.wrappedFunction = invokeWrapper;
|
1210
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1214
1211
|
Object.defineProperty(invokeWrapper, 'name', {
|
1215
1212
|
value: registration.name,
|
1216
1213
|
});
|
@@ -1226,7 +1223,7 @@ class DBOS {
|
|
1226
1223
|
*/
|
1227
1224
|
static storedProcedure(config = {}) {
|
1228
1225
|
function decorator(target, propertyKey, inDescriptor) {
|
1229
|
-
const { descriptor, registration } = (0, decorators_1.
|
1226
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1230
1227
|
registration.setProcConfig(config);
|
1231
1228
|
const invokeWrapper = async function (...rawArgs) {
|
1232
1229
|
if (typeof this !== 'function') {
|
@@ -1250,10 +1247,11 @@ class DBOS {
|
|
1250
1247
|
const wfParams = {
|
1251
1248
|
workflowUUID: wfId,
|
1252
1249
|
};
|
1253
|
-
return await DBOS.#executor.
|
1250
|
+
return await DBOS.#executor.runProcedureTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1254
1251
|
};
|
1255
1252
|
descriptor.value = invokeWrapper;
|
1256
1253
|
registration.wrappedFunction = invokeWrapper;
|
1254
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1257
1255
|
Object.defineProperty(invokeWrapper, 'name', {
|
1258
1256
|
value: registration.name,
|
1259
1257
|
});
|
@@ -1271,7 +1269,7 @@ class DBOS {
|
|
1271
1269
|
*/
|
1272
1270
|
static step(config = {}) {
|
1273
1271
|
function decorator(target, propertyKey, inDescriptor) {
|
1274
|
-
const { descriptor, registration } = (0, decorators_1.
|
1272
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1275
1273
|
registration.setStepConfig(config);
|
1276
1274
|
const invokeWrapper = async function (...rawArgs) {
|
1277
1275
|
let inst = undefined;
|
@@ -1310,10 +1308,11 @@ class DBOS {
|
|
1310
1308
|
configuredInstance: inst,
|
1311
1309
|
workflowUUID: wfId,
|
1312
1310
|
};
|
1313
|
-
return await DBOS.#executor.
|
1311
|
+
return await DBOS.#executor.runStepTempWF(registration.registeredFunction, wfParams, ...rawArgs);
|
1314
1312
|
};
|
1315
1313
|
descriptor.value = invokeWrapper;
|
1316
1314
|
registration.wrappedFunction = invokeWrapper;
|
1315
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1317
1316
|
Object.defineProperty(invokeWrapper, 'name', {
|
1318
1317
|
value: registration.name,
|
1319
1318
|
});
|
@@ -1328,29 +1327,31 @@ class DBOS {
|
|
1328
1327
|
* This ensures "at least once" execution of the step, and that the step will not
|
1329
1328
|
* be executed again once the checkpoint is recorded
|
1330
1329
|
* @param func - The function to register as a step
|
1331
|
-
* @param config - Configuration information for the step, particularly the retry policy
|
1332
|
-
* @param config.name - The name of the step; if not provided, the function name will be used
|
1330
|
+
* @param config - Configuration information for the step, particularly the retry policy and name
|
1333
1331
|
*/
|
1334
1332
|
static registerStep(func, config = {}) {
|
1335
1333
|
const name = config.name ?? func.name;
|
1334
|
+
const reg = (0, decorators_1.wrapDBOSFunctionAndRegister)(config?.ctorOrProto, config?.className, name, func);
|
1336
1335
|
const invokeWrapper = async function (...rawArgs) {
|
1337
1336
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
1338
1337
|
const inst = this;
|
1338
|
+
const callFunc = reg.registeredFunction ?? reg.origFunction;
|
1339
1339
|
if (DBOS.isWithinWorkflow()) {
|
1340
1340
|
if (DBOS.isInTransaction()) {
|
1341
1341
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `step` function from within a `transaction`');
|
1342
1342
|
}
|
1343
1343
|
if (DBOS.isInStep()) {
|
1344
1344
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1345
|
-
return
|
1345
|
+
return callFunc.call(this, ...rawArgs);
|
1346
1346
|
}
|
1347
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(
|
1347
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(callFunc, name, config, inst ?? null, ...rawArgs);
|
1348
1348
|
}
|
1349
1349
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1350
1350
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|
1351
1351
|
}
|
1352
|
-
return
|
1352
|
+
return callFunc.call(this, ...rawArgs);
|
1353
1353
|
};
|
1354
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, reg);
|
1354
1355
|
Object.defineProperty(invokeWrapper, 'name', { value: name });
|
1355
1356
|
return invokeWrapper;
|
1356
1357
|
}
|
@@ -1430,14 +1431,6 @@ class DBOS {
|
|
1430
1431
|
/////
|
1431
1432
|
// Registration, etc
|
1432
1433
|
/////
|
1433
|
-
/**
|
1434
|
-
* Construct and register an object.
|
1435
|
-
* Calling this is not necessary; calling the constructor of any `ConfiguredInstance` subclass is sufficient
|
1436
|
-
* @deprecated Use `new` directly
|
1437
|
-
*/
|
1438
|
-
static configureInstance(cls, name, ...args) {
|
1439
|
-
return (0, decorators_1.configureInstance)(cls, name, ...args);
|
1440
|
-
}
|
1441
1434
|
/**
|
1442
1435
|
* Register a lifecycle listener
|
1443
1436
|
*/
|
@@ -1460,13 +1453,13 @@ class DBOS {
|
|
1460
1453
|
* Register information to be associated with a DBOS function
|
1461
1454
|
*/
|
1462
1455
|
static associateFunctionWithInfo(external, func, target) {
|
1463
|
-
return (0, decorators_1.associateMethodWithExternal)(external, target.ctorOrProto, target.className, target.name, func);
|
1456
|
+
return (0, decorators_1.associateMethodWithExternal)(external, target.ctorOrProto, target.className, target.name ?? func.name, func);
|
1464
1457
|
}
|
1465
1458
|
/**
|
1466
1459
|
* Register information to be associated with a DBOS function
|
1467
1460
|
*/
|
1468
1461
|
static associateParamWithInfo(external, func, target) {
|
1469
|
-
return (0, decorators_1.associateParameterWithExternal)(external, target.ctorOrProto, target.className, target.name, func, target.param);
|
1462
|
+
return (0, decorators_1.associateParameterWithExternal)(external, target.ctorOrProto, target.className, target.name ?? func.name, func, target.param);
|
1470
1463
|
}
|
1471
1464
|
/** Get registrations */
|
1472
1465
|
static getAssociatedInfo(external, cls, funcName) {
|
@@ -1487,14 +1480,6 @@ class InitContext {
|
|
1487
1480
|
queryUserDB(sql, ...params) {
|
1488
1481
|
return DBOS.queryUserDB(sql, params);
|
1489
1482
|
}
|
1490
|
-
getConfig(key, defaultValue) {
|
1491
|
-
const value = DBOS.getConfig(key, defaultValue);
|
1492
|
-
// If the key is found and the default value is provided, check whether the value is of the same type.
|
1493
|
-
if (value && defaultValue && typeof value !== typeof defaultValue) {
|
1494
|
-
throw new error_1.DBOSConfigKeyTypeError(key, typeof defaultValue, typeof value);
|
1495
|
-
}
|
1496
|
-
return value;
|
1497
|
-
}
|
1498
1483
|
}
|
1499
1484
|
exports.InitContext = InitContext;
|
1500
1485
|
//# sourceMappingURL=dbos.js.map
|