effect-app 1.32.0 → 2.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.
- package/CHANGELOG.md +6 -0
- package/_cjs/Array.cjs +132 -0
- package/_cjs/Array.cjs.map +1 -0
- package/_cjs/Chunk.cjs +128 -0
- package/_cjs/Chunk.cjs.map +1 -0
- package/_cjs/Config/SecretURL.cjs +3 -3
- package/_cjs/Config/SecretURL.cjs.map +1 -1
- package/_cjs/Config/internal/configSecretURL.cjs +2 -2
- package/_cjs/Config/internal/configSecretURL.cjs.map +1 -1
- package/_cjs/Context.cjs +243 -0
- package/_cjs/Context.cjs.map +1 -0
- package/_cjs/Dictionary.cjs +522 -0
- package/_cjs/Dictionary.cjs.map +1 -0
- package/_cjs/Effect.cjs +202 -0
- package/_cjs/Effect.cjs.map +1 -0
- package/_cjs/Function.cjs +107 -0
- package/_cjs/Function.cjs.map +1 -0
- package/_cjs/NonEmptySet.cjs +26 -0
- package/_cjs/NonEmptySet.cjs.map +1 -0
- package/_cjs/NonEmptySetAspects.cjs +17 -0
- package/_cjs/NonEmptySetAspects.cjs.map +1 -0
- package/_cjs/NonEmptySetBase.cjs +82 -0
- package/_cjs/NonEmptySetBase.cjs.map +1 -0
- package/_cjs/Object.cjs +24 -0
- package/_cjs/Object.cjs.map +1 -0
- package/_cjs/Operations.cjs +1 -1
- package/_cjs/Option.cjs +88 -0
- package/_cjs/Option.cjs.map +1 -0
- package/_cjs/Prelude.cjs +51 -0
- package/_cjs/Prelude.cjs.map +1 -0
- package/_cjs/Prelude.code.cjs +51 -0
- package/_cjs/Prelude.code.cjs.map +1 -0
- package/_cjs/Pure.cjs +39 -36
- package/_cjs/Pure.cjs.map +1 -1
- package/_cjs/Schema/Class.cjs +61 -0
- package/_cjs/Schema/Class.cjs.map +1 -0
- package/_cjs/Schema/FastCheck.cjs +39 -0
- package/_cjs/Schema/FastCheck.cjs.map +1 -0
- package/_cjs/Schema/Methods.cjs +6 -0
- package/_cjs/Schema/Methods.cjs.map +1 -0
- package/_cjs/Schema/brand.cjs +17 -0
- package/_cjs/Schema/brand.cjs.map +1 -0
- package/_cjs/Schema/email.cjs +20 -0
- package/_cjs/Schema/email.cjs.map +1 -0
- package/_cjs/Schema/ext.cjs +174 -0
- package/_cjs/Schema/ext.cjs.map +1 -0
- package/_cjs/Schema/moreStrings.cjs +124 -0
- package/_cjs/Schema/moreStrings.cjs.map +1 -0
- package/_cjs/Schema/numbers.cjs +52 -0
- package/_cjs/Schema/numbers.cjs.map +1 -0
- package/_cjs/Schema/phoneNumber.cjs +22 -0
- package/_cjs/Schema/phoneNumber.cjs.map +1 -0
- package/_cjs/Schema/schema.cjs +15 -0
- package/_cjs/Schema/schema.cjs.map +1 -0
- package/_cjs/Schema/strings.cjs +32 -0
- package/_cjs/Schema/strings.cjs.map +1 -0
- package/_cjs/Schema.cjs +334 -0
- package/_cjs/Schema.cjs.map +1 -0
- package/_cjs/Set.cjs +567 -0
- package/_cjs/Set.cjs.map +1 -0
- package/_cjs/Struct.cjs +51 -0
- package/_cjs/Struct.cjs.map +1 -0
- package/_cjs/Tag.cjs +25 -0
- package/_cjs/Tag.cjs.map +1 -0
- package/_cjs/Unify.cjs +40 -0
- package/_cjs/Unify.cjs.map +1 -0
- package/_cjs/_ext/misc.cjs +16 -16
- package/_cjs/_ext/misc.cjs.map +1 -1
- package/_cjs/_ext/ord.ext.cjs +52 -0
- package/_cjs/_ext/ord.ext.cjs.map +1 -0
- package/_cjs/builtin.cjs +6 -0
- package/_cjs/builtin.cjs.map +1 -0
- package/_cjs/client/clientFor.cjs +5 -3
- package/_cjs/client/clientFor.cjs.map +1 -1
- package/_cjs/client/config.cjs +4 -4
- package/_cjs/client/config.cjs.map +1 -1
- package/_cjs/client/errors.cjs +9 -9
- package/_cjs/client/errors.cjs.map +1 -1
- package/_cjs/http/http-client.cjs +35 -0
- package/_cjs/http/http-client.cjs.map +1 -0
- package/_cjs/ids.cjs +5 -5
- package/_cjs/ids.cjs.map +1 -1
- package/_cjs/index.cjs +1 -1
- package/_cjs/lib.cjs +178 -9
- package/_cjs/lib.cjs.map +1 -1
- package/_cjs/logger.cjs +1 -1
- package/_cjs/transform.cjs +45 -0
- package/_cjs/transform.cjs.map +1 -0
- package/_cjs/utils/effectify.cjs +25 -0
- package/_cjs/utils/effectify.cjs.map +1 -0
- package/_cjs/utils/extend.cjs +17 -0
- package/_cjs/utils/extend.cjs.map +1 -0
- package/_cjs/utils/logger.cjs +23 -0
- package/_cjs/utils/logger.cjs.map +1 -0
- package/_cjs/utils.cjs +431 -4
- package/_cjs/utils.cjs.map +1 -1
- package/_cjs/validation/validators.cjs +32 -0
- package/_cjs/validation/validators.cjs.map +1 -0
- package/_cjs/validation.cjs +45 -0
- package/_cjs/validation.cjs.map +1 -0
- package/dist/Array.d.ts +64 -0
- package/dist/Array.d.ts.map +1 -0
- package/dist/Array.js +89 -0
- package/dist/Chunk.d.ts +68 -0
- package/dist/Chunk.d.ts.map +1 -0
- package/dist/Chunk.js +93 -0
- package/dist/Config/SecretURL.d.ts +3 -3
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +2 -2
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Context.d.ts +55 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +204 -0
- package/dist/Dictionary.d.ts +260 -0
- package/dist/Dictionary.d.ts.map +1 -0
- package/dist/Dictionary.js +448 -0
- package/dist/Effect.d.ts +115 -0
- package/dist/Effect.d.ts.map +1 -0
- package/dist/Effect.js +153 -0
- package/dist/Function.d.ts +72 -0
- package/dist/Function.d.ts.map +1 -0
- package/dist/Function.js +71 -0
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Inputify.type.d.ts.map +1 -1
- package/dist/NonEmptySet.d.ts +3 -0
- package/dist/NonEmptySet.d.ts.map +1 -0
- package/dist/NonEmptySet.js +3 -0
- package/dist/NonEmptySetAspects.d.ts +2 -0
- package/dist/NonEmptySetAspects.d.ts.map +1 -0
- package/dist/NonEmptySetAspects.js +2 -0
- package/dist/NonEmptySetBase.d.ts +39 -0
- package/dist/NonEmptySetBase.d.ts.map +1 -0
- package/dist/NonEmptySetBase.js +63 -0
- package/dist/Object.d.ts +7 -0
- package/dist/Object.d.ts.map +1 -0
- package/dist/Object.js +7 -0
- package/dist/Operations.d.ts +2 -2
- package/dist/Operations.js +1 -1
- package/dist/Option.d.ts +39 -0
- package/dist/Option.d.ts.map +1 -0
- package/dist/Option.js +55 -0
- package/dist/Prelude.code.d.ts +24 -0
- package/dist/Prelude.code.d.ts.map +1 -0
- package/dist/Prelude.code.js +23 -0
- package/dist/Prelude.d.ts +163 -0
- package/dist/Prelude.d.ts.map +1 -0
- package/dist/Prelude.js +23 -0
- package/dist/Pure.d.ts +13 -12
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +18 -17
- package/dist/Schema/Class.d.ts +45 -0
- package/dist/Schema/Class.d.ts.map +1 -0
- package/dist/Schema/Class.js +50 -0
- package/dist/Schema/FastCheck.d.ts +10 -0
- package/dist/Schema/FastCheck.d.ts.map +1 -0
- package/dist/Schema/FastCheck.js +12 -0
- package/dist/Schema/Methods.d.ts +6 -0
- package/dist/Schema/Methods.d.ts.map +1 -0
- package/dist/Schema/Methods.js +2 -0
- package/dist/Schema/brand.d.ts +35 -0
- package/dist/Schema/brand.d.ts.map +1 -0
- package/dist/Schema/brand.js +7 -0
- package/dist/Schema/email.d.ts +9 -0
- package/dist/Schema/email.d.ts.map +1 -0
- package/dist/Schema/email.js +12 -0
- package/dist/Schema/ext.d.ts +89 -0
- package/dist/Schema/ext.d.ts.map +1 -0
- package/dist/Schema/ext.js +111 -0
- package/dist/Schema/moreStrings.d.ts +109 -0
- package/dist/Schema/moreStrings.d.ts.map +1 -0
- package/dist/Schema/moreStrings.js +108 -0
- package/dist/Schema/numbers.d.ts +46 -0
- package/dist/Schema/numbers.d.ts.map +1 -0
- package/dist/Schema/numbers.js +28 -0
- package/dist/Schema/phoneNumber.d.ts +9 -0
- package/dist/Schema/phoneNumber.d.ts.map +1 -0
- package/dist/Schema/phoneNumber.js +14 -0
- package/dist/Schema/schema.d.ts +6 -0
- package/dist/Schema/schema.d.ts.map +1 -0
- package/dist/Schema/schema.js +5 -0
- package/dist/Schema/strings.d.ts +19 -0
- package/dist/Schema/strings.d.ts.map +1 -0
- package/dist/Schema/strings.js +32 -0
- package/dist/{schema.d.ts → Schema.d.ts} +25 -9
- package/dist/Schema.d.ts.map +1 -0
- package/dist/Schema.js +89 -0
- package/dist/Set.d.ts +221 -0
- package/dist/Set.d.ts.map +1 -0
- package/dist/Set.js +516 -0
- package/dist/Struct.d.ts +44 -0
- package/dist/Struct.d.ts.map +1 -0
- package/dist/Struct.js +29 -0
- package/dist/Tag.d.ts +9 -0
- package/dist/Tag.d.ts.map +1 -0
- package/dist/Tag.js +18 -0
- package/dist/Unify.d.ts +43 -0
- package/dist/Unify.d.ts.map +1 -0
- package/dist/Unify.js +31 -0
- package/dist/Widen.type.d.ts +1 -1
- package/dist/Widen.type.d.ts.map +1 -1
- package/dist/_ext/misc.d.ts +11 -11
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +8 -8
- package/dist/_ext/ord.ext.d.ts +23 -0
- package/dist/_ext/ord.ext.d.ts.map +1 -0
- package/dist/_ext/ord.ext.js +44 -0
- package/dist/builtin.d.ts +51 -0
- package/dist/builtin.d.ts.map +1 -0
- package/dist/builtin.js +2 -0
- package/dist/client/clientFor.d.ts +1 -1
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +2 -2
- package/dist/client/config.d.ts +1 -1
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js +2 -2
- package/dist/client/errors.js +1 -1
- package/dist/http/http-client.d.ts +43 -0
- package/dist/http/http-client.d.ts.map +1 -0
- package/dist/http/http-client.js +30 -0
- package/dist/ids.d.ts +3 -3
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib.d.ts +22 -4
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +20 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +2 -2
- package/dist/transform.d.ts +12 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +39 -0
- package/dist/utils/effectify.d.ts +210 -0
- package/dist/utils/effectify.d.ts.map +1 -0
- package/dist/utils/effectify.js +19 -0
- package/dist/utils/extend.d.ts +3 -0
- package/dist/utils/extend.d.ts.map +1 -0
- package/dist/utils/extend.js +9 -0
- package/dist/utils/logger.d.ts +12 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +15 -0
- package/dist/utils.d.ts +192 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +332 -2
- package/dist/validation/validators.d.ts +11 -0
- package/dist/validation/validators.d.ts.map +1 -0
- package/dist/validation/validators.js +26 -0
- package/dist/validation.d.ts +13 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +14 -0
- package/package.json +360 -9
- package/src/Array.ts +127 -0
- package/src/Chunk.ts +112 -0
- package/src/Config/SecretURL.ts +3 -3
- package/src/Config/internal/configSecretURL.ts +1 -1
- package/src/Context.ts +293 -0
- package/src/Dictionary.ts +669 -0
- package/src/Effect.ts +265 -0
- package/src/Function.ts +175 -0
- package/src/Inputify.type.ts +1 -1
- package/src/NonEmptySet.ts +3 -0
- package/src/NonEmptySetAspects.ts +1 -0
- package/src/NonEmptySetBase.ts +109 -0
- package/src/Object.ts +19 -0
- package/src/Operations.ts +1 -1
- package/src/Option.ts +82 -0
- package/src/Prelude.code.ts +26 -0
- package/src/Prelude.ts +220 -0
- package/src/Pure.ts +37 -30
- package/src/Schema/Class.ts +225 -0
- package/src/Schema/FastCheck.ts +23 -0
- package/src/Schema/Methods.ts +8 -0
- package/src/Schema/brand.ts +50 -0
- package/src/Schema/email.ts +22 -0
- package/src/Schema/ext.ts +273 -0
- package/src/Schema/moreStrings.ts +260 -0
- package/src/Schema/numbers.ts +83 -0
- package/src/Schema/phoneNumber.ts +24 -0
- package/src/Schema/schema.ts +6 -0
- package/src/Schema/strings.ts +60 -0
- package/src/{schema.ts → Schema.ts} +52 -20
- package/src/Set.ts +674 -0
- package/src/Struct.ts +54 -0
- package/src/Tag.ts +20 -0
- package/src/Unify.ts +56 -0
- package/src/Widen.type.ts +1 -1
- package/src/_ext/misc.ts +22 -22
- package/src/_ext/ord.ext.ts +49 -0
- package/src/builtin.ts +64 -0
- package/src/client/clientFor.ts +1 -1
- package/src/client/config.ts +1 -1
- package/src/client/errors.ts +1 -1
- package/src/http/http-client.ts +73 -0
- package/src/ids.ts +3 -3
- package/src/index.ts +1 -1
- package/src/lib.ts +88 -4
- package/src/logger.ts +1 -1
- package/src/transform.ts +80 -0
- package/src/utils/effectify.ts +259 -0
- package/src/utils/extend.ts +9 -0
- package/src/utils/logger.ts +24 -0
- package/src/utils.ts +805 -1
- package/src/validation/validators.ts +32 -0
- package/src/validation.ts +18 -0
- package/tsconfig.src.json +1 -5
- package/_cjs/schema.cjs +0 -110
- package/_cjs/schema.cjs.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -73
package/src/Struct.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type { Types } from "effect"
|
|
3
|
+
import * as Struct from "effect/Struct"
|
|
4
|
+
|
|
5
|
+
export * from "effect/Struct"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a new object by picking properties of an existing object.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { pick } from "effect/Struct"
|
|
12
|
+
* import { pipe } from "effect/Function"
|
|
13
|
+
*
|
|
14
|
+
* assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, pick("a", "b")), { a: "a", b: 1 })
|
|
15
|
+
* assert.deepStrictEqual(pick({ a: "a", b: 1, c: true }, "a", "b"), { a: "a", b: 1 })
|
|
16
|
+
*
|
|
17
|
+
* @since 2.0.0
|
|
18
|
+
*/
|
|
19
|
+
export const pick: {
|
|
20
|
+
<Keys extends Array<PropertyKey>>(
|
|
21
|
+
...keys: Keys
|
|
22
|
+
): <S extends { [K in Keys[number]]?: any }>(
|
|
23
|
+
s: S
|
|
24
|
+
) => Types.MatchRecord<S, { [K in Keys[number]]?: S[K] }, Pick<S, Keys[number]>>
|
|
25
|
+
<S extends object, Keys extends Array<keyof S>>(
|
|
26
|
+
s: S,
|
|
27
|
+
...keys: Keys
|
|
28
|
+
): Types.MatchRecord<S, { [K in Keys[number]]?: S[K] }, Pick<S, Keys[number]>>
|
|
29
|
+
} = Struct.pick
|
|
30
|
+
|
|
31
|
+
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K>
|
|
32
|
+
: never
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a new object by omitting properties of an existing object.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* import { omit } from "effect/Struct"
|
|
39
|
+
* import { pipe } from "effect/Function"
|
|
40
|
+
*
|
|
41
|
+
* assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, omit("c")), { a: "a", b: 1 })
|
|
42
|
+
* assert.deepStrictEqual(omit({ a: "a", b: 1, c: true }, "c"), { a: "a", b: 1 })
|
|
43
|
+
*
|
|
44
|
+
* @since 2.0.0
|
|
45
|
+
*/
|
|
46
|
+
export const omit: {
|
|
47
|
+
<Keys extends Array<PropertyKey>>(
|
|
48
|
+
...keys: Keys
|
|
49
|
+
): <S extends { [K in Keys[number]]?: any }>(s: S) => DistributiveOmit<S, Keys[number]>
|
|
50
|
+
<S extends object, Keys extends Array<keyof S>>(
|
|
51
|
+
s: S,
|
|
52
|
+
...keys: Keys
|
|
53
|
+
): DistributiveOmit<S, Keys[number]>
|
|
54
|
+
} = Struct.omit as any
|
package/src/Tag.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// /**
|
|
2
|
+
// * @tsplus fluent effect/data/Context/Tag withEffect_
|
|
3
|
+
// */
|
|
4
|
+
// export function accessM_<T, I, R, E, A>(self: Tag<T, I>, f: (x: T) => Effect<R, E, A>) {
|
|
5
|
+
// return Effect.serviceWithEffect(self)(f)
|
|
6
|
+
// }
|
|
7
|
+
|
|
8
|
+
import { Layer } from "effect"
|
|
9
|
+
|
|
10
|
+
// /**
|
|
11
|
+
// * @tsplus fluent effect/data/Context/Tag with_
|
|
12
|
+
// */
|
|
13
|
+
// export function access_<T, I, B>(self: Tag<T, I>, f: (x: T) => B) {
|
|
14
|
+
// return Effect.serviceWith(self)(f)
|
|
15
|
+
// }
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @tsplus fluent effect/data/Context/Tag makeLayer
|
|
19
|
+
*/
|
|
20
|
+
export const makeLayer = Layer.succeed
|
package/src/Unify.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
// TODO: Add effect cause/exit etc
|
|
3
|
+
|
|
4
|
+
import type { Chunk, Either, Option } from "effect"
|
|
5
|
+
import type { Effect, EffectTypeId } from "effect/Effect"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @tsplus unify effect/io/Effect
|
|
9
|
+
*/
|
|
10
|
+
export function unifyEffect<X extends { readonly [EffectTypeId]: Effect.VarianceStruct<any, any, any> }>(
|
|
11
|
+
self: X
|
|
12
|
+
): Effect<
|
|
13
|
+
[X] extends [{ readonly [EffectTypeId]: { _A: (_: never) => infer A } }] ? A : never,
|
|
14
|
+
[X] extends [{ readonly [EffectTypeId]: { _E: (_: never) => infer E } }] ? E : never,
|
|
15
|
+
[X] extends [{ readonly [EffectTypeId]: { _R: (_: never) => infer R } }] ? R : never
|
|
16
|
+
> {
|
|
17
|
+
return self as any
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @tsplus unify effect/data/Chunk
|
|
22
|
+
*/
|
|
23
|
+
export function unifyChunk<X extends Chunk.Chunk<any>>(
|
|
24
|
+
self: X
|
|
25
|
+
): Chunk.Chunk<[X] extends [Chunk.Chunk<infer A>] ? A : never> {
|
|
26
|
+
return self
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @tsplus unify effect/data/Either
|
|
31
|
+
* @tsplus unify effect/data/Either.Left
|
|
32
|
+
* @tsplus unify effect/data/Either.Right
|
|
33
|
+
*/
|
|
34
|
+
export function unifyEither<X extends Either.Either<any, any>>(
|
|
35
|
+
self: X
|
|
36
|
+
): Either.Either<
|
|
37
|
+
X extends Either.Right<any, infer AX> ? AX : X extends Either.Left<any, infer AX> ? AX : never,
|
|
38
|
+
X extends Either.Left<infer EX, any> ? EX : X extends Either.Right<infer EX, any> ? EX : never
|
|
39
|
+
> {
|
|
40
|
+
return self
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @tsplus unify effect/data/Option
|
|
45
|
+
* @tsplus unify effect/data/Option.Some
|
|
46
|
+
* @tsplus unify effect/data/Option.None
|
|
47
|
+
*/
|
|
48
|
+
export function unifyOption<X extends Option.Option<any>>(
|
|
49
|
+
self: X
|
|
50
|
+
): Option.Option<
|
|
51
|
+
X extends Option.Some<infer A> ? A
|
|
52
|
+
: X extends Option.None<infer A> ? A
|
|
53
|
+
: never
|
|
54
|
+
> {
|
|
55
|
+
return self
|
|
56
|
+
}
|
package/src/Widen.type.ts
CHANGED
package/src/_ext/misc.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Effect, Either, Option, type Scope } from "
|
|
2
|
-
import type { LazyArg } from "
|
|
1
|
+
import { Effect, Either, Option, type Scope } from "effect"
|
|
2
|
+
import type { LazyArg } from "effect-app/Function"
|
|
3
3
|
|
|
4
|
-
export type _R<T extends Effect<any, any, any>> = [T] extends [
|
|
5
|
-
Effect<any, any, infer R>
|
|
4
|
+
export type _R<T extends Effect.Effect<any, any, any>> = [T] extends [
|
|
5
|
+
Effect.Effect<any, any, infer R>
|
|
6
6
|
] ? R
|
|
7
7
|
: never
|
|
8
8
|
|
|
9
|
-
export type _E<T extends Effect<any, any, any>> = [T] extends [
|
|
10
|
-
Effect<any, infer E, any>
|
|
9
|
+
export type _E<T extends Effect.Effect<any, any, any>> = [T] extends [
|
|
10
|
+
Effect.Effect<any, infer E, any>
|
|
11
11
|
] ? E
|
|
12
12
|
: never
|
|
13
13
|
|
|
@@ -15,9 +15,9 @@ export type _E<T extends Effect<any, any, any>> = [T] extends [
|
|
|
15
15
|
* @tsplus fluent effect/data/Option encaseInEffect
|
|
16
16
|
*/
|
|
17
17
|
export function encaseMaybeInEffect_<E, A>(
|
|
18
|
-
o: Option<A>,
|
|
18
|
+
o: Option.Option<A>,
|
|
19
19
|
onError: LazyArg<E>
|
|
20
|
-
): Effect<A, E> {
|
|
20
|
+
): Effect.Effect<A, E> {
|
|
21
21
|
return Option.match(o, { onNone: () => Effect.fail(onError()), onSome: Effect.succeed })
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ export function encaseMaybeInEffect_<E, A>(
|
|
|
25
25
|
* @tsplus fluent effect/data/Option encaseInEither
|
|
26
26
|
*/
|
|
27
27
|
export function encaseMaybeEither_<E, A>(
|
|
28
|
-
o: Option<A>,
|
|
28
|
+
o: Option.Option<A>,
|
|
29
29
|
onError: LazyArg<E>
|
|
30
30
|
): Either.Either<A, E> {
|
|
31
31
|
return Option.match(o, { onNone: () => Either.left(onError()), onSome: Either.right })
|
|
@@ -35,7 +35,7 @@ export function encaseMaybeEither_<E, A>(
|
|
|
35
35
|
* @tsplus getter effect/io/Effect toNullable
|
|
36
36
|
*/
|
|
37
37
|
export function toNullable<R, E, A>(
|
|
38
|
-
self: Effect<Option<A>, E, R>
|
|
38
|
+
self: Effect.Effect<Option.Option<A>, E, R>
|
|
39
39
|
) {
|
|
40
40
|
return Effect.map(self, (_) => Option.getOrNull(_))
|
|
41
41
|
}
|
|
@@ -44,9 +44,9 @@ export function toNullable<R, E, A>(
|
|
|
44
44
|
* @tsplus fluent effect/io/Effect scope
|
|
45
45
|
*/
|
|
46
46
|
export function scope<R, E, A, R2, E2, A2>(
|
|
47
|
-
scopedEffect: Effect<A, E, R | Scope>,
|
|
48
|
-
effect: Effect<A2, E2, R2>
|
|
49
|
-
): Effect<A2, E | E2, Exclude<R | R2, Scope>> {
|
|
47
|
+
scopedEffect: Effect.Effect<A, E, R | Scope.Scope>,
|
|
48
|
+
effect: Effect.Effect<A2, E2, R2>
|
|
49
|
+
): Effect.Effect<A2, E | E2, Exclude<R | R2, Scope.Scope>> {
|
|
50
50
|
return Effect.zipRight(scopedEffect, effect).pipe(Effect.scoped)
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -54,9 +54,9 @@ export function scope<R, E, A, R2, E2, A2>(
|
|
|
54
54
|
* @tsplus fluent effect/io/Effect flatMapScoped
|
|
55
55
|
*/
|
|
56
56
|
export function flatMapScoped<R, E, A, R2, E2, A2>(
|
|
57
|
-
scopedEffect: Effect<A, E, R | Scope>,
|
|
58
|
-
effect: (a: A) => Effect<A2, E2, R2>
|
|
59
|
-
): Effect<A2, E | E2, Exclude<R | R2, Scope>> {
|
|
57
|
+
scopedEffect: Effect.Effect<A, E, R | Scope.Scope>,
|
|
58
|
+
effect: (a: A) => Effect.Effect<A2, E2, R2>
|
|
59
|
+
): Effect.Effect<A2, E | E2, Exclude<R | R2, Scope.Scope>> {
|
|
60
60
|
return scopedEffect.pipe(Effect.flatMap(effect), Effect.scoped)
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -64,9 +64,9 @@ export function flatMapScoped<R, E, A, R2, E2, A2>(
|
|
|
64
64
|
// * @tsplus fluent effect/io/Effect withScoped
|
|
65
65
|
// */
|
|
66
66
|
// export function withScoped<R, E, A, R2, E2, A2>(
|
|
67
|
-
// effect: Effect<R2, E2, A2>,
|
|
68
|
-
// scopedEffect: Effect<R | Scope, E, A>
|
|
69
|
-
// ): Effect<Exclude<R | R2, Scope>, E | E2, A2> {
|
|
67
|
+
// effect: Effect.Effect<R2, E2, A2>,
|
|
68
|
+
// scopedEffect: Effect.Effect<R | Scope.Scope, E, A>
|
|
69
|
+
// ): Effect.Effect<Exclude<R | R2, Scope.Scope>, E | E2, A2> {
|
|
70
70
|
// return scopedEffect.zipRight(effect).scoped
|
|
71
71
|
// }
|
|
72
72
|
|
|
@@ -74,8 +74,8 @@ export function flatMapScoped<R, E, A, R2, E2, A2>(
|
|
|
74
74
|
// * @tsplus fluent effect/io/Effect withScoped
|
|
75
75
|
// */
|
|
76
76
|
// export function withScopedFlatMap<R, E, A, R2, E2, A2>(
|
|
77
|
-
// effect: (a: A) => Effect<R2, E2, A2>,
|
|
78
|
-
// scopedEffect: Effect<R | Scope, E, A>
|
|
79
|
-
// ): Effect<Exclude<R | R2, Scope>, E | E2, A2> {
|
|
77
|
+
// effect: (a: A) => Effect.Effect<R2, E2, A2>,
|
|
78
|
+
// scopedEffect: Effect.Effect<R | Scope.Scope, E, A>
|
|
79
|
+
// ): Effect.Effect<Exclude<R | R2, Scope.Scope>, E | E2, A2> {
|
|
80
80
|
// return scopedEffect.flatMap(effect).scoped
|
|
81
81
|
// }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Chunk } from "effect"
|
|
2
|
+
import type { Equivalence } from "effect"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @tsplus getter Generator toArray
|
|
6
|
+
*/
|
|
7
|
+
export function toArray<A>(
|
|
8
|
+
gen: Generator<A, void, unknown>
|
|
9
|
+
) {
|
|
10
|
+
return Array.from(gen)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Remove duplicates from an array, keeping the first occurrence of an element.
|
|
15
|
+
*
|
|
16
|
+
* @tsplus static effect/data/Chunk.Ops uniq
|
|
17
|
+
* @tsplus pipeable effect/data/Chunk uniq
|
|
18
|
+
*/
|
|
19
|
+
export function uniq<A>(E: Equivalence.Equivalence<A>) {
|
|
20
|
+
return (self: Chunk.Chunk<A>): Chunk.Chunk<A> => {
|
|
21
|
+
let out = Chunk.fromIterable<A>([])
|
|
22
|
+
for (let i = 0; i < self.length; i++) {
|
|
23
|
+
const a = Chunk.unsafeGet(self, i)
|
|
24
|
+
if (!elem(E, a)(out)) {
|
|
25
|
+
out = Chunk.append(out, a)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return self.length === out.length ? self : out
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Test if a value is a member of an array. Takes a `Equivalence.Equivalence<A>` as a single
|
|
34
|
+
* argument which returns the function to use to search for a value of type `A`
|
|
35
|
+
* in an array of type `Chunk.Chunk<A>`.
|
|
36
|
+
*
|
|
37
|
+
* @tsplus static effect/data/Chunk.Ops elem2
|
|
38
|
+
* @tsplus pipeable effect/data/Chunk elem2
|
|
39
|
+
*/
|
|
40
|
+
export function elem<A>(E: Equivalence.Equivalence<A>, value: A) {
|
|
41
|
+
return (self: Chunk.Chunk<A>): boolean => {
|
|
42
|
+
for (let i = 0; i < self.length; i++) {
|
|
43
|
+
if (E(Chunk.unsafeGet(self, i), value)) {
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/builtin.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { NonEmptyArray, NonEmptyReadonlyArray } from "effect/Array"
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface String {
|
|
5
|
+
/**
|
|
6
|
+
* Split a string into substrings using the specified separator and return them as an array.
|
|
7
|
+
* @param splitter An object that can split a string.
|
|
8
|
+
* @param limit A value used to limit the number of elements returned in the array.
|
|
9
|
+
*/
|
|
10
|
+
split(splitter: { [Symbol.split](string: string, limit?: number): string[] }, limit?: number): [string, ...string[]]
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Split a string into substrings using the specified separator and return them as an array.
|
|
14
|
+
* @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
|
|
15
|
+
* @param limit A value used to limit the number of elements returned in the array.
|
|
16
|
+
*/
|
|
17
|
+
split(separator: string | RegExp, limit?: number): [string, ...string[]]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface JSON {
|
|
21
|
+
/**
|
|
22
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
23
|
+
* @param text A valid JSON string.
|
|
24
|
+
* @param reviver A function that transforms the results. This function is called for each member of the object.
|
|
25
|
+
* If a member contains nested objects, the nested objects are transformed before the parent object is.
|
|
26
|
+
*/
|
|
27
|
+
parse(text: string, reviver?: (this: any, key: string, value: any) => any): unknown
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Body {
|
|
31
|
+
json(): Promise<unknown>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface Array<T> {
|
|
35
|
+
map<A, B>(
|
|
36
|
+
this: NonEmptyArray<A>,
|
|
37
|
+
map: (a: A, index: number) => B
|
|
38
|
+
): NonEmptyArray<B>
|
|
39
|
+
}
|
|
40
|
+
interface ReadonlyArray<T> {
|
|
41
|
+
// Subsequent property declarations must have the same type. Property 'length' must be of type 'number', but here has type 'NonNegativeInt'.
|
|
42
|
+
// readonly length: NonNegativeInt
|
|
43
|
+
|
|
44
|
+
map<A, B>(
|
|
45
|
+
this: NonEmptyReadonlyArray<A>,
|
|
46
|
+
map: (a: A, index: number) => B
|
|
47
|
+
): NonEmptyReadonlyArray<B>
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module "effect/Option" {
|
|
52
|
+
export interface None<out A> {
|
|
53
|
+
get value(): A | undefined
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare module "effect/Either" {
|
|
58
|
+
export interface Left<out L, out R> {
|
|
59
|
+
get right(): R | undefined
|
|
60
|
+
}
|
|
61
|
+
export interface Right<out L, out R> {
|
|
62
|
+
get left(): L | undefined
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/client/clientFor.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { RpcResolver } from "@effect/rpc"
|
|
|
5
5
|
import { HttpRpcResolver } from "@effect/rpc-http"
|
|
6
6
|
import type { RpcRouter } from "@effect/rpc/RpcRouter"
|
|
7
7
|
import { Record } from "effect"
|
|
8
|
-
import { S } from "effect-app"
|
|
9
8
|
import { ApiConfig } from "effect-app/client"
|
|
10
9
|
import { HttpClient, HttpClientRequest } from "effect-app/http"
|
|
11
10
|
import { typedKeysOf } from "effect-app/utils"
|
|
@@ -14,6 +13,7 @@ import type { Path } from "path-parser"
|
|
|
14
13
|
import qs from "query-string"
|
|
15
14
|
import type { Schema } from "../lib.js"
|
|
16
15
|
import { Effect, flow, HashMap, Layer, Option, Predicate, Struct } from "../lib.js"
|
|
16
|
+
import * as S from "../Schema.js"
|
|
17
17
|
|
|
18
18
|
export function makePathWithQuery(
|
|
19
19
|
path: Path,
|
package/src/client/config.ts
CHANGED
package/src/client/errors.ts
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import type { Option } from "../Option.js"
|
|
4
|
+
|
|
5
|
+
export const Method = {
|
|
6
|
+
GET: null,
|
|
7
|
+
POST: null,
|
|
8
|
+
PUT: null,
|
|
9
|
+
DELETE: null,
|
|
10
|
+
PATCH: null
|
|
11
|
+
}
|
|
12
|
+
export type Method = keyof typeof Method
|
|
13
|
+
|
|
14
|
+
/** @deprecated use @effect/platform */
|
|
15
|
+
export type Headers = Record<string, string>
|
|
16
|
+
|
|
17
|
+
/** @deprecated use @effect/platform */
|
|
18
|
+
export interface Response<Body> {
|
|
19
|
+
body: Option<Body>
|
|
20
|
+
headers: Headers
|
|
21
|
+
status: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @deprecated use @effect/platform */
|
|
25
|
+
export const HttpErrorReason = {
|
|
26
|
+
Request: "HttpErrorRequest",
|
|
27
|
+
Response: "HttpErrorResponse"
|
|
28
|
+
} as const
|
|
29
|
+
|
|
30
|
+
/** @deprecated use @effect/platform */
|
|
31
|
+
export type HttpErrorReason = typeof HttpErrorReason
|
|
32
|
+
|
|
33
|
+
/** @deprecated use @effect/platform */
|
|
34
|
+
export interface HttpResponseError<ErrorBody> {
|
|
35
|
+
_tag: HttpErrorReason["Response"]
|
|
36
|
+
response: Response<ErrorBody>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @deprecated use @effect/platform */
|
|
40
|
+
export function isHttpResponseError(
|
|
41
|
+
u: unknown
|
|
42
|
+
): u is HttpResponseError<unknown> {
|
|
43
|
+
return (
|
|
44
|
+
typeof u === "object"
|
|
45
|
+
&& u !== null
|
|
46
|
+
&& (u as any)["_tag"] === HttpErrorReason.Response
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @deprecated use @effect/platform */
|
|
51
|
+
export interface HttpRequestError {
|
|
52
|
+
_tag: HttpErrorReason["Request"]
|
|
53
|
+
error: Error
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @deprecated use @effect/platform */
|
|
57
|
+
export function isHttpRequestError(u: unknown): u is HttpRequestError {
|
|
58
|
+
return (
|
|
59
|
+
typeof u === "object"
|
|
60
|
+
&& u !== null
|
|
61
|
+
&& (u as any)["_tag"] === HttpErrorReason.Request
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @deprecated use @effect/platform */
|
|
66
|
+
export function isHttpError(u: unknown): u is HttpError<unknown> {
|
|
67
|
+
return isHttpRequestError(u) || isHttpResponseError(u)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @deprecated use @effect/platform */
|
|
71
|
+
export type HttpError<ErrorBody> =
|
|
72
|
+
| HttpRequestError
|
|
73
|
+
| HttpResponseError<ErrorBody>
|
package/src/ids.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import { brandedStringId, NonEmptyString255, StringId, withDefaultMake } from "effect-app/Schema"
|
|
2
|
+
import type { Schema, StringIdBrand } from "effect-app/Schema"
|
|
3
|
+
import type { B } from "effect-app/Schema/schema"
|
|
4
4
|
import type { Simplify } from "effect/Types"
|
|
5
5
|
import { S } from "./index.js"
|
|
6
6
|
import { extendM } from "./utils.js"
|
package/src/index.ts
CHANGED
package/src/lib.ts
CHANGED
|
@@ -1,4 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * as
|
|
1
|
+
import type { YieldWrap } from "effect/Utils"
|
|
2
|
+
import { Effect } from "./Prelude.js"
|
|
3
|
+
|
|
4
|
+
export * as Fnc from "./Function.js"
|
|
5
|
+
export * as Record from "./Object.js"
|
|
6
|
+
export * as Utils from "./utils.js"
|
|
7
|
+
|
|
8
|
+
export * from "effect"
|
|
9
|
+
|
|
10
|
+
// we cannot export types colliding with namespaces from .ts files, only from .d.ts files with custom .js trick, applied in effect-app
|
|
11
|
+
// for app land, it may make sense to create an app/prelude?
|
|
12
|
+
export * from "./Prelude.js"
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
Array,
|
|
16
|
+
Cause,
|
|
17
|
+
Chunk,
|
|
18
|
+
Config,
|
|
19
|
+
Context,
|
|
20
|
+
Duration,
|
|
21
|
+
Effect,
|
|
22
|
+
Either,
|
|
23
|
+
Equal,
|
|
24
|
+
Equivalence,
|
|
25
|
+
Exit,
|
|
26
|
+
FiberRef,
|
|
27
|
+
HashMap,
|
|
28
|
+
Layer,
|
|
29
|
+
Option,
|
|
30
|
+
Order,
|
|
31
|
+
Ref,
|
|
32
|
+
Schema,
|
|
33
|
+
Scope
|
|
34
|
+
} from "./Prelude.js"
|
|
35
|
+
|
|
36
|
+
export * as Struct from "./Struct.js"
|
|
37
|
+
|
|
38
|
+
export * as SecretURL from "./Config/SecretURL.js"
|
|
39
|
+
export * as S from "./Schema.js"
|
|
40
|
+
export { copy } from "./utils.js"
|
|
41
|
+
|
|
42
|
+
// Simply Effect! https://github.com/kasperpeulen/simply-effect
|
|
43
|
+
type InferE<Eff extends YieldWrap<Effect<any, any, any>>> = [
|
|
44
|
+
Eff
|
|
45
|
+
] extends [never] ? never
|
|
46
|
+
: [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E
|
|
47
|
+
: never
|
|
48
|
+
type InferR<Eff extends YieldWrap<Effect<any, any, any>>> = [
|
|
49
|
+
Eff
|
|
50
|
+
] extends [never] ? never
|
|
51
|
+
: [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R
|
|
52
|
+
: never
|
|
53
|
+
|
|
54
|
+
export function effect<
|
|
55
|
+
Eff extends YieldWrap<Effect<any, any, any>>,
|
|
56
|
+
AEff
|
|
57
|
+
>(
|
|
58
|
+
f: () => Generator<Eff, AEff, never>
|
|
59
|
+
): Effect<AEff, InferE<Eff>, InferR<Eff>>
|
|
60
|
+
export function effect<
|
|
61
|
+
Eff extends YieldWrap<Effect<any, any, any>>,
|
|
62
|
+
AEff,
|
|
63
|
+
Args extends any[]
|
|
64
|
+
>(
|
|
65
|
+
f: (...args: Args) => Generator<Eff, AEff, never>
|
|
66
|
+
): (...args: Args) => Effect<AEff, InferE<Eff>, InferR<Eff>>
|
|
67
|
+
export function effect<
|
|
68
|
+
Self,
|
|
69
|
+
Eff extends YieldWrap<Effect<any, any, any>>,
|
|
70
|
+
AEff
|
|
71
|
+
>(
|
|
72
|
+
self: Self,
|
|
73
|
+
f: (this: Self) => Generator<Eff, AEff, never>
|
|
74
|
+
): Effect<AEff, InferE<Eff>, InferR<Eff>>
|
|
75
|
+
export function effect<
|
|
76
|
+
Eff extends YieldWrap<Effect<any, any, any>>,
|
|
77
|
+
AEff,
|
|
78
|
+
Args extends any[],
|
|
79
|
+
Self
|
|
80
|
+
>(
|
|
81
|
+
self: Self,
|
|
82
|
+
f: (this: Self, ...args: Args) => Generator<Eff, AEff, never>
|
|
83
|
+
): (...args: Args) => Effect<AEff, InferE<Eff>, InferR<Eff>>
|
|
84
|
+
export function effect() {
|
|
85
|
+
const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])
|
|
86
|
+
if (f.length === 0) return Effect.gen(f)
|
|
87
|
+
return (...args: any) => Effect.gen(() => f(...args))
|
|
88
|
+
}
|
package/src/logger.ts
CHANGED
package/src/transform.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { Option } from "effect"
|
|
3
|
+
import type { NonEmptyReadonlyArray } from "effect/Array"
|
|
4
|
+
import type { Misc, Union } from "ts-toolbelt"
|
|
5
|
+
import type * as SET from "./Set.js"
|
|
6
|
+
|
|
7
|
+
// type SomeObject = {
|
|
8
|
+
// 0: Option<string>
|
|
9
|
+
// a: {
|
|
10
|
+
// b: Option<string>
|
|
11
|
+
// g: Option<Option<string>>
|
|
12
|
+
// h: Option<{ i: Option<boolean> }>
|
|
13
|
+
// }
|
|
14
|
+
// c: { d: Array<Option<{ e: Option<boolean> }>> }
|
|
15
|
+
// }
|
|
16
|
+
// type test0 = Transform<SomeObject>
|
|
17
|
+
// type test1 = Transform<SomeObject[]>
|
|
18
|
+
|
|
19
|
+
type OptOf<A> = Union.Exclude<
|
|
20
|
+
A extends Option.Some<infer X> ? X | null : A,
|
|
21
|
+
Option.None<any>
|
|
22
|
+
>
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
|
|
25
|
+
export type TransformRoot<O> = O extends Option.Option<any> ? Transform<OptOf<O>>
|
|
26
|
+
: Transform<O>
|
|
27
|
+
export type Transform<O> = O extends Misc.BuiltIn | Misc.Primitive ? O
|
|
28
|
+
: {
|
|
29
|
+
[K in keyof O]: OptOf<O[K]> extends infer X ? X extends (infer Y)[] ? OptOf<Transform<Y>>[]
|
|
30
|
+
: X extends NonEmptyReadonlyArray<infer Y> ? NonEmptyReadonlyArray<OptOf<Transform<Y>>>
|
|
31
|
+
: X extends SET.Set<infer Y> ? SET.Set<OptOf<Transform<Y>>>
|
|
32
|
+
: X extends readonly (infer Y)[] ? readonly OptOf<Transform<Y>>[]
|
|
33
|
+
: Transform<X>
|
|
34
|
+
: never
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const encodeOptsAsNullable = <T>(root: T): TransformRoot<T> => encodeOptsAsNullable_(root, new Map())
|
|
38
|
+
|
|
39
|
+
const encodeOptsAsNullable_ = (value: any, cacheMap: Map<any, any>): any => {
|
|
40
|
+
const cacheEntry = cacheMap.get(value)
|
|
41
|
+
if (cacheEntry) {
|
|
42
|
+
return cacheEntry
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
const newAr: typeof value = []
|
|
47
|
+
cacheMap.set(value, newAr)
|
|
48
|
+
value.forEach((x) => newAr.push(encodeOptsAsNullable_(x, cacheMap)))
|
|
49
|
+
return newAr
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
value instanceof Date
|
|
54
|
+
|| value instanceof Function
|
|
55
|
+
|| value instanceof Promise
|
|
56
|
+
) {
|
|
57
|
+
return value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (value instanceof Set) {
|
|
61
|
+
const newValue = [...value]
|
|
62
|
+
cacheMap.set(value, newValue)
|
|
63
|
+
return newValue
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (value instanceof Object) {
|
|
67
|
+
if (value._tag === "Some" || value._tag === "None") {
|
|
68
|
+
const v = value as Option.Option<unknown>
|
|
69
|
+
return encodeOptsAsNullable_(Option.getOrNull(v), cacheMap)
|
|
70
|
+
}
|
|
71
|
+
const newObj = {} as Record<string, any>
|
|
72
|
+
cacheMap.set(value, newObj)
|
|
73
|
+
|
|
74
|
+
Object.keys(value).forEach((key) => {
|
|
75
|
+
newObj[key] = encodeOptsAsNullable_(value[key], cacheMap)
|
|
76
|
+
})
|
|
77
|
+
return newObj
|
|
78
|
+
}
|
|
79
|
+
return value
|
|
80
|
+
}
|