///
import { Awaitable as Awaitable_2 } from '@miniflare/shared';
import { MockAgent } from 'undici';
import type { Database as SqliteDB } from 'better-sqlite3';
import type { Options as SqliteOptions } from 'better-sqlite3';
import { TransferListItem } from 'worker_threads';
export declare function addAll(set: Set, values: Iterable): void;
export declare type AdditionalModules = {
[key: string]: Context;
};
export declare function arrayCompare(a: T, b: T): number;
export declare function assertInRequest(): void;
export declare type Awaitable = T | Promise;
export declare function base64Decode(encoded: string): string;
export declare function base64Encode(value: string): string;
export declare interface BeforeSetupResult {
watch?: string[];
}
export declare type Clock = () => number;
export declare class Compatibility {
#private;
private compatibilityDate;
private compatibilityFlags;
constructor(compatibilityDate?: string, compatibilityFlags?: CompatibilityFlag[]);
isEnabled(flag: CompatibilityEnableFlag): boolean;
update(compatibilityDate?: string, compatibilityFlags?: CompatibilityFlag[]): boolean;
get enabled(): CompatibilityEnableFlag[];
}
export declare type CompatibilityDisableFlag = "streams_disable_constructors" | "transformstream_disable_standard_constructor" | "export_commonjs_namespace" | "no_global_navigator" | "durable_object_fetch_allows_relative_url" | "fetch_treats_unknown_protocols_as_http" | "formdata_parser_converts_files_to_strings";
export declare type CompatibilityEnableFlag = "nodejs_compat" | "streams_enable_constructors" | "transformstream_enable_standard_constructor" | "export_commonjs_default" | "r2_list_honor_include" | "global_navigator" | "durable_object_fetch_requires_full_url" | "fetch_refuses_unknown_protocols" | "formdata_parser_supports_files" | "html_rewriter_treats_esi_include_as_void_tag" | "experimental";
export declare interface CompatibilityFeature {
defaultAsOf?: string;
enableFlag: CompatibilityEnableFlag;
disableFlag?: CompatibilityDisableFlag;
}
export declare type CompatibilityFlag = CompatibilityEnableFlag | CompatibilityDisableFlag;
export declare interface Consumer {
queueName: string;
maxBatchSize: number;
maxWaitMs: number;
maxRetries: number;
deadLetterQueue?: string;
dispatcher: QueueEventDispatcher;
}
export declare type Context = {
[key: string | symbol]: any;
};
export declare function createSQLiteDB(dbPath: string): Promise;
export declare interface DBConstructor {
new (filename: string | Buffer, options?: SqliteOptions): SqliteDB;
}
export declare const defaultClock: Clock;
export declare const EXTERNAL_SUBREQUEST_LIMIT_BUNDLED = 50;
export declare const EXTERNAL_SUBREQUEST_LIMIT_UNBOUND = 1000;
export declare type ExtractOptions = Instance extends Plugin ? Options : never;
export declare function getRequestContext(): RequestContext | undefined;
export declare function getSQLiteNativeBindingLocation(sqliteResolvePath: string): string;
export declare function globsToMatcher(globs?: string[]): Matcher;
export declare class InputGate {
#private;
constructor(parent?: InputGate);
/** Waits for input gate to open, then runs closure under the input gate */
runWith(closure: () => Awaitable): Promise;
/** Waits for input gate to be open (e.g. before returning from async I/O) */
waitForOpen(): Promise;
/**
* Runs a closure with this input gate closed (e.g. performing Durable Object
* storage operation, blockConcurrencyWhile). Once complete, if the gate is
* now open, resolves some waiters.
*/
runWithClosed(closure: () => Promise): Promise;
}
export declare class InputGatedEventTarget> extends TypedEventTarget {
protected [kWrapListener](listener: (event: EventMap[Type]) => void): (event: EventMap[Type]) => void;
}
export declare const INTERNAL_SUBREQUEST_LIMIT = 1000;
export declare function kebabCase(s: string): string;
export declare const kGetConsumer: unique symbol;
export declare const kSetConsumer: unique symbol;
export declare const kWrapListener: unique symbol;
export declare function lexicographicCompare(x: string, y: string): number;
export declare class Log {
#private;
readonly level: LogLevel;
constructor(level?: LogLevel, opts?: LogOptions);
log(message: string): void;
logWithLevel(level: LogLevel, message: string): void;
error(message: Error): void;
warn(message: string): void;
info(message: string): void;
debug(message: string): void;
verbose(message: string): void;
}
export declare enum LogLevel {
NONE = 0,
ERROR = 1,
WARN = 2,
INFO = 3,
DEBUG = 4,
VERBOSE = 5
}
export declare interface LogOptions {
prefix?: string;
suffix?: string;
}
export declare function logOptions(plugins: PluginEntries, log: Log, options: PluginOptions): void;
export declare interface Matcher {
test(string: string): boolean;
toString(): string;
}
export declare interface Message {
readonly id: string;
readonly timestamp: Date;
readonly body: Body;
retry(): void;
}
export declare interface MessageBatch {
readonly queue: string;
readonly messages: Message[];
retryAll(): void;
}
export declare type MessageSendOptions = {};
export declare type MessageSendRequest = {
body: Body;
} & MessageSendOptions;
export declare function millisToSeconds(millis: number): number;
export declare abstract class MiniflareError extends Error {
readonly code: Code;
readonly cause?: Error | undefined;
constructor(code: Code, message?: string, cause?: Error | undefined);
}
export declare interface ModuleRule {
type: ModuleRuleType;
include: string[];
fallthrough?: boolean;
}
export declare type ModuleRuleType = "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm";
export declare interface Mount {
moduleExports?: Context;
dispatchFetch?: (request: Request) => Promise;
usageModel?: UsageModel;
}
export declare class Mutex {
private locked;
private resolveQueue;
private lock;
private unlock;
get hasWaiting(): boolean;
runWith(closure: () => Awaitable_2): Promise;
}
export declare function nonCircularClone(value: T): T;
export declare class NoOpLog extends Log {
log(): void;
error(message: Error): void;
}
export declare const numericCompare: (x: string, y: string) => number;
export declare function Option(metadata: OptionMetadata): (prototype: typeof Plugin.prototype, key: string | symbol) => void;
export declare type OptionMetadata = OptionMetadataType | OptionMetadataType | OptionMetadataType | OptionMetadataType | OptionMetadataType | OptionMetadataType | OptionMetadataType | OptionMetadataType | OptionMetadataType;
export declare interface OptionMetadataType {
type: Type;
typeFormat?: Type extends OptionType.OBJECT ? string : undefined;
name?: string;
alias?: string;
description?: string;
negatable?: Type extends OptionType.BOOLEAN | OptionType.BOOLEAN_STRING | OptionType.BOOLEAN_NUMBER ? boolean : undefined;
logName?: string;
logValue?: (value: Value) => string | undefined;
fromEntries?: Type extends OptionType.OBJECT ? (entries: [key: string, value: string][]) => Value : undefined;
fromWrangler?: (config: WranglerConfig, configDir: string, log: Log) => Value | undefined;
}
export declare type Options = UnionToIntersection>;
export declare enum OptionType {
NONE = 0,
BOOLEAN = 1,
NUMBER = 2,
STRING = 3,
STRING_POSITIONAL = 4,
BOOLEAN_STRING = 5,
BOOLEAN_NUMBER = 6,
ARRAY = 7,
OBJECT = 8
}
export declare class OutputGate {
#private;
/** Runs closure under the output gate, then waits for output gate to open */
runWith(closure: () => Awaitable): Promise;
/** Waits for promises registered with this gate via waitUntil to resolve */
waitForOpen(): Promise;
/**
* Registers a promise with this output gate. The gate won't open until this
* promise resolves.
*/
waitUntil(promise: Promise): void;
}
export declare interface ParsedRange {
offset: number;
length: number;
}
export declare function parseRange({ offset, length, suffix }: Range, size: number): ParsedRange;
export declare abstract class Plugin {
#private;
protected readonly ctx: PluginContext;
opts?: Map;
protected constructor(ctx: PluginContext);
protected assignOptions(options?: Options): void;
beforeSetup?(): Awaitable;
setup?(storageFactory: StorageFactory): Awaitable;
beforeReload?(): Awaitable;
reload?(bindings: Context, moduleExports: Context, mounts: Map): Awaitable;
dispose?(): Awaitable;
}
export declare interface PluginContext {
log: Log;
compat: Compatibility;
rootPath: string;
usageModel?: UsageModel;
globalAsyncIO?: boolean;
fetchMock?: MockAgent;
queueEventDispatcher: QueueEventDispatcher;
queueBroker: QueueBroker;
sharedCache: Map;
}
export declare type PluginEntries = [
name: keyof Plugins,
plugin: ValueOf
][];
export declare type PluginOptions = {
[key in keyof Plugins]: ExtractOptions>;
};
export declare type PluginOptionsUnion = ValueOf>;
export declare type PluginSignature = {
new (ctx: PluginContext, options?: Context): Plugin;
prototype: {
opts?: Map;
};
};
export declare type PluginSignatures = {
[pluginName: string]: PluginSignature;
};
export declare function prefixError(prefix: string, e: any): Error;
export declare interface ProcessedModuleRule {
type: ModuleRuleType;
include: Matcher;
}
export declare interface Queue {
send(message: Body, options?: MessageSendOptions): Promise;
sendBatch(batch: Iterable>): Promise;
[kSetConsumer](consumer?: Consumer): void;
[kGetConsumer](): Consumer | null;
}
export declare interface QueueBroker {
getOrCreateQueue(name: string): Queue;
setConsumer(queue: Queue, consumer: Consumer): void;
resetConsumers(): void;
}
export declare type QueueEventDispatcher = (batch: MessageBatch) => Promise;
export declare function randomHex(digits?: number): string;
export declare interface Range {
offset?: number;
length?: number;
suffix?: number;
}
export declare interface RangeStoredMeta extends StoredMeta {
range: {
offset: number;
length: number;
};
}
export declare interface RangeStoredValue extends StoredValue {
range: {
offset: number;
length: number;
};
}
export declare type RangeStoredValueMeta = RangeStoredValue & RangeStoredMeta;
export declare class RequestContext {
#private;
readonly requestDepth: number;
readonly pipelineDepth: number;
readonly durableObject: boolean;
readonly externalSubrequestLimit: number | false;
readonly internalSubrequestLimit: number | false;
constructor({ requestDepth, pipelineDepth, durableObject, externalSubrequestLimit, internalSubrequestLimit, }?: RequestContextOptions);
runWith(closure: () => T): T;
get externalSubrequests(): number;
get internalSubrequests(): number;
incrementExternalSubrequests(count?: number): void;
incrementInternalSubrequests(count?: number): void;
get currentTime(): number;
advanceCurrentTime(): void;
}
export declare interface RequestContextOptions {
/**
* In this context, a request is the initial entry fetch to a Worker
* (e.g. the incoming HTTP request), or fetch to a Durable Object stub.
* The depth starts at 1, and increments for each recursive request.
*/
requestDepth?: number;
/**
* The pipeline depth starts at 1, and increments for each recursive service
* binding fetch. The requestDepth should not be incremented in this case.
* The pipeline depth resets for each new request (as described above).
*/
pipelineDepth?: number;
/**
* Whether this context is for inside a Durable Object fetch. Affects
* WebSocket subrequest limits for incoming messages.
*/
durableObject?: boolean;
/** Maximum external subrequests (`fetch`, Cache API) allowed. */
externalSubrequestLimit?: number | false;
/** Maximum internal subrequests (KV, Durable Objects) allowed. */
internalSubrequestLimit?: number | false;
}
export declare function resolveStoragePersist(rootPath: string, persist?: boolean | string): boolean | string | undefined;
export declare type RouteType = string | {
pattern: string;
zone_id?: string;
zone_name?: string;
};
/**
* Runs closure with the context's input gate (if any) closed, unless
* allowConcurrency is true. Should be called when performing storage
* operations.
*/
export declare function runWithInputGateClosed(closure: () => Promise, allowConcurrency?: boolean): Promise;
export declare function sanitisePath(unsafe: string): string;
export declare interface ScriptBlueprint {
readonly filePath: string;
readonly code: string;
}
export declare interface ScriptRunner {
run(globalScope: Context, blueprint: ScriptBlueprint, modulesRules?: ProcessedModuleRule[], additionalModules?: AdditionalModules, compat?: Compatibility): Promise;
}
export declare interface ScriptRunnerResult {
exports: Context;
bundleSize?: number;
watch?: string[];
}
export declare interface SetupResult extends BeforeSetupResult {
globals?: Context;
bindings?: Context;
script?: ScriptBlueprint;
requiresModuleExports?: boolean;
additionalModules?: AdditionalModules;
}
export declare const SITES_NO_CACHE_PREFIX = "$__MINIFLARE_SITES__$/";
export declare function spaceCase(s: string): string;
export { SqliteDB }
export { SqliteOptions }
/**
* Common class for key-value storage:
* - Methods should always return fresh copies of data (safe to mutate returned)
* - Methods shouldn't return expired keys
*/
export declare abstract class Storage {
abstract has(key: string): Awaitable;
abstract head(key: string): Awaitable | undefined>;
abstract get(key: string, skipMetadata?: false): Awaitable | undefined>;
abstract get(key: string, skipMetadata: true): Awaitable;
abstract getRange(key: string, range?: Range, skipMetadata?: false): Awaitable | undefined>;
abstract getRange(key: string, range: undefined | Range, skipMetadata: true): Awaitable;
abstract put(key: string, value: StoredValueMeta): Awaitable;
abstract delete(key: string): Awaitable;
abstract list(options?: StorageListOptions, skipMetadata?: false): Awaitable>>;
abstract list(options: StorageListOptions, skipMetadata: true): Awaitable>;
getSqliteDatabase(): Promise;
hasMany(keys: string[]): Promise;
getMany(keys: string[], skipMetadata?: false): Promise<(StoredValueMeta | undefined)[]>;
getMany(keys: string[], skipMetadata: true): Promise<(StoredValue | undefined)[]>;
putMany(data: [key: string, value: StoredValueMeta][]): Promise;
deleteMany(keys: string[]): Promise;
}
export declare interface StorageFactory {
storage(namespace: string, persist?: boolean | string): Storage;
dispose?(): Awaitable;
}
export declare interface StorageListOptions {
/** Returned keys must start with this string if defined */
prefix?: string;
/** Returned keys must NOT start with this string if defined */
excludePrefix?: string;
/** Returned keys must be lexicographically >= this string if defined */
start?: string;
/** Returned keys must be lexicographically < this string if defined */
end?: string;
/** Return keys in reverse order, MUST be applied before the limit/cursor */
reverse?: boolean;
/** Cursor for pagination, undefined/empty-string means start at beginning */
cursor?: string;
/** Maximum number of keys to return if defined */
limit?: number;
/** If Delimiter, filter all keys containing delimiter and update cursor */
delimiter?: string;
}
export declare interface StorageListResult {
keys: Key[];
/** Cursor for next page */
cursor: string;
/** DelimitedPrefixes if delimiter */
delimitedPrefixes?: string[];
}
export declare interface StoredKey {
name: string;
}
export declare type StoredKeyMeta = StoredKey & StoredMeta;
export declare interface StoredMeta {
/** Unix timestamp in seconds when this key expires */
expiration?: number;
/** Arbitrary JSON-serializable object */
metadata?: Meta;
}
export declare interface StoredValue {
value: Uint8Array;
}
export declare type StoredValueMeta = StoredValue & StoredMeta;
export declare const STRING_SCRIPT_PATH = "