effect@4.0.0-beta.101.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. diff --git a/dist/unstable/httpapi/HttpApiSchema.js b/dist/unstable/httpapi/HttpApiSchema.js
  2. index c51851b..2100420 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 aae6cd5..f05e3ed 100644
  31. --- a/src/unstable/httpapi/HttpApiSchema.ts
  32. +++ b/src/unstable/httpapi/HttpApiSchema.ts
  33. @@ -407,7 +407,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. @@ -423,6 +423,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. *