tadcode-wpsjs 0.3.0 → 0.3.2

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/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import{writeFile as G}from"fs/promises";import $ 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,Q,S)=>{return z.push({method:"get",arguments:[Q]}),S},set:(K,Q,S,Z)=>{return z.push({method:"set",arguments:[Q,S]}),Z},apply:(K,Q,S)=>{if(z.at(-1)?.arguments[0]==="execution")return z.pop(),W({scriptToken:E,webhookURL:M,isAsync:H,argv:{info:z}}).then(async(q)=>{let Y=await q.json();if(z=[],N)D(Y);if(J)await P(Y);return Y.data.result});return z.push({method:"apply",arguments:S}),Q}})},W=({scriptToken:B,webhookURL:E,isAsync:M,argv:H})=>{let N=JSON.stringify({Context:{argv:H}}),J=$.parse(E);J.base=M?"task":"sync_task";let z=$.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)},D=(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 X=H.logs.filter((K)=>K.filename!=="<system>");if(X.length!==0){console.log("log:");for(let K of X)console[K.level](...K.args)}return console.log("result:"),console.log(H.result),E},P=(B)=>{return G("./wpsjs.log.json",JSON.stringify(B,void 0,2))};export{P as writeLogFileToCurrent,U as queryTask,O as initRemoteCallWpsjsGlobal,W as execution};
package/index.ts CHANGED
@@ -1,110 +1,110 @@
1
- import type { InfoItem, RemoteCallWpsjsGlobalReturn, WithExecutionWpsjsGlobal } 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
-
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
-
76
- const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
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,
110
- }
1
+ import type { InfoItem, RemoteCallWpsjsGlobalReturn, WithExecutionWpsjsGlobal } 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
+
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
+
76
+ const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
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,
110
+ }
package/package.json CHANGED
@@ -1,17 +1,29 @@
1
1
  {
2
2
  "name": "tadcode-wpsjs",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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 --minify --outfile index.js"
9
+ "build": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/bun": "latest"
13
13
  },
14
14
  "keywords": [
15
15
  "tadcode-wpsjs"
16
- ]
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
+ }
17
29
  }
@@ -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: Omit<RecordItem, 'id'>[] }): RecordItem[]
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[]
@@ -52,9 +52,9 @@ export default interface KSDrive {
52
52
  }
53
53
 
54
54
  listFiles(options?: {
55
- dirUrl: string
56
- offset: number
57
- count: number
58
- includeExts: string[]
59
- })
55
+ dirUrl?: string
56
+ offset?: number
57
+ count?: number
58
+ includeExts?: string[]
59
+ }): FilesInfo
60
60
  }