@better-media/adapter-jobs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 abenezeratnafu
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, NEGLIGENCE OR OTHER TORTIOUS
20
+ ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @better-media/adapter-jobs
2
+
3
+ Job adapters for background execution in the Better Media framework.
4
+
5
+ ## Overview
6
+
7
+ Some media pipeline steps (e.g. video transcoding, large virus scans) should not block the main request thread. This package provides:
8
+
9
+ - **In-Memory Job Adapter**: Simple FIFO queue for development or small-scale apps.
10
+ - **Hook Integration**: Automatically enqueues tasks tagged with `execution: 'background'`.
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import { InMemoryJobAdapter } from "@better-media/adapter-jobs";
16
+
17
+ const jobs = new InMemoryJobAdapter({ concurrency: 2 });
18
+ ```
19
+
20
+ Visit [better-media.dev/docs/adapters/jobs](https://better-media.dev/docs/adapters/jobs) for more.
@@ -0,0 +1,14 @@
1
+ import { JobAdapter } from '@better-media/core';
2
+
3
+ interface MemoryJobAdapterOptions {
4
+ /** When provided, jobs are run in-process via setImmediate (default for background plugins) */
5
+ processor?: (payload: Record<string, unknown>) => Promise<void>;
6
+ }
7
+ /**
8
+ * Default in-memory job adapter for development/testing.
9
+ * When processor is provided, jobs run in-process via setImmediate.
10
+ * When not provided, jobs are stored only (for manual worker polling).
11
+ */
12
+ declare function memoryJobAdapter(options?: MemoryJobAdapterOptions): JobAdapter;
13
+
14
+ export { type MemoryJobAdapterOptions, memoryJobAdapter };
@@ -0,0 +1,14 @@
1
+ import { JobAdapter } from '@better-media/core';
2
+
3
+ interface MemoryJobAdapterOptions {
4
+ /** When provided, jobs are run in-process via setImmediate (default for background plugins) */
5
+ processor?: (payload: Record<string, unknown>) => Promise<void>;
6
+ }
7
+ /**
8
+ * Default in-memory job adapter for development/testing.
9
+ * When processor is provided, jobs run in-process via setImmediate.
10
+ * When not provided, jobs are stored only (for manual worker polling).
11
+ */
12
+ declare function memoryJobAdapter(options?: MemoryJobAdapterOptions): JobAdapter;
13
+
14
+ export { type MemoryJobAdapterOptions, memoryJobAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ function memoryJobAdapter(options) {
5
+ const processor = options?.processor;
6
+ return {
7
+ async enqueue(name, payload) {
8
+ if (processor) {
9
+ setImmediate(() => {
10
+ void processor(payload);
11
+ });
12
+ }
13
+ }
14
+ };
15
+ }
16
+
17
+ exports.memoryJobAdapter = memoryJobAdapter;
18
+ //# sourceMappingURL=index.js.map
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAYO,SAAS,iBAAiB,OAAA,EAA+C;AAC9E,EAAA,MAAM,YAAY,OAAA,EAAS,SAAA;AAC3B,EAAA,OAAO;AAAA,IACL,MAAM,OAAA,CAAQ,IAAA,EAAc,OAAA,EAAkC;AAC5D,MAAA,IAAI,SAAA,EAAW;AACb,QAAA,YAAA,CAAa,MAAM;AACjB,UAAA,KAAK,UAAU,OAAO,CAAA;AAAA,QACxB,CAAC,CAAA;AAAA,MACH;AACK,IACP;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { JobAdapter } from \"@better-media/core\";\n\nexport interface MemoryJobAdapterOptions {\n /** When provided, jobs are run in-process via setImmediate (default for background plugins) */\n processor?: (payload: Record<string, unknown>) => Promise<void>;\n}\n\n/**\n * Default in-memory job adapter for development/testing.\n * When processor is provided, jobs run in-process via setImmediate.\n * When not provided, jobs are stored only (for manual worker polling).\n */\nexport function memoryJobAdapter(options?: MemoryJobAdapterOptions): JobAdapter {\n const processor = options?.processor;\n return {\n async enqueue(name: string, payload: Record<string, unknown>) {\n if (processor) {\n setImmediate(() => {\n void processor(payload);\n });\n }\n void name;\n },\n };\n}\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,17 @@
1
+ // src/index.ts
2
+ function memoryJobAdapter(options) {
3
+ const processor = options?.processor;
4
+ return {
5
+ async enqueue(name, payload) {
6
+ if (processor) {
7
+ setImmediate(() => {
8
+ void processor(payload);
9
+ });
10
+ }
11
+ }
12
+ };
13
+ }
14
+
15
+ export { memoryJobAdapter };
16
+ //# sourceMappingURL=index.mjs.map
17
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAYO,SAAS,iBAAiB,OAAA,EAA+C;AAC9E,EAAA,MAAM,YAAY,OAAA,EAAS,SAAA;AAC3B,EAAA,OAAO;AAAA,IACL,MAAM,OAAA,CAAQ,IAAA,EAAc,OAAA,EAAkC;AAC5D,MAAA,IAAI,SAAA,EAAW;AACb,QAAA,YAAA,CAAa,MAAM;AACjB,UAAA,KAAK,UAAU,OAAO,CAAA;AAAA,QACxB,CAAC,CAAA;AAAA,MACH;AACK,IACP;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["import type { JobAdapter } from \"@better-media/core\";\n\nexport interface MemoryJobAdapterOptions {\n /** When provided, jobs are run in-process via setImmediate (default for background plugins) */\n processor?: (payload: Record<string, unknown>) => Promise<void>;\n}\n\n/**\n * Default in-memory job adapter for development/testing.\n * When processor is provided, jobs run in-process via setImmediate.\n * When not provided, jobs are stored only (for manual worker polling).\n */\nexport function memoryJobAdapter(options?: MemoryJobAdapterOptions): JobAdapter {\n const processor = options?.processor;\n return {\n async enqueue(name: string, payload: Record<string, unknown>) {\n if (processor) {\n setImmediate(() => {\n void processor(payload);\n });\n }\n void name;\n },\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@better-media/adapter-jobs",
3
+ "version": "0.1.0",
4
+ "description": "Job adapter implementations for Better Media (in-memory, Redis, etc.)",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "dependencies": {
20
+ "@better-media/core": "0.1.0"
21
+ },
22
+ "keywords": [],
23
+ "author": "Abenezer Atnafu",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/AbenezerAtnafu/better-media.git"
28
+ },
29
+ "homepage": "https://better-media.dev",
30
+ "bugs": {
31
+ "url": "https://github.com/AbenezerAtnafu/better-media/issues"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "dev": "tsup --watch",
39
+ "typecheck": "tsc --noEmit",
40
+ "lint": "eslint .",
41
+ "test": "jest"
42
+ }
43
+ }