Skip to content

Commit fc56775

Browse files
authored
Merge pull request #30 from eijawerner/export-json-struct
export json struct function and types
2 parents 7073c96 + 39d2d24 commit fc56775

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/bright-vans-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/graph-schema-utils": patch
3+
---
4+
5+
exported json struct functions and types

packages/graph-schema-utils/src/formatters/json/extensions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export function toJson(
4949
schema: GraphSchema,
5050
space: string | number | undefined = undefined
5151
) {
52+
const out = toJsonStruct(schema);
53+
return JSON.stringify(out, null, space);
54+
}
55+
56+
export function toJsonStruct(schema: GraphSchema): RootSchemaJsonStruct {
5257
const labels = schema.nodeLabels
5358
.sort((a, b) => (a.$id < b.$id ? -1 : 1))
5459
.map(nodeLabel.extract);
@@ -90,11 +95,15 @@ export function toJson(
9095
},
9196
},
9297
};
93-
return JSON.stringify(out, null, space);
98+
return out;
9499
}
95100

96101
export function fromJson(schema: string): GraphSchema {
97102
const schemaJson = JSON.parse(schema) as RootSchemaJsonStruct;
103+
return fromJsonStruct(schemaJson);
104+
}
105+
106+
export function fromJsonStruct(schemaJson: RootSchemaJsonStruct): GraphSchema {
98107
const { graphSchema } = schemaJson.graphSchemaRepresentation;
99108
const labels = graphSchema.nodeLabels.map(nodeLabel.create);
100109
const relationshipTypes = graphSchema.relationshipTypes.map(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from "./types.js";
12
export { toJson, fromJson, VERSION } from "./extensions.js";

0 commit comments

Comments
 (0)