Skip to content

Commit

Permalink
feat(lyra): adds possibility to save and load Lyra schema
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Aug 9, 2022
1 parent 0661601 commit 290c8a2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1,121 deletions.
11 changes: 9 additions & 2 deletions packages/lyra/src/lyra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Data<S extends PropertiesSchema> = {
docs: Record<string, ResolveSchema<S> | undefined>;
index: Index;
nodes: Nodes;
schema: S;
};

export interface Lyra<S extends PropertiesSchema> extends Data<S> {
Expand Down Expand Up @@ -307,15 +308,21 @@ export function search<S extends PropertiesSchema>(
}

export function save<S extends PropertiesSchema>(lyra: Lyra<S>): Data<S> {
return { index: lyra.index, docs: lyra.docs, nodes: lyra.nodes };
return {
index: lyra.index,
docs: lyra.docs,
nodes: lyra.nodes,
schema: lyra.schema,
};
}

export function load<S extends PropertiesSchema>(lyra: Lyra<S>, { index, docs, nodes }: Data<S>) {
export function load<S extends PropertiesSchema>(lyra: Lyra<S>, { index, docs, nodes, schema }: Data<S>) {
if (!lyra.edge) {
throw new Error(ERRORS.GETTER_SETTER_WORKS_ON_EDGE_ONLY("load"));
}

lyra.index = index;
lyra.docs = docs;
lyra.nodes = nodes;
lyra.schema = schema;
}
4 changes: 2 additions & 2 deletions packages/lyra/tests/lyra.edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ t.test("Edge getters", t => {
age: 37,
});

const { index, docs, nodes } = save(db2);
load(db, { index, docs, nodes });
const { index, docs, nodes, schema } = save(db2);
load(db, { index, docs, nodes, schema });

const search1 = search(db, { term: "Jane" });
const search2 = search(db, { term: "John" });
Expand Down
Loading

0 comments on commit 290c8a2

Please sign in to comment.