graphile-plugin-utils 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/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 Constructive <developers@constructive.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,139 @@
1
+ # graphile-plugin-utils
2
+
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
6
+
7
+ <p align="center" width="100%">
8
+ <a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
9
+ <img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
10
+ </a>
11
+ <a href="https://github.com/constructive-io/constructive/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-plugin-utils"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=graphile%2Fgraphile-plugin-utils%2Fpackage.json"/></a>
13
+ </p>
14
+
15
+
16
+ Shared internals for Constructive's PostGraphile v5 plugins. This package holds
17
+ the small cross-plugin helpers that would otherwise be duplicated across
18
+ `graphile-connection-filter`, `graphile-search`, and `graphile-pg-aggregates`,
19
+ so there is a single home for them and no plugin has to depend on a sibling
20
+ feature plugin just to borrow a utility.
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install graphile-plugin-utils
26
+ ```
27
+
28
+ ## API
29
+
30
+ ### `getQueryBuilder(build, $condition)`
31
+
32
+ Walks from a `PgCondition` up to its `PgSelectQueryBuilder`, following Benjie's
33
+ pattern from `postgraphile-plugin-fulltext-filter`. Satellite filter plugins
34
+ (search, BM25, pgvector) use it from inside a filter's `apply` callback to
35
+ inject `SELECT` expressions (for ranking/scoring) and `ORDER BY` clauses.
36
+
37
+ ```ts
38
+ import { getQueryBuilder } from 'graphile-plugin-utils';
39
+
40
+ const qb = getQueryBuilder(build, $condition);
41
+ if (qb) {
42
+ qb.orderBy({ /* ... */ });
43
+ }
44
+ ```
45
+
46
+ Returns the query builder, or `null` when it cannot be resolved (e.g. the build
47
+ does not expose `dataplanPg.PgCondition`).
48
+
49
+ ### `isComputedScalarAttributeResource(resource)`
50
+
51
+ Type guard for a computed scalar attribute function โ€” a `pgResource` that takes
52
+ a table row as its first parameter, returns a scalar, and is unique. Used to
53
+ recognise computed columns exposed as functions when building filters and
54
+ aggregates.
55
+
56
+ ```ts
57
+ import { isComputedScalarAttributeResource } from 'graphile-plugin-utils';
58
+
59
+ const computed = Object.values(build.input.pgRegistry.pgResources).filter(
60
+ isComputedScalarAttributeResource
61
+ );
62
+ ```
63
+
64
+ ## License
65
+
66
+ MIT
67
+
68
+ ---
69
+
70
+ ## Education and Tutorials
71
+
72
+ 1. ๐Ÿš€ [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
73
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
74
+
75
+ 2. ๐Ÿ“ฆ [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
76
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
77
+
78
+ 3. โœ๏ธ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
79
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
80
+
81
+ 4. ๐Ÿงช [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
82
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
83
+
84
+ 5. โšก [Supabase Testing](https://constructive.io/learn/supabase)
85
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
86
+
87
+ 6. ๐Ÿ’ง [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
88
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
89
+
90
+ 7. ๐Ÿ”ง [Troubleshooting](https://constructive.io/learn/troubleshooting)
91
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
92
+
93
+ ## Related Constructive Tooling
94
+
95
+ ### ๐Ÿ“ฆ Package Management
96
+
97
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **๐Ÿ–ฅ๏ธ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
98
+
99
+ ### ๐Ÿงช Testing
100
+
101
+ * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **๐Ÿ“Š Isolated testing environments** with per-test transaction rollbacksโ€”ideal for integration tests, complex migrations, and RLS simulation.
102
+ * [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **๐ŸŒฑ PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
103
+ * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **๐Ÿงช Supabase-native test harness** preconfigured for the local Supabase stackโ€”per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
104
+ * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **๐Ÿ” Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
105
+ * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/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.
106
+
107
+ ### ๐Ÿง  Parsing & AST
108
+
109
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **๐Ÿ”„ SQL conversion engine** that interprets and converts PostgreSQL syntax.
110
+ * [libpg-query-node](https://www.npmjs.com/package/libpg-query): **๐ŸŒ‰ Node.js bindings** for `libpg_query`, converting SQL into parse trees.
111
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **๐Ÿ“ฆ Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
112
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **๐Ÿท๏ธ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
113
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **๐Ÿ“ Type definitions** for PostgreSQL AST nodes in TypeScript.
114
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **๐Ÿ› ๏ธ AST utilities** for constructing and transforming PostgreSQL syntax trees.
115
+
116
+ ### ๐Ÿ“š Documentation & Skills
117
+
118
+ * [constructive-skills](https://github.com/constructive-io/constructive-skills): **๐Ÿ“– Platform documentation and AI agent skills** โ€” feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
119
+
120
+ Install skills for AI coding agents:
121
+
122
+ ```bash
123
+ # All platform skills (security, blueprints, codegen, billing, etc.)
124
+ npx skills add constructive-io/constructive-skills
125
+
126
+ # Individual repo skills (pgpm, testing, CLI, search, etc.)
127
+ npx skills add https://github.com/constructive-io/constructive --skill pgpm
128
+ npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
129
+ ```
130
+
131
+ ## Credits
132
+
133
+ **๐Ÿ›  Built by the [Constructive](https://constructive.io) team โ€” creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
134
+
135
+ ## Disclaimer
136
+
137
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
138
+
139
+ 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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const pg_resources_1 = require("../pg-resources");
4
+ const tableCodec = { attributes: { id: {} } };
5
+ const scalarCodec = {};
6
+ function resource(overrides) {
7
+ return {
8
+ isUnique: true,
9
+ codec: scalarCodec,
10
+ parameters: [{ codec: tableCodec }],
11
+ ...overrides
12
+ };
13
+ }
14
+ describe('isComputedScalarAttributeResource', () => {
15
+ it('accepts a unique scalar function taking a table row', () => {
16
+ expect((0, pg_resources_1.isComputedScalarAttributeResource)(resource({}))).toBe(true);
17
+ });
18
+ it('rejects a resource without parameters', () => {
19
+ expect((0, pg_resources_1.isComputedScalarAttributeResource)(resource({ parameters: [] }))).toBe(false);
20
+ });
21
+ it('rejects a table-returning resource (codec has attributes)', () => {
22
+ expect((0, pg_resources_1.isComputedScalarAttributeResource)(resource({ codec: tableCodec }))).toBe(false);
23
+ });
24
+ it('rejects a non-unique resource', () => {
25
+ expect((0, pg_resources_1.isComputedScalarAttributeResource)(resource({ isUnique: false }))).toBe(false);
26
+ });
27
+ it('rejects when the first parameter is not a table row', () => {
28
+ expect((0, pg_resources_1.isComputedScalarAttributeResource)(resource({ parameters: [{ codec: scalarCodec }] }))).toBe(false);
29
+ });
30
+ });
@@ -0,0 +1,28 @@
1
+ import { isComputedScalarAttributeResource } from '../pg-resources';
2
+ const tableCodec = { attributes: { id: {} } };
3
+ const scalarCodec = {};
4
+ function resource(overrides) {
5
+ return {
6
+ isUnique: true,
7
+ codec: scalarCodec,
8
+ parameters: [{ codec: tableCodec }],
9
+ ...overrides
10
+ };
11
+ }
12
+ describe('isComputedScalarAttributeResource', () => {
13
+ it('accepts a unique scalar function taking a table row', () => {
14
+ expect(isComputedScalarAttributeResource(resource({}))).toBe(true);
15
+ });
16
+ it('rejects a resource without parameters', () => {
17
+ expect(isComputedScalarAttributeResource(resource({ parameters: [] }))).toBe(false);
18
+ });
19
+ it('rejects a table-returning resource (codec has attributes)', () => {
20
+ expect(isComputedScalarAttributeResource(resource({ codec: tableCodec }))).toBe(false);
21
+ });
22
+ it('rejects a non-unique resource', () => {
23
+ expect(isComputedScalarAttributeResource(resource({ isUnique: false }))).toBe(false);
24
+ });
25
+ it('rejects when the first parameter is not a table row', () => {
26
+ expect(isComputedScalarAttributeResource(resource({ parameters: [{ codec: scalarCodec }] }))).toBe(false);
27
+ });
28
+ });
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Shared internals for Constructive PostGraphile v5 plugins.
2
+ // PgCondition โ†’ PgSelectQueryBuilder walker (search / BM25 / pgvector)
3
+ export { getQueryBuilder } from './query-builder';
4
+ // pg-resource introspection helpers (connection-filter / pg-aggregates)
5
+ export { isComputedScalarAttributeResource } from './pg-resources';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Whether a pgResource is a computed scalar attribute function, i.e. one that:
3
+ * - takes at least one parameter,
4
+ * - returns a scalar (its codec has no attributes),
5
+ * - is unique (returns a single row),
6
+ * - and takes a table row as its first parameter (that parameter's codec has
7
+ * attributes).
8
+ *
9
+ * Shared by the connection-filter and pg-aggregates plugins, which both need
10
+ * to recognise computed columns exposed as functions.
11
+ */
12
+ export function isComputedScalarAttributeResource(s) {
13
+ if (!s.parameters || s.parameters.length < 1) {
14
+ return false;
15
+ }
16
+ if (s.codec.attributes) {
17
+ return false;
18
+ }
19
+ if (!s.isUnique) {
20
+ return false;
21
+ }
22
+ const firstParameter = s.parameters[0];
23
+ if (!firstParameter?.codec.attributes) {
24
+ return false;
25
+ }
26
+ return true;
27
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Walks from a PgCondition up to the PgSelectQueryBuilder.
3
+ * Uses the `.parent` property on PgCondition to traverse up the chain,
4
+ * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
5
+ *
6
+ * This is used by satellite plugins (search, BM25, pgvector) that need to
7
+ * access the query builder from within a filter's apply callback to inject
8
+ * SELECT expressions (for ranking/scoring) and ORDER BY clauses.
9
+ *
10
+ * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
11
+ * @param $condition - The PgCondition instance from the filter apply callback
12
+ * @returns The PgSelectQueryBuilder if found, or null
13
+ */
14
+ export function getQueryBuilder(build, $condition) {
15
+ const PgCondition = build.dataplanPg?.PgCondition;
16
+ if (!PgCondition)
17
+ return null;
18
+ let current = $condition;
19
+ const { alias } = current;
20
+ // Walk up through nested PgConditions (e.g. and/or/not)
21
+ // Note: PgCondition.parent is protected, so we use bracket notation
22
+ // to access it from outside the class hierarchy.
23
+ while (current &&
24
+ current instanceof PgCondition &&
25
+ current.alias === alias) {
26
+ current = current['parent'];
27
+ }
28
+ // Verify we found a query builder with matching alias
29
+ // Using duck-typing per Benjie's pattern
30
+ if (current &&
31
+ typeof current.selectAndReturnIndex === 'function' &&
32
+ current.alias === alias) {
33
+ return current;
34
+ }
35
+ return null;
36
+ }
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { getQueryBuilder } from './query-builder';
2
+ export { isComputedScalarAttributeResource } from './pg-resources';
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Shared internals for Constructive PostGraphile v5 plugins.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isComputedScalarAttributeResource = exports.getQueryBuilder = void 0;
5
+ // PgCondition โ†’ PgSelectQueryBuilder walker (search / BM25 / pgvector)
6
+ var query_builder_1 = require("./query-builder");
7
+ Object.defineProperty(exports, "getQueryBuilder", { enumerable: true, get: function () { return query_builder_1.getQueryBuilder; } });
8
+ // pg-resource introspection helpers (connection-filter / pg-aggregates)
9
+ var pg_resources_1 = require("./pg-resources");
10
+ Object.defineProperty(exports, "isComputedScalarAttributeResource", { enumerable: true, get: function () { return pg_resources_1.isComputedScalarAttributeResource; } });
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "graphile-plugin-utils",
3
+ "version": "1.0.1",
4
+ "description": "Shared internals for Constructive PostGraphile v5 plugins - PgCondition query-builder walker and pg-resource introspection helpers",
5
+ "author": "Constructive <developers@constructive.io>",
6
+ "homepage": "https://github.com/constructive-io/constructive",
7
+ "license": "MIT",
8
+ "main": "index.js",
9
+ "module": "esm/index.js",
10
+ "types": "index.d.ts",
11
+ "scripts": {
12
+ "clean": "makage clean",
13
+ "prepack": "npm run build",
14
+ "build": "makage build",
15
+ "build:dev": "makage build --dev",
16
+ "lint": "eslint . --fix",
17
+ "test": "jest --passWithNoTests",
18
+ "test:watch": "jest --watch"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "directory": "dist"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/constructive-io/constructive"
27
+ },
28
+ "keywords": [
29
+ "postgraphile",
30
+ "graphile",
31
+ "constructive",
32
+ "plugin",
33
+ "postgres",
34
+ "graphql",
35
+ "utils",
36
+ "v5"
37
+ ],
38
+ "bugs": {
39
+ "url": "https://github.com/constructive-io/constructive/issues"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.19.11",
43
+ "makage": "^0.3.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@dataplan/pg": "1.0.3",
47
+ "graphile-build": "5.0.2",
48
+ "graphile-build-pg": "5.0.2",
49
+ "graphile-config": "1.0.1",
50
+ "graphql": "16.13.0",
51
+ "pg-sql2": "5.0.1",
52
+ "postgraphile": "5.0.3"
53
+ },
54
+ "gitHead": "cd21f62bb64bdc7f4f40f6cef6af73f8f1c8f8dc"
55
+ }
@@ -0,0 +1,13 @@
1
+ import type { PgCodec, PgRegistry, PgResource, PgResourceParameter } from '@dataplan/pg';
2
+ /**
3
+ * Whether a pgResource is a computed scalar attribute function, i.e. one that:
4
+ * - takes at least one parameter,
5
+ * - returns a scalar (its codec has no attributes),
6
+ * - is unique (returns a single row),
7
+ * - and takes a table row as its first parameter (that parameter's codec has
8
+ * attributes).
9
+ *
10
+ * Shared by the connection-filter and pg-aggregates plugins, which both need
11
+ * to recognise computed columns exposed as functions.
12
+ */
13
+ export declare function isComputedScalarAttributeResource(s: PgResource<any, any, any, any, any>): s is PgResource<string, PgCodec, never[], PgResourceParameter[], PgRegistry>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isComputedScalarAttributeResource = isComputedScalarAttributeResource;
4
+ /**
5
+ * Whether a pgResource is a computed scalar attribute function, i.e. one that:
6
+ * - takes at least one parameter,
7
+ * - returns a scalar (its codec has no attributes),
8
+ * - is unique (returns a single row),
9
+ * - and takes a table row as its first parameter (that parameter's codec has
10
+ * attributes).
11
+ *
12
+ * Shared by the connection-filter and pg-aggregates plugins, which both need
13
+ * to recognise computed columns exposed as functions.
14
+ */
15
+ function isComputedScalarAttributeResource(s) {
16
+ if (!s.parameters || s.parameters.length < 1) {
17
+ return false;
18
+ }
19
+ if (s.codec.attributes) {
20
+ return false;
21
+ }
22
+ if (!s.isUnique) {
23
+ return false;
24
+ }
25
+ const firstParameter = s.parameters[0];
26
+ if (!firstParameter?.codec.attributes) {
27
+ return false;
28
+ }
29
+ return true;
30
+ }
@@ -0,0 +1,15 @@
1
+ import type { GraphileBuild } from 'graphile-build';
2
+ /**
3
+ * Walks from a PgCondition up to the PgSelectQueryBuilder.
4
+ * Uses the `.parent` property on PgCondition to traverse up the chain,
5
+ * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
6
+ *
7
+ * This is used by satellite plugins (search, BM25, pgvector) that need to
8
+ * access the query builder from within a filter's apply callback to inject
9
+ * SELECT expressions (for ranking/scoring) and ORDER BY clauses.
10
+ *
11
+ * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
12
+ * @param $condition - The PgCondition instance from the filter apply callback
13
+ * @returns The PgSelectQueryBuilder if found, or null
14
+ */
15
+ export declare function getQueryBuilder(build: GraphileBuild.Build, $condition: any): any | null;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getQueryBuilder = getQueryBuilder;
4
+ /**
5
+ * Walks from a PgCondition up to the PgSelectQueryBuilder.
6
+ * Uses the `.parent` property on PgCondition to traverse up the chain,
7
+ * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
8
+ *
9
+ * This is used by satellite plugins (search, BM25, pgvector) that need to
10
+ * access the query builder from within a filter's apply callback to inject
11
+ * SELECT expressions (for ranking/scoring) and ORDER BY clauses.
12
+ *
13
+ * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
14
+ * @param $condition - The PgCondition instance from the filter apply callback
15
+ * @returns The PgSelectQueryBuilder if found, or null
16
+ */
17
+ function getQueryBuilder(build, $condition) {
18
+ const PgCondition = build.dataplanPg?.PgCondition;
19
+ if (!PgCondition)
20
+ return null;
21
+ let current = $condition;
22
+ const { alias } = current;
23
+ // Walk up through nested PgConditions (e.g. and/or/not)
24
+ // Note: PgCondition.parent is protected, so we use bracket notation
25
+ // to access it from outside the class hierarchy.
26
+ while (current &&
27
+ current instanceof PgCondition &&
28
+ current.alias === alias) {
29
+ current = current['parent'];
30
+ }
31
+ // Verify we found a query builder with matching alias
32
+ // Using duck-typing per Benjie's pattern
33
+ if (current &&
34
+ typeof current.selectAndReturnIndex === 'function' &&
35
+ current.alias === alias) {
36
+ return current;
37
+ }
38
+ return null;
39
+ }