@effect/sql-pg 4.0.0-rc.111 → 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.
- package/AGENTS.md +24 -9
- package/CLAUDE.md +24 -9
- package/ai-docs/package.json +2 -2
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +18 -5
- package/ai-docs/src/01_effect/01_basics/index.md +5 -3
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +1 -1
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +2 -2
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +2 -2
- package/ai-docs/src/03_stream/30_encoding.ts +5 -7
- package/ai-docs/src/08_observability/10_logging.ts +1 -1
- package/ai-docs/src/70_cli/10_basics.ts +7 -7
- package/ai-docs/src/71_ai/10_language-model.ts +2 -2
- package/ai-docs/src/71_ai/20_tools.ts +1 -1
- package/ai-docs/src/71_ai/30_chat.ts +1 -1
- package/dist/PgAuth.d.ts +93 -0
- package/dist/PgAuth.d.ts.map +1 -0
- package/dist/PgAuth.js +229 -0
- package/dist/PgAuth.js.map +1 -0
- package/dist/PgClient.d.ts +49 -82
- package/dist/PgClient.d.ts.map +1 -1
- package/dist/PgClient.js +58 -510
- package/dist/PgClient.js.map +1 -1
- package/dist/PgConnection.d.ts +177 -0
- package/dist/PgConnection.d.ts.map +1 -0
- package/dist/PgConnection.js +1786 -0
- package/dist/PgConnection.js.map +1 -0
- package/dist/PgPool.d.ts +107 -0
- package/dist/PgPool.d.ts.map +1 -0
- package/dist/PgPool.js +124 -0
- package/dist/PgPool.js.map +1 -0
- package/dist/PgProtocol.d.ts +783 -0
- package/dist/PgProtocol.d.ts.map +1 -0
- package/dist/PgProtocol.js +1202 -0
- package/dist/PgProtocol.js.map +1 -0
- package/dist/PgTypes.d.ts +429 -0
- package/dist/PgTypes.d.ts.map +1 -0
- package/dist/PgTypes.js +1511 -0
- package/dist/PgTypes.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/connection.d.ts +2 -0
- package/dist/internal/connection.d.ts.map +1 -0
- package/dist/internal/connection.js +5 -0
- package/dist/internal/connection.js.map +1 -0
- package/dist/internal/sqlError.d.ts +10 -0
- package/dist/internal/sqlError.d.ts.map +1 -0
- package/dist/internal/sqlError.js +57 -0
- package/dist/internal/sqlError.js.map +1 -0
- package/package.json +8 -12
- package/src/PgAuth.ts +318 -0
- package/src/PgClient.ts +138 -681
- package/src/PgConnection.ts +2294 -0
- package/src/PgPool.ts +231 -0
- package/src/PgProtocol.ts +1863 -0
- package/src/PgTypes.ts +1998 -0
- package/src/index.ts +25 -0
- package/src/internal/connection.ts +26 -0
- package/src/internal/sqlError.ts +75 -0
package/src/index.ts
CHANGED
|
@@ -4,12 +4,37 @@
|
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @since 4.0.0
|
|
9
|
+
*/
|
|
10
|
+
export * as PgAuth from "./PgAuth.ts"
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* @since 4.0.0
|
|
9
14
|
*/
|
|
10
15
|
export * as PgClient from "./PgClient.ts"
|
|
11
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
export * as PgConnection from "./PgConnection.ts"
|
|
21
|
+
|
|
12
22
|
/**
|
|
13
23
|
* @since 4.0.0
|
|
14
24
|
*/
|
|
15
25
|
export * as PgMigrator from "./PgMigrator.ts"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @since 4.0.0
|
|
29
|
+
*/
|
|
30
|
+
export * as PgPool from "./PgPool.ts"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @since 4.0.0
|
|
34
|
+
*/
|
|
35
|
+
export * as PgProtocol from "./PgProtocol.ts"
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @since 4.0.0
|
|
39
|
+
*/
|
|
40
|
+
export * as PgTypes from "./PgTypes.ts"
|
|
@@ -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
|
+
}
|