foobara-typescript-remote-command-generator 1.2.4 → 1.2.6

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: 7d547512385bac27319b644bb141ab01c46a53020b10e8aaf59f97f281733bc4
4
- data.tar.gz: 0b5156e84353c299cd9b9076ad416f420306993181d9984e01b62fbbb2b4dbbe
3
+ metadata.gz: 0e9da9e5402f377488227d8a3d9911e0b5aaecb17c377e7209668993fcac7580
4
+ data.tar.gz: 7910689c819504d3d902ee61b433f1b10765c67b75f24cfad052f55141a89c8f
5
5
  SHA512:
6
- metadata.gz: 076de1fb493fa9ad32f00fce13fef08f92da9dd9864efb17dd9137ea939737ada06485c0de0552d4d6ef59b7e4c5ae5ea541d3bc122bd8a088dbdfcd510efd42
7
- data.tar.gz: 378f783a3dba0e843b5409414f2eb553aab1099555a9443c48d2ccdd3c8d67ef54b8d473c780bc83c44a469250445f9a624546915cde317d5ffc3fd6fc2d2e15
6
+ metadata.gz: fd073a89e550986306bcf2ba57d2cb5c7bf7b13e0d3c244517e09223b9106000c429cec615e4f985359f6548c7aca8b3533e7bf0f4e53dd777228a4bb999367b
7
+ data.tar.gz: 36dd52e22fbaf4c2cc193fa67ac7a7de8126e75b950a4850e9c1d896bf7e814ba4eb8b4b4936879d8cf8d508e5584153ccedad726834e13a76c6a9a6d55f1e44
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.2.6] - 2026-02-16
2
+
3
+ - Make use of guaranteed_to_exist to avoid marking present delegates as optional
4
+ - Make queries automatically run regardless of inputs presence
5
+
6
+ ## [1.2.5] - 2026-01-27
7
+
8
+ - Fix circular dependency that happens if an item from this domain collides
9
+
1
10
  ## [1.2.4] - 2026-01-26
2
11
 
3
12
  - Fix bug where we include models/entities from command inputs
@@ -34,10 +34,6 @@ module Foobara
34
34
  [*super, superclass_generator]
35
35
  end
36
36
 
37
- def collision_winners
38
- superclass_generator
39
- end
40
-
41
37
  def superclass_generator
42
38
  @superclass_generator ||= LoadedEntityGenerator.new(relevant_manifest)
43
39
  end
@@ -145,7 +145,15 @@ module Foobara
145
145
  @dependency_roots = dependency_group.non_colliding_dependency_roots.sort_by(&:scoped_full_name)
146
146
  end
147
147
 
148
- def collision_winners = nil
148
+ def collision_winners
149
+ # TODO: odd that root_manifest exists but isn't decorated. We need a decorated and undecorated method
150
+ root_manifest = Manifest::RootManifest.new(self.root_manifest)
151
+
152
+ [*dependencies].select do |dependency|
153
+ root_manifest.contains?(dependency.domain_reference, :domain) &&
154
+ dependency.domain == domain
155
+ end
156
+ end
149
157
 
150
158
  def ts_instance_path
151
159
  scoped_path
@@ -277,21 +285,26 @@ module Foobara
277
285
  if model_and_entity_free
278
286
  model_type = type_declaration.to_type
279
287
 
280
- translated_type = if type_declaration.detached_entity?
281
- model_type.primary_key_type
282
- else
283
- model_type.attributes_type
284
- end
285
-
286
- foobara_type_to_ts_type(
287
- translated_type,
288
- association_depth:,
289
- dependency_group:,
290
- initial:,
291
- model_and_entity_free:,
292
- is_output:,
293
- parent: model_type
294
- )
288
+ if type_declaration.detached_entity?
289
+ foobara_type_to_ts_type(
290
+ model_type.primary_key_type,
291
+ association_depth:,
292
+ dependency_group:,
293
+ initial:,
294
+ model_and_entity_free:,
295
+ is_output:,
296
+ parent: model_type
297
+ )
298
+ else
299
+ attributes_to_ts_type(
300
+ model_type.attributes_type,
301
+ association_depth:,
302
+ dependency_group:,
303
+ model_and_entity_free:,
304
+ is_output:,
305
+ parent: model_type
306
+ )
307
+ end
295
308
  else
296
309
  model_to_ts_model_name(type_declaration, association_depth:, initial:)
297
310
  end
@@ -334,18 +347,22 @@ module Foobara
334
347
  # or something.
335
348
  if attributes.has_attribute_declarations?
336
349
  guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
337
- is_required = attributes.required?(attribute_name)
350
+ exists = attributes.required?(attribute_name)
351
+
352
+ if !exists && parent&.model?
353
+ exists = parent.guaranteed_to_exist?(attribute_name)
354
+ end
338
355
 
339
- if !is_required && is_output
356
+ if !exists && is_output
340
357
  default = attributes.default_for(attribute_name)
341
358
 
342
359
  if default || default == false ||
343
360
  (parent&.detached_entity? && attribute_name == parent.primary_key_name.to_sym)
344
- is_required = true
361
+ exists = true
345
362
  end
346
363
  end
347
364
 
348
- " #{attribute_name}#{"?" unless is_required}: #{
365
+ " #{attribute_name}#{"?" unless exists}: #{
349
366
  foobara_type_to_ts_type(
350
367
  attribute_declaration,
351
368
  dependency_group:,
@@ -7,7 +7,7 @@ export default class LoginCommand<Inputs, Result, Error extends FoobaraError<any
7
7
  extends RemoteCommand<Inputs, Result, Error> {
8
8
  async _handleResponse (response: Response): Promise<Outcome<Result, Error>> {
9
9
  if (response.ok) {
10
- const accessToken: string | null = response.headers.get('X-Access-Token')
10
+ const accessToken: string | null = response.headers.get('x-access-token')
11
11
 
12
12
  if (accessToken != null) {
13
13
  handleLogin(this.urlBase, accessToken)
@@ -2,6 +2,7 @@ import type Query from '../../../base/Query'
2
2
  import type RemoteCommand from '../../../base/RemoteCommand'
3
3
  import { forEachQuery } from '../../../base/QueryCache'
4
4
 
5
+ // TODO: Why is this in here? It seems general-purpose not auth-specific
5
6
  function dirtyAllQueries () {
6
7
  forEachQuery((query: Query<RemoteCommand<any, any, any>>) => {
7
8
  query.setDirty()
@@ -10,28 +11,49 @@ function dirtyAllQueries () {
10
11
 
11
12
  const accessTokens = new Map<string, string>()
12
13
 
14
+ interface AuthMessage {
15
+ type: 'login' | 'logout'
16
+ baseUrl: string
17
+ }
18
+
19
+ const login = (baseUrl: string, accessToken: string): void => {
20
+ accessTokens.set(baseUrl, accessToken)
21
+ dirtyAllQueries()
22
+ }
23
+
13
24
  const logout = (urlBase: string): void => {
14
25
  accessTokens.delete(urlBase)
15
26
  dirtyAllQueries()
16
27
  }
28
+
29
+ // These functions gets overridden with a form that broadcasts the event if BroadcastChannel is available
30
+ let handleLogin: (baseUrl: string, accessToken: string) => void = login
17
31
  let handleLogout: (baseUrl: string) => void = logout
18
32
 
19
33
  const tokenForUrl = (baseUrl: string): string | undefined => accessTokens.get(baseUrl)
20
- const handleLogin: (baseUrl: string, accessToken: string) => void = (baseUrl, accessToken) => {
21
- accessTokens.set(baseUrl, accessToken)
22
- dirtyAllQueries()
23
- }
24
34
 
25
35
  if (typeof BroadcastChannel !== 'undefined') {
26
36
  const logoutChannel = new BroadcastChannel('foobara-auth-events')
27
37
 
28
- logoutChannel.addEventListener('message', (event: MessageEvent<string>) => {
29
- accessTokens.delete(event.data)
38
+ logoutChannel.addEventListener('message', (event: MessageEvent<AuthMessage>) => {
39
+ const { type, baseUrl } = event.data
40
+
41
+ if (type === 'login') {
42
+ dirtyAllQueries()
43
+ } else if (type === 'logout') {
44
+ logout(baseUrl)
45
+ } else {
46
+ throw new Error(`Unknown auth message type: ${JSON.stringify(type)}`)
47
+ }
30
48
  })
31
49
 
32
50
  handleLogout = (baseUrl: string) => {
33
51
  logout(baseUrl)
34
- logoutChannel.postMessage(baseUrl)
52
+ logoutChannel.postMessage({ baseUrl, type: 'logout' })
53
+ }
54
+ handleLogin = (baseUrl: string, accessToken: string) => {
55
+ login(baseUrl, accessToken)
56
+ logoutChannel.postMessage({ baseUrl, type: 'login' })
35
57
  }
36
58
  }
37
59
 
@@ -16,6 +16,7 @@ export function getQuery<CommandT extends RemoteCommand<any, any, any>> (
16
16
  }
17
17
 
18
18
  let query: Query<CommandT>
19
+
19
20
  if (arguments.length === 2) {
20
21
  query = new Query<CommandT>(CommandClass, inputs)
21
22
  query.run()
@@ -48,12 +48,7 @@ export default function useQuery<CommandT extends RemoteCommand<any, any, any>>
48
48
  let query = queryRef.current
49
49
 
50
50
  if (query == null) {
51
- if (arguments.length === 2) {
52
- query = getQuery(CommandClass, inputs as InputsOf<CommandT>)
53
- } else {
54
- query = getQuery(CommandClass)
55
- }
56
-
51
+ query = getQuery(CommandClass, inputs)
57
52
  queryRef.current = query
58
53
  }
59
54
 
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.2.4
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi