The best way to control Claude Code, Codex and more from any computer or phone

main
ts 382 lines 10.4 KB
Raw
1 import * as PrismaPackage from "@alchemy.run/prisma";
2 import * as Prisma from "@alchemy.run/prisma";
3 import { describe, expect, it } from "@alchemy.run/test";
4 import * as NodeServices from "@effect/platform-node/NodeServices";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8
9 const publicExports = [
10 "CheckViolationError",
11 "CliError",
12 "ConnectionError",
13 "Contract",
14 "ContractProvider",
15 "ForeignKeyViolationError",
16 "Migrate",
17 "MigrateProvider",
18 "NotNullViolationError",
19 "OrmError",
20 "QueryError",
21 "RollbackError",
22 "RuntimeError",
23 "UniqueViolationError",
24 "UnknownError",
25 "Website",
26 "wrapPrismaError",
27
28 // Tagged errors each resource's lifecycle fails with.
29 "AppConflict",
30 "AppInvalidProps",
31 "AppOperationFailed",
32 "AppUnexpectedResponse",
33 "BranchConflict",
34 "BranchOperationFailed",
35 "BranchUnexpectedResponse",
36 "ComputeArchiveInvalidProps",
37 "ComputeArchiveOperationFailed",
38 "ComputeArchiveOptionsError",
39 "ComputeBuildError",
40 "ComputeBuildInvalidProps",
41 "ComputeConflict",
42 "ComputeInvalidProps",
43 "ComputeNotReady",
44 "ComputeOperationFailed",
45 "ComputePackageJsonError",
46 "ComputeUnexpectedResponse",
47 "ConnectionConflict",
48 "ConnectionUnexpectedResponse",
49 "CustomDomainConflict",
50 "CustomDomainInvalidProps",
51 "CustomDomainOperationFailed",
52 "CustomDomainUnexpectedResponse",
53 "DatabaseConflict",
54 "DatabaseInvalidProps",
55 "DatabaseOperationFailed",
56 "DeploymentConflict",
57 "DeploymentInvalidProps",
58 "DeploymentOperationFailed",
59 "DeploymentUnexpectedResponse",
60 "EnvironmentVariableConflict",
61 "EnvironmentVariableInvalidProps",
62 "InvalidArtifactUploadUrlError",
63 "ProjectConflict",
64 "ProjectInvalidProps",
65 "ProjectUnexpectedResponse",
66 "SourceRepositoryConflict",
67 "SourceRepositoryInvalidProps",
68 "SourceRepositoryOperationFailed",
69
70 "providers",
71 "managementApi",
72 "Providers",
73 "PrismaEnvironment",
74 "PrismaAuth",
75 "PrismaClient",
76 "Project",
77 "ProjectProvider",
78 "Database",
79 "DatabaseProvider",
80 "Postgres",
81 "Connection",
82 "Connect",
83 "ConnectBinding",
84 "ConnectionProvider",
85 "connectEnvKeys",
86 "parsePostgresOrigin",
87 "Branch",
88 "BranchProvider",
89 "Bucket",
90 "BucketProvider",
91 "BucketAccessKey",
92 "BucketAccessKeyProvider",
93 "BucketProjectMismatchError",
94 "BucketError",
95 "AmbiguousBucketAccessKeyError",
96 "ReadBucket",
97 "ReadBucketBinding",
98 "readBucketOperations",
99 "makeReadBucketClient",
100 "WriteBucket",
101 "WriteBucketBinding",
102 "writeBucketOperations",
103 "makeWriteBucketClient",
104 "ReadWriteBucket",
105 "ReadWriteBucketBinding",
106 "makeReadWriteBucketClient",
107 "App",
108 "AppProvider",
109 "Deployment",
110 "DeploymentProvider",
111 "MAX_DEPLOYMENT_ARTIFACT_BYTES",
112 "CustomDomain",
113 "CustomDomainProvider",
114 "EnvironmentVariable",
115 "EnvironmentVariableProvider",
116 "SourceRepository",
117 "SourceRepositoryProvider",
118 "Compute",
119 "ComputeProvider",
120 "ComputeDevProvider",
121 "isCompute",
122 "KNOWN_REGION_IDS",
123 "REGIONS",
124 "PRISMA_AUTH_PROVIDER_NAME",
125 "PrismaStoredCredentials",
126 "PrismaApiDecodeError",
127 "PrismaApiError",
128 "PrismaClientLive",
129 "PrismaDeploymentFailed",
130 "PrismaDeploymentWaitInvalidOptions",
131 "PrismaDeploymentWaitTimeout",
132 "PrismaLogStreamError",
133 "listWorkspaces",
134 "getWorkspace",
135 "getCurrentPrincipal",
136 "listRegions",
137 "listPostgresRegions",
138 "listAccelerateRegions",
139 "listProjects",
140 "getProject",
141 "createProject",
142 "updateProject",
143 "deleteProject",
144 "transferProject",
145 "listDatabases",
146 "listProjectDatabases",
147 "getDatabase",
148 "createDatabase",
149 "createProjectDatabase",
150 "updateDatabase",
151 "deleteDatabase",
152 "listBackups",
153 "restoreDatabase",
154 "getDatabaseUsage",
155 "listConnections",
156 "listDatabaseConnections",
157 "getConnection",
158 "createConnection",
159 "createDatabaseConnection",
160 "deleteConnection",
161 "rotateConnection",
162 "listBranches",
163 "getBranch",
164 "createBranch",
165 "updateBranch",
166 "deleteBranch",
167 "listBuckets",
168 "getBucket",
169 "createBucket",
170 "deleteBucket",
171 "listBucketKeys",
172 "createBucketKey",
173 "deleteBucketKey",
174 "getCustomDomain",
175 "deleteCustomDomain",
176 "retryCustomDomain",
177 "listApps",
178 "getApp",
179 "createApp",
180 "updateApp",
181 "deleteApp",
182 "promoteApp",
183 "rollbackApp",
184 "listAppDomains",
185 "createAppDomain",
186 "listAppDeployments",
187 "createAppDeployment",
188 "getDeployment",
189 "deleteDeployment",
190 "startDeployment",
191 "stopDeployment",
192 "getDeploymentLogsRequest",
193 "getBuildLogsRequest",
194 "listEnvironmentVariables",
195 "getEnvironmentVariable",
196 "createEnvironmentVariable",
197 "updateEnvironmentVariable",
198 "deleteEnvironmentVariable",
199 "listIntegrations",
200 "listWorkspaceIntegrations",
201 "getIntegration",
202 "deleteIntegration",
203 "revokeWorkspaceIntegration",
204 "listScmInstallations",
205 "createScmInstallIntent",
206 "listScmInstallationRepositories",
207 "listSourceRepositories",
208 "getSourceRepository",
209 "createSourceRepository",
210 "deleteSourceRepository",
211 "COMPUTE_MANIFEST_VERSION",
212 "createComputeArchive",
213 "normalizeEntrypoint",
214 "runBuildCommand",
215 "runComputeAutoBuild",
216 "runComputeStaticBuild",
217 "parseDeploymentLogRecord",
218 "tailDeploymentLogs",
219 "waitForDeploymentStatus",
220 "waitForDeploymentUrl",
221 "destroyDeployment",
222 "destroyApp",
223 "destroyProjectApps",
224 "toDeploymentUrl",
225 "syncComputeEnvironment",
226 "readUploadArtifact",
227 "uploadArtifact",
228 "validateDeploymentArtifactBytes",
229 "extractConnectionSecrets",
230 "requestBody",
231 "isNotFound",
232 "isConflict",
233 "fromProfile",
234 ] as const;
235
236 const publicPrismaDeepImports = [
237 "App",
238 "AuthProvider",
239 "Bootstrap",
240 "Branch",
241 "Bucket",
242 "BucketBinding",
243 "BucketAccessKey",
244 "BucketTypes",
245 "Cli",
246 "Client",
247 "Compute",
248 "ComputeArchive",
249 "ComputeBuild",
250 "ComputeLifecycle",
251 "Connect",
252 "Connection",
253 "Contributions",
254 "CustomDomain",
255 "Database",
256 "Deployment",
257 "EnvironmentVariable",
258 "Operations",
259 "Postgres",
260 "PostgresOrigin",
261 "PrismaEnvironment",
262 "PrismaLogs",
263 "Project",
264 "Providers",
265 "ReadBucket",
266 "ReadWriteBucket",
267 "SourceRepository",
268 "Types",
269 "WriteBucket",
270 ] as const;
271
272 // Internal modules live under src/internal/, which the published export map
273 // blocks; they are not reachable as root deep imports.
274 const internalPrismaDeepImports = ["Credentials", "PrismaDevDatabase", "Refs"] as const;
275
276 const removedPrismaDeepImports = [
277 "ComputeApp",
278 "ComputeService",
279 "ComputeVersion",
280 "ComputeVersionObserve",
281 ] as const;
282
283 const importPackagePath = (specifier: string) => import(/* @vite-ignore */ specifier);
284
285 describe("Prisma public surface", { tags: ["unit", "provider:prisma", "local"] }, () => {
286 it("exports the user-facing resources, providers, and operations", () => {
287 const expected = [...publicExports].sort();
288
289 expect(Object.keys(Prisma).sort()).toEqual(expected);
290 expect(Prisma.KNOWN_REGION_IDS).toContain("us-east-1");
291 expect(Prisma.REGIONS[0]).toEqual({
292 id: Prisma.KNOWN_REGION_IDS[0],
293 displayName: Prisma.KNOWN_REGION_IDS[0],
294 });
295 });
296
297 it("exports the same surface through the @alchemy.run/prisma package path", () => {
298 const expected = [...publicExports].sort();
299
300 expect(Object.keys(PrismaPackage).sort()).toEqual(expected);
301 });
302
303 it(
304 "supports deep Prisma package path imports",
305 async () => {
306 for (const moduleName of publicPrismaDeepImports) {
307 const module = await importPackagePath(`@alchemy.run/prisma/${moduleName}`);
308 expect(Object.keys(module as object).length).toBeGreaterThan(0);
309 }
310
311 const [compute, operations, client, archive, types, postgres] = await Promise.all([
312 import("@alchemy.run/prisma/Compute"),
313 import("@alchemy.run/prisma/Operations"),
314 import("@alchemy.run/prisma/Client"),
315 import("@alchemy.run/prisma/ComputeArchive"),
316 import("@alchemy.run/prisma/Types"),
317 import("@alchemy.run/prisma/Postgres"),
318 ]);
319
320 expect(compute.Compute.Type).toBe("Prisma.Compute");
321 expect(typeof operations.listProjects).toBe("function");
322 expect(typeof client.PrismaApiError).toBe("function");
323 expect(archive.COMPUTE_MANIFEST_VERSION).toBe("1");
324 expect(types.KNOWN_REGION_IDS).toContain("us-east-1");
325 expect(postgres.Postgres.Type).toBe("Prisma.Database");
326 expect(Prisma.Postgres).toBe(Prisma.Database);
327 },
328 { tags: ["provider:prisma:database"] },
329 );
330
331 it("does not expose removed Compute deep imports", async () => {
332 for (const moduleName of removedPrismaDeepImports) {
333 await expect(importPackagePath(`@alchemy.run/prisma/${moduleName}`)).rejects.toThrow();
334 }
335 });
336
337 it("does not expose internal Prisma deep imports", async () => {
338 for (const moduleName of internalPrismaDeepImports) {
339 await expect(importPackagePath(`@alchemy.run/prisma/${moduleName}`)).rejects.toThrow();
340 }
341 });
342
343 it.effect("keeps Prisma root modules intentionally classified", () =>
344 Effect.gen(function* () {
345 const fs = yield* FileSystem.FileSystem;
346 const path = yield* Path.Path;
347 const prismaSourceRoot = path.resolve(import.meta.dirname, "../../../prisma/src");
348 const files = (yield* fs.readDirectory(prismaSourceRoot))
349 .filter((file) => file.endsWith(".ts"))
350 .sort();
351
352 expect(files).toEqual(
353 ["index.ts", ...publicPrismaDeepImports.map((moduleName) => `${moduleName}.ts`)].sort(),
354 );
355 }).pipe(Effect.provide(NodeServices.layer)),
356 );
357
358 it.effect("blocks internal Prisma deep imports in the package export map", () =>
359 Effect.gen(function* () {
360 const fs = yield* FileSystem.FileSystem;
361 const path = yield* Path.Path;
362 const packageJsonPath = path.resolve(import.meta.dirname, "../../../prisma/package.json");
363 const packageJson = JSON.parse(yield* fs.readFileString(packageJsonPath));
364
365 expect(packageJson.publishConfig.exports["./internal/*"]).toBeNull();
366 }).pipe(Effect.provide(NodeServices.layer)),
367 );
368
369 it.effect("pins Prisma package export map entries", () =>
370 Effect.gen(function* () {
371 const fs = yield* FileSystem.FileSystem;
372 const path = yield* Path.Path;
373 const packageJsonPath = path.resolve(import.meta.dirname, "../../../prisma/package.json");
374 const packageJson = JSON.parse(yield* fs.readFileString(packageJsonPath));
375
376 expect(packageJson.exports["."]).toBe("./src/index.ts");
377 expect(packageJson.exports["./ORM"]).toBe("./src/ORM/index.ts");
378 // Deep Prisma modules use the package-wide source export wildcard.
379 expect(packageJson.exports["./*"]).toBe("./src/*.ts");
380 }).pipe(Effect.provide(NodeServices.layer)),
381 );
382 });