w-serv-orm 1.0.13 → 1.0.15

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.
@@ -60,37 +60,40 @@ import getProc from './getProc.mjs'
60
60
  * @param {String} url 輸入資料庫連線位址字串
61
61
  * @param {String} db 輸入資料庫名稱字串
62
62
  * @param {Object} [opt={}] 輸入設定物件,預設{}
63
- * @param {Boolean} [opt.bCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
64
- * @param {Function} [opt.getUserById=null] 輸入當bCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
65
- * @param {Boolean} [opt.bExcludeWhenNotAdmin=true] 輸入使用ORM的select方法時是否自動刪除數據內isActive欄位之布林值,預設true
63
+ * @param {Boolean} [opt.useCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
64
+ * @param {Function} [opt.getUserById=null] 輸入當useCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
65
+ * @param {Boolean} [opt.useExcludeWhenNotAdmin=true] 輸入使用ORM的select方法時是否自動刪除數據內isActive欄位之布林值,預設true
66
66
  * @returns {Object} 回傳通訊物件,可監聽事件open、error、clientChange、execute、broadcast、deliver,可使用函數broadcast
67
67
  * @example
68
68
  *
69
- * import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
69
+ * // import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
70
+ * import WOrm from 'w-orm-lowdb/src/WOrmLowdb.mjs' //自行選擇引用ORM
70
71
  * import ds from './schema/index.mjs' //先行建置schema
71
72
  * import WServOrm from './src/WServOrm.mjs'
72
73
  *
73
- * //st
74
- * let st = {
75
- * dbUsername: 'username',
76
- * dbPassword: 'password',
77
- * dbName: 'wservorm',
78
- * dbIP: 'localhost',
79
- * dbPort: 27017,
80
- * }
74
+ * // //st
75
+ * // let st = {
76
+ * // dbUsername: 'username',
77
+ * // dbPassword: 'password',
78
+ * // dbName: 'wservorm',
79
+ * // dbIP: 'localhost',
80
+ * // dbPort: 27017,
81
+ * // }
81
82
  *
82
83
  * //url, db
83
- * let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
84
- * let db = st.dbName
84
+ * // let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
85
+ * // let db = st.dbName
86
+ * let url = './db.json'
87
+ * let db = 'worm'
85
88
  *
86
89
  * //WServOrm
87
90
  * let opt = {
88
91
  * getUserById: null,
89
- * bCheckUser: false,
90
- * bExcludeWhenNotAdmin: false,
92
+ * useCheckUser: false,
93
+ * useExcludeWhenNotAdmin: false,
91
94
  * }
92
95
  * let r = WServOrm(ds, WOrm, url, db, opt)
93
- console.log(r) //回傳server用orm相關函數
96
+ * console.log(r) //回傳server用orm相關函數
94
97
  * // => {
95
98
  * // backup: [AsyncFunction: backup],
96
99
  * // recover: [AsyncFunction: recover],
@@ -158,7 +161,7 @@ export default WServOrm
158
161
  <br class="clear">
159
162
 
160
163
  <footer>
161
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 30 2025 22:12:29 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
164
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 02 2025 11:26:08 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
162
165
  </footer>
163
166
 
164
167
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <br class="clear">
72
72
 
73
73
  <footer>
74
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 30 2025 22:12:29 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 02 2025 11:26:08 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/g-mOrm.mjs CHANGED
@@ -1,26 +1,29 @@
1
- import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
1
+ // import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
2
+ import WOrm from 'w-orm-lowdb/src/WOrmLowdb.mjs' //自行選擇引用ORM
2
3
  import ds from './schema/index.mjs' //先行建置schema
3
4
  import WServOrm from './src/WServOrm.mjs'
4
5
 
5
6
 
6
- //st
7
- let st = {
8
- dbUsername: 'username',
9
- dbPassword: 'password',
10
- dbName: 'wservorm',
11
- dbIP: 'localhost',
12
- dbPort: 27017,
13
- }
7
+ // //st
8
+ // let st = {
9
+ // dbUsername: 'username',
10
+ // dbPassword: 'password',
11
+ // dbName: 'wservorm',
12
+ // dbIP: 'localhost',
13
+ // dbPort: 27017,
14
+ // }
14
15
 
15
16
  //url, db
16
- let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
17
- let db = st.dbName
17
+ // let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
18
+ // let db = st.dbName
19
+ let url = './db.json'
20
+ let db = 'worm'
18
21
 
19
22
  //WServOrm
20
23
  let opt = {
21
24
  getUserById: null,
22
- bCheckUser: false,
23
- bExcludeWhenNotAdmin: false,
25
+ useCheckUser: false,
26
+ useExcludeWhenNotAdmin: false,
24
27
  }
25
28
  let r = WServOrm(ds, WOrm, url, db, opt)
26
29
  console.log(r) //回傳server用orm相關函數
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-serv-orm",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "main": "dist/w-serv-orm.umd.js",
5
5
  "dependencies": {
6
6
  "json5": "^2.2.3",
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "devDependencies": {
11
11
  "w-data-collector": "^1.0.22",
12
- "w-orm-mongodb": "^1.1.32",
13
- "w-package-tools": "^1.0.82"
12
+ "w-orm-lowdb": "^1.0.1",
13
+ "w-package-tools": "^1.0.85"
14
14
  },
15
15
  "scripts": {
16
16
  "test": "mocha --parallel --timeout 60000 --experimental-modules",
package/src/WServOrm.mjs CHANGED
@@ -13,37 +13,40 @@ import getProc from './getProc.mjs'
13
13
  * @param {String} url 輸入資料庫連線位址字串
14
14
  * @param {String} db 輸入資料庫名稱字串
15
15
  * @param {Object} [opt={}] 輸入設定物件,預設{}
16
- * @param {Boolean} [opt.bCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
17
- * @param {Function} [opt.getUserById=null] 輸入當bCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
18
- * @param {Boolean} [opt.bExcludeWhenNotAdmin=true] 輸入使用ORM的select方法時是否自動刪除數據內isActive欄位之布林值,預設true
16
+ * @param {Boolean} [opt.useCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
17
+ * @param {Function} [opt.getUserById=null] 輸入當useCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
18
+ * @param {Boolean} [opt.useExcludeWhenNotAdmin=true] 輸入使用ORM的select方法時是否自動刪除數據內isActive欄位之布林值,預設true
19
19
  * @returns {Object} 回傳通訊物件,可監聽事件open、error、clientChange、execute、broadcast、deliver,可使用函數broadcast
20
20
  * @example
21
21
  *
22
- * import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
22
+ * // import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
23
+ * import WOrm from 'w-orm-lowdb/src/WOrmLowdb.mjs' //自行選擇引用ORM
23
24
  * import ds from './schema/index.mjs' //先行建置schema
24
25
  * import WServOrm from './src/WServOrm.mjs'
25
26
  *
26
- * //st
27
- * let st = {
28
- * dbUsername: 'username',
29
- * dbPassword: 'password',
30
- * dbName: 'wservorm',
31
- * dbIP: 'localhost',
32
- * dbPort: 27017,
33
- * }
27
+ * // //st
28
+ * // let st = {
29
+ * // dbUsername: 'username',
30
+ * // dbPassword: 'password',
31
+ * // dbName: 'wservorm',
32
+ * // dbIP: 'localhost',
33
+ * // dbPort: 27017,
34
+ * // }
34
35
  *
35
36
  * //url, db
36
- * let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
37
- * let db = st.dbName
37
+ * // let url = `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`
38
+ * // let db = st.dbName
39
+ * let url = './db.json'
40
+ * let db = 'worm'
38
41
  *
39
42
  * //WServOrm
40
43
  * let opt = {
41
44
  * getUserById: null,
42
- * bCheckUser: false,
43
- * bExcludeWhenNotAdmin: false,
45
+ * useCheckUser: false,
46
+ * useExcludeWhenNotAdmin: false,
44
47
  * }
45
48
  * let r = WServOrm(ds, WOrm, url, db, opt)
46
- console.log(r) //回傳server用orm相關函數
49
+ * console.log(r) //回傳server用orm相關函數
47
50
  * // => {
48
51
  * // backup: [AsyncFunction: backup],
49
52
  * // recover: [AsyncFunction: recover],
package/src/getMapOrm.mjs CHANGED
@@ -160,7 +160,7 @@ async function mapOrm(userId, woName, mode, input) {
160
160
  })
161
161
  }
162
162
  else if (mode === 'save') {
163
- r = await wo.save(input, { atomic: true })
163
+ r = await wo.save(input)
164
164
  .catch((msg) => {
165
165
  console.log(`${woName}.save catch`, msg)
166
166
  err = '儲存資料失敗'
package/src/getProc.mjs CHANGED
@@ -15,8 +15,8 @@ let _funPreProcessing = []
15
15
  let _funPostProcessing = []
16
16
  let _mapOrm = null
17
17
  let _getUserById = null
18
- let bCheckUser = true
19
- let bExcludeWhenNotAdmin = true
18
+ let useCheckUser = true
19
+ let useExcludeWhenNotAdmin = true
20
20
 
21
21
 
22
22
  function addFunCheck(f) {
@@ -58,7 +58,7 @@ async function procOrm(userId, woName, mode, input) {
58
58
  }
59
59
 
60
60
  //check
61
- if (bCheckUser && !isestr(userId)) {
61
+ if (useCheckUser && !isestr(userId)) {
62
62
  console.log('userId', userId)
63
63
  console.log('找不到使用者主鍵')
64
64
  return Promise.reject(`找不到使用者主鍵`)
@@ -67,8 +67,8 @@ async function procOrm(userId, woName, mode, input) {
67
67
  //isAdmin
68
68
  let isAdmin = 'n'
69
69
 
70
- //bCheckUser
71
- if (bCheckUser) {
70
+ //useCheckUser
71
+ if (useCheckUser) {
72
72
 
73
73
  //check
74
74
  if (!isfun(_getUserById)) {
@@ -122,8 +122,8 @@ async function procOrm(userId, woName, mode, input) {
122
122
  //output
123
123
  let output = await _mapOrm(userId, woName, mode, input)
124
124
 
125
- //bExcludeWhenNotAdmin, 非管理者則要過濾掉已刪除之數據
126
- if (bExcludeWhenNotAdmin && isAdmin === 'n') {
125
+ //useExcludeWhenNotAdmin, 非管理者則要過濾掉已刪除之數據
126
+ if (useExcludeWhenNotAdmin && isAdmin === 'n') {
127
127
  if (mode === 'select' && isarr(output)) { //有可能為錯誤物件
128
128
  output = filter(output, (v) => {
129
129
  if (haskey(v, 'isActive')) { //針對有isActive屬性
@@ -153,19 +153,19 @@ function getProc(mapOrm, opt = {}) {
153
153
  //save _mapOrm
154
154
  _mapOrm = mapOrm
155
155
 
156
- //bCheckUser
157
- bCheckUser = get(opt, 'bCheckUser')
158
- if (!isbol(bCheckUser)) {
159
- bCheckUser = true
156
+ //useCheckUser
157
+ useCheckUser = get(opt, 'useCheckUser')
158
+ if (!isbol(useCheckUser)) {
159
+ useCheckUser = true
160
160
  }
161
161
 
162
- //save _getUserById, 不事先檢查, 因若bCheckUser=false可允許不給
162
+ //save _getUserById, 不事先檢查, 因若useCheckUser=false可允許不給
163
163
  _getUserById = get(opt, 'getUserById')
164
164
 
165
- //bExcludeWhenNotAdmin
166
- bExcludeWhenNotAdmin = get(opt, 'bExcludeWhenNotAdmin')
167
- if (!isbol(bExcludeWhenNotAdmin)) {
168
- bExcludeWhenNotAdmin = true
165
+ //useExcludeWhenNotAdmin
166
+ useExcludeWhenNotAdmin = get(opt, 'useExcludeWhenNotAdmin')
167
+ if (!isbol(useExcludeWhenNotAdmin)) {
168
+ useExcludeWhenNotAdmin = true
169
169
  }
170
170
 
171
171
  return {