miniflare
Advanced tools
Comparing version 0.1.0 to 0.1.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const vm_1 = tslib_1.__importDefault(require("vm")); | ||
const _1 = require("."); | ||
(async () => { | ||
const mf = new _1.Miniflare(new vm_1.default.Script(` | ||
const mf = new _1.Miniflare({ | ||
script: ` | ||
addEventListener("fetch", (event) => { | ||
@@ -14,2 +13,3 @@ event.respondWith(handleRequest(event.request)); | ||
async function handleRequest(request) { | ||
// throw new Error("error"); | ||
const value = await TEST_NAMESPACE.get("key"); | ||
@@ -24,5 +24,5 @@ return new Response(\`Hello from Miniflare! key="\${value}"\`, { | ||
}); | ||
`), { | ||
`, | ||
kvNamespaces: ["TEST_NAMESPACE"], | ||
log: new _1.ConsoleLog(), | ||
log: new _1.ConsoleLog(true), | ||
}); | ||
@@ -29,0 +29,0 @@ const ns = await mf.getNamespace("TEST_NAMESPACE"); |
@@ -24,3 +24,3 @@ /// <reference types="node" /> | ||
} | ||
declare type EventListener = (event: any) => void; | ||
declare type EventListener<Event> = (event: Event) => void; | ||
export declare type ResponseWaitUntil<WaitUntil extends any[] = any[]> = Response & { | ||
@@ -30,4 +30,5 @@ waitUntil: () => Promise<WaitUntil>; | ||
export declare class EventsModule extends Module { | ||
private listeners; | ||
addEventListener(type: string, listener: EventListener): void; | ||
_listeners: Record<string, EventListener<any>[]>; | ||
addEventListener(type: "fetch", listener: EventListener<FetchEvent>): void; | ||
addEventListener(type: "scheduled", listener: EventListener<ScheduledEvent>): void; | ||
removeEventListeners(): void; | ||
@@ -34,0 +35,0 @@ buildSandbox(_options: ProcessedOptions): Sandbox; |
@@ -38,3 +38,3 @@ "use strict"; | ||
super(...arguments); | ||
this.listeners = {}; | ||
this._listeners = {}; | ||
} | ||
@@ -45,8 +45,8 @@ addEventListener(type, listener) { | ||
} | ||
if (!(type in this.listeners)) | ||
this.listeners[type] = []; | ||
this.listeners[type].push(listener); | ||
if (!(type in this._listeners)) | ||
this._listeners[type] = []; | ||
this._listeners[type].push(listener); | ||
} | ||
removeEventListeners() { | ||
this.listeners = {}; | ||
this._listeners = {}; | ||
} | ||
@@ -64,3 +64,3 @@ buildSandbox(_options) { | ||
const waitUntil = async () => (await Promise.all(event._waitUntilPromises)); | ||
for (const listener of (_a = this.listeners.fetch) !== null && _a !== void 0 ? _a : []) { | ||
for (const listener of (_a = this._listeners.fetch) !== null && _a !== void 0 ? _a : []) { | ||
try { | ||
@@ -93,3 +93,3 @@ listener(event); | ||
const event = new ScheduledEvent(scheduledTime !== null && scheduledTime !== void 0 ? scheduledTime : Date.now()); | ||
for (const listener of (_a = this.listeners.scheduled) !== null && _a !== void 0 ? _a : []) { | ||
for (const listener of (_a = this._listeners.scheduled) !== null && _a !== void 0 ? _a : []) { | ||
listener(event); | ||
@@ -96,0 +96,0 @@ } |
{ | ||
"name": "miniflare", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Fully-local Cloudflare Workers Simulator", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@mrbbot/node-fetch": "github:mrbbot/node-fetch", | ||
"@mrbbot/node-fetch": "^4.0.1", | ||
"@peculiar/webcrypto": "^1.1.4", | ||
@@ -33,0 +33,0 @@ "chalk": "^4.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
111502
61
2519
0
6
4
+ Added@cloudflare/workers-types@2.2.2(transitive)
+ Added@mrbbot/node-fetch@4.6.0(transitive)
+ Addedbusboy@0.3.1(transitive)
+ Addeddicer@0.3.0(transitive)
+ Addedformdata-node@2.5.0(transitive)
+ Addedmime-db@1.46.0(transitive)
+ Addedmime-types@2.1.29(transitive)
+ Addedstreamsearch@0.1.2(transitive)
Updated@mrbbot/node-fetch@^4.0.1