@cnstra/pg-boss 0.3.0 → 0.6.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/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@cnstra/pg-boss",
3
- "version": "0.3.0",
3
+ "version": "0.6.0",
4
4
  "description": "pg-boss (Postgres) integration for CNStra: run stimulations as jobs and stream per-hop progress",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/abaikov/cnstra.git",
8
+ "directory": "packages/pg-boss"
9
+ },
5
10
  "keywords": [
6
11
  "cnstra",
7
12
  "pg-boss",
@@ -33,26 +38,27 @@
33
38
  "dist"
34
39
  ],
35
40
  "scripts": {
41
+ "prepublishOnly": "node ../../scripts/check-drift.mjs --gate",
36
42
  "build": "tsup",
37
43
  "test": "jest",
38
44
  "test:types": "tsc --noEmit",
39
45
  "clean": "rm -rf dist"
40
46
  },
41
47
  "dependencies": {
42
- "@cnstra/types": "^0.1.0",
43
- "@cnstra/broker": "^0.1.0"
48
+ "@cnstra/types": "^0.2.0",
49
+ "@cnstra/broker": "^0.2.0"
44
50
  },
45
51
  "peerDependencies": {
46
- "@cnstra/core": "^2.4.0",
47
- "@cnstra/persist": "^0.1.0",
48
- "@cnstra/persist-dto": "^0.1.0",
52
+ "@cnstra/core": "^3.0.0",
53
+ "@cnstra/persist": "^0.2.0",
54
+ "@cnstra/persist-dto": "^0.2.0",
49
55
  "pg-boss": ">=9",
50
56
  "pg": ">=8"
51
57
  },
52
58
  "devDependencies": {
53
- "@cnstra/core": "^2.4.0",
54
- "@cnstra/persist": "^0.1.0",
55
- "@cnstra/persist-dto": "^0.1.0",
59
+ "@cnstra/core": "^3.0.0",
60
+ "@cnstra/persist": "^0.2.0",
61
+ "@cnstra/persist-dto": "^0.2.0",
56
62
  "@types/jest": "29.5.12",
57
63
  "@types/pg": "^8.11.0",
58
64
  "jest": "29.7.0",
@@ -60,7 +66,8 @@
60
66
  "ts-jest": "29.1.2",
61
67
  "tsup": "8.5.1",
62
68
  "typescript": "5.7.2",
63
- "@cnstra/broker": "^0.1.0"
69
+ "@cnstra/broker": "^0.2.0",
70
+ "@cnstra/postgres-schema": "0.1.0"
64
71
  },
65
72
  "peerDependenciesMeta": {
66
73
  "pg-boss": {
@@ -1,35 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-2JTKI4GS.mjs";
4
-
5
- // src/migrate.ts
6
- var DEFAULT_TABLE = "cns_pgboss_progress";
7
- function assertSafeTable(table) {
8
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(table)) {
9
- throw new Error(`[@cnstra/pg-boss] unsafe progress table name: ${JSON.stringify(table)}`);
10
- }
11
- return table;
12
- }
13
- __name(assertSafeTable, "assertSafeTable");
14
- function pgBossProgressSchemaSql(table = DEFAULT_TABLE) {
15
- assertSafeTable(table);
16
- return `CREATE TABLE IF NOT EXISTS ${table} (
17
- key text PRIMARY KEY,
18
- progress jsonb NOT NULL,
19
- updated_at timestamptz NOT NULL DEFAULT now()
20
- );
21
- CREATE INDEX IF NOT EXISTS ${table}_updated_idx ON ${table} (updated_at)`;
22
- }
23
- __name(pgBossProgressSchemaSql, "pgBossProgressSchemaSql");
24
- async function ensureSchema(db, table = DEFAULT_TABLE) {
25
- await db.query(pgBossProgressSchemaSql(table));
26
- }
27
- __name(ensureSchema, "ensureSchema");
28
-
29
- export {
30
- DEFAULT_TABLE,
31
- assertSafeTable,
32
- pgBossProgressSchemaSql,
33
- ensureSchema
34
- };
35
- //# sourceMappingURL=chunk-XJFC72LU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["/**\n * Schema / migrations for the pg-boss progress table (`cns_pgboss_progress`).\n *\n * The package OWNS this schema so you can manage it explicitly (a migration step in\n * your own tooling) instead of relying on the repository's lazy auto-create. Run it\n * via the `cnstra-pgboss-progress migrate` CLI, or call `ensureSchema(db)` yourself\n * with any pg client/pool.\n */\n\n/** Minimal pg client surface (a `pg` Pool or Client satisfies it). */\nexport interface IPgQueryable {\n query(text: string, params?: unknown[]): Promise<{ rows: unknown[] }>;\n}\n\nexport const DEFAULT_TABLE = 'cns_pgboss_progress';\n\n/** Guard the table identifier (it is interpolated into DDL/DML, not parameterised). */\nexport function assertSafeTable(table: string): string {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(table)) {\n throw new Error(\n `[@cnstra/pg-boss] unsafe progress table name: ${JSON.stringify(table)}`\n );\n }\n return table;\n}\n\n/** The CREATE TABLE for the progress store. One upserted row per key (job id). */\nexport function pgBossProgressSchemaSql(table: string = DEFAULT_TABLE): string {\n assertSafeTable(table);\n // `updated_at` + its index back `deleteStale()`: a row is deleted when its job\n // succeeds, but a job that fails PERMANENTLY (retries exhausted) leaves its row —\n // pg-boss has no terminal-failure hook to key off. Pruning by staleness collects\n // those, and the index keeps the sweep cheap.\n return `CREATE TABLE IF NOT EXISTS ${table} (\n key text PRIMARY KEY,\n progress jsonb NOT NULL,\n updated_at timestamptz NOT NULL DEFAULT now()\n);\nCREATE INDEX IF NOT EXISTS ${table}_updated_idx ON ${table} (updated_at)`;\n}\n\n/** Idempotently create the progress table. Safe to run repeatedly. */\nexport async function ensureSchema(\n db: IPgQueryable,\n table: string = DEFAULT_TABLE\n): Promise<void> {\n await db.query(pgBossProgressSchemaSql(table));\n}\n"],"mappings":";;;;;AAcO,IAAMA,gBAAgB;AAGtB,SAASC,gBAAgBC,OAAa;AACzC,MAAI,CAAC,2BAA2BC,KAAKD,KAAAA,GAAQ;AACzC,UAAM,IAAIE,MACN,iDAAiDC,KAAKC,UAAUJ,KAAAA,CAAAA,EAAQ;EAEhF;AACA,SAAOA;AACX;AAPgBD;AAUT,SAASM,wBAAwBL,QAAgBF,eAAa;AACjEC,kBAAgBC,KAAAA;AAKhB,SAAO,8BAA8BA,KAAAA;;;;;6BAKZA,KAAAA,mBAAwBA,KAAAA;AACrD;AAZgBK;AAehB,eAAsBC,aAClBC,IACAP,QAAgBF,eAAa;AAE7B,QAAMS,GAAGC,MAAMH,wBAAwBL,KAAAA,CAAAA;AAC3C;AALsBM;","names":["DEFAULT_TABLE","assertSafeTable","table","test","Error","JSON","stringify","pgBossProgressSchemaSql","ensureSchema","db","query"]}