0.1.3 (#4)
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Reviewed-on: https://gitea:3000/Thilawyn/effect-fc/pulls/4
This commit was merged in pull request #4.
This commit is contained in:
38
packages/example/src/lib/schema/datetime.ts
Normal file
38
packages/example/src/lib/schema/datetime.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { DateTime, Effect, Option, ParseResult, Schema } from "effect"
|
||||
|
||||
|
||||
export class DateTimeUtcFromZoned extends Schema.transformOrFail(
|
||||
Schema.DateTimeZonedFromSelf,
|
||||
Schema.DateTimeUtcFromSelf,
|
||||
{
|
||||
strict: true,
|
||||
encode: DateTime.setZoneCurrent,
|
||||
decode: i => ParseResult.succeed(DateTime.toUtc(i)),
|
||||
},
|
||||
) {}
|
||||
|
||||
export class DateTimeZonedFromUtc extends Schema.transformOrFail(
|
||||
Schema.DateTimeUtcFromSelf,
|
||||
Schema.DateTimeZonedFromSelf,
|
||||
{
|
||||
strict: true,
|
||||
encode: a => ParseResult.succeed(DateTime.toUtc(a)),
|
||||
decode: DateTime.setZoneCurrent,
|
||||
},
|
||||
) {}
|
||||
|
||||
export class DateTimeUtcFromZonedInput extends Schema.transformOrFail(
|
||||
Schema.String,
|
||||
DateTimeUtcFromZoned,
|
||||
{
|
||||
strict: true,
|
||||
encode: a => ParseResult.succeed(DateTime.formatIsoZoned(a).slice(0, 16)),
|
||||
decode: (i, _, ast) => Effect.flatMap(
|
||||
DateTime.CurrentTimeZone,
|
||||
timeZone => Option.match(DateTime.makeZoned(i, { timeZone, adjustForTimeZone: true }), {
|
||||
onSome: ParseResult.succeed,
|
||||
onNone: () => ParseResult.fail(new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a DateTime.Zoned`)),
|
||||
}),
|
||||
),
|
||||
},
|
||||
) {}
|
||||
2
packages/example/src/lib/schema/index.ts
Normal file
2
packages/example/src/lib/schema/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./datetime"
|
||||
export * from "./json"
|
||||
6
packages/example/src/lib/schema/json.ts
Normal file
6
packages/example/src/lib/schema/json.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { Schema } from "effect"
|
||||
import type { JsonValue } from "type-fest"
|
||||
|
||||
|
||||
export const assertEncodedJsonifiable = <S extends Schema.Schema<A, I, R>, A, I extends JsonValue, R>(schema: S & Schema.Schema<A, I, R>): S => schema
|
||||
export const assertTypeJsonifiable = <S extends Schema.Schema<A, I, R>, A extends JsonValue, I, R>(schema: S & Schema.Schema<A, I, R>): S => schema
|
||||
Reference in New Issue
Block a user