@pgxsinkit/contracts 0.2.7 → 0.5.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/dist/apply-strategy.d.ts +13 -1
  3. package/dist/apply-strategy.d.ts.map +1 -1
  4. package/dist/config.d.ts +256 -87
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/convergence-model.d.ts +2 -2
  7. package/dist/convergence-model.d.ts.map +1 -1
  8. package/dist/event-stream.d.ts +1 -1
  9. package/dist/fingerprint.d.ts +31 -11
  10. package/dist/fingerprint.d.ts.map +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +480 -202
  14. package/dist/index.js.map +16 -14
  15. package/dist/predicate.d.ts +162 -0
  16. package/dist/predicate.d.ts.map +1 -0
  17. package/dist/projection.d.ts +2 -2
  18. package/dist/projection.d.ts.map +1 -1
  19. package/dist/registry-diff.d.ts.map +1 -1
  20. package/dist/registry-invariant.d.ts +26 -14
  21. package/dist/registry-invariant.d.ts.map +1 -1
  22. package/dist/registry.d.ts +74 -48
  23. package/dist/registry.d.ts.map +1 -1
  24. package/dist/sql-role-guard.d.ts +1 -1
  25. package/dist/stream-envelope.d.ts +84 -0
  26. package/dist/stream-envelope.d.ts.map +1 -0
  27. package/dist/supabase-rls.d.ts +32 -36
  28. package/dist/supabase-rls.d.ts.map +1 -1
  29. package/package.json +3 -2
  30. package/skills/registry-authoring/SKILL.md +185 -185
  31. package/skills/registry-authoring/references/storage-engine-and-build.md +29 -0
  32. package/src/apply-strategy.ts +23 -4
  33. package/src/config.ts +340 -116
  34. package/src/convergence-model.ts +2 -2
  35. package/src/event-stream.ts +1 -1
  36. package/src/fingerprint.ts +76 -14
  37. package/src/index.ts +2 -0
  38. package/src/predicate.ts +274 -0
  39. package/src/projection.ts +6 -2
  40. package/src/registry-diff.ts +15 -4
  41. package/src/registry-invariant.ts +34 -19
  42. package/src/registry.ts +324 -78
  43. package/src/sql-role-guard.ts +1 -1
  44. package/src/stream-envelope.ts +91 -0
  45. package/src/supabase-rls.ts +76 -74
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Static, type-driven read-path apply ladder (ADR-0009 decision 3).
3
3
  *
4
- * We own the registry's column types ahead of time and only ever target the latest PGlite, so the
4
+ * We own the registry's column types ahead of time and only ever target the latest pgwasm, so the
5
5
  * bulk-insert strategy for a synced table is chosen **once, statically** from its column types —
6
6
  * never by probing `information_schema` at runtime. This module is the pure, dependency-free core
7
7
  * (no registry, no Drizzle import) so it stays in the fast unit lane; {@link deriveSyncColumnTypes}
@@ -36,7 +36,7 @@ export interface SyncColumnType {
36
36
  }
37
37
 
38
38
  /**
39
- * Postgres scalar types whose JS→CSV-text rendering is unambiguous, so PGlite `COPY ... FROM`
39
+ * Postgres scalar types whose JS→CSV-text rendering is unambiguous, so pgwasm `COPY ... FROM`
40
40
  * round-trips them losslessly. Deliberately **conservative** (ADR-0009 decision 3): never add a
41
41
  * type here unless `COPY` truly handles it. Notably EXCLUDES timestamps/dates (format nuances),
42
42
  * `numeric` (precision/format), `bytea`, `interval`, `json`/`jsonb`, and arrays — those route to the
@@ -85,7 +85,7 @@ function isCopySafe(column: SyncColumnType): boolean {
85
85
  if (column.isArray) {
86
86
  return false;
87
87
  }
88
- // Enum labels are plain text on the COPY wire; PGlite's COPY input casts them into the enum type
88
+ // Enum labels are plain text on the COPY wire; pgwasm's COPY input casts them into the enum type
89
89
  // losslessly, so an enum column is COPY-safe even though its `sqlType` (the enum name) is not a base type.
90
90
  if (column.isEnum) {
91
91
  return true;
@@ -95,7 +95,7 @@ function isCopySafe(column: SyncColumnType): boolean {
95
95
 
96
96
  /**
97
97
  * `json_to_recordset` extends the COPY-safe set with arrays, `json`, and `jsonb` — viable now that
98
- * the latest PGlite round-trips bigint and bigint[] correctly (ADR-0009 decision 3).
98
+ * the latest pgwasm round-trips bigint and bigint[] correctly (ADR-0009 decision 3).
99
99
  */
100
100
  function isJsonSafe(column: SyncColumnType): boolean {
101
101
  if (isCopySafe(column)) {
@@ -108,6 +108,25 @@ function isJsonSafe(column: SyncColumnType): boolean {
108
108
  return base === "json" || base === "jsonb";
109
109
  }
110
110
 
111
+ /**
112
+ * The Postgres `udt_name` of a `json`/`jsonb` column — `json`/`jsonb` for a scalar one, `_json`/`_jsonb`
113
+ * for an array one — and `undefined` for every other column. The single classifier for "is this a JSON
114
+ * column, and is it an array of them?", shared by the read path's wire decode (which parses the cell of a
115
+ * SCALAR json column — see `envelopeToChange`) and the COPY serializer's `udtName` map, so the two cannot
116
+ * disagree about which columns carry JSON.
117
+ *
118
+ * The array forms are reported but deliberately NOT decoded: an array column arrives (and stays) in
119
+ * Postgres's own `array_out` text, which every apply tier hands straight back to `array_in` — the element
120
+ * JSON inside it is Postgres's business, not ours.
121
+ */
122
+ export function jsonUdtName(column: SyncColumnType): "json" | "jsonb" | "_json" | "_jsonb" | undefined {
123
+ const base = normalizeBaseType(column.sqlType);
124
+ if (base !== "json" && base !== "jsonb") {
125
+ return undefined;
126
+ }
127
+ return column.isArray ? (`_${base}` as const) : base;
128
+ }
129
+
111
130
  /**
112
131
  * Chooses the bulk-insert strategy for a table from its column types (ADR-0009 decision 3):
113
132
  * - every column COPY-safe → `copy`;