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

@miniflare/durable-objects

Package Overview
Dependencies
Maintainers
4
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/durable-objects - npm Package Compare versions

Comparing version 2.9.0-next.1 to 2.9.0

9

dist/src/index.d.ts

@@ -30,2 +30,3 @@ /// <reference types="node" />

deleteAlarm(key: string): Promise<void>;
flushAlarms(keys?: string[]): Promise<void>;
dispose(): void;

@@ -135,2 +136,3 @@ }

constructor(ctx: PluginContext, options?: DurableObjectsOptions);
getStorage(storage: StorageFactory, id: DurableObjectId): DurableObjectStorage;
getObject(storage: StorageFactory, id: DurableObjectId): Promise<DurableObjectState>;

@@ -140,5 +142,5 @@ getNamespace(storage: StorageFactory, objectName: string): DurableObjectNamespace;

flushAlarms(storageFactory: StorageFactory, ids?: DurableObjectId[]): Promise<void>;
beforeReload(): void;
beforeReload(): Promise<void>;
reload(bindings: Context, moduleExports: Context, mounts: Map<string, Mount>): void;
dispose(): void;
dispose(): Promise<void>;
}

@@ -154,2 +156,3 @@

blockConcurrencyWhile<T>(closure: () => Promise<T>): Promise<T>;
/* Excluded from this release type: [_kRunWithGates] */
[kFetch](request: Request): Promise<Response>;

@@ -224,2 +227,4 @@ [kAlarm](): Promise<void>;

/* Excluded from this release type: _kRunWithGates */
declare const kStartTxnCount: unique symbol;

@@ -226,0 +231,0 @@

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

ShadowStorage: () => ShadowStorage,
_kRunWithGates: () => _kRunWithGates,
kAlarmExists: () => kAlarmExists

@@ -61,3 +62,3 @@ });

async setupStore(storage, persist) {
this.#store = await storage.storage(ALARM_KEY, persist);
this.#store = storage.storage(ALARM_KEY, persist);
const { keys } = await this.#store.list();

@@ -72,3 +73,3 @@ for (const { name, metadata } of keys) {

doAlarm.timeout = setTimeout(() => {
this.#deleteAlarm(objectKey, doAlarm);
void this.#deleteAlarm(objectKey, doAlarm);
this.#callback?.(objectKey);

@@ -134,2 +135,18 @@ }, Math.max(doAlarm.scheduledTime - now, 0));

}
async flushAlarms(keys) {
if (keys === void 0) {
for (const [key, alarm] of this.#alarms) {
await this.#deleteAlarm(key, alarm);
await this.#callback?.(key);
}
} else {
for (const key of keys) {
const alarm = this.#alarms.get(key);
if (alarm !== void 0) {
await this.#deleteAlarm(key, alarm);
await this.#callback?.(key);
}
}
}
}
dispose() {

@@ -181,2 +198,3 @@ if (this.#alarmTimeout) {

var kInstance = Symbol("kInstance");
var _kRunWithGates = Symbol("kRunWithGates");
var kAlarm = Symbol("kAlarm");

@@ -196,5 +214,8 @@ var kFetch = Symbol("kFetch");

}
[_kRunWithGates](closure) {
const outputGate = new import_shared2.OutputGate();
return outputGate.runWith(() => this.#inputGate.runWith(closure));
}
[kFetch](request) {
const outputGate = new import_shared2.OutputGate();
return outputGate.runWith(() => this.#inputGate.runWith(() => {
return this[_kRunWithGates](() => {
const instance = this[kInstance];

@@ -205,8 +226,7 @@ if (!instance?.fetch) {

return instance.fetch(request);
}));
});
}
[kAlarm]() {
const outputGate = new import_shared2.OutputGate();
return outputGate.runWith(() => this.#inputGate.runWith(() => {
this.storage.deleteAlarm();
return this[_kRunWithGates](async () => {
await this.storage.deleteAlarm();
const instance = this[kInstance];

@@ -217,3 +237,3 @@ if (!instance?.alarm) {

return instance.alarm();
}));
});
}

@@ -965,2 +985,11 @@ };

// packages/durable-objects/src/plugin.ts
function getObjectKeyFromId(id) {
return `${id[kObjectName]}:${id.toString()}`;
}
function getObjectIdFromKey(key) {
const colonIndex = key.lastIndexOf(":");
const objectName = key.substring(0, colonIndex);
const hexId = key.substring(colonIndex + 1);
return new DurableObjectId(objectName, hexId);
}
var DurableObjectsPlugin = class extends import_shared5.Plugin {

@@ -977,4 +1006,7 @@ durableObjects;

#bindings = {};
#objects = new Map();
#objectStorages = new Map();
#objectStates = new Map();
#alarmStore;
#alarmStoreCallback;
#alarmStoreCallbackAttached = false;
constructor(ctx, options) {

@@ -992,23 +1024,29 @@ super(ctx);

}
getStorage(storage, id) {
const key = getObjectKeyFromId(id);
let objectStorage = this.#objectStorages.get(key);
if (objectStorage !== void 0)
return objectStorage;
objectStorage = new DurableObjectStorage(storage.storage(key, this.#persist), this.#alarmStore.buildBridge(key));
this.#objectStorages.set(key, objectStorage);
return objectStorage;
}
async getObject(storage, id) {
(0, import_assert4.default)(this.#contextPromise, "beforeReload() must be called before getObject()");
await this.#contextPromise;
const key = getObjectKeyFromId(id);
let state = this.#objectStates.get(key);
if (state !== void 0)
return state;
const objectName = id[kObjectName];
const key = `${objectName}:${id.toString()}`;
let statePromise = this.#objects.get(key);
if (statePromise)
return statePromise;
statePromise = (async () => {
const objectStorage = new DurableObjectStorage(await storage.storage(key, this.#persist), this.#alarmStore.buildBridge(key));
const unnamedId = new DurableObjectId(objectName, id.toString());
const state = new DurableObjectState(unnamedId, objectStorage);
const constructor = this.#constructors.get(objectName);
(0, import_assert4.default)(constructor);
state[kInstance] = new constructor(state, this.#bindings);
if (!state[kInstance]?.alarm)
objectStorage[kAlarmExists] = false;
return state;
})();
this.#objects.set(key, statePromise);
return statePromise;
const unnamedId = new DurableObjectId(objectName, id.toString());
const objectStorage = this.getStorage(storage, id);
state = new DurableObjectState(unnamedId, objectStorage);
this.#objectStates.set(key, state);
const constructor = this.#constructors.get(objectName);
(0, import_assert4.default)(constructor);
state[kInstance] = new constructor(state, this.#bindings);
if (!state[kInstance]?.alarm)
objectStorage[kAlarmExists] = false;
return state;
}

@@ -1030,28 +1068,14 @@ getNamespace(storage, objectName) {

}
async #setupAlarms(storage) {
async #setupAlarms(storageFactory) {
if (this.durableObjectsAlarms === false)
return;
await this.#alarmStore.setupStore(storage, this.#persist);
await this.#alarmStore.setupAlarms(async (objectKey) => {
const index = objectKey.lastIndexOf(":");
const objectName = objectKey.substring(0, index);
const hexId = objectKey.substring(index + 1);
const id = new DurableObjectId(objectName, hexId);
const state = await this.getObject(storage, id);
await this.#alarmStore.setupStore(storageFactory, this.#persist);
this.#alarmStoreCallback = async (objectKey) => {
const id = getObjectIdFromKey(objectKey);
const state = await this.getObject(storageFactory, id);
await this.#executeAlarm(state);
});
};
}
async flushAlarms(storageFactory, ids) {
if (ids !== void 0) {
for (const id of ids) {
const state = await this.getObject(storageFactory, id);
await this.#executeAlarm(state);
this.#alarmStore.deleteAlarm(`${id[kObjectName]}:${id.toString()}`);
}
} else {
for (const [key, state] of this.#objects) {
await this.#executeAlarm(await state);
this.#alarmStore.deleteAlarm(key);
}
}
flushAlarms(storageFactory, ids) {
return this.#alarmStore.flushAlarms(ids?.map(getObjectKeyFromId));
}

@@ -1066,5 +1090,10 @@ async #executeAlarm(state) {

}
beforeReload() {
this.#objects.clear();
async beforeReload() {
this.#objectStorages.clear();
this.#objectStates.clear();
this.#contextPromise = new Promise((resolve) => this.#contextResolve = resolve);
if (!this.#alarmStoreCallbackAttached && this.#alarmStoreCallback !== void 0) {
this.#alarmStoreCallbackAttached = true;
await this.#alarmStore.setupAlarms(this.#alarmStoreCallback);
}
}

@@ -1096,5 +1125,5 @@ reload(bindings, moduleExports, mounts) {

}
dispose() {
async dispose() {
await this.beforeReload();
this.#alarmStore.dispose();
return this.beforeReload();
}

@@ -1158,4 +1187,5 @@ };

ShadowStorage,
_kRunWithGates,
kAlarmExists
});
//# sourceMappingURL=index.js.map
{
"name": "@miniflare/durable-objects",
"version": "2.9.0-next.1",
"version": "2.9.0",
"description": "Durable Objects module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

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

"dependencies": {
"@miniflare/core": "2.9.0-next.1",
"@miniflare/shared": "2.9.0-next.1",
"@miniflare/storage-memory": "2.9.0-next.1",
"@miniflare/core": "2.9.0",
"@miniflare/shared": "2.9.0",
"@miniflare/storage-memory": "2.9.0",
"undici": "5.9.1"
},
"devDependencies": {
"@miniflare/cache": "2.9.0-next.1",
"@miniflare/runner-vm": "2.9.0-next.1",
"@miniflare/shared-test": "2.9.0-next.1"
"@miniflare/cache": "2.9.0",
"@miniflare/runner-vm": "2.9.0",
"@miniflare/shared-test": "2.9.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