UNPKG

@miniflare/tre

Version:

Fun, full-featured, fully-local simulator for Cloudflare Workers

1,262 lines (1,095 loc) 136 kB
/// <reference types="node" /> import { Awaitable as Awaitable_2 } from '../shared'; import { BodyInit } from 'undici'; import { CacheGateway as CacheGateway_2 } from './cache'; import { Clock as Clock_2 } from '../shared'; import { D1Gateway as D1Gateway_2 } from './d1'; import { Database } from 'better-sqlite3'; import { DurableObjectsStorageGateway as DurableObjectsStorageGateway_2 } from './do'; import { ExternalServer as ExternalServer_2 } from '../../runtime'; import { ExternalServer as ExternalServer_3 } from '../index'; import { File } from 'undici'; import { FormData } from 'undici'; import { Headers } from 'undici'; import { HeadersInit } from 'undici'; import type { IncomingRequestCfProperties } from '@cloudflare/workers-types/experimental'; import { Json as Json_2 } from '../../shared'; import { Json as Json_3 } from '../shared'; import { KVGateway as KVGateway_2 } from './kv'; import { Log as Log_2 } from '../shared'; import NodeWebSocket from 'ws'; import { Plugin as Plugin_2 } from './shared'; import { R2Gateway as R2Gateway_2 } from './r2'; import type { R2StringChecksums } from '@cloudflare/workers-types/experimental'; import { ReferrerPolicy } from 'undici'; import { Request as Request_2 } from 'undici'; import { Request as Request_3 } from '../../index'; import { Request as Request_4 } from '../index'; import { RequestCache } from 'undici'; import { RequestCredentials } from 'undici'; import { RequestDestination } from 'undici'; import { RequestDuplex } from 'undici'; import { RequestInfo } from 'undici'; import { RequestInit as RequestInit_2 } from 'undici'; import { RequestInit as RequestInit_3 } from '../../index'; import { RequestInit as RequestInit_4 } from '../index'; import type { RequestInitCfProperties } from '@cloudflare/workers-types/experimental'; import { RequestInitCfType as RequestInitCfType_2 } from '../../index'; import { RequestInitCfType as RequestInitCfType_3 } from '../index'; import { RequestMode } from 'undici'; import { RequestRedirect } from 'undici'; import { Response as Response_2 } from 'undici'; import { Response as Response_3 } from '../../index'; import { Response as Response_4 } from '../index'; import { ResponseInit as ResponseInit_2 } from 'undici'; import { ResponseRedirectStatus } from 'undici'; import { ResponseType } from 'undici'; import { compatibilityDate as supportedCompatibilityDate } from 'workerd'; import { TlsOptions_Version as TlsOptions_Version_2 } from '../../runtime'; import { TlsOptions_Version as TlsOptions_Version_3 } from '../index'; import { URL as URL_2 } from 'url'; import { URLSearchParams as URLSearchParams_2 } from 'url'; import { z } from 'zod'; export declare type Awaitable<T> = T | Promise<T>; export declare const BASE64_REGEXP: RegExp; export declare const Base64DataSchema: z.ZodEffects<z.ZodString, Buffer, string>; export declare function base64Decode(encoded: string): string; export declare function base64Encode(value: string): string; export declare const BINDING_SERVICE_LOOPBACK = "MINIFLARE_LOOPBACK"; export declare const BINDING_TEXT_NAMESPACE = "MINIFLARE_NAMESPACE"; export declare const BINDING_TEXT_PERSIST = "MINIFLARE_PERSIST"; export declare const BINDING_TEXT_PLUGIN = "MINIFLARE_PLUGIN"; export { BodyInit } export declare const CACHE_LOOPBACK_SCRIPT: string; export declare const CACHE_PLUGIN: Plugin<typeof CacheOptionsSchema, typeof CacheSharedOptionsSchema, CacheGateway>; export declare const CACHE_PLUGIN_NAME = "cache"; export declare class CacheGateway { private readonly log; private readonly storage; private readonly clock; constructor(log: Log, storage: Storage, clock: Clock); match(request: Request, cacheKey?: string): Promise<Response>; put(request: Request, value: Uint8Array, cacheKey?: string): Promise<Response>; delete(request: Request, cacheKey?: string): Promise<Response>; } export declare const CacheOptionsSchema: z.ZodObject<{ cache: z.ZodOptional<z.ZodBoolean>; cacheWarnUsage: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { cache?: boolean | undefined; cacheWarnUsage?: boolean | undefined; }, { cache?: boolean | undefined; cacheWarnUsage?: boolean | undefined; }>; export declare const CacheSharedOptionsSchema: z.ZodObject<{ cachePersist: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>; }, "strip", z.ZodTypeAny, { cachePersist?: string | boolean | undefined; }, { cachePersist?: string | boolean | undefined; }>; export declare enum CfHeader { Error = "cf-r2-error", Request = "cf-r2-request", MetadataSize = "cf-r2-metadata-size", Blob = "cf-blob", CacheNamespace = "cf-cache-namespace", CacheStatus = "cf-cache-status" } export declare type Clock = () => number; export declare function cloneMetadata<Meta>(metadata?: unknown): Meta | undefined; export declare class CloseEvent extends Event { readonly code: number; readonly reason: string; readonly wasClean: boolean; constructor(type: "close", init?: { code?: number; reason?: string; wasClean?: boolean; }); } export declare type CloudflareFetch = z.infer<typeof CloudflareFetchSchema>; export declare const CloudflareFetchSchema: z.ZodType<(resource: string, searchParams?: URLSearchParams_2, init?: RequestInit) => Awaitable<Response>, z.ZodTypeDef, (resource: string, searchParams?: URLSearchParams_2, init?: RequestInit) => Awaitable<Response>>; export declare interface Config { services?: Service[]; sockets?: Socket[]; } export declare const CORE_PLUGIN: Plugin<typeof CoreOptionsSchema, typeof CoreSharedOptionsSchema>; export declare const CORE_PLUGIN_NAME = "core"; export declare const CoreOptionsSchema: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{ modules: z.ZodArray<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; path: z.ZodString; contents: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>>; }, "strip", z.ZodTypeAny, { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }, { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }>, "many">; modulesRoot: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { modulesRoot?: string | undefined; modules: { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }[]; }, { modulesRoot?: string | undefined; modules: { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }[]; }>, z.ZodObject<{ script: z.ZodString; scriptPath: z.ZodOptional<z.ZodString>; modules: z.ZodOptional<z.ZodBoolean>; modulesRules: z.ZodOptional<z.ZodArray<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; include: z.ZodArray<z.ZodString, "many">; fallthrough: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }>, "many">>; }, "strip", z.ZodTypeAny, { modules?: boolean | undefined; scriptPath?: string | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; script: string; }, { modules?: boolean | undefined; scriptPath?: string | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; script: string; }>, z.ZodObject<{ scriptPath: z.ZodString; modules: z.ZodOptional<z.ZodBoolean>; modulesRules: z.ZodOptional<z.ZodArray<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; include: z.ZodArray<z.ZodString, "many">; fallthrough: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }>, "many">>; }, "strip", z.ZodTypeAny, { modules?: boolean | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; scriptPath: string; }, { modules?: boolean | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; scriptPath: string; }>]>, z.ZodObject<{ name: z.ZodOptional<z.ZodString>; compatibilityDate: z.ZodOptional<z.ZodString>; compatibilityFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; routes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; bindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json_2, z.ZodTypeDef, Json_2>>>; wasmBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; textBlobBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; dataBlobBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; serviceBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{ network: z.ZodObject<{ allow: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; deny: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; tlsOptions: z.ZodOptional<z.ZodObject<{ keypair: z.ZodOptional<z.ZodObject<{ privateKey: z.ZodOptional<z.ZodString>; certificateChain: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { privateKey?: string | undefined; certificateChain?: string | undefined; }, { privateKey?: string | undefined; certificateChain?: string | undefined; }>>; requireClientCerts: z.ZodOptional<z.ZodBoolean>; trustBrowserCas: z.ZodOptional<z.ZodBoolean>; trustedCertificates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; minVersion: z.ZodOptional<z.ZodNativeEnum<TlsOptions_Version_2>>; cipherList: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; }, { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; }>>; }, "strip", z.ZodTypeAny, { allow?: string[] | undefined; deny?: string[] | undefined; tlsOptions?: { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; } | undefined; }, { allow?: string[] | undefined; deny?: string[] | undefined; tlsOptions?: { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; } | undefined; }>; }, "strip", z.ZodTypeAny, { network: { allow?: string[] | undefined; deny?: string[] | undefined; tlsOptions?: { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; } | undefined; }; }, { network: { allow?: string[] | undefined; deny?: string[] | undefined; tlsOptions?: { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; } | undefined; }; }>, z.ZodObject<{ external: z.ZodType<ExternalServer_2, z.ZodTypeDef, ExternalServer_2>; }, "strip", z.ZodTypeAny, { external: ExternalServer_2; }, { external: ExternalServer_2; }>, z.ZodObject<{ disk: z.ZodObject<{ path: z.ZodString; writable: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { writable?: boolean | undefined; path: string; }, { writable?: boolean | undefined; path: string; }>; }, "strip", z.ZodTypeAny, { disk: { writable?: boolean | undefined; path: string; }; }, { disk: { writable?: boolean | undefined; path: string; }; }>, z.ZodFunction<z.ZodTuple<[z.ZodType<Request_3<RequestInitCfType_2>, z.ZodTypeDef, Request_3<RequestInitCfType_2>>], z.ZodUnknown>, z.ZodUnion<[z.ZodType<Response_3, z.ZodTypeDef, Response_3>, z.ZodPromise<z.ZodType<Response_3, z.ZodTypeDef, Response_3>>]>>]>>>; }, "strip", z.ZodTypeAny, { name?: string | undefined; compatibilityDate?: string | undefined; bindings?: Record<string, Json_2> | undefined; compatibilityFlags?: string[] | undefined; routes?: string[] | undefined; wasmBindings?: Record<string, string> | undefined; textBlobBindings?: Record<string, string> | undefined; dataBlobBindings?: Record<string, string> | undefined; serviceBindings?: Record<string, string | { network: { allow?: string[] | undefined; deny?: string[] | undefined; tlsOptions?: { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; } | undefined; }; } | { external: ExternalServer_2; } | { disk: { writable?: boolean | undefined; path: string; }; } | ((args_0: Request_3<RequestInitCfType_2>, ...args_1: unknown[]) => Response_3 | Promise<Response_3>)> | undefined; }, { name?: string | undefined; compatibilityDate?: string | undefined; bindings?: Record<string, Json_2> | undefined; compatibilityFlags?: string[] | undefined; routes?: string[] | undefined; wasmBindings?: Record<string, string> | undefined; textBlobBindings?: Record<string, string> | undefined; dataBlobBindings?: Record<string, string> | undefined; serviceBindings?: Record<string, string | { network: { allow?: string[] | undefined; deny?: string[] | undefined; tlsOptions?: { minVersion?: TlsOptions_Version_2 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; } | undefined; }; } | { external: ExternalServer_2; } | { disk: { writable?: boolean | undefined; path: string; }; } | ((args_0: Request_3<RequestInitCfType_2>, ...args_1: unknown[]) => Response_3 | Promise<Response_3>)> | undefined; }>>; export declare const CoreSharedOptionsSchema: z.ZodObject<{ host: z.ZodOptional<z.ZodString>; port: z.ZodOptional<z.ZodNumber>; inspectorPort: z.ZodOptional<z.ZodNumber>; verbose: z.ZodOptional<z.ZodBoolean>; log: z.ZodOptional<z.ZodType<Log, z.ZodTypeDef, Log>>; clock: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodNumber>>; cloudflareFetch: z.ZodOptional<z.ZodType<(resource: string, searchParams?: URLSearchParams_2 | undefined, init?: RequestInit_3<RequestInitCfType_2> | undefined) => Awaitable<Response_3>, z.ZodTypeDef, (resource: string, searchParams?: URLSearchParams_2 | undefined, init?: RequestInit_3<RequestInitCfType_2> | undefined) => Awaitable<Response_3>>>; cf: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>>; liveReload: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { host?: string | undefined; port?: number | undefined; cf?: string | boolean | Record<string, any> | undefined; cloudflareFetch?: ((resource: string, searchParams?: URLSearchParams_2 | undefined, init?: RequestInit_3<RequestInitCfType_2> | undefined) => Awaitable<Response_3>) | undefined; inspectorPort?: number | undefined; verbose?: boolean | undefined; log?: Log | undefined; clock?: ((...args: unknown[]) => number) | undefined; liveReload?: boolean | undefined; }, { host?: string | undefined; port?: number | undefined; cf?: string | boolean | Record<string, any> | undefined; cloudflareFetch?: ((resource: string, searchParams?: URLSearchParams_2 | undefined, init?: RequestInit_3<RequestInitCfType_2> | undefined) => Awaitable<Response_3>) | undefined; inspectorPort?: number | undefined; verbose?: boolean | undefined; log?: Log | undefined; clock?: ((...args: unknown[]) => number) | undefined; liveReload?: boolean | undefined; }>; export declare function coupleWebSocket(ws: NodeWebSocket, pair: WebSocket): Promise<void>; export declare function createVersion(): string; export declare const D1_PLUGIN: Plugin<typeof D1OptionsSchema, typeof D1SharedOptionsSchema, D1Gateway>; export declare const D1_PLUGIN_NAME = "d1"; export declare class D1Error extends HttpError { constructor(cause: Error); toResponse(): Response; } export declare interface D1ErrorResponse { error: string; success: false; served_by: string; } export declare class D1Gateway { #private; private readonly log; private readonly storage; private readonly db; constructor(log: Log, storage: Storage); query(query: D1Query): D1SuccessResponse | D1SuccessResponse[]; execute(query: D1Query): D1SuccessResponse | D1SuccessResponse[]; dump(): Promise<Uint8Array>; } export declare const D1OptionsSchema: z.ZodObject<{ d1Databases: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodString>, z.ZodArray<z.ZodString, "many">]>>; }, "strip", z.ZodTypeAny, { d1Databases?: string[] | Record<string, string> | undefined; }, { d1Databases?: string[] | Record<string, string> | undefined; }>; export declare type D1Query = z.infer<typeof D1QuerySchema>; export declare const D1QuerySchema: z.ZodUnion<[z.ZodObject<{ sql: z.ZodString; params: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodNull, z.ZodArray<z.ZodNumber, "many">]>, "many">>>; }, "strip", z.ZodTypeAny, { params?: (string | number | number[] | null)[] | null | undefined; sql: string; }, { params?: (string | number | number[] | null)[] | null | undefined; sql: string; }>, z.ZodArray<z.ZodObject<{ sql: z.ZodString; params: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodNull, z.ZodArray<z.ZodNumber, "many">]>, "many">>>; }, "strip", z.ZodTypeAny, { params?: (string | number | number[] | null)[] | null | undefined; sql: string; }, { params?: (string | number | number[] | null)[] | null | undefined; sql: string; }>, "many">]>; export declare interface D1ResponseMeta { duration: number; last_row_id: number | null; changes: number | null; served_by: string; internal_stats: null; } export declare const D1SharedOptionsSchema: z.ZodObject<{ d1Persist: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>; }, "strip", z.ZodTypeAny, { d1Persist?: string | boolean | undefined; }, { d1Persist?: string | boolean | undefined; }>; export declare type D1SingleQuery = z.infer<typeof D1SingleQuerySchema>; export declare const D1SingleQuerySchema: z.ZodObject<{ sql: z.ZodString; params: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodNull, z.ZodArray<z.ZodNumber, "many">]>, "many">>>; }, "strip", z.ZodTypeAny, { params?: (string | number | number[] | null)[] | null | undefined; sql: string; }, { params?: (string | number | number[] | null)[] | null | undefined; sql: string; }>; export declare interface D1SuccessResponse { results: Record<string, D1Value>[] | null; duration: number; success: true; served_by: string; meta: D1ResponseMeta | null; lastRowId: null; changes: null; } export declare type D1Value = z.infer<typeof D1ValueSchema>; export declare const D1ValueSchema: z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodNull, z.ZodArray<z.ZodNumber, "many">]>; export declare const DateSchema: z.ZodEffects<z.ZodNumber, Date, number>; export declare function decodePersist(headers: Headers): Persistence; export declare const DEFAULT_PERSIST_ROOT = ".mf"; export declare const defaultClock: Clock; export declare class DeferredPromise<T> extends Promise<T> { readonly resolve: DeferredPromiseResolve<T>; readonly reject: DeferredPromiseReject; constructor(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void); } export declare type DeferredPromiseReject = (reason?: any) => void; export declare type DeferredPromiseResolve<T> = (value: T | PromiseLike<T>) => void; export declare const DELETE: (path: string) => (prototype: Router<any>, key: string | symbol) => void; export declare function deleteFile(filePath: string): Promise<boolean>; export declare function deserialiseRegExps(matcher: SerialisableMatcherRegExps): MatcherRegExps; export declare interface DiskDirectory { path?: string; writable?: boolean; } export declare const DURABLE_OBJECTS_PLUGIN: Plugin<typeof DurableObjectsOptionsSchema, typeof DurableObjectsSharedOptionsSchema, DurableObjectsStorageGateway>; export declare const DURABLE_OBJECTS_PLUGIN_NAME = "do"; export declare const DURABLE_OBJECTS_STORAGE_SERVICE_NAME: string; export declare type DurableObjectClassNames = Map<string, Set<string>>; export declare const DurableObjectsOptionsSchema: z.ZodObject<{ durableObjects: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{ className: z.ZodString; scriptName: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { scriptName?: string | undefined; className: string; }, { scriptName?: string | undefined; className: string; }>]>>>; }, "strip", z.ZodTypeAny, { durableObjects?: Record<string, string | { scriptName?: string | undefined; className: string; }> | undefined; }, { durableObjects?: Record<string, string | { scriptName?: string | undefined; className: string; }> | undefined; }>; export declare const DurableObjectsSharedOptionsSchema: z.ZodObject<{ durableObjectsPersist: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>; }, "strip", z.ZodTypeAny, { durableObjectsPersist?: string | boolean | undefined; }, { durableObjectsPersist?: string | boolean | undefined; }>; export declare class DurableObjectsStorageGateway { private readonly log; private readonly storage; private readonly clock; constructor(log: Log, storage: Storage, clock: Clock); get(_key: string): Promise<void>; put(_key: string, _value: Uint8Array): Promise<void>; delete(_key: string): Promise<void>; list(): Promise<void>; } export declare interface EncodedMetadata { metadataSize: number; value: Uint8Array; } export declare function encodePersist(persist: Persistence): Worker_Binding[]; export declare class ErrorEvent extends Event { readonly error: Error | null; constructor(type: "error", init?: { error?: Error; }); } export declare type ExternalServer = { address?: string; } & ({ http: HttpOptions; } | { https: ExternalServer_Https; }); export declare interface ExternalServer_Https { options?: HttpOptions; tlsOptions?: TlsOptions; certificateHost?: string; } export declare function fetch(input: RequestInfo, init?: RequestInit | Request): Promise<Response>; export { File } export declare interface FileMeta<Meta = unknown> extends StoredMeta<Meta> { key?: string; } export declare interface FileRange { value: Buffer; offset: number; length: number; } export declare class FileStorage extends LocalStorage { #private; private readonly sanitise; protected readonly root: string; constructor(root: string, sanitise?: boolean, clock?: Clock_2); private keyPath; private meta; hasMaybeExpired(key: string): Promise<StoredMeta | undefined>; headMaybeExpired<Meta>(key: string): Promise<FileMeta<Meta> | undefined>; getMaybeExpired<Meta>(key: string): Promise<StoredValueMeta<Meta> | undefined>; getRangeMaybeExpired<Meta = unknown>(key: string, { offset: _offset, length: _length, suffix }: Range): Promise<RangeStoredValueMeta<Meta> | undefined>; put<Meta = unknown>(key: string, { value, expiration, metadata }: StoredValueMeta<Meta>): Promise<void>; deleteMaybeExpired(key: string): Promise<boolean>; listAllMaybeExpired<Meta>(): Promise<StoredKeyMeta<Meta>[]>; getSqliteDatabase(): Database; } export declare class FileStorageError extends MiniflareError<FileStorageErrorCode> { } export declare type FileStorageErrorCode = "ERR_TRAVERSAL" | "ERR_NAMESPACE_KEY_CHILD"; export declare function formatResponse(request: Request): Promise<string>; export { FormData } export declare interface GatewayConstructor<Gateway> { new (log: Log, storage: Storage, clock: Clock): Gateway; } export declare class GatewayFactory<Gateway> { #private; private readonly log; private readonly clock; private readonly cloudflareFetch; private readonly pluginName; private readonly gatewayClass; private readonly remoteStorageClass?; constructor(log: Log, clock: Clock, cloudflareFetch: CloudflareFetch | undefined, pluginName: string, gatewayClass: GatewayConstructor<Gateway>, remoteStorageClass?: RemoteStorageConstructor | undefined); getStorage(namespace: string, persist: Persistence): Storage; get(namespace: string, persist: Persistence): Gateway; } export declare const GET: (path: string) => (prototype: Router<any>, key: string | symbol) => void; export declare function getCacheServiceName(workerIndex: number): string; export declare function getGlobalServices({ optionsVersion, sharedOptions, allWorkerRoutes, fallbackWorkerName, loopbackPort, log, }: GlobalServicesOptions): Service[]; /* Excluded from this release type: _getRangeResponse */ export declare interface GlobalServicesOptions { optionsVersion: number; sharedOptions: z.infer<typeof CoreSharedOptionsSchema>; allWorkerRoutes: Map<string, string[]>; fallbackWorkerName: string | undefined; loopbackPort: number; log: Log; } export declare function globsToRegExps(globs?: string[]): MatcherRegExps; export declare const HEAD: (path: string) => (prototype: Router<any>, key: string | symbol) => void; export declare const HEADER_CF_BLOB = "MF-CF-Blob"; export declare const HEADER_PERSIST = "MF-Persist"; export declare const HEADER_PROBE = "MF-Probe"; export { Headers } export { HeadersInit } export declare const HEX_REGEXP: RegExp; export declare const HexDataSchema: z.ZodEffects<z.ZodString, Buffer, string>; export declare class HttpError extends MiniflareError<number> { constructor(code: number, message?: string, cause?: Error); toResponse(): Response; } export declare interface HttpOptions { style?: HttpOptions_Style; forwardedProtoHeader?: string; cfBlobHeader?: string; injectRequestHeaders?: HttpOptions_Header[]; injectResponseHeaders?: HttpOptions_Header[]; } export declare interface HttpOptions_Header { name?: string; value?: string; } export declare enum HttpOptions_Style { HOST = 0, PROXY = 1 } export declare function isSitesRequest(request: Request): boolean; export declare type Json = Literal | { [key: string]: Json; } | Json[]; export declare const JsonSchema: z.ZodType<Json>; declare const kAccepted: unique symbol; declare const kCf: unique symbol; declare const kClose: unique symbol; declare const kClosedIncoming: unique symbol; declare const kClosedOutgoing: unique symbol; declare const kCoupled: unique symbol; declare const kError: unique symbol; declare const kPair: unique symbol; declare const kSend: unique symbol; export declare const KV_PLUGIN: Plugin<typeof KVOptionsSchema, typeof KVSharedOptionsSchema, KVGateway>; export declare const KV_PLUGIN_NAME = "kv"; export declare class KVError extends HttpError { } export declare class KVGateway { private readonly log; private readonly storage; private readonly clock; constructor(log: Log, storage: Storage, clock: Clock); get(key: string, options?: KVGatewayGetOptions): Promise<StoredValueMeta | undefined>; put(key: string, value: Uint8Array, options?: KVGatewayPutOptions): Promise<void>; delete(key: string): Promise<void>; list(options?: KVGatewayListOptions): Promise<KVGatewayListResult>; } export declare interface KVGatewayGetOptions { cacheTtl?: number; } export declare interface KVGatewayListOptions { limit?: number; prefix?: string; cursor?: string; } export declare interface KVGatewayListResult<Meta = unknown> { keys: StoredKeyMeta<Meta>[]; cursor?: string; list_complete: boolean; } export declare interface KVGatewayPutOptions<Meta = unknown> { expiration?: string | number; expirationTtl?: string | number; metadata?: Meta; } export declare const kVoid: unique symbol; export declare const KVOptionsSchema: z.ZodObject<{ kvNamespaces: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodString>, z.ZodArray<z.ZodString, "many">]>>; sitePath: z.ZodOptional<z.ZodString>; siteInclude: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; siteExclude: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; }, "strip", z.ZodTypeAny, { kvNamespaces?: string[] | Record<string, string> | undefined; sitePath?: string | undefined; siteInclude?: string[] | undefined; siteExclude?: string[] | undefined; }, { kvNamespaces?: string[] | Record<string, string> | undefined; sitePath?: string | undefined; siteInclude?: string[] | undefined; siteExclude?: string[] | undefined; }>; export declare const KVSharedOptionsSchema: z.ZodObject<{ kvPersist: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>; }, "strip", z.ZodTypeAny, { kvPersist?: string | boolean | undefined; }, { kvPersist?: string | boolean | undefined; }>; declare const kWebSocket: unique symbol; export declare function lexicographicCompare(x: string, y: string): number; export declare function listFilterMatch(options: StorageListOptions | undefined, name: string): boolean; export declare function listPaginate<Key extends StoredKey>(options: StorageListOptions | undefined, keys: Key[]): StorageListResult<Key>; export declare type Literal = z.infer<typeof LiteralSchema>; export declare const LiteralSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>; export declare abstract class LocalStorage extends Storage { private readonly clock; protected constructor(clock?: Clock_2); 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>; abstract listAllMaybeExpired<Meta>(): Awaitable<StoredKeyMeta<Meta>[]>; private expired; 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>>>; } export declare class Log { #private; readonly level: LogLevel; constructor(level?: LogLevel, opts?: LogOptions); protected log(message: string): void; protected 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 interface MatcherRegExps { include: RegExp[]; exclude: RegExp[]; } export declare function matchRoutes(routes: WorkerRoute[], url: URL_2): string | null; export declare function maybeGetSitesManifestModule(bindings: Worker_Binding[]): Worker_Module | undefined; export declare function maybeParseURL(url: Persistence): URL | undefined; export declare class MemoryStorage extends LocalStorage { #private; protected map: Map<string, StoredValueMeta<unknown>>; constructor(map?: Map<string, StoredValueMeta<unknown>>, clock?: Clock_2); hasMaybeExpired(key: string): StoredMeta | undefined; headMaybeExpired<Meta>(key: string): StoredMeta<Meta> | undefined; getMaybeExpired<Meta>(key: string): StoredValueMeta<Meta> | undefined; getRangeMaybeExpired<Meta>(key: string, range: Range): RangeStoredValueMeta<Meta> | undefined; put<Meta = unknown>(key: string, value: StoredValueMeta<Meta>): void; deleteMaybeExpired(key: string): boolean; private static entryToStoredKey; listAllMaybeExpired<Meta>(): StoredKeyMeta<Meta>[]; getSqliteDatabase(): Database; } export declare class MessageEvent extends Event { readonly data: ArrayBuffer | string; constructor(type: "message", init: { data: ArrayBuffer | string; }); } export declare function millisToSeconds(millis: number): number; export declare class Miniflare { #private; constructor(opts: MiniflareOptions); get ready(): Promise<URL>; setOptions(opts: MiniflareOptions): Promise<void>; dispatchFetch(input: RequestInfo, init?: RequestInit<Partial<IncomingRequestCfProperties>>): Promise<Response>; dispose(): Promise<void>; } export declare class MiniflareCoreError extends MiniflareError<MiniflareCoreErrorCode> { } export declare type MiniflareCoreErrorCode = "ERR_RUNTIME_FAILURE" | "ERR_DISPOSED" | "ERR_MODULE_PARSE" | "ERR_MODULE_STRING_SCRIPT" | "ERR_MODULE_DYNAMIC_SPEC" | "ERR_MODULE_RULE" | "ERR_PERSIST_UNSUPPORTED" | "ERR_PERSIST_REMOTE_UNAUTHENTICATED" | "ERR_PERSIST_REMOTE_UNSUPPORTED" | "ERR_FUTURE_COMPATIBILITY_DATE" | "ERR_NO_WORKERS" | "ERR_DUPLICATE_NAME"; export declare class MiniflareError<Code extends string | number = string | number> extends Error { readonly code: Code; readonly cause?: Error | undefined; constructor(code: Code, message?: string, cause?: Error | undefined); } export declare type MiniflareOptions = SharedOptions & (WorkerOptions | { workers: WorkerOptions[]; }); export declare type ModuleDefinition = z.infer<typeof ModuleDefinitionSchema>; export declare const ModuleDefinitionSchema: z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; path: z.ZodString; contents: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>>; }, "strip", z.ZodTypeAny, { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }, { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }>; export declare type ModuleRule = z.infer<typeof ModuleRuleSchema>; export declare const ModuleRuleSchema: z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; include: z.ZodArray<z.ZodString, "many">; fallthrough: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }>; export declare type ModuleRuleType = z.infer<typeof ModuleRuleTypeSchema>; export declare const ModuleRuleTypeSchema: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; export declare class Mutex { private locked; private resolveQueue; private lock; private unlock; get hasWaiting(): boolean; runWith<T>(closure: () => Awaitable<T>): Promise<T>; } export declare function namespaceEntries(namespaces?: Record<string, string> | string[]): [bindingName: string, id: string][]; export declare interface Network { allow?: string[]; deny?: string[]; tlsOptions?: TlsOptions; } export declare function nonCircularClone<T>(value: T): T; export declare const NOOP_CACHE_SCRIPT: string; export declare class NoOpLog extends Log { constructor(); protected log(): void; error(message: Error): void; } export declare function normaliseDurableObject(designator: NonNullable<z.infer<typeof DurableObjectsOptionsSchema>["durableObjects"]>[string]): [className: string, serviceName: string | undefined]; export declare type OmitRequest<T> = Omit<T, "method" | "object">; export declare type OptionalZodTypeOf<T extends z.ZodTypeAny | undefined> = T extends z.ZodTypeAny ? z.TypeOf<T> : undefined; export declare const PARAM_FILE_UNSANITISE = "unsanitise"; export declare interface ParsedRange { offset: number; length: number; } export declare function parseRange({ offset, length, suffix }: Range, size: number): ParsedRange; /* Excluded from this release type: _parseRanges */ export declare function parseRoutes(allRoutes: Map<string, string[]>): WorkerRoute[]; export declare const PATCH: (path: string) => (prototype: Router<any>, key: string | symbol) => void; export declare type Persistence = z.infer<typeof PersistenceSchema>; export declare const PersistenceSchema: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>; export declare type Plugin<Options extends z.ZodType, SharedOptions extends z.ZodType | undefined = undefined, Gateway = undefined> = PluginBase<Options, SharedOptions> & (SharedOptions extends undefined ? { sharedOptions?: undefined; } : { sharedOptions: SharedOptions; }) & (Gateway extends undefined ? { gateway?: undefined; router?: undefined; remoteStorage?: undefined; } : { gateway: GatewayConstructor<Gateway>; router: RouterConstructor<Gateway>; remoteStorage?: RemoteStorageConstructor; }); export declare const PLUGIN_ENTRIES: ["cache" | "kv" | "core" | "do" | "d1" | "r2", ValueOf<{ core: Plugin_2<z.ZodIntersection<z.ZodUnion<[z.ZodObject<{ modules: z.ZodArray<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; path: z.ZodString; contents: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>>; }, "strip", z.ZodTypeAny, { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }, { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }>, "many">; modulesRoot: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { modulesRoot?: string | undefined; modules: { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }[]; }, { modulesRoot?: string | undefined; modules: { contents?: string | Uint8Array | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; path: string; }[]; }>, z.ZodObject<{ script: z.ZodString; scriptPath: z.ZodOptional<z.ZodString>; modules: z.ZodOptional<z.ZodBoolean>; modulesRules: z.ZodOptional<z.ZodArray<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; include: z.ZodArray<z.ZodString, "many">; fallthrough: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }>, "many">>; }, "strip", z.ZodTypeAny, { modules?: boolean | undefined; scriptPath?: string | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; script: string; }, { modules?: boolean | undefined; scriptPath?: string | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; script: string; }>, z.ZodObject<{ scriptPath: z.ZodString; modules: z.ZodOptional<z.ZodBoolean>; modulesRules: z.ZodOptional<z.ZodArray<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"ESModule">, z.ZodLiteral<"CommonJS">, z.ZodLiteral<"Text">, z.ZodLiteral<"Data">, z.ZodLiteral<"CompiledWasm">]>; include: z.ZodArray<z.ZodString, "many">; fallthrough: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }, { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }>, "many">>; }, "strip", z.ZodTypeAny, { modules?: boolean | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; scriptPath: string; }, { modules?: boolean | undefined; modulesRules?: { fallthrough?: boolean | undefined; type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"; include: string[]; }[] | undefined; scriptPath: string; }>]>, z.ZodObject<{ name: z.ZodOptional<z.ZodString>; compatibilityDate: z.ZodOptional<z.ZodString>; compatibilityFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; routes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; bindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json_3, z.ZodTypeDef, Json_3>>>; wasmBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; textBlobBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; dataBlobBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; serviceBindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{ network: z.ZodObject<{ allow: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; deny: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; tlsOptions: z.ZodOptional<z.ZodObject<{ keypair: z.ZodOptional<z.ZodObject<{ privateKey: z.ZodOptional<z.ZodString>; certificateChain: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { privateKey?: string | undefined; certificateChain?: string | undefined; }, { privateKey?: string | undefined; certificateChain?: string | undefined; }>>; requireClientCerts: z.ZodOptional<z.ZodBoolean>; trustBrowserCas: z.ZodOptional<z.ZodBoolean>; trustedCertificates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; minVersion: z.ZodOptional<z.ZodNativeEnum<TlsOptions_Version_3>>; cipherList: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { minVersion?: TlsOptions_Version_3 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCertificates?: string[] | undefined; cipherList?: string | undefined; }, { minVersion?: TlsOptions_Version_3 | undefined; keypair?: { privateKey?: string | undefined; certificateChain?: string | undefined; } | undefined; requireClientCerts?: boolean | undefined; trustBrowserCas?: boolean | undefined; trustedCer