@oino-ts/common 0.17.4 → 0.17.5
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.
- package/dist/cjs/OINOResult.js +9 -1
- package/dist/esm/OINOResult.js +9 -1
- package/dist/types/OINOResult.d.ts +3 -2
- package/package.json +2 -2
- package/src/OINOResult.ts +10 -3
package/dist/cjs/OINOResult.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.OINOHttpResult = exports.OINOResult = void 0;
|
|
9
9
|
const node_crypto_1 = require("node:crypto");
|
|
10
|
+
const node_buffer_1 = require("node:buffer");
|
|
10
11
|
const _1 = require(".");
|
|
11
12
|
/**
|
|
12
13
|
* OINO API request result object with returned data and/or http status code/message and
|
|
@@ -209,7 +210,14 @@ class OINOHttpResult extends OINOResult {
|
|
|
209
210
|
if (headers) {
|
|
210
211
|
merged_headers.setHeaders(headers);
|
|
211
212
|
}
|
|
212
|
-
|
|
213
|
+
let body;
|
|
214
|
+
if (this.body instanceof node_buffer_1.Buffer) {
|
|
215
|
+
body = new Uint8Array(this.body);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
body = this.body;
|
|
219
|
+
}
|
|
220
|
+
const result = new Response(body, { status: this.status, statusText: this.statusText, headers: merged_headers });
|
|
213
221
|
result.headers.set('Content-Length', this.body.length.toString());
|
|
214
222
|
if (merged_headers['Last-Modified'] === undefined && this.lastModified > 0) {
|
|
215
223
|
result.headers.set('Last-Modified', new Date(this.lastModified).toUTCString());
|
package/dist/esm/OINOResult.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
|
+
import { Buffer } from "node:buffer";
|
|
7
8
|
import { OINO_DEBUG_PREFIX, OINO_ERROR_PREFIX, OINO_INFO_PREFIX, OINO_WARNING_PREFIX, OINOHeaders } from ".";
|
|
8
9
|
/**
|
|
9
10
|
* OINO API request result object with returned data and/or http status code/message and
|
|
@@ -205,7 +206,14 @@ export class OINOHttpResult extends OINOResult {
|
|
|
205
206
|
if (headers) {
|
|
206
207
|
merged_headers.setHeaders(headers);
|
|
207
208
|
}
|
|
208
|
-
|
|
209
|
+
let body;
|
|
210
|
+
if (this.body instanceof Buffer) {
|
|
211
|
+
body = new Uint8Array(this.body);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
body = this.body;
|
|
215
|
+
}
|
|
216
|
+
const result = new Response(body, { status: this.status, statusText: this.statusText, headers: merged_headers });
|
|
209
217
|
result.headers.set('Content-Length', this.body.length.toString());
|
|
210
218
|
if (merged_headers['Last-Modified'] === undefined && this.lastModified > 0) {
|
|
211
219
|
result.headers.set('Last-Modified', new Date(this.lastModified).toUTCString());
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
1
2
|
import { OINOHeaders, OINOHeadersInit } from ".";
|
|
2
3
|
export interface OINOResultInit {
|
|
3
4
|
success?: boolean;
|
|
@@ -88,7 +89,7 @@ export declare class OINOResult {
|
|
|
88
89
|
printLog(): string;
|
|
89
90
|
}
|
|
90
91
|
export interface OINOHttpResultInit extends OINOResultInit {
|
|
91
|
-
body?: string;
|
|
92
|
+
body?: string | Buffer;
|
|
92
93
|
headers?: OINOHeadersInit;
|
|
93
94
|
expires?: number;
|
|
94
95
|
lastModified?: number;
|
|
@@ -99,7 +100,7 @@ export interface OINOHttpResultInit extends OINOResultInit {
|
|
|
99
100
|
export declare class OINOHttpResult extends OINOResult {
|
|
100
101
|
private _etag;
|
|
101
102
|
/** HTTP body data */
|
|
102
|
-
readonly body: string;
|
|
103
|
+
readonly body: string | Buffer;
|
|
103
104
|
/** HTTP headers */
|
|
104
105
|
readonly headers: OINOHeaders;
|
|
105
106
|
/** HTTP cache expiration value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/common",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.5",
|
|
4
4
|
"description": "OINO TS package for common classes.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@oino-ts/types": "0.17.
|
|
22
|
+
"@oino-ts/types": "0.17.5",
|
|
23
23
|
"@types/node": "^22.0.0",
|
|
24
24
|
"typescript": "~5.9.0"
|
|
25
25
|
},
|
package/src/OINOResult.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { createHash, Hash } from "node:crypto";
|
|
8
|
+
import { Buffer } from "node:buffer";
|
|
8
9
|
import { OINO_DEBUG_PREFIX, OINO_ERROR_PREFIX, OINO_INFO_PREFIX, OINO_WARNING_PREFIX, OINOHeaders, OINOHeadersInit } from ".";
|
|
9
10
|
|
|
10
11
|
export interface OINOResultInit {
|
|
@@ -177,7 +178,7 @@ export class OINOResult {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
export interface OINOHttpResultInit extends OINOResultInit {
|
|
180
|
-
body?: string
|
|
181
|
+
body?: string|Buffer
|
|
181
182
|
headers?: OINOHeadersInit
|
|
182
183
|
expires?: number
|
|
183
184
|
lastModified?: number
|
|
@@ -190,7 +191,7 @@ export class OINOHttpResult extends OINOResult {
|
|
|
190
191
|
private _etag:string
|
|
191
192
|
|
|
192
193
|
/** HTTP body data */
|
|
193
|
-
readonly body: string
|
|
194
|
+
readonly body: string|Buffer
|
|
194
195
|
|
|
195
196
|
/** HTTP headers */
|
|
196
197
|
readonly headers: OINOHeaders
|
|
@@ -240,7 +241,13 @@ export class OINOHttpResult extends OINOResult {
|
|
|
240
241
|
if (headers) {
|
|
241
242
|
merged_headers.setHeaders(headers)
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
+
let body: string|BufferSource
|
|
245
|
+
if (this.body instanceof Buffer) {
|
|
246
|
+
body = new Uint8Array(this.body)
|
|
247
|
+
} else {
|
|
248
|
+
body = this.body as string
|
|
249
|
+
}
|
|
250
|
+
const result: Response = new Response(body, { status: this.status, statusText: this.statusText, headers: merged_headers })
|
|
244
251
|
result.headers.set('Content-Length', this.body.length.toString())
|
|
245
252
|
if (merged_headers['Last-Modified'] === undefined && this.lastModified > 0) {
|
|
246
253
|
result.headers.set('Last-Modified', new Date(this.lastModified).toUTCString())
|