### Example Zen Namespace Definition (EDN) Source: https://github.com/zen-lang/zen/blob/master/README.md Defines a Zen namespace `myapp.module` with imports, database configuration (`db`), web server setup (`web`), API definition (`api`), and specific operation definitions (`create-pt`, `search-pt`). Demonstrates the structure of a Zen namespace, including tags, references between models, and nested configurations. ```edn { ns myapp.module ;; namespace name imports #{http pg model auth} ;; imports - TODO: think about aliases db {:zen/tags #{pg/config} :connection {:host "..." :port "..."} :storages #{model/patient-store}} ;; model web {:zen/tags #{http/server} ;; tags set :port 8080 :workers 8 :db db :apis #{api http/admin-api}} api {:zen/tags #{http/api} :zen/desc "API definition" :middleware [{:type http/cors :allow #{"https://myapp.io"}} {:type auth/authorize}] :routes { "Patient" {:post {:op create-pt} :get {:op search-pt}} "meta" {:get {:op http/meta}}}} create-pt {:zen/tags #{http/create} :operation http/create :schemas #{model/patient} :response { 201 {:confirms #{model/patient}} 422 {:confirms #{http/error}}}} search-pt {:zen/tags #{http/search} :operation http/search :store #{model/patient-store} :params {:query {:name {:zen/desc "Search by name" :engine http/fhir-search-param :type "string" :expression "Patient.name"} :ilike {:engine http/sql-search-param :query "resource::text ilike {{param.value}}"}}} :response { 201 {:confirms #{model/search-bundle}} 422 {:confirms #{model/search-errors}}}}} ``` -------------------------------- ### Zen Namespace with Local and External References Source: https://github.com/zen-lang/zen/blob/master/doc.md Provides an example of a Zen namespace demonstrating how to use both local references (within the same namespace) and external references (to models in imported namespaces) using symbols. ```EDN { ns myapp imports #{zenbox} ;; imported namespace operation { ;; ... } routes { :zen/tags #{zenbox/routes} ;; extrnal ref :GET operation ;; local ref, i.e. myapp/operation } main { :zen/tags #{zenbox/server} ;; extrnal ref :port 8080 :routes routes ;; local ref , i.e. myapp/routes } } ``` -------------------------------- ### Defining Schemas and Instances in Zen (EDN) Source: https://github.com/zen-lang/zen/blob/master/README.md This snippet defines several data schemas (Contact, Contactable, User) and a property schema (human-name) using Zen's schema language in EDN format. It demonstrates the use of tags, types, keys, confirmations, requirements, and regex for validation, along with an example instance conforming to the defined schemas. ```EDN {ns myapp Contact {:zen/tags #{zen/schema} :type zen/map :keys {:system {:type zen/string :enum [{:value "phone"} {:value "email"}]} :value {:type zen/string}}} Contactable {:zen/tags #{zen/schema} :type zen/map :keys {:contacts {:type zen/vector :every {:type map :confirms #{Contact}}}}} User {:zen/tags #{zen/schema} :type zen/map :confirms #{Contactable} :require #{:id :email} :keys { :id {:type zen/string} :email {:type zen/string :regex ".*@.*"} :password {:type zen/string }}} ;; example of property schema human-name {:zen/tags #{zen/property zen/schema} :type zen/map :keys {:family {:type zen/string} :given {:type zen/vector :every {:type zen/string}}}}} instance {:id "niquola" :myapp/human-name {:given ["Nikolai"] :family "Ryzhikov"} :password "secret"} ``` -------------------------------- ### Defining a Zen Namespace with Imports and Models Source: https://github.com/zen-lang/zen/blob/master/doc.md Demonstrates a more complete Zen namespace definition, including the `ns` key, the `imports` key for specifying dependencies on other namespaces, and definitions for multiple models within the namespace. ```EDN { ;; file name: my-package/my-namespace.edn { ;; namespace name ns my-package.my-namespace ;; dependencies imports #{library.utils} ;; model model { ;; ... } ;; other model other-model { ;; ... } } } ``` -------------------------------- ### Defining a Zen Namespace (Basic) Source: https://github.com/zen-lang/zen/blob/master/doc.md Shows the basic structure of a Zen namespace definition in an EDN file, including the `ns` key for the namespace name and placeholders for model definitions. ```EDN { ns package.namespace ;; ... model-name { ;; model data } } ``` -------------------------------- ### Zen Namespace with Environment Variable Readers (EDN) Source: https://github.com/zen-lang/zen/blob/master/README.md Illustrates how to use Zen's environment variable readers (`#env`, `#env-integer`, etc.) within an EDN namespace definition. Defines a schema and a model that reads various data types from environment variables, including support for default values. ```edn { ns test-env schema {:zen/tags #{zen/schema zen/tag} :type zen/map :keys {:string {:type zen/string} :int {:type zen/integer} :sym {:type zen/symbol} :key {:type zen/keyword} :num {:type zen/number} :bool {:type zen/boolean}}} model {:zen/tags #{schema } :string #env ESTR :int #env-integer EINT :sym #env-symbol ESYM :key #env-keyword EKEY :num #env-number ENUM} :bool #env-boolean BOOL ;; or with defaults :string #env [ESTR "Default"] } ``` -------------------------------- ### Using zen/case for Polymorphic Schema (EDN) Source: https://github.com/zen-lang/zen/blob/master/README.md This snippet demonstrates the use of the `zen/case` type in Zen schema definition. It defines a schema for a vector (`path`) where each element can be either a simple string or a map with a required `:name` key, illustrating how `zen/case` handles polymorphic data structures. ```EDN path {:zen/tags #{'zen/schema} :type 'zen/vector :every {:type 'zen/case :case [{:when {:type 'zen/string}} {:when {:type 'zen/map} :then {:type 'zen/map :require #{:name} :keys {:name {:type 'zen/string}}}}]}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.