pg-query-context 2.1.4

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,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
4
+ Copyright (c) 2025 Hyperweb <developers@hyperweb.io>
5
+ Copyright (c) 2020-present, Interweb, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # pg-query-context
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/pg-query-context"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fpg-query-context%2Fpackage.json"/></a>
13
+ </p>
14
+
15
+ ## Related LaunchQL Tooling
16
+
17
+ ### 🧪 Testing
18
+
19
+ * [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.
20
+ * [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.
21
+ * [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.
22
+
23
+ ### 🧠 Parsing & AST
24
+
25
+ * [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
26
+ * [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
27
+ * [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.
28
+ * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
29
+ * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
30
+ * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
31
+ * [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
32
+
33
+ ### 🚀 API & Dev Tools
34
+
35
+ * [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.
36
+ * [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.
37
+
38
+ ### 🔁 Streaming & Uploads
39
+
40
+ * [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.
41
+ * [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.
42
+ * [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
43
+ * [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.
44
+ * [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.
45
+ * [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.
46
+
47
+ ### 🧰 CLI & Codegen
48
+
49
+ * [@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.
50
+ * [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.
51
+ * [@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.
52
+ * [@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.
53
+
54
+ ## Disclaimer
55
+
56
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
57
+
58
+ 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.
59
+
package/esm/index.js ADDED
@@ -0,0 +1,36 @@
1
+ function setContext(ctx) {
2
+ return Object.keys(ctx || {}).reduce((m, el) => {
3
+ m.push(`SELECT set_config('${el}', '${ctx[el]}', true);`);
4
+ return m;
5
+ }, []);
6
+ }
7
+ async function execContext(client, ctx) {
8
+ const local = setContext(ctx);
9
+ for (const query of local) {
10
+ await client.query(query);
11
+ }
12
+ }
13
+ export default async ({ client, context = {}, query = '', variables = [] }) => {
14
+ const isPool = 'connect' in client;
15
+ const shouldRelease = isPool;
16
+ let pgClient = null;
17
+ try {
18
+ pgClient = isPool ? await client.connect() : client;
19
+ await pgClient.query('BEGIN');
20
+ await execContext(pgClient, context);
21
+ const result = await pgClient.query(query, variables);
22
+ await pgClient.query('COMMIT');
23
+ return result;
24
+ }
25
+ catch (error) {
26
+ if (pgClient) {
27
+ await pgClient.query('ROLLBACK').catch(() => { });
28
+ }
29
+ throw error;
30
+ }
31
+ finally {
32
+ if (shouldRelease && pgClient && 'release' in pgClient) {
33
+ pgClient.release();
34
+ }
35
+ }
36
+ };
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Pool, ClientBase, QueryResult } from 'pg';
2
+ interface ExecOptions {
3
+ client: Pool | ClientBase;
4
+ context?: Record<string, string>;
5
+ query: string;
6
+ variables?: any[];
7
+ }
8
+ declare const _default: ({ client, context, query, variables }: ExecOptions) => Promise<QueryResult>;
9
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function setContext(ctx) {
4
+ return Object.keys(ctx || {}).reduce((m, el) => {
5
+ m.push(`SELECT set_config('${el}', '${ctx[el]}', true);`);
6
+ return m;
7
+ }, []);
8
+ }
9
+ async function execContext(client, ctx) {
10
+ const local = setContext(ctx);
11
+ for (const query of local) {
12
+ await client.query(query);
13
+ }
14
+ }
15
+ exports.default = async ({ client, context = {}, query = '', variables = [] }) => {
16
+ const isPool = 'connect' in client;
17
+ const shouldRelease = isPool;
18
+ let pgClient = null;
19
+ try {
20
+ pgClient = isPool ? await client.connect() : client;
21
+ await pgClient.query('BEGIN');
22
+ await execContext(pgClient, context);
23
+ const result = await pgClient.query(query, variables);
24
+ await pgClient.query('COMMIT');
25
+ return result;
26
+ }
27
+ catch (error) {
28
+ if (pgClient) {
29
+ await pgClient.query('ROLLBACK').catch(() => { });
30
+ }
31
+ throw error;
32
+ }
33
+ finally {
34
+ if (shouldRelease && pgClient && 'release' in pgClient) {
35
+ pgClient.release();
36
+ }
37
+ }
38
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "pg-query-context",
3
+ "version": "2.1.4",
4
+ "author": "Dan Lynch <pyramation@gmail.com>",
5
+ "description": "pg query context",
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
+ "pg": "^8.16.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/pg": "^8.15.2"
37
+ },
38
+ "gitHead": "36e9eb71ef72f72d21e9557fb190da1900f31b87"
39
+ }