Skip to content

Commit 43fd249

Browse files
MH4GFclaude
andcommitted
refactor: extract shared path schemas to reduce duplication
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent df53d71 commit 43fd249

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

frontend/packages/db-structure/src/operation/schema/column.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import type { Operation } from './index.js'
66

77
const isColumnPath = createPathValidator(PATH_PATTERNS.COLUMN_BASE)
88

9+
const columnPathSchema = v.custom<`/tables/${string}/columns/${string}`>(
10+
isColumnPath,
11+
'Path must match the pattern /tables/{tableName}/columns/{columnName}',
12+
)
13+
914
// Add column operation
1015
const addColumnOperationSchema = v.object({
1116
op: v.literal('add'),
12-
path: v.custom<`/tables/${string}/columns/${string}`>(
13-
isColumnPath,
14-
'Path must match the pattern /tables/{tableName}/columns/{columnName}',
15-
),
17+
path: columnPathSchema,
1618
value: columnSchema,
1719
})
1820

@@ -27,10 +29,7 @@ export const isAddColumnOperation = (
2729
// Remove column operation
2830
const removeColumnOperationSchema = v.object({
2931
op: v.literal('remove'),
30-
path: v.custom<`/tables/${string}/columns/${string}`>(
31-
isColumnPath,
32-
'Path must match the pattern /tables/{tableName}/columns/{columnName}',
33-
),
32+
path: columnPathSchema,
3433
})
3534

3635
export type RemoveColumnOperation = v.InferOutput<

frontend/packages/db-structure/src/operation/schema/table.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ import type { Operation } from './index.js'
66

77
const isTablePath = createPathValidator(PATH_PATTERNS.TABLE_BASE)
88

9+
const tablePathSchema = v.custom<`/tables/${string}`>(
10+
isTablePath,
11+
'Path must match the pattern /tables/{tableName}',
12+
)
13+
914
const addTableOperationSchema = v.object({
1015
op: v.literal('add'),
11-
path: v.custom<`/tables/${string}`>(
12-
isTablePath,
13-
'Path must match the pattern /tables/{tableName}',
14-
),
16+
path: tablePathSchema,
1517
value: tableSchema,
1618
})
1719

1820
const removeTableOperationSchema = v.object({
1921
op: v.literal('remove'),
20-
path: v.custom<`/tables/${string}`>(
21-
isTablePath,
22-
'Path must match the pattern /tables/{tableName}',
23-
),
22+
path: tablePathSchema,
2423
})
2524

2625
export type AddTableOperation = v.InferOutput<typeof addTableOperationSchema>

0 commit comments

Comments
 (0)