Skip to content

Commit

Permalink
Merge pull request #191 from dotindustries/fix/update_extended_type_s…
Browse files Browse the repository at this point in the history
…upport

fix: update extended type support
  • Loading branch information
nadilas authored Jan 5, 2025
2 parents 4c891e3 + 2af16ad commit c0b5dc0
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 8 deletions.
131 changes: 131 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/ogre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"license": "MIT",
"dependencies": {
"fast-json-patch": "^3.1.1",
"jsondiffpatch": "^0.6.0",
"fflate": "^0.8.2",
"tslib": "^2.6.2"
},
Expand All @@ -41,7 +42,8 @@
"ts-node": "^10.8.1",
"tsx": "^4.7.1",
"typescript": "^5.4.4",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"superjson": "^2.2.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down
62 changes: 60 additions & 2 deletions packages/ogre/src/repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test } from "tap";
import superjson from "superjson";

import { Repository } from "./repository.js";
import {
Expand All @@ -12,6 +13,7 @@ import {
} from "./test.utils.js";
import { Reference } from "./interfaces.js";
import { compare } from "fast-json-patch";
import {objectToTree, treeToObject} from "./serialize.js";

test("diff is ok", async (t) => {
const [repo, obj] = await getBaseline();
Expand Down Expand Up @@ -44,10 +46,10 @@ test("restore", async (t) => {
t.test("history check", async (t) => {
const [repo, wrapped] = await getBaseline();

let changeEntries = updateHeaderData(wrapped);
updateHeaderData(wrapped);
await repo.commit("header data", testAuthor);

changeEntries += addOneNested(wrapped);
addOneNested(wrapped);
const firstStep = await repo.commit("first step", testAuthor);

const history = repo.getHistory();
Expand Down Expand Up @@ -76,6 +78,62 @@ test("restore", async (t) => {
);
});

t.test("date stays date", async (t) => {
/**
* Serialize an object to a string using the Ogre library.
* This is useful for storing and retrieving objects in a repository.
* @param obj
*/
const serializeObject = async (obj: any) => {
return objectToTree(obj, superjson.stringify)
}

/**
* Deserialize an object from a string using the Ogre library.
* This is useful for retrieving objects from a repository.
* @param str
*/
const deserializeObject = async <T>(str: string) => {
return treeToObject(str, superjson.parse<T>)
}

const [repo, wrapped] = await getBaseline(
undefined,
serializeObject,
deserializeObject
);

updateHeaderData(wrapped);
wrapped.aDate = new Date();
await repo.commit("header data", testAuthor);

t.equal(repo.getHistory().commits.length, 1, "incorrect # of commits");

const repo2 = new Repository<ComplexObject>(
{},
{
history: repo.getHistory(),
overrides: {
serializeObjectFn: serializeObject,
deserializeObjectFn: deserializeObject
},
},
);
await repo2.isReady();

t.equal(repo2.data.aDate instanceof Date, true, "date is not a date");
t.matchStrict(
repo2.data,
repo.data,
"restored object does not equal last version.",
);
t.equal(
sumChanges(repo2.getHistory().commits),
sumChanges(repo.getHistory().commits),
"incorrect # of changelog entries",
);
});

t.test("reconstruct with 2 commits", async (t) => {
const [repo, wrapped] = await getBaseline();

Expand Down
Loading

0 comments on commit c0b5dc0

Please sign in to comment.