1+ 'use strict' ;
2+
3+ var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
4+
5+ function _asyncToGenerator ( fn ) { return function ( ) { var gen = fn . apply ( this , arguments ) ; return new Promise ( function ( resolve , reject ) { function step ( key , arg ) { try { var info = gen [ key ] ( arg ) ; var value = info . value ; } catch ( error ) { reject ( error ) ; return ; } if ( info . done ) { resolve ( value ) ; } else { return Promise . resolve ( value ) . then ( function ( value ) { step ( "next" , value ) ; } , function ( err ) { step ( "throw" , err ) ; } ) ; } } return step ( "next" ) ; } ) ; } ; }
6+
7+ /* eslint-disable arrow-body-style */
8+
9+ var graphqlHTTP = require ( 'express-graphql' ) ;
10+
11+ var _require = require ( 'graphql' ) ,
12+ buildSchema = _require . buildSchema ;
13+
14+ var fetch = require ( 'node-fetch' ) ;
15+
16+ var schema = buildSchema ( '\n type Registry {\n href: String\n ocVersion: String\n type: String\n }\n\n type Person {\n name: String\n email: String\n }\n\n type Repository {\n type: String\n url: String\n }\n\n type Parameter {\n key: String\n type: String\n mandatory: Boolean\n example: String\n description: String\n }\n\n type Component {\n name: String\n description: String\n version: String\n allVersions: [String]\n author: Person\n repository: Repository\n parameters: [Parameter]\n }\n\n type Query {\n registry: Registry\n component(name: String): Component\n components: [Component]\n }\n' ) ;
17+
18+ var fetchComponent = function ( ) {
19+ var _ref = _asyncToGenerator ( regeneratorRuntime . mark ( function _callee ( url ) {
20+ return regeneratorRuntime . wrap ( function _callee$ ( _context ) {
21+ while ( 1 ) {
22+ switch ( _context . prev = _context . next ) {
23+ case 0 :
24+ return _context . abrupt ( 'return' , fetch ( url ) . then ( function ( response ) {
25+ return response . json ( ) ;
26+ } ) . then ( function ( data ) {
27+ return data ;
28+ } ) ) ;
29+
30+ case 1 :
31+ case 'end' :
32+ return _context . stop ( ) ;
33+ }
34+ }
35+ } , _callee , undefined ) ;
36+ } ) ) ;
37+
38+ return function fetchComponent ( _x ) {
39+ return _ref . apply ( this , arguments ) ;
40+ } ;
41+ } ( ) ;
42+
43+ var makeComponent = function ( ) {
44+ var _ref2 = _asyncToGenerator ( regeneratorRuntime . mark ( function _callee2 ( baseUrl , name ) {
45+ var url , info , parameters , copy ;
46+ return regeneratorRuntime . wrap ( function _callee2$ ( _context2 ) {
47+ while ( 1 ) {
48+ switch ( _context2 . prev = _context2 . next ) {
49+ case 0 :
50+ url = '' + baseUrl + name + '/~info' ;
51+ _context2 . next = 3 ;
52+ return fetchComponent ( url ) ;
53+
54+ case 3 :
55+ info = _context2 . sent ;
56+ parameters = [ ] ;
57+
58+ if ( info . oc . parameters ) {
59+ parameters = Object . keys ( info . oc . parameters ) . map ( function ( key ) {
60+ return _extends ( { key : key } , info . oc . parameters [ key ] ) ;
61+ } ) ;
62+ }
63+
64+ copy = Object . assign ( { } , info , { parameters : parameters } ) ;
65+ return _context2 . abrupt ( 'return' , copy ) ;
66+
67+ case 8 :
68+ case 'end' :
69+ return _context2 . stop ( ) ;
70+ }
71+ }
72+ } , _callee2 , undefined ) ;
73+ } ) ) ;
74+
75+ return function makeComponent ( _x2 , _x3 ) {
76+ return _ref2 . apply ( this , arguments ) ;
77+ } ;
78+ } ( ) ;
79+
80+ var root = function root ( options ) {
81+ return {
82+ registry : function ( ) {
83+ var _ref3 = _asyncToGenerator ( regeneratorRuntime . mark ( function _callee3 ( ) {
84+ return regeneratorRuntime . wrap ( function _callee3$ ( _context3 ) {
85+ while ( 1 ) {
86+ switch ( _context3 . prev = _context3 . next ) {
87+ case 0 :
88+ return _context3 . abrupt ( 'return' , fetch ( options . baseUrl ) . then ( function ( response ) {
89+ return response . json ( ) ;
90+ } ) . then ( function ( data ) {
91+ return {
92+ href : data . href ,
93+ ocVersion : data . ocVersion ,
94+ type : data . type
95+ } ;
96+ } ) ) ;
97+
98+ case 1 :
99+ case 'end' :
100+ return _context3 . stop ( ) ;
101+ }
102+ }
103+ } , _callee3 , undefined ) ;
104+ } ) ) ;
105+
106+ return function registry ( ) {
107+ return _ref3 . apply ( this , arguments ) ;
108+ } ;
109+ } ( ) ,
110+ components : function ( ) {
111+ var _ref4 = _asyncToGenerator ( regeneratorRuntime . mark ( function _callee4 ( ) {
112+ return regeneratorRuntime . wrap ( function _callee4$ ( _context4 ) {
113+ while ( 1 ) {
114+ switch ( _context4 . prev = _context4 . next ) {
115+ case 0 :
116+ return _context4 . abrupt ( 'return' , fetch ( options . baseUrl ) . then ( function ( response ) {
117+ return response . json ( ) ;
118+ } ) . then ( function ( data ) {
119+ return data . components . map ( function ( component ) {
120+ var name = component . replace ( options . baseUrl , '' ) ;
121+ return makeComponent ( options . baseUrl , name ) ;
122+ } ) ;
123+ } ) ) ;
124+
125+ case 1 :
126+ case 'end' :
127+ return _context4 . stop ( ) ;
128+ }
129+ }
130+ } , _callee4 , undefined ) ;
131+ } ) ) ;
132+
133+ return function components ( ) {
134+ return _ref4 . apply ( this , arguments ) ;
135+ } ;
136+ } ( ) ,
137+ component : function ( ) {
138+ var _ref5 = _asyncToGenerator ( regeneratorRuntime . mark ( function _callee5 ( _ref6 ) {
139+ var name = _ref6 . name ;
140+ return regeneratorRuntime . wrap ( function _callee5$ ( _context5 ) {
141+ while ( 1 ) {
142+ switch ( _context5 . prev = _context5 . next ) {
143+ case 0 :
144+ return _context5 . abrupt ( 'return' , makeComponent ( options . baseUrl , name ) ) ;
145+
146+ case 1 :
147+ case 'end' :
148+ return _context5 . stop ( ) ;
149+ }
150+ }
151+ } , _callee5 , undefined ) ;
152+ } ) ) ;
153+
154+ return function component ( _x4 ) {
155+ return _ref5 . apply ( this , arguments ) ;
156+ } ;
157+ } ( )
158+ } ;
159+ } ;
160+
161+ var factory = function factory ( options ) {
162+ return graphqlHTTP ( {
163+ schema : schema ,
164+ rootValue : root ( options ) ,
165+ graphiql : options . graphiql
166+ } ) ;
167+ } ;
168+
169+ module . exports = factory ;
0 commit comments