effect-app 4.0.0-beta.26 → 4.0.0-beta.261
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 +1194 -0
- package/dist/Array.d.ts +3 -2
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +4 -4
- package/dist/Chunk.d.ts +1 -1
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +4 -2
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +3 -6
- package/dist/Config/internal/configSecretURL.d.ts +1 -1
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Config.d.ts +7 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +6 -0
- package/dist/ConfigProvider.d.ts +39 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +42 -0
- package/dist/Context.d.ts +42 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/DataDependencies.d.ts +158 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +39 -0
- package/dist/Effect.d.ts +13 -12
- 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 +1 -1
- package/dist/Function.d.ts.map +1 -1
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Layer.d.ts +11 -7
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +3 -2
- package/dist/Model/Repository/Registry.d.ts +21 -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 +95 -0
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
- package/dist/Model/filter/types/path/eager.js +31 -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 +4 -2
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/NonEmptySet.js +2 -2
- package/dist/Option.d.ts +2 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -1
- package/dist/Pure.d.ts +8 -6
- 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 +91 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +49 -0
- package/dist/Schema/Class.d.ts +66 -20
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +192 -27
- package/dist/Schema/FastCheck.d.ts +1 -1
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/Methods.d.ts +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 +5 -3
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +3 -1
- package/dist/Schema/email.d.ts +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +7 -4
- package/dist/Schema/ext.d.ts +339 -56
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +358 -53
- package/dist/Schema/moreStrings.d.ts +83 -37
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +49 -42
- package/dist/Schema/numbers.d.ts +35 -22
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +55 -12
- package/dist/Schema/phoneNumber.d.ts +1 -1
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -3
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/strings.d.ts +19 -5
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +214 -8
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +190 -11
- package/dist/Set.d.ts +5 -2
- 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/TypeTest.d.ts +1 -1
- package/dist/Types.d.ts +1 -1
- package/dist/Widen.type.d.ts +1 -1
- package/dist/_ext/Array.d.ts +2 -2
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/Array.js +4 -2
- package/dist/_ext/date.d.ts +1 -1
- package/dist/_ext/misc.d.ts +5 -2
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +4 -2
- package/dist/_ext/ord.ext.d.ts +3 -2
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/_ext/ord.ext.js +2 -2
- package/dist/builtin.d.ts +1 -1
- package/dist/builtin.d.ts.map +1 -1
- 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 +20 -32
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +104 -34
- package/dist/client/clientFor.d.ts +53 -19
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +49 -25
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +43 -17
- package/dist/client/makeClient.d.ts +495 -33
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +66 -24
- package/dist/client.d.ts +6 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/faker.d.ts +1 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +2 -2
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +2 -2
- package/dist/http/internal/lib.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/ids.d.ts +43 -15
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +30 -5
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/logger.d.ts +1 -1
- package/dist/middleware.d.ts +14 -8
- 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 +12 -8
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +59 -38
- package/dist/rpc/RpcContextMap.d.ts +4 -4
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +15 -11
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +2 -2
- 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 +2 -2
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +4 -5
- package/dist/utils/effectify.d.ts +2 -2
- package/dist/utils/effectify.d.ts.map +1 -1
- package/dist/utils/effectify.js +2 -2
- package/dist/utils/extend.d.ts +1 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +5 -5
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +3 -3
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +5 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +4 -4
- package/dist/utils.d.ts +40 -45
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -27
- package/dist/validation/validators.d.ts +1 -1
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts +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 +20 -245
- package/src/Array.ts +3 -3
- package/src/Config/SecretURL.ts +5 -2
- package/src/Config/internal/configSecretURL.ts +1 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +56 -63
- package/src/Effect.ts +12 -14
- package/src/Emailer.ts +51 -0
- package/src/Layer.ts +10 -6
- package/src/Model/Repository/Registry.ts +34 -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 +666 -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 +297 -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 +3 -1
- package/src/Option.ts +2 -0
- package/src/Pure.ts +21 -19
- package/src/QueueMaker.ts +19 -0
- package/src/RequestContext.ts +62 -0
- package/src/Schema/Class.ts +274 -68
- 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 +7 -2
- package/src/Schema/ext.ts +443 -88
- package/src/Schema/moreStrings.ts +146 -67
- package/src/Schema/numbers.ts +96 -27
- package/src/Schema/phoneNumber.ts +5 -1
- package/src/Schema/strings.ts +22 -13
- package/src/Schema.ts +374 -10
- package/src/Set.ts +5 -1
- package/src/Store.ts +277 -0
- package/src/_ext/Array.ts +3 -1
- 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 +230 -131
- package/src/client/clientFor.ts +102 -31
- package/src/client/errors.ts +52 -26
- package/src/client/makeClient.ts +592 -71
- package/src/client.ts +5 -4
- package/src/http/Request.ts +1 -1
- package/src/ids.ts +32 -5
- package/src/index.ts +7 -10
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +261 -0
- package/src/rpc/MiddlewareMaker.ts +83 -75
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +18 -12
- package/src/rpc.ts +1 -1
- package/src/runtime.ts +56 -0
- package/src/setupRequest.ts +134 -0
- package/src/toast.ts +54 -0
- package/src/transform.ts +3 -3
- 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 +62 -139
- package/src/withToast.ts +133 -0
- package/test/dist/rpc-dynamic-middleware.test.d.ts.map +1 -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/dist/stream-error.types.d.ts +2 -0
- package/test/dist/stream-error.types.d.ts.map +1 -0
- package/test/dist/stream-error.types.js +27 -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 +2 -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 +0 -44
- 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.js"
|
|
2
|
+
import { accessEffectFn } from "./Context.js"
|
|
3
|
+
import * as Effect from "./Effect.js"
|
|
4
|
+
import * as Option from "./Option.js"
|
|
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,6 +1,6 @@
|
|
|
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
5
|
import type * as SET from "./Set.js"
|
|
6
6
|
|
|
@@ -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.js"
|
|
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 type { GetFieldType, NumericDictionary, PropertyPath } from "lodash"
|
|
9
13
|
import { identity, pipe } from "./Function.js"
|
|
10
14
|
import type { DeepMutable, Equals, Mutable } from "./Types.js"
|
|
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"
|
|
@@ -684,7 +570,7 @@ export type OptPromise<T extends () => any> = (
|
|
|
684
570
|
) => Promise<ReturnType<T>> | ReturnType<T>
|
|
685
571
|
|
|
686
572
|
export function access<T extends string, T2>(t: Record<T, T2>) {
|
|
687
|
-
return (key: T) => t[key]
|
|
573
|
+
return (key: T) => t[key]
|
|
688
574
|
}
|
|
689
575
|
|
|
690
576
|
export function todayAtUTCNoon() {
|
|
@@ -736,25 +622,64 @@ export const copy = dual<
|
|
|
736
622
|
}
|
|
737
623
|
>(2, <A>(self: A, f: Partial<A> | ((a: A) => Partial<A>)) => clone(self, { ...self, ...(isFunction(f) ? f(self) : f) }))
|
|
738
624
|
|
|
739
|
-
type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
625
|
+
export type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
740
626
|
& {
|
|
741
627
|
[K in keyof U & keyof InstanceType<Ctor>]?: U[K]
|
|
742
628
|
}
|
|
743
629
|
& {}
|
|
744
630
|
|
|
745
|
-
type CopyOriginRet<A, U> =
|
|
631
|
+
export type CopyOriginRet<A, U> =
|
|
746
632
|
& {
|
|
747
633
|
[K in keyof A | keyof U]: K extends keyof U ? U[K] : A[K & keyof A]
|
|
748
634
|
}
|
|
749
635
|
& {}
|
|
750
636
|
|
|
751
|
-
type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
637
|
+
export type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
752
638
|
? Equals<keyof {}, keyof U> extends true ? `updates argument is empty or contains only extra properties`
|
|
753
639
|
: A
|
|
754
640
|
: A
|
|
755
641
|
|
|
642
|
+
export interface StructuralCopyOrigin<Self extends object> {
|
|
643
|
+
<A extends Self, U extends Partial<Self>>(
|
|
644
|
+
f: (a: A) =>
|
|
645
|
+
& {
|
|
646
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
647
|
+
}
|
|
648
|
+
& {}
|
|
649
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
650
|
+
<A extends Self, U extends Partial<Self>>(
|
|
651
|
+
updates:
|
|
652
|
+
& {
|
|
653
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
654
|
+
}
|
|
655
|
+
& {}
|
|
656
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
657
|
+
<A extends Self, U extends Partial<Self>>(
|
|
658
|
+
self: CopyOriginSelf<A, U>,
|
|
659
|
+
f: (a: A) =>
|
|
660
|
+
& {
|
|
661
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
662
|
+
}
|
|
663
|
+
& {}
|
|
664
|
+
): CopyOriginRet<A, U>
|
|
665
|
+
<A extends Self, U extends Partial<Self>>(
|
|
666
|
+
self: CopyOriginSelf<A, U>,
|
|
667
|
+
updates:
|
|
668
|
+
& {
|
|
669
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
670
|
+
}
|
|
671
|
+
& {}
|
|
672
|
+
): CopyOriginRet<A, U>
|
|
673
|
+
}
|
|
674
|
+
|
|
756
675
|
// just one input param: the convention is that the ctor takes an object
|
|
757
|
-
// containing the properties of the
|
|
676
|
+
// containing the properties of the value (I can't put object there as type because of contravariance)
|
|
677
|
+
/**
|
|
678
|
+
* By design this does not return `Self` directly.
|
|
679
|
+
*
|
|
680
|
+
* The return type is computed from `Self` and the update payload so callers can
|
|
681
|
+
* expose an explicit structural return type that remains assignable to `Self`.
|
|
682
|
+
*/
|
|
758
683
|
export const copyOrigin = <Ctor extends new(_: any) => any>(ctor: Ctor) =>
|
|
759
684
|
dual<
|
|
760
685
|
{
|
|
@@ -883,8 +808,6 @@ export function setMoveElDropUndefined<T>(el: T, newIndex: number) {
|
|
|
883
808
|
pipe([...arrInput], arMoveElDropUndefined(el, newIndex), Option.map((ar) => new Set(ar)))
|
|
884
809
|
}
|
|
885
810
|
|
|
886
|
-
export { get }
|
|
887
|
-
|
|
888
811
|
type RemoveNonArray<T> = T extends readonly any[] ? T : never
|
|
889
812
|
export function isNativeTuple<A>(a: A): a is RemoveNonArray<A> {
|
|
890
813
|
return Array.isArray(a)
|
|
@@ -956,7 +879,7 @@ const genConstructor = (function*() {}).constructor
|
|
|
956
879
|
/**
|
|
957
880
|
* @example
|
|
958
881
|
* ```ts
|
|
959
|
-
* import
|
|
882
|
+
* import * as Utils from "effect/Utils"
|
|
960
883
|
*
|
|
961
884
|
* function* generatorFn() {
|
|
962
885
|
* yield 1
|
|
@@ -970,5 +893,5 @@ const genConstructor = (function*() {}).constructor
|
|
|
970
893
|
* @category predicates
|
|
971
894
|
* @since 3.11.0
|
|
972
895
|
*/
|
|
973
|
-
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any
|
|
974
|
-
|
|
896
|
+
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any> =>
|
|
897
|
+
isFunction(u) && u.constructor === genConstructor
|
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.js"
|
|
4
|
+
import * as Effect from "./Effect.js"
|
|
5
|
+
import * as Layer from "./Layer.js"
|
|
6
|
+
import type * as Option from "./Option.js"
|
|
7
|
+
import * as S from "./Schema.js"
|
|
8
|
+
import { CurrentToastId, Toast, type ToastId } from "./toast.js"
|
|
9
|
+
import { wrapEffect } from "./utils.js"
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-dynamic-middleware.test.d.ts","sourceRoot":"","sources":["../rpc-dynamic-middleware.test.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACtE,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,IAAI,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;;;;;;;;AASrC,cAAM,WAAY,SAAQ,gBAKzB;CAAG;;;;;;;AAeJ,cAAM,cAAe,SAAQ,mBAE3B;CAAG;;;;;;;;AAGL,cAAM,eAAgB,SAAQ,oBAG5B;CAAG;;;;;;;;;AASL,cAAM,aAAc,SAAQ,kBAIC;CAC3B;AAkDF,eAAO,MAAM,OAAO,+MAWlB,CAAA;AA4CF,eAAO,MAAM,SAAS,yNAAwC,CAAA;AA0G9D,eAAO,MAAM,gBAAgB,sRAA+C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAErF,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,qBAAa,iBAAkB,SAAQ,sBAIrC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAI0B,KAAK;;;;AAKpC,qBAAa,KAAM,SAAQ,UAQzB;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secretURL.test.d.ts","sourceRoot":"","sources":["../secretURL.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special.test.d.ts","sourceRoot":"","sources":["../special.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-error.types.d.ts","sourceRoot":"","sources":["../stream-error.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { S } from "effect-app";
|
|
2
|
+
import { makeRpcClient } from "effect-app/client";
|
|
3
|
+
class GeneralError extends S.TaggedError("GeneralError")("GeneralError", {
|
|
4
|
+
message: S.String
|
|
5
|
+
}) {
|
|
6
|
+
}
|
|
7
|
+
class CustomError extends S.TaggedError("CustomError")("CustomError", {
|
|
8
|
+
reason: S.String
|
|
9
|
+
}) {
|
|
10
|
+
}
|
|
11
|
+
const { TaggedRequestFor } = makeRpcClient({ config: {} }, GeneralError);
|
|
12
|
+
const Req = TaggedRequestFor("Test");
|
|
13
|
+
class StreamWithError extends Req.Stream()("StreamWithError", {}, {
|
|
14
|
+
success: S.Number,
|
|
15
|
+
error: CustomError
|
|
16
|
+
}) {
|
|
17
|
+
}
|
|
18
|
+
const _check = true;
|
|
19
|
+
const _check2 = true;
|
|
20
|
+
class StreamNoError extends Req.Stream()("StreamNoError", {}, {
|
|
21
|
+
success: S.Number
|
|
22
|
+
}) {
|
|
23
|
+
}
|
|
24
|
+
const _check3 = true;
|
|
25
|
+
const _check4 = true;
|
|
26
|
+
console.log("ok");
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyZWFtLWVycm9yLnR5cGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3RyZWFtLWVycm9yLnR5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxDQUFDLEVBQUUsTUFBTSxZQUFZLENBQUE7QUFDOUIsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFBO0FBRWpELE1BQU0sWUFBYSxTQUFRLENBQUMsQ0FBQyxXQUFXLENBQWUsY0FBYyxDQUFDLENBQUMsY0FBYyxFQUFFO0lBQ3JGLE9BQU8sRUFBRSxDQUFDLENBQUMsTUFBTTtDQUNsQixDQUFDO0NBQUc7QUFFTCxNQUFNLFdBQVksU0FBUSxDQUFDLENBQUMsV0FBVyxDQUFjLGFBQWEsQ0FBQyxDQUFDLGFBQWEsRUFBRTtJQUNqRixNQUFNLEVBQUUsQ0FBQyxDQUFDLE1BQU07Q0FDakIsQ0FBQztDQUFHO0FBRUwsTUFBTSxFQUFFLGdCQUFnQixFQUFFLEdBQUcsYUFBYSxDQUFDLEVBQUUsTUFBTSxFQUFFLEVBQVMsRUFBRSxFQUFFLFlBQVksQ0FBQyxDQUFBO0FBQy9FLE1BQU0sR0FBRyxHQUFHLGdCQUFnQixDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBRXBDLE1BQU0sZUFBZ0IsU0FBUSxHQUFHLENBQUMsTUFBTSxFQUFtQixDQUFDLGlCQUFpQixFQUFFLEVBQUUsRUFBRTtJQUNqRixPQUFPLEVBQUUsQ0FBQyxDQUFDLE1BQU07SUFDakIsS0FBSyxFQUFFLFdBQVc7Q0FDbkIsQ0FBQztDQUFHO0FBR0wsTUFBTSxNQUFNLEdBQXdELElBQUksQ0FBQTtBQUN4RSxNQUFNLE9BQU8sR0FBd0QsSUFBSSxDQUFBO0FBRXpFLE1BQU0sYUFBYyxTQUFRLEdBQUcsQ0FBQyxNQUFNLEVBQWlCLENBQUMsZUFBZSxFQUFFLEVBQUUsRUFBRTtJQUMzRSxPQUFPLEVBQUUsQ0FBQyxDQUFDLE1BQU07Q0FDbEIsQ0FBQztDQUFHO0FBRUwsTUFBTSxPQUFPLEdBQTJDLElBQUksQ0FBQTtBQUM1RCxNQUFNLE9BQU8sR0FBMkMsSUFBSSxDQUFBO0FBRTVELE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUEifQ==
|
package/test/moreStrings.test.ts
CHANGED