foobara-typescript-remote-command-generator 0.0.11 → 0.0.13

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: 9636a0e5c388533ffbff27af94716f4331f37b8b4e0c2261de0e1d42105e7e83
4
- data.tar.gz: c78a86ed94e77fdd6f15e11784dd2decc99c699a0e69de8b0d694b05bfaa4189
3
+ metadata.gz: 5045b4f54238822deb4764d5ea2f259b482c3350c20e348472b20d30fd1feb83
4
+ data.tar.gz: 24187f3f79dc8fcd275ff4a8b98010dbac41128b4a6dd92faaf073544746eb7c
5
5
  SHA512:
6
- metadata.gz: 63441cad1c78b161556fa5cab4477960e5f35bca1bd0871440b5b8e880b2b9f50ec8d81e9ecc122b8211f583cdae993af70c8c3a63f506ec44b9f9329dd5b2aa
7
- data.tar.gz: 671c9580a817b76939d2acfb0a9ae12c5da0a442c41ff05fb2307e5b7d8c728b2ba06bfcb9412d281690f2fbef5986e92244dcb8eece6947e031dd49a2432c92
6
+ metadata.gz: ae7f0d944f64a64faf54c8cc78f9d0afc53f9c4e857c75efff8993c3132ecefcaa96aec799909444f80dd38b3023db947ab3381a116f298e365b2fb0455432e3
7
+ data.tar.gz: 8b8b124b10f82ce701b48216f338561b7104d44b45f0793148df2d0545d41947cde9d5b12dd2dea4796c9a5c79005d4f9489ebc6f52cbf68d39cf1698b863b26
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.0.13] - 2025-03-17
2
+
3
+ - Fix bug incorrectly generating model typescript for detached entities
4
+ - Fix bug preventing Loaded/Unloaded entity import from being destructured properly
5
+ - Handle errors with prefixes
6
+ - Include custom types and models in error generator dependencies
7
+ - Fix bug preventing allow_nil from having an effect
8
+
9
+ ## [0.0.12] - 2025-03-02
10
+
11
+ - Add ability to ask RemoteCommand for its state and outcome
12
+
1
13
  ## [0.0.11] - 2025-02-26
2
14
 
3
15
  - Implement support for command result types that are arrays
@@ -9,17 +9,17 @@ module Foobara
9
9
  def target_path
10
10
  p = parent
11
11
 
12
- basename = "#{error_name}.ts"
12
+ basename = "#{error_name}.ts".split("::")
13
13
 
14
14
  case parent
15
15
  when OrganizationGenerator, DomainGenerator, CommandGenerator
16
- [*p.target_dir, "errors", basename]
16
+ [*p.target_dir, "errors", *basename]
17
17
  when nil
18
18
  # :nocov:
19
19
  raise "Expected #{error_name} to have a parent but it did not"
20
20
  # :nocov:
21
21
  else
22
- [*p.target_dir, basename]
22
+ [*p.target_dir, *basename]
23
23
  end
24
24
  end
25
25
 
@@ -50,8 +50,7 @@ module Foobara
50
50
  end
51
51
 
52
52
  def dependencies
53
- # Why don't we need models and custom types?
54
- types_depended_on.select(&:detached_entity?)
53
+ types_depended_on.select { |type| type.detached_entity? || type.custom? || type.model? }
55
54
  end
56
55
 
57
56
  def ts_type_full_path
@@ -21,6 +21,10 @@ module Foobara
21
21
  *prefix, name = super
22
22
  [*prefix, "Loaded#{name}"]
23
23
  end
24
+
25
+ def import_destructure
26
+ "{ Loaded#{scoped_short_name} }"
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -76,7 +76,7 @@ module Foobara
76
76
  # :nocov:
77
77
  end
78
78
 
79
- if declaration_data["allows_nil"]
79
+ if declaration_data["allow_nil"]
80
80
  # TODO: add a custom type to the fixture manifest that includes allows_nil
81
81
  # :nocov:
82
82
  guts += " | undefined"
@@ -48,7 +48,7 @@ module Foobara
48
48
  Services::OrganizationConfigGenerator,
49
49
  Services::OrganizationManifestGenerator
50
50
  ]
51
- when Manifest::Entity
51
+ when Manifest::Entity, Manifest::DetachedEntity
52
52
  [
53
53
  Services::EntityGenerator,
54
54
  Services::EntityVariantsGenerator,
@@ -14,6 +14,10 @@ module Foobara
14
14
  *prefix, name = super
15
15
  [*prefix, "Unloaded#{name}"]
16
16
  end
17
+
18
+ def import_destructure
19
+ "{ Unloaded#{scoped_short_name} }"
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -4,5 +4,5 @@ import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= de
4
4
 
5
5
  import { <%= error_base_class %> } from "<%= path_to_root %>base/Error"
6
6
 
7
- export class <%= error_name %> extends <%= error_base_class %><<%= context_ts_type %>> {
7
+ export class <%= short_error_name %> extends <%= error_base_class %><<%= context_ts_type %>> {
8
8
  }
@@ -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.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-26 00:00:00.000000000 Z
10
+ date: 2025-03-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubygems_version: 3.6.3
137
+ rubygems_version: 3.6.5
138
138
  specification_version: 4
139
139
  summary: Generates remote commands for Typescript from a foobara manifest
140
140
  test_files: []