Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@miniflare/storage-memory

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/storage-memory - npm Package Compare versions

Comparing version 2.6.0-d1.1 to 2.6.0

10

dist/src/index.d.ts
import { Awaitable } from '@miniflare/shared';
import { Clock } from '@miniflare/shared';
import Database from 'better-sqlite3';
import { Range } from '@miniflare/shared';
import { RangeStoredValueMeta } from '@miniflare/shared';
import { Storage } from '@miniflare/shared';

@@ -22,3 +23,5 @@ import { StorageListOptions } from '@miniflare/shared';

abstract hasMaybeExpired(key: string): Awaitable<StoredMeta | undefined>;
abstract headMaybeExpired<Meta>(key: string): Awaitable<StoredMeta<Meta> | undefined>;
abstract getMaybeExpired<Meta>(key: string): Awaitable<StoredValueMeta<Meta> | undefined>;
abstract getRangeMaybeExpired<Meta>(key: string, range: Range): Awaitable<RangeStoredValueMeta<Meta> | undefined>;
abstract deleteMaybeExpired(key: string): Awaitable<boolean>;

@@ -28,6 +31,7 @@ abstract listAllMaybeExpired<Meta>(): Awaitable<StoredKeyMeta<Meta>[]>;

has(key: string): Promise<boolean>;
head<Meta = unknown>(key: string): Promise<StoredMeta<Meta> | undefined>;
get<Meta = unknown>(key: string): Promise<StoredValueMeta<Meta> | undefined>;
getRange<Meta = unknown>(key: string, range?: Range): Promise<RangeStoredValueMeta<Meta> | undefined>;
delete(key: string): Promise<boolean>;
list<Meta = unknown>(options?: StorageListOptions): Promise<StorageListResult<StoredKeyMeta<Meta>>>;
getSqliteDatabase(): Database.Database;
}

@@ -39,3 +43,5 @@

hasMaybeExpired(key: string): StoredMeta | undefined;
headMaybeExpired<Meta>(key: string): StoredMeta<Meta> | undefined;
getMaybeExpired<Meta>(key: string): StoredValueMeta<Meta> | undefined;
getRangeMaybeExpired<Meta>(key: string, { offset, length, suffix }: Range): RangeStoredValueMeta<Meta> | undefined;
put<Meta = unknown>(key: string, value: StoredValueMeta<Meta>): void;

@@ -42,0 +48,0 @@ deleteMaybeExpired(key: string): boolean;

113

dist/src/index.js

@@ -43,2 +43,3 @@ var __create = Object.create;

function listPaginate(options, keys) {
const resKeys = [];
const direction = options?.reverse ? -1 : 1;

@@ -54,6 +55,39 @@ keys.sort((a, b) => direction * (0, import_shared.lexicographicCompare)(a.name, b.name));

}
const endIndex = options?.limit === void 0 ? keys.length : startIndex + options.limit;
const nextCursor = endIndex < keys.length ? (0, import_shared.base64Encode)(keys[endIndex - 1].name) : "";
keys = keys.slice(startIndex, endIndex);
return { keys, cursor: nextCursor };
let endIndex = startIndex;
const prefix = options?.prefix ?? "";
const delimitedPrefixes = new Set();
for (let i = startIndex; i < keys.length; i++) {
const key = keys[i];
const { name } = key;
endIndex = i;
if (options?.delimiter !== void 0 && name.startsWith(prefix) && name.slice(prefix.length).includes(options.delimiter)) {
const { delimiter } = options;
const objectKey = name.slice(prefix.length);
const delimitedPrefix = prefix + objectKey.split(delimiter)[0] + delimiter;
delimitedPrefixes.add(delimitedPrefix);
while (i < keys.length) {
const nextKey = keys[i];
const nextName = nextKey.name;
if (!nextName.startsWith(delimitedPrefix))
break;
endIndex = i;
i++;
}
i--;
} else {
resKeys.push(key);
}
if (options?.limit !== void 0 && resKeys.length + delimitedPrefixes.size >= options.limit) {
break;
}
}
const nextCursor = endIndex < keys.length - 1 ? (0, import_shared.base64Encode)(keys[endIndex].name) : "";
const res = {
keys: resKeys,
cursor: nextCursor
};
if (options?.delimiter !== void 0) {
res.delimitedPrefixes = Array.from(delimitedPrefixes);
}
return res;
}

@@ -63,3 +97,2 @@

var import_shared2 = __toModule(require("@miniflare/shared"));
var import_better_sqlite3 = __toModule(require("better-sqlite3"));
var LocalStorage = class extends import_shared2.Storage {

@@ -83,2 +116,12 @@ constructor(clock = import_shared2.defaultClock) {

}
async head(key) {
const stored = await this.headMaybeExpired(key);
if (stored === void 0)
return void 0;
if (this.expired(stored)) {
await this.deleteMaybeExpired(key);
return void 0;
}
return stored;
}
async get(key) {

@@ -94,2 +137,12 @@ const stored = await this.getMaybeExpired(key);

}
async getRange(key, range = {}) {
const stored = await this.getRangeMaybeExpired(key, range);
if (stored === void 0)
return void 0;
if (this.expired(stored)) {
await this.deleteMaybeExpired(key);
return void 0;
}
return stored;
}
async delete(key) {

@@ -118,8 +171,2 @@ const stored = await this.hasMaybeExpired(key);

}
getSqliteDatabase() {
const location = (0, import_shared2.getSQLiteNativeBindingLocation)();
return new import_better_sqlite3.default(":memory:", {
nativeBinding: location
});
}
};

@@ -141,2 +188,9 @@

}
headMaybeExpired(key) {
const stored = this.map.get(key);
return stored && {
expiration: stored.expiration,
metadata: cloneMetadata(stored.metadata)
};
}
getMaybeExpired(key) {

@@ -150,2 +204,39 @@ const stored = this.map.get(key);

}
getRangeMaybeExpired(key, { offset, length, suffix }) {
const stored = this.map.get(key);
if (stored === void 0)
return;
const { value } = stored;
const size = value.byteLength;
if (suffix !== void 0) {
if (suffix <= 0) {
throw new Error("Suffix must be > 0");
}
if (suffix > size)
suffix = size;
offset = size - suffix;
length = size - offset;
}
if (offset === void 0)
offset = 0;
if (length === void 0)
length = size - offset;
if (offset < 0)
throw new Error("Offset must be >= 0");
if (offset > size)
throw new Error("Offset must be < size");
if (length <= 0)
throw new Error("Length must be > 0");
if (offset + length > size)
length = size - offset;
return {
value: value.slice(offset, offset + length),
expiration: stored.expiration,
metadata: cloneMetadata(stored.metadata),
range: {
offset,
length
}
};
}
put(key, value) {

@@ -152,0 +243,0 @@ this.map.set(key, {

{
"name": "@miniflare/storage-memory",
"version": "2.6.0-d1.1",
"version": "2.6.0",
"description": "In-memory storage module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

@@ -38,7 +38,7 @@ "keywords": [

"dependencies": {
"@miniflare/shared": "2.6.0-d1.1"
"@miniflare/shared": "2.6.0"
},
"devDependencies": {
"@miniflare/shared-test": "2.6.0-d1.1"
"@miniflare/shared-test": "2.6.0"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc