@oino-ts/types 0.16.2 → 0.17.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.
@@ -0,0 +1,58 @@
1
+ import { OINOContentType } from ".";
2
+ export interface OINORequestInit {
3
+ params?: Record<string, string>;
4
+ }
5
+ /**
6
+ * OINO API request result object with returned data and/or http status code/message and
7
+ * error / warning messages.
8
+ *
9
+ */
10
+ export declare class OINORequest {
11
+ /** Key-value parameters */
12
+ params?: Record<string, string>;
13
+ /**
14
+ * Constructor of OINORequest.
15
+ *
16
+ * @param init initialization values
17
+ *
18
+ */
19
+ constructor(init?: OINORequestInit);
20
+ /**
21
+ * Copy values from different result.
22
+ *
23
+ * @param request source value
24
+ */
25
+ copy(request: OINORequest): void;
26
+ }
27
+ export interface OINOHttpRequestInit extends OINORequestInit {
28
+ url?: URL;
29
+ method?: string;
30
+ headers?: Record<string, string>;
31
+ data?: string | Buffer | Uint8Array | object | null;
32
+ requestType?: OINOContentType;
33
+ responseType?: OINOContentType;
34
+ multipartBoundary?: string;
35
+ lastModified?: number;
36
+ }
37
+ /**
38
+ * Specialized result for HTTP responses.
39
+ */
40
+ export declare class OINOHttpRequest extends OINORequest {
41
+ readonly url?: URL;
42
+ readonly method: string;
43
+ readonly headers: Record<string, string>;
44
+ readonly data: string | Buffer | Uint8Array | object | null;
45
+ readonly requestType: OINOContentType;
46
+ readonly responseType: OINOContentType;
47
+ readonly multipartBoundary?: string;
48
+ readonly lastModified?: number;
49
+ readonly etags?: string[];
50
+ /**
51
+ * Constructor for a `OINOHttpRequest`
52
+ *
53
+ * @param init initialization values
54
+ *
55
+ */
56
+ constructor(init: OINOHttpRequestInit);
57
+ static fromRequest(request: Request): Promise<OINOHttpRequest>;
58
+ }
@@ -1,3 +1,9 @@
1
+ export interface OINOResultInit {
2
+ success?: boolean;
3
+ status?: number;
4
+ statusText?: string;
5
+ messages?: string[];
6
+ }
1
7
  /**
2
8
  * OINO API request result object with returned data and/or http status code/message and
3
9
  * error / warning messages.
@@ -7,16 +13,18 @@ export declare class OINOResult {
7
13
  /** Wheter request was successfully executed */
8
14
  success: boolean;
9
15
  /** HTTP status code */
10
- statusCode: number;
16
+ status: number;
11
17
  /** HTTP status message */
12
- statusMessage: string;
18
+ statusText: string;
13
19
  /** Error / warning messages */
14
20
  messages: string[];
15
21
  /**
16
22
  * Constructor of OINOResult.
17
23
  *
24
+ * @param init initialization values
25
+ *
18
26
  */
19
- constructor();
27
+ constructor(init?: OINOResultInit);
20
28
  /**
21
29
  * Copy values from different result.
22
30
  *
@@ -31,12 +39,12 @@ export declare class OINOResult {
31
39
  /**
32
40
  * Set HTTP error status using given code and message. Returns self reference for chaining.
33
41
  *
34
- * @param statusCode HTTP status code
35
- * @param statusMessage HTTP status message
42
+ * @param status HTTP status code
43
+ * @param statusText HTTP status message
36
44
  * @param operation operation where error occured
37
45
  *
38
46
  */
39
- setError(statusCode: number, statusMessage: string, operation: string): OINOResult;
47
+ setError(status: number, statusText: string, operation: string): OINOResult;
40
48
  /**
41
49
  * Add warning message. Returns self reference for chaining.
42
50
  *
@@ -77,12 +85,11 @@ export declare class OINOResult {
77
85
  *
78
86
  */
79
87
  printLog(): string;
80
- /**
81
- * Get a Response object from the result values.
82
- *
83
- * @param headers HTTP headers (overrides existing values)
84
- */
85
- getStatusResponse(headers?: Record<string, string>): Response;
88
+ }
89
+ export interface OINOHttpResultInit extends OINOResultInit {
90
+ body?: string;
91
+ expires?: number;
92
+ lastModified?: number;
86
93
  }
87
94
  /**
88
95
  * Specialized result for HTTP responses.
@@ -91,17 +98,19 @@ export declare class OINOHttpResult extends OINOResult {
91
98
  private _etag;
92
99
  /** HTTP body data */
93
100
  readonly body: string;
94
- /** HTTP cache expiration value */
101
+ /** HTTP cache expiration value
102
+ * Note: default 0 means no expiration and 'Pragma: no-cache' is set.
103
+ */
95
104
  expires: number;
96
105
  /** HTTP cache last-modified value */
97
106
  lastModified: number;
98
107
  /**
99
108
  * Constructor for a `OINOHttpResult`
100
109
  *
101
- * @param body HTTP body
110
+ * @param init initialization values
102
111
  *
103
112
  */
104
- constructor(body: string);
113
+ constructor(init?: OINOHttpResultInit);
105
114
  /**
106
115
  * Get the ETag value for the body opportunistically, i.e. don't calculate until requested and reuse value.
107
116
  *
@@ -1,6 +1,7 @@
1
1
  export { OINOBenchmark, OINOMemoryBenchmark } from "./OINOBenchmark.js";
2
2
  export { OINOLog, OINOLogLevel, OINOConsoleLog } from "./OINOLog.js";
3
- export { OINOResult, OINOHttpResult } from "./OINOResult.js";
3
+ export { OINOResult, OINOHttpResult, type OINOResultInit, type OINOHttpResultInit } from "./OINOResult.js";
4
+ export { OINORequest, OINOHttpRequest, type OINORequestInit, type OINOHttpRequestInit } from "./OINORequest.js";
4
5
  export { OINOStr } from "./OINOStr.js";
5
6
  export { OINOHtmlTemplate } from "./OINOHtmlTemplate.js";
6
7
  export { OINOFormatter, OINO_EMPTY_FORMATTER } from "./OINOFormatter.js";
@@ -12,6 +13,10 @@ export declare const OINO_WARNING_PREFIX = "OINO WARNING";
12
13
  export declare const OINO_INFO_PREFIX = "OINO INFO";
13
14
  /** OINO debug message prefix */
14
15
  export declare const OINO_DEBUG_PREFIX = "OINO DEBUG";
16
+ /** Name of the OINOContentType-parameter request */
17
+ export declare const OINO_REQUEST_TYPE_PARAM = "oinorequesttype";
18
+ /** Name of the OINOContentType-parameter request */
19
+ export declare const OINO_RESPONSE_TYPE_PARAM = "oinoresponsetype";
15
20
  /**
16
21
  * Supported content format mime-types
17
22
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/types",
3
- "version": "0.16.2",
3
+ "version": "0.17.2",
4
4
  "description": "OINO TS package for types.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",