foobara-typescript-remote-command-generator 0.0.10 → 0.0.12

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: 7c5ff8b54e5b247ccdc88cbf0a743192b0e2ac1ff077856eb10744d88843881d
4
- data.tar.gz: 581c8871b10007741cbf13064ff4c544542fefdf797844c159ebef1ae78eaa85
3
+ metadata.gz: 1104e4a22fbc43acc6eb9224e9e4a2e66c50a9de682ec7433869852d16fa5066
4
+ data.tar.gz: a3ac71e2f721f84fc3b939ab1bee3022c2db37aa69c6a315557e75470e5e0bcc
5
5
  SHA512:
6
- metadata.gz: 9a367b46888d713b45e7538f8fcf3a562e5556124d6f31d5115ddf87f152ee1e4ac0621312a477acaad5375032418b6d7835007bd22d2c25c660143acdbc5d77
7
- data.tar.gz: 7e8d6756ae1aeddd49a5daa61e2c4f20974e94fb2f31756b3b81495a40591b5e2d0bc11b94792ce1364beb5e9749110015449c0f80b236786a4ffa052f99ee0c
6
+ metadata.gz: bfc502a91885feb02d56384ee7add5b7740dd22159b33eb2dd844283be6f8e77ed989a494218d72f2ce98d540a335a5fafef126e7770e0b33c9e2eed32a43511
7
+ data.tar.gz: 2f6a3fe9fa23fcd90014030b037f0e0eafb90b1011a795ac9755c0b9cbde88ea7bcfb56500254eb5b087bab1ec074b189887efaa94aaffbf25d17cd5158b24aa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.12] - 2025-03-02
2
+
3
+ - Add ability to ask RemoteCommand for its state and outcome
4
+
5
+ ## [0.0.11] - 2025-02-26
6
+
7
+ - Implement support for command result types that are arrays
8
+
1
9
  ## [0.0.10] - 2025-02-21
2
10
 
3
11
  - Include org/domain prefixes in command URLs
@@ -53,8 +53,10 @@ module Foobara
53
53
  type.attribute_declarations.values.map do |attribute_declaration|
54
54
  model_generators(attribute_declaration, false)
55
55
  end.flatten.uniq
56
+ elsif type.array?
57
+ model_generators(type.element_type, false)
56
58
  else
57
- # TODO: handle tuples, associative arrays, arrays
59
+ # TODO: handle tuples, associative arrays
58
60
  []
59
61
  end
60
62
  end
@@ -1,6 +1,8 @@
1
1
  import { type Outcome, SuccessfulOutcome, ErrorOutcome } from './Outcome'
2
2
  import { type FoobaraError } from './Error'
3
3
 
4
+ export type commandState = 'initialized' | 'executing' | 'succeeded' | 'errored' | 'failed'
5
+
4
6
  export default abstract class RemoteCommand<Inputs, Result, CommandError extends FoobaraError> {
5
7
  static _urlBase: string | undefined
6
8
  static commandName: string
@@ -16,7 +18,7 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
16
18
  }
17
19
 
18
20
  if (base == null) {
19
- throw new Error("urlBase is not set and REACT_APP_FOOBARA_GLOBAL_URL_BASE is undefined")
21
+ throw new Error('urlBase is not set and REACT_APP_FOOBARA_GLOBAL_URL_BASE is undefined')
20
22
  }
21
23
 
22
24
  return base
@@ -35,9 +37,13 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
35
37
  }
36
38
 
37
39
  inputs: Inputs
40
+ outcome: null | Outcome<Result, CommandError>
41
+ commandState: commandState
38
42
 
39
43
  constructor (inputs: Inputs) {
40
44
  this.inputs = inputs
45
+ this.commandState = 'initialized'
46
+ this.outcome = null
41
47
  }
42
48
 
43
49
  get commandName (): string {
@@ -51,10 +57,10 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
51
57
  static get fullCommandName (): string {
52
58
  const path = []
53
59
 
54
- if (this.organizationName != null && this.organizationName !== "GlobalOrganization") {
60
+ if (this.organizationName != null && this.organizationName !== 'GlobalOrganization') {
55
61
  path.push(this.organizationName)
56
62
  }
57
- if (this.domainName != null && this.domainName !== "GlobalDomain") {
63
+ if (this.domainName != null && this.domainName !== 'GlobalDomain') {
58
64
  path.push(this.domainName)
59
65
  }
60
66
  if (this.commandName != null) {
@@ -70,18 +76,26 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
70
76
  async run (): Promise<Outcome<Result, CommandError>> {
71
77
  const url = `${this.urlBase}/run/${this.fullCommandName}`
72
78
 
79
+ this.commandState = 'executing'
73
80
  const response = await fetch(url, {
74
81
  method: 'POST',
75
82
  headers: { 'Content-Type': 'application/json' },
76
83
  body: JSON.stringify(this.inputs)
77
84
  })
78
85
 
86
+ const body = await response.json()
87
+
79
88
  if (response.ok) {
80
- return new SuccessfulOutcome<Result, CommandError>(await response.json())
89
+ this.commandState = 'succeeded'
90
+ this.outcome = new SuccessfulOutcome<Result, CommandError>(body)
81
91
  } else if (response.status === 422) {
82
- return new ErrorOutcome<Result, CommandError>(await response.json())
92
+ this.commandState = 'errored'
93
+ this.outcome = new ErrorOutcome<Result, CommandError>(body)
83
94
  } else {
95
+ this.commandState = 'failed'
84
96
  throw new Error(`not sure how to handle ${await response.text()}`)
85
97
  }
98
+
99
+ return this.outcome
86
100
  }
87
101
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-typescript-remote-command-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-22 00:00:00.000000000 Z
10
+ date: 2025-03-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara