Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions crates/ct_worker/shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import shim, {
Sequencer, Batcher, Cleaner, __wbg_reset_state,
} from "./build/worker/shim.mjs";

// no-op worker entrypoint for now
const WorkerEntrypointProxy = new Proxy(shim, {});

const DOProxy = new Proxy(Sequencer, {
construct(target, args) {
const state = args[0] // get state
// const env = args[1] // get env
try {
const instance = new target(...args);

return new Proxy(instance, {
get(target, prop, receiver) {
const original = Reflect.get(target, prop, receiver);
// Check if the property is a function
if (typeof original === 'function') {
return new Proxy(original, {
async apply(target, thisArg, argArray) {
try {
const resultPromise = await target.bind(thisArg, ...argArray)();
// const resultPromise = await target.bind(thisArg, ...argArray)()
return resultPromise;
} catch (e) {
if (e.message == "memory access out of bounds") {
console.error(e)
__wbg_reset_state();
state.abort("Call to DO panicked, force-restarting DO")
return new Response("Worker panicked... restarting DO")
}
throw e;
}


}
});
}
return original; // Return the property directly if it's not a function
}
});

} catch (err) {
__wbg_reset_state();
state.abort("Constructor for DO panicked, force-restarting DO")
}
},
});

export { DOProxy as Sequencer, Batcher, Cleaner, WorkerEntrypointProxy as default };
2 changes: 1 addition & 1 deletion crates/ct_worker/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "static-ct",
"main": "build/worker/shim.mjs",
"main": "./shim.js",
"compatibility_date": "2025-09-25",
"workers_dev": false,
"build": {
Expand Down