@odunlamizo/node-river 1.0.4 → 1.0.6

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.
@@ -0,0 +1,238 @@
1
+ import { Buffer } from 'buffer';
2
+
3
+ /**
4
+ * Represents the lifecycle state of a job, such as available, running, completed, or scheduled.
5
+ */
6
+ declare enum JobState {
7
+ /**
8
+ * Immediately eligible to be worked
9
+ */
10
+ Available = "available",
11
+ /**
12
+ * Manually cancelled by user; cleaned after a period
13
+ */
14
+ Cancelled = "cancelled",
15
+ /**
16
+ * Successfully run to completion; cleaned after a period
17
+ */
18
+ Completed = "completed",
19
+ /**
20
+ * Errored too many times; needs manual intervention
21
+ */
22
+ Discarded = "discarded",
23
+ /**
24
+ * Waiting for external action; not worked or deleted until moved
25
+ */
26
+ Pending = "pending",
27
+ /**
28
+ * Errored but will be retried; becomes Available when ready
29
+ */
30
+ Retryable = "retryable",
31
+ /**
32
+ * Actively running; may need rescue if stuck
33
+ */
34
+ Running = "running",
35
+ /**
36
+ * Scheduled for future execution; becomes Available when due
37
+ */
38
+ Scheduled = "scheduled"
39
+ }
40
+
41
+ /**
42
+ * Represents a failed job attempt, including error details and stack trace.
43
+ */
44
+ interface AttemptError {
45
+ /**
46
+ * Time the error occurred
47
+ */
48
+ at: string;
49
+ /**
50
+ * Attempt number when the error occurred
51
+ */
52
+ attempt: number;
53
+ /**
54
+ * Stringified error or panic value
55
+ */
56
+ error: string;
57
+ /**
58
+ * Stack trace from a job that panicked
59
+ */
60
+ trace: string;
61
+ }
62
+
63
+ /**
64
+ * Options for enforcing uniqueness constraints on jobs.
65
+ */
66
+ interface UniqueOpts {
67
+ /**
68
+ * Enforce uniqueness based on job arguments.
69
+ * True for all args, or specify keys to include.
70
+ */
71
+ byArgs?: true | string[];
72
+ /**
73
+ * Enforce uniqueness within a time period (seconds).
74
+ */
75
+ byPeriod?: number;
76
+ /**
77
+ * Enforce uniqueness within each queue.
78
+ */
79
+ byQueue?: true;
80
+ /**
81
+ * Enforce uniqueness across specified job states.
82
+ */
83
+ byState?: string[];
84
+ /**
85
+ * Exclude job kind from uniqueness computation.
86
+ */
87
+ excludeKind?: true;
88
+ }
89
+
90
+ /**
91
+ * Options for job insertion, such as queue, priority, scheduling, and metadata.
92
+ */
93
+ interface InsertOpts {
94
+ /**
95
+ * List of tags for grouping and categorizing jobs
96
+ */
97
+ tags?: string[];
98
+ /**
99
+ * Name of the job queue to insert into
100
+ */
101
+ queue?: string;
102
+ /**
103
+ * Job priority (1 = highest, 4 = lowest)
104
+ */
105
+ priority?: number;
106
+ /**
107
+ * Arbitrary metadata for the job
108
+ */
109
+ metadata?: Record<string, unknown>;
110
+ /**
111
+ * Maximum number of attempts before discarding the job
112
+ */
113
+ maxAttempts?: number;
114
+ /**
115
+ * Schedule the job for future execution
116
+ */
117
+ scheduledAt?: Date;
118
+ /**
119
+ * Options relating to job uniqueness.
120
+ * If not set, the job is never treated as unique.
121
+ */
122
+ uniqueOpts?: UniqueOpts;
123
+ }
124
+
125
+ /**
126
+ * Interface for job argument objects passed to job handlers.
127
+ *
128
+ * Every job must specify a `kind` to identify its type, and can include
129
+ * any number of additional properties relevant to the job's execution.
130
+ */
131
+ interface JobArgs {
132
+ /**
133
+ * Identifies the job type for routing and processing.
134
+ */
135
+ kind: string;
136
+ /**
137
+ * Arbitrary job parameters, allowing for flexible job payloads.
138
+ * All values should be JSON-compatible.
139
+ */
140
+ [key: string]: unknown;
141
+ }
142
+
143
+ /**
144
+ * Represents a job persisted in the database, including its state, metadata, and scheduling information.
145
+ */
146
+ interface Job<T extends JobArgs = JobArgs> {
147
+ /**
148
+ * Unique job ID, generated by the database
149
+ */
150
+ id: number;
151
+ /**
152
+ * Current state of the job (e.g., available, completed)
153
+ */
154
+ state: JobState;
155
+ /**
156
+ * Current attempt number, incremented each time the job is worked
157
+ */
158
+ attempt: number;
159
+ /**
160
+ * Maximum number of attempts before the job stops retrying
161
+ */
162
+ maxAttempts: number;
163
+ /**
164
+ * Last time the job was worked, null if never
165
+ */
166
+ attemptedAt: Date | null;
167
+ /**
168
+ * When the job record was created
169
+ */
170
+ createdAt: Date;
171
+ /**
172
+ * When the job was finalized (completed or errored for last time), null if not finalized
173
+ */
174
+ finalizedAt: Date | null;
175
+ /**
176
+ * When the job is scheduled to become available
177
+ */
178
+ scheduledAt: Date;
179
+ /**
180
+ * Job priority (1 = highest, 4 = lowest)
181
+ */
182
+ priority: number;
183
+ /**
184
+ * Job arguments, decoded from JSON
185
+ */
186
+ args: T;
187
+ /**
188
+ * Worker IDs that have worked this job, null if never
189
+ */
190
+ attemptedBy: string[] | null;
191
+ /**
192
+ * Errors for each attempt, ordered earliest to latest, null if none
193
+ */
194
+ errors: AttemptError[] | null;
195
+ /**
196
+ * Job type identifier, set at insertion
197
+ */
198
+ kind: string;
199
+ /**
200
+ * Arbitrary metadata associated with the job
201
+ */
202
+ metadata: Record<string, unknown>;
203
+ /**
204
+ * Name of the queue where the job will be worked
205
+ */
206
+ queue: string;
207
+ /**
208
+ * List of tags for grouping and categorizing jobs
209
+ */
210
+ tags: string[];
211
+ /**
212
+ * Unique key for job within its kind, used for unique insertions, null if not set
213
+ */
214
+ uniqueKey: Buffer | null;
215
+ /**
216
+ * States required for uniqueness, null if not set
217
+ */
218
+ uniqueStates: JobState[] | null;
219
+ }
220
+
221
+ /**
222
+ * Result of a job insertion operation.
223
+ *
224
+ * - If a unique job already exists, `job` is the existing job and `skipped` is true.
225
+ * - If the job was inserted, `job` is the new job and `skipped` is false.
226
+ */
227
+ interface InsertResult<T extends JobArgs = JobArgs> {
228
+ /**
229
+ * The inserted job, or the existing job if insertion was skipped due to uniqueness.
230
+ */
231
+ job: Job<T>;
232
+ /**
233
+ * True if insertion was skipped because a unique job already exists.
234
+ */
235
+ skipped: boolean;
236
+ }
237
+
238
+ export { type AttemptError as A, type InsertOpts as I, type JobArgs as J, type UniqueOpts as U, type InsertResult as a, type Job as b, JobState as c };
package/dist/types.cjs ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ // src/types/enums.ts
4
+ var JobState = /* @__PURE__ */ ((JobState2) => {
5
+ JobState2["Available"] = "available";
6
+ JobState2["Cancelled"] = "cancelled";
7
+ JobState2["Completed"] = "completed";
8
+ JobState2["Discarded"] = "discarded";
9
+ JobState2["Pending"] = "pending";
10
+ JobState2["Retryable"] = "retryable";
11
+ JobState2["Running"] = "running";
12
+ JobState2["Scheduled"] = "scheduled";
13
+ return JobState2;
14
+ })(JobState || {});
15
+
16
+ exports.JobState = JobState;
17
+ //# sourceMappingURL=types.cjs.map
18
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/enums.ts"],"names":["JobState"],"mappings":";;;AAGO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAIL,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAKV,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAKV,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAvCF,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA","file":"types.cjs","sourcesContent":["/**\n * Represents the lifecycle state of a job, such as available, running, completed, or scheduled.\n */\nexport enum JobState {\n /**\n * Immediately eligible to be worked\n */\n Available = 'available',\n\n /**\n * Manually cancelled by user; cleaned after a period\n */\n Cancelled = 'cancelled',\n\n /**\n * Successfully run to completion; cleaned after a period\n */\n Completed = 'completed',\n\n /**\n * Errored too many times; needs manual intervention\n */\n Discarded = 'discarded',\n\n /**\n * Waiting for external action; not worked or deleted until moved\n */\n Pending = 'pending',\n\n /**\n * Errored but will be retried; becomes Available when ready\n */\n Retryable = 'retryable',\n\n /**\n * Actively running; may need rescue if stuck\n */\n Running = 'running',\n\n /**\n * Scheduled for future execution; becomes Available when due\n */\n Scheduled = 'scheduled',\n}\n"]}
@@ -0,0 +1,18 @@
1
+ export { A as AttemptError, I as InsertOpts, a as InsertResult, b as Job, J as JobArgs, c as JobState, U as UniqueOpts } from './insert-result-Bf0bAFvJ.cjs';
2
+ import 'buffer';
3
+
4
+ /**
5
+ * Configuration options for the RiverQueue client.
6
+ */
7
+ interface ClientConfiguration {
8
+ /**
9
+ * Default queue name for job insertion
10
+ */
11
+ defaultQueue?: string;
12
+ /**
13
+ * Maximum number of attempts for jobs
14
+ */
15
+ maxAttempts?: number;
16
+ }
17
+
18
+ export type { ClientConfiguration };
@@ -0,0 +1,18 @@
1
+ export { A as AttemptError, I as InsertOpts, a as InsertResult, b as Job, J as JobArgs, c as JobState, U as UniqueOpts } from './insert-result-Bf0bAFvJ.js';
2
+ import 'buffer';
3
+
4
+ /**
5
+ * Configuration options for the RiverQueue client.
6
+ */
7
+ interface ClientConfiguration {
8
+ /**
9
+ * Default queue name for job insertion
10
+ */
11
+ defaultQueue?: string;
12
+ /**
13
+ * Maximum number of attempts for jobs
14
+ */
15
+ maxAttempts?: number;
16
+ }
17
+
18
+ export type { ClientConfiguration };
package/dist/types.js ADDED
@@ -0,0 +1,16 @@
1
+ // src/types/enums.ts
2
+ var JobState = /* @__PURE__ */ ((JobState2) => {
3
+ JobState2["Available"] = "available";
4
+ JobState2["Cancelled"] = "cancelled";
5
+ JobState2["Completed"] = "completed";
6
+ JobState2["Discarded"] = "discarded";
7
+ JobState2["Pending"] = "pending";
8
+ JobState2["Retryable"] = "retryable";
9
+ JobState2["Running"] = "running";
10
+ JobState2["Scheduled"] = "scheduled";
11
+ return JobState2;
12
+ })(JobState || {});
13
+
14
+ export { JobState };
15
+ //# sourceMappingURL=types.js.map
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/enums.ts"],"names":["JobState"],"mappings":";AAGO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAIL,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAKV,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAKZ,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAKV,EAAAA,UAAA,WAAA,CAAA,GAAY,WAAA;AAvCF,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA","file":"types.js","sourcesContent":["/**\n * Represents the lifecycle state of a job, such as available, running, completed, or scheduled.\n */\nexport enum JobState {\n /**\n * Immediately eligible to be worked\n */\n Available = 'available',\n\n /**\n * Manually cancelled by user; cleaned after a period\n */\n Cancelled = 'cancelled',\n\n /**\n * Successfully run to completion; cleaned after a period\n */\n Completed = 'completed',\n\n /**\n * Errored too many times; needs manual intervention\n */\n Discarded = 'discarded',\n\n /**\n * Waiting for external action; not worked or deleted until moved\n */\n Pending = 'pending',\n\n /**\n * Errored but will be retried; becomes Available when ready\n */\n Retryable = 'retryable',\n\n /**\n * Actively running; may need rescue if stuck\n */\n Running = 'running',\n\n /**\n * Scheduled for future execution; becomes Available when due\n */\n Scheduled = 'scheduled',\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odunlamizo/node-river",
3
- "version": "1.0.4",
4
- "description": "Node.js library to support riverqueue integration.",
3
+ "version": "1.0.6",
4
+ "description": "Node.js library to support River integration.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -9,9 +9,26 @@
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js"
17
+ },
18
+ "./drivers/pg": {
19
+ "types": "./dist/drivers/pg/index.d.ts",
20
+ "import": "./dist/drivers/pg/index.mjs",
21
+ "require": "./dist/drivers/pg/index.js"
22
+ },
23
+ "./types": {
24
+ "types": "./dist/types.d.ts",
25
+ "import": "./dist/types.mjs",
26
+ "require": "./dist/types.js"
27
+ }
28
+ },
12
29
  "scripts": {
13
- "build": "tsup src/index.ts --dts --format cjs,esm",
14
- "dev": "tsup src/index.ts --watch --dts --format cjs,esm",
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
15
32
  "test": "jest --runInBand",
16
33
  "lint": "eslint . --ext .ts,.js --ignore-pattern eslint.config.js",
17
34
  "format": "prettier --write .",