pg-workflows 0.10.0 → 0.11.0
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/client.entry.cjs +3 -11
- package/dist/client.entry.d.cts +15 -5
- package/dist/client.entry.d.ts +15 -5
- package/dist/client.entry.js +6 -2
- package/dist/client.entry.js.map +4 -4
- package/dist/index.cjs +34 -44
- package/dist/index.d.cts +6 -21
- package/dist/index.d.ts +6 -21
- package/dist/index.js +35 -36
- package/dist/index.js.map +8 -8
- package/dist/shared/{chunk-nygamc7b.js → chunk-ahxqsytt.js} +3 -13
- package/dist/shared/chunk-ahxqsytt.js.map +16 -0
- package/package.json +1 -1
- package/dist/shared/chunk-nygamc7b.js.map +0 -16
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ type DurationObject = {
|
|
|
33
33
|
seconds?: number;
|
|
34
34
|
};
|
|
35
35
|
type Duration = string | DurationObject;
|
|
36
|
-
declare function parseDuration(duration: Duration): number;
|
|
37
36
|
declare enum WorkflowStatus {
|
|
38
37
|
PENDING = "pending",
|
|
39
38
|
RUNNING = "running",
|
|
@@ -53,7 +52,7 @@ declare enum StepType {
|
|
|
53
52
|
}
|
|
54
53
|
type InputParameters = StandardSchemaV1;
|
|
55
54
|
type InferInputParameters<P extends InputParameters> = StandardSchemaV1.InferOutput<P>;
|
|
56
|
-
type
|
|
55
|
+
type StartWorkflowOptions = {
|
|
57
56
|
resourceId?: string;
|
|
58
57
|
timeout?: number;
|
|
59
58
|
retries?: number;
|
|
@@ -107,13 +106,13 @@ type StepBaseContext = {
|
|
|
107
106
|
<
|
|
108
107
|
TInput extends InputParameters,
|
|
109
108
|
TOutput = unknown
|
|
110
|
-
>(stepId: string, ref: WorkflowRef<TInput, TOutput>, input: InferInputParameters<TInput>, options?:
|
|
109
|
+
>(stepId: string, ref: WorkflowRef<TInput, TOutput>, input: InferInputParameters<TInput>, options?: StartWorkflowOptions): Promise<TOutput>;
|
|
111
110
|
<TOutput = unknown>(stepId: string, params: {
|
|
112
111
|
workflowId: string;
|
|
113
112
|
input: unknown;
|
|
114
113
|
resourceId?: string;
|
|
115
114
|
idempotencyKey?: string;
|
|
116
|
-
options?:
|
|
115
|
+
options?: StartWorkflowOptions;
|
|
117
116
|
}): Promise<TOutput>;
|
|
118
117
|
};
|
|
119
118
|
};
|
|
@@ -197,14 +196,6 @@ interface WorkflowLogger {
|
|
|
197
196
|
log(message: string): void;
|
|
198
197
|
error(message: string, ...args: unknown[]): void;
|
|
199
198
|
}
|
|
200
|
-
type WorkflowInternalLoggerContext = {
|
|
201
|
-
runId?: string;
|
|
202
|
-
workflowId?: string;
|
|
203
|
-
};
|
|
204
|
-
interface WorkflowInternalLogger {
|
|
205
|
-
log(message: string, context?: WorkflowInternalLoggerContext): void;
|
|
206
|
-
error(message: string, error: Error, context?: WorkflowInternalLoggerContext): void;
|
|
207
|
-
}
|
|
208
199
|
type WorkflowClientOptions = {
|
|
209
200
|
logger?: WorkflowLogger;
|
|
210
201
|
/**
|
|
@@ -221,7 +212,6 @@ type WorkflowClientOptions = {
|
|
|
221
212
|
connectionString: string;
|
|
222
213
|
pool?: never;
|
|
223
214
|
});
|
|
224
|
-
type StartWorkflowOptions = WorkflowRunOptions;
|
|
225
215
|
declare class WorkflowClient {
|
|
226
216
|
private boss;
|
|
227
217
|
private db;
|
|
@@ -306,9 +296,6 @@ declare function createWorkflowRef<
|
|
|
306
296
|
declare const workflow: WorkflowFactory;
|
|
307
297
|
import pg2 from "pg";
|
|
308
298
|
import { Db, PgBoss as PgBoss2 } from "pg-boss";
|
|
309
|
-
type StartWorkflowOptions2 = WorkflowRunOptions & {
|
|
310
|
-
batchSize?: number;
|
|
311
|
-
};
|
|
312
299
|
type WorkflowEngineOptions = {
|
|
313
300
|
workflows?: WorkflowDefinition[];
|
|
314
301
|
logger?: WorkflowLogger;
|
|
@@ -339,13 +326,13 @@ declare class WorkflowEngine {
|
|
|
339
326
|
unregisterWorkflow(workflowId: string): Promise<WorkflowEngine>;
|
|
340
327
|
unregisterAllWorkflows(): Promise<WorkflowEngine>;
|
|
341
328
|
private resolveWorkflowRunParameters;
|
|
342
|
-
startWorkflow<TInput extends InputParameters>(ref: WorkflowRef<TInput>, input: InferInputParameters<TInput>, options?:
|
|
329
|
+
startWorkflow<TInput extends InputParameters>(ref: WorkflowRef<TInput>, input: InferInputParameters<TInput>, options?: StartWorkflowOptions): Promise<WorkflowRun>;
|
|
343
330
|
startWorkflow(params: {
|
|
344
331
|
resourceId?: string;
|
|
345
332
|
workflowId: string;
|
|
346
333
|
input: unknown;
|
|
347
334
|
idempotencyKey?: string;
|
|
348
|
-
options?:
|
|
335
|
+
options?: StartWorkflowOptions;
|
|
349
336
|
}): Promise<WorkflowRun>;
|
|
350
337
|
private createWorkflowRun;
|
|
351
338
|
private enqueueWorkflowRun;
|
|
@@ -455,8 +442,6 @@ declare class WorkflowEngine {
|
|
|
455
442
|
}>;
|
|
456
443
|
}
|
|
457
444
|
import { StandardSchemaV1 as StandardSchemaV12 } from "@standard-schema/spec";
|
|
458
|
-
declare function validateWorkflowId(workflowId: string): void;
|
|
459
|
-
declare function validateResourceId(resourceId: string | undefined | null): void;
|
|
460
445
|
declare class WorkflowEngineError extends Error {
|
|
461
446
|
readonly workflowId?: string | undefined;
|
|
462
447
|
readonly runId?: string | undefined;
|
|
@@ -467,4 +452,4 @@ declare class WorkflowEngineError extends Error {
|
|
|
467
452
|
declare class WorkflowRunNotFoundError extends WorkflowEngineError {
|
|
468
453
|
constructor(runId?: string, workflowId?: string);
|
|
469
454
|
}
|
|
470
|
-
export { workflow,
|
|
455
|
+
export { workflow, createWorkflowRef, WorkflowStatus, WorkflowRunProgress, WorkflowRunNotFoundError, WorkflowRun, WorkflowRef, WorkflowPlugin, WorkflowOptions, WorkflowLogger, WorkflowEngineOptions, WorkflowEngineError, WorkflowEngine, WorkflowDefinition, WorkflowContext, WorkflowClientOptions, WorkflowClient, StepBaseContext, StartWorkflowOptions, InputParameters, InferInputParameters, Duration };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_PGBOSS_SCHEMA,
|
|
3
3
|
PAUSE_EVENT_NAME,
|
|
4
|
-
StepType,
|
|
5
4
|
WORKFLOW_RUN_DLQ_QUEUE_NAME,
|
|
6
5
|
WORKFLOW_RUN_QUEUE_NAME,
|
|
7
6
|
WorkflowClient,
|
|
@@ -21,32 +20,7 @@ import {
|
|
|
21
20
|
waitForTimelineKey,
|
|
22
21
|
withPostgresTransaction,
|
|
23
22
|
workflow
|
|
24
|
-
} from "./shared/chunk-
|
|
25
|
-
// src/duration.ts
|
|
26
|
-
import parse from "parse-duration";
|
|
27
|
-
var MS_PER_SECOND = 1000;
|
|
28
|
-
var MS_PER_MINUTE = 60 * MS_PER_SECOND;
|
|
29
|
-
var MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
|
30
|
-
var MS_PER_DAY = 24 * MS_PER_HOUR;
|
|
31
|
-
var MS_PER_WEEK = 7 * MS_PER_DAY;
|
|
32
|
-
function parseDuration(duration) {
|
|
33
|
-
if (typeof duration === "string") {
|
|
34
|
-
if (duration.trim() === "") {
|
|
35
|
-
throw new WorkflowEngineError("Invalid duration: empty string");
|
|
36
|
-
}
|
|
37
|
-
const ms2 = parse(duration);
|
|
38
|
-
if (ms2 == null || ms2 <= 0) {
|
|
39
|
-
throw new WorkflowEngineError(`Invalid duration: "${duration}"`);
|
|
40
|
-
}
|
|
41
|
-
return ms2;
|
|
42
|
-
}
|
|
43
|
-
const { weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0 } = duration;
|
|
44
|
-
const ms = weeks * MS_PER_WEEK + days * MS_PER_DAY + hours * MS_PER_HOUR + minutes * MS_PER_MINUTE + seconds * MS_PER_SECOND;
|
|
45
|
-
if (ms <= 0) {
|
|
46
|
-
throw new WorkflowEngineError("Invalid duration: must be a positive value");
|
|
47
|
-
}
|
|
48
|
-
return ms;
|
|
49
|
-
}
|
|
23
|
+
} from "./shared/chunk-ahxqsytt.js";
|
|
50
24
|
// src/engine.ts
|
|
51
25
|
import { merge } from "es-toolkit";
|
|
52
26
|
import pg from "pg";
|
|
@@ -122,6 +96,32 @@ function parseWorkflowHandler(handler) {
|
|
|
122
96
|
return { steps: Array.from(steps.values()) };
|
|
123
97
|
}
|
|
124
98
|
|
|
99
|
+
// src/duration.ts
|
|
100
|
+
import parse from "parse-duration";
|
|
101
|
+
var MS_PER_SECOND = 1000;
|
|
102
|
+
var MS_PER_MINUTE = 60 * MS_PER_SECOND;
|
|
103
|
+
var MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
|
104
|
+
var MS_PER_DAY = 24 * MS_PER_HOUR;
|
|
105
|
+
var MS_PER_WEEK = 7 * MS_PER_DAY;
|
|
106
|
+
function parseDuration(duration) {
|
|
107
|
+
if (typeof duration === "string") {
|
|
108
|
+
if (duration.trim() === "") {
|
|
109
|
+
throw new WorkflowEngineError("Invalid duration: empty string");
|
|
110
|
+
}
|
|
111
|
+
const ms2 = parse(duration);
|
|
112
|
+
if (ms2 == null || ms2 <= 0) {
|
|
113
|
+
throw new WorkflowEngineError(`Invalid duration: "${duration}"`);
|
|
114
|
+
}
|
|
115
|
+
return ms2;
|
|
116
|
+
}
|
|
117
|
+
const { weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0 } = duration;
|
|
118
|
+
const ms = weeks * MS_PER_WEEK + days * MS_PER_DAY + hours * MS_PER_HOUR + minutes * MS_PER_MINUTE + seconds * MS_PER_SECOND;
|
|
119
|
+
if (ms <= 0) {
|
|
120
|
+
throw new WorkflowEngineError("Invalid duration: must be a positive value");
|
|
121
|
+
}
|
|
122
|
+
return ms;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
125
|
// src/engine.ts
|
|
126
126
|
var LOG_PREFIX = "[WorkflowEngine]";
|
|
127
127
|
var StepTypeToIcon = {
|
|
@@ -271,7 +271,7 @@ class WorkflowEngine {
|
|
|
271
271
|
async startWorkflow(refOrParams, inputArg, optionsArg) {
|
|
272
272
|
const { workflowId, input, resourceId, idempotencyKey, options } = this.resolveWorkflowRunParameters(refOrParams, inputArg, optionsArg);
|
|
273
273
|
if (!this._started) {
|
|
274
|
-
await this.start(false
|
|
274
|
+
await this.start(false);
|
|
275
275
|
}
|
|
276
276
|
const { run } = await this.createWorkflowRun({
|
|
277
277
|
workflowId,
|
|
@@ -740,7 +740,9 @@ class WorkflowEngine {
|
|
|
740
740
|
input: run.input,
|
|
741
741
|
workflowId: run.workflowId,
|
|
742
742
|
runId: run.id,
|
|
743
|
-
timeline
|
|
743
|
+
get timeline() {
|
|
744
|
+
return run?.timeline ?? {};
|
|
745
|
+
},
|
|
744
746
|
logger: this.logger,
|
|
745
747
|
step
|
|
746
748
|
};
|
|
@@ -1037,7 +1039,7 @@ class WorkflowEngine {
|
|
|
1037
1039
|
if (output === undefined) {
|
|
1038
1040
|
output = {};
|
|
1039
1041
|
}
|
|
1040
|
-
|
|
1042
|
+
const updated = await this.updateRun({
|
|
1041
1043
|
runId: run.id,
|
|
1042
1044
|
resourceId: run.resourceId ?? undefined,
|
|
1043
1045
|
data: {
|
|
@@ -1049,6 +1051,7 @@ class WorkflowEngine {
|
|
|
1049
1051
|
})
|
|
1050
1052
|
}
|
|
1051
1053
|
}, { db });
|
|
1054
|
+
Object.assign(run, updated);
|
|
1052
1055
|
return output;
|
|
1053
1056
|
} catch (error) {
|
|
1054
1057
|
this.logger.error(`Step ${stepId} failed:`, error, {
|
|
@@ -1278,17 +1281,13 @@ ${error.stack}` : String(error)
|
|
|
1278
1281
|
}
|
|
1279
1282
|
export {
|
|
1280
1283
|
workflow,
|
|
1281
|
-
validateWorkflowId,
|
|
1282
|
-
validateResourceId,
|
|
1283
|
-
parseDuration,
|
|
1284
1284
|
createWorkflowRef,
|
|
1285
1285
|
WorkflowStatus,
|
|
1286
1286
|
WorkflowRunNotFoundError,
|
|
1287
1287
|
WorkflowEngineError,
|
|
1288
1288
|
WorkflowEngine,
|
|
1289
|
-
WorkflowClient
|
|
1290
|
-
StepType
|
|
1289
|
+
WorkflowClient
|
|
1291
1290
|
};
|
|
1292
1291
|
|
|
1293
|
-
//# debugId=
|
|
1292
|
+
//# debugId=F9D6596295A7020B64756E2164756E21
|
|
1294
1293
|
//# sourceMappingURL=index.js.map
|