@rdlabo/ionic-angular-kit 21.5.5 → 21.5.7
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
|
@@ -291,7 +291,7 @@ export const appConfig: ApplicationConfig = {
|
|
|
291
291
|
// const session = await auth.exchangeCredential();
|
|
292
292
|
// return {
|
|
293
293
|
// activate: (lease) => offline.prepareRemoteSession(
|
|
294
|
-
// session.userId, session.
|
|
294
|
+
// session.userId, session.scopeIds, session.subject, lease,
|
|
295
295
|
// ),
|
|
296
296
|
// resume: () => offline.resumeRemoteSession(),
|
|
297
297
|
// };
|
|
@@ -310,7 +310,7 @@ export const appConfig: ApplicationConfig = {
|
|
|
310
310
|
// return session
|
|
311
311
|
// ? {
|
|
312
312
|
// activate: (lease) => offline.prepareRemoteSession(
|
|
313
|
-
// session.userId, session.
|
|
313
|
+
// session.userId, session.scopeIds, session.subject, lease,
|
|
314
314
|
// ),
|
|
315
315
|
// resume: () => offline.resumeRemoteSession(),
|
|
316
316
|
// }
|
|
@@ -389,7 +389,7 @@ A fleet-canonical HTTP interceptor with:
|
|
|
389
389
|
|
|
390
390
|
### Scoped local replica and outbox (`@rdlabo/ionic-angular-kit/offline`)
|
|
391
391
|
|
|
392
|
-
The optional `offline` entry point provides a user/
|
|
392
|
+
The optional `offline` entry point provides a user/partition-scoped local replica, durable outbox, authenticated
|
|
393
393
|
session boundary, cursor-based delta pull, aggregate-ordered replay, optimistic updates, retry classification, and a
|
|
394
394
|
read-only request-policy interceptor. Applications provide URL/DTO read policies, a replica puller, and a command
|
|
395
395
|
executor through `provideOffline(...)`.
|
|
@@ -401,8 +401,8 @@ For cold-start offline route access, `OfflineCoordinatorService.activateOfflineS
|
|
|
401
401
|
that is bound to a non-null authentication-provider subject. Supplying a currently known subject also rejects a
|
|
402
402
|
different user on a shared device. It activates local replica writes and durable outbox enqueue, but remote pull and
|
|
403
403
|
command replay remain disabled until online authentication completes the ordered
|
|
404
|
-
`prepareRemoteSession(...)` → publish `remote` → `resumeRemoteSession()` transition. `activateSession(...)`
|
|
405
|
-
available as a
|
|
404
|
+
`prepareRemoteSession(...)` → publish `remote` → `resumeRemoteSession()` transition. `activateSession(...)` is
|
|
405
|
+
available as a one-step API for callers that do not enforce shared access mode.
|
|
406
406
|
Explicit sign-out must first call `KitAuthAccessService.clear()` and then await `clearActiveSession()`. The first
|
|
407
407
|
step immediately invalidates every in-flight auth lease; the second serializes cleanup after local persistence
|
|
408
408
|
already in progress and removes the manifest and user replica.
|
|
@@ -430,8 +430,9 @@ provideKitAuth(() => ({
|
|
|
430
430
|
ordering via `KitRemoteAccessRecovery`. Product code keeps consent, error UI, and credential mapping inside
|
|
431
431
|
`exchange(context)` (`phase: 'authorize' | 'recover'`, optional route state, lease). Return `null`/`false` to decline
|
|
432
432
|
without throwing; thrown errors are never swallowed and remain available to the guard's unavailable/denial
|
|
433
|
-
classification. The returned identity requires a positive `userId`, non-
|
|
434
|
-
|
|
433
|
+
classification. The returned identity requires a positive `userId`, non-empty string `scopeIds`, and a non-empty
|
|
434
|
+
`authSubject`. A scope may be a numeric database id serialized as a string or a domain UUID such as an organization
|
|
435
|
+
or venue id. The bridge compares the subject before
|
|
435
436
|
session activation, immediately before the coordinator commits through a composite lease, and around remote resume.
|
|
436
437
|
Optional `isIdentityCurrent` can add provider object-identity checks. `onRemoteResumed` receives the identity, phase,
|
|
437
438
|
route state, and post-grant lease for safe redirects or other product side effects. Default recovery availability
|
|
@@ -505,16 +506,18 @@ provideOffline({
|
|
|
505
506
|
});
|
|
506
507
|
```
|
|
507
508
|
|
|
508
|
-
SQLite
|
|
509
|
-
`
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
509
|
+
Every SQLite entity uses an immutable client-generated UUID as `localId`; the outbox references only
|
|
510
|
+
`aggregateLocalId`. Remote identity is declared per entity:
|
|
511
|
+
|
|
512
|
+
| Remote identity | SQLite representation | Executor target |
|
|
513
|
+
| ------------------------------- | --------------------------------------------- | ----------------------------------------- |
|
|
514
|
+
| `serverId()` | nullable `server_id` | `{ localId, serverId }` |
|
|
515
|
+
| `naturalKey(['a', 'b'])` | mapped `a`/`b` columns; no `server_id` column | `{ localId, serverId: null, naturalKey }` |
|
|
516
|
+
| no remote identity (local-only) | mapped values only | `{ localId, serverId: null }` |
|
|
513
517
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
| `serverId` | `server_id` | `NULL` for a new entity | positive server `AUTO_INCREMENT` id |
|
|
518
|
+
A successful numeric create adds `serverId` without replacing `localId`. A natural key is derived from current
|
|
519
|
+
mapped values in declaration order; it is not duplicated as hidden row metadata. Entity projection and outbox
|
|
520
|
+
append/removal are committed in one local transaction.
|
|
518
521
|
|
|
519
522
|
The write lifecycle is: update the replica immediately → append an outbox command in the same transaction → render
|
|
520
523
|
the optimistic value → replay in the background → validate the server revision → store the confirmed value and
|
|
@@ -527,9 +530,10 @@ may lower these limits with `outboxLimits: { maxCommandsPerUser, maxBytesPerUser
|
|
|
527
530
|
existing replica and Outbox remain unchanged and enqueue rejects with `OfflineOutboxCapacityError`, so the UI can ask
|
|
528
531
|
the user to reconnect or resolve/discard an attention item.
|
|
529
532
|
|
|
530
|
-
`serverId()`
|
|
531
|
-
|
|
532
|
-
|
|
533
|
+
Use `serverId()` for a positive safe-integer `AUTO_INCREMENT` key. Use `naturalKey([...])` when the product table's
|
|
534
|
+
remote identity is an existing composite primary key. Natural-key components must be required mapped `text()` or
|
|
535
|
+
`integer()` columns; nullable, ignored, JSON, empty declarations, duplicates, and mixed `serverId()`/`naturalKey()`
|
|
536
|
+
declarations reject. Text components reject NUL, malformed Unicode, and values larger than 1,024 UTF-8 bytes.
|
|
533
537
|
|
|
534
538
|
When the application already knows the numeric server id but the first replica pull has not materialized the row,
|
|
535
539
|
pass that identity explicitly while adopting the entity. This is required for updates and especially deletes: an
|
|
@@ -537,7 +541,7 @@ omitted id would otherwise make the executor interpret the row as a not-yet-crea
|
|
|
537
541
|
|
|
538
542
|
```ts
|
|
539
543
|
await offlineSync.enqueue({
|
|
540
|
-
|
|
544
|
+
scopeId,
|
|
541
545
|
aggregateType: 'items',
|
|
542
546
|
aggregateLocalId: localId,
|
|
543
547
|
serverId: existingApiItem.id,
|
|
@@ -548,17 +552,21 @@ await offlineSync.enqueue({
|
|
|
548
552
|
```
|
|
549
553
|
|
|
550
554
|
The mapping is immutable and unique inside its effective replica scope. Reassigning one `localId` to another
|
|
551
|
-
`serverId
|
|
552
|
-
the
|
|
553
|
-
|
|
555
|
+
`serverId` or natural key, or assigning the same remote identity to another `localId`, rejects before persistence.
|
|
556
|
+
Web storage enforces the rule transactionally. SQLite uses a scoped partial unique index for `server_id` and a
|
|
557
|
+
scoped composite unique index over the natural-key columns: partition-scoped entities are unique per
|
|
558
|
+
user/partition/source, and user-scoped entities are unique per user/source across partitions. If an adopted row has
|
|
559
|
+
no confirmed baseline and
|
|
554
560
|
its final command is discarded, the local row is removed; the next pull may materialize the authoritative server
|
|
555
561
|
row again. A row with a confirmed baseline rolls back to that baseline instead.
|
|
556
562
|
|
|
557
563
|
Each synchronization cycle pulls authoritative server deltas before replaying the outbox. Every page carries the
|
|
558
|
-
replica schema version/hash and advances a durable user/
|
|
564
|
+
replica schema version/hash and advances a durable user/partition cursor in the same transaction as its rows. A schema
|
|
559
565
|
mismatch, malformed row, or non-advancing cursor rejects synchronization without advancing that cursor. If a remote
|
|
560
566
|
revision changed while a local command is pending, the optimistic row remains visible and both row and command move
|
|
561
|
-
to `conflict`; the new server value is retained as the confirmed baseline.
|
|
567
|
+
to `conflict`; the new server value is retained as the confirmed baseline. A remote tombstone follows the same
|
|
568
|
+
retention rule: without pending commands it removes the row, while a pending row and its Outbox remain under
|
|
569
|
+
`remote_deleted` conflict so the user can resolve or discard them.
|
|
562
570
|
|
|
563
571
|
The command adapter must send `commandId` as the server-side idempotency key. The server persists that key with the
|
|
564
572
|
mutation and returns all keys represented by a delta row as `acknowledgedCommandIds`. This correlation is required:
|
|
@@ -575,8 +583,22 @@ shape or `null` to delete a row. Identity and sync metadata (`localId`, `serverI
|
|
|
575
583
|
`syncState`) stay outside the callback. The bundle fingerprint hashes `version`, entity layouts, and
|
|
576
584
|
migration `fromVersion`/`statements` — never function bodies.
|
|
577
585
|
|
|
586
|
+
Changing a natural-key component list or its order changes the schema fingerprint and SQLite unique index. For a
|
|
587
|
+
released schema, bump `version`; native migration SQL must `DROP INDEX` and recreate the scoped composite index, and
|
|
588
|
+
`migrateWebRow` must preserve every natural-key value. Keep the transaction journal and schema-migration recovery
|
|
589
|
+
records until the replacement rows, index, and metadata commit together. This natural-key API is currently
|
|
590
|
+
unreleased, so adopting it before the first release needs no compatibility helper or legacy-row migration.
|
|
591
|
+
|
|
578
592
|
```typescript
|
|
579
|
-
import {
|
|
593
|
+
import {
|
|
594
|
+
defineOfflineReplicaSchema,
|
|
595
|
+
defineReplicaEntity,
|
|
596
|
+
integer,
|
|
597
|
+
naturalKey,
|
|
598
|
+
provideOffline,
|
|
599
|
+
serverId,
|
|
600
|
+
text,
|
|
601
|
+
} from '@rdlabo/ionic-angular-kit/offline';
|
|
580
602
|
|
|
581
603
|
// This is the Hono package's existing `typeof items.$inferSelect` export.
|
|
582
604
|
import type { Items as ItemSelect } from '@product/hono/db/schema';
|
|
@@ -584,7 +606,7 @@ import type { Items as ItemSelect } from '@product/hono/db/schema';
|
|
|
584
606
|
const itemEntityV2 = defineReplicaEntity<ItemSelect>()({
|
|
585
607
|
table: 'items',
|
|
586
608
|
sourceKey: 'items',
|
|
587
|
-
scope: '
|
|
609
|
+
scope: 'partition',
|
|
588
610
|
fields: {
|
|
589
611
|
id: serverId(),
|
|
590
612
|
title: text(),
|
|
@@ -592,9 +614,28 @@ const itemEntityV2 = defineReplicaEntity<ItemSelect>()({
|
|
|
592
614
|
},
|
|
593
615
|
});
|
|
594
616
|
|
|
617
|
+
// Mirrors a product DB TableScheme whose primary key is (favFrom, favTo).
|
|
618
|
+
type FavoriteSelect = {
|
|
619
|
+
favFrom: number;
|
|
620
|
+
favTo: number;
|
|
621
|
+
label: string;
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const favoriteEntity = defineReplicaEntity<FavoriteSelect>()({
|
|
625
|
+
table: 'favorites',
|
|
626
|
+
sourceKey: 'favorites',
|
|
627
|
+
scope: 'user',
|
|
628
|
+
identity: naturalKey(['favFrom', 'favTo']),
|
|
629
|
+
fields: {
|
|
630
|
+
favFrom: integer(),
|
|
631
|
+
favTo: integer(),
|
|
632
|
+
label: text(),
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
|
|
595
636
|
const replicaSchema = defineOfflineReplicaSchema({
|
|
596
637
|
version: 2,
|
|
597
|
-
entities: [itemEntityV2],
|
|
638
|
+
entities: [itemEntityV2, favoriteEntity],
|
|
598
639
|
migrations: [
|
|
599
640
|
{
|
|
600
641
|
fromVersion: 1,
|
|
@@ -621,11 +662,12 @@ not a compatibility option: without strict null checking, TypeScript cannot dist
|
|
|
621
662
|
from a required one and the schema lock cannot prove the SQLite mapping.
|
|
622
663
|
|
|
623
664
|
The schema definition must import the Hono package's exported `$inferSelect` type and map every key exactly once as
|
|
624
|
-
a SQLite column, `serverId()`, or `ignored(reason)
|
|
665
|
+
a SQLite column, `serverId()`, or `ignored(reason)`. A remotely replicated entity declares either one numeric
|
|
666
|
+
`serverId()` or one ordered `naturalKey([...])`; a local-only projection declares neither.
|
|
625
667
|
Nullable Hono columns require `nullable(...)`; non-null columns reject it. Therefore adding,
|
|
626
668
|
removing, or changing nullability of a Drizzle column breaks the app build until its replica mapping is updated.
|
|
627
|
-
At runtime, `values` contains only the mapped column projection; `localId` and `serverId` remain dedicated
|
|
628
|
-
fields and ignored server fields are never persisted.
|
|
669
|
+
At runtime, `values` contains only the mapped column projection; `localId` and numeric `serverId` remain dedicated
|
|
670
|
+
replica fields, natural identity is always derived from `values`, and ignored server fields are never persisted.
|
|
629
671
|
|
|
630
672
|
- **Status classification**: `0`→`onNetworkError` (connected only), `429`→`onRateLimited`, `502/503/504`→`onServerBusy`, `400/422/500`+message→`onServerError`, `401`→`onUnauthorized`, `403`→`onForbidden`. Other statuses (e.g. `404`) are left to the caller.
|
|
631
673
|
- **Universal 60s timeout** — every request fails with a synthetic (retryable) `408` if it hangs for 60s. Deliberately generous (catches a dead server without cutting off a large upload / AI generation; `timeout({ each })` resets per emission, so streaming is unaffected). Not configurable — one fleet-wide behavior.
|