pg-workflows 0.7.1 → 0.8.1
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/README.md +83 -765
- package/dist/client.entry.cjs +826 -0
- package/dist/client.entry.d.cts +229 -0
- package/dist/client.entry.d.ts +229 -0
- package/dist/client.entry.js +13 -0
- package/dist/client.entry.js.map +16 -0
- package/dist/index.cjs +644 -323
- package/dist/index.d.cts +125 -11
- package/dist/index.d.ts +125 -11
- package/dist/index.js +75 -487
- package/dist/index.js.map +12 -10
- package/dist/shared/chunk-wsa44g1x.js +757 -0
- package/dist/shared/chunk-wsa44g1x.js.map +16 -0
- package/package.json +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pg from "pg";
|
|
2
2
|
type WorkflowRun = {
|
|
3
3
|
id: string;
|
|
4
4
|
createdAt: Date;
|
|
@@ -20,6 +20,7 @@ type WorkflowRun = {
|
|
|
20
20
|
jobId: string | null;
|
|
21
21
|
idempotencyKey: string | null;
|
|
22
22
|
};
|
|
23
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
23
24
|
type DurationObject = {
|
|
24
25
|
weeks?: number;
|
|
25
26
|
days?: number;
|
|
@@ -136,6 +137,21 @@ type WorkflowInternalDefinition<TInput extends InputParameters = InputParameters
|
|
|
136
137
|
interface WorkflowFactory<TStepExt = object> {
|
|
137
138
|
<I extends InputParameters = InputParameters>(id: string, handler: (context: WorkflowContext<I, StepBaseContext & TStepExt>) => Promise<unknown>, options?: WorkflowOptions<I>): WorkflowDefinition<I>;
|
|
138
139
|
use<TNewExt>(plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>): WorkflowFactory<TStepExt & TNewExt>;
|
|
140
|
+
ref<TInput extends InputParameters = InputParameters>(id: string, options?: {
|
|
141
|
+
inputSchema?: TInput;
|
|
142
|
+
}): WorkflowRef<TInput>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Lightweight workflow reference - carries the workflow ID and input type
|
|
146
|
+
* but no handler code. Safe to import in API services without pulling in
|
|
147
|
+
* heavy worker dependencies.
|
|
148
|
+
*
|
|
149
|
+
* Callable: pass a handler to create a full WorkflowDefinition.
|
|
150
|
+
*/
|
|
151
|
+
interface WorkflowRef<TInput extends InputParameters = InputParameters> {
|
|
152
|
+
(handler: (context: WorkflowContext<TInput, StepBaseContext>) => Promise<unknown>, options?: Omit<WorkflowOptions<TInput>, "inputSchema">): WorkflowDefinition<TInput>;
|
|
153
|
+
readonly id: string;
|
|
154
|
+
readonly inputSchema?: TInput;
|
|
139
155
|
}
|
|
140
156
|
type WorkflowRunProgress = WorkflowRun & {
|
|
141
157
|
completionPercentage: number;
|
|
@@ -154,15 +170,117 @@ interface WorkflowInternalLogger {
|
|
|
154
170
|
log(message: string, context?: WorkflowInternalLoggerContext): void;
|
|
155
171
|
error(message: string, error: Error, context?: WorkflowInternalLoggerContext): void;
|
|
156
172
|
}
|
|
173
|
+
type WorkflowClientOptions = {
|
|
174
|
+
logger?: WorkflowLogger;
|
|
175
|
+
} & ({
|
|
176
|
+
pool: pg.Pool;
|
|
177
|
+
connectionString?: never;
|
|
178
|
+
} | {
|
|
179
|
+
connectionString: string;
|
|
180
|
+
pool?: never;
|
|
181
|
+
});
|
|
182
|
+
type StartWorkflowOptions = {
|
|
183
|
+
resourceId?: string;
|
|
184
|
+
timeout?: number;
|
|
185
|
+
retries?: number;
|
|
186
|
+
expireInSeconds?: number;
|
|
187
|
+
idempotencyKey?: string;
|
|
188
|
+
};
|
|
189
|
+
declare class WorkflowClient {
|
|
190
|
+
private boss;
|
|
191
|
+
private db;
|
|
192
|
+
private pool;
|
|
193
|
+
private _ownsPool;
|
|
194
|
+
private _started;
|
|
195
|
+
private logger;
|
|
196
|
+
constructor({ logger,...connectionOptions }: WorkflowClientOptions);
|
|
197
|
+
start(): Promise<void>;
|
|
198
|
+
stop(): Promise<void>;
|
|
199
|
+
startWorkflow<TInput extends InputParameters>(ref: WorkflowRef<TInput>, input: InferInputParameters<TInput>, options?: StartWorkflowOptions): Promise<WorkflowRun>;
|
|
200
|
+
startWorkflow(params: {
|
|
201
|
+
workflowId: string;
|
|
202
|
+
input: unknown;
|
|
203
|
+
resourceId?: string;
|
|
204
|
+
idempotencyKey?: string;
|
|
205
|
+
options?: StartWorkflowOptions;
|
|
206
|
+
}): Promise<WorkflowRun>;
|
|
207
|
+
triggerEvent({ runId, resourceId, eventName, data, options }: {
|
|
208
|
+
runId: string;
|
|
209
|
+
resourceId?: string;
|
|
210
|
+
eventName: string;
|
|
211
|
+
data?: Record<string, unknown>;
|
|
212
|
+
options?: {
|
|
213
|
+
expireInSeconds?: number;
|
|
214
|
+
};
|
|
215
|
+
}): Promise<WorkflowRun>;
|
|
216
|
+
pauseWorkflow({ runId, resourceId }: {
|
|
217
|
+
runId: string;
|
|
218
|
+
resourceId?: string;
|
|
219
|
+
}): Promise<WorkflowRun>;
|
|
220
|
+
resumeWorkflow({ runId, resourceId, options }: {
|
|
221
|
+
runId: string;
|
|
222
|
+
resourceId?: string;
|
|
223
|
+
options?: {
|
|
224
|
+
expireInSeconds?: number;
|
|
225
|
+
};
|
|
226
|
+
}): Promise<WorkflowRun>;
|
|
227
|
+
fastForwardWorkflow({ runId, resourceId, data }: {
|
|
228
|
+
runId: string;
|
|
229
|
+
resourceId?: string;
|
|
230
|
+
data?: Record<string, unknown>;
|
|
231
|
+
}): Promise<WorkflowRun>;
|
|
232
|
+
cancelWorkflow({ runId, resourceId }: {
|
|
233
|
+
runId: string;
|
|
234
|
+
resourceId?: string;
|
|
235
|
+
}): Promise<WorkflowRun>;
|
|
236
|
+
getRun({ runId, resourceId }: {
|
|
237
|
+
runId: string;
|
|
238
|
+
resourceId?: string;
|
|
239
|
+
}): Promise<WorkflowRun>;
|
|
240
|
+
checkProgress({ runId, resourceId }: {
|
|
241
|
+
runId: string;
|
|
242
|
+
resourceId?: string;
|
|
243
|
+
}): Promise<WorkflowRunProgress>;
|
|
244
|
+
getRuns({ resourceId, startingAfter, endingBefore, limit, statuses, workflowId }: {
|
|
245
|
+
resourceId?: string;
|
|
246
|
+
startingAfter?: string | null;
|
|
247
|
+
endingBefore?: string | null;
|
|
248
|
+
limit?: number;
|
|
249
|
+
statuses?: WorkflowStatus[];
|
|
250
|
+
workflowId?: string;
|
|
251
|
+
}): Promise<{
|
|
252
|
+
items: WorkflowRun[];
|
|
253
|
+
nextCursor: string | null;
|
|
254
|
+
prevCursor: string | null;
|
|
255
|
+
hasMore: boolean;
|
|
256
|
+
hasPrev: boolean;
|
|
257
|
+
}>;
|
|
258
|
+
private ensureStarted;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Create a lightweight workflow reference.
|
|
262
|
+
* Safe to import from `pg-workflows/client` - no engine or handler code.
|
|
263
|
+
*/
|
|
264
|
+
declare function createWorkflowRef<TInput extends InputParameters = InputParameters>(id: string, options?: {
|
|
265
|
+
inputSchema?: TInput;
|
|
266
|
+
}): WorkflowRef<TInput>;
|
|
157
267
|
declare const workflow: WorkflowFactory;
|
|
158
|
-
import
|
|
268
|
+
import pg2 from "pg";
|
|
159
269
|
import { Db, PgBoss } from "pg-boss";
|
|
270
|
+
type StartWorkflowOptions2 = {
|
|
271
|
+
resourceId?: string;
|
|
272
|
+
timeout?: number;
|
|
273
|
+
retries?: number;
|
|
274
|
+
expireInSeconds?: number;
|
|
275
|
+
batchSize?: number;
|
|
276
|
+
idempotencyKey?: string;
|
|
277
|
+
};
|
|
160
278
|
type WorkflowEngineOptions = {
|
|
161
279
|
workflows?: WorkflowDefinition[];
|
|
162
280
|
logger?: WorkflowLogger;
|
|
163
281
|
boss?: PgBoss;
|
|
164
282
|
} & ({
|
|
165
|
-
pool:
|
|
283
|
+
pool: pg2.Pool;
|
|
166
284
|
connectionString?: never;
|
|
167
285
|
} | {
|
|
168
286
|
connectionString: string;
|
|
@@ -185,17 +303,13 @@ declare class WorkflowEngine {
|
|
|
185
303
|
registerWorkflow(definition: WorkflowDefinition<InputParameters>): Promise<WorkflowEngine>;
|
|
186
304
|
unregisterWorkflow(workflowId: string): Promise<WorkflowEngine>;
|
|
187
305
|
unregisterAllWorkflows(): Promise<WorkflowEngine>;
|
|
188
|
-
startWorkflow(
|
|
306
|
+
startWorkflow<TInput extends InputParameters>(ref: WorkflowRef<TInput>, input: InferInputParameters<TInput>, options?: StartWorkflowOptions2): Promise<WorkflowRun>;
|
|
307
|
+
startWorkflow(params: {
|
|
189
308
|
resourceId?: string;
|
|
190
309
|
workflowId: string;
|
|
191
310
|
input: unknown;
|
|
192
311
|
idempotencyKey?: string;
|
|
193
|
-
options?:
|
|
194
|
-
timeout?: number;
|
|
195
|
-
retries?: number;
|
|
196
|
-
expireInSeconds?: number;
|
|
197
|
-
batchSize?: number;
|
|
198
|
-
};
|
|
312
|
+
options?: StartWorkflowOptions2;
|
|
199
313
|
}): Promise<WorkflowRun>;
|
|
200
314
|
pauseWorkflow({ runId, resourceId }: {
|
|
201
315
|
runId: string;
|
|
@@ -286,4 +400,4 @@ declare class WorkflowEngineError extends Error {
|
|
|
286
400
|
declare class WorkflowRunNotFoundError extends WorkflowEngineError {
|
|
287
401
|
constructor(runId?: string, workflowId?: string);
|
|
288
402
|
}
|
|
289
|
-
export { workflow, parseDuration, WorkflowStatus, WorkflowRunProgress, WorkflowRunNotFoundError, WorkflowPlugin, WorkflowOptions, WorkflowLogger, WorkflowInternalLoggerContext, WorkflowInternalLogger, WorkflowInternalDefinition, WorkflowFactory, WorkflowEngineOptions, WorkflowEngineError, WorkflowEngine, WorkflowDefinition, WorkflowContext, StepType, StepInternalDefinition, StepBaseContext, InputParameters, InferInputParameters, DurationObject, Duration };
|
|
403
|
+
export { workflow, parseDuration, createWorkflowRef, WorkflowStatus, WorkflowRunProgress, WorkflowRunNotFoundError, WorkflowRef, WorkflowPlugin, WorkflowOptions, WorkflowLogger, WorkflowInternalLoggerContext, WorkflowInternalLogger, WorkflowInternalDefinition, WorkflowFactory, WorkflowEngineOptions, WorkflowEngineError, WorkflowEngine, WorkflowDefinition, WorkflowContext, WorkflowClientOptions, WorkflowClient, StepType, StepInternalDefinition, StepBaseContext, StartWorkflowOptions, InputParameters, InferInputParameters, DurationObject, Duration };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pg from "pg";
|
|
2
2
|
type WorkflowRun = {
|
|
3
3
|
id: string;
|
|
4
4
|
createdAt: Date;
|
|
@@ -20,6 +20,7 @@ type WorkflowRun = {
|
|
|
20
20
|
jobId: string | null;
|
|
21
21
|
idempotencyKey: string | null;
|
|
22
22
|
};
|
|
23
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
23
24
|
type DurationObject = {
|
|
24
25
|
weeks?: number;
|
|
25
26
|
days?: number;
|
|
@@ -136,6 +137,21 @@ type WorkflowInternalDefinition<TInput extends InputParameters = InputParameters
|
|
|
136
137
|
interface WorkflowFactory<TStepExt = object> {
|
|
137
138
|
<I extends InputParameters = InputParameters>(id: string, handler: (context: WorkflowContext<I, StepBaseContext & TStepExt>) => Promise<unknown>, options?: WorkflowOptions<I>): WorkflowDefinition<I>;
|
|
138
139
|
use<TNewExt>(plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>): WorkflowFactory<TStepExt & TNewExt>;
|
|
140
|
+
ref<TInput extends InputParameters = InputParameters>(id: string, options?: {
|
|
141
|
+
inputSchema?: TInput;
|
|
142
|
+
}): WorkflowRef<TInput>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Lightweight workflow reference - carries the workflow ID and input type
|
|
146
|
+
* but no handler code. Safe to import in API services without pulling in
|
|
147
|
+
* heavy worker dependencies.
|
|
148
|
+
*
|
|
149
|
+
* Callable: pass a handler to create a full WorkflowDefinition.
|
|
150
|
+
*/
|
|
151
|
+
interface WorkflowRef<TInput extends InputParameters = InputParameters> {
|
|
152
|
+
(handler: (context: WorkflowContext<TInput, StepBaseContext>) => Promise<unknown>, options?: Omit<WorkflowOptions<TInput>, "inputSchema">): WorkflowDefinition<TInput>;
|
|
153
|
+
readonly id: string;
|
|
154
|
+
readonly inputSchema?: TInput;
|
|
139
155
|
}
|
|
140
156
|
type WorkflowRunProgress = WorkflowRun & {
|
|
141
157
|
completionPercentage: number;
|
|
@@ -154,15 +170,117 @@ interface WorkflowInternalLogger {
|
|
|
154
170
|
log(message: string, context?: WorkflowInternalLoggerContext): void;
|
|
155
171
|
error(message: string, error: Error, context?: WorkflowInternalLoggerContext): void;
|
|
156
172
|
}
|
|
173
|
+
type WorkflowClientOptions = {
|
|
174
|
+
logger?: WorkflowLogger;
|
|
175
|
+
} & ({
|
|
176
|
+
pool: pg.Pool;
|
|
177
|
+
connectionString?: never;
|
|
178
|
+
} | {
|
|
179
|
+
connectionString: string;
|
|
180
|
+
pool?: never;
|
|
181
|
+
});
|
|
182
|
+
type StartWorkflowOptions = {
|
|
183
|
+
resourceId?: string;
|
|
184
|
+
timeout?: number;
|
|
185
|
+
retries?: number;
|
|
186
|
+
expireInSeconds?: number;
|
|
187
|
+
idempotencyKey?: string;
|
|
188
|
+
};
|
|
189
|
+
declare class WorkflowClient {
|
|
190
|
+
private boss;
|
|
191
|
+
private db;
|
|
192
|
+
private pool;
|
|
193
|
+
private _ownsPool;
|
|
194
|
+
private _started;
|
|
195
|
+
private logger;
|
|
196
|
+
constructor({ logger,...connectionOptions }: WorkflowClientOptions);
|
|
197
|
+
start(): Promise<void>;
|
|
198
|
+
stop(): Promise<void>;
|
|
199
|
+
startWorkflow<TInput extends InputParameters>(ref: WorkflowRef<TInput>, input: InferInputParameters<TInput>, options?: StartWorkflowOptions): Promise<WorkflowRun>;
|
|
200
|
+
startWorkflow(params: {
|
|
201
|
+
workflowId: string;
|
|
202
|
+
input: unknown;
|
|
203
|
+
resourceId?: string;
|
|
204
|
+
idempotencyKey?: string;
|
|
205
|
+
options?: StartWorkflowOptions;
|
|
206
|
+
}): Promise<WorkflowRun>;
|
|
207
|
+
triggerEvent({ runId, resourceId, eventName, data, options }: {
|
|
208
|
+
runId: string;
|
|
209
|
+
resourceId?: string;
|
|
210
|
+
eventName: string;
|
|
211
|
+
data?: Record<string, unknown>;
|
|
212
|
+
options?: {
|
|
213
|
+
expireInSeconds?: number;
|
|
214
|
+
};
|
|
215
|
+
}): Promise<WorkflowRun>;
|
|
216
|
+
pauseWorkflow({ runId, resourceId }: {
|
|
217
|
+
runId: string;
|
|
218
|
+
resourceId?: string;
|
|
219
|
+
}): Promise<WorkflowRun>;
|
|
220
|
+
resumeWorkflow({ runId, resourceId, options }: {
|
|
221
|
+
runId: string;
|
|
222
|
+
resourceId?: string;
|
|
223
|
+
options?: {
|
|
224
|
+
expireInSeconds?: number;
|
|
225
|
+
};
|
|
226
|
+
}): Promise<WorkflowRun>;
|
|
227
|
+
fastForwardWorkflow({ runId, resourceId, data }: {
|
|
228
|
+
runId: string;
|
|
229
|
+
resourceId?: string;
|
|
230
|
+
data?: Record<string, unknown>;
|
|
231
|
+
}): Promise<WorkflowRun>;
|
|
232
|
+
cancelWorkflow({ runId, resourceId }: {
|
|
233
|
+
runId: string;
|
|
234
|
+
resourceId?: string;
|
|
235
|
+
}): Promise<WorkflowRun>;
|
|
236
|
+
getRun({ runId, resourceId }: {
|
|
237
|
+
runId: string;
|
|
238
|
+
resourceId?: string;
|
|
239
|
+
}): Promise<WorkflowRun>;
|
|
240
|
+
checkProgress({ runId, resourceId }: {
|
|
241
|
+
runId: string;
|
|
242
|
+
resourceId?: string;
|
|
243
|
+
}): Promise<WorkflowRunProgress>;
|
|
244
|
+
getRuns({ resourceId, startingAfter, endingBefore, limit, statuses, workflowId }: {
|
|
245
|
+
resourceId?: string;
|
|
246
|
+
startingAfter?: string | null;
|
|
247
|
+
endingBefore?: string | null;
|
|
248
|
+
limit?: number;
|
|
249
|
+
statuses?: WorkflowStatus[];
|
|
250
|
+
workflowId?: string;
|
|
251
|
+
}): Promise<{
|
|
252
|
+
items: WorkflowRun[];
|
|
253
|
+
nextCursor: string | null;
|
|
254
|
+
prevCursor: string | null;
|
|
255
|
+
hasMore: boolean;
|
|
256
|
+
hasPrev: boolean;
|
|
257
|
+
}>;
|
|
258
|
+
private ensureStarted;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Create a lightweight workflow reference.
|
|
262
|
+
* Safe to import from `pg-workflows/client` - no engine or handler code.
|
|
263
|
+
*/
|
|
264
|
+
declare function createWorkflowRef<TInput extends InputParameters = InputParameters>(id: string, options?: {
|
|
265
|
+
inputSchema?: TInput;
|
|
266
|
+
}): WorkflowRef<TInput>;
|
|
157
267
|
declare const workflow: WorkflowFactory;
|
|
158
|
-
import
|
|
268
|
+
import pg2 from "pg";
|
|
159
269
|
import { Db, PgBoss } from "pg-boss";
|
|
270
|
+
type StartWorkflowOptions2 = {
|
|
271
|
+
resourceId?: string;
|
|
272
|
+
timeout?: number;
|
|
273
|
+
retries?: number;
|
|
274
|
+
expireInSeconds?: number;
|
|
275
|
+
batchSize?: number;
|
|
276
|
+
idempotencyKey?: string;
|
|
277
|
+
};
|
|
160
278
|
type WorkflowEngineOptions = {
|
|
161
279
|
workflows?: WorkflowDefinition[];
|
|
162
280
|
logger?: WorkflowLogger;
|
|
163
281
|
boss?: PgBoss;
|
|
164
282
|
} & ({
|
|
165
|
-
pool:
|
|
283
|
+
pool: pg2.Pool;
|
|
166
284
|
connectionString?: never;
|
|
167
285
|
} | {
|
|
168
286
|
connectionString: string;
|
|
@@ -185,17 +303,13 @@ declare class WorkflowEngine {
|
|
|
185
303
|
registerWorkflow(definition: WorkflowDefinition<InputParameters>): Promise<WorkflowEngine>;
|
|
186
304
|
unregisterWorkflow(workflowId: string): Promise<WorkflowEngine>;
|
|
187
305
|
unregisterAllWorkflows(): Promise<WorkflowEngine>;
|
|
188
|
-
startWorkflow(
|
|
306
|
+
startWorkflow<TInput extends InputParameters>(ref: WorkflowRef<TInput>, input: InferInputParameters<TInput>, options?: StartWorkflowOptions2): Promise<WorkflowRun>;
|
|
307
|
+
startWorkflow(params: {
|
|
189
308
|
resourceId?: string;
|
|
190
309
|
workflowId: string;
|
|
191
310
|
input: unknown;
|
|
192
311
|
idempotencyKey?: string;
|
|
193
|
-
options?:
|
|
194
|
-
timeout?: number;
|
|
195
|
-
retries?: number;
|
|
196
|
-
expireInSeconds?: number;
|
|
197
|
-
batchSize?: number;
|
|
198
|
-
};
|
|
312
|
+
options?: StartWorkflowOptions2;
|
|
199
313
|
}): Promise<WorkflowRun>;
|
|
200
314
|
pauseWorkflow({ runId, resourceId }: {
|
|
201
315
|
runId: string;
|
|
@@ -286,4 +400,4 @@ declare class WorkflowEngineError extends Error {
|
|
|
286
400
|
declare class WorkflowRunNotFoundError extends WorkflowEngineError {
|
|
287
401
|
constructor(runId?: string, workflowId?: string);
|
|
288
402
|
}
|
|
289
|
-
export { workflow, parseDuration, WorkflowStatus, WorkflowRunProgress, WorkflowRunNotFoundError, WorkflowPlugin, WorkflowOptions, WorkflowLogger, WorkflowInternalLoggerContext, WorkflowInternalLogger, WorkflowInternalDefinition, WorkflowFactory, WorkflowEngineOptions, WorkflowEngineError, WorkflowEngine, WorkflowDefinition, WorkflowContext, StepType, StepInternalDefinition, StepBaseContext, InputParameters, InferInputParameters, DurationObject, Duration };
|
|
403
|
+
export { workflow, parseDuration, createWorkflowRef, WorkflowStatus, WorkflowRunProgress, WorkflowRunNotFoundError, WorkflowRef, WorkflowPlugin, WorkflowOptions, WorkflowLogger, WorkflowInternalLoggerContext, WorkflowInternalLogger, WorkflowInternalDefinition, WorkflowFactory, WorkflowEngineOptions, WorkflowEngineError, WorkflowEngine, WorkflowDefinition, WorkflowContext, WorkflowClientOptions, WorkflowClient, StepType, StepInternalDefinition, StepBaseContext, StartWorkflowOptions, InputParameters, InferInputParameters, DurationObject, Duration };
|