@@ -12,29 +12,35 @@ const CREATED_OTS_DEFAULT_CONFIG = {
1212 } ,
1313 } ,
1414} ;
15- const FIELD_KEYWORD = {
16- fieldType : TableStore . FieldType . KEYWORD ,
17- index : true ,
18- enableSortAndAgg : true ,
19- store : true ,
15+
16+ const ID_FIELD = {
17+ fieldName : 'id' ,
18+ fieldType : TableStore . FieldType . KEYWORD , // 设置字段名和字段类型。
19+ index : true , // 设置开启索引。
20+ enableSortAndAgg : true , // 设置开启排序与统计聚合功能。
21+ store : true , // 开启后,可以直接从多元索引中读取该字段的值,而不必反查数据表,可用于查询性能优化。
22+ } ;
23+
24+
25+ function getDefinedColumn ( data : Record < string , number > ) : { type : number ; name : string ; } [ ] {
26+ return Object . keys ( data ) . map ( name => ( { name, type : data [ name ] } ) )
2027}
2128
22- const TIMER_FIELD = [
23- {
24- fieldName : 'updated_time' ,
25- fieldType : TableStore . FieldType . LONG ,
26- index : true ,
27- enableSortAndAgg : true ,
28- store : true ,
29- } ,
30- {
31- fieldName : 'created_time' ,
32- fieldType : TableStore . FieldType . LONG ,
29+ function getFieldSchemas ( data : Record < string , number > ) : {
30+ fieldName : string ;
31+ fieldType : number ;
32+ index : boolean ;
33+ enableSortAndAgg : boolean ;
34+ store : boolean ;
35+ } [ ] {
36+ return Object . keys ( data ) . map ( fieldName => ( {
3337 index : true ,
3438 enableSortAndAgg : true ,
3539 store : true ,
36- }
37- ] ;
40+ fieldType : data [ fieldName ] ,
41+ fieldName,
42+ } ) )
43+ }
3844
3945/*
4046Table user {
@@ -49,12 +55,23 @@ Table user {
4955 updated_time timestamp
5056}
5157*/
58+ const USER_DEFINED_COLUMN = {
59+ avatar : TableStore . DefinedColumnType . DCT_STRING , // 头像
60+ username : TableStore . DefinedColumnType . DCT_STRING , // 名称
61+ password : TableStore . DefinedColumnType . DCT_STRING , // 登录密码(加密)
62+ secrets : TableStore . DefinedColumnType . DCT_STRING , // 个人密钥
63+ third_part : TableStore . DefinedColumnType . DCT_STRING , // 三方绑定(github等)登录的信息
64+ github_unionid : TableStore . DefinedColumnType . DCT_STRING , // github授权的唯一标识ID
65+ created_time : TableStore . DefinedColumnType . DCT_INTEGER ,
66+ updated_time : TableStore . DefinedColumnType . DCT_INTEGER ,
67+ }
5268export const user = ( tableName : string ) => ( {
5369 tableMeta : {
5470 tableName,
5571 primaryKey : [
5672 { name : 'id' , type : 'STRING' } ,
5773 ] ,
74+ definedColumn : getDefinedColumn ( USER_DEFINED_COLUMN ) ,
5875 } ,
5976 ...CREATED_OTS_DEFAULT_CONFIG ,
6077} ) ;
@@ -64,71 +81,10 @@ export const userIndex = (tableName: string, indexName: string) => ({
6481 indexName,
6582 schema : {
6683 fieldSchemas : [
67- {
68- fieldName : 'id' ,
69- fieldType : TableStore . FieldType . KEYWORD , // 设置字段名和字段类型。
70- index : true , // 设置开启索引。
71- enableSortAndAgg : true , // 设置开启排序与统计聚合功能。
72- store : true , // 开启后,可以直接从多元索引中读取该字段的值,而不必反查数据表,可用于查询性能优化。
73- } ,
74- {
75- fieldName : 'github_unionid' ,
76- fieldType : TableStore . FieldType . KEYWORD ,
77- index : true ,
78- enableSortAndAgg : true ,
79- store : true ,
80- } ,
81- {
82- fieldName : 'third_part' ,
83- fieldType : TableStore . FieldType . KEYWORD ,
84- index : true ,
85- enableSortAndAgg : true ,
86- store : true ,
87- } ,
88- {
89- fieldName : 'secrets' ,
90- fieldType : TableStore . FieldType . KEYWORD ,
91- index : true ,
92- enableSortAndAgg : true ,
93- store : true ,
94- } ,
95- {
96- fieldName : 'password' ,
97- fieldType : TableStore . FieldType . KEYWORD ,
98- index : true ,
99- enableSortAndAgg : true ,
100- store : true ,
101- } ,
102- {
103- fieldName : 'username' ,
104- fieldType : TableStore . FieldType . KEYWORD ,
105- index : true ,
106- enableSortAndAgg : true ,
107- store : true ,
108- } ,
109- {
110- fieldName : 'avatar' ,
111- fieldType : TableStore . FieldType . KEYWORD ,
112- index : true ,
113- enableSortAndAgg : true ,
114- store : true ,
115- } ,
116- {
117- fieldName : 'updated_time' ,
118- fieldType : TableStore . FieldType . LONG ,
119- index : true ,
120- enableSortAndAgg : true ,
121- store : true ,
122- } ,
123- {
124- fieldName : 'created_time' ,
125- fieldType : TableStore . FieldType . LONG ,
126- index : true ,
127- enableSortAndAgg : true ,
128- store : true ,
129- } ,
84+ ID_FIELD ,
85+ ...getFieldSchemas ( USER_DEFINED_COLUMN )
13086 ]
131- }
87+ } ,
13288} ) ;
13389
13490/*
@@ -147,31 +103,41 @@ Table application {
147103 updated_time timestamp
148104}
149105*/
106+ const APP_DEFINED_COLUMN = {
107+ user_id : TableStore . DefinedColumnType . DCT_STRING ,
108+ owner : TableStore . DefinedColumnType . DCT_STRING ,
109+ provider : TableStore . DefinedColumnType . DCT_STRING ,
110+ provider_repo_id : TableStore . DefinedColumnType . DCT_STRING ,
111+ repo_name : TableStore . DefinedColumnType . DCT_STRING ,
112+ repo_url : TableStore . DefinedColumnType . DCT_STRING ,
113+ secrets : TableStore . DefinedColumnType . DCT_STRING ,
114+ latest_task : TableStore . DefinedColumnType . DCT_STRING ,
115+ trigger_spec : TableStore . DefinedColumnType . DCT_STRING ,
116+ created_time : TableStore . DefinedColumnType . DCT_INTEGER ,
117+ updated_time : TableStore . DefinedColumnType . DCT_INTEGER ,
118+ }
119+
150120export const application = ( tableName : string ) => ( {
151121 tableMeta : {
152122 tableName,
153123 primaryKey : [
154124 { name : 'id' , type : 'STRING' } ,
155125 ] ,
126+ definedColumn : getDefinedColumn ( APP_DEFINED_COLUMN ) ,
156127 } ,
157128 ...CREATED_OTS_DEFAULT_CONFIG ,
158129} ) ;
159130
160- export const applicationIndex = ( tableName : string , indexName : string ) => {
161- const fieldSchemas = [ ...TIMER_FIELD ] ;
162- const stringKeys = [ 'id' , 'user_id' , 'owner' , 'provider' , 'provider_repo_id' , 'repo_name' , 'repo_url' , 'secrets' , 'latest_task' , 'trigger_spec' ] ;
163- stringKeys . forEach ( fieldName => fieldSchemas . push ( {
164- ...FIELD_KEYWORD ,
165- fieldName,
166- } ) ) ;
167-
168- return {
169- tableName,
170- indexName,
171- schema : { fieldSchemas } ,
172- }
173- }
174-
131+ export const applicationIndex = ( tableName : string , indexName : string ) => ( {
132+ tableName,
133+ indexName,
134+ schema : {
135+ fieldSchemas : [
136+ ID_FIELD ,
137+ ...getFieldSchemas ( APP_DEFINED_COLUMN )
138+ ]
139+ } ,
140+ } )
175141
176142/*
177143Table task {
@@ -185,30 +151,37 @@ Table task {
185151 updated_time timestamp
186152}
187153*/
154+ const TASK_DEFINED_COLUMN = {
155+ user_id : TableStore . DefinedColumnType . DCT_STRING ,
156+ app_id : TableStore . DefinedColumnType . DCT_STRING ,
157+ status : TableStore . DefinedColumnType . DCT_STRING ,
158+ steps : TableStore . DefinedColumnType . DCT_STRING ,
159+ trigger_payload : TableStore . DefinedColumnType . DCT_STRING ,
160+ created_time : TableStore . DefinedColumnType . DCT_INTEGER ,
161+ updated_time : TableStore . DefinedColumnType . DCT_INTEGER ,
162+ }
188163export const task = ( tableName : string ) => ( {
189164 tableMeta : {
190165 tableName,
191166 primaryKey : [
192167 { name : 'id' , type : 'STRING' } ,
193168 ] ,
169+ definedColumn : getDefinedColumn ( TASK_DEFINED_COLUMN ) ,
194170 } ,
195171 ...CREATED_OTS_DEFAULT_CONFIG ,
196172} ) ;
197173
198- export const taskIndex = ( tableName : string , indexName : string ) => {
199- const fieldSchemas = [ ...TIMER_FIELD ] ;
200- const stringKeys = [ 'id' , 'user_id' , 'app_id' , 'status' , 'steps' , 'trigger_payload' ] ;
201- stringKeys . forEach ( fieldName => fieldSchemas . push ( {
202- ...FIELD_KEYWORD ,
203- fieldName,
204- } ) )
174+ export const taskIndex = ( tableName : string , indexName : string ) => ( {
175+ tableName,
176+ indexName,
177+ schema : {
178+ fieldSchemas : [
179+ ID_FIELD ,
180+ ...getFieldSchemas ( TASK_DEFINED_COLUMN )
181+ ]
182+ } ,
183+ } )
205184
206- return {
207- tableName,
208- indexName,
209- schema : { fieldSchemas } ,
210- }
211- }
212185
213186/*
214187Table token {
@@ -222,30 +195,36 @@ Table token {
222195 updated_time timestamp
223196}
224197*/
198+ const TOKEN_DEFINED_COLUMN = {
199+ team_id : TableStore . DefinedColumnType . DCT_STRING ,
200+ cd_token : TableStore . DefinedColumnType . DCT_STRING ,
201+ descripion : TableStore . DefinedColumnType . DCT_STRING ,
202+ active_time : TableStore . DefinedColumnType . DCT_STRING ,
203+ expire_time : TableStore . DefinedColumnType . DCT_STRING ,
204+ created_time : TableStore . DefinedColumnType . DCT_INTEGER ,
205+ updated_time : TableStore . DefinedColumnType . DCT_INTEGER ,
206+ }
225207export const token = ( tableName : string ) => ( {
226208 tableMeta : {
227209 tableName,
228210 primaryKey : [
229211 { name : 'id' , type : 'STRING' } ,
230212 ] ,
213+ definedColumn : getDefinedColumn ( TOKEN_DEFINED_COLUMN ) ,
231214 } ,
232215 ...CREATED_OTS_DEFAULT_CONFIG ,
233216} ) ;
234217
235- export const tokenIndex = ( tableName : string , indexName : string ) => {
236- const fieldSchemas = [ ...TIMER_FIELD ] ;
237- const stringKeys = [ 'id' , 'user_id' , 'team_id' , 'cd_token' , 'descripion' , 'active_time' , 'expire_time' ] ;
238- stringKeys . forEach ( fieldName => fieldSchemas . push ( {
239- ...FIELD_KEYWORD ,
240- fieldName,
241- } ) )
242-
243- return {
244- tableName,
245- indexName,
246- schema : { fieldSchemas } ,
247- }
248- }
218+ export const tokenIndex = ( tableName : string , indexName : string ) => ( {
219+ tableName,
220+ indexName,
221+ schema : {
222+ fieldSchemas : [
223+ ID_FIELD ,
224+ ...getFieldSchemas ( TOKEN_DEFINED_COLUMN )
225+ ]
226+ } ,
227+ } )
249228
250229/*
251230Table session {
@@ -256,6 +235,12 @@ Table session {
256235 updated_time timestamp
257236}
258237*/
238+ const SESSION_DEFINED_COLUMN = {
239+ session_data : TableStore . DefinedColumnType . DCT_STRING ,
240+ expire_time : TableStore . DefinedColumnType . DCT_STRING ,
241+ created_time : TableStore . DefinedColumnType . DCT_INTEGER ,
242+ updated_time : TableStore . DefinedColumnType . DCT_INTEGER ,
243+ }
259244export const session = ( tableName : string , { SESSION_EXPIRATION } : any = { } ) => {
260245 CREATED_OTS_DEFAULT_CONFIG . tableOptions . timeToLive = ( SESSION_EXPIRATION || 1000 * 60 * 60 * 24 * 7 ) / 1000 ;
261246 return {
@@ -264,6 +249,7 @@ export const session = (tableName: string, { SESSION_EXPIRATION }: any = {}) =>
264249 primaryKey : [
265250 { name : 'id' , type : 'STRING' } ,
266251 ] ,
252+ definedColumn : getDefinedColumn ( SESSION_DEFINED_COLUMN ) ,
267253 } ,
268254 ...CREATED_OTS_DEFAULT_CONFIG ,
269255 } ;
0 commit comments