graphile-cache 4.16.4 → 4.16.6

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.
@@ -8,6 +8,7 @@ interface GraphileInstanceOptions {
8
8
  * pgServices (managed by pg-cache) rather than passed separately.
9
9
  */
10
10
  enableRealtime?: boolean;
11
+ realtimeSchema?: string;
11
12
  }
12
13
  /**
13
14
  * Create a PostGraphile v5 instance backed by grafserv/express.
@@ -33,7 +33,7 @@ const log = new logger_1.Logger('graphile-cache:create');
33
33
  * so the estimate errs towards evicting early.
34
34
  */
35
35
  const createGraphileInstance = async (opts) => {
36
- const { preset, cacheKey, enableRealtime = false } = opts;
36
+ const { preset, cacheKey, enableRealtime = false, realtimeSchema } = opts;
37
37
  const heapBefore = process.memoryUsage().heapUsed;
38
38
  const pgl = (0, postgraphile_1.postgraphile)(preset);
39
39
  const serv = pgl.createServ(v4_1.grafserv);
@@ -52,7 +52,7 @@ const createGraphileInstance = async (opts) => {
52
52
  createdAt: Date.now(),
53
53
  heapBytes,
54
54
  };
55
- if (enableRealtime) {
55
+ if (enableRealtime && realtimeSchema) {
56
56
  try {
57
57
  // Extract PgSubscriber and pool from the resolved preset's pgServices.
58
58
  // The pool is the same instance managed by pg-cache (via getPgPool)
@@ -62,17 +62,17 @@ const createGraphileInstance = async (opts) => {
62
62
  const pgSubscriber = pgService?.pgSubscriber ?? null;
63
63
  const pool = pgService?.adaptorSettings?.pool ?? null;
64
64
  if (!pgSubscriber) {
65
- log.warn(`PostGraphile[${cacheKey}] has no pgSubscriber — RealtimeManager will not be started`);
65
+ throw new Error(`PostGraphile[${cacheKey}] has no pgSubscriber for realtime`);
66
66
  }
67
67
  else if (!pool) {
68
- log.warn(`PostGraphile[${cacheKey}] has no pool in pgService — RealtimeManager will not be started`);
68
+ throw new Error(`PostGraphile[${cacheKey}] has no pool in pgService for realtime`);
69
69
  }
70
70
  else {
71
71
  const manager = new graphile_realtime_subscriptions_1.RealtimeManager({
72
72
  pgSubscriber,
73
73
  pool,
74
74
  nodeId: `graphile-cache:${cacheKey}`,
75
- schema: 'realtime_public',
75
+ schema: realtimeSchema,
76
76
  });
77
77
  await manager.start();
78
78
  entry.realtimeManager = manager;
@@ -80,7 +80,13 @@ const createGraphileInstance = async (opts) => {
80
80
  }
81
81
  }
82
82
  catch (err) {
83
- log.error(`Failed to start RealtimeManager for PostGraphile[${cacheKey}]:`, err);
83
+ try {
84
+ await pgl.release();
85
+ }
86
+ catch (cleanupError) {
87
+ throw new AggregateError([err, cleanupError], `Realtime startup and cleanup failed for PostGraphile[${cacheKey}]`);
88
+ }
89
+ throw err;
84
90
  }
85
91
  }
86
92
  return entry;
@@ -27,7 +27,7 @@ const log = new Logger('graphile-cache:create');
27
27
  * so the estimate errs towards evicting early.
28
28
  */
29
29
  export const createGraphileInstance = async (opts) => {
30
- const { preset, cacheKey, enableRealtime = false } = opts;
30
+ const { preset, cacheKey, enableRealtime = false, realtimeSchema } = opts;
31
31
  const heapBefore = process.memoryUsage().heapUsed;
32
32
  const pgl = postgraphile(preset);
33
33
  const serv = pgl.createServ(grafserv);
@@ -46,7 +46,7 @@ export const createGraphileInstance = async (opts) => {
46
46
  createdAt: Date.now(),
47
47
  heapBytes,
48
48
  };
49
- if (enableRealtime) {
49
+ if (enableRealtime && realtimeSchema) {
50
50
  try {
51
51
  // Extract PgSubscriber and pool from the resolved preset's pgServices.
52
52
  // The pool is the same instance managed by pg-cache (via getPgPool)
@@ -56,17 +56,17 @@ export const createGraphileInstance = async (opts) => {
56
56
  const pgSubscriber = pgService?.pgSubscriber ?? null;
57
57
  const pool = pgService?.adaptorSettings?.pool ?? null;
58
58
  if (!pgSubscriber) {
59
- log.warn(`PostGraphile[${cacheKey}] has no pgSubscriber — RealtimeManager will not be started`);
59
+ throw new Error(`PostGraphile[${cacheKey}] has no pgSubscriber for realtime`);
60
60
  }
61
61
  else if (!pool) {
62
- log.warn(`PostGraphile[${cacheKey}] has no pool in pgService — RealtimeManager will not be started`);
62
+ throw new Error(`PostGraphile[${cacheKey}] has no pool in pgService for realtime`);
63
63
  }
64
64
  else {
65
65
  const manager = new RealtimeManager({
66
66
  pgSubscriber,
67
67
  pool,
68
68
  nodeId: `graphile-cache:${cacheKey}`,
69
- schema: 'realtime_public',
69
+ schema: realtimeSchema,
70
70
  });
71
71
  await manager.start();
72
72
  entry.realtimeManager = manager;
@@ -74,7 +74,13 @@ export const createGraphileInstance = async (opts) => {
74
74
  }
75
75
  }
76
76
  catch (err) {
77
- log.error(`Failed to start RealtimeManager for PostGraphile[${cacheKey}]:`, err);
77
+ try {
78
+ await pgl.release();
79
+ }
80
+ catch (cleanupError) {
81
+ throw new AggregateError([err, cleanupError], `Realtime startup and cleanup failed for PostGraphile[${cacheKey}]`);
82
+ }
83
+ throw err;
78
84
  }
79
85
  }
80
86
  return entry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-cache",
3
- "version": "4.16.4",
3
+ "version": "4.16.6",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostGraphile v5 LRU cache with automatic pool cleanup integration",
6
6
  "main": "index.js",
@@ -19,24 +19,15 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/constructive-io/constructive/issues"
21
21
  },
22
- "scripts": {
23
- "clean": "makage clean",
24
- "prepack": "npm run build",
25
- "build": "makage build",
26
- "build:dev": "makage build --dev",
27
- "lint": "eslint . --fix",
28
- "test": "jest --passWithNoTests",
29
- "test:watch": "jest --watch"
30
- },
31
22
  "dependencies": {
32
- "12factor-env": "^1.34.0",
33
- "@pgpmjs/logger": "^2.27.0",
34
23
  "express": "^5.2.1",
35
24
  "grafserv": "1.0.1",
36
- "graphile-realtime-subscriptions": "^1.13.0",
37
25
  "lru-cache": "^11.2.7",
38
- "pg-cache": "^3.30.3",
39
- "postgraphile": "5.1.4"
26
+ "postgraphile": "5.1.4",
27
+ "@pgpmjs/logger": "^2.27.1",
28
+ "graphile-realtime-subscriptions": "^1.13.2",
29
+ "12factor-env": "^1.34.1",
30
+ "pg-cache": "^3.30.4"
40
31
  },
41
32
  "devDependencies": {
42
33
  "@types/express": "^5.0.6",
@@ -53,5 +44,12 @@
53
44
  "constructive",
54
45
  "v5"
55
46
  ],
56
- "gitHead": "a6b53ff76945ce3542e5e20a61980d74a727e877"
57
- }
47
+ "scripts": {
48
+ "clean": "makage clean",
49
+ "build": "makage build",
50
+ "build:dev": "makage build --dev",
51
+ "lint": "eslint . --fix",
52
+ "test": "jest --passWithNoTests",
53
+ "test:watch": "jest --watch"
54
+ }
55
+ }