Skip to content

Commit 7b99308

Browse files
committed
fix: eql type mapping
1 parent 391f57f commit 7b99308

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.changeset/chilly-paths-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cipherstash/stack": minor
3+
---
4+
5+
Fix data type mapping issues to EQL types.

packages/stack/src/schema/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ export const encryptConfigSchema = z.object({
9999
* @see {@link castAsEnum} for possible values.
100100
*/
101101
export type CastAs = z.infer<typeof castAsEnum>
102+
103+
// Map SDK-friendly cast names to EQL database names
104+
const castAsToEql: Record<CastAs, string> = {
105+
string: 'text',
106+
text: 'text',
107+
number: 'int',
108+
bigint: 'big_int',
109+
boolean: 'boolean',
110+
date: 'date',
111+
json: 'jsonb',
112+
}
113+
114+
function mapCastAs(castAs: CastAs): string {
115+
return castAsToEql[castAs] ?? castAs
116+
}
117+
102118
export type TokenFilter = z.infer<typeof tokenFilterSchema>
103119
export type MatchIndexOpts = z.infer<typeof matchIndexOptsSchema>
104120
export type SteVecIndexOpts = z.infer<typeof steVecIndexOptsSchema>
@@ -169,7 +185,7 @@ export class EncryptedField {
169185

170186
build() {
171187
return {
172-
cast_as: this.castAsValue === 'string' ? 'text' : this.castAsValue,
188+
cast_as: mapCastAs(this.castAsValue),
173189
indexes: {},
174190
}
175191
}
@@ -338,7 +354,7 @@ export class EncryptedColumn {
338354

339355
build() {
340356
return {
341-
cast_as: this.castAsValue === 'string' ? 'text' : this.castAsValue,
357+
cast_as: mapCastAs(this.castAsValue),
342358
indexes: this.indexesValue,
343359
}
344360
}

0 commit comments

Comments
 (0)