@neo4j/graph-schema-utils 1.0.0-next.1 → 1.0.0-next.10
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 +52 -1
- package/dist/formatters/json/extensions.d.ts +4 -0
- package/dist/formatters/json/extensions.js +360 -0
- package/dist/formatters/json/extensions.js.map +1 -0
- package/dist/formatters/json/index.d.ts +1 -0
- package/dist/formatters/json/index.js +2 -0
- package/dist/formatters/json/index.js.map +1 -0
- package/dist/formatters/json/types.d.ts +138 -0
- package/dist/formatters/json/types.js +17 -0
- package/dist/formatters/json/types.js.map +1 -0
- package/dist/formatters/llm-prompt/index.d.ts +3 -0
- package/dist/formatters/llm-prompt/index.js +102 -0
- package/dist/formatters/llm-prompt/index.js.map +1 -0
- package/dist/formatters/llm-prompt/types.d.ts +5 -0
- package/dist/formatters/llm-prompt/types.js +2 -0
- package/dist/formatters/llm-prompt/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/model/index.d.ts +116 -0
- package/dist/model/index.js +167 -0
- package/dist/model/index.js.map +1 -0
- package/dist/validation.d.ts +9 -0
- package/dist/validation.js +49 -0
- package/dist/validation.js.map +1 -0
- package/package.json +15 -8
- package/src/index.js +0 -4
- package/src/model/index.js +0 -330
- package/src/types.d.ts +0 -5
- package/src/validation.js +0 -65
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { PropertyBaseType, } from "../../model/index.js";
|
|
2
|
+
export function toTomaz(schema) {
|
|
3
|
+
let out = [`Node properties are the following:`].concat(schema.nodeObjectTypes.map(nodeObjectTypes).filter(Boolean), [`Relationship properties are the following:`], schema.relationshipObjectTypes.map(relationshipObjectTypes).filter(Boolean), [`The relationships are the following:`], JSON.stringify(schema.relationshipObjectTypes.map(paths)));
|
|
4
|
+
function nodeObjectTypes(nodeObjectType) {
|
|
5
|
+
const out = [];
|
|
6
|
+
const properties = nodeObjectType.getProperties().map((property) => {
|
|
7
|
+
const base = {
|
|
8
|
+
property: property.token,
|
|
9
|
+
type: formatPropertyType(property.type),
|
|
10
|
+
};
|
|
11
|
+
if (property.nullable) {
|
|
12
|
+
base.nullable = true;
|
|
13
|
+
}
|
|
14
|
+
return base;
|
|
15
|
+
});
|
|
16
|
+
if (!properties.length) {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
out.push({
|
|
20
|
+
properties: properties,
|
|
21
|
+
labels: nodeObjectType.labels.map((label) => label.token),
|
|
22
|
+
});
|
|
23
|
+
return JSON.stringify(out);
|
|
24
|
+
}
|
|
25
|
+
function relationshipObjectTypes(relationshipObjectType) {
|
|
26
|
+
const out = [];
|
|
27
|
+
const properties = relationshipObjectType
|
|
28
|
+
.getProperties()
|
|
29
|
+
.map((property) => {
|
|
30
|
+
const base = {
|
|
31
|
+
property: property.token,
|
|
32
|
+
type: formatPropertyType(property.type),
|
|
33
|
+
};
|
|
34
|
+
if (property.nullable) {
|
|
35
|
+
base.nullable = true;
|
|
36
|
+
}
|
|
37
|
+
return base;
|
|
38
|
+
});
|
|
39
|
+
if (!properties.length) {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
out.push({
|
|
43
|
+
labels: [relationshipObjectType.type.token],
|
|
44
|
+
properties: properties,
|
|
45
|
+
});
|
|
46
|
+
return JSON.stringify(out);
|
|
47
|
+
}
|
|
48
|
+
function paths(relationshipObjectType) {
|
|
49
|
+
return `(:${relationshipObjectType.from.labels
|
|
50
|
+
.map((label) => label.token)
|
|
51
|
+
.join(":")})-[:${relationshipObjectType.type.token}]->(:${relationshipObjectType.to.labels
|
|
52
|
+
.map((label) => label.token)
|
|
53
|
+
.join(":")})`;
|
|
54
|
+
}
|
|
55
|
+
return out.join("\n");
|
|
56
|
+
}
|
|
57
|
+
export function toOskars(schema) {
|
|
58
|
+
let out = [`Node types with their properties + types`].concat(schema.nodeObjectTypes.map(nodeObjectTypes), [`Relationship types with properties + types`], schema.relationshipObjectTypes.map(relationshipObjectTypes).filter(Boolean), [
|
|
59
|
+
`Paths (all combinations of node types and relationship types and the direction of the relationship)`,
|
|
60
|
+
], schema.relationshipObjectTypes.map(paths));
|
|
61
|
+
function nodeObjectTypes(nodeObjectType) {
|
|
62
|
+
const out = [];
|
|
63
|
+
const properties = nodeObjectType.getProperties().map((property) => {
|
|
64
|
+
return `${property.token}: ${formatPropertyType(property.type)}${property.nullable ? " (nullable)" : ""}`;
|
|
65
|
+
});
|
|
66
|
+
out.push(` (:${nodeObjectType.labels.map((label) => label.token).join(":")}${properties.length > 0 ? ` {${properties.join(", ")}}` : ""})`);
|
|
67
|
+
return out.join("\n");
|
|
68
|
+
}
|
|
69
|
+
function relationshipObjectTypes(relationshipObjectType) {
|
|
70
|
+
const out = [];
|
|
71
|
+
const properties = relationshipObjectType
|
|
72
|
+
.getProperties()
|
|
73
|
+
.map((property) => {
|
|
74
|
+
return `${property.token}: ${formatPropertyType(property.type)}${property.nullable ? " (nullable)" : ""}`;
|
|
75
|
+
});
|
|
76
|
+
if (!properties.length) {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
out.push(` [:${relationshipObjectType.type.token}${properties.length > 0 ? ` {${properties.join(", ")}}` : ""}]`);
|
|
80
|
+
return out.join("\n");
|
|
81
|
+
}
|
|
82
|
+
function paths(relationshipObjectType) {
|
|
83
|
+
const out = [];
|
|
84
|
+
out.push(` (:${relationshipObjectType.from.labels
|
|
85
|
+
.map((label) => label.token)
|
|
86
|
+
.join(":")})-[:${relationshipObjectType.type.token}]->(:${relationshipObjectType.to.labels
|
|
87
|
+
.map((label) => label.token)
|
|
88
|
+
.join(":")})`);
|
|
89
|
+
return out.join("\n");
|
|
90
|
+
}
|
|
91
|
+
return out.join("\n");
|
|
92
|
+
}
|
|
93
|
+
function formatPropertyType(type) {
|
|
94
|
+
if (Array.isArray(type)) {
|
|
95
|
+
return type.map(formatPropertyType).join("|");
|
|
96
|
+
}
|
|
97
|
+
if (type instanceof PropertyBaseType) {
|
|
98
|
+
return type.type;
|
|
99
|
+
}
|
|
100
|
+
return `${type.items.type}[]`;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/formatters/llm-prompt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,GAIjB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,UAAU,OAAO,CAAC,MAAmB;IACzC,IAAI,GAAG,GAAa,CAAC,oCAAoC,CAAC,CAAC,MAAM,CAC/D,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAC3D,CAAC,4CAA4C,CAAC,EAC9C,MAAM,CAAC,uBAAuB,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAC3E,CAAC,sCAAsC,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;IAEF,SAAS,eAAe,CAAC,cAA8B;QACrD,MAAM,GAAG,GAAG,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjE,MAAM,IAAI,GAA0B;gBAClC,QAAQ,EAAE,QAAQ,CAAC,KAAK;gBACxB,IAAI,EAAE,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC;aACxC,CAAC;YACF,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACvB,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,C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AC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,kBAAkB,CAAC,IAA2B;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,IAAI,YAAY,gBAAgB,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/formatters/llm-prompt/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { validateSchema, SchemaValidationError } from "./validation.js";
|
|
2
|
+
import * as model from "./model/index.js";
|
|
3
|
+
import * as json from "./formatters/json/index.js";
|
|
4
|
+
const formatters = { json };
|
|
5
|
+
export { model, formatters };
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAEnD,MAAM,UAAU,GAAG,EAAE,IAAI,EAAE,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export declare class GraphSchema {
|
|
2
|
+
nodeLabels: NodeLabel[];
|
|
3
|
+
relationshipTypes: RelationshipType[];
|
|
4
|
+
nodeObjectTypes: NodeObjectType[];
|
|
5
|
+
relationshipObjectTypes: RelationshipObjectType[];
|
|
6
|
+
constraints: Constraint[];
|
|
7
|
+
indexes: Index[];
|
|
8
|
+
constructor(nodeObjectTypes: NodeObjectType[], relationshipObjectTypes: RelationshipObjectType[], constraints?: Constraint[], indexes?: Index[]);
|
|
9
|
+
private extractNodeLabels;
|
|
10
|
+
private extractRelationshipTypes;
|
|
11
|
+
getAllNodeLabelTokens(): string[];
|
|
12
|
+
getAllRelationshipTypeTokens(): string[];
|
|
13
|
+
getAllPropertyTokens(): string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class NodeLabel {
|
|
16
|
+
$id: string;
|
|
17
|
+
token: string;
|
|
18
|
+
properties: Property[];
|
|
19
|
+
constructor(id: string, token: string, properties?: Property[]);
|
|
20
|
+
getPropertyTokens(): string[];
|
|
21
|
+
}
|
|
22
|
+
export declare class RelationshipType {
|
|
23
|
+
$id: string;
|
|
24
|
+
token: string;
|
|
25
|
+
properties: Property[];
|
|
26
|
+
constructor(id: string, token: string, properties?: Property[]);
|
|
27
|
+
getPropertyTokens(): string[];
|
|
28
|
+
}
|
|
29
|
+
export declare class NodeObjectType {
|
|
30
|
+
$id: string;
|
|
31
|
+
labels: NodeLabel[];
|
|
32
|
+
constructor(id: string, labels: NodeLabel[]);
|
|
33
|
+
getProperties(): Property[];
|
|
34
|
+
getPropertyTokens(): string[];
|
|
35
|
+
}
|
|
36
|
+
export declare class RelationshipObjectType {
|
|
37
|
+
$id: string;
|
|
38
|
+
type: RelationshipType;
|
|
39
|
+
from: NodeObjectType;
|
|
40
|
+
to: NodeObjectType;
|
|
41
|
+
constructor(id: string, type: RelationshipType, from: NodeObjectType, to: NodeObjectType);
|
|
42
|
+
getProperties(): Property[];
|
|
43
|
+
getPropertyTokens(): string[];
|
|
44
|
+
}
|
|
45
|
+
export type Constraint = NodeLabelConstraint | RelationshipTypeConstraint;
|
|
46
|
+
export type Index = NodeLabelIndex | RelationshipTypeIndex | LookupIndex;
|
|
47
|
+
export declare const isNodeLabelConstraint: (constraint: Constraint) => constraint is NodeLabelConstraint;
|
|
48
|
+
export declare const isRelationshipTypeConstraint: (constraint: Constraint) => constraint is RelationshipTypeConstraint;
|
|
49
|
+
export declare const isNodeLabelIndex: (index: Index) => index is NodeLabelIndex;
|
|
50
|
+
export declare const isRelationshipTypeIndex: (index: Index) => index is RelationshipTypeIndex;
|
|
51
|
+
export declare const isLookupIndex: (index: Index) => index is LookupIndex;
|
|
52
|
+
export declare class NodeLabelConstraint {
|
|
53
|
+
$id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
constraintType: ConstraintType;
|
|
56
|
+
nodeLabel: NodeLabel;
|
|
57
|
+
properties: Property[];
|
|
58
|
+
entityType: EntityType;
|
|
59
|
+
constructor($id: string, name: string, constraintType: ConstraintType, nodeLabel: NodeLabel, properties: Property[]);
|
|
60
|
+
}
|
|
61
|
+
export declare class RelationshipTypeConstraint {
|
|
62
|
+
$id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
constraintType: ConstraintType;
|
|
65
|
+
relationshipType: RelationshipType;
|
|
66
|
+
properties: Property[];
|
|
67
|
+
entityType: EntityType;
|
|
68
|
+
constructor($id: string, name: string, constraintType: ConstraintType, relationshipType: RelationshipType, properties: Property[]);
|
|
69
|
+
}
|
|
70
|
+
export declare class NodeLabelIndex {
|
|
71
|
+
$id: string;
|
|
72
|
+
name: string;
|
|
73
|
+
indexType: Exclude<IndexType, "lookup">;
|
|
74
|
+
entityType: EntityType;
|
|
75
|
+
nodeLabel: NodeLabel;
|
|
76
|
+
properties: Property[];
|
|
77
|
+
constructor($id: string, name: string, indexType: Exclude<IndexType, "lookup">, nodeLabel: NodeLabel, properties: Property[]);
|
|
78
|
+
}
|
|
79
|
+
export declare class RelationshipTypeIndex {
|
|
80
|
+
$id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
indexType: Exclude<IndexType, "lookup">;
|
|
83
|
+
entityType: EntityType;
|
|
84
|
+
relationshipType: RelationshipType;
|
|
85
|
+
properties: Property[];
|
|
86
|
+
constructor($id: string, name: string, indexType: Exclude<IndexType, "lookup">, relationshipType: RelationshipType, properties: Property[]);
|
|
87
|
+
}
|
|
88
|
+
export declare class LookupIndex {
|
|
89
|
+
$id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
entityType: EntityType;
|
|
92
|
+
indexType: IndexType;
|
|
93
|
+
constructor($id: string, name: string, entityType: EntityType);
|
|
94
|
+
}
|
|
95
|
+
export type ConstraintType = "uniqueness" | "propertyExistence" | "propertyType" | "key";
|
|
96
|
+
export type IndexType = "range" | "lookup" | "text" | "full-text" | "point" | "default";
|
|
97
|
+
export type EntityType = "node" | "relationship";
|
|
98
|
+
export type PropertyTypes = PropertyBaseType | PropertyArrayType;
|
|
99
|
+
export type PropertyTypeRecursive = PropertyTypes | Array<PropertyTypes | PropertyTypeRecursive[]>;
|
|
100
|
+
export declare class Property {
|
|
101
|
+
$id: string;
|
|
102
|
+
token: string;
|
|
103
|
+
type: PropertyTypeRecursive;
|
|
104
|
+
nullable: boolean;
|
|
105
|
+
constructor($id: string, token: string, type: PropertyTypeRecursive, nullable: boolean);
|
|
106
|
+
}
|
|
107
|
+
export declare class PropertyBaseType {
|
|
108
|
+
type: PrimitivePropertyTypes;
|
|
109
|
+
constructor(type: PrimitivePropertyTypes);
|
|
110
|
+
}
|
|
111
|
+
export declare class PropertyArrayType {
|
|
112
|
+
items: PropertyBaseType;
|
|
113
|
+
type: "array";
|
|
114
|
+
constructor(items: PropertyBaseType);
|
|
115
|
+
}
|
|
116
|
+
export type PrimitivePropertyTypes = "integer" | "string" | "float" | "boolean" | "point" | "date" | "datetime" | "time" | "localtime" | "localdatetime" | "duration";
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export class GraphSchema {
|
|
2
|
+
constructor(nodeObjectTypes, relationshipObjectTypes, constraints = [], indexes = []) {
|
|
3
|
+
this.nodeLabels = [];
|
|
4
|
+
this.relationshipTypes = [];
|
|
5
|
+
this.nodeObjectTypes = nodeObjectTypes;
|
|
6
|
+
this.relationshipObjectTypes = relationshipObjectTypes;
|
|
7
|
+
this.constraints = constraints;
|
|
8
|
+
this.indexes = indexes;
|
|
9
|
+
this.extractNodeLabels();
|
|
10
|
+
this.extractRelationshipTypes();
|
|
11
|
+
}
|
|
12
|
+
extractNodeLabels() {
|
|
13
|
+
const nodeLabels = this.nodeObjectTypes.flatMap((nodeObjectType) => nodeObjectType.labels);
|
|
14
|
+
this.nodeLabels = [...new Set(nodeLabels)];
|
|
15
|
+
}
|
|
16
|
+
extractRelationshipTypes() {
|
|
17
|
+
const relationshipTypes = this.relationshipObjectTypes.flatMap((relationshipObjectType) => relationshipObjectType.type);
|
|
18
|
+
this.relationshipTypes = [...new Set(relationshipTypes)];
|
|
19
|
+
}
|
|
20
|
+
getAllNodeLabelTokens() {
|
|
21
|
+
return this.nodeLabels.map((nodeLabel) => nodeLabel.token);
|
|
22
|
+
}
|
|
23
|
+
getAllRelationshipTypeTokens() {
|
|
24
|
+
return this.relationshipTypes.map((relationshipType) => relationshipType.token);
|
|
25
|
+
}
|
|
26
|
+
getAllPropertyTokens() {
|
|
27
|
+
const nodeProperties = this.nodeObjectTypes.flatMap((nodeObjectType) => nodeObjectType.getPropertyTokens());
|
|
28
|
+
const relationshipProperties = this.relationshipObjectTypes.flatMap((relationshipObjectType) => relationshipObjectType.getPropertyTokens());
|
|
29
|
+
// return all tokens without duplicates
|
|
30
|
+
return [...new Set([...nodeProperties, ...relationshipProperties])];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class NodeLabel {
|
|
34
|
+
constructor(id, token, properties = []) {
|
|
35
|
+
this.$id = id;
|
|
36
|
+
this.token = token;
|
|
37
|
+
this.properties = properties;
|
|
38
|
+
}
|
|
39
|
+
getPropertyTokens() {
|
|
40
|
+
return this.properties.map((property) => property.token);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class RelationshipType {
|
|
44
|
+
constructor(id, token, properties = []) {
|
|
45
|
+
this.$id = id;
|
|
46
|
+
this.token = token;
|
|
47
|
+
this.properties = properties;
|
|
48
|
+
}
|
|
49
|
+
getPropertyTokens() {
|
|
50
|
+
return this.properties.map((property) => property.token);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class NodeObjectType {
|
|
54
|
+
constructor(id, labels) {
|
|
55
|
+
this.$id = id;
|
|
56
|
+
this.labels = labels;
|
|
57
|
+
}
|
|
58
|
+
getProperties() {
|
|
59
|
+
return this.labels.flatMap((l) => l.properties);
|
|
60
|
+
}
|
|
61
|
+
getPropertyTokens() {
|
|
62
|
+
// return all tokens without duplicates
|
|
63
|
+
return [...new Set(this.getProperties().map((property) => property.token))];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class RelationshipObjectType {
|
|
67
|
+
constructor(id, type, from, to) {
|
|
68
|
+
this.$id = id;
|
|
69
|
+
this.type = type;
|
|
70
|
+
this.from = from;
|
|
71
|
+
this.to = to;
|
|
72
|
+
}
|
|
73
|
+
getProperties() {
|
|
74
|
+
return this.type.properties;
|
|
75
|
+
}
|
|
76
|
+
getPropertyTokens() {
|
|
77
|
+
// return all tokens without duplicates
|
|
78
|
+
return [...new Set(this.getProperties().map((property) => property.token))];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export const isNodeLabelConstraint = (constraint) => {
|
|
82
|
+
return constraint.entityType === "node" && "nodeLabel" in constraint;
|
|
83
|
+
};
|
|
84
|
+
export const isRelationshipTypeConstraint = (constraint) => {
|
|
85
|
+
return (constraint.entityType === "relationship" && "relationshipType" in constraint);
|
|
86
|
+
};
|
|
87
|
+
export const isNodeLabelIndex = (index) => {
|
|
88
|
+
return (index.entityType === "node" &&
|
|
89
|
+
index.indexType !== "lookup" &&
|
|
90
|
+
"nodeLabel" in index);
|
|
91
|
+
};
|
|
92
|
+
export const isRelationshipTypeIndex = (index) => {
|
|
93
|
+
return (index.entityType === "relationship" &&
|
|
94
|
+
index.indexType !== "lookup" &&
|
|
95
|
+
"relationshipType" in index);
|
|
96
|
+
};
|
|
97
|
+
export const isLookupIndex = (index) => {
|
|
98
|
+
return index.indexType === "lookup";
|
|
99
|
+
};
|
|
100
|
+
export class NodeLabelConstraint {
|
|
101
|
+
constructor($id, name, constraintType, nodeLabel, properties) {
|
|
102
|
+
this.$id = $id;
|
|
103
|
+
this.name = name;
|
|
104
|
+
this.constraintType = constraintType;
|
|
105
|
+
this.nodeLabel = nodeLabel;
|
|
106
|
+
this.properties = properties;
|
|
107
|
+
this.entityType = "node";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class RelationshipTypeConstraint {
|
|
111
|
+
constructor($id, name, constraintType, relationshipType, properties) {
|
|
112
|
+
this.$id = $id;
|
|
113
|
+
this.name = name;
|
|
114
|
+
this.constraintType = constraintType;
|
|
115
|
+
this.relationshipType = relationshipType;
|
|
116
|
+
this.properties = properties;
|
|
117
|
+
this.entityType = "relationship";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export class NodeLabelIndex {
|
|
121
|
+
constructor($id, name, indexType, nodeLabel, properties) {
|
|
122
|
+
this.$id = $id;
|
|
123
|
+
this.name = name;
|
|
124
|
+
this.nodeLabel = nodeLabel;
|
|
125
|
+
this.indexType = indexType;
|
|
126
|
+
this.properties = properties;
|
|
127
|
+
this.entityType = "node";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export class RelationshipTypeIndex {
|
|
131
|
+
constructor($id, name, indexType, relationshipType, properties) {
|
|
132
|
+
this.$id = $id;
|
|
133
|
+
this.name = name;
|
|
134
|
+
this.indexType = indexType;
|
|
135
|
+
this.entityType = "relationship";
|
|
136
|
+
this.relationshipType = relationshipType;
|
|
137
|
+
this.properties = properties;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export class LookupIndex {
|
|
141
|
+
constructor($id, name, entityType) {
|
|
142
|
+
this.$id = $id;
|
|
143
|
+
this.name = name;
|
|
144
|
+
this.indexType = "lookup";
|
|
145
|
+
this.entityType = entityType;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class Property {
|
|
149
|
+
constructor($id, token, type, nullable) {
|
|
150
|
+
this.$id = $id;
|
|
151
|
+
this.token = token;
|
|
152
|
+
this.type = type;
|
|
153
|
+
this.nullable = nullable;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export class PropertyBaseType {
|
|
157
|
+
constructor(type) {
|
|
158
|
+
this.type = type;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export class PropertyArrayType {
|
|
162
|
+
constructor(items) {
|
|
163
|
+
this.type = "array";
|
|
164
|
+
this.items = items;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IAQtB,YACE,eAAiC,EACjC,uBAAiD,EACjD,cAA4B,EAAE,EAC9B,UAAmB,EAAE;QAXvB,eAAU,GAAgB,EAAE,CAAC;QAC7B,sBAAiB,GAAuB,EAAE,CAAC;QAYzC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IACO,iBAAiB;QACvB,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAC7C,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAC1C,CAAC;QACF,IAAI,CAAC,U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,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC;QACjC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,WAAW;IAMtB,YAAY,GAAW,EAAE,IAAY,EAAE,UAAsB;QAC3D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAsBD,MAAM,OAAO,QAAQ;IAMnB,YACE,GAAW,EACX,KAAa,EACb,IAA2B,EAC3B,QAAiB;QAEjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IAE3B,YAAY,IAA4B;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAM,OAAO,iBAAiB;IAI5B,YAAY,KAAuB;QACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import AjvModule from "ajv";
|
|
2
|
+
export declare function validateSchema(jsonSchema: string, graphSchema: string): boolean;
|
|
3
|
+
export declare class SchemaValidationError extends Error {
|
|
4
|
+
messages: AjvModule.ErrorObject<string, Record<string, any>, unknown>[];
|
|
5
|
+
constructor(inputMessages: AjvModule.ErrorObject<string, Record<string, any>, unknown>[]);
|
|
6
|
+
}
|
|
7
|
+
export declare class InputTypeError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import AjvModule from "ajv";
|
|
2
|
+
// FIXME: https://github.com/ajv-validator/ajv/issues/2047
|
|
3
|
+
const Ajv = AjvModule.default;
|
|
4
|
+
const ajv = new Ajv({ strict: false, allErrors: true });
|
|
5
|
+
export function validateSchema(jsonSchema, graphSchema) {
|
|
6
|
+
if (typeof jsonSchema !== "string") {
|
|
7
|
+
throw new InputTypeError("JSON schema should be a string");
|
|
8
|
+
}
|
|
9
|
+
let jsonSchemaObj;
|
|
10
|
+
try {
|
|
11
|
+
jsonSchemaObj = JSON.parse(jsonSchema);
|
|
12
|
+
}
|
|
13
|
+
catch (_) {
|
|
14
|
+
throw new InputTypeError("Cannot JSON.parse JSON schema input");
|
|
15
|
+
}
|
|
16
|
+
if (typeof graphSchema !== "string") {
|
|
17
|
+
throw new InputTypeError("Graph schema should be a string");
|
|
18
|
+
}
|
|
19
|
+
let graphSchemaObj;
|
|
20
|
+
try {
|
|
21
|
+
graphSchemaObj = JSON.parse(graphSchema);
|
|
22
|
+
}
|
|
23
|
+
catch (_) {
|
|
24
|
+
throw new InputTypeError("Cannot JSON.parse graph schema input");
|
|
25
|
+
}
|
|
26
|
+
const validate = ajv.compile(jsonSchemaObj);
|
|
27
|
+
const result = validate(graphSchemaObj);
|
|
28
|
+
if (result !== true) {
|
|
29
|
+
if (validate.errors) {
|
|
30
|
+
throw new SchemaValidationError(validate.errors);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
export class SchemaValidationError extends Error {
|
|
36
|
+
constructor(inputMessages) {
|
|
37
|
+
super(`See error.messages for details`);
|
|
38
|
+
this.messages = [];
|
|
39
|
+
this.messages = inputMessages;
|
|
40
|
+
this.name = "SchemaValidationError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class InputTypeError extends Error {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = "InputTypeError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,KAAK,CAAC;AAE5B,0DAA0D;AAC1D,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC;AAE9B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAExD,MAAM,UAAU,cAAc,CAC5B,UAAkB,EAClB,WAAmB;IAEnB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,cAAc,CAAC,gCAAgC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,aAAa,CAAC;IAClB,IAAI,CAAC;QACH,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,cAAc,CAAC,qCAAqC,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,cAAc,CAAC,iCAAiC,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,cAAc,CAAC;IACnB,IAAI,CAAC;QACH,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,cAAc,CAAC,sCAAsC,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAG9C,YACE,aAA4E;QAE5E,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAL1C,aAAQ,GAAkE,EAAE,CAAC;QAM3E,IAAI,CAAC,QAAQ,GAAG,aAAa,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j/graph-schema-utils",
|
|
3
|
-
"version": "1.0.0-next.
|
|
4
|
-
"description": "Utilities for
|
|
5
|
-
"module": "
|
|
3
|
+
"version": "1.0.0-next.10",
|
|
4
|
+
"description": "Utilities for Neo4j Graph Schema JSON representation",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
6
13
|
"type": "module",
|
|
7
14
|
"scripts": {
|
|
8
15
|
"test:watch": "vitest",
|
|
9
|
-
"test": "vitest run"
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"build": "tsc --project tsconfig.build.json",
|
|
18
|
+
"check": "tsc --project tsconfig.check.json"
|
|
10
19
|
},
|
|
11
20
|
"files": [
|
|
12
|
-
"
|
|
21
|
+
"dist"
|
|
13
22
|
],
|
|
14
23
|
"repository": {
|
|
15
24
|
"type": "git",
|
|
@@ -27,8 +36,6 @@
|
|
|
27
36
|
"graph schema"
|
|
28
37
|
],
|
|
29
38
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"vitest": "^0.25.3",
|
|
32
|
-
"@neo4j/graph-json-schema": "*"
|
|
39
|
+
"@neo4j/graph-json-schema": "1.0.0-next.4"
|
|
33
40
|
}
|
|
34
41
|
}
|
package/src/index.js
DELETED