@@ -361,14 +361,19 @@ case class ExecutableWhiskActionMetaData(namespace: EntityPath,
361361case class WhiskActionVersion (id : String , namespace : EntityPath , name : EntityName , version : SemVer , publish : Boolean )
362362
363363object WhiskActionVersion {
364- val serdes = jsonFormat(WhiskActionVersion .apply, " _id " , " namespace" , " name" , " version" , " publish" )
364+ val serdes = jsonFormat(WhiskActionVersion .apply, " id " , " namespace" , " name" , " version" , " publish" )
365365}
366366
367- case class WhiskActionVersionList (namespace : EntityPath , name : EntityName , versions : Map [SemVer , String ]) {
367+ case class WhiskActionVersionList (namespace : EntityPath ,
368+ name : EntityName ,
369+ versions : Map [SemVer , String ],
370+ defaultVersion : Option [String ]) {
368371 def matchedDocId (version : Option [SemVer ]): Option [DocId ] = {
369372 version match {
370373 case Some (ver) =>
371374 versions.get(ver).map(DocId (_))
375+ case None if defaultVersion.nonEmpty =>
376+ versions.get(SemVer (defaultVersion.get)).map(DocId (_))
372377 case None if versions.nonEmpty =>
373378 Some (DocId (versions.maxBy(_._1)._2))
374379 case _ =>
@@ -385,7 +390,7 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
385390 CacheKey (action.fullPath.asString)
386391 }
387392
388- def get (action : FullyQualifiedEntityName , datastore : EntityStore , fetchAll : Boolean = true )(
393+ def get (action : FullyQualifiedEntityName , datastore : EntityStore , fromCache : Boolean = true )(
389394 implicit transId : TransactionId ): Future [WhiskActionVersionList ] = {
390395 implicit val logger : Logging = datastore.logging
391396 implicit val ec = datastore.executionContext
@@ -401,7 +406,7 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
401406 endKey = endKey,
402407 skip = 0 ,
403408 limit = 0 ,
404- includeDocs = false ,
409+ includeDocs = true ,
405410 descending = false ,
406411 reduce = false ,
407412 stale = StaleParameter .No )
@@ -411,24 +416,32 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
411416 }
412417 val mappings = values
413418 .map(WhiskActionVersion .serdes.read(_))
414- .filter(_.publish || fetchAll)
415419 .map { actionVersion =>
416420 (actionVersion.version, actionVersion.id)
417421 }
418422 .toMap
419- WhiskActionVersionList (action.namespace.toPath, action.name, mappings)
420- })
423+ val defaultVersion = if (result.nonEmpty) {
424+ val doc = result.head.fields.getOrElse(" doc" , JsNull )
425+ if (doc != JsNull ) doc.asJsObject.fields.get(" default" ).map(_.convertTo[String ])
426+ else
427+ None
428+ } else None
429+ WhiskActionVersionList (action.namespace.toPath, action.name, mappings, defaultVersion)
430+ },
431+ fromCache)
421432 }
422433
423434 def getMatchedDocId (
424435 action : FullyQualifiedEntityName ,
425436 version : Option [SemVer ],
426437 datastore : EntityStore ,
427438 tryAgain : Boolean = true )(implicit transId : TransactionId , ec : ExecutionContext ): Future [Option [DocId ]] = {
428- get(action, datastore, version.nonEmpty ).flatMap { res =>
439+ get(action, datastore).flatMap { res =>
429440 val docId = version match {
430441 case Some (ver) =>
431442 res.versions.get(ver).map(DocId (_))
443+ case None if res.defaultVersion.nonEmpty =>
444+ res.versions.get(SemVer (res.defaultVersion.get)).map(DocId (_))
432445 case None if res.versions.nonEmpty =>
433446 Some (DocId (res.versions.maxBy(_._1)._2))
434447 case _ =>
0 commit comments