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.
- package/.github/workflows/ci-test.yml +1 -1
- package/README.md +1 -1
- package/dist/w-orm-mongodb.umd.js +2 -2
- package/dist/w-orm-mongodb.umd.js.map +1 -1
- package/docs/WOrmMongodb.html +10 -50
- package/docs/WOrmMongodb.mjs.html +16 -41
- package/docs/index.html +1 -1
- package/g-basic.mjs +2 -2
- package/g-gfs.mjs +1 -1
- package/package.json +3 -3
- package/script.txt +18 -0
- package/src/WOrmMongodb.mjs +15 -40
- package/test/basic.test.mjs +332 -324
- package/test/gfs.test.mjs +158 -151
package/test/gfs.test.mjs
CHANGED
|
@@ -4,179 +4,186 @@ import fs from 'fs'
|
|
|
4
4
|
import wo from '../src/WOrmMongodb.mjs'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let vget = {}
|
|
7
|
+
function isWindows() {
|
|
8
|
+
return process.platform === 'win32'
|
|
9
|
+
}
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
if (isWindows()) {
|
|
13
|
+
describe('gfs', function() {
|
|
14
|
+
let rt = null
|
|
15
|
+
let vans = {}
|
|
16
|
+
let vget = {}
|
|
14
17
|
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
url: 'mongodb://username:password@127.0.0.1:27017',
|
|
18
|
-
db: 'worm',
|
|
19
|
-
cl: 'usersGfs',
|
|
20
|
-
}
|
|
19
|
+
before(async function () {
|
|
21
20
|
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let opt = {
|
|
23
|
+
url: 'mongodb://username:password@127.0.0.1:27017',
|
|
24
|
+
db: 'worm',
|
|
25
|
+
cl: 'usersGfs',
|
|
26
|
+
}
|
|
25
27
|
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// console.log('change', mode)
|
|
30
|
-
})
|
|
31
|
-
|
|
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)
|
|
38
|
-
|
|
39
|
-
|
|
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)
|
|
29
|
+
//w
|
|
30
|
+
let w = wo(opt)
|
|
52
31
|
|
|
53
32
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
await w.delAllGfs()
|
|
58
|
-
.then(function(msg) {
|
|
59
|
-
// console.log('delAllGfs then', msg)
|
|
60
|
-
// delAllGfs then { n: 0, ok: 1 }
|
|
61
|
-
rt = msg
|
|
33
|
+
//on
|
|
34
|
+
w.on('change', function(mode, data, res) {
|
|
35
|
+
// console.log('change', mode)
|
|
62
36
|
})
|
|
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] = {
|
|
74
|
-
n: 1,
|
|
75
|
-
ok: 1,
|
|
76
|
-
// id: {random id},
|
|
77
|
-
}
|
|
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] = [
|
|
98
|
-
0,
|
|
99
|
-
0,
|
|
100
|
-
0,
|
|
101
|
-
24,
|
|
102
|
-
102,
|
|
103
|
-
47381362,
|
|
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
37
|
|
|
142
38
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
39
|
+
//fn_in, fn_out
|
|
40
|
+
let fn_in = path.resolve('../', './_data', 'data(in).dat')
|
|
41
|
+
let fn_out = path.resolve('../', './_data', 'data(out).dat')
|
|
42
|
+
// console.log('fn_in', fn_in)
|
|
43
|
+
// console.log('fn_out', fn_out)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
//unlinkSync
|
|
47
|
+
try {
|
|
48
|
+
fs.unlinkSync(fn_out)
|
|
49
|
+
}
|
|
50
|
+
catch (err) {}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
//u8a
|
|
54
|
+
let b = await fs.readFileSync(fn_in)
|
|
55
|
+
let u8a = new Uint8Array(b)
|
|
56
|
+
// let u8a = new Uint8Array([66, 97, 115]) //Uint8Array data from nodejs or browser
|
|
57
|
+
// console.log('u8a', u8a)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
//delAllGfs
|
|
61
|
+
rt = null
|
|
62
|
+
vans[1] = { n: 0, ok: 1 }
|
|
63
|
+
await w.delAllGfs()
|
|
64
|
+
.then(function(msg) {
|
|
65
|
+
// console.log('delAllGfs then', msg)
|
|
66
|
+
// delAllGfs then { n: 0, ok: 1 }
|
|
67
|
+
rt = msg
|
|
68
|
+
})
|
|
69
|
+
.catch(function(msg) {
|
|
70
|
+
// console.log('delAllGfs catch', msg)
|
|
71
|
+
rt = msg.toString()
|
|
72
|
+
})
|
|
73
|
+
vget[1] = rt
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
//insertGfs
|
|
77
|
+
let gi = null
|
|
78
|
+
rt = null
|
|
79
|
+
vans[2] = {
|
|
80
|
+
n: 1,
|
|
81
|
+
ok: 1,
|
|
82
|
+
// id: {random id},
|
|
83
|
+
}
|
|
84
|
+
await w.insertGfs(u8a)
|
|
85
|
+
.then(function(msg) {
|
|
86
|
+
// console.log('insertGfs then', msg)
|
|
87
|
+
// insertGfs { n: 1, ok: 1, id: {random id} }
|
|
88
|
+
gi = msg
|
|
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
|
+
vget[2] = rt
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
//selectGfs
|
|
102
|
+
rt = null
|
|
103
|
+
vans[3] = [
|
|
104
|
+
0,
|
|
105
|
+
0,
|
|
106
|
+
0,
|
|
107
|
+
24,
|
|
108
|
+
102,
|
|
109
|
+
47381362,
|
|
110
|
+
]
|
|
111
|
+
await w.selectGfs(gi.id)
|
|
112
|
+
.then(function(msg) {
|
|
113
|
+
// console.log('selectGfs then', msg)
|
|
114
|
+
// console.log('msg[0]', msg[0], msg[0] === 0)
|
|
115
|
+
// console.log('msg[1]', msg[1], msg[1] === 0)
|
|
116
|
+
// console.log('msg[2]', msg[2], msg[2] === 0)
|
|
117
|
+
// console.log('msg[3]', msg[3], msg[3] === 24)
|
|
118
|
+
// console.log('msg[4]', msg[4], msg[4] === 102)
|
|
119
|
+
// console.log('msg.length', msg.length, msg.length === 47381362)
|
|
120
|
+
// selectGfs Uint8Array(47381362) [
|
|
121
|
+
// 0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50,
|
|
122
|
+
// 0, 0, 0, 0, 105, 115, 111, 109, 109, 112, 52, 50,
|
|
123
|
+
// 0, 2, 14, 73, 109, 111, 111, 118, 0, 0, 0, 108,
|
|
124
|
+
// 109, 118, 104, 100, 0, 0, 0, 0, 214, 15, 24, 167,
|
|
125
|
+
// 214, 15, 24, 167, 0, 1, 95, 144, 1, 106, 95, 88,
|
|
126
|
+
// 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
|
127
|
+
// 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
|
|
128
|
+
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
|
129
|
+
// 0, 0, 0, 0,
|
|
130
|
+
// ... 47381262 more items
|
|
131
|
+
// ]
|
|
132
|
+
// fs.writeFileSync(fn_out, msg)
|
|
133
|
+
rt = [
|
|
134
|
+
msg[0],
|
|
135
|
+
msg[1],
|
|
136
|
+
msg[2],
|
|
137
|
+
msg[3],
|
|
138
|
+
msg[4],
|
|
139
|
+
msg.length,
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
.catch(function(msg) {
|
|
143
|
+
// console.log('selectGfs catch', msg)
|
|
144
|
+
rt = msg.toString()
|
|
145
|
+
})
|
|
146
|
+
vget[3] = rt
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
//delGfs
|
|
150
|
+
rt = null
|
|
151
|
+
vans[4] = { n: 1, nDeleted: 1, ok: 1 }
|
|
152
|
+
await w.delGfs(gi.id)
|
|
153
|
+
.then(function(msg) {
|
|
154
|
+
// console.log('delGfs then', msg)
|
|
155
|
+
// delGfs { n: 1, nDeleted: 1, ok: 1 }
|
|
156
|
+
rt = msg
|
|
157
|
+
})
|
|
158
|
+
.catch(function(msg) {
|
|
159
|
+
// console.log('delGfs catch', msg)
|
|
160
|
+
rt = msg.toString()
|
|
161
|
+
})
|
|
162
|
+
vget[4] = rt
|
|
157
163
|
|
|
158
164
|
|
|
159
|
-
|
|
165
|
+
})
|
|
160
166
|
|
|
161
167
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
it(`should get ${JSON.stringify(vans[1])} for delAllGfs`, function() {
|
|
169
|
+
assert.strict.deepStrictEqual(vget[1], vans[1])
|
|
170
|
+
})
|
|
165
171
|
|
|
166
172
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
it(`should get ${JSON.stringify(vans[2])} for insertGfs`, async function() {
|
|
174
|
+
assert.strict.deepStrictEqual(vget[2], vans[2])
|
|
175
|
+
})
|
|
170
176
|
|
|
171
177
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
it(`should get ${JSON.stringify(vans[3])} for selectGfs`, async function() {
|
|
179
|
+
assert.strict.deepStrictEqual(vget[3], vans[3])
|
|
180
|
+
})
|
|
175
181
|
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
it(`should get ${JSON.stringify(vans[4])} for delGfs`, async function() {
|
|
184
|
+
assert.strict.deepStrictEqual(vget[4], vans[4])
|
|
185
|
+
})
|
|
180
186
|
|
|
181
187
|
|
|
182
|
-
})
|
|
188
|
+
})
|
|
189
|
+
}
|