@shivaedev/test-kits 0.3.1 → 0.5.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 (113) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +105 -0
  3. package/dist/github/adapters/appProvider.d.ts +31 -0
  4. package/dist/github/adapters/appProvider.d.ts.map +1 -0
  5. package/dist/github/adapters/appProvider.js +31 -0
  6. package/dist/github/adapters/appProvider.js.map +1 -0
  7. package/dist/github/adapters/credentials.d.ts +21 -0
  8. package/dist/github/adapters/credentials.d.ts.map +1 -0
  9. package/dist/github/adapters/credentials.js +48 -0
  10. package/dist/github/adapters/credentials.js.map +1 -0
  11. package/dist/github/adapters/webhookDelivery.d.ts +7 -0
  12. package/dist/github/adapters/webhookDelivery.d.ts.map +1 -0
  13. package/dist/github/adapters/webhookDelivery.js +15 -0
  14. package/dist/github/adapters/webhookDelivery.js.map +1 -0
  15. package/dist/github/fake.d.ts +52 -0
  16. package/dist/github/fake.d.ts.map +1 -0
  17. package/dist/github/fake.js +18 -0
  18. package/dist/github/fake.js.map +1 -0
  19. package/dist/jobs/adapters/expireAttempt.d.ts +4 -0
  20. package/dist/jobs/adapters/expireAttempt.d.ts.map +1 -0
  21. package/dist/jobs/adapters/expireAttempt.js +17 -0
  22. package/dist/jobs/adapters/expireAttempt.js.map +1 -0
  23. package/dist/jobs/adapters/queueSignal.d.ts +7 -0
  24. package/dist/jobs/adapters/queueSignal.d.ts.map +1 -0
  25. package/dist/jobs/adapters/queueSignal.js +29 -0
  26. package/dist/jobs/adapters/queueSignal.js.map +1 -0
  27. package/dist/jobs/adapters/quotedSchema.d.ts +2 -0
  28. package/dist/jobs/adapters/quotedSchema.d.ts.map +1 -0
  29. package/dist/jobs/adapters/quotedSchema.js +4 -0
  30. package/dist/jobs/adapters/quotedSchema.js.map +1 -0
  31. package/dist/jobs/adapters/testingClient.d.ts +13 -0
  32. package/dist/jobs/adapters/testingClient.d.ts.map +1 -0
  33. package/dist/jobs/adapters/testingClient.js +99 -0
  34. package/dist/jobs/adapters/testingClient.js.map +1 -0
  35. package/dist/jobs/adapters/testingController.d.ts +80 -0
  36. package/dist/jobs/adapters/testingController.d.ts.map +1 -0
  37. package/dist/jobs/adapters/testingController.js +121 -0
  38. package/dist/jobs/adapters/testingController.js.map +1 -0
  39. package/dist/jobs/adapters/testingDueNow.d.ts +7 -0
  40. package/dist/jobs/adapters/testingDueNow.d.ts.map +1 -0
  41. package/dist/jobs/adapters/testingDueNow.js +26 -0
  42. package/dist/jobs/adapters/testingDueNow.js.map +1 -0
  43. package/dist/jobs/adapters/testingEngine.d.ts +8 -0
  44. package/dist/jobs/adapters/testingEngine.d.ts.map +1 -0
  45. package/dist/jobs/adapters/testingEngine.js +12 -0
  46. package/dist/jobs/adapters/testingEngine.js.map +1 -0
  47. package/dist/jobs/adapters/testingExpirations.d.ts +8 -0
  48. package/dist/jobs/adapters/testingExpirations.d.ts.map +1 -0
  49. package/dist/jobs/adapters/testingExpirations.js +27 -0
  50. package/dist/jobs/adapters/testingExpirations.js.map +1 -0
  51. package/dist/jobs/adapters/testingInspectionClient.d.ts +6 -0
  52. package/dist/jobs/adapters/testingInspectionClient.d.ts.map +1 -0
  53. package/dist/jobs/adapters/testingInspectionClient.js +52 -0
  54. package/dist/jobs/adapters/testingInspectionClient.js.map +1 -0
  55. package/dist/jobs/adapters/testingSignal.d.ts +12 -0
  56. package/dist/jobs/adapters/testingSignal.d.ts.map +1 -0
  57. package/dist/jobs/adapters/testingSignal.js +28 -0
  58. package/dist/jobs/adapters/testingSignal.js.map +1 -0
  59. package/dist/jobs/adapters/testingTime.d.ts +10 -0
  60. package/dist/jobs/adapters/testingTime.d.ts.map +1 -0
  61. package/dist/jobs/adapters/testingTime.js +18 -0
  62. package/dist/jobs/adapters/testingTime.js.map +1 -0
  63. package/dist/jobs/error.d.ts +22 -0
  64. package/dist/jobs/error.d.ts.map +1 -0
  65. package/dist/jobs/error.js +9 -0
  66. package/dist/jobs/error.js.map +1 -0
  67. package/dist/jobs/internal/adapters/testingFetches.d.ts +7 -0
  68. package/dist/jobs/internal/adapters/testingFetches.d.ts.map +1 -0
  69. package/dist/jobs/internal/adapters/testingFetches.js +30 -0
  70. package/dist/jobs/internal/adapters/testingFetches.js.map +1 -0
  71. package/dist/jobs/internal/testingIdle.d.ts +17 -0
  72. package/dist/jobs/internal/testingIdle.d.ts.map +1 -0
  73. package/dist/jobs/internal/testingIdle.js +18 -0
  74. package/dist/jobs/internal/testingIdle.js.map +1 -0
  75. package/dist/jobs/internal/testingOperation.d.ts +6 -0
  76. package/dist/jobs/internal/testingOperation.d.ts.map +1 -0
  77. package/dist/jobs/internal/testingOperation.js +13 -0
  78. package/dist/jobs/internal/testingOperation.js.map +1 -0
  79. package/dist/jobs/internal/testingSchedules.d.ts +14 -0
  80. package/dist/jobs/internal/testingSchedules.d.ts.map +1 -0
  81. package/dist/jobs/internal/testingSchedules.js +20 -0
  82. package/dist/jobs/internal/testingSchedules.js.map +1 -0
  83. package/dist/jobs/internal/testingWaits.d.ts +21 -0
  84. package/dist/jobs/internal/testingWaits.d.ts.map +1 -0
  85. package/dist/jobs/internal/testingWaits.js +53 -0
  86. package/dist/jobs/internal/testingWaits.js.map +1 -0
  87. package/dist/jobs/testing.d.ts +89 -0
  88. package/dist/jobs/testing.d.ts.map +1 -0
  89. package/dist/jobs/testing.js +12 -0
  90. package/dist/jobs/testing.js.map +1 -0
  91. package/package.json +17 -13
  92. package/src/github/adapters/appProvider.ts +34 -0
  93. package/src/github/adapters/credentials.ts +62 -0
  94. package/src/github/adapters/webhookDelivery.ts +20 -0
  95. package/src/github/fake.ts +30 -0
  96. package/src/jobs/adapters/expireAttempt.ts +27 -0
  97. package/src/jobs/adapters/queueSignal.ts +30 -0
  98. package/src/jobs/adapters/quotedSchema.ts +3 -0
  99. package/src/jobs/adapters/testingClient.ts +121 -0
  100. package/src/jobs/adapters/testingController.ts +138 -0
  101. package/src/jobs/adapters/testingDueNow.ts +32 -0
  102. package/src/jobs/adapters/testingEngine.ts +14 -0
  103. package/src/jobs/adapters/testingExpirations.ts +33 -0
  104. package/src/jobs/adapters/testingInspectionClient.ts +71 -0
  105. package/src/jobs/adapters/testingSignal.ts +34 -0
  106. package/src/jobs/adapters/testingTime.ts +25 -0
  107. package/src/jobs/error.ts +17 -0
  108. package/src/jobs/internal/adapters/testingFetches.ts +36 -0
  109. package/src/jobs/internal/testingIdle.ts +36 -0
  110. package/src/jobs/internal/testingOperation.ts +19 -0
  111. package/src/jobs/internal/testingSchedules.ts +35 -0
  112. package/src/jobs/internal/testingWaits.ts +95 -0
  113. package/src/jobs/testing.ts +31 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0 - 2026-11-04
4
+
5
+ ### Added
6
+
7
+ - Publish a scoped fake GitHub App with real HTTP installation-token exchanges, configurable REST and GraphQL routes, provider fault controls and signed webhook delivery for application stories.
8
+
9
+ ## 0.4.0 - 2026-11-04
10
+
11
+ ### Added
12
+
13
+ - Provide the pg-boss testing controller in test-kits, using jobs’ public client and inspection service with the real PostgreSQL engine.
14
+
15
+ ### Changed
16
+
17
+ - Require Effect 4.0.7 and its matching companion packages. Install the 4.0.7 Effect stack together.
18
+
3
19
  ## 0.3.1 - 2026-11-04
4
20
 
5
21
  ### Changed
package/README.md CHANGED
@@ -31,6 +31,28 @@ Import `signedInUser`, `signInAgain`, `passwordUser` and `storedProviderAccounts
31
31
 
32
32
  Import `fakeDiscord` from `@shivaedev/test-kits/discord/fake.ts` and acquire it in a scope. Its loopback `server` retains messages across creation, editing, history reads and deletion, and supports the standard fake HTTP fault controls. Use the token `story-discord-token` with the real Discord REST client and set its API URL to `server.url`. Provide `gateway.transport` as the real gateway client's `GatewayTransport`; it speaks identify, heartbeat and resume frames, retains sessions and replays dispatches emitted during a dropped connection. `gateway.dispatch(type, data)`, `drop(code?)` and `invalidate(resumable)` change the provider, while `frames` and `urls` expose outbound observations. Drive reconnect and rate-limit time through the story kit's controlled clock.
33
33
 
34
+ ### GitHub Apps
35
+
36
+ Import `fakeGitHubApp` from `@shivaedev/test-kits/github/fake.ts` and acquire it in a scope. The provider exchanges signed App JWTs for installation tokens over loopback HTTP. Give the real `@shivaedev/github` client its `credentials.appId`, redacted `credentials.privateKey`, an installation ID and `server.url` as `GitHubConfig.apiUrl`.
37
+
38
+ ```ts
39
+ const github = yield* fakeGitHubApp({
40
+ routes: ({ installationToken }) => ({
41
+ repository: {
42
+ guard: installationToken,
43
+ path: "/repos/acme/widgets/issues/3",
44
+ reply: () => ({ body: { title: "Ship widgets" } }),
45
+ },
46
+ }),
47
+ });
48
+ ```
49
+
50
+ `routes` uses test-story's named fake HTTP routes for REST reads and writes and GraphQL POSTs. `installationToken` admits issued tokens, `installationOf(request)` returns their installation ID, and `appRequest` checks an App JWT. Routes own their paths; `prefix` changes the token exchange path for Enterprise API bases. Supply `credentials` from `githubAppCredentials()` in `@shivaedev/test-kits/github/adapters/credentials.ts` when several fixtures need the same App key.
51
+
52
+ `server.requests` records method, path, headers and raw body; `server.scriptFault`, `hold` and the other fake HTTP controls drive rate limits and delayed or refused exchanges. Return rate-limit headers on routes or script a 403/429 reply with `retry-after` to exercise the real client's typed rate-limit handling. The kit does not simulate a GitHub database or interpret GraphQL queries: route replies describe the outside provider's data.
53
+
54
+ `deliverWebhook(url, { body, event, deliveryId })` sends the exact body bytes over HTTP with GitHub event, delivery and HMAC signature headers, consumes the receiver's response and returns its status. Configure the receiver with `credentials.webhookSecret`; `credentials.webhookSignature(body)` is available for signature-specific stories. Drive token expiry and rate-limit time through the story clock. No client implementation is replaced.
55
+
34
56
  ### MCP bearer tokens
35
57
 
36
58
  Import `mcpBearerToken` from `@shivaedev/test-kits/mcp/adapters/bearerToken.ts`. With the application's mounted Better Auth instance (JWT and MCP provider plugins enabled), an existing signed-in user and OAuth client, mint the token precondition:
@@ -53,6 +75,89 @@ Import `withChangeCoverage`, `expectPublished`, `UnannouncedWrites`, `PublishedK
53
75
 
54
76
  Import `watchHints`, `heard`, `layerMemoryProtocol` and the `HintViewer` type from `@shivaedev/test-kits/contract/testing.ts`. `watchHints(stream)` starts a scoped listener and waits for its first hint. `heard(viewer, keys, { within }?)` reports whether a delivered changed hint contains all requested keys, using a one-second Effect-clock deadline by default. `layerMemoryProtocol(group)` connects the native RPC client and server in-process; provide the real group's handlers and middleware.
55
77
 
78
+ ### Jobs
79
+
80
+ `linkedWorkerSpans(sender, spans)` from `@shivaedev/test-kits/jobs/testing.ts` reads native recorded Effect spans and returns the pg-boss consumer spans whose links match both the sender's `traceId` and `spanId`. It returns every matching attempt, including retries, and no matches before a worker runs. An untraced job has no sender link. Settle the workers before reading their completed attempts; this readout does not wait or read queue storage.
81
+
82
+ `testing.ts` gives story kits a controller for one real pg-boss client. Create a fresh controller per runtime, pass its `clientFactory` to `pgBossLayer`, and keep that Layer scoped as usual. `jobs(queue, options?)` returns jobs-owned `Job` metadata with `data` decoded through the queue's Schema, including traced payloads. For a scheduled run with no payload, pass `{ name: Cleanup.name, schema: Schema.Null }` to read `data: null`. Invalid durable data fails with `PgBossPayloadError`; decoding services remain in the Effect's requirements.
83
+
84
+ This producer story uses the `SendEmail` definition and `Jobs` service from above. `databaseUrl` points to the story's PostgreSQL database:
85
+
86
+ ```ts
87
+ import { Context, Effect, Layer, Option } from "effect";
88
+ import { TestClock } from "effect/testing";
89
+ import { expect } from "vitest";
90
+ import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
91
+ import { pgBossLayer } from "@shivaedev/jobs/server/service.ts";
92
+ import { makePgBossTesting, testRetryPolicy } from "@shivaedev/test-kits/jobs/testing.ts";
93
+
94
+ const emailStories = storyKit({
95
+ clock: "test",
96
+ *create() {
97
+ const testing = makePgBossTesting({ clock: yield* TestClock.testClockWith(Effect.succeed), retryPolicy: testRetryPolicy });
98
+ const context = yield* Layer.build(
99
+ Jobs.layer({ jobs: [SendEmail] }).pipe(Layer.provide(pgBossLayer({ connectionString: databaseUrl, clientFactory: testing.clientFactory }))),
100
+ );
101
+ return { jobs: Context.get(context, Jobs), testing };
102
+ },
103
+ name: "queued email",
104
+ stages: ["ready"],
105
+ verbs: ({ jobs, testing }) => ({
106
+ enqueue: (userId: number) => jobs.enqueue(SendEmail, { userId }),
107
+ testing,
108
+ }),
109
+ });
110
+
111
+ emailStories.it("decodes the queued email", [], function* ({ enqueue, testing }) {
112
+ const id = Option.getOrThrow(yield* enqueue(42));
113
+ expect(yield* testing.jobs(SendEmail)).toMatchObject([{ id, data: { userId: 42 }, state: "created" }]);
114
+ });
115
+ ```
116
+
117
+ Set `retryPolicy: testRetryPolicy` through the controller to override queue and send settings with `retryDelay: 0` and `retryBackoff: false`. A failing worker can then exhaust its native retries without production backoff. The policy applies to subsequently sent jobs; it does not rewrite jobs already stored.
118
+
119
+ To pass time, use the controller's `timePasses` verb with the same native story `TestClock`:
120
+
121
+ ```ts
122
+ import { Effect } from "effect";
123
+ import { TestClock } from "effect/testing";
124
+ import { makePgBossTesting } from "@shivaedev/test-kits/jobs/testing.ts";
125
+
126
+ const testing = makePgBossTesting({ clock: yield* TestClock.testClockWith(Effect.succeed) });
127
+ yield* testing.timePasses("1 day");
128
+ ```
129
+
130
+ The controller advances the application clock and pg-boss's PostgreSQL clock together, wakes due workers and waits for their settlement. A `RetryAt` later than the new time remains deferred. Provide `testing.clientFactory` to the jobs Layer as above, and use an isolated database for each story. Passing time first waits for existing work to settle; release a held handler before advancing this controller. Supply the story clock so both the application and pg-boss stay under the kit's control.
131
+
132
+ `schedules()` lists registered schedules as `{ name, cron, timezone }` entries from PostgreSQL. `trigger(schedule)` takes a schedule definition, such as `Cleanup`, and enqueues one run now using its stored schedule data and options. It returns the run ID, or null when pg-boss suppresses the send. Register `Cleanup.run(effect)` in the testing Layer first, then yield `testing.trigger(Cleanup)` and `testing.waitForIdle` before observing the Effect's result. An unregistered schedule fails with `PgBossTestingError` (`operation: "trigger"`).
133
+
134
+ `refreshQueueStats(queue?)` requests a native pg-boss supervisor pass for one queue, or all queues when omitted, before reading cached counts through the jobs service's `health`. Like the service method, it performs native queue maintenance and respects pg-boss monitor intervals and backoff.
135
+
136
+ `failNextSend(queue)` arms one send failure for that queue. The next valid `enqueue` fails with the usual typed `PgBossError` (`operation: "enqueue"`); the following send proceeds normally.
137
+
138
+ `expireAfter(queue, n)` takes a positive attempt count: configure it before enqueueing to limit subsequent jobs to `n` attempts. Each successful send keeps its own expiry rule; later changes and duplicate-ID sends do not alter pending jobs. Earlier attempts run the handler normally; on attempt `n`, the controller expires the claimed job instead of invoking its handler. PostgreSQL supervision performs the terminal failure and dead lettering. A job that succeeds earlier completes normally.
139
+
140
+ `expireIn(queue, duration)` takes an Effect `Duration.Input`, such as `"1 second"`, and sets the expiry of subsequent sends, rounded up to whole seconds. Durations below one second or nonfinite durations fail with `PgBossTestingError` (`operation: "expireIn"`). Earlier sends retain their expiry, and later calls and duplicate-ID sends do not change stored jobs. Both expiry controls also apply to runs sent by `trigger(schedule)`. It can be combined with `expireAfter`: one sets each attempt's time budget, the other limits attempts. A stuck handler is interrupted at its deadline, and the same worker can fetch its retry after pg-boss fails the attempt. The testing expiry hooks support pg-boss schema version 46.
141
+
142
+ `runDueNow(queue)` makes future jobs in the queue's `created` or `retry` state due at the database's current time and wakes local workers. It includes delayed sends (`startAfter`), native retries and `RetryAt` deferrals. Yield `waitForIdle` afterwards before observing handler results; future jobs do not hold that wait open. It leaves active and terminal jobs and other queues unchanged.
143
+
144
+ `deferred(queue)` returns waiting deferrals as `{ at: DateTime.Utc, reason: string }[]`. `runDeferredNow(queue)` pulls those jobs forward to the database’s current time and wakes local workers without waiting for their original due time. Read `revision` before reading deferrals and use `waitForChange(revision)` as with other controls.
145
+
146
+ `checkBatchWindow(queue, millisecondsPerJob)` checks that the declared sequential batch fits strictly inside the stored queue expiry window. `schemaVersion` reads the installed version, and `checkSchemaVersion(expected)` fails when it differs. Import `PgBossTestingError` and `PgBossWaitError` from `@shivaedev/test-kits/jobs/error.ts`. Test control, read and check failures use `PgBossTestingError` with `operation`, optional `queue` and a redacted `original`.
147
+
148
+ `snapshot(queues)` reads the unfinished jobs of several queues in one query, so the result is one consistent PostgreSQL snapshot. It returns jobs in the `created`, `retry`, `active` and `failed` states, never completed ones, oldest first by creation. A waiting `RetryAt` job reads as `deferred` while its `startAfter` is in the future; once due, it reads as `retry` until claimed. A retry after a handler failure reads as `retry` even when its next attempt is in the future. Each entry has the job's `id`, `queue` (the definition's name), `state`, `startAfter` as a UTC `DateTime` and `data` decoded by that queue's Schema. Only unfinished rows are decoded, so a completed job whose stored data the Schema no longer accepts does not fail the read; invalid unfinished data fails with `PgBossPayloadError`.
149
+
150
+ `waitForIdle` discovers queues from the jobs registered in the controller's Layer, including producer-only definitions and schedules; it takes no queue list. It completes when none of those queues has an active job or an unblocked job ready to fetch, including work claimed by another client. Ready jobs keep the wait open even when no local worker runs them. A terminal native worker timeout lets the wait complete after pg-boss fails the job. Jobs whose `startAfter` is in the future do not hold the wait open. While a local fetched batch has no settlement yet, the wait reads nothing and waits for the next local change; otherwise it checks PostgreSQL on local changes and committed job-change notifications from other clients. A kit settles by yielding `waitForIdle` and then reading jobs once. As with any idle snapshot, a producer can enqueue more work after the wait returns.
151
+
152
+ A kit can also capture `revision` before reading jobs and yield `waitForChange(revision)` when its condition is unmet. The wait resumes after a local send, settlement or worker fetch, and when a local worker returns to idle as `waitForIdle` defines it, including terminal native worker timeouts. It also resumes immediately if a change occurred between the read and the wait. Local deferral settlements advance its revision before the worker continues the batch. It also observes committed job-change notifications from other clients through the inspection service. Future scheduled work and external writes that emit no job notification need their own wake source. Stories should retain a bounded test timeout.
153
+
154
+ `untilJob(queue, id, state)` waits that way for one job: it reads the job, waits for the next change when the job is in another state, and returns the job with `data` decoded through the queue's Schema once it reaches `state`. It also accepts `{ name, schema: Schema.Null }` for a triggered schedule's run. `fetchesPass(queue, n)` completes once `n` worker fetches on the queue that began after the wait started have finished, whether or not they claimed anything, so a story can show that a job stayed untaken by fetches that could have claimed it. Each fetch also counts as a change for `waitForChange`. Both waits give up after `within` (default 20 seconds) on the caller's Effect clock, so a story forks the wait and advances its `TestClock` to exercise a timeout, and fail with `PgBossWaitError`, whose message names what the wait expected and what it last saw:
155
+
156
+ ```ts
157
+ yield* testing.untilJob(SendEmail, id, "completed", { within: "5 seconds" });
158
+ // Gave up after 5s waiting until job <id> in send-email is completed; last seen: retry
159
+ ```
160
+
56
161
  ### Development setup
57
162
 
58
163
  Install `@shivaedev/test-kits` as a development dependency alongside `effect`, Better Auth and the runtime packages used by the kit. The package depends on `@shivaedev/test-story` and `@shivaedev/test-sql`; runtime packages are peers. The [story-testing skill](https://github.com/ShivaeDev/platform/blob/main/packages/skills/skills/story-testing/SKILL.md) describes how to compose an application's facade and prove its behavior.
@@ -0,0 +1,31 @@
1
+ import { Effect } from "effect";
2
+ import type { FakeHttpRequest } from "@shivaedev/test-story/server/fakeHttpService.ts";
3
+ import type { GitHubAppAccess } from "#github/fake.ts";
4
+ import type { AppJwt } from "./credentials.ts";
5
+ export declare const appProvider: (credentials: {
6
+ appId: string;
7
+ appJwtOf: (authorization: string | undefined, nowMillis: number) => AppJwt | undefined;
8
+ privateKey: string;
9
+ signedByApp: (jwt: AppJwt | undefined) => boolean;
10
+ tokenPrefix: string;
11
+ webhookSecret: string;
12
+ webhookSignature: (body: Uint8Array) => string;
13
+ }, prefix: string) => Effect.Effect<{
14
+ access: GitHubAppAccess;
15
+ state: {
16
+ exchanges: number;
17
+ jwts: (AppJwt | undefined)[];
18
+ };
19
+ token: {
20
+ guard: (request: FakeHttpRequest) => boolean;
21
+ method: string;
22
+ path: string;
23
+ reply: (request: FakeHttpRequest) => {
24
+ body: {
25
+ expires_at: string;
26
+ token: string;
27
+ };
28
+ };
29
+ };
30
+ }, never, never>;
31
+ //# sourceMappingURL=appProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appProvider.d.ts","sourceRoot":"","sources":["../../../src/github/adapters/appProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAwB,MAAM,kBAAkB,CAAC;AAErE,eAAO,MAAM,WAAW;;;;;;;;;;;mBAEG,MAAM;cAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE;;;QAe5D,KAAK;QACL,MAAM;QACN,IAAI;QACJ,KAAK,YAAY,eAAe;;;;;;;gBAQjC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { Clock, Effect } from "effect";
2
+ export const appProvider = Effect.fnUntraced(function* (credentials, prefix) {
3
+ const clock = yield* Clock.Clock;
4
+ const state = { exchanges: 0, jwts: [] };
5
+ const tokens = new Map();
6
+ const access = {
7
+ appRequest: (request) => {
8
+ const jwt = credentials.appJwtOf(request.headers.authorization, clock.currentTimeMillisUnsafe());
9
+ state.jwts.push(jwt);
10
+ return credentials.signedByApp(jwt);
11
+ },
12
+ installationOf: (request) => tokens.get(request.headers.authorization ?? ""),
13
+ installationToken: (request) => tokens.has(request.headers.authorization ?? ""),
14
+ };
15
+ return {
16
+ access,
17
+ state,
18
+ token: {
19
+ guard: access.appRequest,
20
+ method: "POST",
21
+ path: `${prefix}/app/installations/:installationId/access_tokens`,
22
+ reply: (request) => {
23
+ state.exchanges += 1;
24
+ const token = `${credentials.tokenPrefix}-${state.exchanges}`;
25
+ tokens.set(`Bearer ${token}`, Number(request.params.installationId));
26
+ return { body: { "expires_at": new Date(clock.currentTimeMillisUnsafe() + 3_600_000).toISOString(), token } };
27
+ },
28
+ },
29
+ };
30
+ });
31
+ //# sourceMappingURL=appProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appProvider.js","sourceRoot":"","sources":["../../../src/github/adapters/appProvider.ts"],"names":[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AI,KAAK,CAAC,SAAS,EAAE,CAAC;gBAC9D,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;gBACrE,OAAO,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;YAC/G,CAAC;SACD;KACD,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ export declare function githubAppCredentials(): {
3
+ appId: string;
4
+ appJwtOf: (authorization: string | undefined, nowMillis: number) => AppJwt | undefined;
5
+ privateKey: string;
6
+ signedByApp: (jwt: AppJwt | undefined) => boolean;
7
+ tokenPrefix: string;
8
+ webhookSecret: string;
9
+ webhookSignature: (body: Uint8Array) => string;
10
+ };
11
+ export interface AppJwt {
12
+ readonly algorithm: string;
13
+ readonly expiresIn: number;
14
+ readonly issuedAgo: number;
15
+ readonly issuer: string;
16
+ readonly signedBy: "the App's key" | "another key";
17
+ readonly type: string;
18
+ }
19
+ export declare function appJwtOf(publicKey: KeyObject, authorization: string | undefined, nowMillis: number): AppJwt | undefined;
20
+ export declare function signedByApp(appId: string, jwt: AppJwt | undefined): boolean;
21
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../src/github/adapters/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,SAAS,EAAU,MAAM,aAAa,CAAC;AAGtF,wBAAgB,oBAAoB;;8BAMR,MAAM,GAAG,SAAS,aAAa,MAAM;;uBAE5C,MAAM,GAAG,SAAS;;;6BAGZ,UAAU;EAEpC;AAKD,MAAM,WAAW,MAAM;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,aAAa,CAAC;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBvH;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,WAWjE"}
@@ -0,0 +1,48 @@
1
+ import { createHmac, generateKeyPairSync, verify } from "node:crypto";
2
+ import { Option, Schema } from "effect";
3
+ export function githubAppCredentials() {
4
+ const keys = generateKeyPairSync("rsa", { modulusLength: 2048 });
5
+ const appId = "123456";
6
+ const webhookSecret = "webhook-secret";
7
+ return {
8
+ appId,
9
+ appJwtOf: (authorization, nowMillis) => appJwtOf(keys.publicKey, authorization, nowMillis),
10
+ privateKey: keys.privateKey.export({ format: "pem", type: "pkcs8" }).toString(),
11
+ signedByApp: (jwt) => signedByApp(appId, jwt),
12
+ tokenPrefix: "installation-token-secret",
13
+ webhookSecret,
14
+ webhookSignature: (body) => `sha256=${createHmac("sha256", webhookSecret).update(body).digest("hex")}`,
15
+ };
16
+ }
17
+ const Claims = Schema.fromJsonString(Schema.Struct({ exp: Schema.Number, iat: Schema.Number, iss: Schema.String }));
18
+ const Header = Schema.fromJsonString(Schema.Struct({ alg: Schema.String, typ: Schema.String }));
19
+ export function appJwtOf(publicKey, authorization, nowMillis) {
20
+ const [header = "", payload = "", signature = ""] = (authorization?.replace(/^Bearer /u, "") ?? "").split(".");
21
+ const claims = Schema.decodeUnknownOption(Claims)(Buffer.from(payload, "base64url").toString());
22
+ const fields = Schema.decodeUnknownOption(Header)(Buffer.from(header, "base64url").toString());
23
+ if (Option.isNone(claims) || Option.isNone(fields)) {
24
+ return undefined;
25
+ }
26
+ const now = nowMillis / 1000;
27
+ return {
28
+ algorithm: fields.value.alg,
29
+ expiresIn: claims.value.exp - now,
30
+ issuedAgo: now - claims.value.iat,
31
+ issuer: claims.value.iss,
32
+ signedBy: verify("RSA-SHA256", Buffer.from(`${header}.${payload}`), publicKey, Buffer.from(signature, "base64url"))
33
+ ? "the App's key"
34
+ : "another key",
35
+ type: fields.value.typ,
36
+ };
37
+ }
38
+ export function signedByApp(appId, jwt) {
39
+ return (jwt !== undefined
40
+ && jwt.signedBy === "the App's key"
41
+ && jwt.algorithm === "RS256"
42
+ && jwt.issuer === appId
43
+ && jwt.issuedAgo >= 0
44
+ && jwt.issuedAgo <= 600
45
+ && jwt.expiresIn > 0
46
+ && jwt.expiresIn <= 600);
47
+ }
48
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/github/adapters/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAkB,MAAM,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,UAAU,oBAAoB;IACnC,MAAM,IAAI,GAAG,mBAAmB,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,QAAQ,CAAC;IACvB,MAAM,aAAa,GAAG,gBAAgB,CAAC;IACvC,OAAO;QACN,KAAK;QACL,QAAQ,EAAE,CAAC,aAAiC,EAAE,SAAiB,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC;QACtH,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAA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string): (url: string, delivery: {
3
+ readonly body: Uint8Array;
4
+ readonly event: string;
5
+ readonly deliveryId: string;
6
+ }) => Effect.Effect<number, import("effect/http/HttpClientError").HttpClientError, never>;
7
+ //# sourceMappingURL=webhookDelivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhookDelivery.d.ts","sourceRoot":"","sources":["../../../src/github/adapters/webhookDelivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,wBAAgB,eAAe,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM;mBACW,UAAU;oBAAkB,MAAM;yBAAuB,MAAM;0FAe3I"}
@@ -0,0 +1,15 @@
1
+ import { Effect } from "effect";
2
+ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
3
+ export function webhookDelivery(sign) {
4
+ return Effect.fnUntraced(function* (url, delivery) {
5
+ const client = yield* HttpClient.HttpClient;
6
+ const response = yield* client.execute(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders({
7
+ "x-github-delivery": delivery.deliveryId,
8
+ "x-github-event": delivery.event,
9
+ "x-hub-signature-256": sign(delivery.body),
10
+ }), HttpClientRequest.bodyUint8Array(delivery.body, "application/json")));
11
+ yield* response.text;
12
+ return response.status;
13
+ }, Effect.provide(FetchHttpClient.layer));
14
+ }
15
+ //# sourceMappingURL=webhookDelivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhookDelivery.js","sourceRoot":"","sources":["../../../src/github/adapters/webhookDelivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,UAAU,eAAe,CAAC,IAAkC;IACjE,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,GAAW,EAAE,QAA4F;QAC5I,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;QAC5C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CACrC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC/B,iBAAiB,CAAC,UAAU,CAAC;YAC5B,mBAAmB,EAAE,QAAQ,CAAC,UAAU;YACxC,gBAAgB,EAAE,QAAQ,CAAC,KAAK;YAChC,qBAAqB,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;SAC1C,CAAC,EACF,iBAAiB,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC,CACnE,CACD,CAAC;QACF,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrB,OAAO,QAAQ,CAAC,MAAM,CAAC;IACxB,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { Effect } from "effect";
2
+ import { type FakeHttpRequest, type FakeHttpRoute } from "@shivaedev/test-story/server/fakeHttpService.ts";
3
+ import { githubAppCredentials } from "#github/adapters/credentials.ts";
4
+ export interface GitHubAppAccess {
5
+ readonly appRequest: (request: FakeHttpRequest) => boolean;
6
+ readonly installationOf: (request: FakeHttpRequest) => number | undefined;
7
+ readonly installationToken: (request: FakeHttpRequest) => boolean;
8
+ }
9
+ export declare const fakeGitHubApp: (options?: {
10
+ readonly credentials?: ReturnType<typeof githubAppCredentials>;
11
+ readonly prefix?: string;
12
+ readonly routes?: (access: GitHubAppAccess) => Readonly<Record<string, FakeHttpRoute>>;
13
+ } | undefined) => Effect.Effect<{
14
+ credentials: {
15
+ appId: string;
16
+ appJwtOf: (authorization: string | undefined, nowMillis: number) => import("#github/adapters/credentials.ts").AppJwt | undefined;
17
+ privateKey: string;
18
+ signedByApp: (jwt: import("#github/adapters/credentials.ts").AppJwt | undefined) => boolean;
19
+ tokenPrefix: string;
20
+ webhookSecret: string;
21
+ webhookSignature: (body: Uint8Array) => string;
22
+ };
23
+ deliverWebhook: (url: string, delivery: {
24
+ readonly body: Uint8Array;
25
+ readonly event: string;
26
+ readonly deliveryId: string;
27
+ }) => Effect.Effect<number, import("effect/http/HttpClientError").HttpClientError, never>;
28
+ server: {
29
+ completed: import("effect/Stream").Stream<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord, never, never>;
30
+ fault: (route: string, fault: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpFault, scope?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScope) => Effect.Effect<void, never, never>;
31
+ hold: (route: string, holdOptions?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpHoldOptions) => Effect.Effect<{
32
+ release: Effect.Effect<void, never, never>;
33
+ waiting: Effect.Effect<void, never, never>;
34
+ }, never, never>;
35
+ narrate: (sink: (line: string) => void) => void;
36
+ received: import("effect/Stream").Stream<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord, never, never>;
37
+ releaseOnArrival: (route: string, arrival: string, scope?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScope) => Effect.Effect<void, never, never>;
38
+ readonly requests: readonly import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord[];
39
+ scriptFault: (route: string, fault: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpFault, scriptOptions?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScriptOptions) => Effect.Effect<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScript, never, never>;
40
+ stall: (route: string, scope?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScope) => Effect.Effect<{
41
+ release: Effect.Effect<void, never, never>;
42
+ waiting: Effect.Effect<void, never, never>;
43
+ }, never, never>;
44
+ untilAbandoned: (matches: (request: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord) => boolean, wait: import("@shivaedev/test-story/server/until.ts").UntilOptions) => Effect.Effect<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord, import("@shivaedev/test-story/server/until.ts").SignalNotReceived, never>;
45
+ url: string;
46
+ };
47
+ state: {
48
+ exchanges: number;
49
+ jwts: (import("#github/adapters/credentials.ts").AppJwt | undefined)[];
50
+ };
51
+ }, import("effect/Cause").UnknownError, import("effect/Scope").Scope>;
52
+ //# sourceMappingURL=fake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake.d.ts","sourceRoot":"","sources":["../../src/github/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAmB,MAAM,iDAAiD,CAAC;AAE5H,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC;IAC3D,QAAQ,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,GAAG,SAAS,CAAC;IAC1E,QAAQ,CAAC,iBAAiB,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC;CAClE;AAED,eAAO,MAAM,aAAa;2BAED,UAAU,CAAC,OAAO,oBAAoB,CAAC;sBAC5C,MAAM;sBACN,CAAC,MAAM,EAAE,eAAe,KAAK,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAatF,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Effect } from "effect";
2
+ import { fakeHttpService } from "@shivaedev/test-story/server/fakeHttpService.ts";
3
+ import { appProvider } from "#github/adapters/appProvider.ts";
4
+ import { githubAppCredentials } from "#github/adapters/credentials.ts";
5
+ import { webhookDelivery } from "#github/adapters/webhookDelivery.ts";
6
+ export const fakeGitHubApp = Effect.fnUntraced(function* (options = {}) {
7
+ const credentials = options.credentials ?? githubAppCredentials();
8
+ const prefix = options.prefix ?? "";
9
+ const { access, state, token } = yield* appProvider(credentials, prefix);
10
+ const server = yield* fakeHttpService({
11
+ routes: {
12
+ token,
13
+ ...options.routes?.(access),
14
+ },
15
+ });
16
+ return { credentials, deliverWebhook: webhookDelivery(credentials.webhookSignature), server, state };
17
+ });
18
+ //# sourceMappingURL=fake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake.js","sourceRoot":"","sources":["../../src/github/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAA4C,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAC5H,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAQtE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EACvD,OAAO,GAIH,EAAE;IAEN,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,oBAAoB,EAAE,CAAC;IAClE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC;QACrC,MAAM,EAAE;YACP,KAAK;YACL,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC;SAC3B;KACD,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACtG,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { EngineClient } from "@shivaedev/jobs/server/engineClient.ts";
2
+ import type { WorkerJob } from "@shivaedev/jobs/server/job.ts";
3
+ export declare function expireAttempt(client: EngineClient, schema: string, job: Pick<WorkerJob<unknown>, "name" | "id" | "retryCount">, cause?: "expiry" | "heartbeat"): Promise<void>;
4
+ //# sourceMappingURL=expireAttempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expireAttempt.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/expireAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,wBAAsB,aAAa,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CAAC,EAC3D,KAAK,GAAE,QAAQ,GAAG,WAAsB,GACtC,OAAO,CAAC,IAAI,CAAC,CAiBf"}
@@ -0,0 +1,17 @@
1
+ import { quotedSchema } from "./quotedSchema.js";
2
+ export async function expireAttempt(client, schema, job, cause = "expiry") {
3
+ if ((await client.schemaVersion()) !== 46) {
4
+ throw new Error("Testing expiry requires pg-boss schema version 46");
5
+ }
6
+ const quoted = quotedSchema(schema);
7
+ const timestamp = cause === "expiry" ? "started_on" : "heartbeat_on";
8
+ const seconds = cause === "expiry" ? "expire_seconds" : "heartbeat_seconds";
9
+ await client.getDb().executeSql(`UPDATE ${quoted}.job SET ${timestamp} = ${quoted}.job_now() - (${seconds} + 1) * interval '1 second'
10
+ WHERE name = $1 AND id = $2 AND retry_count = $3 AND state = 'active'`, [job.name, job.id, job.retryCount]);
11
+ // Supervision owns expiry and dead lettering; make its claim due with the job's deadline.
12
+ await client
13
+ .getDb()
14
+ .executeSql(`UPDATE ${quoted}.queue SET monitor_claim_on = ${quoted}.job_now() - interval '1 week' WHERE name = $1`, [job.name]);
15
+ await client.supervise(job.name);
16
+ }
17
+ //# sourceMappingURL=expireAttempt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expireAttempt.js","sourceRoot":"","sources":["../../../src/jobs/adapters/expireAttempt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAAoB,EACpB,MAAc,EACd,GAA2D,EAC3D,KAAK,GAA2B,QAAQ;IAExC,IAAI,CAAC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC;IACrE,MAAM,OAAO,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,mBAAmB,CAAC;IAC5E,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,UAAU,CAC9B,UAAU,MAAM,YAAY,SAAS,MAAM,MAAM,iBAAiB,OAAO;wEACH,EACtE,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,CAClC,CAAC;IACF,0FAA0F;IAC1F,MAAM,MAAM;SACV,KAAK,EAAE;SACP,UAAU,CAAC,UAAU,MAAM,iCAAiC,MAAM,gDAAgD,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAClI,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Effect } from "effect";
2
+ export declare function queueSignal(): {
3
+ changed(): void;
4
+ revision: Effect.Effect<number, never, never>;
5
+ waitForChange: (after: number) => Effect.Effect<number>;
6
+ };
7
+ //# sourceMappingURL=queueSignal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queueSignal.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/queueSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,wBAAgB,WAAW;IAIzB,OAAO;IASP,QAAQ;IACR,aAAa,UAAU,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;EAatD"}
@@ -0,0 +1,29 @@
1
+ import { Effect } from "effect";
2
+ export function queueSignal() {
3
+ let revision = 0;
4
+ const listeners = new Set();
5
+ return {
6
+ changed() {
7
+ revision += 1;
8
+ // A resumed waiter can wait again synchronously; it must wait for the next change, not this one.
9
+ const waiting = [...listeners];
10
+ listeners.clear();
11
+ for (const listener of waiting) {
12
+ listener(revision);
13
+ }
14
+ },
15
+ revision: Effect.sync(() => revision),
16
+ waitForChange: (after) => Effect.callback((resume) => {
17
+ if (revision !== after) {
18
+ resume(Effect.succeed(revision));
19
+ return;
20
+ }
21
+ function listener(current) {
22
+ resume(Effect.succeed(current));
23
+ }
24
+ listeners.add(listener);
25
+ return Effect.sync(() => listeners.delete(listener));
26
+ }),
27
+ };
28
+ }
29
+ //# sourceMappingURL=queueSignal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queueSignal.js","sourceRoot":"","sources":["../../../src/jobs/adapters/queueSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,UAAU,WAAW;IAC1B,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAM,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAC;IACxD,OAAO;QACN,OAAO;YACN,QAAQ,IAAI,CAAC,CAAC;YACd,iGAAiG;YACjG,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;YAC/B,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;gBAChC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACpB,CAAC;QACF,CAAC;QACD,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC;QACrC,aAAa,EAAE,CAAC,KAAa,EAAyB,EAAE,CACvD,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1B,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;gBACxB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACjC,OAAO;YACR,CAAC;YACD,SAAS,QAAQ,CAAC,OAAe;gBAChC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;YACjC,CAAC;YACD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC;KACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function quotedSchema(schema: string): string;
2
+ //# sourceMappingURL=quotedSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotedSchema.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/quotedSchema.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,4 @@
1
+ export function quotedSchema(schema) {
2
+ return `"${schema.replaceAll('"', '""')}"`;
3
+ }
4
+ //# sourceMappingURL=quotedSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotedSchema.js","sourceRoot":"","sources":["../../../src/jobs/adapters/quotedSchema.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,MAAc;IAC1C,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { EngineClient } from "@shivaedev/jobs/server/engineClient.ts";
2
+ import type { EnqueueOptions } from "@shivaedev/jobs/server/enqueueOptions.ts";
3
+ import type { TestingWork } from "#jobs/internal/testingIdle.ts";
4
+ export interface TestingControls {
5
+ readonly changed: () => void;
6
+ readonly expirations: Map<string, number>;
7
+ readonly expirySeconds: Map<string, number>;
8
+ readonly failures: Set<string>;
9
+ readonly retryPolicy: Pick<EnqueueOptions, "retryBackoff" | "retryDelay">;
10
+ readonly work: TestingWork;
11
+ }
12
+ export declare function testingClient(client: EngineClient, schema: string, controls: TestingControls): EngineClient;
13
+ //# sourceMappingURL=testingClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingClient.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/testingClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAI/E,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE/E,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC;IAC1E,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC3B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,YAAY,CAsG3G"}