graphile-cache 1.0.0 → 1.0.1

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
@@ -41,11 +41,11 @@ When you import this package, it automatically registers a cleanup callback with
41
41
 
42
42
  ```typescript
43
43
  import { graphileCache, GraphileCache } from 'graphile-cache';
44
- import { getRootPgPool } from 'pg-cache';
44
+ import { getPgPool } from 'pg-cache';
45
45
  import { postgraphile } from 'postgraphile';
46
46
 
47
47
  // Create a PostGraphile instance
48
- const pgPool = getRootPgPool({ database: 'mydb' });
48
+ const pgPool = getPgPool({ database: 'mydb' });
49
49
  const handler = postgraphile(pgPool, 'public', {
50
50
  // PostGraphile options
51
51
  });
@@ -90,7 +90,7 @@ console.log(graphileCache.has('mydb.private')); // false
90
90
 
91
91
  ```typescript
92
92
  import { graphileCache, GraphileCache } from 'graphile-cache';
93
- import { getRootPgPool } from 'pg-cache';
93
+ import { getPgPool } from 'pg-cache';
94
94
  import { postgraphile } from 'postgraphile';
95
95
 
96
96
  function getGraphileInstance(database: string, schema: string): GraphileCache {
@@ -103,7 +103,7 @@ function getGraphileInstance(database: string, schema: string): GraphileCache {
103
103
  }
104
104
 
105
105
  // Create new instance
106
- const pgPool = getRootPgPool({ database });
106
+ const pgPool = getPgPool({ database });
107
107
  const handler = postgraphile(pgPool, schema, {
108
108
  graphqlRoute: '/graphql',
109
109
  graphiqlRoute: '/graphiql',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-cache",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "PostGraphile LRU cache with automatic pool cleanup integration",
6
6
  "main": "index.js",
@@ -30,10 +30,10 @@
30
30
  "test:watch": "jest --watch"
31
31
  },
32
32
  "dependencies": {
33
- "@launchql/logger": "^1.0.0",
34
- "pg-cache": "^1.0.0",
33
+ "@launchql/logger": "^1.0.1",
35
34
  "lru-cache": "^11.1.0",
36
35
  "pg": "^8.16.0",
36
+ "pg-cache": "^1.0.1",
37
37
  "postgraphile": "^4.14.1"
38
38
  },
39
39
  "devDependencies": {
@@ -49,5 +49,6 @@
49
49
  "lru",
50
50
  "postgresql",
51
51
  "launchql"
52
- ]
52
+ ],
53
+ "gitHead": "835a2e84ed84edab5bea8f5954d9dfeb657beb03"
53
54
  }
package/dist/README.md DELETED
@@ -1,226 +0,0 @@
1
- # graphile-cache
2
-
3
- <p align="center" width="100%">
4
- <img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" />
5
- </p>
6
-
7
- <p align="center" width="100%">
8
- <a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml">
9
- <img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" />
10
- </a>
11
- <a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
12
- <a href="https://www.npmjs.com/package/graphile-cache"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fgraphile-cache%2Fpackage.json"/></a>
13
- </p>
14
-
15
-
16
- PostGraphile instance LRU cache with automatic cleanup when PostgreSQL pools are disposed.
17
-
18
- ## Installation
19
-
20
- ```bash
21
- npm install graphile-cache pg-cache
22
- ```
23
-
24
- Note: This package depends on `pg-cache` for the PostgreSQL pool management.
25
-
26
- ## Features
27
-
28
- - LRU cache for PostGraphile instances
29
- - Automatic cleanup when associated PostgreSQL pools are disposed
30
- - Integrates seamlessly with `pg-cache`
31
- - Service cache re-exported for convenience
32
- - TypeScript support
33
-
34
- ## How It Works
35
-
36
- When you import this package, it automatically registers a cleanup callback with `pg-cache`. When a PostgreSQL pool is disposed, any PostGraphile instances using that pool are automatically removed from the cache.
37
-
38
- ## Usage
39
-
40
- ### Basic Usage
41
-
42
- ```typescript
43
- import { graphileCache, GraphileCache } from 'graphile-cache';
44
- import { getRootPgPool } from 'pg-cache';
45
- import { postgraphile } from 'postgraphile';
46
-
47
- // Create a PostGraphile instance
48
- const pgPool = getRootPgPool({ database: 'mydb' });
49
- const handler = postgraphile(pgPool, 'public', {
50
- // PostGraphile options
51
- });
52
-
53
- // Cache it
54
- const cacheEntry: GraphileCache = {
55
- pgPool,
56
- pgPoolKey: 'mydb',
57
- handler
58
- };
59
-
60
- graphileCache.set('mydb.public', cacheEntry);
61
-
62
- // Retrieve it later
63
- const cached = graphileCache.get('mydb.public');
64
- if (cached) {
65
- // Use cached.handler
66
- }
67
- ```
68
-
69
- ### Automatic Cleanup
70
-
71
- The cleanup happens automatically:
72
-
73
- ```typescript
74
- import { pgCache } from 'pg-cache';
75
- import { graphileCache } from 'graphile-cache';
76
-
77
- // Add entries
78
- graphileCache.set('mydb.public', { pgPoolKey: 'mydb', ... });
79
- graphileCache.set('mydb.private', { pgPoolKey: 'mydb', ... });
80
-
81
- // When the pool is removed...
82
- pgCache.delete('mydb');
83
-
84
- // Both graphile entries are automatically cleaned up!
85
- console.log(graphileCache.has('mydb.public')); // false
86
- console.log(graphileCache.has('mydb.private')); // false
87
- ```
88
-
89
- ### Complete Example
90
-
91
- ```typescript
92
- import { graphileCache, GraphileCache } from 'graphile-cache';
93
- import { getRootPgPool } from 'pg-cache';
94
- import { postgraphile } from 'postgraphile';
95
-
96
- function getGraphileInstance(database: string, schema: string): GraphileCache {
97
- const key = `${database}.${schema}`;
98
-
99
- // Check cache first
100
- const cached = graphileCache.get(key);
101
- if (cached) {
102
- return cached;
103
- }
104
-
105
- // Create new instance
106
- const pgPool = getRootPgPool({ database });
107
- const handler = postgraphile(pgPool, schema, {
108
- graphqlRoute: '/graphql',
109
- graphiqlRoute: '/graphiql',
110
- // other options...
111
- });
112
-
113
- const entry: GraphileCache = {
114
- pgPool,
115
- pgPoolKey: database,
116
- handler
117
- };
118
-
119
- // Cache it
120
- graphileCache.set(key, entry);
121
- return entry;
122
- }
123
-
124
- // Use in Express
125
- app.use((req, res, next) => {
126
- const { handler } = getGraphileInstance('mydb', 'public');
127
- handler(req, res, next);
128
- });
129
- ```
130
-
131
- ### Graceful Shutdown
132
-
133
- ```typescript
134
- import { closeAllCaches } from 'graphile-cache';
135
-
136
- // This closes all caches including pg pools
137
- process.on('SIGTERM', async () => {
138
- await closeAllCaches();
139
- process.exit(0);
140
- });
141
- ```
142
-
143
- ## API Reference
144
-
145
- ### graphileCache
146
-
147
- The main PostGraphile instance cache.
148
-
149
- - `get(key: string): GraphileCache | undefined` - Get a cached instance
150
- - `set(key: string, value: GraphileCache): void` - Cache an instance
151
- - `has(key: string): boolean` - Check if an instance is cached
152
- - `delete(key: string): void` - Remove an instance
153
- - `clear(): void` - Remove all instances
154
-
155
- ### GraphileCache Interface
156
-
157
- ```typescript
158
- interface GraphileCache {
159
- pgPool: pg.Pool;
160
- pgPoolKey: string;
161
- handler: HttpRequestHandler;
162
- }
163
- ```
164
-
165
- ### closeAllCaches()
166
-
167
- Closes all caches including the service cache, graphile cache, and all PostgreSQL pools.
168
-
169
- ### svcCache
170
-
171
- Re-exported from `pg-cache` for convenience.
172
-
173
- ## Integration Details
174
-
175
- The integration with `pg-cache` happens automatically when this module is imported. The cleanup callback is registered immediately, ensuring that PostGraphile instances are cleaned up whenever their associated PostgreSQL pools are disposed.
176
-
177
- This design ensures:
178
- - No memory leaks from orphaned PostGraphile instances
179
- - Automatic cleanup without manual intervention
180
- - Loose coupling between packages
181
-
182
- ## Related LaunchQL Tooling
183
-
184
- ### 🧪 Testing
185
-
186
- * [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
187
- * [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
188
- * [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/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.
189
-
190
- ### 🧠 Parsing & AST
191
-
192
- * [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
193
- * [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
194
- * [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
195
- * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
196
- * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
197
- * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
198
- * [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
199
-
200
- ### 🚀 API & Dev Tools
201
-
202
- * [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
203
- * [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
204
-
205
- ### 🔁 Streaming & Uploads
206
-
207
- * [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
208
- * [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
209
- * [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
210
- * [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
211
- * [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
212
- * [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
213
-
214
- ### 🧰 CLI & Codegen
215
-
216
- * [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
217
- * [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
218
- * [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
219
- * [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
220
-
221
- ## Disclaimer
222
-
223
- AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
224
-
225
- 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.
226
-
package/dist/package.json DELETED
@@ -1,53 +0,0 @@
1
- {
2
- "name": "graphile-cache",
3
- "version": "1.0.0",
4
- "author": "Dan Lynch <pyramation@gmail.com>",
5
- "description": "PostGraphile LRU cache with automatic pool cleanup integration",
6
- "main": "index.js",
7
- "module": "esm/index.js",
8
- "types": "index.d.ts",
9
- "homepage": "https://github.com/launchql/launchql",
10
- "license": "MIT",
11
- "publishConfig": {
12
- "access": "public",
13
- "directory": "dist"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/launchql/launchql"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/launchql/launchql/issues"
21
- },
22
- "scripts": {
23
- "copy": "copyfiles -f ../../LICENSE README.md package.json dist",
24
- "clean": "rimraf dist/**",
25
- "prepare": "npm run build",
26
- "build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
27
- "build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
28
- "lint": "eslint . --fix",
29
- "test": "jest",
30
- "test:watch": "jest --watch"
31
- },
32
- "dependencies": {
33
- "@launchql/logger": "^1.0.0",
34
- "pg-cache": "^1.0.0",
35
- "lru-cache": "^11.1.0",
36
- "pg": "^8.16.0",
37
- "postgraphile": "^4.14.1"
38
- },
39
- "devDependencies": {
40
- "@types/pg": "^8.15.2",
41
- "@types/rimraf": "^4.0.5",
42
- "nodemon": "^3.1.10",
43
- "ts-node": "^10.9.2"
44
- },
45
- "keywords": [
46
- "postgraphile",
47
- "graphile",
48
- "cache",
49
- "lru",
50
- "postgresql",
51
- "launchql"
52
- ]
53
- }