@supabase/pg-delta 1.0.0-alpha.26 → 1.0.0-alpha.27

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.
@@ -36,6 +36,9 @@ const foreignTablePropsSchema = z.object({
36
36
  columns: z.array(columnPropsSchema),
37
37
  privileges: z.array(privilegePropsSchema),
38
38
  security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
39
+ // Parent FDW handler/validator — filter metadata only, not in dataFields.
40
+ wrapper_handler: z.string().nullable().optional(),
41
+ wrapper_validator: z.string().nullable().optional(),
39
42
  });
40
43
 
41
44
  type ForeignTablePrivilegeProps = PrivilegeProps;
@@ -51,6 +54,8 @@ export class ForeignTable extends BasePgModel implements TableLikeObject {
51
54
  public readonly columns: ForeignTableProps["columns"];
52
55
  public readonly privileges: ForeignTablePrivilegeProps[];
53
56
  public readonly security_labels: SecurityLabelProps[];
57
+ public readonly wrapper_handler: ForeignTableProps["wrapper_handler"];
58
+ public readonly wrapper_validator: ForeignTableProps["wrapper_validator"];
54
59
 
55
60
  constructor(props: ForeignTableProps) {
56
61
  super();
@@ -67,6 +72,8 @@ export class ForeignTable extends BasePgModel implements TableLikeObject {
67
72
  this.columns = props.columns;
68
73
  this.privileges = props.privileges;
69
74
  this.security_labels = props.security_labels ?? [];
75
+ this.wrapper_handler = props.wrapper_handler ?? null;
76
+ this.wrapper_validator = props.wrapper_validator ?? null;
70
77
  }
71
78
 
72
79
  get stableId(): `foreignTable:${string}` {
@@ -146,12 +153,22 @@ export async function extractForeignTables(
146
153
  c.relowner::regrole::text as owner,
147
154
  quote_ident(srv.srvname) as server,
148
155
  coalesce(ft.ftoptions, array[]::text[]) as options,
149
- c.oid as oid
156
+ c.oid as oid,
157
+ case
158
+ when fdw.fdwhandler = 0 then null
159
+ else p_handler.pronamespace::regnamespace::text || '.' || quote_ident(p_handler.proname)
160
+ end as wrapper_handler,
161
+ case
162
+ when fdw.fdwvalidator = 0 then null
163
+ else p_validator.pronamespace::regnamespace::text || '.' || quote_ident(p_validator.proname)
164
+ end as wrapper_validator
150
165
  from
151
166
  pg_class c
152
167
  inner join pg_foreign_table ft on ft.ftrelid = c.oid
153
168
  inner join pg_foreign_server srv on srv.oid = ft.ftserver
154
169
  inner join pg_foreign_data_wrapper fdw on fdw.oid = srv.srvfdw
170
+ left join pg_catalog.pg_proc p_handler on p_handler.oid = fdw.fdwhandler
171
+ left join pg_catalog.pg_proc p_validator on p_validator.oid = fdw.fdwvalidator
155
172
  left outer join extension_oids e1 on c.oid = e1.objid
156
173
  where
157
174
  c.relkind = 'f'
@@ -165,6 +182,8 @@ export async function extractForeignTables(
165
182
  ft.owner,
166
183
  ft.server,
167
184
  ft.options,
185
+ ft.wrapper_handler,
186
+ ft.wrapper_validator,
168
187
  obj_description(ft.oid, 'pg_class') as comment,
169
188
  coalesce(json_agg(
170
189
  case when a.attname is not null then
@@ -250,7 +269,14 @@ export async function extractForeignTables(
250
269
  left join pg_attrdef ad on a.attrelid = ad.adrelid and a.attnum = ad.adnum
251
270
  left join pg_type ty on ty.oid = a.atttypid
252
271
  group by
253
- ft.oid, ft.schema, ft.name, ft.owner, ft.server, ft.options
272
+ ft.oid,
273
+ ft.schema,
274
+ ft.name,
275
+ ft.owner,
276
+ ft.server,
277
+ ft.options,
278
+ ft.wrapper_handler,
279
+ ft.wrapper_validator
254
280
  order by
255
281
  ft.schema, ft.name
256
282
  `);
@@ -26,6 +26,9 @@ const serverPropsSchema = z.object({
26
26
  options: z.array(z.string()).nullable(),
27
27
  comment: z.string().nullable(),
28
28
  privileges: z.array(privilegePropsSchema),
29
+ // Parent FDW handler/validator — filter metadata only, not in dataFields.
30
+ wrapper_handler: z.string().nullable().optional(),
31
+ wrapper_validator: z.string().nullable().optional(),
29
32
  });
30
33
 
31
34
  type ServerPrivilegeProps = PrivilegeProps;
@@ -40,6 +43,8 @@ export class Server extends BasePgModel {
40
43
  public readonly options: ServerProps["options"];
41
44
  public readonly comment: ServerProps["comment"];
42
45
  public readonly privileges: ServerPrivilegeProps[];
46
+ public readonly wrapper_handler: ServerProps["wrapper_handler"];
47
+ public readonly wrapper_validator: ServerProps["wrapper_validator"];
43
48
 
44
49
  constructor(props: ServerProps) {
45
50
  super();
@@ -55,6 +60,8 @@ export class Server extends BasePgModel {
55
60
  this.options = props.options;
56
61
  this.comment = props.comment;
57
62
  this.privileges = props.privileges;
63
+ this.wrapper_handler = props.wrapper_handler ?? null;
64
+ this.wrapper_validator = props.wrapper_validator ?? null;
58
65
  }
59
66
 
60
67
  get stableId(): `server:${string}` {
@@ -112,10 +119,20 @@ export async function extractServers(pool: Pool): Promise<Server[]> {
112
119
  )
113
120
  from lateral aclexplode(srv.srvacl) as x(grantor, grantee, privilege_type, is_grantable)
114
121
  ), '[]'
115
- ) as privileges
122
+ ) as privileges,
123
+ case
124
+ when fdw.fdwhandler = 0 then null
125
+ else p_handler.pronamespace::regnamespace::text || '.' || quote_ident(p_handler.proname)
126
+ end as wrapper_handler,
127
+ case
128
+ when fdw.fdwvalidator = 0 then null
129
+ else p_validator.pronamespace::regnamespace::text || '.' || quote_ident(p_validator.proname)
130
+ end as wrapper_validator
116
131
  from
117
132
  pg_catalog.pg_foreign_server srv
118
133
  inner join pg_catalog.pg_foreign_data_wrapper fdw on fdw.oid = srv.srvfdw
134
+ left join pg_catalog.pg_proc p_handler on p_handler.oid = fdw.fdwhandler
135
+ left join pg_catalog.pg_proc p_validator on p_validator.oid = fdw.fdwvalidator
119
136
  where
120
137
  not fdw.fdwname like any(array['pg\\_%'])
121
138
  order by
@@ -18,6 +18,9 @@ const userMappingPropsSchema = z.object({
18
18
  user: z.string(),
19
19
  server: z.string(),
20
20
  options: z.array(z.string()).nullable(),
21
+ // Parent FDW handler/validator — filter metadata only, not in dataFields.
22
+ wrapper_handler: z.string().nullable().optional(),
23
+ wrapper_validator: z.string().nullable().optional(),
21
24
  });
22
25
 
23
26
  export type UserMappingProps = z.infer<typeof userMappingPropsSchema>;
@@ -26,6 +29,8 @@ export class UserMapping extends BasePgModel {
26
29
  public readonly user: UserMappingProps["user"];
27
30
  public readonly server: UserMappingProps["server"];
28
31
  public readonly options: UserMappingProps["options"];
32
+ public readonly wrapper_handler: UserMappingProps["wrapper_handler"];
33
+ public readonly wrapper_validator: UserMappingProps["wrapper_validator"];
29
34
 
30
35
  constructor(props: UserMappingProps) {
31
36
  super();
@@ -36,6 +41,8 @@ export class UserMapping extends BasePgModel {
36
41
 
37
42
  // Data fields
38
43
  this.options = props.options;
44
+ this.wrapper_handler = props.wrapper_handler ?? null;
45
+ this.wrapper_validator = props.wrapper_validator ?? null;
39
46
  }
40
47
 
41
48
  get stableId(): `userMapping:${string}:${string}` {
@@ -74,11 +81,21 @@ export async function extractUserMappings(pool: Pool): Promise<UserMapping[]> {
74
81
  else um.umuser::regrole::text
75
82
  end as user,
76
83
  quote_ident(srv.srvname) as server,
77
- coalesce(um.umoptions, array[]::text[]) as options
84
+ coalesce(um.umoptions, array[]::text[]) as options,
85
+ case
86
+ when fdw.fdwhandler = 0 then null
87
+ else p_handler.pronamespace::regnamespace::text || '.' || quote_ident(p_handler.proname)
88
+ end as wrapper_handler,
89
+ case
90
+ when fdw.fdwvalidator = 0 then null
91
+ else p_validator.pronamespace::regnamespace::text || '.' || quote_ident(p_validator.proname)
92
+ end as wrapper_validator
78
93
  from
79
94
  pg_catalog.pg_user_mapping um
80
95
  inner join pg_catalog.pg_foreign_server srv on srv.oid = um.umserver
81
96
  inner join pg_catalog.pg_foreign_data_wrapper fdw on fdw.oid = srv.srvfdw
97
+ left join pg_catalog.pg_proc p_handler on p_handler.oid = fdw.fdwhandler
98
+ left join pg_catalog.pg_proc p_validator on p_validator.oid = fdw.fdwvalidator
82
99
  where
83
100
  not fdw.fdwname like any(array['pg\\_%'])
84
101
  order by