@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PgAsyncDatabase, type PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
2
|
+
import { type BatchMutationRequest, type RegistryRelations, type SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
3
|
+
import type { TransactionClient } from "./types";
|
|
4
|
+
export declare function buildPlpgsqlBatchFunctionDdl(registry: SyncTableRegistry, options?: {
|
|
5
|
+
functionSchema?: string;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function installPlpgsqlBatchFunction<TRegistry extends SyncTableRegistry>(db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>, registry: TRegistry, options?: {
|
|
8
|
+
functionSchema?: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
export declare function verifyPlpgsqlBatchFunction<TRegistry extends SyncTableRegistry>(db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>, options?: {
|
|
11
|
+
functionSchema?: string;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function verifyArtifactRlsAuthHelpers<TRegistry extends SyncTableRegistry>(db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>): Promise<void>;
|
|
14
|
+
export declare function executePlpgsqlBatch(tx: TransactionClient, batch: BatchMutationRequest, requestPath: string, logEnabled: boolean, rlsEnabled: boolean, userClaims: Record<string, unknown>, options?: {
|
|
15
|
+
functionSchema?: string;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=plpgsql-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plpgsql-strategy.d.ts","sourceRoot":"","sources":["../../../src/mutations/bulk/plpgsql-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGnH,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAqJjD,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,MAAM,CA8HR;AAED,wBAAsB,2BAA2B,CAAC,SAAS,SAAS,iBAAiB,EACnF,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,EACnE,QAAQ,EAAE,SAAS,EACnB,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,IAAI,CAAC,CAGf;AAMD,wBAAsB,0BAA0B,CAAC,SAAS,SAAS,iBAAiB,EAClF,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,EACnE,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,IAAI,CAAC,CAaf;AAMD,wBAAsB,4BAA4B,CAAC,SAAS,SAAS,iBAAiB,EACpF,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,GAClE,OAAO,CAAC,IAAI,CAAC,CAef;AAED,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,iBAAiB,EACrB,KAAK,EAAE,oBAAoB,EAC3B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,OAAO,EACnB,UAAU,EAAE,OAAO,EACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,GAAE;IACP,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PgAsyncDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
2
|
+
import type { Hono } from "hono";
|
|
3
|
+
import type { JwtClaims, RegistryRelations, SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
4
|
+
import type { OperationsLogConfig } from "../../operations-log/types";
|
|
5
|
+
import type { BulkMutationBackend } from "./types";
|
|
6
|
+
export declare function registerBulkMutationRoute<TRegistry extends SyncTableRegistry>(app: Hono, db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>, registry: TRegistry, backend: BulkMutationBackend, operationsLogConfig: OperationsLogConfig, operationsLogReady: Promise<void>, resolveAuthClaims?: (request: Request) => Promise<JwtClaims | null> | JwtClaims | null): void;
|
|
7
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/mutations/bulk/route.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAEV,SAAS,EAET,iBAAiB,EAEjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE,OAAO,KAAK,EAAE,mBAAmB,EAAqB,MAAM,SAAS,CAAC;AAQtE,wBAAgB,yBAAyB,CAAC,SAAS,SAAS,iBAAiB,EAC3E,GAAG,EAAE,IAAI,EACT,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,EACnE,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,mBAAmB,EAC5B,mBAAmB,EAAE,mBAAmB,EACxC,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,EACjC,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,SAAS,GAAG,IAAI,QA8QvF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/mutations/bulk/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAE1D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PgAsyncDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
2
|
+
import type { RegistryRelations, SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
3
|
+
import type { OperationsLogConfig } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Ensures the operations_log table exists in the database.
|
|
6
|
+
*
|
|
7
|
+
* Returns `true` if the table is present, `false` if missing.
|
|
8
|
+
* Consumers should include `operationsLogTable` from `@pgxsinkit/server`
|
|
9
|
+
* in their Drizzle schema so `drizzle-kit generate`/`push` creates it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureOperationsLogSchema<TRegistry extends SyncTableRegistry>(db: PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>>, config: OperationsLogConfig): Promise<boolean>;
|
|
12
|
+
//# sourceMappingURL=ddl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddl.d.ts","sourceRoot":"","sources":["../../src/operations-log/ddl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAMnD;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAAC,SAAS,SAAS,iBAAiB,EACjF,EAAE,EAAE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,EACnE,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,OAAO,CAAC,CA0BlB"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
export declare const operationsLogTable: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
2
|
+
name: "operations_log";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").SetIsPrimaryKey<import("drizzle-orm/pg-core").PgBigSerial53Builder>, {
|
|
6
|
+
name: string;
|
|
7
|
+
tableName: "operations_log";
|
|
8
|
+
dataType: "number int53";
|
|
9
|
+
data: number;
|
|
10
|
+
driverParam: number;
|
|
11
|
+
notNull: true;
|
|
12
|
+
hasDefault: true;
|
|
13
|
+
isPrimaryKey: false;
|
|
14
|
+
isAutoincrement: false;
|
|
15
|
+
hasRuntimeDefault: false;
|
|
16
|
+
enumValues: undefined;
|
|
17
|
+
identity: undefined;
|
|
18
|
+
generated: undefined;
|
|
19
|
+
}>;
|
|
20
|
+
source: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>>, {
|
|
21
|
+
name: string;
|
|
22
|
+
tableName: "operations_log";
|
|
23
|
+
dataType: "string";
|
|
24
|
+
data: string;
|
|
25
|
+
driverParam: string;
|
|
26
|
+
notNull: true;
|
|
27
|
+
hasDefault: false;
|
|
28
|
+
isPrimaryKey: false;
|
|
29
|
+
isAutoincrement: false;
|
|
30
|
+
hasRuntimeDefault: false;
|
|
31
|
+
enumValues: undefined;
|
|
32
|
+
identity: undefined;
|
|
33
|
+
generated: undefined;
|
|
34
|
+
}>;
|
|
35
|
+
backend: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>>, {
|
|
36
|
+
name: string;
|
|
37
|
+
tableName: "operations_log";
|
|
38
|
+
dataType: "string";
|
|
39
|
+
data: string;
|
|
40
|
+
driverParam: string;
|
|
41
|
+
notNull: true;
|
|
42
|
+
hasDefault: false;
|
|
43
|
+
isPrimaryKey: false;
|
|
44
|
+
isAutoincrement: false;
|
|
45
|
+
hasRuntimeDefault: false;
|
|
46
|
+
enumValues: undefined;
|
|
47
|
+
identity: undefined;
|
|
48
|
+
generated: undefined;
|
|
49
|
+
}>;
|
|
50
|
+
tableName: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>, {
|
|
51
|
+
name: string;
|
|
52
|
+
tableName: "operations_log";
|
|
53
|
+
dataType: "string";
|
|
54
|
+
data: string;
|
|
55
|
+
driverParam: string;
|
|
56
|
+
notNull: false;
|
|
57
|
+
hasDefault: false;
|
|
58
|
+
isPrimaryKey: false;
|
|
59
|
+
isAutoincrement: false;
|
|
60
|
+
hasRuntimeDefault: false;
|
|
61
|
+
enumValues: undefined;
|
|
62
|
+
identity: undefined;
|
|
63
|
+
generated: undefined;
|
|
64
|
+
}>;
|
|
65
|
+
operationKind: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>, {
|
|
66
|
+
name: string;
|
|
67
|
+
tableName: "operations_log";
|
|
68
|
+
dataType: "string";
|
|
69
|
+
data: string;
|
|
70
|
+
driverParam: string;
|
|
71
|
+
notNull: false;
|
|
72
|
+
hasDefault: false;
|
|
73
|
+
isPrimaryKey: false;
|
|
74
|
+
isAutoincrement: false;
|
|
75
|
+
hasRuntimeDefault: false;
|
|
76
|
+
enumValues: undefined;
|
|
77
|
+
identity: undefined;
|
|
78
|
+
generated: undefined;
|
|
79
|
+
}>;
|
|
80
|
+
userId: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgUUIDBuilder, {
|
|
81
|
+
name: string;
|
|
82
|
+
tableName: "operations_log";
|
|
83
|
+
dataType: "string uuid";
|
|
84
|
+
data: string;
|
|
85
|
+
driverParam: string;
|
|
86
|
+
notNull: false;
|
|
87
|
+
hasDefault: false;
|
|
88
|
+
isPrimaryKey: false;
|
|
89
|
+
isAutoincrement: false;
|
|
90
|
+
hasRuntimeDefault: false;
|
|
91
|
+
enumValues: undefined;
|
|
92
|
+
identity: undefined;
|
|
93
|
+
generated: undefined;
|
|
94
|
+
}>;
|
|
95
|
+
entityKeyJson: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgJsonbBuilder, {
|
|
96
|
+
name: string;
|
|
97
|
+
tableName: "operations_log";
|
|
98
|
+
dataType: "object json";
|
|
99
|
+
data: unknown;
|
|
100
|
+
driverParam: unknown;
|
|
101
|
+
notNull: false;
|
|
102
|
+
hasDefault: false;
|
|
103
|
+
isPrimaryKey: false;
|
|
104
|
+
isAutoincrement: false;
|
|
105
|
+
hasRuntimeDefault: false;
|
|
106
|
+
enumValues: undefined;
|
|
107
|
+
identity: undefined;
|
|
108
|
+
generated: undefined;
|
|
109
|
+
}>;
|
|
110
|
+
payloadJson: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgJsonbBuilder, {
|
|
111
|
+
name: string;
|
|
112
|
+
tableName: "operations_log";
|
|
113
|
+
dataType: "object json";
|
|
114
|
+
data: unknown;
|
|
115
|
+
driverParam: unknown;
|
|
116
|
+
notNull: false;
|
|
117
|
+
hasDefault: false;
|
|
118
|
+
isPrimaryKey: false;
|
|
119
|
+
isAutoincrement: false;
|
|
120
|
+
hasRuntimeDefault: false;
|
|
121
|
+
enumValues: undefined;
|
|
122
|
+
identity: undefined;
|
|
123
|
+
generated: undefined;
|
|
124
|
+
}>;
|
|
125
|
+
status: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>>, {
|
|
126
|
+
name: string;
|
|
127
|
+
tableName: "operations_log";
|
|
128
|
+
dataType: "string";
|
|
129
|
+
data: string;
|
|
130
|
+
driverParam: string;
|
|
131
|
+
notNull: true;
|
|
132
|
+
hasDefault: false;
|
|
133
|
+
isPrimaryKey: false;
|
|
134
|
+
isAutoincrement: false;
|
|
135
|
+
hasRuntimeDefault: false;
|
|
136
|
+
enumValues: undefined;
|
|
137
|
+
identity: undefined;
|
|
138
|
+
generated: undefined;
|
|
139
|
+
}>;
|
|
140
|
+
errorMessage: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>, {
|
|
141
|
+
name: string;
|
|
142
|
+
tableName: "operations_log";
|
|
143
|
+
dataType: "string";
|
|
144
|
+
data: string;
|
|
145
|
+
driverParam: string;
|
|
146
|
+
notNull: false;
|
|
147
|
+
hasDefault: false;
|
|
148
|
+
isPrimaryKey: false;
|
|
149
|
+
isAutoincrement: false;
|
|
150
|
+
hasRuntimeDefault: false;
|
|
151
|
+
enumValues: undefined;
|
|
152
|
+
identity: undefined;
|
|
153
|
+
generated: undefined;
|
|
154
|
+
}>;
|
|
155
|
+
httpStatus: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgIntegerBuilder, {
|
|
156
|
+
name: string;
|
|
157
|
+
tableName: "operations_log";
|
|
158
|
+
dataType: "number int32";
|
|
159
|
+
data: number;
|
|
160
|
+
driverParam: string | number;
|
|
161
|
+
notNull: false;
|
|
162
|
+
hasDefault: false;
|
|
163
|
+
isPrimaryKey: false;
|
|
164
|
+
isAutoincrement: false;
|
|
165
|
+
hasRuntimeDefault: false;
|
|
166
|
+
enumValues: undefined;
|
|
167
|
+
identity: undefined;
|
|
168
|
+
generated: undefined;
|
|
169
|
+
}>;
|
|
170
|
+
mutationId: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgUUIDBuilder, {
|
|
171
|
+
name: string;
|
|
172
|
+
tableName: "operations_log";
|
|
173
|
+
dataType: "string uuid";
|
|
174
|
+
data: string;
|
|
175
|
+
driverParam: string;
|
|
176
|
+
notNull: false;
|
|
177
|
+
hasDefault: false;
|
|
178
|
+
isPrimaryKey: false;
|
|
179
|
+
isAutoincrement: false;
|
|
180
|
+
hasRuntimeDefault: false;
|
|
181
|
+
enumValues: undefined;
|
|
182
|
+
identity: undefined;
|
|
183
|
+
generated: undefined;
|
|
184
|
+
}>;
|
|
185
|
+
mutationSeq: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgIntegerBuilder, {
|
|
186
|
+
name: string;
|
|
187
|
+
tableName: "operations_log";
|
|
188
|
+
dataType: "number int32";
|
|
189
|
+
data: number;
|
|
190
|
+
driverParam: string | number;
|
|
191
|
+
notNull: false;
|
|
192
|
+
hasDefault: false;
|
|
193
|
+
isPrimaryKey: false;
|
|
194
|
+
isAutoincrement: false;
|
|
195
|
+
hasRuntimeDefault: false;
|
|
196
|
+
enumValues: undefined;
|
|
197
|
+
identity: undefined;
|
|
198
|
+
generated: undefined;
|
|
199
|
+
}>;
|
|
200
|
+
clientTimestampUs: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgBigInt64Builder, {
|
|
201
|
+
name: string;
|
|
202
|
+
tableName: "operations_log";
|
|
203
|
+
dataType: "bigint int64";
|
|
204
|
+
data: bigint;
|
|
205
|
+
driverParam: string;
|
|
206
|
+
notNull: false;
|
|
207
|
+
hasDefault: false;
|
|
208
|
+
isPrimaryKey: false;
|
|
209
|
+
isAutoincrement: false;
|
|
210
|
+
hasRuntimeDefault: false;
|
|
211
|
+
enumValues: undefined;
|
|
212
|
+
identity: undefined;
|
|
213
|
+
generated: undefined;
|
|
214
|
+
}>;
|
|
215
|
+
requestPath: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>, {
|
|
216
|
+
name: string;
|
|
217
|
+
tableName: "operations_log";
|
|
218
|
+
dataType: "string";
|
|
219
|
+
data: string;
|
|
220
|
+
driverParam: string;
|
|
221
|
+
notNull: false;
|
|
222
|
+
hasDefault: false;
|
|
223
|
+
isPrimaryKey: false;
|
|
224
|
+
isAutoincrement: false;
|
|
225
|
+
hasRuntimeDefault: false;
|
|
226
|
+
enumValues: undefined;
|
|
227
|
+
identity: undefined;
|
|
228
|
+
generated: undefined;
|
|
229
|
+
}>;
|
|
230
|
+
serverTimestampUs: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgBigInt64Builder>>, {
|
|
231
|
+
name: string;
|
|
232
|
+
tableName: "operations_log";
|
|
233
|
+
dataType: "bigint int64";
|
|
234
|
+
data: bigint;
|
|
235
|
+
driverParam: string;
|
|
236
|
+
notNull: true;
|
|
237
|
+
hasDefault: true;
|
|
238
|
+
isPrimaryKey: false;
|
|
239
|
+
isAutoincrement: false;
|
|
240
|
+
hasRuntimeDefault: false;
|
|
241
|
+
enumValues: undefined;
|
|
242
|
+
identity: undefined;
|
|
243
|
+
generated: undefined;
|
|
244
|
+
}>;
|
|
245
|
+
createdAt: import("drizzle-orm/pg-core").PgBuildColumn<"operations_log", import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>, {
|
|
246
|
+
name: string;
|
|
247
|
+
tableName: "operations_log";
|
|
248
|
+
dataType: "object date";
|
|
249
|
+
data: Date;
|
|
250
|
+
driverParam: string;
|
|
251
|
+
notNull: true;
|
|
252
|
+
hasDefault: true;
|
|
253
|
+
isPrimaryKey: false;
|
|
254
|
+
isAutoincrement: false;
|
|
255
|
+
hasRuntimeDefault: false;
|
|
256
|
+
enumValues: undefined;
|
|
257
|
+
identity: undefined;
|
|
258
|
+
generated: undefined;
|
|
259
|
+
}>;
|
|
260
|
+
};
|
|
261
|
+
dialect: 'pg';
|
|
262
|
+
}>;
|
|
263
|
+
export type OperationsLogRow = typeof operationsLogTable.$inferSelect;
|
|
264
|
+
export type NewOperationsLogRow = typeof operationsLogTable.$inferInsert;
|
|
265
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/operations-log/schema.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B9B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,OAAO,kBAAkB,CAAC,YAAY,CAAC;AACtE,MAAM,MAAM,mBAAmB,GAAG,OAAO,kBAAkB,CAAC,YAAY,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SQLWrapper } from "drizzle-orm";
|
|
2
|
+
import type { AnyPgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
export type OpsLogSource = "crud" | "batch";
|
|
4
|
+
export type OpsLogBackend = "bulk-plpgsql-artifact";
|
|
5
|
+
export type OpsLogStatus = "succeeded" | "validation_failed" | "not_found" | "execution_failed";
|
|
6
|
+
export interface OperationsLogConfig {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface OpsLogEntry {
|
|
10
|
+
source: OpsLogSource;
|
|
11
|
+
backend: OpsLogBackend;
|
|
12
|
+
tableName?: string | null;
|
|
13
|
+
operationKind?: "create" | "update" | "delete" | null;
|
|
14
|
+
userId?: string | null;
|
|
15
|
+
entityKey?: Record<string, string> | null;
|
|
16
|
+
payload?: unknown;
|
|
17
|
+
status: OpsLogStatus;
|
|
18
|
+
errorMessage?: string | null;
|
|
19
|
+
httpStatus?: number | null;
|
|
20
|
+
mutationId?: string | null;
|
|
21
|
+
mutationSeq?: number | null;
|
|
22
|
+
clientTimestampUs?: string | null;
|
|
23
|
+
requestPath?: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface SqlExecutor {
|
|
26
|
+
execute: (query: string | SQLWrapper<unknown>) => Promise<unknown>;
|
|
27
|
+
insert: (table: AnyPgTable) => {
|
|
28
|
+
values: (values: Record<string, unknown>) => PromiseLike<unknown>;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/operations-log/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,mBAAmB,GAAG,WAAW,GAAG,kBAAkB,CAAC;AAEhG,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK;QAC7B,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,WAAW,CAAC,OAAO,CAAC,CAAC;KACnE,CAAC;CACH"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OpsLogEntry, OperationsLogConfig, SqlExecutor } from "./types";
|
|
2
|
+
export declare function logOperation(executor: SqlExecutor, config: OperationsLogConfig, entry: OpsLogEntry): Promise<void>;
|
|
3
|
+
export declare function logOperationSafely(executor: SqlExecutor, config: OperationsLogConfig, entry: OpsLogEntry): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/operations-log/writer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAkB7E,wBAAsB,YAAY,CAChC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.31",
|
|
4
4
|
"bin": {
|
|
5
5
|
"pgxsinkit-generate": "src/cli/generate.ts"
|
|
6
6
|
},
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
],
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "./dist/index.js",
|
|
14
|
-
"types": "./
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"types": "./
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
18
|
"default": "./dist/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@pgxsinkit/contracts": "^0.1.
|
|
28
|
+
"@pgxsinkit/contracts": "^0.1.31"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"drizzle-orm": "1.0.0-rc.2",
|
|
32
|
-
"hono": "^4.12.
|
|
32
|
+
"hono": "^4.12.25"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/electric-proxy.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
buildRowFilterWhere,
|
|
3
|
+
getOmittedProjectedColumnNames,
|
|
4
|
+
type JwtClaims,
|
|
5
|
+
type RowTransform,
|
|
6
|
+
type RowTransformContext,
|
|
7
|
+
type SyncTableRegistry,
|
|
8
|
+
} from "@pgxsinkit/contracts";
|
|
2
9
|
|
|
3
10
|
export interface ElectricProxyOptions {
|
|
4
11
|
registry: SyncTableRegistry;
|
|
@@ -16,7 +23,7 @@ export interface ElectricProxyOptions {
|
|
|
16
23
|
*/
|
|
17
24
|
export async function proxyElectricShapeRequest(
|
|
18
25
|
request: Request,
|
|
19
|
-
claims:
|
|
26
|
+
claims: JwtClaims | null,
|
|
20
27
|
options: ElectricProxyOptions,
|
|
21
28
|
): Promise<Response> {
|
|
22
29
|
const targetUrl = buildProxyTargetUrl(request, claims, options);
|
|
@@ -41,17 +48,22 @@ export async function proxyElectricShapeRequest(
|
|
|
41
48
|
|
|
42
49
|
const table = new URL(request.url).searchParams.get("table");
|
|
43
50
|
const omittedColumns = table ? getOmittedProjectedColumnsForTable(options.registry, table) : [];
|
|
51
|
+
const rowTransform = table ? getRowTransformForTable(options.registry, table) : undefined;
|
|
44
52
|
const contentType = responseHeaders.get("content-type") ?? "";
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
// Re-serialize the shape log when this table needs any row-level rewriting: column
|
|
55
|
+
// omission and/or a registry-declared row transform. The transform runs first so it can
|
|
56
|
+
// read a column (e.g. a control flag) that omission then strips from the client row.
|
|
57
|
+
if ((omittedColumns.length > 0 || rowTransform) && contentType.includes("application/json")) {
|
|
47
58
|
const payload = await response
|
|
48
59
|
.clone()
|
|
49
60
|
.json()
|
|
50
61
|
.catch(() => undefined);
|
|
51
62
|
|
|
52
63
|
if (Array.isArray(payload)) {
|
|
53
|
-
const
|
|
54
|
-
|
|
64
|
+
const context: RowTransformContext = { claims, ...(options.extraParams ? { params: options.extraParams } : {}) };
|
|
65
|
+
const rewritten = rewriteShapeLogEntries(payload, omittedColumns, rowTransform, context);
|
|
66
|
+
return new Response(JSON.stringify(rewritten), {
|
|
55
67
|
status: response.status,
|
|
56
68
|
statusText: response.statusText,
|
|
57
69
|
headers: responseHeaders,
|
|
@@ -66,11 +78,7 @@ export async function proxyElectricShapeRequest(
|
|
|
66
78
|
});
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
function buildProxyTargetUrl(
|
|
70
|
-
request: Request,
|
|
71
|
-
claims: Record<string, unknown> | null,
|
|
72
|
-
options: ElectricProxyOptions,
|
|
73
|
-
): string {
|
|
81
|
+
function buildProxyTargetUrl(request: Request, claims: JwtClaims | null, options: ElectricProxyOptions): string {
|
|
74
82
|
const requestUrl = new URL(request.url);
|
|
75
83
|
const targetUrl = new URL(options.electricUrl);
|
|
76
84
|
|
|
@@ -132,30 +140,68 @@ function getOmittedProjectedColumnsForTable(registry: SyncTableRegistry, table:
|
|
|
132
140
|
return entry ? getOmittedProjectedColumnNames(entry) : [];
|
|
133
141
|
}
|
|
134
142
|
|
|
143
|
+
function getRowTransformForTable(registry: SyncTableRegistry, table: string): RowTransform | undefined {
|
|
144
|
+
return getRegistryEntry(registry, table)?.clientProjection?.rowTransform;
|
|
145
|
+
}
|
|
146
|
+
|
|
135
147
|
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
136
148
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
137
149
|
}
|
|
138
150
|
|
|
139
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Subset of an Electric shape-log entry the proxy rewrites: `value` carries the
|
|
153
|
+
* row, `old_value` the prior row on updates. Runtime guards still validate both
|
|
154
|
+
* before use; the declared shape is the wire-protocol expectation.
|
|
155
|
+
*/
|
|
156
|
+
interface ShapeLogEntry {
|
|
157
|
+
value?: Record<string, unknown>;
|
|
158
|
+
old_value?: Record<string, unknown>;
|
|
159
|
+
[key: string]: unknown;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function isShapeLogEntry(value: unknown): value is ShapeLogEntry {
|
|
163
|
+
return isObjectRecord(value);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Rewrite each shape-log row: apply the registry row transform (if any), then strip
|
|
168
|
+
* omitted columns. Both passes preserve object identity when nothing changes, so an
|
|
169
|
+
* untouched entry flows through unmodified.
|
|
170
|
+
*/
|
|
171
|
+
function rewriteRow(
|
|
172
|
+
row: Record<string, unknown>,
|
|
173
|
+
omittedColumns: readonly string[],
|
|
174
|
+
rowTransform: RowTransform | undefined,
|
|
175
|
+
context: RowTransformContext,
|
|
176
|
+
): Record<string, unknown> {
|
|
177
|
+
const transformed = rowTransform ? rowTransform(row, context) : row;
|
|
178
|
+
return omittedColumns.length > 0 ? omitColumnsFromRow(transformed, omittedColumns) : transformed;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function rewriteShapeLogEntries(
|
|
182
|
+
payload: unknown[],
|
|
183
|
+
omittedColumns: readonly string[],
|
|
184
|
+
rowTransform: RowTransform | undefined,
|
|
185
|
+
context: RowTransformContext,
|
|
186
|
+
): unknown[] {
|
|
140
187
|
return payload.map((entry) => {
|
|
141
|
-
if (!
|
|
188
|
+
if (!isShapeLogEntry(entry)) {
|
|
142
189
|
return entry;
|
|
143
190
|
}
|
|
144
191
|
|
|
145
|
-
let
|
|
192
|
+
let currentEntry: ShapeLogEntry = entry;
|
|
146
193
|
|
|
147
194
|
if (isObjectRecord(entry.value)) {
|
|
148
|
-
const nextValue =
|
|
195
|
+
const nextValue = rewriteRow(entry.value, omittedColumns, rowTransform, context);
|
|
149
196
|
if (nextValue !== entry.value) {
|
|
150
|
-
|
|
197
|
+
currentEntry = { ...currentEntry, value: nextValue };
|
|
151
198
|
}
|
|
152
199
|
}
|
|
153
200
|
|
|
154
|
-
const currentEntry = nextEntry ?? entry;
|
|
155
201
|
if (isObjectRecord(currentEntry.old_value)) {
|
|
156
|
-
const nextOldValue =
|
|
202
|
+
const nextOldValue = rewriteRow(currentEntry.old_value, omittedColumns, rowTransform, context);
|
|
157
203
|
if (nextOldValue !== currentEntry.old_value) {
|
|
158
|
-
|
|
204
|
+
currentEntry = { ...currentEntry, old_value: nextOldValue };
|
|
159
205
|
}
|
|
160
206
|
}
|
|
161
207
|
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { PgAsyncDatabase } from "drizzle-orm/pg-core";
|
|
1
|
+
import type { PgAsyncDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { cors } from "hono/cors";
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
+
JwtClaims,
|
|
6
7
|
RegistryRelations,
|
|
7
8
|
RegistryTables,
|
|
8
9
|
SyncRuntimeStatus,
|
|
@@ -32,14 +33,17 @@ interface BunNamespace {
|
|
|
32
33
|
|
|
33
34
|
export interface CreateSyncServerOptions<
|
|
34
35
|
TRegistry extends SyncTableRegistry,
|
|
35
|
-
TDb extends PgAsyncDatabase<
|
|
36
|
+
TDb extends PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>> = PgAsyncDatabase<
|
|
37
|
+
PgQueryResultHKT,
|
|
38
|
+
RegistryRelations<TRegistry>
|
|
39
|
+
>,
|
|
36
40
|
> {
|
|
37
41
|
registry: TRegistry;
|
|
38
42
|
db: TDb;
|
|
39
43
|
/** Existing Hono app to register routes on. If omitted, a new Hono app is created. */
|
|
40
44
|
app?: Hono;
|
|
41
45
|
backend?: BulkMutationBackend;
|
|
42
|
-
resolveAuthClaims?: (request: Request) => Promise<
|
|
46
|
+
resolveAuthClaims?: (request: Request) => Promise<JwtClaims | null> | JwtClaims | null;
|
|
43
47
|
operationsLog?: {
|
|
44
48
|
enabled?: boolean;
|
|
45
49
|
};
|
|
@@ -59,7 +63,10 @@ export interface ServerDiagnostics<TRegistry extends SyncTableRegistry> {
|
|
|
59
63
|
|
|
60
64
|
export interface SyncServer<
|
|
61
65
|
TRegistry extends SyncTableRegistry,
|
|
62
|
-
TDb extends PgAsyncDatabase<
|
|
66
|
+
TDb extends PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>> = PgAsyncDatabase<
|
|
67
|
+
PgQueryResultHKT,
|
|
68
|
+
RegistryRelations<TRegistry>
|
|
69
|
+
>,
|
|
63
70
|
> {
|
|
64
71
|
drizzle: TDb;
|
|
65
72
|
fetch: (request: Request) => Promise<Response>;
|
|
@@ -73,7 +80,10 @@ export interface SyncServer<
|
|
|
73
80
|
|
|
74
81
|
export function createSyncServer<
|
|
75
82
|
TRegistry extends SyncTableRegistry,
|
|
76
|
-
TDb extends PgAsyncDatabase<
|
|
83
|
+
TDb extends PgAsyncDatabase<PgQueryResultHKT, RegistryRelations<TRegistry>> = PgAsyncDatabase<
|
|
84
|
+
PgQueryResultHKT,
|
|
85
|
+
RegistryRelations<TRegistry>
|
|
86
|
+
>,
|
|
77
87
|
>(options: CreateSyncServerOptions<TRegistry, TDb>): SyncServer<TRegistry, TDb> {
|
|
78
88
|
const ownsApp = !options.app;
|
|
79
89
|
const db = options.db;
|
|
@@ -150,7 +160,7 @@ export function createSyncServer<
|
|
|
150
160
|
fetch,
|
|
151
161
|
request: (path, init) => {
|
|
152
162
|
const baseUrl = address === null ? "http://localhost" : `http://${address.host}:${address.port}`;
|
|
153
|
-
return fetch(new Request(new URL(path, baseUrl), init));
|
|
163
|
+
return fetch(new Request(new URL(path, baseUrl).toString(), init));
|
|
154
164
|
},
|
|
155
165
|
start: async () => {
|
|
156
166
|
if (bunServer) {
|