daytona 0.179.0 → 0.180.0.alpha.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea639b85defa7ec8ea3220b340850e2a8528258b4d84c99dafc48934f2527e78
4
- data.tar.gz: 4599b389e4591ea8b1a2776950b003f419c4636a5a66b2551c71b28255e2ce4e
3
+ metadata.gz: 5ef29fb3887fb9d38af38910afa732e55a63f6f6006f1096aa00f4a56aaa47ab
4
+ data.tar.gz: 4dd900933102173c986bc0c34683fa5f575da8fc18e2b94eb836f8c5caa254aa
5
5
  SHA512:
6
- metadata.gz: 2abc3f082a36a04e971d67c62f01f08126ba3c8fe81a2258c607fad204805ecb4551bd434c07d2ad55e569fb17fdef95ac068a426adb39518868f6e1dc6a6319
7
- data.tar.gz: 0ce97e0c6749c4473d995b78d4f4b29ec96363ff7c850a8d5f9ea051b2c9f08209302bbe05d7f53b96c44a3a6f0a5da01d4f6e4d9a6ebd5bfb210f0ccd26bf03
6
+ metadata.gz: 6653a399ac8b2689e2f515c675f7999ae2280ab9a802629b08c3fc017bcd530e11ab39a9524c4a0a5cc4ba61d102ce610ddc6a5ad3970cad1edd741685da6f65
7
+ data.tar.gz: a3136c2d3a5976a3c8177f0f1952929afbfb63cab2bcfc98730b945264ad4b6d76f53bdb0dae4c78f201f28acd212abcb12346a5d592952d0c4bc1c7fcb20f94
@@ -4,6 +4,12 @@
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Daytona
7
+ # Re-export of api-client enum constants under the Daytona namespace so
8
+ # SDK consumers never need to import from DaytonaApiClient directly.
9
+ SandboxState = DaytonaApiClient::SandboxState
10
+ SandboxListSortField = DaytonaApiClient::SandboxListSortField
11
+ SandboxListSortDirection = DaytonaApiClient::SandboxListSortDirection
12
+
7
13
  class PaginatedResource
8
14
  # @return [Array<Object>]
9
15
  attr_reader :items
@@ -28,4 +34,48 @@ module Daytona
28
34
  @total_pages = total_pages
29
35
  end
30
36
  end
37
+
38
+ # Query parameters for filtering and sorting when listing Sandboxes.
39
+ #
40
+ # All fields are optional and default to +nil+. Constructed via keyword
41
+ # arguments and immutable (Ruby 3.2+ Data semantics).
42
+ #
43
+ # @example
44
+ # query = Daytona::ListSandboxesQuery.new(labels: { 'env' => 'prod' }, limit: 10)
45
+ # daytona.list(query).each { |sandbox| puts sandbox.id }
46
+ ListSandboxesQuery = Data.define(
47
+ :limit,
48
+ :id,
49
+ :name,
50
+ :labels,
51
+ :states,
52
+ :snapshots,
53
+ :targets,
54
+ :min_cpu,
55
+ :max_cpu,
56
+ :min_memory_gib,
57
+ :max_memory_gib,
58
+ :min_disk_gib,
59
+ :max_disk_gib,
60
+ :is_public,
61
+ :is_recoverable,
62
+ :created_at_after,
63
+ :created_at_before,
64
+ :last_activity_after,
65
+ :last_activity_before,
66
+ :sort,
67
+ :order
68
+ ) do
69
+ # All members default to nil so callers pass only the filters they care about.
70
+ DEFAULTS = members.to_h { |m| [m, nil] }.freeze
71
+
72
+ class << self
73
+ alias_method :_data_new, :new
74
+ def new(**attrs) = _data_new(**DEFAULTS, **attrs)
75
+ end
76
+
77
+ # Idiomatic Ruby boolean predicate aliases.
78
+ def public? = is_public
79
+ def recoverable? = is_recoverable
80
+ end
31
81
  end
@@ -95,28 +95,32 @@ module Daytona
95
95
  to_sandbox(sandbox_dto:)
96
96
  end
97
97
 
98
- # Lists Sandboxes filtered by labels.
98
+ # Iterates over Sandboxes matching the given query.
99
99
  #
100
- # @param labels [Hash<String, String>]
101
- # @param page [Integer, Nil]
102
- # @param limit [Integer, Nil]
103
- # @return [Daytona::PaginatedResource]
100
+ # @param query [Daytona::ListSandboxesQuery, nil] Optional filters, sorting, and per-page size.
101
+ # @return [Enumerator<Daytona::Sandbox>]
104
102
  # @raise [Daytona::Sdk::Error]
105
- def list(labels = {}, page: nil, limit: nil)
106
- raise Sdk::Error, 'page must be positive integer' if page && page < 1
107
-
108
- raise Sdk::Error, 'limit must be positive integer' if limit && limit < 1
109
-
110
- response = sandbox_api.list_sandboxes_paginated(labels: JSON.dump(labels), page:, limit:)
111
-
112
- PaginatedResource.new(
113
- total: response.total,
114
- page: response.page,
115
- total_pages: response.total_pages,
116
- items: response.items.map do |sandbox_dto|
117
- to_sandbox(sandbox_dto:)
103
+ #
104
+ # @example
105
+ # daytona.list(Daytona::ListSandboxesQuery.new(labels: { 'env' => 'dev' })).each do |sandbox|
106
+ # puts sandbox.id
107
+ # end
108
+ def list(query = nil)
109
+ q = query || ListSandboxesQuery.new
110
+
111
+ Enumerator.new do |yielder|
112
+ cursor = nil
113
+ first_page = true
114
+ while first_page || cursor
115
+ first_page = false
116
+ response = fetch_sandbox_page(q, cursor)
117
+ response.items.each do |sandbox_dto|
118
+ yielder << to_sandbox(sandbox_dto: sandbox_dto)
119
+ end
120
+ cursor = response.next_cursor
121
+ break if cursor.nil? || (cursor.respond_to?(:empty?) && cursor.empty?)
118
122
  end
119
- )
123
+ end
120
124
  end
121
125
 
122
126
  # Starts a Sandbox and waits for it to be ready.
@@ -133,13 +137,51 @@ module Daytona
133
137
  # @return [void]
134
138
  def stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) = sandbox.stop(timeout)
135
139
 
136
- instrument :create, :delete, :get, :list, :start, :stop, component: 'Daytona'
140
+ instrument :create, :delete, :get, :start, :stop, component: 'Daytona'
137
141
 
138
142
  private
139
143
 
140
144
  # @return [Daytona::OtelState, nil]
141
145
  attr_reader :otel_state
142
146
 
147
+ # Fetches a single page of sandboxes. Each call produces one OTel span
148
+ # ("Daytona.list_fetch_page") so that paginated iteration emits N spans
149
+ # for N pages.
150
+ #
151
+ # @param q [Daytona::ListSandboxesQuery]
152
+ # @param cursor [String, nil]
153
+ # @return [DaytonaApiClient::ListSandboxesResponse]
154
+ def fetch_sandbox_page(q, cursor)
155
+ opts = {
156
+ cursor: cursor,
157
+ limit: q.limit,
158
+ id: q.id,
159
+ name: q.name,
160
+ labels: q.labels ? JSON.dump(q.labels) : nil,
161
+ states: q.states,
162
+ snapshots: q.snapshots,
163
+ region_ids: q.targets,
164
+ min_cpu: q.min_cpu,
165
+ max_cpu: q.max_cpu,
166
+ min_memory_gi_b: q.min_memory_gib,
167
+ max_memory_gi_b: q.max_memory_gib,
168
+ min_disk_gi_b: q.min_disk_gib,
169
+ max_disk_gi_b: q.max_disk_gib,
170
+ is_public: q.is_public,
171
+ is_recoverable: q.is_recoverable,
172
+ created_at_after: q.created_at_after,
173
+ created_at_before: q.created_at_before,
174
+ last_event_after: q.last_activity_after,
175
+ last_event_before: q.last_activity_before,
176
+ sort: q.sort,
177
+ order: q.order
178
+ }.compact
179
+
180
+ sandbox_api.list_sandboxes(opts)
181
+ end
182
+
183
+ instrument :fetch_sandbox_page, component: 'Daytona.list'
184
+
143
185
  # Creates a sandbox with the specified parameters
144
186
  #
145
187
  # @param params [Daytona::CreateSandboxFromSnapshotParams, Daytona::CreateSandboxFromImageParams] Sandbox creation parameters
@@ -262,7 +304,7 @@ module Daytona
262
304
  end
263
305
  end
264
306
 
265
- # @param sandbox_dto [DaytonaApiClient::Sandbox]
307
+ # @param sandbox_dto [DaytonaApiClient::Sandbox, DaytonaApiClient::SandboxListItem]
266
308
  # @return [Daytona::Sandbox]
267
309
  def to_sandbox(sandbox_dto:)
268
310
  Sandbox.new(
@@ -23,7 +23,8 @@ module Daytona
23
23
  # @return [String] The user associated with the project
24
24
  attr_reader :user
25
25
 
26
- # @return [Hash<String, String>] Environment variables for the sandbox
26
+ # @return [Hash<String, String>, nil] Environment variables for the sandbox.
27
+ # Not returned by list results; call #refresh on each item to populate.
27
28
  attr_reader :env
28
29
 
29
30
  # @return [Hash<String, String>] Labels for the sandbox
@@ -32,10 +33,12 @@ module Daytona
32
33
  # @return [Boolean] Whether the sandbox http preview is public
33
34
  attr_reader :public
34
35
 
35
- # @return [Boolean] Whether to block all network access for the sandbox
36
+ # @return [Boolean, nil] Whether to block all network access for the sandbox.
37
+ # Not returned by list results; call #refresh on each item to populate.
36
38
  attr_reader :network_block_all
37
39
 
38
- # @return [String] Comma-separated list of allowed CIDR network addresses for the sandbox
40
+ # @return [String, nil] Comma-separated list of allowed CIDR network addresses for the sandbox.
41
+ # Not returned by list results; call #refresh on each item to populate.
39
42
  attr_reader :network_allow_list
40
43
 
41
44
  # @return [String] The target environment for the sandbox
@@ -65,7 +68,8 @@ module Daytona
65
68
  # @return [String] The state of the backup
66
69
  attr_reader :backup_state
67
70
 
68
- # @return [String] The creation timestamp of the last backup
71
+ # @return [String, nil] The creation timestamp of the last backup.
72
+ # Not returned by list results; call #refresh on each item to populate.
69
73
  attr_reader :backup_created_at
70
74
 
71
75
  # @return [Float] Auto-stop interval in minutes (0 means disabled)
@@ -78,10 +82,13 @@ module Daytona
78
82
  # (negative value means disabled, 0 means delete immediately upon stopping)
79
83
  attr_reader :auto_delete_interval
80
84
 
81
- # @return [Array<DaytonaApiClient::SandboxVolume>] Array of volumes attached to the sandbox
85
+ # @return [Array<DaytonaApiClient::SandboxVolume>, nil] Volumes attached to the sandbox.
86
+ # Not returned by list results; call #refresh on each item to populate.
82
87
  attr_reader :volumes
83
88
 
84
- # @return [DaytonaApiClient::BuildInfo] Build information for the sandbox
89
+ # @return [DaytonaApiClient::BuildInfo, nil] Build information for the sandbox if it was
90
+ # created from a dynamic build.
91
+ # Not returned by list results; call #refresh on each item to populate.
85
92
  attr_reader :build_info
86
93
 
87
94
  # @return [String] The creation timestamp of the sandbox
@@ -119,7 +126,7 @@ module Daytona
119
126
 
120
127
  # @params config [Daytona::Config]
121
128
  # @params sandbox_api [DaytonaApiClient::SandboxApi]
122
- # @params sandbox_dto [DaytonaApiClient::Sandbox]
129
+ # @params sandbox_dto [DaytonaApiClient::Sandbox, DaytonaApiClient::SandboxListItem]
123
130
  # @params otel_state [Daytona::OtelState, nil]
124
131
  def initialize(sandbox_dto:, config:, sandbox_api:, otel_state: nil) # rubocop:disable Metrics/MethodLength
125
132
  process_response(sandbox_dto)
@@ -565,14 +572,14 @@ module Daytona
565
572
  end
566
573
  end
567
574
 
568
- # @params sandbox_dto [DaytonaApiClient::Sandbox]
575
+ # @params sandbox_dto [DaytonaApiClient::Sandbox, DaytonaApiClient::SandboxListItem]
569
576
  # @return [void]
570
577
  def process_response(sandbox_dto) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
578
+ # Fields shared by both DaytonaApiClient::Sandbox and DaytonaApiClient::SandboxListItem.
571
579
  @id = sandbox_dto.id
572
580
  @organization_id = sandbox_dto.organization_id
573
581
  @snapshot = sandbox_dto.snapshot
574
582
  @user = sandbox_dto.user
575
- @env = sandbox_dto.env
576
583
  @labels = sandbox_dto.labels
577
584
  @public = sandbox_dto.public
578
585
  @target = sandbox_dto.target
@@ -584,19 +591,25 @@ module Daytona
584
591
  @desired_state = sandbox_dto.desired_state
585
592
  @error_reason = sandbox_dto.error_reason
586
593
  @backup_state = sandbox_dto.backup_state
587
- @backup_created_at = sandbox_dto.backup_created_at
588
594
  @auto_stop_interval = sandbox_dto.auto_stop_interval
589
595
  @auto_archive_interval = sandbox_dto.auto_archive_interval
590
596
  @auto_delete_interval = sandbox_dto.auto_delete_interval
591
- @volumes = sandbox_dto.volumes
592
- @build_info = sandbox_dto.build_info
593
597
  @created_at = sandbox_dto.created_at
594
598
  @updated_at = sandbox_dto.updated_at
595
599
  @last_activity_at = sandbox_dto.last_activity_at
596
600
  @daemon_version = sandbox_dto.daemon_version
601
+ @toolbox_proxy_url = sandbox_dto.toolbox_proxy_url
602
+
603
+ # Fields only present on the full DaytonaApiClient::Sandbox DTO (not returned by list
604
+ # results; call #refresh on each item to populate them).
605
+ return unless sandbox_dto.is_a?(DaytonaApiClient::Sandbox)
606
+
607
+ @env = sandbox_dto.env
597
608
  @network_block_all = sandbox_dto.network_block_all
598
609
  @network_allow_list = sandbox_dto.network_allow_list
599
- @toolbox_proxy_url = sandbox_dto.toolbox_proxy_url
610
+ @volumes = sandbox_dto.volumes
611
+ @build_info = sandbox_dto.build_info
612
+ @backup_created_at = sandbox_dto.backup_created_at
600
613
  end
601
614
 
602
615
  # Monitors block not to exceed max execution time.
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Daytona
7
7
  module Sdk
8
- VERSION = '0.179.0'
8
+ VERSION = '0.180.0.alpha.1'
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daytona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.179.0
4
+ version: 0.180.0.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daytona Platforms Inc.
@@ -85,28 +85,28 @@ dependencies:
85
85
  requirements:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: 0.179.0
88
+ version: 0.180.0.alpha.1
89
89
  type: :runtime
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 0.179.0
95
+ version: 0.180.0.alpha.1
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: daytona_toolbox_api_client
98
98
  requirement: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
- version: 0.179.0
102
+ version: 0.180.0.alpha.1
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: 0.179.0
109
+ version: 0.180.0.alpha.1
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: dotenv
112
112
  requirement: !ruby/object:Gem::Requirement