added documentation exposure

This commit is contained in:
Theodor Diaconu 2016-10-05 10:02:32 +03:00
parent 378fd65aae
commit 45cf24befe
3 changed files with 56 additions and 2 deletions

50
lib/documentor/index.js Normal file
View file

@ -0,0 +1,50 @@
import { linkStorage } from '../links/symbols.js';
export default function extractDocumentation() {
const collections = Mongo.Collection.getAll();
let DocumentationObject = {};
_.each(collections, ({name, instance}) => {
if (name.substr(0, 7) == 'meteor_') {
return;
}
DocumentationObject[name] = {};
extractSchema(DocumentationObject[name], instance);
extractLinks(DocumentationObject[name], instance);
});
return DocumentationObject;
}
function extractSchema(storage, collection) {
storage.schema = {};
if (collection.simpleSchema && collection.simpleSchema()) {
storage.schema = collection.simpleSchema()._schema;
_.each(storage.schema, (value, key) => {
if (value.type && value.type.name) {
value.type = value.type.name;
}
});
}
}
function extractLinks(storage, collection) {
storage.links = {};
const collectionLinkStorage = collection[linkStorage];
_.each(collectionLinkStorage, (linker, name) => {
storage.links[name] = {
collection: !linker.isResolver() ? linker.getLinkedCollection()._name : null,
strategy: linker.strategy,
metadata: linker.linkConfig.metadata,
isVirtual: linker.isVirtual(),
isResolver: linker.isResolver(),
resolverFunction: linker.isResolver() ? linker.linkConfig.resolve.toString() : null,
field: linker.linkConfig.field,
isOneResult: linker.isOneResult()
}
})
}

View file

@ -13,4 +13,8 @@ export {
export {
default as Exposure
} from './lib/exposure/exposure.js';
} from './lib/exposure/exposure.js';
export {
default as getDocumentationObject
} from './lib/documentor/index.js';

View file

@ -1,6 +1,6 @@
Package.describe({
name: 'cultofcoders:grapher',
version: '1.1.5',
version: '1.1.6',
// Brief, one-line summary of the package.
summary: 'Grapher makes linking collections easily. And fetching data as a graph.',
// URL to the Git repository containing the source code for this package.