Skip to content

Commit f2ffba5

Browse files
committed
feat: add faas module
1 parent 9508663 commit f2ffba5

File tree

18 files changed

+1048
-1
lines changed

18 files changed

+1048
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Tencent Cloud SDK
88
| ----------------------- | ------------------------------------------------------ | ----------------------------------------------------------- |
99
| `@tencent-sdk/capi` | [@tencent-sdk/capi](./packages/capi/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/capi) |
1010
| `@tencent-sdk/login` | [@tencent-sdk/login](./packages/login/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/login) |
11+
| `@tencent-sdk/faas` | [@tencent-sdk/faas](./packages/faas/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/faas) |
1112
| `@tencent-sdk/cls` | [@tencent-sdk/cls](./packages/cls/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/cls) |
1213
| `@tencent-sdk/capi-web` | [@tencent-sdk/capi-web](./packages/capi-web/README.md) | [Link](https://www.npmjs.com/package/@tencent-sdk/capi-web) |
1314

packages/common/.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
*.map
3+
tsconfig.tsbuildinfo
4+
test
5+
tests
6+
__test__
7+
__tests__
8+
src
9+
tsconfig.json

packages/common/README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
## Tencent Cloud FaaS SDK
2+
3+
This is a SDK tool for [Tencent Cloud FaaS](https://console.cloud.tencent.com/scf) service.
4+
5+
## Usage
6+
7+
`Cls` is the only class for create a client request instance.
8+
You can use it like below:
9+
10+
```js
11+
import { Cls } from '@tencent-sdk/cls';
12+
13+
const client = new Cls({
14+
region: 'ap-guangzhou',
15+
secretId: 'Please input your SecretId',
16+
secretKey: 'Please input your SecretKey',
17+
token: 'Please input your Token',
18+
debug: false,
19+
});
20+
```
21+
22+
Support methods:
23+
24+
- [getLogsetList()](#getLogsetList)
25+
- [createLogset()](#createLogset)
26+
- [getLogset()](#getLogset)
27+
- [deleteLogset()](#deleteLogset)
28+
- [getTopicList()](#getTopicList)
29+
- [createTopic()](#createTopic)
30+
- [getTopic()](#getTopic)
31+
- [deleteTopic()](#deleteTopic)
32+
- [updateIndex()](#updateIndex)
33+
- [getIndex()](#getIndex)
34+
35+
### getLogsetList
36+
37+
Get logset list:
38+
39+
```js
40+
const res = await client.getLogsetList();
41+
```
42+
43+
### createLogset
44+
45+
Create logset:
46+
47+
```js
48+
const res = await client.createLogset({
49+
logset_name: 'cls-test',
50+
period: 7,
51+
});
52+
```
53+
54+
### getLogset
55+
56+
Get logset:
57+
58+
```js
59+
const res = await client.getLogset({
60+
logset_id: 'xxx-xxx',
61+
});
62+
```
63+
64+
### deleteLogset
65+
66+
Delete logset:
67+
68+
```js
69+
const res = await client.deleteLogset({
70+
logset_id: 'xxx-xxx',
71+
});
72+
```
73+
74+
### getTopicList
75+
76+
Get topic list:
77+
78+
```js
79+
const res = await client.getTopicList();
80+
```
81+
82+
### createTopic
83+
84+
Create topic:
85+
86+
```js
87+
const res = await client.createTopic({
88+
logset_id: 'xxx-xxx',
89+
topic_name: 'cls-test-topic',
90+
});
91+
```
92+
93+
### getTopic
94+
95+
Get topic:
96+
97+
```js
98+
const res = await client.getTopic({
99+
topic_id: 'xxx-xxx',
100+
});
101+
```
102+
103+
### deleteTopic
104+
105+
Delete topic:
106+
107+
```js
108+
const res = await client.deleteTopic({
109+
topic_id: 'xxx-xxx',
110+
});
111+
```
112+
113+
### updateIndex
114+
115+
Update topic index:
116+
117+
```js
118+
const res = await client.updateIndex({
119+
topic_id: 'xxx-xxx',
120+
effective: true,
121+
rule: {
122+
full_text: {
123+
case_sensitive: true,
124+
tokenizer: '!@#%^&*()_="\', <>/?|\\;:\n\t\r[]{}',
125+
},
126+
key_value: {
127+
case_sensitive: true,
128+
keys: ['SCF_RetMsg'],
129+
types: ['text'],
130+
tokenizers: [' '],
131+
},
132+
},
133+
});
134+
```
135+
136+
### getIndex
137+
138+
Get topic index:
139+
140+
```js
141+
const res = await client.getIndex({
142+
topic_id: 'xxx-xxx',
143+
});
144+
```
145+
146+
### Custom methods
147+
148+
If you need methods expect above list, you can use `client.request()` like below:
149+
150+
```js
151+
// create cls shipper
152+
const res = await client.request({
153+
path: '/shipper',
154+
method: 'POST',
155+
data: {
156+
topic_id: 'xxxx-xx-xx-xx-xxxxxxxx',
157+
bucket: 'test-1250000001',
158+
prefix: 'test',
159+
shipper_name: 'myname',
160+
interval: 300,
161+
max_size: 100,
162+
partition: '%Y%m%d',
163+
compress: {
164+
format: 'none',
165+
},
166+
content: {
167+
format: 'csv',
168+
csv_info: {
169+
print_key: true,
170+
keys: ['key1', 'key2'],
171+
delimiter: '|',
172+
escape_char: "'",
173+
non_existing_field: 'null',
174+
},
175+
},
176+
},
177+
});
178+
```
179+
180+
## Options
181+
182+
```js
183+
const client = new Cls(ClsOptions);
184+
```
185+
186+
### `ClsOptions` for Cls Construct
187+
188+
| Name | Description | Type | Required | Default |
189+
| --------- | ------------------------------------ | ------- | -------- | ------------ |
190+
| region | request region | string | true | ap-guangzhou |
191+
| secretId | tencent account secret id | string | true | '' |
192+
| secretKey | tencent account secret key | string | true | '' |
193+
| token | tencent account token | string | false | '' |
194+
| debug | whether enable log debug info | boolean | false | false |
195+
| timeout | request timeout, unit `ms` | number | false | 5000 |
196+
| expire | expire time for signature, unit `ms` | number | false | 300000 |
197+
198+
## License
199+
200+
MIT
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { Cls } from '../src';
2+
3+
describe('Cls', () => {
4+
const client = new Cls({
5+
region: 'ap-guangzhou',
6+
secretId: process.env.TENCENT_SECRET_ID,
7+
secretKey: process.env.TENCENT_SECRET_KEY,
8+
token: process.env.TENCENT_TOKEN,
9+
debug: true,
10+
});
11+
12+
let logset_id;
13+
let topic_id;
14+
15+
test('create logset', async () => {
16+
const res = await client.createLogset({
17+
logset_name: 'cls-test',
18+
period: 7,
19+
});
20+
expect(res).toEqual({
21+
requestId: expect.any(String),
22+
logset_id: expect.any(String),
23+
});
24+
25+
logset_id = res.logset_id;
26+
});
27+
28+
test('get logset', async () => {
29+
const res = await client.getLogset({
30+
logset_id,
31+
});
32+
expect(res).toEqual({
33+
requestId: expect.any(String),
34+
create_time: expect.any(String),
35+
logset_id: logset_id,
36+
logset_name: 'cls-test',
37+
period: 7,
38+
topics_number: 0,
39+
});
40+
41+
logset_id = res.logset_id;
42+
});
43+
44+
test('get logset list', async () => {
45+
const res = await client.getLogsetList();
46+
expect(res).toEqual({
47+
requestId: expect.any(String),
48+
logsets: expect.any(Array),
49+
});
50+
51+
const [exist] = res.logsets.filter((item) => item.logset_id === logset_id);
52+
expect(exist).toEqual({
53+
create_time: expect.any(String),
54+
logset_id,
55+
logset_name: 'cls-test',
56+
period: 7,
57+
topics_number: 0,
58+
});
59+
});
60+
61+
test('create topic', async () => {
62+
const res = await client.createTopic({
63+
logset_id,
64+
topic_name: 'cls-test-topic',
65+
});
66+
expect(res).toEqual({
67+
requestId: expect.any(String),
68+
topic_id: expect.any(String),
69+
});
70+
71+
topic_id = res.topic_id;
72+
});
73+
74+
test('get topic', async () => {
75+
const res = await client.getTopic({
76+
topic_id,
77+
});
78+
expect(res).toEqual({
79+
requestId: expect.any(String),
80+
ExcludePaths: [],
81+
collection: true,
82+
create_time: expect.any(String),
83+
extract_rule: { filter_keys: [], filter_regex: [] },
84+
index: false,
85+
isolated: 0,
86+
log_format: '',
87+
log_type: 'minimalist_log',
88+
logset_id,
89+
multi_wild_path: [],
90+
partition_count: 1,
91+
path: '',
92+
shipper: false,
93+
sql_flag: true,
94+
topic_id,
95+
topic_name: 'cls-test-topic',
96+
});
97+
});
98+
99+
test('update index', async () => {
100+
const res = await client.updateIndex({
101+
topic_id,
102+
effective: true,
103+
rule: {
104+
full_text: {
105+
case_sensitive: true,
106+
tokenizer: '!@#%^&*()_="\', <>/?|\\;:\n\t\r[]{}',
107+
},
108+
key_value: {
109+
case_sensitive: true,
110+
keys: ['SCF_RetMsg'],
111+
types: ['text'],
112+
tokenizers: [' '],
113+
},
114+
},
115+
});
116+
117+
expect(res).toEqual({
118+
requestId: expect.any(String),
119+
success: true,
120+
});
121+
});
122+
123+
test('get index', async () => {
124+
const res = await client.getIndex({
125+
topic_id,
126+
});
127+
128+
expect(res).toEqual({
129+
requestId: expect.any(String),
130+
effective: true,
131+
rule: {
132+
full_text: {
133+
case_sensitive: true,
134+
tokenizer: `!@#%^&*()_="', <>/?|\\;:\n\t\r[]{}`,
135+
},
136+
key_value: {
137+
case_sensitive: true,
138+
template_type: 'static',
139+
keys: ['SCF_RetMsg'],
140+
types: ['text'],
141+
tokenizers: [' '],
142+
},
143+
},
144+
topic_id,
145+
});
146+
});
147+
148+
test('delete topic', async () => {
149+
const res = await client.deleteTopic({
150+
topic_id,
151+
});
152+
expect(res).toEqual({
153+
requestId: expect.any(String),
154+
success: true,
155+
});
156+
});
157+
158+
test('delete logset', async () => {
159+
const res = await client.deleteLogset({
160+
logset_id,
161+
});
162+
expect(res).toEqual({
163+
requestId: expect.any(String),
164+
success: true,
165+
});
166+
});
167+
});

0 commit comments

Comments
 (0)