Skip to content

Repository files navigation

Clojars Project cljdoc badge

The goal of this library is to facilitate translating back and forth between data in a form described by realms and a different form, usually EDN or Transit.

Latest Version

API Docs

Introduction

Given some data described by realms, for example a record:

(require '[active.data.record :as r])
(require '[active.data.realm :as realm])

(r/def-record user
  [user-id :- realm/integer
   user-name :- realm/string])

We can define a format that translates between instances of the record an EDN compatible map representation of the record, and identity translations for strings and integers:

(require '[active.data.translate.format :as format])
(require '[active.data.translate.formatter :as formatter])

(def my-edn-format
  {realm/string (formatter/identity realm/string)
   realm/integer (formatter/identity realm/interger)
   user (formatter/record-map user {user-id :id
                                    user-name :name})})

Using the format, we can create functions that translate between the two:

(require '[active.data.translate.core :as translate])

(def edn-from-user (translate/to-extern user my-edn-format))
(def edn-to-user (translate/from-extern user my-edn-format))

(= {:id 1 :name "Alice"}
   (edn-from-user (user user-id 1 user-name "Alice")))

(= (user user-id 1 user-name "Alice")
   (edn-to-user {:id 1 :name "Alice"}))

License

Copyright © 2024 Active Group GmbH

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

About

A library to define data translations based on realms.

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages