tadcode-wpsjs 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +15 -0
- package/README.md +28 -4
- package/index.js +1 -1
- package/index.ts +50 -39
- package/package.json +2 -2
- package/types/DB_Application.d.ts +157 -52
- package/types/KSDrive.d.ts +2 -2
- package/types/KSheet_Application.d.ts +1 -1
- package/types/index.d.ts +7 -2
- package/types/type-tools.ts +13 -0
- package/test/one.test.ts +0 -14
package/.vscode/settings.json
CHANGED
|
@@ -8,4 +8,19 @@
|
|
|
8
8
|
"bun.debugTerminal.stopOnEntry": false,
|
|
9
9
|
// Glob pattern to find test files. Defaults to the value shown below.
|
|
10
10
|
"bun.test.filePattern": "**/*{.test.,.spec.,_test_,_spec_}{js,ts,tsx,jsx,mts,cts}",
|
|
11
|
+
"search.exclude": {
|
|
12
|
+
"**/node_modules": true,
|
|
13
|
+
"**/bower_components": true,
|
|
14
|
+
"**/*.code-search": true
|
|
15
|
+
},
|
|
16
|
+
"files.exclude": {
|
|
17
|
+
"**/node_modules": true,
|
|
18
|
+
"**/.git": true,
|
|
19
|
+
"**/.svn": true,
|
|
20
|
+
"**/.hg": true,
|
|
21
|
+
"**/CVS": true,
|
|
22
|
+
"**/.DS_Store": true,
|
|
23
|
+
"**/Thumbs.db": true,
|
|
24
|
+
"bun.lock": true,
|
|
25
|
+
}
|
|
11
26
|
}
|
package/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# tadcode-wpsjs
|
|
2
2
|
|
|
3
|
+
基于wps官方文档
|
|
4
|
+
1. [**AirScript文档**](https://airsheet.wps.cn/docs/apitoken/intro.html)
|
|
5
|
+
2. [**WPS多维表格:“开发”功能使用说明文档**](https://365.kdocs.cn/l/ctzsgDlAGF0l)
|
|
6
|
+
|
|
7
|
+
## 联系我
|
|
8
|
+
|
|
9
|
+
**如你有业务需要,可以点此[联系我](https://f.kdocs.cn/g/SIdEy3GE/),三个工作日内必定回复。**
|
|
10
|
+
|
|
11
|
+
**如您公司存在敏感信息业务,需要长期人才,亦可来讯商谈。**
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
3
15
|
## 应用
|
|
4
16
|
|
|
5
17
|
用于学习wpsjsapi,远程调用wpsjsapi。
|
|
@@ -14,6 +26,14 @@
|
|
|
14
26
|
|
|
15
27
|
`npm install tadcode-wpsjs` 或 `bun install tadcode-wpsjs`
|
|
16
28
|
|
|
29
|
+
## 获取脚本令牌和webhook链接
|
|
30
|
+
|
|
31
|
+
### 获取脚本令牌
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
### webhook链接
|
|
35
|
+

|
|
36
|
+
|
|
17
37
|
## 案例
|
|
18
38
|
|
|
19
39
|
```ts
|
|
@@ -21,8 +41,12 @@ import { RemoteCallWpsjsGlobal } from 'tadcode-wpsjs'
|
|
|
21
41
|
const remoteCall = new RemoteCallWpsjsGlobal()
|
|
22
42
|
remoteCall.scriptToken = 'xxxx' /* 脚本令牌 */
|
|
23
43
|
remoteCall.webhookURL = 'xxxx' /* webhook url地址 */
|
|
24
|
-
|
|
25
|
-
wpsjsGlobal.
|
|
26
|
-
const
|
|
27
|
-
console.log(
|
|
44
|
+
/* 获取表信息 */
|
|
45
|
+
const sheets = await remoteCall.wpsjsGlobal.Application.Sheet.GetSheets().execution()
|
|
46
|
+
const data = sheets.map(({ id, name, sheetType }) => ({ id, name, sheetType }))
|
|
47
|
+
console.log(data)
|
|
28
48
|
```
|
|
49
|
+
|
|
50
|
+
## 支持
|
|
51
|
+
|
|
52
|
+
如果对你有用请给个`star`
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import
|
|
2
|
+
import V from"path";var X="execution";class W{sync=!0;scriptToken="";webhookURL="";asyncQueryURL="https://www.kdocs.cn/api/v3/script/task";printLog=!1;writeLogFile=!1;info=[];wpsjsGlobal=new Proxy(()=>{},{get:(G,j,q)=>{return this.info.push({method:"get",arguments:[j]}),q},apply:(G,j,q)=>{let{info:z}=this;if(z.at(-1)?.arguments[0]===X)return this.execute().then(async(B)=>{let{printLog:H,writeLogFile:M}=this,E=await B.json();if(H)Y(E);if(M)Bun.write("./wpsjs.log.json",JSON.stringify(E,void 0,4));return E.data.result});return z.push({method:"apply",arguments:q}),j}});queryTask(G){let{asyncQueryURL:j}=this,q=new URL(j);return q.searchParams.append("task_id",G),fetch(q.toString())}execute(){let{scriptToken:G,webhookURL:j,sync:q,info:z}=this;z.pop();let K=JSON.stringify({Context:{argv:{info:z}}});this.info=[];let B=V.parse(j);B.base=q?"sync_task":"task";let H=V.format(B);return fetch(H,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":G},body:K})}}var Y=(G)=>{let j=G,{status:q,data:z,error:K,error_details:B}=j;console.log("status:",q);let H=z.logs.at(-1).unix_time-z.logs[1].unix_time;if(console.log("runtime:",H),K)console.error(B.name),console.error(B.msg),console.error(B.stack);let M=z.logs.filter((E)=>E.filename!=="<system>");if(M.length!==0){console.log("log:");for(let E of M)console[E.level](...E.args)}return console.log("result:"),console.log(z.result),j};export{W as default};
|
package/index.ts
CHANGED
|
@@ -1,34 +1,52 @@
|
|
|
1
|
-
import type { InfoItem, RemoteCallWpsjsGlobalReturn,
|
|
1
|
+
import type { InfoItem, RemoteCallWpsjsGlobalReturn, WithExecutionWpsjsGlobal } from './types'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
|
|
3
|
+
const fnName = 'execution'
|
|
4
|
+
export default class RemoteCallWpsjsGlobal {
|
|
5
|
+
/* true 同步执行代码 */
|
|
4
6
|
sync = true
|
|
5
7
|
scriptToken = ''
|
|
6
8
|
webhookURL = ''
|
|
7
9
|
asyncQueryURL = 'https://www.kdocs.cn/api/v3/script/task'
|
|
10
|
+
/* true 在控制台上打印日志 */
|
|
11
|
+
printLog = false
|
|
12
|
+
/* true 在当前目录下,写入日志文件 */
|
|
13
|
+
writeLogFile = false
|
|
8
14
|
info: InfoItem[] = []
|
|
9
15
|
wpsjsGlobal = new Proxy(() => { }, {
|
|
10
|
-
get: (_target, p) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
method: 'get',
|
|
14
|
-
arguments: [p]
|
|
15
|
-
})
|
|
16
|
-
return wpsjsGlobal
|
|
16
|
+
get: (_target, p, receiver) => {
|
|
17
|
+
this.info.push({ method: 'get', arguments: [p] })
|
|
18
|
+
return receiver
|
|
17
19
|
},
|
|
18
|
-
apply: (_target,
|
|
19
|
-
const { info
|
|
20
|
-
info.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
apply: (_target, thisArg, argArray) => {
|
|
21
|
+
const { info } = this
|
|
22
|
+
const lastInfo = info.at(-1)
|
|
23
|
+
if (lastInfo?.arguments[0] === fnName) {
|
|
24
|
+
return this.execute().then(async (response) => {
|
|
25
|
+
const { printLog, writeLogFile } = this
|
|
26
|
+
const responseJSON = await response.json()
|
|
27
|
+
if (printLog) printInfo(responseJSON)
|
|
28
|
+
if (writeLogFile) Bun.write('./wpsjs.log.json', JSON.stringify((responseJSON), undefined, 4))
|
|
29
|
+
return responseJSON['data']['result']
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
info.push({ method: 'apply', arguments: argArray })
|
|
33
|
+
return thisArg
|
|
25
34
|
},
|
|
26
|
-
}) as
|
|
35
|
+
}) as unknown as WithExecutionWpsjsGlobal
|
|
36
|
+
queryTask(id: string) {
|
|
37
|
+
const { asyncQueryURL } = this
|
|
38
|
+
const url = new URL(asyncQueryURL)
|
|
39
|
+
url.searchParams.append('task_id', id)
|
|
40
|
+
return fetch(url.toString())
|
|
41
|
+
}
|
|
27
42
|
execute() {
|
|
28
|
-
const { scriptToken, webhookURL,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
const { scriptToken, webhookURL, sync, info } = this
|
|
44
|
+
/* 删除 execution的调用信息 */
|
|
45
|
+
info.pop()
|
|
46
|
+
/* 获取请求信息 */
|
|
47
|
+
const data = JSON.stringify({ Context: { argv: { info }, } })
|
|
48
|
+
/* 清空调用 */
|
|
49
|
+
this.info = []
|
|
32
50
|
/* 根据是否同步返回不同的url */
|
|
33
51
|
const parsedPath = path.parse(webhookURL)
|
|
34
52
|
parsedPath.base = sync ? 'sync_task' : 'task'
|
|
@@ -42,26 +60,10 @@ export class RemoteCallWpsjsGlobal {
|
|
|
42
60
|
body: data
|
|
43
61
|
})
|
|
44
62
|
}
|
|
45
|
-
queryTask(id: string) {
|
|
46
|
-
const { asyncQueryURL } = this
|
|
47
|
-
const url = new URL(asyncQueryURL)
|
|
48
|
-
/* 这样子可以不用 encodeURIComponent */
|
|
49
|
-
url.searchParams.append('task_id', id)
|
|
50
|
-
return fetch(url.toString())
|
|
51
|
-
}
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
const responseData =
|
|
64
|
+
const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
|
|
65
|
+
const responseData = remoteCallResponse as RemoteCallWpsjsGlobalReturn
|
|
55
66
|
const { status, data, error, error_details } = responseData
|
|
56
|
-
console.log('result:')
|
|
57
|
-
console.log(data.result)
|
|
58
|
-
const userInfo = data.logs.filter(x => x.filename !== '<system>')
|
|
59
|
-
if (userInfo.length !== 0) {
|
|
60
|
-
console.log('log:')
|
|
61
|
-
for (const item of userInfo) {
|
|
62
|
-
console[item.level](...item.args)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
67
|
console.log('status:', status)
|
|
66
68
|
const time = data.logs.at(-1)!.unix_time - data.logs[1].unix_time
|
|
67
69
|
console.log('runtime:', time)
|
|
@@ -70,5 +72,14 @@ export async function printInfo(response: Response) {
|
|
|
70
72
|
console.error(error_details.msg)
|
|
71
73
|
console.error(error_details.stack)
|
|
72
74
|
}
|
|
75
|
+
const userInfo = data.logs.filter(x => x.filename !== '<system>')
|
|
76
|
+
if (userInfo.length !== 0) {
|
|
77
|
+
console.log('log:')
|
|
78
|
+
for (const item of userInfo) {
|
|
79
|
+
console[item.level](...item.args)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
console.log('result:')
|
|
83
|
+
console.log(data.result)
|
|
73
84
|
return responseData
|
|
74
85
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tadcode-wpsjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"hot": "NODE_ENV=development bun --hot index.ts",
|
|
7
|
+
"hot": "NODE_ENV=development bun --hot ignore/index.ts",
|
|
8
8
|
"dev": "NODE_ENV=development bun --watch index.ts",
|
|
9
9
|
"build": "NODE_ENV=production bun build index.ts --target bun --minify --outfile index.js"
|
|
10
10
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MakePropertyOptional, PickModify } from './type-tools'
|
|
1
2
|
export default interface DB_Application {
|
|
2
3
|
Sheet: DBSheet
|
|
3
4
|
Record: DBRecord
|
|
@@ -6,7 +7,7 @@ export default interface DB_Application {
|
|
|
6
7
|
}
|
|
7
8
|
/* 表 */
|
|
8
9
|
interface DBSheet {
|
|
9
|
-
GetSheets(): SheetInfo
|
|
10
|
+
GetSheets(): SheetInfo[]
|
|
10
11
|
CreateSheet(options: Pick<SheetOptions, 'SheetId'>)
|
|
11
12
|
DeleteSheet(options: Pick<SheetOptions, 'SheetId'>)
|
|
12
13
|
UpdateSheet(options: Omit<SheetOptions, 'SheetId'> & Partial<SheetOptions>)
|
|
@@ -24,75 +25,179 @@ interface SheetOptions {
|
|
|
24
25
|
Fields: { name: string, type: FieldType }[]
|
|
25
26
|
}
|
|
26
27
|
interface SheetInfo {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
'description': string,
|
|
29
|
+
'fields': {
|
|
30
|
+
'arraySupport': boolean,
|
|
31
|
+
'autoFillSourceField': string,
|
|
32
|
+
'customConfig': string,
|
|
33
|
+
'defaultValueType': 'Normal',
|
|
34
|
+
'description': string,
|
|
35
|
+
'id': string,
|
|
36
|
+
'name': string,
|
|
37
|
+
'numberFormat': string,
|
|
38
|
+
'syncField': boolean,
|
|
39
|
+
'type': FieldType,
|
|
40
|
+
'uniqueValue': boolean
|
|
41
|
+
'loadLegalHoliday': number,
|
|
42
|
+
'items': {
|
|
43
|
+
'color': number,
|
|
44
|
+
'id': string,
|
|
45
|
+
'value': string
|
|
45
46
|
}[],
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
'allowAddItemWhenInputting': true,
|
|
48
|
+
'autoAddItem': boolean,
|
|
48
49
|
}[],
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
'icon': string,
|
|
51
|
+
'id': number,
|
|
52
|
+
'name': number,
|
|
53
|
+
'primaryFieldId': number,
|
|
54
|
+
'recordsCount': number,
|
|
55
|
+
'sheetType': 'xlEtDataBaseSheet',
|
|
56
|
+
'subType': 'Normal',
|
|
57
|
+
'syncFieldSourceId': string,
|
|
58
|
+
'syncFieldSourceNameId': string,
|
|
59
|
+
'syncType': 'None',
|
|
60
|
+
'views': {
|
|
61
|
+
'id': string,
|
|
62
|
+
'name': string,
|
|
63
|
+
'notice': string,
|
|
64
|
+
'recordsCount': number,
|
|
65
|
+
'type': ViewType
|
|
65
66
|
}[]
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
type FieldType = 'MultiLineText' | 'Date' | 'Time' | 'Number' | 'Currency' | 'Percentage' | 'ID' | 'Phone' | 'Email' | 'Url' | 'Checkbox' | 'SingleSelect' | 'MultipleSelect' | 'Rating' | 'Complete' | 'Contact' | 'Attachment' | 'Link' | 'Note' | 'AutoNumber' | 'CreatedBy' | 'CreatedTime' | 'Formula' | 'Lookup'
|
|
69
70
|
type ViewType = 'Grid' | 'Kanban' | 'Gallery' | 'Form' | 'Gantt'
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
GetRecord(options: Pick<RcordOptions, 'SheetId' | 'RecordId'>)
|
|
75
|
-
DeleteRecords(options: Pick<RcordOptions, 'SheetId' | 'RecordIds'>)
|
|
76
|
-
UpdateRecords(options: Pick<RcordOptions, 'SheetId' | 'Records'>)
|
|
72
|
+
interface Entry {
|
|
73
|
+
id: string,
|
|
74
|
+
fields: Record<string, boolean | number | string | string[]>
|
|
77
75
|
}
|
|
78
|
-
interface
|
|
76
|
+
interface Options {
|
|
79
77
|
SheetId: number
|
|
80
78
|
RecordId: string
|
|
81
79
|
RecordIds: string[]
|
|
82
|
-
Records:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
Records: Entry[]
|
|
81
|
+
/**
|
|
82
|
+
* 填写后将从被指定的视图获取该用户所见到的记录;若不填写,则从工作表获取记录
|
|
83
|
+
*/
|
|
84
|
+
ViewId: string
|
|
85
|
+
/**
|
|
86
|
+
* 存在分页时,指定本次查询的起始记录(含)。若不填写或填写为空字符串,则从第一条记录开始获取
|
|
87
|
+
*
|
|
88
|
+
* 当前最大值:1000
|
|
89
|
+
*/
|
|
90
|
+
PageSize: number
|
|
91
|
+
/**分页查询时,将返回一个offset值,指向下一页的第一条记录,供后续查询。查询到最后一页或第maxRecords条记录时,返回数据将不再包含offset值 */
|
|
92
|
+
Offset: number
|
|
93
|
+
/**指定要获取的“前maxRecords条记录”,若不填写,则默认返回全部记录 */
|
|
94
|
+
MaxRecords: number
|
|
95
|
+
/**具体字段类型说明详见 [附件2](https://kdocs.cn/l/ctzsgDlAGF0l?linkname=QSt7dOHYA0) */
|
|
96
|
+
Fields: any[]
|
|
97
|
+
/**详细说明见 [附件4](https://www.kdocs.cn/l/ctzsgDlAGF0l?linkname=wsTfzS9o34) */
|
|
98
|
+
Filter: {
|
|
99
|
+
/**选填。表示各筛选条件之间的逻辑关系。只能是'AND'或'OR'。缺省值为'AND' */
|
|
100
|
+
mode?: 'AND' | 'OR',
|
|
101
|
+
/**filter结构体内必填。包含筛选条件的数组。每个字段上只能有一个筛选条件 */
|
|
102
|
+
criteria: {
|
|
103
|
+
/**必填。根据 preferId 与否,需要填入字段名或字段id */
|
|
104
|
+
field: string
|
|
105
|
+
/**"Equals": 等于
|
|
106
|
+
|
|
107
|
+
"NotEqu": 不等于
|
|
108
|
+
|
|
109
|
+
"Greater": 大于
|
|
110
|
+
|
|
111
|
+
"GreaterEqu": 大等于
|
|
112
|
+
|
|
113
|
+
"Less": 小于
|
|
114
|
+
|
|
115
|
+
"LessEqu": 小等于
|
|
116
|
+
|
|
117
|
+
"GreaterEquAndLessEqu": 介于(取等)
|
|
87
118
|
|
|
119
|
+
"LessOrGreater": 介于(不取等)
|
|
120
|
+
|
|
121
|
+
"BeginWith": 开头是
|
|
122
|
+
|
|
123
|
+
"EndWith": 结尾是
|
|
124
|
+
|
|
125
|
+
"Contains": 包含
|
|
126
|
+
|
|
127
|
+
"NotContains": 不包含
|
|
128
|
+
|
|
129
|
+
"Intersected": 指定值
|
|
130
|
+
|
|
131
|
+
"Empty": 为空
|
|
132
|
+
|
|
133
|
+
"NotEmpty": 不为空
|
|
134
|
+
*/
|
|
135
|
+
op: 'Equals' | 'NotEqu' | 'Greater' | 'GreaterEqu' | 'Less' | 'LessEqu' | 'GreaterEquAndLessEqu' | 'LessOrGreater' | 'BeginWith' | 'EndWith' | 'Contains' | 'NotContains' | 'Intersected' | 'Empty' | 'NotEmpty'
|
|
136
|
+
/**
|
|
137
|
+
* 必填。表示筛选规则中的值。数组形式。值为字符串时表示文本匹配。
|
|
138
|
+
* 这里的 values,必须是一个数组,传 ["多维表"],相当于传 [{ type: 'Text', value: '多维表' }],即不传默认帮你补充 Text 类型。
|
|
139
|
+
* 复选框的值,values: ['0'] 代表否,value: ['1'] 代表是。
|
|
140
|
+
*
|
|
141
|
+
* values[]数组内的元素为字符串时,表示文本匹配。各筛选规则独立地限制了values数组内最多允许填写的元素数,当values内元素数超过阈值时,该筛选规则将失效。
|
|
142
|
+
*
|
|
143
|
+
* a. “为空、不为空”不允许填写元素;
|
|
144
|
+
*
|
|
145
|
+
* b. “介于”允许最多填写2个元素;
|
|
146
|
+
*
|
|
147
|
+
* c. “指定值”允许填写65535个元素;
|
|
148
|
+
*
|
|
149
|
+
* d. 其他规则允许最多填写1个元素
|
|
150
|
+
*/
|
|
151
|
+
values: string[] | {
|
|
152
|
+
type: 'Text'
|
|
153
|
+
value: string
|
|
154
|
+
}[] |
|
|
155
|
+
{
|
|
156
|
+
type: 'DynamicSimple'
|
|
157
|
+
/**
|
|
158
|
+
* 当"op"为"greater"或"less"时,"dynamicType"只能是昨天、今天或明天。
|
|
159
|
+
*
|
|
160
|
+
* "today": 今天
|
|
161
|
+
*
|
|
162
|
+
* "yesterday": 昨天
|
|
163
|
+
*
|
|
164
|
+
* "tomorrow": 明天
|
|
165
|
+
*
|
|
166
|
+
* "last7Days": 最近7天
|
|
167
|
+
*
|
|
168
|
+
* "last30Days": 最近30天
|
|
169
|
+
*
|
|
170
|
+
* "thisWeek": 本周
|
|
171
|
+
*
|
|
172
|
+
* "lastWeek": 上周
|
|
173
|
+
*
|
|
174
|
+
* "nextWeek":下周
|
|
175
|
+
*
|
|
176
|
+
* "thisMonth": 本月
|
|
177
|
+
*
|
|
178
|
+
* "lastMonth": 上月
|
|
179
|
+
*
|
|
180
|
+
* "nextMonth": 次月
|
|
181
|
+
*/
|
|
182
|
+
dynamicType: "today" | "yesterday" | "tomorrow" | "last7Days" | "last30Days" | "thisWeek" | "lastWeek" | "nextWeek" | "thisMonth" | "lastMonth" | "nextMonth"
|
|
183
|
+
}[]
|
|
184
|
+
}[]
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/* 行记录 */
|
|
188
|
+
interface DBRecord {
|
|
189
|
+
GetRecord(options: Pick<Options, 'SheetId' | 'RecordId'>)
|
|
190
|
+
GetRecords(options: Pick<Options, 'SheetId'> & Partial<Pick<Options, 'ViewId' | 'PageSize' | 'Offset' | 'MaxRecords' | 'Fields' | 'Filter'>>): { records: Entry[] }
|
|
191
|
+
CreateRecords(options: Pick<Options, 'SheetId'> & PickModify<Options, 'Records', MakePropertyOptional<Entry, 'id'>[]>): Entry[]
|
|
192
|
+
UpdateRecords(options: Pick<Options, 'SheetId' | 'Records'>)
|
|
193
|
+
DeleteRecords(options: Pick<Options, 'SheetId' | 'RecordIds'>)
|
|
194
|
+
}
|
|
88
195
|
/* 字段 */
|
|
89
196
|
interface DBField {
|
|
90
197
|
GetFields(options: Pick<FieldOptions, 'SheetId'>)
|
|
91
198
|
CreateFields(options: Pick<FieldOptions, 'SheetId' | 'Fields'>)
|
|
92
199
|
DeleteFields(options: Pick<FieldOptions, 'SheetId' | 'FieldIds'>)
|
|
93
|
-
UpdateFields(options: Pick<FieldOptions, 'SheetId' | 'Fields'> & {
|
|
94
|
-
|
|
95
|
-
})
|
|
200
|
+
UpdateFields(options: Pick<FieldOptions, 'SheetId' | 'Fields'> & {})
|
|
96
201
|
}
|
|
97
202
|
interface FieldOptions {
|
|
98
203
|
SheetId: number
|
package/types/KSDrive.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import DB_Application from './DB_Application'
|
|
2
|
-
import KSheet_Application from './KSheet_Application'
|
|
1
|
+
import type DB_Application from './DB_Application'
|
|
2
|
+
import type KSheet_Application from './KSheet_Application'
|
|
3
3
|
export default interface KSDrive {
|
|
4
4
|
FileType: {
|
|
5
5
|
/**智能文档 */
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { WithExecution } from './type-tools'
|
|
2
|
+
import type DB_Application from './DB_Application'
|
|
3
|
+
import type KSheet_Application from './KSheet_Application'
|
|
4
|
+
import type KSDrive from './KSDrive'
|
|
2
5
|
interface WpsjsGlobal {
|
|
3
|
-
(): WpsjsGlobal
|
|
4
6
|
Date: typeof Date
|
|
5
7
|
KSDrive: KSDrive
|
|
8
|
+
Application: KSheet_Application & DB_Application
|
|
6
9
|
}
|
|
10
|
+
type WithExecutionWpsjsGlobal = WithExecution<WpsjsGlobal>
|
|
7
11
|
interface InfoItem {
|
|
8
12
|
method: keyof typeof Reflect
|
|
9
13
|
arguments: (string | symbol)[]
|
|
@@ -76,6 +80,7 @@ interface RemoteCallWpsjsGlobalReturn {
|
|
|
76
80
|
}
|
|
77
81
|
export {
|
|
78
82
|
WpsjsGlobal,
|
|
83
|
+
WithExecutionWpsjsGlobal,
|
|
79
84
|
InfoItem,
|
|
80
85
|
RemoteCallWpsjsGlobalReturn,
|
|
81
86
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* 根据给的对象,添加execution方法 */
|
|
2
|
+
type WithExecution<T> = T extends (...args: infer A) => infer R
|
|
3
|
+
? ((...args: A) => WithExecution<R>) & { execution: () => Promise<R> }
|
|
4
|
+
: T extends object
|
|
5
|
+
? { [K in keyof T]: WithExecution<T[K]> } & { execution: () => Promise<T> }
|
|
6
|
+
: T & { execution: () => Promise<T> }
|
|
7
|
+
/**部分可选 */
|
|
8
|
+
type MakePropertyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
9
|
+
/* 选取修改类型 */
|
|
10
|
+
type PickModify<T, K extends keyof T, M> = {
|
|
11
|
+
[P in K]: M
|
|
12
|
+
}
|
|
13
|
+
export type { WithExecution, MakePropertyOptional, PickModify }
|
package/test/one.test.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { RemoteCallWpsjsGlobalReturn } from '../types'
|
|
2
|
-
import { test, expect } from 'bun:test'
|
|
3
|
-
import { RemoteCallWpsjsGlobal } from '../index'
|
|
4
|
-
|
|
5
|
-
test('ok', async () => {
|
|
6
|
-
const remoteCall = new RemoteCallWpsjsGlobal()
|
|
7
|
-
remoteCall.webhookURL = 'xxxx' /* webhook url地址 */
|
|
8
|
-
remoteCall.webhookURL = 'xxxx' /* webhook url地址 */
|
|
9
|
-
const { wpsjsGlobal } = remoteCall
|
|
10
|
-
wpsjsGlobal.KSDrive.listFiles()
|
|
11
|
-
const response = await remoteCall.execute()
|
|
12
|
-
console.log(await response.text())
|
|
13
|
-
// const responseData = await printInfo(response)
|
|
14
|
-
})
|