@conduit-client/generator-ts 3.19.1 → 3.19.2

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.
@@ -11,6 +11,7 @@ import { HttpCommandGenerator } from './http-command-generator';
11
11
  */
12
12
  export declare class AuraCommandGenerator extends HttpCommandGenerator {
13
13
  commandBaseClass: ImportableTypeReference;
14
+ protected get hasSemanticNullResponses(): boolean;
14
15
  get commandGeneratedClass(): ImportableTypeReference;
15
16
  /**
16
17
  * Constructs and returns an array of code blocks that form the body of the Aura-specific command class.
@@ -13,12 +13,15 @@ export declare const MEDIATYPE_APP_JSON = "application/json";
13
13
  export declare class HttpCommandGenerator extends CommandGenerator {
14
14
  commandBaseClass: ImportableTypeReference;
15
15
  get commandGeneratedClass(): ImportableTypeReference;
16
+ protected get hasSemanticNullResponses(): boolean;
17
+ protected buildCommandTypeGenerics(): Code;
16
18
  /**
17
19
  * Constructs and returns an array of code blocks that form the body of the HTTP command class.
18
20
  * Includes methods for generating fetch parameters and error coercion logic.
19
21
  * @returns {Code[]} An array of code snippets that define the command class body for HTTP operations.
20
22
  */
21
23
  get classBody(): Code[];
24
+ protected generateAdditionalNullResponses(): Code[];
22
25
  /**
23
26
  * Generates a code block for fetch parameters based on the command model's configuration.
24
27
  * Constructs a detailed setup for fetch operations including method, headers, body, and cache settings.
@@ -108,6 +108,7 @@ export type ICommandModel = {
108
108
  serverUrlPath: string;
109
109
  endpointUrlPath: string;
110
110
  invalidationConfigs: InvalidationConfig[];
111
+ semanticNullStatusCodes: readonly number[];
111
112
  };
112
113
  /**
113
114
  * Base abstract class for command models that encapsulates the common functionality required by all command models.
@@ -173,6 +174,7 @@ export declare abstract class BaseCommandModel implements ICommandModel {
173
174
  get serverUrlPath(): string;
174
175
  get endpointUrlPath(): string;
175
176
  get request(): import("@conduit-client/model/v1").Request<Type>;
177
+ get semanticNullStatusCodes(): readonly number[];
176
178
  get invalidationConfigs(): InvalidationConfig[];
177
179
  protected buildBody(): {
178
180
  content: ContentModel;
package/dist/v1/index.js CHANGED
@@ -2579,13 +2579,39 @@ class HttpCommandGenerator extends CommandGenerator {
2579
2579
  get commandGeneratedClass() {
2580
2580
  return GENERATED_FETCH_NETWORK_COMMAND;
2581
2581
  }
2582
+ get hasSemanticNullResponses() {
2583
+ var _a;
2584
+ return (((_a = this.commandModel.semanticNullStatusCodes) == null ? void 0 : _a.length) ?? 0) > 0;
2585
+ }
2586
+ buildCommandTypeGenerics() {
2587
+ var _a;
2588
+ const extraServicesCode = this.buildExtraServices();
2589
+ const responseType = this.services.typeDefinition.build(
2590
+ (_a = this.commandModel.responseType) == null ? void 0 : _a.default[MEDIATYPE_APP_JSON]
2591
+ );
2592
+ const dataType = this.hasSemanticNullResponses ? code`${responseType} | null` : responseType;
2593
+ return code`${dataType}${extraServicesCode ? code`, ${extraServicesCode}` : ""}`;
2594
+ }
2582
2595
  /**
2583
2596
  * Constructs and returns an array of code blocks that form the body of the HTTP command class.
2584
2597
  * Includes methods for generating fetch parameters and error coercion logic.
2585
2598
  * @returns {Code[]} An array of code snippets that define the command class body for HTTP operations.
2586
2599
  */
2587
2600
  get classBody() {
2588
- return [code`${this.generateFetchParams()}`, this.generateCoerceError()];
2601
+ return [
2602
+ code`${this.generateFetchParams()}`,
2603
+ this.generateCoerceError(),
2604
+ ...this.generateAdditionalNullResponses()
2605
+ ];
2606
+ }
2607
+ generateAdditionalNullResponses() {
2608
+ const codes = this.commandModel.semanticNullStatusCodes ?? [];
2609
+ if (codes.length === 0) {
2610
+ return [];
2611
+ }
2612
+ return [
2613
+ code`protected readonly additionalNullResponses:ReadonlyArray<number>=[${codes.join(",")}];`
2614
+ ];
2589
2615
  }
2590
2616
  /**
2591
2617
  * Generates a code block for fetch parameters based on the command model's configuration.
@@ -2755,6 +2781,9 @@ class AuraCommandGenerator extends HttpCommandGenerator {
2755
2781
  super(...arguments);
2756
2782
  this.commandBaseClass = AURA_COMMAND_BASE_CLASS;
2757
2783
  }
2784
+ get hasSemanticNullResponses() {
2785
+ return false;
2786
+ }
2758
2787
  get commandGeneratedClass() {
2759
2788
  return GENERATED_AURA_NETWORK_COMMAND;
2760
2789
  }
@@ -2999,10 +3028,11 @@ class ImperativeAdapterBindingGenerator {
2999
3028
  return code`${DEFAULT_IMPERATIVE_RETURN_SHAPE}`;
3000
3029
  }
3001
3030
  get responseTypeCode() {
3002
- var _a;
3003
- return this.services.typeDefinition.build(
3031
+ var _a, _b;
3032
+ const baseType = this.services.typeDefinition.build(
3004
3033
  (_a = this.commandModel.responseType) == null ? void 0 : _a.default["application/json"]
3005
3034
  );
3035
+ return this.commandModel.transportType === "http" && (((_b = this.commandModel.semanticNullStatusCodes) == null ? void 0 : _b.length) ?? 0) > 0 ? code`${baseType} | null` : baseType;
3006
3036
  }
3007
3037
  get invoker() {
3008
3038
  if (this.isSubscribable()) {
@@ -3071,10 +3101,11 @@ class ImperativeAdapterLegacyBindingGenerator {
3071
3101
  };
3072
3102
  }
3073
3103
  get responseTypeCode() {
3074
- var _a;
3075
- return this.services.typeDefinition.build(
3104
+ var _a, _b;
3105
+ const baseType = this.services.typeDefinition.build(
3076
3106
  (_a = this.commandModel.responseType) == null ? void 0 : _a.default["application/json"]
3077
3107
  );
3108
+ return this.commandModel.transportType === "http" && (((_b = this.commandModel.semanticNullStatusCodes) == null ? void 0 : _b.length) ?? 0) > 0 ? code`${baseType} | null` : baseType;
3078
3109
  }
3079
3110
  buildDeclaration() {
3080
3111
  return code`let ${this.binding.identifier}:${LEGACY_IMPERATIVE_RETURN_SHAPE}<${this.commandConfigTypeImport},${this.responseTypeCode}>;`;
@@ -3188,10 +3219,11 @@ class WireAdapterBindingGenerator {
3188
3219
  };
3189
3220
  }
3190
3221
  get responseTypeCode() {
3191
- var _a;
3192
- return this.services.typeDefinition.build(
3222
+ var _a, _b;
3223
+ const baseType = this.services.typeDefinition.build(
3193
3224
  (_a = this.commandModel.responseType) == null ? void 0 : _a.default["application/json"]
3194
3225
  );
3226
+ return this.commandModel.transportType === "http" && (((_b = this.commandModel.semanticNullStatusCodes) == null ? void 0 : _b.length) ?? 0) > 0 ? code`${baseType} | null` : baseType;
3195
3227
  }
3196
3228
  buildDeclaration() {
3197
3229
  return code`let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR$1}<${this.commandConfigTypeImport}, ${WIRE_ADAPTER_RESULT$1}<${this.responseTypeCode}>, {}>;`;
@@ -4738,6 +4770,12 @@ class BaseCommandModel {
4738
4770
  get request() {
4739
4771
  return this.operation.requests[0];
4740
4772
  }
4773
+ get semanticNullStatusCodes() {
4774
+ return this.operation.responses.filter((res) => {
4775
+ const code2 = parseInt(res.statusCode, 10);
4776
+ return code2 >= 200 && code2 < 300 && res.payloads.length === 0;
4777
+ }).map((res) => parseInt(res.statusCode, 10));
4778
+ }
4741
4779
  get invalidationConfigs() {
4742
4780
  return this.operation.responses.filter((res) => {
4743
4781
  return res.invalidation !== void 0;