@gaganref/confect-alchemy 10.6.0-fork.2 → 10.6.0-fork.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/dist/ConvexClient.d.ts +9 -3
- package/dist/ConvexClient.d.ts.map +1 -1
- package/dist/ConvexClient.js +48 -23
- package/dist/ConvexClient.js.map +1 -1
- package/dist/Deployment.d.ts +29 -3
- package/dist/Deployment.d.ts.map +1 -1
- package/dist/Deployment.js +37 -13
- package/dist/Deployment.js.map +1 -1
- package/dist/internal/CommandRunner.d.ts +4 -0
- package/dist/internal/CommandRunner.d.ts.map +1 -1
- package/dist/internal/CommandRunner.js +90 -4
- package/dist/internal/CommandRunner.js.map +1 -1
- package/dist/internal/LocalBackend.js +2 -2
- package/package.json +4 -4
- package/src/ConvexClient.ts +81 -31
- package/src/Deployment.ts +74 -12
- package/src/internal/CommandRunner.ts +182 -1
package/dist/ConvexClient.d.ts
CHANGED
|
@@ -15,10 +15,10 @@ export type DeployKey = Omit<ManagementApi.PlatformDeployKeyResponse, "allowedAc
|
|
|
15
15
|
};
|
|
16
16
|
export type CreateProjectInput = Pick<ManagementApi.PlatformCreateProjectArgs, "projectName">;
|
|
17
17
|
export type UpdateProjectInput = Pick<ManagementApi.PlatformUpdateProjectArgs, "name">;
|
|
18
|
-
export type CreateDeploymentInput = Pick<ManagementApi.PlatformCreateDeploymentArgs, "type" | "region" | "class"> & {
|
|
18
|
+
export type CreateDeploymentInput = Pick<ManagementApi.PlatformCreateDeploymentArgs, "type" | "region" | "class" | "expiresAt"> & {
|
|
19
19
|
readonly reference: string;
|
|
20
20
|
};
|
|
21
|
-
export type UpdateDeploymentInput = Pick<ManagementApi.PlatformUpdateDeploymentArgs, "reference" | "expiresAt" | "sendLogsToClient">;
|
|
21
|
+
export type UpdateDeploymentInput = Pick<ManagementApi.PlatformUpdateDeploymentArgs, "reference" | "expiresAt" | "sendLogsToClient" | "class">;
|
|
22
22
|
export type CreateDeployKeyInput = ManagementApi.PlatformCreateDeployKeyArgs;
|
|
23
23
|
export type CreatedDeployKey = {
|
|
24
24
|
readonly deployKey: Redacted.Redacted<ManagementApi.PlatformCreateDeployKeyResponse["deployKey"]>;
|
|
@@ -30,29 +30,35 @@ export type EnvironmentVariables = Readonly<Record<string, Redacted.Redacted<Dep
|
|
|
30
30
|
declare const ConvexApiError_base: Schema.Class<ConvexApiError, Schema.TaggedStruct<"ConvexApiError", {
|
|
31
31
|
operation: Schema.String;
|
|
32
32
|
status: Schema.optionalKey<Schema.Finite>;
|
|
33
|
+
serverCode: Schema.optionalKey<Schema.String>;
|
|
33
34
|
code: Schema.Literals<readonly ["HttpError", "TransportError", "InvalidResponse", "InvalidRequest", "InvalidPagination", "InvalidConfiguration"]>;
|
|
34
35
|
}>, import("effect/Cause").YieldableError & {
|
|
35
36
|
readonly brand: unique symbol;
|
|
36
37
|
}>;
|
|
37
38
|
export declare class ConvexApiError extends ConvexApiError_base {
|
|
39
|
+
get message(): string;
|
|
38
40
|
}
|
|
39
41
|
declare const ConvexNotFound_base: Schema.Class<ConvexNotFound, Schema.TaggedStruct<"ConvexNotFound", {
|
|
40
42
|
operation: Schema.String;
|
|
41
43
|
status: Schema.optionalKey<Schema.Finite>;
|
|
44
|
+
serverCode: Schema.optionalKey<Schema.String>;
|
|
42
45
|
code: Schema.Literals<readonly ["HttpError", "TransportError", "InvalidResponse", "InvalidRequest", "InvalidPagination", "InvalidConfiguration"]>;
|
|
43
46
|
}>, import("effect/Cause").YieldableError & {
|
|
44
47
|
readonly brand: unique symbol;
|
|
45
48
|
}>;
|
|
46
49
|
export declare class ConvexNotFound extends ConvexNotFound_base {
|
|
50
|
+
get message(): string;
|
|
47
51
|
}
|
|
48
52
|
declare const ConvexConflict_base: Schema.Class<ConvexConflict, Schema.TaggedStruct<"ConvexConflict", {
|
|
49
53
|
operation: Schema.String;
|
|
50
54
|
status: Schema.optionalKey<Schema.Finite>;
|
|
55
|
+
serverCode: Schema.optionalKey<Schema.String>;
|
|
51
56
|
code: Schema.Literals<readonly ["HttpError", "TransportError", "InvalidResponse", "InvalidRequest", "InvalidPagination", "InvalidConfiguration"]>;
|
|
52
57
|
}>, import("effect/Cause").YieldableError & {
|
|
53
58
|
readonly brand: unique symbol;
|
|
54
59
|
}>;
|
|
55
60
|
export declare class ConvexConflict extends ConvexConflict_base {
|
|
61
|
+
get message(): string;
|
|
56
62
|
}
|
|
57
63
|
declare const ConvexFunctionError_base: Schema.Class<ConvexFunctionError, Schema.TaggedStruct<"ConvexFunctionError", {
|
|
58
64
|
readonly functionPath: Schema.String;
|
|
@@ -71,7 +77,7 @@ declare const ConvexClient_base: Context.ServiceClass<ConvexClient, "@confect/al
|
|
|
71
77
|
* Run a deployment function with admin authority, internal ones and ones
|
|
72
78
|
* inside a component included.
|
|
73
79
|
*/
|
|
74
|
-
runFunction: (url: string, key: Redacted.Redacted<string>, functionPath: string, args: unknown, componentPath?: string | undefined) => Effect.Effect<unknown, ConvexApiError | ConvexFunctionError, never>;
|
|
80
|
+
runFunction: (url: string, key: Redacted.Redacted<string>, functionPath: string, args: unknown, componentPath?: string | undefined) => Effect.Effect<unknown, ConvexApiError | ConvexConflict | ConvexFunctionError | ConvexNotFound, never>;
|
|
75
81
|
listProjects: (teamId: number) => Effect.Effect<{
|
|
76
82
|
id: ManagementApi.components["schemas"]["ProjectId"];
|
|
77
83
|
name: ManagementApi.components["schemas"]["ProjectName"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConvexClient.d.ts","sources":["../src/ConvexClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,aAAa,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,KAAK,aAAa,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;A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AiB,GACzB,cAAc,GACd,cAAc,GACd,cAAc,CAAC;;IA6Qf;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwPP,qBAAa,YAAa,SAAQ,iBAGE;CAAG;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,aAAc;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC;CAC9B,4DAC4E,CAAC"}
|
package/dist/ConvexClient.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as Config from "effect/Config";
|
|
|
6
6
|
import * as Context from "effect/Context";
|
|
7
7
|
import * as Redacted from "effect/Redacted";
|
|
8
8
|
import * as Schema from "effect/Schema";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
9
10
|
import * as HttpClient from "effect/http/HttpClient";
|
|
10
11
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
11
12
|
import * as String from "effect/String";
|
|
@@ -16,6 +17,7 @@ import * as Rec from "effect/Record";
|
|
|
16
17
|
const errorFields = {
|
|
17
18
|
operation: Schema.String,
|
|
18
19
|
status: Schema.optionalKey(Schema.Finite),
|
|
20
|
+
serverCode: Schema.optionalKey(Schema.String),
|
|
19
21
|
code: Schema.Literals([
|
|
20
22
|
"HttpError",
|
|
21
23
|
"TransportError",
|
|
@@ -25,9 +27,26 @@ const errorFields = {
|
|
|
25
27
|
"InvalidConfiguration"
|
|
26
28
|
])
|
|
27
29
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const errorMessage = (error) => {
|
|
31
|
+
const classification = error.status === void 0 ? error.code : `${error.status}, ${error.code}`;
|
|
32
|
+
const serverCode = error.serverCode === void 0 ? "" : `, ${error.serverCode}`;
|
|
33
|
+
return `${error.operation} failed (${classification}${serverCode})`;
|
|
34
|
+
};
|
|
35
|
+
var ConvexApiError = class extends Schema.TaggedError()("ConvexApiError", errorFields) {
|
|
36
|
+
get message() {
|
|
37
|
+
return errorMessage(this);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var ConvexNotFound = class extends Schema.TaggedError()("ConvexNotFound", errorFields) {
|
|
41
|
+
get message() {
|
|
42
|
+
return errorMessage(this);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var ConvexConflict = class extends Schema.TaggedError()("ConvexConflict", errorFields) {
|
|
46
|
+
get message() {
|
|
47
|
+
return errorMessage(this);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
31
50
|
/**
|
|
32
51
|
* A function the deployment ran failed, with the message Convex reports.
|
|
33
52
|
*/
|
|
@@ -115,6 +134,30 @@ const ProjectsPageSchema = Schema.Struct({
|
|
|
115
134
|
nextCursor: Schema.String.pipe(Schema.NullOr, Schema.optionalKey)
|
|
116
135
|
})
|
|
117
136
|
});
|
|
137
|
+
const maxErrorBodyBytes = 8192;
|
|
138
|
+
const httpFailure = Effect.fn("ConvexClient.httpFailure")(function* (operation, response) {
|
|
139
|
+
const fallback = ConvexApiError.make({
|
|
140
|
+
operation,
|
|
141
|
+
status: response.status,
|
|
142
|
+
code: "HttpError"
|
|
143
|
+
});
|
|
144
|
+
const serverCode = yield* response.stream.pipe(Stream.mapAccum(() => 0, (size, bytes) => {
|
|
145
|
+
const total = size + bytes.byteLength;
|
|
146
|
+
return [total, [{
|
|
147
|
+
size: total,
|
|
148
|
+
bytes
|
|
149
|
+
}]];
|
|
150
|
+
}), Stream.mapEffect(({ size, bytes }) => size > maxErrorBodyBytes ? Effect.fail(fallback) : Effect.succeed(bytes)), Stream.mkArrayBuffer, Effect.timeout("5 seconds"), Effect.map((bytes) => new TextDecoder().decode(bytes)), Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(Schema.Struct({ code: Schema.String })))), Effect.map(({ code }) => /^[A-Za-z][A-Za-z0-9]{0,63}$/.test(code) ? code : void 0), Effect.orElseSucceed(() => void 0));
|
|
151
|
+
const fields = {
|
|
152
|
+
operation,
|
|
153
|
+
status: response.status,
|
|
154
|
+
code: "HttpError",
|
|
155
|
+
...serverCode === void 0 ? {} : { serverCode }
|
|
156
|
+
};
|
|
157
|
+
if (response.status === 404) return yield* ConvexNotFound.make(fields);
|
|
158
|
+
if (response.status === 409) return yield* ConvexConflict.make(fields);
|
|
159
|
+
return yield* ConvexApiError.make(fields);
|
|
160
|
+
});
|
|
118
161
|
const make = Effect.fn("ConvexClient.make")(function* (options) {
|
|
119
162
|
const http = yield* HttpClient.HttpClient;
|
|
120
163
|
const managementAuthorization = Effect.gen(function* () {
|
|
@@ -135,21 +178,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options) {
|
|
|
135
178
|
operation,
|
|
136
179
|
code: "TransportError"
|
|
137
180
|
})));
|
|
138
|
-
if (response.status
|
|
139
|
-
operation,
|
|
140
|
-
status: 404,
|
|
141
|
-
code: "HttpError"
|
|
142
|
-
});
|
|
143
|
-
if (response.status === 409) return yield* ConvexConflict.make({
|
|
144
|
-
operation,
|
|
145
|
-
status: 409,
|
|
146
|
-
code: "HttpError"
|
|
147
|
-
});
|
|
148
|
-
if (response.status < 200 || response.status >= 300) return yield* ConvexApiError.make({
|
|
149
|
-
operation,
|
|
150
|
-
status: response.status,
|
|
151
|
-
code: "HttpError"
|
|
152
|
-
});
|
|
181
|
+
if (response.status < 200 || response.status >= 300) return yield* httpFailure(operation, response);
|
|
153
182
|
return response;
|
|
154
183
|
});
|
|
155
184
|
const decode = Effect.fn("ConvexClient.decode")(function* (operation, response, schema) {
|
|
@@ -208,11 +237,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options) {
|
|
|
208
237
|
operation,
|
|
209
238
|
code: "TransportError"
|
|
210
239
|
})));
|
|
211
|
-
if (response.status !== 200 && response.status !== 560) return yield*
|
|
212
|
-
operation,
|
|
213
|
-
status: response.status,
|
|
214
|
-
code: "HttpError"
|
|
215
|
-
});
|
|
240
|
+
if (response.status !== 200 && response.status !== 560) return yield* httpFailure(operation, response);
|
|
216
241
|
const result = yield* decode(operation, response, FunctionResponse);
|
|
217
242
|
if (result.status === "error") return yield* ConvexFunctionError.make({
|
|
218
243
|
functionPath,
|
package/dist/ConvexClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConvexClient.js","names":["Loopback.isOrigin"],"sources":["../src/ConvexClient.ts"],"sourcesContent":["import type * as DeploymentApi from \"@convex-dev/platform/deploymentApi\";\nimport type * as ManagementApi from \"@convex-dev/platform/managementApi\";\nimport type { ProviderMode } from \"alchemy/ProviderMode\";\nimport * as Config from \"effect/Config\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as HttpClient from \"effect/http/HttpClient\";\nimport * as HttpClientRequest from \"effect/http/HttpClientRequest\";\nimport type * as HttpClientResponse from \"effect/http/HttpClientResponse\";\nimport * as Loopback from \"./internal/Loopback.js\";\nimport * as String from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\n\nexport type Project = ManagementApi.ProjectResponse;\nexport type CreatedProject = ManagementApi.PlatformCreateProjectResponse;\nexport type Deployment = ManagementApi.PlatformDeploymentResponse;\nexport type DeployKey = Omit<\n ManagementApi.PlatformDeployKeyResponse,\n \"allowedActions\"\n> & {\n readonly allowedActions: readonly string[];\n};\nexport type CreateProjectInput = Pick<\n ManagementApi.PlatformCreateProjectArgs,\n \"projectName\"\n>;\nexport type UpdateProjectInput = Pick<\n ManagementApi.PlatformUpdateProjectArgs,\n \"name\"\n>;\nexport type CreateDeploymentInput = Pick<\n ManagementApi.PlatformCreateDeploymentArgs,\n \"type\" | \"region\" | \"class\"\n> & { readonly reference: string };\nexport type UpdateDeploymentInput = Pick<\n ManagementApi.PlatformUpdateDeploymentArgs,\n \"reference\" | \"expiresAt\" | \"sendLogsToClient\"\n>;\nexport type CreateDeployKeyInput = ManagementApi.PlatformCreateDeployKeyArgs;\nexport type CreatedDeployKey = {\n readonly deployKey: Redacted.Redacted<\n ManagementApi.PlatformCreateDeployKeyResponse[\"deployKey\"]\n >;\n};\nexport type EnvironmentVariableChange = Omit<\n DeploymentApi.UpdateEnvVarRequest,\n \"value\"\n> & {\n readonly value?:\n | Exclude<DeploymentApi.UpdateEnvVarRequest[\"value\"], undefined>\n | Redacted.Redacted<string>;\n};\nexport type EnvironmentVariables = Readonly<\n Record<\n string,\n Redacted.Redacted<\n DeploymentApi.ListEnvVarsResponse[\"environmentVariables\"][string]\n >\n >\n>;\n\nconst errorFields = {\n operation: Schema.String,\n status: Schema.optionalKey(Schema.Finite),\n code: Schema.Literals([\n \"HttpError\",\n \"TransportError\",\n \"InvalidResponse\",\n \"InvalidRequest\",\n \"InvalidPagination\",\n \"InvalidConfiguration\",\n ]),\n};\n\nexport class ConvexApiError extends Schema.TaggedError<\n ConvexApiError,\n { readonly brand: unique symbol }\n>()(\"ConvexApiError\", errorFields) {}\n\nexport class ConvexNotFound extends Schema.TaggedError<\n ConvexNotFound,\n { readonly brand: unique symbol }\n>()(\"ConvexNotFound\", errorFields) {}\n\nexport class ConvexConflict extends Schema.TaggedError<\n ConvexConflict,\n { readonly brand: unique symbol }\n>()(\"ConvexConflict\", errorFields) {}\n\n/**\n * A function the deployment ran failed, with the message Convex reports.\n */\nexport class ConvexFunctionError extends Schema.TaggedError<\n ConvexFunctionError,\n { readonly brand: unique symbol }\n>()(\"ConvexFunctionError\", {\n functionPath: Schema.String,\n errorMessage: Schema.String,\n}) {}\n\nconst FunctionResponse = Schema.Union([\n Schema.Struct({ status: Schema.Literal(\"success\"), value: Schema.Unknown }),\n Schema.Struct({\n status: Schema.Literal(\"error\"),\n errorMessage: Schema.String,\n }),\n]);\n\nexport type ConvexClientError =\n | ConvexApiError\n | ConvexNotFound\n | ConvexConflict;\n\nconst ProjectSchema = Schema.Struct({\n id: Schema.Finite,\n name: Schema.String,\n slug: Schema.String,\n teamId: Schema.Finite,\n teamSlug: Schema.String,\n createTime: Schema.Finite,\n prodDeploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n devDeploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n}) satisfies Schema.Schema<Project>;\n\nconst CreatedProjectSchema = Schema.Struct({\n id: Schema.Finite,\n projectId: Schema.Finite,\n slug: Schema.String,\n deploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n deploymentUrl: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n}) satisfies Schema.Schema<CreatedProject>;\n\nconst deploymentFields = {\n name: Schema.String,\n createTime: Schema.Finite,\n deploymentType: Schema.Literals([\"dev\", \"prod\", \"preview\", \"custom\"]),\n projectId: Schema.Finite,\n previewIdentifier: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n};\n\nconst DeploymentSchema = Schema.Union([\n Schema.Struct({\n ...deploymentFields,\n kind: Schema.Literal(\"cloud\"),\n id: Schema.Finite,\n lastDeployTime: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n creator: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n region: Schema.Literals([\n \"aws-us-east-1\",\n \"aws-eu-west-1\",\n \"aws-ap-southeast-2\",\n \"aws-ca-central-1\",\n ]),\n isDefault: Schema.Boolean,\n reference: Schema.String,\n dashboardEditConfirmation: Schema.Boolean.pipe(\n Schema.NullOr,\n Schema.optionalKey,\n ),\n deploymentUrl: Schema.String,\n expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n class: Schema.String,\n sendLogsToClient: Schema.Boolean.pipe(Schema.NullOr, Schema.optionalKey),\n }),\n Schema.Struct({\n ...deploymentFields,\n kind: Schema.Literal(\"local\"),\n creator: Schema.Finite,\n port: Schema.Finite,\n deviceName: Schema.String,\n isActive: Schema.Boolean,\n }),\n]) satisfies Schema.Schema<Deployment>;\n\nconst DeployKeySchema = Schema.Struct({\n id: Schema.Finite,\n name: Schema.String,\n creationTime: Schema.Finite,\n lastUsedTime: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n creator: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n managedBy: Schema.Union([\n Schema.Literal(\"vercel\"),\n Schema.Struct({ oauthApp: Schema.String }),\n ]).pipe(Schema.NullOr, Schema.optionalKey),\n allowedActions: Schema.Array(Schema.String),\n}) satisfies Schema.Schema<DeployKey>;\n\nconst ProjectsPageSchema = Schema.Struct({\n items: Schema.Array(ProjectSchema),\n pagination: Schema.Struct({\n hasMore: Schema.Boolean,\n nextCursor: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n }),\n});\n\nconst make = Effect.fn(\"ConvexClient.make\")(function* (options?: {\n readonly token?: Redacted.Redacted<string>;\n readonly mode?: ProviderMode;\n}) {\n const http = yield* HttpClient.HttpClient;\n const managementAuthorization = Effect.gen(function* () {\n const token =\n options?.token ??\n (yield* Config.Redacted(\"CONVEX_ACCESS_TOKEN\").pipe(\n Effect.mapError(() =>\n ConvexApiError.make({\n operation: \"configure\",\n code: \"InvalidConfiguration\",\n }),\n ),\n ));\n return Redacted.make(`Bearer ${Redacted.value(token)}`);\n });\n const baseUrl = \"https://api.convex.dev/v1\";\n\n const send = Effect.fn(\"ConvexClient.request\")(function* (\n operation: string,\n method: \"GET\" | \"POST\" | \"PATCH\",\n url: string,\n authorization: Redacted.Redacted<string>,\n body?: unknown,\n ) {\n let request = HttpClientRequest.make(method)(url).pipe(\n HttpClientRequest.setHeader(\n \"authorization\",\n Redacted.value(authorization),\n ),\n HttpClientRequest.acceptJson,\n );\n if (body !== undefined) {\n request = yield* HttpClientRequest.bodyJson(request, body).pipe(\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"InvalidRequest\" }),\n ),\n );\n }\n const response = yield* http.execute(request).pipe(\n Effect.provideService(FetchHttpClient.RequestInit, {\n redirect: \"manual\",\n }),\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"TransportError\" }),\n ),\n );\n if (response.status === 404) {\n return yield* ConvexNotFound.make({\n operation,\n status: 404,\n code: \"HttpError\",\n });\n }\n if (response.status === 409) {\n return yield* ConvexConflict.make({\n operation,\n status: 409,\n code: \"HttpError\",\n });\n }\n if (response.status < 200 || response.status >= 300) {\n return yield* ConvexApiError.make({\n operation,\n status: response.status,\n code: \"HttpError\",\n });\n }\n return response;\n });\n\n const decode = Effect.fn(\"ConvexClient.decode\")(function* <A>(\n operation: string,\n response: HttpClientResponse.HttpClientResponse,\n schema: Schema.Decoder<A>,\n ) {\n const invalidResponse = () =>\n ConvexApiError.make({\n operation,\n status: response.status,\n code: \"InvalidResponse\",\n });\n const body = yield* response.json.pipe(Effect.mapError(invalidResponse));\n return yield* Schema.decodeEffect(schema)(body).pipe(\n Effect.mapError(invalidResponse),\n );\n });\n\n const management = Effect.fn(\"ConvexClient.management\")(function* <A>(\n operation: string,\n method: \"GET\" | \"POST\" | \"PATCH\",\n path: string,\n schema: Schema.Decoder<A>,\n body?: unknown,\n ) {\n const managementAuthorizationValue = yield* managementAuthorization;\n const response = yield* send(\n operation,\n method,\n `${baseUrl}${path}`,\n managementAuthorizationValue,\n body,\n );\n return yield* decode(operation, response, schema);\n });\n\n const managementVoid = Effect.fn(\"ConvexClient.managementVoid\")(function* (\n operation: string,\n method: \"POST\" | \"PATCH\",\n path: string,\n body?: unknown,\n ) {\n const managementAuthorizationValue = yield* managementAuthorization;\n yield* send(\n operation,\n method,\n `${baseUrl}${path}`,\n managementAuthorizationValue,\n body,\n );\n });\n\n const deploymentUrl = Effect.fn(\"ConvexClient.deploymentUrl\")(function* (\n operation: string,\n url: string,\n ) {\n const invalidUrl = () =>\n ConvexApiError.make({ operation, code: \"InvalidRequest\" });\n if (options?.mode === \"local\") {\n if (!Loopback.isOrigin(url)) return yield* invalidUrl();\n return `${url}/api/v1`;\n }\n const parsed = yield* Effect.try({\n try: () => new URL(url),\n catch: invalidUrl,\n });\n if (\n parsed.protocol !== \"https:\" ||\n parsed.username !== \"\" ||\n parsed.password !== \"\" ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.pathname !== \"/\" ||\n !/^[a-z0-9-]+(?:\\.(?:eu-west-1|ap-southeast-2|ca-central-1))?\\.convex\\.cloud$/.test(\n parsed.hostname,\n ) ||\n pipe(url, String.replace(/\\/$/, \"\")) !== parsed.origin\n ) {\n return yield* invalidUrl();\n }\n return `${parsed.origin}/api/v1`;\n });\n\n return {\n /**\n * Run a deployment function with admin authority, internal ones and ones\n * inside a component included.\n */\n runFunction: Effect.fn(\"ConvexClient.runFunction\")(function* (\n url: string,\n key: Redacted.Redacted<string>,\n functionPath: string,\n args: unknown,\n componentPath?: string,\n ) {\n const operation = \"runFunction\";\n const deploymentUrlResult = yield* deploymentUrl(operation, url);\n const origin = pipe(\n deploymentUrlResult,\n String.replace(/\\/api\\/v1$/, \"\"),\n );\n const request = yield* HttpClientRequest.post(\n `${origin}/api/function`,\n ).pipe(\n HttpClientRequest.setHeader(\n \"authorization\",\n `Convex ${Redacted.value(key)}`,\n ),\n HttpClientRequest.acceptJson,\n HttpClientRequest.bodyJson({\n path: functionPath,\n args,\n format: \"json\",\n ...(componentPath === undefined ? {} : { componentPath }),\n }),\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"InvalidRequest\" }),\n ),\n );\n const response = yield* http.execute(request).pipe(\n Effect.provideService(FetchHttpClient.RequestInit, {\n redirect: \"manual\",\n }),\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"TransportError\" }),\n ),\n );\n // Convex answers a function that threw with 560 and its message.\n if (response.status !== 200 && response.status !== 560)\n return yield* ConvexApiError.make({\n operation,\n status: response.status,\n code: \"HttpError\",\n });\n const result = yield* decode(operation, response, FunctionResponse);\n if (result.status === \"error\")\n return yield* ConvexFunctionError.make({\n functionPath,\n errorMessage: result.errorMessage,\n });\n return result.value;\n }),\n listProjects: Effect.fn(\"ConvexClient.listProjects\")(function* (\n teamId: number,\n ) {\n const projects: Project[] = [];\n const seenCursors = new Set<string>();\n let cursor: string | undefined;\n while (true) {\n const page = yield* management(\n \"listProjects\",\n \"GET\",\n `/teams/${teamId}/projects${cursor === undefined ? \"\" : `?cursor=${encodeURIComponent(cursor)}`}`,\n ProjectsPageSchema,\n );\n projects.push(...page.items);\n if (!page.pagination.hasMore) return projects;\n const nextCursor = page.pagination.nextCursor;\n if (\n nextCursor === undefined ||\n nextCursor === null ||\n nextCursor === \"\" ||\n seenCursors.has(nextCursor)\n ) {\n return yield* ConvexApiError.make({\n operation: \"listProjects\",\n code: \"InvalidPagination\",\n });\n }\n seenCursors.add(nextCursor);\n cursor = nextCursor;\n }\n }),\n getProject: Effect.fn(\"ConvexClient.getProject\")((projectId: number) =>\n management(\"getProject\", \"GET\", `/projects/${projectId}`, ProjectSchema),\n ),\n createProject: Effect.fn(\"ConvexClient.createProject\")(\n (teamId: number, input: CreateProjectInput) =>\n management(\n \"createProject\",\n \"POST\",\n `/teams/${teamId}/create_project`,\n CreatedProjectSchema,\n input,\n ),\n ),\n updateProject: Effect.fn(\"ConvexClient.updateProject\")(\n (projectId: number, input: UpdateProjectInput) =>\n management(\n \"updateProject\",\n \"PATCH\",\n `/projects/${projectId}`,\n ProjectSchema,\n input,\n ),\n ),\n deleteProject: Effect.fn(\"ConvexClient.deleteProject\")(\n (projectId: number) =>\n managementVoid(\n \"deleteProject\",\n \"POST\",\n `/projects/${projectId}/delete`,\n ),\n ),\n listDeployments: Effect.fn(\"ConvexClient.listDeployments\")(\n (projectId: number) =>\n management(\n \"listDeployments\",\n \"GET\",\n `/projects/${projectId}/list_deployments`,\n Schema.Array(DeploymentSchema),\n ),\n ),\n getDeployment: Effect.fn(\"ConvexClient.getDeployment\")((name: string) =>\n management(\n \"getDeployment\",\n \"GET\",\n `/deployments/${encodeURIComponent(name)}`,\n DeploymentSchema,\n ),\n ),\n createDeployment: Effect.fn(\"ConvexClient.createDeployment\")(\n (projectId: number, input: CreateDeploymentInput) =>\n management(\n \"createDeployment\",\n \"POST\",\n `/projects/${projectId}/create_deployment`,\n DeploymentSchema,\n input,\n ),\n ),\n updateDeployment: Effect.fn(\"ConvexClient.updateDeployment\")(\n (name: string, input: UpdateDeploymentInput) =>\n managementVoid(\n \"updateDeployment\",\n \"PATCH\",\n `/deployments/${encodeURIComponent(name)}`,\n input,\n ),\n ),\n deleteDeployment: Effect.fn(\"ConvexClient.deleteDeployment\")(\n (name: string) =>\n managementVoid(\n \"deleteDeployment\",\n \"POST\",\n `/deployments/${encodeURIComponent(name)}/delete`,\n ),\n ),\n createDeployKey: Effect.fn(\"ConvexClient.createDeployKey\")(function* (\n name: string,\n input: CreateDeployKeyInput,\n ): Effect.fn.Return<CreatedDeployKey, ConvexClientError> {\n const response = yield* management(\n \"createDeployKey\",\n \"POST\",\n `/deployments/${encodeURIComponent(name)}/create_deploy_key`,\n Schema.Struct({ deployKey: Schema.String }),\n input,\n );\n return { deployKey: Redacted.make(response.deployKey) };\n }),\n listDeployKeys: Effect.fn(\"ConvexClient.listDeployKeys\")((name: string) =>\n management(\n \"listDeployKeys\",\n \"GET\",\n `/deployments/${encodeURIComponent(name)}/list_deploy_keys`,\n Schema.Array(DeployKeySchema),\n ),\n ),\n deleteDeployKey: Effect.fn(\"ConvexClient.deleteDeployKey\")(\n (name: string, id: string | Redacted.Redacted<string>) =>\n managementVoid(\n \"deleteDeployKey\",\n \"POST\",\n `/deployments/${encodeURIComponent(name)}/delete_deploy_key`,\n {\n id: Redacted.isRedacted(id) ? Redacted.value(id) : id,\n } satisfies ManagementApi.PlatformDeleteDeployKeyArgs,\n ),\n ),\n listEnvironmentVariables: Effect.fn(\n \"ConvexClient.listEnvironmentVariables\",\n )(function* (\n url: string,\n key: Redacted.Redacted<string>,\n ): Effect.fn.Return<EnvironmentVariables, ConvexClientError> {\n const response = yield* send(\n \"listEnvironmentVariables\",\n \"GET\",\n `${yield* deploymentUrl(\"listEnvironmentVariables\", url)}/list_environment_variables`,\n Redacted.make(`Convex ${Redacted.value(key)}`),\n );\n const result = yield* decode(\n \"listEnvironmentVariables\",\n response,\n Schema.Struct({\n environmentVariables: Schema.Record(Schema.String, Schema.String),\n }),\n );\n return Rec.fromEntries(\n Array.map(\n Rec.toEntries(result.environmentVariables),\n ([name, value]) => [name, Redacted.make(value)],\n ),\n );\n }),\n updateEnvironmentVariables: Effect.fn(\n \"ConvexClient.updateEnvironmentVariables\",\n )(function* (\n url: string,\n key: Redacted.Redacted<string>,\n changes: readonly EnvironmentVariableChange[],\n ) {\n yield* send(\n \"updateEnvironmentVariables\",\n \"POST\",\n `${yield* deploymentUrl(\"updateEnvironmentVariables\", url)}/update_environment_variables`,\n Redacted.make(`Convex ${Redacted.value(key)}`),\n {\n changes: Array.map(changes, ({ name, value }) => ({\n name,\n ...(value === undefined\n ? {}\n : {\n value: Redacted.isRedacted(value)\n ? Redacted.value(value)\n : value,\n }),\n })),\n } satisfies {\n readonly changes: Readonly<\n DeploymentApi.UpdateEnvVarsRequest[\"changes\"]\n >;\n },\n );\n }),\n };\n});\n\nexport class ConvexClient extends Context.Service<\n ConvexClient,\n Effect.Success<ReturnType<typeof make>>\n>()(\"@confect/alchemy/ConvexClient\") {}\n\n/**\n * `mode: \"local\"` sends deployment requests only to a loopback backend over\n * HTTP; the default accepts only Convex cloud HTTPS origins.\n *\n * @stability unstable\n */\nexport const layer = (options?: {\n readonly token?: Redacted.Redacted<string>;\n readonly mode?: ProviderMode;\n}) =>\n Layer.effect(ConvexClient, make(options).pipe(Effect.map(ConvexClient.of)));\n"],"mappings":";;;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,MAAM,SAAS,OAAO,OACpB,4BACA,UACA,OAAO,OAAO,EACZ,sBAAsB,OAAO,OAAO,OAAO,QAAQ,OAAO,MAAM,EAClE,CAAC,CACH;GACA,OAAO,IAAI,YACT,MAAM,IACJ,IAAI,UAAU,OAAO,oBAAoB,IACxC,CAAC,MAAM,WAAW,CAAC,MAAM,SAAS,KAAK,KAAK,CAAC,CAChD,CACF;EACF,CAAC;EACD,4BAA4B,OAAO,GACjC,yCACF,CAAC,CAAC,WACA,KACA,KACA,SACA;GACA,OAAO,KACL,8BACA,QACA,GAAG,OAAO,cAAc,8BAA8B,GAAG,EAAE,gCAC3D,SAAS,KAAK,UAAU,SAAS,MAAM,GAAG,GAAG,GAC7C,EACE,SAAS,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa;IAChD;IACA,GAAI,UAAU,KAAA,IACV,CAAC,IACD,EACE,OAAO,SAAS,WAAW,KAAK,IAC5B,SAAS,MAAM,KAAK,IACpB,MACN;GACN,EAAE,EACJ,CAKF;EACF,CAAC;CACH;AACF,CAAC;AAED,IAAa,eAAb,cAAkC,QAAQ,QAGxC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC;;;;;;;AAQtC,MAAa,SAAS,YAIpB,MAAM,OAAO,cAAc,KAAK,OAAO,CAAC,CAAC,KAAK,OAAO,IAAI,aAAa,EAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"ConvexClient.js","names":["Loopback.isOrigin"],"sources":["../src/ConvexClient.ts"],"sourcesContent":["import type * as DeploymentApi from \"@convex-dev/platform/deploymentApi\";\nimport type * as ManagementApi from \"@convex-dev/platform/managementApi\";\nimport type { ProviderMode } from \"alchemy/ProviderMode\";\nimport * as Config from \"effect/Config\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport * as Stream from \"effect/Stream\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport * as HttpClient from \"effect/http/HttpClient\";\nimport * as HttpClientRequest from \"effect/http/HttpClientRequest\";\nimport type * as HttpClientResponse from \"effect/http/HttpClientResponse\";\nimport * as Loopback from \"./internal/Loopback.js\";\nimport * as String from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\n\nexport type Project = ManagementApi.ProjectResponse;\nexport type CreatedProject = ManagementApi.PlatformCreateProjectResponse;\nexport type Deployment = ManagementApi.PlatformDeploymentResponse;\nexport type DeployKey = Omit<\n ManagementApi.PlatformDeployKeyResponse,\n \"allowedActions\"\n> & {\n readonly allowedActions: readonly string[];\n};\nexport type CreateProjectInput = Pick<\n ManagementApi.PlatformCreateProjectArgs,\n \"projectName\"\n>;\nexport type UpdateProjectInput = Pick<\n ManagementApi.PlatformUpdateProjectArgs,\n \"name\"\n>;\nexport type CreateDeploymentInput = Pick<\n ManagementApi.PlatformCreateDeploymentArgs,\n \"type\" | \"region\" | \"class\" | \"expiresAt\"\n> & { readonly reference: string };\nexport type UpdateDeploymentInput = Pick<\n ManagementApi.PlatformUpdateDeploymentArgs,\n \"reference\" | \"expiresAt\" | \"sendLogsToClient\" | \"class\"\n>;\nexport type CreateDeployKeyInput = ManagementApi.PlatformCreateDeployKeyArgs;\nexport type CreatedDeployKey = {\n readonly deployKey: Redacted.Redacted<\n ManagementApi.PlatformCreateDeployKeyResponse[\"deployKey\"]\n >;\n};\nexport type EnvironmentVariableChange = Omit<\n DeploymentApi.UpdateEnvVarRequest,\n \"value\"\n> & {\n readonly value?:\n | Exclude<DeploymentApi.UpdateEnvVarRequest[\"value\"], undefined>\n | Redacted.Redacted<string>;\n};\nexport type EnvironmentVariables = Readonly<\n Record<\n string,\n Redacted.Redacted<\n DeploymentApi.ListEnvVarsResponse[\"environmentVariables\"][string]\n >\n >\n>;\n\nconst errorFields = {\n operation: Schema.String,\n status: Schema.optionalKey(Schema.Finite),\n serverCode: Schema.optionalKey(Schema.String),\n code: Schema.Literals([\n \"HttpError\",\n \"TransportError\",\n \"InvalidResponse\",\n \"InvalidRequest\",\n \"InvalidPagination\",\n \"InvalidConfiguration\",\n ]),\n};\n\nconst errorMessage = (error: {\n readonly operation: string;\n readonly status?: number;\n readonly code: string;\n readonly serverCode?: string;\n}) => {\n const classification =\n error.status === undefined ? error.code : `${error.status}, ${error.code}`;\n const serverCode =\n error.serverCode === undefined ? \"\" : `, ${error.serverCode}`;\n return `${error.operation} failed (${classification}${serverCode})`;\n};\n\nexport class ConvexApiError extends Schema.TaggedError<\n ConvexApiError,\n { readonly brand: unique symbol }\n>()(\"ConvexApiError\", errorFields) {\n override get message() {\n return errorMessage(this);\n }\n}\n\nexport class ConvexNotFound extends Schema.TaggedError<\n ConvexNotFound,\n { readonly brand: unique symbol }\n>()(\"ConvexNotFound\", errorFields) {\n override get message() {\n return errorMessage(this);\n }\n}\n\nexport class ConvexConflict extends Schema.TaggedError<\n ConvexConflict,\n { readonly brand: unique symbol }\n>()(\"ConvexConflict\", errorFields) {\n override get message() {\n return errorMessage(this);\n }\n}\n\n/**\n * A function the deployment ran failed, with the message Convex reports.\n */\nexport class ConvexFunctionError extends Schema.TaggedError<\n ConvexFunctionError,\n { readonly brand: unique symbol }\n>()(\"ConvexFunctionError\", {\n functionPath: Schema.String,\n errorMessage: Schema.String,\n}) {}\n\nconst FunctionResponse = Schema.Union([\n Schema.Struct({ status: Schema.Literal(\"success\"), value: Schema.Unknown }),\n Schema.Struct({\n status: Schema.Literal(\"error\"),\n errorMessage: Schema.String,\n }),\n]);\n\nexport type ConvexClientError =\n | ConvexApiError\n | ConvexNotFound\n | ConvexConflict;\n\nconst ProjectSchema = Schema.Struct({\n id: Schema.Finite,\n name: Schema.String,\n slug: Schema.String,\n teamId: Schema.Finite,\n teamSlug: Schema.String,\n createTime: Schema.Finite,\n prodDeploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n devDeploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n}) satisfies Schema.Schema<Project>;\n\nconst CreatedProjectSchema = Schema.Struct({\n id: Schema.Finite,\n projectId: Schema.Finite,\n slug: Schema.String,\n deploymentName: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n deploymentUrl: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n}) satisfies Schema.Schema<CreatedProject>;\n\nconst deploymentFields = {\n name: Schema.String,\n createTime: Schema.Finite,\n deploymentType: Schema.Literals([\"dev\", \"prod\", \"preview\", \"custom\"]),\n projectId: Schema.Finite,\n previewIdentifier: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n};\n\nconst DeploymentSchema = Schema.Union([\n Schema.Struct({\n ...deploymentFields,\n kind: Schema.Literal(\"cloud\"),\n id: Schema.Finite,\n lastDeployTime: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n creator: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n region: Schema.Literals([\n \"aws-us-east-1\",\n \"aws-eu-west-1\",\n \"aws-ap-southeast-2\",\n \"aws-ca-central-1\",\n ]),\n isDefault: Schema.Boolean,\n reference: Schema.String,\n dashboardEditConfirmation: Schema.Boolean.pipe(\n Schema.NullOr,\n Schema.optionalKey,\n ),\n deploymentUrl: Schema.String,\n expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n class: Schema.String,\n sendLogsToClient: Schema.Boolean.pipe(Schema.NullOr, Schema.optionalKey),\n }),\n Schema.Struct({\n ...deploymentFields,\n kind: Schema.Literal(\"local\"),\n creator: Schema.Finite,\n port: Schema.Finite,\n deviceName: Schema.String,\n isActive: Schema.Boolean,\n }),\n]) satisfies Schema.Schema<Deployment>;\n\nconst DeployKeySchema = Schema.Struct({\n id: Schema.Finite,\n name: Schema.String,\n creationTime: Schema.Finite,\n lastUsedTime: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n expiresAt: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n creator: Schema.Finite.pipe(Schema.NullOr, Schema.optionalKey),\n managedBy: Schema.Union([\n Schema.Literal(\"vercel\"),\n Schema.Struct({ oauthApp: Schema.String }),\n ]).pipe(Schema.NullOr, Schema.optionalKey),\n allowedActions: Schema.Array(Schema.String),\n}) satisfies Schema.Schema<DeployKey>;\n\nconst ProjectsPageSchema = Schema.Struct({\n items: Schema.Array(ProjectSchema),\n pagination: Schema.Struct({\n hasMore: Schema.Boolean,\n nextCursor: Schema.String.pipe(Schema.NullOr, Schema.optionalKey),\n }),\n});\n\n// Retain at most 8 KiB before parsing an error body. Stop the stream on overflow.\nconst maxErrorBodyBytes = 8 * 1024;\nconst httpFailure = Effect.fn(\"ConvexClient.httpFailure\")(function* (\n operation: string,\n response: HttpClientResponse.HttpClientResponse,\n) {\n const fallback = ConvexApiError.make({\n operation,\n status: response.status,\n code: \"HttpError\",\n });\n const serverCode = yield* response.stream.pipe(\n Stream.mapAccum(\n () => 0,\n (size, bytes) => {\n const total = size + bytes.byteLength;\n return [total, [{ size: total, bytes }]] as const;\n },\n ),\n Stream.mapEffect(({ size, bytes }) =>\n size > maxErrorBodyBytes ? Effect.fail(fallback) : Effect.succeed(bytes),\n ),\n Stream.mkArrayBuffer,\n Effect.timeout(\"5 seconds\"),\n Effect.map((bytes) => new TextDecoder().decode(bytes)),\n Effect.flatMap(\n Schema.decodeEffect(\n Schema.fromJsonString(Schema.Struct({ code: Schema.String })),\n ),\n ),\n Effect.map(({ code }) =>\n /^[A-Za-z][A-Za-z0-9]{0,63}$/.test(code) ? code : undefined,\n ),\n Effect.orElseSucceed(() => undefined),\n );\n const fields = {\n operation,\n status: response.status,\n code: \"HttpError\" as const,\n ...(serverCode === undefined ? {} : { serverCode }),\n };\n if (response.status === 404) return yield* ConvexNotFound.make(fields);\n if (response.status === 409) return yield* ConvexConflict.make(fields);\n return yield* ConvexApiError.make(fields);\n});\n\nconst make = Effect.fn(\"ConvexClient.make\")(function* (options?: {\n readonly token?: Redacted.Redacted<string>;\n readonly mode?: ProviderMode;\n}) {\n const http = yield* HttpClient.HttpClient;\n const managementAuthorization = Effect.gen(function* () {\n const token =\n options?.token ??\n (yield* Config.Redacted(\"CONVEX_ACCESS_TOKEN\").pipe(\n Effect.mapError(() =>\n ConvexApiError.make({\n operation: \"configure\",\n code: \"InvalidConfiguration\",\n }),\n ),\n ));\n return Redacted.make(`Bearer ${Redacted.value(token)}`);\n });\n const baseUrl = \"https://api.convex.dev/v1\";\n\n const send = Effect.fn(\"ConvexClient.request\")(function* (\n operation: string,\n method: \"GET\" | \"POST\" | \"PATCH\",\n url: string,\n authorization: Redacted.Redacted<string>,\n body?: unknown,\n ) {\n let request = HttpClientRequest.make(method)(url).pipe(\n HttpClientRequest.setHeader(\n \"authorization\",\n Redacted.value(authorization),\n ),\n HttpClientRequest.acceptJson,\n );\n if (body !== undefined) {\n request = yield* HttpClientRequest.bodyJson(request, body).pipe(\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"InvalidRequest\" }),\n ),\n );\n }\n const response = yield* http.execute(request).pipe(\n Effect.provideService(FetchHttpClient.RequestInit, {\n redirect: \"manual\",\n }),\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"TransportError\" }),\n ),\n );\n if (response.status < 200 || response.status >= 300)\n return yield* httpFailure(operation, response);\n return response;\n });\n\n const decode = Effect.fn(\"ConvexClient.decode\")(function* <A>(\n operation: string,\n response: HttpClientResponse.HttpClientResponse,\n schema: Schema.Decoder<A>,\n ) {\n const invalidResponse = () =>\n ConvexApiError.make({\n operation,\n status: response.status,\n code: \"InvalidResponse\",\n });\n const body = yield* response.json.pipe(Effect.mapError(invalidResponse));\n return yield* Schema.decodeEffect(schema)(body).pipe(\n Effect.mapError(invalidResponse),\n );\n });\n\n const management = Effect.fn(\"ConvexClient.management\")(function* <A>(\n operation: string,\n method: \"GET\" | \"POST\" | \"PATCH\",\n path: string,\n schema: Schema.Decoder<A>,\n body?: unknown,\n ) {\n const managementAuthorizationValue = yield* managementAuthorization;\n const response = yield* send(\n operation,\n method,\n `${baseUrl}${path}`,\n managementAuthorizationValue,\n body,\n );\n return yield* decode(operation, response, schema);\n });\n\n const managementVoid = Effect.fn(\"ConvexClient.managementVoid\")(function* (\n operation: string,\n method: \"POST\" | \"PATCH\",\n path: string,\n body?: unknown,\n ) {\n const managementAuthorizationValue = yield* managementAuthorization;\n yield* send(\n operation,\n method,\n `${baseUrl}${path}`,\n managementAuthorizationValue,\n body,\n );\n });\n\n const deploymentUrl = Effect.fn(\"ConvexClient.deploymentUrl\")(function* (\n operation: string,\n url: string,\n ) {\n const invalidUrl = () =>\n ConvexApiError.make({ operation, code: \"InvalidRequest\" });\n if (options?.mode === \"local\") {\n if (!Loopback.isOrigin(url)) return yield* invalidUrl();\n return `${url}/api/v1`;\n }\n const parsed = yield* Effect.try({\n try: () => new URL(url),\n catch: invalidUrl,\n });\n if (\n parsed.protocol !== \"https:\" ||\n parsed.username !== \"\" ||\n parsed.password !== \"\" ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.pathname !== \"/\" ||\n !/^[a-z0-9-]+(?:\\.(?:eu-west-1|ap-southeast-2|ca-central-1))?\\.convex\\.cloud$/.test(\n parsed.hostname,\n ) ||\n pipe(url, String.replace(/\\/$/, \"\")) !== parsed.origin\n ) {\n return yield* invalidUrl();\n }\n return `${parsed.origin}/api/v1`;\n });\n\n return {\n /**\n * Run a deployment function with admin authority, internal ones and ones\n * inside a component included.\n */\n runFunction: Effect.fn(\"ConvexClient.runFunction\")(function* (\n url: string,\n key: Redacted.Redacted<string>,\n functionPath: string,\n args: unknown,\n componentPath?: string,\n ) {\n const operation = \"runFunction\";\n const deploymentUrlResult = yield* deploymentUrl(operation, url);\n const origin = pipe(\n deploymentUrlResult,\n String.replace(/\\/api\\/v1$/, \"\"),\n );\n const request = yield* HttpClientRequest.post(\n `${origin}/api/function`,\n ).pipe(\n HttpClientRequest.setHeader(\n \"authorization\",\n `Convex ${Redacted.value(key)}`,\n ),\n HttpClientRequest.acceptJson,\n HttpClientRequest.bodyJson({\n path: functionPath,\n args,\n format: \"json\",\n ...(componentPath === undefined ? {} : { componentPath }),\n }),\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"InvalidRequest\" }),\n ),\n );\n const response = yield* http.execute(request).pipe(\n Effect.provideService(FetchHttpClient.RequestInit, {\n redirect: \"manual\",\n }),\n Effect.mapError(() =>\n ConvexApiError.make({ operation, code: \"TransportError\" }),\n ),\n );\n // Convex answers a function that threw with 560 and its message.\n if (response.status !== 200 && response.status !== 560)\n return yield* httpFailure(operation, response);\n const result = yield* decode(operation, response, FunctionResponse);\n if (result.status === \"error\")\n return yield* ConvexFunctionError.make({\n functionPath,\n errorMessage: result.errorMessage,\n });\n return result.value;\n }),\n listProjects: Effect.fn(\"ConvexClient.listProjects\")(function* (\n teamId: number,\n ) {\n const projects: Project[] = [];\n const seenCursors = new Set<string>();\n let cursor: string | undefined;\n while (true) {\n const page = yield* management(\n \"listProjects\",\n \"GET\",\n `/teams/${teamId}/projects${cursor === undefined ? \"\" : `?cursor=${encodeURIComponent(cursor)}`}`,\n ProjectsPageSchema,\n );\n projects.push(...page.items);\n if (!page.pagination.hasMore) return projects;\n const nextCursor = page.pagination.nextCursor;\n if (\n nextCursor === undefined ||\n nextCursor === null ||\n nextCursor === \"\" ||\n seenCursors.has(nextCursor)\n ) {\n return yield* ConvexApiError.make({\n operation: \"listProjects\",\n code: \"InvalidPagination\",\n });\n }\n seenCursors.add(nextCursor);\n cursor = nextCursor;\n }\n }),\n getProject: Effect.fn(\"ConvexClient.getProject\")((projectId: number) =>\n management(\"getProject\", \"GET\", `/projects/${projectId}`, ProjectSchema),\n ),\n createProject: Effect.fn(\"ConvexClient.createProject\")(\n (teamId: number, input: CreateProjectInput) =>\n management(\n \"createProject\",\n \"POST\",\n `/teams/${teamId}/create_project`,\n CreatedProjectSchema,\n input,\n ),\n ),\n updateProject: Effect.fn(\"ConvexClient.updateProject\")(\n (projectId: number, input: UpdateProjectInput) =>\n management(\n \"updateProject\",\n \"PATCH\",\n `/projects/${projectId}`,\n ProjectSchema,\n input,\n ),\n ),\n deleteProject: Effect.fn(\"ConvexClient.deleteProject\")(\n (projectId: number) =>\n managementVoid(\n \"deleteProject\",\n \"POST\",\n `/projects/${projectId}/delete`,\n ),\n ),\n listDeployments: Effect.fn(\"ConvexClient.listDeployments\")(\n (projectId: number) =>\n management(\n \"listDeployments\",\n \"GET\",\n `/projects/${projectId}/list_deployments`,\n Schema.Array(DeploymentSchema),\n ),\n ),\n getDeployment: Effect.fn(\"ConvexClient.getDeployment\")((name: string) =>\n management(\n \"getDeployment\",\n \"GET\",\n `/deployments/${encodeURIComponent(name)}`,\n DeploymentSchema,\n ),\n ),\n createDeployment: Effect.fn(\"ConvexClient.createDeployment\")(\n (projectId: number, input: CreateDeploymentInput) =>\n management(\n \"createDeployment\",\n \"POST\",\n `/projects/${projectId}/create_deployment`,\n DeploymentSchema,\n input,\n ),\n ),\n updateDeployment: Effect.fn(\"ConvexClient.updateDeployment\")(\n (name: string, input: UpdateDeploymentInput) =>\n managementVoid(\n \"updateDeployment\",\n \"PATCH\",\n `/deployments/${encodeURIComponent(name)}`,\n input,\n ),\n ),\n deleteDeployment: Effect.fn(\"ConvexClient.deleteDeployment\")(\n (name: string) =>\n managementVoid(\n \"deleteDeployment\",\n \"POST\",\n `/deployments/${encodeURIComponent(name)}/delete`,\n ),\n ),\n createDeployKey: Effect.fn(\"ConvexClient.createDeployKey\")(function* (\n name: string,\n input: CreateDeployKeyInput,\n ): Effect.fn.Return<CreatedDeployKey, ConvexClientError> {\n const response = yield* management(\n \"createDeployKey\",\n \"POST\",\n `/deployments/${encodeURIComponent(name)}/create_deploy_key`,\n Schema.Struct({ deployKey: Schema.String }),\n input,\n );\n return { deployKey: Redacted.make(response.deployKey) };\n }),\n listDeployKeys: Effect.fn(\"ConvexClient.listDeployKeys\")((name: string) =>\n management(\n \"listDeployKeys\",\n \"GET\",\n `/deployments/${encodeURIComponent(name)}/list_deploy_keys`,\n Schema.Array(DeployKeySchema),\n ),\n ),\n deleteDeployKey: Effect.fn(\"ConvexClient.deleteDeployKey\")(\n (name: string, id: string | Redacted.Redacted<string>) =>\n managementVoid(\n \"deleteDeployKey\",\n \"POST\",\n `/deployments/${encodeURIComponent(name)}/delete_deploy_key`,\n {\n id: Redacted.isRedacted(id) ? Redacted.value(id) : id,\n } satisfies ManagementApi.PlatformDeleteDeployKeyArgs,\n ),\n ),\n listEnvironmentVariables: Effect.fn(\n \"ConvexClient.listEnvironmentVariables\",\n )(function* (\n url: string,\n key: Redacted.Redacted<string>,\n ): Effect.fn.Return<EnvironmentVariables, ConvexClientError> {\n const response = yield* send(\n \"listEnvironmentVariables\",\n \"GET\",\n `${yield* deploymentUrl(\"listEnvironmentVariables\", url)}/list_environment_variables`,\n Redacted.make(`Convex ${Redacted.value(key)}`),\n );\n const result = yield* decode(\n \"listEnvironmentVariables\",\n response,\n Schema.Struct({\n environmentVariables: Schema.Record(Schema.String, Schema.String),\n }),\n );\n return Rec.fromEntries(\n Array.map(\n Rec.toEntries(result.environmentVariables),\n ([name, value]) => [name, Redacted.make(value)],\n ),\n );\n }),\n updateEnvironmentVariables: Effect.fn(\n \"ConvexClient.updateEnvironmentVariables\",\n )(function* (\n url: string,\n key: Redacted.Redacted<string>,\n changes: readonly EnvironmentVariableChange[],\n ) {\n yield* send(\n \"updateEnvironmentVariables\",\n \"POST\",\n `${yield* deploymentUrl(\"updateEnvironmentVariables\", url)}/update_environment_variables`,\n Redacted.make(`Convex ${Redacted.value(key)}`),\n {\n changes: Array.map(changes, ({ name, value }) => ({\n name,\n ...(value === undefined\n ? {}\n : {\n value: Redacted.isRedacted(value)\n ? Redacted.value(value)\n : value,\n }),\n })),\n } satisfies {\n readonly changes: Readonly<\n DeploymentApi.UpdateEnvVarsRequest[\"changes\"]\n >;\n },\n );\n }),\n };\n});\n\nexport class ConvexClient extends Context.Service<\n ConvexClient,\n Effect.Success<ReturnType<typeof make>>\n>()(\"@confect/alchemy/ConvexClient\") {}\n\n/**\n * `mode: \"local\"` sends deployment requests only to a loopback backend over\n * HTTP; the default accepts only Convex cloud HTTPS origins.\n *\n * @stability unstable\n */\nexport const layer = (options?: {\n readonly token?: Redacted.Redacted<string>;\n readonly mode?: ProviderMode;\n}) =>\n Layer.effect(ConvexClient, make(options).pipe(Effect.map(ConvexClient.of)));\n"],"mappings":";;;;;;;;;;;;;;;;AAoEA,MAAM,cAAc;CAClB,WAAW,OAAO;CAClB,QAAQ,OAAO,YAAY,OAAO,MAAM;CACxC,YAAY,OAAO,YAAY,OAAO,MAAM;CAC5C,MAAM,OAAO,SAAS;EACpB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAEA,MAAM,gBAAgB,UAKhB;CACJ,MAAM,iBACJ,MAAM,WAAW,KAAA,IAAY,MAAM,OAAO,GAAG,MAAM,OAAO,IAAI,MAAM;CACtE,MAAM,aACJ,MAAM,eAAe,KAAA,IAAY,KAAK,KAAK,MAAM;CACnD,OAAO,GAAG,MAAM,UAAU,WAAW,iBAAiB,WAAW;AACnE;AAEA,IAAa,iBAAb,cAAoC,OAAO,YAGzC,CAAC,CAAC,kBAAkB,WAAW,CAAC,CAAC;CACjC,IAAa,UAAU;EACrB,OAAO,aAAa,IAAI;CAC1B;AACF;AAEA,IAAa,iBAAb,cAAoC,OAAO,YAGzC,CAAC,CAAC,kBAAkB,WAAW,CAAC,CAAC;CACjC,IAAa,UAAU;EACrB,OAAO,aAAa,IAAI;CAC1B;AACF;AAEA,IAAa,iBAAb,cAAoC,OAAO,YAGzC,CAAC,CAAC,kBAAkB,WAAW,CAAC,CAAC;CACjC,IAAa,UAAU;EACrB,OAAO,aAAa,IAAI;CAC1B;AACF;;;;AAKA,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CACzB,cAAc,OAAO;CACrB,cAAc,OAAO;AACvB,CAAC,CAAC,CAAC,CAAC;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AAI,GACrD,CACF,CACJ;EACA,0BAA0B,OAAO,GAC/B,uCACF,CAAC,CAAC,WACA,KACA,KAC2D;GAC3D,MAAM,WAAW,OAAO,KACtB,4BACA,OACA,GAAG,OAAO,cAAc,4BAA4B,GAAG,EAAE,8BACzD,SAAS,KAAK,UAAU,SAAS,MAAM,GAAG,GAAG,CAC/C;GACA,MAAM,SAAS,OAAO,OACpB,4BACA,UACA,OAAO,OAAO,EACZ,sBAAsB,OAAO,OAAO,OAAO,QAAQ,OAAO,MAAM,EAClE,CAAC,CACH;GACA,OAAO,IAAI,YACT,MAAM,IACJ,IAAI,UAAU,OAAO,oBAAoB,IACxC,CAAC,MAAM,WAAW,CAAC,MAAM,SAAS,KAAK,KAAK,CAAC,CAChD,CACF;EACF,CAAC;EACD,4BAA4B,OAAO,GACjC,yCACF,CAAC,CAAC,WACA,KACA,KACA,SACA;GACA,OAAO,KACL,8BACA,QACA,GAAG,OAAO,cAAc,8BAA8B,GAAG,EAAE,gCAC3D,SAAS,KAAK,UAAU,SAAS,MAAM,GAAG,GAAG,GAC7C,EACE,SAAS,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa;IAChD;IACA,GAAI,UAAU,KAAA,IACV,CAAC,IACD,EACE,OAAO,SAAS,WAAW,KAAK,IAC5B,SAAS,MAAM,KAAK,IACpB,MACN;GACN,EAAE,EACJ,CAKF;EACF,CAAC;CACH;AACF,CAAC;AAED,IAAa,eAAb,cAAkC,QAAQ,QAGxC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC;;;;;;;AAQtC,MAAa,SAAS,YAIpB,MAAM,OAAO,cAAc,KAAK,OAAO,CAAC,CAAC,KAAK,OAAO,IAAI,aAAa,EAAE,CAAC,CAAC"}
|
package/dist/Deployment.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateDeploymentType, RegionName } from "@convex-dev/platform/managementApi";
|
|
1
|
+
import type { CreateDeploymentType, DeploymentClass, RegionName } from "@convex-dev/platform/managementApi";
|
|
2
2
|
import { OwnedBySomeoneElse } from "alchemy/AdoptPolicy";
|
|
3
3
|
import * as Provider from "alchemy/Provider";
|
|
4
4
|
import { Resource } from "alchemy/Resource";
|
|
@@ -12,6 +12,12 @@ export interface DeploymentProps {
|
|
|
12
12
|
readonly type: CreateDeploymentType;
|
|
13
13
|
readonly reference?: string;
|
|
14
14
|
readonly region?: RegionName;
|
|
15
|
+
readonly class?: DeploymentClass;
|
|
16
|
+
/**
|
|
17
|
+
* Safe integer milliseconds since the Unix epoch. Omit to preserve the
|
|
18
|
+
* current cloud expiry; only null clears it.
|
|
19
|
+
*/
|
|
20
|
+
readonly expiresAt?: number | null;
|
|
15
21
|
}
|
|
16
22
|
export interface DeploymentAttributes {
|
|
17
23
|
readonly projectId: number;
|
|
@@ -23,6 +29,14 @@ export interface DeploymentAttributes {
|
|
|
23
29
|
* Always set in the cloud; a local deployment echoes the requested region.
|
|
24
30
|
*/
|
|
25
31
|
readonly region?: RegionName;
|
|
32
|
+
/**
|
|
33
|
+
* Always set in the cloud; local deployments do not have a cloud class.
|
|
34
|
+
*/
|
|
35
|
+
readonly class?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Cloud expiry in milliseconds since the Unix epoch, or null when unset.
|
|
38
|
+
*/
|
|
39
|
+
readonly expiresAt?: number | null;
|
|
26
40
|
}
|
|
27
41
|
export type Deployment = Resource<"Convex.Deployment", DeploymentProps, DeploymentAttributes, never, Providers>;
|
|
28
42
|
export declare const Deployment: import("alchemy").ResourceClass<Deployment>;
|
|
@@ -51,6 +65,14 @@ declare const AmbiguousDeployment_base: Schema.Class<AmbiguousDeployment, Schema
|
|
|
51
65
|
}>;
|
|
52
66
|
export declare class AmbiguousDeployment extends AmbiguousDeployment_base {
|
|
53
67
|
}
|
|
68
|
+
declare const InvalidDeploymentExpiry_base: Schema.Class<InvalidDeploymentExpiry, Schema.TaggedStruct<"InvalidDeploymentExpiry", {
|
|
69
|
+
readonly requested: Schema.String;
|
|
70
|
+
}>, import("effect/Cause").YieldableError & {
|
|
71
|
+
readonly brand: unique symbol;
|
|
72
|
+
}>;
|
|
73
|
+
export declare class InvalidDeploymentExpiry extends InvalidDeploymentExpiry_base {
|
|
74
|
+
get message(): string;
|
|
75
|
+
}
|
|
54
76
|
export declare const provider: Effect.Effect<{
|
|
55
77
|
diff: (args_0: {
|
|
56
78
|
id: string;
|
|
@@ -63,7 +85,7 @@ export declare const provider: Effect.Effect<{
|
|
|
63
85
|
output: DeploymentAttributes | undefined;
|
|
64
86
|
}) => Effect.Effect<{
|
|
65
87
|
action: "update";
|
|
66
|
-
} | undefined, import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | DeploymentIdentityChange | UnsupportedLocalDeployment, never>;
|
|
88
|
+
} | undefined, import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | DeploymentIdentityChange | InvalidDeploymentExpiry | UnsupportedLocalDeployment, never>;
|
|
67
89
|
read: (args_0: {
|
|
68
90
|
id: string;
|
|
69
91
|
fqn: string;
|
|
@@ -78,6 +100,8 @@ export declare const provider: Effect.Effect<{
|
|
|
78
100
|
type: "custom" | "dev" | "preview" | "prod";
|
|
79
101
|
url: string;
|
|
80
102
|
region: "aws-ap-southeast-2" | "aws-ca-central-1" | "aws-eu-west-1" | "aws-us-east-1";
|
|
103
|
+
class: string;
|
|
104
|
+
expiresAt: number | null;
|
|
81
105
|
} | undefined, AmbiguousDeployment | import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | import("./ConvexClient.js").ConvexNotFound | UnsupportedLocalDeployment, never>;
|
|
82
106
|
reconcile: (args_0: {
|
|
83
107
|
id: string;
|
|
@@ -95,7 +119,9 @@ export declare const provider: Effect.Effect<{
|
|
|
95
119
|
type: "custom" | "dev" | "preview" | "prod";
|
|
96
120
|
url: string;
|
|
97
121
|
region: "aws-ap-southeast-2" | "aws-ca-central-1" | "aws-eu-west-1" | "aws-us-east-1";
|
|
98
|
-
|
|
122
|
+
class: string;
|
|
123
|
+
expiresAt: number | null;
|
|
124
|
+
}, AmbiguousDeployment | import("./ConvexClient.js").ConvexApiError | import("./ConvexClient.js").ConvexConflict | import("./ConvexClient.js").ConvexNotFound | DeploymentIdentityChange | InvalidDeploymentExpiry | import("./internal/Lifecycle.js").LifecycleStateError | OwnedBySomeoneElse | import("alchemy/State/State").StateStoreError | UnsupportedLocalDeployment, never>;
|
|
99
125
|
delete: (args_0: {
|
|
100
126
|
id: string;
|
|
101
127
|
fqn: string;
|
package/dist/Deployment.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Deployment.d.ts","sources":["../src/Deployment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,
|
|
1
|
+
{"version":3,"file":"Deployment.d.ts","sources":["../src/Deployment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EAEf,UAAU,EACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAW,MAAM,qBAAqB,CAAC;AAGlE,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMhD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;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C,CAAC"}
|
package/dist/Deployment.js
CHANGED
|
@@ -25,6 +25,14 @@ var AmbiguousDeployment = class extends Schema.TaggedError()("AmbiguousDeploymen
|
|
|
25
25
|
projectId: Schema.Finite,
|
|
26
26
|
reference: Schema.String
|
|
27
27
|
}) {};
|
|
28
|
+
var InvalidDeploymentExpiry = class extends Schema.TaggedError()("InvalidDeploymentExpiry", { requested: Schema.String }) {
|
|
29
|
+
get message() {
|
|
30
|
+
return "Deployment expiresAt must be a safe integer timestamp in milliseconds, or null to clear the expiry.";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const validateExpiry = Effect.fn("Deployment.validateExpiry")(function* ({ expiresAt }) {
|
|
34
|
+
if (expiresAt != null && !Number.isSafeInteger(expiresAt)) return yield* InvalidDeploymentExpiry.make({ requested: String(expiresAt) });
|
|
35
|
+
});
|
|
28
36
|
const provider = Effect.gen(function* () {
|
|
29
37
|
const client = yield* ConvexClient;
|
|
30
38
|
const attributes = Effect.fn("Deployment.attributes")(function* (deployment) {
|
|
@@ -35,7 +43,9 @@ const provider = Effect.gen(function* () {
|
|
|
35
43
|
reference: deployment.reference,
|
|
36
44
|
type: deployment.deploymentType,
|
|
37
45
|
url: deployment.deploymentUrl,
|
|
38
|
-
region: deployment.region
|
|
46
|
+
region: deployment.region,
|
|
47
|
+
class: deployment.class,
|
|
48
|
+
expiresAt: deployment.expiresAt ?? null
|
|
39
49
|
};
|
|
40
50
|
});
|
|
41
51
|
const find = Effect.fn("Deployment.find")(function* (projectId, reference) {
|
|
@@ -61,13 +71,16 @@ const provider = Effect.gen(function* () {
|
|
|
61
71
|
});
|
|
62
72
|
return {
|
|
63
73
|
diff: Effect.fn("Deployment.diff")(function* ({ news, output }) {
|
|
64
|
-
if (!isResolved(news)
|
|
74
|
+
if (!isResolved(news)) return;
|
|
75
|
+
yield* validateExpiry(news);
|
|
76
|
+
if (output === void 0) return;
|
|
77
|
+
const expiresAt = news.expiresAt;
|
|
65
78
|
yield* validate(output, news);
|
|
66
79
|
const deployment = yield* client.getDeployment(output.name).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void));
|
|
67
80
|
if (deployment === void 0) return { action: "update" };
|
|
68
81
|
const current = yield* attributes(deployment);
|
|
69
82
|
yield* validate(current, news);
|
|
70
|
-
if ((news.reference ?? output.reference) !== current.reference) return { action: "update" };
|
|
83
|
+
if ((news.reference ?? output.reference) !== current.reference || news.class !== void 0 && news.class !== current.class || expiresAt !== void 0 && expiresAt !== (current.expiresAt ?? null)) return { action: "update" };
|
|
71
84
|
}),
|
|
72
85
|
read: Effect.fn("Deployment.read")(function* ({ fqn, instanceId, olds, output }) {
|
|
73
86
|
if (output !== void 0) {
|
|
@@ -79,10 +92,12 @@ const provider = Effect.gen(function* () {
|
|
|
79
92
|
return deployment !== void 0 ? yield* Effect.map(attributes(deployment), Unowned) : void 0;
|
|
80
93
|
}),
|
|
81
94
|
reconcile: Effect.fn("Deployment.reconcile")(function* ({ fqn, instanceId, news, output }) {
|
|
95
|
+
yield* validateExpiry(news);
|
|
82
96
|
if (output === void 0) yield* checkpointCreate(fqn, instanceId, news);
|
|
83
97
|
if (output !== void 0) yield* validate(output, news);
|
|
84
98
|
let deployment = output !== void 0 ? yield* client.getDeployment(output.name).pipe(Effect.catchTag("ConvexNotFound", () => Effect.void)) : void 0;
|
|
85
99
|
const reference = news.reference ?? output?.reference ?? (yield* resourceName("deployment", fqn, instanceId));
|
|
100
|
+
const expiresAt = news.expiresAt;
|
|
86
101
|
if (deployment === void 0) {
|
|
87
102
|
const existing = yield* find(news.projectId, reference);
|
|
88
103
|
if (existing !== void 0 && !(yield* shouldAdopt(fqn))) return yield* new OwnedBySomeoneElse({
|
|
@@ -98,19 +113,27 @@ const provider = Effect.gen(function* () {
|
|
|
98
113
|
} else deployment = yield* client.createDeployment(news.projectId, {
|
|
99
114
|
type: news.type,
|
|
100
115
|
reference,
|
|
101
|
-
...news.region === void 0 ? {} : { region: news.region }
|
|
116
|
+
...news.region === void 0 ? {} : { region: news.region },
|
|
117
|
+
...news.class === void 0 ? {} : { class: news.class },
|
|
118
|
+
...expiresAt === void 0 ? {} : { expiresAt }
|
|
102
119
|
});
|
|
103
120
|
}
|
|
104
121
|
const current = yield* attributes(deployment);
|
|
105
122
|
yield* validate(current, news);
|
|
106
|
-
if (current.reference !== reference) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
if (current.reference !== reference || news.class !== void 0 && news.class !== current.class || expiresAt !== void 0 && expiresAt !== (current.expiresAt ?? null)) {
|
|
124
|
+
if (current.reference !== reference) {
|
|
125
|
+
const existing = yield* find(news.projectId, reference);
|
|
126
|
+
if (existing !== void 0 && existing.name !== current.name) return yield* new OwnedBySomeoneElse({
|
|
127
|
+
message: "The requested deployment reference is already in use.",
|
|
128
|
+
resourceType: Deployment.Type,
|
|
129
|
+
physicalName: reference
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
yield* client.updateDeployment(current.name, {
|
|
133
|
+
reference,
|
|
134
|
+
...news.class === void 0 || news.class === current.class ? {} : { class: news.class },
|
|
135
|
+
...expiresAt === void 0 || expiresAt === (current.expiresAt ?? null) ? {} : { expiresAt }
|
|
112
136
|
});
|
|
113
|
-
yield* client.updateDeployment(current.name, { reference });
|
|
114
137
|
deployment = yield* client.getDeployment(current.name);
|
|
115
138
|
}
|
|
116
139
|
return yield* attributes(deployment);
|
|
@@ -134,9 +157,10 @@ const localLayer = LocalProvider.make(Deployment, new URL(`./internal/LocalSidec
|
|
|
134
157
|
const directory = yield* dataDirectories;
|
|
135
158
|
return {
|
|
136
159
|
resolveConfig: Effect.fn("Deployment.localConfig")(function* ({ fqn, instanceId, news }) {
|
|
160
|
+
const { class: _class, expiresAt: _expiresAt, ...props } = news;
|
|
137
161
|
return {
|
|
138
162
|
name: yield* resourceName("deployment", fqn, instanceId),
|
|
139
|
-
props
|
|
163
|
+
props
|
|
140
164
|
};
|
|
141
165
|
}),
|
|
142
166
|
start: Effect.fn("Deployment.localStart")(function* ({ config, invalidate }) {
|
|
@@ -158,6 +182,6 @@ const localLayer = LocalProvider.make(Deployment, new URL(`./internal/LocalSidec
|
|
|
158
182
|
};
|
|
159
183
|
}));
|
|
160
184
|
const layer = Provider.effect(Deployment, provider);
|
|
161
|
-
export { AmbiguousDeployment, Deployment, DeploymentIdentityChange, UnsupportedLocalDeployment, layer, localLayer, provider };
|
|
185
|
+
export { AmbiguousDeployment, Deployment, DeploymentIdentityChange, InvalidDeploymentExpiry, UnsupportedLocalDeployment, layer, localLayer, provider };
|
|
162
186
|
|
|
163
187
|
//# sourceMappingURL=Deployment.js.map
|
package/dist/Deployment.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Deployment.js","names":[],"sources":["../src/Deployment.ts"],"sourcesContent":["import type {\n CreateDeploymentType,\n PlatformDeploymentResponse,\n RegionName,\n} from \"@convex-dev/platform/managementApi\";\nimport { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as LocalProvider from \"alchemy/Local/LocalProvider\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport { moduleExtension } from \"alchemy/Util/Node\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Schema from \"effect/Schema\";\n\nimport { ConvexClient } from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { resourceName } from \"./internal/ResourceIdentity.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport { boot, dataDirectories, remove } from \"./internal/LocalBackend.js\";\nimport * as Array from \"effect/Array\";\n\nexport interface DeploymentProps {\n readonly projectId: number;\n readonly type: CreateDeploymentType;\n readonly reference?: string;\n readonly region?: RegionName;\n}\n\nexport interface DeploymentAttributes {\n readonly projectId: number;\n readonly name: string;\n readonly reference: string;\n readonly type: CreateDeploymentType;\n readonly url: string;\n /**\n * Always set in the cloud; a local deployment echoes the requested region.\n */\n readonly region?: RegionName;\n}\n\nexport type Deployment = Resource<\n \"Convex.Deployment\",\n DeploymentProps,\n DeploymentAttributes,\n never,\n Providers\n>;\nexport const Deployment = Resource<Deployment>(\"Convex.Deployment\", {\n defaultRemovalPolicy: \"retain\",\n});\n\nexport class DeploymentIdentityChange extends Schema.TaggedError<\n DeploymentIdentityChange,\n { readonly brand: unique symbol }\n>()(\"DeploymentIdentityChange\", {\n deploymentName: Schema.String,\n field: Schema.String,\n current: Schema.String,\n requested: Schema.String,\n}) {}\n\nexport class UnsupportedLocalDeployment extends Schema.TaggedError<\n UnsupportedLocalDeployment,\n { readonly brand: unique symbol }\n>()(\"UnsupportedLocalDeployment\", { deploymentName: Schema.String }) {}\n\nexport class AmbiguousDeployment extends Schema.TaggedError<\n AmbiguousDeployment,\n { readonly brand: unique symbol }\n>()(\"AmbiguousDeployment\", {\n projectId: Schema.Finite,\n reference: Schema.String,\n}) {}\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient;\n const attributes = Effect.fn(\"Deployment.attributes\")(function* (\n deployment: PlatformDeploymentResponse,\n ) {\n if (deployment.kind !== \"cloud\")\n return yield* UnsupportedLocalDeployment.make({\n deploymentName: deployment.name,\n });\n return {\n projectId: deployment.projectId,\n name: deployment.name,\n reference: deployment.reference,\n type: deployment.deploymentType,\n url: deployment.deploymentUrl,\n region: deployment.region,\n } satisfies DeploymentAttributes;\n });\n const find = Effect.fn(\"Deployment.find\")(function* (\n projectId: number,\n reference: string,\n ) {\n const deployments = yield* client.listDeployments(projectId);\n const matches = Array.filter(\n deployments,\n (deployment) =>\n deployment.kind === \"cloud\" && deployment.reference === reference,\n );\n if (matches.length > 1)\n return yield* AmbiguousDeployment.make({ projectId, reference });\n return matches[0];\n });\n const validate = Effect.fn(\"Deployment.validate\")(function* (\n current: DeploymentAttributes,\n news: DeploymentProps,\n ) {\n for (const field of [\"projectId\", \"type\", \"region\"] as const) {\n if (news[field] !== undefined && current[field] !== news[field])\n return yield* DeploymentIdentityChange.make({\n deploymentName: current.name,\n field,\n current: String(current[field]),\n requested: String(news[field]),\n });\n }\n });\n return {\n diff: Effect.fn(\"Deployment.diff\")(function* ({ news, output }) {\n if (!isResolved(news) || output === undefined) return;\n yield* validate(output, news);\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (deployment === undefined) return { action: \"update\" };\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if ((news.reference ?? output.reference) !== current.reference)\n return { action: \"update\" };\n }),\n read: Effect.fn(\"Deployment.read\")(function* ({\n fqn,\n instanceId,\n olds,\n output,\n }) {\n if (output !== undefined) {\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n return deployment !== undefined\n ? yield* attributes(deployment)\n : undefined;\n }\n if (olds.projectId === undefined) return;\n const deployment = yield* find(\n olds.projectId,\n olds.reference ?? (yield* resourceName(\"deployment\", fqn, instanceId)),\n );\n return deployment !== undefined\n ? yield* Effect.map(attributes(deployment), Unowned)\n : undefined;\n }),\n reconcile: Effect.fn(\"Deployment.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);\n if (output !== undefined) yield* validate(output, news);\n let deployment =\n output !== undefined\n ? yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void))\n : undefined;\n const reference =\n news.reference ??\n output?.reference ??\n (yield* resourceName(\"deployment\", fqn, instanceId));\n if (deployment === undefined) {\n const existing = yield* find(news.projectId, reference);\n if (existing !== undefined && !(yield* shouldAdopt(fqn)))\n return yield* new OwnedBySomeoneElse({\n message: \"An existing deployment requires explicit adoption.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n if (existing !== undefined) {\n const adopted = yield* attributes(existing);\n yield* validate(adopted, news);\n yield* checkpointCreate(fqn, instanceId, news, adopted);\n deployment = existing;\n } else {\n deployment = yield* client.createDeployment(news.projectId, {\n type: news.type,\n reference,\n ...(news.region === undefined ? {} : { region: news.region }),\n });\n }\n }\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if (current.reference !== reference) {\n const existing = yield* find(news.projectId, reference);\n if (existing !== undefined && existing.name !== current.name)\n return yield* new OwnedBySomeoneElse({\n message: \"The requested deployment reference is already in use.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n yield* client.updateDeployment(current.name, {\n reference,\n });\n deployment = yield* client.getDeployment(current.name);\n }\n return yield* attributes(deployment);\n }),\n delete: Effect.fn(\"Deployment.delete\")(function* ({ output }) {\n yield* client\n .deleteDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<Deployment>;\n});\n\ninterface LocalConfig {\n readonly name: string;\n readonly props: DeploymentProps;\n}\n\n/**\n * Under `alchemy dev` a deployment is a local Convex backend this provider\n * owns. Alchemy's dev sidecar hosts it, so the backend keeps running across\n * reloads of the stack and stops when the dev session ends. Its data lives in\n * `.alchemy/convex/<stack>/<stage>/<name>` and is removed only when the\n * deployment is destroyed.\n *\n * @stability unstable\n */\nexport const localLayer = LocalProvider.make(\n Deployment,\n new URL(\n `./internal/LocalSidecar${moduleExtension(import.meta.url)}`,\n import.meta.url,\n ).href,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const directory = yield* dataDirectories;\n return {\n resolveConfig: Effect.fn(\"Deployment.localConfig\")(function* ({\n fqn,\n instanceId,\n news,\n }) {\n return {\n name: yield* resourceName(\"deployment\", fqn, instanceId),\n props: news,\n } satisfies LocalConfig;\n }),\n start: Effect.fn(\"Deployment.localStart\")(function* ({\n config,\n invalidate,\n }) {\n const backend = yield* boot(config.name, directory(config.name));\n yield* backend.exited.pipe(\n Effect.andThen(invalidate),\n Effect.forkScoped,\n );\n return {\n projectId: config.props.projectId,\n name: config.name,\n reference: config.props.reference ?? config.name,\n type: config.props.type,\n url: backend.url,\n ...(config.props.region === undefined\n ? {}\n : { region: config.props.region }),\n } satisfies DeploymentAttributes;\n }),\n stop: Effect.fn(\"Deployment.localStop\")(function* ({ fqn, instanceId }) {\n const name = yield* resourceName(\"deployment\", fqn, instanceId);\n yield* remove(name, directory(name)).pipe(\n Effect.provideService(FileSystem.FileSystem, fs),\n );\n }),\n } satisfies LocalProvider.LocalProviderSpec<\n Deployment,\n LocalConfig,\n Effect.Services<ReturnType<typeof boot>>\n >;\n }),\n);\n\nexport const layer = Provider.effect(Deployment, provider);\n"],"mappings":";;;;;;;;;;;;;;;AAgDA,MAAa,aAAa,SAAqB,qBAAqB,EAClE,sBAAsB,SACxB,CAAC;AAED,IAAa,2BAAb,cAA8C,OAAO,YAGnD,CAAC,CAAC,4BAA4B;CAC9B,gBAAgB,OAAO;CACvB,OAAO,OAAO;CACd,SAAS,OAAO;CAChB,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,6BAAb,cAAgD,OAAO,YAGrD,CAAC,CAAC,8BAA8B,EAAE,gBAAgB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtE,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CACzB,WAAW,OAAO;CAClB,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAa,WAAW,OAAO,IAAI,aAAa;CAC9C,MAAM,SAAS,OAAO;CACtB,MAAM,aAAa,OAAO,GAAG,uBAAuB,CAAC,CAAC,WACpD,YACA;EACA,IAAI,WAAW,SAAS,SACtB,OAAO,OAAO,2BAA2B,KAAK,EAC5C,gBAAgB,WAAW,KAC7B,CAAC;EACH,OAAO;GACL,WAAW,WAAW;GACtB,MAAM,WAAW;GACjB,WAAW,WAAW;GACtB,MAAM,WAAW;GACjB,KAAK,WAAW;GAChB,QAAQ,WAAW;EACrB;CACF,CA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OAAO,UACT;GACA,OAAO;IACL,WAAW,OAAO,MAAM;IACxB,MAAM,OAAO;IACb,WAAW,OAAO,MAAM,aAAa,OAAO;IAC5C,MAAM,OAAO,MAAM;IACnB,KAAK,QAAQ;IACb,GAAI,OAAO,MAAM,WAAW,KAAA,IACxB,CAAC,IACD,EAAE,QAAQ,OAAO,MAAM,OAAO;GACpC;EACF,CAAC;EACD,MAAM,OAAO,GAAG,sBAAsB,CAAC,CAAC,WAAW,EAAE,KAAK,cAAc;GACtE,MAAM,OAAO,OAAO,aAAa,cAAc,KAAK,UAAU;GAC9D,OAAO,OAAO,MAAM,UAAU,IAAI,CAAC,CAAC,CAAC,KACnC,OAAO,eAAe,WAAW,YAAY,EAAE,CACjD;EACF,CAAC;CACH;AAKF,CAAC,CACH;AAEA,MAAa,QAAQ,SAAS,OAAO,YAAY,QAAQ"}
|
|
1
|
+
{"version":3,"file":"Deployment.js","names":[],"sources":["../src/Deployment.ts"],"sourcesContent":["import type {\n CreateDeploymentType,\n DeploymentClass,\n PlatformDeploymentResponse,\n RegionName,\n} from \"@convex-dev/platform/managementApi\";\nimport { OwnedBySomeoneElse, Unowned } from \"alchemy/AdoptPolicy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as LocalProvider from \"alchemy/Local/LocalProvider\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Resource } from \"alchemy/Resource\";\nimport { moduleExtension } from \"alchemy/Util/Node\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Schema from \"effect/Schema\";\n\nimport { ConvexClient } from \"./ConvexClient.js\";\nimport type { Providers } from \"./Providers.js\";\nimport { resourceName } from \"./internal/ResourceIdentity.js\";\nimport { checkpointCreate, shouldAdopt } from \"./internal/Lifecycle.js\";\nimport { boot, dataDirectories, remove } from \"./internal/LocalBackend.js\";\nimport * as Array from \"effect/Array\";\n\nexport interface DeploymentProps {\n readonly projectId: number;\n readonly type: CreateDeploymentType;\n readonly reference?: string;\n readonly region?: RegionName;\n readonly class?: DeploymentClass;\n /**\n * Safe integer milliseconds since the Unix epoch. Omit to preserve the\n * current cloud expiry; only null clears it.\n */\n readonly expiresAt?: number | null;\n}\n\nexport interface DeploymentAttributes {\n readonly projectId: number;\n readonly name: string;\n readonly reference: string;\n readonly type: CreateDeploymentType;\n readonly url: string;\n /**\n * Always set in the cloud; a local deployment echoes the requested region.\n */\n readonly region?: RegionName;\n /**\n * Always set in the cloud; local deployments do not have a cloud class.\n */\n readonly class?: string;\n /**\n * Cloud expiry in milliseconds since the Unix epoch, or null when unset.\n */\n readonly expiresAt?: number | null;\n}\n\nexport type Deployment = Resource<\n \"Convex.Deployment\",\n DeploymentProps,\n DeploymentAttributes,\n never,\n Providers\n>;\nexport const Deployment = Resource<Deployment>(\"Convex.Deployment\", {\n defaultRemovalPolicy: \"retain\",\n});\n\nexport class DeploymentIdentityChange extends Schema.TaggedError<\n DeploymentIdentityChange,\n { readonly brand: unique symbol }\n>()(\"DeploymentIdentityChange\", {\n deploymentName: Schema.String,\n field: Schema.String,\n current: Schema.String,\n requested: Schema.String,\n}) {}\n\nexport class UnsupportedLocalDeployment extends Schema.TaggedError<\n UnsupportedLocalDeployment,\n { readonly brand: unique symbol }\n>()(\"UnsupportedLocalDeployment\", { deploymentName: Schema.String }) {}\n\nexport class AmbiguousDeployment extends Schema.TaggedError<\n AmbiguousDeployment,\n { readonly brand: unique symbol }\n>()(\"AmbiguousDeployment\", {\n projectId: Schema.Finite,\n reference: Schema.String,\n}) {}\n\nexport class InvalidDeploymentExpiry extends Schema.TaggedError<\n InvalidDeploymentExpiry,\n { readonly brand: unique symbol }\n>()(\"InvalidDeploymentExpiry\", {\n requested: Schema.String,\n}) {\n override get message() {\n return \"Deployment expiresAt must be a safe integer timestamp in milliseconds, or null to clear the expiry.\";\n }\n}\n\nconst validateExpiry = Effect.fn(\"Deployment.validateExpiry\")(function* ({\n expiresAt,\n}: DeploymentProps) {\n if (expiresAt != null && !Number.isSafeInteger(expiresAt))\n return yield* InvalidDeploymentExpiry.make({\n requested: String(expiresAt),\n });\n});\n\nexport const provider = Effect.gen(function* () {\n const client = yield* ConvexClient;\n const attributes = Effect.fn(\"Deployment.attributes\")(function* (\n deployment: PlatformDeploymentResponse,\n ) {\n if (deployment.kind !== \"cloud\")\n return yield* UnsupportedLocalDeployment.make({\n deploymentName: deployment.name,\n });\n return {\n projectId: deployment.projectId,\n name: deployment.name,\n reference: deployment.reference,\n type: deployment.deploymentType,\n url: deployment.deploymentUrl,\n region: deployment.region,\n class: deployment.class,\n expiresAt: deployment.expiresAt ?? null,\n } satisfies DeploymentAttributes;\n });\n const find = Effect.fn(\"Deployment.find\")(function* (\n projectId: number,\n reference: string,\n ) {\n const deployments = yield* client.listDeployments(projectId);\n const matches = Array.filter(\n deployments,\n (deployment) =>\n deployment.kind === \"cloud\" && deployment.reference === reference,\n );\n if (matches.length > 1)\n return yield* AmbiguousDeployment.make({ projectId, reference });\n return matches[0];\n });\n const validate = Effect.fn(\"Deployment.validate\")(function* (\n current: DeploymentAttributes,\n news: DeploymentProps,\n ) {\n for (const field of [\"projectId\", \"type\", \"region\"] as const) {\n if (news[field] !== undefined && current[field] !== news[field])\n return yield* DeploymentIdentityChange.make({\n deploymentName: current.name,\n field,\n current: String(current[field]),\n requested: String(news[field]),\n });\n }\n });\n return {\n diff: Effect.fn(\"Deployment.diff\")(function* ({ news, output }) {\n if (!isResolved(news)) return;\n yield* validateExpiry(news);\n if (output === undefined) return;\n const expiresAt = news.expiresAt;\n yield* validate(output, news);\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n if (deployment === undefined) return { action: \"update\" };\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if (\n (news.reference ?? output.reference) !== current.reference ||\n (news.class !== undefined && news.class !== current.class) ||\n (expiresAt !== undefined && expiresAt !== (current.expiresAt ?? null))\n )\n return { action: \"update\" };\n }),\n read: Effect.fn(\"Deployment.read\")(function* ({\n fqn,\n instanceId,\n olds,\n output,\n }) {\n if (output !== undefined) {\n const deployment = yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n return deployment !== undefined\n ? yield* attributes(deployment)\n : undefined;\n }\n if (olds.projectId === undefined) return;\n const deployment = yield* find(\n olds.projectId,\n olds.reference ?? (yield* resourceName(\"deployment\", fqn, instanceId)),\n );\n return deployment !== undefined\n ? yield* Effect.map(attributes(deployment), Unowned)\n : undefined;\n }),\n reconcile: Effect.fn(\"Deployment.reconcile\")(function* ({\n fqn,\n instanceId,\n news,\n output,\n }) {\n yield* validateExpiry(news);\n if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);\n if (output !== undefined) yield* validate(output, news);\n let deployment =\n output !== undefined\n ? yield* client\n .getDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void))\n : undefined;\n const reference =\n news.reference ??\n output?.reference ??\n (yield* resourceName(\"deployment\", fqn, instanceId));\n const expiresAt = news.expiresAt;\n if (deployment === undefined) {\n const existing = yield* find(news.projectId, reference);\n if (existing !== undefined && !(yield* shouldAdopt(fqn)))\n return yield* new OwnedBySomeoneElse({\n message: \"An existing deployment requires explicit adoption.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n if (existing !== undefined) {\n const adopted = yield* attributes(existing);\n yield* validate(adopted, news);\n yield* checkpointCreate(fqn, instanceId, news, adopted);\n deployment = existing;\n } else {\n deployment = yield* client.createDeployment(news.projectId, {\n type: news.type,\n reference,\n ...(news.region === undefined ? {} : { region: news.region }),\n ...(news.class === undefined ? {} : { class: news.class }),\n ...(expiresAt === undefined ? {} : { expiresAt }),\n });\n }\n }\n const current = yield* attributes(deployment);\n yield* validate(current, news);\n if (\n current.reference !== reference ||\n (news.class !== undefined && news.class !== current.class) ||\n (expiresAt !== undefined && expiresAt !== (current.expiresAt ?? null))\n ) {\n if (current.reference !== reference) {\n const existing = yield* find(news.projectId, reference);\n if (existing !== undefined && existing.name !== current.name)\n return yield* new OwnedBySomeoneElse({\n message: \"The requested deployment reference is already in use.\",\n resourceType: Deployment.Type,\n physicalName: reference,\n });\n }\n yield* client.updateDeployment(current.name, {\n reference,\n ...(news.class === undefined || news.class === current.class\n ? {}\n : { class: news.class }),\n ...(expiresAt === undefined ||\n expiresAt === (current.expiresAt ?? null)\n ? {}\n : { expiresAt }),\n });\n deployment = yield* client.getDeployment(current.name);\n }\n return yield* attributes(deployment);\n }),\n delete: Effect.fn(\"Deployment.delete\")(function* ({ output }) {\n yield* client\n .deleteDeployment(output.name)\n .pipe(Effect.catchTag(\"ConvexNotFound\", () => Effect.void));\n }),\n } satisfies Provider.ProviderServiceInput<Deployment>;\n});\n\ninterface LocalConfig {\n readonly name: string;\n readonly props: Omit<DeploymentProps, \"class\" | \"expiresAt\">;\n}\n\n/**\n * Under `alchemy dev` a deployment is a local Convex backend this provider\n * owns. Alchemy's dev sidecar hosts it, so the backend keeps running across\n * reloads of the stack and stops when the dev session ends. Its data lives in\n * `.alchemy/convex/<stack>/<stage>/<name>` and is removed only when the\n * deployment is destroyed.\n *\n * @stability unstable\n */\nexport const localLayer = LocalProvider.make(\n Deployment,\n new URL(\n `./internal/LocalSidecar${moduleExtension(import.meta.url)}`,\n import.meta.url,\n ).href,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const directory = yield* dataDirectories;\n return {\n resolveConfig: Effect.fn(\"Deployment.localConfig\")(function* ({\n fqn,\n instanceId,\n news,\n }) {\n const { class: _class, expiresAt: _expiresAt, ...props } = news;\n return {\n name: yield* resourceName(\"deployment\", fqn, instanceId),\n props,\n } satisfies LocalConfig;\n }),\n start: Effect.fn(\"Deployment.localStart\")(function* ({\n config,\n invalidate,\n }) {\n const backend = yield* boot(config.name, directory(config.name));\n yield* backend.exited.pipe(\n Effect.andThen(invalidate),\n Effect.forkScoped,\n );\n return {\n projectId: config.props.projectId,\n name: config.name,\n reference: config.props.reference ?? config.name,\n type: config.props.type,\n url: backend.url,\n ...(config.props.region === undefined\n ? {}\n : { region: config.props.region }),\n } satisfies DeploymentAttributes;\n }),\n stop: Effect.fn(\"Deployment.localStop\")(function* ({ fqn, instanceId }) {\n const name = yield* resourceName(\"deployment\", fqn, instanceId);\n yield* remove(name, directory(name)).pipe(\n Effect.provideService(FileSystem.FileSystem, fs),\n );\n }),\n } satisfies LocalProvider.LocalProviderSpec<\n Deployment,\n LocalConfig,\n Effect.Services<ReturnType<typeof boot>>\n >;\n }),\n);\n\nexport const layer = Provider.effect(Deployment, provider);\n"],"mappings":";;;;;;;;;;;;;;;AA+DA,MAAa,aAAa,SAAqB,qBAAqB,EAClE,sBAAsB,SACxB,CAAC;AAED,IAAa,2BAAb,cAA8C,OAAO,YAGnD,CAAC,CAAC,4BAA4B;CAC9B,gBAAgB,OAAO;CACvB,OAAO,OAAO;CACd,SAAS,OAAO;CAChB,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,6BAAb,cAAgD,OAAO,YAGrD,CAAC,CAAC,8BAA8B,EAAE,gBAAgB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtE,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CACzB,WAAW,OAAO;CAClB,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,0BAAb,cAA6C,OAAO,YAGlD,CAAC,CAAC,2BAA2B,EAC7B,WAAW,OAAO,OACpB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO;CACT;AACF;AAEA,MAAM,iBAAiB,OAAO,GAAG,2BAA2B,CAAC,CAAC,WAAW,EACvE,aACkB;CAClB,IAAI,aAAa,QAAQ,CAAC,OAAO,cAAc,SAAS,GACtD,OAAO,OAAO,wBAAwB,KAAK,EACzC,WAAW,OAAO,SAAS,EAC7B,CAAC;AACL,CAAC;AAED,MAAa,WAAW,OAAO,IAAI,aAAa;CAC9C,MAAM,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