Skip to content

Commit

Permalink
updates peer dep, and switches itty-router internal to use router.fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Apr 2, 2024
1 parent 86c8f01 commit 3a8b3ac
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 100 deletions.
Binary file not shown.
7 changes: 1 addition & 6 deletions examples/simple-counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
"scripts": {},
"author": "Kevin Whitley <[email protected]>",
"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"
}
}
20 changes: 0 additions & 20 deletions examples/simple-counter/src/Counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
48 changes: 8 additions & 40 deletions examples/simple-counter/src/index.js
Original file line number Diff line number Diff line change
@@ -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 }

/*
Expand Down
31 changes: 4 additions & 27 deletions examples/simple-counter/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@
"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",
"vitest": "^0.31.4",
"yarn-release": "^1.10.5"
},
"peerDependencies": {
"itty-router": "^4.0.9"
"itty-router": "^5.0.4"
}
}
2 changes: 1 addition & 1 deletion src/itty-durable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3a8b3ac

Please sign in to comment.