Commit 307711c
feat(data-access): expose postgrestClient for direct PostgREST queries (#1396)
## Summary
- Exposes the underlying `PostgrestClient` instance under a `services`
namespace on the object returned by `createDataAccess()`, enabling
direct PostgREST queries against tables that are not modeled as entities
(e.g. analytics views, brand presence tables)
- Adds full TypeScript typings for all 32 entity collections on the
`DataAccess` interface (previously typed as `object`)
- Re-exports 5 previously missing collection types from
`models/index.d.ts` (`ApiKey`, `AuditUrl`, `PageCitability`,
`PageIntent`, `Project`)
## Motivation
Some API endpoints need to query PostgREST tables that don't have
corresponding entity models in the data-access layer (e.g.
`brand_presence_executions`, `brand_metrics_weekly`). Previously,
developers resorted to reaching into collection internals like
`Site.postgrestService` to get the raw client. This change makes it a
first-class, typed API under a `services` namespace that cleanly
separates infrastructure from entity collections.
## Usage
```javascript
// Entity collections stay top-level
const { Site, Organization } = context.dataAccess;
const site = await Site.findById(siteId);
// Infrastructure services live under the services namespace
const { postgrestClient } = context.dataAccess.services;
// Direct queries against non-entity tables
const { data, error } = await postgrestClient
.from('brand_presence_executions')
.select('execution_date, visibility_score, sentiment')
.eq('site_id', siteId)
.gte('execution_date', '2025-01-01')
.order('execution_date', { ascending: false })
.limit(100);
```
Full IDE autocomplete is available for the entire PostgREST query
builder chain (`.from()`, `.select()`, `.eq()`, `.gte()`, `.order()`,
`.range()`, `.rpc()`, etc.).
## Test plan
- [x] Existing unit tests updated to verify `services.postgrestClient`
is present and is the correct instance
- [x] All 1522 unit tests passing
- [x] Lint passing
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 4e29cc5 commit 307711c
File tree
5 files changed
+101
-10
lines changed5 files changed
+101
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
Lines changed: 13 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | | - | |
21 | | - | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | | - | |
37 | 44 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 45 | + | |
Lines changed: 76 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
13 | 48 | | |
14 | 49 | | |
15 | 50 | | |
| |||
19 | 54 | | |
20 | 55 | | |
21 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
22 | 97 | | |
23 | 98 | | |
24 | 99 | | |
25 | 100 | | |
26 | | - | |
| 101 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
102 | 107 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
0 commit comments