@pgxsinkit/server 0.1.29 → 0.1.31
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/cli/generate.d.ts +18 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/electric-proxy.d.ts +16 -0
- package/dist/electric-proxy.d.ts.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +139 -101
- package/dist/index.js.map +10 -10
- package/dist/mutations/bulk/plpgsql-strategy.d.ts +17 -0
- package/dist/mutations/bulk/plpgsql-strategy.d.ts.map +1 -0
- package/dist/mutations/bulk/route.d.ts +7 -0
- package/dist/mutations/bulk/route.d.ts.map +1 -0
- package/dist/mutations/bulk/types.d.ts +5 -0
- package/dist/mutations/bulk/types.d.ts.map +1 -0
- package/dist/operations-log/ddl.d.ts +12 -0
- package/dist/operations-log/ddl.d.ts.map +1 -0
- package/dist/operations-log/schema.d.ts +265 -0
- package/dist/operations-log/schema.d.ts.map +1 -0
- package/dist/operations-log/types.d.ts +31 -0
- package/dist/operations-log/types.d.ts.map +1 -0
- package/dist/operations-log/writer.d.ts +4 -0
- package/dist/operations-log/writer.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/electric-proxy.ts +64 -18
- package/src/index.ts +16 -6
- package/src/mutations/bulk/plpgsql-strategy.ts +6 -6
- package/src/mutations/bulk/route.ts +8 -7
- package/src/operations-log/ddl.ts +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getTableName, sql } from "drizzle-orm";
|
|
2
|
-
import { getTableConfig, type AnyPgTable, type PgAsyncDatabase } from "drizzle-orm/pg-core";
|
|
2
|
+
import { getTableConfig, type AnyPgTable, type PgAsyncDatabase, type PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
3
3
|
import { getColumns } from "drizzle-orm/utils";
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -293,7 +293,7 @@ $$;
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
export async function installPlpgsqlBatchFunction<TRegistry extends SyncTableRegistry>(
|
|
296
|
-
db: PgAsyncDatabase<
|
|
296
|
+
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
297
297
|
registry: TRegistry,
|
|
298
298
|
options: {
|
|
299
299
|
functionSchema?: string;
|
|
@@ -308,7 +308,7 @@ type FunctionPresenceRow = {
|
|
|
308
308
|
};
|
|
309
309
|
|
|
310
310
|
export async function verifyPlpgsqlBatchFunction<TRegistry extends SyncTableRegistry>(
|
|
311
|
-
db: PgAsyncDatabase<
|
|
311
|
+
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
312
312
|
options: {
|
|
313
313
|
functionSchema?: string;
|
|
314
314
|
} = {},
|
|
@@ -318,7 +318,7 @@ export async function verifyPlpgsqlBatchFunction<TRegistry extends SyncTableRegi
|
|
|
318
318
|
SELECT to_regprocedure(${functionSignature})::text AS "functionName"
|
|
319
319
|
`);
|
|
320
320
|
|
|
321
|
-
const row = Array.from(result
|
|
321
|
+
const row = Array.from(result as Iterable<unknown>, (entry) => entry as FunctionPresenceRow)[0];
|
|
322
322
|
|
|
323
323
|
if (!row?.functionName) {
|
|
324
324
|
throw new Error(
|
|
@@ -332,14 +332,14 @@ type AuthHelperPresenceRow = {
|
|
|
332
332
|
};
|
|
333
333
|
|
|
334
334
|
export async function verifyArtifactRlsAuthHelpers<TRegistry extends SyncTableRegistry>(
|
|
335
|
-
db: PgAsyncDatabase<
|
|
335
|
+
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
336
336
|
): Promise<void> {
|
|
337
337
|
const result = await db.execute<AuthHelperPresenceRow>(sql`
|
|
338
338
|
SELECT
|
|
339
339
|
to_regprocedure('auth.uid()')::text AS "authUid"
|
|
340
340
|
`);
|
|
341
341
|
|
|
342
|
-
const row = Array.from(result
|
|
342
|
+
const row = Array.from(result as Iterable<unknown>, (entry) => entry as AuthHelperPresenceRow)[0];
|
|
343
343
|
const missingHelpers = [row?.authUid ? null : "auth.uid()"].filter((value): value is string => value !== null);
|
|
344
344
|
|
|
345
345
|
if (missingHelpers.length > 0) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { and, eq, sql } from "drizzle-orm";
|
|
1
|
+
import { and, eq, sql, type AnyRelations } from "drizzle-orm";
|
|
2
2
|
import { getTableConfig, type AnyPgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import type { PgAsyncDatabase } from "drizzle-orm/pg-core";
|
|
3
|
+
import type { PgAsyncDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
4
4
|
import { getColumns } from "drizzle-orm/utils";
|
|
5
5
|
import { createSchemaFactory } from "drizzle-orm/zod";
|
|
6
6
|
import type { Context, Hono } from "hono";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
BatchMutationRequest,
|
|
10
|
+
JwtClaims,
|
|
10
11
|
MutationAck,
|
|
11
12
|
RegistryRelations,
|
|
12
13
|
SyncTableEntry,
|
|
@@ -26,16 +27,16 @@ const { createInsertSchema: createMutationInsertSchema } = createSchemaFactory({
|
|
|
26
27
|
coerce: { date: true },
|
|
27
28
|
});
|
|
28
29
|
|
|
29
|
-
type RouteReadQueryClient = Pick<PgAsyncDatabase<
|
|
30
|
+
type RouteReadQueryClient = Pick<PgAsyncDatabase<PgQueryResultHKT, AnyRelations>, "select">;
|
|
30
31
|
|
|
31
32
|
export function registerBulkMutationRoute<TRegistry extends SyncTableRegistry>(
|
|
32
33
|
app: Hono,
|
|
33
|
-
db: PgAsyncDatabase<
|
|
34
|
+
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
34
35
|
registry: TRegistry,
|
|
35
36
|
backend: BulkMutationBackend,
|
|
36
37
|
operationsLogConfig: OperationsLogConfig,
|
|
37
38
|
operationsLogReady: Promise<void>,
|
|
38
|
-
resolveAuthClaims?: (request: Request) => Promise<
|
|
39
|
+
resolveAuthClaims?: (request: Request) => Promise<JwtClaims | null> | JwtClaims | null,
|
|
39
40
|
) {
|
|
40
41
|
let startupReadyPromise: Promise<void> | undefined;
|
|
41
42
|
const batchMutationPaths = ["/api/mutations", "/mutations"] as const;
|
|
@@ -375,7 +376,7 @@ function isArtifactAuthContextRequired(registry: SyncTableRegistry): boolean {
|
|
|
375
376
|
|
|
376
377
|
class UnauthorizedBatchMutationError extends Error {}
|
|
377
378
|
|
|
378
|
-
function getUuidClaim(claims:
|
|
379
|
+
function getUuidClaim(claims: JwtClaims, key: string): string | null {
|
|
379
380
|
const value = claims[key];
|
|
380
381
|
|
|
381
382
|
if (typeof value !== "string") {
|
|
@@ -567,7 +568,7 @@ async function readServerUpdatedAtUs(
|
|
|
567
568
|
}
|
|
568
569
|
|
|
569
570
|
async function installBulkStartupDdl<TRegistry extends SyncTableRegistry>(
|
|
570
|
-
db: PgAsyncDatabase<
|
|
571
|
+
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
571
572
|
registry: TRegistry,
|
|
572
573
|
_backend: BulkMutationBackend,
|
|
573
574
|
): Promise<void> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from "drizzle-orm";
|
|
2
|
-
import type { PgAsyncDatabase } from "drizzle-orm/pg-core";
|
|
2
|
+
import type { PgAsyncDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
3
3
|
|
|
4
4
|
import type { RegistryRelations, SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ type OperationsLogPresenceRow = {
|
|
|
17
17
|
* in their Drizzle schema so `drizzle-kit generate`/`push` creates it.
|
|
18
18
|
*/
|
|
19
19
|
export async function ensureOperationsLogSchema<TRegistry extends SyncTableRegistry>(
|
|
20
|
-
db: PgAsyncDatabase<
|
|
20
|
+
db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>,
|
|
21
21
|
config: OperationsLogConfig,
|
|
22
22
|
): Promise<boolean> {
|
|
23
23
|
if (!config.enabled) {
|
|
@@ -29,7 +29,7 @@ export async function ensureOperationsLogSchema<TRegistry extends SyncTableRegis
|
|
|
29
29
|
SELECT to_regclass('public.operations_log')::text AS "tableName"
|
|
30
30
|
`);
|
|
31
31
|
|
|
32
|
-
const row = Array.from(result
|
|
32
|
+
const row = Array.from(result as Iterable<unknown>, (entry) => entry as OperationsLogPresenceRow)[0];
|
|
33
33
|
|
|
34
34
|
if (!row?.tableName) {
|
|
35
35
|
console.warn(
|