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.
Files changed (97) hide show
  1. package/dist/Channel.d.ts +2 -2
  2. package/dist/Channel.d.ts.map +1 -1
  3. package/dist/Channel.js.map +1 -1
  4. package/dist/Cron.js +3 -3
  5. package/dist/Cron.js.map +1 -1
  6. package/dist/DateTime.d.ts +33 -77
  7. package/dist/DateTime.d.ts.map +1 -1
  8. package/dist/DateTime.js +1 -1
  9. package/dist/DateTime.js.map +1 -1
  10. package/dist/Duration.d.ts +29 -1
  11. package/dist/Duration.d.ts.map +1 -1
  12. package/dist/Duration.js +77 -48
  13. package/dist/Duration.js.map +1 -1
  14. package/dist/Layer.d.ts +97 -2
  15. package/dist/Layer.d.ts.map +1 -1
  16. package/dist/Layer.js +8 -2
  17. package/dist/Layer.js.map +1 -1
  18. package/dist/Schema.d.ts +2316 -114
  19. package/dist/Schema.d.ts.map +1 -1
  20. package/dist/Schema.js +1331 -67
  21. package/dist/Schema.js.map +1 -1
  22. package/dist/SchemaAST.d.ts +2 -2
  23. package/dist/SchemaAST.js +2 -2
  24. package/dist/SchemaRepresentation.d.ts +2 -2
  25. package/dist/SchemaRepresentation.d.ts.map +1 -1
  26. package/dist/SchemaRepresentation.js.map +1 -1
  27. package/dist/internal/dateTime.js +57 -50
  28. package/dist/internal/dateTime.js.map +1 -1
  29. package/dist/internal/effect.js +1 -1
  30. package/dist/internal/effect.js.map +1 -1
  31. package/dist/unstable/ai/Chat.d.ts +3 -4
  32. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  33. package/dist/unstable/ai/Chat.js.map +1 -1
  34. package/dist/unstable/ai/LanguageModel.d.ts +30 -16
  35. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  36. package/dist/unstable/ai/LanguageModel.js +10 -87
  37. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  38. package/dist/unstable/cli/Completions.d.ts +16 -0
  39. package/dist/unstable/cli/Completions.d.ts.map +1 -0
  40. package/dist/unstable/cli/Completions.js +23 -0
  41. package/dist/unstable/cli/Completions.js.map +1 -0
  42. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  43. package/dist/unstable/cli/GlobalFlag.js +4 -4
  44. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  45. package/dist/unstable/cli/index.d.ts +4 -0
  46. package/dist/unstable/cli/index.d.ts.map +1 -1
  47. package/dist/unstable/cli/index.js +4 -0
  48. package/dist/unstable/cli/index.js.map +1 -1
  49. package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
  50. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  51. package/dist/unstable/cluster/DeliverAt.js +1 -1
  52. package/dist/unstable/cluster/DeliverAt.js.map +1 -1
  53. package/dist/unstable/encoding/Ndjson.d.ts +8 -8
  54. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  55. package/dist/unstable/encoding/Ndjson.js.map +1 -1
  56. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  57. package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
  58. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  59. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  60. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  61. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +2 -2
  62. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  63. package/dist/unstable/persistence/Persistable.js +1 -1
  64. package/dist/unstable/persistence/Persistable.js.map +1 -1
  65. package/dist/unstable/rpc/RpcGroup.d.ts +1 -3
  66. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/src/Channel.ts +3 -3
  69. package/src/Cron.ts +3 -3
  70. package/src/DateTime.ts +35 -77
  71. package/src/Duration.ts +78 -23
  72. package/src/Layer.ts +123 -19
  73. package/src/Schema.ts +2317 -115
  74. package/src/SchemaAST.ts +2 -2
  75. package/src/SchemaRepresentation.ts +2 -2
  76. package/src/internal/dateTime.ts +60 -51
  77. package/src/internal/effect.ts +1 -1
  78. package/src/unstable/ai/Chat.ts +11 -13
  79. package/src/unstable/ai/LanguageModel.ts +148 -97
  80. package/src/unstable/cli/Completions.ts +36 -0
  81. package/src/unstable/cli/GlobalFlag.ts +4 -5
  82. package/src/unstable/cli/index.ts +5 -0
  83. package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -1
  84. package/src/unstable/cluster/DeliverAt.ts +1 -1
  85. package/src/unstable/encoding/Ndjson.ts +17 -17
  86. package/src/unstable/http/HttpClientResponse.ts +2 -2
  87. package/src/unstable/http/HttpIncomingMessage.ts +1 -1
  88. package/src/unstable/http/HttpServerRequest.ts +4 -4
  89. package/src/unstable/http/HttpServerResponse.ts +2 -2
  90. package/src/unstable/httpapi/HttpApiBuilder.ts +4 -4
  91. package/src/unstable/persistence/Persistable.ts +1 -1
  92. package/src/unstable/rpc/RpcGroup.ts +3 -3
  93. package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
  94. package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
  95. package/dist/unstable/cli/internal/completions/Completions.js +0 -23
  96. package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
  97. 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
- <I, S extends object>(service: ServiceMap.Key<I, S>) => (implementation: PartialEffectful<S>): Layer<I> =>
3091
- succeed(service)(
3092
- new Proxy({ ...implementation as object } as S, {
3093
- get(target, prop, _receiver) {
3094
- if (prop in target) {
3095
- return target[prop as keyof S]
3096
- }
3097
- const prevLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
3098
- ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = 2
3099
- const error = new Error(`${service.key}: Unimplemented method "${prop.toString()}"`)
3100
- ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevLimit
3101
- error.name = "UnimplementedError"
3102
- return makeUnimplemented(error)
3103
- },
3104
- has: constTrue
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)