http-request-manager 22.0.13 → 22.0.14
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.
package/README.md
CHANGED
|
@@ -262,6 +262,63 @@ Behavior notes:
|
|
|
262
262
|
- Database disabled: tracker is bypassed; requests call the API directly each time.
|
|
263
263
|
- `forceRefresh: true` always forces an API call.
|
|
264
264
|
|
|
265
|
+
### Delta Sync (Incremental Fetch)
|
|
266
|
+
|
|
267
|
+
When `deltaSync: true` is set on `DatabaseStorage`, `HTTPManagerStateService` sends an `X-Modified-Since: <epoch>` header on every fetch after the initial full load. The backend returns only records created or modified at or after the provided timestamp; the store merges them via upsert (IndexedDB `bulkPut` + `mergeDeltaData$` state updater).
|
|
268
|
+
|
|
269
|
+
**Requirements:**
|
|
270
|
+
|
|
271
|
+
- `DatabaseStorage` must be configured with a valid `table` name (database storage enabled).
|
|
272
|
+
- `deltaSync: true` must be set on the `DatabaseStorage` config.
|
|
273
|
+
- `expiresIn` controls the TTL for periodic full re-syncs. Set `expiresIn: '0'` to disable TTL expiry entirely — delta sync will run on every call without periodic full re-syncs. Use a non-zero value (e.g., `'1d'`) to periodically clear and re-fetch all data (corrects soft-delete drift).
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
// Delta sync with no TTL expiry (delta on every call, no periodic full re-sync)
|
|
277
|
+
const service = new HTTPManagerStateService(
|
|
278
|
+
ApiRequest.adapt({ server: 'https://api.example.com', path: ['api', 'items'] }),
|
|
279
|
+
DataType.ARRAY,
|
|
280
|
+
DatabaseStorage.adapt({ table: 'items', expiresIn: '0', deltaSync: true })
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Delta sync with daily full re-sync (delta between cycles, full fetch at TTL boundary)
|
|
284
|
+
const service2 = new HTTPManagerStateService(
|
|
285
|
+
ApiRequest.adapt({ server: 'https://api.example.com', path: ['api', 'items'] }),
|
|
286
|
+
DataType.ARRAY,
|
|
287
|
+
DatabaseStorage.adapt({ table: 'items', expiresIn: '1d', deltaSync: true })
|
|
288
|
+
);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**How it works:**
|
|
292
|
+
|
|
293
|
+
1. **First call** (no `savedAt`): full fetch, DB populated, `savedAt` written to localStorage as `Date.now()`.
|
|
294
|
+
2. **Subsequent calls** (within TTL): sends `X-Modified-Since: floor(savedAt / 1000)` header. Backend returns only changed/new records.
|
|
295
|
+
- **Records returned**: upserted to IndexedDB via `bulkPut`, merged into state via `mergeDeltaData$`, `savedAt` updated.
|
|
296
|
+
- **Empty response `[]`**: state/DB unchanged, `savedAt` updated to current time.
|
|
297
|
+
- **Error**: state/DB unchanged, `savedAt` NOT updated — next call retries from the same timestamp.
|
|
298
|
+
3. **TTL expiry** (when `expiresIn` is non-zero): `clearTable` runs, full fetch replaces all data, `savedAt` reset.
|
|
299
|
+
4. **`forceRefresh: true`**: full fetch bypasses delta path entirely.
|
|
300
|
+
|
|
301
|
+
**localStorage updates on DB write:**
|
|
302
|
+
|
|
303
|
+
When data is pushed to IndexedDB (both full fetch and delta fetch), the localStorage store for the table is updated with:
|
|
304
|
+
- `expires`: refreshed to `utils.expires(expiresIn)` — resets the TTL clock so the next full re-sync is scheduled from the last DB write.
|
|
305
|
+
- `requestCache.GET.savedAt`: set to `Date.now()` — the cursor for the next delta request's `X-Modified-Since` header.
|
|
306
|
+
|
|
307
|
+
**`DatabaseStorage` properties:**
|
|
308
|
+
|
|
309
|
+
| Property | Type | Default | Description |
|
|
310
|
+
|----------|------|---------|-------------|
|
|
311
|
+
| `table` | `string` | `''` | IndexedDB table name (required for delta sync) |
|
|
312
|
+
| `expiresIn` | `string` | `''` | TTL for full re-sync. Use `'0'` to disable (delta sync only, no periodic full re-sync). Examples: `'1m'`, `'1h'`, `'1d'` |
|
|
313
|
+
| `deltaSync` | `boolean` | `false` | Enable incremental fetch with `X-Modified-Since` header |
|
|
314
|
+
|
|
315
|
+
**Notes:**
|
|
316
|
+
|
|
317
|
+
- `X-Modified-Since` is added to `volatileHeaders` so it's excluded from request signatures and cache metadata.
|
|
318
|
+
- With `expiresIn: '0'`, TTL never expires — delta sync runs on every call. Use a non-zero value to periodically full re-sync and catch deleted records.
|
|
319
|
+
- The `savedAt` timestamp (used as the `X-Modified-Since` value) is the last time data was successfully written to the DB — it represents the last DB sync time, not the last API call time.
|
|
320
|
+
- Fully backwards compatible — existing consumers see no behavior change unless `deltaSync: true` is set.
|
|
321
|
+
|
|
265
322
|
## ⚙️ Configuration
|
|
266
323
|
|
|
267
324
|
### Module Initialization (`forRoot`)
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-request-manager",
|
|
3
|
-
"version": "22.0.
|
|
3
|
+
"version": "22.0.14",
|
|
4
4
|
"homepage": "https://wavecoders.ca",
|
|
5
5
|
"author": "Mike Bonifacio <wavecoders@gmail.com> (http://wavecoders@gmail.com/)",
|
|
6
6
|
"description": "This is an Angular Module containing Components/Services using Material",
|