@distilled.cloud/turso 1.0.0-rc.20 → 1.0.0-rc.21

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,13 +1,11 @@
1
- import type * as API from "@distilled.cloud/core/api";
2
- import type { ConfigError, InvalidInput } from "@distilled.cloud/core/errors";
3
- import { makeRestProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
4
- import type { SdkError } from "@distilled.cloud/core/sdk-error";
1
+ import type { ErrorOf } from "@distilled.cloud/core/protocol";
2
+ import { restProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
5
3
  /**
6
4
  * TursoProtocol -- hand-written.
7
5
  *
8
6
  * Turso's platform API is plain bearer-REST JSON (`Authorization: Bearer
9
7
  * <apiKey>`, no response envelope), so the protocol is a direct
10
- * `makeRestProtocol` instantiation from `core/protocol-rest`:
8
+ * `restProtocol` instantiation from `core/protocol-rest`:
11
9
  *
12
10
  * request: credentials resolved per request from the Credentials service,
13
11
  * bearer auth header, base URL from `creds.apiBaseUrl`
@@ -20,33 +18,27 @@ import type { SdkError } from "@distilled.cloud/core/sdk-error";
20
18
  */
21
19
  import * as Effect from "effect/Effect";
22
20
  import type * as HttpClient from "effect/http/HttpClient";
23
- import type * as HttpClientError from "effect/http/HttpClientError";
24
- import type * as Layer from "effect/Layer";
25
21
  import * as Redacted from "effect/Redacted";
26
- import { Credentials, type Config } from "./credentials.ts";
27
- import { UnknownTursoError, type DefaultErrors, TursoParseError } from "./errors.ts";
22
+ import { Credentials } from "./credentials.ts";
23
+ import { UnknownTursoError, TursoParseError, type TursoServiceError } from "./errors.ts";
28
24
 
29
25
  /**
30
- * Error channel shared by every generated Turso operation. Generated service
31
- * files annotate operations with `API.OperationMethod<I, O, TursoOpError,
32
- * TursoOpContext>` explicitly so the compiler never infers these back out of
33
- * the schema generics.
26
+ * What every generated Turso operation fails with besides its own errors: the
27
+ * service's errors, the protocol's, and what resolving the credentials fails
28
+ * with. Generated service files annotate operations with
29
+ * `API.OperationMethod<I, O, TursoOpError, TursoOpContext>` explicitly so the
30
+ * compiler never infers these back out of the schema generics.
34
31
  */
35
- export type TursoOpError =
36
- | DefaultErrors
37
- | ConfigError
38
- | HttpClientError.HttpClientError
39
- | InvalidInput
40
- | SdkError;
32
+ export type TursoOpError = TursoServiceError | ErrorOf<typeof TursoProtocol>;
41
33
 
42
34
  /** Context (requirements) shared by every generated Turso operation. */
43
35
  export type TursoOpContext = Credentials | HttpClient.HttpClient;
44
36
 
45
- export const TursoProtocol: Layer.Layer<API.Protocol> = /*@__PURE__*/ makeRestProtocol<Config>({
37
+ export const TursoProtocol = /*@__PURE__*/ restProtocol({
46
38
  // The Credentials service holds an effect -- resolving it here (per
47
39
  // request) picks up rotations. Its error channel is erased at the protocol
48
40
  // boundary; TursoOpError reintroduces it for callers.
49
- credentials: /*@__PURE__*/ Effect.flatMap(Credentials, (resolve) => resolve),
41
+ credentials: /*@__PURE__*/ Effect.flatten(Credentials),
50
42
  baseUrl: (creds) => creds.apiBaseUrl,
51
43
  headers: (creds) => ({
52
44
  Authorization: `Bearer ${Redacted.value(creds.apiKey)}`,