tadcode-wpsjs 0.3.0 → 1.0.0
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/README.md +1 -23
- package/index.js +1 -1
- package/index.ts +115 -110
- package/package.json +35 -17
- package/types/DB_Application.d.ts +27 -0
- package/types/DB_Application_Record.d.ts +2 -2
- package/types/DB_Application_Selection.ts +22 -22
- package/types/KSDrive.d.ts +32 -20
- package/types/KSheet_Application.d.ts +10 -8
- package/types/index.d.ts +37 -21
- package/types/type-tools.ts +17 -0
package/README.md
CHANGED
|
@@ -51,32 +51,10 @@ const scriptToken = 'xxxx'
|
|
|
51
51
|
/* webhook url地址 具体获取方式参考上面 */
|
|
52
52
|
const webhookURL = 'xxxx'
|
|
53
53
|
const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, })
|
|
54
|
-
const data = await wpsjsGlobal.Application.Sheet.GetSheets()
|
|
54
|
+
const data = await wpsjsGlobal.Application.Sheet.GetSheets()
|
|
55
55
|
console.log(data)
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
### 对于智能表格执行赋值操作
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
import { initRemoteCallWpsjsGlobal } from 'tadcode-wpsjs'
|
|
62
|
-
/* 脚本令牌 具体获取方式参考上面 */
|
|
63
|
-
const scriptToken = 'xxxx'
|
|
64
|
-
/* webhook url地址 具体获取方式参考上面 */
|
|
65
|
-
const webhookURL = 'xxxx'
|
|
66
|
-
const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, })
|
|
67
|
-
const values = [
|
|
68
|
-
['name', 'price'],
|
|
69
|
-
['米', 2.5],
|
|
70
|
-
]
|
|
71
|
-
function setValue(data: any[][], rangeReference = 'a1') {
|
|
72
|
-
const rowCount = data.length
|
|
73
|
-
const columnCount = data[0].length
|
|
74
|
-
wpsjsGlobal.Application.ActiveSheet.Range(rangeReference).Resize(rowCount, columnCount).Value2 = data
|
|
75
|
-
return wpsjsGlobal.execution() as unknown as boolean
|
|
76
|
-
}
|
|
77
|
-
setValue(values)
|
|
78
|
-
```
|
|
79
|
-
|
|
80
58
|
### 执行脚本并且返回(不用部署remoteCode代码)
|
|
81
59
|
|
|
82
60
|
```ts
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{writeFile as W}from"fs/promises";import G from"path";var Q=Symbol("info"),Z=Symbol("then"),_=(B)=>{let{scriptToken:E,webhookURL:V,isAsync:H=!1,printLog:X=!1,writeLogFile:J=!1}=B,N={get(K,M,$){let Y=K[Q]??=[],z=()=>{};if(z[Z]=!1,z[Q]=[...Y],M!=="then")z[Q].push({method:"get",arguments:[M]});else z[Z]=!0;return new Proxy(z,N)},apply(K,M,$){if(!K[Z]){let Y=K[Q]??=[],z=()=>{};return z[Z]=!1,z[Q]=[...Y,{method:"apply",arguments:$}],new Proxy(z,N)}else{let Y=K[Q];return v({scriptToken:E,webhookURL:V,isAsync:H,argv:{info:Y}}).then(async(z)=>{let q=await z.json();if(X)D(q);if(J)await P(q);return q?.data.result}).then(...$)}}};return new Proxy(()=>{},N)},v=({scriptToken:B,webhookURL:E,isAsync:V,argv:H})=>{let X=JSON.stringify({Context:{argv:H}}),J=G.parse(E);J.base=V?"task":"sync_task";let N=G.format(J);return fetch(N,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":B},body:X})},j=(B)=>{let E=new URL("https://www.kdocs.cn/api/v3/script/task");return E.searchParams.append("task_id",B),fetch(E)},D=(B)=>{let E=B,{status:V,data:H,error:X,error_details:J}=E;console.log("status:",V);let N=H.logs.at(-1).unix_time-H.logs[1].unix_time;if(console.log("runtime:",N),X)console.error(J.name),console.error(J.msg),console.error(J.stack);let K=H.logs.filter((M)=>M.filename!=="<system>");if(K.length!==0){console.log("log:");for(let M of K)console[M.level](...M.args)}return console.log("result:"),console.log(H.result),E},P=(B)=>{return W("./wpsjs.log.json",JSON.stringify(B,void 0,2))};export{P as writeLogFileToCurrent,j as queryTask,_ as initRemoteCallWpsjsGlobal,v as execution};
|
package/index.ts
CHANGED
|
@@ -1,110 +1,115 @@
|
|
|
1
|
-
import type { InfoItem, RemoteCallWpsjsGlobalReturn,
|
|
2
|
-
import { writeFile } from 'fs/promises'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
|
|
5
|
-
interface Config {
|
|
6
|
-
/**脚本令牌 */
|
|
7
|
-
scriptToken: string
|
|
8
|
-
/**脚本链接 */
|
|
9
|
-
webhookURL: string
|
|
10
|
-
/**异步任务 */
|
|
11
|
-
isAsync?: boolean
|
|
12
|
-
/**在控制台打印日志 */
|
|
13
|
-
printLog?: boolean
|
|
14
|
-
/**在当前路径下写入日志文件 */
|
|
15
|
-
writeLogFile?: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
1
|
+
import type { InfoItem, RemoteCallWpsjsGlobalReturn, WpsjsGlobalApi } from './types'
|
|
2
|
+
import { writeFile } from 'fs/promises'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
interface Config {
|
|
6
|
+
/**脚本令牌 */
|
|
7
|
+
scriptToken: string
|
|
8
|
+
/**脚本链接 */
|
|
9
|
+
webhookURL: string
|
|
10
|
+
/**异步任务 */
|
|
11
|
+
isAsync?: boolean
|
|
12
|
+
/**在控制台打印日志 */
|
|
13
|
+
printLog?: boolean
|
|
14
|
+
/**在当前路径下写入日志文件 */
|
|
15
|
+
writeLogFile?: boolean
|
|
16
|
+
}
|
|
17
|
+
const infoSymbol = Symbol('info')
|
|
18
|
+
const isThenSymbol = Symbol('then')
|
|
19
|
+
const initRemoteCallWpsjsGlobal = (config: Config) => {
|
|
20
|
+
const { scriptToken, webhookURL, isAsync = false, printLog = false, writeLogFile = false, } = config
|
|
21
|
+
type ProxyTarget = { (): void;[infoSymbol]: InfoItem[], [isThenSymbol]: boolean }
|
|
22
|
+
|
|
23
|
+
const handle: ProxyHandler<ProxyTarget> = {
|
|
24
|
+
get(target, p: string, _receiver) {
|
|
25
|
+
const oldInfo = target[infoSymbol] ??= []
|
|
26
|
+
const func: ProxyTarget = () => { }
|
|
27
|
+
func[isThenSymbol] = false
|
|
28
|
+
func[infoSymbol] = [...oldInfo]
|
|
29
|
+
if (p !== 'then')
|
|
30
|
+
func[infoSymbol].push({ method: 'get', arguments: [p] })
|
|
31
|
+
else
|
|
32
|
+
func[isThenSymbol] = true
|
|
33
|
+
return new Proxy(func, handle)
|
|
34
|
+
},
|
|
35
|
+
apply(target, _thisArg, argArray) {
|
|
36
|
+
if (!target[isThenSymbol]) {
|
|
37
|
+
const oldInfo = target[infoSymbol] ??= []
|
|
38
|
+
const func: ProxyTarget = () => { }
|
|
39
|
+
func[isThenSymbol] = false
|
|
40
|
+
func[infoSymbol] = [...oldInfo, { method: 'apply', arguments: argArray }]
|
|
41
|
+
return new Proxy(func, handle)
|
|
42
|
+
} else {
|
|
43
|
+
const info = target[infoSymbol]
|
|
44
|
+
return execution({ scriptToken, webhookURL, isAsync, argv: { info } })
|
|
45
|
+
.then(async (response) => {
|
|
46
|
+
const responseObj = await response.json()
|
|
47
|
+
if (printLog) printInfo(responseObj)
|
|
48
|
+
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
49
|
+
return responseObj?.['data']['result']
|
|
50
|
+
})
|
|
51
|
+
.then(...argArray)
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
return new Proxy(() => { }, handle) as unknown as WpsjsGlobalApi
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type ExecutionConfig = Pick<Config, 'scriptToken' | 'webhookURL' | 'isAsync'> & { argv?: Record<string | number, any> }
|
|
59
|
+
|
|
60
|
+
const execution = ({ scriptToken, webhookURL, isAsync, argv }: ExecutionConfig) => {
|
|
61
|
+
/* 请求信息 */
|
|
62
|
+
const data = JSON.stringify({ Context: { argv, } })
|
|
63
|
+
/* 根据是否同步返回不同的url */
|
|
64
|
+
const parsedPath = path.parse(webhookURL)
|
|
65
|
+
parsedPath.base = isAsync ? 'task' : 'sync_task'
|
|
66
|
+
const url = path.format(parsedPath)
|
|
67
|
+
return fetch(url, {
|
|
68
|
+
method: 'post',
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
'AirScript-Token': scriptToken
|
|
72
|
+
},
|
|
73
|
+
body: data
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const queryTask = (id: string) => {
|
|
78
|
+
const url = new URL('https://www.kdocs.cn/api/v3/script/task')
|
|
79
|
+
url.searchParams.append('task_id', id)
|
|
80
|
+
return fetch(url)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
|
|
84
|
+
const responseData = remoteCallResponse as RemoteCallWpsjsGlobalReturn
|
|
85
|
+
const { status, data, error, error_details } = responseData
|
|
86
|
+
console.log('status:', status)
|
|
87
|
+
const time = data.logs.at(-1)!.unix_time - data.logs[1].unix_time
|
|
88
|
+
console.log('runtime:', time)
|
|
89
|
+
if (error) {
|
|
90
|
+
console.error(error_details.name)
|
|
91
|
+
console.error(error_details.msg)
|
|
92
|
+
console.error(error_details.stack)
|
|
93
|
+
}
|
|
94
|
+
const userInfo = data.logs.filter(x => x.filename !== '<system>')
|
|
95
|
+
if (userInfo.length !== 0) {
|
|
96
|
+
console.log('log:')
|
|
97
|
+
for (const item of userInfo) {
|
|
98
|
+
console[item.level](...item.args)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
console.log('result:')
|
|
102
|
+
console.log(data.result)
|
|
103
|
+
return responseData
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const writeLogFileToCurrent = (data: object) => {
|
|
107
|
+
return writeFile('./wpsjs.log.json', JSON.stringify((data), undefined, 2))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
execution,
|
|
112
|
+
initRemoteCallWpsjsGlobal,
|
|
113
|
+
queryTask,
|
|
114
|
+
writeLogFileToCurrent,
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tadcode-wpsjs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"hot": "NODE_ENV=development bun --hot ignore/index.ts",
|
|
8
|
-
"dev": "NODE_ENV=development bun --watch index.ts",
|
|
9
|
-
"build": "NODE_ENV=production bun build index.ts --minify --outfile index.js"
|
|
10
|
-
},
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"@types/bun": "latest"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"tadcode-wpsjs"
|
|
16
|
-
]
|
|
17
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "tadcode-wpsjs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"hot": "NODE_ENV=development bun --hot ignore/index.ts",
|
|
8
|
+
"dev": "NODE_ENV=development bun --watch index.ts",
|
|
9
|
+
"build": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/bun": "latest"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"tadcode-wpsjs"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./index.js",
|
|
20
|
+
"types": "./index.ts"
|
|
21
|
+
},
|
|
22
|
+
"./types": {
|
|
23
|
+
"types": "./types/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./types/DB_Application": {
|
|
26
|
+
"types": "./types/DB_Application.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./types/KSDrive": {
|
|
29
|
+
"types": "./types/KSDrive.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./types/KSheet_Application": {
|
|
32
|
+
"types": "./types/KSheet_Application.d.ts"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -4,6 +4,31 @@ import type DBField from './DB_Application_Field'
|
|
|
4
4
|
import type DBRecord from './DB_Application_Record'
|
|
5
5
|
import type DBSelection from './DB_Application_Selection'
|
|
6
6
|
|
|
7
|
+
interface DBUserInfo {
|
|
8
|
+
id: string
|
|
9
|
+
name: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DBFileInfo {
|
|
13
|
+
id: string
|
|
14
|
+
name: string
|
|
15
|
+
officeType: string
|
|
16
|
+
creator: {
|
|
17
|
+
id: string
|
|
18
|
+
name: string
|
|
19
|
+
avatar_url: string
|
|
20
|
+
logined: boolean
|
|
21
|
+
attrs: {
|
|
22
|
+
real_userid: string
|
|
23
|
+
}
|
|
24
|
+
real_id: string
|
|
25
|
+
}
|
|
26
|
+
size: number
|
|
27
|
+
groupId: string
|
|
28
|
+
docType: number
|
|
29
|
+
version: number
|
|
30
|
+
}
|
|
31
|
+
|
|
7
32
|
export type * from './DB_Application_Sheet'
|
|
8
33
|
export type * from './DB_Application_View'
|
|
9
34
|
export type * from './DB_Application_Field'
|
|
@@ -18,5 +43,7 @@ export default interface DB_Application {
|
|
|
18
43
|
Field: DBField
|
|
19
44
|
Record: DBRecord
|
|
20
45
|
Selection: DBSelection
|
|
46
|
+
UserInfo: DBUserInfo
|
|
47
|
+
FileInfo: DBFileInfo
|
|
21
48
|
}
|
|
22
49
|
|
|
@@ -166,11 +166,11 @@ interface RecordFuncOptions {
|
|
|
166
166
|
Filter: RecordsFuncOptionsFilter
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export type { Operator, DynamicDateRange, RecordItem, RecordFuncOptions }
|
|
169
|
+
export type { Operator, DynamicDateRange, RecordItem, RecordFuncOptions, RecordsFuncOptionsFilter }
|
|
170
170
|
|
|
171
171
|
/* 行记录 */
|
|
172
172
|
export default interface DBRecord {
|
|
173
|
-
CreateRecords(options: Pick<RecordFuncOptions, 'SheetId'> & { Records:
|
|
173
|
+
CreateRecords(options: Pick<RecordFuncOptions, 'SheetId'> & { Records: { fields: Record<string, any> }[] }): RecordItem[]
|
|
174
174
|
GetRecord(options: Pick<RecordFuncOptions, 'SheetId' | 'RecordId'>): RecordItem
|
|
175
175
|
GetRecords(options: Pick<RecordFuncOptions, 'SheetId'> & Partial<Pick<RecordFuncOptions, 'ViewId' | 'PageSize' | 'Offset' | 'MaxRecords' | 'Fields' | 'Filter'>>): { records: RecordItem[] }
|
|
176
176
|
UpdateRecords(options: Pick<RecordFuncOptions, 'SheetId' | 'Records'>): RecordItem[]
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { RecordItem } from './DB_Application_Record'
|
|
2
|
-
|
|
3
|
-
interface ActiveView {
|
|
4
|
-
"sheetId": number
|
|
5
|
-
"viewId": string
|
|
6
|
-
"name": string
|
|
7
|
-
"type": string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface ActiveSheet {
|
|
11
|
-
"sheetId": number
|
|
12
|
-
"name": string
|
|
13
|
-
"description": string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type { ActiveView, ActiveSheet }
|
|
17
|
-
|
|
18
|
-
export default interface DBSelection {
|
|
19
|
-
GetActiveView(): ActiveView
|
|
20
|
-
GetSelectionRecords(): RecordItem[]
|
|
21
|
-
GetActiveSheet(): ActiveSheet
|
|
22
|
-
}
|
|
1
|
+
import type { RecordItem } from './DB_Application_Record'
|
|
2
|
+
|
|
3
|
+
interface ActiveView {
|
|
4
|
+
"sheetId": number
|
|
5
|
+
"viewId": string
|
|
6
|
+
"name": string
|
|
7
|
+
"type": string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ActiveSheet {
|
|
11
|
+
"sheetId": number
|
|
12
|
+
"name": string
|
|
13
|
+
"description": string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type { ActiveView, ActiveSheet }
|
|
17
|
+
|
|
18
|
+
export default interface DBSelection {
|
|
19
|
+
GetActiveView(): ActiveView
|
|
20
|
+
GetSelectionRecords(): RecordItem[]
|
|
21
|
+
GetActiveSheet(): ActiveSheet
|
|
22
|
+
}
|
package/types/KSDrive.d.ts
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import type DB_Application from './DB_Application'
|
|
2
2
|
import type KSheet_Application from './KSheet_Application'
|
|
3
3
|
|
|
4
|
+
interface FileType {
|
|
5
|
+
/**智能文档 */
|
|
6
|
+
AP: 'o'
|
|
7
|
+
/**智能表格 */
|
|
8
|
+
KSheet: 'k'
|
|
9
|
+
/**表格 */
|
|
10
|
+
ET: 's'
|
|
11
|
+
/**多维表 */
|
|
12
|
+
DB: 'd'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 文件类型
|
|
17
|
+
* - 'o': 智能文档
|
|
18
|
+
* - 'k': 智能表格
|
|
19
|
+
* - 's': 表格
|
|
20
|
+
* - 'd': 多维表
|
|
21
|
+
*/
|
|
22
|
+
type FileTypeValue = FileType[keyof FileType]
|
|
23
|
+
|
|
4
24
|
interface CreateOptions {
|
|
5
25
|
/**是 新文件的文件名 */
|
|
6
26
|
name: string
|
|
7
27
|
/**否 新文件的文件目录 */
|
|
8
|
-
dirUrl
|
|
28
|
+
dirUrl?: string
|
|
9
29
|
/**否 将目标文件另存为新文件 */
|
|
10
|
-
source
|
|
30
|
+
source?: string
|
|
11
31
|
}
|
|
12
32
|
|
|
13
33
|
interface FilesInfo {
|
|
@@ -26,25 +46,17 @@ interface FileInfo {
|
|
|
26
46
|
updateTime: number
|
|
27
47
|
}
|
|
28
48
|
|
|
29
|
-
export
|
|
30
|
-
FileType: {
|
|
31
|
-
/**智能文档 */
|
|
32
|
-
AP: 'o'
|
|
33
|
-
/**智能表格 */
|
|
34
|
-
KSheet: 'k'
|
|
35
|
-
/**表格 */
|
|
36
|
-
ET: 's'
|
|
37
|
-
/**多维表 */
|
|
38
|
-
DB: 'd'
|
|
39
|
-
}
|
|
49
|
+
export type { FileType, FileTypeValue, CreateOptions, FilesInfo, FileInfo }
|
|
40
50
|
|
|
51
|
+
export default interface KSDrive {
|
|
52
|
+
FileType: FileType
|
|
41
53
|
/**
|
|
42
54
|
* 创建文件
|
|
43
55
|
* @param type 新文件的类型
|
|
44
56
|
* @param createOptions 新文件的参数选项
|
|
45
|
-
* @returns
|
|
57
|
+
* @returns 新文件url
|
|
46
58
|
*/
|
|
47
|
-
createFile(type:
|
|
59
|
+
createFile(type: FileTypeValue, createOptions: CreateOptions): string
|
|
48
60
|
|
|
49
61
|
openFile(url: string): {
|
|
50
62
|
Application: KSheet_Application & DB_Application
|
|
@@ -52,9 +64,9 @@ export default interface KSDrive {
|
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
listFiles(options?: {
|
|
55
|
-
dirUrl
|
|
56
|
-
offset
|
|
57
|
-
count
|
|
58
|
-
includeExts
|
|
59
|
-
})
|
|
67
|
+
dirUrl?: string
|
|
68
|
+
offset?: number
|
|
69
|
+
count?: number
|
|
70
|
+
includeExts?: string[]
|
|
71
|
+
}): FilesInfo
|
|
60
72
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface KSheetRange {
|
|
2
2
|
Value2: any
|
|
3
3
|
Formula: any
|
|
4
|
-
Resize(RowSize: number, ColumnSize?: number):
|
|
4
|
+
Resize(RowSize: number, ColumnSize?: number): KSheetRange
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
interface
|
|
8
|
-
UsedRange:
|
|
7
|
+
interface KSheetSheet {
|
|
8
|
+
UsedRange: KSheetRange
|
|
9
9
|
/**
|
|
10
10
|
* 获取一个单元格或单元格区域,返回一个 Range 对象
|
|
11
11
|
* @paramaddress — 地址,可以是单元格地址或者选区范围范围地址
|
|
@@ -17,13 +17,15 @@ interface Sheet {
|
|
|
17
17
|
* // 修改当前活动工作表D2单元格的内容
|
|
18
18
|
* sheet.Range('D2').Value = 'this is D2'
|
|
19
19
|
*/
|
|
20
|
-
Range(address: string):
|
|
20
|
+
Range(address: string): KSheetRange
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export type { KSheetRange, KSheetSheet }
|
|
24
|
+
|
|
23
25
|
export default interface KSheet_Application {
|
|
24
|
-
ActiveSheet:
|
|
26
|
+
ActiveSheet: KSheetSheet
|
|
25
27
|
Sheets: {
|
|
26
|
-
Item(index: number | string):
|
|
28
|
+
Item(index: number | string): KSheetSheet
|
|
27
29
|
}
|
|
28
|
-
Range(index: string):
|
|
30
|
+
Range(index: string): KSheetRange
|
|
29
31
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WithPromise } from './type-tools'
|
|
2
2
|
import type DB_Application from './DB_Application'
|
|
3
3
|
import type KSheet_Application from './KSheet_Application'
|
|
4
4
|
import type KSDrive from './KSDrive'
|
|
@@ -8,40 +8,56 @@ interface WpsjsGlobal {
|
|
|
8
8
|
Application: KSheet_Application & DB_Application
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
type
|
|
11
|
+
type WpsjsGlobalApi = WithPromise<WpsjsGlobal>
|
|
12
12
|
|
|
13
13
|
interface InfoItem {
|
|
14
14
|
method: keyof typeof Reflect
|
|
15
15
|
arguments: string[]
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/* 基本 */
|
|
18
19
|
interface RemoteCallWpsjsGlobalReturn {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
data: {
|
|
21
|
+
logs: {
|
|
22
|
+
filename: string
|
|
23
|
+
timestamp: string
|
|
24
|
+
unix_time: number
|
|
25
|
+
level: 'info' | 'error' | 'warn'
|
|
26
|
+
args: string[]
|
|
26
27
|
}[]
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
result: unknown
|
|
29
|
+
task_id: string
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
error: string
|
|
32
|
+
error_details: {
|
|
33
|
+
name: string
|
|
34
|
+
msg: string
|
|
35
|
+
stack: string[]
|
|
36
|
+
unix_time: number
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
status: 'finished'
|
|
39
|
+
task_id: string
|
|
40
|
+
task_type: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* token 过期 */
|
|
44
|
+
interface RemoteCallWpsjsGlobalReturn {
|
|
45
|
+
errno: 10000
|
|
46
|
+
msg: string
|
|
47
|
+
reason: string
|
|
48
|
+
result: ApiTokenExpired
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
export {
|
|
43
52
|
WpsjsGlobal,
|
|
44
|
-
|
|
53
|
+
WpsjsGlobalApi,
|
|
45
54
|
InfoItem,
|
|
46
55
|
RemoteCallWpsjsGlobalReturn,
|
|
47
56
|
}
|
|
57
|
+
|
|
58
|
+
export type * from './DB_Application'
|
|
59
|
+
export type { default as DB_Application } from './DB_Application'
|
|
60
|
+
export type * from './KSDrive'
|
|
61
|
+
export type { default as KSDrive } from './KSDrive'
|
|
62
|
+
export type * from './KSheet_Application'
|
|
63
|
+
export type { default as KSheet_Application } from './KSheet_Application'
|
package/types/type-tools.ts
CHANGED
|
@@ -24,10 +24,27 @@ type DeepPartial<T> = T extends object
|
|
|
24
24
|
type DistributiveOmit<T, K extends PropertyKey> =
|
|
25
25
|
T extends any ? Omit<T, K> : never
|
|
26
26
|
|
|
27
|
+
/**根据给的对象,添加promise方法 */
|
|
28
|
+
type WithPromise<T> = T extends (...args: infer A) => infer R ?
|
|
29
|
+
((...args: A) => WithPromise<R>) & Promise<T> :
|
|
30
|
+
T extends Array<infer U> ?
|
|
31
|
+
Array<WithPromise<U>> & Promise<T> :
|
|
32
|
+
T extends object ?
|
|
33
|
+
{ [K in keyof T]: WithPromise<T[K]> } & Promise<T> :
|
|
34
|
+
T extends boolean ?
|
|
35
|
+
Promise<boolean> :
|
|
36
|
+
T extends number ?
|
|
37
|
+
Promise<number> :
|
|
38
|
+
T extends string ?
|
|
39
|
+
Promise<string>
|
|
40
|
+
: T & Promise<T>
|
|
41
|
+
|
|
42
|
+
// 搞定!🎉
|
|
27
43
|
export type {
|
|
28
44
|
WithExecution,
|
|
29
45
|
MakePropertyOptional,
|
|
30
46
|
PickModify,
|
|
31
47
|
DeepPartial,
|
|
32
48
|
DistributiveOmit,
|
|
49
|
+
WithPromise,
|
|
33
50
|
}
|