Skip to content

Commit

Permalink
new files
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed May 1, 2024
1 parent e274fdb commit 4587d5b
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 410 deletions.
14 changes: 14 additions & 0 deletions examples/counters/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
account_id = "ac29ce961091a45f22b60d762e3e33a8"
name = "itty-durable-example"
compatibility_date = "2022-06-22"
workers_dev = false
routes = [
"durable.itty-router.dev/counters/*",
"durable.itty-router.dev/counters"
]

[durable_objects]
bindings = [
{ name = "Counter", class_name = "Counter" },
{ name = "Counters", class_name = "Counters" }
]
Empty file added src/IttyDurable.spec.ts
Empty file.
41 changes: 41 additions & 0 deletions src/IttyDurable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { DurableObject } from 'cloudflare:workers'

class IttyDurable extends DurableObject {

Check failure on line 3 in src/IttyDurable.ts

View workflow job for this annotation

GitHub Actions / build

'IttyDurable' is defined but never used
persisted
#persistTimer
#persistDelay = 5000
#persistLoaded

constructor(...args: any) {
super(...args)

return new Proxy(this, {
get: (obj, prop, receiver, target = obj[prop]) =>
// @ts-ignore
(typeof target == 'function' && this.persist(prop))
|| target?.bind?.(obj) || target
})
}

async isLoaded() {
if (this.#persistLoaded) return true
this.persisted = await this.ctx.storage.get('value')
return this.#persistLoaded = true
}

persist(methodName) {

Check failure on line 26 in src/IttyDurable.ts

View workflow job for this annotation

GitHub Actions / build

'methodName' is defined but never used
if (!this.persisted) return

clearTimeout(this.#persistTimer)
this.#persistTimer = setTimeout(() => {
// @ts-ignore
this.ctx?.storage.put('value', this.persisted)
}, this.#persistDelay)
}

toJSON() {
// @ts-ignore
const { ctx, env, ...other } = this

Check failure on line 38 in src/IttyDurable.ts

View workflow job for this annotation

GitHub Actions / build

'ctx' is assigned a value but never used

Check failure on line 38 in src/IttyDurable.ts

View workflow job for this annotation

GitHub Actions / build

'env' is assigned a value but never used
return other
}
}
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {

Check failure on line 1 in src/index.js

View workflow job for this annotation

GitHub Actions / build

'module' is not defined
...require('./itty-durable'),
...require('./with-durables'),
...require('./proxy-durable'),
...require('./IttyDurable'),

Check failure on line 2 in src/index.js

View workflow job for this annotation

GitHub Actions / build

'require' is not defined
...require('./withDurables'),

Check failure on line 3 in src/index.js

View workflow job for this annotation

GitHub Actions / build

'require' is not defined
}
222 changes: 0 additions & 222 deletions src/itty-durable.js

This file was deleted.

77 changes: 0 additions & 77 deletions src/itty-durable.spec.js

This file was deleted.

Loading

0 comments on commit 4587d5b

Please sign in to comment.