effect 4.1.5 → 4.1.6
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/ai-docs/package.json +2 -2
- package/dist/Channel.d.ts +104 -7
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +73 -4
- package/dist/Channel.js.map +1 -1
- package/dist/Codegen.d.ts +7 -2
- package/dist/Codegen.d.ts.map +1 -1
- package/dist/Codegen.js +7 -2
- package/dist/Codegen.js.map +1 -1
- package/dist/Effect.d.ts +139 -18
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +10 -2
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +4 -4
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +78 -65
- package/dist/Equal.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +24 -17
- package/dist/Hash.js.map +1 -1
- package/dist/LayerRef.d.ts +1 -1
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +3 -3
- package/dist/LayerRef.js.map +1 -1
- package/dist/Logger.d.ts +37 -13
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +39 -10
- package/dist/Logger.js.map +1 -1
- package/dist/Match.d.ts +23 -23
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js.map +1 -1
- package/dist/Order.js +1 -1
- package/dist/Order.js.map +1 -1
- package/dist/Schema.d.ts +41 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +51 -390
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +0 -3
- package/dist/SchemaAST.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +6 -4
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +128 -5
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +124 -29
- package/dist/Stream.js.map +1 -1
- package/dist/String.js +1 -1
- package/dist/String.js.map +1 -1
- package/dist/Tracer.d.ts +10 -0
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -0
- package/dist/Tracer.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 +152 -2
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +8 -2
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts +3 -1
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js +17 -3
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Skill.d.ts +172 -0
- package/dist/ai/Skill.d.ts.map +1 -0
- package/dist/ai/Skill.js +209 -0
- package/dist/ai/Skill.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +155 -83
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +56 -0
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +18 -2
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +45 -22
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/internal/entityActivation.js +2 -0
- package/dist/cluster/internal/entityActivation.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +8 -5
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/encoding/Base64.js +5 -1
- package/dist/encoding/Base64.js.map +1 -1
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +6 -1
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Xml.d.ts +38 -9
- package/dist/encoding/Xml.d.ts.map +1 -1
- package/dist/encoding/Xml.js +63 -31
- package/dist/encoding/Xml.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +2 -1
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +14 -10
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/Headers.d.ts +201 -3
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +205 -3
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +11 -7
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts +1 -0
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +32 -9
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +46 -0
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +15 -0
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts +132 -0
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +83 -0
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMiddleware.js +1 -1
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts +118 -0
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +43 -0
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/Multipart.d.ts.map +1 -1
- package/dist/http/Multipart.js +0 -5
- package/dist/http/Multipart.js.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
- package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.js +1 -1
- package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
- package/dist/http/internal/clientPath.d.ts +2 -0
- package/dist/http/internal/clientPath.d.ts.map +1 -0
- package/dist/http/internal/clientPath.js +24 -0
- package/dist/http/internal/clientPath.js.map +1 -0
- package/dist/http/internal/redactedPath.js +2 -0
- package/dist/http/internal/redactedPath.js.map +1 -1
- package/dist/http/internal/tracing.js +5 -3
- package/dist/http/internal/tracing.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +2 -2
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +30 -7
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +5 -2
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +23 -6
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/internal/redactedKeys.d.ts +2 -0
- package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
- package/dist/http-api/internal/redactedKeys.js +37 -0
- package/dist/http-api/internal/redactedKeys.js.map +1 -0
- package/dist/internal/base64.js +34 -2
- package/dist/internal/base64.js.map +1 -1
- package/dist/internal/dateTime.js +35 -17
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +9 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +14 -13
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/hash.js +4 -1
- package/dist/internal/hash.js.map +1 -1
- package/dist/internal/matcher.js +17 -17
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/schemaCodegen.js +3 -2
- package/dist/internal/schema/schemaCodegen.js.map +1 -1
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
- package/dist/internal/schema/toEquivalence.js +3 -4
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/jose/JoseError.d.ts +51 -1
- package/dist/jose/JoseError.d.ts.map +1 -1
- package/dist/jose/JoseError.js +25 -18
- package/dist/jose/JoseError.js.map +1 -1
- package/dist/jose/internal/compact.js +10 -5
- package/dist/jose/internal/compact.js.map +1 -1
- package/dist/observability/Otlp.d.ts +19 -0
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpExporter.d.ts +49 -13
- package/dist/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/observability/OtlpExporter.js +135 -54
- package/dist/observability/OtlpExporter.js.map +1 -1
- package/dist/observability/OtlpLogger.d.ts +14 -0
- package/dist/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/observability/OtlpLogger.js +10 -2
- package/dist/observability/OtlpLogger.js.map +1 -1
- package/dist/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/observability/OtlpMetrics.js +2 -0
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.d.ts +14 -0
- package/dist/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/observability/OtlpTracer.js +10 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +6 -4
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +10 -9
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +32 -1
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcGroup.d.ts +1 -1
- package/dist/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/rpc/RpcGroup.js +4 -0
- package/dist/rpc/RpcGroup.js.map +1 -1
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +2 -5
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -1
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/workflow/Activity.d.ts +18 -0
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/Activity.js +13 -4
- package/dist/workflow/Activity.js.map +1 -1
- package/dist/workflow/Workflow.d.ts +10 -9
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +33 -22
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +26 -12
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/dist/workflow/internal/retry.d.ts +2 -0
- package/dist/workflow/internal/retry.d.ts.map +1 -0
- package/dist/workflow/internal/retry.js +11 -0
- package/dist/workflow/internal/retry.js.map +1 -0
- package/dist/workflow/internal/scope.d.ts +2 -0
- package/dist/workflow/internal/scope.d.ts.map +1 -0
- package/dist/workflow/internal/scope.js +26 -0
- package/dist/workflow/internal/scope.js.map +1 -0
- package/package.json +3 -3
- package/src/Channel.ts +105 -8
- package/src/Codegen.ts +7 -2
- package/src/Effect.ts +224 -48
- package/src/Equal.ts +85 -79
- package/src/Hash.ts +30 -22
- package/src/LayerRef.ts +6 -4
- package/src/Logger.ts +68 -25
- package/src/Match.ts +78 -50
- package/src/Order.ts +1 -1
- package/src/Schema.ts +79 -296
- package/src/SchemaAST.ts +0 -1
- package/src/ScopedCache.ts +6 -4
- package/src/Stream.ts +167 -33
- package/src/String.ts +1 -1
- package/src/Tracer.ts +10 -0
- package/src/ai/McpServer.ts +161 -4
- package/src/ai/Prompt.ts +20 -3
- package/src/ai/Skill.ts +236 -0
- package/src/ai/index.ts +6 -0
- package/src/cluster/ClusterWorkflowEngine.ts +172 -96
- package/src/cluster/MessageStorage.ts +51 -2
- package/src/cluster/SqlMessageStorage.ts +81 -34
- package/src/cluster/internal/entityActivation.ts +6 -0
- package/src/cluster/internal/entityManager.ts +8 -4
- package/src/encoding/Base64.ts +5 -1
- package/src/encoding/Base64Url.ts +6 -1
- package/src/encoding/Xml.ts +96 -26
- package/src/http/FetchHttpClient.ts +8 -5
- package/src/http/Headers.ts +309 -3
- package/src/http/HttpClient.ts +19 -7
- package/src/http/HttpClientError.ts +42 -9
- package/src/http/HttpClientRequest.ts +51 -0
- package/src/http/HttpClientResponse.ts +156 -0
- package/src/http/HttpMiddleware.ts +1 -1
- package/src/http/HttpServerResponse.ts +126 -0
- package/src/http/Multipart.ts +0 -5
- package/src/http/MultipartParser/internal/contentType.ts +1 -1
- package/src/http/internal/clientPath.ts +39 -0
- package/src/http/internal/redactedPath.ts +4 -0
- package/src/http/internal/tracing.ts +6 -3
- package/src/http-api/HttpApi.ts +29 -8
- package/src/http-api/HttpApiBuilder.ts +7 -2
- package/src/http-api/HttpApiClient.ts +30 -7
- package/src/http-api/internal/redactedKeys.ts +40 -0
- package/src/internal/base64.ts +57 -2
- package/src/internal/dateTime.ts +43 -24
- package/src/internal/effect.ts +31 -102
- package/src/internal/equal.ts +37 -17
- package/src/internal/hash.ts +5 -1
- package/src/internal/matcher.ts +34 -113
- package/src/internal/schema/schemaCodegen.ts +5 -4
- package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
- package/src/internal/schema/toEquivalence.ts +3 -5
- package/src/internal/version.ts +1 -1
- package/src/jose/JoseError.ts +34 -0
- package/src/jose/internal/compact.ts +14 -5
- package/src/observability/Otlp.ts +29 -0
- package/src/observability/OtlpExporter.ts +206 -75
- package/src/observability/OtlpLogger.ts +24 -2
- package/src/observability/OtlpMetrics.ts +2 -0
- package/src/observability/OtlpTracer.ts +24 -3
- package/src/persistence/KeyValueStore.ts +17 -14
- package/src/reactivity/Atom.ts +12 -18
- package/src/rpc/RpcClient.ts +26 -1
- package/src/rpc/RpcGroup.ts +4 -1
- package/src/sql/Migrator.ts +2 -11
- package/src/sql/SqlClient.ts +14 -8
- package/src/workflow/Activity.ts +28 -4
- package/src/workflow/Workflow.ts +68 -44
- package/src/workflow/WorkflowEngine.ts +38 -15
- package/src/workflow/internal/retry.ts +12 -0
- package/src/workflow/internal/scope.ts +36 -0
package/src/Equal.ts
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { Equivalence } from "./Equivalence.ts"
|
|
14
14
|
import * as Hash from "./Hash.ts"
|
|
15
|
-
import {
|
|
15
|
+
import { byReferenceInstances, getAllObjectKeys, objectKind, toBytes } from "./internal/equal.ts"
|
|
16
|
+
import { addBackEdge, backEdges, hashCache } from "./internal/hash.ts"
|
|
16
17
|
import { hasProperty } from "./Predicate.ts"
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -133,14 +134,14 @@ export interface Equal extends Hash.Hash {
|
|
|
133
134
|
* Functions without an `Equal` implementation compare by reference. Circular
|
|
134
135
|
* structures use coinductive equality.
|
|
135
136
|
*
|
|
136
|
-
* Hash
|
|
137
|
-
*
|
|
138
|
-
* predicate.
|
|
137
|
+
* Custom `Hash` implementations and already-cached structural hashes are
|
|
138
|
+
* checked first as a fast-path rejection. The function also supports dual
|
|
139
|
+
* data-last usage: call it with one argument to get a curried predicate.
|
|
139
140
|
*
|
|
140
141
|
* **Gotchas**
|
|
141
142
|
*
|
|
142
143
|
* - Object-pair results are cached in a WeakMap. **Objects must not be
|
|
143
|
-
*
|
|
144
|
+
* mutated after their first comparison.**
|
|
144
145
|
* - Map and Set entries are matched within groups of equal hashes, so they
|
|
145
146
|
* are O(n) for well-distributed hashes and O(n²) when every hash collides.
|
|
146
147
|
*
|
|
@@ -184,114 +185,121 @@ export function equals(): any {
|
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
function compareBoth(self: unknown, that: unknown): boolean {
|
|
187
|
-
if (self
|
|
188
|
-
if (self == null || that == null) return false
|
|
188
|
+
if (self == null || that == null) return self === that
|
|
189
189
|
const selfType = typeof self
|
|
190
|
-
if (selfType !==
|
|
191
|
-
return
|
|
190
|
+
if (selfType !== "object" && selfType !== "function") {
|
|
191
|
+
return self === that || (self !== self && that !== that)
|
|
192
192
|
}
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
if (self === that) {
|
|
194
|
+
// A shared reference can close a cycle on one side; hashing records any back-edge.
|
|
195
|
+
if (pathLeft.length > 0 && !hashCache.has(self)) Hash.hash(self)
|
|
195
196
|
return true
|
|
196
197
|
}
|
|
197
|
-
if (selfType !==
|
|
198
|
-
return false
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (byReferenceInstances.has(self) || byReferenceInstances.has(that)) {
|
|
198
|
+
if (selfType !== typeof that || byReferenceInstances.has(self) || byReferenceInstances.has(that)) {
|
|
202
199
|
return false
|
|
203
200
|
}
|
|
204
|
-
|
|
205
201
|
return compareObjects(self, that)
|
|
206
202
|
}
|
|
207
203
|
|
|
208
204
|
function compareObjects(self: object, that: object): boolean {
|
|
209
205
|
const depth = pathLeft.length
|
|
210
|
-
|
|
206
|
+
const prev = seen.get(self)
|
|
207
|
+
if (prev === that) return true
|
|
208
|
+
let known: WeakMap<object, boolean> | undefined
|
|
209
|
+
if (!depth || prev !== undefined) {
|
|
210
|
+
known = results.get(self)
|
|
211
|
+
const cached = known?.get(that)
|
|
212
|
+
if (cached !== undefined) return cached
|
|
213
|
+
}
|
|
214
|
+
let revisited = false
|
|
211
215
|
for (let i = depth; i-- > 0;) {
|
|
212
|
-
|
|
216
|
+
const sameLeft = pathLeft[i] === self
|
|
217
|
+
if (sameLeft || pathRight[i] === that) {
|
|
218
|
+
addBackEdge()
|
|
219
|
+
// A repeated pair closes a cycle under coinductive equality.
|
|
220
|
+
if (sameLeft && pathRight[i] === that) return true
|
|
221
|
+
revisited = true
|
|
222
|
+
}
|
|
213
223
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (!known) results.set(self, known = new WeakMap())
|
|
218
|
-
let result = known.get(that)
|
|
219
|
-
if (result === undefined) known.set(that, result = compareOnPath(self, that))
|
|
220
|
-
return result
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function compareOnPath(self: object, that: object): boolean {
|
|
224
|
+
// Reject mismatched cycle lengths instead of unrolling both loops.
|
|
225
|
+
if (revisited && Hash.hash(self) !== Hash.hash(that)) return false
|
|
226
|
+
const seenBack = backEdges
|
|
224
227
|
pathLeft.push(self)
|
|
225
228
|
pathRight.push(that)
|
|
229
|
+
let result: boolean
|
|
226
230
|
try {
|
|
227
|
-
|
|
231
|
+
result = compareStructure(self, that)
|
|
228
232
|
} finally {
|
|
229
233
|
pathLeft.pop()
|
|
230
234
|
pathRight.pop()
|
|
235
|
+
if (!depth) seen.clear()
|
|
236
|
+
}
|
|
237
|
+
// Cyclic hashes depend on entry point; verify hash agreement.
|
|
238
|
+
if (seenBack !== backEdges) return result && Hash.hash(self) === Hash.hash(that)
|
|
239
|
+
// Only cache acyclic results so nested lookups never skip a back-edge.
|
|
240
|
+
if (depth && prev === undefined) {
|
|
241
|
+
if (result) seen.set(self, that)
|
|
242
|
+
} else {
|
|
243
|
+
if (!known) results.set(self, known = new WeakMap())
|
|
244
|
+
known.set(that, result)
|
|
231
245
|
}
|
|
246
|
+
return result
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
// The pairs on the current comparison's path (the coinductive assumptions).
|
|
235
250
|
const pathLeft: Array<object> = []
|
|
236
251
|
const pathRight: Array<object> = []
|
|
252
|
+
const seen = new Map<object, object>()
|
|
237
253
|
const results = new WeakMap<object, WeakMap<object, boolean>>()
|
|
238
254
|
|
|
239
255
|
function compareStructure(self: object, that: object): boolean {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
256
|
+
const selfHash = hashCache.get(self)
|
|
257
|
+
if (selfHash !== undefined && selfHash !== (hashCache.get(that) ?? selfHash)) return false
|
|
258
|
+
const kind = objectKind(self)
|
|
259
|
+
if (kind === 1 || kind === 2) {
|
|
260
|
+
if (objectKind(that) !== kind) return false
|
|
261
|
+
if (kind === 2) return self.toString() === that.toString()
|
|
262
|
+
if (Hash.hash(self) !== Hash.hash(that)) return false
|
|
263
|
+
const a = (self as Date).getTime()
|
|
264
|
+
const b = (that as Date).getTime()
|
|
265
|
+
return a === b || (a !== a && b !== b)
|
|
249
266
|
}
|
|
250
267
|
const bothEquals = isEqual(self)
|
|
251
268
|
if (bothEquals !== isEqual(that) || (typeof self === "function" && !bothEquals)) {
|
|
252
269
|
return false
|
|
253
|
-
}
|
|
270
|
+
}
|
|
271
|
+
if ((bothEquals || Hash.isHash(self) || Hash.isHash(that)) && Hash.hash(self) !== Hash.hash(that)) {
|
|
272
|
+
return false
|
|
273
|
+
}
|
|
274
|
+
if (bothEquals) {
|
|
254
275
|
return (self as Equal)[symbol](that as Equal)
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return false
|
|
263
|
-
}
|
|
264
|
-
const selfBytes = bufferBytes(self)
|
|
265
|
-
const thatBytes = bufferBytes(that)
|
|
276
|
+
}
|
|
277
|
+
if (kind !== objectKind(that)) {
|
|
278
|
+
return false
|
|
279
|
+
}
|
|
280
|
+
if (kind >= 7) {
|
|
281
|
+
const selfBytes = toBytes(self as ArrayBufferLike | DataView, kind)
|
|
282
|
+
const thatBytes = toBytes(that as ArrayBufferLike | DataView, kind)
|
|
266
283
|
return selfBytes !== undefined && thatBytes !== undefined && compareTypedArrays(selfBytes, thatBytes)
|
|
267
|
-
} else if (
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
self
|
|
272
|
-
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
return compareTypedArrays(self as Uint8Array, that as Uint8Array)
|
|
280
|
-
} else if (self instanceof Map) {
|
|
281
|
-
if (!(that instanceof Map) || self.size !== that.size) {
|
|
282
|
-
return false
|
|
283
|
-
}
|
|
284
|
-
return compareHashed(self, that, entryHash, equalEntries)
|
|
285
|
-
} else if (self instanceof Set) {
|
|
286
|
-
if (!(that instanceof Set) || self.size !== that.size) {
|
|
287
|
-
return false
|
|
288
|
-
}
|
|
289
|
-
return compareHashed(self, that, Hash.hash, compareBoth)
|
|
284
|
+
} else if (kind === 5) {
|
|
285
|
+
return compareArrays(self as Array<unknown>, that as Array<unknown>)
|
|
286
|
+
} else if (kind === 6) {
|
|
287
|
+
return (self as ArrayBufferView).byteLength === (that as ArrayBufferView).byteLength &&
|
|
288
|
+
compareTypedArrays(self as Uint8Array, that as Uint8Array)
|
|
289
|
+
} else if (kind === 3) {
|
|
290
|
+
return (self as Map<unknown, unknown>).size === (that as Map<unknown, unknown>).size &&
|
|
291
|
+
compareHashed(self as Map<unknown, unknown>, that as Map<unknown, unknown>, entryHash, equalEntries)
|
|
292
|
+
} else if (kind === 4) {
|
|
293
|
+
return (self as Set<unknown>).size === (that as Set<unknown>).size &&
|
|
294
|
+
compareHashed(self as Set<unknown>, that as Set<unknown>, Hash.hash, compareBoth)
|
|
290
295
|
}
|
|
291
296
|
return compareRecords(self as any, that as any)
|
|
292
297
|
}
|
|
293
298
|
|
|
294
299
|
function compareArrays(self: Array<unknown>, that: Array<unknown>): boolean {
|
|
300
|
+
if (self.length !== that.length) {
|
|
301
|
+
return false
|
|
302
|
+
}
|
|
295
303
|
for (let i = 0; i < self.length; i++) {
|
|
296
304
|
if (!compareBoth(self[i], that[i])) {
|
|
297
305
|
return false
|
|
@@ -319,17 +327,15 @@ function compareRecords(
|
|
|
319
327
|
): boolean {
|
|
320
328
|
const selfKeys = getAllObjectKeys(self)
|
|
321
329
|
const thatKeys = getAllObjectKeys(that)
|
|
322
|
-
|
|
323
|
-
if (selfKeys.size !== thatKeys.size) {
|
|
330
|
+
const thatIsSet = thatKeys instanceof Set
|
|
331
|
+
if ((selfKeys instanceof Set ? selfKeys.size : selfKeys.length) !== (thatIsSet ? thatKeys.size : thatKeys.length)) {
|
|
324
332
|
return false
|
|
325
333
|
}
|
|
326
|
-
|
|
327
334
|
for (const key of selfKeys) {
|
|
328
|
-
if (!(thatKeys.has(key)) || !compareBoth(self[key], that[key])) {
|
|
335
|
+
if (!(thatIsSet ? thatKeys.has(key) : Object.hasOwn(that, key)) || !compareBoth(self[key], that[key])) {
|
|
329
336
|
return false
|
|
330
337
|
}
|
|
331
338
|
}
|
|
332
|
-
|
|
333
339
|
return true
|
|
334
340
|
}
|
|
335
341
|
|
package/src/Hash.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* @since 2.0.0
|
|
12
12
|
*/
|
|
13
13
|
import { dual } from "./Function.ts"
|
|
14
|
-
import {
|
|
15
|
-
import { addBackEdge, backEdges } from "./internal/hash.ts"
|
|
14
|
+
import { byReferenceInstances, getAllObjectKeys, objectKind, toBytes } from "./internal/equal.ts"
|
|
15
|
+
import { addBackEdge, backEdges, hashCache } from "./internal/hash.ts"
|
|
16
16
|
import { hasProperty } from "./Predicate.ts"
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -117,13 +117,15 @@ export const hash: <A>(self: A) => number = <A>(self: A) => {
|
|
|
117
117
|
case "object": {
|
|
118
118
|
if (self === null) {
|
|
119
119
|
break
|
|
120
|
-
}
|
|
121
|
-
|
|
120
|
+
}
|
|
121
|
+
const kind = objectKind(self)
|
|
122
|
+
if (kind === 1) {
|
|
123
|
+
if (Number.isNaN((self as any as Date).getTime())) {
|
|
122
124
|
return string("Invalid Date")
|
|
123
125
|
}
|
|
124
|
-
return string(self.toISOString())
|
|
125
|
-
} else if (
|
|
126
|
-
return string(self.toString())
|
|
126
|
+
return string((self as any as Date).toISOString())
|
|
127
|
+
} else if (kind === 2) {
|
|
128
|
+
return string((self as any as RegExp).toString())
|
|
127
129
|
} else {
|
|
128
130
|
if (byReferenceInstances.has(self)) {
|
|
129
131
|
return random(self)
|
|
@@ -144,17 +146,15 @@ export const hash: <A>(self: A) => number = <A>(self: A) => {
|
|
|
144
146
|
h = (self as Hash)[symbol]()
|
|
145
147
|
} else if (typeof self === "function") {
|
|
146
148
|
h = random(self)
|
|
147
|
-
} else if (
|
|
148
|
-
const bytes =
|
|
149
|
-
h = bytes === undefined ? random(self) :
|
|
150
|
-
} else if (
|
|
151
|
-
h =
|
|
152
|
-
} else if (
|
|
153
|
-
h =
|
|
154
|
-
} else if (
|
|
155
|
-
h =
|
|
156
|
-
} else if (self instanceof Set) {
|
|
157
|
-
h = hashSet(self)
|
|
149
|
+
} else if (kind >= 7) {
|
|
150
|
+
const bytes = toBytes(self as any, kind)
|
|
151
|
+
h = bytes === undefined ? random(self) : hashIndexed(bytes)
|
|
152
|
+
} else if (kind >= 5) {
|
|
153
|
+
h = hashIndexed(self as any)
|
|
154
|
+
} else if (kind === 3) {
|
|
155
|
+
h = hashMap(self as any)
|
|
156
|
+
} else if (kind === 4) {
|
|
157
|
+
h = hashSet(self as any)
|
|
158
158
|
} else {
|
|
159
159
|
h = structure(self)
|
|
160
160
|
}
|
|
@@ -203,10 +203,11 @@ export const hash: <A>(self: A) => number = <A>(self: A) => {
|
|
|
203
203
|
* @since 2.0.0
|
|
204
204
|
*/
|
|
205
205
|
export const random: <A extends object>(self: A) => number = (self) => {
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
let h = randomHashCache.get(self)
|
|
207
|
+
if (h === undefined) {
|
|
208
|
+
randomHashCache.set(self, h = optimize((Math.random() * 0x100000000) | 0))
|
|
208
209
|
}
|
|
209
|
-
return
|
|
210
|
+
return h
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
// 32-bit MurmurHash3 finalizer.
|
|
@@ -580,6 +581,14 @@ export const array = <A>(arr: Iterable<A>): number => {
|
|
|
580
581
|
return optimize(h)
|
|
581
582
|
}
|
|
582
583
|
|
|
584
|
+
const hashIndexed = (arr: ArrayLike<unknown>): number => {
|
|
585
|
+
let h = 6151
|
|
586
|
+
for (let i = 0; i < arr.length; i++) {
|
|
587
|
+
h = combine(h, hash(arr[i]))
|
|
588
|
+
}
|
|
589
|
+
return optimize(h)
|
|
590
|
+
}
|
|
591
|
+
|
|
583
592
|
const hashMap: <K, V>(map: Iterable<readonly [K, V]>) => number = unordered(
|
|
584
593
|
string("Map"),
|
|
585
594
|
([k, v]) => combine(hash(k), hash(v))
|
|
@@ -588,5 +597,4 @@ const setSeed = string("Set")
|
|
|
588
597
|
const hashSet: <A>(set: Iterable<A>) => number = unordered(setSeed, (element) => combine(setSeed, hash(element)))
|
|
589
598
|
|
|
590
599
|
const randomHashCache = new WeakMap<any, number>()
|
|
591
|
-
const hashCache = new WeakMap<object, number>()
|
|
592
600
|
const visitedObjects = new WeakSet<object>()
|
package/src/LayerRef.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { getStackTraceLimit, setStackTraceLimit } from "./internal/stackTraceLim
|
|
|
16
16
|
import * as Layer from "./Layer.ts"
|
|
17
17
|
import * as RcRef from "./RcRef.ts"
|
|
18
18
|
import type * as Schedule from "./Schedule.ts"
|
|
19
|
-
import * as Scope from "./Scope.ts"
|
|
19
|
+
import type * as Scope from "./Scope.ts"
|
|
20
20
|
import type { Mutable } from "./Types.ts"
|
|
21
21
|
|
|
22
22
|
const TypeId = "~effect/LayerRef"
|
|
@@ -157,11 +157,13 @@ export const make = Effect.fnUntraced(
|
|
|
157
157
|
Scope.Scope | R | SR
|
|
158
158
|
> {
|
|
159
159
|
const context = yield* Effect.context<never>()
|
|
160
|
-
const memoMap = Layer.CurrentMemoMap.forkOrCreate(context)
|
|
161
160
|
|
|
162
161
|
const rcRef = yield* RcRef.make({
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
// Fork the creation-time memo map per acquisition so rebuilds don't reuse
|
|
163
|
+
// a live borrow (`Layer.build` would inherit the borrower's memo map).
|
|
164
|
+
acquire: Effect.flatMap(
|
|
165
|
+
Effect.scope,
|
|
166
|
+
(scope) => Layer.buildWithMemoMap(layer, Layer.CurrentMemoMap.forkOrCreate(context), scope)
|
|
165
167
|
),
|
|
166
168
|
idleTimeToLive: options?.idleTimeToLive
|
|
167
169
|
})
|
package/src/Logger.ts
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* logger references, console routing helpers, built-in formatters, batching,
|
|
8
8
|
* file logging, and layers for installing loggers.
|
|
9
9
|
*
|
|
10
|
+
* When a log effect (`Effect.log`, `Effect.logWithLevel`, or a level-specific
|
|
11
|
+
* variant) invokes a logger, it does so synchronously in the logging fiber
|
|
12
|
+
* before the log effect completes. A logger that defers work says so in its own
|
|
13
|
+
* documentation, as `batched` and `toFile` do.
|
|
14
|
+
*
|
|
10
15
|
* @stability stable
|
|
11
16
|
* @since 2.0.0
|
|
12
17
|
*/
|
|
@@ -37,9 +42,9 @@ const TypeId = "~effect/Logger"
|
|
|
37
42
|
*
|
|
38
43
|
* **Details**
|
|
39
44
|
*
|
|
40
|
-
* The runtime calls `log`
|
|
41
|
-
* for each log event. Use
|
|
42
|
-
* effect.
|
|
45
|
+
* The runtime calls `log` synchronously, in the fiber that logs, with the
|
|
46
|
+
* message, level, cause, fiber, and timestamp for each log event. Use
|
|
47
|
+
* `Logger.layer` to install one or more loggers for an effect.
|
|
43
48
|
*
|
|
44
49
|
* **Example** (Creating custom loggers)
|
|
45
50
|
*
|
|
@@ -198,6 +203,10 @@ export const LogToStderr: Context.Reference<boolean> = effect.LogToStderr
|
|
|
198
203
|
* Use when an existing logger's output should be transformed without recreating the
|
|
199
204
|
* logging logic.
|
|
200
205
|
*
|
|
206
|
+
* **Details**
|
|
207
|
+
*
|
|
208
|
+
* The returned logger calls `self` and then `f` inside the same `log` call.
|
|
209
|
+
*
|
|
201
210
|
* **Example** (Transforming logger output)
|
|
202
211
|
*
|
|
203
212
|
* ```ts import.meta.vitest
|
|
@@ -233,6 +242,10 @@ export const map = dual<
|
|
|
233
242
|
* Use when an existing logger's output should be transformed without recreating the
|
|
234
243
|
* logging logic.
|
|
235
244
|
*
|
|
245
|
+
* **Details**
|
|
246
|
+
*
|
|
247
|
+
* The returned logger calls `self` and then `f` inside the same `log` call.
|
|
248
|
+
*
|
|
236
249
|
* **Example** (Transforming logger output)
|
|
237
250
|
*
|
|
238
251
|
* ```ts import.meta.vitest
|
|
@@ -270,6 +283,10 @@ export const map = dual<
|
|
|
270
283
|
* Use when an existing logger's output should be transformed without recreating the
|
|
271
284
|
* logging logic.
|
|
272
285
|
*
|
|
286
|
+
* **Details**
|
|
287
|
+
*
|
|
288
|
+
* The returned logger calls `self` and then `f` inside the same `log` call.
|
|
289
|
+
*
|
|
273
290
|
* **Example** (Transforming logger output)
|
|
274
291
|
*
|
|
275
292
|
* ```ts import.meta.vitest
|
|
@@ -308,6 +325,10 @@ export const map = dual<
|
|
|
308
325
|
* Use when a logger's string or object output should be routed to `console.log` for
|
|
309
326
|
* development or debugging.
|
|
310
327
|
*
|
|
328
|
+
* **Details**
|
|
329
|
+
*
|
|
330
|
+
* Writes to the console inside the `log` call.
|
|
331
|
+
*
|
|
311
332
|
* **Example** (Writing logger output with console.log)
|
|
312
333
|
*
|
|
313
334
|
* ```ts import.meta.vitest
|
|
@@ -349,6 +370,10 @@ export const withConsoleLog = <Message, Output>(
|
|
|
349
370
|
* Use when logger output should be routed to `console.error`, such as error logs that
|
|
350
371
|
* should appear on stderr instead of stdout.
|
|
351
372
|
*
|
|
373
|
+
* **Details**
|
|
374
|
+
*
|
|
375
|
+
* Writes to the console inside the `log` call.
|
|
376
|
+
*
|
|
352
377
|
* **Example** (Writing logger output with console.error)
|
|
353
378
|
*
|
|
354
379
|
* ```ts import.meta.vitest
|
|
@@ -387,8 +412,9 @@ export const withConsoleError = <Message, Output>(
|
|
|
387
412
|
*
|
|
388
413
|
* **Details**
|
|
389
414
|
*
|
|
390
|
-
*
|
|
391
|
-
* etc.) based upon the current
|
|
415
|
+
* Writes to the console inside the `log` call. Will use the appropriate console
|
|
416
|
+
* method (i.e. `console.log`, `console.error`, etc.) based upon the current
|
|
417
|
+
* `LogLevel`.
|
|
392
418
|
*
|
|
393
419
|
* `Debug` uses `console.debug`, `Info` uses `console.info`, `Trace` uses
|
|
394
420
|
* `console.trace`, `Warn` uses `console.warn`, `Error` and `Fatal` use
|
|
@@ -519,6 +545,12 @@ const format = (
|
|
|
519
545
|
*
|
|
520
546
|
* The log function receives an options object containing the message, log level,
|
|
521
547
|
* cause, fiber information, and timestamp, and should return the desired output.
|
|
548
|
+
* `log` is called synchronously in the fiber that logs, before the log effect
|
|
549
|
+
* completes.
|
|
550
|
+
*
|
|
551
|
+
* **Gotchas**
|
|
552
|
+
*
|
|
553
|
+
* If `log` throws, the log effect dies with the thrown value as a defect.
|
|
522
554
|
*
|
|
523
555
|
* **Example** (Creating loggers from functions)
|
|
524
556
|
*
|
|
@@ -747,9 +779,11 @@ export const formatJson = map(formatStructured, Formatter.formatJson)
|
|
|
747
779
|
*
|
|
748
780
|
* **Details**
|
|
749
781
|
*
|
|
750
|
-
* The returned
|
|
751
|
-
*
|
|
752
|
-
*
|
|
782
|
+
* The returned logger formats each event with `self` and buffers the output
|
|
783
|
+
* during the log call. A background fiber passes pending entries to `flush`
|
|
784
|
+
* once per window, skipping empty windows. When the scope closes, the
|
|
785
|
+
* background fiber is interrupted and the scope finalizer flushes any remaining
|
|
786
|
+
* entries.
|
|
753
787
|
*
|
|
754
788
|
* **Example** (Batching logger output)
|
|
755
789
|
*
|
|
@@ -785,9 +819,11 @@ export const batched = dual<
|
|
|
785
819
|
*
|
|
786
820
|
* **Details**
|
|
787
821
|
*
|
|
788
|
-
* The returned
|
|
789
|
-
*
|
|
790
|
-
*
|
|
822
|
+
* The returned logger formats each event with `self` and buffers the output
|
|
823
|
+
* during the log call. A background fiber passes pending entries to `flush`
|
|
824
|
+
* once per window, skipping empty windows. When the scope closes, the
|
|
825
|
+
* background fiber is interrupted and the scope finalizer flushes any remaining
|
|
826
|
+
* entries.
|
|
791
827
|
*
|
|
792
828
|
* **Example** (Batching logger output)
|
|
793
829
|
*
|
|
@@ -830,9 +866,11 @@ export const batched = dual<
|
|
|
830
866
|
*
|
|
831
867
|
* **Details**
|
|
832
868
|
*
|
|
833
|
-
* The returned
|
|
834
|
-
*
|
|
835
|
-
*
|
|
869
|
+
* The returned logger formats each event with `self` and buffers the output
|
|
870
|
+
* during the log call. A background fiber passes pending entries to `flush`
|
|
871
|
+
* once per window, skipping empty windows. When the scope closes, the
|
|
872
|
+
* background fiber is interrupted and the scope finalizer flushes any remaining
|
|
873
|
+
* entries.
|
|
836
874
|
*
|
|
837
875
|
* **Example** (Batching logger output)
|
|
838
876
|
*
|
|
@@ -1136,8 +1174,10 @@ export const consoleJson: Logger<unknown, void> = withConsoleLog(formatJson)
|
|
|
1136
1174
|
* **Details**
|
|
1137
1175
|
*
|
|
1138
1176
|
* This logger integrates logging with distributed tracing by recording
|
|
1139
|
-
* all log messages as events on the current
|
|
1140
|
-
* in tracing tools like OpenTelemetry, Jaeger, or Zipkin.
|
|
1177
|
+
* all log messages as events on the current local span, making them visible
|
|
1178
|
+
* in tracing tools like OpenTelemetry, Jaeger, or Zipkin. A log made with no
|
|
1179
|
+
* current span, or while the nearest parent span is an `ExternalSpan`, is not
|
|
1180
|
+
* recorded by this logger.
|
|
1141
1181
|
*
|
|
1142
1182
|
* This logger is included in the default set of loggers for all Effect programs,
|
|
1143
1183
|
* so log messages automatically appear as span events unless you override the
|
|
@@ -1221,9 +1261,10 @@ export const layer = <
|
|
|
1221
1261
|
*
|
|
1222
1262
|
* **Details**
|
|
1223
1263
|
*
|
|
1224
|
-
* The returned effect requires `FileSystem` and `Scope`. The file logger
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1264
|
+
* The returned effect requires `FileSystem` and `Scope`. The file logger is
|
|
1265
|
+
* built on `batched`, so each log call formats and buffers its string output.
|
|
1266
|
+
* Each flushed batch is written to the specified path, and remaining entries
|
|
1267
|
+
* are flushed when the scope closes.
|
|
1227
1268
|
*
|
|
1228
1269
|
* **Example** (Writing JSON logs to a file)
|
|
1229
1270
|
*
|
|
@@ -1287,9 +1328,10 @@ export const toFile = dual<
|
|
|
1287
1328
|
*
|
|
1288
1329
|
* **Details**
|
|
1289
1330
|
*
|
|
1290
|
-
* The returned effect requires `FileSystem` and `Scope`. The file logger
|
|
1291
|
-
*
|
|
1292
|
-
*
|
|
1331
|
+
* The returned effect requires `FileSystem` and `Scope`. The file logger is
|
|
1332
|
+
* built on `batched`, so each log call formats and buffers its string output.
|
|
1333
|
+
* Each flushed batch is written to the specified path, and remaining entries
|
|
1334
|
+
* are flushed when the scope closes.
|
|
1293
1335
|
*
|
|
1294
1336
|
* **Example** (Writing JSON logs to a file)
|
|
1295
1337
|
*
|
|
@@ -1362,9 +1404,10 @@ export const toFile = dual<
|
|
|
1362
1404
|
*
|
|
1363
1405
|
* **Details**
|
|
1364
1406
|
*
|
|
1365
|
-
* The returned effect requires `FileSystem` and `Scope`. The file logger
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1407
|
+
* The returned effect requires `FileSystem` and `Scope`. The file logger is
|
|
1408
|
+
* built on `batched`, so each log call formats and buffers its string output.
|
|
1409
|
+
* Each flushed batch is written to the specified path, and remaining entries
|
|
1410
|
+
* are flushed when the scope closes.
|
|
1368
1411
|
*
|
|
1369
1412
|
* **Example** (Writing JSON logs to a file)
|
|
1370
1413
|
*
|