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

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 +111 -111
  2. package/README.ru.md +111 -111
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -175,94 +175,94 @@ 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
+ };
232
+
233
+ onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
234
+ ```
235
235
 
236
236
  ### Cache management and types
237
237
 
238
- **`listOpfsCachedResources`** — returns the list of cached resources.
238
+ - **`listOpfsCachedResources`** — returns the list of cached resources.
239
239
 
240
- ```ts
241
- listOpfsCachedResources(): Promise<OpfsCachedResource[]>
242
- ```
240
+ ```ts
241
+ listOpfsCachedResources(): Promise<OpfsCachedResource[]>
242
+ ```
243
243
 
244
- Each array element:
244
+ Each array element:
245
245
 
246
- ```ts
247
- interface OpfsCachedResource {
248
- url: string;
249
- size: number;
250
- type: string | undefined;
251
- lastModified: string | undefined;
252
- }
253
- ```
246
+ ```ts
247
+ interface OpfsCachedResource {
248
+ url: string;
249
+ size: number;
250
+ type: string | undefined;
251
+ lastModified: string | undefined;
252
+ }
253
+ ```
254
254
 
255
- **`hasInOpfsCache`** — checks whether a URL is in the cache.
255
+ - **`hasInOpfsCache`** — checks whether a URL is in the cache.
256
256
 
257
- ```ts
258
- hasInOpfsCache(url: string): Promise<boolean>
259
- ```
257
+ ```ts
258
+ hasInOpfsCache(url: string): Promise<boolean>
259
+ ```
260
260
 
261
- **`deleteFromOpfsCache`** — removes a resource by URL from the cache.
261
+ - **`deleteFromOpfsCache`** — removes a resource by URL from the cache.
262
262
 
263
- ```ts
264
- deleteFromOpfsCache(url: string): Promise<void>
265
- ```
263
+ ```ts
264
+ deleteFromOpfsCache(url: string): Promise<void>
265
+ ```
266
266
 
267
267
  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
268
 
@@ -304,52 +304,52 @@ If you need finer‑grained control (show a list of cached resources and let use
304
304
 
305
305
  Global cache settings (folder name, quota fraction) are set in **configureOpfs({ folderName, maxCacheFraction })**. Below are the package plugins and their options.
306
306
 
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
- ```
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
+ ```
353
353
 
354
354
  To trigger downloads from the client: `@budarin/pluggable-serviceworker/client/background-fetch`.
355
355
 
package/README.ru.md CHANGED
@@ -165,94 +165,94 @@ 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
+ };
222
+
223
+ onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
224
+ ```
225
225
 
226
226
  ### Управление кешем и типы
227
227
 
228
- **`listOpfsCachedResources`** — возвращает список закешированных ресурсов.
228
+ - **`listOpfsCachedResources`** — возвращает список закешированных ресурсов.
229
229
 
230
- ```ts
231
- listOpfsCachedResources(): Promise<OpfsCachedResource[]>
232
- ```
230
+ ```ts
231
+ listOpfsCachedResources(): Promise<OpfsCachedResource[]>
232
+ ```
233
233
 
234
- Элемент массива:
234
+ Элемент массива:
235
235
 
236
- ```ts
237
- interface OpfsCachedResource {
238
- url: string;
239
- size: number;
240
- type: string | undefined;
241
- lastModified: string | undefined;
242
- }
243
- ```
236
+ ```ts
237
+ interface OpfsCachedResource {
238
+ url: string;
239
+ size: number;
240
+ type: string | undefined;
241
+ lastModified: string | undefined;
242
+ }
243
+ ```
244
244
 
245
- **`hasInOpfsCache`** — проверяет наличие URL в кеше.
245
+ - **`hasInOpfsCache`** — проверяет наличие URL в кеше.
246
246
 
247
- ```ts
248
- hasInOpfsCache(url: string): Promise<boolean>
249
- ```
247
+ ```ts
248
+ hasInOpfsCache(url: string): Promise<boolean>
249
+ ```
250
250
 
251
- **`deleteFromOpfsCache`** — удаляет ресурс по URL из кеша.
251
+ - **`deleteFromOpfsCache`** — удаляет ресурс по URL из кеша.
252
252
 
253
- ```ts
254
- deleteFromOpfsCache(url: string): Promise<void>
255
- ```
253
+ ```ts
254
+ deleteFromOpfsCache(url: string): Promise<void>
255
+ ```
256
256
 
257
257
  Типы `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
258
 
@@ -294,52 +294,52 @@ const unsubSkip = onOPFSSkipQuotaExceeded((event: MessageEvent) => {
294
294
 
295
295
  Общая настройка кеша (имя папки, доля квоты) задаётся в **configureOpfs({ folderName, maxCacheFraction })**. Ниже — плагины пакета и их опции.
296
296
 
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
- ```
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
+ ```
343
343
 
344
344
  Запуск загрузки с клиента: утилиты из `@budarin/pluggable-serviceworker/client/background-fetch`.
345
345
 
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.9",
4
4
  "description": "Service Worker plugin: serve HTTP Range requests from OPFS files",
5
5
  "keywords": [
6
6
  "service-worker",