Codync
免费开源的 1:1 Grok Bot 与 Muse 替代方案。可在 iPhone、Mac 或 Linux 桌面上将 Claude 代码、Codex、Cursor 以及 40 多个编码代理作为持久机器人使用。支持群组聊天、线程、应用。
AI 翻译
尚未检测到更新。GitHub 发布版本后会显示在这里。
个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
在项目文件夹中运行 /nomorevibe verify,即可验证所有权并自行管理介绍。
一分钟完成验证macros to work with case classes field names
翻译准备中
取自仓库 README
正在加载完整 README。
查看完整 README ↗Macro that creates a Fields object with the names of a case class' fields,
so MongoDB filters and projections don't need hardcoded strings. Misspelled
field names fail at compile time.
Works on Scala 2.13 and Scala 3 (3.3 LTS) — including cross-compiled codebases sharing the same sources.
libraryDependencies += "io.github.vimalaguti" %% "moka" % "0.1.0"
On Scala 2.13 @moka is a macro annotation, so the compiler flag that
expands those is required:
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Ymacro-annotations")
case _ => Nil
})
Without it the annotation is silently left in place and every Fields
selection fails with not a member of io.moka.FieldsNotGenerated_AddYmacroAnnotations
(with @moka alone: not found: value Fields).
Scala 3 needs no flags.
Cross-compiled style (works on both versions):
import io.moka._
@moka
case class Apple(color: String)
object Apple {
val Fields = generateFields[Apple]
}
Apple.Fields.color == "color"
Apple.Fields.colour // does not compile
Scala 2 only — the annotation generates the companion by itself:
@moka
case class Apple(color: String)
Apple.Fields.color == "color"
Scala 3 only — no annotation needed:
case class Apple(color: String)
object Apple {
val Fields = generateFields[Apple]
}
Fields annotated with @BsonProperty (mongo-scala-bson) or @bsonField
(zio-bson) keep their Scala name but carry the annotated wire name as value:
@moka
case class Fruit(@BsonProperty("c") color: String, @bsonField("w") weight: Double)
object Fruit {
val Fields = generateFields[Fruit]
}
Fruit.Fields.color == "c"
Fruit.Fields.weight == "w"
generateFields (and @moka) defaults to MongoDB's BSON wire format and ignores
JSON annotations, avoiding unintended renames in Mongo queries.
To target JSON or project both formats from the same model, use generateBsonFields / @mokaBson and generateJsonFields / @mokaJson:
@moka
case class Fruit(
_id: String,
@BsonProperty("b_col") @jsonField("color") color: String
)
object Fruit {
val BsonFields = generateBsonFields[Fruit] // BsonFields.color == "b_col"
val JsonFields = generateJsonFields[Fruit] // JsonFields.color == "color"
}
@jsonField (zio-json), matched by simple name without library dependencies.@BsonProperty("a") and @bsonField("b")), compilation fails fast with an informative error. Agreeing annotations succeed.A field whose type is another case class becomes a path node exposing that type's fields, each carrying the dotted path MongoDB expects:
@moka
case class Engine(power: Int)
object Engine {
val Fields = generateFields[Engine]
}
@moka
case class Car(engine: Engine, wheels: List[Engine])
object Car {
val Fields = generateFields[Car]
}
Car.Fields.engine.power == "engine.power"
Car.Fields.engine._path == "engine"
Option and collections are transparent (List[Engine] gives the same path).
A collection of case classes also exposes MongoDB's array operators:
Car.Fields.wheels._matched.power == "wheels.$.power" // positional $
Car.Fields.wheels._all.power == "wheels.$[].power" // $[]
Every generated member starts with an underscore (_path, _matched, _all),
so it can never collide with a field of your own.
On Scala 2.13 — and so in cross-compiled sources — every nested case class
needs its own moka object (since 0.2.0), as Engine has above: the outer
object takes the nested names from it, which is what keeps zio-bson and
zio-json renames correct across modules, jars and incremental builds. Without
one, compilation fails and says what to add. Scala 3 needs none. See the
Scala 2 page for the details and the opt-out.
When using mongodb, you are required to set the field name when filtering or
for projections. With this macro you can avoid setting the name manually and
instead use the Fields object.
Apache-2.0. Copyright 2026 Vittorio Malaguti.