diff --git a/examples/simple-counter/.wrangler/state/v3/do/itty-durable-simple-counter-Counter/d40e9dba971cfb1783256627c4159679eb852b950de2f31e6323d02d8e9434d6.sqlite b/examples/simple-counter/.wrangler/state/v3/do/itty-durable-simple-counter-Counter/d40e9dba971cfb1783256627c4159679eb852b950de2f31e6323d02d8e9434d6.sqlite new file mode 100644 index 0000000..898906e Binary files /dev/null and b/examples/simple-counter/.wrangler/state/v3/do/itty-durable-simple-counter-Counter/d40e9dba971cfb1783256627c4159679eb852b950de2f31e6323d02d8e9434d6.sqlite differ diff --git a/examples/simple-counter/package.json b/examples/simple-counter/package.json index 457a203..47e231b 100644 --- a/examples/simple-counter/package.json +++ b/examples/simple-counter/package.json @@ -6,12 +6,7 @@ "scripts": {}, "author": "Kevin Whitley ", "license": "MIT", - "devDependencies": { - "esbuild": "^0.11.11", - "prettier": "^2.2.1" - }, "dependencies": { - "itty-router": "^2.5.0", - "itty-router-extras": "^0.4.2" + "itty-router": "^5.0.4" } } diff --git a/examples/simple-counter/src/Counter.js b/examples/simple-counter/src/Counter.js index d9d1707..572168b 100644 --- a/examples/simple-counter/src/Counter.js +++ b/examples/simple-counter/src/Counter.js @@ -6,27 +6,7 @@ export class Counter extends createDurable({ autoReturn: true, autoPersist: true this.counter = 0 } - getId() { - return this.state.id.toString() - } - - getState() { - return this.state - } - increment() { this.counter++ } - - set(prop, value) { - this[prop] = value - } - - onLoad() { - this.loaded = true - } - - add(a, b) { - return Number(a) + Number(b) - } } diff --git a/examples/simple-counter/src/index.js b/examples/simple-counter/src/index.js index 0df2bf4..7e7403f 100644 --- a/examples/simple-counter/src/index.js +++ b/examples/simple-counter/src/index.js @@ -1,59 +1,27 @@ import { error, json, - missing, StatusError, text, - ThrowableRouter, + AutoRouter, withParams, -} from 'itty-router-extras' +} from 'itty-router' import { withDurables } from '../../../src' // from 'itty-durable' // export durable object class, per spec export { Counter } from './Counter' // create a basic router -const router = ThrowableRouter({ base: '/' }) +const router = AutoRouter({ + before: [withDurables()], +}) router - // add upstream middleware - .get('*', withDurables()) - - // get get the durable itself... returns JSON Response, so no need to wrap - .get('/', ({ Counter }) => Counter.get('test').toJSON()) - - // example route with multiple calls to DO - .get('/do-stuff', - async ({ Counter }) => { - const counter = Counter.get('test') - - // then we fire some methods on the durable... these could all be done separately. - await Promise.all([ - counter.increment(), - counter.increment(), - counter.increment(), - ]) - - // all instance calls return a promise to a JSON-formatted Response - // unless withDurables({ parse: true }) is used - return counter.toJSON() - } - ) - - // will pass on requests to the durable... (e.g. /add/3/4 => 7) - .get('/:action/:a?/:b?', withParams, - ({ Counter, action, a, b }) => Counter.get('test')[action](a, b) - ) - - .get('*', request => text(request.url)) - - // all else gets a 404 - .all('*', () => missing('Are you sure about that?')) + .get('/counter/:name', ({ Counter, name }) => Counter.get(name).toJSON()) + .get('/counter/:name/increment', ({ Counter, name }) => Counter.get(name).increment()) // CF ES6 module syntax -export default { - fetch: router.handle -} +export default { ...router } /* diff --git a/examples/simple-counter/yarn.lock b/examples/simple-counter/yarn.lock index 3498220..ddfdaf5 100644 --- a/examples/simple-counter/yarn.lock +++ b/examples/simple-counter/yarn.lock @@ -2,30 +2,7 @@ # yarn lockfile v1 -esbuild@^0.11.11: - version "0.11.23" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.11.23.tgz#c42534f632e165120671d64db67883634333b4b8" - integrity sha512-iaiZZ9vUF5wJV8ob1tl+5aJTrwDczlvGP0JoMmnpC2B0ppiMCu8n8gmy5ZTGl5bcG081XBVn+U+jP+mPFm5T5Q== - -itty-durable@=0.4.0-next.1: - version "0.4.0-next.1" - resolved "https://registry.yarnpkg.com/itty-durable/-/itty-durable-0.4.0-next.1.tgz#d122e1495dfccd167271864040e093be4d7d9a3a" - integrity sha512-ht/nNokztjKoUsQQoxVdlSDRZRPOIqfQgSmzpaNmtUfxTGQZkYdwYqoq18YhEJGkoC0OIMpz/dwEophfcBv4SA== - dependencies: - itty-router "^2.6.1" - itty-router-extras "^0.4.2" - -itty-router-extras@^0.4.2: - version "0.4.2" - resolved "https://registry.yarnpkg.com/itty-router-extras/-/itty-router-extras-0.4.2.tgz#e46891ebea63f09ada74603649d8a6c4ce0c5df7" - integrity sha512-ppHaBzcTXs7idFSDISehG+8kif2/4aqLCfyY/Y/uIZv79sfEfNmTq9G+rDeqblun/VZRBiXZD8ztYmMS8EOsKw== - -itty-router@^2.5.0, itty-router@^2.6.1: - version "2.6.1" - resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-2.6.1.tgz#eecb59fa25b5f6f519276cc5bcaaa1cb341d5fee" - integrity sha512-l9gxWe5TOLUESYnBn85Jxd6tIZLWdRX5YKkHIBfSgbNQ7UFPNUGuWihRV+LlEbfJJIzgLmhwAbaWRi5yWJm8kg== - -prettier@^2.2.1: - version "2.7.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" - integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== +itty-router@^5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-5.0.4.tgz#d9e9397b43a1d11f3ea6c5af8abbf44d948fc382" + integrity sha512-5YptFbHqxpnYnKitKPA5pfleq2HufZGcM/xWRSa4arMHdCLfiuJ276vQD3NGOuFPJEFqNlgKtgn9BKIMuImsjQ== diff --git a/package.json b/package.json index f800b00..e4bbdbb 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "eslint": "^8.41.0", "eslint-plugin-jest": "^27.2.1", "isomorphic-fetch": "^3.0.0", - "itty-router": "^4.0.9", "jsdom": "^22.1.0", "rimraf": "^5.0.1", "typescript": "^5.0.4", @@ -45,6 +44,6 @@ "yarn-release": "^1.10.5" }, "peerDependencies": { - "itty-router": "^4.0.9" + "itty-router": "^5.0.4" } } diff --git a/src/itty-durable.js b/src/itty-durable.js index 47b257c..d5441be 100644 --- a/src/itty-durable.js +++ b/src/itty-durable.js @@ -135,7 +135,7 @@ export const createDurable = (options = {}) => { // we pass off the request to the internal router const response = await this.state.router - .handle(request, ...args) + .fetch(request, ...args) .catch(onError) // if persistOnChange is true, we persist on every response diff --git a/yarn.lock b/yarn.lock index 2ef8d70..b3598ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1714,10 +1714,10 @@ istanbul-reports@^3.1.4: html-escaper "^2.0.0" istanbul-lib-report "^3.0.0" -itty-router@^4.0.9: - version "4.0.9" - resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-4.0.9.tgz#d725ff3868ef104ddf33cd5484804e43345f8ff0" - integrity sha512-al8PIAJEWuWZcg4iwLcLiF7R9njsIQxrT27ik2Vfp1Mi5CBEVr1BDKbA1xpOyqkRbj9cCBQiTRpLIKnNO2YKlQ== +itty-router@^5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-5.0.4.tgz#d9e9397b43a1d11f3ea6c5af8abbf44d948fc382" + integrity sha512-5YptFbHqxpnYnKitKPA5pfleq2HufZGcM/xWRSa4arMHdCLfiuJ276vQD3NGOuFPJEFqNlgKtgn9BKIMuImsjQ== jackspeak@^2.0.3: version "2.2.1"