miniflare
Advanced tools
Comparing version 0.0.0-10242377a to 0.0.0-103148b28
@@ -29,5 +29,5 @@ var __create = Object.create; | ||
// ../../node_modules/.pnpm/http-cache-semantics@4.1.0/node_modules/http-cache-semantics/index.js | ||
// ../../node_modules/.pnpm/http-cache-semantics@4.1.1/node_modules/http-cache-semantics/index.js | ||
var require_http_cache_semantics = __commonJS({ | ||
"../../node_modules/.pnpm/http-cache-semantics@4.1.0/node_modules/http-cache-semantics/index.js"(exports, module) { | ||
"../../node_modules/.pnpm/http-cache-semantics@4.1.1/node_modules/http-cache-semantics/index.js"(exports, module) { | ||
"use strict"; | ||
@@ -41,2 +41,3 @@ var statusCodeCacheableByDefault = /* @__PURE__ */ new Set([ | ||
301, | ||
308, | ||
404, | ||
@@ -96,6 +97,6 @@ 405, | ||
return cc; | ||
let parts = header.trim().split(/\s*,\s*/); | ||
let parts = header.trim().split(/,/); | ||
for (let part of parts) { | ||
let [k, v] = part.split(/\s*=\s*/, 2); | ||
cc[k] = v === void 0 ? !0 : v.replace(/^"|"$/g, ""); | ||
let [k, v] = part.split(/=/, 2); | ||
cc[k.trim()] = v === void 0 ? !0 : v.trim().replace(/^"|"$/g, ""); | ||
} | ||
@@ -102,0 +103,0 @@ return cc; |
@@ -689,3 +689,3 @@ // ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs | ||
function isObject(value) { | ||
return value && typeof value == "object"; | ||
return !!value && typeof value == "object"; | ||
} | ||
@@ -695,2 +695,5 @@ function getType(value) { | ||
} | ||
function isInternal(value) { | ||
return isObject(value) && value[Symbol.for("cloudflare:internal-class")]; | ||
} | ||
var ProxyServer = class { | ||
@@ -710,3 +713,3 @@ constructor(_state, env) { | ||
let type = getType(value); | ||
if (type === "Object" && !isPlainObject(value) || type === "Promise") { | ||
if ((type === "Object" || isInternal(value)) && !isPlainObject(value) || type === "Promise") { | ||
let address = this.nextHeapAddress++; | ||
@@ -869,3 +872,3 @@ this.heap.set(address, value), assert2(value !== null); | ||
var encoder = new TextEncoder(); | ||
function getUserRequest(request, env) { | ||
function getUserRequest(request, env, clientIp) { | ||
let originalUrl = request.headers.get(CoreHeaders.ORIGINAL_URL), url = new URL(originalUrl ?? request.url), rewriteHeadersFromOriginalUrl = !1, proxySharedSecret = request.headers.get( | ||
@@ -889,12 +892,7 @@ CoreHeaders.PROXY_SHARED_SECRET | ||
} | ||
if (request = new Request(url, request), request.cf === void 0) { | ||
let cf = { | ||
...env[CoreBindings.JSON_CF_BLOB], | ||
// Defaulting to empty string to preserve undefined `Accept-Encoding` | ||
// through Wrangler's proxy worker. | ||
clientAcceptEncoding: request.headers.get("Accept-Encoding") ?? "" | ||
}; | ||
request = new Request(request, { cf }); | ||
if (request = new Request(url, request), request.headers.set("Accept-Encoding", "br, gzip"), rewriteHeadersFromOriginalUrl && request.headers.set("Host", url.host), clientIp && !request.headers.get("CF-Connecting-IP")) { | ||
let ipv4Regex = /(?<ip>.*?):\d+/, ipv6Regex = /\[(?<ip>.*?)\]:\d+/, ip = clientIp.match(ipv6Regex)?.groups?.ip ?? clientIp.match(ipv4Regex)?.groups?.ip; | ||
ip && request.headers.set("CF-Connecting-IP", ip); | ||
} | ||
return request.headers.set("Accept-Encoding", "br, gzip"), rewriteHeadersFromOriginalUrl && request.headers.set("Host", url.host), request.headers.delete(CoreHeaders.PROXY_SHARED_SECRET), request.headers.delete(CoreHeaders.ORIGINAL_URL), request.headers.delete(CoreHeaders.DISABLE_PRETTY_ERROR), request; | ||
return request.headers.delete(CoreHeaders.PROXY_SHARED_SECRET), request.headers.delete(CoreHeaders.ORIGINAL_URL), request.headers.delete(CoreHeaders.DISABLE_PRETTY_ERROR), request; | ||
} | ||
@@ -1014,8 +1012,13 @@ function getTargetService(request, url, env) { | ||
async fetch(request, env, ctx) { | ||
let startTime = Date.now(); | ||
if (request.headers.get(CoreHeaders.OP) !== null) | ||
let startTime = Date.now(), clientIp = request.cf?.clientIp, clientCfBlobHeader = request.headers.get(CoreHeaders.CF_BLOB), cf = clientCfBlobHeader ? JSON.parse(clientCfBlobHeader) : { | ||
...env[CoreBindings.JSON_CF_BLOB], | ||
// Defaulting to empty string to preserve undefined `Accept-Encoding` | ||
// through Wrangler's proxy worker. | ||
clientAcceptEncoding: request.headers.get("Accept-Encoding") ?? "" | ||
}; | ||
if (request = new Request(request, { cf }), request.headers.get(CoreHeaders.OP) !== null) | ||
return handleProxy(request, env); | ||
let disablePrettyErrorPage = request.headers.get(CoreHeaders.DISABLE_PRETTY_ERROR) !== null, clientAcceptEncoding = request.headers.get("Accept-Encoding"); | ||
try { | ||
request = getUserRequest(request, env); | ||
request = getUserRequest(request, env, clientIp); | ||
} catch (e) { | ||
@@ -1022,0 +1025,0 @@ if (e instanceof HttpError) |
@@ -53,3 +53,3 @@ var __defProp = Object.defineProperty; | ||
let colType = columns[i].type, cellType = typeof cell; | ||
return cell === null ? "NULL" : colType === "INTEGER" || cellType === "number" ? cell : colType === "TEXT" || cellType === "string" ? outputQuotedEscapedString(cell) : cell instanceof ArrayBuffer ? `X'${Array.prototype.map.call(new Uint8Array(cell), (b) => b.toString(16)).join("")}'` : (console.log({ colType, cellType, cell, column: columns[i] }), "ERROR"); | ||
return cell === null ? "NULL" : colType === "INTEGER" || cellType === "number" ? cell : colType === "TEXT" || cellType === "string" ? outputQuotedEscapedString(cell) : cell instanceof ArrayBuffer ? `X'${Array.prototype.map.call(new Uint8Array(cell), (b) => b.toString(16).padStart(2, "0")).join("")}'` : (console.log({ colType, cellType, cell, column: columns[i] }), "ERROR"); | ||
}); | ||
@@ -56,0 +56,0 @@ yield `INSERT INTO ${sqliteQuote(table)} VALUES(${formattedCells.join(",")});`; |
@@ -57,8 +57,10 @@ var __defProp = Object.defineProperty; | ||
maxBatchSize: z.number().min(0).max(100).optional(), | ||
maxBatchTimeout: z.number().min(0).max(30).optional(), | ||
maxBatchTimeout: z.number().min(0).max(60).optional(), | ||
// seconds | ||
maxRetires: z.number().min(0).max(100).optional(), | ||
// deprecated | ||
maxRetries: z.number().min(0).max(100).optional(), | ||
deadLetterQueue: z.ostring(), | ||
retryDelay: QueueMessageDelaySchema | ||
}), QueueConsumerSchema = /* @__PURE__ */ z.intersection( | ||
}).transform((queue) => (queue.maxRetires !== void 0 && (queue.maxRetries = queue.maxRetires), queue)), QueueConsumerSchema = /* @__PURE__ */ z.intersection( | ||
QueueConsumerOptionsSchema, | ||
@@ -180,3 +182,5 @@ z.object({ workerName: z.string() }) | ||
get #maybeProducer() { | ||
return this.#producers[this.name]; | ||
return Object.values(this.#producers).find( | ||
(p) => p?.queueName === this.name | ||
); | ||
} | ||
@@ -201,3 +205,3 @@ get #maybeConsumer() { | ||
assert(consumer !== void 0); | ||
let batchSize = consumer.maxBatchSize ?? DEFAULT_BATCH_SIZE, maxAttempts = (consumer.maxRetires ?? DEFAULT_RETRIES) + 1, maxAttemptsS = maxAttempts === 1 ? "" : "s", batch = this.#messages.splice(0, batchSize), startTime = Date.now(), endTime, response; | ||
let batchSize = consumer.maxBatchSize ?? DEFAULT_BATCH_SIZE, maxAttempts = (consumer.maxRetries ?? DEFAULT_RETRIES) + 1, maxAttemptsS = maxAttempts === 1 ? "" : "s", batch = this.#messages.splice(0, batchSize), startTime = Date.now(), endTime, response; | ||
try { | ||
@@ -268,13 +272,17 @@ response = await this.#dispatchBatch(consumer.workerName, batch), endTime = Date.now(); | ||
message = async (req) => { | ||
if (this.#maybeConsumer === void 0) | ||
return new Response(); | ||
validateMessageSize(req.headers); | ||
let contentType = validateContentType(req.headers), delay = validateMessageDelay(req.headers), body = Buffer2.from(await req.arrayBuffer()); | ||
return this.#maybeConsumer === void 0 ? new Response() : (this.#enqueue( | ||
let contentType = validateContentType(req.headers), delay = validateMessageDelay(req.headers) ?? this.#maybeProducer?.deliveryDelay, body = Buffer2.from(await req.arrayBuffer()); | ||
return this.#enqueue( | ||
[{ contentType, delaySecs: delay, body }], | ||
this.#maybeProducer?.deliveryDelay | ||
), new Response()); | ||
), new Response(); | ||
}; | ||
batch = async (req) => { | ||
if (this.#maybeConsumer === void 0) | ||
return new Response(); | ||
validateBatchSize(req.headers); | ||
let delay = validateMessageDelay(req.headers) ?? this.#maybeProducer?.deliveryDelay, body = QueuesBatchRequestSchema.parse(await req.json()); | ||
return this.#maybeConsumer === void 0 ? new Response() : (this.#enqueue(body.messages, delay), new Response()); | ||
return this.#enqueue(body.messages, delay), new Response(); | ||
}; | ||
@@ -281,0 +289,0 @@ }; |
@@ -8,3 +8,6 @@ // src/workers/shared/blob.worker.ts | ||
function viewToBuffer(view) { | ||
return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength); | ||
return view.buffer.slice( | ||
view.byteOffset, | ||
view.byteOffset + view.byteLength | ||
); | ||
} | ||
@@ -11,0 +14,0 @@ function base64Encode(value) { |
{ | ||
"name": "miniflare", | ||
"version": "0.0.0-10242377a", | ||
"version": "0.0.0-103148b28", | ||
"description": "Fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -34,18 +34,17 @@ "keywords": [ | ||
"@cspotcode/source-map-support": "0.8.1", | ||
"acorn": "^8.8.0", | ||
"acorn-walk": "^8.2.0", | ||
"capnp-ts": "^0.7.0", | ||
"exit-hook": "^2.2.1", | ||
"glob-to-regexp": "^0.4.1", | ||
"stoppable": "^1.1.0", | ||
"acorn": "8.14.0", | ||
"acorn-walk": "8.3.2", | ||
"exit-hook": "2.2.1", | ||
"glob-to-regexp": "0.4.1", | ||
"stoppable": "1.1.0", | ||
"undici": "^5.28.4", | ||
"workerd": "1.20240821.1", | ||
"ws": "^8.17.1", | ||
"youch": "^3.2.2", | ||
"zod": "^3.22.3" | ||
"workerd": "1.20250204.0", | ||
"ws": "8.18.0", | ||
"youch": "3.2.3", | ||
"zod": "3.22.3" | ||
}, | ||
"devDependencies": { | ||
"@ava/typescript": "^4.1.0", | ||
"@cloudflare/workers-types": "^4.20240821.1", | ||
"@microsoft/api-extractor": "^7.47.0", | ||
"@cloudflare/workers-types": "^4.20250204.0", | ||
"@microsoft/api-extractor": "7.49.1", | ||
"@types/debug": "^4.1.7", | ||
@@ -56,4 +55,3 @@ "@types/estree": "^1.0.0", | ||
"@types/mime": "^3.0.4", | ||
"@types/node": "20.8.3", | ||
"@types/rimraf": "^4.0.5", | ||
"@types/node": "^18.19.71", | ||
"@types/stoppable": "^1.1.1", | ||
@@ -65,3 +63,3 @@ "@types/which": "^2.0.1", | ||
"ava": "^6.0.1", | ||
"capnpc-ts": "^0.7.0", | ||
"capnp-es": "^0.0.7", | ||
"concurrently": "^8.2.2", | ||
@@ -77,2 +75,3 @@ "devalue": "^4.3.0", | ||
"expect-type": "^0.15.0", | ||
"heap-js": "^2.5.0", | ||
"http-cache-semantics": "^4.1.0", | ||
@@ -82,6 +81,9 @@ "kleur": "^4.1.5", | ||
"pretty-bytes": "^6.0.0", | ||
"rimraf": "^5.0.1", | ||
"rimraf": "^5.0.10", | ||
"source-map": "^0.6.1", | ||
"typescript": "^5.7.2", | ||
"which": "^2.0.2", | ||
"@cloudflare/kv-asset-handler": "0.3.4" | ||
"@cloudflare/kv-asset-handler": "0.3.4", | ||
"@cloudflare/workers-shared": "0.0.0-103148b28", | ||
"@cloudflare/workflows-shared": "0.2.2" | ||
}, | ||
@@ -102,3 +104,3 @@ "engines": { | ||
"build": "node scripts/build.mjs && pnpm run types:build", | ||
"capnp:workerd": "capnpc -o ts src/runtime/config/workerd.capnp", | ||
"capnp:workerd": "node scripts/build-capnp.mjs", | ||
"check:lint": "eslint --max-warnings=0 \"{src,test}/**/*.ts\" \"scripts/**/*.{js,mjs}\" \"types/**/*.ts\"", | ||
@@ -105,0 +107,0 @@ "check:type": "tsc", |
@@ -217,2 +217,16 @@ # 🔥 Miniflare | ||
### `interface WorkflowOptions` | ||
- `name: string` | ||
The name of the Workflow. | ||
- `className: string` | ||
The name of the class exported from the Worker that implements the `WorkflowEntrypoint`. | ||
- `scriptName?`: string | ||
The name of the script that includes the `WorkflowEntrypoint`. This is optional because it defaults to the current script if not set. | ||
#### Core | ||
@@ -578,2 +592,25 @@ | ||
#### Assets | ||
- `directory?: string` | ||
Path to serve Workers static asset files from. | ||
- `binding?: string` | ||
Binding name to inject as a `Fetcher` binding to allow access to static assets from within the Worker. | ||
- `assetOptions?: { html_handling?: HTMLHandlingOptions, not_found_handling?: NotFoundHandlingOptions}` | ||
Configuration for file-based asset routing - see [docs](https://developers.cloudflare.com/workers/static-assets/routing/#routing-configuration) for options | ||
#### Pipelines | ||
- `pipelines?: Record<string, PipelineOptions> | string[]` | ||
Record mapping binding name to a Pipeline. Different workers may bind to the same Pipeline with different bindings | ||
names. If a `string[]` of pipeline names, the binding and Pipeline name are assumed to be the same. | ||
#### Workflows | ||
- `workflows?: WorkflowOptions[]` | ||
Configuration for one or more Workflows in your project. | ||
#### Analytics Engine, Sending Email, Vectorize and Workers for Platforms | ||
@@ -719,2 +756,6 @@ | ||
- `workflowsPersist?: Persistence` | ||
Where to persist data stored in Workflows. See docs for `Persistence`. | ||
#### Analytics Engine, Browser Rendering, Sending Email, Vectorize, Workers AI and Workers for Platforms | ||
@@ -721,0 +762,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2839182
11
42
45059
889
38
45
8
+ Added@cloudflare/workerd-darwin-64@1.20250204.0(transitive)
+ Added@cloudflare/workerd-darwin-arm64@1.20250204.0(transitive)
+ Added@cloudflare/workerd-linux-64@1.20250204.0(transitive)
+ Added@cloudflare/workerd-linux-arm64@1.20250204.0(transitive)
+ Added@cloudflare/workerd-windows-64@1.20250204.0(transitive)
+ Addedacorn-walk@8.3.2(transitive)
+ Addedcookie@0.5.0(transitive)
+ Addedworkerd@1.20250204.0(transitive)
+ Addedws@8.18.0(transitive)
+ Addedyouch@3.2.3(transitive)
+ Addedzod@3.22.3(transitive)
- Removedcapnp-ts@^0.7.0
- Removed@cloudflare/workerd-darwin-64@1.20240821.1(transitive)
- Removed@cloudflare/workerd-darwin-arm64@1.20240821.1(transitive)
- Removed@cloudflare/workerd-linux-64@1.20240821.1(transitive)
- Removed@cloudflare/workerd-linux-arm64@1.20240821.1(transitive)
- Removed@cloudflare/workerd-windows-64@1.20240821.1(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedcapnp-ts@0.7.0(transitive)
- Removedcookie@0.7.2(transitive)
- Removeddebug@4.4.0(transitive)
- Removedms@2.1.3(transitive)
- Removedtslib@2.8.1(transitive)
- Removedworkerd@1.20240821.1(transitive)
- Removedws@8.18.1(transitive)
- Removedyouch@3.3.4(transitive)
- Removedzod@3.24.2(transitive)
Updatedacorn@8.14.0
Updatedacorn-walk@8.3.2
Updatedexit-hook@2.2.1
Updatedglob-to-regexp@0.4.1
Updatedstoppable@1.1.0
Updatedworkerd@1.20250204.0
Updatedws@8.18.0
Updatedyouch@3.2.3
Updatedzod@3.22.3