-
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.
- Loading branch information
Showing
2 changed files
with
26 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './traverse'; | ||
export * from './is'; | ||
export * from './traverse'; | ||
export * from './validate'; |
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,25 @@ | ||
import { CollectionTree, CollectionTreeImplementation } from '~/types'; | ||
import { normalize } from '~/transform/normalize'; | ||
import { routes } from '~/transform/routes'; | ||
import { isTreeImplementation } from './is'; | ||
|
||
// TODO: validate collection object (ajv) + check schemas are valid | ||
|
||
/** | ||
* It will throw if a collection: | ||
* - Is either fully a implementation or not at all. | ||
* - Contains conflicting routes. | ||
* - Has a scope name equal to a service of its parent. | ||
* - Contains references to non existent types. | ||
* - Contains types, services, or scopes with an empty name or with non word characters. | ||
* - Contains services with inline types or type references of the wrong kind. | ||
* - Contains services which inline type names would collide upon normalization - see `normalize`. | ||
* @returns `true` if a collection is a `CollectionTreeImplementation`. | ||
*/ | ||
export function validate( | ||
collection: CollectionTree | ||
): collection is CollectionTreeImplementation { | ||
routes(collection); | ||
normalize(collection); | ||
return isTreeImplementation(collection, true); | ||
} |