@budarin/psw-plugin-opfs-serve-range 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +59 -67
  2. package/README.ru.md +59 -67
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -163,11 +163,11 @@ The response may not have a `Content-Length` header – when writing the full bo
163
163
 
164
164
  Client‑side helpers are exported from the entry point `@budarin/psw-plugin-opfs-serve-range/client`. This section gives signatures, types, and examples; [opfs-cache-behavior.md](https://github.com/budarin/psw-plugin-opfs-serve-range/blob/master/docs/opfs-cache-behavior.md) only describes **when** the service worker sends messages (limits, LRU, eviction), not the API.
165
165
 
166
- **Message payload**
166
+ ### Message payload
167
167
 
168
168
  Each handler receives a `MessageEvent`; `event.data` is `{ type: string } & OpfsMessagePayload`, and some events add a `count` field. The package type `OpfsMessagePayload` is `{ url?: string; size?: number; limit?: number; reason?: string }`.
169
169
 
170
- **Message subscriptions**
170
+ ### Message subscriptions
171
171
 
172
172
  Each function takes a handler and returns an unsubscribe function (call it to remove the subscription). Below are the subscriptions for messages that the service worker actually sends in the current version.
173
173
 
@@ -175,98 +175,90 @@ Each function takes a handler and returns an unsubscribe function (call it to re
175
175
  type Unsubscribe = () => void;
176
176
  ```
177
177
 
178
- ### `onOPFSQuotaExceeded` — subscribe to notification when the browser throws QuotaExceeded while writing to OPFS.
178
+ **`onOPFSQuotaExceeded`** — subscribe to notification when the browser throws QuotaExceeded while writing to OPFS.
179
179
 
180
180
  ```ts
181
- onOPFSQuotaExceeded(handler: (event: MessageEvent) => void): Unsubscribe
182
- ```
181
+ type EventData = {
182
+ type: string;
183
+ url: string;
184
+ };
183
185
 
184
- - `event.data`:
185
- ```ts
186
- {
187
- type: string;
188
- url: string;
189
- }
190
- ```
186
+ onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
187
+ ```
191
188
 
192
- ### `onOPFSWriteSkipped` — subscribe to notification when the write was skipped (file does not fit even after eviction).
189
+ **`onOPFSWriteSkipped`** — subscribe to notification when the write was skipped (file does not fit even after eviction).
193
190
 
194
191
  ```ts
195
- onOPFSWriteSkipped(handler: (event: MessageEvent) => void): Unsubscribe
192
+ type EventData = {
193
+ type: string;
194
+ url: string;
195
+ size: number; // File size in bytes
196
+ reason: string; // Reason the write was not started
197
+ };
198
+
199
+ onOPFSWriteSkipped(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
196
200
  ```
197
201
 
198
- - `event.data`:
199
- ```ts
200
- {
201
- type: string;
202
- url: string;
203
- /** File size in bytes */
204
- size: number;
205
- /** Reason the write was not started */
206
- reason: string;
207
- }
208
- ```
209
-
210
- ### `onOPFSEvictionCompleted` — subscribe to notification when eviction has finished.
202
+ **`onOPFSEvictionCompleted`** — subscribe to notification when eviction has finished.
211
203
 
212
204
  ```ts
213
- onOPFSEvictionCompleted(handler: (event: MessageEvent) => void): Unsubscribe
214
- ```
205
+ type EventData = {
206
+ type: string;
207
+ count: number; // Number of files removed by eviction
208
+ };
215
209
 
216
- - `event.data`:
217
- ```ts
218
- {
219
- type: string;
220
- /** Number of files removed by eviction */
221
- count: number;
222
- }
223
- ```
210
+ onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
211
+ ```
224
212
 
225
- ### `onOPFSWriteFailed` — subscribe to notification on write error (network, disk, partial file removed).
213
+ **`onOPFSWriteFailed`** — subscribe to notification on write error (network, disk, partial file removed).
226
214
 
227
215
  ```ts
228
- onOPFSWriteFailed(handler: (event: MessageEvent) => void): Unsubscribe
229
- ```
216
+ type EventData = {
217
+ type: string;
218
+ url?: string;
219
+ reason: string; // Reason the write failed
220
+ };
230
221
 
231
- - `event.data`:
232
- ```ts
233
- {
234
- type: string;
235
- url?: string;
236
- /** Reason the write failed */
237
- reason: string;
238
- }
239
- ```
222
+ onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
223
+ ```
240
224
 
241
- ### `onOPFSSkipQuotaExceeded` — subscribe to notification on repeat request for a blacklisted URL (resource not cached).
225
+ **`onOPFSSkipQuotaExceeded`** — subscribe to notification on repeat request for a blacklisted URL (resource not cached).
242
226
 
243
227
  ```ts
244
- onOPFSSkipQuotaExceeded(handler: (event: MessageEvent) => void): Unsubscribe
245
- ```
228
+ type EventData = {
229
+ type: string;
230
+ url: string;
231
+ };
246
232
 
247
- - `event.data`:
248
- ```ts
249
- {
250
- type: string;
251
- url: string;
252
- }
253
- ```
233
+ onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
234
+ ```
254
235
 
255
- **Cache management and types**
236
+ ### Cache management and types
256
237
 
257
- ### `listOpfsCachedResources` — returns the list of cached resources. Each item: `{ url, size, type?, lastModified? }`.
238
+ **`listOpfsCachedResources`** — returns the list of cached resources.
258
239
 
259
240
  ```ts
260
241
  listOpfsCachedResources(): Promise<OpfsCachedResource[]>
261
242
  ```
262
243
 
263
- ### `hasInOpfsCache` — checks whether a URL is in the cache.
244
+ Each array element:
245
+
246
+ ```ts
247
+ interface OpfsCachedResource {
248
+ url: string;
249
+ size: number;
250
+ type: string | undefined;
251
+ lastModified: string | undefined;
252
+ }
253
+ ```
254
+
255
+ **`hasInOpfsCache`** — checks whether a URL is in the cache.
264
256
 
265
257
  ```ts
266
258
  hasInOpfsCache(url: string): Promise<boolean>
267
259
  ```
268
260
 
269
- ### `deleteFromOpfsCache` — removes a resource by URL from the cache.
261
+ **`deleteFromOpfsCache`** — removes a resource by URL from the cache.
270
262
 
271
263
  ```ts
272
264
  deleteFromOpfsCache(url: string): Promise<void>
@@ -312,7 +304,7 @@ If you need finer‑grained control (show a list of cached resources and let use
312
304
 
313
305
  Global cache settings (folder name, quota fraction) are set in **configureOpfs({ folderName, maxCacheFraction })**. Below are the package plugins and their options.
314
306
 
315
- ### `opfsServeRange` — reads files from OPFS and serves requested byte ranges.
307
+ **`opfsServeRange`** — reads files from OPFS and serves requested byte ranges.
316
308
 
317
309
  ```ts
318
310
  opfsServeRange(options?: {
@@ -324,7 +316,7 @@ opfsServeRange(options?: {
324
316
  }): Plugin | undefined
325
317
  ```
326
318
 
327
- ### `opfsPrecache` — during SW install, fetches a list of URLs and writes them to OPFS.
319
+ **`opfsPrecache`** — during SW install, fetches a list of URLs and writes them to OPFS.
328
320
 
329
321
  ```ts
330
322
  opfsPrecache(options: {
@@ -335,7 +327,7 @@ opfsPrecache(options: {
335
327
  }): Plugin | undefined
336
328
  ```
337
329
 
338
- ### `opfsRangeFromNetworkAndCache` — handles requests that opfsServeRange did not serve (resource not in cache yet): goes to the network, streams the response to the client, and optionally fills OPFS in the background.
330
+ **`opfsRangeFromNetworkAndCache`** — handles requests that opfsServeRange did not serve (resource not in cache yet): goes to the network, streams the response to the client, and optionally fills OPFS in the background.
339
331
 
340
332
  ```ts
341
333
  opfsRangeFromNetworkAndCache(options?: {
@@ -347,7 +339,7 @@ opfsRangeFromNetworkAndCache(options?: {
347
339
  }): Plugin | undefined
348
340
  ```
349
341
 
350
- ### `opfsBackgroundFetch` — on successful Background Fetch completion, writes responses into OPFS; subsequent Range requests for these URLs are served by opfsServeRange.
342
+ **`opfsBackgroundFetch`** — on successful Background Fetch completion, writes responses into OPFS; subsequent Range requests for these URLs are served by opfsServeRange.
351
343
 
352
344
  ```ts
353
345
  opfsBackgroundFetch(options?: {
package/README.ru.md CHANGED
@@ -153,11 +153,11 @@ await writeToOpfs(dir, key, response.body, metadata);
153
153
 
154
154
  Клиентские хелперы экспортируются из entry point `@budarin/psw-plugin-opfs-serve-range/client`. В этом разделе — сигнатуры, типы и примеры; в [opfs-cache-behavior.ru.md](https://github.com/budarin/psw-plugin-opfs-serve-range/blob/master/docs/opfs-cache-behavior.ru.md) описано только **когда** сервис-воркер шлёт сообщения (лимиты, LRU, эвикция), не API.
155
155
 
156
- **Данные в сообщениях**
156
+ ### Данные в сообщениях
157
157
 
158
158
  Обработчик получает `MessageEvent`; `event.data` имеет тип `{ type: string } & OpfsMessagePayload` плюс при необходимости поле `count`. Тип `OpfsMessagePayload` в пакете: `{ url?: string; size?: number; limit?: number; reason?: string }`.
159
159
 
160
- **Подписки на сообщения**
160
+ ### Подписки на сообщения
161
161
 
162
162
  Каждая функция принимает обработчик и возвращает функцию отписки (вызов снимает подписку). Ниже перечислены подписки, сообщения которых сервис-воркер реально отправляет в текущей версии.
163
163
 
@@ -165,98 +165,90 @@ await writeToOpfs(dir, key, response.body, metadata);
165
165
  type Unsubscribe = () => void;
166
166
  ```
167
167
 
168
- ### `onOPFSQuotaExceeded` — подписка на уведомление об исчерпании квоты при записи в OPFS.
168
+ **`onOPFSQuotaExceeded`** — подписка на уведомление об исчерпании квоты при записи в OPFS.
169
169
 
170
170
  ```ts
171
- onOPFSQuotaExceeded(handler: (event: MessageEvent) => void): Unsubscribe
172
- ```
171
+ type EventData = {
172
+ type: string;
173
+ url: string;
174
+ };
173
175
 
174
- - `event.data`:
175
- ```ts
176
- {
177
- type: string;
178
- url: string;
179
- }
180
- ```
176
+ onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
177
+ ```
181
178
 
182
- ### `onOPFSWriteSkipped` — подписка на уведомление о пропуске записи (файл не влезает даже после эвикции).
179
+ **`onOPFSWriteSkipped`** — подписка на уведомление о пропуске записи (файл не влезает даже после эвикции).
183
180
 
184
181
  ```ts
185
- onOPFSWriteSkipped(handler: (event: MessageEvent) => void): Unsubscribe
182
+ type EventData = {
183
+ type: string;
184
+ url: string;
185
+ size: number; // Размер файла в байтах
186
+ reason: string; // Причина (почему запись не начата)
187
+ };
188
+
189
+ onOPFSWriteSkipped(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
186
190
  ```
187
191
 
188
- - `event.data`:
189
- ```ts
190
- {
191
- type: string;
192
- url: string;
193
- /** Размер файла в байтах */
194
- size: number;
195
- /** Причина (почему запись не начата) */
196
- reason: string;
197
- }
198
- ```
199
-
200
- ### `onOPFSEvictionCompleted` — подписка на уведомление о завершении эвикции.
192
+ **`onOPFSEvictionCompleted`** — подписка на уведомление о завершении эвикции.
201
193
 
202
194
  ```ts
203
- onOPFSEvictionCompleted(handler: (event: MessageEvent) => void): Unsubscribe
204
- ```
195
+ type EventData = {
196
+ type: string;
197
+ count: number; // Число удалённых при эвикции файлов
198
+ };
205
199
 
206
- - `event.data`:
207
- ```ts
208
- {
209
- type: string;
210
- /** Число удалённых при эвикции файлов */
211
- count: number;
212
- }
213
- ```
200
+ onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
201
+ ```
214
202
 
215
- ### `onOPFSWriteFailed` — подписка на уведомление об ошибке записи (сеть, диск, удалён частичный файл).
203
+ **`onOPFSWriteFailed`** — подписка на уведомление об ошибке записи (сеть, диск, удалён частичный файл).
216
204
 
217
205
  ```ts
218
- onOPFSWriteFailed(handler: (event: MessageEvent) => void): Unsubscribe
219
- ```
206
+ type EventData = {
207
+ type: string;
208
+ url?: string;
209
+ reason: string; // Причина ошибки записи
210
+ };
220
211
 
221
- - `event.data`:
222
- ```ts
223
- {
224
- type: string;
225
- url?: string;
226
- /** Причина ошибки записи */
227
- reason: string;
228
- }
229
- ```
212
+ onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
213
+ ```
230
214
 
231
- ### `onOPFSSkipQuotaExceeded` — подписка на уведомление о повторном запросе к URL из чёрного списка (ресурс не кешируем).
215
+ **`onOPFSSkipQuotaExceeded`** — подписка на уведомление о повторном запросе к URL из чёрного списка (ресурс не кешируем).
232
216
 
233
217
  ```ts
234
- onOPFSSkipQuotaExceeded(handler: (event: MessageEvent) => void): Unsubscribe
235
- ```
218
+ type EventData = {
219
+ type: string;
220
+ url: string;
221
+ };
236
222
 
237
- - `event.data`:
238
- ```ts
239
- {
240
- type: string;
241
- url: string;
242
- }
243
- ```
223
+ onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
224
+ ```
244
225
 
245
- **Управление кешем и типы**
226
+ ### Управление кешем и типы
246
227
 
247
- ### `listOpfsCachedResources` — возвращает список закешированных ресурсов. Элемент: `{ url, size, type?, lastModified? }`.
228
+ **`listOpfsCachedResources`** — возвращает список закешированных ресурсов.
248
229
 
249
230
  ```ts
250
231
  listOpfsCachedResources(): Promise<OpfsCachedResource[]>
251
232
  ```
252
233
 
253
- ### `hasInOpfsCache` — проверяет наличие URL в кеше.
234
+ Элемент массива:
235
+
236
+ ```ts
237
+ interface OpfsCachedResource {
238
+ url: string;
239
+ size: number;
240
+ type: string | undefined;
241
+ lastModified: string | undefined;
242
+ }
243
+ ```
244
+
245
+ **`hasInOpfsCache`** — проверяет наличие URL в кеше.
254
246
 
255
247
  ```ts
256
248
  hasInOpfsCache(url: string): Promise<boolean>
257
249
  ```
258
250
 
259
- ### `deleteFromOpfsCache` — удаляет ресурс по URL из кеша.
251
+ **`deleteFromOpfsCache`** — удаляет ресурс по URL из кеша.
260
252
 
261
253
  ```ts
262
254
  deleteFromOpfsCache(url: string): Promise<void>
@@ -302,7 +294,7 @@ const unsubSkip = onOPFSSkipQuotaExceeded((event: MessageEvent) => {
302
294
 
303
295
  Общая настройка кеша (имя папки, доля квоты) задаётся в **configureOpfs({ folderName, maxCacheFraction })**. Ниже — плагины пакета и их опции.
304
296
 
305
- ### `opfsServeRange` — читает файлы из OPFS и отдаёт запрошенные диапазоны байтов.
297
+ **`opfsServeRange`** — читает файлы из OPFS и отдаёт запрошенные диапазоны байтов.
306
298
 
307
299
  ```ts
308
300
  opfsServeRange(options?: {
@@ -314,7 +306,7 @@ opfsServeRange(options?: {
314
306
  }): Plugin | undefined
315
307
  ```
316
308
 
317
- ### `opfsPrecache` — при установке сервис-воркера загружает список URL и записывает их в OPFS.
309
+ **`opfsPrecache`** — при установке сервис-воркера загружает список URL и записывает их в OPFS.
318
310
 
319
311
  ```ts
320
312
  opfsPrecache(options: {
@@ -325,7 +317,7 @@ opfsPrecache(options: {
325
317
  }): Plugin | undefined
326
318
  ```
327
319
 
328
- ### `opfsRangeFromNetworkAndCache` — обрабатывает запросы, которые opfsServeRange не обслужил (ресурс ещё не в кеше): идёт в сеть, отдаёт ответ клиенту и при необходимости догружает файл в OPFS в фоне.
320
+ **`opfsRangeFromNetworkAndCache`** — обрабатывает запросы, которые opfsServeRange не обслужил (ресурс ещё не в кеше): идёт в сеть, отдаёт ответ клиенту и при необходимости догружает файл в OPFS в фоне.
329
321
 
330
322
  ```ts
331
323
  opfsRangeFromNetworkAndCache(options?: {
@@ -337,7 +329,7 @@ opfsRangeFromNetworkAndCache(options?: {
337
329
  }): Plugin | undefined
338
330
  ```
339
331
 
340
- ### `opfsBackgroundFetch` — при успешном завершении загрузки через Background Fetch API записывает ответы в OPFS; дальнейшие range‑запросы по этим URL обслуживает opfsServeRange.
332
+ **`opfsBackgroundFetch`** — при успешном завершении загрузки через Background Fetch API записывает ответы в OPFS; дальнейшие range‑запросы по этим URL обслуживает opfsServeRange.
341
333
 
342
334
  ```ts
343
335
  opfsBackgroundFetch(options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budarin/psw-plugin-opfs-serve-range",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Service Worker plugin: serve HTTP Range requests from OPFS files",
5
5
  "keywords": [
6
6
  "service-worker",