@dudousxd/nestjs-durable-core 0.88.0 → 0.89.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/index.d.cts CHANGED
@@ -5562,6 +5562,10 @@ declare class WorkflowEngine {
5562
5562
  private readonly workflows;
5563
5563
  /** The newest registered version per workflow name — used to `start` new runs. */
5564
5564
  private readonly latest;
5565
+ /** Workflows this instance starts but never runs, keyed `name@version` (like {@link workflows}), so every version stays startable. See {@link registerStartOnly}. */
5566
+ private readonly startOnly;
5567
+ /** The latest start-only registration per name, for unpinned starts (like {@link latest}). */
5568
+ private readonly startOnlyLatest;
5565
5569
  /** Event name → subscribing workflow name → that workflow's subscriptions to it. See `onEvent`. */
5566
5570
  private readonly eventTriggers;
5567
5571
  /** Durable-entity subsystem (registers the `__entity` runner; see `registerEntity`). */
@@ -5841,6 +5845,23 @@ declare class WorkflowEngine {
5841
5845
  /** Handler workflows a matching failure is routed to — see {@link OnErrorRoute}. */
5842
5846
  onError?: OnErrorRoute[] | undefined;
5843
5847
  }): void;
5848
+ /**
5849
+ * Let {@link start} create runs of `name@version` on this instance without registering a body here:
5850
+ * the run is stored and left for an instance that {@link register}ed the workflow, and this one
5851
+ * never executes it. For a process that only emits work (an API pod) while workers run it.
5852
+ *
5853
+ * Runs this instance picks up anyway (a driving poll, the run queue) are released for another
5854
+ * instance without a log line, and dead-lettered after `unregisteredWorkflowGraceMs` like any run
5855
+ * whose workflow nobody registered. A {@link register} of the same name on this instance wins.
5856
+ */
5857
+ registerStartOnly(name: string, version: string, opts?: {
5858
+ tags?: string[] | undefined;
5859
+ /** The declaring package, stamped onto every run started here. See {@link register}'s `origin`. */
5860
+ origin?: string | undefined;
5861
+ validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
5862
+ }): void;
5863
+ /** Whether `run` is of a workflow this instance only starts (see {@link registerStartOnly}). */
5864
+ private isStartOnlyHere;
5844
5865
  /**
5845
5866
  * The retained in-process body for `name@version`, for an IN-APP worker that consumes this engine's
5846
5867
  * own group to SERVE a group-served `register(..., { group, executor })` workflow (uniform dispatch):
package/dist/index.d.ts CHANGED
@@ -5562,6 +5562,10 @@ declare class WorkflowEngine {
5562
5562
  private readonly workflows;
5563
5563
  /** The newest registered version per workflow name — used to `start` new runs. */
5564
5564
  private readonly latest;
5565
+ /** Workflows this instance starts but never runs, keyed `name@version` (like {@link workflows}), so every version stays startable. See {@link registerStartOnly}. */
5566
+ private readonly startOnly;
5567
+ /** The latest start-only registration per name, for unpinned starts (like {@link latest}). */
5568
+ private readonly startOnlyLatest;
5565
5569
  /** Event name → subscribing workflow name → that workflow's subscriptions to it. See `onEvent`. */
5566
5570
  private readonly eventTriggers;
5567
5571
  /** Durable-entity subsystem (registers the `__entity` runner; see `registerEntity`). */
@@ -5841,6 +5845,23 @@ declare class WorkflowEngine {
5841
5845
  /** Handler workflows a matching failure is routed to — see {@link OnErrorRoute}. */
5842
5846
  onError?: OnErrorRoute[] | undefined;
5843
5847
  }): void;
5848
+ /**
5849
+ * Let {@link start} create runs of `name@version` on this instance without registering a body here:
5850
+ * the run is stored and left for an instance that {@link register}ed the workflow, and this one
5851
+ * never executes it. For a process that only emits work (an API pod) while workers run it.
5852
+ *
5853
+ * Runs this instance picks up anyway (a driving poll, the run queue) are released for another
5854
+ * instance without a log line, and dead-lettered after `unregisteredWorkflowGraceMs` like any run
5855
+ * whose workflow nobody registered. A {@link register} of the same name on this instance wins.
5856
+ */
5857
+ registerStartOnly(name: string, version: string, opts?: {
5858
+ tags?: string[] | undefined;
5859
+ /** The declaring package, stamped onto every run started here. See {@link register}'s `origin`. */
5860
+ origin?: string | undefined;
5861
+ validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
5862
+ }): void;
5863
+ /** Whether `run` is of a workflow this instance only starts (see {@link registerStartOnly}). */
5864
+ private isStartOnlyHere;
5844
5865
  /**
5845
5866
  * The retained in-process body for `name@version`, for an IN-APP worker that consumes this engine's
5846
5867
  * own group to SERVE a group-served `register(..., { group, executor })` workflow (uniform dispatch):
package/dist/index.js CHANGED
@@ -6453,6 +6453,10 @@ var WorkflowEngine = class _WorkflowEngine {
6453
6453
  workflows = /* @__PURE__ */ new Map();
6454
6454
  /** The newest registered version per workflow name — used to `start` new runs. */
6455
6455
  latest = /* @__PURE__ */ new Map();
6456
+ /** Workflows this instance starts but never runs, keyed `name@version` (like {@link workflows}), so every version stays startable. See {@link registerStartOnly}. */
6457
+ startOnly = /* @__PURE__ */ new Map();
6458
+ /** The latest start-only registration per name, for unpinned starts (like {@link latest}). */
6459
+ startOnlyLatest = /* @__PURE__ */ new Map();
6456
6460
  /** Event name → subscribing workflow name → that workflow's subscriptions to it. See `onEvent`. */
6457
6461
  eventTriggers = /* @__PURE__ */ new Map();
6458
6462
  /** Durable-entity subsystem (registers the `__entity` runner; see `registerEntity`). */
@@ -6973,7 +6977,7 @@ var WorkflowEngine = class _WorkflowEngine {
6973
6977
  if (!this.isRegisteredHere(run) && !await this.canResolveWorkflow(run)) {
6974
6978
  const result = await this.settleUnregistered(run, nowMs);
6975
6979
  if (result) settled?.set(run.id, result);
6976
- else if (result === void 0) this.logUnregisteredSkip(run);
6980
+ else if (result === void 0 && !this.isStartOnlyHere(run)) this.logUnregisteredSkip(run);
6977
6981
  continue;
6978
6982
  }
6979
6983
  try {
@@ -7119,6 +7123,34 @@ var WorkflowEngine = class _WorkflowEngine {
7119
7123
  }
7120
7124
  }
7121
7125
  /**
7126
+ * Let {@link start} create runs of `name@version` on this instance without registering a body here:
7127
+ * the run is stored and left for an instance that {@link register}ed the workflow, and this one
7128
+ * never executes it. For a process that only emits work (an API pod) while workers run it.
7129
+ *
7130
+ * Runs this instance picks up anyway (a driving poll, the run queue) are released for another
7131
+ * instance without a log line, and dead-lettered after `unregisteredWorkflowGraceMs` like any run
7132
+ * whose workflow nobody registered. A {@link register} of the same name on this instance wins.
7133
+ */
7134
+ registerStartOnly(name, version, opts) {
7135
+ const entry = {
7136
+ name,
7137
+ version,
7138
+ fn: /* @__PURE__ */ __name(() => {
7139
+ throw new Error(`workflow ${name} is start-only on this instance \u2014 it has no body here`);
7140
+ }, "fn"),
7141
+ tags: opts?.tags,
7142
+ validateInput: opts?.validateInput,
7143
+ origin: opts?.origin
7144
+ };
7145
+ this.startOnly.set(versionKey(name, version), entry);
7146
+ const current = this.startOnlyLatest.get(name);
7147
+ if (!current || isNewerVersion(version, current.version)) this.startOnlyLatest.set(name, entry);
7148
+ }
7149
+ /** Whether `run` is of a workflow this instance only starts (see {@link registerStartOnly}). */
7150
+ isStartOnlyHere(run) {
7151
+ return !this.isRegisteredHere(run) && this.startOnly.has(versionKey(run.workflow, run.workflowVersion));
7152
+ }
7153
+ /**
7122
7154
  * The retained in-process body for `name@version`, for an IN-APP worker that consumes this engine's
7123
7155
  * own group to SERVE a group-served `register(..., { group, executor })` workflow (uniform dispatch):
7124
7156
  * the worker fetches the body by name when it picks up the dispatched {@link WorkflowTask}, replays
@@ -8658,7 +8690,8 @@ var WorkflowEngine = class _WorkflowEngine {
8658
8690
  async start(workflow, input, runId, opts) {
8659
8691
  const name = workflowName(workflow);
8660
8692
  const pinned = opts?.version;
8661
- let registered = pinned === void 0 ? this.latest.get(name) : this.workflows.get(versionKey(name, pinned));
8693
+ const startOnly = pinned === void 0 ? this.startOnlyLatest.get(name) : this.startOnly.get(versionKey(name, pinned));
8694
+ let registered = pinned === void 0 ? this.latest.get(name) ?? startOnly : this.workflows.get(versionKey(name, pinned)) ?? startOnly;
8662
8695
  if (!registered && pinned === void 0) {
8663
8696
  const ancestor = await this.findRemoteAncestor(runId);
8664
8697
  if (ancestor) registered = this.synthesizeRemoteChild(name, ancestor.version, ancestor);
@@ -8761,7 +8794,10 @@ var WorkflowEngine = class _WorkflowEngine {
8761
8794
  status: "suspended"
8762
8795
  };
8763
8796
  }
8764
- await this.dispatchRun(runId, run.priority, pendingStateKey(run.updatedAt));
8797
+ const runsLocally = this.customDispatcher === void 0 && !this.dispatchesOverTransport;
8798
+ if (!(runsLocally && registered === startOnly)) {
8799
+ await this.dispatchRun(runId, run.priority, pendingStateKey(run.updatedAt));
8800
+ }
8765
8801
  if (this.controlPlane && !this.queuesRunsOverTransport) {
8766
8802
  void this.controlPlane.publishControl({
8767
8803
  kind: "enqueued",
@@ -9418,7 +9454,7 @@ var WorkflowEngine = class _WorkflowEngine {
9418
9454
  result: settled2,
9419
9455
  dispatch: false
9420
9456
  };
9421
- if (settled2 === void 0) this.logUnregisteredSkip(run);
9457
+ if (settled2 === void 0 && !this.isStartOnlyHere(run)) this.logUnregisteredSkip(run);
9422
9458
  return void 0;
9423
9459
  }
9424
9460
  const settled = await this.countRecovery(run);
@@ -9699,6 +9735,7 @@ var WorkflowEngine = class _WorkflowEngine {
9699
9735
  const run = await this.store.getRun(runId);
9700
9736
  const settled = run ? await this.settleUnregistered(run, nowMs) : null;
9701
9737
  if (settled !== void 0) return settled;
9738
+ if (run && this.isStartOnlyHere(run)) return null;
9702
9739
  }
9703
9740
  throw err;
9704
9741
  });
@@ -9988,6 +10025,7 @@ var WorkflowEngine = class _WorkflowEngine {
9988
10025
  if (error2 instanceof WorkflowNotRegistered) {
9989
10026
  const settled = await this.settleUnregistered(run, this.clock()).catch(() => void 0);
9990
10027
  if (settled) return settled;
10028
+ if (this.isStartOnlyHere(run)) return void 0;
9991
10029
  }
9992
10030
  console.error(`[nestjs-durable] could not resume run ${run.id} (${run.workflow}@${run.workflowVersion}); leaving it for another instance:`, error2);
9993
10031
  return void 0;
@@ -10017,7 +10055,7 @@ var WorkflowEngine = class _WorkflowEngine {
10017
10055
  if (error2 instanceof WorkflowNotRegistered) {
10018
10056
  const settled = await this.settleUnregistered(run, nowMs).catch(() => void 0);
10019
10057
  if (settled) results.push(settled);
10020
- if (settled !== void 0) continue;
10058
+ if (settled !== void 0 || this.isStartOnlyHere(run)) continue;
10021
10059
  }
10022
10060
  console.error(`[nestjs-durable] could not resume run ${run.id} (${run.workflow}@${run.workflowVersion}); leaving it for another instance:`, error2);
10023
10061
  } finally {