Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sergey Kozlovskiy
Schema
Commits
a1fd532e
Commit
a1fd532e
authored
4 years ago
by
Ruben Seggers
Browse files
Options
Download
Plain Diff
Merge branch 'tests' into 'dev'
Tests See merge request
memri/schema!10
parents
d1d603b2
f8dee45d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
.gitignore
tools/test.js
+55
-15
tools/test.js
with
56 additions
and
15 deletions
+56
-15
.gitignore
+
1
-
0
View file @
a1fd532e
# Output files
*schema.swift
*schema_target.swift
*schema_target2.swift
*schema.ts
*schema_target.ts
*autogenerated_database_schema.json
...
...
This diff is collapsed.
Click to expand it.
tools/test.js
+
55
-
15
View file @
a1fd532e
...
...
@@ -10,56 +10,96 @@ let predicateHierarchy = {};
await
helpers
.
getHierarchy
(
entityHierarchyPath
,
entityHierarchy
,
entityHierarchyPath
,
'
Item
'
);
await
helpers
.
getHierarchy
(
predicateHierarchyPath
,
predicateHierarchy
,
predicateHierarchyPath
,
'
EdgeOrProperty
'
);
console
.
log
(
'
Check if properties of entities exist...
'
);
console
.
log
(
'
\n
Check if properties of entities exist...
'
);
for
(
const
entity
of
Object
.
keys
(
entityHierarchy
))
{
for
(
let
property
of
entityHierarchy
[
entity
][
'
properties
'
])
{
if
(
!
Object
.
keys
(
predicateHierarchy
).
includes
(
property
))
{
console
.
log
(
`
->
Type: '
${
entity
}
', has non-existent property: '
${
property
}
'`
);
console
.
log
(
`
E:
Type: '
${
entity
}
', has non-existent property: '
${
property
}
'`
);
}
}
}
console
.
log
(
'
Check if relations of entities exist...
'
);
console
.
log
(
'
\n
Check if relations of entities exist...
'
);
for
(
const
entity
of
Object
.
keys
(
entityHierarchy
))
{
for
(
let
relation
of
Object
.
keys
(
entityHierarchy
[
entity
][
'
relations
'
]))
{
if
(
!
Object
.
keys
(
predicateHierarchy
).
includes
(
relation
))
{
console
.
log
(
`
->
Type: '
${
entity
}
', has non-existent relation: '
${
relation
}
'`
);
console
.
log
(
`
E:
Type: '
${
entity
}
', has non-existent relation: '
${
relation
}
'`
);
}
}
}
console
.
log
(
'
Check if types of predicates exist...
'
);
console
.
log
(
'
\n
Check if types of predicates exist...
'
);
for
(
const
predicate
of
Object
.
keys
(
predicateHierarchy
))
{
if
(
predicateHierarchy
[
predicate
][
'
type
'
])
{
let
type
=
predicateHierarchy
[
predicate
][
'
type
'
];
if
(
!
Object
.
keys
(
entityHierarchy
).
includes
(
type
)
&&
!
helpers
.
PRIMITIVE_TYPES
.
includes
(
type
)
&&
type
!==
'
any
'
)
{
console
.
log
(
`
->
Edge / Property: '
${
predicateHierarchy
[
predicate
][
'
path
'
]}
', expects non-existent type: '
${
type
}
'`
);
console
.
log
(
`
E:
Edge / Property: '
${
predicateHierarchy
[
predicate
][
'
path
'
]}
', expects non-existent type: '
${
type
}
'`
);
}
}
else
{
if
(
!
predicateHierarchy
[
predicate
][
'
children
'
])
{
console
.
log
(
`
->
Edge / Property: '
${
predicateHierarchy
[
predicate
][
'
path
'
]}
', has no type.`
);
console
.
log
(
`
E:
Edge / Property: '
${
predicateHierarchy
[
predicate
][
'
path
'
]}
', has no type.`
);
}
}
}
console
.
log
(
'
Check for duplicate properties and edges (inherited and redefined)...
'
);
console
.
log
(
'
\n
Check for duplicate properties and edges (inherited and redefined)...
'
);
for
(
const
entity
of
Object
.
keys
(
entityHierarchy
))
{
if
(
entityHierarchy
[
entity
][
'
children
'
])
{
const
fields
=
entityHierarchy
[
entity
][
'
properties
'
].
concat
(
Object
.
keys
(
entityHierarchy
[
entity
][
'
relations
'
]))
const
fields
=
entityHierarchy
[
entity
][
'
properties
'
].
concat
(
Object
.
keys
(
entityHierarchy
[
entity
][
'
relations
'
]))
;
for
(
const
child
of
entityHierarchy
[
entity
][
'
children
'
])
{
const
childFields
=
entityHierarchy
[
child
][
'
properties
'
].
concat
(
Object
.
keys
(
entityHierarchy
[
child
][
'
relations
'
]))
const
childFields
=
entityHierarchy
[
child
][
'
properties
'
].
concat
(
Object
.
keys
(
entityHierarchy
[
child
][
'
relations
'
]))
;
for
(
const
childField
of
childFields
)
{
if
(
fields
.
includes
(
childField
))
{
console
.
log
(
`
->
${
child
}
redefines
${
childField
}
that is already in
${
entity
}
.`
)
console
.
log
(
`
E:
${
child
}
redefines
${
childField
}
that is already in
${
entity
}
.`
)
;
}
}
}
}
}
// TODO check if lower cased properties and relations don't clash: they can't have different types
// TODO check if props are `double`, i.e. already inherited
// TODO check if there are unused Items
// TODO check if there are unused relationships/properties
console
.
log
(
'
\n
Check for unused Items...
'
);
let
usedTypes
=
new
Set
();
for
(
const
predicate
of
Object
.
values
(
predicateHierarchy
))
{
if
(
predicate
[
'
type
'
])
usedTypes
.
add
(
predicate
[
'
type
'
]);
}
for
(
const
entity
of
Object
.
keys
(
entityHierarchy
))
{
if
(
!
usedTypes
.
has
(
entity
))
{
console
.
log
(
`W: No Edge uses Item
${
entity
}
`
);
}
}
console
.
log
(
'
\n
Check for unused Edges...
'
);
let
usedEdges
=
new
Set
();
for
(
const
entity
of
Object
.
values
(
entityHierarchy
))
{
for
(
const
relation
of
Object
.
keys
(
entity
[
'
relations
'
]))
{
usedEdges
.
add
(
relation
);
}
}
for
(
const
edge
of
Object
.
keys
(
predicateHierarchy
))
{
if
(
!
(
usedEdges
.
has
(
edge
)
||
helpers
.
PRIMITIVE_TYPES
.
includes
(
predicateHierarchy
[
edge
][
'
type
'
])))
{
console
.
log
(
`W: No Item uses Edge
${
edge
}
`
);
}
}
console
.
log
(
'
\n
Check for TBDs...
'
);
for
(
const
entity
of
Object
.
keys
(
entityHierarchy
))
{
if
(
entityHierarchy
[
entity
][
'
description
'
])
{
if
(
entityHierarchy
[
entity
][
'
description
'
].
toLowerCase
().
includes
(
'
tbd
'
))
{
console
.
log
(
`W: Item
${
entity
}
has TBD in description.`
);
}
}
else
{
console
.
log
(
`W: Item
${
entity
}
is missing a description.`
);
}
}
for
(
const
predicate
of
Object
.
keys
(
predicateHierarchy
))
{
if
(
predicateHierarchy
[
predicate
][
'
description
'
])
{
if
(
predicateHierarchy
[
predicate
][
'
description
'
].
toLowerCase
().
includes
(
'
tbd
'
))
{
console
.
log
(
`W: Edge / Property
${
predicate
}
has TBD in description.`
);
}
}
else
{
console
.
log
(
`W: Edge / Property
${
predicate
}
is missing a description.`
);
}
}
// TODO check if properties are shared over all children of an Item, so they could be inherited
})();
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment