2016-10-05 10:02:32 +03:00
|
|
|
import { linkStorage } from '../links/symbols.js';
|
2016-10-07 11:59:18 +03:00
|
|
|
import NamedQueryStore from '../namedQuery/store';
|
2016-10-07 12:49:02 +03:00
|
|
|
import deepClone from '../query/lib/deepClone.js';
|
2016-10-05 10:02:32 +03:00
|
|
|
|
2016-10-07 11:59:18 +03:00
|
|
|
export default function extract() {
|
|
|
|
return {
|
|
|
|
namedQueries: extractNamedQueryDocumentation(),
|
|
|
|
collections: extractCollectionDocumentation()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function extractNamedQueryDocumentation() {
|
|
|
|
const namedQueries = NamedQueryStore.getAll();
|
|
|
|
|
|
|
|
let DocumentationObject = {};
|
|
|
|
|
|
|
|
_.each(namedQueries, namedQuery => {
|
|
|
|
DocumentationObject[namedQuery.queryName] = {
|
|
|
|
body: namedQuery.body,
|
|
|
|
collection: namedQuery.collection._name,
|
|
|
|
isExposed: namedQuery.isExposed,
|
|
|
|
paramsSchema: (namedQuery.exposeConfig.schema)
|
|
|
|
?
|
|
|
|
formatSchemaType(
|
2016-10-07 12:49:02 +03:00
|
|
|
deepClone(namedQuery.exposeConfig.schema)
|
2016-10-07 11:59:18 +03:00
|
|
|
)
|
|
|
|
: null
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return DocumentationObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
function extractCollectionDocumentation() {
|
2016-10-05 10:02:32 +03:00
|
|
|
const collections = Mongo.Collection.getAll();
|
|
|
|
let DocumentationObject = {};
|
|
|
|
|
|
|
|
_.each(collections, ({name, instance}) => {
|
|
|
|
if (name.substr(0, 7) == 'meteor_') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentationObject[name] = {};
|
2016-10-19 17:11:01 +03:00
|
|
|
var isExposed = !!instance.__isExposedForGrapher;
|
|
|
|
DocumentationObject[name]['isExposed'] = isExposed;
|
|
|
|
|
|
|
|
if (isExposed && instance.__exposure.config.body) {
|
|
|
|
DocumentationObject[name]['exposureBody'] = deepClone(instance.__exposure.config.body);
|
|
|
|
}
|
2016-10-07 11:59:18 +03:00
|
|
|
|
2016-10-05 10:02:32 +03:00
|
|
|
extractSchema(DocumentationObject[name], instance);
|
|
|
|
extractLinks(DocumentationObject[name], instance);
|
|
|
|
});
|
|
|
|
|
|
|
|
return DocumentationObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function extractSchema(storage, collection) {
|
|
|
|
storage.schema = {};
|
|
|
|
|
|
|
|
if (collection.simpleSchema && collection.simpleSchema()) {
|
2016-10-07 12:49:02 +03:00
|
|
|
storage.schema = deepClone(collection.simpleSchema()._schema);
|
2016-10-07 11:59:18 +03:00
|
|
|
|
|
|
|
formatSchemaType(storage.schema);
|
2016-10-05 10:02:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 11:59:18 +03:00
|
|
|
function formatSchemaType(schema) {
|
|
|
|
_.each(schema, (value, key) => {
|
|
|
|
if (value.type && value.type.name) {
|
|
|
|
value.type = value.type.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return schema;
|
|
|
|
}
|
|
|
|
|
2016-10-05 10:02:32 +03:00
|
|
|
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(),
|
2016-10-05 11:33:06 +03:00
|
|
|
inversedBy: linker.linkConfig.inversedBy,
|
2016-10-05 10:02:32 +03:00
|
|
|
isResolver: linker.isResolver(),
|
|
|
|
resolverFunction: linker.isResolver() ? linker.linkConfig.resolve.toString() : null,
|
2016-10-05 11:33:06 +03:00
|
|
|
isOneResult: linker.isOneResult(),
|
|
|
|
linkStorageField: linker.linkStorageField
|
2016-10-05 10:02:32 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|