datomic-flare 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.env.example +4 -0
 - data/.gitignore +3 -0
 - data/.rspec +1 -0
 - data/.rubocop.yml +15 -0
 - data/.ruby-version +1 -0
 - data/Gemfile +19 -0
 - data/Gemfile.lock +100 -0
 - data/LICENSE +9 -0
 - data/README.md +1042 -0
 - data/components/errors.rb +22 -0
 - data/components/http.rb +55 -0
 - data/controllers/api.rb +48 -0
 - data/controllers/client.rb +43 -0
 - data/controllers/documentation/formatter.rb +37 -0
 - data/controllers/documentation/generator.rb +390 -0
 - data/controllers/dsl/querying.rb +39 -0
 - data/controllers/dsl/schema.rb +37 -0
 - data/controllers/dsl/transacting.rb +62 -0
 - data/controllers/dsl.rb +48 -0
 - data/datomic-flare.gemspec +39 -0
 - data/docs/CURL.md +781 -0
 - data/docs/README.md +360 -0
 - data/docs/api.md +395 -0
 - data/docs/dsl.md +257 -0
 - data/docs/templates/.rubocop.yml +15 -0
 - data/docs/templates/README.md +319 -0
 - data/docs/templates/api.md +267 -0
 - data/docs/templates/dsl.md +206 -0
 - data/helpers/h.rb +17 -0
 - data/logic/dangerous_override.rb +108 -0
 - data/logic/querying.rb +34 -0
 - data/logic/schema.rb +91 -0
 - data/logic/transacting.rb +53 -0
 - data/logic/types.rb +141 -0
 - data/ports/cli.rb +26 -0
 - data/ports/dsl/datomic-flare/errors.rb +5 -0
 - data/ports/dsl/datomic-flare.rb +20 -0
 - data/static/gem.rb +15 -0
 - metadata +146 -0
 
| 
         @@ -0,0 +1,62 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative '../../logic/transacting'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative '../../logic/types'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module Flare
         
     | 
| 
      
 7 
     | 
    
         
            +
              module DSLTransacting
         
     | 
| 
      
 8 
     | 
    
         
            +
                def retract_from!(namespace, data, database: nil, debug: nil)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  transaction_data = data.is_a?(Array) ? data : [data]
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  transaction_data = TransactingLogic.retractions_to_edn(
         
     | 
| 
      
 12 
     | 
    
         
            +
                    namespace, transaction_data
         
     | 
| 
      
 13 
     | 
    
         
            +
                  )
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  payload = { data: transaction_data }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  payload[:connection] = { database: { name: database } } unless database.nil?
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  response = client.api.transact!(payload, debug:)
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  debug ? response : true
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def assert_into!(namespace, data, database: nil, raw: nil, debug: nil)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  transaction_data = data.is_a?(Array) ? data : [data]
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  ids = {}
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  # Within the scope of a single transaction, tempids map consistently
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # to permanent ids. Values of n from -1 to -1000000, inclusive, are
         
     | 
| 
      
 31 
     | 
    
         
            +
                  # reserved for user-created tempids.
         
     | 
| 
      
 32 
     | 
    
         
            +
                  transaction_data = transaction_data.map.with_index do |fact, i|
         
     | 
| 
      
 33 
     | 
    
         
            +
                    if fact.key?(:_id)
         
     | 
| 
      
 34 
     | 
    
         
            +
                      ids[fact[:_id]] = fact[:_id]
         
     | 
| 
      
 35 
     | 
    
         
            +
                      fact
         
     | 
| 
      
 36 
     | 
    
         
            +
                    else
         
     | 
| 
      
 37 
     | 
    
         
            +
                      temporary_id = (i + 1) * -1
         
     | 
| 
      
 38 
     | 
    
         
            +
                      ids[temporary_id] = nil
         
     | 
| 
      
 39 
     | 
    
         
            +
                      fact.merge({ _temporary_id: temporary_id })
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  transaction_data = TransactingLogic.transactions_to_edn(
         
     | 
| 
      
 44 
     | 
    
         
            +
                    namespace, transaction_data
         
     | 
| 
      
 45 
     | 
    
         
            +
                  )
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  payload = { data: transaction_data }
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  payload[:connection] = { database: { name: database } } unless database.nil?
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  result = client.api.transact!(payload, debug:)
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  return result if debug || raw
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  result['data']['tempids'].map do |temporary_id, entity_id|
         
     | 
| 
      
 56 
     | 
    
         
            +
                    ids[temporary_id.to_i] = entity_id
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                  data.is_a?(Array) ? ids.values : ids.values.first
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
            end
         
     | 
    
        data/controllers/dsl.rb
    ADDED
    
    | 
         @@ -0,0 +1,48 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'dsl/schema'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative 'dsl/transacting'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative 'dsl/querying'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module Flare
         
     | 
| 
      
 8 
     | 
    
         
            +
              class DSL
         
     | 
| 
      
 9 
     | 
    
         
            +
                include DSLQuerying
         
     | 
| 
      
 10 
     | 
    
         
            +
                include DSLSchema
         
     | 
| 
      
 11 
     | 
    
         
            +
                include DSLTransacting
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                attr_reader :client, :api
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def initialize(client)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @client = client
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @api = client.api
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def create_database!(database_name, debug: nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  result = api.create_database!(
         
     | 
| 
      
 22 
     | 
    
         
            +
                    { name: database_name }, debug:
         
     | 
| 
      
 23 
     | 
    
         
            +
                  )
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  debug ? result : result['data']
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def destroy_database!(database_name, debug: nil)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  result = api.delete_database!(
         
     | 
| 
      
 30 
     | 
    
         
            +
                    { name: database_name }, debug:
         
     | 
| 
      
 31 
     | 
    
         
            +
                  )
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  debug ? result : result['data']
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                def databases(mode:, debug: nil)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  mode = client.meta['meta']['mode'] if mode.nil?
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  response = if mode == 'peer'
         
     | 
| 
      
 40 
     | 
    
         
            +
                               client.api.get_database_names(debug:)
         
     | 
| 
      
 41 
     | 
    
         
            +
                             else
         
     | 
| 
      
 42 
     | 
    
         
            +
                               client.api.list_databases(debug:)
         
     | 
| 
      
 43 
     | 
    
         
            +
                             end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  debug ? response : response['data']
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'static/gem'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 6 
     | 
    
         
            +
              spec.name    = Flare::GEM[:name]
         
     | 
| 
      
 7 
     | 
    
         
            +
              spec.version = Flare::GEM[:version]
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.authors = [Flare::GEM[:author]]
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              spec.summary = Flare::GEM[:summary]
         
     | 
| 
      
 11 
     | 
    
         
            +
              spec.description = Flare::GEM[:description]
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              spec.homepage = Flare::GEM[:github]
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              spec.license = Flare::GEM[:license]
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              spec.required_ruby_version = Gem::Requirement.new(">= #{Flare::GEM[:ruby]}")
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              spec.metadata['allowed_push_host'] = Flare::GEM[:gem_server]
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              spec.metadata['homepage_uri'] = spec.homepage
         
     | 
| 
      
 22 
     | 
    
         
            +
              spec.metadata['source_code_uri'] = Flare::GEM[:github]
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              spec.files = Dir.chdir(File.expand_path(__dir__)) do
         
     | 
| 
      
 25 
     | 
    
         
            +
                `git ls-files -z`.split("\x0").reject do |f|
         
     | 
| 
      
 26 
     | 
    
         
            +
                  f.match(%r{\A(?:test|spec|features)/})
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              spec.require_paths = ['ports/dsl']
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              spec.add_dependency 'faraday', '~> 2.12'
         
     | 
| 
      
 33 
     | 
    
         
            +
              spec.add_dependency 'faraday-typhoeus', '~> 1.1'
         
     | 
| 
      
 34 
     | 
    
         
            +
              spec.add_dependency 'typhoeus', '~> 1.4', '>= 1.4.1'
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              spec.add_dependency 'uuidx', '~> 0.10.0'
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              spec.metadata['rubygems_mfa_required'] = 'true'
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     |