graphile-connection-filter 1.15.0 → 1.15.2

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/esm/utils.d.ts CHANGED
@@ -1,37 +1,15 @@
1
1
  /**
2
2
  * Utility functions for the connection filter plugin.
3
3
  */
4
+ export { getQueryBuilder, isComputedScalarAttributeResource } from 'graphile-plugin-utils';
4
5
  /**
5
6
  * Check if a value is an empty object (no own enumerable keys).
6
7
  */
7
8
  export declare function isEmpty(o: unknown): boolean;
8
- /**
9
- * Check if a pgResource is a computed scalar attribute function.
10
- * A computed attribute is a function that:
11
- * - has parameters
12
- * - returns a scalar (no attributes on codec)
13
- * - is unique (returns single row)
14
- * - first parameter's codec has attributes (i.e. takes a table row)
15
- */
16
- export declare function isComputedScalarAttributeResource(s: any): boolean;
17
9
  /**
18
10
  * Get all computed attribute resources for a given source.
19
11
  */
20
12
  export declare function getComputedAttributeResources(build: any, source: any): any[];
21
- /**
22
- * Walks from a PgCondition up to the PgSelectQueryBuilder.
23
- * Uses the .parent property on PgCondition to traverse up the chain,
24
- * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
25
- *
26
- * This is used by satellite plugins (search, BM25, pgvector) that need
27
- * to access the query builder from within a filter's apply callback
28
- * to inject SELECT expressions (for ranking/scoring) and ORDER BY clauses.
29
- *
30
- * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
31
- * @param $condition - The PgCondition instance from the filter apply callback
32
- * @returns The PgSelectQueryBuilder if found, or null
33
- */
34
- export declare function getQueryBuilder(build: GraphileBuild.Build, $condition: any): any | null;
35
13
  /**
36
14
  * Creates an assertion function that validates filter input values.
37
15
  *
package/esm/utils.js CHANGED
@@ -1,36 +1,16 @@
1
1
  /**
2
2
  * Utility functions for the connection filter plugin.
3
3
  */
4
+ import { isComputedScalarAttributeResource } from 'graphile-plugin-utils';
5
+ // Shared helpers now live in graphile-plugin-utils. Re-exported here so the
6
+ // plugin's public API (see index.ts) stays backward compatible.
7
+ export { getQueryBuilder, isComputedScalarAttributeResource } from 'graphile-plugin-utils';
4
8
  /**
5
9
  * Check if a value is an empty object (no own enumerable keys).
6
10
  */
7
11
  export function isEmpty(o) {
8
12
  return typeof o === 'object' && o !== null && Object.keys(o).length === 0;
9
13
  }
10
- /**
11
- * Check if a pgResource is a computed scalar attribute function.
12
- * A computed attribute is a function that:
13
- * - has parameters
14
- * - returns a scalar (no attributes on codec)
15
- * - is unique (returns single row)
16
- * - first parameter's codec has attributes (i.e. takes a table row)
17
- */
18
- export function isComputedScalarAttributeResource(s) {
19
- if (!s.parameters || s.parameters.length < 1) {
20
- return false;
21
- }
22
- if (s.codec.attributes) {
23
- return false;
24
- }
25
- if (!s.isUnique) {
26
- return false;
27
- }
28
- const firstParameter = s.parameters[0];
29
- if (!firstParameter?.codec.attributes) {
30
- return false;
31
- }
32
- return true;
33
- }
34
14
  /**
35
15
  * Get all computed attribute resources for a given source.
36
16
  */
@@ -39,42 +19,6 @@ export function getComputedAttributeResources(build, source) {
39
19
  s.parameters[0].codec === source.codec);
40
20
  return computedAttributeSources;
41
21
  }
42
- /**
43
- * Walks from a PgCondition up to the PgSelectQueryBuilder.
44
- * Uses the .parent property on PgCondition to traverse up the chain,
45
- * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
46
- *
47
- * This is used by satellite plugins (search, BM25, pgvector) that need
48
- * to access the query builder from within a filter's apply callback
49
- * to inject SELECT expressions (for ranking/scoring) and ORDER BY clauses.
50
- *
51
- * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
52
- * @param $condition - The PgCondition instance from the filter apply callback
53
- * @returns The PgSelectQueryBuilder if found, or null
54
- */
55
- export function getQueryBuilder(build, $condition) {
56
- const PgCondition = build.dataplanPg?.PgCondition;
57
- if (!PgCondition)
58
- return null;
59
- let current = $condition;
60
- const { alias } = current;
61
- // Walk up through nested PgConditions (e.g. and/or/not)
62
- // Note: PgCondition.parent is protected, so we use bracket notation
63
- // to access it from outside the class hierarchy.
64
- while (current &&
65
- current instanceof PgCondition &&
66
- current.alias === alias) {
67
- current = current['parent'];
68
- }
69
- // Verify we found a query builder with matching alias
70
- // Using duck-typing per Benjie's pattern
71
- if (current &&
72
- typeof current.selectAndReturnIndex === 'function' &&
73
- current.alias === alias) {
74
- return current;
75
- }
76
- return null;
77
- }
78
22
  /**
79
23
  * Creates an assertion function that validates filter input values.
80
24
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-connection-filter",
3
- "version": "1.15.0",
3
+ "version": "1.15.2",
4
4
  "description": "PostGraphile v5 native connection filter plugin - adds advanced filtering to connections",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/constructive",
@@ -39,11 +39,14 @@
39
39
  "bugs": {
40
40
  "url": "https://github.com/constructive-io/constructive/issues"
41
41
  },
42
+ "dependencies": {
43
+ "graphile-plugin-utils": "^1.0.1"
44
+ },
42
45
  "devDependencies": {
43
46
  "@types/node": "^22.19.11",
44
- "graphile-test": "^4.20.0",
47
+ "graphile-test": "^4.20.2",
45
48
  "makage": "^0.3.0",
46
- "pgsql-test": "^4.19.0"
49
+ "pgsql-test": "^4.19.2"
47
50
  },
48
51
  "peerDependencies": {
49
52
  "@dataplan/pg": "1.0.3",
@@ -54,5 +57,5 @@
54
57
  "pg-sql2": "5.0.1",
55
58
  "postgraphile": "5.0.3"
56
59
  },
57
- "gitHead": "7eb34a3baa10ba3476575967b87ff51b606e042a"
60
+ "gitHead": "cd21f62bb64bdc7f4f40f6cef6af73f8f1c8f8dc"
58
61
  }
package/utils.d.ts CHANGED
@@ -1,37 +1,15 @@
1
1
  /**
2
2
  * Utility functions for the connection filter plugin.
3
3
  */
4
+ export { getQueryBuilder, isComputedScalarAttributeResource } from 'graphile-plugin-utils';
4
5
  /**
5
6
  * Check if a value is an empty object (no own enumerable keys).
6
7
  */
7
8
  export declare function isEmpty(o: unknown): boolean;
8
- /**
9
- * Check if a pgResource is a computed scalar attribute function.
10
- * A computed attribute is a function that:
11
- * - has parameters
12
- * - returns a scalar (no attributes on codec)
13
- * - is unique (returns single row)
14
- * - first parameter's codec has attributes (i.e. takes a table row)
15
- */
16
- export declare function isComputedScalarAttributeResource(s: any): boolean;
17
9
  /**
18
10
  * Get all computed attribute resources for a given source.
19
11
  */
20
12
  export declare function getComputedAttributeResources(build: any, source: any): any[];
21
- /**
22
- * Walks from a PgCondition up to the PgSelectQueryBuilder.
23
- * Uses the .parent property on PgCondition to traverse up the chain,
24
- * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
25
- *
26
- * This is used by satellite plugins (search, BM25, pgvector) that need
27
- * to access the query builder from within a filter's apply callback
28
- * to inject SELECT expressions (for ranking/scoring) and ORDER BY clauses.
29
- *
30
- * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
31
- * @param $condition - The PgCondition instance from the filter apply callback
32
- * @returns The PgSelectQueryBuilder if found, or null
33
- */
34
- export declare function getQueryBuilder(build: GraphileBuild.Build, $condition: any): any | null;
35
13
  /**
36
14
  * Creates an assertion function that validates filter input values.
37
15
  *
package/utils.js CHANGED
@@ -3,85 +3,30 @@
3
3
  * Utility functions for the connection filter plugin.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isComputedScalarAttributeResource = exports.getQueryBuilder = void 0;
6
7
  exports.isEmpty = isEmpty;
7
- exports.isComputedScalarAttributeResource = isComputedScalarAttributeResource;
8
8
  exports.getComputedAttributeResources = getComputedAttributeResources;
9
- exports.getQueryBuilder = getQueryBuilder;
10
9
  exports.makeAssertAllowed = makeAssertAllowed;
10
+ const graphile_plugin_utils_1 = require("graphile-plugin-utils");
11
+ // Shared helpers now live in graphile-plugin-utils. Re-exported here so the
12
+ // plugin's public API (see index.ts) stays backward compatible.
13
+ var graphile_plugin_utils_2 = require("graphile-plugin-utils");
14
+ Object.defineProperty(exports, "getQueryBuilder", { enumerable: true, get: function () { return graphile_plugin_utils_2.getQueryBuilder; } });
15
+ Object.defineProperty(exports, "isComputedScalarAttributeResource", { enumerable: true, get: function () { return graphile_plugin_utils_2.isComputedScalarAttributeResource; } });
11
16
  /**
12
17
  * Check if a value is an empty object (no own enumerable keys).
13
18
  */
14
19
  function isEmpty(o) {
15
20
  return typeof o === 'object' && o !== null && Object.keys(o).length === 0;
16
21
  }
17
- /**
18
- * Check if a pgResource is a computed scalar attribute function.
19
- * A computed attribute is a function that:
20
- * - has parameters
21
- * - returns a scalar (no attributes on codec)
22
- * - is unique (returns single row)
23
- * - first parameter's codec has attributes (i.e. takes a table row)
24
- */
25
- function isComputedScalarAttributeResource(s) {
26
- if (!s.parameters || s.parameters.length < 1) {
27
- return false;
28
- }
29
- if (s.codec.attributes) {
30
- return false;
31
- }
32
- if (!s.isUnique) {
33
- return false;
34
- }
35
- const firstParameter = s.parameters[0];
36
- if (!firstParameter?.codec.attributes) {
37
- return false;
38
- }
39
- return true;
40
- }
41
22
  /**
42
23
  * Get all computed attribute resources for a given source.
43
24
  */
44
25
  function getComputedAttributeResources(build, source) {
45
- const computedAttributeSources = Object.values(build.input.pgRegistry.pgResources).filter((s) => isComputedScalarAttributeResource(s) &&
26
+ const computedAttributeSources = Object.values(build.input.pgRegistry.pgResources).filter((s) => (0, graphile_plugin_utils_1.isComputedScalarAttributeResource)(s) &&
46
27
  s.parameters[0].codec === source.codec);
47
28
  return computedAttributeSources;
48
29
  }
49
- /**
50
- * Walks from a PgCondition up to the PgSelectQueryBuilder.
51
- * Uses the .parent property on PgCondition to traverse up the chain,
52
- * following Benjie's pattern from postgraphile-plugin-fulltext-filter.
53
- *
54
- * This is used by satellite plugins (search, BM25, pgvector) that need
55
- * to access the query builder from within a filter's apply callback
56
- * to inject SELECT expressions (for ranking/scoring) and ORDER BY clauses.
57
- *
58
- * @param build - The Graphile Build object (needs build.dataplanPg.PgCondition)
59
- * @param $condition - The PgCondition instance from the filter apply callback
60
- * @returns The PgSelectQueryBuilder if found, or null
61
- */
62
- function getQueryBuilder(build, $condition) {
63
- const PgCondition = build.dataplanPg?.PgCondition;
64
- if (!PgCondition)
65
- return null;
66
- let current = $condition;
67
- const { alias } = current;
68
- // Walk up through nested PgConditions (e.g. and/or/not)
69
- // Note: PgCondition.parent is protected, so we use bracket notation
70
- // to access it from outside the class hierarchy.
71
- while (current &&
72
- current instanceof PgCondition &&
73
- current.alias === alias) {
74
- current = current['parent'];
75
- }
76
- // Verify we found a query builder with matching alias
77
- // Using duck-typing per Benjie's pattern
78
- if (current &&
79
- typeof current.selectAndReturnIndex === 'function' &&
80
- current.alias === alias) {
81
- return current;
82
- }
83
- return null;
84
- }
85
30
  /**
86
31
  * Creates an assertion function that validates filter input values.
87
32
  *