neon_schemas 0.1.3 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 256ab185a37500f1421db349c6592519b70f632ef546e9bc14f2743ed98240ba
4
- data.tar.gz: 7521061a30c9d0209a300176c05ac2c3979755cd29e629a4fbae159de9edc36d
3
+ metadata.gz: a424270038e2855b7fb950dde4ce047aff75553b0e3aa4bf6aaf6afedf295547
4
+ data.tar.gz: dbaeeae211db24dba2be55c5be3a0671026649d9987dbf50eb17dc6727511f35
5
5
  SHA512:
6
- metadata.gz: 643cf45777e56a9fce7e850083bdef6d361c109b046a75d5f39f1ee7f26077aeaca4df196e07e9013ec71f5a7d7e1b3c49b1a74211412866750e131b34304ff9
7
- data.tar.gz: eabcd65d93a71e80e8f19dc040d466b7b81998b4dd9c9406b522e647491c975a7b47f0ce077aa3729ec9d5549f9a35c8baabda6901412afdb19815c5386b31b6
6
+ metadata.gz: 843bd7a29981c338aa3507cb9d097a3b7b009b1e5c947b623047db425a1a8fa72d62bb5c151f2fe75265d3c3b6e8ea704d0fb19e0ba80fa49faa3d7e110987c8
7
+ data.tar.gz: '03947621adb4591ee887956d7fe0d53081ea31130cc508bcc3853fd296bfc3f20b60d7c198ef443f0cbb9987552c3e04ca2419375a5afe810384d081348536ca'
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neon_schemas (0.1.2)
4
+ neon_schemas (0.1.6)
5
5
  avro (~> 1.10)
6
+ dry-validation (= 1.6)
7
+ neon_operations (= 0.0.1)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
@@ -11,9 +13,45 @@ GEM
11
13
  avro (1.10.2)
12
14
  multi_json (~> 1)
13
15
  coderay (1.1.3)
16
+ concurrent-ruby (1.1.9)
14
17
  diff-lcs (1.4.4)
18
+ dry-configurable (0.12.1)
19
+ concurrent-ruby (~> 1.0)
20
+ dry-core (~> 0.5, >= 0.5.0)
21
+ dry-container (0.8.0)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-configurable (~> 0.1, >= 0.1.3)
24
+ dry-core (0.6.0)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-equalizer (0.3.0)
27
+ dry-inflector (0.2.0)
28
+ dry-initializer (3.0.4)
29
+ dry-logic (1.2.0)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-core (~> 0.5, >= 0.5)
32
+ dry-schema (1.7.0)
33
+ concurrent-ruby (~> 1.0)
34
+ dry-configurable (~> 0.8, >= 0.8.3)
35
+ dry-core (~> 0.5, >= 0.5)
36
+ dry-initializer (~> 3.0)
37
+ dry-logic (~> 1.0)
38
+ dry-types (~> 1.5)
39
+ dry-types (1.5.1)
40
+ concurrent-ruby (~> 1.0)
41
+ dry-container (~> 0.3)
42
+ dry-core (~> 0.5, >= 0.5)
43
+ dry-inflector (~> 0.1, >= 0.1.2)
44
+ dry-logic (~> 1.0, >= 1.0.2)
45
+ dry-validation (1.6.0)
46
+ concurrent-ruby (~> 1.0)
47
+ dry-container (~> 0.7, >= 0.7.1)
48
+ dry-core (~> 0.4)
49
+ dry-equalizer (~> 0.2)
50
+ dry-initializer (~> 3.0)
51
+ dry-schema (~> 1.5, >= 1.5.2)
15
52
  method_source (1.0.0)
16
53
  multi_json (1.15.0)
54
+ neon_operations (0.0.1)
17
55
  parallel (1.20.1)
18
56
  parser (3.0.1.1)
19
57
  ast (~> 2.4.1)
data/lib/neon_schemas.rb CHANGED
@@ -1,36 +1,10 @@
1
1
  require "neon_schemas/version"
2
- require "avro"
3
2
 
4
3
  module NeonSchemas
5
- class Error < StandardError; end
6
-
7
- class Avro
8
- SCHEMA_DIRECTORY = "#{__dir__}/../schemas"
9
-
10
- def self.encode(record:, schema_name:)
11
- avro_schema = ::Avro::Schema.parse(
12
- File.read("#{SCHEMA_DIRECTORY}/#{schema_name}.avsc")
13
- )
14
- writer = ::Avro::IO::DatumWriter.new avro_schema
15
- buffer = ::StringIO.new
16
- encoder = ::Avro::IO::BinaryEncoder.new buffer
17
-
18
- writer.write record, encoder
19
-
20
- buffer
21
- end
4
+ module Contracts; end
22
5
 
23
- def self.decode(string:, schema_name:)
24
- avro_schema = ::Avro::Schema.parse(
25
- File.read("#{SCHEMA_DIRECTORY}/#{schema_name}.avsc")
26
- )
27
- buffer = ::StringIO.new string
28
- decoder = ::Avro::IO::BinaryDecoder.new buffer
29
- reader = ::Avro::IO::DatumReader.new avro_schema
30
-
31
- json = reader.read(decoder).to_json
32
-
33
- JSON.parse(json, symbolize_names: true)
34
- end
35
- end
6
+ class Error < StandardError; end
36
7
  end
8
+
9
+ require "neon_schemas/avro"
10
+ Dir["#{__dir__}/neon_schemas/contracts/**/*.rb"].sort.each { |f| require f }
@@ -0,0 +1,34 @@
1
+ require "neon_schemas/version"
2
+ require "avro"
3
+
4
+ module NeonSchemas
5
+ class Avro
6
+ SCHEMA_DIRECTORY = "#{__dir__}/../../schemas"
7
+
8
+ def self.encode(record:, schema_name:)
9
+ avro_schema = ::Avro::Schema.parse(
10
+ File.read("#{SCHEMA_DIRECTORY}/#{schema_name.tr(".", "/")}.avsc")
11
+ )
12
+ writer = ::Avro::IO::DatumWriter.new avro_schema
13
+ buffer = ::StringIO.new
14
+ encoder = ::Avro::IO::BinaryEncoder.new buffer
15
+
16
+ writer.write record, encoder
17
+
18
+ buffer
19
+ end
20
+
21
+ def self.decode(string:, schema_name:)
22
+ avro_schema = ::Avro::Schema.parse(
23
+ File.read("#{SCHEMA_DIRECTORY}/#{schema_name.tr(".", "/")}.avsc")
24
+ )
25
+ buffer = ::StringIO.new string
26
+ decoder = ::Avro::IO::BinaryDecoder.new buffer
27
+ reader = ::Avro::IO::DatumReader.new avro_schema
28
+
29
+ json = reader.read(decoder).to_json
30
+
31
+ JSON.parse(json, symbolize_names: true)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ require "dry-validation"
2
+
3
+ module NeonSchemas::Contracts::Authentication
4
+ class SuccessfulLoginContract < Dry::Validation::Contract
5
+ json do
6
+ required(:email).filled(:string)
7
+ required(:sub).value(:string)
8
+ end
9
+
10
+ rule(:email) do
11
+ return if EMAIL_REGEX.match?(value)
12
+
13
+ key.failure("has invalid format")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require "dry-validation"
2
+
3
+ module NeonSchemas::Contracts::Documents
4
+ class ProcessDocumentContract < Dry::Validation::Contract
5
+ json do
6
+ required(:filename).filled(:string)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require "dry-validation"
2
+
3
+ module NeonSchemas::Contracts::OutboundEmails
4
+ class WelcomeEmailContract < Dry::Validation::Contract
5
+ json do
6
+ required(:email).filled(:string)
7
+ end
8
+
9
+ rule(:email) do
10
+ email_regex = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
11
+
12
+ return if email_regex.match?(value)
13
+
14
+ key.failure("has invalid format")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ require "dry-validation"
2
+
3
+ module NeonSchemas::Contracts::Slack
4
+ class SendMessageContract < Dry::Validation::Contract
5
+ json do
6
+ required(:message).filled(:string)
7
+ required(:channel).value(:string)
8
+ end
9
+
10
+ rule(:channel) do
11
+ return if channel == "devops"
12
+
13
+ key.failure("invalid channel")
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module NeonSchemas
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.6"
3
3
  end
data/neon_schemas.gemspec CHANGED
@@ -17,10 +17,12 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
21
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
22
  end
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_runtime_dependency "avro", "~> 1.10"
26
+ spec.add_runtime_dependency "dry-validation", "1.6"
27
+ spec.add_runtime_dependency "neon_operations", "0.0.1"
26
28
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neonlaw/schemas",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "license": "Apache-2.0",
5
5
  "author": "@neonlaw",
6
6
  "scripts": {
data/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "neon_schemas"
3
- version = "0.1.2"
3
+ version = "0.1.5"
4
4
  description = "Schemas for Neon Law"
5
5
  authors = ["neon law <support@neonlaw.com>"]
6
6
  license = "Apache-2.0"
@@ -1,5 +1,5 @@
1
1
  {
2
- "namespace": "com.neon_law.outbound_email",
2
+ "namespace": "com.neon_law.outbound_emails",
3
3
  "name": "welcome_email",
4
4
  "type": "record",
5
5
  "fields": [
@@ -9,8 +9,8 @@
9
9
  "doc": "The 'to' email to send the email to."
10
10
  },
11
11
  {
12
- "type" : "string",
13
- "name" : "sub",
12
+ "type": "string",
13
+ "name": "sub",
14
14
  "doc": "The 'sub' from Auth0."
15
15
  }
16
16
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neon_schemas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neon Law
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-validation
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: neon_operations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.1
27
55
  description: A gem containing schemas and encoding/decoding Avro classes
28
56
  email:
29
57
  - support@neonlaw.com
@@ -40,6 +68,11 @@ files:
40
68
  - bin/console
41
69
  - bin/setup
42
70
  - lib/neon_schemas.rb
71
+ - lib/neon_schemas/avro.rb
72
+ - lib/neon_schemas/contracts/authentication/successful_login_contract.rb
73
+ - lib/neon_schemas/contracts/documents/process_document_contract.rb
74
+ - lib/neon_schemas/contracts/outbound_emails/welcome_email_contract.rb
75
+ - lib/neon_schemas/contracts/slack/send_message_contract.rb
43
76
  - lib/neon_schemas/version.rb
44
77
  - neon_schemas.gemspec
45
78
  - neon_schemas/__init__.py