@storyshelf/queue-sqs 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +32 -23
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Siddhant Gupta
|
|
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
CHANGED
|
@@ -49,7 +49,7 @@ Creates an SQS-backed `CaptureQueue`. The returned adapter implements every meth
|
|
|
49
49
|
|
|
50
50
|
## How it fits in
|
|
51
51
|
|
|
52
|
-
`queue-sqs` is the `
|
|
52
|
+
`queue-sqs` is the `captureQueue` option for `createShelfRouter` in AWS/cloud deployments. It implements the same `CaptureQueue` interface as `InMemoryCaptureQueue` (exported from `@storyshelf/core`), so switching between in-process and remote queues requires no changes to router or build logic.
|
|
53
53
|
|
|
54
54
|
See `docs/architecture.md` and ADR 0009.
|
|
55
55
|
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import __tsdown_shims_path from 'node:path';
|
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
3
|
import { SQSClient } from "@aws-sdk/client-sqs";
|
|
4
4
|
import { CaptureQueue } from "@storyshelf/core";
|
|
5
|
-
import { Logger } from "
|
|
5
|
+
import { Logger } from "@storyshelf/core/types";
|
|
6
6
|
//#region src/index.d.ts
|
|
7
7
|
/** Options for configuring an SQS-backed CaptureQueue. */
|
|
8
8
|
interface SqsCaptureQueueOptions {
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n DeleteMessageCommand,\n ReceiveMessageCommand,\n SendMessageCommand,\n SQSClient,\n} from \"@aws-sdk/client-sqs\";\n\nimport type {\n CaptureJob,\n CaptureQueue,\n JobStatus,\n QueueEntry,\n} from \"@storyshelf/core\";\n\nimport type { Logger } from \"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n DeleteMessageCommand,\n ReceiveMessageCommand,\n SendMessageCommand,\n SQSClient,\n} from \"@aws-sdk/client-sqs\";\n\nimport type {\n CaptureJob,\n CaptureQueue,\n JobStatus,\n QueueEntry,\n} from \"@storyshelf/core\";\n\nimport type { Logger } from \"@storyshelf/core/types\";\n\ndeclare const __PKG_VERSION__: string | undefined;\n\n/** Options for configuring an SQS-backed CaptureQueue. */\nexport interface SqsCaptureQueueOptions {\n /** SQS queue URL. */\n queueUrl: string;\n /** Optional pre-configured SQSClient. */\n client?: SQSClient;\n /** Optional logger for queue diagnostics. */\n logger?: Logger;\n}\n\ninterface QueuedBody {\n buildId?: string;\n status?: JobStatus;\n queuedAt?: string;\n startedAt?: string;\n finishedAt?: string;\n error?: string;\n reqId?: string;\n}\n\nfunction parseBody(raw: string): QueuedBody {\n return JSON.parse(raw) as QueuedBody;\n}\n\nfunction hasQueuedOrRunningStatus(body: QueuedBody): boolean {\n const status = body.status ?? \"queued\";\n return [\"queued\", \"running\"].includes(status);\n}\n\nfunction mapQueueEntry(raw: { Body?: string }): QueueEntry {\n const body = parseBody(raw.Body ?? \"{}\");\n return {\n buildId: body.buildId ?? \"unknown\",\n status: body.status ?? \"queued\",\n queuedAt: body.queuedAt ?? new Date().toISOString(),\n };\n}\n\n/**\n * Create an SQS-backed `CaptureQueue`.\n *\n * Jobs are submitted via `SendMessage` and retrieved via `ReceiveMessage`;\n * messages are deleted after reading to prevent re-processing.\n * A separately-assembled worker polls the queue and calls\n * `executeCaptureJob` from `@storyshelf/core`.\n *\n * @param options - SQS queue URL and optional client configuration.\n * @returns A `CaptureQueue` satisfying the core interface.\n */\n/* oxlint-disable max-lines-per-function */\nexport function createSqsCaptureQueue(\n options: SqsCaptureQueueOptions,\n): CaptureQueue {\n const client = options.client ?? new SQSClient({});\n\n return {\n metadata: {\n name: \"SQS Queue\",\n version: (globalThis as unknown as { __PKG_VERSION__?: string }).__PKG_VERSION__ ?? \"0.0.0\",\n description: \"SQS-backed capture queue\",\n kind: \"sqs\",\n },\n /**\n * Submit a build for capture. Resolves once the message is sent to SQS.\n *\n * The actual capture execution happens in a separate worker that\n * polls the queue and calls `executeCaptureJob`.\n */\n async enqueue(job: CaptureJob): Promise<void> {\n await client.send(\n new SendMessageCommand({\n QueueUrl: options.queueUrl,\n MessageBody: JSON.stringify({\n buildId: job.buildId,\n reqId: job.reqId,\n }),\n MessageAttributes: {\n buildId: {\n DataType: \"String\",\n StringValue: job.buildId,\n },\n status: {\n DataType: \"String\",\n StringValue: \"queued\",\n },\n },\n }),\n );\n },\n\n /**\n * Return the current status entry for a build, or null if untracked.\n *\n * Polls the SQS queue for a message matching the buildId. If found,\n * the message is deleted so it is not re-processed.\n */\n async status(buildId: string): Promise<QueueEntry | null> {\n const resp = await client.send(\n new ReceiveMessageCommand({\n QueueUrl: options.queueUrl,\n MaxNumberOfMessages: 1,\n MessageAttributeNames: [\"All\"],\n }),\n );\n\n const messages = resp.Messages ?? [];\n if (messages.length === 0) {\n return null;\n }\n\n const [msg] = messages;\n if (!msg?.Body) {\n return null;\n }\n\n const body = parseBody(msg.Body);\n\n await client.send(\n new DeleteMessageCommand({\n QueueUrl: options.queueUrl,\n ReceiptHandle: msg.ReceiptHandle,\n }),\n );\n\n return {\n buildId: body.buildId ?? buildId,\n status: body.status ?? \"queued\",\n queuedAt: body.queuedAt ?? new Date().toISOString(),\n startedAt: body.startedAt,\n finishedAt: body.finishedAt,\n error: body.error,\n };\n },\n\n /**\n * Return queue entries that are queued or running, newest first.\n *\n * Short poll for up to 10 messages. Filters by status.\n */\n async active(): Promise<QueueEntry[]> {\n const resp = await client.send(\n new ReceiveMessageCommand({\n QueueUrl: options.queueUrl,\n MaxNumberOfMessages: 10,\n MessageAttributeNames: [\"All\"],\n }),\n );\n\n return (resp.Messages ?? [])\n .filter((message) => message.Body?.length && hasQueuedOrRunningStatus(parseBody(message.Body)))\n .map((msg) => mapQueueEntry(msg))\n .toSorted((left, right) => right.queuedAt.localeCompare(left.queuedAt));\n },\n\n /**\n * Return the most recent queue entries, newest first.\n *\n * Short poll for up to `limit` messages, sorted by queuedAt descending.\n */\n async recent(limit: number): Promise<QueueEntry[]> {\n const resp = await client.send(\n new ReceiveMessageCommand({\n QueueUrl: options.queueUrl,\n MaxNumberOfMessages: limit,\n MessageAttributeNames: [\"All\"],\n }),\n );\n\n return (resp.Messages ?? [])\n .map((msg) => mapQueueEntry(msg))\n .to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AAM,OAAO,KACX,IAAI,qBAAqB;IACvB,UAAU,QAAQ;IAClB,eAAe,IAAI;GACrB,CAAC,CACH;GAEA,OAAO;IACL,SAAS,KAAK,WAAW;IACzB,QAAQ,KAAK,UAAU;IACvB,UAAU,KAAK,6BAAY,IAAI,KAAK,EAAA,CAAE,YAAY;IAClD,WAAW,KAAK;IAChB,YAAY,KAAK;IACjB,OAAO,KAAK;GACd;EACF;;;;;;EAOA,MAAM,SAAgC;GASpC,SAAQ,MARW,OAAO,KACxB,IAAI,sBAAsB;IACxB,UAAU,QAAQ;IAClB,qBAAqB;IACrB,uBAAuB,CAAC,KAAK;GAC/B,CAAC,CACH,EAAA,CAEa,YAAY,CAAC,EAAA,CACvB,QAAQ,YAAY,QAAQ,MAAM,UAAU,yBAAyB,UAAU,QAAQ,IAAI,CAAC,CAAC,CAAC,CAC9F,KAAK,QAAQ,cAAc,GAAG,CAAC,CAAC,CAChC,UAAU,MAAM,UAAU,MAAM,SAAS,cAAc,KAAK,QAAQ,CAAC;EAC1E;;;;;;EAOA,MAAM,OAAO,OAAsC;GASjD,SAAQ,MARW,OAAO,KACxB,IAAI,sBAAsB;IACxB,UAAU,QAAQ;IAClB,qBAAqB;IACrB,uBAAuB,CAAC,KAAK;GAC/B,CAAC,CACH,EAAA,CAEa,YAAY,CAAC,EAAA,CACvB,KAAK,QAAQ,cAAc,GAAG,CAAC,CAAC,CAChC,UAAU,MAAM,UAAU,MAAM,SAAS,cAAc,KAAK,QAAQ,CAAC;EAC1E;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,61 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyshelf/queue-sqs",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.1.2",
|
|
5
4
|
"description": "SQS capture job queue adapter for StoryShelf (AWS cloud deployments).",
|
|
5
|
+
"homepage": "https://github.com/GuptaSiddhant/StoryShelf#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/GuptaSiddhant/StoryShelf/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
6
10
|
"author": {
|
|
7
11
|
"name": "Siddhant Gupta",
|
|
8
12
|
"url": "https://guptasiddhant.com"
|
|
9
13
|
},
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"sideEffects": false,
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/GuptaSiddhant/
|
|
16
|
+
"url": "git+https://github.com/GuptaSiddhant/StoryShelf.git",
|
|
15
17
|
"directory": "packages/queue-sqs"
|
|
16
18
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
20
31
|
},
|
|
21
32
|
"publishConfig": {
|
|
22
|
-
"access": "public",
|
|
23
33
|
"exports": {
|
|
24
34
|
".": "./dist/index.mjs",
|
|
25
35
|
"./package.json": "./package.json"
|
|
26
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"access": "public"
|
|
27
38
|
},
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
39
|
"scripts": {
|
|
32
40
|
"build": "tsdown",
|
|
33
41
|
"dev": "tsdown -w",
|
|
34
|
-
"fmt": "oxfmt
|
|
42
|
+
"fmt": "oxfmt ./src",
|
|
35
43
|
"lint": "oxlint --type-aware --type-check ./src",
|
|
36
44
|
"test": "vitest run",
|
|
37
45
|
"prepublishOnly": "nub run build"
|
|
38
46
|
},
|
|
39
47
|
"dependencies": {
|
|
40
48
|
"@aws-sdk/client-sqs": "^3.700.0",
|
|
41
|
-
"@storyshelf/core": "
|
|
49
|
+
"@storyshelf/core": "^0.1.2"
|
|
42
50
|
},
|
|
43
51
|
"devDependencies": {
|
|
44
52
|
"@types/node": "catalog:",
|
|
45
53
|
"@vitest/coverage-v8": "catalog:",
|
|
46
54
|
"oxfmt": "catalog:",
|
|
47
55
|
"oxlint": "catalog:",
|
|
48
|
-
"
|
|
56
|
+
"oxlint-tsgolint": "catalog:",
|
|
49
57
|
"tsdown": "catalog:",
|
|
50
58
|
"typescript": "catalog:",
|
|
51
59
|
"vitest": "catalog:"
|
|
52
60
|
},
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
"jsr": {
|
|
62
|
+
"runtimeCompat": {
|
|
63
|
+
"node": true,
|
|
64
|
+
"deno": true,
|
|
65
|
+
"browser": false,
|
|
66
|
+
"workerd": false,
|
|
67
|
+
"bun": true
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
}
|