w-orm-mongodb 1.1.28 → 1.1.29

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.
@@ -9,7 +9,7 @@ jobs:
9
9
 
10
10
  strategy:
11
11
  matrix:
12
- node-version: [16.x]
12
+ node-version: [18.x]
13
13
 
14
14
  steps:
15
15
  - uses: actions/checkout@v2
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * w-orm-mongodb v1.1.28
2
+ * w-orm-mongodb v1.1.29
3
3
  * (c) 2018-2021 yuda-lyu(semisphere)
4
4
  * Released under the MIT License.
5
5
  */
@@ -2085,7 +2085,7 @@
2085
2085
  <br class="clear">
2086
2086
 
2087
2087
  <footer>
2088
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Mar 30 2023 11:53:34 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2088
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Mar 31 2023 11:07:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2089
2089
  </footer>
2090
2090
 
2091
2091
  <script>prettyPrint();</script>
@@ -863,7 +863,7 @@ export default WOrmMongodb
863
863
  <br class="clear">
864
864
 
865
865
  <footer>
866
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Mar 30 2023 11:53:34 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
866
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Mar 31 2023 11:07:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
867
867
  </footer>
868
868
 
869
869
  <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 Thu Mar 30 2023 11:53:34 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 Fri Mar 31 2023 11:07:07 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/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "w-orm-mongodb",
3
- "version": "1.1.28",
3
+ "version": "1.1.29",
4
4
  "main": "dist/w-orm-mongodb.umd.js",
5
5
  "dependencies": {
6
6
  "mongodb": "^5.1.0",
7
7
  "saslprep": "^1.0.3",
8
8
  "lodash": "^4.17.21",
9
- "wsemi": "^1.7.1"
9
+ "wsemi": "^1.7.2"
10
10
  },
11
11
  "devDependencies": {
12
- "w-package-tools": "^1.0.68"
12
+ "w-package-tools": "^1.0.69"
13
13
  },
14
14
  "scripts": {
15
15
  "test": "mocha --parallel --timeout 60000 --experimental-modules --es-module-specifier-resolution=node",
@@ -2,157 +2,135 @@ import assert from 'assert'
2
2
  import wo from '../src/WOrmMongodb.mjs'
3
3
 
4
4
 
5
- describe('basic', async function() {
6
-
7
-
8
- let opt = {
9
- url: 'mongodb://username:password@127.0.0.1:27017',
10
- db: 'worm',
11
- cl: 'users',
12
- }
13
-
14
-
15
- let rs = [
16
- {
17
- id: 'id-peter',
18
- name: 'peter',
19
- value: 123,
20
- },
21
- {
22
- id: 'id-rosemary',
23
- name: 'rosemary',
24
- value: 123.456,
25
- },
26
- {
27
- id: '',
28
- name: 'kettle',
29
- value: 456,
30
- },
31
- ]
32
-
33
-
34
- let rsm = [
35
- {
36
- id: 'id-peter',
37
- name: 'peter(modify)'
38
- },
39
- {
40
- id: 'id-rosemary',
41
- name: 'rosemary(modify)'
42
- },
43
- {
44
- id: '',
45
- name: 'kettle(modify)'
46
- },
47
- ]
48
-
49
-
50
- //w
51
- let w = wo(opt)
52
-
53
-
54
- //on
55
- w.on('change', function(mode, data, res) {
56
- // console.log('change', mode)
57
- })
5
+ describe('basic', function() {
6
+ let rt = null
7
+ let vans = {}
8
+ let vget = {}
58
9
 
59
10
 
60
- //delAll
61
- if (true) {
11
+ before(async function () {
62
12
 
63
- let rr = {
64
- nDeleted: 2,
65
- ok: 1,
13
+
14
+ let opt = {
15
+ url: 'mongodb://username:password@127.0.0.1:27017',
16
+ db: 'worm',
17
+ cl: 'users',
66
18
  }
67
19
 
68
- it(`should get ${JSON.stringify(rr)} for delAll`, async function() {
69
-
70
- let rt = null
71
- await w.delAll()
72
- .then(function(msg) {
73
- // console.log('delAll then', msg)
74
- //考慮可能有不同初始測試數據
75
- // delAll then { n: 2, nDeleted: 2, ok: 1 }
76
- // delAll then { n: 3, nDeleted: 2, ok: 1 }
77
- //僅針對nDeleted與ok欄位比對
78
- rt = {
79
- nDeleted: msg.nDeleted,
80
- ok: msg.ok,
81
- }
82
- })
83
- .catch(function(msg) {
84
- // console.log('delAll catch', msg)
85
- rt = msg.toString()
86
- })
87
-
88
- assert.strict.deepStrictEqual(rt, rr)
89
- })
90
20
 
91
- }
21
+ let rs = [
22
+ {
23
+ id: 'id-peter',
24
+ name: 'peter',
25
+ value: 123,
26
+ },
27
+ {
28
+ id: 'id-rosemary',
29
+ name: 'rosemary',
30
+ value: 123.456,
31
+ },
32
+ {
33
+ id: '',
34
+ name: 'kettle',
35
+ value: 456,
36
+ },
37
+ ]
92
38
 
93
39
 
94
- //insert
95
- if (true) {
40
+ let rsm = [
41
+ {
42
+ id: 'id-peter',
43
+ name: 'peter(modify)'
44
+ },
45
+ {
46
+ id: 'id-rosemary',
47
+ name: 'rosemary(modify)'
48
+ },
49
+ {
50
+ id: '',
51
+ name: 'kettle(modify)'
52
+ },
53
+ ]
96
54
 
97
- let rr = { n: 3, nInserted: 3, ok: 1 }
98
55
 
99
- it(`should get ${JSON.stringify(rr)} for insert`, async function() {
56
+ //w
57
+ let w = wo(opt)
100
58
 
101
- let rt = null
102
- await w.insert(rs)
103
- .then(function(msg) {
104
- // console.log('insert then', msg)
105
- // insert then { n: 3, nInserted: 3, ok: 1 }
106
- rt = msg
107
- })
108
- .catch(function(msg) {
109
- // console.log('insert catch', msg)
110
- rt = msg.toString()
111
- })
112
59
 
113
- assert.strict.deepStrictEqual(rt, rr)
60
+ //on
61
+ w.on('change', function(mode, data, res) {
62
+ // console.log('change', mode)
114
63
  })
115
64
 
116
- }
117
65
 
66
+ //delAll
67
+ rt = null
68
+ vans[1] = {
69
+ nDeleted: 2,
70
+ ok: 1,
71
+ }
72
+ await w.delAll()
73
+ .then(function(msg) {
74
+ // console.log('delAll then', msg)
75
+ //考慮可能有不同初始測試數據
76
+ // delAll then { n: 2, nDeleted: 2, ok: 1 }
77
+ // delAll then { n: 3, nDeleted: 2, ok: 1 }
78
+ //僅針對nDeleted與ok欄位比對
79
+ rt = {
80
+ nDeleted: msg.nDeleted,
81
+ ok: msg.ok,
82
+ }
83
+ })
84
+ .catch(function(msg) {
85
+ // console.log('delAll catch', msg)
86
+ rt = msg.toString()
87
+ })
88
+ vget[1] = rt
89
+
90
+
91
+ //insert
92
+ rt = null
93
+ vans[2] = { n: 3, nInserted: 3, ok: 1 }
94
+ await w.insert(rs)
95
+ .then(function(msg) {
96
+ // console.log('insert then', msg)
97
+ // insert then { n: 3, nInserted: 3, ok: 1 }
98
+ rt = msg
99
+ })
100
+ .catch(function(msg) {
101
+ // console.log('insert catch', msg)
102
+ rt = msg.toString()
103
+ })
104
+ vget[2] = rt
118
105
 
119
- //save
120
- if (true) {
121
106
 
122
- let rr = [
107
+ //save
108
+ rt = null
109
+ vans[3] = [
123
110
  { n: 1, nModified: 1, ok: 1 },
124
111
  { n: 1, nModified: 1, ok: 1 },
125
112
  { n: 0, nModified: 0, ok: 1 }
126
113
  ]
114
+ await w.save(rsm, { autoInsert: false, atomic: true })
115
+ .then(function(msg) {
116
+ // console.log('save then', msg)
117
+ // save then [
118
+ // { n: 1, nModified: 1, ok: 1 },
119
+ // { n: 1, nModified: 1, ok: 1 },
120
+ // { n: 0, nModified: 0, ok: 1 }
121
+ // ]
122
+ rt = msg
123
+ })
124
+ .catch(function(msg) {
125
+ // console.log('save catch', msg)
126
+ rt = msg.toString()
127
+ })
128
+ vget[3] = rt
127
129
 
128
- it(`should get ${JSON.stringify(rr)} for save`, async function() {
129
-
130
- let rt = null
131
- await w.save(rsm, { autoInsert: false, atomic: true })
132
- .then(function(msg) {
133
- // console.log('save then', msg)
134
- // save then [
135
- // { n: 1, nModified: 1, ok: 1 },
136
- // { n: 1, nModified: 1, ok: 1 },
137
- // { n: 0, nModified: 0, ok: 1 }
138
- // ]
139
- rt = msg
140
- })
141
- .catch(function(msg) {
142
- // console.log('save catch', msg)
143
- rt = msg.toString()
144
- })
145
-
146
- assert.strict.deepStrictEqual(rt, rr)
147
- })
148
-
149
- }
150
-
151
-
152
- //select all
153
- if (true) {
154
130
 
155
- let rr = [
131
+ //select all
132
+ rt = null
133
+ vans[4] = [
156
134
  { id: 'id-peter', name: 'peter(modify)', value: 123 },
157
135
  { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
158
136
  {
@@ -161,138 +139,102 @@ describe('basic', async function() {
161
139
  value: 456
162
140
  }
163
141
  ]
142
+ await w.select()
143
+ .then(function(msg) {
144
+ // console.log('select all then', msg)
145
+ // select all [
146
+ // { id: 'id-peter', name: 'peter(modify)', value: 123 },
147
+ // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
148
+ // {
149
+ // id: {random id},
150
+ // name: 'kettle',
151
+ // value: 456
152
+ // }
153
+ // ]
154
+ rt = [
155
+ msg[0],
156
+ msg[1],
157
+ {
158
+ name: msg[2].name,
159
+ value: msg[2].value,
160
+ },
161
+ ]
162
+ })
163
+ .catch(function(msg) {
164
+ // console.log('select all catch', msg)
165
+ rt = msg.toString()
166
+ })
167
+ vget[4] = rt
164
168
 
165
- it(`should get ${JSON.stringify(rr)} for select all`, async function() {
166
-
167
- let rt = null
168
- await w.select()
169
- .then(function(msg) {
170
- // console.log('select all then', msg)
171
- // select all [
172
- // { id: 'id-peter', name: 'peter(modify)', value: 123 },
173
- // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
174
- // {
175
- // id: {random id},
176
- // name: 'kettle',
177
- // value: 456
178
- // }
179
- // ]
180
- rt = [
181
- msg[0],
182
- msg[1],
183
- {
184
- name: msg[2].name,
185
- value: msg[2].value,
186
- },
187
- ]
188
- })
189
- .catch(function(msg) {
190
- // console.log('select all catch', msg)
191
- rt = msg.toString()
192
- })
193
-
194
- assert.strict.deepStrictEqual(rt, rr)
195
- })
196
-
197
- }
198
-
199
-
200
- //select
201
- if (true) {
202
-
203
- let rr = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
204
-
205
- it(`should get ${JSON.stringify(rr)} for select`, async function() {
206
-
207
- let rt = null
208
- await w.select({ id: 'id-rosemary' })
209
- .then(function(msg) {
210
- // console.log('select then', msg)
211
- // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
212
- rt = msg
213
- })
214
- .catch(function(msg) {
215
- // console.log('select catch', msg)
216
- rt = msg.toString()
217
- })
218
-
219
- assert.strict.deepStrictEqual(rt, rr)
220
- })
221
-
222
- }
223
-
224
-
225
- //select by $and, $gt, $lt
226
- if (true) {
227
-
228
- let rr = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
229
-
230
- it(`should get ${JSON.stringify(rr)} for select by $and, $gt, $lt`, async function() {
231
-
232
- let rt = null
233
- await w.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
234
- .then(function(msg) {
235
- // console.log('select by $and, $gt, $lt then', msg)
236
- // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
237
- rt = msg
238
- })
239
- .catch(function(msg) {
240
- // console.log('select by $and, $gt, $lt catch', msg)
241
- rt = msg.toString()
242
- })
243
169
 
244
- assert.strict.deepStrictEqual(rt, rr)
245
- })
170
+ //select
171
+ rt = null
172
+ vans[5] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
173
+ await w.select({ id: 'id-rosemary' })
174
+ .then(function(msg) {
175
+ // console.log('select then', msg)
176
+ // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
177
+ rt = msg
178
+ })
179
+ .catch(function(msg) {
180
+ // console.log('select catch', msg)
181
+ rt = msg.toString()
182
+ })
183
+ vget[5] = rt
246
184
 
247
- }
248
185
 
186
+ //select by $and, $gt, $lt
187
+ rt = null
188
+ vans[6] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
189
+ await w.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
190
+ .then(function(msg) {
191
+ // console.log('select by $and, $gt, $lt then', msg)
192
+ // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
193
+ rt = msg
194
+ })
195
+ .catch(function(msg) {
196
+ // console.log('select by $and, $gt, $lt catch', msg)
197
+ rt = msg.toString()
198
+ })
199
+ vget[6] = rt
249
200
 
250
- //select by $or, $gte, $lte
251
- if (true) {
252
201
 
253
- let rr = [
202
+ //select by $or, $gte, $lte
203
+ rt = null
204
+ vans[7] = [
254
205
  {
255
206
  // id: {random id},
256
207
  name: 'kettle',
257
208
  value: 456
258
209
  }
259
210
  ]
211
+ await w.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
212
+ .then(function(msg) {
213
+ // console.log('select by $or, $gte, $lte then', msg)
214
+ // select by $or, $gte, $lte [
215
+ // {
216
+ // id: {random id},
217
+ // name: 'kettle',
218
+ // value: 456
219
+ // }
220
+ // ]
221
+ rt = [
222
+ {
223
+ name: msg[0].name,
224
+ value: msg[0].value,
225
+ },
226
+ ]
227
+ })
228
+ .catch(function(msg) {
229
+ // console.log('select by $or, $gte, $lte catch', msg)
230
+ rt = msg.toString()
231
+ })
232
+ vget[7] = rt
260
233
 
261
- it(`should get ${JSON.stringify(rr)} for select by $or, $gte, $lte`, async function() {
262
-
263
- let rt = null
264
- await w.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
265
- .then(function(msg) {
266
- // console.log('select by $or, $gte, $lte then', msg)
267
- // select by $or, $gte, $lte [
268
- // {
269
- // id: {random id},
270
- // name: 'kettle',
271
- // value: 456
272
- // }
273
- // ]
274
- rt = [
275
- {
276
- name: msg[0].name,
277
- value: msg[0].value,
278
- },
279
- ]
280
- })
281
- .catch(function(msg) {
282
- // console.log('select by $or, $gte, $lte catch', msg)
283
- rt = msg.toString()
284
- })
285
-
286
- assert.strict.deepStrictEqual(rt, rr)
287
- })
288
-
289
- }
290
-
291
-
292
- //select by $or, $and, $ne, $in, $nin
293
- if (true) {
294
234
 
295
- let rr = [
235
+ //select by $or, $and, $ne, $in, $nin
236
+ rt = null
237
+ vans[8] = [
296
238
  {
297
239
  id: 'id-rosemary',
298
240
  name: 'rosemary(modify)',
@@ -304,97 +246,123 @@ describe('basic', async function() {
304
246
  value: 456
305
247
  }
306
248
  ]
249
+ await w.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
250
+ .then(function(msg) {
251
+ // console.log('select by $or, $and, $ne, $in, $nin then', msg)
252
+ // select by $or, $and, $ne, $in, $nin [
253
+ // {
254
+ // id: 'id-rosemary',
255
+ // name: 'rosemary(modify)',
256
+ // value: 123.456
257
+ // },
258
+ // {
259
+ // id: {random id},
260
+ // name: 'kettle',
261
+ // value: 456
262
+ // }
263
+ // ]
264
+ rt = [
265
+ msg[0],
266
+ {
267
+ name: msg[1].name,
268
+ value: msg[1].value,
269
+ },
270
+ ]
271
+ })
272
+ .catch(function(msg) {
273
+ // console.log('select by $or, $and, $ne, $in, $nin catch', msg)
274
+ rt = msg.toString()
275
+ })
276
+ vget[8] = rt
277
+
278
+
279
+ //select by regex
280
+ rt = null
281
+ vans[9] = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
282
+ await w.select({ name: { $regex: 'PeT', $options: '$i' } })
283
+ .then(function(msg) {
284
+ // console.log('select by regex then', msg)
285
+ // selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
286
+ rt = msg
287
+ })
288
+ .catch(function(msg) {
289
+ // console.log('select by regex catch', msg)
290
+ rt = msg.toString()
291
+ })
292
+ vget[9] = rt
293
+
307
294
 
308
- it(`should get ${JSON.stringify(rr)} for select by $or, $and, $ne, $in, $nin`, async function() {
309
-
310
- let rt = null
311
- await w.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
312
- .then(function(msg) {
313
- // console.log('select by $or, $and, $ne, $in, $nin then', msg)
314
- // select by $or, $and, $ne, $in, $nin [
315
- // {
316
- // id: 'id-rosemary',
317
- // name: 'rosemary(modify)',
318
- // value: 123.456
319
- // },
320
- // {
321
- // id: {random id},
322
- // name: 'kettle',
323
- // value: 456
324
- // }
325
- // ]
326
- rt = [
327
- msg[0],
328
- {
329
- name: msg[1].name,
330
- value: msg[1].value,
331
- },
332
- ]
333
- })
334
- .catch(function(msg) {
335
- // console.log('select by $or, $and, $ne, $in, $nin catch', msg)
336
- rt = msg.toString()
337
- })
338
-
339
- assert.strict.deepStrictEqual(rt, rr)
295
+ //del
296
+ rt = null
297
+ vans[10] = [{ n: 1, nDeleted: 1, ok: 1 }]
298
+ let ss = await w.select()
299
+ let d = ss.filter(function(v) {
300
+ return v.name === 'kettle'
340
301
  })
302
+ await w.del(d)
303
+ .then(function(msg) {
304
+ // console.log('del then', msg)
305
+ // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
306
+ rt = msg
307
+ })
308
+ .catch(function(msg) {
309
+ // console.log('del catch', msg)
310
+ rt = msg.toString()
311
+ })
312
+ vget[10] = rt
341
313
 
342
- }
343
314
 
315
+ })
344
316
 
345
- //select by regex
346
- if (true) {
347
317
 
348
- let rr = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
318
+ it(`should get ${JSON.stringify(vans[1])} for delAll`, async function() {
319
+ assert.strict.deepStrictEqual(vget[1], vans[1])
320
+ })
349
321
 
350
- it(`should get ${JSON.stringify(rr)} for select by regex`, async function() {
351
322
 
352
- let rt = null
353
- await w.select({ name: { $regex: 'PeT', $options: '$i' } })
354
- .then(function(msg) {
355
- // console.log('select by regex then', msg)
356
- // selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
357
- rt = msg
358
- })
359
- .catch(function(msg) {
360
- // console.log('select by regex catch', msg)
361
- rt = msg.toString()
362
- })
323
+ it(`should get ${JSON.stringify(vans[2])} for insert`, async function() {
324
+ assert.strict.deepStrictEqual(vget[2], vans[2])
325
+ })
363
326
 
364
- assert.strict.deepStrictEqual(rt, rr)
365
- })
366
327
 
367
- }
328
+ it(`should get ${JSON.stringify(vans[3])} for save`, async function() {
329
+ assert.strict.deepStrictEqual(vget[3], vans[3])
330
+ })
368
331
 
369
332
 
370
- //del
371
- if (true) {
333
+ it(`should get ${JSON.stringify(vans[4])} for select all`, async function() {
334
+ assert.strict.deepStrictEqual(vget[4], vans[4])
335
+ })
372
336
 
373
- let rr = [{ n: 1, nDeleted: 1, ok: 1 }]
374
337
 
375
- it(`should get ${JSON.stringify(rr)} for del`, async function() {
338
+ it(`should get ${JSON.stringify(vans[5])} for select`, async function() {
339
+ assert.strict.deepStrictEqual(vget[5], vans[5])
340
+ })
376
341
 
377
- let ss = await w.select()
378
- let d = ss.filter(function(v) {
379
- return v.name === 'kettle'
380
- })
381
342
 
382
- let rt = null
383
- await w.del(d)
384
- .then(function(msg) {
385
- // console.log('del then', msg)
386
- // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
387
- rt = msg
388
- })
389
- .catch(function(msg) {
390
- // console.log('del catch', msg)
391
- rt = msg.toString()
392
- })
393
-
394
- assert.strict.deepStrictEqual(rt, rr)
395
- })
343
+ it(`should get ${JSON.stringify(vans[6])} for select by $and, $gt, $lt`, async function() {
344
+ assert.strict.deepStrictEqual(vget[6], vans[6])
345
+ })
396
346
 
397
- }
347
+
348
+ it(`should get ${JSON.stringify(vans[7])} for select by $or, $gte, $lte`, async function() {
349
+ assert.strict.deepStrictEqual(vget[7], vans[7])
350
+ })
351
+
352
+
353
+ it(`should get ${JSON.stringify(vans[8])} for select by $or, $and, $ne, $in, $nin`, async function() {
354
+ assert.strict.deepStrictEqual(vget[8], vans[8])
355
+ })
356
+
357
+
358
+ it(`should get ${JSON.stringify(vans[9])} for select by regex`, async function() {
359
+ assert.strict.deepStrictEqual(vget[9], vans[9])
360
+ })
361
+
362
+
363
+ it(`should get ${JSON.stringify(vans[10])} for del`, async function() {
364
+ assert.strict.deepStrictEqual(vget[10], vans[10])
365
+ })
398
366
 
399
367
 
400
368
  })
package/test/gfs.test.mjs CHANGED
@@ -4,109 +4,97 @@ import fs from 'fs'
4
4
  import wo from '../src/WOrmMongodb.mjs'
5
5
 
6
6
 
7
- describe('gfs', async function() {
7
+ describe('gfs', function() {
8
+ let rt = null
9
+ let vans = {}
10
+ let vget = {}
8
11
 
9
12
 
10
- let opt = {
11
- url: 'mongodb://username:password@127.0.0.1:27017',
12
- db: 'worm',
13
- cl: 'usersGfs',
14
- }
13
+ before(async function () {
15
14
 
16
15
 
17
- //w
18
- let w = wo(opt)
19
-
20
-
21
- //on
22
- w.on('change', function(mode, data, res) {
23
- // console.log('change', mode)
24
- })
25
-
26
-
27
- //fn_in, fn_out
28
- let fn_in = path.resolve('../', './_data', 'data(in).dat')
29
- let fn_out = path.resolve('../', './_data', 'data(out).dat')
30
- // console.log('fn_in', fn_in)
31
- // console.log('fn_out', fn_out)
32
-
33
-
34
- //unlinkSync
35
- try {
36
- fs.unlinkSync(fn_out)
37
- }
38
- catch (err) {}
39
-
40
-
41
- //u8a
42
- let b = await fs.readFileSync(fn_in)
43
- let u8a = new Uint8Array(b)
44
- // let u8a = new Uint8Array([66, 97, 115]) //Uint8Array data from nodejs or browser
45
- // console.log('u8a', u8a)
46
-
47
-
48
- //delAllGfs
49
- if (true) {
16
+ let opt = {
17
+ url: 'mongodb://username:password@127.0.0.1:27017',
18
+ db: 'worm',
19
+ cl: 'usersGfs',
20
+ }
50
21
 
51
- let rr = { n: 0, ok: 1 }
52
22
 
53
- it(`should get ${JSON.stringify(rr)} for delAllGfs`, async function() {
23
+ //w
24
+ let w = wo(opt)
54
25
 
55
- let rt = null
56
- await w.delAllGfs()
57
- .then(function(msg) {
58
- // console.log('delAllGfs then', msg)
59
- // delAllGfs then { n: 0, ok: 1 }
60
- rt = msg
61
- })
62
- .catch(function(msg) {
63
- // console.log('delAllGfs catch', msg)
64
- rt = msg.toString()
65
- })
66
26
 
67
- assert.strict.deepStrictEqual(rt, rr)
27
+ //on
28
+ w.on('change', function(mode, data, res) {
29
+ // console.log('change', mode)
68
30
  })
69
31
 
70
- }
71
32
 
33
+ //fn_in, fn_out
34
+ let fn_in = path.resolve('../', './_data', 'data(in).dat')
35
+ let fn_out = path.resolve('../', './_data', 'data(out).dat')
36
+ // console.log('fn_in', fn_in)
37
+ // console.log('fn_out', fn_out)
72
38
 
73
- //insertGfs
74
- if (true) {
75
39
 
76
- let rr = {
40
+ //unlinkSync
41
+ try {
42
+ fs.unlinkSync(fn_out)
43
+ }
44
+ catch (err) {}
45
+
46
+
47
+ //u8a
48
+ let b = await fs.readFileSync(fn_in)
49
+ let u8a = new Uint8Array(b)
50
+ // let u8a = new Uint8Array([66, 97, 115]) //Uint8Array data from nodejs or browser
51
+ // console.log('u8a', u8a)
52
+
53
+
54
+ //delAllGfs
55
+ rt = null
56
+ vans[1] = { n: 0, ok: 1 }
57
+ await w.delAllGfs()
58
+ .then(function(msg) {
59
+ // console.log('delAllGfs then', msg)
60
+ // delAllGfs then { n: 0, ok: 1 }
61
+ rt = msg
62
+ })
63
+ .catch(function(msg) {
64
+ // console.log('delAllGfs catch', msg)
65
+ rt = msg.toString()
66
+ })
67
+ vget[1] = rt
68
+
69
+
70
+ //insertGfs
71
+ let gi = null
72
+ rt = null
73
+ vans[2] = {
77
74
  n: 1,
78
75
  ok: 1,
79
76
  // id: {random id},
80
77
  }
81
-
82
- it(`should get ${JSON.stringify(rr)} for insertGfs`, async function() {
83
-
84
- let rt = null
85
- await w.insertGfs(u8a)
86
- .then(function(msg) {
87
- // console.log('insertGfs then', msg)
88
- // insertGfs { n: 1, ok: 1, id: {random id} }
89
- rt = {
90
- n: msg.n,
91
- ok: msg.ok,
92
- }
93
- })
94
- .catch(function(msg) {
95
- // console.log('insertGfs catch', msg)
96
- rt = msg.toString()
97
- })
98
-
99
- assert.strict.deepStrictEqual(rt, rr)
100
- })
101
-
102
- }
103
- let gi = await w.insertGfs(u8a)
104
-
105
-
106
- //selectGfs
107
- if (true) {
108
-
109
- let rr = [
78
+ await w.insertGfs(u8a)
79
+ .then(function(msg) {
80
+ // console.log('insertGfs then', msg)
81
+ // insertGfs { n: 1, ok: 1, id: {random id} }
82
+ gi = msg
83
+ rt = {
84
+ n: msg.n,
85
+ ok: msg.ok,
86
+ }
87
+ })
88
+ .catch(function(msg) {
89
+ // console.log('insertGfs catch', msg)
90
+ rt = msg.toString()
91
+ })
92
+ vget[2] = rt
93
+
94
+
95
+ //selectGfs
96
+ rt = null
97
+ vans[3] = [
110
98
  0,
111
99
  0,
112
100
  0,
@@ -114,75 +102,81 @@ describe('gfs', async function() {
114
102
  102,
115
103
  47381362,
116
104
  ]
105
+ await w.selectGfs(gi.id)
106
+ .then(function(msg) {
107
+ // console.log('selectGfs then', msg)
108
+ // console.log('msg[0]', msg[0], msg[0] === 0)
109
+ // console.log('msg[1]', msg[1], msg[1] === 0)
110
+ // console.log('msg[2]', msg[2], msg[2] === 0)
111
+ // console.log('msg[3]', msg[3], msg[3] === 24)
112
+ // console.log('msg[4]', msg[4], msg[4] === 102)
113
+ // console.log('msg.length', msg.length, msg.length === 47381362)
114
+ // selectGfs Uint8Array(47381362) [
115
+ // 0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50,
116
+ // 0, 0, 0, 0, 105, 115, 111, 109, 109, 112, 52, 50,
117
+ // 0, 2, 14, 73, 109, 111, 111, 118, 0, 0, 0, 108,
118
+ // 109, 118, 104, 100, 0, 0, 0, 0, 214, 15, 24, 167,
119
+ // 214, 15, 24, 167, 0, 1, 95, 144, 1, 106, 95, 88,
120
+ // 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
121
+ // 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
122
+ // 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
123
+ // 0, 0, 0, 0,
124
+ // ... 47381262 more items
125
+ // ]
126
+ // fs.writeFileSync(fn_out, msg)
127
+ rt = [
128
+ msg[0],
129
+ msg[1],
130
+ msg[2],
131
+ msg[3],
132
+ msg[4],
133
+ msg.length,
134
+ ]
135
+ })
136
+ .catch(function(msg) {
137
+ // console.log('selectGfs catch', msg)
138
+ rt = msg.toString()
139
+ })
140
+ vget[3] = rt
141
+
142
+
143
+ //delGfs
144
+ rt = null
145
+ vans[4] = { n: 1, nDeleted: 1, ok: 1 }
146
+ await w.delGfs(gi.id)
147
+ .then(function(msg) {
148
+ // console.log('delGfs then', msg)
149
+ // delGfs { n: 1, nDeleted: 1, ok: 1 }
150
+ rt = msg
151
+ })
152
+ .catch(function(msg) {
153
+ // console.log('delGfs catch', msg)
154
+ rt = msg.toString()
155
+ })
156
+ vget[4] = rt
117
157
 
118
- it(`should get ${JSON.stringify(rr)} for selectGfs`, async function() {
119
-
120
- let rt = null
121
- await w.selectGfs(gi.id)
122
- .then(function(msg) {
123
- // console.log('selectGfs then', msg)
124
- // console.log('msg[0]', msg[0], msg[0] === 0)
125
- // console.log('msg[1]', msg[1], msg[1] === 0)
126
- // console.log('msg[2]', msg[2], msg[2] === 0)
127
- // console.log('msg[3]', msg[3], msg[3] === 24)
128
- // console.log('msg[4]', msg[4], msg[4] === 102)
129
- // console.log('msg.length', msg.length, msg.length === 47381362)
130
- // selectGfs Uint8Array(47381362) [
131
- // 0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50,
132
- // 0, 0, 0, 0, 105, 115, 111, 109, 109, 112, 52, 50,
133
- // 0, 2, 14, 73, 109, 111, 111, 118, 0, 0, 0, 108,
134
- // 109, 118, 104, 100, 0, 0, 0, 0, 214, 15, 24, 167,
135
- // 214, 15, 24, 167, 0, 1, 95, 144, 1, 106, 95, 88,
136
- // 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
137
- // 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
138
- // 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
139
- // 0, 0, 0, 0,
140
- // ... 47381262 more items
141
- // ]
142
- // fs.writeFileSync(fn_out, msg)
143
- rt = [
144
- msg[0],
145
- msg[1],
146
- msg[2],
147
- msg[3],
148
- msg[4],
149
- msg.length,
150
- ]
151
- })
152
- .catch(function(msg) {
153
- // console.log('selectGfs catch', msg)
154
- rt = msg.toString()
155
- })
156
-
157
- assert.strict.deepStrictEqual(rt, rr)
158
- })
159
158
 
160
- }
159
+ })
161
160
 
162
161
 
163
- //delGfs
164
- if (true) {
162
+ it(`should get ${JSON.stringify(vans[1])} for delAllGfs`, function() {
163
+ assert.strict.deepStrictEqual(vget[1], vans[1])
164
+ })
165
165
 
166
- let rr = { n: 1, nDeleted: 1, ok: 1 }
167
166
 
168
- it(`should get ${JSON.stringify(rr)} for delGfs`, async function() {
167
+ it(`should get ${JSON.stringify(vans[2])} for insertGfs`, async function() {
168
+ assert.strict.deepStrictEqual(vget[2], vans[2])
169
+ })
169
170
 
170
- let rt = null
171
- await w.delGfs(gi.id)
172
- .then(function(msg) {
173
- // console.log('delGfs then', msg)
174
- // delGfs { n: 1, nDeleted: 1, ok: 1 }
175
- rt = msg
176
- })
177
- .catch(function(msg) {
178
- // console.log('delGfs catch', msg)
179
- rt = msg.toString()
180
- })
181
171
 
182
- assert.strict.deepStrictEqual(rt, rr)
183
- })
172
+ it(`should get ${JSON.stringify(vans[3])} for selectGfs`, async function() {
173
+ assert.strict.deepStrictEqual(vget[3], vans[3])
174
+ })
175
+
184
176
 
185
- }
177
+ it(`should get ${JSON.stringify(vans[4])} for delGfs`, async function() {
178
+ assert.strict.deepStrictEqual(vget[4], vans[4])
179
+ })
186
180
 
187
181
 
188
182
  })