@anfenn/zync 0.3.2 → 0.3.4
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 +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@anfenn/zync)
|
|
4
4
|
|
|
5
|
-
Simple, bullet-proof, offline-first sync middleware for Zustand.
|
|
5
|
+
Simple, unopinionated, bullet-proof, offline-first sync middleware for Zustand.
|
|
6
6
|
|
|
7
7
|
**_STATUS_**: Actively developed in alpha stage while requirements are being understood. Api may change, requests are welcome.
|
|
8
8
|
|
|
@@ -28,10 +28,13 @@ Simple, bullet-proof, offline-first sync middleware for Zustand.
|
|
|
28
28
|
|
|
29
29
|
- Client records will have a `_localId` field which is stable and never sent to the server. It is ideal for use as a key in JSX. The provided helper function `nextLocalId()` returns a UUID, but you could use any unique value
|
|
30
30
|
- Server records must have:
|
|
31
|
+
|
|
31
32
|
- `id`: Any datatype, can be a server OR client assigned value
|
|
32
33
|
- `updated_at`: Server assigned **_millisecond_** timestamp (db trigger or api layer). The client will never send this as the client clock is unlikely to be in sync with the server, so is never used for change detection. If it has a higher precision than millisecond, like PostgreSQL's microsecond timestampz, updates could be ignored.
|
|
33
34
|
- `deleted`: Boolean, used for soft deletes, to allow other clients to download deleted records to keep their local records in sync
|
|
34
35
|
|
|
36
|
+
**_TIP: If your endpoint doesn't have the same names as the 3 fields above, you can map them in your `api.ts` file e.g. `deleted` -> `isDeleted`_**
|
|
37
|
+
|
|
35
38
|
## Quickstart
|
|
36
39
|
|
|
37
40
|
```bash
|
|
@@ -201,8 +204,8 @@ async function add(item: any): Promise<any | undefined> {
|
|
|
201
204
|
throw new Error(error.message);
|
|
202
205
|
}
|
|
203
206
|
|
|
204
|
-
if (data
|
|
205
|
-
//
|
|
207
|
+
if (data?.length > 0) {
|
|
208
|
+
// Return server id if not using client assigned id's, and any other fields you want merged in
|
|
206
209
|
return { id: data[0].id };
|
|
207
210
|
}
|
|
208
211
|
}
|