@trayio/commons 0.0.1-beta
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/LICENSE.txt +22 -0
- package/dist/base64/Base64.d.ts +18 -0
- package/dist/base64/Base64.d.ts.map +1 -0
- package/dist/base64/Base64.js +52 -0
- package/dist/base64/Base64.unit.test.d.ts +2 -0
- package/dist/base64/Base64.unit.test.d.ts.map +1 -0
- package/dist/base64/Base64.unit.test.js +50 -0
- package/dist/buffer/BufferExtensions.d.ts +9 -0
- package/dist/buffer/BufferExtensions.d.ts.map +1 -0
- package/dist/buffer/BufferExtensions.js +68 -0
- package/dist/buffer/BufferExtensions.unit.test.d.ts +2 -0
- package/dist/buffer/BufferExtensions.unit.test.d.ts.map +1 -0
- package/dist/buffer/BufferExtensions.unit.test.js +47 -0
- package/dist/callsite/CallSite.d.ts +9 -0
- package/dist/callsite/CallSite.d.ts.map +1 -0
- package/dist/callsite/CallSite.js +50 -0
- package/dist/cli/CliLogging.d.ts +11 -0
- package/dist/cli/CliLogging.d.ts.map +1 -0
- package/dist/cli/CliLogging.js +9 -0
- package/dist/codec/Codec.abstract.test.d.ts +8 -0
- package/dist/codec/Codec.abstract.test.d.ts.map +1 -0
- package/dist/codec/Codec.abstract.test.js +42 -0
- package/dist/codec/Codec.d.ts +6 -0
- package/dist/codec/Codec.d.ts.map +1 -0
- package/dist/codec/Codec.js +2 -0
- package/dist/codec/CompositeCodec.d.ts +11 -0
- package/dist/codec/CompositeCodec.d.ts.map +1 -0
- package/dist/codec/CompositeCodec.js +44 -0
- package/dist/codec/RemoveNullValuesCodec.d.ts +12 -0
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -0
- package/dist/codec/RemoveNullValuesCodec.js +76 -0
- package/dist/codec/TypeCodec.d.ts +16 -0
- package/dist/codec/TypeCodec.d.ts.map +1 -0
- package/dist/codec/TypeCodec.js +58 -0
- package/dist/codec/TypeCodec.unit.test.d.ts +2 -0
- package/dist/codec/TypeCodec.unit.test.d.ts.map +1 -0
- package/dist/codec/TypeCodec.unit.test.js +97 -0
- package/dist/dynamictype/DynamicType.d.ts +20 -0
- package/dist/dynamictype/DynamicType.d.ts.map +1 -0
- package/dist/dynamictype/DynamicType.js +49 -0
- package/dist/error/Error.d.ts +2 -0
- package/dist/error/Error.d.ts.map +1 -0
- package/dist/error/Error.js +13 -0
- package/dist/file/FakeFileStorage.d.ts +12 -0
- package/dist/file/FakeFileStorage.d.ts.map +1 -0
- package/dist/file/FakeFileStorage.integration.test.d.ts +2 -0
- package/dist/file/FakeFileStorage.integration.test.d.ts.map +1 -0
- package/dist/file/FakeFileStorage.integration.test.js +7 -0
- package/dist/file/FakeFileStorage.js +60 -0
- package/dist/file/File.d.ts +29 -0
- package/dist/file/File.d.ts.map +1 -0
- package/dist/file/File.js +36 -0
- package/dist/file/FileStorage.abstract.test.d.ts +3 -0
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -0
- package/dist/file/FileStorage.abstract.test.js +109 -0
- package/dist/file/NodeFsFileStorage.d.ts +12 -0
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -0
- package/dist/file/NodeFsFileStorage.integration.test.d.ts +2 -0
- package/dist/file/NodeFsFileStorage.integration.test.d.ts.map +1 -0
- package/dist/file/NodeFsFileStorage.integration.test.js +7 -0
- package/dist/file/NodeFsFileStorage.js +82 -0
- package/dist/http/Http.d.ts +55 -0
- package/dist/http/Http.d.ts.map +1 -0
- package/dist/http/Http.js +64 -0
- package/dist/http/HttpClient.abstract.test.d.ts +3 -0
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -0
- package/dist/http/HttpClient.abstract.test.js +354 -0
- package/dist/http/HttpClient.d.ts +6 -0
- package/dist/http/HttpClient.d.ts.map +1 -0
- package/dist/http/HttpClient.js +2 -0
- package/dist/http/HttpController.d.ts +11 -0
- package/dist/http/HttpController.d.ts.map +1 -0
- package/dist/http/HttpController.js +2 -0
- package/dist/logging/Logging.d.ts +10 -0
- package/dist/logging/Logging.d.ts.map +1 -0
- package/dist/logging/Logging.js +2 -0
- package/dist/record/Record.d.ts +4 -0
- package/dist/record/Record.d.ts.map +1 -0
- package/dist/record/Record.js +35 -0
- package/dist/result/Result.d.ts +31 -0
- package/dist/result/Result.d.ts.map +1 -0
- package/dist/result/Result.js +68 -0
- package/dist/serialization/JsonSerialization.d.ts +10 -0
- package/dist/serialization/JsonSerialization.d.ts.map +1 -0
- package/dist/serialization/JsonSerialization.js +49 -0
- package/dist/serialization/JsonSerialization.unit.test.d.ts +2 -0
- package/dist/serialization/JsonSerialization.unit.test.d.ts.map +1 -0
- package/dist/serialization/JsonSerialization.unit.test.js +5 -0
- package/dist/serialization/Serialization.abstract.test.d.ts +3 -0
- package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -0
- package/dist/serialization/Serialization.abstract.test.js +54 -0
- package/dist/serialization/Serialization.d.ts +10 -0
- package/dist/serialization/Serialization.d.ts.map +1 -0
- package/dist/serialization/Serialization.js +7 -0
- package/dist/string/StringConversions.d.ts +6 -0
- package/dist/string/StringConversions.d.ts.map +1 -0
- package/dist/string/StringConversions.js +16 -0
- package/dist/string/StringConversions.unit.test.d.ts +2 -0
- package/dist/string/StringConversions.unit.test.d.ts.map +1 -0
- package/dist/string/StringConversions.unit.test.js +36 -0
- package/dist/string/StringExtensions.d.ts +6 -0
- package/dist/string/StringExtensions.d.ts.map +1 -0
- package/dist/string/StringExtensions.js +8 -0
- package/dist/string/StringExtensions.unit.test.d.ts +2 -0
- package/dist/string/StringExtensions.unit.test.d.ts.map +1 -0
- package/dist/string/StringExtensions.unit.test.js +39 -0
- package/dist/task/Task.d.ts +7 -0
- package/dist/task/Task.d.ts.map +1 -0
- package/dist/task/Task.js +14 -0
- package/dist/try/Try.d.ts +3 -0
- package/dist/try/Try.d.ts.map +1 -0
- package/dist/try/Try.js +37 -0
- package/package.json +41 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.NodeFsFileStorage = void 0;
|
|
36
|
+
const fs = __importStar(require("fs/promises"));
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const TE = __importStar(require("fp-ts/lib/TaskEither"));
|
|
39
|
+
const function_1 = require("fp-ts/lib/function");
|
|
40
|
+
const Task_1 = require("../task/Task");
|
|
41
|
+
class NodeFsFileStorage {
|
|
42
|
+
constructor(basePath = '/tmp') {
|
|
43
|
+
this.basePath = basePath;
|
|
44
|
+
}
|
|
45
|
+
write(file) {
|
|
46
|
+
const filePath = `${this.basePath}/${file.key}`;
|
|
47
|
+
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.writeFile(filePath, file.content));
|
|
48
|
+
return (0, function_1.pipe)(result, TE.map(() => file));
|
|
49
|
+
}
|
|
50
|
+
read(key, name = key) {
|
|
51
|
+
const filePath = `${this.basePath}/${key}`;
|
|
52
|
+
return TE.tryCatch(() => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const fileHandle = yield fs.open(filePath, 'r');
|
|
54
|
+
const stat = yield fs.stat(filePath);
|
|
55
|
+
const stream = fileHandle.createReadStream();
|
|
56
|
+
const metadata = {
|
|
57
|
+
name,
|
|
58
|
+
size: stat.size,
|
|
59
|
+
};
|
|
60
|
+
return { metadata, key: filePath, content: stream };
|
|
61
|
+
}), (reason) => new Error(String(reason)));
|
|
62
|
+
}
|
|
63
|
+
getSharedUrl(key) {
|
|
64
|
+
const filePath = `${this.basePath}/${key}`;
|
|
65
|
+
return TE.tryCatch(() => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return ({
|
|
67
|
+
url: path.resolve(filePath),
|
|
68
|
+
});
|
|
69
|
+
}), (reason) => new Error(String(reason)));
|
|
70
|
+
}
|
|
71
|
+
delete(key) {
|
|
72
|
+
const filePath = `${this.basePath}/${key}`;
|
|
73
|
+
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.unlink(filePath));
|
|
74
|
+
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
75
|
+
}
|
|
76
|
+
createDirectory(key) {
|
|
77
|
+
const filePath = `${this.basePath}/${key}`;
|
|
78
|
+
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.mkdir(filePath, { recursive: true }));
|
|
79
|
+
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.NodeFsFileStorage = NodeFsFileStorage;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as O from 'fp-ts/lib/Option';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { File } from '../file/File';
|
|
5
|
+
import { SerializationFormat } from '../serialization/Serialization';
|
|
6
|
+
export type HttpHeaderValue = string | string[];
|
|
7
|
+
export type HttpHeaders = Record<string, HttpHeaderValue | HttpContentType>;
|
|
8
|
+
export type HttpQueryStringSingleValue = number | string | boolean;
|
|
9
|
+
export type HttpQueryStringValue = HttpQueryStringSingleValue | HttpQueryStringSingleValue[];
|
|
10
|
+
export type HttpQueryString = Record<string, HttpQueryStringValue>;
|
|
11
|
+
export type RegularHttpRequestBody = Readable;
|
|
12
|
+
export type MultipartHttpRequestBody = {
|
|
13
|
+
fields: Record<string, string>;
|
|
14
|
+
files: Record<string, File>;
|
|
15
|
+
};
|
|
16
|
+
export type HttpRequestBody = RegularHttpRequestBody | MultipartHttpRequestBody;
|
|
17
|
+
export type HttpRequest = {
|
|
18
|
+
headers: HttpHeaders;
|
|
19
|
+
pathParams: Record<string, string>;
|
|
20
|
+
queryString: HttpQueryString;
|
|
21
|
+
body: HttpRequestBody;
|
|
22
|
+
};
|
|
23
|
+
export type HttpResponse = {
|
|
24
|
+
statusCode: number;
|
|
25
|
+
headers: HttpHeaders;
|
|
26
|
+
body: Readable;
|
|
27
|
+
};
|
|
28
|
+
export declare enum HttpMethod {
|
|
29
|
+
Get = "GET",
|
|
30
|
+
Put = "PUT",
|
|
31
|
+
Post = "POST",
|
|
32
|
+
Patch = "PATCH",
|
|
33
|
+
Delete = "DELETE"
|
|
34
|
+
}
|
|
35
|
+
export declare enum HttpContentType {
|
|
36
|
+
Json = "application/json",
|
|
37
|
+
OctetStream = "application/octet-stream",
|
|
38
|
+
MultipartRequestBody = "multipart/form-data",
|
|
39
|
+
Text = "text/plain"
|
|
40
|
+
}
|
|
41
|
+
export declare enum HttpHeader {
|
|
42
|
+
Authorization = "Authorization",
|
|
43
|
+
ContentType = "Content-Type",
|
|
44
|
+
Impersonation = "X-Tray-Admin-Impersonate",
|
|
45
|
+
UserAgent = "User-Agent",
|
|
46
|
+
ContentLength = "Content-Length"
|
|
47
|
+
}
|
|
48
|
+
export interface HttpHeadersInterface {
|
|
49
|
+
get: (headers: HttpHeaders, name: string) => O.Option<HttpHeaderValue>;
|
|
50
|
+
extractBearerToken: (headers: HttpHeaders) => O.Option<string>;
|
|
51
|
+
}
|
|
52
|
+
export declare const HttpHeaders: HttpHeadersInterface;
|
|
53
|
+
export declare const serializationFormatToHttpContentType: Record<SerializationFormat, HttpContentType>;
|
|
54
|
+
export declare const isMultiPartBody: (body: HttpRequestBody) => body is MultipartHttpRequestBody;
|
|
55
|
+
//# sourceMappingURL=Http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../src/http/Http.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAOrE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAAC,CAAC;AAE5E,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,MAAM,MAAM,oBAAoB,GAC7B,0BAA0B,GAC1B,0BAA0B,EAAE,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEnE,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;AAE9C,MAAM,MAAM,wBAAwB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG,wBAAwB,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,WAAW,EAAE,eAAe,CAAC;IAC7B,IAAI,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC;CACf,CAAC;AAEF,oBAAY,UAAU;IACrB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;CACjB;AAED,oBAAY,eAAe;IAC1B,IAAI,qBAAqB;IACzB,WAAW,6BAA6B;IACxC,oBAAoB,wBAAwB;IAC5C,IAAI,eAAe;CACnB;AAED,oBAAY,UAAU;IACrB,aAAa,kBAAkB;IAC/B,WAAW,iBAAiB;IAC5B,aAAa,6BAA6B;IAC1C,SAAS,eAAe;IACxB,aAAa,mBAAmB;CAChC;AAED,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACvE,kBAAkB,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,WAAW,EAAE,oBAYzB,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACxD,mBAAmB,EACnB,eAAe,CAGf,CAAC;AAEF,eAAO,MAAM,eAAe,SACrB,eAAe,qCAEkC,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isMultiPartBody = exports.serializationFormatToHttpContentType = exports.HttpHeaders = exports.HttpHeader = exports.HttpContentType = exports.HttpMethod = void 0;
|
|
27
|
+
const O = __importStar(require("fp-ts/lib/Option"));
|
|
28
|
+
const function_1 = require("fp-ts/lib/function");
|
|
29
|
+
const Serialization_1 = require("../serialization/Serialization");
|
|
30
|
+
const getHeader = (headers, name) => O.fromNullable(headers[name.toLowerCase()]);
|
|
31
|
+
var HttpMethod;
|
|
32
|
+
(function (HttpMethod) {
|
|
33
|
+
HttpMethod["Get"] = "GET";
|
|
34
|
+
HttpMethod["Put"] = "PUT";
|
|
35
|
+
HttpMethod["Post"] = "POST";
|
|
36
|
+
HttpMethod["Patch"] = "PATCH";
|
|
37
|
+
HttpMethod["Delete"] = "DELETE";
|
|
38
|
+
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
39
|
+
var HttpContentType;
|
|
40
|
+
(function (HttpContentType) {
|
|
41
|
+
HttpContentType["Json"] = "application/json";
|
|
42
|
+
HttpContentType["OctetStream"] = "application/octet-stream";
|
|
43
|
+
HttpContentType["MultipartRequestBody"] = "multipart/form-data";
|
|
44
|
+
HttpContentType["Text"] = "text/plain";
|
|
45
|
+
})(HttpContentType || (exports.HttpContentType = HttpContentType = {}));
|
|
46
|
+
var HttpHeader;
|
|
47
|
+
(function (HttpHeader) {
|
|
48
|
+
HttpHeader["Authorization"] = "Authorization";
|
|
49
|
+
HttpHeader["ContentType"] = "Content-Type";
|
|
50
|
+
HttpHeader["Impersonation"] = "X-Tray-Admin-Impersonate";
|
|
51
|
+
HttpHeader["UserAgent"] = "User-Agent";
|
|
52
|
+
HttpHeader["ContentLength"] = "Content-Length";
|
|
53
|
+
})(HttpHeader || (exports.HttpHeader = HttpHeader = {}));
|
|
54
|
+
exports.HttpHeaders = {
|
|
55
|
+
get: (headers, name) => getHeader(headers, name),
|
|
56
|
+
extractBearerToken: (headers) => (0, function_1.pipe)(getHeader(headers, HttpHeader.Authorization), O.chain((header) => header.toLowerCase().startsWith('bearer ')
|
|
57
|
+
? O.fromNullable(header.substring(7))
|
|
58
|
+
: O.fromNullable(null))),
|
|
59
|
+
};
|
|
60
|
+
exports.serializationFormatToHttpContentType = {
|
|
61
|
+
[Serialization_1.SerializationFormat.Json]: HttpContentType.Json,
|
|
62
|
+
};
|
|
63
|
+
const isMultiPartBody = (body) => (body === null || body === void 0 ? void 0 : body.files) !== undefined;
|
|
64
|
+
exports.isMultiPartBody = isMultiPartBody;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,QAogBpD"}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.httpClientTest = void 0;
|
|
39
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
40
|
+
const stream_1 = require("stream");
|
|
41
|
+
const function_1 = require("fp-ts/function");
|
|
42
|
+
const t = __importStar(require("io-ts"));
|
|
43
|
+
const http_1 = require("http");
|
|
44
|
+
const util_1 = require("util");
|
|
45
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
46
|
+
const formidable_1 = __importDefault(require("formidable"));
|
|
47
|
+
const Task_1 = require("../task/Task");
|
|
48
|
+
const JsonSerialization_1 = require("../serialization/JsonSerialization");
|
|
49
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
50
|
+
const Http_1 = require("./Http");
|
|
51
|
+
const File_1 = require("../file/File");
|
|
52
|
+
const NodeFsFileStorage_1 = require("../file/NodeFsFileStorage");
|
|
53
|
+
const BufferExtensions_1 = require("../buffer/BufferExtensions");
|
|
54
|
+
function httpClientTest(httpClient) {
|
|
55
|
+
const serialization = new JsonSerialization_1.JsonSerialization();
|
|
56
|
+
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage();
|
|
57
|
+
const testErrorResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
58
|
+
message: t.string,
|
|
59
|
+
}));
|
|
60
|
+
const testResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
61
|
+
strField: t.string,
|
|
62
|
+
intField: t.number,
|
|
63
|
+
}));
|
|
64
|
+
const ReadableCodec = new t.Type('Readable', (input) => input instanceof stream_1.Readable, (input, ctx) => input instanceof stream_1.Readable ? t.success(input) : t.failure(input, ctx), (input) => input);
|
|
65
|
+
const testMultiPartBodyTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
66
|
+
fields: t.record(t.string, t.string),
|
|
67
|
+
files: t.record(t.string, t.type({
|
|
68
|
+
key: t.string,
|
|
69
|
+
metadata: File_1.fileMetadataDescriptor,
|
|
70
|
+
content: t.any,
|
|
71
|
+
})),
|
|
72
|
+
}));
|
|
73
|
+
const testInputCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
74
|
+
inputField: t.number,
|
|
75
|
+
}));
|
|
76
|
+
function sendHttpResponse(httpResponse, response, responseCodec) {
|
|
77
|
+
const serializedResponse = (0, function_1.pipe)(E.right(responseCodec.encode(response)), E.map((encodedResponse) => serialization.serialize(encodedResponse)), E.getOrElse(() => (new util_1.TextEncoder().encode('Error serializing value').buffer)));
|
|
78
|
+
httpResponse.end(Buffer.from(serializedResponse));
|
|
79
|
+
}
|
|
80
|
+
function processHttpRequest(requestCodec, responseCodec, httpRequest, httpResponse, process, isMultiPartBody = false) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (isMultiPartBody) {
|
|
83
|
+
const form = (0, formidable_1.default)({});
|
|
84
|
+
let fields;
|
|
85
|
+
let files;
|
|
86
|
+
try {
|
|
87
|
+
[fields, files] = yield form.parse(httpRequest);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
console.error(err);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const input = {
|
|
94
|
+
fields: flattenFields(fields),
|
|
95
|
+
files: flattenFiles(files),
|
|
96
|
+
};
|
|
97
|
+
const response = (0, function_1.pipe)(requestCodec.decode(input), E.map(process), E.map((result) => new util_1.TextEncoder().encode(JSON.stringify(responseCodec.encode(result))).buffer), E.getOrElse(() => new util_1.TextEncoder().encode('Error serializing value').buffer));
|
|
98
|
+
httpResponse.end(Buffer.from(response));
|
|
99
|
+
}
|
|
100
|
+
const body = [];
|
|
101
|
+
httpRequest.on('data', (chunk) => {
|
|
102
|
+
body.push(chunk);
|
|
103
|
+
});
|
|
104
|
+
httpRequest.on('end', () => {
|
|
105
|
+
const buffer = Buffer.concat(body);
|
|
106
|
+
const response = (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encodedRequest) => requestCodec.decode(encodedRequest)), E.map(process), E.map((result) => responseCodec.encode(result)), E.map((encodedResult) => serialization.serialize(encodedResult)), E.getOrElse(() => (new util_1.TextEncoder().encode('Error serializing value').buffer)));
|
|
107
|
+
httpResponse.end(Buffer.from(response));
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const flattenFields = (fields) => {
|
|
112
|
+
const flattenedFields = {};
|
|
113
|
+
Object.entries(fields).forEach(([key, value]) => {
|
|
114
|
+
if (Array.isArray(value) && value.length > 1) {
|
|
115
|
+
throw new Error(`Field ${key} has more than one value and is current not supported`);
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
flattenedFields[key] = value.join(',');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
flattenedFields[key] = value !== null && value !== void 0 ? value : '';
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return flattenedFields;
|
|
125
|
+
};
|
|
126
|
+
const flattenFiles = (files) => {
|
|
127
|
+
const flattenedFiles = {};
|
|
128
|
+
Object.entries(files)
|
|
129
|
+
.filter(([_key, file]) => file !== null)
|
|
130
|
+
.forEach(([key, file]) => {
|
|
131
|
+
if (Array.isArray(file) && file.length > 1) {
|
|
132
|
+
throw new Error(`Field ${key} has more than one file and is currently not supported`);
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(file)) {
|
|
135
|
+
const fileContent = convertFormidableFileToTrayFile(file[0]);
|
|
136
|
+
flattenedFiles[key] = fileContent;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return flattenedFiles;
|
|
140
|
+
};
|
|
141
|
+
const convertFormidableFileToTrayFile = (file) => {
|
|
142
|
+
var _a;
|
|
143
|
+
return ({
|
|
144
|
+
key: file.newFilename,
|
|
145
|
+
metadata: {
|
|
146
|
+
name: (_a = file.originalFilename) !== null && _a !== void 0 ? _a : '',
|
|
147
|
+
size: file.size,
|
|
148
|
+
},
|
|
149
|
+
content: stream_1.Readable.from(file.filepath),
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const requestListener = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
if (req.method === 'GET' && typeof req.headers['error'] === 'string') {
|
|
155
|
+
const errorCode = +req.headers['error'];
|
|
156
|
+
res.writeHead(errorCode, {
|
|
157
|
+
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json,
|
|
158
|
+
});
|
|
159
|
+
const errorResponse = {
|
|
160
|
+
message: `some error message ${errorCode}`,
|
|
161
|
+
};
|
|
162
|
+
sendHttpResponse(res, errorResponse, testErrorResponseCodec);
|
|
163
|
+
}
|
|
164
|
+
else if (req.method === 'GET') {
|
|
165
|
+
const customHeader = req.headers['x-custom-header'];
|
|
166
|
+
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
167
|
+
const response = {
|
|
168
|
+
strField: customHeader,
|
|
169
|
+
intField: 123,
|
|
170
|
+
};
|
|
171
|
+
sendHttpResponse(res, response, testResponseCodec);
|
|
172
|
+
}
|
|
173
|
+
else if (req.method === 'POST' &&
|
|
174
|
+
((_a = req.headers['content-type']) === null || _a === void 0 ? void 0 : _a.includes(Http_1.HttpContentType.MultipartRequestBody))) {
|
|
175
|
+
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
176
|
+
yield processHttpRequest(testMultiPartBodyTypeCodec, testMultiPartBodyTypeCodec, req, res, (input) => input, true);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const customHeader = req.headers['x-custom-header'];
|
|
180
|
+
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
181
|
+
yield processHttpRequest(testInputCodec, testResponseCodec, req, res, (input) => ({
|
|
182
|
+
strField: customHeader,
|
|
183
|
+
intField: input.inputField,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const host = 'localhost';
|
|
188
|
+
const port = 8000; // TODO: Get random port
|
|
189
|
+
const baseUrl = `http://${host}:${port}`;
|
|
190
|
+
const server = (0, http_1.createServer)(requestListener);
|
|
191
|
+
describe('HttpClient Test', () => {
|
|
192
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
yield new Promise((resolve) => {
|
|
194
|
+
server.listen(port, host, resolve);
|
|
195
|
+
});
|
|
196
|
+
}));
|
|
197
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
yield new Promise((resolve, reject) => {
|
|
199
|
+
server.close((error) => {
|
|
200
|
+
if (error) {
|
|
201
|
+
reject(error);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
resolve();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}));
|
|
209
|
+
test('should send a GET request', () => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
211
|
+
headers: { 'x-custom-header': 'customVal' },
|
|
212
|
+
pathParams: {},
|
|
213
|
+
queryString: {},
|
|
214
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
215
|
+
})();
|
|
216
|
+
const testValue = {
|
|
217
|
+
strField: 'customVal',
|
|
218
|
+
intField: 123,
|
|
219
|
+
};
|
|
220
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
221
|
+
const resultE = yield result();
|
|
222
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
223
|
+
}));
|
|
224
|
+
test('should send a POST request', () => __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
const testInput = {
|
|
226
|
+
inputField: 321,
|
|
227
|
+
};
|
|
228
|
+
const response = yield (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputCodec.encode(testInput))), TE.map((encoded) => serialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, {
|
|
229
|
+
headers: {
|
|
230
|
+
'x-custom-header': 'customVal',
|
|
231
|
+
},
|
|
232
|
+
pathParams: {},
|
|
233
|
+
queryString: {},
|
|
234
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedInput),
|
|
235
|
+
})))();
|
|
236
|
+
const testValue = {
|
|
237
|
+
strField: 'customVal',
|
|
238
|
+
intField: 321,
|
|
239
|
+
};
|
|
240
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
241
|
+
const resultE = yield result();
|
|
242
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
243
|
+
}));
|
|
244
|
+
test('should send a POST request with multipart body', () => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
yield fileStorage.delete('file1')();
|
|
246
|
+
yield fileStorage.delete('file2')();
|
|
247
|
+
const file1 = yield fileStorage.write({
|
|
248
|
+
key: 'file1',
|
|
249
|
+
metadata: {
|
|
250
|
+
name: 'file1',
|
|
251
|
+
},
|
|
252
|
+
content: stream_1.Readable.from('file 1 content'),
|
|
253
|
+
})();
|
|
254
|
+
const file2 = yield fileStorage.write({
|
|
255
|
+
key: 'file2',
|
|
256
|
+
metadata: {
|
|
257
|
+
name: 'file2',
|
|
258
|
+
},
|
|
259
|
+
content: stream_1.Readable.from('file 2 content'),
|
|
260
|
+
})();
|
|
261
|
+
if (file1._tag === 'Left') {
|
|
262
|
+
throw file1.left;
|
|
263
|
+
}
|
|
264
|
+
if (file2._tag === 'Left') {
|
|
265
|
+
throw file2.left;
|
|
266
|
+
}
|
|
267
|
+
const testInput = {
|
|
268
|
+
fields: {
|
|
269
|
+
field1: 'field1',
|
|
270
|
+
field2: 'field2',
|
|
271
|
+
},
|
|
272
|
+
files: {
|
|
273
|
+
file1: {
|
|
274
|
+
key: 'file1',
|
|
275
|
+
metadata: {
|
|
276
|
+
name: 'file1',
|
|
277
|
+
},
|
|
278
|
+
content: stream_1.Readable.from('Hello world'),
|
|
279
|
+
},
|
|
280
|
+
file2: {
|
|
281
|
+
key: 'file2',
|
|
282
|
+
metadata: {
|
|
283
|
+
name: 'file2',
|
|
284
|
+
},
|
|
285
|
+
content: stream_1.Readable.from('Hello world'),
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Post, baseUrl, {
|
|
290
|
+
headers: {
|
|
291
|
+
'x-custom-header': 'customVal',
|
|
292
|
+
'content-type': Http_1.HttpContentType.MultipartRequestBody,
|
|
293
|
+
},
|
|
294
|
+
pathParams: {},
|
|
295
|
+
queryString: {},
|
|
296
|
+
body: testInput,
|
|
297
|
+
})();
|
|
298
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testMultiPartBodyTypeCodec.decode(encoded)))));
|
|
299
|
+
const resultE = yield result();
|
|
300
|
+
expect(resultE).toEqual(E.right(expect.objectContaining({
|
|
301
|
+
fields: testInput.fields,
|
|
302
|
+
files: expect.objectContaining({
|
|
303
|
+
file1: expect.objectContaining({
|
|
304
|
+
key: expect.any(String),
|
|
305
|
+
metadata: expect.objectContaining({
|
|
306
|
+
name: 'file1',
|
|
307
|
+
}),
|
|
308
|
+
}),
|
|
309
|
+
file2: expect.objectContaining({
|
|
310
|
+
key: expect.any(String),
|
|
311
|
+
metadata: expect.objectContaining({
|
|
312
|
+
name: 'file2',
|
|
313
|
+
}),
|
|
314
|
+
}),
|
|
315
|
+
}),
|
|
316
|
+
})));
|
|
317
|
+
}));
|
|
318
|
+
test('should parse an internal error response', () => __awaiter(this, void 0, void 0, function* () {
|
|
319
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
320
|
+
headers: { error: '500' },
|
|
321
|
+
pathParams: {},
|
|
322
|
+
queryString: {},
|
|
323
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
324
|
+
})();
|
|
325
|
+
const testErrorResponse = {
|
|
326
|
+
message: 'some error message 500',
|
|
327
|
+
};
|
|
328
|
+
if (E.isLeft(response)) {
|
|
329
|
+
throw response.left;
|
|
330
|
+
}
|
|
331
|
+
const responseBodyE = yield BufferExtensions_1.BufferExtensions.readableToArrayBuffer(response.right.body)();
|
|
332
|
+
expect(response.right.statusCode).toStrictEqual(500);
|
|
333
|
+
expect(responseBodyE).toStrictEqual(E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse))));
|
|
334
|
+
}));
|
|
335
|
+
test('should parse a not found error response', () => __awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
337
|
+
headers: { error: '404' },
|
|
338
|
+
pathParams: {},
|
|
339
|
+
queryString: {},
|
|
340
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
341
|
+
})();
|
|
342
|
+
const testErrorResponse = {
|
|
343
|
+
message: 'some error message 404',
|
|
344
|
+
};
|
|
345
|
+
if (E.isLeft(response)) {
|
|
346
|
+
throw response.left;
|
|
347
|
+
}
|
|
348
|
+
const responseBodyE = yield BufferExtensions_1.BufferExtensions.readableToArrayBuffer(response.right.body)();
|
|
349
|
+
expect(response.right.statusCode).toStrictEqual(404);
|
|
350
|
+
expect(responseBodyE).toStrictEqual(E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse))));
|
|
351
|
+
}));
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
exports.httpClientTest = httpClientTest;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TaskEither } from 'fp-ts/TaskEither';
|
|
2
|
+
import { HttpMethod, HttpRequest, HttpResponse } from './Http';
|
|
3
|
+
export interface HttpClient {
|
|
4
|
+
execute(method: HttpMethod, url: string, request: HttpRequest): TaskEither<Error, HttpResponse>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/D,MAAM,WAAW,UAAU;IAC1B,OAAO,CACN,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,GAClB,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as T from 'fp-ts/Task';
|
|
2
|
+
import { HttpMethod, HttpRequest, HttpResponse } from './Http';
|
|
3
|
+
export interface HttpController {
|
|
4
|
+
getEndpoints: () => ReadonlyArray<HttpEndpoint>;
|
|
5
|
+
}
|
|
6
|
+
export interface HttpEndpoint {
|
|
7
|
+
path: string;
|
|
8
|
+
method: HttpMethod;
|
|
9
|
+
execute: (request: HttpRequest) => T.Task<HttpResponse>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=HttpController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpController.d.ts","sourceRoot":"","sources":["../../src/http/HttpController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/D,MAAM,WAAW,cAAc;IAC9B,YAAY,EAAE,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Logging {
|
|
2
|
+
info(message: string, octx: ObservabilityContext): void;
|
|
3
|
+
debug(message: string, octx: ObservabilityContext): void;
|
|
4
|
+
error(message: string, octx: ObservabilityContext): void;
|
|
5
|
+
warning(message: string, octx: ObservabilityContext): void;
|
|
6
|
+
}
|
|
7
|
+
export interface ObservabilityContext {
|
|
8
|
+
[key: string]: string | number | Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logging.d.ts","sourceRoot":"","sources":["../../src/logging/Logging.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACvB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAExD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAEzD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAEzD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC3D;AAED,MAAM,WAAW,oBAAoB;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
2
|
+
export declare const addValueToRecordIfPresent: <K extends string | number | symbol, V>(record: Record<K, V>, key: K, valueOpt: O.Option<V>) => Record<K, V>;
|
|
3
|
+
export declare const addValuesToRecordIfPresent: <K extends string | number | symbol, V>(record: Record<K, V>, valuesToAdd: Record<K, O.Option<V>>) => Record<K, V>;
|
|
4
|
+
//# sourceMappingURL=Record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Record.d.ts","sourceRoot":"","sources":["../../src/record/Record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,eAAO,MAAM,yBAAyB,8GAUpC,CAAC;AAEH,eAAO,MAAM,0BAA0B,oHAMC,CAAC"}
|