tadcode-wpsjs 1.0.0 → 1.1.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 +15 -0
- package/index.js +1 -1
- package/index.ts +19 -0
- package/package.json +3 -2
- package/remoteCode/index.min.js +1 -0
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
- [**WPS多维表格:“开发”功能使用说明文档**](https://365.kdocs.cn/l/ctzsgDlAGF0l)
|
|
6
6
|
- [**执行AirScript脚本操作使用指南**](https://365.kdocs.cn/l/cdQOqc6TZuMk)
|
|
7
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)
|
|
8
9
|
|
|
9
10
|
## 联系我
|
|
10
11
|
|
|
@@ -55,6 +56,20 @@ const data = await wpsjsGlobal.Application.Sheet.GetSheets()
|
|
|
55
56
|
console.log(data)
|
|
56
57
|
```
|
|
57
58
|
|
|
59
|
+
### 重命名(远程赋值操作)
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { initRemoteCallWpsjsGlobal } from 'tadcode-wpsjs'
|
|
63
|
+
/* 脚本令牌 具体获取方式参考上面 */
|
|
64
|
+
const scriptToken = 'xxxx'
|
|
65
|
+
/* webhook url地址 具体获取方式参考上面 */
|
|
66
|
+
const webhookURL = 'xxxx'
|
|
67
|
+
const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, })
|
|
68
|
+
/* 类型完善中 */
|
|
69
|
+
wpsjsGlobal.Application.Sheets(1).Name = 'new table4'
|
|
70
|
+
console.log(data)
|
|
71
|
+
```
|
|
72
|
+
|
|
58
73
|
### 执行脚本并且返回(不用部署remoteCode代码)
|
|
59
74
|
|
|
60
75
|
```ts
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{writeFile as
|
|
1
|
+
import{writeFile as V}from"fs/promises";import v from"path";var Q=Symbol("info"),G=Symbol("then"),I=(J)=>{let{scriptToken:B,webhookURL:X,isAsync:K=!1,printLog:Y=!1,writeLogFile:M=!1}=J,N={get(E,H,$){let Z=E[Q]??=[],z=()=>{};if(z[G]=!1,z[Q]=[...Z],H!=="then")z[Q].push({method:"get",arguments:[H]});else z[G]=!0;return new Proxy(z,N)},set(E,H,$,Z){let q=[...E[Q]??=[],{method:"set",arguments:[H,$]}];return U=D({scriptToken:B,webhookURL:X,isAsync:K,argv:{info:q}}).then(async(x)=>{let W=await x.json();if(Y)_(W);if(M)await P(W);return W?.data.result}),!0},apply(E,H,$){if(!E[G]){let Z=E[Q]??=[],z=()=>{};return z[G]=!1,z[Q]=[...Z,{method:"apply",arguments:$}],new Proxy(z,N)}else{let Z=E[Q];return D({scriptToken:B,webhookURL:X,isAsync:K,argv:{info:Z}}).then(async(z)=>{let q=await z.json();if(Y)_(q);if(M)await P(q);return q?.data.result}).then(...$)}}};return new Proxy(()=>{},N)},D=({scriptToken:J,webhookURL:B,isAsync:X,argv:K})=>{let Y=JSON.stringify({Context:{argv:K}}),M=v.parse(B);M.base=X?"task":"sync_task";let N=v.format(M);return fetch(N,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":J},body:Y})},U=null,j=async()=>U,O=(J)=>{let B=new URL("https://www.kdocs.cn/api/v3/script/task");return B.searchParams.append("task_id",J),fetch(B)},_=(J)=>{let B=J,{status:X,data:K,error:Y,error_details:M}=B;console.log("status:",X);let N=K.logs.at(-1).unix_time-K.logs[1].unix_time;if(console.log("runtime:",N),Y)console.error(M.name),console.error(M.msg),console.error(M.stack);let E=K.logs.filter((H)=>H.filename!=="<system>");if(E.length!==0){console.log("log:");for(let H of E)console[H.level](...H.args)}return console.log("result:"),console.log(K.result),B},P=(J)=>{return V("./wpsjs.log.json",JSON.stringify(J,void 0,2))};export{P as writeLogFileToCurrent,j as setValueOk,O as queryTask,I as initRemoteCallWpsjsGlobal,D as execution};
|
package/index.ts
CHANGED
|
@@ -14,8 +14,10 @@ interface Config {
|
|
|
14
14
|
/**在当前路径下写入日志文件 */
|
|
15
15
|
writeLogFile?: boolean
|
|
16
16
|
}
|
|
17
|
+
|
|
17
18
|
const infoSymbol = Symbol('info')
|
|
18
19
|
const isThenSymbol = Symbol('then')
|
|
20
|
+
|
|
19
21
|
const initRemoteCallWpsjsGlobal = (config: Config) => {
|
|
20
22
|
const { scriptToken, webhookURL, isAsync = false, printLog = false, writeLogFile = false, } = config
|
|
21
23
|
type ProxyTarget = { (): void;[infoSymbol]: InfoItem[], [isThenSymbol]: boolean }
|
|
@@ -32,6 +34,18 @@ const initRemoteCallWpsjsGlobal = (config: Config) => {
|
|
|
32
34
|
func[isThenSymbol] = true
|
|
33
35
|
return new Proxy(func, handle)
|
|
34
36
|
},
|
|
37
|
+
set(target, p, newValue, _receiver) {
|
|
38
|
+
const oldInfo = target[infoSymbol] ??= []
|
|
39
|
+
const info = [...oldInfo, { method: 'set', arguments: [p, newValue] }]
|
|
40
|
+
setValuePromise = execution({ scriptToken, webhookURL, isAsync, argv: { info } })
|
|
41
|
+
.then(async (response) => {
|
|
42
|
+
const responseObj = await response.json()
|
|
43
|
+
if (printLog) printInfo(responseObj)
|
|
44
|
+
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
45
|
+
return responseObj?.['data']['result']
|
|
46
|
+
})
|
|
47
|
+
return true
|
|
48
|
+
},
|
|
35
49
|
apply(target, _thisArg, argArray) {
|
|
36
50
|
if (!target[isThenSymbol]) {
|
|
37
51
|
const oldInfo = target[infoSymbol] ??= []
|
|
@@ -74,6 +88,10 @@ const execution = ({ scriptToken, webhookURL, isAsync, argv }: ExecutionConfig)
|
|
|
74
88
|
})
|
|
75
89
|
}
|
|
76
90
|
|
|
91
|
+
let setValuePromise: any = null
|
|
92
|
+
/* 远程调用的赋值操作返回的promise */
|
|
93
|
+
const setValueOk = async () => setValuePromise
|
|
94
|
+
|
|
77
95
|
const queryTask = (id: string) => {
|
|
78
96
|
const url = new URL('https://www.kdocs.cn/api/v3/script/task')
|
|
79
97
|
url.searchParams.append('task_id', id)
|
|
@@ -111,5 +129,6 @@ export {
|
|
|
111
129
|
execution,
|
|
112
130
|
initRemoteCallWpsjsGlobal,
|
|
113
131
|
queryTask,
|
|
132
|
+
setValueOk,
|
|
114
133
|
writeLogFileToCurrent,
|
|
115
134
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tadcode-wpsjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"hot": "NODE_ENV=development bun --hot ignore/index.ts",
|
|
8
8
|
"dev": "NODE_ENV=development bun --watch index.ts",
|
|
9
|
-
"build": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js"
|
|
9
|
+
"build-main": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js",
|
|
10
|
+
"build-remotecode": "NODE_ENV=production bun build remoteCode/index.js --target browser --minify --outfile remoteCode/index.min.js"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"@types/bun": "latest"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{info:a}=Context.argv,s=void 0,e=globalThis;for(let t of a)switch(t.method){case"get":{s=e;let[r]=t.arguments;e=Reflect.get(e,r)}break;case"set":{let[r,o]=t.arguments;e=Reflect.set(e,r,o)}break;case"apply":e=Reflect.apply(e,s,t.arguments);break;default:throw Error("method must be get or apply")}return e;
|