w-web-api 1.0.4 → 1.0.7
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 +11 -11
- package/dist/connecting.svg +10 -0
- package/dist/css/app.ff30ea93.css +1 -0
- package/dist/css/chunk-vendors.f0a39794.css +5 -0
- package/dist/deny.png +0 -0
- package/dist/disconnect.png +0 -0
- package/dist/index.html +1 -0
- package/dist/js/app.462646b9.js +2 -0
- package/dist/js/app.462646b9.js.map +1 -0
- package/dist/js/chunk-vendors.f69911fd.js +28 -0
- package/dist/js/chunk-vendors.f69911fd.js.map +1 -0
- package/dist/logout.png +0 -0
- package/dist/w-web-api.umd.js +2 -2
- package/dist/w-web-api.umd.js.map +1 -1
- package/docs/WWebApi.html +39 -39
- package/docs/WWebApi.mjs.html +21 -23
- package/docs/index.html +1 -1
- package/{server/getSettings.mjs → g.getSettings.mjs} +0 -0
- package/{server/mDb.mjs → g.mDb.mjs} +3 -3
- package/{server/mInitialTestData.mjs → g.mInitialTestData.mjs} +3 -3
- package/{server/mOrm.mjs → g.mOrm.mjs} +7 -5
- package/package.json +13 -19
- package/server/WWebApi.mjs +20 -22
- package/server/provideApis.mjs +70 -0
- package/srv.mjs +2 -2
- package/tableTags-web-api.json +1 -0
- package/toolg/gDistRollup.mjs +5 -3
- package/tableTags.json +0 -1
package/docs/WWebApi.html
CHANGED
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
<h4 class="name" id="WWebApi"><span class="type-signature">(async) </span>new WWebApi<span class="signature">(opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Object}</span></h4>
|
|
62
|
+
<h4 class="name" id="WWebApi"><span class="type-signature">(async) </span>new WWebApi<span class="signature">(WOrm, url, db, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Object}</span></h4>
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
|
|
72
72
|
<dt class="tag-source">Source:</dt>
|
|
73
73
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
74
|
-
<a href="WWebApi.mjs.html">WWebApi.mjs</a>, <a href="WWebApi.mjs.html#
|
|
74
|
+
<a href="WWebApi.mjs.html">WWebApi.mjs</a>, <a href="WWebApi.mjs.html#line64">line 64</a>
|
|
75
75
|
</li></ul></dd>
|
|
76
76
|
|
|
77
77
|
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
|
|
125
125
|
<h5>Example</h5>
|
|
126
126
|
|
|
127
|
-
<pre class="prettyprint"><code>import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM, 使用Mongodb測試
|
|
128
127
|
getUserById: null,
|
|
129
128
|
bCheckUser: false,
|
|
130
129
|
bExcludeWhenNotAdmin: false,
|
|
131
130
|
serverPort: 11005,
|
|
132
131
|
webName: {
|
|
133
132
|
'eng': 'API Service',
|
|
134
133
|
'cht': 'API管理系統'
|
|
135
134
|
},
|
|
136
135
|
.catch((err) => {
|
|
137
136
|
console.log(err)
|
|
138
137
|
})</code></pre>
|
|
138
|
+
<pre class="prettyprint"><code>import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM, 使用Mongodb測試
|
|
139
139
|
getUserById: null,
|
|
140
140
|
bCheckUser: false,
|
|
141
141
|
bExcludeWhenNotAdmin: false,
|
|
142
142
|
serverPort: 11005,
|
|
143
143
|
webName: {
|
|
144
144
|
'eng': 'API Service',
|
|
145
145
|
'cht': 'API管理系統'
|
|
146
146
|
},
|
|
147
147
|
.catch((err) => {
|
|
148
148
|
console.log(err)
|
|
149
149
|
})</code></pre>
|
|
150
150
|
|
|
151
151
|
|
|
152
152
|
|
|
@@ -158,13 +158,13 @@
|
|
|
158
158
|
|
|
159
159
|
<tr>
|
|
160
160
|
|
|
161
|
-
<td class="name"><code>
|
|
161
|
+
<td class="name"><code>WOrm</code></td>
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
<td class="type">
|
|
165
165
|
|
|
166
166
|
|
|
167
|
-
<span class="param-type">
|
|
167
|
+
<span class="param-type">function</span>
|
|
168
168
|
|
|
169
169
|
|
|
170
170
|
|
|
@@ -173,8 +173,6 @@
|
|
|
173
173
|
|
|
174
174
|
<td class="attributes">
|
|
175
175
|
|
|
176
|
-
<optional><br>
|
|
177
|
-
|
|
178
176
|
|
|
179
177
|
|
|
180
178
|
|
|
@@ -185,37 +183,12 @@
|
|
|
185
183
|
|
|
186
184
|
<td class="default">
|
|
187
185
|
|
|
188
|
-
<code>{}</code>
|
|
189
|
-
|
|
190
186
|
</td>
|
|
191
187
|
|
|
192
188
|
|
|
193
|
-
<td class="description last"><p
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
<table class="params">
|
|
198
|
-
<thead>
|
|
199
|
-
<tr>
|
|
200
|
-
|
|
201
|
-
<th>Name</th>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<th>Type</th>
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
<th>Attributes</th>
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
<th>Default</th>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
<th class="last">Description</th>
|
|
215
|
-
</tr>
|
|
216
|
-
</thead>
|
|
189
|
+
<td class="description last"><p>輸入資料庫ORM函數</p></td>
|
|
190
|
+
</tr>
|
|
217
191
|
|
|
218
|
-
<tbody>
|
|
219
192
|
|
|
220
193
|
|
|
221
194
|
<tr>
|
|
@@ -290,13 +263,13 @@
|
|
|
290
263
|
|
|
291
264
|
<tr>
|
|
292
265
|
|
|
293
|
-
<td class="name"><code>
|
|
266
|
+
<td class="name"><code>opt</code></td>
|
|
294
267
|
|
|
295
268
|
|
|
296
269
|
<td class="type">
|
|
297
270
|
|
|
298
271
|
|
|
299
|
-
<span class="param-type">
|
|
272
|
+
<span class="param-type">Object</span>
|
|
300
273
|
|
|
301
274
|
|
|
302
275
|
|
|
@@ -305,6 +278,8 @@
|
|
|
305
278
|
|
|
306
279
|
<td class="attributes">
|
|
307
280
|
|
|
281
|
+
<optional><br>
|
|
282
|
+
|
|
308
283
|
|
|
309
284
|
|
|
310
285
|
|
|
@@ -315,12 +290,37 @@
|
|
|
315
290
|
|
|
316
291
|
<td class="default">
|
|
317
292
|
|
|
293
|
+
<code>{}</code>
|
|
294
|
+
|
|
318
295
|
</td>
|
|
319
296
|
|
|
320
297
|
|
|
321
|
-
<td class="description last"><p
|
|
322
|
-
|
|
298
|
+
<td class="description last"><p>輸入設定物件,預設{}</p>
|
|
299
|
+
<h6>Properties</h6>
|
|
300
|
+
|
|
323
301
|
|
|
302
|
+
<table class="params">
|
|
303
|
+
<thead>
|
|
304
|
+
<tr>
|
|
305
|
+
|
|
306
|
+
<th>Name</th>
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
<th>Type</th>
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
<th>Attributes</th>
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
<th>Default</th>
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
<th class="last">Description</th>
|
|
320
|
+
</tr>
|
|
321
|
+
</thead>
|
|
322
|
+
|
|
323
|
+
<tbody>
|
|
324
324
|
|
|
325
325
|
|
|
326
326
|
<tr>
|
|
@@ -604,7 +604,7 @@
|
|
|
604
604
|
<br class="clear">
|
|
605
605
|
|
|
606
606
|
<footer>
|
|
607
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022
|
|
607
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022 16:47:26 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
608
608
|
</footer>
|
|
609
609
|
|
|
610
610
|
<script>prettyPrint();</script>
|
package/docs/WWebApi.mjs.html
CHANGED
|
@@ -62,10 +62,10 @@ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
|
62
62
|
* 基於hapi之API伺服器
|
|
63
63
|
*
|
|
64
64
|
* @class
|
|
65
|
+
* @param {Function} WOrm 輸入資料庫ORM函數
|
|
66
|
+
* @param {String} url 輸入資料庫連線字串,例如'mongodb://sername:password@$127.0.0.1:27017'
|
|
67
|
+
* @param {String} db 輸入資料庫名稱字串
|
|
65
68
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
66
|
-
* @param {String} opt.url 輸入資料庫連線字串,例如'mongodb://sername:password@$127.0.0.1:27017'
|
|
67
|
-
* @param {String} opt.db 輸入資料庫名稱字串
|
|
68
|
-
* @param {Function} opt.WOrm 輸入資料庫ORM函數
|
|
69
69
|
* @param {Integer} [opt.serverPort=11005] 輸入伺服器通訊port,預設11005
|
|
70
70
|
* @param {Function} [opt.getUserById=null] 輸入當bCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
|
|
71
71
|
* @param {Boolean} [opt.bCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
|
|
@@ -78,7 +78,6 @@ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
|
78
78
|
* import getSettings from './server/getSettings.mjs'
|
|
79
79
|
* import WWebApi from './server/WWebApi.mjs'
|
|
80
80
|
*
|
|
81
|
-
*
|
|
82
81
|
* //st
|
|
83
82
|
* let st = getSettings()
|
|
84
83
|
*
|
|
@@ -100,14 +99,20 @@ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
|
100
99
|
* }
|
|
101
100
|
*
|
|
102
101
|
* //WWebApi
|
|
103
|
-
* WWebApi(url, db,
|
|
102
|
+
* WWebApi(WOrm, url, db, opt)
|
|
104
103
|
* .catch((err) => {
|
|
105
104
|
* console.log(err)
|
|
106
105
|
* })
|
|
107
106
|
*
|
|
108
|
-
*
|
|
109
107
|
*/
|
|
110
|
-
async function WWebApi(url, db,
|
|
108
|
+
async function WWebApi(WOrm, url, db, opt = {}) {
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
//check WOrm
|
|
112
|
+
if (!isfun(WOrm)) {
|
|
113
|
+
console.log('invalid WOrm', WOrm)
|
|
114
|
+
throw new Error('invalid WOrm')
|
|
115
|
+
}
|
|
111
116
|
|
|
112
117
|
|
|
113
118
|
//check url
|
|
@@ -124,13 +129,6 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
|
|
127
|
-
//check WOrm
|
|
128
|
-
if (!isfun(WOrm)) {
|
|
129
|
-
console.log('invalid WOrm', WOrm)
|
|
130
|
-
throw new Error('invalid WOrm')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
132
|
//serverPort
|
|
135
133
|
let serverPort = get(opt, 'serverPort')
|
|
136
134
|
if (!ispint(serverPort)) {
|
|
@@ -139,14 +137,14 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
139
137
|
serverPort = cint(serverPort)
|
|
140
138
|
|
|
141
139
|
|
|
142
|
-
//getUserById
|
|
143
|
-
let getUserById = get(opt, 'getUserById', null)
|
|
144
|
-
|
|
145
|
-
|
|
146
140
|
//bCheckUser
|
|
147
141
|
let bCheckUser = get(opt, 'bCheckUser', false)
|
|
148
142
|
|
|
149
143
|
|
|
144
|
+
//getUserById
|
|
145
|
+
let getUserById = get(opt, 'getUserById', null)
|
|
146
|
+
|
|
147
|
+
|
|
150
148
|
//bExcludeWhenNotAdmin
|
|
151
149
|
let bExcludeWhenNotAdmin = get(opt, 'bExcludeWhenNotAdmin', false)
|
|
152
150
|
|
|
@@ -157,15 +155,13 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
157
155
|
|
|
158
156
|
//WServOrm
|
|
159
157
|
let optWServOrm = {
|
|
160
|
-
url,
|
|
161
|
-
db,
|
|
162
|
-
getUserById,
|
|
163
158
|
bCheckUser,
|
|
159
|
+
getUserById,
|
|
164
160
|
bExcludeWhenNotAdmin,
|
|
165
161
|
}
|
|
166
162
|
let wp = {}
|
|
167
163
|
try {
|
|
168
|
-
wp = WServOrm(ds, WOrm, optWServOrm)
|
|
164
|
+
wp = WServOrm(ds, WOrm, url, db, optWServOrm)
|
|
169
165
|
}
|
|
170
166
|
catch (err) {
|
|
171
167
|
console.log(err)
|
|
@@ -247,6 +243,7 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
247
243
|
if (fsIsFolder(npmPathStaticFiles)) {
|
|
248
244
|
pathStaticFiles = npmPathStaticFiles
|
|
249
245
|
}
|
|
246
|
+
// console.log('pathStaticFiles', pathStaticFiles)
|
|
250
247
|
|
|
251
248
|
|
|
252
249
|
//apis
|
|
@@ -347,6 +344,7 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
347
344
|
},
|
|
348
345
|
hookBefores: null,
|
|
349
346
|
hookAfters: null,
|
|
347
|
+
fnTableTags: 'tableTags-web-api.json',
|
|
350
348
|
})
|
|
351
349
|
|
|
352
350
|
|
|
@@ -369,7 +367,7 @@ export default WWebApi
|
|
|
369
367
|
<br class="clear">
|
|
370
368
|
|
|
371
369
|
<footer>
|
|
372
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022
|
|
370
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022 16:47:26 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
373
371
|
</footer>
|
|
374
372
|
|
|
375
373
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
<br class="clear">
|
|
69
69
|
|
|
70
70
|
<footer>
|
|
71
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022
|
|
71
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022 16:47:26 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
72
72
|
</footer>
|
|
73
73
|
|
|
74
74
|
<script>prettyPrint();</script>
|
|
File without changes
|
|
@@ -3,8 +3,8 @@ import fs from 'fs'
|
|
|
3
3
|
// import _ from 'lodash'
|
|
4
4
|
import w from 'wsemi'
|
|
5
5
|
import br from 'w-serv-orm/src/getDbBackupAndRecover.mjs'
|
|
6
|
-
import { woItems } from './mOrm.mjs'
|
|
7
|
-
// import { genModels } from './mOrmGenModels.mjs'
|
|
6
|
+
import { woItems } from './g.mOrm.mjs'
|
|
7
|
+
// import { genModels } from './g.mOrmGenModels.mjs'
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
//mOrmGenModels.mjs
|
|
@@ -73,4 +73,4 @@ function recover() {
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
//備份資料重與由備份資料重建資料庫
|
|
76
|
-
//node --experimental-modules --es-module-specifier-resolution=node
|
|
76
|
+
//node --experimental-modules --es-module-specifier-resolution=node g.mDb.mjs
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// import fs from 'fs'
|
|
3
3
|
// import _ from 'lodash'
|
|
4
4
|
import w from 'wsemi'
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import ds from './src/schema/index.mjs'
|
|
6
|
+
import { woItems } from './g.mOrm.mjs'
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
async function initialTestData() {
|
|
@@ -37,4 +37,4 @@ initialTestData()
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
//刪除舊檔與重建測試資料庫
|
|
40
|
-
//node --experimental-modules --es-module-specifier-resolution=node
|
|
40
|
+
//node --experimental-modules --es-module-specifier-resolution=node g.mInitialTestData.mjs
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs'
|
|
2
|
-
import ds from '../src/schema/index.mjs'
|
|
3
|
-
import getSettings from './getSettings.mjs'
|
|
4
2
|
import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
3
|
+
import ds from './src/schema/index.mjs'
|
|
4
|
+
import getSettings from './g.getSettings.mjs'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
//getSettings
|
|
8
8
|
let st = getSettings()
|
|
9
9
|
|
|
10
|
+
//url, db
|
|
11
|
+
let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
|
|
12
|
+
let db = st.dbName
|
|
13
|
+
|
|
10
14
|
//WServOrm
|
|
11
15
|
let opt = {
|
|
12
|
-
url: `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`,
|
|
13
|
-
db: st.dbName,
|
|
14
16
|
getUserById: null,
|
|
15
17
|
bCheckUser: false,
|
|
16
18
|
bExcludeWhenNotAdmin: false,
|
|
17
19
|
}
|
|
18
|
-
let r = WServOrm(ds, WOrm, opt)
|
|
20
|
+
let r = WServOrm(ds, WOrm, url, db, opt)
|
|
19
21
|
let { woItems, procOrm } = r
|
|
20
22
|
|
|
21
23
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-web-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"main": "dist/w-web-api.umd.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@mdi/js": "^6.6.96",
|
|
7
|
+
"axios": "^0.26.1",
|
|
7
8
|
"lodash": "^4.17.21",
|
|
8
9
|
"showdown": "^2.0.3",
|
|
9
10
|
"w-component-vue": "^2.2.6",
|
|
10
11
|
"w-data-collector": "^1.0.13",
|
|
11
|
-
"w-
|
|
12
|
-
"w-serv-
|
|
13
|
-
"w-serv-orm": "^1.0.0",
|
|
12
|
+
"w-serv-hapi": "^1.0.6",
|
|
13
|
+
"w-serv-orm": "^1.0.1",
|
|
14
14
|
"wsemi": "^1.6.55"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@vue/cli-plugin-babel": "^4.5.13",
|
|
18
|
+
"@vue/cli-plugin-eslint": "^4.5.13",
|
|
19
|
+
"@vue/cli-service": "^4.5.13",
|
|
20
|
+
"cheerio": "^1.0.0-rc.10",
|
|
17
21
|
"eslint": "^7.26.0",
|
|
18
22
|
"eslint-config-standard": "^16.0.2",
|
|
19
23
|
"eslint-friendly-formatter": "^4.0.1",
|
|
@@ -23,17 +27,14 @@
|
|
|
23
27
|
"eslint-plugin-promise": "^5.1.0",
|
|
24
28
|
"eslint-plugin-standard": "^4.1.0",
|
|
25
29
|
"eslint-plugin-vue": "^7.9.0",
|
|
26
|
-
"@vue/cli-plugin-babel": "^4.5.13",
|
|
27
|
-
"@vue/cli-plugin-eslint": "^4.5.13",
|
|
28
|
-
"@vue/cli-service": "^4.5.13",
|
|
29
|
-
"cheerio": "^1.0.0-rc.10",
|
|
30
30
|
"sass": "^1.34.0",
|
|
31
31
|
"sass-loader": "^10.1.1",
|
|
32
32
|
"vue": "^2.6.14",
|
|
33
|
-
"vuex": "^3.6.2",
|
|
34
33
|
"vue-cli-plugin-vuetify": "^2.4.8",
|
|
35
34
|
"vuetify": "^2.6.4",
|
|
36
35
|
"vuetify-loader": "^1.7.3",
|
|
36
|
+
"vuex": "^3.6.2",
|
|
37
|
+
"w-orm-mongodb": "^1.1.26",
|
|
37
38
|
"w-package-tools": "^1.0.65"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
@@ -66,16 +67,9 @@
|
|
|
66
67
|
"url": "https://github.com/yuda-lyu/w-web-api"
|
|
67
68
|
},
|
|
68
69
|
"keywords": [
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"fuzzy",
|
|
73
|
-
"xss",
|
|
74
|
-
"xlsx",
|
|
75
|
-
"tool",
|
|
76
|
-
"package ",
|
|
77
|
-
"browser",
|
|
78
|
-
"developer"
|
|
70
|
+
"web",
|
|
71
|
+
"service",
|
|
72
|
+
"api"
|
|
79
73
|
],
|
|
80
74
|
"author": "yuda-lyu(semisphere)",
|
|
81
75
|
"license": "MIT"
|
package/server/WWebApi.mjs
CHANGED
|
@@ -18,10 +18,10 @@ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
|
18
18
|
* 基於hapi之API伺服器
|
|
19
19
|
*
|
|
20
20
|
* @class
|
|
21
|
+
* @param {Function} WOrm 輸入資料庫ORM函數
|
|
22
|
+
* @param {String} url 輸入資料庫連線字串,例如'mongodb://sername:password@$127.0.0.1:27017'
|
|
23
|
+
* @param {String} db 輸入資料庫名稱字串
|
|
21
24
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
22
|
-
* @param {String} opt.url 輸入資料庫連線字串,例如'mongodb://sername:password@$127.0.0.1:27017'
|
|
23
|
-
* @param {String} opt.db 輸入資料庫名稱字串
|
|
24
|
-
* @param {Function} opt.WOrm 輸入資料庫ORM函數
|
|
25
25
|
* @param {Integer} [opt.serverPort=11005] 輸入伺服器通訊port,預設11005
|
|
26
26
|
* @param {Function} [opt.getUserById=null] 輸入當bCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
|
|
27
27
|
* @param {Boolean} [opt.bCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
|
|
@@ -34,7 +34,6 @@ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
|
34
34
|
* import getSettings from './server/getSettings.mjs'
|
|
35
35
|
* import WWebApi from './server/WWebApi.mjs'
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
37
|
* //st
|
|
39
38
|
* let st = getSettings()
|
|
40
39
|
*
|
|
@@ -56,14 +55,20 @@ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
|
56
55
|
* }
|
|
57
56
|
*
|
|
58
57
|
* //WWebApi
|
|
59
|
-
* WWebApi(url, db,
|
|
58
|
+
* WWebApi(WOrm, url, db, opt)
|
|
60
59
|
* .catch((err) => {
|
|
61
60
|
* console.log(err)
|
|
62
61
|
* })
|
|
63
62
|
*
|
|
64
|
-
*
|
|
65
63
|
*/
|
|
66
|
-
async function WWebApi(url, db,
|
|
64
|
+
async function WWebApi(WOrm, url, db, opt = {}) {
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
//check WOrm
|
|
68
|
+
if (!isfun(WOrm)) {
|
|
69
|
+
console.log('invalid WOrm', WOrm)
|
|
70
|
+
throw new Error('invalid WOrm')
|
|
71
|
+
}
|
|
67
72
|
|
|
68
73
|
|
|
69
74
|
//check url
|
|
@@ -80,13 +85,6 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
|
|
83
|
-
//check WOrm
|
|
84
|
-
if (!isfun(WOrm)) {
|
|
85
|
-
console.log('invalid WOrm', WOrm)
|
|
86
|
-
throw new Error('invalid WOrm')
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
88
|
//serverPort
|
|
91
89
|
let serverPort = get(opt, 'serverPort')
|
|
92
90
|
if (!ispint(serverPort)) {
|
|
@@ -95,14 +93,14 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
95
93
|
serverPort = cint(serverPort)
|
|
96
94
|
|
|
97
95
|
|
|
98
|
-
//getUserById
|
|
99
|
-
let getUserById = get(opt, 'getUserById', null)
|
|
100
|
-
|
|
101
|
-
|
|
102
96
|
//bCheckUser
|
|
103
97
|
let bCheckUser = get(opt, 'bCheckUser', false)
|
|
104
98
|
|
|
105
99
|
|
|
100
|
+
//getUserById
|
|
101
|
+
let getUserById = get(opt, 'getUserById', null)
|
|
102
|
+
|
|
103
|
+
|
|
106
104
|
//bExcludeWhenNotAdmin
|
|
107
105
|
let bExcludeWhenNotAdmin = get(opt, 'bExcludeWhenNotAdmin', false)
|
|
108
106
|
|
|
@@ -113,15 +111,13 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
113
111
|
|
|
114
112
|
//WServOrm
|
|
115
113
|
let optWServOrm = {
|
|
116
|
-
url,
|
|
117
|
-
db,
|
|
118
|
-
getUserById,
|
|
119
114
|
bCheckUser,
|
|
115
|
+
getUserById,
|
|
120
116
|
bExcludeWhenNotAdmin,
|
|
121
117
|
}
|
|
122
118
|
let wp = {}
|
|
123
119
|
try {
|
|
124
|
-
wp = WServOrm(ds, WOrm, optWServOrm)
|
|
120
|
+
wp = WServOrm(ds, WOrm, url, db, optWServOrm)
|
|
125
121
|
}
|
|
126
122
|
catch (err) {
|
|
127
123
|
console.log(err)
|
|
@@ -203,6 +199,7 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
203
199
|
if (fsIsFolder(npmPathStaticFiles)) {
|
|
204
200
|
pathStaticFiles = npmPathStaticFiles
|
|
205
201
|
}
|
|
202
|
+
// console.log('pathStaticFiles', pathStaticFiles)
|
|
206
203
|
|
|
207
204
|
|
|
208
205
|
//apis
|
|
@@ -303,6 +300,7 @@ async function WWebApi(url, db, WOrm, opt = {}) {
|
|
|
303
300
|
},
|
|
304
301
|
hookBefores: null,
|
|
305
302
|
hookAfters: null,
|
|
303
|
+
fnTableTags: 'tableTags-web-api.json',
|
|
306
304
|
})
|
|
307
305
|
|
|
308
306
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import map from 'lodash/map'
|
|
3
|
+
import ltdtpick from 'wsemi/src/ltdtpick.mjs'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async function provideApis(url, levels, apis) {
|
|
7
|
+
//url: 指API伺服器提供的接入網址, 例如 http://localhost:11005/replaceAPIsByLevels
|
|
8
|
+
|
|
9
|
+
//ks
|
|
10
|
+
let ks = [
|
|
11
|
+
'id', //'id-for-apis-pets-guineapigs-1'
|
|
12
|
+
'name', //'取得天竺鼠清單資訊'
|
|
13
|
+
'description', //'取得天竺鼠清單資訊'
|
|
14
|
+
'url', //指api網址, 例如 http://localhost:11005/getDogsList
|
|
15
|
+
'method', //'get'
|
|
16
|
+
'version', //'v1'
|
|
17
|
+
'levels', //'寵物.天竺鼠'
|
|
18
|
+
'keywords', //'pets;guineapigs'
|
|
19
|
+
'state', //'ok'
|
|
20
|
+
'creator', //'pets-system'
|
|
21
|
+
'dataSource', //'pets-data'
|
|
22
|
+
'mdInputParams', //輸入方式說明, markdown格式
|
|
23
|
+
'outputExample', //輸出範例數據, json格式
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
//ltdtpick
|
|
27
|
+
apis = ltdtpick(apis, ks)
|
|
28
|
+
|
|
29
|
+
//update levels
|
|
30
|
+
apis = map(apis, (v) => {
|
|
31
|
+
v.levels = levels
|
|
32
|
+
return v
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
//rin
|
|
36
|
+
let rin = {
|
|
37
|
+
levels,
|
|
38
|
+
apis,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//axios
|
|
42
|
+
let rout
|
|
43
|
+
await axios({
|
|
44
|
+
method: 'post',
|
|
45
|
+
url,
|
|
46
|
+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
47
|
+
data: rin,
|
|
48
|
+
})
|
|
49
|
+
.then((res) => {
|
|
50
|
+
// console.log(res)
|
|
51
|
+
rout = {
|
|
52
|
+
state: 'success',
|
|
53
|
+
msg: '成功傳輸API清單',
|
|
54
|
+
res,
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
// console.log(err)
|
|
59
|
+
rout = {
|
|
60
|
+
state: 'success',
|
|
61
|
+
msg: '無法傳輸API清單',
|
|
62
|
+
res: err,
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
return rout
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export default provideApis
|
package/srv.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM, 使用Mongodb測試
|
|
2
|
-
import getSettings from './server/getSettings.mjs'
|
|
3
2
|
import WWebApi from './server/WWebApi.mjs'
|
|
3
|
+
import getSettings from './g.getSettings.mjs'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
//st
|
|
@@ -24,7 +24,7 @@ let opt = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
//WWebApi
|
|
27
|
-
WWebApi(url, db,
|
|
27
|
+
WWebApi(WOrm, url, db, opt)
|
|
28
28
|
.catch((err) => {
|
|
29
29
|
console.log(err)
|
|
30
30
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"apis":"dJSgfx"}
|
package/toolg/gDistRollup.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import rollupFiles from 'w-package-tools/src/rollupFiles.mjs'
|
|
1
|
+
// import rollupFiles from 'w-package-tools/src/rollupFiles.mjs'
|
|
2
|
+
import rollupFile from 'w-package-tools/src/rollupFile.mjs' //因只有1檔案且不需刪除dsit故改用rollupFile
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
let fdSrc = './server' //'./src'
|
|
5
6
|
let fdTar = './dist'
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
fns: ['WWebApi.mjs'],
|
|
9
|
+
rollupFile({
|
|
10
|
+
// fns: ['WWebApi.mjs'],
|
|
11
|
+
fn: 'WWebApi.mjs',
|
|
10
12
|
fdSrc,
|
|
11
13
|
fdTar,
|
|
12
14
|
nameDistType: 'kebabCase',
|
package/tableTags.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"apis":"gertCD"}
|