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