@standardbeagle/edit-db 0.4.417 → 0.4.419

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.
@@ -1,35 +1,11 @@
1
1
  import { Join } from '../types/schema';
2
2
  /**
3
- * Minimal descriptor of the parent→child relationship needed to decide whether
4
- * (and how) to scope a polymorphic drill-down. Mirrors the polymorphic fields
5
- * projected onto a multi-join by the server's `_dbSchema` resolver.
6
- */
7
- export interface PolymorphicDescriptor {
8
- isPolymorphic?: boolean;
9
- polymorphicTypeColumn?: string;
10
- polymorphicTypeValue?: string;
11
- }
12
- /**
13
- * Build the discriminator filter clause for a polymorphic child drill-down, or
14
- * `null` when the relationship is not polymorphic (or lacks discriminator info).
15
- *
16
- * Returns a single filter object clause string such as
17
- * `{entity_type: {_eq: "company"}}` ready to be combined with the id predicate.
18
- */
19
- export declare function buildPolymorphicClause(rel: PolymorphicDescriptor): string | null;
20
- /**
21
- * Build the complete drill-down filter for a parent→child relationship,
22
- * combining the id predicate with the polymorphic discriminator when present.
23
- *
24
- * - Non-polymorphic: `{<idColumn>: {_eq: $id}}` (unchanged legacy shape).
25
- * - Polymorphic: `{and: [{<idColumn>: {_eq: $id}}, {<typeColumn>: {_eq: "<typeValue>"}}]}`.
26
- *
27
- * `idVar` defaults to `$id` to match `buildQuery`'s variable naming.
28
- */
29
- export declare function buildChildDrillDownFilter(idColumn: string, rel: PolymorphicDescriptor, idVar?: string): string;
30
- /**
31
- * Locate the parent table's multi-join that targets a given child via a given
32
- * destination (id) column, so the drill-down can read its polymorphic fields.
33
- * Returns `undefined` when no matching multi-join exists.
34
- */
35
- export declare function findChildMultiJoin(parentMultiJoins: Join[] | undefined, childTable: string, idColumn: string): Join | undefined;
3
+ * Locate the parent table's multi-join that targets a given child table. When
4
+ * the parent has more than one multi-join to the same child (e.g. a polymorphic
5
+ * shared table mapped under several parents, or a self-FK alias), `idColumn`
6
+ * (the child destination column) disambiguates. Returns `undefined` when no
7
+ * matching multi-join exists.
8
+ */
9
+ export declare function resolveChildJoin(parentMultiJoins: Join[] | undefined, childTable: string, idColumn?: string): Join | undefined;
10
+ /** The child collection field name on the parent type for a given join. */
11
+ export declare function childFieldName(join: Join): string;
@@ -49,4 +49,34 @@ export declare function getPkTypes(table: Table): PkTypeInfo[];
49
49
  */
50
50
  export declare function buildPkEqVariables(idRoute: string, table: Table): Record<string, unknown>;
51
51
  export declare function buildQuery(table: Table, schema: Schema, filterString: string, columnFilters: ColumnFiltersState, id?: string, tableFilter?: string, filterColumn?: string): string | null;
52
+ export interface DrillDownTarget {
53
+ /** The parent table whose row owns the child collection. */
54
+ parentTable: Table;
55
+ /** The child collection field name on the parent type. */
56
+ childField: string;
57
+ }
58
+ /**
59
+ * Resolve the parent table + child collection field for a parent→child
60
+ * related-records drill-down. The child is `table`; the parent is `tableFilter`
61
+ * (or the destination of `table`'s single-join named `tableFilter` when the
62
+ * relationship is described from the child side). `filterColumn` (the child
63
+ * destination column) disambiguates when the parent has several multi-joins to
64
+ * the same child. Returns `null` when no parent multi-join targets the child —
65
+ * the caller then falls back to the standard (non-traversal) query.
66
+ */
67
+ export interface PagedResult {
68
+ data: unknown[];
69
+ total: number;
70
+ offset: number;
71
+ limit: number;
72
+ }
73
+ /**
74
+ * Unwrap the nested paged child collection from a MODEL B drill-down response.
75
+ *
76
+ * The query shape is `{ <parentField>: { data: [ { <childField>: <paged> } ] } }`.
77
+ * Returns the child's `{total,offset,limit,data}` page, or an empty page when the
78
+ * parent row was not found (no children / unknown id).
79
+ */
80
+ export declare function unwrapDrillDownPage(response: Record<string, unknown> | null | undefined, parentField: string, childField: string): PagedResult;
81
+ export declare function resolveDrillDown(table: Table, schema: Schema, tableFilter?: string, filterColumn?: string): DrillDownTarget | null;
52
82
  export {};
@@ -98,16 +98,6 @@ export interface Join {
98
98
  destinationTable: string;
99
99
  /** Column names in the target table */
100
100
  destinationColumnNames: string[];
101
- /**
102
- * True when the target is a shared polymorphic child table keyed by a
103
- * discriminator column plus an id column (e.g. notes keyed by entity_type +
104
- * entity_id). Only present on multi-joins; absent/false on plain FK joins.
105
- */
106
- isPolymorphic?: boolean;
107
- /** Discriminator column on the child table (e.g. "entity_type"). Set when isPolymorphic. */
108
- polymorphicTypeColumn?: string;
109
- /** Discriminator value identifying this parent's rows (e.g. "company"). Set when isPolymorphic. */
110
- polymorphicTypeValue?: string;
111
101
  }
112
102
  /**
113
103
  * Many-to-many bridge between this entity and a target entity through a
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@standardbeagle/edit-db",
3
3
  "private": false,
4
- "version": "0.4.417",
4
+ "version": "0.4.419",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@radix-ui/react-slot": "^1.2.4",