@distilled.cloud/starburst-galaxy 0.0.0 → 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/LICENSE +201 -0
- package/README.md +110 -4
- package/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +84 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +83 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +42 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/pagination.d.ts +10 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +1 -0
- package/lib/protocol.d.ts +29 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +32 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +1 -0
- package/lib/services/catalog.d.ts +2791 -0
- package/lib/services/catalog.d.ts.map +1 -0
- package/lib/services/catalog.js +101 -0
- package/lib/services/catalog.js.map +1 -0
- package/lib/services/cluster.d.ts +248 -0
- package/lib/services/cluster.d.ts.map +1 -0
- package/lib/services/cluster.js +2 -0
- package/lib/services/cluster.js.map +1 -0
- package/lib/services/column_mask.d.ts +162 -0
- package/lib/services/column_mask.d.ts.map +1 -0
- package/lib/services/column_mask.js +2 -0
- package/lib/services/column_mask.js.map +1 -0
- package/lib/services/cross_account_iam_role.d.ts +133 -0
- package/lib/services/cross_account_iam_role.d.ts.map +1 -0
- package/lib/services/cross_account_iam_role.js +2 -0
- package/lib/services/cross_account_iam_role.js.map +1 -0
- package/lib/services/data_domain.d.ts +223 -0
- package/lib/services/data_domain.d.ts.map +1 -0
- package/lib/services/data_domain.js +2 -0
- package/lib/services/data_domain.js.map +1 -0
- package/lib/services/data_product.d.ts +290 -0
- package/lib/services/data_product.d.ts.map +1 -0
- package/lib/services/data_product.js +2 -0
- package/lib/services/data_product.js.map +1 -0
- package/lib/services/data_product_usage_example.d.ts +158 -0
- package/lib/services/data_product_usage_example.d.ts.map +1 -0
- package/lib/services/data_product_usage_example.js +2 -0
- package/lib/services/data_product_usage_example.js.map +1 -0
- package/lib/services/data_quality.d.ts +344 -0
- package/lib/services/data_quality.d.ts.map +1 -0
- package/lib/services/data_quality.js +2 -0
- package/lib/services/data_quality.js.map +1 -0
- package/lib/services/data_quality_metrics.d.ts +282 -0
- package/lib/services/data_quality_metrics.d.ts.map +1 -0
- package/lib/services/data_quality_metrics.js +2 -0
- package/lib/services/data_quality_metrics.js.map +1 -0
- package/lib/services/data_quality_schedule.d.ts +220 -0
- package/lib/services/data_quality_schedule.d.ts.map +1 -0
- package/lib/services/data_quality_schedule.js +2 -0
- package/lib/services/data_quality_schedule.js.map +1 -0
- package/lib/services/discovery.d.ts +439 -0
- package/lib/services/discovery.d.ts.map +1 -0
- package/lib/services/discovery.js +36 -0
- package/lib/services/discovery.js.map +1 -0
- package/lib/services/file_ingest_source.d.ts +205 -0
- package/lib/services/file_ingest_source.d.ts.map +1 -0
- package/lib/services/file_ingest_source.js +2 -0
- package/lib/services/file_ingest_source.js.map +1 -0
- package/lib/services/group.d.ts +140 -0
- package/lib/services/group.d.ts.map +1 -0
- package/lib/services/group.js +2 -0
- package/lib/services/group.js.map +1 -0
- package/lib/services/index.d.ts +26 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +25 -0
- package/lib/services/kafka_ingest_source.d.ts +236 -0
- package/lib/services/kafka_ingest_source.d.ts.map +1 -0
- package/lib/services/kafka_ingest_source.js +2 -0
- package/lib/services/kafka_ingest_source.js.map +1 -0
- package/lib/services/live_table.d.ts +851 -0
- package/lib/services/live_table.d.ts.map +1 -0
- package/lib/services/live_table.js +20 -0
- package/lib/services/live_table.js.map +1 -0
- package/lib/services/policy.d.ts +213 -0
- package/lib/services/policy.d.ts.map +1 -0
- package/lib/services/policy.js +2 -0
- package/lib/services/policy.js.map +1 -0
- package/lib/services/privatelink.d.ts +95 -0
- package/lib/services/privatelink.d.ts.map +1 -0
- package/lib/services/privatelink.js +2 -0
- package/lib/services/privatelink.js.map +1 -0
- package/lib/services/privilege.d.ts +167 -0
- package/lib/services/privilege.d.ts.map +1 -0
- package/lib/services/privilege.js +2 -0
- package/lib/services/privilege.js.map +1 -0
- package/lib/services/role.d.ts +222 -0
- package/lib/services/role.d.ts.map +1 -0
- package/lib/services/role.js +2 -0
- package/lib/services/role.js.map +1 -0
- package/lib/services/row_filter.d.ts +155 -0
- package/lib/services/row_filter.d.ts.map +1 -0
- package/lib/services/row_filter.js +2 -0
- package/lib/services/row_filter.js.map +1 -0
- package/lib/services/schema_discovery.d.ts +236 -0
- package/lib/services/schema_discovery.d.ts.map +1 -0
- package/lib/services/schema_discovery.js +2 -0
- package/lib/services/schema_discovery.js.map +1 -0
- package/lib/services/service_account.d.ts +206 -0
- package/lib/services/service_account.d.ts.map +1 -0
- package/lib/services/service_account.js +2 -0
- package/lib/services/service_account.js.map +1 -0
- package/lib/services/sql_jobs.d.ts +264 -0
- package/lib/services/sql_jobs.d.ts.map +1 -0
- package/lib/services/sql_jobs.js +2 -0
- package/lib/services/sql_jobs.js.map +1 -0
- package/lib/services/tag.d.ts +287 -0
- package/lib/services/tag.d.ts.map +1 -0
- package/lib/services/tag.js +2 -0
- package/lib/services/tag.js.map +1 -0
- package/lib/services/user.d.ts +175 -0
- package/lib/services/user.d.ts.map +1 -0
- package/lib/services/user.js +2 -0
- package/lib/services/user.js.map +1 -0
- package/lib/services.lazy/catalog.js +4 -0
- package/lib/services.lazy/cluster.js +1 -0
- package/lib/services.lazy/column_mask.js +1 -0
- package/lib/services.lazy/cross_account_iam_role.js +1 -0
- package/lib/services.lazy/data_domain.js +1 -0
- package/lib/services.lazy/data_product.js +1 -0
- package/lib/services.lazy/data_product_usage_example.js +1 -0
- package/lib/services.lazy/data_quality.js +1 -0
- package/lib/services.lazy/data_quality_metrics.js +1 -0
- package/lib/services.lazy/data_quality_schedule.js +1 -0
- package/lib/services.lazy/discovery.js +4 -0
- package/lib/services.lazy/file_ingest_source.js +1 -0
- package/lib/services.lazy/group.js +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/kafka_ingest_source.js +1 -0
- package/lib/services.lazy/live_table.js +4 -0
- package/lib/services.lazy/policy.js +1 -0
- package/lib/services.lazy/privatelink.js +1 -0
- package/lib/services.lazy/privilege.js +1 -0
- package/lib/services.lazy/role.js +1 -0
- package/lib/services.lazy/row_filter.js +1 -0
- package/lib/services.lazy/schema_discovery.js +1 -0
- package/lib/services.lazy/service_account.js +1 -0
- package/lib/services.lazy/sql_jobs.js +1 -0
- package/lib/services.lazy/tag.js +1 -0
- package/lib/services.lazy/user.js +1 -0
- package/lib/traits.d.ts +11 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +1 -0
- package/package.json +82 -2
- package/src/credentials.ts +205 -0
- package/src/errors.ts +102 -0
- package/src/index.ts +45 -0
- package/src/pagination.ts +9 -0
- package/src/protocol.ts +94 -0
- package/src/retry.ts +50 -0
- package/src/services/catalog.ts +6636 -0
- package/src/services/cluster.ts +492 -0
- package/src/services/column_mask.ts +388 -0
- package/src/services/cross_account_iam_role.ts +328 -0
- package/src/services/data_domain.ts +509 -0
- package/src/services/data_product.ts +641 -0
- package/src/services/data_product_usage_example.ts +380 -0
- package/src/services/data_quality.ts +771 -0
- package/src/services/data_quality_metrics.ts +580 -0
- package/src/services/data_quality_schedule.ts +454 -0
- package/src/services/discovery.ts +1257 -0
- package/src/services/file_ingest_source.ts +480 -0
- package/src/services/group.ts +282 -0
- package/src/services/index.ts +26 -0
- package/src/services/kafka_ingest_source.ts +545 -0
- package/src/services/live_table.ts +1537 -0
- package/src/services/policy.ts +526 -0
- package/src/services/privatelink.ts +209 -0
- package/src/services/privilege.ts +423 -0
- package/src/services/role.ts +501 -0
- package/src/services/row_filter.ts +365 -0
- package/src/services/schema_discovery.ts +516 -0
- package/src/services/service_account.ts +525 -0
- package/src/services/sql_jobs.ts +621 -0
- package/src/services/tag.ts +785 -0
- package/src/services/user.ts +375 -0
- package/src/traits.ts +44 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starburst Galaxy error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the common HTTP errors from core and adds the one status Galaxy
|
|
5
|
+
* documents that core's shared map has no entry for (412), plus the
|
|
6
|
+
* unknown-error and parse-error wrappers.
|
|
7
|
+
*
|
|
8
|
+
* Galaxy failures carry `{ message, ... }` bodies. Operations that declare a
|
|
9
|
+
* status get the generated per-status class for it, which keeps `message`
|
|
10
|
+
* and the whole `body` (where `BadRequest`'s `fields` and
|
|
11
|
+
* `FailedPrecondition`'s `detail` are read). Every other failure is
|
|
12
|
+
* dispatched on its status by `StarburstGalaxyProtocol` to the classes
|
|
13
|
+
* here, which carry `message`. Both share their `_tag`s, so `catchTag`
|
|
14
|
+
* works against either.
|
|
15
|
+
*/
|
|
16
|
+
export {
|
|
17
|
+
BadGateway,
|
|
18
|
+
BadRequest,
|
|
19
|
+
Conflict,
|
|
20
|
+
ConfigError,
|
|
21
|
+
Forbidden,
|
|
22
|
+
GatewayTimeout,
|
|
23
|
+
InternalServerError,
|
|
24
|
+
Locked,
|
|
25
|
+
NotFound,
|
|
26
|
+
ServiceUnavailable,
|
|
27
|
+
TooManyRequests,
|
|
28
|
+
Unauthorized,
|
|
29
|
+
UnprocessableEntity,
|
|
30
|
+
HTTP_STATUS_MAP,
|
|
31
|
+
DEFAULT_ERRORS,
|
|
32
|
+
API_ERRORS,
|
|
33
|
+
} from "@distilled.cloud/core/errors";
|
|
34
|
+
export type { DefaultErrors } from "@distilled.cloud/core/errors";
|
|
35
|
+
|
|
36
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
37
|
+
import { API_ERRORS, UnknownErrorFields } from "@distilled.cloud/core/errors";
|
|
38
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
39
|
+
import { applyErrorMatchers } from "@distilled.cloud/core/trait";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* HTTP 412 -- `FailedPrecondition`: the request cannot run in the
|
|
43
|
+
* resource's current state (for example deleting a data domain that still
|
|
44
|
+
* holds data products, or creating a cluster the account cannot host yet).
|
|
45
|
+
* Retrying unchanged keeps failing until that state changes, so it is not
|
|
46
|
+
* retryable. Like the generated per-operation `PreconditionFailed` (core
|
|
47
|
+
* derives categories from the status, and 412 has none), it carries no
|
|
48
|
+
* category, so handling by `_tag` or by category does not depend on
|
|
49
|
+
* whether an operation declares 412.
|
|
50
|
+
*/
|
|
51
|
+
export class PreconditionFailed
|
|
52
|
+
extends /*@__PURE__*/ applyErrorMatchers(
|
|
53
|
+
/*@__PURE__*/ Schema.TaggedError<PreconditionFailed>()("PreconditionFailed", {
|
|
54
|
+
message: Schema.String,
|
|
55
|
+
}),
|
|
56
|
+
[{ status: 412 }],
|
|
57
|
+
) {}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Unknown Starburst Galaxy error -- returned when a failed response's HTTP
|
|
61
|
+
* status has no mapped error class. Carries that `status`, Galaxy's
|
|
62
|
+
* `message` and the whole `body`.
|
|
63
|
+
*/
|
|
64
|
+
export class UnknownStarburstGalaxyError
|
|
65
|
+
extends /*@__PURE__*/ Schema.TaggedError<UnknownStarburstGalaxyError>()(
|
|
66
|
+
"UnknownStarburstGalaxyError",
|
|
67
|
+
UnknownErrorFields,
|
|
68
|
+
) {}
|
|
69
|
+
|
|
70
|
+
/** A 2xx body that does not match the output schema (strict response validation). */
|
|
71
|
+
export class StarburstGalaxyParseError
|
|
72
|
+
extends /*@__PURE__*/ Schema.TaggedError<StarburstGalaxyParseError>()(
|
|
73
|
+
"StarburstGalaxyParseError",
|
|
74
|
+
{
|
|
75
|
+
body: Schema.Unknown,
|
|
76
|
+
cause: Schema.Unknown,
|
|
77
|
+
},
|
|
78
|
+
).pipe(Category.withParseError) {}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The OAuth token request the credentials make failed: Galaxy could not
|
|
82
|
+
* be reached, refused the client credentials, answered with something that
|
|
83
|
+
* is not a token, or did not answer in time.
|
|
84
|
+
* `status` is the token endpoint's HTTP status, when it answered. It is a
|
|
85
|
+
* failure of a request at run time, so it is not a `ConfigError`.
|
|
86
|
+
*/
|
|
87
|
+
export class TokenRequestFailed
|
|
88
|
+
extends /*@__PURE__*/ Schema.TaggedError<TokenRequestFailed>()("TokenRequestFailed", {
|
|
89
|
+
message: Schema.String,
|
|
90
|
+
status: /*@__PURE__*/ Schema.optional(Schema.Number),
|
|
91
|
+
}).pipe(Category.withAuthError) {}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The errors declared on the Galaxy service: any operation can return them,
|
|
95
|
+
* and every generated operation lists them as its `serviceErrors`. Each of
|
|
96
|
+
* core's status classes, and {@link PreconditionFailed} for 412, matched by
|
|
97
|
+
* its status like an operation's own errors.
|
|
98
|
+
*/
|
|
99
|
+
export const StarburstGalaxyServiceErrors = [...API_ERRORS, PreconditionFailed] as const;
|
|
100
|
+
export type StarburstGalaxyServiceError = InstanceType<
|
|
101
|
+
(typeof StarburstGalaxyServiceErrors)[number]
|
|
102
|
+
>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/starburst-galaxy -- Starburst Galaxy SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy models
|
|
5
|
+
* that `scripts/convert.ts` converts from Galaxy's public OpenAPI documents,
|
|
6
|
+
* mirrored at `specs/spec-mirror-starburst-galaxy/specs/`. Everything else in
|
|
7
|
+
* this folder is hand-written.
|
|
8
|
+
*
|
|
9
|
+
* One module per Galaxy API service: `cluster`, `catalog`, `role`,
|
|
10
|
+
* `privilege`, `serviceAccount`, `dataProduct`, `tag`, ....
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { Effect, Layer } from "effect";
|
|
15
|
+
* import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
16
|
+
* import * as StarburstGalaxy from "@distilled.cloud/starburst-galaxy";
|
|
17
|
+
* import * as Cluster from "@distilled.cloud/starburst-galaxy/cluster";
|
|
18
|
+
*
|
|
19
|
+
* const program = Effect.gen(function* () {
|
|
20
|
+
* const { result } = yield* Cluster.listClusters({});
|
|
21
|
+
* const [first] = result;
|
|
22
|
+
* if (first === undefined) return undefined;
|
|
23
|
+
*
|
|
24
|
+
* const cluster = yield* Cluster.getCluster({ clusterId: first.clusterId });
|
|
25
|
+
* yield* Effect.log(`${cluster.name}: ${cluster.clusterState} at ${cluster.trinoUri}`);
|
|
26
|
+
* return cluster;
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const Live = Layer.mergeAll(
|
|
30
|
+
* StarburstGalaxy.CredentialsFromEnv,
|
|
31
|
+
* ).pipe(Layer.provideMerge(FetchHttpClient.layer));
|
|
32
|
+
*
|
|
33
|
+
* program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export * from "./credentials.ts";
|
|
37
|
+
export * from "./errors.ts";
|
|
38
|
+
export * as T from "./traits.ts";
|
|
39
|
+
export {
|
|
40
|
+
StarburstGalaxyProtocol,
|
|
41
|
+
type StarburstGalaxyOpError,
|
|
42
|
+
type StarburstGalaxyOpContext,
|
|
43
|
+
} from "./protocol.ts";
|
|
44
|
+
export { paginateToken } from "./pagination.ts";
|
|
45
|
+
export * as Retry from "./retry.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starburst Galaxy pagination -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* List operations page by token: `pageToken` in, `nextPageToken` out (`""`
|
|
5
|
+
* on the last page), items under `result`. `scripts/convert.ts` stamps
|
|
6
|
+
* `smithy.api#paginated` on them; generated operations pass core's
|
|
7
|
+
* {@link paginateToken} strategy to `API.makePaginated`.
|
|
8
|
+
*/
|
|
9
|
+
export { paginateToken } from "@distilled.cloud/core/pagination";
|
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { TooManyRequests } from "@distilled.cloud/core/errors";
|
|
2
|
+
import type { ErrorOf } from "@distilled.cloud/core/protocol";
|
|
3
|
+
import {
|
|
4
|
+
restProtocol,
|
|
5
|
+
type RestErrorInfo,
|
|
6
|
+
unknownErrorProps,
|
|
7
|
+
} from "@distilled.cloud/core/protocol-rest";
|
|
8
|
+
import { parseRetryAfter } from "@distilled.cloud/core/retry-after";
|
|
9
|
+
/**
|
|
10
|
+
* StarburstGalaxyProtocol -- hand-written.
|
|
11
|
+
*
|
|
12
|
+
* Galaxy speaks bearer-authenticated JSON REST with no success envelope, so
|
|
13
|
+
* the whole protocol is one `restProtocol` call from
|
|
14
|
+
* `core/protocol-rest`:
|
|
15
|
+
*
|
|
16
|
+
* request: credentials -> `Authorization: Bearer <access token>` + the
|
|
17
|
+
* account's base URL (`https://<account-domain>`), resolved
|
|
18
|
+
* from the calling fiber on every request (picking up the
|
|
19
|
+
* token refresh in credentials.ts)
|
|
20
|
+
*
|
|
21
|
+
* response: 2xx JSON is the payload (sensitive members delivered as
|
|
22
|
+
* `Redacted`); a 429 is read by {@link rateLimited}; other
|
|
23
|
+
* non-2xx `{ message, ... }` bodies map to the operation's typed
|
|
24
|
+
* error classes by status, then the shared HTTP-status classes
|
|
25
|
+
* plus 412 -> {@link PreconditionFailed}, then
|
|
26
|
+
* {@link UnknownStarburstGalaxyError}.
|
|
27
|
+
*/
|
|
28
|
+
import * as Duration from "effect/Duration";
|
|
29
|
+
import * as Effect from "effect/Effect";
|
|
30
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
31
|
+
import * as Redacted from "effect/Redacted";
|
|
32
|
+
import { Credentials } from "./credentials.ts";
|
|
33
|
+
import {
|
|
34
|
+
StarburstGalaxyParseError,
|
|
35
|
+
UnknownStarburstGalaxyError,
|
|
36
|
+
type StarburstGalaxyServiceError,
|
|
37
|
+
} from "./errors.ts";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* What every generated Galaxy operation fails with besides its own errors: the
|
|
41
|
+
* service's errors, the protocol's, and what resolving the credentials fails
|
|
42
|
+
* with. Generated service files annotate operations with
|
|
43
|
+
* `API.OperationMethod<I, O, StarburstGalaxyOpError,
|
|
44
|
+
* StarburstGalaxyOpContext>` explicitly so the compiler never infers these
|
|
45
|
+
* back out of the schema generics.
|
|
46
|
+
*/
|
|
47
|
+
export type StarburstGalaxyOpError =
|
|
48
|
+
| StarburstGalaxyServiceError
|
|
49
|
+
| ErrorOf<typeof StarburstGalaxyProtocol>;
|
|
50
|
+
|
|
51
|
+
/** Context (requirements) shared by every generated Galaxy operation. */
|
|
52
|
+
export type StarburstGalaxyOpContext = Credentials | HttpClient.HttpClient;
|
|
53
|
+
|
|
54
|
+
/** The wait Galaxy's rate limiter states in its plain-text 429 body. */
|
|
55
|
+
const TRY_AGAIN_IN = /try again in (\d+) seconds?/i;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Galaxy's rate limiter answers `429 Too Many Requests` with
|
|
59
|
+
* `Retry-After: 0` and the real wait in its text body ("Rate limit
|
|
60
|
+
* exceeded. Please try again in 10 seconds."). Core honors a zero hint as
|
|
61
|
+
* "retry now", which fails again at once, so the body's wait wins; a
|
|
62
|
+
* positive `Retry-After` is used when the body names none, and otherwise the
|
|
63
|
+
* retry policy's own backoff applies. Core has no hook for a body-stated
|
|
64
|
+
* wait, so this is Galaxy's `classifyError`.
|
|
65
|
+
*/
|
|
66
|
+
export const rateLimited = (info: RestErrorInfo): TooManyRequests | undefined => {
|
|
67
|
+
if (info.status !== 429) return undefined;
|
|
68
|
+
const stated = TRY_AGAIN_IN.exec(info.message)?.[1];
|
|
69
|
+
const wait =
|
|
70
|
+
stated === undefined ? parseRetryAfter(info.headers) : Duration.seconds(Number(stated));
|
|
71
|
+
return new TooManyRequests({
|
|
72
|
+
message: info.message,
|
|
73
|
+
retryAfter: wait !== undefined && Duration.toMillis(wait) > 0 ? wait : undefined,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const StarburstGalaxyProtocol = /*@__PURE__*/ restProtocol({
|
|
78
|
+
// The Credentials service holds an effect -- resolving it here (per
|
|
79
|
+
// request, on the calling fiber) picks up a refreshed access token.
|
|
80
|
+
credentials: /*@__PURE__*/ Effect.flatten(Credentials),
|
|
81
|
+
baseUrl: (creds) => creds.apiBaseUrl,
|
|
82
|
+
headers: (creds) => ({
|
|
83
|
+
Authorization: `Bearer ${Redacted.value(creds.accessToken)}`,
|
|
84
|
+
}),
|
|
85
|
+
// A status becomes the class the service declares for it
|
|
86
|
+
// (`StarburstGalaxyServiceErrors`: core's classes plus 412,
|
|
87
|
+
// `FailedPrecondition`, which Galaxy documents on cluster creation, schema
|
|
88
|
+
// discovery, data domain deletion and data quality operations).
|
|
89
|
+
classifyError: rateLimited,
|
|
90
|
+
// Galaxy's error body is `{ message, ... }` -- the factory's default
|
|
91
|
+
// lenient `{ code?, message? }` envelope reads it.
|
|
92
|
+
unknownError: (info) => new UnknownStarburstGalaxyError(unknownErrorProps(info)),
|
|
93
|
+
parseError: ({ body, cause }) => new StarburstGalaxyParseError({ body, cause }),
|
|
94
|
+
});
|
package/src/retry.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Policy, throttlingFactory, transientFactory } from "@distilled.cloud/core/retry";
|
|
2
|
+
/**
|
|
3
|
+
* Starburst Galaxy retry configuration.
|
|
4
|
+
*
|
|
5
|
+
* Defines the per-SDK `Retry` Context.Service tag that generated operations
|
|
6
|
+
* wire into `API.make`. Callers can install a blanket retry policy at the
|
|
7
|
+
* layer level and have every Starburst Galaxy API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as StarburstGalaxy from "@distilled.cloud/starburst-galaxy";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(StarburstGalaxy.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(StarburstGalaxy.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Layer from "effect/Layer";
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
type Options,
|
|
23
|
+
type Factory,
|
|
24
|
+
type Policy,
|
|
25
|
+
makeDefault,
|
|
26
|
+
jittered,
|
|
27
|
+
capped,
|
|
28
|
+
throttlingOptions,
|
|
29
|
+
transientOptions,
|
|
30
|
+
throttlingFactory,
|
|
31
|
+
transientFactory,
|
|
32
|
+
} from "@distilled.cloud/core/retry";
|
|
33
|
+
|
|
34
|
+
/** Context tag for configuring retry behavior of Starburst Galaxy API calls. */
|
|
35
|
+
export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("StarburstGalaxyRetry") {}
|
|
36
|
+
|
|
37
|
+
/** Provides a custom retry policy to every Starburst Galaxy API call below it. */
|
|
38
|
+
export const policy = (optionsOrFactory: Policy) =>
|
|
39
|
+
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
40
|
+
|
|
41
|
+
/** Disables all automatic retries. */
|
|
42
|
+
export const none = /*@__PURE__*/ Effect.provide(
|
|
43
|
+
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
47
|
+
export const throttling = /*@__PURE__*/ policy(throttlingFactory);
|
|
48
|
+
|
|
49
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
50
|
+
export const transient = /*@__PURE__*/ policy(transientFactory);
|