sf_cli 0.0.7 → 0.0.8

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/{rdoc/README.rdoc → README.rdoc} +24 -38
  3. data/lib/sf_cli/console/commands.rb +36 -0
  4. data/lib/sf_cli/console.rb +5 -0
  5. data/lib/sf_cli/sf/apex/core.rb +5 -6
  6. data/lib/sf_cli/sf/apex/run.rb +13 -10
  7. data/lib/sf_cli/sf/core/base.rb +1 -0
  8. data/lib/sf_cli/sf/data/bulk_result_v2.rb +2 -3
  9. data/lib/sf_cli/sf/data/core.rb +5 -6
  10. data/lib/sf_cli/sf/data/create_record.rb +6 -8
  11. data/lib/sf_cli/sf/data/delete_bulk.rb +9 -10
  12. data/lib/sf_cli/sf/data/delete_record.rb +8 -9
  13. data/lib/sf_cli/sf/data/delete_resume.rb +7 -9
  14. data/lib/sf_cli/sf/data/get_record.rb +11 -13
  15. data/lib/sf_cli/sf/data/helper_methods.rb +1 -0
  16. data/lib/sf_cli/sf/data/query.rb +20 -27
  17. data/lib/sf_cli/sf/data/query_helper.rb +3 -0
  18. data/lib/sf_cli/sf/data/resume.rb +6 -6
  19. data/lib/sf_cli/sf/data/search.rb +9 -10
  20. data/lib/sf_cli/sf/data/update_record.rb +11 -14
  21. data/lib/sf_cli/sf/data/upsert_bulk.rb +9 -12
  22. data/lib/sf_cli/sf/data/upsert_resume.rb +7 -10
  23. data/lib/sf_cli/sf/main.rb +7 -3
  24. data/lib/sf_cli/sf/model/base_methods.rb +1 -0
  25. data/lib/sf_cli/sf/model/class_definition.rb +1 -0
  26. data/lib/sf_cli/sf/model/dml_methods.rb +1 -0
  27. data/lib/sf_cli/sf/model/generator.rb +2 -1
  28. data/lib/sf_cli/sf/model/query_condition.rb +1 -0
  29. data/lib/sf_cli/sf/model/query_methods.rb +1 -0
  30. data/lib/sf_cli/sf/model/sf_command_connection.rb +24 -5
  31. data/lib/sf_cli/sf/model.rb +6 -4
  32. data/lib/sf_cli/sf/org/core.rb +6 -6
  33. data/lib/sf_cli/sf/org/display.rb +7 -6
  34. data/lib/sf_cli/sf/org/list.rb +12 -13
  35. data/lib/sf_cli/sf/org/login.rb +22 -28
  36. data/lib/sf_cli/sf/project/core.rb +10 -72
  37. data/lib/sf_cli/sf/project/generate.rb +35 -0
  38. data/lib/sf_cli/sf/project/generate_manifest.rb +31 -0
  39. data/lib/sf_cli/sf/sobject/core.rb +10 -47
  40. data/lib/sf_cli/sf/sobject/describe.rb +29 -0
  41. data/lib/sf_cli/sf/sobject/list.rb +18 -0
  42. data/lib/sf_cli.rb +5 -12
  43. metadata +10 -9
  44. data/CHANGELOG.md +0 -57
  45. data/lib/sf_cli/sf/console.rb +0 -33
  46. data/rdoc/ObjectModel.rdoc +0 -83
@@ -1,57 +1,20 @@
1
1
  require_relative '../core/base'
2
- require_relative './schema'
2
+ require_relative './describe'
3
+ require_relative './list'
3
4
 
4
5
  module SfCli
5
6
  module Sf
7
+ #
8
+ # SObject Commands
9
+ #
10
+ # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm command reference
11
+ #
6
12
  module Sobject
7
- # ==== description
8
- # The class representing *sf* *sobject*
9
- #
10
- # command reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm
11
- #
13
+ # @private :nodoc: just for developers
12
14
  class Core
13
15
  include ::SfCli::Sf::Core::Base
14
-
15
- # returns a schema object containing the Salesforce object schema
16
- #
17
- # *objectType* --- object type (ex: Account)<br>
18
- #
19
- # *target_org* --- an alias of paticular org, or username can be used<br>
20
- #
21
- # ======
22
- # schema = sf.sobject.describe :Account
23
- # schema.name # Account
24
- # schema.label # Account
25
- # schema.field_names # [:Id, :Name, ....]
26
- # schema.fields[:Name] # => {"aggregatable"=>true, "aiPredictionField"=>false, "autoNumber"=>false,...}
27
- #
28
- # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_describe_unified]
29
- #
30
- def describe(object_type, target_org: nil)
31
- flags = {
32
- :"sobject" => object_type,
33
- :"target-org" => target_org,
34
- }
35
- json = exec(__method__, flags: flags, redirection: :null_stderr)
36
- Schema.new(json['result'])
37
- end
38
-
39
- # returns a list of Salesforce object name
40
- #
41
- # *object_type* --- all or custom<br>
42
- #
43
- # *target_org* --- an alias of paticular org, or username can be used<br>
44
- #
45
- # For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_list_unified]
46
- #
47
- def list(object_type, target_org: nil)
48
- flags = {
49
- :"sobject" => (object_type.to_sym == :custom ? :custom : :all),
50
- :"target-org" => target_org,
51
- }
52
- json = exec(__method__, flags: flags, redirection: :null_stderr)
53
- json['result']
54
- end
16
+ include Describe
17
+ include List
55
18
  end
56
19
  end
57
20
  end
@@ -0,0 +1,29 @@
1
+ require_relative './schema'
2
+
3
+ module SfCli::Sf::Sobject
4
+ module Describe
5
+ # Returns a schema object containing the Salesforce object schema
6
+ # @param object_type [Symbol,String] object type(ex: Account)
7
+ # @param target_org [Symbol,String] an alias of paticular org, or username can be used
8
+ #
9
+ # @return [Schema] a schema object that represents the object schema
10
+ #
11
+ # @example
12
+ # schema = sf.sobject.describe :Account
13
+ # schema.name # Account
14
+ # schema.label # Account
15
+ # schema.field_names # [:Id, :Name, ....]
16
+ # schema.fields[:Name] # => {"aggregatable"=>true, "aiPredictionField"=>false, "autoNumber"=>false,...}
17
+ #
18
+ # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_describe_unified command reference
19
+ #
20
+ def describe(object_type, target_org: nil)
21
+ flags = {
22
+ :"sobject" => object_type,
23
+ :"target-org" => target_org,
24
+ }
25
+ json = exec(__method__, flags: flags, redirection: :null_stderr)
26
+ Schema.new(json['result'])
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ module SfCli::Sf::Sobject
2
+ module List
3
+ # Returns a list of Salesforce object name
4
+ # @param object_type [Symbol,String] 'all' or 'custom'
5
+ # @param target_org [Symbol,String] an alias of paticular org, or username can be used
6
+ #
7
+ # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_list_unified command reference
8
+ #
9
+ def list(object_type, target_org: nil)
10
+ flags = {
11
+ :"sobject" => (object_type.to_sym == :custom ? :custom : :all),
12
+ :"target-org" => target_org,
13
+ }
14
+ json = exec(__method__, flags: flags, redirection: :null_stderr)
15
+ json['result']
16
+ end
17
+ end
18
+ end
data/lib/sf_cli.rb CHANGED
@@ -1,18 +1,11 @@
1
1
  require 'sf_cli/sf/main'
2
- #
3
- # the global method that represents *sf* command.
2
+
3
+ # The global method that represents *sf* command.
4
4
  #
5
5
  # With method chaining, you can use similar syntax as original command.
6
- #
7
- # == examples
8
- #
9
- # ======
10
- # sf.org.display # => returns the org information object
11
- #
12
- # ======
13
- # sf.data.query "SELECT Name FROM Account" # => [{"Name"=>"Aethna Home Products"}]
14
- #
15
- # For details of sf command, see the {reference guide}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_unified.htm]
6
+ # @example
7
+ # sf.org.display # returns the org information object
8
+ # sf.data.query "SELECT Name FROM Account" # [{"Name"=>"Aethna Home Products"}]
16
9
  #
17
10
  def sf
18
11
  SfCli::Sf::Main.instance
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sf_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takanobu Maekawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-18 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is a class library for introducing Salesforce CLI to Ruby scripting.
14
14
  Currenty only sf command is the target of development.
@@ -16,15 +16,14 @@ email:
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files:
19
- - rdoc/ObjectModel.rdoc
20
- - rdoc/README.rdoc
21
- - CHANGELOG.md
19
+ - README.rdoc
22
20
  files:
23
- - CHANGELOG.md
21
+ - README.rdoc
24
22
  - lib/sf_cli.rb
23
+ - lib/sf_cli/console.rb
24
+ - lib/sf_cli/console/commands.rb
25
25
  - lib/sf_cli/sf/apex/core.rb
26
26
  - lib/sf_cli/sf/apex/run.rb
27
- - lib/sf_cli/sf/console.rb
28
27
  - lib/sf_cli/sf/core/base.rb
29
28
  - lib/sf_cli/sf/data/bulk_result_v2.rb
30
29
  - lib/sf_cli/sf/data/core.rb
@@ -55,10 +54,12 @@ files:
55
54
  - lib/sf_cli/sf/org/list.rb
56
55
  - lib/sf_cli/sf/org/login.rb
57
56
  - lib/sf_cli/sf/project/core.rb
57
+ - lib/sf_cli/sf/project/generate.rb
58
+ - lib/sf_cli/sf/project/generate_manifest.rb
58
59
  - lib/sf_cli/sf/sobject/core.rb
60
+ - lib/sf_cli/sf/sobject/describe.rb
61
+ - lib/sf_cli/sf/sobject/list.rb
59
62
  - lib/sf_cli/sf/sobject/schema.rb
60
- - rdoc/ObjectModel.rdoc
61
- - rdoc/README.rdoc
62
63
  homepage: https://github.com/tmkw/sf_cli
63
64
  licenses:
64
65
  - MIT
data/CHANGELOG.md DELETED
@@ -1,57 +0,0 @@
1
- ## 0.0.7 - 2024-09-19
2
- - NEW: add `sf.apex.run`
3
- ## 0.0.6 - 2024-09-16
4
- - NEW: Object Model Support renewal;
5
- - `SfCli::Sf::Model.connection` represents the connection to Salesforce. It can be set by `set_connection` class method in the module. As of now there is only `SfCommandConnection`, which is based on sf command, as connection adapter. After the connection is set by `set_connection`, it is also automatically set to classes when `SfCli::Sf::Model.generate` method is called.
6
- - Each object model class has `create` class method for creating a new record.
7
- - Each object model has `#save` and `#delete` instance methods to create, update and delete the record it represents.
8
- - Each object class has query interface such as `where`, `select`, `limit` and `order` methods that can be chainable.
9
- - Each object class has query interface such as `find`, `all`, `take` and `pluck`.
10
- - CHANGE: `sf.sobject.describe` changed to return `schema` object.
11
- ## 0.0.5 - 2024-09-08
12
- - CHANGE: target CLI version is changed: from 2.54.6 to 2.56.7
13
- - NEW: new command features are added;
14
- - `--bulk` option to `sf.data.query`
15
- - `sf.data.query_resume`
16
- - `sf.data.upsert_bulk`
17
- - `sf.data.upsert_resume`
18
- - `sf.data.delete_bulk`
19
- - `sf.data.delete_resume`
20
- - `sf.data.resume`
21
- - `sf.data.search`
22
- - `sf.org.list`
23
- - `sf.login_access_token`
24
- - `--browser` option to `sf.login_web`
25
- ## 0.0.4 - 2024-09-02
26
- - breaking change:
27
- - Sf class doesn't exist anymore. You can not write like `sf = SfCli::Sf.new`. Instead of that, global `sf` method is introduced. You can directly type like `sf.org.display`, which is as almost same usability as the original command.
28
- - sf data query:
29
- - support child-parent relationship
30
- - support parent-children relationship
31
- - add `--result-format` option
32
- - auto generation of \Object Model (experimental)
33
- - generates SF \Object Classes automatically
34
- - relationship is supported
35
-
36
- ## 0.0.3 - 2024-08-25
37
- add command operations:
38
-
39
- - sf data get record
40
- - sf data create record
41
- - sf data update record
42
- - sf data delete record
43
-
44
- ## 0.0.2 - 2024-08-18
45
- this version up was made by mistake.
46
- nothing was changed.
47
-
48
- ## 0.0.1 - 2024-08-18
49
- support some command operations:
50
-
51
- - sf org login web
52
- - sf display
53
- - sf data query
54
- - sf sobject describe
55
- - sf sobject list
56
- - sf project generate
57
- - sf project generate manifest
@@ -1,33 +0,0 @@
1
- require 'sf_cli'
2
- require 'sf_cli/sf/model'
3
- require 'sf_cli/sf/model/sf_command_connection'
4
- require 'stringio'
5
-
6
- def sf_init(org_alias)
7
- org_info = sf.org.display target_org: org_alias
8
- conn = SfCli::Sf::Model::SfCommandConnection.new target_org: org_alias, instance_url: org_info.instance_url
9
- SfCli::Sf::Model.set_connection conn
10
- end
11
-
12
- def generate(*object_types)
13
- SfCli::Sf::Model.generate object_types
14
- end
15
-
16
- def connection
17
- SfCli::Sf::Model.connection
18
- end
19
-
20
- def target_org
21
- connection.target_org
22
- end
23
-
24
- def apex(apex_code)
25
- sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
26
- end
27
-
28
- alias :sfinit :sf_init
29
- alias :gen :generate
30
- alias :conn :connection
31
- alias :org :target_org
32
-
33
- sfinit ARGV[0]
@@ -1,83 +0,0 @@
1
- == \Object Model support
2
- === generate Models
3
- require 'sf_cli/sf/model'
4
- require 'sf_cli/sf/model/sf_command_connection'
5
-
6
- # first, you must prepare the connection
7
- conn = SfCli::Sf::Model::SfCommandConnection.new target_org: your_org, instance_url: your_org_url
8
-
9
- # then set it to Model module
10
- SfCli::Sf::Model.set_connection conn
11
-
12
- # generates some model classes (for example, Account and Contact)
13
- SfCli::Sf::Model.generate %w[Account Contact]
14
- === apply to sf command
15
- rows = sf.data.query "SELECT Id, Name FROM Contact WHERE Name = 'Akin Kristen'", model_class: Contact
16
-
17
- # the array object contains Contact object instances
18
- rows.size # 1
19
- rows.first # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
20
- rows.first.Name # Akin Kristen
21
-
22
- === using models Independently
23
- ==== initialize and save a record
24
- c = Contact.new(:Name => "John Smith")
25
- c.Name # "John Smith"
26
- c.save
27
-
28
- ==== find and update a record
29
- # find by record ID and update
30
- c2 = Contact.find(c.id)
31
- c2.Name = "Johnny Smith"
32
- c2.save # update
33
-
34
- ==== delete a record
35
- c2 = Contact.find(c.id)
36
- c2.delete
37
-
38
- ==== query and get a record
39
- contact = Contact.select(:Id, :Name).where(Name: 'Akin Kristen').take
40
- contact # => #<Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
41
- contact.Name # Akin Kristen
42
-
43
- # these 2 example are the same meaning
44
- Contact.select(Name).where(Name: 'John Smith', LastModifiedDate: :Yesterday).take
45
- Contact.select(Name).where(Name: 'John Smith').where(LastModifiedDate: :Yesterday).take
46
-
47
- ==== query and get records
48
- contacts = Contact.select(:Id, :Name).where(LastModifiedDate: :Yesterday).all # get all records that is modified yesterday
49
-
50
- ==== child-parent relationship
51
- contact = Contact.select(:Id, :Name, "Account.Name").where(Name: 'Akin Kristen').take
52
- contact # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen", @Account= #<Account @Name="Aethna Home Products">>
53
- contact.Account.Name # Aethna Home Products
54
-
55
- ==== parent-children relationship
56
- account = Account.select(:Id, :Name, "(SELECT Name FROM Contacts)").take
57
- account # <Account @Contacts=[#<Contact @Name="Akin Kristen">], @Id="0015j00001dsDuhAAE", @Name="Aethna Home Products">
58
- account.Name # Aethna Home Products
59
- rows.Contacts # [#<Contact @Name="Akin Kristen">]
60
- rows.Contacts.first.Name # Akin Kristen
61
-
62
- ==== get all fields in a record
63
- # just by not using 'select' method
64
- contact = Contact.find(record_id) # <Contact @Id="...", @Name="...", other fields...>
65
-
66
- ==== time keywords such as 'yesterday' or 'LAST_N_DAYS:N' with symbol style
67
- Contact.select(:Name).where(LastModifiedDate: :Yesterday).take # "SELECT Id, Name FROM Contact WHERE LastModifiedDate = Yesterday"
68
- Contact.select(:Name).where(LastModifiedDate: :"LAST_N_DAYS:5").take # "SELECT Id, Name FROM Contact WHERE LastModifiedDate = LAST_N_DAYS:5"
69
-
70
- ==== array for 'IN' keyword
71
- Contact.select(:Name).where(Name: ['Jonny Good', 'John Smith']).all # same as "SELECT Name FROM Contact WHERE Name IN ('Jonny Good', 'John Smith')"
72
-
73
- ==== using partial soql directly
74
- Contact.select("Id, Name").where("LastModifiedDate = LAST_N_DAYS:5").all
75
-
76
- ==== ternary style
77
- Contact.select(:Id, :Name).where(:LastModifiedDate, :>=, :"LAST_N_DAYS:5").all # SELECT Id, Name FROM Contact WHERE LastModifiedDate >= LAST_N_DAYS:5
78
- Account.select(:Id, :Name).where(:Name, :LIKE, "%OIL%").all # SELECT Id, Name FROM Account WHERE Name LIKE '%OIL%'
79
-
80
- ==== get schema
81
- schema = Account.describe
82
- schema.name # Account
83
- schema.field_names # [Id, Name, ....]