effect-app 4.0.0-beta.1 → 4.0.0-beta.100
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 +444 -0
- package/dist/Config/SecretURL.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 +40 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +66 -0
- package/dist/Effect.d.ts +8 -7
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +3 -2
- package/dist/Layer.d.ts +5 -4
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +1 -1
- package/dist/Operations.d.ts +62 -25
- package/dist/Operations.d.ts.map +1 -1
- package/dist/Pure.d.ts +2 -2
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +13 -13
- package/dist/Schema/Class.d.ts +43 -10
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +89 -16
- package/dist/Schema/SpecialJsonSchema.d.ts +21 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +59 -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 +8 -5
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +9 -4
- package/dist/Schema/ext.d.ts +103 -46
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +110 -51
- package/dist/Schema/moreStrings.d.ts +25 -13
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +14 -9
- package/dist/Schema/numbers.d.ts +11 -11
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +10 -9
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +8 -3
- package/dist/Schema/strings.d.ts +4 -4
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema.d.ts +22 -55
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +43 -64
- package/dist/client/apiClientFactory.d.ts +11 -28
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +21 -23
- package/dist/client/clientFor.d.ts +8 -7
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/errors.d.ts +18 -9
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +35 -10
- package/dist/client/makeClient.d.ts +21 -16
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +32 -34
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +5 -5
- package/dist/ids.d.ts +10 -10
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +3 -2
- package/dist/index.d.ts +3 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -9
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +3 -3
- package/dist/rpc/MiddlewareMaker.d.ts +6 -5
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +7 -6
- package/dist/rpc/RpcContextMap.d.ts +2 -2
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +6 -5
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/utils/gen.d.ts +1 -1
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +2 -2
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +24 -5
- package/package.json +29 -17
- package/src/Config/SecretURL.ts +1 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +57 -64
- package/src/Effect.ts +11 -9
- package/src/Layer.ts +5 -4
- package/src/Pure.ts +17 -18
- package/src/Schema/Class.ts +118 -30
- package/src/Schema/SpecialJsonSchema.ts +69 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +13 -7
- package/src/Schema/email.ts +10 -2
- package/src/Schema/ext.ts +185 -82
- package/src/Schema/moreStrings.ts +27 -18
- package/src/Schema/numbers.ts +9 -8
- package/src/Schema/phoneNumber.ts +8 -1
- package/src/Schema.ts +79 -103
- package/src/client/apiClientFactory.ts +35 -43
- package/src/client/clientFor.ts +8 -3
- package/src/client/errors.ts +46 -12
- package/src/client/makeClient.ts +122 -75
- package/src/http/Request.ts +7 -4
- package/src/ids.ts +4 -3
- package/src/index.ts +3 -11
- package/src/middleware.ts +2 -2
- package/src/rpc/MiddlewareMaker.ts +12 -10
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +7 -6
- package/src/utils/gen.ts +1 -1
- package/src/utils/logger.ts +2 -2
- package/src/utils.ts +26 -4
- package/test/dist/moreStrings.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/moreStrings.test.ts +17 -0
- package/test/rpc.test.ts +28 -6
- package/test/schema.test.ts +397 -4
- package/test/secretURL.test.ts +157 -0
- package/test/special.test.ts +729 -0
- package/test/utils.test.ts +2 -2
- package/tsconfig.base.json +0 -1
- package/tsconfig.json +0 -1
- 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/src/Struct.ts +0 -54
package/src/ids.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { brandedStringId, type Codec, NonEmptyString255, StringId, type StringIdBrand, withDefaultMake } from "effect-app/Schema"
|
|
2
3
|
import type { B } from "effect-app/Schema/schema"
|
|
3
4
|
import type { Simplify } from "effect/Types"
|
|
4
5
|
import { S } from "./index.js"
|
|
@@ -12,12 +13,12 @@ export type RequestId = NonEmptyString255
|
|
|
12
13
|
// a request id may be made from a span id, which does not comply with StringId schema.
|
|
13
14
|
export const RequestId = extendM(
|
|
14
15
|
Object
|
|
15
|
-
.assign(Object.create(NonEmptyString255) as {}, NonEmptyString255 as unknown as
|
|
16
|
+
.assign(Object.create(NonEmptyString255) as {}, NonEmptyString255 as unknown as Codec<NonEmptyString255, string>),
|
|
16
17
|
(s) => {
|
|
17
18
|
const make = StringId.make as () => NonEmptyString255
|
|
18
19
|
return ({
|
|
19
20
|
make,
|
|
20
|
-
withDefault:
|
|
21
|
+
withDefault: S.withConstructorDefault(Effect.sync(make))(s as typeof s & S.WithoutConstructorDefault)
|
|
21
22
|
})
|
|
22
23
|
}
|
|
23
24
|
)
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import "./builtin.js"
|
|
2
2
|
|
|
3
|
-
import * as ServiceMap from "./ServiceMap.js"
|
|
4
|
-
|
|
5
3
|
export * as Fnc from "./Function.js"
|
|
6
4
|
export * as Utils from "./utils.js"
|
|
7
5
|
|
|
8
6
|
export * as Array from "./Array.js"
|
|
7
|
+
export * as Config from "./Config.js"
|
|
8
|
+
export * as ConfigProvider from "./ConfigProvider.js"
|
|
9
|
+
export * as Context from "./Context.js"
|
|
9
10
|
export * as Effect from "./Effect.js"
|
|
10
11
|
export * as Layer from "./Layer.js"
|
|
11
12
|
export * as NonEmptySet from "./NonEmptySet.js"
|
|
12
|
-
export * as ServiceMap from "./ServiceMap.js"
|
|
13
13
|
export * as Set from "./Set.js"
|
|
14
14
|
|
|
15
|
-
export {
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated use ServiceMap directly instead
|
|
18
|
-
*/
|
|
19
|
-
ServiceMap as Context
|
|
20
|
-
}
|
|
21
|
-
|
|
22
15
|
export { type NonEmptyArray, type NonEmptyReadonlyArray } from "./Array.js"
|
|
23
16
|
|
|
24
17
|
export * from "effect"
|
|
25
18
|
|
|
26
|
-
export * as Struct from "./Struct.js"
|
|
27
19
|
export type * as Types from "./Types.js"
|
|
28
20
|
|
|
29
21
|
export * as SecretURL from "./Config/SecretURL.js"
|
package/src/middleware.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
2
|
+
import { Context } from "effect-app"
|
|
3
3
|
import { RpcX } from "./rpc.js"
|
|
4
4
|
|
|
5
|
-
export class DevMode extends
|
|
5
|
+
export class DevMode extends Context.Reference("DevMode", { defaultValue: () => false }) {}
|
|
6
6
|
|
|
7
7
|
export class RequestCacheMiddleware
|
|
8
8
|
extends RpcX.RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware")
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Effect, Layer, type Schema, Schema as S, type Scope
|
|
2
|
+
import { Effect, Layer, type Schema, Schema as S, type Scope } from "effect"
|
|
3
3
|
import { type NonEmptyArray, type NonEmptyReadonlyArray } from "effect/Array"
|
|
4
4
|
import { type Simplify } from "effect/Types"
|
|
5
5
|
import { Rpc, type RpcGroup, type RpcSchema } from "effect/unstable/rpc"
|
|
6
6
|
import { type HandlersFrom } from "effect/unstable/rpc/RpcGroup"
|
|
7
7
|
import { type RequestId } from "effect/unstable/rpc/RpcMessage"
|
|
8
|
+
import * as Context from "../Context.js"
|
|
8
9
|
import { type HttpHeaders } from "../http.js"
|
|
9
10
|
import { PreludeLogger } from "../logger.js"
|
|
10
11
|
import { type TypeTestId } from "../TypeTest.js"
|
|
@@ -14,7 +15,8 @@ import { type AddMiddleware, type AnyDynamic, type RpcDynamic, type RpcMiddlewar
|
|
|
14
15
|
import * as RpcMiddlewareX from "./RpcMiddleware.js"
|
|
15
16
|
|
|
16
17
|
// adapter for effect/rpc v3 middleware provides. (in effect-smol (v4), it's just a Service Identifier, no tags.)
|
|
17
|
-
|
|
18
|
+
// hm?
|
|
19
|
+
type MakeTags<A> = A
|
|
18
20
|
|
|
19
21
|
export interface MiddlewareMaker<
|
|
20
22
|
Self,
|
|
@@ -39,7 +41,7 @@ export interface MiddlewareMaker<
|
|
|
39
41
|
})
|
|
40
42
|
& (MiddlewareMaker.ManyErrors<MiddlewareProviders> extends never ? {}
|
|
41
43
|
: {
|
|
42
|
-
readonly error: S.
|
|
44
|
+
readonly error: S.Codec<MiddlewareMaker.ManyErrors<MiddlewareProviders>>
|
|
43
45
|
})
|
|
44
46
|
& (MiddlewareMaker.ManyProvided<MiddlewareProviders> extends never ? {}
|
|
45
47
|
: { readonly provides: MakeTags<MiddlewareMaker.ManyProvided<MiddlewareProviders>> })
|
|
@@ -60,13 +62,13 @@ export interface MiddlewareMaker<
|
|
|
60
62
|
}
|
|
61
63
|
>
|
|
62
64
|
{
|
|
63
|
-
readonly layer: Layer.Layer<Self, never,
|
|
65
|
+
readonly layer: Layer.Layer<Self, never, Context.Service.Identifier<MiddlewareProviders[number]>>
|
|
64
66
|
readonly requestContext: RequestContextTag<RequestContextMap>
|
|
65
67
|
readonly requestContextMap: RequestContextMap
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
export interface RequestContextTag<RequestContextMap extends Record<string, RpcContextMap.Any>>
|
|
69
|
-
extends
|
|
71
|
+
extends Context.Service<"RequestContextConfig", GetContextConfig<RequestContextMap>>
|
|
70
72
|
{}
|
|
71
73
|
|
|
72
74
|
export namespace MiddlewareMaker {
|
|
@@ -274,7 +276,7 @@ const middlewareMaker = <
|
|
|
274
276
|
middlewares = middlewares.toReversed() as any
|
|
275
277
|
|
|
276
278
|
return Effect.gen(function*() {
|
|
277
|
-
const context = yield* Effect.
|
|
279
|
+
const context = yield* Effect.context()
|
|
278
280
|
|
|
279
281
|
// returns a Effect/RpcMiddlewareV4 with Scope.Scope in requirements
|
|
280
282
|
// v4: wrap middleware takes (effect, options) as two params instead of a single options bag
|
|
@@ -294,7 +296,7 @@ const middlewareMaker = <
|
|
|
294
296
|
// inspired from Effect/RpcMiddleware
|
|
295
297
|
for (const tag of middlewares) {
|
|
296
298
|
// use the tag to get the middleware from context
|
|
297
|
-
const middleware =
|
|
299
|
+
const middleware = Context.getUnsafe(context, tag)
|
|
298
300
|
|
|
299
301
|
// wrap the current handler, allowing the middleware to run before and after it
|
|
300
302
|
handler = PreludeLogger.logDebug("Applying middleware wrap " + tag.key).pipe(
|
|
@@ -332,7 +334,7 @@ const makeMiddlewareBasic = <Self>() =>
|
|
|
332
334
|
error: (firstFailure
|
|
333
335
|
? S.Union([firstFailure, ...restFailures])
|
|
334
336
|
: S.Never) as unknown as MiddlewareMaker.ManyErrors<MiddlewareProviders> extends never ? never
|
|
335
|
-
: S.
|
|
337
|
+
: S.Codec<MiddlewareMaker.ManyErrors<MiddlewareProviders>>,
|
|
336
338
|
requires: (requires.length > 0
|
|
337
339
|
? requires
|
|
338
340
|
: undefined) as unknown as Exclude<
|
|
@@ -366,7 +368,7 @@ const makeMiddlewareBasic = <Self>() =>
|
|
|
366
368
|
return Object.assign(MiddlewareMaker, {
|
|
367
369
|
layer,
|
|
368
370
|
// tag to be used to retrieve the RequestContextConfig from Rpc annotations
|
|
369
|
-
requestContext:
|
|
371
|
+
requestContext: Context.Service<"RequestContextConfig", GetContextConfig<RequestContextMap>>(
|
|
370
372
|
"RequestContextConfig"
|
|
371
373
|
),
|
|
372
374
|
requestContextMap: rcm
|
|
@@ -379,7 +381,7 @@ export const Tag = <Self>() =>
|
|
|
379
381
|
RequestContextMap extends RequestContextMapTagAny
|
|
380
382
|
>(id: Id, rcm: RequestContextMap): MiddlewaresBuilder<Self, Id, RequestContextMap["config"]> => {
|
|
381
383
|
let allMiddleware: MiddlewareMaker.Any[] = []
|
|
382
|
-
const requestContext =
|
|
384
|
+
const requestContext = Context.Service<"RequestContextConfig", GetContextConfig<RequestContextMap["config"]>>(
|
|
383
385
|
"RequestContextConfig"
|
|
384
386
|
)
|
|
385
387
|
const it = {
|
package/src/rpc/RpcContextMap.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
4
|
|
|
5
|
-
import { type Schema as S
|
|
5
|
+
import { type Schema as S } from "effect"
|
|
6
6
|
import { type AnyWithProps } from "effect/unstable/rpc/Rpc"
|
|
7
|
+
import * as Context from "../Context.js"
|
|
7
8
|
import { type RpcDynamic } from "./RpcMiddleware.js"
|
|
8
9
|
|
|
9
10
|
type Values<T extends Record<any, any>> = T[keyof T]
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Middleware is inactivate by default, the Key is optional in route context, and the service is optionally provided as Effect
|
|
13
|
+
* Middleware is inactivate by default, the Key is optional in route context, and the service is optionally provided as Effect Context.
|
|
13
14
|
* Unless explicitly configured as `true`.
|
|
14
15
|
*/
|
|
15
16
|
export type RpcContextMap<Service, E> = {
|
|
@@ -22,7 +23,7 @@ export type RpcContextMap<Service, E> = {
|
|
|
22
23
|
|
|
23
24
|
export declare namespace RpcContextMap {
|
|
24
25
|
/**
|
|
25
|
-
* Middleware is active by default, and provides the Service at Key in route context, and the Service is provided as Effect
|
|
26
|
+
* Middleware is active by default, and provides the Service at Key in route context, and the Service is provided as Effect Context.
|
|
26
27
|
* Unless explicitly omitted.
|
|
27
28
|
*/
|
|
28
29
|
export type Inverted<Service, E> = {
|
|
@@ -97,7 +98,7 @@ export type GetEffectError<RequestContextMap extends Record<string, RpcContextMa
|
|
|
97
98
|
}
|
|
98
99
|
>
|
|
99
100
|
|
|
100
|
-
const tag =
|
|
101
|
+
const tag = Context.Service("RequestContextConfig")
|
|
101
102
|
|
|
102
103
|
export const makeMap = <const Config extends Record<string, RpcContextMap.Any>>(config: Config) => {
|
|
103
104
|
const cls = class {
|
|
@@ -109,7 +110,7 @@ export const makeMap = <const Config extends Record<string, RpcContextMap.Any>>(
|
|
|
109
110
|
return Object.assign(cls, {
|
|
110
111
|
config, /** Retrieves RequestContextConfig out of the Rpc annotations */
|
|
111
112
|
getConfig: (rpc: AnyWithProps): GetContextConfig<Config> => {
|
|
112
|
-
return
|
|
113
|
+
return Context.getOrElse(rpc.annotations, tag as any, () => ({}))
|
|
113
114
|
},
|
|
114
115
|
/** Adapter used when setting the dynamic prop on a middleware implementation */
|
|
115
116
|
get: <
|
package/src/rpc/RpcMiddleware.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
import { type Effect, type Schema, type Schema as S, type Scope, type
|
|
4
|
+
import { type Effect, type Schema, type Schema as S, type Scope, type Stream } from "effect"
|
|
5
5
|
import { type NonEmptyReadonlyArray } from "effect/Array"
|
|
6
6
|
import { type Rpc, RpcMiddleware } from "effect/unstable/rpc"
|
|
7
7
|
import { type TypeId } from "effect/unstable/rpc/RpcMiddleware"
|
|
8
|
+
import type * as Context from "../Context.js"
|
|
8
9
|
import { type GetEffectContext, type RpcContextMap } from "./RpcContextMap.js"
|
|
9
10
|
|
|
10
11
|
export type RpcMiddlewareV4<Provides, E, Requires> = RpcMiddleware.RpcMiddleware<Provides, E, Requires>
|
|
@@ -59,7 +60,7 @@ export declare namespace TagClass {
|
|
|
59
60
|
* @since 1.0.0
|
|
60
61
|
* @category models
|
|
61
62
|
*/
|
|
62
|
-
export type Failure<Options> = Options extends { readonly error: Schema.
|
|
63
|
+
export type Failure<Options> = Options extends { readonly error: Schema.Codec<infer _A>; readonly optional?: false }
|
|
63
64
|
? _A
|
|
64
65
|
// actually not, the Failure depends on Dynamic Middleware Configuration!
|
|
65
66
|
: Options extends { readonly dynamic: RpcDynamic<any, infer A> } ? S.Schema.Type<A["error"]>
|
|
@@ -102,8 +103,8 @@ export declare namespace TagClass {
|
|
|
102
103
|
requires?: any
|
|
103
104
|
provides?: any
|
|
104
105
|
}
|
|
105
|
-
> extends
|
|
106
|
-
new(_: never):
|
|
106
|
+
> extends Context.Service<Self, Service> {
|
|
107
|
+
new(_: never): Context.ServiceClass.Shape<Name, Service>
|
|
107
108
|
readonly [TypeId]: TypeId
|
|
108
109
|
readonly optional: Optional<Options>
|
|
109
110
|
readonly error: FailureSchema<Options>
|
|
@@ -226,8 +227,8 @@ export type ExtractProvides<R extends Rpc.Any, Tag extends string> = R extends
|
|
|
226
227
|
Rpc.Rpc<Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Middleware extends {
|
|
227
228
|
readonly provides: infer _P
|
|
228
229
|
} ? [_P] extends [never] ? never
|
|
229
|
-
: _P extends
|
|
230
|
-
: never
|
|
230
|
+
: _P /*_P extends Context.Service<infer _I, infer _S> ? _I
|
|
231
|
+
: never */
|
|
231
232
|
: never
|
|
232
233
|
: never
|
|
233
234
|
|
package/src/utils/gen.ts
CHANGED
|
@@ -15,7 +15,7 @@ export namespace EffectGenUtils {
|
|
|
15
15
|
: EG extends (..._: infer _3) => Generator<Yieldable<any, infer _, infer E, infer _R>, infer _A, infer _2> ? E
|
|
16
16
|
: never
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type Context<EG> = EG extends Effect<infer _A, infer _E, infer R> ? R
|
|
19
19
|
// there could be a case where the generator function does not yield anything, so we need to handle that
|
|
20
20
|
: EG extends (..._: infer _3) => Generator<never, infer _A, infer _2> ? never
|
|
21
21
|
// v4: generators can yield Yieldable (Effect, Service, etc.), all have asEffect()
|
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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
|
4
|
-
import { Effect, Exit, Fiber, Option, Record } from "effect"
|
|
4
|
+
import { Cause, Effect, Exit, Fiber, Option, Record } from "effect"
|
|
5
5
|
import { dual } from "effect/Function"
|
|
6
|
-
import { isFunction } from "effect/Predicate"
|
|
6
|
+
import { isFunction, isObject } 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"
|
|
@@ -924,8 +924,8 @@ export const runtimeFiberAsPromise = <A, E>(fiber: Fiber.Fiber<A, E>, signal?: A
|
|
|
924
924
|
if (Exit.isSuccess(exit)) {
|
|
925
925
|
resolve(exit.value)
|
|
926
926
|
} else {
|
|
927
|
-
//
|
|
928
|
-
reject(exit.cause)
|
|
927
|
+
// eslint-disable-next-line
|
|
928
|
+
reject(Cause.squash(exit.cause))
|
|
929
929
|
}
|
|
930
930
|
})
|
|
931
931
|
)
|
|
@@ -950,3 +950,25 @@ export type UnionToTuples<T, U = T> = [T] extends [never] ? []
|
|
|
950
950
|
| [T, ...UnionToTuples<Exclude<U, T>>]
|
|
951
951
|
| UnionToTuples<Exclude<U, T>>
|
|
952
952
|
: []
|
|
953
|
+
|
|
954
|
+
const genConstructor = (function*() {}).constructor
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* @example
|
|
958
|
+
* ```ts
|
|
959
|
+
* import { Utils } from "effect"
|
|
960
|
+
*
|
|
961
|
+
* function* generatorFn() {
|
|
962
|
+
* yield 1
|
|
963
|
+
* yield 2
|
|
964
|
+
* }
|
|
965
|
+
*
|
|
966
|
+
* console.log(Utils.isGeneratorFunction(generatorFn)) // true
|
|
967
|
+
* console.log(Utils.isGeneratorFunction(() => {})) // false
|
|
968
|
+
* ```
|
|
969
|
+
*
|
|
970
|
+
* @category predicates
|
|
971
|
+
* @since 3.11.0
|
|
972
|
+
*/
|
|
973
|
+
export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>
|
|
974
|
+
isObject(u) && u.constructor === genConstructor
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moreStrings.test.d.ts","sourceRoot":"","sources":["../moreStrings.test.ts"],"names":[],"mappings":""}
|
|
@@ -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":"AACA,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,17 @@
|
|
|
1
|
+
import { S } from "effect-app"
|
|
2
|
+
import * as fc from "fast-check"
|
|
3
|
+
import { urlAlphabet } from "nanoid"
|
|
4
|
+
import { test } from "vitest"
|
|
5
|
+
|
|
6
|
+
const nanoidAlphabet = new Set(urlAlphabet)
|
|
7
|
+
|
|
8
|
+
const isNanoId = (value: string) => value.length === 21 && Array.from(value).every((char) => nanoidAlphabet.has(char))
|
|
9
|
+
|
|
10
|
+
test("StringId arbitrary generates nanoid-shaped values", () => {
|
|
11
|
+
fc.assert(
|
|
12
|
+
fc.property(S.toArbitrary(S.StringId), (value) => {
|
|
13
|
+
expect(isNanoId(value)).toBe(true)
|
|
14
|
+
expect(S.is(S.StringId)(value)).toBe(true)
|
|
15
|
+
})
|
|
16
|
+
)
|
|
17
|
+
})
|
package/test/rpc.test.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { expect, test } from "vitest"
|
|
1
2
|
import { makeRpcClient, NotLoggedInError, UnauthorizedError } from "../src/client.js"
|
|
3
|
+
import { ForceVoid } from "../src/client/makeClient.js"
|
|
2
4
|
import { S } from "../src/index.js"
|
|
3
5
|
import { RpcContextMap } from "../src/rpc.js"
|
|
4
6
|
|
|
@@ -8,16 +10,36 @@ export class RequestContextMap extends RpcContextMap.makeMap({
|
|
|
8
10
|
test: RpcContextMap.make()(S.Never)
|
|
9
11
|
}) {}
|
|
10
12
|
|
|
11
|
-
const {
|
|
13
|
+
const { TaggedRequestFor } = makeRpcClient(RequestContextMap)
|
|
14
|
+
const TaggedRequest = TaggedRequestFor("Test")
|
|
12
15
|
|
|
13
16
|
export class Stats extends TaggedRequest<Stats>()("Stats", {}, {
|
|
14
17
|
allowedRoles: ["manager"],
|
|
15
18
|
success: {
|
|
16
|
-
usersActive24Hours: S.
|
|
17
|
-
usersActiveLastWeek: S.
|
|
18
|
-
newUsersLast24Hours: S.
|
|
19
|
-
newUsersLastWeek: S.
|
|
19
|
+
usersActive24Hours: S.Finite,
|
|
20
|
+
usersActiveLastWeek: S.Finite,
|
|
21
|
+
newUsersLast24Hours: S.Finite,
|
|
22
|
+
newUsersLastWeek: S.Finite
|
|
20
23
|
}
|
|
21
24
|
}) {}
|
|
22
25
|
|
|
23
|
-
declare const _stats: typeof Stats.
|
|
26
|
+
declare const _stats: typeof Stats.Type
|
|
27
|
+
declare const _statsSuccess: typeof Stats.success.Type
|
|
28
|
+
declare const _statsError: typeof Stats.error.Type
|
|
29
|
+
|
|
30
|
+
test("ForceVoid decodes and encodes as void", () => {
|
|
31
|
+
expect(S.decodeUnknownSync(ForceVoid)(undefined)).toBe(undefined)
|
|
32
|
+
expect(S.is(ForceVoid)(undefined)).toBe(true)
|
|
33
|
+
expect(S.decodeUnknownSync(ForceVoid)("test")).toBe(undefined)
|
|
34
|
+
expect(S.is(ForceVoid)("test")).toBe(true)
|
|
35
|
+
expect(S.encodeUnknownSync(ForceVoid)("test")).toBe(undefined)
|
|
36
|
+
expect(S.encodeUnknownSync(S.toCodecJson(ForceVoid))("test")).toBe(null)
|
|
37
|
+
expectTypeOf<typeof _stats>().toEqualTypeOf<Stats>()
|
|
38
|
+
expectTypeOf<typeof _statsSuccess>().toEqualTypeOf<{
|
|
39
|
+
readonly usersActive24Hours: number
|
|
40
|
+
readonly usersActiveLastWeek: number
|
|
41
|
+
readonly newUsersLast24Hours: number
|
|
42
|
+
readonly newUsersLastWeek: number
|
|
43
|
+
}>()
|
|
44
|
+
expectTypeOf<typeof _statsError>().toEqualTypeOf<NotLoggedInError | UnauthorizedError>()
|
|
45
|
+
})
|