@@ -13,6 +13,9 @@ import { and, eq, inArray, isNotNull, isNull, or, sql } from 'drizzle-orm'
1313import { OrchestrationError } from '@/lib/core/orchestration/types'
1414import type { DbOrTx , DbTransaction } from '@/lib/db/types'
1515import {
16+ ALL_TAG_SLOTS ,
17+ type AllTagSlot ,
18+ getFieldTypeForSlot ,
1619 getSlotsForFieldType ,
1720 isValidSlotForFieldType ,
1821 SUPPORTED_FIELD_TYPES ,
@@ -27,25 +30,7 @@ import type {
2730
2831const logger = createLogger ( 'TagsService' )
2932
30- /** Text tag slots */
31- const VALID_TEXT_SLOTS = [ 'tag1' , 'tag2' , 'tag3' , 'tag4' , 'tag5' , 'tag6' , 'tag7' ] as const
32-
33- const VALID_NUMBER_SLOTS = [ 'number1' , 'number2' , 'number3' , 'number4' , 'number5' ] as const
34- /** Date tag slots (reduced to 2 for write performance) */
35- const VALID_DATE_SLOTS = [ 'date1' , 'date2' ] as const
36- /** Boolean tag slots */
37- const VALID_BOOLEAN_SLOTS = [ 'boolean1' , 'boolean2' , 'boolean3' ] as const
38-
39- /** All valid tag slots combined */
40- const VALID_TAG_SLOTS = [
41- ...VALID_TEXT_SLOTS ,
42- ...VALID_NUMBER_SLOTS ,
43- ...VALID_DATE_SLOTS ,
44- ...VALID_BOOLEAN_SLOTS ,
45- ] as const
46-
47- type ValidTagSlot = ( typeof VALID_TAG_SLOTS ) [ number ]
48- type ClearedTagValues = Partial < Record < ValidTagSlot , null > >
33+ type ClearedTagValues = Partial < Record < AllTagSlot , null > >
4934const TAG_MUTATION_STATEMENT_TIMEOUT_MS = 120_000
5035const TAG_MUTATION_LOCK_TIMEOUT_MS = 5_000
5136const TAG_MUTATION_IDLE_TIMEOUT_MS = 30_000
@@ -63,9 +48,9 @@ export class KnowledgeTagProvenanceConflictError extends OrchestrationError {
6348/**
6449 * Validates that a tag slot is a valid slot name
6550 */
66- function validateTagSlot ( tagSlot : string ) : asserts tagSlot is ValidTagSlot {
67- if ( ! VALID_TAG_SLOTS . includes ( tagSlot as ValidTagSlot ) ) {
68- throw new Error ( `Invalid tag slot: ${ tagSlot } . Must be one of: ${ VALID_TAG_SLOTS . join ( ', ' ) } ` )
51+ function validateTagSlot ( tagSlot : string ) : asserts tagSlot is AllTagSlot {
52+ if ( ! ALL_TAG_SLOTS . includes ( tagSlot as AllTagSlot ) ) {
53+ throw new Error ( `Invalid tag slot: ${ tagSlot } . Must be one of: ${ ALL_TAG_SLOTS . join ( ', ' ) } ` )
6954 }
7055}
7156
@@ -120,7 +105,7 @@ async function assertKnowledgeBaseTagsCanBeClearedInTx(
120105async function clearTagSlotsInTx (
121106 tx : DbTransaction ,
122107 knowledgeBaseId : string ,
123- tagSlots : readonly ValidTagSlot [ ]
108+ tagSlots : readonly AllTagSlot [ ]
124109) : Promise < void > {
125110 if ( tagSlots . length === 0 ) return
126111
@@ -150,17 +135,6 @@ async function clearTagSlotsInTx(
150135 )
151136}
152137
153- /**
154- * Get the field type for a tag slot
155- */
156- function getFieldTypeForSlot ( tagSlot : string ) : string | null {
157- if ( ( VALID_TEXT_SLOTS as readonly string [ ] ) . includes ( tagSlot ) ) return 'text'
158- if ( ( VALID_NUMBER_SLOTS as readonly string [ ] ) . includes ( tagSlot ) ) return 'number'
159- if ( ( VALID_DATE_SLOTS as readonly string [ ] ) . includes ( tagSlot ) ) return 'date'
160- if ( ( VALID_BOOLEAN_SLOTS as readonly string [ ] ) . includes ( tagSlot ) ) return 'boolean'
161- return null
162- }
163-
164138/**
165139 * Get the next available slot for a knowledge base and field type
166140 */
@@ -499,7 +473,7 @@ export async function createOrUpdateTagDefinitionsBulk(
499473 const newDefinition = {
500474 id : generateId ( ) ,
501475 knowledgeBaseId,
502- tagSlot : finalTagSlot as ValidTagSlot ,
476+ tagSlot : finalTagSlot as AllTagSlot ,
503477 displayName,
504478 fieldType,
505479 createdAt : new Date ( ) ,
@@ -746,7 +720,7 @@ async function insertTagDefinition(
746720 const newDefinition = {
747721 id : tagDefinitionId ,
748722 knowledgeBaseId : data . knowledgeBaseId ,
749- tagSlot : data . tagSlot as ValidTagSlot ,
723+ tagSlot : data . tagSlot as AllTagSlot ,
750724 displayName : data . displayName ,
751725 fieldType : data . fieldType ,
752726 createdAt : now ,
0 commit comments