Skip to content

Commit

Permalink
feat: vstorage without instance binding
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 26, 2024
1 parent f680b15 commit 2c4e2e3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/client-utils/src/vstorage-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const makeVStorage = (powers, config) => {
return data;
});

return {
const vstorage = {
url,
decode({ result: { response } }) {
const { code } = response;
Expand All @@ -65,11 +65,11 @@ export const makeVStorage = (powers, config) => {
*/
async readLatest(path = 'published') {
const raw = await readStorage(path, { kind: 'data' });
return this.decode(raw);
return vstorage.decode(raw);
},
async keys(path = 'published') {
const raw = await readStorage(path, { kind: 'children' });
return JSON.parse(this.decode(raw)).children;
return JSON.parse(vstorage.decode(raw)).children;
},
/**
* @param {string} path
Expand All @@ -78,7 +78,7 @@ export const makeVStorage = (powers, config) => {
*/
async readAt(path, height = undefined) {
const raw = await readStorage(path, { kind: 'data', height });
const txt = this.decode(raw);
const txt = vstorage.decode(raw);
/** @type {{ value: string }} */
const { value } = JSON.parse(txt);
return JSON.parse(value);
Expand All @@ -99,7 +99,7 @@ export const makeVStorage = (powers, config) => {
// console.debug('READING', { blockHeight });
let values;
try {
({ blockHeight, values } = await this.readAt(
({ blockHeight, values } = await vstorage.readAt(
path,
blockHeight && Number(blockHeight) - 1,
));
Expand Down Expand Up @@ -127,6 +127,7 @@ export const makeVStorage = (powers, config) => {
return parts.flat();
},
};
return vstorage;
};
/** @typedef {ReturnType<typeof makeVStorage>} VStorage */

Expand Down

0 comments on commit 2c4e2e3

Please sign in to comment.