@shivaedev/effect-pg-boss 0.0.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 (54) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +117 -0
  4. package/dist/definition.d.ts +61 -0
  5. package/dist/definition.d.ts.map +1 -0
  6. package/dist/definition.js +39 -0
  7. package/dist/definition.js.map +1 -0
  8. package/dist/error.d.ts +23 -0
  9. package/dist/error.d.ts.map +1 -0
  10. package/dist/error.js +11 -0
  11. package/dist/error.js.map +1 -0
  12. package/dist/health.d.ts +18 -0
  13. package/dist/health.d.ts.map +1 -0
  14. package/dist/health.js +2 -0
  15. package/dist/health.js.map +1 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +5 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/internal/client.d.ts +16 -0
  21. package/dist/internal/client.d.ts.map +1 -0
  22. package/dist/internal/client.js +3 -0
  23. package/dist/internal/client.js.map +1 -0
  24. package/dist/internal/health.d.ts +5 -0
  25. package/dist/internal/health.d.ts.map +1 -0
  26. package/dist/internal/health.js +28 -0
  27. package/dist/internal/health.js.map +1 -0
  28. package/dist/internal/lifecycle.d.ts +16 -0
  29. package/dist/internal/lifecycle.d.ts.map +1 -0
  30. package/dist/internal/lifecycle.js +83 -0
  31. package/dist/internal/lifecycle.js.map +1 -0
  32. package/dist/internal/register.d.ts +6 -0
  33. package/dist/internal/register.d.ts.map +1 -0
  34. package/dist/internal/register.js +72 -0
  35. package/dist/internal/register.js.map +1 -0
  36. package/dist/internal/service.d.ts +4 -0
  37. package/dist/internal/service.d.ts.map +1 -0
  38. package/dist/internal/service.js +24 -0
  39. package/dist/internal/service.js.map +1 -0
  40. package/dist/service.d.ts +27 -0
  41. package/dist/service.d.ts.map +1 -0
  42. package/dist/service.js +43 -0
  43. package/dist/service.js.map +1 -0
  44. package/package.json +59 -0
  45. package/src/definition.ts +144 -0
  46. package/src/error.ts +31 -0
  47. package/src/health.ts +20 -0
  48. package/src/index.ts +33 -0
  49. package/src/internal/client.ts +45 -0
  50. package/src/internal/health.ts +47 -0
  51. package/src/internal/lifecycle.ts +121 -0
  52. package/src/internal/register.ts +135 -0
  53. package/src/internal/service.ts +51 -0
  54. package/src/service.ts +148 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.1.0 - 2026-08-03
6
+
7
+ ### Added
8
+
9
+ - Add Effect services for typed pg-boss queues, Schema-decoded workers,
10
+ scheduled jobs, retry and dead-letter setup, enqueueing, health checks, and
11
+ scoped client lifecycle management.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShivaeDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # `@shivaedev/effect-pg-boss`
2
+
3
+ Effect-native queues, workers, schedules, and lifecycle management for
4
+ pg-boss.
5
+
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.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ pnpm add @shivaedev/effect-pg-boss effect pg-boss
14
+ ```
15
+
16
+ ## Define jobs
17
+
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.
20
+
21
+ ```ts
22
+ import { defineQueue } from "@shivaedev/effect-pg-boss"
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
+ })
36
+
37
+ const emailWorker = EmailQueue.handle(({ userId, attempt }) =>
38
+ Effect.gen(function* () {
39
+ const email = yield* Email
40
+ yield* email.send(userId, attempt)
41
+ }),
42
+ )
43
+ ```
44
+
45
+ Queue payloads are encoded through the same Schema when enqueued, so transforms
46
+ such as `NumberFromString` have one contract in both directions.
47
+
48
+ Schedules are queues with a cron trigger and an Effect that takes no payload:
49
+
50
+ ```ts
51
+ import { defineSchedule } from "@shivaedev/effect-pg-boss"
52
+
53
+ const Cleanup = defineSchedule({
54
+ name: "cleanup",
55
+ cron: "17 3 * * *",
56
+ })
57
+
58
+ const cleanupWorker = Cleanup.run(
59
+ Effect.gen(function* () {
60
+ const sessions = yield* Sessions
61
+ yield* sessions.removeExpired()
62
+ }),
63
+ )
64
+ ```
65
+
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.
69
+
70
+ ## Provide the service
71
+
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.
75
+
76
+ ```ts
77
+ import { makePgBoss } from "@shivaedev/effect-pg-boss"
78
+
79
+ export const Jobs = makePgBoss("@app/Jobs")
80
+
81
+ export const JobsLive = Jobs.layer({
82
+ connectionString: databaseUrl,
83
+ schema: "app_jobs",
84
+ jobs: [emailWorker, cleanupWorker],
85
+ developmentCacheKey: "app-jobs",
86
+ })
87
+ ```
88
+
89
+ `developmentCacheKey` reuses and reference-counts one client across module
90
+ reloads outside production. Applications decide which registrations are passed
91
+ to the Layer, so environment rules such as production-only schedules remain
92
+ application policy.
93
+
94
+ An `onError` Effect can route pg-boss background errors through application
95
+ logging or telemetry. Without one, errors use Effect logging.
96
+
97
+ ## Enqueue and inspect health
98
+
99
+ ```ts
100
+ const program = Effect.gen(function* () {
101
+ const jobs = yield* Jobs
102
+
103
+ const id = yield* jobs.enqueue(EmailQueue, {
104
+ userId: "user-1",
105
+ attempt: 1,
106
+ })
107
+
108
+ const health = yield* jobs.health
109
+ return { id, health }
110
+ })
111
+ ```
112
+
113
+ `enqueue` returns `Option<string>` because pg-boss can decline a job under a
114
+ queue policy. Its payload stays fully typed from the queue Schema. `health`
115
+ reports queued, ready, active, failed, and dead-letter counts for every
116
+ registered job without choosing an HTTP response shape or application health
117
+ policy.
@@ -0,0 +1,61 @@
1
+ import type { Effect, Schema } from "effect";
2
+ import type { Job, QueueOptions, ScheduleOptions, WorkOptions } from "pg-boss";
3
+ export interface JobPayloadSchema extends Schema.Top {
4
+ readonly Encoded: object;
5
+ readonly Type: object;
6
+ }
7
+ export interface JobContext {
8
+ readonly id: string;
9
+ readonly name: string;
10
+ readonly signal: AbortSignal;
11
+ readonly expireInSeconds: number;
12
+ readonly heartbeatSeconds: number | null;
13
+ }
14
+ export interface QueueDefinition<Name extends string = string, Payload extends JobPayloadSchema = JobPayloadSchema> {
15
+ readonly _tag: "QueueDefinition";
16
+ readonly name: Name;
17
+ readonly schema: Payload;
18
+ readonly queueOptions: Omit<QueueOptions, "deadLetter">;
19
+ readonly workerOptions: WorkOptions;
20
+ readonly handle: <E, R>(handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, E, R>) => QueueWorker<Payload, R>;
21
+ }
22
+ export interface QueueWorker<Payload extends JobPayloadSchema = JobPayloadSchema, Requirements = unknown> {
23
+ readonly _tag: "QueueWorker";
24
+ readonly queue: QueueDefinition<string, Payload>;
25
+ readonly handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, unknown, Requirements>;
26
+ }
27
+ export interface JobRegistration {
28
+ readonly _tag: "QueueWorker" | "ScheduledWorker";
29
+ }
30
+ export interface ScheduleDefinition<Name extends string = string> {
31
+ readonly _tag: "ScheduleDefinition";
32
+ readonly cron: string;
33
+ readonly name: Name;
34
+ readonly queueOptions: Omit<QueueOptions, "deadLetter">;
35
+ readonly scheduleOptions: ScheduleOptions;
36
+ readonly workerOptions: WorkOptions;
37
+ readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
38
+ }
39
+ export interface ScheduledWorker<Requirements = unknown> {
40
+ readonly _tag: "ScheduledWorker";
41
+ readonly schedule: ScheduleDefinition;
42
+ readonly effect: Effect.Effect<unknown, unknown, Requirements>;
43
+ }
44
+ export type RegistrationRequirements<Registrations extends readonly JobRegistration[]> = Registrations[number] extends infer Registration ? Registration extends QueueWorker<infer Payload, infer Requirements> ? Requirements | Payload["DecodingServices"] : Registration extends ScheduledWorker<infer Requirements> ? Requirements : never : never;
45
+ export interface DefineQueueOptions<Name extends string, Payload extends JobPayloadSchema> {
46
+ readonly name: Name;
47
+ readonly schema: Payload;
48
+ readonly queue?: Omit<QueueOptions, "deadLetter">;
49
+ readonly worker?: WorkOptions;
50
+ }
51
+ export declare const defineQueue: <const Name extends string, const Payload extends JobPayloadSchema>(options: DefineQueueOptions<Name, Payload>) => QueueDefinition<Name, Payload>;
52
+ export interface DefineScheduleOptions<Name extends string> {
53
+ readonly cron: string;
54
+ readonly name: Name;
55
+ readonly queue?: Omit<QueueOptions, "deadLetter">;
56
+ readonly schedule?: ScheduleOptions;
57
+ readonly worker?: WorkOptions;
58
+ }
59
+ export declare const defineSchedule: <const Name extends string>(options: DefineScheduleOptions<Name>) => ScheduleDefinition<Name>;
60
+ export declare const jobContext: (job: Job<unknown>) => JobContext;
61
+ //# sourceMappingURL=definition.d.ts.map
@@ -0,0 +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,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,eAAe,CAC/B,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,OAAO,SAAS,gBAAgB,GAAG,gBAAgB;IAEnD,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CA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zD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAClD,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,CAAC,IAAI,SAAS,MAAM,EACvD,SAAS,qBAAqB,CAAC,IAAI,CAAC,KAClC,kBAAkB,CAAC,IAAI,CAgBzB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,KAAK,GAAG,CAAC,OAAO,CAAC,KAAG,UAM7C,CAAC"}
@@ -0,0 +1,39 @@
1
+ export const defineQueue = (options) => {
2
+ const definition = {
3
+ _tag: "QueueDefinition",
4
+ name: options.name,
5
+ queueOptions: Object.freeze({ ...options.queue }),
6
+ schema: options.schema,
7
+ workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
8
+ handle: (handler) => Object.freeze({
9
+ _tag: "QueueWorker",
10
+ handler,
11
+ queue: definition,
12
+ }),
13
+ };
14
+ return Object.freeze(definition);
15
+ };
16
+ export const defineSchedule = (options) => {
17
+ const definition = {
18
+ _tag: "ScheduleDefinition",
19
+ cron: options.cron,
20
+ name: options.name,
21
+ queueOptions: Object.freeze({ ...options.queue }),
22
+ scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
23
+ workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
24
+ run: (effect) => Object.freeze({
25
+ _tag: "ScheduledWorker",
26
+ effect,
27
+ schedule: definition,
28
+ }),
29
+ };
30
+ return Object.freeze(definition);
31
+ };
32
+ export const jobContext = (job) => ({
33
+ expireInSeconds: job.expireInSeconds,
34
+ heartbeatSeconds: job.heartbeatSeconds,
35
+ id: job.id,
36
+ name: job.name,
37
+ signal: job.signal,
38
+ });
39
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AAE,EAAE,CACf,MAAM,CAAC,MAAM,CAAC;YACb,IAAI,EAAE,iBAA0B;YAChC,MAAM;YACN,QAAQ,EAAE,UAAU;SACpB,CAAC;KACH,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAiB,EAAc,EAAE,CAAC,CAAC;IAC7D,eAAe,EAAE,GAAG,CAAC,eAAe;IACpC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;IACtC,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Redacted } from "effect";
2
+ export type PgBossOperation = "enqueue" | "health" | "register" | "start" | "stop";
3
+ declare const PgBossError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
4
+ readonly _tag: "PgBossError";
5
+ } & Readonly<A>;
6
+ export declare class PgBossError extends PgBossError_base<{
7
+ readonly operation: PgBossOperation;
8
+ readonly queue?: string;
9
+ readonly original: Redacted.Redacted<unknown>;
10
+ }> {
11
+ }
12
+ declare const PgBossPayloadError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
13
+ readonly _tag: "PgBossPayloadError";
14
+ } & Readonly<A>;
15
+ export declare class PgBossPayloadError extends PgBossPayloadError_base<{
16
+ readonly direction: "decode" | "encode";
17
+ readonly queue: string;
18
+ readonly original: Redacted.Redacted<unknown>;
19
+ }> {
20
+ }
21
+ export declare const toPgBossError: (operation: PgBossOperation, error: unknown, queue?: string) => PgBossError;
22
+ export {};
23
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,eAAe,GACxB,SAAS,GACT,QAAQ,GACR,UAAU,GACV,OAAO,GACP,MAAM,CAAC;;;;AAEV,qBAAa,WAAY,SAAQ,iBAAgC;IAChE,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;CAAG;;;;AAEL,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC9E,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;CAAG;AAEL,eAAO,MAAM,aAAa,GACzB,WAAW,eAAe,EAC1B,OAAO,OAAO,EACd,QAAQ,MAAM,KACZ,WAKA,CAAC"}
package/dist/error.js ADDED
@@ -0,0 +1,11 @@
1
+ import { Data, Redacted } from "effect";
2
+ export class PgBossError extends Data.TaggedError("PgBossError") {
3
+ }
4
+ export class PgBossPayloadError extends Data.TaggedError("PgBossPayloadError") {
5
+ }
6
+ export const toPgBossError = (operation, error, queue) => new PgBossError({
7
+ operation,
8
+ queue,
9
+ original: Redacted.make(error),
10
+ });
11
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AASxC,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAI7D;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAI3E;CAAG;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,SAA0B,EAC1B,KAAc,EACd,KAAc,EACA,EAAE,CAChB,IAAI,WAAW,CAAC;IACf,SAAS;IACT,KAAK;IACL,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;CAC9B,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ export interface QueueHealth {
2
+ readonly activeCount: number;
3
+ readonly deadLetteredCount: number;
4
+ readonly failedCount: number;
5
+ readonly name: string;
6
+ readonly queuedCount: number;
7
+ readonly readyCount: number;
8
+ }
9
+ export interface JobsHealth {
10
+ readonly activeTotal: number;
11
+ readonly deadLetteredTotal: number;
12
+ readonly failedTotal: number;
13
+ readonly jobs: readonly QueueHealth[];
14
+ readonly queuedTotal: number;
15
+ readonly readyTotal: number;
16
+ }
17
+ export declare const deadLetterQueueName: (queueName: string) => string;
18
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"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,GAAI,WAAW,MAAM,KAAG,MACrC,CAAC"}
package/dist/health.js ADDED
@@ -0,0 +1,2 @@
1
+ export const deadLetterQueueName = (queueName) => `${queueName}-dlq`;
2
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAU,EAAE,CAChE,GAAG,SAAS,MAAM,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { type DefineQueueOptions, type DefineScheduleOptions, defineQueue, defineSchedule, type JobContext, type JobPayloadSchema, type JobRegistration, type QueueDefinition, type QueueWorker, type ScheduleDefinition, type ScheduledWorker, } from "./definition.js";
2
+ export { PgBossError, type PgBossOperation, PgBossPayloadError, } from "./error.js";
3
+ export { deadLetterQueueName, type JobsHealth, type QueueHealth, } from "./health.js";
4
+ export type { PgBossClient, PgBossClientFactory, } from "./internal/client.js";
5
+ export { makePgBoss, type PgBossDefinition, type PgBossLayerOptions, type PgBossService, } from "./service.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,WAAW,EACX,cAAc,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,KAAK,eAAe,EACpB,kBAAkB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,YAAY,EACZ,mBAAmB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,GAClB,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { defineQueue, defineSchedule, } from "./definition.js";
2
+ export { PgBossError, PgBossPayloadError, } from "./error.js";
3
+ export { deadLetterQueueName, } from "./health.js";
4
+ export { makePgBoss, } from "./service.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,WAAW,EACX,cAAc,GAQd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EAEX,kBAAkB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,mBAAmB,GAGnB,MAAM,aAAa,CAAC;AAKrB,OAAO,EACN,UAAU,GAIV,MAAM,cAAc,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { ConstructorOptions, Job, Queue, QueueResult, ScheduleOptions, SendOptions, StopOptions, WorkOptions } from "pg-boss";
2
+ export interface PgBossClient {
3
+ readonly createQueue: (name: string, options?: Omit<Queue, "name">) => Promise<void>;
4
+ readonly getQueue: (name: string) => Promise<QueueResult | null>;
5
+ readonly offWork: (name: string) => Promise<void>;
6
+ readonly on: (event: "error", listener: (error: Error) => void) => unknown;
7
+ readonly off: (event: "error", listener: (error: Error) => void) => unknown;
8
+ readonly schedule: (name: string, cron: string, data?: object | null, options?: ScheduleOptions) => Promise<void>;
9
+ readonly send: (name: string, data?: object | null, options?: SendOptions) => Promise<string | null>;
10
+ readonly start: () => Promise<unknown>;
11
+ readonly stop: (options?: StopOptions) => Promise<void>;
12
+ readonly work: <Payload>(name: string, options: WorkOptions, handler: (jobs: readonly Job<Payload>[]) => Promise<unknown>) => Promise<string>;
13
+ }
14
+ export type PgBossClientFactory = (options: ConstructorOptions) => PgBossClient;
15
+ export declare const defaultClientFactory: PgBossClientFactory;
16
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/internal/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,kBAAkB,EAClB,GAAG,EACH,KAAK,EACL,WAAW,EACX,eAAe,EACf,WAAW,EACX,WAAW,EACX,WAAW,EACX,MAAM,SAAS,CAAC;AAGjB,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,WAAW,EAAE,CACrB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,OAAO,CAAC;IAC3E,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,OAAO,CAAC;IAC5E,QAAQ,CAAC,QAAQ,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,CAAC,EAAE,eAAe,KACrB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,CACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,KACxD,OAAO,CAAC,MAAM,CAAC,CAAC;CACrB;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,YAAY,CAAC;AAEhF,eAAO,MAAM,oBAAoB,EAAE,mBACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { PgBoss } from "pg-boss";
2
+ export const defaultClientFactory = (options) => new PgBoss(options);
3
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/internal/client.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAiCjC,MAAM,CAAC,MAAM,oBAAoB,GAAwB,CAAC,OAAO,EAAE,EAAE,CACpE,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Effect } from "effect";
2
+ import { type JobsHealth } from "../health.js";
3
+ import type { PgBossClient } from "./client.js";
4
+ export declare const healthFor: (client: PgBossClient, names: readonly string[]) => Effect.Effect<JobsHealth, import("../error.js").PgBossError>;
5
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAEN,KAAK,UAAU,EAEf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,SAAS,GACrB,QAAQ,YAAY,EACpB,OAAO,SAAS,MAAM,EAAE,KACtB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,aAAa,EAAE,WAAW,CAkC5D,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { Effect } from "effect";
2
+ import { toPgBossError } from "../error.js";
3
+ import { deadLetterQueueName, } from "../health.js";
4
+ export const healthFor = (client, names) => Effect.forEach(names, (name) => Effect.tryPromise({
5
+ try: async () => {
6
+ const [queue, deadLetter] = await Promise.all([
7
+ client.getQueue(name),
8
+ client.getQueue(deadLetterQueueName(name)),
9
+ ]);
10
+ return {
11
+ activeCount: queue?.activeCount ?? 0,
12
+ deadLetteredCount: deadLetter?.queuedCount ?? 0,
13
+ failedCount: queue?.failedCount ?? 0,
14
+ name,
15
+ queuedCount: queue?.queuedCount ?? 0,
16
+ readyCount: queue?.readyCount ?? 0,
17
+ };
18
+ },
19
+ catch: (error) => toPgBossError("health", error, name),
20
+ }), { concurrency: "unbounded" }).pipe(Effect.map((jobs) => ({
21
+ activeTotal: jobs.reduce((sum, job) => sum + job.activeCount, 0),
22
+ deadLetteredTotal: jobs.reduce((sum, job) => sum + job.deadLetteredCount, 0),
23
+ failedTotal: jobs.reduce((sum, job) => sum + job.failedCount, 0),
24
+ jobs,
25
+ queuedTotal: jobs.reduce((sum, job) => sum + job.queuedCount, 0),
26
+ readyTotal: jobs.reduce((sum, job) => sum + job.readyCount, 0),
27
+ })));
28
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACN,mBAAmB,GAGnB,MAAM,cAAc,CAAC;AAGtB,MAAM,CAAC,MAAM,SAAS,GAAG,CACxB,MAAoB,EACpB,KAAwB,EACuC,EAAE,CACjE,MAAM,CAAC,OAAO,CACb,KAAK,EACL,CAAC,IAAI,EAAE,EAAE,CACR,MAAM,CAAC,UAAU,CAAC;IACjB,GAAG,EAAE,KAAK,IAA0B,EAAE;QACrC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC7C,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;YACrB,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;SAC1C,CAAC,CAAC;QACH,OAAO;YACN,WAAW,EAAE,KAAK,EAAE,WAAW,IAAI,CAAC;YACpC,iBAAiB,EAAE,UAAU,EAAE,WAAW,IAAI,CAAC;YAC/C,WAAW,EAAE,KAAK,EAAE,WAAW,IAAI,CAAC;YACpC,IAAI;YACJ,WAAW,EAAE,KAAK,EAAE,WAAW,IAAI,CAAC;YACpC,UAAU,EAAE,KAAK,EAAE,UAAU,IAAI,CAAC;SAClC,CAAC;IACH,CAAC;IACD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC;CACtD,CAAC,EACH,EAAE,WAAW,EAAE,WAAW,EAAE,CAC5B,CAAC,IAAI,CACL,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrB,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAC7B,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,iBAAiB,EACzC,CAAC,CACD;IACD,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,IAAI;IACJ,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;CAC9D,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { Effect } from "effect";
2
+ import type { ConstructorOptions, StopOptions } from "pg-boss";
3
+ import { type PgBossClient, type PgBossClientFactory } from "./client.js";
4
+ export interface AcquireClientOptions {
5
+ readonly clientFactory?: PgBossClientFactory;
6
+ readonly constructor: ConstructorOptions;
7
+ readonly developmentCacheKey?: string | symbol;
8
+ }
9
+ export interface AcquiredClient {
10
+ readonly client: PgBossClient;
11
+ readonly cacheKey?: string | symbol;
12
+ readonly reused: boolean;
13
+ }
14
+ export declare const acquireClient: (options: AcquireClientOptions) => Effect.Effect<AcquiredClient, import("../error.js").PgBossError>;
15
+ export declare const releaseClient: (acquired: AcquiredClient, stopOptions?: StopOptions) => Effect.Effect<void>;
16
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +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;AAE/D,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,MAAM,aAAa,CAAC;AAerB,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAC7C,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACzC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/C;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AAmBD,eAAO,MAAM,aAAa,GACzB,SAAS,oBAAoB,KAC3B,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,aAAa,EAAE,WAAW,CA8C/D,CAAC;AAEJ,eAAO,MAAM,aAAa,GACzB,UAAU,cAAc,EACxB,cAAc,WAAW,KACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAgBoC,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { Effect } from "effect";
2
+ import { toPgBossError } from "../error.js";
3
+ import { defaultClientFactory, } from "./client.js";
4
+ const CacheKey = Symbol.for("@shivaedev/effect-pg-boss/client-cache");
5
+ const globalCache = globalThis;
6
+ const clientCache = globalCache[CacheKey] ?? new Map();
7
+ globalCache[CacheKey] = clientCache;
8
+ const startClient = (options) => {
9
+ const client = (options.clientFactory ?? defaultClientFactory)(options.constructor);
10
+ return client.start().then(() => client, async (error) => {
11
+ try {
12
+ await client.stop();
13
+ }
14
+ catch {
15
+ // Preserve the startup failure; stop is best effort on failed acquisition.
16
+ }
17
+ throw error;
18
+ });
19
+ };
20
+ export const acquireClient = (options) => Effect.tryPromise({
21
+ try: async () => {
22
+ const cacheKey = process.env.NODE_ENV === "production"
23
+ ? undefined
24
+ : options.developmentCacheKey;
25
+ if (cacheKey === undefined) {
26
+ return {
27
+ client: await startClient(options),
28
+ reused: false,
29
+ };
30
+ }
31
+ const existing = clientCache.get(cacheKey);
32
+ if (existing !== undefined) {
33
+ existing.references += 1;
34
+ try {
35
+ return {
36
+ cacheKey,
37
+ client: await existing.client,
38
+ reused: true,
39
+ };
40
+ }
41
+ catch (error) {
42
+ existing.references -= 1;
43
+ throw error;
44
+ }
45
+ }
46
+ const entry = {
47
+ client: startClient(options),
48
+ references: 1,
49
+ };
50
+ clientCache.set(cacheKey, entry);
51
+ try {
52
+ return {
53
+ cacheKey,
54
+ client: await entry.client,
55
+ reused: false,
56
+ };
57
+ }
58
+ catch (error) {
59
+ if (clientCache.get(cacheKey) === entry)
60
+ clientCache.delete(cacheKey);
61
+ throw error;
62
+ }
63
+ },
64
+ catch: (error) => toPgBossError("start", error),
65
+ });
66
+ export const releaseClient = (acquired, stopOptions) => Effect.tryPromise({
67
+ try: async () => {
68
+ if (acquired.cacheKey === undefined) {
69
+ await acquired.client.stop(stopOptions);
70
+ return;
71
+ }
72
+ const entry = clientCache.get(acquired.cacheKey);
73
+ if (entry === undefined)
74
+ return;
75
+ entry.references -= 1;
76
+ if (entry.references > 0)
77
+ return;
78
+ clientCache.delete(acquired.cacheKey);
79
+ await acquired.client.stop(stopOptions);
80
+ },
81
+ catch: (error) => toPgBossError("stop", error),
82
+ }).pipe(Effect.catch((error) => Effect.logError(error)));
83
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +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,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C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,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO;QAChC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC;YAAE,OAAO;QACjC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IACD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC;CAC9C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Effect } from "effect";
2
+ import { type JobRegistration } from "../definition.js";
3
+ import type { PgBossClient } from "./client.js";
4
+ export declare const registrationNames: (registrations: readonly JobRegistration[]) => readonly string[];
5
+ export declare const registerJobs: <R>(client: PgBossClient, registrations: readonly JobRegistration[], context: import("effect").Context.Context<R>, replaceWorkers: boolean) => Effect.Effect<void, import("../error.js").PgBossError>;
6
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAElD,OAAO,EAEN,KAAK,eAAe,EAIpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiFhD,eAAO,MAAM,iBAAiB,GAC7B,eAAe,SAAS,eAAe,EAAE,KACvC,SAAS,MAAM,EAUjB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAC7B,QAAQ,YAAY,EACpB,eAAe,SAAS,eAAe,EAAE,EACzC,SAAS,OAAO,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAC5C,gBAAgB,OAAO,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,aAAa,EAAE,WAAW,CAuBrD,CAAC"}