feat: add standard offline sync runtime - #28
Merged
Conversation
✅ Deploy Preview for rdlabo-ionic-angular-library ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Adds a new optional @rdlabo/ionic-angular-kit/offline secondary entry point that provides a standard offline runtime (scoped cache + durable outbox + session boundary) without impacting existing consumers of the primary kit entry point.
Changes:
- Introduces the
/offlinesecondary entry point with repository abstractions (web: Ionic Storage; native: encrypted Capawesome SQLite) plus sync/coordinator/session services. - Adds an offline request-policy interceptor supporting cache fallback for transport failures and queued mutation responses.
- Updates kit docs and build/test wiring to include the new offline entry point and its test suite.
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/kit/tsconfig.spec.json | Includes offline specs in kit test compilation. |
| projects/kit/src/public-api.ts | Documents /offline as a separate secondary entry point. |
| projects/kit/README.md | Adds consumer-facing setup/installation docs for the offline runtime. |
| projects/kit/package.json | Adds optional peer dependency metadata for Capawesome SQLite. |
| projects/kit/offline/src/public-api.ts | Exposes the offline runtime public surface. |
| projects/kit/offline/src/lib/sqlite-offline-repository.ts | Implements encrypted native persistence via Capawesome SQLite. |
| projects/kit/offline/src/lib/sqlite-offline-repository.spec.ts | Verifies SQLite adapter behaviors (transactions, key presence, sequencing). |
| projects/kit/offline/src/lib/offline.interceptor.ts | Adds interceptor behavior for read caching and queued mutations. |
| projects/kit/offline/src/lib/offline.interceptor.spec.ts | Tests interceptor behavior (bypass, cache fallback, persistence error reporting). |
| projects/kit/offline/src/lib/offline-sync.service.ts | Implements aggregate-ordered outbox replay with retries and session guards. |
| projects/kit/offline/src/lib/offline-sync.service.spec.ts | Tests sync ordering, hash stability, classification, and session/flush races. |
| projects/kit/offline/src/lib/offline-session.service.ts | Adds shared-device session boundary + scope management. |
| projects/kit/offline/src/lib/offline-session.service.spec.ts | Tests session activation and shared-device isolation semantics. |
| projects/kit/offline/src/lib/offline-request-policy.ts | Defines DI-driven request policy resolution and bypass/header conventions. |
| projects/kit/offline/src/lib/offline-repository.ts | Defines the repository contract and the Ionic Storage (web) implementation. |
| projects/kit/offline/src/lib/offline-repository.spec.ts | Tests web repository scoping, ordering, ID allocation, and schema migration behavior. |
| projects/kit/offline/src/lib/offline-provider.ts | Adds provideOffline(...) to wire the runtime via Angular DI. |
| projects/kit/offline/src/lib/offline-network.service.ts | Adds offline/online/unverified network state tracking for runtime decisions. |
| projects/kit/offline/src/lib/offline-kit-options.ts | Defines DI options for native encrypted persistence. |
| projects/kit/offline/src/lib/offline-error-reporter.ts | Adds background persistence error reporting contract + default reporter. |
| projects/kit/offline/src/lib/offline-coordinator.service.ts | Provides a high-level coordinator API for app integration (init, logout, flush). |
| projects/kit/offline/src/lib/offline-command-hooks.ts | Adds optional product hooks for cache projection and command cleanup. |
| projects/kit/offline/src/lib/offline-command-executor.ts | Defines the product adapter interface for executing offline commands. |
| projects/kit/offline/ng-package.json | Declares the new ng-packagr secondary entry point. |
| package-lock.json | Updates lockfile to reflect package output/versioning alignment. |
| angular.json | Includes offline specs in Angular test configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+6
to
+7
| import { OFFLINE_ERROR_REPORTER, type OfflineErrorReporter } from './offline-error-reporter'; | ||
| import { isOfflineFallbackError } from './offline-network.service'; |
Comment on lines
+15
to
+34
| export const offlineInterceptor: HttpInterceptorFn = (request, next) => { | ||
| if (request.context.get(OFFLINE_BYPASS)) return next(request); | ||
| const registry = inject(OfflineRequestPolicyRegistry); | ||
| const fallback = inject(OfflineRequestFallbackService); | ||
| const errorReporter = inject(OFFLINE_ERROR_REPORTER); | ||
| const plan = registry.resolve(request); | ||
| if (!plan) return next(request); | ||
| if (plan.kind === 'mutation') { | ||
| if (plan.enqueue) return enqueueMutation(plan.enqueue, request.urlWithParams); | ||
| if (!plan.storeFresh) return next(request); | ||
| return observeRemoteResponse(next(request), plan.storeFresh, errorReporter, request); | ||
| } | ||
| if (request.method !== 'GET') return next(request); | ||
| return observeRemoteResponse( | ||
| defer(() => next(request)), | ||
| plan.storeFresh, | ||
| errorReporter, | ||
| request, | ||
| ).pipe(catchError((error: unknown) => fallback.handle(request, error, plan) ?? throwError(() => error))); | ||
| }; |
Comment on lines
+350
to
+354
| provideOffline({ | ||
| // ...product policies and executor | ||
| sqlitePlugin: Sqlite, | ||
| encryptionKey: () => securePreferences.get({ key: 'offline-database-key' }).then(({ value }) => value), | ||
| }); |
Comment on lines
+29
to
+30
| @Injectable({ providedIn: 'root' }) | ||
| export class OfflineSyncService { |
| } | ||
|
|
||
| async #open(): Promise<void> { | ||
| if (!this.#sqlite) throw new Error('Native offline storage requires the Capawesome Sqlite plugin'); |
rdlabo
marked this pull request as draft
July 22, 2026 11:30
rdlabo
marked this pull request as ready for review
July 22, 2026 13:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Compatibility
Verification