Skip to content

Commit

Permalink
v0.18.1 Re-aligning Meta semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgrue committed Mar 9, 2019
1 parent 27607cd commit 3364af7
Show file tree
Hide file tree
Showing 97 changed files with 421 additions and 416 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ lazy val yourProject = project.in(file("app"))
Resolver.sonatypeRepo("releases")
),
libraryDependencies ++= Seq(
"org.scalamolecule" %% "molecule" % "0.18.0",
"org.scalamolecule" %% "molecule" % "0.18.1",
"com.datomic" % "datomic-free" % "0.9.5697"
),
moleculeSchemas := Seq("app") // paths to your schema definition files...
)
```
Molecule 0.18.0 for Scala 2.12.8 is available at
Molecule 0.18.1 for Scala 2.12.8 is available at
[Sonatype](https://oss.sonatype.org/content/repositories/releases/org/scalamolecule/molecule_2.12/).


Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sbt.compilerPlugin
lazy val commonSettings = Defaults.coreDefaultSettings ++ Seq(
organization := "org.scalamolecule",
version := "0.18.0",
version := "0.18.1",
scalaVersion := "2.12.8",
scalacOptions := Seq(
"-feature",
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/scala/molecule/api/core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package molecule.api

import molecule.expression.{AggregateKeywords, AttrExpressions, LogicImplicits}
import molecule.facade.Datomic
import molecule.generic.GenericLog
import molecule.generic.index.{GenericAVET, GenericEAVT, GenericVAET}
import molecule.generic.index.{GenericAEVT, GenericAVET, GenericEAVT, GenericVAET}
import molecule.generic.schema.GenericSchema
import molecule.meta.GenericLog
import molecule.meta.index.{GenericAEVT, GenericAVET, GenericEAVT, GenericVAET}
import molecule.meta.schema.GenericSchema


/** Molecule API to be imported into your project to use Molecule.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/molecule/api/get/GetList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ trait GetList[Tpl] extends GetArray[Tpl] { self: Molecule[Tpl] =>
* @group getHistory
* @param conn Implicit [[molecule.facade.Conn Conn]] value in scope
* @return List[Tpl] where Tpl is a tuple of data matching molecule
* @see [[http://www.scalamolecule.org/manual/time/history/ manual]] for more info on generic attributes.
* @see [[http://www.scalamolecule.org/manual/time/history/ manual]] for more info on meta attributes.
* @see Equivalent asynchronous [[molecule.api.getAsync.GetAsyncList.getAsyncHistory(implicit* getAsyncHistory]] method.
*/
def getHistory(implicit conn: Conn): List[Tpl] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ trait GetAsyncList[Tpl] { self: Molecule[Tpl] with GetAsyncArray[Tpl] =>
* @group getHistory
* @param conn Implicit [[molecule.facade.Conn Conn]] value in scope
* @return List[Tpl] where Tpl is tuple of data matching molecule
* @see [[http://www.scalamolecule.org/manual/time/history/ manual]] for more info on generic attributes.
* @see [[http://www.scalamolecule.org/manual/time/history/ manual]] for more info on meta attributes.
*/
def getAsyncHistory(implicit conn: Conn): Future[List[Tpl]] =
Future(getHistory(conn))
Expand Down
23 changes: 12 additions & 11 deletions core/src/main/scala/molecule/ast/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,33 @@ object model extends Helpers {
trait MetaAtom extends Element {
val ns : String
val attr : String
val tpe : String
val value: Value
}

case class Meta(ns: String,
attr: String,
kind: String,
tpe: String,
value: Value) extends MetaAtom {
override def toString: String = s"""Meta("$ns", "$attr", "$kind", $value)"""
override def toString: String = s"""Meta("$ns", "$attr", "$tpe", $value)"""
}

case class Atom(ns: String,
attr: String,
tpeS: String,
tpe: String,
card: Int,
value: Value,
enumPrefix: Option[String] = None,
gs: Seq[Generic] = Nil,
gs: Seq[MetaValue] = Nil,
keys: Seq[String] = Nil) extends MetaAtom {
override def toString: String = s"""Atom("$ns", "$attr", "$tpeS", $card, $value, ${o(enumPrefix)}, ${seq(gs)}, ${seq(keys)})"""
override def toString: String = s"""Atom("$ns", "$attr", "$tpe", $card, $value, ${o(enumPrefix)}, ${seq(gs)}, ${seq(keys)})"""
}

case class Bond(ns: String,
refAttr: String,
refNs: String = "",
card: Int,
gs: Seq[Generic] = Nil) extends Element {
gs: Seq[MetaValue] = Nil) extends Element {
override def toString: String = s"""Bond("$ns", "$refAttr", "$refNs", $card, ${seq(gs)})"""
}

Expand Down Expand Up @@ -135,14 +136,14 @@ object model extends Helpers {
case class MapKeys(keys: Seq[String]) extends Value {override def toString: String = s"MapKeys(${seq(keys)})"}


sealed trait Generic extends Value
sealed trait MetaValue extends Value

case object NoValue extends Generic
case class Id(eid: Any) extends Generic
case class Card(card: Int) extends Generic {override def toString: String = s"Card($card)"}
case object NoValue extends MetaValue
case class Id(eid: Any) extends MetaValue
case class Card(card: Int) extends MetaValue {override def toString: String = s"Card($card)"}


sealed trait Bidirectional extends Generic
sealed trait Bidirectional extends MetaValue

case class BiSelfRef(card: Int) extends Bidirectional {override def toString: String = s"BiSelfRef($card)"}
case class BiSelfRefAttr(card: Int) extends Bidirectional {override def toString: String = s"BiSelfRefAttr($card)"}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/molecule/ast/transactionModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object transactionModel {
val e : Any
val a : String
val v : Any
val bi : Generic
val meta : MetaValue
val oldV: Any = null

def value(v: Any): Object = (v match {
Expand All @@ -33,25 +33,25 @@ object transactionModel {
}
}

case class Add(e: Any, a: String, v: Any, bi: Generic) extends Statement {
case class Add(e: Any, a: String, v: Any, meta: MetaValue) extends Statement {
val action = ":db/add"
}

// Todo: Implement in updates?
// Current Add's let Datomic automatically create a retract datom for each new update.
case class Cas(e: Any, a: String, override val oldV: Any, v: Any, bi: Generic) extends Statement {
case class Cas(e: Any, a: String, override val oldV: Any, v: Any, meta: MetaValue) extends Statement {
val action = ":db.fn/cas"
}

case class Retract(e: Any, a: String, v: Any, bi: Generic = NoValue) extends Statement {
case class Retract(e: Any, a: String, v: Any, meta: MetaValue = NoValue) extends Statement {
val action = ":db/retract"
}

case class RetractEntity(e: Any) extends Statement {
val action = ":db.fn/retractEntity"
val a = ""
val v = ""
val bi = NoValue
val meta = NoValue
}

case class Eid(id: Long)
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/scala/molecule/boilerplate/in1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package molecule.boilerplate
import molecule.boilerplate.base._
import molecule.composition.CompositeInit_In_1._
import molecule.expression.AggregateKeywords._
import molecule.generic.datom._
import molecule.generic.datom._
import molecule.meta.datom._
import scala.language.higherKinds


Expand Down
5 changes: 2 additions & 3 deletions core/src/main/scala/molecule/boilerplate/in2.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package molecule.boilerplate
import molecule.expression.AggregateKeywords._
import molecule.boilerplate.base._
import molecule.composition.CompositeInit_In_2._
import molecule.generic.datom._
import molecule.generic.datom._
import molecule.expression.AggregateKeywords._
import molecule.meta.datom._
import scala.language.higherKinds


Expand Down
5 changes: 2 additions & 3 deletions core/src/main/scala/molecule/boilerplate/in3.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package molecule.boilerplate
import molecule.expression.AggregateKeywords._
import molecule.boilerplate.base._
import molecule.composition.CompositeInit_In_3._
import molecule.generic.datom._
import molecule.generic.datom._
import molecule.expression.AggregateKeywords._
import molecule.meta.datom._
import scala.language.higherKinds

/** Type distribution to groups of functionality for input molecules expecting 3 inputs. */
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/scala/molecule/boilerplate/out.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package molecule.boilerplate
import molecule.expression.AggregateKeywords._
import molecule.boilerplate.base._
import molecule.composition.CompositeInit._
import molecule.composition.Tx._
import molecule.generic.datom._
import molecule.generic.datom._
import molecule.expression.AggregateKeywords._
import molecule.meta.datom._
import scala.language.higherKinds


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package molecule.expression
import scala.language.higherKinds


/** Count expression on generic attributes.
/** Count expression on meta attributes.
* <br><br>
* Apply `count` or `countDistinct` keywords to generic attributes.
* Apply `count` or `countDistinct` keywords to meta attributes.
* {{{
* Schema.e(count).get.head === 27 // count of all attributes in schema
* Schema.a(countDistinct).get.head === 23 // count of all distinct attribute names in schema
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/molecule/facade/Conn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class Conn(val datomicConn: datomic.Connection) extends Helpers {
* @return java.util.Collection[java.util.List[AnyRef]]
* */
def query(model: Model, query: Query): jCollection[jList[AnyRef]] = model.elements.head match {
case Meta("log" | "eavt" | "aevt" | "avet" | "vaet", _, _, _) => _index(model)
case Meta("Log" | "EAVT" | "AEVT" | "AVET" | "VAET", _, _, _) => _index(model)
case _ => _query(model, query)
}

Expand Down Expand Up @@ -535,7 +535,7 @@ class Conn(val datomicConn: datomic.Connection) extends Helpers {
// Datoms API providing direct access to indexes
private[molecule] def _index(model: Model): jCollection[jList[AnyRef]] = {
val (api, index, args) = model.elements.head match {
case Meta("eavt", _, _, value) =>
case Meta("EAVT", _, _, value) =>
("datoms", datomic.Database.EAVT, value match {
case Eq(Seq(e)) => Seq(e.asInstanceOf[Object])
case Eq(Seq(e, a)) => Seq(e.asInstanceOf[Object], a.asInstanceOf[Object])
Expand All @@ -544,7 +544,7 @@ class Conn(val datomicConn: datomic.Connection) extends Helpers {
case Eq(Seq(e, a, v, t)) => Seq(e.asInstanceOf[Object], a.asInstanceOf[Object], v.asInstanceOf[Object], t.asInstanceOf[Object])
})

case Meta("aevt", _, _, value) =>
case Meta("AEVT", _, _, value) =>
("datoms", datomic.Database.AEVT, value match {
case Eq(Seq(a)) => Seq(a.asInstanceOf[Object])
case Eq(Seq(a, e)) => Seq(a.asInstanceOf[Object], e.asInstanceOf[Object])
Expand All @@ -553,7 +553,7 @@ class Conn(val datomicConn: datomic.Connection) extends Helpers {
case Eq(Seq(a, e, v, t)) => Seq(a.asInstanceOf[Object], e.asInstanceOf[Object], v.asInstanceOf[Object], t.asInstanceOf[Object])
})

case Meta("avet", attr, _, value) =>
case Meta("AVET", attr, _, value) =>
attr match {
case "range" =>
("indexRange", datomic.Database.AVET, value match {
Expand All @@ -578,7 +578,7 @@ class Conn(val datomicConn: datomic.Connection) extends Helpers {
})
}

case Meta("vaet", attr, _, value) =>
case Meta("VAET", attr, _, value) =>
("datoms", datomic.Database.VAET, value match {
case Eq(Seq(v)) => Seq(v.asInstanceOf[Object])
case Eq(Seq(v, a)) => Seq(v.asInstanceOf[Object], a.asInstanceOf[Object])
Expand All @@ -587,7 +587,7 @@ class Conn(val datomicConn: datomic.Connection) extends Helpers {
case Eq(Seq(v, a, e, t)) => Seq(v.asInstanceOf[Object], a.asInstanceOf[Object], e.asInstanceOf[Object], t.asInstanceOf[Object])
})

case Meta("log", _, _, value) =>
case Meta("Log", _, _, value) =>
("txRange", datomic.Database.VAET, value match {
case Eq(Seq(from: Int, until: Int)) => Seq(from.asInstanceOf[Object], until.asInstanceOf[Object])
case Eq(Seq(from: Int, until: Long)) => Seq(from.asInstanceOf[Object], until.asInstanceOf[Object])
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/molecule/generic/GenericNs.scala

This file was deleted.

13 changes: 0 additions & 13 deletions core/src/main/scala/molecule/generic/package.scala

This file was deleted.

4 changes: 2 additions & 2 deletions core/src/main/scala/molecule/input/InputMolecule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ trait InputMolecule extends MoleculeBase {
val ns_ = ns + "_"
val (attr_, attrK, attrK_) = (attr + "_", attr + "K", attr + "K_")
def isTacit_(elements: Seq[Element], tacit0: Option[Boolean]): Option[Boolean] = elements.foldLeft(tacit0) {
case (tacit, Meta(`ns`, `attr`, _, _)) => Some(true)
case (tacit, Meta(_, `attr`, `ns`, _)) => Some(true)
case (tacit, Atom(`ns` | `ns_`, `attr_` | `attrK_`, _, _, _, _, _, _)) => Some(true)
case (tacit, Atom(`ns_`, `attr` | `attrK`, _, _, _, _, _, _)) => Some(true)
case (tacit, Atom(`ns`, `attr` | `attrK`, _, _, _, _, _, _)) => Some(false)
Expand All @@ -83,7 +83,7 @@ trait InputMolecule extends MoleculeBase {
val ns_ = ns + "_"
val (attr_, attrK, attrK_) = (attr + "_", attr + "K", attr + "K_")
def isTacit_(elements: Seq[Element], cardOpt0: Option[Int]): Option[Int] = elements.foldLeft(cardOpt0) {
case (cardOpt, Meta(`ns`, `attr`, _, _)) => Some(2)
case (cardOpt, Meta(_, `attr`, `ns`, _)) => Some(2)
case (cardOpt, Atom(`ns` | `ns_`, `attr` | `attr_` | `attrK` | `attrK_`, _, card, _, _, _, _)) => Some(card)
case (cardOpt, Nested(_, elements2)) => isTacit_(elements2, cardOpt)
case (cardOpt, Composite(elements2)) => isTacit_(elements2, cardOpt)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic
package molecule.meta

import java.util.Date
import molecule.boilerplate.attributes._
Expand Down Expand Up @@ -97,7 +97,7 @@ trait GenericLog {
* of transaction data. This is to have a transparent unified return type
* as all other molecules returning data. Data can always be grouped if needed.
*/
trait Log extends GenericNs {
trait Log extends MetaNs {

/** Entity id (Long) */
final class e [Ns, In] extends OneLong [Ns, In] with Indexed
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/molecule/meta/MetaNs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package molecule.meta

private[molecule] trait MetaNs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
* 2. `sbt compile` in terminal
* 3. Refresh and re-compile project in IDE
*/
package molecule.generic.datom
package molecule.meta.datom

import molecule.boilerplate.attributes._
import molecule.generic.GenericNs
import scala.language.higherKinds

/** Base trait with generic attribute trait types shared by all arity interfaces */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package molecule.generic.datom
package molecule.meta.datom

import java.util.Date
import scala.language.higherKinds
Expand Down
Loading

0 comments on commit 3364af7

Please sign in to comment.