@trayio/commons 5.33.0 → 5.35.0-unstable.fd7158a
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/base64/Base64.d.ts +5 -10
- package/dist/base64/Base64.d.ts.map +1 -1
- package/dist/base64/Base64.js +8 -40
- package/dist/base64/Base64.unit.test.js +4 -27
- package/dist/buffer/BufferExtensions.d.ts +4 -4
- package/dist/buffer/BufferExtensions.d.ts.map +1 -1
- package/dist/buffer/BufferExtensions.js +25 -38
- package/dist/buffer/BufferExtensions.unit.test.js +22 -45
- package/dist/callsite/CallSite.js +17 -7
- package/dist/codec/CamelCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/CamelCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/CamelCasePropertyNameCodec.js +2 -25
- package/dist/codec/Codec.abstract.test.d.ts +2 -2
- package/dist/codec/Codec.abstract.test.d.ts.map +1 -1
- package/dist/codec/Codec.abstract.test.js +5 -31
- package/dist/codec/Codec.d.ts +2 -2
- package/dist/codec/Codec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.d.ts +2 -2
- package/dist/codec/CompositeCodec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.js +2 -26
- package/dist/codec/PartialRedactionCodec.d.ts +2 -2
- package/dist/codec/PartialRedactionCodec.d.ts.map +1 -1
- package/dist/codec/PartialRedactionCodec.js +2 -25
- package/dist/codec/RemoveNullValuesCodec.d.ts +2 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -1
- package/dist/codec/RemoveNullValuesCodec.js +2 -25
- package/dist/codec/RemoveTopLevelTagCodec.d.ts +2 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts.map +1 -1
- package/dist/codec/RemoveTopLevelTagCodec.js +2 -25
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts +2 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts.map +1 -1
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.js +2 -25
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +15 -38
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/SnakeCasePropertyNameCodec.js +2 -25
- package/dist/codec/TypeCodec.d.ts +24 -8
- package/dist/codec/TypeCodec.d.ts.map +1 -1
- package/dist/codec/TypeCodec.js +40 -48
- package/dist/codec/TypeCodec.unit.test.js +12 -38
- package/dist/dynamicschema/DynamicSchema.d.ts +6 -12
- package/dist/dynamicschema/DynamicSchema.d.ts.map +1 -1
- package/dist/dynamicschema/DynamicSchema.js +18 -41
- package/dist/dynamicschema/DynamicSchema.unit.test.js +51 -75
- package/dist/dynamictype/DynamicType.d.ts +17 -20
- package/dist/dynamictype/DynamicType.d.ts.map +1 -1
- package/dist/dynamictype/DynamicType.js +48 -35
- package/dist/effect/EffectExtensions.d.ts +29 -0
- package/dist/effect/EffectExtensions.d.ts.map +1 -0
- package/dist/effect/EffectExtensions.js +30 -0
- package/dist/effect/EffectExtensions.unit.test.d.ts +2 -0
- package/dist/effect/EffectExtensions.unit.test.d.ts.map +1 -0
- package/dist/effect/EffectExtensions.unit.test.js +59 -0
- package/dist/effect/Interop.d.ts +53 -0
- package/dist/effect/Interop.d.ts.map +1 -0
- package/dist/effect/Interop.js +56 -0
- package/dist/effect/Interop.unit.test.d.ts +2 -0
- package/dist/effect/Interop.unit.test.d.ts.map +1 -0
- package/dist/effect/Interop.unit.test.js +134 -0
- package/dist/effect/SchemaExtensions.d.ts +11 -0
- package/dist/effect/SchemaExtensions.d.ts.map +1 -0
- package/dist/effect/SchemaExtensions.js +7 -0
- package/dist/effect/SchemaExtensions.unit.test.d.ts +2 -0
- package/dist/effect/SchemaExtensions.unit.test.d.ts.map +1 -0
- package/dist/effect/SchemaExtensions.unit.test.js +29 -0
- package/dist/file/FakeFileStorage.d.ts +8 -8
- package/dist/file/FakeFileStorage.d.ts.map +1 -1
- package/dist/file/FakeFileStorage.js +16 -40
- package/dist/file/File.d.ts +10 -14
- package/dist/file/File.d.ts.map +1 -1
- package/dist/file/File.js +31 -24
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
- package/dist/file/FileStorage.abstract.test.js +18 -41
- package/dist/file/NodeFsFileStorage.d.ts +9 -11
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
- package/dist/file/NodeFsFileStorage.integration.test.js +21 -45
- package/dist/file/NodeFsFileStorage.js +37 -29
- package/dist/http/Http.d.ts +11 -13
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +30 -22
- package/dist/http/Http.unit.test.js +3 -26
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +104 -108
- package/dist/http/HttpClient.d.ts +2 -2
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpController.d.ts +2 -3
- package/dist/http/HttpController.d.ts.map +1 -1
- package/dist/http/HttpSchemas.d.ts +13 -0
- package/dist/http/HttpSchemas.d.ts.map +1 -0
- package/dist/http/HttpSchemas.js +23 -0
- package/dist/http/MultipartHttpRequestBody.integration.test.js +31 -20
- package/dist/http/MultipartHttpRequestBody.unit.test.js +70 -53
- package/dist/record/Record.d.ts +3 -3
- package/dist/record/Record.d.ts.map +1 -1
- package/dist/record/Record.js +9 -30
- package/dist/result/Result.d.ts +3 -3
- package/dist/result/Result.d.ts.map +1 -1
- package/dist/result/Result.js +9 -26
- package/dist/schema/DateFromUnixTime.d.ts +4 -0
- package/dist/schema/DateFromUnixTime.d.ts.map +1 -0
- package/dist/schema/DateFromUnixTime.js +10 -0
- package/dist/schema/DateFromUnixTime.unit.test.d.ts +2 -0
- package/dist/schema/DateFromUnixTime.unit.test.d.ts.map +1 -0
- package/dist/schema/DateFromUnixTime.unit.test.js +11 -0
- package/dist/schema/JsonSchemaIntrospector.js +17 -7
- package/dist/sensitive/Sensitive.d.ts +7 -3
- package/dist/sensitive/Sensitive.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.js +23 -39
- package/dist/sensitive/Sensitive.unit.test.d.ts +4 -4
- package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.unit.test.js +20 -46
- package/dist/serialization/FormUrlEncodedSerialization.d.ts +2 -2
- package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -1
- package/dist/serialization/FormUrlEncodedSerialization.js +5 -28
- package/dist/serialization/JsonSerialization.d.ts +2 -2
- package/dist/serialization/JsonSerialization.d.ts.map +1 -1
- package/dist/serialization/JsonSerialization.js +5 -28
- package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -1
- package/dist/serialization/Serialization.abstract.test.js +6 -32
- package/dist/serialization/Serialization.d.ts +2 -2
- package/dist/serialization/Serialization.d.ts.map +1 -1
- package/dist/try/Try.d.ts +2 -2
- package/dist/try/Try.d.ts.map +1 -1
- package/dist/try/Try.js +2 -32
- package/dist/uuid/Uuid.d.ts +11 -10
- package/dist/uuid/Uuid.d.ts.map +1 -1
- package/dist/uuid/Uuid.js +13 -39
- package/dist/uuid/Uuid.unit.test.js +4 -27
- package/dist/zod/SchemaParser.abstract.test.d.ts.map +1 -1
- package/dist/zod/SchemaParser.abstract.test.js +6 -31
- package/dist/zod/SchemaParser.d.ts +2 -2
- package/dist/zod/SchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.d.ts +3 -4
- package/dist/zod/ZodSchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.js +4 -28
- package/dist/zod/ZodSchemaParser.unit.test.js +2 -25
- package/package.json +3 -8
- package/dist/http/HttpTypeDescriptors.d.ts +0 -11
- package/dist/http/HttpTypeDescriptors.d.ts.map +0 -1
- package/dist/http/HttpTypeDescriptors.js +0 -59
- package/dist/task/Task.d.ts +0 -19
- package/dist/task/Task.d.ts.map +0 -1
- package/dist/task/Task.js +0 -74
- package/dist/task/Task.unit.test.d.ts +0 -2
- package/dist/task/Task.unit.test.d.ts.map +0 -1
- package/dist/task/Task.unit.test.js +0 -46
package/dist/file/File.js
CHANGED
|
@@ -15,16 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.FileDescriptor = exports.
|
|
27
|
-
const
|
|
36
|
+
exports.FileDescriptor = exports.fileDescriptorSchema = exports.fileMetadataSchema = exports.FileContentTypeChecker = void 0;
|
|
37
|
+
const effect_1 = require("effect");
|
|
28
38
|
const mime = __importStar(require("mime-types"));
|
|
29
39
|
exports.FileContentTypeChecker = {
|
|
30
40
|
isFileContentType(value) {
|
|
@@ -35,20 +45,17 @@ exports.FileContentTypeChecker = {
|
|
|
35
45
|
return mime.contentType(lowerCaseValue) !== false;
|
|
36
46
|
},
|
|
37
47
|
};
|
|
38
|
-
exports.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
key: t.string,
|
|
50
|
-
metadata: exports.fileMetadataDescriptor,
|
|
51
|
-
});
|
|
48
|
+
exports.fileMetadataSchema = effect_1.Schema.mutable(effect_1.Schema.Struct({
|
|
49
|
+
name: effect_1.Schema.String,
|
|
50
|
+
size: effect_1.Schema.optional(effect_1.Schema.Number),
|
|
51
|
+
contentType: effect_1.Schema.optional(effect_1.Schema.String),
|
|
52
|
+
})).annotations({ identifier: 'FileMetadata' });
|
|
53
|
+
exports.fileDescriptorSchema = effect_1.Schema.mutable(effect_1.Schema.Struct({
|
|
54
|
+
_tag: effect_1.Schema.Literal('FileDescriptor'),
|
|
55
|
+
key: effect_1.Schema.String,
|
|
56
|
+
metadata: exports.fileMetadataSchema,
|
|
57
|
+
})).annotations({ identifier: 'FileDescriptor' });
|
|
58
|
+
const isFileMetadata = effect_1.Schema.is(exports.fileMetadataSchema);
|
|
52
59
|
exports.FileDescriptor = {
|
|
53
60
|
isFileDescriptor(value) {
|
|
54
61
|
return (typeof value === 'object' &&
|
|
@@ -58,7 +65,7 @@ exports.FileDescriptor = {
|
|
|
58
65
|
'key' in value &&
|
|
59
66
|
typeof value.key === 'string' &&
|
|
60
67
|
'metadata' in value &&
|
|
61
|
-
|
|
68
|
+
isFileMetadata(value.metadata));
|
|
62
69
|
},
|
|
63
70
|
fromFile(file) {
|
|
64
71
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileStorage.abstract.test.d.ts","sourceRoot":"","sources":["../../src/file/FileStorage.abstract.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAQ,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"FileStorage.abstract.test.d.ts","sourceRoot":"","sources":["../../src/file/FileStorage.abstract.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAQ,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,eAAe,GAAI,aAAa,WAAW,SA6GvD,CAAC"}
|
|
@@ -1,33 +1,10 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.fileStorageTest = void 0;
|
|
27
|
-
const
|
|
4
|
+
const effect_1 = require("effect");
|
|
28
5
|
const uuid_1 = require("uuid");
|
|
29
|
-
const O = __importStar(require("fp-ts/Option"));
|
|
30
6
|
const stream_1 = require("stream");
|
|
7
|
+
const BufferExtensions_1 = require("../buffer/BufferExtensions");
|
|
31
8
|
const JsonSerialization_1 = require("../serialization/JsonSerialization");
|
|
32
9
|
const fileStorageTest = (fileStorage) => {
|
|
33
10
|
describe('FileStorage Tests', () => {
|
|
@@ -51,23 +28,23 @@ const fileStorageTest = (fileStorage) => {
|
|
|
51
28
|
},
|
|
52
29
|
content: readableStream,
|
|
53
30
|
};
|
|
54
|
-
const writtenFile = await fileStorage.write(file,
|
|
55
|
-
expect(writtenFile).toEqual(
|
|
56
|
-
const sharedUrl = await fileStorage.getSharedUrl(file.reference.key)
|
|
57
|
-
expect(sharedUrl).toEqual(
|
|
31
|
+
const writtenFile = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.write(file, effect_1.Option.none())));
|
|
32
|
+
expect(writtenFile).toEqual(effect_1.Either.right(file));
|
|
33
|
+
const sharedUrl = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.getSharedUrl(file.reference.key)));
|
|
34
|
+
expect(sharedUrl).toEqual(effect_1.Either.right(expect.objectContaining({
|
|
58
35
|
url: expect.any(String),
|
|
59
36
|
})));
|
|
60
|
-
if (
|
|
37
|
+
if (effect_1.Either.isRight(sharedUrl)) {
|
|
61
38
|
if (typeof sharedUrl.right.expires !== 'undefined') {
|
|
62
39
|
expect(sharedUrl.right.expires).toEqual(expect.any(Number));
|
|
63
40
|
}
|
|
64
41
|
}
|
|
65
|
-
const size = await fileStorage.getSize(file.reference.key)
|
|
66
|
-
expect(size).toEqual(
|
|
67
|
-
const read = await fileStorage.read(file.reference.key)
|
|
68
|
-
const readResponse =
|
|
42
|
+
const size = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.getSize(file.reference.key)));
|
|
43
|
+
expect(size).toEqual(effect_1.Either.right(expect.any(Number)));
|
|
44
|
+
const read = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.read(file.reference.key)));
|
|
45
|
+
const readResponse = effect_1.Either.getOrElse(read, () => {
|
|
69
46
|
throw new Error('Expected right');
|
|
70
|
-
})
|
|
47
|
+
});
|
|
71
48
|
let data = '';
|
|
72
49
|
await new Promise((resolve) => {
|
|
73
50
|
readResponse.content.on('data', (chunk) => {
|
|
@@ -77,21 +54,21 @@ const fileStorageTest = (fileStorage) => {
|
|
|
77
54
|
resolve(undefined);
|
|
78
55
|
});
|
|
79
56
|
});
|
|
80
|
-
const deserializedData = serialization.deserialize(Buffer.from(data));
|
|
81
|
-
if (
|
|
57
|
+
const deserializedData = serialization.deserialize(BufferExtensions_1.BufferExtensions.bufferToArrayBuffer(Buffer.from(data)));
|
|
58
|
+
if (effect_1.Either.isLeft(deserializedData)) {
|
|
82
59
|
throw new Error('failed to deserialise stream contents');
|
|
83
60
|
}
|
|
84
61
|
expect(deserializedData.right).toStrictEqual(fileContent);
|
|
85
|
-
const deleted = await fileStorage.delete(file.reference.key)
|
|
86
|
-
expect(deleted).toEqual(
|
|
62
|
+
const deleted = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.delete(file.reference.key)));
|
|
63
|
+
expect(deleted).toEqual(effect_1.Either.right(undefined));
|
|
87
64
|
});
|
|
88
65
|
});
|
|
89
66
|
});
|
|
90
67
|
describe('Reading a file', () => {
|
|
91
68
|
describe('when the file does not exist', () => {
|
|
92
69
|
it('should return does not exist error', async () => {
|
|
93
|
-
const read = await fileStorage.read(`fail_test-${(0, uuid_1.v4)()}.zip`)
|
|
94
|
-
if (
|
|
70
|
+
const read = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.read(`fail_test-${(0, uuid_1.v4)()}.zip`)));
|
|
71
|
+
if (effect_1.Either.isRight(read)) {
|
|
95
72
|
throw new Error('Expected left');
|
|
96
73
|
}
|
|
97
74
|
expect(read.left).toBeInstanceOf(Error);
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as TE from 'fp-ts/lib/TaskEither';
|
|
3
1
|
import { Dirent } from 'fs';
|
|
4
|
-
import
|
|
2
|
+
import { Effect, Option } from 'effect';
|
|
5
3
|
import { File, FileStorage, SharedUrl } from './File';
|
|
6
4
|
import { DynamicObject } from '../dynamictype/DynamicType';
|
|
7
5
|
export declare class NodeFsFileStorage implements FileStorage {
|
|
8
6
|
private basePath;
|
|
9
7
|
constructor(basePath?: string);
|
|
10
|
-
write(file: File, writeOptions?:
|
|
11
|
-
read(key: string):
|
|
12
|
-
getSharedUrl(key: string):
|
|
13
|
-
getSize(key: string):
|
|
14
|
-
delete(key: string):
|
|
15
|
-
createDirectory(key: string):
|
|
16
|
-
readDirectory(key: string):
|
|
17
|
-
deleteDirectory(key: string):
|
|
8
|
+
write(file: File, writeOptions?: Option.Option<DynamicObject>): Effect.Effect<File, Error>;
|
|
9
|
+
read(key: string): Effect.Effect<File, Error>;
|
|
10
|
+
getSharedUrl(key: string): Effect.Effect<SharedUrl, Error>;
|
|
11
|
+
getSize(key: string): Effect.Effect<number, Error>;
|
|
12
|
+
delete(key: string): Effect.Effect<undefined, Error>;
|
|
13
|
+
createDirectory(key: string): Effect.Effect<undefined, Error>;
|
|
14
|
+
readDirectory(key: string): Effect.Effect<Dirent[], Error>;
|
|
15
|
+
deleteDirectory(key: string): Effect.Effect<undefined, Error>;
|
|
18
16
|
}
|
|
19
17
|
//# sourceMappingURL=NodeFsFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeFsFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/NodeFsFileStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeFsFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/NodeFsFileStorage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EACN,IAAI,EACJ,WAAW,EAEX,SAAS,EAET,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAS3D,qBAAa,iBAAkB,YAAW,WAAW;IACxC,OAAO,CAAC,QAAQ;gBAAR,QAAQ,GAAE,MAAe;IAE7C,KAAK,CACJ,IAAI,EAAE,IAAI,EACV,YAAY,GAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAiB,GACxD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC;IAgB7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC;IAoB7C,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;IAQ1D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IASlD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;IAQpD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;IAU7D,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC;IAS1D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;CAS7D"}
|
|
@@ -1,32 +1,8 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const effect_1 = require("effect");
|
|
26
4
|
const stream_1 = require("stream");
|
|
27
5
|
const uuid_1 = require("uuid");
|
|
28
|
-
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
-
const E = __importStar(require("fp-ts/Either"));
|
|
30
6
|
const FileStorage_abstract_test_1 = require("./FileStorage.abstract.test");
|
|
31
7
|
const NodeFsFileStorage_1 = require("./NodeFsFileStorage");
|
|
32
8
|
describe('NodeFsFileStorage Tests', () => {
|
|
@@ -49,8 +25,8 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
49
25
|
},
|
|
50
26
|
content: readableStream,
|
|
51
27
|
};
|
|
52
|
-
const writtenFile = await fileStorage.write(file,
|
|
53
|
-
expect(writtenFile).toEqual(
|
|
28
|
+
const writtenFile = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.write(file, effect_1.Option.none())));
|
|
29
|
+
expect(writtenFile).toEqual(effect_1.Either.right(file));
|
|
54
30
|
const secondFileContent = ' And we continue to write.';
|
|
55
31
|
const appendReadableStream = new stream_1.Readable({
|
|
56
32
|
read() {
|
|
@@ -66,13 +42,13 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
66
42
|
},
|
|
67
43
|
content: appendReadableStream,
|
|
68
44
|
};
|
|
69
|
-
const appendedFile = await fileStorage.write(appendFile,
|
|
70
|
-
expect(appendedFile).toEqual(
|
|
45
|
+
const appendedFile = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.write(appendFile, effect_1.Option.some({ flag: 'a' }))));
|
|
46
|
+
expect(appendedFile).toEqual(effect_1.Either.right(appendFile));
|
|
71
47
|
// When reading the full contents.
|
|
72
|
-
const read = await fileStorage.read(file.reference.key)
|
|
73
|
-
const readResponse =
|
|
48
|
+
const read = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.read(file.reference.key)));
|
|
49
|
+
const readResponse = effect_1.Either.getOrElse(read, () => {
|
|
74
50
|
throw new Error('Expected right');
|
|
75
|
-
})
|
|
51
|
+
});
|
|
76
52
|
let data = '';
|
|
77
53
|
await new Promise((resolve) => {
|
|
78
54
|
readResponse.content.on('data', (chunk) => {
|
|
@@ -83,8 +59,8 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
83
59
|
});
|
|
84
60
|
});
|
|
85
61
|
expect(Buffer.from(data).toString()).toStrictEqual(`${fileContent}${secondFileContent}`);
|
|
86
|
-
const deleted = await fileStorage.delete(file.reference.key)
|
|
87
|
-
expect(deleted).toEqual(
|
|
62
|
+
const deleted = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.delete(file.reference.key)));
|
|
63
|
+
expect(deleted).toEqual(effect_1.Either.right(undefined));
|
|
88
64
|
});
|
|
89
65
|
it('should create, read and remove a folder', async () => {
|
|
90
66
|
const fileContent = 'This is the initial text.';
|
|
@@ -96,8 +72,8 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
96
72
|
});
|
|
97
73
|
const folderName = `folder`;
|
|
98
74
|
const fileName = `test-${(0, uuid_1.v4)()}.txt`;
|
|
99
|
-
const createdFolderResult = await fileStorage.createDirectory(folderName)
|
|
100
|
-
expect(createdFolderResult).toEqual(
|
|
75
|
+
const createdFolderResult = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.createDirectory(folderName)));
|
|
76
|
+
expect(createdFolderResult).toEqual(effect_1.Either.right(undefined));
|
|
101
77
|
const file = {
|
|
102
78
|
reference: {
|
|
103
79
|
_tag: 'FileDescriptor',
|
|
@@ -106,16 +82,16 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
106
82
|
},
|
|
107
83
|
content: readableStream,
|
|
108
84
|
};
|
|
109
|
-
const writtenFile = await fileStorage.write(file,
|
|
110
|
-
expect(writtenFile).toEqual(
|
|
111
|
-
const readFolderResult = await fileStorage.readDirectory(folderName)
|
|
112
|
-
const contents =
|
|
85
|
+
const writtenFile = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.write(file, effect_1.Option.none())));
|
|
86
|
+
expect(writtenFile).toEqual(effect_1.Either.right(file));
|
|
87
|
+
const readFolderResult = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.readDirectory(folderName)));
|
|
88
|
+
const contents = effect_1.Either.getOrElse(readFolderResult, () => {
|
|
113
89
|
throw new Error('Expected right');
|
|
114
|
-
})
|
|
90
|
+
});
|
|
115
91
|
expect(contents.length).toEqual(1);
|
|
116
|
-
const deleteFolderResult = await fileStorage.deleteDirectory(folderName)
|
|
117
|
-
expect(deleteFolderResult).toEqual(
|
|
118
|
-
const readFolderResult2 = await fileStorage.readDirectory(folderName)
|
|
119
|
-
expect(readFolderResult2).toEqual(
|
|
92
|
+
const deleteFolderResult = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.deleteDirectory(folderName)));
|
|
93
|
+
expect(deleteFolderResult).toEqual(effect_1.Either.right(undefined));
|
|
94
|
+
const readFolderResult2 = await effect_1.Effect.runPromise(effect_1.Effect.either(fileStorage.readDirectory(folderName)));
|
|
95
|
+
expect(readFolderResult2).toEqual(effect_1.Either.left(new Error("Error: ENOENT: no such file or directory, scandir '/tmp/folder'")));
|
|
120
96
|
});
|
|
121
97
|
});
|
|
@@ -15,35 +15,46 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.NodeFsFileStorage = void 0;
|
|
27
37
|
const fs = __importStar(require("fs/promises"));
|
|
28
38
|
const path = __importStar(require("path"));
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
39
|
+
const effect_1 = require("effect");
|
|
40
|
+
const EffectExtensions_1 = require("../effect/EffectExtensions");
|
|
41
|
+
const attempt = (block) => effect_1.Effect.tryPromise({
|
|
42
|
+
try: block,
|
|
43
|
+
catch: (reason) => new Error(String(reason)),
|
|
44
|
+
});
|
|
33
45
|
class NodeFsFileStorage {
|
|
34
46
|
basePath;
|
|
35
47
|
constructor(basePath = '/tmp') {
|
|
36
48
|
this.basePath = basePath;
|
|
37
49
|
}
|
|
38
|
-
write(file, writeOptions =
|
|
50
|
+
write(file, writeOptions = effect_1.Option.none()) {
|
|
39
51
|
const filePath = `${this.basePath}/${file.reference.key}`;
|
|
40
|
-
const uploadOptions =
|
|
41
|
-
|
|
42
|
-
return (0, function_1.pipe)(result, TE.map(() => file));
|
|
52
|
+
const uploadOptions = effect_1.Option.getOrNull(writeOptions);
|
|
53
|
+
return effect_1.Effect.map(EffectExtensions_1.EffectExtensions.tryPromiseWithSimpleError(() => fs.writeFile(filePath, file.content, uploadOptions?.flag ? { flag: uploadOptions.flag } : {})), () => file);
|
|
43
54
|
}
|
|
44
55
|
read(key) {
|
|
45
56
|
const filePath = `${this.basePath}/${key}`;
|
|
46
|
-
return
|
|
57
|
+
return attempt(async () => {
|
|
47
58
|
const fileHandle = await fs.open(filePath, 'r');
|
|
48
59
|
const stat = await fs.stat(filePath);
|
|
49
60
|
const stream = fileHandle.createReadStream();
|
|
@@ -57,42 +68,39 @@ class NodeFsFileStorage {
|
|
|
57
68
|
metadata,
|
|
58
69
|
};
|
|
59
70
|
return { reference: fileReference, content: stream };
|
|
60
|
-
}
|
|
71
|
+
});
|
|
61
72
|
}
|
|
62
73
|
getSharedUrl(key) {
|
|
63
74
|
const filePath = `${this.basePath}/${key}`;
|
|
64
|
-
return
|
|
75
|
+
return attempt(async () => ({
|
|
65
76
|
url: path.resolve(filePath),
|
|
66
|
-
})
|
|
77
|
+
}));
|
|
67
78
|
}
|
|
68
79
|
getSize(key) {
|
|
69
80
|
const filePath = `${this.basePath}/${key}`;
|
|
70
|
-
return
|
|
81
|
+
return attempt(async () => {
|
|
71
82
|
const stat = await fs.stat(filePath);
|
|
72
83
|
return stat.size;
|
|
73
|
-
}
|
|
84
|
+
});
|
|
74
85
|
}
|
|
75
86
|
delete(key) {
|
|
76
87
|
const filePath = `${this.basePath}/${key}`;
|
|
77
|
-
|
|
78
|
-
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
88
|
+
return effect_1.Effect.map(EffectExtensions_1.EffectExtensions.tryPromiseWithSimpleError(() => fs.unlink(filePath)), () => undefined);
|
|
79
89
|
}
|
|
80
90
|
createDirectory(key) {
|
|
81
91
|
const dirPath = `${this.basePath}/${key}`;
|
|
82
|
-
|
|
83
|
-
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
92
|
+
return effect_1.Effect.map(EffectExtensions_1.EffectExtensions.tryPromiseWithSimpleError(() => fs.mkdir(dirPath, { recursive: true })), () => undefined);
|
|
84
93
|
}
|
|
85
94
|
readDirectory(key) {
|
|
86
95
|
const dirPath = `${this.basePath}/${key}`;
|
|
87
|
-
return
|
|
96
|
+
return attempt(async () => {
|
|
88
97
|
const files = await fs.readdir(dirPath, { withFileTypes: true });
|
|
89
98
|
return files;
|
|
90
|
-
}
|
|
99
|
+
});
|
|
91
100
|
}
|
|
92
101
|
deleteDirectory(key) {
|
|
93
102
|
const dirPath = `${this.basePath}/${key}`;
|
|
94
|
-
|
|
95
|
-
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
103
|
+
return effect_1.Effect.map(EffectExtensions_1.EffectExtensions.tryPromiseWithSimpleError(() => fs.rm(dirPath, { recursive: true, force: true })), () => undefined);
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
exports.NodeFsFileStorage = NodeFsFileStorage;
|
package/dist/http/Http.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import * as O from 'fp-ts/lib/Option';
|
|
3
|
-
import * as TE from 'fp-ts/lib/TaskEither';
|
|
1
|
+
import { Effect, Option } from 'effect';
|
|
4
2
|
import { Readable } from 'stream';
|
|
5
3
|
import { File, FileStorage } from '../file/File';
|
|
6
4
|
import { SerializationFormat } from '../serialization/Serialization';
|
|
@@ -17,10 +15,10 @@ export type MultipartHttpRequestBody = {
|
|
|
17
15
|
};
|
|
18
16
|
export type StreamHttpRequestBody = Readable;
|
|
19
17
|
export interface MultipartHttpRequestBodyInterface {
|
|
20
|
-
create: (value: unknown, fileStorage: FileStorage) =>
|
|
18
|
+
create: (value: unknown, fileStorage: FileStorage) => Effect.Effect<MultipartHttpRequestBody, Error>;
|
|
21
19
|
}
|
|
22
20
|
export declare const MultipartHttpRequestBody: {
|
|
23
|
-
create: (value: unknown, fileStorage: FileStorage) =>
|
|
21
|
+
create: (value: unknown, fileStorage: FileStorage) => Effect.Effect<MultipartHttpRequestBody, Error>;
|
|
24
22
|
};
|
|
25
23
|
export type HttpRequestBody = RegularHttpRequestBody | MultipartHttpRequestBody | StreamHttpRequestBody;
|
|
26
24
|
export type HttpCertificate = {
|
|
@@ -28,20 +26,20 @@ export type HttpCertificate = {
|
|
|
28
26
|
key: string;
|
|
29
27
|
};
|
|
30
28
|
export type HttpAgent = {
|
|
31
|
-
certificate:
|
|
29
|
+
certificate: Option.Option<HttpCertificate>;
|
|
32
30
|
};
|
|
33
31
|
export type HeaderOptions = {
|
|
34
|
-
preserveHeaderCasing:
|
|
32
|
+
preserveHeaderCasing: Option.Option<boolean>;
|
|
35
33
|
};
|
|
36
34
|
export type HttpRequest = {
|
|
37
35
|
headers: HttpHeaders;
|
|
38
|
-
headerOptions:
|
|
36
|
+
headerOptions: Option.Option<HeaderOptions>;
|
|
39
37
|
pathParams: Record<string, string>;
|
|
40
38
|
queryString: HttpQueryString;
|
|
41
39
|
body: HttpRequestBody;
|
|
42
|
-
agent:
|
|
43
|
-
clientIp:
|
|
44
|
-
timeout?:
|
|
40
|
+
agent: Option.Option<HttpAgent>;
|
|
41
|
+
clientIp: Option.Option<string>;
|
|
42
|
+
timeout?: Option.Option<number>;
|
|
45
43
|
};
|
|
46
44
|
export type HttpResponse = {
|
|
47
45
|
statusCode: number;
|
|
@@ -79,8 +77,8 @@ export interface HttpRequestInterface {
|
|
|
79
77
|
}
|
|
80
78
|
export declare const HttpRequest: HttpRequestInterface;
|
|
81
79
|
export interface HttpHeadersInterface {
|
|
82
|
-
get: (headers: HttpHeaders, name: string) =>
|
|
83
|
-
extractBearerToken: (headers: HttpHeaders) =>
|
|
80
|
+
get: (headers: HttpHeaders, name: string) => Option.Option<HttpHeaderValue>;
|
|
81
|
+
extractBearerToken: (headers: HttpHeaders) => Option.Option<string>;
|
|
84
82
|
fromDynamicObject: (headers: DynamicObject) => HttpHeaders;
|
|
85
83
|
toDynamicObject: (headers: HttpHeaders) => DynamicObject;
|
|
86
84
|
}
|
package/dist/http/Http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../src/http/Http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../src/http/Http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,IAAI,EAAkB,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAgB3D,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,WAAW,CAAC;AAEjD,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,qBAAqB,GAAG,QAAQ,CAAC;AAE7C,MAAM,WAAW,iCAAiC;IACjD,MAAM,EAAE,CACP,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,WAAW,KACpB,MAAM,CAAC,MAAM,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;CACpD;AAED,eAAO,MAAM,wBAAwB;oBAE5B,OAAO,eACD,WAAW,KACtB,MAAM,CAAC,MAAM,CAAC,wBAAwB,EAAE,KAAK,CAAC;CAqGjD,CAAC;AAEF,MAAM,MAAM,eAAe,GACxB,sBAAsB,GACtB,wBAAwB,GACxB,qBAAqB,CAAC;AAEzB,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC5C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,WAAW,EAAE,eAAe,CAAC;IAC7B,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CAChC,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,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,GAAG,QAAQ;CACX;AAED,oBAAY,eAAe;IAC1B,IAAI,qBAAqB;IACzB,WAAW,6BAA6B;IACxC,cAAc,sCAAsC;IACpD,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;IAChC,kBAAkB,wBAAwB;IAC1C,IAAI,SAAS;IACb,YAAY,oBAAoB;CAChC;AAED,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,WAAW,CAAC;CAC3D;AAED,eAAO,MAAM,WAAW,EAAE,oBAYzB,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAC5E,kBAAkB,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpE,iBAAiB,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,WAAW,CAAC;IAC3D,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,aAAa,CAAC;CACzD;AAED,eAAO,MAAM,WAAW,EAAE,oBAwIzB,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACxD,mBAAmB,EACnB,eAAe,CAIf,CAAC;AAEF,eAAO,MAAM,eAAe,GAC3B,MAAM,eAAe,KACnB,IAAI,IAAI,wBAC6C,CAAC"}
|
package/dist/http/Http.js
CHANGED
|
@@ -15,18 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.isMultiPartBody = exports.serializationFormatToHttpContentType = exports.HttpHeaders = exports.HttpRequest = exports.HttpHeader = exports.HttpContentType = exports.HttpMethod = exports.MultipartHttpRequestBody = void 0;
|
|
27
|
-
const
|
|
28
|
-
const TE = __importStar(require("fp-ts/lib/TaskEither"));
|
|
29
|
-
const function_1 = require("fp-ts/lib/function");
|
|
37
|
+
const effect_1 = require("effect");
|
|
30
38
|
const stream_1 = require("stream");
|
|
31
39
|
const _ = __importStar(require("lodash"));
|
|
32
40
|
const File_1 = require("../file/File");
|
|
@@ -36,12 +44,12 @@ const getHeader = (headers, name) => {
|
|
|
36
44
|
...acc,
|
|
37
45
|
[key.toLowerCase()]: headers[key],
|
|
38
46
|
}), {});
|
|
39
|
-
return
|
|
47
|
+
return effect_1.Option.fromNullable(lowerCasedHeaders[name.toLowerCase()]);
|
|
40
48
|
};
|
|
41
49
|
exports.MultipartHttpRequestBody = {
|
|
42
50
|
create: (value, fileStorage) => {
|
|
43
51
|
if (value === null || typeof value !== 'object') {
|
|
44
|
-
return
|
|
52
|
+
return effect_1.Effect.fail(Error('Multipart body must be an object'));
|
|
45
53
|
}
|
|
46
54
|
/**
|
|
47
55
|
* Recursively traverses an object to find FileDescriptors at any nesting level.
|
|
@@ -92,7 +100,7 @@ exports.MultipartHttpRequestBody = {
|
|
|
92
100
|
const fileDescriptorPaths = findFileDescriptors(value);
|
|
93
101
|
// Extract fields, using dot notation for nested structures
|
|
94
102
|
const fields = extractFields(value);
|
|
95
|
-
return
|
|
103
|
+
return effect_1.Effect.map(effect_1.Effect.all(fileDescriptorPaths.map(({ path, descriptor }) => effect_1.Effect.map(fileStorage.read(descriptor.key), (file) => ({
|
|
96
104
|
// Use the object path (not the file key) as the form field name
|
|
97
105
|
// This tells the server where to place the FileDescriptor in the reconstructed object
|
|
98
106
|
key: path.join('.'),
|
|
@@ -107,13 +115,13 @@ exports.MultipartHttpRequestBody = {
|
|
|
107
115
|
},
|
|
108
116
|
},
|
|
109
117
|
},
|
|
110
|
-
}))))
|
|
118
|
+
})))), (files) => {
|
|
111
119
|
const filesRecord = {};
|
|
112
120
|
files.forEach(({ key, file }) => {
|
|
113
121
|
filesRecord[key] = file;
|
|
114
122
|
});
|
|
115
123
|
return { fields, files: filesRecord };
|
|
116
|
-
})
|
|
124
|
+
});
|
|
117
125
|
},
|
|
118
126
|
};
|
|
119
127
|
var HttpMethod;
|
|
@@ -151,18 +159,18 @@ exports.HttpRequest = {
|
|
|
151
159
|
pathParams: {},
|
|
152
160
|
queryString: {},
|
|
153
161
|
body: stream_1.Readable.from(''),
|
|
154
|
-
headerOptions:
|
|
155
|
-
agent:
|
|
156
|
-
clientIp:
|
|
157
|
-
timeout:
|
|
162
|
+
headerOptions: effect_1.Option.none(),
|
|
163
|
+
agent: effect_1.Option.none(),
|
|
164
|
+
clientIp: effect_1.Option.none(),
|
|
165
|
+
timeout: effect_1.Option.none(),
|
|
158
166
|
...httpRequest,
|
|
159
167
|
}),
|
|
160
168
|
};
|
|
161
169
|
exports.HttpHeaders = {
|
|
162
170
|
get: (headers, name) => getHeader(headers, name),
|
|
163
|
-
extractBearerToken: (headers) =>
|
|
164
|
-
?
|
|
165
|
-
:
|
|
171
|
+
extractBearerToken: (headers) => effect_1.Option.flatMap(getHeader(headers, HttpHeader.Authorization), (header) => header.toLowerCase().startsWith('bearer ')
|
|
172
|
+
? effect_1.Option.some(header.substring(7))
|
|
173
|
+
: effect_1.Option.none()),
|
|
166
174
|
fromDynamicObject(headers) {
|
|
167
175
|
const flattenObject = (obj, prefix = '') => Object.entries(obj).reduce((acc, [key, value]) => {
|
|
168
176
|
const newKey = prefix ? `${prefix}.${key}` : key;
|