@mblaney/holster 1.0.35 → 2.0.0
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/build/holster.js +3 -3
- package/build/holster.js.map +3 -3
- package/dist/holster.js +4 -0
- package/dist/holster.js.map +7 -0
- package/package.json +22 -5
- package/src/dup.js +4 -5
- package/src/get.js +10 -19
- package/src/ham.js +22 -49
- package/src/holster.js +172 -58
- package/src/index.js +1 -1
- package/src/radisk.js +89 -86
- package/src/sea-utils.js +1 -1
- package/src/sea.js +0 -52
- package/src/store.js +8 -8
- package/src/user.js +0 -4
- package/src/wire.js +209 -79
- package/ts/src/array.ts +78 -0
- package/ts/src/buffer.ts +441 -0
- package/ts/src/dup.ts +38 -0
- package/ts/src/get.ts +83 -0
- package/ts/src/ham.ts +258 -0
- package/ts/src/holster.ts +968 -0
- package/ts/src/index.ts +35 -0
- package/ts/src/radisk.ts +591 -0
- package/ts/src/radix.ts +157 -0
- package/ts/src/schemas.ts +515 -0
- package/ts/src/sea-utils.ts +103 -0
- package/ts/src/sea.ts +388 -0
- package/ts/src/store.ts +321 -0
- package/ts/src/user.ts +377 -0
- package/ts/src/utils.ts +232 -0
- package/ts/src/wire.ts +961 -0
- package/.dockerignore +0 -9
- package/.github/workflows/node.js.yml +0 -31
- package/.github/workflows/npm-publish.yml +0 -33
- package/Dockerfile +0 -20
- package/examples/index.html +0 -33
- package/examples/index.js +0 -49
- package/examples/user.html +0 -31
- package/examples/user.js +0 -93
- package/examples/wire.html +0 -27
- package/examples/wire.js +0 -55
- package/test/holster.get.test.js +0 -94
- package/test/holster.lex.test.js +0 -196
- package/test/holster.off.test.js +0 -53
- package/test/holster.on.test.js +0 -264
- package/test/holster.put.test.js +0 -358
- package/test/holster.secure.test.js +0 -202
- package/test/holster.user.get.test.js +0 -114
- package/test/holster.user.lex.test.js +0 -149
- package/test/holster.user.off.test.js +0 -73
- package/test/holster.user.on.test.js +0 -300
- package/test/holster.user.put.test.js +0 -463
- package/test/kitty/! +0 -9
- package/test/names.js +0 -225
- package/test/radisk.cache.test.js +0 -213
- package/test/radisk.test.js +0 -331
- package/test/radix.test.js +0 -117
- package/test/sea.test.js +0 -284
- package/test/split.test.js +0 -317
- package/test/store.test.js +0 -316
- package/test/system/basic.test.js +0 -29
- package/test/system/chained-on.test.js +0 -41
- package/test/system/concurrent-listeners.test.js +0 -125
- package/test/system/immediate-read.test.js +0 -30
- package/test/system/listener-before-data.test.js +0 -51
- package/test/system/promise-wrapper.test.js +0 -47
- package/test/system/user-chained-on.test.js +0 -60
- package/test/system/user-concurrent-listeners.test.js +0 -142
- package/test/system/user-listener-before-data.test.js +0 -66
- package/test/user.test.js +0 -173
- package/test/wire.test.js +0 -158
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import {describe, test} from "node:test"
|
|
2
|
-
import assert from "node:assert/strict"
|
|
3
|
-
import Radisk from "../src/radisk.js"
|
|
4
|
-
|
|
5
|
-
describe("radisk with cache", () => {
|
|
6
|
-
const puts = {}
|
|
7
|
-
const opt = {
|
|
8
|
-
write: 1,
|
|
9
|
-
batch: 2,
|
|
10
|
-
size: 100,
|
|
11
|
-
cache: true,
|
|
12
|
-
store: {
|
|
13
|
-
get: (file, cb) => {
|
|
14
|
-
cb(null, puts[file])
|
|
15
|
-
},
|
|
16
|
-
put: (file, data, cb) => {
|
|
17
|
-
puts[file] = data
|
|
18
|
-
cb(null)
|
|
19
|
-
},
|
|
20
|
-
list: cb => {
|
|
21
|
-
Object.keys(puts).sort().forEach(cb)
|
|
22
|
-
cb(null)
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
const radisk = Radisk(opt)
|
|
27
|
-
const big =
|
|
28
|
-
"file size is only 100 bytes so writing this value requires calling slice"
|
|
29
|
-
|
|
30
|
-
test("write and read from memory with cache", (t, done) => {
|
|
31
|
-
radisk("key", "value", () => {})
|
|
32
|
-
|
|
33
|
-
// Reading after write means radisk.batch is still available.
|
|
34
|
-
radisk("key", (err, value) => {
|
|
35
|
-
assert.equal(value, "value")
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test("read from store with cache", (t, done) => {
|
|
41
|
-
// Waiting until after opt.write means radisk.batch has been reset, so a
|
|
42
|
-
// call to radisk.read is required which means the file needs to be parsed.
|
|
43
|
-
setTimeout(() => {
|
|
44
|
-
radisk("key", (err, value) => {
|
|
45
|
-
assert.equal(value, "value")
|
|
46
|
-
done()
|
|
47
|
-
})
|
|
48
|
-
}, opt.write + 1)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test("write and read value with state and cache", (t, done) => {
|
|
52
|
-
radisk("key", ["value", 1234])
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
radisk("key", (err, value) => {
|
|
55
|
-
assert.deepEqual(value, ["value", 1234])
|
|
56
|
-
done()
|
|
57
|
-
})
|
|
58
|
-
}, 10)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test("write and read a plain object with cache", (t, done) => {
|
|
62
|
-
radisk("key", {object: true})
|
|
63
|
-
setTimeout(() => {
|
|
64
|
-
radisk("key", (err, value) => {
|
|
65
|
-
// With cache enabled, we get the actual object back from memory
|
|
66
|
-
assert.deepEqual(value, {object: true})
|
|
67
|
-
done()
|
|
68
|
-
})
|
|
69
|
-
}, 10)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test("write a plain object with state and cache", (t, done) => {
|
|
73
|
-
radisk("key", [{object: true}, 1234])
|
|
74
|
-
setTimeout(() => {
|
|
75
|
-
radisk("key", (err, value) => {
|
|
76
|
-
// With cache enabled, we get the actual object back from memory
|
|
77
|
-
assert.deepEqual(value, [{object: true}, 1234])
|
|
78
|
-
done()
|
|
79
|
-
})
|
|
80
|
-
}, 10)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test("write and read a soul relation with cache", (t, done) => {
|
|
84
|
-
const rel = {"#": "soul"}
|
|
85
|
-
radisk("key", rel)
|
|
86
|
-
setTimeout(() => {
|
|
87
|
-
radisk("key", (err, value) => {
|
|
88
|
-
assert.deepEqual(value, rel)
|
|
89
|
-
done()
|
|
90
|
-
})
|
|
91
|
-
}, 10)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
test("write and read a soul relation with state and cache", (t, done) => {
|
|
95
|
-
const rel = [{"#": "soul"}, 1234]
|
|
96
|
-
radisk("key", rel)
|
|
97
|
-
setTimeout(() => {
|
|
98
|
-
radisk("key", (err, value) => {
|
|
99
|
-
assert.deepEqual(value, rel)
|
|
100
|
-
done()
|
|
101
|
-
})
|
|
102
|
-
}, 10)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test("write and read value with newline and cache", (t, done) => {
|
|
106
|
-
radisk("key", "value\ncontinued")
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
radisk("key", (err, value) => {
|
|
109
|
-
assert.equal(value, "value\ncontinued")
|
|
110
|
-
done()
|
|
111
|
-
})
|
|
112
|
-
}, 10)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test("write and read value with newline and state and cache", (t, done) => {
|
|
116
|
-
radisk("key", ["value\ncontinued", 12345])
|
|
117
|
-
setTimeout(() => {
|
|
118
|
-
radisk("key", (err, value) => {
|
|
119
|
-
assert.deepEqual(value, ["value\ncontinued", 12345])
|
|
120
|
-
done()
|
|
121
|
-
})
|
|
122
|
-
}, 10)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
test("write more than batch size with cache", (t, done) => {
|
|
126
|
-
radisk("keyA", "valueA")
|
|
127
|
-
radisk("keyB", "valueB")
|
|
128
|
-
radisk("keyC", "valueC")
|
|
129
|
-
setTimeout(() => {
|
|
130
|
-
radisk("keyA", (err, value) => {
|
|
131
|
-
assert.equal(value, "valueA")
|
|
132
|
-
done()
|
|
133
|
-
})
|
|
134
|
-
}, 10)
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
test("write and read value bigger than file size with cache", (t, done) => {
|
|
138
|
-
radisk("newFile", big)
|
|
139
|
-
radisk("newFile", (err, value) => {
|
|
140
|
-
assert.equal(value, big)
|
|
141
|
-
})
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
radisk("newFile", (err, value) => {
|
|
144
|
-
assert.equal(value, big)
|
|
145
|
-
done()
|
|
146
|
-
})
|
|
147
|
-
}, 10)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
test("write and read a small value after split with cache", (t, done) => {
|
|
151
|
-
radisk("small", "small value")
|
|
152
|
-
radisk("small", (err, value) => {
|
|
153
|
-
assert.equal(value, "small value")
|
|
154
|
-
})
|
|
155
|
-
setTimeout(() => {
|
|
156
|
-
done()
|
|
157
|
-
}, 10)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test("write small value to newFile with cache", (t, done) => {
|
|
161
|
-
radisk("newFile", "removed...")
|
|
162
|
-
radisk("newFile", (err, value) => {
|
|
163
|
-
assert.equal(value, "removed...")
|
|
164
|
-
})
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
done()
|
|
167
|
-
}, 10)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
test("write big value to first file with cache", (t, done) => {
|
|
171
|
-
radisk("keyA", big)
|
|
172
|
-
radisk("keyA", (err, value) => {
|
|
173
|
-
assert.equal(value, big)
|
|
174
|
-
done()
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
test.skip("add to last file with cache", (t, done) => {
|
|
179
|
-
// Skip: This test exercises a complex edge case in file splitting
|
|
180
|
-
// that behaves differently with caching enabled
|
|
181
|
-
radisk("smallContinued", "continued value")
|
|
182
|
-
setTimeout(() => {
|
|
183
|
-
radisk("smallContinued", (err, value) => {
|
|
184
|
-
assert.equal(value, "continued value")
|
|
185
|
-
done()
|
|
186
|
-
})
|
|
187
|
-
}, 10)
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
test("set a key to null and add a value to that file with cache", (t, done) => {
|
|
191
|
-
radisk("keyC", null)
|
|
192
|
-
radisk("keyC", (err, value) => {
|
|
193
|
-
assert.equal(value, null)
|
|
194
|
-
})
|
|
195
|
-
radisk("keyD", "valueD")
|
|
196
|
-
radisk("keyD", (err, value) => {
|
|
197
|
-
assert.equal(value, "valueD")
|
|
198
|
-
done()
|
|
199
|
-
})
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
test("set first keys to null with cache", (t, done) => {
|
|
203
|
-
radisk("key", null)
|
|
204
|
-
radisk("key", (err, value) => {
|
|
205
|
-
assert.equal(value, null)
|
|
206
|
-
})
|
|
207
|
-
radisk("keyA", null)
|
|
208
|
-
radisk("keyA", (err, value) => {
|
|
209
|
-
assert.equal(value, null)
|
|
210
|
-
done()
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
})
|
package/test/radisk.test.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import {describe, test} from "node:test"
|
|
2
|
-
import assert from "node:assert/strict"
|
|
3
|
-
import Radisk from "../src/radisk.js"
|
|
4
|
-
|
|
5
|
-
describe("radisk", () => {
|
|
6
|
-
const puts = {}
|
|
7
|
-
const opt = {
|
|
8
|
-
write: 1,
|
|
9
|
-
batch: 2,
|
|
10
|
-
size: 100,
|
|
11
|
-
cache: false,
|
|
12
|
-
store: {
|
|
13
|
-
get: (file, cb) => {
|
|
14
|
-
cb(null, puts[file])
|
|
15
|
-
},
|
|
16
|
-
put: (file, data, cb) => {
|
|
17
|
-
puts[file] = data
|
|
18
|
-
cb(null)
|
|
19
|
-
},
|
|
20
|
-
list: cb => {
|
|
21
|
-
Object.keys(puts).sort().forEach(cb)
|
|
22
|
-
cb(null)
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
const radisk = Radisk(opt)
|
|
27
|
-
const big =
|
|
28
|
-
"file size is only 100 bytes so writing this value requires calling slice"
|
|
29
|
-
|
|
30
|
-
test("write and read from memory", (t, done) => {
|
|
31
|
-
radisk("key", "value", () => {
|
|
32
|
-
assert.deepEqual(puts, {"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\x1F\n'})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
// Reading after write means radisk.batch is still available.
|
|
36
|
-
radisk("key", (err, value) => {
|
|
37
|
-
assert.equal(value, "value")
|
|
38
|
-
done()
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test("read from store", (t, done) => {
|
|
43
|
-
// Waiting until after opt.write means radisk.batch has been reset, so a
|
|
44
|
-
// call to radisk.read is required which means the file needs to be parsed.
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
radisk("key", (err, value) => {
|
|
47
|
-
assert.equal(value, "value")
|
|
48
|
-
done()
|
|
49
|
-
})
|
|
50
|
-
}, opt.write + 1)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test("write and read value with state", (t, done) => {
|
|
54
|
-
radisk("key", ["value", 1234])
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
assert.deepEqual(puts, {
|
|
57
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\x031234\x1F\n',
|
|
58
|
-
})
|
|
59
|
-
radisk("key", (err, value) => {
|
|
60
|
-
assert.deepEqual(value, ["value", 1234])
|
|
61
|
-
done()
|
|
62
|
-
})
|
|
63
|
-
}, 10)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test("write and read a plain object is undefined", (t, done) => {
|
|
67
|
-
radisk("key", {object: true})
|
|
68
|
-
setTimeout(() => {
|
|
69
|
-
assert.deepEqual(puts, {
|
|
70
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=undefined\n',
|
|
71
|
-
})
|
|
72
|
-
radisk("key", (err, value) => {
|
|
73
|
-
assert.deepEqual(value, undefined)
|
|
74
|
-
done()
|
|
75
|
-
})
|
|
76
|
-
}, 10)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test("write a plain object with state is also undefined", (t, done) => {
|
|
80
|
-
radisk("key", [{object: true}, 1234])
|
|
81
|
-
setTimeout(() => {
|
|
82
|
-
assert.deepEqual(puts, {
|
|
83
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=undefined\n',
|
|
84
|
-
})
|
|
85
|
-
radisk("key", (err, value) => {
|
|
86
|
-
assert.deepEqual(value, undefined)
|
|
87
|
-
done()
|
|
88
|
-
})
|
|
89
|
-
}, 10)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test("write and read a soul relation is ok", (t, done) => {
|
|
93
|
-
const rel = {"#": "soul"}
|
|
94
|
-
radisk("key", rel)
|
|
95
|
-
setTimeout(() => {
|
|
96
|
-
assert.deepEqual(puts, {
|
|
97
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F#soul\x1F\n',
|
|
98
|
-
})
|
|
99
|
-
radisk("key", (err, value) => {
|
|
100
|
-
assert.deepEqual(value, rel)
|
|
101
|
-
done()
|
|
102
|
-
})
|
|
103
|
-
}, 10)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test("write and read a soul relation with state is ok", (t, done) => {
|
|
107
|
-
const rel = [{"#": "soul"}, 1234]
|
|
108
|
-
radisk("key", rel)
|
|
109
|
-
setTimeout(() => {
|
|
110
|
-
assert.deepEqual(puts, {
|
|
111
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F#soul\x031234\x1F\n',
|
|
112
|
-
})
|
|
113
|
-
radisk("key", (err, value) => {
|
|
114
|
-
assert.deepEqual(value, rel)
|
|
115
|
-
done()
|
|
116
|
-
})
|
|
117
|
-
}, 10)
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
test("write and read value with newline", (t, done) => {
|
|
121
|
-
radisk("key", "value\ncontinued")
|
|
122
|
-
setTimeout(() => {
|
|
123
|
-
assert.deepEqual(puts, {
|
|
124
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x1F\n',
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
radisk("key", (err, value) => {
|
|
128
|
-
assert.equal(value, "value\ncontinued")
|
|
129
|
-
done()
|
|
130
|
-
})
|
|
131
|
-
}, 10)
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
test("write and read value with newline and state", (t, done) => {
|
|
135
|
-
radisk("key", ["value\ncontinued", 12345])
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
assert.deepEqual(puts, {
|
|
138
|
-
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n',
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
radisk("key", (err, value) => {
|
|
142
|
-
assert.deepEqual(value, ["value\ncontinued", 12345])
|
|
143
|
-
done()
|
|
144
|
-
})
|
|
145
|
-
}, 10)
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
test("write more than batch size", (t, done) => {
|
|
149
|
-
radisk("keyA", "valueA")
|
|
150
|
-
radisk("keyB", "valueB")
|
|
151
|
-
radisk("keyC", "valueC")
|
|
152
|
-
setTimeout(() => {
|
|
153
|
-
assert.deepEqual(puts, {
|
|
154
|
-
"!":
|
|
155
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
156
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"valueA\x1F\n' +
|
|
157
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
158
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
159
|
-
})
|
|
160
|
-
radisk("keyA", (err, value) => {
|
|
161
|
-
assert.equal(value, "valueA")
|
|
162
|
-
done()
|
|
163
|
-
})
|
|
164
|
-
}, 10)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
test("write and read value bigger than file size", (t, done) => {
|
|
168
|
-
radisk("newFile", big)
|
|
169
|
-
radisk("newFile", (err, value) => {
|
|
170
|
-
assert.equal(value, big)
|
|
171
|
-
})
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
assert.deepEqual(puts, {
|
|
174
|
-
"!":
|
|
175
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
176
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"valueA\x1F\n' +
|
|
177
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
178
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
179
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"' + big + "\x1F\n",
|
|
180
|
-
})
|
|
181
|
-
radisk("newFile", (err, value) => {
|
|
182
|
-
assert.equal(value, big)
|
|
183
|
-
done()
|
|
184
|
-
})
|
|
185
|
-
}, 10)
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
// This tests trying to add to a file that is already too long, so needs to
|
|
189
|
-
// split again. Previously wasn't able to do this and would loop.
|
|
190
|
-
test("write and read a small value after split", (t, done) => {
|
|
191
|
-
radisk("small", "small value")
|
|
192
|
-
radisk("small", (err, value) => {
|
|
193
|
-
assert.equal(value, "small value")
|
|
194
|
-
})
|
|
195
|
-
setTimeout(() => {
|
|
196
|
-
assert.deepEqual(puts, {
|
|
197
|
-
"!":
|
|
198
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
199
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"valueA\x1F\n' +
|
|
200
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
201
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
202
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"' + big + "\x1F\n",
|
|
203
|
-
small: '\x1F+0\x1F#\x1F"small\x1F=\x1F"small value\x1F\n',
|
|
204
|
-
})
|
|
205
|
-
done()
|
|
206
|
-
}, 10)
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
// This tests how existing files are handled when they are made smaller than
|
|
210
|
-
// the maximum file size. (They should be kept as they are created so that
|
|
211
|
-
// we don't have to deal with removing files.)
|
|
212
|
-
test("write small value to newFile", (t, done) => {
|
|
213
|
-
radisk("newFile", "removed...")
|
|
214
|
-
radisk("newFile", (err, value) => {
|
|
215
|
-
assert.equal(value, "removed...")
|
|
216
|
-
})
|
|
217
|
-
setTimeout(() => {
|
|
218
|
-
assert.deepEqual(puts, {
|
|
219
|
-
"!":
|
|
220
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
221
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"valueA\x1F\n' +
|
|
222
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
223
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
224
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"removed...\x1F\n',
|
|
225
|
-
small: '\x1F+0\x1F#\x1F"small\x1F=\x1F"small value\x1F\n',
|
|
226
|
-
})
|
|
227
|
-
done()
|
|
228
|
-
}, 10)
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
// This tests ignoring the maximum file size when writing sub-keys. Since
|
|
232
|
-
// radisk.write has already been called for a key it would previously get
|
|
233
|
-
// duplicated when trying to split due to reaching the max length.
|
|
234
|
-
test("write big value to first file", (t, done) => {
|
|
235
|
-
radisk("keyA", big)
|
|
236
|
-
radisk("keyA", (err, value) => {
|
|
237
|
-
assert.equal(value, big)
|
|
238
|
-
})
|
|
239
|
-
setTimeout(() => {
|
|
240
|
-
assert.deepEqual(puts, {
|
|
241
|
-
"!":
|
|
242
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
243
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"' +
|
|
244
|
-
big +
|
|
245
|
-
"\x1F\n" +
|
|
246
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
247
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
248
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"removed...\x1F\n',
|
|
249
|
-
small: '\x1F+0\x1F#\x1F"small\x1F=\x1F"small value\x1F\n',
|
|
250
|
-
})
|
|
251
|
-
done()
|
|
252
|
-
}, 10)
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
test("add to last file", (t, done) => {
|
|
256
|
-
radisk("smallContinued", "continued value")
|
|
257
|
-
radisk("smallContinued", (err, value) => {
|
|
258
|
-
assert.equal(value, "continued value")
|
|
259
|
-
})
|
|
260
|
-
setTimeout(() => {
|
|
261
|
-
assert.deepEqual(puts, {
|
|
262
|
-
"!":
|
|
263
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
264
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"' +
|
|
265
|
-
big +
|
|
266
|
-
"\x1F\n" +
|
|
267
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
268
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
269
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"removed...\x1F\n',
|
|
270
|
-
small:
|
|
271
|
-
'\x1F+0\x1F#\x1F"small\x1F=\x1F"small value\x1F\n' +
|
|
272
|
-
'\x1F+1\x1F#\x1F"Continued\x1F=\x1F"continued value\x1F\n',
|
|
273
|
-
})
|
|
274
|
-
done()
|
|
275
|
-
}, 10)
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
test("set a key to null and add a value to that file", (t, done) => {
|
|
279
|
-
radisk("keyC", null)
|
|
280
|
-
radisk("keyC", (err, value) => {
|
|
281
|
-
assert.equal(value, null)
|
|
282
|
-
})
|
|
283
|
-
radisk("keyD", "valueD")
|
|
284
|
-
radisk("keyD", (err, value) => {
|
|
285
|
-
assert.equal(value, "valueD")
|
|
286
|
-
})
|
|
287
|
-
setTimeout(() => {
|
|
288
|
-
assert.deepEqual(puts, {
|
|
289
|
-
"!":
|
|
290
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
291
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F"' +
|
|
292
|
-
big +
|
|
293
|
-
"\x1F\n" +
|
|
294
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
295
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F \x1F\n' +
|
|
296
|
-
'\x1F+1\x1F#\x1F"D\x1F=\x1F"valueD\x1F\n',
|
|
297
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"removed...\x1F\n',
|
|
298
|
-
small:
|
|
299
|
-
'\x1F+0\x1F#\x1F"small\x1F=\x1F"small value\x1F\n' +
|
|
300
|
-
'\x1F+1\x1F#\x1F"Continued\x1F=\x1F"continued value\x1F\n',
|
|
301
|
-
})
|
|
302
|
-
done()
|
|
303
|
-
}, 10)
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
test("set first keys to null", (t, done) => {
|
|
307
|
-
radisk("key", null)
|
|
308
|
-
radisk("key", (err, value) => {
|
|
309
|
-
assert.equal(value, null)
|
|
310
|
-
})
|
|
311
|
-
radisk("keyA", null)
|
|
312
|
-
radisk("keyA", (err, value) => {
|
|
313
|
-
assert.equal(value, null)
|
|
314
|
-
})
|
|
315
|
-
setTimeout(() => {
|
|
316
|
-
assert.deepEqual(puts, {
|
|
317
|
-
"!":
|
|
318
|
-
'\x1F+0\x1F#\x1F"key\x1F=\x1F \x1F\n' +
|
|
319
|
-
'\x1F+1\x1F#\x1F"A\x1F=\x1F \x1F\n' +
|
|
320
|
-
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
321
|
-
'\x1F+1\x1F#\x1F"C\x1F=\x1F \x1F\n' +
|
|
322
|
-
'\x1F+1\x1F#\x1F"D\x1F=\x1F"valueD\x1F\n',
|
|
323
|
-
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"removed...\x1F\n',
|
|
324
|
-
small:
|
|
325
|
-
'\x1F+0\x1F#\x1F"small\x1F=\x1F"small value\x1F\n' +
|
|
326
|
-
'\x1F+1\x1F#\x1F"Continued\x1F=\x1F"continued value\x1F\n',
|
|
327
|
-
})
|
|
328
|
-
done()
|
|
329
|
-
}, 10)
|
|
330
|
-
})
|
|
331
|
-
})
|
package/test/radix.test.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import {describe, test} from "node:test"
|
|
2
|
-
import assert from "node:assert/strict"
|
|
3
|
-
import Radix from "../src/radix.js"
|
|
4
|
-
import Names from "./names.js"
|
|
5
|
-
const names = Names()
|
|
6
|
-
|
|
7
|
-
// ASCII character for group separator.
|
|
8
|
-
const group = String.fromCharCode(29)
|
|
9
|
-
// ASCII character for record separator.
|
|
10
|
-
const record = String.fromCharCode(30)
|
|
11
|
-
|
|
12
|
-
describe("radix", () => {
|
|
13
|
-
const radix = Radix()
|
|
14
|
-
|
|
15
|
-
test("unit", () => {
|
|
16
|
-
radix("asdf.pub", "yum")
|
|
17
|
-
radix("ablah", "cool")
|
|
18
|
-
radix("abc", {yes: 1})
|
|
19
|
-
radix("node/circle.bob", "awesome")
|
|
20
|
-
|
|
21
|
-
assert.deepEqual(radix("asdf."), {pub: {[record]: "yum"}})
|
|
22
|
-
assert.equal(radix("nv/foo.bar"), undefined)
|
|
23
|
-
assert.equal(radix("ablah"), "cool")
|
|
24
|
-
assert.deepEqual(radix("abc"), {yes: 1})
|
|
25
|
-
assert.equal(radix("abcd"), undefined)
|
|
26
|
-
assert.deepEqual(radix(), {
|
|
27
|
-
a: {
|
|
28
|
-
[group]: {
|
|
29
|
-
"sdf.pub": {[record]: "yum"},
|
|
30
|
-
b: {
|
|
31
|
-
[group]: {
|
|
32
|
-
c: {
|
|
33
|
-
[record]: {
|
|
34
|
-
yes: 1,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
lah: {
|
|
38
|
-
[record]: "cool",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
"node/circle.bob": {[record]: "awesome"},
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test("replace", () => {
|
|
49
|
-
radix("asdf.pub", "yuck")
|
|
50
|
-
radix("ablah", "cool!")
|
|
51
|
-
radix("abc", {yes: 2})
|
|
52
|
-
radix("node/circle.bob", "awe")
|
|
53
|
-
radix("abcd", true)
|
|
54
|
-
|
|
55
|
-
assert.deepEqual(radix("asdf."), {pub: {[record]: "yuck"}})
|
|
56
|
-
assert.equal(radix("ablah"), "cool!")
|
|
57
|
-
assert.equal(radix("nv/foo.bar"), undefined)
|
|
58
|
-
assert.deepEqual(radix("abc"), {yes: 2})
|
|
59
|
-
assert.equal(radix("abcd"), true)
|
|
60
|
-
assert.deepEqual(radix(), {
|
|
61
|
-
a: {
|
|
62
|
-
[group]: {
|
|
63
|
-
"sdf.pub": {[record]: "yuck"},
|
|
64
|
-
b: {
|
|
65
|
-
[group]: {
|
|
66
|
-
c: {
|
|
67
|
-
[group]: {
|
|
68
|
-
d: {
|
|
69
|
-
[record]: true,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
[record]: {
|
|
73
|
-
yes: 2,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
lah: {
|
|
77
|
-
[record]: "cool!",
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
"node/circle.bob": {[record]: "awe"},
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test("radix write read", () => {
|
|
88
|
-
// Add some shorter values to also force group matching in Radix.map.
|
|
89
|
-
radix("A", 1)
|
|
90
|
-
radix("Be", 2)
|
|
91
|
-
radix("Bo", 3)
|
|
92
|
-
radix("L", 4)
|
|
93
|
-
radix("Mi", 5)
|
|
94
|
-
var all = {}
|
|
95
|
-
names.forEach((value, index) => {
|
|
96
|
-
all[value] = index
|
|
97
|
-
radix(value, index)
|
|
98
|
-
})
|
|
99
|
-
assert.equal(Object.keys(all).length, names.length)
|
|
100
|
-
Radix.map(radix, (value, key) => {
|
|
101
|
-
delete all[key]
|
|
102
|
-
})
|
|
103
|
-
assert.equal(Object.keys(all).length, 0)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test("radix read again", () => {
|
|
107
|
-
var all = {}
|
|
108
|
-
names.forEach((value, index) => {
|
|
109
|
-
all[value] = index
|
|
110
|
-
})
|
|
111
|
-
assert.equal(Object.keys(all).length, names.length)
|
|
112
|
-
Radix.map(radix, (value, key) => {
|
|
113
|
-
delete all[key]
|
|
114
|
-
})
|
|
115
|
-
assert.equal(Object.keys(all).length, 0)
|
|
116
|
-
})
|
|
117
|
-
})
|