@fuzdev/fuz_app 0.67.1 → 0.68.0
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/dist/auth/CLAUDE.md +99 -5
- package/dist/auth/account_queries.d.ts +87 -4
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +107 -17
- package/dist/auth/account_schema.d.ts +19 -0
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +8 -0
- package/dist/auth/admin_action_specs.d.ts +168 -0
- package/dist/auth/admin_action_specs.d.ts.map +1 -1
- package/dist/auth/admin_action_specs.js +146 -1
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +218 -4
- package/dist/auth/audit_log_ddl.d.ts +10 -1
- package/dist/auth/audit_log_ddl.d.ts.map +1 -1
- package/dist/auth/audit_log_ddl.js +13 -4
- package/dist/auth/audit_log_schema.d.ts +34 -1
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +73 -0
- package/dist/auth/auth_ddl.d.ts +2 -2
- package/dist/auth/auth_ddl.d.ts.map +1 -1
- package/dist/auth/auth_ddl.js +10 -2
- package/dist/auth/cell_action_specs.d.ts +1295 -0
- package/dist/auth/cell_action_specs.d.ts.map +1 -0
- package/dist/auth/cell_action_specs.js +397 -0
- package/dist/auth/cell_actions.d.ts +63 -0
- package/dist/auth/cell_actions.d.ts.map +1 -0
- package/dist/auth/cell_actions.js +546 -0
- package/dist/auth/cell_audit_action_specs.d.ts +131 -0
- package/dist/auth/cell_audit_action_specs.d.ts.map +1 -0
- package/dist/auth/cell_audit_action_specs.js +70 -0
- package/dist/auth/cell_audit_actions.d.ts +18 -0
- package/dist/auth/cell_audit_actions.d.ts.map +1 -0
- package/dist/auth/cell_audit_actions.js +59 -0
- package/dist/auth/cell_audit_events.d.ts +28 -0
- package/dist/auth/cell_audit_events.d.ts.map +1 -0
- package/dist/auth/cell_audit_events.js +42 -0
- package/dist/auth/cell_audit_metadata.d.ts +48 -0
- package/dist/auth/cell_audit_metadata.d.ts.map +1 -0
- package/dist/auth/cell_audit_metadata.js +46 -0
- package/dist/auth/cell_authorize.d.ts +88 -0
- package/dist/auth/cell_authorize.d.ts.map +1 -0
- package/dist/auth/cell_authorize.js +172 -0
- package/dist/auth/cell_data_schema.d.ts +44 -0
- package/dist/auth/cell_data_schema.d.ts.map +1 -0
- package/dist/auth/cell_data_schema.js +42 -0
- package/dist/auth/cell_field_action_specs.d.ts +244 -0
- package/dist/auth/cell_field_action_specs.d.ts.map +1 -0
- package/dist/auth/cell_field_action_specs.js +136 -0
- package/dist/auth/cell_field_actions.d.ts +34 -0
- package/dist/auth/cell_field_actions.d.ts.map +1 -0
- package/dist/auth/cell_field_actions.js +153 -0
- package/dist/auth/cell_field_audit_metadata.d.ts +30 -0
- package/dist/auth/cell_field_audit_metadata.d.ts.map +1 -0
- package/dist/auth/cell_field_audit_metadata.js +28 -0
- package/dist/auth/cell_grant_action_specs.d.ts +333 -0
- package/dist/auth/cell_grant_action_specs.d.ts.map +1 -0
- package/dist/auth/cell_grant_action_specs.js +148 -0
- package/dist/auth/cell_grant_actions.d.ts +50 -0
- package/dist/auth/cell_grant_actions.d.ts.map +1 -0
- package/dist/auth/cell_grant_actions.js +208 -0
- package/dist/auth/cell_grant_audit_metadata.d.ts +75 -0
- package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -0
- package/dist/auth/cell_grant_audit_metadata.js +54 -0
- package/dist/auth/cell_item_action_specs.d.ts +331 -0
- package/dist/auth/cell_item_action_specs.d.ts.map +1 -0
- package/dist/auth/cell_item_action_specs.js +182 -0
- package/dist/auth/cell_item_actions.d.ts +37 -0
- package/dist/auth/cell_item_actions.d.ts.map +1 -0
- package/dist/auth/cell_item_actions.js +204 -0
- package/dist/auth/cell_item_audit_metadata.d.ts +35 -0
- package/dist/auth/cell_item_audit_metadata.d.ts.map +1 -0
- package/dist/auth/cell_item_audit_metadata.js +32 -0
- package/dist/auth/cell_relation_visibility.d.ts +32 -0
- package/dist/auth/cell_relation_visibility.d.ts.map +1 -0
- package/dist/auth/cell_relation_visibility.js +57 -0
- package/dist/auth/deps.d.ts +9 -0
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.d.ts +30 -0
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +54 -0
- package/dist/db/CLAUDE.md +118 -0
- package/dist/db/cell_audit_queries.d.ts +26 -0
- package/dist/db/cell_audit_queries.d.ts.map +1 -0
- package/dist/db/cell_audit_queries.js +53 -0
- package/dist/db/cell_ddl.d.ts +151 -0
- package/dist/db/cell_ddl.d.ts.map +1 -0
- package/dist/db/cell_ddl.js +247 -0
- package/dist/db/cell_field_queries.d.ts +105 -0
- package/dist/db/cell_field_queries.d.ts.map +1 -0
- package/dist/db/cell_field_queries.js +113 -0
- package/dist/db/cell_grant_queries.d.ts +132 -0
- package/dist/db/cell_grant_queries.d.ts.map +1 -0
- package/dist/db/cell_grant_queries.js +145 -0
- package/dist/db/cell_history_ddl.d.ts +38 -0
- package/dist/db/cell_history_ddl.d.ts.map +1 -0
- package/dist/db/cell_history_ddl.js +61 -0
- package/dist/db/cell_item_queries.d.ts +107 -0
- package/dist/db/cell_item_queries.d.ts.map +1 -0
- package/dist/db/cell_item_queries.js +119 -0
- package/dist/db/cell_queries.d.ts +327 -0
- package/dist/db/cell_queries.d.ts.map +1 -0
- package/dist/db/cell_queries.js +431 -0
- package/dist/db/fact_ddl.d.ts +38 -0
- package/dist/db/fact_ddl.d.ts.map +1 -0
- package/dist/db/fact_ddl.js +71 -0
- package/dist/db/fact_queries.d.ts +140 -0
- package/dist/db/fact_queries.d.ts.map +1 -0
- package/dist/db/fact_queries.js +161 -0
- package/dist/db/fact_store.d.ts +112 -0
- package/dist/db/fact_store.d.ts.map +1 -0
- package/dist/db/fact_store.js +225 -0
- package/dist/server/env.d.ts +2 -0
- package/dist/server/env.d.ts.map +1 -1
- package/dist/server/env.js +6 -0
- package/dist/server/fact_write.d.ts +32 -0
- package/dist/server/fact_write.d.ts.map +1 -0
- package/dist/server/fact_write.js +56 -0
- package/dist/server/file_fact_fetcher.d.ts +42 -0
- package/dist/server/file_fact_fetcher.d.ts.map +1 -0
- package/dist/server/file_fact_fetcher.js +60 -0
- package/dist/server/file_fact_url.d.ts +53 -0
- package/dist/server/file_fact_url.d.ts.map +1 -0
- package/dist/server/file_fact_url.js +52 -0
- package/dist/server/serve_fact_route.d.ts +78 -0
- package/dist/server/serve_fact_route.d.ts.map +1 -0
- package/dist/server/serve_fact_route.js +205 -0
- package/dist/testing/CLAUDE.md +58 -5
- package/dist/testing/app_server.d.ts +12 -0
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +36 -2
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +67 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts +10 -0
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -0
- package/dist/testing/cross_backend/account_lifecycle.js +76 -0
- package/dist/testing/cross_backend/capabilities.d.ts +31 -0
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +3 -0
- package/dist/testing/cross_backend/cell_cross_helpers.d.ts +39 -0
- package/dist/testing/cross_backend/cell_cross_helpers.d.ts.map +1 -0
- package/dist/testing/cross_backend/cell_cross_helpers.js +45 -0
- package/dist/testing/cross_backend/cell_crud.d.ts +4 -0
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -0
- package/dist/testing/cross_backend/cell_crud.js +168 -0
- package/dist/testing/cross_backend/cell_relations.d.ts +4 -0
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -0
- package/dist/testing/cross_backend/cell_relations.js +229 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +6 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +5 -0
- package/dist/testing/entities.d.ts.map +1 -1
- package/dist/testing/entities.js +4 -0
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +4 -0
- package/dist/ui/AdminAccounts.svelte +58 -0
- package/dist/ui/AdminAccounts.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +30 -2
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.js +45 -1
- package/dist/ui/admin_rpc_adapters.d.ts +6 -2
- package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
- package/dist/ui/admin_rpc_adapters.js +5 -1
- package/package.json +2 -2
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw queries against the `cell` table.
|
|
3
|
+
*
|
|
4
|
+
* Convention: `deps: QueryDeps` first, no audit side effects, mutations
|
|
5
|
+
* return the affected row (or `null` for not-found).
|
|
6
|
+
*
|
|
7
|
+
* `cell.refs` is auto-extracted from `data` on every create and update via
|
|
8
|
+
* `fact_hash_extract_refs` (depth-first walk for `blake3:`-prefixed strings). Callers
|
|
9
|
+
* never pass `refs` directly — the column is a derived projection of
|
|
10
|
+
* `data` for cells-by-fact discovery, mirroring what a fact store does for
|
|
11
|
+
* JSON facts.
|
|
12
|
+
*
|
|
13
|
+
* Soft delete via `deleted_at`. All `get` / `list` queries exclude
|
|
14
|
+
* tombstones by default; `include_deleted: true` opts in for admin /
|
|
15
|
+
* audit views.
|
|
16
|
+
*
|
|
17
|
+
* `path` uniqueness is global, enforced by `idx_cell_path_unique` (partial
|
|
18
|
+
* on active rows). Path reuse after soft delete falls out of the partial
|
|
19
|
+
* index — queries do not need special handling.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
import type { QueryDeps } from './query_deps.js';
|
|
24
|
+
import type { Json } from '@fuzdev/fuz_util/json.js';
|
|
25
|
+
import type { Uuid } from '@fuzdev/fuz_util/id.js';
|
|
26
|
+
import { type FactHash } from '@fuzdev/fuz_util/fact_hash.js';
|
|
27
|
+
import type { CellData } from '../auth/cell_data_schema.js';
|
|
28
|
+
import type { CellVisibility } from '../auth/cell_action_specs.js';
|
|
29
|
+
/**
|
|
30
|
+
* Row shape returned by `cell` SELECTs. `data` is typed as `CellData` —
|
|
31
|
+
* the storage layer trusts the wire validation; the row is what was
|
|
32
|
+
* written, and the wire validates `CellData` on every write.
|
|
33
|
+
*
|
|
34
|
+
* Parent↔child membership and named relations live in the `cell_item` /
|
|
35
|
+
* `cell_field` sibling tables (see `cell_item_queries.ts` /
|
|
36
|
+
* `cell_field_queries.ts`). The cell row carries identity + content only.
|
|
37
|
+
*
|
|
38
|
+
* `grant_count` is a derived projection (correlated subquery against
|
|
39
|
+
* `cell_grant` keyed by `cell_id`, served by `idx_cell_grant_cell`) —
|
|
40
|
+
* not a table column. New cells naturally land at 0.
|
|
41
|
+
*/
|
|
42
|
+
export interface CellRow {
|
|
43
|
+
id: Uuid;
|
|
44
|
+
data: CellData;
|
|
45
|
+
visibility: CellVisibility;
|
|
46
|
+
path: string | null;
|
|
47
|
+
refs: Array<FactHash> | null;
|
|
48
|
+
created_at: Date;
|
|
49
|
+
updated_at: Date | null;
|
|
50
|
+
deleted_at: Date | null;
|
|
51
|
+
created_by: Uuid | null;
|
|
52
|
+
updated_by: Uuid | null;
|
|
53
|
+
grant_count: number;
|
|
54
|
+
}
|
|
55
|
+
/** Input for `query_cell_create`. `refs` is derived from `data`. */
|
|
56
|
+
export interface CellCreateQueryInput {
|
|
57
|
+
data: Json;
|
|
58
|
+
visibility?: CellVisibility;
|
|
59
|
+
path?: string | null;
|
|
60
|
+
created_by?: Uuid | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Patch for `query_cell_update`. Fields left `undefined` are unchanged;
|
|
64
|
+
* `path` may be explicitly set to `null` to clear. `refs` is re-derived
|
|
65
|
+
* from `data` whenever `data` is updated.
|
|
66
|
+
*/
|
|
67
|
+
export interface CellUpdatePatch {
|
|
68
|
+
data?: Json;
|
|
69
|
+
visibility?: CellVisibility;
|
|
70
|
+
path?: string | null;
|
|
71
|
+
updated_by?: Uuid | null;
|
|
72
|
+
}
|
|
73
|
+
/** Common pagination + tombstone-visibility options for list queries. */
|
|
74
|
+
export interface CellListOptions {
|
|
75
|
+
limit?: number;
|
|
76
|
+
offset?: number;
|
|
77
|
+
include_deleted?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Insert a cell row, deriving `refs` from `data`.
|
|
81
|
+
*
|
|
82
|
+
* `updated_by` is left NULL on insert — same convention as `updated_at`
|
|
83
|
+
* (NULL until first update). The "last modifier" stamp is meaningful only
|
|
84
|
+
* after a real edit; copying the creator's id into `updated_by` at create
|
|
85
|
+
* time would make a no-op update by a different actor look authored by
|
|
86
|
+
* the creator.
|
|
87
|
+
*
|
|
88
|
+
* @param deps - query deps
|
|
89
|
+
* @param input - data, optional visibility, path, and ownership
|
|
90
|
+
* @returns the inserted row
|
|
91
|
+
* @mutates `cell` - inserts one row
|
|
92
|
+
*/
|
|
93
|
+
export declare const query_cell_create: (deps: QueryDeps, input: CellCreateQueryInput) => Promise<CellRow>;
|
|
94
|
+
/**
|
|
95
|
+
* Fetch a cell by id. Excludes soft-deleted rows by default.
|
|
96
|
+
*
|
|
97
|
+
* @param deps - query deps
|
|
98
|
+
* @param id - cell id
|
|
99
|
+
* @param options - `include_deleted: true` returns tombstones
|
|
100
|
+
* @returns the row or `null` when not found (or soft-deleted and not requested)
|
|
101
|
+
*/
|
|
102
|
+
export declare const query_cell_get: (deps: QueryDeps, id: Uuid, options?: {
|
|
103
|
+
include_deleted?: boolean;
|
|
104
|
+
}) => Promise<CellRow | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Fetch a cell by `path`. Excludes soft-deleted rows; the global partial
|
|
107
|
+
* unique index on `path WHERE deleted_at IS NULL` guarantees at most one
|
|
108
|
+
* result.
|
|
109
|
+
*
|
|
110
|
+
* @param deps - query deps
|
|
111
|
+
* @param path - the named lookup alias (e.g. `/map/main`)
|
|
112
|
+
* @returns the row or `null` when not found
|
|
113
|
+
*/
|
|
114
|
+
export declare const query_cell_get_by_path: (deps: QueryDeps, path: string) => Promise<CellRow | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Bulk-load active cell rows by id, **no visibility filter applied**. Used
|
|
117
|
+
* by the strict relation-read filter (`auth/cell_relation_visibility.ts`'s
|
|
118
|
+
* `filter_visible_target_ids`), which runs `can_view_cell` per row in
|
|
119
|
+
* memory rather than in SQL. Soft-deleted rows are excluded so relations
|
|
120
|
+
* to tombstones never surface.
|
|
121
|
+
*
|
|
122
|
+
* @param deps - query deps
|
|
123
|
+
* @param ids - cell ids to load (duplicates are harmless)
|
|
124
|
+
* @returns active rows in arbitrary order (caller indexes by `id`)
|
|
125
|
+
*/
|
|
126
|
+
export declare const query_cell_load_many: (deps: QueryDeps, ids: ReadonlyArray<Uuid>) => Promise<Array<CellRow>>;
|
|
127
|
+
/**
|
|
128
|
+
* Update a cell. Fields left `undefined` in the patch keep their existing
|
|
129
|
+
* value; explicit `null` writes `NULL`. `refs` is re-derived from `data`
|
|
130
|
+
* whenever the patch updates `data`. `updated_at` is bumped to `NOW()`
|
|
131
|
+
* on every successful update.
|
|
132
|
+
*
|
|
133
|
+
* @param deps - query deps
|
|
134
|
+
* @param id - cell id
|
|
135
|
+
* @param patch - subset of mutable fields
|
|
136
|
+
* @returns the updated row, or `null` when no row matched (already deleted
|
|
137
|
+
* or never existed)
|
|
138
|
+
* @mutates `cell` - updates one row
|
|
139
|
+
*/
|
|
140
|
+
export declare const query_cell_update: (deps: QueryDeps, id: Uuid, patch: CellUpdatePatch) => Promise<CellRow | null>;
|
|
141
|
+
/**
|
|
142
|
+
* Soft-delete a cell. Sets `deleted_at = NOW()`, `updated_at = NOW()`,
|
|
143
|
+
* and `updated_by = options.deleted_by` (or `NULL`). No-op when the row
|
|
144
|
+
* is already deleted.
|
|
145
|
+
*
|
|
146
|
+
* @param deps - query deps
|
|
147
|
+
* @param id - cell id
|
|
148
|
+
* @param options - `deleted_by` records who triggered the delete
|
|
149
|
+
* @returns `true` when a row was soft-deleted, `false` when no active row matched
|
|
150
|
+
* @mutates `cell` - sets `deleted_at` on one row
|
|
151
|
+
*/
|
|
152
|
+
export declare const query_cell_delete: (deps: QueryDeps, id: Uuid, options?: {
|
|
153
|
+
deleted_by?: Uuid | null;
|
|
154
|
+
}) => Promise<boolean>;
|
|
155
|
+
/**
|
|
156
|
+
* List cells whose `data.kind` matches the given value, newest first.
|
|
157
|
+
* Uses the `idx_cell_data` GIN index (`data @> ...`).
|
|
158
|
+
*
|
|
159
|
+
* @param deps - query deps
|
|
160
|
+
* @param kind - `data.kind` value to match (e.g. `'collection'`, `'entry'`)
|
|
161
|
+
* @param options - pagination
|
|
162
|
+
* @returns matching active rows
|
|
163
|
+
*/
|
|
164
|
+
export declare const query_cell_list_by_data_kind: (deps: QueryDeps, kind: string, options?: Pick<CellListOptions, "limit" | "offset">) => Promise<Array<CellRow>>;
|
|
165
|
+
/**
|
|
166
|
+
* List active cells created by an actor, newest first. Backed by the
|
|
167
|
+
* `idx_cell_created_by` partial index.
|
|
168
|
+
*
|
|
169
|
+
* @param deps - query deps
|
|
170
|
+
* @param actor_id - the creator's actor id
|
|
171
|
+
* @param options - pagination
|
|
172
|
+
* @returns matching active rows
|
|
173
|
+
*/
|
|
174
|
+
export declare const query_cell_list_by_creator: (deps: QueryDeps, actor_id: Uuid, options?: Pick<CellListOptions, "limit" | "offset">) => Promise<Array<CellRow>>;
|
|
175
|
+
/**
|
|
176
|
+
* Filterable list query for the generic `cell_list` RPC.
|
|
177
|
+
*
|
|
178
|
+
* Takes a flat filter shape (single optional clause per dimension; the
|
|
179
|
+
* `cell_list` API explicitly does NOT support OR'd alternatives within a
|
|
180
|
+
* dimension — keep it simple) plus an optional viewer-aware visibility
|
|
181
|
+
* predicate.
|
|
182
|
+
*
|
|
183
|
+
* The visibility predicate mirrors `can_view_cell` in SQL form:
|
|
184
|
+
*
|
|
185
|
+
* ```
|
|
186
|
+
* (viewer_is_admin
|
|
187
|
+
* OR cell.visibility = 'public'
|
|
188
|
+
* OR (viewer_actor_id IS NOT NULL AND created_by = viewer_actor_id)
|
|
189
|
+
* OR (viewer_actor_id IS NOT NULL AND <grant admits caller>))
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* The grants branch closes parity with `can_view_cell`: a SQL `EXISTS`
|
|
193
|
+
* over `cell_grant`, parameterized by the caller's `actor_id` and the
|
|
194
|
+
* parallel `(role[], scope_id[])` projection of `auth.role_grants`. The
|
|
195
|
+
* caller's role_grants are materialized once via a `caller_role_grants`
|
|
196
|
+
* CTE so the role-grant `unnest` isn't re-scanned per outer row. Empty
|
|
197
|
+
* role_grant arrays are fine: the CTE yields zero rows, the inner EXISTS
|
|
198
|
+
* returns false, and the actor-grant branch still fires for actor-shaped
|
|
199
|
+
* grants.
|
|
200
|
+
*
|
|
201
|
+
* `shared_with_caller_only: true` (`shared_with: 'me'` at the wire layer)
|
|
202
|
+
* takes a **different SQL shape**: instead of layering an extra
|
|
203
|
+
* conjunction on the cell-driven scan, it semi-joins through
|
|
204
|
+
* `cell_grant`, letting the planner drive from the (typically tiny)
|
|
205
|
+
* admitted-grant set via `idx_cell_grant_actor` /
|
|
206
|
+
* `idx_cell_grant_role_scope` rather than scanning every cell row. For a
|
|
207
|
+
* sharee with N grants over a table of M cells, the cost drops from
|
|
208
|
+
* O(M) to O(N + matched-cells). Owner-is-implicit (a cell's owner never
|
|
209
|
+
* appears as a grant principal) means the grants branch is itself
|
|
210
|
+
* owner-excluding, but the explicit `created_by IS DISTINCT FROM caller`
|
|
211
|
+
* guards against any future deviation. The shared_with branch does NOT
|
|
212
|
+
* bypass for admin: an admin asking "what's shared with me" wants their
|
|
213
|
+
* own grant footprint, not every cell.
|
|
214
|
+
*
|
|
215
|
+
* Soft-deleted rows are excluded by default; opt-in via `include_deleted`.
|
|
216
|
+
*
|
|
217
|
+
* @param deps - query deps
|
|
218
|
+
* @param params - filter + visibility + ordering + pagination
|
|
219
|
+
* @returns matching rows, ordered per `order_by` / `order_direction`
|
|
220
|
+
*/
|
|
221
|
+
export declare const query_cell_list: (deps: QueryDeps, params: CellListParams) => Promise<Array<CellRow>>;
|
|
222
|
+
/** Parameters for `query_cell_list`. All filter dimensions are optional. */
|
|
223
|
+
export interface CellListParams {
|
|
224
|
+
/** Match `data.kind = ?` via `data @> {"kind": ?}` (uses `idx_cell_data`). */
|
|
225
|
+
data_kind?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Match `cell.visibility = ?` directly on the top-level column.
|
|
228
|
+
* Additional narrowing on top of the SQL-side auth visibility
|
|
229
|
+
* predicate — useful for the public discovery feed where authed
|
|
230
|
+
* callers must NOT see their own private entries mixed in.
|
|
231
|
+
*/
|
|
232
|
+
visibility?: CellVisibility;
|
|
233
|
+
/** Match cells whose `refs[]` contains this hash (uses `idx_cell_refs`). */
|
|
234
|
+
ref?: FactHash;
|
|
235
|
+
/** Filter to cells created by this actor (uses `idx_cell_created_by`). */
|
|
236
|
+
created_by?: Uuid;
|
|
237
|
+
/**
|
|
238
|
+
* Filter to cells whose `path` starts with this prefix. Wildcard
|
|
239
|
+
* metachars in the prefix are NOT special — `starts_with()` does
|
|
240
|
+
* literal matching.
|
|
241
|
+
*/
|
|
242
|
+
path_prefix?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Batch-fetch by id. The visibility predicate still runs, so callers
|
|
245
|
+
* passing ids they can't view simply get fewer rows back. Order of
|
|
246
|
+
* the returned rows follows `order_by` / `order_direction`, not the
|
|
247
|
+
* input list — callers that need positional output (e.g. preserving
|
|
248
|
+
* a collection's `items[]` order) should re-index client-side.
|
|
249
|
+
*/
|
|
250
|
+
ids?: Array<Uuid>;
|
|
251
|
+
/**
|
|
252
|
+
* Viewer actor for the visibility predicate. Pass `null` for
|
|
253
|
+
* unauthenticated callers — only `cell.visibility === 'public'` rows
|
|
254
|
+
* are admitted then.
|
|
255
|
+
*/
|
|
256
|
+
viewer_actor_id: Uuid | null;
|
|
257
|
+
/**
|
|
258
|
+
* When `true`, the visibility predicate is dropped (admin sees all).
|
|
259
|
+
* When `false`, rows pass when public, owned by the viewer, or
|
|
260
|
+
* admitted by a `cell_grant` row.
|
|
261
|
+
*/
|
|
262
|
+
viewer_is_admin: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Caller's `actor_id` for the actor-shaped grant branch. NULL =
|
|
265
|
+
* anonymous (actor-grants can never admit). Kept distinct from
|
|
266
|
+
* `viewer_actor_id` for the predicate's clarity (the visibility branch
|
|
267
|
+
* and the grant branch are independent concerns even when they
|
|
268
|
+
* currently agree).
|
|
269
|
+
*/
|
|
270
|
+
caller_actor_id?: Uuid | null;
|
|
271
|
+
/**
|
|
272
|
+
* Caller's role_grant roles, parallel-array projection of `auth.role_grants`
|
|
273
|
+
* (active-only — middleware filters). Pair-wise aligned with
|
|
274
|
+
* `caller_role_grant_scope_ids`. Empty array (or omitted) admits no
|
|
275
|
+
* role-shaped grants. The two arrays MUST have equal length —
|
|
276
|
+
* `unnest(text[], uuid[])` null-pads on length mismatch and would
|
|
277
|
+
* silently widen role-grant admits.
|
|
278
|
+
*/
|
|
279
|
+
caller_role_grant_roles?: ReadonlyArray<string>;
|
|
280
|
+
/**
|
|
281
|
+
* Caller's role_grant scope ids, parallel-array projection. NULLs in the
|
|
282
|
+
* array mark global (any-scope) role_grants — `IS NOT DISTINCT FROM`
|
|
283
|
+
* handles them per design.
|
|
284
|
+
*/
|
|
285
|
+
caller_role_grant_scope_ids?: ReadonlyArray<Uuid | null>;
|
|
286
|
+
/**
|
|
287
|
+
* When `true`, narrow to cells admitting the caller via a
|
|
288
|
+
* `cell_grant` row AND that the caller does not own. Authenticated
|
|
289
|
+
* only (`viewer_actor_id` must be set). Combine with `data_kind` /
|
|
290
|
+
* `path_prefix` etc. to scope further.
|
|
291
|
+
*/
|
|
292
|
+
shared_with_caller_only?: boolean;
|
|
293
|
+
/** Sort column. Default `created_at`. */
|
|
294
|
+
order_by?: 'created_at' | 'updated_at';
|
|
295
|
+
/** Sort direction. Default `desc`. */
|
|
296
|
+
order_direction?: 'asc' | 'desc';
|
|
297
|
+
/** Page size. */
|
|
298
|
+
limit?: number;
|
|
299
|
+
/** Page offset. */
|
|
300
|
+
offset?: number;
|
|
301
|
+
/** Include soft-deleted rows. Default `false`. */
|
|
302
|
+
include_deleted?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* List active cells whose `refs` array contains the given fact hash,
|
|
306
|
+
* newest first. Backed by the `idx_cell_refs` GIN index.
|
|
307
|
+
*
|
|
308
|
+
* Used by the fact-serving route's authz walk: a fact is viewable iff
|
|
309
|
+
* **at least one** referencing active cell admits the caller via
|
|
310
|
+
* `can_view_cell`. Unreferenced facts (no row returned here) are
|
|
311
|
+
* unreachable through the public surface — orphan-fact GC handles them.
|
|
312
|
+
*
|
|
313
|
+
* `include_grant_count` defaults to true so the row hydrates uniformly
|
|
314
|
+
* with the rest of the cell query surface. The fact-serving route is
|
|
315
|
+
* the one hot path where the count is wasted work — pass `false`
|
|
316
|
+
* there to skip the per-row correlated subquery; the field falls back
|
|
317
|
+
* to a constant 0 so `CellRow` stays type-stable.
|
|
318
|
+
*
|
|
319
|
+
* @param deps - query deps
|
|
320
|
+
* @param hash - fact hash to search for
|
|
321
|
+
* @param options - pagination + grant-count toggle
|
|
322
|
+
* @returns matching active rows
|
|
323
|
+
*/
|
|
324
|
+
export declare const query_cell_list_by_ref: (deps: QueryDeps, hash: FactHash, options?: Pick<CellListOptions, "limit" | "offset"> & {
|
|
325
|
+
include_grant_count?: boolean;
|
|
326
|
+
}) => Promise<Array<CellRow>>;
|
|
327
|
+
//# sourceMappingURL=cell_queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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