@web3-storage/pail 0.6.2 → 0.6.3-rc.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/package.json +1 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -208
- package/dist/scripts/randomcid.d.ts +0 -2
- package/dist/scripts/randomcid.d.ts.map +0 -1
- package/dist/scripts/randomcid.js +0 -10
- package/dist/scripts/words/gen.d.ts +0 -2
- package/dist/scripts/words/gen.d.ts.map +0 -1
- package/dist/scripts/words/gen.js +0 -51
- package/dist/src/api.d.ts +0 -61
- package/dist/src/api.d.ts.map +0 -1
- package/dist/src/api.js +0 -1
- package/dist/src/batch/api.d.ts +0 -31
- package/dist/src/batch/api.d.ts.map +0 -1
- package/dist/src/batch/api.js +0 -1
- package/dist/src/batch/index.d.ts +0 -23
- package/dist/src/batch/index.d.ts.map +0 -1
- package/dist/src/batch/index.js +0 -241
- package/dist/src/batch/shard.d.ts +0 -3
- package/dist/src/batch/shard.d.ts.map +0 -1
- package/dist/src/batch/shard.js +0 -12
- package/dist/src/block.d.ts +0 -35
- package/dist/src/block.d.ts.map +0 -1
- package/dist/src/block.js +0 -66
- package/dist/src/clock/api.d.ts +0 -10
- package/dist/src/clock/api.d.ts.map +0 -1
- package/dist/src/clock/api.js +0 -1
- package/dist/src/clock/index.d.ts +0 -48
- package/dist/src/clock/index.d.ts.map +0 -1
- package/dist/src/clock/index.js +0 -199
- package/dist/src/crdt/api.d.ts +0 -26
- package/dist/src/crdt/api.d.ts.map +0 -1
- package/dist/src/crdt/api.js +0 -1
- package/dist/src/crdt/batch/api.d.ts +0 -11
- package/dist/src/crdt/batch/api.d.ts.map +0 -1
- package/dist/src/crdt/batch/api.js +0 -1
- package/dist/src/crdt/batch/index.d.ts +0 -5
- package/dist/src/crdt/batch/index.d.ts.map +0 -1
- package/dist/src/crdt/batch/index.js +0 -140
- package/dist/src/crdt/index.d.ts +0 -9
- package/dist/src/crdt/index.d.ts.map +0 -1
- package/dist/src/crdt/index.js +0 -344
- package/dist/src/diff.d.ts +0 -13
- package/dist/src/diff.d.ts.map +0 -1
- package/dist/src/diff.js +0 -151
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -356
- package/dist/src/merge.d.ts +0 -5
- package/dist/src/merge.d.ts.map +0 -1
- package/dist/src/merge.js +0 -42
- package/dist/src/shard.d.ts +0 -43
- package/dist/src/shard.d.ts.map +0 -1
- package/dist/src/shard.js +0 -166
- package/dist/test/batch.test.d.ts +0 -2
- package/dist/test/batch.test.d.ts.map +0 -1
- package/dist/test/batch.test.js +0 -126
- package/dist/test/clock.test.d.ts +0 -2
- package/dist/test/clock.test.d.ts.map +0 -1
- package/dist/test/clock.test.js +0 -244
- package/dist/test/crdt.test.d.ts +0 -2
- package/dist/test/crdt.test.d.ts.map +0 -1
- package/dist/test/crdt.test.js +0 -271
- package/dist/test/del.test.d.ts +0 -2
- package/dist/test/del.test.d.ts.map +0 -1
- package/dist/test/del.test.js +0 -21
- package/dist/test/diff.test.d.ts +0 -2
- package/dist/test/diff.test.d.ts.map +0 -1
- package/dist/test/diff.test.js +0 -38
- package/dist/test/entries.test.d.ts +0 -2
- package/dist/test/entries.test.d.ts.map +0 -1
- package/dist/test/entries.test.js +0 -210
- package/dist/test/get.test.d.ts +0 -2
- package/dist/test/get.test.d.ts.map +0 -1
- package/dist/test/get.test.js +0 -26
- package/dist/test/helpers.d.ts +0 -35
- package/dist/test/helpers.d.ts.map +0 -1
- package/dist/test/helpers.js +0 -168
- package/dist/test/put.test.d.ts +0 -2
- package/dist/test/put.test.d.ts.map +0 -1
- package/dist/test/put.test.js +0 -165
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vitest.config.d.ts +0 -3
- package/dist/vitest.config.d.ts.map +0 -1
- package/dist/vitest.config.js +0 -13
package/package.json
CHANGED
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../cli.js"],"names":[],"mappings":""}
|
package/dist/cli.js
DELETED
|
@@ -1,208 +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
|
-
const cli = sade('pail')
|
|
19
|
-
.option('--path', 'Path to data store.', './pail.car');
|
|
20
|
-
cli.command('put <key> <value>')
|
|
21
|
-
.describe('Put a value (a CID) for the given key. If the key exists it\'s value is overwritten.')
|
|
22
|
-
.alias('set')
|
|
23
|
-
.action(async (key, value, opts) => {
|
|
24
|
-
const { root: prevRoot, blocks } = await openPail(opts.path);
|
|
25
|
-
const { root, additions, removals } = await put(blocks, prevRoot, key, CID.parse(value));
|
|
26
|
-
await updatePail(opts.path, blocks, root, { additions, removals });
|
|
27
|
-
console.log(clc.red(`--- ${prevRoot}`));
|
|
28
|
-
console.log(clc.green(`+++ ${root}`));
|
|
29
|
-
console.log(clc.magenta('@@ -1 +1 @@'));
|
|
30
|
-
additions.forEach(b => console.log(clc.green(`+${b.cid}`)));
|
|
31
|
-
removals.forEach(b => console.log(clc.red(`-${b.cid}`)));
|
|
32
|
-
});
|
|
33
|
-
cli.command('get <key>')
|
|
34
|
-
.describe('Get the stored value for the given key from the pail. If the key is not found, `undefined` is returned.')
|
|
35
|
-
.action(async (key, opts) => {
|
|
36
|
-
const { root, blocks } = await openPail(opts.path);
|
|
37
|
-
const value = await get(blocks, root, key);
|
|
38
|
-
if (value)
|
|
39
|
-
console.log(value.toString());
|
|
40
|
-
});
|
|
41
|
-
cli.command('del <key>')
|
|
42
|
-
.describe('Delete the value for the given key from the pail. If the key is not found no operation occurs.')
|
|
43
|
-
.alias('delete', 'rm', 'remove')
|
|
44
|
-
.action(async (key, opts) => {
|
|
45
|
-
const { root: prevRoot, blocks } = await openPail(opts.path);
|
|
46
|
-
const { root, additions, removals } = await del(blocks, prevRoot, key);
|
|
47
|
-
await updatePail(opts.path, blocks, root, { additions, removals });
|
|
48
|
-
console.log(clc.red(`--- ${prevRoot}`));
|
|
49
|
-
console.log(clc.green(`+++ ${root}`));
|
|
50
|
-
console.log(clc.magenta('@@ -1 +1 @@'));
|
|
51
|
-
additions.forEach(b => console.log(clc.green(`+ ${b.cid}`)));
|
|
52
|
-
removals.forEach(b => console.log(clc.red(`- ${b.cid}`)));
|
|
53
|
-
});
|
|
54
|
-
cli.command('ls')
|
|
55
|
-
.describe('List entries in the pail.')
|
|
56
|
-
.alias('list')
|
|
57
|
-
.option('-p, --prefix', 'Key prefix to filter by.')
|
|
58
|
-
.option('--gt', 'Filter results by keys greater than this string.')
|
|
59
|
-
.option('--lt', 'Filter results by keys less than this string.')
|
|
60
|
-
.option('--json', 'Format output as newline delimted JSON.')
|
|
61
|
-
.action(async (opts) => {
|
|
62
|
-
const { root, blocks } = await openPail(opts.path);
|
|
63
|
-
let n = 0;
|
|
64
|
-
for await (const [k, v] of entries(blocks, root, { prefix: opts.prefix, gt: opts.gt, lt: opts.lt })) {
|
|
65
|
-
console.log(opts.json ? JSON.stringify({ key: k, value: v.toString() }) : `${k}\t${v}`);
|
|
66
|
-
n++;
|
|
67
|
-
}
|
|
68
|
-
if (!opts.json)
|
|
69
|
-
console.log(`total ${n}`);
|
|
70
|
-
});
|
|
71
|
-
cli.command('tree')
|
|
72
|
-
.describe('Visualise the pail.')
|
|
73
|
-
.alias('vis')
|
|
74
|
-
.action(async (opts) => {
|
|
75
|
-
const { root, blocks } = await openPail(opts.path);
|
|
76
|
-
const shards = new ShardFetcher(blocks);
|
|
77
|
-
const rshard = await shards.get(root);
|
|
78
|
-
/** @type {archy.Data} */
|
|
79
|
-
const archyRoot = { label: `Shard(${clc.yellow(rshard.cid.toString())}) ${rshard.bytes.length + 'b'}`, nodes: [] };
|
|
80
|
-
/** @param {API.ShardEntry} entry */
|
|
81
|
-
const getData = async ([k, v]) => {
|
|
82
|
-
if (!Array.isArray(v)) {
|
|
83
|
-
return { label: `Key(${clc.magenta(k)})`, nodes: [{ label: `Value(${clc.cyan(v)})` }] };
|
|
84
|
-
}
|
|
85
|
-
/** @type {archy.Data} */
|
|
86
|
-
const data = { label: `Key(${clc.magenta(k)})`, nodes: [] };
|
|
87
|
-
if (v[1])
|
|
88
|
-
data.nodes?.push({ label: `Value(${clc.cyan(v[1])})` });
|
|
89
|
-
const blk = await shards.get(v[0]);
|
|
90
|
-
data.nodes?.push({
|
|
91
|
-
label: `Shard(${clc.yellow(v[0])}) ${blk.bytes.length + 'b'}`,
|
|
92
|
-
nodes: await Promise.all(blk.value.entries.map(e => getData(e)))
|
|
93
|
-
});
|
|
94
|
-
return data;
|
|
95
|
-
};
|
|
96
|
-
for (const entry of rshard.value.entries) {
|
|
97
|
-
archyRoot.nodes?.push(await getData(entry));
|
|
98
|
-
}
|
|
99
|
-
console.log(archy(archyRoot));
|
|
100
|
-
});
|
|
101
|
-
cli.command('diff <path>')
|
|
102
|
-
.describe('Find the differences between this pail and the passed pail.')
|
|
103
|
-
.option('-k, --keys', 'Output key/value diff.')
|
|
104
|
-
.action(async (path, opts) => {
|
|
105
|
-
const [{ root: aroot, blocks: ablocks }, { root: broot, blocks: bblocks }] = await Promise.all([openPail(opts.path), openPail(path)]);
|
|
106
|
-
if (aroot.toString() === broot.toString())
|
|
107
|
-
return;
|
|
108
|
-
const fetcher = new MultiBlockFetcher(ablocks, bblocks);
|
|
109
|
-
const { shards: { additions, removals }, keys } = await difference(fetcher, aroot, broot);
|
|
110
|
-
console.log(clc.red(`--- ${aroot}`));
|
|
111
|
-
console.log(clc.green(`+++ ${broot}`));
|
|
112
|
-
console.log(clc.magenta('@@ -1 +1 @@'));
|
|
113
|
-
if (opts.keys) {
|
|
114
|
-
keys.forEach(([k, v]) => {
|
|
115
|
-
if (v[0] != null)
|
|
116
|
-
console.log(clc.red(`- ${k}\t${v[0]}`));
|
|
117
|
-
if (v[1] != null)
|
|
118
|
-
console.log(clc.green(`+ ${k}\t${v[1]}`));
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
additions.forEach(b => console.log(clc.green(`+ ${b.cid}`)));
|
|
123
|
-
removals.forEach(b => console.log(clc.red(`- ${b.cid}`)));
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
cli.command('merge <path>')
|
|
127
|
-
.describe('Merge the passed pail into this pail.')
|
|
128
|
-
.action(async (path, opts) => {
|
|
129
|
-
const [{ root: aroot, blocks: ablocks }, { root: broot, blocks: bblocks }] = await Promise.all([openPail(opts.path), openPail(path)]);
|
|
130
|
-
if (aroot.toString() === broot.toString())
|
|
131
|
-
return;
|
|
132
|
-
const fetcher = new MultiBlockFetcher(ablocks, bblocks);
|
|
133
|
-
const { root, additions, removals } = await merge(fetcher, aroot, [broot]);
|
|
134
|
-
await updatePail(opts.path, ablocks, root, { additions, removals });
|
|
135
|
-
console.log(clc.red(`--- ${aroot}`));
|
|
136
|
-
console.log(clc.green(`+++ ${root}`));
|
|
137
|
-
console.log(clc.magenta('@@ -1 +1 @@'));
|
|
138
|
-
additions.forEach(b => console.log(clc.green(`+ ${b.cid}`)));
|
|
139
|
-
removals.forEach(b => console.log(clc.red(`- ${b.cid}`)));
|
|
140
|
-
});
|
|
141
|
-
cli.parse(process.argv);
|
|
142
|
-
/**
|
|
143
|
-
* @param {string} path
|
|
144
|
-
* @returns {Promise<{ root: API.ShardLink, blocks: MemoryBlockstore }>}
|
|
145
|
-
*/
|
|
146
|
-
async function openPail(path) {
|
|
147
|
-
const blocks = new MemoryBlockstore();
|
|
148
|
-
try {
|
|
149
|
-
const carReader = new CARReaderStream();
|
|
150
|
-
const readable = /** @type {ReadableStream<Uint8Array>} */ (Readable.toWeb(fs.createReadStream(path)));
|
|
151
|
-
await readable.pipeThrough(carReader).pipeTo(new WritableStream({ write: b => blocks.put(b.cid, b.bytes) }));
|
|
152
|
-
const header = await carReader.getHeader();
|
|
153
|
-
if (!isShardLink(header.roots[0]))
|
|
154
|
-
throw new Error(`not a shard: ${header.roots[0]}`);
|
|
155
|
-
return { root: header.roots[0], blocks };
|
|
156
|
-
}
|
|
157
|
-
catch (err) {
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
if (err.code !== 'ENOENT')
|
|
160
|
-
throw new Error('failed to open bucket', { cause: err });
|
|
161
|
-
const rootblk = await ShardBlock.create();
|
|
162
|
-
blocks.put(rootblk.cid, rootblk.bytes);
|
|
163
|
-
return { root: rootblk.cid, blocks };
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* @param {string} path
|
|
168
|
-
* @param {MemoryBlockstore} blocks
|
|
169
|
-
* @param {API.ShardLink} root
|
|
170
|
-
* @param {API.ShardDiff} diff
|
|
171
|
-
*/
|
|
172
|
-
async function updatePail(path, blocks, root, { additions, removals }) {
|
|
173
|
-
const tmp = join(os.tmpdir(), `pail${Date.now()}.car`);
|
|
174
|
-
const iterator = blocks.entries();
|
|
175
|
-
const readable = new ReadableStream({
|
|
176
|
-
start(controller) {
|
|
177
|
-
for (const b of additions)
|
|
178
|
-
controller.enqueue(b);
|
|
179
|
-
},
|
|
180
|
-
pull(controller) {
|
|
181
|
-
for (const b of iterator) {
|
|
182
|
-
if (removals.some(r => b.cid.toString() === r.cid.toString()))
|
|
183
|
-
continue;
|
|
184
|
-
return controller.enqueue(b);
|
|
185
|
-
}
|
|
186
|
-
controller.close();
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
await readable.pipeThrough(new CARWriterStream([root])).pipeTo(Writable.toWeb(fs.createWriteStream(tmp)));
|
|
190
|
-
const old = `${path}-${new Date().toISOString()}`;
|
|
191
|
-
try {
|
|
192
|
-
await fs.promises.rename(path, old);
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
// @ts-ignore
|
|
196
|
-
if (err.code !== 'ENOENT')
|
|
197
|
-
throw err;
|
|
198
|
-
}
|
|
199
|
-
await fs.promises.rename(tmp, path);
|
|
200
|
-
try {
|
|
201
|
-
await fs.promises.rm(old);
|
|
202
|
-
}
|
|
203
|
-
catch (err) {
|
|
204
|
-
// @ts-ignore
|
|
205
|
-
if (err.code !== 'ENOENT')
|
|
206
|
-
throw err;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"randomcid.d.ts","sourceRoot":"","sources":["../../scripts/randomcid.js"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CID } from 'multiformats/cid';
|
|
2
|
-
import * as raw from 'multiformats/codecs/raw';
|
|
3
|
-
import { sha256 } from 'multiformats/hashes/sha2';
|
|
4
|
-
import { randomBytes } from '../test/helpers.js';
|
|
5
|
-
async function main() {
|
|
6
|
-
const bytes = await randomBytes(32);
|
|
7
|
-
const hash = await sha256.digest(bytes);
|
|
8
|
-
process.stdout.write(CID.create(1, raw.code, hash).toString());
|
|
9
|
-
}
|
|
10
|
-
main();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../scripts/words/gen.js"],"names":[],"mappings":""}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { Readable } from 'node:stream';
|
|
3
|
-
import { CarWriter } from '@ipld/car';
|
|
4
|
-
import { CID } from 'multiformats/cid';
|
|
5
|
-
import * as raw from 'multiformats/codecs/raw';
|
|
6
|
-
import { sha256 } from 'multiformats/hashes/sha2';
|
|
7
|
-
import { put } from '../../src/index.js';
|
|
8
|
-
import { ShardBlock } from '../../src/shard.js';
|
|
9
|
-
import { MemoryBlockstore } from '../../src/block.js';
|
|
10
|
-
/** @param {string} str */
|
|
11
|
-
async function stringToCID(str) {
|
|
12
|
-
const hash = await sha256.digest(new TextEncoder().encode(str));
|
|
13
|
-
return CID.create(1, raw.code, hash);
|
|
14
|
-
}
|
|
15
|
-
async function main() {
|
|
16
|
-
const data = await fs.promises.readFile('/usr/share/dict/words', 'utf8');
|
|
17
|
-
const words = data.split(/\n/);
|
|
18
|
-
const cids = await Promise.all(words.map(stringToCID));
|
|
19
|
-
const blocks = new MemoryBlockstore();
|
|
20
|
-
const rootblk = await ShardBlock.create();
|
|
21
|
-
blocks.putSync(rootblk.cid, rootblk.bytes);
|
|
22
|
-
console.time(`put x${words.length}`);
|
|
23
|
-
/** @type {import('../../src/api.ts').ShardLink} */
|
|
24
|
-
let root = rootblk.cid;
|
|
25
|
-
for (const [i, word] of words.entries()) {
|
|
26
|
-
const res = await put(blocks, root, word, cids[i]);
|
|
27
|
-
root = res.root;
|
|
28
|
-
for (const b of res.additions) {
|
|
29
|
-
blocks.putSync(b.cid, b.bytes);
|
|
30
|
-
}
|
|
31
|
-
for (const b of res.removals) {
|
|
32
|
-
blocks.deleteSync(b.cid);
|
|
33
|
-
}
|
|
34
|
-
if (i % 1000 === 0) {
|
|
35
|
-
console.log(`${Math.floor(i / words.length * 100)}%`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
console.timeEnd(`put x${words.length}`);
|
|
39
|
-
// @ts-expect-error
|
|
40
|
-
const { writer, out } = CarWriter.create(root);
|
|
41
|
-
const finishPromise = new Promise(resolve => {
|
|
42
|
-
Readable.from(out).pipe(fs.createWriteStream('./pail.car')).on('finish', () => resolve(true));
|
|
43
|
-
});
|
|
44
|
-
for (const b of blocks.entries()) {
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
await writer.put(b);
|
|
47
|
-
}
|
|
48
|
-
await writer.close();
|
|
49
|
-
await finishPromise;
|
|
50
|
-
}
|
|
51
|
-
main();
|
package/dist/src/api.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Version } from 'multiformats';
|
|
2
|
-
import type { Link, UnknownLink } from 'multiformats/link/interface';
|
|
3
|
-
import type { Block, BlockView } from 'multiformats/block/interface';
|
|
4
|
-
import { sha256 } from 'multiformats/hashes/sha2';
|
|
5
|
-
import * as dagCBOR from '@ipld/dag-cbor';
|
|
6
|
-
export { Link, UnknownLink, BlockView, Block, Version };
|
|
7
|
-
export type ShardEntryValueValue = UnknownLink;
|
|
8
|
-
export type ShardEntryLinkValue = [ShardLink];
|
|
9
|
-
export type ShardEntryLinkAndValueValue = [ShardLink, UnknownLink];
|
|
10
|
-
export type ShardValueEntry = [key: string, value: ShardEntryValueValue];
|
|
11
|
-
export type ShardLinkEntry = [key: string, value: ShardEntryLinkValue | ShardEntryLinkAndValueValue];
|
|
12
|
-
/** Single key/value entry within a shard. */
|
|
13
|
-
export type ShardEntry = [key: string, value: ShardEntryValueValue | ShardEntryLinkValue | ShardEntryLinkAndValueValue];
|
|
14
|
-
export interface Shard extends ShardConfig {
|
|
15
|
-
entries: ShardEntry[];
|
|
16
|
-
}
|
|
17
|
-
export type ShardLink = Link<Shard, typeof dagCBOR.code, typeof sha256.code, 1>;
|
|
18
|
-
export interface ShardBlockView extends BlockView<Shard, typeof dagCBOR.code, typeof sha256.code, 1> {
|
|
19
|
-
}
|
|
20
|
-
export interface ShardDiff {
|
|
21
|
-
additions: ShardBlockView[];
|
|
22
|
-
removals: ShardBlockView[];
|
|
23
|
-
}
|
|
24
|
-
export interface BlockFetcher {
|
|
25
|
-
get: <T = unknown, C extends number = number, A extends number = number, V extends Version = 1>(link: Link<T, C, A, V>) => Promise<Block<T, C, A, V> | undefined>;
|
|
26
|
-
}
|
|
27
|
-
export interface ShardConfig {
|
|
28
|
-
/** Shard compatibility version. */
|
|
29
|
-
version: number;
|
|
30
|
-
/**
|
|
31
|
-
* Characters allowed in keys, referring to a known character set.
|
|
32
|
-
* e.g. "ascii" refers to the printable ASCII characters in the code range 32-126.
|
|
33
|
-
*/
|
|
34
|
-
keyChars: string;
|
|
35
|
-
/** Max key size in bytes - default 4096 bytes. */
|
|
36
|
-
maxKeySize: number;
|
|
37
|
-
/** The key prefix from the root to this shard. */
|
|
38
|
-
prefix: string;
|
|
39
|
-
}
|
|
40
|
-
export type ShardOptions = Partial<ShardConfig>;
|
|
41
|
-
export interface KeyPrefixOption {
|
|
42
|
-
/** Filter results to entries with keys prefixed with this string. */
|
|
43
|
-
prefix: string;
|
|
44
|
-
}
|
|
45
|
-
export type KeyRangeOption = KeyLowerBoundRangeOption | KeyUpperBoundRangeOption | (KeyLowerBoundRangeOption & KeyUpperBoundRangeOption);
|
|
46
|
-
export type KeyLowerBoundRangeOption = KeyLowerBoundRangeExclusiveOption | KeyLowerBoundRangeInclusiveOption;
|
|
47
|
-
export interface KeyLowerBoundRangeExclusiveOption {
|
|
48
|
-
gt: string;
|
|
49
|
-
}
|
|
50
|
-
export interface KeyLowerBoundRangeInclusiveOption {
|
|
51
|
-
gte: string;
|
|
52
|
-
}
|
|
53
|
-
export type KeyUpperBoundRangeOption = KeyUpperBoundRangeExclusiveOption | KeyUpperBoundRangeInclusiveOption;
|
|
54
|
-
export interface KeyUpperBoundRangeExclusiveOption {
|
|
55
|
-
lt: string;
|
|
56
|
-
}
|
|
57
|
-
export interface KeyUpperBoundRangeInclusiveOption {
|
|
58
|
-
lte: string;
|
|
59
|
-
}
|
|
60
|
-
export type EntriesOptions = KeyPrefixOption | KeyRangeOption;
|
|
61
|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AA;CACZ;AAED,MAAM,MAAM,wBAAwB,GAChC,iCAAiC,GACjC,iCAAiC,CAAA;AAErC,MAAM,WAAW,iCAAiC;IAChD,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,iCAAiC;IAChD,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,MAAM,cAAc,GACtB,eAAe,GACf,cAAc,CAAA"}
|
package/dist/src/api.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/src/batch/api.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { UnknownLink, ShardLink, ShardDiff, ShardEntry, ShardEntryValueValue, ShardEntryLinkValue, ShardEntryLinkAndValueValue, ShardConfig, ShardOptions, ShardBlockView, BlockFetcher } from '../api.js';
|
|
2
|
-
export { UnknownLink, ShardLink, ShardDiff, ShardEntry, ShardEntryValueValue, ShardEntryLinkValue, ShardEntryLinkAndValueValue, ShardConfig, ShardOptions, ShardBlockView, BlockFetcher };
|
|
3
|
-
export interface BatcherShard extends ShardConfig {
|
|
4
|
-
base?: ShardBlockView;
|
|
5
|
-
entries: BatcherShardEntry[];
|
|
6
|
-
}
|
|
7
|
-
export interface BatcherShardInit extends ShardOptions {
|
|
8
|
-
base?: ShardBlockView;
|
|
9
|
-
entries?: BatcherShardEntry[];
|
|
10
|
-
}
|
|
11
|
-
export type BatcherShardEntry = [
|
|
12
|
-
key: string,
|
|
13
|
-
value: ShardEntryValueValue | ShardEntryLinkValue | ShardEntryLinkAndValueValue | ShardEntryShardValue | ShardEntryShardAndValueValue
|
|
14
|
-
];
|
|
15
|
-
export type ShardEntryShardValue = [BatcherShard];
|
|
16
|
-
export type ShardEntryShardAndValueValue = [BatcherShard, UnknownLink];
|
|
17
|
-
export interface Batcher {
|
|
18
|
-
/**
|
|
19
|
-
* Put a value (a CID) for the given key. If the key exists it's value is
|
|
20
|
-
* overwritten.
|
|
21
|
-
*/
|
|
22
|
-
put: (key: string, value: UnknownLink) => Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Encode all altered shards in the batch and return the new root CID and
|
|
25
|
-
* difference blocks.
|
|
26
|
-
*/
|
|
27
|
-
commit: () => Promise<{
|
|
28
|
-
root: ShardLink;
|
|
29
|
-
} & ShardDiff>;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/batch/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,WAAW,EACX,YAAY,EACZ,cAAc,EACd,YAAY,EACb,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,WAAW,EACX,YAAY,EACZ,cAAc,EACd,YAAY,EACb,CAAA;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,IAAI,CAAC,EAAE,cAAc,CAAA;IACrB,OAAO,EAAE,iBAAiB,EAAE,CAAA;CAC7B;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,IAAI,CAAC,EAAE,cAAc,CAAA;IACrB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAC9B;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,oBAAoB,GAAG,mBAAmB,GAAG,2BAA2B,GAAG,oBAAoB,GAAG,4BAA4B;CACtI,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC,YAAY,CAAC,CAAA;AAEjD,MAAM,MAAM,4BAA4B,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;AAEtE,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD;;;OAGG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC,CAAA;CACvD"}
|
package/dist/src/batch/api.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function put(blocks: API.BlockFetcher, shard: API.BatcherShard, key: string, value: API.UnknownLink): Promise<void>;
|
|
2
|
-
export function traverse(shards: ShardFetcher, shard: API.BatcherShard, key: string): Promise<{
|
|
3
|
-
shard: API.BatcherShard;
|
|
4
|
-
key: string;
|
|
5
|
-
}>;
|
|
6
|
-
export function commit(shard: API.BatcherShard): Promise<{
|
|
7
|
-
root: import("multiformats").CID<import("../api.js").Shard, 113, 18, 1>;
|
|
8
|
-
additions: API.ShardBlockView[];
|
|
9
|
-
removals: API.ShardBlockView[];
|
|
10
|
-
}>;
|
|
11
|
-
export function create(blocks: API.BlockFetcher, root: API.ShardLink): Promise<API.Batcher>;
|
|
12
|
-
export class BatchCommittedError extends Error {
|
|
13
|
-
static code: string;
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} [message]
|
|
16
|
-
* @param {ErrorOptions} [options]
|
|
17
|
-
*/
|
|
18
|
-
constructor(message?: string, options?: ErrorOptions);
|
|
19
|
-
code: string;
|
|
20
|
-
}
|
|
21
|
-
import * as API from './api.js';
|
|
22
|
-
import { ShardFetcher } from '../shard.js';
|
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/batch/index.js"],"names":[],"mappings":"AAiEO,4BANI,GAAG,CAAC,YAAY,SAChB,GAAG,CAAC,YAAY,OAChB,MAAM,SACN,GAAG,CAAC,WAAW,GACb,OAAO,CAAC,IAAI,CAAC,CAsGzB;AAWM,iCALI,YAAY,SACZ,GAAG,CAAC,YAAY,OAChB,MAAM,GACJ,OAAO,CAAC;IAAE,KAAK,EAAE,GAAG,CAAC,YAAY,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAiB7D;AAQM,8BAFI,GAAG,CAAC,YAAY;;;;GAkC1B;AAaM,+BAJI,GAAG,CAAC,YAAY,QAChB,GAAG,CAAC,SAAS,GACX,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAE6C;AAE9E;IAUE,oBAAmC;IATnC;;;OAGG;IACH,sBAHW,MAAM,YACN,YAAY,EAKtB;IADC,aAAoC;CAIvC;qBAhQoB,UAAU;6BACgB,aAAa"}
|