effect-app 4.0.0-beta.99 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2028 -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 +2 -2
- 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 +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/Effect.d.ts +3 -3
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +6 -9
- 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 +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 +611 -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 +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 +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 +370 -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 -0
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -1
- package/dist/Pure.d.ts +5 -3
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +5 -2
- 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 +297 -72
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +331 -67
- 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 +223 -6
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +189 -23
- 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 +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/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 +13 -8
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +148 -29
- 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/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 -39
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -37
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/withToast.d.ts +30 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +64 -0
- package/package.json +26 -266
- 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 +6 -13
- package/src/ConfigProvider.ts +4 -47
- package/src/Context.ts +9 -8
- package/src/DataDependencies.ts +171 -0
- package/src/Effect.ts +9 -12
- package/src/Emailer.ts +51 -0
- 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 +988 -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 +129 -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 +532 -0
- package/src/Model/query.ts +13 -0
- package/src/Model.ts +5 -0
- package/src/NonEmptySet.ts +6 -4
- package/src/Option.ts +2 -0
- package/src/Pure.ts +6 -3
- 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 +408 -91
- 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 +6 -2
- package/src/Store.ts +325 -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 +291 -126
- 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/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 -158
- package/src/validation.ts +2 -2
- package/src/withToast.ts +133 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/rpcMiddlewareContext.test.d.ts.map +1 -0
- package/test/moreStrings.test.ts +55 -10
- 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/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
- package/tsconfig.json.bak +0 -12
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { flow } from "effect/Function"
|
|
2
|
+
import { constant, flow } from "effect/Function"
|
|
3
3
|
import * as Layer from "effect/Layer"
|
|
4
4
|
import * as ManagedRuntime from "effect/ManagedRuntime"
|
|
5
|
+
import * as Option from "effect/Option"
|
|
5
6
|
import * as Predicate from "effect/Predicate"
|
|
7
|
+
import { Rpc, RpcClient, RpcGroup, RpcSerialization } from "effect/rpc"
|
|
6
8
|
import * as Schema from "effect/Schema"
|
|
9
|
+
import * as Stream from "effect/Stream"
|
|
7
10
|
import * as Struct from "effect/Struct"
|
|
8
|
-
import
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import * as Effect from "../Effect.
|
|
12
|
-
import { HttpClient, HttpClientRequest } from "../http.
|
|
13
|
-
import
|
|
14
|
-
import type * as S from "../Schema.
|
|
15
|
-
import { typedKeysOf, typedValuesOf } from "../utils.
|
|
16
|
-
import type { Client, ClientForOptions, ExtractModuleName, RequestsAny } from "./clientFor.
|
|
11
|
+
import * as Config from "../Config.ts"
|
|
12
|
+
import * as Context from "../Context.ts"
|
|
13
|
+
import * as DataDependencies from "../DataDependencies.ts"
|
|
14
|
+
import * as Effect from "../Effect.ts"
|
|
15
|
+
import { HttpClient, HttpClientRequest } from "../http.ts"
|
|
16
|
+
import { Invalidation } from "../rpc.ts"
|
|
17
|
+
import type * as S from "../Schema.ts"
|
|
18
|
+
import { typedKeysOf, typedValuesOf } from "../utils.ts"
|
|
19
|
+
import type { Client, ClientForOptions, ExtractModuleName, RequestsAny } from "./clientFor.ts"
|
|
20
|
+
import { InvalidationKeysFromServer } from "./InvalidationKeys.ts"
|
|
17
21
|
|
|
18
22
|
export interface ApiConfig {
|
|
19
23
|
url: string
|
|
@@ -21,25 +25,24 @@ export interface ApiConfig {
|
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export const DefaultApiConfig = Config.all({
|
|
24
|
-
url: Config.
|
|
25
|
-
headers: Config
|
|
26
|
-
.schema(
|
|
27
|
-
Config.Record(Schema.String, Schema.String),
|
|
28
|
-
"headers"
|
|
29
|
-
)
|
|
30
|
-
.pipe(Config.option)
|
|
28
|
+
url: Config.String("apiUrl").pipe(Config.withDefault("/api")),
|
|
29
|
+
headers: Config.Record(Schema.String, Schema.String, "headers").pipe(Config.option)
|
|
31
30
|
})
|
|
32
31
|
|
|
33
32
|
export type Req = S.Top & {
|
|
34
|
-
|
|
33
|
+
readonly make: (...args: any[]) => any
|
|
35
34
|
_tag: string
|
|
36
35
|
fields: S.Struct.Fields
|
|
37
36
|
success: S.Top
|
|
38
37
|
error: S.Top
|
|
38
|
+
/** Optional final-value schema for stream requests. When set, the execute effect resolves with the last stream value decoded to this type. */
|
|
39
|
+
final?: S.Top
|
|
39
40
|
config?: Record<string, any>
|
|
40
41
|
readonly id: string
|
|
41
42
|
readonly moduleName: string
|
|
42
|
-
readonly "
|
|
43
|
+
readonly type: "command" | "query"
|
|
44
|
+
readonly stream: boolean
|
|
45
|
+
readonly middleware?: unknown
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
class RequestName extends Context.Reference("RequestName", {
|
|
@@ -58,7 +61,7 @@ export const HttpClientLayer = (config: ApiConfig) =>
|
|
|
58
61
|
HttpClientRequest.setHeaders(config.headers.pipe(Option.getOrElse(() => ({}))))
|
|
59
62
|
),
|
|
60
63
|
HttpClient.mapRequestEffect((req) =>
|
|
61
|
-
Effect.map(RequestName
|
|
64
|
+
Effect.map(RequestName, (ctx) =>
|
|
62
65
|
flow(
|
|
63
66
|
HttpClientRequest.appendUrlParam("action", ctx.requestName),
|
|
64
67
|
HttpClientRequest.appendUrl("/" + ctx.moduleName)
|
|
@@ -104,33 +107,61 @@ const getFiltered = <M extends RequestsAny>(resource: M) => {
|
|
|
104
107
|
return filtered as unknown as Filtered
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
export const getMeta = <M extends RequestsAny>(
|
|
110
|
+
export const getMeta = <M extends RequestsAny>(
|
|
111
|
+
resource: M
|
|
112
|
+
): { moduleName: ExtractModuleName<M>; middleware?: unknown } => {
|
|
108
113
|
const first = typedValuesOf(getFiltered(resource))[0]
|
|
109
|
-
if (first && "moduleName" in first) return { moduleName: first.moduleName
|
|
114
|
+
if (first && "moduleName" in first) return { moduleName: first.moduleName, middleware: (first as any).middleware }
|
|
110
115
|
throw new Error("No moduleName on requests!")
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
export const makeRpcGroupFromRequestsAndModuleName = <M extends RequestsAny, const ModuleName extends string>(
|
|
114
119
|
resource: M,
|
|
115
|
-
moduleName: ModuleName
|
|
120
|
+
moduleName: ModuleName,
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
+
middleware?: any
|
|
116
123
|
) => {
|
|
117
124
|
const filtered = getFiltered(resource)
|
|
118
125
|
type newM = typeof filtered
|
|
119
|
-
const
|
|
126
|
+
const baseRpcs = RpcGroup
|
|
120
127
|
.make(
|
|
121
128
|
...typedValuesOf(filtered).map((_) => {
|
|
122
|
-
|
|
129
|
+
const r = _ as any
|
|
130
|
+
const isStream = r.stream
|
|
131
|
+
const isCommand = r.type === "command"
|
|
132
|
+
return (isCommand
|
|
133
|
+
? isStream
|
|
134
|
+
? Invalidation.makeStreamRpc(r._tag, {
|
|
135
|
+
payload: r,
|
|
136
|
+
success: r.success,
|
|
137
|
+
error: r.error,
|
|
138
|
+
stream: true as const
|
|
139
|
+
})
|
|
140
|
+
: Invalidation.makeCommandRpc(r._tag, { payload: r, success: r.success, error: r.error })
|
|
141
|
+
: Rpc.make(r._tag, {
|
|
142
|
+
payload: r,
|
|
143
|
+
success: isStream ? r.success : Invalidation.QueryResponseWithMetaData(r.success),
|
|
144
|
+
error: r.error,
|
|
145
|
+
stream: isStream
|
|
146
|
+
})) as any
|
|
123
147
|
})
|
|
124
148
|
)
|
|
125
|
-
.prefix(`${moduleName}.`)
|
|
126
|
-
|
|
127
|
-
|
|
149
|
+
.prefix(`${moduleName}.`)
|
|
150
|
+
// Attach the middleware tag (schema-only on the client — no Live invoked)
|
|
151
|
+
// so its declared `error` joins the rpc failure union via
|
|
152
|
+
// `Rpc.exitSchema`'s `rpc.middlewares[*].error` walk. Required for stream
|
|
153
|
+
// rpcs whose top-level `errorSchema` is forced to `Never` by effect-rpc;
|
|
154
|
+
// without it, middleware-thrown errors fail client decode.
|
|
155
|
+
const rpcs = (middleware ? baseRpcs.middleware(middleware) : baseRpcs) as unknown as RpcGroup.RpcGroup<
|
|
156
|
+
Rpc.Prefixed<RpcHandlers<newM>[keyof newM], `${ModuleName}.`>
|
|
157
|
+
>
|
|
128
158
|
return rpcs
|
|
129
159
|
}
|
|
130
160
|
|
|
131
|
-
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
const makeRpcTag = <M extends RequestsAny>(resource: M, middleware?: any) => {
|
|
132
163
|
const meta = getMeta(resource)
|
|
133
|
-
const rpcs = makeRpcGroupFromRequestsAndModuleName(resource, meta.moduleName)
|
|
164
|
+
const rpcs = makeRpcGroupFromRequestsAndModuleName(resource, meta.moduleName, middleware)
|
|
134
165
|
|
|
135
166
|
// Use Object.assign instead of class extension to avoid TS2509 with complex generic return types.
|
|
136
167
|
// The first type arg is `any` because this is a dynamically created tag — its identity is the string key.
|
|
@@ -141,7 +172,7 @@ const makeRpcTag = <M extends RequestsAny>(resource: M) => {
|
|
|
141
172
|
// Use Layer.effect directly (not TheClient.toLayer) so TypeScript properly excludes Scope
|
|
142
173
|
const layer = Layer.effect(
|
|
143
174
|
TheClient,
|
|
144
|
-
RpcClient.make(rpcs
|
|
175
|
+
RpcClient.make(rpcs)
|
|
145
176
|
)
|
|
146
177
|
return Object.assign(TheClient, { layer })
|
|
147
178
|
}
|
|
@@ -149,124 +180,258 @@ const makeRpcTag = <M extends RequestsAny>(resource: M) => {
|
|
|
149
180
|
const makeApiClientFactory = Effect
|
|
150
181
|
.gen(function*() {
|
|
151
182
|
const ctx = yield* Effect.context<RpcSerialization.RpcSerialization | HttpClient.HttpClient>()
|
|
152
|
-
const makeClientFor =
|
|
183
|
+
const makeClientFor = Effect.fnUntraced(function*<M extends RequestsAny>(
|
|
153
184
|
resource: M,
|
|
154
185
|
requestLevelLayers = Layer.empty,
|
|
155
186
|
options?: ClientForOptions
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
187
|
+
) {
|
|
188
|
+
const meta = getMeta(resource)
|
|
189
|
+
|
|
190
|
+
const TheClient = makeRpcTag(resource, meta.middleware)
|
|
191
|
+
|
|
192
|
+
// TODO: somehow we need a protocol per REQUEST kind of it seems ...
|
|
193
|
+
// otherwise it locks up on the client, navigation remains empty...
|
|
194
|
+
const clientLayer = TheClient.layer.pipe(
|
|
195
|
+
// add ApiClientFactory for nested schemas
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
197
|
+
Layer.provide(Layer.succeed(ApiClientFactory, makeClientForCached as any)),
|
|
198
|
+
Layer.provide(
|
|
199
|
+
RpcClient
|
|
200
|
+
.layerProtocolHttp({ url: "" }) // why not here set meta.moduleName as root?
|
|
201
|
+
.pipe(
|
|
202
|
+
Layer.provideMerge(Layer.succeedContext(ctx))
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
const mr = ManagedRuntime.make(clientLayer)
|
|
207
|
+
|
|
208
|
+
const filtered = getFiltered(resource)
|
|
209
|
+
|
|
210
|
+
// Unwrap `CommandResponseWithMetaData` (success) and `CommandFailureWithMetaData`
|
|
211
|
+
// (handler-thrown failure): forward accumulated invalidation keys to
|
|
212
|
+
// `InvalidationKeysFromServer` and yield the raw payload / re-fail with the raw
|
|
213
|
+
// error. Middleware-thrown failures arrive raw on the Cause already (no wrap to
|
|
214
|
+
// strip) — the `else` branch passes them through.
|
|
215
|
+
const forwardDependencies = (
|
|
216
|
+
dependencies: DataDependencies.DataDependencySet | undefined,
|
|
217
|
+
options?: { readonly reads?: boolean }
|
|
218
|
+
) =>
|
|
219
|
+
dependencies === undefined
|
|
220
|
+
? Effect.void
|
|
221
|
+
: Effect.gen(function*() {
|
|
222
|
+
const dependencyRecorder = yield* DataDependencies.getDataDependencyRecorder
|
|
223
|
+
if (options?.reads) {
|
|
224
|
+
yield* Effect.forEach(dependencies.reads, dependencyRecorder.read, { discard: true })
|
|
225
|
+
}
|
|
226
|
+
yield* Effect.forEach(dependencies.writes, dependencyRecorder.write, { discard: true })
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
const unwrapCommand = (eff: Effect.Effect<any, any, any>): Effect.Effect<any, any, any> =>
|
|
230
|
+
eff.pipe(
|
|
231
|
+
Effect.flatMap((result: any) =>
|
|
232
|
+
Effect.gen(function*() {
|
|
233
|
+
const keys: ReadonlyArray<Invalidation.InvalidationKey> = result?.metadata?.invalidateQueries ?? []
|
|
234
|
+
const invalidationKeys = yield* InvalidationKeysFromServer
|
|
235
|
+
yield* Effect.forEach(keys, (key) => invalidationKeys.add(key), { discard: true })
|
|
236
|
+
yield* forwardDependencies(result?.metadata?.dataDependencies)
|
|
237
|
+
return result.payload
|
|
238
|
+
})
|
|
239
|
+
),
|
|
240
|
+
Effect.catch((result: any) =>
|
|
241
|
+
result?._tag === "CommandFailureWithMetaData"
|
|
242
|
+
? Effect.gen(function*() {
|
|
243
|
+
const keys: ReadonlyArray<Invalidation.InvalidationKey> = result.metadata?.invalidateQueries ?? []
|
|
244
|
+
const invalidationKeys = yield* InvalidationKeysFromServer
|
|
245
|
+
yield* Effect.forEach(keys, (key) => invalidationKeys.add(key), { discard: true })
|
|
246
|
+
yield* forwardDependencies(result.metadata?.dataDependencies)
|
|
247
|
+
return yield* Effect.fail(result.error)
|
|
172
248
|
})
|
|
173
|
-
.
|
|
174
|
-
Layer.provideMerge(Layer.succeedContext(ctx))
|
|
175
|
-
)
|
|
249
|
+
: Effect.fail(result)
|
|
176
250
|
)
|
|
177
251
|
)
|
|
178
|
-
const mr = ManagedRuntime.make(clientLayer)
|
|
179
252
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
253
|
+
const unwrapQuery = (eff: Effect.Effect<any, any, any>): Effect.Effect<any, any, any> =>
|
|
254
|
+
eff.pipe(
|
|
255
|
+
Effect.flatMap((result: any) =>
|
|
256
|
+
Effect.gen(function*() {
|
|
257
|
+
yield* forwardDependencies(result?.metadata?.dataDependencies, { reads: true })
|
|
258
|
+
return result.payload
|
|
259
|
+
})
|
|
260
|
+
)
|
|
261
|
+
)
|
|
186
262
|
|
|
187
|
-
|
|
263
|
+
return {
|
|
264
|
+
mr,
|
|
265
|
+
client: typedKeysOf(filtered)
|
|
266
|
+
.reduce((prev, cur) => {
|
|
267
|
+
const h = filtered[cur]!
|
|
268
|
+
|
|
269
|
+
const Request = h
|
|
270
|
+
|
|
271
|
+
const id = `${meta.moduleName}.${cur as string}`
|
|
272
|
+
.replaceAll(".js", "")
|
|
273
|
+
|
|
274
|
+
const requestMeta = {
|
|
275
|
+
Request,
|
|
276
|
+
id,
|
|
277
|
+
options,
|
|
278
|
+
disableQueryInvalidation: (h as { config?: { disableQueryInvalidation?: boolean } })
|
|
279
|
+
.config
|
|
280
|
+
?.disableQueryInvalidation === true
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const requestNameLayer = Layer.succeed(RequestName, {
|
|
284
|
+
requestName: cur as string,
|
|
285
|
+
moduleName: meta.moduleName
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
const layers = requestLevelLayers.pipe(Layer.provideMerge(requestNameLayer))
|
|
289
|
+
|
|
290
|
+
const fields = Struct.omit(Request.fields, ["_tag"] as const)
|
|
291
|
+
const requestAttr = `${meta.moduleName}.${h._tag}`
|
|
292
|
+
const isCommand = h.type === "command"
|
|
293
|
+
const isStream = h.stream
|
|
294
|
+
|
|
295
|
+
const buildEffect = (input: any) =>
|
|
296
|
+
mr.contextEffect.pipe(
|
|
297
|
+
Effect.flatMap((svcs) => {
|
|
298
|
+
const rpcEffect = TheClient
|
|
299
|
+
.use((client) => (client as any)[requestAttr]!(Request.make(input)) as Effect.Effect<any, any>)
|
|
300
|
+
.pipe(
|
|
301
|
+
// local: true → isolate to this RPC call. `layers` is pure today
|
|
302
|
+
// (RequestName + caller-supplied requestLevelLayers), but the
|
|
303
|
+
// flag prevents a stateful caller-supplied layer from leaking
|
|
304
|
+
// across RPC calls via the ambient fiber MemoMap.
|
|
305
|
+
Effect.provide(layers, { local: true }),
|
|
306
|
+
Effect.provide(svcs)
|
|
307
|
+
)
|
|
308
|
+
return isCommand ? unwrapCommand(rpcEffect) : isStream ? rpcEffect : unwrapQuery(rpcEffect)
|
|
309
|
+
}),
|
|
310
|
+
// Forwarding the server's dependency metadata needs a recorder in scope. A parent
|
|
311
|
+
// query/command (vue) provides one; a top-level call gets a fresh per-request one.
|
|
312
|
+
DataDependencies.ensureDataDependencyRecorder
|
|
313
|
+
)
|
|
188
314
|
|
|
189
|
-
|
|
190
|
-
|
|
315
|
+
const buildStream = (input: any) => {
|
|
316
|
+
const stream = Stream.unwrap(
|
|
317
|
+
mr.contextEffect.pipe(
|
|
318
|
+
Effect.flatMap((svcs) =>
|
|
319
|
+
TheClient
|
|
320
|
+
.useSync((client) => {
|
|
321
|
+
const rpcStream = (client as any)[requestAttr]!(
|
|
322
|
+
Request.make(input)
|
|
323
|
+
) as Stream.Stream<any, any, any>
|
|
324
|
+
return rpcStream.pipe(
|
|
325
|
+
// Collect server invalidation keys from the "done" chunk, then discard it.
|
|
326
|
+
Stream.tap((item: any) =>
|
|
327
|
+
item._tag === "done" || item._tag === "metadata"
|
|
328
|
+
? Effect.gen(function*() {
|
|
329
|
+
const metadata = item.metadata as Invalidation.CommandMetaData
|
|
330
|
+
const invalidationKeys = yield* InvalidationKeysFromServer
|
|
331
|
+
yield* Effect.forEach(metadata.invalidateQueries, invalidationKeys.add, {
|
|
332
|
+
discard: true
|
|
333
|
+
})
|
|
334
|
+
const dependencyRecorder = yield* DataDependencies.getDataDependencyRecorder
|
|
335
|
+
yield* Effect.forEach(
|
|
336
|
+
metadata.dataDependencies.reads,
|
|
337
|
+
dependencyRecorder.read,
|
|
338
|
+
{ discard: true }
|
|
339
|
+
)
|
|
340
|
+
yield* Effect.forEach(
|
|
341
|
+
metadata.dataDependencies.writes,
|
|
342
|
+
dependencyRecorder.write,
|
|
343
|
+
{ discard: true }
|
|
344
|
+
)
|
|
345
|
+
})
|
|
346
|
+
: Effect.void
|
|
347
|
+
),
|
|
348
|
+
Stream.filter((item: any) => item._tag === "value"),
|
|
349
|
+
Stream.map((item: any) => item.value),
|
|
350
|
+
// V2: unwrap StreamFailureChunk — forward keys from failures too,
|
|
351
|
+
// then re-fail with the original error so callers see the unmodified
|
|
352
|
+
// error type.
|
|
353
|
+
Stream.catch((err: any) =>
|
|
354
|
+
err?._tag === "error" && err?.metadata
|
|
355
|
+
? Stream.fromEffect(
|
|
356
|
+
Effect.gen(function*() {
|
|
357
|
+
const metadata = err.metadata as Invalidation.CommandMetaData
|
|
358
|
+
const invalidationKeys = yield* InvalidationKeysFromServer
|
|
359
|
+
yield* Effect.forEach(metadata.invalidateQueries, invalidationKeys.add, {
|
|
360
|
+
discard: true
|
|
361
|
+
})
|
|
362
|
+
const dependencyRecorder = yield* DataDependencies.getDataDependencyRecorder
|
|
363
|
+
yield* Effect.forEach(
|
|
364
|
+
metadata.dataDependencies.writes,
|
|
365
|
+
dependencyRecorder.write,
|
|
366
|
+
{ discard: true }
|
|
367
|
+
)
|
|
368
|
+
return yield* Effect.fail(err.error)
|
|
369
|
+
})
|
|
370
|
+
)
|
|
371
|
+
: Stream.fail(err)
|
|
372
|
+
),
|
|
373
|
+
// local: true — see buildEffect above.
|
|
374
|
+
Stream.provide(layers, { local: true }),
|
|
375
|
+
Stream.provide(svcs)
|
|
376
|
+
)
|
|
377
|
+
})
|
|
378
|
+
.pipe(Effect.provide(svcs))
|
|
379
|
+
)
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
// Forwarding the server's dependency metadata needs a recorder in scope. A parent
|
|
383
|
+
// query/command (vue) provides one; a top-level stream call gets a fresh per-request one.
|
|
384
|
+
return Stream.unwrap(
|
|
385
|
+
Effect.map(
|
|
386
|
+
DataDependencies.DataDependencyRecorder,
|
|
387
|
+
(current) =>
|
|
388
|
+
current === "root"
|
|
389
|
+
? Stream.provide(stream, DataDependencies.DataDependencyRecorder.layer)
|
|
390
|
+
: stream
|
|
391
|
+
)
|
|
392
|
+
)
|
|
393
|
+
}
|
|
191
394
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
395
|
+
// @ts-expect-error doc
|
|
396
|
+
prev[cur] = Object.keys(fields).length === 0
|
|
397
|
+
? {
|
|
398
|
+
handler: isStream ? constant(buildStream({})) : constant(buildEffect({})),
|
|
399
|
+
...requestMeta
|
|
400
|
+
}
|
|
401
|
+
: {
|
|
402
|
+
handler: isStream
|
|
403
|
+
? (req: any) => buildStream(req)
|
|
404
|
+
: (req: any) => buildEffect(req),
|
|
405
|
+
...requestMeta
|
|
196
406
|
}
|
|
197
407
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const layers = requestLevelLayers.pipe(Layer.provideMerge(requestNameLayer))
|
|
204
|
-
|
|
205
|
-
const fields = Struct.omit(Request.fields, ["_tag"] as const)
|
|
206
|
-
const requestAttr = `${meta.moduleName}.${h._tag}`
|
|
207
|
-
// @ts-expect-error doc
|
|
208
|
-
prev[cur] = Object.keys(fields).length === 0
|
|
209
|
-
? {
|
|
210
|
-
handler: mr.contextEffect.pipe(
|
|
211
|
-
Effect.flatMap((svcs) =>
|
|
212
|
-
TheClient
|
|
213
|
-
.use((client) => (client as any)[requestAttr]!(new Request()) as Effect.Effect<any, any, never>)
|
|
214
|
-
.pipe(
|
|
215
|
-
Effect.provide(layers),
|
|
216
|
-
Effect.provide(svcs)
|
|
217
|
-
)
|
|
218
|
-
)
|
|
219
|
-
),
|
|
220
|
-
...requestMeta
|
|
221
|
-
}
|
|
222
|
-
: {
|
|
223
|
-
handler: (req: any) =>
|
|
224
|
-
mr.contextEffect.pipe(
|
|
225
|
-
Effect.flatMap((svcs) =>
|
|
226
|
-
TheClient
|
|
227
|
-
.use((client) =>
|
|
228
|
-
(client as any)[requestAttr]!(new Request(req)) as Effect.Effect<any, any, never>
|
|
229
|
-
)
|
|
230
|
-
.pipe(
|
|
231
|
-
Effect.provide(layers),
|
|
232
|
-
Effect.provide(svcs)
|
|
233
|
-
)
|
|
234
|
-
)
|
|
235
|
-
),
|
|
236
|
-
|
|
237
|
-
...requestMeta
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return prev
|
|
241
|
-
}, {} as Client<M, ExtractModuleName<M>>)
|
|
242
|
-
}
|
|
243
|
-
})
|
|
408
|
+
return prev
|
|
409
|
+
}, {} as Client<M, ExtractModuleName<M>>)
|
|
410
|
+
}
|
|
411
|
+
})
|
|
244
412
|
|
|
245
413
|
const register: ManagedRuntime.ManagedRuntime<any, any>[] = []
|
|
246
414
|
yield* Effect.addFinalizer(() => Effect.forEach(register, (mr) => mr.disposeEffect))
|
|
247
415
|
|
|
248
416
|
const cacheL = new Map<any, Map<any, Client<any, any>>>()
|
|
249
417
|
|
|
250
|
-
function makeClientForCached(requestLevelLayers: Layer.Layer<never
|
|
418
|
+
function makeClientForCached(requestLevelLayers: Layer.Layer<never>, options?: ClientForOptions) {
|
|
251
419
|
let cache = cacheL.get(requestLevelLayers)
|
|
252
420
|
if (!cache) {
|
|
253
421
|
cache = new Map<any, Client<any, any>>()
|
|
254
422
|
cacheL.set(requestLevelLayers, cache)
|
|
255
423
|
}
|
|
256
424
|
|
|
257
|
-
return
|
|
258
|
-
models
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
register.push(m.mr)
|
|
268
|
-
return m.client
|
|
269
|
-
})
|
|
425
|
+
return Effect.fnUntraced(function*<M extends RequestsAny>(models: M) {
|
|
426
|
+
const found = cache.get(models) as Client<M, ExtractModuleName<M>> | undefined
|
|
427
|
+
if (found) {
|
|
428
|
+
return found
|
|
429
|
+
}
|
|
430
|
+
const m = yield* makeClientFor(models, requestLevelLayers, options)
|
|
431
|
+
cache.set(models, m.client)
|
|
432
|
+
register.push(m.mr)
|
|
433
|
+
return m.client
|
|
434
|
+
})
|
|
270
435
|
}
|
|
271
436
|
|
|
272
437
|
return makeClientForCached
|
|
@@ -288,7 +453,7 @@ export class ApiClientFactory
|
|
|
288
453
|
)
|
|
289
454
|
|
|
290
455
|
static readonly makeFor =
|
|
291
|
-
(requestLevelLayers: Layer.Layer<never
|
|
456
|
+
(requestLevelLayers: Layer.Layer<never>, options?: ClientForOptions) =>
|
|
292
457
|
<M extends RequestsAny>(
|
|
293
458
|
resource: M
|
|
294
459
|
) =>
|