@pgxsinkit/contracts 0.1.30 → 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/common.d.ts +3 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/config.d.ts +132 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -74
- package/dist/index.js.map +5 -5
- package/dist/mutation.d.ts +85 -0
- package/dist/mutation.d.ts.map +1 -0
- package/dist/registry.d.ts +475 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/supabase-rls.d.ts +20 -0
- package/dist/supabase-rls.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/config.ts +26 -1
- package/src/registry.ts +64 -19
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,sBAAsB,aAA+B,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export type TableMode = "readonly" | "writeonly" | "readwrite";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal verified-JWT claim shape the sync layer understands. Providers may
|
|
5
|
+
* attach arbitrary extra claims; those stay reachable through index access and
|
|
6
|
+
* ownership claim paths (e.g. "app_metadata.person_id"). Parse decoded JWT
|
|
7
|
+
* payloads with this schema at the auth boundary so the static type is honest.
|
|
8
|
+
*/
|
|
9
|
+
export declare const jwtClaimsSchema: z.ZodObject<{
|
|
10
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
11
|
+
app_metadata: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
13
|
+
}, z.core.$loose>>;
|
|
14
|
+
}, z.core.$loose>;
|
|
15
|
+
export type JwtClaims = z.infer<typeof jwtClaimsSchema>;
|
|
16
|
+
export interface PrimaryKeySpec {
|
|
17
|
+
columns: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface ShapeSpec {
|
|
20
|
+
tableName: string;
|
|
21
|
+
shapeKey: string;
|
|
22
|
+
electricTable?: string;
|
|
23
|
+
rowFilter?: RowFilterSpec;
|
|
24
|
+
}
|
|
25
|
+
/** Input variant of {@link ShapeSpec} where `tableName` and `shapeKey` are optional.
|
|
26
|
+
* When omitted, both default to the top-level `tableName` of the `defineSyncTable` call. */
|
|
27
|
+
export type ShapeSpecInput = Omit<ShapeSpec, "tableName" | "shapeKey"> & {
|
|
28
|
+
tableName?: string;
|
|
29
|
+
shapeKey?: string;
|
|
30
|
+
};
|
|
31
|
+
/** Context available to a {@link RowTransform}: the verified claims and any extra runtime params. */
|
|
32
|
+
export interface RowTransformContext {
|
|
33
|
+
claims: JwtClaims | null;
|
|
34
|
+
params?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Per-row rewrite applied in the proxy response path (after the row filter, before
|
|
38
|
+
* column omission). Receives a shape-log row's column map (keys are wire/column names)
|
|
39
|
+
* and returns a possibly-rewritten one — letting the server strip a *sub-document* of a
|
|
40
|
+
* jsonb column, or otherwise rewrite a value, *conditionally on row data*. This expresses
|
|
41
|
+
* what a static, whole-column `omitColumns` cannot.
|
|
42
|
+
*
|
|
43
|
+
* It runs only in the proxy's per-response path: it never alters the local PGlite schema,
|
|
44
|
+
* never changes the Electric shape URL, and so never pollutes Electric's shared shape
|
|
45
|
+
* cache. Return the same `row` reference to signal "no change".
|
|
46
|
+
*/
|
|
47
|
+
export type RowTransform = (row: Record<string, unknown>, context: RowTransformContext) => Record<string, unknown>;
|
|
48
|
+
export interface ClientProjectionSpec {
|
|
49
|
+
syncedTable?: string;
|
|
50
|
+
overlayTable?: string;
|
|
51
|
+
journalTable?: string;
|
|
52
|
+
omitColumns?: readonly string[];
|
|
53
|
+
/**
|
|
54
|
+
* Optional per-row rewrite applied in the proxy response path. Runs before column
|
|
55
|
+
* omission, so it may read a column (e.g. a control flag) that `omitColumns` then
|
|
56
|
+
* removes from the client-visible row. See {@link RowTransform}.
|
|
57
|
+
*/
|
|
58
|
+
rowTransform?: RowTransform;
|
|
59
|
+
localPrimaryKey?: PrimaryKeySpec;
|
|
60
|
+
}
|
|
61
|
+
export interface DeferrableConstraintSpec {
|
|
62
|
+
constraintName: string;
|
|
63
|
+
columns: string[];
|
|
64
|
+
initiallyDeferred?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export type ManagedFieldApplyOn = "create" | "update";
|
|
67
|
+
export type ManagedFieldStrategy = "authUid" | "nowMicroseconds";
|
|
68
|
+
export interface ManagedFieldSpec {
|
|
69
|
+
column: string;
|
|
70
|
+
applyOn: ManagedFieldApplyOn[];
|
|
71
|
+
strategy: ManagedFieldStrategy;
|
|
72
|
+
}
|
|
73
|
+
export interface TableGovernanceSpec {
|
|
74
|
+
deferrableConstraints?: DeferrableConstraintSpec[];
|
|
75
|
+
managedFields?: ManagedFieldSpec[];
|
|
76
|
+
}
|
|
77
|
+
export interface TableSpecInput {
|
|
78
|
+
mode: TableMode;
|
|
79
|
+
primaryKey: PrimaryKeySpec;
|
|
80
|
+
shape?: ShapeSpec;
|
|
81
|
+
clientProjection?: ClientProjectionSpec;
|
|
82
|
+
governance?: TableGovernanceSpec;
|
|
83
|
+
}
|
|
84
|
+
export interface SyncConfigInput<TTables extends Record<string, TableSpecInput> = Record<string, TableSpecInput>> {
|
|
85
|
+
electricUrl: string;
|
|
86
|
+
localSchema?: string;
|
|
87
|
+
tables: TTables;
|
|
88
|
+
}
|
|
89
|
+
export declare function getLocalSyncPrimaryKey(source: {
|
|
90
|
+
primaryKey: PrimaryKeySpec;
|
|
91
|
+
clientProjection?: Pick<ClientProjectionSpec, "localPrimaryKey">;
|
|
92
|
+
}): PrimaryKeySpec;
|
|
93
|
+
export declare function getLocalSyncPrimaryKeyColumns(source: {
|
|
94
|
+
primaryKey: PrimaryKeySpec;
|
|
95
|
+
clientProjection?: Pick<ClientProjectionSpec, "localPrimaryKey">;
|
|
96
|
+
}): string[];
|
|
97
|
+
export interface RowFilterSpec {
|
|
98
|
+
/** WHERE "column" = '<owner claim>' — ownership-based row filtering. */
|
|
99
|
+
ownership?: {
|
|
100
|
+
column: string;
|
|
101
|
+
/**
|
|
102
|
+
* Dot-path into the JWT claims used as the owner value (e.g.
|
|
103
|
+
* "app_metadata.person_id"). Defaults to "sub". A missing, empty, or
|
|
104
|
+
* non-primitive claim denies all rows, matching the missing-sub behavior.
|
|
105
|
+
*/
|
|
106
|
+
claim?: string;
|
|
107
|
+
};
|
|
108
|
+
/** OR clause for shared content: adds rows owned by sharedUserId. */
|
|
109
|
+
shared?: {
|
|
110
|
+
/** Column used for owner comparison. Defaults to ownership.column. */
|
|
111
|
+
ownerColumn?: string;
|
|
112
|
+
/** If set, also requires "sharedColumn" = true. */
|
|
113
|
+
sharedColumn?: string;
|
|
114
|
+
/** Static UUID or a function that returns a UUID given runtime params. */
|
|
115
|
+
sharedUserId: string | ((params: Record<string, unknown>) => string);
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Escape hatch: returns a raw SQL fragment ANDed with other filters.
|
|
119
|
+
* Return `null` to bypass all filters (e.g. admin access).
|
|
120
|
+
*/
|
|
121
|
+
customWhere?: (claims: JwtClaims, params?: Record<string, unknown>) => string | null;
|
|
122
|
+
/** Column projection for the shape URL (e.g. ["id", "source_text"]). */
|
|
123
|
+
columns?: string[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Composes ownership, shared, and customWhere filters into a single
|
|
127
|
+
* SQL WHERE clause suitable for Electric shape requests.
|
|
128
|
+
*
|
|
129
|
+
* Returns null if no filters apply (all rows visible).
|
|
130
|
+
*/
|
|
131
|
+
export declare function buildRowFilterWhere(filter: RowFilterSpec, claims: JwtClaims | null, params?: Record<string, unknown>): string | null;
|
|
132
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,eAAe;;;;;iBAO1B,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED;4FAC4F;AAC5F,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,UAAU,CAAC,GAAG;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,qGAAqG;AACrG,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,mBAAmB,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnH,MAAM,WAAW,oBA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