@effect/sql-pg 4.0.0-rc.112 → 4.0.0-rc.113

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 (60) hide show
  1. package/AGENTS.md +24 -9
  2. package/CLAUDE.md +24 -9
  3. package/ai-docs/package.json +2 -2
  4. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +18 -5
  5. package/ai-docs/src/01_effect/01_basics/index.md +5 -3
  6. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +1 -1
  7. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +2 -2
  8. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +2 -2
  9. package/ai-docs/src/03_stream/30_encoding.ts +5 -7
  10. package/ai-docs/src/08_observability/10_logging.ts +1 -1
  11. package/ai-docs/src/70_cli/10_basics.ts +7 -7
  12. package/ai-docs/src/71_ai/10_language-model.ts +2 -2
  13. package/ai-docs/src/71_ai/20_tools.ts +1 -1
  14. package/ai-docs/src/71_ai/30_chat.ts +1 -1
  15. package/dist/PgAuth.d.ts +24 -0
  16. package/dist/PgAuth.d.ts.map +1 -1
  17. package/dist/PgAuth.js +29 -2
  18. package/dist/PgAuth.js.map +1 -1
  19. package/dist/PgClient.d.ts +49 -82
  20. package/dist/PgClient.d.ts.map +1 -1
  21. package/dist/PgClient.js +58 -510
  22. package/dist/PgClient.js.map +1 -1
  23. package/dist/PgConnection.d.ts +177 -0
  24. package/dist/PgConnection.d.ts.map +1 -0
  25. package/dist/PgConnection.js +1786 -0
  26. package/dist/PgConnection.js.map +1 -0
  27. package/dist/PgPool.d.ts +107 -0
  28. package/dist/PgPool.d.ts.map +1 -0
  29. package/dist/PgPool.js +124 -0
  30. package/dist/PgPool.js.map +1 -0
  31. package/dist/PgProtocol.d.ts +63 -30
  32. package/dist/PgProtocol.d.ts.map +1 -1
  33. package/dist/PgProtocol.js +64 -22
  34. package/dist/PgProtocol.js.map +1 -1
  35. package/dist/PgTypes.d.ts +85 -17
  36. package/dist/PgTypes.d.ts.map +1 -1
  37. package/dist/PgTypes.js +166 -169
  38. package/dist/PgTypes.js.map +1 -1
  39. package/dist/index.d.ts +8 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +8 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/internal/connection.d.ts +2 -0
  44. package/dist/internal/connection.d.ts.map +1 -0
  45. package/dist/internal/connection.js +5 -0
  46. package/dist/internal/connection.js.map +1 -0
  47. package/dist/internal/sqlError.d.ts +10 -0
  48. package/dist/internal/sqlError.d.ts.map +1 -0
  49. package/dist/internal/sqlError.js +57 -0
  50. package/dist/internal/sqlError.js.map +1 -0
  51. package/package.json +6 -14
  52. package/src/PgAuth.ts +33 -2
  53. package/src/PgClient.ts +138 -681
  54. package/src/PgConnection.ts +2294 -0
  55. package/src/PgPool.ts +231 -0
  56. package/src/PgProtocol.ts +93 -50
  57. package/src/PgTypes.ts +254 -186
  58. package/src/index.ts +10 -0
  59. package/src/internal/connection.ts +26 -0
  60. package/src/internal/sqlError.ts +75 -0
@@ -0,0 +1,26 @@
1
+ import type * as Effect from "effect/Effect"
2
+ import type * as Scope from "effect/Scope"
3
+ import type { SqlError } from "effect/unstable/sql/SqlError"
4
+
5
+ /** @internal */
6
+ export const internalsKey = "~@effect/sql-pg/PgConnection/internals" as const
7
+
8
+ /** @internal */
9
+ export interface ConnectionInternals {
10
+ /** The pool item identity: the unpinned base connection. */
11
+ readonly base: object
12
+ readonly deadError: () => SqlError | undefined
13
+ /** Fired once when the connection dies outside its own scope release. */
14
+ readonly fatalHooks: Set<() => void>
15
+ /**
16
+ * Installed by a multiplexed pool so that pinning the session also takes it
17
+ * out of shared circulation for as long as the pin lasts. Every route to an
18
+ * exclusive session goes through `pin`, including `stream` and `listen`, so
19
+ * this is the one place that covers them all.
20
+ */
21
+ reserve?: Effect.Effect<void, never, Scope.Scope> | undefined
22
+ }
23
+
24
+ /** @internal */
25
+ export const connectionInternals = (connection: object): ConnectionInternals =>
26
+ (connection as Record<typeof internalsKey, ConnectionInternals>)[internalsKey]
@@ -0,0 +1,75 @@
1
+ import {
2
+ AuthenticationError,
3
+ AuthorizationError,
4
+ ConnectionError,
5
+ ConstraintError,
6
+ DeadlockError,
7
+ LockTimeoutError,
8
+ SerializationError,
9
+ SqlError,
10
+ type SqlErrorReason,
11
+ SqlSyntaxError,
12
+ StatementTimeoutError,
13
+ UniqueViolation,
14
+ UnknownError
15
+ } from "effect/unstable/sql/SqlError"
16
+
17
+ interface ErrorProps {
18
+ readonly cause: unknown
19
+ readonly message: string
20
+ readonly operation: string
21
+ }
22
+
23
+ const channelNameEncoder = new TextEncoder()
24
+
25
+ export const validateChannelName = (channel: string, operation: string): SqlError | undefined => {
26
+ if (channelNameEncoder.encode(channel).byteLength <= 63) return undefined
27
+ const message = "PostgreSQL channel names must not exceed 63 UTF-8 bytes"
28
+ return new SqlError({ reason: new UnknownError({ cause: new Error(message), message, operation }) })
29
+ }
30
+
31
+ const normalizeConstraint = (constraint: unknown): string => {
32
+ if (typeof constraint !== "string") return "unknown"
33
+ const normalized = constraint.trim()
34
+ return normalized.length === 0 ? "unknown" : normalized
35
+ }
36
+
37
+ export const classifySqlState = (
38
+ code: string | undefined,
39
+ constraint: unknown,
40
+ props: ErrorProps
41
+ ): SqlErrorReason => {
42
+ if (code !== undefined) {
43
+ if (code.startsWith("08")) {
44
+ return new ConnectionError(props)
45
+ }
46
+ if (code.startsWith("28")) {
47
+ return new AuthenticationError(props)
48
+ }
49
+ if (code === "42501") {
50
+ return new AuthorizationError(props)
51
+ }
52
+ if (code.startsWith("42")) {
53
+ return new SqlSyntaxError(props)
54
+ }
55
+ if (code === "23505") {
56
+ return new UniqueViolation({ ...props, constraint: normalizeConstraint(constraint) })
57
+ }
58
+ if (code.startsWith("23")) {
59
+ return new ConstraintError(props)
60
+ }
61
+ if (code === "40P01") {
62
+ return new DeadlockError(props)
63
+ }
64
+ if (code === "40001") {
65
+ return new SerializationError(props)
66
+ }
67
+ if (code === "55P03") {
68
+ return new LockTimeoutError(props)
69
+ }
70
+ if (code === "57014") {
71
+ return new StatementTimeoutError(props)
72
+ }
73
+ }
74
+ return new UnknownError(props)
75
+ }