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

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 +114 -112
  2. package/README.ru.md +114 -112
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -175,94 +175,96 @@ 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
- ```ts
181
- type EventData = {
182
- type: string;
183
- url: string;
184
- };
180
+ ```ts
181
+ type EventData = {
182
+ type: string;
183
+ url: string;
184
+ };
185
185
 
186
- onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
187
- ```
186
+ onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
187
+ ```
188
188
 
189
- **`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).
190
190
 
191
- ```ts
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
200
- ```
191
+ ```ts
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
+ };
201
198
 
202
- **`onOPFSEvictionCompleted`** subscribe to notification when eviction has finished.
199
+ onOPFSWriteSkipped(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
200
+ ```
203
201
 
204
- ```ts
205
- type EventData = {
206
- type: string;
207
- count: number; // Number of files removed by eviction
208
- };
202
+ - **`onOPFSEvictionCompleted`** — subscribe to notification when eviction has finished.
209
203
 
210
- onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
211
- ```
204
+ ```ts
205
+ type EventData = {
206
+ type: string;
207
+ count: number; // Number of files removed by eviction
208
+ };
212
209
 
213
- **`onOPFSWriteFailed`** — subscribe to notification on write error (network, disk, partial file removed).
210
+ onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
211
+ ```
214
212
 
215
- ```ts
216
- type EventData = {
217
- type: string;
218
- url?: string;
219
- reason: string; // Reason the write failed
220
- };
213
+ - **`onOPFSWriteFailed`** — subscribe to notification on write error (network, disk, partial file removed).
221
214
 
222
- onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
223
- ```
215
+ ```ts
216
+ type EventData = {
217
+ type: string;
218
+ url?: string;
219
+ reason: string; // Reason the write failed
220
+ };
224
221
 
225
- **`onOPFSSkipQuotaExceeded`** subscribe to notification on repeat request for a blacklisted URL (resource not cached).
222
+ onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
223
+ ```
226
224
 
227
- ```ts
228
- type EventData = {
229
- type: string;
230
- url: string;
231
- };
225
+ - **`onOPFSSkipQuotaExceeded`** — subscribe to notification on repeat request for a blacklisted URL (resource not cached).
232
226
 
233
- onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
234
- ```
227
+ ```ts
228
+ type EventData = {
229
+ type: string;
230
+ url: string;
231
+ };
235
232
 
236
- ### Cache management and types
233
+ onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
234
+ ```
237
235
 
238
- **`listOpfsCachedResources`** returns the list of cached resources.
236
+ ### Cache management utilities
239
237
 
240
- ```ts
241
- listOpfsCachedResources(): Promise<OpfsCachedResource[]>
242
- ```
238
+ Functions to list cached resources, check by URL, and remove by URL. Called from the client (page); use when you need to show the user what is cached and let them delete selected items.
243
239
 
244
- Each array element:
240
+ - **`listOpfsCachedResources`** — returns the list of cached resources.
245
241
 
246
- ```ts
247
- interface OpfsCachedResource {
248
- url: string;
249
- size: number;
250
- type: string | undefined;
251
- lastModified: string | undefined;
252
- }
253
- ```
242
+ ```ts
243
+ listOpfsCachedResources(): Promise<OpfsCachedResource[]>
244
+ ```
254
245
 
255
- **`hasInOpfsCache`** checks whether a URL is in the cache.
246
+ Each array element:
256
247
 
257
- ```ts
258
- hasInOpfsCache(url: string): Promise<boolean>
259
- ```
248
+ ```ts
249
+ interface OpfsCachedResource {
250
+ url: string;
251
+ size: number;
252
+ type: string | undefined;
253
+ lastModified: string | undefined;
254
+ }
255
+ ```
260
256
 
261
- **`deleteFromOpfsCache`** — removes a resource by URL from the cache.
257
+ - **`hasInOpfsCache`** — checks whether a URL is in the cache.
262
258
 
263
- ```ts
264
- deleteFromOpfsCache(url: string): Promise<void>
265
- ```
259
+ ```ts
260
+ hasInOpfsCache(url: string): Promise<boolean>
261
+ ```
262
+
263
+ - **`deleteFromOpfsCache`** — removes a resource by URL from the cache.
264
+
265
+ ```ts
266
+ deleteFromOpfsCache(url: string): Promise<void>
267
+ ```
266
268
 
267
269
  Types `OpfsMessagePayload` and `OpfsCachedResource` are exported. Message type constants (name equals the string value in `event.data.type`): `OPFS_MSG_QUOTA_EXCEEDED`, `OPFS_MSG_WRITE_SKIPPED_SIZE`, `OPFS_MSG_CACHE_LIMIT_REACHED`, `OPFS_MSG_EVICTION_COMPLETED`, `OPFS_MSG_WRITE_FAILED`, `OPFS_MSG_SKIP_QUOTA_EXCEEDED`.
268
270
 
@@ -304,52 +306,52 @@ If you need finer‑grained control (show a list of cached resources and let use
304
306
 
305
307
  Global cache settings (folder name, quota fraction) are set in **configureOpfs({ folderName, maxCacheFraction })**. Below are the package plugins and their options.
306
308
 
307
- **`opfsServeRange`** — reads files from OPFS and serves requested byte ranges.
308
-
309
- ```ts
310
- opfsServeRange(options?: {
311
- order?: number;
312
- enableLogging?: boolean;
313
- include?: string[];
314
- exclude?: string[];
315
- rangeResponseCacheControl?: string; // Cache-Control for 206 responses (default: max-age=31536000, immutable)
316
- }): Plugin | undefined
317
- ```
318
-
319
- **`opfsPrecache`** — during SW install, fetches a list of URLs and writes them to OPFS.
320
-
321
- ```ts
322
- opfsPrecache(options: {
323
- urls: string[] | (() => Promise<string[]>); // array of URLs or function
324
- order?: number;
325
- enableLogging?: boolean;
326
- pinned?: string[]; // glob patterns for URLs protected from eviction (see «Pinned resources»)
327
- }): Plugin | undefined
328
- ```
329
-
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.
331
-
332
- ```ts
333
- opfsRangeFromNetworkAndCache(options?: {
334
- order?: number;
335
- include?: string[];
336
- exclude?: string[];
337
- enableLogging?: boolean;
338
- pinned?: string[]; // glob patterns for URLs protected from eviction
339
- }): Plugin | undefined
340
- ```
341
-
342
- **`opfsBackgroundFetch`** — on successful Background Fetch completion, writes responses into OPFS; subsequent Range requests for these URLs are served by opfsServeRange.
343
-
344
- ```ts
345
- opfsBackgroundFetch(options?: {
346
- order?: number;
347
- include?: string[];
348
- exclude?: string[];
349
- enableLogging?: boolean;
350
- pinned?: string[]; // glob patterns for URLs protected from eviction
351
- }): Plugin | undefined
352
- ```
309
+ - **`opfsServeRange`** — reads files from OPFS and serves requested byte ranges.
310
+
311
+ ```ts
312
+ opfsServeRange(options?: {
313
+ order?: number;
314
+ enableLogging?: boolean;
315
+ include?: string[];
316
+ exclude?: string[];
317
+ rangeResponseCacheControl?: string; // Cache-Control for 206 responses (default: max-age=31536000, immutable)
318
+ }): Plugin | undefined
319
+ ```
320
+
321
+ - **`opfsPrecache`** — during SW install, fetches a list of URLs and writes them to OPFS.
322
+
323
+ ```ts
324
+ opfsPrecache(options: {
325
+ urls: string[] | (() => Promise<string[]>); // array of URLs or function
326
+ order?: number;
327
+ enableLogging?: boolean;
328
+ pinned?: string[]; // glob patterns for URLs protected from eviction (see «Pinned resources»)
329
+ }): Plugin | undefined
330
+ ```
331
+
332
+ - **`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.
333
+
334
+ ```ts
335
+ opfsRangeFromNetworkAndCache(options?: {
336
+ order?: number;
337
+ include?: string[];
338
+ exclude?: string[];
339
+ enableLogging?: boolean;
340
+ pinned?: string[]; // glob patterns for URLs protected from eviction
341
+ }): Plugin | undefined
342
+ ```
343
+
344
+ - **`opfsBackgroundFetch`** — on successful Background Fetch completion, writes responses into OPFS; subsequent Range requests for these URLs are served by opfsServeRange.
345
+
346
+ ```ts
347
+ opfsBackgroundFetch(options?: {
348
+ order?: number;
349
+ include?: string[];
350
+ exclude?: string[];
351
+ enableLogging?: boolean;
352
+ pinned?: string[]; // glob patterns for URLs protected from eviction
353
+ }): Plugin | undefined
354
+ ```
353
355
 
354
356
  To trigger downloads from the client: `@budarin/pluggable-serviceworker/client/background-fetch`.
355
357
 
package/README.ru.md CHANGED
@@ -165,94 +165,96 @@ 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
- ```ts
171
- type EventData = {
172
- type: string;
173
- url: string;
174
- };
170
+ ```ts
171
+ type EventData = {
172
+ type: string;
173
+ url: string;
174
+ };
175
175
 
176
- onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
177
- ```
176
+ onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
177
+ ```
178
178
 
179
- **`onOPFSWriteSkipped`** — подписка на уведомление о пропуске записи (файл не влезает даже после эвикции).
179
+ - **`onOPFSWriteSkipped`** — подписка на уведомление о пропуске записи (файл не влезает даже после эвикции).
180
180
 
181
- ```ts
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
190
- ```
181
+ ```ts
182
+ type EventData = {
183
+ type: string;
184
+ url: string;
185
+ size: number; // Размер файла в байтах
186
+ reason: string; // Причина (почему запись не начата)
187
+ };
191
188
 
192
- **`onOPFSEvictionCompleted`** подписка на уведомление о завершении эвикции.
189
+ onOPFSWriteSkipped(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
190
+ ```
193
191
 
194
- ```ts
195
- type EventData = {
196
- type: string;
197
- count: number; // Число удалённых при эвикции файлов
198
- };
192
+ - **`onOPFSEvictionCompleted`** — подписка на уведомление о завершении эвикции.
199
193
 
200
- onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
201
- ```
194
+ ```ts
195
+ type EventData = {
196
+ type: string;
197
+ count: number; // Число удалённых при эвикции файлов
198
+ };
202
199
 
203
- **`onOPFSWriteFailed`** — подписка на уведомление об ошибке записи (сеть, диск, удалён частичный файл).
200
+ onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
201
+ ```
204
202
 
205
- ```ts
206
- type EventData = {
207
- type: string;
208
- url?: string;
209
- reason: string; // Причина ошибки записи
210
- };
203
+ - **`onOPFSWriteFailed`** — подписка на уведомление об ошибке записи (сеть, диск, удалён частичный файл).
211
204
 
212
- onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
213
- ```
205
+ ```ts
206
+ type EventData = {
207
+ type: string;
208
+ url?: string;
209
+ reason: string; // Причина ошибки записи
210
+ };
214
211
 
215
- **`onOPFSSkipQuotaExceeded`** подписка на уведомление о повторном запросе к URL из чёрного списка (ресурс не кешируем).
212
+ onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
213
+ ```
216
214
 
217
- ```ts
218
- type EventData = {
219
- type: string;
220
- url: string;
221
- };
215
+ - **`onOPFSSkipQuotaExceeded`** — подписка на уведомление о повторном запросе к URL из чёрного списка (ресурс не кешируем).
222
216
 
223
- onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
224
- ```
217
+ ```ts
218
+ type EventData = {
219
+ type: string;
220
+ url: string;
221
+ };
225
222
 
226
- ### Управление кешем и типы
223
+ onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
224
+ ```
227
225
 
228
- **`listOpfsCachedResources`** возвращает список закешированных ресурсов.
226
+ ### Утилиты управления кэшем
229
227
 
230
- ```ts
231
- listOpfsCachedResources(): Promise<OpfsCachedResource[]>
232
- ```
228
+ Функции для получения списка закешированных ресурсов, проверки по URL и удаления по URL. Вызываются на клиенте (страница); нужны, когда надо показать пользователю, что в кэше, и дать удалить выбранное.
233
229
 
234
- Элемент массива:
230
+ - **`listOpfsCachedResources`** — возвращает список закешированных ресурсов.
235
231
 
236
- ```ts
237
- interface OpfsCachedResource {
238
- url: string;
239
- size: number;
240
- type: string | undefined;
241
- lastModified: string | undefined;
242
- }
243
- ```
232
+ ```ts
233
+ listOpfsCachedResources(): Promise<OpfsCachedResource[]>
234
+ ```
244
235
 
245
- **`hasInOpfsCache`** — проверяет наличие URL в кеше.
236
+ Элемент массива:
246
237
 
247
- ```ts
248
- hasInOpfsCache(url: string): Promise<boolean>
249
- ```
238
+ ```ts
239
+ interface OpfsCachedResource {
240
+ url: string;
241
+ size: number;
242
+ type: string | undefined;
243
+ lastModified: string | undefined;
244
+ }
245
+ ```
250
246
 
251
- **`deleteFromOpfsCache`** — удаляет ресурс по URL из кеша.
247
+ - **`hasInOpfsCache`** — проверяет наличие URL в кеше.
252
248
 
253
- ```ts
254
- deleteFromOpfsCache(url: string): Promise<void>
255
- ```
249
+ ```ts
250
+ hasInOpfsCache(url: string): Promise<boolean>
251
+ ```
252
+
253
+ - **`deleteFromOpfsCache`** — удаляет ресурс по URL из кеша.
254
+
255
+ ```ts
256
+ deleteFromOpfsCache(url: string): Promise<void>
257
+ ```
256
258
 
257
259
  Типы `OpfsMessagePayload` и `OpfsCachedResource` экспортируются из пакета. Константы типов сообщений (имя совпадает со строковым значением в `event.data.type`): `OPFS_MSG_QUOTA_EXCEEDED`, `OPFS_MSG_WRITE_SKIPPED_SIZE`, `OPFS_MSG_CACHE_LIMIT_REACHED`, `OPFS_MSG_EVICTION_COMPLETED`, `OPFS_MSG_WRITE_FAILED`, `OPFS_MSG_SKIP_QUOTA_EXCEEDED`.
258
260
 
@@ -294,52 +296,52 @@ const unsubSkip = onOPFSSkipQuotaExceeded((event: MessageEvent) => {
294
296
 
295
297
  Общая настройка кеша (имя папки, доля квоты) задаётся в **configureOpfs({ folderName, maxCacheFraction })**. Ниже — плагины пакета и их опции.
296
298
 
297
- **`opfsServeRange`** — читает файлы из OPFS и отдаёт запрошенные диапазоны байтов.
298
-
299
- ```ts
300
- opfsServeRange(options?: {
301
- order?: number;
302
- enableLogging?: boolean;
303
- include?: string[];
304
- exclude?: string[];
305
- rangeResponseCacheControl?: string; // Cache-Control для ответов 206 (по умолчанию max-age=31536000, immutable)
306
- }): Plugin | undefined
307
- ```
308
-
309
- **`opfsPrecache`** — при установке сервис-воркера загружает список URL и записывает их в OPFS.
310
-
311
- ```ts
312
- opfsPrecache(options: {
313
- urls: string[] | (() => Promise<string[]>); // список URL или функция
314
- order?: number;
315
- enableLogging?: boolean;
316
- pinned?: string[]; // glob-паттерны URL, защищённых от эвикции (см. «Закреплённые ресурсы»)
317
- }): Plugin | undefined
318
- ```
319
-
320
- **`opfsRangeFromNetworkAndCache`** — обрабатывает запросы, которые opfsServeRange не обслужил (ресурс ещё не в кеше): идёт в сеть, отдаёт ответ клиенту и при необходимости догружает файл в OPFS в фоне.
321
-
322
- ```ts
323
- opfsRangeFromNetworkAndCache(options?: {
324
- order?: number;
325
- include?: string[];
326
- exclude?: string[];
327
- enableLogging?: boolean;
328
- pinned?: string[]; // glob-паттерны URL, защищённых от эвикции
329
- }): Plugin | undefined
330
- ```
331
-
332
- **`opfsBackgroundFetch`** — при успешном завершении загрузки через Background Fetch API записывает ответы в OPFS; дальнейшие range‑запросы по этим URL обслуживает opfsServeRange.
333
-
334
- ```ts
335
- opfsBackgroundFetch(options?: {
336
- order?: number;
337
- include?: string[];
338
- exclude?: string[];
339
- enableLogging?: boolean;
340
- pinned?: string[]; // glob-паттерны URL, защищённых от эвикции
341
- }): Plugin | undefined
342
- ```
299
+ - **`opfsServeRange`** — читает файлы из OPFS и отдаёт запрошенные диапазоны байтов.
300
+
301
+ ```ts
302
+ opfsServeRange(options?: {
303
+ order?: number;
304
+ enableLogging?: boolean;
305
+ include?: string[];
306
+ exclude?: string[];
307
+ rangeResponseCacheControl?: string; // Cache-Control для ответов 206 (по умолчанию max-age=31536000, immutable)
308
+ }): Plugin | undefined
309
+ ```
310
+
311
+ - **`opfsPrecache`** — при установке сервис-воркера загружает список URL и записывает их в OPFS.
312
+
313
+ ```ts
314
+ opfsPrecache(options: {
315
+ urls: string[] | (() => Promise<string[]>); // список URL или функция
316
+ order?: number;
317
+ enableLogging?: boolean;
318
+ pinned?: string[]; // glob-паттерны URL, защищённых от эвикции (см. «Закреплённые ресурсы»)
319
+ }): Plugin | undefined
320
+ ```
321
+
322
+ - **`opfsRangeFromNetworkAndCache`** — обрабатывает запросы, которые opfsServeRange не обслужил (ресурс ещё не в кеше): идёт в сеть, отдаёт ответ клиенту и при необходимости догружает файл в OPFS в фоне.
323
+
324
+ ```ts
325
+ opfsRangeFromNetworkAndCache(options?: {
326
+ order?: number;
327
+ include?: string[];
328
+ exclude?: string[];
329
+ enableLogging?: boolean;
330
+ pinned?: string[]; // glob-паттерны URL, защищённых от эвикции
331
+ }): Plugin | undefined
332
+ ```
333
+
334
+ - **`opfsBackgroundFetch`** — при успешном завершении загрузки через Background Fetch API записывает ответы в OPFS; дальнейшие range‑запросы по этим URL обслуживает opfsServeRange.
335
+
336
+ ```ts
337
+ opfsBackgroundFetch(options?: {
338
+ order?: number;
339
+ include?: string[];
340
+ exclude?: string[];
341
+ enableLogging?: boolean;
342
+ pinned?: string[]; // glob-паттерны URL, защищённых от эвикции
343
+ }): Plugin | undefined
344
+ ```
343
345
 
344
346
  Запуск загрузки с клиента: утилиты из `@budarin/pluggable-serviceworker/client/background-fetch`.
345
347
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budarin/psw-plugin-opfs-serve-range",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Service Worker plugin: serve HTTP Range requests from OPFS files",
5
5
  "keywords": [
6
6
  "service-worker",