w-serv-orm 1.0.1 → 1.0.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/dist/w-serv-orm.umd.js +1 -1
- package/docs/WServOrm.html +1 -1
- package/docs/WServOrm.mjs.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +2 -1
- package/src/genTestData.mjs +59 -0
- package/src/getDb.mjs +145 -0
- package/src/getMapOrm.mjs +1 -1
- package/src/getProc.mjs +6 -6
- package/src/getSettings.mjs +74 -0
- package/src/getWoItems.mjs +2 -2
package/dist/w-serv-orm.umd.js
CHANGED
package/docs/WServOrm.html
CHANGED
|
@@ -562,7 +562,7 @@ console.log(r) //回傳server用orm相關函數
|
|
|
562
562
|
<br class="clear">
|
|
563
563
|
|
|
564
564
|
<footer>
|
|
565
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022
|
|
565
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022 22:43:02 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
566
566
|
</footer>
|
|
567
567
|
|
|
568
568
|
<script>prettyPrint();</script>
|
package/docs/WServOrm.mjs.html
CHANGED
|
@@ -155,7 +155,7 @@ export default WServOrm
|
|
|
155
155
|
<br class="clear">
|
|
156
156
|
|
|
157
157
|
<footer>
|
|
158
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022
|
|
158
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Thu Apr 14 2022 22:43:02 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
159
159
|
</footer>
|
|
160
160
|
|
|
161
161
|
<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 22:43:02 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
72
72
|
</footer>
|
|
73
73
|
|
|
74
74
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import get from 'lodash/get'
|
|
2
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
3
|
+
import isfun from 'wsemi/src/isfun'
|
|
4
|
+
import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async function genTestData(ds, woItems, opt = {}) {
|
|
8
|
+
|
|
9
|
+
//bLog
|
|
10
|
+
let bLog = get(opt, 'bLog')
|
|
11
|
+
if (!isbol(bLog)) {
|
|
12
|
+
bLog = true
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//mode
|
|
16
|
+
let mode = get(opt, 'mode')
|
|
17
|
+
if (mode !== 'funTestAndSave' && mode !== 'funTest') {
|
|
18
|
+
mode = 'funTestAndSave'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//hookFunTestData
|
|
22
|
+
let hookFunTestData = get(opt, 'hookFunTestData')
|
|
23
|
+
|
|
24
|
+
//pmSeries
|
|
25
|
+
await pmSeries(ds, async (v, k) => {
|
|
26
|
+
|
|
27
|
+
if (mode === 'funTestAndSave') {
|
|
28
|
+
|
|
29
|
+
//funTestAndSave
|
|
30
|
+
let rs = await v.funTestAndSave(woItems)
|
|
31
|
+
|
|
32
|
+
if (bLog) {
|
|
33
|
+
console.log(`${k}.funTestAndSave`, rs)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
|
|
38
|
+
//funTest
|
|
39
|
+
let rs = await v.funTest(woItems)
|
|
40
|
+
|
|
41
|
+
//hookFunTestData
|
|
42
|
+
if (isfun(hookFunTestData)) {
|
|
43
|
+
rs = hookFunTestData(rs)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//save
|
|
47
|
+
await woItems[k].save(rs)
|
|
48
|
+
|
|
49
|
+
if (bLog) {
|
|
50
|
+
console.log(`${k}.funTest and save`, rs)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export default genTestData
|
package/src/getDb.mjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import get from 'lodash/get'
|
|
4
|
+
import each from 'lodash/each'
|
|
5
|
+
import keys from 'lodash/keys'
|
|
6
|
+
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
7
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
8
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
9
|
+
import o2j from 'wsemi/src/o2j.mjs'
|
|
10
|
+
import now2strp from 'wsemi/src/now2strp.mjs'
|
|
11
|
+
import haskey from 'wsemi/src/haskey.mjs'
|
|
12
|
+
import br from './getDbBackupAndRecover.mjs'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
let fdSrv = path.resolve()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function genModels(ds, genModelsByTabs, opt = {}) {
|
|
19
|
+
|
|
20
|
+
//fdModels
|
|
21
|
+
let fdModels = get(opt, 'fdModels')
|
|
22
|
+
if (!isestr(fdModels)) {
|
|
23
|
+
fdModels = './models'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//bLog
|
|
27
|
+
let bLog = get(opt, 'bLog')
|
|
28
|
+
if (!isbol(bLog)) {
|
|
29
|
+
bLog = true
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//names
|
|
33
|
+
let names = keys(ds)
|
|
34
|
+
|
|
35
|
+
//tabs
|
|
36
|
+
let tabs = {}
|
|
37
|
+
each(names, (name) => {
|
|
38
|
+
|
|
39
|
+
//check
|
|
40
|
+
if (!haskey(ds[name], 'settings')) {
|
|
41
|
+
console.log(`資料表[${name}]無settings資訊`)
|
|
42
|
+
return true //跳出換下一個
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//check
|
|
46
|
+
if (!iseobj(ds[name].settings)) {
|
|
47
|
+
console.log(`ds[${name}].settings非有效物件`)
|
|
48
|
+
return true //跳出換下一個
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//save
|
|
52
|
+
tabs[name] = ds[name].settings
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
if (bLog) {
|
|
56
|
+
console.log('tabs', tabs)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//fd
|
|
60
|
+
let fd = path.resolve(fdSrv, fdModels) //fdSrv + '/models'
|
|
61
|
+
|
|
62
|
+
//genModelsByTabs
|
|
63
|
+
genModelsByTabs(fd, tabs)
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async function backup(woItems, opt = {}) {
|
|
69
|
+
|
|
70
|
+
//bLog
|
|
71
|
+
let bLog = get(opt, 'bLog')
|
|
72
|
+
if (!isbol(bLog)) {
|
|
73
|
+
bLog = true
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//backup
|
|
77
|
+
await br.backup(woItems)
|
|
78
|
+
.then((res) => {
|
|
79
|
+
|
|
80
|
+
//o2j
|
|
81
|
+
let j = o2j(res)
|
|
82
|
+
|
|
83
|
+
//fn
|
|
84
|
+
let fn = `backup-${now2strp()}.json`
|
|
85
|
+
|
|
86
|
+
//fp
|
|
87
|
+
let fp = path.resolve(fdSrv, fn)
|
|
88
|
+
|
|
89
|
+
//writeFileSync
|
|
90
|
+
fs.writeFileSync(fp, j, 'utf8')
|
|
91
|
+
|
|
92
|
+
if (bLog) {
|
|
93
|
+
console.log('backup finish')
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch((err) => {
|
|
97
|
+
console.log(err)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async function recover(woItems, fp, opt = {}) {
|
|
104
|
+
|
|
105
|
+
//bRela, 是否為關聯資料庫
|
|
106
|
+
let bRela = get(opt, 'bRela')
|
|
107
|
+
if (!isbol(bRela)) {
|
|
108
|
+
bRela = false
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//bLog
|
|
112
|
+
let bLog = get(opt, 'bLog')
|
|
113
|
+
if (!isbol(bLog)) {
|
|
114
|
+
bLog = true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//funGenModels and bNeedCreateStorage, 若為關聯資料庫則需使用genModels與needCreateStorage=true
|
|
118
|
+
let funGenModels = null
|
|
119
|
+
let bNeedCreateStorage = false
|
|
120
|
+
if (bRela) {
|
|
121
|
+
funGenModels = genModels
|
|
122
|
+
bNeedCreateStorage = true
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//recover
|
|
126
|
+
await br.recover(fp, woItems, funGenModels, bNeedCreateStorage)
|
|
127
|
+
.then(() => {
|
|
128
|
+
if (bLog) {
|
|
129
|
+
console.log('recover finish')
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.catch((err) => {
|
|
133
|
+
console.log(err)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
let getDb = {
|
|
140
|
+
backup,
|
|
141
|
+
recover,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
export default getDb
|
package/src/getMapOrm.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import size from 'lodash/size'
|
|
|
5
5
|
import nowms2str from 'wsemi/src/nowms2str.mjs'
|
|
6
6
|
import isarr from 'wsemi/src/isarr.mjs'
|
|
7
7
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
8
|
-
import isestr from 'wsemi/src/isestr'
|
|
8
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
let _ds = null
|
package/src/getProc.mjs
CHANGED
|
@@ -2,12 +2,12 @@ import get from 'lodash/get'
|
|
|
2
2
|
import size from 'lodash/size'
|
|
3
3
|
import filter from 'lodash/filter'
|
|
4
4
|
import isarr from 'wsemi/src/isarr.mjs'
|
|
5
|
-
import isestr from 'wsemi/src/isestr'
|
|
6
|
-
import haskey from 'wsemi/src/haskey'
|
|
7
|
-
import pmSeries from 'wsemi/src/pmSeries'
|
|
8
|
-
import pmChain from 'wsemi/src/pmChain'
|
|
9
|
-
import isfun from 'wsemi/src/isfun'
|
|
10
|
-
import isbol from 'wsemi/src/isbol'
|
|
5
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
6
|
+
import haskey from 'wsemi/src/haskey.mjs'
|
|
7
|
+
import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
8
|
+
import pmChain from 'wsemi/src/pmChain.mjs'
|
|
9
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
10
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
let _funChecks = []
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import JSON5 from 'json5'
|
|
4
|
+
import get from 'lodash/get'
|
|
5
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
6
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let fdSrv = path.resolve()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
function getSettings(opt = {}) {
|
|
13
|
+
|
|
14
|
+
//fn
|
|
15
|
+
let fn = get(opt, 'fn')
|
|
16
|
+
if (!isestr(fn)) {
|
|
17
|
+
fn = 'settings.json'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//fp
|
|
21
|
+
let fp = path.resolve(fdSrv, fn) //`${fdSrv}/${fn}`
|
|
22
|
+
|
|
23
|
+
//st
|
|
24
|
+
let st = {}
|
|
25
|
+
try {
|
|
26
|
+
|
|
27
|
+
//readFileSync
|
|
28
|
+
let j = fs.readFileSync(fp, 'utf8')
|
|
29
|
+
|
|
30
|
+
//parse
|
|
31
|
+
st = JSON5.parse(j)
|
|
32
|
+
|
|
33
|
+
//check
|
|
34
|
+
if (!isestr(get(st, 'dbType'))) {
|
|
35
|
+
console.log('invalid st.dbType', st.dbType)
|
|
36
|
+
}
|
|
37
|
+
if (!isestr(get(st, 'dbUsername'))) {
|
|
38
|
+
console.log('invalid st.dbUsername', st.dbUsername)
|
|
39
|
+
}
|
|
40
|
+
if (!isestr(get(st, 'dbPassword'))) {
|
|
41
|
+
console.log('invalid st.dbPassword', st.dbPassword)
|
|
42
|
+
}
|
|
43
|
+
if (!isestr(get(st, 'dbIP'))) {
|
|
44
|
+
console.log('invalid st.dbIP', st.dbIP)
|
|
45
|
+
}
|
|
46
|
+
if (!isnum(get(st, 'dbPort'))) {
|
|
47
|
+
console.log('invalid st.dbPort', st.dbPort)
|
|
48
|
+
}
|
|
49
|
+
if (!isestr(get(st, 'dbType'))) {
|
|
50
|
+
console.log('invalid st.dbType', st.dbType)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//url, db
|
|
54
|
+
let url = `${st.dbType}://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
|
|
55
|
+
let db = st.dbName
|
|
56
|
+
|
|
57
|
+
//merge
|
|
58
|
+
st = {
|
|
59
|
+
...st,
|
|
60
|
+
url,
|
|
61
|
+
db,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.log(err)
|
|
67
|
+
throw new Error('伺服器讀取設定檔失敗')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return st
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
export default getSettings
|
package/src/getWoItems.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import each from 'lodash/each'
|
|
2
2
|
import keys from 'lodash/keys'
|
|
3
3
|
import size from 'lodash/size'
|
|
4
|
-
import isfun from 'wsemi/src/isfun'
|
|
5
|
-
import isestr from 'wsemi/src/isestr'
|
|
4
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
5
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
function getWoItems(ds, WOrm, url, db) {
|