effect-app 4.0.0-beta.99 → 4.0.1
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 +2042 -0
- package/dist/Array.d.ts +1 -17
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +3 -27
- package/dist/Chunk.d.ts +3 -27
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +4 -39
- 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 +0 -5
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +7 -5
- package/dist/ConfigProvider.d.ts +0 -37
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +5 -41
- package/dist/Context.d.ts +6 -4
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +4 -3
- package/dist/DataDependencies.d.ts +136 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +112 -0
- package/dist/DateTime.d.ts +33 -0
- package/dist/DateTime.d.ts.map +1 -0
- package/dist/DateTime.js +18 -0
- package/dist/Effect.d.ts +3 -14
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +8 -26
- 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 +0 -4
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +1 -7
- package/dist/Layer.d.ts +6 -3
- 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/dependency.d.ts +6 -0
- package/dist/Model/Repository/dependency.d.ts.map +1 -0
- package/dist/Model/Repository/dependency.js +29 -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 +124 -0
- package/dist/Model/Repository/internal/internal.d.ts +68 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +610 -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 +71 -0
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
- package/dist/Model/Repository/makeRepo.js +30 -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 +72 -0
- package/dist/Model/Repository/validation.d.ts.map +1 -0
- package/dist/Model/Repository/validation.js +39 -0
- package/dist/Model/Repository.d.ts +8 -0
- package/dist/Model/Repository.d.ts.map +1 -0
- package/dist/Model/Repository.js +8 -0
- package/dist/Model/dsl.d.ts +34 -0
- package/dist/Model/dsl.d.ts.map +1 -0
- package/dist/Model/dsl.js +45 -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 +630 -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 +132 -0
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
- package/dist/Model/query/new-kid-interpreter.js +369 -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 +6 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +6 -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 -2
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -7
- package/dist/Pure.d.ts +9 -7
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +20 -17
- package/dist/QueueMaker.d.ts +11 -0
- package/dist/QueueMaker.d.ts.map +1 -0
- package/dist/QueueMaker.js +11 -0
- package/dist/RequestContext.d.ts +87 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +45 -0
- package/dist/RequestScopedDependencies.d.ts +21 -0
- package/dist/RequestScopedDependencies.d.ts.map +1 -0
- package/dist/RequestScopedDependencies.js +16 -0
- package/dist/Schema/Class.d.ts +163 -16
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +193 -21
- 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 +15 -2
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -1
- package/dist/Schema/SpecialJsonSchema.js +70 -12
- package/dist/Schema/SpecialOpenApi.d.ts +1 -1
- package/dist/Schema/SpecialOpenApi.js +3 -3
- package/dist/Schema/brand.d.ts +5 -5
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +6 -4
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +8 -5
- package/dist/Schema/ext.d.ts +279 -75
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +330 -72
- package/dist/Schema/moreStrings.d.ts +82 -48
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +85 -51
- package/dist/Schema/numbers.d.ts +33 -21
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +64 -12
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -6
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/schema.d.ts.map +1 -1
- package/dist/Schema/schema.js +2 -2
- 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 +224 -7
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +190 -24
- package/dist/SchemaAST.d.ts +2 -0
- package/dist/SchemaAST.d.ts.map +1 -0
- package/dist/SchemaAST.js +2 -0
- package/dist/Set.d.ts +4 -1
- package/dist/Set.d.ts.map +1 -1
- package/dist/Set.js +8 -6
- package/dist/Store.d.ts +215 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +113 -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/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/builtin.d.ts +2 -14
- package/dist/builtin.d.ts.map +1 -1
- package/dist/builtin.js +1 -1
- package/dist/client/InvalidationKeys.d.ts +30 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +37 -0
- package/dist/client/apiClientFactory.d.ts +13 -8
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +154 -34
- package/dist/client/clientFor.d.ts +48 -13
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +74 -28
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +41 -10
- package/dist/client/makeClient.d.ts +487 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +47 -21
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -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 +12 -12
- package/dist/http/internal/lib.d.ts.map +1 -1
- package/dist/http/internal/lib.js +13 -13
- package/dist/ids.d.ts +32 -14
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +38 -7
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/middleware.d.ts +12 -6
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +13 -7
- package/dist/migration/nativeEffect.d.ts +21 -0
- package/dist/migration/nativeEffect.d.ts.map +1 -0
- package/dist/migration/nativeEffect.js +598 -0
- package/dist/rpc/Invalidation.d.ts +1124 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +178 -0
- package/dist/rpc/MiddlewareMaker.d.ts +10 -7
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +57 -37
- package/dist/rpc/RpcContextMap.d.ts +2 -2
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.d.ts +13 -10
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +2 -2
- 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 +20 -0
- package/dist/setupRequest.d.ts.map +1 -0
- package/dist/setupRequest.js +72 -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 +6 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/extend.js +24 -6
- 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 +2 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils.d.ts +34 -45
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -49
- 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 +25 -266
- package/src/Array.ts +7 -39
- package/src/Chunk.ts +6 -55
- package/src/Config/SecretURL.ts +6 -3
- package/src/Config/internal/configSecretURL.ts +2 -2
- package/src/Config.ts +6 -13
- package/src/ConfigProvider.ts +4 -47
- package/src/Context.ts +9 -8
- package/src/DataDependencies.ts +171 -0
- package/src/DateTime.ts +473 -0
- package/src/Effect.ts +10 -32
- package/src/Emailer.ts +51 -0
- package/src/Function.ts +0 -7
- package/src/Inputify.type.ts +1 -1
- package/src/Layer.ts +8 -5
- package/src/Model/Repository/Registry.ts +35 -0
- package/src/Model/Repository/dependency.ts +32 -0
- package/src/Model/Repository/ext.ts +374 -0
- package/src/Model/Repository/internal/internal.ts +987 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +168 -0
- package/src/Model/Repository/service.ts +676 -0
- package/src/Model/Repository/validation.ts +38 -0
- package/src/Model/Repository.ts +7 -0
- package/src/Model/dsl.ts +130 -0
- package/src/Model/filter/filterApi.ts +78 -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 +3092 -0
- package/src/Model/query/new-kid-interpreter.ts +531 -0
- package/src/Model/query.ts +13 -0
- package/src/Model.ts +5 -0
- package/src/NonEmptySet.ts +6 -4
- package/src/Option.ts +3 -8
- package/src/Pure.ts +20 -17
- package/src/QueueMaker.ts +11 -0
- package/src/RequestContext.ts +48 -0
- package/src/RequestScopedDependencies.ts +45 -0
- package/src/Schema/Class.ts +550 -56
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +75 -7
- package/src/Schema/SpecialOpenApi.ts +5 -5
- package/src/Schema/brand.ts +27 -12
- package/src/Schema/email.ts +9 -7
- package/src/Schema/ext.ts +405 -95
- package/src/Schema/moreStrings.ts +213 -88
- package/src/Schema/numbers.ts +107 -29
- package/src/Schema/phoneNumber.ts +8 -9
- package/src/Schema/schema.ts +1 -1
- package/src/Schema/strings.ts +23 -14
- package/src/Schema.ts +403 -46
- package/src/SchemaAST.ts +1 -0
- package/src/Set.ts +10 -5
- package/src/Store.ts +325 -0
- package/src/_ext/Array.ts +4 -2
- package/src/_ext/ord.ext.ts +2 -1
- package/src/builtin-json.d.ts +24 -0
- package/src/builtin.ts +16 -21
- package/src/client/InvalidationKeys.ts +55 -0
- package/src/client/apiClientFactory.ts +295 -129
- package/src/client/clientFor.ts +101 -33
- package/src/client/errors.ts +66 -20
- package/src/client/makeClient.ts +519 -60
- package/src/client.ts +6 -4
- package/src/http/Request.ts +4 -4
- package/src/http/internal/lib.ts +12 -12
- package/src/http.ts +1 -1
- package/src/ids.ts +45 -8
- package/src/index.ts +20 -16
- package/src/middleware.ts +12 -8
- package/src/migration/nativeEffect.ts +645 -0
- package/src/rpc/Invalidation.ts +278 -0
- package/src/rpc/MiddlewareMaker.ts +86 -79
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +4 -4
- package/src/rpc/RpcMiddleware.ts +18 -13
- package/src/rpc.ts +4 -4
- package/src/runtime.ts +57 -0
- package/src/setupRequest.ts +138 -0
- package/src/toast.ts +54 -0
- package/src/transform.ts +4 -4
- package/src/utils/effectify.ts +1 -1
- package/src/utils/extend.ts +24 -5
- package/src/utils/gen.ts +7 -7
- package/src/utils/logLevel.ts +1 -1
- package/src/utils/logger.ts +3 -2
- package/src/utils.ts +85 -175
- package/src/validation.ts +2 -2
- package/src/withToast.ts +133 -0
- package/test/dateTimeLocal.test.ts +55 -0
- package/test/dist/dateTimeLocal.test.d.ts.map +1 -0
- package/test/dist/nativeEffectMigration.test.d.ts.map +1 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/rpcMiddlewareContext.test.d.ts.map +1 -0
- package/test/moreStrings.test.ts +55 -10
- package/test/nativeEffectMigration.test.ts +77 -0
- package/test/rpc.test.ts +28 -11
- package/test/rpcMiddlewareContext.test.ts +63 -0
- package/test/schema.test.ts +318 -55
- package/test/secretURL.test.ts +4 -1
- package/test/special.test.ts +663 -131
- package/test/utils.test.ts +5 -5
- package/tsconfig.base.json +6 -4
- package/tsconfig.json +9 -1
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -124
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/_ext/date.d.ts +0 -15
- package/dist/_ext/date.d.ts.map +0 -1
- package/dist/_ext/date.js +0 -16
- package/dist/_ext/misc.d.ts +0 -14
- package/dist/_ext/misc.d.ts.map +0 -1
- package/dist/_ext/misc.js +0 -17
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
- package/src/_ext/date.ts +0 -27
- package/src/_ext/misc.ts +0 -46
- package/tsconfig.json.bak +0 -12
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)
|
|
@@ -158,11 +47,6 @@ export function toString(v: unknown) {
|
|
|
158
47
|
return `${v}`
|
|
159
48
|
}
|
|
160
49
|
|
|
161
|
-
export const typedKeysOf = <T extends {}>(obj: T) => Object.keys(obj) as (keyof T)[]
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
163
|
-
export const typedValuesOf = <T extends {}>(obj: T) => Object.values(obj) as ValueOf<T>[]
|
|
164
|
-
type ValueOf<T> = T[keyof T]
|
|
165
|
-
|
|
166
50
|
export type Constructor<T = any> = { new(...args: any[]): T }
|
|
167
51
|
export type ThenArg<T> = T extends Promise<infer U> ? U
|
|
168
52
|
: T extends (...args: any[]) => Promise<infer V> ? V
|
|
@@ -244,14 +128,6 @@ export function dropUndefined<A>(
|
|
|
244
128
|
type GetTag<T> = T extends { _tag: infer K } ? K : never
|
|
245
129
|
export const isOfType = <T extends { _tag: string }>(tag: GetTag<T>) => (e: { _tag: string }): e is T => e._tag === tag
|
|
246
130
|
|
|
247
|
-
export function capitalize<T extends string>(string: T): Capitalize<T> {
|
|
248
|
-
return (string.charAt(0).toUpperCase() + string.slice(1)) as Capitalize<T>
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function uncapitalize<T extends string>(string: T): Uncapitalize<T> {
|
|
252
|
-
return (string.charAt(0).toLowerCase() + string.slice(1)) as Uncapitalize<T>
|
|
253
|
-
}
|
|
254
|
-
|
|
255
131
|
export function pretty(o: unknown): string {
|
|
256
132
|
return JSON.stringify(o, undefined, 2) ?? "undefined"
|
|
257
133
|
}
|
|
@@ -269,7 +145,7 @@ export type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R
|
|
|
269
145
|
export function intersect<AS extends unknown[] & { 0: unknown }>(
|
|
270
146
|
...as: AS
|
|
271
147
|
): UnionToIntersection<{ [k in keyof AS]: AS[k] }[number]> {
|
|
272
|
-
return as.reduce((a: any, b: any) => (
|
|
148
|
+
return as.reduce((a: any, b: any) => Object.assign(a, b), {}) as any
|
|
273
149
|
}
|
|
274
150
|
|
|
275
151
|
export type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
@@ -280,8 +156,7 @@ export type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
|
280
156
|
export const unifyIndex = Symbol()
|
|
281
157
|
export type unifyIndex = typeof unifyIndex
|
|
282
158
|
|
|
283
|
-
|
|
284
|
-
export interface UnifiableIndexed<X> {}
|
|
159
|
+
export interface UnifiableIndexed<_X> {}
|
|
285
160
|
export type UnifiableIndexedURI = keyof UnifiableIndexed<any>
|
|
286
161
|
|
|
287
162
|
export interface Unifiable<X> {
|
|
@@ -313,9 +188,7 @@ function decorateNew(
|
|
|
313
188
|
if (out.descriptor) {
|
|
314
189
|
out.descriptor = Object.assign({}, out.descriptor)
|
|
315
190
|
}
|
|
316
|
-
const actualDesc: PropertyDescriptor =
|
|
317
|
-
out.descriptor || /* istanbul ignore next */ out
|
|
318
|
-
)
|
|
191
|
+
const actualDesc: PropertyDescriptor = out.descriptor || /* istanbul ignore next */ out
|
|
319
192
|
|
|
320
193
|
const originalMethod = validateAndExtractMethodFromDescriptor(actualDesc)
|
|
321
194
|
const isStatic = inp.placement === "static"
|
|
@@ -342,7 +215,7 @@ function decorateNew(
|
|
|
342
215
|
function decorateLegacy(
|
|
343
216
|
target: any,
|
|
344
217
|
key: PropertyKey,
|
|
345
|
-
descriptor: PropertyDescriptor,
|
|
218
|
+
descriptor: PropertyDescriptor | undefined,
|
|
346
219
|
setProto: boolean,
|
|
347
220
|
makeNonConfigurable: boolean,
|
|
348
221
|
// tslint:enable:bool-param-default
|
|
@@ -350,11 +223,12 @@ function decorateLegacy(
|
|
|
350
223
|
): PropertyDescriptor {
|
|
351
224
|
/* istanbul ignore if */
|
|
352
225
|
if (!descriptor) {
|
|
353
|
-
descriptor =
|
|
226
|
+
descriptor = Object.getOwnPropertyDescriptor(target, key)
|
|
354
227
|
if (!descriptor) {
|
|
355
|
-
const e = new Error("@LazyGetter is unable to determine the property descriptor")
|
|
356
|
-
|
|
357
|
-
|
|
228
|
+
const e = Object.assign(new Error("@LazyGetter is unable to determine the property descriptor"), {
|
|
229
|
+
$key: key,
|
|
230
|
+
$target: target
|
|
231
|
+
})
|
|
358
232
|
throw e
|
|
359
233
|
}
|
|
360
234
|
}
|
|
@@ -409,7 +283,7 @@ function defaultFilter(): boolean {
|
|
|
409
283
|
|
|
410
284
|
function validateAndExtractMethodFromDescriptor(desc: PropertyDescriptor): Function {
|
|
411
285
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
412
|
-
const originalMethod =
|
|
286
|
+
const originalMethod = desc.get
|
|
413
287
|
|
|
414
288
|
if (!originalMethod) {
|
|
415
289
|
throw new Error("@LazyGetter can only decorate getters!")
|
|
@@ -432,7 +306,7 @@ function getterCommon( // tslint:disable-line:parameters-max-number
|
|
|
432
306
|
makeNonConfigurable: boolean,
|
|
433
307
|
resultSelector: ResultSelectorFn
|
|
434
308
|
): any {
|
|
435
|
-
const value = originalMethod.apply(thisArg,
|
|
309
|
+
const value = originalMethod.apply(thisArg, args)
|
|
436
310
|
|
|
437
311
|
if (resultSelector(value)) {
|
|
438
312
|
const newDescriptor: PropertyDescriptor = {
|
|
@@ -467,23 +341,23 @@ export function LazyGetter(
|
|
|
467
341
|
): MethodDecorator & ResettableDescriptor {
|
|
468
342
|
let desc: PropertyDescriptor
|
|
469
343
|
let prop: PropertyKey
|
|
470
|
-
let args:
|
|
344
|
+
let args: [targetOrDesc: any, key: PropertyKey | undefined, descriptor: PropertyDescriptor | undefined] | undefined
|
|
471
345
|
let isLegacy: boolean
|
|
472
346
|
|
|
473
347
|
function decorator(
|
|
474
348
|
targetOrDesc: any,
|
|
475
|
-
key: PropertyKey,
|
|
476
|
-
descriptor: PropertyDescriptor
|
|
349
|
+
key: PropertyKey | undefined,
|
|
350
|
+
descriptor: PropertyDescriptor | undefined
|
|
477
351
|
): DecoratorReturn {
|
|
478
|
-
|
|
479
|
-
args = arguments
|
|
352
|
+
args = [targetOrDesc, key, descriptor]
|
|
480
353
|
if (key === undefined) {
|
|
481
354
|
if (typeof desc === "undefined") {
|
|
355
|
+
const newDescriptor = targetOrDesc as NewDescriptor
|
|
482
356
|
isLegacy = false
|
|
483
|
-
prop =
|
|
357
|
+
prop = newDescriptor.key
|
|
484
358
|
desc = Object.assign(
|
|
485
359
|
{},
|
|
486
|
-
|
|
360
|
+
newDescriptor.descriptor
|
|
487
361
|
/* istanbul ignore next */ || targetOrDesc
|
|
488
362
|
)
|
|
489
363
|
}
|
|
@@ -525,11 +399,14 @@ export function LazyGetter(
|
|
|
525
399
|
"Unable to restore descriptor. Did you remember to apply your decorator to a method?"
|
|
526
400
|
)
|
|
527
401
|
}
|
|
402
|
+
if (!args) {
|
|
403
|
+
throw new Error("Unable to restore descriptor before applying the decorator.")
|
|
404
|
+
}
|
|
528
405
|
// Restore descriptor to its original state
|
|
529
406
|
Object.defineProperty(on, prop, desc)
|
|
530
|
-
|
|
531
|
-
const ret:
|
|
532
|
-
Object.defineProperty(on, prop,
|
|
407
|
+
const ret = decorator.apply(null, args)
|
|
408
|
+
const restoredDescriptor = isLegacy ? ret : "descriptor" in ret && ret.descriptor ? ret.descriptor : ret
|
|
409
|
+
Object.defineProperty(on, prop, restoredDescriptor)
|
|
533
410
|
}
|
|
534
411
|
|
|
535
412
|
return decorator
|
|
@@ -675,16 +552,12 @@ export function exhaustiveMatch_<T extends string>(t: T) {
|
|
|
675
552
|
return <Out extends Record<T, (t: T) => any>>(handlers: Out): ReturnType<Out[keyof Out]> => handlers[t](t)
|
|
676
553
|
}
|
|
677
554
|
|
|
678
|
-
export function assertUnreachable(x: never): never {
|
|
679
|
-
throw new Error("Unknown case " + x)
|
|
680
|
-
}
|
|
681
|
-
|
|
682
555
|
export type OptPromise<T extends () => any> = (
|
|
683
556
|
...args: Parameters<T>
|
|
684
557
|
) => Promise<ReturnType<T>> | ReturnType<T>
|
|
685
558
|
|
|
686
559
|
export function access<T extends string, T2>(t: Record<T, T2>) {
|
|
687
|
-
return (key: T) => t[key]
|
|
560
|
+
return (key: T) => t[key]
|
|
688
561
|
}
|
|
689
562
|
|
|
690
563
|
export function todayAtUTCNoon() {
|
|
@@ -736,25 +609,64 @@ export const copy = dual<
|
|
|
736
609
|
}
|
|
737
610
|
>(2, <A>(self: A, f: Partial<A> | ((a: A) => Partial<A>)) => clone(self, { ...self, ...(isFunction(f) ? f(self) : f) }))
|
|
738
611
|
|
|
739
|
-
type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
612
|
+
export type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
740
613
|
& {
|
|
741
614
|
[K in keyof U & keyof InstanceType<Ctor>]?: U[K]
|
|
742
615
|
}
|
|
743
616
|
& {}
|
|
744
617
|
|
|
745
|
-
type CopyOriginRet<A, U> =
|
|
618
|
+
export type CopyOriginRet<A, U> =
|
|
746
619
|
& {
|
|
747
620
|
[K in keyof A | keyof U]: K extends keyof U ? U[K] : A[K & keyof A]
|
|
748
621
|
}
|
|
749
622
|
& {}
|
|
750
623
|
|
|
751
|
-
type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
624
|
+
export type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
752
625
|
? Equals<keyof {}, keyof U> extends true ? `updates argument is empty or contains only extra properties`
|
|
753
626
|
: A
|
|
754
627
|
: A
|
|
755
628
|
|
|
629
|
+
export interface StructuralCopyOrigin<Self extends object> {
|
|
630
|
+
<A extends Self, U extends Partial<Self>>(
|
|
631
|
+
f: (a: A) =>
|
|
632
|
+
& {
|
|
633
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
634
|
+
}
|
|
635
|
+
& {}
|
|
636
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
637
|
+
<A extends Self, U extends Partial<Self>>(
|
|
638
|
+
updates:
|
|
639
|
+
& {
|
|
640
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
641
|
+
}
|
|
642
|
+
& {}
|
|
643
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
644
|
+
<A extends Self, U extends Partial<Self>>(
|
|
645
|
+
self: CopyOriginSelf<A, U>,
|
|
646
|
+
f: (a: A) =>
|
|
647
|
+
& {
|
|
648
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
649
|
+
}
|
|
650
|
+
& {}
|
|
651
|
+
): CopyOriginRet<A, U>
|
|
652
|
+
<A extends Self, U extends Partial<Self>>(
|
|
653
|
+
self: CopyOriginSelf<A, U>,
|
|
654
|
+
updates:
|
|
655
|
+
& {
|
|
656
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
657
|
+
}
|
|
658
|
+
& {}
|
|
659
|
+
): CopyOriginRet<A, U>
|
|
660
|
+
}
|
|
661
|
+
|
|
756
662
|
// just one input param: the convention is that the ctor takes an object
|
|
757
|
-
// containing the properties of the
|
|
663
|
+
// containing the properties of the value (I can't put object there as type because of contravariance)
|
|
664
|
+
/**
|
|
665
|
+
* By design this does not return `Self` directly.
|
|
666
|
+
*
|
|
667
|
+
* The return type is computed from `Self` and the update payload so callers can
|
|
668
|
+
* expose an explicit structural return type that remains assignable to `Self`.
|
|
669
|
+
*/
|
|
758
670
|
export const copyOrigin = <Ctor extends new(_: any) => any>(ctor: Ctor) =>
|
|
759
671
|
dual<
|
|
760
672
|
{
|
|
@@ -883,8 +795,6 @@ export function setMoveElDropUndefined<T>(el: T, newIndex: number) {
|
|
|
883
795
|
pipe([...arrInput], arMoveElDropUndefined(el, newIndex), Option.map((ar) => new Set(ar)))
|
|
884
796
|
}
|
|
885
797
|
|
|
886
|
-
export { get }
|
|
887
|
-
|
|
888
798
|
type RemoveNonArray<T> = T extends readonly any[] ? T : never
|
|
889
799
|
export function isNativeTuple<A>(a: A): a is RemoveNonArray<A> {
|
|
890
800
|
return Array.isArray(a)
|
|
@@ -956,7 +866,7 @@ const genConstructor = (function*() {}).constructor
|
|
|
956
866
|
/**
|
|
957
867
|
* @example
|
|
958
868
|
* ```ts
|
|
959
|
-
* import
|
|
869
|
+
* import * as Utils from "effect/Utils"
|
|
960
870
|
*
|
|
961
871
|
* function* generatorFn() {
|
|
962
872
|
* yield 1
|
|
@@ -970,5 +880,5 @@ const genConstructor = (function*() {}).constructor
|
|
|
970
880
|
* @category predicates
|
|
971
881
|
* @since 3.11.0
|
|
972
882
|
*/
|
|
973
|
-
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any
|
|
974
|
-
|
|
883
|
+
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any> =>
|
|
884
|
+
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
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { makeZonedLocal, pipeZonedLocal } from "effect-app/DateTime"
|
|
2
|
+
import * as DateTime from "effect/DateTime"
|
|
3
|
+
import { describe, expect, test } from "vitest"
|
|
4
|
+
|
|
5
|
+
describe("local Date helpers", () => {
|
|
6
|
+
const start = new Date("2024-03-09T17:00:00.000Z")
|
|
7
|
+
|
|
8
|
+
test("makeZonedLocal keeps the instant and uses the process zone", () => {
|
|
9
|
+
const zoned = makeZonedLocal(start)
|
|
10
|
+
expect(zoned.epochMilliseconds).toBe(start.getTime())
|
|
11
|
+
expect(DateTime.zoneToString(zoned.zone)).toBe(DateTime.zoneToString(DateTime.zoneMakeLocal()))
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test("pipeZonedLocal adds a local calendar day and returns the instant", () => {
|
|
15
|
+
const expected = new Date(start.getTime())
|
|
16
|
+
expected.setDate(expected.getDate() + 1)
|
|
17
|
+
expect(pipeZonedLocal(start, DateTime.add({ days: 1 })).getTime()).toBe(expected.getTime())
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test("pipeZonedLocal runs every step before toDateUtc", () => {
|
|
21
|
+
const expected = new Date(start.getTime())
|
|
22
|
+
expected.setDate(expected.getDate() + 1)
|
|
23
|
+
expected.setMonth(expected.getMonth() + 1)
|
|
24
|
+
const result = pipeZonedLocal(start, DateTime.add({ days: 1 }), DateTime.add({ months: 1 }))
|
|
25
|
+
expect(result.getTime()).toBe(expected.getTime())
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test("pipeZonedLocal accepts as many functions as pipe", () => {
|
|
29
|
+
const keep = <A extends DateTime.DateTime>(self: A) => self
|
|
30
|
+
const expected = new Date(start.getTime())
|
|
31
|
+
expected.setDate(expected.getDate() + 1)
|
|
32
|
+
const result = pipeZonedLocal(
|
|
33
|
+
start,
|
|
34
|
+
keep,
|
|
35
|
+
keep,
|
|
36
|
+
keep,
|
|
37
|
+
keep,
|
|
38
|
+
keep,
|
|
39
|
+
keep,
|
|
40
|
+
keep,
|
|
41
|
+
keep,
|
|
42
|
+
keep,
|
|
43
|
+
keep,
|
|
44
|
+
keep,
|
|
45
|
+
keep,
|
|
46
|
+
keep,
|
|
47
|
+
keep,
|
|
48
|
+
keep,
|
|
49
|
+
keep,
|
|
50
|
+
keep,
|
|
51
|
+
DateTime.add({ days: 1 })
|
|
52
|
+
)
|
|
53
|
+
expect(result.getTime()).toBe(expected.getTime())
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeLocal.test.d.ts","sourceRoot":"","sources":["../dateTimeLocal.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeEffectMigration.test.d.ts","sourceRoot":"","sources":["../nativeEffectMigration.test.ts"],"names":[],"mappings":""}
|
|
@@ -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;AACrF,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":"rpcMiddlewareContext.test.d.ts","sourceRoot":"","sources":["../rpcMiddlewareContext.test.ts"],"names":[],"mappings":""}
|