@distilled.cloud/render 0.0.0 → 1.0.0-rc.11

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.
Files changed (47) hide show
  1. package/LICENSE +201 -0
  2. package/lib/credentials.d.ts +29 -0
  3. package/lib/credentials.d.ts.map +1 -0
  4. package/lib/credentials.js +35 -0
  5. package/lib/credentials.js.map +1 -0
  6. package/lib/errors.d.ts +36 -0
  7. package/lib/errors.d.ts.map +1 -0
  8. package/lib/errors.js +26 -0
  9. package/lib/errors.js.map +1 -0
  10. package/lib/index.d.ts +24 -0
  11. package/lib/index.d.ts.map +1 -0
  12. package/lib/index.js +28 -0
  13. package/lib/index.js.map +1 -0
  14. package/lib/pagination.d.ts +8 -0
  15. package/lib/pagination.d.ts.map +1 -0
  16. package/lib/pagination.js +50 -0
  17. package/lib/pagination.js.map +1 -0
  18. package/lib/protocol.d.ts +18 -0
  19. package/lib/protocol.d.ts.map +1 -0
  20. package/lib/protocol.js +46 -0
  21. package/lib/protocol.js.map +1 -0
  22. package/lib/retry.d.ts +32 -0
  23. package/lib/retry.d.ts.map +1 -0
  24. package/lib/retry.js +32 -0
  25. package/lib/retry.js.map +1 -0
  26. package/lib/services/index.d.ts +2 -0
  27. package/lib/services/index.d.ts.map +1 -0
  28. package/lib/services/index.js +3 -0
  29. package/lib/services/index.js.map +1 -0
  30. package/lib/services/render.d.ts +6083 -0
  31. package/lib/services/render.d.ts.map +1 -0
  32. package/lib/services/render.js +6273 -0
  33. package/lib/services/render.js.map +1 -0
  34. package/lib/traits.d.ts +11 -0
  35. package/lib/traits.d.ts.map +1 -0
  36. package/lib/traits.js +11 -0
  37. package/lib/traits.js.map +1 -0
  38. package/package.json +77 -6
  39. package/src/credentials.ts +57 -0
  40. package/src/errors.ts +50 -0
  41. package/src/index.ts +36 -0
  42. package/src/pagination.ts +66 -0
  43. package/src/protocol.ts +69 -0
  44. package/src/retry.ts +54 -0
  45. package/src/services/index.ts +2 -0
  46. package/src/services/render.ts +16417 -0
  47. package/src/traits.ts +44 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Render SDK trait surface — hand-written.
3
+ *
4
+ * Re-exports the generic protocol traits from core (so generated operations
5
+ * import everything from one place). Render has no envelope of its own; the
6
+ * REST-protocol traits (SensitiveValue / RawResponse) come from
7
+ * `core/protocol-rest`.
8
+ */
9
+ export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, type HttpTrait, type ErrorMatcher, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
10
+ export { SensitiveValue, RawResponse, RawResponseRoot, sensitiveValueSymbol, rawResponseSymbol, rawResponseRootSymbol, } from "@distilled.cloud/core/protocol-rest";
11
+ //# sourceMappingURL=traits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traits.d.ts","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
package/lib/traits.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Render SDK trait surface — hand-written.
3
+ *
4
+ * Re-exports the generic protocol traits from core (so generated operations
5
+ * import everything from one place). Render has no envelope of its own; the
6
+ * REST-protocol traits (SensitiveValue / RawResponse) come from
7
+ * `core/protocol-rest`.
8
+ */
9
+ export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
10
+ export { SensitiveValue, RawResponse, RawResponseRoot, sensitiveValueSymbol, rawResponseSymbol, rawResponseRootSymbol, } from "@distilled.cloud/core/protocol-rest";
11
+ //# sourceMappingURL=traits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traits.js","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAGhB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,85 @@
1
1
  {
2
2
  "name": "@distilled.cloud/render",
3
- "version": "0.0.0",
4
- "description": "Placeholder package for an upcoming distilled SDK.",
5
- "license": "Apache-2.0",
3
+ "version": "1.0.0-rc.11",
6
4
  "repository": {
7
5
  "type": "git",
8
6
  "url": "https://github.com/alchemy-run/distilled",
9
7
  "directory": "packages/render"
10
8
  },
11
- "publishConfig": {
12
- "access": "public"
9
+ "license": "Apache-2.0",
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "files": [
13
+ "lib",
14
+ "src"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/index.d.ts",
19
+ "bun": "./src/index.ts",
20
+ "worker": "./src/index.ts",
21
+ "default": "./lib/index.js"
22
+ },
23
+ "./Credentials": {
24
+ "types": "./lib/credentials.d.ts",
25
+ "bun": "./src/credentials.ts",
26
+ "worker": "./src/credentials.ts",
27
+ "default": "./lib/credentials.js"
28
+ },
29
+ "./Errors": {
30
+ "types": "./lib/errors.d.ts",
31
+ "bun": "./src/errors.ts",
32
+ "worker": "./src/errors.ts",
33
+ "default": "./lib/errors.js"
34
+ },
35
+ "./Traits": {
36
+ "types": "./lib/traits.d.ts",
37
+ "bun": "./src/traits.ts",
38
+ "worker": "./src/traits.ts",
39
+ "default": "./lib/traits.js"
40
+ },
41
+ "./Pagination": {
42
+ "types": "./lib/pagination.d.ts",
43
+ "bun": "./src/pagination.ts",
44
+ "worker": "./src/pagination.ts",
45
+ "default": "./lib/pagination.js"
46
+ },
47
+ "./Protocol": {
48
+ "types": "./lib/protocol.d.ts",
49
+ "bun": "./src/protocol.ts",
50
+ "worker": "./src/protocol.ts",
51
+ "default": "./lib/protocol.js"
52
+ },
53
+ "./Retry": {
54
+ "types": "./lib/retry.d.ts",
55
+ "bun": "./src/retry.ts",
56
+ "worker": "./src/retry.ts",
57
+ "default": "./lib/retry.js"
58
+ },
59
+ "./*": {
60
+ "types": "./lib/services/*.d.ts",
61
+ "bun": "./src/services/*.ts",
62
+ "worker": "./src/services/*.ts",
63
+ "default": "./lib/services/*.js"
64
+ }
65
+ },
66
+ "dependencies": {
67
+ "@distilled.cloud/core": "1.0.0-rc.11"
68
+ },
69
+ "devDependencies": {
70
+ "@types/bun": "1.3.14",
71
+ "@types/node": "26.2.0",
72
+ "@effect/platform-bun": ">=4.0.0-rc.115 || >=4.0.0"
73
+ },
74
+ "peerDependencies": {
75
+ "effect": ">=4.0.0-rc.115 || >=4.0.0"
76
+ },
77
+ "scripts": {
78
+ "build": "tsc -b",
79
+ "convert": "bun scripts/convert.ts",
80
+ "generate": "bun scripts/convert.ts && bun scripts/generate.ts",
81
+ "typecheck": "tsc -p tsconfig.json",
82
+ "specs:fetch": "git submodule update --force --init --depth=1 specs/spec-mirror-render",
83
+ "specs:update": "git submodule update --remote --force --depth=1 specs/spec-mirror-render"
13
84
  }
14
- }
85
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Render credentials — hand-written.
3
+ *
4
+ * The `Credentials` service holds an *effect* that resolves the current
5
+ * credentials on every request (the protocol layer resolves it per request
6
+ * on the calling fiber). Auth is a Render API key sent as
7
+ * `Authorization: Bearer <apiKey>`.
8
+ */
9
+ import * as Context from "effect/Context";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Layer from "effect/Layer";
12
+ import * as Redacted from "effect/Redacted";
13
+ import { ConfigError } from "@distilled.cloud/core/errors";
14
+
15
+ export const DEFAULT_API_BASE_URL = "https://api.render.com/v1";
16
+
17
+ export interface Config {
18
+ readonly apiKey: Redacted.Redacted<string>;
19
+ readonly apiBaseUrl: string;
20
+ }
21
+
22
+ export class Credentials extends Context.Service<
23
+ Credentials,
24
+ Effect.Effect<Config>
25
+ >()("RenderCredentials") {}
26
+
27
+ /** Layer from a plain API key + optional base URL. */
28
+ export const fromApiKey = (config: {
29
+ readonly apiKey: string;
30
+ readonly apiBaseUrl?: string;
31
+ }): Layer.Layer<Credentials> =>
32
+ Layer.succeed(
33
+ Credentials,
34
+ Effect.succeed({
35
+ apiKey: Redacted.make(config.apiKey),
36
+ apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,
37
+ }),
38
+ );
39
+
40
+ /** Reads RENDER_API_KEY (required) and RENDER_API_BASE_URL (optional). */
41
+ export const CredentialsFromEnv: Layer.Layer<Credentials> = Layer.succeed(
42
+ Credentials,
43
+ Effect.gen(function* () {
44
+ const apiKey = process.env.RENDER_API_KEY;
45
+
46
+ if (!apiKey) {
47
+ return yield* new ConfigError({
48
+ message: "RENDER_API_KEY environment variable is required",
49
+ });
50
+ }
51
+
52
+ return {
53
+ apiKey: Redacted.make(apiKey),
54
+ apiBaseUrl: process.env.RENDER_API_BASE_URL ?? DEFAULT_API_BASE_URL,
55
+ };
56
+ }).pipe(Effect.orDie),
57
+ );
package/src/errors.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Render-specific error types.
3
+ *
4
+ * Re-exports the common HTTP errors from core and adds the Render fallback
5
+ * errors. Note the generated service module additionally defines its own
6
+ * per-status matcher classes (BadRequest/NotFound/…) for the statuses each
7
+ * operation declares — those share `_tag`s with the core classes here, so
8
+ * `catchTag` works against either.
9
+ */
10
+ export {
11
+ BadGateway,
12
+ BadRequest,
13
+ Conflict,
14
+ ConfigError,
15
+ Forbidden,
16
+ GatewayTimeout,
17
+ InternalServerError,
18
+ Locked,
19
+ NotFound,
20
+ ServiceUnavailable,
21
+ TooManyRequests,
22
+ Unauthorized,
23
+ UnprocessableEntity,
24
+ HTTP_STATUS_MAP,
25
+ DEFAULT_ERRORS,
26
+ API_ERRORS,
27
+ } from "@distilled.cloud/core/errors";
28
+ export type { DefaultErrors } from "@distilled.cloud/core/errors";
29
+
30
+ import * as Schema from "effect/Schema";
31
+ import * as Category from "@distilled.cloud/core/category";
32
+
33
+ /** Unknown Render error — returned when nothing else matches the failure. */
34
+ export class UnknownRenderError extends Schema.TaggedError<UnknownRenderError>()(
35
+ "UnknownRenderError",
36
+ {
37
+ code: Schema.optional(Schema.String),
38
+ message: Schema.optional(Schema.String),
39
+ body: Schema.Unknown,
40
+ },
41
+ ).pipe(Category.withServerError) {}
42
+
43
+ /** Schema parse error wrapper. */
44
+ export class RenderParseError extends Schema.TaggedError<RenderParseError>()(
45
+ "RenderParseError",
46
+ {
47
+ body: Schema.Unknown,
48
+ cause: Schema.Unknown,
49
+ },
50
+ ).pipe(Category.withParseError) {}
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @distilled.cloud/render — Render SDK for Effect.
3
+ *
4
+ * `./services` is generated by `scripts/generate.ts` from the Smithy model
5
+ * in `.generated-specs` (written by `scripts/convert.ts` from the OpenAPI
6
+ * spec). Everything else in this folder is hand-written.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import * as Render from "@distilled.cloud/render";
11
+ *
12
+ * const services = yield* Render.Services.render.listServices({});
13
+ * ```
14
+ */
15
+ export * from "./credentials.ts";
16
+ export * from "./errors.ts";
17
+ export * as T from "./traits.ts";
18
+ export {
19
+ RenderProtocol,
20
+ type RenderOpError,
21
+ type RenderOpContext,
22
+ } from "./protocol.ts";
23
+ export { paginateCursor, paginateRender } from "./pagination.ts";
24
+ export * as Retry from "./retry.ts";
25
+ export * as Services from "./services/index.ts";
26
+ // Operations (and their request/response types) are importable straight off
27
+ // the package root. The service-local typed error classes shadow the
28
+ // same-named shared ones from ./errors.ts — the ops actually raise the
29
+ // service-local classes.
30
+ export * from "./services/render.ts";
31
+ export {
32
+ BadRequest,
33
+ Conflict,
34
+ Forbidden,
35
+ NotFound,
36
+ } from "./services/render.ts";
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Render pagination — hand-written.
3
+ *
4
+ * Render's list operations are cursor-mode (`cursor`/`limit` in). Most lists
5
+ * return a bare array of `{ cursor, <resource> }` objects; the next page is
6
+ * requested with the last item's `cursor`. The converter does not stamp
7
+ * those lists as paginated (that would un-collapse the raw-array wrapper),
8
+ * so {@link paginateRender} is for callers that walk the cursor by hand.
9
+ */
10
+ import * as Effect from "effect/Effect";
11
+ import * as Stream from "effect/Stream";
12
+ import * as Pagination from "@distilled.cloud/core/pagination";
13
+
14
+ export { paginateCursor } from "@distilled.cloud/core/pagination";
15
+
16
+ /**
17
+ * Walk forward with `cursor` set to the last item's `cursor` until a page
18
+ * comes back empty or the cursor does not advance.
19
+ */
20
+ export const paginateRender: Pagination.PaginationStrategy = (
21
+ operation,
22
+ input,
23
+ pagination,
24
+ ) => {
25
+ const inputToken = pagination.inputToken;
26
+ if (!inputToken) {
27
+ return Stream.die(
28
+ new Error("Render cursor pagination requires inputToken"),
29
+ );
30
+ }
31
+ const itemsPath = pagination.items ?? "body";
32
+
33
+ type State = { cursor: string | undefined; done: boolean };
34
+ const startCursor =
35
+ typeof input[inputToken] === "string"
36
+ ? (input[inputToken] as string)
37
+ : undefined;
38
+
39
+ return Stream.unfold({ cursor: startCursor, done: false } as State, (state) =>
40
+ Effect.gen(function* () {
41
+ if (state.done) return undefined;
42
+
43
+ const requestPayload = {
44
+ ...input,
45
+ ...(state.cursor ? { [inputToken]: state.cursor } : {}),
46
+ } as typeof input;
47
+ const response = yield* operation(requestPayload);
48
+ const items = Array.isArray(response)
49
+ ? response
50
+ : Pagination.getItems(response, itemsPath);
51
+ const last = items.at(-1) as { cursor?: unknown } | undefined;
52
+ const nextCursor =
53
+ typeof last?.cursor === "string" ? last.cursor : undefined;
54
+ const stuckCursor =
55
+ state.cursor !== undefined && nextCursor === state.cursor;
56
+
57
+ return [
58
+ response,
59
+ {
60
+ cursor: nextCursor,
61
+ done: items.length === 0 || nextCursor === undefined || stuckCursor,
62
+ },
63
+ ] as const;
64
+ }),
65
+ );
66
+ };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * RenderProtocol — hand-written.
3
+ *
4
+ * Render speaks plain bearer-authenticated JSON REST (no response envelope),
5
+ * so the whole protocol is one `makeRestProtocol` call from
6
+ * `core/protocol-rest`:
7
+ *
8
+ * request: credentials → `Authorization: Bearer <apiKey>` + base URL
9
+ * (default https://api.render.com/v1), resolved from the
10
+ * calling fiber on every request
11
+ *
12
+ * response: 2xx JSON is the payload (sensitive members delivered as
13
+ * `Redacted`); non-2xx `{ message }` bodies map to the
14
+ * operation's typed error classes by status, then the shared
15
+ * HTTP-status classes, then {@link UnknownRenderError}.
16
+ */
17
+ import * as Effect from "effect/Effect";
18
+ import type * as Layer from "effect/Layer";
19
+ 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
+ import { Credentials, type Config } from "./credentials.ts";
26
+ import { UnknownRenderError } from "./errors.ts";
27
+
28
+ /**
29
+ * Error channel shared by every generated Render operation. Generated
30
+ * service files annotate operations with `API.OperationMethod<I, O,
31
+ * RenderOpError, RenderOpContext>` explicitly so the compiler never infers
32
+ * these back out of the schema generics.
33
+ */
34
+ export type RenderOpError =
35
+ | InstanceType<(typeof API_ERRORS)[number]>
36
+ | UnknownRenderError
37
+ | ConfigError
38
+ | HttpClientError.HttpClientError;
39
+
40
+ /** Context (requirements) shared by every generated Render operation. */
41
+ export type RenderOpContext = Credentials | HttpClient.HttpClient;
42
+
43
+ export const RenderProtocol: Layer.Layer<API.Protocol> =
44
+ 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
+ Accept: "application/json",
55
+ }),
56
+ // Render's error body is `{ message: string }` — the factory's default
57
+ // lenient envelope covers it.
58
+ unknownError: ({ code, message, body }) =>
59
+ new UnknownRenderError({
60
+ code:
61
+ typeof code === "string"
62
+ ? code
63
+ : code !== undefined
64
+ ? String(code)
65
+ : undefined,
66
+ message,
67
+ body,
68
+ }),
69
+ });
package/src/retry.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Render retry configuration.
3
+ *
4
+ * Defines the per-SDK `Retry` Context.Service tag that generated operations
5
+ * wire into `API.make`. Callers can install a blanket retry policy at the
6
+ * layer level and have every Render API call below it pick it up:
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import * as Render from "@distilled.cloud/render";
11
+ *
12
+ * myEffect.pipe(Render.Retry.transient);
13
+ * Effect.provide(myEffect, Layer.succeed(Render.Retry.Retry, customPolicy));
14
+ * ```
15
+ */
16
+ import * as Context from "effect/Context";
17
+ import * as Effect from "effect/Effect";
18
+ import * as Layer from "effect/Layer";
19
+ import {
20
+ type Policy,
21
+ throttlingFactory,
22
+ transientFactory,
23
+ } from "@distilled.cloud/core/retry";
24
+
25
+ export {
26
+ type Options,
27
+ type Factory,
28
+ type Policy,
29
+ makeDefault,
30
+ jittered,
31
+ capped,
32
+ throttlingOptions,
33
+ transientOptions,
34
+ throttlingFactory,
35
+ transientFactory,
36
+ } from "@distilled.cloud/core/retry";
37
+
38
+ /** Context tag for configuring retry behavior of Render API calls. */
39
+ export class Retry extends Context.Service<Retry, Policy>()("RenderRetry") {}
40
+
41
+ /** Provides a custom retry policy to every Render API call below it. */
42
+ export const policy = (optionsOrFactory: Policy) =>
43
+ Effect.provide(Layer.succeed(Retry, optionsOrFactory));
44
+
45
+ /** Disables all automatic retries. */
46
+ export const none = Effect.provide(
47
+ Layer.succeed(Retry, { while: () => false }),
48
+ );
49
+
50
+ /** Apply the throttling retry policy (retries throttling errors indefinitely). */
51
+ export const throttling = policy(throttlingFactory);
52
+
53
+ /** Apply the transient retry policy (retries all transient errors indefinitely). */
54
+ export const transient = policy(transientFactory);
@@ -0,0 +1,2 @@
1
+ // AUTO-GENERATED by scripts/generate.ts. Do not edit.
2
+ export * as render from "./render.ts";