effect 4.0.0-beta.105 → 4.0.0-beta.106

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 (134) hide show
  1. package/dist/Config.js +3 -3
  2. package/dist/Config.js.map +1 -1
  3. package/dist/ConfigProvider.d.ts +35 -3
  4. package/dist/ConfigProvider.d.ts.map +1 -1
  5. package/dist/ConfigProvider.js +41 -8
  6. package/dist/ConfigProvider.js.map +1 -1
  7. package/dist/Fiber.d.ts +1 -1
  8. package/dist/Fiber.d.ts.map +1 -1
  9. package/dist/Function.d.ts +26 -0
  10. package/dist/Function.d.ts.map +1 -1
  11. package/dist/Function.js +36 -0
  12. package/dist/Function.js.map +1 -1
  13. package/dist/JsonSchema.d.ts.map +1 -1
  14. package/dist/JsonSchema.js +34 -17
  15. package/dist/JsonSchema.js.map +1 -1
  16. package/dist/Schema.d.ts +32 -84
  17. package/dist/Schema.d.ts.map +1 -1
  18. package/dist/Schema.js +58 -54
  19. package/dist/Schema.js.map +1 -1
  20. package/dist/SchemaAST.d.ts +2 -17
  21. package/dist/SchemaAST.d.ts.map +1 -1
  22. package/dist/SchemaAST.js +39 -28
  23. package/dist/SchemaAST.js.map +1 -1
  24. package/dist/SchemaRepresentation.d.ts +15 -3
  25. package/dist/SchemaRepresentation.d.ts.map +1 -1
  26. package/dist/SchemaRepresentation.js +8 -2
  27. package/dist/SchemaRepresentation.js.map +1 -1
  28. package/dist/ScopedRef.d.ts.map +1 -1
  29. package/dist/ScopedRef.js +1 -1
  30. package/dist/ScopedRef.js.map +1 -1
  31. package/dist/TxQueue.js +1 -1
  32. package/dist/TxQueue.js.map +1 -1
  33. package/dist/internal/effect.js +2 -4
  34. package/dist/internal/effect.js.map +1 -1
  35. package/dist/internal/executionPlan.js +3 -2
  36. package/dist/internal/executionPlan.js.map +1 -1
  37. package/dist/internal/rcRef.js +18 -13
  38. package/dist/internal/rcRef.js.map +1 -1
  39. package/dist/internal/schema/fromJsonSchemaDocument.js +10 -6
  40. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  41. package/dist/internal/schema/toArbitrary.d.ts +1 -4
  42. package/dist/internal/schema/toArbitrary.d.ts.map +1 -1
  43. package/dist/internal/schema/toArbitrary.js +0 -74
  44. package/dist/internal/schema/toArbitrary.js.map +1 -1
  45. package/dist/internal/schema/toJsonSchemaDocument.js +18 -4
  46. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  47. package/dist/internal/schema/toRepresentation.js +45 -43
  48. package/dist/internal/schema/toRepresentation.js.map +1 -1
  49. package/dist/testing/TestSchema.js +2 -2
  50. package/dist/testing/TestSchema.js.map +1 -1
  51. package/dist/unstable/ai/McpSchema.d.ts +110 -110
  52. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  53. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  54. package/dist/unstable/ai/McpServer.js +23 -11
  55. package/dist/unstable/ai/McpServer.js.map +1 -1
  56. package/dist/unstable/ai/Prompt.d.ts +4 -3
  57. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  58. package/dist/unstable/ai/Prompt.js +38 -13
  59. package/dist/unstable/ai/Prompt.js.map +1 -1
  60. package/dist/unstable/cluster/Entity.d.ts +2 -2
  61. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  62. package/dist/unstable/cluster/Entity.js.map +1 -1
  63. package/dist/unstable/cluster/EntityProxy.d.ts +3 -3
  64. package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
  65. package/dist/unstable/cluster/EntityProxy.js +4 -3
  66. package/dist/unstable/cluster/EntityProxy.js.map +1 -1
  67. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  68. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  69. package/dist/unstable/cluster/Sharding.js +14 -5
  70. package/dist/unstable/cluster/Sharding.js.map +1 -1
  71. package/dist/unstable/eventlog/EventLogEncryption.d.ts +6 -5
  72. package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
  73. package/dist/unstable/eventlog/EventLogEncryption.js +14 -12
  74. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  75. package/dist/unstable/eventlog/EventLogMessage.d.ts +3 -3
  76. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  77. package/dist/unstable/eventlog/EventLogMessage.js +2 -3
  78. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  79. package/dist/unstable/eventlog/EventLogRemote.js +4 -4
  80. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  81. package/dist/unstable/eventlog/EventLogServerEncrypted.js +3 -2
  82. package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
  83. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  84. package/dist/unstable/http/HttpServerRequest.js +7 -1
  85. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  86. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
  87. package/dist/unstable/http/MultipartParser/internal/multipart.js +18 -6
  88. package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
  89. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  90. package/dist/unstable/httpapi/OpenApi.js +1 -1
  91. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  92. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  93. package/dist/unstable/rpc/RpcClient.js +5 -0
  94. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  95. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  96. package/dist/unstable/sql/SqlResolver.js +20 -16
  97. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  98. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  99. package/dist/unstable/workers/Worker.js +11 -12
  100. package/dist/unstable/workers/Worker.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/Config.ts +3 -3
  103. package/src/ConfigProvider.ts +43 -8
  104. package/src/Fiber.ts +1 -1
  105. package/src/Function.ts +37 -0
  106. package/src/JsonSchema.ts +43 -42
  107. package/src/Schema.ts +68 -146
  108. package/src/SchemaAST.ts +50 -30
  109. package/src/SchemaRepresentation.ts +15 -3
  110. package/src/ScopedRef.ts +3 -1
  111. package/src/TxQueue.ts +1 -1
  112. package/src/internal/effect.ts +3 -6
  113. package/src/internal/executionPlan.ts +3 -2
  114. package/src/internal/rcRef.ts +24 -16
  115. package/src/internal/schema/fromJsonSchemaDocument.ts +19 -14
  116. package/src/internal/schema/toArbitrary.ts +0 -72
  117. package/src/internal/schema/toJsonSchemaDocument.ts +24 -4
  118. package/src/internal/schema/toRepresentation.ts +66 -48
  119. package/src/testing/TestSchema.ts +2 -2
  120. package/src/unstable/ai/McpServer.ts +23 -11
  121. package/src/unstable/ai/Prompt.ts +37 -15
  122. package/src/unstable/cluster/Entity.ts +7 -2
  123. package/src/unstable/cluster/EntityProxy.ts +12 -5
  124. package/src/unstable/cluster/Sharding.ts +29 -17
  125. package/src/unstable/eventlog/EventLogEncryption.ts +15 -16
  126. package/src/unstable/eventlog/EventLogMessage.ts +2 -3
  127. package/src/unstable/eventlog/EventLogRemote.ts +4 -4
  128. package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -2
  129. package/src/unstable/http/HttpServerRequest.ts +8 -3
  130. package/src/unstable/http/MultipartParser/internal/multipart.ts +19 -6
  131. package/src/unstable/httpapi/OpenApi.ts +4 -1
  132. package/src/unstable/rpc/RpcClient.ts +5 -0
  133. package/src/unstable/sql/SqlResolver.ts +28 -20
  134. package/src/unstable/workers/Worker.ts +13 -14
@@ -67,10 +67,10 @@ export const layerRpcHandlers = Layer.unwrap(Effect.gen(function*() {
67
67
  })
68
68
  }
69
69
  if (request.encryptedEntries.length === 0) return
70
- const entries = request.encryptedEntries.map(({ encryptedEntry, entryId }) =>
70
+ const entries = request.encryptedEntries.map(({ encryptedEntry, entryId, iv }) =>
71
71
  new PersistedEntry({
72
72
  entryId,
73
- iv: request.iv,
73
+ iv,
74
74
  encryptedEntry
75
75
  })
76
76
  )
@@ -436,14 +436,19 @@ export const toClientRequest = (request: HttpServerRequest): HttpClientRequest.H
436
436
  Option.getOrElse(toURL(request), () => request.url)
437
437
  )
438
438
 
439
- const toClientBody = (request: HttpServerRequest): HttpBody.HttpBody =>
440
- hasBody(request.method)
439
+ const toClientBody = (request: HttpServerRequest): HttpBody.HttpBody => {
440
+ if (!hasBody(request.method)) {
441
+ return HttpBody.empty
442
+ }
443
+ const formData = getFormDataBody(request)
444
+ return formData === undefined
441
445
  ? HttpBody.stream(
442
446
  request.stream,
443
447
  request.headers["content-type"],
444
448
  parseContentLength(request.headers["content-length"])
445
449
  )
446
- : HttpBody.empty
450
+ : HttpBody.formData(formData)
451
+ }
447
452
 
448
453
  const parseContentLength = (contentLength: string | undefined): number | undefined => {
449
454
  if (contentLength === undefined) {
@@ -74,7 +74,8 @@ export function make({
74
74
  isFile: false,
75
75
  fieldChunks: [] as Array<Uint8Array>,
76
76
  fieldSize: 0,
77
- done: false
77
+ done: false,
78
+ stopped: false
78
79
  }
79
80
 
80
81
  function skipBody() {
@@ -88,6 +89,10 @@ export function make({
88
89
  const split = Search.make(
89
90
  `\r\n--${boundary}`,
90
91
  function(index, chunk) {
92
+ if (state.stopped) {
93
+ return
94
+ }
95
+
91
96
  if (index === 0) {
92
97
  // data before the first boundary
93
98
  skipBody()
@@ -127,12 +132,14 @@ export function make({
127
132
 
128
133
  state.parts++
129
134
  if (state.parts > maxParts) {
130
- onError(errMaxParts)
135
+ state.stopped = true
136
+ return onError(errMaxParts)
131
137
  }
132
138
  }
133
139
 
134
140
  if ((state.partSize += chunk.length) > maxPartSize) {
135
- onError(errMaxPartSize)
141
+ state.stopped = true
142
+ return onError(errMaxPartSize)
136
143
  }
137
144
 
138
145
  if (state.state === State.headers) {
@@ -199,7 +206,8 @@ export function make({
199
206
  } else {
200
207
  const buf = chunk.subarray(result.endPosition)
201
208
  if ((state.fieldSize += buf.length) > maxFieldSize) {
202
- onError(errMaxFieldSize)
209
+ state.stopped = true
210
+ return onError(errMaxFieldSize)
203
211
  }
204
212
  state.fieldChunks.push(buf)
205
213
  }
@@ -208,7 +216,8 @@ export function make({
208
216
  state.onChunk(chunk)
209
217
  } else {
210
218
  if ((state.fieldSize += chunk.length) > maxFieldSize) {
211
- onError(errMaxFieldSize)
219
+ state.stopped = true
220
+ return onError(errMaxFieldSize)
212
221
  }
213
222
  state.fieldChunks.push(chunk)
214
223
  }
@@ -219,6 +228,9 @@ export function make({
219
228
 
220
229
  return {
221
230
  write(chunk: Uint8Array) {
231
+ if (state.stopped) {
232
+ return
233
+ }
222
234
  if ((state.totalSize += chunk.length) > maxTotalSize) {
223
235
  return onError(errMaxTotalSize)
224
236
  }
@@ -226,7 +238,7 @@ export function make({
226
238
  },
227
239
  end() {
228
240
  split.end()
229
- if (!state.done) {
241
+ if (!state.done && !state.stopped) {
230
242
  onError(errEndNotReached)
231
243
  }
232
244
 
@@ -240,6 +252,7 @@ export function make({
240
252
  state.fieldChunks = []
241
253
  state.fieldSize = 0
242
254
  state.done = false
255
+ state.stopped = false
243
256
  }
244
257
  } as const
245
258
  }
@@ -220,7 +220,10 @@ type CompileSchemas = (
220
220
  const compileSchemas: CompileSchemas = (asts) =>
221
221
  JsonSchema.toMultiDocumentOpenApi3_1(
222
222
  InternalToJsonSchemaDocument.toJsonSchemaMultiDocument(
223
- InternalToRepresentation.toRepresentations(Arr.map(asts, Schema.toCodecJsonAST))
223
+ InternalToRepresentation.toRepresentations(
224
+ Arr.map(asts, Schema.toCodecJsonAST),
225
+ InternalToJsonSchemaDocument.toRepresentationOptions
226
+ )
224
227
  )
225
228
  )
226
229
 
@@ -1299,6 +1299,11 @@ export const makeProtocolWorker = (
1299
1299
  undefined
1300
1300
  }).pipe(
1301
1301
  Effect.tapCause((cause) => {
1302
+ for (const [requestId, entry] of entries) {
1303
+ if (entry.worker !== backing) continue
1304
+ entries.delete(requestId)
1305
+ entry.latch.openUnsafe()
1306
+ }
1302
1307
  const error = Cause.findError(cause)
1303
1308
  return broadcast({
1304
1309
  _tag: "ClientProtocolError",
@@ -134,7 +134,8 @@ export const ordered = <Req extends Schema.Constraint, Res extends Schema.Constr
134
134
  key: transactionKey,
135
135
  resolver: Effect.fnUntraced(function*(entries) {
136
136
  const [inputs, encodedEntries] = yield* partitionRequests(entries, options.Request)
137
- const results = yield* options.execute(inputs as any).pipe(
137
+ if (!Arr.isArrayNonEmpty(inputs)) return
138
+ const results = yield* options.execute(inputs).pipe(
138
139
  Effect.provideContext(entries[0].context)
139
140
  )
140
141
  if (results.length !== inputs.length) {
@@ -190,8 +191,9 @@ export const grouped = <Req extends Schema.Constraint, Res extends Schema.Constr
190
191
  key: transactionKey,
191
192
  resolver: Effect.fnUntraced(function*(entries) {
192
193
  const [inputs] = yield* partitionRequests(entries, options.Request)
194
+ if (!Arr.isArrayNonEmpty(inputs)) return
193
195
  const resultMap = MutableHashMap.empty<K, Arr.NonEmptyArray<Res["Type"]>>()
194
- const results = yield* options.execute(inputs as any).pipe(
196
+ const results = yield* options.execute(inputs).pipe(
195
197
  Effect.provideContext(entries[0].context)
196
198
  )
197
199
  const decodedResults = yield* decodeResults(results).pipe(
@@ -258,7 +260,8 @@ export const findById = <Id extends Schema.Constraint, Res extends Schema.Constr
258
260
  key: transactionKey,
259
261
  resolver: Effect.fnUntraced(function*(entries) {
260
262
  const [inputs, idMap] = yield* partitionRequestsById(entries, options.Id)
261
- const results = yield* options.execute(inputs as any).pipe(
263
+ if (!Arr.isArrayNonEmpty(inputs)) return
264
+ const results = yield* options.execute(inputs).pipe(
262
265
  Effect.provideContext(entries[0].context)
263
266
  )
264
267
  const decodedResults = yield* decodeResults(results).pipe(
@@ -311,7 +314,8 @@ const void_ = <Req extends Schema.Constraint, _, E, R>(
311
314
  key: transactionKey,
312
315
  resolver: Effect.fnUntraced(function*(entries) {
313
316
  const [inputs] = yield* partitionRequests(entries, options.Request)
314
- yield* options.execute(inputs as any).pipe(
317
+ if (!Arr.isArrayNonEmpty(inputs)) return
318
+ yield* options.execute(inputs).pipe(
315
319
  Effect.provideContext(entries[0].context)
316
320
  )
317
321
  for (let i = 0; i < entries.length; i++) {
@@ -366,35 +370,39 @@ const partitionRequestsById = function*<In, A, E, R, InE>(
366
370
  const len = requests.length
367
371
  const inputs = Arr.empty<InE>()
368
372
  const byIdMap = MutableHashMap.empty<In, Request.Entry<SqlRequest<In, A, E, R>>>()
369
- let entry!: Request.Entry<SqlRequest<In, A, E, R>>
370
- const encode = Schema.encodeEffect(schema)
371
- const handle = Effect.matchCauseEager({
372
- onFailure(cause: Cause.Cause<Schema.SchemaError>) {
373
- entry.completeUnsafe(Exit.failCause(cause))
374
- },
375
- onSuccess(value: InE) {
376
- inputs.push(value)
377
- }
378
- })
379
373
 
380
374
  for (let i = 0; i < len; i++) {
381
- entry = requests[i]
375
+ const entry = requests[i]
382
376
  const existing = MutableHashMap.get(byIdMap, entry.request.payload)
383
377
  if (Option.isSome(existing)) {
384
- const duplicate = entry
378
+ const previous = existing.value
385
379
  MutableHashMap.set(byIdMap, entry.request.payload, {
386
- ...existing.value,
380
+ ...previous,
387
381
  completeUnsafe(exit) {
388
- existing.value.completeUnsafe(exit)
389
- duplicate.completeUnsafe(exit)
382
+ previous.completeUnsafe(exit)
383
+ entry.completeUnsafe(exit)
390
384
  }
391
385
  })
392
386
  } else {
393
- yield (Effect.provideContext(handle(encode(entry.request.payload)), entry.context) as Effect.Effect<void>)
394
387
  MutableHashMap.set(byIdMap, entry.request.payload, entry)
395
388
  }
396
389
  }
397
390
 
391
+ const encode = Schema.encodeEffect(schema)
392
+ for (const [, entry] of byIdMap) {
393
+ yield* Effect.provideContext(
394
+ Effect.matchCauseEager(encode(entry.request.payload), {
395
+ onFailure(cause) {
396
+ entry.completeUnsafe(Exit.failCause(cause))
397
+ },
398
+ onSuccess(value) {
399
+ inputs.push(value)
400
+ }
401
+ }),
402
+ entry.context
403
+ )
404
+ }
405
+
398
406
  return [inputs, byIdMap] as const
399
407
  }
400
408
 
@@ -165,6 +165,17 @@ export const makePlatform = <W>() =>
165
165
  const spawn = (yield* Spawner) as SpawnerFn<W>
166
166
  let currentPort: P | undefined
167
167
  const buffer: Array<[unknown, ReadonlyArray<unknown> | undefined]> = []
168
+ const sendToPort = (port: P, message: unknown, transfers?: ReadonlyArray<unknown>) =>
169
+ Effect.try({
170
+ try: () => port.postMessage([0, message], transfers as any),
171
+ catch: (cause) =>
172
+ new WorkerError({
173
+ reason: new WorkerSendError({
174
+ message: "Failed to send message to worker",
175
+ cause
176
+ })
177
+ })
178
+ })
168
179
 
169
180
  const run = <A, E, R>(
170
181
  handler: (_: O) => Effect.Effect<A, E, R>,
@@ -209,7 +220,7 @@ export const makePlatform = <W>() =>
209
220
  currentPort = port
210
221
  if (buffer.length > 0) {
211
222
  for (const [message, transfers] of buffer) {
212
- port.postMessage([0, message], transfers as any)
223
+ yield* sendToPort(port, message, transfers)
213
224
  }
214
225
  buffer.length = 0
215
226
  }
@@ -224,19 +235,7 @@ export const makePlatform = <W>() =>
224
235
  buffer.push([message, transfers])
225
236
  return Effect.void
226
237
  }
227
- try {
228
- currentPort.postMessage([0, message], transfers as any)
229
- return Effect.void
230
- } catch (cause) {
231
- return Effect.fail(
232
- new WorkerError({
233
- reason: new WorkerSendError({
234
- message: "Failed to send message to worker",
235
- cause
236
- })
237
- })
238
- )
239
- }
238
+ return sendToPort(currentPort, message, transfers)
240
239
  })
241
240
 
242
241
  return { run, send }