in src/commands/dev/mock/kv.js [42:66]
async get(key, options) {
await this._loadData();
const namespaceData = this.allData[this.namespace] || {};
if (!(key in namespaceData)) {
return undefined;
}
const value = namespaceData[key];
const type = options?.type || 'text';
switch (type) {
case 'text':
return value;
case 'json':
try {
return JSON.parse(value);
} catch (error) {
throw new Error('Failed to parse JSON');
}
case 'arrayBuffer':
const encoder = new TextEncoder();
const uint8Array = encoder.encode(value);
return uint8Array.buffer;
default:
throw new Error('Invalid type option');
}
}