Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
rename franken-gen -> generate, remove boot, remove dynaload
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchkyle-reify committed Oct 20, 2022
1 parent 08bddaf commit afcb798
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 192 deletions.
30 changes: 9 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ jobs:
environment:
- _JAVA_OPTIONS: "-Xms512m -Xmx1024m"
docker:
- image: circleci/openjdk:8-jdk-node
- image: cimg/clojure:1.11.1-openjdk-8.0-node
steps:
- checkout
- run:
name: Download boot
command: sudo curl -L https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh -o /usr/bin/boot
- run:
name: Change boot permissions
command: sudo chmod +x /usr/bin/boot
- run:
name: Check deps
command: boot show -d
name: Run clj tests
command: clojure -X:test
- run:
name: Run clj and cljs tests
command: boot test-all
name: Run cljs tests
command: clojure -X:test-cljs
- run:
name: Install bb
command: |
Expand All @@ -28,14 +22,14 @@ jobs:
command: bb test
- run:
name: Build
command: boot make # Validate the namespaces are correct
command: clojure -T:build jar # Validate the namespaces are correct
- save-cache:
paths:
- ~/bin
- ~/.m2
- ~/.boot/cache/bin
- ~/.boot/cache/lib
key: specmonstah-{{ checksum "build.boot" }}
key: specmonstah-{{ checksum "build.clj" }}
- persist_to_workspace:
root: ./
paths:
Expand All @@ -46,18 +40,12 @@ jobs:
steps:
- checkout
- restore_cache:
key: specmonstah-{{ checksum "build.boot" }}
key: specmonstah-{{ checksum "build.clj" }}
- attach_workspace:
at: ./
- run:
name: Download boot
command: sudo curl -L https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh -o /usr/bin/boot
- run:
name: Change boot permissions
command: sudo chmod +x /usr/bin/boot
- run:
name: Deploy to clojars
command: boot make push-release-without-gpg
command: clojure -T:build deploy

workflows:
version: 2
Expand Down
65 changes: 44 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ todos or todo lists?

```clojure
(ns short-sweet
(:require [reifyhealth.specmonstah.core :as sm]
[reifyhealth.specmonstah.franken-gen :as fg]
[clojure.spec.alpha :as s]
[clojure.test.check.generators :as gen]))
(:require [clojure.spec.alpha :as s]
[clojure.test.check.generators :as gen]
[reifyhealth.specmonstah.core :as sm]
[reifyhealth.specmonstah.generate :as generate]
;; Include namespace this if you want to use malli for generation
[reifyhealth.specmonstah.generate.malli]))

;;-------*****--------
;; Begin example setup
Expand Down Expand Up @@ -110,7 +112,9 @@ todos or todo lists?
[:map {:registry {::id [:schema {:gen/fmap gen-id} pos-int?]}}
[:id ::id]
[:created-by-id ::id]
[:content [:string {:min 1 :max 10}]]])
[:content [:string {:gen/gen gen/string-alpha-numeric ; for readability
:min 1
:max 10}]]])

;; Test Check Generator
(def like
Expand All @@ -121,9 +125,9 @@ todos or todo lists?

;; ---
;; The schema defines specmonstah `ent-types`, which roughly
;; correspond to db tables. It also defines the `:spec` for generting
;; ents of that type, and defines ent `relations` that specify how
;; ents reference each other
;; correspond to db tables. It also defines the default generation mechanism
;; for ents of that type (e.g `:spec`, `:malli`, `:generator`, `:fn`), and
;; defines ent `relations` that specify how ents reference each other
(def schema
{:user {:prefix :u
:spec ::user}
Expand All @@ -150,7 +154,7 @@ todos or todo lists?
(defn insert [query]
(reset! id-seq 0)
(reset! mock-db [])
(fg/generate {:schema schema} query :insert! insert*)
(generate/generate {:schema schema} query :insert! insert*)
;; normally you'd return the expression above, but return nil for
;; the example to not produce overwhelming output
nil)
Expand All @@ -160,28 +164,44 @@ todos or todo lists?
;;-------*****--------

;; Return a map of user entities and their generated data
(-> (fg/generate {:schema schema} {:user [[3]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:user [[3]]})
generate/attrs)

'=> {:u0 {:id 2, :username "3O9m6"},
:u1 {:id 1, :username "j7ABrtg0C"},
:u2 {:id 3, :username "a"}}

;; You can specify a username and id
(-> (fg/generate {:schema schema} {:user [[1 {:set {:username "Meeghan"
:id 100}}]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:user [[1 {:set {:username "Meeghan"
:id 100}}]]})
generate/attrs)

'=> {:u0 {:id 100, :username "Meeghan"}}

;; Generating a post generates the user the post belongs to, with
;; foreign keys correct
(-> (fg/generate {:schema schema} {:post [[1]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:post [[1]]})
generate/attrs)

'=> {:p0 {:id 6, :created-by-id 5, :content "`"},
:u0 {:id 5, :username "MXdL1snT"}}

;; Generating a like also generates a post and user
(-> (fg/generate {:schema schema} {:like [[1]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:like [[1]]})
generate/attrs)

'=> {:l0 {:id 11, :post-id 9, :created-by-id 8},
:p0 {:id 9, :created-by-id 8, :content "qwhl2!~"},
:u0 {:id 8, :username "2mcJPc"}}

;; The `insert` function shows that records are inserted into the
;; simulate "database" (`mock-db`) in correct dependency order:
(insert {:like [[1]]})
@mock-db

'=> [[:user {:id 1, :username "9m5VC9Us"}]
[:post {:id 2, :created-by-id 1, :content "9Yh9KzKYAgT"}]
[:like {:id 4, :post-id 2, :created-by-id 1}]]
```

## Usage
Expand Down Expand Up @@ -223,12 +243,15 @@ A schema is a map of _ent types_ to _ent type schemas_:
ents. [See the
tutorial](https://sweet-tooth.gitbook.io/specmonstah/tutorial/11-collect-constraint-vector-of-foreign-keys)
* `:required` is used to indicate ent sort order when your ent graph has a cycle
* For an entity to be generated with `reifyhealth.specmonstah.franken-gen/generate`
* For an entity to be generated with `reifyhealth.specmonstah.generate/generate`
it needs to include one of the following generation mechanism:
* `:spec` a clojure.spec for entity the same as what's used by `spec-gen`
* `:malli` a malli schema
* `:generator` a `test.check` generator
* `:fn` a plain function called with no arguments to generate the entity
* `:malli` a malli schema
* NOTE: to use malli, include
[metosin/malli](https://github.com/metosin/malli) as a dependency on your
project and load the namespace `reifyhealth.specmonstah.generate.malli`

You can also add arbitrary keys to the schema matching the
`visit-key`s you give to visiting functions. The schema will be
Expand Down Expand Up @@ -298,4 +321,4 @@ db. The second argument is a map that includes the following keys:

- document `:bind` syntax
- document `wrap-gen-data-visiting-fn`
- update tutorials to include franken-gen
- update tutorials to include `reifyhealth.specmonstah.generate`
5 changes: 2 additions & 3 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{:paths ["src" "test"]
{:paths ["src"]
:deps {aysylu/loom {:mvn/version "1.0.2"}
medley/medley {:mvn/version "0.8.3"}
better-cond/better-cond {:mvn/version "2.0.1-SNAPSHOT"}
org.clojure/core.specs.alpha {:mvn/version "0.2.62"}
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}
metosin/malli {:mvn/version "0.9.2"}
borkdude/dynaload {:mvn/version "0.3.5"}}
metosin/malli {:mvn/version "0.9.2"}}
:tasks
{test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
Expand Down
64 changes: 0 additions & 64 deletions build.boot

This file was deleted.

10 changes: 6 additions & 4 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

(defn deploy "Deploy the JAR to Clojars"
[opts]
(-> opts
(assoc :lib lib :version version)
(bb/deploy)))

(if-not (System/getenv "CI")
(do (println "Only CI is allowed to push a release")
(System/exit 1))
(-> opts
(assoc :lib lib :version version)
(bb/deploy)))

(defn jar "build a jar"
[opts]
Expand Down
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
:deps {aysylu/loom {:mvn/version "1.0.2"}
medley/medley {:mvn/version "0.8.3"}
better-cond/better-cond {:mvn/version "2.0.1-SNAPSHOT"}
org.clojure/spec.alpha {:mvn/version "0.3.218"}
borkdude/dynaload {:mvn/version "0.3.5"}}
org.clojure/spec.alpha {:mvn/version "0.3.218"}}

:aliases
{:test
Expand All @@ -17,7 +16,8 @@
:test-cljs
{:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "0.9.0"}
olical/cljs-test-runner {:mvn/version "3.8.0"}}
olical/cljs-test-runner {:mvn/version "3.8.0"}
metosin/malli {:mvn/version "0.8.9"}}
:exec-fn cljs-test-runner.main/-main}

:build
Expand Down
35 changes: 19 additions & 16 deletions examples/short-sweet/short_sweet.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(ns short-sweet
(:require [reifyhealth.specmonstah.core :as sm]
[reifyhealth.specmonstah.franken-gen :as fg]
[clojure.spec.alpha :as s]
[clojure.test.check.generators :as gen]))
(:require [clojure.spec.alpha :as s]
[clojure.test.check.generators :as gen]
[reifyhealth.specmonstah.core :as sm]
[reifyhealth.specmonstah.generate :as generate]
;; Include this if you want to use malli to generate entities
[reifyhealth.specmonstah.generate.malli]))

;;-------*****--------
;; Begin example setup
Expand Down Expand Up @@ -31,7 +33,9 @@
[:map {:registry {::id [:schema {:gen/fmap gen-id} pos-int?]}}
[:id ::id]
[:created-by-id ::id]
[:content [:string {:min 1, :max 10}]]])
[:content [:string {:gen/gen gen/string-alpha-numeric ; for readability
:min 1
:max 10}]]])

;; Test Check Generator
(def like
Expand Down Expand Up @@ -71,7 +75,7 @@
(defn insert [query]
(reset! id-seq 0)
(reset! mock-db [])
(fg/generate {:schema schema} query :insert! insert*)
(generate/generate {:schema schema} query :insert! insert*)
;; normally you'd return the expression above, but return nil for
;; the example to not produce overwhelming output
nil)
Expand All @@ -81,23 +85,22 @@
;;-------*****--------

;; Return a map of user entities and their generated data
(-> (fg/generate {:schema schema} {:user [[3]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:user [[3]]})
generate/attrs)

;; You can specify a username and id
(-> (fg/generate {:schema schema} {:user [[1 {:set {:username "Meeghan"
:id 100}}]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:user [[1 {:set {:username "Meeghan"
:id 100}}]]})
generate/attrs)

;; Generating a post generates the user the post belongs to, with
;; foreign keys correct
(-> (fg/generate {:schema schema} {:post [[1]]})
fg/attrs)
(-> (generate/generate {:schema schema} {:post [[1]]})
generate/attrs)

;; Generating a like also generates a post and user
(-> (fg/generate {:schema schema} {:like [[1]]})
fg/attrs)

(-> (generate/generate {:schema schema} {:like [[1]]})
generate/attrs)

;; The `insert` function shows that records are inserted into the
;; simulate "database" (`mock-db`) in correct dependency order:
Expand Down
Loading

0 comments on commit afcb798

Please sign in to comment.