CipherStashDocs
StackLatestPackagesStackSrcTypes publicType aliases

EncryptedFromSchema

Maps a plaintext model type to its encrypted form using the table schema. Fields whose keys match columns defined in `S` become `Encrypted`; all other field...

@cipherstash/stack


Type Alias: EncryptedFromSchema<T, S>

type EncryptedFromSchema&lt;T, S&gt; = { [K in keyof T]: [K] extends [keyof S] ? [S[K & keyof S]] extends [EncryptedColumn | EncryptedField] ? null extends T[K] ? Encrypted | null : Encrypted : T[K] : T[K] };

Defined in: packages/stack/src/types.ts:190

Maps a plaintext model type to its encrypted form using the table schema.

Fields whose keys match columns defined in S become Encrypted; all other fields retain their original types from T.

When S is the widened EncryptedTableColumn (e.g. when a user passes an explicit &lt;User&gt; type argument without specifying S), the type degrades gracefully to T — preserving backward compatibility.

Type Parameters

T

T

The plaintext model type (e.g. { id: string; email: string })

S

S extends EncryptedTableColumn

The table schema column definition, inferred from the table argument

Example

type User = { id: string; email: string }
// With a schema that defines `email`:
type Encrypted = EncryptedFromSchema&lt;User, { email: EncryptedColumn }&gt;
// => { id: string; email: Encrypted }

On this page