foobara-typescript-remote-command-generator 1.3.0 → 1.4.0
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 +8 -0
- data/src/generators/type_generator.rb +4 -0
- data/templates/Command/Inputs.ts.erb +1 -1
- data/templates/Command/Result.ts.erb +1 -1
- data/templates/Command/castJsonResult.ts.erb +1 -1
- data/templates/Command.ts.erb +3 -3
- data/templates/Domain/config.ts.erb +1 -1
- data/templates/Entity/Aggregate.ts.erb +1 -1
- data/templates/Entity/Atom.ts.erb +1 -1
- data/templates/Entity/Loaded.ts.erb +1 -1
- data/templates/Entity/Unloaded.ts.erb +3 -3
- data/templates/EntityVariants.ts.erb +5 -5
- data/templates/Foobara/Auth/RequiresAuthCommand.ts.erb +1 -1
- data/templates/Model/Aggregate.ts.erb +1 -1
- data/templates/Model/Atom.ts.erb +1 -1
- data/templates/ModelVariants.ts.erb +3 -3
- data/templates/Organization/config.ts.erb +1 -1
- data/templates/base/QueryCache.ts +48 -0
- data/templates/base/RemoteCommand.ts.erb +9 -15
- data/templates/hooks/useQuery.ts +2 -9
- 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: 16a68cb56fbf77e520f577b5ef5d0b6c677d6461fb69ce242906d608b6412e3f
|
|
4
|
+
data.tar.gz: 35dcccf09cff04cad00c02423b77ebecdebc3643080cc9e534bae8e957dd273c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 952c659c1ace30fbbd24f980c8382db56f95757ac5a802b25ed19e5c6faf276dd1647f6fe999cb3afc49c3bb35b90003e95765ad2363f1ce160846cd9d3100d3
|
|
7
|
+
data.tar.gz: 78c60b378c18f6786c9d6cd29db44d7c693c45c433977deedeaec79694ccb4f640f092159349758be3d1094d04c83f379e6caaea4c3e3bd4c9d5e820e4929fcc
|
data/CHANGELOG.md
CHANGED
data/templates/Command.ts.erb
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
|
|
3
3
|
<% end %>
|
|
4
4
|
|
|
5
|
-
import Inputs from "./Inputs"
|
|
6
|
-
import Result from "./Result"
|
|
7
|
-
import { Error } from "./Errors"
|
|
5
|
+
import type Inputs from "./Inputs"
|
|
6
|
+
import type Result from "./Result"
|
|
7
|
+
import { type Error } from "./Errors"
|
|
8
8
|
<% if result_json_requires_cast? %>
|
|
9
9
|
import castJsonResult from "./castJsonResult"
|
|
10
10
|
<% end %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
<%= entity_short_name %>,
|
|
3
|
-
<%= entity_short_name %>AttributesType
|
|
3
|
+
type <%= entity_short_name %>AttributesType
|
|
4
4
|
} from "./Ambiguous"
|
|
5
5
|
|
|
6
6
|
export class Loaded<%= entity_short_name %><T extends <%= entity_short_name %>AttributesType = <%= entity_short_name %>AttributesType> extends <%= entity_short_name %><T> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Never } from "<%= path_to_root %>base/Entity"
|
|
1
|
+
import { type Never } from "<%= path_to_root %>base/Entity"
|
|
2
2
|
import {
|
|
3
3
|
<%= entity_short_name %>,
|
|
4
|
-
<%= entity_short_name %>PrimaryKeyType,
|
|
5
|
-
<%= entity_short_name %>AttributesType
|
|
4
|
+
type <%= entity_short_name %>PrimaryKeyType,
|
|
5
|
+
type <%= entity_short_name %>AttributesType
|
|
6
6
|
} from "./Ambiguous"
|
|
7
7
|
|
|
8
8
|
export type Unloaded<%= entity_short_name %>AttributesType = Never<<%= entity_short_name %>AttributesType>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
<%= entity_short_name %>,
|
|
3
|
-
<%= entity_short_name %>PrimaryKeyType,
|
|
3
|
+
type <%= entity_short_name %>PrimaryKeyType,
|
|
4
4
|
<%= entity_name_downcase %>PrimaryKeyAttributeName,
|
|
5
|
-
<%= entity_short_name %>AttributesType
|
|
5
|
+
type <%= entity_short_name %>AttributesType
|
|
6
6
|
} from "./<%= entity_short_name %>/Ambiguous"
|
|
7
7
|
import {
|
|
8
8
|
Unloaded<%= entity_short_name %>,
|
|
9
|
-
Unloaded<%= entity_short_name %>AttributesType
|
|
9
|
+
type Unloaded<%= entity_short_name %>AttributesType
|
|
10
10
|
} from "./<%= entity_short_name %>/Unloaded"
|
|
11
11
|
import {
|
|
12
12
|
Loaded<%= entity_short_name %>
|
|
@@ -15,11 +15,11 @@ import {
|
|
|
15
15
|
<% if has_associations? %>
|
|
16
16
|
import {
|
|
17
17
|
<%= entity_short_name %>Atom,
|
|
18
|
-
<%= entity_short_name %>AtomAttributesType
|
|
18
|
+
type <%= entity_short_name %>AtomAttributesType
|
|
19
19
|
} from "./<%= entity_short_name %>/Atom"
|
|
20
20
|
import {
|
|
21
21
|
<%= entity_short_name %>Aggregate,
|
|
22
|
-
<%= entity_short_name %>AggregateAttributesType
|
|
22
|
+
type <%= entity_short_name %>AggregateAttributesType
|
|
23
23
|
} from "./<%= entity_short_name %>/Aggregate"
|
|
24
24
|
<% end %>
|
|
25
25
|
|
|
@@ -2,6 +2,7 @@ import RemoteCommand from '../../base/RemoteCommand'
|
|
|
2
2
|
import { type Outcome } from '../../base/Outcome'
|
|
3
3
|
import { type FoobaraError } from '../../base/Error'
|
|
4
4
|
import { tokenForUrl } from './utils/accessTokens'
|
|
5
|
+
import { RefreshLogin } from './RefreshLogin'
|
|
5
6
|
|
|
6
7
|
export default class RequiresAuthCommand<Inputs, Result, Error extends FoobaraError<any>>
|
|
7
8
|
extends RemoteCommand<Inputs, Result, Error> {
|
|
@@ -27,7 +28,6 @@ export default class RequiresAuthCommand<Inputs, Result, Error extends FoobaraEr
|
|
|
27
28
|
if (response.status === 401) {
|
|
28
29
|
this.commandState = 'refreshing_authentication'
|
|
29
30
|
|
|
30
|
-
const { RefreshLogin } = await import('./RefreshLogin')
|
|
31
31
|
// See if we can authenticate using the refresh token
|
|
32
32
|
const refreshCommand = new RefreshLogin()
|
|
33
33
|
const outcome = await refreshCommand.run()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
<%= model_short_name %>,
|
|
3
|
-
<%= model_short_name %>AttributesType
|
|
3
|
+
type <%= model_short_name %>AttributesType
|
|
4
4
|
} from "./<%= model_short_name %>"
|
|
5
5
|
<% dependency_roots.each do |dependency_root| %>
|
|
6
6
|
import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
|
data/templates/Model/Atom.ts.erb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
<%= model_short_name %>,
|
|
3
|
-
<%= model_short_name %>AttributesType
|
|
3
|
+
type <%= model_short_name %>AttributesType
|
|
4
4
|
} from "./<%= model_short_name %>"
|
|
5
5
|
<% dependency_roots.each do |dependency_root| %>
|
|
6
6
|
import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
<%= model_short_name %>,
|
|
3
|
-
<%= model_short_name %>AttributesType
|
|
3
|
+
type <%= model_short_name %>AttributesType
|
|
4
4
|
} from "./<%= model_short_name %>/<%= model_short_name %>"
|
|
5
5
|
|
|
6
6
|
<% if has_associations? %>
|
|
7
7
|
import {
|
|
8
8
|
<%= model_short_name %>Atom,
|
|
9
|
-
<%= model_short_name %>AtomAttributesType
|
|
9
|
+
type <%= model_short_name %>AtomAttributesType
|
|
10
10
|
} from "./<%= model_short_name %>/Atom"
|
|
11
11
|
import {
|
|
12
12
|
<%= model_short_name %>Aggregate,
|
|
13
|
-
<%= model_short_name %>AggregateAttributesType
|
|
13
|
+
type <%= model_short_name %>AggregateAttributesType
|
|
14
14
|
} from "./<%= model_short_name %>/Aggregate"
|
|
15
15
|
<% end %>
|
|
16
16
|
|
|
@@ -38,6 +38,54 @@ export function forEachQuery (callback: (query: Query<RemoteCommand<any, any, an
|
|
|
38
38
|
queryCache.forEach(callback)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
interface DirtyQueryEvent {
|
|
42
|
+
commandName: string
|
|
43
|
+
propertyName: string | undefined
|
|
44
|
+
value: string | number | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let dirtyQueryChannel: BroadcastChannel | null = null
|
|
48
|
+
|
|
49
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
50
|
+
dirtyQueryChannel = new BroadcastChannel('dirty-query')
|
|
51
|
+
|
|
52
|
+
dirtyQueryChannel.addEventListener('message', (event: MessageEvent<DirtyQueryEvent>) => {
|
|
53
|
+
const { commandName, propertyName, value } = event.data
|
|
54
|
+
|
|
55
|
+
dirtyQuery(commandName, propertyName, value, { skipBroadcast: true })
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function dirtyQuery<CommandT extends RemoteCommand<any, any, any>> (
|
|
60
|
+
commandClass: RemoteCommandConstructor<CommandT> | string,
|
|
61
|
+
propertyName: string | undefined = undefined,
|
|
62
|
+
propertyValue: string | number | undefined = undefined,
|
|
63
|
+
options: { skipBroadcast: boolean } = { skipBroadcast: false }) {
|
|
64
|
+
if (typeof commandClass !== 'string') {
|
|
65
|
+
commandClass = commandClass.fullCommandName
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
forEachQuery((query) => {
|
|
69
|
+
if (query.CommandClass.fullCommandName === commandClass) {
|
|
70
|
+
if (query.inputs == null || Object.keys(query.inputs).length === 0) {
|
|
71
|
+
query.setDirty()
|
|
72
|
+
} else {
|
|
73
|
+
if (propertyName != null) {
|
|
74
|
+
if (query.inputs[propertyName] !== propertyValue) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
query.setDirty()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (dirtyQueryChannel != null && !options.skipBroadcast) {
|
|
85
|
+
dirtyQueryChannel.postMessage({ commandName: commandClass, propertyName, value: propertyValue })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
41
89
|
function toKey<CommandT extends RemoteCommand<any, any, any>> (
|
|
42
90
|
CommandClass: RemoteCommandConstructor<CommandT>,
|
|
43
91
|
inputs: InputsOf<CommandT> | undefined
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Outcome, SuccessfulOutcome, ErrorOutcome } from './Outcome'
|
|
2
2
|
import { type FoobaraError } from './Error'
|
|
3
3
|
<% if auto_dirty_queries? %>
|
|
4
|
-
import
|
|
4
|
+
import { dirtyQuery } from './QueryCache'
|
|
5
5
|
<% end %>
|
|
6
6
|
|
|
7
7
|
export default abstract class RemoteCommand<Inputs, Result, CommandError extends FoobaraError> {
|
|
@@ -10,12 +10,12 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
|
|
|
10
10
|
static organizationName: string
|
|
11
11
|
static domainName: string
|
|
12
12
|
|
|
13
|
-
// TODO: make use of domain's config instead of
|
|
13
|
+
// TODO: make use of domain's config instead of import.meta.env directly.
|
|
14
14
|
static get urlBase (): string {
|
|
15
15
|
let base = this._urlBase
|
|
16
16
|
|
|
17
17
|
if (base == null) {
|
|
18
|
-
base =
|
|
18
|
+
base = import.meta.env.REACT_APP_FOOBARA_GLOBAL_URL_BASE
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
if (base == null) {
|
|
@@ -136,19 +136,13 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
|
|
|
136
136
|
<% if auto_dirty_queries? %>
|
|
137
137
|
dirtyQueries () {
|
|
138
138
|
for (const [commandClass, inputs] of this.dirties()) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (inputs == null || Object.keys(inputs).length === 0) {
|
|
143
|
-
query.setDirty()
|
|
144
|
-
} else {
|
|
145
|
-
for (const [property, value] of Object.entries(inputs)) {
|
|
146
|
-
if (query.inputs[property] !== value) { return }
|
|
147
|
-
}
|
|
148
|
-
query.setDirty()
|
|
149
|
-
}
|
|
139
|
+
if (inputs != null) {
|
|
140
|
+
for (const [propertyName, value] of Object.entries(inputs)) {
|
|
141
|
+
dirtyQuery(commandClass, propertyName, value)
|
|
150
142
|
}
|
|
151
|
-
}
|
|
143
|
+
} else {
|
|
144
|
+
dirtyQuery(commandClass)
|
|
145
|
+
}
|
|
152
146
|
}
|
|
153
147
|
}
|
|
154
148
|
<% end %>
|
data/templates/hooks/useQuery.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type InputsOf, type ResultOf, type ErrorOf, type RemoteCommandConstructor
|
|
5
5
|
} from '../base/RemoteCommandTypes'
|
|
6
6
|
import type Query from '../base/Query'
|
|
7
|
-
import { useState,
|
|
7
|
+
import { useState, useEffect } from 'react'
|
|
8
8
|
import { getQuery } from '../base/QueryCache'
|
|
9
9
|
|
|
10
10
|
interface QueryState<CommandT extends RemoteCommand<any, any, any>> {
|
|
@@ -43,14 +43,7 @@ export default function useQuery<CommandT extends RemoteCommand<any, any, any>>
|
|
|
43
43
|
CommandClass: RemoteCommandConstructor<CommandT>,
|
|
44
44
|
inputs: InputsOf<CommandT> | undefined = undefined
|
|
45
45
|
): QueryState<CommandT> {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
let query = queryRef.current
|
|
49
|
-
|
|
50
|
-
if (query == null) {
|
|
51
|
-
query = getQuery(CommandClass, inputs)
|
|
52
|
-
queryRef.current = query
|
|
53
|
-
}
|
|
46
|
+
const [query] = useState<Query<CommandT>>(() => getQuery(CommandClass, inputs))
|
|
54
47
|
|
|
55
48
|
const [queryState, setQueryState] = useState<QueryState<CommandT>>(
|
|
56
49
|
queryToQueryState<CommandT>(query)
|