graphile-search-plugin 0.1.7 → 0.1.9

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,15 +1,28 @@
1
- # graphile-search-plugin [![Build Status](https://travis-ci.org/pyramation/graphile-search-plugin.svg?branch=master)](https://travis-ci.org/pyramation/graphile-search-plugin)
1
+ # graphile-search-plugin
2
2
 
3
- ```sh
4
- npm install graphile-search-plugin
5
- ```
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
+ </p>
6
13
 
7
14
  This [PostGraphile](http://postgraphile.org/) schema plugin was built to enable ordering via `ts_rank` of full-text search on all `tsvector` fields, providing auto-generated queries within PostGraphile.
8
15
 
16
+ ## Install
17
+
18
+ ```sh
19
+ npm install graphile-search-plugin
20
+ ```
21
+
9
22
  ## Usage
10
23
 
11
24
  1. Append the new plugins!
12
- 2. Query `search<YourTsvectorColumn>` in the `conditions` field
25
+ 2. Query `search<YourTsvectorColumn>` in the `conditions` field
13
26
  3. Enjoy!
14
27
 
15
28
  ```js
@@ -38,3 +51,79 @@ psql test_database < sql/test.sql
38
51
  yarn test
39
52
  ```
40
53
 
54
+ ---
55
+
56
+ ## Education and Tutorials
57
+
58
+ 1. 🚀 [Quickstart: Getting Up and Running](https://launchql.com/learn/quickstart)
59
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
60
+
61
+ 2. 📦 [Modular PostgreSQL Development with Database Packages](https://launchql.com/learn/modular-postgres)
62
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
63
+
64
+ 3. ✏️ [Authoring Database Changes](https://launchql.com/learn/authoring-database-changes)
65
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
66
+
67
+ 4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://launchql.com/learn/e2e-postgres-testing)
68
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
69
+
70
+ 5. ⚡ [Supabase Testing](https://launchql.com/learn/supabase)
71
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
72
+
73
+ 6. 💧 [Drizzle ORM Testing](https://launchql.com/learn/drizzle-testing)
74
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
75
+
76
+ 7. 🔧 [Troubleshooting](https://launchql.com/learn/troubleshooting)
77
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
78
+
79
+ ## Related LaunchQL Tooling
80
+
81
+ ### 🧪 Testing
82
+
83
+ * [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.
84
+ * [launchql/supabase-test](https://github.com/launchql/launchql/tree/main/packages/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
85
+ * [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.
86
+ * [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.
87
+
88
+ ### 🧠 Parsing & AST
89
+
90
+ * [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
91
+ * [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
92
+ * [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.
93
+ * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
94
+ * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
95
+ * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
96
+ * [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
97
+
98
+ ### 🚀 API & Dev Tools
99
+
100
+ * [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.
101
+ * [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.
102
+
103
+ ### 🔁 Streaming & Uploads
104
+
105
+ * [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.
106
+ * [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.
107
+ * [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
108
+ * [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.
109
+ * [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.
110
+ * [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.
111
+
112
+ ### 🧰 CLI & Codegen
113
+
114
+ * [pgpm](https://github.com/launchql/launchql/tree/main/packages/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
115
+ * [@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.
116
+ * [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.
117
+ * [@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.
118
+ * [@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.
119
+
120
+ ## Credits
121
+
122
+ 🛠 Built by LaunchQL — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/launchql)
123
+
124
+
125
+ ## Disclaimer
126
+
127
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
128
+
129
+ 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,57 @@
1
+ // plugins/PgSearchPlugin.ts
2
+ /**
3
+ * PgSearchPlugin - Generates search conditions for tsvector columns
4
+ */
5
+ const PgSearchPlugin = (builder, options = {}) => {
6
+ const { pgSearchPrefix = 'tsv' } = options;
7
+ builder.hook('GraphQLInputObjectType:fields', (fields, build, context) => {
8
+ const { inflection } = build;
9
+ const { scope: { isPgCondition, pgIntrospection: table }, fieldWithHooks } = context;
10
+ if (!isPgCondition || !table || table.kind !== 'class')
11
+ return fields;
12
+ const tsvs = table.attributes.filter((attr) => attr.type.name === 'tsvector');
13
+ if (!tsvs.length)
14
+ return fields;
15
+ return build.extend(fields, tsvs.reduce((memo, attr) => {
16
+ const fieldName = inflection.camelCase(`${pgSearchPrefix}_${attr.name}`);
17
+ memo[fieldName] = fieldWithHooks(fieldName, { type: build.graphql.GraphQLString }, {});
18
+ return memo;
19
+ }, {}));
20
+ });
21
+ builder.hook('GraphQLObjectType:fields:field:args', (args, build, context) => {
22
+ const { pgSql: sql, inflection } = build;
23
+ const { scope: { isPgFieldConnection, isPgFieldSimpleCollection, pgFieldIntrospection: procOrTable, pgFieldIntrospectionTable: tableIfProc, }, addArgDataGenerator, } = context;
24
+ const table = tableIfProc || procOrTable;
25
+ if ((!isPgFieldConnection && !isPgFieldSimpleCollection) ||
26
+ !table ||
27
+ table.kind !== 'class') {
28
+ return args;
29
+ }
30
+ const tsvs = table.attributes.filter((attr) => attr.type.name === 'tsvector');
31
+ if (!tsvs.length)
32
+ return args;
33
+ tsvs.forEach((tsv) => {
34
+ const conditionFieldName = inflection.camelCase(`${pgSearchPrefix}_${tsv.name}`);
35
+ addArgDataGenerator(function addSearchCondition({ condition }) {
36
+ if (!condition || !(conditionFieldName in condition))
37
+ return {};
38
+ const value = condition[conditionFieldName];
39
+ if (value == null)
40
+ return {};
41
+ return {
42
+ pgQuery: (queryBuilder) => {
43
+ const tsquery = sql.fragment `websearch_to_tsquery('english', ${sql.value(value)})`;
44
+ const tableAlias = queryBuilder.getTableAlias();
45
+ // WHERE condition
46
+ queryBuilder.where(sql.fragment `${tableAlias}.${sql.identifier(tsv.name)} @@ ${tsquery}`);
47
+ // Automatically add ordering by relevance (descending)
48
+ queryBuilder.orderBy(sql.fragment `ts_rank(${tableAlias}.${sql.identifier(tsv.name)}, ${tsquery})`, false);
49
+ },
50
+ };
51
+ });
52
+ });
53
+ return args;
54
+ }, [], ['PgConnectionArgOrderBy']);
55
+ };
56
+ export { PgSearchPlugin };
57
+ export default PgSearchPlugin;
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export interface PgSearchPluginOptions {
2
+ /** Prefix for tsvector fields, default is 'tsv' */
3
+ pgSearchPrefix?: string;
4
+ }
5
+ /**
6
+ * PgSearchPlugin - Generates search conditions for tsvector columns
7
+ */
8
+ declare const PgSearchPlugin: (builder: any, options?: PgSearchPluginOptions) => void;
9
+ export { PgSearchPlugin };
10
+ export default PgSearchPlugin;
package/package.json CHANGED
@@ -1,26 +1,19 @@
1
1
  {
2
2
  "name": "graphile-search-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "generate search conditions for your tsvector columns",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
- "homepage": "https://github.com/pyramation/graphile-search-plugin#readme",
7
- "license": "SEE LICENSE IN LICENSE",
6
+ "homepage": "https://github.com/launchql/launchql",
7
+ "license": "MIT",
8
8
  "main": "index.js",
9
9
  "module": "esm/index.js",
10
10
  "types": "index.d.ts",
11
- "directories": {
12
- "lib": "src",
13
- "test": "__tests__"
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
11
  "scripts": {
19
- "copy": "copyfiles -f ../../LICENSE README.md package.json dist",
20
- "clean": "rimraf dist/**",
12
+ "clean": "makage clean",
13
+ "copy": "makage assets",
21
14
  "prepack": "pnpm run build",
22
- "build": "pnpm run clean; tsc -p tsconfig.json; tsc -p tsconfig.esm.json; pnpm run copy",
23
- "build:dev": "pnpm run clean; tsc -p tsconfig.json --declarationMap; tsc -p tsconfig.esm.json; pnpm run copy",
15
+ "build": "makage build",
16
+ "build:dev": "makage build --dev",
24
17
  "lint": "eslint . --fix",
25
18
  "test": "jest",
26
19
  "test:watch": "jest --watch"
@@ -31,7 +24,7 @@
31
24
  },
32
25
  "repository": {
33
26
  "type": "git",
34
- "url": "https://github.com/pyramation/graphile-search-plugin"
27
+ "url": "https://github.com/launchql/launchql"
35
28
  },
36
29
  "keywords": [
37
30
  "postgraphile",
@@ -42,18 +35,19 @@
42
35
  "graphql"
43
36
  ],
44
37
  "bugs": {
45
- "url": "https://github.com/pyramation/graphile-search-plugin/issues"
38
+ "url": "https://github.com/launchql/launchql/issues"
46
39
  },
47
40
  "devDependencies": {
48
41
  "@pyramation/postgraphile-plugin-fulltext-filter": "2.0.0",
49
- "graphile-simple-inflector": "^0.1.1",
50
- "graphile-test": "^2.8.3",
51
- "pgsql-test": "^2.14.6",
42
+ "graphile-simple-inflector": "^0.1.4",
43
+ "graphile-test": "^2.8.5",
44
+ "makage": "^0.1.6",
45
+ "pgsql-test": "^2.14.8",
52
46
  "postgraphile-plugin-connection-filter": "^2.0.0"
53
47
  },
54
48
  "dependencies": {
55
49
  "graphile-build": "^4.14.1",
56
50
  "graphql-tag": "2.12.6"
57
51
  },
58
- "gitHead": "4850ef84ce134d1bb43dc9132619a59257bd1157"
52
+ "gitHead": "e4643c07b6a961b964bbb132308366fc549504a1"
59
53
  }