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