Skip to content

Commit 7d1ac54

Browse files
committed
refactor(prisma-next): address CodeRabbit review (centralize v3 index guard, fix docs/test labels)
- Move V3_INDEX_VALUES + isV3Index to v3/domain-map.ts (single source of truth; was duplicated in derive-schemas.ts and codec-hooks-v3.ts). - Align vendor-script run comment with REFRESH_EQL_V3.md (node --experimental-strip-types). - Rename the mislabeled e2e 'NULL round-trips' test (UserV3 columns are NOT NULL).
1 parent dd561bf commit 7d1ac54

5 files changed

Lines changed: 14 additions & 17 deletions

File tree

examples/prisma/test/e2e/str-v3.e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ describe.skipIf(!dbUrl)('EQL v3 String e2e (live PG + eql_v3 + ZeroKMS)', () =>
8888
expect(rows.map((r) => r.id).sort()).toEqual(expected)
8989
})
9090

91-
it('NULL round-trips: a null v3 column decrypts back to null', async () => {
91+
it('insert + decrypt round-trips a freshly-created v3 row (UserV3 columns are NOT NULL)', async () => {
9292
await db.orm.UserV3.create({
93-
id: 'e2e-strv3-null',
93+
id: 'e2e-strv3-extra',
9494
email: EncryptedString.from('present'),
9595
bio: EncryptedString.from('present'),
9696
name: EncryptedString.from('present'),

packages/prisma-next/scripts/vendor-eql-v3-install.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Regenerates src/migration/eql-v3-install.generated.ts from the vendored
22
// __tests__/fixtures/cipherstash-encrypt-v3.sql installer.
33
//
4-
// Run: pnpm tsx scripts/vendor-eql-v3-install.ts
4+
// Run (tsx is not installed in this workspace; Node 22+ runs the TS directly):
5+
// node --experimental-strip-types scripts/vendor-eql-v3-install.ts
56
//
67
// See scripts/REFRESH_EQL_V3.md for the full refresh procedure (which EQL commit
78
// the fixture is built from, the cross-package duplication hazard, etc.).

packages/prisma-next/src/migration/codec-hooks-v3.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
*/
1616

1717
import type { CodecControlHooks } from '@prisma-next/family-sql/control'
18-
import { type V3Index, eqlV3Domain } from '../v3/domain-map'
19-
20-
const V3_INDEX_VALUES = ['equality', 'freeTextSearch', 'orderAndRange'] as const
21-
22-
function isV3Index(value: unknown): value is V3Index {
23-
return typeof value === 'string' && (V3_INDEX_VALUES as readonly string[]).includes(value)
24-
}
18+
import { eqlV3Domain, isV3Index } from '../v3/domain-map'
2519

2620
const expandNativeType: NonNullable<CodecControlHooks['expandNativeType']> = ({ typeParams }) => {
2721
const index = typeParams?.['index']

packages/prisma-next/src/stack/derive-schemas.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
isCipherstashCodecId,
3434
isCipherstashV3CodecId,
3535
} from '../extension-metadata/constants'
36-
import { type V3Index, v3CastAs } from '../v3/domain-map'
36+
import { V3_INDEX_VALUES, isV3Index, v3CastAs } from '../v3/domain-map'
3737

3838
/**
3939
* Structural shape of the subset of `contract.json` this derivation
@@ -155,12 +155,6 @@ function isCipherstashFlag(value: string): value is CipherstashFlag {
155155
return value in FLAG_DISPATCH
156156
}
157157

158-
const V3_INDEX_VALUES = ['equality', 'freeTextSearch', 'orderAndRange'] as const
159-
160-
function isV3Index(value: unknown): value is V3Index {
161-
return typeof value === 'string' && (V3_INDEX_VALUES as readonly string[]).includes(value)
162-
}
163-
164158
/**
165159
* Apply a v3 column's single index. `typeParams.index` is `unknown` (the contract
166160
* view types typeParams as `Record<string, unknown> | null`), so narrow with

packages/prisma-next/src/v3/domain-map.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export type V3DataType = 'text'
1818
/** v3 single-capability index choices for the text scalar. */
1919
export type V3Index = 'equality' | 'freeTextSearch' | 'orderAndRange'
2020

21+
/** The closed set of v3 index values, as a runtime array (SSOT for {@link isV3Index}). */
22+
export const V3_INDEX_VALUES = ['equality', 'freeTextSearch', 'orderAndRange'] as const
23+
24+
/** Narrow an `unknown` (e.g. a `typeParams.index` read from a contract) to {@link V3Index}. */
25+
export function isV3Index(value: unknown): value is V3Index {
26+
return typeof value === 'string' && (V3_INDEX_VALUES as readonly string[]).includes(value)
27+
}
28+
2129
/**
2230
* Per-scalar capability table. Keyed by scalar so adding int/date/timestamptz is
2331
* a type-shape extension (new key + its valid index subset), not a row append

0 commit comments

Comments
 (0)