w-orm-mongodb 1.1.28 → 1.1.30
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/.eslintrc.js +1 -0
- package/.github/workflows/ci-test.yml +1 -1
- package/README.md +1 -0
- package/dist/w-orm-mongodb.umd.js +2 -2
- package/dist/w-orm-mongodb.umd.js.map +1 -1
- package/docs/WOrmMongodb.html +9 -9
- package/docs/WOrmMongodb.mjs.html +30 -21
- package/docs/index.html +1 -1
- package/package.json +5 -5
- package/src/WOrmMongodb.mjs +29 -20
- package/test/basic.test.mjs +288 -320
- package/test/gfs.test.mjs +140 -146
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',
|
|
7
|
+
describe('gfs', function() {
|
|
8
|
+
let rt = null
|
|
9
|
+
let vans = {}
|
|
10
|
+
let vget = {}
|
|
8
11
|
|
|
9
12
|
|
|
10
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
})
|