@mblaney/holster 1.0.4 → 1.0.6
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/package.json +1 -1
- package/src/holster.js +78 -70
- package/src/radisk.js +23 -50
- package/src/wire.js +2 -8
- package/test/radisk.test.js +14 -18
- package/test/split.test.js +317 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import {describe, test} from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import Radisk from "../src/radisk.js"
|
|
4
|
+
|
|
5
|
+
// ASCII character for enquiry.
|
|
6
|
+
const enq = String.fromCharCode(5)
|
|
7
|
+
|
|
8
|
+
describe("split", () => {
|
|
9
|
+
const puts = {}
|
|
10
|
+
const opt = {
|
|
11
|
+
size: 100,
|
|
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 now = Date.now()
|
|
28
|
+
const lorem =
|
|
29
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
|
30
|
+
const parent = () => {
|
|
31
|
+
return (
|
|
32
|
+
'\x1F+0\x1F#\x1F"parent\x05\x1F\n' +
|
|
33
|
+
'\x1F+1\x1F#\x1F"boolean\x1F=\x1F+\x03' +
|
|
34
|
+
now +
|
|
35
|
+
"\x1F\n" +
|
|
36
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+42\x03' +
|
|
37
|
+
now +
|
|
38
|
+
"\x1F\n" +
|
|
39
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#child\x03' +
|
|
40
|
+
now +
|
|
41
|
+
"\x1F\n" +
|
|
42
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"parent value\x03' +
|
|
43
|
+
now +
|
|
44
|
+
"\x1F\n"
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
const child = () => {
|
|
48
|
+
return (
|
|
49
|
+
'\x1F+0\x1F#\x1F"child\x05\x1F\n' +
|
|
50
|
+
'\x1F+1\x1F#\x1F"boolean\x1F=\x1F+\x03' +
|
|
51
|
+
now +
|
|
52
|
+
"\x1F\n" +
|
|
53
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+43\x03' +
|
|
54
|
+
now +
|
|
55
|
+
"\x1F\n" +
|
|
56
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#grandchild\x03' +
|
|
57
|
+
now +
|
|
58
|
+
"\x1F\n" +
|
|
59
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"child value\x03' +
|
|
60
|
+
now +
|
|
61
|
+
"\x1F\n"
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
const grandchild = () => {
|
|
65
|
+
return (
|
|
66
|
+
'\x1F+0\x1F#\x1F"grandchild\x05\x1F\n' +
|
|
67
|
+
'\x1F+1\x1F#\x1F"boolean\x1F=\x1F-\x03' +
|
|
68
|
+
now +
|
|
69
|
+
"\x1F\n" +
|
|
70
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+44\x03' +
|
|
71
|
+
now +
|
|
72
|
+
"\x1F\n" +
|
|
73
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#toys\x03' +
|
|
74
|
+
now +
|
|
75
|
+
"\x1F\n" +
|
|
76
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"grandchild value\x03' +
|
|
77
|
+
now +
|
|
78
|
+
"\x1F\n"
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
const toys = () => {
|
|
82
|
+
return (
|
|
83
|
+
'\x1F+0\x1F#\x1F"toys\x05\x1F\n' +
|
|
84
|
+
'\x1F+1\x1F#\x1F"b\x1F\n' +
|
|
85
|
+
'\x1F+2\x1F#\x1F"all\x1F=\x1F"green\x03' +
|
|
86
|
+
now +
|
|
87
|
+
"\x1F\n" +
|
|
88
|
+
'\x1F+2\x1F#\x1F"ook\x1F=\x1F"' +
|
|
89
|
+
lorem +
|
|
90
|
+
"\x03" +
|
|
91
|
+
now +
|
|
92
|
+
"\x1F\n" +
|
|
93
|
+
'\x1F+1\x1F#\x1F"car\x1F=\x1F"red\x03' +
|
|
94
|
+
now +
|
|
95
|
+
"\x1F\n"
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
const alpha = () => {
|
|
99
|
+
return (
|
|
100
|
+
'\x1F+0\x1F#\x1F"alpha\x05\x1F\n' +
|
|
101
|
+
'\x1F+1\x1F#\x1F"boolean\x1F=\x1F+\x03' +
|
|
102
|
+
now +
|
|
103
|
+
"\x1F\n" +
|
|
104
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+1\x03' +
|
|
105
|
+
now +
|
|
106
|
+
"\x1F\n" +
|
|
107
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#beta\x03' +
|
|
108
|
+
now +
|
|
109
|
+
"\x1F\n" +
|
|
110
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"alpha value\x03' +
|
|
111
|
+
now +
|
|
112
|
+
"\x1F\n"
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
test("write a parent node", (t, done) => {
|
|
117
|
+
radisk("parent" + enq + "string", ["parent value", now])
|
|
118
|
+
radisk("parent" + enq + "number", [42, now])
|
|
119
|
+
radisk("parent" + enq + "boolean", [true, now])
|
|
120
|
+
radisk("parent" + enq + "rel", [{"#": "child"}, now])
|
|
121
|
+
|
|
122
|
+
setTimeout(() => {
|
|
123
|
+
assert.deepEqual(puts, {
|
|
124
|
+
"!": parent(),
|
|
125
|
+
})
|
|
126
|
+
done()
|
|
127
|
+
}, 10)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test("write a child node", (t, done) => {
|
|
131
|
+
radisk("child" + enq + "string", ["child value", now])
|
|
132
|
+
radisk("child" + enq + "number", [43, now])
|
|
133
|
+
radisk("child" + enq + "boolean", [true, now])
|
|
134
|
+
radisk("child" + enq + "rel", [{"#": "grandchild"}, now])
|
|
135
|
+
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
assert.deepEqual(puts, {
|
|
138
|
+
"!": child(),
|
|
139
|
+
parent: parent(),
|
|
140
|
+
})
|
|
141
|
+
done()
|
|
142
|
+
}, 10)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
test("write a grandchild node", (t, done) => {
|
|
146
|
+
radisk("grandchild" + enq + "string", ["grandchild value", now])
|
|
147
|
+
radisk("grandchild" + enq + "number", [44, now])
|
|
148
|
+
radisk("grandchild" + enq + "boolean", [false, now])
|
|
149
|
+
radisk("grandchild" + enq + "rel", [{"#": "toys"}, now])
|
|
150
|
+
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
assert.deepEqual(puts, {
|
|
153
|
+
"!": child(),
|
|
154
|
+
parent: parent(),
|
|
155
|
+
grandchild: grandchild(),
|
|
156
|
+
})
|
|
157
|
+
done()
|
|
158
|
+
}, 10)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test("write grandchild toys", (t, done) => {
|
|
162
|
+
radisk("toys" + enq + "car", ["red", now])
|
|
163
|
+
radisk("toys" + enq + "ball", ["green", now])
|
|
164
|
+
radisk("toys" + enq + "book", [lorem, now])
|
|
165
|
+
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
assert.deepEqual(puts, {
|
|
168
|
+
"!": child(),
|
|
169
|
+
parent: parent(),
|
|
170
|
+
grandchild: grandchild(),
|
|
171
|
+
toys: toys(),
|
|
172
|
+
})
|
|
173
|
+
done()
|
|
174
|
+
}, 10)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test("write new first node", (t, done) => {
|
|
178
|
+
radisk("alpha" + enq + "string", ["alpha value", now])
|
|
179
|
+
radisk("alpha" + enq + "number", [1, now])
|
|
180
|
+
radisk("alpha" + enq + "boolean", [true, now])
|
|
181
|
+
radisk("alpha" + enq + "rel", [{"#": "beta"}, now])
|
|
182
|
+
radisk("beta" + enq + "string", ["beta value", now])
|
|
183
|
+
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
assert.deepEqual(puts, {
|
|
186
|
+
"!": alpha(),
|
|
187
|
+
beta:
|
|
188
|
+
'\x1F+0\x1F#\x1F"beta\x05string\x1F=\x1F"beta value\x03' +
|
|
189
|
+
now +
|
|
190
|
+
"\x1F\n" +
|
|
191
|
+
child(),
|
|
192
|
+
parent: parent(),
|
|
193
|
+
grandchild: grandchild(),
|
|
194
|
+
toys: toys(),
|
|
195
|
+
})
|
|
196
|
+
done()
|
|
197
|
+
}, 10)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
// Note that "beta" remains a separate file here (nodes aren't combined).
|
|
201
|
+
test("write new second node", (t, done) => {
|
|
202
|
+
radisk("be" + enq + "string", ["be value", now])
|
|
203
|
+
|
|
204
|
+
setTimeout(() => {
|
|
205
|
+
assert.deepEqual(puts, {
|
|
206
|
+
"!": alpha(),
|
|
207
|
+
be:
|
|
208
|
+
'\x1F+0\x1F#\x1F"be\x05string\x1F=\x1F"be value\x03' + now + "\x1F\n",
|
|
209
|
+
beta:
|
|
210
|
+
'\x1F+0\x1F#\x1F"beta\x05string\x1F=\x1F"beta value\x03' +
|
|
211
|
+
now +
|
|
212
|
+
"\x1F\n" +
|
|
213
|
+
child(),
|
|
214
|
+
parent: parent(),
|
|
215
|
+
grandchild: grandchild(),
|
|
216
|
+
toys: toys(),
|
|
217
|
+
})
|
|
218
|
+
done()
|
|
219
|
+
}, 10)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
test("add a parent item", (t, done) => {
|
|
223
|
+
radisk("parent" + enq + "after", ["this was added after", now])
|
|
224
|
+
|
|
225
|
+
setTimeout(() => {
|
|
226
|
+
assert.deepEqual(puts, {
|
|
227
|
+
"!": alpha(),
|
|
228
|
+
be:
|
|
229
|
+
'\x1F+0\x1F#\x1F"be\x05string\x1F=\x1F"be value\x03' + now + "\x1F\n",
|
|
230
|
+
beta:
|
|
231
|
+
'\x1F+0\x1F#\x1F"beta\x05string\x1F=\x1F"beta value\x03' +
|
|
232
|
+
now +
|
|
233
|
+
"\x1F\n" +
|
|
234
|
+
child(),
|
|
235
|
+
grandchild: grandchild(),
|
|
236
|
+
parent:
|
|
237
|
+
'\x1F+0\x1F#\x1F"parent\x05\x1F\n' +
|
|
238
|
+
'\x1F+1\x1F#\x1F"after\x1F=\x1F"this was added after\x03' +
|
|
239
|
+
now +
|
|
240
|
+
"\x1F\n" +
|
|
241
|
+
'\x1F+1\x1F#\x1F"boolean\x1F=\x1F+\x03' +
|
|
242
|
+
now +
|
|
243
|
+
"\x1F\n" +
|
|
244
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+42\x03' +
|
|
245
|
+
now +
|
|
246
|
+
"\x1F\n" +
|
|
247
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#child\x03' +
|
|
248
|
+
now +
|
|
249
|
+
"\x1F\n" +
|
|
250
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"parent value\x03' +
|
|
251
|
+
now +
|
|
252
|
+
"\x1F\n",
|
|
253
|
+
toys: toys(),
|
|
254
|
+
})
|
|
255
|
+
done()
|
|
256
|
+
}, 10)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
test("add two child items", (t, done) => {
|
|
260
|
+
radisk("child" + enq + "book", [lorem, now])
|
|
261
|
+
radisk("child" + enq + "pi", [3.14159, now])
|
|
262
|
+
|
|
263
|
+
setTimeout(() => {
|
|
264
|
+
assert.deepEqual(puts, {
|
|
265
|
+
"!": alpha(),
|
|
266
|
+
be:
|
|
267
|
+
'\x1F+0\x1F#\x1F"be\x05string\x1F=\x1F"be value\x03' + now + "\x1F\n",
|
|
268
|
+
beta:
|
|
269
|
+
'\x1F+0\x1F#\x1F"beta\x05string\x1F=\x1F"beta value\x03' +
|
|
270
|
+
now +
|
|
271
|
+
"\x1F\n" +
|
|
272
|
+
'\x1F+0\x1F#\x1F"child\x05\x1F\n' +
|
|
273
|
+
'\x1F+1\x1F#\x1F"boo\x1F\n' +
|
|
274
|
+
'\x1F+2\x1F#\x1F"k\x1F=\x1F"' +
|
|
275
|
+
lorem +
|
|
276
|
+
"\x03" +
|
|
277
|
+
now +
|
|
278
|
+
"\x1F\n" +
|
|
279
|
+
'\x1F+2\x1F#\x1F"lean\x1F=\x1F+\x03' +
|
|
280
|
+
now +
|
|
281
|
+
"\x1F\n" +
|
|
282
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+43\x03' +
|
|
283
|
+
now +
|
|
284
|
+
"\x1F\n" +
|
|
285
|
+
'\x1F+1\x1F#\x1F"pi\x1F=\x1F+3.14159\x03' +
|
|
286
|
+
now +
|
|
287
|
+
"\x1F\n" +
|
|
288
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#grandchild\x03' +
|
|
289
|
+
now +
|
|
290
|
+
"\x1F\n" +
|
|
291
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"child value\x03' +
|
|
292
|
+
now +
|
|
293
|
+
"\x1F\n",
|
|
294
|
+
grandchild: grandchild(),
|
|
295
|
+
parent:
|
|
296
|
+
'\x1F+0\x1F#\x1F"parent\x05\x1F\n' +
|
|
297
|
+
'\x1F+1\x1F#\x1F"after\x1F=\x1F"this was added after\x03' +
|
|
298
|
+
now +
|
|
299
|
+
"\x1F\n" +
|
|
300
|
+
'\x1F+1\x1F#\x1F"boolean\x1F=\x1F+\x03' +
|
|
301
|
+
now +
|
|
302
|
+
"\x1F\n" +
|
|
303
|
+
'\x1F+1\x1F#\x1F"number\x1F=\x1F+42\x03' +
|
|
304
|
+
now +
|
|
305
|
+
"\x1F\n" +
|
|
306
|
+
'\x1F+1\x1F#\x1F"rel\x1F=\x1F#child\x03' +
|
|
307
|
+
now +
|
|
308
|
+
"\x1F\n" +
|
|
309
|
+
'\x1F+1\x1F#\x1F"string\x1F=\x1F"parent value\x03' +
|
|
310
|
+
now +
|
|
311
|
+
"\x1F\n",
|
|
312
|
+
toys: toys(),
|
|
313
|
+
})
|
|
314
|
+
done()
|
|
315
|
+
}, 10)
|
|
316
|
+
})
|
|
317
|
+
})
|