w-orm-mongodb 1.1.30 → 1.1.32

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.
@@ -80,7 +80,7 @@
80
80
 
81
81
  <dt class="tag-source">Source:</dt>
82
82
  <dd class="tag-source"><ul class="dummy"><li>
83
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line32">line 32</a>
83
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line33">line 33</a>
84
84
  </li></ul></dd>
85
85
 
86
86
 
@@ -429,7 +429,7 @@
429
429
 
430
430
  <dt class="tag-source">Source:</dt>
431
431
  <dd class="tag-source"><ul class="dummy"><li>
432
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line309">line 309</a>
432
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line284">line 284</a>
433
433
  </li></ul></dd>
434
434
 
435
435
 
@@ -590,7 +590,7 @@
590
590
 
591
591
  <dt class="tag-source">Source:</dt>
592
592
  <dd class="tag-source"><ul class="dummy"><li>
593
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line378">line 378</a>
593
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line353">line 353</a>
594
594
  </li></ul></dd>
595
595
 
596
596
 
@@ -768,7 +768,7 @@
768
768
 
769
769
  <dt class="tag-source">Source:</dt>
770
770
  <dd class="tag-source"><ul class="dummy"><li>
771
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line736">line 736</a>
771
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line711">line 711</a>
772
772
  </li></ul></dd>
773
773
 
774
774
 
@@ -946,7 +946,7 @@
946
946
 
947
947
  <dt class="tag-source">Source:</dt>
948
948
  <dd class="tag-source"><ul class="dummy"><li>
949
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line629">line 629</a>
949
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line604">line 604</a>
950
950
  </li></ul></dd>
951
951
 
952
952
 
@@ -1104,7 +1104,7 @@
1104
1104
 
1105
1105
  <dt class="tag-source">Source:</dt>
1106
1106
  <dd class="tag-source"><ul class="dummy"><li>
1107
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line115">line 115</a>
1107
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line116">line 116</a>
1108
1108
  </li></ul></dd>
1109
1109
 
1110
1110
 
@@ -1265,7 +1265,7 @@
1265
1265
 
1266
1266
  <dt class="tag-source">Source:</dt>
1267
1267
  <dd class="tag-source"><ul class="dummy"><li>
1268
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line430">line 430</a>
1268
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line405">line 405</a>
1269
1269
  </li></ul></dd>
1270
1270
 
1271
1271
 
@@ -1638,46 +1638,6 @@
1638
1638
  </tr>
1639
1639
 
1640
1640
 
1641
-
1642
- <tr>
1643
-
1644
- <td class="name"><code>atomic</code></td>
1645
-
1646
-
1647
- <td class="type">
1648
-
1649
-
1650
- <span class="param-type">boolean</span>
1651
-
1652
-
1653
-
1654
-
1655
- </td>
1656
-
1657
-
1658
- <td class="attributes">
1659
-
1660
- &lt;optional><br>
1661
-
1662
-
1663
-
1664
-
1665
-
1666
- </td>
1667
-
1668
-
1669
-
1670
- <td class="default">
1671
-
1672
- <code>false</code>
1673
-
1674
- </td>
1675
-
1676
-
1677
- <td class="description last"><p>輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false</p></td>
1678
- </tr>
1679
-
1680
-
1681
1641
  </tbody>
1682
1642
  </table>
1683
1643
 
@@ -1750,7 +1710,7 @@
1750
1710
 
1751
1711
  <dt class="tag-source">Source:</dt>
1752
1712
  <dd class="tag-source"><ul class="dummy"><li>
1753
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line62">line 62</a>
1713
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line63">line 63</a>
1754
1714
  </li></ul></dd>
1755
1715
 
1756
1716
 
@@ -1928,7 +1888,7 @@
1928
1888
 
1929
1889
  <dt class="tag-source">Source:</dt>
1930
1890
  <dd class="tag-source"><ul class="dummy"><li>
1931
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line517">line 517</a>
1891
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line492">line 492</a>
1932
1892
  </li></ul></dd>
1933
1893
 
1934
1894
 
@@ -2085,7 +2045,7 @@
2085
2045
  <br class="clear">
2086
2046
 
2087
2047
  <footer>
2088
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Mar 20 2024 16:44:25 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2048
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 07 2024 21:30:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2089
2049
  </footer>
2090
2050
 
2091
2051
  <script>prettyPrint();</script>
@@ -48,14 +48,15 @@
48
48
  <pre class="prettyprint source linenums"><code>import events from 'events'
49
49
  import mongodb from 'mongodb'
50
50
  import stream from 'stream'
51
- import cloneDeep from 'lodash-es/cloneDeep'
52
- import get from 'lodash-es/get'
53
- import map from 'lodash-es/map'
54
- import omit from 'lodash-es/omit'
55
- import size from 'lodash-es/size'
51
+ import cloneDeep from 'lodash-es/cloneDeep.js'
52
+ import get from 'lodash-es/get.js'
53
+ import map from 'lodash-es/map.js'
54
+ import omit from 'lodash-es/omit.js'
55
+ import size from 'lodash-es/size.js'
56
56
  import genPm from 'wsemi/src/genPm.mjs'
57
57
  import genID from 'wsemi/src/genID.mjs'
58
58
  import isarr from 'wsemi/src/isarr.mjs'
59
+ import iseobj from 'wsemi/src/iseobj.mjs'
59
60
  import pmSeries from 'wsemi/src/pmSeries.mjs'
60
61
 
61
62
 
@@ -239,7 +240,6 @@ function WOrmMongodb(opt = {}) {
239
240
  * @param {Object|Array} data 輸入數據物件或陣列
240
241
  * @param {Object} [option={}] 輸入設定物件,預設為{}
241
242
  * @param {boolean} [option.autoInsert=true] 輸入是否於儲存時發現原本無數據,則自動改以插入處理,預設為true
242
- * @param {boolean} [option.atomic=false] 輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false
243
243
  * @returns {Promise} 回傳Promise,resolve回傳儲存結果,reject回傳錯誤訊息
244
244
  */
245
245
  async function save(data, option = {}) {
@@ -248,9 +248,8 @@ function WOrmMongodb(opt = {}) {
248
248
  //cloneDeep
249
249
  data = cloneDeep(data)
250
250
 
251
- //autoInsert, atomic
251
+ //autoInsert
252
252
  let autoInsert = get(option, 'autoInsert', true)
253
- let atomic = get(option, 'atomic', false)
254
253
 
255
254
  //client
256
255
  // let client = await MongoClient.connect(opt.url, optMGConn)
@@ -270,15 +269,6 @@ function WOrmMongodb(opt = {}) {
270
269
  data = [data]
271
270
  }
272
271
 
273
- //oper
274
- let oper = null
275
- if (atomic) {
276
- oper = 'findOneAndUpdate'
277
- }
278
- else {
279
- oper = 'updateOne'
280
- }
281
-
282
272
  //pmSeries
283
273
  res = await pmSeries(data, async(v) => {
284
274
 
@@ -286,38 +276,23 @@ function WOrmMongodb(opt = {}) {
286
276
  let rest = null
287
277
 
288
278
  //oper
289
- rest = await collection[oper]({ id: v.id }, { $set: v })
279
+ rest = await collection.findOneAndUpdate({ id: v.id }, { $set: v })
280
+ // console.log('rest', rest)
290
281
 
291
- //lastErrorObject for findOneAndUpdate
292
- if (rest.lastErrorObject) {
293
- // console.log('rest.lastErrorObject', rest.lastErrorObject)
282
+ if (iseobj(rest)) {
294
283
  rest = {
295
- // lastErrorObject: { n: 1, updatedExisting: true },
296
- // value: {
297
- // _id: new ObjectId("615c18bb6e5db9935b10d88e"),
298
- // id: 'id-rosemary',
299
- // name: 'rosemary',
300
- // value: 123.456
301
- // },
302
- // ok: 1
303
- n: rest.lastErrorObject.n,
304
- nModified: rest.lastErrorObject.updatedExisting ? 1 : 0,
284
+ n: 1,
285
+ nModified: 1,
305
286
  ok: 1,
306
287
  }
307
288
  }
308
289
  else {
309
290
  rest = {
310
- // acknowledged: true,
311
- // modifiedCount: 1,
312
- // upsertedId: null,
313
- // upsertedCount: 0,
314
- // matchedCount: 1
315
- n: rest.matchedCount,
316
- nModified: rest.modifiedCount,
317
- ok: rest.acknowledged ? 1 : 0,
291
+ n: 0,
292
+ nModified: 0,
293
+ ok: 1,
318
294
  }
319
295
  }
320
- // console.log('rest', rest)
321
296
 
322
297
  //autoInsert
323
298
  if (autoInsert &amp;&amp; rest.n === 0) {
@@ -872,7 +847,7 @@ export default WOrmMongodb
872
847
  <br class="clear">
873
848
 
874
849
  <footer>
875
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Mar 20 2024 16:44:25 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
850
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 07 2024 21:30:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
876
851
  </footer>
877
852
 
878
853
  <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 Wed Mar 20 2024 16:44:25 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 Sun Apr 07 2024 21:30:47 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-basic.mjs CHANGED
@@ -75,7 +75,7 @@ async function test() {
75
75
 
76
76
 
77
77
  //save
78
- await w.save(rsm, { autoInsert: false, atomic: true })
78
+ await w.save(rsm, { autoInsert: false })
79
79
  .then(function(msg) {
80
80
  console.log('save then', msg)
81
81
  })
@@ -173,4 +173,4 @@ test()
173
173
  // change del
174
174
  // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
175
175
 
176
- //node --experimental-modules --es-module-specifier-resolution=node g-basic.mjs
176
+ //node --experimental-modules g-basic.mjs
package/g-gfs.mjs CHANGED
@@ -109,4 +109,4 @@ test()
109
109
  // change delGfs
110
110
  // delGfs { n: 1, nDeleted: 1, ok: 1 }
111
111
 
112
- //node --experimental-modules --es-module-specifier-resolution=node g-gfs.mjs
112
+ //node --experimental-modules g-gfs.mjs
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "w-orm-mongodb",
3
- "version": "1.1.30",
3
+ "version": "1.1.32",
4
4
  "main": "dist/w-orm-mongodb.umd.js",
5
5
  "dependencies": {
6
6
  "mongodb": "^6.5.0",
7
7
  "saslprep": "^1.0.3",
8
8
  "lodash-es": "^4.17.21",
9
- "wsemi": "^1.7.47"
9
+ "wsemi": "^1.7.49"
10
10
  },
11
11
  "devDependencies": {
12
- "w-package-tools": "^1.0.73"
12
+ "w-package-tools": "^1.0.75"
13
13
  },
14
14
  "scripts": {
15
15
  "test": "mocha --parallel --timeout 60000 --experimental-modules --es-module-specifier-resolution=node",
package/script.txt ADDED
@@ -0,0 +1,18 @@
1
+ #node --experimental-modules --es-module-specifier-resolution=node toolg/addVersion.mjs
2
+ node --experimental-modules --es-module-specifier-resolution=node toolg/modifyReadme.mjs
3
+
4
+ node --experimental-modules --es-module-specifier-resolution=node toolg/cleanFolder.mjs
5
+ ./node_modules/.bin/jsdoc -c .jsdoc
6
+
7
+ node --experimental-modules --es-module-specifier-resolution=node toolg/gDistRollup.mjs
8
+
9
+ git add . -A
10
+ git commit -m 'modify: '
11
+ git push origin master:master
12
+
13
+ npm run deploy
14
+
15
+ #npm test
16
+
17
+ #npm publish
18
+
@@ -1,14 +1,15 @@
1
1
  import events from 'events'
2
2
  import mongodb from 'mongodb'
3
3
  import stream from 'stream'
4
- import cloneDeep from 'lodash-es/cloneDeep'
5
- import get from 'lodash-es/get'
6
- import map from 'lodash-es/map'
7
- import omit from 'lodash-es/omit'
8
- import size from 'lodash-es/size'
4
+ import cloneDeep from 'lodash-es/cloneDeep.js'
5
+ import get from 'lodash-es/get.js'
6
+ import map from 'lodash-es/map.js'
7
+ import omit from 'lodash-es/omit.js'
8
+ import size from 'lodash-es/size.js'
9
9
  import genPm from 'wsemi/src/genPm.mjs'
10
10
  import genID from 'wsemi/src/genID.mjs'
11
11
  import isarr from 'wsemi/src/isarr.mjs'
12
+ import iseobj from 'wsemi/src/iseobj.mjs'
12
13
  import pmSeries from 'wsemi/src/pmSeries.mjs'
13
14
 
14
15
 
@@ -192,7 +193,6 @@ function WOrmMongodb(opt = {}) {
192
193
  * @param {Object|Array} data 輸入數據物件或陣列
193
194
  * @param {Object} [option={}] 輸入設定物件,預設為{}
194
195
  * @param {boolean} [option.autoInsert=true] 輸入是否於儲存時發現原本無數據,則自動改以插入處理,預設為true
195
- * @param {boolean} [option.atomic=false] 輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false
196
196
  * @returns {Promise} 回傳Promise,resolve回傳儲存結果,reject回傳錯誤訊息
197
197
  */
198
198
  async function save(data, option = {}) {
@@ -201,9 +201,8 @@ function WOrmMongodb(opt = {}) {
201
201
  //cloneDeep
202
202
  data = cloneDeep(data)
203
203
 
204
- //autoInsert, atomic
204
+ //autoInsert
205
205
  let autoInsert = get(option, 'autoInsert', true)
206
- let atomic = get(option, 'atomic', false)
207
206
 
208
207
  //client
209
208
  // let client = await MongoClient.connect(opt.url, optMGConn)
@@ -223,15 +222,6 @@ function WOrmMongodb(opt = {}) {
223
222
  data = [data]
224
223
  }
225
224
 
226
- //oper
227
- let oper = null
228
- if (atomic) {
229
- oper = 'findOneAndUpdate'
230
- }
231
- else {
232
- oper = 'updateOne'
233
- }
234
-
235
225
  //pmSeries
236
226
  res = await pmSeries(data, async(v) => {
237
227
 
@@ -239,38 +229,23 @@ function WOrmMongodb(opt = {}) {
239
229
  let rest = null
240
230
 
241
231
  //oper
242
- rest = await collection[oper]({ id: v.id }, { $set: v })
232
+ rest = await collection.findOneAndUpdate({ id: v.id }, { $set: v })
233
+ // console.log('rest', rest)
243
234
 
244
- //lastErrorObject for findOneAndUpdate
245
- if (rest.lastErrorObject) {
246
- // console.log('rest.lastErrorObject', rest.lastErrorObject)
235
+ if (iseobj(rest)) {
247
236
  rest = {
248
- // lastErrorObject: { n: 1, updatedExisting: true },
249
- // value: {
250
- // _id: new ObjectId("615c18bb6e5db9935b10d88e"),
251
- // id: 'id-rosemary',
252
- // name: 'rosemary',
253
- // value: 123.456
254
- // },
255
- // ok: 1
256
- n: rest.lastErrorObject.n,
257
- nModified: rest.lastErrorObject.updatedExisting ? 1 : 0,
237
+ n: 1,
238
+ nModified: 1,
258
239
  ok: 1,
259
240
  }
260
241
  }
261
242
  else {
262
243
  rest = {
263
- // acknowledged: true,
264
- // modifiedCount: 1,
265
- // upsertedId: null,
266
- // upsertedCount: 0,
267
- // matchedCount: 1
268
- n: rest.matchedCount,
269
- nModified: rest.modifiedCount,
270
- ok: rest.acknowledged ? 1 : 0,
244
+ n: 0,
245
+ nModified: 0,
246
+ ok: 1,
271
247
  }
272
248
  }
273
- // console.log('rest', rest)
274
249
 
275
250
  //autoInsert
276
251
  if (autoInsert && rest.n === 0) {