@api-client/core 0.8.9 → 0.8.11

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.
@@ -1,5 +1,7 @@
1
1
  import { SerializablePayload } from './SerializablePayload.js';
2
2
  import { Payload } from '../lib/transformers/PayloadSerializer.js';
3
+ import { IProperty } from './Property.js';
4
+ import { HeadersArray } from './HeadersArray.js';
3
5
 
4
6
  export const Kind = 'Core#HttpRequest';
5
7
 
@@ -28,6 +30,12 @@ export interface IBaseHttpRequest {
28
30
  */
29
31
  export interface IHttpRequest extends IBaseHttpRequest {
30
32
  kind?: string;
33
+
34
+ /**
35
+ * Headers model, if any.
36
+ * When reading headers string, the value of `headers` is preferred over the model.
37
+ */
38
+ headersModel?: Array<IProperty>;
31
39
  }
32
40
 
33
41
  /**
@@ -55,6 +63,12 @@ export class HttpRequest extends SerializablePayload {
55
63
  */
56
64
  headers?: string;
57
65
 
66
+ /**
67
+ * Headers model, if any.
68
+ * When reading headers string, the value of `headers` is preferred over the model.
69
+ */
70
+ headersModel?: HeadersArray;
71
+
58
72
  static fromBaseValues(values: IBaseHttpRequest): HttpRequest {
59
73
  return new HttpRequest({
60
74
  ...values,
@@ -88,12 +102,15 @@ export class HttpRequest extends SerializablePayload {
88
102
  * Note, this throws an error when the object is not a request.
89
103
  */
90
104
  new(init: IHttpRequest): void {
91
- const { url, method='GET', headers, payload, kind = Kind } = init;
105
+ const { url, method='GET', headers, payload, kind = Kind, headersModel } = init;
92
106
  this.kind = kind;
93
107
  this.url = url;
94
108
  this.method = method;
95
109
  this.headers = headers;
96
110
  this.payload = payload;
111
+ if (Array.isArray(headersModel)) {
112
+ this.headersModel = HeadersArray.from(headersModel);
113
+ }
97
114
  }
98
115
 
99
116
  /**
@@ -119,6 +136,9 @@ export class HttpRequest extends SerializablePayload {
119
136
  if (this.payload) {
120
137
  result.payload = this.payload;
121
138
  }
139
+ if (this.headersModel) {
140
+ result.headersModel = this.headersModel.toJSON();
141
+ }
122
142
  return result;
123
143
  }
124
144
  }
@@ -1,4 +1,4 @@
1
- import { IResponseRedirect, ResponseRedirect } from './ResponseRedirect.js';
1
+ import { IResponseRedirect, ResponseRedirect } from './ResponseRedirect.js';
2
2
  import { ISentRequest, SentRequest } from './SentRequest.js';
3
3
  import { IErrorResponse, ErrorResponse } from './ErrorResponse.js';
4
4
  import { IResponse, Response } from './Response.js';
@@ -78,7 +78,7 @@ export class RequestLog {
78
78
  /**
79
79
  * @param input The response definition used to restore the state.
80
80
  */
81
- constructor(input?: string|IRequestLog) {
81
+ constructor(input?: string | IRequestLog) {
82
82
  let init: IRequestLog;
83
83
  if (typeof input === 'string') {
84
84
  init = JSON.parse(input);
@@ -128,6 +128,7 @@ export abstract class HttpEngine extends EventEmitter {
128
128
  * The current sent request
129
129
  */
130
130
  sentRequest: SentRequest;
131
+
131
132
  redirects: ResponseRedirect[] = [];
132
133
  /**
133
134
  * When true the request has been aborted.
@@ -589,7 +590,7 @@ Check your request parameters.`);
589
590
  }
590
591
  message = message || 'Unknown error occurred';
591
592
  const error = new SerializableError(message, opts.code);
592
- const log = RequestLog.fromRequest(this.sentRequest);
593
+ const log = RequestLog.fromRequest(this.sentRequest.toJSON());
593
594
  const response = ErrorResponse.fromError(error);
594
595
  log.response = response;
595
596
  if (currentResponse && currentResponse.status) {
@@ -633,7 +634,7 @@ Check your request parameters.`);
633
634
  if (!response) {
634
635
  return;
635
636
  }
636
- const result = RequestLog.fromRequestResponse(this.sentRequest, response.toJSON());
637
+ const result = RequestLog.fromRequestResponse(this.sentRequest.toJSON(), response.toJSON());
637
638
  if (this.redirects.length) {
638
639
  result.redirects = this.redirects;
639
640
  }