@pgxsinkit/server 0.1.32 → 0.1.40
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/README.md +12 -0
- package/bin/pgxsinkit-generate.mjs +25 -0
- package/dist/cli/generate.d.ts +14 -2
- package/dist/cli/generate.d.ts.map +1 -1
- package/dist/electric-proxy.d.ts +30 -2
- package/dist/electric-proxy.d.ts.map +1 -1
- package/dist/index.d.ts +56 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3936 -937
- package/dist/index.js.map +40 -25
- package/dist/migrations/utilities.d.ts +13 -0
- package/dist/migrations/utilities.d.ts.map +1 -0
- package/dist/mutations/plpgsql-apply.d.ts +36 -0
- package/dist/mutations/plpgsql-apply.d.ts.map +1 -0
- package/dist/mutations/route.d.ts +64 -0
- package/dist/mutations/route.d.ts.map +1 -0
- package/dist/mutations/types.d.ts +4 -0
- package/dist/mutations/types.d.ts.map +1 -0
- package/dist/operations-log/ddl.d.ts +6 -0
- package/dist/operations-log/ddl.d.ts.map +1 -1
- package/dist/operations-log/schema.d.ts +2 -32
- package/dist/operations-log/schema.d.ts.map +1 -1
- package/dist/operations-log/types.d.ts +1 -5
- package/dist/operations-log/types.d.ts.map +1 -1
- package/dist/operations-log/writer.d.ts.map +1 -1
- package/dist/router.d.ts +22 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/sql-state.d.ts +23 -0
- package/dist/sql-state.d.ts.map +1 -0
- package/package.json +11 -6
- package/skills/deploying/SKILL.md +162 -0
- package/src/cli/generate.ts +292 -21
- package/src/electric-proxy.ts +280 -45
- package/src/index.ts +146 -59
- package/src/migrations/utilities.ts +25 -0
- package/src/mutations/plpgsql-apply.ts +658 -0
- package/src/mutations/route.ts +1176 -0
- package/src/mutations/{bulk/types.ts → types.ts} +0 -2
- package/src/operations-log/ddl.ts +13 -3
- package/src/operations-log/schema.ts +9 -6
- package/src/operations-log/types.ts +1 -7
- package/src/operations-log/writer.ts +0 -2
- package/src/router.ts +109 -0
- package/src/sql-state.ts +59 -0
- package/dist/mutations/bulk/plpgsql-strategy.d.ts +0 -17
- package/dist/mutations/bulk/plpgsql-strategy.d.ts.map +0 -1
- package/dist/mutations/bulk/route.d.ts +0 -7
- package/dist/mutations/bulk/route.d.ts.map +0 -1
- package/dist/mutations/bulk/types.d.ts +0 -5
- package/dist/mutations/bulk/types.d.ts.map +0 -1
- package/src/mutations/bulk/plpgsql-strategy.ts +0 -370
- package/src/mutations/bulk/route.ts +0 -580
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
import { getTableName, sql } from "drizzle-orm";
|
|
2
|
-
import { getTableConfig, type AnyPgTable, type PgAsyncDatabase, type PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
3
|
-
import { getColumns } from "drizzle-orm/utils";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
getProjectedColumns,
|
|
7
|
-
type BatchMutationRequest,
|
|
8
|
-
type RegistryRelations,
|
|
9
|
-
type SyncTableEntry,
|
|
10
|
-
type SyncTableRegistry,
|
|
11
|
-
} from "@pgxsinkit/contracts";
|
|
12
|
-
|
|
13
|
-
import type { TransactionClient } from "./types";
|
|
14
|
-
|
|
15
|
-
function quoteIdent(name: string): string {
|
|
16
|
-
return `"${name.replace(/"/g, '""')}"`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function qualifyIdent(schemaName: string | undefined, name: string): string {
|
|
20
|
-
if (!schemaName) {
|
|
21
|
-
return quoteIdent(name);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `${quoteIdent(schemaName)}.${quoteIdent(name)}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function toSqlLiteral(value: string): string {
|
|
28
|
-
return value.replace(/'/g, "''");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function toSqlTextOrNull(value: string): string {
|
|
32
|
-
return value.length > 0 ? `'${toSqlLiteral(value)}'` : "NULL";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function buildManagedFieldExpression(strategy: "authUid" | "nowMicroseconds"): string {
|
|
36
|
-
if (strategy === "authUid") {
|
|
37
|
-
return "auth.uid()";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return "CAST(FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000000) AS BIGINT)";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function getManagedFieldsForOperation(entry: SyncTableEntry, operation: "create" | "update") {
|
|
44
|
-
const columns = getColumns(entry.table as AnyPgTable);
|
|
45
|
-
const columnNameMap = new Map(Object.entries(columns).map(([propertyKey, column]) => [propertyKey, column.name]));
|
|
46
|
-
|
|
47
|
-
return (entry.governance?.managedFields ?? []).flatMap((field) => {
|
|
48
|
-
if (!field.applyOn.includes(operation)) {
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const columnName = columnNameMap.get(field.column);
|
|
53
|
-
if (!columnName) {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return [
|
|
58
|
-
{
|
|
59
|
-
propertyKey: field.column,
|
|
60
|
-
columnName,
|
|
61
|
-
strategy: field.strategy,
|
|
62
|
-
},
|
|
63
|
-
];
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function buildTableBranch(entry: SyncTableEntry): string {
|
|
68
|
-
const tableName = getTableName(entry.table as AnyPgTable);
|
|
69
|
-
const { schema } = getTableConfig(entry.table as AnyPgTable);
|
|
70
|
-
const qualifiedTableName = qualifyIdent(schema, tableName);
|
|
71
|
-
const columns = getColumns(entry.table as AnyPgTable);
|
|
72
|
-
const projectedColumns = getProjectedColumns(entry);
|
|
73
|
-
const primaryKeyColumn = entry.primaryKey.columns[0]!;
|
|
74
|
-
const primaryKeyColumnObject = Object.values(columns).find((column) => column.name === primaryKeyColumn);
|
|
75
|
-
const primaryKeyType = primaryKeyColumnObject?.getSQLType() ?? "text";
|
|
76
|
-
|
|
77
|
-
const createManagedFields = getManagedFieldsForOperation(entry, "create");
|
|
78
|
-
const updateManagedFields = getManagedFieldsForOperation(entry, "update");
|
|
79
|
-
const createManagedFieldNames = new Set(createManagedFields.map((field) => field.columnName));
|
|
80
|
-
const updateManagedFieldNames = new Set(updateManagedFields.map((field) => field.columnName));
|
|
81
|
-
|
|
82
|
-
const allColumnPairs = projectedColumns
|
|
83
|
-
.map(({ column }) => column)
|
|
84
|
-
.filter((column) => !createManagedFieldNames.has(column.name))
|
|
85
|
-
.map((column) => `('${toSqlLiteral(column.name)}', '${toSqlLiteral(column.getSQLType())}')`)
|
|
86
|
-
.join(",\n ");
|
|
87
|
-
|
|
88
|
-
const nonPrimaryKeyColumnPairs = projectedColumns
|
|
89
|
-
.map(({ column }) => column)
|
|
90
|
-
.filter((column) => column.name !== primaryKeyColumn && !updateManagedFieldNames.has(column.name))
|
|
91
|
-
.map((column) => `('${toSqlLiteral(column.name)}', '${toSqlLiteral(column.getSQLType())}')`)
|
|
92
|
-
.join(",\n ");
|
|
93
|
-
|
|
94
|
-
const createManagedColumnsSql = createManagedFields.map((field) => quoteIdent(field.columnName)).join(", ");
|
|
95
|
-
const createManagedValuesSql = createManagedFields
|
|
96
|
-
.map((field) => buildManagedFieldExpression(field.strategy))
|
|
97
|
-
.join(", ");
|
|
98
|
-
const updateManagedAssignmentsSql = updateManagedFields
|
|
99
|
-
.map((field) => `${quoteIdent(field.columnName)} = ${buildManagedFieldExpression(field.strategy)}`)
|
|
100
|
-
.join(", ");
|
|
101
|
-
|
|
102
|
-
const createSqlTemplate = `INSERT INTO ${qualifiedTableName} (%s) VALUES (%s)`.replace(/'/g, "''");
|
|
103
|
-
const updateSqlTemplate =
|
|
104
|
-
`UPDATE ${qualifiedTableName} SET %s WHERE ${quoteIdent(primaryKeyColumn)} = ($2->>%L)::${primaryKeyType}`.replace(
|
|
105
|
-
/'/g,
|
|
106
|
-
"''",
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const createBranch = `
|
|
110
|
-
SELECT format(
|
|
111
|
-
'${createSqlTemplate}',
|
|
112
|
-
concat_ws(', ', nullif(string_agg(quote_ident(col_name), ', '), ''), ${toSqlTextOrNull(createManagedColumnsSql)}),
|
|
113
|
-
concat_ws(', ', nullif(string_agg(format('($1->>%L)::%s', col_name, col_type), ', '), ''), ${toSqlTextOrNull(createManagedValuesSql)})
|
|
114
|
-
)
|
|
115
|
-
INTO dml_sql
|
|
116
|
-
FROM (VALUES
|
|
117
|
-
${allColumnPairs}
|
|
118
|
-
) AS col_types(col_name, col_type)
|
|
119
|
-
WHERE v_payload ? col_name;
|
|
120
|
-
|
|
121
|
-
IF dml_sql IS NOT NULL THEN
|
|
122
|
-
EXECUTE dml_sql USING v_payload;
|
|
123
|
-
END IF;
|
|
124
|
-
`.trim();
|
|
125
|
-
|
|
126
|
-
const updateBranch = `
|
|
127
|
-
SELECT format(
|
|
128
|
-
'${updateSqlTemplate}',
|
|
129
|
-
concat_ws(', ', nullif(string_agg(format('%I = ($1->>%L)::%s', col_name, col_name, col_type), ', '), ''), ${toSqlTextOrNull(updateManagedAssignmentsSql)}),
|
|
130
|
-
'${toSqlLiteral(primaryKeyColumn)}'
|
|
131
|
-
)
|
|
132
|
-
INTO dml_sql
|
|
133
|
-
FROM (VALUES
|
|
134
|
-
${nonPrimaryKeyColumnPairs}
|
|
135
|
-
) AS col_types(col_name, col_type)
|
|
136
|
-
WHERE v_payload ? col_name;
|
|
137
|
-
|
|
138
|
-
IF dml_sql IS NOT NULL THEN
|
|
139
|
-
EXECUTE dml_sql USING v_payload, v_entity_key;
|
|
140
|
-
END IF;
|
|
141
|
-
`.trim();
|
|
142
|
-
|
|
143
|
-
const deleteBranch = `
|
|
144
|
-
DELETE FROM ${qualifiedTableName}
|
|
145
|
-
WHERE ${quoteIdent(primaryKeyColumn)} = (v_entity_key->>'${toSqlLiteral(primaryKeyColumn)}')::${primaryKeyType};
|
|
146
|
-
`.trim();
|
|
147
|
-
|
|
148
|
-
return `
|
|
149
|
-
ELSIF v_table = '${toSqlLiteral(tableName)}' THEN
|
|
150
|
-
IF v_kind = 'create' THEN
|
|
151
|
-
${createBranch}
|
|
152
|
-
ELSIF v_kind = 'update' THEN
|
|
153
|
-
${updateBranch}
|
|
154
|
-
ELSIF v_kind = 'delete' THEN
|
|
155
|
-
${deleteBranch}
|
|
156
|
-
ELSE
|
|
157
|
-
RAISE EXCEPTION 'Unsupported mutation kind "%" for table "%"', v_kind, v_table;
|
|
158
|
-
END IF;
|
|
159
|
-
`.trim();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function buildPlpgsqlBatchFunctionDdl(
|
|
163
|
-
registry: SyncTableRegistry,
|
|
164
|
-
options: {
|
|
165
|
-
functionSchema?: string;
|
|
166
|
-
} = {},
|
|
167
|
-
): string {
|
|
168
|
-
const tableBranches = Object.values(registry)
|
|
169
|
-
.map((entry) => buildTableBranch(entry as SyncTableEntry))
|
|
170
|
-
.join("\n");
|
|
171
|
-
const functionName = qualifyIdent(options.functionSchema, "pgxsinkit_apply_batch_mutations");
|
|
172
|
-
|
|
173
|
-
return `
|
|
174
|
-
CREATE OR REPLACE FUNCTION ${functionName}(
|
|
175
|
-
p_batch jsonb,
|
|
176
|
-
p_request_path text,
|
|
177
|
-
p_log_enabled boolean,
|
|
178
|
-
p_rls_enabled boolean,
|
|
179
|
-
p_user_claims jsonb
|
|
180
|
-
) RETURNS void LANGUAGE plpgsql AS $$
|
|
181
|
-
DECLARE
|
|
182
|
-
mutation jsonb;
|
|
183
|
-
dml_sql text;
|
|
184
|
-
v_table text;
|
|
185
|
-
v_kind text;
|
|
186
|
-
v_payload jsonb;
|
|
187
|
-
v_entity_key jsonb;
|
|
188
|
-
v_mutation_id text;
|
|
189
|
-
v_mutation_seq integer;
|
|
190
|
-
v_client_timestamp_us bigint;
|
|
191
|
-
_claims jsonb;
|
|
192
|
-
_target_role text;
|
|
193
|
-
_previous_role text;
|
|
194
|
-
_previous_claims text;
|
|
195
|
-
_previous_claim_sub text;
|
|
196
|
-
BEGIN
|
|
197
|
-
IF p_rls_enabled THEN
|
|
198
|
-
-- Capture the caller's role/claims before switching into the RLS actor context, so the
|
|
199
|
-
-- batch does not leak that context into the rest of the caller's transaction. The HTTP
|
|
200
|
-
-- route RESET ROLEs after calling this function, but in-transaction callers cannot —
|
|
201
|
-
-- restoring here leaves every caller exactly as it was found.
|
|
202
|
-
_previous_role := current_setting('role', true);
|
|
203
|
-
_previous_claims := current_setting('request.jwt.claims', true);
|
|
204
|
-
_previous_claim_sub := current_setting('request.jwt.claim.sub', true);
|
|
205
|
-
_claims := COALESCE(p_user_claims, '{}'::jsonb);
|
|
206
|
-
_target_role := COALESCE(NULLIF(_claims ->> 'role', ''), 'authenticated');
|
|
207
|
-
BEGIN
|
|
208
|
-
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = _target_role) THEN
|
|
209
|
-
PERFORM set_config('role', _target_role, true);
|
|
210
|
-
ELSIF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN
|
|
211
|
-
PERFORM set_config('role', 'authenticated', true);
|
|
212
|
-
END IF;
|
|
213
|
-
EXCEPTION WHEN insufficient_privilege THEN NULL;
|
|
214
|
-
END;
|
|
215
|
-
PERFORM set_config('request.jwt.claims', _claims::text, true);
|
|
216
|
-
IF _claims ? 'sub' THEN
|
|
217
|
-
PERFORM set_config('request.jwt.claim.sub', _claims ->> 'sub', true);
|
|
218
|
-
END IF;
|
|
219
|
-
END IF;
|
|
220
|
-
|
|
221
|
-
IF jsonb_typeof(p_batch) <> 'object' THEN
|
|
222
|
-
RAISE EXCEPTION 'Batch payload must be a JSON object';
|
|
223
|
-
END IF;
|
|
224
|
-
|
|
225
|
-
IF jsonb_typeof(p_batch->'mutations') <> 'array' THEN
|
|
226
|
-
RAISE EXCEPTION 'Batch payload mutations must be a JSON array';
|
|
227
|
-
END IF;
|
|
228
|
-
|
|
229
|
-
FOR mutation IN SELECT value FROM jsonb_array_elements(p_batch->'mutations')
|
|
230
|
-
LOOP
|
|
231
|
-
dml_sql := NULL;
|
|
232
|
-
v_table := mutation->>'tableName';
|
|
233
|
-
v_kind := mutation->>'kind';
|
|
234
|
-
v_payload := COALESCE(mutation->'payload', '{}'::jsonb);
|
|
235
|
-
v_entity_key := COALESCE(mutation->'entityKey', '{}'::jsonb);
|
|
236
|
-
v_mutation_id := mutation->>'mutationId';
|
|
237
|
-
v_mutation_seq := (mutation->>'mutationSeq')::integer;
|
|
238
|
-
v_client_timestamp_us := NULLIF(mutation->>'clientTimestampUs', '')::bigint;
|
|
239
|
-
|
|
240
|
-
IF FALSE THEN
|
|
241
|
-
NULL;
|
|
242
|
-
${tableBranches}
|
|
243
|
-
ELSE
|
|
244
|
-
RAISE EXCEPTION 'Unknown table "%" in batch mutation', v_table;
|
|
245
|
-
END IF;
|
|
246
|
-
|
|
247
|
-
IF p_log_enabled THEN
|
|
248
|
-
INSERT INTO operations_log (
|
|
249
|
-
source,
|
|
250
|
-
backend,
|
|
251
|
-
table_name,
|
|
252
|
-
operation_kind,
|
|
253
|
-
entity_key_json,
|
|
254
|
-
payload_json,
|
|
255
|
-
status,
|
|
256
|
-
http_status,
|
|
257
|
-
mutation_id,
|
|
258
|
-
mutation_seq,
|
|
259
|
-
client_timestamp_us,
|
|
260
|
-
request_path,
|
|
261
|
-
server_timestamp_us
|
|
262
|
-
) VALUES (
|
|
263
|
-
'batch',
|
|
264
|
-
'bulk-plpgsql',
|
|
265
|
-
v_table,
|
|
266
|
-
v_kind,
|
|
267
|
-
v_entity_key,
|
|
268
|
-
v_payload,
|
|
269
|
-
'succeeded',
|
|
270
|
-
200,
|
|
271
|
-
v_mutation_id::uuid,
|
|
272
|
-
v_mutation_seq,
|
|
273
|
-
v_client_timestamp_us,
|
|
274
|
-
p_request_path,
|
|
275
|
-
CAST(FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000000) AS BIGINT)
|
|
276
|
-
);
|
|
277
|
-
END IF;
|
|
278
|
-
END LOOP;
|
|
279
|
-
|
|
280
|
-
IF p_rls_enabled THEN
|
|
281
|
-
-- Restore the caller's prior role/claims captured above, so the RLS context applied for
|
|
282
|
-
-- the batch does not persist into subsequent statements of the caller's transaction.
|
|
283
|
-
BEGIN
|
|
284
|
-
PERFORM set_config('role', COALESCE(NULLIF(_previous_role, ''), 'none'), true);
|
|
285
|
-
EXCEPTION WHEN insufficient_privilege THEN NULL;
|
|
286
|
-
END;
|
|
287
|
-
PERFORM set_config('request.jwt.claims', COALESCE(_previous_claims, ''), true);
|
|
288
|
-
PERFORM set_config('request.jwt.claim.sub', COALESCE(_previous_claim_sub, ''), true);
|
|
289
|
-
END IF;
|
|
290
|
-
END;
|
|
291
|
-
$$;
|
|
292
|
-
`.trim();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export async function installPlpgsqlBatchFunction<TRegistry extends SyncTableRegistry>(
|
|
296
|
-
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
297
|
-
registry: TRegistry,
|
|
298
|
-
options: {
|
|
299
|
-
functionSchema?: string;
|
|
300
|
-
} = {},
|
|
301
|
-
): Promise<void> {
|
|
302
|
-
const ddl = buildPlpgsqlBatchFunctionDdl(registry, options);
|
|
303
|
-
await db.execute(sql.raw(ddl));
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
type FunctionPresenceRow = {
|
|
307
|
-
functionName: string | null;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
export async function verifyPlpgsqlBatchFunction<TRegistry extends SyncTableRegistry>(
|
|
311
|
-
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
312
|
-
options: {
|
|
313
|
-
functionSchema?: string;
|
|
314
|
-
} = {},
|
|
315
|
-
): Promise<void> {
|
|
316
|
-
const functionSignature = `${options.functionSchema ? `${options.functionSchema}.` : "public."}pgxsinkit_apply_batch_mutations(jsonb,text,boolean,boolean,jsonb)`;
|
|
317
|
-
const result = await db.execute<FunctionPresenceRow>(sql`
|
|
318
|
-
SELECT to_regprocedure(${functionSignature})::text AS "functionName"
|
|
319
|
-
`);
|
|
320
|
-
|
|
321
|
-
const row = Array.from(result as Iterable<unknown>, (entry) => entry as FunctionPresenceRow)[0];
|
|
322
|
-
|
|
323
|
-
if (!row?.functionName) {
|
|
324
|
-
throw new Error(
|
|
325
|
-
"bulk-plpgsql-artifact backend requires preinstalled function pgxsinkit_apply_batch_mutations(jsonb,text,boolean,boolean,jsonb). Apply sync function migrations before starting the write API.",
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
type AuthHelperPresenceRow = {
|
|
331
|
-
authUid: string | null;
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
export async function verifyArtifactRlsAuthHelpers<TRegistry extends SyncTableRegistry>(
|
|
335
|
-
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
336
|
-
): Promise<void> {
|
|
337
|
-
const result = await db.execute<AuthHelperPresenceRow>(sql`
|
|
338
|
-
SELECT
|
|
339
|
-
to_regprocedure('auth.uid()')::text AS "authUid"
|
|
340
|
-
`);
|
|
341
|
-
|
|
342
|
-
const row = Array.from(result as Iterable<unknown>, (entry) => entry as AuthHelperPresenceRow)[0];
|
|
343
|
-
const missingHelpers = [row?.authUid ? null : "auth.uid()"].filter((value): value is string => value !== null);
|
|
344
|
-
|
|
345
|
-
if (missingHelpers.length > 0) {
|
|
346
|
-
throw new Error(
|
|
347
|
-
`bulk-plpgsql-artifact backend requires Supabase auth helpers. Missing: ${missingHelpers.join(", ")}. ` +
|
|
348
|
-
"Ensure auth.uid() is available (standard on Supabase-managed databases).",
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export async function executePlpgsqlBatch(
|
|
354
|
-
tx: TransactionClient,
|
|
355
|
-
batch: BatchMutationRequest,
|
|
356
|
-
requestPath: string,
|
|
357
|
-
logEnabled: boolean,
|
|
358
|
-
rlsEnabled: boolean,
|
|
359
|
-
userClaims: Record<string, unknown>,
|
|
360
|
-
options: {
|
|
361
|
-
functionSchema?: string;
|
|
362
|
-
} = {},
|
|
363
|
-
): Promise<void> {
|
|
364
|
-
const normalizedClaims = userClaims ?? {};
|
|
365
|
-
const functionName = qualifyIdent(options.functionSchema, "pgxsinkit_apply_batch_mutations");
|
|
366
|
-
|
|
367
|
-
await tx.execute(
|
|
368
|
-
sql`SELECT ${sql.raw(functionName)}(${JSON.stringify(batch)}::text::jsonb, ${requestPath}, ${logEnabled}, ${rlsEnabled}, ${JSON.stringify(normalizedClaims)}::text::jsonb)`,
|
|
369
|
-
);
|
|
370
|
-
}
|