@owlmeans/postgres-resource 0.1.18-rc.41 → 0.1.18-rc.43

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 (171) hide show
  1. package/README.md +13 -13
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/postgres-resource/SKILL.md +2 -2
  4. package/build/consts.d.ts +9 -0
  5. package/build/consts.d.ts.map +1 -1
  6. package/build/consts.js +6 -0
  7. package/build/consts.js.map +1 -1
  8. package/build/declarations/types.d.ts +12 -0
  9. package/build/declarations/types.d.ts.map +1 -0
  10. package/build/declarations/types.js +2 -0
  11. package/build/declarations/types.js.map +1 -0
  12. package/build/declarations.d.ts +6 -9
  13. package/build/declarations.d.ts.map +1 -1
  14. package/build/declarations.js +25 -15
  15. package/build/declarations.js.map +1 -1
  16. package/build/errors.d.ts +0 -20
  17. package/build/errors.d.ts.map +1 -1
  18. package/build/errors.js +1 -111
  19. package/build/errors.js.map +1 -1
  20. package/build/index.d.ts +3 -0
  21. package/build/index.d.ts.map +1 -1
  22. package/build/index.js +1 -0
  23. package/build/index.js.map +1 -1
  24. package/build/pg-error/types.d.ts +24 -0
  25. package/build/pg-error/types.d.ts.map +1 -0
  26. package/build/pg-error/types.js +2 -0
  27. package/build/pg-error/types.js.map +1 -0
  28. package/build/pg-error.d.ts +4 -0
  29. package/build/pg-error.d.ts.map +1 -0
  30. package/build/pg-error.js +100 -0
  31. package/build/pg-error.js.map +1 -0
  32. package/build/resource.d.ts +1 -1
  33. package/build/resource.d.ts.map +1 -1
  34. package/build/resource.js +15 -11
  35. package/build/resource.js.map +1 -1
  36. package/build/types.d.ts +6 -1
  37. package/build/types.d.ts.map +1 -1
  38. package/build/types.local.d.ts +14 -0
  39. package/build/types.local.d.ts.map +1 -0
  40. package/build/types.local.js +2 -0
  41. package/build/types.local.js.map +1 -0
  42. package/build/utils/consts.local.d.ts +35 -0
  43. package/build/utils/consts.local.d.ts.map +1 -0
  44. package/build/utils/consts.local.js +63 -0
  45. package/build/utils/consts.local.js.map +1 -0
  46. package/build/utils/criteria/types.d.ts +31 -0
  47. package/build/utils/criteria/types.d.ts.map +1 -0
  48. package/build/utils/criteria/types.js +2 -0
  49. package/build/utils/criteria/types.js.map +1 -0
  50. package/build/utils/criteria.d.ts +3 -27
  51. package/build/utils/criteria.d.ts.map +1 -1
  52. package/build/utils/criteria.js +88 -107
  53. package/build/utils/criteria.js.map +1 -1
  54. package/build/utils/diff/types.d.ts +40 -0
  55. package/build/utils/diff/types.d.ts.map +1 -0
  56. package/build/utils/diff/types.js +2 -0
  57. package/build/utils/diff/types.js.map +1 -0
  58. package/build/utils/diff.d.ts +5 -35
  59. package/build/utils/diff.d.ts.map +1 -1
  60. package/build/utils/diff.js +321 -343
  61. package/build/utils/diff.js.map +1 -1
  62. package/build/utils/index.d.ts +10 -0
  63. package/build/utils/index.d.ts.map +1 -1
  64. package/build/utils/index.js.map +1 -1
  65. package/build/utils/introspect/types.d.ts +9 -0
  66. package/build/utils/introspect/types.d.ts.map +1 -0
  67. package/build/utils/introspect/types.js +2 -0
  68. package/build/utils/introspect/types.js.map +1 -0
  69. package/build/utils/introspect.d.ts +3 -3
  70. package/build/utils/introspect.d.ts.map +1 -1
  71. package/build/utils/introspect.js +42 -67
  72. package/build/utils/introspect.js.map +1 -1
  73. package/build/utils/life-cycle/types.d.ts +37 -0
  74. package/build/utils/life-cycle/types.d.ts.map +1 -0
  75. package/build/utils/life-cycle/types.js +2 -0
  76. package/build/utils/life-cycle/types.js.map +1 -0
  77. package/build/utils/life-cycle.d.ts +3 -38
  78. package/build/utils/life-cycle.d.ts.map +1 -1
  79. package/build/utils/life-cycle.js +90 -107
  80. package/build/utils/life-cycle.js.map +1 -1
  81. package/build/utils/marshal/types.d.ts +39 -0
  82. package/build/utils/marshal/types.d.ts.map +1 -0
  83. package/build/utils/marshal/types.js +2 -0
  84. package/build/utils/marshal/types.js.map +1 -0
  85. package/build/utils/marshal.d.ts +4 -32
  86. package/build/utils/marshal.d.ts.map +1 -1
  87. package/build/utils/marshal.js +124 -141
  88. package/build/utils/marshal.js.map +1 -1
  89. package/build/utils/migrations.d.ts.map +1 -1
  90. package/build/utils/migrations.js +41 -36
  91. package/build/utils/migrations.js.map +1 -1
  92. package/build/utils/name/types.d.ts +43 -0
  93. package/build/utils/name/types.d.ts.map +1 -0
  94. package/build/utils/name/types.js +2 -0
  95. package/build/utils/name/types.js.map +1 -0
  96. package/build/utils/name.d.ts +6 -35
  97. package/build/utils/name.d.ts.map +1 -1
  98. package/build/utils/name.js +40 -59
  99. package/build/utils/name.js.map +1 -1
  100. package/build/utils/schema/types.d.ts +22 -0
  101. package/build/utils/schema/types.d.ts.map +1 -0
  102. package/build/utils/schema/types.js +2 -0
  103. package/build/utils/schema/types.js.map +1 -0
  104. package/build/utils/schema.d.ts +4 -24
  105. package/build/utils/schema.d.ts.map +1 -1
  106. package/build/utils/schema.js +341 -352
  107. package/build/utils/schema.js.map +1 -1
  108. package/build/utils/sql/types.d.ts +25 -0
  109. package/build/utils/sql/types.d.ts.map +1 -0
  110. package/build/utils/sql/types.js +2 -0
  111. package/build/utils/sql/types.js.map +1 -0
  112. package/build/utils/sql.d.ts +5 -27
  113. package/build/utils/sql.d.ts.map +1 -1
  114. package/build/utils/sql.js +0 -0
  115. package/build/utils/sql.js.map +1 -1
  116. package/build/utils/sync/types.d.ts +25 -0
  117. package/build/utils/sync/types.d.ts.map +1 -0
  118. package/build/utils/sync/types.js +2 -0
  119. package/build/utils/sync/types.js.map +1 -0
  120. package/build/utils/sync.d.ts +2 -19
  121. package/build/utils/sync.d.ts.map +1 -1
  122. package/build/utils/sync.js +67 -84
  123. package/build/utils/sync.js.map +1 -1
  124. package/build/utils/types.d.ts +18 -0
  125. package/build/utils/types.d.ts.map +1 -0
  126. package/build/utils/types.js +2 -0
  127. package/build/utils/types.js.map +1 -0
  128. package/build/utils/types.local.d.ts +33 -0
  129. package/build/utils/types.local.d.ts.map +1 -0
  130. package/build/utils/types.local.js +2 -0
  131. package/build/utils/types.local.js.map +1 -0
  132. package/package.json +14 -13
  133. package/src/consts.ts +7 -0
  134. package/src/declarations/types.ts +12 -0
  135. package/src/declarations.ts +30 -23
  136. package/src/errors.ts +1 -131
  137. package/src/index.ts +3 -0
  138. package/src/pg-error/types.ts +23 -0
  139. package/src/pg-error.ts +114 -0
  140. package/src/resource.ts +20 -24
  141. package/src/types.local.ts +16 -0
  142. package/src/types.ts +8 -4
  143. package/src/utils/consts.local.ts +71 -0
  144. package/src/utils/criteria/types.ts +32 -0
  145. package/src/utils/criteria.ts +99 -129
  146. package/src/utils/diff/types.ts +41 -0
  147. package/src/utils/diff.ts +331 -348
  148. package/src/utils/index.ts +10 -0
  149. package/src/utils/introspect/types.ts +9 -0
  150. package/src/utils/introspect.ts +54 -79
  151. package/src/utils/life-cycle/types.ts +41 -0
  152. package/src/utils/life-cycle.ts +108 -134
  153. package/src/utils/marshal/types.ts +40 -0
  154. package/src/utils/marshal.ts +134 -147
  155. package/src/utils/migrations.ts +39 -33
  156. package/src/utils/name/types.ts +44 -0
  157. package/src/utils/name.ts +49 -63
  158. package/src/utils/schema/types.ts +26 -0
  159. package/src/utils/schema.ts +366 -397
  160. package/src/utils/sql/types.ts +25 -0
  161. package/src/utils/sql.ts +0 -0
  162. package/src/utils/sync/types.ts +25 -0
  163. package/src/utils/sync.ts +65 -83
  164. package/src/utils/types.local.ts +35 -0
  165. package/src/utils/types.ts +19 -0
  166. package/tests/criteria.spec.ts +4 -1
  167. package/tests/diff.spec.ts +28 -1
  168. package/tests/errors.spec.ts +4 -3
  169. package/tests/name.spec.ts +5 -3
  170. package/tests/schema.spec.ts +3 -1
  171. package/tests/sql.spec.ts +20 -22
package/README.md CHANGED
@@ -13,7 +13,7 @@ SQL. Other stores fit other shapes:
13
13
  ## Installation
14
14
 
15
15
  ```bash
16
- bun add @owlmeans/postgres-resource@^0.1.18-rc.41 @owlmeans/postgres@^0.1.18-rc.43 pg
16
+ bun add @owlmeans/postgres-resource@^0.1.18-rc.43 @owlmeans/postgres@^0.1.18-rc.45 pg
17
17
  ```
18
18
 
19
19
  `pg` and `ajv` are peer dependencies of this package. `@owlmeans/postgres` provides the connection
@@ -81,7 +81,7 @@ await projects.update({ ...record, title: 'Renamed' }) // replace
81
81
 
82
82
  `size` defaults to `DEFAULT_PAGE_SIZE` (100); `list(where, { size: 0 })` lifts the limit. `total`
83
83
  always describes the whole match, independently of the page. `entityId` is the organization's
84
- stable record id from `requireEntityKey(req)`, never a value read off the token.
84
+ stable record id from `makeEntityScope(req).requireEntityKey()`, never a value read off the token.
85
85
 
86
86
  ### Schema to table
87
87
 
@@ -224,7 +224,7 @@ are `@>`/`<@`/`&&` on array columns.
224
224
  `PostgresError` and its subclasses are `PostgresSyncError`, `PostgresCastRequired`,
225
225
  `PostgresConstraintError`, `PostgresForeignKeyError`, `PostgresCheckError`, `PostgresDeadlockError`
226
226
  (`retryable`), `PostgresPlaceholderError`, `PostgresConnectionError` and `PostgresBootstrapError`.
227
- Driver errors are translated by `pgErrorToResourceError`, which unwraps Drizzle's
227
+ Driver errors are translated by `pgErrorHelper.pgErrorToResourceError`, which unwraps Drizzle's
228
228
  `DrizzleQueryError` to reach the `pg` error underneath and preserves the raw
229
229
  `code`/`detail`/`hint`/`severity` in the message. Unique violations surface as `RecordExists` and
230
230
  not-null violations as `MisshapedRecord`.
@@ -240,17 +240,17 @@ not-null violations as `MisshapedRecord`.
240
240
  | `PgPropertyOverride`, `PgRootOverride`, `PgIndexSpec`, `PgUniqueSpec`, `PgCheckSpec`, `PgReferenceSpec` | type | The `pg:` vocabulary and `index()` spec |
241
241
  | `LiveTable`, `LiveColumn`, `LiveIndex`, `LiveConstraint`, `DdlPlan`, `DdlStatement`, `DdlKind` | type | Introspection results and the reconciliation plan |
242
242
  | `pgKeyword` | const | `{ keyword: 'pg', valid: true }` for AJV strict mode |
243
- | `schemaToTableSpec`, `toFormatType` | function | The schema compiler |
244
- | `criteriaToSql`, `sortToSql` | function | `Criteria<T>` to a WHERE clause and `Sort<T>` to ORDER BY over the same table |
245
- | `refOf`, `resolvePlaceholders`, `resetPlaceholderCache`, `PlaceholderContext` | function / type | `{{alias}}` resolution, identifiers only |
246
- | `pgTableName`, `pgIdentifier`, `assertSqlIdentifier`, `quoteIdent`, `quoteLiteral`, `qualify`, `advisoryKey` | function | Identifier helpers |
247
- | `rowToRecord`, `resultToRecord`, `recordToValues`, `recordToFullValues`, `specToTable` | function | Row and record marshalling, Drizzle table construction |
248
- | `initializeTable`, `applyForeignKeys`, `TableInit` | function / type | The `init()` lifecycle |
249
- | `introspectTable`, `countNonNull`, `planSync`, `planForeignKeys`, `applyPlan`, `ensureSchema`, `acquireLock`, `releaseLock` | function | Reconciliation machinery |
243
+ | `pgSchemaHelper` (`PgSchemaHelper`) | helper | The schema compiler: `schemaToTableSpec`, `toFormatType` |
244
+ | `pgCriteriaHelper` (`PgCriteriaHelper`) | helper | `criteriaToSql` — `Criteria<T>` to a WHERE clause; `sortToSql` — `Sort<T>` to ORDER BY over the same table |
245
+ | `pgPlaceholdersOf(context)` (`makePgPlaceholderHelper`, `PgPlaceholderHelper`), `resetPlaceholderCache`, `PlaceholderContext` | helper / function / type | `{{alias}}` resolution through one context — `refOf(self, alias?)`, `resolvePlaceholders(text, self)` — identifiers only |
246
+ | `pgNameHelper` (`PgNameHelper`) | helper | Identifier helpers: `pgTableName`, `pgIdentifier`, `assertSqlIdentifier`, `quoteIdent`, `quoteLiteral`, `qualify`, `advisoryKey` |
247
+ | `pgMarshalHelper` (`PgMarshalHelper`), `specToTable` | helper / function | Row and record marshalling (`rowToRecord`, `resultToRecord`, `recordToValues`, `recordToFullValues`), Drizzle table construction |
248
+ | `makePgLifeCycleHelper(db)` (`PgLifeCycleHelper`), `TableInit` | helper / type | The `init()` lifecycle: `initializeTable`, `applyForeignKeys` |
249
+ | `makePgIntrospectHelper(client)`, `makePgSyncHelper(client)`, `pgDiffHelper` | helper | Reconciliation machinery: `introspectTable`, `countNonNull`; `acquireLock`, `releaseLock`, `ensureSchema`, `applyPlan`; `planSync`, `planForeignKeys`, `canonicalDefinition` |
250
250
  | `makeTx`, `makeMigrationStore` | function | The migration façade and ledger |
251
- | `getDeclaration`, `resetDeclarations`, `PostgresDeclaration` | function / type | Module-scope declarations per alias; `resetDeclarations` is the testing seam |
251
+ | `pgDeclarationHelper` (`PgDeclarationHelper`), `PostgresDeclaration` | helper / type | Module-scope declarations per alias: `getDeclaration`, and `resetDeclarations` — the testing seam |
252
252
  | `getSchemaSecureFeilds` | function | `secure: true` properties used by `lock`/`unlock` |
253
- | `pgErrorToResourceError`, `describePgError`, `PostgresError` family | function / class | Driver error translation |
253
+ | `pgErrorHelper` (`PgErrorHelper`), `PostgresError` family | helper / class | Driver error translation: `pgErrorToResourceError`, `describePgError` |
254
254
  | `DEFAULT_DB_ALIAS`, `DEFAULT_PAGE_SIZE`, `DEF_MIGRATIONS_TABLE` | const | `'postgres'`, `100`, `'_owlmeans_migrations'` |
255
255
  | `PG_KEYWORD`, `PG_MAX_IDENTIFIER`, `ID_FIELD`, `DEF_SQL_TYPE`, `DEF_JSON_TYPE`, `DEF_ID_DEFAULT`, `STRING_RETURNING_TYPES` | const | Compiler constants |
256
256
  | `PgAutoSync`, `PgIndexMethod`, `PgReferentialAction`, `PgErrorCode`, `PgTypeOid` | enum | Reconciliation policy, index methods, FK actions, driver codes, type OIDs |
@@ -293,7 +293,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
293
293
  your project's skill store (`.agents/skills/`):
294
294
 
295
295
  ```sh
296
- npx @owlmeans/agent-skills@^0.1.18-rc.46
296
+ npx @owlmeans/agent-skills@^0.1.18-rc.49
297
297
  ```
298
298
 
299
299
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/postgres-resource",
4
- "version": "0.1.18-rc.41",
5
- "generatedAt": "2026-10-03T15:33:53.022Z",
4
+ "version": "0.1.18-rc.43",
5
+ "generatedAt": "2026-10-05T21:03:06.396Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/postgres-resource
9
9
 
10
10
  **Layer:** Infra
11
- **Install:** `"@owlmeans/postgres-resource": "^0.1.18-rc.41"` in `dependencies` (peers `pg`, `ajv`)
11
+ **Install:** `"@owlmeans/postgres-resource": "^0.1.18-rc.43"` in `dependencies` (peers `pg`, `ajv`)
12
12
 
13
13
  The Postgres counterpart of [[mongo-resource]]. The difference that governs everything else: a
14
14
  Mongo collection has no structure, a Postgres table does — so **the resource layer owns the DDL**
@@ -100,7 +100,7 @@ declaration sites merge into one `TableSpec` — the schema root, a per-property
100
100
  not an error. Two entries under one name would emit the same `CREATE INDEX` twice in a single DDL
101
101
  transaction, and Postgres answers the second with `42P07`, rolling back the plan that created the
102
102
  table: the resource then fails every boot with an error naming an index that does not exist.
103
- The compiler collapses the duplicates itself, keeps the first declaration and warns on the console.
103
+ The compiler collapses the duplicates itself, keeps the first declaration and logs a warning.
104
104
 
105
105
  ## Reconciliation is authoritative — `PgAutoSync`
106
106
 
package/build/consts.d.ts CHANGED
@@ -15,6 +15,15 @@ export declare const DEFAULT_PAGE_SIZE = 100;
15
15
  export declare const DEF_MIGRATIONS_TABLE = "_owlmeans_migrations";
16
16
  /** JSON Schema keyword carrying the Postgres specific overrides. */
17
17
  export declare const PG_KEYWORD = "pg";
18
+ /**
19
+ * AJV keyword registration for consumers running in strict mode. The mapper reads the raw
20
+ * schema object and never validates through AJV, so this is purely to stop strict mode
21
+ * rejecting a schema that carries `pg` overrides.
22
+ */
23
+ export declare const pgKeyword: {
24
+ keyword: string;
25
+ valid: boolean;
26
+ };
18
27
  /** Postgres `NAMEDATALEN - 1`. Identifiers past this are silently truncated by the server. */
19
28
  export declare const PG_MAX_IDENTIFIER = 63;
20
29
  /** Property name that carries the record identity across every OwlM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AU;IAC7B,gBAAgB,UAAU;IAC1B,cAAc,UAAU;IACxB,cAAc,UAAU;IACxB,eAAe,UAAU;IACzB,cAAc,UAAU;IACxB,eAAe,UAAU;IACzB,eAAe,UAAU;IACzB,YAAY,UAAU;IACtB,gBAAgB,UAAU;IAC1B,yBAAyB,UAAU;IACnC,yBAAyB,UAAU;IACnC,sBAAsB,UAAU;IAChC,oBAAoB,UAAU;IAC9B,gBAAgB,UAAU;IAC1B,mBAAmB,UAAU;CAC9B;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,YAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA;AAEhG,uFAAuF;AACvF,oBAAY,SAAS;IACnB,IAAI,OAAO;IACX,SAAS,OAAO;IAChB,WAAW,OAAO;CACnB"}
package/build/consts.js CHANGED
@@ -15,6 +15,12 @@ export const DEFAULT_PAGE_SIZE = 100;
15
15
  export const DEF_MIGRATIONS_TABLE = '_owlmeans_migrations';
16
16
  /** JSON Schema keyword carrying the Postgres specific overrides. */
17
17
  export const PG_KEYWORD = 'pg';
18
+ /**
19
+ * AJV keyword registration for consumers running in strict mode. The mapper reads the raw
20
+ * schema object and never validates through AJV, so this is purely to stop strict mode
21
+ * rejecting a schema that carries `pg` overrides.
22
+ */
23
+ export const pgKeyword = { keyword: PG_KEYWORD, valid: true };
18
24
  /** Postgres `NAMEDATALEN - 1`. Identifiers past this are silently truncated by the server. */
19
25
  export const PG_MAX_IDENTIFIER = 63;
20
26
  /** Property name that carries the record identity across every OwlMeans resource. */
@@ -1 +1 @@
1
- {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAEpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB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AAA;IAChB,0DAAkB,CAAA;AACpB,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB"}
@@ -0,0 +1,12 @@
1
+ import type { PostgresDeclaration } from '../types.js';
2
+ /**
3
+ * The per-alias declaration store every postgres resource maker reads and extends — schema,
4
+ * indexes and migrations, keyed by resource alias.
5
+ */
6
+ export interface PgDeclarationHelper {
7
+ /** The declaration of an alias, created empty on first use. */
8
+ getDeclaration: (alias: string) => PostgresDeclaration;
9
+ /** Testing seam — drops every declaration so a spec can redeclare a resource from scratch. */
10
+ resetDeclarations: (alias?: string) => void;
11
+ }
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/declarations/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,mBAAmB,CAAA;IACtD,8FAA8F;IAC9F,iBAAiB,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/declarations/types.ts"],"names":[],"mappings":""}
@@ -1,12 +1,9 @@
1
- import type { MigrationRegistry } from '@owlmeans/resource';
2
- import type { AnySchema } from 'ajv';
3
- import type { PgIndexSpec, PostgresTx } from './types.js';
4
- export interface PostgresDeclaration {
5
- schema?: AnySchema;
6
- indexes: PgIndexSpec[];
7
- migrations: MigrationRegistry<PostgresTx>;
8
- }
1
+ import type { PgDeclarationHelper } from './declarations/types.js';
2
+ import type { PostgresDeclaration } from './types.js';
3
+ export declare const createPgDeclarationHelper: () => PgDeclarationHelper;
4
+ export declare const pgDeclarationHelper: PgDeclarationHelper;
5
+ /** @deprecated compat:factory-refactor — use `pgDeclarationHelper.getDeclaration(…)` */
9
6
  export declare const getDeclaration: (alias: string) => PostgresDeclaration;
10
- /** Testing seam — drops every declaration so a spec can redeclare a resource from scratch. */
7
+ /** @deprecated compat:factory-refactor — use `pgDeclarationHelper.resetDeclarations(…)` */
11
8
  export declare const resetDeclarations: (alias?: string) => void;
12
9
  //# sourceMappingURL=declarations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,UAAU,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAA;CAC1C;AAaD,eAAO,MAAM,cAAc,UAAW,MAAM,KAAG,mBAQ9C,CAAA;AAED,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,WAAY,MAAM,KAAG,IAMlD,CAAA"}
1
+ {"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,KAAK,EAAc,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAgBjE,eAAO,MAAM,yBAAyB,QAAO,mBAoB5C,CAAA;AAED,eAAO,MAAM,mBAAmB,qBAA8B,CAAA;AAE9D,wFAAwF;AACxF,eAAO,MAAM,cAAc,UAAW,MAAM,KAAG,mBAAgE,CAAA;AAE/G,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,WAAY,MAAM,KAAG,IAAoD,CAAA"}
@@ -7,22 +7,32 @@ import { createMigrationRegistry } from '@owlmeans/resource';
7
7
  * a no-op: every run reads and extends the same schema, indexes and migrations, so nothing a
8
8
  * caller chained onto an earlier resource object is lost. Losing a migration is silent — the
9
9
  * data transformation simply never runs — which is why the store cannot live on the object.
10
+ *
11
+ * Process-wide for the same reason: it stays outside the factory, so every helper built from it
12
+ * reads the one store.
10
13
  */
11
14
  const declarations = new Map();
12
- export const getDeclaration = (alias) => {
13
- let declaration = declarations.get(alias);
14
- if (declaration == null) {
15
- declaration = { indexes: [], migrations: createMigrationRegistry() };
16
- declarations.set(alias, declaration);
17
- }
18
- return declaration;
19
- };
20
- /** Testing seam — drops every declaration so a spec can redeclare a resource from scratch. */
21
- export const resetDeclarations = (alias) => {
22
- if (alias == null) {
23
- declarations.clear();
24
- return;
25
- }
26
- declarations.delete(alias);
15
+ export const createPgDeclarationHelper = () => {
16
+ const getDeclaration = (alias) => {
17
+ let declaration = declarations.get(alias);
18
+ if (declaration == null) {
19
+ declaration = { indexes: [], migrations: createMigrationRegistry() };
20
+ declarations.set(alias, declaration);
21
+ }
22
+ return declaration;
23
+ };
24
+ const resetDeclarations = (alias) => {
25
+ if (alias == null) {
26
+ declarations.clear();
27
+ return;
28
+ }
29
+ declarations.delete(alias);
30
+ };
31
+ return { getDeclaration, resetDeclarations };
27
32
  };
33
+ export const pgDeclarationHelper = createPgDeclarationHelper();
34
+ /** @deprecated compat:factory-refactor — use `pgDeclarationHelper.getDeclaration(…)` */
35
+ export const getDeclaration = (alias) => pgDeclarationHelper.getDeclaration(alias);
36
+ /** @deprecated compat:factory-refactor — use `pgDeclarationHelper.resetDeclarations(…)` */
37
+ export const resetDeclarations = (alias) => pgDeclarationHelper.resetDeclarations(alias);
28
38
  //# sourceMappingURL=declarations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,E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C,KAAK,EAAE,WAAW,CAAC,CAAA;QACtC,CAAC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC,CAAA;IAED,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAQ,EAAE;QACjD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,YAAY,CAAC,KAAK,EAAE,CAAA;YACpB,OAAM;QACR,CAAC;QACD,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC,CAAA;IAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,EAAE,CAAA;AAE9D,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAuB,EAAE,CAAC,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;AAE/G,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAQ,EAAE,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA"}
package/build/errors.d.ts CHANGED
@@ -49,24 +49,4 @@ export declare class PostgresBootstrapError extends PostgresError {
49
49
  static typeName: string;
50
50
  constructor(message: string);
51
51
  }
52
- /**
53
- * The framework's error marshalling preserves only type, message and stack, so the
54
- * Postgres diagnostics have to travel inside the message. Downstream tooling — notably
55
- * the viable-agent fixer, which retries on `42P01` / `42703` — classifies on exactly
56
- * this text, so the code always leads.
57
- *
58
- * `where` is deliberately never included: it can echo bound parameter values.
59
- *
60
- * Exported so a wrapper can quote the diagnostics without also quoting the translated error's
61
- * own type prefix, which would nest one error vocabulary inside another's message.
62
- */
63
- export declare const describePgError: (error: unknown) => string;
64
- /**
65
- * Translate a raw `pg` driver error into the framework's error vocabulary, so a driver
66
- * type never escapes the package. Errors that already are `ResilientError`s pass through
67
- * untouched — the reconciler and the migration runner raise their own.
68
- * A migration may supply its resolved SQL; placeholders stay intact and parameter values
69
- * are never added. The statement travels in the message so error marshalling preserves it.
70
- */
71
- export declare const pgErrorToResourceError: (error: unknown, query?: string) => Error;
72
52
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAC0B,aAAa,EAC7C,MAAM,oBAAoB,CAAA;AAI3B,qBAAa,aAAc,SAAQ,aAAa;IAC9C,OAAuB,QAAQ,SAA2C;IAE1E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAuB,QAAQ,SAAuC;IAEtE,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;IACzD,OAAuB,QAAQ,SAA8C;IAE7E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,OAAuB,QAAQ,SAA6C;IAE5E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,uBAAwB,SAAQ,uBAAuB;IAClE,OAAuB,QAAQ,SAAkD;IAEjF,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,kBAAmB,SAAQ,uBAAuB;IAC7D,OAAuB,QAAQ,SAA6C;IAE5E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,sFAAsF;AACtF,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,OAAuB,QAAQ,SAA2C;IAE1E,SAAgB,SAAS,EAAE,OAAO,CAAO;IAEzC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,oEAAoE;AACpE,qBAAa,wBAAyB,SAAQ,aAAa;IACzD,OAAuB,QAAQ,SAA8C;IAE7E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,uBAAwB,SAAQ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,SAAgB,SAAS,EAAE,OAAO,CAAO;IAEzC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,oEAAoE;AACpE,qBAAa,wBAAyB,SAAQ,aAAa;IACzD,OAAuB,QAAQ,SAA8C;IAE7E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,OAAuB,QAAQ,SAA6C;IAE5E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,6CAA6C;AAC7C,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,OAAuB,QAAQ,SAA4C;IAE3E,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF"}
package/build/errors.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ResilientError } from '@owlmeans/error';
2
- import { MisshapedRecord, RecordExists, ResourceError } from '@owlmeans/resource';
3
- import { PgErrorCode } from './consts.js';
2
+ import { ResourceError } from '@owlmeans/resource';
4
3
  export class PostgresError extends ResourceError {
5
4
  static typeName = `${ResourceError.typeName}PostgresError`;
6
5
  constructor(message = 'error') {
@@ -81,115 +80,6 @@ export class PostgresBootstrapError extends PostgresError {
81
80
  this.type = PostgresBootstrapError.typeName;
82
81
  }
83
82
  }
84
- const isDriverError = (error) => error != null && typeof error === 'object' && 'code' in error;
85
- /**
86
- * Reach the `pg` error inside whatever wrapped it.
87
- *
88
- * Drizzle raises `DrizzleQueryError` and hangs the driver error off `cause`, so a unique
89
- * violation arriving through the query builder carries no `code` at the top level. Reading
90
- * only the outer error is what makes the whole vocabulary below collapse to one opaque
91
- * class on every CRUD path — and it is exactly the paths that go through Drizzle.
92
- *
93
- * The walk is bounded because `cause` chains can be circular.
94
- */
95
- const unwrap = (error) => {
96
- let current = error;
97
- for (let depth = 0; depth < 8; depth += 1) {
98
- if (isDriverError(current)) {
99
- return current;
100
- }
101
- const cause = current?.cause;
102
- if (cause == null || cause === current) {
103
- return error;
104
- }
105
- current = cause;
106
- }
107
- return error;
108
- };
109
- /**
110
- * The framework's error marshalling preserves only type, message and stack, so the
111
- * Postgres diagnostics have to travel inside the message. Downstream tooling — notably
112
- * the viable-agent fixer, which retries on `42P01` / `42703` — classifies on exactly
113
- * this text, so the code always leads.
114
- *
115
- * `where` is deliberately never included: it can echo bound parameter values.
116
- *
117
- * Exported so a wrapper can quote the diagnostics without also quoting the translated error's
118
- * own type prefix, which would nest one error vocabulary inside another's message.
119
- */
120
- export const describePgError = (error) => {
121
- const driver = unwrap(error);
122
- if (!isDriverError(driver)) {
123
- return error instanceof Error ? error.message : `${error}`;
124
- }
125
- return describe(driver);
126
- };
127
- const describe = (error) => {
128
- const parts = [error.code ?? 'unknown'];
129
- if (error.message != null)
130
- parts.push(error.message);
131
- if (error.constraint != null)
132
- parts.push(`constraint=${error.constraint}`);
133
- if (error.table != null)
134
- parts.push(`table=${error.table}`);
135
- if (error.column != null)
136
- parts.push(`column=${error.column}`);
137
- if (error.detail != null)
138
- parts.push(`detail=${error.detail}`);
139
- if (error.hint != null)
140
- parts.push(`hint=${error.hint}`);
141
- if (error.severity != null)
142
- parts.push(`severity=${error.severity}`);
143
- return parts.join(' ');
144
- };
145
- /**
146
- * Translate a raw `pg` driver error into the framework's error vocabulary, so a driver
147
- * type never escapes the package. Errors that already are `ResilientError`s pass through
148
- * untouched — the reconciler and the migration runner raise their own.
149
- * A migration may supply its resolved SQL; placeholders stay intact and parameter values
150
- * are never added. The statement travels in the message so error marshalling preserves it.
151
- */
152
- export const pgErrorToResourceError = (error, query) => {
153
- if (error instanceof ResilientError) {
154
- return error;
155
- }
156
- const driver = unwrap(error);
157
- if (!isDriverError(driver)) {
158
- return error instanceof Error ? error : new PostgresError(`${error}`);
159
- }
160
- const message = describe(driver) + (query == null ? '' : `\nSQL: ${query}`);
161
- const produce = () => {
162
- switch (driver.code) {
163
- case PgErrorCode.UniqueViolation:
164
- return new RecordExists(message);
165
- case PgErrorCode.NotNullViolation:
166
- return new MisshapedRecord(message);
167
- case PgErrorCode.ForeignKeyViolation:
168
- return new PostgresForeignKeyError(message);
169
- case PgErrorCode.CheckViolation:
170
- return new PostgresCheckError(message);
171
- case PgErrorCode.DatatypeMismatch:
172
- case PgErrorCode.CannotCoerce:
173
- return new PostgresCastRequired(message);
174
- case PgErrorCode.SerializationFailure:
175
- case PgErrorCode.DeadlockDetected:
176
- return new PostgresDeadlockError(message);
177
- default:
178
- break;
179
- }
180
- if (driver.code != null && driver.code.startsWith('08')) {
181
- return new PostgresConnectionError(message);
182
- }
183
- if (driver.code != null && driver.code.startsWith('23')) {
184
- return new PostgresConstraintError(message);
185
- }
186
- return new PostgresError(message);
187
- };
188
- const produced = produce();
189
- /** The *original* error, wrapper and all — unwrapping is for classification, not for loss. */
190
- produced.cause = error;
191
- return produced;
192
- };
193
83
  ResilientError.registerErrorClass(PostgresError);
194
84
  ResilientError.registerErrorClass(PostgresSyncError);
195
85
  ResilientError.registerErrorClass(PostgresCastRequired);
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EACL,eAAe,EAAE,YAAY,EAAE,aAAa,EAC7C,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,OAAO,aAAc,SAAQ,aAAa;IACvC,MAAM,CAAU,QAAQ,GAAG,GAAG,aAAa,CAAC,QAAQ,eAAe,CAAA;IAE1E,YAAY,OAAO,GAAW,OAAO;QACnC,KAAK,CAAC,YAAY,OAAO,EAAE,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAA;IACpC,CAAC;CACF;AAED,oFAAoF;AACpF,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAC3C,MAAM,CAAU,QAAQ,GAAG,GAAG,aAAa,CAAC,QAAQ,WAAW,CAAA;IAEtE,YAAY,OAAe;QACz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CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAA;AAC1D,cAAc,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  export type * from './types.js';
2
2
  export * from './consts.js';
3
3
  export * from './declarations.js';
4
+ export type * from './declarations/types.js';
4
5
  export * from './errors.js';
6
+ export * from './pg-error.js';
7
+ export type * from './pg-error/types.js';
5
8
  export * from './helper.js';
6
9
  export * from './resource.js';
7
10
  export * from './utils/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,mBAAmB,yBAAyB,CAAA;AAC5C,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,mBAAmB,qBAAqB,CAAA;AACxC,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
package/build/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './consts.js';
2
2
  export * from './declarations.js';
3
3
  export * from './errors.js';
4
+ export * from './pg-error.js';
4
5
  export * from './helper.js';
5
6
  export * from './resource.js';
6
7
  export * from './utils/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAE7B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,24 @@
1
+ /** Reading and translating the errors the `pg` driver raises. */
2
+ export interface PgErrorHelper {
3
+ /**
4
+ * The framework's error marshalling preserves only type, message and stack, so the
5
+ * Postgres diagnostics have to travel inside the message. Downstream tooling — notably
6
+ * the viable-agent fixer, which retries on `42P01` / `42703` — classifies on exactly
7
+ * this text, so the code always leads.
8
+ *
9
+ * `where` is deliberately never included: it can echo bound parameter values.
10
+ *
11
+ * Exported so a wrapper can quote the diagnostics without also quoting the translated error's
12
+ * own type prefix, which would nest one error vocabulary inside another's message.
13
+ */
14
+ describePgError: (error: unknown) => string;
15
+ /**
16
+ * Translate a raw `pg` driver error into the framework's error vocabulary, so a driver
17
+ * type never escapes the package. Errors that already are `ResilientError`s pass through
18
+ * untouched — the reconciler and the migration runner raise their own.
19
+ * A migration may supply its resolved SQL; placeholders stay intact and parameter values
20
+ * are never added. The statement travels in the message so error marshalling preserves it.
21
+ */
22
+ pgErrorToResourceError: (error: unknown, query?: string) => Error;
23
+ }
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pg-error/types.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;OAUG;IACH,eAAe,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;IAC3C;;;;;;OAMG;IACH,sBAAsB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,KAAK,CAAA;CAClE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pg-error/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { PgErrorHelper } from './pg-error/types.js';
2
+ export declare const createPgErrorHelper: () => PgErrorHelper;
3
+ export declare const pgErrorHelper: PgErrorHelper;
4
+ //# sourceMappingURL=pg-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pg-error.d.ts","sourceRoot":"","sources":["../src/pg-error.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,eAAO,MAAM,mBAAmB,QAAO,aAmGtC,CAAA;AAED,eAAO,MAAM,aAAa,eAAwB,CAAA"}
@@ -0,0 +1,100 @@
1
+ import { ResilientError } from '@owlmeans/error';
2
+ import { MisshapedRecord, RecordExists } from '@owlmeans/resource';
3
+ import { PgErrorCode } from './consts.js';
4
+ import { PostgresCastRequired, PostgresCheckError, PostgresConnectionError, PostgresConstraintError, PostgresDeadlockError, PostgresError, PostgresForeignKeyError } from './errors.js';
5
+ export const createPgErrorHelper = () => {
6
+ const isDriverError = (error) => error != null && typeof error === 'object' && 'code' in error;
7
+ /**
8
+ * Reach the `pg` error inside whatever wrapped it.
9
+ *
10
+ * Drizzle raises `DrizzleQueryError` and hangs the driver error off `cause`, so a unique
11
+ * violation arriving through the query builder carries no `code` at the top level. Reading
12
+ * only the outer error is what makes the whole vocabulary below collapse to one opaque
13
+ * class on every CRUD path — and it is exactly the paths that go through Drizzle.
14
+ *
15
+ * The walk is bounded because `cause` chains can be circular.
16
+ */
17
+ const unwrap = (error) => {
18
+ let current = error;
19
+ for (let depth = 0; depth < 8; depth += 1) {
20
+ if (isDriverError(current)) {
21
+ return current;
22
+ }
23
+ const cause = current?.cause;
24
+ if (cause == null || cause === current) {
25
+ return error;
26
+ }
27
+ current = cause;
28
+ }
29
+ return error;
30
+ };
31
+ const describePgError = (error) => {
32
+ const driver = unwrap(error);
33
+ if (!isDriverError(driver)) {
34
+ return error instanceof Error ? error.message : `${error}`;
35
+ }
36
+ return describe(driver);
37
+ };
38
+ const describe = (error) => {
39
+ const parts = [error.code ?? 'unknown'];
40
+ if (error.message != null)
41
+ parts.push(error.message);
42
+ if (error.constraint != null)
43
+ parts.push(`constraint=${error.constraint}`);
44
+ if (error.table != null)
45
+ parts.push(`table=${error.table}`);
46
+ if (error.column != null)
47
+ parts.push(`column=${error.column}`);
48
+ if (error.detail != null)
49
+ parts.push(`detail=${error.detail}`);
50
+ if (error.hint != null)
51
+ parts.push(`hint=${error.hint}`);
52
+ if (error.severity != null)
53
+ parts.push(`severity=${error.severity}`);
54
+ return parts.join(' ');
55
+ };
56
+ const pgErrorToResourceError = (error, query) => {
57
+ if (error instanceof ResilientError) {
58
+ return error;
59
+ }
60
+ const driver = unwrap(error);
61
+ if (!isDriverError(driver)) {
62
+ return error instanceof Error ? error : new PostgresError(`${error}`);
63
+ }
64
+ const message = describe(driver) + (query == null ? '' : `\nSQL: ${query}`);
65
+ const produce = () => {
66
+ switch (driver.code) {
67
+ case PgErrorCode.UniqueViolation:
68
+ return new RecordExists(message);
69
+ case PgErrorCode.NotNullViolation:
70
+ return new MisshapedRecord(message);
71
+ case PgErrorCode.ForeignKeyViolation:
72
+ return new PostgresForeignKeyError(message);
73
+ case PgErrorCode.CheckViolation:
74
+ return new PostgresCheckError(message);
75
+ case PgErrorCode.DatatypeMismatch:
76
+ case PgErrorCode.CannotCoerce:
77
+ return new PostgresCastRequired(message);
78
+ case PgErrorCode.SerializationFailure:
79
+ case PgErrorCode.DeadlockDetected:
80
+ return new PostgresDeadlockError(message);
81
+ default:
82
+ break;
83
+ }
84
+ if (driver.code != null && driver.code.startsWith('08')) {
85
+ return new PostgresConnectionError(message);
86
+ }
87
+ if (driver.code != null && driver.code.startsWith('23')) {
88
+ return new PostgresConstraintError(message);
89
+ }
90
+ return new PostgresError(message);
91
+ };
92
+ const produced = produce();
93
+ /** The *original* error, wrapper and all — unwrapping is for classification, not for loss. */
94
+ produced.cause = error;
95
+ return produced;
96
+ };
97
+ return { describePgError, pgErrorToResourceError };
98
+ };
99
+ export const pgErrorHelper = createPgErrorHelper();
100
+ //# sourceMappingURL=pg-error.js.map