The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { rewriteEmittedTypes, runPrismaCli } from "@alchemy.run/prisma/ORM/internal"; |
| 2 | import { expect, layer } from "@alchemy.run/test"; |
| 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | import * as Path from "effect/Path"; |
| 7 | import * as Result from "effect/Result"; |
| 8 | |
| 9 | const describe = layer(NodeServices.layer); |
| 10 | |
| 11 | const writeDts = (contents: string) => |
| 12 | Effect.gen(function* () { |
| 13 | const fs = yield* FileSystem.FileSystem; |
| 14 | const path = yield* Path.Path; |
| 15 | const dir = yield* fs.makeTempDirectory({ prefix: "alchemy-prisma-rewrite-" }); |
| 16 | const dtsPath = path.join(dir, "contract.d.ts"); |
| 17 | yield* fs.writeFileString(dtsPath, contents); |
| 18 | return dtsPath; |
| 19 | }); |
| 20 | |
| 21 | describe("runPrismaCli", (it) => { |
| 22 | it.effect( |
| 23 | "omits database arguments from CLI error messages", |
| 24 | () => |
| 25 | Effect.gen(function* () { |
| 26 | const fs = yield* FileSystem.FileSystem; |
| 27 | const path = yield* Path.Path; |
| 28 | const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "alchemy-prisma-cli-" }); |
| 29 | const result = yield* Effect.result( |
| 30 | runPrismaCli( |
| 31 | [ |
| 32 | "db", |
| 33 | "verify", |
| 34 | "--config", |
| 35 | path.join(cwd, "missing.config.ts"), |
| 36 | "--db", |
| 37 | "postgresql://test:private-test-password@127.0.0.1:1/test", |
| 38 | ], |
| 39 | { cwd }, |
| 40 | ), |
| 41 | ); |
| 42 | expect(Result.isFailure(result)).toBe(true); |
| 43 | if (Result.isFailure(result)) { |
| 44 | expect(JSON.stringify(result.failure)).not.toContain("private-test-password"); |
| 45 | expect(result.failure.message).toContain("prisma db verify failed"); |
| 46 | } |
| 47 | }).pipe(Effect.scoped), |
| 48 | { tags: ["unit", "provider:prisma", "provider:prisma:orm", "local"] }, |
| 49 | ); |
| 50 | }); |
| 51 | |
| 52 | describe("rewriteEmittedTypes", (it) => { |
| 53 | it.effect( |
| 54 | "maps leaked @internal/extension-* specifiers to @prisma/orm-extension-*", |
| 55 | () => |
| 56 | Effect.gen(function* () { |
| 57 | const fs = yield* FileSystem.FileSystem; |
| 58 | // Imports already use the public package. Prisma still writes the |
| 59 | // unpublished @internal/extension-* name as a string in the type |
| 60 | // body (through 8.0.0-rc.8). |
| 61 | const dtsPath = yield* writeDts(` |
| 62 | import type { Vector } from "@prisma/orm-extension-pgvector/codec-types"; |
| 63 | type Pgvector = { package: "@internal/extension-pgvector/codec-types" }; |
| 64 | type Parade = { package: "@internal/extension-paradedb/pack" }; |
| 65 | `); |
| 66 | yield* rewriteEmittedTypes(dtsPath); |
| 67 | const dts = yield* fs.readFileString(dtsPath); |
| 68 | expect(dts).not.toContain("@internal/"); |
| 69 | expect(dts).toContain('"@prisma/orm-extension-pgvector/codec-types"'); |
| 70 | expect(dts).toContain('"@prisma/orm-extension-paradedb/pack"'); |
| 71 | }), |
| 72 | { tags: ["unit", "provider:prisma", "provider:prisma:orm", "local"] }, |
| 73 | ); |
| 74 | |
| 75 | it.effect( |
| 76 | "still maps postgres @internal/* prefixes when an extension specifier is present", |
| 77 | () => |
| 78 | Effect.gen(function* () { |
| 79 | const fs = yield* FileSystem.FileSystem; |
| 80 | const dtsPath = yield* writeDts(` |
| 81 | import type { X } from "@internal/adapter-postgres/operation-types"; |
| 82 | import type { Y } from "@internal/contract/types"; |
| 83 | type Pack = { package: "@internal/extension-pgvector/pack" }; |
| 84 | `); |
| 85 | yield* rewriteEmittedTypes(dtsPath); |
| 86 | const dts = yield* fs.readFileString(dtsPath); |
| 87 | expect(dts).not.toContain("@internal/"); |
| 88 | expect(dts).toContain("@prisma/orm-postgres/adapter/operation-types"); |
| 89 | expect(dts).toContain("@prisma/orm-postgres/contract/types"); |
| 90 | expect(dts).toContain("@prisma/orm-extension-pgvector/pack"); |
| 91 | }), |
| 92 | { tags: ["unit", "provider:prisma", "provider:prisma:orm", "local"] }, |
| 93 | ); |
| 94 | |
| 95 | it.effect( |
| 96 | "fails when an unmapped @internal/* specifier remains", |
| 97 | () => |
| 98 | Effect.gen(function* () { |
| 99 | const dtsPath = yield* writeDts( |
| 100 | `type Leak = { package: "@internal/unknown-pkg/types" };\n`, |
| 101 | ); |
| 102 | const result = yield* Effect.result(rewriteEmittedTypes(dtsPath)); |
| 103 | expect(Result.isFailure(result)).toBe(true); |
| 104 | if (Result.isFailure(result)) { |
| 105 | expect(String(result.failure)).toContain("@internal/unknown-pkg/"); |
| 106 | } |
| 107 | }), |
| 108 | { tags: ["unit", "provider:prisma", "provider:prisma:orm", "local"] }, |
| 109 | ); |
| 110 | }); |