tadcode-wpsjs 1.1.1 → 1.3.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 +39 -16
- package/index.js +4 -1
- package/index.ts +59 -52
- package/package.json +5 -18
- package/remoteCode/index.js +23 -23
- package/types/KSDrive.d.ts +72 -72
- package/types/TypeTools.d.ts +53 -0
- package/types/application/Criteria.d.ts +31 -0
- package/types/application/Field.d.ts +25 -0
- package/types/application/FieldApi.d.ts +212 -0
- package/types/application/Fields.d.ts +20 -0
- package/types/application/Font.d.ts +10 -0
- package/types/application/Record.d.ts +22 -0
- package/types/application/RecordApi.d.ts +178 -0
- package/types/application/RecordRange.d.ts +77 -0
- package/types/application/Records.d.ts +28 -0
- package/types/application/SelectionApi.d.ts +29 -0
- package/types/application/Sheet.d.ts +73 -0
- package/types/application/SheetApi.d.ts +62 -0
- package/types/application/Sheets.d.ts +88 -0
- package/types/application/View.d.ts +51 -0
- package/types/application/ViewApi.d.ts +26 -0
- package/types/application/Views.d.ts +36 -0
- package/types/application/Window.d.ts +57 -0
- package/types/application/global.d.ts +28 -0
- package/types/application/index.d.ts +29 -0
- package/types/global.d.ts +36 -0
- package/types/index.d.ts +4 -64
- package/types/return.response.d.ts +34 -0
- package/types/DB_Application.d.ts +0 -49
- package/types/DB_Application_Field.d.ts +0 -212
- package/types/DB_Application_Plus/index.d.ts +0 -7
- package/types/DB_Application_Plus/record.d.ts +0 -33
- package/types/DB_Application_Plus/records.d.ts +0 -58
- package/types/DB_Application_Plus/sheet.d.ts +0 -137
- package/types/DB_Application_Plus/sheets.d.ts +0 -113
- package/types/DB_Application_Record.d.ts +0 -178
- package/types/DB_Application_Selection.ts +0 -22
- package/types/DB_Application_Sheet.d.ts +0 -63
- package/types/DB_Application_View.d.ts +0 -24
- package/types/type-tools.ts +0 -50
package/README.md
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
# tadcode-wpsjs
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
- [**AirScript文档**](https://airsheet.wps.cn/docs/apitoken/intro.html)
|
|
5
|
-
- [**WPS多维表格:“开发”功能使用说明文档**](https://365.kdocs.cn/l/ctzsgDlAGF0l)
|
|
6
|
-
- [**执行AirScript脚本操作使用指南**](https://365.kdocs.cn/l/cdQOqc6TZuMk)
|
|
7
|
-
- [**快速入门多维表“开发”**](https://365.kdocs.cn/l/ctx1jAV1xJhR)
|
|
8
|
-
- [**WPS开放平台dbsheet-Api部分**](https://365.kdocs.cn/3rd/open/documents/app-integration-dev/guide/dbsheet/Api/api-instro)
|
|
3
|
+
## 介绍
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
项目地址:[https://gitcode.com/caisijian/tadcode-wpsjs](https://gitcode.com/caisijian/tadcode-wpsjs)
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
在部署远程代码的情况下,可以远程调用`WpsjsGlobal`,实现对支持`AirScript`的多维表,智能表格等远程操作。如果你对`AirScript`,感兴趣,也能帮助你学习`WpsjsGlobal`。
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
In the case of deploying remote code, WpsjsGlobal can be remotely called to achieve remote operations on multidimensional tables, smart tables, and other tables that support AirScript. If you are interested in AirScript, it can also help you learn WpsjsGlobal.
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
原理是使用代理收集调用信息,之后让远程代码进行调用并且返回结果。
|
|
12
|
+
远程代码在`tadcode-wpsjs/remoteCode`目录的`index.js`文件中。
|
|
13
|
+
将其复制粘贴到对应`webhook`的脚本中才能支持`WpsjsGlobal`对象的调用。
|
|
14
|
+
|
|
15
|
+
目前已经对多维表的基本操作,实现了全类型支持。
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
如果对你有用请在[gitcode](https://gitcode.com/caisijian/tadcode-wpsjs)给个`star`,谢谢。
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
## 联系我
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
**如你有业务需要wps代码,可以点此[联系我](https://f.kdocs.cn/g/SIdEy3GE/),三个工作日内必定回复。**
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
**如您公司存在敏感信息业务,需要长期人才,亦可来讯商谈。**
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+

|
|
27
26
|
|
|
28
27
|
## 安装
|
|
29
28
|
|
|
@@ -56,7 +55,7 @@ const data = await wpsjsGlobal.Application.Sheet.GetSheets()
|
|
|
56
55
|
console.log(data)
|
|
57
56
|
```
|
|
58
57
|
|
|
59
|
-
###
|
|
58
|
+
### 多维表的重命名(赋值操作)
|
|
60
59
|
|
|
61
60
|
```ts
|
|
62
61
|
import { initRemoteCallWpsjsGlobal,setValue } from 'tadcode-wpsjs'
|
|
@@ -71,6 +70,23 @@ const sheet = wpsjsGlobal.Application.Sheets(1)
|
|
|
71
70
|
await setValue(sheet,'Name','table1001')
|
|
72
71
|
```
|
|
73
72
|
|
|
73
|
+
### 修改记录区域字体颜色(赋值操作,此写法可以复用对象)
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import type { Font } from 'application:datatable'
|
|
77
|
+
import { initRemoteCallWpsjsGlobal,setValue } from 'tadcode-wpsjs'
|
|
78
|
+
/* 脚本令牌 具体获取方式参考上面 */
|
|
79
|
+
const scriptToken = 'xxxx'
|
|
80
|
+
/* webhook url地址 具体获取方式参考上面 */
|
|
81
|
+
const webhookURL = 'xxxx'
|
|
82
|
+
const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, })
|
|
83
|
+
|
|
84
|
+
const range = wpsjsGlobal.Application.ActiveSheet.RecordRange([1, 2], [1, 2]).Font as unknown as Font
|
|
85
|
+
range.Color = '#ff00ff'
|
|
86
|
+
/* 注意:赋值操作依旧远程操作。此函数会拿到最后一次赋值操作的promise */
|
|
87
|
+
await setValueOk()
|
|
88
|
+
```
|
|
89
|
+
|
|
74
90
|
### 执行脚本并且返回(不用部署remoteCode代码)
|
|
75
91
|
|
|
76
92
|
```ts
|
|
@@ -84,6 +100,13 @@ const data =await result.json()
|
|
|
84
100
|
console.log(data)
|
|
85
101
|
```
|
|
86
102
|
|
|
103
|
+
## 基于wps官方文档
|
|
104
|
+
- [**AirScript文档**](https://airsheet.wps.cn/docs/apitoken/intro.html)
|
|
105
|
+
- [**WPS多维表格:“开发”功能使用说明文档**](https://365.kdocs.cn/l/ctzsgDlAGF0l)
|
|
106
|
+
- [**执行AirScript脚本操作使用指南**](https://365.kdocs.cn/l/cdQOqc6TZuMk)
|
|
107
|
+
- [**快速入门多维表“开发”**](https://365.kdocs.cn/l/ctx1jAV1xJhR)
|
|
108
|
+
- [**WPS开放平台dbsheet-Api部分**](https://365.kdocs.cn/3rd/open/documents/app-integration-dev/guide/dbsheet/Api/api-instro)
|
|
109
|
+
|
|
87
110
|
## 支持
|
|
88
111
|
|
|
89
112
|
如果对你有用请在[gitcode](https://gitcode.com/caisijian/tadcode-wpsjs)给个`star`
|
package/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import{writeFile as
|
|
1
|
+
import{writeFile as A}from"fs/promises";import I from"path";var Z=Symbol("info-tacode"),F=Symbol("then-tacode"),U=Symbol("raw-tacode"),L={then:1,catch:1,finally:1},R=(B)=>{let{scriptToken:H,webhookURL:z,isAsync:N=!1,printLog:Q=!1,writeLogFile:J=!1}=B;if(!H||!z)throw Error("scriptToken and webhookURL are both required");let $=async(D)=>{let K=await D.json();if(J)await j(K);if(x(K),Q)V(K);return K.data?.result},X=async(D)=>P({scriptToken:H,webhookURL:z,isAsync:N,argv:{info:D}}).then($),W=()=>{let D=()=>{};return D[F]=!1,D[Z]=[],D},v={get(D,K,q){if(K===U)return D;let G=D[Z],M=W(),Y=M[Z];if(Y.push(...G),K in L)M[F]=!0;return Y.push({method:"get",arguments:[K]}),new Proxy(M,v)},set(D,K,q,G){let Y=[...D[Z],{method:"set",arguments:[K,q]}];return _=X(Y),!0},apply(D,K,q){let G=D[F],M=D[Z],Y=W();if(G){let E=M[M.length-1].arguments[0];return M.pop(),X(M)[E](...q)}return Y[Z].push(...M,{method:"apply",arguments:q}),new Proxy(Y,v)}};return new Proxy(W(),v)},P=({scriptToken:B,webhookURL:H,isAsync:z,argv:N})=>{let Q=JSON.stringify({Context:{argv:N}}),J=I.parse(H);J.base=z?"task":"sync_task";let $=I.format(J);return fetch($,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":B},body:Q})},_=null,S=async()=>_,h=async(B,H,z)=>{return B[U][Z].push({method:"set",arguments:[H,z]}),B},w=(B)=>{let H=new URL("https://www.kdocs.cn/api/v3/script/task");return H.searchParams.append("task_id",B),fetch(H)},V=(B)=>{let{status:H,data:z}=B;if(console.log("===result==="),z?.result)console.log(z?.result);let N=z?.logs.filter((J)=>J.filename!=="<system>");if(N.length!==0){console.log("===console===");for(let J of N)console[J.level](...J.args)}let Q=z?.logs.at(-1).unix_time-z?.logs[1].unix_time;console.log("runtime:",Q),console.log("status:",H)},x=(B)=>{let{error:H,error_details:z,errno:N,result:Q,msg:J,reason:$}=B;if(H){let X=Error(z.msg,{cause:`${z.stack.join(`
|
|
2
|
+
`)}
|
|
3
|
+
unix_time:${z.unix_time}`});throw X.name=`Remote ${z.name}`,X}if("errno"in B){let X=Error(Q,{cause:`${J}
|
|
4
|
+
${$}`});throw X.name=`Remote Errno ${N}`,X}},j=(B)=>{return A("./return.wpsjs.json",JSON.stringify(B,void 0,2))};export{j as writeLogFileToCurrent,S as setValueOk,h as setValue,w as queryTask,R as initRemoteCallWpsjsGlobal,P as execution};
|
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InfoItem, RemoteCallWpsjsGlobalReturn, WpsjsGlobalApi } from '
|
|
1
|
+
import type { InfoItem, RemoteCallWpsjsGlobalReturn, WpsjsGlobalApi } from 'tadcode-wpsjs:global'
|
|
2
2
|
import { writeFile } from 'fs/promises'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
@@ -16,60 +16,62 @@ interface Config {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const infoSymbol = Symbol('info-tacode')
|
|
19
|
-
const
|
|
19
|
+
const promiseTagSymbol = Symbol('then-tacode')
|
|
20
20
|
const rawSymbol = Symbol('raw-tacode')
|
|
21
|
+
const promiseTypeObj = { then: 1, catch: 1, finally: 1 }
|
|
21
22
|
|
|
22
|
-
type ProxyTarget = { (): void;[infoSymbol]: InfoItem[], [
|
|
23
|
+
type ProxyTarget = { (): void;[infoSymbol]: InfoItem[], [promiseTagSymbol]: boolean }
|
|
23
24
|
|
|
24
25
|
const initRemoteCallWpsjsGlobal = (config: Config) => {
|
|
25
26
|
const { scriptToken, webhookURL, isAsync = false, printLog = false, writeLogFile = false, } = config
|
|
26
27
|
if (!scriptToken || !webhookURL) { throw new Error('scriptToken and webhookURL are both required') }
|
|
28
|
+
const handleResponse = async (response: Response) => {
|
|
29
|
+
const responseObj = await response.json()
|
|
30
|
+
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
31
|
+
handleError(responseObj)
|
|
32
|
+
if (printLog) printInfo(responseObj)
|
|
33
|
+
return responseObj['data']?.['result']
|
|
34
|
+
}
|
|
35
|
+
const startExecution = async (info: InfoItem[]) =>
|
|
36
|
+
execution({ scriptToken, webhookURL, isAsync, argv: { info } }).then(handleResponse)
|
|
37
|
+
const createProxyTarget = () => {
|
|
38
|
+
const func: ProxyTarget = () => { }
|
|
39
|
+
func[promiseTagSymbol] = false
|
|
40
|
+
func[infoSymbol] = []
|
|
41
|
+
return func
|
|
42
|
+
}
|
|
27
43
|
const handle: ProxyHandler<ProxyTarget> = {
|
|
28
44
|
get(target, p, _receiver) {
|
|
29
45
|
if (p === rawSymbol) { return target }
|
|
30
|
-
const oldInfo = target[infoSymbol]
|
|
31
|
-
const func
|
|
32
|
-
func[
|
|
33
|
-
|
|
34
|
-
if (p
|
|
35
|
-
|
|
36
|
-
else
|
|
37
|
-
func[isThenSymbol] = true
|
|
46
|
+
const oldInfo = target[infoSymbol]
|
|
47
|
+
const func = createProxyTarget()
|
|
48
|
+
const info = func[infoSymbol]
|
|
49
|
+
info.push(...oldInfo)
|
|
50
|
+
if (p in promiseTypeObj) func[promiseTagSymbol] = true
|
|
51
|
+
info.push({ method: 'get', arguments: [p as string] })
|
|
38
52
|
return new Proxy(func, handle)
|
|
39
53
|
},
|
|
40
54
|
set(target, p, newValue, _receiver) {
|
|
41
|
-
const oldInfo = target[infoSymbol]
|
|
42
|
-
const info = [...oldInfo, { method: 'set', arguments: [p, newValue] }]
|
|
43
|
-
setValuePromise =
|
|
44
|
-
.then(async (response) => {
|
|
45
|
-
const responseObj = await response.json()
|
|
46
|
-
if (printLog) printInfo(responseObj)
|
|
47
|
-
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
48
|
-
return responseObj?.['data']['result']
|
|
49
|
-
})
|
|
55
|
+
const oldInfo = target[infoSymbol]
|
|
56
|
+
const info: InfoItem[] = [...oldInfo, { method: 'set', arguments: [p, newValue] }]
|
|
57
|
+
setValuePromise = startExecution(info)
|
|
50
58
|
return true
|
|
51
59
|
},
|
|
52
60
|
apply(target, _thisArg, argArray) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return execution({ scriptToken, webhookURL, isAsync, argv: { info } })
|
|
62
|
-
.then(async (response) => {
|
|
63
|
-
const responseObj = await response.json()
|
|
64
|
-
if (printLog) printInfo(responseObj)
|
|
65
|
-
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
66
|
-
return responseObj?.['data']['result']
|
|
67
|
-
})
|
|
68
|
-
.then(...argArray)
|
|
61
|
+
const isCallPromise = target[promiseTagSymbol]
|
|
62
|
+
const info = target[infoSymbol]
|
|
63
|
+
const func = createProxyTarget()
|
|
64
|
+
if (isCallPromise) {
|
|
65
|
+
const last = info[info.length - 1]
|
|
66
|
+
const p = last.arguments[0] as 'then'
|
|
67
|
+
info.pop()
|
|
68
|
+
return startExecution(info)[p](...argArray)
|
|
69
69
|
}
|
|
70
|
+
func[infoSymbol].push(...info, { method: 'apply', arguments: argArray })
|
|
71
|
+
return new Proxy(func, handle)
|
|
70
72
|
},
|
|
71
73
|
}
|
|
72
|
-
return new Proxy(()
|
|
74
|
+
return new Proxy(createProxyTarget(), handle) as unknown as WpsjsGlobalApi
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
type ExecutionConfig = Pick<Config, 'scriptToken' | 'webhookURL' | 'isAsync'> & { argv?: Record<string | number, any> }
|
|
@@ -114,37 +116,42 @@ const queryTask = (id: string) => {
|
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
|
|
117
|
-
const
|
|
118
|
-
const { status, data, error, error_details } = responseData
|
|
119
|
+
const { status, data, } = remoteCallResponse as RemoteCallWpsjsGlobalReturn
|
|
119
120
|
console.log('===result===')
|
|
120
|
-
console.log(data
|
|
121
|
-
const userInfo = data
|
|
121
|
+
if (data?.result) { console.log(data?.result) }
|
|
122
|
+
const userInfo = data?.logs.filter(x => x.filename !== '<system>')
|
|
122
123
|
if (userInfo.length !== 0) {
|
|
123
124
|
console.log('===console===')
|
|
124
125
|
for (const item of userInfo) {
|
|
125
126
|
console[item.level](...item.args)
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
|
|
129
|
-
console.log('===error===')
|
|
130
|
-
console.error(error_details.name)
|
|
131
|
-
console.error(error_details.msg)
|
|
132
|
-
console.error(error_details.stack)
|
|
133
|
-
console.error(error_details.unix_time)
|
|
134
|
-
}
|
|
135
|
-
const time = data.logs.at(-1)!.unix_time - data.logs[1].unix_time
|
|
129
|
+
const time = data?.logs.at(-1)!.unix_time - data?.logs[1].unix_time
|
|
136
130
|
console.log('runtime:', time)
|
|
137
131
|
console.log('status:', status)
|
|
138
|
-
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const handleError = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
|
|
135
|
+
const { error, error_details, errno, result, msg, reason } = remoteCallResponse as RemoteCallWpsjsGlobalReturn
|
|
136
|
+
if (error) {
|
|
137
|
+
const normalErr = new Error(error_details.msg, { cause: `${error_details.stack.join('\n')}\nunix_time:${error_details.unix_time}` })
|
|
138
|
+
normalErr.name = `Remote ${error_details.name}`
|
|
139
|
+
throw normalErr
|
|
140
|
+
}
|
|
141
|
+
if ('errno' in remoteCallResponse) {
|
|
142
|
+
const err = new Error(result, { cause: `${msg}\n${reason}` })
|
|
143
|
+
err.name = `Remote Errno ${errno}`
|
|
144
|
+
throw err
|
|
145
|
+
}
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
const writeLogFileToCurrent = (data: object) => {
|
|
142
|
-
return writeFile('./wpsjs.
|
|
149
|
+
return writeFile('./return.wpsjs.json', JSON.stringify((data), undefined, 2))
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
export {
|
|
146
|
-
execution,
|
|
147
153
|
initRemoteCallWpsjsGlobal,
|
|
154
|
+
execution,
|
|
148
155
|
queryTask,
|
|
149
156
|
setValueOk,
|
|
150
157
|
setValue,
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tadcode-wpsjs",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.3.0",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"hot": "NODE_ENV=development bun --hot ignore/index.ts",
|
|
8
7
|
"dev": "NODE_ENV=development bun --watch index.ts",
|
|
9
|
-
"build
|
|
10
|
-
"build
|
|
8
|
+
"build:main": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js",
|
|
9
|
+
"build:remotecode": "NODE_ENV=production bun build remoteCode/index.js --target browser --minify --outfile remoteCode/index.min.js"
|
|
11
10
|
},
|
|
12
11
|
"devDependencies": {
|
|
13
12
|
"@types/bun": "latest"
|
|
@@ -17,20 +16,8 @@
|
|
|
17
16
|
],
|
|
18
17
|
"exports": {
|
|
19
18
|
".": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
},
|
|
23
|
-
"./types": {
|
|
24
|
-
"types": "./types/index.d.ts"
|
|
25
|
-
},
|
|
26
|
-
"./types/DB_Application": {
|
|
27
|
-
"types": "./types/DB_Application.d.ts"
|
|
28
|
-
},
|
|
29
|
-
"./types/KSDrive": {
|
|
30
|
-
"types": "./types/KSDrive.d.ts"
|
|
31
|
-
},
|
|
32
|
-
"./types/KSheet_Application": {
|
|
33
|
-
"types": "./types/KSheet_Application.d.ts"
|
|
19
|
+
"types": "./types/index.d.ts",
|
|
20
|
+
"import": "./index.js"
|
|
34
21
|
}
|
|
35
22
|
}
|
|
36
23
|
}
|
package/remoteCode/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/* version 0.2 */
|
|
2
|
-
const { info } = Context.argv
|
|
3
|
-
let peviousTemp = undefined
|
|
4
|
-
let current = globalThis
|
|
5
|
-
for (const item of info) {
|
|
6
|
-
switch (item.method) {
|
|
7
|
-
case 'get': {
|
|
8
|
-
peviousTemp = current
|
|
9
|
-
const [k] = item.arguments
|
|
10
|
-
current = Reflect.get(current, k)
|
|
11
|
-
} break
|
|
12
|
-
case 'set': {
|
|
13
|
-
const [k, v] = item.arguments
|
|
14
|
-
current = Reflect.set(current, k, v)
|
|
15
|
-
} break
|
|
16
|
-
case 'apply': {
|
|
17
|
-
current = Reflect.apply(current, peviousTemp, item.arguments)
|
|
18
|
-
} break
|
|
19
|
-
default:
|
|
20
|
-
throw Error('method must be get or apply')
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return current
|
|
1
|
+
/* version 0.2.1 */
|
|
2
|
+
const { info } = Context.argv
|
|
3
|
+
let peviousTemp = undefined
|
|
4
|
+
let current = globalThis
|
|
5
|
+
for (const item of info) {
|
|
6
|
+
switch (item.method) {
|
|
7
|
+
case 'get': {
|
|
8
|
+
peviousTemp = current
|
|
9
|
+
const [k] = item.arguments
|
|
10
|
+
current = Reflect.get(current, k)
|
|
11
|
+
} break
|
|
12
|
+
case 'set': {
|
|
13
|
+
const [k, v] = item.arguments
|
|
14
|
+
current = Reflect.set(current, k, v)
|
|
15
|
+
} break
|
|
16
|
+
case 'apply': {
|
|
17
|
+
current = Reflect.apply(current, peviousTemp, item.arguments)
|
|
18
|
+
} break
|
|
19
|
+
default:
|
|
20
|
+
throw Error('The method must be get, set, or apply')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return current
|
package/types/KSDrive.d.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
}
|
|
1
|
+
declare module 'tadcode-wpsjs:global' {
|
|
2
|
+
import type DBApplication from 'application:datatable'
|
|
3
|
+
interface FileType {
|
|
4
|
+
/**智能文档 */
|
|
5
|
+
AP: 'o'
|
|
6
|
+
/**智能表格 */
|
|
7
|
+
KSheet: 'k'
|
|
8
|
+
/**表格 */
|
|
9
|
+
ET: 's'
|
|
10
|
+
/**多维表 */
|
|
11
|
+
DB: 'd'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 文件类型
|
|
16
|
+
* - 'o': 智能文档
|
|
17
|
+
* - 'k': 智能表格
|
|
18
|
+
* - 's': 表格
|
|
19
|
+
* - 'd': 多维表
|
|
20
|
+
*/
|
|
21
|
+
type FileTypeValue = FileType[keyof FileType]
|
|
22
|
+
|
|
23
|
+
interface CreateOptions {
|
|
24
|
+
/**是 新文件的文件名 */
|
|
25
|
+
name: string
|
|
26
|
+
/**否 新文件的文件目录 */
|
|
27
|
+
dirUrl?: string
|
|
28
|
+
/**否 将目标文件另存为新文件 */
|
|
29
|
+
source?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface FilesInfo {
|
|
33
|
+
files: FileInfo[]
|
|
34
|
+
nextOffset: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface FileInfo {
|
|
38
|
+
/** 文件名 */
|
|
39
|
+
fileName: string
|
|
40
|
+
/** 加密后的文件 id */
|
|
41
|
+
fileId: string
|
|
42
|
+
/** 文件创建时间戳 */
|
|
43
|
+
createTime: number
|
|
44
|
+
/** 文件修改时间戳 */
|
|
45
|
+
updateTime: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface KSDrive {
|
|
49
|
+
FileType: FileType
|
|
50
|
+
/**
|
|
51
|
+
* 创建文件
|
|
52
|
+
* @param type 新文件的类型
|
|
53
|
+
* @param createOptions 新文件的参数选项
|
|
54
|
+
* @returns 新文件url
|
|
55
|
+
*/
|
|
56
|
+
createFile(type: FileTypeValue, createOptions: CreateOptions): string
|
|
57
|
+
|
|
58
|
+
openFile(url: string): {
|
|
59
|
+
Application: DB_Application
|
|
60
|
+
close()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
listFiles(options?: {
|
|
64
|
+
dirUrl?: string
|
|
65
|
+
offset?: number
|
|
66
|
+
count?: number
|
|
67
|
+
includeExts?: string[]
|
|
68
|
+
}): FilesInfo
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type { KSDrive, FileTypeValue }
|
|
72
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare module 'tadcode-wpsjs:typetools' {
|
|
2
|
+
/**根据给的对象,添加execution方法 */
|
|
3
|
+
type WithExecution<T> = T extends (...args: infer A) => infer R
|
|
4
|
+
? ((...args: A) => WithExecution<R>) & { execution: () => Promise<R> }
|
|
5
|
+
: T extends object
|
|
6
|
+
? { [K in keyof T]: WithExecution<T[K]> } & { execution: () => Promise<T> }
|
|
7
|
+
: T & { execution: () => Promise<T> }
|
|
8
|
+
|
|
9
|
+
/**部分可选 */
|
|
10
|
+
type MakePropertyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
11
|
+
|
|
12
|
+
/**选取修改类型 */
|
|
13
|
+
type PickModify<T, K extends keyof T, M> = {
|
|
14
|
+
[P in K]: M
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 深度可选工具类型
|
|
19
|
+
*/
|
|
20
|
+
type DeepPartial<T> = T extends object
|
|
21
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
22
|
+
: T
|
|
23
|
+
|
|
24
|
+
/**去掉联合类型对象中的id */
|
|
25
|
+
type DistributiveOmit<T, K extends PropertyKey> =
|
|
26
|
+
T extends any ? Omit<T, K> : never
|
|
27
|
+
|
|
28
|
+
/**根据给的对象,添加promise方法 */
|
|
29
|
+
type WithPromise<T> =
|
|
30
|
+
T extends (...args: infer A) => infer R ?
|
|
31
|
+
((...args: A) => WithPromise<R>) & Promise<T> & { [K in keyof T]: WithPromise<T[K]> } :
|
|
32
|
+
T extends Array<infer U> ?
|
|
33
|
+
Array<WithPromise<U>> & Promise<T> :
|
|
34
|
+
T extends object ?
|
|
35
|
+
{ [K in keyof T]: WithPromise<T[K]> } & Promise<T> :
|
|
36
|
+
T extends boolean ?
|
|
37
|
+
Promise<boolean> :
|
|
38
|
+
T extends number ?
|
|
39
|
+
Promise<number> :
|
|
40
|
+
T extends string ?
|
|
41
|
+
Promise<string> :
|
|
42
|
+
Promise<T>
|
|
43
|
+
|
|
44
|
+
// 搞定!🎉
|
|
45
|
+
export type {
|
|
46
|
+
WithExecution,
|
|
47
|
+
MakePropertyOptional,
|
|
48
|
+
PickModify,
|
|
49
|
+
DeepPartial,
|
|
50
|
+
DistributiveOmit,
|
|
51
|
+
WithPromise,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare module 'application:datatable' {
|
|
2
|
+
// 基础类型定义
|
|
3
|
+
type CriteriaOp =
|
|
4
|
+
| 'Equals' | 'NotEqu' | 'Greater' | 'GreaterEqu' | 'Less' | 'LessEqu'
|
|
5
|
+
| 'GreaterEquAndLessEqu' | 'LessOrGreater' | 'BeginWith' | 'EndWith'
|
|
6
|
+
| 'Contains' | 'NotContains' | 'Intersected' | 'Empty' | 'NotEmpty';
|
|
7
|
+
|
|
8
|
+
type DynamicType =
|
|
9
|
+
| 'today' | 'yesterday' | 'tomorrow' | 'last7Days' | 'last30Days'
|
|
10
|
+
| 'thisWeek' | 'lastWeek' | 'nextWeek' | 'thisMonth' | 'lastMonth' | 'nextMonth';
|
|
11
|
+
|
|
12
|
+
// Criteria Value 类型
|
|
13
|
+
interface CriteriaValue {
|
|
14
|
+
type?: string;
|
|
15
|
+
value?: any;
|
|
16
|
+
dynamicType?: DynamicType;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Criteria 接口
|
|
20
|
+
interface Criteria {
|
|
21
|
+
// 属性
|
|
22
|
+
Field: number | string;
|
|
23
|
+
Op: CriteriaOp;
|
|
24
|
+
Values: CriteriaValue[];
|
|
25
|
+
|
|
26
|
+
// 注意:文档中显示有 Criteria 构造函数/工厂方法,但这里是接口定义
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 导出 Criteria 类型
|
|
30
|
+
export type { Criteria };
|
|
31
|
+
}
|