Skip to content

Commit 8c7339f

Browse files
committed
[docs] Linting
1 parent e4c9b0f commit 8c7339f

File tree

1 file changed

+112
-100
lines changed
  • src/@types/persisters/persister-durable-object-sql-storage

1 file changed

+112
-100
lines changed
Lines changed: 112 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,97 @@
11
/**
2-
* This persister uses Cloudflare's SQLite storage backend, which offers significantly
3-
* better pricing compared to the Key-value storage backend. The SQLite storage backend
4-
* is Cloudflare's recommended storage option for new Durable Object namespaces.
5-
*
6-
* **Important:** Before using this persister, you must configure your Durable Object
7-
* class to use SQLite storage by adding a migration to your `wrangler.toml` or
8-
* `wrangler.json` configuration file. Use `new_sqlite_classes` in your migration
9-
* configuration to enable SQLite storage for your Durable Object class.
10-
*
2+
* The persister-durable-object-sql-storage module of the TinyBase project lets
3+
* you save and load Store data to and from Cloudflare Durable Object SQLite
4+
* storage (in an appropriate environment).
5+
*
6+
* Cloudflare's SQLite storage backend for Durable Objects offers significantly
7+
* better pricing compared to the key-value storage backend. The SQLite storage
8+
* backend is Cloudflare's recommended storage option for new Durable Object
9+
* namespaces.
10+
*
11+
* **Important:** Before using this persister, you must configure your Durable
12+
* Object class to use SQLite storage by adding a migration to your
13+
* `wrangler.toml` or `wrangler.json` configuration file. Use
14+
* `new_sqlite_classes` in your migration configuration to enable SQLite storage
15+
* for your Durable Object class.
16+
*
17+
* See [Cloudflare's
18+
* documentation](https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/)
19+
* for more details.
1120
* @see Cloudflare Durable Objects guide
1221
* @see Persistence guides
13-
* @see {@link https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ | Durable Objects migrations}
1422
* @packageDocumentation
1523
* @module persister-durable-object-sql-storage
16-
* @since v6.2.0
24+
* @since v6.3.0
1725
*/
1826
/// persister-durable-object-sql-storage
1927

2028
/**
21-
* The DpcFragmented type represents the configuration for fragmented persistence mode
22-
* in a DurableObjectSqlStoragePersister.
29+
* The DpcFragmented type represents the configuration for fragmented
30+
* persistence mode in a DurableObjectSqlStoragePersister.
2331
*
2432
* This mode stores each table, row, cell, and value as separate database rows,
25-
* avoiding Cloudflare's 2MB row limit that can be hit with large stores in JSON mode.
26-
* While this creates more database writes, it provides better scalability for
27-
* larger datasets.
28-
*
33+
* avoiding Cloudflare's 2MB row limit that can be hit with large stores in JSON
34+
* mode. While this creates more database writes, it provides better scalability
35+
* for larger datasets.
2936
* @example
3037
* This example shows how to configure a DurableObjectSqlStoragePersister to use
31-
* fragmented mode with a custom storage prefix:
38+
* fragmented mode with a custom storage prefix.
39+
*
40+
* ```js yolo
41+
* import {createMergeableStore} from 'tinybase';
42+
* import {createDurableObjectSqlStoragePersister} from 'tinybase/persisters/persister-durable-object-sql-storage';
43+
* import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
3244
*
33-
* ```js
3445
* const config = {
3546
* mode: 'fragmented',
36-
* storagePrefix: 'my_app_'
47+
* storagePrefix: 'my_app_',
3748
* };
3849
*
39-
* const persister = createDurableObjectSqlStoragePersister(
40-
* store,
41-
* ctx.storage.sql,
42-
* config
43-
* );
50+
* export class MyDurableObject extends WsServerDurableObject {
51+
* createPersister() {
52+
* const store = createMergeableStore();
53+
* const persister = createDurableObjectSqlStoragePersister(
54+
* store,
55+
* this.ctx.storage.sql,
56+
* config,
57+
* );
58+
* return persister;
59+
* }
60+
* }
4461
* ```
45-
*
4662
* @category Configuration
47-
* @since v6.2.0
63+
* @since v6.3.0
4864
*/
4965
/// DpcFragmented
5066
{
5167
/**
52-
* The mode property must be set to 'fragmented' to enable fragmented persistence mode.
53-
* @since v6.2.0
68+
* The mode property must be set to 'fragmented' to enable fragmented
69+
* persistence mode.
70+
* @category Configuration
71+
* @since v6.3.0
5472
*/
5573
/// DpcFragmented.mode
5674
/**
57-
* The storagePrefix property lets you specify an optional prefix for the database
58-
* table names used in fragmented mode.
59-
*
60-
* This is useful when you have multiple stores or applications sharing the same
61-
* Durable Object SQL storage and want to avoid table name conflicts.
75+
* The storagePrefix property lets you specify an optional prefix for the
76+
* database table names used in fragmented mode.
6277
*
63-
* The prefix will be sanitized to only include alphanumeric characters and underscores.
64-
* For example, a prefix of 'my-app!' becomes 'my_app_'.
78+
* This is useful when you have multiple stores or applications sharing the
79+
* same Durable Object SQL storage and want to avoid table name conflicts.
6580
*
81+
* The prefix will be sanitized to only include alphanumeric characters and
82+
* underscores. For example, a prefix of 'my-app!' becomes 'my_app_'.
6683
* @example
67-
* This example shows how the storagePrefix affects table names:
68-
*
69-
* ```js
70-
* // With storagePrefix: 'user_data_'
71-
* // Creates tables: user_data_tinybase_tables, user_data_tinybase_values
72-
*
73-
* const config = {
84+
* This example shows a configuration using the storagePrefix setting. With a
85+
* `storagePrefix` of 'user_data_', it creates `user_data_tinybase_tables` and
86+
* `user_data_tinybase_values` tables.
87+
* ```json
88+
* {
7489
* mode: 'fragmented',
75-
* storagePrefix: 'user_data_'
90+
* storagePrefix: 'user_data_',
7691
* };
7792
* ```
78-
*
79-
* @since v6.2.0
93+
* @category Configuration
94+
* @since v6.3.0
8095
*/
8196
/// DpcFragmented.storagePrefix
8297
}
@@ -85,52 +100,50 @@
85100
* The DurableObjectSqlDatabasePersisterConfig type represents the union of all
86101
* possible configuration types for a DurableObjectSqlStoragePersister.
87102
*
88-
* This allows the persister to support multiple persistence modes:
89-
* - JSON mode (via DpcJson): Stores the entire Store as JSON in a single row
90-
* - Fragmented mode (via DpcFragmented): Stores each piece of data as separate rows
91-
*
103+
* This allows the persister to support multiple persistence modes.
104+
* - JSON mode (via DpcJson): Stores the entire Store as JSON in a single row.
105+
* - Fragmented mode (via DpcFragmented): Stores each piece of data as separate
106+
* rows.
92107
* @example
93-
* This example shows the different configuration options:
94-
*
95-
* ```js
108+
* These examples show some different configuration options.
109+
* ```json
96110
* // JSON mode (default)
97-
* const jsonConfig = {
111+
* {
98112
* mode: 'json',
99-
* storeTableName: 'my_store'
113+
* storeTableName: 'my_store',
100114
* };
101115
*
102116
* // Fragmented mode
103-
* const fragmentedConfig = {
117+
* {
104118
* mode: 'fragmented',
105-
* storagePrefix: 'app_'
119+
* storagePrefix: 'app_',
106120
* };
107-
*
108121
* ```
109-
*
110122
* @category Configuration
111-
* @since v6.2.0
123+
* @since v6.3.0
112124
*/
113125
/// DurableObjectSqlDatabasePersisterConfig
114126

115127
/**
116-
* The DurableObjectSqlStoragePersister interface represents a Persister that lets
117-
* you save and load Store data to and from Cloudflare Durable Object SQL storage.
128+
* The DurableObjectSqlStoragePersister interface represents a Persister that
129+
* lets you save and load Store data to and from Cloudflare Durable Object SQL
130+
* storage.
118131
*
119-
* You should use the createDurableObjectSqlStoragePersister function to create a
120-
* DurableObjectSqlStoragePersister object, most likely within the createPersister
121-
* method of a WsServerDurableObject.
132+
* You should use the createDurableObjectSqlStoragePersister function to create
133+
* a DurableObjectSqlStoragePersister object, most likely within the
134+
* createPersister method of a WsServerDurableObject.
122135
*
123136
* It is a minor extension to the Persister interface and simply provides an
124-
* extra getSqlStorage method for accessing a reference to the SQL storage that the
125-
* Store is being persisted to.
137+
* extra getSqlStorage method for accessing a reference to the SQL storage that
138+
* the Store is being persisted to.
126139
* @category Persister
127-
* @since v6.2.0
140+
* @since v6.3.0
128141
*/
129142
/// DurableObjectSqlStoragePersister
130143
{
131144
/**
132-
* The getSqlStorage method returns a reference to the SQL storage that the Store is
133-
* being persisted to.
145+
* The getSqlStorage method returns a reference to the SQL storage that the
146+
* Store is being persisted to.
134147
* @returns The reference to the SQL storage.
135148
* @example
136149
* This example creates a Persister object against a newly-created Store
@@ -157,26 +170,25 @@
157170
* }
158171
* ```
159172
* @category Getter
160-
* @since v6.2.0
173+
* @since v6.3.0
161174
*/
162175
/// DurableObjectSqlStoragePersister.getSqlStorage
163176
}
164177
/**
165178
* The createDurableObjectSqlStoragePersister function creates a
166-
* DurableObjectSqlStoragePersister object that can persist the Store to and from
167-
* Cloudflare Durable Object SQLite storage.
179+
* DurableObjectSqlStoragePersister object that can persist the Store to and
180+
* from Cloudflare Durable Object SQLite storage.
168181
*
169182
* You will mostly use this within the createPersister method of a
170183
* WsServerDurableObject.
171184
*
172-
* This persister uses Cloudflare's SQLite storage backend, which provides better
173-
* pricing and performance compared to the legacy Key-value storage backend.
174-
*
175-
* **Important Prerequisites:**
176-
* Before using this persister, you must configure your Durable Object class to use
177-
* SQLite storage by adding a migration to your Wrangler configuration file. In your
178-
* `wrangler.toml`, add:
185+
* This persister uses Cloudflare's SQLite storage backend, which provides
186+
* better pricing and performance compared to the legacy Key-value storage
187+
* backend.
179188
*
189+
* **Important Prerequisites:** Before using this persister, you must configure
190+
* your Durable Object class to use SQLite storage by adding a migration to your
191+
* Wrangler configuration file. In your `wrangler.toml`, add the following.
180192
* ```toml
181193
* [[migrations]]
182194
* tag = "v1"
@@ -196,8 +208,8 @@
196208
* }
197209
* ```
198210
*
199-
* For more details on Durable Object migrations, see the
200-
* {@link https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ | Cloudflare documentation}.
211+
* For more details on Durable Object migrations, see the [Cloudflare
212+
* documentation](https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/).
201213
*
202214
* A database Persister uses one of two modes: either a JSON serialization of
203215
* the whole Store stored in a single row of a table (the default), a fragmented
@@ -206,24 +218,24 @@
206218
*
207219
* **JSON Mode (Default)**: Stores the entire Store as JSON in a single database
208220
* row. This is efficient for smaller stores but may hit Cloudflare's 2MB row
209-
* limit for very large stores. Uses fewer database writes.
221+
* limit for very large stores and uses fewer database writes.
210222
*
211-
* **Fragmented Mode**: Stores each table, row, cell, and value as separate database
212-
* rows. Use this mode if you're concerned about hitting Cloudflare's 2MB row
213-
* limit with large stores in JSON mode. This mode creates more database writes
214-
* but avoids row size limitations.
223+
* **Fragmented Mode**: Stores each table, row, cell, and value as separate
224+
* database rows. Use this mode if you're concerned about hitting Cloudflare's
225+
* 2MB row limit with large stores in JSON mode. This mode creates more database
226+
* writes but avoids row size limitations.
215227
*
216228
* The third argument is a DatabasePersisterConfig object that configures which
217229
* of those modes to use, and settings for each. If the third argument is simply
218230
* a string, it is used as the `storeTableName` property of the JSON
219231
* serialization. If it is the string 'fragmented', it enables fragmented mode.
220232
*
221-
* See the documentation for the DpcJson, DpcFragmented, and DpcTabular types for more
222-
* information on how all of those modes can be configured.
233+
* See the documentation for the DpcJson, DpcFragmented, and DpcTabular types
234+
* for more information on how all of those modes can be configured.
223235
*
224-
* As well as providing a reference to the Store or MergeableStore to persist, you must
225-
* provide a `sqlStorage` parameter which identifies the Durable Object SQLite storage to
226-
* persist it to.
236+
* As well as providing a reference to the Store or MergeableStore to persist,
237+
* you must provide a `sqlStorage` parameter which identifies the Durable Object
238+
* SQLite storage to persist it to.
227239
* @param store The Store or MergeableStore to persist.
228240
* @param sqlStorage The Durable Object SQL storage to persist the Store to.
229241
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
@@ -237,9 +249,9 @@
237249
* debugging persistence issues in a development environment.
238250
* @returns A reference to the new DurableObjectSqlStoragePersister object.
239251
* @example
240-
* This example creates a DurableObjectSqlStoragePersister object and persists the
241-
* Store to Durable Object SQLite storage as a JSON serialization into the default
242-
* `tinybase` table. It uses this within the createPersister method of a
252+
* This example creates a DurableObjectSqlStoragePersister object and persists
253+
* the Store to Durable Object SQLite storage as a JSON serialization into the
254+
* default `tinybase` table. It uses this within the createPersister method of a
243255
* WsServerDurableObject instance.
244256
*
245257
* ```js yolo
@@ -282,8 +294,8 @@
282294
* }
283295
* ```
284296
* @example
285-
* This example creates a DurableObjectSqlStoragePersister object using fragmented
286-
* mode to avoid Cloudflare's 2MB row limit for large stores.
297+
* This example creates a DurableObjectSqlStoragePersister object using
298+
* fragmented mode to avoid Cloudflare's 2MB row limit for large stores.
287299
*
288300
* ```js yolo
289301
* import {createMergeableStore} from 'tinybase';
@@ -303,8 +315,8 @@
303315
* }
304316
* ```
305317
* @example
306-
* This example creates a DurableObjectSqlStoragePersister object using fragmented
307-
* mode with a custom storage prefix.
318+
* This example creates a DurableObjectSqlStoragePersister object using
319+
* fragmented mode with a custom storage prefix.
308320
*
309321
* ```js yolo
310322
* import {createMergeableStore} from 'tinybase';
@@ -324,6 +336,6 @@
324336
* }
325337
* ```
326338
* @category Creation
327-
* @since v6.2.0
339+
* @since v6.3.0
328340
*/
329341
/// createDurableObjectSqlStoragePersister

0 commit comments

Comments
 (0)