@distilled.cloud/prisma-postgres 0.16.1 → 0.16.3
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/lib/client.d.ts.map +1 -1
- package/lib/client.js +12 -3
- package/lib/client.js.map +1 -1
- package/lib/retry.d.ts +24 -13
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +24 -12
- package/lib/retry.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +15 -2
- package/src/retry.ts +32 -12
package/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAWxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAyDzD;;GAEG;AACH,eAAO,MAAM,GAAG;;;CASd,CAAC"}
|
package/lib/client.js
CHANGED
|
@@ -8,6 +8,8 @@ import * as Effect from "effect/Effect";
|
|
|
8
8
|
import * as Redacted from "effect/Redacted";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
10
|
import { makeAPI } from "@distilled.cloud/core/client";
|
|
11
|
+
import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
|
|
12
|
+
import { Retry } from "./retry.js";
|
|
11
13
|
import { HTTP_STATUS_MAP, UnknownPrismaPostgresError, PrismaPostgresParseError, } from "./errors.js";
|
|
12
14
|
// Re-export for backwards compatibility
|
|
13
15
|
export { UnknownPrismaPostgresError } from "./errors.js";
|
|
@@ -23,12 +25,15 @@ const ApiErrorResponse = Schema.Struct({
|
|
|
23
25
|
/**
|
|
24
26
|
* Match a Prisma Postgres API error response to the appropriate error class based on HTTP status.
|
|
25
27
|
*/
|
|
26
|
-
const matchError = (status, errorBody) => {
|
|
28
|
+
const matchError = (status, errorBody, _errors, headers) => {
|
|
27
29
|
try {
|
|
28
30
|
const parsed = Schema.decodeUnknownSync(ApiErrorResponse)(errorBody);
|
|
29
31
|
const ErrorClass = HTTP_STATUS_MAP[status];
|
|
30
32
|
if (ErrorClass) {
|
|
31
|
-
return Effect.fail(new ErrorClass({
|
|
33
|
+
return Effect.fail(new ErrorClass({
|
|
34
|
+
message: parsed.error.message ?? "",
|
|
35
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
36
|
+
}));
|
|
32
37
|
}
|
|
33
38
|
return Effect.fail(new UnknownPrismaPostgresError({
|
|
34
39
|
code: parsed.error.code,
|
|
@@ -42,7 +47,10 @@ const matchError = (status, errorBody) => {
|
|
|
42
47
|
const ErrorClass = HTTP_STATUS_MAP[status];
|
|
43
48
|
if (ErrorClass) {
|
|
44
49
|
const message = typeof errorBody === "string" ? errorBody : String(errorBody ?? "");
|
|
45
|
-
return Effect.fail(new ErrorClass({
|
|
50
|
+
return Effect.fail(new ErrorClass({
|
|
51
|
+
message,
|
|
52
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
53
|
+
}));
|
|
46
54
|
}
|
|
47
55
|
return Effect.fail(new UnknownPrismaPostgresError({ body: errorBody }));
|
|
48
56
|
}
|
|
@@ -58,5 +66,6 @@ export const API = makeAPI({
|
|
|
58
66
|
}),
|
|
59
67
|
matchError,
|
|
60
68
|
ParseError: PrismaPostgresParseError,
|
|
69
|
+
retry: Retry,
|
|
61
70
|
});
|
|
62
71
|
//# sourceMappingURL=client.js.map
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,K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CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;YACtE,OAAO,MAAM,CAAC,IAAI,CAChB,IAAI,UAAU,CAAC;gBACb,OAAO;gBACP,UAAU,EAAE,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;aACtD,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAC;IACzB,WAAW,EAAE,WAAkB;IAC/B,UAAU,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IAC5C,cAAc,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC;QAC/B,aAAa,EAAE,UAAU,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;KAC1D,CAAC;IACF,UAAU;IACV,UAAU,EAAE,wBAA+B;IAC3C,KAAK,EAAE,KAAY;CACpB,CAAC,CAAC"}
|
package/lib/retry.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PrismaPostgres retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/prisma-postgres/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* PrismaPostgres API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as PrismaPostgres from "@distilled.cloud/prisma-postgres";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(PrismaPostgres.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(PrismaPostgres.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
17
|
import * as Context from "effect/Context";
|
|
6
|
-
|
|
7
|
-
import type
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import { type Policy } from "@distilled.cloud/core/retry";
|
|
20
|
+
export { type Options, type Factory, type Policy, makeDefault, jittered, capped, throttlingOptions, transientOptions, throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
|
|
8
21
|
declare const Retry_base: Context.ServiceClass<Retry, "PrismaPostgresRetry", Policy>;
|
|
9
|
-
/**
|
|
10
|
-
* Context tag for configuring retry behavior of Prisma Postgres API calls.
|
|
11
|
-
*/
|
|
22
|
+
/** Context tag for configuring retry behavior of PrismaPostgres API calls. */
|
|
12
23
|
export declare class Retry extends Retry_base {
|
|
13
24
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Provides a custom retry policy to all Prisma Postgres API calls.
|
|
16
|
-
*/
|
|
25
|
+
/** Provides a custom retry policy to every PrismaPostgres API call below it. */
|
|
17
26
|
export declare const policy: (optionsOrFactory: Policy) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
18
|
-
/**
|
|
19
|
-
* Disables all automatic retries.
|
|
20
|
-
*/
|
|
27
|
+
/** Disables all automatic retries. */
|
|
21
28
|
export declare const none: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
29
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
30
|
+
export declare const throttling: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
31
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
32
|
+
export declare const transient: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
22
33
|
//# sourceMappingURL=retry.d.ts.map
|
package/lib/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,KAAK,MAAM,EAGZ,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;;AAErC,8EAA8E;AAC9E,qBAAa,KAAM,SAAQ,UAE1B;CAAG;AAEJ,gFAAgF;AAChF,eAAO,MAAM,MAAM,qBAAsB,MAAM,sFACS,CAAC;AAEzD,sCAAsC;AACtC,eAAO,MAAM,IAAI,mFAEhB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,UAAU,mFAA4B,CAAC;AAEpD,oFAAoF;AACpF,eAAO,MAAM,SAAS,mFAA2B,CAAC"}
|
package/lib/retry.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PrismaPostgres retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/prisma-postgres/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* PrismaPostgres API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as PrismaPostgres from "@distilled.cloud/prisma-postgres";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(PrismaPostgres.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(PrismaPostgres.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
4
18
|
import * as Effect from "effect/Effect";
|
|
5
19
|
import * as Layer from "effect/Layer";
|
|
6
|
-
import
|
|
7
|
-
export { makeDefault, jittered, capped, throttlingOptions, transientOptions, } from "@distilled.cloud/core/retry";
|
|
8
|
-
/**
|
|
9
|
-
* Context tag for configuring retry behavior of Prisma Postgres API calls.
|
|
10
|
-
*/
|
|
20
|
+
import { throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
|
|
21
|
+
export { makeDefault, jittered, capped, throttlingOptions, transientOptions, throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
|
|
22
|
+
/** Context tag for configuring retry behavior of PrismaPostgres API calls. */
|
|
11
23
|
export class Retry extends Context.Service()("PrismaPostgresRetry") {
|
|
12
24
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Provides a custom retry policy to all Prisma Postgres API calls.
|
|
15
|
-
*/
|
|
25
|
+
/** Provides a custom retry policy to every PrismaPostgres API call below it. */
|
|
16
26
|
export const policy = (optionsOrFactory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
17
|
-
/**
|
|
18
|
-
* Disables all automatic retries.
|
|
19
|
-
*/
|
|
27
|
+
/** Disables all automatic retries. */
|
|
20
28
|
export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
|
|
29
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
30
|
+
export const throttling = policy(throttlingFactory);
|
|
31
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
32
|
+
export const transient = policy(transientFactory);
|
|
21
33
|
//# sourceMappingURL=retry.js.map
|
package/lib/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAIL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,8EAA8E;AAC9E,MAAM,OAAO,KAAM,SAAQ,OAAO,CAAC,OAAO,EAAiB,CACzD,qBAAqB,CACtB;CAAG;AAEJ,gFAAgF;AAChF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,gBAAwB,EAAE,EAAE,CACjD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEzD,sCAAsC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAChC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAC7C,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEpD,oFAAoF;AACpF,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/prisma-postgres",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"specs:update": "git -C specs/distilled-spec-prisma-postgres fetch && git -C specs/distilled-spec-prisma-postgres checkout main && git -C specs/distilled-spec-prisma-postgres pull"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@distilled.cloud/core": "0.16.
|
|
77
|
+
"@distilled.cloud/core": "0.16.3",
|
|
78
78
|
"effect": "4.0.0-beta.58"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
package/src/client.ts
CHANGED
|
@@ -8,6 +8,8 @@ import * as Effect from "effect/Effect";
|
|
|
8
8
|
import * as Redacted from "effect/Redacted";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
10
|
import { makeAPI } from "@distilled.cloud/core/client";
|
|
11
|
+
import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
|
|
12
|
+
import { Retry } from "./retry.ts";
|
|
11
13
|
import {
|
|
12
14
|
HTTP_STATUS_MAP,
|
|
13
15
|
UnknownPrismaPostgresError,
|
|
@@ -33,13 +35,18 @@ const ApiErrorResponse = Schema.Struct({
|
|
|
33
35
|
const matchError = (
|
|
34
36
|
status: number,
|
|
35
37
|
errorBody: unknown,
|
|
38
|
+
_errors?: readonly unknown[],
|
|
39
|
+
headers?: Record<string, string | undefined>,
|
|
36
40
|
): Effect.Effect<never, unknown> => {
|
|
37
41
|
try {
|
|
38
42
|
const parsed = Schema.decodeUnknownSync(ApiErrorResponse)(errorBody);
|
|
39
43
|
const ErrorClass = (HTTP_STATUS_MAP as any)[status];
|
|
40
44
|
if (ErrorClass) {
|
|
41
45
|
return Effect.fail(
|
|
42
|
-
new ErrorClass({
|
|
46
|
+
new ErrorClass({
|
|
47
|
+
message: parsed.error.message ?? "",
|
|
48
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
49
|
+
}),
|
|
43
50
|
);
|
|
44
51
|
}
|
|
45
52
|
return Effect.fail(
|
|
@@ -56,7 +63,12 @@ const matchError = (
|
|
|
56
63
|
if (ErrorClass) {
|
|
57
64
|
const message =
|
|
58
65
|
typeof errorBody === "string" ? errorBody : String(errorBody ?? "");
|
|
59
|
-
return Effect.fail(
|
|
66
|
+
return Effect.fail(
|
|
67
|
+
new ErrorClass({
|
|
68
|
+
message,
|
|
69
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
60
72
|
}
|
|
61
73
|
return Effect.fail(new UnknownPrismaPostgresError({ body: errorBody }));
|
|
62
74
|
}
|
|
@@ -73,4 +85,5 @@ export const API = makeAPI({
|
|
|
73
85
|
}),
|
|
74
86
|
matchError,
|
|
75
87
|
ParseError: PrismaPostgresParseError as any,
|
|
88
|
+
retry: Retry as any,
|
|
76
89
|
});
|
package/src/retry.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PrismaPostgres retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/prisma-postgres/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* PrismaPostgres API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as PrismaPostgres from "@distilled.cloud/prisma-postgres";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(PrismaPostgres.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(PrismaPostgres.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
4
18
|
import * as Effect from "effect/Effect";
|
|
5
19
|
import * as Layer from "effect/Layer";
|
|
6
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
type Policy,
|
|
22
|
+
throttlingFactory,
|
|
23
|
+
transientFactory,
|
|
24
|
+
} from "@distilled.cloud/core/retry";
|
|
25
|
+
|
|
7
26
|
export {
|
|
8
27
|
type Options,
|
|
9
28
|
type Factory,
|
|
@@ -13,25 +32,26 @@ export {
|
|
|
13
32
|
capped,
|
|
14
33
|
throttlingOptions,
|
|
15
34
|
transientOptions,
|
|
35
|
+
throttlingFactory,
|
|
36
|
+
transientFactory,
|
|
16
37
|
} from "@distilled.cloud/core/retry";
|
|
17
|
-
import type { Policy } from "@distilled.cloud/core/retry";
|
|
18
38
|
|
|
19
|
-
/**
|
|
20
|
-
* Context tag for configuring retry behavior of Prisma Postgres API calls.
|
|
21
|
-
*/
|
|
39
|
+
/** Context tag for configuring retry behavior of PrismaPostgres API calls. */
|
|
22
40
|
export class Retry extends Context.Service<Retry, Policy>()(
|
|
23
41
|
"PrismaPostgresRetry",
|
|
24
42
|
) {}
|
|
25
43
|
|
|
26
|
-
/**
|
|
27
|
-
* Provides a custom retry policy to all Prisma Postgres API calls.
|
|
28
|
-
*/
|
|
44
|
+
/** Provides a custom retry policy to every PrismaPostgres API call below it. */
|
|
29
45
|
export const policy = (optionsOrFactory: Policy) =>
|
|
30
46
|
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
31
47
|
|
|
32
|
-
/**
|
|
33
|
-
* Disables all automatic retries.
|
|
34
|
-
*/
|
|
48
|
+
/** Disables all automatic retries. */
|
|
35
49
|
export const none = Effect.provide(
|
|
36
50
|
Layer.succeed(Retry, { while: () => false }),
|
|
37
51
|
);
|
|
52
|
+
|
|
53
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
54
|
+
export const throttling = policy(throttlingFactory);
|
|
55
|
+
|
|
56
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
57
|
+
export const transient = policy(transientFactory);
|