effect@4.0.0-beta.83.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. diff --git a/dist/unstable/httpapi/HttpApiSchema.js b/dist/unstable/httpapi/HttpApiSchema.js
  2. index ecb6603d1ee4e89e92174b3a1100e8c9c720b3f3..08b832b6b3e9e4d10df156eca36b16f571f67f6e 100644
  3. --- a/dist/unstable/httpapi/HttpApiSchema.js
  4. +++ b/dist/unstable/httpapi/HttpApiSchema.js
  5. @@ -151,7 +151,7 @@ export const StreamSse = options => {
  6. const events = options.events ?? (options.data === undefined ? undefined : Schema.Struct({
  7. id: Schema.UndefinedOr(Schema.String),
  8. event: Schema.String,
  9. - data: Schema.fromJsonString(options.data)
  10. + data: sseDataJsonSchema(options.data)
  11. }));
  12. if (events === undefined) {
  13. throw new Error("StreamSse requires either an events schema or a data schema");
  14. @@ -166,6 +166,14 @@ export const StreamSse = options => {
  15. error: options.error ?? Schema.Never
  16. });
  17. };
  18. +const sseDataJsonSchema = data => {
  19. + const identifier = SchemaAST.resolveIdentifier(data.ast);
  20. + return identifier === undefined ? Schema.fromJsonString(data) : Schema.fromJsonString(data).annotate({
  21. + // The SSE transport field is a JSON string. Give that wrapper its own
  22. + // OpenAPI identifier so it does not claim the decoded data schema's name.
  23. + identifier: `${identifier}Stream`
  24. + });
  25. +};
  26. /**
  27. * Creates a streaming `Uint8Array` success response schema.
  28. *
  29. diff --git a/src/unstable/httpapi/HttpApiSchema.ts b/src/unstable/httpapi/HttpApiSchema.ts
  30. index f2920365cf0328146523ce2e2dba04d6a8809a4a..5482d635cdf01a72063ff683d244fab891910211 100644
  31. --- a/src/unstable/httpapi/HttpApiSchema.ts
  32. +++ b/src/unstable/httpapi/HttpApiSchema.ts
  33. @@ -433,7 +433,7 @@ export const StreamSse: {
  34. const events = options.events ?? (options.data === undefined ? undefined : Schema.Struct({
  35. id: Schema.UndefinedOr(Schema.String),
  36. event: Schema.String,
  37. - data: Schema.fromJsonString(options.data)
  38. + data: sseDataJsonSchema(options.data)
  39. }))
  40. if (events === undefined) {
  41. throw new Error("StreamSse requires either an events schema or a data schema")
  42. @@ -449,6 +449,15 @@ export const StreamSse: {
  43. })
  44. }
  45. +const sseDataJsonSchema = (data: Schema.Constraint) => {
  46. + const identifier = SchemaAST.resolveIdentifier(data.ast)
  47. + return identifier === undefined ? Schema.fromJsonString(data) : Schema.fromJsonString(data).annotate({
  48. + // The SSE transport field is a JSON string. Give that wrapper its own
  49. + // OpenAPI identifier so it does not claim the decoded data schema's name.
  50. + identifier: `${identifier}Stream`
  51. + })
  52. +}
  53. +
  54. /**
  55. * Creates a streaming `Uint8Array` success response schema.
  56. *