@constructive-io/knative-job-server 0.4.0 → 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.
package/README.md CHANGED
@@ -1 +1,59 @@
1
1
  # knative-job-server
2
+
3
+ ---
4
+
5
+ ## Education and Tutorials
6
+
7
+ 1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
8
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
9
+
10
+ 2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
11
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
12
+
13
+ 3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
14
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
15
+
16
+ 4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
17
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
18
+
19
+ 5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
20
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
21
+
22
+ 6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
23
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
24
+
25
+ 7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
26
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
27
+
28
+ ## Related Constructive Tooling
29
+
30
+ ### 📦 Package Management
31
+
32
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
33
+
34
+ ### 🧪 Testing
35
+
36
+ * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
37
+ * [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
38
+ * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
39
+ * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
40
+ * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
41
+
42
+ ### 🧠 Parsing & AST
43
+
44
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
45
+ * [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
46
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
47
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
48
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
49
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
50
+
51
+ ## Credits
52
+
53
+ **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
54
+
55
+ ## Disclaimer
56
+
57
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
58
+
59
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/esm/index.js ADDED
@@ -0,0 +1,76 @@
1
+ import express from 'express';
2
+ import bodyParser from 'body-parser';
3
+ import * as jobs from '@constructive-io/job-utils';
4
+ import poolManager from '@constructive-io/job-pg';
5
+ import { createLogger } from '@pgpmjs/logger';
6
+ const logger = createLogger('knative-job-server');
7
+ export default (pgPool = poolManager.getPool()) => {
8
+ const app = express();
9
+ app.use(bodyParser.json());
10
+ const withClient = (cb) => async (req, res, next) => {
11
+ const client = (await pgPool.connect());
12
+ try {
13
+ await cb(client, req, res, next);
14
+ }
15
+ catch (e) {
16
+ next(e);
17
+ }
18
+ finally {
19
+ client.release();
20
+ }
21
+ };
22
+ const complete = withClient(async (client, req, res) => {
23
+ const workerId = req.get('X-Worker-Id');
24
+ const jobIdHeader = req.get('X-Job-Id');
25
+ if (!workerId || !jobIdHeader) {
26
+ logger.warn('missing worker/job headers on completion callback', { workerId, jobIdHeader });
27
+ res.status(400).json({ error: 'Missing X-Worker-Id or X-Job-Id header' });
28
+ return;
29
+ }
30
+ logger.info(`Completed task ${jobIdHeader} with success`);
31
+ await jobs.completeJob(client, { workerId, jobId: jobIdHeader });
32
+ res
33
+ .set({
34
+ 'Content-Type': 'application/json'
35
+ })
36
+ .status(200)
37
+ .send({ workerId, jobId: jobIdHeader });
38
+ });
39
+ const fail = withClient(async (client, req, res) => {
40
+ const workerId = req.get('X-Worker-Id');
41
+ const jobIdHeader = req.get('X-Job-Id');
42
+ if (!workerId || !jobIdHeader) {
43
+ logger.warn('missing worker/job headers on failure callback', { workerId, jobIdHeader });
44
+ res.status(400).json({ error: 'Missing X-Worker-Id or X-Job-Id header' });
45
+ return;
46
+ }
47
+ const errorMessage = req.body.error || req.body.message || 'UNKNOWN_ERROR';
48
+ logger.error(`Failed task ${jobIdHeader} with error: \n${errorMessage}\n\n`);
49
+ await jobs.failJob(client, {
50
+ workerId,
51
+ jobId: jobIdHeader,
52
+ message: errorMessage
53
+ });
54
+ res.status(200).json({ workerId, jobId: jobIdHeader });
55
+ });
56
+ app.post('/callback', async (req, res, next) => {
57
+ const jobId = req.get('X-Job-Id');
58
+ if (typeof jobId === 'undefined') {
59
+ logger.warn('undefined JOB, what is this? healthcheck?');
60
+ logger.debug(req.url);
61
+ logger.debug(req.originalUrl);
62
+ return res.status(200).json('OK');
63
+ }
64
+ if (req.get('X-Job-Error') === 'true') {
65
+ await fail(req, res, next);
66
+ }
67
+ else {
68
+ await complete(req, res, next);
69
+ }
70
+ });
71
+ app.use((error, req, res, next) => {
72
+ // TODO check headers for jobId and call fail?
73
+ res.status(500).json({ error });
74
+ });
75
+ return app;
76
+ };
@@ -1,14 +1,11 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  import server from './index';
4
3
  import poolManager from '@constructive-io/job-pg';
5
4
  import { getJobsCallbackPort } from '@constructive-io/job-utils';
6
5
  import { createLogger } from '@pgpmjs/logger';
7
-
8
6
  const logger = createLogger('knative-job-server');
9
7
  const pgPool = poolManager.getPool();
10
8
  const port = getJobsCallbackPort();
11
-
12
9
  server(pgPool).listen(port, () => {
13
- logger.info(`listening ON ${port}`);
10
+ logger.info(`listening ON ${port}`);
14
11
  });
package/package.json CHANGED
@@ -1,20 +1,23 @@
1
1
  {
2
2
  "name": "@constructive-io/knative-job-server",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "knative job server",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/jobs/tree/master/packages/knative-job-server#readme",
7
7
  "license": "SEE LICENSE IN LICENSE",
8
- "main": "dist/index.js",
8
+ "main": "index.js",
9
+ "module": "esm/index.js",
10
+ "types": "index.d.ts",
9
11
  "directories": {
10
12
  "lib": "src",
11
13
  "test": "__tests__"
12
14
  },
13
15
  "bin": {
14
- "faas-job-server": "src/run.ts"
16
+ "faas-job-server": "run.js"
15
17
  },
16
18
  "publishConfig": {
17
- "access": "public"
19
+ "access": "public",
20
+ "directory": "dist"
18
21
  },
19
22
  "repository": {
20
23
  "type": "git",
@@ -24,19 +27,24 @@
24
27
  "test": "jest --passWithNoTests",
25
28
  "test:watch": "jest --watch",
26
29
  "test:debug": "node --inspect node_modules/.bin/jest --runInBand",
27
- "build": "tsc -p tsconfig.json",
28
- "build:watch": "tsc -p tsconfig.json -w"
30
+ "clean": "makage clean",
31
+ "prepack": "npm run build",
32
+ "build": "makage build",
33
+ "build:dev": "makage build --dev"
29
34
  },
30
35
  "bugs": {
31
36
  "url": "https://github.com/constructive-io/jobs/issues"
32
37
  },
38
+ "devDependencies": {
39
+ "makage": "^0.1.10"
40
+ },
33
41
  "dependencies": {
34
- "@constructive-io/job-pg": "^0.4.0",
35
- "@constructive-io/job-utils": "^0.6.0",
36
- "@pgpmjs/logger": "^1.4.0",
42
+ "@constructive-io/job-pg": "^0.5.0",
43
+ "@constructive-io/job-utils": "^0.7.0",
44
+ "@pgpmjs/logger": "^1.5.0",
37
45
  "body-parser": "1.19.0",
38
46
  "express": "5.2.1",
39
- "pg": "8.16.3"
47
+ "pg": "8.17.1"
40
48
  },
41
- "gitHead": "481b3a50b4eec2da6b376c4cd1868065e1e28edb"
49
+ "gitHead": "ec2b5f644c479626305ef85a05a6e7105c2c58cd"
42
50
  }
package/CHANGELOG.md DELETED
@@ -1,88 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [0.4.0](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.25...@constructive-io/knative-job-server@0.4.0) (2026-01-18)
7
-
8
- **Note:** Version bump only for package @constructive-io/knative-job-server
9
-
10
- ## [0.3.25](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.24...@constructive-io/knative-job-server@0.3.25) (2026-01-18)
11
-
12
- **Note:** Version bump only for package @constructive-io/knative-job-server
13
-
14
- ## [0.3.24](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.23...@constructive-io/knative-job-server@0.3.24) (2026-01-09)
15
-
16
- **Note:** Version bump only for package @constructive-io/knative-job-server
17
-
18
- ## [0.3.23](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.22...@constructive-io/knative-job-server@0.3.23) (2026-01-07)
19
-
20
- **Note:** Version bump only for package @constructive-io/knative-job-server
21
-
22
- ## [0.3.22](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.21...@constructive-io/knative-job-server@0.3.22) (2026-01-02)
23
-
24
- **Note:** Version bump only for package @constructive-io/knative-job-server
25
-
26
- ## [0.3.21](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.20...@constructive-io/knative-job-server@0.3.21) (2026-01-02)
27
-
28
- **Note:** Version bump only for package @constructive-io/knative-job-server
29
-
30
- ## [0.3.20](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.19...@constructive-io/knative-job-server@0.3.20) (2025-12-31)
31
-
32
- **Note:** Version bump only for package @constructive-io/knative-job-server
33
-
34
- ## [0.3.19](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.18...@constructive-io/knative-job-server@0.3.19) (2025-12-31)
35
-
36
- **Note:** Version bump only for package @constructive-io/knative-job-server
37
-
38
- ## [0.3.18](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.17...@constructive-io/knative-job-server@0.3.18) (2025-12-27)
39
-
40
- **Note:** Version bump only for package @constructive-io/knative-job-server
41
-
42
- ## [0.3.17](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.16...@constructive-io/knative-job-server@0.3.17) (2025-12-26)
43
-
44
- **Note:** Version bump only for package @constructive-io/knative-job-server
45
-
46
- ## [0.3.16](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.15...@constructive-io/knative-job-server@0.3.16) (2025-12-26)
47
-
48
- **Note:** Version bump only for package @constructive-io/knative-job-server
49
-
50
- ## [0.3.15](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.14...@constructive-io/knative-job-server@0.3.15) (2025-12-26)
51
-
52
- **Note:** Version bump only for package @constructive-io/knative-job-server
53
-
54
- ## [0.3.14](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.13...@constructive-io/knative-job-server@0.3.14) (2025-12-25)
55
-
56
- **Note:** Version bump only for package @constructive-io/knative-job-server
57
-
58
- ## [0.3.13](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.12...@constructive-io/knative-job-server@0.3.13) (2025-12-24)
59
-
60
- **Note:** Version bump only for package @constructive-io/knative-job-server
61
-
62
- ## [0.3.12](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.11...@constructive-io/knative-job-server@0.3.12) (2025-12-23)
63
-
64
- **Note:** Version bump only for package @constructive-io/knative-job-server
65
-
66
- ## [0.3.11](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.10...@constructive-io/knative-job-server@0.3.11) (2025-12-22)
67
-
68
- **Note:** Version bump only for package @constructive-io/knative-job-server
69
-
70
- ## [0.3.10](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.9...@constructive-io/knative-job-server@0.3.10) (2025-12-22)
71
-
72
- **Note:** Version bump only for package @constructive-io/knative-job-server
73
-
74
- ## [0.3.9](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.8...@constructive-io/knative-job-server@0.3.9) (2025-12-21)
75
-
76
- **Note:** Version bump only for package @constructive-io/knative-job-server
77
-
78
- ## [0.3.8](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.7...@constructive-io/knative-job-server@0.3.8) (2025-12-19)
79
-
80
- **Note:** Version bump only for package @constructive-io/knative-job-server
81
-
82
- ## 0.3.7 (2025-12-18)
83
-
84
- **Note:** Version bump only for package @constructive-io/knative-job-server
85
-
86
- ## [0.3.6](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-server@0.3.5...@constructive-io/knative-job-server@0.3.6) (2025-12-17)
87
-
88
- **Note:** Version bump only for package @constructive-io/knative-job-server
package/jest.config.js DELETED
@@ -1,18 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- transform: {
6
- '^.+\\.tsx?$': [
7
- 'ts-jest',
8
- {
9
- babelConfig: false,
10
- tsconfig: 'tsconfig.json',
11
- },
12
- ],
13
- },
14
- transformIgnorePatterns: [`/node_modules/*`],
15
- testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
16
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
17
- modulePathIgnorePatterns: ['dist/*'],
18
- };
package/src/index.ts DELETED
@@ -1,130 +0,0 @@
1
- import express from 'express';
2
- import bodyParser from 'body-parser';
3
- import type { Pool, PoolClient } from 'pg';
4
- import * as jobs from '@constructive-io/job-utils';
5
- import poolManager from '@constructive-io/job-pg';
6
- import { createLogger } from '@pgpmjs/logger';
7
-
8
- type JobRequestBody = {
9
- message?: string;
10
- error?: string;
11
- // allow additional fields without typing everything
12
- [key: string]: unknown;
13
- };
14
-
15
- type JobRequest = {
16
- get(name: string): string | undefined;
17
- body: JobRequestBody;
18
- url: string;
19
- originalUrl: string;
20
- };
21
-
22
- type JobResponse = {
23
- set(headers: Record<string, string>): JobResponse;
24
- status(code: number): JobResponse;
25
- json(body: unknown): JobResponse;
26
- send(body: unknown): JobResponse;
27
- };
28
-
29
- type NextFn = (err?: unknown) => void;
30
-
31
- type WithClientHandler = (
32
- client: PoolClient,
33
- req: JobRequest,
34
- res: JobResponse,
35
- next: NextFn
36
- ) => Promise<void>;
37
-
38
- const logger = createLogger('knative-job-server');
39
-
40
- export default (pgPool: Pool = poolManager.getPool()) => {
41
- const app = express();
42
- app.use(bodyParser.json());
43
-
44
- const withClient =
45
- (cb: WithClientHandler) =>
46
- async (req: JobRequest, res: JobResponse, next: NextFn) => {
47
- const client = (await pgPool.connect()) as PoolClient;
48
- try {
49
- await cb(client as PoolClient, req, res, next);
50
- } catch (e) {
51
- next(e);
52
- } finally {
53
- client.release();
54
- }
55
- };
56
-
57
- const complete = withClient(async (client, req, res) => {
58
- const workerId = req.get('X-Worker-Id');
59
- const jobIdHeader = req.get('X-Job-Id');
60
-
61
- if (!workerId || !jobIdHeader) {
62
- logger.warn('missing worker/job headers on completion callback',
63
- { workerId, jobIdHeader }
64
- );
65
- res.status(400).json({ error: 'Missing X-Worker-Id or X-Job-Id header' });
66
- return;
67
- }
68
-
69
- logger.info(`Completed task ${jobIdHeader} with success`);
70
- await jobs.completeJob(client, { workerId, jobId: jobIdHeader });
71
-
72
- res
73
- .set({
74
- 'Content-Type': 'application/json'
75
- })
76
- .status(200)
77
- .send({ workerId, jobId: jobIdHeader });
78
- });
79
-
80
- const fail = withClient(async (client, req, res) => {
81
- const workerId = req.get('X-Worker-Id');
82
- const jobIdHeader = req.get('X-Job-Id');
83
-
84
- if (!workerId || !jobIdHeader) {
85
- logger.warn('missing worker/job headers on failure callback',
86
- { workerId, jobIdHeader }
87
- );
88
- res.status(400).json({ error: 'Missing X-Worker-Id or X-Job-Id header' });
89
- return;
90
- }
91
-
92
- const errorMessage = req.body.error || req.body.message || 'UNKNOWN_ERROR';
93
-
94
- logger.error(
95
- `Failed task ${jobIdHeader} with error: \n${errorMessage}\n\n`
96
- );
97
-
98
- await jobs.failJob(client, {
99
- workerId,
100
- jobId: jobIdHeader,
101
- message: errorMessage
102
- });
103
-
104
- res.status(200).json({ workerId, jobId: jobIdHeader });
105
- });
106
-
107
- app.post('/callback', async (req: JobRequest, res: JobResponse, next: NextFn) => {
108
- const jobId = req.get('X-Job-Id');
109
-
110
- if (typeof jobId === 'undefined') {
111
- logger.warn('undefined JOB, what is this? healthcheck?');
112
- logger.debug(req.url);
113
- logger.debug(req.originalUrl);
114
- return res.status(200).json('OK');
115
- }
116
-
117
- if (req.get('X-Job-Error') === 'true') {
118
- await fail(req, res, next);
119
- } else {
120
- await complete(req, res, next);
121
- }
122
- });
123
-
124
- app.use((error: unknown, req: JobRequest, res: JobResponse, next: NextFn) => {
125
- // TODO check headers for jobId and call fail?
126
- res.status(500).json({ error });
127
- });
128
-
129
- return app;
130
- };
package/tsconfig.esm.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "dist/esm",
5
- "module": "es2022",
6
- "rootDir": "src/",
7
- "declaration": false
8
- }
9
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src/"
6
- },
7
- "include": ["src/**/*.ts", "../../types/**/*.d.ts"],
8
- "exclude": ["dist", "node_modules", "**/*.spec.*", "**/*.test.*"]
9
- }
File without changes
File without changes
File without changes
File without changes