effect-app 4.0.0-beta.27 → 4.0.0-beta.271
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 +1269 -0
- package/dist/Array.d.ts +2 -1
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +4 -4
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +3 -1
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +3 -6
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Config.d.ts +2 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +8 -0
- package/dist/ConfigProvider.d.ts +2 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +6 -0
- package/dist/{ServiceMap.d.ts → Context.d.ts} +18 -20
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/Effect.d.ts +10 -9
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -8
- package/dist/Emailer.d.ts +51 -0
- package/dist/Emailer.d.ts.map +1 -0
- package/dist/Emailer.js +7 -0
- package/dist/Function.d.ts.map +1 -1
- package/dist/Layer.d.ts +10 -6
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +3 -2
- package/dist/Model/Repository/Registry.d.ts +22 -0
- package/dist/Model/Repository/Registry.d.ts.map +1 -0
- package/dist/Model/Repository/Registry.js +18 -0
- package/dist/Model/Repository/ext.d.ts +60 -0
- package/dist/Model/Repository/ext.d.ts.map +1 -0
- package/dist/Model/Repository/ext.js +122 -0
- package/dist/Model/Repository/internal/internal.d.ts +63 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +430 -0
- package/dist/Model/Repository/legacy.d.ts +21 -0
- package/dist/Model/Repository/legacy.d.ts.map +1 -0
- package/dist/Model/Repository/legacy.js +2 -0
- package/dist/Model/Repository/makeRepo.d.ts +54 -0
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
- package/dist/Model/Repository/makeRepo.js +27 -0
- package/dist/Model/Repository/service.d.ts +121 -0
- package/dist/Model/Repository/service.d.ts.map +1 -0
- package/dist/Model/Repository/service.js +2 -0
- package/dist/Model/Repository/validation.d.ts +58 -0
- package/dist/Model/Repository/validation.d.ts.map +1 -0
- package/dist/Model/Repository/validation.js +32 -0
- package/dist/Model/Repository.d.ts +7 -0
- package/dist/Model/Repository.d.ts.map +1 -0
- package/dist/Model/Repository.js +7 -0
- package/dist/Model/dsl.d.ts +33 -0
- package/dist/Model/dsl.d.ts.map +1 -0
- package/dist/Model/dsl.js +43 -0
- package/dist/Model/filter/filterApi.d.ts +30 -0
- package/dist/Model/filter/filterApi.d.ts.map +1 -0
- package/dist/Model/filter/filterApi.js +2 -0
- package/dist/Model/filter/types/errors.d.ts +29 -0
- package/dist/Model/filter/types/errors.d.ts.map +1 -0
- package/dist/Model/filter/types/errors.js +2 -0
- package/dist/Model/filter/types/fields.d.ts +15 -0
- package/dist/Model/filter/types/fields.d.ts.map +1 -0
- package/dist/Model/filter/types/fields.js +2 -0
- package/dist/Model/filter/types/path/common.d.ts +316 -0
- package/dist/Model/filter/types/path/common.d.ts.map +1 -0
- package/dist/Model/filter/types/path/common.js +2 -0
- package/dist/Model/filter/types/path/eager.d.ts +94 -0
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
- package/dist/Model/filter/types/path/eager.js +36 -0
- package/dist/Model/filter/types/path/index.d.ts +4 -0
- package/dist/Model/filter/types/path/index.d.ts.map +1 -0
- package/dist/Model/filter/types/path/index.js +3 -0
- package/dist/Model/filter/types/utils.d.ts +79 -0
- package/dist/Model/filter/types/utils.d.ts.map +1 -0
- package/dist/Model/filter/types/utils.js +2 -0
- package/dist/Model/filter/types/validator.d.ts +30 -0
- package/dist/Model/filter/types/validator.d.ts.map +1 -0
- package/dist/Model/filter/types/validator.js +2 -0
- package/dist/Model/filter/types.d.ts +5 -0
- package/dist/Model/filter/types.d.ts.map +1 -0
- package/dist/Model/filter/types.js +7 -0
- package/dist/Model/query/dsl.d.ts +493 -0
- package/dist/Model/query/dsl.d.ts.map +1 -0
- package/dist/Model/query/dsl.js +376 -0
- package/dist/Model/query/new-kid-interpreter.d.ts +136 -0
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
- package/dist/Model/query/new-kid-interpreter.js +336 -0
- package/dist/Model/query.d.ts +15 -0
- package/dist/Model/query.d.ts.map +1 -0
- package/dist/Model/query.js +3 -0
- package/dist/Model.d.ts +5 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +5 -0
- package/dist/NonEmptySet.d.ts +3 -1
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/NonEmptySet.js +2 -2
- package/dist/Option.d.ts +1 -0
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -1
- package/dist/Pure.d.ts +7 -5
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +17 -14
- package/dist/QueueMaker.d.ts +13 -0
- package/dist/QueueMaker.d.ts.map +1 -0
- package/dist/QueueMaker.js +4 -0
- package/dist/RequestContext.d.ts +208 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +54 -0
- package/dist/Schema/Class.d.ts +157 -19
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +214 -17
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/SchemaParser.d.ts +5 -0
- package/dist/Schema/SchemaParser.d.ts.map +1 -0
- package/dist/Schema/SchemaParser.js +6 -0
- package/dist/Schema/SpecialJsonSchema.d.ts +34 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +118 -0
- package/dist/Schema/SpecialOpenApi.d.ts +32 -0
- package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
- package/dist/Schema/SpecialOpenApi.js +123 -0
- package/dist/Schema/brand.d.ts +4 -2
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +3 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +7 -4
- package/dist/Schema/ext.d.ts +338 -55
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +358 -53
- package/dist/Schema/moreStrings.d.ts +82 -36
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +49 -42
- package/dist/Schema/numbers.d.ts +34 -21
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +55 -12
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -3
- package/dist/Schema/strings.d.ts +18 -4
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +213 -7
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +190 -11
- package/dist/Set.d.ts +4 -1
- package/dist/Set.d.ts.map +1 -1
- package/dist/Set.js +3 -2
- package/dist/Store.d.ts +170 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +121 -0
- package/dist/_ext/Array.d.ts +1 -1
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/Array.js +4 -2
- package/dist/_ext/misc.d.ts +4 -1
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +4 -2
- package/dist/_ext/ord.ext.d.ts +2 -1
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/_ext/ord.ext.js +2 -2
- package/dist/client/InvalidationKeys.d.ts +29 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +33 -0
- package/dist/client/apiClientFactory.d.ts +19 -31
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +104 -34
- package/dist/client/clientFor.d.ts +52 -18
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +82 -27
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +75 -19
- package/dist/client/makeClient.d.ts +494 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +66 -24
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +1 -1
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +2 -2
- package/dist/ids.d.ts +42 -14
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +30 -5
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/middleware.d.ts +13 -7
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +14 -8
- package/dist/rpc/Invalidation.d.ts +420 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +168 -0
- package/dist/rpc/MiddlewareMaker.d.ts +11 -7
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +59 -38
- package/dist/rpc/RpcContextMap.d.ts +3 -3
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +14 -10
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +40 -0
- package/dist/setupRequest.d.ts +19 -0
- package/dist/setupRequest.d.ts.map +1 -0
- package/dist/setupRequest.js +69 -0
- package/dist/toast.d.ts +51 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +34 -0
- package/dist/transform.d.ts +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +4 -5
- package/dist/utils/effectify.d.ts +1 -1
- package/dist/utils/effectify.d.ts.map +1 -1
- package/dist/utils/effectify.js +2 -2
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +4 -4
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +2 -2
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +4 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +4 -4
- package/dist/utils.d.ts +34 -39
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -37
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/withToast.d.ts +30 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +64 -0
- package/package.json +22 -247
- package/src/Array.ts +5 -5
- package/src/Chunk.ts +3 -3
- package/src/Config/SecretURL.ts +6 -3
- package/src/Config/internal/configSecretURL.ts +2 -2
- package/src/Config.ts +7 -0
- package/src/ConfigProvider.ts +5 -0
- package/src/{ServiceMap.ts → Context.ts} +56 -63
- package/src/Effect.ts +14 -16
- package/src/Emailer.ts +51 -0
- package/src/Inputify.type.ts +1 -1
- package/src/Layer.ts +11 -7
- package/src/Model/Repository/Registry.ts +35 -0
- package/src/Model/Repository/ext.ts +375 -0
- package/src/Model/Repository/internal/internal.ts +741 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +145 -0
- package/src/Model/Repository/service.ts +676 -0
- package/src/Model/Repository/validation.ts +31 -0
- package/src/Model/Repository.ts +6 -0
- package/src/Model/dsl.ts +129 -0
- package/src/Model/filter/filterApi.ts +60 -0
- package/src/Model/filter/types/errors.ts +47 -0
- package/src/Model/filter/types/fields.ts +50 -0
- package/src/Model/filter/types/path/common.ts +404 -0
- package/src/Model/filter/types/path/eager.ts +329 -0
- package/src/Model/filter/types/path/index.ts +4 -0
- package/src/Model/filter/types/utils.ts +128 -0
- package/src/Model/filter/types/validator.ts +46 -0
- package/src/Model/filter/types.ts +6 -0
- package/src/Model/query/dsl.ts +2694 -0
- package/src/Model/query/new-kid-interpreter.ts +484 -0
- package/src/Model/query.ts +13 -0
- package/src/Model.ts +4 -0
- package/src/NonEmptySet.ts +6 -4
- package/src/Option.ts +2 -0
- package/src/Pure.ts +22 -20
- package/src/QueueMaker.ts +19 -0
- package/src/RequestContext.ts +95 -0
- package/src/Schema/Class.ts +517 -59
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +139 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +22 -2
- package/src/Schema/email.ts +9 -4
- package/src/Schema/ext.ts +446 -91
- package/src/Schema/moreStrings.ts +147 -68
- package/src/Schema/numbers.ts +97 -28
- package/src/Schema/phoneNumber.ts +9 -5
- package/src/Schema/strings.ts +23 -14
- package/src/Schema.ts +389 -25
- package/src/Set.ts +6 -2
- package/src/Store.ts +277 -0
- package/src/_ext/Array.ts +4 -2
- package/src/_ext/misc.ts +4 -1
- package/src/_ext/ord.ext.ts +2 -1
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +234 -135
- package/src/client/clientFor.ts +105 -34
- package/src/client/errors.ts +100 -29
- package/src/client/makeClient.ts +594 -73
- package/src/client.ts +5 -4
- package/src/http/Request.ts +3 -3
- package/src/http.ts +1 -1
- package/src/ids.ts +33 -6
- package/src/index.ts +20 -23
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +261 -0
- package/src/rpc/MiddlewareMaker.ts +88 -80
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +7 -6
- package/src/rpc/RpcMiddleware.ts +19 -13
- package/src/rpc.ts +4 -4
- package/src/runtime.ts +56 -0
- package/src/setupRequest.ts +134 -0
- package/src/toast.ts +54 -0
- package/src/transform.ts +4 -4
- package/src/utils/effectify.ts +1 -1
- package/src/utils/gen.ts +8 -8
- package/src/utils/logLevel.ts +1 -1
- package/src/utils/logger.ts +4 -3
- package/src/utils.ts +85 -158
- package/src/validation.ts +2 -2
- package/src/withToast.ts +133 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/moreStrings.test.ts +1 -1
- package/test/rpc.test.ts +46 -6
- package/test/schema.test.ts +459 -30
- package/test/secretURL.test.ts +160 -0
- package/test/special.test.ts +1026 -0
- package/test/utils.test.ts +7 -7
- package/tsconfig.base.json +6 -5
- package/tsconfig.json +3 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -123
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js +0 -91
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
package/src/toast.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as Context from "./Context.ts"
|
|
2
|
+
import { accessEffectFn } from "./Context.ts"
|
|
3
|
+
import * as Effect from "./Effect.ts"
|
|
4
|
+
import * as Option from "./Option.ts"
|
|
5
|
+
|
|
6
|
+
export type ToastId = string | number
|
|
7
|
+
export type ToastOpts = { id?: ToastId; timeout?: number; groupId?: string; requestId?: string }
|
|
8
|
+
export type ToastOptsInternal = { id?: ToastId | null; timeout?: number; groupId?: string; requestId?: string }
|
|
9
|
+
|
|
10
|
+
export type UseToast = () => {
|
|
11
|
+
error: (this: void, message: string, options?: ToastOpts) => ToastId
|
|
12
|
+
warning: (this: void, message: string, options?: ToastOpts) => ToastId
|
|
13
|
+
success: (this: void, message: string, options?: ToastOpts) => ToastId
|
|
14
|
+
info: (this: void, message: string, options?: ToastOpts) => ToastId
|
|
15
|
+
dismiss: (this: void, id: ToastId) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class CurrentToastId extends Context.Opaque<CurrentToastId, { toastId: ToastId }>()("CurrentToastId") {}
|
|
19
|
+
|
|
20
|
+
/** fallback to CurrentToastId when available unless id is explicitly set to a value or null */
|
|
21
|
+
export const wrap = (toast: ReturnType<UseToast>) => {
|
|
22
|
+
const wrap = (toastHandler: (message: string, options?: ToastOpts) => ToastId) => {
|
|
23
|
+
return (message: string, options?: ToastOptsInternal) =>
|
|
24
|
+
Effect.serviceOption(CurrentToastId).pipe(
|
|
25
|
+
Effect.flatMap((currentToast) =>
|
|
26
|
+
Effect.sync(() => {
|
|
27
|
+
const { id: _id, ...rest } = options ?? {}
|
|
28
|
+
const id = _id !== undefined
|
|
29
|
+
? _id ?? undefined
|
|
30
|
+
: Option.getOrUndefined(Option.map(currentToast, (_) => _.toastId))
|
|
31
|
+
// when id is undefined, we may end up with no toast at all..
|
|
32
|
+
return toastHandler(message, id !== undefined ? { ...rest, id } : rest)
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
error: wrap(toast.error),
|
|
39
|
+
info: wrap(toast.info),
|
|
40
|
+
success: wrap(toast.success),
|
|
41
|
+
warning: wrap(toast.warning),
|
|
42
|
+
dismiss: (toastId: ToastId) => Effect.sync(() => toast.dismiss(toastId))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type ToastShape = ReturnType<typeof wrap>
|
|
47
|
+
|
|
48
|
+
export class Toast extends Context.Opaque<Toast, ToastShape>()("Toast") {
|
|
49
|
+
static readonly error = accessEffectFn(this, "error")
|
|
50
|
+
static readonly info = accessEffectFn(this, "info")
|
|
51
|
+
static readonly success = accessEffectFn(this, "success")
|
|
52
|
+
static readonly warning = accessEffectFn(this, "warning")
|
|
53
|
+
static readonly dismiss = accessEffectFn(this, "dismiss")
|
|
54
|
+
}
|
package/src/transform.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Option } from "effect"
|
|
3
2
|
import type { NonEmptyReadonlyArray } from "effect/Array"
|
|
3
|
+
import * as Option from "effect/Option"
|
|
4
4
|
import type { Misc, Union } from "ts-toolbelt"
|
|
5
|
-
import type * as SET from "./Set.
|
|
5
|
+
import type * as SET from "./Set.ts"
|
|
6
6
|
|
|
7
7
|
// type SomeObject = {
|
|
8
8
|
// 0: Option.Option<string>
|
|
@@ -51,8 +51,8 @@ const encodeOptsAsNullable_ = (value: any, cacheMap: Map<any, any>): any => {
|
|
|
51
51
|
|
|
52
52
|
if (
|
|
53
53
|
value instanceof Date
|
|
54
|
-
|| value
|
|
55
|
-
|| value
|
|
54
|
+
|| typeof value === "function"
|
|
55
|
+
|| (typeof value === "object" && value !== null && "then" in value && typeof value.then === "function")
|
|
56
56
|
) {
|
|
57
57
|
return value
|
|
58
58
|
}
|
package/src/utils/effectify.ts
CHANGED
package/src/utils/gen.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { type Effect
|
|
1
|
+
import { type Effect } from "effect/Effect"
|
|
2
2
|
|
|
3
3
|
export namespace EffectGenUtils {
|
|
4
4
|
export type Success<EG> = EG extends Effect<infer A, infer _E, infer _R> ? A
|
|
5
5
|
// there could be a case where the generator function does not yield anything, so we need to handle that
|
|
6
6
|
: EG extends (..._: infer _3) => Generator<never, infer A, infer _2> ? A
|
|
7
|
-
//
|
|
8
|
-
: EG extends (..._: infer _3) => Generator<
|
|
7
|
+
// generators yield Effect values
|
|
8
|
+
: EG extends (..._: infer _3) => Generator<Effect<any, infer _E, infer _R>, infer A, infer _2> ? A
|
|
9
9
|
: never
|
|
10
10
|
|
|
11
11
|
export type Error<EG> = EG extends Effect<infer _A, infer E, infer _R> ? E
|
|
12
12
|
// there could be a case where the generator function does not yield anything, so we need to handle that
|
|
13
13
|
: EG extends (..._: infer _3) => Generator<never, infer _A, infer _2> ? never
|
|
14
|
-
//
|
|
15
|
-
: EG extends (..._: infer _3) => Generator<
|
|
14
|
+
// generators yield Effect values
|
|
15
|
+
: EG extends (..._: infer _3) => Generator<Effect<any, infer E, infer _R>, infer _A, infer _2> ? E
|
|
16
16
|
: never
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type Context<EG> = EG extends Effect<infer _A, infer _E, infer R> ? R
|
|
19
19
|
// there could be a case where the generator function does not yield anything, so we need to handle that
|
|
20
20
|
: EG extends (..._: infer _3) => Generator<never, infer _A, infer _2> ? never
|
|
21
|
-
//
|
|
22
|
-
: EG extends (..._: infer _3) => Generator<
|
|
21
|
+
// generators yield Effect values
|
|
22
|
+
: EG extends (..._: infer _3) => Generator<Effect<any, infer _E, infer R>, infer _A, infer _2> ? R
|
|
23
23
|
: never
|
|
24
24
|
}
|
package/src/utils/logLevel.ts
CHANGED
package/src/utils/logger.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
4
|
+
import * as Effect from "effect/Effect"
|
|
5
|
+
import type * as LogLevel from "effect/LogLevel"
|
|
6
|
+
import * as Context from "../Context.ts"
|
|
6
7
|
|
|
7
8
|
type Levels = "info" | "debug" | "warn" | "error"
|
|
8
9
|
|
|
9
|
-
export class LogLevels extends
|
|
10
|
+
export class LogLevels extends Context.Reference("LogLevels", {
|
|
10
11
|
defaultValue: () => new Map<string, Levels>()
|
|
11
12
|
}) {}
|
|
12
13
|
|
package/src/utils.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
|
4
|
-
import
|
|
4
|
+
import * as Cause from "effect/Cause"
|
|
5
|
+
import * as Effect from "effect/Effect"
|
|
6
|
+
import * as Exit from "effect/Exit"
|
|
7
|
+
import * as Fiber from "effect/Fiber"
|
|
5
8
|
import { dual } from "effect/Function"
|
|
6
|
-
import
|
|
9
|
+
import * as Option from "effect/Option"
|
|
10
|
+
import { isFunction } from "effect/Predicate"
|
|
11
|
+
import * as Record from "effect/Record"
|
|
7
12
|
import * as Result from "effect/Result"
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import type { DeepMutable, Equals, Mutable } from "./Types.js"
|
|
13
|
+
import { identity, pipe } from "./Function.ts"
|
|
14
|
+
import type { DeepMutable, Equals, Mutable } from "./Types.ts"
|
|
11
15
|
|
|
12
16
|
// codegen:start {preset: barrel, include: ./utils/*.ts, nodir: false }
|
|
13
|
-
export * from "./utils/effectify.
|
|
14
|
-
export * from "./utils/extend.
|
|
15
|
-
export * from "./utils/gen.
|
|
16
|
-
export * from "./utils/logger.
|
|
17
|
-
export * from "./utils/logLevel.
|
|
17
|
+
export * from "./utils/effectify.ts"
|
|
18
|
+
export * from "./utils/extend.ts"
|
|
19
|
+
export * from "./utils/gen.ts"
|
|
20
|
+
export * from "./utils/logger.ts"
|
|
21
|
+
export * from "./utils/logLevel.ts"
|
|
18
22
|
// codegen:end
|
|
19
23
|
|
|
20
24
|
export * from "effect/Utils"
|
|
@@ -24,121 +28,6 @@ export interface Clone {
|
|
|
24
28
|
[cloneTrait](this: this, that: any): this
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
function get<TObject extends object, TKey extends keyof TObject>(object: TObject, path: TKey | [TKey]): TObject[TKey]
|
|
28
|
-
function get<TObject extends object, TKey extends keyof TObject>(
|
|
29
|
-
object: TObject | null | undefined,
|
|
30
|
-
path: TKey | [TKey]
|
|
31
|
-
): TObject[TKey] | undefined
|
|
32
|
-
function get<TObject extends object, TKey extends keyof TObject, TDefault>(
|
|
33
|
-
object: TObject | null | undefined,
|
|
34
|
-
path: TKey | [TKey],
|
|
35
|
-
defaultValue: TDefault
|
|
36
|
-
): Exclude<TObject[TKey], undefined> | TDefault
|
|
37
|
-
function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(
|
|
38
|
-
object: TObject,
|
|
39
|
-
path: [TKey1, TKey2]
|
|
40
|
-
): TObject[TKey1][TKey2]
|
|
41
|
-
function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(
|
|
42
|
-
object: TObject | null | undefined,
|
|
43
|
-
path: [TKey1, TKey2]
|
|
44
|
-
): TObject[TKey1][TKey2] | undefined
|
|
45
|
-
function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TDefault>(
|
|
46
|
-
object: TObject | null | undefined,
|
|
47
|
-
path: [TKey1, TKey2],
|
|
48
|
-
defaultValue: TDefault
|
|
49
|
-
): Exclude<TObject[TKey1][TKey2], undefined> | TDefault
|
|
50
|
-
function get<
|
|
51
|
-
TObject extends object,
|
|
52
|
-
TKey1 extends keyof TObject,
|
|
53
|
-
TKey2 extends keyof TObject[TKey1],
|
|
54
|
-
TKey3 extends keyof TObject[TKey1][TKey2]
|
|
55
|
-
>(object: TObject, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3]
|
|
56
|
-
function get<
|
|
57
|
-
TObject extends object,
|
|
58
|
-
TKey1 extends keyof TObject,
|
|
59
|
-
TKey2 extends keyof TObject[TKey1],
|
|
60
|
-
TKey3 extends keyof TObject[TKey1][TKey2]
|
|
61
|
-
>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3] | undefined
|
|
62
|
-
function get<
|
|
63
|
-
TObject extends object,
|
|
64
|
-
TKey1 extends keyof TObject,
|
|
65
|
-
TKey2 extends keyof TObject[TKey1],
|
|
66
|
-
TKey3 extends keyof TObject[TKey1][TKey2],
|
|
67
|
-
TDefault
|
|
68
|
-
>(
|
|
69
|
-
object: TObject | null | undefined,
|
|
70
|
-
path: [TKey1, TKey2, TKey3],
|
|
71
|
-
defaultValue: TDefault
|
|
72
|
-
): Exclude<TObject[TKey1][TKey2][TKey3], undefined> | TDefault
|
|
73
|
-
function get<
|
|
74
|
-
TObject extends object,
|
|
75
|
-
TKey1 extends keyof TObject,
|
|
76
|
-
TKey2 extends keyof TObject[TKey1],
|
|
77
|
-
TKey3 extends keyof TObject[TKey1][TKey2],
|
|
78
|
-
TKey4 extends keyof TObject[TKey1][TKey2][TKey3]
|
|
79
|
-
>(object: TObject, path: [TKey1, TKey2, TKey3, TKey4]): TObject[TKey1][TKey2][TKey3][TKey4]
|
|
80
|
-
function get<
|
|
81
|
-
TObject extends object,
|
|
82
|
-
TKey1 extends keyof TObject,
|
|
83
|
-
TKey2 extends keyof TObject[TKey1],
|
|
84
|
-
TKey3 extends keyof TObject[TKey1][TKey2],
|
|
85
|
-
TKey4 extends keyof TObject[TKey1][TKey2][TKey3]
|
|
86
|
-
>(
|
|
87
|
-
object: TObject | null | undefined,
|
|
88
|
-
path: [TKey1, TKey2, TKey3, TKey4]
|
|
89
|
-
): TObject[TKey1][TKey2][TKey3][TKey4] | undefined
|
|
90
|
-
function get<
|
|
91
|
-
TObject extends object,
|
|
92
|
-
TKey1 extends keyof TObject,
|
|
93
|
-
TKey2 extends keyof TObject[TKey1],
|
|
94
|
-
TKey3 extends keyof TObject[TKey1][TKey2],
|
|
95
|
-
TKey4 extends keyof TObject[TKey1][TKey2][TKey3],
|
|
96
|
-
TDefault
|
|
97
|
-
>(
|
|
98
|
-
object: TObject | null | undefined,
|
|
99
|
-
path: [TKey1, TKey2, TKey3, TKey4],
|
|
100
|
-
defaultValue: TDefault
|
|
101
|
-
): Exclude<TObject[TKey1][TKey2][TKey3][TKey4], undefined> | TDefault
|
|
102
|
-
function get<T>(object: NumericDictionary<T>, path: number): T
|
|
103
|
-
function get<T>(object: NumericDictionary<T> | null | undefined, path: number): T | undefined
|
|
104
|
-
function get<T, TDefault>(
|
|
105
|
-
object: NumericDictionary<T> | null | undefined,
|
|
106
|
-
path: number,
|
|
107
|
-
defaultValue: TDefault
|
|
108
|
-
): T | TDefault
|
|
109
|
-
function get<TDefault>(object: null | undefined, path: PropertyPath, defaultValue: TDefault): TDefault
|
|
110
|
-
function get(object: null | undefined, path: PropertyPath): undefined
|
|
111
|
-
function get<TObject, TPath extends string>(
|
|
112
|
-
data: TObject,
|
|
113
|
-
path: TPath
|
|
114
|
-
): string extends TPath ? any : GetFieldType<TObject, TPath>
|
|
115
|
-
function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPath>>(
|
|
116
|
-
data: TObject,
|
|
117
|
-
path: TPath,
|
|
118
|
-
defaultValue: TDefault
|
|
119
|
-
): Exclude<GetFieldType<TObject, TPath>, null | undefined> | TDefault
|
|
120
|
-
function get(object: any, path: PropertyPath, defaultValue?: any): any
|
|
121
|
-
function get(obj: any, path: any, defaultValue = undefined) {
|
|
122
|
-
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore?tab=readme-ov-file#_get
|
|
123
|
-
const travel = (regexp: any) =>
|
|
124
|
-
String
|
|
125
|
-
.prototype
|
|
126
|
-
.split
|
|
127
|
-
.call(path, regexp)
|
|
128
|
-
.filter(Boolean)
|
|
129
|
-
.reduce((res, key) => (res !== null && res !== undefined ? res[key] : res), obj)
|
|
130
|
-
const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/)
|
|
131
|
-
return result === undefined || result === obj ? defaultValue : result
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// codegen:start {preset: barrel, include: ./utils/*.ts }
|
|
135
|
-
export * from "./utils/effectify.js"
|
|
136
|
-
export * from "./utils/extend.js"
|
|
137
|
-
export * from "./utils/gen.js"
|
|
138
|
-
export * from "./utils/logger.js"
|
|
139
|
-
export * from "./utils/logLevel.js"
|
|
140
|
-
// codegen:end
|
|
141
|
-
|
|
142
31
|
export const unsafeRight = <E, A>(ei: Result.Result<A, E>) => {
|
|
143
32
|
if (Result.isFailure(ei)) {
|
|
144
33
|
console.error(ei.failure)
|
|
@@ -269,7 +158,7 @@ export type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R
|
|
|
269
158
|
export function intersect<AS extends unknown[] & { 0: unknown }>(
|
|
270
159
|
...as: AS
|
|
271
160
|
): UnionToIntersection<{ [k in keyof AS]: AS[k] }[number]> {
|
|
272
|
-
return as.reduce((a: any, b: any) => (
|
|
161
|
+
return as.reduce((a: any, b: any) => Object.assign(a, b), {}) as any
|
|
273
162
|
}
|
|
274
163
|
|
|
275
164
|
export type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
@@ -280,8 +169,7 @@ export type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
|
280
169
|
export const unifyIndex = Symbol()
|
|
281
170
|
export type unifyIndex = typeof unifyIndex
|
|
282
171
|
|
|
283
|
-
|
|
284
|
-
export interface UnifiableIndexed<X> {}
|
|
172
|
+
export interface UnifiableIndexed<_X> {}
|
|
285
173
|
export type UnifiableIndexedURI = keyof UnifiableIndexed<any>
|
|
286
174
|
|
|
287
175
|
export interface Unifiable<X> {
|
|
@@ -313,9 +201,7 @@ function decorateNew(
|
|
|
313
201
|
if (out.descriptor) {
|
|
314
202
|
out.descriptor = Object.assign({}, out.descriptor)
|
|
315
203
|
}
|
|
316
|
-
const actualDesc: PropertyDescriptor =
|
|
317
|
-
out.descriptor || /* istanbul ignore next */ out
|
|
318
|
-
)
|
|
204
|
+
const actualDesc: PropertyDescriptor = out.descriptor || /* istanbul ignore next */ out
|
|
319
205
|
|
|
320
206
|
const originalMethod = validateAndExtractMethodFromDescriptor(actualDesc)
|
|
321
207
|
const isStatic = inp.placement === "static"
|
|
@@ -342,7 +228,7 @@ function decorateNew(
|
|
|
342
228
|
function decorateLegacy(
|
|
343
229
|
target: any,
|
|
344
230
|
key: PropertyKey,
|
|
345
|
-
descriptor: PropertyDescriptor,
|
|
231
|
+
descriptor: PropertyDescriptor | undefined,
|
|
346
232
|
setProto: boolean,
|
|
347
233
|
makeNonConfigurable: boolean,
|
|
348
234
|
// tslint:enable:bool-param-default
|
|
@@ -350,11 +236,12 @@ function decorateLegacy(
|
|
|
350
236
|
): PropertyDescriptor {
|
|
351
237
|
/* istanbul ignore if */
|
|
352
238
|
if (!descriptor) {
|
|
353
|
-
descriptor =
|
|
239
|
+
descriptor = Object.getOwnPropertyDescriptor(target, key)
|
|
354
240
|
if (!descriptor) {
|
|
355
|
-
const e = new Error("@LazyGetter is unable to determine the property descriptor")
|
|
356
|
-
|
|
357
|
-
|
|
241
|
+
const e = Object.assign(new Error("@LazyGetter is unable to determine the property descriptor"), {
|
|
242
|
+
$key: key,
|
|
243
|
+
$target: target
|
|
244
|
+
})
|
|
358
245
|
throw e
|
|
359
246
|
}
|
|
360
247
|
}
|
|
@@ -409,7 +296,7 @@ function defaultFilter(): boolean {
|
|
|
409
296
|
|
|
410
297
|
function validateAndExtractMethodFromDescriptor(desc: PropertyDescriptor): Function {
|
|
411
298
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
412
|
-
const originalMethod =
|
|
299
|
+
const originalMethod = desc.get
|
|
413
300
|
|
|
414
301
|
if (!originalMethod) {
|
|
415
302
|
throw new Error("@LazyGetter can only decorate getters!")
|
|
@@ -432,7 +319,7 @@ function getterCommon( // tslint:disable-line:parameters-max-number
|
|
|
432
319
|
makeNonConfigurable: boolean,
|
|
433
320
|
resultSelector: ResultSelectorFn
|
|
434
321
|
): any {
|
|
435
|
-
const value = originalMethod.apply(thisArg,
|
|
322
|
+
const value = originalMethod.apply(thisArg, args)
|
|
436
323
|
|
|
437
324
|
if (resultSelector(value)) {
|
|
438
325
|
const newDescriptor: PropertyDescriptor = {
|
|
@@ -467,23 +354,23 @@ export function LazyGetter(
|
|
|
467
354
|
): MethodDecorator & ResettableDescriptor {
|
|
468
355
|
let desc: PropertyDescriptor
|
|
469
356
|
let prop: PropertyKey
|
|
470
|
-
let args:
|
|
357
|
+
let args: [targetOrDesc: any, key: PropertyKey | undefined, descriptor: PropertyDescriptor | undefined] | undefined
|
|
471
358
|
let isLegacy: boolean
|
|
472
359
|
|
|
473
360
|
function decorator(
|
|
474
361
|
targetOrDesc: any,
|
|
475
|
-
key: PropertyKey,
|
|
476
|
-
descriptor: PropertyDescriptor
|
|
362
|
+
key: PropertyKey | undefined,
|
|
363
|
+
descriptor: PropertyDescriptor | undefined
|
|
477
364
|
): DecoratorReturn {
|
|
478
|
-
|
|
479
|
-
args = arguments
|
|
365
|
+
args = [targetOrDesc, key, descriptor]
|
|
480
366
|
if (key === undefined) {
|
|
481
367
|
if (typeof desc === "undefined") {
|
|
368
|
+
const newDescriptor = targetOrDesc as NewDescriptor
|
|
482
369
|
isLegacy = false
|
|
483
|
-
prop =
|
|
370
|
+
prop = newDescriptor.key
|
|
484
371
|
desc = Object.assign(
|
|
485
372
|
{},
|
|
486
|
-
|
|
373
|
+
newDescriptor.descriptor
|
|
487
374
|
/* istanbul ignore next */ || targetOrDesc
|
|
488
375
|
)
|
|
489
376
|
}
|
|
@@ -525,11 +412,14 @@ export function LazyGetter(
|
|
|
525
412
|
"Unable to restore descriptor. Did you remember to apply your decorator to a method?"
|
|
526
413
|
)
|
|
527
414
|
}
|
|
415
|
+
if (!args) {
|
|
416
|
+
throw new Error("Unable to restore descriptor before applying the decorator.")
|
|
417
|
+
}
|
|
528
418
|
// Restore descriptor to its original state
|
|
529
419
|
Object.defineProperty(on, prop, desc)
|
|
530
|
-
|
|
531
|
-
const ret:
|
|
532
|
-
Object.defineProperty(on, prop,
|
|
420
|
+
const ret = decorator.apply(null, args)
|
|
421
|
+
const restoredDescriptor = isLegacy ? ret : "descriptor" in ret && ret.descriptor ? ret.descriptor : ret
|
|
422
|
+
Object.defineProperty(on, prop, restoredDescriptor)
|
|
533
423
|
}
|
|
534
424
|
|
|
535
425
|
return decorator
|
|
@@ -684,7 +574,7 @@ export type OptPromise<T extends () => any> = (
|
|
|
684
574
|
) => Promise<ReturnType<T>> | ReturnType<T>
|
|
685
575
|
|
|
686
576
|
export function access<T extends string, T2>(t: Record<T, T2>) {
|
|
687
|
-
return (key: T) => t[key]
|
|
577
|
+
return (key: T) => t[key]
|
|
688
578
|
}
|
|
689
579
|
|
|
690
580
|
export function todayAtUTCNoon() {
|
|
@@ -736,25 +626,64 @@ export const copy = dual<
|
|
|
736
626
|
}
|
|
737
627
|
>(2, <A>(self: A, f: Partial<A> | ((a: A) => Partial<A>)) => clone(self, { ...self, ...(isFunction(f) ? f(self) : f) }))
|
|
738
628
|
|
|
739
|
-
type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
629
|
+
export type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
740
630
|
& {
|
|
741
631
|
[K in keyof U & keyof InstanceType<Ctor>]?: U[K]
|
|
742
632
|
}
|
|
743
633
|
& {}
|
|
744
634
|
|
|
745
|
-
type CopyOriginRet<A, U> =
|
|
635
|
+
export type CopyOriginRet<A, U> =
|
|
746
636
|
& {
|
|
747
637
|
[K in keyof A | keyof U]: K extends keyof U ? U[K] : A[K & keyof A]
|
|
748
638
|
}
|
|
749
639
|
& {}
|
|
750
640
|
|
|
751
|
-
type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
641
|
+
export type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
752
642
|
? Equals<keyof {}, keyof U> extends true ? `updates argument is empty or contains only extra properties`
|
|
753
643
|
: A
|
|
754
644
|
: A
|
|
755
645
|
|
|
646
|
+
export interface StructuralCopyOrigin<Self extends object> {
|
|
647
|
+
<A extends Self, U extends Partial<Self>>(
|
|
648
|
+
f: (a: A) =>
|
|
649
|
+
& {
|
|
650
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
651
|
+
}
|
|
652
|
+
& {}
|
|
653
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
654
|
+
<A extends Self, U extends Partial<Self>>(
|
|
655
|
+
updates:
|
|
656
|
+
& {
|
|
657
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
658
|
+
}
|
|
659
|
+
& {}
|
|
660
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
661
|
+
<A extends Self, U extends Partial<Self>>(
|
|
662
|
+
self: CopyOriginSelf<A, U>,
|
|
663
|
+
f: (a: A) =>
|
|
664
|
+
& {
|
|
665
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
666
|
+
}
|
|
667
|
+
& {}
|
|
668
|
+
): CopyOriginRet<A, U>
|
|
669
|
+
<A extends Self, U extends Partial<Self>>(
|
|
670
|
+
self: CopyOriginSelf<A, U>,
|
|
671
|
+
updates:
|
|
672
|
+
& {
|
|
673
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
674
|
+
}
|
|
675
|
+
& {}
|
|
676
|
+
): CopyOriginRet<A, U>
|
|
677
|
+
}
|
|
678
|
+
|
|
756
679
|
// just one input param: the convention is that the ctor takes an object
|
|
757
|
-
// containing the properties of the
|
|
680
|
+
// containing the properties of the value (I can't put object there as type because of contravariance)
|
|
681
|
+
/**
|
|
682
|
+
* By design this does not return `Self` directly.
|
|
683
|
+
*
|
|
684
|
+
* The return type is computed from `Self` and the update payload so callers can
|
|
685
|
+
* expose an explicit structural return type that remains assignable to `Self`.
|
|
686
|
+
*/
|
|
758
687
|
export const copyOrigin = <Ctor extends new(_: any) => any>(ctor: Ctor) =>
|
|
759
688
|
dual<
|
|
760
689
|
{
|
|
@@ -883,8 +812,6 @@ export function setMoveElDropUndefined<T>(el: T, newIndex: number) {
|
|
|
883
812
|
pipe([...arrInput], arMoveElDropUndefined(el, newIndex), Option.map((ar) => new Set(ar)))
|
|
884
813
|
}
|
|
885
814
|
|
|
886
|
-
export { get }
|
|
887
|
-
|
|
888
815
|
type RemoveNonArray<T> = T extends readonly any[] ? T : never
|
|
889
816
|
export function isNativeTuple<A>(a: A): a is RemoveNonArray<A> {
|
|
890
817
|
return Array.isArray(a)
|
|
@@ -956,7 +883,7 @@ const genConstructor = (function*() {}).constructor
|
|
|
956
883
|
/**
|
|
957
884
|
* @example
|
|
958
885
|
* ```ts
|
|
959
|
-
* import
|
|
886
|
+
* import * as Utils from "effect/Utils"
|
|
960
887
|
*
|
|
961
888
|
* function* generatorFn() {
|
|
962
889
|
* yield 1
|
|
@@ -970,5 +897,5 @@ const genConstructor = (function*() {}).constructor
|
|
|
970
897
|
* @category predicates
|
|
971
898
|
* @since 3.11.0
|
|
972
899
|
*/
|
|
973
|
-
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any
|
|
974
|
-
|
|
900
|
+
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any> =>
|
|
901
|
+
isFunction(u) && u.constructor === genConstructor
|
package/src/validation.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Predicate } from "./Function.
|
|
1
|
+
import type { Predicate } from "./Function.ts"
|
|
2
2
|
|
|
3
3
|
export const all_ = <T>(v: T, ...a: Predicate<T>[]) => !a.some((x) => !x(v))
|
|
4
4
|
export const all = <T>(...a: Predicate<T>[]) => (v: T) => all_(v, ...a)
|
|
@@ -15,4 +15,4 @@ export const min = (min: number) => {
|
|
|
15
15
|
return (v: { length: number }) => f(v.length)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export * from "./validation/validators.
|
|
18
|
+
export * from "./validation/validators.ts"
|
package/src/withToast.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as Cause from "effect/Cause"
|
|
2
|
+
import * as Fiber from "effect/Fiber"
|
|
3
|
+
import * as Context from "./Context.ts"
|
|
4
|
+
import * as Effect from "./Effect.ts"
|
|
5
|
+
import * as Layer from "./Layer.ts"
|
|
6
|
+
import type * as Option from "./Option.ts"
|
|
7
|
+
import * as S from "./Schema.ts"
|
|
8
|
+
import { CurrentToastId, Toast, type ToastId } from "./toast.ts"
|
|
9
|
+
import { wrapEffect } from "./utils.ts"
|
|
10
|
+
|
|
11
|
+
export interface ToastOptions<A, E, Args extends ReadonlyArray<unknown>, WaiR, SucR, ErrR> {
|
|
12
|
+
stableToastId?: undefined | string | ((...args: Args) => string | undefined)
|
|
13
|
+
timeout?: number
|
|
14
|
+
showSpanInfo?: false
|
|
15
|
+
groupId?: string
|
|
16
|
+
onWaiting:
|
|
17
|
+
| string
|
|
18
|
+
| ((...args: Args) => string | null)
|
|
19
|
+
| null
|
|
20
|
+
| ((
|
|
21
|
+
...args: Args
|
|
22
|
+
) => Effect.Effect<string | null, never, WaiR>)
|
|
23
|
+
onSuccess:
|
|
24
|
+
| string
|
|
25
|
+
| ((a: A, ...args: Args) => string | null)
|
|
26
|
+
| null
|
|
27
|
+
| ((
|
|
28
|
+
a: A,
|
|
29
|
+
...args: Args
|
|
30
|
+
) => Effect.Effect<string | null, never, SucR>)
|
|
31
|
+
onFailure:
|
|
32
|
+
| string
|
|
33
|
+
| ((
|
|
34
|
+
error: Option.Option<E>,
|
|
35
|
+
...args: Args
|
|
36
|
+
) => string | { level: "warn" | "error"; message: string })
|
|
37
|
+
| ((
|
|
38
|
+
error: Option.Option<E>,
|
|
39
|
+
...args: Args
|
|
40
|
+
) => Effect.Effect<string | { level: "warn" | "error"; message: string }, never, ErrR>)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// @effect-diagnostics-next-line missingEffectServiceDependency:off
|
|
44
|
+
export class WithToast extends Context.Service<WithToast>()("WithToast", {
|
|
45
|
+
make: Effect.gen(function*() {
|
|
46
|
+
const toast = yield* Toast
|
|
47
|
+
return <A, E, Args extends readonly unknown[], R, WaiR = never, SucR = never, ErrR = never>(
|
|
48
|
+
options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
|
|
49
|
+
) =>
|
|
50
|
+
Effect.fnUntraced(function*(self: Effect.Effect<A, E, R>, ...args: Args) {
|
|
51
|
+
const baseTimeout = options.timeout ?? 3_000
|
|
52
|
+
|
|
53
|
+
const stableToastId = typeof options.stableToastId === "function"
|
|
54
|
+
? options.stableToastId(...args)
|
|
55
|
+
: options.stableToastId
|
|
56
|
+
|
|
57
|
+
const requestId: string = yield* Effect.currentSpan.pipe(
|
|
58
|
+
Effect.map((span) => span.traceId),
|
|
59
|
+
Effect.orElseSucceed(() => S.StringId.make())
|
|
60
|
+
)
|
|
61
|
+
const groupId = options.groupId
|
|
62
|
+
const meta = { ...(groupId !== undefined ? { groupId } : {}), requestId }
|
|
63
|
+
|
|
64
|
+
const t = yield* wrapEffect(options.onWaiting)(...args)
|
|
65
|
+
const toastId: ToastId | undefined = t === null
|
|
66
|
+
? stableToastId
|
|
67
|
+
: stableToastId ?? `wait-${Math.random().toString(36).slice(2)}`
|
|
68
|
+
|
|
69
|
+
const waitingFiber = t === null ? undefined : yield* Effect.forkChild(
|
|
70
|
+
Effect.sleep("1 seconds").pipe(
|
|
71
|
+
Effect.andThen(toast.info(t, { id: toastId!, timeout: Infinity, ...meta }))
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
const interruptWaiting = waitingFiber ? Fiber.interrupt(waitingFiber) : Effect.void
|
|
75
|
+
|
|
76
|
+
return yield* self.pipe(
|
|
77
|
+
Effect.tap(Effect.fnUntraced(function*(a) {
|
|
78
|
+
yield* interruptWaiting
|
|
79
|
+
const t = yield* wrapEffect(options.onSuccess)(a, ...args)
|
|
80
|
+
if (t === null) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
yield* toast.success(
|
|
84
|
+
t,
|
|
85
|
+
toastId !== undefined
|
|
86
|
+
? { id: toastId, timeout: baseTimeout, ...meta }
|
|
87
|
+
: { timeout: baseTimeout, ...meta }
|
|
88
|
+
)
|
|
89
|
+
})),
|
|
90
|
+
Effect.tapCause(Effect.fnUntraced(function*(cause) {
|
|
91
|
+
yield* interruptWaiting
|
|
92
|
+
yield* Effect.logDebug(
|
|
93
|
+
"WithToast - caught error cause: " + Cause.squash(cause),
|
|
94
|
+
Cause.hasInterruptsOnly(cause),
|
|
95
|
+
cause
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
if (Cause.hasInterruptsOnly(cause)) {
|
|
99
|
+
if (toastId) yield* toast.dismiss(toastId)
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const spanInfo = options.showSpanInfo !== false
|
|
104
|
+
? yield* Effect.currentSpan.pipe(
|
|
105
|
+
Effect.map((span) => `\nTrace: ${span.traceId}\nSpan: ${span.spanId}`),
|
|
106
|
+
Effect.orElseSucceed(() => "")
|
|
107
|
+
)
|
|
108
|
+
: ""
|
|
109
|
+
|
|
110
|
+
const t = yield* wrapEffect(options.onFailure)(Cause.findErrorOption(cause), ...args)
|
|
111
|
+
const opts = { timeout: baseTimeout * 2, ...meta }
|
|
112
|
+
|
|
113
|
+
if (typeof t === "object") {
|
|
114
|
+
const message = t.message + spanInfo
|
|
115
|
+
return t.level === "warn"
|
|
116
|
+
? yield* toast.warning(message, toastId !== undefined ? { ...opts, id: toastId } : opts)
|
|
117
|
+
: yield* toast.error(message, toastId !== undefined ? { ...opts, id: toastId } : opts)
|
|
118
|
+
}
|
|
119
|
+
yield* toast.error(t + spanInfo, toastId !== undefined ? { ...opts, id: toastId } : opts)
|
|
120
|
+
}, Effect.uninterruptible)),
|
|
121
|
+
toastId !== undefined ? Effect.provideService(CurrentToastId, CurrentToastId.of({ toastId })) : (_) => _
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
}) {
|
|
126
|
+
static readonly DefaultWithoutDependencies = Layer.effect(this, this.make)
|
|
127
|
+
static readonly Default = this.DefaultWithoutDependencies
|
|
128
|
+
|
|
129
|
+
static readonly handle = <A, E, Args extends Array<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
|
|
130
|
+
options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
|
|
131
|
+
): (self: Effect.Effect<A, E, R>, ...args: Args) => Effect.Effect<A, E, R | WaiR | SucR | ErrR | WithToast> =>
|
|
132
|
+
(self, ...args) => this.use((_) => _<A, E, Args, R, WaiR, SucR, ErrR>(options)(self, ...args))
|
|
133
|
+
}
|