Skip to content

Commit a4fd619

Browse files
authored
Merge pull request #467 from cipherstash/prisma-next-0-8-0
Upgrading Prisma Next to 0.8.0
2 parents 526e4b4 + f2aca22 commit a4fd619

7 files changed

Lines changed: 360 additions & 345 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@cipherstash/prisma-next": minor
3+
---
4+
5+
Upgrade `@prisma-next/*` peer/runtime stack from `0.6.0-dev.8` to `0.8.0`.
6+
7+
`@prisma-next/sql-runtime@0.8` reordered the SQL execution pipeline so the `beforeExecute` middleware chain fires *before* `encodeParams`. `bulkEncryptMiddleware` now mutates params via `replaceValues(...)` ahead of encode, which means `CipherstashCellCodec.encode` is invoked with the wire-format string rather than the original `EncryptedEnvelopeBase`. The cell codec now short-circuits string values through unchanged; the envelope path is preserved for direct (non-runtime) callers such as the codec unit tests.
8+
9+
`SqlMiddlewareContext.scope` (`"runtime" | "connection" | "transaction"`) also became required in 0.8 (was optional in 0.7); test mocks now set `scope: 'runtime'` explicitly.

examples/prisma/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
"dependencies": {
1616
"@cipherstash/prisma-next": "workspace:*",
1717
"@cipherstash/stack": "workspace:*",
18-
"@prisma-next/adapter-postgres": "0.6.0-dev.8",
19-
"@prisma-next/contract": "0.6.0-dev.8",
20-
"@prisma-next/driver-postgres": "0.6.0-dev.8",
21-
"@prisma-next/family-sql": "0.6.0-dev.8",
22-
"@prisma-next/framework-components": "0.6.0-dev.8",
23-
"@prisma-next/postgres": "0.6.0-dev.8",
24-
"@prisma-next/sql-contract": "0.6.0-dev.8",
25-
"@prisma-next/sql-contract-psl": "0.6.0-dev.8",
26-
"@prisma-next/sql-orm-client": "0.6.0-dev.8",
27-
"@prisma-next/sql-runtime": "0.6.0-dev.8",
28-
"@prisma-next/target-postgres": "0.6.0-dev.8",
18+
"@prisma-next/adapter-postgres": "0.8.0",
19+
"@prisma-next/contract": "0.8.0",
20+
"@prisma-next/driver-postgres": "0.8.0",
21+
"@prisma-next/family-sql": "0.8.0",
22+
"@prisma-next/framework-components": "0.8.0",
23+
"@prisma-next/postgres": "0.8.0",
24+
"@prisma-next/sql-contract": "0.8.0",
25+
"@prisma-next/sql-contract-psl": "0.8.0",
26+
"@prisma-next/sql-orm-client": "0.8.0",
27+
"@prisma-next/sql-runtime": "0.8.0",
28+
"@prisma-next/target-postgres": "0.8.0",
2929
"dotenv": "^17.4.2"
3030
},
3131
"devDependencies": {
32-
"@prisma-next/cli": "0.6.0-dev.8",
32+
"@prisma-next/cli": "0.8.0",
3333
"@types/node": "^22.15.12",
3434
"pathe": "^2.0.3",
3535
"tsx": "catalog:repo",

packages/prisma-next/package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,27 @@
8080
},
8181
"dependencies": {
8282
"@cipherstash/stack": "workspace:*",
83-
"@prisma-next/contract": "0.6.0-dev.8",
84-
"@prisma-next/family-sql": "0.6.0-dev.8",
85-
"@prisma-next/framework-components": "0.6.0-dev.8",
86-
"@prisma-next/migration-tools": "0.6.0-dev.8",
87-
"@prisma-next/sql-contract": "0.6.0-dev.8",
88-
"@prisma-next/sql-operations": "0.6.0-dev.8",
89-
"@prisma-next/sql-relational-core": "0.6.0-dev.8",
90-
"@prisma-next/sql-runtime": "0.6.0-dev.8",
91-
"@prisma-next/ts-render": "0.6.0-dev.8",
92-
"@prisma-next/utils": "0.6.0-dev.8",
83+
"@prisma-next/contract": "0.8.0",
84+
"@prisma-next/family-sql": "0.8.0",
85+
"@prisma-next/framework-components": "0.8.0",
86+
"@prisma-next/migration-tools": "0.8.0",
87+
"@prisma-next/sql-contract": "0.8.0",
88+
"@prisma-next/sql-operations": "0.8.0",
89+
"@prisma-next/sql-relational-core": "0.8.0",
90+
"@prisma-next/sql-runtime": "0.8.0",
91+
"@prisma-next/ts-render": "0.8.0",
92+
"@prisma-next/utils": "0.8.0",
9393
"arktype": "^2.1.29"
9494
},
9595
"devDependencies": {
96-
"@prisma-next/adapter-postgres": "0.6.0-dev.8",
97-
"@prisma-next/cli": "0.6.0-dev.8",
98-
"@prisma-next/driver-postgres": "0.6.0-dev.8",
99-
"@prisma-next/psl-parser": "0.6.0-dev.8",
100-
"@prisma-next/sql-contract-psl": "0.6.0-dev.8",
101-
"@prisma-next/sql-contract-ts": "0.6.0-dev.8",
102-
"@prisma-next/sql-schema-ir": "0.6.0-dev.8",
103-
"@prisma-next/target-postgres": "0.6.0-dev.8",
96+
"@prisma-next/adapter-postgres": "0.8.0",
97+
"@prisma-next/cli": "0.8.0",
98+
"@prisma-next/driver-postgres": "0.8.0",
99+
"@prisma-next/psl-parser": "0.8.0",
100+
"@prisma-next/sql-contract-psl": "0.8.0",
101+
"@prisma-next/sql-contract-ts": "0.8.0",
102+
"@prisma-next/sql-schema-ir": "0.8.0",
103+
"@prisma-next/target-postgres": "0.8.0",
104104
"pathe": "^2.0.3",
105105
"tsup": "catalog:repo",
106106
"typescript": "catalog:repo",

packages/prisma-next/src/execution/cell-codec-factory.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,19 @@ export class CipherstashCellCodec<E extends EncryptedEnvelopeBase<unknown>> exte
131131
}
132132

133133
async encode(value: E, _ctx: SqlCodecCallContext): Promise<unknown> {
134-
// Two-pass write path: `lower`/`encodeParams` runs first and reaches
135-
// this method with the envelope as the user authored it (plaintext
136-
// set, ciphertext unset). We return the envelope as a sentinel; the
137-
// bulk-encrypt middleware then runs in `beforeExecute`, stamps the
138-
// ciphertext onto the envelope, and rewrites the param slot to the
139-
// wire-format string via `params.replaceValues(...)` before the
140-
// driver reads. See `../middleware/bulk-encrypt.ts` for the full
141-
// flow. On the read side, `handle.ciphertext` is already set on
142-
// arrival and encode short-circuits to the wire-format string.
134+
// Two-pass write path. As of `@prisma-next/sql-runtime@0.8`, the
135+
// `beforeExecute` middleware chain fires *before* `encodeParams`:
136+
// `bulkEncryptMiddleware` runs, calls `params.replaceValues(...)` to
137+
// swap each envelope for its wire-format composite-literal string,
138+
// and the encoder then sees that string directly. Pass it through.
139+
// (Prior to 0.8 the order was inverted: encode ran first, returned
140+
// the envelope as a sentinel, then the middleware replaced the param
141+
// before the driver read it. The branches below preserve that older
142+
// contract for non-runtime callers — e.g. the codec unit tests that
143+
// call `encode` directly with an envelope.)
144+
if (typeof value === 'string') {
145+
return value;
146+
}
143147
const handle = value.expose();
144148
if (handle.ciphertext === undefined) {
145149
// Misconfig diagnostic: when an SDK-bound codec sees a pre-encrypt

packages/prisma-next/test/abort.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function makeMiddlewareCtx(signal: AbortSignal | undefined): SqlMiddlewareContex
114114
return {
115115
contract: {} as Contract<SqlStorage>,
116116
mode: 'strict',
117+
scope: 'runtime',
117118
now: () => Date.now(),
118119
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
119120
contentHash: async () => 'mock-hash',

packages/prisma-next/test/bulk-encrypt-middleware.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function createCtx(overrides?: Partial<SqlMiddlewareContext>): SqlMiddlewareCont
5656
return {
5757
contract: {} as Contract<SqlStorage>,
5858
mode: 'strict' as const,
59+
scope: 'runtime' as const,
5960
now: () => Date.now(),
6061
log: {
6162
info: vi.fn(),

0 commit comments

Comments
 (0)