@pgxsinkit/client 0.1.15 → 0.1.17
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/index.js +57 -326
- package/dist/index.js.map +5 -5
- package/package.json +3 -3
- package/src/index.ts +10 -5
- package/src/mutation.ts +93 -512
- package/src/schema.ts +48 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"src",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@pgxsinkit/contracts": "^0.1.
|
|
26
|
-
"@pgxsinkit/sync-engine": "^0.1.
|
|
25
|
+
"@pgxsinkit/contracts": "^0.1.17",
|
|
26
|
+
"@pgxsinkit/sync-engine": "^0.1.17"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@electric-sql/pglite": "0.4.5",
|
package/src/index.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { drizzle } from "drizzle-orm/pglite";
|
|
|
5
5
|
import { defineRelations } from "drizzle-orm/relations";
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
ClientProjectionSpec,
|
|
9
8
|
MutationDiagnostics,
|
|
10
9
|
RegistryRelations,
|
|
11
10
|
RegistryTables,
|
|
11
|
+
RegistryViews,
|
|
12
12
|
SyncConfigInput,
|
|
13
13
|
SyncRuntimeStatus,
|
|
14
14
|
SyncTableCreateInput,
|
|
@@ -32,7 +32,6 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
32
32
|
registry: TRegistry;
|
|
33
33
|
electricUrl: string;
|
|
34
34
|
writeUrl: string;
|
|
35
|
-
batchWriteUrl?: string;
|
|
36
35
|
getAuthToken?: () => Promise<string | undefined>;
|
|
37
36
|
syncEnabled?: boolean;
|
|
38
37
|
dataDir?: string;
|
|
@@ -55,6 +54,7 @@ export interface SyncClientTableHandle<TRegistry extends SyncTableRegistry, TKey
|
|
|
55
54
|
export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
56
55
|
drizzle: PgliteDatabase<RegistryRelations<TRegistry>>;
|
|
57
56
|
pglite: ClientPGlite;
|
|
57
|
+
views: RegistryViews<TRegistry>;
|
|
58
58
|
tables: {
|
|
59
59
|
[TKey in SyncTableName<TRegistry>]: SyncClientTableHandle<TRegistry, TKey>;
|
|
60
60
|
};
|
|
@@ -158,7 +158,6 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
158
158
|
db: pglite,
|
|
159
159
|
registry: options.registry,
|
|
160
160
|
writeUrl: options.writeUrl,
|
|
161
|
-
batchWriteUrl: options.batchWriteUrl ?? options.writeUrl,
|
|
162
161
|
...(options.getAuthToken ? { getAuthToken: options.getAuthToken } : {}),
|
|
163
162
|
});
|
|
164
163
|
|
|
@@ -174,6 +173,7 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
174
173
|
const client: SyncClient<TRegistry> = {
|
|
175
174
|
drizzle: drizzleDb,
|
|
176
175
|
pglite,
|
|
176
|
+
views: buildViews(options.registry),
|
|
177
177
|
tables: Object.fromEntries(
|
|
178
178
|
Object.keys(options.registry).map((tableKey) => [
|
|
179
179
|
tableKey,
|
|
@@ -254,6 +254,12 @@ function buildSchema<TRegistry extends SyncTableRegistry>(registry: TRegistry) {
|
|
|
254
254
|
) as RegistryTables<TRegistry>;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
function buildViews<TRegistry extends SyncTableRegistry>(registry: TRegistry) {
|
|
258
|
+
return Object.fromEntries(
|
|
259
|
+
Object.entries(registry).flatMap(([key, entry]) => (entry.view != null ? [[key, entry.view]] : [])),
|
|
260
|
+
) as RegistryViews<TRegistry>;
|
|
261
|
+
}
|
|
262
|
+
|
|
257
263
|
function buildSyncConfigFromRegistry<TRegistry extends SyncTableRegistry>(
|
|
258
264
|
registry: TRegistry,
|
|
259
265
|
electricUrl: string,
|
|
@@ -273,12 +279,11 @@ function buildSyncTableInput(entry: SyncTableEntry, tableKey: string) {
|
|
|
273
279
|
mode: entry.mode,
|
|
274
280
|
primaryKey: entry.primaryKey,
|
|
275
281
|
shape: entry.shape,
|
|
276
|
-
routes: entry.routes,
|
|
277
282
|
clientProjection,
|
|
278
283
|
};
|
|
279
284
|
}
|
|
280
285
|
|
|
281
|
-
function getClientProjection(entry: SyncTableEntry, tableKey: string)
|
|
286
|
+
function getClientProjection(entry: SyncTableEntry, tableKey: string) {
|
|
282
287
|
if (!entry.clientProjection) {
|
|
283
288
|
throw new Error(`clientProjection is required for client table ${tableKey}`);
|
|
284
289
|
}
|