effect 4.0.0-beta.46 → 4.0.0-beta.48

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 (58) hide show
  1. package/dist/Schema.d.ts +223 -140
  2. package/dist/Schema.d.ts.map +1 -1
  3. package/dist/Schema.js +110 -32
  4. package/dist/Schema.js.map +1 -1
  5. package/dist/Types.d.ts +9 -0
  6. package/dist/Types.d.ts.map +1 -1
  7. package/dist/unstable/ai/McpSchema.d.ts +1 -1
  8. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  9. package/dist/unstable/eventlog/EventLog.d.ts +4 -1
  10. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  11. package/dist/unstable/eventlog/EventLog.js +1 -1
  12. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  13. package/dist/unstable/eventlog/EventLogRemote.d.ts.map +1 -1
  14. package/dist/unstable/eventlog/EventLogRemote.js +1 -0
  15. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  16. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
  17. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  18. package/dist/unstable/httpapi/HttpApiBuilder.js +3 -2
  19. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  20. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  21. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  22. package/dist/unstable/httpapi/HttpApiMiddleware.js +1 -0
  23. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  24. package/dist/unstable/httpapi/HttpApiSchema.d.ts +7 -7
  25. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  26. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  27. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  28. package/dist/unstable/observability/OtlpExporter.js +1 -1
  29. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  30. package/dist/unstable/reactivity/Atom.d.ts +1 -1
  31. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  32. package/dist/unstable/reactivity/Atom.js.map +1 -1
  33. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  34. package/dist/unstable/rpc/RpcSchema.d.ts +1 -1
  35. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  36. package/dist/unstable/socket/Socket.js.map +1 -1
  37. package/dist/unstable/workers/Transferable.d.ts +1 -1
  38. package/dist/unstable/workers/Transferable.d.ts.map +1 -1
  39. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  40. package/dist/unstable/workflow/Workflow.js +1 -1
  41. package/dist/unstable/workflow/Workflow.js.map +1 -1
  42. package/package.json +10 -10
  43. package/src/Schema.ts +260 -167
  44. package/src/Types.ts +8 -0
  45. package/src/unstable/ai/McpSchema.ts +1 -1
  46. package/src/unstable/eventlog/EventLog.ts +7 -2
  47. package/src/unstable/eventlog/EventLogRemote.ts +1 -0
  48. package/src/unstable/httpapi/HttpApiBuilder.ts +11 -3
  49. package/src/unstable/httpapi/HttpApiClient.ts +2 -2
  50. package/src/unstable/httpapi/HttpApiMiddleware.ts +1 -0
  51. package/src/unstable/httpapi/HttpApiSchema.ts +4 -6
  52. package/src/unstable/observability/OtlpExporter.ts +1 -0
  53. package/src/unstable/reactivity/Atom.ts +1 -1
  54. package/src/unstable/reactivity/AtomRpc.ts +4 -4
  55. package/src/unstable/rpc/RpcSchema.ts +1 -1
  56. package/src/unstable/socket/Socket.ts +1 -1
  57. package/src/unstable/workers/Transferable.ts +2 -2
  58. package/src/unstable/workflow/Workflow.ts +5 -2
package/src/Types.ts CHANGED
@@ -1001,3 +1001,11 @@ export type OmitReason<E, K extends string> = E extends { readonly reason: infer
1001
1001
  export type ExcludeReason<E, K extends string> = E extends { readonly reason: infer R }
1002
1002
  ? Exclude<R, { readonly _tag: K }>
1003
1003
  : never
1004
+
1005
+ /**
1006
+ * Extracts the required keys from a type.
1007
+ *
1008
+ * @since 4.0.0
1009
+ * @category types
1010
+ */
1011
+ export type RequiredKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]
@@ -2106,7 +2106,7 @@ export interface Param<Name extends string, S extends Schema.Top> extends
2106
2106
  S["~encoded.optionality"]
2107
2107
  >
2108
2108
  {
2109
- readonly "~rebuild.out": this
2109
+ readonly "Rebuild": Param<Name, S>
2110
2110
  readonly [ParamSchemaTypeId]: typeof ParamSchemaTypeId
2111
2111
  readonly name: Name
2112
2112
  readonly schema: S
@@ -358,7 +358,9 @@ const IdentityEncodedSchema = Schema.Struct({
358
358
  privateKey: Schema.Uint8ArrayFromBase64
359
359
  })
360
360
 
361
- const IdentityStringSchema = Schema.fromJsonString(IdentityEncodedSchema)
361
+ const IdentityStringSchema = Schema.StringFromBase64Url.pipe(
362
+ Schema.decodeTo(Schema.fromJsonString(IdentityEncodedSchema))
363
+ )
362
364
 
363
365
  /**
364
366
  * @since 4.0.0
@@ -584,7 +586,10 @@ export const makeReplayFromRemote = (options: {
584
586
  }
585
587
  }) =>
586
588
  Effect.fnUntraced(
587
- function*({ conflicts, entry }): Effect.fn.Return<void, Schema.SchemaError> {
589
+ function*({ conflicts, entry }: {
590
+ readonly entry: Entry
591
+ readonly conflicts: ReadonlyArray<Entry>
592
+ }): Effect.fn.Return<void, Schema.SchemaError> {
588
593
  const handler = options.handlers.get(entry.event) as Handlers.Item<any> | undefined
589
594
  if (!handler) {
590
595
  return yield* Effect.logDebug(`Event handler not found for: "${entry.event}"`)
@@ -245,6 +245,7 @@ export const makeWith = Effect.fnUntraced(function*({ encodeWrite, decodeChanges
245
245
  return remote
246
246
  })
247
247
 
248
+ /** @effect-diagnostics-next-line classSelfMismatch:off */
248
249
  class IdentityService extends Context.Service<Identity, Identity["Service"]>()(
249
250
  "effect/eventlog/EventLog/Identity" satisfies Identity["key"]
250
251
  ) {}
@@ -18,7 +18,7 @@ import * as Schema from "../../Schema.ts"
18
18
  import type * as AST from "../../SchemaAST.ts"
19
19
  import * as Issue from "../../SchemaIssue.ts"
20
20
  import * as Transformation from "../../SchemaTransformation.ts"
21
- import type * as Scope from "../../Scope.ts"
21
+ import * as Scope from "../../Scope.ts"
22
22
  import * as Stream from "../../Stream.ts"
23
23
  import type { Covariant, NoInfer } from "../../Types.ts"
24
24
  import * as UndefinedOr from "../../UndefinedOr.ts"
@@ -120,7 +120,9 @@ export const group = <
120
120
  Exclude<Handlers.Context<Return>, Scope.Scope>
121
121
  > =>
122
122
  Layer.effectContext(Effect.gen(function*() {
123
- const services = yield* Effect.context<any>()
123
+ const services = (yield* Effect.context<any>()).pipe(
124
+ Context.omit(Scope.Scope)
125
+ )
124
126
  const group = api.groups[groupName]!
125
127
  const result = build(makeHandlers(group))
126
128
  const handlers: Handlers<any, any> = Effect.isEffect(result)
@@ -333,7 +335,13 @@ export const endpoint = <
333
335
  Effect.contextWith((context: Context.Context<any>) => {
334
336
  const group = api.groups[groupName] as unknown as HttpApiGroup.AnyWithProps
335
337
  const endpoint = group.endpoints[endpointName] as unknown as HttpApiEndpoint.AnyWithProps
336
- return Effect.succeed(handlerToHttpEffect(group, endpoint, context, handler as any, false))
338
+ return Effect.succeed(handlerToHttpEffect(
339
+ group,
340
+ endpoint,
341
+ Context.omit(Scope.Scope)(context),
342
+ handler as any,
343
+ false
344
+ ))
337
345
  })
338
346
 
339
347
  /**
@@ -715,11 +715,11 @@ function getEncodePayloadSchemaFromBody(
715
715
  const encoding = HttpApiSchema.getPayloadEncoding(ast, method)
716
716
  const out = $HttpBody.pipe(Schema.decodeTo(
717
717
  schema,
718
- Transformation.transformOrFail({
718
+ Transformation.transformOrFail<unknown, HttpBody.HttpBody>({
719
719
  decode(httpBody) {
720
720
  return Effect.fail(new Issue.Forbidden(Option.some(httpBody), { message: "Encode only schema" }))
721
721
  },
722
- encode(t: unknown) {
722
+ encode(t) {
723
723
  switch (encoding._tag) {
724
724
  case "Multipart":
725
725
  return Effect.fail(new Issue.Forbidden(Option.some(t), { message: "Payload must be a FormData" }))
@@ -279,6 +279,7 @@ export const Service = <
279
279
  const creationError = new Err()
280
280
  Err.stackTraceLimit = limit
281
281
 
282
+ /** @effect-diagnostics-next-line classSelfMismatch:off */
282
283
  class Service extends Context.Service<Self, any>()(id) {}
283
284
  const self = Service as any
284
285
  Object.defineProperty(Service, "stack", {
@@ -87,7 +87,7 @@ export type ResponseEncoding = {
87
87
  * @since 4.0.0
88
88
  */
89
89
  export function status(code: number) {
90
- return <S extends Schema.Top>(self: S): S["~rebuild.out"] => {
90
+ return <S extends Schema.Top>(self: S): S["Rebuild"] => {
91
91
  return self.annotate({ httpApiStatus: code })
92
92
  }
93
93
  }
@@ -190,7 +190,7 @@ export type MultipartTypeId = typeof MultipartTypeId
190
190
  /**
191
191
  * @since 4.0.0
192
192
  */
193
- export interface asMultipart<S extends Schema.Top> extends Schema.brand<S["~rebuild.out"], MultipartTypeId> {}
193
+ export interface asMultipart<S extends Schema.Top> extends Schema.brand<S["Rebuild"], MultipartTypeId> {}
194
194
 
195
195
  /**
196
196
  * Marks a schema as a multipart payload.
@@ -225,9 +225,7 @@ export type MultipartStreamTypeId = typeof MultipartStreamTypeId
225
225
  /**
226
226
  * @since 4.0.0
227
227
  */
228
- export interface asMultipartStream<S extends Schema.Top>
229
- extends Schema.brand<S["~rebuild.out"], MultipartStreamTypeId>
230
- {}
228
+ export interface asMultipartStream<S extends Schema.Top> extends Schema.brand<S["Rebuild"], MultipartStreamTypeId> {}
231
229
 
232
230
  /**
233
231
  * Marks a schema as a multipart stream payload.
@@ -252,7 +250,7 @@ export function asMultipartStream(options?: Multipart_.withLimits.Options) {
252
250
  function asNonMultipartEncoding<S extends Schema.Top>(self: S, options: {
253
251
  readonly _tag: "Json" | "FormUrlEncoded" | "Uint8Array" | "Text"
254
252
  readonly contentType?: string | undefined
255
- }): S["~rebuild.out"] {
253
+ }): S["Rebuild"] {
256
254
  return self.annotate({
257
255
  "~httpApiEncoding": {
258
256
  _tag: options._tag,
@@ -61,6 +61,7 @@ export const make: (
61
61
  let disabledUntil: number | undefined = undefined
62
62
 
63
63
  const client = HttpClient.filterStatusOk(Context.get(services, HttpClient.HttpClient)).pipe(
64
+ HttpClient.transformResponse(Effect.provideService(HttpClient.TracerPropagationEnabled, false)),
64
65
  HttpClient.retryTransient({ schedule: policy, times: 3 })
65
66
  )
66
67
 
@@ -2201,7 +2201,7 @@ export const kvs = <S extends Schema.Codec<any, any>, const Mode extends "sync"
2201
2201
  */
2202
2202
  export const searchParam = <S extends Schema.Codec<any, string> = never>(name: string, options?: {
2203
2203
  readonly schema?: S | undefined
2204
- }): Writable<S extends never ? string : Option.Option<S["Type"]>> => {
2204
+ }): Writable<[S] extends [never] ? string : Option.Option<S["Type"]>> => {
2205
2205
  const decode = options?.schema && Schema.decodeExit(options.schema)
2206
2206
  const encode = options?.schema && Schema.encodeExit(options.schema)
2207
2207
  return writable(
@@ -179,10 +179,10 @@ export const Service = <Self>() =>
179
179
  Effect.fnUntraced(function*({ headers, payload, reactivityKeys }) {
180
180
  const client = yield* self
181
181
  const effect = client(tag, payload, { headers } as any)
182
- return yield* reactivityKeys
183
- ? Reactivity.mutation(effect, reactivityKeys)
184
- : effect
185
- }) as any
182
+ return yield* (reactivityKeys
183
+ ? Reactivity.mutation(effect, reactivityKeys) as Effect.Effect<any>
184
+ : effect as any as Effect.Effect<any>)
185
+ })
186
186
  ).pipe(
187
187
  Atom.serializable({
188
188
  key: `AtomRpc:mutation:${tag}`,
@@ -47,7 +47,7 @@ export interface Stream<A extends Schema.Top, E extends Schema.Top> extends
47
47
  Stream<A, E>
48
48
  >
49
49
  {
50
- readonly "~rebuild.out": this
50
+ readonly "Rebuild": Stream<A, E>
51
51
  readonly [StreamSchemaTypeId]: typeof StreamSchemaTypeId
52
52
  readonly success: A
53
53
  readonly error: E
@@ -580,7 +580,7 @@ export const fromWebSocket = <RO>(
580
580
  if (isCloseEvent(chunk)) {
581
581
  ws.close(chunk.code, chunk.reason)
582
582
  } else {
583
- ws.send(chunk)
583
+ ws.send(chunk as string | Uint8Array<ArrayBuffer>)
584
584
  }
585
585
  }))
586
586
  const writer = Effect.succeed(write)
@@ -89,8 +89,8 @@ export const getterAddAll = <A>(
89
89
  */
90
90
  export interface Transferable<S extends Schema.Top> extends
91
91
  Schema.decodeTo<
92
- Schema.toType<S["~rebuild.out"]>,
93
- S["~rebuild.out"]
92
+ Schema.toType<S["Rebuild"]>,
93
+ S["Rebuild"]
94
94
  >
95
95
  {}
96
96
 
@@ -316,7 +316,10 @@ export const make = <
316
316
  })
317
317
  },
318
318
  execute: Effect.fnUntraced(
319
- function*(fields: any, opts) {
319
+ function*<const Discard extends boolean = false>(
320
+ fields: any,
321
+ opts?: { readonly discard?: Discard } | undefined
322
+ ) {
320
323
  const payload = self.payloadSchema.make(fields)
321
324
  const engine = yield* EngineTag
322
325
  const executionId = yield* makeExecutionId(payload)
@@ -376,7 +379,7 @@ export const make = <
376
379
  ),
377
380
  executionId: (payload) =>
378
381
  Effect.flatMap(
379
- Effect.sync(() => self.payloadSchema.make(payload)),
382
+ Effect.orDie(self.payloadSchema.makeEffect(payload)),
380
383
  makeExecutionId
381
384
  ),
382
385
  withCompensation