@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.17
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/README.md +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- package/testing/system.ts +117 -133
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Normalized PostgreSQL error categories mapped from SQLSTATE codes for common
|
|
3
|
+
* application error handling. Unmapped SQLSTATEs use `other` (inspect
|
|
4
|
+
* {@link DatabaseError.sqlState} for the exact code).
|
|
4
5
|
*
|
|
5
6
|
* @example
|
|
6
7
|
* try {
|
|
@@ -13,85 +14,78 @@
|
|
|
13
14
|
* }
|
|
14
15
|
*/
|
|
15
16
|
export declare const ErrorCode: {
|
|
16
|
-
/**
|
|
17
|
+
/** Any other SQLSTATE; see `DatabaseError.sqlState` for details. */
|
|
17
18
|
readonly Other: "other";
|
|
18
|
-
/** A `NOT NULL` constraint
|
|
19
|
+
/** A `NOT NULL` constraint was violated (SQLSTATE 23502). */
|
|
19
20
|
readonly NotNullViolation: "not_null_violation";
|
|
20
|
-
/** A foreign key constraint
|
|
21
|
+
/** A foreign key constraint was violated (SQLSTATE 23503). */
|
|
21
22
|
readonly ForeignKeyViolation: "foreign_key_violation";
|
|
22
|
-
/** A unique constraint
|
|
23
|
+
/** A unique constraint was violated (SQLSTATE 23505). */
|
|
23
24
|
readonly UniqueViolation: "unique_violation";
|
|
24
|
-
/** A check constraint
|
|
25
|
+
/** A check constraint was violated (SQLSTATE 23514). */
|
|
25
26
|
readonly CheckViolation: "check_violation";
|
|
26
|
-
/** An exclusion constraint
|
|
27
|
+
/** An exclusion constraint was violated (SQLSTATE 23P01). */
|
|
27
28
|
readonly ExcludeViolation: "exclude_violation";
|
|
28
|
-
/** A statement ran in a transaction an earlier
|
|
29
|
+
/** A statement ran in a transaction aborted by an earlier error (SQLSTATE 25P02). */
|
|
29
30
|
readonly TransactionFailed: "transaction_failed";
|
|
30
|
-
/** A deadlock was detected (40P01). */
|
|
31
|
+
/** A deadlock was detected (SQLSTATE 40P01). */
|
|
31
32
|
readonly DeadlockDetected: "deadlock_detected";
|
|
32
|
-
/** The server
|
|
33
|
+
/** The server rejected the connection due to its connection limit (SQLSTATE 53300). */
|
|
33
34
|
readonly TooManyConnections: "too_many_connections";
|
|
34
35
|
/**
|
|
35
|
-
* A serializable or repeatable
|
|
36
|
-
*
|
|
36
|
+
* A serializable or repeatable-read transaction conflicted with a concurrent
|
|
37
|
+
* transaction (SQLSTATE 40001); retrying the transaction may succeed.
|
|
37
38
|
*/
|
|
38
39
|
readonly SerializationFailure: "serialization_failure";
|
|
39
|
-
/** A write in a read-only transaction (25006), such as
|
|
40
|
+
/** A write was attempted in a read-only transaction (SQLSTATE 25006), such as via a read handle. */
|
|
40
41
|
readonly ReadOnlyTransaction: "read_only_transaction";
|
|
41
42
|
/**
|
|
42
|
-
* A lock could not be
|
|
43
|
-
* `FOR UPDATE NOWAIT` or `lock_timeout`.
|
|
43
|
+
* A lock could not be acquired without waiting (SQLSTATE 55P03), such as
|
|
44
|
+
* with `FOR UPDATE NOWAIT` or `lock_timeout`.
|
|
44
45
|
*/
|
|
45
46
|
readonly LockNotAvailable: "lock_not_available";
|
|
46
|
-
/** The statement was canceled
|
|
47
|
+
/** The statement was canceled by timeout or explicit request (SQLSTATE 57014). */
|
|
47
48
|
readonly QueryCanceled: "query_canceled";
|
|
48
|
-
/** The database could not be reached
|
|
49
|
+
/** The database could not be reached or the connection was lost (SQLSTATE class 08). */
|
|
49
50
|
readonly ConnectionFailure: "connection_failure";
|
|
50
51
|
};
|
|
51
|
-
/**
|
|
52
|
+
/** Union of {@link ErrorCode} string values (e.g. `'unique_violation'`). */
|
|
52
53
|
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
+
* Error reported by PostgreSQL or caused by a connection failure.
|
|
55
56
|
*
|
|
56
|
-
*
|
|
57
|
-
* `
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* errors instead.
|
|
57
|
+
* Connection failures (which do not originate from the server) have `sqlState`
|
|
58
|
+
* `"08001"`, `code` `"connection_failure"`, the client error message, and no
|
|
59
|
+
* optional fields. Caller mistakes (such as invalid parameter types or using a
|
|
60
|
+
* closed handle) throw standard `Error`/`TypeError` instances instead.
|
|
61
61
|
*
|
|
62
|
-
*
|
|
63
|
-
* https://www.postgresql.org/docs/current/protocol-error-fields.html)
|
|
64
|
-
* being there says nothing about the others.
|
|
62
|
+
* Optional diagnostic fields are populated only when sent by PostgreSQL (see
|
|
63
|
+
* https://www.postgresql.org/docs/current/protocol-error-fields.html).
|
|
65
64
|
*
|
|
66
|
-
*
|
|
67
|
-
* "users_pkey" (Code unique_violation: SQLSTATE 23505)`.
|
|
68
|
-
* handler that throws one fails with the API error code of its SQLSTATE:
|
|
69
|
-
* `already_exists` for a unique violation.
|
|
65
|
+
* `message` is formatted like `ERROR: duplicate key value violates unique
|
|
66
|
+
* constraint "users_pkey" (Code unique_violation: SQLSTATE 23505)`.
|
|
70
67
|
*/
|
|
71
68
|
export declare class DatabaseError extends Error {
|
|
72
69
|
readonly name: 'DatabaseError';
|
|
73
|
-
/**
|
|
70
|
+
/** Normalized error category derived from `sqlState`. */
|
|
74
71
|
readonly code: ErrorCode;
|
|
75
|
-
/**
|
|
72
|
+
/** Five-character PostgreSQL SQLSTATE code (e.g. `"23505"`). */
|
|
76
73
|
readonly sqlState: string;
|
|
77
|
-
/** `ERROR`, `FATAL
|
|
74
|
+
/** PostgreSQL severity (`ERROR`, `FATAL`, or `PANIC`). */
|
|
78
75
|
readonly severity: string;
|
|
79
|
-
/**
|
|
80
|
-
* A secondary message with more detail, such as the key a unique
|
|
81
|
-
* violation conflicted on.
|
|
82
|
-
*/
|
|
76
|
+
/** Optional secondary detail message (e.g. the conflicting key in a unique violation). */
|
|
83
77
|
readonly detail?: string;
|
|
84
|
-
/**
|
|
78
|
+
/** Optional PostgreSQL hint suggesting how to resolve the error. */
|
|
85
79
|
readonly hint?: string;
|
|
86
|
-
/**
|
|
80
|
+
/** Schema name associated with the error, if provided. */
|
|
87
81
|
readonly schemaName?: string;
|
|
88
|
-
/**
|
|
82
|
+
/** Table name associated with the error, if provided. */
|
|
89
83
|
readonly tableName?: string;
|
|
90
|
-
/**
|
|
84
|
+
/** Column name associated with the error, if provided. */
|
|
91
85
|
readonly columnName?: string;
|
|
92
|
-
/**
|
|
86
|
+
/** Data type name associated with the error, if provided. */
|
|
93
87
|
readonly dataTypeName?: string;
|
|
94
|
-
/**
|
|
88
|
+
/** Constraint or index name associated with the error, if provided. */
|
|
95
89
|
readonly constraintName?: string;
|
|
96
90
|
constructor(fields: {
|
|
97
91
|
message: string;
|
|
@@ -107,14 +101,14 @@ export declare class DatabaseError extends Error {
|
|
|
107
101
|
constraintName?: string;
|
|
108
102
|
});
|
|
109
103
|
}
|
|
110
|
-
/** Thrown by `queryRow` and `rawQueryRow`
|
|
104
|
+
/** Thrown by `queryRow` and `rawQueryRow` when a query returns more than one row. */
|
|
111
105
|
export declare class TooManyRowsError extends Error {
|
|
112
106
|
readonly name: 'TooManyRowsError';
|
|
113
107
|
constructor();
|
|
114
108
|
}
|
|
115
109
|
/**
|
|
116
|
-
* Awaits a native database call
|
|
117
|
-
*
|
|
110
|
+
* Awaits a native database call and converts encoded native errors into
|
|
111
|
+
* {@link DatabaseError}.
|
|
118
112
|
*/
|
|
119
113
|
export declare function native<T>(call: Promise<T>): Promise<T>;
|
|
120
114
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../storage/postgres/errors.ts"],"names":[],"mappings":"AAAA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;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,SAAS,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;CAkBF;AAED,qFAAqF;AACrF,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAiB,IAAI,EAAE,kBAAkB,CAAC;;CAU3C;AAQD;;;GAGG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM5D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Normalized PostgreSQL error categories mapped from SQLSTATE codes for common
|
|
3
|
+
* application error handling. Unmapped SQLSTATEs use `other` (inspect
|
|
4
|
+
* {@link DatabaseError.sqlState} for the exact code).
|
|
4
5
|
*
|
|
5
6
|
* @example
|
|
6
7
|
* try {
|
|
@@ -13,82 +14,75 @@
|
|
|
13
14
|
* }
|
|
14
15
|
*/
|
|
15
16
|
export const ErrorCode = {
|
|
16
|
-
/**
|
|
17
|
+
/** Any other SQLSTATE; see `DatabaseError.sqlState` for details. */
|
|
17
18
|
Other: 'other',
|
|
18
|
-
/** A `NOT NULL` constraint
|
|
19
|
+
/** A `NOT NULL` constraint was violated (SQLSTATE 23502). */
|
|
19
20
|
NotNullViolation: 'not_null_violation',
|
|
20
|
-
/** A foreign key constraint
|
|
21
|
+
/** A foreign key constraint was violated (SQLSTATE 23503). */
|
|
21
22
|
ForeignKeyViolation: 'foreign_key_violation',
|
|
22
|
-
/** A unique constraint
|
|
23
|
+
/** A unique constraint was violated (SQLSTATE 23505). */
|
|
23
24
|
UniqueViolation: 'unique_violation',
|
|
24
|
-
/** A check constraint
|
|
25
|
+
/** A check constraint was violated (SQLSTATE 23514). */
|
|
25
26
|
CheckViolation: 'check_violation',
|
|
26
|
-
/** An exclusion constraint
|
|
27
|
+
/** An exclusion constraint was violated (SQLSTATE 23P01). */
|
|
27
28
|
ExcludeViolation: 'exclude_violation',
|
|
28
|
-
/** A statement ran in a transaction an earlier
|
|
29
|
+
/** A statement ran in a transaction aborted by an earlier error (SQLSTATE 25P02). */
|
|
29
30
|
TransactionFailed: 'transaction_failed',
|
|
30
|
-
/** A deadlock was detected (40P01). */
|
|
31
|
+
/** A deadlock was detected (SQLSTATE 40P01). */
|
|
31
32
|
DeadlockDetected: 'deadlock_detected',
|
|
32
|
-
/** The server
|
|
33
|
+
/** The server rejected the connection due to its connection limit (SQLSTATE 53300). */
|
|
33
34
|
TooManyConnections: 'too_many_connections',
|
|
34
35
|
/**
|
|
35
|
-
* A serializable or repeatable
|
|
36
|
-
*
|
|
36
|
+
* A serializable or repeatable-read transaction conflicted with a concurrent
|
|
37
|
+
* transaction (SQLSTATE 40001); retrying the transaction may succeed.
|
|
37
38
|
*/
|
|
38
39
|
SerializationFailure: 'serialization_failure',
|
|
39
|
-
/** A write in a read-only transaction (25006), such as
|
|
40
|
+
/** A write was attempted in a read-only transaction (SQLSTATE 25006), such as via a read handle. */
|
|
40
41
|
ReadOnlyTransaction: 'read_only_transaction',
|
|
41
42
|
/**
|
|
42
|
-
* A lock could not be
|
|
43
|
-
* `FOR UPDATE NOWAIT` or `lock_timeout`.
|
|
43
|
+
* A lock could not be acquired without waiting (SQLSTATE 55P03), such as
|
|
44
|
+
* with `FOR UPDATE NOWAIT` or `lock_timeout`.
|
|
44
45
|
*/
|
|
45
46
|
LockNotAvailable: 'lock_not_available',
|
|
46
|
-
/** The statement was canceled
|
|
47
|
+
/** The statement was canceled by timeout or explicit request (SQLSTATE 57014). */
|
|
47
48
|
QueryCanceled: 'query_canceled',
|
|
48
|
-
/** The database could not be reached
|
|
49
|
+
/** The database could not be reached or the connection was lost (SQLSTATE class 08). */
|
|
49
50
|
ConnectionFailure: 'connection_failure',
|
|
50
51
|
};
|
|
51
52
|
/**
|
|
52
|
-
*
|
|
53
|
+
* Error reported by PostgreSQL or caused by a connection failure.
|
|
53
54
|
*
|
|
54
|
-
*
|
|
55
|
-
* `
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* errors instead.
|
|
55
|
+
* Connection failures (which do not originate from the server) have `sqlState`
|
|
56
|
+
* `"08001"`, `code` `"connection_failure"`, the client error message, and no
|
|
57
|
+
* optional fields. Caller mistakes (such as invalid parameter types or using a
|
|
58
|
+
* closed handle) throw standard `Error`/`TypeError` instances instead.
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
* https://www.postgresql.org/docs/current/protocol-error-fields.html)
|
|
62
|
-
* being there says nothing about the others.
|
|
60
|
+
* Optional diagnostic fields are populated only when sent by PostgreSQL (see
|
|
61
|
+
* https://www.postgresql.org/docs/current/protocol-error-fields.html).
|
|
63
62
|
*
|
|
64
|
-
*
|
|
65
|
-
* "users_pkey" (Code unique_violation: SQLSTATE 23505)`.
|
|
66
|
-
* handler that throws one fails with the API error code of its SQLSTATE:
|
|
67
|
-
* `already_exists` for a unique violation.
|
|
63
|
+
* `message` is formatted like `ERROR: duplicate key value violates unique
|
|
64
|
+
* constraint "users_pkey" (Code unique_violation: SQLSTATE 23505)`.
|
|
68
65
|
*/
|
|
69
66
|
export class DatabaseError extends Error {
|
|
70
|
-
/**
|
|
67
|
+
/** Normalized error category derived from `sqlState`. */
|
|
71
68
|
code;
|
|
72
|
-
/**
|
|
69
|
+
/** Five-character PostgreSQL SQLSTATE code (e.g. `"23505"`). */
|
|
73
70
|
sqlState;
|
|
74
|
-
/** `ERROR`, `FATAL
|
|
71
|
+
/** PostgreSQL severity (`ERROR`, `FATAL`, or `PANIC`). */
|
|
75
72
|
severity;
|
|
76
|
-
/**
|
|
77
|
-
* A secondary message with more detail, such as the key a unique
|
|
78
|
-
* violation conflicted on.
|
|
79
|
-
*/
|
|
73
|
+
/** Optional secondary detail message (e.g. the conflicting key in a unique violation). */
|
|
80
74
|
detail;
|
|
81
|
-
/**
|
|
75
|
+
/** Optional PostgreSQL hint suggesting how to resolve the error. */
|
|
82
76
|
hint;
|
|
83
|
-
/**
|
|
77
|
+
/** Schema name associated with the error, if provided. */
|
|
84
78
|
schemaName;
|
|
85
|
-
/**
|
|
79
|
+
/** Table name associated with the error, if provided. */
|
|
86
80
|
tableName;
|
|
87
|
-
/**
|
|
81
|
+
/** Column name associated with the error, if provided. */
|
|
88
82
|
columnName;
|
|
89
|
-
/**
|
|
83
|
+
/** Data type name associated with the error, if provided. */
|
|
90
84
|
dataTypeName;
|
|
91
|
-
/**
|
|
85
|
+
/** Constraint or index name associated with the error, if provided. */
|
|
92
86
|
constraintName;
|
|
93
87
|
constructor(fields) {
|
|
94
88
|
super(fields.message);
|
|
@@ -109,7 +103,7 @@ export class DatabaseError extends Error {
|
|
|
109
103
|
this.constraintName = fields.constraintName;
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
|
-
/** Thrown by `queryRow` and `rawQueryRow`
|
|
106
|
+
/** Thrown by `queryRow` and `rawQueryRow` when a query returns more than one row. */
|
|
113
107
|
export class TooManyRowsError extends Error {
|
|
114
108
|
constructor() {
|
|
115
109
|
super('query returned more than one row');
|
|
@@ -121,14 +115,13 @@ export class TooManyRowsError extends Error {
|
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
117
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* `DATABASE_ERROR_PREFIX` in `sdk/ts/src/postgres.rs`.
|
|
118
|
+
* Prefix for JSON-encoded `DatabaseError` messages from the native module.
|
|
119
|
+
* Must match `DATABASE_ERROR_PREFIX` in `sdk/ts/src/postgres.rs`.
|
|
127
120
|
*/
|
|
128
121
|
const DATABASE_ERROR_PREFIX = 'encore:postgres.DatabaseError:';
|
|
129
122
|
/**
|
|
130
|
-
* Awaits a native database call
|
|
131
|
-
*
|
|
123
|
+
* Awaits a native database call and converts encoded native errors into
|
|
124
|
+
* {@link DatabaseError}.
|
|
132
125
|
*/
|
|
133
126
|
export async function native(call) {
|
|
134
127
|
try {
|
|
@@ -138,7 +131,7 @@ export async function native(call) {
|
|
|
138
131
|
throw fromNative(err);
|
|
139
132
|
}
|
|
140
133
|
}
|
|
141
|
-
/**
|
|
134
|
+
/** Converts an encoded native error into a {@link DatabaseError}, passing other errors through. */
|
|
142
135
|
function fromNative(err) {
|
|
143
136
|
if (!(err instanceof Error) ||
|
|
144
137
|
!err.message.startsWith(DATABASE_ERROR_PREFIX)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../storage/postgres/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../storage/postgres/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,oEAAoE;IACpE,KAAK,EAAE,OAAO;IACd,6DAA6D;IAC7D,gBAAgB,EAAE,oBAAoB;IACtC,8DAA8D;IAC9D,mBAAmB,EAAE,uBAAuB;IAC5C,yDAAyD;IACzD,eAAe,EAAE,kBAAkB;IACnC,wDAAwD;IACxD,cAAc,EAAE,iBAAiB;IACjC,6DAA6D;IAC7D,gBAAgB,EAAE,mBAAmB;IACrC,qFAAqF;IACrF,iBAAiB,EAAE,oBAAoB;IACvC,gDAAgD;IAChD,gBAAgB,EAAE,mBAAmB;IACrC,uFAAuF;IACvF,kBAAkB,EAAE,sBAAsB;IAC1C;;;OAGG;IACH,oBAAoB,EAAE,uBAAuB;IAC7C,oGAAoG;IACpG,mBAAmB,EAAE,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AAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;QACrC,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS;QACnC,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;QACrC,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,SAAS;QACzC,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,SAAS;KAC9C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* (
|
|
2
|
+
* Represents a PostgreSQL `interval` with its three independent components —
|
|
3
|
+
* `months`, `days`, and `microseconds` — matching PostgreSQL's internal model
|
|
4
|
+
* (months do not have a fixed number of days, and days do not have a fixed
|
|
5
|
+
* number of microseconds across daylight-saving transitions).
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
7
|
+
* `interval` columns are returned as ISO 8601 strings (e.g.
|
|
8
|
+
* `'P1Y2M3DT4H5M6.5S'` or `'P1M-2D'`), which can be parsed with
|
|
9
|
+
* {@link Interval.parse}. Query parameters for `interval` columns accept an
|
|
10
|
+
* `Interval`, a `Temporal.Duration`, or any string PostgreSQL parses (e.g.
|
|
11
|
+
* `'1 day 02:00:00'`, `'P1DT2H'`, `'90 minutes'`).
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* const row = await db.queryRow`SELECT ${new Interval(1, 0, 0)} + now() AS due`;
|
|
@@ -19,24 +20,23 @@ export declare class Interval {
|
|
|
19
20
|
readonly days: number;
|
|
20
21
|
readonly microseconds: number;
|
|
21
22
|
/**
|
|
22
|
-
* @param months - Whole months
|
|
23
|
-
* @param days - Whole days
|
|
24
|
-
* @param microseconds - Whole microseconds
|
|
23
|
+
* @param months - Whole months (signed 32-bit integer).
|
|
24
|
+
* @param days - Whole days (signed 32-bit integer).
|
|
25
|
+
* @param microseconds - Whole microseconds (safe integer).
|
|
25
26
|
*/
|
|
26
27
|
constructor(months: number, days: number, microseconds: number);
|
|
27
28
|
/**
|
|
28
|
-
* Parses an interval in ISO 8601
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* number. To have Postgres parse other forms, pass the string as a query
|
|
29
|
+
* Parses an interval string in ISO 8601 format (`P1Y2M3DT4H5M6.5S`, `P2W`)
|
|
30
|
+
* or PostgreSQL's default format (`1 year 2 mons 3 days 04:05:06.5`,
|
|
31
|
+
* `-1 days +02:00:00`). All components except seconds must be whole numbers;
|
|
32
|
+
* infinite intervals (`infinity`, `-infinity`) throw. To parse other
|
|
33
|
+
* PostgreSQL interval syntaxes, pass the string directly as a query
|
|
34
34
|
* parameter instead.
|
|
35
35
|
*
|
|
36
|
-
* @throws {TypeError}
|
|
36
|
+
* @throws {TypeError} If `s` is not in a supported format.
|
|
37
37
|
*/
|
|
38
38
|
static parse(s: string): Interval;
|
|
39
|
-
/**
|
|
39
|
+
/** Formats the interval as an ISO 8601 duration string (e.g. `P1Y2M3DT4H5M6.5S`, `PT0S`). */
|
|
40
40
|
toString(): string;
|
|
41
41
|
toJSON(): string;
|
|
42
42
|
private get __encore_interval();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../../storage/postgres/interval.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../../storage/postgres/interval.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,QAAQ;IAOjB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM;IAR/B;;;;OAIG;gBAEQ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM;IAO/B;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;IAUjC,6FAA6F;IAC7F,QAAQ,IAAI,MAAM;IAqBlB,MAAM,IAAI,MAAM;IAIhB,OAAO,KAAK,iBAAiB,GAE5B;CACF"}
|
|
@@ -3,15 +3,16 @@ const MICROS_PER_MINUTE = 60 * MICROS_PER_SECOND;
|
|
|
3
3
|
const MICROS_PER_HOUR = 60 * MICROS_PER_MINUTE;
|
|
4
4
|
const INT32_MAX = 2 ** 31 - 1;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* (
|
|
6
|
+
* Represents a PostgreSQL `interval` with its three independent components —
|
|
7
|
+
* `months`, `days`, and `microseconds` — matching PostgreSQL's internal model
|
|
8
|
+
* (months do not have a fixed number of days, and days do not have a fixed
|
|
9
|
+
* number of microseconds across daylight-saving transitions).
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
11
|
+
* `interval` columns are returned as ISO 8601 strings (e.g.
|
|
12
|
+
* `'P1Y2M3DT4H5M6.5S'` or `'P1M-2D'`), which can be parsed with
|
|
13
|
+
* {@link Interval.parse}. Query parameters for `interval` columns accept an
|
|
14
|
+
* `Interval`, a `Temporal.Duration`, or any string PostgreSQL parses (e.g.
|
|
15
|
+
* `'1 day 02:00:00'`, `'P1DT2H'`, `'90 minutes'`).
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* const row = await db.queryRow`SELECT ${new Interval(1, 0, 0)} + now() AS due`;
|
|
@@ -23,9 +24,9 @@ export class Interval {
|
|
|
23
24
|
days;
|
|
24
25
|
microseconds;
|
|
25
26
|
/**
|
|
26
|
-
* @param months - Whole months
|
|
27
|
-
* @param days - Whole days
|
|
28
|
-
* @param microseconds - Whole microseconds
|
|
27
|
+
* @param months - Whole months (signed 32-bit integer).
|
|
28
|
+
* @param days - Whole days (signed 32-bit integer).
|
|
29
|
+
* @param microseconds - Whole microseconds (safe integer).
|
|
29
30
|
*/
|
|
30
31
|
constructor(months, days, microseconds) {
|
|
31
32
|
this.months = months;
|
|
@@ -36,15 +37,14 @@ export class Interval {
|
|
|
36
37
|
check('microseconds', microseconds, Number.MAX_SAFE_INTEGER);
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
|
-
* Parses an interval in ISO 8601
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* number. To have Postgres parse other forms, pass the string as a query
|
|
40
|
+
* Parses an interval string in ISO 8601 format (`P1Y2M3DT4H5M6.5S`, `P2W`)
|
|
41
|
+
* or PostgreSQL's default format (`1 year 2 mons 3 days 04:05:06.5`,
|
|
42
|
+
* `-1 days +02:00:00`). All components except seconds must be whole numbers;
|
|
43
|
+
* infinite intervals (`infinity`, `-infinity`) throw. To parse other
|
|
44
|
+
* PostgreSQL interval syntaxes, pass the string directly as a query
|
|
45
45
|
* parameter instead.
|
|
46
46
|
*
|
|
47
|
-
* @throws {TypeError}
|
|
47
|
+
* @throws {TypeError} If `s` is not in a supported format.
|
|
48
48
|
*/
|
|
49
49
|
static parse(s) {
|
|
50
50
|
const parsed = parseISO(s) ?? parsePostgres(s);
|
|
@@ -53,7 +53,7 @@ export class Interval {
|
|
|
53
53
|
}
|
|
54
54
|
return new Interval(parsed.months, parsed.days, parsed.microseconds);
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/** Formats the interval as an ISO 8601 duration string (e.g. `P1Y2M3DT4H5M6.5S`, `PT0S`). */
|
|
57
57
|
toString() {
|
|
58
58
|
const years = Math.trunc(this.months / 12);
|
|
59
59
|
const months = this.months % 12;
|
|
@@ -84,7 +84,7 @@ export class Interval {
|
|
|
84
84
|
}
|
|
85
85
|
function check(name, value, max) {
|
|
86
86
|
if (!Number.isInteger(value) || Math.abs(value) > max) {
|
|
87
|
-
throw new RangeError(`
|
|
87
|
+
throw new RangeError(`Interval ${name} must be an integer with magnitude at most ${max}, got ${value}`);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
function part(n, unit) {
|
|
@@ -143,7 +143,7 @@ function parsePostgres(s) {
|
|
|
143
143
|
}
|
|
144
144
|
return any ? parts : null;
|
|
145
145
|
}
|
|
146
|
-
/**
|
|
146
|
+
/** Converts a decimal seconds string (up to 6 decimal places) into microseconds. */
|
|
147
147
|
function seconds(s) {
|
|
148
148
|
const negative = s.startsWith('-');
|
|
149
149
|
const [whole, fraction = ''] = s.replace(/^[+-]/, '').split('.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interval.js","sourceRoot":"","sources":["../../../storage/postgres/interval.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,OAAS,CAAC;AACpC,MAAM,iBAAiB,GAAG,EAAE,GAAG,iBAAiB,CAAC;AACjD,MAAM,eAAe,GAAG,EAAE,GAAG,iBAAiB,CAAC;AAC/C,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAE9B
|
|
1
|
+
{"version":3,"file":"interval.js","sourceRoot":"","sources":["../../../storage/postgres/interval.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,OAAS,CAAC;AACpC,MAAM,iBAAiB,GAAG,EAAE,GAAG,iBAAiB,CAAC;AACjD,MAAM,eAAe,GAAG,EAAE,GAAG,iBAAiB,CAAC;AAC/C,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,QAAQ;IAOR;IACA;IACA;IARX;;;;OAIG;IACH,YACW,MAAc,EACd,IAAY,EACZ,YAAoB;QAFpB,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAQ;QAE7B,KAAK,CAAC,QAAQ,EAAE,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