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 +4 -4
- data/CHANGELOG.md +9 -0
- data/src/remote_generator/services/aggregate_entity_generator.rb +0 -4
- data/src/remote_generator/services/typescript_from_manifest_base_generator.rb +37 -20
- data/templates/Foobara/Auth/LoginCommand.ts.erb +1 -1
- data/templates/Foobara/Auth/utils/accessTokens.ts.erb +29 -7
- data/templates/base/QueryCache.ts +1 -0
- data/templates/hooks/useQuery.ts +1 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e9da9e5402f377488227d8a3d9911e0b5aaecb17c377e7209668993fcac7580
|
|
4
|
+
data.tar.gz: 7910689c819504d3d902ee61b433f1b10765c67b75f24cfad052f55141a89c8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
@@ -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
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
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 !
|
|
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
|
-
|
|
361
|
+
exists = true
|
|
345
362
|
end
|
|
346
363
|
end
|
|
347
364
|
|
|
348
|
-
" #{attribute_name}#{"?" unless
|
|
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('
|
|
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<
|
|
29
|
-
|
|
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
|
|
data/templates/hooks/useQuery.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|