effect-app 4.0.0-beta.26 → 4.0.0-beta.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1194 -0
- package/dist/Array.d.ts +3 -2
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +4 -4
- package/dist/Chunk.d.ts +1 -1
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +4 -2
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +3 -6
- package/dist/Config/internal/configSecretURL.d.ts +1 -1
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Config.d.ts +7 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +6 -0
- package/dist/ConfigProvider.d.ts +39 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +42 -0
- package/dist/Context.d.ts +42 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/DataDependencies.d.ts +158 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +39 -0
- package/dist/Effect.d.ts +13 -12
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -8
- package/dist/Emailer.d.ts +51 -0
- package/dist/Emailer.d.ts.map +1 -0
- package/dist/Emailer.js +7 -0
- package/dist/Function.d.ts +1 -1
- package/dist/Function.d.ts.map +1 -1
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Layer.d.ts +11 -7
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +3 -2
- package/dist/Model/Repository/Registry.d.ts +21 -0
- package/dist/Model/Repository/Registry.d.ts.map +1 -0
- package/dist/Model/Repository/Registry.js +18 -0
- package/dist/Model/Repository/ext.d.ts +60 -0
- package/dist/Model/Repository/ext.d.ts.map +1 -0
- package/dist/Model/Repository/ext.js +122 -0
- package/dist/Model/Repository/internal/internal.d.ts +63 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +430 -0
- package/dist/Model/Repository/legacy.d.ts +21 -0
- package/dist/Model/Repository/legacy.d.ts.map +1 -0
- package/dist/Model/Repository/legacy.js +2 -0
- package/dist/Model/Repository/makeRepo.d.ts +54 -0
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
- package/dist/Model/Repository/makeRepo.js +27 -0
- package/dist/Model/Repository/service.d.ts +121 -0
- package/dist/Model/Repository/service.d.ts.map +1 -0
- package/dist/Model/Repository/service.js +2 -0
- package/dist/Model/Repository/validation.d.ts +58 -0
- package/dist/Model/Repository/validation.d.ts.map +1 -0
- package/dist/Model/Repository/validation.js +32 -0
- package/dist/Model/Repository.d.ts +7 -0
- package/dist/Model/Repository.d.ts.map +1 -0
- package/dist/Model/Repository.js +7 -0
- package/dist/Model/dsl.d.ts +33 -0
- package/dist/Model/dsl.d.ts.map +1 -0
- package/dist/Model/dsl.js +43 -0
- package/dist/Model/filter/filterApi.d.ts +30 -0
- package/dist/Model/filter/filterApi.d.ts.map +1 -0
- package/dist/Model/filter/filterApi.js +2 -0
- package/dist/Model/filter/types/errors.d.ts +29 -0
- package/dist/Model/filter/types/errors.d.ts.map +1 -0
- package/dist/Model/filter/types/errors.js +2 -0
- package/dist/Model/filter/types/fields.d.ts +15 -0
- package/dist/Model/filter/types/fields.d.ts.map +1 -0
- package/dist/Model/filter/types/fields.js +2 -0
- package/dist/Model/filter/types/path/common.d.ts +316 -0
- package/dist/Model/filter/types/path/common.d.ts.map +1 -0
- package/dist/Model/filter/types/path/common.js +2 -0
- package/dist/Model/filter/types/path/eager.d.ts +95 -0
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
- package/dist/Model/filter/types/path/eager.js +31 -0
- package/dist/Model/filter/types/path/index.d.ts +4 -0
- package/dist/Model/filter/types/path/index.d.ts.map +1 -0
- package/dist/Model/filter/types/path/index.js +3 -0
- package/dist/Model/filter/types/utils.d.ts +79 -0
- package/dist/Model/filter/types/utils.d.ts.map +1 -0
- package/dist/Model/filter/types/utils.js +2 -0
- package/dist/Model/filter/types/validator.d.ts +30 -0
- package/dist/Model/filter/types/validator.d.ts.map +1 -0
- package/dist/Model/filter/types/validator.js +2 -0
- package/dist/Model/filter/types.d.ts +5 -0
- package/dist/Model/filter/types.d.ts.map +1 -0
- package/dist/Model/filter/types.js +7 -0
- package/dist/Model/query/dsl.d.ts +493 -0
- package/dist/Model/query/dsl.d.ts.map +1 -0
- package/dist/Model/query/dsl.js +376 -0
- package/dist/Model/query/new-kid-interpreter.d.ts +136 -0
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
- package/dist/Model/query/new-kid-interpreter.js +336 -0
- package/dist/Model/query.d.ts +15 -0
- package/dist/Model/query.d.ts.map +1 -0
- package/dist/Model/query.js +3 -0
- package/dist/Model.d.ts +5 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +5 -0
- package/dist/NonEmptySet.d.ts +4 -2
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/NonEmptySet.js +2 -2
- package/dist/Option.d.ts +2 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -1
- package/dist/Pure.d.ts +8 -6
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +17 -14
- package/dist/QueueMaker.d.ts +13 -0
- package/dist/QueueMaker.d.ts.map +1 -0
- package/dist/QueueMaker.js +4 -0
- package/dist/RequestContext.d.ts +91 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +49 -0
- package/dist/Schema/Class.d.ts +66 -20
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +192 -27
- package/dist/Schema/FastCheck.d.ts +1 -1
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/Methods.d.ts +1 -1
- package/dist/Schema/SchemaParser.d.ts +5 -0
- package/dist/Schema/SchemaParser.d.ts.map +1 -0
- package/dist/Schema/SchemaParser.js +6 -0
- package/dist/Schema/SpecialJsonSchema.d.ts +34 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +118 -0
- package/dist/Schema/SpecialOpenApi.d.ts +32 -0
- package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
- package/dist/Schema/SpecialOpenApi.js +123 -0
- package/dist/Schema/brand.d.ts +5 -3
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +3 -1
- package/dist/Schema/email.d.ts +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +7 -4
- package/dist/Schema/ext.d.ts +339 -56
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +358 -53
- package/dist/Schema/moreStrings.d.ts +83 -37
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +49 -42
- package/dist/Schema/numbers.d.ts +35 -22
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +55 -12
- package/dist/Schema/phoneNumber.d.ts +1 -1
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -3
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/strings.d.ts +19 -5
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +214 -8
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +190 -11
- package/dist/Set.d.ts +5 -2
- package/dist/Set.d.ts.map +1 -1
- package/dist/Set.js +3 -2
- package/dist/Store.d.ts +170 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +121 -0
- package/dist/TypeTest.d.ts +1 -1
- package/dist/Types.d.ts +1 -1
- package/dist/Widen.type.d.ts +1 -1
- package/dist/_ext/Array.d.ts +2 -2
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/Array.js +4 -2
- package/dist/_ext/date.d.ts +1 -1
- package/dist/_ext/misc.d.ts +5 -2
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +4 -2
- package/dist/_ext/ord.ext.d.ts +3 -2
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/_ext/ord.ext.js +2 -2
- package/dist/builtin.d.ts +1 -1
- package/dist/builtin.d.ts.map +1 -1
- package/dist/client/InvalidationKeys.d.ts +29 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +33 -0
- package/dist/client/apiClientFactory.d.ts +20 -32
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +104 -34
- package/dist/client/clientFor.d.ts +53 -19
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +49 -25
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +43 -17
- package/dist/client/makeClient.d.ts +495 -33
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +66 -24
- package/dist/client.d.ts +6 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/faker.d.ts +1 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +2 -2
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +2 -2
- package/dist/http/internal/lib.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/ids.d.ts +43 -15
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +30 -5
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/logger.d.ts +1 -1
- package/dist/middleware.d.ts +14 -8
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +14 -8
- package/dist/rpc/Invalidation.d.ts +420 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +168 -0
- package/dist/rpc/MiddlewareMaker.d.ts +12 -8
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +59 -38
- package/dist/rpc/RpcContextMap.d.ts +4 -4
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +15 -11
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +40 -0
- package/dist/setupRequest.d.ts +19 -0
- package/dist/setupRequest.d.ts.map +1 -0
- package/dist/setupRequest.js +69 -0
- package/dist/toast.d.ts +51 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +34 -0
- package/dist/transform.d.ts +2 -2
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +4 -5
- package/dist/utils/effectify.d.ts +2 -2
- package/dist/utils/effectify.d.ts.map +1 -1
- package/dist/utils/effectify.js +2 -2
- package/dist/utils/extend.d.ts +1 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +5 -5
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +3 -3
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +5 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +4 -4
- package/dist/utils.d.ts +40 -45
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -27
- package/dist/validation/validators.d.ts +1 -1
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/withToast.d.ts +30 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +64 -0
- package/package.json +20 -245
- package/src/Array.ts +3 -3
- package/src/Config/SecretURL.ts +5 -2
- package/src/Config/internal/configSecretURL.ts +1 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +56 -63
- package/src/Effect.ts +12 -14
- package/src/Emailer.ts +51 -0
- package/src/Layer.ts +10 -6
- package/src/Model/Repository/Registry.ts +34 -0
- package/src/Model/Repository/ext.ts +375 -0
- package/src/Model/Repository/internal/internal.ts +741 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +145 -0
- package/src/Model/Repository/service.ts +666 -0
- package/src/Model/Repository/validation.ts +31 -0
- package/src/Model/Repository.ts +6 -0
- package/src/Model/dsl.ts +129 -0
- package/src/Model/filter/filterApi.ts +60 -0
- package/src/Model/filter/types/errors.ts +47 -0
- package/src/Model/filter/types/fields.ts +50 -0
- package/src/Model/filter/types/path/common.ts +404 -0
- package/src/Model/filter/types/path/eager.ts +297 -0
- package/src/Model/filter/types/path/index.ts +4 -0
- package/src/Model/filter/types/utils.ts +128 -0
- package/src/Model/filter/types/validator.ts +46 -0
- package/src/Model/filter/types.ts +6 -0
- package/src/Model/query/dsl.ts +2694 -0
- package/src/Model/query/new-kid-interpreter.ts +484 -0
- package/src/Model/query.ts +13 -0
- package/src/Model.ts +4 -0
- package/src/NonEmptySet.ts +3 -1
- package/src/Option.ts +2 -0
- package/src/Pure.ts +21 -19
- package/src/QueueMaker.ts +19 -0
- package/src/RequestContext.ts +62 -0
- package/src/Schema/Class.ts +274 -68
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +139 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +22 -2
- package/src/Schema/email.ts +7 -2
- package/src/Schema/ext.ts +443 -88
- package/src/Schema/moreStrings.ts +146 -67
- package/src/Schema/numbers.ts +96 -27
- package/src/Schema/phoneNumber.ts +5 -1
- package/src/Schema/strings.ts +22 -13
- package/src/Schema.ts +374 -10
- package/src/Set.ts +5 -1
- package/src/Store.ts +277 -0
- package/src/_ext/Array.ts +3 -1
- package/src/_ext/misc.ts +4 -1
- package/src/_ext/ord.ext.ts +2 -1
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +230 -131
- package/src/client/clientFor.ts +102 -31
- package/src/client/errors.ts +52 -26
- package/src/client/makeClient.ts +592 -71
- package/src/client.ts +5 -4
- package/src/http/Request.ts +1 -1
- package/src/ids.ts +32 -5
- package/src/index.ts +7 -10
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +261 -0
- package/src/rpc/MiddlewareMaker.ts +83 -75
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +18 -12
- package/src/rpc.ts +1 -1
- package/src/runtime.ts +56 -0
- package/src/setupRequest.ts +134 -0
- package/src/toast.ts +54 -0
- package/src/transform.ts +3 -3
- package/src/utils/effectify.ts +1 -1
- package/src/utils/gen.ts +8 -8
- package/src/utils/logLevel.ts +1 -1
- package/src/utils/logger.ts +4 -3
- package/src/utils.ts +62 -139
- package/src/withToast.ts +133 -0
- package/test/dist/rpc-dynamic-middleware.test.d.ts.map +1 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/dist/stream-error.types.d.ts +2 -0
- package/test/dist/stream-error.types.d.ts.map +1 -0
- package/test/dist/stream-error.types.js +27 -0
- package/test/moreStrings.test.ts +1 -1
- package/test/rpc.test.ts +46 -6
- package/test/schema.test.ts +459 -30
- package/test/secretURL.test.ts +160 -0
- package/test/special.test.ts +1026 -0
- package/test/utils.test.ts +7 -7
- package/tsconfig.base.json +6 -5
- package/tsconfig.json +2 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -123
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/ServiceMap.d.ts +0 -44
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js +0 -91
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
package/src/client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// codegen:start {preset: barrel, include: ./client/*.ts}
|
|
2
|
-
export * from "./client/apiClientFactory.
|
|
3
|
-
export * from "./client/clientFor.
|
|
4
|
-
export * from "./client/errors.
|
|
5
|
-
export * from "./client/
|
|
2
|
+
export * from "./client/apiClientFactory.ts"
|
|
3
|
+
export * from "./client/clientFor.ts"
|
|
4
|
+
export * from "./client/errors.ts"
|
|
5
|
+
export * from "./client/InvalidationKeys.ts"
|
|
6
|
+
export * from "./client/makeClient.ts"
|
|
6
7
|
// codegen:end
|
package/src/http/Request.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Option from "effect/Option"
|
|
2
2
|
import type { HttpClientResponse } from "effect/unstable/http/HttpClientResponse"
|
|
3
3
|
import * as Effect from "../Effect.js"
|
|
4
4
|
import { HttpClient, HttpClientError, HttpClientRequest, HttpHeaders } from "./internal/lib.js"
|
package/src/ids.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { brandedStringId, type Codec, NonEmptyString255, StringId, type StringIdBrand, withDefaultMake } from "effect-app/Schema"
|
|
2
2
|
import type { B } from "effect-app/Schema/schema"
|
|
3
|
+
import * as Effect from "effect/Effect"
|
|
3
4
|
import type { Simplify } from "effect/Types"
|
|
4
|
-
import
|
|
5
|
+
import * as S from "./Schema.js"
|
|
5
6
|
import { extendM } from "./utils.js"
|
|
6
7
|
|
|
7
8
|
export interface RequestIdBrand extends StringIdBrand {
|
|
@@ -9,20 +10,46 @@ export interface RequestIdBrand extends StringIdBrand {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export type RequestId = NonEmptyString255
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Schema for a request id.
|
|
15
|
+
*
|
|
16
|
+
* A request id may be made from a span id, which does not comply with the
|
|
17
|
+
* `StringId` schema (hence the looser `NonEmptyString255` base).
|
|
18
|
+
*
|
|
19
|
+
* `.withConstructorDefault` => fresh `StringId` (construction-only; not
|
|
20
|
+
* applied during decode — cannot be used to JIT-migrate database fields).
|
|
21
|
+
* See `./Schema/ext.ts` for the full policy note.
|
|
22
|
+
*/
|
|
13
23
|
export const RequestId = extendM(
|
|
14
24
|
Object
|
|
15
25
|
.assign(Object.create(NonEmptyString255) as {}, NonEmptyString255 as unknown as Codec<NonEmptyString255, string>),
|
|
16
26
|
(s) => {
|
|
17
|
-
|
|
27
|
+
function make(): NonEmptyString255
|
|
28
|
+
function make(input: string, options?: S.MakeOptions): NonEmptyString255
|
|
29
|
+
function make(input?: string, options?: S.MakeOptions): NonEmptyString255 {
|
|
30
|
+
const id = input === undefined ? StringId.make() : StringId.make(input, options)
|
|
31
|
+
return id as NonEmptyString255
|
|
32
|
+
}
|
|
18
33
|
return ({
|
|
19
34
|
make,
|
|
20
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Construction-only default: fresh `StringId`. Applied only when the
|
|
37
|
+
* field is omitted from `.make(...)` input. NOT applied during decode —
|
|
38
|
+
* cannot be used to JIT-migrate database fields. See `./Schema/ext.ts`
|
|
39
|
+
* file-level note.
|
|
40
|
+
*/
|
|
41
|
+
withConstructorDefault: S.withConstructorDefault(Effect.sync(make))(s as typeof s & S.WithoutConstructorDefault)
|
|
21
42
|
})
|
|
22
43
|
}
|
|
23
44
|
)
|
|
24
45
|
.pipe(withDefaultMake)
|
|
25
46
|
|
|
26
47
|
export interface UserProfileIdBrand extends Simplify<B.Brand<"UserProfileId"> & StringIdBrand> {}
|
|
27
|
-
export type UserProfileId =
|
|
48
|
+
export type UserProfileId = string & UserProfileIdBrand
|
|
49
|
+
/**
|
|
50
|
+
* Branded `StringId` for user profiles.
|
|
51
|
+
*
|
|
52
|
+
* Exposes `.withConstructorDefault` (fresh id) — construction-only; not
|
|
53
|
+
* applied during decode. See `./Schema/ext.ts` for the full policy note.
|
|
54
|
+
*/
|
|
28
55
|
export const UserProfileId = brandedStringId<UserProfileId>()
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
1
2
|
import "./builtin.js"
|
|
2
3
|
|
|
3
|
-
import * as ServiceMap from "./ServiceMap.js"
|
|
4
|
-
|
|
5
4
|
export * as Fnc from "./Function.js"
|
|
6
5
|
export * as Utils from "./utils.js"
|
|
7
6
|
|
|
8
7
|
export * as Array from "./Array.js"
|
|
8
|
+
export * as Config from "./Config.js"
|
|
9
|
+
export * as ConfigProvider from "./ConfigProvider.js"
|
|
10
|
+
export * as Context from "./Context.js"
|
|
9
11
|
export * as Effect from "./Effect.js"
|
|
10
12
|
export * as Layer from "./Layer.js"
|
|
13
|
+
export * as Model from "./Model.js"
|
|
11
14
|
export * as NonEmptySet from "./NonEmptySet.js"
|
|
12
|
-
export * as ServiceMap from "./ServiceMap.js"
|
|
13
15
|
export * as Set from "./Set.js"
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated use ServiceMap directly instead
|
|
18
|
-
*/
|
|
19
|
-
ServiceMap as Context
|
|
20
|
-
}
|
|
16
|
+
export * as Store from "./Store.js"
|
|
21
17
|
|
|
22
18
|
export { type NonEmptyArray, type NonEmptyReadonlyArray } from "./Array.js"
|
|
23
19
|
|
|
@@ -26,5 +22,6 @@ export * from "effect"
|
|
|
26
22
|
export type * as Types from "./Types.js"
|
|
27
23
|
|
|
28
24
|
export * as SecretURL from "./Config/SecretURL.js"
|
|
25
|
+
export * as RpcX from "./rpc.js"
|
|
29
26
|
export * as S from "./Schema.js"
|
|
30
27
|
export { copy } from "./utils.js"
|
package/src/middleware.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import * as Context from "effect-app/Context"
|
|
3
|
+
import { RpcMiddleware } from "./rpc.js"
|
|
4
4
|
|
|
5
|
-
export class DevMode extends
|
|
5
|
+
export class DevMode extends Context.Reference("DevMode", { defaultValue: () => false }) {}
|
|
6
6
|
|
|
7
|
-
export class RequestCacheMiddleware
|
|
8
|
-
extends RpcX.RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware")
|
|
9
|
-
{}
|
|
7
|
+
export class RequestCacheMiddleware extends RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware") {}
|
|
10
8
|
|
|
11
9
|
export class ConfigureInterruptibilityMiddleware
|
|
12
|
-
extends
|
|
10
|
+
extends RpcMiddleware.Tag<ConfigureInterruptibilityMiddleware>()("ConfigureInterruptibilityMiddleware")
|
|
13
11
|
{}
|
|
14
12
|
|
|
15
|
-
export class LoggerMiddleware extends
|
|
13
|
+
export class LoggerMiddleware extends RpcMiddleware.Tag<LoggerMiddleware>()("LoggerMiddleware") {}
|
|
16
14
|
|
|
17
|
-
export class DevModeMiddleware extends
|
|
15
|
+
export class DevModeMiddleware extends RpcMiddleware.Tag<DevModeMiddleware>()("DevModeMiddleware") {}
|
|
18
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Generic middlewares attached by `makeRouter` to every request.
|
|
19
|
+
*
|
|
20
|
+
* Invalidation key wrap/unwrap is handled by the routing layer (server) and the
|
|
21
|
+
* api client factory (client) directly — there is no middleware tag for it.
|
|
22
|
+
*/
|
|
19
23
|
export const DefaultGenericMiddlewares = [
|
|
20
24
|
RequestCacheMiddleware,
|
|
21
25
|
ConfigureInterruptibilityMiddleware,
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import * as Ref from "effect/Ref"
|
|
2
|
+
import { Rpc } from "effect/unstable/rpc"
|
|
3
|
+
import { type ClientForOptions, makeQueryKey } from "../client/clientFor.js"
|
|
4
|
+
import * as Context from "../Context.js"
|
|
5
|
+
import * as Effect from "../Effect.js"
|
|
6
|
+
import * as S from "../Schema.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shorthand for a handler-derived invalidation key.
|
|
10
|
+
* Accepts an RPC handler object so `add(GetMe)` is equivalent to
|
|
11
|
+
* `add(makeQueryKey(GetMe))`.
|
|
12
|
+
*/
|
|
13
|
+
export type InvalidationKeyInput = InvalidationKey | { readonly id: string; readonly options?: ClientForOptions }
|
|
14
|
+
|
|
15
|
+
const normalizeKey = (input: InvalidationKeyInput): InvalidationKey => {
|
|
16
|
+
if (Array.isArray(input)) return input
|
|
17
|
+
const handler = input as { id: string; options?: ClientForOptions }
|
|
18
|
+
return makeQueryKey(handler.options ? { id: handler.id, options: handler.options } : { id: handler.id })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Disambiguates `add` overloads: a `string[]` means a single key; an array
|
|
22
|
+
// containing arrays-or-objects means a batch of inputs.
|
|
23
|
+
const isBatch = (
|
|
24
|
+
input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
|
|
25
|
+
): input is ReadonlyArray<InvalidationKeyInput> =>
|
|
26
|
+
Array.isArray(input) && input.length > 0 && typeof input[0] !== "string"
|
|
27
|
+
|
|
28
|
+
const normalizeInputs = (
|
|
29
|
+
input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
|
|
30
|
+
): ReadonlyArray<InvalidationKey> => isBatch(input) ? input.map(normalizeKey) : [normalizeKey(input)]
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A single segment within an `InvalidationKey` array.
|
|
34
|
+
* Accepts any JSON-compatible value: string, number, boolean, null,
|
|
35
|
+
* arrays and objects recursively — matching TanStack Query's `queryKey` element type.
|
|
36
|
+
*/
|
|
37
|
+
export const InvalidationKeySegment = S.Json
|
|
38
|
+
export type InvalidationKeySegment = S.Schema.Type<typeof InvalidationKeySegment>
|
|
39
|
+
|
|
40
|
+
/** Schema for a single invalidation key – an array of segments compatible with TanStack Query `queryKey`. */
|
|
41
|
+
export const InvalidationKey = S.Array(InvalidationKeySegment)
|
|
42
|
+
export type InvalidationKey = S.Schema.Type<typeof InvalidationKey>
|
|
43
|
+
|
|
44
|
+
/** Schema for the full set of invalidation keys – an array of `InvalidationKey`. */
|
|
45
|
+
export const InvalidationKeys = S.Array(InvalidationKey)
|
|
46
|
+
export type InvalidationKeys = S.Schema.Type<typeof InvalidationKeys>
|
|
47
|
+
|
|
48
|
+
/** Metadata included in every command response for server-driven cache invalidation. */
|
|
49
|
+
export const CommandMetaData = S.Struct({ invalidateQueries: InvalidationKeys })
|
|
50
|
+
export type CommandMetaData = S.Schema.Type<typeof CommandMetaData>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Wraps a command's success schema so that the wire format carries both the `payload`
|
|
54
|
+
* (the handler's actual return value) and `metadata` (server-driven cache invalidation keys).
|
|
55
|
+
* Transparent to users: the server handler returns the plain payload and the client receives
|
|
56
|
+
* the plain payload — wrapping/unwrapping is handled internally by the routing layer.
|
|
57
|
+
*/
|
|
58
|
+
export const CommandResponseWithMetaData = <S extends S.Top>(success: S) =>
|
|
59
|
+
S.Struct({ payload: success, metadata: CommandMetaData })
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Wraps a command's failure schema so that the wire format carries both the `error`
|
|
63
|
+
* (the handler's actual failure value) and `metadata` (server-driven cache invalidation keys
|
|
64
|
+
* accumulated thus far before the failure occurred).
|
|
65
|
+
* Transparent to users: the server handler fails with the plain error and the client receives
|
|
66
|
+
* the plain error — wrapping/unwrapping is handled internally by the routing layer.
|
|
67
|
+
*/
|
|
68
|
+
export const CommandFailureWithMetaData = <E extends S.Top>(error: E) =>
|
|
69
|
+
S.Struct({ _tag: S.Literal("CommandFailureWithMetaData"), error, metadata: CommandMetaData })
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Stream chunk schema for stream responses with metadata.
|
|
73
|
+
* Each item is either a data value, an intermediate "metadata" signal carrying cache
|
|
74
|
+
* invalidation keys accumulated since the previous drain, or a final "done" signal.
|
|
75
|
+
* Transparent to users: stream handlers return plain values and clients receive plain values —
|
|
76
|
+
* wrapping/unwrapping is handled internally by the routing layer.
|
|
77
|
+
*
|
|
78
|
+
* The "done" chunk is always the last item in the stream and carries any remaining invalidation
|
|
79
|
+
* keys. An optional "metadata" chunk may appear after any "value" chunk and carries keys
|
|
80
|
+
* accumulated since the last drain (V3: mid-stream invalidation).
|
|
81
|
+
*/
|
|
82
|
+
export const StreamResponseChunk = <S extends S.Top>(success: S) =>
|
|
83
|
+
S.Union([
|
|
84
|
+
S.Struct({ _tag: S.Literal("value"), value: success }),
|
|
85
|
+
S.Struct({ _tag: S.Literal("metadata"), metadata: CommandMetaData }),
|
|
86
|
+
S.Struct({ _tag: S.Literal("done"), metadata: CommandMetaData })
|
|
87
|
+
])
|
|
88
|
+
|
|
89
|
+
export type StreamResponseChunk<A> =
|
|
90
|
+
| { readonly _tag: "value"; readonly value: A }
|
|
91
|
+
| { readonly _tag: "metadata"; readonly metadata: CommandMetaData }
|
|
92
|
+
| { readonly _tag: "done"; readonly metadata: CommandMetaData }
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Stream chunk schema for stream failures with metadata.
|
|
96
|
+
* Used to signal a stream failure while still carrying cache invalidation keys
|
|
97
|
+
* accumulated thus far.
|
|
98
|
+
*/
|
|
99
|
+
export const StreamFailureChunk = <E extends S.Top>(error: E) =>
|
|
100
|
+
S.Struct({ _tag: S.Literal("error"), error, metadata: CommandMetaData })
|
|
101
|
+
|
|
102
|
+
export type StreamFailureChunk<E> = { readonly _tag: "error"; readonly error: E; readonly metadata: CommandMetaData }
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Context annotation for declaring static cache invalidation keys on a low-level `Rpc` definition.
|
|
106
|
+
* These keys are always included in the command response metadata, regardless of the handler logic.
|
|
107
|
+
*
|
|
108
|
+
* Prefer using `makeQueryKey` over raw string arrays to stay in sync with the actual query
|
|
109
|
+
* definitions without manual string maintenance:
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { makeQueryKey } from "effect-app/client"
|
|
113
|
+
* import { Invalidation } from "effect-app/rpc"
|
|
114
|
+
* import * as UserRsc from "../User/index.js" // separate module to avoid circular deps
|
|
115
|
+
*
|
|
116
|
+
* class UpdateProfile extends Rpc.make("UpdateProfile", { ... })
|
|
117
|
+
* .annotate(Invalidation.Invalidates, [makeQueryKey(UserRsc.GetMe), makeQueryKey(UserRsc.GetProfile)]) {}
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* **Circular dependency note:** if mutations and queries live in the same file you may hit a
|
|
121
|
+
* circular reference at evaluation time. The idiomatic fix is to move mutations into their own
|
|
122
|
+
* module (e.g. `User/mutations.ts`) that directly imports the relevant query classes rather than
|
|
123
|
+
* re-exporting them through a barrel.
|
|
124
|
+
*
|
|
125
|
+
* For the higher-level `Command`/`Query` builders from `makeRpcClient`, use the
|
|
126
|
+
* `invalidatesQueries` callback argument instead (it receives the same query keys at runtime).
|
|
127
|
+
*/
|
|
128
|
+
export const Invalidates = Context.Reference<ReadonlyArray<InvalidationKey>>(
|
|
129
|
+
"effect-app/rpc/Invalidates",
|
|
130
|
+
{ defaultValue: () => [] }
|
|
131
|
+
)
|
|
132
|
+
export type Invalidates = typeof Invalidates
|
|
133
|
+
|
|
134
|
+
/** The shape of the per-request service that accumulates invalidation keys. */
|
|
135
|
+
export interface InvalidationSetService {
|
|
136
|
+
readonly add: (
|
|
137
|
+
input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
|
|
138
|
+
) => Effect.Effect<void>
|
|
139
|
+
readonly get: Effect.Effect<ReadonlyArray<InvalidationKey>>
|
|
140
|
+
/**
|
|
141
|
+
* V3: Reads all currently accumulated keys and resets the bucket to empty.
|
|
142
|
+
* Used by the stream routing layer to emit intermediate "metadata" chunks
|
|
143
|
+
* without re-sending keys that have already been forwarded to the client.
|
|
144
|
+
*/
|
|
145
|
+
readonly drain: Effect.Effect<ReadonlyArray<InvalidationKey>>
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Request-scoped service for accumulating invalidation keys dynamically inside a handler.
|
|
150
|
+
* Provided by `InvalidationMiddlewareLive` for every RPC call; has a no-op default so it is
|
|
151
|
+
* safe to use even when the HTTP middleware is absent (tests, workers, etc.).
|
|
152
|
+
*
|
|
153
|
+
* Use `InvalidationSet.add(key)` as a shorthand to skip `.use(_ => _.add(key))`. The
|
|
154
|
+
* underlying service is still available via `.use` / `.useSync` for advanced cases.
|
|
155
|
+
*
|
|
156
|
+
* `add` accepts an RPC handler directly (e.g. `UserRsc.GetMe`) — its query key is derived via
|
|
157
|
+
* `makeQueryKey` so keys stay in sync with the actual query definitions. Raw `InvalidationKey`
|
|
158
|
+
* arrays and arrays of either form are also accepted.
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* import * as Effect from "effect/Effect"
|
|
162
|
+
* import { Invalidation } from "effect-app/rpc"
|
|
163
|
+
* import * as CartRsc from "../Cart/queries.js"
|
|
164
|
+
* import * as UserRsc from "../User/queries.js"
|
|
165
|
+
*
|
|
166
|
+
* const handler = Effect.fnUntraced(function*(req: UpdateCartRequest) {
|
|
167
|
+
* const cart = yield* CartRepo.save(req.cart)
|
|
168
|
+
*
|
|
169
|
+
* // single handler
|
|
170
|
+
* yield* Invalidation.InvalidationSet.add(UserRsc.GetMe)
|
|
171
|
+
*
|
|
172
|
+
* // batch
|
|
173
|
+
* if (cart.isCheckedOut) {
|
|
174
|
+
* yield* Invalidation.InvalidationSet.add([CartRsc.GetCartStats, UserRsc.GetMe])
|
|
175
|
+
* }
|
|
176
|
+
*
|
|
177
|
+
* return cart
|
|
178
|
+
* })
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* You can combine static (`Invalidates` annotation) and dynamic (`InvalidationSet.use`) keys:
|
|
182
|
+
* the annotation pre-populates the set before the handler runs; dynamic additions accumulate
|
|
183
|
+
* throughout the handler. All keys are included in the command response metadata.
|
|
184
|
+
*/
|
|
185
|
+
const InvalidationSetRef = Context.Reference<InvalidationSetService>(
|
|
186
|
+
"effect-app/rpc/InvalidationSet",
|
|
187
|
+
{
|
|
188
|
+
defaultValue: () => ({
|
|
189
|
+
add: (_input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>) => Effect.void,
|
|
190
|
+
get: Effect.succeed([] as ReadonlyArray<InvalidationKey>),
|
|
191
|
+
drain: Effect.succeed([] as ReadonlyArray<InvalidationKey>)
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
)
|
|
195
|
+
export const InvalidationSet = Object.assign(InvalidationSetRef, {
|
|
196
|
+
/**
|
|
197
|
+
* Shortcut for `InvalidationSet.use(_ => _.add(input))`. Accepts a single
|
|
198
|
+
* `InvalidationKeyInput` or an array of them.
|
|
199
|
+
*/
|
|
200
|
+
add: (input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>) =>
|
|
201
|
+
InvalidationSetRef.use((_) => _.add(input))
|
|
202
|
+
})
|
|
203
|
+
export type InvalidationSet = typeof InvalidationSetRef
|
|
204
|
+
|
|
205
|
+
/** Creates a fresh `InvalidationSet` implementation backed by a `Ref`. */
|
|
206
|
+
export const makeInvalidationSet = (ref: Ref.Ref<ReadonlyArray<InvalidationKey>>): InvalidationSetService => ({
|
|
207
|
+
add: (input) => Ref.update(ref, (keys) => [...keys, ...normalizeInputs(input)]),
|
|
208
|
+
get: Ref.get(ref),
|
|
209
|
+
drain: Ref.getAndSet(ref, [])
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* `Rpc.Custom` definition for command RPCs that wrap the success/error schemas
|
|
214
|
+
* with `CommandResponseWithMetaData` / `CommandFailureWithMetaData`. The wrap
|
|
215
|
+
* lets server forward accumulated invalidation keys on both success and
|
|
216
|
+
* handler-thrown failure paths. Middleware-thrown errors bypass the wrap
|
|
217
|
+
* (the handler never ran, so no metadata) and flow raw at the Cause level —
|
|
218
|
+
* the client decodes them via the `rpc.middlewares[*].error` failure-union
|
|
219
|
+
* channel of `Rpc.exitSchema`.
|
|
220
|
+
*/
|
|
221
|
+
// eslint-disable-next-line import/namespace
|
|
222
|
+
export interface CommandRpc extends Rpc.Custom {
|
|
223
|
+
readonly out: Rpc.Custom.Out<
|
|
224
|
+
ReturnType<typeof CommandResponseWithMetaData<this["success"] & S.Top>>,
|
|
225
|
+
ReturnType<typeof CommandFailureWithMetaData<this["error"] & S.Top>>
|
|
226
|
+
>
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Custom Rpc constructor for command RPCs.
|
|
231
|
+
* Wraps the success schema with `CommandResponseWithMetaData` and the error
|
|
232
|
+
* schema with `CommandFailureWithMetaData`.
|
|
233
|
+
*/
|
|
234
|
+
export const makeCommandRpc = Rpc.custom<CommandRpc>(({ defect, error, success }) => ({
|
|
235
|
+
success: CommandResponseWithMetaData(success),
|
|
236
|
+
error: CommandFailureWithMetaData(error),
|
|
237
|
+
defect
|
|
238
|
+
}))
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* `Rpc.Custom` definition for stream RPCs that wrap the success/error schemas
|
|
242
|
+
* with `StreamResponseChunk` / `StreamFailureChunk`.
|
|
243
|
+
*/
|
|
244
|
+
// eslint-disable-next-line import/namespace
|
|
245
|
+
export interface StreamRpc extends Rpc.Custom {
|
|
246
|
+
readonly out: Rpc.Custom.Out<
|
|
247
|
+
ReturnType<typeof StreamResponseChunk<this["success"] & S.Top>>,
|
|
248
|
+
ReturnType<typeof StreamFailureChunk<this["error"] & S.Top>>
|
|
249
|
+
>
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Custom Rpc constructor for stream RPCs.
|
|
254
|
+
* Wraps the success schema with `StreamResponseChunk` and
|
|
255
|
+
* the error schema with `StreamFailureChunk`.
|
|
256
|
+
*/
|
|
257
|
+
export const makeStreamRpc = Rpc.custom<StreamRpc>(({ defect, error, success }) => ({
|
|
258
|
+
success: StreamResponseChunk(success),
|
|
259
|
+
error: StreamFailureChunk(error),
|
|
260
|
+
defect
|
|
261
|
+
}))
|