@statewalker/cellb 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +323 -2
- package/dist/adapters/files-backup.d.ts +16 -0
- package/dist/adapters/files-backup.js +32 -0
- package/dist/adapters/files-backup.js.map +1 -0
- package/dist/adapters/files-changelog.d.ts +33 -0
- package/dist/adapters/files-changelog.js +96 -0
- package/dist/adapters/files-changelog.js.map +1 -0
- package/dist/adapters/files-ltx.d.ts +35 -0
- package/dist/adapters/files-ltx.js +9 -0
- package/dist/adapters/files-ltx.js.map +1 -0
- package/dist/adapters/ltx-vfs.d.ts +21 -0
- package/dist/adapters/ltx-vfs.js +286 -0
- package/dist/adapters/ltx-vfs.js.map +1 -0
- package/dist/adapters/node-sqlite.d.ts +45 -0
- package/dist/adapters/node-sqlite.js +254 -0
- package/dist/adapters/node-sqlite.js.map +1 -0
- package/dist/adapters/wasm-page-hook.d.ts +26 -0
- package/dist/adapters/wasm-page-hook.js +55 -0
- package/dist/adapters/wasm-page-hook.js.map +1 -0
- package/dist/adapters/wasm-session.d.ts +11 -0
- package/dist/adapters/wasm-session.js +76 -0
- package/dist/adapters/wasm-session.js.map +1 -0
- package/dist/adapters/wasm-sqlite.d.ts +89 -0
- package/dist/adapters/wasm-sqlite.js +258 -0
- package/dist/adapters/wasm-sqlite.js.map +1 -0
- package/dist/bindings/assets.d.ts +26 -0
- package/dist/bindings/assets.js +260 -0
- package/dist/bindings/assets.js.map +1 -0
- package/dist/bindings/cache.d.ts +16 -0
- package/dist/bindings/cache.js +34 -0
- package/dist/bindings/cache.js.map +1 -0
- package/dist/bindings/celld-kv.d.ts +26 -0
- package/dist/bindings/celld-kv.js +81 -0
- package/dist/bindings/celld-kv.js.map +1 -0
- package/dist/bindings/celld-queues.d.ts +56 -0
- package/dist/bindings/celld-queues.js +223 -0
- package/dist/bindings/celld-queues.js.map +1 -0
- package/dist/bindings/celld-workflows.d.ts +22 -0
- package/dist/bindings/celld-workflows.js +54 -0
- package/dist/bindings/celld-workflows.js.map +1 -0
- package/dist/bindings/cron.d.ts +27 -0
- package/dist/bindings/cron.js +232 -0
- package/dist/bindings/cron.js.map +1 -0
- package/dist/bindings/d1-migrations.d.ts +22 -0
- package/dist/bindings/d1-migrations.js +32 -0
- package/dist/bindings/d1-migrations.js.map +1 -0
- package/dist/bindings/html-rewriter.d.ts +8 -0
- package/dist/bindings/html-rewriter.js +75 -0
- package/dist/bindings/html-rewriter.js.map +1 -0
- package/dist/bindings/r2-celld.d.ts +3 -0
- package/dist/bindings/r2-celld.js +113 -0
- package/dist/bindings/r2-celld.js.map +1 -0
- package/dist/bindings/r2.d.ts +236 -0
- package/dist/bindings/r2.js +419 -0
- package/dist/bindings/r2.js.map +1 -0
- package/dist/bindings/worker-loader.d.ts +83 -0
- package/dist/bindings/worker-loader.js +183 -0
- package/dist/bindings/worker-loader.js.map +1 -0
- package/dist/bindings/workers-ai.d.ts +39 -0
- package/dist/bindings/workers-ai.js +175 -0
- package/dist/bindings/workers-ai.js.map +1 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +8 -0
- package/dist/browser.js.map +1 -0
- package/dist/bucket/celld-cells.d.ts +86 -0
- package/dist/bucket/celld-cells.js +273 -0
- package/dist/bucket/celld-cells.js.map +1 -0
- package/dist/bucket/celld-format.d.ts +10 -0
- package/dist/bucket/celld-format.js +27 -0
- package/dist/bucket/celld-format.js.map +1 -0
- package/dist/bucket/idb-object-store.d.ts +9 -0
- package/dist/bucket/idb-object-store.js +73 -0
- package/dist/bucket/idb-object-store.js.map +1 -0
- package/dist/bucket/ltx-log.d.ts +34 -0
- package/dist/bucket/ltx-log.js +289 -0
- package/dist/bucket/ltx-log.js.map +1 -0
- package/dist/bucket/object-store.d.ts +51 -0
- package/dist/bucket/object-store.js +114 -0
- package/dist/bucket/object-store.js.map +1 -0
- package/dist/bucket/s3-object-store.d.ts +25 -0
- package/dist/bucket/s3-object-store.js +151 -0
- package/dist/bucket/s3-object-store.js.map +1 -0
- package/dist/bucket/sqlite-object-store.d.ts +10 -0
- package/dist/bucket/sqlite-object-store.js +107 -0
- package/dist/bucket/sqlite-object-store.js.map +1 -0
- package/dist/core/alarms.d.ts +27 -0
- package/dist/core/alarms.js +88 -0
- package/dist/core/alarms.js.map +1 -0
- package/dist/core/async-context.d.ts +34 -0
- package/dist/core/async-context.js +50 -0
- package/dist/core/async-context.js.map +1 -0
- package/dist/core/celld-schema.d.ts +14 -0
- package/dist/core/celld-schema.js +34 -0
- package/dist/core/celld-schema.js.map +1 -0
- package/dist/core/durable-object.d.ts +28 -0
- package/dist/core/durable-object.js +31 -0
- package/dist/core/durable-object.js.map +1 -0
- package/dist/core/gates.d.ts +33 -0
- package/dist/core/gates.js +89 -0
- package/dist/core/gates.js.map +1 -0
- package/dist/core/handles.d.ts +90 -0
- package/dist/core/handles.js +224 -0
- package/dist/core/handles.js.map +1 -0
- package/dist/core/id.d.ts +19 -0
- package/dist/core/id.js +64 -0
- package/dist/core/id.js.map +1 -0
- package/dist/core/namespace.d.ts +38 -0
- package/dist/core/namespace.js +141 -0
- package/dist/core/namespace.js.map +1 -0
- package/dist/core/object-host.d.ts +91 -0
- package/dist/core/object-host.js +616 -0
- package/dist/core/object-host.js.map +1 -0
- package/dist/core/request-body.d.ts +9 -0
- package/dist/core/request-body.js +55 -0
- package/dist/core/request-body.js.map +1 -0
- package/dist/core/runtime.d.ts +121 -0
- package/dist/core/runtime.js +366 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/shard.d.ts +7 -0
- package/dist/core/shard.js +10 -0
- package/dist/core/shard.js.map +1 -0
- package/dist/core/sql-split.d.ts +15 -0
- package/dist/core/sql-split.js +101 -0
- package/dist/core/sql-split.js.map +1 -0
- package/dist/core/sql-storage.d.ts +53 -0
- package/dist/core/sql-storage.js +407 -0
- package/dist/core/sql-storage.js.map +1 -0
- package/dist/core/state.d.ts +44 -0
- package/dist/core/state.js +93 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/storage.d.ts +103 -0
- package/dist/core/storage.js +351 -0
- package/dist/core/storage.js.map +1 -0
- package/dist/core/worker-rejections.d.ts +21 -0
- package/dist/core/worker-rejections.js +55 -0
- package/dist/core/worker-rejections.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/isolate/browser.d.ts +16 -0
- package/dist/isolate/browser.js +37 -0
- package/dist/isolate/browser.js.map +1 -0
- package/dist/isolate/host.d.ts +24 -0
- package/dist/isolate/host.js +74 -0
- package/dist/isolate/host.js.map +1 -0
- package/dist/isolate/isolate-worker.d.ts +1 -0
- package/dist/isolate/isolate-worker.js +53 -0
- package/dist/isolate/isolate-worker.js.map +1 -0
- package/dist/isolate/isolate.d.ts +10 -0
- package/dist/isolate/isolate.js +169 -0
- package/dist/isolate/isolate.js.map +1 -0
- package/dist/isolate/node-entry.d.ts +1 -0
- package/dist/isolate/node-entry.js +12 -0
- package/dist/isolate/node-entry.js.map +1 -0
- package/dist/isolate/protocol.d.ts +66 -0
- package/dist/isolate/protocol.js +205 -0
- package/dist/isolate/protocol.js.map +1 -0
- package/dist/ltx/crc64.d.ts +6 -0
- package/dist/ltx/crc64.js +46 -0
- package/dist/ltx/crc64.js.map +1 -0
- package/dist/ltx/ltx-page-server.d.ts +65 -0
- package/dist/ltx/ltx-page-server.js +309 -0
- package/dist/ltx/ltx-page-server.js.map +1 -0
- package/dist/ltx/ltx-pages.d.ts +81 -0
- package/dist/ltx/ltx-pages.js +315 -0
- package/dist/ltx/ltx-pages.js.map +1 -0
- package/dist/ltx/ltx-store-worker.d.ts +1 -0
- package/dist/ltx/ltx-store-worker.js +38 -0
- package/dist/ltx/ltx-store-worker.js.map +1 -0
- package/dist/ltx/ltx.d.ts +45 -0
- package/dist/ltx/ltx.js +203 -0
- package/dist/ltx/ltx.js.map +1 -0
- package/dist/ltx/lz4.d.ts +9 -0
- package/dist/ltx/lz4.js +156 -0
- package/dist/ltx/lz4.js.map +1 -0
- package/dist/ltx/opfs-sync-files.d.ts +23 -0
- package/dist/ltx/opfs-sync-files.js +191 -0
- package/dist/ltx/opfs-sync-files.js.map +1 -0
- package/dist/ltx/xxh32.d.ts +1 -0
- package/dist/ltx/xxh32.js +43 -0
- package/dist/ltx/xxh32.js.map +1 -0
- package/dist/miniflare-compat/blob-service.d.ts +13 -0
- package/dist/miniflare-compat/blob-service.js +66 -0
- package/dist/miniflare-compat/blob-service.js.map +1 -0
- package/dist/miniflare-compat/kv-binding.d.ts +44 -0
- package/dist/miniflare-compat/kv-binding.js +99 -0
- package/dist/miniflare-compat/kv-binding.js.map +1 -0
- package/dist/miniflare-compat/shims/assert.d.ts +15 -0
- package/dist/miniflare-compat/shims/assert.js +24 -0
- package/dist/miniflare-compat/shims/assert.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-cloudflare.d.ts +7 -0
- package/dist/miniflare-compat/shims/workerd-cloudflare.js +6 -0
- package/dist/miniflare-compat/shims/workerd-cloudflare.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-globals.d.ts +1 -0
- package/dist/miniflare-compat/shims/workerd-globals.js +30 -0
- package/dist/miniflare-compat/shims/workerd-globals.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-internal.d.ts +20 -0
- package/dist/miniflare-compat/shims/workerd-internal.js +23 -0
- package/dist/miniflare-compat/shims/workerd-internal.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-performance.d.ts +4 -0
- package/dist/miniflare-compat/shims/workerd-performance.js +17 -0
- package/dist/miniflare-compat/shims/workerd-performance.js.map +1 -0
- package/dist/miniflare-compat/simulator-fetcher.d.ts +9 -0
- package/dist/miniflare-compat/simulator-fetcher.js +14 -0
- package/dist/miniflare-compat/simulator-fetcher.js.map +1 -0
- package/dist/miniflare-compat/vendored.d.ts +15 -0
- package/dist/miniflare-compat/vendored.js +27 -0
- package/dist/miniflare-compat/vendored.js.map +1 -0
- package/dist/node-compat/async_hooks.d.ts +22 -0
- package/dist/node-compat/async_hooks.js +176 -0
- package/dist/node-compat/async_hooks.js.map +1 -0
- package/dist/node-compat/browser-registry.d.ts +3 -0
- package/dist/node-compat/browser-registry.js +39 -0
- package/dist/node-compat/browser-registry.js.map +1 -0
- package/dist/node-compat/crypto.d.ts +60 -0
- package/dist/node-compat/crypto.js +143 -0
- package/dist/node-compat/crypto.js.map +1 -0
- package/dist/node-compat/diagnostics_channel.d.ts +27 -0
- package/dist/node-compat/diagnostics_channel.js +46 -0
- package/dist/node-compat/diagnostics_channel.js.map +1 -0
- package/dist/node-compat/fs.d.ts +35 -0
- package/dist/node-compat/fs.js +40 -0
- package/dist/node-compat/fs.js.map +1 -0
- package/dist/node-compat/globals.d.ts +3 -0
- package/dist/node-compat/globals.js +4 -0
- package/dist/node-compat/globals.js.map +1 -0
- package/dist/node-compat/install.d.ts +5 -0
- package/dist/node-compat/install.js +12 -0
- package/dist/node-compat/install.js.map +1 -0
- package/dist/node-compat/module.d.ts +12 -0
- package/dist/node-compat/module.js +36 -0
- package/dist/node-compat/module.js.map +1 -0
- package/dist/node-compat/modules.d.ts +8 -0
- package/dist/node-compat/modules.js +23 -0
- package/dist/node-compat/modules.js.map +1 -0
- package/dist/node-compat/os.d.ts +36 -0
- package/dist/node-compat/os.js +36 -0
- package/dist/node-compat/os.js.map +1 -0
- package/dist/node-compat/process.d.ts +14 -0
- package/dist/node-compat/process.js +16 -0
- package/dist/node-compat/process.js.map +1 -0
- package/dist/node-compat/shims.d.ts +4 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +6 -0
- package/dist/node.js.map +1 -0
- package/dist/peer/celld-peer.d.ts +53 -0
- package/dist/peer/celld-peer.js +555 -0
- package/dist/peer/celld-peer.js.map +1 -0
- package/dist/ports.d.ts +183 -0
- package/dist/ports.js +10 -0
- package/dist/ports.js.map +1 -0
- package/dist/project/browser-bundle.d.ts +17 -0
- package/dist/project/browser-bundle.js +125 -0
- package/dist/project/browser-bundle.js.map +1 -0
- package/dist/project/browser-cookies.d.ts +12 -0
- package/dist/project/browser-cookies.js +90 -0
- package/dist/project/browser-cookies.js.map +1 -0
- package/dist/project/browser-host.d.ts +173 -0
- package/dist/project/browser-host.js +200 -0
- package/dist/project/browser-host.js.map +1 -0
- package/dist/project/browser-modules.d.ts +17 -0
- package/dist/project/browser-modules.js +89 -0
- package/dist/project/browser-modules.js.map +1 -0
- package/dist/project/browser-shards.d.ts +62 -0
- package/dist/project/browser-shards.js +210 -0
- package/dist/project/browser-shards.js.map +1 -0
- package/dist/project/browser-tabs.d.ts +103 -0
- package/dist/project/browser-tabs.js +418 -0
- package/dist/project/browser-tabs.js.map +1 -0
- package/dist/project/cloudflare-email.d.ts +8 -0
- package/dist/project/cloudflare-email.js +11 -0
- package/dist/project/cloudflare-email.js.map +1 -0
- package/dist/project/cloudflare-workers.d.ts +12 -0
- package/dist/project/cloudflare-workers.js +16 -0
- package/dist/project/cloudflare-workers.js.map +1 -0
- package/dist/project/host-modules.d.ts +4 -0
- package/dist/project/host-modules.js +40 -0
- package/dist/project/host-modules.js.map +1 -0
- package/dist/project/jsonc.d.ts +2 -0
- package/dist/project/jsonc.js +27 -0
- package/dist/project/jsonc.js.map +1 -0
- package/dist/project/lower-await.d.ts +2 -0
- package/dist/project/lower-await.js +151 -0
- package/dist/project/lower-await.js.map +1 -0
- package/dist/project/node-project.d.ts +38 -0
- package/dist/project/node-project.js +362 -0
- package/dist/project/node-project.js.map +1 -0
- package/dist/project/own-module.d.ts +6 -0
- package/dist/project/own-module.js +13 -0
- package/dist/project/own-module.js.map +1 -0
- package/dist/project/scheduler.d.ts +2 -0
- package/dist/project/scheduler.js +3 -0
- package/dist/project/scheduler.js.map +1 -0
- package/dist/project/site.d.ts +74 -0
- package/dist/project/site.js +206 -0
- package/dist/project/site.js.map +1 -0
- package/dist/project/virtual-modules.d.ts +3 -0
- package/dist/project/worker-scope.d.ts +27 -0
- package/dist/project/worker-scope.js +46 -0
- package/dist/project/worker-scope.js.map +1 -0
- package/dist/project/workerd-message-channel.d.ts +13 -0
- package/dist/project/workerd-message-channel.js +137 -0
- package/dist/project/workerd-message-channel.js.map +1 -0
- package/dist/project/workers-global-names.d.ts +6 -0
- package/dist/project/workers-global-names.js +15 -0
- package/dist/project/workers-global-names.js.map +1 -0
- package/dist/project/workers-globals-module.d.ts +8 -0
- package/dist/project/workers-globals-module.js +9 -0
- package/dist/project/workers-globals-module.js.map +1 -0
- package/dist/project/workers-globals.d.ts +9 -0
- package/dist/project/workers-globals.js +19 -0
- package/dist/project/workers-globals.js.map +1 -0
- package/dist/project/wrangler.d.ts +116 -0
- package/dist/project/wrangler.js +342 -0
- package/dist/project/wrangler.js.map +1 -0
- package/dist/router/cell-router.d.ts +72 -0
- package/dist/router/cell-router.js +247 -0
- package/dist/router/cell-router.js.map +1 -0
- package/dist/router/shard-worker.d.ts +44 -0
- package/dist/router/shard-worker.js +163 -0
- package/dist/router/shard-worker.js.map +1 -0
- package/dist/transport/cells-http.d.ts +25 -0
- package/dist/transport/cells-http.js +141 -0
- package/dist/transport/cells-http.js.map +1 -0
- package/dist/transport/cells-link.d.ts +27 -0
- package/dist/transport/cells-link.js +71 -0
- package/dist/transport/cells-link.js.map +1 -0
- package/dist/transport/port.d.ts +26 -0
- package/dist/transport/port.js +100 -0
- package/dist/transport/port.js.map +1 -0
- package/dist/v8/codec.d.ts +6 -0
- package/dist/v8/codec.js +9 -0
- package/dist/v8/codec.js.map +1 -0
- package/dist/v8/serialize.d.ts +10 -0
- package/dist/v8/serialize.js +601 -0
- package/dist/v8/serialize.js.map +1 -0
- package/dist/ws/client.d.ts +25 -0
- package/dist/ws/client.js +203 -0
- package/dist/ws/client.js.map +1 -0
- package/dist/ws/control.d.ts +48 -0
- package/dist/ws/control.js +44 -0
- package/dist/ws/control.js.map +1 -0
- package/dist/ws/frames.d.ts +38 -0
- package/dist/ws/frames.js +39 -0
- package/dist/ws/frames.js.map +1 -0
- package/dist/ws/server.d.ts +99 -0
- package/dist/ws/server.js +295 -0
- package/dist/ws/server.js.map +1 -0
- package/dist/ws/sw-connector.d.ts +10 -0
- package/dist/ws/sw-connector.js +25 -0
- package/dist/ws/sw-connector.js.map +1 -0
- package/dist/ws/upgrade.d.ts +28 -0
- package/dist/ws/upgrade.js +75 -0
- package/dist/ws/upgrade.js.map +1 -0
- package/package.json +111 -3
- package/vendor/celld/LICENSE +202 -0
- package/vendor/celld/kv.js +1131 -0
- package/vendor/celld/queues.js +1656 -0
- package/vendor/celld/workflows.js +1610 -0
- package/vendor/html-rewriter-wasm/html_rewriter.js +925 -0
- package/vendor/html-rewriter-wasm/html_rewriter_bg.wasm +0 -0
- package/vendor/miniflare/d1-api.js +738 -0
- package/vendor/miniflare/d1-database.js +6978 -0
- package/vendor/miniflare/kv-namespace.js +3061 -0
|
@@ -0,0 +1,3061 @@
|
|
|
1
|
+
// GENERATED by scripts/vendor-miniflare.mjs from cloudflare/workers-sdk@d0359e06bee7970bc857430590733af8a8f1d372 packages/miniflare/src/workers/kv/namespace.worker.ts (MIT OR Apache-2.0). Do not edit.
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res, err) => function __init() {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
17
|
+
try {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw mod = 0, e;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
40
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
41
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
42
|
+
if (decorator = decorators[i])
|
|
43
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
44
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/miniflare-compat/shims/workerd-globals.ts
|
|
49
|
+
var g, BYOB;
|
|
50
|
+
var init_workerd_globals = __esm({
|
|
51
|
+
"src/miniflare-compat/shims/workerd-globals.ts"() {
|
|
52
|
+
g = globalThis;
|
|
53
|
+
if (typeof g.IdentityTransformStream === "undefined") {
|
|
54
|
+
g.IdentityTransformStream = class IdentityTransformStream extends TransformStream {
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
BYOB = globalThis.ReadableStreamBYOBReader;
|
|
58
|
+
if (BYOB && typeof BYOB.prototype.readAtLeast !== "function") {
|
|
59
|
+
BYOB.prototype.readAtLeast = async function readAtLeast(min, view) {
|
|
60
|
+
let offset = 0;
|
|
61
|
+
let buffer = view.buffer;
|
|
62
|
+
while (offset < min) {
|
|
63
|
+
const { value, done } = await this.read(
|
|
64
|
+
new Uint8Array(buffer, view.byteOffset + offset, view.byteLength - offset)
|
|
65
|
+
);
|
|
66
|
+
if (value) {
|
|
67
|
+
buffer = value.buffer;
|
|
68
|
+
offset += value.byteLength;
|
|
69
|
+
}
|
|
70
|
+
if (done)
|
|
71
|
+
return { value: new Uint8Array(buffer, view.byteOffset, offset), done: offset === 0 };
|
|
72
|
+
}
|
|
73
|
+
return { value: new Uint8Array(buffer, view.byteOffset, offset), done: false };
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// src/miniflare-compat/shims/workerd-performance.ts
|
|
80
|
+
var real, performance;
|
|
81
|
+
var init_workerd_performance = __esm({
|
|
82
|
+
"src/miniflare-compat/shims/workerd-performance.ts"() {
|
|
83
|
+
real = globalThis.performance;
|
|
84
|
+
performance = {
|
|
85
|
+
get timeOrigin() {
|
|
86
|
+
return Math.floor(real.timeOrigin);
|
|
87
|
+
},
|
|
88
|
+
now() {
|
|
89
|
+
return Math.floor(real.now());
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
|
|
96
|
+
var require_base64_js = __commonJS({
|
|
97
|
+
"../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports) {
|
|
98
|
+
"use strict";
|
|
99
|
+
init_workerd_globals();
|
|
100
|
+
init_workerd_performance();
|
|
101
|
+
exports.byteLength = byteLength;
|
|
102
|
+
exports.toByteArray = toByteArray;
|
|
103
|
+
exports.fromByteArray = fromByteArray;
|
|
104
|
+
var lookup = [];
|
|
105
|
+
var revLookup = [];
|
|
106
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
107
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
108
|
+
for (i = 0, len = code.length; i < len; ++i) {
|
|
109
|
+
lookup[i] = code[i];
|
|
110
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
111
|
+
}
|
|
112
|
+
var i;
|
|
113
|
+
var len;
|
|
114
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
115
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
116
|
+
function getLens(b64) {
|
|
117
|
+
var len2 = b64.length;
|
|
118
|
+
if (len2 % 4 > 0) {
|
|
119
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
120
|
+
}
|
|
121
|
+
var validLen = b64.indexOf("=");
|
|
122
|
+
if (validLen === -1) validLen = len2;
|
|
123
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
124
|
+
return [validLen, placeHoldersLen];
|
|
125
|
+
}
|
|
126
|
+
function byteLength(b64) {
|
|
127
|
+
var lens = getLens(b64);
|
|
128
|
+
var validLen = lens[0];
|
|
129
|
+
var placeHoldersLen = lens[1];
|
|
130
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
131
|
+
}
|
|
132
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
133
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
134
|
+
}
|
|
135
|
+
function toByteArray(b64) {
|
|
136
|
+
var tmp;
|
|
137
|
+
var lens = getLens(b64);
|
|
138
|
+
var validLen = lens[0];
|
|
139
|
+
var placeHoldersLen = lens[1];
|
|
140
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
141
|
+
var curByte = 0;
|
|
142
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
143
|
+
var i2;
|
|
144
|
+
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
145
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
146
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
147
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
148
|
+
arr[curByte++] = tmp & 255;
|
|
149
|
+
}
|
|
150
|
+
if (placeHoldersLen === 2) {
|
|
151
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
152
|
+
arr[curByte++] = tmp & 255;
|
|
153
|
+
}
|
|
154
|
+
if (placeHoldersLen === 1) {
|
|
155
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
156
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
157
|
+
arr[curByte++] = tmp & 255;
|
|
158
|
+
}
|
|
159
|
+
return arr;
|
|
160
|
+
}
|
|
161
|
+
function tripletToBase64(num) {
|
|
162
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
163
|
+
}
|
|
164
|
+
function encodeChunk(uint8, start, end) {
|
|
165
|
+
var tmp;
|
|
166
|
+
var output = [];
|
|
167
|
+
for (var i2 = start; i2 < end; i2 += 3) {
|
|
168
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
169
|
+
output.push(tripletToBase64(tmp));
|
|
170
|
+
}
|
|
171
|
+
return output.join("");
|
|
172
|
+
}
|
|
173
|
+
function fromByteArray(uint8) {
|
|
174
|
+
var tmp;
|
|
175
|
+
var len2 = uint8.length;
|
|
176
|
+
var extraBytes = len2 % 3;
|
|
177
|
+
var parts = [];
|
|
178
|
+
var maxChunkLength = 16383;
|
|
179
|
+
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
180
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
181
|
+
}
|
|
182
|
+
if (extraBytes === 1) {
|
|
183
|
+
tmp = uint8[len2 - 1];
|
|
184
|
+
parts.push(
|
|
185
|
+
lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
|
|
186
|
+
);
|
|
187
|
+
} else if (extraBytes === 2) {
|
|
188
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
189
|
+
parts.push(
|
|
190
|
+
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return parts.join("");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// ../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js
|
|
199
|
+
var require_ieee754 = __commonJS({
|
|
200
|
+
"../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js"(exports) {
|
|
201
|
+
init_workerd_globals();
|
|
202
|
+
init_workerd_performance();
|
|
203
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
204
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
205
|
+
var e, m;
|
|
206
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
207
|
+
var eMax = (1 << eLen) - 1;
|
|
208
|
+
var eBias = eMax >> 1;
|
|
209
|
+
var nBits = -7;
|
|
210
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
211
|
+
var d = isLE ? -1 : 1;
|
|
212
|
+
var s = buffer[offset + i];
|
|
213
|
+
i += d;
|
|
214
|
+
e = s & (1 << -nBits) - 1;
|
|
215
|
+
s >>= -nBits;
|
|
216
|
+
nBits += eLen;
|
|
217
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
218
|
+
}
|
|
219
|
+
m = e & (1 << -nBits) - 1;
|
|
220
|
+
e >>= -nBits;
|
|
221
|
+
nBits += mLen;
|
|
222
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
223
|
+
}
|
|
224
|
+
if (e === 0) {
|
|
225
|
+
e = 1 - eBias;
|
|
226
|
+
} else if (e === eMax) {
|
|
227
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
228
|
+
} else {
|
|
229
|
+
m = m + Math.pow(2, mLen);
|
|
230
|
+
e = e - eBias;
|
|
231
|
+
}
|
|
232
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
233
|
+
};
|
|
234
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
235
|
+
var e, m, c;
|
|
236
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
237
|
+
var eMax = (1 << eLen) - 1;
|
|
238
|
+
var eBias = eMax >> 1;
|
|
239
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
240
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
241
|
+
var d = isLE ? 1 : -1;
|
|
242
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
243
|
+
value = Math.abs(value);
|
|
244
|
+
if (isNaN(value) || value === Infinity) {
|
|
245
|
+
m = isNaN(value) ? 1 : 0;
|
|
246
|
+
e = eMax;
|
|
247
|
+
} else {
|
|
248
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
249
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
250
|
+
e--;
|
|
251
|
+
c *= 2;
|
|
252
|
+
}
|
|
253
|
+
if (e + eBias >= 1) {
|
|
254
|
+
value += rt / c;
|
|
255
|
+
} else {
|
|
256
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
257
|
+
}
|
|
258
|
+
if (value * c >= 2) {
|
|
259
|
+
e++;
|
|
260
|
+
c /= 2;
|
|
261
|
+
}
|
|
262
|
+
if (e + eBias >= eMax) {
|
|
263
|
+
m = 0;
|
|
264
|
+
e = eMax;
|
|
265
|
+
} else if (e + eBias >= 1) {
|
|
266
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
267
|
+
e = e + eBias;
|
|
268
|
+
} else {
|
|
269
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
270
|
+
e = 0;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
274
|
+
}
|
|
275
|
+
e = e << mLen | m;
|
|
276
|
+
eLen += mLen;
|
|
277
|
+
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
278
|
+
}
|
|
279
|
+
buffer[offset + i - d] |= s * 128;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// ../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js
|
|
285
|
+
var require_buffer = __commonJS({
|
|
286
|
+
"../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js"(exports) {
|
|
287
|
+
"use strict";
|
|
288
|
+
init_workerd_globals();
|
|
289
|
+
init_workerd_performance();
|
|
290
|
+
/*!
|
|
291
|
+
* The buffer module from node.js, for the browser.
|
|
292
|
+
*
|
|
293
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
294
|
+
* @license MIT
|
|
295
|
+
*/
|
|
296
|
+
var base64 = require_base64_js();
|
|
297
|
+
var ieee754 = require_ieee754();
|
|
298
|
+
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
299
|
+
exports.Buffer = Buffer5;
|
|
300
|
+
exports.SlowBuffer = SlowBuffer;
|
|
301
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
302
|
+
var K_MAX_LENGTH = 2147483647;
|
|
303
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
304
|
+
Buffer5.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
305
|
+
if (!Buffer5.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
306
|
+
console.error(
|
|
307
|
+
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
function typedArraySupport() {
|
|
311
|
+
try {
|
|
312
|
+
const arr = new Uint8Array(1);
|
|
313
|
+
const proto = { foo: function() {
|
|
314
|
+
return 42;
|
|
315
|
+
} };
|
|
316
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
317
|
+
Object.setPrototypeOf(arr, proto);
|
|
318
|
+
return arr.foo() === 42;
|
|
319
|
+
} catch (e) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
Object.defineProperty(Buffer5.prototype, "parent", {
|
|
324
|
+
enumerable: true,
|
|
325
|
+
get: function() {
|
|
326
|
+
if (!Buffer5.isBuffer(this)) return void 0;
|
|
327
|
+
return this.buffer;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
Object.defineProperty(Buffer5.prototype, "offset", {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
get: function() {
|
|
333
|
+
if (!Buffer5.isBuffer(this)) return void 0;
|
|
334
|
+
return this.byteOffset;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
function createBuffer(length) {
|
|
338
|
+
if (length > K_MAX_LENGTH) {
|
|
339
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"');
|
|
340
|
+
}
|
|
341
|
+
const buf = new Uint8Array(length);
|
|
342
|
+
Object.setPrototypeOf(buf, Buffer5.prototype);
|
|
343
|
+
return buf;
|
|
344
|
+
}
|
|
345
|
+
function Buffer5(arg, encodingOrOffset, length) {
|
|
346
|
+
if (typeof arg === "number") {
|
|
347
|
+
if (typeof encodingOrOffset === "string") {
|
|
348
|
+
throw new TypeError(
|
|
349
|
+
'The "string" argument must be of type string. Received type number'
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return allocUnsafe(arg);
|
|
353
|
+
}
|
|
354
|
+
return from(arg, encodingOrOffset, length);
|
|
355
|
+
}
|
|
356
|
+
Buffer5.poolSize = 8192;
|
|
357
|
+
function from(value, encodingOrOffset, length) {
|
|
358
|
+
if (typeof value === "string") {
|
|
359
|
+
return fromString(value, encodingOrOffset);
|
|
360
|
+
}
|
|
361
|
+
if (ArrayBuffer.isView(value)) {
|
|
362
|
+
return fromArrayView(value);
|
|
363
|
+
}
|
|
364
|
+
if (value == null) {
|
|
365
|
+
throw new TypeError(
|
|
366
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
370
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
371
|
+
}
|
|
372
|
+
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
373
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
374
|
+
}
|
|
375
|
+
if (typeof value === "number") {
|
|
376
|
+
throw new TypeError(
|
|
377
|
+
'The "value" argument must not be of type number. Received type number'
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
381
|
+
if (valueOf != null && valueOf !== value) {
|
|
382
|
+
return Buffer5.from(valueOf, encodingOrOffset, length);
|
|
383
|
+
}
|
|
384
|
+
const b = fromObject(value);
|
|
385
|
+
if (b) return b;
|
|
386
|
+
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
387
|
+
return Buffer5.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
388
|
+
}
|
|
389
|
+
throw new TypeError(
|
|
390
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
Buffer5.from = function(value, encodingOrOffset, length) {
|
|
394
|
+
return from(value, encodingOrOffset, length);
|
|
395
|
+
};
|
|
396
|
+
Object.setPrototypeOf(Buffer5.prototype, Uint8Array.prototype);
|
|
397
|
+
Object.setPrototypeOf(Buffer5, Uint8Array);
|
|
398
|
+
function assertSize(size) {
|
|
399
|
+
if (typeof size !== "number") {
|
|
400
|
+
throw new TypeError('"size" argument must be of type number');
|
|
401
|
+
} else if (size < 0) {
|
|
402
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function alloc(size, fill, encoding) {
|
|
406
|
+
assertSize(size);
|
|
407
|
+
if (size <= 0) {
|
|
408
|
+
return createBuffer(size);
|
|
409
|
+
}
|
|
410
|
+
if (fill !== void 0) {
|
|
411
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
412
|
+
}
|
|
413
|
+
return createBuffer(size);
|
|
414
|
+
}
|
|
415
|
+
Buffer5.alloc = function(size, fill, encoding) {
|
|
416
|
+
return alloc(size, fill, encoding);
|
|
417
|
+
};
|
|
418
|
+
function allocUnsafe(size) {
|
|
419
|
+
assertSize(size);
|
|
420
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
421
|
+
}
|
|
422
|
+
Buffer5.allocUnsafe = function(size) {
|
|
423
|
+
return allocUnsafe(size);
|
|
424
|
+
};
|
|
425
|
+
Buffer5.allocUnsafeSlow = function(size) {
|
|
426
|
+
return allocUnsafe(size);
|
|
427
|
+
};
|
|
428
|
+
function fromString(string, encoding) {
|
|
429
|
+
if (typeof encoding !== "string" || encoding === "") {
|
|
430
|
+
encoding = "utf8";
|
|
431
|
+
}
|
|
432
|
+
if (!Buffer5.isEncoding(encoding)) {
|
|
433
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
434
|
+
}
|
|
435
|
+
const length = byteLength(string, encoding) | 0;
|
|
436
|
+
let buf = createBuffer(length);
|
|
437
|
+
const actual = buf.write(string, encoding);
|
|
438
|
+
if (actual !== length) {
|
|
439
|
+
buf = buf.slice(0, actual);
|
|
440
|
+
}
|
|
441
|
+
return buf;
|
|
442
|
+
}
|
|
443
|
+
function fromArrayLike(array) {
|
|
444
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
445
|
+
const buf = createBuffer(length);
|
|
446
|
+
for (let i = 0; i < length; i += 1) {
|
|
447
|
+
buf[i] = array[i] & 255;
|
|
448
|
+
}
|
|
449
|
+
return buf;
|
|
450
|
+
}
|
|
451
|
+
function fromArrayView(arrayView) {
|
|
452
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
453
|
+
const copy = new Uint8Array(arrayView);
|
|
454
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
455
|
+
}
|
|
456
|
+
return fromArrayLike(arrayView);
|
|
457
|
+
}
|
|
458
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
459
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
460
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
461
|
+
}
|
|
462
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
463
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
464
|
+
}
|
|
465
|
+
let buf;
|
|
466
|
+
if (byteOffset === void 0 && length === void 0) {
|
|
467
|
+
buf = new Uint8Array(array);
|
|
468
|
+
} else if (length === void 0) {
|
|
469
|
+
buf = new Uint8Array(array, byteOffset);
|
|
470
|
+
} else {
|
|
471
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
472
|
+
}
|
|
473
|
+
Object.setPrototypeOf(buf, Buffer5.prototype);
|
|
474
|
+
return buf;
|
|
475
|
+
}
|
|
476
|
+
function fromObject(obj) {
|
|
477
|
+
if (Buffer5.isBuffer(obj)) {
|
|
478
|
+
const len = checked(obj.length) | 0;
|
|
479
|
+
const buf = createBuffer(len);
|
|
480
|
+
if (buf.length === 0) {
|
|
481
|
+
return buf;
|
|
482
|
+
}
|
|
483
|
+
obj.copy(buf, 0, 0, len);
|
|
484
|
+
return buf;
|
|
485
|
+
}
|
|
486
|
+
if (obj.length !== void 0) {
|
|
487
|
+
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
488
|
+
return createBuffer(0);
|
|
489
|
+
}
|
|
490
|
+
return fromArrayLike(obj);
|
|
491
|
+
}
|
|
492
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
493
|
+
return fromArrayLike(obj.data);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function checked(length) {
|
|
497
|
+
if (length >= K_MAX_LENGTH) {
|
|
498
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
499
|
+
}
|
|
500
|
+
return length | 0;
|
|
501
|
+
}
|
|
502
|
+
function SlowBuffer(length) {
|
|
503
|
+
if (+length != length) {
|
|
504
|
+
length = 0;
|
|
505
|
+
}
|
|
506
|
+
return Buffer5.alloc(+length);
|
|
507
|
+
}
|
|
508
|
+
Buffer5.isBuffer = function isBuffer(b) {
|
|
509
|
+
return b != null && b._isBuffer === true && b !== Buffer5.prototype;
|
|
510
|
+
};
|
|
511
|
+
Buffer5.compare = function compare(a, b) {
|
|
512
|
+
if (isInstance(a, Uint8Array)) a = Buffer5.from(a, a.offset, a.byteLength);
|
|
513
|
+
if (isInstance(b, Uint8Array)) b = Buffer5.from(b, b.offset, b.byteLength);
|
|
514
|
+
if (!Buffer5.isBuffer(a) || !Buffer5.isBuffer(b)) {
|
|
515
|
+
throw new TypeError(
|
|
516
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
if (a === b) return 0;
|
|
520
|
+
let x = a.length;
|
|
521
|
+
let y = b.length;
|
|
522
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
523
|
+
if (a[i] !== b[i]) {
|
|
524
|
+
x = a[i];
|
|
525
|
+
y = b[i];
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (x < y) return -1;
|
|
530
|
+
if (y < x) return 1;
|
|
531
|
+
return 0;
|
|
532
|
+
};
|
|
533
|
+
Buffer5.isEncoding = function isEncoding(encoding) {
|
|
534
|
+
switch (String(encoding).toLowerCase()) {
|
|
535
|
+
case "hex":
|
|
536
|
+
case "utf8":
|
|
537
|
+
case "utf-8":
|
|
538
|
+
case "ascii":
|
|
539
|
+
case "latin1":
|
|
540
|
+
case "binary":
|
|
541
|
+
case "base64":
|
|
542
|
+
case "ucs2":
|
|
543
|
+
case "ucs-2":
|
|
544
|
+
case "utf16le":
|
|
545
|
+
case "utf-16le":
|
|
546
|
+
return true;
|
|
547
|
+
default:
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
Buffer5.concat = function concat(list, length) {
|
|
552
|
+
if (!Array.isArray(list)) {
|
|
553
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
554
|
+
}
|
|
555
|
+
if (list.length === 0) {
|
|
556
|
+
return Buffer5.alloc(0);
|
|
557
|
+
}
|
|
558
|
+
let i;
|
|
559
|
+
if (length === void 0) {
|
|
560
|
+
length = 0;
|
|
561
|
+
for (i = 0; i < list.length; ++i) {
|
|
562
|
+
length += list[i].length;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
const buffer = Buffer5.allocUnsafe(length);
|
|
566
|
+
let pos = 0;
|
|
567
|
+
for (i = 0; i < list.length; ++i) {
|
|
568
|
+
let buf = list[i];
|
|
569
|
+
if (isInstance(buf, Uint8Array)) {
|
|
570
|
+
if (pos + buf.length > buffer.length) {
|
|
571
|
+
if (!Buffer5.isBuffer(buf)) buf = Buffer5.from(buf);
|
|
572
|
+
buf.copy(buffer, pos);
|
|
573
|
+
} else {
|
|
574
|
+
Uint8Array.prototype.set.call(
|
|
575
|
+
buffer,
|
|
576
|
+
buf,
|
|
577
|
+
pos
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
} else if (!Buffer5.isBuffer(buf)) {
|
|
581
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
582
|
+
} else {
|
|
583
|
+
buf.copy(buffer, pos);
|
|
584
|
+
}
|
|
585
|
+
pos += buf.length;
|
|
586
|
+
}
|
|
587
|
+
return buffer;
|
|
588
|
+
};
|
|
589
|
+
function byteLength(string, encoding) {
|
|
590
|
+
if (Buffer5.isBuffer(string)) {
|
|
591
|
+
return string.length;
|
|
592
|
+
}
|
|
593
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
594
|
+
return string.byteLength;
|
|
595
|
+
}
|
|
596
|
+
if (typeof string !== "string") {
|
|
597
|
+
throw new TypeError(
|
|
598
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
const len = string.length;
|
|
602
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
603
|
+
if (!mustMatch && len === 0) return 0;
|
|
604
|
+
let loweredCase = false;
|
|
605
|
+
for (; ; ) {
|
|
606
|
+
switch (encoding) {
|
|
607
|
+
case "ascii":
|
|
608
|
+
case "latin1":
|
|
609
|
+
case "binary":
|
|
610
|
+
return len;
|
|
611
|
+
case "utf8":
|
|
612
|
+
case "utf-8":
|
|
613
|
+
return utf8ToBytes(string).length;
|
|
614
|
+
case "ucs2":
|
|
615
|
+
case "ucs-2":
|
|
616
|
+
case "utf16le":
|
|
617
|
+
case "utf-16le":
|
|
618
|
+
return len * 2;
|
|
619
|
+
case "hex":
|
|
620
|
+
return len >>> 1;
|
|
621
|
+
case "base64":
|
|
622
|
+
return base64ToBytes(string).length;
|
|
623
|
+
default:
|
|
624
|
+
if (loweredCase) {
|
|
625
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
626
|
+
}
|
|
627
|
+
encoding = ("" + encoding).toLowerCase();
|
|
628
|
+
loweredCase = true;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
Buffer5.byteLength = byteLength;
|
|
633
|
+
function slowToString(encoding, start, end) {
|
|
634
|
+
let loweredCase = false;
|
|
635
|
+
if (start === void 0 || start < 0) {
|
|
636
|
+
start = 0;
|
|
637
|
+
}
|
|
638
|
+
if (start > this.length) {
|
|
639
|
+
return "";
|
|
640
|
+
}
|
|
641
|
+
if (end === void 0 || end > this.length) {
|
|
642
|
+
end = this.length;
|
|
643
|
+
}
|
|
644
|
+
if (end <= 0) {
|
|
645
|
+
return "";
|
|
646
|
+
}
|
|
647
|
+
end >>>= 0;
|
|
648
|
+
start >>>= 0;
|
|
649
|
+
if (end <= start) {
|
|
650
|
+
return "";
|
|
651
|
+
}
|
|
652
|
+
if (!encoding) encoding = "utf8";
|
|
653
|
+
while (true) {
|
|
654
|
+
switch (encoding) {
|
|
655
|
+
case "hex":
|
|
656
|
+
return hexSlice(this, start, end);
|
|
657
|
+
case "utf8":
|
|
658
|
+
case "utf-8":
|
|
659
|
+
return utf8Slice(this, start, end);
|
|
660
|
+
case "ascii":
|
|
661
|
+
return asciiSlice(this, start, end);
|
|
662
|
+
case "latin1":
|
|
663
|
+
case "binary":
|
|
664
|
+
return latin1Slice(this, start, end);
|
|
665
|
+
case "base64":
|
|
666
|
+
return base64Slice(this, start, end);
|
|
667
|
+
case "ucs2":
|
|
668
|
+
case "ucs-2":
|
|
669
|
+
case "utf16le":
|
|
670
|
+
case "utf-16le":
|
|
671
|
+
return utf16leSlice(this, start, end);
|
|
672
|
+
default:
|
|
673
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
674
|
+
encoding = (encoding + "").toLowerCase();
|
|
675
|
+
loweredCase = true;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
Buffer5.prototype._isBuffer = true;
|
|
680
|
+
function swap(b, n, m) {
|
|
681
|
+
const i = b[n];
|
|
682
|
+
b[n] = b[m];
|
|
683
|
+
b[m] = i;
|
|
684
|
+
}
|
|
685
|
+
Buffer5.prototype.swap16 = function swap16() {
|
|
686
|
+
const len = this.length;
|
|
687
|
+
if (len % 2 !== 0) {
|
|
688
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
689
|
+
}
|
|
690
|
+
for (let i = 0; i < len; i += 2) {
|
|
691
|
+
swap(this, i, i + 1);
|
|
692
|
+
}
|
|
693
|
+
return this;
|
|
694
|
+
};
|
|
695
|
+
Buffer5.prototype.swap32 = function swap32() {
|
|
696
|
+
const len = this.length;
|
|
697
|
+
if (len % 4 !== 0) {
|
|
698
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
699
|
+
}
|
|
700
|
+
for (let i = 0; i < len; i += 4) {
|
|
701
|
+
swap(this, i, i + 3);
|
|
702
|
+
swap(this, i + 1, i + 2);
|
|
703
|
+
}
|
|
704
|
+
return this;
|
|
705
|
+
};
|
|
706
|
+
Buffer5.prototype.swap64 = function swap64() {
|
|
707
|
+
const len = this.length;
|
|
708
|
+
if (len % 8 !== 0) {
|
|
709
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
710
|
+
}
|
|
711
|
+
for (let i = 0; i < len; i += 8) {
|
|
712
|
+
swap(this, i, i + 7);
|
|
713
|
+
swap(this, i + 1, i + 6);
|
|
714
|
+
swap(this, i + 2, i + 5);
|
|
715
|
+
swap(this, i + 3, i + 4);
|
|
716
|
+
}
|
|
717
|
+
return this;
|
|
718
|
+
};
|
|
719
|
+
Buffer5.prototype.toString = function toString() {
|
|
720
|
+
const length = this.length;
|
|
721
|
+
if (length === 0) return "";
|
|
722
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
723
|
+
return slowToString.apply(this, arguments);
|
|
724
|
+
};
|
|
725
|
+
Buffer5.prototype.toLocaleString = Buffer5.prototype.toString;
|
|
726
|
+
Buffer5.prototype.equals = function equals(b) {
|
|
727
|
+
if (!Buffer5.isBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
728
|
+
if (this === b) return true;
|
|
729
|
+
return Buffer5.compare(this, b) === 0;
|
|
730
|
+
};
|
|
731
|
+
Buffer5.prototype.inspect = function inspect() {
|
|
732
|
+
let str = "";
|
|
733
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
734
|
+
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
735
|
+
if (this.length > max) str += " ... ";
|
|
736
|
+
return "<Buffer " + str + ">";
|
|
737
|
+
};
|
|
738
|
+
if (customInspectSymbol) {
|
|
739
|
+
Buffer5.prototype[customInspectSymbol] = Buffer5.prototype.inspect;
|
|
740
|
+
}
|
|
741
|
+
Buffer5.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
742
|
+
if (isInstance(target, Uint8Array)) {
|
|
743
|
+
target = Buffer5.from(target, target.offset, target.byteLength);
|
|
744
|
+
}
|
|
745
|
+
if (!Buffer5.isBuffer(target)) {
|
|
746
|
+
throw new TypeError(
|
|
747
|
+
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
if (start === void 0) {
|
|
751
|
+
start = 0;
|
|
752
|
+
}
|
|
753
|
+
if (end === void 0) {
|
|
754
|
+
end = target ? target.length : 0;
|
|
755
|
+
}
|
|
756
|
+
if (thisStart === void 0) {
|
|
757
|
+
thisStart = 0;
|
|
758
|
+
}
|
|
759
|
+
if (thisEnd === void 0) {
|
|
760
|
+
thisEnd = this.length;
|
|
761
|
+
}
|
|
762
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
763
|
+
throw new RangeError("out of range index");
|
|
764
|
+
}
|
|
765
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
766
|
+
return 0;
|
|
767
|
+
}
|
|
768
|
+
if (thisStart >= thisEnd) {
|
|
769
|
+
return -1;
|
|
770
|
+
}
|
|
771
|
+
if (start >= end) {
|
|
772
|
+
return 1;
|
|
773
|
+
}
|
|
774
|
+
start >>>= 0;
|
|
775
|
+
end >>>= 0;
|
|
776
|
+
thisStart >>>= 0;
|
|
777
|
+
thisEnd >>>= 0;
|
|
778
|
+
if (this === target) return 0;
|
|
779
|
+
let x = thisEnd - thisStart;
|
|
780
|
+
let y = end - start;
|
|
781
|
+
const len = Math.min(x, y);
|
|
782
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
783
|
+
const targetCopy = target.slice(start, end);
|
|
784
|
+
for (let i = 0; i < len; ++i) {
|
|
785
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
786
|
+
x = thisCopy[i];
|
|
787
|
+
y = targetCopy[i];
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if (x < y) return -1;
|
|
792
|
+
if (y < x) return 1;
|
|
793
|
+
return 0;
|
|
794
|
+
};
|
|
795
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
796
|
+
if (buffer.length === 0) return -1;
|
|
797
|
+
if (typeof byteOffset === "string") {
|
|
798
|
+
encoding = byteOffset;
|
|
799
|
+
byteOffset = 0;
|
|
800
|
+
} else if (byteOffset > 2147483647) {
|
|
801
|
+
byteOffset = 2147483647;
|
|
802
|
+
} else if (byteOffset < -2147483648) {
|
|
803
|
+
byteOffset = -2147483648;
|
|
804
|
+
}
|
|
805
|
+
byteOffset = +byteOffset;
|
|
806
|
+
if (numberIsNaN(byteOffset)) {
|
|
807
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
808
|
+
}
|
|
809
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
810
|
+
if (byteOffset >= buffer.length) {
|
|
811
|
+
if (dir) return -1;
|
|
812
|
+
else byteOffset = buffer.length - 1;
|
|
813
|
+
} else if (byteOffset < 0) {
|
|
814
|
+
if (dir) byteOffset = 0;
|
|
815
|
+
else return -1;
|
|
816
|
+
}
|
|
817
|
+
if (typeof val === "string") {
|
|
818
|
+
val = Buffer5.from(val, encoding);
|
|
819
|
+
}
|
|
820
|
+
if (Buffer5.isBuffer(val)) {
|
|
821
|
+
if (val.length === 0) {
|
|
822
|
+
return -1;
|
|
823
|
+
}
|
|
824
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
825
|
+
} else if (typeof val === "number") {
|
|
826
|
+
val = val & 255;
|
|
827
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
828
|
+
if (dir) {
|
|
829
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
830
|
+
} else {
|
|
831
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
835
|
+
}
|
|
836
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
837
|
+
}
|
|
838
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
839
|
+
let indexSize = 1;
|
|
840
|
+
let arrLength = arr.length;
|
|
841
|
+
let valLength = val.length;
|
|
842
|
+
if (encoding !== void 0) {
|
|
843
|
+
encoding = String(encoding).toLowerCase();
|
|
844
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
845
|
+
if (arr.length < 2 || val.length < 2) {
|
|
846
|
+
return -1;
|
|
847
|
+
}
|
|
848
|
+
indexSize = 2;
|
|
849
|
+
arrLength /= 2;
|
|
850
|
+
valLength /= 2;
|
|
851
|
+
byteOffset /= 2;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function read(buf, i2) {
|
|
855
|
+
if (indexSize === 1) {
|
|
856
|
+
return buf[i2];
|
|
857
|
+
} else {
|
|
858
|
+
return buf.readUInt16BE(i2 * indexSize);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
let i;
|
|
862
|
+
if (dir) {
|
|
863
|
+
let foundIndex = -1;
|
|
864
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
865
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
866
|
+
if (foundIndex === -1) foundIndex = i;
|
|
867
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
868
|
+
} else {
|
|
869
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
870
|
+
foundIndex = -1;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
} else {
|
|
874
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
875
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
876
|
+
let found = true;
|
|
877
|
+
for (let j = 0; j < valLength; j++) {
|
|
878
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
879
|
+
found = false;
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (found) return i;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return -1;
|
|
887
|
+
}
|
|
888
|
+
Buffer5.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
889
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
890
|
+
};
|
|
891
|
+
Buffer5.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
892
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
893
|
+
};
|
|
894
|
+
Buffer5.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
895
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
896
|
+
};
|
|
897
|
+
function hexWrite(buf, string, offset, length) {
|
|
898
|
+
offset = Number(offset) || 0;
|
|
899
|
+
const remaining = buf.length - offset;
|
|
900
|
+
if (!length) {
|
|
901
|
+
length = remaining;
|
|
902
|
+
} else {
|
|
903
|
+
length = Number(length);
|
|
904
|
+
if (length > remaining) {
|
|
905
|
+
length = remaining;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
const strLen = string.length;
|
|
909
|
+
if (length > strLen / 2) {
|
|
910
|
+
length = strLen / 2;
|
|
911
|
+
}
|
|
912
|
+
let i;
|
|
913
|
+
for (i = 0; i < length; ++i) {
|
|
914
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
915
|
+
if (numberIsNaN(parsed)) return i;
|
|
916
|
+
buf[offset + i] = parsed;
|
|
917
|
+
}
|
|
918
|
+
return i;
|
|
919
|
+
}
|
|
920
|
+
function utf8Write(buf, string, offset, length) {
|
|
921
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
922
|
+
}
|
|
923
|
+
function asciiWrite(buf, string, offset, length) {
|
|
924
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
925
|
+
}
|
|
926
|
+
function base64Write(buf, string, offset, length) {
|
|
927
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
928
|
+
}
|
|
929
|
+
function ucs2Write(buf, string, offset, length) {
|
|
930
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
931
|
+
}
|
|
932
|
+
Buffer5.prototype.write = function write(string, offset, length, encoding) {
|
|
933
|
+
if (offset === void 0) {
|
|
934
|
+
encoding = "utf8";
|
|
935
|
+
length = this.length;
|
|
936
|
+
offset = 0;
|
|
937
|
+
} else if (length === void 0 && typeof offset === "string") {
|
|
938
|
+
encoding = offset;
|
|
939
|
+
length = this.length;
|
|
940
|
+
offset = 0;
|
|
941
|
+
} else if (isFinite(offset)) {
|
|
942
|
+
offset = offset >>> 0;
|
|
943
|
+
if (isFinite(length)) {
|
|
944
|
+
length = length >>> 0;
|
|
945
|
+
if (encoding === void 0) encoding = "utf8";
|
|
946
|
+
} else {
|
|
947
|
+
encoding = length;
|
|
948
|
+
length = void 0;
|
|
949
|
+
}
|
|
950
|
+
} else {
|
|
951
|
+
throw new Error(
|
|
952
|
+
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
const remaining = this.length - offset;
|
|
956
|
+
if (length === void 0 || length > remaining) length = remaining;
|
|
957
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
958
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
959
|
+
}
|
|
960
|
+
if (!encoding) encoding = "utf8";
|
|
961
|
+
let loweredCase = false;
|
|
962
|
+
for (; ; ) {
|
|
963
|
+
switch (encoding) {
|
|
964
|
+
case "hex":
|
|
965
|
+
return hexWrite(this, string, offset, length);
|
|
966
|
+
case "utf8":
|
|
967
|
+
case "utf-8":
|
|
968
|
+
return utf8Write(this, string, offset, length);
|
|
969
|
+
case "ascii":
|
|
970
|
+
case "latin1":
|
|
971
|
+
case "binary":
|
|
972
|
+
return asciiWrite(this, string, offset, length);
|
|
973
|
+
case "base64":
|
|
974
|
+
return base64Write(this, string, offset, length);
|
|
975
|
+
case "ucs2":
|
|
976
|
+
case "ucs-2":
|
|
977
|
+
case "utf16le":
|
|
978
|
+
case "utf-16le":
|
|
979
|
+
return ucs2Write(this, string, offset, length);
|
|
980
|
+
default:
|
|
981
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
982
|
+
encoding = ("" + encoding).toLowerCase();
|
|
983
|
+
loweredCase = true;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
Buffer5.prototype.toJSON = function toJSON() {
|
|
988
|
+
return {
|
|
989
|
+
type: "Buffer",
|
|
990
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
991
|
+
};
|
|
992
|
+
};
|
|
993
|
+
function base64Slice(buf, start, end) {
|
|
994
|
+
if (start === 0 && end === buf.length) {
|
|
995
|
+
return base64.fromByteArray(buf);
|
|
996
|
+
} else {
|
|
997
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function utf8Slice(buf, start, end) {
|
|
1001
|
+
end = Math.min(buf.length, end);
|
|
1002
|
+
const res = [];
|
|
1003
|
+
let i = start;
|
|
1004
|
+
while (i < end) {
|
|
1005
|
+
const firstByte = buf[i];
|
|
1006
|
+
let codePoint = null;
|
|
1007
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
1008
|
+
if (i + bytesPerSequence <= end) {
|
|
1009
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1010
|
+
switch (bytesPerSequence) {
|
|
1011
|
+
case 1:
|
|
1012
|
+
if (firstByte < 128) {
|
|
1013
|
+
codePoint = firstByte;
|
|
1014
|
+
}
|
|
1015
|
+
break;
|
|
1016
|
+
case 2:
|
|
1017
|
+
secondByte = buf[i + 1];
|
|
1018
|
+
if ((secondByte & 192) === 128) {
|
|
1019
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
1020
|
+
if (tempCodePoint > 127) {
|
|
1021
|
+
codePoint = tempCodePoint;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
break;
|
|
1025
|
+
case 3:
|
|
1026
|
+
secondByte = buf[i + 1];
|
|
1027
|
+
thirdByte = buf[i + 2];
|
|
1028
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
1029
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
1030
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
1031
|
+
codePoint = tempCodePoint;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
break;
|
|
1035
|
+
case 4:
|
|
1036
|
+
secondByte = buf[i + 1];
|
|
1037
|
+
thirdByte = buf[i + 2];
|
|
1038
|
+
fourthByte = buf[i + 3];
|
|
1039
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
1040
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
1041
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
1042
|
+
codePoint = tempCodePoint;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (codePoint === null) {
|
|
1048
|
+
codePoint = 65533;
|
|
1049
|
+
bytesPerSequence = 1;
|
|
1050
|
+
} else if (codePoint > 65535) {
|
|
1051
|
+
codePoint -= 65536;
|
|
1052
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
1053
|
+
codePoint = 56320 | codePoint & 1023;
|
|
1054
|
+
}
|
|
1055
|
+
res.push(codePoint);
|
|
1056
|
+
i += bytesPerSequence;
|
|
1057
|
+
}
|
|
1058
|
+
return decodeCodePointsArray(res);
|
|
1059
|
+
}
|
|
1060
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
1061
|
+
function decodeCodePointsArray(codePoints) {
|
|
1062
|
+
const len = codePoints.length;
|
|
1063
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1064
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
1065
|
+
}
|
|
1066
|
+
let res = "";
|
|
1067
|
+
let i = 0;
|
|
1068
|
+
while (i < len) {
|
|
1069
|
+
res += String.fromCharCode.apply(
|
|
1070
|
+
String,
|
|
1071
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
return res;
|
|
1075
|
+
}
|
|
1076
|
+
function asciiSlice(buf, start, end) {
|
|
1077
|
+
let ret = "";
|
|
1078
|
+
end = Math.min(buf.length, end);
|
|
1079
|
+
for (let i = start; i < end; ++i) {
|
|
1080
|
+
ret += String.fromCharCode(buf[i] & 127);
|
|
1081
|
+
}
|
|
1082
|
+
return ret;
|
|
1083
|
+
}
|
|
1084
|
+
function latin1Slice(buf, start, end) {
|
|
1085
|
+
let ret = "";
|
|
1086
|
+
end = Math.min(buf.length, end);
|
|
1087
|
+
for (let i = start; i < end; ++i) {
|
|
1088
|
+
ret += String.fromCharCode(buf[i]);
|
|
1089
|
+
}
|
|
1090
|
+
return ret;
|
|
1091
|
+
}
|
|
1092
|
+
function hexSlice(buf, start, end) {
|
|
1093
|
+
const len = buf.length;
|
|
1094
|
+
if (!start || start < 0) start = 0;
|
|
1095
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1096
|
+
let out = "";
|
|
1097
|
+
for (let i = start; i < end; ++i) {
|
|
1098
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1099
|
+
}
|
|
1100
|
+
return out;
|
|
1101
|
+
}
|
|
1102
|
+
function utf16leSlice(buf, start, end) {
|
|
1103
|
+
const bytes = buf.slice(start, end);
|
|
1104
|
+
let res = "";
|
|
1105
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1106
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1107
|
+
}
|
|
1108
|
+
return res;
|
|
1109
|
+
}
|
|
1110
|
+
Buffer5.prototype.slice = function slice(start, end) {
|
|
1111
|
+
const len = this.length;
|
|
1112
|
+
start = ~~start;
|
|
1113
|
+
end = end === void 0 ? len : ~~end;
|
|
1114
|
+
if (start < 0) {
|
|
1115
|
+
start += len;
|
|
1116
|
+
if (start < 0) start = 0;
|
|
1117
|
+
} else if (start > len) {
|
|
1118
|
+
start = len;
|
|
1119
|
+
}
|
|
1120
|
+
if (end < 0) {
|
|
1121
|
+
end += len;
|
|
1122
|
+
if (end < 0) end = 0;
|
|
1123
|
+
} else if (end > len) {
|
|
1124
|
+
end = len;
|
|
1125
|
+
}
|
|
1126
|
+
if (end < start) end = start;
|
|
1127
|
+
const newBuf = this.subarray(start, end);
|
|
1128
|
+
Object.setPrototypeOf(newBuf, Buffer5.prototype);
|
|
1129
|
+
return newBuf;
|
|
1130
|
+
};
|
|
1131
|
+
function checkOffset(offset, ext, length) {
|
|
1132
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
1133
|
+
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
1134
|
+
}
|
|
1135
|
+
Buffer5.prototype.readUintLE = Buffer5.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1136
|
+
offset = offset >>> 0;
|
|
1137
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1138
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1139
|
+
let val = this[offset];
|
|
1140
|
+
let mul = 1;
|
|
1141
|
+
let i = 0;
|
|
1142
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1143
|
+
val += this[offset + i] * mul;
|
|
1144
|
+
}
|
|
1145
|
+
return val;
|
|
1146
|
+
};
|
|
1147
|
+
Buffer5.prototype.readUintBE = Buffer5.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1148
|
+
offset = offset >>> 0;
|
|
1149
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1150
|
+
if (!noAssert) {
|
|
1151
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1152
|
+
}
|
|
1153
|
+
let val = this[offset + --byteLength2];
|
|
1154
|
+
let mul = 1;
|
|
1155
|
+
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1156
|
+
val += this[offset + --byteLength2] * mul;
|
|
1157
|
+
}
|
|
1158
|
+
return val;
|
|
1159
|
+
};
|
|
1160
|
+
Buffer5.prototype.readUint8 = Buffer5.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1161
|
+
offset = offset >>> 0;
|
|
1162
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1163
|
+
return this[offset];
|
|
1164
|
+
};
|
|
1165
|
+
Buffer5.prototype.readUint16LE = Buffer5.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1166
|
+
offset = offset >>> 0;
|
|
1167
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1168
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1169
|
+
};
|
|
1170
|
+
Buffer5.prototype.readUint16BE = Buffer5.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1171
|
+
offset = offset >>> 0;
|
|
1172
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1173
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1174
|
+
};
|
|
1175
|
+
Buffer5.prototype.readUint32LE = Buffer5.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1176
|
+
offset = offset >>> 0;
|
|
1177
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1178
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1179
|
+
};
|
|
1180
|
+
Buffer5.prototype.readUint32BE = Buffer5.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1181
|
+
offset = offset >>> 0;
|
|
1182
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1183
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1184
|
+
};
|
|
1185
|
+
Buffer5.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1186
|
+
offset = offset >>> 0;
|
|
1187
|
+
validateNumber(offset, "offset");
|
|
1188
|
+
const first = this[offset];
|
|
1189
|
+
const last = this[offset + 7];
|
|
1190
|
+
if (first === void 0 || last === void 0) {
|
|
1191
|
+
boundsError(offset, this.length - 8);
|
|
1192
|
+
}
|
|
1193
|
+
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
1194
|
+
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
1195
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1196
|
+
});
|
|
1197
|
+
Buffer5.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1198
|
+
offset = offset >>> 0;
|
|
1199
|
+
validateNumber(offset, "offset");
|
|
1200
|
+
const first = this[offset];
|
|
1201
|
+
const last = this[offset + 7];
|
|
1202
|
+
if (first === void 0 || last === void 0) {
|
|
1203
|
+
boundsError(offset, this.length - 8);
|
|
1204
|
+
}
|
|
1205
|
+
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1206
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1207
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1208
|
+
});
|
|
1209
|
+
Buffer5.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1210
|
+
offset = offset >>> 0;
|
|
1211
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1212
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1213
|
+
let val = this[offset];
|
|
1214
|
+
let mul = 1;
|
|
1215
|
+
let i = 0;
|
|
1216
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1217
|
+
val += this[offset + i] * mul;
|
|
1218
|
+
}
|
|
1219
|
+
mul *= 128;
|
|
1220
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1221
|
+
return val;
|
|
1222
|
+
};
|
|
1223
|
+
Buffer5.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1224
|
+
offset = offset >>> 0;
|
|
1225
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1226
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1227
|
+
let i = byteLength2;
|
|
1228
|
+
let mul = 1;
|
|
1229
|
+
let val = this[offset + --i];
|
|
1230
|
+
while (i > 0 && (mul *= 256)) {
|
|
1231
|
+
val += this[offset + --i] * mul;
|
|
1232
|
+
}
|
|
1233
|
+
mul *= 128;
|
|
1234
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1235
|
+
return val;
|
|
1236
|
+
};
|
|
1237
|
+
Buffer5.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1238
|
+
offset = offset >>> 0;
|
|
1239
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1240
|
+
if (!(this[offset] & 128)) return this[offset];
|
|
1241
|
+
return (255 - this[offset] + 1) * -1;
|
|
1242
|
+
};
|
|
1243
|
+
Buffer5.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1244
|
+
offset = offset >>> 0;
|
|
1245
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1246
|
+
const val = this[offset] | this[offset + 1] << 8;
|
|
1247
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1248
|
+
};
|
|
1249
|
+
Buffer5.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1250
|
+
offset = offset >>> 0;
|
|
1251
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1252
|
+
const val = this[offset + 1] | this[offset] << 8;
|
|
1253
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1254
|
+
};
|
|
1255
|
+
Buffer5.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1256
|
+
offset = offset >>> 0;
|
|
1257
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1258
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1259
|
+
};
|
|
1260
|
+
Buffer5.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1261
|
+
offset = offset >>> 0;
|
|
1262
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1263
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1264
|
+
};
|
|
1265
|
+
Buffer5.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1266
|
+
offset = offset >>> 0;
|
|
1267
|
+
validateNumber(offset, "offset");
|
|
1268
|
+
const first = this[offset];
|
|
1269
|
+
const last = this[offset + 7];
|
|
1270
|
+
if (first === void 0 || last === void 0) {
|
|
1271
|
+
boundsError(offset, this.length - 8);
|
|
1272
|
+
}
|
|
1273
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
|
|
1274
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
|
|
1275
|
+
});
|
|
1276
|
+
Buffer5.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
|
|
1277
|
+
offset = offset >>> 0;
|
|
1278
|
+
validateNumber(offset, "offset");
|
|
1279
|
+
const first = this[offset];
|
|
1280
|
+
const last = this[offset + 7];
|
|
1281
|
+
if (first === void 0 || last === void 0) {
|
|
1282
|
+
boundsError(offset, this.length - 8);
|
|
1283
|
+
}
|
|
1284
|
+
const val = (first << 24) + // Overflow
|
|
1285
|
+
this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1286
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
|
|
1287
|
+
});
|
|
1288
|
+
Buffer5.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1289
|
+
offset = offset >>> 0;
|
|
1290
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1291
|
+
return ieee754.read(this, offset, true, 23, 4);
|
|
1292
|
+
};
|
|
1293
|
+
Buffer5.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1294
|
+
offset = offset >>> 0;
|
|
1295
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1296
|
+
return ieee754.read(this, offset, false, 23, 4);
|
|
1297
|
+
};
|
|
1298
|
+
Buffer5.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1299
|
+
offset = offset >>> 0;
|
|
1300
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1301
|
+
return ieee754.read(this, offset, true, 52, 8);
|
|
1302
|
+
};
|
|
1303
|
+
Buffer5.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1304
|
+
offset = offset >>> 0;
|
|
1305
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1306
|
+
return ieee754.read(this, offset, false, 52, 8);
|
|
1307
|
+
};
|
|
1308
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
1309
|
+
if (!Buffer5.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1310
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
|
|
1311
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1312
|
+
}
|
|
1313
|
+
Buffer5.prototype.writeUintLE = Buffer5.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1314
|
+
value = +value;
|
|
1315
|
+
offset = offset >>> 0;
|
|
1316
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1317
|
+
if (!noAssert) {
|
|
1318
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1319
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1320
|
+
}
|
|
1321
|
+
let mul = 1;
|
|
1322
|
+
let i = 0;
|
|
1323
|
+
this[offset] = value & 255;
|
|
1324
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1325
|
+
this[offset + i] = value / mul & 255;
|
|
1326
|
+
}
|
|
1327
|
+
return offset + byteLength2;
|
|
1328
|
+
};
|
|
1329
|
+
Buffer5.prototype.writeUintBE = Buffer5.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1330
|
+
value = +value;
|
|
1331
|
+
offset = offset >>> 0;
|
|
1332
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1333
|
+
if (!noAssert) {
|
|
1334
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1335
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1336
|
+
}
|
|
1337
|
+
let i = byteLength2 - 1;
|
|
1338
|
+
let mul = 1;
|
|
1339
|
+
this[offset + i] = value & 255;
|
|
1340
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1341
|
+
this[offset + i] = value / mul & 255;
|
|
1342
|
+
}
|
|
1343
|
+
return offset + byteLength2;
|
|
1344
|
+
};
|
|
1345
|
+
Buffer5.prototype.writeUint8 = Buffer5.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1346
|
+
value = +value;
|
|
1347
|
+
offset = offset >>> 0;
|
|
1348
|
+
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
1349
|
+
this[offset] = value & 255;
|
|
1350
|
+
return offset + 1;
|
|
1351
|
+
};
|
|
1352
|
+
Buffer5.prototype.writeUint16LE = Buffer5.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1353
|
+
value = +value;
|
|
1354
|
+
offset = offset >>> 0;
|
|
1355
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1356
|
+
this[offset] = value & 255;
|
|
1357
|
+
this[offset + 1] = value >>> 8;
|
|
1358
|
+
return offset + 2;
|
|
1359
|
+
};
|
|
1360
|
+
Buffer5.prototype.writeUint16BE = Buffer5.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1361
|
+
value = +value;
|
|
1362
|
+
offset = offset >>> 0;
|
|
1363
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1364
|
+
this[offset] = value >>> 8;
|
|
1365
|
+
this[offset + 1] = value & 255;
|
|
1366
|
+
return offset + 2;
|
|
1367
|
+
};
|
|
1368
|
+
Buffer5.prototype.writeUint32LE = Buffer5.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1369
|
+
value = +value;
|
|
1370
|
+
offset = offset >>> 0;
|
|
1371
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1372
|
+
this[offset + 3] = value >>> 24;
|
|
1373
|
+
this[offset + 2] = value >>> 16;
|
|
1374
|
+
this[offset + 1] = value >>> 8;
|
|
1375
|
+
this[offset] = value & 255;
|
|
1376
|
+
return offset + 4;
|
|
1377
|
+
};
|
|
1378
|
+
Buffer5.prototype.writeUint32BE = Buffer5.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1379
|
+
value = +value;
|
|
1380
|
+
offset = offset >>> 0;
|
|
1381
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1382
|
+
this[offset] = value >>> 24;
|
|
1383
|
+
this[offset + 1] = value >>> 16;
|
|
1384
|
+
this[offset + 2] = value >>> 8;
|
|
1385
|
+
this[offset + 3] = value & 255;
|
|
1386
|
+
return offset + 4;
|
|
1387
|
+
};
|
|
1388
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
1389
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1390
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1391
|
+
buf[offset++] = lo;
|
|
1392
|
+
lo = lo >> 8;
|
|
1393
|
+
buf[offset++] = lo;
|
|
1394
|
+
lo = lo >> 8;
|
|
1395
|
+
buf[offset++] = lo;
|
|
1396
|
+
lo = lo >> 8;
|
|
1397
|
+
buf[offset++] = lo;
|
|
1398
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1399
|
+
buf[offset++] = hi;
|
|
1400
|
+
hi = hi >> 8;
|
|
1401
|
+
buf[offset++] = hi;
|
|
1402
|
+
hi = hi >> 8;
|
|
1403
|
+
buf[offset++] = hi;
|
|
1404
|
+
hi = hi >> 8;
|
|
1405
|
+
buf[offset++] = hi;
|
|
1406
|
+
return offset;
|
|
1407
|
+
}
|
|
1408
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
1409
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1410
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1411
|
+
buf[offset + 7] = lo;
|
|
1412
|
+
lo = lo >> 8;
|
|
1413
|
+
buf[offset + 6] = lo;
|
|
1414
|
+
lo = lo >> 8;
|
|
1415
|
+
buf[offset + 5] = lo;
|
|
1416
|
+
lo = lo >> 8;
|
|
1417
|
+
buf[offset + 4] = lo;
|
|
1418
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1419
|
+
buf[offset + 3] = hi;
|
|
1420
|
+
hi = hi >> 8;
|
|
1421
|
+
buf[offset + 2] = hi;
|
|
1422
|
+
hi = hi >> 8;
|
|
1423
|
+
buf[offset + 1] = hi;
|
|
1424
|
+
hi = hi >> 8;
|
|
1425
|
+
buf[offset] = hi;
|
|
1426
|
+
return offset + 8;
|
|
1427
|
+
}
|
|
1428
|
+
Buffer5.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1429
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1430
|
+
});
|
|
1431
|
+
Buffer5.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1432
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1433
|
+
});
|
|
1434
|
+
Buffer5.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1435
|
+
value = +value;
|
|
1436
|
+
offset = offset >>> 0;
|
|
1437
|
+
if (!noAssert) {
|
|
1438
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1439
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1440
|
+
}
|
|
1441
|
+
let i = 0;
|
|
1442
|
+
let mul = 1;
|
|
1443
|
+
let sub = 0;
|
|
1444
|
+
this[offset] = value & 255;
|
|
1445
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1446
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1447
|
+
sub = 1;
|
|
1448
|
+
}
|
|
1449
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1450
|
+
}
|
|
1451
|
+
return offset + byteLength2;
|
|
1452
|
+
};
|
|
1453
|
+
Buffer5.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1454
|
+
value = +value;
|
|
1455
|
+
offset = offset >>> 0;
|
|
1456
|
+
if (!noAssert) {
|
|
1457
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1458
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1459
|
+
}
|
|
1460
|
+
let i = byteLength2 - 1;
|
|
1461
|
+
let mul = 1;
|
|
1462
|
+
let sub = 0;
|
|
1463
|
+
this[offset + i] = value & 255;
|
|
1464
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1465
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1466
|
+
sub = 1;
|
|
1467
|
+
}
|
|
1468
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1469
|
+
}
|
|
1470
|
+
return offset + byteLength2;
|
|
1471
|
+
};
|
|
1472
|
+
Buffer5.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1473
|
+
value = +value;
|
|
1474
|
+
offset = offset >>> 0;
|
|
1475
|
+
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1476
|
+
if (value < 0) value = 255 + value + 1;
|
|
1477
|
+
this[offset] = value & 255;
|
|
1478
|
+
return offset + 1;
|
|
1479
|
+
};
|
|
1480
|
+
Buffer5.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1481
|
+
value = +value;
|
|
1482
|
+
offset = offset >>> 0;
|
|
1483
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1484
|
+
this[offset] = value & 255;
|
|
1485
|
+
this[offset + 1] = value >>> 8;
|
|
1486
|
+
return offset + 2;
|
|
1487
|
+
};
|
|
1488
|
+
Buffer5.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1489
|
+
value = +value;
|
|
1490
|
+
offset = offset >>> 0;
|
|
1491
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1492
|
+
this[offset] = value >>> 8;
|
|
1493
|
+
this[offset + 1] = value & 255;
|
|
1494
|
+
return offset + 2;
|
|
1495
|
+
};
|
|
1496
|
+
Buffer5.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1497
|
+
value = +value;
|
|
1498
|
+
offset = offset >>> 0;
|
|
1499
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1500
|
+
this[offset] = value & 255;
|
|
1501
|
+
this[offset + 1] = value >>> 8;
|
|
1502
|
+
this[offset + 2] = value >>> 16;
|
|
1503
|
+
this[offset + 3] = value >>> 24;
|
|
1504
|
+
return offset + 4;
|
|
1505
|
+
};
|
|
1506
|
+
Buffer5.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1507
|
+
value = +value;
|
|
1508
|
+
offset = offset >>> 0;
|
|
1509
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1510
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
1511
|
+
this[offset] = value >>> 24;
|
|
1512
|
+
this[offset + 1] = value >>> 16;
|
|
1513
|
+
this[offset + 2] = value >>> 8;
|
|
1514
|
+
this[offset + 3] = value & 255;
|
|
1515
|
+
return offset + 4;
|
|
1516
|
+
};
|
|
1517
|
+
Buffer5.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1518
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1519
|
+
});
|
|
1520
|
+
Buffer5.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1521
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1522
|
+
});
|
|
1523
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1524
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1525
|
+
if (offset < 0) throw new RangeError("Index out of range");
|
|
1526
|
+
}
|
|
1527
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1528
|
+
value = +value;
|
|
1529
|
+
offset = offset >>> 0;
|
|
1530
|
+
if (!noAssert) {
|
|
1531
|
+
checkIEEE754(buf, value, offset, 4, 34028234663852886e22, -34028234663852886e22);
|
|
1532
|
+
}
|
|
1533
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1534
|
+
return offset + 4;
|
|
1535
|
+
}
|
|
1536
|
+
Buffer5.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1537
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1538
|
+
};
|
|
1539
|
+
Buffer5.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1540
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1541
|
+
};
|
|
1542
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1543
|
+
value = +value;
|
|
1544
|
+
offset = offset >>> 0;
|
|
1545
|
+
if (!noAssert) {
|
|
1546
|
+
checkIEEE754(buf, value, offset, 8, 17976931348623157e292, -17976931348623157e292);
|
|
1547
|
+
}
|
|
1548
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1549
|
+
return offset + 8;
|
|
1550
|
+
}
|
|
1551
|
+
Buffer5.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1552
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1553
|
+
};
|
|
1554
|
+
Buffer5.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1555
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1556
|
+
};
|
|
1557
|
+
Buffer5.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1558
|
+
if (!Buffer5.isBuffer(target)) throw new TypeError("argument should be a Buffer");
|
|
1559
|
+
if (!start) start = 0;
|
|
1560
|
+
if (!end && end !== 0) end = this.length;
|
|
1561
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1562
|
+
if (!targetStart) targetStart = 0;
|
|
1563
|
+
if (end > 0 && end < start) end = start;
|
|
1564
|
+
if (end === start) return 0;
|
|
1565
|
+
if (target.length === 0 || this.length === 0) return 0;
|
|
1566
|
+
if (targetStart < 0) {
|
|
1567
|
+
throw new RangeError("targetStart out of bounds");
|
|
1568
|
+
}
|
|
1569
|
+
if (start < 0 || start >= this.length) throw new RangeError("Index out of range");
|
|
1570
|
+
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1571
|
+
if (end > this.length) end = this.length;
|
|
1572
|
+
if (target.length - targetStart < end - start) {
|
|
1573
|
+
end = target.length - targetStart + start;
|
|
1574
|
+
}
|
|
1575
|
+
const len = end - start;
|
|
1576
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1577
|
+
this.copyWithin(targetStart, start, end);
|
|
1578
|
+
} else {
|
|
1579
|
+
Uint8Array.prototype.set.call(
|
|
1580
|
+
target,
|
|
1581
|
+
this.subarray(start, end),
|
|
1582
|
+
targetStart
|
|
1583
|
+
);
|
|
1584
|
+
}
|
|
1585
|
+
return len;
|
|
1586
|
+
};
|
|
1587
|
+
Buffer5.prototype.fill = function fill(val, start, end, encoding) {
|
|
1588
|
+
if (typeof val === "string") {
|
|
1589
|
+
if (typeof start === "string") {
|
|
1590
|
+
encoding = start;
|
|
1591
|
+
start = 0;
|
|
1592
|
+
end = this.length;
|
|
1593
|
+
} else if (typeof end === "string") {
|
|
1594
|
+
encoding = end;
|
|
1595
|
+
end = this.length;
|
|
1596
|
+
}
|
|
1597
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1598
|
+
throw new TypeError("encoding must be a string");
|
|
1599
|
+
}
|
|
1600
|
+
if (typeof encoding === "string" && !Buffer5.isEncoding(encoding)) {
|
|
1601
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
1602
|
+
}
|
|
1603
|
+
if (val.length === 1) {
|
|
1604
|
+
const code = val.charCodeAt(0);
|
|
1605
|
+
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1606
|
+
val = code;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
} else if (typeof val === "number") {
|
|
1610
|
+
val = val & 255;
|
|
1611
|
+
} else if (typeof val === "boolean") {
|
|
1612
|
+
val = Number(val);
|
|
1613
|
+
}
|
|
1614
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1615
|
+
throw new RangeError("Out of range index");
|
|
1616
|
+
}
|
|
1617
|
+
if (end <= start) {
|
|
1618
|
+
return this;
|
|
1619
|
+
}
|
|
1620
|
+
start = start >>> 0;
|
|
1621
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1622
|
+
if (!val) val = 0;
|
|
1623
|
+
let i;
|
|
1624
|
+
if (typeof val === "number") {
|
|
1625
|
+
for (i = start; i < end; ++i) {
|
|
1626
|
+
this[i] = val;
|
|
1627
|
+
}
|
|
1628
|
+
} else {
|
|
1629
|
+
const bytes = Buffer5.isBuffer(val) ? val : Buffer5.from(val, encoding);
|
|
1630
|
+
const len = bytes.length;
|
|
1631
|
+
if (len === 0) {
|
|
1632
|
+
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1633
|
+
}
|
|
1634
|
+
for (i = 0; i < end - start; ++i) {
|
|
1635
|
+
this[i + start] = bytes[i % len];
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return this;
|
|
1639
|
+
};
|
|
1640
|
+
var errors = {};
|
|
1641
|
+
function E(sym, getMessage, Base) {
|
|
1642
|
+
errors[sym] = class NodeError extends Base {
|
|
1643
|
+
constructor() {
|
|
1644
|
+
super();
|
|
1645
|
+
Object.defineProperty(this, "message", {
|
|
1646
|
+
value: getMessage.apply(this, arguments),
|
|
1647
|
+
writable: true,
|
|
1648
|
+
configurable: true
|
|
1649
|
+
});
|
|
1650
|
+
this.name = `${this.name} [${sym}]`;
|
|
1651
|
+
this.stack;
|
|
1652
|
+
delete this.name;
|
|
1653
|
+
}
|
|
1654
|
+
get code() {
|
|
1655
|
+
return sym;
|
|
1656
|
+
}
|
|
1657
|
+
set code(value) {
|
|
1658
|
+
Object.defineProperty(this, "code", {
|
|
1659
|
+
configurable: true,
|
|
1660
|
+
enumerable: true,
|
|
1661
|
+
value,
|
|
1662
|
+
writable: true
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
toString() {
|
|
1666
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
E(
|
|
1671
|
+
"ERR_BUFFER_OUT_OF_BOUNDS",
|
|
1672
|
+
function(name) {
|
|
1673
|
+
if (name) {
|
|
1674
|
+
return `${name} is outside of buffer bounds`;
|
|
1675
|
+
}
|
|
1676
|
+
return "Attempt to access memory outside buffer bounds";
|
|
1677
|
+
},
|
|
1678
|
+
RangeError
|
|
1679
|
+
);
|
|
1680
|
+
E(
|
|
1681
|
+
"ERR_INVALID_ARG_TYPE",
|
|
1682
|
+
function(name, actual) {
|
|
1683
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1684
|
+
},
|
|
1685
|
+
TypeError
|
|
1686
|
+
);
|
|
1687
|
+
E(
|
|
1688
|
+
"ERR_OUT_OF_RANGE",
|
|
1689
|
+
function(str, range, input) {
|
|
1690
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
1691
|
+
let received = input;
|
|
1692
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1693
|
+
received = addNumericalSeparator(String(input));
|
|
1694
|
+
} else if (typeof input === "bigint") {
|
|
1695
|
+
received = String(input);
|
|
1696
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1697
|
+
received = addNumericalSeparator(received);
|
|
1698
|
+
}
|
|
1699
|
+
received += "n";
|
|
1700
|
+
}
|
|
1701
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1702
|
+
return msg;
|
|
1703
|
+
},
|
|
1704
|
+
RangeError
|
|
1705
|
+
);
|
|
1706
|
+
function addNumericalSeparator(val) {
|
|
1707
|
+
let res = "";
|
|
1708
|
+
let i = val.length;
|
|
1709
|
+
const start = val[0] === "-" ? 1 : 0;
|
|
1710
|
+
for (; i >= start + 4; i -= 3) {
|
|
1711
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1712
|
+
}
|
|
1713
|
+
return `${val.slice(0, i)}${res}`;
|
|
1714
|
+
}
|
|
1715
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1716
|
+
validateNumber(offset, "offset");
|
|
1717
|
+
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1718
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1722
|
+
if (value > max || value < min) {
|
|
1723
|
+
const n = typeof min === "bigint" ? "n" : "";
|
|
1724
|
+
let range;
|
|
1725
|
+
if (byteLength2 > 3) {
|
|
1726
|
+
if (min === 0 || min === BigInt(0)) {
|
|
1727
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1728
|
+
} else {
|
|
1729
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1730
|
+
}
|
|
1731
|
+
} else {
|
|
1732
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1733
|
+
}
|
|
1734
|
+
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1735
|
+
}
|
|
1736
|
+
checkBounds(buf, offset, byteLength2);
|
|
1737
|
+
}
|
|
1738
|
+
function validateNumber(value, name) {
|
|
1739
|
+
if (typeof value !== "number") {
|
|
1740
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
function boundsError(value, length, type) {
|
|
1744
|
+
if (Math.floor(value) !== value) {
|
|
1745
|
+
validateNumber(value, type);
|
|
1746
|
+
throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
1747
|
+
}
|
|
1748
|
+
if (length < 0) {
|
|
1749
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1750
|
+
}
|
|
1751
|
+
throw new errors.ERR_OUT_OF_RANGE(
|
|
1752
|
+
type || "offset",
|
|
1753
|
+
`>= ${type ? 1 : 0} and <= ${length}`,
|
|
1754
|
+
value
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1758
|
+
function base64clean(str) {
|
|
1759
|
+
str = str.split("=")[0];
|
|
1760
|
+
str = str.trim().replace(INVALID_BASE64_RE, "");
|
|
1761
|
+
if (str.length < 2) return "";
|
|
1762
|
+
while (str.length % 4 !== 0) {
|
|
1763
|
+
str = str + "=";
|
|
1764
|
+
}
|
|
1765
|
+
return str;
|
|
1766
|
+
}
|
|
1767
|
+
function utf8ToBytes(string, units) {
|
|
1768
|
+
units = units || Infinity;
|
|
1769
|
+
let codePoint;
|
|
1770
|
+
const length = string.length;
|
|
1771
|
+
let leadSurrogate = null;
|
|
1772
|
+
const bytes = [];
|
|
1773
|
+
for (let i = 0; i < length; ++i) {
|
|
1774
|
+
codePoint = string.charCodeAt(i);
|
|
1775
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1776
|
+
if (!leadSurrogate) {
|
|
1777
|
+
if (codePoint > 56319) {
|
|
1778
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1779
|
+
continue;
|
|
1780
|
+
} else if (i + 1 === length) {
|
|
1781
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
leadSurrogate = codePoint;
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1787
|
+
if (codePoint < 56320) {
|
|
1788
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1789
|
+
leadSurrogate = codePoint;
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1793
|
+
} else if (leadSurrogate) {
|
|
1794
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1795
|
+
}
|
|
1796
|
+
leadSurrogate = null;
|
|
1797
|
+
if (codePoint < 128) {
|
|
1798
|
+
if ((units -= 1) < 0) break;
|
|
1799
|
+
bytes.push(codePoint);
|
|
1800
|
+
} else if (codePoint < 2048) {
|
|
1801
|
+
if ((units -= 2) < 0) break;
|
|
1802
|
+
bytes.push(
|
|
1803
|
+
codePoint >> 6 | 192,
|
|
1804
|
+
codePoint & 63 | 128
|
|
1805
|
+
);
|
|
1806
|
+
} else if (codePoint < 65536) {
|
|
1807
|
+
if ((units -= 3) < 0) break;
|
|
1808
|
+
bytes.push(
|
|
1809
|
+
codePoint >> 12 | 224,
|
|
1810
|
+
codePoint >> 6 & 63 | 128,
|
|
1811
|
+
codePoint & 63 | 128
|
|
1812
|
+
);
|
|
1813
|
+
} else if (codePoint < 1114112) {
|
|
1814
|
+
if ((units -= 4) < 0) break;
|
|
1815
|
+
bytes.push(
|
|
1816
|
+
codePoint >> 18 | 240,
|
|
1817
|
+
codePoint >> 12 & 63 | 128,
|
|
1818
|
+
codePoint >> 6 & 63 | 128,
|
|
1819
|
+
codePoint & 63 | 128
|
|
1820
|
+
);
|
|
1821
|
+
} else {
|
|
1822
|
+
throw new Error("Invalid code point");
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
return bytes;
|
|
1826
|
+
}
|
|
1827
|
+
function asciiToBytes(str) {
|
|
1828
|
+
const byteArray = [];
|
|
1829
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1830
|
+
byteArray.push(str.charCodeAt(i) & 255);
|
|
1831
|
+
}
|
|
1832
|
+
return byteArray;
|
|
1833
|
+
}
|
|
1834
|
+
function utf16leToBytes(str, units) {
|
|
1835
|
+
let c, hi, lo;
|
|
1836
|
+
const byteArray = [];
|
|
1837
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1838
|
+
if ((units -= 2) < 0) break;
|
|
1839
|
+
c = str.charCodeAt(i);
|
|
1840
|
+
hi = c >> 8;
|
|
1841
|
+
lo = c % 256;
|
|
1842
|
+
byteArray.push(lo);
|
|
1843
|
+
byteArray.push(hi);
|
|
1844
|
+
}
|
|
1845
|
+
return byteArray;
|
|
1846
|
+
}
|
|
1847
|
+
function base64ToBytes(str) {
|
|
1848
|
+
return base64.toByteArray(base64clean(str));
|
|
1849
|
+
}
|
|
1850
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1851
|
+
let i;
|
|
1852
|
+
for (i = 0; i < length; ++i) {
|
|
1853
|
+
if (i + offset >= dst.length || i >= src.length) break;
|
|
1854
|
+
dst[i + offset] = src[i];
|
|
1855
|
+
}
|
|
1856
|
+
return i;
|
|
1857
|
+
}
|
|
1858
|
+
function isInstance(obj, type) {
|
|
1859
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1860
|
+
}
|
|
1861
|
+
function numberIsNaN(obj) {
|
|
1862
|
+
return obj !== obj;
|
|
1863
|
+
}
|
|
1864
|
+
var hexSliceLookupTable = (function() {
|
|
1865
|
+
const alphabet = "0123456789abcdef";
|
|
1866
|
+
const table = new Array(256);
|
|
1867
|
+
for (let i = 0; i < 16; ++i) {
|
|
1868
|
+
const i16 = i * 16;
|
|
1869
|
+
for (let j = 0; j < 16; ++j) {
|
|
1870
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
return table;
|
|
1874
|
+
})();
|
|
1875
|
+
function defineBigIntMethod(fn) {
|
|
1876
|
+
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1877
|
+
}
|
|
1878
|
+
function BufferBigIntNotDefined() {
|
|
1879
|
+
throw new Error("BigInt not supported");
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
|
|
1884
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/kv/namespace.worker.ts
|
|
1885
|
+
init_workerd_globals();
|
|
1886
|
+
init_workerd_performance();
|
|
1887
|
+
|
|
1888
|
+
// src/miniflare-compat/shims/assert.ts
|
|
1889
|
+
init_workerd_globals();
|
|
1890
|
+
init_workerd_performance();
|
|
1891
|
+
var AssertionError = class extends Error {
|
|
1892
|
+
constructor(message) {
|
|
1893
|
+
super(message ?? "Assertion failed");
|
|
1894
|
+
this.name = "AssertionError";
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
function assert(value, message) {
|
|
1898
|
+
if (!value) throw message instanceof Error ? message : new AssertionError(message);
|
|
1899
|
+
}
|
|
1900
|
+
assert.ok = assert;
|
|
1901
|
+
assert.strictEqual = (a, b, message) => {
|
|
1902
|
+
if (!Object.is(a, b))
|
|
1903
|
+
throw new AssertionError(message ?? `Expected ${String(a)} to be ${String(b)}`);
|
|
1904
|
+
};
|
|
1905
|
+
assert.fail = (message) => {
|
|
1906
|
+
throw new AssertionError(message);
|
|
1907
|
+
};
|
|
1908
|
+
assert.AssertionError = AssertionError;
|
|
1909
|
+
var assert_default = assert;
|
|
1910
|
+
var strictEqual = assert.strictEqual;
|
|
1911
|
+
|
|
1912
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/index.worker.ts
|
|
1913
|
+
init_workerd_globals();
|
|
1914
|
+
init_workerd_performance();
|
|
1915
|
+
|
|
1916
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/blob.worker.ts
|
|
1917
|
+
init_workerd_globals();
|
|
1918
|
+
init_workerd_performance();
|
|
1919
|
+
var import_node_buffer2 = __toESM(require_buffer());
|
|
1920
|
+
|
|
1921
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/data.ts
|
|
1922
|
+
init_workerd_globals();
|
|
1923
|
+
init_workerd_performance();
|
|
1924
|
+
var import_node_buffer = __toESM(require_buffer());
|
|
1925
|
+
function base64Encode(value) {
|
|
1926
|
+
return import_node_buffer.Buffer.from(value, "utf8").toString("base64");
|
|
1927
|
+
}
|
|
1928
|
+
function base64Decode(encoded) {
|
|
1929
|
+
return import_node_buffer.Buffer.from(encoded, "base64").toString("utf8");
|
|
1930
|
+
}
|
|
1931
|
+
/*! Path sanitisation regexps adapted from node-sanitize-filename:
|
|
1932
|
+
* https://github.com/parshap/node-sanitize-filename/blob/209c39b914c8eb48ee27bcbde64b2c7822fdf3de/index.js#L4-L37
|
|
1933
|
+
*
|
|
1934
|
+
* Licensed under the ISC license:
|
|
1935
|
+
*
|
|
1936
|
+
* Copyright Parsha Pourkhomami <parshap@gmail.com>
|
|
1937
|
+
*
|
|
1938
|
+
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the
|
|
1939
|
+
* above copyright notice and this permission notice appear in all copies.
|
|
1940
|
+
*
|
|
1941
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
1942
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
|
|
1943
|
+
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
1944
|
+
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
1945
|
+
*/
|
|
1946
|
+
var dotRegexp = /(^|\/|\\)(\.+)(\/|\\|$)/g;
|
|
1947
|
+
var illegalRegexp = /[?<>*"'^/\\:|\x00-\x1f\x80-\x9f]/g;
|
|
1948
|
+
var windowsReservedRegexp = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
|
|
1949
|
+
var leadingRegexp = /^[ /\\]+/;
|
|
1950
|
+
var trailingRegexp = /[ /\\]+$/;
|
|
1951
|
+
function dotReplacement(match, g1, g2, g3) {
|
|
1952
|
+
return `${g1}${"".padStart(g2.length, "_")}${g3}`;
|
|
1953
|
+
}
|
|
1954
|
+
function underscoreReplacement(match) {
|
|
1955
|
+
return "".padStart(match.length, "_");
|
|
1956
|
+
}
|
|
1957
|
+
function sanitisePath(unsafe) {
|
|
1958
|
+
return unsafe.replace(dotRegexp, dotReplacement).replace(dotRegexp, dotReplacement).replace(illegalRegexp, "_").replace(windowsReservedRegexp, "_").replace(leadingRegexp, underscoreReplacement).replace(trailingRegexp, underscoreReplacement).substring(0, 255);
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/blob.worker.ts
|
|
1962
|
+
var ENCODER = new TextEncoder();
|
|
1963
|
+
function rangeHeaders(range) {
|
|
1964
|
+
return { Range: `bytes=${range.start}-${range.end}` };
|
|
1965
|
+
}
|
|
1966
|
+
function assertFullRangeRequest(range, contentLength) {
|
|
1967
|
+
assert_default(
|
|
1968
|
+
range.start === 0 && range.end === contentLength - 1,
|
|
1969
|
+
"Received full content, but requested partial content"
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
async function fetchSingleRange(fetcher, url, range) {
|
|
1973
|
+
const headers = range === void 0 ? {} : rangeHeaders(range);
|
|
1974
|
+
const res = await fetcher.fetch(url, { headers });
|
|
1975
|
+
if (res.status === 404) {
|
|
1976
|
+
return null;
|
|
1977
|
+
}
|
|
1978
|
+
assert_default(res.ok && res.body !== null);
|
|
1979
|
+
if (range !== void 0 && res.status !== 206) {
|
|
1980
|
+
const contentLength = parseInt(res.headers.get("Content-Length") ?? "NaN");
|
|
1981
|
+
assert_default(!Number.isNaN(contentLength));
|
|
1982
|
+
assertFullRangeRequest(range, contentLength);
|
|
1983
|
+
}
|
|
1984
|
+
return res.body;
|
|
1985
|
+
}
|
|
1986
|
+
async function writeMultipleRanges(fetcher, url, ranges, boundary, writable, contentLength, contentType) {
|
|
1987
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
1988
|
+
const range = ranges[i];
|
|
1989
|
+
const writer2 = writable.getWriter();
|
|
1990
|
+
if (i > 0) {
|
|
1991
|
+
await writer2.write(ENCODER.encode("\r\n"));
|
|
1992
|
+
}
|
|
1993
|
+
await writer2.write(ENCODER.encode(`--${boundary}\r
|
|
1994
|
+
`));
|
|
1995
|
+
if (contentType !== void 0) {
|
|
1996
|
+
await writer2.write(ENCODER.encode(`Content-Type: ${contentType}\r
|
|
1997
|
+
`));
|
|
1998
|
+
}
|
|
1999
|
+
const start = range.start;
|
|
2000
|
+
const end = Math.min(range.end, contentLength - 1);
|
|
2001
|
+
await writer2.write(
|
|
2002
|
+
ENCODER.encode(
|
|
2003
|
+
`Content-Range: bytes ${start}-${end}/${contentLength}\r
|
|
2004
|
+
\r
|
|
2005
|
+
`
|
|
2006
|
+
)
|
|
2007
|
+
);
|
|
2008
|
+
writer2.releaseLock();
|
|
2009
|
+
const res = await fetcher.fetch(url, { headers: rangeHeaders(range) });
|
|
2010
|
+
assert_default(
|
|
2011
|
+
res.ok && res.body !== null,
|
|
2012
|
+
`Failed to fetch ${url}[${range.start},${range.end}], received ${res.status} ${res.statusText}`
|
|
2013
|
+
);
|
|
2014
|
+
if (res.status !== 206) {
|
|
2015
|
+
assertFullRangeRequest(range, contentLength);
|
|
2016
|
+
}
|
|
2017
|
+
await res.body.pipeTo(writable, { preventClose: true });
|
|
2018
|
+
}
|
|
2019
|
+
const writer = writable.getWriter();
|
|
2020
|
+
if (ranges.length > 0) {
|
|
2021
|
+
await writer.write(ENCODER.encode("\r\n"));
|
|
2022
|
+
}
|
|
2023
|
+
await writer.write(ENCODER.encode(`--${boundary}--`));
|
|
2024
|
+
await writer.close();
|
|
2025
|
+
}
|
|
2026
|
+
async function fetchMultipleRanges(fetcher, url, ranges, opts) {
|
|
2027
|
+
const res = await fetcher.fetch(url, { method: "HEAD" });
|
|
2028
|
+
if (res.status === 404) {
|
|
2029
|
+
return null;
|
|
2030
|
+
}
|
|
2031
|
+
assert_default(res.ok);
|
|
2032
|
+
const contentLength = parseInt(res.headers.get("Content-Length") ?? "NaN");
|
|
2033
|
+
assert_default(!Number.isNaN(contentLength));
|
|
2034
|
+
const boundary = `miniflare-boundary-${crypto.randomUUID()}`;
|
|
2035
|
+
const multipartContentType = `multipart/byteranges; boundary=${boundary}`;
|
|
2036
|
+
const { readable, writable } = new IdentityTransformStream();
|
|
2037
|
+
void writeMultipleRanges(
|
|
2038
|
+
fetcher,
|
|
2039
|
+
url,
|
|
2040
|
+
ranges,
|
|
2041
|
+
boundary,
|
|
2042
|
+
writable,
|
|
2043
|
+
contentLength,
|
|
2044
|
+
opts?.contentType
|
|
2045
|
+
).catch((e) => console.error("Error writing multipart stream:", e));
|
|
2046
|
+
return { multipartContentType, body: readable };
|
|
2047
|
+
}
|
|
2048
|
+
async function fetchRange(fetcher, url, range, opts) {
|
|
2049
|
+
if (Array.isArray(range)) {
|
|
2050
|
+
return fetchMultipleRanges(fetcher, url, range, opts);
|
|
2051
|
+
} else {
|
|
2052
|
+
return fetchSingleRange(fetcher, url, range);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
function generateBlobId() {
|
|
2056
|
+
const idBuffer = import_node_buffer2.Buffer.alloc(40);
|
|
2057
|
+
crypto.getRandomValues(
|
|
2058
|
+
new Uint8Array(idBuffer.buffer, idBuffer.byteOffset, 32)
|
|
2059
|
+
);
|
|
2060
|
+
idBuffer.writeBigInt64BE(
|
|
2061
|
+
BigInt(performance.timeOrigin + performance.now()),
|
|
2062
|
+
32
|
|
2063
|
+
);
|
|
2064
|
+
return idBuffer.toString("hex");
|
|
2065
|
+
}
|
|
2066
|
+
var BlobStore = class {
|
|
2067
|
+
// Database for binary large objects. Provides single and multi-ranged
|
|
2068
|
+
// streaming reads and writes.
|
|
2069
|
+
//
|
|
2070
|
+
// Blobs have unguessable identifiers, can be deleted, but are otherwise
|
|
2071
|
+
// immutable. These properties make it possible to perform atomic updates with
|
|
2072
|
+
// the SQLite metadata store. No other operations will be able to interact
|
|
2073
|
+
// with the blob until it's committed to the metadata store, because they
|
|
2074
|
+
// won't be able to guess the ID, and we don't allow listing blobs.
|
|
2075
|
+
//
|
|
2076
|
+
// For example, if we put a blob in the store, then fail to insert the blob ID
|
|
2077
|
+
// into the SQLite database for some reason during a transaction (e.g.
|
|
2078
|
+
// `onlyIf` condition failed), no other operations can read that blob because
|
|
2079
|
+
// the ID is lost (we'll just background-delete the blob in this case).
|
|
2080
|
+
#fetcher;
|
|
2081
|
+
#baseURL;
|
|
2082
|
+
constructor(fetcher, namespace) {
|
|
2083
|
+
namespace = encodeURIComponent(sanitisePath(namespace));
|
|
2084
|
+
this.#fetcher = fetcher;
|
|
2085
|
+
this.#baseURL = `http://placeholder/${namespace}/blobs/`;
|
|
2086
|
+
}
|
|
2087
|
+
idURL(id) {
|
|
2088
|
+
const url = new URL(this.#baseURL + id);
|
|
2089
|
+
return url.toString().startsWith(this.#baseURL) ? url : null;
|
|
2090
|
+
}
|
|
2091
|
+
async get(id, range, opts) {
|
|
2092
|
+
const idURL = this.idURL(id);
|
|
2093
|
+
if (idURL === null) {
|
|
2094
|
+
return null;
|
|
2095
|
+
}
|
|
2096
|
+
return fetchRange(this.#fetcher, idURL, range, opts);
|
|
2097
|
+
}
|
|
2098
|
+
async put(stream) {
|
|
2099
|
+
const id = generateBlobId();
|
|
2100
|
+
const idURL = this.idURL(id);
|
|
2101
|
+
assert_default(idURL !== null);
|
|
2102
|
+
await this.#fetcher.fetch(idURL, {
|
|
2103
|
+
method: "PUT",
|
|
2104
|
+
body: stream
|
|
2105
|
+
});
|
|
2106
|
+
return id;
|
|
2107
|
+
}
|
|
2108
|
+
async delete(id) {
|
|
2109
|
+
const idURL = this.idURL(id);
|
|
2110
|
+
if (idURL === null) {
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
const res = await this.#fetcher.fetch(idURL, { method: "DELETE" });
|
|
2114
|
+
assert_default(res.ok || res.status === 404);
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
|
|
2118
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/constants.ts
|
|
2119
|
+
init_workerd_globals();
|
|
2120
|
+
init_workerd_performance();
|
|
2121
|
+
var SharedHeaders = {
|
|
2122
|
+
LOG_LEVEL: "MF-Log-Level",
|
|
2123
|
+
NAMESPACE: "MF-Namespace"
|
|
2124
|
+
};
|
|
2125
|
+
var SharedBindings = {
|
|
2126
|
+
TEXT_NAMESPACE: "MINIFLARE_NAMESPACE",
|
|
2127
|
+
DURABLE_OBJECT_NAMESPACE_OBJECT: "MINIFLARE_OBJECT",
|
|
2128
|
+
MAYBE_SERVICE_BLOBS: "MINIFLARE_BLOBS",
|
|
2129
|
+
MAYBE_SERVICE_LOOPBACK: "MINIFLARE_LOOPBACK",
|
|
2130
|
+
MAYBE_JSON_ENABLE_CONTROL_ENDPOINTS: "MINIFLARE_ENABLE_CONTROL_ENDPOINTS"
|
|
2131
|
+
};
|
|
2132
|
+
|
|
2133
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/keyvalue.worker.ts
|
|
2134
|
+
init_workerd_globals();
|
|
2135
|
+
init_workerd_performance();
|
|
2136
|
+
|
|
2137
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/sql.worker.ts
|
|
2138
|
+
init_workerd_globals();
|
|
2139
|
+
init_workerd_performance();
|
|
2140
|
+
function isTypedValue(value) {
|
|
2141
|
+
return value === null || typeof value === "string" || typeof value === "number" || value instanceof ArrayBuffer;
|
|
2142
|
+
}
|
|
2143
|
+
function createStatementFactory(sql) {
|
|
2144
|
+
return (query) => {
|
|
2145
|
+
const keyIndices = /* @__PURE__ */ new Map();
|
|
2146
|
+
query = query.replace(/[:@$]([a-z0-9_]+)/gi, (_, name) => {
|
|
2147
|
+
let index = keyIndices.get(name);
|
|
2148
|
+
if (index === void 0) {
|
|
2149
|
+
index = keyIndices.size;
|
|
2150
|
+
keyIndices.set(name, index);
|
|
2151
|
+
}
|
|
2152
|
+
return `?${index + 1}`;
|
|
2153
|
+
});
|
|
2154
|
+
const stmt = sql.prepare(query);
|
|
2155
|
+
return (argsObject) => {
|
|
2156
|
+
const entries = Object.entries(argsObject);
|
|
2157
|
+
assert_default.strictEqual(
|
|
2158
|
+
entries.length,
|
|
2159
|
+
keyIndices.size,
|
|
2160
|
+
"Expected same number of keys in bindings and query"
|
|
2161
|
+
);
|
|
2162
|
+
const argsArray = new Array(entries.length);
|
|
2163
|
+
for (const [key, value] of entries) {
|
|
2164
|
+
const index = keyIndices.get(key);
|
|
2165
|
+
assert_default(index !== void 0, `Unexpected binding key: ${key}`);
|
|
2166
|
+
argsArray[index] = value;
|
|
2167
|
+
}
|
|
2168
|
+
return stmt(...argsArray);
|
|
2169
|
+
};
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
function createTransactionFactory(storage) {
|
|
2173
|
+
return (closure) => (...args) => storage.transactionSync(() => closure(...args));
|
|
2174
|
+
}
|
|
2175
|
+
function createTypedSql(storage) {
|
|
2176
|
+
const sql = storage.sql;
|
|
2177
|
+
sql.stmt = createStatementFactory(sql);
|
|
2178
|
+
sql.txn = createTransactionFactory(storage);
|
|
2179
|
+
return sql;
|
|
2180
|
+
}
|
|
2181
|
+
function get(cursor) {
|
|
2182
|
+
let result;
|
|
2183
|
+
for (const row of cursor) {
|
|
2184
|
+
result ??= row;
|
|
2185
|
+
}
|
|
2186
|
+
return result;
|
|
2187
|
+
}
|
|
2188
|
+
function all(cursor) {
|
|
2189
|
+
return Array.from(cursor);
|
|
2190
|
+
}
|
|
2191
|
+
function drain(cursor) {
|
|
2192
|
+
for (const _ of cursor) {
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/keyvalue.worker.ts
|
|
2197
|
+
var SQL_SCHEMA = `
|
|
2198
|
+
CREATE TABLE IF NOT EXISTS _mf_entries (
|
|
2199
|
+
key TEXT PRIMARY KEY,
|
|
2200
|
+
blob_id TEXT NOT NULL,
|
|
2201
|
+
expiration INTEGER,
|
|
2202
|
+
metadata TEXT
|
|
2203
|
+
);
|
|
2204
|
+
CREATE INDEX IF NOT EXISTS _mf_entries_expiration_idx ON _mf_entries(expiration);
|
|
2205
|
+
`;
|
|
2206
|
+
function sqlStmts(db) {
|
|
2207
|
+
const stmtGetBlobIdByKey = db.stmt(
|
|
2208
|
+
"SELECT blob_id FROM _mf_entries WHERE key = :key"
|
|
2209
|
+
);
|
|
2210
|
+
const stmtPut = db.stmt(
|
|
2211
|
+
`INSERT OR REPLACE INTO _mf_entries (key, blob_id, expiration, metadata)
|
|
2212
|
+
VALUES (:key, :blob_id, :expiration, :metadata)`
|
|
2213
|
+
);
|
|
2214
|
+
return {
|
|
2215
|
+
db,
|
|
2216
|
+
getByKey: db.prepare(
|
|
2217
|
+
"SELECT key, blob_id, expiration, metadata FROM _mf_entries WHERE key = ?1"
|
|
2218
|
+
),
|
|
2219
|
+
put: db.txn((newEntry) => {
|
|
2220
|
+
const key = newEntry.key;
|
|
2221
|
+
const previousEntry = get(stmtGetBlobIdByKey({ key }));
|
|
2222
|
+
stmtPut(newEntry);
|
|
2223
|
+
return previousEntry?.blob_id;
|
|
2224
|
+
}),
|
|
2225
|
+
deleteByKey: db.stmt(
|
|
2226
|
+
"DELETE FROM _mf_entries WHERE key = :key RETURNING blob_id, expiration"
|
|
2227
|
+
),
|
|
2228
|
+
deleteExpired: db.stmt(
|
|
2229
|
+
// `expiration` may be `NULL`, but `NULL < ...` should be falsy
|
|
2230
|
+
"DELETE FROM _mf_entries WHERE expiration < :now RETURNING blob_id"
|
|
2231
|
+
),
|
|
2232
|
+
deleteAll: db.prepare(
|
|
2233
|
+
"DELETE FROM _mf_entries RETURNING blob_id"
|
|
2234
|
+
),
|
|
2235
|
+
list: db.stmt(
|
|
2236
|
+
`SELECT key, expiration, metadata FROM _mf_entries
|
|
2237
|
+
WHERE substr(key, 1, length(:prefix)) = :prefix
|
|
2238
|
+
AND key > :start_after
|
|
2239
|
+
AND (expiration IS NULL OR expiration >= :now)
|
|
2240
|
+
ORDER BY key LIMIT :limit`
|
|
2241
|
+
)
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2244
|
+
function rowEntry(entry) {
|
|
2245
|
+
return {
|
|
2246
|
+
key: entry.key,
|
|
2247
|
+
expiration: entry.expiration ?? void 0,
|
|
2248
|
+
metadata: entry.metadata === null ? void 0 : JSON.parse(entry.metadata)
|
|
2249
|
+
};
|
|
2250
|
+
}
|
|
2251
|
+
var KeyValueStorage = class {
|
|
2252
|
+
#stmts;
|
|
2253
|
+
#blob;
|
|
2254
|
+
#timers;
|
|
2255
|
+
constructor(object) {
|
|
2256
|
+
object.db.exec("PRAGMA case_sensitive_like = TRUE");
|
|
2257
|
+
object.db.exec(SQL_SCHEMA);
|
|
2258
|
+
this.#stmts = sqlStmts(object.db);
|
|
2259
|
+
this.#blob = object.blob;
|
|
2260
|
+
this.#timers = object.timers;
|
|
2261
|
+
}
|
|
2262
|
+
#hasExpired(entry) {
|
|
2263
|
+
return entry.expiration !== null && entry.expiration <= this.#timers.now();
|
|
2264
|
+
}
|
|
2265
|
+
#backgroundDelete(blobId) {
|
|
2266
|
+
this.#timers.queueMicrotask(
|
|
2267
|
+
() => this.#blob.delete(blobId).catch(() => {
|
|
2268
|
+
})
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
async get(key, optsFactory) {
|
|
2272
|
+
const row = get(this.#stmts.getByKey(key));
|
|
2273
|
+
if (row === void 0) {
|
|
2274
|
+
return null;
|
|
2275
|
+
}
|
|
2276
|
+
if (this.#hasExpired(row)) {
|
|
2277
|
+
drain(this.#stmts.deleteByKey({ key }));
|
|
2278
|
+
this.#backgroundDelete(row.blob_id);
|
|
2279
|
+
return null;
|
|
2280
|
+
}
|
|
2281
|
+
const entry = rowEntry(row);
|
|
2282
|
+
const opts = entry.metadata && optsFactory?.(entry.metadata);
|
|
2283
|
+
if (opts?.ranges === void 0 || opts.ranges.length <= 1) {
|
|
2284
|
+
const value = await this.#blob.get(row.blob_id, opts?.ranges?.[0]);
|
|
2285
|
+
if (value === null) {
|
|
2286
|
+
return null;
|
|
2287
|
+
}
|
|
2288
|
+
return { ...entry, value };
|
|
2289
|
+
} else {
|
|
2290
|
+
const value = await this.#blob.get(row.blob_id, opts.ranges, opts);
|
|
2291
|
+
if (value === null) {
|
|
2292
|
+
return null;
|
|
2293
|
+
}
|
|
2294
|
+
return { ...entry, value };
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
async put(entry) {
|
|
2298
|
+
assert_default(entry.key !== "");
|
|
2299
|
+
const blobId = await this.#blob.put(entry.value);
|
|
2300
|
+
if (entry.signal?.aborted) {
|
|
2301
|
+
this.#backgroundDelete(blobId);
|
|
2302
|
+
entry.signal.throwIfAborted();
|
|
2303
|
+
}
|
|
2304
|
+
const maybeOldBlobId = this.#stmts.put({
|
|
2305
|
+
key: entry.key,
|
|
2306
|
+
blob_id: blobId,
|
|
2307
|
+
expiration: entry.expiration ?? null,
|
|
2308
|
+
metadata: entry.metadata === void 0 ? null : JSON.stringify(await entry.metadata)
|
|
2309
|
+
});
|
|
2310
|
+
if (maybeOldBlobId !== void 0) {
|
|
2311
|
+
this.#backgroundDelete(maybeOldBlobId);
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
async delete(key) {
|
|
2315
|
+
const cursor = this.#stmts.deleteByKey({ key });
|
|
2316
|
+
const row = get(cursor);
|
|
2317
|
+
if (row === void 0) {
|
|
2318
|
+
return false;
|
|
2319
|
+
}
|
|
2320
|
+
this.#backgroundDelete(row.blob_id);
|
|
2321
|
+
return !this.#hasExpired(row);
|
|
2322
|
+
}
|
|
2323
|
+
deleteAll() {
|
|
2324
|
+
const rows = all(this.#stmts.deleteAll());
|
|
2325
|
+
for (const { blob_id } of rows) {
|
|
2326
|
+
this.#backgroundDelete(blob_id);
|
|
2327
|
+
}
|
|
2328
|
+
return rows.length;
|
|
2329
|
+
}
|
|
2330
|
+
async list(opts) {
|
|
2331
|
+
const now = this.#timers.now();
|
|
2332
|
+
const prefix = opts.prefix ?? "";
|
|
2333
|
+
const start_after = opts.cursor === void 0 ? "" : base64Decode(opts.cursor);
|
|
2334
|
+
const limit = opts.limit + 1;
|
|
2335
|
+
const rowsCursor = this.#stmts.list({
|
|
2336
|
+
now,
|
|
2337
|
+
prefix,
|
|
2338
|
+
start_after,
|
|
2339
|
+
limit
|
|
2340
|
+
});
|
|
2341
|
+
const rows = Array.from(rowsCursor);
|
|
2342
|
+
const expiredRows = this.#stmts.deleteExpired({ now });
|
|
2343
|
+
for (const row of expiredRows) {
|
|
2344
|
+
this.#backgroundDelete(row.blob_id);
|
|
2345
|
+
}
|
|
2346
|
+
const hasMoreRows = rows.length === opts.limit + 1;
|
|
2347
|
+
rows.splice(opts.limit, 1);
|
|
2348
|
+
const keys = rows.map((row) => rowEntry(row));
|
|
2349
|
+
const nextCursor = hasMoreRows ? base64Encode(rows[opts.limit - 1].key) : void 0;
|
|
2350
|
+
return { keys, cursor: nextCursor };
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
|
|
2354
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/matcher.ts
|
|
2355
|
+
init_workerd_globals();
|
|
2356
|
+
init_workerd_performance();
|
|
2357
|
+
|
|
2358
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/object.worker.ts
|
|
2359
|
+
init_workerd_globals();
|
|
2360
|
+
init_workerd_performance();
|
|
2361
|
+
|
|
2362
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/router.worker.ts
|
|
2363
|
+
init_workerd_globals();
|
|
2364
|
+
init_workerd_performance();
|
|
2365
|
+
var HttpError = class extends Error {
|
|
2366
|
+
constructor(code, message) {
|
|
2367
|
+
super(message);
|
|
2368
|
+
this.code = code;
|
|
2369
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
2370
|
+
this.name = `${new.target.name} [${code}]`;
|
|
2371
|
+
}
|
|
2372
|
+
code;
|
|
2373
|
+
toResponse() {
|
|
2374
|
+
return new Response(this.message, {
|
|
2375
|
+
status: this.code,
|
|
2376
|
+
// Custom statusMessage is required for runtime error messages
|
|
2377
|
+
statusText: this.message.substring(0, 512)
|
|
2378
|
+
});
|
|
2379
|
+
}
|
|
2380
|
+
};
|
|
2381
|
+
var kRoutesTemplate = /* @__PURE__ */ Symbol("kRoutesTemplate");
|
|
2382
|
+
var Router = class {
|
|
2383
|
+
// Routes added by @METHOD decorators
|
|
2384
|
+
#routes;
|
|
2385
|
+
constructor() {
|
|
2386
|
+
this.#routes = new.target.prototype[kRoutesTemplate];
|
|
2387
|
+
}
|
|
2388
|
+
async fetch(req) {
|
|
2389
|
+
const url = new URL(req.url);
|
|
2390
|
+
const methodRoutes = this.#routes?.get(req.method);
|
|
2391
|
+
if (methodRoutes === void 0) {
|
|
2392
|
+
return new Response(null, { status: 405 });
|
|
2393
|
+
}
|
|
2394
|
+
const handlers = this;
|
|
2395
|
+
try {
|
|
2396
|
+
for (const [path, key] of methodRoutes) {
|
|
2397
|
+
const match = path.exec(url.pathname);
|
|
2398
|
+
if (match !== null) {
|
|
2399
|
+
return await handlers[key](req, match.groups, url);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
return new Response(null, { status: 404 });
|
|
2403
|
+
} catch (e) {
|
|
2404
|
+
if (e instanceof HttpError) {
|
|
2405
|
+
return e.toResponse();
|
|
2406
|
+
}
|
|
2407
|
+
throw e;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
};
|
|
2411
|
+
function pathToRegexp(path) {
|
|
2412
|
+
if (path === void 0) {
|
|
2413
|
+
return /^.*$/;
|
|
2414
|
+
}
|
|
2415
|
+
if (!path.endsWith("/")) {
|
|
2416
|
+
path += "/?";
|
|
2417
|
+
}
|
|
2418
|
+
path = path.replace(/\//g, "\\/");
|
|
2419
|
+
path = path.replace(/:(\w+)/g, "(?<$1>[^\\/]+)");
|
|
2420
|
+
return new RegExp(`^${path}$`);
|
|
2421
|
+
}
|
|
2422
|
+
var createRouteDecorator = (method) => (path) => (prototype, key) => {
|
|
2423
|
+
const route = [pathToRegexp(path), key];
|
|
2424
|
+
const routes = prototype[kRoutesTemplate] ??= /* @__PURE__ */ new Map();
|
|
2425
|
+
const methodRoutes = routes.get(method);
|
|
2426
|
+
if (methodRoutes) {
|
|
2427
|
+
methodRoutes.push(route);
|
|
2428
|
+
} else {
|
|
2429
|
+
routes.set(method, [route]);
|
|
2430
|
+
}
|
|
2431
|
+
};
|
|
2432
|
+
var GET = createRouteDecorator("GET");
|
|
2433
|
+
var HEAD = createRouteDecorator("HEAD");
|
|
2434
|
+
var POST = createRouteDecorator("POST");
|
|
2435
|
+
var PUT = createRouteDecorator("PUT");
|
|
2436
|
+
var DELETE = createRouteDecorator("DELETE");
|
|
2437
|
+
var PURGE = createRouteDecorator("PURGE");
|
|
2438
|
+
var PATCH = createRouteDecorator("PATCH");
|
|
2439
|
+
|
|
2440
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/timers.worker.ts
|
|
2441
|
+
init_workerd_globals();
|
|
2442
|
+
init_workerd_performance();
|
|
2443
|
+
var kFakeTimerHandle = /* @__PURE__ */ Symbol("kFakeTimerHandle");
|
|
2444
|
+
var Timers = class {
|
|
2445
|
+
// Fake unix time in milliseconds. If defined, fake timers will be enabled.
|
|
2446
|
+
#fakeTimestamp;
|
|
2447
|
+
#fakeNextTimerHandle = 0;
|
|
2448
|
+
#fakePendingTimeouts = /* @__PURE__ */ new Map();
|
|
2449
|
+
#fakeRunningTasks = /* @__PURE__ */ new Set();
|
|
2450
|
+
// Timers API
|
|
2451
|
+
now = () => this.#fakeTimestamp ?? Date.now();
|
|
2452
|
+
setTimeout(closure, delay, ...args) {
|
|
2453
|
+
if (this.#fakeTimestamp === void 0) {
|
|
2454
|
+
return setTimeout(closure, delay, ...args);
|
|
2455
|
+
}
|
|
2456
|
+
const handle = this.#fakeNextTimerHandle++;
|
|
2457
|
+
const argsClosure = () => closure(...args);
|
|
2458
|
+
if (delay === 0) {
|
|
2459
|
+
this.queueMicrotask(argsClosure);
|
|
2460
|
+
} else {
|
|
2461
|
+
const timeout = {
|
|
2462
|
+
triggerTimestamp: this.#fakeTimestamp + delay,
|
|
2463
|
+
closure: argsClosure
|
|
2464
|
+
};
|
|
2465
|
+
this.#fakePendingTimeouts.set(handle, timeout);
|
|
2466
|
+
}
|
|
2467
|
+
return { [kFakeTimerHandle]: handle };
|
|
2468
|
+
}
|
|
2469
|
+
clearTimeout(handle) {
|
|
2470
|
+
if (typeof handle === "number") {
|
|
2471
|
+
return clearTimeout(handle);
|
|
2472
|
+
} else {
|
|
2473
|
+
this.#fakePendingTimeouts.delete(handle[kFakeTimerHandle]);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
queueMicrotask(closure) {
|
|
2477
|
+
if (this.#fakeTimestamp === void 0) {
|
|
2478
|
+
return queueMicrotask(closure);
|
|
2479
|
+
}
|
|
2480
|
+
const result = closure();
|
|
2481
|
+
if (result instanceof Promise) {
|
|
2482
|
+
this.#fakeRunningTasks.add(result);
|
|
2483
|
+
result.finally(() => this.#fakeRunningTasks.delete(result));
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
// Fake Timers Control API
|
|
2487
|
+
#runPendingTimeouts() {
|
|
2488
|
+
if (this.#fakeTimestamp === void 0) {
|
|
2489
|
+
return;
|
|
2490
|
+
}
|
|
2491
|
+
for (const [handle, timeout] of this.#fakePendingTimeouts) {
|
|
2492
|
+
if (timeout.triggerTimestamp <= this.#fakeTimestamp) {
|
|
2493
|
+
this.#fakePendingTimeouts.delete(handle);
|
|
2494
|
+
this.queueMicrotask(timeout.closure);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
enableFakeTimers(timestamp) {
|
|
2499
|
+
this.#fakeTimestamp = timestamp;
|
|
2500
|
+
this.#runPendingTimeouts();
|
|
2501
|
+
}
|
|
2502
|
+
disableFakeTimers() {
|
|
2503
|
+
this.#fakeTimestamp = void 0;
|
|
2504
|
+
this.#fakePendingTimeouts.clear();
|
|
2505
|
+
}
|
|
2506
|
+
advanceFakeTime(delta) {
|
|
2507
|
+
assert_default(
|
|
2508
|
+
this.#fakeTimestamp !== void 0,
|
|
2509
|
+
"Expected fake timers to be enabled before `advanceFakeTime()` call"
|
|
2510
|
+
);
|
|
2511
|
+
this.#fakeTimestamp += delta;
|
|
2512
|
+
this.#runPendingTimeouts();
|
|
2513
|
+
}
|
|
2514
|
+
async waitForFakeTasks() {
|
|
2515
|
+
while (this.#fakeRunningTasks.size > 0) {
|
|
2516
|
+
await Promise.all(this.#fakeRunningTasks);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
};
|
|
2520
|
+
|
|
2521
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/types.ts
|
|
2522
|
+
init_workerd_globals();
|
|
2523
|
+
init_workerd_performance();
|
|
2524
|
+
function reduceError(e) {
|
|
2525
|
+
return {
|
|
2526
|
+
name: e?.name,
|
|
2527
|
+
message: e?.message ?? String(e),
|
|
2528
|
+
stack: e?.stack,
|
|
2529
|
+
cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
function maybeApply(f, maybeValue) {
|
|
2533
|
+
return maybeValue === void 0 ? void 0 : f(maybeValue);
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/object.worker.ts
|
|
2537
|
+
var MiniflareDurableObject = class extends Router {
|
|
2538
|
+
constructor(state, env) {
|
|
2539
|
+
super();
|
|
2540
|
+
this.state = state;
|
|
2541
|
+
this.env = env;
|
|
2542
|
+
}
|
|
2543
|
+
state;
|
|
2544
|
+
env;
|
|
2545
|
+
timers = new Timers();
|
|
2546
|
+
// If this Durable Object receives a control op, assume it's being tested.
|
|
2547
|
+
// We use this to adjust some limits in tests.
|
|
2548
|
+
beingTested = false;
|
|
2549
|
+
#db;
|
|
2550
|
+
get db() {
|
|
2551
|
+
return this.#db ??= createTypedSql(this.state.storage);
|
|
2552
|
+
}
|
|
2553
|
+
#name;
|
|
2554
|
+
get name() {
|
|
2555
|
+
assert_default(
|
|
2556
|
+
this.#name !== void 0,
|
|
2557
|
+
"Expected `MiniflareDurableObject#fetch()` call before `name` access"
|
|
2558
|
+
);
|
|
2559
|
+
return this.#name;
|
|
2560
|
+
}
|
|
2561
|
+
#blob;
|
|
2562
|
+
get blob() {
|
|
2563
|
+
if (this.#blob !== void 0) {
|
|
2564
|
+
return this.#blob;
|
|
2565
|
+
}
|
|
2566
|
+
const maybeBlobsService = this.env[SharedBindings.MAYBE_SERVICE_BLOBS];
|
|
2567
|
+
assert_default(
|
|
2568
|
+
maybeBlobsService !== void 0,
|
|
2569
|
+
`Expected ${SharedBindings.MAYBE_SERVICE_BLOBS} service binding`
|
|
2570
|
+
);
|
|
2571
|
+
this.#blob = new BlobStore(maybeBlobsService, this.name);
|
|
2572
|
+
return this.#blob;
|
|
2573
|
+
}
|
|
2574
|
+
async logWithLevel(level, message) {
|
|
2575
|
+
await this.env[SharedBindings.MAYBE_SERVICE_LOOPBACK]?.fetch(
|
|
2576
|
+
"http://localhost/core/log",
|
|
2577
|
+
{
|
|
2578
|
+
method: "POST",
|
|
2579
|
+
headers: { [SharedHeaders.LOG_LEVEL]: level.toString() },
|
|
2580
|
+
body: message
|
|
2581
|
+
}
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2584
|
+
async #handleControlOp({
|
|
2585
|
+
name,
|
|
2586
|
+
args
|
|
2587
|
+
}) {
|
|
2588
|
+
this.beingTested = true;
|
|
2589
|
+
if (name === "sqlQuery") {
|
|
2590
|
+
assert_default(args !== void 0);
|
|
2591
|
+
const [query, ...params] = args;
|
|
2592
|
+
assert_default(typeof query === "string");
|
|
2593
|
+
assert_default(params.every(isTypedValue));
|
|
2594
|
+
const results = all(this.db.prepare(query)(...params));
|
|
2595
|
+
return Response.json(results);
|
|
2596
|
+
} else if (name === "getBlob") {
|
|
2597
|
+
assert_default(args !== void 0);
|
|
2598
|
+
const [id] = args;
|
|
2599
|
+
assert_default(typeof id === "string");
|
|
2600
|
+
const stream = await this.blob.get(id);
|
|
2601
|
+
return new Response(stream, { status: stream === null ? 404 : 200 });
|
|
2602
|
+
} else {
|
|
2603
|
+
const func = this.timers[name];
|
|
2604
|
+
assert_default(typeof func === "function");
|
|
2605
|
+
const result = await func.apply(this.timers, args);
|
|
2606
|
+
return Response.json(result ?? null);
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
async fetch(req) {
|
|
2610
|
+
if (this.env[SharedBindings.MAYBE_JSON_ENABLE_CONTROL_ENDPOINTS] === true) {
|
|
2611
|
+
const controlOp = req?.cf?.miniflare?.controlOp;
|
|
2612
|
+
if (controlOp !== void 0) {
|
|
2613
|
+
return this.#handleControlOp(controlOp);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
const name = req.cf?.miniflare?.name;
|
|
2617
|
+
assert_default(name !== void 0, "Expected `cf.miniflare.name`");
|
|
2618
|
+
this.#name = name;
|
|
2619
|
+
try {
|
|
2620
|
+
return await super.fetch(req);
|
|
2621
|
+
} catch (e) {
|
|
2622
|
+
const error = reduceError(e);
|
|
2623
|
+
const fallback = error.stack ?? error.message;
|
|
2624
|
+
const loopbackService = this.env[SharedBindings.MAYBE_SERVICE_LOOPBACK];
|
|
2625
|
+
if (loopbackService !== void 0) {
|
|
2626
|
+
void loopbackService.fetch("http://localhost/core/error", {
|
|
2627
|
+
method: "POST",
|
|
2628
|
+
body: JSON.stringify(error)
|
|
2629
|
+
}).catch(() => {
|
|
2630
|
+
console.error(fallback);
|
|
2631
|
+
});
|
|
2632
|
+
} else {
|
|
2633
|
+
console.error(fallback);
|
|
2634
|
+
}
|
|
2635
|
+
return new Response(fallback, { status: 500 });
|
|
2636
|
+
} finally {
|
|
2637
|
+
if (req.body !== null && !req.bodyUsed) {
|
|
2638
|
+
await req.body.pipeTo(new WritableStream());
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
|
|
2644
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/public-url.ts
|
|
2645
|
+
init_workerd_globals();
|
|
2646
|
+
init_workerd_performance();
|
|
2647
|
+
|
|
2648
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/range.ts
|
|
2649
|
+
init_workerd_globals();
|
|
2650
|
+
init_workerd_performance();
|
|
2651
|
+
|
|
2652
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/shared/sync.ts
|
|
2653
|
+
init_workerd_globals();
|
|
2654
|
+
init_workerd_performance();
|
|
2655
|
+
var DeferredPromise = class extends Promise {
|
|
2656
|
+
resolve;
|
|
2657
|
+
reject;
|
|
2658
|
+
constructor(executor = () => {
|
|
2659
|
+
}) {
|
|
2660
|
+
let promiseResolve = void 0;
|
|
2661
|
+
let promiseReject = void 0;
|
|
2662
|
+
super((resolve, reject) => {
|
|
2663
|
+
promiseResolve = resolve;
|
|
2664
|
+
promiseReject = reject;
|
|
2665
|
+
return executor(resolve, reject);
|
|
2666
|
+
});
|
|
2667
|
+
assert_default(promiseResolve);
|
|
2668
|
+
assert_default(promiseReject);
|
|
2669
|
+
this.resolve = promiseResolve;
|
|
2670
|
+
this.reject = promiseReject;
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
|
|
2674
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/kv/constants.ts
|
|
2675
|
+
init_workerd_globals();
|
|
2676
|
+
init_workerd_performance();
|
|
2677
|
+
var KVLimits = {
|
|
2678
|
+
MIN_CACHE_TTL_SECONDS: 30,
|
|
2679
|
+
MIN_EXPIRATION_TTL_SECONDS: 60,
|
|
2680
|
+
MAX_LIST_KEYS: 1e3,
|
|
2681
|
+
MAX_KEY_SIZE_BYTES: 512,
|
|
2682
|
+
MAX_VALUE_SIZE_BYTES: 25 * 1024 * 1024,
|
|
2683
|
+
MAX_VALUE_SIZE_TEST_BYTES: 1024,
|
|
2684
|
+
MAX_METADATA_SIZE_BYTES: 1024,
|
|
2685
|
+
MAX_BULK_SIZE_BYTES: 25 * 1024 * 1024
|
|
2686
|
+
};
|
|
2687
|
+
var KVParams = {
|
|
2688
|
+
URL_ENCODED: "urlencoded",
|
|
2689
|
+
CACHE_TTL: "cache_ttl",
|
|
2690
|
+
EXPIRATION: "expiration",
|
|
2691
|
+
EXPIRATION_TTL: "expiration_ttl",
|
|
2692
|
+
LIST_LIMIT: "key_count_limit",
|
|
2693
|
+
LIST_PREFIX: "prefix",
|
|
2694
|
+
LIST_CURSOR: "cursor"
|
|
2695
|
+
};
|
|
2696
|
+
var KVHeaders = {
|
|
2697
|
+
EXPIRATION: "CF-Expiration",
|
|
2698
|
+
METADATA: "CF-KV-Metadata"
|
|
2699
|
+
};
|
|
2700
|
+
var MAX_BULK_GET_KEYS = 100;
|
|
2701
|
+
|
|
2702
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/kv/validator.worker.ts
|
|
2703
|
+
init_workerd_globals();
|
|
2704
|
+
init_workerd_performance();
|
|
2705
|
+
var import_node_buffer3 = __toESM(require_buffer());
|
|
2706
|
+
function decodeKey({ key }, query) {
|
|
2707
|
+
if (query.get(KVParams.URL_ENCODED)?.toLowerCase() !== "true") {
|
|
2708
|
+
return key;
|
|
2709
|
+
}
|
|
2710
|
+
try {
|
|
2711
|
+
return decodeURIComponent(key);
|
|
2712
|
+
} catch (e) {
|
|
2713
|
+
if (e instanceof URIError) {
|
|
2714
|
+
throw new HttpError(400, "Could not URL-decode key name");
|
|
2715
|
+
} else {
|
|
2716
|
+
throw e;
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
function validateKey(key) {
|
|
2721
|
+
if (key === "") {
|
|
2722
|
+
throw new HttpError(400, "Key names must not be empty");
|
|
2723
|
+
}
|
|
2724
|
+
if (key === "." || key === "..") {
|
|
2725
|
+
throw new HttpError(
|
|
2726
|
+
400,
|
|
2727
|
+
`Illegal key name "${key}". Please use a different name.`
|
|
2728
|
+
);
|
|
2729
|
+
}
|
|
2730
|
+
validateKeyLength(key);
|
|
2731
|
+
}
|
|
2732
|
+
function validateKeyLength(key) {
|
|
2733
|
+
const keyLength = import_node_buffer3.Buffer.byteLength(key);
|
|
2734
|
+
if (keyLength > KVLimits.MAX_KEY_SIZE_BYTES) {
|
|
2735
|
+
throw new HttpError(
|
|
2736
|
+
414,
|
|
2737
|
+
`UTF-8 encoded length of ${keyLength} exceeds key length limit of ${KVLimits.MAX_KEY_SIZE_BYTES}.`
|
|
2738
|
+
);
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
function validateGetOptions(key, options) {
|
|
2742
|
+
validateKey(key);
|
|
2743
|
+
const cacheTtl = options?.cacheTtl;
|
|
2744
|
+
if (cacheTtl !== void 0 && (isNaN(cacheTtl) || cacheTtl < KVLimits.MIN_CACHE_TTL_SECONDS)) {
|
|
2745
|
+
throw new HttpError(
|
|
2746
|
+
400,
|
|
2747
|
+
`Invalid ${KVParams.CACHE_TTL} of ${cacheTtl}. Cache TTL must be at least ${KVLimits.MIN_CACHE_TTL_SECONDS}.`
|
|
2748
|
+
);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
function validatePutOptions(key, options) {
|
|
2752
|
+
const { now, rawExpiration, rawExpirationTtl, rawMetadata } = options;
|
|
2753
|
+
validateKey(key);
|
|
2754
|
+
let expiration;
|
|
2755
|
+
if (rawExpirationTtl !== null) {
|
|
2756
|
+
const expirationTtl = parseInt(rawExpirationTtl);
|
|
2757
|
+
if (Number.isNaN(expirationTtl) || expirationTtl <= 0) {
|
|
2758
|
+
throw new HttpError(
|
|
2759
|
+
400,
|
|
2760
|
+
`Invalid ${KVParams.EXPIRATION_TTL} of ${rawExpirationTtl}. Please specify integer greater than 0.`
|
|
2761
|
+
);
|
|
2762
|
+
}
|
|
2763
|
+
if (expirationTtl < KVLimits.MIN_EXPIRATION_TTL_SECONDS) {
|
|
2764
|
+
throw new HttpError(
|
|
2765
|
+
400,
|
|
2766
|
+
`Invalid ${KVParams.EXPIRATION_TTL} of ${rawExpirationTtl}. Expiration TTL must be at least ${KVLimits.MIN_EXPIRATION_TTL_SECONDS}.`
|
|
2767
|
+
);
|
|
2768
|
+
}
|
|
2769
|
+
expiration = now + expirationTtl;
|
|
2770
|
+
} else if (rawExpiration !== null) {
|
|
2771
|
+
expiration = parseInt(rawExpiration);
|
|
2772
|
+
if (Number.isNaN(expiration) || expiration <= now) {
|
|
2773
|
+
throw new HttpError(
|
|
2774
|
+
400,
|
|
2775
|
+
`Invalid ${KVParams.EXPIRATION} of ${rawExpiration}. Please specify integer greater than the current number of seconds since the UNIX epoch.`
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
if (expiration < now + KVLimits.MIN_EXPIRATION_TTL_SECONDS) {
|
|
2779
|
+
throw new HttpError(
|
|
2780
|
+
400,
|
|
2781
|
+
`Invalid ${KVParams.EXPIRATION} of ${rawExpiration}. Expiration times must be at least ${KVLimits.MIN_EXPIRATION_TTL_SECONDS} seconds in the future.`
|
|
2782
|
+
);
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
let metadata;
|
|
2786
|
+
if (rawMetadata !== null) {
|
|
2787
|
+
const metadataLength = import_node_buffer3.Buffer.byteLength(rawMetadata);
|
|
2788
|
+
if (metadataLength > KVLimits.MAX_METADATA_SIZE_BYTES) {
|
|
2789
|
+
throw new HttpError(
|
|
2790
|
+
413,
|
|
2791
|
+
`Metadata length of ${metadataLength} exceeds limit of ${KVLimits.MAX_METADATA_SIZE_BYTES}.`
|
|
2792
|
+
);
|
|
2793
|
+
}
|
|
2794
|
+
metadata = JSON.parse(rawMetadata);
|
|
2795
|
+
}
|
|
2796
|
+
return { expiration, metadata };
|
|
2797
|
+
}
|
|
2798
|
+
function decodeListOptions(url) {
|
|
2799
|
+
const limitParam = url.searchParams.get(KVParams.LIST_LIMIT);
|
|
2800
|
+
const limit = limitParam === null ? KVLimits.MAX_LIST_KEYS : parseInt(limitParam);
|
|
2801
|
+
const prefix = url.searchParams.get(KVParams.LIST_PREFIX) ?? void 0;
|
|
2802
|
+
const cursor = url.searchParams.get(KVParams.LIST_CURSOR) ?? void 0;
|
|
2803
|
+
return { limit, prefix, cursor };
|
|
2804
|
+
}
|
|
2805
|
+
function validateListOptions(options) {
|
|
2806
|
+
const limit = options.limit;
|
|
2807
|
+
if (limit !== void 0) {
|
|
2808
|
+
if (isNaN(limit) || limit < 1) {
|
|
2809
|
+
throw new HttpError(
|
|
2810
|
+
400,
|
|
2811
|
+
`Invalid ${KVParams.LIST_LIMIT} of ${limit}. Please specify an integer greater than 0.`
|
|
2812
|
+
);
|
|
2813
|
+
}
|
|
2814
|
+
if (limit > KVLimits.MAX_LIST_KEYS) {
|
|
2815
|
+
throw new HttpError(
|
|
2816
|
+
400,
|
|
2817
|
+
`Invalid ${KVParams.LIST_LIMIT} of ${limit}. Please specify an integer less than ${KVLimits.MAX_LIST_KEYS}.`
|
|
2818
|
+
);
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
const prefix = options.prefix;
|
|
2822
|
+
if (prefix != null) {
|
|
2823
|
+
validateKeyLength(prefix);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
// ../../../../../tmp/wsdk/packages/miniflare/src/workers/kv/namespace.worker.ts
|
|
2828
|
+
function createMaxValueSizeError(length, maxValueSize) {
|
|
2829
|
+
return new HttpError(
|
|
2830
|
+
413,
|
|
2831
|
+
`Value length of ${length} exceeds limit of ${maxValueSize}.`
|
|
2832
|
+
);
|
|
2833
|
+
}
|
|
2834
|
+
var MaxLengthStream = class extends TransformStream {
|
|
2835
|
+
signal;
|
|
2836
|
+
length;
|
|
2837
|
+
constructor(maxLength) {
|
|
2838
|
+
const abortController = new AbortController();
|
|
2839
|
+
const lengthPromise = new DeferredPromise();
|
|
2840
|
+
let length = 0;
|
|
2841
|
+
super({
|
|
2842
|
+
transform(chunk, controller) {
|
|
2843
|
+
length += chunk.byteLength;
|
|
2844
|
+
if (length <= maxLength) {
|
|
2845
|
+
controller.enqueue(chunk);
|
|
2846
|
+
} else if (!abortController.signal.aborted) {
|
|
2847
|
+
abortController.abort();
|
|
2848
|
+
}
|
|
2849
|
+
},
|
|
2850
|
+
flush() {
|
|
2851
|
+
lengthPromise.resolve(length);
|
|
2852
|
+
}
|
|
2853
|
+
});
|
|
2854
|
+
this.signal = abortController.signal;
|
|
2855
|
+
this.length = lengthPromise;
|
|
2856
|
+
}
|
|
2857
|
+
};
|
|
2858
|
+
function millisToSeconds(millis) {
|
|
2859
|
+
return Math.floor(millis / 1e3);
|
|
2860
|
+
}
|
|
2861
|
+
function secondsToMillis(seconds) {
|
|
2862
|
+
return seconds * 1e3;
|
|
2863
|
+
}
|
|
2864
|
+
async function processKeyValue(obj, type = "text", withMetadata = false) {
|
|
2865
|
+
const decoder = new TextDecoder();
|
|
2866
|
+
let decodedValue = "";
|
|
2867
|
+
if (obj?.value) {
|
|
2868
|
+
for await (const chunk of obj?.value) {
|
|
2869
|
+
decodedValue += decoder.decode(chunk, { stream: true });
|
|
2870
|
+
}
|
|
2871
|
+
decodedValue += decoder.decode();
|
|
2872
|
+
}
|
|
2873
|
+
let val = null;
|
|
2874
|
+
const size = decodedValue.length;
|
|
2875
|
+
try {
|
|
2876
|
+
val = !obj?.value ? null : type === "json" ? JSON.parse(decodedValue) : decodedValue;
|
|
2877
|
+
} catch {
|
|
2878
|
+
throw new HttpError(
|
|
2879
|
+
400,
|
|
2880
|
+
`At least one of the requested keys corresponds to a non-${type} value`
|
|
2881
|
+
);
|
|
2882
|
+
}
|
|
2883
|
+
if (val !== null && withMetadata) {
|
|
2884
|
+
return [
|
|
2885
|
+
{
|
|
2886
|
+
value: val,
|
|
2887
|
+
metadata: obj?.metadata ?? null
|
|
2888
|
+
},
|
|
2889
|
+
size
|
|
2890
|
+
];
|
|
2891
|
+
}
|
|
2892
|
+
return [val, size];
|
|
2893
|
+
}
|
|
2894
|
+
var KVNamespaceObject = class extends MiniflareDurableObject {
|
|
2895
|
+
#storage;
|
|
2896
|
+
get storage() {
|
|
2897
|
+
return this.#storage ??= new KeyValueStorage(this);
|
|
2898
|
+
}
|
|
2899
|
+
get = async (req, params, url) => {
|
|
2900
|
+
if (req.method === "POST" && req.body != null) {
|
|
2901
|
+
let decodedBody = "";
|
|
2902
|
+
const decoder = new TextDecoder();
|
|
2903
|
+
for await (const chunk of req.body) {
|
|
2904
|
+
decodedBody += decoder.decode(chunk, { stream: true });
|
|
2905
|
+
}
|
|
2906
|
+
decodedBody += decoder.decode();
|
|
2907
|
+
const parsedBody = JSON.parse(decodedBody);
|
|
2908
|
+
const keys = parsedBody.keys;
|
|
2909
|
+
const type = parsedBody?.type;
|
|
2910
|
+
if (type && type !== "text" && type !== "json") {
|
|
2911
|
+
const errorStr = `"${type}" is not a valid type. Use "json" or "text"`;
|
|
2912
|
+
return new Response(errorStr, { status: 400, statusText: errorStr });
|
|
2913
|
+
}
|
|
2914
|
+
const obj = {};
|
|
2915
|
+
if (keys.length > MAX_BULK_GET_KEYS) {
|
|
2916
|
+
const errorStr = `You can request a maximum of ${MAX_BULK_GET_KEYS} keys`;
|
|
2917
|
+
return new Response(errorStr, { status: 400, statusText: errorStr });
|
|
2918
|
+
}
|
|
2919
|
+
if (keys.length < 1) {
|
|
2920
|
+
const errorStr = "You must request a minimum of 1 key";
|
|
2921
|
+
return new Response(errorStr, { status: 400, statusText: errorStr });
|
|
2922
|
+
}
|
|
2923
|
+
let totalBytes = 0;
|
|
2924
|
+
for (const key2 of keys) {
|
|
2925
|
+
validateGetOptions(key2, { cacheTtl: parsedBody?.cacheTtl });
|
|
2926
|
+
const entry2 = await this.storage.get(key2);
|
|
2927
|
+
const [value, size] = await processKeyValue(
|
|
2928
|
+
entry2,
|
|
2929
|
+
parsedBody?.type,
|
|
2930
|
+
parsedBody?.withMetadata
|
|
2931
|
+
);
|
|
2932
|
+
totalBytes += size;
|
|
2933
|
+
obj[key2] = value;
|
|
2934
|
+
}
|
|
2935
|
+
const maxValueSize = this.beingTested ? KVLimits.MAX_VALUE_SIZE_TEST_BYTES : KVLimits.MAX_BULK_SIZE_BYTES;
|
|
2936
|
+
if (totalBytes > maxValueSize) {
|
|
2937
|
+
throw new HttpError(
|
|
2938
|
+
413,
|
|
2939
|
+
`Total size of request exceeds the limit of ${maxValueSize / 1024 / 1024}MB`
|
|
2940
|
+
);
|
|
2941
|
+
}
|
|
2942
|
+
return new Response(JSON.stringify(obj));
|
|
2943
|
+
}
|
|
2944
|
+
const key = decodeKey(params, url.searchParams);
|
|
2945
|
+
const cacheTtlParam = url.searchParams.get(KVParams.CACHE_TTL);
|
|
2946
|
+
const cacheTtl = cacheTtlParam === null ? void 0 : parseInt(cacheTtlParam);
|
|
2947
|
+
validateGetOptions(key, { cacheTtl });
|
|
2948
|
+
const entry = await this.storage.get(key);
|
|
2949
|
+
if (entry === null) {
|
|
2950
|
+
throw new HttpError(404, "Not Found");
|
|
2951
|
+
}
|
|
2952
|
+
const headers = new Headers();
|
|
2953
|
+
if (entry.expiration !== void 0) {
|
|
2954
|
+
headers.set(
|
|
2955
|
+
KVHeaders.EXPIRATION,
|
|
2956
|
+
millisToSeconds(entry.expiration).toString()
|
|
2957
|
+
);
|
|
2958
|
+
}
|
|
2959
|
+
if (entry.metadata !== void 0) {
|
|
2960
|
+
headers.set(KVHeaders.METADATA, JSON.stringify(entry.metadata));
|
|
2961
|
+
}
|
|
2962
|
+
return new Response(entry.value, { headers });
|
|
2963
|
+
};
|
|
2964
|
+
put = async (req, params, url) => {
|
|
2965
|
+
const key = decodeKey(params, url.searchParams);
|
|
2966
|
+
const rawExpiration = url.searchParams.get(KVParams.EXPIRATION);
|
|
2967
|
+
const rawExpirationTtl = url.searchParams.get(KVParams.EXPIRATION_TTL);
|
|
2968
|
+
const rawMetadata = req.headers.get(KVHeaders.METADATA);
|
|
2969
|
+
const now = millisToSeconds(this.timers.now());
|
|
2970
|
+
const { expiration, metadata } = validatePutOptions(key, {
|
|
2971
|
+
now,
|
|
2972
|
+
rawExpiration,
|
|
2973
|
+
rawExpirationTtl,
|
|
2974
|
+
rawMetadata
|
|
2975
|
+
});
|
|
2976
|
+
let value = req.body;
|
|
2977
|
+
const contentLength = parseInt(req.headers.get("Content-Length") ?? "NaN");
|
|
2978
|
+
let valueLengthHint;
|
|
2979
|
+
if (!Number.isNaN(contentLength)) {
|
|
2980
|
+
valueLengthHint = contentLength;
|
|
2981
|
+
} else if (value === null) {
|
|
2982
|
+
valueLengthHint = 0;
|
|
2983
|
+
}
|
|
2984
|
+
value ??= new ReadableStream({
|
|
2985
|
+
start(controller) {
|
|
2986
|
+
controller.close();
|
|
2987
|
+
}
|
|
2988
|
+
});
|
|
2989
|
+
const maxValueSize = this.beingTested ? KVLimits.MAX_VALUE_SIZE_TEST_BYTES : KVLimits.MAX_VALUE_SIZE_BYTES;
|
|
2990
|
+
let maxLengthStream;
|
|
2991
|
+
if (valueLengthHint !== void 0 && valueLengthHint > maxValueSize) {
|
|
2992
|
+
throw createMaxValueSizeError(valueLengthHint, maxValueSize);
|
|
2993
|
+
} else {
|
|
2994
|
+
maxLengthStream = new MaxLengthStream(maxValueSize);
|
|
2995
|
+
value = value.pipeThrough(maxLengthStream);
|
|
2996
|
+
}
|
|
2997
|
+
try {
|
|
2998
|
+
await this.storage.put({
|
|
2999
|
+
key,
|
|
3000
|
+
value,
|
|
3001
|
+
expiration: maybeApply(secondsToMillis, expiration),
|
|
3002
|
+
metadata,
|
|
3003
|
+
signal: maxLengthStream?.signal
|
|
3004
|
+
});
|
|
3005
|
+
} catch (e) {
|
|
3006
|
+
if (typeof e === "object" && e !== null && "name" in e && e.name === "AbortError") {
|
|
3007
|
+
assert_default(maxLengthStream !== void 0);
|
|
3008
|
+
const length = await maxLengthStream.length;
|
|
3009
|
+
throw createMaxValueSizeError(length, maxValueSize);
|
|
3010
|
+
} else {
|
|
3011
|
+
throw e;
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
return new Response();
|
|
3015
|
+
};
|
|
3016
|
+
delete = async (req, params, url) => {
|
|
3017
|
+
const key = decodeKey(params, url.searchParams);
|
|
3018
|
+
validateKey(key);
|
|
3019
|
+
await this.storage.delete(key);
|
|
3020
|
+
return new Response();
|
|
3021
|
+
};
|
|
3022
|
+
list = async (req, params, url) => {
|
|
3023
|
+
const options = decodeListOptions(url);
|
|
3024
|
+
validateListOptions(options);
|
|
3025
|
+
const res = await this.storage.list(options);
|
|
3026
|
+
const keys = res.keys.map((key) => ({
|
|
3027
|
+
name: key.key,
|
|
3028
|
+
expiration: maybeApply(millisToSeconds, key.expiration),
|
|
3029
|
+
// workerd expects metadata to be a JSON-serialised string
|
|
3030
|
+
metadata: maybeApply(JSON.stringify, key.metadata)
|
|
3031
|
+
}));
|
|
3032
|
+
let result;
|
|
3033
|
+
if (res.cursor === void 0) {
|
|
3034
|
+
result = { keys, list_complete: true, cacheStatus: null };
|
|
3035
|
+
} else {
|
|
3036
|
+
result = {
|
|
3037
|
+
keys,
|
|
3038
|
+
list_complete: false,
|
|
3039
|
+
cursor: res.cursor,
|
|
3040
|
+
cacheStatus: null
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
return Response.json(result);
|
|
3044
|
+
};
|
|
3045
|
+
};
|
|
3046
|
+
__decorateClass([
|
|
3047
|
+
GET("/:key"),
|
|
3048
|
+
POST("/bulk/get")
|
|
3049
|
+
], KVNamespaceObject.prototype, "get", 2);
|
|
3050
|
+
__decorateClass([
|
|
3051
|
+
PUT("/:key")
|
|
3052
|
+
], KVNamespaceObject.prototype, "put", 2);
|
|
3053
|
+
__decorateClass([
|
|
3054
|
+
DELETE("/:key")
|
|
3055
|
+
], KVNamespaceObject.prototype, "delete", 2);
|
|
3056
|
+
__decorateClass([
|
|
3057
|
+
GET("/")
|
|
3058
|
+
], KVNamespaceObject.prototype, "list", 2);
|
|
3059
|
+
export {
|
|
3060
|
+
KVNamespaceObject
|
|
3061
|
+
};
|