w-web-api 1.0.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.
Files changed (78) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +54 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +62 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +14 -0
  9. package/dist/w-web-api.umd.js +7 -0
  10. package/dist/w-web-api.umd.js.map +1 -0
  11. package/docs/WWebApi.html +551 -0
  12. package/docs/WWebApi.mjs.html +335 -0
  13. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  14. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  15. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  16. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  31. package/docs/index.html +81 -0
  32. package/docs/scripts/collapse.js +20 -0
  33. package/docs/scripts/linenumber.js +25 -0
  34. package/docs/scripts/nav.js +12 -0
  35. package/docs/scripts/polyfill.js +4 -0
  36. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  37. package/docs/scripts/prettify/lang-css.js +2 -0
  38. package/docs/scripts/prettify/prettify.js +28 -0
  39. package/docs/scripts/search.js +83 -0
  40. package/docs/styles/jsdoc.css +765 -0
  41. package/docs/styles/prettify.css +79 -0
  42. package/package.json +81 -0
  43. package/public/connecting.svg +10 -0
  44. package/public/deny.png +0 -0
  45. package/public/disconnect.png +0 -0
  46. package/public/index.html +23 -0
  47. package/public/logout.png +0 -0
  48. package/server/WWebApi.mjs +283 -0
  49. package/server/getSettings.mjs +17 -0
  50. package/server/mDb.mjs +76 -0
  51. package/server/mInitialTestData.mjs +40 -0
  52. package/server/mOrm.mjs +22 -0
  53. package/src/App.vue +91 -0
  54. package/src/components/Layout.vue +131 -0
  55. package/src/components/LayoutContent.vue +67 -0
  56. package/src/components/LayoutContentList.vue +573 -0
  57. package/src/components/MdPanel.vue +152 -0
  58. package/src/main.js +98 -0
  59. package/src/plugins/mDataSelectorSchema.mjs +30 -0
  60. package/src/plugins/mDataSupport.mjs +78 -0
  61. package/src/plugins/mShare.mjs +235 -0
  62. package/src/plugins/mUI.mjs +141 -0
  63. package/src/plugins/mVuetify.mjs +12 -0
  64. package/src/schema/gi.mjs +8 -0
  65. package/src/schema/index.mjs +16 -0
  66. package/src/schema/tables/apis.mjs +918 -0
  67. package/src/store/actions.mjs +1 -0
  68. package/src/store/getters.mjs +1 -0
  69. package/src/store/index.mjs +25 -0
  70. package/src/store/mutations.mjs +185 -0
  71. package/src/store/types.mjs +14 -0
  72. package/srv.mjs +33 -0
  73. package/tableTags.json +1 -0
  74. package/toolg/addVersion.mjs +4 -0
  75. package/toolg/cleanFolder.mjs +4 -0
  76. package/toolg/gDistRollup.mjs +34 -0
  77. package/toolg/modifyReadme.mjs +4 -0
  78. package/vue.config.js +15 -0
@@ -0,0 +1,79 @@
1
+ .pln {
2
+ color: #ddd;
3
+ }
4
+
5
+ /* string content */
6
+ .str {
7
+ color: #61ce3c;
8
+ }
9
+
10
+ /* a keyword */
11
+ .kwd {
12
+ color: #fbde2d;
13
+ }
14
+
15
+ /* a comment */
16
+ .com {
17
+ color: #aeaeae;
18
+ }
19
+
20
+ /* a type name */
21
+ .typ {
22
+ color: #8da6ce;
23
+ }
24
+
25
+ /* a literal value */
26
+ .lit {
27
+ color: #fbde2d;
28
+ }
29
+
30
+ /* punctuation */
31
+ .pun {
32
+ color: #ddd;
33
+ }
34
+
35
+ /* lisp open bracket */
36
+ .opn {
37
+ color: #000000;
38
+ }
39
+
40
+ /* lisp close bracket */
41
+ .clo {
42
+ color: #000000;
43
+ }
44
+
45
+ /* a markup tag name */
46
+ .tag {
47
+ color: #8da6ce;
48
+ }
49
+
50
+ /* a markup attribute name */
51
+ .atn {
52
+ color: #fbde2d;
53
+ }
54
+
55
+ /* a markup attribute value */
56
+ .atv {
57
+ color: #ddd;
58
+ }
59
+
60
+ /* a declaration */
61
+ .dec {
62
+ color: #EF5050;
63
+ }
64
+
65
+ /* a variable name */
66
+ .var {
67
+ color: #c82829;
68
+ }
69
+
70
+ /* a function name */
71
+ .fun {
72
+ color: #4271ae;
73
+ }
74
+
75
+ /* Specify class=linenums on a pre to get line numbering */
76
+ ol.linenums {
77
+ margin-top: 0;
78
+ margin-bottom: 0;
79
+ }
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "w-web-api",
3
+ "version": "1.0.0",
4
+ "main": "dist/w-web-api.umd.js",
5
+ "dependencies": {
6
+ "@mdi/js": "^6.6.96",
7
+ "lodash": "^4.17.21",
8
+ "showdown": "^2.0.3",
9
+ "w-component-vue": "^2.2.6",
10
+ "w-data-collector": "^1.0.13",
11
+ "w-orm-mongodb": "^1.1.26",
12
+ "w-serv-hapi": "^1.0.5",
13
+ "w-serv-orm": "^1.0.0",
14
+ "wsemi": "^1.6.55"
15
+ },
16
+ "devDependencies": {
17
+ "eslint": "^7.26.0",
18
+ "eslint-config-standard": "^16.0.2",
19
+ "eslint-friendly-formatter": "^4.0.1",
20
+ "eslint-loader": "^4.0.2",
21
+ "eslint-plugin-import": "^2.22.1",
22
+ "eslint-plugin-node": "^11.1.0",
23
+ "eslint-plugin-promise": "^5.1.0",
24
+ "eslint-plugin-standard": "^4.1.0",
25
+ "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
+ "sass": "^1.34.0",
31
+ "sass-loader": "^10.1.1",
32
+ "vue": "^2.6.14",
33
+ "vuex": "^3.6.2",
34
+ "vue-cli-plugin-vuetify": "^2.4.8",
35
+ "vuetify": "^2.6.4",
36
+ "vuetify-loader": "^1.7.3",
37
+ "w-package-tools": "^1.0.65"
38
+ },
39
+ "scripts": {
40
+ "serve": "vue-cli-service serve",
41
+ "build": "vue-cli-service build",
42
+ "lint": "vue-cli-service lint",
43
+ "start": "node --experimental-modules --es-module-specifier-resolution=node server/srv.mjs"
44
+ },
45
+ "eslintConfig": {
46
+ "root": true,
47
+ "env": {
48
+ "node": true
49
+ },
50
+ "extends": [
51
+ "plugin:vue/essential",
52
+ "eslint:recommended"
53
+ ],
54
+ "rules": {},
55
+ "parserOptions": {
56
+ "parser": "babel-eslint"
57
+ }
58
+ },
59
+ "browserslist": [
60
+ "> 1%",
61
+ "last 2 versions"
62
+ ],
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "https://github.com/yuda-lyu/w-web-api"
66
+ },
67
+ "keywords": [
68
+ "lodash",
69
+ "color",
70
+ "crypto",
71
+ "fuzzy",
72
+ "xss",
73
+ "xlsx",
74
+ "tool",
75
+ "package ",
76
+ "browser",
77
+ "developer"
78
+ ],
79
+ "author": "yuda-lyu(semisphere)",
80
+ "license": "MIT"
81
+ }
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100px" height="100px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
2
+ <circle cx="50" cy="50" r="13.8193" fill="none" stroke="#5f2a62" stroke-width="2">
3
+ <animate attributeName="r" repeatCount="indefinite" dur="1.2658227848101264s" values="0;44" keyTimes="0;1" keySplines="0 0.2 0.8 1" calcMode="spline" begin="-0.6329113924050632s"></animate>
4
+ <animate attributeName="opacity" repeatCount="indefinite" dur="1.2658227848101264s" values="1;0" keyTimes="0;1" keySplines="0.2 0 0.8 1" calcMode="spline" begin="-0.6329113924050632s"></animate>
5
+ </circle>
6
+ <circle cx="50" cy="50" r="35.8165" fill="none" stroke="#a976c3" stroke-width="2">
7
+ <animate attributeName="r" repeatCount="indefinite" dur="1.2658227848101264s" values="0;44" keyTimes="0;1" keySplines="0 0.2 0.8 1" calcMode="spline"></animate>
8
+ <animate attributeName="opacity" repeatCount="indefinite" dur="1.2658227848101264s" values="1;0" keyTimes="0;1" keySplines="0.2 0 0.8 1" calcMode="spline"></animate>
9
+ </circle>
10
+ </svg>
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-tw">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
6
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
+ <title></title>
8
+
9
+ <!-- mdi font -->
10
+ <link href="https://cdn.jsdelivr.net/npm/@mdi/font/css/materialdesignicons.min.css" rel="stylesheet">
11
+
12
+ <!-- fontawesome -->
13
+ <link href="https://pro.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet">
14
+
15
+ </head>
16
+ <body style="font-family:'Microsoft JhengHei','Avenir','Helvetica', 'Arial', 'sans-serif'; padding:0px; margin:0px;">
17
+ <noscript>
18
+ <strong>We're sorry but w-component-vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
19
+ </noscript>
20
+ <div id="app"></div>
21
+ <!-- built files will be auto injected -->
22
+ </body>
23
+ </html>
Binary file
@@ -0,0 +1,283 @@
1
+ import get from 'lodash/get'
2
+ import map from 'lodash/map'
3
+ import keys from 'lodash/keys'
4
+ import cloneDeep from 'lodash/cloneDeep'
5
+ import j2o from 'wsemi/src/j2o.mjs'
6
+ import iseobj from 'wsemi/src/iseobj'
7
+ import isestr from 'wsemi/src/isestr'
8
+ import ispint from 'wsemi/src/ispint'
9
+ import isfun from 'wsemi/src/isfun'
10
+ import fsIsFolder from 'wsemi/src/fsIsFolder'
11
+ import cint from 'wsemi/src/cint'
12
+ import WServHapiServer from 'w-serv-hapi/src/WServHapiServer.mjs'
13
+ import ds from '../src/schema/index.mjs'
14
+ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
15
+
16
+
17
+ /**
18
+ * 基於hapi之API伺服器
19
+ *
20
+ * @class
21
+ * @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
+ * @param {Integer} [opt.serverPort=11005] 輸入伺服器通訊port,預設11005
26
+ * @param {Function} [opt.getUserById=null] 輸入當bCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
27
+ * @param {Boolean} [opt.bCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
28
+ * @param {Boolean} [opt.bExcludeWhenNotAdmin=true] 輸入使用ORM的select方法時是否自動刪除數據內isActive欄位之布林值,預設true
29
+ * @param {Object} [opt.webName={}] 輸入站台名稱物件,至少包含語系eng與cht鍵的名稱,預設{}
30
+ * @returns {Object} 回傳物件,其內server為hapi伺服器實體,wsrv為w-converhp的伺服器事件物件,wsds為w-serv-webdata的伺服器事件物件,可監聽error事件
31
+ * @example
32
+ *
33
+
34
+ *
35
+ */
36
+ async function WWebApi(url, db, WOrm, opt = {}) {
37
+
38
+
39
+ //check url
40
+ if (!isestr(url)) {
41
+ console.log('invalid url', url)
42
+ throw new Error('invalid url')
43
+ }
44
+
45
+
46
+ //check db
47
+ if (!isestr(db)) {
48
+ console.log('invalid db', db)
49
+ throw new Error('invalid db')
50
+ }
51
+
52
+
53
+ //check WOrm
54
+ if (!isfun(WOrm)) {
55
+ console.log('invalid WOrm', WOrm)
56
+ throw new Error('invalid WOrm')
57
+ }
58
+
59
+
60
+ //serverPort
61
+ let serverPort = get(opt, 'serverPort')
62
+ if (!ispint(serverPort)) {
63
+ serverPort = 11005
64
+ }
65
+ serverPort = cint(serverPort)
66
+
67
+
68
+ //getUserById
69
+ let getUserById = get(opt, 'getUserById', null)
70
+
71
+
72
+ //bCheckUser
73
+ let bCheckUser = get(opt, 'bCheckUser', false)
74
+
75
+
76
+ //bExcludeWhenNotAdmin
77
+ let bExcludeWhenNotAdmin = get(opt, 'bExcludeWhenNotAdmin', false)
78
+
79
+
80
+ //webName
81
+ let webName = get(opt, 'webName', {})
82
+
83
+
84
+ //WServOrm
85
+ let optWServOrm = {
86
+ url,
87
+ db,
88
+ getUserById,
89
+ bCheckUser,
90
+ bExcludeWhenNotAdmin,
91
+ }
92
+ let wp = {}
93
+ try {
94
+ wp = WServOrm(ds, WOrm, optWServOrm)
95
+ }
96
+ catch (err) {
97
+ console.log(err)
98
+ }
99
+ let { woItems, procOrm } = wp
100
+
101
+
102
+ //getWebInfor
103
+ let getWebInfor = (userId) => {
104
+ return {
105
+ webName,
106
+ }
107
+ }
108
+
109
+
110
+ //getAPIsList
111
+ let getAPIsList = async (userId, token) => {
112
+ let rs = await woItems.apis.select()
113
+ return rs
114
+ }
115
+
116
+
117
+ //parsePayload
118
+ let parsePayload = (req) => {
119
+ let inp = get(req, 'payload')
120
+ if (isestr(inp)) {
121
+ inp = j2o(inp)
122
+ }
123
+ if (!iseobj(inp)) {
124
+ inp = null
125
+ }
126
+ return inp
127
+ }
128
+
129
+
130
+ //updateAPIs
131
+ let updateAPIs = async (userId, params = {}) => {
132
+
133
+ //spread params
134
+ let { apis: rsApis } = params
135
+ // console.log('levels', levels)
136
+ // console.log('rsApis', rsApis)
137
+
138
+ //save
139
+ let r = await woItems.apis.save(rsApis)
140
+
141
+ return r
142
+ }
143
+
144
+
145
+ //replaceAPIsByLevels
146
+ let replaceAPIsByLevels = async (userId, params = {}) => {
147
+
148
+ //spread params
149
+ let { levels, apis: rsApis } = params
150
+ // console.log('levels', levels)
151
+ // console.log('rsApis', rsApis)
152
+
153
+ //delAll levels
154
+ await woItems.apis.delAll({ levels })
155
+
156
+ //rsApisTemp
157
+ let rsApisTemp = cloneDeep(rsApis)
158
+ rsApisTemp = map(rsApisTemp, (v) => {
159
+ v.levels = levels
160
+ return v
161
+ })
162
+
163
+ //insert
164
+ let r = await woItems.apis.insert(rsApisTemp)
165
+
166
+ return r
167
+ }
168
+
169
+
170
+ //pathStaticFiles
171
+ let pathStaticFiles = 'dist'
172
+ let npmPathStaticFiles = './node_modules/w-web-api/dist'
173
+ if (fsIsFolder(npmPathStaticFiles)) {
174
+ pathStaticFiles = npmPathStaticFiles
175
+ }
176
+
177
+
178
+ //apis
179
+ let apis = [
180
+ // {
181
+ // method: 'GET',
182
+ // path: '/api/someAPI',
183
+ // handler: async function (req, res) {
184
+
185
+ // // //token
186
+ // // let token = get(req, 'query.token', '')
187
+
188
+ // return 'someAPI'
189
+ // },
190
+ // },
191
+ {
192
+ method: 'GET',
193
+ path: '/getWebInfor',
194
+ handler: async function (req, res) {
195
+ return getWebInfor()
196
+ },
197
+ },
198
+ {
199
+ method: 'GET',
200
+ path: '/getAPIsList',
201
+ handler: async function (req, res) {
202
+
203
+ //token
204
+ let token = get(req, 'query.token', '')
205
+
206
+ //getAPIsList
207
+ let r = await getAPIsList('', token)
208
+
209
+ return r
210
+ },
211
+ },
212
+ {
213
+ method: 'POST',
214
+ path: '/updateAPIs',
215
+ handler: async function (req, res) {
216
+ // console.log(req, res)
217
+ // console.log('payload', req.payload)
218
+
219
+ //parsePayload
220
+ let inp = parsePayload(req)
221
+
222
+ //updateAPIs
223
+ let r = await updateAPIs('', inp)
224
+
225
+ return r
226
+ },
227
+ },
228
+ {
229
+ method: 'POST',
230
+ path: '/replaceAPIsByLevels',
231
+ handler: async function (req, res) {
232
+ // console.log(req, res)
233
+ // console.log('payload', req.payload)
234
+
235
+ //parsePayload
236
+ let inp = parsePayload(req)
237
+
238
+ //replaceAPIsByLevels
239
+ let r = await replaceAPIsByLevels('', inp)
240
+
241
+ return r
242
+ },
243
+ },
244
+ ]
245
+
246
+
247
+ //tableNamesExec, tableNamesSync
248
+ let tableNamesExec = keys(ds)
249
+ // let tableNamesSync = filter(tableNamesExec, (v) => {
250
+ // return strright(v, 5) !== 'Items'//不同步數據
251
+ // })
252
+ let tableNamesSync = tableNamesExec
253
+
254
+
255
+ //WServHapiServer
256
+ let wshs = WServHapiServer({
257
+ port: opt.serverPort,
258
+ pathStaticFiles,
259
+ apis,
260
+ getUserIDFromToken: async (token) => { //可使用async或sync函數
261
+ return 'id-for-admin'
262
+ },
263
+ useDbORM: true,
264
+ dbORMs: woItems,
265
+ operORM: procOrm, //procOrm的輸入為: userId, tableName, methodName, input
266
+ tableNamesExec,
267
+ methodsExec: ['select', 'insert', 'save', 'del'], //mix需於procOrm內註冊以提供
268
+ tableNamesSync,
269
+ extFuncs: { //接收參數第1個為userId, 之後才是前端給予參數
270
+ getWebInfor,
271
+ getAPIsList,
272
+ //...
273
+ },
274
+ hookBefores: null,
275
+ hookAfters: null,
276
+ })
277
+
278
+
279
+ return wshs
280
+ }
281
+
282
+
283
+ export default WWebApi
@@ -0,0 +1,17 @@
1
+ // import path from 'path'
2
+ // import fs from 'fs'
3
+ // import JSON5 from 'json5'
4
+
5
+
6
+ function getSettings() {
7
+ return {
8
+ 'dbUsername': 'username',
9
+ 'dbPassword': 'password',
10
+ 'dbName': 'wapis',
11
+ 'dbIP': 'localhost',
12
+ 'dbPort': 27017,
13
+ }
14
+ }
15
+
16
+
17
+ export default getSettings
package/server/mDb.mjs ADDED
@@ -0,0 +1,76 @@
1
+ // import path from 'path'
2
+ import fs from 'fs'
3
+ // import _ from 'lodash'
4
+ import w from 'wsemi'
5
+ import br from 'w-serv-orm/src/getDbBackupAndRecover.mjs'
6
+ import { woItems } from './mOrm.mjs'
7
+ // import { genModels } from './mOrmGenModels.mjs'
8
+
9
+
10
+ //mOrmGenModels.mjs
11
+ let genModels = `
12
+ import path from 'path'
13
+ import _ from 'lodash'
14
+ // import w from 'wsemi'
15
+ import genModelsByTabs from 'w-orm-reladb/src/genModelsByTabs.mjs'
16
+ import ds from '../src/schema/index.mjs'
17
+
18
+
19
+ let fdSrv = path.resolve()
20
+
21
+
22
+ function genModels() {
23
+
24
+ //names
25
+ let names = _.keys(ds)
26
+
27
+ //tabs
28
+ let tabs = {}
29
+ _.each(names, (name) => {
30
+ tabs[name] = ds[name].settings
31
+ })
32
+ console.log('tabs', tabs)
33
+
34
+ //fd
35
+ let fd = fdSrv + '/models'
36
+
37
+ //genModelsByTabs
38
+ genModelsByTabs(fd, tabs)
39
+
40
+ }
41
+
42
+
43
+ export { genModels }
44
+ `
45
+
46
+ function backup() {
47
+ br.backup(woItems)
48
+ .then((res) => {
49
+ let j = w.o2j(res)
50
+ fs.writeFileSync(`./backup-${w.now2strp()}.json`, j, 'utf8')
51
+ console.log('backup finish')
52
+ })
53
+ .catch((err) => {
54
+ console.log(err)
55
+ })
56
+ }
57
+ backup()
58
+
59
+
60
+ function recover() {
61
+ let fp = '../_db/backup-20220222134749.json'
62
+ let genModels = null
63
+ let needCreateStorage = false
64
+ br.recover(fp, woItems, genModels, needCreateStorage)
65
+ .then(() => {
66
+ console.log('recover finish')
67
+ })
68
+ .catch((err) => {
69
+ console.log(err)
70
+ })
71
+ }
72
+ // recover()
73
+
74
+
75
+ //備份資料重與由備份資料重建資料庫
76
+ //node --experimental-modules --es-module-specifier-resolution=node server/mDb.mjs
@@ -0,0 +1,40 @@
1
+ // import path from 'path'
2
+ // import fs from 'fs'
3
+ // import _ from 'lodash'
4
+ import w from 'wsemi'
5
+ import { woItems } from './mOrm.mjs'
6
+ import ds from '../src/schema/index.mjs'
7
+
8
+
9
+ async function initialTestData() {
10
+
11
+ //delFiles
12
+ // delFiles('./histData')
13
+ // delFiles('./uploadFiles')
14
+
15
+ //funTest
16
+ await w.pmSeries(ds, async (v, k) => {
17
+
18
+ //funTestAndSave
19
+ let rs = await v.funTestAndSave(woItems)
20
+ console.log(`${k}.funTestAndSave`, rs)
21
+
22
+ // //funTest
23
+ // let rs = await v.funTest(woItems)
24
+
25
+ // //save
26
+ // await woItems[k].save(rs)
27
+ // console.log(`${k}.funTest and save`, rs)
28
+
29
+ })
30
+
31
+ }
32
+
33
+ initialTestData()
34
+ .catch((err) => {
35
+ console.log('initialTestData catch', err)
36
+ })
37
+
38
+
39
+ //刪除舊檔與重建測試資料庫
40
+ //node --experimental-modules --es-module-specifier-resolution=node server/mInitialTestData.mjs
@@ -0,0 +1,22 @@
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
+ import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
5
+
6
+
7
+ //getSettings
8
+ let st = getSettings()
9
+
10
+ //WServOrm
11
+ let opt = {
12
+ url: `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`,
13
+ db: st.dbName,
14
+ getUserById: null,
15
+ bCheckUser: false,
16
+ bExcludeWhenNotAdmin: false,
17
+ }
18
+ let r = WServOrm(ds, WOrm, opt)
19
+ let { woItems, procOrm } = r
20
+
21
+
22
+ export { woItems, procOrm }