Skip to content

Commit

Permalink
feat(core/inspect): adds validate
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Oct 15, 2019
1 parent 039a929 commit d0a547a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/inspect/index.ts
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';
25 changes: 25 additions & 0 deletions packages/core/src/inspect/validate.ts
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);
}

0 comments on commit d0a547a

Please sign in to comment.