effect 4.0.0-beta.30 → 4.0.0-beta.31
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/dist/Channel.d.ts +2 -2
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Cron.js +3 -3
- package/dist/Cron.js.map +1 -1
- package/dist/DateTime.d.ts +33 -77
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +1 -1
- package/dist/DateTime.js.map +1 -1
- package/dist/Duration.d.ts +29 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +77 -48
- package/dist/Duration.js.map +1 -1
- package/dist/Layer.d.ts +97 -2
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +8 -2
- package/dist/Layer.js.map +1 -1
- package/dist/Schema.d.ts +2316 -114
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +1331 -67
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -2
- package/dist/SchemaAST.js +2 -2
- package/dist/SchemaRepresentation.d.ts +2 -2
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/internal/dateTime.js +57 -50
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +1 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +3 -4
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +30 -16
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +10 -87
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/cli/Completions.d.ts +16 -0
- package/dist/unstable/cli/Completions.d.ts.map +1 -0
- package/dist/unstable/cli/Completions.js +23 -0
- package/dist/unstable/cli/Completions.js.map +1 -0
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +4 -4
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/DeliverAt.js +1 -1
- package/dist/unstable/cluster/DeliverAt.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +8 -8
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.js +1 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +1 -3
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +3 -3
- package/src/Cron.ts +3 -3
- package/src/DateTime.ts +35 -77
- package/src/Duration.ts +78 -23
- package/src/Layer.ts +123 -19
- package/src/Schema.ts +2317 -115
- package/src/SchemaAST.ts +2 -2
- package/src/SchemaRepresentation.ts +2 -2
- package/src/internal/dateTime.ts +60 -51
- package/src/internal/effect.ts +1 -1
- package/src/unstable/ai/Chat.ts +11 -13
- package/src/unstable/ai/LanguageModel.ts +148 -97
- package/src/unstable/cli/Completions.ts +36 -0
- package/src/unstable/cli/GlobalFlag.ts +4 -5
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -1
- package/src/unstable/cluster/DeliverAt.ts +1 -1
- package/src/unstable/encoding/Ndjson.ts +17 -17
- package/src/unstable/http/HttpClientResponse.ts +2 -2
- package/src/unstable/http/HttpIncomingMessage.ts +1 -1
- package/src/unstable/http/HttpServerRequest.ts +4 -4
- package/src/unstable/http/HttpServerResponse.ts +2 -2
- package/src/unstable/httpapi/HttpApiBuilder.ts +4 -4
- package/src/unstable/persistence/Persistable.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -3
- package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
- package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
- package/dist/unstable/cli/internal/completions/Completions.js +0 -23
- package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
- package/src/unstable/cli/internal/completions/Completions.ts +0 -31
package/src/Layer.ts
CHANGED
|
@@ -3062,7 +3062,7 @@ export type PartialEffectful<A extends object> = Types.Simplify<
|
|
|
3062
3062
|
* }>()("UserService") {}
|
|
3063
3063
|
*
|
|
3064
3064
|
* // Create a partial mock - only implement what you need for testing
|
|
3065
|
-
* const testUserLayer = Layer.mock(UserService
|
|
3065
|
+
* const testUserLayer = Layer.mock(UserService, {
|
|
3066
3066
|
* config: { apiUrl: "https://test-api.com" }, // Required - non-Effect property
|
|
3067
3067
|
* getUser: (id: string) => Effect.succeed({ id, name: "Test User" }) // Mock implementation
|
|
3068
3068
|
* // deleteUser and updateUser are omitted - will throw UnimplementedError if called
|
|
@@ -3086,24 +3086,128 @@ export type PartialEffectful<A extends object> = Types.Simplify<
|
|
|
3086
3086
|
* @since 4.0.0
|
|
3087
3087
|
* @category Testing
|
|
3088
3088
|
*/
|
|
3089
|
-
export const mock
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3089
|
+
export const mock: {
|
|
3090
|
+
/**
|
|
3091
|
+
* Creates a mock layer for testing purposes. You can provide a partial
|
|
3092
|
+
* implementation of the service, and any methods not provided will
|
|
3093
|
+
* throw an unimplemented defect when called.
|
|
3094
|
+
*
|
|
3095
|
+
* @example
|
|
3096
|
+
* ```ts
|
|
3097
|
+
* import { Effect, Layer, ServiceMap } from "effect"
|
|
3098
|
+
*
|
|
3099
|
+
* class UserService extends ServiceMap.Service<UserService, {
|
|
3100
|
+
* readonly config: { apiUrl: string }
|
|
3101
|
+
* readonly getUser: (
|
|
3102
|
+
* id: string
|
|
3103
|
+
* ) => Effect.Effect<{ id: string; name: string }, Error>
|
|
3104
|
+
* readonly deleteUser: (id: string) => Effect.Effect<void, Error>
|
|
3105
|
+
* readonly updateUser: (
|
|
3106
|
+
* id: string,
|
|
3107
|
+
* data: object
|
|
3108
|
+
* ) => Effect.Effect<{ id: string; name: string }, Error>
|
|
3109
|
+
* }>()("UserService") {}
|
|
3110
|
+
*
|
|
3111
|
+
* // Create a partial mock - only implement what you need for testing
|
|
3112
|
+
* const testUserLayer = Layer.mock(UserService, {
|
|
3113
|
+
* config: { apiUrl: "https://test-api.com" }, // Required - non-Effect property
|
|
3114
|
+
* getUser: (id: string) => Effect.succeed({ id, name: "Test User" }) // Mock implementation
|
|
3115
|
+
* // deleteUser and updateUser are omitted - will throw UnimplementedError if called
|
|
3116
|
+
* })
|
|
3117
|
+
*
|
|
3118
|
+
* // Use in tests
|
|
3119
|
+
* const testProgram = Effect.gen(function*() {
|
|
3120
|
+
* const userService = yield* UserService
|
|
3121
|
+
*
|
|
3122
|
+
* // This works - we provided an implementation
|
|
3123
|
+
* const user = yield* userService.getUser("123")
|
|
3124
|
+
* console.log(user.name) // "Test User"
|
|
3125
|
+
*
|
|
3126
|
+
* // This would throw - we didn't implement deleteUser
|
|
3127
|
+
* // yield* userService.deleteUser("123") // UnimplementedError
|
|
3128
|
+
* }).pipe(
|
|
3129
|
+
* Effect.provide(testUserLayer)
|
|
3130
|
+
* )
|
|
3131
|
+
* ```
|
|
3132
|
+
*
|
|
3133
|
+
* @since 4.0.0
|
|
3134
|
+
* @category Testing
|
|
3135
|
+
*/
|
|
3136
|
+
<I, S extends object>(service: ServiceMap.Key<I, S>): (implementation: PartialEffectful<S>) => Layer<I>
|
|
3137
|
+
/**
|
|
3138
|
+
* Creates a mock layer for testing purposes. You can provide a partial
|
|
3139
|
+
* implementation of the service, and any methods not provided will
|
|
3140
|
+
* throw an unimplemented defect when called.
|
|
3141
|
+
*
|
|
3142
|
+
* @example
|
|
3143
|
+
* ```ts
|
|
3144
|
+
* import { Effect, Layer, ServiceMap } from "effect"
|
|
3145
|
+
*
|
|
3146
|
+
* class UserService extends ServiceMap.Service<UserService, {
|
|
3147
|
+
* readonly config: { apiUrl: string }
|
|
3148
|
+
* readonly getUser: (
|
|
3149
|
+
* id: string
|
|
3150
|
+
* ) => Effect.Effect<{ id: string; name: string }, Error>
|
|
3151
|
+
* readonly deleteUser: (id: string) => Effect.Effect<void, Error>
|
|
3152
|
+
* readonly updateUser: (
|
|
3153
|
+
* id: string,
|
|
3154
|
+
* data: object
|
|
3155
|
+
* ) => Effect.Effect<{ id: string; name: string }, Error>
|
|
3156
|
+
* }>()("UserService") {}
|
|
3157
|
+
*
|
|
3158
|
+
* // Create a partial mock - only implement what you need for testing
|
|
3159
|
+
* const testUserLayer = Layer.mock(UserService, {
|
|
3160
|
+
* config: { apiUrl: "https://test-api.com" }, // Required - non-Effect property
|
|
3161
|
+
* getUser: (id: string) => Effect.succeed({ id, name: "Test User" }) // Mock implementation
|
|
3162
|
+
* // deleteUser and updateUser are omitted - will throw UnimplementedError if called
|
|
3163
|
+
* })
|
|
3164
|
+
*
|
|
3165
|
+
* // Use in tests
|
|
3166
|
+
* const testProgram = Effect.gen(function*() {
|
|
3167
|
+
* const userService = yield* UserService
|
|
3168
|
+
*
|
|
3169
|
+
* // This works - we provided an implementation
|
|
3170
|
+
* const user = yield* userService.getUser("123")
|
|
3171
|
+
* console.log(user.name) // "Test User"
|
|
3172
|
+
*
|
|
3173
|
+
* // This would throw - we didn't implement deleteUser
|
|
3174
|
+
* // yield* userService.deleteUser("123") // UnimplementedError
|
|
3175
|
+
* }).pipe(
|
|
3176
|
+
* Effect.provide(testUserLayer)
|
|
3177
|
+
* )
|
|
3178
|
+
* ```
|
|
3179
|
+
*
|
|
3180
|
+
* @since 4.0.0
|
|
3181
|
+
* @category Testing
|
|
3182
|
+
*/
|
|
3183
|
+
<I, S extends object>(
|
|
3184
|
+
service: ServiceMap.Key<I, S>,
|
|
3185
|
+
implementation: Types.NoInfer<PartialEffectful<S>>
|
|
3186
|
+
): Layer<I>
|
|
3187
|
+
} = function() {
|
|
3188
|
+
if (arguments.length === 1) {
|
|
3189
|
+
return (implementation: any) => mockImpl(arguments[0], implementation)
|
|
3190
|
+
}
|
|
3191
|
+
return mockImpl(arguments[0], arguments[1])
|
|
3192
|
+
} as any
|
|
3193
|
+
|
|
3194
|
+
const mockImpl = <I, S extends object>(service: ServiceMap.Key<I, S>, implementation: PartialEffectful<S>): Layer<I> =>
|
|
3195
|
+
succeed(service)(
|
|
3196
|
+
new Proxy({ ...implementation as object } as S, {
|
|
3197
|
+
get(target, prop, _receiver) {
|
|
3198
|
+
if (prop in target) {
|
|
3199
|
+
return target[prop as keyof S]
|
|
3200
|
+
}
|
|
3201
|
+
const prevLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
|
|
3202
|
+
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = 2
|
|
3203
|
+
const error = new Error(`${service.key}: Unimplemented method "${prop.toString()}"`)
|
|
3204
|
+
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevLimit
|
|
3205
|
+
error.name = "UnimplementedError"
|
|
3206
|
+
return makeUnimplemented(error)
|
|
3207
|
+
},
|
|
3208
|
+
has: constTrue
|
|
3209
|
+
})
|
|
3210
|
+
)
|
|
3107
3211
|
|
|
3108
3212
|
const makeUnimplemented = (error: globalThis.Error) => {
|
|
3109
3213
|
const dead = internalEffect.die(error)
|