@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
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EffectExtensions.unit.test.d.ts","sourceRoot":"","sources":["../../src/effect/EffectExtensions.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interop.d.ts","sourceRoot":"","sources":["../../src/effect/Interop.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codecFromIoTs = exports.schemaFromIoTs = exports.toTaskEither = exports.fromTaskEither = exports.toTask = exports.fromTask = exports.toFpEither = exports.fromFpEither = exports.toFpOption = exports.fromFpOption = void 0;
|
|
4
|
+
const effect_1 = require("effect");
|
|
5
|
+
const fromFpOption = (option) => option._tag === 'Some' ? effect_1.Option.some(option.value) : effect_1.Option.none();
|
|
6
|
+
exports.fromFpOption = fromFpOption;
|
|
7
|
+
const toFpOption = (option) => effect_1.Option.match(option, {
|
|
8
|
+
onNone: () => ({ _tag: 'None' }),
|
|
9
|
+
onSome: (value) => ({ _tag: 'Some', value }),
|
|
10
|
+
});
|
|
11
|
+
exports.toFpOption = toFpOption;
|
|
12
|
+
const fromFpEither = (either) => either._tag === 'Right'
|
|
13
|
+
? effect_1.Either.right(either.right)
|
|
14
|
+
: effect_1.Either.left(either.left);
|
|
15
|
+
exports.fromFpEither = fromFpEither;
|
|
16
|
+
const toFpEither = (either) => effect_1.Either.match(either, {
|
|
17
|
+
onLeft: (left) => ({ _tag: 'Left', left }),
|
|
18
|
+
onRight: (right) => ({ _tag: 'Right', right }),
|
|
19
|
+
});
|
|
20
|
+
exports.toFpEither = toFpEither;
|
|
21
|
+
const fromTask = (task) => effect_1.Effect.promise(task);
|
|
22
|
+
exports.fromTask = fromTask;
|
|
23
|
+
const toTask = (effect) => () => effect_1.Effect.runPromise(effect);
|
|
24
|
+
exports.toTask = toTask;
|
|
25
|
+
const fromTaskEither = (taskEither) => effect_1.Effect.flatMap(effect_1.Effect.promise(taskEither), exports.fromFpEither);
|
|
26
|
+
exports.fromTaskEither = fromTaskEither;
|
|
27
|
+
const toTaskEither = (effect) => () => effect_1.Effect.runPromise(effect_1.Effect.either(effect)).then(exports.toFpEither);
|
|
28
|
+
exports.toTaskEither = toTaskEither;
|
|
29
|
+
const formatIoTsErrors = (errors) => errors
|
|
30
|
+
.map((error) => {
|
|
31
|
+
const path = error.context
|
|
32
|
+
.map((c) => c.key)
|
|
33
|
+
.filter((key) => key !== '')
|
|
34
|
+
.join('.');
|
|
35
|
+
const message = error.message ?? `Invalid value ${JSON.stringify(error.value)}`;
|
|
36
|
+
return path ? `${path}: ${message}` : message;
|
|
37
|
+
})
|
|
38
|
+
.join(', ');
|
|
39
|
+
/** An Effect Schema that decodes and encodes through an existing io-ts type. */
|
|
40
|
+
const schemaFromIoTs = (type) => effect_1.Schema.transformOrFail(effect_1.Schema.Unknown, effect_1.Schema.declare((u) => type.is(u), {
|
|
41
|
+
identifier: type.name,
|
|
42
|
+
}), {
|
|
43
|
+
strict: true,
|
|
44
|
+
decode: (input, _options, ast) => effect_1.Either.match((0, exports.fromFpEither)(type.decode(input)), {
|
|
45
|
+
onLeft: (errors) => effect_1.ParseResult.fail(new effect_1.ParseResult.Type(ast, input, formatIoTsErrors(errors))),
|
|
46
|
+
onRight: (value) => effect_1.ParseResult.succeed(value),
|
|
47
|
+
}),
|
|
48
|
+
encode: (value) => effect_1.ParseResult.succeed(type.encode(value)),
|
|
49
|
+
}).annotations({ identifier: type.name });
|
|
50
|
+
exports.schemaFromIoTs = schemaFromIoTs;
|
|
51
|
+
/** A Codec backed by an existing io-ts type. */
|
|
52
|
+
const codecFromIoTs = (type) => ({
|
|
53
|
+
encode: (value) => type.encode(value),
|
|
54
|
+
decode: (value) => effect_1.Either.mapLeft((0, exports.fromFpEither)(type.decode(value)), (errors) => new Error(formatIoTsErrors(errors))),
|
|
55
|
+
});
|
|
56
|
+
exports.codecFromIoTs = codecFromIoTs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interop.unit.test.d.ts","sourceRoot":"","sources":["../../src/effect/Interop.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const effect_1 = require("effect");
|
|
4
|
+
const Interop_1 = require("./Interop");
|
|
5
|
+
const isPerson = (u) => typeof u === 'object' &&
|
|
6
|
+
u !== null &&
|
|
7
|
+
typeof u.name === 'string' &&
|
|
8
|
+
typeof u.age === 'number';
|
|
9
|
+
/** Behaves like `t.type({ name: t.string, age: t.number }, 'Person')`, including io-ts' error shape. */
|
|
10
|
+
const personType = {
|
|
11
|
+
name: 'Person',
|
|
12
|
+
is: isPerson,
|
|
13
|
+
decode: (u) => isPerson(u)
|
|
14
|
+
? { _tag: 'Right', right: u }
|
|
15
|
+
: {
|
|
16
|
+
_tag: 'Left',
|
|
17
|
+
left: [
|
|
18
|
+
{
|
|
19
|
+
value: u,
|
|
20
|
+
context: [{ key: '' }, { key: 'age' }],
|
|
21
|
+
message: 'expected a number',
|
|
22
|
+
},
|
|
23
|
+
{ value: u, context: [{ key: '' }, { key: 'name' }] },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
encode: (person) => ({ ...person, encoded: true }),
|
|
27
|
+
};
|
|
28
|
+
describe('Interop', () => {
|
|
29
|
+
describe('Option', () => {
|
|
30
|
+
it('converts fp-ts Some and None to Effect options', () => {
|
|
31
|
+
expect((0, Interop_1.fromFpOption)({ _tag: 'Some', value: 1 })).toEqual(effect_1.Option.some(1));
|
|
32
|
+
expect((0, Interop_1.fromFpOption)({ _tag: 'None' })).toEqual(effect_1.Option.none());
|
|
33
|
+
});
|
|
34
|
+
it('converts Effect options to plain fp-ts shapes', () => {
|
|
35
|
+
expect((0, Interop_1.toFpOption)(effect_1.Option.some(1))).toStrictEqual({
|
|
36
|
+
_tag: 'Some',
|
|
37
|
+
value: 1,
|
|
38
|
+
});
|
|
39
|
+
expect((0, Interop_1.toFpOption)(effect_1.Option.none())).toStrictEqual({ _tag: 'None' });
|
|
40
|
+
});
|
|
41
|
+
it('round trips', () => {
|
|
42
|
+
expect((0, Interop_1.toFpOption)((0, Interop_1.fromFpOption)({ _tag: 'Some', value: 'x' }))).toStrictEqual({ _tag: 'Some', value: 'x' });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('Either', () => {
|
|
46
|
+
it('converts fp-ts Right and Left, swapping the type parameter order', () => {
|
|
47
|
+
expect((0, Interop_1.fromFpEither)({ _tag: 'Right', right: 1 })).toEqual(effect_1.Either.right(1));
|
|
48
|
+
expect((0, Interop_1.fromFpEither)({ _tag: 'Left', left: 'boom' })).toEqual(effect_1.Either.left('boom'));
|
|
49
|
+
});
|
|
50
|
+
it('converts Effect eithers to plain fp-ts shapes', () => {
|
|
51
|
+
expect((0, Interop_1.toFpEither)(effect_1.Either.right(1))).toStrictEqual({
|
|
52
|
+
_tag: 'Right',
|
|
53
|
+
right: 1,
|
|
54
|
+
});
|
|
55
|
+
expect((0, Interop_1.toFpEither)(effect_1.Either.left('boom'))).toStrictEqual({
|
|
56
|
+
_tag: 'Left',
|
|
57
|
+
left: 'boom',
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('Task and TaskEither', () => {
|
|
62
|
+
it('runs an fp-ts Task as an effect', async () => {
|
|
63
|
+
expect(await effect_1.Effect.runPromise((0, Interop_1.fromTask)(async () => 42))).toEqual(42);
|
|
64
|
+
});
|
|
65
|
+
it('exposes an effect as an fp-ts Task', async () => {
|
|
66
|
+
expect(await (0, Interop_1.toTask)(effect_1.Effect.succeed(42))()).toEqual(42);
|
|
67
|
+
});
|
|
68
|
+
it('lifts a TaskEither success and failure into the effect channels', async () => {
|
|
69
|
+
const success = { _tag: 'Right', right: 1 };
|
|
70
|
+
const failure = { _tag: 'Left', left: 'boom' };
|
|
71
|
+
expect(await effect_1.Effect.runPromise(effect_1.Effect.either((0, Interop_1.fromTaskEither)(async () => success)))).toEqual(effect_1.Either.right(1));
|
|
72
|
+
expect(await effect_1.Effect.runPromise(effect_1.Effect.either((0, Interop_1.fromTaskEither)(async () => failure)))).toEqual(effect_1.Either.left('boom'));
|
|
73
|
+
});
|
|
74
|
+
it('exposes an effect as a TaskEither that never rejects on typed failures', async () => {
|
|
75
|
+
expect(await (0, Interop_1.toTaskEither)(effect_1.Effect.succeed(1))()).toStrictEqual({
|
|
76
|
+
_tag: 'Right',
|
|
77
|
+
right: 1,
|
|
78
|
+
});
|
|
79
|
+
expect(await (0, Interop_1.toTaskEither)(effect_1.Effect.fail('boom'))()).toStrictEqual({
|
|
80
|
+
_tag: 'Left',
|
|
81
|
+
left: 'boom',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('schemaFromIoTs', () => {
|
|
86
|
+
const schema = (0, Interop_1.schemaFromIoTs)(personType);
|
|
87
|
+
const decode = effect_1.Schema.decodeUnknownEither(schema);
|
|
88
|
+
it('decodes through the io-ts type', () => {
|
|
89
|
+
expect(decode({ name: 'Ada', age: 36 })).toEqual(effect_1.Either.right({ name: 'Ada', age: 36 }));
|
|
90
|
+
});
|
|
91
|
+
it('reports io-ts errors as a parse error with the io-ts-reporters style message', () => {
|
|
92
|
+
const result = decode({ name: 'Ada' });
|
|
93
|
+
expect(effect_1.Either.isLeft(result)).toBe(true);
|
|
94
|
+
const message = effect_1.Either.match(result, {
|
|
95
|
+
onLeft: (error) => error.message,
|
|
96
|
+
onRight: () => '',
|
|
97
|
+
});
|
|
98
|
+
expect(message).toContain('age: expected a number');
|
|
99
|
+
expect(message).toContain('name: Invalid value {"name":"Ada"}');
|
|
100
|
+
});
|
|
101
|
+
it('encodes through the io-ts type', () => {
|
|
102
|
+
expect(effect_1.Schema.encodeSync(schema)({ name: 'Ada', age: 36 })).toEqual({
|
|
103
|
+
name: 'Ada',
|
|
104
|
+
age: 36,
|
|
105
|
+
encoded: true,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
it('carries the io-ts name as its identifier', () => {
|
|
109
|
+
expect(String(schema.ast)).toEqual('Person');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('codecFromIoTs', () => {
|
|
113
|
+
const codec = (0, Interop_1.codecFromIoTs)(personType);
|
|
114
|
+
it('decodes valid values', () => {
|
|
115
|
+
expect(codec.decode({ name: 'Ada', age: 36 })).toEqual(effect_1.Either.right({ name: 'Ada', age: 36 }));
|
|
116
|
+
});
|
|
117
|
+
it('decodes invalid values to an Error with every io-ts issue', () => {
|
|
118
|
+
const result = codec.decode(null);
|
|
119
|
+
expect(effect_1.Either.isLeft(result)).toBe(true);
|
|
120
|
+
const message = effect_1.Either.match(result, {
|
|
121
|
+
onLeft: (error) => error.message,
|
|
122
|
+
onRight: () => '',
|
|
123
|
+
});
|
|
124
|
+
expect(message).toEqual('age: expected a number, name: Invalid value null');
|
|
125
|
+
});
|
|
126
|
+
it('encodes through the io-ts type', () => {
|
|
127
|
+
expect(codec.encode({ name: 'Ada', age: 36 })).toEqual({
|
|
128
|
+
name: 'Ada',
|
|
129
|
+
age: 36,
|
|
130
|
+
encoded: true,
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
export interface SchemaExtensionsInterface {
|
|
3
|
+
/**
|
|
4
|
+
* A human readable name for a schema: its identifier annotation when present (set with
|
|
5
|
+
* `.annotations({ identifier })`), otherwise its title, otherwise the rendered AST.
|
|
6
|
+
* Replaces reading `.name` off an io-ts type.
|
|
7
|
+
*/
|
|
8
|
+
nameOf: (schema: Schema.Schema.All) => string;
|
|
9
|
+
}
|
|
10
|
+
export declare const SchemaExtensions: SchemaExtensionsInterface;
|
|
11
|
+
//# sourceMappingURL=SchemaExtensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaExtensions.d.ts","sourceRoot":"","sources":["../../src/effect/SchemaExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAa,MAAM,QAAQ,CAAC;AAEnD,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,MAAM,CAAC;CAC9C;AAED,eAAO,MAAM,gBAAgB,EAAE,yBAQ9B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaExtensions = void 0;
|
|
4
|
+
const effect_1 = require("effect");
|
|
5
|
+
exports.SchemaExtensions = {
|
|
6
|
+
nameOf: (schema) => effect_1.Option.getOrElse(effect_1.Option.orElse(effect_1.SchemaAST.getIdentifierAnnotation(schema.ast), () => effect_1.SchemaAST.getTitleAnnotation(schema.ast)), () => String(schema.ast)),
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaExtensions.unit.test.d.ts","sourceRoot":"","sources":["../../src/effect/SchemaExtensions.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const effect_1 = require("effect");
|
|
4
|
+
const SchemaExtensions_1 = require("./SchemaExtensions");
|
|
5
|
+
describe('SchemaExtensions.nameOf', () => {
|
|
6
|
+
it('returns the identifier annotation when present', () => {
|
|
7
|
+
const schema = effect_1.Schema.Struct({ id: effect_1.Schema.String }).annotations({
|
|
8
|
+
identifier: 'Thing',
|
|
9
|
+
title: 'A thing',
|
|
10
|
+
});
|
|
11
|
+
expect(SchemaExtensions_1.SchemaExtensions.nameOf(schema)).toEqual('Thing');
|
|
12
|
+
});
|
|
13
|
+
it('falls back to the title annotation when there is no identifier', () => {
|
|
14
|
+
const schema = effect_1.Schema.Struct({ id: effect_1.Schema.String }).annotations({
|
|
15
|
+
title: 'A thing',
|
|
16
|
+
});
|
|
17
|
+
expect(SchemaExtensions_1.SchemaExtensions.nameOf(schema)).toEqual('A thing');
|
|
18
|
+
});
|
|
19
|
+
it('falls back to the rendered AST when there are no annotations', () => {
|
|
20
|
+
expect(SchemaExtensions_1.SchemaExtensions.nameOf(effect_1.Schema.Struct({ id: effect_1.Schema.String }))).toEqual('{ readonly id: string }');
|
|
21
|
+
expect(SchemaExtensions_1.SchemaExtensions.nameOf(effect_1.Schema.String)).toEqual('string');
|
|
22
|
+
});
|
|
23
|
+
it('reads the identifier through a transformation', () => {
|
|
24
|
+
const schema = effect_1.Schema.OptionFromNullishOr(effect_1.Schema.String, null).annotations({
|
|
25
|
+
identifier: 'MaybeString',
|
|
26
|
+
});
|
|
27
|
+
expect(SchemaExtensions_1.SchemaExtensions.nameOf(schema)).toEqual('MaybeString');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
2
|
import { File, FileStorage, SharedUrl } from './File';
|
|
3
3
|
export declare class FakeFileStorage implements FileStorage {
|
|
4
4
|
files: Map<string, File>;
|
|
5
5
|
constructor();
|
|
6
|
-
write(file: File):
|
|
7
|
-
read(fileName: string):
|
|
8
|
-
delete(fileName: string):
|
|
9
|
-
getSharedUrl(key: string):
|
|
10
|
-
getSize(key: string):
|
|
11
|
-
createDirectory(key: string):
|
|
12
|
-
deleteDirectory(key: string):
|
|
6
|
+
write(file: File): Effect.Effect<File, Error>;
|
|
7
|
+
read(fileName: string): Effect.Effect<File, Error>;
|
|
8
|
+
delete(fileName: string): Effect.Effect<undefined, Error>;
|
|
9
|
+
getSharedUrl(key: string): Effect.Effect<SharedUrl, Error>;
|
|
10
|
+
getSize(key: string): Effect.Effect<number, Error>;
|
|
11
|
+
createDirectory(key: string): Effect.Effect<undefined, Error>;
|
|
12
|
+
deleteDirectory(key: string): Effect.Effect<undefined, Error>;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=FakeFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/FakeFileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FakeFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/FakeFileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAQtD,qBAAa,eAAgB,YAAW,WAAW;IAClD,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;IAMzB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC;IAO7C,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC;IAUlD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;IAOzD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;IAI1D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAOlD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;IAgB7D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC;CAM7D"}
|
|
@@ -1,73 +1,49 @@
|
|
|
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.FakeFileStorage = void 0;
|
|
27
|
-
const
|
|
28
|
-
const E = __importStar(require("fp-ts/Either"));
|
|
29
|
-
const function_1 = require("fp-ts/lib/function");
|
|
4
|
+
const effect_1 = require("effect");
|
|
30
5
|
const stream_1 = require("stream");
|
|
6
|
+
const attempt = (block) => effect_1.Effect.try({
|
|
7
|
+
try: block,
|
|
8
|
+
catch: (error) => new Error(error),
|
|
9
|
+
});
|
|
31
10
|
class FakeFileStorage {
|
|
32
11
|
files;
|
|
33
12
|
constructor() {
|
|
34
13
|
this.files = new Map();
|
|
35
14
|
}
|
|
36
15
|
write(file) {
|
|
37
|
-
return
|
|
16
|
+
return effect_1.Effect.map(attempt(() => this.files.set(file.reference.key, file)), () => file);
|
|
38
17
|
}
|
|
39
18
|
read(fileName) {
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return TE.right(file);
|
|
45
|
-
}));
|
|
19
|
+
return effect_1.Effect.flatMap(attempt(() => this.files.get(fileName)), (file) => file === undefined
|
|
20
|
+
? effect_1.Effect.fail(new Error(`File ${fileName} not found`))
|
|
21
|
+
: effect_1.Effect.succeed(file));
|
|
46
22
|
}
|
|
47
23
|
delete(fileName) {
|
|
48
|
-
return
|
|
24
|
+
return effect_1.Effect.map(attempt(() => this.files.delete(fileName)), () => undefined);
|
|
49
25
|
}
|
|
50
26
|
getSharedUrl(key) {
|
|
51
|
-
return
|
|
27
|
+
return effect_1.Effect.succeed({ url: key });
|
|
52
28
|
}
|
|
53
29
|
getSize(key) {
|
|
54
|
-
return
|
|
30
|
+
return effect_1.Effect.map(this.read(key), (file) => {
|
|
55
31
|
const { size } = file.reference.metadata;
|
|
56
32
|
return size || 0; // node-fs returns 0 for directories
|
|
57
|
-
})
|
|
33
|
+
});
|
|
58
34
|
}
|
|
59
35
|
createDirectory(key) {
|
|
60
|
-
return
|
|
36
|
+
return effect_1.Effect.map(attempt(() => this.files.set(key, {
|
|
61
37
|
reference: {
|
|
62
38
|
_tag: 'FileDescriptor',
|
|
63
39
|
key,
|
|
64
40
|
metadata: { name: key },
|
|
65
41
|
},
|
|
66
42
|
content: stream_1.Readable.from(''),
|
|
67
|
-
})
|
|
43
|
+
})), () => undefined);
|
|
68
44
|
}
|
|
69
45
|
deleteDirectory(key) {
|
|
70
|
-
return
|
|
46
|
+
return effect_1.Effect.map(attempt(() => this.files.delete(key)), () => undefined);
|
|
71
47
|
}
|
|
72
48
|
}
|
|
73
49
|
exports.FakeFileStorage = FakeFileStorage;
|
package/dist/file/File.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Readable } from 'stream';
|
|
3
|
-
import {
|
|
4
|
-
import * as t from 'io-ts';
|
|
5
|
-
import { Option } from 'fp-ts/lib/Option';
|
|
6
|
-
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import { Effect, Option, Schema } from 'effect';
|
|
7
3
|
import { DynamicObject } from '../dynamictype/DynamicType';
|
|
8
4
|
export interface FileContentTypeCheckerInterface {
|
|
9
5
|
isFileContentType(value: unknown): value is string;
|
|
@@ -14,8 +10,8 @@ export type FileMetadata = {
|
|
|
14
10
|
size?: number;
|
|
15
11
|
contentType?: string;
|
|
16
12
|
};
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
13
|
+
export declare const fileMetadataSchema: Schema.Schema<FileMetadata>;
|
|
14
|
+
export declare const fileDescriptorSchema: Schema.Schema<FileDescriptor>;
|
|
19
15
|
export type File = {
|
|
20
16
|
reference: FileDescriptor;
|
|
21
17
|
content: Readable;
|
|
@@ -35,12 +31,12 @@ export type SharedUrl = {
|
|
|
35
31
|
expires?: number;
|
|
36
32
|
};
|
|
37
33
|
export interface FileStorage {
|
|
38
|
-
write(file: File, writeOptions: Option<DynamicObject>):
|
|
39
|
-
read(key: string, name?: string):
|
|
40
|
-
getSharedUrl(key: string):
|
|
41
|
-
getSize(key: string):
|
|
42
|
-
delete(key: string):
|
|
43
|
-
createDirectory(key: string):
|
|
44
|
-
deleteDirectory(key: string):
|
|
34
|
+
write(file: File, writeOptions: Option.Option<DynamicObject>): Effect.Effect<File, Error>;
|
|
35
|
+
read(key: string, name?: string): Effect.Effect<File, Error>;
|
|
36
|
+
getSharedUrl(key: string): Effect.Effect<SharedUrl, Error>;
|
|
37
|
+
getSize(key: string): Effect.Effect<number, Error>;
|
|
38
|
+
delete(key: string): Effect.Effect<undefined, Error>;
|
|
39
|
+
createDirectory(key: string): Effect.Effect<undefined, Error>;
|
|
40
|
+
deleteDirectory(key: string): Effect.Effect<undefined, Error>;
|
|
45
41
|
}
|
|
46
42
|
//# sourceMappingURL=File.d.ts.map
|
package/dist/file/File.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/file/File.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/file/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,WAAW,+BAA+B;IAC/C,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC;CACnD;AAED,eAAO,MAAM,sBAAsB,EAAE,+BAQpC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAMd,CAAC;AAE9C,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,CAOf,CAAC;AAOjD,MAAM,MAAM,IAAI,GAAG;IAElB,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,YAAY,CAAC;CACvB,CAAC;AACF,MAAM,WAAW,uBAAuB;IACvC,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAAC;IAC1D,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,cAAc,CAAC;CACrC;AAED,eAAO,MAAM,cAAc,EAAE,uBAoB5B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,WAAW;IAC3B,KAAK,CACJ,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,GACxC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7D,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACrD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;CAC9D"}
|