Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

feat: emit contract hashes as branded string literal types for future strict comparisons. - #111

Merged
igalklebanov merged 1 commit into
mainfrom
emit-hashes
Jan 16, 2026
Merged

igalklebanov merged 1 commit into
mainfrom
emit-hashes

Conversation

@igalklebanov

@igalklebanov igalklebanov commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Hey 👋

part of TML-1819.

This PR makes contract types emit to also include a branded string literal type for the contract hashes. This can be used with different refs to enforce same-contract inputs - type errors because of a mismatch would point the user to re-emit at the source of input.

Hashes as string literal types are a faster/simpler check in general.

Summary by CodeRabbit

  • New Features

    • Branded CoreHash and ProfileHash types are now exposed in generated contract types.
    • Contract schemas now include the post → user foreign-key relationship.
  • Updates

    • Contract generation and factory APIs now accept and propagate precomputed core/profile hashes into generated types and outputs.
    • Runtime helpers and contract builders include typed hash fields by default; public type exports now surface hash-related types.
  • Tests

    • Test suites updated to pass and validate the new hash inputs and adjusted contract shapes.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Emission threads coreHash and profileHash into TargetFamilyHook.generateContractTypes; core/profile hash branding types added across contract types, factories, and emitter; SQL emitter generates branded CoreHash/ProfileHash and updated contract artifacts; tests and helpers updated to accept and propagate the new hashes.

Changes

Cohort / File(s) Summary
Prisma contract artifacts
examples/prisma-next-demo/src/prisma/contract.json, examples/prisma-next-demo/src/prisma/contract.d.ts
coreHash literal updated; storage.tables.post.foreignKeys set to reference user(id); generated .d.ts now exposes branded CoreHash/ProfileHash and adds readonly types: Record<string, never> to the Contract surface.
Emission orchestration
packages/1-framework/1-core/migration/control-plane/src/emission/emit.ts
Threaded { coreHash, profileHash } into targetFamily.generateContractTypes call as the new hashes argument.
Core contract types & exports
packages/1-framework/1-core/shared/contract/src/types.ts, packages/1-framework/1-core/shared/contract/src/exports/types.ts
Added branding (__Brand__, Brand), CoreHashBase/ProfileHashBase, RenderTypeContext; made ContractBase/DocumentContract generic over core/profile hash types and changed coreHash/profileHash to those generics; updated TargetFamilyHook.generateContractTypes to accept hashes.
Framework component typing move
packages/1-framework/1-core/shared/contract/src/framework-components.ts, packages/1-framework/1-core/shared/contract/src/exports/framework-components.ts
Removed local RenderTypeContext declaration and import it from ./types; removed RenderTypeContext from one export file.
SQL emitter implementation & output
packages/2-sql/3-tooling/emitter/src/index.ts, packages/2-sql/3-tooling/emitter/package.json
generateContractTypes now accepts hashes: { coreHash, profileHash }; emitter imports hash base types and emits export type CoreHash = CoreHashBase<'...'> and export type ProfileHash = ProfileHashBase<'...'> into generated contract types; added devDependency to package.json.
SQL contract factory & types
packages/2-sql/1-core/contract/src/factories.ts, packages/2-sql/1-core/contract/src/types.ts
Made contract factory and SqlContract generic over TCoreHash/TProfileHash; function params and return types now use branded generics and propagate them through type assertions.
Emitter tests & mocks
packages/1-framework/3-tooling/emitter/test/emitter.test.ts, packages/2-sql/3-tooling/emitter/test/*
Updated mocks and tests to accept the new _hashes/testHashes fourth parameter; adjusted calls to generateContractTypes to pass hashes (options moved to 5th argument where present).
Test helpers & runtime utils
packages/2-sql/5-runtime/test/utils.ts, packages/2-sql/4-lanes/.../test/*, packages/3-targets/.../test/*, test/integration/test/*
Tightened createTestContract signature to include core/profile hash fields and defaults; many test fixtures cast coreHash/profileHash literals (e.g., 'sha256:...' as never) to satisfy the new branded types.

Sequence Diagram(s)

sequenceDiagram
  participant Emission as Emission Process
  participant Hook as TargetFamilyHook
  participant Emitter as SQL Emitter
  participant FS as Filesystem

  Emission->>Hook: compute coreHash & profileHash\ncall generateContractTypes(ir, codecImports, opImports, {coreHash, profileHash}, options)
  Hook->>Emitter: forward IR + hashes + imports + options
  Emitter->>Emitter: render TS surface using hashes\nemit branded CoreHash/ProfileHash types
  Emitter->>FS: write `contract.d.ts` and `contract.json` (coreHash, foreignKeys)
Loading

Comment @coderabbitai help to get the list of available commands and usage tips.

@igalklebanov igalklebanov changed the title TBD feat: emit contract hashes as branded string literal types for future strict comparisons. Jan 12, 2026
@igalklebanov
igalklebanov marked this pull request as ready for review January 12, 2026 11:19
coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as duplicate.

...

...

...

...

...

...

...

...

...

...

...

...

...
coderabbitai[bot]

This comment was marked as duplicate.

@wmadden wmadden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, doesn't have much effect on its own but I expect we'll see its value soon.

@linear

linear Bot commented Jan 15, 2026

Copy link
Copy Markdown

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants