-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathblueprint-types.generated.ts
More file actions
988 lines (987 loc) · 46.7 KB
/
blueprint-types.generated.ts
File metadata and controls
988 lines (987 loc) · 46.7 KB
1
2
3
4
5
6
7
8
9
10
11
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
48
49
50
51
52
53
54
55
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
// GENERATED FILE — DO NOT EDIT
//
// Regenerate with:
// cd graphql/node-type-registry && pnpm generate:types
//
// These types match the JSONB shape expected by construct_blueprint().
// All field names are snake_case to match the SQL convention.
/**
* ===========================================================================
* Data node type parameters
* ===========================================================================
*/
;
/** Adds a UUID primary key column with auto-generation default (uuidv7). This is the standard primary key pattern for all tables. */
export interface DataIdParams {
/* Column name for the primary key */
field_name?: string;
}
/** Adds ownership column for direct user ownership. Enables AuthzDirectOwner authorization. */
export interface DataDirectOwnerParams {
/* Column name for owner ID */
owner_field_name?: string;
/* If true, adds a foreign key constraint from owner_id to the users table */
include_user_fk?: boolean;
}
/** Adds entity reference for organization/group scoping. Enables AuthzEntityMembership, AuthzMembership, AuthzOrgHierarchy authorization. */
export interface DataEntityMembershipParams {
/* Column name for entity ID */
entity_field_name?: string;
/* If true, adds a foreign key constraint from entity_id to the users table */
include_user_fk?: boolean;
}
/** Combines direct ownership with entity scoping. Adds both owner_id and entity_id columns. Enables AuthzDirectOwner, AuthzEntityMembership, and AuthzOrgHierarchy authorization. Particularly useful for OrgHierarchy where a user owns a row (owner_id) within an entity (entity_id), and managers above can see subordinate-owned records via the hierarchy closure table. */
export interface DataOwnershipInEntityParams {
/* If true, adds foreign key constraints from owner_id and entity_id to the users table */
include_user_fk?: boolean;
}
/** Adds automatic timestamp tracking with created_at and updated_at columns. */
export interface DataTimestampsParams {
}
/** Adds user tracking for creates/updates with created_by and updated_by columns. */
export interface DataPeoplestampsParams {
/* If true, adds foreign key constraints from created_by and updated_by to the users table */
include_user_fk?: boolean;
}
/** Adds publish state columns (is_published, published_at) for content visibility. Enables AuthzPublishable and AuthzTemporal authorization. */
export interface DataPublishableParams {
}
/** Adds soft delete support with deleted_at and is_deleted columns. */
export interface DataSoftDeleteParams {
}
/** Adds a vector embedding column with HNSW or IVFFlat index for similarity search. Supports configurable dimensions, distance metrics (cosine, l2, ip), stale tracking strategies (column, null, hash), and automatic job enqueue triggers for embedding generation. */
export interface DataEmbeddingParams {
/* Name of the vector column */
field_name?: string;
/* Vector dimensions (e.g. 384, 768, 1536, 3072) */
dimensions?: number;
/* Index type for similarity search */
index_method?: "hnsw" | "ivfflat";
/* Distance metric (cosine, l2, ip) */
metric?: "cosine" | "l2" | "ip";
/* Index-specific options. HNSW: {m, ef_construction}. IVFFlat: {lists}. */
index_options?: {
[key: string]: unknown;
};
/* When stale_strategy is column, adds an embedding_stale boolean field */
include_stale_field?: boolean;
/* Column names that feed the embedding. Used by stale trigger to detect content changes. */
source_fields?: string[];
/* Auto-create trigger that enqueues embedding generation jobs */
enqueue_job?: boolean;
/* Task identifier for the job queue */
job_task_name?: string;
/* Strategy for tracking embedding staleness. column: embedding_stale boolean. null: set embedding to NULL. hash: md5 hash of source fields. */
stale_strategy?: "column" | "null" | "hash";
/* Chunking configuration for long-text embedding. Creates an embedding_chunks record that drives automatic text splitting and per-chunk embedding. Omit to skip chunking. */
chunks?: {
/* Name of the text content column in the chunks table */content_field_name?: string;
/* Maximum number of characters per chunk */chunk_size?: number;
/* Number of overlapping characters between consecutive chunks */chunk_overlap?: number;
/* Strategy for splitting text into chunks */chunk_strategy?: "fixed" | "sentence" | "paragraph" | "semantic";
/* Metadata fields from parent to copy into chunks */metadata_fields?: {
[key: string]: unknown;
};
/* Whether to auto-enqueue a chunking job on insert/update */enqueue_chunking_job?: boolean;
/* Task identifier for the chunking job queue */chunking_task_name?: string;
};
}
/** Adds a tsvector column with GIN index and automatic trigger population from source fields. Enables PostgreSQL full-text search with configurable weights and language support. Leverages the existing metaschema full_text_search infrastructure. */
export interface DataFullTextSearchParams {
/* Name of the tsvector column */
field_name?: string;
/* Source columns that feed the tsvector. Each has a field name, weight (A-D), and language config. */
source_fields: {
/* Name of the source column */field: string;
/* tsvector weight class (A=highest, D=lowest) */weight?: "A" | "B" | "C" | "D";
/* PostgreSQL text search configuration */lang?: string;
}[];
/* Weight for this algorithm in composite searchScore */
search_score_weight?: number;
}
/** Creates a BM25 index on an existing text column using pg_textsearch. Enables statistical relevance ranking with configurable k1 and b parameters. The BM25 index is auto-detected by graphile-search. */
export interface DataBm25Params {
/* Name of existing text column to index with BM25 */
field_name: string;
/* PostgreSQL text search configuration for BM25 */
text_config?: string;
/* BM25 k1 parameter: term frequency saturation (typical: 1.2-2.0) */
k1?: number;
/* BM25 b parameter: document length normalization (0=none, 1=full, typical: 0.75) */
b?: number;
/* Weight for this algorithm in composite searchScore */
search_score_weight?: number;
}
/** Composite node type that orchestrates multiple search modalities (full-text search, BM25, embeddings, trigram) on a single table. Configures per-table search score weights, normalization strategy, and recency boost via the @searchConfig smart tag. */
export interface DataSearchParams {
/* DataFullTextSearch parameters. Omit to skip FTS setup. */
full_text_search?: {
field_name?: string;
source_fields?: {
field: string;
weight?: "A" | "B" | "C" | "D";
lang?: string;
}[];
search_score_weight?: number;
};
/* DataBm25 parameters. Omit to skip BM25 setup. */
bm25?: {
field_name?: string;
text_config?: string;
k1?: number;
b?: number;
search_score_weight?: number;
};
/* DataEmbedding parameters. Omit to skip embedding setup. */
embedding?: {
field_name?: string;
dimensions?: number;
index_method?: "hnsw" | "ivfflat";
metric?: "cosine" | "l2" | "ip";
source_fields?: string[];
search_score_weight?: number;
/* Chunking configuration for long-text embedding. Creates an embedding_chunks record that drives automatic text splitting and per-chunk embedding. Omit to skip chunking. */chunks?: {
/* Name of the text content column in the chunks table */content_field_name?: string;
/* Maximum number of characters per chunk */chunk_size?: number;
/* Number of overlapping characters between consecutive chunks */chunk_overlap?: number;
/* Strategy for splitting text into chunks */chunk_strategy?: "fixed" | "sentence" | "paragraph" | "semantic";
/* Metadata fields from parent to copy into chunks */metadata_fields?: {
[key: string]: unknown;
};
/* Whether to auto-enqueue a chunking job on insert/update */enqueue_chunking_job?: boolean;
/* Task identifier for the chunking job queue */chunking_task_name?: string;
};
};
/* Field names to tag with @trgmSearch for fuzzy/typo-tolerant matching */
trgm_fields?: string[];
/* Unified search score configuration written to @searchConfig smart tag */
search_config?: {
/* Per-algorithm weights: {tsv: 1.5, bm25: 1.0, pgvector: 0.8, trgm: 0.3} */weights?: {
[key: string]: unknown;
};
/* Score normalization strategy */normalization?: "linear" | "sigmoid";
/* Enable recency boost for search results */boost_recent?: boolean;
/* Timestamp field for recency boost (e.g. created_at, updated_at) */boost_recency_field?: string;
/* Decay rate for recency boost (0-1, lower = faster decay) */boost_recency_decay?: number;
};
}
/** Adds a PostGIS geometry or geography column with a spatial index (GiST or SP-GiST). Supports configurable geometry types (Point, Polygon, etc.), SRID, and dimensionality. The graphile-postgis plugin auto-detects geometry/geography columns by codec type for spatial filtering (ST_Contains, ST_DWithin, bbox operators). */
export interface DataPostGISParams {
/* Name of the geometry/geography column */
field_name?: string;
/* PostGIS geometry type constraint */
geometry_type?: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon" | "GeometryCollection" | "Geometry";
/* Spatial Reference System Identifier (e.g. 4326 for WGS84) */
srid?: number;
/* Coordinate dimension (2=XY, 3=XYZ, 4=XYZM) */
dimension?: 2 | 3 | 4;
/* Use geography type instead of geometry (for geodetic calculations on the sphere) */
use_geography?: boolean;
/* Spatial index method */
index_method?: "gist" | "spgist";
}
/** Creates a derived/materialized geometry field on the parent table that automatically aggregates geometries from a source (child) table via triggers. When child rows are inserted/updated/deleted, the parent aggregate field is recalculated using the specified PostGIS aggregation function (ST_Union, ST_Collect, ST_ConvexHull, ST_ConcaveHull). Useful for materializing spatial boundaries from collections of points or polygons. */
export interface DataPostGISAggregateParams {
/* Name of the aggregate geometry column on the parent table */
field_name?: string;
/* UUID of the source (child) table containing individual geometries */
source_table_id: string;
/* Name of the geometry column on the source table */
source_geom_field?: string;
/* Name of the foreign key column on the source table pointing to the parent */
source_fk_field: string;
/* PostGIS aggregation function: union (ST_Union, merges overlapping), collect (ST_Collect, groups without merging), convex_hull (smallest convex polygon), concave_hull (tighter boundary) */
aggregate_function?: "union" | "collect" | "convex_hull" | "concave_hull";
/* Output geometry type constraint for the aggregate field */
geometry_type?: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon" | "GeometryCollection" | "Geometry";
/* Spatial Reference System Identifier (e.g. 4326 for WGS84) */
srid?: number;
/* Coordinate dimension (2=XY, 3=XYZ, 4=XYZM) */
dimension?: 2 | 3 | 4;
/* Use geography type instead of geometry */
use_geography?: boolean;
/* Spatial index method for the aggregate field */
index_method?: "gist" | "spgist";
}
/** Dynamically creates PostgreSQL triggers that enqueue jobs via app_jobs.add_job() when table rows are inserted, updated, or deleted. Supports configurable payload strategies (full row, row ID, selected fields, or custom mapping), conditional firing via WHEN clauses, watched field changes, and extended job options (queue, priority, delay, max attempts). */
export interface DataJobTriggerParams {
/* Job task identifier passed to add_job (e.g., process_invoice, sync_to_stripe) */
task_identifier: string;
/* How to build the job payload: row (full NEW/OLD), row_id (just id), fields (selected columns), custom (mapped columns) */
payload_strategy?: "row" | "row_id" | "fields" | "custom";
/* Column names to include in payload (only for fields strategy) */
payload_fields?: string[];
/* Key-to-column mapping for custom payload (e.g., {"invoice_id": "id", "total": "amount"}) */
payload_custom?: {
[key: string]: unknown;
};
/* Trigger events to create */
events?: ("INSERT" | "UPDATE" | "DELETE")[];
/* Include OLD row in payload (for UPDATE triggers) */
include_old?: boolean;
/* Include table/schema metadata in payload */
include_meta?: boolean;
/* Column name for conditional WHEN clause (fires only when field equals condition_value) */
condition_field?: string;
/* Value to compare against condition_field in WHEN clause */
condition_value?: string;
/* For UPDATE triggers, only fire when these fields change (uses DISTINCT FROM) */
watch_fields?: string[];
/* Static job key for upsert semantics (prevents duplicate jobs) */
job_key?: string;
/* Job queue name for routing to specific workers */
queue_name?: string;
/* Job priority (lower = higher priority) */
priority?: number;
/* Delay before job runs as PostgreSQL interval (e.g., 30 seconds, 5 minutes) */
run_at_delay?: string;
/* Maximum retry attempts for the job */
max_attempts?: number;
}
/** Adds a citext[] tags column with GIN index for efficient array containment queries (@>, &&). Standard tagging pattern for categorization and filtering. */
export interface DataTagsParams {
/* Column name for the tags array */
field_name?: string;
/* Default value expression for the tags column */
default_value?: string;
/* Whether the column has a NOT NULL constraint */
is_required?: boolean;
}
/** Adds a status column with B-tree index for efficient equality filtering and sorting. Optionally constrains values via CHECK constraint when allowed_values is provided. */
export interface DataStatusFieldParams {
/* Column name for the status field */
field_name?: string;
/* Column type (text or citext) */
type?: string;
/* Default value expression (e.g., active) */
default_value?: string;
/* Whether the column has a NOT NULL constraint */
is_required?: boolean;
/* If provided, creates a CHECK constraint restricting the column to these values */
allowed_values?: string[];
}
/** Adds a JSONB column with optional GIN index for containment queries (@>, ?, ?|, ?&). Standard pattern for semi-structured metadata. */
export interface DataJsonbParams {
/* Column name for the JSONB field */
field_name?: string;
/* Default value expression */
default_value?: string;
/* Whether the column has a NOT NULL constraint */
is_required?: boolean;
/* Whether to create a GIN index */
create_index?: boolean;
}
/** Creates GIN trigram indexes (gin_trgm_ops) on specified text/citext fields for fuzzy LIKE/ILIKE/similarity search. Adds @trgmSearch smart tag for PostGraphile integration. Fields must already exist on the table. */
export interface DataTrgmParams {
/* Field names to create trigram indexes on (fields must already exist on the table) */
fields: string[];
}
/** Auto-generates URL-friendly slugs from field values on insert/update. Attaches BEFORE INSERT and BEFORE UPDATE triggers that call inflection.slugify() on the target field. References fields by name in data jsonb. */
export interface DataSlugParams {
/* Name of the field to slugify */
field_name: string;
/* Optional source field name (defaults to field_name) */
source_field_name?: string;
}
/** Transforms field values using inflection operations (snake_case, camelCase, slugify, plural, singular, etc). Attaches BEFORE INSERT and BEFORE UPDATE triggers. References fields by name in data jsonb. */
export interface DataInflectionParams {
/* Name of the field to transform */
field_name: string;
/* Inflection operations to apply in order */
ops: ("plural" | "singular" | "camel" | "pascal" | "dashed" | "slugify" | "underscore" | "lower" | "upper")[];
}
/** Restricts which user can modify specific columns in shared objects. Creates an AFTER UPDATE trigger that throws OWNED_PROPS when a non-owner tries to change protected fields. References fields by name in data jsonb. */
export interface DataOwnedFieldsParams {
/* Name of the field identifying the owner (e.g. sender_id) */
role_key_field_name: string;
/* Names of fields only this owner can modify */
protected_field_names: string[];
}
/** BEFORE INSERT trigger that copies specified fields from a parent table via a foreign key. The parent row is looked up through RLS (SECURITY INVOKER), so the insert fails if the caller cannot see the parent. Used by the storage module to inherit owner_id and is_public from buckets to files. */
export interface DataInheritFromParentParams {
/* Name of the FK field on this table that references the parent (e.g. bucket_id) */
parent_fk_field: string;
/* Field names to copy from the parent row (e.g. ["owner_id", "is_public"]) */
fields: string[];
/* Parent table name (optional fallback if FK not yet registered in metaschema) */
parent_table?: string;
/* Parent table schema (optional, defaults to same schema as child table) */
parent_schema?: string;
}
/** BEFORE INSERT trigger that forces a field to the value of jwt_public.current_user_id(). Prevents clients from spoofing the actor/uploader identity. The field value is always overwritten regardless of what the client provides. */
export interface DataForceCurrentUserParams {
/* Name of the field to force to current_user_id() */
field_name?: string;
}
/** BEFORE UPDATE trigger that prevents changes to a list of specified fields after INSERT. Raises an exception if any of the listed fields have changed. Unlike FieldImmutable (single-field), this handles multiple fields in a single trigger for efficiency. */
export interface DataImmutableFieldsParams {
/* Field names that cannot be modified after INSERT (e.g. ["key", "bucket_id", "owner_id"]) */
fields: string[];
}
/** Creates a user profiles table with standard profile fields (profile_picture, bio, first_name, last_name, tags, desired). Uses AuthzDirectOwner for edit access and AuthzAllowAll for select. */
export type TableUserProfilesParams = {};
/** Creates an organization settings table with standard business fields (legal_name, address fields). Uses AuthzEntityMembership for access control. */
export type TableOrganizationSettingsParams = {};
/** Creates a user settings table for user-specific configuration. Uses AuthzDirectOwner for access control. */
export type TableUserSettingsParams = {};
/**
* ===========================================================================
* Authz node type parameters
* ===========================================================================
*/
;
/** Direct equality comparison between a table column and the current user ID. Simplest authorization pattern with no subqueries. */
export interface AuthzDirectOwnerParams {
/* Column name containing the owner user ID (e.g., owner_id) */
entity_field: string;
}
/** OR logic for multiple ownership fields. Checks if current user matches any of the specified fields. */
export interface AuthzDirectOwnerAnyParams {
/* Array of column names to check for ownership */
entity_fields: string[];
}
/** Membership check that verifies the user has membership (optionally with specific permission) without binding to any entity from the row. Uses EXISTS subquery against SPRT table. */
export interface AuthzMembershipParams {
/* Scope: 1=app, 2=org, 3=group (or string name resolved via membership_types_module) */
membership_type: number | string;
/* Single permission name to check (resolved to bitstring mask) */
permission?: string;
/* Multiple permission names to check (ORed together into mask) */
permissions?: string[];
/* If true, require is_admin flag */
is_admin?: boolean;
/* If true, require is_owner flag */
is_owner?: boolean;
}
/** Membership check scoped by a field on the row through the SPRT table. Verifies user has membership in the entity referenced by the row. */
export interface AuthzEntityMembershipParams {
/* Column name referencing the entity (e.g., entity_id, org_id) */
entity_field: string;
/* Scope: 1=app, 2=org, 3=group (or string name resolved via membership_types_module) */
membership_type?: number | string;
/* Single permission name to check (resolved to bitstring mask) */
permission?: string;
/* Multiple permission names to check (ORed together into mask) */
permissions?: string[];
/* If true, require is_admin flag */
is_admin?: boolean;
/* If true, require is_owner flag */
is_owner?: boolean;
}
/** JOIN-based membership verification through related tables. Joins SPRT table with another table to verify membership. */
export interface AuthzRelatedEntityMembershipParams {
/* Column name on protected table referencing the join table */
entity_field: string;
/* Scope: 1=app, 2=org, 3=group (or string name resolved via membership_types_module) */
membership_type?: number | string;
/* UUID of the join table (alternative to obj_schema/obj_table) */
obj_table_id?: string;
/* Schema of the join table (or use obj_table_id) */
obj_schema?: string;
/* Name of the join table (or use obj_table_id) */
obj_table?: string;
/* UUID of field on join table (alternative to obj_field) */
obj_field_id?: string;
/* Field name on join table to match against SPRT entity_id */
obj_field?: string;
/* Single permission name to check (resolved to bitstring mask) */
permission?: string;
/* Multiple permission names to check (ORed together into mask) */
permissions?: string[];
/* If true, require is_admin flag */
is_admin?: boolean;
/* If true, require is_owner flag */
is_owner?: boolean;
}
/** Organizational hierarchy visibility using closure table. Managers can see subordinate data or subordinates can see manager data. */
export interface AuthzOrgHierarchyParams {
/* down=manager sees subordinates, up=subordinate sees managers */
direction: "up" | "down";
/* Field referencing the org entity */
entity_field?: string;
/* Field referencing the user (e.g., owner_id) */
anchor_field: string;
/* Optional max depth to limit visibility */
max_depth?: number;
}
/** Time-window based access control. Restricts access based on valid_from and/or valid_until timestamps. At least one of valid_from_field or valid_until_field must be provided. */
export interface AuthzTemporalParams {
/* Column for start time (at least one of valid_from_field or valid_until_field required) */
valid_from_field?: string;
/* Column for end time (at least one of valid_from_field or valid_until_field required) */
valid_until_field?: string;
/* Include start boundary */
valid_from_inclusive?: boolean;
/* Include end boundary */
valid_until_inclusive?: boolean;
}
/** Published state access control. Restricts access to records that are published. */
export interface AuthzPublishableParams {
/* Boolean field indicating published state */
is_published_field?: string;
/* Timestamp field for publish time */
published_at_field?: string;
/* Require published_at to be non-null and <= now() */
require_published_at?: boolean;
}
/** Check if current user is in an array column on the same row. */
export interface AuthzMemberListParams {
/* Column name containing the array of user IDs */
array_field: string;
}
/** Array membership check in a related table. */
export interface AuthzRelatedMemberListParams {
/* Schema of the related table */
owned_schema: string;
/* Name of the related table */
owned_table: string;
/* Array column in related table */
owned_table_key: string;
/* FK column in related table */
owned_table_ref_key: string;
/* PK column in protected table */
this_object_key: string;
}
/** Allows all access. Generates TRUE expression. */
export type AuthzAllowAllParams = {};
/** Denies all access. Generates FALSE expression. */
export type AuthzDenyAllParams = {};
/** Composite authorization policy that combines multiple authorization nodes using boolean logic (AND/OR). The data field contains a JSONB AST with nested authorization nodes. */
export interface AuthzCompositeParams {
/* Boolean expression combining multiple authorization nodes */
BoolExpr?: {
/* Boolean operator: AND_EXPR, OR_EXPR, or NOT_EXPR */boolop?: "AND_EXPR" | "OR_EXPR" | "NOT_EXPR";
/* Array of authorization nodes to combine */args?: {
[key: string]: unknown;
}[];
};
}
/** Peer visibility through shared entity membership. Authorizes access to user-owned rows when the owner and current user are both members of the same entity. Self-joins the SPRT table to find peers. */
export interface AuthzPeerOwnershipParams {
/* Column name on protected table referencing the owning user (e.g., owner_id) */
owner_field: string;
/* Scope: 1=app, 2=org, 3=group (or string name resolved via membership_types_module) */
membership_type?: number | string;
/* Single permission name to check on the current user membership (resolved to bitstring mask) */
permission?: string;
/* Multiple permission names to check on the current user membership (ORed together into mask) */
permissions?: string[];
/* If true, require is_admin flag on current user membership */
is_admin?: boolean;
/* If true, require is_owner flag on current user membership */
is_owner?: boolean;
}
/** Peer visibility through shared entity membership via a related table. Like AuthzPeerOwnership but the owning user is resolved through a FK JOIN to a related table. Combines SPRT self-join with object table JOIN. */
export interface AuthzRelatedPeerOwnershipParams {
/* Column name on protected table referencing the related table (e.g., message_id) */
entity_field: string;
/* Scope: 1=app, 2=org, 3=group (or string name resolved via membership_types_module) */
membership_type?: number | string;
/* UUID of the related table (alternative to obj_schema/obj_table) */
obj_table_id?: string;
/* Schema of the related table (or use obj_table_id) */
obj_schema?: string;
/* Name of the related table (or use obj_table_id) */
obj_table?: string;
/* UUID of field on related table containing the owner user ID (alternative to obj_field) */
obj_field_id?: string;
/* Field name on related table containing the owner user ID (e.g., sender_id) */
obj_field?: string;
/* Field on related table to select for matching entity_field (defaults to id) */
obj_ref_field?: string;
/* Single permission name to check on the current user membership (resolved to bitstring mask) */
permission?: string;
/* Multiple permission names to check on the current user membership (ORed together into mask) */
permissions?: string[];
/* If true, require is_admin flag on current user membership */
is_admin?: boolean;
/* If true, require is_owner flag on current user membership */
is_owner?: boolean;
}
/**
* ===========================================================================
* Relation node type parameters
* ===========================================================================
*/
;
/** Creates a foreign key field on the source table referencing the target table. Auto-derives the FK field name from the target table name using inflection (e.g., projects derives project_id). delete_action is required and must be explicitly provided by the caller. */
export interface RelationBelongsToParams {
/* Table that will have the FK field added */
source_table_id: string;
/* Table being referenced by the FK */
target_table_id: string;
/* FK field name on the source table. Auto-derived from target table name if omitted (e.g., projects → project_id) */
field_name?: string;
/* FK delete action: c=CASCADE, r=RESTRICT, n=SET NULL, d=SET DEFAULT, a=NO ACTION. Required. */
delete_action: "c" | "r" | "n" | "d" | "a";
/* Whether the FK field is NOT NULL */
is_required?: boolean;
}
/** Creates a foreign key field with a unique constraint on the source table referencing the target table. Enforces 1:1 cardinality. Auto-derives the FK field name from the target table name using inflection. delete_action is required and must be explicitly provided by the caller. */
export interface RelationHasOneParams {
/* Table that will have the FK field and unique constraint */
source_table_id: string;
/* Table being referenced by the FK */
target_table_id: string;
/* FK field name on the source table. Auto-derived from target table name if omitted (e.g., users → user_id) */
field_name?: string;
/* FK delete action: c=CASCADE, r=RESTRICT, n=SET NULL, d=SET DEFAULT, a=NO ACTION. Required. */
delete_action: "c" | "r" | "n" | "d" | "a";
/* Whether the FK field is NOT NULL */
is_required?: boolean;
}
/** Creates a foreign key field on the target table referencing the source table. Inverse of RelationBelongsTo — same FK, different perspective. "projects has many tasks" creates tasks.project_id. Auto-derives the FK field name from the source table name using inflection. delete_action is required and must be explicitly provided by the caller. */
export interface RelationHasManyParams {
/* Parent table being referenced by the FK (e.g., projects in projects has many tasks) */
source_table_id: string;
/* Child table that receives the FK field (e.g., tasks in projects has many tasks) */
target_table_id: string;
/* FK field name on the target table. Auto-derived from source table name if omitted (e.g., projects derives project_id) */
field_name?: string;
/* FK delete action: c=CASCADE, r=RESTRICT, n=SET NULL, d=SET DEFAULT, a=NO ACTION. Required. */
delete_action: "c" | "r" | "n" | "d" | "a";
/* Whether the FK field is NOT NULL */
is_required?: boolean;
}
/** Creates a junction table between source and target tables with auto-derived naming and FK fields. The trigger creates a bare table (no implicit DataId or any node_type), adds FK fields to both tables, optionally creates a composite PK (use_composite_key), then forwards all security config to secure_table_provision as-is. The trigger never injects values the caller did not provide. Junction table FKs always CASCADE on delete. */
export interface RelationManyToManyParams {
/* First table in the M:N relationship */
source_table_id: string;
/* Second table in the M:N relationship */
target_table_id: string;
/* Existing junction table to use. If uuid_nil(), a new bare table is created */
junction_table_id?: string;
/* Junction table name. Auto-derived from both table names if omitted (e.g., projects + tags derives project_tags) */
junction_table_name?: string;
/* FK field name on junction for source table. Auto-derived if omitted (e.g., projects derives project_id) */
source_field_name?: string;
/* FK field name on junction for target table. Auto-derived if omitted (e.g., tags derives tag_id) */
target_field_name?: string;
/* When true, creates a composite PK from the two FK fields. When false, no PK is created by the trigger (use node_type=DataId for UUID PK). Mutually exclusive with node_type=DataId. */
use_composite_key?: boolean;
/* Generator for field creation on junction table. Forwarded to secure_table_provision as-is. Examples: DataId, DataEntityMembership, DataDirectOwner. NULL means no additional fields. */
node_type?: string;
/* Configuration for the generator. Forwarded to secure_table_provision as-is. Only used when node_type is set. */
node_data?: {
[key: string]: unknown;
};
/* Database roles to grant privileges to. Forwarded to secure_table_provision as-is. Default: [authenticated] */
grant_roles?: string[];
/* Privilege grants for the junction table as [verb, columns] tuples (e.g. [['select','*'],['insert','*']]). Forwarded to secure_table_provision as-is. Default: select/insert/delete for all columns */
grant_privileges?: string[][];
/* RLS policy type for the junction table. Forwarded to secure_table_provision as-is. NULL means no policy. */
policy_type?: string;
/* Privileges the policy applies to. Forwarded to secure_table_provision as-is. NULL means derived from grant_privileges verbs. */
policy_privileges?: string[];
/* Database role the policy targets. Forwarded to secure_table_provision as-is. NULL means falls back to first grant_role. */
policy_role?: string;
/* Whether the policy is PERMISSIVE (true) or RESTRICTIVE (false). Forwarded to secure_table_provision as-is. */
policy_permissive?: boolean;
/* Policy configuration forwarded to secure_table_provision as-is. Structure varies by policy_type. */
policy_data?: {
[key: string]: unknown;
};
}
/**
* ===========================================================================
* View node type parameters
* ===========================================================================
*/
;
/** Simple column selection from a single source table. Projects all or specific fields. */
export interface ViewTableProjectionParams {
/* UUID of the source table to project from */
source_table_id: string;
/* Optional array of field UUIDs to include (all fields if omitted) */
field_ids?: string[];
/* Optional array of field names to include (alternative to field_ids) */
field_names?: string[];
}
/** Table projection with an Authz* filter baked into the view definition. The view only returns records matching the filter. */
export interface ViewFilteredTableParams {
/* UUID of the source table */
source_table_id: string;
/* Authz* node type name (e.g., AuthzDirectOwner, AuthzPublishable) */
filter_type: string;
/* Parameters for the Authz* filter type */
filter_data?: {
[key: string]: unknown;
};
/* Optional array of field UUIDs to include (alternative to field_names) */
field_ids?: string[];
/* Optional array of field names to include (alternative to field_ids) */
field_names?: string[];
}
/** View that joins multiple tables together. Supports INNER, LEFT, RIGHT, and FULL joins. */
export interface ViewJoinedTablesParams {
/* UUID of the primary (left-most) table */
primary_table_id: string;
/* Optional array of column names to include from the primary table */
primary_columns?: string[];
/* Array of join specifications */
joins: {
/* UUID of the joined table */table_id: string;
join_type?: "INNER" | "LEFT" | "RIGHT" | "FULL";
/* Field on primary table */primary_field: string;
/* Field on joined table */join_field: string;
/* Optional column names to include from this joined table */columns?: string[];
}[];
/* Optional array of field UUIDs to include (alternative to per-table columns) */
field_ids?: string[];
}
/** View with GROUP BY and aggregate functions. Useful for summary/reporting views. */
export interface ViewAggregatedParams {
/* UUID of the source table */
source_table_id: string;
/* Field names to group by */
group_by_fields: string[];
/* Array of aggregate specifications */
aggregates: {
function: "COUNT" | "SUM" | "AVG" | "MIN" | "MAX";
/* Field to aggregate (or * for COUNT) */field?: string;
/* Output column name */alias: string;
}[];
}
/** Advanced view using composite AST for the query. Use when other node types are insufficient (CTEs, UNIONs, complex subqueries, etc.). */
export interface ViewCompositeParams {
/* Composite SELECT query AST (JSONB) */
query_ast: {
[key: string]: unknown;
};
}
/**
* ===========================================================================
* Structural types — Static fallback (no _meta provided)
* ===========================================================================
*/
;
/** A custom field (column) to add to a blueprint table. */
export interface BlueprintField {
/** The column name. */
name: string;
/** The PostgreSQL type (e.g., "text", "integer", "boolean", "uuid"). */
type: string;
/** Whether the column has a NOT NULL constraint. */
is_required?: boolean;
/** SQL default value expression (e.g., "true", "now()"). */
default_value?: string;
/** Comment/description for this field. */
description?: string;
}
/** An RLS policy entry for a blueprint table. Uses $type to match the blueprint JSON convention. */
export interface BlueprintPolicy {
/** Authz* policy type name (e.g., "AuthzDirectOwner", "AuthzAllowAll"). */
$type: "AuthzDirectOwner" | "AuthzDirectOwnerAny" | "AuthzMembership" | "AuthzEntityMembership" | "AuthzRelatedEntityMembership" | "AuthzOrgHierarchy" | "AuthzTemporal" | "AuthzPublishable" | "AuthzMemberList" | "AuthzRelatedMemberList" | "AuthzAllowAll" | "AuthzDenyAll" | "AuthzComposite" | "AuthzPeerOwnership" | "AuthzRelatedPeerOwnership";
/** Privileges this policy applies to (e.g., ["select"], ["insert", "update", "delete"]). */
privileges?: string[];
/** Whether this policy is permissive (true) or restrictive (false). Defaults to true. */
permissive?: boolean;
/** Role for this policy. Defaults to "authenticated". */
policy_role?: string;
/** Optional custom name for this policy. */
policy_name?: string;
/** Policy-specific data (structure varies by policy type). */
data?: Record<string, unknown>;
}
/** A source field contributing to a full-text search tsvector column. */
export interface BlueprintFtsSource {
/** Column name of the source field. */
field: string;
/** TSVector weight: "A", "B", "C", or "D". */
weight: string;
/** Language for text search. Defaults to "english". */
lang?: string;
}
/** A full-text search configuration for a blueprint table (top-level, requires table_name). */
export interface BlueprintFullTextSearch {
/** Table name this full-text search belongs to. */
table_name: string;
/** Optional schema name for disambiguation (falls back to top-level default). */
schema_name?: string;
/** Name of the tsvector field on the table. */
field: string;
/** Source fields that feed into this tsvector. */
sources: BlueprintFtsSource[];
}
/** A full-text search configuration nested inside a table definition (table_name not required). */
export interface BlueprintTableFullTextSearch {
/** Name of the tsvector field on the table. */
field: string;
/** Source fields that feed into this tsvector. */
sources: BlueprintFtsSource[];
/** Optional schema name override. */
schema_name?: string;
}
/** An index definition within a blueprint (top-level, requires table_name). */
export interface BlueprintIndex {
/** Table name this index belongs to. */
table_name: string;
/** Optional schema name for disambiguation (falls back to top-level default). */
schema_name?: string;
/** Single column name for the index. */
column?: string;
/** Array of column names for a multi-column index. */
columns?: string[];
/** Index access method (e.g., "BTREE", "GIN", "GIST", "HNSW", "BM25"). */
access_method: string;
/** Whether this is a unique index. */
is_unique?: boolean;
/** Optional custom name for the index. */
name?: string;
/** Operator classes for the index columns. */
op_classes?: string[];
/** Additional index-specific options. */
options?: Record<string, unknown>;
}
/** An index definition nested inside a table definition (table_name not required). */
export interface BlueprintTableIndex {
/** Single column name for the index. */
column?: string;
/** Array of column names for a multi-column index. */
columns?: string[];
/** Index access method (e.g., "BTREE", "GIN", "GIST", "HNSW", "BM25"). */
access_method: string;
/** Whether this is a unique index. */
is_unique?: boolean;
/** Optional custom name for the index. */
name?: string;
/** Operator classes for the index columns. */
op_classes?: string[];
/** Additional index-specific options. */
options?: Record<string, unknown>;
/** Optional schema name override. */
schema_name?: string;
}
/** A unique constraint definition within a blueprint (top-level, requires table_name). */
export interface BlueprintUniqueConstraint {
/** Table name this unique constraint belongs to. */
table_name: string;
/** Optional schema name for disambiguation (falls back to top-level default). */
schema_name?: string;
/** Column names that form the unique constraint. */
columns: string[];
}
/** A unique constraint nested inside a table definition (table_name not required). */
export interface BlueprintTableUniqueConstraint {
/** Column names that form the unique constraint. */
columns: string[];
/** Optional schema name override. */
schema_name?: string;
}
/**
* ===========================================================================
* Node types -- discriminated union for nodes[] entries
* ===========================================================================
*/
;
/** String shorthand -- just the node type name. */
export type BlueprintNodeShorthand = "AuthzDirectOwner" | "AuthzDirectOwnerAny" | "AuthzMembership" | "AuthzEntityMembership" | "AuthzRelatedEntityMembership" | "AuthzOrgHierarchy" | "AuthzTemporal" | "AuthzPublishable" | "AuthzMemberList" | "AuthzRelatedMemberList" | "AuthzAllowAll" | "AuthzDenyAll" | "AuthzComposite" | "AuthzPeerOwnership" | "AuthzRelatedPeerOwnership" | "DataId" | "DataDirectOwner" | "DataEntityMembership" | "DataOwnershipInEntity" | "DataTimestamps" | "DataPeoplestamps" | "DataPublishable" | "DataSoftDelete" | "DataEmbedding" | "DataFullTextSearch" | "DataBm25" | "DataSearch" | "DataPostGIS" | "DataPostGISAggregate" | "DataJobTrigger" | "DataTags" | "DataStatusField" | "DataJsonb" | "DataTrgm" | "DataSlug" | "DataInflection" | "DataOwnedFields" | "DataInheritFromParent" | "DataForceCurrentUser" | "DataImmutableFields" | "TableUserProfiles" | "TableOrganizationSettings" | "TableUserSettings";
/** Object form -- { $type, data } with typed parameters. */
export type BlueprintNodeObject = {
$type: "AuthzDirectOwner";
data: AuthzDirectOwnerParams;
} | {
$type: "AuthzDirectOwnerAny";
data: AuthzDirectOwnerAnyParams;
} | {
$type: "AuthzMembership";
data: AuthzMembershipParams;
} | {
$type: "AuthzEntityMembership";
data: AuthzEntityMembershipParams;
} | {
$type: "AuthzRelatedEntityMembership";
data: AuthzRelatedEntityMembershipParams;
} | {
$type: "AuthzOrgHierarchy";
data: AuthzOrgHierarchyParams;
} | {
$type: "AuthzTemporal";
data: AuthzTemporalParams;
} | {
$type: "AuthzPublishable";
data: AuthzPublishableParams;
} | {
$type: "AuthzMemberList";
data: AuthzMemberListParams;
} | {
$type: "AuthzRelatedMemberList";
data: AuthzRelatedMemberListParams;
} | {
$type: "AuthzAllowAll";
data?: Record<string, never>;
} | {
$type: "AuthzDenyAll";
data?: Record<string, never>;
} | {
$type: "AuthzComposite";
data: AuthzCompositeParams;
} | {
$type: "AuthzPeerOwnership";
data: AuthzPeerOwnershipParams;
} | {
$type: "AuthzRelatedPeerOwnership";
data: AuthzRelatedPeerOwnershipParams;
} | {
$type: "DataId";
data: DataIdParams;
} | {
$type: "DataDirectOwner";
data: DataDirectOwnerParams;
} | {
$type: "DataEntityMembership";
data: DataEntityMembershipParams;
} | {
$type: "DataOwnershipInEntity";
data: DataOwnershipInEntityParams;
} | {
$type: "DataTimestamps";
data: DataTimestampsParams;
} | {
$type: "DataPeoplestamps";
data: DataPeoplestampsParams;
} | {
$type: "DataPublishable";
data: DataPublishableParams;
} | {
$type: "DataSoftDelete";
data: DataSoftDeleteParams;
} | {
$type: "DataEmbedding";
data: DataEmbeddingParams;
} | {
$type: "DataFullTextSearch";
data: DataFullTextSearchParams;
} | {
$type: "DataBm25";
data: DataBm25Params;
} | {
$type: "DataSearch";
data: DataSearchParams;
} | {
$type: "DataPostGIS";
data: DataPostGISParams;
} | {
$type: "DataPostGISAggregate";
data: DataPostGISAggregateParams;
} | {
$type: "DataJobTrigger";
data: DataJobTriggerParams;
} | {
$type: "DataTags";
data: DataTagsParams;
} | {
$type: "DataStatusField";
data: DataStatusFieldParams;
} | {
$type: "DataJsonb";
data: DataJsonbParams;
} | {
$type: "DataTrgm";
data: DataTrgmParams;
} | {
$type: "DataSlug";
data: DataSlugParams;
} | {
$type: "DataInflection";
data: DataInflectionParams;
} | {
$type: "DataOwnedFields";
data: DataOwnedFieldsParams;
} | {
$type: "DataInheritFromParent";
data: DataInheritFromParentParams;
} | {
$type: "DataForceCurrentUser";
data: DataForceCurrentUserParams;
} | {
$type: "DataImmutableFields";
data: DataImmutableFieldsParams;
} | {
$type: "TableUserProfiles";
data?: Record<string, never>;
} | {
$type: "TableOrganizationSettings";
data?: Record<string, never>;
} | {
$type: "TableUserSettings";
data?: Record<string, never>;
};
/** A node entry in a blueprint table. Either a string shorthand or a typed object. */
export type BlueprintNode = BlueprintNodeShorthand | BlueprintNodeObject;
/**
* ===========================================================================
* Relation types
* ===========================================================================
*/
;
/** A relation entry in a blueprint definition. */
export type BlueprintRelation = {
$type: "RelationBelongsTo";
source_table: string;
target_table: string;
source_schema_name?: string;
target_schema_name?: string;
} & Partial<RelationBelongsToParams> | {
$type: "RelationHasOne";
source_table: string;
target_table: string;
source_schema_name?: string;
target_schema_name?: string;
} & Partial<RelationHasOneParams> | {
$type: "RelationHasMany";
source_table: string;
target_table: string;
source_schema_name?: string;
target_schema_name?: string;
} & Partial<RelationHasManyParams> | {
$type: "RelationManyToMany";
source_table: string;
target_table: string;
source_schema_name?: string;
target_schema_name?: string;
} & Partial<RelationManyToManyParams>;
/**
* ===========================================================================
* Blueprint table and definition
* ===========================================================================
*/
;
/** A table definition within a blueprint. */
export interface BlueprintTable {
/** The PostgreSQL table name to create. */
table_name: string;
/** Optional schema name (falls back to top-level default). */
schema_name?: string;
/** Array of node type entries that define the table's behavior. */
nodes: BlueprintNode[];
/** Custom fields (columns) to add to the table. */
fields?: BlueprintField[];
/** RLS policies for this table. */
policies?: BlueprintPolicy[];
/** Database roles to grant privileges to. Defaults to ["authenticated"]. */
grant_roles?: string[];
/** Privilege grants as [verb, column] tuples or objects. Defaults to empty (no grants — callers must explicitly specify). */
grants?: unknown[];
/** Whether to enable RLS on this table. Defaults to true. */
use_rls?: boolean;
/** Table-level indexes (table_name inherited from parent). */
indexes?: BlueprintTableIndex[];
/** Table-level full-text search configurations (table_name inherited from parent). */
full_text_searches?: BlueprintTableFullTextSearch[];
/** Table-level unique constraints (table_name inherited from parent). */
unique_constraints?: BlueprintTableUniqueConstraint[];
}
/** The complete blueprint definition -- the JSONB shape accepted by construct_blueprint(). */
export interface BlueprintDefinition {
/** Tables to create. */
tables: BlueprintTable[];
/** Relations between tables. */
relations?: BlueprintRelation[];
/** Indexes on table columns. */
indexes?: BlueprintIndex[];
/** Full-text search configurations. */
full_text_searches?: BlueprintFullTextSearch[];
/** Unique constraints on table columns. */
unique_constraints?: BlueprintUniqueConstraint[];
}