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
package/src/internal/core.ts
CHANGED
|
@@ -8,11 +8,12 @@ import { dual, identity } from "../Function.ts"
|
|
|
8
8
|
import * as Hash from "../Hash.ts"
|
|
9
9
|
import { NodeInspectSymbol } from "../Inspectable.ts"
|
|
10
10
|
import { pipeArguments } from "../Pipeable.ts"
|
|
11
|
-
import { hasProperty } from "../Predicate.ts"
|
|
12
11
|
import type { StackFrame } from "../References.ts"
|
|
13
12
|
import type * as Types from "../Types.ts"
|
|
14
13
|
import { SingleShotGen } from "../Utils.ts"
|
|
15
14
|
import type { FiberImpl } from "./effect.ts"
|
|
15
|
+
import { combine as hashCombine } from "./equal.ts"
|
|
16
|
+
import { hasProperty } from "./predicate.ts"
|
|
16
17
|
import * as InternalRecord from "./record.ts"
|
|
17
18
|
|
|
18
19
|
/** @internal */
|
|
@@ -101,13 +102,6 @@ export const EffectProto = {
|
|
|
101
102
|
...PipeInspectableProto,
|
|
102
103
|
[Symbol.iterator]() {
|
|
103
104
|
return new SingleShotGen(this) as any
|
|
104
|
-
},
|
|
105
|
-
toJSON(this: Primitive) {
|
|
106
|
-
return {
|
|
107
|
-
_id: "Effect",
|
|
108
|
-
op: this[identifier],
|
|
109
|
-
...(args in this ? { args: this[args] } : undefined)
|
|
110
|
-
}
|
|
111
105
|
}
|
|
112
106
|
}
|
|
113
107
|
|
|
@@ -176,19 +170,37 @@ export class CauseImpl<E> implements Cause.Cause<E> {
|
|
|
176
170
|
|
|
177
171
|
const annotationsMap = new WeakMap<object, ReadonlyMap<string, unknown>>()
|
|
178
172
|
|
|
173
|
+
const annotateReasonMap = <T extends ReasonBase<any>>(
|
|
174
|
+
reason: T,
|
|
175
|
+
annotations: ReadonlyMap<string, unknown>,
|
|
176
|
+
options?: { readonly overwrite?: boolean | undefined }
|
|
177
|
+
): T => {
|
|
178
|
+
if (annotations.size === 0) return reason
|
|
179
|
+
const overwrite = options?.overwrite === true
|
|
180
|
+
const newAnnotations = new Map(reason.annotations)
|
|
181
|
+
for (const [key, value] of annotations) {
|
|
182
|
+
if (overwrite || !newAnnotations.has(key)) {
|
|
183
|
+
newAnnotations.set(key, value)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Keep the reason when nothing was added, so interrupts still match by identity.
|
|
187
|
+
if (!overwrite && newAnnotations.size === reason.annotations.size) return reason
|
|
188
|
+
const self = Object.assign(Object.create(Object.getPrototypeOf(reason)), reason)
|
|
189
|
+
self.annotations = newAnnotations
|
|
190
|
+
return self
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
/** @internal */
|
|
180
194
|
export abstract class ReasonBase<Tag extends string> implements Cause.Cause.ReasonProto<Tag> {
|
|
181
|
-
readonly [CauseReasonTypeId]: typeof CauseReasonTypeId
|
|
182
|
-
readonly annotations: ReadonlyMap<string, unknown>
|
|
183
|
-
readonly _tag: Tag
|
|
195
|
+
declare readonly [CauseReasonTypeId]: typeof CauseReasonTypeId
|
|
196
|
+
declare readonly annotations: ReadonlyMap<string, unknown>
|
|
197
|
+
declare readonly _tag: Tag
|
|
184
198
|
|
|
185
199
|
constructor(
|
|
186
200
|
_tag: Tag,
|
|
187
201
|
annotations: ReadonlyMap<string, unknown>,
|
|
188
202
|
originalError: unknown
|
|
189
203
|
) {
|
|
190
|
-
this[CauseReasonTypeId] = CauseReasonTypeId
|
|
191
|
-
this._tag = _tag
|
|
192
204
|
if (
|
|
193
205
|
annotations !== constEmptyAnnotations && typeof originalError === "object" && originalError !== null &&
|
|
194
206
|
annotations.size > 0
|
|
@@ -202,24 +214,16 @@ export abstract class ReasonBase<Tag extends string> implements Cause.Cause.Reas
|
|
|
202
214
|
}
|
|
203
215
|
annotationsMap.set(originalError, annotations)
|
|
204
216
|
}
|
|
217
|
+
this[CauseReasonTypeId] = CauseReasonTypeId
|
|
205
218
|
this.annotations = annotations
|
|
219
|
+
this._tag = _tag
|
|
206
220
|
}
|
|
207
221
|
|
|
208
222
|
annotate(
|
|
209
223
|
annotations: Context.Context<never>,
|
|
210
224
|
options?: { readonly overwrite?: boolean | undefined }
|
|
211
225
|
): this {
|
|
212
|
-
|
|
213
|
-
const newAnnotations = new Map(this.annotations)
|
|
214
|
-
annotations.mapUnsafe.forEach((value, key) => {
|
|
215
|
-
if (options?.overwrite !== true && newAnnotations.has(key)) return
|
|
216
|
-
newAnnotations.set(key, value)
|
|
217
|
-
})
|
|
218
|
-
// Keep the reason when nothing was added, so interrupts still match by identity.
|
|
219
|
-
if (options?.overwrite !== true && newAnnotations.size === this.annotations.size) return this
|
|
220
|
-
const self = Object.assign(Object.create(Object.getPrototypeOf(this)), this)
|
|
221
|
-
self.annotations = newAnnotations
|
|
222
|
-
return self
|
|
226
|
+
return annotateReasonMap(this, annotations.mapUnsafe, options)
|
|
223
227
|
}
|
|
224
228
|
|
|
225
229
|
pipe() {
|
|
@@ -227,13 +231,10 @@ export abstract class ReasonBase<Tag extends string> implements Cause.Cause.Reas
|
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
abstract toJSON(): unknown
|
|
234
|
+
abstract toString(): string
|
|
230
235
|
abstract [Equal.symbol](that: any): boolean
|
|
231
236
|
abstract [Hash.symbol](): number
|
|
232
237
|
|
|
233
|
-
toString() {
|
|
234
|
-
return format(this)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
238
|
[NodeInspectSymbol]() {
|
|
238
239
|
return this.toString()
|
|
239
240
|
}
|
|
@@ -269,9 +270,9 @@ export class Fail<E> extends ReasonBase<"Fail"> implements Cause.Fail<E> {
|
|
|
269
270
|
)
|
|
270
271
|
}
|
|
271
272
|
[Hash.symbol](): number {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
)
|
|
273
|
+
// The error is hashed before the annotations, as both can run user code
|
|
274
|
+
const error = Hash.hash(this.error)
|
|
275
|
+
return hashCombine(hashCombine(Hash.hash(this.annotations), error), Hash.string(this._tag))
|
|
275
276
|
}
|
|
276
277
|
}
|
|
277
278
|
|
|
@@ -375,15 +376,45 @@ export class Die extends ReasonBase<"Die"> implements Cause.Die {
|
|
|
375
376
|
)
|
|
376
377
|
}
|
|
377
378
|
[Hash.symbol](): number {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
)
|
|
379
|
+
// The defect is hashed before the annotations, as both can run user code
|
|
380
|
+
const defect = Hash.hash(this.defect)
|
|
381
|
+
return hashCombine(hashCombine(Hash.hash(this.annotations), defect), Hash.string(this._tag))
|
|
381
382
|
}
|
|
382
383
|
}
|
|
383
384
|
|
|
384
385
|
/** @internal */
|
|
385
386
|
export const causeDie = (defect: unknown): Cause.Cause<never> => new CauseImpl([new Die(defect)])
|
|
386
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Context.ts imports this module, so it registers `makeUnsafe` here instead.
|
|
390
|
+
*
|
|
391
|
+
* @internal
|
|
392
|
+
*/
|
|
393
|
+
export const contextMaker: {
|
|
394
|
+
makeUnsafe?: (mapUnsafe: ReadonlyMap<string, unknown>) => Context.Context<never>
|
|
395
|
+
} = {}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Data-first `causeAnnotate` taking a plain annotation map, so the fiber
|
|
399
|
+
* runtime does not pull in `Function.dual` or wrap maps in a `Context`.
|
|
400
|
+
* Only reasons with their own `annotate` method receive a `Context`.
|
|
401
|
+
*
|
|
402
|
+
* @internal
|
|
403
|
+
*/
|
|
404
|
+
export const causeAnnotateMap = <E>(
|
|
405
|
+
self: Cause.Cause<E>,
|
|
406
|
+
annotations: ReadonlyMap<string, unknown>,
|
|
407
|
+
options?: { readonly overwrite?: boolean | undefined },
|
|
408
|
+
context?: Context.Context<never>
|
|
409
|
+
): Cause.Cause<E> => {
|
|
410
|
+
if (annotations.size === 0) return self
|
|
411
|
+
return new CauseImpl(self.reasons.map((f) =>
|
|
412
|
+
f.annotate as unknown === ReasonBase.prototype.annotate
|
|
413
|
+
? annotateReasonMap(f as any, annotations, options)
|
|
414
|
+
: f.annotate(context ?? contextMaker.makeUnsafe!(annotations), options)
|
|
415
|
+
))
|
|
416
|
+
}
|
|
417
|
+
|
|
387
418
|
/** @internal */
|
|
388
419
|
export const causeAnnotate: {
|
|
389
420
|
(
|
|
@@ -407,10 +438,7 @@ export const causeAnnotate: {
|
|
|
407
438
|
options?: {
|
|
408
439
|
readonly overwrite?: boolean | undefined
|
|
409
440
|
}
|
|
410
|
-
): Cause.Cause<E> =>
|
|
411
|
-
if (annotations.mapUnsafe.size === 0) return self
|
|
412
|
-
return new CauseImpl(self.reasons.map((f) => f.annotate(annotations, options)))
|
|
413
|
-
}
|
|
441
|
+
): Cause.Cause<E> => causeAnnotateMap(self, annotations.mapUnsafe, options, annotations)
|
|
414
442
|
)
|
|
415
443
|
|
|
416
444
|
/** @internal */
|
|
@@ -477,6 +505,13 @@ export const makePrimitiveProto = <Op extends string>(options: {
|
|
|
477
505
|
}): Primitive =>
|
|
478
506
|
({
|
|
479
507
|
...EffectProto,
|
|
508
|
+
toJSON(this: Primitive) {
|
|
509
|
+
return {
|
|
510
|
+
_id: "Effect",
|
|
511
|
+
op: this[identifier],
|
|
512
|
+
...(args in this ? { args: this[args] } : undefined)
|
|
513
|
+
}
|
|
514
|
+
},
|
|
480
515
|
[identifier]: options.op,
|
|
481
516
|
[evaluate]: options[evaluate] ?? defaultEvaluate,
|
|
482
517
|
[contA]: options[contA],
|
|
@@ -540,13 +575,16 @@ export const makeExit = <
|
|
|
540
575
|
fiber: FiberImpl<unknown, unknown>
|
|
541
576
|
) => Primitive | Yield
|
|
542
577
|
}): Fn => {
|
|
578
|
+
const opHash = Hash.string(options.op)
|
|
543
579
|
const Proto = {
|
|
544
580
|
[ExitTypeId]: ExitTypeId,
|
|
545
581
|
_tag: options.op,
|
|
546
582
|
get [options.prop](): any {
|
|
547
583
|
return (this as any)[args]
|
|
548
584
|
},
|
|
549
|
-
...
|
|
585
|
+
...EffectProto,
|
|
586
|
+
[identifier]: options.op,
|
|
587
|
+
[evaluate]: options[evaluate],
|
|
550
588
|
toString(this: any) {
|
|
551
589
|
return `${options.op}(${format(this[args])})`
|
|
552
590
|
},
|
|
@@ -565,7 +603,7 @@ export const makeExit = <
|
|
|
565
603
|
)
|
|
566
604
|
},
|
|
567
605
|
[Hash.symbol](this: any): number {
|
|
568
|
-
return
|
|
606
|
+
return hashCombine(opHash, Hash.hash(this[args]))
|
|
569
607
|
}
|
|
570
608
|
}
|
|
571
609
|
const ExitPrimitive = function(this: any, value: unknown) {
|
|
@@ -588,9 +626,7 @@ export const exitSucceed: <A>(a: A) => Exit.Exit<A> = makeExit({
|
|
|
588
626
|
})
|
|
589
627
|
|
|
590
628
|
/** @internal */
|
|
591
|
-
export const StackTraceKey =
|
|
592
|
-
key: "effect/Cause/StackTrace" satisfies typeof Cause.StackTrace.key
|
|
593
|
-
} as Context.Service<Cause.StackTrace, StackFrame>
|
|
629
|
+
export const StackTraceKey = "effect/Cause/StackTrace" satisfies typeof Cause.StackTrace.key
|
|
594
630
|
|
|
595
631
|
/** @internal */
|
|
596
632
|
export const InterruptorStackTrace = {
|
|
@@ -605,7 +641,7 @@ export const exitFailCause: <E>(cause: Cause.Cause<E>) => Exit.Exit<never, E> =
|
|
|
605
641
|
let cause = this[args]
|
|
606
642
|
let annotated = false
|
|
607
643
|
if (fiber.cache.stackFrame) {
|
|
608
|
-
cause =
|
|
644
|
+
cause = causeAnnotateMap(cause, new Map([[StackTraceKey, fiber.cache.stackFrame]]))
|
|
609
645
|
annotated = true
|
|
610
646
|
}
|
|
611
647
|
let cont = fiber.getCont(contE)
|
package/src/internal/effect.ts
CHANGED
|
@@ -22,7 +22,7 @@ import * as Option from "../Option.ts"
|
|
|
22
22
|
import * as Order from "../Order.ts"
|
|
23
23
|
import { pipeArguments } from "../Pipeable.ts"
|
|
24
24
|
import type * as Predicate from "../Predicate.ts"
|
|
25
|
-
import {
|
|
25
|
+
import { isIterable, isString, isTagged } from "../Predicate.ts"
|
|
26
26
|
import { currentFiberTypeId, redact } from "../Redactable.ts"
|
|
27
27
|
import type { StackFrame } from "../References.ts"
|
|
28
28
|
import * as Result from "../Result.ts"
|
|
@@ -50,7 +50,7 @@ import type { Primitive } from "./core.ts"
|
|
|
50
50
|
import {
|
|
51
51
|
args,
|
|
52
52
|
causeAddInterrupts,
|
|
53
|
-
|
|
53
|
+
causeAnnotateMap,
|
|
54
54
|
causeCombine,
|
|
55
55
|
causeEmpty,
|
|
56
56
|
causeFromReasons,
|
|
@@ -85,15 +85,31 @@ import {
|
|
|
85
85
|
Yield
|
|
86
86
|
} from "./core.ts"
|
|
87
87
|
import * as doNotation from "./doNotation.ts"
|
|
88
|
-
import
|
|
88
|
+
import {
|
|
89
|
+
CurrentLogLevelKey,
|
|
90
|
+
CurrentStackFrameKey,
|
|
91
|
+
defaultCurrentLogLevel,
|
|
92
|
+
defaultMaxOpsBeforeYield,
|
|
93
|
+
defaultMinimumLogLevel,
|
|
94
|
+
defaultPreventSchedulerYield,
|
|
95
|
+
defaultTracerEnabled,
|
|
96
|
+
type FiberCacheKey,
|
|
97
|
+
FiberRuntimeMetricsKey,
|
|
98
|
+
MaxOpsBeforeYieldKey,
|
|
99
|
+
MinimumLogLevelKey,
|
|
100
|
+
ParentSpanKey,
|
|
101
|
+
PreventSchedulerYieldKey,
|
|
102
|
+
SchedulerKey,
|
|
103
|
+
TracerEnabledKey,
|
|
104
|
+
TracerKey
|
|
105
|
+
} from "./fiberCachedKeys.ts"
|
|
106
|
+
import { hasProperty } from "./predicate.ts"
|
|
89
107
|
import * as InternalRecord from "./record.ts"
|
|
90
108
|
import {
|
|
91
109
|
CurrentErrorReporters,
|
|
92
110
|
CurrentLogAnnotations,
|
|
93
|
-
CurrentLogLevel,
|
|
94
111
|
CurrentLogSpans,
|
|
95
112
|
CurrentStackFrame,
|
|
96
|
-
MinimumLogLevel,
|
|
97
113
|
TracerEnabled,
|
|
98
114
|
TracerSpanAnnotations,
|
|
99
115
|
TracerSpanLinks,
|
|
@@ -422,7 +438,7 @@ const cleanErrorStack = (
|
|
|
422
438
|
}
|
|
423
439
|
|
|
424
440
|
const addStackAnnotations = (stack: string, annotations: ReadonlyMap<string, unknown>) => {
|
|
425
|
-
const frame = annotations?.get(CauseStackTrace
|
|
441
|
+
const frame = annotations?.get(CauseStackTrace) as StackFrame | undefined
|
|
426
442
|
if (frame) {
|
|
427
443
|
stack = `${stack}\n${currentStackTrace(frame)}`
|
|
428
444
|
}
|
|
@@ -496,7 +512,7 @@ const fiberVariance = {
|
|
|
496
512
|
_E: identity
|
|
497
513
|
}
|
|
498
514
|
|
|
499
|
-
|
|
515
|
+
let nextFiberId = 0
|
|
500
516
|
|
|
501
517
|
interface AsyncContext {
|
|
502
518
|
runInAsyncScope<This, Arg, R>(fn: (this: This, arg: Arg) => R, thisArg: This, arg: Arg): R
|
|
@@ -524,7 +540,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
|
524
540
|
interruptible: boolean = true
|
|
525
541
|
) {
|
|
526
542
|
this.setContext(context)
|
|
527
|
-
this.id = ++
|
|
543
|
+
this.id = ++nextFiberId
|
|
528
544
|
this.currentOpCount = 0
|
|
529
545
|
this.interruptible = interruptible
|
|
530
546
|
this._stack = []
|
|
@@ -570,18 +586,14 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
|
570
586
|
}
|
|
571
587
|
|
|
572
588
|
getRef<X>(ref: Context.Reference<X>): X {
|
|
573
|
-
return Context.
|
|
589
|
+
return Context.getReferenceUnsafe(this.context, ref)
|
|
574
590
|
}
|
|
575
591
|
addObserver(cb: (exit: Exit.Exit<A, E>) => void): () => void {
|
|
576
592
|
if (this._exit) {
|
|
577
593
|
cb(this._exit)
|
|
578
594
|
return constVoid
|
|
579
595
|
}
|
|
580
|
-
|
|
581
|
-
this._observers = [cb]
|
|
582
|
-
} else {
|
|
583
|
-
this._observers.push(cb)
|
|
584
|
-
}
|
|
596
|
+
;(this._observers ??= []).push(cb)
|
|
585
597
|
return () => this.removeObserver(cb)
|
|
586
598
|
}
|
|
587
599
|
removeObserver(cb: (exit: Exit.Exit<A, E>) => void): void {
|
|
@@ -597,10 +609,10 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
|
597
609
|
}
|
|
598
610
|
let cause = causeInterrupt(fiberId)
|
|
599
611
|
if (this.cache.stackFrame) {
|
|
600
|
-
cause =
|
|
612
|
+
cause = causeAnnotateMap(cause, new Map([[CauseStackTrace, this.cache.stackFrame]]))
|
|
601
613
|
}
|
|
602
614
|
if (annotations) {
|
|
603
|
-
cause =
|
|
615
|
+
cause = causeAnnotateMap(cause, annotations.mapUnsafe)
|
|
604
616
|
}
|
|
605
617
|
this._interruptedCause = this._interruptedCause
|
|
606
618
|
? causeAddInterrupts(this._interruptedCause, cause)
|
|
@@ -642,11 +654,11 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
|
642
654
|
// the interruptChildren middleware is added in Effect.forkChild, so it can be
|
|
643
655
|
// tree-shaken if not used
|
|
644
656
|
const interruptChildren = fiberMiddleware.interruptChildren &&
|
|
645
|
-
fiberMiddleware.interruptChildren(this)
|
|
657
|
+
fiberMiddleware.interruptChildren(this, exit)
|
|
646
658
|
if (interruptChildren !== undefined) {
|
|
647
659
|
// uninterruptible, so a pending interrupt cannot replace the exit during the wait
|
|
648
660
|
this.interruptible = false
|
|
649
|
-
return this.evaluate(
|
|
661
|
+
return this.evaluate(interruptChildren as any)
|
|
650
662
|
}
|
|
651
663
|
|
|
652
664
|
this._exit = exit
|
|
@@ -757,6 +769,8 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
|
757
769
|
if (op[symbol]) return op as any
|
|
758
770
|
}
|
|
759
771
|
}
|
|
772
|
+
// Primitives built by other versions of effect call succeedWith, children
|
|
773
|
+
// and currentSpanLocal, so they stay fiber members.
|
|
760
774
|
// Passes a success value straight to the next continuation instead of
|
|
761
775
|
// returning an Exit for the run loop to unwrap. Each call counts as an
|
|
762
776
|
// operation, and every `maxInlineSteps`th call returns an Exit instead, so
|
|
@@ -812,21 +826,22 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
|
812
826
|
}
|
|
813
827
|
|
|
814
828
|
const makeFiberContextCache = (context: Context.Context<never>): Fiber.Fiber.Cache => {
|
|
815
|
-
//
|
|
816
|
-
//
|
|
817
|
-
const
|
|
829
|
+
// Reading by key keeps the service objects, and the native tracer behind
|
|
830
|
+
// Tracer.Tracer's default, out of bundles that never use them.
|
|
831
|
+
const get = <A>(key: FiberCacheKey): A | undefined => Context.getOrUndefinedUnsafe(context, key)
|
|
832
|
+
const currentTracer = get<Tracer.Tracer>(TracerKey)
|
|
818
833
|
return {
|
|
819
|
-
scheduler:
|
|
834
|
+
scheduler: get<Scheduler.Scheduler>(SchedulerKey) ?? Scheduler.getDefaultScheduler(),
|
|
820
835
|
tracer: currentTracer,
|
|
821
|
-
tracerContext: currentTracer
|
|
822
|
-
tracerEnabled:
|
|
823
|
-
span:
|
|
824
|
-
logLevel:
|
|
825
|
-
minimumLogLevel:
|
|
826
|
-
stackFrame:
|
|
827
|
-
runtimeMetrics:
|
|
828
|
-
maxOpsBeforeYield:
|
|
829
|
-
preventYield:
|
|
836
|
+
tracerContext: currentTracer?.["context"],
|
|
837
|
+
tracerEnabled: get<boolean>(TracerEnabledKey) ?? defaultTracerEnabled,
|
|
838
|
+
span: get(ParentSpanKey),
|
|
839
|
+
logLevel: get<LogLevel.Severity>(CurrentLogLevelKey) ?? defaultCurrentLogLevel,
|
|
840
|
+
minimumLogLevel: get<LogLevel.LogLevel>(MinimumLogLevelKey) ?? defaultMinimumLogLevel,
|
|
841
|
+
stackFrame: get(CurrentStackFrameKey),
|
|
842
|
+
runtimeMetrics: get(FiberRuntimeMetricsKey),
|
|
843
|
+
maxOpsBeforeYield: get<number>(MaxOpsBeforeYieldKey) ?? defaultMaxOpsBeforeYield,
|
|
844
|
+
preventYield: get<boolean>(PreventSchedulerYieldKey) ?? defaultPreventSchedulerYield
|
|
830
845
|
}
|
|
831
846
|
}
|
|
832
847
|
|
|
@@ -844,7 +859,7 @@ const maxInlineSteps = 32
|
|
|
844
859
|
|
|
845
860
|
const fiberMiddleware = {
|
|
846
861
|
interruptChildren: undefined as
|
|
847
|
-
| ((fiber: FiberImpl) => Effect.Effect<
|
|
862
|
+
| (<A, E>(fiber: FiberImpl<A, E>, exit: Exit.Exit<A, E>) => Effect.Effect<A, E> | undefined)
|
|
848
863
|
| undefined
|
|
849
864
|
}
|
|
850
865
|
|
|
@@ -855,11 +870,11 @@ const fiberStackAnnotations = (fiber: Fiber.Fiber<any, any>) => {
|
|
|
855
870
|
return Context.makeUnsafe(annotations)
|
|
856
871
|
}
|
|
857
872
|
|
|
858
|
-
const fiberInterruptChildren = (fiber: FiberImpl) => {
|
|
873
|
+
const fiberInterruptChildren = <A, E>(fiber: FiberImpl<A, E>, exit: Exit.Exit<A, E>) => {
|
|
859
874
|
if (fiber._children === undefined || fiber._children.size === 0) {
|
|
860
875
|
return undefined
|
|
861
876
|
}
|
|
862
|
-
return fiberInterruptAll(fiber._children)
|
|
877
|
+
return flatMap(fiberInterruptAll(fiber._children), () => exit)
|
|
863
878
|
}
|
|
864
879
|
|
|
865
880
|
/** @internal */
|
|
@@ -5713,34 +5728,41 @@ export const forkScoped: {
|
|
|
5713
5728
|
// execution
|
|
5714
5729
|
// ----------------------------------------------------------------------------
|
|
5715
5730
|
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
<A, E>(
|
|
5731
|
+
const runFiber = <R, A, E>(
|
|
5732
|
+
context: Context.Context<R>,
|
|
5719
5733
|
effect: Effect.Effect<A, E, R>,
|
|
5720
5734
|
options?: Effect.RunOptions | undefined
|
|
5721
5735
|
): Fiber.Fiber<A, E> => {
|
|
5722
|
-
const fiber = new FiberImpl<A, E>(
|
|
5723
|
-
options?.scheduler ? Context.add(context, Scheduler.Scheduler, options.scheduler) : context,
|
|
5724
|
-
options?.uninterruptible !== true
|
|
5725
|
-
)
|
|
5736
|
+
const fiber = new FiberImpl<A, E>(context as Context.Context<never>, options?.uninterruptible !== true)
|
|
5726
5737
|
fiber.evaluate(effect as any)
|
|
5727
|
-
if (fiber._exit)
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5738
|
+
if (!fiber._exit) {
|
|
5739
|
+
const signal = options?.signal
|
|
5740
|
+
if (signal) {
|
|
5741
|
+
if (signal.aborted) {
|
|
5742
|
+
fiber.interruptUnsafe()
|
|
5743
|
+
} else {
|
|
5744
|
+
const abort = () => fiber.interruptUnsafe()
|
|
5745
|
+
signal.addEventListener("abort", abort, { once: true })
|
|
5746
|
+
fiber.addObserver(() => signal.removeEventListener("abort", abort))
|
|
5747
|
+
}
|
|
5736
5748
|
}
|
|
5737
|
-
|
|
5738
|
-
if (options?.onFiberStart) {
|
|
5739
|
-
options.onFiberStart(fiber)
|
|
5749
|
+
options?.onFiberStart?.(fiber)
|
|
5740
5750
|
}
|
|
5741
5751
|
return fiber
|
|
5742
5752
|
}
|
|
5743
5753
|
|
|
5754
|
+
/** @internal */
|
|
5755
|
+
export const runForkWith = <R>(context: Context.Context<R>) =>
|
|
5756
|
+
<A, E>(
|
|
5757
|
+
effect: Effect.Effect<A, E, R>,
|
|
5758
|
+
options?: Effect.RunOptions | undefined
|
|
5759
|
+
): Fiber.Fiber<A, E> =>
|
|
5760
|
+
runFiber(
|
|
5761
|
+
options?.scheduler ? Context.addUnsafe(context, SchedulerKey, options.scheduler) : context,
|
|
5762
|
+
effect,
|
|
5763
|
+
options
|
|
5764
|
+
)
|
|
5765
|
+
|
|
5744
5766
|
/** @internal */
|
|
5745
5767
|
export const fiberRunIn: {
|
|
5746
5768
|
(scope: Scope.Scope): <A, E>(self: Fiber.Fiber<A, E>) => Fiber.Fiber<A, E>
|
|
@@ -5765,10 +5787,17 @@ export const fiberRunIn: {
|
|
|
5765
5787
|
})
|
|
5766
5788
|
|
|
5767
5789
|
/** @internal */
|
|
5768
|
-
export const runFork
|
|
5790
|
+
export const runFork = <A, E>(
|
|
5769
5791
|
effect: Effect.Effect<A, E, never>,
|
|
5770
5792
|
options?: Effect.RunOptions | undefined
|
|
5771
|
-
)
|
|
5793
|
+
): Fiber.Fiber<A, E> =>
|
|
5794
|
+
runFiber(
|
|
5795
|
+
options?.scheduler
|
|
5796
|
+
? Context.makeUnsafe(new Map([[SchedulerKey, options.scheduler]]))
|
|
5797
|
+
: Context.empty(),
|
|
5798
|
+
effect,
|
|
5799
|
+
options
|
|
5800
|
+
)
|
|
5772
5801
|
|
|
5773
5802
|
/** @internal */
|
|
5774
5803
|
export const runCallbackWith = <R>(context: Context.Context<R>) => {
|
package/src/internal/equal.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Shared state and helpers for `Equal.ts` and `Hash.ts`.
|
|
2
|
+
|
|
1
3
|
// JavaScriptCore (Bun, Safari) stamps the construction site onto every Error as
|
|
2
4
|
// non-enumerable own properties. Like `stack`, they describe where the error was
|
|
3
5
|
// created, not what it is.
|
|
@@ -74,3 +76,37 @@ export const toBytes = (u: ArrayBufferLike | DataView, kind: number): Uint8Array
|
|
|
74
76
|
return undefined
|
|
75
77
|
}
|
|
76
78
|
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Back-edge count used to avoid caching entry-point-dependent hashes and
|
|
82
|
+
* comparisons.
|
|
83
|
+
*
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
export let backEdges = 0
|
|
87
|
+
|
|
88
|
+
/** @internal */
|
|
89
|
+
export const addBackEdge = (): void => {
|
|
90
|
+
backEdges++
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @internal */
|
|
94
|
+
export const hashCache = new WeakMap<object, number>()
|
|
95
|
+
|
|
96
|
+
// 32-bit MurmurHash3 finalizer.
|
|
97
|
+
/** @internal */
|
|
98
|
+
export const mix = (h: number): number => {
|
|
99
|
+
h ^= h >>> 16
|
|
100
|
+
h = Math.imul(h, 0x85ebca6b)
|
|
101
|
+
h ^= h >>> 13
|
|
102
|
+
h = Math.imul(h, 0xc2b2ae35)
|
|
103
|
+
return h ^ (h >>> 16)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Data-first `Hash.combine` used by `Hash.ts` and runtime data types so
|
|
108
|
+
* hashing does not pull in `Function.dual`.
|
|
109
|
+
*
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export const combine = (self: number, b: number): number => mix(Math.imul(self, 0x9e3779b1) + Math.imul(b, 0x85ebca6b))
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { LogLevel, Severity } from "../LogLevel.ts"
|
|
2
|
+
import type * as Tracer from "../Tracer.ts"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reading cached services by key lets bundlers drop unused service constructors.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** @internal */
|
|
9
|
+
export const SchedulerKey = "effect/Scheduler" as const
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export const MaxOpsBeforeYieldKey = "effect/Scheduler/MaxOpsBeforeYield" as const
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const PreventSchedulerYieldKey = "effect/Scheduler/PreventSchedulerYield" as const
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const TracerKey = "effect/Tracer" satisfies typeof Tracer.TracerKey
|
|
19
|
+
|
|
20
|
+
/** @internal */
|
|
21
|
+
export const ParentSpanKey = "effect/Tracer/ParentSpan" satisfies typeof Tracer.ParentSpanKey
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
export const TracerEnabledKey = "effect/References/TracerEnabled" as const
|
|
25
|
+
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const CurrentStackFrameKey = "effect/References/CurrentStackFrame" as const
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const CurrentLogLevelKey = "effect/References/CurrentLogLevel" as const
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export const MinimumLogLevelKey = "effect/References/MinimumLogLevel" as const
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
export const FiberRuntimeMetricsKey = "effect/Metric/FiberRuntimeMetrics" as const
|
|
37
|
+
|
|
38
|
+
/** @internal */
|
|
39
|
+
export const defaultMaxOpsBeforeYield = 2048
|
|
40
|
+
|
|
41
|
+
/** @internal */
|
|
42
|
+
export const defaultPreventSchedulerYield = false
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
export const defaultTracerEnabled = true
|
|
46
|
+
|
|
47
|
+
/** @internal */
|
|
48
|
+
export const defaultCurrentLogLevel: Severity = "Info"
|
|
49
|
+
|
|
50
|
+
/** @internal */
|
|
51
|
+
export const defaultMinimumLogLevel: LogLevel = "Info"
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Constrains fiber cache reads to registered keys. `tracerContext` is derived
|
|
55
|
+
* from `tracer`, not read from the context.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
const runtimeKeys = [
|
|
60
|
+
SchedulerKey,
|
|
61
|
+
TracerKey,
|
|
62
|
+
TracerEnabledKey,
|
|
63
|
+
ParentSpanKey,
|
|
64
|
+
CurrentLogLevelKey,
|
|
65
|
+
MinimumLogLevelKey,
|
|
66
|
+
CurrentStackFrameKey,
|
|
67
|
+
FiberRuntimeMetricsKey,
|
|
68
|
+
MaxOpsBeforeYieldKey,
|
|
69
|
+
PreventSchedulerYieldKey
|
|
70
|
+
] as const
|
|
71
|
+
|
|
72
|
+
/** @internal */
|
|
73
|
+
export type FiberCacheKey = typeof runtimeKeys[number]
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pre-register runtime keys so cache invalidation survives tree-shaking of
|
|
77
|
+
* their service constructors. `fiberCached: true` registers additional keys.
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export const fiberCachedKeys: Set<string> = new Set(runtimeKeys)
|
package/src/internal/hashMap.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { pipeArguments } from "../Pipeable.ts"
|
|
|
14
14
|
import { hasProperty } from "../Predicate.ts"
|
|
15
15
|
import * as Result from "../Result.ts"
|
|
16
16
|
import type { NoInfer } from "../Types.ts"
|
|
17
|
-
import { backEdges } from "./
|
|
17
|
+
import { backEdges } from "./equal.ts"
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
20
|
export const HashMapTypeId = "~effect/HashMap"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-first `Predicate.hasProperty`.
|
|
3
|
+
*
|
|
4
|
+
* The guards of the runtime data types call this directly, so bundles that only
|
|
5
|
+
* run an effect do not carry `Function.dual` for the curried form.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const hasProperty = <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown } =>
|
|
10
|
+
((typeof self === "object" && self !== null) || typeof self === "function") && (property in self)
|