shatter-rb 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.husky/commit-msg +5 -0
  3. data/.rubocop.yml +4 -0
  4. data/.ruby-version +1 -1
  5. data/.tool-versions +1 -1
  6. data/Gemfile +0 -2
  7. data/Gemfile.lock +51 -8
  8. data/Guardfile +72 -0
  9. data/README.md +76 -14
  10. data/commitlint.config.js +1 -0
  11. data/example_app/Gemfile +3 -2
  12. data/example_app/Gemfile.lock +9 -16
  13. data/example_app/app/application.rb +4 -0
  14. data/example_app/app/functions/hello_world_function.rb +8 -16
  15. data/example_app/app/service_definition.rb +2 -6
  16. data/example_app/application.rb +4 -2
  17. data/example_app/bin/service +2 -2
  18. data/example_app/config/environment.rb +13 -7
  19. data/example_app/config.ru +8 -0
  20. data/exe/console +1 -1
  21. data/exe/shatter +33 -23
  22. data/lib/shatter/config.rb +14 -4
  23. data/lib/shatter/service/base.rb +28 -35
  24. data/lib/shatter/service/discovery.rb +32 -19
  25. data/lib/shatter/service/function.rb +45 -31
  26. data/lib/shatter/service/response_pool.rb +12 -7
  27. data/lib/shatter/service/service_definition.rb +10 -4
  28. data/lib/shatter/util.rb +21 -5
  29. data/lib/shatter/version.rb +1 -1
  30. data/lib/shatter/web/application.rb +34 -32
  31. data/lib/shatter/web/server.rb +25 -18
  32. data/lib/shatter.rb +59 -11
  33. data/package.json +7 -0
  34. data/templates/Gemfile.template +1 -3
  35. data/templates/application.erb +2 -6
  36. data/templates/config.ru +8 -0
  37. data/templates/environment.rb.erb +9 -8
  38. data/templates/function_definition.ts.erb +5 -0
  39. data/templates/hello_world_function.rb.erb +6 -14
  40. data/templates/service_client.ts.erb +25 -0
  41. data/templates/service_definition.rb.erb +3 -7
  42. data/yarn.lock +1338 -0
  43. metadata +115 -25
  44. data/example_app/bin/console +0 -11
  45. data/lib/shatter/service/function_params.rb +0 -21
  46. data/shatter.gemspec +0 -51
@@ -1,9 +1,10 @@
1
- Shatter::Config.zookeeper_host = "localhost:2181"
2
- Shatter::Config.initial_delay = 100
3
- Shatter::Config.missing_result_delay = 100
4
- Shatter::Config.service_port = ENV.fetch('SHATTER_SERVICE_PORT') { 8787 }
1
+ Shatter.config do |config|
2
+ config.zookeeper_host = "localhost:2181"
3
+ config.initial_delay = 100
4
+ config.missing_result_delay = 100
5
+ config.service_port = ENV.fetch('SHATTER_SERVICE_PORT') { 8787 }
6
+ config.autoload_paths = %w( app app/functions )
7
+ config.reload_classes = true
8
+ end
5
9
 
6
- require_relative '../application'
7
-
8
- Shatter::Service::Base.service_definition = <%= app_name%>::ServiceDefinition
9
- Shatter::Web::Server.application = <%= app_name%>::Application
10
+ Shatter.load
@@ -0,0 +1,5 @@
1
+ async <%= function_nm.camel_case_lower %>( params : {<%= meta.map { |k,v| "#{k}#{v[:nullable] ? '?':''}: #{v[:type] == 'integer' ? 'number' : v[:type]}" }.join(", ") %>}){
2
+ return this.makeRequest<ShatterResult & {
3
+ result: any
4
+ }>('<%= function_nm %>', params )
5
+ }
@@ -1,17 +1,9 @@
1
- require "pg"
2
- require "shatter/service/function"
3
- require "shatter/service/function_params"
1
+ class HelloWorldFunction < Shatter::Service::Function
2
+ define_param :name, nullable: false, type: 'string'
3
+ define_param :number, nullable: false, type: 'integer'
4
4
 
5
- module <%= app_name %>
6
- module Functions
7
- class HelloWorldFunction < Shatter::Service::Function
8
- define_param :name, nullable: false, type: 'string'
9
- define_param :number, nullable: false, type: 'integer'
10
-
11
- def invoke
12
- params.to_h => name:, uuid:
13
- { result: "Hello #{name}", uuid:, error: nil, uuid: }
14
- end
15
- end
5
+ def invoke
6
+ params.to_h => name:, uuid:
7
+ { result: "Hello #{name}", error: nil, uuid: }
16
8
  end
17
9
  end
@@ -0,0 +1,25 @@
1
+ import { ShatterClient } from 'shatter-client'
2
+
3
+ interface ShatterResult {
4
+ result: string | number | Array<any> | object,
5
+ error: string | null
6
+ uuid: string
7
+ }
8
+
9
+ class AppClient {
10
+ client: ShatterClient;
11
+
12
+ constructor(host: string){
13
+ this.client = new ShatterClient(host)
14
+ }
15
+
16
+ async makeRequest<responseType>(operation : string, params : object) : Promise<responseType> {
17
+ return await this.client.invokeRPC(operation,params) as responseType;
18
+ }
19
+ }
20
+
21
+ class Client extends AppClient {
22
+ <%= function_defs.map(&:to_typescript).join("\n") %>
23
+ }
24
+
25
+ export default Client;
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './functions/hello_world_function'
4
-
5
- module <%= app_name %>
6
- class ServiceDefinition < Shatter::Service::ServiceDefinition
7
- register_function :hello_world, <%= app_name %>::Functions::HelloWorldFunction
8
- end
9
- end
3
+ class ServiceDefinition < Shatter::Service::ServiceDefinition
4
+ register_function :hello_world, HelloWorldFunction
5
+ end