@distilled.cloud/xata 1.0.0-rc.13 → 1.0.0-rc.14

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/src/protocol.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type * as API from "@distilled.cloud/core/api";
2
+ import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
3
+ import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
1
4
  /**
2
5
  * XataProtocol — hand-written.
3
6
  *
@@ -15,13 +18,10 @@
15
18
  * HTTP-status classes, then {@link UnknownXataError}.
16
19
  */
17
20
  import * as Effect from "effect/Effect";
18
- import type * as Layer from "effect/Layer";
19
- import * as Redacted from "effect/Redacted";
20
21
  import type * as HttpClient from "effect/http/HttpClient";
21
22
  import type * as HttpClientError from "effect/http/HttpClientError";
22
- import type * as API from "@distilled.cloud/core/api";
23
- import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
24
- import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
23
+ import type * as Layer from "effect/Layer";
24
+ import * as Redacted from "effect/Redacted";
25
25
  import { Credentials, type Config } from "./credentials.ts";
26
26
  import { UnknownXataError, XataParseError } from "./errors.ts";
27
27
 
@@ -41,31 +41,24 @@ export type XataOpError =
41
41
  /** Context (requirements) shared by every generated Xata operation. */
42
42
  export type XataOpContext = Credentials | HttpClient.HttpClient;
43
43
 
44
- export const XataProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>(
45
- {
46
- // The Credentials service holds an effect — resolving it here (per
47
- // request, on the calling fiber) picks up context-provided credentials.
48
- credentials: Effect.gen(function* () {
49
- const resolve = yield* Credentials;
50
- return yield* resolve;
51
- }),
52
- baseUrl: (creds) => creds.apiBaseUrl,
53
- headers: (creds) => ({
54
- Authorization: `Bearer ${Redacted.value(creds.apiKey)}`,
44
+ export const XataProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>({
45
+ // The Credentials service holds an effect — resolving it here (per
46
+ // request, on the calling fiber) picks up context-provided credentials.
47
+ credentials: Effect.gen(function* () {
48
+ const resolve = yield* Credentials;
49
+ return yield* resolve;
50
+ }),
51
+ baseUrl: (creds) => creds.apiBaseUrl,
52
+ headers: (creds) => ({
53
+ Authorization: `Bearer ${Redacted.value(creds.apiKey)}`,
54
+ }),
55
+ // Xata's error body is `{ message: string, ... }` — the factory's
56
+ // default lenient envelope covers it.
57
+ unknownError: ({ code, message, body }) =>
58
+ new UnknownXataError({
59
+ code: typeof code === "string" ? code : code !== undefined ? String(code) : undefined,
60
+ message,
61
+ body,
55
62
  }),
56
- // Xata's error body is `{ message: string, ... }` — the factory's
57
- // default lenient envelope covers it.
58
- unknownError: ({ code, message, body }) =>
59
- new UnknownXataError({
60
- code:
61
- typeof code === "string"
62
- ? code
63
- : code !== undefined
64
- ? String(code)
65
- : undefined,
66
- message,
67
- body,
68
- }),
69
- parseError: ({ body, cause }) => new XataParseError({ body, cause }),
70
- },
71
- );
63
+ parseError: ({ body, cause }) => new XataParseError({ body, cause }),
64
+ });
package/src/retry.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type Policy, throttlingFactory, transientFactory } from "@distilled.cloud/core/retry";
1
2
  /**
2
3
  * Xata retry configuration.
3
4
  *
@@ -16,11 +17,6 @@
16
17
  import * as Context from "effect/Context";
17
18
  import * as Effect from "effect/Effect";
18
19
  import * as Layer from "effect/Layer";
19
- import {
20
- type Policy,
21
- throttlingFactory,
22
- transientFactory,
23
- } from "@distilled.cloud/core/retry";
24
20
 
25
21
  export {
26
22
  type Options,
@@ -43,9 +39,7 @@ export const policy = (optionsOrFactory: Policy) =>
43
39
  Effect.provide(Layer.succeed(Retry, optionsOrFactory));
44
40
 
45
41
  /** Disables all automatic retries. */
46
- export const none = Effect.provide(
47
- Layer.succeed(Retry, { while: () => false }),
48
- );
42
+ export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
49
43
 
50
44
  /** Apply the throttling retry policy (retries throttling errors indefinitely). */
51
45
  export const throttling = policy(throttlingFactory);