@antelopejs/cloud-sdk 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file was auto-generated by openapi-typescript.
3
+ * Do not make direct changes to the file.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=cloud-api.js.map
@@ -0,0 +1,9 @@
1
+ /** Whether `value` is a string primitive. */
2
+ export declare function isString(value: unknown): value is string;
3
+ /**
4
+ * Whether `value` is a non-null object, arrays and class instances included.
5
+ * A value already typed `any` keeps that type.
6
+ */
7
+ export declare function isObject<T>(value: T): value is T & object;
8
+ /** Whether `value` is a non-null object that is not an array. */
9
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
package/dist/guards.js ADDED
@@ -0,0 +1,16 @@
1
+ /** Whether `value` is a string primitive. */
2
+ export function isString(value) {
3
+ return typeof value === "string";
4
+ }
5
+ /**
6
+ * Whether `value` is a non-null object, arrays and class instances included.
7
+ * A value already typed `any` keeps that type.
8
+ */
9
+ export function isObject(value) {
10
+ return typeof value === "object" && value !== null;
11
+ }
12
+ /** Whether `value` is a non-null object that is not an array. */
13
+ export function isRecord(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ //# sourceMappingURL=guards.js.map
@@ -0,0 +1,6 @@
1
+ export * from "./api-error.js";
2
+ export * from "./api.js";
3
+ export * from "./environments.js";
4
+ export type { components, operations, paths } from "./generated/cloud-api.js";
5
+ export type * from "./resources.js";
6
+ export * from "./sse.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./api-error.js";
2
+ export * from "./api.js";
3
+ export * from "./environments.js";
4
+ export * from "./sse.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,43 @@
1
+ import type { components } from "./generated/cloud-api.js";
2
+ type Schemas = components["schemas"];
3
+ /** The runtime tier of a workspace's plan. */
4
+ export type AppTier = Schemas["AppTier"];
5
+ export type DatabaseEngine = Schemas["DatabaseEngine"];
6
+ export type DatabaseMode = Schemas["DatabaseMode"];
7
+ /**
8
+ * A monthly amount. A plan that rates nothing a database holds includes it:
9
+ * `included` is true and there is no amount to show.
10
+ */
11
+ export type MonthlyCost = Schemas["MonthlyCost"];
12
+ /** A database an environment runs. */
13
+ export type EnvironmentResource = Schemas["EnvironmentResource"];
14
+ /** The databases an environment runs. */
15
+ export type EnvironmentResources = Schemas["EnvironmentResources"];
16
+ /** A database Cloud would create for a module of the project. */
17
+ export type PlannedResource = Schemas["PlannedResource"];
18
+ /** A database of the environment that already satisfies a module. */
19
+ export type ExistingResource = Schemas["ExistingResource"];
20
+ /**
21
+ * A module whose need Cloud cannot provide: `not_offered` when Cloud does not
22
+ * run it, `not_on_plan` (with the cheapest `requiredTier`) when the
23
+ * workspace's plan does not include it.
24
+ */
25
+ export type UnprovidedResource = Schemas["UnprovidedResource"];
26
+ /** A count held against a ceiling, before and after the plan is applied. */
27
+ export type CeilingUse = Schemas["CeilingUse"];
28
+ /**
29
+ * What the environment's ceilings leave for the plan: the services it may
30
+ * hold, and, on Free, the databases.
31
+ */
32
+ export type ResourcePlanLimits = Schemas["ResourcePlanLimits"];
33
+ /**
34
+ * Why an apply is refused with a 409 before any write: `preview_environment`,
35
+ * `services_per_environment` or `databases_per_environment`. The apply answers
36
+ * with the error key of the plan's first one.
37
+ */
38
+ export type ResourcePlanRefusal = Schemas["ResourcePlanRefusal"];
39
+ /** What applying a project's modules to an environment would do. */
40
+ export type ResourcePlan = Schemas["ResourcePlan"];
41
+ /** The databases an apply created, and the plan that remains. */
42
+ export type AppliedResources = Schemas["AppliedResources"];
43
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1,25 @@
1
+ import { type ApiErrorParams, CloudApiError } from "./api-error.js";
2
+ interface ApiErrorFields {
3
+ code?: unknown;
4
+ error?: unknown;
5
+ message?: unknown;
6
+ params?: unknown;
7
+ }
8
+ /** A refusal as the OpenAPI document names it: a code, or an object naming it. */
9
+ export type ApiErrorBody = string | ApiErrorFields;
10
+ /** What an `openapi-fetch` call settles to. */
11
+ export interface ApiResult<T> {
12
+ data?: T;
13
+ error?: unknown;
14
+ response: Response;
15
+ }
16
+ export declare function isApiErrorBody(value: unknown): value is ApiErrorBody;
17
+ export declare function errorCode(body: ApiErrorBody | undefined): string;
18
+ /** The string values a `{ message, params }` refusal interpolates. */
19
+ export declare function errorParams(body: ApiErrorBody | undefined): ApiErrorParams;
20
+ export declare function refusal(status: number, body: ApiErrorBody | undefined, text?: string): CloudApiError;
21
+ /** The answer's body, or the refusal it carries. */
22
+ export declare function dataOf<T>(result: ApiResult<T>): T;
23
+ /** For an answer that has no body: it only has to be accepted. */
24
+ export declare function acceptedOf(result: ApiResult<unknown>): void;
25
+ export {};
package/dist/result.js ADDED
@@ -0,0 +1,36 @@
1
+ import { CloudApiError } from "./api-error.js";
2
+ import { isObject, isRecord, isString } from "./guards.js";
3
+ export function isApiErrorBody(value) {
4
+ return isString(value) || isRecord(value);
5
+ }
6
+ export function errorCode(body) {
7
+ if (isString(body))
8
+ return body;
9
+ return [body?.code, body?.error, body?.message].find(isString) ?? "api_error";
10
+ }
11
+ /** The string values a `{ message, params }` refusal interpolates. */
12
+ export function errorParams(body) {
13
+ const params = isString(body) ? undefined : body?.params;
14
+ if (!isObject(params))
15
+ return {};
16
+ return Object.fromEntries(Object.entries(params).filter((entry) => typeof entry[1] === "string"));
17
+ }
18
+ export function refusal(status, body, text) {
19
+ return new CloudApiError(status, errorCode(body), text, errorParams(body));
20
+ }
21
+ function refusalOf(result) {
22
+ return refusal(result.response.status, isApiErrorBody(result.error) ? result.error : undefined);
23
+ }
24
+ /** The answer's body, or the refusal it carries. */
25
+ export function dataOf(result) {
26
+ if (!result.response.ok || result.error || result.data === undefined) {
27
+ throw refusalOf(result);
28
+ }
29
+ return result.data;
30
+ }
31
+ /** For an answer that has no body: it only has to be accepted. */
32
+ export function acceptedOf(result) {
33
+ if (!result.response.ok || result.error)
34
+ throw refusalOf(result);
35
+ }
36
+ //# sourceMappingURL=result.js.map
package/dist/sse.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export interface SseEvent {
2
+ event: string;
3
+ data: unknown;
4
+ id?: string;
5
+ }
6
+ export declare function parseSse(response: Response): AsyncGenerator<SseEvent>;
package/dist/sse.js ADDED
@@ -0,0 +1,45 @@
1
+ function eventOf(lines) {
2
+ let event = "message";
3
+ let id;
4
+ const data = [];
5
+ for (const line of lines) {
6
+ if (line.startsWith("event:"))
7
+ event = fieldValue(line.slice(6));
8
+ if (line.startsWith("id:"))
9
+ id = fieldValue(line.slice(3));
10
+ if (line.startsWith("data:"))
11
+ data.push(fieldValue(line.slice(5)));
12
+ }
13
+ if (data.length === 0)
14
+ return null;
15
+ const text = data.join("\n");
16
+ try {
17
+ return { event, data: JSON.parse(text), id };
18
+ }
19
+ catch {
20
+ return { event, data: text, id };
21
+ }
22
+ }
23
+ function fieldValue(value) {
24
+ return value.startsWith(" ") ? value.slice(1) : value;
25
+ }
26
+ export async function* parseSse(response) {
27
+ if (!response.body)
28
+ return;
29
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
30
+ let buffer = "";
31
+ while (true) {
32
+ const { done, value } = await reader.read();
33
+ buffer += value ?? "";
34
+ const frames = buffer.split(/\r?\n\r?\n/);
35
+ buffer = frames.pop() ?? "";
36
+ for (const frame of frames) {
37
+ const event = eventOf(frame.split(/\r?\n/));
38
+ if (event)
39
+ yield event;
40
+ }
41
+ if (done)
42
+ break;
43
+ }
44
+ }
45
+ //# sourceMappingURL=sse.js.map