Skip to content

Commit d2a9c3b

Browse files
committed
fix: sync array_index_mode to stack schema and clean up code
- Add array_index_mode support to packages/stack/src/schema (was only in packages/schema, causing silent divergence) - Update stack schema builder tests for array_index_mode - Remove empty constructors from ProtectClient and EncryptionClient - Replace TOCTOU existsSync check with try/catch in drizzle migration generator
1 parent afeb1e5 commit d2a9c3b

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

packages/drizzle/src/bin/generate-eql-migration.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ async function main(): Promise<void> {
8585
const eqlSql = await response.text()
8686

8787
const drizzlePath = resolve(process.cwd(), args.drizzleDir)
88-
if (!existsSync(drizzlePath)) {
88+
89+
let files: string[]
90+
try {
91+
files = await readdir(drizzlePath)
92+
} catch {
8993
throw new Error(
9094
`Drizzle directory not found: ${drizzlePath}\nMake sure to run this command from your project root.`,
9195
)
9296
}
93-
94-
const files = await readdir(drizzlePath)
9597
const migrationFile = files
9698
.filter(
9799
(file) => file.endsWith('.sql') && file.includes(args.migrationName),

packages/protect/src/ffi/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export const noClientError = () =>
4747
export class ProtectClient {
4848
private client: Client
4949
private encryptConfig: EncryptConfig | undefined
50-
constructor() {}
51-
5250

5351
/**
5452
* Initializes the ProtectClient with the provided configuration.

packages/stack/__tests__/schema-builders.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('schema builders', () => {
114114
const built = col.build()
115115
expect(built.cast_as).toBe('json')
116116
expect(built.indexes).toHaveProperty('ste_vec')
117-
expect(built.indexes.ste_vec).toEqual({ prefix: 'enabled' })
117+
expect(built.indexes.ste_vec).toEqual({ prefix: 'enabled', array_index_mode: 'all' })
118118
})
119119

120120
it('chaining multiple indexes: .equality().freeTextSearch().orderAndRange()', () => {
@@ -222,6 +222,7 @@ describe('schema builders', () => {
222222
expect(built.columns.metadata.cast_as).toBe('json')
223223
expect(built.columns.metadata.indexes.ste_vec).toEqual({
224224
prefix: 'documents/metadata',
225+
array_index_mode: 'all',
225226
})
226227
})
227228

@@ -296,6 +297,7 @@ describe('schema builders', () => {
296297

297298
expect(config.tables.documents.metadata.indexes.ste_vec).toEqual({
298299
prefix: 'documents/metadata',
300+
array_index_mode: 'all',
299301
})
300302
})
301303
})

packages/stack/src/encryption/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export class EncryptionClient {
4949
private client: Client
5050
private encryptConfig: EncryptConfig | undefined
5151

52-
constructor() {}
53-
5452
/**
5553
* Initializes the EncryptionClient with the provided configuration.
5654
* @internal

packages/stack/src/schema/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,19 @@ const matchIndexOptsSchema = z.object({
104104
include_original: z.boolean().default(false).optional(),
105105
})
106106

107+
const arrayIndexModeSchema = z.union([
108+
z.literal('all'),
109+
z.literal('none'),
110+
z.object({
111+
item: z.boolean().optional(),
112+
wildcard: z.boolean().optional(),
113+
position: z.boolean().optional(),
114+
}),
115+
])
116+
107117
const steVecIndexOptsSchema = z.object({
108118
prefix: z.string(),
119+
array_index_mode: arrayIndexModeSchema.optional(),
109120
})
110121

111122
const indexesSchema = z
@@ -379,7 +390,7 @@ export class EncryptedColumn {
379390
*/
380391
searchableJson() {
381392
this.castAsValue = 'json'
382-
this.indexesValue.ste_vec = { prefix: 'enabled' }
393+
this.indexesValue.ste_vec = { prefix: 'enabled', array_index_mode: 'all' }
383394
return this
384395
}
385396

@@ -461,6 +472,7 @@ export class EncryptedTable<T extends EncryptedTableColumn> {
461472
indexes: {
462473
...builtColumn.indexes,
463474
ste_vec: {
475+
...builtColumn.indexes.ste_vec,
464476
prefix: `${this.tableName}/${colName}`,
465477
},
466478
},

0 commit comments

Comments
 (0)