@wxn0brp/db-crdt 0.0.3 → 0.0.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/dist/rebuild.js CHANGED
@@ -1,10 +1,15 @@
1
1
  import { sortByIds } from "@wxn0brp/db-core";
2
2
  import { collectionPrefix } from "./static.js";
3
3
  export async function rebuild(db, collection) {
4
- const operations = await db.find(collectionPrefix + "/" + collection, {}).then(res => sortByIds(res));
4
+ const operations = await db.find(collectionPrefix + "/" + collection, {});
5
5
  await db.removeCollection(collection);
6
6
  const _db = db._target();
7
- for (const op of operations) {
7
+ const primaryDataOperations = operations.filter(op => op.p);
8
+ for (const op of primaryDataOperations) {
9
+ await _db.add(collection, op.p, false);
10
+ }
11
+ const modificationOperations = sortByIds(operations.filter(op => !op.p));
12
+ for (const op of modificationOperations) {
8
13
  if (op.a) {
9
14
  await _db.add(collection, op.a, false);
10
15
  }
package/dist/snapshot.js CHANGED
@@ -4,6 +4,6 @@ export async function makeSnapshot(db, collection) {
4
4
  await db.removeCollection(collectionPrefix + "/" + collection);
5
5
  await db._target().updateOneOrAdd(collectionPrefix, { _id: collection }, { time: Date.now() });
6
6
  for (const d of data) {
7
- await db._target().add(collectionPrefix + "/" + collection, d, false);
7
+ await db._target().add(collectionPrefix + "/" + collection, { p: d }, false);
8
8
  }
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-crdt",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "CRDT integration for ValtheraDB",
@@ -13,13 +13,13 @@
13
13
  "url": "https://github.com/wxn0brP/ValtheraDB-crdt.git"
14
14
  },
15
15
  "devDependencies": {
16
- "@types/node": "*",
16
+ "@types/bun": "*",
17
17
  "@wxn0brp/db": "^0.41.0",
18
18
  "tsc-alias": "*",
19
19
  "typescript": "*"
20
20
  },
21
21
  "peerDependencies": {
22
- "@wxn0brp/db-core": ">=0.3.0"
22
+ "@wxn0brp/db-core": ">=0.3.2"
23
23
  },
24
24
  "files": [
25
25
  "dist"