tadcode-wpsjs 0.1.2 → 0.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 +58 -15
- package/index.js +1 -2
- package/index.ts +105 -80
- package/package.json +15 -15
- package/remoteCode/index.js +17 -13
- package/tsconfig.json +25 -25
- package/types/DB_Application.d.ts +17 -220
- package/types/DB_Application_Field.d.ts +212 -0
- package/types/DB_Application_Record.d.ts +178 -0
- package/types/DB_Application_Selection.ts +22 -0
- package/types/DB_Application_Sheet.d.ts +63 -0
- package/types/DB_Application_View.d.ts +24 -0
- package/types/KSDrive.d.ts +51 -44
- package/types/KSheet_Application.d.ts +25 -21
- package/types/index.d.ts +34 -73
- package/types/type-tools.ts +28 -8
- package/.editorconfig +0 -16
- package/.vscode/launch.json +0 -44
- package/.vscode/settings.json +0 -26
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# tadcode-wpsjs
|
|
2
2
|
|
|
3
|
-
基于wps官方文档
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
## 基于wps官方文档
|
|
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)
|
|
6
8
|
|
|
7
9
|
## 联系我
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
**如你有业务需要wps代码服务,可以点此[联系我](https://f.kdocs.cn/g/SIdEy3GE/),三个工作日内必定回复。**
|
|
10
12
|
|
|
11
13
|
**如您公司存在敏感信息业务,需要长期人才,亦可来讯商谈。**
|
|
12
14
|
|
|
@@ -14,13 +16,13 @@
|
|
|
14
16
|
|
|
15
17
|
## 应用
|
|
16
18
|
|
|
17
|
-
用于学习
|
|
19
|
+
用于学习wpsjs-api,远程调用wpsjs-api。
|
|
18
20
|
|
|
19
|
-
使用wpsjs-
|
|
21
|
+
使用wpsjs-api。支持异步任务。
|
|
20
22
|
|
|
21
23
|
在远程部署代码好代码,通过传输的调用信息进行调用api。原理是使用代理收集调用信息,之后让远程代码进行调用并且返回结果。
|
|
22
24
|
|
|
23
|
-
远程代码在`remoteCode`目录的`index.js
|
|
25
|
+
远程代码在`tadcode-wpsjs/remoteCode`目录的`index.js`文件中。将其复制粘贴到对应`webhook`的脚本中才能支持`wpsjsGlobal`的调用。
|
|
24
26
|
|
|
25
27
|
## 安装
|
|
26
28
|
|
|
@@ -29,24 +31,65 @@
|
|
|
29
31
|
## 获取脚本令牌和webhook链接
|
|
30
32
|
|
|
31
33
|
### 获取脚本令牌
|
|
34
|
+
|
|
32
35
|

|
|
33
36
|
|
|
34
37
|
### webhook链接
|
|
38
|
+
|
|
39
|
+
**!!!webhook链接的脚本内容必须部署为`tadcode-wpsjs/remoteCode/index.js`中的脚本内容。**
|
|
40
|
+
|
|
35
41
|

|
|
36
42
|
|
|
37
43
|
## 案例
|
|
38
44
|
|
|
45
|
+
### 获取当前多维表的所有表格信息
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { initRemoteCallWpsjsGlobal } from 'tadcode-wpsjs'
|
|
49
|
+
/* 脚本令牌 具体获取方式参考上面 */
|
|
50
|
+
const scriptToken = 'xxxx'
|
|
51
|
+
/* webhook url地址 具体获取方式参考上面 */
|
|
52
|
+
const webhookURL = 'xxxx'
|
|
53
|
+
const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, })
|
|
54
|
+
const data = await wpsjsGlobal.Application.Sheet.GetSheets().execution()
|
|
55
|
+
console.log(data)
|
|
56
|
+
```
|
|
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
|
+
### 执行脚本并且返回(不用部署remoteCode代码)
|
|
81
|
+
|
|
39
82
|
```ts
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const data =
|
|
83
|
+
import { execution } from 'tadcode-wpsjs'
|
|
84
|
+
/* 脚本令牌 具体获取方式参考上面 */
|
|
85
|
+
const scriptToken = 'xxxx'
|
|
86
|
+
/* webhook url地址 具体获取方式参考上面 */
|
|
87
|
+
const webhookURL = 'xxxx'
|
|
88
|
+
const result=await execution({ scriptToken, webhookURL })
|
|
89
|
+
const data =await result.json()
|
|
47
90
|
console.log(data)
|
|
48
91
|
```
|
|
49
92
|
|
|
50
93
|
## 支持
|
|
51
94
|
|
|
52
|
-
|
|
95
|
+
如果对你有用请在[gitcode](https://gitcode.com/caisijian/tadcode-wpsjs)给个`star`
|
package/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
//
|
|
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};
|
|
1
|
+
var{writeFile:M}=(()=>({}));function o(e){if(typeof e!=="string")throw TypeError("Path must be a string. Received "+JSON.stringify(e))}function m(e,r){var n="",l=0,t=-1,f=0,i;for(var s=0;s<=e.length;++s){if(s<e.length)i=e.charCodeAt(s);else if(i===47)break;else i=47;if(i===47){if(t===s-1||f===1);else if(t!==s-1&&f===2){if(n.length<2||l!==2||n.charCodeAt(n.length-1)!==46||n.charCodeAt(n.length-2)!==46){if(n.length>2){var c=n.lastIndexOf("/");if(c!==n.length-1){if(c===-1)n="",l=0;else n=n.slice(0,c),l=n.length-1-n.lastIndexOf("/");t=s,f=0;continue}}else if(n.length===2||n.length===1){n="",l=0,t=s,f=0;continue}}if(r){if(n.length>0)n+="/..";else n="..";l=2}}else{if(n.length>0)n+="/"+e.slice(t+1,s);else n=e.slice(t+1,s);l=s-t-1}t=s,f=0}else if(i===46&&f!==-1)++f;else f=-1}return n}function h(e,r){var n=r.dir||r.root,l=r.base||(r.name||"")+(r.ext||"");if(!n)return l;if(n===r.root)return n+l;return n+e+l}function A(){var e="",r=!1,n;for(var l=arguments.length-1;l>=-1&&!r;l--){var t;if(l>=0)t=arguments[l];else{if(n===void 0)n=process.cwd();t=n}if(o(t),t.length===0)continue;e=t+"/"+e,r=t.charCodeAt(0)===47}if(e=m(e,!r),r)if(e.length>0)return"/"+e;else return"/";else if(e.length>0)return e;else return"."}function b(e){if(o(e),e.length===0)return".";var r=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;if(e=m(e,!r),e.length===0&&!r)e=".";if(e.length>0&&n)e+="/";if(r)return"/"+e;return e}function S(e){return o(e),e.length>0&&e.charCodeAt(0)===47}function k(){if(arguments.length===0)return".";var e;for(var r=0;r<arguments.length;++r){var n=arguments[r];if(o(n),n.length>0)if(e===void 0)e=n;else e+="/"+n}if(e===void 0)return".";return b(e)}function y(e,r){if(o(e),o(r),e===r)return"";if(e=A(e),r=A(r),e===r)return"";var n=1;for(;n<e.length;++n)if(e.charCodeAt(n)!==47)break;var l=e.length,t=l-n,f=1;for(;f<r.length;++f)if(r.charCodeAt(f)!==47)break;var i=r.length,s=i-f,c=t<s?t:s,g=-1,u=0;for(;u<=c;++u){if(u===c){if(s>c){if(r.charCodeAt(f+u)===47)return r.slice(f+u+1);else if(u===0)return r.slice(f+u)}else if(t>c){if(e.charCodeAt(n+u)===47)g=u;else if(u===0)g=0}break}var v=e.charCodeAt(n+u),a=r.charCodeAt(f+u);if(v!==a)break;else if(v===47)g=u}var d="";for(u=n+g+1;u<=l;++u)if(u===l||e.charCodeAt(u)===47)if(d.length===0)d+="..";else d+="/..";if(d.length>0)return d+r.slice(f+g);else{if(f+=g,r.charCodeAt(f)===47)++f;return r.slice(f)}}function P(e){return e}function z(e){if(o(e),e.length===0)return".";var r=e.charCodeAt(0),n=r===47,l=-1,t=!0;for(var f=e.length-1;f>=1;--f)if(r=e.charCodeAt(f),r===47){if(!t){l=f;break}}else t=!1;if(l===-1)return n?"/":".";if(n&&l===1)return"//";return e.slice(0,l)}function D(e,r){if(r!==void 0&&typeof r!=="string")throw TypeError('"ext" argument must be a string');o(e);var n=0,l=-1,t=!0,f;if(r!==void 0&&r.length>0&&r.length<=e.length){if(r.length===e.length&&r===e)return"";var i=r.length-1,s=-1;for(f=e.length-1;f>=0;--f){var c=e.charCodeAt(f);if(c===47){if(!t){n=f+1;break}}else{if(s===-1)t=!1,s=f+1;if(i>=0)if(c===r.charCodeAt(i)){if(--i===-1)l=f}else i=-1,l=s}}if(n===l)l=s;else if(l===-1)l=e.length;return e.slice(n,l)}else{for(f=e.length-1;f>=0;--f)if(e.charCodeAt(f)===47){if(!t){n=f+1;break}}else if(l===-1)t=!1,l=f+1;if(l===-1)return"";return e.slice(n,l)}}function E(e){o(e);var r=-1,n=0,l=-1,t=!0,f=0;for(var i=e.length-1;i>=0;--i){var s=e.charCodeAt(i);if(s===47){if(!t){n=i+1;break}continue}if(l===-1)t=!1,l=i+1;if(s===46){if(r===-1)r=i;else if(f!==1)f=1}else if(r!==-1)f=-1}if(r===-1||l===-1||f===0||f===1&&r===l-1&&r===n+1)return"";return e.slice(r,l)}function J(e){if(e===null||typeof e!=="object")throw TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return h("/",e)}function w(e){o(e);var r={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return r;var n=e.charCodeAt(0),l=n===47,t;if(l)r.root="/",t=1;else t=0;var f=-1,i=0,s=-1,c=!0,g=e.length-1,u=0;for(;g>=t;--g){if(n=e.charCodeAt(g),n===47){if(!c){i=g+1;break}continue}if(s===-1)c=!1,s=g+1;if(n===46){if(f===-1)f=g;else if(u!==1)u=1}else if(f!==-1)u=-1}if(f===-1||s===-1||u===0||u===1&&f===s-1&&f===i+1){if(s!==-1)if(i===0&&l)r.base=r.name=e.slice(1,s);else r.base=r.name=e.slice(i,s)}else{if(i===0&&l)r.name=e.slice(1,f),r.base=e.slice(1,s);else r.name=e.slice(i,f),r.base=e.slice(i,s);r.ext=e.slice(f,s)}if(i>0)r.dir=e.slice(0,i-1);else if(l)r.dir="/";return r}var B="/",H=":",K=((e)=>(e.posix=e,e))({resolve:A,normalize:b,isAbsolute:S,join:k,relative:y,_makeLong:P,dirname:z,basename:D,extname:E,format:J,parse:w,sep:B,delimiter:H,win32:null,posix:null}),C=K;var q=(e)=>{let{scriptToken:r,webhookURL:n,isAsync:l=!1,printLog:t=!1,writeLogFile:f=!1}=e,i=[];return new Proxy(()=>{},{get:(c,g,u)=>{return i.push({method:"get",arguments:[g]}),u},set:(c,g,u,v)=>{return i.push({method:"set",arguments:[g,u]}),v},apply:(c,g,u)=>{if(i.at(-1)?.arguments[0]==="execution")return i.pop(),Q({scriptToken:r,webhookURL:n,isAsync:l,argv:{info:i}}).then(async(a)=>{let d=await a.json();if(i=[],t)X(d);if(f)await Y(d);return d.data.result});return i.push({method:"apply",arguments:u}),g}})},Q=({scriptToken:e,webhookURL:r,isAsync:n,argv:l})=>{let t=JSON.stringify({Context:{argv:l}}),f=C.parse(r);f.base=n?"task":"sync_task";let i=C.format(f);return fetch(i,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":e},body:t})},G=(e)=>{let r=new URL("https://www.kdocs.cn/api/v3/script/task");return r.searchParams.append("task_id",e),fetch(r)},X=(e)=>{let r=e,{status:n,data:l,error:t,error_details:f}=r;console.log("status:",n);let i=l.logs.at(-1).unix_time-l.logs[1].unix_time;if(console.log("runtime:",i),t)console.error(f.name),console.error(f.msg),console.error(f.stack);let s=l.logs.filter((c)=>c.filename!=="<system>");if(s.length!==0){console.log("log:");for(let c of s)console[c.level](...c.args)}return console.log("result:"),console.log(l.result),r},Y=(e)=>{return M("./wpsjs.log.json",JSON.stringify(e,void 0,2))};export{Y as writeLogFileToCurrent,G as queryTask,q as initRemoteCallWpsjsGlobal,Q as execution};
|
package/index.ts
CHANGED
|
@@ -1,85 +1,110 @@
|
|
|
1
1
|
import type { InfoItem, RemoteCallWpsjsGlobalReturn, WithExecutionWpsjsGlobal } from './types'
|
|
2
|
+
import { writeFile } from 'fs/promises'
|
|
2
3
|
import path from 'path'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
wpsjsGlobal = new Proxy(() => { }, {
|
|
16
|
-
get: (_target, p, receiver) => {
|
|
17
|
-
this.info.push({ method: 'get', arguments: [p] })
|
|
18
|
-
return receiver
|
|
19
|
-
},
|
|
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
|
|
34
|
-
},
|
|
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
|
-
}
|
|
42
|
-
execute() {
|
|
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 = []
|
|
50
|
-
/* 根据是否同步返回不同的url */
|
|
51
|
-
const parsedPath = path.parse(webhookURL)
|
|
52
|
-
parsedPath.base = sync ? 'sync_task' : 'task'
|
|
53
|
-
const url = path.format(parsedPath)
|
|
54
|
-
return fetch(url, {
|
|
55
|
-
method: 'post',
|
|
56
|
-
headers: {
|
|
57
|
-
'Content-Type': 'application/json',
|
|
58
|
-
'AirScript-Token': scriptToken
|
|
59
|
-
},
|
|
60
|
-
body: data
|
|
61
|
-
})
|
|
62
|
-
}
|
|
4
|
+
|
|
5
|
+
interface Config {
|
|
6
|
+
/**脚本令牌 */
|
|
7
|
+
scriptToken: string
|
|
8
|
+
/**脚本链接 */
|
|
9
|
+
webhookURL: string
|
|
10
|
+
/**异步任务 */
|
|
11
|
+
isAsync?: boolean
|
|
12
|
+
/**在控制台打印日志 */
|
|
13
|
+
printLog?: boolean
|
|
14
|
+
/**在当前路径下写入日志文件 */
|
|
15
|
+
writeLogFile?: boolean
|
|
63
16
|
}
|
|
17
|
+
|
|
18
|
+
const initRemoteCallWpsjsGlobal = (config: Config) => {
|
|
19
|
+
const { scriptToken, webhookURL, isAsync = false, printLog = false, writeLogFile = false, } = config
|
|
20
|
+
let info: InfoItem[] = []
|
|
21
|
+
const handle: ProxyHandler<() => void> = {
|
|
22
|
+
get: (_target, p: string, receiver) => {
|
|
23
|
+
info.push({ method: 'get', arguments: [p] })
|
|
24
|
+
return receiver
|
|
25
|
+
},
|
|
26
|
+
set: (_target, p: string, newValue, receiver) => {
|
|
27
|
+
info.push({ method: 'set', arguments: [p, newValue] })
|
|
28
|
+
return receiver
|
|
29
|
+
},
|
|
30
|
+
apply: (_target, thisArg, argArray) => {
|
|
31
|
+
const lastInfo = info.at(-1)
|
|
32
|
+
if (lastInfo?.arguments[0] === 'execution') {
|
|
33
|
+
info.pop() /* 删除 execution的调用信息 */
|
|
34
|
+
return execution({ scriptToken, webhookURL, isAsync, argv: { info } })
|
|
35
|
+
.then(async (response) => {
|
|
36
|
+
const responseObj = await response.json()
|
|
37
|
+
info = [] /* 执行结束,清空调用 */
|
|
38
|
+
if (printLog) printInfo(responseObj)
|
|
39
|
+
|
|
40
|
+
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
41
|
+
return responseObj['data']['result']
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
info.push({ method: 'apply', arguments: argArray })
|
|
45
|
+
return thisArg
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
return new Proxy(() => { }, handle) as unknown as WithExecutionWpsjsGlobal
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ExecutionConfig = Pick<Config, 'scriptToken' | 'webhookURL' | 'isAsync'> & { argv?: Record<string | number, any> }
|
|
52
|
+
|
|
53
|
+
const execution = ({ scriptToken, webhookURL, isAsync, argv }: ExecutionConfig) => {
|
|
54
|
+
/* 获取请求信息 */
|
|
55
|
+
const data = JSON.stringify({ Context: { argv, } })
|
|
56
|
+
/* 根据是否同步返回不同的url */
|
|
57
|
+
const parsedPath = path.parse(webhookURL)
|
|
58
|
+
parsedPath.base = isAsync ? 'task' : 'sync_task'
|
|
59
|
+
const url = path.format(parsedPath)
|
|
60
|
+
return fetch(url, {
|
|
61
|
+
method: 'post',
|
|
62
|
+
headers: {
|
|
63
|
+
'Content-Type': 'application/json',
|
|
64
|
+
'AirScript-Token': scriptToken
|
|
65
|
+
},
|
|
66
|
+
body: data
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const queryTask = (id: string) => {
|
|
71
|
+
const url = new URL('https://www.kdocs.cn/api/v3/script/task')
|
|
72
|
+
url.searchParams.append('task_id', id)
|
|
73
|
+
return fetch(url)
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
const responseData = remoteCallResponse as RemoteCallWpsjsGlobalReturn
|
|
78
|
+
const { status, data, error, error_details } = responseData
|
|
79
|
+
console.log('status:', status)
|
|
80
|
+
const time = data.logs.at(-1)!.unix_time - data.logs[1].unix_time
|
|
81
|
+
console.log('runtime:', time)
|
|
82
|
+
if (error) {
|
|
83
|
+
console.error(error_details.name)
|
|
84
|
+
console.error(error_details.msg)
|
|
85
|
+
console.error(error_details.stack)
|
|
86
|
+
}
|
|
87
|
+
const userInfo = data.logs.filter(x => x.filename !== '<system>')
|
|
88
|
+
if (userInfo.length !== 0) {
|
|
89
|
+
console.log('log:')
|
|
90
|
+
for (const item of userInfo) {
|
|
91
|
+
console[item.level](...item.args)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
console.log('result:')
|
|
95
|
+
console.log(data.result)
|
|
96
|
+
return responseData
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const writeLogFileToCurrent = (data: object) => {
|
|
100
|
+
return writeFile('./wpsjs.log.json', JSON.stringify((data), undefined, 2))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type * from './types'
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
execution,
|
|
107
|
+
initRemoteCallWpsjsGlobal,
|
|
108
|
+
queryTask,
|
|
109
|
+
writeLogFileToCurrent,
|
|
85
110
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
"name": "tadcode-wpsjs",
|
|
3
|
+
"version": "0.3.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
17
|
}
|
package/remoteCode/index.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
/* version 0.
|
|
1
|
+
/* version 0.2 */
|
|
2
2
|
const { info } = Context.argv
|
|
3
3
|
let peviousTemp = undefined
|
|
4
4
|
let current = globalThis
|
|
5
5
|
for (const item of info) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|
|
18
22
|
}
|
|
19
23
|
return current
|
package/tsconfig.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable latest features
|
|
4
|
+
"lib": [
|
|
5
|
+
"ESNext",
|
|
6
|
+
"DOM"
|
|
7
|
+
],
|
|
8
|
+
"target": "ESNext",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleDetection": "force",
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"allowJs": true,
|
|
13
|
+
// Bundler mode
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"allowImportingTsExtensions": true,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
// Best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
// Some stricter flags (disabled by default)
|
|
23
|
+
"noUnusedLocals": false,
|
|
24
|
+
"noUnusedParameters": false,
|
|
25
|
+
"noPropertyAccessFromIndexSignature": false
|
|
26
|
+
}
|
|
27
27
|
}
|