Skip to content

Commit b07f31d

Browse files
committed
version
1 parent 6b42b6f commit b07f31d

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/ordered-keyvalue.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,37 +118,46 @@ const OrderedKeyValue =
118118
let count = 0;
119119
const orderedLogEntries: LogEntry<DagCborEncodable>[] = [];
120120
for await (const entry of log.traverse()) {
121-
orderedLogEntries.unshift(entry)
122-
};
121+
orderedLogEntries.unshift(entry);
122+
}
123123

124-
let finalEntries: {key: string; value: unknown; position: number, hash: string}[] = []
124+
let finalEntries: {
125+
key: string;
126+
value: unknown;
127+
position: number;
128+
hash: string;
129+
}[] = [];
125130
for (const entry of orderedLogEntries) {
126131
const { op, key, value } = entry.payload;
127132
if (!key) return;
128133

129134
if (op === "PUT") {
130-
finalEntries = finalEntries.filter(e=>e.key !== key);
135+
finalEntries = finalEntries.filter((e) => e.key !== key);
131136

132137
const putValue = value as { value: unknown; position?: number };
133138

134139
const hash = entry.hash;
135140

136-
const position = putValue.position !== undefined ? putValue.position : -1;
141+
const position =
142+
putValue.position !== undefined ? putValue.position : -1;
137143
finalEntries.push({
138144
key,
139145
value: putValue.value,
140146
position,
141-
hash
147+
hash,
142148
});
143-
count++
149+
count++;
144150
} else if (op === "MOVE") {
145-
const existingEntry = finalEntries.find(e=>e.key === key);
151+
const existingEntry = finalEntries.find((e) => e.key === key);
146152
if (existingEntry) {
147153
existingEntry.position = value as number;
148-
finalEntries = [...finalEntries.filter(e=>e.key !== key), existingEntry]
154+
finalEntries = [
155+
...finalEntries.filter((e) => e.key !== key),
156+
existingEntry,
157+
];
149158
}
150159
} else if (op === "DEL") {
151-
finalEntries = finalEntries.filter(e=>e.key !== key);
160+
finalEntries = finalEntries.filter((e) => e.key !== key);
152161
}
153162
if (amount !== undefined && count >= amount) {
154163
break;
@@ -169,7 +178,7 @@ const OrderedKeyValue =
169178
position: number;
170179
}[] = [];
171180
for await (const entry of iterator()) {
172-
entries.push(entry)
181+
entries.push(entry);
173182
}
174183

175184
const values: {
@@ -179,14 +188,17 @@ const OrderedKeyValue =
179188
}[] = [];
180189

181190
for (const entry of entries) {
182-
const position = entry.position >= 0 ? entry.position : (entries.length + entry.position + 1)
191+
const position =
192+
entry.position >= 0
193+
? entry.position
194+
: entries.length + entry.position + 1;
183195
values.splice(position, 0, {
184196
key: entry.key,
185197
value: entry.value,
186198
hash: entry.hash,
187-
})
199+
});
188200
}
189-
201+
190202
return values;
191203
};
192204

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Generated by genversion.
2-
export const version = "1.1.2";
2+
export const version = "1.1.3";

test/ordered-keyvalue.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ describe("OrderedKeyValue Database", () => {
355355
const hash2 = await db.put(key2, value2);
356356
const hash3 = await db.put(key3, value3);
357357
await db.move(key, 1);
358-
358+
359359
const actual1 = await db.all();
360360
expect(actual1).to.deep.equal([
361361
{ value: value2, key: key2, hash: hash2 },
@@ -364,7 +364,7 @@ describe("OrderedKeyValue Database", () => {
364364
]);
365365

366366
await db.move(key, 2);
367-
367+
368368
const actual2 = await db.all();
369369
expect(actual2).to.deep.equal([
370370
{ value: value2, key: key2, hash: hash2 },

0 commit comments

Comments
 (0)