-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from bcgsc/release/v4.0.0
Release/v4.0.0
- Loading branch information
Showing
30 changed files
with
2,020 additions
and
1,856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@bcgsc-pori/graphkb-schema", | ||
"version": "3.16.0", | ||
"version": "4.0.0", | ||
"description": "Shared package between the API and GUI for GraphKB which holds the schema definitions and schema-related functions", | ||
"bugs": { | ||
"email": "[email protected]" | ||
|
@@ -23,11 +23,11 @@ | |
"@bcgsc-pori/graphkb-parser": ">=2.0.0 <3.0.0" | ||
}, | ||
"dependencies": { | ||
"isemail": "^3.2.0", | ||
"lodash.omit": "4.5.0", | ||
"typescript": "^4.5.5", | ||
"uuid": "3.3.2", | ||
"uuid-validate": "0.0.3" | ||
"uuid-validate": "0.0.3", | ||
"validator": "^13.7.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
ClassDefinition, PropertyDefinition, ClassDefinitionInput, Expose, ClassPermissions, GroupName, | ||
} from './types'; | ||
import { createPropertyDefinition } from './property'; | ||
import { | ||
EXPOSE_ALL, EXPOSE_EDGE, EXPOSE_NONE, PERMISSIONS, | ||
} from './constants'; | ||
|
||
const getRouteName = (name: string, isEdge: boolean) => { | ||
if (name.length === 1) { | ||
return `/${name.toLowerCase()}`; | ||
} if (!isEdge && !name.endsWith('ary') && name.toLowerCase() !== 'evidence') { | ||
if (/.*[^aeiou]y$/.exec(name)) { | ||
return `/${name.slice(0, name.length - 1)}ies`.toLowerCase(); | ||
} | ||
return `/${name}s`.toLowerCase(); | ||
} | ||
return `/${name.toLowerCase()}`; | ||
}; | ||
|
||
const defaultPermissions = (routes: Partial<Expose> = {}): ClassPermissions => { | ||
const permissions = { | ||
default: PERMISSIONS.NONE, | ||
readonly: PERMISSIONS.READ, | ||
}; | ||
|
||
if (routes.QUERY || routes.GET) { | ||
permissions.default |= PERMISSIONS.READ; | ||
} | ||
if (routes.POST) { | ||
permissions.default |= PERMISSIONS.CREATE; | ||
} | ||
if (routes.PATCH) { | ||
permissions.default |= PERMISSIONS.UPDATE; | ||
} | ||
if (routes.DELETE) { | ||
permissions.default |= PERMISSIONS.DELETE; | ||
} | ||
return permissions; | ||
}; | ||
|
||
const createClassDefinition = (opt: ClassDefinitionInput): ClassDefinition => { | ||
const { name } = opt; | ||
const properties: Record<string, PropertyDefinition> = {}; | ||
|
||
for (const propDefn of opt.properties || []) { | ||
properties[propDefn.name] = createPropertyDefinition(propDefn); | ||
} | ||
|
||
let isEdge = Boolean(opt.isEdge); | ||
|
||
if (opt.targetModel || opt.sourceModel) { | ||
isEdge = true; | ||
} | ||
|
||
let defaultRoutes: Expose; | ||
|
||
if (opt.isAbstract || opt.embedded) { | ||
defaultRoutes = EXPOSE_NONE; | ||
} else if (opt.isEdge) { | ||
defaultRoutes = EXPOSE_EDGE; | ||
} else { | ||
defaultRoutes = EXPOSE_ALL; | ||
} | ||
|
||
const routes = opt.routes || defaultRoutes || {}; | ||
|
||
return { | ||
...opt, | ||
properties, | ||
routeName: getRouteName(opt.name, Boolean(opt.isEdge)), | ||
isEdge, | ||
routes, | ||
isAbstract: Boolean(opt.isAbstract), | ||
inherits: opt.inherits || [], | ||
description: opt.description || '', | ||
embedded: Boolean(opt.embedded), | ||
indices: opt.indices || [], | ||
permissions: { ...defaultPermissions(routes), ...(opt.permissions || {}) }, | ||
}; | ||
}; | ||
|
||
export { createClassDefinition, getRouteName }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.