@web3-storage/pail 0.6.0 → 0.6.2

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.
Files changed (106) hide show
  1. package/dist/cli.d.ts +3 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +208 -0
  4. package/dist/scripts/randomcid.d.ts +2 -0
  5. package/dist/scripts/randomcid.d.ts.map +1 -0
  6. package/dist/scripts/randomcid.js +10 -0
  7. package/dist/scripts/words/gen.d.ts +2 -0
  8. package/dist/scripts/words/gen.d.ts.map +1 -0
  9. package/dist/scripts/words/gen.js +51 -0
  10. package/dist/src/api.d.ts +4 -2
  11. package/dist/src/api.d.ts.map +1 -1
  12. package/dist/src/api.js +1 -0
  13. package/dist/src/batch/api.d.ts +2 -2
  14. package/dist/src/batch/api.d.ts.map +1 -1
  15. package/dist/src/batch/api.js +1 -0
  16. package/dist/src/batch/index.d.ts +1 -53
  17. package/dist/src/batch/index.d.ts.map +1 -1
  18. package/dist/src/batch/index.js +241 -0
  19. package/dist/src/batch/shard.d.ts +1 -1
  20. package/dist/src/batch/shard.d.ts.map +1 -1
  21. package/dist/src/batch/shard.js +12 -0
  22. package/dist/src/block.d.ts +2 -2
  23. package/dist/src/block.d.ts.map +1 -1
  24. package/dist/src/block.js +66 -0
  25. package/dist/src/clock/api.d.ts +1 -1
  26. package/dist/src/clock/api.d.ts.map +1 -1
  27. package/dist/src/clock/api.js +1 -0
  28. package/dist/src/clock/index.d.ts +2 -2
  29. package/dist/src/clock/index.d.ts.map +1 -1
  30. package/dist/src/clock/index.js +199 -0
  31. package/dist/src/crdt/api.d.ts +1 -1
  32. package/dist/src/crdt/api.d.ts.map +1 -1
  33. package/dist/src/crdt/api.js +1 -0
  34. package/dist/src/crdt/batch/api.d.ts +1 -1
  35. package/dist/src/crdt/batch/api.d.ts.map +1 -1
  36. package/dist/src/crdt/batch/api.js +1 -0
  37. package/dist/src/crdt/batch/index.d.ts.map +1 -1
  38. package/dist/src/crdt/batch/index.js +140 -0
  39. package/dist/src/crdt/index.d.ts +2 -2
  40. package/dist/src/crdt/index.d.ts.map +1 -1
  41. package/dist/src/crdt/index.js +344 -0
  42. package/dist/src/diff.d.ts +3 -3
  43. package/dist/src/diff.d.ts.map +1 -1
  44. package/dist/src/diff.js +151 -0
  45. package/dist/src/index.d.ts +1 -1
  46. package/dist/src/index.d.ts.map +1 -1
  47. package/dist/src/index.js +356 -0
  48. package/dist/src/merge.d.ts.map +1 -1
  49. package/dist/src/merge.js +42 -0
  50. package/dist/src/shard.d.ts +4 -4
  51. package/dist/src/shard.d.ts.map +1 -1
  52. package/dist/src/shard.js +166 -0
  53. package/dist/test/batch.test.d.ts +2 -0
  54. package/dist/test/batch.test.d.ts.map +1 -0
  55. package/dist/test/batch.test.js +126 -0
  56. package/dist/test/clock.test.d.ts +2 -0
  57. package/dist/test/clock.test.d.ts.map +1 -0
  58. package/dist/test/clock.test.js +244 -0
  59. package/dist/test/crdt.test.d.ts +2 -0
  60. package/dist/test/crdt.test.d.ts.map +1 -0
  61. package/dist/test/crdt.test.js +271 -0
  62. package/dist/test/del.test.d.ts +2 -0
  63. package/dist/test/del.test.d.ts.map +1 -0
  64. package/dist/test/del.test.js +21 -0
  65. package/dist/test/diff.test.d.ts +2 -0
  66. package/dist/test/diff.test.d.ts.map +1 -0
  67. package/dist/test/diff.test.js +38 -0
  68. package/dist/test/entries.test.d.ts +2 -0
  69. package/dist/test/entries.test.d.ts.map +1 -0
  70. package/dist/test/entries.test.js +210 -0
  71. package/dist/test/get.test.d.ts +2 -0
  72. package/dist/test/get.test.d.ts.map +1 -0
  73. package/dist/test/get.test.js +26 -0
  74. package/dist/test/helpers.d.ts +35 -0
  75. package/dist/test/helpers.d.ts.map +1 -0
  76. package/dist/test/helpers.js +168 -0
  77. package/dist/test/put.test.d.ts +2 -0
  78. package/dist/test/put.test.d.ts.map +1 -0
  79. package/dist/test/put.test.js +165 -0
  80. package/dist/tsconfig.tsbuildinfo +1 -1
  81. package/dist/vitest.config.d.ts +3 -0
  82. package/dist/vitest.config.d.ts.map +1 -0
  83. package/dist/vitest.config.js +13 -0
  84. package/package.json +49 -94
  85. package/scripts/propernames/gen.sh +3 -0
  86. package/cli.js +0 -218
  87. package/src/api.js +0 -1
  88. package/src/api.ts +0 -90
  89. package/src/batch/api.js +0 -1
  90. package/src/batch/api.ts +0 -59
  91. package/src/batch/index.js +0 -258
  92. package/src/batch/shard.js +0 -13
  93. package/src/block.js +0 -75
  94. package/src/clock/api.js +0 -1
  95. package/src/clock/api.ts +0 -12
  96. package/src/clock/index.js +0 -182
  97. package/src/crdt/api.js +0 -1
  98. package/src/crdt/api.ts +0 -33
  99. package/src/crdt/batch/api.js +0 -1
  100. package/src/crdt/batch/api.ts +0 -30
  101. package/src/crdt/batch/index.js +0 -155
  102. package/src/crdt/index.js +0 -354
  103. package/src/diff.js +0 -151
  104. package/src/index.js +0 -406
  105. package/src/merge.js +0 -43
  106. package/src/shard.js +0 -180
package/package.json CHANGED
@@ -1,132 +1,73 @@
1
1
  {
2
2
  "name": "@web3-storage/pail",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "DAG based key value store.",
5
- "main": "src/index.js",
5
+ "main": "./dist/src/index.js",
6
6
  "type": "module",
7
7
  "types": "./dist/src/index.d.ts",
8
- "typesVersions": {
9
- "*": {
10
- "*": [
11
- "dist/*"
12
- ],
13
- "dist/src/index.d.ts": [
14
- "dist/src/index.d.ts"
15
- ],
16
- "api": [
17
- "dist/src/api.d.ts"
18
- ],
19
- "batch": [
20
- "dist/src/batch/index.d.ts"
21
- ],
22
- "batch/api": [
23
- "dist/src/batch/api.d.ts"
24
- ],
25
- "block": [
26
- "dist/src/block.d.ts"
27
- ],
28
- "clock": [
29
- "dist/src/clock/index.d.ts"
30
- ],
31
- "clock/api": [
32
- "dist/src/clock/api.d.ts"
33
- ],
34
- "crdt": [
35
- "dist/src/crdt/index.d.ts"
36
- ],
37
- "crdt/api": [
38
- "dist/src/crdt/api.d.ts"
39
- ],
40
- "crdt/batch": [
41
- "dist/src/crdt/batch/index.d.ts"
42
- ],
43
- "crdt/batch/api": [
44
- "dist/src/crdt/batch/api.d.ts"
45
- ],
46
- "diff": [
47
- "dist/src/diff.d.ts"
48
- ],
49
- "link": [
50
- "dist/src/link.d.ts"
51
- ],
52
- "merge": [
53
- "dist/src/merge.d.ts"
54
- ],
55
- "shard": [
56
- "dist/src/shard.d.ts"
57
- ]
58
- }
59
- },
60
8
  "exports": {
61
9
  ".": {
62
10
  "types": "./dist/src/index.d.ts",
63
- "import": "./src/index.js"
11
+ "import": "./dist/src/index.js"
64
12
  },
65
13
  "./api": {
66
14
  "types": "./dist/src/api.d.ts",
67
- "import": "./src/api.js"
15
+ "import": "./dist/src/api.js"
68
16
  },
69
17
  "./batch": {
70
18
  "types": "./dist/src/batch/index.d.ts",
71
- "import": "./src/batch/index.js"
19
+ "import": "./dist/src/batch/index.js"
72
20
  },
73
21
  "./batch/api": {
74
22
  "types": "./dist/src/batch/api.d.ts",
75
- "import": "./src/batch/api.js"
23
+ "import": "./dist/src/batch/api.js"
76
24
  },
77
25
  "./block": {
78
26
  "types": "./dist/src/block.d.ts",
79
- "import": "./src/block.js"
27
+ "import": "./dist/src/block.js"
80
28
  },
81
29
  "./clock": {
82
30
  "types": "./dist/src/clock/index.d.ts",
83
- "import": "./src/clock/index.js"
31
+ "import": "./dist/src/clock/index.js"
84
32
  },
85
33
  "./clock/api": {
86
34
  "types": "./dist/src/clock/api.d.ts",
87
- "import": "./src/clock/api.js"
35
+ "import": "./dist/src/clock/api.js"
88
36
  },
89
37
  "./crdt": {
90
38
  "types": "./dist/src/crdt/index.d.ts",
91
- "import": "./src/crdt/index.js"
39
+ "import": "./dist/src/crdt/index.js"
92
40
  },
93
41
  "./crdt/api": {
94
42
  "types": "./dist/src/crdt/api.d.ts",
95
- "import": "./src/crdt/api.js"
43
+ "import": "./dist/src/crdt/api.js"
96
44
  },
97
45
  "./crdt/batch": {
98
46
  "types": "./dist/src/crdt/batch/index.d.ts",
99
- "import": "./src/crdt/batch/index.js"
47
+ "import": "./dist/src/crdt/batch/index.js"
100
48
  },
101
49
  "./crdt/batch/api": {
102
50
  "types": "./dist/src/crdt/batch/api.d.ts",
103
- "import": "./src/crdt/batch/api.js"
51
+ "import": "./dist/src/crdt/batch/api.js"
104
52
  },
105
53
  "./diff": {
106
54
  "types": "./dist/src/diff.d.ts",
107
- "import": "./src/diff.js"
108
- },
109
- "./link": {
110
- "types": "./dist/src/link.d.ts",
111
- "import": "./src/link.js"
55
+ "import": "./dist/src/diff.js"
112
56
  },
113
57
  "./merge": {
114
58
  "types": "./dist/src/merge.d.ts",
115
- "import": "./src/merge.js"
59
+ "import": "./dist/src/merge.js"
116
60
  },
117
61
  "./shard": {
118
62
  "types": "./dist/src/shard.d.ts",
119
- "import": "./src/shard.js"
63
+ "import": "./dist/src/shard.js"
120
64
  }
121
65
  },
122
66
  "bin": {
123
- "pail": "./cli.js"
124
- },
125
- "scripts": {
126
- "build": "tsc --build",
127
- "test": "mocha test/*.test.js",
128
- "coverage": "c8 -r html -r text npm test",
129
- "lint": "standard"
67
+ "pail": "./dist/cli.js",
68
+ "pail-propernames": "./scripts/propernames/gen.sh",
69
+ "pail-gen": "./dist/scripts/words/gen.js",
70
+ "pail-randomcid": "./dist/scripts/randomcid.js"
130
71
  },
131
72
  "keywords": [
132
73
  "bucket",
@@ -139,23 +80,25 @@
139
80
  "author": "Alan Shaw",
140
81
  "license": "Apache-2.0 OR MIT",
141
82
  "files": [
142
- "src",
143
83
  "dist"
144
84
  ],
145
85
  "dependencies": {
146
- "@ipld/dag-cbor": "^9.2.0",
147
- "multiformats": "^13.1.0"
148
- },
149
- "devDependencies": {
86
+ "@ipld/dag-cbor": "^9.2.2",
87
+ "cli-color": "^2.0.3",
88
+ "@ipld/car": "^5.4.0",
150
89
  "archy": "^1.0.0",
151
- "c8": "^8.0.1",
152
90
  "carstream": "^2.0.0",
153
- "cli-color": "^2.0.3",
154
- "mocha": "^10.2.0",
155
- "nanoid": "^4.0.0",
156
- "sade": "^1.8.1",
157
- "standard": "^17.0.0",
158
- "typescript": "^5.0.2"
91
+ "multiformats": "^13.3.2",
92
+ "sade": "^1.8.1"
93
+ },
94
+ "devDependencies": {
95
+ "@types/archy": "^0.0.36",
96
+ "@types/cli-color": "^2.0.6",
97
+ "@types/node": "^22.13.17",
98
+ "@vitest/coverage-v8": "^3.1.1",
99
+ "standard": "^17.1.2",
100
+ "typescript": "^5.8.2",
101
+ "vitest": "^3.1.1"
159
102
  },
160
103
  "repository": {
161
104
  "type": "git",
@@ -166,8 +109,20 @@
166
109
  },
167
110
  "homepage": "https://github.com/web3-storage/pail#readme",
168
111
  "standard": {
169
- "ignore": [
170
- "*.ts"
112
+ "globals": [
113
+ "describe",
114
+ "before",
115
+ "after",
116
+ "beforeEach",
117
+ "afterEach",
118
+ "it",
119
+ "assert"
171
120
  ]
121
+ },
122
+ "scripts": {
123
+ "build": "tsc --build",
124
+ "test": "vitest --run",
125
+ "coverage": "vitest --run --coverage",
126
+ "lint": "standard"
172
127
  }
173
- }
128
+ }
@@ -0,0 +1,3 @@
1
+ while read p; do
2
+ pail put $p $(pail-randomcid) --max-shard-size=10000
3
+ done </usr/share/dict/propernames
package/cli.js DELETED
@@ -1,218 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'fs'
3
- import os from 'os'
4
- import { join } from 'path'
5
- import { Readable, Writable } from 'stream'
6
- import sade from 'sade'
7
- import { CID } from 'multiformats/cid'
8
- import { CARReaderStream, CARWriterStream } from 'carstream'
9
- import clc from 'cli-color'
10
- import archy from 'archy'
11
- // eslint-disable-next-line no-unused-vars
12
- import * as API from './src/api.js'
13
- import { put, get, del, entries } from './src/index.js'
14
- import { ShardFetcher, ShardBlock, isShardLink } from './src/shard.js'
15
- import { difference } from './src/diff.js'
16
- import { merge } from './src/merge.js'
17
- import { MemoryBlockstore, MultiBlockFetcher } from './src/block.js'
18
-
19
- const cli = sade('pail')
20
- .option('--path', 'Path to data store.', './pail.car')
21
-
22
- cli.command('put <key> <value>')
23
- .describe('Put a value (a CID) for the given key. If the key exists it\'s value is overwritten.')
24
- .alias('set')
25
- .action(async (key, value, opts) => {
26
- const { root: prevRoot, blocks } = await openPail(opts.path)
27
- const { root, additions, removals } = await put(blocks, prevRoot, key, CID.parse(value))
28
- await updatePail(opts.path, blocks, root, { additions, removals })
29
-
30
- console.log(clc.red(`--- ${prevRoot}`))
31
- console.log(clc.green(`+++ ${root}`))
32
- console.log(clc.magenta('@@ -1 +1 @@'))
33
- additions.forEach(b => console.log(clc.green(`+${b.cid}`)))
34
- removals.forEach(b => console.log(clc.red(`-${b.cid}`)))
35
- })
36
-
37
- cli.command('get <key>')
38
- .describe('Get the stored value for the given key from the pail. If the key is not found, `undefined` is returned.')
39
- .action(async (key, opts) => {
40
- const { root, blocks } = await openPail(opts.path)
41
- const value = await get(blocks, root, key)
42
- if (value) console.log(value.toString())
43
- })
44
-
45
- cli.command('del <key>')
46
- .describe('Delete the value for the given key from the pail. If the key is not found no operation occurs.')
47
- .alias('delete', 'rm', 'remove')
48
- .action(async (key, opts) => {
49
- const { root: prevRoot, blocks } = await openPail(opts.path)
50
- const { root, additions, removals } = await del(blocks, prevRoot, key)
51
- await updatePail(opts.path, blocks, root, { additions, removals })
52
-
53
- console.log(clc.red(`--- ${prevRoot}`))
54
- console.log(clc.green(`+++ ${root}`))
55
- console.log(clc.magenta('@@ -1 +1 @@'))
56
- additions.forEach(b => console.log(clc.green(`+ ${b.cid}`)))
57
- removals.forEach(b => console.log(clc.red(`- ${b.cid}`)))
58
- })
59
-
60
- cli.command('ls')
61
- .describe('List entries in the pail.')
62
- .alias('list')
63
- .option('-p, --prefix', 'Key prefix to filter by.')
64
- .option('--gt', 'Filter results by keys greater than this string.')
65
- .option('--lt', 'Filter results by keys less than this string.')
66
- .option('--json', 'Format output as newline delimted JSON.')
67
- .action(async (opts) => {
68
- const { root, blocks } = await openPail(opts.path)
69
- let n = 0
70
- for await (const [k, v] of entries(blocks, root, { prefix: opts.prefix, gt: opts.gt, lt: opts.lt })) {
71
- console.log(opts.json ? JSON.stringify({ key: k, value: v.toString() }) : `${k}\t${v}`)
72
- n++
73
- }
74
- if (!opts.json) console.log(`total ${n}`)
75
- })
76
-
77
- cli.command('tree')
78
- .describe('Visualise the pail.')
79
- .alias('vis')
80
- .action(async (opts) => {
81
- const { root, blocks } = await openPail(opts.path)
82
- const shards = new ShardFetcher(blocks)
83
- const rshard = await shards.get(root)
84
-
85
- /** @type {archy.Data} */
86
- const archyRoot = { label: `Shard(${clc.yellow(rshard.cid.toString())}) ${rshard.bytes.length + 'b'}`, nodes: [] }
87
-
88
- /** @param {API.ShardEntry} entry */
89
- const getData = async ([k, v]) => {
90
- if (!Array.isArray(v)) {
91
- return { label: `Key(${clc.magenta(k)})`, nodes: [{ label: `Value(${clc.cyan(v)})` }] }
92
- }
93
- /** @type {archy.Data} */
94
- const data = { label: `Key(${clc.magenta(k)})`, nodes: [] }
95
- if (v[1]) data.nodes?.push({ label: `Value(${clc.cyan(v[1])})` })
96
- const blk = await shards.get(v[0])
97
- data.nodes?.push({
98
- label: `Shard(${clc.yellow(v[0])}) ${blk.bytes.length + 'b'}`,
99
- nodes: await Promise.all(blk.value.entries.map(e => getData(e)))
100
- })
101
- return data
102
- }
103
-
104
- for (const entry of rshard.value.entries) {
105
- archyRoot.nodes?.push(await getData(entry))
106
- }
107
-
108
- console.log(archy(archyRoot))
109
- })
110
-
111
- cli.command('diff <path>')
112
- .describe('Find the differences between this pail and the passed pail.')
113
- .option('-k, --keys', 'Output key/value diff.')
114
- .action(async (path, opts) => {
115
- const [
116
- { root: aroot, blocks: ablocks },
117
- { root: broot, blocks: bblocks }
118
- ] = await Promise.all([openPail(opts.path), openPail(path)])
119
- if (aroot.toString() === broot.toString()) return
120
-
121
- const fetcher = new MultiBlockFetcher(ablocks, bblocks)
122
- const { shards: { additions, removals }, keys } = await difference(fetcher, aroot, broot)
123
-
124
- console.log(clc.red(`--- ${aroot}`))
125
- console.log(clc.green(`+++ ${broot}`))
126
- console.log(clc.magenta('@@ -1 +1 @@'))
127
-
128
- if (opts.keys) {
129
- keys.forEach(([k, v]) => {
130
- if (v[0] != null) console.log(clc.red(`- ${k}\t${v[0]}`))
131
- if (v[1] != null) console.log(clc.green(`+ ${k}\t${v[1]}`))
132
- })
133
- } else {
134
- additions.forEach(b => console.log(clc.green(`+ ${b.cid}`)))
135
- removals.forEach(b => console.log(clc.red(`- ${b.cid}`)))
136
- }
137
- })
138
-
139
- cli.command('merge <path>')
140
- .describe('Merge the passed pail into this pail.')
141
- .action(async (path, opts) => {
142
- const [
143
- { root: aroot, blocks: ablocks },
144
- { root: broot, blocks: bblocks }
145
- ] = await Promise.all([openPail(opts.path), openPail(path)])
146
- if (aroot.toString() === broot.toString()) return
147
-
148
- const fetcher = new MultiBlockFetcher(ablocks, bblocks)
149
- const { root, additions, removals } = await merge(fetcher, aroot, [broot])
150
-
151
- await updatePail(opts.path, ablocks, root, { additions, removals })
152
-
153
- console.log(clc.red(`--- ${aroot}`))
154
- console.log(clc.green(`+++ ${root}`))
155
- console.log(clc.magenta('@@ -1 +1 @@'))
156
- additions.forEach(b => console.log(clc.green(`+ ${b.cid}`)))
157
- removals.forEach(b => console.log(clc.red(`- ${b.cid}`)))
158
- })
159
-
160
- cli.parse(process.argv)
161
-
162
- /**
163
- * @param {string} path
164
- * @returns {Promise<{ root: API.ShardLink, blocks: MemoryBlockstore }>}
165
- */
166
- async function openPail (path) {
167
- const blocks = new MemoryBlockstore()
168
- try {
169
- const carReader = new CARReaderStream()
170
- const readable = /** @type {ReadableStream<Uint8Array>} */ (Readable.toWeb(fs.createReadStream(path)))
171
- await readable.pipeThrough(carReader).pipeTo(new WritableStream({ write: b => blocks.put(b.cid, b.bytes) }))
172
- const header = await carReader.getHeader()
173
- if (!isShardLink(header.roots[0])) throw new Error(`not a shard: ${header.roots[0]}`)
174
- return { root: header.roots[0], blocks }
175
- } catch (err) {
176
- if (err.code !== 'ENOENT') throw new Error('failed to open bucket', { cause: err })
177
- const rootblk = await ShardBlock.create()
178
- blocks.put(rootblk.cid, rootblk.bytes)
179
- return { root: rootblk.cid, blocks }
180
- }
181
- }
182
-
183
- /**
184
- * @param {string} path
185
- * @param {MemoryBlockstore} blocks
186
- * @param {API.ShardLink} root
187
- * @param {API.ShardDiff} diff
188
- */
189
- async function updatePail (path, blocks, root, { additions, removals }) {
190
- const tmp = join(os.tmpdir(), `pail${Date.now()}.car`)
191
- const iterator = blocks.entries()
192
- const readable = new ReadableStream({
193
- start (controller) {
194
- for (const b of additions) controller.enqueue(b)
195
- },
196
- pull (controller) {
197
- for (const b of iterator) {
198
- if (removals.some(r => b.cid.toString() === r.cid.toString())) continue
199
- return controller.enqueue(b)
200
- }
201
- controller.close()
202
- }
203
- })
204
- await readable.pipeThrough(new CARWriterStream([root])).pipeTo(Writable.toWeb(fs.createWriteStream(tmp)))
205
-
206
- const old = `${path}-${new Date().toISOString()}`
207
- try {
208
- await fs.promises.rename(path, old)
209
- } catch (err) {
210
- if (err.code !== 'ENOENT') throw err
211
- }
212
- await fs.promises.rename(tmp, path)
213
- try {
214
- await fs.promises.rm(old)
215
- } catch (err) {
216
- if (err.code !== 'ENOENT') throw err
217
- }
218
- }
package/src/api.js DELETED
@@ -1 +0,0 @@
1
- export {}
package/src/api.ts DELETED
@@ -1,90 +0,0 @@
1
- import { Link, UnknownLink, BlockView, Block, Version } from 'multiformats'
2
- import { sha256 } from 'multiformats/hashes/sha2'
3
- import * as dagCBOR from '@ipld/dag-cbor'
4
-
5
- export { Link, UnknownLink, BlockView, Block, Version }
6
-
7
- export type ShardEntryValueValue = UnknownLink
8
-
9
- export type ShardEntryLinkValue = [ShardLink]
10
-
11
- export type ShardEntryLinkAndValueValue = [ShardLink, UnknownLink]
12
-
13
- export type ShardValueEntry = [key: string, value: ShardEntryValueValue]
14
-
15
- export type ShardLinkEntry = [key: string, value: ShardEntryLinkValue | ShardEntryLinkAndValueValue]
16
-
17
- /** Single key/value entry within a shard. */
18
- export type ShardEntry = [key: string, value: ShardEntryValueValue | ShardEntryLinkValue | ShardEntryLinkAndValueValue]
19
-
20
- export interface Shard extends ShardConfig {
21
- entries: ShardEntry[]
22
- }
23
-
24
- export type ShardLink = Link<Shard, typeof dagCBOR.code, typeof sha256.code, 1>
25
-
26
- export interface ShardBlockView extends BlockView<Shard, typeof dagCBOR.code, typeof sha256.code, 1> {}
27
-
28
- export interface ShardDiff {
29
- additions: ShardBlockView[]
30
- removals: ShardBlockView[]
31
- }
32
-
33
- export interface BlockFetcher {
34
- get<T = unknown, C extends number = number, A extends number = number, V extends Version = 1> (link: Link<T, C, A, V>):
35
- Promise<Block<T, C, A, V> | undefined>
36
- }
37
-
38
- export interface ShardConfig {
39
- /** Shard compatibility version. */
40
- version: number
41
- /**
42
- * Characters allowed in keys, referring to a known character set.
43
- * e.g. "ascii" refers to the printable ASCII characters in the code range 32-126.
44
- */
45
- keyChars: string
46
- /** Max key size in bytes - default 4096 bytes. */
47
- maxKeySize: number
48
- /** The key prefix from the root to this shard. */
49
- prefix: string
50
- }
51
-
52
- export type ShardOptions = Partial<ShardConfig>
53
-
54
- export interface KeyPrefixOption {
55
- /** Filter results to entries with keys prefixed with this string. */
56
- prefix: string
57
- }
58
-
59
- export type KeyRangeOption =
60
- | KeyLowerBoundRangeOption
61
- | KeyUpperBoundRangeOption
62
- | (KeyLowerBoundRangeOption & KeyUpperBoundRangeOption)
63
-
64
- export type KeyLowerBoundRangeOption =
65
- | KeyLowerBoundRangeExclusiveOption
66
- | KeyLowerBoundRangeInclusiveOption
67
-
68
- export interface KeyLowerBoundRangeExclusiveOption {
69
- gt: string
70
- }
71
-
72
- export interface KeyLowerBoundRangeInclusiveOption {
73
- gte: string
74
- }
75
-
76
- export type KeyUpperBoundRangeOption =
77
- | KeyUpperBoundRangeExclusiveOption
78
- | KeyUpperBoundRangeInclusiveOption
79
-
80
- export interface KeyUpperBoundRangeExclusiveOption {
81
- lt: string
82
- }
83
-
84
- export interface KeyUpperBoundRangeInclusiveOption {
85
- lte: string
86
- }
87
-
88
- export type EntriesOptions =
89
- | KeyPrefixOption
90
- | KeyRangeOption
package/src/batch/api.js DELETED
@@ -1 +0,0 @@
1
- export {}
package/src/batch/api.ts DELETED
@@ -1,59 +0,0 @@
1
- import {
2
- UnknownLink,
3
- ShardLink,
4
- ShardDiff,
5
- ShardEntry,
6
- ShardEntryValueValue,
7
- ShardEntryLinkValue,
8
- ShardEntryLinkAndValueValue,
9
- ShardConfig,
10
- ShardOptions,
11
- ShardBlockView,
12
- BlockFetcher
13
- } from '../api.js'
14
-
15
- export {
16
- UnknownLink,
17
- ShardLink,
18
- ShardDiff,
19
- ShardEntry,
20
- ShardEntryValueValue,
21
- ShardEntryLinkValue,
22
- ShardEntryLinkAndValueValue,
23
- ShardConfig,
24
- ShardOptions,
25
- ShardBlockView,
26
- BlockFetcher
27
- }
28
-
29
- export interface BatcherShard extends ShardConfig {
30
- base?: ShardBlockView
31
- entries: BatcherShardEntry[]
32
- }
33
-
34
- export interface BatcherShardInit extends ShardOptions {
35
- base?: ShardBlockView
36
- entries?: BatcherShardEntry[]
37
- }
38
-
39
- export type BatcherShardEntry = [
40
- key: string,
41
- value: ShardEntryValueValue | ShardEntryLinkValue | ShardEntryLinkAndValueValue | ShardEntryShardValue | ShardEntryShardAndValueValue
42
- ]
43
-
44
- export type ShardEntryShardValue = [BatcherShard]
45
-
46
- export type ShardEntryShardAndValueValue = [BatcherShard, UnknownLink]
47
-
48
- export interface Batcher {
49
- /**
50
- * Put a value (a CID) for the given key. If the key exists it's value is
51
- * overwritten.
52
- */
53
- put (key: string, value: UnknownLink): Promise<void>
54
- /**
55
- * Encode all altered shards in the batch and return the new root CID and
56
- * difference blocks.
57
- */
58
- commit (): Promise<{ root: ShardLink } & ShardDiff>
59
- }