{"id":23037331,"url":"https://github.com/saostad/sync-engine","last_synced_at":"2025-07-21T08:02:03.816Z","repository":{"id":233542333,"uuid":"785037435","full_name":"saostad/sync-engine","owner":"saostad","description":"One-Way Syncing Engine to transform data, detect inserted, updated, and deleted records, and perform synchronization.","archived":false,"fork":false,"pushed_at":"2024-06-05T21:42:35.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T21:44:54.476Z","etag":null,"topics":["sync-engine","synchronization"],"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/saostad.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":"2024-04-11T04:08:05.000Z","updated_at":"2024-06-05T21:42:39.000Z","dependencies_parsed_at":"2024-04-16T16:43:20.799Z","dependency_job_id":"f8fae8ca-6301-4953-9bd8-753691975cf3","html_url":"https://github.com/saostad/sync-engine","commit_stats":null,"previous_names":["saostad/sync-engine"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/saostad/sync-engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saostad%2Fsync-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saostad%2Fsync-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saostad%2Fsync-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saostad%2Fsync-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saostad","download_url":"https://codeload.github.com/saostad/sync-engine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saostad%2Fsync-engine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266263057,"owners_count":23901353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["sync-engine","synchronization"],"created_at":"2024-12-15T17:32:53.720Z","updated_at":"2025-07-21T08:02:03.785Z","avatar_url":"https://github.com/saostad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Here's an updated version of your README file to include the new changes:\n\n---\n\n# One-Way Syncing Engine\n\nThis guide will walk you through the process of using the One-Way Syncing Engine to transform data, detect inserted, updated, and deleted records, and perform synchronization.\n\n## Step 1: Prepare the Data\n\nFirst, define the source and destination data arrays. In this example, we have `src` and `dst` arrays containing objects with specific properties.\n\n```ts\nconst src = [\n  { id: 1, company: 1, firstName: \"John\", lastName: \"Doe\", age: null },\n  { id: 1, company: 2, firstName: \"John\", lastName: \"Doe\", age: null },\n  { id: 2, company: 1, firstName: \"Jane\", lastName: \"Diana\", age: null },\n  { id: 4, company: 1, firstName: \"Rid\", lastName: \"Lomba\", age: 25 },\n  { id: 5, company: 1, firstName: \"Homa\", lastName: \"Shiri\", age: 30 },\n];\nconst dst = [\n  { id: 1, company: 1, FullName: \"John Doe\", bio: { age: null } },\n  { id: 3, company: 1, FullName: \"Doe Risko\", bio: { age: 30 } },\n  { id: 4, company: 1, FullName: \"Fids Almo\", bio: { age: 26 } },\n  { id: 5, company: 1, FullName: \"Homa Shiri\", bio: { age: 30 } },\n];\n```\n\n## Step 2: Create the Sync Engine\n\nCreate an instance of the `SyncEngine` class, providing the necessary configuration options:\n\n```ts\nconst engine = new SyncEngine\u003ctypeof src, typeof dst\u003e({\n  src,\n  dst,\n  mappings: [\n    {\n      dstField: \"FullName\",\n      updateVal: (row) =\u003e `${row.company}-${row.id}`,\n      insertVal: (row) =\u003e `${row.company}-${row.id}`,\n      fn: async (row) =\u003e {\n        await new Promise((resolve) =\u003e setTimeout(resolve, 100));\n        return `${row.firstName} ${row.lastName}`;\n      },\n    },\n    { dstField: \"id\", isKey: true, srcField: \"id\" },\n    { dstField: \"company\", isKey: true, fn: (row) =\u003e row.company },\n    {\n      dstField: \"bio\",\n      compareFn: (src, dst) =\u003e src.bio.age === dst.bio.age,\n      fn: (row) =\u003e ({ age: row.age }),\n    },\n  ],\n  syncFns: {\n    insertFn: async (row) =\u003e {\n      await new Promise((resolve) =\u003e setTimeout(resolve, 500));\n      return row.id;\n    },\n    deleteFn: (row) =\u003e row.id,\n    updateFn: async (row, fields) =\u003e {\n      await new Promise((resolve) =\u003e setTimeout(resolve, 1000));\n      return row.id;\n    },\n  },\n});\n```\n\nThe `mappings` option defines how the fields from the source data should be mapped to the destination data. The `syncFns` specifies the (Async or Sync) functions to be executed for inserting, deleting, and updating records.\n\n## Step 3 (Optional): Map the Fields\n\nCall the `mapFields()` method on the sync engine to map the fields from the source data to the destination data format.\n\n```ts\nconst mappings = await engine.mapFields();\nconsole.log(\"Mappings: \", JSON.stringify(mappings, null, 2));\n```\n\nThis will output the mapped fields in JSON format.\n\n## Step 4 (Optional): Get the Changes\n\nUse the `getChanges()` method to retrieve the inserted, deleted, and updated records.\n\n```ts\nconst changes = await engine.getChanges();\nconsole.log(\"inserted:\", changes.inserted);\nconsole.log(\"updated:\", changes.updated);\nconsole.log(\"deleted:\", changes.deleted);\n```\n\nThe output will show the changes detected by the sync engine.\n\n## Step 5 (Optional): Perform the Synchronization\n\nFinally, call the `sync()` method to execute the synchronization process based on the detected changes.\n\n```ts\nconst result = await engine.sync();\nconsole.log(\"Result: \", JSON.stringify(result, null, 2));\n```\n\nThe `sync()` method will run the insertFn, deleteFn, updateFn provided in syncFns and return the result of the synchronization, indicating the inserted, deleted, and updated records.\n\nThat's it! You have now successfully used the One-Way Syncing Engine to transform data, detect changes, and perform synchronization.\n\n## Additional Tips\n\n- Make sure to handle errors and edge cases appropriately.\n- Customize the `syncFns` and `mappings` options to fit your specific use case.\n- Use the `getChanges()` method to inspect the detected changes before performing the synchronization.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaostad%2Fsync-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaostad%2Fsync-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaostad%2Fsync-engine/lists"}