effect-app 4.0.0-beta.3 → 4.0.0-beta.300
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 +1592 -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/Context.d.ts +42 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/DataDependencies.d.ts +388 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +64 -0
- package/dist/Effect.d.ts +10 -9
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -7
- 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 +438 -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 +514 -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 +361 -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 +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 +188 -19
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +259 -22
- 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 +11 -6
- 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 +9 -5
- package/dist/Schema/ext.d.ts +340 -56
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +361 -63
- package/dist/Schema/moreStrings.d.ts +82 -36
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +53 -44
- 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 +8 -4
- 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 +238 -58
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +227 -69
- 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 +3 -2
- package/dist/Store.d.ts +163 -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/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/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 +19 -31
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +160 -41
- package/dist/client/clientFor.d.ts +54 -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 +492 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +62 -38
- 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 +1 -1
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +5 -5
- 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 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -9
- 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 +3140 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +178 -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 +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.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 +50 -37
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +51 -36
- 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 +27 -255
- 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} +59 -65
- package/src/DataDependencies.ts +114 -0
- package/src/Effect.ts +15 -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 +755 -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 +2770 -0
- package/src/Model/query/new-kid-interpreter.ts +526 -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 +11 -0
- package/src/RequestContext.ts +48 -0
- package/src/RequestScopedDependencies.ts +45 -0
- package/src/Schema/Class.ts +631 -63
- 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 +34 -8
- package/src/Schema/email.ts +12 -5
- package/src/Schema/ext.ts +469 -106
- package/src/Schema/moreStrings.ts +155 -73
- package/src/Schema/numbers.ts +97 -28
- package/src/Schema/phoneNumber.ts +12 -6
- package/src/Schema/schema.ts +1 -1
- package/src/Schema/strings.ts +23 -14
- package/src/Schema.ts +468 -121
- package/src/SchemaAST.ts +1 -0
- package/src/Set.ts +6 -2
- package/src/Store.ts +273 -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/builtin-json.d.ts +24 -0
- package/src/builtin.ts +16 -21
- package/src/client/InvalidationKeys.ts +55 -0
- package/src/client/apiClientFactory.ts +306 -144
- package/src/client/clientFor.ts +107 -34
- package/src/client/errors.ts +109 -29
- package/src/client/makeClient.ts +593 -87
- package/src/client.ts +6 -4
- package/src/http/Request.ts +9 -6
- package/src/http.ts +1 -1
- package/src/ids.ts +34 -7
- package/src/index.ts +20 -24
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +278 -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 +138 -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 +105 -156
- package/src/validation.ts +2 -2
- package/src/withToast.ts +133 -0
- package/test/dist/moreStrings.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/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/moreStrings.test.ts +17 -0
- package/test/rpc.test.ts +45 -6
- package/test/rpcMiddlewareContext.test.ts +63 -0
- package/test/schema.test.ts +613 -7
- package/test/secretURL.test.ts +160 -0
- package/test/special.test.ts +1258 -0
- package/test/utils.test.ts +7 -7
- package/tsconfig.base.json +6 -5
- package/tsconfig.json +3 -1
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -87
- 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/dist/Struct.d.ts +0 -44
- package/dist/Struct.d.ts.map +0 -1
- package/dist/Struct.js +0 -29
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
- package/src/Struct.ts +0 -54
- package/tsconfig.json.bak +0 -12
package/src/client/clientFor.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
|
|
4
4
|
import * as Record from "effect/Record"
|
|
5
|
-
import type * as
|
|
5
|
+
import type * as Stream from "effect/Stream"
|
|
6
6
|
import type { Path } from "path-parser"
|
|
7
7
|
import qs from "query-string"
|
|
8
|
-
import type * as Effect from "../Effect.
|
|
9
|
-
import type * as S from "../Schema.
|
|
10
|
-
import { type Req } from "./apiClientFactory.
|
|
8
|
+
import type * as Effect from "../Effect.ts"
|
|
9
|
+
import type * as S from "../Schema.ts"
|
|
10
|
+
import { type Req } from "./apiClientFactory.ts"
|
|
11
11
|
|
|
12
12
|
export function makePathWithQuery(
|
|
13
13
|
path: Path,
|
|
@@ -48,9 +48,14 @@ export function makePathWithBody(
|
|
|
48
48
|
return path.build(pars, { ignoreSearch: true, ignoreConstraints: true })
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export type Requests
|
|
51
|
+
export type Requests = RequestsAny
|
|
52
52
|
export type RequestsAny = Record<string, any>
|
|
53
53
|
|
|
54
|
+
export type ExtractModuleName<M extends RequestsAny> =
|
|
55
|
+
{ [K in keyof M]: M[K] extends { moduleName: infer N extends string } ? N : never }[keyof M] extends
|
|
56
|
+
infer R extends string ? R
|
|
57
|
+
: string
|
|
58
|
+
|
|
54
59
|
export type Client<M extends RequestsAny, ModuleName extends string> = RequestHandlers<
|
|
55
60
|
never,
|
|
56
61
|
never,
|
|
@@ -58,56 +63,124 @@ export type Client<M extends RequestsAny, ModuleName extends string> = RequestHa
|
|
|
58
63
|
ModuleName
|
|
59
64
|
>
|
|
60
65
|
|
|
61
|
-
export type ExtractResponse<T> = T extends S.Codec<any> ?
|
|
66
|
+
export type ExtractResponse<T> = T extends S.Codec<any> ? T["Type"]
|
|
62
67
|
: T extends unknown ? void
|
|
63
68
|
: never
|
|
64
69
|
|
|
65
|
-
export type ExtractEResponse<T> = T extends S.Codec<any> ?
|
|
70
|
+
export type ExtractEResponse<T> = T extends S.Codec<any> ? T["Encoded"]
|
|
66
71
|
: T extends unknown ? void
|
|
67
72
|
: never
|
|
68
73
|
|
|
69
|
-
type IsEmpty<T> = keyof T extends never ? true
|
|
70
|
-
: false
|
|
71
|
-
|
|
72
|
-
// v4: Request.RequestTypeId, S.symbolSerializable, S.symbolWithResult removed — use keyof Request to filter internal props
|
|
73
|
-
type Cruft = "_tag" | keyof Request.Request<any, any, any>
|
|
74
|
-
|
|
75
74
|
export interface ClientForOptions {
|
|
76
75
|
readonly skipQueryKey?: readonly string[]
|
|
76
|
+
/**
|
|
77
|
+
* Middleware tag to attach to every rpc on the client. Schema-only — the
|
|
78
|
+
* client never invokes the middleware (no Live impl required), but its
|
|
79
|
+
* declared `error` schema joins the rpc failure union via
|
|
80
|
+
* `Rpc.exitSchema`'s `rpc.middlewares[*].error` walk. Required when
|
|
81
|
+
* middleware can throw errors that aren't part of the resource's declared
|
|
82
|
+
* error union (e.g. auth middleware throwing `NotLoggedInError`); without
|
|
83
|
+
* it the client decode would fail with a `SchemaError` for stream rpcs.
|
|
84
|
+
*/
|
|
77
85
|
}
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
// $Project/$Configuration.Index
|
|
88
|
+
// -> "$Project", "$Configuration", "Index"
|
|
89
|
+
export const makeQueryKey = ({ id, options }: { id: string; options?: ClientForOptions }) =>
|
|
90
|
+
id
|
|
91
|
+
.split("/")
|
|
92
|
+
.filter((segment: string) => !options || !options.skipQueryKey?.includes(segment))
|
|
93
|
+
.map((segment: string) => "$" + segment)
|
|
94
|
+
.join(".")
|
|
95
|
+
.split(".")
|
|
96
|
+
|
|
97
|
+
export interface RequestHandlerWithInput<I, A, E, R, Request extends Req, Id extends string> {
|
|
98
|
+
handler: (i: I) => Effect.Effect<A, E, R>
|
|
81
99
|
id: Id
|
|
82
100
|
options?: ClientForOptions
|
|
83
101
|
Request: Request
|
|
102
|
+
queryKeyProjectionHash?: string
|
|
103
|
+
disableQueryInvalidation?: boolean
|
|
84
104
|
}
|
|
85
105
|
|
|
86
|
-
|
|
87
|
-
|
|
106
|
+
/** Type alias: a no-input handler is simply `RequestHandlerWithInput<void, …>`. */
|
|
107
|
+
export type RequestHandler<A, E, R, Request extends Req, Id extends string> = RequestHandlerWithInput<
|
|
108
|
+
void,
|
|
109
|
+
A,
|
|
110
|
+
E,
|
|
111
|
+
R,
|
|
112
|
+
Request,
|
|
113
|
+
Id
|
|
114
|
+
>
|
|
115
|
+
|
|
116
|
+
export interface RequestStreamHandlerWithInput<I, A, E, R, Request extends Req, Id extends string, Final = A> {
|
|
117
|
+
handler: (i: I) => Stream.Stream<A, E, R>
|
|
88
118
|
id: Id
|
|
89
119
|
options?: ClientForOptions
|
|
90
120
|
Request: Request
|
|
121
|
+
/**
|
|
122
|
+
* Phantom type property (never set at runtime) that carries the `Final` type to
|
|
123
|
+
* `StreamMutationWithExtensions`. The tilde prefix follows the Effect convention for
|
|
124
|
+
* phantom/virtual properties and prevents accidental runtime access.
|
|
125
|
+
* Stream failures bubble through the execute effect's typed error channel `E`;
|
|
126
|
+
* the reactive `AsyncResult` ref also mirrors the failure for live progress UI.
|
|
127
|
+
*/
|
|
128
|
+
readonly "~final"?: Final
|
|
91
129
|
}
|
|
92
130
|
|
|
131
|
+
/** Type alias: a no-input stream handler is simply `RequestStreamHandlerWithInput<void, …>`. */
|
|
132
|
+
export type RequestStreamHandler<A, E, R, Request extends Req, Id extends string, Final = A> =
|
|
133
|
+
RequestStreamHandlerWithInput<void, A, E, R, Request, Id, Final>
|
|
134
|
+
|
|
93
135
|
// make sure this is exported or d.ts of apiClientFactory breaks?!
|
|
94
|
-
type
|
|
136
|
+
export type RequestInputFromMake<I extends { readonly make: (...args: any[]) => any }> = Parameters<I["make"]> extends
|
|
137
|
+
[] ? void : Parameters<I["make"]>[0]
|
|
138
|
+
|
|
139
|
+
// Has no input only when the request schema declares no payload fields (the auto-added
|
|
140
|
+
// `_tag` field is ignored). Any payload fields (even all-optional) produce a function handler.
|
|
141
|
+
type HasNoFields<I> = I extends { readonly fields: infer F extends S.Struct.Fields }
|
|
142
|
+
? [Exclude<keyof F, "_tag">] extends [never] ? true : false
|
|
143
|
+
: false
|
|
144
|
+
|
|
145
|
+
type RequestInput<I extends { readonly make: (...args: any[]) => any }> = Parameters<I["make"]>[0]
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Caller-facing input type for a request. `void` when the request schema has no fields;
|
|
149
|
+
* otherwise `make`'s first param type.
|
|
150
|
+
*/
|
|
151
|
+
export type HandlerInput<I extends { readonly make: (...args: any[]) => any }> = HasNoFields<I> extends true ? void
|
|
152
|
+
: RequestInput<I>
|
|
153
|
+
|
|
154
|
+
/** Extracts the final-value type from a stream request. Defaults to the success type when no `final` schema is set. */
|
|
155
|
+
type FinalTypeOf<T extends Req> = T extends { readonly final: infer F extends S.Top } ? F["Type"]
|
|
156
|
+
: T["success"]["Type"]
|
|
157
|
+
|
|
158
|
+
// `T["success"]` / `T["error"]` are constrained to `S.Top` via `Req`, so we
|
|
159
|
+
// can read `["DecodingServices"]` directly. Avoids the conditional in
|
|
160
|
+
// `S.Codec.DecodingServices<X> = X extends Top ? X["DecodingServices"] : never`,
|
|
161
|
+
// which tsgo (native) fails to reduce in this generic position and leaves as
|
|
162
|
+
// `unknown`, polluting the `R` channel of every client handler.
|
|
163
|
+
type RequestHandlerFor<R, E, T extends Req, Id extends string> = T["stream"] extends true
|
|
164
|
+
? RequestStreamHandlerWithInput<
|
|
165
|
+
HandlerInput<T>,
|
|
166
|
+
T["success"]["Type"],
|
|
167
|
+
T["error"]["Type"] | E,
|
|
168
|
+
R | T["success"]["DecodingServices"] | T["error"]["DecodingServices"],
|
|
169
|
+
T,
|
|
170
|
+
Id,
|
|
171
|
+
FinalTypeOf<T>
|
|
172
|
+
>
|
|
173
|
+
: RequestHandlerWithInput<
|
|
174
|
+
HandlerInput<T>,
|
|
175
|
+
T["success"]["Type"],
|
|
176
|
+
T["error"]["Type"] | E,
|
|
177
|
+
R | T["success"]["DecodingServices"] | T["error"]["DecodingServices"],
|
|
178
|
+
T,
|
|
179
|
+
Id
|
|
180
|
+
>
|
|
95
181
|
|
|
96
182
|
export type RequestHandlers<R, E, M extends RequestsAny, ModuleName extends string> = {
|
|
97
|
-
[K in keyof M as M[K] extends Req ? K : never]:
|
|
98
|
-
?
|
|
99
|
-
|
|
100
|
-
S.Schema.Type<M[K]["error"]> | E,
|
|
101
|
-
R | ReqDecodingServices<M[K]>,
|
|
102
|
-
M[K],
|
|
103
|
-
`${ModuleName}.${K & string}`
|
|
104
|
-
>
|
|
105
|
-
: RequestHandlerWithInput<
|
|
106
|
-
Omit<S.Schema.Type<M[K]>, Cruft>,
|
|
107
|
-
S.Schema.Type<M[K]["success"]>,
|
|
108
|
-
S.Schema.Type<M[K]["error"]> | E,
|
|
109
|
-
R | ReqDecodingServices<M[K]>,
|
|
110
|
-
M[K],
|
|
111
|
-
`${ModuleName}.${K & string}`
|
|
112
|
-
>
|
|
183
|
+
[K in keyof M as M[K] extends Req ? K : never]: Extract<M[K], Req> extends infer T extends Req
|
|
184
|
+
? RequestHandlerFor<R, E, T, `${ModuleName}.${K & string}`>
|
|
185
|
+
: never
|
|
113
186
|
}
|
package/src/client/errors.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/** @effect-diagnostics overriddenSchemaConstructor:skip-file */
|
|
2
|
-
import {
|
|
2
|
+
import { TaggedErrorClass } from "effect-app/Schema"
|
|
3
3
|
import * as Cause from "effect/Cause"
|
|
4
|
-
import * as S from "../Schema.
|
|
4
|
+
import * as S from "../Schema.ts"
|
|
5
5
|
|
|
6
|
-
export const tryToJson = (error:
|
|
6
|
+
export const tryToJson = (error: unknown) => {
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
const errorJson = (error as any).toJSON()
|
|
9
|
+
return errorJson && typeof errorJson === "object" ? errorJson as Record<string, unknown> : { error }
|
|
9
10
|
} catch {
|
|
10
11
|
try {
|
|
11
|
-
return error.toString()
|
|
12
|
+
return { error: (error as any).toString() }
|
|
12
13
|
} catch (err) {
|
|
13
14
|
try {
|
|
14
|
-
return `Failed to convert error: ${err}`
|
|
15
|
+
return { error: `Failed to convert error: ${err}` }
|
|
15
16
|
} catch {
|
|
16
|
-
return `Failed to convert error: unknown failure`
|
|
17
|
+
return { error: `Failed to convert error: unknown failure` }
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -21,7 +22,7 @@ export const tryToJson = (error: { toJSON(): unknown; toString(): string }) => {
|
|
|
21
22
|
|
|
22
23
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
23
24
|
// @ts-expect-error type not used
|
|
24
|
-
export class NotFoundError<ItemType = string> extends
|
|
25
|
+
export class NotFoundError<ItemType = string> extends TaggedErrorClass<NotFoundError<ItemType>>()("NotFoundError", {
|
|
25
26
|
type: S.String,
|
|
26
27
|
id: S.Unknown
|
|
27
28
|
}) {
|
|
@@ -29,70 +30,97 @@ export class NotFoundError<ItemType = string> extends TaggedError<NotFoundError<
|
|
|
29
30
|
props: { type: string; id: unknown; cause?: unknown },
|
|
30
31
|
disableValidation?: boolean
|
|
31
32
|
) {
|
|
32
|
-
super(props
|
|
33
|
+
super(props, disableValidation as any)
|
|
33
34
|
}
|
|
34
35
|
override get message() {
|
|
35
36
|
return `Didn't find ${(this as any).type}#${JSON.stringify((this as any).id)}`
|
|
36
37
|
}
|
|
38
|
+
override toString() {
|
|
39
|
+
return `NotFoundError: ${this.message}`
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
const messageFallback = (messageOrObject?: string | { message: string }) =>
|
|
40
44
|
typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject ?? "" }
|
|
41
45
|
|
|
42
|
-
export class InvalidStateError extends
|
|
46
|
+
export class InvalidStateError extends TaggedErrorClass<InvalidStateError>()("InvalidStateError", {
|
|
43
47
|
message: S.String
|
|
44
48
|
}) {
|
|
45
49
|
constructor(messageOrObject: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
|
|
46
|
-
super(
|
|
50
|
+
super(
|
|
51
|
+
typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject },
|
|
52
|
+
disableValidation as any
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
override toString() {
|
|
56
|
+
return `InvalidStateError: ${this.message}`
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
export class ServiceUnavailableError extends
|
|
60
|
+
export class ServiceUnavailableError extends TaggedErrorClass<ServiceUnavailableError>()("ServiceUnavailableError", {
|
|
51
61
|
message: S.String
|
|
52
62
|
}) {
|
|
53
63
|
constructor(messageOrObject: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
|
|
54
|
-
super(
|
|
64
|
+
super(
|
|
65
|
+
typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject },
|
|
66
|
+
disableValidation as any
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
override toString() {
|
|
70
|
+
return `ServiceUnavailableError: ${this.message}`
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
export class ValidationError extends
|
|
74
|
+
export class ValidationError extends TaggedErrorClass<ValidationError>()("ValidationError", {
|
|
59
75
|
errors: S.Array(S.Unknown)
|
|
60
76
|
}) {
|
|
61
77
|
constructor(
|
|
62
78
|
props: { errors: ReadonlyArray<unknown>; cause?: unknown },
|
|
63
79
|
disableValidation?: boolean
|
|
64
80
|
) {
|
|
65
|
-
super(props
|
|
81
|
+
super(props, disableValidation as any)
|
|
66
82
|
}
|
|
67
83
|
override get message() {
|
|
68
84
|
return `Validation failed: ${(this as any).errors.map((e: any) => JSON.stringify(e, undefined, 2)).join(",\n")}`
|
|
69
85
|
}
|
|
86
|
+
override toString() {
|
|
87
|
+
return `ValidationError: ${this.message}`
|
|
88
|
+
}
|
|
70
89
|
}
|
|
71
90
|
|
|
72
|
-
export class NotLoggedInError extends
|
|
91
|
+
export class NotLoggedInError extends TaggedErrorClass<NotLoggedInError>()("NotLoggedInError", {
|
|
73
92
|
message: S.String
|
|
74
93
|
}) {
|
|
75
94
|
constructor(messageOrObject?: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
|
|
76
|
-
super(messageFallback(messageOrObject)
|
|
95
|
+
super(messageFallback(messageOrObject), disableValidation as any)
|
|
96
|
+
}
|
|
97
|
+
override toString() {
|
|
98
|
+
return `NotLoggedInError: ${this.message}`
|
|
77
99
|
}
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
/**
|
|
81
103
|
* The user carries a valid Userprofile, but there is a problem with the login none the less.
|
|
82
104
|
*/
|
|
83
|
-
export class LoginError extends
|
|
105
|
+
export class LoginError extends TaggedErrorClass<LoginError>()("NotLoggedInError", {
|
|
84
106
|
message: S.String
|
|
85
107
|
}) {
|
|
86
108
|
constructor(messageOrObject?: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
|
|
87
|
-
super(messageFallback(messageOrObject)
|
|
109
|
+
super(messageFallback(messageOrObject), disableValidation as any)
|
|
110
|
+
}
|
|
111
|
+
override toString() {
|
|
112
|
+
return `LoginError: ${this.message}`
|
|
88
113
|
}
|
|
89
114
|
}
|
|
90
115
|
|
|
91
|
-
export class UnauthorizedError extends
|
|
116
|
+
export class UnauthorizedError extends TaggedErrorClass<UnauthorizedError>()("UnauthorizedError", {
|
|
92
117
|
message: S.String
|
|
93
118
|
}) {
|
|
94
119
|
constructor(messageOrObject?: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
|
|
95
|
-
super(messageFallback(messageOrObject)
|
|
120
|
+
super(messageFallback(messageOrObject), disableValidation as any)
|
|
121
|
+
}
|
|
122
|
+
override toString() {
|
|
123
|
+
return `UnauthorizedError: ${this.message}`
|
|
96
124
|
}
|
|
97
125
|
}
|
|
98
126
|
|
|
@@ -104,7 +132,7 @@ type OptimisticConcurrencyDetails = {
|
|
|
104
132
|
readonly found?: string | undefined
|
|
105
133
|
}
|
|
106
134
|
|
|
107
|
-
export class OptimisticConcurrencyException extends
|
|
135
|
+
export class OptimisticConcurrencyException extends TaggedErrorClass<OptimisticConcurrencyException>()(
|
|
108
136
|
"OptimisticConcurrencyException",
|
|
109
137
|
{ message: S.String }
|
|
110
138
|
) {
|
|
@@ -116,11 +144,56 @@ export class OptimisticConcurrencyException extends TaggedError<OptimisticConcur
|
|
|
116
144
|
| ({ message: string; cause?: unknown; raw?: unknown }),
|
|
117
145
|
disableValidation?: boolean
|
|
118
146
|
) {
|
|
119
|
-
super(
|
|
147
|
+
super(
|
|
148
|
+
"message" in args ? args : { message: `Existing ${args.type} ${args.id} record changed` },
|
|
149
|
+
disableValidation as any
|
|
150
|
+
)
|
|
120
151
|
if (!("message" in args)) {
|
|
121
152
|
this.details = args
|
|
122
153
|
}
|
|
123
154
|
}
|
|
155
|
+
override toString() {
|
|
156
|
+
return `OptimisticConcurrencyException: ${this.message}`
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Raised by a store adapter when a database operation fails for an
|
|
162
|
+
* infrastructure reason (request timeout, throttle, 5xx, dropped socket, or any
|
|
163
|
+
* non-conflict error). Distinct from `OptimisticConcurrencyException`, which is
|
|
164
|
+
* an expected etag conflict.
|
|
165
|
+
*
|
|
166
|
+
* `transient` is set by the adapter for failures worth retrying (timeout /
|
|
167
|
+
* throttle / 5xx / network). `cause` is the underlying adapter error, carried
|
|
168
|
+
* through a `Defect` schema so it serializes (an `Error` encodes to
|
|
169
|
+
* `{ name, message, cause }`) instead of breaking JSON encoding of the channel.
|
|
170
|
+
*
|
|
171
|
+
* Treated by the api/client/FE machinery like an unexpected (500-class) error.
|
|
172
|
+
*/
|
|
173
|
+
export class DatabaseError extends TaggedErrorClass<DatabaseError>()(
|
|
174
|
+
"DatabaseError",
|
|
175
|
+
{
|
|
176
|
+
message: S.String,
|
|
177
|
+
transient: S.Boolean,
|
|
178
|
+
cause: S.optional(S.Defect())
|
|
179
|
+
}
|
|
180
|
+
) {
|
|
181
|
+
constructor(
|
|
182
|
+
args: { message?: string; transient?: boolean; cause?: unknown },
|
|
183
|
+
disableValidation?: boolean
|
|
184
|
+
) {
|
|
185
|
+
super(
|
|
186
|
+
{
|
|
187
|
+
message: args.message ?? "Database operation failed",
|
|
188
|
+
transient: args.transient ?? false,
|
|
189
|
+
cause: args.cause
|
|
190
|
+
},
|
|
191
|
+
disableValidation as any
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
override toString() {
|
|
195
|
+
return `DatabaseError: ${this.message}`
|
|
196
|
+
}
|
|
124
197
|
}
|
|
125
198
|
|
|
126
199
|
const MutationOnlyErrors = [
|
|
@@ -134,7 +207,8 @@ const GeneralErrors = [
|
|
|
134
207
|
LoginError,
|
|
135
208
|
UnauthorizedError,
|
|
136
209
|
ValidationError,
|
|
137
|
-
ServiceUnavailableError
|
|
210
|
+
ServiceUnavailableError,
|
|
211
|
+
DatabaseError
|
|
138
212
|
] as const
|
|
139
213
|
|
|
140
214
|
export const SupportedErrors = S.Union([
|
|
@@ -169,11 +243,17 @@ export const silenceError = (e: Record<PropertyKey, any>) => {
|
|
|
169
243
|
}
|
|
170
244
|
|
|
171
245
|
export class CauseException<E> extends Error {
|
|
172
|
-
|
|
246
|
+
readonly originalCause: Cause.Cause<E>
|
|
247
|
+
readonly _tag: string
|
|
248
|
+
|
|
249
|
+
constructor(originalCause: Cause.Cause<E>, _tag: string) {
|
|
173
250
|
const limit = Error.stackTraceLimit
|
|
174
251
|
Error.stackTraceLimit = 0
|
|
175
252
|
super()
|
|
176
253
|
Error.stackTraceLimit = limit
|
|
254
|
+
this.originalCause = originalCause
|
|
255
|
+
this._tag = _tag
|
|
256
|
+
this.cause = Cause.squash(originalCause)
|
|
177
257
|
// v4: makeFiberFailure removed — use Cause.prettyErrors instead
|
|
178
258
|
const errors = Cause.prettyErrors(originalCause)
|
|
179
259
|
const first = errors[0]
|
|
@@ -213,17 +293,17 @@ export class CauseException<E> extends Error {
|
|
|
213
293
|
}
|
|
214
294
|
}
|
|
215
295
|
|
|
216
|
-
export const tryToReport = (error: { toReport(): unknown
|
|
296
|
+
export const tryToReport = (error: { toReport(): Record<string, unknown>; toString(): string }) => {
|
|
217
297
|
try {
|
|
218
298
|
return error.toReport()
|
|
219
299
|
} catch {
|
|
220
300
|
try {
|
|
221
|
-
return error.toString()
|
|
301
|
+
return { error: error.toString() }
|
|
222
302
|
} catch (err) {
|
|
223
303
|
try {
|
|
224
|
-
return `Failed to convert error: ${err}`
|
|
304
|
+
return { error: `Failed to convert error: ${err}` }
|
|
225
305
|
} catch {
|
|
226
|
-
return `Failed to convert error: unknown failure`
|
|
306
|
+
return { error: `Failed to convert error: unknown failure` }
|
|
227
307
|
}
|
|
228
308
|
}
|
|
229
309
|
}
|