effect 4.0.0-beta.75 → 4.0.0-beta.76

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 (95) hide show
  1. package/dist/Schema.d.ts +102 -40
  2. package/dist/Schema.d.ts.map +1 -1
  3. package/dist/Schema.js +149 -78
  4. package/dist/Schema.js.map +1 -1
  5. package/dist/SchemaAST.d.ts.map +1 -1
  6. package/dist/SchemaAST.js +2 -1
  7. package/dist/SchemaAST.js.map +1 -1
  8. package/dist/SchemaRepresentation.d.ts +10 -1
  9. package/dist/SchemaRepresentation.d.ts.map +1 -1
  10. package/dist/SchemaRepresentation.js +12 -5
  11. package/dist/SchemaRepresentation.js.map +1 -1
  12. package/dist/SchemaTransformation.d.ts.map +1 -1
  13. package/dist/SchemaTransformation.js +57 -18
  14. package/dist/SchemaTransformation.js.map +1 -1
  15. package/dist/internal/schema/representation.js +1 -0
  16. package/dist/internal/schema/representation.js.map +1 -1
  17. package/dist/unstable/ai/McpSchema.js +1 -1
  18. package/dist/unstable/ai/McpSchema.js.map +1 -1
  19. package/dist/unstable/cli/CliError.js +1 -1
  20. package/dist/unstable/cli/CliError.js.map +1 -1
  21. package/dist/unstable/cluster/ClusterError.js +2 -2
  22. package/dist/unstable/cluster/ClusterError.js.map +1 -1
  23. package/dist/unstable/cluster/Reply.js +1 -1
  24. package/dist/unstable/cluster/Reply.js.map +1 -1
  25. package/dist/unstable/devtools/DevToolsSchema.js +5 -1
  26. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  27. package/dist/unstable/http/HttpClientError.js +1 -1
  28. package/dist/unstable/http/HttpClientError.js.map +1 -1
  29. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -0
  30. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  31. package/dist/unstable/httpapi/HttpApiScalar.js +12 -6
  32. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  33. package/dist/unstable/persistence/Persistable.js +1 -1
  34. package/dist/unstable/persistence/Persistable.js.map +1 -1
  35. package/dist/unstable/persistence/PersistedQueue.js +1 -1
  36. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  37. package/dist/unstable/persistence/Persistence.js +1 -1
  38. package/dist/unstable/persistence/Persistence.js.map +1 -1
  39. package/dist/unstable/persistence/RateLimiter.js +1 -1
  40. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  41. package/dist/unstable/persistence/Redis.js +1 -1
  42. package/dist/unstable/persistence/Redis.js.map +1 -1
  43. package/dist/unstable/reactivity/AsyncResult.js +1 -1
  44. package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
  45. package/dist/unstable/rpc/Rpc.d.ts +1 -1
  46. package/dist/unstable/rpc/Rpc.js +2 -2
  47. package/dist/unstable/rpc/Rpc.js.map +1 -1
  48. package/dist/unstable/rpc/RpcClient.js +1 -1
  49. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  50. package/dist/unstable/rpc/RpcClientError.js +1 -1
  51. package/dist/unstable/rpc/RpcClientError.js.map +1 -1
  52. package/dist/unstable/rpc/RpcMessage.d.ts +2 -2
  53. package/dist/unstable/rpc/RpcMessage.js +3 -3
  54. package/dist/unstable/rpc/RpcMessage.js.map +1 -1
  55. package/dist/unstable/socket/Socket.js +3 -3
  56. package/dist/unstable/socket/Socket.js.map +1 -1
  57. package/dist/unstable/sql/SqlError.js +1 -1
  58. package/dist/unstable/sql/SqlError.js.map +1 -1
  59. package/dist/unstable/workers/WorkerError.js +4 -4
  60. package/dist/unstable/workers/WorkerError.js.map +1 -1
  61. package/dist/unstable/workflow/Activity.js +1 -1
  62. package/dist/unstable/workflow/Activity.js.map +1 -1
  63. package/dist/unstable/workflow/DurableDeferred.js +1 -1
  64. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  65. package/dist/unstable/workflow/Workflow.js +2 -2
  66. package/dist/unstable/workflow/Workflow.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/Schema.ts +179 -117
  69. package/src/SchemaAST.ts +3 -1
  70. package/src/SchemaRepresentation.ts +12 -4
  71. package/src/SchemaTransformation.ts +75 -25
  72. package/src/internal/schema/representation.ts +1 -0
  73. package/src/unstable/ai/McpSchema.ts +1 -1
  74. package/src/unstable/cli/CliError.ts +1 -1
  75. package/src/unstable/cluster/ClusterError.ts +2 -2
  76. package/src/unstable/cluster/Reply.ts +1 -1
  77. package/src/unstable/devtools/DevToolsSchema.ts +1 -1
  78. package/src/unstable/http/HttpClientError.ts +1 -1
  79. package/src/unstable/httpapi/HttpApiScalar.ts +14 -7
  80. package/src/unstable/persistence/Persistable.ts +1 -1
  81. package/src/unstable/persistence/PersistedQueue.ts +1 -1
  82. package/src/unstable/persistence/Persistence.ts +1 -1
  83. package/src/unstable/persistence/RateLimiter.ts +1 -1
  84. package/src/unstable/persistence/Redis.ts +1 -1
  85. package/src/unstable/reactivity/AsyncResult.ts +1 -1
  86. package/src/unstable/rpc/Rpc.ts +3 -3
  87. package/src/unstable/rpc/RpcClient.ts +1 -1
  88. package/src/unstable/rpc/RpcClientError.ts +1 -1
  89. package/src/unstable/rpc/RpcMessage.ts +3 -3
  90. package/src/unstable/socket/Socket.ts +3 -3
  91. package/src/unstable/sql/SqlError.ts +1 -1
  92. package/src/unstable/workers/WorkerError.ts +4 -4
  93. package/src/unstable/workflow/Activity.ts +1 -1
  94. package/src/unstable/workflow/DurableDeferred.ts +1 -1
  95. package/src/unstable/workflow/Workflow.ts +2 -2
@@ -80,6 +80,8 @@ export type ScalarConfig = {
80
80
  layout?: "modern" | "classic"
81
81
  /** URL to a request proxy for the API client */
82
82
  proxyUrl?: string
83
+ /** Browser JavaScript function expression used by Scalar for documents and test requests */
84
+ customFetch?: string
83
85
  /** Whether to show the sidebar */
84
86
  showSidebar?: boolean
85
87
  /**
@@ -179,9 +181,10 @@ const makeHandler = <Id extends string, Groups extends HttpApiGroup.Any>(options
179
181
  readonly scalar: ScalarConfig | undefined
180
182
  }) => {
181
183
  const spec = OpenApi.fromApi(options.api)
184
+ const { customFetch, ...scalar } = options.scalar ?? {}
182
185
  const scalarConfig = {
183
186
  _integration: "html",
184
- ...options.scalar
187
+ ...scalar
185
188
  }
186
189
  const response = HttpServerResponse.html(`<!doctype html>
187
190
  <html>
@@ -203,12 +206,7 @@ const makeHandler = <Id extends string, Groups extends HttpApiGroup.Any>(options
203
206
  content="width=device-width, initial-scale=1" />
204
207
  </head>
205
208
  <body>
206
- <script id="api-reference" type="application/json">
207
- ${Html.escapeJson(spec)}
208
- </script>
209
- <script>
210
- document.getElementById('api-reference').dataset.configuration = JSON.stringify(${Html.escapeJson(scalarConfig)})
211
- </script>
209
+ <div id="api-reference-container"></div>
212
210
  ${
213
211
  options.source._tag === "Cdn"
214
212
  ? `<script src="${`https://cdn.jsdelivr.net/npm/@scalar/api-reference@${
@@ -216,6 +214,15 @@ const makeHandler = <Id extends string, Groups extends HttpApiGroup.Any>(options
216
214
  }/dist/browser/standalone.min.js`}" crossorigin></script>`
217
215
  : `<script>${options.source.source}</script>`
218
216
  }
217
+ <script>
218
+ window.Scalar.createApiReference(document.getElementById('api-reference-container'), {
219
+ ...${Html.escapeJson(scalarConfig)},
220
+ content: ${Html.escapeJson(spec)}${
221
+ customFetch === undefined ? "" : `,
222
+ customFetch: ${customFetch}`
223
+ }
224
+ })
225
+ </script>
219
226
  </body>
220
227
  </html>`)
221
228
  return Effect.succeed(response)
@@ -224,7 +224,7 @@ export const exitSchema = <A extends Schema.Top, E extends Schema.Top>(
224
224
  ): Schema.Exit<A, E, Schema.Defect> => {
225
225
  let schema = exitSchemaCache.get(self)
226
226
  if (schema) return schema as Schema.Exit<A, E, Schema.Defect>
227
- schema = Schema.Exit(self[symbol].success, self[symbol].error, Schema.Defect)
227
+ schema = Schema.Exit(self[symbol].success, self[symbol].error, Schema.Defect())
228
228
  exitSchemaCache.set(self, schema)
229
229
  return schema as Schema.Exit<A, E, Schema.Defect>
230
230
  }
@@ -244,7 +244,7 @@ export class PersistedQueueError extends Schema.ErrorClass<PersistedQueueError>(
244
244
  )({
245
245
  _tag: Schema.tag("PersistedQueueError"),
246
246
  message: Schema.String,
247
- cause: Schema.optional(Schema.Defect)
247
+ cause: Schema.optional(Schema.Defect())
248
248
  }) {
249
249
  /**
250
250
  * Marks this value as a persisted queue error for runtime guards.
@@ -52,7 +52,7 @@ const ErrorTypeId = "~effect/persistence/Persistence/PersistenceError" as const
52
52
  export class PersistenceError extends Schema.ErrorClass<PersistenceError>(ErrorTypeId)({
53
53
  _tag: Schema.tag("PersistenceError"),
54
54
  message: Schema.String,
55
- cause: Schema.optional(Schema.Defect)
55
+ cause: Schema.optional(Schema.Defect())
56
56
  }) {
57
57
  /**
58
58
  * Marks this value as a persistence error for runtime guards.
@@ -396,7 +396,7 @@ export class RateLimitStoreError extends Schema.ErrorClass<RateLimitStoreError>(
396
396
  )({
397
397
  _tag: Schema.tag("RateLimitStoreError"),
398
398
  message: Schema.String,
399
- cause: Schema.optional(Schema.Defect)
399
+ cause: Schema.optional(Schema.Defect())
400
400
  }) {}
401
401
 
402
402
  /**
@@ -115,7 +115,7 @@ const ErrorTypeId: ErrorTypeId = "~effect/persistence/Redis/RedisError"
115
115
  */
116
116
  export class RedisError extends Schema.ErrorClass<RedisError>(ErrorTypeId)({
117
117
  _tag: Schema.tag("RedisError"),
118
- cause: Schema.Defect
118
+ cause: Schema.Defect()
119
119
  }) {
120
120
  /**
121
121
  * Marks this value as a Redis persistence error for runtime guards.
@@ -1129,7 +1129,7 @@ export const Schema = <
1129
1129
  AsyncResult<A["Type"], E["Type"]>,
1130
1130
  AsyncResult<A["Encoded"], E["Encoded"]>
1131
1131
  >()(
1132
- [success_, Schema_.Cause(error, Schema_.Defect)],
1132
+ [success_, Schema_.Cause(error, Schema_.Defect())],
1133
1133
  ([value, cause]) => (input, ast, options) => {
1134
1134
  if (!isAsyncResult(input)) {
1135
1135
  return Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(input)))
@@ -35,7 +35,7 @@
35
35
  * - Streaming RPCs store element and stream-error schemas in
36
36
  * `RpcSchema.Stream`; the immediate exit success is `void` and the ordinary
37
37
  * RPC error schema is `Schema.Never`
38
- * - Defects use a separate defect schema, defaulting to `Schema.Defect`; custom
38
+ * - Defects use a separate defect schema, defaulting to `Schema.Defect()`; custom
39
39
  * defect schemas must not require decoding or encoding services
40
40
  * - Schema services are directional: clients encode payloads and decode
41
41
  * responses, while servers decode payloads and encode responses
@@ -956,7 +956,7 @@ export const make = <
956
956
  > => {
957
957
  const successSchema = options?.success ?? Schema.Void
958
958
  const errorSchema = options?.error ?? Schema.Never
959
- const defectSchema = options?.defect ?? Schema.Defect
959
+ const defectSchema = options?.defect ?? Schema.Defect()
960
960
  let payloadSchema: any
961
961
  if (options?.primaryKey) {
962
962
  payloadSchema = class Payload extends Schema.Class<Payload>(`effect/rpc/Rpc/${tag}`)(options.payload as any) {
@@ -1058,7 +1058,7 @@ export const custom = <Def extends Custom>(
1058
1058
  > => {
1059
1059
  const success = options?.success ?? Schema.Void
1060
1060
  const error = options?.error ?? Schema.Never
1061
- const defect = options?.defect ?? Schema.Defect
1061
+ const defect = options?.defect ?? Schema.Defect()
1062
1062
  const out = f({
1063
1063
  success,
1064
1064
  error,
@@ -1407,4 +1407,4 @@ export class ConnectionHooks extends Context.Service<ConnectionHooks, {
1407
1407
 
1408
1408
  // internal
1409
1409
 
1410
- const decodeDefect = Schema.decodeSync(Schema.Defect)
1410
+ const decodeDefect = Schema.decodeSync(Schema.Defect())
@@ -48,7 +48,7 @@ const TypeId = "~effect/rpc/RpcClientError"
48
48
  export class RpcClientDefect extends Schema.ErrorClass<RpcClientDefect>("effect/rpc/RpcClientError/RpcClientDefect")({
49
49
  _tag: Schema.tag("RpcClientDefect"),
50
50
  message: Schema.String,
51
- cause: Schema.Defect
51
+ cause: Schema.Defect()
52
52
  }) {}
53
53
 
54
54
  /**
@@ -350,11 +350,11 @@ export interface ResponseDefectEncoded {
350
350
  readonly defect: unknown
351
351
  }
352
352
 
353
- const encodeDefect = Schema.encodeSync(Schema.Defect)
353
+ const encodeDefect = Schema.encodeSync(Schema.Defect())
354
354
 
355
355
  /**
356
356
  * Creates an encoded terminal response for a request whose exit is a defect
357
- * encoded with `Schema.Defect`.
357
+ * encoded with `Schema.Defect()`.
358
358
  *
359
359
  * @category response
360
360
  * @since 4.0.0
@@ -376,7 +376,7 @@ export const ResponseExitDieEncoded = (options: {
376
376
 
377
377
  /**
378
378
  * Creates a transport-encoded defect response by encoding the input with
379
- * `Schema.Defect`.
379
+ * `Schema.Defect()`.
380
380
  *
381
381
  * @category response
382
382
  * @since 4.0.0
@@ -237,7 +237,7 @@ export const isSocketError = (u: unknown): u is SocketError => Predicate.hasProp
237
237
  */
238
238
  export class SocketReadError extends Schema.ErrorClass<SocketReadError>("effect/socket/Socket/SocketReadError")({
239
239
  _tag: Schema.tag("SocketReadError"),
240
- cause: Schema.Defect
240
+ cause: Schema.Defect()
241
241
  }) {
242
242
  /**
243
243
  * Default message used for socket read failures.
@@ -255,7 +255,7 @@ export class SocketReadError extends Schema.ErrorClass<SocketReadError>("effect/
255
255
  */
256
256
  export class SocketWriteError extends Schema.ErrorClass<SocketWriteError>("effect/socket/Socket/SocketWriteError")({
257
257
  _tag: Schema.tag("SocketWriteError"),
258
- cause: Schema.Defect
258
+ cause: Schema.Defect()
259
259
  }) {
260
260
  /**
261
261
  * Default message used for socket write failures.
@@ -275,7 +275,7 @@ export class SocketWriteError extends Schema.ErrorClass<SocketWriteError>("effec
275
275
  export class SocketOpenError extends Schema.ErrorClass<SocketOpenError>("effect/socket/Socket/SocketOpenError")({
276
276
  _tag: Schema.tag("SocketOpenError"),
277
277
  kind: Schema.Literals(["Unknown", "Timeout"]),
278
- cause: Schema.Defect
278
+ cause: Schema.Defect()
279
279
  }) {
280
280
  /**
281
281
  * Formats timeout and unknown open failures for display.
@@ -42,7 +42,7 @@ const TypeId = "~effect/sql/SqlError" as const
42
42
  const ReasonTypeId = "~effect/sql/SqlError/Reason" as const
43
43
 
44
44
  const ReasonFields = {
45
- cause: Schema.Defect,
45
+ cause: Schema.Defect(),
46
46
  message: Schema.optional(Schema.String),
47
47
  operation: Schema.optional(Schema.String)
48
48
  }
@@ -68,7 +68,7 @@ export class WorkerSpawnError extends Schema.ErrorClass<WorkerSpawnError>(
68
68
  )({
69
69
  _tag: Schema.tag("WorkerSpawnError"),
70
70
  message: Schema.String,
71
- cause: Schema.optional(Schema.Defect)
71
+ cause: Schema.optional(Schema.Defect())
72
72
  }) {}
73
73
 
74
74
  /**
@@ -82,7 +82,7 @@ export class WorkerSendError extends Schema.ErrorClass<WorkerSendError>(
82
82
  )({
83
83
  _tag: Schema.tag("WorkerSendError"),
84
84
  message: Schema.String,
85
- cause: Schema.optional(Schema.Defect)
85
+ cause: Schema.optional(Schema.Defect())
86
86
  }) {}
87
87
 
88
88
  /**
@@ -97,7 +97,7 @@ export class WorkerReceiveError extends Schema.ErrorClass<WorkerReceiveError>(
97
97
  )({
98
98
  _tag: Schema.tag("WorkerReceiveError"),
99
99
  message: Schema.String,
100
- cause: Schema.optional(Schema.Defect)
100
+ cause: Schema.optional(Schema.Defect())
101
101
  }) {}
102
102
 
103
103
  /**
@@ -111,7 +111,7 @@ export class WorkerUnknownError extends Schema.ErrorClass<WorkerUnknownError>(
111
111
  )({
112
112
  _tag: Schema.tag("WorkerUnknownError"),
113
113
  message: Schema.String,
114
- cause: Schema.optional(Schema.Defect)
114
+ cause: Schema.optional(Schema.Defect())
115
115
  }) {}
116
116
 
117
117
  /**
@@ -165,7 +165,7 @@ export const make = <
165
165
  name: options.name,
166
166
  successSchema,
167
167
  errorSchema,
168
- exitSchema: Schema.Exit(successSchemaJson, errorSchemaJson, Schema.Defect),
168
+ exitSchema: Schema.Exit(successSchemaJson, errorSchemaJson, Schema.Defect()),
169
169
  annotations: options.annotations ?? Context.empty(),
170
170
  annotate(tag: Context.Key<any, any>, value: any) {
171
171
  return make({
@@ -113,7 +113,7 @@ export const make = <
113
113
  exitSchema: Schema.Exit(
114
114
  Schema.toCodecJson(successSchema),
115
115
  Schema.toCodecJson(errorSchema),
116
- Schema.toCodecJson(Schema.Defect)
116
+ Schema.toCodecJson(Schema.Defect())
117
117
  ) as any,
118
118
  withActivityAttempt: Effect.gen(function*() {
119
119
  const attempt = yield* CurrentAttempt
@@ -566,7 +566,7 @@ export class Complete<A, E> extends Data.TaggedClass("Complete")<{
566
566
  Complete<Success["Type"], Error["Type"]>,
567
567
  Complete<Success["Encoded"], Error["Encoded"]>
568
568
  >()(
569
- [Schema.Exit(options.success, options.error, Schema.Defect)],
569
+ [Schema.Exit(options.success, options.error, Schema.Defect())],
570
570
  ([exit]) => (input, ast, options) => {
571
571
  if (!(isResult(input) && input._tag === "Complete")) {
572
572
  return Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(input)))
@@ -618,7 +618,7 @@ export class Suspended extends Schema.Class<Suspended>(
618
618
  "effect/workflow/Workflow/Suspended"
619
619
  )({
620
620
  _tag: Schema.tag("Suspended"),
621
- cause: Schema.optional(Schema.Cause(Schema.Never, Schema.Defect))
621
+ cause: Schema.optional(Schema.Cause(Schema.Never, Schema.Defect()))
622
622
  }) {
623
623
  /**
624
624
  * Marks this value as a workflow result for runtime guards.