tadcode-wpsjs 0.1.3 → 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 CHANGED
@@ -1,8 +1,10 @@
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)
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
 
@@ -14,7 +16,7 @@
14
16
 
15
17
  ## 应用
16
18
 
17
- 用于学习wpsjsapi,远程调用wpsjs-api。
19
+ 用于学习wpsjs-api,远程调用wpsjs-api。
18
20
 
19
21
  使用wpsjs-api。支持异步任务。
20
22
 
@@ -53,6 +55,28 @@ const data = await wpsjsGlobal.Application.Sheet.GetSheets().execution()
53
55
  console.log(data)
54
56
  ```
55
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
+
56
80
  ### 执行脚本并且返回(不用部署remoteCode代码)
57
81
 
58
82
  ```ts
@@ -68,4 +92,4 @@ console.log(data)
68
92
 
69
93
  ## 支持
70
94
 
71
- 如果对你有用请给个`star`
95
+ 如果对你有用请在[gitcode](https://gitcode.com/caisijian/tadcode-wpsjs)给个`star`
package/index.js CHANGED
@@ -1,2 +1 @@
1
- // @bun
2
- import{writeFile as $}from"fs/promises";import Y from"path";var O=(B)=>{let{scriptToken:E,webhookURL:M,isAsync:H=!1,printLog:N=!1,writeLogFile:J=!1}=B,z=[];return new Proxy(()=>{},{get:(K,S,V)=>{return z.push({method:"get",arguments:[S]}),V},apply:(K,S,V)=>{if(z.at(-1)?.arguments[0]==="execution")return z.pop(),q({scriptToken:E,webhookURL:M,isAsync:H,argv:{info:z}}).then(async(Z)=>{let X=await Z.json();if(z=[],N)G(X);if(J)W(X);return X.data.result});return z.push({method:"apply",arguments:V}),S}})},q=({scriptToken:B,webhookURL:E,isAsync:M,argv:H})=>{let N=JSON.stringify({Context:{argv:H}}),J=Y.parse(E);J.base=M?"task":"sync_task";let z=Y.format(J);return fetch(z,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":B},body:N})},U=(B)=>{let E=new URL("https://www.kdocs.cn/api/v3/script/task");return E.searchParams.append("task_id",B),fetch(E)},G=(B)=>{let E=B,{status:M,data:H,error:N,error_details:J}=E;console.log("status:",M);let z=H.logs.at(-1).unix_time-H.logs[1].unix_time;if(console.log("runtime:",z),N)console.error(J.name),console.error(J.msg),console.error(J.stack);let Q=H.logs.filter((K)=>K.filename!=="<system>");if(Q.length!==0){console.log("log:");for(let K of Q)console[K.level](...K.args)}return console.log("result:"),console.log(H.result),E},W=(B)=>{$("./wpsjs.log.json",JSON.stringify(B,void 0,4))};export{W as writeLogFileToCurrent,U as queryTask,O as initRemoteCallWpsjsGlobal,q as execution};
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,87 +1,110 @@
1
1
  import type { InfoItem, RemoteCallWpsjsGlobalReturn, WithExecutionWpsjsGlobal } from './types'
2
2
  import { writeFile } from 'fs/promises'
3
3
  import path from 'path'
4
+
4
5
  interface Config {
5
- scriptToken: string
6
- webhookURL: string
7
- isAsync?: boolean
8
- printLog?: boolean
9
- writeLogFile?: boolean
6
+ /**脚本令牌 */
7
+ scriptToken: string
8
+ /**脚本链接 */
9
+ webhookURL: string
10
+ /**异步任务 */
11
+ isAsync?: boolean
12
+ /**在控制台打印日志 */
13
+ printLog?: boolean
14
+ /**在当前路径下写入日志文件 */
15
+ writeLogFile?: boolean
10
16
  }
17
+
11
18
  const initRemoteCallWpsjsGlobal = (config: Config) => {
12
- const { scriptToken, webhookURL, isAsync = false, printLog = false, writeLogFile = false, } = config
13
- let info: InfoItem[] = []
14
- const handle: ProxyHandler<() => void> = {
15
- get: (_target, p: string, receiver) => {
16
- info.push({ method: 'get', arguments: [p] })
17
- return receiver
18
- },
19
- apply: (_target, thisArg, argArray) => {
20
- const lastInfo = info.at(-1)
21
- if (lastInfo?.arguments[0] === 'execution') {
22
- info.pop() /* 删除 execution的调用信息 */
23
- return execution({ scriptToken, webhookURL, isAsync, argv: { info } })
24
- .then(async (response) => {
25
- const responseObj = await response.json()
26
- info = [] /* 执行结束,清空调用 */
27
- if (printLog) printInfo(responseObj)
28
- if (writeLogFile) writeLogFileToCurrent(responseObj)
29
- return responseObj['data']['result']
30
- })
31
- }
32
- info.push({ method: 'apply', arguments: argArray })
33
- return thisArg
34
- },
35
- }
36
- return new Proxy(() => { }, handle) as unknown as WithExecutionWpsjsGlobal
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
37
49
  }
50
+
38
51
  type ExecutionConfig = Pick<Config, 'scriptToken' | 'webhookURL' | 'isAsync'> & { argv?: Record<string | number, any> }
52
+
39
53
  const execution = ({ scriptToken, webhookURL, isAsync, argv }: ExecutionConfig) => {
40
- /* 获取请求信息 */
41
- const data = JSON.stringify({ Context: { argv, } })
42
- /* 根据是否同步返回不同的url */
43
- const parsedPath = path.parse(webhookURL)
44
- parsedPath.base = isAsync ? 'task' : 'sync_task'
45
- const url = path.format(parsedPath)
46
- return fetch(url, {
47
- method: 'post',
48
- headers: {
49
- 'Content-Type': 'application/json',
50
- 'AirScript-Token': scriptToken
51
- },
52
- body: data
53
- })
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
+ })
54
68
  }
69
+
55
70
  const queryTask = (id: string) => {
56
- const url = new URL('https://www.kdocs.cn/api/v3/script/task')
57
- url.searchParams.append('task_id', id)
58
- return fetch(url)
71
+ const url = new URL('https://www.kdocs.cn/api/v3/script/task')
72
+ url.searchParams.append('task_id', id)
73
+ return fetch(url)
59
74
  }
75
+
60
76
  const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
61
- const responseData = remoteCallResponse as RemoteCallWpsjsGlobalReturn
62
- const { status, data, error, error_details } = responseData
63
- console.log('status:', status)
64
- const time = data.logs.at(-1)!.unix_time - data.logs[1].unix_time
65
- console.log('runtime:', time)
66
- if (error) {
67
- console.error(error_details.name)
68
- console.error(error_details.msg)
69
- console.error(error_details.stack)
70
- }
71
- const userInfo = data.logs.filter(x => x.filename !== '<system>')
72
- if (userInfo.length !== 0) {
73
- console.log('log:')
74
- for (const item of userInfo) {
75
- console[item.level](...item.args)
76
- }
77
- }
78
- console.log('result:')
79
- console.log(data.result)
80
- return responseData
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
81
97
  }
98
+
82
99
  const writeLogFileToCurrent = (data: object) => {
83
- writeFile('./wpsjs.log.json', JSON.stringify((data), undefined, 4))
100
+ return writeFile('./wpsjs.log.json', JSON.stringify((data), undefined, 2))
84
101
  }
85
102
 
86
- export { execution, initRemoteCallWpsjsGlobal, queryTask, writeLogFileToCurrent }
87
103
  export type * from './types'
104
+
105
+ export {
106
+ execution,
107
+ initRemoteCallWpsjsGlobal,
108
+ queryTask,
109
+ writeLogFileToCurrent,
110
+ }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
- "name": "tadcode-wpsjs",
3
- "version": "0.1.3",
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 bun --minify --outfile index.js"
10
- },
11
- "devDependencies": {
12
- "@types/bun": "latest"
13
- },
14
- "keywords": [
15
- "tadcode-wpsjs"
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
  }
@@ -1,18 +1,23 @@
1
- /* version 0.1 */
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
- switch (item.method) {
7
- case 'get': {
8
- peviousTemp = current
9
- current = Reflect.get(current, item.arguments[0])
10
- } break
11
- case 'apply': {
12
- current = Reflect.apply(current, peviousTemp, item.arguments)
13
- } break
14
- default:
15
- throw Error('reflect method undefined')
16
- }
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
+ }
17
22
  }
18
23
  return current
package/tsconfig.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
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
- }
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
  }
@@ -1,225 +1,22 @@
1
- import { MakePropertyOptional, PickModify } from './type-tools'
2
- export default interface DB_Application {
3
- Sheet: DBSheet
4
- Record: DBRecord
5
- Field: DBField
6
- View: DBView
7
- }
8
- /* 表 */
9
- interface DBSheet {
10
- GetSheets(): SheetInfo[]
11
- CreateSheet(options: Pick<SheetOptions, 'SheetId'>)
12
- DeleteSheet(options: Pick<SheetOptions, 'SheetId'>)
13
- UpdateSheet(options: Omit<SheetOptions, 'SheetId'> & Partial<SheetOptions>)
14
- }
15
- interface SheetOptions {
16
- SheetId: number
17
- Name: string
18
- Views: {
19
- name: string
20
- /**
21
- * 表格视图 看板视图 画册视图 表单视图 甘特视图
22
- */
23
- type: ViewType
24
- }[]
25
- Fields: { name: string, type: FieldType }[]
26
- }
27
- interface SheetInfo {
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
46
- }[],
47
- 'allowAddItemWhenInputting': true,
48
- 'autoAddItem': boolean,
49
- }[],
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
66
- }[]
67
- }
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'
70
- type ViewType = 'Grid' | 'Kanban' | 'Gallery' | 'Form' | 'Gantt'
71
-
72
- interface Entry {
73
- id: string,
74
- fields: Record<string, boolean | number | string | string[]>
75
- }
76
- interface Options {
77
- SheetId: number
78
- RecordId: string
79
- RecordIds: string[]
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": 小等于
1
+ import type DBSheet from './DB_Application_Sheet'
2
+ import type DBView from './DB_Application_View'
3
+ import type DBField from './DB_Application_Field'
4
+ import type DBRecord from './DB_Application_Record'
5
+ import type DBSelection from './DB_Application_Selection'
116
6
 
117
- "GreaterEquAndLessEqu": 介于(取等)
7
+ export type * from './DB_Application_Sheet'
8
+ export type * from './DB_Application_View'
9
+ export type * from './DB_Application_Field'
10
+ export type * from './DB_Application_Record'
11
+ export type * from './DB_Application_Selection'
118
12
 
119
- "LessOrGreater": 介于(不取等)
13
+ export type { DBSheet, DBView, DBField, DBRecord, DBSelection }
120
14
 
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
- }
195
- /* 字段 */
196
- interface DBField {
197
- GetFields(options: Pick<FieldOptions, 'SheetId'>)
198
- CreateFields(options: Pick<FieldOptions, 'SheetId' | 'Fields'>)
199
- DeleteFields(options: Pick<FieldOptions, 'SheetId' | 'FieldIds'>)
200
- UpdateFields(options: Pick<FieldOptions, 'SheetId' | 'Fields'> & {})
201
- }
202
- interface FieldOptions {
203
- SheetId: number
204
- Fields: Partial<Field>[]
205
- FieldIds: string[]
206
- }
207
- interface Field {
208
- id: string,
209
- name: string,
210
- type: FieldType
15
+ export default interface DB_Application {
16
+ Sheet: DBSheet
17
+ View: DBView
18
+ Field: DBField
19
+ Record: DBRecord
20
+ Selection: DBSelection
211
21
  }
212
22
 
213
- /* 视图 */
214
- interface DBView {
215
- GetViews(options: Pick<ViewOptions, 'SheetId'>)
216
- CreateView(options: Pick<ViewOptions, 'SheetId' | 'Name' | 'ViewType'>)
217
- DeleteView(options: Pick<ViewOptions, 'SheetId' | 'ViewId'>)
218
- UpdateView(options: Pick<ViewOptions, 'SheetId' | 'Name' | 'ViewId'>)
219
- }
220
- interface ViewOptions {
221
- SheetId: number
222
- ViewId: string
223
- Name: string
224
- ViewType: ViewType
225
- }