Skip to content

Commit 60fbd69

Browse files
committed
feat: change cls index from snake_case to camelCase
1 parent 6e3ec19 commit 60fbd69

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

__tests__/cls/notice.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CreateNoticeOptions, CreateNoticeResult } from '../../src/modules/cls/interface';
22
import { ClsNotice } from '../../src';
33

4-
describe('Cls Alarm', () => {
4+
describe('Cls Notice', () => {
55
const credentials = {
66
SecretId: process.env.TENCENT_SECRET_ID,
77
SecretKey: process.env.TENCENT_SECRET_KEY,

src/modules/cls/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,34 @@ export default class Cls {
152152

153153
// 更新索引
154154
async deployIndex(inputs: DeployIndexInputs) {
155-
if (inputs.rule) {
155+
if (inputs.indexRule) {
156156
console.log('Deploying index');
157157

158+
const { fullText, keyValue } = inputs.indexRule!;
159+
let parsedFullText;
160+
let parsedKeyValue: any;
161+
if (fullText) {
162+
parsedFullText = {
163+
case_sensitive: fullText.caseSensitive,
164+
tokenizer: fullText.tokenizer,
165+
};
166+
parsedKeyValue = {
167+
case_sensitive: keyValue?.caseSensitive!,
168+
keys: keyValue?.keys?.map((v) => v.key) ?? [],
169+
types: keyValue?.keys?.map((v) => v.type) ?? [],
170+
sql_flags: keyValue?.keys?.map((v) => v.sqlFlag) ?? [],
171+
tokenizers: keyValue?.keys.map((v) => v.tokenizer) ?? [],
172+
};
173+
}
158174
try {
159175
await updateIndex(this.clsClient, {
160176
topicId: inputs.topicId!,
161177
// FIXME: effective is always true in updateIndex
162178
effective: inputs.effective !== false ? true : false,
163-
rule: inputs.rule,
179+
rule: {
180+
full_text: parsedFullText,
181+
key_value: parsedKeyValue,
182+
},
164183
});
165184
} catch (err) {
166185
console.log('' + err);

src/modules/cls/interface.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { IndexRule } from '@tencent-sdk/cls/dist/typings';
21
import { RegionType, CamelCasedProps } from './../interface';
32
import { DeployDashboardInputs } from './dashboard';
43

@@ -162,7 +161,21 @@ export interface DeployTopicInputs {
162161
export interface DeployIndexInputs {
163162
topicId?: string;
164163
effective?: boolean;
165-
rule?: IndexRule;
164+
indexRule?: {
165+
fullText: {
166+
caseSensitive: boolean;
167+
tokenizer: string;
168+
};
169+
keyValue?: {
170+
caseSensitive: boolean;
171+
keys: {
172+
key: string;
173+
type: string;
174+
sqlFlag: boolean;
175+
tokenizer: string;
176+
}[];
177+
};
178+
};
166179
}
167180

168181
export interface AlarmInputs {

0 commit comments

Comments
 (0)