@dbos-inc/dbos-sdk 3.0.38-preview.g8bb2030562 → 3.0.42-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 +3 -9
- package/dist/src/datasource.d.ts.map +1 -1
- package/dist/src/datasource.js +7 -7
- package/dist/src/datasource.js.map +1 -1
- package/dist/src/dbos-executor.d.ts +23 -25
- package/dist/src/dbos-executor.d.ts.map +1 -1
- package/dist/src/dbos-executor.js +5 -43
- package/dist/src/dbos-executor.js.map +1 -1
- package/dist/src/dbos-runtime/cli.js +2 -2
- package/dist/src/dbos-runtime/cli.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 +90 -54
- package/dist/src/dbos-runtime/config.js.map +1 -1
- package/dist/src/dbos-runtime/docker_pg_helper.d.ts +3 -0
- package/dist/src/dbos-runtime/docker_pg_helper.d.ts.map +1 -1
- package/dist/src/dbos-runtime/docker_pg_helper.js +17 -4
- package/dist/src/dbos-runtime/docker_pg_helper.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 -5
- package/dist/src/dbos-runtime/runtime.js.map +1 -1
- package/dist/src/dbos.d.ts +84 -52
- package/dist/src/dbos.d.ts.map +1 -1
- package/dist/src/dbos.js +162 -112
- package/dist/src/dbos.js.map +1 -1
- package/dist/src/decorators.d.ts +28 -6
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +91 -44
- package/dist/src/decorators.js.map +1 -1
- package/dist/src/error.d.ts +1 -1
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +5 -5
- package/dist/src/error.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.map +1 -1
- package/dist/src/httpServer/middleware.d.ts +6 -1
- package/dist/src/httpServer/middleware.d.ts.map +1 -1
- package/dist/src/httpServer/middleware.js +5 -0
- 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 +0 -3
- package/dist/src/httpServer/server.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/paramdecorators.d.ts +15 -6
- package/dist/src/paramdecorators.d.ts.map +1 -1
- package/dist/src/paramdecorators.js +9 -0
- 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 -136
- package/dist/src/scheduler/scheduler.js.map +1 -1
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.js +27 -6
- package/dist/src/system_database.js.map +1 -1
- package/dist/src/telemetry/exporters.d.ts +2 -2
- package/dist/src/telemetry/exporters.d.ts.map +1 -1
- package/dist/src/telemetry/exporters.js +3 -2
- package/dist/src/telemetry/exporters.js.map +1 -1
- package/dist/src/user_database.d.ts.map +1 -1
- package/dist/src/user_database.js +7 -1
- package/dist/src/user_database.js.map +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +19 -5
- package/dist/src/utils.js.map +1 -1
- package/dist/src/workflow.d.ts +5 -4
- package/dist/src/workflow.d.ts.map +1 -1
- package/dist/src/workflow.js +4 -3
- package/dist/src/workflow.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.cjs +6 -1
- package/package.json +2 -8
- package/dist/src/dbos-runtime/cloudutils/authentication.d.ts +0 -7
- package/dist/src/dbos-runtime/cloudutils/authentication.d.ts.map +0 -1
- package/dist/src/dbos-runtime/cloudutils/authentication.js +0 -101
- package/dist/src/dbos-runtime/cloudutils/authentication.js.map +0 -1
- package/dist/src/dbos-runtime/cloudutils/cloudutils.d.ts +0 -50
- package/dist/src/dbos-runtime/cloudutils/cloudutils.d.ts.map +0 -1
- package/dist/src/dbos-runtime/cloudutils/cloudutils.js +0 -262
- package/dist/src/dbos-runtime/cloudutils/cloudutils.js.map +0 -1
- package/dist/src/dbos-runtime/cloudutils/databases.d.ts +0 -21
- package/dist/src/dbos-runtime/cloudutils/databases.d.ts.map +0 -1
- package/dist/src/dbos-runtime/cloudutils/databases.js +0 -190
- package/dist/src/dbos-runtime/cloudutils/databases.js.map +0 -1
- package/src/dbos-runtime/cloudutils/README.md +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,53 +65,18 @@ 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.
|
111
78
|
* Only relevant for TypeORM, and for testing purposes only, not production
|
79
|
+
* @deprecated - use data source packages such as `@dbos-inc/typeorm-datasource`
|
112
80
|
*/
|
113
81
|
static async createUserSchema() {
|
114
82
|
return dbos_executor_1.DBOSExecutor.globalInstance?.userDatabase.createSchema();
|
@@ -116,6 +84,7 @@ class DBOS {
|
|
116
84
|
/**
|
117
85
|
* Use ORMEntities to drop database schema.
|
118
86
|
* Only relevant for TypeORM, and for testing purposes only, not production
|
87
|
+
* @deprecated - use data source packages such as `@dbos-inc/typeorm-datasource`
|
119
88
|
*/
|
120
89
|
static async dropUserSchema() {
|
121
90
|
return dbos_executor_1.DBOSExecutor.globalInstance?.userDatabase.dropSchema();
|
@@ -141,25 +110,55 @@ class DBOS {
|
|
141
110
|
if (DBOS.isInitialized()) {
|
142
111
|
return;
|
143
112
|
}
|
144
|
-
const debugMode = options?.debugMode ?? DBOS.getDebugModeFromEnv();
|
145
113
|
if (options?.conductorKey) {
|
146
114
|
// Use a generated executor ID.
|
147
115
|
utils_1.globalParams.executorID = (0, node_crypto_1.randomUUID)();
|
148
116
|
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
117
|
+
const debugMode = options?.debugMode ?? process.env.DBOS_DEBUG_WORKFLOW_ID !== undefined;
|
118
|
+
const configFile = (0, config_1.readConfigFile)();
|
119
|
+
const $dbosConfig = DBOS.#dbosConfig;
|
120
|
+
let [internalConfig, runtimeConfig] = $dbosConfig
|
121
|
+
? (0, config_1.translatePublicDBOSconfig)(
|
122
|
+
// copy config settings to ensure no unexpected fields are passed thru
|
123
|
+
{
|
124
|
+
adminPort: $dbosConfig.adminPort,
|
125
|
+
name: $dbosConfig.name,
|
126
|
+
databaseUrl: $dbosConfig.databaseUrl,
|
127
|
+
userDbclient: $dbosConfig.userDbclient,
|
128
|
+
userDbPoolSize: $dbosConfig.userDbPoolSize,
|
129
|
+
sysDbName: $dbosConfig.sysDbName,
|
130
|
+
sysDbPoolSize: $dbosConfig.sysDbPoolSize,
|
131
|
+
logLevel: $dbosConfig.logLevel,
|
132
|
+
addContextMetadata: $dbosConfig.addContextMetadata,
|
133
|
+
runAdminServer: $dbosConfig.runAdminServer,
|
134
|
+
otlpTracesEndpoints: [...($dbosConfig.otlpTracesEndpoints ?? [])],
|
135
|
+
otlpLogsEndpoints: [...($dbosConfig.otlpLogsEndpoints ?? [])],
|
136
|
+
}, debugMode)
|
137
|
+
: (0, config_1.processConfigFile)(configFile, { forceConsole: debugMode });
|
138
|
+
if (process.env.DBOS__CLOUD === 'true') {
|
139
|
+
[internalConfig, runtimeConfig] = (0, config_1.overwrite_config)(internalConfig, runtimeConfig, configFile);
|
140
|
+
}
|
141
|
+
DBOS.#port = runtimeConfig.port;
|
142
|
+
DBOS.#poolConfig = internalConfig.poolConfig;
|
143
|
+
DBOS.#dbosConfig = {
|
144
|
+
name: internalConfig.name,
|
145
|
+
databaseUrl: internalConfig.databaseUrl,
|
146
|
+
userDbclient: internalConfig.userDbclient,
|
147
|
+
userDbPoolSize: DBOS.#dbosConfig?.userDbPoolSize,
|
148
|
+
sysDbName: internalConfig.system_database,
|
149
|
+
sysDbPoolSize: internalConfig.sysDbPoolSize,
|
150
|
+
logLevel: internalConfig.telemetry.logs?.logLevel,
|
151
|
+
addContextMetadata: internalConfig.telemetry.logs?.addContextMetadata,
|
152
|
+
otlpTracesEndpoints: [...(internalConfig.telemetry.OTLPExporter?.tracesEndpoint ?? [])],
|
153
|
+
otlpLogsEndpoints: [...(internalConfig.telemetry.OTLPExporter?.logsEndpoint ?? [])],
|
154
|
+
adminPort: runtimeConfig.admin_port,
|
155
|
+
runAdminServer: runtimeConfig.runAdminServer,
|
156
|
+
};
|
157
|
+
if (utils_1.globalParams.appName === '' && DBOS.#dbosConfig.name) {
|
158
|
+
utils_1.globalParams.appName = DBOS.#dbosConfig.name;
|
158
159
|
}
|
159
160
|
dbos_executor_1.DBOSExecutor.createInternalQueue();
|
160
|
-
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(
|
161
|
-
debugMode,
|
162
|
-
});
|
161
|
+
dbos_executor_1.DBOSExecutor.globalInstance = new dbos_executor_1.DBOSExecutor(internalConfig, { debugMode });
|
163
162
|
const executor = dbos_executor_1.DBOSExecutor.globalInstance;
|
164
163
|
await executor.init();
|
165
164
|
const debugWorkflowId = process.env.DBOS_DEBUG_WORKFLOW_ID;
|
@@ -186,14 +185,14 @@ class DBOS {
|
|
186
185
|
}
|
187
186
|
// Start the DBOS admin server
|
188
187
|
const logger = DBOS.logger;
|
189
|
-
if (
|
188
|
+
if (runtimeConfig.runAdminServer) {
|
190
189
|
const adminApp = server_1.DBOSHttpServer.setupAdminApp(executor);
|
191
190
|
try {
|
192
|
-
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(
|
191
|
+
await server_1.DBOSHttpServer.checkPortAvailabilityIPv4Ipv6(runtimeConfig.admin_port, logger);
|
193
192
|
// Wrap the listen call in a promise to properly catch errors
|
194
193
|
DBOS.adminServer = await new Promise((resolve, reject) => {
|
195
|
-
const server = adminApp.listen(
|
196
|
-
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${
|
194
|
+
const server = adminApp.listen(runtimeConfig?.admin_port, () => {
|
195
|
+
DBOS.logger.debug(`DBOS Admin Server is running at http://localhost:${runtimeConfig?.admin_port}`);
|
197
196
|
resolve(server);
|
198
197
|
});
|
199
198
|
server.on('error', (err) => {
|
@@ -202,7 +201,7 @@ class DBOS {
|
|
202
201
|
});
|
203
202
|
}
|
204
203
|
catch (e) {
|
205
|
-
logger.warn(`Unable to start DBOS admin server on port ${
|
204
|
+
logger.warn(`Unable to start DBOS admin server on port ${runtimeConfig.admin_port}`);
|
206
205
|
}
|
207
206
|
}
|
208
207
|
if (options?.koaApp) {
|
@@ -242,7 +241,6 @@ class DBOS {
|
|
242
241
|
if (!dbos_executor_1.DBOSExecutor.globalInstance)
|
243
242
|
return;
|
244
243
|
dbos_executor_1.DBOSExecutor.globalInstance.logRegisteredHTTPUrls();
|
245
|
-
dbos_executor_1.DBOSExecutor.globalInstance.scheduler?.logRegisteredSchedulerEndpoints();
|
246
244
|
wfqueue_1.wfQueueRunner.logRegisteredEndpoints(dbos_executor_1.DBOSExecutor.globalInstance);
|
247
245
|
for (const lcl of (0, decorators_1.getLifecycleListeners)()) {
|
248
246
|
lcl.logRegisteredEndpoints?.();
|
@@ -305,6 +303,7 @@ class DBOS {
|
|
305
303
|
* Creates a node.js HTTP handler for all entrypoints registered with `@DBOS.getApi`
|
306
304
|
* and other decorators. The handler can be retrieved with `DBOS.getHTTPHandlersCallback()`.
|
307
305
|
* This method does not start listening for requests. For that, call `DBOS.launchAppHTTPServer()`.
|
306
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
308
307
|
*/
|
309
308
|
static setUpHandlerCallback() {
|
310
309
|
if (!dbos_executor_1.DBOSExecutor.globalInstance) {
|
@@ -319,12 +318,13 @@ class DBOS {
|
|
319
318
|
* Creates a node.js HTTP handler for all entrypoints registered with `@DBOS.getApi`
|
320
319
|
* and other decorators. This method also starts listening for requests, on the port
|
321
320
|
* specified in the `DBOSRuntimeConfig`.
|
321
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
322
322
|
*/
|
323
323
|
static async launchAppHTTPServer() {
|
324
324
|
const server = DBOS.setUpHandlerCallback();
|
325
|
-
if (DBOS.#
|
325
|
+
if (DBOS.#port) {
|
326
326
|
// This will not listen if there's no decorated endpoint
|
327
|
-
DBOS.appServer = await server.appListen(DBOS.#
|
327
|
+
DBOS.appServer = await server.appListen(DBOS.#port);
|
328
328
|
}
|
329
329
|
}
|
330
330
|
/**
|
@@ -332,6 +332,7 @@ class DBOS {
|
|
332
332
|
* (This is the one that handles the @DBOS.getApi, etc., methods.)
|
333
333
|
* Useful for testing purposes, or to combine the DBOS service with other
|
334
334
|
* node.js HTTP server frameworks.
|
335
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
335
336
|
*/
|
336
337
|
static getHTTPHandlersCallback() {
|
337
338
|
if (!server_1.DBOSHttpServer.instance) {
|
@@ -350,9 +351,10 @@ class DBOS {
|
|
350
351
|
// Globals
|
351
352
|
//////
|
352
353
|
static #dbosConfig;
|
353
|
-
static #
|
354
|
+
static #poolConfig;
|
355
|
+
static #port;
|
354
356
|
static get dbosConfig() {
|
355
|
-
return DBOS.#dbosConfig;
|
357
|
+
return { ...DBOS.#dbosConfig, poolConfig: DBOS.#poolConfig };
|
356
358
|
}
|
357
359
|
//////
|
358
360
|
// Context
|
@@ -396,11 +398,17 @@ class DBOS {
|
|
396
398
|
throw new error_1.DBOSError('`DBOS.request` accessed from outside of HTTP requests');
|
397
399
|
return r;
|
398
400
|
}
|
399
|
-
/**
|
401
|
+
/**
|
402
|
+
* Get the current Koa context (within `@DBOS.getApi` et al)
|
403
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
404
|
+
*/
|
400
405
|
static getKoaContext() {
|
401
406
|
return (0, context_1.getCurrentContextStore)()?.koaContext;
|
402
407
|
}
|
403
|
-
/**
|
408
|
+
/**
|
409
|
+
* Get the current Koa context (within `@DBOS.getApi` et al)
|
410
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
411
|
+
*/
|
404
412
|
static get koaContext() {
|
405
413
|
const r = DBOS.getKoaContext();
|
406
414
|
if (!r)
|
@@ -466,7 +474,16 @@ class DBOS {
|
|
466
474
|
return DBOS.isWithinWorkflow() && !DBOS.isInTransaction() && !DBOS.isInStep() && !DBOS.isInStoredProc();
|
467
475
|
}
|
468
476
|
// sql session (various forms)
|
469
|
-
/**
|
477
|
+
/**
|
478
|
+
* @returns the current SQL client; only allowed within `@DBOS.transaction` functions
|
479
|
+
* @deprecated - use data source packages such as:
|
480
|
+
* `@dbos-inc/drizzle-datasource`
|
481
|
+
* `@dbos-inc/knex-datasource`
|
482
|
+
* `@dbos-inc/node-pg-datasource`
|
483
|
+
* `@dbos-inc/postgres-datasource`
|
484
|
+
* `@dbos-inc/prisma-datasource`
|
485
|
+
* `@dbos-inc/typeorm-datasource`
|
486
|
+
*/
|
470
487
|
static get sqlClient() {
|
471
488
|
const c = (0, context_1.getCurrentContextStore)()?.sqlClient;
|
472
489
|
if (!DBOS.isInTransaction() || !c)
|
@@ -476,6 +493,7 @@ class DBOS {
|
|
476
493
|
/**
|
477
494
|
* @returns the current PG SQL client;
|
478
495
|
* only allowed within `@DBOS.transaction` functions when a `PGNODE` user database is in use
|
496
|
+
* @deprecated - use data source packages such as `@dbos-inc/node-pg-datasource`
|
479
497
|
*/
|
480
498
|
static get pgClient() {
|
481
499
|
const client = DBOS.sqlClient;
|
@@ -487,6 +505,7 @@ class DBOS {
|
|
487
505
|
/**
|
488
506
|
* @returns the current Knex SQL client;
|
489
507
|
* only allowed within `@DBOS.transaction` functions when a `KNEX` user database is in use
|
508
|
+
* @deprecated - use `@dbos-inc/knex-datasource` package
|
490
509
|
*/
|
491
510
|
static get knexClient() {
|
492
511
|
if (DBOS.isInStoredProc()) {
|
@@ -501,6 +520,7 @@ class DBOS {
|
|
501
520
|
/**
|
502
521
|
* @returns the current Prisma SQL client;
|
503
522
|
* only allowed within `@DBOS.transaction` functions when a `PRISMA` user database is in use
|
523
|
+
* @deprecated - use `@dbos-inc/prisma-datasource` package
|
504
524
|
*/
|
505
525
|
static get prismaClient() {
|
506
526
|
if (DBOS.isInStoredProc()) {
|
@@ -515,6 +535,7 @@ class DBOS {
|
|
515
535
|
/**
|
516
536
|
* @returns the current TypeORM SQL client;
|
517
537
|
* only allowed within `@DBOS.transaction` functions when the `TYPEORM` user database is in use
|
538
|
+
* @deprecated - use `@dbos-inc/typeorm-datasource` package
|
518
539
|
*/
|
519
540
|
static get typeORMClient() {
|
520
541
|
if (DBOS.isInStoredProc()) {
|
@@ -529,6 +550,7 @@ class DBOS {
|
|
529
550
|
/**
|
530
551
|
* @returns the current Drizzle SQL client;
|
531
552
|
* only allowed within `@DBOS.transaction` functions when the `DRIZZLE` user database is in use
|
553
|
+
* @deprecated - use `@dbos-inc/drizzle-datasource` package
|
532
554
|
*/
|
533
555
|
static get drizzleClient() {
|
534
556
|
if (DBOS.isInStoredProc()) {
|
@@ -540,23 +562,19 @@ class DBOS {
|
|
540
562
|
const client = DBOS.sqlClient;
|
541
563
|
return client;
|
542
564
|
}
|
543
|
-
/**
|
544
|
-
* Gets configuration information from the `application` section
|
545
|
-
* of `DBOSConfig`
|
546
|
-
* @param key - name of configuration item
|
547
|
-
* @param defaultValue - value to return if `key` does not exist in the configuration
|
548
|
-
*/
|
549
|
-
static getConfig(key, defaultValue) {
|
550
|
-
if (DBOS.#executor)
|
551
|
-
return DBOS.#executor.getConfig(key, defaultValue);
|
552
|
-
return defaultValue;
|
553
|
-
}
|
554
565
|
/**
|
555
566
|
* Query the current application database
|
556
567
|
* @param sql - parameterized SQL statement (string) to execute
|
557
568
|
* @param params - parameter values for `sql`
|
558
569
|
* @template T - Type for the returned records
|
559
570
|
* @returns Array of records returned by the SQL statement
|
571
|
+
* @deprecated - use data source packages such as:
|
572
|
+
* `@dbos-inc/drizzle-datasource`
|
573
|
+
* `@dbos-inc/knex-datasource`
|
574
|
+
* `@dbos-inc/node-pg-datasource`
|
575
|
+
* `@dbos-inc/postgres-datasource`
|
576
|
+
* `@dbos-inc/prisma-datasource`
|
577
|
+
* `@dbos-inc/typeorm-datasource`
|
560
578
|
*/
|
561
579
|
static async queryUserDB(sql, params) {
|
562
580
|
if (DBOS.isWithinWorkflow() && !DBOS.isInStep()) {
|
@@ -1033,21 +1051,33 @@ class DBOS {
|
|
1033
1051
|
}
|
1034
1052
|
return DBOS.#executor.getEvent(workflowID, key, timeoutSeconds);
|
1035
1053
|
}
|
1054
|
+
/**
|
1055
|
+
* registers a workflow method or function with an invocation schedule
|
1056
|
+
* @param func - The workflow method or function to register with an invocation schedule
|
1057
|
+
* @param options - Configuration information for the scheduled workflow
|
1058
|
+
*/
|
1059
|
+
static registerScheduled(func, config) {
|
1060
|
+
scheduler_1.ScheduledReceiver.registerScheduled(func, config);
|
1061
|
+
}
|
1036
1062
|
//////
|
1037
1063
|
// Decorators
|
1038
1064
|
//////
|
1039
1065
|
/**
|
1040
1066
|
* Decorator associating a class static method with an invocation schedule
|
1041
|
-
* @param
|
1067
|
+
* @param config - The schedule, consisting of a crontab and policy for "make-up work"
|
1042
1068
|
*/
|
1043
|
-
static scheduled(
|
1044
|
-
function
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1069
|
+
static scheduled(config) {
|
1070
|
+
function methodDecorator(target, propertyKey, descriptor) {
|
1071
|
+
if (descriptor.value) {
|
1072
|
+
DBOS.registerScheduled(descriptor.value, {
|
1073
|
+
...config,
|
1074
|
+
ctorOrProto: target,
|
1075
|
+
name: String(propertyKey),
|
1076
|
+
});
|
1077
|
+
}
|
1048
1078
|
return descriptor;
|
1049
1079
|
}
|
1050
|
-
return
|
1080
|
+
return methodDecorator;
|
1051
1081
|
}
|
1052
1082
|
/**
|
1053
1083
|
* Decorator designating a method as a DBOS workflow
|
@@ -1057,10 +1087,11 @@ class DBOS {
|
|
1057
1087
|
*/
|
1058
1088
|
static workflow(config = {}) {
|
1059
1089
|
function decorator(target, propertyKey, inDescriptor) {
|
1060
|
-
const { descriptor, registration } = (0, decorators_1.
|
1090
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1061
1091
|
const invoker = DBOS.#getWorkflowInvoker(registration, config);
|
1062
1092
|
descriptor.value = invoker;
|
1063
1093
|
registration.wrappedFunction = invoker;
|
1094
|
+
(0, decorators_1.registerFunctionWrapper)(invoker, registration);
|
1064
1095
|
return descriptor;
|
1065
1096
|
}
|
1066
1097
|
return decorator;
|
@@ -1074,9 +1105,9 @@ class DBOS {
|
|
1074
1105
|
* @param name - The name of the registered workflow
|
1075
1106
|
* @param options - Configuration information for the registered workflow
|
1076
1107
|
*/
|
1077
|
-
static registerWorkflow(func,
|
1078
|
-
const
|
1079
|
-
return DBOS.#getWorkflowInvoker(registration,
|
1108
|
+
static registerWorkflow(func, config) {
|
1109
|
+
const registration = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueName)(config?.ctorOrProto, config?.className, config?.name ?? func.name, func);
|
1110
|
+
return DBOS.#getWorkflowInvoker(registration, config);
|
1080
1111
|
}
|
1081
1112
|
static async #invokeWorkflow($this, regOP, args, params = {}) {
|
1082
1113
|
const wfId = (0, context_1.getNextWFID)(params.workflowID);
|
@@ -1163,10 +1194,17 @@ class DBOS {
|
|
1163
1194
|
* A durable execution checkpoint will be applied to to the underlying database transaction
|
1164
1195
|
* @see `DBOS.sqlClient`
|
1165
1196
|
* @param config - Configuration information for the transaction, particularly its isolation mode
|
1197
|
+
* @deprecated - use data source packages such as:
|
1198
|
+
* `@dbos-inc/drizzle-datasource`
|
1199
|
+
* `@dbos-inc/knex-datasource`
|
1200
|
+
* `@dbos-inc/node-pg-datasource`
|
1201
|
+
* `@dbos-inc/postgres-datasource`
|
1202
|
+
* `@dbos-inc/prisma-datasource`
|
1203
|
+
* `@dbos-inc/typeorm-datasource`
|
1166
1204
|
*/
|
1167
1205
|
static transaction(config = {}) {
|
1168
1206
|
function decorator(target, propertyKey, inDescriptor) {
|
1169
|
-
const { descriptor, registration } = (0, decorators_1.
|
1207
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1170
1208
|
registration.setTxnConfig(config);
|
1171
1209
|
const invokeWrapper = async function (...rawArgs) {
|
1172
1210
|
let inst = undefined;
|
@@ -1208,6 +1246,7 @@ class DBOS {
|
|
1208
1246
|
};
|
1209
1247
|
descriptor.value = invokeWrapper;
|
1210
1248
|
registration.wrappedFunction = invokeWrapper;
|
1249
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1211
1250
|
Object.defineProperty(invokeWrapper, 'name', {
|
1212
1251
|
value: registration.name,
|
1213
1252
|
});
|
@@ -1223,7 +1262,7 @@ class DBOS {
|
|
1223
1262
|
*/
|
1224
1263
|
static storedProcedure(config = {}) {
|
1225
1264
|
function decorator(target, propertyKey, inDescriptor) {
|
1226
|
-
const { descriptor, registration } = (0, decorators_1.
|
1265
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1227
1266
|
registration.setProcConfig(config);
|
1228
1267
|
const invokeWrapper = async function (...rawArgs) {
|
1229
1268
|
if (typeof this !== 'function') {
|
@@ -1251,6 +1290,7 @@ class DBOS {
|
|
1251
1290
|
};
|
1252
1291
|
descriptor.value = invokeWrapper;
|
1253
1292
|
registration.wrappedFunction = invokeWrapper;
|
1293
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1254
1294
|
Object.defineProperty(invokeWrapper, 'name', {
|
1255
1295
|
value: registration.name,
|
1256
1296
|
});
|
@@ -1268,7 +1308,7 @@ class DBOS {
|
|
1268
1308
|
*/
|
1269
1309
|
static step(config = {}) {
|
1270
1310
|
function decorator(target, propertyKey, inDescriptor) {
|
1271
|
-
const { descriptor, registration } = (0, decorators_1.
|
1311
|
+
const { descriptor, registration } = (0, decorators_1.wrapDBOSFunctionAndRegisterByUniqueNameDec)(target, propertyKey, inDescriptor);
|
1272
1312
|
registration.setStepConfig(config);
|
1273
1313
|
const invokeWrapper = async function (...rawArgs) {
|
1274
1314
|
let inst = undefined;
|
@@ -1311,6 +1351,7 @@ class DBOS {
|
|
1311
1351
|
};
|
1312
1352
|
descriptor.value = invokeWrapper;
|
1313
1353
|
registration.wrappedFunction = invokeWrapper;
|
1354
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, registration);
|
1314
1355
|
Object.defineProperty(invokeWrapper, 'name', {
|
1315
1356
|
value: registration.name,
|
1316
1357
|
});
|
@@ -1325,29 +1366,31 @@ class DBOS {
|
|
1325
1366
|
* This ensures "at least once" execution of the step, and that the step will not
|
1326
1367
|
* be executed again once the checkpoint is recorded
|
1327
1368
|
* @param func - The function to register as a step
|
1328
|
-
* @param config - Configuration information for the step, particularly the retry policy
|
1329
|
-
* @param config.name - The name of the step; if not provided, the function name will be used
|
1369
|
+
* @param config - Configuration information for the step, particularly the retry policy and name
|
1330
1370
|
*/
|
1331
1371
|
static registerStep(func, config = {}) {
|
1332
1372
|
const name = config.name ?? func.name;
|
1373
|
+
const reg = (0, decorators_1.wrapDBOSFunctionAndRegister)(config?.ctorOrProto, config?.className, name, func);
|
1333
1374
|
const invokeWrapper = async function (...rawArgs) {
|
1334
1375
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
1335
1376
|
const inst = this;
|
1377
|
+
const callFunc = reg.registeredFunction ?? reg.origFunction;
|
1336
1378
|
if (DBOS.isWithinWorkflow()) {
|
1337
1379
|
if (DBOS.isInTransaction()) {
|
1338
1380
|
throw new error_1.DBOSInvalidWorkflowTransitionError('Invalid call to a `step` function from within a `transaction`');
|
1339
1381
|
}
|
1340
1382
|
if (DBOS.isInStep()) {
|
1341
1383
|
// There should probably be checks here about the compatibility of the StepConfig...
|
1342
|
-
return
|
1384
|
+
return callFunc.call(this, ...rawArgs);
|
1343
1385
|
}
|
1344
|
-
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(
|
1386
|
+
return await dbos_executor_1.DBOSExecutor.globalInstance.callStepFunction(callFunc, name, config, inst ?? null, ...rawArgs);
|
1345
1387
|
}
|
1346
1388
|
if ((0, context_1.getNextWFID)(undefined)) {
|
1347
1389
|
throw new error_1.DBOSInvalidWorkflowTransitionError(`Invalid call to step '${name}' outside of a workflow; with directive to start a workflow.`);
|
1348
1390
|
}
|
1349
|
-
return
|
1391
|
+
return callFunc.call(this, ...rawArgs);
|
1350
1392
|
};
|
1393
|
+
(0, decorators_1.registerFunctionWrapper)(invokeWrapper, reg);
|
1351
1394
|
Object.defineProperty(invokeWrapper, 'name', { value: name });
|
1352
1395
|
return invokeWrapper;
|
1353
1396
|
}
|
@@ -1375,23 +1418,38 @@ class DBOS {
|
|
1375
1418
|
}
|
1376
1419
|
return func();
|
1377
1420
|
}
|
1378
|
-
/**
|
1421
|
+
/**
|
1422
|
+
* Decorator indicating that the method is the target of HTTP GET operations for `url`
|
1423
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1424
|
+
*/
|
1379
1425
|
static getApi(url) {
|
1380
1426
|
return httpApiDec(handlerTypes_1.APITypes.GET, url);
|
1381
1427
|
}
|
1382
|
-
/**
|
1428
|
+
/**
|
1429
|
+
* Decorator indicating that the method is the target of HTTP POST operations for `url`
|
1430
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1431
|
+
*/
|
1383
1432
|
static postApi(url) {
|
1384
1433
|
return httpApiDec(handlerTypes_1.APITypes.POST, url);
|
1385
1434
|
}
|
1386
|
-
/**
|
1435
|
+
/**
|
1436
|
+
* Decorator indicating that the method is the target of HTTP PUT operations for `url`
|
1437
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1438
|
+
*/
|
1387
1439
|
static putApi(url) {
|
1388
1440
|
return httpApiDec(handlerTypes_1.APITypes.PUT, url);
|
1389
1441
|
}
|
1390
|
-
/**
|
1442
|
+
/**
|
1443
|
+
* Decorator indicating that the method is the target of HTTP PATCH operations for `url`
|
1444
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1445
|
+
*/
|
1391
1446
|
static patchApi(url) {
|
1392
1447
|
return httpApiDec(handlerTypes_1.APITypes.PATCH, url);
|
1393
1448
|
}
|
1394
|
-
/**
|
1449
|
+
/**
|
1450
|
+
* Decorator indicating that the method is the target of HTTP DELETE operations for `url`
|
1451
|
+
* @deprecated - use `@dbos-inc/koa-serve`
|
1452
|
+
*/
|
1395
1453
|
static deleteApi(url) {
|
1396
1454
|
return httpApiDec(handlerTypes_1.APITypes.DELETE, url);
|
1397
1455
|
}
|
@@ -1449,13 +1507,13 @@ class DBOS {
|
|
1449
1507
|
* Register information to be associated with a DBOS function
|
1450
1508
|
*/
|
1451
1509
|
static associateFunctionWithInfo(external, func, target) {
|
1452
|
-
return (0, decorators_1.associateMethodWithExternal)(external, target.ctorOrProto, target.className, target.name, func);
|
1510
|
+
return (0, decorators_1.associateMethodWithExternal)(external, target.ctorOrProto, target.className, target.name ?? func.name, func);
|
1453
1511
|
}
|
1454
1512
|
/**
|
1455
1513
|
* Register information to be associated with a DBOS function
|
1456
1514
|
*/
|
1457
1515
|
static associateParamWithInfo(external, func, target) {
|
1458
|
-
return (0, decorators_1.associateParameterWithExternal)(external, target.ctorOrProto, target.className, target.name, func, target.param);
|
1516
|
+
return (0, decorators_1.associateParameterWithExternal)(external, target.ctorOrProto, target.className, target.name ?? func.name, func, target.param);
|
1459
1517
|
}
|
1460
1518
|
/** Get registrations */
|
1461
1519
|
static getAssociatedInfo(external, cls, funcName) {
|
@@ -1476,14 +1534,6 @@ class InitContext {
|
|
1476
1534
|
queryUserDB(sql, ...params) {
|
1477
1535
|
return DBOS.queryUserDB(sql, params);
|
1478
1536
|
}
|
1479
|
-
getConfig(key, defaultValue) {
|
1480
|
-
const value = DBOS.getConfig(key, defaultValue);
|
1481
|
-
// If the key is found and the default value is provided, check whether the value is of the same type.
|
1482
|
-
if (value && defaultValue && typeof value !== typeof defaultValue) {
|
1483
|
-
throw new error_1.DBOSConfigKeyTypeError(key, typeof defaultValue, typeof value);
|
1484
|
-
}
|
1485
|
-
return value;
|
1486
|
-
}
|
1487
1537
|
}
|
1488
1538
|
exports.InitContext = InitContext;
|
1489
1539
|
//# sourceMappingURL=dbos.js.map
|