{"id":42113657,"url":"https://github.com/serenysoft/rxdb-orion","last_synced_at":"2026-01-26T14:02:29.483Z","repository":{"id":186119148,"uuid":"674664577","full_name":"serenysoft/rxdb-orion","owner":"serenysoft","description":"RxDB - Replication with Laravel Orion","archived":false,"fork":false,"pushed_at":"2025-08-27T18:10:22.000Z","size":107,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-28T10:29:26.434Z","etag":null,"topics":["laravel","orion","replication","rxdb","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serenysoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-04T13:35:41.000Z","updated_at":"2025-08-27T18:10:26.000Z","dependencies_parsed_at":"2024-12-20T13:29:26.218Z","dependency_job_id":"24fd9949-c959-45bd-b75e-d5920547637e","html_url":"https://github.com/serenysoft/rxdb-orion","commit_stats":null,"previous_names":["serenysoft/rxdb-orion"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/serenysoft/rxdb-orion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serenysoft%2Frxdb-orion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serenysoft%2Frxdb-orion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serenysoft%2Frxdb-orion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serenysoft%2Frxdb-orion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serenysoft","download_url":"https://codeload.github.com/serenysoft/rxdb-orion/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serenysoft%2Frxdb-orion/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28780032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","orion","replication","rxdb","typescript"],"created_at":"2026-01-26T14:02:22.228Z","updated_at":"2026-01-26T14:02:29.460Z","avatar_url":"https://github.com/serenysoft.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [RxDB](https://rxdb.info) - Replication with [Laravel Orion](https://tailflow.github.io/laravel-orion-docs)\n\n[![Build Status](https://github.com/serenysoft/rxdb-orion/actions/workflows/ci.yml/badge.svg)](https://github.com/serenysoft/rxdb-orion/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/serenysoft/rxdb-orion/branch/master/graph/badge.svg?token=GANBHB4ZHS)](https://codecov.io/gh/serenysoft/rxdb-orion)\n\nThe Orion replication provides handlers for run replication with Orion REST API as the transportation layer.\n\n## Installation\n\n`npm i rxdb-orion`\n\n## Usage\n\nThe package usage is simple, but there are some important rules to follow\n\n### Frontend\n\n- Array properties with ref will be replicated using [`sync` route](https://tailflow.github.io/laravel-orion-docs/v2.x/guide/relationships.html#syncing)\n- For other relationship properties, a specific replication will be required for each one.\n\n```typescript\nimport { replicateOrion } from 'rxdb-orion';\nimport { userSchema } from './schemas/user';\nimport { roleSchema } from './schemas/role';\n\nconst database = await createRxDatabase({\n  name: 'mydb',\n  storage: getRxStorageDexie(),\n});\n\nawait database.addCollections({\n  users: {\n    schema: userSchema,\n  },\n  roles: {\n    schema: roleSchema,\n  },\n});\n\nconst replicationState = replicateOrion({\n  url: 'http://my.fake.api/users',\n  params: { include: 'roles' },\n  collection: users,\n  batchSize: 3,\n});\n\nawait replicationState.start();\n```\n\n#### Manager\n\nIt is common for an application to require handling multiple replications.\nFor this reason, the package includes the `Manager` class to assist in such situations.\n\nAs [Laravel Orion](https://tailflow.github.io/laravel-orion-docs) backend is unable to send events to the client,\nthe **manager** executes `reSync()` every `10000ms` by default.\n\nYou can customize the interval as you see fit.\n\n```typescript\nimport { replicateOrion, Manager } from 'rxdb-orion';\n\nconst manager = new Manager([\n  replicateOrion({\n    url: 'http://my.fake.api/users',\n    params: { include: 'roles' },\n    collection: users,\n    batchSize: 3,\n  }),\n  replicateOrion({\n    url: 'http://my.fake.api/categories',\n    collection: categories,\n    batchSize: 3,\n  }),\n], 5000);\n\nawait manager.start();\n```\n\n### Database\n\n\u003e **Important:**\n\u003e To ensure correct replication, define your `created_at`, `updated_at`, and `deleted_at` fields as `timestamp(6)` in your database migrations. This allows storage of milliseconds, which is required for accurate checkpointing and synchronization.\n\n```php\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreateCategoriesTable extends Migration\n{\n  public function up()\n  {\n    Schema::create('categories', function (Blueprint $table) {\n      $table-\u003euuid('id')-\u003eprimary();\n      $table-\u003estring('name');\n      $table-\u003etimestamps(6);\n      $table-\u003esoftDeletes(precision: 6);\n    });\n  }\n\n  public function down()\n  {\n    Schema::dropIfExists('categories');\n  }\n}\n```\n\n### Model\n\nThe package uses a [Scope](https://tailflow.github.io/laravel-orion-docs/v2.x/guide/search.html#filtering) to request all documents that have been written after the given checkpoint.\n\nTherefore, it is recommended to create a trait for making the necessary model customizations.\n\n```php\n\u003c?php\n\nnamespace App\\Traits;\n\ntrait Syncable {\n\n    /**\n     * Initialize the trait\n     *\n     * @return void\n     */\n    protected function initializeSyncable()\n    {\n        $this-\u003eappend('_deleted');\n    }\n\n    /**\n     * Prepare a date for array / JSON serialization.\n     *\n     * @param  \\DateTimeInterface  $date\n     * @return string\n     */\n    protected function serializeDate(DateTimeInterface $date)\n    {\n        $instance = $date instanceof DateTimeImmutable\n            ? CarbonImmutable::instance($date)\n            : Carbon::instance($date);\n\n        return $instance-\u003etoDateTimeString('millisecond');\n    }\n\n    /**\n     * Determine if model is deleted\n     *\n     * @return boolean\n     */\n    protected function getDeletedAttribute()\n    {\n        return $this-\u003edeleted_at !== null;\n    }\n\n    /**\n     * Scope a query to only include models changed after given value.\n     *\n     * @param  \\Illuminate\\Database\\Eloquent\\Builder  $query\n     * @param  int  $updatedAt\n     * @param  string  $id\n     * @return \\Illuminate\\Database\\Eloquent\\Builder\n     */\n      public function scopeMinUpdatedAt(Builder $query, string $updatedAt, ?string $id = null): Builder\n      {\n          return $query-\u003ewhere('updated_at', '\u003e', $updatedAt)\n              -\u003ewhen($id, fn($query) =\u003e\n                  $query-\u003eorWhere(function($query) use ($updatedAt, $id) {\n                      $query-\u003ewhere('updated_at', $updatedAt)-\u003ewhere('id', '\u003e', $id);\n                  })\n              )\n              -\u003eorderBy('updated_at');\n      }\n}\n\n```\n\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass User extends Model {\n\n    use Syncable;\n\n    ....\n}\n```\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserenysoft%2Frxdb-orion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserenysoft%2Frxdb-orion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserenysoft%2Frxdb-orion/lists"}