Skip to content

Commit

Permalink
released v3.0.0-next.0 - testing import
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Jun 3, 2024
1 parent 704a085 commit bb00fe3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/counter/Counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IttyDurable } from '../../dist'
import { IttyDurable } from '../../dist/index.mjs'

export class Counter extends IttyDurable {
value = 0
Expand Down
4 changes: 2 additions & 2 deletions examples/counter/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AutoRouter } from 'itty-router'
import { AutoRouter } from './node_modules/itty-router'
export { Counter } from './Counter'
import { withDO } from '../../dist'
import { withDO } from '../../dist/index.mjs'

const router = AutoRouter({
before: [withDO],
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "itty-durable",
"description": "Easier to use Durable Objects.",
"version": "2.4.1",
"version": "3.0.0-next.0",
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
Expand All @@ -17,8 +17,8 @@
"lint": "yarn run eslint src",
"test": "vitest run --coverage",
"verify": "echo 'verifying module...' && yarn build && yarn test",
"prerelease": "yarn verify",
"prerelease:next": "yarn verify",
"Xprerelease": "yarn verify",
"Xprerelease:next": "yarn verify",
"prebuild": "rimraf dist && mkdir dist",
"build": "rollup -c",
"release": "release --tag --push --patch --src=dist",
Expand Down
3 changes: 3 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default async () => {
// export base files
return files.map(file => ({
input: file.path,
external: [
'cloudflare:workers'
],
output: [
{
format: 'esm',
Expand Down
8 changes: 8 additions & 0 deletions src/IttyDurable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class IttyDurable extends DurableObject {
#persistLoaded: undefined | true

// public attributes
id?: any
persisted: any

// default store
Expand All @@ -36,7 +37,14 @@ export class IttyDurable extends DurableObject {
target = obj[prop],
fn = target?.bind?.(obj),
) => {
// allow chainable id setting before calling other methods
if (prop == '$id') return (id: any) => (this.id = this.id ?? id) && this

// return properties directly
if (!fn) return target

// if method, start the persist debounce and call the function
// CONSIDER: moving the persist to after fn is called
this.persist()
return async (...args: any) => this.#sync().then(() => fn(args))
}
Expand Down
2 changes: 1 addition & 1 deletion src/itty-router/withDO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const withDO = (request: any, env: Record<string, any>) => {
request[k] = request[k] ?? (
(id: any) =>
typeof id == 'string'
? v.get(v.idFromName(id))
? v.get(v.idFromName(id))//.$id(id)
: v.get(id)
)
}
Expand Down

0 comments on commit bb00fe3

Please sign in to comment.