UNPKG

polen

Version:

A framework for delightful GraphQL developer portals

53 lines 1.63 kB
import { Grafaid } from '#lib/grafaid/index'; import { GraphqlChange } from '#lib/graphql-change/index'; import { Arr } from '@wollybeard/kit'; export const normalize = (configInput) => { const config = { versions: Arr.map(Arr.sure(configInput.versions), _ => { if (typeof _ === `string`) { return { date: new Date(), value: _, }; } return _; }), }; return config; }; export const read = async (configInput) => { const config = normalize(configInput); if (!Arr.isntEmpty(config.versions)) { return null; } const versions = Arr.map(config.versions, _ => { return { date: _.date, schema: Grafaid.Schema.fromAST(Grafaid.Schema.AST.parse(_.value)), }; }); versions.sort((a, b) => a.date.getTime() - b.date.getTime()); // todo: make DRY, this is same as for schema-directory const changesets = await Promise.all(Arr.map(versions, async (version, index) => { const current = version; const previous = versions[index - 1]; const before = previous?.schema ?? Grafaid.Schema.empty; const after = current.schema; const changes = await GraphqlChange.calcChangeset({ before, after, }); return { date: current.date, before, after, changes, }; })); changesets.reverse(); const schema = { versions: changesets, }; return schema; }; //# sourceMappingURL=memory.js.map