Skip to content

Commit 3bc2be1

Browse files
committed
fixes breaking serialization of terms that serialize to strings longer than 127 chars by explicitly setting valueEncoding in level options (closes #152)
1 parent 78fd616 commit 3bc2be1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/quadstore.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import {
4747
emptyObject,
4848
defaultIndexes,
4949
separator,
50+
levelPutOpts,
51+
levelDelOpts,
5052
} from './utils/constants';
5153
import { consumeOneByOne } from './utils/consumeonebyone';
5254
import { consumeInBatches } from './utils/consumeinbatches';
@@ -187,7 +189,7 @@ export class Quadstore implements Store {
187189
valueOffset = baseValueOffset + i * 16;
188190
index = indexes[i];
189191
const key = quadWriter.write(index.prefix, value, valueOffset, quad, index.terms, this.prefixes);
190-
batch = batch.put(key, viewUint16ArrayAsUint8Array(value, valueOffset, 16));
192+
batch = batch.put(key, viewUint16ArrayAsUint8Array(value, valueOffset, 16), levelPutOpts);
191193
}
192194
return batch;
193195
}
@@ -228,7 +230,7 @@ export class Quadstore implements Store {
228230
for (let i = 0, il = indexes.length, index; i < il; i += 1) {
229231
index = indexes[i];
230232
const key = quadWriter.write(index.prefix, undefined, 0, quad, index.terms, this.prefixes);
231-
batch = batch.del(key);
233+
batch = batch.del(key, levelDelOpts);
232234
}
233235
return batch;
234236
}

src/utils/constants.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
import { TermName } from '../types';
2+
import type { TermName } from '../types';
3+
import type { AbstractChainedBatchPutOptions, AbstractChainedBatchDelOptions } from 'abstract-level';
34

45
export const emptyObject: { [key: string]: any } = {};
56

@@ -21,3 +22,12 @@ export const defaultIndexes: TermName[][] = [
2122
['predicate', 'object', 'graph', 'subject'],
2223
['graph', 'predicate', 'object', 'subject'],
2324
];
25+
26+
export const levelPutOpts: AbstractChainedBatchPutOptions<any, any, any> = {
27+
keyEncoding: 'utf8',
28+
valueEncoding: 'view',
29+
};
30+
31+
export const levelDelOpts: AbstractChainedBatchDelOptions<any, any> = {
32+
keyEncoding: 'utf8',
33+
};

0 commit comments

Comments
 (0)