effect-app 4.0.0-beta.20 → 4.0.0-beta.201
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 +888 -0
- package/dist/Array.d.ts +1 -1
- package/dist/Chunk.d.ts +1 -1
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +1 -1
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +2 -2
- package/dist/Config/internal/configSecretURL.d.ts +1 -1
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- 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 +40 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/Effect.d.ts +9 -10
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +3 -6
- 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 +7 -6
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +1 -1
- package/dist/NonEmptySet.d.ts +1 -1
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/Option.d.ts +1 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Pure.d.ts +5 -5
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +13 -13
- package/dist/Schema/Class.d.ts +66 -20
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +189 -22
- 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 +33 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +122 -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 +7 -2
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +1 -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 +117 -45
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +131 -42
- package/dist/Schema/moreStrings.d.ts +111 -11
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +14 -15
- package/dist/Schema/numbers.d.ts +127 -15
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +10 -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 +37 -5
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +154 -56
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +131 -64
- package/dist/Set.d.ts +1 -1
- package/dist/Set.d.ts.map +1 -1
- 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 +1 -1
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/date.d.ts +1 -1
- package/dist/_ext/misc.d.ts +1 -1
- package/dist/_ext/ord.ext.d.ts +1 -1
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- 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 +18 -32
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +95 -32
- package/dist/client/clientFor.d.ts +61 -17
- 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 +468 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +62 -23
- package/dist/client.d.ts +2 -1
- 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 +5 -5
- package/dist/http/internal/lib.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/ids.d.ts +3 -3
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +3 -2
- package/dist/index.d.ts +5 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -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 +402 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +150 -0
- package/dist/rpc/MiddlewareMaker.d.ts +5 -4
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +57 -37
- 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 +5 -4
- 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/transform.d.ts +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +3 -3
- package/dist/utils/effectify.d.ts +1 -1
- package/dist/utils/extend.d.ts +1 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +2 -2
- 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 +3 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils.d.ts +31 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -7
- 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/package.json +46 -24
- package/src/Config/SecretURL.ts +2 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +52 -59
- package/src/Effect.ts +12 -14
- package/src/Layer.ts +6 -5
- package/src/Pure.ts +17 -18
- package/src/Schema/Class.ts +268 -62
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +137 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +9 -1
- package/src/Schema/email.ts +7 -2
- package/src/Schema/ext.ts +204 -72
- package/src/Schema/moreStrings.ts +22 -20
- package/src/Schema/numbers.ts +14 -16
- package/src/Schema/phoneNumber.ts +5 -1
- package/src/Schema/strings.ts +4 -8
- package/src/Schema.ts +332 -105
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +220 -129
- package/src/client/clientFor.ts +97 -29
- package/src/client/errors.ts +52 -26
- package/src/client/makeClient.ts +538 -68
- package/src/client.ts +1 -0
- package/src/http/Request.ts +7 -4
- package/src/ids.ts +2 -1
- package/src/index.ts +5 -10
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +226 -0
- package/src/rpc/MiddlewareMaker.ts +65 -60
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +5 -4
- package/src/rpc.ts +1 -1
- package/src/transform.ts +2 -2
- package/src/utils/gen.ts +1 -1
- package/src/utils/logger.ts +2 -2
- package/src/utils.ts +51 -15
- 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/rpc.test.ts +41 -6
- package/test/schema.test.ts +591 -17
- package/test/secretURL.test.ts +157 -0
- package/test/special.test.ts +1023 -0
- package/test/utils.test.ts +6 -6
- package/tsconfig.base.json +3 -4
- package/tsconfig.json +0 -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 -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/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
package/src/utils/logger.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
|
|
4
4
|
import { Effect, type LogLevel } from "effect"
|
|
5
|
-
import * as
|
|
5
|
+
import * as Context from "../Context.js"
|
|
6
6
|
|
|
7
7
|
type Levels = "info" | "debug" | "warn" | "error"
|
|
8
8
|
|
|
9
|
-
export class LogLevels extends
|
|
9
|
+
export class LogLevels extends Context.Reference("LogLevels", {
|
|
10
10
|
defaultValue: () => new Map<string, Levels>()
|
|
11
11
|
}) {}
|
|
12
12
|
|
package/src/utils.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
|
4
4
|
import { Cause, Effect, Exit, Fiber, Option, Record } from "effect"
|
|
5
5
|
import { dual } from "effect/Function"
|
|
6
|
-
import { isFunction
|
|
6
|
+
import { isFunction } from "effect/Predicate"
|
|
7
7
|
import * as Result from "effect/Result"
|
|
8
8
|
import type { GetFieldType, NumericDictionary, PropertyPath } from "lodash"
|
|
9
9
|
import { identity, pipe } from "./Function.js"
|
|
@@ -118,7 +118,7 @@ function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPa
|
|
|
118
118
|
defaultValue: TDefault
|
|
119
119
|
): Exclude<GetFieldType<TObject, TPath>, null | undefined> | TDefault
|
|
120
120
|
function get(object: any, path: PropertyPath, defaultValue?: any): any
|
|
121
|
-
function get(obj: any, path: any, defaultValue
|
|
121
|
+
function get(obj: any, path: any, defaultValue?: any) {
|
|
122
122
|
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore?tab=readme-ov-file#_get
|
|
123
123
|
const travel = (regexp: any) =>
|
|
124
124
|
String
|
|
@@ -269,7 +269,7 @@ export type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R
|
|
|
269
269
|
export function intersect<AS extends unknown[] & { 0: unknown }>(
|
|
270
270
|
...as: AS
|
|
271
271
|
): UnionToIntersection<{ [k in keyof AS]: AS[k] }[number]> {
|
|
272
|
-
return as.reduce((a: any, b: any) => (
|
|
272
|
+
return as.reduce((a: any, b: any) => Object.assign(a, b), {}) as any
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
export type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
@@ -280,8 +280,7 @@ export type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
|
280
280
|
export const unifyIndex = Symbol()
|
|
281
281
|
export type unifyIndex = typeof unifyIndex
|
|
282
282
|
|
|
283
|
-
|
|
284
|
-
export interface UnifiableIndexed<X> {}
|
|
283
|
+
export interface UnifiableIndexed<_X> {}
|
|
285
284
|
export type UnifiableIndexedURI = keyof UnifiableIndexed<any>
|
|
286
285
|
|
|
287
286
|
export interface Unifiable<X> {
|
|
@@ -313,9 +312,7 @@ function decorateNew(
|
|
|
313
312
|
if (out.descriptor) {
|
|
314
313
|
out.descriptor = Object.assign({}, out.descriptor)
|
|
315
314
|
}
|
|
316
|
-
const actualDesc: PropertyDescriptor =
|
|
317
|
-
out.descriptor || /* istanbul ignore next */ out
|
|
318
|
-
)
|
|
315
|
+
const actualDesc: PropertyDescriptor = out.descriptor || /* istanbul ignore next */ out
|
|
319
316
|
|
|
320
317
|
const originalMethod = validateAndExtractMethodFromDescriptor(actualDesc)
|
|
321
318
|
const isStatic = inp.placement === "static"
|
|
@@ -684,7 +681,7 @@ export type OptPromise<T extends () => any> = (
|
|
|
684
681
|
) => Promise<ReturnType<T>> | ReturnType<T>
|
|
685
682
|
|
|
686
683
|
export function access<T extends string, T2>(t: Record<T, T2>) {
|
|
687
|
-
return (key: T) => t[key]
|
|
684
|
+
return (key: T) => t[key]
|
|
688
685
|
}
|
|
689
686
|
|
|
690
687
|
export function todayAtUTCNoon() {
|
|
@@ -736,25 +733,64 @@ export const copy = dual<
|
|
|
736
733
|
}
|
|
737
734
|
>(2, <A>(self: A, f: Partial<A> | ((a: A) => Partial<A>)) => clone(self, { ...self, ...(isFunction(f) ? f(self) : f) }))
|
|
738
735
|
|
|
739
|
-
type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
736
|
+
export type CopyOriginU<U, Ctor extends new(...args: any[]) => any> =
|
|
740
737
|
& {
|
|
741
738
|
[K in keyof U & keyof InstanceType<Ctor>]?: U[K]
|
|
742
739
|
}
|
|
743
740
|
& {}
|
|
744
741
|
|
|
745
|
-
type CopyOriginRet<A, U> =
|
|
742
|
+
export type CopyOriginRet<A, U> =
|
|
746
743
|
& {
|
|
747
744
|
[K in keyof A | keyof U]: K extends keyof U ? U[K] : A[K & keyof A]
|
|
748
745
|
}
|
|
749
746
|
& {}
|
|
750
747
|
|
|
751
|
-
type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
748
|
+
export type CopyOriginSelf<A, U> = Equals<{}, U> extends true
|
|
752
749
|
? Equals<keyof {}, keyof U> extends true ? `updates argument is empty or contains only extra properties`
|
|
753
750
|
: A
|
|
754
751
|
: A
|
|
755
752
|
|
|
753
|
+
export interface StructuralCopyOrigin<Self extends object> {
|
|
754
|
+
<A extends Self, U extends Partial<Self>>(
|
|
755
|
+
f: (a: A) =>
|
|
756
|
+
& {
|
|
757
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
758
|
+
}
|
|
759
|
+
& {}
|
|
760
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
761
|
+
<A extends Self, U extends Partial<Self>>(
|
|
762
|
+
updates:
|
|
763
|
+
& {
|
|
764
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
765
|
+
}
|
|
766
|
+
& {}
|
|
767
|
+
): (self: CopyOriginSelf<A, U>) => CopyOriginRet<A, U>
|
|
768
|
+
<A extends Self, U extends Partial<Self>>(
|
|
769
|
+
self: CopyOriginSelf<A, U>,
|
|
770
|
+
f: (a: A) =>
|
|
771
|
+
& {
|
|
772
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
773
|
+
}
|
|
774
|
+
& {}
|
|
775
|
+
): CopyOriginRet<A, U>
|
|
776
|
+
<A extends Self, U extends Partial<Self>>(
|
|
777
|
+
self: CopyOriginSelf<A, U>,
|
|
778
|
+
updates:
|
|
779
|
+
& {
|
|
780
|
+
[K in keyof U & keyof Self]?: U[K]
|
|
781
|
+
}
|
|
782
|
+
& {}
|
|
783
|
+
): CopyOriginRet<A, U>
|
|
784
|
+
}
|
|
785
|
+
|
|
756
786
|
// just one input param: the convention is that the ctor takes an object
|
|
757
|
-
// containing the properties of the
|
|
787
|
+
// containing the properties of the value (I can't put object there as type because of contravariance)
|
|
788
|
+
/**
|
|
789
|
+
* By design this does not return `Self` directly.
|
|
790
|
+
*
|
|
791
|
+
* The return type is computed from `Self` and the update payload so callers can
|
|
792
|
+
* expose an explicit structural return type that remains assignable to `Self`.
|
|
793
|
+
*/
|
|
758
794
|
export const copyOrigin = <Ctor extends new(_: any) => any>(ctor: Ctor) =>
|
|
759
795
|
dual<
|
|
760
796
|
{
|
|
@@ -970,5 +1006,5 @@ const genConstructor = (function*() {}).constructor
|
|
|
970
1006
|
* @category predicates
|
|
971
1007
|
* @since 3.11.0
|
|
972
1008
|
*/
|
|
973
|
-
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any
|
|
974
|
-
|
|
1009
|
+
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any> =>
|
|
1010
|
+
isFunction(u) && u.constructor === genConstructor
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAErF,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,qBAAa,iBAAkB,SAAQ,sBAIrC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKL,qBAAa,KAAM,SAAQ,UAQzB;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secretURL.test.d.ts","sourceRoot":"","sources":["../secretURL.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special.test.d.ts","sourceRoot":"","sources":["../special.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-error.types.d.ts","sourceRoot":"","sources":["../stream-error.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { S } from "effect-app";
|
|
2
|
+
import { makeRpcClient } from "effect-app/client";
|
|
3
|
+
class GeneralError extends S.TaggedError("GeneralError")("GeneralError", {
|
|
4
|
+
message: S.String
|
|
5
|
+
}) {
|
|
6
|
+
}
|
|
7
|
+
class CustomError extends S.TaggedError("CustomError")("CustomError", {
|
|
8
|
+
reason: S.String
|
|
9
|
+
}) {
|
|
10
|
+
}
|
|
11
|
+
const { TaggedRequestFor } = makeRpcClient({ config: {} }, GeneralError);
|
|
12
|
+
const Req = TaggedRequestFor("Test");
|
|
13
|
+
class StreamWithError extends Req.Stream()("StreamWithError", {}, {
|
|
14
|
+
success: S.Number,
|
|
15
|
+
error: CustomError
|
|
16
|
+
}) {
|
|
17
|
+
}
|
|
18
|
+
const _check = true;
|
|
19
|
+
const _check2 = true;
|
|
20
|
+
class StreamNoError extends Req.Stream()("StreamNoError", {}, {
|
|
21
|
+
success: S.Number
|
|
22
|
+
}) {
|
|
23
|
+
}
|
|
24
|
+
const _check3 = true;
|
|
25
|
+
const _check4 = true;
|
|
26
|
+
console.log("ok");
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyZWFtLWVycm9yLnR5cGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3RyZWFtLWVycm9yLnR5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxDQUFDLEVBQUUsTUFBTSxZQUFZLENBQUE7QUFDOUIsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFBO0FBRWpELE1BQU0sWUFBYSxTQUFRLENBQUMsQ0FBQyxXQUFXLENBQWUsY0FBYyxDQUFDLENBQUMsY0FBYyxFQUFFO0lBQ3JGLE9BQU8sRUFBRSxDQUFDLENBQUMsTUFBTTtDQUNsQixDQUFDO0NBQUc7QUFFTCxNQUFNLFdBQVksU0FBUSxDQUFDLENBQUMsV0FBVyxDQUFjLGFBQWEsQ0FBQyxDQUFDLGFBQWEsRUFBRTtJQUNqRixNQUFNLEVBQUUsQ0FBQyxDQUFDLE1BQU07Q0FDakIsQ0FBQztDQUFHO0FBRUwsTUFBTSxFQUFFLGdCQUFnQixFQUFFLEdBQUcsYUFBYSxDQUFDLEVBQUUsTUFBTSxFQUFFLEVBQVMsRUFBRSxFQUFFLFlBQVksQ0FBQyxDQUFBO0FBQy9FLE1BQU0sR0FBRyxHQUFHLGdCQUFnQixDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBRXBDLE1BQU0sZUFBZ0IsU0FBUSxHQUFHLENBQUMsTUFBTSxFQUFtQixDQUFDLGlCQUFpQixFQUFFLEVBQUUsRUFBRTtJQUNqRixPQUFPLEVBQUUsQ0FBQyxDQUFDLE1BQU07SUFDakIsS0FBSyxFQUFFLFdBQVc7Q0FDbkIsQ0FBQztDQUFHO0FBR0wsTUFBTSxNQUFNLEdBQXdELElBQUksQ0FBQTtBQUN4RSxNQUFNLE9BQU8sR0FBd0QsSUFBSSxDQUFBO0FBRXpFLE1BQU0sYUFBYyxTQUFRLEdBQUcsQ0FBQyxNQUFNLEVBQWlCLENBQUMsZUFBZSxFQUFFLEVBQUUsRUFBRTtJQUMzRSxPQUFPLEVBQUUsQ0FBQyxDQUFDLE1BQU07Q0FDbEIsQ0FBQztDQUFHO0FBRUwsTUFBTSxPQUFPLEdBQTJDLElBQUksQ0FBQTtBQUM1RCxNQUFNLE9BQU8sR0FBMkMsSUFBSSxDQUFBO0FBRTVELE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUEifQ==
|
package/test/rpc.test.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { type Effect, type Option } from "effect"
|
|
2
|
+
import { expect, test } from "vitest"
|
|
1
3
|
import { makeRpcClient, NotLoggedInError, UnauthorizedError } from "../src/client.js"
|
|
4
|
+
import { ForceVoid } from "../src/client/makeClient.js"
|
|
2
5
|
import { S } from "../src/index.js"
|
|
3
6
|
import { RpcContextMap } from "../src/rpc.js"
|
|
4
7
|
|
|
@@ -8,16 +11,48 @@ export class RequestContextMap extends RpcContextMap.makeMap({
|
|
|
8
11
|
test: RpcContextMap.make()(S.Never)
|
|
9
12
|
}) {}
|
|
10
13
|
|
|
11
|
-
const {
|
|
14
|
+
const { TaggedRequestFor } = makeRpcClient(RequestContextMap)
|
|
15
|
+
const TaggedRequest = TaggedRequestFor("Test").Query
|
|
12
16
|
|
|
13
17
|
export class Stats extends TaggedRequest<Stats>()("Stats", {}, {
|
|
14
18
|
allowedRoles: ["manager"],
|
|
15
19
|
success: {
|
|
16
|
-
usersActive24Hours: S.
|
|
17
|
-
usersActiveLastWeek: S.
|
|
18
|
-
newUsersLast24Hours: S.
|
|
19
|
-
newUsersLastWeek: S.
|
|
20
|
+
usersActive24Hours: S.Finite,
|
|
21
|
+
usersActiveLastWeek: S.Finite,
|
|
22
|
+
newUsersLast24Hours: S.Finite,
|
|
23
|
+
newUsersLastWeek: S.Finite
|
|
20
24
|
}
|
|
21
25
|
}) {}
|
|
22
26
|
|
|
23
|
-
declare const _stats: typeof Stats.
|
|
27
|
+
declare const _stats: typeof Stats.Type
|
|
28
|
+
declare const _statsSuccess: typeof Stats.success.Type
|
|
29
|
+
declare const _statsError: typeof Stats.error.Type
|
|
30
|
+
declare const _statsRequestType: typeof Stats.type
|
|
31
|
+
|
|
32
|
+
test("ForceVoid decodes and encodes as void", () => {
|
|
33
|
+
const statsFromMake = Stats.make({})
|
|
34
|
+
const statsFromMakeOption = Stats.makeOption({})
|
|
35
|
+
const statsFromMakeEffect = Stats.makeEffect({})
|
|
36
|
+
|
|
37
|
+
expect(S.decodeUnknownSync(ForceVoid)(undefined)).toBe(undefined)
|
|
38
|
+
expect(S.is(ForceVoid)(undefined)).toBe(true)
|
|
39
|
+
expect(S.decodeUnknownSync(ForceVoid)("test")).toBe(undefined)
|
|
40
|
+
expect(S.is(ForceVoid)("test")).toBe(true)
|
|
41
|
+
expect(S.encodeUnknownSync(ForceVoid)("test")).toBe(undefined)
|
|
42
|
+
expect(S.encodeUnknownSync(S.toCodecJson(ForceVoid))("test")).toBe(null)
|
|
43
|
+
expectTypeOf<typeof _stats>().toEqualTypeOf<Stats>()
|
|
44
|
+
expectTypeOf<typeof _statsSuccess>().toEqualTypeOf<{
|
|
45
|
+
readonly usersActive24Hours: number
|
|
46
|
+
readonly usersActiveLastWeek: number
|
|
47
|
+
readonly newUsersLast24Hours: number
|
|
48
|
+
readonly newUsersLastWeek: number
|
|
49
|
+
}>()
|
|
50
|
+
// Resource error carries only `config.error` (and optional `generalErrors`); rcm-derived
|
|
51
|
+
// middleware errors no longer leak into `resource.error` — they reach the wire via the
|
|
52
|
+
// middleware tag attached to the rpc group (`rpc.middlewares[*].error` failure-union).
|
|
53
|
+
expectTypeOf<typeof _statsError>().toEqualTypeOf<never>()
|
|
54
|
+
expectTypeOf<typeof _statsRequestType>().toEqualTypeOf<"query">()
|
|
55
|
+
expectTypeOf(statsFromMake).toEqualTypeOf<Stats>()
|
|
56
|
+
expectTypeOf(statsFromMakeOption).toEqualTypeOf<Option.Option<Stats>>()
|
|
57
|
+
expectTypeOf(statsFromMakeEffect).toEqualTypeOf<Effect.Effect<Stats, S.SchemaError>>()
|
|
58
|
+
})
|