Search by

pushinbr / pam-native-sync

DavidWilliamBalbino

Offline-first outbox, cursors, conflict resolution and incremental synchronization for PAM Native.

Package info

github.com/push-in/pam-native-sync

Type:pam-native-plugin

pkg:composer/pushinbr/pam-native-sync

Statistics

Installs: 969

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.1 2026-08-25 22:03 UTC

This package is auto-updated.

Last update: 2026-11-29 10:38:21 UTC


README

pam-native-sync: Offline-first outbox, resumable cursors and explicit conflicts for PAM Native apps.

Offline-first writes with explicit conflicts and resumable cursors.
An idempotent outbox, ordered batches, incremental pulls, tombstones, retry budgets and deterministic conflict policies above PAM Native SQLite and any transport.

Packagist Latest release PHP 8.5 CI License

Install · Quick example · Platforms · CRDTs · Docs · Issues

Install

Inside a PAM Native project, add only this capability:

pam composer require pushinbr/pam-native-sync
pam doctor --fix

New to PAM? Create a project with pam init my-app --template native (see the PAM Native overview), then come back here. Composer owns the manifest and the lockfile; pam composer runs it on PAM's verified PHP runtime.

Quick example

use Pam\Native\Sync\ConflictPolicy;
use Pam\Native\Sync\PolicyConflictResolver;
use Pam\Native\Sync\Storage\SQLiteSyncStore;
use Pam\Native\Sync\SyncEngine;
use Pam\Native\Sync\SyncRunReport;
use Pam\Native\Sync\Transport\HttpSyncTransport;

$transport = new HttpSyncTransport(
    endpoint: 'https://api.example.com/sync',
    clientIdentifier: $deviceId,
    tokenProvider: fn (): ?string => $session->accessToken(),
);

$engine = new SyncEngine(
    new SQLiteSyncStore(),
    $transport,
    new PolicyConflictResolver(ConflictPolicy::LastWriteWins),
);

$engine->upsert('todos', 'todo-42', ['title' => 'Ship'], 7, fn ($operation) => null);
$engine->synchronize(fn (SyncRunReport $report) => null);

SyncTransport is provider-neutral. The built-in HttpSyncTransport speaks the documented JSON protocol and works with Laravel, PAM HTTP or any other compatible server without adding a backend package to the app. SQLite writes are prepared, and remote changes plus cursor advancement are committed in one native transaction. Server versions are monotonic, so stale pulls cannot overwrite newer replicas.

Platform support

Platform Support Notes
Android API 26+ No runtime permissions declared
iOS 15.0+ No usage descriptions declared
PAM Native 0.8.0 to < 2.0.0 From pam-native.plugin.json; PHP 8.5+

What you can build

  • Field apps that must work without signal
  • Collaborative records and optimistic edits
  • Incremental synchronization of large local datasets

This is an offline-first synchronization engine, not a database wrapper, and it does not prescribe an application vertical.

Native path Durable outbox · Cursor protocol
Application model Composer package + generated native integration
Design rule Independent module; no feed, vertical or application template bundled

Local-first CRDTs

For collaboration that must converge before a server answers, the package also ships backend-free primitives: HybridLogicalClock, LogicalTimestamp and LastWriteWinsMap. Clocks remain monotonic when wall clocks move backwards; map snapshots retain tombstones and merge deterministically across replicas.

$clock = new Pam\Native\Sync\Crdt\HybridLogicalClock($deviceId);
$document = new Pam\Native\Sync\Crdt\LastWriteWinsMap();
$document->assign('title', 'Offline edit', $clock->tick());

// Exchange snapshots through any transport, then merge in either order.
$remote = Pam\Native\Sync\Crdt\LastWriteWinsMap::restore($payload);
$document->merge($remote);

CRDTs do not require pam-native-sync-laravel, PAM HTTP or a specific cloud. Persistence and transport remain explicit application choices.

Server side

The client is backend-agnostic and never installs or references a server package. If your backend is Laravel, pam-native-sync-laravel implements the same protocol on the server.

Docs

Part of the PAM ecosystem

PAM

PAM runs PHP natively on servers, desktops and phones. This repository is one piece of it.

PAM PAM Desktop PAM Native Ecosystem
the runtime and CLI native desktop apps in PHP native Android and iOS apps in PHP every official package and plugin

Docs: push-in.github.io/pam-docs · Issues

Apache License 2.0 · Made in Brazil by Pushin