-
Notifications
You must be signed in to change notification settings - Fork 3
feat(authoring): close VP2 with target-owned terse field presets #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
166d19b
239f97e
f09141a
dac9d4d
7448e08
dfe5ffc
d5f2e0c
1417eb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| import type { FamilyPackRef } from '@prisma-next/framework-components/components'; | ||
|
|
||
| const mongoFamilyPack = { | ||
| kind: 'family', | ||
| id: 'mongo', | ||
| familyId: 'mongo', | ||
| version: '0.0.1', | ||
| } as const; | ||
|
|
||
| export default mongoFamilyPack as typeof mongoFamilyPack & FamilyPackRef<'mongo'>; | ||
| export default mongoFamilyPack; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| import type { ExtensionPackRef } from '@prisma-next/framework-components/components'; | ||
| import { pgvectorPackMeta } from '../core/descriptor-meta'; | ||
| import type { CodecTypes } from '../types/codec-types'; | ||
|
|
||
| const pgvectorPack = pgvectorPackMeta; | ||
|
|
||
| export default pgvectorPack as typeof pgvectorPackMeta & | ||
| ExtensionPackRef<'sql', 'postgres'> & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; | ||
| export default pgvectorPack as typeof pgvectorPackMeta & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| import type { TargetPackRef } from '@prisma-next/framework-components/components'; | ||
| import { mongoTargetDescriptorMeta } from '../core/descriptor-meta'; | ||
| import type { CodecTypes } from './codec-types'; | ||
|
|
||
| const mongoTargetPack = mongoTargetDescriptorMeta; | ||
|
|
||
| export default mongoTargetPack as typeof mongoTargetPack & | ||
| TargetPackRef<'mongo', 'mongo'> & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; | ||
| export default mongoTargetPack as typeof mongoTargetPack & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| import type { CodecTypes } from '@prisma-next/adapter-postgres/codec-types'; | ||
| import type { TargetPackRef } from '@prisma-next/framework-components/components'; | ||
| import { postgresTargetDescriptorMeta } from '../core/descriptor-meta'; | ||
|
|
||
| const postgresPack = postgresTargetDescriptorMeta; | ||
|
|
||
| export default postgresPack as typeof postgresTargetDescriptorMeta & | ||
| TargetPackRef<'sql', 'postgres'> & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; | ||
| export default postgresPack as typeof postgresTargetDescriptorMeta & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; | ||
|
Comment on lines
+6
to
+8
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F04 — Same pattern in all pack exports (sqlite, pgvector, mongo-target). Now that the This PR touched every one of these files and had the opportunity to clean this up. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| import type { CodecTypes } from '@prisma-next/adapter-sqlite/codec-types'; | ||
| import type { TargetPackRef } from '@prisma-next/framework-components/components'; | ||
| import { sqliteTargetDescriptorMeta } from '../core/descriptor-meta'; | ||
|
|
||
| const sqlitePack = sqliteTargetDescriptorMeta; | ||
|
|
||
| export default sqlitePack as TargetPackRef<'sql', 'sqlite'> & { | ||
| export default sqlitePack as typeof sqliteTargetDescriptorMeta & { | ||
| readonly __codecTypes?: CodecTypes; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const fixtureDir = join(__dirname, 'parity', 'callback-mode-scalars'); | ||
|
|
||
| /** | ||
| * Counts semantic lines in a source file — non-blank lines that are not | ||
| * comments. Matches the heuristic used by the contract-psl ts-psl-parity | ||
| * test so results are comparable across parity tests. | ||
| */ | ||
| function countSemanticLines(source: string): number { | ||
| return source | ||
| .split('\n') | ||
| .map((line) => line.trim()) | ||
| .filter((line) => line.length > 0 && !line.startsWith('//')).length; | ||
|
Comment on lines
+14
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F02 — The JSDoc says this matches the heuristic in the contract-psl ts-psl-parity test. If that copy drifts, the two tests would measure terseness differently. Consider extracting to a shared test utility (e.g. alongside |
||
| } | ||
|
|
||
| describe('VP2: TS callback-mode authoring terseness parity', () => { | ||
| const pslSource = readFileSync(join(fixtureDir, 'schema.prisma'), 'utf-8'); | ||
| const tsSource = readFileSync(join(fixtureDir, 'contract.ts'), 'utf-8'); | ||
| const pslLines = countSemanticLines(pslSource); | ||
| const tsLines = countSemanticLines(tsSource); | ||
| const ratio = tsLines / pslLines; | ||
|
|
||
| it('keeps the callback-mode TS contract in the ~1.5–2.1x PSL ballpark', () => { | ||
| // VP2 stop condition: "The TypeScript version of a representative | ||
| // contract is in the same ballpark of length as the PSL version." | ||
| // | ||
| // Baseline (April milestone): structural TS authoring was ~3–5x the | ||
| // PSL version. The callback-mode field presets (contributed by | ||
| // @prisma-next/target-postgres/pack) should collapse scalar fields to | ||
| // one line each, pulling the ratio well under the baseline. | ||
| // | ||
| // The upper bound of 2.1x is intentional: any drift above 2.1x should | ||
| // force a re-review of the preset vocabulary rather than silently | ||
| // widen the acceptance window. | ||
| expect(ratio).toBeLessThanOrEqual(2.1); | ||
| expect(ratio).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('is measurably tighter than the structural core-surface baseline', () => { | ||
| const coreSurfaceDir = join(__dirname, 'parity', 'core-surface'); | ||
| const coreSurfacePsl = readFileSync(join(coreSurfaceDir, 'schema.prisma'), 'utf-8'); | ||
| const coreSurfaceTs = readFileSync(join(coreSurfaceDir, 'contract.ts'), 'utf-8'); | ||
| const coreRatio = countSemanticLines(coreSurfaceTs) / countSemanticLines(coreSurfacePsl); | ||
|
|
||
| expect(ratio).toBeLessThan(coreRatio); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import pgvector from '@prisma-next/extension-pgvector/pack'; | ||
| import sqlFamily from '@prisma-next/family-sql/pack'; | ||
| import { defineContract, rel } from '@prisma-next/sql-contract-ts/contract-builder'; | ||
| import postgresPack from '@prisma-next/target-postgres/pack'; | ||
|
|
||
| export const contract = defineContract( | ||
| { family: sqlFamily, target: postgresPack, extensionPacks: { pgvector } }, | ||
| ({ field, model, type }) => { | ||
| const types = { | ||
| Embedding: type.pgvector.Vector(1536), | ||
| } as const; | ||
| const User = model('User', { | ||
| fields: { | ||
| id: field.int().defaultSql('autoincrement()').id(), | ||
| email: field.text().unique(), | ||
| age: field.int(), | ||
| isActive: field.boolean().default(true), | ||
| score: field.float().optional(), | ||
| profile: field.json().optional(), | ||
| embedding: field.namedType(types.Embedding).optional(), | ||
| createdAt: field.createdAt(), | ||
| }, | ||
| }).sql({ table: 'user' }); | ||
| const Post = model('Post', { | ||
| fields: { | ||
| id: field.int().defaultSql('autoincrement()').id(), | ||
| userId: field.int(), | ||
| title: field.text(), | ||
| rating: field.float().optional(), | ||
| }, | ||
| relations: { | ||
| user: rel | ||
| .belongsTo(User, { from: 'userId', to: 'id' }) | ||
| .sql({ fk: { onDelete: 'cascade', onUpdate: 'cascade' } }), | ||
| }, | ||
| }).sql({ table: 'post' }); | ||
| return { types, models: { User, Post } }; | ||
| }, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F06 — 4 of 10 presets lack parity fixture coverage (deferred)
bigint,decimal,bytes, anddateTimeare defined here but not exercised by any parity fixture. If the PSL mapping or codec IDs change for these scalars, the misalignment would go undetected.I understand this is a deliberate scope decision (April stop condition: terseness, not vocabulary coverage). Noting it for visibility — please track the follow-up.