@distilled.cloud/clickhouse-cloud 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 +134 -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 +34 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +58 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +49 -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 +19 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +35 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +1 -0
- package/lib/services/api_keys.d.ts +175 -0
- package/lib/services/api_keys.d.ts.map +1 -0
- package/lib/services/api_keys.js +2 -0
- package/lib/services/api_keys.js.map +1 -0
- package/lib/services/backup.d.ts +117 -0
- package/lib/services/backup.d.ts.map +1 -0
- package/lib/services/backup.js +2 -0
- package/lib/services/backup.js.map +1 -0
- package/lib/services/billing.d.ts +69 -0
- package/lib/services/billing.d.ts.map +1 -0
- package/lib/services/billing.js +2 -0
- package/lib/services/billing.js.map +1 -0
- package/lib/services/click_pipes.d.ts +1637 -0
- package/lib/services/click_pipes.d.ts.map +1 -0
- package/lib/services/click_pipes.js +31 -0
- package/lib/services/click_pipes.js.map +1 -0
- package/lib/services/index.d.ts +14 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +13 -0
- package/lib/services/organization.d.ts +336 -0
- package/lib/services/organization.d.ts.map +1 -0
- package/lib/services/organization.js +2 -0
- package/lib/services/organization.js.map +1 -0
- package/lib/services/postgres.d.ts +726 -0
- package/lib/services/postgres.d.ts.map +1 -0
- package/lib/services/postgres.js +31 -0
- package/lib/services/postgres.js.map +1 -0
- package/lib/services/prometheus.d.ts +71 -0
- package/lib/services/prometheus.d.ts.map +1 -0
- package/lib/services/prometheus.js +2 -0
- package/lib/services/prometheus.js.map +1 -0
- package/lib/services/query_api_endpoints.d.ts +189 -0
- package/lib/services/query_api_endpoints.d.ts.map +1 -0
- package/lib/services/query_api_endpoints.js +2 -0
- package/lib/services/query_api_endpoints.js.map +1 -0
- package/lib/services/role_management.d.ts +159 -0
- package/lib/services/role_management.d.ts.map +1 -0
- package/lib/services/role_management.js +2 -0
- package/lib/services/role_management.js.map +1 -0
- package/lib/services/saved_queries.d.ts +129 -0
- package/lib/services/saved_queries.d.ts.map +1 -0
- package/lib/services/saved_queries.js +2 -0
- package/lib/services/saved_queries.js.map +1 -0
- package/lib/services/service.d.ts +886 -0
- package/lib/services/service.d.ts.map +1 -0
- package/lib/services/service.js +41 -0
- package/lib/services/service.js.map +1 -0
- package/lib/services/udf.d.ts +373 -0
- package/lib/services/udf.d.ts.map +1 -0
- package/lib/services/udf.js +24 -0
- package/lib/services/udf.js.map +1 -0
- package/lib/services/user_management.d.ts +150 -0
- package/lib/services/user_management.d.ts.map +1 -0
- package/lib/services/user_management.js +2 -0
- package/lib/services/user_management.js.map +1 -0
- package/lib/services.lazy/api_keys.js +1 -0
- package/lib/services.lazy/backup.js +1 -0
- package/lib/services.lazy/billing.js +1 -0
- package/lib/services.lazy/click_pipes.js +3 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/organization.js +1 -0
- package/lib/services.lazy/postgres.js +4 -0
- package/lib/services.lazy/prometheus.js +1 -0
- package/lib/services.lazy/query_api_endpoints.js +1 -0
- package/lib/services.lazy/role_management.js +1 -0
- package/lib/services.lazy/saved_queries.js +1 -0
- package/lib/services.lazy/service.js +4 -0
- package/lib/services.lazy/udf.js +3 -0
- package/lib/services.lazy/user_management.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/lib/unstable-services/backup.d.ts +165 -0
- package/lib/unstable-services/backup.d.ts.map +1 -0
- package/lib/unstable-services/backup.js +2 -0
- package/lib/unstable-services/backup.js.map +1 -0
- package/lib/unstable-services/billing.d.ts +84 -0
- package/lib/unstable-services/billing.d.ts.map +1 -0
- package/lib/unstable-services/billing.js +2 -0
- package/lib/unstable-services/billing.js.map +1 -0
- package/lib/unstable-services/click_pipes.d.ts +324 -0
- package/lib/unstable-services/click_pipes.d.ts.map +1 -0
- package/lib/unstable-services/click_pipes.js +2 -0
- package/lib/unstable-services/click_pipes.js.map +1 -0
- package/lib/unstable-services/click_stack.d.ts +3538 -0
- package/lib/unstable-services/click_stack.d.ts.map +1 -0
- package/lib/unstable-services/click_stack.js +60 -0
- package/lib/unstable-services/click_stack.js.map +1 -0
- package/lib/unstable-services/index.d.ts +11 -0
- package/lib/unstable-services/index.d.ts.map +1 -0
- package/lib/unstable-services/index.js +10 -0
- package/lib/unstable-services/notifications.d.ts +166 -0
- package/lib/unstable-services/notifications.d.ts.map +1 -0
- package/lib/unstable-services/notifications.js +2 -0
- package/lib/unstable-services/notifications.js.map +1 -0
- package/lib/unstable-services/organization.d.ts +403 -0
- package/lib/unstable-services/organization.d.ts.map +1 -0
- package/lib/unstable-services/organization.js +26 -0
- package/lib/unstable-services/organization.js.map +1 -0
- package/lib/unstable-services/postgres.d.ts +415 -0
- package/lib/unstable-services/postgres.d.ts.map +1 -0
- package/lib/unstable-services/postgres.js +2 -0
- package/lib/unstable-services/postgres.js.map +1 -0
- package/lib/unstable-services/service.d.ts +244 -0
- package/lib/unstable-services/service.d.ts.map +1 -0
- package/lib/unstable-services/service.js +2 -0
- package/lib/unstable-services/service.js.map +1 -0
- package/lib/unstable-services/snapshot.d.ts +146 -0
- package/lib/unstable-services/snapshot.d.ts.map +1 -0
- package/lib/unstable-services/snapshot.js +2 -0
- package/lib/unstable-services/snapshot.js.map +1 -0
- package/lib/unstable-services/user_management.d.ts +41 -0
- package/lib/unstable-services/user_management.d.ts.map +1 -0
- package/lib/unstable-services/user_management.js +2 -0
- package/lib/unstable-services/user_management.js.map +1 -0
- package/lib/unstable-services.lazy/backup.js +1 -0
- package/lib/unstable-services.lazy/billing.js +1 -0
- package/lib/unstable-services.lazy/click_pipes.js +1 -0
- package/lib/unstable-services.lazy/click_stack.js +4 -0
- package/lib/unstable-services.lazy/index.js +3 -0
- package/lib/unstable-services.lazy/notifications.js +1 -0
- package/lib/unstable-services.lazy/organization.js +4 -0
- package/lib/unstable-services.lazy/postgres.js +1 -0
- package/lib/unstable-services.lazy/service.js +1 -0
- package/lib/unstable-services.lazy/snapshot.js +1 -0
- package/lib/unstable-services.lazy/user_management.js +1 -0
- package/package.json +89 -2
- package/src/credentials.ts +88 -0
- package/src/errors.ts +76 -0
- package/src/index.ts +53 -0
- package/src/pagination.ts +9 -0
- package/src/protocol.ts +76 -0
- package/src/retry.ts +53 -0
- package/src/services/api_keys.ts +466 -0
- package/src/services/backup.ts +347 -0
- package/src/services/billing.ts +170 -0
- package/src/services/click_pipes.ts +3483 -0
- package/src/services/index.ts +14 -0
- package/src/services/organization.ts +901 -0
- package/src/services/postgres.ts +1967 -0
- package/src/services/prometheus.ts +271 -0
- package/src/services/query_api_endpoints.ts +466 -0
- package/src/services/role_management.ts +436 -0
- package/src/services/saved_queries.ts +384 -0
- package/src/services/service.ts +2112 -0
- package/src/services/udf.ts +1019 -0
- package/src/services/user_management.ts +508 -0
- package/src/traits.ts +45 -0
- package/src/unstable-services/backup.ts +422 -0
- package/src/unstable-services/billing.ts +232 -0
- package/src/unstable-services/click_pipes.ts +702 -0
- package/src/unstable-services/click_stack.ts +7114 -0
- package/src/unstable-services/index.ts +11 -0
- package/src/unstable-services/notifications.ts +451 -0
- package/src/unstable-services/organization.ts +1107 -0
- package/src/unstable-services/postgres.ts +1061 -0
- package/src/unstable-services/service.ts +795 -0
- package/src/unstable-services/snapshot.ts +397 -0
- package/src/unstable-services/user_management.ts +127 -0
package/package.json
CHANGED
|
@@ -1,10 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/clickhouse-cloud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-rc.21",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/alchemy-run/distilled",
|
|
8
8
|
"directory": "packages/clickhouse-cloud"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"module": "src/index.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/index.d.ts",
|
|
20
|
+
"bun": "./src/index.ts",
|
|
21
|
+
"worker": "./src/index.ts",
|
|
22
|
+
"default": "./lib/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./Credentials": {
|
|
25
|
+
"types": "./lib/credentials.d.ts",
|
|
26
|
+
"bun": "./src/credentials.ts",
|
|
27
|
+
"worker": "./src/credentials.ts",
|
|
28
|
+
"default": "./lib/credentials.js"
|
|
29
|
+
},
|
|
30
|
+
"./Errors": {
|
|
31
|
+
"types": "./lib/errors.d.ts",
|
|
32
|
+
"bun": "./src/errors.ts",
|
|
33
|
+
"worker": "./src/errors.ts",
|
|
34
|
+
"default": "./lib/errors.js"
|
|
35
|
+
},
|
|
36
|
+
"./Pagination": {
|
|
37
|
+
"types": "./lib/pagination.d.ts",
|
|
38
|
+
"bun": "./src/pagination.ts",
|
|
39
|
+
"worker": "./src/pagination.ts",
|
|
40
|
+
"default": "./lib/pagination.js"
|
|
41
|
+
},
|
|
42
|
+
"./Protocol": {
|
|
43
|
+
"types": "./lib/protocol.d.ts",
|
|
44
|
+
"bun": "./src/protocol.ts",
|
|
45
|
+
"worker": "./src/protocol.ts",
|
|
46
|
+
"default": "./lib/protocol.js"
|
|
47
|
+
},
|
|
48
|
+
"./Retry": {
|
|
49
|
+
"types": "./lib/retry.d.ts",
|
|
50
|
+
"bun": "./src/retry.ts",
|
|
51
|
+
"worker": "./src/retry.ts",
|
|
52
|
+
"default": "./lib/retry.js"
|
|
53
|
+
},
|
|
54
|
+
"./Traits": {
|
|
55
|
+
"types": "./lib/traits.d.ts",
|
|
56
|
+
"bun": "./src/traits.ts",
|
|
57
|
+
"worker": "./src/traits.ts",
|
|
58
|
+
"default": "./lib/traits.js"
|
|
59
|
+
},
|
|
60
|
+
"./unstable/*": {
|
|
61
|
+
"types": "./lib/unstable-services/*.d.ts",
|
|
62
|
+
"bun": "./src/unstable-services/*.ts",
|
|
63
|
+
"worker": "./src/unstable-services/*.ts",
|
|
64
|
+
"distilled-lazy": "./lib/unstable-services.lazy/*.js",
|
|
65
|
+
"default": "./lib/unstable-services/*.js"
|
|
66
|
+
},
|
|
67
|
+
"./*": {
|
|
68
|
+
"types": "./lib/services/*.d.ts",
|
|
69
|
+
"bun": "./src/services/*.ts",
|
|
70
|
+
"worker": "./src/services/*.ts",
|
|
71
|
+
"distilled-lazy": "./lib/services.lazy/*.js",
|
|
72
|
+
"default": "./lib/services/*.js"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"@distilled.cloud/core": "1.0.0-rc.21"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@distilled.cloud/dev": "0.0.0",
|
|
80
|
+
"@types/node": "26.6.5"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"effect": "~4.1.7"
|
|
84
|
+
},
|
|
85
|
+
"distilled": {
|
|
86
|
+
"generatedAt": "2026-11-27",
|
|
87
|
+
"specUpdatedAt": "2026-11-24"
|
|
88
|
+
},
|
|
89
|
+
"scripts": {
|
|
90
|
+
"build": "tsrs -b",
|
|
91
|
+
"convert": "node --conditions=bun scripts/convert.ts",
|
|
92
|
+
"generate": "node --conditions=bun scripts/generate.ts",
|
|
93
|
+
"typecheck": "tsrs -p tsconfig.json",
|
|
94
|
+
"specs:fetch": "git submodule update --force --init --depth=1 specs/spec-mirror-clickhouse-cloud",
|
|
95
|
+
"specs:update": "git submodule update --remote --force --depth=1 specs/spec-mirror-clickhouse-cloud"
|
|
9
96
|
}
|
|
10
|
-
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClickHouse Cloud credentials -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* The `Credentials` service resolves `{ keyId, keySecret, apiBaseUrl }` per
|
|
5
|
+
* request; the protocol sends them as `Authorization: Basic` (key ID as the
|
|
6
|
+
* username, key secret as the password), the scheme the OpenAPI document
|
|
7
|
+
* declares as `basicAuth`. Keys are created in the ClickHouse Cloud console or
|
|
8
|
+
* with `apiKeys.createApiKey`; the secret is shown once, at creation.
|
|
9
|
+
*
|
|
10
|
+
* Every operation path already carries the `/v1` prefix, so `apiBaseUrl` is
|
|
11
|
+
* the API origin.
|
|
12
|
+
*
|
|
13
|
+
* @see https://clickhouse.com/docs/cloud/manage/openapi
|
|
14
|
+
*/
|
|
15
|
+
import * as EffectConfig from "@distilled.cloud/core/config";
|
|
16
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Layer from "effect/Layer";
|
|
20
|
+
import * as Redacted from "effect/Redacted";
|
|
21
|
+
|
|
22
|
+
/** ClickHouse Cloud's API origin (the spec's `servers` entry). */
|
|
23
|
+
export const DEFAULT_API_BASE_URL = "https://api.clickhouse.cloud";
|
|
24
|
+
|
|
25
|
+
export interface Config {
|
|
26
|
+
/** API key ID, sent as the Basic-auth username. */
|
|
27
|
+
readonly keyId: string;
|
|
28
|
+
/** API key secret, sent as the Basic-auth password. */
|
|
29
|
+
readonly keySecret: Redacted.Redacted<string>;
|
|
30
|
+
/** API origin, without a trailing slash. */
|
|
31
|
+
readonly apiBaseUrl: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class Credentials
|
|
35
|
+
extends /*@__PURE__*/ Context.Service<Credentials, Effect.Effect<Config>>()(
|
|
36
|
+
"ClickHouseCloudCredentials",
|
|
37
|
+
) {}
|
|
38
|
+
|
|
39
|
+
const envConfig = /*@__PURE__*/ EffectConfig.all({
|
|
40
|
+
keyId: /*@__PURE__*/ EffectConfig.String("CLICKHOUSE_CLOUD_API_KEY_ID"),
|
|
41
|
+
keySecret: /*@__PURE__*/ EffectConfig.Redacted("CLICKHOUSE_CLOUD_API_KEY_SECRET"),
|
|
42
|
+
apiBaseUrl: /*@__PURE__*/ EffectConfig.String("CLICKHOUSE_CLOUD_API_URL").pipe(
|
|
43
|
+
/*@__PURE__*/ EffectConfig.withDefault(DEFAULT_API_BASE_URL),
|
|
44
|
+
),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Reads `CLICKHOUSE_CLOUD_API_KEY_ID` and `CLICKHOUSE_CLOUD_API_KEY_SECRET`
|
|
49
|
+
* (both required) and `CLICKHOUSE_CLOUD_API_URL` (optional).
|
|
50
|
+
*
|
|
51
|
+
* Its configuration is read and checked once, when the layer is built: a
|
|
52
|
+
* problem there fails the layer with `ConfigError`.
|
|
53
|
+
*/
|
|
54
|
+
export const CredentialsFromEnv: Layer.Layer<Credentials, ConfigError> = /*@__PURE__*/ Layer.effect(
|
|
55
|
+
Credentials,
|
|
56
|
+
/*@__PURE__*/ Effect.map(
|
|
57
|
+
/*@__PURE__*/ envConfig.pipe(
|
|
58
|
+
/*@__PURE__*/ Effect.map(({ keyId, keySecret, apiBaseUrl }) => ({
|
|
59
|
+
keyId,
|
|
60
|
+
keySecret,
|
|
61
|
+
apiBaseUrl: apiBaseUrl.replace(/\/+$/, ""),
|
|
62
|
+
})),
|
|
63
|
+
/*@__PURE__*/ Effect.mapError(
|
|
64
|
+
() =>
|
|
65
|
+
new ConfigError({
|
|
66
|
+
message:
|
|
67
|
+
"CLICKHOUSE_CLOUD_API_KEY_ID and CLICKHOUSE_CLOUD_API_KEY_SECRET environment variables are required",
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
(config) => Effect.succeed(config),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
/** Credentials from an API key ID, its redacted secret and an optional origin. */
|
|
76
|
+
export const credentials = (config: {
|
|
77
|
+
readonly keyId: string;
|
|
78
|
+
readonly keySecret: Redacted.Redacted<string>;
|
|
79
|
+
readonly apiBaseUrl?: string;
|
|
80
|
+
}): Layer.Layer<Credentials> =>
|
|
81
|
+
Layer.succeed(
|
|
82
|
+
Credentials,
|
|
83
|
+
Effect.succeed({
|
|
84
|
+
keyId: config.keyId,
|
|
85
|
+
keySecret: config.keySecret,
|
|
86
|
+
apiBaseUrl: (config.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/+$/, ""),
|
|
87
|
+
}),
|
|
88
|
+
);
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClickHouse Cloud error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the common HTTP errors from core and adds the unknown-error and
|
|
5
|
+
* parse-error classes.
|
|
6
|
+
*
|
|
7
|
+
* Every ClickHouse Cloud failure carries the same envelope -- `{ "status":
|
|
8
|
+
* number, "error": string, "requestId": string }` -- where `error` is a
|
|
9
|
+
* human-readable description and there is no machine-readable code. The spec
|
|
10
|
+
* lists `400` and `500` on every operation and a few more statuses on some,
|
|
11
|
+
* all against that one envelope, so the SDK dispatches on the status (the
|
|
12
|
+
* classes here) and keeps the body on {@link UnknownClickHouseCloudError}
|
|
13
|
+
* for the statuses nothing else maps (the documented `410` and `424`
|
|
14
|
+
* included). Where an answer means something a caller acts on, a patch under
|
|
15
|
+
* `patches/` types it per operation by status and `error` text:
|
|
16
|
+
* `DeletionProtectionEnabled`, `ServiceNotTerminable` and `InstanceLimitReached`
|
|
17
|
+
* (409), `FeatureUnavailable` (a 403 for a feature the plan or organization
|
|
18
|
+
* lacks, such as ClickStack not set up or a BYOC-only operation),
|
|
19
|
+
* `ServiceNotIdle` and `DeletionProtectionNotEnabled` (400). Everything else
|
|
20
|
+
* stays the status's class, with the envelope's `error` as its message.
|
|
21
|
+
*/
|
|
22
|
+
export {
|
|
23
|
+
BadGateway,
|
|
24
|
+
BadRequest,
|
|
25
|
+
Conflict,
|
|
26
|
+
ConfigError,
|
|
27
|
+
Forbidden,
|
|
28
|
+
GatewayTimeout,
|
|
29
|
+
InternalServerError,
|
|
30
|
+
Locked,
|
|
31
|
+
NotFound,
|
|
32
|
+
ServiceUnavailable,
|
|
33
|
+
TooManyRequests,
|
|
34
|
+
Unauthorized,
|
|
35
|
+
UnprocessableEntity,
|
|
36
|
+
HTTP_STATUS_MAP,
|
|
37
|
+
DEFAULT_ERRORS,
|
|
38
|
+
API_ERRORS,
|
|
39
|
+
} from "@distilled.cloud/core/errors";
|
|
40
|
+
export type { DefaultErrors } from "@distilled.cloud/core/errors";
|
|
41
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
42
|
+
import { API_ERRORS, UnknownErrorFields } from "@distilled.cloud/core/errors";
|
|
43
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Unknown ClickHouse Cloud error -- returned when a failed response's HTTP
|
|
47
|
+
* status has no mapped error class. `status` is that HTTP status, `message`
|
|
48
|
+
* is the envelope's `error` text, and `body` is the whole response body
|
|
49
|
+
* (with its `requestId`, which ClickHouse Cloud support asks for).
|
|
50
|
+
*/
|
|
51
|
+
export class UnknownClickHouseCloudError
|
|
52
|
+
extends /*@__PURE__*/ Schema.TaggedError<UnknownClickHouseCloudError>()(
|
|
53
|
+
"UnknownClickHouseCloudError",
|
|
54
|
+
UnknownErrorFields,
|
|
55
|
+
) {}
|
|
56
|
+
|
|
57
|
+
/** A 2xx response that does not match the operation's output schema. */
|
|
58
|
+
export class ClickHouseCloudParseError
|
|
59
|
+
extends /*@__PURE__*/ Schema.TaggedError<ClickHouseCloudParseError>()(
|
|
60
|
+
"ClickHouseCloudParseError",
|
|
61
|
+
{
|
|
62
|
+
body: Schema.Unknown,
|
|
63
|
+
cause: Schema.Unknown,
|
|
64
|
+
},
|
|
65
|
+
).pipe(Category.withParseError) {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The errors declared on the ClickHouse Cloud service: any operation can
|
|
69
|
+
* return them, and every generated operation lists them as its
|
|
70
|
+
* `serviceErrors`. Today that is each of core's status classes (401, 403, 404,
|
|
71
|
+
* 429, the 5xx ...).
|
|
72
|
+
*/
|
|
73
|
+
export const ClickHouseCloudServiceErrors = API_ERRORS;
|
|
74
|
+
export type ClickHouseCloudServiceError = InstanceType<
|
|
75
|
+
(typeof ClickHouseCloudServiceErrors)[number]
|
|
76
|
+
>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/clickhouse-cloud -- ClickHouse Cloud API SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy models
|
|
5
|
+
* that `scripts/convert.ts` converts from the OpenAPI document ClickHouse
|
|
6
|
+
* Cloud serves at `https://api.clickhouse.cloud/v1`, mirrored at
|
|
7
|
+
* `specs/spec-mirror-clickhouse-cloud/specs/openapi.json`. Everything else in
|
|
8
|
+
* this folder is hand-written.
|
|
9
|
+
*
|
|
10
|
+
* One module per API tag (`service`, `apiKeys`, `clickPipes`, ...), the
|
|
11
|
+
* split the API reference uses. A module whose every operation is Beta
|
|
12
|
+
* upstream is generated to `./unstable-services` and imported as
|
|
13
|
+
* `@distilled.cloud/clickhouse-cloud/unstable/<module>` (`postgres`,
|
|
14
|
+
* `click_stack`, ...). Operations return the `result` of
|
|
15
|
+
* the API's `{ status, requestId, result }` envelope; a cursor page keeps the
|
|
16
|
+
* envelope, with its `result` page beside `nextCursor`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { Effect, Layer } from "effect";
|
|
21
|
+
* import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
22
|
+
* import * as ClickHouseCloud from "@distilled.cloud/clickhouse-cloud";
|
|
23
|
+
* import * as Organization from "@distilled.cloud/clickhouse-cloud/organization";
|
|
24
|
+
* import * as Service from "@distilled.cloud/clickhouse-cloud/service";
|
|
25
|
+
*
|
|
26
|
+
* const program = Effect.gen(function* () {
|
|
27
|
+
* const organizations = yield* Organization.listOrganizations({});
|
|
28
|
+
* const organizationId = organizations.result[0]?.id;
|
|
29
|
+
* if (organizationId === undefined) return [];
|
|
30
|
+
*
|
|
31
|
+
* const services = yield* Service.listServices({ organizationId });
|
|
32
|
+
* return services.map(({ name, state, region }) => ({ name, state, region }));
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const Live = Layer.mergeAll(
|
|
36
|
+
* FetchHttpClient.layer,
|
|
37
|
+
* ClickHouseCloud.CredentialsFromEnv,
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* program.pipe(Effect.provide(Live), Effect.runPromise).then(console.log);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export * from "./credentials.ts";
|
|
44
|
+
export * from "./errors.ts";
|
|
45
|
+
export * as T from "./traits.ts";
|
|
46
|
+
export {
|
|
47
|
+
ClickHouseCloudProtocol,
|
|
48
|
+
ClickHouseCloudPaginatedProtocol,
|
|
49
|
+
type ClickHouseCloudOpError,
|
|
50
|
+
type ClickHouseCloudOpContext,
|
|
51
|
+
} from "./protocol.ts";
|
|
52
|
+
export { paginateCursor } from "./pagination.ts";
|
|
53
|
+
export * as Retry from "./retry.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClickHouse Cloud pagination -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* Cursor-paginated lists take `cursor` and `limit` and answer with the page
|
|
5
|
+
* under `result` beside `nextCursor` (`null` on the last page). Generated
|
|
6
|
+
* operations pass core's {@link paginateCursor} strategy to
|
|
7
|
+
* `API.makePaginated`; `patches/<service>/pagination.json` marks them.
|
|
8
|
+
*/
|
|
9
|
+
export { paginateCursor } from "@distilled.cloud/core/pagination";
|
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ErrorOf } from "@distilled.cloud/core/protocol";
|
|
2
|
+
import { restProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
|
|
3
|
+
/**
|
|
4
|
+
* ClickHouseCloudProtocol -- the shared REST protocol instantiated for the
|
|
5
|
+
* ClickHouse Cloud API.
|
|
6
|
+
*
|
|
7
|
+
* request: `Authorization: Basic base64(keyId:keySecret)` against the API
|
|
8
|
+
* origin (`https://api.clickhouse.cloud`), resolved from the
|
|
9
|
+
* calling fiber on every request. Operation paths carry `/v1`.
|
|
10
|
+
*
|
|
11
|
+
* response: every JSON success body is the `{ status, requestId, result }`
|
|
12
|
+
* envelope; {@link ClickHouseCloudProtocol} returns its `result`,
|
|
13
|
+
* the payload the generated output shapes model. A body with no
|
|
14
|
+
* `result` (a delete, which has no payload) and a bare array come
|
|
15
|
+
* back as read. A cursor page keeps its envelope, because the
|
|
16
|
+
* pagination strategy reads `nextCursor` beside `result`: the
|
|
17
|
+
* paginated operations use {@link ClickHouseCloudPaginatedProtocol}.
|
|
18
|
+
* The Prometheus endpoints answer `text/plain` and the Postgres CA
|
|
19
|
+
* certificate endpoint `application/x-pem-file`; the body comes
|
|
20
|
+
* back as that text.
|
|
21
|
+
*
|
|
22
|
+
* Failures are `{ status, error, requestId }`; core's default
|
|
23
|
+
* envelope reader takes `error` as the message, and the status
|
|
24
|
+
* picks the class (core's `HTTP_STATUS_MAP`, then
|
|
25
|
+
* {@link UnknownClickHouseCloudError}).
|
|
26
|
+
*/
|
|
27
|
+
import * as Effect from "effect/Effect";
|
|
28
|
+
import * as Base64 from "effect/encoding/Base64";
|
|
29
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
30
|
+
import * as Redacted from "effect/Redacted";
|
|
31
|
+
import { Credentials } from "./credentials.ts";
|
|
32
|
+
import {
|
|
33
|
+
ClickHouseCloudParseError,
|
|
34
|
+
UnknownClickHouseCloudError,
|
|
35
|
+
type ClickHouseCloudServiceError,
|
|
36
|
+
} from "./errors.ts";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* What every generated ClickHouse Cloud operation fails with besides its own
|
|
40
|
+
* errors: the service's errors, the protocol's, and what resolving the
|
|
41
|
+
* credentials fails with. Generated service files annotate operations with
|
|
42
|
+
* `API.OperationMethod<I, O, ClickHouseCloudOpError,
|
|
43
|
+
* ClickHouseCloudOpContext>` explicitly so the compiler never infers these
|
|
44
|
+
* back out of the schema generics.
|
|
45
|
+
*/
|
|
46
|
+
export type ClickHouseCloudOpError =
|
|
47
|
+
| ClickHouseCloudServiceError
|
|
48
|
+
| ErrorOf<typeof ClickHouseCloudProtocol | typeof ClickHouseCloudPaginatedProtocol>;
|
|
49
|
+
|
|
50
|
+
/** Context (requirements) shared by every generated ClickHouse Cloud operation. */
|
|
51
|
+
export type ClickHouseCloudOpContext = Credentials | HttpClient.HttpClient;
|
|
52
|
+
|
|
53
|
+
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
54
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
55
|
+
|
|
56
|
+
const unwrapResult = (body: unknown): unknown =>
|
|
57
|
+
isObject(body) && "result" in body ? body.result : body;
|
|
58
|
+
|
|
59
|
+
const makeProtocol = (unwrap: boolean) =>
|
|
60
|
+
restProtocol({
|
|
61
|
+
// Resolved on the CALLING fiber per request, so a key rotated between
|
|
62
|
+
// calls is picked up.
|
|
63
|
+
credentials: /*@__PURE__*/ Effect.flatten(Credentials),
|
|
64
|
+
baseUrl: (creds) => creds.apiBaseUrl,
|
|
65
|
+
headers: (creds) => ({
|
|
66
|
+
Authorization: `Basic ${Base64.encode(`${creds.keyId}:${Redacted.value(creds.keySecret)}`)}`,
|
|
67
|
+
}),
|
|
68
|
+
...(unwrap ? { transformResponse: unwrapResult } : {}),
|
|
69
|
+
unknownError: (info) => new UnknownClickHouseCloudError(unknownErrorProps(info)),
|
|
70
|
+
parseError: ({ body, cause }) => new ClickHouseCloudParseError({ body, cause }),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const ClickHouseCloudProtocol = /*@__PURE__*/ makeProtocol(true);
|
|
74
|
+
|
|
75
|
+
/** The protocol for cursor-paginated operations: the envelope stays whole. */
|
|
76
|
+
export const ClickHouseCloudPaginatedProtocol = /*@__PURE__*/ makeProtocol(false);
|
package/src/retry.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClickHouse Cloud retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
3
|
+
*
|
|
4
|
+
* The `Retry` service tag is threaded into every generated operation, so a
|
|
5
|
+
* caller-installed policy applies to all ClickHouse Cloud calls below it and
|
|
6
|
+
* core's `makeDefault` is the fallback when none is provided.
|
|
7
|
+
*
|
|
8
|
+
* Each API key is limited to 10 requests per 10 seconds. A tripped limit is a
|
|
9
|
+
* `429`, which core maps to `TooManyRequests`; the default policy retries it
|
|
10
|
+
* with backoff and honors a `Retry-After` header.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import * as ClickHouseCloud from "@distilled.cloud/clickhouse-cloud";
|
|
15
|
+
*
|
|
16
|
+
* myEffect.pipe(ClickHouseCloud.Retry.transient);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import { type Policy, throttlingFactory, transientFactory } from "@distilled.cloud/core/retry";
|
|
20
|
+
import * as Context from "effect/Context";
|
|
21
|
+
import * as Effect from "effect/Effect";
|
|
22
|
+
import * as Layer from "effect/Layer";
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
type Factory,
|
|
26
|
+
type Options,
|
|
27
|
+
type Policy,
|
|
28
|
+
capped,
|
|
29
|
+
jittered,
|
|
30
|
+
makeDefault,
|
|
31
|
+
throttlingFactory,
|
|
32
|
+
throttlingOptions,
|
|
33
|
+
transientFactory,
|
|
34
|
+
transientOptions,
|
|
35
|
+
} from "@distilled.cloud/core/retry";
|
|
36
|
+
|
|
37
|
+
/** Context tag for configuring retry behavior of ClickHouse Cloud API calls. */
|
|
38
|
+
export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("ClickHouseCloudRetry") {}
|
|
39
|
+
|
|
40
|
+
/** Provides a custom retry policy to every ClickHouse Cloud API call below it. */
|
|
41
|
+
export const policy = (optionsOrFactory: Policy) =>
|
|
42
|
+
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
43
|
+
|
|
44
|
+
/** Disables all automatic retries. */
|
|
45
|
+
export const none = /*@__PURE__*/ Effect.provide(
|
|
46
|
+
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
50
|
+
export const throttling = /*@__PURE__*/ policy(throttlingFactory);
|
|
51
|
+
|
|
52
|
+
/** Retries all transient errors indefinitely (honoring server hints). */
|
|
53
|
+
export const transient = /*@__PURE__*/ policy(transientFactory);
|