@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.
Files changed (146) hide show
  1. package/dist/base64/Base64.d.ts +5 -10
  2. package/dist/base64/Base64.d.ts.map +1 -1
  3. package/dist/base64/Base64.js +8 -40
  4. package/dist/base64/Base64.unit.test.js +4 -27
  5. package/dist/buffer/BufferExtensions.d.ts +4 -4
  6. package/dist/buffer/BufferExtensions.d.ts.map +1 -1
  7. package/dist/buffer/BufferExtensions.js +25 -38
  8. package/dist/buffer/BufferExtensions.unit.test.js +22 -45
  9. package/dist/callsite/CallSite.js +17 -7
  10. package/dist/codec/CamelCasePropertyNameCodec.d.ts +2 -2
  11. package/dist/codec/CamelCasePropertyNameCodec.d.ts.map +1 -1
  12. package/dist/codec/CamelCasePropertyNameCodec.js +2 -25
  13. package/dist/codec/Codec.abstract.test.d.ts +2 -2
  14. package/dist/codec/Codec.abstract.test.d.ts.map +1 -1
  15. package/dist/codec/Codec.abstract.test.js +5 -31
  16. package/dist/codec/Codec.d.ts +2 -2
  17. package/dist/codec/Codec.d.ts.map +1 -1
  18. package/dist/codec/CompositeCodec.d.ts +2 -2
  19. package/dist/codec/CompositeCodec.d.ts.map +1 -1
  20. package/dist/codec/CompositeCodec.js +2 -26
  21. package/dist/codec/PartialRedactionCodec.d.ts +2 -2
  22. package/dist/codec/PartialRedactionCodec.d.ts.map +1 -1
  23. package/dist/codec/PartialRedactionCodec.js +2 -25
  24. package/dist/codec/RemoveNullValuesCodec.d.ts +2 -2
  25. package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -1
  26. package/dist/codec/RemoveNullValuesCodec.js +2 -25
  27. package/dist/codec/RemoveTopLevelTagCodec.d.ts +2 -2
  28. package/dist/codec/RemoveTopLevelTagCodec.d.ts.map +1 -1
  29. package/dist/codec/RemoveTopLevelTagCodec.js +2 -25
  30. package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts +2 -2
  31. package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts.map +1 -1
  32. package/dist/codec/SensitiveRemoveTagAndRedactCodec.js +2 -25
  33. package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +15 -38
  34. package/dist/codec/SnakeCasePropertyNameCodec.d.ts +2 -2
  35. package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -1
  36. package/dist/codec/SnakeCasePropertyNameCodec.js +2 -25
  37. package/dist/codec/TypeCodec.d.ts +24 -8
  38. package/dist/codec/TypeCodec.d.ts.map +1 -1
  39. package/dist/codec/TypeCodec.js +40 -48
  40. package/dist/codec/TypeCodec.unit.test.js +12 -38
  41. package/dist/dynamicschema/DynamicSchema.d.ts +6 -12
  42. package/dist/dynamicschema/DynamicSchema.d.ts.map +1 -1
  43. package/dist/dynamicschema/DynamicSchema.js +18 -41
  44. package/dist/dynamicschema/DynamicSchema.unit.test.js +51 -75
  45. package/dist/dynamictype/DynamicType.d.ts +17 -20
  46. package/dist/dynamictype/DynamicType.d.ts.map +1 -1
  47. package/dist/dynamictype/DynamicType.js +48 -35
  48. package/dist/effect/EffectExtensions.d.ts +29 -0
  49. package/dist/effect/EffectExtensions.d.ts.map +1 -0
  50. package/dist/effect/EffectExtensions.js +30 -0
  51. package/dist/effect/EffectExtensions.unit.test.d.ts +2 -0
  52. package/dist/effect/EffectExtensions.unit.test.d.ts.map +1 -0
  53. package/dist/effect/EffectExtensions.unit.test.js +59 -0
  54. package/dist/effect/Interop.d.ts +53 -0
  55. package/dist/effect/Interop.d.ts.map +1 -0
  56. package/dist/effect/Interop.js +56 -0
  57. package/dist/effect/Interop.unit.test.d.ts +2 -0
  58. package/dist/effect/Interop.unit.test.d.ts.map +1 -0
  59. package/dist/effect/Interop.unit.test.js +134 -0
  60. package/dist/effect/SchemaExtensions.d.ts +11 -0
  61. package/dist/effect/SchemaExtensions.d.ts.map +1 -0
  62. package/dist/effect/SchemaExtensions.js +7 -0
  63. package/dist/effect/SchemaExtensions.unit.test.d.ts +2 -0
  64. package/dist/effect/SchemaExtensions.unit.test.d.ts.map +1 -0
  65. package/dist/effect/SchemaExtensions.unit.test.js +29 -0
  66. package/dist/file/FakeFileStorage.d.ts +8 -8
  67. package/dist/file/FakeFileStorage.d.ts.map +1 -1
  68. package/dist/file/FakeFileStorage.js +16 -40
  69. package/dist/file/File.d.ts +10 -14
  70. package/dist/file/File.d.ts.map +1 -1
  71. package/dist/file/File.js +31 -24
  72. package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
  73. package/dist/file/FileStorage.abstract.test.js +18 -41
  74. package/dist/file/NodeFsFileStorage.d.ts +9 -11
  75. package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
  76. package/dist/file/NodeFsFileStorage.integration.test.js +21 -45
  77. package/dist/file/NodeFsFileStorage.js +37 -29
  78. package/dist/http/Http.d.ts +11 -13
  79. package/dist/http/Http.d.ts.map +1 -1
  80. package/dist/http/Http.js +30 -22
  81. package/dist/http/Http.unit.test.js +3 -26
  82. package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
  83. package/dist/http/HttpClient.abstract.test.js +104 -108
  84. package/dist/http/HttpClient.d.ts +2 -2
  85. package/dist/http/HttpClient.d.ts.map +1 -1
  86. package/dist/http/HttpController.d.ts +2 -3
  87. package/dist/http/HttpController.d.ts.map +1 -1
  88. package/dist/http/HttpSchemas.d.ts +13 -0
  89. package/dist/http/HttpSchemas.d.ts.map +1 -0
  90. package/dist/http/HttpSchemas.js +23 -0
  91. package/dist/http/MultipartHttpRequestBody.integration.test.js +31 -20
  92. package/dist/http/MultipartHttpRequestBody.unit.test.js +70 -53
  93. package/dist/record/Record.d.ts +3 -3
  94. package/dist/record/Record.d.ts.map +1 -1
  95. package/dist/record/Record.js +9 -30
  96. package/dist/result/Result.d.ts +3 -3
  97. package/dist/result/Result.d.ts.map +1 -1
  98. package/dist/result/Result.js +9 -26
  99. package/dist/schema/DateFromUnixTime.d.ts +4 -0
  100. package/dist/schema/DateFromUnixTime.d.ts.map +1 -0
  101. package/dist/schema/DateFromUnixTime.js +10 -0
  102. package/dist/schema/DateFromUnixTime.unit.test.d.ts +2 -0
  103. package/dist/schema/DateFromUnixTime.unit.test.d.ts.map +1 -0
  104. package/dist/schema/DateFromUnixTime.unit.test.js +11 -0
  105. package/dist/schema/JsonSchemaIntrospector.js +17 -7
  106. package/dist/sensitive/Sensitive.d.ts +7 -3
  107. package/dist/sensitive/Sensitive.d.ts.map +1 -1
  108. package/dist/sensitive/Sensitive.js +23 -39
  109. package/dist/sensitive/Sensitive.unit.test.d.ts +4 -4
  110. package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
  111. package/dist/sensitive/Sensitive.unit.test.js +20 -46
  112. package/dist/serialization/FormUrlEncodedSerialization.d.ts +2 -2
  113. package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -1
  114. package/dist/serialization/FormUrlEncodedSerialization.js +5 -28
  115. package/dist/serialization/JsonSerialization.d.ts +2 -2
  116. package/dist/serialization/JsonSerialization.d.ts.map +1 -1
  117. package/dist/serialization/JsonSerialization.js +5 -28
  118. package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -1
  119. package/dist/serialization/Serialization.abstract.test.js +6 -32
  120. package/dist/serialization/Serialization.d.ts +2 -2
  121. package/dist/serialization/Serialization.d.ts.map +1 -1
  122. package/dist/try/Try.d.ts +2 -2
  123. package/dist/try/Try.d.ts.map +1 -1
  124. package/dist/try/Try.js +2 -32
  125. package/dist/uuid/Uuid.d.ts +11 -10
  126. package/dist/uuid/Uuid.d.ts.map +1 -1
  127. package/dist/uuid/Uuid.js +13 -39
  128. package/dist/uuid/Uuid.unit.test.js +4 -27
  129. package/dist/zod/SchemaParser.abstract.test.d.ts.map +1 -1
  130. package/dist/zod/SchemaParser.abstract.test.js +6 -31
  131. package/dist/zod/SchemaParser.d.ts +2 -2
  132. package/dist/zod/SchemaParser.d.ts.map +1 -1
  133. package/dist/zod/ZodSchemaParser.d.ts +3 -4
  134. package/dist/zod/ZodSchemaParser.d.ts.map +1 -1
  135. package/dist/zod/ZodSchemaParser.js +4 -28
  136. package/dist/zod/ZodSchemaParser.unit.test.js +2 -25
  137. package/package.json +3 -8
  138. package/dist/http/HttpTypeDescriptors.d.ts +0 -11
  139. package/dist/http/HttpTypeDescriptors.d.ts.map +0 -1
  140. package/dist/http/HttpTypeDescriptors.js +0 -59
  141. package/dist/task/Task.d.ts +0 -19
  142. package/dist/task/Task.d.ts.map +0 -1
  143. package/dist/task/Task.js +0 -74
  144. package/dist/task/Task.unit.test.d.ts +0 -2
  145. package/dist/task/Task.unit.test.d.ts.map +0 -1
  146. 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 (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
- };
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.fileDescriptorDescriptor = exports.fileMetadataDescriptor = exports.FileContentTypeChecker = void 0;
27
- const t = __importStar(require("io-ts"));
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.fileMetadataDescriptor = t.intersection([
39
- t.type({
40
- name: t.string,
41
- }),
42
- t.partial({
43
- size: t.number,
44
- contentType: t.string,
45
- }),
46
- ]);
47
- exports.fileDescriptorDescriptor = t.type({
48
- _tag: t.literal('FileDescriptor'),
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
- exports.fileMetadataDescriptor.is(value.metadata));
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,gBAAiB,WAAW,SAiGvD,CAAC"}
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 E = __importStar(require("fp-ts/Either"));
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, O.none)();
55
- expect(writtenFile).toEqual(E.right(file));
56
- const sharedUrl = await fileStorage.getSharedUrl(file.reference.key)();
57
- expect(sharedUrl).toEqual(E.right(expect.objectContaining({
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 (E.isRight(sharedUrl)) {
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(E.right(expect.any(Number)));
67
- const read = await fileStorage.read(file.reference.key)();
68
- const readResponse = E.getOrElse(() => {
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
- })(read);
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 (E.isLeft(deserializedData)) {
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(E.right(undefined));
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 (E.isRight(read)) {
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 * as O from 'fp-ts/Option';
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?: O.Option<DynamicObject>): TE.TaskEither<Error, File>;
11
- read(key: string): TE.TaskEither<Error, File>;
12
- getSharedUrl(key: string): TE.TaskEither<Error, SharedUrl>;
13
- getSize(key: string): TE.TaskEither<Error, number>;
14
- delete(key: string): TE.TaskEither<Error, undefined>;
15
- createDirectory(key: string): TE.TaskEither<Error, undefined>;
16
- readDirectory(key: string): TE.TaskEither<Error, Dirent[]>;
17
- deleteDirectory(key: string): TE.TaskEither<Error, undefined>;
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":";AAGA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EACN,IAAI,EACJ,WAAW,EAEX,SAAS,EAET,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,qBAAa,iBAAkB,YAAW,WAAW;IACxC,OAAO,CAAC,QAAQ;gBAAR,QAAQ,GAAE,MAAe;IAE7C,KAAK,CACJ,IAAI,EAAE,IAAI,EACV,YAAY,GAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAU,GAC5C,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAkB7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAuB7C,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAW1D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,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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, O.none)();
53
- expect(writtenFile).toEqual(E.right(file));
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, O.some({ flag: 'a' }))();
70
- expect(appendedFile).toEqual(E.right(appendFile));
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 = E.getOrElse(() => {
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
- })(read);
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(E.right(undefined));
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(E.right(undefined));
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, O.none)();
110
- expect(writtenFile).toEqual(E.right(file));
111
- const readFolderResult = await fileStorage.readDirectory(folderName)();
112
- const contents = E.getOrElse(() => {
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
- })(readFolderResult);
90
+ });
115
91
  expect(contents.length).toEqual(1);
116
- const deleteFolderResult = await fileStorage.deleteDirectory(folderName)();
117
- expect(deleteFolderResult).toEqual(E.right(undefined));
118
- const readFolderResult2 = await fileStorage.readDirectory(folderName)();
119
- expect(readFolderResult2).toEqual(E.left(new Error("Error: ENOENT: no such file or directory, scandir '/tmp/folder'")));
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 (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
- };
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 TE = __importStar(require("fp-ts/lib/TaskEither"));
30
- const function_1 = require("fp-ts/lib/function");
31
- const O = __importStar(require("fp-ts/Option"));
32
- const Task_1 = require("../task/Task");
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 = O.none) {
50
+ write(file, writeOptions = effect_1.Option.none()) {
39
51
  const filePath = `${this.basePath}/${file.reference.key}`;
40
- const uploadOptions = O.toNullable(writeOptions);
41
- const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.writeFile(filePath, file.content, uploadOptions?.flag ? { flag: uploadOptions.flag } : {}));
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 TE.tryCatch(async () => {
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
- }, (reason) => new Error(String(reason)));
71
+ });
61
72
  }
62
73
  getSharedUrl(key) {
63
74
  const filePath = `${this.basePath}/${key}`;
64
- return TE.tryCatch(async () => ({
75
+ return attempt(async () => ({
65
76
  url: path.resolve(filePath),
66
- }), (reason) => new Error(String(reason)));
77
+ }));
67
78
  }
68
79
  getSize(key) {
69
80
  const filePath = `${this.basePath}/${key}`;
70
- return TE.tryCatch(async () => {
81
+ return attempt(async () => {
71
82
  const stat = await fs.stat(filePath);
72
83
  return stat.size;
73
- }, (reason) => new Error(String(reason)));
84
+ });
74
85
  }
75
86
  delete(key) {
76
87
  const filePath = `${this.basePath}/${key}`;
77
- const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.unlink(filePath));
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
- const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.mkdir(dirPath, { recursive: true }));
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 TE.tryCatch(async () => {
96
+ return attempt(async () => {
88
97
  const files = await fs.readdir(dirPath, { withFileTypes: true });
89
98
  return files;
90
- }, (reason) => new Error(String(reason)));
99
+ });
91
100
  }
92
101
  deleteDirectory(key) {
93
102
  const dirPath = `${this.basePath}/${key}`;
94
- const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.rm(dirPath, { recursive: true, force: true }));
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;
@@ -1,6 +1,4 @@
1
- /// <reference types="node" />
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) => TE.TaskEither<Error, MultipartHttpRequestBody>;
18
+ create: (value: unknown, fileStorage: FileStorage) => Effect.Effect<MultipartHttpRequestBody, Error>;
21
19
  }
22
20
  export declare const MultipartHttpRequestBody: {
23
- create: (value: unknown, fileStorage: FileStorage) => TE.TaskEither<Error, MultipartHttpRequestBody>;
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: O.Option<HttpCertificate>;
29
+ certificate: Option.Option<HttpCertificate>;
32
30
  };
33
31
  export type HeaderOptions = {
34
- preserveHeaderCasing: O.Option<boolean>;
32
+ preserveHeaderCasing: Option.Option<boolean>;
35
33
  };
36
34
  export type HttpRequest = {
37
35
  headers: HttpHeaders;
38
- headerOptions: O.Option<HeaderOptions>;
36
+ headerOptions: Option.Option<HeaderOptions>;
39
37
  pathParams: Record<string, string>;
40
38
  queryString: HttpQueryString;
41
39
  body: HttpRequestBody;
42
- agent: O.Option<HttpAgent>;
43
- clientIp: O.Option<string>;
44
- timeout?: O.Option<number>;
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) => O.Option<HttpHeaderValue>;
83
- extractBearerToken: (headers: HttpHeaders) => O.Option<string>;
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
  }
@@ -1 +1 @@
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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 (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
- };
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 O = __importStar(require("fp-ts/lib/Option"));
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 O.fromNullable(lowerCasedHeaders[name.toLowerCase()]);
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 TE.left(Error('Multipart body must be an object'));
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 (0, function_1.pipe)(TE.sequenceArray(fileDescriptorPaths.map(({ path, descriptor }) => (0, function_1.pipe)(fileStorage.read(descriptor.key), TE.map((file) => ({
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
- }))))), TE.map((files) => {
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: O.none,
155
- agent: O.none,
156
- clientIp: O.none,
157
- timeout: O.none,
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) => (0, function_1.pipe)(getHeader(headers, HttpHeader.Authorization), O.chain((header) => header.toLowerCase().startsWith('bearer ')
164
- ? O.fromNullable(header.substring(7))
165
- : O.fromNullable(null))),
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;