gemi 0.217.0 → 0.219.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.
Files changed (115) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/ai/index.js.map +2 -2
  3. package/dist/ai/testing/index.js +2 -2
  4. package/dist/ai/testing/index.js.map +1 -1
  5. package/dist/{chunk-ww62b10k.js → chunk-0egjv6cj.js} +2 -2
  6. package/dist/{chunk-ww62b10k.js.map → chunk-0egjv6cj.js.map} +1 -1
  7. package/dist/{chunk-q30f4r5x.js → chunk-2vktfp1f.js} +2 -2
  8. package/dist/{chunk-q30f4r5x.js.map → chunk-2vktfp1f.js.map} +1 -1
  9. package/dist/chunk-4g24ffv8.js +5 -0
  10. package/dist/{chunk-d6bgh2nr.js.map → chunk-4g24ffv8.js.map} +1 -1
  11. package/dist/chunk-4kkb85z8.js +8 -0
  12. package/dist/{chunk-xese0rng.js.map → chunk-4kkb85z8.js.map} +4 -5
  13. package/dist/{chunk-b1pps9bj.js → chunk-59p034g3.js} +2 -2
  14. package/dist/{chunk-b1pps9bj.js.map → chunk-59p034g3.js.map} +1 -1
  15. package/dist/{chunk-p18nfs9t.js → chunk-66re5qsr.js} +2 -2
  16. package/dist/{chunk-p18nfs9t.js.map → chunk-66re5qsr.js.map} +1 -1
  17. package/dist/{chunk-sqqh78tf.js → chunk-6my6c6b1.js} +2 -2
  18. package/dist/{chunk-sqqh78tf.js.map → chunk-6my6c6b1.js.map} +1 -1
  19. package/dist/chunk-71r1x773.js +19 -0
  20. package/dist/{chunk-b1btq22a.js.map → chunk-71r1x773.js.map} +3 -3
  21. package/dist/chunk-ak85ee4e.js +39 -0
  22. package/dist/chunk-ak85ee4e.js.map +20 -0
  23. package/dist/{chunk-gxd1388t.js → chunk-c250kpcm.js} +2 -2
  24. package/dist/{chunk-gxd1388t.js.map → chunk-c250kpcm.js.map} +1 -1
  25. package/dist/{chunk-4s72m6zx.js → chunk-cmyt2txd.js} +3 -3
  26. package/dist/{chunk-4s72m6zx.js.map → chunk-cmyt2txd.js.map} +1 -1
  27. package/dist/{chunk-fq7wkefg.js → chunk-cw50n89n.js} +2 -2
  28. package/dist/{chunk-fq7wkefg.js.map → chunk-cw50n89n.js.map} +1 -1
  29. package/dist/{chunk-c71g46aw.js → chunk-g5drp5xx.js} +2 -2
  30. package/dist/{chunk-c71g46aw.js.map → chunk-g5drp5xx.js.map} +1 -1
  31. package/dist/{chunk-snt0523y.js → chunk-gf3m0866.js} +2 -2
  32. package/dist/{chunk-snt0523y.js.map → chunk-gf3m0866.js.map} +1 -1
  33. package/dist/{chunk-94fdjkzf.js → chunk-jfpwjqvq.js} +2 -2
  34. package/dist/{chunk-94fdjkzf.js.map → chunk-jfpwjqvq.js.map} +1 -1
  35. package/dist/{chunk-gxfyd8wr.js → chunk-kt174y9e.js} +3 -3
  36. package/dist/{chunk-gxfyd8wr.js.map → chunk-kt174y9e.js.map} +1 -1
  37. package/dist/{chunk-s7jwsbfd.js → chunk-nrv7hdeh.js} +3 -3
  38. package/dist/{chunk-s7jwsbfd.js.map → chunk-nrv7hdeh.js.map} +1 -1
  39. package/dist/{chunk-7t13vyzg.js → chunk-p4b5hmr8.js} +2 -2
  40. package/dist/{chunk-7t13vyzg.js.map → chunk-p4b5hmr8.js.map} +1 -1
  41. package/dist/chunk-pnt0c59g.js +484 -0
  42. package/dist/chunk-pnt0c59g.js.map +24 -0
  43. package/dist/{chunk-m0pfdc1n.js → chunk-s4sx97fn.js} +3 -3
  44. package/dist/{chunk-m0pfdc1n.js.map → chunk-s4sx97fn.js.map} +1 -1
  45. package/dist/{chunk-ncw3zjxm.js → chunk-w4aw44zg.js} +2 -2
  46. package/dist/{chunk-ncw3zjxm.js.map → chunk-w4aw44zg.js.map} +1 -1
  47. package/dist/{chunk-7081awrd.js → chunk-w9a3b4vs.js} +2 -2
  48. package/dist/{chunk-7081awrd.js.map → chunk-w9a3b4vs.js.map} +1 -1
  49. package/dist/{chunk-bcfwa370.js → chunk-xm6hfksv.js} +2 -2
  50. package/dist/{chunk-bcfwa370.js.map → chunk-xm6hfksv.js.map} +1 -1
  51. package/dist/{chunk-k8nsefzb.js → chunk-xrkr2yzz.js} +2 -2
  52. package/dist/{chunk-k8nsefzb.js.map → chunk-xrkr2yzz.js.map} +1 -1
  53. package/dist/{chunk-tsjg2k2h.js → chunk-xvf1hcxg.js} +2 -2
  54. package/dist/{chunk-tsjg2k2h.js.map → chunk-xvf1hcxg.js.map} +2 -2
  55. package/dist/{chunk-eh3ktv8k.js → chunk-y12m6w7b.js} +2 -2
  56. package/dist/{chunk-eh3ktv8k.js.map → chunk-y12m6w7b.js.map} +1 -1
  57. package/dist/chunk-yv3y3r9q.js +88 -0
  58. package/dist/{chunk-sxxkkx75.js.map → chunk-yv3y3r9q.js.map} +3 -10
  59. package/dist/client/index.d.ts +2 -0
  60. package/dist/client/index.d.ts.map +1 -1
  61. package/dist/client/index.js +54 -1
  62. package/dist/client/index.js.map +1 -1
  63. package/dist/client/useWorkflow.d.ts +51 -0
  64. package/dist/client/useWorkflow.d.ts.map +1 -0
  65. package/dist/console/run.js +2 -2
  66. package/dist/console/run.js.map +1 -1
  67. package/dist/database/index.js +1 -1
  68. package/dist/facades/index.js +2 -2
  69. package/dist/facades/index.js.map +1 -1
  70. package/dist/http/index.js +2 -2
  71. package/dist/http/index.js.map +1 -1
  72. package/dist/i18n/index.js +2 -2
  73. package/dist/i18n/index.js.map +1 -1
  74. package/dist/kernel/index.js +2 -2
  75. package/dist/kernel/index.js.map +1 -1
  76. package/dist/orm/index.js +2 -2
  77. package/dist/orm/index.js.map +1 -1
  78. package/dist/server/index.js +1 -1
  79. package/dist/services/index.d.ts +4 -3
  80. package/dist/services/index.d.ts.map +1 -1
  81. package/dist/services/index.js +3 -3
  82. package/dist/services/index.js.map +2 -2
  83. package/dist/services/queue/DatabaseQueueDriver.d.ts +8 -1
  84. package/dist/services/queue/DatabaseQueueDriver.d.ts.map +1 -1
  85. package/dist/services/queue/QueueManager.d.ts +2 -0
  86. package/dist/services/queue/QueueManager.d.ts.map +1 -1
  87. package/dist/services/queue/work.js +2 -2
  88. package/dist/services/queue/work.js.map +1 -1
  89. package/dist/services/queue/workflow/DatabaseWorkflowStore.d.ts +20 -1
  90. package/dist/services/queue/workflow/DatabaseWorkflowStore.d.ts.map +1 -1
  91. package/dist/services/queue/workflow/MemoryWorkflowStore.d.ts +12 -1
  92. package/dist/services/queue/workflow/MemoryWorkflowStore.d.ts.map +1 -1
  93. package/dist/services/queue/workflow/Step.d.ts +124 -2
  94. package/dist/services/queue/workflow/Step.d.ts.map +1 -1
  95. package/dist/services/queue/workflow/Workflow.d.ts +37 -33
  96. package/dist/services/queue/workflow/Workflow.d.ts.map +1 -1
  97. package/dist/services/queue/workflow/WorkflowRuntime.d.ts +51 -0
  98. package/dist/services/queue/workflow/WorkflowRuntime.d.ts.map +1 -1
  99. package/dist/services/queue/workflow/WorkflowStore.d.ts +66 -16
  100. package/dist/services/queue/workflow/WorkflowStore.d.ts.map +1 -1
  101. package/dist/services/queue/workflow/wire.d.ts +71 -0
  102. package/dist/services/queue/workflow/wire.d.ts.map +1 -0
  103. package/dist/services/queue/workflow/workflowContract.d.ts +2 -0
  104. package/dist/services/queue/workflow/workflowContract.d.ts.map +1 -1
  105. package/dist/support/index.js +2 -2
  106. package/dist/support/index.js.map +1 -1
  107. package/package.json +1 -1
  108. package/dist/chunk-b1btq22a.js +0 -19
  109. package/dist/chunk-d6bgh2nr.js +0 -5
  110. package/dist/chunk-sxxkkx75.js +0 -117
  111. package/dist/chunk-wkmd81k4.js +0 -416
  112. package/dist/chunk-wkmd81k4.js.map +0 -23
  113. package/dist/chunk-xb0evp2m.js +0 -5
  114. package/dist/chunk-xb0evp2m.js.map +0 -12
  115. package/dist/chunk-xese0rng.js +0 -13
@@ -1,6 +1,10 @@
1
+ import { ChangeFeedManager } from "../../change-feed/ChangeFeedManager";
2
+ import type { ChangeFeedResponse, StreamOptions } from "../../change-feed/stream";
1
3
  import { Job } from "../Job";
2
4
  import type { QueueManager } from "../QueueManager";
5
+ import { type EachProblem } from "./Step";
3
6
  import type { WorkflowClass, WorkflowStatus } from "./Workflow";
7
+ import { type WorkflowUpdate } from "./wire";
4
8
  import { type WorkflowStore } from "./WorkflowStore";
5
9
  /**
6
10
  * The queue's half of workflows: the registry of workflow classes, what
@@ -24,6 +28,10 @@ export declare class WorkflowRuntime {
24
28
  private readonly queue;
25
29
  private registry;
26
30
  private storeInstance;
31
+ private ownFeed;
32
+ /** Workflows with a publish scheduled, and when each was last published. */
33
+ private readonly publishing;
34
+ private readonly published;
27
35
  private tickClass;
28
36
  private readonly reportedNames;
29
37
  constructor(queue: QueueManager);
@@ -34,10 +42,53 @@ export declare class WorkflowRuntime {
34
42
  /** The internal job a workflow's passes run in, one class per manager. */
35
43
  get tickJob(): new () => Job;
36
44
  get store(): WorkflowStore;
45
+ /**
46
+ * The change feed workflow changes are published to: the application's,
47
+ * or one of this runtime's own (in memory) without one.
48
+ */
49
+ get feed(): ChangeFeedManager;
50
+ /** The ChangeFeed channel a workflow's changes are published to. */
51
+ channel(id: string): string;
52
+ /** What a change publishes: the status without `args` and `result`. */
53
+ update(id: string): Promise<WorkflowUpdate | null>;
54
+ /**
55
+ * An SSE response following workflow `id`: each event's `data` is a
56
+ * `WorkflowUpdate`, for a route that has already decided the caller may
57
+ * read it.
58
+ */
59
+ stream(request: {
60
+ rawRequest: Request;
61
+ } | Request, id: string, options?: StreamOptions): ChangeFeedResponse<WorkflowUpdate>;
62
+ /** A cursor at the workflow's channel head, for a view to hand its client. */
63
+ cursor(id: string): Promise<string>;
64
+ /**
65
+ * Follows workflow `id` on the server: yields it as it is now, then each
66
+ * newer update, and ends after the one that ended it. Yields nothing for
67
+ * an unknown id.
68
+ */
69
+ subscribe(id: string, options?: {
70
+ signal?: AbortSignal;
71
+ }): AsyncGenerator<WorkflowUpdate, void, undefined>;
72
+ /**
73
+ * The store, with every change scheduling a publish of the workflow it
74
+ * changed. Publishes are coalesced: at most one per workflow every
75
+ * `PUBLISH_INTERVAL_MS`, each carrying the workflow as it is then, so the
76
+ * last change is always published.
77
+ */
78
+ private publishingStore;
79
+ private schedulePublish;
80
+ private publish;
81
+ /** Ends this runtime's own feed, if it made one, and drops pending publishes. For tests. */
82
+ close(): Promise<void>;
37
83
  start(workflow: WorkflowClass, args: unknown[]): Promise<string>;
38
84
  signal(id: string, key: string, payload?: unknown): Promise<boolean>;
39
85
  cancel(id: string): Promise<boolean>;
40
86
  find(id: string): Promise<WorkflowStatus | null>;
87
+ items(id: string, key: string, options?: {
88
+ status?: "failed" | "skipped";
89
+ after?: number;
90
+ limit?: number;
91
+ }): Promise<EachProblem[]>;
41
92
  /** One pass of the workflow `id`, run by its tick job. */
42
93
  tick(id: string, job: Job): Promise<void>;
43
94
  /** The tick's last write: the pass's outcome, and letting go. */
@@ -1 +1 @@
1
- {"version":3,"file":"WorkflowRuntime.d.ts","sourceRoot":"","sources":["../../../../services/queue/workflow/WorkflowRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQpD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAYzB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAe;IAMd,OAAO,CAAC,QAAQ,CAAC,KAAK;IALlC,OAAO,CAAC,QAAQ,CAAqC;IACrD,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;gBAEtB,KAAK,EAAE,YAAY;IAEhD,mEAAmE;IACnE,IAAI,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,C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@@ -14,6 +14,7 @@
14
14
  * a workflow sleeps) is decided by the runtime, in the `decide` callback of
15
15
  * `update`, while the store holds the workflow exclusively.
16
16
  */
17
+ import type { StepRunStatus, WorkflowRunStatus } from "./wire";
17
18
  import type { EnqueueBatch } from "../QueueDriver";
18
19
  /** The registered name the internal tick job runs under. */
19
20
  export declare const WORKFLOW_TICK_JOB = "gemi.WorkflowTick";
@@ -22,21 +23,7 @@ export declare const WORKFLOW_TICK_JOB = "gemi.WorkflowTick";
22
23
  * as JSON, in bytes. Store an id for anything larger.
23
24
  */
24
25
  export declare const WORKFLOW_OUTPUT_LIMIT: number;
25
- /**
26
- * Where a workflow stands.
27
- *
28
- * - `running`: a tick is running it, or one is queued to.
29
- * - `sleeping`: waiting for a `step.sleep` or a step's retry backoff.
30
- * - `waiting`: waiting for a signal (`step.waitFor`) or a batch (`step.batch`).
31
- * - `cancelling`: `cancel` was accepted, and `onCancel` has not finished yet.
32
- * - `completed`, `failed`, `cancelled`: final.
33
- */
34
- export type WorkflowRunStatus = "running" | "sleeping" | "waiting" | "completed" | "failed" | "cancelling" | "cancelled";
35
- /**
36
- * Where one step stands. `signalled` is a signal that arrived before its
37
- * `step.waitFor`, kept until the workflow gets there.
38
- */
39
- export type StepRunStatus = "running" | "retrying" | "completed" | "failed" | "sleeping" | "waiting" | "signalled" | "timed_out" | "batching";
26
+ export type { StepRunStatus, WorkflowRunStatus } from "./wire";
40
27
  /** A workflow's row. Times are epoch milliseconds. */
41
28
  export type WorkflowRecord = {
42
29
  id: string;
@@ -81,6 +68,50 @@ export type StepRecord = {
81
68
  createdAt: number;
82
69
  updatedAt: number;
83
70
  };
71
+ /**
72
+ * Where one item of a `step.each` stands. Only items that are in flight or
73
+ * had a problem have a row: one that succeeded is deleted, so a long list
74
+ * keeps rows for its problems and its window, not for every item.
75
+ *
76
+ * - `running`: an attempt was started. Found at the start of a tick, it is an
77
+ * attempt whose process died, and the item runs again.
78
+ * - `retrying`: an attempt failed; the next one is due at `wakeAt`.
79
+ * - `failed`: out of attempts. `skipped`: the step function called `ctx.skip`.
80
+ */
81
+ export type ItemRunStatus = "running" | "retrying" | "failed" | "skipped";
82
+ /** An item's row, unique per workflow, step key and index. */
83
+ export type ItemRecord = {
84
+ workflowId: string;
85
+ /** The key of the `step.each` it belongs to. */
86
+ step: string;
87
+ /** Its index in the list, from 0. */
88
+ index: number;
89
+ /** The item key `key(input)` gave, once known; `null` before. */
90
+ key: string | null;
91
+ status: ItemRunStatus;
92
+ /** Attempts started, counting from 1. */
93
+ attempt: number;
94
+ /** The error's message, or the reason given to `ctx.skip`. */
95
+ error: string | null;
96
+ /** The `data` given to `ctx.skip`, as JSON. */
97
+ output: string | null;
98
+ /** When the next attempt of a `retrying` item is due. */
99
+ wakeAt: number | null;
100
+ startedAt: number | null;
101
+ finishedAt: number | null;
102
+ createdAt: number;
103
+ updatedAt: number;
104
+ };
105
+ /** The item rows a change writes, all of one `step.each`. */
106
+ export type ItemChange = {
107
+ step: string;
108
+ /** Rows that do not exist yet. */
109
+ insert?: ItemRecord[];
110
+ /** Rows that exist, replaced whole. */
111
+ update?: ItemRecord[];
112
+ /** Indexes whose rows are deleted. */
113
+ delete?: number[];
114
+ };
84
115
  /** A workflow and its steps, in the order the steps were first recorded. */
85
116
  export type WorkflowState = {
86
117
  workflow: WorkflowRecord;
@@ -102,6 +133,11 @@ export type WorkflowSnapshot = {
102
133
  step: StepRecord | null;
103
134
  /** Every step, when `allSteps` was asked for; otherwise empty. */
104
135
  steps: StepRecord[];
136
+ /**
137
+ * The `running` and `retrying` item rows of the step `items` names, by
138
+ * index; otherwise empty.
139
+ */
140
+ items: ItemRecord[];
105
141
  /** This process's clock, for the wake-up times the runtime computes. */
106
142
  now: number;
107
143
  };
@@ -112,6 +148,8 @@ export type WorkflowChange<T> = {
112
148
  workflow?: Partial<Pick<WorkflowRecord, "status" | "currentStep" | "progress" | "result" | "error" | "wakeAt">>;
113
149
  /** The step's new row: inserted, or replacing the one under its key. */
114
150
  step?: StepRecord;
151
+ /** Item rows of a `step.each` to insert, replace or delete. */
152
+ items?: ItemChange;
115
153
  /** A batch to dispatch, as `QueueDriver.enqueueBatch` would. */
116
154
  batch?: EnqueueBatch;
117
155
  /** Batches to cancel, as `QueueDriver.cancelBatch` would. */
@@ -174,10 +212,22 @@ export interface WorkflowStore {
174
212
  owner?: string;
175
213
  key?: string;
176
214
  allSteps?: boolean;
215
+ items?: string;
177
216
  }, decide: (snapshot: WorkflowSnapshot) => WorkflowChange<T>): Promise<T | undefined>;
217
+ /**
218
+ * The item rows of one `step.each` whose status is one of `statuses`, by
219
+ * index, from just after `after`, at most `limit`. A store that has it
220
+ * supports `step.each`: it also reads `items` in `update` and writes a
221
+ * change's `items`.
222
+ */
223
+ listItems?(workflowId: string, step: string, options: {
224
+ statuses: ItemRunStatus[];
225
+ after?: number;
226
+ limit: number;
227
+ }): Promise<ItemRecord[]>;
178
228
  /**
179
229
  * Deletes workflows that ended (completed, failed or cancelled) more than
180
- * `olderThanMs` ago, with their steps, and resolves to how many.
230
+ * `olderThanMs` ago, with their steps and items, and resolves to how many.
181
231
  */
182
232
  prune?(olderThanMs: number): Promise<number>;
183
233
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WorkflowStore.d.ts","sourceRoot":"","sources":["../../../../services/queue/workflow/WorkflowStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,4DAA4D;AAC5D,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAa,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,UAAU,GACV,SAAS,GACT,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,WAAW,CAAC;AAEhB;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,UAAU,GACV,WAAW,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C,EAAE,MAAM,CAAA;KAAE,EAC7E,MAAM,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,cAAc,CAAC,CAAC,CAAC,GACxD,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAE1B;;;;;OAKG;IACH,SAAS,CAAC,CACR,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GACpE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAEzB;;;OAGG;IACH,KAAK,CAAC,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Where a workflow stands.
3
+ *
4
+ * - `running`: a tick is running it, or one is queued to.
5
+ * - `sleeping`: waiting for a `step.sleep` or a step's retry backoff.
6
+ * - `waiting`: waiting for a signal (`step.waitFor`) or a batch (`step.batch`).
7
+ * - `cancelling`: `cancel` was accepted, and `onCancel` has not finished yet.
8
+ * - `completed`, `failed`, `cancelled`: final.
9
+ */
10
+ export type WorkflowRunStatus = "running" | "sleeping" | "waiting" | "completed" | "failed" | "cancelling" | "cancelled";
11
+ /**
12
+ * Where one step stands. `signalled` is a signal that arrived before its
13
+ * `step.waitFor`, kept until the workflow gets there. `iterating` is a
14
+ * `step.each` that has items left.
15
+ */
16
+ export type StepRunStatus = "running" | "retrying" | "completed" | "failed" | "sleeping" | "waiting" | "signalled" | "timed_out" | "batching" | "iterating";
17
+ /** How far a `step.each` is. */
18
+ export type EachProgress = {
19
+ total: number;
20
+ /** Items that ended: `succeeded + skipped + failed`. */
21
+ done: number;
22
+ succeeded: number;
23
+ skipped: number;
24
+ failed: number;
25
+ };
26
+ /** One step, as `Workflow.find` and the workflow's stream show it. Times are epoch milliseconds. */
27
+ export type WorkflowStepStatus = {
28
+ key: string;
29
+ status: StepRunStatus;
30
+ /** Attempts started; `step.run` only. */
31
+ attempt: number;
32
+ error: string | null;
33
+ /** The batch a `step.batch` dispatched. */
34
+ batchId: string | null;
35
+ /**
36
+ * 0 to 1: the batch's progress for a `step.batch`, or the share of items
37
+ * that have ended for a `step.each`.
38
+ */
39
+ progress?: number;
40
+ /** How far a `step.each` is. */
41
+ items?: EachProgress;
42
+ /** When a sleep ends, a wait times out, or a retry is due. */
43
+ wakeAt: number | null;
44
+ startedAt: number | null;
45
+ finishedAt: number | null;
46
+ };
47
+ /**
48
+ * What a workflow's channel publishes on every change, and what
49
+ * `useWorkflow` returns: its status without `args` and `result`, which can
50
+ * hold what a browser must not see.
51
+ */
52
+ export type WorkflowUpdate = {
53
+ id: string;
54
+ /** The workflow class's `static name`. */
55
+ name: string;
56
+ status: WorkflowRunStatus;
57
+ /** The key of the step it is on, or `null`. */
58
+ currentStep: string | null;
59
+ /** 0 to 1, as `step.progress` or a running `step.each` last set it; 1 once completed. */
60
+ progress: number;
61
+ /** Why it failed; for a cancelled one, why `onCancel` failed. */
62
+ error: string | null;
63
+ /** Every step recorded so far, in the order they were first reached. */
64
+ steps: WorkflowStepStatus[];
65
+ createdAt: number;
66
+ /** When it last changed: of two updates, the later one has the larger `updatedAt`. */
67
+ updatedAt: number;
68
+ };
69
+ /** Whether a workflow has ended: `completed`, `failed` or `cancelled`. */
70
+ export declare function workflowEnded(status: WorkflowRunStatus): boolean;
71
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../../services/queue/workflow/wire.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,UAAU,GACV,SAAS,GACT,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,WAAW,CAAC;AAEhB;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GAC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ClB,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAEhE"}
@@ -26,5 +26,7 @@ export declare function workflowContract(name: string, storage: () => Promise<{
26
26
  * needs to finish its transaction.
27
27
  */
28
28
  concurrentWorkers?: boolean;
29
+ /** How many items the "long list" `step.each` test works through. Default 2,000. */
30
+ largeCount?: number;
29
31
  }): void;
30
32
  //# sourceMappingURL=workflowContract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflowContract.d.ts","sourceRoot":"","sources":["../../../../services/queue/workflow/workflowContract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,OAAO,CAAC;IAAE,MAAM,IAAI,WAAW,CAAC;IAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,EAC3E,QAAQ,GAAE;IACR;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACC,QAogBhC"}
1
+ {"version":3,"file":"workflowContract.d.ts","sourceRoot":"","sources":["../../../../services/queue/workflow/workflowContract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOlD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,OAAO,CAAC;IAAE,MAAM,IAAI,WAAW,CAAC;IAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,EAC3E,QAAQ,GAAE;IACR;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,oFAAoF;IACpF,UAAU,CAAC,EAAE,MAAM,CAAC;CACS,QAk8BhC"}
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{Pe as Y}from"../chunk-sqqh78tf.js";import{al as M}from"../chunk-yxtfg4wy.js";import{hm as P,jm as R}from"../chunk-aes0ecnp.js";import"../chunk-sba3s380.js";import{Dm as Q,Em as U,Fm as V,Gm as W}from"../chunk-hmtn7996.js";import"../chunk-yedb5vvg.js";class S{static token;async boot(){}onShutdown(x){}static inject(){if(!this.token)throw Error(`Service [${this.name}] does not declare a \`static token\`, so the container has no key to resolve it by.`);try{return R(this)}catch(x){throw Error(`Could not inject [${this.name}]. Services are constructed when the kernel boots, so `+"inject() only works from code that runs after that \u2014 a constructor default or a method "+`body, never module top level. Check that [${this.name}] is listed in \`services\` on your Kernel.`,{cause:x})}}static with(x){let f=new this;for(let[C,g]of Object.entries(x))if(g!==void 0)f[C]=g;return f}}import{readdir as z}from"fs/promises";import{join as B,parse as j}from"path";var H=[".ts",".tsx",".js",".mjs",".jsx"];function J(x={}){let f={};for(let[C,g]of Object.entries(x))f[C]=q(g);return new P(f)}async function L(x,f=new P){let C=[];try{C=await z(x)}catch(D){return f}let g=C.filter((D)=>{let{ext:v,name:F}=j(D);return H.includes(v)&&!F.startsWith(".")}).sort();for(let D of g){let{name:v}=j(D),F=await import(B(x,D));f.set(v,q(F))}return f}function q(x){if(x&&typeof x==="object"&&"default"in x)return x.default;return x}export{M as withDefaults,Q as sourceFiles,W as projectRoot,L as loadConfigFrom,V as discoverClasses,J as createConfigRepository,Y as ServiceProvider,S as Service,P as Repository,U as DiscoveryError};
2
+ import{Qe as Y}from"../chunk-6my6c6b1.js";import{al as M}from"../chunk-yxtfg4wy.js";import{hm as P,jm as R}from"../chunk-aes0ecnp.js";import"../chunk-sba3s380.js";import{Dm as Q,Em as U,Fm as V,Gm as W}from"../chunk-hmtn7996.js";import"../chunk-yedb5vvg.js";class S{static token;async boot(){}onShutdown(x){}static inject(){if(!this.token)throw Error(`Service [${this.name}] does not declare a \`static token\`, so the container has no key to resolve it by.`);try{return R(this)}catch(x){throw Error(`Could not inject [${this.name}]. Services are constructed when the kernel boots, so `+"inject() only works from code that runs after that \u2014 a constructor default or a method "+`body, never module top level. Check that [${this.name}] is listed in \`services\` on your Kernel.`,{cause:x})}}static with(x){let f=new this;for(let[C,g]of Object.entries(x))if(g!==void 0)f[C]=g;return f}}import{readdir as z}from"fs/promises";import{join as B,parse as j}from"path";var H=[".ts",".tsx",".js",".mjs",".jsx"];function J(x={}){let f={};for(let[C,g]of Object.entries(x))f[C]=q(g);return new P(f)}async function L(x,f=new P){let C=[];try{C=await z(x)}catch(D){return f}let g=C.filter((D)=>{let{ext:v,name:F}=j(D);return H.includes(v)&&!F.startsWith(".")}).sort();for(let D of g){let{name:v}=j(D),F=await import(B(x,D));f.set(v,q(F))}return f}function q(x){if(x&&typeof x==="object"&&"default"in x)return x.default;return x}export{M as withDefaults,Q as sourceFiles,W as projectRoot,L as loadConfigFrom,V as discoverClasses,J as createConfigRepository,Y as ServiceProvider,S as Service,P as Repository,U as DiscoveryError};
3
3
 
4
- //# debugId=6359932777B8C99064756E2164756E21
4
+ //# debugId=325CF77C44A8E78464756E2164756E21
@@ -6,6 +6,6 @@
6
6
  "import { readdir } from \"node:fs/promises\";\nimport { join, parse } from \"node:path\";\n\nimport { Repository } from \"./Repository\";\n\nconst CONFIG_EXTENSIONS = [\".ts\", \".tsx\", \".js\", \".mjs\", \".jsx\"];\n\n// Builds a Repository from an already-imported map of config modules. The map\n// key becomes the top-level config key, so `{ mail: mailModule }` is readable\n// as `config.get(\"mail.driver\")`. Each entry may be either the module namespace\n// (its `default` export is unwrapped) or the config object itself.\nexport function createConfigRepository(\n modules: Record<string, any> = {},\n): Repository {\n const items: Record<string, any> = {};\n\n for (const [key, mod] of Object.entries(modules)) {\n items[key] = unwrap(mod);\n }\n\n return new Repository(items);\n}\n\n// Reads every config module in an app's `app/config` directory into a\n// Repository. The file's basename is the top-level key: `app/config/mail.ts`\n// populates `mail.*`. A missing directory yields an empty Repository so apps\n// that declare no config still boot.\nexport async function loadConfigFrom(\n directory: string,\n repository = new Repository(),\n): Promise<Repository> {\n let entries: string[] = [];\n\n try {\n entries = await readdir(directory);\n } catch (err) {\n return repository;\n }\n\n const files = entries\n .filter((entry) => {\n const { ext, name } = parse(entry);\n return CONFIG_EXTENSIONS.includes(ext) && !name.startsWith(\".\");\n })\n .sort();\n\n for (const file of files) {\n const { name } = parse(file);\n const mod = await import(join(directory, file));\n repository.set(name, unwrap(mod));\n }\n\n return repository;\n}\n\nfunction unwrap(mod: any) {\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return mod.default;\n }\n return mod;\n}\n"
7
7
  ],
8
8
  "mappings": ";2RAiCO,CAAe,JAAQ,EAOrB,OAMD,AAAI,EAAkB,EAmB5B,UAAU,CAAC,EAEkD,QAmBtD,OAAS,EAKX,CACH,GAAI,CAAC,KAAK,MACR,MAAU,MACR,YAAY,KAAK,0FACnB,EAGF,GAAI,CACF,OAAO,EAAI,IAAuB,EAClC,MAAO,EAAO,CACd,MAAU,MACR,qBAAqB,KAAK,6DACxB,+FACA,6CAA6C,KAAK,kDAEpD,CAAE,OAAM,CACV,SAoBG,KAAuB,CAAoB,EAA0B,CAC1E,IAAM,EAAW,IAAI,KACrB,QAAY,EAAK,KAAU,OAAO,QAAQ,CAAS,EACjD,GAAI,IAAU,OAAW,EAAS,GAAO,EAE3C,OAAO,EAEX,CCtIA,kBAAS,oBACT,eAAS,WAAM,aAIf,IAAM,EAAoB,CAAC,MAAO,OAAQ,MAAO,OAAQ,MAAM,EAMxD,SAAS,CAAsB,CACpC,EAA+B,CAAC,EACpB,CACZ,IAAM,EAA6B,CAAC,EAEpC,QAAY,EAAK,KAAQ,OAAO,QAAQ,CAAO,EAC7C,EAAM,GAAO,EAAO,CAAG,EAGzB,OAAO,IAAI,EAAW,CAAK,EAO7B,eAAsB,CAAc,CAClC,EACA,EAAa,IAAI,EACI,CACrB,IAAI,EAAoB,CAAC,EAEzB,GAAI,CACF,EAAU,MAAM,EAAQ,CAAS,EACjC,MAAO,EAAK,CACZ,OAAO,EAGT,IAAM,EAAQ,EACX,OAAO,CAAC,IAAU,CACjB,IAAQ,MAAK,QAAS,EAAM,CAAK,EACjC,OAAO,EAAkB,SAAS,CAAG,GAAK,CAAC,EAAK,WAAW,GAAG,EAC/D,EACA,KAAK,EAER,QAAW,KAAQ,EAAO,CACxB,IAAQ,QAAS,EAAM,CAAI,EACrB,EAAM,MAAa,SAAK,EAAW,CAAI,GAC7C,EAAW,IAAI,EAAM,EAAO,CAAG,CAAC,EAGlC,OAAO,EAGT,SAAS,CAAM,CAAC,EAAU,CACxB,GAAI,GAAO,OAAO,IAAQ,UAAY,YAAa,EACjD,OAAO,EAAI,QAEb,OAAO",
9
- "debugId": "6359932777B8C99064756E2164756E21",
9
+ "debugId": "325CF77C44A8E78464756E2164756E21",
10
10
  "names": []
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemi",
3
- "version": "0.217.0",
3
+ "version": "0.219.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Enes Tufekci <enes@gemijs.dev>",
@@ -1,19 +0,0 @@
1
- // @bun
2
- import{re as R}from"./chunk-7xe5vd4w.js";import{He as S,Me as E,ye as Q}from"./chunk-wkmd81k4.js";import{jm as K}from"./chunk-aes0ecnp.js";import{Em as A,Fm as $,Gm as D}from"./chunk-hmtn7996.js";class j extends Error{code;constructor(q,z=1){super(q);this.code=z;this.name="CommandFailed"}}class J{static commandName="unset";static description="";static args=[];static options=[];run(q){}}function p(q){return q}function C(){return{commands:[],commandsDir:"app/commands"}}var I=Symbol.for("gemi.console.builder");function k(q){if(q.trim()==="")throw Error("A command name cannot be empty.");if(/[{}]/.test(q)||/\s/.test(q))throw Error(`Invalid command name ${JSON.stringify(q)}. gemi does not parse a signature string; the name is the whole of it. Declare arguments with .arg() and flags with .option():
3
-
4
- defineCommand("mail:send")
5
- .arg("user", { required: true })
6
- .option("queue", { type: "boolean" })
7
- .handle(async ({ args, options }) => { ... })`)}function c(q){k(q);let z=[],F=[],P="",X={[I]:q,describe(G){return P=G,X},arg(G,H={}){if(H.required&&H.default!==void 0)throw Error(`Argument "${G}" of command "${q}" is both required and has a default. An argument that is supplied when absent cannot also be `+"absent \u2014 drop one.");if(H.variadic&&H.default!==void 0)throw Error(`Argument "${G}" of command "${q}" is variadic and has a default. A variadic argument collects the remaining values and is an empty list when there are none, so the default could never `+"apply \u2014 drop it, or drop `variadic`.");let V=z.find((O)=>O.variadic);if(V)throw Error(`Argument "${G}" of command "${q}" is declared after the variadic argument "${V.name}", which collects everything that follows, so "${G}" could never receive a value. A variadic argument must be declared last.`);if(z.some((O)=>O.name===G))throw Error(`Command "${q}" declares the argument "${G}" twice.`);return z.push({...H,name:G}),X},option(G,H){if(F.some((Y)=>Y.name===G))throw Error(`Command "${q}" declares the option "${G}" twice.`);let V="alias"in H?H.alias:void 0,O=V===void 0?void 0:F.find((Y)=>("alias"in Y)&&Y.alias===V);if(O)throw Error(`Options "${O.name}" and "${G}" of command "${q}" both use the alias "-${V}".`);return F.push({...H,name:G}),X},handle(G){let H=q,V=P,O=class extends J{static commandName=H;static description=V;static args=[...z];static options=[...F];run(Y){return G(Y)}};return delete X[I],Object.defineProperty(O,"name",{value:H,configurable:!0}),O}};return X}function L(q){return typeof q==="object"&&q!==null&&typeof q[I]==="string"}function o(q){return q}function T(){return{jobs:[],jobsDir:"app/cron"}}function i(q){return q}function B(){return{listeners:[],listenersDir:"app/listeners"}}class U{static name="unset";static event;queued=!1;maxAttempts=3;backoff=0;worker=!1}class W{static name="unset";run(q,...z){throw Error(`The workflow ${this.constructor.name} has no run method.`)}onCancel(q,...z){return}static start(...q){return K(S).workflows.start(this,q)}static signal(q,z,F){return K(S).workflows.signal(q,z,F)}static find(q){return K(S).workflows.find(q)}static cancel(q){return K(S).workflows.cancel(q)}}import{existsSync as M}from"fs";import{dirname as x,isAbsolute as y,join as N}from"path";function Z(q){return y(q)?q:N(D(),q)}function _(q,z,F){if(M(q)||M(x(q)))return;console.warn(`No ${z} were discovered: neither ${q} nor the directory above it exists, so this process cannot see the application's source. If this is a deploy that ships only the build output, list the classes explicitly in app/config/${F}.ts so they travel with it.`)}async function Sq(q=Q().jobsDir){let z=Z(q);_(z,"queue jobs","queue");let F=await $(z,E);return w(F),F}async function Zq(q=Q().workflowsDir){let z=Z(q);_(z,"workflows","queue");let F=await $(z,W);for(let P of F){if(Object.getOwnPropertyDescriptor(P,"name")?.writable)continue;console.warn(`Workflow ${P.name} does not declare \`static name\`. A workflow is stored under its name, and a production build renames the class. Add: static name = "${P.name}";`)}return F}function w(q){for(let z of q){if(Object.getOwnPropertyDescriptor(z,"name")?.writable)continue;console.warn(`Queued job ${z.name} does not declare \`static name\`, so it is registered under its class name. A production build minifies the class that dispatches it and renames it, while discovery reads this `+"file from source and does not \u2014 so the dispatch would be dropped in "+`production and nowhere else. Add: static name = "${z.name}";`)}}async function _q(q=T().jobsDir){let z=Z(q);return _(z,"cron jobs","schedule"),await $(z,R)}async function Iq(q=C().commandsDir){let z=Z(q);_(z,"commands","command");let F=[],P=await $(z,J,[],(X,G)=>{if(L(X))F.push(G)});return b(F),P}function b(q){if(q.length===0)return;let z=q.length===1?`${q[0]} exports a command builder that never called \`.handle()\``:`${q.length} files export a command builder that never called \`.handle()\`:
8
- ${q.join(`
9
- `)}`;throw new A(`${z}, so there is no command to run. \`.handle()\` is what turns `+`the chain into a command \u2014 finish it:
10
-
11
- `+` export default defineCommand("my-command")
12
- .handle(async ({ line }) => { line("hello") })`)}async function Uq(q=B().listenersDir){let z=Z(q);_(z,"event listeners","events");let F=await $(z,U);return f(F),v(F),u(F),F}function f(q){let z=q.filter((F)=>!F.event);if(z.length===0)return;throw new A(`${z.map((F)=>F.name).join(", ")} declare no \`static event\`, so there is no event name to register them under and their \`handle\` would never run. Every listener binds to exactly one event:
13
-
14
- static event = UserRegistered;
15
-
16
- If this is an abstract base its subclasses extend, move it out of the `+"listeners directory \u2014 the walk excludes gemi's `Listener` and "+"nothing else, so a base sitting beside its subclasses is registered and run like one of them.")}function v(q){for(let z of q){if(Object.getOwnPropertyDescriptor(z,"name")?.writable)continue;console.warn(`Event listener ${z.name} does not declare \`static name\`, so it is registered under its class name, which a production build renames. Nothing reads that name across a build boundary while the `+"listener is sync, which is why this is a warning \u2014 but adding "+`\`queued = true\` to it is refused at boot for the same reason, because the queue's key is that string. Add: static name = "${z.name}";`)}}function u(q){let z=new Set;for(let{event:F}of q){if(z.has(F))continue;if(Object.getOwnPropertyDescriptor(F,"name")?.writable)continue;z.add(F),console.warn(`Event ${F.name} does not declare \`static name\`, so it is dispatched under its class name. A production build minifies the code that dispatches it and renames the class, while discovery reads `+"the listener's copy from source and does not \u2014 so the dispatch would "+`reach no listener in production and nowhere else. Add: static name = "${F.name}";`)}}
17
- export{j as be,J as ce,p as de,C as ee,c as fe,o as ge,T as he,i as ie,B as je,U as ke,W as le,Sq as me,Zq as ne,_q as oe,Iq as pe,Uq as qe};
18
-
19
- //# debugId=DFC91F7D3EAB10BE64756E2164756E21
@@ -1,5 +0,0 @@
1
- // @bun
2
- import{Oe as o}from"./chunk-7t13vyzg.js";import{Pe as i}from"./chunk-sqqh78tf.js";import{al as t}from"./chunk-yxtfg4wy.js";import{fm as r}from"./chunk-qstjm3cb.js";class n extends i{register(){this.app.singleton(r,()=>new r(t(o(),this.app.config.get("translation",{}))))}}
3
- export{n as pb};
4
-
5
- //# debugId=1BE1A2F1C892D74064756E2164756E21