@shivaedev/effect-pg-boss 0.3.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 - 2026-10-12
4
+
5
+ ### Changed
6
+
7
+ - Explain the jobs boundary in a package north star, agent guidance, usage guide and roadmap, and publish the guide and `docs/` with the package.
8
+ - Build package JavaScript, declarations and source maps with TypeScript 7.
9
+
10
+ ### Fixed
11
+
12
+ - Preserve the literal identifier of each `makePgBoss(identifier)` in its service and Layer types, so a Layer for another jobs definition leaves the required service unprovided at compile time. This is breaking only for code that names the shared `PgBossIdentifier` type; use the definition's literal identifier instead.
13
+
3
14
  ## 0.3.0 - 2026-10-04
4
15
 
5
16
  ### Changed
package/README.md CHANGED
@@ -1,119 +1,235 @@
1
- # `@shivaedev/effect-pg-boss`
1
+ # @shivaedev/effect-pg-boss
2
2
 
3
- Effect-native queues, workers, schedules, and lifecycle management for
4
- pg-boss.
3
+ Run PostgreSQL jobs through the same Effect services as the rest of your application. A queue has one payload Schema for enqueueing and handling, and an Effect Layer owns the pg-boss client, workers and schedules.
5
4
 
6
- This package currently targets exact early-access versions of Effect v4 and
7
- pg-boss. It is built for ShivaeDev applications and may change without a
8
- deprecation period.
5
+ ## Why you want this
9
6
 
10
- ## Install
7
+ A background worker lives outside the request that queued it. Without a shared boundary, the producer writes one payload shape, the worker assumes another, and every worker rebuilds its dependencies and shutdown plumbing. This package puts those decisions in one place:
11
8
 
12
- ```sh
13
- pnpm add @shivaedev/effect-pg-boss effect pg-boss
9
+ ```ts
10
+ import { defineQueue } from "@shivaedev/effect-pg-boss/definition.ts";
11
+ import { Effect, Schema } from "effect";
12
+ import { Mail } from "./services.ts";
13
+
14
+ const SendEmail = defineQueue({
15
+ name: "send-email",
16
+ schema: Schema.Struct({ userId: Schema.NumberFromString }),
17
+ });
18
+
19
+ const emailWorker = SendEmail.handle(({ userId }) =>
20
+ Effect.flatMap(Mail, (mail) => mail.send(userId)),
21
+ );
14
22
  ```
15
23
 
16
- ## Define jobs
24
+ `Mail` is the application's Effect service, defined in the guide below. The worker receives a number even though the durable payload stores a string. The same Schema encodes the producer's payload and decodes the worker's input; malformed stored data fails before the handler runs. Provide the worker's services when the jobs Layer starts, and the handler uses that captured context when pg-boss calls it later.
25
+
26
+ ## Using it
27
+
28
+ ### How to think about it
29
+
30
+ A **queue definition** names a pg-boss queue and the Schema of its payload. Application code uses the Schema's decoded type; pg-boss receives its encoded type. Both must be objects. Defining a queue describes the contract; `queue.handle(handler)` pairs it with the Effect that performs the work.
31
+
32
+ A **schedule definition** describes a queue with a cron trigger. `schedule.run(effect)` pairs it with an Effect that needs no payload. Queue workers and scheduled workers are **registrations**: the values you put in the jobs Layer's `jobs` list.
33
+
34
+ The application creates one jobs service with `makePgBoss(identifier)`. Its Layer starts a client, registers the job list and captures the services those workers need. The Layer's scope owns its client reference and releases it when the scope ends; the final reference closes the client. Callers use the jobs service to enqueue a decoded payload or read queue health.
17
35
 
18
- A queue pairs its durable wire schema with its Effect handler. The handler only
19
- receives decoded data; malformed stored data fails before domain code runs.
36
+ Use a distinct literal identifier for each jobs service. The service and its Layer keep that identifier in their types, so providing a Layer for a different identifier leaves the required jobs service unprovided at compile time.
37
+
38
+ The work separates naturally: declare the application services once, define a queue and its worker for each feature, provide the complete registration list at the runtime boundary, and enqueue from ordinary application Effects.
39
+
40
+ ### Once per application: the jobs service
41
+
42
+ Define the application's jobs service and worker dependencies in `services.ts`:
20
43
 
21
44
  ```ts
22
- import { defineQueue } from "@shivaedev/effect-pg-boss/definition.ts"
23
- import { Effect, Schema } from "effect"
24
-
25
- export const EmailQueue = defineQueue({
26
- name: "email",
27
- schema: Schema.Struct({
28
- userId: Schema.String,
29
- attempt: Schema.NumberFromString,
30
- }),
31
- queue: {
32
- retryLimit: 5,
33
- retryBackoff: true,
34
- },
35
- })
45
+ import { makePgBoss } from "@shivaedev/effect-pg-boss/service.ts";
46
+ import { Context, Effect, Layer } from "effect";
36
47
 
37
- const emailWorker = EmailQueue.handle(({ userId, attempt }) =>
38
- Effect.gen(function* () {
39
- const email = yield* Email
40
- yield* email.send(userId, attempt)
41
- }),
42
- )
48
+ export const Jobs = makePgBoss("@app/Jobs");
49
+
50
+ export class Mail extends Context.Service<Mail, {
51
+ readonly send: (userId: number) => Effect.Effect<void>;
52
+ readonly removeExpired: Effect.Effect<void>;
53
+ }>()("@app/Mail") {}
54
+
55
+ export const MailLive = Layer.succeed(Mail, {
56
+ send: (userId) => Effect.log({ event: "send_email", userId }),
57
+ removeExpired: Effect.log({ event: "remove_expired_mail" }),
58
+ });
43
59
  ```
44
60
 
45
- Queue payloads are encoded through the same Schema when enqueued, so transforms
46
- such as `NumberFromString` have one contract in both directions.
61
+ `Jobs` is the service that callers yield. `Mail` is a separate domain service that workers use. The example implementation logs calls so the wiring is complete; an application supplies its own implementation of those methods. The jobs package does not need a provider-specific interface.
62
+
63
+ ### Once per feature: the payload and handler
47
64
 
48
- Schedules are queues with a cron trigger and an Effect that takes no payload:
65
+ Define the feature's registrations in `jobs.ts`:
49
66
 
50
67
  ```ts
51
- import { defineSchedule } from "@shivaedev/effect-pg-boss/definition.ts"
68
+ import { defineQueue, defineSchedule } from "@shivaedev/effect-pg-boss/definition.ts";
69
+ import { Effect, Schema } from "effect";
70
+ import { Mail } from "./services.ts";
52
71
 
53
- const Cleanup = defineSchedule({
54
- name: "cleanup",
55
- cron: "17 3 * * *",
56
- })
72
+ export const SendEmail = defineQueue({
73
+ name: "send-email",
74
+ schema: Schema.Struct({ userId: Schema.NumberFromString }),
75
+ queue: { retryLimit: 5 },
76
+ });
57
77
 
58
- const cleanupWorker = Cleanup.run(
78
+ export const emailWorker = SendEmail.handle(({ userId }, job) =>
59
79
  Effect.gen(function* () {
60
- const sessions = yield* Sessions
61
- yield* sessions.removeExpired()
80
+ const mail = yield* Mail;
81
+ yield* mail.send(userId);
82
+ yield* Effect.log({ jobId: job.id });
62
83
  }),
63
- )
84
+ );
85
+
86
+ export const Cleanup = defineSchedule({
87
+ name: "cleanup-mail",
88
+ cron: "17 3 * * *",
89
+ });
90
+
91
+ export const cleanupWorker = Cleanup.run(
92
+ Effect.flatMap(Mail, (mail) => mail.removeExpired),
93
+ );
64
94
  ```
65
95
 
66
- Schedules default to UTC. Every job defaults to three retries with exponential
67
- backoff and a `<name>-dlq` dead-letter queue. Ordinary pg-boss queue, worker,
68
- and schedule options can override those defaults.
96
+ The queue takes `{ userId: number }` in application code and stores `{ userId: string }`. Its handler receives the decoded number and a job context, including the job's `id`. Keep the queue definition available to producers; the runtime registers the worker created by `handle`.
97
+
98
+ The schedule runs a payload-free Effect. This schedule registers its cron expression with `tz: "UTC"`. The package creates a `<name>-dlq` dead-letter queue for both kinds of worker and supplies `retryLimit: 3` and `retryBackoff: true` by default. The email queue above overrides the retry limit to five. These are pg-boss registration settings; pg-boss runs the retry and scheduling engine.
69
99
 
70
- ## Provide the service
100
+ The Layer requires the workers' Effect services. Leaving `Mail` unprovided leaves that requirement in the resulting Effect's type. A primitive Schema such as `Schema.String` is rejected as a queue definition because the durable contract must be an object.
71
101
 
72
- Create one service identifier, then provide its scoped Layer. The Layer starts
73
- pg-boss, registers workers and schedules, captures their Effect services, and
74
- stops pg-boss when its scope closes.
102
+ ### Once per runtime: provide the workers
103
+
104
+ Build the jobs Layer in `runtime.ts`:
75
105
 
76
106
  ```ts
77
- import { makePgBoss } from "@shivaedev/effect-pg-boss/service.ts"
107
+ import { Layer } from "effect";
108
+ import { cleanupWorker, emailWorker } from "./jobs.ts";
109
+ import { Jobs, MailLive } from "./services.ts";
110
+
111
+ export const jobsLayer = (databaseUrl: string) =>
112
+ Jobs.layer({
113
+ connectionString: databaseUrl,
114
+ schema: "app_jobs",
115
+ jobs: [emailWorker, cleanupWorker],
116
+ }).pipe(Layer.provide(MailLive));
117
+ ```
118
+
119
+ The constructor options belong to pg-boss. `jobs` is the complete list of registrations for this Layer. The Layer captures `MailLive` for both the queue handler and the scheduled Effect. A startup or registration failure fails Layer acquisition with `PgBossError` and releases its acquired client reference. A shared client stays running while another scope still owns a reference.
78
120
 
79
- export const Jobs = makePgBoss("@app/Jobs")
121
+ Keep the Layer in the application's worker runtime scope. A short scope is useful for an acquisition or health check; a worker process needs its scope to remain open while it handles jobs.
80
122
 
81
- export const JobsLive = Jobs.layer({
82
- connectionString: databaseUrl,
83
- schema: "app_jobs",
84
- jobs: [emailWorker, cleanupWorker],
85
- clientCacheKey: isDevelopment ? "app-jobs" : undefined,
86
- })
123
+ ```ts
124
+ import { Effect } from "effect";
125
+ import { jobsLayer } from "./runtime.ts";
126
+ import { Jobs } from "./services.ts";
127
+
128
+ const inspectJobs = (databaseUrl: string) =>
129
+ Effect.scoped(
130
+ Effect.gen(function* () {
131
+ const jobs = yield* Jobs;
132
+ return yield* jobs.health;
133
+ }).pipe(Effect.provide(jobsLayer(databaseUrl))),
134
+ );
87
135
  ```
88
136
 
89
- `clientCacheKey` reuses and reference-counts one started client across Layer
90
- builds that share the key, such as development module reloads. The package does
91
- not inspect `NODE_ENV`; without a key every build starts its own client.
92
- Applications decide which key and registrations are passed to the Layer, so
93
- environment rules such as development caching and production-only schedules
94
- remain application policy.
137
+ This Effect starts the jobs Layer, reads health and closes the scope. The client stops when that scope closes.
95
138
 
96
- An `onError` Effect can route pg-boss background errors through application
97
- logging or telemetry. Without one, errors use Effect logging.
139
+ ### In application code: enqueue
98
140
 
99
- ## Enqueue and inspect health
141
+ ```ts
142
+ import { Effect } from "effect";
143
+ import { SendEmail } from "./jobs.ts";
144
+ import { Jobs } from "./services.ts";
145
+
146
+ export const enqueueEmail = (userId: number) =>
147
+ Effect.gen(function* () {
148
+ const jobs = yield* Jobs;
149
+ return yield* jobs.enqueue(SendEmail, { userId });
150
+ });
151
+ ```
152
+
153
+ Provide `Jobs` through the application's existing runtime. `enqueue` takes the decoded payload, so passing a string `userId` is a type error. It encodes the number to a string before calling pg-boss. The result type is `Option.Option<string>`: a job identifier becomes `Some`, and a `null` send result becomes `None`.
154
+
155
+ `PgBossPayloadError` names a payload boundary failure; malformed durable input is rejected before the worker's domain code runs. The PostgreSQL test also checks that invalid data sent directly to pg-boss reaches the dead-letter queue without reaching the handler.
156
+
157
+ ### Read health
100
158
 
101
159
  ```ts
102
- const program = Effect.gen(function* () {
103
- const jobs = yield* Jobs
160
+ import { Effect } from "effect";
161
+ import { Jobs } from "./services.ts";
162
+
163
+ export const readJobCounts = Effect.gen(function* () {
164
+ const jobs = yield* Jobs;
165
+ const health = yield* jobs.health;
166
+ return {
167
+ active: health.activeTotal,
168
+ deadLettered: health.deadLetteredTotal,
169
+ failed: health.failedTotal,
170
+ queued: health.queuedTotal,
171
+ ready: health.readyTotal,
172
+ };
173
+ });
174
+ ```
175
+
176
+ `health` exposes pg-boss queue counts as data. Its total fields include the registered queue's active, failed, queued and ready counts, plus the dead-letter queue's queued count. Decide in the application which values affect an HTTP health response or an alert.
177
+
178
+ ### Share a client between Layer builds
179
+
180
+ ```ts
181
+ import { Layer } from "effect";
182
+ import { cleanupWorker, emailWorker } from "./jobs.ts";
183
+ import { Jobs, MailLive } from "./services.ts";
184
+
185
+ const sharedJobsLayer = (databaseUrl: string) =>
186
+ Jobs.layer({
187
+ connectionString: databaseUrl,
188
+ schema: "app_jobs",
189
+ clientCacheKey: "app-jobs",
190
+ jobs: [emailWorker, cleanupWorker],
191
+ }).pipe(Layer.provide(MailLive));
192
+ ```
193
+
194
+ Overlapping Layer builds with the same `clientCacheKey` share one started client. The later build replaces the registered worker, and the final scope release stops the shared client. A later build after that release starts a new client. Without a key, each build creates its own client. The application chooses whether to pass a key.
195
+
196
+ ### API
104
197
 
105
- const id = yield* jobs.enqueue(EmailQueue, {
106
- userId: "user-1",
107
- attempt: 1,
108
- })
198
+ Import the module that defines the name; the package has no root entry.
109
199
 
110
- const health = yield* jobs.health
111
- return { id, health }
112
- })
200
+ | Module | Public names |
201
+ | --- | --- |
202
+ | `@shivaedev/effect-pg-boss/definition.ts` | `defineQueue`, `defineSchedule`, `jobContext`; `DefineQueueOptions`, `DefineScheduleOptions`, `JobContext`, `JobPayloadSchema`, `JobRegistration`, `QueueDefinition`, `QueueWorker`, `RegistrationRequirements`, `ScheduleDefinition`, `ScheduledWorker` |
203
+ | `@shivaedev/effect-pg-boss/service.ts` | `makePgBoss`; `PgBossDefinition`, `PgBossLayerOptions`, `PgBossService` |
204
+ | `@shivaedev/effect-pg-boss/health.ts` | `deadLetterQueueName`; `JobsHealth`, `QueueHealth` |
205
+ | `@shivaedev/effect-pg-boss/error.ts` | `PgBossError`, `PgBossPayloadError`, `toPgBossError`; `PgBossOperation` |
206
+ | `@shivaedev/effect-pg-boss/client.ts` | `defaultClientFactory`; `PgBossClient`, `PgBossClientFactory` |
207
+
208
+ The definition options keep the pg-boss names: `queue` uses `QueueOptions` except `deadLetter`, `worker` uses `WorkOptions`, and a schedule's `schedule` uses `ScheduleOptions`. A queue also requires `name` and `schema`; a schedule requires `name` and `cron`.
209
+
210
+ The application's service has two operations:
211
+
212
+ - `enqueue(queue, payload, options?)`: an Effect returning `Option.Option<string>`, with `PgBossError | PgBossPayloadError` in its error type. Its options use pg-boss `SendOptions`.
213
+ - `health`: an Effect returning `JobsHealth`, with `PgBossError` in its error type.
214
+
215
+ `Jobs.layer(options)` accepts pg-boss `ConstructorOptions` plus `jobs`, optional `clientCacheKey`, optional `clientFactory`, optional `onError` and optional `stop`. The factory type accepts constructor options and returns `PgBossClient`; `onError` has the type `(error: Error) => Effect.Effect<unknown, never, R>`; `stop` uses pg-boss `StopOptions`.
216
+
217
+ `onError` handles pg-boss client `error` events using the services captured by the Layer. The Layer's requirement type includes the workers' services, the payload Schemas' `DecodingServices` and the callback's services. `enqueue` includes the payload Schema's `EncodingServices` in its requirement type.
218
+
219
+ `JobContext` has `id`, `name`, `signal`, `expireInSeconds` and `heartbeatSeconds`. `QueueHealth` has `name`, `activeCount`, `deadLetteredCount`, `failedCount`, `queuedCount` and `readyCount`. `JobsHealth` has `jobs` and the corresponding `activeTotal`, `deadLetteredTotal`, `failedTotal`, `queuedTotal` and `readyTotal` fields.
220
+
221
+ `PgBossError` has `operation`, optional `queue` and a `Redacted` `original`. `PgBossPayloadError` has `direction`, `queue` and a `Redacted` `original`. Those fields distinguish the pg-boss operation from the payload boundary.
222
+
223
+ ### Install, setup and limits
224
+
225
+ ```sh
226
+ pnpm add @shivaedev/effect-pg-boss effect@4.0.0-rc.112 pg-boss@12.23.1
113
227
  ```
114
228
 
115
- `enqueue` returns `Option<string>` because pg-boss can decline a job under a
116
- queue policy. Its payload stays fully typed from the queue Schema. `health`
117
- reports queued, ready, active, failed, and dead-letter counts for every
118
- registered job without choosing an HTTP response shape or application health
119
- policy.
229
+ The package requires Node.js 24 or later and PostgreSQL. `effect` and `pg-boss` are peers; use versions that satisfy the package's published peer ranges.
230
+
231
+ Provide the database connection and job registrations at the application runtime boundary. Application services own the domain work and provider calls; pg-boss owns queue execution. Treat enqueueing and an application database transaction as separate operations, and choose any required transaction or outbox policy in the application.
232
+
233
+ For package development, the real PostgreSQL test uses `PLATFORM_EFFECT_PG_BOSS_TEST_DATABASE_URL` and skips when the variable is absent. A skipped test does not establish durable queue behavior. Fake-client tests cover registration and lifecycle calls; they do not establish real cron execution, retry timing or deployment behavior. The package is built for ShivaeDev applications and may change without a deprecation period.
234
+
235
+ The [north star](./docs/north-star.md) explains the design trade-offs; the [roadmap](./docs/roadmap.md) owns package work and open choices.
@@ -1 +1 @@
1
- {"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/E,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,GAAG;IACnD,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[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,mBAAmB,cAAe,MAAM,KAAG,MAA4B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAuB,KAAK,UAAU,EAAoB,MAAM,YAAY,CAAC;AAEpF,eAAO,MAAM,SAAS,GAAI,QAAQ,YAAY,EAAE,OAAO,SAAS,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,WAAW,EAAE,WAAW,CA4BlI,CAAC"}
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAuB,KAAK,UAAU,EAAoB,MAAM,YAAY,CAAC;AAEpF,eAAO,MAAM,SAAS,WAAY,YAAY,SAAS,SAAS,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,WAAW,EAAE,WAAW,CA4BlI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/internal/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAwB,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAwB/F,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;CACzC;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AAiBD,eAAO,MAAM,aAAa,GAAI,SAAS,oBAAoB,KAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,WAAW,EAAE,WAAW,CA6CxH,CAAC;AAEJ,eAAO,MAAM,aAAa,GAAI,UAAU,cAAc,EAAE,cAAc,WAAW,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAoB7C,CAAC"}
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/internal/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAwB,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA2B/F,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;CACzC;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AAiBD,eAAO,MAAM,aAAa,YAAa,oBAAoB,KAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,WAAW,EAAE,WAAW,CA6CxH,CAAC;AAEJ,eAAO,MAAM,aAAa,aAAc,cAAc,gBAAgB,WAAW,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAoB7C,CAAC"}
@@ -5,15 +5,17 @@ const CacheKey = Symbol.for("@shivaedev/effect-pg-boss/client-cache");
5
5
  const sharedCache = Reflect.get(globalThis, CacheKey);
6
6
  const clientCache = sharedCache instanceof Map ? sharedCache : new Map();
7
7
  Reflect.set(globalThis, CacheKey, clientCache);
8
- const isCachedClient = (value) => typeof value === "object"
9
- && value !== null
10
- && Reflect.get(value, "client") instanceof Promise
11
- && typeof Reflect.get(value, "references") === "number";
12
- const cachedClient = (key) => {
8
+ function isCachedClient(value) {
9
+ return (typeof value === "object"
10
+ && value !== null
11
+ && Reflect.get(value, "client") instanceof Promise
12
+ && typeof Reflect.get(value, "references") === "number");
13
+ }
14
+ function cachedClient(key) {
13
15
  const entry = clientCache.get(key);
14
16
  return isCachedClient(entry) ? entry : undefined;
15
- };
16
- const startClient = (options) => {
17
+ }
18
+ function startClient(options) {
17
19
  const client = (options.clientFactory ?? defaultClientFactory)(options.constructor);
18
20
  return client.start().then(() => client, async (error) => {
19
21
  try {
@@ -24,7 +26,7 @@ const startClient = (options) => {
24
26
  }
25
27
  throw error;
26
28
  });
27
- };
29
+ }
28
30
  export const acquireClient = (options) => Effect.tryPromise({
29
31
  catch: (error) => toPgBossError("start", error),
30
32
  try: async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/internal/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,oBAAoB,EAA+C,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAO1C,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACtE,MAAM,WAAW,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC/D,MAAM,WAAW,GAAkC,WAAW,YAAY,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,EAA4B,CAAC;AAClI,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAE/C,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE,CAChE,OAAO,KAAK,KAAK,QAAQ;OACtB,KAAK,KAAK,IAAI;OACd,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,OAAO;OAC/C,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,QAAQ,CAAC;AAEzD,MAAM,YAAY,GAAG,CAAC,GAAoB,EAA4B,EAAE;IACvE,MAA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ACD,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;CACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,eAAe,EAAsD,MAAM,gBAAgB,CAAC;AAc1G,eAAO,MAAM,gBAAgB,GAAI,cAAc,eAAe,KAAG,MAQhE,CAAC;AAqEF,eAAO,MAAM,iBAAiB,GAAI,eAAe,SAAS,eAAe,EAAE,KAAG,SAAS,MAAM,EAM5F,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAC7B,QAAQ,YAAY,EACpB,eAAe,SAAS,eAAe,EAAE,EACzC,SAAS,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAC3B,gBAAgB,OAAO,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,WAAW,CAcnD,CAAC"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,eAAe,EAAsD,MAAM,gBAAgB,CAAC;AAoB1G,eAAO,MAAM,gBAAgB,iBAAkB,eAAe,KAAG,MAQhE,CAAC;AAsEF,eAAO,MAAM,iBAAiB,kBAAmB,SAAS,eAAe,EAAE,KAAG,SAAS,MAAM,EAM5F,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,UACrB,YAAY,iBACL,SAAS,eAAe,EAAE,WAChC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,kBACX,OAAO,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,WAAW,CAcnD,CAAC"}
@@ -2,13 +2,19 @@ import { Effect, Redacted, Schema } from "effect";
2
2
  import { jobContext } from "#definition.ts";
3
3
  import { PgBossPayloadError, toPgBossError } from "#error.ts";
4
4
  import { deadLetterQueueName } from "#health.ts";
5
- const queueOptions = (options) => ({
6
- retryBackoff: true,
7
- retryLimit: 3,
8
- ...options,
9
- });
10
- const isQueueWorker = (registration) => registration._tag === "QueueWorker";
11
- const isScheduledWorker = (registration) => registration._tag === "ScheduledWorker";
5
+ function queueOptions(options) {
6
+ return {
7
+ retryBackoff: true,
8
+ retryLimit: 3,
9
+ ...options,
10
+ };
11
+ }
12
+ function isQueueWorker(registration) {
13
+ return registration._tag === "QueueWorker";
14
+ }
15
+ function isScheduledWorker(registration) {
16
+ return registration._tag === "ScheduledWorker";
17
+ }
12
18
  export const registrationName = (registration) => {
13
19
  if (isQueueWorker(registration)) {
14
20
  return registration.queue.name;
@@ -21,12 +27,14 @@ export const registrationName = (registration) => {
21
27
  function workerContext(context) {
22
28
  return context;
23
29
  }
24
- const runQueueWorker = (worker, job, context) => Effect.runPromise(Schema.decodeUnknownEffect(worker.queue.schema)(job.data).pipe(Effect.mapError((error) => new PgBossPayloadError({
25
- direction: "decode",
26
- original: Redacted.make(error),
27
- queue: worker.queue.name,
28
- })), Effect.flatMap((payload) => worker.handler(payload, jobContext(job))), Effect.provide(context)), { signal: job.signal });
29
- const registerQueue = async (client, worker, context, replaceWorker) => {
30
+ function runQueueWorker(worker, job, context) {
31
+ return Effect.runPromise(Schema.decodeUnknownEffect(worker.queue.schema)(job.data).pipe(Effect.mapError((error) => new PgBossPayloadError({
32
+ direction: "decode",
33
+ original: Redacted.make(error),
34
+ queue: worker.queue.name,
35
+ })), Effect.flatMap((payload) => worker.handler(payload, jobContext(job))), Effect.provide(context)), { signal: job.signal });
36
+ }
37
+ async function registerQueue(client, worker, context, replaceWorker) {
30
38
  const name = worker.queue.name;
31
39
  const deadLetter = deadLetterQueueName(name);
32
40
  if (replaceWorker) {
@@ -42,8 +50,8 @@ const registerQueue = async (client, worker, context, replaceWorker) => {
42
50
  await runQueueWorker(worker, job, context);
43
51
  }
44
52
  });
45
- };
46
- const registerSchedule = async (client, worker, context, replaceWorker) => {
53
+ }
54
+ async function registerSchedule(client, worker, context, replaceWorker) {
47
55
  const { schedule } = worker;
48
56
  const deadLetter = deadLetterQueueName(schedule.name);
49
57
  if (replaceWorker) {
@@ -62,7 +70,7 @@ const registerSchedule = async (client, worker, context, replaceWorker) => {
62
70
  }
63
71
  });
64
72
  await client.schedule(schedule.name, schedule.cron, null, schedule.scheduleOptions);
65
- };
73
+ }
66
74
  export const registrationNames = (registrations) => {
67
75
  const names = registrations.map(registrationName);
68
76
  if (new Set(names).size !== names.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhE,OAAO,EAAwB,UAAU,EAA0C,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,YAAY,GAAG,CA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,QAAQ,EAAE,cAAc,CAAC,CAAC;YACrE,CAAC;iBAAM,IAAI,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC5C,MAAM,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;YACxE,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,eAAO,MAAM,WAAW,GAAI,QAAQ,YAAY,EAAE,OAAO,SAAS,MAAM,EAAE,KAAG,aA4B3E,CAAC"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,eAAO,MAAM,WAAW,WAAY,YAAY,SAAS,SAAS,MAAM,EAAE,KAAG,aA4B3E,CAAC"}
package/dist/service.d.ts CHANGED
@@ -5,22 +5,18 @@ import type { JobPayloadSchema, JobRegistration, QueueDefinition, RegistrationRe
5
5
  import type { PgBossError, PgBossPayloadError } from "./error.ts";
6
6
  import type { JobsHealth } from "./health.ts";
7
7
  export interface PgBossService {
8
- readonly enqueue: <const Name extends string, const Payload extends JobPayloadSchema>(queue: QueueDefinition<Name, Payload>, payload: Schema.Schema.Type<Payload>, options?: SendOptions) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, Payload["EncodingServices"]>;
8
+ readonly enqueue: <const TName extends string, const TPayload extends JobPayloadSchema>(queue: QueueDefinition<TName, TPayload>, payload: Schema.Schema.Type<TPayload>, options?: SendOptions) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, TPayload["EncodingServices"]>;
9
9
  readonly health: Effect.Effect<JobsHealth, PgBossError>;
10
10
  }
11
- interface PgBossIdentifier {
12
- readonly _pgBossIdentifier: unique symbol;
13
- }
14
- export type PgBossLayerOptions<Registrations extends readonly JobRegistration[], ErrorRequirements> = ConstructorOptions & {
11
+ export type PgBossLayerOptions<TRegistrations extends readonly JobRegistration[], TErrorRequirements> = ConstructorOptions & {
15
12
  readonly clientFactory?: PgBossClientFactory;
16
13
  readonly clientCacheKey?: string | symbol | undefined;
17
- readonly jobs: Registrations;
18
- readonly onError?: (error: Error) => Effect.Effect<unknown, never, ErrorRequirements>;
14
+ readonly jobs: TRegistrations;
15
+ readonly onError?: (error: Error) => Effect.Effect<unknown, never, TErrorRequirements>;
19
16
  readonly stop?: StopOptions;
20
17
  };
21
- export interface PgBossDefinition extends Context.Service<PgBossIdentifier, PgBossService> {
22
- readonly layer: <const Registrations extends readonly JobRegistration[], ErrorRequirements = never>(options: PgBossLayerOptions<Registrations, ErrorRequirements>) => Layer.Layer<PgBossIdentifier, PgBossError, RegistrationRequirements<Registrations> | ErrorRequirements>;
18
+ export interface PgBossDefinition<TIdentifier extends string = string> extends Context.Service<TIdentifier, PgBossService> {
19
+ readonly layer: <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(options: PgBossLayerOptions<TRegistrations, TErrorRequirements>) => Layer.Layer<TIdentifier, PgBossError, RegistrationRequirements<TRegistrations> | TErrorRequirements>;
23
20
  }
24
- export declare const makePgBoss: (identifier: string) => PgBossDefinition;
25
- export {};
21
+ export declare const makePgBoss: <const TIdentifier extends string>(identifier: TIdentifier) => PgBossDefinition<TIdentifier>;
26
22
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,K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,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,EAAE,wBAAwB,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC,CAAC;CAC1G;AAMD,eAAO,MAAM,UAAU,GAAI,KAAK,CAAC,WAAW,SAAS,MAAM,cAAc,WAAW,KAAG,gBAAgB,CAAC,WAAW,CA6ClH,CAAC"}
package/dist/service.js CHANGED
@@ -2,7 +2,9 @@ import { Context, Effect, Layer } from "effect";
2
2
  import { acquireClient, releaseClient } from "#internal/lifecycle.ts";
3
3
  import { registerJobs, registrationName } from "#internal/register.ts";
4
4
  import { makeService } from "#internal/service.ts";
5
- const logClientError = (error) => Effect.logError({ event: "pg_boss_error", message: error.message });
5
+ function logClientError(error) {
6
+ return Effect.logError({ event: "pg_boss_error", message: error.message });
7
+ }
6
8
  export const makePgBoss = (identifier) => {
7
9
  const Service = Context.Service(identifier);
8
10
  const layer = (options) => {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAA4B,MAAM,QAAQ,CAAC;AAG1E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAiCnD,MAAM,cAAc,GAAG,CAAC,KAAY,EAAuB,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AAElI,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAoB,EAAE;IAClE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAkC,UAAU,CAAC,CAAC;IAE7E,MAAM,KAAK,GAAG,CACb,OAA6D,EAC6C,E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,EAAE,IAAI,CAAC,CAAC;YACtC,CAAC,CAAC,CACF,CAAC;QACH,CAAC,CAAC,EACF,CAAC,QAAQ,EAAE,EAAE;YACZ,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC9D,OAAO,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC,CACD,CAAC;QAEF,OAAO,KAAK,CAAC,MAAM,CAClB,OAAO,EACP,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAC1E,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ # North star
2
+
3
+ ## The problem
4
+
5
+ A durable job crosses two boundaries at once. Data leaves the producer's process and is read later by a worker; execution leaves the request's Effect context and is called later by pg-boss. When applications bridge those boundaries by hand, they repeat payload validation, dependency capture, queue registration and shutdown logic. A producer can drift from its worker's payload shape, a worker can rebuild services differently from the rest of the application, and a client can outlive the scope that should own it.
6
+
7
+ The package exists to make that boundary one reusable path. pg-boss remains the PostgreSQL queue engine. Effect remains the application's language for services, errors and resources. The adapter should join those pieces without making the application learn another execution model.
8
+
9
+ ## The ideal
10
+
11
+ A feature declares one object Schema for a queue, then attaches an ordinary Effect handler. The producer uses its decoded type; the durable boundary uses its encoded type; the handler receives decoded data. Domain code never has to guess what an old or malformed stored payload means.
12
+
13
+ A scheduled feature declares a name and cron expression, then attaches a payload-free Effect. Queue workers and scheduled workers become one list of registrations at the application's runtime boundary. The application's jobs Layer supplies the workers' services and owns the client that pg-boss calls through.
14
+
15
+ An application that needs only queueing should not import a repository framework, transport or UI package. A worker that needs application services should declare them through ordinary Effect requirements. The jobs adapter should preserve those requirements rather than hiding them in a global runtime or making each callback rebuild its dependencies.
16
+
17
+ ## What good looks like
18
+
19
+ - The payload contract is authored once, including transformations between application and durable representations.
20
+ - Invalid stored data is rejected before the worker's domain handler executes.
21
+ - Worker services are supplied where the jobs Layer is built, and their requirements remain visible to TypeScript.
22
+ - The client starts under an Effect scope. Startup failure, registration failure and scope release have a clear resource owner.
23
+ - Client reuse is requested with a key. Applications choose the environments and registrations that should share a client.
24
+ - pg-boss options remain pg-boss options. The package removes repeated boundary plumbing, not the engine's vocabulary.
25
+ - Operational observations are data, such as queue counts; an application decides what those observations mean for its health endpoint and alerts.
26
+ - Documentation distinguishes a fake client's observed calls from durable behavior demonstrated against PostgreSQL.
27
+
28
+ ## Trade-offs
29
+
30
+ **The durable contract wins over permissive input.** A queue Schema must describe object data on both sides. A malformed payload should not become a partially trusted value in domain code merely to keep a worker running.
31
+
32
+ **Explicit dependencies win over callback convenience.** The jobs Layer requires the services its handlers use. Adding a hidden runtime or service locator would make a worker shorter while moving its real dependencies out of the type system.
33
+
34
+ **Resource ownership wins over reuse.** Sharing a client can avoid duplicate starts across Layer builds, but a cache key is an application choice. It must not become a reason to ignore cleanup or silently infer environment policy.
35
+
36
+ **A thin boundary wins over orchestration features.** pg-boss already owns queue execution and scheduling. A new helper earns its place by removing repeated application code at the Effect boundary, with tests for the semantics it preserves.
37
+
38
+ **Proven behavior wins over a broader pitch.** Passing `retryBackoff: true` proves registration supplied that option. It does not prove retry timing. A fake client cannot establish a PostgreSQL delivery guarantee, and a PostgreSQL library test cannot establish application adoption or deployment behavior.
39
+
40
+ ## What it deliberately leaves out
41
+
42
+ - A replacement for pg-boss storage, cron interpretation, queue policy or retry execution.
43
+ - Domain workers, authorization rules, external-provider interfaces and application logging or health policy.
44
+ - Another general service declaration system; native Context and Layer stay available, and general declaration ergonomics belong to `effect-service`.
45
+ - Application repositories or migration ownership; those belong to `effect-sql`.
46
+ - An implicit link between enqueueing and an application's database transaction. Transaction and outbox policy remain application decisions; after-commit changes have their own path through `effect-changes`.
47
+ - A promise of exactly-once domain side effects or provider idempotency. Those need application-specific decisions and evidence.
48
+ - Browser, device or offline synchronization behavior. A PostgreSQL queue boundary cannot establish those product contracts.
@@ -0,0 +1,26 @@
1
+ # Roadmap
2
+
3
+ This file owns the package's implementation inventory and open API choices. The [framework roadmap](https://github.com/ShivaeDev/platform/blob/main/docs/framework/roadmap.md#next-application-and-deployment-acceptance) owns jobs integration with application services and external providers, including deployment and device validation.
4
+
5
+ ## Built
6
+
7
+ - [x] `makePgBoss` retains its literal service identity in `PgBossDefinition` and its Layer type, so a different jobs Layer does not satisfy the required service. [Compiler evidence](https://github.com/ShivaeDev/platform/blob/main/packages/effect-pg-boss/src/service.typecheck.test.ts).
8
+ - [x] Object payload Schema definitions, decoded enqueue types and queue workers. Type tests reject primitive schemas, missing fields and encoded values passed as decoded payloads.
9
+ - [x] Encoding at enqueue and decoding before the handler. The PostgreSQL test round-trips a transformed payload and checks that malformed stored data reaches the dead-letter queue without calling the domain handler.
10
+ - [x] Queue and schedule registration, with dead-letter queues, default retry settings and UTC schedule registration. Fake-client tests verify the supplied settings and a retry-limit override.
11
+ - [x] Worker and scheduled Effect service capture. Runtime and packed-consumer type tests preserve handler requirements.
12
+ - [x] Scoped startup and shutdown, including cleanup when startup or registration fails.
13
+ - [x] Explicit keyed client reuse and unkeyed per-build acquisition. Lifecycle tests cover two builds sharing one client and replacing the registered worker.
14
+ - [x] Queue health totals for active, failed, queued, ready and dead-lettered counts, verified with a populated fake queue.
15
+ - [x] Public defining-module imports and an installed-package type fixture.
16
+
17
+ ## Next
18
+
19
+ No further package API expansion is selected. Let the framework's jobs integration work identify the next package change, and preserve the existing payload and lifecycle contracts while it does. That integration's status stays in the framework roadmap.
20
+
21
+ ## Open questions
22
+
23
+ - Which application boundary should choose how a database write becomes a durable job: an explicit after-commit action, an outbox, or another demonstrated approach? The enqueue API is independent of application SQL; no transaction coupling is selected.
24
+ - Should a shared client key be checked against constructor settings and registration changes? The lifecycle fixture uses the same Layer twice; it does not settle incompatible configurations under one key.
25
+ - Which public hooks need dedicated regression coverage before the guide makes stronger claims? Error-event reporting, cancellation through a job's AbortSignal, a declined send result, multi-queue health and actual cron/retry execution are implemented boundaries or engine behaviors without focused evidence here.
26
+ - Should the package grow only when an application's integration needs a helper, or is a wider jobs API intended? The package has no in-repo application consumer to settle that question.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/effect-pg-boss",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Effect-native jobs and lifecycle management for pg-boss",
5
5
  "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/effect-pg-boss#readme",
6
6
  "bugs": {
@@ -15,7 +15,7 @@
15
15
  "sideEffects": false,
16
16
  "type": "module",
17
17
  "imports": {
18
- "#test/*": "./test/*",
18
+ "#test/*": "./src/test-support/*",
19
19
  "#*.ts": {
20
20
  "source": "./src/*.ts",
21
21
  "types": "./dist/*.d.ts",
@@ -35,21 +35,25 @@
35
35
  "files": [
36
36
  "dist",
37
37
  "src",
38
+ "!src/**/*.test.ts",
39
+ "!src/**/*.spec.ts",
40
+ "!src/**/test-support",
41
+ "docs",
38
42
  "CHANGELOG.md",
39
43
  "README.md"
40
44
  ],
41
45
  "devDependencies": {
42
- "@shivaedev/quality": "0.9.0",
43
- "@types/node": "24.10.1",
46
+ "@shivaedev/quality": "0.19.0",
47
+ "@types/node": "24.19.1",
44
48
  "@typescript/native": "npm:typescript@7.0.2",
45
49
  "effect": "4.0.0-rc.112",
46
- "pg-boss": "12.23.1",
50
+ "pg-boss": "12.36.0",
47
51
  "typescript": "npm:@typescript/typescript6@6.0.2",
48
- "vitest": "4.1.9"
52
+ "vitest": "4.1.11"
49
53
  },
50
54
  "peerDependencies": {
51
55
  "effect": "4.0.0-rc.112",
52
- "pg-boss": "12.23.1"
56
+ "pg-boss": "12.36.0"
53
57
  },
54
58
  "engines": {
55
59
  "node": ">=24"
@@ -59,7 +63,7 @@
59
63
  "provenance": true
60
64
  },
61
65
  "scripts": {
62
- "build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && tsc6 --project tsconfig.build.json",
66
+ "build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && tsc --project tsconfig.build.json",
63
67
  "ready": "pnpm typecheck && pnpm test && pnpm build",
64
68
  "test": "vitest run",
65
69
  "typecheck": "tsc --noEmit"
@@ -13,16 +13,19 @@ const sharedCache: unknown = Reflect.get(globalThis, CacheKey);
13
13
  const clientCache: Map<string | symbol, unknown> = sharedCache instanceof Map ? sharedCache : new Map<string | symbol, unknown>();
14
14
  Reflect.set(globalThis, CacheKey, clientCache);
15
15
 
16
- const isCachedClient = (value: unknown): value is CachedClient =>
17
- typeof value === "object"
18
- && value !== null
19
- && Reflect.get(value, "client") instanceof Promise
20
- && typeof Reflect.get(value, "references") === "number";
16
+ function isCachedClient(value: unknown): value is CachedClient {
17
+ return (
18
+ typeof value === "object"
19
+ && value !== null
20
+ && Reflect.get(value, "client") instanceof Promise
21
+ && typeof Reflect.get(value, "references") === "number"
22
+ );
23
+ }
21
24
 
22
- const cachedClient = (key: string | symbol): CachedClient | undefined => {
25
+ function cachedClient(key: string | symbol): CachedClient | undefined {
23
26
  const entry = clientCache.get(key);
24
27
  return isCachedClient(entry) ? entry : undefined;
25
- };
28
+ }
26
29
 
27
30
  export interface AcquireClientOptions {
28
31
  readonly clientCacheKey?: string | symbol | undefined;
@@ -36,7 +39,7 @@ export interface AcquiredClient {
36
39
  readonly reused: boolean;
37
40
  }
38
41
 
39
- const startClient = (options: AcquireClientOptions): Promise<PgBossClient> => {
42
+ function startClient(options: AcquireClientOptions): Promise<PgBossClient> {
40
43
  const client = (options.clientFactory ?? defaultClientFactory)(options.constructor);
41
44
  return client.start().then(
42
45
  () => client,
@@ -49,7 +52,7 @@ const startClient = (options: AcquireClientOptions): Promise<PgBossClient> => {
49
52
  throw error;
50
53
  },
51
54
  );
52
- };
55
+ }
53
56
 
54
57
  export const acquireClient = (options: AcquireClientOptions): Effect.Effect<AcquiredClient, import("#error.ts").PgBossError> =>
55
58
  Effect.tryPromise({
@@ -5,15 +5,21 @@ import { type JobRegistration, jobContext, type QueueWorker, type ScheduledWorke
5
5
  import { PgBossPayloadError, toPgBossError } from "#error.ts";
6
6
  import { deadLetterQueueName } from "#health.ts";
7
7
 
8
- const queueOptions = (options: Readonly<Record<string, unknown>>) => ({
9
- retryBackoff: true,
10
- retryLimit: 3,
11
- ...options,
12
- });
8
+ function queueOptions(options: Readonly<Record<string, unknown>>) {
9
+ return {
10
+ retryBackoff: true,
11
+ retryLimit: 3,
12
+ ...options,
13
+ };
14
+ }
13
15
 
14
- const isQueueWorker = (registration: JobRegistration): registration is QueueWorker => registration._tag === "QueueWorker";
16
+ function isQueueWorker(registration: JobRegistration): registration is QueueWorker {
17
+ return registration._tag === "QueueWorker";
18
+ }
15
19
 
16
- const isScheduledWorker = (registration: JobRegistration): registration is ScheduledWorker => registration._tag === "ScheduledWorker";
20
+ function isScheduledWorker(registration: JobRegistration): registration is ScheduledWorker {
21
+ return registration._tag === "ScheduledWorker";
22
+ }
17
23
 
18
24
  export const registrationName = (registration: JobRegistration): string => {
19
25
  if (isQueueWorker(registration)) {
@@ -31,8 +37,8 @@ function workerContext(context: unknown): unknown {
31
37
  return context;
32
38
  }
33
39
 
34
- const runQueueWorker = (worker: QueueWorker, job: Job<unknown>, context: Context.Context<unknown>): Promise<unknown> =>
35
- Effect.runPromise(
40
+ function runQueueWorker(worker: QueueWorker, job: Job<unknown>, context: Context.Context<unknown>): Promise<unknown> {
41
+ return Effect.runPromise(
36
42
  Schema.decodeUnknownEffect(worker.queue.schema)(job.data).pipe(
37
43
  Effect.mapError(
38
44
  (error) =>
@@ -47,8 +53,9 @@ const runQueueWorker = (worker: QueueWorker, job: Job<unknown>, context: Context
47
53
  ),
48
54
  { signal: job.signal },
49
55
  );
56
+ }
50
57
 
51
- const registerQueue = async (client: PgBossClient, worker: QueueWorker, context: Context.Context<unknown>, replaceWorker: boolean): Promise<void> => {
58
+ async function registerQueue(client: PgBossClient, worker: QueueWorker, context: Context.Context<unknown>, replaceWorker: boolean): Promise<void> {
52
59
  const name = worker.queue.name;
53
60
  const deadLetter = deadLetterQueueName(name);
54
61
  if (replaceWorker) {
@@ -64,14 +71,14 @@ const registerQueue = async (client: PgBossClient, worker: QueueWorker, context:
64
71
  await runQueueWorker(worker, job, context);
65
72
  }
66
73
  });
67
- };
74
+ }
68
75
 
69
- const registerSchedule = async (
76
+ async function registerSchedule(
70
77
  client: PgBossClient,
71
78
  worker: ScheduledWorker,
72
79
  context: Context.Context<unknown>,
73
80
  replaceWorker: boolean,
74
- ): Promise<void> => {
81
+ ): Promise<void> {
75
82
  const { schedule } = worker;
76
83
  const deadLetter = deadLetterQueueName(schedule.name);
77
84
  if (replaceWorker) {
@@ -90,7 +97,7 @@ const registerSchedule = async (
90
97
  }
91
98
  });
92
99
  await client.schedule(schedule.name, schedule.cron, null, schedule.scheduleOptions);
93
- };
100
+ }
94
101
 
95
102
  export const registrationNames = (registrations: readonly JobRegistration[]): readonly string[] => {
96
103
  const names = registrations.map(registrationName);
package/src/service.ts CHANGED
@@ -9,42 +9,40 @@ import type { PgBossError, PgBossPayloadError } from "./error.ts";
9
9
  import type { JobsHealth } from "./health.ts";
10
10
 
11
11
  export interface PgBossService {
12
- readonly enqueue: <const Name extends string, const Payload extends JobPayloadSchema>(
13
- queue: QueueDefinition<Name, Payload>,
14
- payload: Schema.Schema.Type<Payload>,
12
+ readonly enqueue: <const TName extends string, const TPayload extends JobPayloadSchema>(
13
+ queue: QueueDefinition<TName, TPayload>,
14
+ payload: Schema.Schema.Type<TPayload>,
15
15
  options?: SendOptions,
16
- ) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, Payload["EncodingServices"]>;
16
+ ) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, TPayload["EncodingServices"]>;
17
17
  readonly health: Effect.Effect<JobsHealth, PgBossError>;
18
18
  }
19
19
 
20
- interface PgBossIdentifier {
21
- readonly _pgBossIdentifier: unique symbol;
22
- }
23
-
24
- export type PgBossLayerOptions<Registrations extends readonly JobRegistration[], ErrorRequirements> = ConstructorOptions & {
20
+ export type PgBossLayerOptions<TRegistrations extends readonly JobRegistration[], TErrorRequirements> = ConstructorOptions & {
25
21
  readonly clientFactory?: PgBossClientFactory;
26
22
  // One started client is reference-counted per key, so development module reloads reuse it instead of starting another.
27
23
  readonly clientCacheKey?: string | symbol | undefined;
28
- readonly jobs: Registrations;
29
- readonly onError?: (error: Error) => Effect.Effect<unknown, never, ErrorRequirements>;
24
+ readonly jobs: TRegistrations;
25
+ readonly onError?: (error: Error) => Effect.Effect<unknown, never, TErrorRequirements>;
30
26
  readonly stop?: StopOptions;
31
27
  };
32
28
 
33
- export interface PgBossDefinition extends Context.Service<PgBossIdentifier, PgBossService> {
34
- readonly layer: <const Registrations extends readonly JobRegistration[], ErrorRequirements = never>(
35
- options: PgBossLayerOptions<Registrations, ErrorRequirements>,
36
- ) => Layer.Layer<PgBossIdentifier, PgBossError, RegistrationRequirements<Registrations> | ErrorRequirements>;
29
+ export interface PgBossDefinition<TIdentifier extends string = string> extends Context.Service<TIdentifier, PgBossService> {
30
+ readonly layer: <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(
31
+ options: PgBossLayerOptions<TRegistrations, TErrorRequirements>,
32
+ ) => Layer.Layer<TIdentifier, PgBossError, RegistrationRequirements<TRegistrations> | TErrorRequirements>;
37
33
  }
38
34
 
39
- const logClientError = (error: Error): Effect.Effect<void> => Effect.logError({ event: "pg_boss_error", message: error.message });
35
+ function logClientError(error: Error): Effect.Effect<void> {
36
+ return Effect.logError({ event: "pg_boss_error", message: error.message });
37
+ }
40
38
 
41
- export const makePgBoss = (identifier: string): PgBossDefinition => {
42
- const Service = Context.Service<PgBossIdentifier, PgBossService>(identifier);
39
+ export const makePgBoss = <const TIdentifier extends string>(identifier: TIdentifier): PgBossDefinition<TIdentifier> => {
40
+ const Service = Context.Service<TIdentifier, PgBossService>(identifier);
43
41
 
44
- const layer = <const Registrations extends readonly JobRegistration[], ErrorRequirements = never>(
45
- options: PgBossLayerOptions<Registrations, ErrorRequirements>,
46
- ): Layer.Layer<PgBossIdentifier, PgBossError, RegistrationRequirements<Registrations> | ErrorRequirements> => {
47
- type Requirements = RegistrationRequirements<Registrations> | ErrorRequirements;
42
+ const layer = <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(
43
+ options: PgBossLayerOptions<TRegistrations, TErrorRequirements>,
44
+ ): Layer.Layer<TIdentifier, PgBossError, RegistrationRequirements<TRegistrations> | TErrorRequirements> => {
45
+ type Requirements = RegistrationRequirements<TRegistrations> | TErrorRequirements;
48
46
  const names = options.jobs.map(registrationName);
49
47
  const { clientFactory, clientCacheKey, jobs, onError, stop, ...constructorOptions } = options;
50
48