@pgxsinkit/client 0.1.29 → 0.1.30
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 +43 -30
- package/dist/index.js.map +5 -5
- package/package.json +3 -3
- package/src/mutation.ts +9 -9
package/dist/index.js
CHANGED
|
@@ -6222,6 +6222,13 @@ function getTableAsAliasSQL2(table) {
|
|
|
6222
6222
|
import { z } from "zod";
|
|
6223
6223
|
var unixMicrosecondsSchema = z.string().regex(/^[0-9]+$/);
|
|
6224
6224
|
// packages/contracts/src/config.ts
|
|
6225
|
+
import { z as z2 } from "zod";
|
|
6226
|
+
var jwtClaimsSchema = z2.looseObject({
|
|
6227
|
+
sub: z2.string().optional(),
|
|
6228
|
+
app_metadata: z2.looseObject({
|
|
6229
|
+
roles: z2.array(z2.string()).optional()
|
|
6230
|
+
}).optional()
|
|
6231
|
+
});
|
|
6225
6232
|
function getLocalSyncPrimaryKey(source) {
|
|
6226
6233
|
return source.clientProjection?.localPrimaryKey ?? source.primaryKey;
|
|
6227
6234
|
}
|
|
@@ -6277,35 +6284,35 @@ function getSyncRegistrySchema(registry) {
|
|
|
6277
6284
|
return typeof schema === "string" && schema.length > 0 ? schema : "public";
|
|
6278
6285
|
}
|
|
6279
6286
|
// packages/contracts/src/mutation.ts
|
|
6280
|
-
import { z as
|
|
6281
|
-
var mutationKindSchema =
|
|
6282
|
-
var mutationStatusSchema =
|
|
6283
|
-
var mutationAckStatusSchema =
|
|
6284
|
-
var entityKeySchema =
|
|
6285
|
-
var mutationEnvelopeSchema =
|
|
6286
|
-
tableName:
|
|
6287
|
+
import { z as z3 } from "zod";
|
|
6288
|
+
var mutationKindSchema = z3.enum(["create", "update", "delete"]);
|
|
6289
|
+
var mutationStatusSchema = z3.enum(["pending", "sending", "acked", "failed"]);
|
|
6290
|
+
var mutationAckStatusSchema = z3.enum(["acked", "failed", "conflicted"]);
|
|
6291
|
+
var entityKeySchema = z3.record(z3.string().trim().min(1), z3.string().trim().min(1));
|
|
6292
|
+
var mutationEnvelopeSchema = z3.object({
|
|
6293
|
+
tableName: z3.string().trim().min(1),
|
|
6287
6294
|
entityKey: entityKeySchema,
|
|
6288
|
-
mutationId:
|
|
6289
|
-
mutationSeq:
|
|
6295
|
+
mutationId: z3.uuid(),
|
|
6296
|
+
mutationSeq: z3.number().int().nonnegative(),
|
|
6290
6297
|
kind: mutationKindSchema,
|
|
6291
|
-
payload:
|
|
6298
|
+
payload: z3.unknown(),
|
|
6292
6299
|
clientTimestampUs: unixMicrosecondsSchema
|
|
6293
6300
|
}).strict();
|
|
6294
|
-
var mutationAckSchema =
|
|
6295
|
-
tableName:
|
|
6301
|
+
var mutationAckSchema = z3.object({
|
|
6302
|
+
tableName: z3.string().trim().min(1),
|
|
6296
6303
|
entityKey: entityKeySchema,
|
|
6297
|
-
mutationId:
|
|
6298
|
-
mutationSeq:
|
|
6304
|
+
mutationId: z3.uuid(),
|
|
6305
|
+
mutationSeq: z3.number().int().nonnegative(),
|
|
6299
6306
|
status: mutationAckStatusSchema,
|
|
6300
6307
|
serverUpdatedAtUs: unixMicrosecondsSchema.optional(),
|
|
6301
|
-
conflictReason:
|
|
6302
|
-
httpStatus:
|
|
6308
|
+
conflictReason: z3.string().trim().min(1).optional(),
|
|
6309
|
+
httpStatus: z3.number().int().min(100).max(599).optional()
|
|
6303
6310
|
}).strict();
|
|
6304
|
-
var batchMutationRequestSchema =
|
|
6305
|
-
mutations:
|
|
6311
|
+
var batchMutationRequestSchema = z3.object({
|
|
6312
|
+
mutations: z3.array(mutationEnvelopeSchema).min(1)
|
|
6306
6313
|
}).strict();
|
|
6307
|
-
var batchMutationAckSchema =
|
|
6308
|
-
acks:
|
|
6314
|
+
var batchMutationAckSchema = z3.object({
|
|
6315
|
+
acks: z3.array(mutationAckSchema)
|
|
6309
6316
|
}).strict();
|
|
6310
6317
|
// packages/pglite-sync/src/index.ts
|
|
6311
6318
|
import { isChangeMessage, isControlMessage } from "@electric-sql/client";
|
|
@@ -6658,6 +6665,13 @@ function subscriptionMetadataTableName(metadataSchema) {
|
|
|
6658
6665
|
}
|
|
6659
6666
|
|
|
6660
6667
|
// packages/pglite-sync/src/index.ts
|
|
6668
|
+
function readReplicationHeaders(headers) {
|
|
6669
|
+
const rawLsn = headers["lsn"];
|
|
6670
|
+
return {
|
|
6671
|
+
lsn: typeof rawLsn === "string" ? BigInt(rawLsn) : BigInt(0),
|
|
6672
|
+
isLastOfLsn: headers["last"] === true
|
|
6673
|
+
};
|
|
6674
|
+
}
|
|
6661
6675
|
async function createPlugin(pg, options) {
|
|
6662
6676
|
const debug = options?.debug ?? false;
|
|
6663
6677
|
const metadataSchema = options?.metadataSchema ?? "electric";
|
|
@@ -6896,11 +6910,10 @@ async function createPlugin(pg, options) {
|
|
|
6896
6910
|
const lastCommittedLsnForShape = completeLsns.get(message.shape) ?? BigInt(-1);
|
|
6897
6911
|
if (isChangeMessage(message)) {
|
|
6898
6912
|
const shapeChanges = changes.get(message.shape);
|
|
6899
|
-
const
|
|
6913
|
+
const { lsn, isLastOfLsn } = readReplicationHeaders(message.headers);
|
|
6900
6914
|
if (lsn <= lastCommittedLsnForShape) {
|
|
6901
6915
|
return;
|
|
6902
6916
|
}
|
|
6903
|
-
const isLastOfLsn = message.headers.last ?? false;
|
|
6904
6917
|
if (!shapeChanges.has(lsn)) {
|
|
6905
6918
|
shapeChanges.set(lsn, []);
|
|
6906
6919
|
}
|
|
@@ -6994,7 +7007,7 @@ async function createPlugin(pg, options) {
|
|
|
6994
7007
|
return multiShapeSub.isUpToDate;
|
|
6995
7008
|
},
|
|
6996
7009
|
stream: (() => {
|
|
6997
|
-
const stream = multiShapeSub.streams
|
|
7010
|
+
const stream = multiShapeSub.streams["shape"];
|
|
6998
7011
|
if (!stream) {
|
|
6999
7012
|
throw new Error("Missing stream for shape");
|
|
7000
7013
|
}
|
|
@@ -7618,11 +7631,11 @@ function createOptimisticRecordFromContext(context, input) {
|
|
|
7618
7631
|
...isRecord(input) ? input : {}
|
|
7619
7632
|
};
|
|
7620
7633
|
const nowUs = nowMicroseconds();
|
|
7621
|
-
if (hasProperty(context, "createdAtUs") && record
|
|
7622
|
-
record
|
|
7634
|
+
if (hasProperty(context, "createdAtUs") && record["createdAtUs"] === undefined) {
|
|
7635
|
+
record["createdAtUs"] = nowUs;
|
|
7623
7636
|
}
|
|
7624
|
-
if (hasProperty(context, "updatedAtUs") && record
|
|
7625
|
-
record
|
|
7637
|
+
if (hasProperty(context, "updatedAtUs") && record["updatedAtUs"] === undefined) {
|
|
7638
|
+
record["updatedAtUs"] = nowUs;
|
|
7626
7639
|
}
|
|
7627
7640
|
for (const { propertyKey, column } of context.columns) {
|
|
7628
7641
|
if (record[propertyKey] !== undefined) {
|
|
@@ -7955,7 +7968,7 @@ async function flushBatch(db, tableContexts, batchWriteUrl, tableFilter, getAuth
|
|
|
7955
7968
|
...row,
|
|
7956
7969
|
context,
|
|
7957
7970
|
entityKey,
|
|
7958
|
-
envelopePayload: row.mutationKind === "delete" ? entityKey : toSqlColumnPayload(context, stripManagedFields(context, rawPayload
|
|
7971
|
+
envelopePayload: row.mutationKind === "delete" ? entityKey : toSqlColumnPayload(context, stripManagedFields(context, rawPayload["value"] ?? rawPayload["patch"] ?? rawPayload, row.mutationKind)),
|
|
7959
7972
|
sqlTableName: context.entry.shape?.tableName ?? context.key
|
|
7960
7973
|
};
|
|
7961
7974
|
pending.push(preparedRow);
|
|
@@ -8279,8 +8292,8 @@ class MutationRequestError extends Error {
|
|
|
8279
8292
|
status;
|
|
8280
8293
|
constructor(message, status) {
|
|
8281
8294
|
super(message);
|
|
8282
|
-
this.status = status;
|
|
8283
8295
|
this.name = "MutationRequestError";
|
|
8296
|
+
this.status = status;
|
|
8284
8297
|
}
|
|
8285
8298
|
}
|
|
8286
8299
|
|
|
@@ -8720,4 +8733,4 @@ export {
|
|
|
8720
8733
|
createSyncClient
|
|
8721
8734
|
};
|
|
8722
8735
|
|
|
8723
|
-
//# debugId=
|
|
8736
|
+
//# debugId=8A9E313F338EF35D64756E2164756E21
|