@falcondev-oss/workflow 0.7.4 → 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/dist/index.d.mts CHANGED
@@ -4,7 +4,7 @@ import { Meter, Span } from "@opentelemetry/api";
4
4
  import { SuperJSONResult } from "superjson";
5
5
  import { Options } from "p-retry";
6
6
  import { StandardSchemaV1 } from "@standard-schema/spec";
7
- import { AddOptions, Job, Queue, QueueOptions, WorkerOptions } from "groupmq";
7
+ import { AddOptions, Job, Queue, QueueOptions, Worker, WorkerOptions } from "groupmq";
8
8
  import { Except, IsUnknown, SetOptional, Tagged } from "type-fest";
9
9
 
10
10
  //#region src/settings.d.ts
@@ -103,18 +103,21 @@ type WorkflowWorkerOptions<Input> = Except<WorkerOptions<WorkflowJobPayloadInter
103
103
  };
104
104
  };
105
105
  declare class Workflow<RunInput, Input, Output> {
106
- id: string;
107
- private opts;
108
- private queue?;
106
+ 'id': string;
107
+ private 'opts';
108
+ private 'queue'?;
109
+ '~internal': {
110
+ getOrCreateQueue: () => Promise<WorkflowQueueInternal<Input>>;
111
+ };
109
112
  constructor(opts: WorkflowOptions<RunInput, Input, Output>);
110
- work(opts?: WorkflowWorkerOptions<Input>): Promise<this>;
111
- run(input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
112
- runIn(input: RunInput, delayMs: number, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
113
- runAt(input: RunInput, date: Date, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
114
- runCron(scheduleId: string, cron: string, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
115
- runEvery(scheduleId: string, everyMs: number, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
116
- private getOrCreateQueue;
117
- private setupMetrics;
113
+ 'work'(opts?: WorkflowWorkerOptions<Input>): Promise<Worker<WorkflowJobPayloadInternal<Input>>>;
114
+ 'run'(input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
115
+ 'runIn'(input: RunInput, delayMs: number, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
116
+ 'runAt'(input: RunInput, date: Date, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
117
+ 'runCron'(scheduleId: string, cron: string, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
118
+ 'runEvery'(scheduleId: string, everyMs: number, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
119
+ private 'getOrCreateQueue';
120
+ private 'setupMetrics';
118
121
  }
119
122
  interface WorkflowRunContext<Input> {
120
123
  input: IsUnknown<Input> extends true ? undefined : Input;
package/dist/index.mjs CHANGED
@@ -9706,14 +9706,15 @@ var WorkflowStep = class WorkflowStep {
9706
9706
  //#endregion
9707
9707
  //#region src/workflow.ts
9708
9708
  var Workflow = class {
9709
- id;
9710
- opts;
9711
- queue;
9712
- constructor(opts) {
9709
+ "id";
9710
+ "opts";
9711
+ "queue";
9712
+ "~internal" = { getOrCreateQueue: this.getOrCreateQueue.bind(this) };
9713
+ "constructor"(opts) {
9713
9714
  this.id = opts.id;
9714
9715
  this.opts = opts;
9715
9716
  }
9716
- async work(opts) {
9717
+ async "work"(opts) {
9717
9718
  const queue = await this.getOrCreateQueue();
9718
9719
  const worker = new Worker({
9719
9720
  handler: async (job) => {
@@ -9762,9 +9763,9 @@ var Workflow = class {
9762
9763
  Settings.logger?.info?.(`[${this.opts.id}] Received ${signal}, shutting down worker...`);
9763
9764
  await worker.close();
9764
9765
  }, { wait: 1e4 });
9765
- return this;
9766
+ return worker;
9766
9767
  }
9767
- async run(input, opts) {
9768
+ async "run"(input, opts) {
9768
9769
  const parsedInput = this.opts.schema && await this.opts.schema["~standard"].validate(input);
9769
9770
  if (parsedInput?.issues) throw new Error("Invalid workflow input");
9770
9771
  const queue = await this.getOrCreateQueue();
@@ -9788,33 +9789,33 @@ var Workflow = class {
9788
9789
  }) });
9789
9790
  });
9790
9791
  }
9791
- async runIn(input, delayMs, opts) {
9792
+ async "runIn"(input, delayMs, opts) {
9792
9793
  return this.run(input, {
9793
9794
  delay: delayMs,
9794
9795
  ...opts
9795
9796
  });
9796
9797
  }
9797
- async runAt(input, date, opts) {
9798
+ async "runAt"(input, date, opts) {
9798
9799
  return this.run(input, {
9799
9800
  runAt: date,
9800
9801
  ...opts
9801
9802
  });
9802
9803
  }
9803
- async runCron(scheduleId, cron, input, opts) {
9804
+ async "runCron"(scheduleId, cron, input, opts) {
9804
9805
  return this.run(input, {
9805
9806
  groupId: scheduleId,
9806
9807
  repeat: { pattern: cron },
9807
9808
  ...opts
9808
9809
  });
9809
9810
  }
9810
- async runEvery(scheduleId, everyMs, input, opts) {
9811
+ async "runEvery"(scheduleId, everyMs, input, opts) {
9811
9812
  return this.run(input, {
9812
9813
  groupId: scheduleId,
9813
9814
  repeat: { every: everyMs },
9814
9815
  ...opts
9815
9816
  });
9816
9817
  }
9817
- async getOrCreateQueue() {
9818
+ async "getOrCreateQueue"() {
9818
9819
  if (!this.queue) this.queue = new Queue({
9819
9820
  namespace: this.opts.id,
9820
9821
  redis: this.opts.redis ?? await defaultRedisConnection(),
@@ -9823,7 +9824,7 @@ var Workflow = class {
9823
9824
  });
9824
9825
  return this.queue;
9825
9826
  }
9826
- async setupMetrics({ meter, prefix }) {
9827
+ async "setupMetrics"({ meter, prefix }) {
9827
9828
  const attributes = { workflow_id: this.opts.id };
9828
9829
  const queue = await this.getOrCreateQueue();
9829
9830
  const completedJobsGauge = meter.createObservableGauge(`${prefix}_workflow_completed_jobs`, { description: "Number of completed workflow jobs" });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@falcondev-oss/workflow",
3
3
  "type": "module",
4
- "version": "0.7.4",
4
+ "version": "0.8.1",
5
5
  "description": "Simple type-safe queue worker with durable execution using Redis.",
6
6
  "license": "MIT",
7
7
  "repository": "github:falcondev-oss/workflow",