@distilled.cloud/xata 1.0.0-rc.12 → 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/README.md +34 -0
- package/lib/credentials.d.ts +2 -2
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +3 -3
- package/lib/credentials.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/protocol.d.ts +5 -5
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +4 -7
- package/lib/protocol.js.map +1 -1
- package/lib/retry.d.ts +1 -1
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -1
- package/lib/retry.js.map +1 -1
- package/lib/services/xata.d.ts +381 -33
- package/lib/services/xata.d.ts.map +1 -1
- package/lib/services/xata.js +451 -356
- package/lib/services/xata.js.map +1 -1
- package/package.json +13 -11
- package/src/credentials.ts +7 -8
- package/src/errors.ts +10 -16
- package/src/index.ts +1 -5
- package/src/protocol.ts +28 -33
- package/src/retry.ts +2 -8
- package/src/services/xata.ts +1135 -708
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,15 +18,12 @@
|
|
|
15
18
|
* HTTP-status classes, then {@link UnknownXataError}.
|
|
16
19
|
*/
|
|
17
20
|
import * as Effect from "effect/Effect";
|
|
21
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
22
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
18
23
|
import type * as Layer from "effect/Layer";
|
|
19
24
|
import * as Redacted from "effect/Redacted";
|
|
20
|
-
import type * as HttpClient from "effect/unstable/http/HttpClient";
|
|
21
|
-
import type * as HttpClientError from "effect/unstable/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";
|
|
25
25
|
import { Credentials, type Config } from "./credentials.ts";
|
|
26
|
-
import { UnknownXataError } from "./errors.ts";
|
|
26
|
+
import { UnknownXataError, XataParseError } from "./errors.ts";
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Error channel shared by every generated Xata operation. Generated service
|
|
@@ -35,35 +35,30 @@ export type XataOpError =
|
|
|
35
35
|
| InstanceType<(typeof API_ERRORS)[number]>
|
|
36
36
|
| UnknownXataError
|
|
37
37
|
| ConfigError
|
|
38
|
-
| HttpClientError.HttpClientError
|
|
38
|
+
| HttpClientError.HttpClientError
|
|
39
|
+
| XataParseError;
|
|
39
40
|
|
|
40
41
|
/** Context (requirements) shared by every generated Xata operation. */
|
|
41
42
|
export type XataOpContext = Credentials | HttpClient.HttpClient;
|
|
42
43
|
|
|
43
|
-
export const XataProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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,
|
|
54
62
|
}),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
unknownError: ({ code, message, body }) =>
|
|
58
|
-
new UnknownXataError({
|
|
59
|
-
code:
|
|
60
|
-
typeof code === "string"
|
|
61
|
-
? code
|
|
62
|
-
: code !== undefined
|
|
63
|
-
? String(code)
|
|
64
|
-
: undefined,
|
|
65
|
-
message,
|
|
66
|
-
body,
|
|
67
|
-
}),
|
|
68
|
-
},
|
|
69
|
-
);
|
|
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);
|