effect 4.1.6 → 4.1.7
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.
- package/dist/Config.d.ts +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +5 -3
- package/dist/Config.js.map +1 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +79 -31
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +10 -9
- package/dist/Cron.js.map +1 -1
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +2 -3
- package/dist/Equal.js.map +1 -1
- package/dist/Formatter.js +4 -4
- package/dist/Formatter.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +13 -27
- package/dist/Hash.js.map +1 -1
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +3 -4
- package/dist/Metric.js.map +1 -1
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +49 -21
- package/dist/Pool.js.map +1 -1
- package/dist/Predicate.d.ts.map +1 -1
- package/dist/Predicate.js +2 -1
- package/dist/Predicate.js.map +1 -1
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +15 -9
- package/dist/Scheduler.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -2
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +199 -95
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +29 -50
- package/dist/SchemaParser.js.map +1 -1
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +1 -4
- package/dist/Tracer.js.map +1 -1
- package/dist/ai/McpClient.d.ts +68 -4
- package/dist/ai/McpClient.d.ts.map +1 -1
- package/dist/ai/McpClient.js +100 -17
- package/dist/ai/McpClient.js.map +1 -1
- package/dist/ai/McpClientError.d.ts +46 -4
- package/dist/ai/McpClientError.d.ts.map +1 -1
- package/dist/ai/McpClientError.js +38 -3
- package/dist/ai/McpClientError.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +88 -88
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpServer.d.ts +6 -5
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +95 -47
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
- package/dist/ai/internal/mcpProtocol.js +11 -0
- package/dist/ai/internal/mcpProtocol.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +29 -17
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
- package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
- package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
- package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
- package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
- package/dist/cluster/ClusterCron.d.ts +5 -20
- package/dist/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/cluster/ClusterCron.js +16 -4
- package/dist/cluster/ClusterCron.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +3 -1
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/encoding/Hex.js +7 -5
- package/dist/encoding/Hex.js.map +1 -1
- package/dist/http/HttpEffect.d.ts.map +1 -1
- package/dist/http/HttpEffect.js +31 -2
- package/dist/http/HttpEffect.js.map +1 -1
- package/dist/http/HttpServerError.d.ts +1 -1
- package/dist/http/HttpServerError.js +1 -1
- package/dist/internal/core.js +60 -43
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/effect.js +51 -51
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +30 -0
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/fiberCachedKeys.d.ts +2 -0
- package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
- package/dist/internal/fiberCachedKeys.js +48 -0
- package/dist/internal/fiberCachedKeys.js.map +1 -0
- package/dist/internal/hashMap.js +1 -1
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/predicate.d.ts +2 -0
- package/dist/internal/predicate.d.ts.map +1 -0
- package/dist/internal/predicate.js +10 -0
- package/dist/internal/predicate.js.map +1 -0
- package/dist/internal/references.js +8 -11
- package/dist/internal/references.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/sql/Statement.d.ts +23 -0
- package/dist/sql/Statement.d.ts.map +1 -1
- package/dist/sql/Statement.js +30 -5
- package/dist/sql/Statement.js.map +1 -1
- package/dist/workers/Worker.d.ts +21 -0
- package/dist/workers/Worker.d.ts.map +1 -1
- package/dist/workers/Worker.js +23 -0
- package/dist/workers/Worker.js.map +1 -1
- package/package.json +1 -1
- package/src/Config.ts +6 -3
- package/src/Context.ts +108 -50
- package/src/Cron.ts +11 -10
- package/src/Equal.ts +10 -3
- package/src/Formatter.ts +4 -4
- package/src/Hash.ts +24 -31
- package/src/Metric.ts +4 -4
- package/src/Pool.ts +62 -33
- package/src/Predicate.ts +2 -5
- package/src/Scheduler.ts +27 -10
- package/src/SchemaAST.ts +231 -156
- package/src/SchemaParser.ts +40 -57
- package/src/Tracer.ts +1 -2
- package/src/ai/McpClient.ts +157 -15
- package/src/ai/McpClientError.ts +55 -4
- package/src/ai/McpServer.ts +157 -87
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
- package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
- package/src/ai/internal/mcpProtocol.ts +15 -0
- package/src/ai/internal/mcpRuntime.ts +36 -13
- package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
- package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
- package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
- package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
- package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
- package/src/cluster/ClusterCron.ts +31 -20
- package/src/cluster/SqlMessageStorage.ts +7 -2
- package/src/encoding/Hex.ts +5 -5
- package/src/http/HttpEffect.ts +23 -3
- package/src/http/HttpServerError.ts +1 -1
- package/src/internal/core.ts +80 -44
- package/src/internal/effect.ts +84 -55
- package/src/internal/equal.ts +36 -0
- package/src/internal/fiberCachedKeys.ts +81 -0
- package/src/internal/hashMap.ts +1 -1
- package/src/internal/predicate.ts +10 -0
- package/src/internal/references.ts +21 -14
- package/src/internal/version.ts +1 -1
- package/src/sql/Statement.ts +48 -12
- package/src/workers/Worker.ts +25 -0
- package/dist/internal/hash.d.ts +0 -2
- package/dist/internal/hash.d.ts.map +0 -1
- package/dist/internal/hash.js +0 -14
- package/dist/internal/hash.js.map +0 -1
- package/dist/internal/metric.d.ts +0 -2
- package/dist/internal/metric.d.ts.map +0 -1
- package/dist/internal/metric.js +0 -3
- package/dist/internal/metric.js.map +0 -1
- package/src/internal/hash.ts +0 -15
- package/src/internal/metric.ts +0 -2
|
@@ -61,6 +61,12 @@ const routingNameKey = (method: string): "name" | "uri" | undefined => {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export const jsonRpcError = (status: number, error: unknown, id: string | number | null = null) =>
|
|
68
|
+
HttpServerResponse.jsonUnsafe({ jsonrpc: "2.0", id, error }, { status })
|
|
69
|
+
|
|
64
70
|
const headerMismatch = (message: string): HttpProtocolSelection => ({
|
|
65
71
|
_tag: "Rejected",
|
|
66
72
|
status: 400,
|
|
@@ -97,11 +103,11 @@ type HttpProtocolSelection =
|
|
|
97
103
|
| {
|
|
98
104
|
readonly _tag: "Rejected"
|
|
99
105
|
readonly status: 400 | 404
|
|
100
|
-
readonly error
|
|
106
|
+
readonly error: {
|
|
101
107
|
readonly code: number
|
|
102
108
|
readonly message: string
|
|
103
109
|
readonly data?: unknown
|
|
104
|
-
}
|
|
110
|
+
}
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
/**
|
|
@@ -241,7 +247,7 @@ export const make = Effect.fnUntraced(function*(
|
|
|
241
247
|
const sessionTerminationListeners = new Set<(binding: RequestBinding) => Effect.Effect<void>>()
|
|
242
248
|
const unsupportedProtocolVersion = (requested: string) => ({
|
|
243
249
|
code: PublicMcpSchema.UNSUPPORTED_PROTOCOL_VERSION_ERROR_CODE,
|
|
244
|
-
message: `Unsupported protocol version '${requested}'`,
|
|
250
|
+
message: `Unsupported protocol version '${requested}'; supported versions: ${protocolVersions.join(", ")}`,
|
|
245
251
|
data: { supported: protocolVersions, requested }
|
|
246
252
|
})
|
|
247
253
|
const selectHttpSession = (headers: Headers.Headers, isInitialize: boolean): HttpProtocolSelection => {
|
|
@@ -249,7 +255,15 @@ export const make = Effect.fnUntraced(function*(
|
|
|
249
255
|
const sessionId = headers[MCP_SESSION_ID_HEADER]
|
|
250
256
|
const binding = sessionId === undefined ? undefined : stateful?.resolveSessionId(sessionId)
|
|
251
257
|
if (sessionId !== undefined && binding === undefined) {
|
|
252
|
-
return {
|
|
258
|
+
return {
|
|
259
|
+
_tag: "Rejected",
|
|
260
|
+
status: 404,
|
|
261
|
+
error: {
|
|
262
|
+
code: PublicMcpSchema.INVALID_REQUEST_ERROR_CODE,
|
|
263
|
+
message:
|
|
264
|
+
"Unknown or expired MCP-Session-Id; send initialize without an MCP-Session-Id header to start a new session"
|
|
265
|
+
}
|
|
266
|
+
}
|
|
253
267
|
}
|
|
254
268
|
if (!isInitialize && protocolVersion !== undefined) {
|
|
255
269
|
if (!protocolVersions.includes(protocolVersion)) {
|
|
@@ -266,6 +280,8 @@ export const make = Effect.fnUntraced(function*(
|
|
|
266
280
|
}
|
|
267
281
|
return { _tag: "Accepted", binding, protocol: binding?.protocol }
|
|
268
282
|
}
|
|
283
|
+
const isStatelessVersion = (headers: Headers.Headers) =>
|
|
284
|
+
statelessProtocol !== undefined && headers[MCP_PROTOCOL_VERSION_HEADER] === statelessProtocol.protocolVersion
|
|
269
285
|
const selectHttpProtocol = (headers: Headers.Headers, input: unknown): HttpProtocolSelection => {
|
|
270
286
|
const protocolVersion = headers[MCP_PROTOCOL_VERSION_HEADER]
|
|
271
287
|
const inputRecord = asRecord(input)
|
|
@@ -395,18 +411,17 @@ export const make = Effect.fnUntraced(function*(
|
|
|
395
411
|
_tag: "Rejected",
|
|
396
412
|
response: error === undefined
|
|
397
413
|
? HttpServerResponse.empty({ status })
|
|
398
|
-
:
|
|
414
|
+
: jsonRpcError(status, error, id)
|
|
399
415
|
})
|
|
400
416
|
if (Result.isFailure(parsed)) {
|
|
401
417
|
const version = headers[MCP_PROTOCOL_VERSION_HEADER]
|
|
402
418
|
if (version !== undefined && !protocolVersions.includes(version)) {
|
|
403
419
|
return reject(400, unsupportedProtocolVersion(version))
|
|
404
420
|
}
|
|
405
|
-
const admission = selectHttpProtocol(headers, undefined)
|
|
406
421
|
// Session and protocol-header errors take precedence over parse errors.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
? reject(
|
|
422
|
+
const selection = isStatelessVersion(headers) ? undefined : selectHttpSession(headers, false)
|
|
423
|
+
return selection?._tag === "Rejected"
|
|
424
|
+
? reject(selection.status, selection.error)
|
|
410
425
|
: reject(200, new PublicMcpSchema.ParseError({ message: "Parse error" }))
|
|
411
426
|
}
|
|
412
427
|
const input = parsed.success
|
|
@@ -414,14 +429,22 @@ export const make = Effect.fnUntraced(function*(
|
|
|
414
429
|
if (input.length === 0) {
|
|
415
430
|
return reject(400, new PublicMcpSchema.InvalidRequest({ message: "Invalid Request" }))
|
|
416
431
|
}
|
|
417
|
-
const admission =
|
|
432
|
+
const admission = selectHttpSession(headers, false)
|
|
433
|
+
if (admission._tag === "Rejected") {
|
|
434
|
+
return reject(admission.status, admission.error)
|
|
435
|
+
}
|
|
418
436
|
if (
|
|
419
|
-
|
|
437
|
+
isStatelessVersion(headers) ||
|
|
420
438
|
input.some(hasRequestProtocolVersion) ||
|
|
421
439
|
input.some((message) => Predicate.hasProperty(message, "method") && message.method === "initialize") ||
|
|
422
440
|
admission.binding?.protocol.runtime.transport.jsonRpc.acceptsBatches !== true
|
|
423
441
|
) {
|
|
424
|
-
return reject(
|
|
442
|
+
return reject(
|
|
443
|
+
400,
|
|
444
|
+
new PublicMcpSchema.InvalidRequest({
|
|
445
|
+
message: "JSON-RPC batches are not supported; send each message in its own POST request"
|
|
446
|
+
})
|
|
447
|
+
)
|
|
425
448
|
}
|
|
426
449
|
return {
|
|
427
450
|
_tag: "Accepted",
|
|
@@ -492,7 +515,7 @@ export const make = Effect.fnUntraced(function*(
|
|
|
492
515
|
}
|
|
493
516
|
const selection = selectHttpSession(headers, false)
|
|
494
517
|
if (selection._tag === "Rejected") {
|
|
495
|
-
return Effect.succeed(
|
|
518
|
+
return Effect.succeed(jsonRpcError(selection.status, selection.error))
|
|
496
519
|
}
|
|
497
520
|
const binding = selection.binding!
|
|
498
521
|
stateful!.terminateSession(sessionId)
|
|
@@ -408,7 +408,8 @@ export const GetPromptResult = Schema.Struct({
|
|
|
408
408
|
*/
|
|
409
409
|
export const ListToolsResult = Schema.Struct({
|
|
410
410
|
...PaginatedResult.fields,
|
|
411
|
-
|
|
411
|
+
// Already JSON-encoded by the protocol adapter.
|
|
412
|
+
tools: Schema.Any
|
|
412
413
|
})
|
|
413
414
|
|
|
414
415
|
/**
|
|
@@ -113,14 +113,6 @@ export const GetPromptResult = Schema.Struct({
|
|
|
113
113
|
messages: Schema.Array(PromptMessage)
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
-
/**
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
export const ListToolsResult = Schema.Struct({
|
|
120
|
-
...Previous.PaginatedResult.fields,
|
|
121
|
-
tools: Schema.Array(Tool)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
116
|
/**
|
|
125
117
|
* @internal
|
|
126
118
|
*/
|
|
@@ -172,7 +164,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
|
|
|
172
164
|
* @internal
|
|
173
165
|
*/
|
|
174
166
|
export class ListTools extends Rpc.make("tools/list", {
|
|
175
|
-
success: ListToolsResult,
|
|
167
|
+
success: Previous.ListToolsResult,
|
|
176
168
|
error: Previous.McpError,
|
|
177
169
|
payload: Schema.UndefinedOr(Previous.PaginatedRequest)
|
|
178
170
|
}) {}
|
|
@@ -356,14 +356,6 @@ export const GetPromptResult = Schema.Struct({
|
|
|
356
356
|
messages: Schema.Array(PromptMessage)
|
|
357
357
|
})
|
|
358
358
|
|
|
359
|
-
/**
|
|
360
|
-
* @internal
|
|
361
|
-
*/
|
|
362
|
-
export const ListToolsResult = Schema.Struct({
|
|
363
|
-
...Previous.PaginatedResult.fields,
|
|
364
|
-
tools: Schema.Array(Tool)
|
|
365
|
-
})
|
|
366
|
-
|
|
367
359
|
/**
|
|
368
360
|
* @internal
|
|
369
361
|
*/
|
|
@@ -417,7 +409,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
|
|
|
417
409
|
* @internal
|
|
418
410
|
*/
|
|
419
411
|
export class ListTools extends Rpc.make("tools/list", {
|
|
420
|
-
success: ListToolsResult,
|
|
412
|
+
success: Previous.ListToolsResult,
|
|
421
413
|
error: Previous.McpError,
|
|
422
414
|
payload: Schema.UndefinedOr(Previous.PaginatedRequest)
|
|
423
415
|
}) {}
|
|
@@ -479,7 +471,8 @@ const RequestedSchema = Schema.Struct({
|
|
|
479
471
|
type: Schema.Literal("object"),
|
|
480
472
|
properties: Schema.Record(
|
|
481
473
|
Schema.String,
|
|
482
|
-
|
|
474
|
+
// EnumSchema first: StringSchema also matches an enum and would drop its values.
|
|
475
|
+
Schema.Union([EnumSchema, StringSchema, NumberSchema, BooleanSchema])
|
|
483
476
|
),
|
|
484
477
|
required: optional(Schema.Array(Schema.String))
|
|
485
478
|
})
|
|
@@ -538,14 +538,6 @@ export const GetPromptResult = Schema.Struct({
|
|
|
538
538
|
messages: Schema.Array(PromptMessage)
|
|
539
539
|
})
|
|
540
540
|
|
|
541
|
-
/**
|
|
542
|
-
* @internal
|
|
543
|
-
*/
|
|
544
|
-
export const ListToolsResult = Schema.Struct({
|
|
545
|
-
...Previous.PaginatedResult.fields,
|
|
546
|
-
tools: Schema.Array(Tool)
|
|
547
|
-
})
|
|
548
|
-
|
|
549
541
|
/**
|
|
550
542
|
* @internal
|
|
551
543
|
*/
|
|
@@ -590,7 +582,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
|
|
|
590
582
|
* @internal
|
|
591
583
|
*/
|
|
592
584
|
export class ListTools extends Rpc.make("tools/list", {
|
|
593
|
-
success: ListToolsResult,
|
|
585
|
+
success: Previous.ListToolsResult,
|
|
594
586
|
error: Previous.McpError,
|
|
595
587
|
payload: Schema.UndefinedOr(Previous.PaginatedRequest)
|
|
596
588
|
}) {}
|
|
@@ -627,14 +627,12 @@ export class GetPrompt extends Rpc.make("prompts/get", {
|
|
|
627
627
|
/**
|
|
628
628
|
* @internal
|
|
629
629
|
*/
|
|
630
|
-
export const ListToolsResult = Schema.
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
[UnknownObject]
|
|
637
|
-
)
|
|
630
|
+
export const ListToolsResult = Schema.Struct({
|
|
631
|
+
...PaginatedResult,
|
|
632
|
+
...CacheableResult,
|
|
633
|
+
// Already JSON-encoded by the protocol adapter; a rest signature would re-walk them.
|
|
634
|
+
tools: Schema.Any
|
|
635
|
+
})
|
|
638
636
|
/**
|
|
639
637
|
* @internal
|
|
640
638
|
*/
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
* @stability unstable
|
|
16
16
|
* @since 4.0.0
|
|
17
17
|
*/
|
|
18
|
+
import * as Cause from "../Cause.ts"
|
|
18
19
|
import * as Context from "../Context.ts"
|
|
19
20
|
import * as Cron from "../Cron.ts"
|
|
20
21
|
import * as DateTime from "../DateTime.ts"
|
|
21
22
|
import * as Duration from "../Duration.ts"
|
|
22
23
|
import * as Effect from "../Effect.ts"
|
|
23
|
-
import * as
|
|
24
|
+
import * as Fiber from "../Fiber.ts"
|
|
24
25
|
import * as Layer from "../Layer.ts"
|
|
25
26
|
import * as PrimaryKey from "../PrimaryKey.ts"
|
|
26
27
|
import * as Rpc from "../rpc/Rpc.ts"
|
|
@@ -79,6 +80,10 @@ export class CronSchedule extends Context.Service<CronSchedule, {
|
|
|
79
80
|
* scheduling step and optional controls for shard group, next-run calculation,
|
|
80
81
|
* and skipping stale scheduled runs.
|
|
81
82
|
*
|
|
83
|
+
* A run that fails or dies is logged and not retried, and the next run is
|
|
84
|
+
* scheduled as usual. To retry typed failures, apply `Effect.retry` inside
|
|
85
|
+
* `execute` with your own stopping policy.
|
|
86
|
+
*
|
|
82
87
|
* @stability unstable
|
|
83
88
|
* @category constructors
|
|
84
89
|
* @since 4.0.0
|
|
@@ -103,9 +108,7 @@ export const make = <E, R>(options: {
|
|
|
103
108
|
* current time.
|
|
104
109
|
*
|
|
105
110
|
* When enabled, all runs are processed one at a time by a single entity, so
|
|
106
|
-
* missed runs are caught up in order without overlapping.
|
|
107
|
-
* is retried in place and blocks later runs until it succeeds or is older
|
|
108
|
-
* than `skipIfOlderThan`.
|
|
111
|
+
* missed runs are caught up in order without overlapping.
|
|
109
112
|
*/
|
|
110
113
|
readonly calculateNextRunFromPrevious?: boolean | undefined
|
|
111
114
|
|
|
@@ -168,16 +171,23 @@ export const make = <E, R>(options: {
|
|
|
168
171
|
{ shardGroup: options.shardGroup }
|
|
169
172
|
)
|
|
170
173
|
|
|
171
|
-
const execute = Effect.fnUntraced(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
const execute = Effect.fnUntraced(
|
|
175
|
+
function*(dateTime: DateTime.Utc) {
|
|
176
|
+
const now = yield* DateTime.now
|
|
177
|
+
if (DateTime.isLessThan(dateTime, DateTime.subtractDuration(now, cronSchedule.skipIfOlderThan))) {
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
// the run gets its own fiber and scope, so its child fibers stop and its
|
|
181
|
+
// finalizers see its exit before the next run is scheduled
|
|
182
|
+
const fiber = yield* Effect.forkChild(
|
|
183
|
+
Effect.provideContext(options.execute, Context.add(scheduleContext, CurrentScheduledTime, dateTime)),
|
|
184
|
+
{ uninterruptible: "inherit" }
|
|
185
|
+
)
|
|
186
|
+
return yield* Fiber.join(fiber).pipe(Effect.onInterrupt(() => Fiber.interrupt(fiber)))
|
|
187
|
+
},
|
|
188
|
+
Effect.scoped,
|
|
189
|
+
Effect.orDie
|
|
190
|
+
)
|
|
181
191
|
|
|
182
192
|
const EntityLayer = CronEntity.toLayer(Effect.gen(function*() {
|
|
183
193
|
const address = yield* Entity.CurrentAddress
|
|
@@ -193,12 +203,13 @@ export const make = <E, R>(options: {
|
|
|
193
203
|
}
|
|
194
204
|
processedRun = true
|
|
195
205
|
return Effect.onExitPrimitive(
|
|
196
|
-
execute(dateTime)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
execute(dateTime).pipe(
|
|
207
|
+
Effect.tapCause(Effect.logWarning),
|
|
208
|
+
// interrupted runs are left for the entity manager to replay
|
|
209
|
+
Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), () => Effect.void)
|
|
210
|
+
),
|
|
211
|
+
() =>
|
|
212
|
+
fromPrevious ? schedule(nextRun(dateTime)) : Effect.flatMap(DateTime.now, (now) => schedule(nextRun(now))),
|
|
202
213
|
true
|
|
203
214
|
).pipe(
|
|
204
215
|
Effect.annotateLogs({
|
|
@@ -784,8 +784,13 @@ export const makeEncodedStorage: (options?: {
|
|
|
784
784
|
const update = reply._tag === "Chunk" ?
|
|
785
785
|
sql`UPDATE ${messagesTableSql} SET last_reply_id = ${reply.id} WHERE id = ${reply.requestId}` :
|
|
786
786
|
sql`UPDATE ${messagesTableSql} SET processed = ${sqlTrue}, last_reply_id = ${reply.id} WHERE request_id = ${reply.requestId}`
|
|
787
|
-
return
|
|
788
|
-
Effect.
|
|
787
|
+
return lockRequest(reply.requestId).pipe(
|
|
788
|
+
Effect.flatMap((request) =>
|
|
789
|
+
// the request was deleted, so there is nothing left to reply to
|
|
790
|
+
request.length === 0 ? Effect.void : update.unprepared.pipe(
|
|
791
|
+
Effect.andThen(sql`INSERT INTO ${repliesTableSql} ${sql.insert(row)}`)
|
|
792
|
+
)
|
|
793
|
+
),
|
|
789
794
|
sql.withTransaction
|
|
790
795
|
)
|
|
791
796
|
}).pipe(
|
package/src/encoding/Hex.ts
CHANGED
|
@@ -284,10 +284,10 @@ const hexEncodeUint8Array = (bytes: Uint8Array): string => {
|
|
|
284
284
|
return result
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
287
|
+
// Maps each byte to its hex digit value, or 255 when it is not a hex digit.
|
|
288
|
+
const hexCodes = Uint8Array.from({ length: 256 }, (_, charCode) => {
|
|
289
|
+
const digit = "0123456789abcdef".indexOf(String.fromCharCode(charCode).toLowerCase())
|
|
290
|
+
return digit === -1 ? 255 : digit
|
|
291
|
+
})
|
|
292
292
|
|
|
293
293
|
const hexCode = (charCode: number): number => charCode < 256 ? hexCodes[charCode] : 255
|
package/src/http/HttpEffect.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @stability unstable
|
|
10
10
|
* @since 4.0.0
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
12
|
+
import * as Cause from "../Cause.ts"
|
|
13
13
|
import * as Context from "../Context.ts"
|
|
14
14
|
import * as Effect from "../Effect.ts"
|
|
15
15
|
import * as Exit from "../Exit.ts"
|
|
@@ -17,6 +17,7 @@ import * as Fiber from "../Fiber.ts"
|
|
|
17
17
|
import { constVoid, dual } from "../Function.ts"
|
|
18
18
|
import { contA, contE } from "../internal/core.ts"
|
|
19
19
|
import { effectIsExit, fiberEnterUninterruptibleUnsafe, reportCauseUnsafe } from "../internal/effect.ts"
|
|
20
|
+
import { isSchemaError } from "../internal/schemaError.ts"
|
|
20
21
|
import * as Layer from "../Layer.ts"
|
|
21
22
|
import * as Scope from "../Scope.ts"
|
|
22
23
|
import * as Stream from "../Stream.ts"
|
|
@@ -26,6 +27,7 @@ import { type HttpMiddleware, isTracerDisabledUnsafe, tracer } from "./HttpMiddl
|
|
|
26
27
|
import { causeResponse, ClientAbort, HttpServerError, InternalError } from "./HttpServerError.ts"
|
|
27
28
|
import { HttpServerRequest } from "./HttpServerRequest.ts"
|
|
28
29
|
import * as Request from "./HttpServerRequest.ts"
|
|
30
|
+
import { isRespondable } from "./HttpServerRespondable.ts"
|
|
29
31
|
import type { HttpServerResponse } from "./HttpServerResponse.ts"
|
|
30
32
|
import * as Response from "./HttpServerResponse.ts"
|
|
31
33
|
import * as requestState from "./internal/requestState.ts"
|
|
@@ -63,7 +65,7 @@ export const toHandled = <E, R, EH, RH>(
|
|
|
63
65
|
const request = frame.request
|
|
64
66
|
return Effect.flatMapEager(causeResponse(cause), ([response, cause]) => {
|
|
65
67
|
const fiber = Fiber.getCurrent()!
|
|
66
|
-
|
|
68
|
+
reportServerCauseUnsafe(fiber, cause)
|
|
67
69
|
const handler = frame.preResponseHandler
|
|
68
70
|
const cont = cause.reasons.length === 0 ? Effect.succeed(response) : Effect.failCause(cause)
|
|
69
71
|
if (handler === undefined) {
|
|
@@ -122,7 +124,7 @@ export const toHandled = <E, R, EH, RH>(
|
|
|
122
124
|
responded :
|
|
123
125
|
Effect.matchCauseEffect(tracer(middleware(responded)), {
|
|
124
126
|
onFailure(cause): Effect.Effect<void, EH, RH> {
|
|
125
|
-
|
|
127
|
+
reportServerCauseUnsafe(Fiber.getCurrent()!, cause)
|
|
126
128
|
if (handledSymbol in request) return Effect.void
|
|
127
129
|
return Effect.matchCauseEffectEager(causeResponse(cause), {
|
|
128
130
|
onFailure(_) {
|
|
@@ -227,6 +229,24 @@ export const toHandled = <E, R, EH, RH>(
|
|
|
227
229
|
|
|
228
230
|
const handledSymbol = Symbol.for("effect/http/HttpEffect/handled")
|
|
229
231
|
|
|
232
|
+
// Client errors that `HttpServerRespondable.toResponseOrElse` answers with 400
|
|
233
|
+
// or 404. They are not reported.
|
|
234
|
+
const isClientError = (u: unknown) => !isRespondable(u) && (isSchemaError(u) || Cause.isNoSuchElementError(u))
|
|
235
|
+
|
|
236
|
+
// Both reporting paths can see the same cause. Reusing its filtered cause lets
|
|
237
|
+
// reporters skip the second report.
|
|
238
|
+
const reportableCauses = new WeakMap<Cause.Cause<unknown>, Cause.Cause<unknown>>()
|
|
239
|
+
|
|
240
|
+
const reportServerCauseUnsafe = (fiber: Fiber.Fiber<unknown, unknown>, cause: Cause.Cause<unknown>) => {
|
|
241
|
+
let reportable = reportableCauses.get(cause)
|
|
242
|
+
if (reportable === undefined) {
|
|
243
|
+
const reasons = cause.reasons.filter((reason) => reason._tag !== "Fail" || !isClientError(reason.error))
|
|
244
|
+
reportable = reasons.length === cause.reasons.length ? cause : Cause.fromReasons(reasons)
|
|
245
|
+
reportableCauses.set(cause, reportable)
|
|
246
|
+
}
|
|
247
|
+
reportCauseUnsafe(fiber, reportable)
|
|
248
|
+
}
|
|
249
|
+
|
|
230
250
|
/**
|
|
231
251
|
* Disables automatic closing for an HTTP request scope.
|
|
232
252
|
*
|
|
@@ -289,7 +289,7 @@ const formatRequestMessage = (reason: string, description: string | undefined, i
|
|
|
289
289
|
|
|
290
290
|
/**
|
|
291
291
|
* Converts a failed handler cause into the HTTP response that should be sent and
|
|
292
|
-
* the cause
|
|
292
|
+
* the cause to propagate.
|
|
293
293
|
*
|
|
294
294
|
* **Details**
|
|
295
295
|
*
|