You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Schema-defined fields are typed as `Encrypted` in the return value
157
+
- Non-schema fields retain their original types
151
158
- Correct handling of optional and nullable fields
152
159
- Preservation of nested object structures
153
-
- Type safety for encrypted and decrypted results
154
160
155
-
### Type inference from schema
161
+
### Using explicit type parameters
156
162
157
-
The model operations can infer types from your schema definition:
163
+
You can still pass an explicit type parameter for backward compatibility. When you do, the schema type parameter defaults to the widened `ProtectTableColumn`, and the return type degrades gracefully to your provided type (same behavior as before):
158
164
159
165
```typescript
160
-
const users =encryptedTable("users", {
161
-
email: encryptedColumn("email").freeTextSearch(),
162
-
address: encryptedColumn("address"),
163
-
});
166
+
// Explicit type parameter — return type is User (no schema-aware mapping)
167
+
const result =awaitclient.encryptModel<User>(user, users);
164
168
165
-
// Types are inferred from the schema
166
-
const result =awaitclient.encryptModel(user, users);
167
-
// Result type includes encrypted fields for email and address
169
+
// For full schema-aware types with explicit parameters, provide both:
170
+
const result =awaitclient.encryptModel<User, typeofusers>(user, users);
168
171
```
169
172
173
+
> [!TIP]
174
+
> For the best developer experience, omit the type parameter and let TypeScript infer the schema-aware return type from the `table` argument.
175
+
170
176
## Identity-aware model operations
171
177
172
178
All model operations support lock contexts for identity-aware encryption:
Encrypt or decrypt an entire object. Only fields matching your schema are encrypted; other fields pass through unchanged.
141
141
142
+
The return type is **schema-aware**: fields matching the table schema are typed as `Encrypted`, while other fields retain their original types. For best results, let TypeScript infer the type parameters from the arguments:
0 commit comments