@trayio/commons 5.35.0-unstable.fd7158a → 6.0.0

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 +10 -5
  2. package/dist/base64/Base64.d.ts.map +1 -1
  3. package/dist/base64/Base64.js +40 -8
  4. package/dist/base64/Base64.unit.test.js +27 -4
  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 +38 -25
  8. package/dist/buffer/BufferExtensions.unit.test.js +45 -22
  9. package/dist/callsite/CallSite.js +7 -17
  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 +25 -2
  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 +31 -5
  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 +26 -2
  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 +25 -2
  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 +25 -2
  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 +25 -2
  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 +25 -2
  33. package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +38 -15
  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 +25 -2
  37. package/dist/codec/TypeCodec.d.ts +8 -24
  38. package/dist/codec/TypeCodec.d.ts.map +1 -1
  39. package/dist/codec/TypeCodec.js +48 -40
  40. package/dist/codec/TypeCodec.unit.test.js +38 -12
  41. package/dist/dynamicschema/DynamicSchema.d.ts +12 -6
  42. package/dist/dynamicschema/DynamicSchema.d.ts.map +1 -1
  43. package/dist/dynamicschema/DynamicSchema.js +41 -18
  44. package/dist/dynamicschema/DynamicSchema.unit.test.js +75 -51
  45. package/dist/dynamictype/DynamicType.d.ts +20 -17
  46. package/dist/dynamictype/DynamicType.d.ts.map +1 -1
  47. package/dist/dynamictype/DynamicType.js +35 -48
  48. package/dist/file/FakeFileStorage.d.ts +8 -8
  49. package/dist/file/FakeFileStorage.d.ts.map +1 -1
  50. package/dist/file/FakeFileStorage.js +40 -16
  51. package/dist/file/File.d.ts +14 -10
  52. package/dist/file/File.d.ts.map +1 -1
  53. package/dist/file/File.js +24 -31
  54. package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
  55. package/dist/file/FileStorage.abstract.test.js +41 -18
  56. package/dist/file/NodeFsFileStorage.d.ts +11 -9
  57. package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
  58. package/dist/file/NodeFsFileStorage.integration.test.js +45 -21
  59. package/dist/file/NodeFsFileStorage.js +29 -37
  60. package/dist/http/Http.d.ts +13 -11
  61. package/dist/http/Http.d.ts.map +1 -1
  62. package/dist/http/Http.js +22 -30
  63. package/dist/http/Http.unit.test.js +26 -3
  64. package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
  65. package/dist/http/HttpClient.abstract.test.js +108 -104
  66. package/dist/http/HttpClient.d.ts +2 -2
  67. package/dist/http/HttpClient.d.ts.map +1 -1
  68. package/dist/http/HttpController.d.ts +3 -2
  69. package/dist/http/HttpController.d.ts.map +1 -1
  70. package/dist/http/HttpTypeDescriptors.d.ts +11 -0
  71. package/dist/http/HttpTypeDescriptors.d.ts.map +1 -0
  72. package/dist/http/HttpTypeDescriptors.js +59 -0
  73. package/dist/http/MultipartHttpRequestBody.integration.test.js +20 -31
  74. package/dist/http/MultipartHttpRequestBody.unit.test.js +53 -70
  75. package/dist/record/Record.d.ts +3 -3
  76. package/dist/record/Record.d.ts.map +1 -1
  77. package/dist/record/Record.js +30 -9
  78. package/dist/result/Result.d.ts +3 -3
  79. package/dist/result/Result.d.ts.map +1 -1
  80. package/dist/result/Result.js +26 -9
  81. package/dist/schema/JsonSchemaIntrospector.js +7 -17
  82. package/dist/sensitive/Sensitive.d.ts +3 -7
  83. package/dist/sensitive/Sensitive.d.ts.map +1 -1
  84. package/dist/sensitive/Sensitive.js +39 -23
  85. package/dist/sensitive/Sensitive.unit.test.d.ts +4 -4
  86. package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
  87. package/dist/sensitive/Sensitive.unit.test.js +46 -20
  88. package/dist/serialization/FormUrlEncodedSerialization.d.ts +2 -2
  89. package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -1
  90. package/dist/serialization/FormUrlEncodedSerialization.js +28 -5
  91. package/dist/serialization/JsonSerialization.d.ts +2 -2
  92. package/dist/serialization/JsonSerialization.d.ts.map +1 -1
  93. package/dist/serialization/JsonSerialization.js +28 -5
  94. package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -1
  95. package/dist/serialization/Serialization.abstract.test.js +32 -6
  96. package/dist/serialization/Serialization.d.ts +2 -2
  97. package/dist/serialization/Serialization.d.ts.map +1 -1
  98. package/dist/task/Task.d.ts +19 -0
  99. package/dist/task/Task.d.ts.map +1 -0
  100. package/dist/task/Task.js +74 -0
  101. package/dist/task/Task.unit.test.d.ts +2 -0
  102. package/dist/task/Task.unit.test.d.ts.map +1 -0
  103. package/dist/task/Task.unit.test.js +46 -0
  104. package/dist/try/Try.d.ts +2 -2
  105. package/dist/try/Try.d.ts.map +1 -1
  106. package/dist/try/Try.js +32 -2
  107. package/dist/uuid/Uuid.d.ts +10 -11
  108. package/dist/uuid/Uuid.d.ts.map +1 -1
  109. package/dist/uuid/Uuid.js +39 -13
  110. package/dist/uuid/Uuid.unit.test.js +27 -4
  111. package/dist/zod/SchemaParser.abstract.test.d.ts.map +1 -1
  112. package/dist/zod/SchemaParser.abstract.test.js +31 -6
  113. package/dist/zod/SchemaParser.d.ts +2 -2
  114. package/dist/zod/SchemaParser.d.ts.map +1 -1
  115. package/dist/zod/ZodSchemaParser.d.ts +4 -3
  116. package/dist/zod/ZodSchemaParser.d.ts.map +1 -1
  117. package/dist/zod/ZodSchemaParser.js +28 -4
  118. package/dist/zod/ZodSchemaParser.unit.test.js +25 -2
  119. package/package.json +9 -4
  120. package/dist/effect/EffectExtensions.d.ts +0 -29
  121. package/dist/effect/EffectExtensions.d.ts.map +0 -1
  122. package/dist/effect/EffectExtensions.js +0 -30
  123. package/dist/effect/EffectExtensions.unit.test.d.ts +0 -2
  124. package/dist/effect/EffectExtensions.unit.test.d.ts.map +0 -1
  125. package/dist/effect/EffectExtensions.unit.test.js +0 -59
  126. package/dist/effect/Interop.d.ts +0 -53
  127. package/dist/effect/Interop.d.ts.map +0 -1
  128. package/dist/effect/Interop.js +0 -56
  129. package/dist/effect/Interop.unit.test.d.ts +0 -2
  130. package/dist/effect/Interop.unit.test.d.ts.map +0 -1
  131. package/dist/effect/Interop.unit.test.js +0 -134
  132. package/dist/effect/SchemaExtensions.d.ts +0 -11
  133. package/dist/effect/SchemaExtensions.d.ts.map +0 -1
  134. package/dist/effect/SchemaExtensions.js +0 -7
  135. package/dist/effect/SchemaExtensions.unit.test.d.ts +0 -2
  136. package/dist/effect/SchemaExtensions.unit.test.d.ts.map +0 -1
  137. package/dist/effect/SchemaExtensions.unit.test.js +0 -29
  138. package/dist/http/HttpSchemas.d.ts +0 -13
  139. package/dist/http/HttpSchemas.d.ts.map +0 -1
  140. package/dist/http/HttpSchemas.js +0 -23
  141. package/dist/schema/DateFromUnixTime.d.ts +0 -4
  142. package/dist/schema/DateFromUnixTime.d.ts.map +0 -1
  143. package/dist/schema/DateFromUnixTime.js +0 -10
  144. package/dist/schema/DateFromUnixTime.unit.test.d.ts +0 -2
  145. package/dist/schema/DateFromUnixTime.unit.test.d.ts.map +0 -1
  146. package/dist/schema/DateFromUnixTime.unit.test.js +0 -11
package/dist/try/Try.js CHANGED
@@ -1,7 +1,37 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.tryToEither = void 0;
4
- const effect_1 = require("effect");
27
+ const E = __importStar(require("fp-ts/Either"));
5
28
  const Error_1 = require("../error/Error");
6
- const tryToEither = (block) => effect_1.Either.try({ try: block, catch: Error_1.castError });
29
+ const tryToEither = (block) => {
30
+ try {
31
+ return E.right(block());
32
+ }
33
+ catch (error) {
34
+ return E.left((0, Error_1.castError)(error));
35
+ }
36
+ };
7
37
  exports.tryToEither = tryToEither;
@@ -1,20 +1,19 @@
1
- import { Either, Schema } from 'effect';
1
+ import * as t from 'io-ts';
2
+ import * as E from 'fp-ts/Either';
2
3
  import { Codec } from '../codec/Codec';
3
- export declare const uuidSchema: Schema.brand<Schema.filter<typeof Schema.String>, "Uuid">;
4
- export type Uuid = typeof uuidSchema.Type;
4
+ declare const uuidTypeDescriptor: t.BrandC<t.StringC, UuidBrand>;
5
+ export type Uuid = t.TypeOf<typeof uuidTypeDescriptor>;
6
+ export interface UuidBrand {
7
+ readonly Uuid: unique symbol;
8
+ }
5
9
  export interface UuidInterface {
6
- schema: typeof uuidSchema;
10
+ typeDescriptor: t.BrandC<t.StringC, UuidBrand>;
7
11
  typeCodec: Codec<Uuid>;
8
- fromString: (value: string) => Either.Either<Uuid, Error>;
12
+ fromString: (value: string) => E.Either<Error, Uuid>;
9
13
  parseUuidUnsafe: (value: string) => Uuid;
10
14
  decodeBinary: (value: Uuid) => ArrayBuffer;
11
15
  randomUuid: () => Uuid;
12
16
  }
13
17
  export declare const Uuid: UuidInterface;
14
- /**
15
- * Drop-in for io-ts-types' `UUID`, which was both a codec and a branded string type. Same here: `UUID` is the schema
16
- * as a value and the branded string as a type, so `import { UUID } from 'io-ts-types'` only needs its source changed.
17
- */
18
- export declare const UUID: Schema.brand<Schema.filter<typeof Schema.String>, "Uuid">;
19
- export type UUID = Uuid;
18
+ export {};
20
19
  //# sourceMappingURL=Uuid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Uuid.d.ts","sourceRoot":"","sources":["../../src/uuid/Uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,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AAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrD,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,YAAY,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,WAAW,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,eAAO,MAAM,IAAI,EAAE,aAoBlB,CAAC"}
package/dist/uuid/Uuid.js CHANGED
@@ -1,26 +1,52 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UUID = exports.Uuid = exports.uuidSchema = void 0;
4
- const effect_1 = require("effect");
26
+ exports.Uuid = void 0;
27
+ const t = __importStar(require("io-ts"));
28
+ const E = __importStar(require("fp-ts/Either"));
5
29
  const crypto_1 = require("crypto");
6
30
  const TypeCodec_1 = require("../codec/TypeCodec");
7
- const BufferExtensions_1 = require("../buffer/BufferExtensions");
8
31
  const isUuid = (s) => {
9
32
  const exp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
33
  return exp.test(s);
11
34
  };
12
- exports.uuidSchema = effect_1.Schema.String.pipe(effect_1.Schema.filter(isUuid, { message: () => 'Invalid Uuid' }), effect_1.Schema.brand('Uuid')).annotations({ identifier: 'Uuid' });
13
- const uuidTypeCodec = TypeCodec_1.TypeCodec.fromSchema(exports.uuidSchema);
35
+ const uuidTypeDescriptor = t.brand(t.string, (input) => isUuid(input), 'Uuid');
36
+ const uuidTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(uuidTypeDescriptor);
14
37
  exports.Uuid = {
15
- schema: exports.uuidSchema,
38
+ typeDescriptor: uuidTypeDescriptor,
16
39
  typeCodec: uuidTypeCodec,
17
40
  fromString: (value) => uuidTypeCodec.decode(value),
18
- parseUuidUnsafe: (value) => effect_1.Either.getOrThrowWith(uuidTypeCodec.decode(value), () => new Error('String could not be parsed to Uuid')),
19
- decodeBinary: (value) => BufferExtensions_1.BufferExtensions.toArrayBuffer(Buffer.from(uuidTypeCodec.encode(value), 'utf-8')),
41
+ parseUuidUnsafe: (value) => {
42
+ const either = uuidTypeCodec.decode(value);
43
+ return E.getOrElse(() => {
44
+ throw new Error('String could not be parsed to Uuid');
45
+ })(either);
46
+ },
47
+ decodeBinary: (value) => {
48
+ const binary = Buffer.from(uuidTypeCodec.encode(value), 'utf-8');
49
+ return binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
50
+ },
20
51
  randomUuid: () => exports.Uuid.parseUuidUnsafe((0, crypto_1.randomUUID)()),
21
52
  };
22
- /**
23
- * Drop-in for io-ts-types' `UUID`, which was both a codec and a branded string type. Same here: `UUID` is the schema
24
- * as a value and the branded string as a type, so `import { UUID } from 'io-ts-types'` only needs its source changed.
25
- */
26
- exports.UUID = exports.uuidSchema;
@@ -1,20 +1,43 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const effect_1 = require("effect");
26
+ const E = __importStar(require("fp-ts/Either"));
4
27
  const Uuid_1 = require("./Uuid");
5
28
  describe('Uuid', () => {
6
29
  test('should create uuid type for valid string', () => {
7
30
  const testValue = '3fa04423-4a2c-462f-8032-8cdd6f1cd5cd';
8
31
  const uuidResult = Uuid_1.Uuid.fromString(testValue);
9
- const uuid = effect_1.Either.getOrElse(uuidResult, (error) => {
32
+ const uuid = E.getOrElse((error) => {
10
33
  throw new Error('This is not a valid UUID');
11
- });
34
+ })(uuidResult);
12
35
  expect(uuid.toString()).toStrictEqual(testValue);
13
36
  });
14
37
  test('should fail when string is invalid', () => {
15
38
  const testValue = 'some-invalid-uuid';
16
39
  const uuidResult = Uuid_1.Uuid.fromString(testValue);
17
- expect(effect_1.Either.isLeft(uuidResult)).toBe(true);
40
+ expect(E.isLeft(uuidResult)).toBe(true);
18
41
  });
19
42
  test('should generate a random and unique UUIDs', () => {
20
43
  const uuids = [...Array(20).keys()].map(() => Uuid_1.Uuid.randomUuid());
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaParser.abstract.test.d.ts","sourceRoot":"","sources":["../../src/zod/SchemaParser.abstract.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,QAAQ,CAAC,QAkEtE"}
1
+ {"version":3,"file":"SchemaParser.abstract.test.d.ts","sourceRoot":"","sources":["../../src/zod/SchemaParser.abstract.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,QAAQ,CAAC,QAkEtE"}
@@ -1,7 +1,31 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.testSchemaParser = testSchemaParser;
4
- const effect_1 = require("effect");
26
+ exports.testSchemaParser = void 0;
27
+ const E = __importStar(require("fp-ts/Either"));
28
+ const O = __importStar(require("fp-ts/Option"));
5
29
  function testSchemaParser(testTypeParser) {
6
30
  describe('Schema Parser', () => {
7
31
  test('should parse a schema', () => {
@@ -11,10 +35,10 @@ function testSchemaParser(testTypeParser) {
11
35
  };
12
36
  const parsedOutput = {
13
37
  strField: 'str',
14
- intField: effect_1.Option.some(123),
38
+ intField: O.some(123),
15
39
  };
16
40
  const result = testTypeParser.parse(testValue);
17
- expect(result).toStrictEqual(effect_1.Either.right(parsedOutput));
41
+ expect(result).toStrictEqual(E.right(parsedOutput));
18
42
  });
19
43
  test('should parse a schema with optional field', () => {
20
44
  const testValue = {
@@ -22,10 +46,10 @@ function testSchemaParser(testTypeParser) {
22
46
  };
23
47
  const parsedOutput = {
24
48
  strField: 'str',
25
- intField: effect_1.Option.none(),
49
+ intField: O.none,
26
50
  };
27
51
  const result = testTypeParser.parse(testValue);
28
- expect(result).toStrictEqual(effect_1.Either.right(parsedOutput));
52
+ expect(result).toStrictEqual(E.right(parsedOutput));
29
53
  });
30
54
  test('should fail to parse a schema with invalid type', () => {
31
55
  const testValue = {
@@ -53,3 +77,4 @@ function testSchemaParser(testTypeParser) {
53
77
  });
54
78
  });
55
79
  }
80
+ exports.testSchemaParser = testSchemaParser;
@@ -1,5 +1,5 @@
1
- import { Either } from 'effect';
1
+ import * as E from 'fp-ts/Either';
2
2
  export interface SchemaParser<T> {
3
- parse(value: unknown): Either.Either<T, Error>;
3
+ parse(value: unknown): E.Either<Error, T>;
4
4
  }
5
5
  //# sourceMappingURL=SchemaParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaParser.d.ts","sourceRoot":"","sources":["../../src/zod/SchemaParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;CAC/C"}
1
+ {"version":3,"file":"SchemaParser.d.ts","sourceRoot":"","sources":["../../src/zod/SchemaParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC1C"}
@@ -1,12 +1,13 @@
1
1
  import { z, ZodSchema } from 'zod';
2
- import { Either, Option } from 'effect';
2
+ import * as E from 'fp-ts/Either';
3
+ import { Option } from 'fp-ts/Option';
3
4
  import { SchemaParser } from './SchemaParser';
4
- export declare const zodOptionFromNullable: <T>(schema: z.ZodType<T, any, any>) => z.ZodType<Option.Option<T>, any, any>;
5
+ export declare const zodOptionFromNullable: <T>(schema: z.ZodType<T, any, any>) => z.ZodType<Option<T>, any, any>;
5
6
  export declare class ZodSchemaParser<T> implements SchemaParser<T> {
6
7
  private readonly schema;
7
8
  constructor(schema: ZodSchema<T>);
8
9
  static fromSchema<T>(schema: ZodSchema): SchemaParser<T>;
9
- parse(value: unknown): Either.Either<T, Error>;
10
+ parse(value: unknown): E.Either<Error, T>;
10
11
  private errorTransformer;
11
12
  }
12
13
  //# sourceMappingURL=ZodSchemaParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ZodSchemaParser.d.ts","sourceRoot":"","sources":["../../src/zod/ZodSchemaParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAsB,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,qBAAqB,GAAI,CAAC,EACtC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAC5B,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAKpC,CAAC;AAEJ,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,YAAY,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAEjD,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC;IAIxD,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC;IAO9C,OAAO,CAAC,gBAAgB;CAmCxB"}
1
+ {"version":3,"file":"ZodSchemaParser.d.ts","sourceRoot":"","sources":["../../src/zod/ZodSchemaParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAsB,MAAM,KAAK,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,MAAM,EAAc,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,qBAAqB,uEAKiC,CAAC;AAEpE,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,YAAY,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAEjD,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC;IAIxD,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAOzC,OAAO,CAAC,gBAAgB;CAsCxB"}
@@ -1,10 +1,34 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.ZodSchemaParser = exports.zodOptionFromNullable = void 0;
4
- const effect_1 = require("effect");
27
+ const E = __importStar(require("fp-ts/Either"));
28
+ const Option_1 = require("fp-ts/Option");
5
29
  const zodOptionFromNullable = (schema) => schema
6
30
  .optional()
7
- .transform((value) => value === undefined ? effect_1.Option.none() : effect_1.Option.some(value));
31
+ .transform((value) => (value === undefined ? Option_1.none : (0, Option_1.some)(value)));
8
32
  exports.zodOptionFromNullable = zodOptionFromNullable;
9
33
  class ZodSchemaParser {
10
34
  schema;
@@ -17,8 +41,8 @@ class ZodSchemaParser {
17
41
  parse(value) {
18
42
  const parseResult = this.schema.safeParse(value);
19
43
  return parseResult.success
20
- ? effect_1.Either.right(parseResult.data)
21
- : effect_1.Either.left(this.errorTransformer(parseResult.error));
44
+ ? E.right(parseResult.data)
45
+ : E.left(this.errorTransformer(parseResult.error));
22
46
  }
23
47
  errorTransformer(zodError) {
24
48
  let errorString = '';
@@ -1,6 +1,29 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const effect_1 = require("effect");
26
+ const E = __importStar(require("fp-ts/Either"));
4
27
  const zod_1 = require("zod");
5
28
  const SchemaParser_abstract_test_1 = require("./SchemaParser.abstract.test");
6
29
  const ZodSchemaParser_1 = require("./ZodSchemaParser");
@@ -18,6 +41,6 @@ describe('Zod Schema Parser', () => {
18
41
  intField: '123',
19
42
  };
20
43
  const result = ZodSchemaParser_1.ZodSchemaParser.fromSchema(TestSchema).parse(testValue);
21
- expect(result).toStrictEqual(effect_1.Either.left(new Error('1. invalid_type at intField: Expected number, received string')));
44
+ expect(result).toStrictEqual(E.left(new Error('1. invalid_type at intField: Invalid input: expected number, received string')));
22
45
  });
23
46
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/commons",
3
- "version": "5.35.0-unstable.fd7158a",
3
+ "version": "6.0.0",
4
4
  "description": "Extensions to the standard/core libraries and basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -16,21 +16,26 @@
16
16
  "dependencies": {
17
17
  "@types/formidable": "3.4.5",
18
18
  "@types/mime-types": "2.1.4",
19
- "@types/node": "18.19.130",
19
+ "@types/node": "18.11.9",
20
20
  "@types/uuid": "9.0.2",
21
21
  "ajv": "8.12.0",
22
22
  "ajv-draft-04": "1.0.0",
23
23
  "ajv-formats": "2.1.1",
24
24
  "deep-copy-ts": "0.5.4",
25
- "effect": "3.22.2",
26
25
  "formidable": "3.5.1",
26
+ "fp-ts": "2.12.3",
27
27
  "fs-extra": "11.3.4",
28
28
  "generate-schema": "2.6.0",
29
+ "io-ts": "2.2.20",
30
+ "io-ts-reporters": "2.0.1",
31
+ "io-ts-types": "0.5.19",
29
32
  "lodash": "4.18.1",
30
33
  "mime-types": "2.1.35",
34
+ "monocle-ts": "2.3.13",
35
+ "newtype-ts": "0.3.5",
31
36
  "qs": "6.13.0",
32
37
  "uuid": "9.0.0",
33
- "zod": "3.23.5"
38
+ "zod": "4.6.5"
34
39
  },
35
40
  "typesVersions": {
36
41
  "*": {
@@ -1,29 +0,0 @@
1
- import { Effect, Either } from 'effect';
2
- /**
3
- * Small helpers on top of Effect for the patterns the codebase used with fp-ts Task / TaskEither.
4
- * Everything here is plain Effect; nothing requires a runtime layer.
5
- */
6
- export interface EffectExtensionsInterface {
7
- /** Wraps a promise-returning block; any rejection becomes an `Error` (strings and objects are coerced). */
8
- tryPromiseWithSimpleError: <T>(block: () => Promise<T>) => Effect.Effect<T, Error>;
9
- /** Wraps a synchronous block; anything thrown becomes an `Error`. */
10
- tryWithSimpleError: <T>(block: () => T) => Effect.Effect<T, Error>;
11
- /**
12
- * Runs the effect. A typed failure rejects with the failure value itself and a defect rejects with the
13
- * thrown value, so callers see the same errors they would have seen from the equivalent promise code.
14
- */
15
- runToPromise: <T, E>(effect: Effect.Effect<T, E>) => Promise<T>;
16
- /** Recovers from both typed failures and defects with a plain value. */
17
- recover: <T, E>(effect: Effect.Effect<T, E>, onError: (error: Error) => T) => Effect.Effect<T>;
18
- /**
19
- * Runs `first`, then feeds each result to `next`: a Right continues the loop with the returned effect,
20
- * a Left ends it with the final result.
21
- *
22
- * Left means "stop", not "error": the loop reuses `Either` as a two-way control-flow signal, the same
23
- * convention as `Effect.loop`/`Effect.iterate`'s predecessors in fp-ts (`chainRec`). Failures travel in the
24
- * effect's error channel as usual.
25
- */
26
- loop: <Interstitial, Final, E>(first: Effect.Effect<Interstitial, E>, next: (result: Interstitial) => Either.Either<Effect.Effect<Interstitial, E>, Final>) => Effect.Effect<Final, E>;
27
- }
28
- export declare const EffectExtensions: EffectExtensionsInterface;
29
- //# sourceMappingURL=EffectExtensions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EffectExtensions.d.ts","sourceRoot":"","sources":["../../src/effect/EffectExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,EAAQ,MAAM,QAAQ,CAAC;AAGrD;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACzC,2GAA2G;IAC3G,yBAAyB,EAAE,CAAC,CAAC,EAC5B,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7B,qEAAqE;IACrE,kBAAkB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACnE;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAChE,wEAAwE;IACxE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,KACxB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtB;;;;;;;OAOG;IACH,IAAI,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,EAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,EACrC,IAAI,EAAE,CACL,MAAM,EAAE,YAAY,KAChB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,KACrD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B;AAED,eAAO,MAAM,gBAAgB,EAAE,yBA4C9B,CAAC"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EffectExtensions = void 0;
4
- const effect_1 = require("effect");
5
- const Error_1 = require("../error/Error");
6
- exports.EffectExtensions = {
7
- tryPromiseWithSimpleError: (block) => effect_1.Effect.tryPromise({ try: block, catch: Error_1.castError }),
8
- tryWithSimpleError: (block) => effect_1.Effect.try({ try: block, catch: Error_1.castError }),
9
- runToPromise: async (effect) => {
10
- const exit = await effect_1.Effect.runPromiseExit(effect);
11
- return effect_1.Exit.match(exit, {
12
- onSuccess: (value) => value,
13
- onFailure: (cause) => {
14
- throw effect_1.Cause.squash(cause);
15
- },
16
- });
17
- },
18
- recover: (effect, onError) => effect_1.Effect.catchAllCause(effect, (cause) => effect_1.Effect.succeed(onError((0, Error_1.castError)(effect_1.Cause.squash(cause))))),
19
- loop: (first, next) => effect_1.Effect.gen(function* loopUntilLeft() {
20
- let current = first;
21
- for (;;) {
22
- const result = yield* current;
23
- const step = next(result);
24
- if (effect_1.Either.isLeft(step)) {
25
- return step.left;
26
- }
27
- current = step.right;
28
- }
29
- }),
30
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=EffectExtensions.unit.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EffectExtensions.unit.test.d.ts","sourceRoot":"","sources":["../../src/effect/EffectExtensions.unit.test.ts"],"names":[],"mappings":""}
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const effect_1 = require("effect");
4
- const EffectExtensions_1 = require("./EffectExtensions");
5
- describe('EffectExtensions', () => {
6
- describe('runToPromise', () => {
7
- test('resolves with the success value', async () => {
8
- const value = { id: 42 };
9
- await expect(EffectExtensions_1.EffectExtensions.runToPromise(effect_1.Effect.succeed(value))).resolves.toBe(value);
10
- });
11
- test('rejects with the original failure object, not a wrapper', async () => {
12
- const failure = { tag: 'not_found', status: 404 };
13
- await expect(EffectExtensions_1.EffectExtensions.runToPromise(effect_1.Effect.fail(failure))).rejects.toBe(failure);
14
- });
15
- test('rejects with the original string failure', async () => {
16
- await expect(EffectExtensions_1.EffectExtensions.runToPromise(effect_1.Effect.fail('boom'))).rejects.toBe('boom');
17
- });
18
- test('rejects with the thrown value on a defect', async () => {
19
- const defect = new Error('unexpected');
20
- await expect(EffectExtensions_1.EffectExtensions.runToPromise(effect_1.Effect.sync(() => {
21
- throw defect;
22
- }))).rejects.toBe(defect);
23
- });
24
- });
25
- describe('tryPromiseWithSimpleError', () => {
26
- test('coerces a rejected string into an Error', async () => {
27
- const result = await effect_1.Effect.runPromise(effect_1.Effect.either(EffectExtensions_1.EffectExtensions.tryPromiseWithSimpleError(() =>
28
- // eslint-disable-next-line prefer-promise-reject-errors
29
- Promise.reject('nope'))));
30
- expect(effect_1.Either.isLeft(result)).toBe(true);
31
- if (effect_1.Either.isLeft(result)) {
32
- expect(result.left).toBeInstanceOf(Error);
33
- expect(result.left.message).toBe('nope');
34
- }
35
- });
36
- });
37
- describe('recover', () => {
38
- test('recovers from a typed failure and from a defect', async () => {
39
- const fromFailure = await effect_1.Effect.runPromise(EffectExtensions_1.EffectExtensions.recover(effect_1.Effect.fail(new Error('x')), (e) => e.message));
40
- const fromDefect = await effect_1.Effect.runPromise(EffectExtensions_1.EffectExtensions.recover(effect_1.Effect.sync(() => {
41
- throw new Error('y');
42
- }), (e) => e.message));
43
- expect([fromFailure, fromDefect]).toEqual(['x', 'y']);
44
- });
45
- });
46
- describe('loop', () => {
47
- test('keeps running while next returns Right and ends with the Left value', async () => {
48
- const seen = [];
49
- const result = await effect_1.Effect.runPromise(EffectExtensions_1.EffectExtensions.loop(effect_1.Effect.succeed(1), (n) => {
50
- seen.push(n);
51
- return n >= 3
52
- ? effect_1.Either.left(`done at ${n}`)
53
- : effect_1.Either.right(effect_1.Effect.succeed(n + 1));
54
- }));
55
- expect(result).toBe('done at 3');
56
- expect(seen).toEqual([1, 2, 3]);
57
- });
58
- });
59
- });
@@ -1,53 +0,0 @@
1
- import { Effect, Either, Option, Schema } from 'effect';
2
- import { Codec } from '../codec/Codec';
3
- /**
4
- * Bridges to code that still speaks fp-ts / io-ts. The shapes are declared structurally so this module has no
5
- * dependency on either library: fp-ts values satisfy these types as they are.
6
- *
7
- * Intended for consumers migrating a module at a time. New code should not need anything in here.
8
- */
9
- export type FpNone = {
10
- readonly _tag: 'None';
11
- };
12
- export type FpSome<A> = {
13
- readonly _tag: 'Some';
14
- readonly value: A;
15
- };
16
- export type FpOption<A> = FpNone | FpSome<A>;
17
- export type FpLeft<E> = {
18
- readonly _tag: 'Left';
19
- readonly left: E;
20
- };
21
- export type FpRight<A> = {
22
- readonly _tag: 'Right';
23
- readonly right: A;
24
- };
25
- export type FpEither<E, A> = FpLeft<E> | FpRight<A>;
26
- export type FpTask<A> = () => Promise<A>;
27
- export type FpTaskEither<E, A> = () => Promise<FpEither<E, A>>;
28
- /** The parts of an io-ts `Type<A, O, unknown>` this module needs. */
29
- export interface IoTsTypeLike<A> {
30
- readonly name: string;
31
- is(u: unknown): u is A;
32
- decode(u: unknown): FpEither<ReadonlyArray<{
33
- readonly message?: string;
34
- readonly value: unknown;
35
- readonly context: ReadonlyArray<{
36
- readonly key: string;
37
- }>;
38
- }>, A>;
39
- encode(a: A): unknown;
40
- }
41
- export declare const fromFpOption: <A>(option: FpOption<A>) => Option.Option<A>;
42
- export declare const toFpOption: <A>(option: Option.Option<A>) => FpOption<A>;
43
- export declare const fromFpEither: <E, A>(either: FpEither<E, A>) => Either.Either<A, E>;
44
- export declare const toFpEither: <E, A>(either: Either.Either<A, E>) => FpEither<E, A>;
45
- export declare const fromTask: <A>(task: FpTask<A>) => Effect.Effect<A>;
46
- export declare const toTask: <A>(effect: Effect.Effect<A>) => FpTask<A>;
47
- export declare const fromTaskEither: <E, A>(taskEither: FpTaskEither<E, A>) => Effect.Effect<A, E>;
48
- export declare const toTaskEither: <E, A>(effect: Effect.Effect<A, E>) => FpTaskEither<E, A>;
49
- /** An Effect Schema that decodes and encodes through an existing io-ts type. */
50
- export declare const schemaFromIoTs: <A>(type: IoTsTypeLike<A>) => Schema.Schema<A, unknown>;
51
- /** A Codec backed by an existing io-ts type. */
52
- export declare const codecFromIoTs: <A>(type: IoTsTypeLike<A>) => Codec<A>;
53
- //# sourceMappingURL=Interop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Interop.d.ts","sourceRoot":"","sources":["../../src/effect/Interop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE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