wao 0.41.3 → 0.41.5
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/.babelrc-cjs +5 -0
- package/.babelrc-esm +5 -0
- package/.gitmodules +4 -0
- package/.prettierrc +6 -0
- package/README.md +90 -0
- package/app/.eslintrc.json +3 -0
- package/app/.mocharc.cjs +6 -0
- package/app/arweave.mjs +87 -0
- package/app/components/Footer.js +76 -0
- package/app/components/Global.js +1128 -0
- package/app/components/Header.js +306 -0
- package/app/components/Left.js +28 -0
- package/app/components/Logo.js +34 -0
- package/app/components/Middle.js +37 -0
- package/app/components/Sidebar.js +93 -0
- package/app/components/Tags.js +42 -0
- package/app/components/editor/Editor.js +322 -0
- package/app/components/editor/FilePath.js +42 -0
- package/app/components/editor/MonacoEditor.js +44 -0
- package/app/components/left/LeftMessages.js +85 -0
- package/app/components/left/LeftModules.js +86 -0
- package/app/components/left/LeftNetworks.js +438 -0
- package/app/components/left/LeftProcesses.js +98 -0
- package/app/components/left/LeftProjects.js +397 -0
- package/app/components/left/LeftTests.js +189 -0
- package/app/components/middle/MiddleBlocks.js +79 -0
- package/app/components/middle/MiddleEntity.js +16 -0
- package/app/components/middle/MiddleEntityAccount.js +264 -0
- package/app/components/middle/MiddleEntityAssignment.js +104 -0
- package/app/components/middle/MiddleEntityBlock.js +148 -0
- package/app/components/middle/MiddleEntityMessage.js +430 -0
- package/app/components/middle/MiddleEntityModule.js +183 -0
- package/app/components/middle/MiddleEntityProcess.js +323 -0
- package/app/components/middle/MiddleEntityTx.js +211 -0
- package/app/components/middle/MiddleMessages.js +87 -0
- package/app/components/middle/MiddleModules.js +89 -0
- package/app/components/middle/MiddleNetworks.js +516 -0
- package/app/components/middle/MiddleProcesses.js +87 -0
- package/app/components/middle/MiddleTests.js +134 -0
- package/app/components/modals/CreateFileModal.js +115 -0
- package/app/components/modals/CreateFolderModal.js +83 -0
- package/app/components/modals/CreateProjectModal.js +63 -0
- package/app/components/modals/FSModal.js +141 -0
- package/app/components/modals/ImportModal.js +105 -0
- package/app/components/modals/LaunchNetworkModal.js +95 -0
- package/app/components/modals/Modal.js +38 -0
- package/app/components/modals/ProxyModal.js +122 -0
- package/app/components/modals/RenameFileModal.js +95 -0
- package/app/components/styles/EditorScrollbarStyle.js +29 -0
- package/app/components/styles/EntityScrollbarStyle.js +29 -0
- package/app/components/styles/GlobalStyle.js +102 -0
- package/app/components/styles/XtermStyle.js +37 -0
- package/app/components/terminal/Terminal.js +132 -0
- package/app/components/terminal/Xterm.js +160 -0
- package/app/components/ui/avatar.jsx +49 -0
- package/app/components/ui/checkbox.jsx +17 -0
- package/app/components/ui/close-button.jsx +20 -0
- package/app/components/ui/color-mode.jsx +61 -0
- package/app/components/ui/dialog.jsx +54 -0
- package/app/components/ui/drawer.jsx +44 -0
- package/app/components/ui/field.jsx +22 -0
- package/app/components/ui/input-group.jsx +39 -0
- package/app/components/ui/popover.jsx +49 -0
- package/app/components/ui/provider.jsx +12 -0
- package/app/components/ui/radio.jsx +17 -0
- package/app/components/ui/slider.jsx +107 -0
- package/app/components/ui/toaster.jsx +69 -0
- package/app/components/ui/tooltip.jsx +35 -0
- package/app/index.js +10 -0
- package/app/jsconfig.json +7 -0
- package/app/lib/GithubCSS.js +1218 -0
- package/app/lib/addon-fit.js +72 -0
- package/app/lib/data.js +31 -0
- package/app/lib/github-markdown.css +1169 -0
- package/app/lib/global.js +1 -0
- package/app/lib/guide.js +82 -0
- package/app/lib/hub.js +109 -0
- package/app/lib/scripts.js +47 -0
- package/app/lib/store.js +34 -0
- package/app/lib/use.js +64 -0
- package/app/lib/utils.js +387 -0
- package/app/lib/webrtc.js +217 -0
- package/app/next.config.js +25 -0
- package/app/package.json +62 -0
- package/app/pages/404.js +9 -0
- package/app/pages/_app.js +10 -0
- package/app/pages/_document.js +14 -0
- package/app/pages/index.js +121 -0
- package/app/playwright.config.mjs +41 -0
- package/app/proxy.mjs +21 -0
- package/app/public/assets/cover.png +0 -0
- package/app/public/blueprints/apm.lua +91 -0
- package/app/public/blueprints/arena.lua +345 -0
- package/app/public/blueprints/arns.lua +318 -0
- package/app/public/blueprints/chat.lua +210 -0
- package/app/public/blueprints/chatroom.lua +56 -0
- package/app/public/blueprints/patch-legacy-reply.lua +13 -0
- package/app/public/blueprints/staking.lua +93 -0
- package/app/public/blueprints/token.lua +298 -0
- package/app/public/blueprints/voting.lua +45 -0
- package/app/public/favicon.ico +0 -0
- package/app/public/logo.png +0 -0
- package/cli-esm.js +55 -0
- package/cli.js +54 -0
- package/devnet/app/api.js +129 -0
- package/devnet/app/components/layout.js +89 -0
- package/devnet/app/components/pagination.js +144 -0
- package/devnet/app/components/search.js +159 -0
- package/devnet/app/components/table.js +124 -0
- package/devnet/app/components/tags.js +89 -0
- package/devnet/app/index.html +14 -0
- package/devnet/app/main.js +215 -0
- package/devnet/app/router.js +59 -0
- package/devnet/app/state.js +19 -0
- package/devnet/app/style.css +1606 -0
- package/devnet/app/utils.js +77 -0
- package/devnet/app/views/blocks.js +75 -0
- package/devnet/app/views/dashboard.js +127 -0
- package/devnet/app/views/entity.js +1473 -0
- package/devnet/app/views/messages.js +90 -0
- package/devnet/app/views/modules.js +165 -0
- package/devnet/app/views/processes.js +90 -0
- package/devnet/app/views/schedulers.js +90 -0
- package/devnet/app/views/transactions.js +88 -0
- package/devnet/migrations/0001_initial.sql +51 -0
- package/devnet/package.json +26 -0
- package/devnet/playwright.config.js +7 -0
- package/devnet/src/cu-worker.js +166 -0
- package/devnet/src/index.js +309 -0
- package/devnet/vite.config.js +17 -0
- package/devnet/vitest.config.js +10 -0
- package/devnet/wrangler-cu.toml +32 -0
- package/devnet/wrangler.toml +38 -0
- package/dhfs-tutorial-app/package.json +15 -0
- package/dist/esm/workspace/dashboard/public/favicon.png +0 -0
- package/dist/esm/workspace/src/counter.lua +14 -0
- package/dist/package.json +82 -0
- package/hb.sh +18 -0
- package/hbsig/.babelrc-cjs +5 -0
- package/hbsig/.babelrc-esm +5 -0
- package/hbsig/README.md +1 -0
- package/hbsig/dist/cjs/bin_to_str.js +44 -0
- package/hbsig/dist/cjs/collect-body-keys.js +470 -0
- package/hbsig/dist/cjs/commit.js +330 -0
- package/hbsig/dist/cjs/encode-array-item.js +110 -0
- package/hbsig/dist/cjs/encode-utils.js +242 -0
- package/hbsig/dist/cjs/encode.js +1365 -0
- package/hbsig/dist/cjs/erl_json.js +326 -0
- package/hbsig/dist/cjs/erl_str.js +1042 -0
- package/hbsig/dist/cjs/flat.js +279 -0
- package/hbsig/dist/cjs/http-message-signatures/httpbis.js +489 -0
- package/hbsig/dist/cjs/http-message-signatures/index.js +25 -0
- package/hbsig/dist/cjs/http-message-signatures/structured-header.js +129 -0
- package/hbsig/dist/cjs/httpsig.js +861 -0
- package/hbsig/dist/cjs/id.js +470 -0
- package/hbsig/dist/cjs/index.js +174 -0
- package/hbsig/dist/cjs/nocrypto.js +51 -0
- package/hbsig/dist/cjs/parser.js +201 -0
- package/hbsig/dist/cjs/send-utils.js +1231 -0
- package/hbsig/dist/cjs/send.js +211 -0
- package/hbsig/dist/cjs/signer-utils.js +494 -0
- package/hbsig/dist/cjs/signer.js +436 -0
- package/hbsig/dist/cjs/structured.js +515 -0
- package/hbsig/dist/cjs/test.js +12 -0
- package/hbsig/dist/cjs/utils.js +44 -0
- package/hbsig/dist/esm/bin_to_str.js +46 -0
- package/hbsig/dist/esm/collect-body-keys.js +436 -0
- package/hbsig/dist/esm/commit.js +219 -0
- package/hbsig/dist/esm/encode-array-item.js +112 -0
- package/hbsig/dist/esm/encode-utils.js +191 -0
- package/hbsig/dist/esm/encode.js +1256 -0
- package/hbsig/dist/esm/erl_json.js +292 -0
- package/hbsig/dist/esm/erl_str.js +1144 -0
- package/hbsig/dist/esm/flat.js +250 -0
- package/hbsig/dist/esm/http-message-signatures/httpbis.js +438 -0
- package/hbsig/dist/esm/http-message-signatures/index.js +4 -0
- package/hbsig/dist/esm/http-message-signatures/structured-header.js +105 -0
- package/hbsig/dist/esm/httpsig.js +866 -0
- package/hbsig/dist/esm/id.js +459 -0
- package/hbsig/dist/esm/index.js +13 -0
- package/hbsig/dist/esm/nocrypto.js +4 -0
- package/hbsig/dist/esm/package.json +3 -0
- package/hbsig/dist/esm/parser.js +171 -0
- package/hbsig/dist/esm/send-utils.js +1132 -0
- package/hbsig/dist/esm/send.js +142 -0
- package/hbsig/dist/esm/signer-utils.js +375 -0
- package/hbsig/dist/esm/signer.js +312 -0
- package/hbsig/dist/esm/structured.js +496 -0
- package/hbsig/dist/esm/test.js +2 -0
- package/hbsig/dist/esm/utils.js +29 -0
- package/hbsig/dist/package.json +39 -0
- package/hbsig/make.js +36 -0
- package/hbsig/package.json +39 -0
- package/hbsig/src/bin_to_str.js +46 -0
- package/hbsig/src/collect-body-keys.js +436 -0
- package/hbsig/src/commit.js +219 -0
- package/hbsig/src/encode-array-item.js +112 -0
- package/hbsig/src/encode-utils.js +191 -0
- package/hbsig/src/encode.js +1256 -0
- package/hbsig/src/erl_json.js +292 -0
- package/hbsig/src/erl_str.js +1144 -0
- package/hbsig/src/flat.js +250 -0
- package/hbsig/src/http-message-signatures/httpbis.js +438 -0
- package/hbsig/src/http-message-signatures/index.js +4 -0
- package/hbsig/src/http-message-signatures/structured-header.js +105 -0
- package/hbsig/src/httpsig.js +866 -0
- package/hbsig/src/id.js +459 -0
- package/hbsig/src/index.js +13 -0
- package/hbsig/src/nocrypto.js +4 -0
- package/hbsig/src/parser.js +171 -0
- package/hbsig/src/send-utils.js +1132 -0
- package/hbsig/src/send.js +142 -0
- package/hbsig/src/signer-utils.js +375 -0
- package/hbsig/src/signer.js +312 -0
- package/hbsig/src/structured.js +496 -0
- package/hbsig/src/test.js +2 -0
- package/hbsig/src/utils.js +29 -0
- package/lp/index.html +25 -0
- package/lp/package.json +19 -0
- package/lp/public/cover.png +0 -0
- package/lp/public/favicon.ico +0 -0
- package/lp/public/favicon.png +0 -0
- package/lp/public/images/book.jpg +0 -0
- package/lp/public/images/dashboard.png +0 -0
- package/lp/public/images/devnet.png +0 -0
- package/lp/public/images/hero-bg.png +0 -0
- package/lp/public/images/hyperadd.png +0 -0
- package/lp/public/images/message-flow.png +0 -0
- package/lp/public/images/mobile.png +0 -0
- package/lp/public/images/og-cover.png +0 -0
- package/lp/public/images/scan.png +0 -0
- package/lp/public/images/wao-hub.png +0 -0
- package/lp/public/images/wao-web.png +0 -0
- package/lp/public/logo.png +0 -0
- package/lp/src/App.jsx +29 -0
- package/lp/src/components/CodeBlock.jsx +37 -0
- package/lp/src/components/CodeBlock.module.css +89 -0
- package/lp/src/components/Footer.jsx +22 -0
- package/lp/src/components/Footer.module.css +60 -0
- package/lp/src/components/Nav.jsx +80 -0
- package/lp/src/components/Nav.module.css +177 -0
- package/lp/src/components/SectionWrapper.jsx +15 -0
- package/lp/src/hooks/useReveal.js +25 -0
- package/lp/src/hooks/useScrolled.js +14 -0
- package/lp/src/main.jsx +10 -0
- package/lp/src/sections/Book.jsx +60 -0
- package/lp/src/sections/Book.module.css +204 -0
- package/lp/src/sections/Browser.jsx +46 -0
- package/lp/src/sections/Browser.module.css +67 -0
- package/lp/src/sections/Devnet.jsx +55 -0
- package/lp/src/sections/Devnet.module.css +136 -0
- package/lp/src/sections/GetStarted.jsx +51 -0
- package/lp/src/sections/GetStarted.module.css +128 -0
- package/lp/src/sections/Hero.jsx +67 -0
- package/lp/src/sections/Hero.module.css +202 -0
- package/lp/src/sections/HyperADD.jsx +46 -0
- package/lp/src/sections/HyperADD.module.css +113 -0
- package/lp/src/sections/SDK.jsx +90 -0
- package/lp/src/sections/SDK.module.css +122 -0
- package/lp/src/sections/Testing.jsx +47 -0
- package/lp/src/sections/Testing.module.css +124 -0
- package/lp/src/sections/Vision.jsx +93 -0
- package/lp/src/sections/Vision.module.css +147 -0
- package/lp/src/styles/globals.css +285 -0
- package/lp/src/utils/scrollTo.js +4 -0
- package/lp/vite.config.js +7 -0
- package/make.js +39 -0
- package/package.json +17 -12
- package/patches/@permaweb+ao-loader+0.0.44.patch +64 -0
- package/plan.md +435 -0
- package/rebar.lock +1 -0
- package/src/accounts-web.js +128 -0
- package/src/accounts.js +124 -0
- package/src/adaptor-base.js +622 -0
- package/src/adaptor-cf.js +11 -0
- package/src/adaptor-web.js +11 -0
- package/src/adaptor.js +10 -0
- package/src/ao-loader.js +30660 -0
- package/src/ao.js +1173 -0
- package/src/aoconnect-base.js +1098 -0
- package/src/aoconnect-cf.js +9 -0
- package/src/aoconnect-web.js +8 -0
- package/src/aoconnect.js +8 -0
- package/src/aos_wamr.js +1 -0
- package/src/ar-remote.js +87 -0
- package/src/ar.js +276 -0
- package/src/armem-base.js +529 -0
- package/src/armem-cf.js +67 -0
- package/src/armem-web.js +19 -0
- package/src/armem.js +26 -0
- package/src/bao.js +141 -0
- package/src/bar.js +366 -0
- package/src/build.js +7 -0
- package/src/bundler.js +119 -0
- package/src/car.js +10 -0
- package/src/cf-env.js +29 -0
- package/src/cf.js +11 -0
- package/src/cli.js +561 -0
- package/src/compress.js +112 -0
- package/src/create.js +415 -0
- package/src/devs.js +86 -0
- package/src/dirname.js +1 -0
- package/src/dodb.js +26 -0
- package/src/erl_json.js +289 -0
- package/src/erl_str.js +1139 -0
- package/src/gql.js +229 -0
- package/src/hb.js +967 -0
- package/src/helpers.js +203 -0
- package/src/http.js +619 -0
- package/src/hub/bundler.js +123 -0
- package/src/hub/cu.js +74 -0
- package/src/hub/fs.js +157 -0
- package/src/hub/index.js +85 -0
- package/src/hub/utils.js +64 -0
- package/src/hub/ws-proxy.js +67 -0
- package/src/hyper-aos.js +1 -0
- package/src/hyperbeam-server.js +21 -0
- package/src/hyperbeam.js +585 -0
- package/src/index.js +5 -0
- package/src/keygen.js +47 -0
- package/src/lfdb.js +67 -0
- package/src/lua/aos.wasm +0 -0
- package/src/lua/aos2_0_1.js +1 -0
- package/src/lua/aos2_0_1.wasm +0 -0
- package/src/lua/aos2_0_3.js +1 -0
- package/src/lua/aos2_0_3.wasm +0 -0
- package/src/lua/aos2_0_4_32.js +1 -0
- package/src/lua/aos2_0_4_32.wasm +0 -0
- package/src/lua/aos2_0_6.wasm +0 -0
- package/src/lua/apm.lua +61 -0
- package/src/lua/llama.wasm +0 -0
- package/src/lua/process.wasm +0 -0
- package/src/lua/sqlite.js +1 -0
- package/src/lua/sqlite.wasm +0 -0
- package/src/lua/weavedb_mock.lua +44 -0
- package/src/lua/weavedrive.lua +53 -0
- package/src/run.js +25 -0
- package/src/server.js +173 -0
- package/src/storage-multi.js +183 -0
- package/src/tao.js +12 -0
- package/src/tar.js +10 -0
- package/src/test.js +42 -0
- package/src/tgql-d1.js +407 -0
- package/src/tgql.js +310 -0
- package/src/toerl.js +162 -0
- package/src/utils.js +777 -0
- package/src/wao.js +29 -0
- package/src/waosm/README.md +81 -0
- package/src/waosm/waosm.d.ts +40 -0
- package/src/waosm/waosm.js +240 -0
- package/src/waosm/waosm_bg.wasm +0 -0
- package/src/waosm/waosm_bg.wasm.d.ts +8 -0
- package/src/waosm-node/README.md +81 -0
- package/src/waosm-node/waosm.d.ts +8 -0
- package/src/waosm-node/waosm.js +4 -0
- package/src/waosm-node/waosm_bg.js +147 -0
- package/src/waosm-node/waosm_bg.wasm +0 -0
- package/src/waosm-node/waosm_bg.wasm.d.ts +8 -0
- package/src/waosm-node/waosm_bg.wasm.js +14 -0
- package/src/waosm-node.js +9 -0
- package/src/war.js +10 -0
- package/src/weavedrive.js +376 -0
- package/src/web.js +11 -0
- package/src/workspace/.mcp.json +8 -0
- package/src/workspace/CLAUDE.md +258 -0
- package/src/workspace/README.md +85 -0
- package/src/workspace/dashboard/index.html +163 -0
- package/src/workspace/dashboard/package.json +18 -0
- package/src/workspace/dashboard/public/favicon.ico +0 -0
- package/src/workspace/dashboard/public/favicon.png +0 -0
- package/src/workspace/dashboard/server.js +224 -0
- package/src/workspace/dashboard/src/App.jsx +2350 -0
- package/{cjs/workspace/frontend → src/workspace/dashboard}/vite.config.js +6 -0
- package/src/workspace/package.json +18 -0
- package/src/workspace/src/counter.lua +14 -0
- package/tsconfig.json +18 -0
- package/types/index.d.ts +329 -0
- package/waollama/.eslintrc.json +3 -0
- package/waollama/README.md +19 -0
- package/waollama/arweave.mjs +87 -0
- package/waollama/components/ui/avatar.jsx +49 -0
- package/waollama/components/ui/checkbox.jsx +17 -0
- package/waollama/components/ui/close-button.jsx +20 -0
- package/waollama/components/ui/color-mode.jsx +61 -0
- package/waollama/components/ui/dialog.jsx +54 -0
- package/waollama/components/ui/drawer.jsx +44 -0
- package/waollama/components/ui/field.jsx +22 -0
- package/waollama/components/ui/input-group.jsx +39 -0
- package/waollama/components/ui/popover.jsx +49 -0
- package/waollama/components/ui/provider.jsx +12 -0
- package/waollama/components/ui/radio.jsx +17 -0
- package/waollama/components/ui/slider.jsx +107 -0
- package/waollama/components/ui/tooltip.jsx +35 -0
- package/waollama/index.js +10 -0
- package/waollama/jsconfig.json +7 -0
- package/waollama/lib/ao-loader.js +30654 -0
- package/waollama/lib/client.js +1 -0
- package/waollama/lib/wasm.js +1 -0
- package/waollama/next.config.js +25 -0
- package/waollama/package.json +43 -0
- package/waollama/pages/404.js +9 -0
- package/waollama/pages/_app.js +9 -0
- package/waollama/pages/_document.js +14 -0
- package/waollama/pages/index.js +212 -0
- package/waollama/playwright.config.js +31 -0
- package/waollama/proxy.mjs +21 -0
- package/waollama/public/favicon.ico +0 -0
- package/waollama/public/human.png +0 -0
- package/waollama/public/llama.png +0 -0
- package/waosm/Cargo.toml +11 -0
- package/waosm/README.md +81 -0
- package/waosm/compress.js +112 -0
- package/waosm/make.js +33 -0
- package/waosm/package.json +10 -0
- package/waosm/src/lib.rs +180 -0
- package/waosm/test.js +16 -0
- package/cjs/workspace/.claude/agents/builder.md +0 -99
- package/cjs/workspace/.claude/agents/device-builder.md +0 -86
- package/cjs/workspace/.claude/agents/tester.md +0 -90
- package/cjs/workspace/.claude/mcp/dashboard/server.js +0 -128
- package/cjs/workspace/.claude/rules/deploy.md +0 -45
- package/cjs/workspace/.claude/rules/frontend.md +0 -69
- package/cjs/workspace/.claude/rules/hyperbeam.md +0 -104
- package/cjs/workspace/.claude/rules/lua.md +0 -108
- package/cjs/workspace/.claude/rules/testing.md +0 -257
- package/cjs/workspace/.claude/settings.json +0 -109
- package/cjs/workspace/.claude/skills/build/SKILL.md +0 -214
- package/cjs/workspace/.claude/skills/build-aos/SKILL.md +0 -129
- package/cjs/workspace/.claude/skills/build-device/SKILL.md +0 -192
- package/cjs/workspace/.claude/skills/build-frontend/SKILL.md +0 -134
- package/cjs/workspace/.claude/skills/build-module/SKILL.md +0 -281
- package/cjs/workspace/.claude/skills/create-aos/SKILL.md +0 -63
- package/cjs/workspace/.claude/skills/create-device/SKILL.md +0 -87
- package/cjs/workspace/.claude/skills/create-module/SKILL.md +0 -162
- package/cjs/workspace/.claude/skills/debug/SKILL.md +0 -57
- package/cjs/workspace/.claude/skills/deploy/SKILL.md +0 -85
- package/cjs/workspace/.claude/skills/dev/SKILL.md +0 -32
- package/cjs/workspace/.claude/skills/plan/SKILL.md +0 -176
- package/cjs/workspace/.claude/skills/readme/SKILL.md +0 -186
- package/cjs/workspace/.claude/skills/report/SKILL.md +0 -49
- package/cjs/workspace/.claude/skills/team/SKILL.md +0 -101
- package/cjs/workspace/.claude/skills/test/SKILL.md +0 -56
- package/cjs/workspace/.claude/skills/test-device/SKILL.md +0 -114
- package/cjs/workspace/.claude/skills/test-e2e/SKILL.md +0 -103
- package/cjs/workspace/.claude/skills/test-hb/SKILL.md +0 -76
- package/cjs/workspace/.claude/skills/validate/SKILL.md +0 -96
- package/cjs/workspace/.claude/skills/validate/scripts/check-lua.sh +0 -41
- package/cjs/workspace/docs/aos-lua.md +0 -428
- package/cjs/workspace/docs/debug.md +0 -230
- package/cjs/workspace/docs/hyperbeam-dev.md +0 -606
- package/cjs/workspace/docs/hyperbeam-devices.md +0 -618
- package/cjs/workspace/docs/wao-sdk.md +0 -807
- package/cjs/workspace/frontend/e2e/.gitkeep +0 -0
- package/cjs/workspace/frontend/index.html +0 -12
- package/cjs/workspace/frontend/package.json +0 -24
- package/cjs/workspace/frontend/playwright.config.js +0 -10
- package/cjs/workspace/frontend/src/App.jsx +0 -24
- package/cjs/workspace/frontend/test/.gitkeep +0 -0
- package/cjs/workspace/frontend/vitest.config.js +0 -10
- package/cjs/workspace/scripts/deploy.js +0 -140
- package/cjs/workspace/scripts/keygen.js +0 -52
- package/cjs/workspace/test/aos.test.js +0 -98
- package/cjs/workspace/test/hyperbeam.test.js +0 -80
- package/esm/compiler/native +0 -0
- package/esm/workspace/.claude/agents/builder.md +0 -99
- package/esm/workspace/.claude/agents/device-builder.md +0 -86
- package/esm/workspace/.claude/agents/tester.md +0 -90
- package/esm/workspace/.claude/mcp/dashboard/server.js +0 -128
- package/esm/workspace/.claude/rules/deploy.md +0 -45
- package/esm/workspace/.claude/rules/frontend.md +0 -69
- package/esm/workspace/.claude/rules/hyperbeam.md +0 -104
- package/esm/workspace/.claude/rules/lua.md +0 -108
- package/esm/workspace/.claude/rules/testing.md +0 -257
- package/esm/workspace/.claude/settings.json +0 -109
- package/esm/workspace/.claude/skills/build/SKILL.md +0 -214
- package/esm/workspace/.claude/skills/build-aos/SKILL.md +0 -129
- package/esm/workspace/.claude/skills/build-device/SKILL.md +0 -192
- package/esm/workspace/.claude/skills/build-frontend/SKILL.md +0 -134
- package/esm/workspace/.claude/skills/build-module/SKILL.md +0 -281
- package/esm/workspace/.claude/skills/create-aos/SKILL.md +0 -63
- package/esm/workspace/.claude/skills/create-device/SKILL.md +0 -87
- package/esm/workspace/.claude/skills/create-module/SKILL.md +0 -162
- package/esm/workspace/.claude/skills/debug/SKILL.md +0 -57
- package/esm/workspace/.claude/skills/deploy/SKILL.md +0 -85
- package/esm/workspace/.claude/skills/dev/SKILL.md +0 -32
- package/esm/workspace/.claude/skills/plan/SKILL.md +0 -176
- package/esm/workspace/.claude/skills/readme/SKILL.md +0 -186
- package/esm/workspace/.claude/skills/report/SKILL.md +0 -49
- package/esm/workspace/.claude/skills/team/SKILL.md +0 -101
- package/esm/workspace/.claude/skills/test/SKILL.md +0 -56
- package/esm/workspace/.claude/skills/test-device/SKILL.md +0 -114
- package/esm/workspace/.claude/skills/test-e2e/SKILL.md +0 -103
- package/esm/workspace/.claude/skills/test-hb/SKILL.md +0 -76
- package/esm/workspace/.claude/skills/validate/SKILL.md +0 -96
- package/esm/workspace/.claude/skills/validate/scripts/check-lua.sh +0 -41
- package/esm/workspace/docs/aos-lua.md +0 -428
- package/esm/workspace/docs/debug.md +0 -230
- package/esm/workspace/docs/hyperbeam-dev.md +0 -606
- package/esm/workspace/docs/hyperbeam-devices.md +0 -618
- package/esm/workspace/docs/wao-sdk.md +0 -807
- package/esm/workspace/frontend/e2e/.gitkeep +0 -0
- package/esm/workspace/frontend/index.html +0 -12
- package/esm/workspace/frontend/package.json +0 -24
- package/esm/workspace/frontend/playwright.config.js +0 -10
- package/esm/workspace/frontend/src/App.jsx +0 -24
- package/esm/workspace/frontend/src/main.jsx +0 -9
- package/esm/workspace/frontend/test/.gitkeep +0 -0
- package/esm/workspace/frontend/vite.config.js +0 -6
- package/esm/workspace/frontend/vitest.config.js +0 -10
- package/esm/workspace/scripts/deploy.js +0 -140
- package/esm/workspace/scripts/keygen.js +0 -52
- package/esm/workspace/test/aos.test.js +0 -98
- package/esm/workspace/test/hyperbeam.test.js +0 -80
- /package/{cjs/workspace/dashboard/public → devnet/app}/favicon.ico +0 -0
- /package/{cjs/workspace → dhfs-tutorial-app}/src/counter.lua +0 -0
- /package/{cjs → dist/cjs}/accounts-web.js +0 -0
- /package/{cjs → dist/cjs}/accounts.js +0 -0
- /package/{cjs → dist/cjs}/adaptor-base.js +0 -0
- /package/{cjs → dist/cjs}/adaptor-cf.js +0 -0
- /package/{cjs → dist/cjs}/adaptor-web.js +0 -0
- /package/{cjs → dist/cjs}/adaptor.js +0 -0
- /package/{cjs → dist/cjs}/ao-loader.js +0 -0
- /package/{cjs → dist/cjs}/ao.js +0 -0
- /package/{cjs → dist/cjs}/aoconnect-base.js +0 -0
- /package/{cjs → dist/cjs}/aoconnect-cf.js +0 -0
- /package/{cjs → dist/cjs}/aoconnect-web.js +0 -0
- /package/{cjs → dist/cjs}/aoconnect.js +0 -0
- /package/{cjs → dist/cjs}/aos_wamr.js +0 -0
- /package/{cjs → dist/cjs}/ar-remote.js +0 -0
- /package/{cjs → dist/cjs}/ar.js +0 -0
- /package/{cjs → dist/cjs}/armem-base.js +0 -0
- /package/{cjs → dist/cjs}/armem-cf.js +0 -0
- /package/{cjs → dist/cjs}/armem-web.js +0 -0
- /package/{cjs → dist/cjs}/armem.js +0 -0
- /package/{cjs → dist/cjs}/bao.js +0 -0
- /package/{cjs → dist/cjs}/bar.js +0 -0
- /package/{cjs → dist/cjs}/build.js +0 -0
- /package/{cjs → dist/cjs}/bundler.js +0 -0
- /package/{cjs → dist/cjs}/car.js +0 -0
- /package/{cjs → dist/cjs}/cf-env.js +0 -0
- /package/{cjs → dist/cjs}/cf.js +0 -0
- /package/{cjs → dist/cjs}/cli.js +0 -0
- /package/{cjs → dist/cjs}/compress.js +0 -0
- /package/{cjs → dist/cjs}/create.js +0 -0
- /package/{cjs → dist/cjs}/devs.js +0 -0
- /package/{cjs → dist/cjs}/dirname.js +0 -0
- /package/{cjs → dist/cjs}/dodb.js +0 -0
- /package/{cjs → dist/cjs}/erl_json.js +0 -0
- /package/{cjs → dist/cjs}/erl_str.js +0 -0
- /package/{cjs → dist/cjs}/gql.js +0 -0
- /package/{cjs → dist/cjs}/hb.js +0 -0
- /package/{cjs → dist/cjs}/helpers.js +0 -0
- /package/{cjs → dist/cjs}/http.js +0 -0
- /package/{cjs → dist/cjs}/hub/bundler.js +0 -0
- /package/{cjs → dist/cjs}/hub/cu.js +0 -0
- /package/{cjs → dist/cjs}/hub/fs.js +0 -0
- /package/{cjs → dist/cjs}/hub/index.js +0 -0
- /package/{cjs → dist/cjs}/hub/utils.js +0 -0
- /package/{cjs → dist/cjs}/hub/ws-proxy.js +0 -0
- /package/{cjs → dist/cjs}/hyper-aos.js +0 -0
- /package/{cjs → dist/cjs}/hyperbeam-server.js +0 -0
- /package/{cjs → dist/cjs}/hyperbeam.js +0 -0
- /package/{cjs → dist/cjs}/index.js +0 -0
- /package/{cjs → dist/cjs}/keygen.js +0 -0
- /package/{cjs → dist/cjs}/lfdb.js +0 -0
- /package/{cjs → dist/cjs}/lua/aos.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_1.js +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_1.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_3.js +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_3.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_4_32.js +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_4_32.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/aos2_0_6.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/apm.lua +0 -0
- /package/{cjs → dist/cjs}/lua/llama.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/process.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/sqlite.js +0 -0
- /package/{cjs → dist/cjs}/lua/sqlite.wasm +0 -0
- /package/{cjs → dist/cjs}/lua/weavedb_mock.lua +0 -0
- /package/{cjs → dist/cjs}/lua/weavedrive.lua +0 -0
- /package/{cjs → dist/cjs}/run.js +0 -0
- /package/{cjs → dist/cjs}/server.js +0 -0
- /package/{cjs → dist/cjs}/storage-multi.js +0 -0
- /package/{cjs → dist/cjs}/tao.js +0 -0
- /package/{cjs → dist/cjs}/tar.js +0 -0
- /package/{cjs → dist/cjs}/test.js +0 -0
- /package/{cjs → dist/cjs}/tgql-d1.js +0 -0
- /package/{cjs → dist/cjs}/tgql.js +0 -0
- /package/{cjs → dist/cjs}/toerl.js +0 -0
- /package/{cjs → dist/cjs}/utils.js +0 -0
- /package/{cjs → dist/cjs}/wao.js +0 -0
- /package/{cjs → dist/cjs}/waosm/waosm.js +0 -0
- /package/{cjs → dist/cjs}/waosm-node/waosm.js +0 -0
- /package/{cjs → dist/cjs}/waosm-node/waosm_bg.js +0 -0
- /package/{cjs → dist/cjs}/waosm-node/waosm_bg.wasm +0 -0
- /package/{cjs → dist/cjs}/waosm-node/waosm_bg.wasm.js +0 -0
- /package/{cjs → dist/cjs}/waosm-node.js +0 -0
- /package/{cjs → dist/cjs}/war.js +0 -0
- /package/{cjs → dist/cjs}/weavedrive.js +0 -0
- /package/{cjs → dist/cjs}/web.js +0 -0
- /package/{cjs → dist/cjs}/workspace/.mcp.json +0 -0
- /package/{cjs → dist/cjs}/workspace/CLAUDE.md +0 -0
- /package/{cjs → dist/cjs}/workspace/README.md +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/index.html +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/package.json +0 -0
- /package/{esm → dist/cjs}/workspace/dashboard/public/favicon.ico +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/public/favicon.png +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/server.js +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/src/App.jsx +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/src/main.jsx +0 -0
- /package/{cjs → dist/cjs}/workspace/dashboard/vite.config.js +0 -0
- /package/{cjs → dist/cjs}/workspace/package.json +0 -0
- /package/{esm → dist/cjs}/workspace/src/counter.lua +0 -0
- /package/{esm → dist/esm}/accounts-web.js +0 -0
- /package/{esm → dist/esm}/accounts.js +0 -0
- /package/{esm → dist/esm}/adaptor-base.js +0 -0
- /package/{esm → dist/esm}/adaptor-cf.js +0 -0
- /package/{esm → dist/esm}/adaptor-web.js +0 -0
- /package/{esm → dist/esm}/adaptor.js +0 -0
- /package/{esm → dist/esm}/ao-loader.js +0 -0
- /package/{esm → dist/esm}/ao.js +0 -0
- /package/{esm → dist/esm}/aoconnect-base.js +0 -0
- /package/{esm → dist/esm}/aoconnect-cf.js +0 -0
- /package/{esm → dist/esm}/aoconnect-web.js +0 -0
- /package/{esm → dist/esm}/aoconnect.js +0 -0
- /package/{esm → dist/esm}/aos_wamr.js +0 -0
- /package/{esm → dist/esm}/ar-remote.js +0 -0
- /package/{esm → dist/esm}/ar.js +0 -0
- /package/{esm → dist/esm}/armem-base.js +0 -0
- /package/{esm → dist/esm}/armem-cf.js +0 -0
- /package/{esm → dist/esm}/armem-web.js +0 -0
- /package/{esm → dist/esm}/armem.js +0 -0
- /package/{esm → dist/esm}/bao.js +0 -0
- /package/{esm → dist/esm}/bar.js +0 -0
- /package/{esm → dist/esm}/build.js +0 -0
- /package/{esm → dist/esm}/bundler.js +0 -0
- /package/{esm → dist/esm}/car.js +0 -0
- /package/{esm → dist/esm}/cf-env.js +0 -0
- /package/{esm → dist/esm}/cf.js +0 -0
- /package/{esm → dist/esm}/cli.js +0 -0
- /package/{esm → dist/esm}/compress.js +0 -0
- /package/{esm → dist/esm}/create.js +0 -0
- /package/{esm → dist/esm}/devs.js +0 -0
- /package/{esm → dist/esm}/dirname.js +0 -0
- /package/{esm → dist/esm}/dodb.js +0 -0
- /package/{esm → dist/esm}/erl_json.js +0 -0
- /package/{esm → dist/esm}/erl_str.js +0 -0
- /package/{esm → dist/esm}/gql.js +0 -0
- /package/{esm → dist/esm}/hb.js +0 -0
- /package/{esm → dist/esm}/helpers.js +0 -0
- /package/{esm → dist/esm}/http.js +0 -0
- /package/{esm → dist/esm}/hub/bundler.js +0 -0
- /package/{esm → dist/esm}/hub/cu.js +0 -0
- /package/{esm → dist/esm}/hub/fs.js +0 -0
- /package/{esm → dist/esm}/hub/index.js +0 -0
- /package/{esm → dist/esm}/hub/utils.js +0 -0
- /package/{esm → dist/esm}/hub/ws-proxy.js +0 -0
- /package/{esm → dist/esm}/hyper-aos.js +0 -0
- /package/{esm → dist/esm}/hyperbeam-server.js +0 -0
- /package/{esm → dist/esm}/hyperbeam.js +0 -0
- /package/{esm → dist/esm}/index.js +0 -0
- /package/{esm → dist/esm}/keygen.js +0 -0
- /package/{esm → dist/esm}/lfdb.js +0 -0
- /package/{esm → dist/esm}/lua/aos.wasm +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_1.js +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_1.wasm +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_3.js +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_3.wasm +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_4_32.js +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_4_32.wasm +0 -0
- /package/{esm → dist/esm}/lua/aos2_0_6.wasm +0 -0
- /package/{esm → dist/esm}/lua/apm.lua +0 -0
- /package/{esm → dist/esm}/lua/llama.wasm +0 -0
- /package/{esm → dist/esm}/lua/process.wasm +0 -0
- /package/{esm → dist/esm}/lua/sqlite.js +0 -0
- /package/{esm → dist/esm}/lua/sqlite.wasm +0 -0
- /package/{esm → dist/esm}/lua/weavedb_mock.lua +0 -0
- /package/{esm → dist/esm}/lua/weavedrive.lua +0 -0
- /package/{esm → dist/esm}/package.json +0 -0
- /package/{esm → dist/esm}/run.js +0 -0
- /package/{esm → dist/esm}/server.js +0 -0
- /package/{esm → dist/esm}/storage-multi.js +0 -0
- /package/{esm → dist/esm}/tao.js +0 -0
- /package/{esm → dist/esm}/tar.js +0 -0
- /package/{esm → dist/esm}/test.js +0 -0
- /package/{esm → dist/esm}/tgql-d1.js +0 -0
- /package/{esm → dist/esm}/tgql.js +0 -0
- /package/{esm → dist/esm}/toerl.js +0 -0
- /package/{esm → dist/esm}/utils.js +0 -0
- /package/{esm → dist/esm}/wao.js +0 -0
- /package/{esm → dist/esm}/waosm/README.md +0 -0
- /package/{esm → dist/esm}/waosm/waosm.d.ts +0 -0
- /package/{esm → dist/esm}/waosm/waosm.js +0 -0
- /package/{esm → dist/esm}/waosm/waosm_bg.wasm +0 -0
- /package/{esm → dist/esm}/waosm/waosm_bg.wasm.d.ts +0 -0
- /package/{esm → dist/esm}/waosm-node/README.md +0 -0
- /package/{esm → dist/esm}/waosm-node/waosm.d.ts +0 -0
- /package/{esm → dist/esm}/waosm-node/waosm.js +0 -0
- /package/{esm → dist/esm}/waosm-node/waosm_bg.js +0 -0
- /package/{esm → dist/esm}/waosm-node/waosm_bg.wasm +0 -0
- /package/{esm → dist/esm}/waosm-node/waosm_bg.wasm.d.ts +0 -0
- /package/{esm → dist/esm}/waosm-node/waosm_bg.wasm.js +0 -0
- /package/{esm → dist/esm}/waosm-node.js +0 -0
- /package/{esm → dist/esm}/war.js +0 -0
- /package/{esm → dist/esm}/weavedrive.js +0 -0
- /package/{esm → dist/esm}/web.js +0 -0
- /package/{esm → dist/esm}/workspace/.mcp.json +0 -0
- /package/{esm → dist/esm}/workspace/CLAUDE.md +0 -0
- /package/{esm → dist/esm}/workspace/README.md +0 -0
- /package/{esm → dist/esm}/workspace/dashboard/index.html +0 -0
- /package/{esm → dist/esm}/workspace/dashboard/package.json +0 -0
- /package/{esm/workspace/dashboard/public/favicon.png → dist/esm/workspace/dashboard/public/favicon.ico} +0 -0
- /package/{esm → dist/esm}/workspace/dashboard/server.js +0 -0
- /package/{esm → dist/esm}/workspace/dashboard/src/App.jsx +0 -0
- /package/{cjs/workspace/frontend → dist/esm/workspace/dashboard}/src/main.jsx +0 -0
- /package/{esm → dist/esm}/workspace/dashboard/vite.config.js +0 -0
- /package/{esm → dist/esm}/workspace/package.json +0 -0
- /package/{postinstall.cjs → dist/postinstall.cjs} +0 -0
- /package/{esm → src}/workspace/dashboard/src/main.jsx +0 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import _Arweave from "arweave"
|
|
2
|
+
const Arweave = _Arweave.default ?? _Arweave
|
|
3
|
+
import { Bundle } from "arbundles"
|
|
4
|
+
import { compress, decompress } from "./compress.js"
|
|
5
|
+
import { last, assoc, is, isNil } from "ramda"
|
|
6
|
+
import { buildTags, tags } from "./utils.js"
|
|
7
|
+
import base64url from "base64url"
|
|
8
|
+
import RemoteAR from "./ar-remote.js"
|
|
9
|
+
|
|
10
|
+
function eq(buf1, buf2, chunkSize = 1024 * 1024) {
|
|
11
|
+
if (buf1.byteLength !== buf2.byteLength) return false
|
|
12
|
+
|
|
13
|
+
const view1 = new Uint8Array(buf1)
|
|
14
|
+
const view2 = new Uint8Array(buf2)
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < buf1.byteLength; i += chunkSize) {
|
|
17
|
+
const slice1 = view1.subarray(i, i + chunkSize)
|
|
18
|
+
const slice2 = view2.subarray(i, i + chunkSize)
|
|
19
|
+
|
|
20
|
+
if (!slice1.every((val, idx) => val === slice2[idx])) return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default class ArMemBase {
|
|
27
|
+
constructor({
|
|
28
|
+
MU_URL,
|
|
29
|
+
CU_URL,
|
|
30
|
+
SU_URL,
|
|
31
|
+
GATEWAY_URL,
|
|
32
|
+
scheduler,
|
|
33
|
+
cache,
|
|
34
|
+
init,
|
|
35
|
+
Waosm,
|
|
36
|
+
variant,
|
|
37
|
+
ar_url,
|
|
38
|
+
} = {}) {
|
|
39
|
+
this.variant = variant
|
|
40
|
+
this.__type__ = "mem"
|
|
41
|
+
this._init = init
|
|
42
|
+
this.Waosm = Waosm
|
|
43
|
+
this.isInit = false
|
|
44
|
+
this.keyInit = false
|
|
45
|
+
this.keys = {}
|
|
46
|
+
this.arweave = Arweave.init()
|
|
47
|
+
this.arweave.transactions.getTransactionAnchor = () => this.getAnchor()
|
|
48
|
+
this.arweave.transactions.getPrice = () => 0
|
|
49
|
+
this.scheduler = scheduler
|
|
50
|
+
this.SU_URL = SU_URL
|
|
51
|
+
this._txCache = new Map()
|
|
52
|
+
this._TX_CACHE_MAX = 200
|
|
53
|
+
this.ar_url = ar_url || null
|
|
54
|
+
this._remote = ar_url ? new RemoteAR(ar_url) : null
|
|
55
|
+
}
|
|
56
|
+
compress(memory) {
|
|
57
|
+
const waosm = new this.Waosm()
|
|
58
|
+
return waosm.compress(memory)
|
|
59
|
+
}
|
|
60
|
+
decompress(memory, size) {
|
|
61
|
+
const waosm = new this.Waosm()
|
|
62
|
+
return waosm.decompress(memory, size)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async owner(di) {
|
|
66
|
+
return base64url.encode(
|
|
67
|
+
Buffer.from(await crypto.subtle.digest("SHA-256", di.rawOwner))
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
getAnchor() {
|
|
71
|
+
if (this._remote) {
|
|
72
|
+
return this._remoteAnchor ?? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
73
|
+
}
|
|
74
|
+
// D1 ready: use lastBlockId scalar (block.id === last tx.id)
|
|
75
|
+
if (this._d1Ready) {
|
|
76
|
+
return this.lastBlockId || "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
77
|
+
}
|
|
78
|
+
// Fallback: use blocks array
|
|
79
|
+
if (this.blocks.length === 0) {
|
|
80
|
+
return "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
81
|
+
}
|
|
82
|
+
const lastBlock = this.blockmap[last(this.blocks)]
|
|
83
|
+
if (!lastBlock) return "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
84
|
+
return last(lastBlock.txs)
|
|
85
|
+
}
|
|
86
|
+
async get(key, field) {
|
|
87
|
+
await this.init()
|
|
88
|
+
if (!field) {
|
|
89
|
+
// Remote AR fallback for height
|
|
90
|
+
if (key === "height" && this._remote && !this[key]) {
|
|
91
|
+
this[key] = await this._remote.getHeight()
|
|
92
|
+
}
|
|
93
|
+
return this[key]
|
|
94
|
+
}
|
|
95
|
+
// Lazy load from storage if not in memory
|
|
96
|
+
if (this[key]?.[field] === undefined && this.db) {
|
|
97
|
+
const val = await this.db.get(`${key}.${field}`)
|
|
98
|
+
if (val !== null) {
|
|
99
|
+
this[key] ??= {}
|
|
100
|
+
if (key === "env" && val) {
|
|
101
|
+
// Try loading memory from R2 first
|
|
102
|
+
if (this.db.r2GetMemory && !val.memory) {
|
|
103
|
+
try {
|
|
104
|
+
const r2mem = await this.db.r2GetMemory(field)
|
|
105
|
+
if (r2mem) {
|
|
106
|
+
val.memory = r2mem
|
|
107
|
+
val.compressed = true
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {}
|
|
110
|
+
}
|
|
111
|
+
// Fallback: memory was stored inline in DO (pre-migration)
|
|
112
|
+
if (val.memory && is(Uint8Array, val.memory)) {
|
|
113
|
+
val.compressed = true
|
|
114
|
+
// Lazy migrate: move inline memory to R2
|
|
115
|
+
if (this.db.r2PutMemory) {
|
|
116
|
+
try {
|
|
117
|
+
await this.db.r2PutMemory(field, val.memory)
|
|
118
|
+
// Remove memory from DO entry to save space
|
|
119
|
+
const meta = { ...val }
|
|
120
|
+
delete meta.memory
|
|
121
|
+
meta._r2_memory = true
|
|
122
|
+
await this.db.put(`${key}.${field}`, meta)
|
|
123
|
+
} catch (e) {}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
this[key][field] = val
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return this[key]?.[field]
|
|
131
|
+
}
|
|
132
|
+
async set(val, key, field) {
|
|
133
|
+
await this.init()
|
|
134
|
+
if (!field) {
|
|
135
|
+
this[key] = val
|
|
136
|
+
if (this.db) await this.db.put(`${key}`, this[key])
|
|
137
|
+
} else {
|
|
138
|
+
this[key] ??= {}
|
|
139
|
+
this[key][field] = val
|
|
140
|
+
if (this.db) {
|
|
141
|
+
if (key === "env") {
|
|
142
|
+
if (val.memory) {
|
|
143
|
+
let memory = val.memory
|
|
144
|
+
try {
|
|
145
|
+
memory = this.compress(val.memory)
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.log(e)
|
|
148
|
+
}
|
|
149
|
+
this[key][field].original_size = val.memory.length
|
|
150
|
+
|
|
151
|
+
// R2 path: store compressed memory in R2, metadata in DO
|
|
152
|
+
if (this.db.r2PutMemory) {
|
|
153
|
+
try {
|
|
154
|
+
await this.db.r2PutMemory(field, memory)
|
|
155
|
+
// Store metadata without memory in DO
|
|
156
|
+
const meta = { ...this[key][field] }
|
|
157
|
+
delete meta.memory
|
|
158
|
+
meta._r2_memory = true
|
|
159
|
+
await this.db.put(`${key}.${field}`, meta)
|
|
160
|
+
} catch (e) {
|
|
161
|
+
// Fallback to inline storage
|
|
162
|
+
await this.db.put(
|
|
163
|
+
`${key}.${field}`,
|
|
164
|
+
assoc("memory", memory, this[key][field])
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
await this.db.put(
|
|
169
|
+
`${key}.${field}`,
|
|
170
|
+
assoc("memory", memory, this[key][field])
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
// Remote CU process — memory lives on satellite, store metadata only
|
|
175
|
+
await this.db.put(`${key}.${field}`, this[key][field])
|
|
176
|
+
}
|
|
177
|
+
} else if (key === "txs" && this._d1Ready) {
|
|
178
|
+
// D1 + R2 are authoritative for tx metadata, skip DO storage
|
|
179
|
+
this._txCache.set(field, val)
|
|
180
|
+
} else {
|
|
181
|
+
await this.db.put(`${key}.${field}`, this[key][field])
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Get all field keys for a given prefix (e.g. all process IDs under "env")
|
|
187
|
+
async getFieldKeys(key) {
|
|
188
|
+
await this.init()
|
|
189
|
+
if (!this.db) return Object.keys(this[key] ?? {})
|
|
190
|
+
const stored = await this.db.getKeys({ start: key + ".", end: key + "0" })
|
|
191
|
+
const dbKeys = (stored || []).map(k => k.split(".")[1]).filter(Boolean)
|
|
192
|
+
const memKeys = Object.keys(this[key] ?? {})
|
|
193
|
+
return [...new Set([...memKeys, ...dbKeys])]
|
|
194
|
+
}
|
|
195
|
+
initSync() {
|
|
196
|
+
this.items = {}
|
|
197
|
+
this.addrmap = {}
|
|
198
|
+
this.txs = {}
|
|
199
|
+
this.blocks = []
|
|
200
|
+
this.blockmap = {}
|
|
201
|
+
this.env = {}
|
|
202
|
+
this.modules = {}
|
|
203
|
+
this.modmap = {}
|
|
204
|
+
this.msgs = {}
|
|
205
|
+
|
|
206
|
+
this.wasms = {
|
|
207
|
+
"ISShJH1ij-hPPt9St5UFFr_8Ys3Kj5cyg7zrMGt7H9s": {
|
|
208
|
+
file: "aos2_0_6",
|
|
209
|
+
variant: "ao.TN.1",
|
|
210
|
+
},
|
|
211
|
+
"WASM32-D8q2OmZ4Mok00sD2Y_6SYEQ7Hjx-6VZ_jl3g": {
|
|
212
|
+
file: "aos2_0_4_32",
|
|
213
|
+
format: "wasm32-unknown-emscripten4",
|
|
214
|
+
},
|
|
215
|
+
"JArYBF-D8q2OmZ4Mok00sD2Y_6SYEQ7Hjx-6VZ_jl3g": { file: "aos2_0_3" },
|
|
216
|
+
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": { file: "aos2_0_1" },
|
|
217
|
+
ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw: { file: "sqlite" },
|
|
218
|
+
}
|
|
219
|
+
for (const k in this.wasms) {
|
|
220
|
+
this.wasms[k].format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
221
|
+
this.modules[this.wasms[k].file] = k
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let txs = []
|
|
225
|
+
for (const key in this.wasms) {
|
|
226
|
+
const w = this.wasms[key]
|
|
227
|
+
txs.push(key)
|
|
228
|
+
this.txs[key] = {
|
|
229
|
+
id: key,
|
|
230
|
+
block: 0,
|
|
231
|
+
owner: this.scheduler || "",
|
|
232
|
+
tags: buildTags(null, {
|
|
233
|
+
"Data-Protocol": "ao",
|
|
234
|
+
Variant: w.variant ?? this.variant ?? "ao.TN.1",
|
|
235
|
+
Type: "Module",
|
|
236
|
+
"Module-Format":
|
|
237
|
+
w.format ?? "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
238
|
+
"Input-Encoding": w.input_encoding ?? "JSON-V1",
|
|
239
|
+
"Output-Encoding": w.output_encoding ?? "JSON-V1",
|
|
240
|
+
"Memory-Limit": w.memory_limit ?? "1-gb",
|
|
241
|
+
"Compute-Limit": w.compute_limit ?? "9000000000000",
|
|
242
|
+
Extension: w.extension ?? "WeaveDrive",
|
|
243
|
+
}),
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (this.scheduler && this.SU_URL) {
|
|
247
|
+
const key = this.scheduler
|
|
248
|
+
txs.push(key)
|
|
249
|
+
this.addrmap[this.scheduler] = { address: this.scheduler }
|
|
250
|
+
this.txs[key] = {
|
|
251
|
+
id: key,
|
|
252
|
+
block: 0,
|
|
253
|
+
owner: this.scheduler,
|
|
254
|
+
tags: buildTags(null, {
|
|
255
|
+
"Data-Protocol": "ao",
|
|
256
|
+
Variant: this.variant ?? "ao.TN.1",
|
|
257
|
+
Type: "Scheduler-Location",
|
|
258
|
+
Url: this.SU_URL,
|
|
259
|
+
"Time-To-Live": 1000 * 60 * 60 * 24 * 365 * 10,
|
|
260
|
+
}),
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
this.blockmap["0"] = {
|
|
264
|
+
txs,
|
|
265
|
+
timestamp: Date.now(),
|
|
266
|
+
height: 1,
|
|
267
|
+
previous: "",
|
|
268
|
+
id: "0",
|
|
269
|
+
}
|
|
270
|
+
this.blocks.push("0")
|
|
271
|
+
this.lastBlockId = "0"
|
|
272
|
+
this.height = 1
|
|
273
|
+
}
|
|
274
|
+
async putAll(key) {
|
|
275
|
+
for (let k in this[key]) await this.set(this[key][k], key, k)
|
|
276
|
+
}
|
|
277
|
+
async init() {
|
|
278
|
+
if (this.isInit) return
|
|
279
|
+
this.isInit = true
|
|
280
|
+
if (typeof this._init === "function") await this._init()
|
|
281
|
+
if (this.db) {
|
|
282
|
+
let fresh = true
|
|
283
|
+
// Probe D1 readiness: binding exists AND schema is applied
|
|
284
|
+
this._d1Ready = false
|
|
285
|
+
if (this.db.d1) {
|
|
286
|
+
try {
|
|
287
|
+
await this.db.d1.prepare("SELECT 1 FROM blocks LIMIT 0").all()
|
|
288
|
+
this._d1Ready = true
|
|
289
|
+
} catch {}
|
|
290
|
+
}
|
|
291
|
+
// Load scalars: always load height + blocks; also lastBlockId when D1 ready
|
|
292
|
+
for (const v of ["height", "blocks"]) {
|
|
293
|
+
const val = await this.db.get(v)
|
|
294
|
+
if (val !== null) {
|
|
295
|
+
this[v] = val
|
|
296
|
+
fresh = false
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (this._d1Ready) {
|
|
300
|
+
const lbid = await this.db.get("lastBlockId")
|
|
301
|
+
if (lbid !== null) {
|
|
302
|
+
this.lastBlockId = lbid
|
|
303
|
+
fresh = false
|
|
304
|
+
}
|
|
305
|
+
// Migration: derive lastBlockId from blocks if not yet stored
|
|
306
|
+
if (this.lastBlockId === "0" && this.blocks.length > 0) {
|
|
307
|
+
this.lastBlockId = this.blocks[this.blocks.length - 1]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Always load blocks + blockmap so the O(n) scan fallback in tgql.js works.
|
|
311
|
+
// Skip eagerly loading txs when D1 is ready (D1 is authoritative for tx queries).
|
|
312
|
+
const collections = this._d1Ready
|
|
313
|
+
? ["items", "env", "modules", "wasms", "addrmap", "blockmap", "modmap", "msgs"]
|
|
314
|
+
: ["items", "txs", "env", "modules", "wasms", "addrmap", "blockmap", "modmap", "msgs"]
|
|
315
|
+
for (const v of collections) {
|
|
316
|
+
this[v] ??= {}
|
|
317
|
+
const items = await this.db.getKeys({ start: v, end: v + "a" })
|
|
318
|
+
if (items?.length) fresh = false
|
|
319
|
+
for (const v2 of items || []) {
|
|
320
|
+
const key = v2.split(".")[0]
|
|
321
|
+
const field = v2.split(".")[1]
|
|
322
|
+
if (key === v && field) {
|
|
323
|
+
if (key === "env") {
|
|
324
|
+
let v3 = await this.db.get(v2)
|
|
325
|
+
if (v3 && is(Uint8Array, v3.memory)) {
|
|
326
|
+
v3.compressed = true
|
|
327
|
+
}
|
|
328
|
+
// If memory was offloaded to R2, fetch it
|
|
329
|
+
if (v3 && !v3.memory && v3._r2_memory && this.db.r2GetMemory) {
|
|
330
|
+
try {
|
|
331
|
+
const r2mem = await this.db.r2GetMemory(field)
|
|
332
|
+
if (r2mem) {
|
|
333
|
+
v3.memory = r2mem
|
|
334
|
+
v3.compressed = true
|
|
335
|
+
}
|
|
336
|
+
} catch (e) {}
|
|
337
|
+
}
|
|
338
|
+
this[v][field] = v3
|
|
339
|
+
} else {
|
|
340
|
+
this[v][field] = await this.db.get(v2)
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (fresh) {
|
|
346
|
+
// First boot: persist initial state from initSync()
|
|
347
|
+
const scalarKeys = this._d1Ready ? ["height", "blocks", "lastBlockId"] : ["height", "blocks"]
|
|
348
|
+
for (const v of scalarKeys) await this.set(this[v], v)
|
|
349
|
+
for (const v of ["modules", "wasms", "addrmap", "blockmap", "txs"]) {
|
|
350
|
+
await this.putAll(v)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// Seed D1 with initial data when D1 is empty, and ensure seed txs
|
|
354
|
+
// from initSync() are present even when D1 already has data
|
|
355
|
+
if (this._d1Ready && this.db?.d1WriteBlock) {
|
|
356
|
+
try {
|
|
357
|
+
const probe = await this.db.d1.prepare("SELECT COUNT(*) as cnt FROM blocks").first()
|
|
358
|
+
if (!probe || probe.cnt === 0) {
|
|
359
|
+
for (const bId of this.blocks) {
|
|
360
|
+
const block = this.blockmap[bId]
|
|
361
|
+
if (block) await this.db.d1WriteBlock(block)
|
|
362
|
+
}
|
|
363
|
+
for (const txId in this.txs) {
|
|
364
|
+
const tx = this.txs[txId]
|
|
365
|
+
if (tx) await this.db.d1WriteTx(tx, tx.block_id ?? "0", tx.block ?? 1)
|
|
366
|
+
}
|
|
367
|
+
for (const addr in this.addrmap) {
|
|
368
|
+
await this.db.d1WriteAddrmap(addr, this.addrmap[addr])
|
|
369
|
+
}
|
|
370
|
+
for (const name in this.modules) {
|
|
371
|
+
await this.db.d1WriteModule(name, this.modules[name])
|
|
372
|
+
}
|
|
373
|
+
for (const id in this.wasms) {
|
|
374
|
+
await this.db.d1WriteWasm(id, this.wasms[id])
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
// D1 has data but seed txs from initSync() might be missing
|
|
378
|
+
// (e.g. Scheduler-Location added after initial boot)
|
|
379
|
+
const txKeys = Object.keys(this.txs)
|
|
380
|
+
for (const txId of txKeys) {
|
|
381
|
+
const existing = await this.db.d1.prepare("SELECT 1 FROM txs WHERE id = ?").bind(txId).first()
|
|
382
|
+
if (!existing) {
|
|
383
|
+
const tx = this.txs[txId]
|
|
384
|
+
if (tx) await this.db.d1WriteTx(tx, tx.block_id ?? "0", tx.block ?? 1)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
for (const addr in this.addrmap) {
|
|
388
|
+
const existing = await this.db.d1.prepare("SELECT 1 FROM addrmap WHERE address = ?").bind(addr).first()
|
|
389
|
+
if (!existing) await this.db.d1WriteAddrmap(addr, this.addrmap[addr])
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
} catch (e) {
|
|
393
|
+
console.error("[ArMem] D1 seed/backfill error:", e?.message || e)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
for (const v of ["height", "blocks"]) await this.set(this[v], v)
|
|
398
|
+
for (const v of ["modules", "wasms", "addrmap", "blockmap"]) {
|
|
399
|
+
await this.putAll(v)
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async getTx(id) {
|
|
404
|
+
// Check LRU cache first
|
|
405
|
+
if (this._txCache.has(id)) return this._txCache.get(id)
|
|
406
|
+
// Check in-memory txs (always available for non-DB path, seed data for DB path)
|
|
407
|
+
let tx = this.txs[id] ?? null
|
|
408
|
+
// Try D1 first (indexed lookup), then DO storage fallback
|
|
409
|
+
if (!tx && this.db) {
|
|
410
|
+
await this.init()
|
|
411
|
+
if (this.db.d1GetTxById) {
|
|
412
|
+
try { tx = await this.db.d1GetTxById(id) } catch (e) {
|
|
413
|
+
if (!e?.message?.includes("no such table")) throw e
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (!tx) {
|
|
417
|
+
const val = await this.db.get(`txs.${id}`)
|
|
418
|
+
if (val !== null) tx = val
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// Remote AR fallback — standalone units fetch from main AR
|
|
422
|
+
if (!tx && this._remote) {
|
|
423
|
+
tx = await this._remote.getTx(id)
|
|
424
|
+
}
|
|
425
|
+
if (isNil(tx)) return null
|
|
426
|
+
// Handle bundle references (DO stores {bundle: parentId} for bundled items)
|
|
427
|
+
if (tx.bundle) {
|
|
428
|
+
try {
|
|
429
|
+
let bundleTx = this.txs[tx.bundle] ?? null
|
|
430
|
+
if (!bundleTx && this.db) {
|
|
431
|
+
bundleTx = await this.db.get(`txs.${tx.bundle}`)
|
|
432
|
+
}
|
|
433
|
+
if (bundleTx) {
|
|
434
|
+
// Lazy-load bundle tx data from R2 if needed
|
|
435
|
+
if (!bundleTx.data && this.db?.r2GetTxData) {
|
|
436
|
+
bundleTx.data = await this.db.r2GetTxData(tx.bundle)
|
|
437
|
+
}
|
|
438
|
+
if (bundleTx.data) {
|
|
439
|
+
let bdata = bundleTx.data
|
|
440
|
+
if (typeof bdata === "string") {
|
|
441
|
+
const b64 = bdata.replace(/-/g, "+").replace(/_/g, "/")
|
|
442
|
+
bdata = Buffer.from(b64, "base64")
|
|
443
|
+
}
|
|
444
|
+
let bundle = new Bundle(bdata)
|
|
445
|
+
for (let di of bundle.items) {
|
|
446
|
+
if (id === di.id) {
|
|
447
|
+
const data = di.data
|
|
448
|
+
const data_size = Buffer.byteLength(di.rawData).toString()
|
|
449
|
+
let data_type = ""
|
|
450
|
+
for (const t of di.tags)
|
|
451
|
+
if (t.name === "Content-Type") data_type = t.value
|
|
452
|
+
const owner = await this.owner(di)
|
|
453
|
+
tx = {
|
|
454
|
+
_data: { size: data_size, type: data_type },
|
|
455
|
+
anchor: di.anchor,
|
|
456
|
+
signature: di.signature,
|
|
457
|
+
recipient: di.target,
|
|
458
|
+
id: await di.id,
|
|
459
|
+
item: di,
|
|
460
|
+
owner,
|
|
461
|
+
tags: di.tags,
|
|
462
|
+
data,
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
} catch (e) {}
|
|
469
|
+
}
|
|
470
|
+
// Lazy-load data from R2 if not present
|
|
471
|
+
if (tx && !tx.data && this.db?.r2GetTxData) {
|
|
472
|
+
tx.data = await this.db.r2GetTxData(tx.id ?? id)
|
|
473
|
+
}
|
|
474
|
+
// Add to LRU cache
|
|
475
|
+
if (tx) {
|
|
476
|
+
if (this._txCache.size >= this._TX_CACHE_MAX) {
|
|
477
|
+
this._txCache.delete(this._txCache.keys().next().value)
|
|
478
|
+
}
|
|
479
|
+
this._txCache.set(id, tx)
|
|
480
|
+
}
|
|
481
|
+
return tx
|
|
482
|
+
}
|
|
483
|
+
async getWasm(module) {
|
|
484
|
+
let mod = module ?? this.modules.aos2_0_1
|
|
485
|
+
if (!mod) throw Error("module not found")
|
|
486
|
+
let format = null
|
|
487
|
+
// Lazy load wasm entry if needed
|
|
488
|
+
if (!this.wasms[mod] && this.db) {
|
|
489
|
+
const val = await this.db.get(`wasms.${mod}`)
|
|
490
|
+
if (val !== null) this.wasms[mod] = val
|
|
491
|
+
}
|
|
492
|
+
let _wasm = await this.wasms[mod]
|
|
493
|
+
let wasm = _wasm?.data
|
|
494
|
+
if (!wasm) {
|
|
495
|
+
if (_wasm?.file) {
|
|
496
|
+
wasm = await this._getWasm(this.wasms[mod].file)
|
|
497
|
+
format = _wasm.format
|
|
498
|
+
} else {
|
|
499
|
+
// Try R2/KV cache for wasm binary
|
|
500
|
+
if (this.db?.r2GetWasm) {
|
|
501
|
+
try { wasm = await this.db.r2GetWasm(mod) } catch (e) {}
|
|
502
|
+
}
|
|
503
|
+
// Remote AR fallback for wasm binary
|
|
504
|
+
if (!wasm && this._remote) {
|
|
505
|
+
const remoteData = await this._remote.data(mod)
|
|
506
|
+
if (remoteData) {
|
|
507
|
+
wasm = remoteData instanceof Uint8Array ? remoteData : Buffer.from(remoteData, "base64")
|
|
508
|
+
format = _wasm?.format
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (!wasm) {
|
|
512
|
+
const tx = await this.getTx(mod)
|
|
513
|
+
if (tx) {
|
|
514
|
+
wasm = Buffer.from(tx.data, "base64")
|
|
515
|
+
format = tags(tx.tags)["Module-Format"]
|
|
516
|
+
// Cache to R2 for future reads
|
|
517
|
+
if (this.db?.r2PutWasm) {
|
|
518
|
+
try { await this.db.r2PutWasm(mod, wasm) } catch (e) {}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
format = _wasm?.format
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
} else format = _wasm.format
|
|
526
|
+
format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
527
|
+
return { format, mod, wasm }
|
|
528
|
+
}
|
|
529
|
+
}
|
package/src/armem-cf.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { cfWasmReady } from "./cf-env.js"
|
|
2
|
+
import sqlite from "./lua/sqlite.js"
|
|
3
|
+
import aos2_0_3 from "./lua/aos2_0_3.js"
|
|
4
|
+
import aos2_0_1 from "./lua/aos2_0_1.js"
|
|
5
|
+
import aos2_0_4_32 from "./lua/aos2_0_4_32.js"
|
|
6
|
+
import Base from "./armem-base.js"
|
|
7
|
+
import StorageMulti from "./storage-multi.js"
|
|
8
|
+
import dodb from "./dodb.js"
|
|
9
|
+
import { initSync, Waosm } from "./waosm/waosm.js"
|
|
10
|
+
import wasmModule from "./waosm/waosm_bg.wasm"
|
|
11
|
+
|
|
12
|
+
// Import .wasm files — wrangler pre-compiles them to WebAssembly.Module
|
|
13
|
+
import aos2_0_1_mod from "./lua/aos2_0_1.wasm"
|
|
14
|
+
import aos2_0_3_mod from "./lua/aos2_0_3.wasm"
|
|
15
|
+
import aos2_0_4_32_mod from "./lua/aos2_0_4_32.wasm"
|
|
16
|
+
import aos2_0_6_mod from "./lua/aos2_0_6.wasm"
|
|
17
|
+
import sqlite_mod from "./lua/sqlite.wasm"
|
|
18
|
+
|
|
19
|
+
const wasm = { sqlite, aos2_0_3, aos2_0_1, aos2_0_4_32 }
|
|
20
|
+
|
|
21
|
+
const precompiled = {
|
|
22
|
+
aos2_0_1: aos2_0_1_mod,
|
|
23
|
+
aos2_0_3: aos2_0_3_mod,
|
|
24
|
+
aos2_0_4_32: aos2_0_4_32_mod,
|
|
25
|
+
aos2_0_6: aos2_0_6_mod,
|
|
26
|
+
sqlite: sqlite_mod,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let wasmReady = false
|
|
30
|
+
function cfInit() {
|
|
31
|
+
if (wasmReady) return
|
|
32
|
+
wasmReady = true
|
|
33
|
+
initSync({ module: wasmModule })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class ArMem extends Base {
|
|
37
|
+
constructor(args = {}) {
|
|
38
|
+
super({ ...args, init: cfInit, Waosm })
|
|
39
|
+
if (args.storage) {
|
|
40
|
+
// Use StorageMulti when D1/R2/KV bindings are available
|
|
41
|
+
if (args.d1 || args.r2 || args.kv) {
|
|
42
|
+
this.db = new StorageMulti({
|
|
43
|
+
storage: args.storage,
|
|
44
|
+
d1: args.d1 || null,
|
|
45
|
+
r2: args.r2 || null,
|
|
46
|
+
kv: args.kv || null,
|
|
47
|
+
})
|
|
48
|
+
} else {
|
|
49
|
+
this.db = dodb(args.storage)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this.initSync()
|
|
53
|
+
}
|
|
54
|
+
async _getWasm(file) {
|
|
55
|
+
// Queue the pre-compiled WebAssembly.Module so the patched
|
|
56
|
+
// WebAssembly.instantiate in cf-env.js can intercept the call.
|
|
57
|
+
const mod = precompiled[file]
|
|
58
|
+
if (mod) cfWasmReady(mod)
|
|
59
|
+
// Return the buffer — emscripten's normal loading path proceeds,
|
|
60
|
+
// but our patched WebAssembly.instantiate swaps the pre-compiled module.
|
|
61
|
+
if (wasm[file]) return Buffer.from(wasm[file], "base64")
|
|
62
|
+
// For modules without a base64 JS file, return a dummy buffer.
|
|
63
|
+
// The patched instantiate will use the pre-compiled module anyway.
|
|
64
|
+
if (mod) return new Uint8Array(1)
|
|
65
|
+
throw new Error(`WASM module not found: ${file}`)
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/armem-web.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import sqlite from "./lua/sqlite.js"
|
|
2
|
+
import aos2_0_3 from "./lua/aos2_0_3.js"
|
|
3
|
+
import aos2_0_1 from "./lua/aos2_0_1.js"
|
|
4
|
+
import aos2_0_4_32 from "./lua/aos2_0_4_32.js"
|
|
5
|
+
import Base from "./armem-base.js"
|
|
6
|
+
import db from "./lfdb.js"
|
|
7
|
+
import init, { Waosm } from "./waosm/waosm.js"
|
|
8
|
+
const wasm = { sqlite, aos2_0_3, aos2_0_1, aos2_0_4_32 }
|
|
9
|
+
|
|
10
|
+
export default class ArMem extends Base {
|
|
11
|
+
constructor(args = {}) {
|
|
12
|
+
super({ ...args, init, Waosm })
|
|
13
|
+
this.db = db(this, args.cache)
|
|
14
|
+
this.initSync()
|
|
15
|
+
}
|
|
16
|
+
async _getWasm(file) {
|
|
17
|
+
return Buffer.from(wasm[file], "base64")
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/armem.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Arweave from "arweave"
|
|
2
|
+
import { last } from "ramda"
|
|
3
|
+
import { tags, buildTags, dirname } from "./utils.js"
|
|
4
|
+
import { open } from "lmdb"
|
|
5
|
+
import { readFileSync } from "fs"
|
|
6
|
+
import { resolve } from "path"
|
|
7
|
+
import Base from "./armem-base.js"
|
|
8
|
+
import { Waosm } from "./waosm-node.js"
|
|
9
|
+
import dodb from "./dodb.js"
|
|
10
|
+
|
|
11
|
+
export default class ArMem extends Base {
|
|
12
|
+
constructor(args = {}) {
|
|
13
|
+
const { cache, storage } = args
|
|
14
|
+
super({ ...args, Waosm })
|
|
15
|
+
if (storage) {
|
|
16
|
+
this.db = dodb(storage)
|
|
17
|
+
} else if (cache) {
|
|
18
|
+
this.db = open({ path: cache, compression: true })
|
|
19
|
+
}
|
|
20
|
+
this.initSync()
|
|
21
|
+
}
|
|
22
|
+
async _getWasm(file) {
|
|
23
|
+
const __dirname = await dirname()
|
|
24
|
+
return readFileSync(resolve(__dirname, `lua/${file}.wasm`))
|
|
25
|
+
}
|
|
26
|
+
}
|