@pgxsinkit/server 0.1.53 → 0.2.0
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/electric-proxy.d.ts +2 -1
- package/dist/electric-proxy.d.ts.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -14
- package/dist/index.js.map +6 -6
- package/dist/mutations/plpgsql-apply.d.ts.map +1 -1
- package/dist/mutations/route.d.ts +2 -2
- package/dist/mutations/route.d.ts.map +1 -1
- package/package.json +2 -2
- package/skills/deploying/SKILL.md +6 -6
- package/src/electric-proxy.ts +2 -1
- package/src/index.ts +12 -10
- package/src/mutations/plpgsql-apply.ts +6 -13
- package/src/mutations/route.ts +2 -2
package/dist/electric-proxy.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export interface ElectricProxyOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* Opt-in per-request timing log (default off). When on, each forwarded shape request emits one compact
|
|
23
23
|
* `[pgxsinkit-timing]` line (route `"shape"`) with the request's table/live/offset and the upstream
|
|
24
|
-
* Electric fetch duration + status, for attributing read-path latency.
|
|
24
|
+
* Electric fetch duration + status, for attributing read-path latency. Off by default — a pure
|
|
25
|
+
* diagnostic surface that adds no standing query or latency when unset.
|
|
25
26
|
*/
|
|
26
27
|
logTimings?: boolean;
|
|
27
28
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electric-proxy.d.ts","sourceRoot":"","sources":["../src/electric-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAId,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAI9B,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB
|
|
1
|
+
{"version":3,"file":"electric-proxy.d.ts","sourceRoot":"","sources":["../src/electric-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAId,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAI9B,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;;;OAQG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAeD;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAYnB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import type { JwtClaims, RegistryRelations, RegistryTables, SyncRuntimeStatus, S
|
|
|
3
3
|
import { type StartupVerificationMode } from "./mutations/route";
|
|
4
4
|
/**
|
|
5
5
|
* How the operations-log table's presence is resolved at startup (ADR-0030 decision 3):
|
|
6
|
-
* - `"probe"` (default):
|
|
7
|
-
* disabled at runtime (with a warning) if it is absent
|
|
6
|
+
* - `"probe"` (default): the safe degradation posture (ADR-0030) — one query ensures/confirms the table,
|
|
7
|
+
* and logging is disabled at runtime (with a warning) if it is absent, so a missing table degrades
|
|
8
|
+
* gracefully instead of failing writes.
|
|
8
9
|
* - `"enabled"`: assume the table exists — NO query. If it is actually absent, writes then fail loudly.
|
|
9
10
|
* - `"disabled"`: turn logging off with NO query.
|
|
10
11
|
*
|
|
@@ -14,8 +15,9 @@ import { type StartupVerificationMode } from "./mutations/route";
|
|
|
14
15
|
export type OperationsLogStartupMode = "probe" | "enabled" | "disabled";
|
|
15
16
|
/**
|
|
16
17
|
* The `deployment` profile owns the server's startup query posture (ADR-0030 decision 3). Its defaults
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
* are the safe degradation posture — probe-and-verify at startup — so a long-lived host that never sets
|
|
19
|
+
* it still verifies and degrades gracefully; serverless / per-request workers set
|
|
20
|
+
* `{ startupVerification: "deploy-time", operationsLog: "enabled" | "disabled" }` for a
|
|
19
21
|
* zero-startup-query first write.
|
|
20
22
|
*/
|
|
21
23
|
export interface DeploymentProfile {
|
|
@@ -54,13 +56,14 @@ export interface CreateSyncServerOptions<TRegistry extends SyncTableRegistry, TD
|
|
|
54
56
|
* The startup query posture (ADR-0030). The apply function now verifies its own ADR-0018 fingerprint
|
|
55
57
|
* in-body on every call (SQLSTATE `PXS01` on drift), so there is no startup drift check to configure;
|
|
56
58
|
* this governs only the RLS auth-helper verify and the operations-log presence resolution. Defaults
|
|
57
|
-
*
|
|
59
|
+
* are the safe degradation posture (ADR-0030). See {@link DeploymentProfile}.
|
|
58
60
|
*/
|
|
59
61
|
deployment?: DeploymentProfile;
|
|
60
62
|
/**
|
|
61
63
|
* Opt-in per-request timing log (default false). When on, each mutation and shape-proxy request emits
|
|
62
64
|
* one compact `[pgxsinkit-timing]` line with an ISO-8601(ms, UTC) timestamp and phase durations, for
|
|
63
|
-
* attributing wall-clock latency against the client's `syncDebug` lines.
|
|
65
|
+
* attributing wall-clock latency against the client's `syncDebug` lines. Off by default — a pure
|
|
66
|
+
* diagnostic surface that adds no standing query or latency when unset.
|
|
64
67
|
*/
|
|
65
68
|
logTimings?: boolean;
|
|
66
69
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,mBAAmB,CAAC;AAoB3B
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,mBAAmB,CAAC;AAoB3B;;;;;;;;;;GAUG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,8GAA8G;IAC9G,mBAAmB,CAAC,EAAE,uBAAuB,CAAC;IAC9C,4EAA4E;IAC5E,aAAa,CAAC,EAAE,wBAAwB,CAAC;CAC1C;AAED,MAAM,WAAW,uBAAuB,CACtC,SAAS,SAAS,iBAAiB,EACnC,GAAG,SAAS,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,GAAG,eAAe,CAC3F,gBAAgB,EAChB,iBAAiB,CAAC,SAAS,CAAC,CAC7B;IAED,QAAQ,EAAE,SA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C,OAAO,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACnG,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -532,16 +532,14 @@ function buildTableBranch(entry) {
|
|
|
532
532
|
}
|
|
533
533
|
var APPLY_FUNCTION_NAME = "pgxsinkit_apply_mutations";
|
|
534
534
|
var APPLY_FUNCTION_ARG_TYPES = "jsonb, text, boolean, boolean, jsonb, text";
|
|
535
|
-
var APPLY_FUNCTION_ARG_TYPES_LEGACY = "jsonb, text, boolean, boolean, jsonb";
|
|
536
535
|
var APPLY_FINGERPRINT_PREFIX = "pgxsinkit:fp1:";
|
|
537
536
|
function buildApplyFunctionBody(registry, options = {}) {
|
|
538
537
|
const tableBranches = Object.values(registry).filter((entry) => !entry.readProjection).map((entry) => buildTableBranch(entry)).join(`
|
|
539
538
|
`);
|
|
540
539
|
const functionName = qualifyIdent(options.functionSchema, APPLY_FUNCTION_NAME);
|
|
541
540
|
return `
|
|
542
|
-
--
|
|
543
|
-
-- return
|
|
544
|
-
-- first. Idempotent: re-running installs the same definition.
|
|
541
|
+
-- Install idempotently by dropping the current signature first. PostgreSQL cannot change a function's
|
|
542
|
+
-- return type through CREATE OR REPLACE, while a generated artifact must install its complete definition.
|
|
545
543
|
--
|
|
546
544
|
-- TWO-TIER MUTATION-ID INVARIANT. \`mutation_id\` is TEXT here (RETURNS TABLE + operations_log), not
|
|
547
545
|
-- uuid, so this apply function can serve a DIRECT server-side caller that derives child envelopes with
|
|
@@ -551,11 +549,6 @@ function buildApplyFunctionBody(registry, options = {}) {
|
|
|
551
549
|
-- builds every ack from that request id, never from the TEXT conflict rows this returns. A non-UUID id
|
|
552
550
|
-- therefore never crosses into the UUID-typed surface.
|
|
553
551
|
--
|
|
554
|
-
-- ADR-0030: the signature gained a trailing p_expected_fingerprint text, so the prior (pre-ADR-0030,
|
|
555
|
-
-- 5-arg) function is a DIFFERENT overload \u2014 drop it too, else a CREATE of the 6-arg form would leave a
|
|
556
|
-
-- stale 5-arg beside it. The runtime only ever calls the 6-arg form; dropping the legacy one keeps an
|
|
557
|
-
-- in-place upgrade clean.
|
|
558
|
-
DROP FUNCTION IF EXISTS ${functionName}(${APPLY_FUNCTION_ARG_TYPES_LEGACY});
|
|
559
552
|
DROP FUNCTION IF EXISTS ${functionName}(${APPLY_FUNCTION_ARG_TYPES});
|
|
560
553
|
|
|
561
554
|
CREATE OR REPLACE FUNCTION ${functionName}(
|
|
@@ -591,7 +584,7 @@ BEGIN
|
|
|
591
584
|
-- ADR-0030: the apply function verifies ITSELF against its ADR-0018 fingerprint comment before it
|
|
592
585
|
-- touches any table. p_expected_fingerprint is what the running server expects for its registry +
|
|
593
586
|
-- codegen; obj_description(...) is the fingerprint this installed function was stamped with, atomically,
|
|
594
|
-
-- by the same migration. A mismatch \u2014 INCLUDING an absent comment (
|
|
587
|
+
-- by the same migration. A mismatch \u2014 INCLUDING an absent comment (an unstamped hand-installed
|
|
595
588
|
-- function \u21D2 NULL, refused per ADR-0030) \u2014 means the installed function is stale relative to the caller,
|
|
596
589
|
-- so raise SQLSTATE 'PXS01' and apply nothing. The check IS the call (no read-then-call TOCTOU) and
|
|
597
590
|
-- costs no extra round trip (the argument rides the existing invocation; the comparison is one text
|
|
@@ -773,8 +766,8 @@ async function executePlpgsqlBatch(tx, batch, requestPath, logEnabled, rlsEnable
|
|
|
773
766
|
var { createInsertSchema: createMutationInsertSchema } = createSchemaFactory({
|
|
774
767
|
coerce: { date: true }
|
|
775
768
|
});
|
|
776
|
-
var batchMutationPaths = ["/api/mutations"
|
|
777
|
-
var authoritativeMutationPaths = ["/api/mutations/unit"
|
|
769
|
+
var batchMutationPaths = ["/api/mutations"];
|
|
770
|
+
var authoritativeMutationPaths = ["/api/mutations/unit"];
|
|
778
771
|
function createMutationHandler(db, registry, operationsLogConfig, operationsLogReady, resolveAuthClaims, startupVerification = "in-process", logTimings = false) {
|
|
779
772
|
let startupReadyPromise;
|
|
780
773
|
const expectedFingerprint = expectedApplyFingerprint(registry);
|
|
@@ -1643,7 +1636,7 @@ function createSyncServer(options) {
|
|
|
1643
1636
|
operationsLogReady = Promise.resolve();
|
|
1644
1637
|
}
|
|
1645
1638
|
const shapeProxyPath = options.shapeProxyPath ?? "/api/shape";
|
|
1646
|
-
const corsScopes = [{ prefix: "/api/" }
|
|
1639
|
+
const corsScopes = [{ prefix: "/api/" }];
|
|
1647
1640
|
if (options.electricUrl) {
|
|
1648
1641
|
corsScopes.push({ exact: shapeProxyPath });
|
|
1649
1642
|
}
|
|
@@ -1778,4 +1771,4 @@ export {
|
|
|
1778
1771
|
FetchRouter
|
|
1779
1772
|
};
|
|
1780
1773
|
|
|
1781
|
-
//# debugId=
|
|
1774
|
+
//# debugId=DBEB97BDC16D59BA64756E2164756E21
|