@@ -16,15 +16,76 @@ type DiffableArgs =
16
16
| [ _ : any , { kind : string ; name : string } ] ;
17
17
18
18
type DiffableOpts = {
19
+ /**
20
+ * The name of the state, typically the name of the field.
21
+ */
19
22
name ?: string ;
23
+ /**
24
+ * Diffable-objects will automatically snapshot the state perodically based on this policy to minimize
25
+ * the number of diffs that must be applied to restore the state when the Durable Object is restarted.
26
+ */
20
27
snapshotPolicy ?: SnapshotPolicy ;
21
28
} ;
22
29
30
+ /**
31
+ * Dynamically create a state object that persists changes to durable storage using Proxy and SQLite.
32
+ *
33
+ * ```
34
+ * import { DurableObject } from "cloudflare:workers";
35
+ * import { diffable } from "diffable-objects";
36
+ *
37
+ * class Counter extends DurableObject {
38
+ * @diffable
39
+ * #state = { count: 0 };
40
+ *
41
+ * async fetch(request) {
42
+ * this.#state.count += 1;
43
+ * return new Response(`Count: ${this.#state.count}`);
44
+ * }
45
+ * }
46
+ * ```
47
+ */
23
48
export function diffable (
24
49
_ : any ,
25
50
{ kind, name } : { kind : string ; name : string } ,
26
51
) : FieldDecoratorReturn < any > ;
52
+ /**
53
+ * Dynamically create a state object that persists changes to durable storage using Proxy and SQLite.
54
+ *
55
+ * ```
56
+ * import { DurableObject } from "cloudflare:workers";
57
+ * import { diffable } from "diffable-objects";
58
+ *
59
+ * class Counter extends DurableObject {
60
+ * @diffable ("counter")
61
+ * #state = { count: 0 };
62
+ *
63
+ * async fetch(request) {
64
+ * this.#state.count += 1;
65
+ * return new Response(`Count: ${this.#state.count}`);
66
+ * }
67
+ * }
68
+ * ```
69
+ */
27
70
export function diffable ( name ?: string ) : FieldDecoratorFactoryReturn < any > ;
71
+ /**
72
+ * Dynamically create a state object that persists changes to durable storage using Proxy and SQLite.
73
+ *
74
+ * ```
75
+ * import { DurableObject } from "cloudflare:workers";
76
+ * import { diffable } from "diffable-objects";
77
+ *
78
+ * class Counter extends DurableObject {
79
+ * @diffable ({ name: "counter", snapshotPolicy: "never" })
80
+ * #state = { count: 0 };
81
+ *
82
+ * async fetch(request) {
83
+ * this.#state.count += 1;
84
+ * return new Response(`Count: ${this.#state.count}`);
85
+ * }
86
+ * }
87
+ * ```
88
+ */
28
89
export function diffable (
29
90
options : DiffableOpts ,
30
91
) : FieldDecoratorFactoryReturn < any > ;
0 commit comments