1+ import { DataTypes , LiteralDataTypes } from "@src/core/DDL/abstracts/BaseFieldBuilder" ;
12import Schema from "@src/core/DDL/implements/Schema"
23
34export type MissingSchemaStrategy = 'create' | 'ignore' | 'error'
45
56// 이 인터페이스는 이제 Configs.ts에서 직접 정의되므로 주석 처리하거나 삭제할 수 있습니다.
67export interface SchemaConfigOptions < T extends Schema [ ] > {
78 onMissingSchema ?: MissingSchemaStrategy ;
9+ recordDetailType ?:boolean ,
10+ parseDetailType ?:boolean ,
811 schemas ?: T ;
912}
1013
@@ -13,11 +16,38 @@ export type SchemaMap<T extends Schema[]> = {
1316}
1417
1518class SchemaConfig < T extends Schema [ ] > {
16- missingSchemaStartegy : MissingSchemaStrategy
1719 readonly DEFAULT_MISSING_STRATEGY : MissingSchemaStrategy = 'create'
20+
21+ missingSchemaStartegy : MissingSchemaStrategy
22+ recordDetailType : boolean
23+ parseDetailType : boolean
1824
1925 readonly schemaList : T ;
2026 readonly schemaMap : SchemaMap < T > ;
27+ schemaSetted :boolean
28+
29+ // type parser for spreadsheet values
30+ typeParsers :Record < LiteralDataTypes , ( value :string ) => DataTypes > = {
31+ boolean :( value ) => value === "true" ,
32+ date : ( value ) => new Date ( value ) ,
33+ number : ( value ) => Number ( value ) ,
34+ string : ( value ) => value ,
35+ }
36+
37+ constructor ( {
38+ onMissingSchema = this . DEFAULT_MISSING_STRATEGY ,
39+ recordDetailType = true ,
40+ parseDetailType = true ,
41+ schemas = [ ] as unknown as T ,
42+ } : SchemaConfigOptions < T > ) {
43+ this . missingSchemaStartegy = onMissingSchema ;
44+ this . recordDetailType = recordDetailType ;
45+ this . parseDetailType = parseDetailType ;
46+
47+ this . schemaList = schemas ;
48+ this . schemaSetted = this . schemaList . length > 0 ;
49+ this . schemaMap = this . makeSchemaMap ( this . schemaList ) ;
50+ }
2151
2252 private makeSchemaMap ( schemas :T ) {
2353 const schemaMap = schemas . reduce ( ( schemaDefinition , schema ) => {
@@ -27,12 +57,6 @@ class SchemaConfig<T extends Schema[]>{
2757 } , { } as SchemaMap < T > )
2858 return schemaMap
2959 }
30-
31- constructor ( options : SchemaConfigOptions < T > ) {
32- this . missingSchemaStartegy = options . onMissingSchema ?? this . DEFAULT_MISSING_STRATEGY
33- this . schemaList = ( options . schemas ?? [ ] ) as T
34- this . schemaMap = this . makeSchemaMap ( this . schemaList )
35- }
3660}
3761export default SchemaConfig
3862
0 commit comments