foobara-typescript-remote-command-generator 1.1.5 → 1.1.7

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: e8215d8808315c6f8fd3d1e630ce0e580a6a577c5b1c70a417347ee2dc334998
4
- data.tar.gz: 9cda7eed3bea9cd2dadb446857d1fb4c133e0b35cbad491c7c1527d49d682d1a
3
+ metadata.gz: 7f320bbabd5ddca46562061c2824136049cdb2527db04dcc12a158faacf976ee
4
+ data.tar.gz: 0dd1e7ede3eb687061654c2a69be0e666558aaac109ad6965cb1d48b23f6e996
5
5
  SHA512:
6
- metadata.gz: 83ce0b3291adbc9bff8e6328f7f7c2a7bd386fb46aae876282ed4f7ee88bb401148cd99720f38fdbbf31d5bf73df3e5a9167a0830a120409a38cd4a5f8e90f8d
7
- data.tar.gz: 829447664b106704867d6c4345d677a6f252b2ffe730a4f54719ffa37b7998a6ec8385f7a22abf3ac57e2a5f8b2e0841b14fdc6ade33415adf80cb8fe76048b7
6
+ metadata.gz: dfe94127bf3d4b42b0846282b3a036a6c7eee1769bd3c06c4b522984ac8ee4556b220471e3da023340d9b60821624f839e629d7609d37d4d51c83b0076a90d46
7
+ data.tar.gz: 41e09f9b71898e73eeb2e8afc94f49aa909e37d8defc7f44454669471c9b925b130f3790e41338d1c23cfd5c2a71582a9e9a0ece77f1f0ba9250def19297950f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.1.7] - 2025-11-02
2
+
3
+ - Make CommandCastResultGenerator's interpretation of atom? match other generators
4
+
5
+ ## [1.1.6] - 2025-10-17
6
+
7
+ - Dirty all queries on login/logout, not just GetCurrentUser
8
+ - Remove no-longer needed /setup.ts file generation
9
+
1
10
  ## [1.1.5] - 2025-10-15
2
11
 
3
12
  - Implement castJsonResult
@@ -5,12 +5,12 @@ module Foobara
5
5
  class Services
6
6
  class CommandCastResultGenerator < CommandResultGenerator
7
7
  class CastTree
8
- attr_accessor :children, :declaration_to_cast, :past_first_model
8
+ attr_accessor :children, :declaration_to_cast, :initial
9
9
 
10
- def initialize(children: nil, declaration_to_cast: nil, past_first_model: false)
10
+ def initialize(children: nil, declaration_to_cast: nil, initial: false)
11
11
  self.children = children
12
12
  self.declaration_to_cast = declaration_to_cast
13
- self.past_first_model = past_first_model
13
+ self.initial = initial
14
14
  end
15
15
 
16
16
  def empty?
@@ -41,31 +41,30 @@ module Foobara
41
41
 
42
42
  nested_model_generators = []
43
43
 
44
- generators = model_generators
45
-
46
- generators.each do |generator|
47
- _models_reachable_from_declaration(
48
- generator.relevant_manifest
49
- )&.each do |(model, past_first)|
50
- generator_class = if atom?
51
- if model.detached_entity? && past_first
52
- Services::UnloadedEntityGenerator
53
- else
54
- Services::AtomModelGenerator
55
- end
56
- elsif aggregate?
57
- Services::AggregateModelGenerator
44
+ if result_type.detached_entity? && atom?
45
+ declaration = result_type.is_a?(Manifest::TypeDeclaration) ? result_type.to_type : result_type
46
+ return @nested_model_generators = Set[Services::AtomEntityGenerator.new(declaration)]
47
+ end
48
+
49
+ _models_reachable_from_declaration(result_type, initial: true)&.each do |model|
50
+ generator_class = if atom?
51
+ if model.detached_entity?
52
+ Services::UnloadedEntityGenerator
58
53
  else
59
- Services::ModelGenerator
54
+ Services::AtomModelGenerator
60
55
  end
56
+ elsif aggregate?
57
+ Services::AggregateModelGenerator
58
+ else
59
+ Services::ModelGenerator
60
+ end
61
61
 
62
- new_generator = generator_class.new(model)
62
+ new_generator = generator_class.new(model)
63
63
 
64
- unless generators.any? do |g|
65
- g.relevant_manifest == model && g.class == new_generator.class
66
- end
67
- nested_model_generators << new_generator
68
- end
64
+ unless nested_model_generators.any? do |g|
65
+ g.relevant_manifest == model && g.class == new_generator.class
66
+ end
67
+ nested_model_generators << new_generator
69
68
  end
70
69
  end
71
70
 
@@ -81,7 +80,7 @@ module Foobara
81
80
  end
82
81
 
83
82
  def dependencies
84
- @dependencies ||= model_generators + nested_model_generators
83
+ nested_model_generators
85
84
  end
86
85
 
87
86
  def cast_json_result_function
@@ -92,7 +91,7 @@ module Foobara
92
91
 
93
92
  # TODO: need to make use of initial?
94
93
  def cast_json_result_function_body(
95
- cast_tree = _construct_cast_tree(result_type),
94
+ cast_tree = _construct_cast_tree(result_type, initial: true),
96
95
  parent: "json",
97
96
  property: nil,
98
97
  value: parent
@@ -189,8 +188,9 @@ module Foobara
189
188
  if type_symbol == :date || type_symbol == :datetime
190
189
  "#{lvalue} = new Date(#{value})"
191
190
  elsif type.model?
192
- ts_model_name = model_to_ts_model_name(type, association_depth:,
193
- initial: !cast_tree.past_first_model)
191
+ ts_model_name = model_to_ts_model_name(type,
192
+ association_depth:,
193
+ initial: cast_tree.initial)
194
194
 
195
195
  "#{lvalue} = new #{ts_model_name}(#{value})"
196
196
  else
@@ -200,7 +200,7 @@ module Foobara
200
200
  end
201
201
  end
202
202
 
203
- def _construct_cast_tree(type_declaration, past_first_model: false)
203
+ def _construct_cast_tree(type_declaration, initial: false)
204
204
  if type_declaration.is_a?(Manifest::Attributes)
205
205
  return unless type_declaration.has_attribute_declarations?
206
206
  return if type_declaration.attribute_declarations.empty?
@@ -209,39 +209,39 @@ module Foobara
209
209
 
210
210
  type_declaration.attribute_declarations.each_pair do |attribute_name, attribute_declaration|
211
211
  if type_requires_cast?(attribute_declaration)
212
- path_tree[attribute_name] = _construct_cast_tree(attribute_declaration, past_first_model:)
212
+ path_tree[attribute_name] = _construct_cast_tree(attribute_declaration)
213
213
  end
214
214
  end
215
215
 
216
216
  unless path_tree.empty?
217
- CastTree.new(children: path_tree, past_first_model:)
217
+ CastTree.new(children: path_tree, initial:)
218
218
  end
219
219
  elsif type_declaration.is_a?(Manifest::Array)
220
220
  element_type = type_declaration.element_type
221
221
 
222
222
  if element_type && type_requires_cast?(element_type)
223
- CastTree.new(children: { "#": _construct_cast_tree(element_type, past_first_model:) })
223
+ CastTree.new(initial:, children: { "#": _construct_cast_tree(element_type) })
224
224
  end
225
225
  elsif type_declaration.type.to_sym == :date || type_declaration.type.to_sym == :datetime
226
- CastTree.new(declaration_to_cast: type_declaration, past_first_model:)
226
+ CastTree.new(declaration_to_cast: type_declaration, initial:)
227
227
  elsif type_declaration.model?
228
228
  type_declaration = type_declaration.to_type
229
229
 
230
230
  children = if type_declaration.detached_entity? && atom?
231
231
  nil
232
232
  else
233
- _construct_cast_tree(type_declaration.attributes_type, past_first_model: true)
233
+ _construct_cast_tree(type_declaration.attributes_type)
234
234
  end
235
235
 
236
- CastTree.new(children:, declaration_to_cast: type_declaration, past_first_model:)
236
+ CastTree.new(children:, declaration_to_cast: type_declaration, initial:)
237
237
  # TODO: either test this code path or raise or delete it
238
238
  # :nocov:
239
239
  elsif type_declaration.custom?
240
240
  if type_requires_cast?(type_declaration.base_type.to_type_declaration)
241
- tree = _construct_cast_tree(type_declaration.base_type.to_type_declaration, past_first_model:)
241
+ tree = _construct_cast_tree(type_declaration.base_type.to_type_declaration)
242
242
 
243
243
  if tree && !tree.empty?
244
- CastTree.new(children: tree, past_first_model:)
244
+ CastTree.new(children: tree, initial:)
245
245
  end
246
246
  end
247
247
  end
@@ -249,7 +249,7 @@ module Foobara
249
249
  end
250
250
 
251
251
  # TODO: Feels like similar complicated logic is popping up in many places? How to find/converge such logic
252
- def _models_reachable_from_declaration(type_declaration, past_first_model: false)
252
+ def _models_reachable_from_declaration(type_declaration, initial: false)
253
253
  if type_declaration.is_a?(Manifest::Attributes)
254
254
  return unless type_declaration.has_attribute_declarations?
255
255
  return if type_declaration.attribute_declarations.empty?
@@ -258,13 +258,14 @@ module Foobara
258
258
 
259
259
  type_declaration.attribute_declarations.each_value do |attribute_declaration|
260
260
  if type_requires_cast?(attribute_declaration)
261
- models ||= Set.new
262
-
263
- _models_reachable_from_declaration(
264
- attribute_declaration,
265
- past_first_model:
266
- )&.each do |pair|
267
- models << pair
261
+ additional = _models_reachable_from_declaration(attribute_declaration)
262
+
263
+ if additional
264
+ if models
265
+ models |= additional
266
+ else
267
+ models = additional
268
+ end
268
269
  end
269
270
  end
270
271
  end
@@ -274,24 +275,23 @@ module Foobara
274
275
  element_type = type_declaration.element_type
275
276
 
276
277
  if element_type && type_requires_cast?(element_type)
277
- _models_reachable_from_declaration(element_type, past_first_model:)
278
+ _models_reachable_from_declaration(element_type)
278
279
  end
279
280
  elsif type_declaration.model?
280
281
  if type_declaration.is_a?(Manifest::TypeDeclaration)
281
282
  type_declaration = type_declaration.to_type
282
283
  end
283
284
 
284
- models = Set[[type_declaration, past_first_model]]
285
+ models = Set[type_declaration]
285
286
 
286
287
  if atom? && type_declaration.detached_entity?
287
288
  return models
288
289
  end
289
290
 
290
- _models_reachable_from_declaration(
291
- type_declaration.attributes_type,
292
- past_first_model: true
293
- )&.each do |pair|
294
- models << pair
291
+ additional = _models_reachable_from_declaration(type_declaration.attributes_type)
292
+
293
+ if additional
294
+ models |= additional
295
295
  end
296
296
 
297
297
  models
@@ -299,10 +299,7 @@ module Foobara
299
299
  # TODO: either test this code path or raise or delete it
300
300
  # :nocov:
301
301
  if type_requires_cast?(type_declaration.base_type.to_type_declaration)
302
- _models_reachable_from_declaration(
303
- type_declaration.base_type.to_type_declaration,
304
- past_first_model:
305
- )
302
+ _models_reachable_from_declaration(type_declaration.base_type.to_type_declaration)
306
303
  end
307
304
  # :nocov:
308
305
  end
@@ -36,10 +36,7 @@ module Foobara
36
36
  when "Foobara::Auth::Logout"
37
37
  Services::Auth::LogoutGenerator
38
38
  when /\bGetCurrentUser$/
39
- [
40
- Services::Auth::RequiresAuthGenerator,
41
- Services::Auth::SetupGenerator
42
- ]
39
+ Services::Auth::RequiresAuthGenerator
43
40
  else
44
41
  if manifest.requires_authentication?
45
42
  Services::Auth::RequiresAuthGenerator
@@ -383,12 +380,7 @@ module Foobara
383
380
 
384
381
  def path_to_root
385
382
  path = super
386
-
387
- if path.empty?
388
- "./"
389
- else
390
- path
391
- end
383
+ path.empty? ? "./" : path
392
384
  end
393
385
  end
394
386
  end
@@ -59,7 +59,6 @@ module Foobara
59
59
 
60
60
  def run_post_generation_tasks
61
61
  eslint_fix
62
- warn_about_adding_setup_to_index
63
62
  end
64
63
 
65
64
  def eslint_fix
@@ -74,24 +73,6 @@ module Foobara
74
73
  end
75
74
  end
76
75
  end
77
-
78
- def warn_about_adding_setup_to_index
79
- if paths_to_source_code.key?("setup.ts")
80
- index_tsx_path = "#{output_directory}/../index.tsx"
81
-
82
- if File.exist?(index_tsx_path)
83
- unless File.read(index_tsx_path) =~ /import.*domains\/setup/
84
- warn "WARNING: you should add the following to src/index.tsx:\n\n" \
85
- "import './domains/setup'"
86
- end
87
- else
88
- # :nocov:
89
- warn "WARNING: Make sure you add the following somewhere:\n\n" \
90
- "import './domains/setup'"
91
- # :nocov:
92
- end
93
- end
94
- end
95
76
  end
96
77
  end
97
78
  end
@@ -1,31 +1,25 @@
1
1
  import type Query from '../../../base/Query'
2
2
  import type RemoteCommand from '../../../base/RemoteCommand'
3
+ import { forEachQuery } from '../../../base/QueryCache'
3
4
 
4
- let getCurrentUserQuery: Query<RemoteCommand<any, any, any>> | undefined
5
-
6
- export function setGetCurrentUserQuery (query: Query<RemoteCommand<any, any, any>>): void {
7
- getCurrentUserQuery = query
8
- }
9
-
10
- function setCurrentUserDirty () {
11
- console.log('setCurrentUserDirty')
12
- if (getCurrentUserQuery != null) {
13
- getCurrentUserQuery.setDirty()
14
- }
5
+ function dirtyAllQueries () {
6
+ forEachQuery((query: Query<RemoteCommand<any, any, any>>) => {
7
+ query.setDirty()
8
+ })
15
9
  }
16
10
 
17
11
  const accessTokens = new Map<string, string>()
18
12
 
19
13
  const logout = (urlBase: string): void => {
20
14
  accessTokens.delete(urlBase)
21
- setCurrentUserDirty()
15
+ dirtyAllQueries()
22
16
  }
23
17
  let handleLogout: (baseUrl: string) => void = logout
24
18
 
25
19
  const tokenForUrl = (baseUrl: string): string | undefined => accessTokens.get(baseUrl)
26
20
  const handleLogin: (baseUrl: string, accessToken: string) => void = (baseUrl, accessToken) => {
27
21
  accessTokens.set(baseUrl, accessToken)
28
- setCurrentUserDirty()
22
+ dirtyAllQueries()
29
23
  }
30
24
 
31
25
  if (typeof BroadcastChannel !== 'undefined') {
@@ -33,6 +33,10 @@ export function getQuery<CommandT extends RemoteCommand<any, any, any>> (
33
33
  return query
34
34
  }
35
35
 
36
+ export function forEachQuery (callback: (query: Query<RemoteCommand<any, any, any>>) => void): void {
37
+ queryCache.forEach(callback)
38
+ }
39
+
36
40
  function toKey<CommandT extends RemoteCommand<any, any, any>> (
37
41
  CommandClass: RemoteCommandConstructor<CommandT>,
38
42
  inputs: InputsOf<CommandT> | undefined
@@ -57,19 +57,23 @@ export default function useQuery<CommandT extends RemoteCommand<any, any, any>>
57
57
  queryRef.current = query
58
58
  }
59
59
 
60
+ const [queryState, setQueryState] = useState<QueryState<CommandT>>(
61
+ queryToQueryState<CommandT>(query)
62
+ )
63
+
60
64
  useEffect(() => {
61
- const unsubscribe = query?.onChange(() => {
62
- if (query != null) { // just here to satisfy type checker
65
+ if (query == null) {
66
+ return undefined
67
+ }
68
+
69
+ const removeListener = query.onChange(() => {
70
+ if (query != null) { // Just here to satisfy type check
63
71
  setQueryState(queryToQueryState<CommandT>(query))
64
72
  }
65
73
  })
66
74
 
67
- return unsubscribe
75
+ return removeListener
68
76
  }, [query])
69
77
 
70
- const [queryState, setQueryState] = useState<QueryState<CommandT>>(
71
- queryToQueryState<CommandT>(query)
72
- )
73
-
74
78
  return queryState
75
79
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-typescript-remote-command-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -70,7 +70,6 @@ files:
70
70
  - src/remote_generator/services/auth/refresh_login_generator.rb
71
71
  - src/remote_generator/services/auth/requires_auth_command_generator.rb
72
72
  - src/remote_generator/services/auth/requires_auth_generator.rb
73
- - src/remote_generator/services/auth/setup_generator.rb
74
73
  - src/remote_generator/services/command_cast_result_generator.rb
75
74
  - src/remote_generator/services/command_errors_generator.rb
76
75
  - src/remote_generator/services/command_errors_index_generator.rb
@@ -136,7 +135,6 @@ files:
136
135
  - templates/base/RemoteCommand.ts
137
136
  - templates/base/RemoteCommandTypes.ts
138
137
  - templates/hooks/useQuery.ts
139
- - templates/setup.ts.erb
140
138
  homepage: https://github.com/foobara/typescript-remote-command-generator
141
139
  licenses:
142
140
  - Apache-2.0
@@ -1,25 +0,0 @@
1
- module Foobara
2
- module RemoteGenerator
3
- class Services
4
- module Auth
5
- class SetupGenerator < CommandGenerator
6
- def template_path
7
- "setup.ts.erb"
8
- end
9
-
10
- def target_path
11
- ["setup.ts"]
12
- end
13
-
14
- def command_generator
15
- generator_for(command_manifest)
16
- end
17
-
18
- def dependencies
19
- [command_generator]
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,6 +0,0 @@
1
- import { getQuery } from './base/QueryCache'
2
- import { setGetCurrentUserQuery } from './Foobara/Auth/utils/accessTokens'
3
-
4
- import <%= command_generator.import_destructure %> from "<%= path_to_root %><%= command_generator.import_path %>"
5
-
6
- setGetCurrentUserQuery(getQuery(<%= dependency_group.non_colliding_type(command_generator) %>, undefined))